@shopify/shop-minis-platform 0.20.0 → 0.22.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
|
@@ -148,6 +148,189 @@ export interface SelectProductVariantResult extends ProductVariantSelection {
|
|
|
148
148
|
outcome: 'selected'
|
|
149
149
|
}
|
|
150
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
|
+
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
252
|
+
// Buy Now Intent — buy_now:shopify/ProductVariant
|
|
253
|
+
// ---------------------------------------------------------------------------
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Data payload for the `buy_now:shopify/ProductVariant` intent.
|
|
257
|
+
*
|
|
258
|
+
* Sends the user to express checkout for a variant, bypassing the cart. If
|
|
259
|
+
* `productVariantId` is omitted (or `forceShow` is `true`), the host opens
|
|
260
|
+
* the same native variant selector sheet as the other variant intents — the
|
|
261
|
+
* user picks a variant and quantity, and the host then creates the checkout
|
|
262
|
+
* on confirm.
|
|
263
|
+
*
|
|
264
|
+
* For products outside Shop's catalog (referral products), the host
|
|
265
|
+
* navigates the user to the product's PDP instead.
|
|
266
|
+
*
|
|
267
|
+
* @publicDocs
|
|
268
|
+
*/
|
|
269
|
+
export interface BuyNowProductVariantParams {
|
|
270
|
+
/** The GID of the product. E.g. `gid://shopify/Product/123`. */
|
|
271
|
+
productId: string
|
|
272
|
+
/**
|
|
273
|
+
* The GID of the variant to buy. When provided, the host creates the
|
|
274
|
+
* checkout directly without showing the sheet. Omit to let the user pick.
|
|
275
|
+
*/
|
|
276
|
+
productVariantId?: string
|
|
277
|
+
/** Quantity to buy. Defaults to `1`. */
|
|
278
|
+
quantity?: number
|
|
279
|
+
/** Discount code to apply to the checkout. */
|
|
280
|
+
discountCode?: string
|
|
281
|
+
/** Allow-list of variant GIDs surfaced in the sheet. */
|
|
282
|
+
includedProductVariantGIDs?: string[]
|
|
283
|
+
/** Variant initially highlighted in the picker. */
|
|
284
|
+
initialVariantId?: string
|
|
285
|
+
/** Initial quantity in the stepper. Defaults to `quantity ?? 1`. */
|
|
286
|
+
initialQuantity?: number
|
|
287
|
+
/** Max quantity selectable in the stepper. */
|
|
288
|
+
maxQuantity?: number
|
|
289
|
+
/** Whether to show the quantity stepper. Defaults to `true`. */
|
|
290
|
+
showQuantity?: boolean
|
|
291
|
+
/**
|
|
292
|
+
* When `true`, always render the sheet — even for single-variant products
|
|
293
|
+
* or when `productVariantId` is supplied. Defaults to `false`.
|
|
294
|
+
*/
|
|
295
|
+
forceShow?: boolean
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Checkout opened for a concrete variant by `buy_now:shopify/ProductVariant`.
|
|
300
|
+
*/
|
|
301
|
+
export interface BuyNowCheckoutOpenedResult extends ProductVariantSelection {
|
|
302
|
+
/** Discriminator. The host opened express checkout for a variant. */
|
|
303
|
+
outcome: 'checkout_opened'
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Returned when the product cannot be bought from the mini (e.g. referral
|
|
308
|
+
* products outside Shop's catalog) and the host instead sent the user to
|
|
309
|
+
* the product's PDP. The mini should treat this as a successful hand-off.
|
|
310
|
+
*/
|
|
311
|
+
export interface BuyNowNavigatedToProductResult {
|
|
312
|
+
/** Discriminator. The host navigated the user to the PDP instead. */
|
|
313
|
+
outcome: 'navigated_to_product'
|
|
314
|
+
/** GID of the product the host navigated to. */
|
|
315
|
+
productId: string
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Successful payload returned from `buy_now:shopify/ProductVariant`.
|
|
320
|
+
*
|
|
321
|
+
* Discriminate via `data.outcome`:
|
|
322
|
+
* - `'checkout_opened'` — express checkout opened for a concrete variant;
|
|
323
|
+
* selection fields (`productVariantId`, `quantity`, `source`) are present.
|
|
324
|
+
* - `'navigated_to_product'` — the host could not buy this product (e.g.
|
|
325
|
+
* referral product on another merchant's storefront) and instead sent
|
|
326
|
+
* the user to the PDP. Only `productId` is present.
|
|
327
|
+
*
|
|
328
|
+
* @publicDocs
|
|
329
|
+
*/
|
|
330
|
+
export type BuyNowProductVariantResult =
|
|
331
|
+
| BuyNowCheckoutOpenedResult
|
|
332
|
+
| BuyNowNavigatedToProductResult
|
|
333
|
+
|
|
151
334
|
// ---------------------------------------------------------------------------
|
|
152
335
|
// Intent Registry
|
|
153
336
|
// ---------------------------------------------------------------------------
|
|
@@ -171,6 +354,18 @@ export interface IntentDefinitions {
|
|
|
171
354
|
data: SelectProductVariantParams
|
|
172
355
|
result: SelectProductVariantResult
|
|
173
356
|
}
|
|
357
|
+
addToCartProductVariant: {
|
|
358
|
+
action: 'add_to_cart'
|
|
359
|
+
type: 'shopify/ProductVariant'
|
|
360
|
+
data: AddToCartProductVariantParams
|
|
361
|
+
result: AddToCartProductVariantResult
|
|
362
|
+
}
|
|
363
|
+
buyNowProductVariant: {
|
|
364
|
+
action: 'buy_now'
|
|
365
|
+
type: 'shopify/ProductVariant'
|
|
366
|
+
data: BuyNowProductVariantParams
|
|
367
|
+
result: BuyNowProductVariantResult
|
|
368
|
+
}
|
|
174
369
|
}
|
|
175
370
|
|
|
176
371
|
export type IntentKey = keyof IntentDefinitions
|
|
@@ -186,6 +381,14 @@ export const INTENT_REGISTRY = {
|
|
|
186
381
|
createUserImage: {action: 'create', type: 'shop/UserImage'},
|
|
187
382
|
tryOnProduct: {action: 'try_on', type: 'shopify/Product'},
|
|
188
383
|
selectProductVariant: {action: 'select', type: 'shopify/ProductVariant'},
|
|
384
|
+
addToCartProductVariant: {
|
|
385
|
+
action: 'add_to_cart',
|
|
386
|
+
type: 'shopify/ProductVariant',
|
|
387
|
+
},
|
|
388
|
+
buyNowProductVariant: {
|
|
389
|
+
action: 'buy_now',
|
|
390
|
+
type: 'shopify/ProductVariant',
|
|
391
|
+
},
|
|
189
392
|
} as const satisfies {
|
|
190
393
|
[K in IntentKey]: {
|
|
191
394
|
action: IntentDefinitions[K]['action']
|