@shopify/shop-minis-platform 0.16.0 → 0.18.0

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shopify/shop-minis-platform",
3
3
  "license": "SEE LICENSE IN LICENSE.txt",
4
- "version": "0.16.0",
4
+ "version": "0.18.0",
5
5
  "description": "Shared type definitions for Shop Minis Platform",
6
6
  "main": "src/index.ts",
7
7
  "exports": {
@@ -1,6 +1,10 @@
1
1
  import {ProductList} from '../types'
2
2
 
3
- import {InvokeIntentParams, InvokeIntentResponse} from './intents'
3
+ import {
4
+ InvokeIntentParams,
5
+ InvokeIntentResponse,
6
+ ResolveIntentParams,
7
+ } from './intents'
4
8
  import {
5
9
  FollowShopParams,
6
10
  UnfollowShopParams,
@@ -96,6 +100,9 @@ import {
96
100
  RequestPermissionResponse,
97
101
  CheckPermissionParams,
98
102
  CheckPermissionResponse,
103
+ CheckScopesConsentParams,
104
+ CheckScopesConsentResponse,
105
+ RequestScopesConsentResponse,
99
106
  ReportErrorParams,
100
107
  ReportFetchParams,
101
108
  } from './params'
@@ -239,7 +246,13 @@ export interface ShopActionEvents {
239
246
  RequestPermissionResponse
240
247
  >
241
248
  CHECK_PERMISSION: ShopAction<CheckPermissionParams, CheckPermissionResponse>
249
+ CHECK_SCOPES_CONSENT: ShopAction<
250
+ CheckScopesConsentParams,
251
+ {data: CheckScopesConsentResponse}
252
+ >
253
+ REQUEST_SCOPES_CONSENT: ShopAction<void, RequestScopesConsentResponse>
242
254
  REPORT_ERROR: ShopAction<ReportErrorParams, void>
243
255
  REPORT_FETCH: ShopAction<ReportFetchParams, void>
244
256
  INVOKE_INTENT: ShopAction<InvokeIntentParams, InvokeIntentResponse>
257
+ RESOLVE_INTENT: ShopAction<ResolveIntentParams, void>
245
258
  }
@@ -32,10 +32,24 @@ export interface CreateUserImageParams {
32
32
  maxSize?: number
33
33
  }
34
34
 
35
- export interface CreateUserImageResponse {
35
+ export interface ImageUrlResponse {
36
+ /** URL of the generated image. */
36
37
  imageUrl: string
37
38
  }
38
39
 
40
+ export type CreateUserImageResponse = ImageUrlResponse
41
+
42
+ // ---------------------------------------------------------------------------
43
+ // Try On Product Intent — try_on:shopify/Product
44
+ // ---------------------------------------------------------------------------
45
+
46
+ export interface TryOnProductParams {
47
+ /** Variant the user selected on the PDP that launched the Mini. */
48
+ variantId: string
49
+ }
50
+
51
+ export type TryOnProductResponse = ImageUrlResponse
52
+
39
53
  // ---------------------------------------------------------------------------
40
54
  // Intent Registry
41
55
  // ---------------------------------------------------------------------------
@@ -47,6 +61,46 @@ export interface IntentDefinitions {
47
61
  data: CreateUserImageParams
48
62
  result: CreateUserImageResponse
49
63
  }
64
+ tryOnProduct: {
65
+ action: 'try_on'
66
+ type: 'shopify/Product'
67
+ data: TryOnProductParams
68
+ result: TryOnProductResponse
69
+ }
50
70
  }
51
71
 
52
72
  export type IntentKey = keyof IntentDefinitions
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Runtime registry — pairs every IntentKey to the (action, type) literals it
76
+ // declares. The type-level IntentDefinitions above is erased at runtime; this
77
+ // constant is what code that needs to look up "which key matches this parsed
78
+ // intent" reads from. Keep in sync with IntentDefinitions.
79
+ // ---------------------------------------------------------------------------
80
+
81
+ export const INTENT_REGISTRY = {
82
+ createUserImage: {action: 'create', type: 'shop/UserImage'},
83
+ tryOnProduct: {action: 'try_on', type: 'shopify/Product'},
84
+ } as const satisfies {
85
+ [K in IntentKey]: {
86
+ action: IntentDefinitions[K]['action']
87
+ type: IntentDefinitions[K]['type']
88
+ }
89
+ }
90
+
91
+ // ---------------------------------------------------------------------------
92
+ // Intent label constants — derived from INTENT_REGISTRY so adding an entry
93
+ // above automatically extends `Intents`. The trailing cast is safe because
94
+ // `INTENT_REGISTRY` is `satisfies {[K in IntentKey]: ...}`, so its keys are
95
+ // exactly `IntentKey`.
96
+ // ---------------------------------------------------------------------------
97
+
98
+ export const Intents = (() => {
99
+ const out: {[label: string]: IntentKey} = {}
100
+ for (const key of Object.keys(INTENT_REGISTRY) as IntentKey[]) {
101
+ out[key[0].toUpperCase() + key.slice(1)] = key
102
+ }
103
+ return out as {[K in IntentKey as Capitalize<K>]: K}
104
+ })()
105
+
106
+ export type Intents = (typeof Intents)[keyof typeof Intents]
@@ -32,19 +32,22 @@ export interface IntentQuery<
32
32
  type: string
33
33
  }
34
34
 
35
- /**
36
- * Params for the INVOKE_INTENT shop action.
37
- */
35
+ /** Params for the INVOKE_INTENT shop action. */
38
36
  export type InvokeIntentParams = IntentQuery<any>
39
37
 
40
38
  // ---------------------------------------------------------------------------
41
39
  // Intent result types
42
40
  // ---------------------------------------------------------------------------
43
41
 
44
- export interface IntentResultOk<T> {
45
- code: 'ok'
46
- data: T
47
- }
42
+ /**
43
+ * Successful intent completion. `data` follows the declared response type:
44
+ * `void` → omitted, concrete shape → required, untyped (`unknown`) → optional.
45
+ */
46
+ export type IntentResultOk<T> = unknown extends T
47
+ ? {code: 'ok'; data?: T}
48
+ : [T] extends [void]
49
+ ? {code: 'ok'}
50
+ : {code: 'ok'; data: T}
48
51
 
49
52
  export interface IntentResultError {
50
53
  code: 'error'
@@ -61,7 +64,7 @@ export interface IntentResultClosed {
61
64
  * - `'error'` — workflow failed with a message
62
65
  * - `'closed'` — user dismissed without completing
63
66
  */
64
- export type IntentResult<T = {[key: string]: unknown}> =
67
+ export type IntentResult<T = unknown> =
65
68
  | IntentResultOk<T>
66
69
  | IntentResultError
67
70
  | IntentResultClosed
@@ -86,6 +89,21 @@ export type IntentAction<TData, TResult> = (
86
89
  /** Untyped intent response used at the INVOKE_INTENT bridge boundary. */
87
90
  export type InvokeIntentResponse = IntentResult
88
91
 
92
+ // ---------------------------------------------------------------------------
93
+ // RESOLVE_INTENT — Mini reports intent completion back to the host
94
+ // ---------------------------------------------------------------------------
95
+
96
+ /**
97
+ * Params for the RESOLVE_INTENT shop action. `result` is loose at the bridge;
98
+ * the typed correlation between `intentKey` and `result.data` is enforced by
99
+ * the `useResolveIntent` hook, where K is concrete.
100
+ */
101
+ export interface ResolveIntentParams {
102
+ /** Lets the host verify the Mini resolved the intent it was launched with. */
103
+ intentKey: IntentKey
104
+ result: IntentResult
105
+ }
106
+
89
107
  // ---------------------------------------------------------------------------
90
108
  // Typed intent utilities — leverage IntentDefinitions for per-intent safety
91
109
  // ---------------------------------------------------------------------------
@@ -61,6 +61,20 @@ export interface CheckPermissionResponse {
61
61
  errorMessage?: string
62
62
  }
63
63
 
64
+ export interface CheckScopesConsentParams {
65
+ fetchPolicy?: DataHookFetchPolicy
66
+ }
67
+
68
+ export interface CheckScopesConsentResponse {
69
+ requiredScopes: string[]
70
+ grantedScopes: string[]
71
+ status: 'granted' | 'partially_granted' | 'not_granted'
72
+ }
73
+
74
+ export interface RequestScopesConsentResponse {
75
+ granted: boolean
76
+ }
77
+
64
78
  export interface FavoriteParams {
65
79
  shopId: string
66
80
  productId: string
@@ -304,19 +318,22 @@ export interface PaginatedResponse<T> {
304
318
  pageInfo: PaginationInfo
305
319
  }
306
320
 
307
- export interface GetProductListsResponse
308
- extends PaginatedResponse<ProductList[]> {}
309
- export interface GetProductListResponse
310
- extends PaginatedResponse<ProductList | null> {}
321
+ export interface GetProductListsResponse extends PaginatedResponse<
322
+ ProductList[]
323
+ > {}
324
+ export interface GetProductListResponse extends PaginatedResponse<ProductList | null> {}
311
325
 
312
- export interface GetRecommendedProductsResponse
313
- extends PaginatedResponse<Product[]> {}
326
+ export interface GetRecommendedProductsResponse extends PaginatedResponse<
327
+ Product[]
328
+ > {}
314
329
 
315
- export interface GetRecommendedShopsResponse
316
- extends PaginatedResponse<Shop[]> {}
330
+ export interface GetRecommendedShopsResponse extends PaginatedResponse<
331
+ Shop[]
332
+ > {}
317
333
 
318
- export interface SearchProductsByShopResponse
319
- extends PaginatedResponse<Product[]> {}
334
+ export interface SearchProductsByShopResponse extends PaginatedResponse<
335
+ Product[]
336
+ > {}
320
337
 
321
338
  export interface GetBuyerAttributesResponse {
322
339
  data: {
@@ -546,8 +563,9 @@ export interface GetPopularProductsParams {
546
563
  fetchPolicy?: DataHookFetchPolicy
547
564
  }
548
565
 
549
- export interface GetPopularProductsResponse
550
- extends PaginatedResponse<Product[]> {}
566
+ export interface GetPopularProductsResponse extends PaginatedResponse<
567
+ Product[]
568
+ > {}
551
569
 
552
570
  export interface PreviewProductInARParams {
553
571
  id: string
@@ -561,8 +579,9 @@ export interface GetProductMediaParams {
561
579
  fetchPolicy?: DataHookFetchPolicy
562
580
  }
563
581
 
564
- export interface GetProductMediaResponse
565
- extends PaginatedResponse<ProductMedia[]> {}
582
+ export interface GetProductMediaResponse extends PaginatedResponse<
583
+ ProductMedia[]
584
+ > {}
566
585
 
567
586
  export interface GetProductReviewsParams {
568
587
  id: string
@@ -571,8 +590,9 @@ export interface GetProductReviewsParams {
571
590
  fetchPolicy?: DataHookFetchPolicy
572
591
  }
573
592
 
574
- export interface GetProductReviewsResponse
575
- extends PaginatedResponse<ProductReview[]> {}
593
+ export interface GetProductReviewsResponse extends PaginatedResponse<
594
+ ProductReview[]
595
+ > {}
576
596
 
577
597
  export interface GetShopParams {
578
598
  id: string
@@ -646,8 +666,9 @@ export interface GetSavedProductsParams {
646
666
  fetchPolicy?: DataHookFetchPolicy
647
667
  }
648
668
 
649
- export interface GetSavedProductsResponse
650
- extends PaginatedResponse<Product[]> {}
669
+ export interface GetSavedProductsResponse extends PaginatedResponse<
670
+ Product[]
671
+ > {}
651
672
 
652
673
  export interface GetRecentProductsParams {
653
674
  includeSensitive?: boolean
@@ -656,8 +677,9 @@ export interface GetRecentProductsParams {
656
677
  fetchPolicy?: DataHookFetchPolicy
657
678
  }
658
679
 
659
- export interface GetRecentProductsResponse
660
- extends PaginatedResponse<Product[]> {}
680
+ export interface GetRecentProductsResponse extends PaginatedResponse<
681
+ Product[]
682
+ > {}
661
683
 
662
684
  export interface GetProductSearchParams {
663
685
  query: string
@@ -669,8 +691,9 @@ export interface GetProductSearchParams {
669
691
  fetchPolicy?: DataHookFetchPolicy
670
692
  }
671
693
 
672
- export interface GetProductSearchResponse
673
- extends PaginatedResponse<Product[]> {}
694
+ export interface GetProductSearchResponse extends PaginatedResponse<
695
+ Product[]
696
+ > {}
674
697
 
675
698
  export interface GetProductVariantsParams {
676
699
  id: string
@@ -679,8 +702,9 @@ export interface GetProductVariantsParams {
679
702
  fetchPolicy?: DataHookFetchPolicy
680
703
  }
681
704
 
682
- export interface GetProductVariantsResponse
683
- extends PaginatedResponse<ProductVariant[]> {}
705
+ export interface GetProductVariantsResponse extends PaginatedResponse<
706
+ ProductVariant[]
707
+ > {}
684
708
 
685
709
  export interface CreateContentParams {
686
710
  title: string
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ import {MinisParams} from './types'
4
4
 
5
5
  export * from './types'
6
6
  export * from './constants'
7
+ export * from './actions/intent-definitions'
7
8
 
8
9
  declare global {
9
10
  interface Window {