Skip to content

Commit 5197314

Browse files
authored
Merge pull request #2563 from bigcommerce/lazy_strategies
CHECKOUT-9388: Lazy load payment strategies by importing them on demand
2 parents a827341 + 829a258 commit 5197314

File tree

103 files changed

+482
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+482
-59
lines changed

.eslintrc.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@
8484
"fixStyle": "inline-type-imports",
8585
"disallowTypeAnnotations": false
8686
}
87+
],
88+
"@typescript-eslint/no-restricted-imports": [
89+
"error",
90+
{
91+
"paths": [
92+
{
93+
"name": "@bigcommerce/checkout-sdk",
94+
"message": "Direct imports from '@bigcommerce/checkout-sdk' are not allowed. Use type-only imports (import type { ... }) or import from subpaths like '@bigcommerce/checkout-sdk/essential' or '@bigcommerce/checkout-sdk/integrations'.",
95+
"allowTypeImports": true
96+
}
97+
]
98+
}
8799
]
88100
}
89101
},
@@ -138,7 +150,17 @@
138150
"plugin:jest-dom/recommended"
139151
],
140152
"rules": {
141-
"@typescript-eslint/consistent-type-assertions": "off"
153+
"@typescript-eslint/consistent-type-assertions": "off",
154+
"@typescript-eslint/no-restricted-imports": "off"
155+
}
156+
},
157+
{
158+
"files": [
159+
"*.mock.ts",
160+
"*.mock.tsx"
161+
],
162+
"rules": {
163+
"@typescript-eslint/no-restricted-imports": "off"
142164
}
143165
}
144166
]

