Skip to content

Commit

Permalink
chore: cut release (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seavenly authored Aug 20, 2024
2 parents 96b5987 + cd05411 commit cecb69c
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 107 deletions.
8 changes: 1 addition & 7 deletions globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'
}
}
Expand Down
13 changes: 1 addition & 12 deletions src/utils/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
getPageType,
getPartnerAccount,
getPayPalDomain,
getScript,
getPayPalAPIDomain
getScript
} from './sdk';
import { createState } from './miscellaneous';
import { ppDebug } from './debug';
Expand Down Expand Up @@ -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) => () => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
45 changes: 0 additions & 45 deletions src/utils/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/spec/non-snapshot-tests/payload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
38 changes: 1 addition & 37 deletions tests/unit/spec/src/utils/sdk.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPayPalDomain, getPayPalAPIDomain, getDevTouchpoint, getFeatures } from '../../../../../src/utils/sdk';
import { getPayPalDomain, getDevTouchpoint, getFeatures } from '../../../../../src/utils/sdk';

describe('getPayPalDomain', () => {
beforeEach(() => {
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/unit/utils/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion utils/devServerProxy/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down

0 comments on commit cecb69c

Please sign in to comment.