@shopify/shop-minis-platform 0.17.0 → 0.19.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.17.0",
4
+ "version": "0.19.0",
5
5
  "description": "Shared type definitions for Shop Minis Platform",
6
6
  "main": "src/index.ts",
7
7
  "exports": {
@@ -21,13 +21,13 @@
21
21
  ],
22
22
  "scripts": {
23
23
  "test": "TZ=UTC jest",
24
- "type-check": "tsc --noEmit",
24
+ "type-check": "tsgo --noEmit",
25
25
  "typecheck": "pnpm run type-check"
26
26
  },
27
27
  "dependencies": {},
28
28
  "peerDependencies": {},
29
29
  "devDependencies": {
30
- "typescript": "^5.8.3"
30
+ "typescript": "^6.0.3"
31
31
  },
32
32
  "author": "Shopify",
33
33
  "repository": {
@@ -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,
@@ -67,6 +71,8 @@ import {
67
71
  GetRecentProductsResponse,
68
72
  GetProductSearchParams,
69
73
  GetProductSearchResponse,
74
+ GetSimilarProductsParams,
75
+ GetSimilarProductsResponse,
70
76
  GetProductsParams,
71
77
  GetProductsResponse,
72
78
  GetProductParams,
@@ -214,6 +220,10 @@ export interface ShopActionEvents {
214
220
  GetProductSearchParams,
215
221
  GetProductSearchResponse
216
222
  >
223
+ GET_SIMILAR_PRODUCTS: ShopAction<
224
+ GetSimilarProductsParams,
225
+ GetSimilarProductsResponse
226
+ >
217
227
  GET_PRODUCTS: ShopAction<GetProductsParams, GetProductsResponse>
218
228
  GET_PRODUCT: ShopAction<GetProductParams, GetProductResponse>
219
229
  GET_PRODUCT_VARIANTS: ShopAction<
@@ -250,4 +260,5 @@ export interface ShopActionEvents {
250
260
  REPORT_ERROR: ShopAction<ReportErrorParams, void>
251
261
  REPORT_FETCH: ShopAction<ReportFetchParams, void>
252
262
  INVOKE_INTENT: ShopAction<InvokeIntentParams, InvokeIntentResponse>
263
+ RESOLVE_INTENT: ShopAction<ResolveIntentParams, void>
253
264
  }
@@ -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
  // ---------------------------------------------------------------------------
@@ -695,6 +695,62 @@ export interface GetProductSearchResponse extends PaginatedResponse<
695
695
  Product[]
696
696
  > {}
697
697
 
698
+ /**
699
+ * Image media used as the source for similar product search.
700
+ * The hook handles base64 encoding from a File — partners pass a File directly,
701
+ * not the encoded payload.
702
+ */
703
+ export interface GetSimilarProductsMediaInput {
704
+ /**
705
+ * The image MIME type. Currently only `image/jpeg` is supported.
706
+ */
707
+ contentType: string
708
+ /**
709
+ * The base64-encoded image content (without `data:` prefix). Must be <= 4 MiB.
710
+ */
711
+ base64: string
712
+ }
713
+
714
+ /**
715
+ * The source for similar product search. Exactly one of `productId`,
716
+ * `productVariantId`, or `media` must be provided.
717
+ */
718
+ export interface GetSimilarProductsSourceInput {
719
+ /**
720
+ * Shopify Product GID, e.g. `gid://shopify/Product/123`.
721
+ */
722
+ productId?: string
723
+ /**
724
+ * Shopify ProductVariant GID, e.g. `gid://shopify/ProductVariant/456`.
725
+ */
726
+ productVariantId?: string
727
+ /**
728
+ * JPEG image media to find similar products for.
729
+ */
730
+ media?: GetSimilarProductsMediaInput
731
+ }
732
+
733
+ export interface GetSimilarProductsParams {
734
+ /**
735
+ * Source for similar product search. Exactly one of `productId`,
736
+ * `productVariantId`, or `media` must be set.
737
+ */
738
+ similarTo: GetSimilarProductsSourceInput
739
+ /**
740
+ * Number of products to return. Must be 1..10.
741
+ */
742
+ first?: number
743
+ /**
744
+ * Cursor for pagination. Currently the backend returns only a first page,
745
+ * so this is effectively unused.
746
+ */
747
+ after?: string
748
+ fetchPolicy?: DataHookFetchPolicy
749
+ }
750
+
751
+ export interface GetSimilarProductsResponse
752
+ extends PaginatedResponse<Product[]> {}
753
+
698
754
  export interface GetProductVariantsParams {
699
755
  id: string
700
756
  first?: number
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 {