@shopify/shop-minis-platform 0.19.0 → 0.20.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.19.0",
4
+ "version": "0.20.0",
5
5
  "description": "Shared type definitions for Shop Minis Platform",
6
6
  "main": "src/index.ts",
7
7
  "exports": {
@@ -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,102 @@ 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
+
53
151
  // ---------------------------------------------------------------------------
54
152
  // Intent Registry
55
153
  // ---------------------------------------------------------------------------
@@ -67,6 +165,12 @@ export interface IntentDefinitions {
67
165
  data: TryOnProductParams
68
166
  result: TryOnProductResponse
69
167
  }
168
+ selectProductVariant: {
169
+ action: 'select'
170
+ type: 'shopify/ProductVariant'
171
+ data: SelectProductVariantParams
172
+ result: SelectProductVariantResult
173
+ }
70
174
  }
71
175
 
72
176
  export type IntentKey = keyof IntentDefinitions
@@ -81,6 +185,7 @@ export type IntentKey = keyof IntentDefinitions
81
185
  export const INTENT_REGISTRY = {
82
186
  createUserImage: {action: 'create', type: 'shop/UserImage'},
83
187
  tryOnProduct: {action: 'try_on', type: 'shopify/Product'},
188
+ selectProductVariant: {action: 'select', type: 'shopify/ProductVariant'},
84
189
  } as const satisfies {
85
190
  [K in IntentKey]: {
86
191
  action: IntentDefinitions[K]['action']
@@ -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