Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-156672: refactor commerce & optimize pandora dependencies #2723

Merged
merged 17 commits into from
Sep 2, 2024
Merged
4 changes: 2 additions & 2 deletions libs/deps/mas/commerce.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Large diffs are not rendered by default.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions libs/deps/mas/merch-card.js

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed libs/features/mas/commerce/internal/fetch-1.3.4.tgz
Binary file not shown.
Binary file removed libs/features/mas/commerce/internal/logger-1.3.0.tgz
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {

Check warning on line 1 in libs/features/mas/commerce/libs/commerce.d.ts

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 File ignored because of a matching ignore pattern. Use "--no-ignore" to override. Raw Output: {"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}
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 @@

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 @@
checkoutWorkflow: CheckoutType;
checkoutWorkflowStep: WorkflowStep;
entitlement: boolean;
upgrade: boolean;
modal: boolean;
extraOptions: Partial<Record<keyof CheckoutLinkParameter, any>>;
}
Expand Down Expand Up @@ -575,8 +569,7 @@
wcsApiKey: string;
wcsBufferDelay: number;
wcsBufferLimit: number;
wcsEnv: Environment;
domainSwitch: boolean;
wcsURL: string;
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions libs/features/mas/commerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,9 @@
},
"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"
"@pandora/data-models-odm": "file:./internal/data-models-odm-0.5.4.tgz"
},
"devDependencies": {
"@web/dev-server-import-maps": "^0.1.1",
Expand Down
5 changes: 5 additions & 0 deletions libs/features/mas/commerce/src/constants.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const CLASS_NAME_FAILED = 'placeholder-failed';

Check warning on line 1 in libs/features/mas/commerce/src/constants.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 File ignored because of a matching ignore pattern. Use "--no-ignore" to override. Raw Output: {"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}
export const CLASS_NAME_PENDING = 'placeholder-pending';
export const CLASS_NAME_RESOLVED = 'placeholder-resolved';

Expand All @@ -24,3 +24,8 @@
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {

Check warning on line 1 in libs/features/mas/commerce/src/defaults.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 File ignored because of a matching ignore pattern. Use "--no-ignore" to override. Raw Output: {"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}
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 @@
displayPerUnit: false,
displayRecurrence: true,
displayTax: false,
domainSwitch: false,
env: Env.PRODUCTION,
forceTaxExclusive: false,
language: 'en',
Expand All @@ -27,7 +25,7 @@
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
// This file aliases and re-exports commonly used external dependencies

Check warning on line 1 in libs/features/mas/commerce/src/external.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 File ignored because of a matching ignore pattern. Use "--no-ignore" to override. Raw Output: {"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}
import {
CheckoutType,
WorkflowStep,
buildCheckoutUrl,
} from '@pandora/commerce-checkout-url-builder';
import { Term, Commitment } from '@pandora/data-models-odm';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need these imports/we can replace them, I propose to remove them as well.

import {
Environment,
Landscape,
ProviderEnvironment,
} from '@pandora/data-source-utils';
import { webCommerceArtifact } from '@pandora/data-source-wcs';

import {
price,
Expand All @@ -33,25 +27,25 @@
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 @@
CheckoutWorkflowStep,
Env,
WcsCommitment,
WcsEnv,
Landscape,
WcsTerm,
WcsPlanType,
applyPlanType,
Expand All @@ -87,7 +79,5 @@
discount,
toBoolean,
toEnumeration,
toKebabCase,
toPositiveFiniteInteger,
webCommerceArtifact,
};
13 changes: 3 additions & 10 deletions libs/features/mas/commerce/src/index.d.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {

Check warning on line 1 in libs/features/mas/commerce/src/index.d.ts

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 File ignored because of a matching ignore pattern. Use "--no-ignore" to override. Raw Output: {"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}
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 @@

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 @@
checkoutWorkflow: CheckoutType;
checkoutWorkflowStep: WorkflowStep;
entitlement: boolean;
upgrade: boolean;
modal: boolean;
extraOptions: Partial<Record<keyof CheckoutLinkParameter, any>>;
}
Expand Down Expand Up @@ -575,8 +569,7 @@
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { CheckoutLink } from './checkout-link.js';

Check warning on line 1 in libs/features/mas/commerce/src/index.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 File ignored because of a matching ignore pattern. Use "--no-ignore" to override. Raw Output: {"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}
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 @@
InlinePrice,
Log,
WcsCommitment,
WcsEnv,
Landscape,
WcsTerm,
WcsPlanType,
Expand Down
29 changes: 14 additions & 15 deletions libs/features/mas/commerce/src/settings.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

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 } from './constants.js';

Check warning on line 1 in libs/features/mas/commerce/src/settings.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 File ignored because of a matching ignore pattern. Use "--no-ignore" to override. Raw Output: {"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}
import { Defaults } from './defaults.js';
import {
CheckoutWorkflow,
CheckoutWorkflowStep,
Env,
WcsEnv,
Landscape,
getParameter,
toBoolean,
toEnumeration,
Expand Down Expand Up @@ -135,15 +133,18 @@
// 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;
const lowHostEnv = ['local', 'stage'].includes(config.env?.name);
let env = Env.PRODUCTION;
let wcsURL = 'https://www.adobe.com/web_commerce_artifact';
if (lowHostEnv) {
wcsURL = 'https://www.stage.adobe.com/web_commerce_artifact';
3ch023 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe string repetition could be avoided by determining the environment and then using a template literal to form the URL? Or maybe even a simple replace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored a bit

const forceWcsStage = getParameter(PARAM_ENV, commerce, { metadata: false }) === 'stage';
if (forceWcsStage) {
env = Env.STAGE;
wcsURL = `${wcsURL}_stage`;
}
}

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

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

Expand Down
Loading
Loading