Skip to content

Commit

Permalink
MWPW-156672: refactor commerce & optimize pandora dependencies (adobe…
Browse files Browse the repository at this point in the history
…com#2723)

* add sitemap

* remove pandora wcs client

* remove obsolete dependencies

* fix request&settings test

* remove domainSwitch

* fix tests

* update deps

* fix review comment

* use usual error message

* fix language param

* commit packag-lock

* bring back transitive dependencies

* bring back www.stage.adobe.com

* omit cookies for wcs requests

* revert special logic for stage
  • Loading branch information
3ch023 authored Sep 2, 2024
1 parent 1c4001b commit 5417762
Show file tree
Hide file tree
Showing 23 changed files with 295 additions and 488 deletions.
6 changes: 0 additions & 6 deletions libs/deps/commerce.js

This file was deleted.

4 changes: 2 additions & 2 deletions libs/deps/mas/commerce.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions libs/deps/mas/mas.js

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 3 additions & 10 deletions libs/features/mas/commerce/libs/commerce.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import {
CheckoutType,
WorkflowStep,
} from '@pandora/commerce-checkout-url-builder';
import {
ProviderEnvironment,
Landscape,
Environment,
} from '@pandora/data-source-utils';
import {
PriceDetails,
ResolvedOffer,
Expand Down Expand Up @@ -131,8 +126,8 @@ declare global {

interface Settings {
country: string;
env: ProviderEnvironment;
landscape: Landscape;
env: string;
landscape: string;
// TODO: ideally, this setting should be processed by price template and belong to price settings
forceTaxExclusive: boolean;
language: string;
Expand Down Expand Up @@ -334,7 +329,6 @@ declare global {
checkoutWorkflow: CheckoutType;
checkoutWorkflowStep: WorkflowStep;
entitlement: boolean;
upgrade: boolean;
modal: boolean;
extraOptions: Partial<Record<keyof CheckoutLinkParameter, any>>;
}
Expand Down Expand Up @@ -575,8 +569,7 @@ declare global {
wcsApiKey: string;
wcsBufferDelay: number;
wcsBufferLimit: number;
wcsEnv: Environment;
domainSwitch: boolean;
wcsURL: string;
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions libs/features/mas/commerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"types": "src/index.d.ts",
"sideEffects": false,
"scripts": {
"build": "npm run build:bundle && npm run build:types",
"build": "npm run test:ci && npm run build:bundle && npm run build:types",
"build:bundle": "node ./build.mjs",
"build:types": "cp ./src/index.d.ts ./libs/commerce.d.ts",
"build:watch": "npm run build:bundle --watch",
Expand All @@ -20,16 +20,11 @@
},
"dependencies": {
"@dexter/tacocat-consonant-templates": "file:./internal/tacocat-consonant-templates-1.13.0.tgz",
"@dexter/tacocat-core": "file:./internal/tacocat-core-1.12.2.tgz",
"@dexter/tacocat-wcs-client": "file:./internal/tacocat-wcs-client-1.17.0.tgz",
"@dexter/tacocat-core": "file:./internal/tacocat-core-1.13.0.tgz",
"@pandora/commerce-checkout-url-builder": "file:./internal/commerce-checkout-url-builder-1.6.0.tgz",
"@pandora/data-models-odm": "file:./internal/data-models-odm-0.5.4.tgz",
"@pandora/data-source-wcs": "file:./internal/data-source-wcs-0.2.8.tgz",
"@pandora/data-source-utils": "file:./internal/data-source-utils-0.3.1.tgz",
"@pandora/fetch": "file:./internal/fetch-1.3.4.tgz",
"@pandora/react-auth-provider": "file:./internal/react-auth-provider-1.2.1.tgz",
"@pandora/react-env-provider": "file:./internal/react-env-provider-1.2.2.tgz",
"@pandora/react-fetch-provider": "file:./internal/react-fetch-provider-1.2.2.tgz",
"@pandora/logger": "file:./internal/logger-1.3.0.tgz"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions libs/features/mas/commerce/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ export const PARAM_LANDSCAPE = 'commerce.landscape';
export const PARAM_AOS_API_KEY = 'commerce.aosKey';
export const PARAM_WCS_API_KEY = 'commerce.wcsKey';

export const WCS_PROD_URL = 'https://www.adobe.com/web_commerce_artifact';
export const WCS_STAGE_URL = 'https://www.stage.adobe.com/web_commerce_artifact_stage';

export const STATE_FAILED = 'failed';
export const STATE_PENDING = 'pending';
export const STATE_RESOLVED = 'resolved';

export const TAG_NAME_SERVICE = 'wcms-commerce';

export const Landscape = {
DRAFT: "DRAFT",
PUBLISHED: "PUBLISHED"
}
6 changes: 2 additions & 4 deletions libs/features/mas/commerce/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import {
CheckoutWorkflow,
CheckoutWorkflowStep,
Env,
Landscape,
WcsEnv,
} from './external.js';
import { Landscape } from './constants.js';

/** @type {Commerce.Defaults} */
export const Defaults = Object.freeze({
Expand All @@ -16,7 +15,6 @@ export const Defaults = Object.freeze({
displayPerUnit: false,
displayRecurrence: true,
displayTax: false,
domainSwitch: false,
env: Env.PRODUCTION,
forceTaxExclusive: false,
language: 'en',
Expand All @@ -27,7 +25,7 @@ export const Defaults = Object.freeze({
quantity: 1,
wcsApiKey: 'wcms-commerce-ims-ro-user-milo',
wcsBufferDelay: 1,
wcsEnv: WcsEnv.PRODUCTION,
wcsURL: 'https://www.adobe.com/web_commerce_artifact',
landscape: Landscape.PUBLISHED,
wcsBufferLimit: 1,
});
22 changes: 6 additions & 16 deletions libs/features/mas/commerce/src/external.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import {
buildCheckoutUrl,
} from '@pandora/commerce-checkout-url-builder';
import { Term, Commitment } from '@pandora/data-models-odm';
import {
Environment,
Landscape,
ProviderEnvironment,
} from '@pandora/data-source-utils';
import { webCommerceArtifact } from '@pandora/data-source-wcs';

import {
price,
Expand All @@ -33,25 +27,25 @@ import {
omitProperties,
toBoolean,
toEnumeration,
toKebabCase,
toPositiveFiniteInteger,
} from '@dexter/tacocat-core';
import {
applyPlanType,
forceTaxExclusivePrice,
PlanType,
} from '@dexter/tacocat-wcs-client';
} from '@dexter/tacocat-core';

const { freeze } = Object;

/** @type {Commerce.Checkout.CheckoutWorkflow} */
const CheckoutWorkflow = freeze({ ...CheckoutType });
/** @type {Commerce.Checkout.CheckoutWorkflowStep} */
const CheckoutWorkflowStep = freeze({ ...WorkflowStep });
const Env = freeze({ ...ProviderEnvironment });
const Env = {
STAGE: "STAGE",
PRODUCTION: "PRODUCTION",
LOCAL: "LOCAL"
};
/** @type {Commerce.Wcs.WcsCommitment} */
const WcsCommitment = freeze({ ...Commitment });
const WcsEnv = freeze({ ...Environment });
/** @type {Commerce.Wcs.WcsPlanType} */
const WcsPlanType = freeze({ ...PlanType });
/** @type {Commerce.Wcs.WcsTerm} */
Expand All @@ -62,8 +56,6 @@ export {
CheckoutWorkflowStep,
Env,
WcsCommitment,
WcsEnv,
Landscape,
WcsTerm,
WcsPlanType,
applyPlanType,
Expand All @@ -87,7 +79,5 @@ export {
discount,
toBoolean,
toEnumeration,
toKebabCase,
toPositiveFiniteInteger,
webCommerceArtifact,
};
13 changes: 3 additions & 10 deletions libs/features/mas/commerce/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import {
CheckoutType,
WorkflowStep,
} from '@pandora/commerce-checkout-url-builder';
import {
ProviderEnvironment,
Landscape,
Environment,
} from '@pandora/data-source-utils';
import {
PriceDetails,
ResolvedOffer,
Expand Down Expand Up @@ -131,8 +126,8 @@ declare global {

interface Settings {
country: string;
env: ProviderEnvironment;
landscape: Landscape;
env: string;
landscape: string;
// TODO: ideally, this setting should be processed by price template and belong to price settings
forceTaxExclusive: boolean;
language: string;
Expand Down Expand Up @@ -334,7 +329,6 @@ declare global {
checkoutWorkflow: CheckoutType;
checkoutWorkflowStep: WorkflowStep;
entitlement: boolean;
upgrade: boolean;
modal: boolean;
extraOptions: Partial<Record<keyof CheckoutLinkParameter, any>>;
}
Expand Down Expand Up @@ -575,8 +569,7 @@ declare global {
wcsApiKey: string;
wcsBufferDelay: number;
wcsBufferLimit: number;
wcsEnv: Environment;
domainSwitch: boolean;
wcsURL: string;
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions libs/features/mas/commerce/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { CheckoutLink } from './checkout-link.js';
import { TAG_NAME_SERVICE } from './constants.js';
import { TAG_NAME_SERVICE, Landscape } from './constants.js';
import { Defaults } from './defaults.js';
import {
CheckoutWorkflow,
CheckoutWorkflowStep,
WcsCommitment,
WcsEnv,
Landscape,
WcsTerm,
WcsPlanType,
applyPlanType,
Expand All @@ -25,7 +23,6 @@ export {
InlinePrice,
Log,
WcsCommitment,
WcsEnv,
Landscape,
WcsTerm,
WcsPlanType,
Expand Down
27 changes: 12 additions & 15 deletions libs/features/mas/commerce/src/settings.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { PARAM_ENV, PARAM_LANDSCAPE } from './constants.js';
import { PARAM_ENV, PARAM_LANDSCAPE, Landscape, WCS_PROD_URL, WCS_STAGE_URL } from './constants.js';
import { Defaults } from './defaults.js';
import {
CheckoutWorkflow,
CheckoutWorkflowStep,
Env,
WcsEnv,
Landscape,
getParameter,
toBoolean,
toEnumeration,
Expand Down Expand Up @@ -135,15 +133,16 @@ function getSettings(config = {}) {
// TODO: add alias names for meta, search and storage
// See https://git.corp.adobe.com/wcms/tacocat.js/pull/348#discussion_r6557570
const { commerce = {}, locale = undefined } = config;
const hostEnv =
config.env?.name === HostEnv.PROD
? HostEnv.PROD
: toEnumeration(
getParameter(PARAM_ENV, commerce, { metadata: false }),
HostEnv,
HostEnv.PROD,
);
const env = hostEnv === HostEnv.STAGE ? Env.STAGE : Env.PRODUCTION;
let env = Env.PRODUCTION;
let wcsURL = WCS_PROD_URL;

const lowHostEnv = ['local', 'stage'].includes(config.env?.name);
const forceWcsStage = getParameter(PARAM_ENV, commerce, { metadata: false })?.toLowerCase() === 'stage';
if (lowHostEnv && forceWcsStage) {
env = Env.STAGE;
wcsURL = WCS_STAGE_URL;
}

const checkoutClientId =
getParameter('checkoutClientId', commerce) ?? Defaults.checkoutClientId;
const checkoutWorkflow = toEnumeration(
Expand Down Expand Up @@ -204,7 +203,6 @@ function getSettings(config = {}) {
getParameter('wcsBufferLimit', commerce),
Defaults.wcsBufferLimit,
);
const domainSwitch = toBoolean(getParameter('domain.switch', commerce), false);

return {
...getLocaleSettings({ locale }),
Expand All @@ -227,9 +225,8 @@ function getSettings(config = {}) {
wcsApiKey,
wcsBufferDelay,
wcsBufferLimit,
wcsEnv: env === Env.STAGE ? WcsEnv.STAGE : WcsEnv.PRODUCTION,
wcsURL,
landscape,
domainSwitch,
};
}

Expand Down
Loading

0 comments on commit 5417762

Please sign in to comment.