Skip to content

Commit 5fc19a8

Browse files
Restore async public API for 3.9
1 parent a349b97 commit 5fc19a8

10 files changed

Lines changed: 81 additions & 73 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ experiences.
6565

6666
## Platform Requirements
6767

68-
- **React Native** - Minimum version `0.76` (v4+) / `0.70` (v3 and earlier)
68+
- **React Native** - Minimum version `0.76` (`3.9.0+`) / `0.70` (`<=3.8.x`)
6969
- **iOS** - Minimum version iOS 13
7070
- **Android** - Minimum Java 11 & Android SDK version `23`
7171

7272
## Version Compatibility
7373

74-
Starting with **v4.0.0**, `@shopify/checkout-sheet-kit` requires the React Native
74+
Starting with **v3.9.0**, `@shopify/checkout-sheet-kit` requires the React Native
7575
**New Architecture** (TurboModules + Fabric). Apps on the old architecture must
76-
stay on the `v3.x` line until they migrate.
76+
stay on `v3.8.x` until they migrate.
7777

7878
| Package version | React Native | Architecture |
7979
| --------------- | -------------- | ------------------ |
80-
| `4.x` | `>= 0.76` | New Architecture |
81-
| `3.x` | `>= 0.70` | Old Architecture |
80+
| `3.9.x` | `>= 0.76` | New Architecture |
81+
| `<=3.8.x` | `>= 0.70` | Old Architecture |
8282

