@wix/himalaya-cli 0.1451.0 → 0.1453.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/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview/src/dispatcher.d.ts +79 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview/src/index.d.ts +41 -30
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview-page/src/capabilities.generated.d.ts +47 -41
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview-page/src/client.d.ts +68 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview-page/src/index.d.ts +13 -21
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/webview-page.mjs +277 -144
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/webview.mjs +505 -49
- package/guides/designing-himi-screens.md +34 -1
- package/guides/index.json +1 -0
- package/guides/sdk-reference.json +45 -45
- package/guides/web-page-native-sdk.md +4 -3
- package/guides/webview-page-sdk.md +102 -3
- package/package.json +2 -2
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export type WebViewRuntime = {
|
|
2
|
+
postToPage(msg: unknown, instanceId?: string): void;
|
|
3
|
+
onPageMessage(cb: (msg: unknown, instanceId?: unknown) => void): void;
|
|
4
|
+
onPageLifecycle?(cb: (envelope: unknown, instanceId?: unknown) => void): void;
|
|
5
|
+
};
|
|
6
|
+
export interface PageCapabilityRequest {
|
|
7
|
+
v: 1;
|
|
8
|
+
id: string;
|
|
9
|
+
capability: string;
|
|
10
|
+
method: string;
|
|
11
|
+
args: unknown[];
|
|
12
|
+
}
|
|
13
|
+
export interface PageCapabilityResponse {
|
|
14
|
+
v: 1;
|
|
15
|
+
id: string;
|
|
16
|
+
ok: boolean;
|
|
17
|
+
result?: unknown;
|
|
18
|
+
/** `true` when the call answers as a stream: chunks follow as `{ v: 1, sid: id, … }`. */
|
|
19
|
+
stream?: true;
|
|
20
|
+
error?: {
|
|
21
|
+
message: string;
|
|
22
|
+
code?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** What every `onPageRequest` handler receives beside its args. */
|
|
26
|
+
export interface PageCtx {
|
|
27
|
+
/** The instance the host stamped on the request (`""` for the full-screen page). */
|
|
28
|
+
readonly instanceId: string;
|
|
29
|
+
readonly requestId: string;
|
|
30
|
+
/** Live: `false` between an `inactive` and the next `active` lifecycle of this instance. */
|
|
31
|
+
readonly active: boolean;
|
|
32
|
+
}
|
|
33
|
+
export type PageRequestHandler = (args: unknown[], ctx: PageCtx) => unknown;
|
|
34
|
+
export interface PageLifecycleEvent {
|
|
35
|
+
instanceId: string;
|
|
36
|
+
state: string;
|
|
37
|
+
detail?: unknown;
|
|
38
|
+
}
|
|
39
|
+
/** Page-sourced console output. UNTRUSTED: the page can forge it (RFC 0073 §5.3). */
|
|
40
|
+
export interface PageConsoleEvent {
|
|
41
|
+
instanceId: string;
|
|
42
|
+
level: string;
|
|
43
|
+
args: unknown[];
|
|
44
|
+
}
|
|
45
|
+
export interface PageStream {
|
|
46
|
+
/** Send one chunk. A no-op once the stream ended, errored, or the page cancelled it. */
|
|
47
|
+
next(data: unknown): void;
|
|
48
|
+
end(): void;
|
|
49
|
+
error(e: unknown): void;
|
|
50
|
+
/** Called once if the page cancels (`break` out of its iterator) or the instance unmounts. */
|
|
51
|
+
onCancel(cb: () => void): void;
|
|
52
|
+
readonly closed: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface ExposedPageCapability {
|
|
55
|
+
module: Record<string, unknown>;
|
|
56
|
+
methods: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
export declare const PAGE_HANDSHAKE_CAPABILITY = "himalaya";
|
|
59
|
+
export declare const PAGE_HANDSHAKE_METHOD = "capabilities";
|
|
60
|
+
export declare const NAMESPACE_PATTERN: RegExp;
|
|
61
|
+
export declare function pageRequest(value: unknown): PageCapabilityRequest | null;
|
|
62
|
+
export declare function pageError(value: unknown): {
|
|
63
|
+
message: string;
|
|
64
|
+
code?: string;
|
|
65
|
+
};
|
|
66
|
+
export interface PageDispatcher {
|
|
67
|
+
readonly runtime: WebViewRuntime;
|
|
68
|
+
/** Whether the runtime routes by instance id (W2/W4/W6 hosts) or has one page (`""`). */
|
|
69
|
+
readonly instanceAware: boolean;
|
|
70
|
+
setRawHandler(cb: (msg: unknown, instanceId: string) => void): void;
|
|
71
|
+
expose(capabilities: Readonly<Record<string, ExposedPageCapability>>): void;
|
|
72
|
+
addNamespace(namespace: string, handlers: Readonly<Record<string, PageRequestHandler>>): void;
|
|
73
|
+
subscribeLifecycle(cb: (e: PageLifecycleEvent) => void): () => void;
|
|
74
|
+
subscribeConsole(cb: (e: PageConsoleEvent) => void): () => void;
|
|
75
|
+
post(instanceId: string, msg: unknown): void;
|
|
76
|
+
emit(target: string, event: string, data: unknown): void;
|
|
77
|
+
openStream(instanceId: string, requestId: string): PageStream;
|
|
78
|
+
}
|
|
79
|
+
export declare function createPageDispatcher(runtime: WebViewRuntime): PageDispatcher;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type ExposedPageCapability, type PageConsoleEvent, type PageLifecycleEvent, type PageRequestHandler, type PageStream } from "./dispatcher.js";
|
|
2
|
+
export { PAGE_HANDSHAKE_CAPABILITY, PAGE_HANDSHAKE_METHOD, type ExposedPageCapability, type PageCapabilityRequest, type PageCapabilityResponse, type PageConsoleEvent, type PageCtx, type PageLifecycleEvent, type PageRequestHandler, type PageStream, } from "./dispatcher.js";
|
|
1
3
|
/**
|
|
2
4
|
* Push a message from the worker to the hosting webview page. Delivered to every
|
|
3
5
|
* `window.HimalayaWorker.onMessage(cb)` handler the page registered. `msg` is
|
|
@@ -7,35 +9,43 @@
|
|
|
7
9
|
*/
|
|
8
10
|
export declare function postToPage(msg: unknown): void;
|
|
9
11
|
/**
|
|
10
|
-
* Register a handler for messages the page posts via `window.HimalayaWorker.post(msg)
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
12
|
+
* Register a handler for messages the page posts via `window.HimalayaWorker.post(msg)` that no
|
|
13
|
+
* responder (`exposeCapabilitiesToPage`, `onPageRequest`) claims. The latest registered handler
|
|
14
|
+
* wins. `instanceId` is the embedded WebView the host says the message came from (`""` for the
|
|
15
|
+
* full-screen page). Call this once during the bundle's setup.
|
|
16
|
+
*/
|
|
17
|
+
export declare function onPageMessage(cb: (msg: unknown, instanceId: string) => void): void;
|
|
18
|
+
/**
|
|
19
|
+
* Answer page requests `call(namespace, method, args)` from `@wix/himalaya/webview-page` (or
|
|
20
|
+
* `himalaya.<namespace>.<method>(…)`) with worker code. A handler gets `(args, ctx)` and returns a value or a promise; a throw answers
|
|
21
|
+
* `ok: false`. To stream, return `openPageStream(ctx.instanceId, ctx.requestId)`.
|
|
22
|
+
*
|
|
23
|
+
* Throws when `namespace` is `"himalaya"`, already registered, already exposed, or not
|
|
24
|
+
* `/^[a-z][a-z0-9_]{0,63}$/`. A method the namespace lacks answers `code: "unknown_method"`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function onPageRequest(namespace: string, handlers: Readonly<Record<string, PageRequestHandler>>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Push an event to one page instance, or `"*"` for every instance that has sent a message or
|
|
29
|
+
* mounted and not unmounted. `event` is `"<namespace>.<event>"`, split on the first dot; the page
|
|
30
|
+
* receives it through `himalaya.<namespace>.on("<event>", cb)`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function emitToPage(instanceId: string, event: `${string}.${string}`, data: unknown): void;
|
|
33
|
+
/**
|
|
34
|
+
* Open a stream answer for an in-flight `onPageRequest` call. Return the handle from the handler;
|
|
35
|
+
* the page then iterates the chunks. After `end`, `error`, or a page cancel, `next` is a no-op.
|
|
36
|
+
*/
|
|
37
|
+
export declare function openPageStream(instanceId: string, requestId: string): PageStream;
|
|
38
|
+
/**
|
|
39
|
+
* Observe host lifecycle envelopes (`mounted | loaded | active | inactive | crashed | reloaded |
|
|
40
|
+
* navBlocked | unmounted`). They arrive only on the host's lifecycle primitive, never from a page.
|
|
41
|
+
* On a runtime without instance support, nothing is delivered. Returns an unsubscribe function.
|
|
42
|
+
*/
|
|
43
|
+
export declare function onPageLifecycle(cb: (e: PageLifecycleEvent) => void): () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Observe `console_forwarding` output of the embedded pages. UNTRUSTED page data: a page can forge
|
|
46
|
+
* these, so never treat them as host events. Returns an unsubscribe function.
|
|
47
|
+
*/
|
|
48
|
+
export declare function onPageConsole(cb: (e: PageConsoleEvent) => void): () => void;
|
|
39
49
|
/**
|
|
40
50
|
* Expose selected typed @himalaya/* modules to the hosting page.
|
|
41
51
|
*
|
|
@@ -47,7 +57,8 @@ export interface ExposedPageCapability {
|
|
|
47
57
|
* });
|
|
48
58
|
*
|
|
49
59
|
* The bundle still has to declare `webview` plus every exposed capability. Importing only
|
|
50
|
-
* selected modules keeps native permissions and `himi dist` additions opt-in.
|
|
60
|
+
* selected modules keeps native permissions and `himi dist` additions opt-in. The page handshake
|
|
61
|
+
* (`call("himalaya", "capabilities")`) answers this allowlist plus every `onPageRequest` namespace.
|
|
51
62
|
*/
|
|
52
63
|
export declare function exposeCapabilitiesToPage(capabilities: Readonly<Record<string, ExposedPageCapability>>): void;
|
|
53
64
|
export declare const version = 1;
|
|
@@ -38,55 +38,61 @@ import type * as ThemeSdk from "@wix/himalaya/theme";
|
|
|
38
38
|
import type * as UiSdk from "@wix/himalaya/ui";
|
|
39
39
|
import type * as WixCashierSdk from "@wix/himalaya/wix-cashier";
|
|
40
40
|
import type * as WixChatSdk from "@wix/himalaya/wix-chat";
|
|
41
|
+
import type { PageClient } from "./client.js";
|
|
41
42
|
type PageModule<T> = {
|
|
42
43
|
readonly [P in keyof T as T[P] extends (...args: any[]) => any ? P : T[P] extends readonly unknown[] ? never : T[P] extends object ? keyof PageModule<T[P]> extends never ? never : P : never]: T[P] extends (...args: infer A) => infer R ? (...args: A) => R : T[P] extends readonly unknown[] ? never : T[P] extends object ? PageModule<T[P]> : never;
|
|
43
44
|
};
|
|
45
|
+
/** `himalaya.<ns>.on(event, cb)`: events the worker pushes with `emitToPage(iid, "<ns>.<event>", data)`. */
|
|
46
|
+
type PageEvents = {
|
|
47
|
+
on(event: string, handler: (data: unknown) => void): () => void;
|
|
48
|
+
};
|
|
44
49
|
/** Every typed request/response capability a trusted WebView page can ask its companion worker for.
|
|
45
50
|
* Availability is still opt-in: the worker imports a subset and its logic-bundle manifest declares
|
|
46
51
|
* that same subset; every other namespace/method is ignored. */
|
|
47
52
|
export interface HimalayaPageCapabilities {
|
|
48
|
-
readonly "app_info": PageModule<typeof AppInfoSdk
|
|
49
|
-
readonly "audio_record": PageModule<typeof AudioRecordSdk
|
|
50
|
-
readonly "base44": PageModule<typeof Base44Sdk
|
|
51
|
-
readonly "biometrics": PageModule<typeof BiometricsSdk
|
|
52
|
-
readonly "browser_auth": PageModule<typeof BrowserAuthSdk
|
|
53
|
-
readonly "calendar": PageModule<typeof CalendarSdk
|
|
54
|
-
readonly "calls": PageModule<typeof CallsSdk
|
|
55
|
-
readonly "camera": PageModule<typeof CameraSdk
|
|
56
|
-
readonly "clipboard": PageModule<typeof ClipboardSdk
|
|
57
|
-
readonly "contacts": PageModule<typeof ContactsSdk
|
|
58
|
-
readonly "file_picker": PageModule<typeof FilePickerSdk
|
|
59
|
-
readonly "files": PageModule<typeof FilesSdk
|
|
60
|
-
readonly "godot": PageModule<typeof GodotSdk
|
|
61
|
-
readonly "haptic": PageModule<typeof HapticSdk
|
|
62
|
-
readonly "health": PageModule<typeof HealthSdk
|
|
63
|
-
readonly "himi_apps": PageModule<typeof HimiAppsSdk
|
|
64
|
-
readonly "iap": PageModule<typeof IapSdk
|
|
65
|
-
readonly "keyboard": PageModule<typeof KeyboardSdk
|
|
66
|
-
readonly "live_activity": PageModule<typeof LiveActivitySdk
|
|
67
|
-
readonly "local_database": PageModule<typeof LocalDatabaseSdk
|
|
68
|
-
readonly "location": PageModule<typeof LocationSdk
|
|
69
|
-
readonly "media_playback": PageModule<typeof MediaPlaybackSdk
|
|
70
|
-
readonly "motion": PageModule<typeof MotionSdk
|
|
71
|
-
readonly "on_device_ai": PageModule<typeof OnDeviceAiSdk
|
|
72
|
-
readonly "open_url": PageModule<typeof OpenUrlSdk
|
|
73
|
-
readonly "pdf": PageModule<typeof PdfSdk
|
|
74
|
-
readonly "photos": PageModule<typeof PhotosSdk
|
|
75
|
-
readonly "presigned_upload": PageModule<typeof PresignedUploadSdk
|
|
76
|
-
readonly "push": PageModule<typeof PushSdk
|
|
77
|
-
readonly "release_control": PageModule<typeof ReleaseControlSdk
|
|
78
|
-
readonly "secure_storage": PageModule<typeof SecureStorageSdk
|
|
79
|
-
readonly "share": PageModule<typeof ShareSdk
|
|
80
|
-
readonly "speaker_diarization": PageModule<typeof SpeakerDiarizationSdk
|
|
81
|
-
readonly "speech": PageModule<typeof SpeechSdk
|
|
82
|
-
readonly "system_intents": PageModule<typeof SystemIntentsSdk
|
|
83
|
-
readonly "tasks": PageModule<typeof TasksSdk
|
|
84
|
-
readonly "theme": PageModule<typeof ThemeSdk
|
|
85
|
-
readonly "ui": PageModule<typeof UiSdk
|
|
86
|
-
readonly "wix_cashier": PageModule<typeof WixCashierSdk
|
|
87
|
-
readonly "wix_chat": PageModule<typeof WixChatSdk
|
|
53
|
+
readonly "app_info": PageModule<typeof AppInfoSdk> & PageEvents;
|
|
54
|
+
readonly "audio_record": PageModule<typeof AudioRecordSdk> & PageEvents;
|
|
55
|
+
readonly "base44": PageModule<typeof Base44Sdk> & PageEvents;
|
|
56
|
+
readonly "biometrics": PageModule<typeof BiometricsSdk> & PageEvents;
|
|
57
|
+
readonly "browser_auth": PageModule<typeof BrowserAuthSdk> & PageEvents;
|
|
58
|
+
readonly "calendar": PageModule<typeof CalendarSdk> & PageEvents;
|
|
59
|
+
readonly "calls": PageModule<typeof CallsSdk> & PageEvents;
|
|
60
|
+
readonly "camera": PageModule<typeof CameraSdk> & PageEvents;
|
|
61
|
+
readonly "clipboard": PageModule<typeof ClipboardSdk> & PageEvents;
|
|
62
|
+
readonly "contacts": PageModule<typeof ContactsSdk> & PageEvents;
|
|
63
|
+
readonly "file_picker": PageModule<typeof FilePickerSdk> & PageEvents;
|
|
64
|
+
readonly "files": PageModule<typeof FilesSdk> & PageEvents;
|
|
65
|
+
readonly "godot": PageModule<typeof GodotSdk> & PageEvents;
|
|
66
|
+
readonly "haptic": PageModule<typeof HapticSdk> & PageEvents;
|
|
67
|
+
readonly "health": PageModule<typeof HealthSdk> & PageEvents;
|
|
68
|
+
readonly "himi_apps": PageModule<typeof HimiAppsSdk> & PageEvents;
|
|
69
|
+
readonly "iap": PageModule<typeof IapSdk> & PageEvents;
|
|
70
|
+
readonly "keyboard": PageModule<typeof KeyboardSdk> & PageEvents;
|
|
71
|
+
readonly "live_activity": PageModule<typeof LiveActivitySdk> & PageEvents;
|
|
72
|
+
readonly "local_database": PageModule<typeof LocalDatabaseSdk> & PageEvents;
|
|
73
|
+
readonly "location": PageModule<typeof LocationSdk> & PageEvents;
|
|
74
|
+
readonly "media_playback": PageModule<typeof MediaPlaybackSdk> & PageEvents;
|
|
75
|
+
readonly "motion": PageModule<typeof MotionSdk> & PageEvents;
|
|
76
|
+
readonly "on_device_ai": PageModule<typeof OnDeviceAiSdk> & PageEvents;
|
|
77
|
+
readonly "open_url": PageModule<typeof OpenUrlSdk> & PageEvents;
|
|
78
|
+
readonly "pdf": PageModule<typeof PdfSdk> & PageEvents;
|
|
79
|
+
readonly "photos": PageModule<typeof PhotosSdk> & PageEvents;
|
|
80
|
+
readonly "presigned_upload": PageModule<typeof PresignedUploadSdk> & PageEvents;
|
|
81
|
+
readonly "push": PageModule<typeof PushSdk> & PageEvents;
|
|
82
|
+
readonly "release_control": PageModule<typeof ReleaseControlSdk> & PageEvents;
|
|
83
|
+
readonly "secure_storage": PageModule<typeof SecureStorageSdk> & PageEvents;
|
|
84
|
+
readonly "share": PageModule<typeof ShareSdk> & PageEvents;
|
|
85
|
+
readonly "speaker_diarization": PageModule<typeof SpeakerDiarizationSdk> & PageEvents;
|
|
86
|
+
readonly "speech": PageModule<typeof SpeechSdk> & PageEvents;
|
|
87
|
+
readonly "system_intents": PageModule<typeof SystemIntentsSdk> & PageEvents;
|
|
88
|
+
readonly "tasks": PageModule<typeof TasksSdk> & PageEvents;
|
|
89
|
+
readonly "theme": PageModule<typeof ThemeSdk> & PageEvents;
|
|
90
|
+
readonly "ui": PageModule<typeof UiSdk> & PageEvents;
|
|
91
|
+
readonly "wix_cashier": PageModule<typeof WixCashierSdk> & PageEvents;
|
|
92
|
+
readonly "wix_chat": PageModule<typeof WixChatSdk> & PageEvents;
|
|
88
93
|
}
|
|
94
|
+
/** `window.himalaya` and the package's `himalaya` export: the namespaces plus the client's own members. */
|
|
89
95
|
export type HimalayaPageSdk = HimalayaPageCapabilities & {
|
|
90
96
|
readonly version: 1;
|
|
91
|
-
}
|
|
97
|
+
} & Readonly<Pick<PageClient, "call" | "on" | "enabledCapabilities" | "isEnabled" | "probe">>;
|
|
92
98
|
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export interface WebViewPageRequest {
|
|
2
|
+
v: 1;
|
|
3
|
+
id: string;
|
|
4
|
+
capability: string;
|
|
5
|
+
method: string;
|
|
6
|
+
args: unknown[];
|
|
7
|
+
}
|
|
8
|
+
export interface WebViewPageError {
|
|
9
|
+
message: string;
|
|
10
|
+
code?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface WebViewPageResponse {
|
|
13
|
+
v: 1;
|
|
14
|
+
id: string;
|
|
15
|
+
ok: boolean;
|
|
16
|
+
result?: unknown;
|
|
17
|
+
/** The answer is a stream: `call()` resolves to an AsyncIterable of the chunks. */
|
|
18
|
+
stream?: boolean;
|
|
19
|
+
error?: WebViewPageError;
|
|
20
|
+
}
|
|
21
|
+
/** `emitToPage(iid, "<ns>.<ev>", data)` on the worker. */
|
|
22
|
+
export interface WebViewPageEvent {
|
|
23
|
+
v: 1;
|
|
24
|
+
ev: string;
|
|
25
|
+
ns: string;
|
|
26
|
+
data?: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** One envelope of a streamed answer; `sid` is the request id. */
|
|
29
|
+
export type WebViewPageStreamEnvelope = {
|
|
30
|
+
v: 1;
|
|
31
|
+
sid: string;
|
|
32
|
+
chunk: unknown;
|
|
33
|
+
} | {
|
|
34
|
+
v: 1;
|
|
35
|
+
sid: string;
|
|
36
|
+
end: true;
|
|
37
|
+
} | {
|
|
38
|
+
v: 1;
|
|
39
|
+
sid: string;
|
|
40
|
+
error: WebViewPageError;
|
|
41
|
+
};
|
|
42
|
+
export interface HimalayaWorkerBridge {
|
|
43
|
+
post(message: unknown): boolean;
|
|
44
|
+
onMessage(handler: (message: unknown) => void): void;
|
|
45
|
+
}
|
|
46
|
+
export type PageEventHandler = (data: unknown) => void;
|
|
47
|
+
export interface PageClient {
|
|
48
|
+
call<T>(capability: string, method: string, args?: unknown[], timeoutMs?: number): Promise<T>;
|
|
49
|
+
/** Subscribe to `namespace.event` pushed by the worker. Returns the unsubscribe function. */
|
|
50
|
+
on(namespace: string, event: string, handler: PageEventHandler): () => void;
|
|
51
|
+
enabledCapabilities(timeoutMs?: number): Promise<Record<string, string[]> | null>;
|
|
52
|
+
isEnabled(capability: string, method: string, timeoutMs?: number): Promise<boolean>;
|
|
53
|
+
probe(capability: string, method: string, args?: unknown[], timeoutMs?: number): Promise<boolean>;
|
|
54
|
+
/** `himalaya.<capability>` — a proxy whose members call, plus `.on(event, cb)`. */
|
|
55
|
+
namespace(capability: string): object;
|
|
56
|
+
/**
|
|
57
|
+
* Merge this client into a host's `himalaya` object (the RFC 0038 shim's) and return what to
|
|
58
|
+
* install as `window.himalaya`: `target` gains `call`, `on`, `enabledCapabilities`, `isEnabled`,
|
|
59
|
+
* `probe` and `version`, is frozen, and any other name resolves to a namespace proxy. Existing
|
|
60
|
+
* members of `target` (e.g. the shim's `general`) win.
|
|
61
|
+
*/
|
|
62
|
+
merge<T extends object>(target: T): T;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A page client over the bridge `getBridge()` returns (`undefined` outside a worker-backed
|
|
66
|
+
* WebView). Calls and listeners re-attach when the page's bridge object changes.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createPageClient(getBridge: () => HimalayaWorkerBridge | undefined): PageClient;
|
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import type { HimalayaPageSdk } from "./capabilities.generated.js";
|
|
2
2
|
export type { HimalayaPageCapabilities, HimalayaPageSdk } from "./capabilities.generated.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
id: string;
|
|
6
|
-
capability: string;
|
|
7
|
-
method: string;
|
|
8
|
-
args: unknown[];
|
|
9
|
-
}
|
|
10
|
-
export interface WebViewPageError {
|
|
11
|
-
message: string;
|
|
12
|
-
code?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface WebViewPageResponse {
|
|
15
|
-
v: 1;
|
|
16
|
-
id: string;
|
|
17
|
-
ok: boolean;
|
|
18
|
-
result?: unknown;
|
|
19
|
-
error?: WebViewPageError;
|
|
20
|
-
}
|
|
3
|
+
import { type PageEventHandler } from "./client.js";
|
|
4
|
+
export type { PageEventHandler, WebViewPageError, WebViewPageEvent, WebViewPageRequest, WebViewPageResponse, WebViewPageStreamEnvelope, } from "./client.js";
|
|
21
5
|
/** Invoke one method through the companion worker. Primarily useful to generated bindings.
|
|
22
6
|
* A call that shows native UI (a permission prompt, the share sheet) answers only when the user
|
|
23
|
-
* is done with it: pass a long `timeoutMs` (e.g. 120_000) rather than the 30-second default.
|
|
7
|
+
* is done with it: pass a long `timeoutMs` (e.g. 120_000) rather than the 30-second default.
|
|
8
|
+
* A method the worker answers as a stream resolves to an `AsyncIterable` of its chunks:
|
|
9
|
+
* `for await (const chunk of await call(…))`; `break` cancels it on the worker. */
|
|
24
10
|
export declare function call<T>(capability: string, method: string, args?: unknown[], timeoutMs?: number): Promise<T>;
|
|
11
|
+
/** Subscribe to `namespace.event`, pushed by the worker's `emitToPage(iid, "<namespace>.<event>", data)`.
|
|
12
|
+
* Same as `himalaya.<namespace>.on(event, handler)`. Returns the unsubscribe function. */
|
|
13
|
+
export declare function on(namespace: string, event: string, handler: PageEventHandler): () => void;
|
|
25
14
|
/**
|
|
26
15
|
* The capabilities and methods this page's companion worker answers, as `{ <id>: [<method>…] }`;
|
|
27
16
|
* `null` outside the app, when the app is older than the handshake, or nothing answered in
|
|
@@ -33,12 +22,13 @@ export declare function enabledCapabilities(timeoutMs?: number): Promise<Record<
|
|
|
33
22
|
* enabledCapabilities() — nothing is called. `false` when there is no list. */
|
|
34
23
|
export declare function isEnabled(capability: string, method: string, timeoutMs?: number): Promise<boolean>;
|
|
35
24
|
/** For an app older than the handshake: CALL `capability.method` and report whether it answered
|
|
36
|
-
* (even with an error). It runs the method, so pass only a read-only one. */
|
|
25
|
+
* (even with an error other than `unknown_method`). It runs the method, so pass only a read-only one. */
|
|
37
26
|
export declare function probe(capability: string, method: string, args?: unknown[], timeoutMs?: number): Promise<boolean>;
|
|
38
27
|
/**
|
|
39
28
|
* Typed SDK proxy for every request/response capability in CAPABILITY_REGISTRY.
|
|
40
29
|
* A namespace is usable only when this screen's companion worker explicitly imported and
|
|
41
|
-
* exposed it and the bundle + host both declared it.
|
|
30
|
+
* exposed it and the bundle + host both declared it. Built by the same `merge` a host uses for the
|
|
31
|
+
* injected client, so `himalaya.call/on/probe/…` are the client's members here too.
|
|
42
32
|
*/
|
|
43
33
|
export declare const himalaya: HimalayaPageSdk;
|
|
44
34
|
/** Convenience named export; equivalent to `himalaya.health`. */
|
|
@@ -79,5 +69,7 @@ export declare const health: {
|
|
|
79
69
|
id: string;
|
|
80
70
|
}>;
|
|
81
71
|
};
|
|
72
|
+
} & {
|
|
73
|
+
on(event: string, handler: (data: unknown) => void): () => void;
|
|
82
74
|
};
|
|
83
75
|
export declare const version = 1;
|