diff --git a/globals.js b/globals.js index 677c865392..68f4644392 100644 --- a/globals.js +++ b/globals.js @@ -8,7 +8,6 @@ const PORT = process.env.PORT || 8080; module.exports = (env = { TARGET: 'sdk' }) => ({ __DISABLE_SET_COOKIE__: false, __PAYPAL_DOMAIN__: 'https://www.paypal.com', - __PAYPAL_API_DOMAIN__: 'https://api.paypal.com', __ZOID__: { ...zoidGlobals.__ZOID__, __DEFAULT_CONTAINER__: true, @@ -36,16 +35,11 @@ module.exports = (env = { TARGET: 'sdk' }) => ({ __SANDBOX__: 'https://www.sandbox.paypal.com', __PRODUCTION__: 'https://www.paypal.com' }, - __API_DOMAIN__: { - __LOCAL__: `https://localhost.paypal.com:${PORT}`, - __SANDBOX__: 'https://api.sandbox.paypal.com', - __PRODUCTION__: 'https://api.paypal.com' - }, __URI__: { __MESSAGE__: '/credit-presentment/smart/message', __TREATMENTS__: '/credit-presentment/experiments/local', __MODAL__: '/credit-presentment/smart/modal', - __LOGGER__: '/v1/credit/upstream-messaging-events', + __LOGGER__: '/credit-presentment/glog', __CREDIT_APPLY__: '/ppcreditapply/da/us' } } diff --git a/src/utils/global.js b/src/utils/global.js index b08e2b92e7..c78b36fec1 100644 --- a/src/utils/global.js +++ b/src/utils/global.js @@ -10,8 +10,7 @@ import { getPageType, getPartnerAccount, getPayPalDomain, - getScript, - getPayPalAPIDomain + getScript } from './sdk'; import { createState } from './miscellaneous'; import { ppDebug } from './debug'; @@ -75,16 +74,6 @@ export const createTitleGenerator = () => { export function getGlobalUrl(type) { return `${getPayPalDomain()}${__MESSAGES__.__URI__[`__${type.toUpperCase()}__`]}`; } - -/** - * Create an API URL of the requested type from Webpack global variables - * @param {String} type URL type - * @returns {String} URL of requested type - */ -export function getGlobalAPIUrl(type) { - return `${getPayPalAPIDomain()}${__MESSAGES__.__URI__[`__${type.toUpperCase()}__`]}`; -} - // Return a getter function as opposed to the value itself so that it can be lazy loaded within // the SDK lifecycle to guard against unintentionally using state from previous SDK instances export const createGlobalVariableGetter = (variable, fn) => () => { diff --git a/src/utils/logger.js b/src/utils/logger.js index 2f6352c124..7ae54b2502 100644 --- a/src/utils/logger.js +++ b/src/utils/logger.js @@ -5,7 +5,7 @@ import arrayIncludes from 'core-js-pure/stable/array/includes'; import { Logger, LOG_LEVEL } from '@krakenjs/beaver-logger/src'; import { ZalgoPromise } from '@krakenjs/zalgo-promise/src'; -import { getGlobalAPIUrl } from './global'; +import { getGlobalUrl } from './global'; import { request } from './miscellaneous'; import { getLibraryVersion, getDisableSetCookie } from './sdk'; @@ -105,7 +105,7 @@ function generateLogPayload(account, { meta, events: bizEvents, tracking }) { /** * Translate the meta, events, and tracking into payloads for the - * endpoint `/v1/credit/upstream-messaging-events` + * endpoint `/credit-presentment/glog` * @param {Object} data - the data the logger wishes to send * @param {Object} data.meta - the data the logger wishes to send * @param {Object[]} data.events - the data captured by logger.{debug|info|warn|error} calls @@ -130,7 +130,7 @@ function translateLogData({ meta, events, tracking }) { export const logger = Logger({ // Url to send logs to - url: getGlobalAPIUrl('LOGGER'), + url: getGlobalUrl('LOGGER'), // Prefix to prepend to all events prefix: 'paypal_messages', // Log level to display in the browser console diff --git a/src/utils/sdk.js b/src/utils/sdk.js index d58fd5d099..4f798167c3 100644 --- a/src/utils/sdk.js +++ b/src/utils/sdk.js @@ -210,51 +210,6 @@ export const isScriptBeingDestroyed = () => { } }; -export function getPayPalAPIDomain() { - if (getEnv() !== 'production' && getEnv() !== 'sandbox') { - const testEnviroment = window.__TEST_ENV__ ?? __MESSAGES__.__TEST_ENV__; - - if (testEnviroment) { - try { - const url = new URL(testEnviroment); - - // Check if the hostname starts with 'www.' and replace it with 'api.' - if (url.hostname.startsWith('www.')) { - url.hostname = url.hostname.replace('www.', 'api.'); - } else { - // If 'www' is not part of the domain, prepend 'api.' directly - url.hostname = `api.${url.hostname}`; - } - return url.pathname === '/' && !url.search ? url.origin : url.href; - } catch (error) { - return testEnviroment; - } - } - - // eslint-disable-next-line security/detect-unsafe-regex - if (window.location.origin.match(/\.paypal\.com(:\d+)?$/)) { - return window.location.origin; - } - } - - // Not using `getPayPalAPIDomain` function call here because it outputs 'cors.api.paypal.com' - // The domain with prefixed 'cors' does not route to logging application. - if (__MESSAGES__.__TARGET__ === 'SDK') { - if (getEnv() === 'sandbox') { - return 'https://api.sandbox.paypal.com'; - } - return 'https://api.paypal.com'; - } else { - const domain = __MESSAGES__.__API_DOMAIN__[`__${getEnv().toUpperCase()}__`]; - - if (domain) { - return domain; - } - - throw new Error('Missing PayPal Domain'); - } -} - export function getPayPalDomain() { if (getEnv() !== 'production' && getEnv() !== 'sandbox') { const testEnviroment = window.__TEST_ENV__ ?? __MESSAGES__.__TEST_ENV__; diff --git a/tests/functional/spec/non-snapshot-tests/payload.test.js b/tests/functional/spec/non-snapshot-tests/payload.test.js index 2753ed5759..0af4e649fd 100644 --- a/tests/functional/spec/non-snapshot-tests/payload.test.js +++ b/tests/functional/spec/non-snapshot-tests/payload.test.js @@ -10,7 +10,7 @@ const createSpy = async () => { page.on('request', request => { const url = request.url(); const postDataString = request.postData(); - if (url.includes('upstream-messaging-events') && postDataString) { + if (url.includes('glog') && postDataString) { const postData = JSON.parse(postDataString); const events = postData.data?.components.reduce((acc, component) => { diff --git a/tests/unit/spec/src/utils/sdk.test.js b/tests/unit/spec/src/utils/sdk.test.js index 17e70370d2..9b276365e0 100644 --- a/tests/unit/spec/src/utils/sdk.test.js +++ b/tests/unit/spec/src/utils/sdk.test.js @@ -1,4 +1,4 @@ -import { getPayPalDomain, getPayPalAPIDomain, getDevTouchpoint, getFeatures } from '../../../../../src/utils/sdk'; +import { getPayPalDomain, getDevTouchpoint, getFeatures } from '../../../../../src/utils/sdk'; describe('getPayPalDomain', () => { beforeEach(() => { @@ -36,42 +36,6 @@ describe('getPayPalDomain', () => { }); }); -describe('getPayPalAPIDomain', () => { - beforeEach(() => { - // reset test variables - window.__TEST_ENV__ = undefined; - __ENV__ = 'stage'; - __MESSAGES__ = { - __TEST_ENV__: undefined, - __API_DOMAIN__: { __SANDBOX__: 'https://api.sandbox.com' } - }; - }); - test('returns message test environment if window test environment is not set', () => { - __MESSAGES__.__TEST_ENV__ = 'https://www.test-env.com'; - expect(getPayPalAPIDomain()).toBe('https://api.test-env.com'); - }); - test('returns window test environment if it is set', () => { - __MESSAGES__.__TEST_ENV__ = 'https://www.test-env.com'; - window.__TEST_ENV__ = 'https://www.window-test-env.com'; - expect(getPayPalAPIDomain()).toBe('https://api.window-test-env.com'); - }); - test('returns sandbox domain if no test environment is set and env is sandbox', () => { - __MESSAGES__.__TEST_ENV__ = 'https://www.test-env.com'; - window.__TEST_ENV__ = 'https://www.window-test-env.com'; - __ENV__ = 'sandbox'; - expect(getPayPalAPIDomain()).toBe('https://api.sandbox.com'); - }); - test('returns error if no test environment is set', () => { - expect(() => getPayPalAPIDomain()).toThrow(Error); - }); - test('returns stage domain if set via window test env global and env is stage', () => { - __MESSAGES__.__TEST_ENV__ = 'https://www.stage.com'; - window.__TEST_ENV__ = 'https://www.stage.com'; - __ENV__ = 'stage'; - expect(getPayPalAPIDomain()).toBe('https://api.stage.com'); - }); -}); - describe('getDevTouchpoint', () => { beforeEach(() => { // reset test variables diff --git a/tests/unit/utils/setup.js b/tests/unit/utils/setup.js index 0fccf73eef..9b3d90bd2f 100644 --- a/tests/unit/utils/setup.js +++ b/tests/unit/utils/setup.js @@ -7,7 +7,6 @@ const standaloneGlobals = globals({ }); standaloneGlobals.__MESSAGES__.__DOMAIN__.__TEST__ = 'http://localhost.paypal.com:8080'; -standaloneGlobals.__MESSAGES__.__API_DOMAIN__.__TEST__ = 'http://localhost.paypal.com:8080'; Object.assign(window, { __ENV__: 'test', diff --git a/utils/devServerProxy/proxy.js b/utils/devServerProxy/proxy.js index 9ea35d84f7..448e5faf09 100644 --- a/utils/devServerProxy/proxy.js +++ b/utils/devServerProxy/proxy.js @@ -5,7 +5,7 @@ export default (app, server, compiler) => { createMessageRoutes(app, server, compiler); createModalRoutes(app, server, compiler); - app.post('/v1/credit/upstream-messaging-events', (req, res) => res.send('')); + app.post('/credit-presentment/glog', (req, res) => res.send('')); app.get('/credit-presentment/experiments/hash', (req, res) => res.send('1daf92517fb7620b02add6943517ae0a5ca8f0a0'));