@shopify/shop-minis-platform 0.19.0 → 0.21.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 +1 -1
- package/src/actions/intent-definitions.ts +215 -0
- package/src/types/product.ts +39 -0
package/package.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type {ProductVariant} from '../types/product'
|
|
2
|
+
|
|
1
3
|
// ---------------------------------------------------------------------------
|
|
2
4
|
// User Image Intent — create:shop/UserImage
|
|
3
5
|
// ---------------------------------------------------------------------------
|
|
@@ -50,6 +52,202 @@ export interface TryOnProductParams {
|
|
|
50
52
|
|
|
51
53
|
export type TryOnProductResponse = ImageUrlResponse
|
|
52
54
|
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Product Variant Selector Intent — select:shopify/ProductVariant
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Data payload for the `select:shopify/ProductVariant` intent.
|
|
61
|
+
*
|
|
62
|
+
* Prompts the user to pick a variant (and quantity) for the product whose
|
|
63
|
+
* GID is passed as `data.productId`. The host renders a native bottom sheet
|
|
64
|
+
* over the mini WebView using the same option pickers as the Shop PDP.
|
|
65
|
+
*
|
|
66
|
+
* Single-variant products short-circuit without showing UI.
|
|
67
|
+
*
|
|
68
|
+
* @publicDocs
|
|
69
|
+
*/
|
|
70
|
+
export interface SelectProductVariantParams {
|
|
71
|
+
/**
|
|
72
|
+
* The GID of the product whose variants should be selectable.
|
|
73
|
+
* E.g. `gid://shopify/Product/123`.
|
|
74
|
+
*/
|
|
75
|
+
productId: string
|
|
76
|
+
/**
|
|
77
|
+
* If present, the GID of the variant that should be initially highlighted.
|
|
78
|
+
* Defaults to the product's default variant.
|
|
79
|
+
*/
|
|
80
|
+
initialVariantId?: string
|
|
81
|
+
/**
|
|
82
|
+
* Optional allow-list of variant GIDs. When set, only these variants are
|
|
83
|
+
* presented to the user. Other variants are filtered out before the option
|
|
84
|
+
* tree is built.
|
|
85
|
+
*/
|
|
86
|
+
includedProductVariantGIDs?: string[]
|
|
87
|
+
/** Initial quantity displayed in the stepper. Defaults to `1`. */
|
|
88
|
+
initialQuantity?: number
|
|
89
|
+
/**
|
|
90
|
+
* Maximum quantity selectable in the stepper. Defaults to the variant's available
|
|
91
|
+
* inventory (or unbounded when stock is not tracked).
|
|
92
|
+
*/
|
|
93
|
+
maxQuantity?: number
|
|
94
|
+
/** Whether to show the quantity stepper. Defaults to `true`. */
|
|
95
|
+
showQuantity?: boolean
|
|
96
|
+
/**
|
|
97
|
+
* When `true`, always render the sheet — even for products with a single
|
|
98
|
+
* variant. The single-variant short-circuit (resolving instantly without
|
|
99
|
+
* showing UI) is bypassed. Useful for flows that want a consistent
|
|
100
|
+
* confirmation step regardless of variant count. Defaults to `false`.
|
|
101
|
+
*/
|
|
102
|
+
forceShow?: boolean
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Shared shape describing the variant + quantity a user (or the host)
|
|
107
|
+
* picked via the native variant selector sheet. Used as the base for the
|
|
108
|
+
* success payload of every variant-picker intent
|
|
109
|
+
* (`select`, `add_to_cart`, `buy_now`).
|
|
110
|
+
*
|
|
111
|
+
* @publicDocs
|
|
112
|
+
*/
|
|
113
|
+
export interface ProductVariantSelection {
|
|
114
|
+
/** The GID of the variant the user picked. */
|
|
115
|
+
productVariantId: string
|
|
116
|
+
/** The full variant the user picked. */
|
|
117
|
+
variant: ProductVariant
|
|
118
|
+
/** The quantity the user chose in the stepper. `1` when the stepper is hidden. */
|
|
119
|
+
quantity: number
|
|
120
|
+
/**
|
|
121
|
+
* Indicates whether the user actively picked a variant in the sheet
|
|
122
|
+
* (`'user'`) or whether the host resolved the selection automatically
|
|
123
|
+
* without showing UI (`'auto'`).
|
|
124
|
+
*
|
|
125
|
+
* `'auto'` is returned when the product has a single selectable variant
|
|
126
|
+
* and `forceShow` is `false` (the default). `'user'` is returned in every
|
|
127
|
+
* other success case — i.e. the sheet was rendered and the user tapped
|
|
128
|
+
* the CTA.
|
|
129
|
+
*/
|
|
130
|
+
source: 'auto' | 'user'
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Successful payload returned from `select:shopify/ProductVariant`. The
|
|
135
|
+
* intent result is `{code: 'ok', data: SelectProductVariantResult}` on
|
|
136
|
+
* success; `{code: 'closed'}` when the user dismisses the sheet.
|
|
137
|
+
*
|
|
138
|
+
* The `outcome` discriminator is single-valued today and is preserved for
|
|
139
|
+
* forward-compatibility — the variant-picker intents (`add_to_cart`,
|
|
140
|
+
* `buy_now`) use the same field to discriminate between multiple success
|
|
141
|
+
* outcomes (e.g. cart added vs. navigated to PDP), and minis can use a
|
|
142
|
+
* single switch over `data.outcome` to handle every intent.
|
|
143
|
+
*
|
|
144
|
+
* @publicDocs
|
|
145
|
+
*/
|
|
146
|
+
export interface SelectProductVariantResult extends ProductVariantSelection {
|
|
147
|
+
/** Discriminator. Currently always `'selected'`. */
|
|
148
|
+
outcome: 'selected'
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
152
|
+
// Add to Cart Intent — add_to_cart:shopify/ProductVariant
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Data payload for the `add_to_cart:shopify/ProductVariant` intent.
|
|
157
|
+
*
|
|
158
|
+
* Adds a variant to the user's cart. If `productVariantId` is omitted (or
|
|
159
|
+
* `forceShow` is `true`), the host opens the same native variant selector
|
|
160
|
+
* sheet as `select:shopify/ProductVariant` first — the user picks a variant
|
|
161
|
+
* and quantity, and the host then performs the add-to-cart on confirm.
|
|
162
|
+
*
|
|
163
|
+
* For products outside Shop's catalog (referral products), the host
|
|
164
|
+
* navigates the user to the product's PDP instead of adding to cart.
|
|
165
|
+
*
|
|
166
|
+
* @publicDocs
|
|
167
|
+
*/
|
|
168
|
+
export interface AddToCartProductVariantParams {
|
|
169
|
+
/**
|
|
170
|
+
* The GID of the product. E.g. `gid://shopify/Product/123`.
|
|
171
|
+
*/
|
|
172
|
+
productId: string
|
|
173
|
+
/**
|
|
174
|
+
* The GID of the variant to add. When provided, the host adds it
|
|
175
|
+
* directly without showing the sheet. Omit to let the user pick.
|
|
176
|
+
*/
|
|
177
|
+
productVariantId?: string
|
|
178
|
+
/** Quantity to add. Defaults to `1`. */
|
|
179
|
+
quantity?: number
|
|
180
|
+
/**
|
|
181
|
+
* Discount codes to apply to the cart when adding.
|
|
182
|
+
*/
|
|
183
|
+
discountCodes?: string[]
|
|
184
|
+
/**
|
|
185
|
+
* Optional allow-list of variant GIDs. When set, only these variants are
|
|
186
|
+
* presented to the user. Other variants are filtered out before the option
|
|
187
|
+
* tree is built. Ignored when `productVariantId` is supplied.
|
|
188
|
+
*/
|
|
189
|
+
includedProductVariantGIDs?: string[]
|
|
190
|
+
/**
|
|
191
|
+
* If present, the GID of the variant that should be initially highlighted
|
|
192
|
+
* in the sheet. Defaults to the product's default variant. Ignored when
|
|
193
|
+
* `productVariantId` is supplied.
|
|
194
|
+
*/
|
|
195
|
+
initialVariantId?: string
|
|
196
|
+
/** Initial quantity displayed in the stepper. Defaults to `quantity ?? 1`. */
|
|
197
|
+
initialQuantity?: number
|
|
198
|
+
/**
|
|
199
|
+
* Maximum quantity selectable in the stepper. Defaults to the variant's
|
|
200
|
+
* `quantityAvailable` (or unbounded when stock is not tracked).
|
|
201
|
+
*/
|
|
202
|
+
maxQuantity?: number
|
|
203
|
+
/** Whether to show the quantity stepper. Defaults to `true`. */
|
|
204
|
+
showQuantity?: boolean
|
|
205
|
+
/**
|
|
206
|
+
* When `true`, always render the sheet — even for products with a single
|
|
207
|
+
* variant or when `productVariantId` is supplied. Bypasses the
|
|
208
|
+
* single-variant short-circuit so the mini gets a consistent confirmation
|
|
209
|
+
* step. Defaults to `false`.
|
|
210
|
+
*/
|
|
211
|
+
forceShow?: boolean
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Variant added to the cart by `add_to_cart:shopify/ProductVariant`.
|
|
216
|
+
*/
|
|
217
|
+
export interface AddToCartAddedResult extends ProductVariantSelection {
|
|
218
|
+
/** Discriminator. The host added a concrete variant to the cart. */
|
|
219
|
+
outcome: 'added_to_cart'
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Returned when the product cannot be added to the cart from the mini
|
|
224
|
+
* (e.g. referral products outside Shop's catalog) and the host instead
|
|
225
|
+
* sent the user to the product's PDP. The mini should treat this as a
|
|
226
|
+
* successful hand-off — the shopper is now on the PDP.
|
|
227
|
+
*/
|
|
228
|
+
export interface AddToCartNavigatedToProductResult {
|
|
229
|
+
/** Discriminator. The host navigated the user to the PDP instead. */
|
|
230
|
+
outcome: 'navigated_to_product'
|
|
231
|
+
/** GID of the product the host navigated to. */
|
|
232
|
+
productId: string
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Successful payload returned from `add_to_cart:shopify/ProductVariant`.
|
|
237
|
+
*
|
|
238
|
+
* Discriminate via `data.outcome`:
|
|
239
|
+
* - `'added_to_cart'` — a concrete variant was added; selection fields
|
|
240
|
+
* (`productVariantId`, `quantity`, `source`) are present.
|
|
241
|
+
* - `'navigated_to_product'` — the host could not add this product (e.g.
|
|
242
|
+
* referral product on another merchant's storefront) and instead sent
|
|
243
|
+
* the user to the PDP. Only `productId` is present.
|
|
244
|
+
*
|
|
245
|
+
* @publicDocs
|
|
246
|
+
*/
|
|
247
|
+
export type AddToCartProductVariantResult =
|
|
248
|
+
| AddToCartAddedResult
|
|
249
|
+
| AddToCartNavigatedToProductResult
|
|
250
|
+
|
|
53
251
|
// ---------------------------------------------------------------------------
|
|
54
252
|
// Intent Registry
|
|
55
253
|
// ---------------------------------------------------------------------------
|
|
@@ -67,6 +265,18 @@ export interface IntentDefinitions {
|
|
|
67
265
|
data: TryOnProductParams
|
|
68
266
|
result: TryOnProductResponse
|
|
69
267
|
}
|
|
268
|
+
selectProductVariant: {
|
|
269
|
+
action: 'select'
|
|
270
|
+
type: 'shopify/ProductVariant'
|
|
271
|
+
data: SelectProductVariantParams
|
|
272
|
+
result: SelectProductVariantResult
|
|
273
|
+
}
|
|
274
|
+
addToCartProductVariant: {
|
|
275
|
+
action: 'add_to_cart'
|
|
276
|
+
type: 'shopify/ProductVariant'
|
|
277
|
+
data: AddToCartProductVariantParams
|
|
278
|
+
result: AddToCartProductVariantResult
|
|
279
|
+
}
|
|
70
280
|
}
|
|
71
281
|
|
|
72
282
|
export type IntentKey = keyof IntentDefinitions
|
|
@@ -81,6 +291,11 @@ export type IntentKey = keyof IntentDefinitions
|
|
|
81
291
|
export const INTENT_REGISTRY = {
|
|
82
292
|
createUserImage: {action: 'create', type: 'shop/UserImage'},
|
|
83
293
|
tryOnProduct: {action: 'try_on', type: 'shopify/Product'},
|
|
294
|
+
selectProductVariant: {action: 'select', type: 'shopify/ProductVariant'},
|
|
295
|
+
addToCartProductVariant: {
|
|
296
|
+
action: 'add_to_cart',
|
|
297
|
+
type: 'shopify/ProductVariant',
|
|
298
|
+
},
|
|
84
299
|
} as const satisfies {
|
|
85
300
|
[K in IntentKey]: {
|
|
86
301
|
action: IntentDefinitions[K]['action']
|
package/src/types/product.ts
CHANGED
|
@@ -13,6 +13,17 @@ export interface ProductImage {
|
|
|
13
13
|
thumbhash?: string | null
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A single (name, value) pair that identifies which value of a product option
|
|
18
|
+
* a variant corresponds to. E.g. `{name: 'Color', value: 'Green'}`.
|
|
19
|
+
*
|
|
20
|
+
* @publicDocs
|
|
21
|
+
*/
|
|
22
|
+
export interface ProductSelectedOption {
|
|
23
|
+
name: string
|
|
24
|
+
value: string
|
|
25
|
+
}
|
|
26
|
+
|
|
16
27
|
export interface ProductVariant {
|
|
17
28
|
id: string
|
|
18
29
|
title: string
|
|
@@ -24,6 +35,13 @@ export interface ProductVariant {
|
|
|
24
35
|
* expose stock state.
|
|
25
36
|
*/
|
|
26
37
|
availableForSale: boolean
|
|
38
|
+
/**
|
|
39
|
+
* The (name, value) pairs of product options this variant corresponds to.
|
|
40
|
+
* E.g. `[{name: 'Color', value: 'Green'}, {name: 'Size', value: 'M'}]`.
|
|
41
|
+
* Optional for backwards compatibility with variants returned by older
|
|
42
|
+
* Shop app hosts; treat as `[]` when undefined.
|
|
43
|
+
*/
|
|
44
|
+
selectedOptions?: ProductSelectedOption[]
|
|
27
45
|
image?: ProductImage | null
|
|
28
46
|
price: Money
|
|
29
47
|
compareAtPrice?: Money | null
|
|
@@ -84,6 +102,21 @@ export type ProductMedia =
|
|
|
84
102
|
alt: string | null
|
|
85
103
|
}
|
|
86
104
|
|
|
105
|
+
/**
|
|
106
|
+
* A configurable product option (e.g. Color, Size) and the set of values it
|
|
107
|
+
* accepts across all variants.
|
|
108
|
+
*
|
|
109
|
+
* @publicDocs
|
|
110
|
+
*/
|
|
111
|
+
export interface ProductOption {
|
|
112
|
+
/** Globally-unique identifier for the option. */
|
|
113
|
+
id?: string
|
|
114
|
+
/** The display name of the option. E.g. `Color`. */
|
|
115
|
+
name: string
|
|
116
|
+
/** All possible values for the option across variants. E.g. `['Red', 'Blue']`. */
|
|
117
|
+
values: string[]
|
|
118
|
+
}
|
|
119
|
+
|
|
87
120
|
export interface Product {
|
|
88
121
|
id: string
|
|
89
122
|
title: string
|
|
@@ -96,6 +129,12 @@ export interface Product {
|
|
|
96
129
|
defaultVariantId: string
|
|
97
130
|
isFavorited: boolean
|
|
98
131
|
variants?: ProductVariant[]
|
|
132
|
+
/**
|
|
133
|
+
* The product's configurable options (e.g. Color, Size). Optional for
|
|
134
|
+
* backwards compatibility with products returned by older Shop app hosts;
|
|
135
|
+
* treat as `[]` when undefined.
|
|
136
|
+
*/
|
|
137
|
+
options?: ProductOption[]
|
|
99
138
|
featuredImage?: ProductImage | null
|
|
100
139
|
price: Money
|
|
101
140
|
compareAtPrice?: Money | null
|