@shopify/shop-minis-react 0.0.0-snapshot.20251222174301 → 0.0.0-snapshot.20251224113248

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/hooks/intents/useInvokeIntentAction.js +10 -0
  2. package/dist/hooks/intents/useInvokeIntentAction.js.map +1 -0
  3. package/dist/hooks/intents/useQueryIntents.js +10 -0
  4. package/dist/hooks/intents/useQueryIntents.js.map +1 -0
  5. package/dist/hooks/intents/useSelectProduct.js +21 -0
  6. package/dist/hooks/intents/useSelectProduct.js.map +1 -0
  7. package/dist/index.js +127 -133
  8. package/dist/index.js.map +1 -1
  9. package/dist/mocks.js +42 -7
  10. package/dist/mocks.js.map +1 -1
  11. package/dist/shop-minis-platform/src/actions/scopes.js +36 -0
  12. package/dist/shop-minis-platform/src/actions/scopes.js.map +1 -0
  13. package/package.json +2 -2
  14. package/src/hooks/intents/index.ts +21 -25
  15. package/src/hooks/intents/useInvokeIntentAction.ts +12 -0
  16. package/src/hooks/intents/useQueryIntents.ts +25 -0
  17. package/src/hooks/intents/useSelectProduct.ts +48 -0
  18. package/src/mocks.ts +35 -0
  19. package/dist/hooks/intents/useBarcodeScanner.js +0 -10
  20. package/dist/hooks/intents/useBarcodeScanner.js.map +0 -1
  21. package/dist/hooks/intents/useContentShare.js +0 -10
  22. package/dist/hooks/intents/useContentShare.js.map +0 -1
  23. package/dist/hooks/intents/useImageCapture.js +0 -10
  24. package/dist/hooks/intents/useImageCapture.js.map +0 -1
  25. package/dist/hooks/intents/useLocationSelection.js +0 -10
  26. package/dist/hooks/intents/useLocationSelection.js.map +0 -1
  27. package/dist/hooks/intents/usePaymentRequest.js +0 -10
  28. package/dist/hooks/intents/usePaymentRequest.js.map +0 -1
  29. package/dist/hooks/intents/useProductSelection.js +0 -10
  30. package/dist/hooks/intents/useProductSelection.js.map +0 -1
  31. package/dist/internal/useHandleIntent.js +0 -26
  32. package/dist/internal/useHandleIntent.js.map +0 -1
  33. package/dist/internal/useShopIntents.js +0 -7
  34. package/dist/internal/useShopIntents.js.map +0 -1
  35. package/dist/shop-minis-platform/src/intents/shared.js +0 -19
  36. package/dist/shop-minis-platform/src/intents/shared.js.map +0 -1
  37. package/src/hooks/intents/useBarcodeScanner.ts +0 -43
  38. package/src/hooks/intents/useContentShare.ts +0 -47
  39. package/src/hooks/intents/useImageCapture.ts +0 -45
  40. package/src/hooks/intents/useLocationSelection.ts +0 -45
  41. package/src/hooks/intents/usePaymentRequest.ts +0 -47
  42. package/src/hooks/intents/useProductSelection.ts +0 -45
  43. package/src/internal/useHandleIntent.ts +0 -101
  44. package/src/internal/useShopIntents.ts +0 -13
