@shopify/shop-minis-platform 0.18.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 +3 -3
- package/src/actions/actions.ts +6 -0
- package/src/actions/intent-definitions.ts +105 -0
- package/src/actions/params.ts +56 -0
- package/src/types/product.ts +39 -0
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.
|
|
4
|
+
"version": "0.20.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": "
|
|
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": "^
|
|
30
|
+
"typescript": "^6.0.3"
|
|
31
31
|
},
|
|
32
32
|
"author": "Shopify",
|
|
33
33
|
"repository": {
|
package/src/actions/actions.ts
CHANGED
|
@@ -71,6 +71,8 @@ import {
|
|
|
71
71
|
GetRecentProductsResponse,
|
|
72
72
|
GetProductSearchParams,
|
|
73
73
|
GetProductSearchResponse,
|
|
74
|
+
GetSimilarProductsParams,
|
|
75
|
+
GetSimilarProductsResponse,
|
|
74
76
|
GetProductsParams,
|
|
75
77
|
GetProductsResponse,
|
|
76
78
|
GetProductParams,
|
|
@@ -218,6 +220,10 @@ export interface ShopActionEvents {
|
|
|
218
220
|
GetProductSearchParams,
|
|
219
221
|
GetProductSearchResponse
|
|
220
222
|
>
|
|
223
|
+
GET_SIMILAR_PRODUCTS: ShopAction<
|
|
224
|
+
GetSimilarProductsParams,
|
|
225
|
+
GetSimilarProductsResponse
|
|
226
|
+
>
|
|
221
227
|
GET_PRODUCTS: ShopAction<GetProductsParams, GetProductsResponse>
|
|
222
228
|
GET_PRODUCT: ShopAction<GetProductParams, GetProductResponse>
|
|
223
229
|
GET_PRODUCT_VARIANTS: ShopAction<
|
|
@@ -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']
|
package/src/actions/params.ts
CHANGED
|
@@ -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/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
|