8383
See the [React Native upgrade guide](https://reactnative.dev/docs/the-new-architecture/use-the-new-architecture)
8484
for help enabling the New Architecture in your app.

modules/@shopify/checkout-sheet-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@shopify/checkout-sheet-kit",
33
"license": "MIT",
4-
"version": "4.0.0",
4+
"version": "3.9.0",
55
"main": "lib/commonjs/index.js",
66
"types": "src/index.ts",
77
"source": "src/index.ts",

modules/@shopify/checkout-sheet-kit/src/context.tsx

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type Maybe<T> = T | undefined;
3838
interface Context {
3939
acceleratedCheckoutsAvailable: boolean;
4040
addEventListener: AddEventListener;
41-
getConfig: () => Configuration | undefined;
42-
setConfig: (config: Configuration) => void;
41+
getConfig: () => Promise<Configuration | undefined>;
42+
setConfig: (config: Configuration) => Promise<void>;
4343
removeEventListeners: RemoveEventListeners;
4444
preload: (checkoutUrl: string) => void;
4545
present: (checkoutUrl: string) => void;
@@ -71,24 +71,28 @@ export function ShopifyCheckoutSheetProvider({
7171
}
7272

7373
useEffect(() => {
74-
if (!instance.current || !configuration) {
75-
return;
76-
}
77-
78-
const customer = configuration.acceleratedCheckouts?.customer;
79-
if (customer?.accessToken && (customer?.email || customer?.phoneNumber)) {
80-
// eslint-disable-next-line no-console
81-
console.warn(
82-
'[ShopifyCheckoutSheetKit] Providing accessToken with contactFields (email / phoneNumber) is deprecated and will become an error in v4.' +
83-
'When the user is authenticated with Customer Accounts, provide accessToken' +
84-
'When the user is otherwise authenticated, provide email/phoneNumber.',
74+
async function configureCheckoutKit() {
75+
if (!instance.current || !configuration) {
76+
return;
77+
}
78+
79+
const customer = configuration.acceleratedCheckouts?.customer;
80+
if (customer?.accessToken && (customer?.email || customer?.phoneNumber)) {
81+
// eslint-disable-next-line no-console
82+
console.warn(
83+
'[ShopifyCheckoutSheetKit] Providing accessToken with contactFields (email / phoneNumber) is deprecated and will become an error in v4.' +
84+
'When the user is authenticated with Customer Accounts, provide accessToken' +
85+
'When the user is otherwise authenticated, provide email/phoneNumber.',
86+
);
87+
}
88+
89+
await instance.current.setConfig(configuration);
90+
setAcceleratedCheckoutsAvailable(
91+
instance.current.acceleratedCheckoutsReady,
8592
);
8693
}
8794

88-
instance.current.setConfig(configuration);
89-
setAcceleratedCheckoutsAvailable(
90-
instance.current.acceleratedCheckoutsReady,
91-
);
95+
configureCheckoutKit();
9296
}, [configuration]);
9397

9498
const addEventListener: AddEventListener = useCallback(
@@ -122,11 +126,11 @@ export function ShopifyCheckoutSheetProvider({
122126
instance.current?.dismiss();
123127
}, []);
124128

125-
const setConfig = useCallback((config: Configuration) => {
126-
instance.current?.setConfig(config);
129+
const setConfig = useCallback(async (config: Configuration) => {
130+
await instance.current?.setConfig(config);
127131
}, []);
128132

129-
const getConfig = useCallback(() => {
133+
const getConfig = useCallback(async () => {
130134
return instance.current?.getConfig();
131135
}, []);
132136

modules/@shopify/checkout-sheet-kit/src/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export interface ShopifyCheckoutSheetKit {
325325
/**
326326
* Return the current config for the checkout. See README.md for more details.
327327
*/
328-
getConfig(): Configuration;
328+
getConfig(): Promise<Configuration>;
329329
/**
330330
* Listen for checkout events
331331
*/
@@ -344,10 +344,10 @@ export interface ShopifyCheckoutSheetKit {
344344
*/
345345
configureAcceleratedCheckouts(
346346
config: AcceleratedCheckoutConfiguration,
347-
): boolean;
347+
): Promise<boolean>;
348348

349349
/**
350350
* Check if accelerated checkout is available for the given cart or product
351351
*/
352-
isAcceleratedCheckoutAvailable(): boolean;
352+
isAcceleratedCheckoutAvailable(): Promise<boolean>;
353353
}

modules/@shopify/checkout-sheet-kit/src/index.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,22 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
151151

152152
/**
153153
* Retrieves the current checkout configuration
154-
* @returns The current Configuration
154+
* @returns Promise containing the current Configuration
155155
*/
156-
public getConfig(): Configuration {
156+
public async getConfig(): Promise<Configuration> {
157157
return this.coerceConfigurationResult(RNShopifyCheckoutSheetKit.getConfig());
158158
}
159159

160160
/**
161161
* Updates the checkout configuration
162162
* @param configuration New configuration settings to apply
163163
*/
164-
public setConfig(configuration: Configuration): void {
164+
public async setConfig(configuration: Configuration): Promise<void> {
165165
if (configuration.acceleratedCheckouts) {
166-
this._acceleratedCheckoutsReady = this.configureAcceleratedCheckouts(
167-
configuration.acceleratedCheckouts,
168-
);
166+
this._acceleratedCheckoutsReady =
167+
await this.configureAcceleratedCheckouts(
168+
configuration.acceleratedCheckouts,
169+
);
169170
}
170171
RNShopifyCheckoutSheetKit.setConfig(configuration);
171172
}
@@ -233,9 +234,9 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
233234
* Configure AcceleratedCheckouts for Shop Pay and Apple Pay buttons
234235
* @param config Configuration for AcceleratedCheckouts
235236
*/
236-
public configureAcceleratedCheckouts(
237+
public async configureAcceleratedCheckouts(
237238
config: AcceleratedCheckoutConfiguration,
238-
): boolean {
239+
): Promise<boolean> {
239240
if (!this.acceleratedCheckoutsSupported) {
240241
return false;
241242
}
@@ -265,9 +266,9 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
265266

266267
/**
267268
* Check if accelerated checkout is available for the given cart or product
268-
* @returns boolean indicating availability
269+
* @returns Promise<boolean> indicating availability
269270
*/
270-
public isAcceleratedCheckoutAvailable(): boolean {
271+
public async isAcceleratedCheckoutAvailable(): Promise<boolean> {
271272
if (!this.acceleratedCheckoutsSupported) {
272273
return false;
273274
}

modules/@shopify/checkout-sheet-kit/tests/context.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ describe('useShopifyCheckoutSheet', () => {
348348
</Wrapper>,
349349
);
350350

351-
const config = hookValue.getConfig();
351+
const config = await hookValue.getConfig();
352352
expect(config).toEqual({
353353
preloading: true,
354354
colorScheme: 'automatic',

modules/@shopify/checkout-sheet-kit/tests/index.test.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ describe('ShopifyCheckoutSheetKit', () => {
160160
});
161161

162162
describe('getConfig', () => {
163-
it('returns the parsed config from the Native Module', () => {
163+
it('returns the parsed config from the Native Module', async () => {
164164
const instance = new ShopifyCheckoutSheet();
165-
expect(instance.getConfig()).toStrictEqual({
165+
await expect(instance.getConfig()).resolves.toStrictEqual({
166166
preloading: true,
167167
colorScheme: ColorScheme.automatic,
168168
logLevel: LogLevel.error,
@@ -732,7 +732,7 @@ describe('ShopifyCheckoutSheetKit', () => {
732732
NativeModule.configureAcceleratedCheckouts.mockReturnValue(true);
733733

734734
const result =
735-
instance.configureAcceleratedCheckouts(acceleratedConfig);
735+
await instance.configureAcceleratedCheckouts(acceleratedConfig);
736736

737737
expect(result).toBe(true);
738738
expect(
@@ -757,7 +757,7 @@ describe('ShopifyCheckoutSheetKit', () => {
757757
};
758758
NativeModule.configureAcceleratedCheckouts.mockReturnValue(true);
759759

760-
instance.configureAcceleratedCheckouts(minimalConfig);
760+
await instance.configureAcceleratedCheckouts(minimalConfig);
761761

762762
expect(
763763
NativeModule.configureAcceleratedCheckouts,
@@ -778,7 +778,7 @@ describe('ShopifyCheckoutSheetKit', () => {
778778
const instance = new ShopifyCheckoutSheet();
779779

780780
const result =
781-
instance.configureAcceleratedCheckouts(acceleratedConfig);
781+
await instance.configureAcceleratedCheckouts(acceleratedConfig);
782782

783783
expect(result).toBe(false);
784784
expect(
@@ -794,9 +794,9 @@ describe('ShopifyCheckoutSheetKit', () => {
794794
};
795795
const expectedError = new Error('`storefrontDomain` is required');
796796

797-
expect(
797+
await expect(
798798
instance.configureAcceleratedCheckouts(invalidConfig),
799-
).toBe(false);
799+
).resolves.toBe(false);
800800
expect(console.error).toHaveBeenCalledWith(
801801
'[ShopifyCheckoutSheetKit] Failed to configure accelerated checkouts with',
802802
expectedError,
@@ -812,9 +812,9 @@ describe('ShopifyCheckoutSheetKit', () => {
812812

813813
const expectedError = new Error('`storefrontAccessToken` is required');
814814

815-
expect(
815+
await expect(
816816
instance.configureAcceleratedCheckouts(invalidConfig),
817-
).toBe(false);
817+
).resolves.toBe(false);
818818
expect(console.error).toHaveBeenCalledWith(
819819
'[ShopifyCheckoutSheetKit] Failed to configure accelerated checkouts with',
820820
expectedError,
@@ -837,9 +837,9 @@ describe('ShopifyCheckoutSheetKit', () => {
837837
'`wallets.applePay.merchantIdentifier` is required',
838838
);
839839

840-
expect(
840+
await expect(
841841
instance.configureAcceleratedCheckouts(invalidConfig),
842-
).toBe(false);
842+
).resolves.toBe(false);
843843
expect(console.error).toHaveBeenCalledWith(
844844
'[ShopifyCheckoutSheetKit] Failed to configure accelerated checkouts with',
845845
expectedError,
@@ -862,29 +862,29 @@ describe('ShopifyCheckoutSheetKit', () => {
862862
`'wallets.applePay.contactFields' contains unexpected values. Expected "email, phone", received "invalid"`,
863863
);
864864

865-
expect(
865+
await expect(
866866
instance.configureAcceleratedCheckouts(invalidConfig as any),
867-
).toBe(false);
867+
).resolves.toBe(false);
868868
expect(console.error).toHaveBeenCalledWith(
869869
'[ShopifyCheckoutSheetKit] Failed to configure accelerated checkouts with',
870870
expectedError,
871871
);
872872
});
873873

874-
it('does not throw when Apple Pay wallet is not configured', () => {
874+
it('does not throw when Apple Pay wallet is not configured', async () => {
875875
const instance = new ShopifyCheckoutSheet();
876876
const configWithoutApplePay = {
877877
storefrontDomain: 'test-shop.myshopify.com',
878878
storefrontAccessToken: 'shpat_test_token',
879879
};
880880
NativeModule.configureAcceleratedCheckouts.mockReturnValue(true);
881881

882-
expect(
882+
await expect(
883883
instance.configureAcceleratedCheckouts(configWithoutApplePay),
884-
).toBe(true);
884+
).resolves.toBe(true);
885885
});
886886

887-
it('throws when a non-string value is given for supportedShippingCountries', () => {
887+
it('throws when a non-string value is given for supportedShippingCountries', async () => {
888888
const instance = new ShopifyCheckoutSheet();
889889
const invalidConfig = {
890890
...acceleratedConfig,
@@ -901,9 +901,9 @@ describe('ShopifyCheckoutSheetKit', () => {
901901
`'wallets.applePay.supportedShippingCountries' contains unexpected values. Expects ISO 3166-1 alpha-2 country codes (e.g., "US", "CA", "GB").`,
902902
);
903903

904-
expect(
904+
await expect(
905905
instance.configureAcceleratedCheckouts(invalidConfig as any),
906-
).toBe(false);
906+
).resolves.toBe(false);
907907
expect(console.error).toHaveBeenCalledWith(
908908
'[ShopifyCheckoutSheetKit] Failed to configure accelerated checkouts with',
909909
expectedError,
@@ -913,7 +913,7 @@ describe('ShopifyCheckoutSheetKit', () => {
913913
it('calls configureAcceleratedCheckouts with an empty array for supportShippingCountries when omitted', async () => {
914914
const instance = new ShopifyCheckoutSheet();
915915

916-
instance.configureAcceleratedCheckouts({
916+
await instance.configureAcceleratedCheckouts({
917917
...acceleratedConfig,
918918
wallets: {
919919
applePay: {
@@ -940,7 +940,7 @@ describe('ShopifyCheckoutSheetKit', () => {
940940
it('calls configureAcceleratedCheckouts with supportShippingCountries when given', async () => {
941941
const instance = new ShopifyCheckoutSheet();
942942

943-
instance.configureAcceleratedCheckouts({
943+
await instance.configureAcceleratedCheckouts({
944944
...acceleratedConfig,
945945
wallets: {
946946
applePay: {
@@ -967,25 +967,25 @@ describe('ShopifyCheckoutSheetKit', () => {
967967
});
968968

969969
describe('isAcceleratedCheckoutAvailable', () => {
970-
it('calls native isAcceleratedCheckoutAvailable on iOS', () => {
970+
it('calls native isAcceleratedCheckoutAvailable on iOS', async () => {
971971
const instance = new ShopifyCheckoutSheet();
972972
NativeModule.isAcceleratedCheckoutAvailable.mockReturnValue(true);
973973

974974
const result = instance.isAcceleratedCheckoutAvailable();
975975

976-
expect(result).toBe(true);
976+
await expect(result).resolves.toBe(true);
977977
expect(
978978
NativeModule.isAcceleratedCheckoutAvailable,
979979
).toHaveBeenCalledTimes(1);
980980
});
981981

982-
it('returns false on Android', () => {
982+
it('returns false on Android', async () => {
983983
Platform.OS = 'android';
984984
const instance = new ShopifyCheckoutSheet();
985985

986986
const result = instance.isAcceleratedCheckoutAvailable();
987987

988-
expect(result).toBe(false);
988+
await expect(result).resolves.toBe(false);
989989
expect(
990990
NativeModule.isAcceleratedCheckoutAvailable,
991991
).not.toHaveBeenCalled();

sample/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,7 @@ PODS:
25782578
- ReactCommon/turbomodule/core
25792579
- SocketRocket
25802580
- Yoga
2581-
- RNShopifyCheckoutSheetKit (4.0.0):
2581+
- RNShopifyCheckoutSheetKit (3.9.0):
25822582
- boost
25832583
- DoubleConversion
25842584
- fast_float
@@ -2996,7 +2996,7 @@ SPEC CHECKSUMS:
29962996
RNGestureHandler: eeb622199ef1fb3a076243131095df1c797072f0
29972997
RNReanimated: 237d420b7bb4378ef1dacc7d7a5c674fddb4b5d2
29982998
RNScreens: 3fc29af06302e1f1c18a7829fe57cbc2c0259912
2999-
RNShopifyCheckoutSheetKit: 2a8c97d7780466538843d4cb1368c7ed76a33689
2999+
RNShopifyCheckoutSheetKit: 5425cb8c6928b1aabe4504a8b37731d7e487cfd3
30003000
RNVectorIcons: be4d047a76ad307ffe54732208fb0498fcb8477f
30013001
ShopifyCheckoutSheetKit: 5253ca4da4c4f31069286509693930d02b4150d8
30023002
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748

sample/src/context/Cart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ export const CartProvider: React.FC<PropsWithChildren> = ({children}) => {
119119
}, [cartId, fetchCart, setTotalQuantity]);
120120

121121
const preloadCheckout = useCallback(
122-
(checkoutURL: string) => {
122+
async (checkoutURL: string) => {
123123
if (checkoutURL) {
124-
const config = shopify.getConfig();
124+
const config = await shopify.getConfig();
125125
if (config?.preloading) {
126126
shopify.preload(checkoutURL);
127127
}

0 commit comments

Comments
 (0)