@shopify/shop-minis-platform 0.13.0 → 0.15.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 +7 -3
- package/src/actions/actions.ts +5 -0
- package/src/actions/index.ts +2 -0
- package/src/actions/intent-definitions.ts +52 -0
- package/src/actions/intents.ts +104 -0
- package/src/actions/params.ts +27 -0
- package/src/actions/scopes.ts +1 -1
- package/src/types/minis.ts +1 -0
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopify/shop-minis-platform",
|
|
3
3
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"description": "Shared type definitions for Shop Minis Platform",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.ts",
|
|
9
|
+
"./package.json": "./package.json",
|
|
9
10
|
"./actions": "./src/actions/index.ts",
|
|
10
11
|
"./events": "./src/events/index.ts"
|
|
11
12
|
},
|
|
@@ -20,7 +21,9 @@
|
|
|
20
21
|
],
|
|
21
22
|
"dependencies": {},
|
|
22
23
|
"peerDependencies": {},
|
|
23
|
-
"devDependencies": {
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.8.3"
|
|
26
|
+
},
|
|
24
27
|
"author": "Shopify",
|
|
25
28
|
"repository": {
|
|
26
29
|
"type": "git",
|
|
@@ -29,6 +32,7 @@
|
|
|
29
32
|
},
|
|
30
33
|
"scripts": {
|
|
31
34
|
"test": "TZ=UTC jest",
|
|
32
|
-
"type-check": "tsc --noEmit"
|
|
35
|
+
"type-check": "tsc --noEmit",
|
|
36
|
+
"typecheck": "pnpm run type-check"
|
|
33
37
|
}
|
|
34
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,
|
|
@@ -93,6 +94,8 @@ import {
|
|
|
93
94
|
ShareSingleResponse,
|
|
94
95
|
RequestPermissionParams,
|
|
95
96
|
RequestPermissionResponse,
|
|
97
|
+
CheckPermissionParams,
|
|
98
|
+
CheckPermissionResponse,
|
|
96
99
|
ReportErrorParams,
|
|
97
100
|
ReportFetchParams,
|
|
98
101
|
} from './params'
|
|
@@ -235,6 +238,8 @@ export interface ShopActionEvents {
|
|
|
235
238
|
RequestPermissionParams,
|
|
236
239
|
RequestPermissionResponse
|
|
237
240
|
>
|
|
241
|
+
CHECK_PERMISSION: ShopAction<CheckPermissionParams, CheckPermissionResponse>
|
|
238
242
|
REPORT_ERROR: ShopAction<ReportErrorParams, void>
|
|
239
243
|
REPORT_FETCH: ShopAction<ReportFetchParams, void>
|
|
244
|
+
INVOKE_INTENT: ShopAction<InvokeIntentParams, InvokeIntentResponse>
|
|
240
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
|
+
>
|
package/src/actions/params.ts
CHANGED
|
@@ -34,6 +34,33 @@ export interface RequestPermissionResponse {
|
|
|
34
34
|
errorMessage?: string
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* The current state of a permission for the Mini.
|
|
39
|
+
*
|
|
40
|
+
* - `granted`: The user has approved the in-app consent dialog and the OS has granted the permission.
|
|
41
|
+
* - `denied`: The user has previously denied the permission, either in the in-app consent dialog or at the OS level. The permission can still be requested again.
|
|
42
|
+
* - `blocked`: The permission is blocked at the OS level. The user must enable it from device settings.
|
|
43
|
+
* - `undetermined`: The user has not yet been shown the in-app consent dialog for this permission.
|
|
44
|
+
* - `unavailable`: The permission is not declared in the Mini's manifest, or the feature is not available on this device.
|
|
45
|
+
*
|
|
46
|
+
* @publicDocs
|
|
47
|
+
*/
|
|
48
|
+
export type PermissionStatus =
|
|
49
|
+
| 'granted'
|
|
50
|
+
| 'denied'
|
|
51
|
+
| 'blocked'
|
|
52
|
+
| 'undetermined'
|
|
53
|
+
| 'unavailable'
|
|
54
|
+
|
|
55
|
+
export interface CheckPermissionParams {
|
|
56
|
+
permission: MiniPermission
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface CheckPermissionResponse {
|
|
60
|
+
status: PermissionStatus
|
|
61
|
+
errorMessage?: string
|
|
62
|
+
}
|
|
63
|
+
|
|
37
64
|
export interface FavoriteParams {
|
|
38
65
|
shopId: string
|
|
39
66
|
productId: string
|
package/src/actions/scopes.ts
CHANGED
package/src/types/minis.ts
CHANGED