packages/adyen-integration/src/adyenv2/AdyenV2PaymentMethod.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type PaymentInitializeOptions,
77
type PaymentMethod,
88
} from '@bigcommerce/checkout-sdk';
9+
import { createAdyenV2PaymentStrategy } from '@bigcommerce/checkout-sdk/integrations/adyen';
910
import { act, fireEvent, render, screen } from '@testing-library/react';
1011
import { Formik } from 'formik';
1112
import { noop } from 'lodash';
@@ -98,6 +99,7 @@ describe('when using Adyen V2 payment', () => {
9899

99100
expect(initializePayment).toHaveBeenCalledWith(
100101
expect.objectContaining({
102+
integrations: [createAdyenV2PaymentStrategy],
101103
adyenv2: {
102104
additionalActionOptions: {
103105
containerId: 'adyen-scheme-additional-action-component-field',

packages/adyen-integration/src/adyenv2/AdyenV2PaymentMethod.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type CardInstrument,
66
type PaymentInitializeOptions,
77
} from '@bigcommerce/checkout-sdk';
8+
import { createAdyenV2PaymentStrategy } from '@bigcommerce/checkout-sdk/integrations/adyen';
89
import React, { type FunctionComponent, useCallback, useRef, useState } from 'react';
910

1011
import { type HostedWidgetComponentProps } from '@bigcommerce/checkout/hosted-widget-integration';
@@ -107,6 +108,7 @@ const AdyenV2PaymentMethod: FunctionComponent<PaymentMethodProps> = ({
107108

108109
return checkoutService.initializePayment({
109110
...options,
111+
integrations: [createAdyenV2PaymentStrategy],
110112
adyenv2: {
111113
cardVerificationContainerId:
112114
selectedInstrumentId && cardVerificationContainerId,

packages/adyen-integration/src/adyenv3/AdyenV3PaymentMethod.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type PaymentInitializeOptions,
77
type PaymentMethod,
88
} from '@bigcommerce/checkout-sdk';
9+
import { createAdyenV3PaymentStrategy } from '@bigcommerce/checkout-sdk/integrations/adyen';
910
import { act, fireEvent, render, screen } from '@testing-library/react';
1011
import { Formik } from 'formik';
1112
import { noop } from 'lodash';
@@ -95,6 +96,7 @@ describe('when using AdyenV3 payment', () => {
9596

9697
expect(initializePayment).toHaveBeenCalledWith(
9798
expect.objectContaining({
99+
integrations: [createAdyenV3PaymentStrategy],
98100
adyenv3: {
99101
cardVerificationContainerId: undefined,
100102
containerId: 'adyen-scheme-component-field',

packages/adyen-integration/src/adyenv3/AdyenV3PaymentMethod.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type CardInstrument,
55
type PaymentInitializeOptions,
66
} from '@bigcommerce/checkout-sdk';
7+
import { createAdyenV3PaymentStrategy } from '@bigcommerce/checkout-sdk/integrations/adyen';
78
import React, { type FunctionComponent, useCallback, useRef, useState } from 'react';
89

910
import { type HostedWidgetComponentProps } from '@bigcommerce/checkout/hosted-widget-integration';
@@ -105,6 +106,7 @@ const AdyenV3PaymentMethod: FunctionComponent<PaymentMethodProps> = ({
105106

106107
return checkoutService.initializePayment({
107108
...options,
109+
integrations: [createAdyenV3PaymentStrategy],
108110
adyenv3: {
109111
cardVerificationContainerId:
110112
selectedInstrumentId && cardVerificationContainerId,

packages/affirm-integration/src/AffirmPaymentMethod.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React, { type FunctionComponent, useMemo } from 'react';
1+
import { type PaymentInitializeOptions } from '@bigcommerce/checkout-sdk';
2+
import { createAffirmPaymentStrategy } from '@bigcommerce/checkout-sdk/integrations/affirm';
3+
import React, { type FunctionComponent, useCallback, useMemo } from 'react';
24

35
import { HostedPaymentComponent } from '@bigcommerce/checkout/hosted-payment-integration';
46
import { TranslatedString } from '@bigcommerce/checkout/locale';
@@ -14,13 +16,23 @@ const AffirmPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
1416
}) => {
1517
const description = useMemo(() => <TranslatedString id="payment.affirm_body_text" />, []);
1618

19+
const initializeAffirmPayment = useCallback(
20+
(options: PaymentInitializeOptions) => {
21+
return checkoutService.initializePayment({
22+
...options,
23+
integrations: [createAffirmPaymentStrategy],
24+
});
25+
},
26+
[checkoutService],
27+
);
28+
1729
return (
1830
<HostedPaymentComponent
1931
{...rest}
2032
checkoutService={checkoutService}
2133
deinitializePayment={checkoutService.deinitializePayment}
2234
description={description}
23-
initializePayment={checkoutService.initializePayment}
35+
initializePayment={initializeAffirmPayment}
2436
/>
2537
);
2638
};

packages/amazon-pay-v2-integration/src/AmazonPayV2PaymentMethod.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type PaymentInitializeOptions,
77
type PaymentMethod,
88
} from '@bigcommerce/checkout-sdk';
9+
import { createAmazonPayV2PaymentStrategy } from '@bigcommerce/checkout-sdk/integrations/amazon-pay';
910
import { render } from '@testing-library/react';
1011
import { Formik } from 'formik';
1112
import { noop } from 'lodash';
@@ -90,6 +91,7 @@ describe('when using AmazonPay payment', () => {
9091
expect.objectContaining({
9192
gatewayId: method.gateway,
9293
methodId: 'amazonpay',
94+
integrations: [createAmazonPayV2PaymentStrategy],
9395
amazonpay: {
9496
editButtonId: 'editButtonId',
9597
},
@@ -106,6 +108,7 @@ describe('when using AmazonPay payment', () => {
106108
expect.objectContaining({
107109
methodId: method.id,
108110
gatewayId: method.gateway,
111+
integrations: [createAmazonPayV2PaymentStrategy],
109112
[method.id]: {
110113
editButtonId: 'editButtonId',
111114
},

packages/amazon-pay-v2-integration/src/AmazonPayV2PaymentMethod.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type PaymentInitializeOptions } from '@bigcommerce/checkout-sdk';
2+
import { createAmazonPayV2PaymentStrategy } from '@bigcommerce/checkout-sdk/integrations/amazon-pay';
23
import { some } from 'lodash';
34
import React, { type FunctionComponent, useCallback } from 'react';
45

@@ -27,6 +28,7 @@ const AmazonPayV2PaymentMethod: FunctionComponent<PaymentMethodProps> = ({
2728
(options: PaymentInitializeOptions) =>
2829
checkoutService.initializePayment({
2930
...options,
31+
integrations: [createAmazonPayV2PaymentStrategy],
3032
amazonpay: {
3133
editButtonId: 'editButtonId',
3234
},

packages/analytics/src/AnalyticsProvider.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as CheckoutSdk from '@bigcommerce/checkout-sdk';
1+
import * as CheckoutSdk from '@bigcommerce/checkout-sdk/essential';
22
import { render } from '@testing-library/react';
33
import React, { useEffect } from 'react';
44

@@ -8,12 +8,12 @@ import AnalyticsProvider from './AnalyticsProvider';
88
import * as createAnalyticsService from './createAnalyticsService';
99
import useAnalytics from './useAnalytics';
1010

11-
jest.mock('@bigcommerce/checkout-sdk', () => {
11+
jest.mock('@bigcommerce/checkout-sdk/essential', () => {
1212
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
1313
return {
1414
// eslint-disable-next-line @typescript-eslint/naming-convention
1515
__esModule: true,
16-
...jest.requireActual('@bigcommerce/checkout-sdk'),
16+
...jest.requireActual('@bigcommerce/checkout-sdk/essential'),
1717
};
1818
});
1919

packages/analytics/src/AnalyticsProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
createStepTracker,
1010
type PayPalCommerceAnalyticTrackerService,
1111
type StepTracker,
12-
} from '@bigcommerce/checkout-sdk';
12+
} from '@bigcommerce/checkout-sdk/essential';
1313
import React, { type ReactNode, useMemo } from 'react';
1414

1515
import AnalyticsContext, { type AnalyticsEvents } from './AnalyticsContext';

0 commit comments

Comments
 (0)