@shopify/shop-minis-platform 0.14.1 → 0.15.1
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.
|
|
4
|
+
"version": "0.15.1",
|
|
5
5
|
"description": "Shared type definitions for Shop Minis Platform",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"exports": {
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"README.md",
|
|
20
20
|
"LICENSE.txt"
|
|
21
21
|
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "TZ=UTC jest",
|
|
24
|
+
"type-check": "tsc --noEmit",
|
|
25
|
+
"typecheck": "pnpm run type-check"
|
|
26
|
+
},
|
|
22
27
|
"dependencies": {},
|
|
23
28
|
"peerDependencies": {},
|
|
24
29
|
"devDependencies": {
|
|
@@ -29,10 +34,5 @@
|
|
|
29
34
|
"type": "git",
|
|
30
35
|
"url": "https://github.com/Shopify/shop-client.git",
|
|
31
36
|
"directory": "packages/minis/shop-minis-platform"
|
|
32
|
-
},
|
|
33
|
-
"scripts": {
|
|
34
|
-
"test": "TZ=UTC jest",
|
|
35
|
-
"type-check": "tsc --noEmit",
|
|
36
|
-
"typecheck": "pnpm run type-check"
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|
package/src/actions/actions.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {ProductList} from '../types'
|
|
2
2
|
|
|
3
|
+
import {InvokeIntentParams, InvokeIntentResponse} from './intents'
|
|
3
4
|
import {
|
|
4
5
|
FollowShopParams,
|
|
5
6
|
UnfollowShopParams,
|
|
@@ -240,4 +241,5 @@ export interface ShopActionEvents {
|
|
|
240
241
|
CHECK_PERMISSION: ShopAction<CheckPermissionParams, CheckPermissionResponse>
|
|
241
242
|
REPORT_ERROR: ShopAction<ReportErrorParams, void>
|
|
242
243
|
REPORT_FETCH: ShopAction<ReportFetchParams, void>
|
|
244
|
+
INVOKE_INTENT: ShopAction<InvokeIntentParams, InvokeIntentResponse>
|
|
243
245
|
}
|
package/src/actions/index.ts
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// User Image Intent — create:shop/UserImage
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
export interface CreateUserImageParams {
|
|
6
|
+
/**
|
|
7
|
+
* Tag identifying the image in the mini's image library. Required so a
|
|
8
|
+
* future saved-images intent can surface previously created images by tag.
|
|
9
|
+
*/
|
|
10
|
+
tag: string
|
|
11
|
+
/**
|
|
12
|
+
* If set, skip the source chooser and open this source directly.
|
|
13
|
+
* When omitted, the host shows a sheet letting the user pick a source.
|
|
14
|
+
*/
|
|
15
|
+
source?: 'camera' | 'library'
|
|
16
|
+
/** Which camera to default to when the camera is used. Defaults to 'front'. */
|
|
17
|
+
camera?: 'front' | 'rear'
|
|
18
|
+
/**
|
|
19
|
+
* Cropping configuration. Omit to skip the cropping step — the user's
|
|
20
|
+
* original photo is returned as-is (capped by `maxSize`).
|
|
21
|
+
*/
|
|
22
|
+
crop?: {
|
|
23
|
+
/**
|
|
24
|
+
* Fixed aspect ratio enforced by the cropper. Omit for free-form crop.
|
|
25
|
+
* e.g. `{width: 1, height: 1}` for a square, `{width: 16, height: 9}` for widescreen.
|
|
26
|
+
*/
|
|
27
|
+
aspectRatio?: {width: number; height: number}
|
|
28
|
+
/** Overlay shape shown to the user. Defaults to 'rectangle'. */
|
|
29
|
+
shape?: 'rectangle' | 'circle'
|
|
30
|
+
}
|
|
31
|
+
/** Max width/height of the output image in pixels. Defaults to 700. */
|
|
32
|
+
maxSize?: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface CreateUserImageResponse {
|
|
36
|
+
imageUrl: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Intent Registry
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
export interface IntentDefinitions {
|
|
44
|
+
createUserImage: {
|
|
45
|
+
action: 'create'
|
|
46
|
+
type: 'shop/UserImage'
|
|
47
|
+
data: CreateUserImageParams
|
|
48
|
+
result: CreateUserImageResponse
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type IntentKey = keyof IntentDefinitions
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic intent type definitions for Shop Minis.
|
|
3
|
+
*
|
|
4
|
+
* These types define the shared contract for intent invocations
|
|
5
|
+
* across the Minis ecosystem (Mini → Host, Host → Mini, Mini → Mini).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {IntentDefinitions, IntentKey} from './intent-definitions'
|
|
9
|
+
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Intent query types
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
export interface IntentQueryOptions<TData = unknown> {
|
|
15
|
+
/** Optional identifier (e.g. a resource GID) for an existing resource */
|
|
16
|
+
value?: string
|
|
17
|
+
/** Optional JSON-serializable input payload */
|
|
18
|
+
data?: TData
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Structured description of an intent to invoke.
|
|
23
|
+
*
|
|
24
|
+
* Pairs an action verb with a resource type and optional inputs.
|
|
25
|
+
*/
|
|
26
|
+
export interface IntentQuery<
|
|
27
|
+
TData = unknown,
|
|
28
|
+
> extends IntentQueryOptions<TData> {
|
|
29
|
+
/** Verb describing the operation (e.g., 'create', 'edit', 'view') */
|
|
30
|
+
action: string
|
|
31
|
+
/** MIME-type identifier for the target resource (e.g., 'shop/UserImage') */
|
|
32
|
+
type: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Params for the INVOKE_INTENT shop action.
|
|
37
|
+
*/
|
|
38
|
+
export type InvokeIntentParams = IntentQuery<any>
|
|
39
|
+
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Intent result types
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
export interface IntentResultOk<T> {
|
|
45
|
+
code: 'ok'
|
|
46
|
+
data: T
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface IntentResultError {
|
|
50
|
+
code: 'error'
|
|
51
|
+
message: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface IntentResultClosed {
|
|
55
|
+
code: 'closed'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Discriminated union of all possible intent completion outcomes.
|
|
60
|
+
* - `'ok'` — workflow completed successfully with typed result data
|
|
61
|
+
* - `'error'` — workflow failed with a message
|
|
62
|
+
* - `'closed'` — user dismissed without completing
|
|
63
|
+
*/
|
|
64
|
+
export type IntentResult<T = {[key: string]: unknown}> =
|
|
65
|
+
| IntentResultOk<T>
|
|
66
|
+
| IntentResultError
|
|
67
|
+
| IntentResultClosed
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Params passed to an individual intent handler.
|
|
71
|
+
*/
|
|
72
|
+
export interface IntentActionParams<TData> {
|
|
73
|
+
/** Resource identifier (e.g. a Shopify GID), or null for creation flows. */
|
|
74
|
+
value: string | null
|
|
75
|
+
/** Optional typed input payload. */
|
|
76
|
+
data?: TData
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A generic type for individual intent implementations.
|
|
81
|
+
*/
|
|
82
|
+
export type IntentAction<TData, TResult> = (
|
|
83
|
+
params: IntentActionParams<TData>
|
|
84
|
+
) => Promise<IntentResult<TResult>>
|
|
85
|
+
|
|
86
|
+
/** Untyped intent response used at the INVOKE_INTENT bridge boundary. */
|
|
87
|
+
export type InvokeIntentResponse = IntentResult
|
|
88
|
+
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
// Typed intent utilities — leverage IntentDefinitions for per-intent safety
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
|
|
93
|
+
/** Type-safe intent query for a registered intent. */
|
|
94
|
+
export type TypedIntentQuery<K extends IntentKey> = IntentQuery<
|
|
95
|
+
IntentDefinitions[K]['data']
|
|
96
|
+
> & {
|
|
97
|
+
action: IntentDefinitions[K]['action']
|
|
98
|
+
type: IntentDefinitions[K]['type']
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Full typed response for a registered intent, narrowable on `code`. */
|
|
102
|
+
export type TypedIntentResponse<K extends IntentKey> = IntentResult<
|
|
103
|
+
IntentDefinitions[K]['result']
|
|
104
|
+
>
|