Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions __mocks__/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const requireNativeComponent = (..._args: any[]) => {
});
};

const codegenNativeComponent = requireNativeComponent;

const StyleSheet = {
flatten: jest.fn(style => style),
};
Expand All @@ -47,6 +49,7 @@ const exampleConfig = {preloading: true};

const ShopifyCheckoutSheetKit = {
version: '0.7.0',
getConstants: jest.fn(() => ({version: '0.7.0'})),
preload: jest.fn(),
present: jest.fn(),
dismiss: jest.fn(),
Expand All @@ -58,6 +61,8 @@ const ShopifyCheckoutSheetKit = {
initiateGeolocationRequest: jest.fn(),
configureAcceleratedCheckouts: jest.fn(),
isAcceleratedCheckoutAvailable: jest.fn(),
addListener: jest.fn(),
removeListeners: jest.fn(),
};

// CommonJS export for Jest manual mock resolution
Expand All @@ -68,6 +73,15 @@ module.exports = {
},
NativeEventEmitter: jest.fn(() => createMockEmitter()),
requireNativeComponent,
codegenNativeComponent,
TurboModuleRegistry: {
getEnforcing: jest.fn((name: string) => {
if (name === 'ShopifyCheckoutSheetKit') {
return ShopifyCheckoutSheetKit;
}
return null;
}),
},
NativeModules: {
ShopifyCheckoutSheetKit: {
...ShopifyCheckoutSheetKit,
Expand Down
8 changes: 8 additions & 0 deletions modules/@shopify/checkout-sheet-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
"react-native-builder-bob": "^0.23.2",
"typescript": "^5.9.2"
},
"codegenConfig": {
"name": "RNShopifyCheckoutSheetKitSpec",
"type": "all",
"jsSrcsDir": "src/specs",
"android": {
"javaPackageName": "com.shopify.checkoutsheetkit"
}
},
"react-native-builder-bob": {
"source": "src",
"output": "lib",
Expand Down
16 changes: 15 additions & 1 deletion modules/@shopify/checkout-sheet-kit/package.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"lib/commonjs/index.js.map",
"lib/commonjs/pixels.d.js",
"lib/commonjs/pixels.d.js.map",
"lib/commonjs/specs/NativeShopifyCheckoutSheetKit.js",
"lib/commonjs/specs/NativeShopifyCheckoutSheetKit.js.map",
"lib/commonjs/specs/RCTAcceleratedCheckoutButtonsNativeComponent.js",
"lib/commonjs/specs/RCTAcceleratedCheckoutButtonsNativeComponent.js.map",
"lib/module/components/AcceleratedCheckoutButtons.js",
"lib/module/components/AcceleratedCheckoutButtons.js.map",
"lib/module/context.js",
Expand All @@ -44,18 +48,28 @@
"lib/module/index.js.map",
"lib/module/pixels.d.js",
"lib/module/pixels.d.js.map",
"lib/module/specs/NativeShopifyCheckoutSheetKit.js",
"lib/module/specs/NativeShopifyCheckoutSheetKit.js.map",
"lib/module/specs/RCTAcceleratedCheckoutButtonsNativeComponent.js",
"lib/module/specs/RCTAcceleratedCheckoutButtonsNativeComponent.js.map",
"lib/typescript/src/components/AcceleratedCheckoutButtons.d.ts",
"lib/typescript/src/components/AcceleratedCheckoutButtons.d.ts.map",
"lib/typescript/src/context.d.ts",
"lib/typescript/src/context.d.ts.map",
"lib/typescript/src/index.d.ts",
"lib/typescript/src/index.d.ts.map",
"lib/typescript/src/specs/NativeShopifyCheckoutSheetKit.d.ts",
"lib/typescript/src/specs/NativeShopifyCheckoutSheetKit.d.ts.map",
"lib/typescript/src/specs/RCTAcceleratedCheckoutButtonsNativeComponent.d.ts",
"lib/typescript/src/specs/RCTAcceleratedCheckoutButtonsNativeComponent.d.ts.map",
"package.json",
"src/components/AcceleratedCheckoutButtons.tsx",
"src/context.tsx",
"src/errors.d.ts",
"src/events.d.ts",
"src/index.d.ts",
"src/index.ts",
"src/pixels.d.ts"
"src/pixels.d.ts",
"src/specs/NativeShopifyCheckoutSheetKit.ts",
"src/specs/RCTAcceleratedCheckoutButtonsNativeComponent.ts"
]
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
*/

import React, {useCallback, useMemo, useState} from 'react';
import {requireNativeComponent, Platform} from 'react-native';
import {codegenNativeComponent, Platform} from 'react-native';
import type {ViewStyle} from 'react-native';
import type {
AcceleratedCheckoutWallet,
Expand Down Expand Up @@ -178,7 +178,7 @@ interface NativeAcceleratedCheckoutButtonsProps {
}

const RCTAcceleratedCheckoutButtons =
requireNativeComponent<NativeAcceleratedCheckoutButtonsProps>(
codegenNativeComponent<NativeAcceleratedCheckoutButtonsProps>(
'RCTAcceleratedCheckoutButtons',
);

Expand Down
22 changes: 5 additions & 17 deletions modules/@shopify/checkout-sheet-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import {
NativeModules,
NativeEventEmitter,
PermissionsAndroid,
Platform,
} from 'react-native';
import {NativeEventEmitter, PermissionsAndroid, Platform} from 'react-native';
import type {
EmitterSubscription,
EventSubscription,
PermissionStatus,
} from 'react-native';
import RNShopifyCheckoutSheetKit from './specs/NativeShopifyCheckoutSheetKit';
import {ShopifyCheckoutSheetProvider, useShopifyCheckoutSheet} from './context';
import {ApplePayContactField, ColorScheme, LogLevel} from './index.d';
import type {
Expand Down Expand Up @@ -64,15 +60,6 @@ import type {
RenderStateChangeEvent,
} from './components/AcceleratedCheckoutButtons';

const RNShopifyCheckoutSheetKit = NativeModules.ShopifyCheckoutSheetKit;

if (!('ShopifyCheckoutSheetKit' in NativeModules)) {
throw new Error(`
"@shopify/checkout-sheet-kit" is not correctly linked.

If you are building for iOS, make sure to run "pod install" first and restart the metro server.`);
}

const defaultFeatures: Features = {
handleGeolocationRequests: true,
};
Expand Down Expand Up @@ -114,7 +101,8 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
}
}

public readonly version: string = RNShopifyCheckoutSheetKit.version;
public readonly version: string =
RNShopifyCheckoutSheetKit.getConstants().version;

/**
* Dismisses the currently displayed checkout sheet
Expand Down Expand Up @@ -151,7 +139,7 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
* @returns Promise containing the current Configuration
*/
public async getConfig(): Promise<Configuration> {
return RNShopifyCheckoutSheetKit.getConfig();
return RNShopifyCheckoutSheetKit.getConfig() as Promise<Configuration>;
Copy link
Copy Markdown
Contributor Author

@kieran-osgood-shopify kieran-osgood-shopify Apr 17, 2026

Choose a reason for hiding this comment

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

this type assertion is removed up stack with a parser to coerce the values to ts enums

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import type {TurboModule} from 'react-native';
import {TurboModuleRegistry} from 'react-native';

type IosColorsSpec = {
tintColor?: string;
backgroundColor?: string;
closeButtonColor?: string;
};

type AndroidColorsBaseSpec = {
progressIndicator?: string;
backgroundColor?: string;
headerBackgroundColor?: string;
headerTextColor?: string;
closeButtonColor?: string;
};

type AndroidColorsSpec = {
progressIndicator?: string;
backgroundColor?: string;
headerBackgroundColor?: string;
headerTextColor?: string;
closeButtonColor?: string;
light?: AndroidColorsBaseSpec;
dark?: AndroidColorsBaseSpec;
};

type ColorsSpec = {
ios?: IosColorsSpec;
android?: AndroidColorsSpec;
};

type ConfigurationSpec = {
preloading?: boolean;
title?: string;
colorScheme?: string;
logLevel?: string;
colors?: ColorsSpec;
};

type ConfigurationResultSpec = {
preloading: boolean;
colorScheme: string;
logLevel: string;
title?: string;
tintColor?: string;
backgroundColor?: string;
closeButtonColor?: string;
};

export interface Spec extends TurboModule {
present(checkoutUrl: string): void;
preload(checkoutUrl: string): void;
dismiss(): void;
invalidateCache(): void;
setConfig(configuration: ConfigurationSpec): void;
getConfig(): Promise<ConfigurationResultSpec>;
configureAcceleratedCheckouts(
storefrontDomain: string,
storefrontAccessToken: string,
customerEmail: string | null,
customerPhoneNumber: string | null,
customerAccessToken: string | null,
applePayMerchantIdentifier: string | null,
applyPayContactFields: string[],
supportedShippingCountries: string[],
): Promise<boolean>;
isAcceleratedCheckoutAvailable(): Promise<boolean>;
isApplePayAvailable(): Promise<boolean>;
initiateGeolocationRequest(allow: boolean): void;
addListener(eventName: string): void;
removeListeners(count: number): void;
getConstants(): {version: string};
}

export default TurboModuleRegistry.getEnforcing<Spec>(
'ShopifyCheckoutSheetKit',
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import {codegenNativeComponent, type ViewProps} from 'react-native';
import type {
BubblingEventHandler,
DirectEventHandler,
Double,
Float,
// eslint-disable-next-line @react-native/no-deep-imports -- codegen parser requires these type names to be imported directly (not via aliases) so it can match them statically during AST traversal
} from 'react-native/Libraries/Types/CodegenTypes';

type FailEvent = Readonly<{
__typename: string;
message: string;
code?: string;
recoverable?: boolean;
}>;

type CompleteEvent = Readonly<{
orderDetails: Readonly<{
id: string;
email?: string;
phone?: string;
}>;
}>;

type RenderStateChangeEvent = Readonly<{
state: string;
reason?: string;
}>;

type ClickLinkEvent = Readonly<{url: string}>;
type SizeChangeEvent = Readonly<{height: Double}>;

type CheckoutIdentifierSpec = Readonly<{
cartId?: string;
variantId?: string;
quantity?: Double;
}>;

interface NativeProps extends ViewProps {
checkoutIdentifier: CheckoutIdentifierSpec;
cornerRadius?: Float;
wallets?: ReadonlyArray<string>;
applePayLabel?: string;
onFail?: BubblingEventHandler<FailEvent>;
onComplete?: BubblingEventHandler<CompleteEvent>;
onCancel?: BubblingEventHandler<null>;
onRenderStateChange?: BubblingEventHandler<RenderStateChangeEvent>;
onWebPixelEvent?: BubblingEventHandler<Readonly<{data: string}>>;
onClickLink?: BubblingEventHandler<ClickLinkEvent>;
onSizeChange?: DirectEventHandler<SizeChangeEvent>;
onShouldRecoverFromError?: DirectEventHandler<
Readonly<{recoverable: boolean}>
>;
}

export default codegenNativeComponent<NativeProps>(
'RCTAcceleratedCheckoutButtons',
);
Loading
Loading