@@ -1,43 +0,0 @@
1
- import {
2
- useHandleIntent,
3
- HandleIntentOptions,
4
- } from '../../internal/useHandleIntent'
5
- import {useShopIntents} from '../../internal/useShopIntents'
6
-
7
- import type {
8
- ScanBarcodeIntentParams,
9
- ScanBarcodeIntentResult,
10
- } from '@shopify/shop-minis-platform'
11
-
12
- /**
13
- * Hook to scan barcodes or QR codes
14
- *
15
- * This intent opens the camera to scan barcodes or QR codes.
16
- *
17
- * @example
18
- * const scanBarcode = useBarcodeScanner({
19
- * onCancel: () => console.log('User cancelled'),
20
- * })
21
- *
22
- * const result = await scanBarcode({
23
- * types: ['qr', 'ean13'],
24
- * instruction: 'Scan product barcode'
25
- * })
26
- *
27
- * if (result) {
28
- * console.log('Scanned:', result.barcodes)
29
- * }
30
- */
31
- export const useBarcodeScanner = (
32
- options?: HandleIntentOptions<ScanBarcodeIntentResult>
33
- ) => {
34
- const intents = useShopIntents()
35
- return useHandleIntent(intents.scanBarcode, options)
36
- }
37
-
38
- /**
39
- * Type helper for the barcode scanner function
40
- */
41
- export type BarcodeScannerFunction = (
42
- params: ScanBarcodeIntentParams
43
- ) => Promise<ScanBarcodeIntentResult | void>
@@ -1,47 +0,0 @@
1
- import {
2
- useHandleIntent,
3
- HandleIntentOptions,
4
- } from '../../internal/useHandleIntent'
5
- import {useShopIntents} from '../../internal/useShopIntents'
6
-
7
- import type {
8
- ShareContentIntentParams,
9
- ShareContentIntentResult,
10
- } from '@shopify/shop-minis-platform'
11
-
12
- /**
13
- * Hook to share content via the Shop app's native share sheet
14
- *
15
- * This intent opens the native share sheet to let the user
16
- * share content to various platforms.
17
- *
18
- * @example
19
- * const shareContent = useContentShare({
20
- * onCancel: () => console.log('User cancelled sharing'),
21
- * })
22
- *
23
- * const result = await shareContent({
24
- * type: 'product',
25
- * content: {
26
- * title: 'Check out this product!',
27
- * url: 'https://shop.app/products/123'
28
- * }
29
- * })
30
- *
31
- * if (result?.shared) {
32
- * console.log('Content shared to:', result.platform)
33
- * }
34
- */
35
- export const useContentShare = (
36
- options?: HandleIntentOptions<ShareContentIntentResult>
37
- ) => {
38
- const intents = useShopIntents()
39
- return useHandleIntent(intents.shareContent, options)
40
- }
41
-
42
- /**
43
- * Type helper for the content share function
44
- */
45
- export type ContentShareFunction = (
46
- params: ShareContentIntentParams
47
- ) => Promise<ShareContentIntentResult | void>
@@ -1,45 +0,0 @@
1
- import {
2
- useHandleIntent,
3
- HandleIntentOptions,
4
- } from '../../internal/useHandleIntent'
5
- import {useShopIntents} from '../../internal/useShopIntents'
6
-
7
- import type {
8
- CaptureImageIntentParams,
9
- CaptureImageIntentResult,
10
- } from '@shopify/shop-minis-platform'
11
-
12
- /**
13
- * Hook to request user to capture or select images
14
- *
15
- * This intent opens the camera or photo gallery to let the user
16
- * capture or select one or more images.
17
- *
18
- * @example
19
- * const captureImage = useImageCapture({
20
- * onCancel: () => console.log('User cancelled'),
21
- * })
22
- *
23
- * const result = await captureImage({
24
- * source: 'camera',
25
- * quality: 0.8,
26
- * maxWidth: 1920
27
- * })
28
- *
29
- * if (result) {
30
- * console.log('Captured images:', result.images)
31
- * }
32
- */
33
- export const useImageCapture = (
34
- options?: HandleIntentOptions<CaptureImageIntentResult>
35
- ) => {
36
- const intents = useShopIntents()
37
- return useHandleIntent(intents.captureImage, options)
38
- }
39
-
40
- /**
41
- * Type helper for the image capture function
42
- */
43
- export type ImageCaptureFunction = (
44
- params: CaptureImageIntentParams
45
- ) => Promise<CaptureImageIntentResult | void>
@@ -1,45 +0,0 @@
1
- import {
2
- useHandleIntent,
3
- HandleIntentOptions,
4
- } from '../../internal/useHandleIntent'
5
- import {useShopIntents} from '../../internal/useShopIntents'
6
-
7
- import type {
8
- SelectLocationIntentParams,
9
- SelectLocationIntentResult,
10
- } from '@shopify/shop-minis-platform'
11
-
12
- /**
13
- * Hook to request user to select a location
14
- *
15
- * This intent shows a map interface where the user can select
16
- * a location and optionally get address information.
17
- *
18
- * @example
19
- * const selectLocation = useLocationSelection({
20
- * onCancel: () => console.log('User cancelled'),
21
- * })
22
- *
23
- * const result = await selectLocation({
24
- * title: 'Select delivery location',
25
- * locationType: 'address'
26
- * })
27
- *
28
- * if (result) {
29
- * console.log('Selected location:', result.coordinates)
30
- * console.log('Address:', result.address?.formattedAddress)
31
- * }
32
- */
33
- export const useLocationSelection = (
34
- options?: HandleIntentOptions<SelectLocationIntentResult>
35
- ) => {
36
- const intents = useShopIntents()
37
- return useHandleIntent(intents.selectLocation, options)
38
- }
39
-
40
- /**
41
- * Type helper for the location selection function
42
- */
43
- export type LocationSelectionFunction = (
44
- params: SelectLocationIntentParams
45
- ) => Promise<SelectLocationIntentResult | void>
@@ -1,47 +0,0 @@
1
- import {
2
- useHandleIntent,
3
- HandleIntentOptions,
4
- } from '../../internal/useHandleIntent'
5
- import {useShopIntents} from '../../internal/useShopIntents'
6
-
7
- import type {
8
- RequestPaymentIntentParams,
9
- RequestPaymentIntentResult,
10
- } from '@shopify/shop-minis-platform'
11
-
12
- /**
13
- * Hook to request payment from user
14
- *
15
- * This intent opens the Shop app's payment flow to process a payment.
16
- *
17
- * **Note:** This intent requires special permissions and may have rate limits.
18
- *
19
- * @example
20
- * const requestPayment = usePaymentRequest({
21
- * onCancel: () => console.log('User cancelled payment'),
22
- * onError: (error) => console.error('Payment failed:', error)
23
- * })
24
- *
25
- * const result = await requestPayment({
26
- * amount: 999, // $9.99 in cents
27
- * currency: 'USD',
28
- * description: 'Premium subscription'
29
- * })
30
- *
31
- * if (result) {
32
- * console.log('Payment successful:', result.transactionId)
33
- * }
34
- */
35
- export const usePaymentRequest = (
36
- options?: HandleIntentOptions<RequestPaymentIntentResult>
37
- ) => {
38
- const intents = useShopIntents()
39
- return useHandleIntent(intents.requestPayment, options)
40
- }
41
-
42
- /**
43
- * Type helper for the payment request function
44
- */
45
- export type PaymentRequestFunction = (
46
- params: RequestPaymentIntentParams
47
- ) => Promise<RequestPaymentIntentResult | void>
@@ -1,45 +0,0 @@
1
- import {
2
- useHandleIntent,
3
- HandleIntentOptions,
4
- } from '../../internal/useHandleIntent'
5
- import {useShopIntents} from '../../internal/useShopIntents'
6
-
7
- import type {
8
- SelectProductIntentParams,
9
- SelectProductIntentResult,
10
- } from '@shopify/shop-minis-platform'
11
-
12
- /**
13
- * Hook to request user to select products
14
- *
15
- * This intent shows a product selection screen where the user can browse
16
- * and select one or more products from the Shop catalog.
17
- *
18
- * @example
19
- * const selectProducts = useProductSelection({
20
- * onCancel: () => console.log('User cancelled'),
21
- * })
22
- *
23
- * const result = await selectProducts({
24
- * multiSelect: true,
25
- * maxSelections: 5,
26
- * title: 'Choose your favorites'
27
- * })
28
- *
29
- * if (result) {
30
- * console.log('Selected products:', result.products)
31
- * }
32
- */
33
- export const useProductSelection = (
34
- options?: HandleIntentOptions<SelectProductIntentResult>
35
- ) => {
36
- const intents = useShopIntents()
37
- return useHandleIntent(intents.selectProduct, options)
38
- }
39
-
40
- /**
41
- * Type helper for the product selection function
42
- */
43
- export type ProductSelectionFunction = (
44
- params: SelectProductIntentParams
45
- ) => Promise<SelectProductIntentResult | void>
@@ -1,101 +0,0 @@
1
- import {useCallback} from 'react'
2
-
3
- import {IntentResultCode} from '@shopify/shop-minis-platform'
4
-
5
- import type {ShopIntentResult} from '@shopify/shop-minis-platform'
6
-
7
- /**
8
- * Options for handling intent results
9
- */
10
- export interface HandleIntentOptions<T> {
11
- /**
12
- * Handler called when user cancels the intent
13
- * If not provided, cancellation is treated as a no-op (returns undefined)
14
- */
15
- onCancel?: () => T | void
16
- /**
17
- * Handler called when intent fails
18
- * If not provided, throws the error
19
- */
20
- onError?: (error: {message: string; code?: string}) => T | void
21
- }
22
-
23
- /**
24
- * Wrapper to handle intent results
25
- *
26
- * Unlike actions which can reject, intents ALWAYS resolve with a result code.
27
- * This hook provides a cleaner API for handling intent results:
28
- *
29
- * - SUCCESS: Returns the data
30
- * - CANCELLED: Calls onCancel or returns undefined
31
- * - FAILED: Calls onError or throws the error
32
- *
33
- * @example
34
- * const selectProduct = useHandleIntent(intents.selectProduct, {
35
- * onCancel: () => console.log('User cancelled'),
36
- * onError: (error) => console.error('Selection failed:', error)
37
- * })
38
- *
39
- * const result = await selectProduct({multiSelect: true})
40
- * // result is the data, or undefined if cancelled
41
- */
42
- export const useHandleIntent = <T, Args extends unknown[]>(
43
- intent: (...args: Args) => Promise<ShopIntentResult<T>>,
44
- options?: HandleIntentOptions<T>
45
- ) => {
46
- return useCallback(
47
- async (...args: Args): Promise<T | void> => {
48
- const result = await intent(...args)
49
-
50
- switch (result.resultCode) {
51
- case IntentResultCode.SUCCESS:
52
- return result.data!
53
-
54
- case IntentResultCode.CANCELLED:
55
- if (options?.onCancel) {
56
- return options.onCancel()
57
- }
58
- return undefined
59
-
60
- case IntentResultCode.FAILED:
61
- if (options?.onError) {
62
- return options.onError(result.error!)
63
- }
64
-
65
- throw new Error(result.error?.message || 'Intent failed')
66
-
67
- default: {
68
- // Exhaustiveness check
69
- const _exhaustive: never = result.resultCode
70
- throw new Error(`Unhandled result code: ${_exhaustive}`)
71
- }
72
- }
73
- },
74
- [intent, options]
75
- )
76
- }
77
-
78
- /**
79
- * Alternative: Manual result handling without throwing
80
- *
81
- * Use this when you want to handle all result codes explicitly
82
- * without throwing errors.
83
- *
84
- * @example
85
- * const selectProduct = useHandleIntentManual(intents.selectProduct)
86
- *
87
- * const result = await selectProduct({multiSelect: true})
88
- * if (result.resultCode === 'SUCCESS') {
89
- * console.log(result.data)
90
- * }
91
- */
92
- export const useHandleIntentManual = <T, Args extends unknown[]>(
93
- intent: (...args: Args) => Promise<ShopIntentResult<T>>
94
- ) => {
95
- return useCallback(
96
- (...args: Args) => {
97
- return intent(...args)
98
- },
99
- [intent]
100
- )
101
- }
@@ -1,13 +0,0 @@
1
- import type {ShopIntents} from '@shopify/shop-minis-platform'
2
-
3
- /**
4
- * Internal hook to access Shop Intents
5
- *
6
- * This provides direct access to window.minisIntents
7
- * Use specific intent hooks (like useProductSelection) instead of this hook directly
8
- *
9
- * @internal
10
- */
11
- export function useShopIntents(): ShopIntents {
12
- return window.minisIntents
13
- }