@heybox/hb-sdk-protocol 0.8.3-alpha.2 → 0.8.3-alpha.4
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/README.md +20 -0
- package/dist/index.cjs.js +287 -163
- package/dist/index.esm.js +283 -164
- package/generated/permission-catalog.json +2 -1
- package/package.json +1 -1
- package/src/bridge.ts +8 -0
- package/src/capabilities.ts +13 -0
- package/src/index.ts +1 -0
- package/src/local-dev-grant.ts +141 -0
- package/src/payloads.ts +21 -0
- package/src/permission-catalog.ts +1 -0
- package/types/bridge.d.ts +7 -1
- package/types/capabilities.d.ts +13 -2
- package/types/index.d.ts +1 -0
- package/types/local-dev-grant.d.ts +63 -0
- package/types/payloads.d.ts +20 -0
- package/types/permission-catalog.d.ts +1 -1
package/src/capabilities.ts
CHANGED
|
@@ -91,6 +91,8 @@ import type {
|
|
|
91
91
|
SaveFileResult,
|
|
92
92
|
SetClipboardPayload,
|
|
93
93
|
SetClipboardResult,
|
|
94
|
+
SetDisplayPayload,
|
|
95
|
+
SetDisplayResult,
|
|
94
96
|
SetNavigationBarStylePayload,
|
|
95
97
|
SetNavigationBarStyleResult,
|
|
96
98
|
SetStoragePayload,
|
|
@@ -114,6 +116,7 @@ export const USER_GET_STEAM_GAME_LIST_METHOD = 'user.getSteamGameList' as const;
|
|
|
114
116
|
export const SHARE_COPY_LINK_METHOD = 'share.copyLink' as const;
|
|
115
117
|
export const SHARE_SHOW_SHARE_MENU_METHOD = 'share.showShareMenu' as const;
|
|
116
118
|
export const SHARE_SCREENSHOT_METHOD = 'share.screenshot' as const;
|
|
119
|
+
export const VIEWPORT_SET_DISPLAY_METHOD = 'viewport.setDisplay' as const;
|
|
117
120
|
export const VIEWPORT_GET_WINDOW_INFO_METHOD = 'viewport.getWindowInfo' as const;
|
|
118
121
|
export const VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD = 'viewport.setNavigationBarStyle' as const;
|
|
119
122
|
export const STORAGE_GET_STORAGE_METHOD = 'storage.getStorage' as const;
|
|
@@ -165,6 +168,7 @@ export type MiniProgramAuthMethod = typeof AUTH_LOGIN_METHOD;
|
|
|
165
168
|
export type MiniProgramUserMethod = typeof USER_GET_INFO_METHOD | typeof USER_REVOKE_AUTHORIZATION_METHOD | typeof USER_GET_STEAM_GAME_LIST_METHOD;
|
|
166
169
|
export type MiniProgramShareMethod = typeof SHARE_COPY_LINK_METHOD | typeof SHARE_SHOW_SHARE_MENU_METHOD | typeof SHARE_SCREENSHOT_METHOD;
|
|
167
170
|
export type MiniProgramViewportMethod =
|
|
171
|
+
| typeof VIEWPORT_SET_DISPLAY_METHOD
|
|
168
172
|
| typeof VIEWPORT_GET_WINDOW_INFO_METHOD
|
|
169
173
|
| typeof VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD;
|
|
170
174
|
export type MiniProgramStorageMethod = typeof STORAGE_GET_STORAGE_METHOD | typeof STORAGE_SET_STORAGE_METHOD;
|
|
@@ -329,6 +333,13 @@ export const MINI_PROGRAM_PROTOCOL_CAPABILITIES = [
|
|
|
329
333
|
requirement: { kind: 'none' },
|
|
330
334
|
risk: 'low',
|
|
331
335
|
},
|
|
336
|
+
{
|
|
337
|
+
method: VIEWPORT_SET_DISPLAY_METHOD,
|
|
338
|
+
module: 'viewport',
|
|
339
|
+
capability: VIEWPORT_SET_DISPLAY_METHOD,
|
|
340
|
+
requirement: { kind: 'none' },
|
|
341
|
+
risk: 'low',
|
|
342
|
+
},
|
|
332
343
|
{
|
|
333
344
|
method: STORAGE_GET_STORAGE_METHOD,
|
|
334
345
|
module: 'storage',
|
|
@@ -541,6 +552,7 @@ export interface MiniProgramCapabilityPayloadMap {
|
|
|
541
552
|
[SHARE_COPY_LINK_METHOD]: CopyLinkPayload;
|
|
542
553
|
[SHARE_SHOW_SHARE_MENU_METHOD]: ShowShareMenuPayload;
|
|
543
554
|
[SHARE_SCREENSHOT_METHOD]: ScreenshotPayload;
|
|
555
|
+
[VIEWPORT_SET_DISPLAY_METHOD]: SetDisplayPayload;
|
|
544
556
|
[VIEWPORT_GET_WINDOW_INFO_METHOD]: GetWindowInfoPayload;
|
|
545
557
|
[VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD]: SetNavigationBarStylePayload;
|
|
546
558
|
[STORAGE_GET_STORAGE_METHOD]: GetStoragePayload;
|
|
@@ -597,6 +609,7 @@ export interface MiniProgramCapabilityResultMap {
|
|
|
597
609
|
[SHARE_COPY_LINK_METHOD]: CopyLinkResult;
|
|
598
610
|
[SHARE_SHOW_SHARE_MENU_METHOD]: ShowShareMenuResult;
|
|
599
611
|
[SHARE_SCREENSHOT_METHOD]: ScreenshotResult;
|
|
612
|
+
[VIEWPORT_SET_DISPLAY_METHOD]: SetDisplayResult;
|
|
600
613
|
[VIEWPORT_GET_WINDOW_INFO_METHOD]: GetWindowInfoResult;
|
|
601
614
|
[VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD]: SetNavigationBarStyleResult;
|
|
602
615
|
[STORAGE_GET_STORAGE_METHOD]: GetStorageResult;
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { MINI_PROGRAM_PERMISSION_KEYS, type MiniProgramPermissionKey } from './permission-catalog';
|
|
2
|
+
import { parseMiniProgramRuntimePermissions, type MiniProgramRuntimePermissionsSnapshot } from './permissions';
|
|
3
|
+
|
|
4
|
+
/** 仅供开发工具和 Host 使用;新增权限必须单独评估,不能从平台审批目录自动推导。 */
|
|
5
|
+
export const LOCAL_DEV_GRANT_PERMISSION_KEYS = ['network', 'companion'] as const;
|
|
6
|
+
export type MiniProgramLocalDevPermissionKey = (typeof LOCAL_DEV_GRANT_PERMISSION_KEYS)[number];
|
|
7
|
+
export type MiniProgramLocalDevGrantEntry =
|
|
8
|
+
| { key: 'network'; status: 'enabled'; config: { useOfficialDomain: false } }
|
|
9
|
+
| { key: 'companion'; status: 'enabled'; config: Record<string, never> };
|
|
10
|
+
|
|
11
|
+
/** CLI-owned Dev Context 合同,不属于小程序业务 API 或线上批准快照。 */
|
|
12
|
+
export interface MiniProgramLocalDevGrant {
|
|
13
|
+
schema_version: 1;
|
|
14
|
+
revision: number;
|
|
15
|
+
entries: MiniProgramLocalDevGrantEntry[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 调用方已校验的本地声明;不存在的权限不会从 grant 获得授权。 */
|
|
19
|
+
export type MiniProgramLocalDevPermissionDeclarations = Partial<
|
|
20
|
+
Record<MiniProgramPermissionKey, { enabled: boolean; useOfficialDomain?: boolean }>
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
export type ParsedMiniProgramLocalDevGrant =
|
|
24
|
+
| { valid: true; grant: MiniProgramLocalDevGrant }
|
|
25
|
+
| { valid: false; grant?: undefined };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 严格解析本地 grant。任何未知字段、重复权限或非法配置都拒绝整份输入。
|
|
29
|
+
* 只校验数据合同;票据、身份、摘要、过期时间和 CLI lease 必须由 Host 另行验证。
|
|
30
|
+
*/
|
|
31
|
+
export function parseMiniProgramLocalDevGrant(value: unknown): ParsedMiniProgramLocalDevGrant {
|
|
32
|
+
if (
|
|
33
|
+
!hasExactFields(value, ['schema_version', 'revision', 'entries']) ||
|
|
34
|
+
value.schema_version !== 1 ||
|
|
35
|
+
typeof value.revision !== 'number' ||
|
|
36
|
+
!Number.isSafeInteger(value.revision) ||
|
|
37
|
+
value.revision < 0 ||
|
|
38
|
+
!Array.isArray(value.entries) ||
|
|
39
|
+
value.entries.length > LOCAL_DEV_GRANT_PERMISSION_KEYS.length
|
|
40
|
+
) return { valid: false };
|
|
41
|
+
|
|
42
|
+
const entries: MiniProgramLocalDevGrantEntry[] = [];
|
|
43
|
+
const seen = new Set<string>();
|
|
44
|
+
for (const entry of value.entries) {
|
|
45
|
+
if (!hasExactFields(entry, ['key', 'status', 'config']) || entry.status !== 'enabled') return { valid: false };
|
|
46
|
+
if (typeof entry.key !== 'string' || seen.has(entry.key)) return { valid: false };
|
|
47
|
+
seen.add(entry.key);
|
|
48
|
+
if (entry.key === 'network') {
|
|
49
|
+
if (!hasExactFields(entry.config, ['useOfficialDomain']) || entry.config.useOfficialDomain !== false) return { valid: false };
|
|
50
|
+
entries.push({ key: 'network', status: 'enabled', config: { useOfficialDomain: false } });
|
|
51
|
+
} else if (entry.key === 'companion') {
|
|
52
|
+
if (!hasExactFields(entry.config, [])) return { valid: false };
|
|
53
|
+
entries.push({ key: 'companion', status: 'enabled', config: {} });
|
|
54
|
+
} else {
|
|
55
|
+
return { valid: false };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
entries.sort((a, b) => LOCAL_DEV_GRANT_PERMISSION_KEYS.indexOf(a.key) - LOCAL_DEV_GRANT_PERMISSION_KEYS.indexOf(b.key));
|
|
59
|
+
return { valid: true, grant: { schema_version: 1, revision: value.revision, entries } };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 从已校验声明生成批准缺口。Companion 默认不符合资格,由 CLI 确认平台、产物与摘要后显式加入。
|
|
64
|
+
* 空 entries 可保留 revision,不能作为存在临时权限的判断依据。
|
|
65
|
+
*/
|
|
66
|
+
export function createMiniProgramLocalDevGrant(options: {
|
|
67
|
+
declaredPermissions: MiniProgramLocalDevPermissionDeclarations;
|
|
68
|
+
runtimePermissions: unknown;
|
|
69
|
+
revision: number;
|
|
70
|
+
eligiblePermissionKeys?: readonly MiniProgramLocalDevPermissionKey[];
|
|
71
|
+
}): MiniProgramLocalDevGrant {
|
|
72
|
+
if (!Number.isSafeInteger(options.revision) || options.revision < 0) throw new Error('本地调试权限 revision 必须是非负安全整数');
|
|
73
|
+
const approvals = parseMiniProgramRuntimePermissions(options.runtimePermissions);
|
|
74
|
+
const eligible = new Set(options.eligiblePermissionKeys ?? ['network']);
|
|
75
|
+
const entries: MiniProgramLocalDevGrantEntry[] = [];
|
|
76
|
+
for (const key of LOCAL_DEV_GRANT_PERMISSION_KEYS) {
|
|
77
|
+
if (!eligible.has(key) || options.declaredPermissions[key]?.enabled !== true) continue;
|
|
78
|
+
if (approvals.valid && approvals.permissions[key]?.status === 'enabled') continue;
|
|
79
|
+
entries.push(key === 'network'
|
|
80
|
+
? { key, status: 'enabled', config: { useOfficialDomain: false } }
|
|
81
|
+
: { key, status: 'enabled', config: {} });
|
|
82
|
+
}
|
|
83
|
+
return { schema_version: 1, revision: options.revision, entries };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 线上基线先与本地声明求交,再补齐临时权限,返回与输入脱离的普通 Runtime 快照。
|
|
88
|
+
* 调用方只可在当前 Dev Session 已验证且用户接受后传入 grant;本函数不证明其可信来源。
|
|
89
|
+
* 非法 grant 整体降权到基线,已批准配置不会被临时配置覆盖。
|
|
90
|
+
*/
|
|
91
|
+
export function composeLocalDevRuntimePermissions(options: {
|
|
92
|
+
declaredPermissions: MiniProgramLocalDevPermissionDeclarations;
|
|
93
|
+
runtimePermissions: unknown;
|
|
94
|
+
localDevGrant?: unknown;
|
|
95
|
+
}): {
|
|
96
|
+
runtimePermissions: MiniProgramRuntimePermissionsSnapshot;
|
|
97
|
+
temporaryPermissionKeys: MiniProgramLocalDevPermissionKey[];
|
|
98
|
+
grantValid: boolean;
|
|
99
|
+
} {
|
|
100
|
+
const baseline = parseMiniProgramRuntimePermissions(options.runtimePermissions);
|
|
101
|
+
const parsed = parseMiniProgramLocalDevGrant(options.localDevGrant);
|
|
102
|
+
const permissions = baseline.valid ? baseline.permissions : {};
|
|
103
|
+
for (const key of MINI_PROGRAM_PERMISSION_KEYS) {
|
|
104
|
+
if (options.declaredPermissions[key]?.enabled !== true) {
|
|
105
|
+
delete permissions[key];
|
|
106
|
+
} else if (key === 'network' && permissions.network) {
|
|
107
|
+
permissions.network.config.useOfficialDomain = permissions.network.status === 'enabled'
|
|
108
|
+
&& permissions.network.config.useOfficialDomain === true
|
|
109
|
+
&& options.declaredPermissions.network?.useOfficialDomain === true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const temporaryPermissionKeys: MiniProgramLocalDevPermissionKey[] = [];
|
|
113
|
+
if (parsed.valid) {
|
|
114
|
+
for (const entry of parsed.grant.entries) {
|
|
115
|
+
if (options.declaredPermissions[entry.key]?.enabled !== true || permissions[entry.key]?.status === 'enabled') continue;
|
|
116
|
+
permissions[entry.key] = entry;
|
|
117
|
+
temporaryPermissionKeys.push(entry.key);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const revision = isRecord(options.runtimePermissions) && typeof options.runtimePermissions.revision === 'number'
|
|
121
|
+
&& Number.isSafeInteger(options.runtimePermissions.revision) && options.runtimePermissions.revision >= 0
|
|
122
|
+
? options.runtimePermissions.revision : undefined;
|
|
123
|
+
return {
|
|
124
|
+
runtimePermissions: {
|
|
125
|
+
schema_version: 1,
|
|
126
|
+
...(revision === undefined ? {} : { revision }),
|
|
127
|
+
entries: MINI_PROGRAM_PERMISSION_KEYS.flatMap((key) => permissions[key] ? [permissions[key]!] : []),
|
|
128
|
+
},
|
|
129
|
+
temporaryPermissionKeys,
|
|
130
|
+
grantValid: parsed.valid,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
135
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function hasExactFields(value: unknown, fields: readonly string[]): value is Record<string, unknown> {
|
|
139
|
+
return isRecord(value) && Object.keys(value).length === fields.length
|
|
140
|
+
&& fields.every((field) => Object.prototype.hasOwnProperty.call(value, field));
|
|
141
|
+
}
|
package/src/payloads.ts
CHANGED
|
@@ -368,6 +368,27 @@ export interface MiniProgramWindowInfoResult {
|
|
|
368
368
|
safeArea: MiniProgramSafeArea;
|
|
369
369
|
screenTop: number;
|
|
370
370
|
}
|
|
371
|
+
/** 小程序窗口方向。 */
|
|
372
|
+
export type MiniProgramOrientationMode = 'portrait' | 'landscape';
|
|
373
|
+
/** 宿主确认生效的小程序展示状态;不表示手机旋转传感器状态。 */
|
|
374
|
+
export interface MiniProgramDisplayState {
|
|
375
|
+
/** 当前小程序锁定的窗口方向。 */
|
|
376
|
+
orientation: MiniProgramOrientationMode;
|
|
377
|
+
/** 是否同时收起胶囊和宿主额外顶部栏;横屏始终为 true。 */
|
|
378
|
+
fullscreen: boolean;
|
|
379
|
+
}
|
|
380
|
+
export interface SetDisplayPayload {
|
|
381
|
+
/** 锁定竖屏或横屏;省略保持当前目标方向,初始为 portrait。 */
|
|
382
|
+
orientation?: MiniProgramOrientationMode;
|
|
383
|
+
/** 同时收起胶囊和宿主额外顶部栏;省略保持当前目标值,初始为 false。合并后横屏强制 true;退出横屏全屏需同时设置 portrait 和 false。 */
|
|
384
|
+
fullscreen?: boolean;
|
|
385
|
+
}
|
|
386
|
+
/** 本次展示设置的原生支持结果;不支持时保留原生状态,宿主仍可尽力收起 H5 顶部栏。 */
|
|
387
|
+
export type SetDisplayResult = {
|
|
388
|
+
/** true 表示原生方向与胶囊设置已完成;false 表示已按宿主可用能力降级。 */
|
|
389
|
+
supported: boolean;
|
|
390
|
+
};
|
|
391
|
+
|
|
371
392
|
export type GetWindowInfoPayload = void;
|
|
372
393
|
export type GetWindowInfoResult = MiniProgramWindowInfoResult;
|
|
373
394
|
export type MiniProgramNavigationBarForegroundStyle = 'light' | 'dark';
|
package/types/bridge.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { COMPANION_SESSION_EXIT_EVENT, COMPANION_SESSION_OUTPUT_EVENT, COMPANION
|
|
|
2
2
|
import type { CompanionSessionExitPayload, CompanionSessionOutputPayload, CompanionSessionOwnershipLostPayload, MiniProgramRuntimeEnvironmentInfo, UserInfoAuthorization } from './payloads';
|
|
3
3
|
import type { MiniProgramCapabilityProgress, MiniProgramProgressMethod } from './capabilities';
|
|
4
4
|
export type MiniProgramBridgeMessageType = 'handshake' | 'request' | 'response' | 'event' | 'cancel';
|
|
5
|
-
export type MiniProgramEventName = 'launch' | 'ready' | 'show' | 'hide' | 'unload' | 'error' | 'heybox_app_login_change' | 'user_info_authorization_change' | typeof COMPANION_SESSION_OUTPUT_EVENT | typeof COMPANION_SESSION_EXIT_EVENT | typeof COMPANION_SESSION_OWNERSHIP_LOST_EVENT;
|
|
5
|
+
export type MiniProgramEventName = 'launch' | 'viewport_change' | 'display_change' | 'ready' | 'show' | 'hide' | 'unload' | 'error' | 'heybox_app_login_change' | 'user_info_authorization_change' | typeof COMPANION_SESSION_OUTPUT_EVENT | typeof COMPANION_SESSION_EXIT_EVENT | typeof COMPANION_SESSION_OWNERSHIP_LOST_EVENT;
|
|
6
6
|
export interface MiniProgramBridgeError {
|
|
7
7
|
code: string;
|
|
8
8
|
message: string;
|
|
@@ -92,6 +92,12 @@ export interface MiniProgramBridgeProgressMessage<TMethod extends MiniProgramPro
|
|
|
92
92
|
error?: never;
|
|
93
93
|
}
|
|
94
94
|
export interface MiniProgramEventPayloadMap {
|
|
95
|
+
/** 展示状态实际变化后通知;不回放初始状态,不支持或失败时不通知。 */
|
|
96
|
+
display_change: import('./payloads').MiniProgramDisplayState & {
|
|
97
|
+
/** api 为开发者调用;user 为用户点击宿主退出全屏按钮。同目标合并时保留首次发起来源。旧宿主可能不提供。 */
|
|
98
|
+
source?: 'api' | 'user';
|
|
99
|
+
};
|
|
100
|
+
viewport_change: import('./payloads').MiniProgramWindowInfoResult;
|
|
95
101
|
launch: {
|
|
96
102
|
timestamp: number;
|
|
97
103
|
url?: string;
|
package/types/capabilities.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CompanionCancelPreparationPayload, CompanionCancelPreparationResult, CompanionGetActiveSessionPayload, CompanionGetActiveSessionResult, CompanionGetInfoPayload, CompanionGetInfoResult, CompanionGetPreparationStatusPayload, CompanionGetPreparationStatusResult, CompanionLaunchPayload, CompanionLaunchResult, CompanionOpenAttachmentPayload, CompanionOpenAttachmentResult, CompanionPreparePayload, CompanionPrepareProgress, CompanionPrepareResult, CompanionSessionAckOutputPayload, CompanionSessionAckOutputResult, CompanionSessionCloseStdinPayload, CompanionSessionCloseStdinResult, CompanionSessionTerminatePayload, CompanionSessionTerminateResult, CompanionSessionWritePayload, CompanionSessionWriteResult, CompanionShowNotificationPayload, CompanionShowNotificationResult, ClosePayload, CloseResult, CopyLinkPayload, CopyLinkResult, DirectoryCreatePayload, DirectoryCreateResult, DirectoryExistsPayload, DirectoryExistsResult, DirectoryListPayload, DirectoryListResult, DirectoryRemovePayload, DirectoryRemoveResult, DownloadProgressPayload, DeleteCurrentUserLeaderboardEntryPayload, DeleteCurrentUserLeaderboardEntryResult, GetCurrentUserLeaderboardEntryPayload, GetCurrentUserLeaderboardEntryResult, GetLeaderboardInfoPayload, GetLeaderboardInfoResult, GetLeaderboardListPayload, GetLeaderboardListResult, GetStoragePayload, GetStorageResult, GetSteamGameListPayload, GetSteamGameListResult, GetUserInfoPayload, GetUserInfoResult, GetWindowInfoPayload, GetWindowInfoResult, HideLoadingPayload, HideLoadingResult, FileCreatePayload, FileCreateResult, FileExistsPayload, FileExistsResult, FileReadBytesPayload, FileReadBytesResult, FileReadTextPayload, FileReadTextResult, FileRemovePayload, FileRemoveResult, FileStatPayload, FileStatResult, FileWriteBytesPayload, FileWriteBytesResult, FileWriteTextPayload, FileWriteTextResult, LoginPayload, LoginResult, NetworkDownloadPayload, NetworkDownloadResult, NetworkRequestPayload, NetworkResponsePayload, OpenAppPagePayload, OpenAppPageResult, PickDirectoryPayload, PickDirectoryResult, PickFilesPayload, PickFilesResult, ReloadPayload, ReloadResult, ScreenshotPayload, ScreenshotResult, SaveFilePayload, SaveFileResult, SetClipboardPayload, SetClipboardResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, SetStoragePayload, ShowLoadingPayload, ShowLoadingResult, ShowShareMenuPayload, ShowShareMenuResult, ShowToastPayload, ShowToastResult, SubmitLeaderboardEntryPayload, SubmitLeaderboardEntryResult, VibratePayload, VibrateResult } from './payloads';
|
|
1
|
+
import type { CompanionCancelPreparationPayload, CompanionCancelPreparationResult, CompanionGetActiveSessionPayload, CompanionGetActiveSessionResult, CompanionGetInfoPayload, CompanionGetInfoResult, CompanionGetPreparationStatusPayload, CompanionGetPreparationStatusResult, CompanionLaunchPayload, CompanionLaunchResult, CompanionOpenAttachmentPayload, CompanionOpenAttachmentResult, CompanionPreparePayload, CompanionPrepareProgress, CompanionPrepareResult, CompanionSessionAckOutputPayload, CompanionSessionAckOutputResult, CompanionSessionCloseStdinPayload, CompanionSessionCloseStdinResult, CompanionSessionTerminatePayload, CompanionSessionTerminateResult, CompanionSessionWritePayload, CompanionSessionWriteResult, CompanionShowNotificationPayload, CompanionShowNotificationResult, ClosePayload, CloseResult, CopyLinkPayload, CopyLinkResult, DirectoryCreatePayload, DirectoryCreateResult, DirectoryExistsPayload, DirectoryExistsResult, DirectoryListPayload, DirectoryListResult, DirectoryRemovePayload, DirectoryRemoveResult, DownloadProgressPayload, DeleteCurrentUserLeaderboardEntryPayload, DeleteCurrentUserLeaderboardEntryResult, GetCurrentUserLeaderboardEntryPayload, GetCurrentUserLeaderboardEntryResult, GetLeaderboardInfoPayload, GetLeaderboardInfoResult, GetLeaderboardListPayload, GetLeaderboardListResult, GetStoragePayload, GetStorageResult, GetSteamGameListPayload, GetSteamGameListResult, GetUserInfoPayload, GetUserInfoResult, GetWindowInfoPayload, GetWindowInfoResult, HideLoadingPayload, HideLoadingResult, FileCreatePayload, FileCreateResult, FileExistsPayload, FileExistsResult, FileReadBytesPayload, FileReadBytesResult, FileReadTextPayload, FileReadTextResult, FileRemovePayload, FileRemoveResult, FileStatPayload, FileStatResult, FileWriteBytesPayload, FileWriteBytesResult, FileWriteTextPayload, FileWriteTextResult, LoginPayload, LoginResult, NetworkDownloadPayload, NetworkDownloadResult, NetworkRequestPayload, NetworkResponsePayload, OpenAppPagePayload, OpenAppPageResult, PickDirectoryPayload, PickDirectoryResult, PickFilesPayload, PickFilesResult, ReloadPayload, ReloadResult, ScreenshotPayload, ScreenshotResult, SaveFilePayload, SaveFileResult, SetClipboardPayload, SetClipboardResult, SetDisplayPayload, SetDisplayResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, SetStoragePayload, ShowLoadingPayload, ShowLoadingResult, ShowShareMenuPayload, ShowShareMenuResult, ShowToastPayload, ShowToastResult, SubmitLeaderboardEntryPayload, SubmitLeaderboardEntryResult, VibratePayload, VibrateResult } from './payloads';
|
|
2
2
|
import type { MiniProgramPermissionRequirement } from './permission-catalog';
|
|
3
3
|
export declare const AUTH_LOGIN_METHOD: "auth.login";
|
|
4
4
|
export declare const USER_GET_INFO_METHOD: "user.getInfo";
|
|
@@ -7,6 +7,7 @@ export declare const USER_GET_STEAM_GAME_LIST_METHOD: "user.getSteamGameList";
|
|
|
7
7
|
export declare const SHARE_COPY_LINK_METHOD: "share.copyLink";
|
|
8
8
|
export declare const SHARE_SHOW_SHARE_MENU_METHOD: "share.showShareMenu";
|
|
9
9
|
export declare const SHARE_SCREENSHOT_METHOD: "share.screenshot";
|
|
10
|
+
export declare const VIEWPORT_SET_DISPLAY_METHOD: "viewport.setDisplay";
|
|
10
11
|
export declare const VIEWPORT_GET_WINDOW_INFO_METHOD: "viewport.getWindowInfo";
|
|
11
12
|
export declare const VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD: "viewport.setNavigationBarStyle";
|
|
12
13
|
export declare const STORAGE_GET_STORAGE_METHOD: "storage.getStorage";
|
|
@@ -56,7 +57,7 @@ export declare const COMPANION_SHOW_NOTIFICATION_METHOD: "companion.showNotifica
|
|
|
56
57
|
export type MiniProgramAuthMethod = typeof AUTH_LOGIN_METHOD;
|
|
57
58
|
export type MiniProgramUserMethod = typeof USER_GET_INFO_METHOD | typeof USER_REVOKE_AUTHORIZATION_METHOD | typeof USER_GET_STEAM_GAME_LIST_METHOD;
|
|
58
59
|
export type MiniProgramShareMethod = typeof SHARE_COPY_LINK_METHOD | typeof SHARE_SHOW_SHARE_MENU_METHOD | typeof SHARE_SCREENSHOT_METHOD;
|
|
59
|
-
export type MiniProgramViewportMethod = typeof VIEWPORT_GET_WINDOW_INFO_METHOD | typeof VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD;
|
|
60
|
+
export type MiniProgramViewportMethod = typeof VIEWPORT_SET_DISPLAY_METHOD | typeof VIEWPORT_GET_WINDOW_INFO_METHOD | typeof VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD;
|
|
60
61
|
export type MiniProgramStorageMethod = typeof STORAGE_GET_STORAGE_METHOD | typeof STORAGE_SET_STORAGE_METHOD;
|
|
61
62
|
export type MiniProgramNetworkMethod = typeof NETWORK_REQUEST_METHOD | typeof NETWORK_DOWNLOAD_METHOD;
|
|
62
63
|
export type MiniProgramFilesMethod = typeof FILES_PICK_FILES_METHOD | typeof FILES_PICK_DIRECTORY_METHOD | typeof FILES_SAVE_FILE_METHOD;
|
|
@@ -174,6 +175,14 @@ export declare const MINI_PROGRAM_PROTOCOL_CAPABILITIES: readonly [{
|
|
|
174
175
|
readonly kind: "none";
|
|
175
176
|
};
|
|
176
177
|
readonly risk: "low";
|
|
178
|
+
}, {
|
|
179
|
+
readonly method: "viewport.setDisplay";
|
|
180
|
+
readonly module: "viewport";
|
|
181
|
+
readonly capability: "viewport.setDisplay";
|
|
182
|
+
readonly requirement: {
|
|
183
|
+
readonly kind: "none";
|
|
184
|
+
};
|
|
185
|
+
readonly risk: "low";
|
|
177
186
|
}, {
|
|
178
187
|
readonly method: "storage.getStorage";
|
|
179
188
|
readonly module: "storage";
|
|
@@ -473,6 +482,7 @@ export interface MiniProgramCapabilityPayloadMap {
|
|
|
473
482
|
[SHARE_COPY_LINK_METHOD]: CopyLinkPayload;
|
|
474
483
|
[SHARE_SHOW_SHARE_MENU_METHOD]: ShowShareMenuPayload;
|
|
475
484
|
[SHARE_SCREENSHOT_METHOD]: ScreenshotPayload;
|
|
485
|
+
[VIEWPORT_SET_DISPLAY_METHOD]: SetDisplayPayload;
|
|
476
486
|
[VIEWPORT_GET_WINDOW_INFO_METHOD]: GetWindowInfoPayload;
|
|
477
487
|
[VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD]: SetNavigationBarStylePayload;
|
|
478
488
|
[STORAGE_GET_STORAGE_METHOD]: GetStoragePayload;
|
|
@@ -528,6 +538,7 @@ export interface MiniProgramCapabilityResultMap {
|
|
|
528
538
|
[SHARE_COPY_LINK_METHOD]: CopyLinkResult;
|
|
529
539
|
[SHARE_SHOW_SHARE_MENU_METHOD]: ShowShareMenuResult;
|
|
530
540
|
[SHARE_SCREENSHOT_METHOD]: ScreenshotResult;
|
|
541
|
+
[VIEWPORT_SET_DISPLAY_METHOD]: SetDisplayResult;
|
|
531
542
|
[VIEWPORT_GET_WINDOW_INFO_METHOD]: GetWindowInfoResult;
|
|
532
543
|
[VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD]: SetNavigationBarStyleResult;
|
|
533
544
|
[STORAGE_GET_STORAGE_METHOD]: GetStorageResult;
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type MiniProgramPermissionKey } from './permission-catalog';
|
|
2
|
+
import { type MiniProgramRuntimePermissionsSnapshot } from './permissions';
|
|
3
|
+
/** 仅供开发工具和 Host 使用;新增权限必须单独评估,不能从平台审批目录自动推导。 */
|
|
4
|
+
export declare const LOCAL_DEV_GRANT_PERMISSION_KEYS: readonly ["network", "companion"];
|
|
5
|
+
export type MiniProgramLocalDevPermissionKey = (typeof LOCAL_DEV_GRANT_PERMISSION_KEYS)[number];
|
|
6
|
+
export type MiniProgramLocalDevGrantEntry = {
|
|
7
|
+
key: 'network';
|
|
8
|
+
status: 'enabled';
|
|
9
|
+
config: {
|
|
10
|
+
useOfficialDomain: false;
|
|
11
|
+
};
|
|
12
|
+
} | {
|
|
13
|
+
key: 'companion';
|
|
14
|
+
status: 'enabled';
|
|
15
|
+
config: Record<string, never>;
|
|
16
|
+
};
|
|
17
|
+
/** CLI-owned Dev Context 合同,不属于小程序业务 API 或线上批准快照。 */
|
|
18
|
+
export interface MiniProgramLocalDevGrant {
|
|
19
|
+
schema_version: 1;
|
|
20
|
+
revision: number;
|
|
21
|
+
entries: MiniProgramLocalDevGrantEntry[];
|
|
22
|
+
}
|
|
23
|
+
/** 调用方已校验的本地声明;不存在的权限不会从 grant 获得授权。 */
|
|
24
|
+
export type MiniProgramLocalDevPermissionDeclarations = Partial<Record<MiniProgramPermissionKey, {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
useOfficialDomain?: boolean;
|
|
27
|
+
}>>;
|
|
28
|
+
export type ParsedMiniProgramLocalDevGrant = {
|
|
29
|
+
valid: true;
|
|
30
|
+
grant: MiniProgramLocalDevGrant;
|
|
31
|
+
} | {
|
|
32
|
+
valid: false;
|
|
33
|
+
grant?: undefined;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* 严格解析本地 grant。任何未知字段、重复权限或非法配置都拒绝整份输入。
|
|
37
|
+
* 只校验数据合同;票据、身份、摘要、过期时间和 CLI lease 必须由 Host 另行验证。
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseMiniProgramLocalDevGrant(value: unknown): ParsedMiniProgramLocalDevGrant;
|
|
40
|
+
/**
|
|
41
|
+
* 从已校验声明生成批准缺口。Companion 默认不符合资格,由 CLI 确认平台、产物与摘要后显式加入。
|
|
42
|
+
* 空 entries 可保留 revision,不能作为存在临时权限的判断依据。
|
|
43
|
+
*/
|
|
44
|
+
export declare function createMiniProgramLocalDevGrant(options: {
|
|
45
|
+
declaredPermissions: MiniProgramLocalDevPermissionDeclarations;
|
|
46
|
+
runtimePermissions: unknown;
|
|
47
|
+
revision: number;
|
|
48
|
+
eligiblePermissionKeys?: readonly MiniProgramLocalDevPermissionKey[];
|
|
49
|
+
}): MiniProgramLocalDevGrant;
|
|
50
|
+
/**
|
|
51
|
+
* 线上基线先与本地声明求交,再补齐临时权限,返回与输入脱离的普通 Runtime 快照。
|
|
52
|
+
* 调用方只可在当前 Dev Session 已验证且用户接受后传入 grant;本函数不证明其可信来源。
|
|
53
|
+
* 非法 grant 整体降权到基线,已批准配置不会被临时配置覆盖。
|
|
54
|
+
*/
|
|
55
|
+
export declare function composeLocalDevRuntimePermissions(options: {
|
|
56
|
+
declaredPermissions: MiniProgramLocalDevPermissionDeclarations;
|
|
57
|
+
runtimePermissions: unknown;
|
|
58
|
+
localDevGrant?: unknown;
|
|
59
|
+
}): {
|
|
60
|
+
runtimePermissions: MiniProgramRuntimePermissionsSnapshot;
|
|
61
|
+
temporaryPermissionKeys: MiniProgramLocalDevPermissionKey[];
|
|
62
|
+
grantValid: boolean;
|
|
63
|
+
};
|
package/types/payloads.d.ts
CHANGED
|
@@ -365,6 +365,26 @@ export interface MiniProgramWindowInfoResult {
|
|
|
365
365
|
safeArea: MiniProgramSafeArea;
|
|
366
366
|
screenTop: number;
|
|
367
367
|
}
|
|
368
|
+
/** 小程序窗口方向。 */
|
|
369
|
+
export type MiniProgramOrientationMode = 'portrait' | 'landscape';
|
|
370
|
+
/** 宿主确认生效的小程序展示状态;不表示手机旋转传感器状态。 */
|
|
371
|
+
export interface MiniProgramDisplayState {
|
|
372
|
+
/** 当前小程序锁定的窗口方向。 */
|
|
373
|
+
orientation: MiniProgramOrientationMode;
|
|
374
|
+
/** 是否同时收起胶囊和宿主额外顶部栏;横屏始终为 true。 */
|
|
375
|
+
fullscreen: boolean;
|
|
376
|
+
}
|
|
377
|
+
export interface SetDisplayPayload {
|
|
378
|
+
/** 锁定竖屏或横屏;省略保持当前目标方向,初始为 portrait。 */
|
|
379
|
+
orientation?: MiniProgramOrientationMode;
|
|
380
|
+
/** 同时收起胶囊和宿主额外顶部栏;省略保持当前目标值,初始为 false。合并后横屏强制 true;退出横屏全屏需同时设置 portrait 和 false。 */
|
|
381
|
+
fullscreen?: boolean;
|
|
382
|
+
}
|
|
383
|
+
/** 本次展示设置的原生支持结果;不支持时保留原生状态,宿主仍可尽力收起 H5 顶部栏。 */
|
|
384
|
+
export type SetDisplayResult = {
|
|
385
|
+
/** true 表示原生方向与胶囊设置已完成;false 表示已按宿主可用能力降级。 */
|
|
386
|
+
supported: boolean;
|
|
387
|
+
};
|
|
368
388
|
export type GetWindowInfoPayload = void;
|
|
369
389
|
export type GetWindowInfoResult = MiniProgramWindowInfoResult;
|
|
370
390
|
export type MiniProgramNavigationBarForegroundStyle = 'light' | 'dark';
|
|
@@ -113,5 +113,5 @@ export declare const MINI_PROGRAM_PERMISSION_CATALOG: readonly [{
|
|
|
113
113
|
readonly methods: readonly ["companion.getInfo", "companion.getPreparationStatus", "companion.prepare", "companion.cancelPreparation", "companion.getActiveSession", "companion.launch", "companion.session.write", "companion.session.closeStdin", "companion.session.terminate", "companion.session.ackOutput", "companion.openAttachment", "companion.showNotification"];
|
|
114
114
|
readonly conditions: readonly ["声明后仍需平台批准,并继续执行可信用户手势、Host 能力和当前版本 Manifest 校验。"];
|
|
115
115
|
}];
|
|
116
|
-
export declare const MINI_PROGRAM_NO_DECLARATION_METHODS: readonly ["user.revokeAuthorization", "ui.showToast", "ui.showLoading", "ui.hideLoading", "viewport.getWindowInfo", "viewport.setNavigationBarStyle", "device.vibrate", "navigation.close", "navigation.reload", "navigation.openAppPage"];
|
|
116
|
+
export declare const MINI_PROGRAM_NO_DECLARATION_METHODS: readonly ["user.revokeAuthorization", "ui.showToast", "ui.showLoading", "ui.hideLoading", "viewport.getWindowInfo", "viewport.setNavigationBarStyle", "viewport.setDisplay", "device.vibrate", "navigation.close", "navigation.reload", "navigation.openAppPage"];
|
|
117
117
|
export declare function isMiniProgramPermissionKey(key: string): key is MiniProgramPermissionKey;
|