@lemoncloud/chatic-apps-sdk 0.0.0-stage → 0.1.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/README.md +288 -2
- package/chatic-apps-sdk.global.js +1 -0
- package/index.cjs +1 -0
- package/index.d.cts +192 -0
- package/index.d.ts +192 -0
- package/index.js +288 -0
- package/mock.cjs +1 -0
- package/mock.d.cts +87 -0
- package/mock.d.ts +87 -0
- package/mock.js +196 -0
- package/package.json +45 -5
- package/storage-BuvWwLx2.js +104 -0
- package/storage-yeS4HWKZ.cjs +1 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/** Every code the app itself can fail a call with. */
|
|
2
|
+
export declare type AppErrorCode = 'NOT_FOUND' | 'INTERNAL_ERROR' | 'TOO_LARGE' | 'INVALID' | 'INVALID_KIND' | 'NOT_OPEN' | 'LINK_NOT_ALLOWED' | 'OPEN_URL_FAILED' | 'CLIPBOARD_WRITE_ERROR' | 'SHARE_ERROR' | 'UNAVAILABLE' | 'QUOTA_EXCEEDED';
|
|
3
|
+
|
|
4
|
+
/** What the page can do. `supports` answers from the app's handshake; a browser tab has none. */
|
|
5
|
+
export declare type Capability = 'finish' | 'title' | 'haptic' | 'clipboard' | 'share' | 'openUrl' | 'userKey' | 'back' | 'closeGuard' | 'errorReport' | 'storage';
|
|
6
|
+
|
|
7
|
+
export declare interface ChaticApps {
|
|
8
|
+
/** `true` inside the app; `false` in a browser tab, where the bridge calls fall back or fail. */
|
|
9
|
+
readonly inApp: boolean;
|
|
10
|
+
/** The app's context: view, platform, language, theme, `params`, `appLink`. `null` in a browser. */
|
|
11
|
+
readonly context: ChaticAppsContext | null;
|
|
12
|
+
/** Whether the app answers `capability` for this page: its version and the page's manifest. */
|
|
13
|
+
supports(capability: Capability): boolean;
|
|
14
|
+
/** Closes the view and hands `result` (JSON, at most 16 KiB) to whoever opened it. */
|
|
15
|
+
finish(result?: unknown): Promise<void>;
|
|
16
|
+
/** Puts a title (1–100 characters) in the app's bar; in a browser, the document's title. */
|
|
17
|
+
setTitle(title: string): Promise<void>;
|
|
18
|
+
/** Plays one short haptic. Never fails: a missing haptic costs nothing but the buzz. */
|
|
19
|
+
haptic(kind: HapticKind): void;
|
|
20
|
+
/** Copies text; in a browser, through the browser's clipboard. */
|
|
21
|
+
copy(text: string): Promise<void>;
|
|
22
|
+
/** Opens a web, mail, phone, SMS or store link outside the view. */
|
|
23
|
+
openUrl(url: string): Promise<void>;
|
|
24
|
+
/** Opens the share sheet; in a browser, the Web Share sheet, else copies. Waits for the user. */
|
|
25
|
+
share(content: ShareContent): Promise<ShareOutcome>;
|
|
26
|
+
/** This device's key for this page's origin (64 hex characters). Not an account, not a proof. */
|
|
27
|
+
getUserKey(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Writes an error to the app's log under this page's origin. `false` when it was not recorded. An
|
|
30
|
+
* `Error` sends its message and stack, a string itself, anything else only its type: a rejected
|
|
31
|
+
* value can be the user's own data, which must not reach a log.
|
|
32
|
+
*/
|
|
33
|
+
reportError(error: unknown): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* This page's own storage, on the device, apart from every other page's. In a browser tab, the
|
|
36
|
+
* browser's `localStorage` under the same limits.
|
|
37
|
+
*/
|
|
38
|
+
readonly storage: ChaticAppsStorage;
|
|
39
|
+
/**
|
|
40
|
+
* Takes Android's back button while `handler` is set: each press calls it, and nothing else
|
|
41
|
+
* happens. `null` gives back to the app.
|
|
42
|
+
*/
|
|
43
|
+
onBack(handler: (() => void) | null): void;
|
|
44
|
+
/**
|
|
45
|
+
* Asks the page before the user closes the view while `handler` is set: it gets what the user did
|
|
46
|
+
* and answers whether to close. A second close within three seconds closes anyway. `null` lets
|
|
47
|
+
* every close through. Use it only for something the user would lose.
|
|
48
|
+
*/
|
|
49
|
+
onCloseRequest(handler: ((trigger: CloseTrigger) => boolean | Promise<boolean>) | null): void;
|
|
50
|
+
/** Hears a theme or language change while the page shows; returns the function that stops it. */
|
|
51
|
+
onContextChange(listener: (context: ChaticAppsContext) => void): () => void;
|
|
52
|
+
/**
|
|
53
|
+
* A link that opens this page in the app with `params` as its query:
|
|
54
|
+
* `https://app.chatic.io/apps/<appId>?level=3`. The page is always opened at its root, so read what
|
|
55
|
+
* a link carries from `location.search`. In a browser, or an app before `appLink`, this page's own
|
|
56
|
+
* root with the same query instead.
|
|
57
|
+
*/
|
|
58
|
+
link(params?: LinkParams): string;
|
|
59
|
+
/** Stops listening to the app. Pending calls fail with `DISCONNECTED`; the next `connect()` starts afresh. */
|
|
60
|
+
disconnect(): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** What the app tells the page about where it runs. A snapshot; changes arrive through `onContextChange`. */
|
|
64
|
+
export declare type ChaticAppsContext = {
|
|
65
|
+
/** The protocol major the app speaks. */
|
|
66
|
+
protocolVersion: 1;
|
|
67
|
+
viewId: string;
|
|
68
|
+
platform: 'ios' | 'android';
|
|
69
|
+
/** The app's own version. */
|
|
70
|
+
appVersion: string;
|
|
71
|
+
/** The language the user chose in the app (`ko`, `en`). */
|
|
72
|
+
locale: string;
|
|
73
|
+
/** The app's theme, which can differ from the OS's. */
|
|
74
|
+
theme: Theme;
|
|
75
|
+
/** What whoever opened the page passed it; `{}` when nothing. */
|
|
76
|
+
params: {
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
/** The link that opens this page in the app; absent from older apps. */
|
|
80
|
+
appLink?: string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Every failure this library reports. Branch on `code`; `message` is English for a developer. */
|
|
84
|
+
export declare class ChaticAppsError extends Error {
|
|
85
|
+
readonly code: ChaticAppsErrorCode;
|
|
86
|
+
constructor(code: ChaticAppsErrorCode, message: string);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* What a call can fail with. The app's codes, plus five of this library's own:
|
|
91
|
+
* - `NOT_SUPPORTED` — this app cannot do it: an app built before it, a permission the page's manifest
|
|
92
|
+
* does not hold, or — in a browser — no clipboard;
|
|
93
|
+
* - `TIMEOUT` — the app did not answer in time;
|
|
94
|
+
* - `UNSUPPORTED_PROTOCOL` — the app speaks a protocol major this library does not know;
|
|
95
|
+
* - `NOT_IN_APP` — the call needs the app and the page is in a browser tab;
|
|
96
|
+
* - `DISCONNECTED` — the connection was closed with `disconnect()` before the app answered.
|
|
97
|
+
* A code this list does not name is still a failure of that call and nothing more.
|
|
98
|
+
*/
|
|
99
|
+
export declare type ChaticAppsErrorCode = AppErrorCode | 'NOT_SUPPORTED' | 'TIMEOUT' | 'UNSUPPORTED_PROTOCOL' | 'NOT_IN_APP' | 'DISCONNECTED' | (string & {});
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* This page's own storage in the app: kept on the device for the page's origin, shared by no other
|
|
103
|
+
* page, and kept when the user signs out. Values are JSON. At most 1,048,576 characters in all — keys
|
|
104
|
+
* plus values serialized — and at most 64 KiB in one call, the app's message limit.
|
|
105
|
+
*/
|
|
106
|
+
export declare interface ChaticAppsStorage {
|
|
107
|
+
/** The value stored under `key`, or `undefined` when there is none. */
|
|
108
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
109
|
+
/** The values stored under `keys`; a key with nothing stored is left out. */
|
|
110
|
+
getMany(keys: string[]): Promise<{
|
|
111
|
+
[key: string]: unknown;
|
|
112
|
+
}>;
|
|
113
|
+
/** Stores `value` under `key`. Fails with `QUOTA_EXCEEDED` past the page's limit. */
|
|
114
|
+
set(key: string, value: unknown): Promise<void>;
|
|
115
|
+
/** Stores every entry, or — when one is refused, or together they go past the limit — none. */
|
|
116
|
+
setMany(entries: {
|
|
117
|
+
[key: string]: unknown;
|
|
118
|
+
}): Promise<void>;
|
|
119
|
+
/** Removes one key or several; a key with nothing stored is no failure. */
|
|
120
|
+
remove(keys: string | string[]): Promise<void>;
|
|
121
|
+
/** Every key this page has stored. */
|
|
122
|
+
keys(): Promise<string[]>;
|
|
123
|
+
/** Removes everything this page has stored. */
|
|
124
|
+
clear(): Promise<void>;
|
|
125
|
+
/** What the page's storage holds and may hold, in characters. */
|
|
126
|
+
usage(): Promise<StorageUsage>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** What the user did to ask for the close: the app's close control, or Android back. */
|
|
130
|
+
export declare type CloseTrigger = 'control' | 'back';
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Connects to the app, or — in a browser tab — to nothing, returning the same interface with browser
|
|
134
|
+
* fallbacks, so one page runs in both. In the app it shakes hands first: what the app answers, and the
|
|
135
|
+
* context, come from that reply.
|
|
136
|
+
*
|
|
137
|
+
* One connection per page: a second call returns the first one's result, so two parts of a page — or a
|
|
138
|
+
* component mounted twice — cannot undo each other's back handler or report every error twice.
|
|
139
|
+
*
|
|
140
|
+
* Rejects with `UNSUPPORTED_PROTOCOL` when the app speaks a protocol major this library does not know
|
|
141
|
+
* (update the library, and tell the user the page needs updating), and with `TIMEOUT` when the app
|
|
142
|
+
* does not answer — as for a page the view navigated to from the one it opened.
|
|
143
|
+
*/
|
|
144
|
+
export declare const connect: (options?: ConnectOptions) => Promise<ChaticApps>;
|
|
145
|
+
|
|
146
|
+
export declare interface ConnectOptions {
|
|
147
|
+
/** Default wait for a reply, in milliseconds, while the page is visible. 10 seconds. */
|
|
148
|
+
timeoutMs?: number;
|
|
149
|
+
/** Report uncaught errors and unhandled rejections to the app's log. On by default. */
|
|
150
|
+
reportErrors?: boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The feel of a haptic: a tick, a tap, or the outcome of something the user did. */
|
|
154
|
+
export declare type HapticKind = 'selection' | 'impact' | 'success' | 'warning' | 'error';
|
|
155
|
+
|
|
156
|
+
/** Whether this page runs inside the app's WebView, which defines this before the page's scripts. */
|
|
157
|
+
export declare const isInApp: () => boolean;
|
|
158
|
+
|
|
159
|
+
/** What a link hands the page it opens, as its query: `{ level: 3 }` opens the page at `/?level=3`. */
|
|
160
|
+
export declare type LinkParams = Readonly<Record<string, string | number | boolean>>;
|
|
161
|
+
|
|
162
|
+
/** The bridge version this library is written against, sent as each request's `version`. */
|
|
163
|
+
export declare const SDK_BRIDGE_VERSION = "2.19.0";
|
|
164
|
+
|
|
165
|
+
export declare interface ShareContent {
|
|
166
|
+
title?: string;
|
|
167
|
+
message?: string;
|
|
168
|
+
/** `http(s)` only. Share `apps.link(params)` so a tap opens the page in the app. */
|
|
169
|
+
url?: string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* How a share went. `copied` is this library's fallback in a browser with no share sheet: the link
|
|
174
|
+
* or message went to the clipboard instead. On Android the app answers `shared` as soon as the chooser
|
|
175
|
+
* opens, whatever the user then does; only iOS reports `dismissed`.
|
|
176
|
+
*/
|
|
177
|
+
export declare type ShareOutcome = 'shared' | 'dismissed' | 'copied';
|
|
178
|
+
|
|
179
|
+
/** What the page's storage holds and may hold, in characters: keys plus values serialized. */
|
|
180
|
+
export declare type StorageUsage = {
|
|
181
|
+
used: number;
|
|
182
|
+
limit: number;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The shapes a page sees, declared here rather than imported: the app's message definitions are a
|
|
187
|
+
* private package, and a published library cannot point at it. `types.contract.test.ts` holds each one
|
|
188
|
+
* equal to its counterpart there, so the two cannot drift apart unnoticed.
|
|
189
|
+
*/
|
|
190
|
+
export declare type Theme = 'light' | 'dark';
|
|
191
|
+
|
|
192
|
+
export { }
|
package/index.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { C as w, b as L, s as I } from "./storage-BuvWwLx2.js";
|
|
2
|
+
const P = "2.19.0", x = 1e4, V = 2e3;
|
|
3
|
+
let W = 0;
|
|
4
|
+
const M = () => `cas-${Date.now().toString(36)}-${(++W).toString(36)}`, E = () => typeof document < "u" && document.visibilityState === "hidden", N = (t, o = x) => {
|
|
5
|
+
const r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
|
|
6
|
+
let l = !1;
|
|
7
|
+
const v = (a, n) => {
|
|
8
|
+
n.remaining === null || E() || (n.startedAt = Date.now(), n.timer = setTimeout(() => {
|
|
9
|
+
r.delete(a), n.reject(new w("TIMEOUT", "The app did not answer in time."));
|
|
10
|
+
}, n.remaining));
|
|
11
|
+
}, f = () => {
|
|
12
|
+
for (const [a, n] of r)
|
|
13
|
+
n.remaining !== null && (E() ? (n.timer && clearTimeout(n.timer), n.timer = null, n.remaining = Math.max(0, n.remaining - (Date.now() - n.startedAt))) : n.timer || (n.remaining = Math.max(n.remaining, V), v(a, n)));
|
|
14
|
+
};
|
|
15
|
+
typeof document < "u" && document.addEventListener("visibilitychange", f);
|
|
16
|
+
const h = t.listen((a) => {
|
|
17
|
+
let n;
|
|
18
|
+
try {
|
|
19
|
+
n = JSON.parse(a);
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!n || typeof n != "object" || typeof n.type != "string") return;
|
|
24
|
+
const d = typeof n.refId == "string" ? r.get(n.refId) : void 0;
|
|
25
|
+
if (d && typeof n.refId == "string") {
|
|
26
|
+
if (r.delete(n.refId), d.timer && clearTimeout(d.timer), n.success === !0)
|
|
27
|
+
d.resolve(n.data);
|
|
28
|
+
else {
|
|
29
|
+
const u = typeof n.error?.code == "string" ? n.error.code : "INTERNAL_ERROR", m = typeof n.error?.message == "string" ? n.error.message : u;
|
|
30
|
+
d.reject(new w(u, m));
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
i.get(n.type)?.forEach((u) => {
|
|
35
|
+
try {
|
|
36
|
+
u(n.data);
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
request: (a, n = {}, d = {}) => new Promise((u, m) => {
|
|
43
|
+
if (l) {
|
|
44
|
+
m(new w("DISCONNECTED", "The connection to the app was closed."));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const p = M(), e = d.timeoutMs === void 0 ? o : d.timeoutMs, s = {
|
|
48
|
+
resolve: u,
|
|
49
|
+
reject: m,
|
|
50
|
+
remaining: e,
|
|
51
|
+
startedAt: Date.now(),
|
|
52
|
+
timer: null
|
|
53
|
+
};
|
|
54
|
+
r.set(p, s), v(p, s), t.send(JSON.stringify({ type: a, data: n, refId: p, version: P }));
|
|
55
|
+
}),
|
|
56
|
+
onPush: (a, n) => {
|
|
57
|
+
let d = i.get(a);
|
|
58
|
+
return d || i.set(a, d = /* @__PURE__ */ new Set()), d.add(n), () => d?.delete(n);
|
|
59
|
+
},
|
|
60
|
+
close: () => {
|
|
61
|
+
if (!l) {
|
|
62
|
+
l = !0, h(), typeof document < "u" && document.removeEventListener("visibilitychange", f);
|
|
63
|
+
for (const a of r.values())
|
|
64
|
+
a.timer && clearTimeout(a.timer), a.reject(new w("DISCONNECTED", "The connection to the app was closed."));
|
|
65
|
+
r.clear(), i.clear();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}, U = () => typeof window < "u" && !!window.ReactNativeWebView, _ = () => ({
|
|
70
|
+
send: (t) => window.ReactNativeWebView?.postMessage(t),
|
|
71
|
+
listen: (t) => {
|
|
72
|
+
const o = (r) => {
|
|
73
|
+
const i = r.data;
|
|
74
|
+
typeof i == "string" && t(i);
|
|
75
|
+
};
|
|
76
|
+
return window.addEventListener("message", o), document.addEventListener("message", o), () => {
|
|
77
|
+
window.removeEventListener("message", o), document.removeEventListener("message", o);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}), b = {
|
|
81
|
+
finish: "FinishSubWebView",
|
|
82
|
+
title: "SetSubWebViewTitle",
|
|
83
|
+
haptic: "TriggerHaptic",
|
|
84
|
+
clipboard: "CopyToClipboard",
|
|
85
|
+
share: "OpenShareSheet",
|
|
86
|
+
openUrl: "OpenURL",
|
|
87
|
+
userKey: "GetSubWebViewUserKey",
|
|
88
|
+
back: "SetCanGoBack",
|
|
89
|
+
closeGuard: "SetSubWebViewCloseGuard",
|
|
90
|
+
errorReport: "ReportSubWebViewError",
|
|
91
|
+
storage: "GetSubWebViewStorage"
|
|
92
|
+
}, T = 1, j = 1e3, q = 4e3, R = () => typeof window < "u" && window.ChaticSubWebView || null, D = () => new Promise((t) => {
|
|
93
|
+
if (typeof document > "u" || document.readyState === "complete") {
|
|
94
|
+
t(R());
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
window.addEventListener("load", () => t(R()), { once: !0 });
|
|
98
|
+
}), G = (t) => {
|
|
99
|
+
let o, r;
|
|
100
|
+
try {
|
|
101
|
+
t instanceof Error ? (o = t.message || t.name, r = typeof t.stack == "string" ? t.stack : void 0) : typeof t == "string" ? o = t : o = `A non-Error value was thrown: ${Object.prototype.toString.call(t)}`;
|
|
102
|
+
} catch {
|
|
103
|
+
o = "An error that could not be read was thrown";
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
message: (o || "Unknown error").slice(0, j),
|
|
107
|
+
...r ? { stack: r.slice(0, q) } : {}
|
|
108
|
+
};
|
|
109
|
+
}, S = (t) => new w("NOT_SUPPORTED", `${t} is not available here: an older app, or not granted.`), O = (t) => Promise.reject(new w("NOT_IN_APP", `${t} needs the app; this page is in a browser.`)), C = (t = {}) => {
|
|
110
|
+
if (t === null || typeof t != "object" || Array.isArray(t))
|
|
111
|
+
throw new w("INVALID", "link() takes an object of query params, such as { level: 3 }.");
|
|
112
|
+
const o = new URLSearchParams();
|
|
113
|
+
for (const [i, l] of Object.entries(t)) o.append(i, String(l));
|
|
114
|
+
const r = o.toString();
|
|
115
|
+
return r ? `?${r}` : "";
|
|
116
|
+
}, k = (t) => typeof location > "u" ? `/${t}` : `${location.origin}/${t}`;
|
|
117
|
+
let y = null;
|
|
118
|
+
const H = (t = {}) => (y || (y = (U() ? $(_(), t) : Promise.resolve(K())).catch((o) => {
|
|
119
|
+
throw y = null, o;
|
|
120
|
+
})), y), $ = async (t, o = {}) => {
|
|
121
|
+
const r = N(t, o.timeoutMs);
|
|
122
|
+
try {
|
|
123
|
+
const i = await A(r, !0);
|
|
124
|
+
return B(r, i, o);
|
|
125
|
+
} catch (i) {
|
|
126
|
+
throw r.close(), i;
|
|
127
|
+
}
|
|
128
|
+
}, A = async (t, o) => {
|
|
129
|
+
const r = await t.request("WebAppReady", {}), i = r.subWebView ?? (o ? await D() : null);
|
|
130
|
+
if (i && i.protocolVersion !== T)
|
|
131
|
+
throw new w(
|
|
132
|
+
"UNSUPPORTED_PROTOCOL",
|
|
133
|
+
`The app speaks protocol ${String(i.protocolVersion)}; this library speaks ${T}.`
|
|
134
|
+
);
|
|
135
|
+
return {
|
|
136
|
+
supported: new Set(Array.isArray(r.supportedWebMessages) ? r.supportedWebMessages : []),
|
|
137
|
+
context: i
|
|
138
|
+
};
|
|
139
|
+
}, B = (t, o, r) => {
|
|
140
|
+
let i = null, l = null;
|
|
141
|
+
const v = /* @__PURE__ */ new Set(), f = [], h = (e) => o.supported.has(b[e]), a = (e, s, c) => h(e) ? t.request(b[e], s, c === void 0 ? {} : { timeoutMs: c }) : Promise.reject(S(e)), n = (e, s) => h("storage") ? t.request(e, s) : Promise.reject(S("storage")), d = (e) => v.forEach((s) => {
|
|
142
|
+
try {
|
|
143
|
+
s(e);
|
|
144
|
+
} catch (c) {
|
|
145
|
+
p.reportError(c);
|
|
146
|
+
}
|
|
147
|
+
}), u = () => {
|
|
148
|
+
h("back") && t.request(b.back, { canGoBack: !!i }).catch(() => {
|
|
149
|
+
}), h("closeGuard") && t.request(b.closeGuard, { enabled: !!l }).catch(() => {
|
|
150
|
+
});
|
|
151
|
+
}, m = (e) => {
|
|
152
|
+
if (!e.persisted) {
|
|
153
|
+
u();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
A(t, !1).then((s) => {
|
|
157
|
+
const c = o.context;
|
|
158
|
+
o.supported = s.supported, s.context && (o.context = s.context), u();
|
|
159
|
+
const g = o.context;
|
|
160
|
+
g && (g.theme !== c?.theme || g.locale !== c?.locale) && d(g);
|
|
161
|
+
}).catch(() => {
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
typeof window < "u" && (window.addEventListener("pageshow", m), f.push(() => window.removeEventListener("pageshow", m))), f.push(
|
|
165
|
+
t.onPush("OnBackPressed", () => {
|
|
166
|
+
try {
|
|
167
|
+
i?.();
|
|
168
|
+
} catch (e) {
|
|
169
|
+
p.reportError(e);
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
), f.push(
|
|
173
|
+
t.onPush("OnSubWebViewCloseRequested", (e) => {
|
|
174
|
+
const s = l;
|
|
175
|
+
if (!s) return;
|
|
176
|
+
const c = e?.trigger ?? "control";
|
|
177
|
+
Promise.resolve().then(() => s(c)).then((g) => g ? p.finish() : void 0).catch((g) => p.reportError(g));
|
|
178
|
+
})
|
|
179
|
+
), f.push(
|
|
180
|
+
t.onPush("OnSubWebViewContextChanged", (e) => {
|
|
181
|
+
o.context && (o.context = { ...o.context, ...e }, d(o.context));
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
const p = {
|
|
185
|
+
inApp: !0,
|
|
186
|
+
get context() {
|
|
187
|
+
return o.context;
|
|
188
|
+
},
|
|
189
|
+
supports: h,
|
|
190
|
+
finish: (e) => a("finish", e === void 0 ? {} : { result: e }).then(() => {
|
|
191
|
+
}),
|
|
192
|
+
setTitle: (e) => a("title", { title: e }).then(() => {
|
|
193
|
+
}),
|
|
194
|
+
haptic: (e) => {
|
|
195
|
+
h("haptic") && t.request(b.haptic, { kind: e }).catch(() => {
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
copy: (e) => a("clipboard", { text: e }).then(() => {
|
|
199
|
+
}),
|
|
200
|
+
openUrl: (e) => a("openUrl", { url: e }).then(() => {
|
|
201
|
+
}),
|
|
202
|
+
share: (e) => a("share", e, null).then(
|
|
203
|
+
(s) => s?.action === "dismissedAction" ? "dismissed" : "shared"
|
|
204
|
+
),
|
|
205
|
+
getUserKey: () => a("userKey").then((e) => e.key),
|
|
206
|
+
reportError: (e) => h("errorReport") ? t.request(b.errorReport, G(e)).then((s) => !!s?.recorded).catch(() => !1) : Promise.resolve(!1),
|
|
207
|
+
storage: I({
|
|
208
|
+
get: (e) => n("GetSubWebViewStorage", { keys: e }),
|
|
209
|
+
set: (e) => n("SetSubWebViewStorage", { entries: e }),
|
|
210
|
+
remove: (e) => n("RemoveSubWebViewStorage", { keys: e }),
|
|
211
|
+
clear: () => n("ClearSubWebViewStorage", {}),
|
|
212
|
+
info: () => n("GetSubWebViewStorageInfo", {})
|
|
213
|
+
}),
|
|
214
|
+
onBack: (e) => {
|
|
215
|
+
i = e, u();
|
|
216
|
+
},
|
|
217
|
+
onCloseRequest: (e) => {
|
|
218
|
+
l = e, u();
|
|
219
|
+
},
|
|
220
|
+
onContextChange: (e) => (v.add(e), () => v.delete(e)),
|
|
221
|
+
link: (e) => {
|
|
222
|
+
const s = C(e), c = o.context?.appLink;
|
|
223
|
+
return c ? `${c}${s}` : k(s);
|
|
224
|
+
},
|
|
225
|
+
disconnect: () => {
|
|
226
|
+
f.forEach((e) => e()), t.close(), y = null;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
if (r.reportErrors !== !1 && typeof window < "u") {
|
|
230
|
+
const e = (c) => {
|
|
231
|
+
p.reportError(c.error ?? c.message);
|
|
232
|
+
}, s = (c) => {
|
|
233
|
+
p.reportError(c.reason);
|
|
234
|
+
};
|
|
235
|
+
window.addEventListener("error", e), window.addEventListener("unhandledrejection", s), f.push(() => {
|
|
236
|
+
window.removeEventListener("error", e), window.removeEventListener("unhandledrejection", s);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return p;
|
|
240
|
+
}, K = () => {
|
|
241
|
+
const t = (o) => typeof navigator < "u" && navigator.clipboard ? navigator.clipboard.writeText(o) : Promise.reject(S("The clipboard"));
|
|
242
|
+
return {
|
|
243
|
+
inApp: !1,
|
|
244
|
+
context: null,
|
|
245
|
+
supports: () => !1,
|
|
246
|
+
finish: () => O("Finishing the view"),
|
|
247
|
+
setTitle: async (o) => {
|
|
248
|
+
typeof document < "u" && (document.title = o);
|
|
249
|
+
},
|
|
250
|
+
haptic: () => {
|
|
251
|
+
typeof navigator < "u" && navigator.vibrate?.(10);
|
|
252
|
+
},
|
|
253
|
+
copy: t,
|
|
254
|
+
openUrl: async (o) => {
|
|
255
|
+
typeof window < "u" && window.open(o, "_blank", "noopener,noreferrer");
|
|
256
|
+
},
|
|
257
|
+
share: async (o) => {
|
|
258
|
+
const r = [o.message, o.url].filter(Boolean).join(" ");
|
|
259
|
+
if (!r) throw new w("INVALID", "Share a message or a url.");
|
|
260
|
+
if (typeof navigator < "u" && navigator.share)
|
|
261
|
+
try {
|
|
262
|
+
return await navigator.share(o), "shared";
|
|
263
|
+
} catch (i) {
|
|
264
|
+
if (i?.name === "AbortError") return "dismissed";
|
|
265
|
+
}
|
|
266
|
+
return await t(r), "copied";
|
|
267
|
+
},
|
|
268
|
+
getUserKey: () => O("A user key"),
|
|
269
|
+
reportError: async (o) => (console.error(o), !1),
|
|
270
|
+
storage: L(),
|
|
271
|
+
onBack: () => {
|
|
272
|
+
},
|
|
273
|
+
onCloseRequest: () => {
|
|
274
|
+
},
|
|
275
|
+
onContextChange: () => () => {
|
|
276
|
+
},
|
|
277
|
+
link: (o) => k(C(o)),
|
|
278
|
+
disconnect: () => {
|
|
279
|
+
y = null;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
export {
|
|
284
|
+
w as ChaticAppsError,
|
|
285
|
+
P as SDK_BRIDGE_VERSION,
|
|
286
|
+
H as connect,
|
|
287
|
+
U as isInApp
|
|
288
|
+
};
|
package/mock.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./storage-yeS4HWKZ.cjs"),D=["WebAppReady","Ping","FinishSubWebView","SetSubWebViewTitle","TriggerHaptic","SetCanGoBack","SetSubWebViewCloseGuard","ReportSubWebViewError","GetSubWebViewStorage","SetSubWebViewStorage","RemoveSubWebViewStorage","ClearSubWebViewStorage","GetSubWebViewStorageInfo"],M={clipboard:"CopyToClipboard",share:"OpenShareSheet",openUrl:"OpenURL",userKey:"GetSubWebViewUserKey"},_=["selection","impact","success","warning","error"],U=64*1024,x=16*1024,K=3e3,B=s=>{if(/^(mailto|tel|sms|itms-apps|market):/i.test(s))return!0;const o=/^https?:\/\/([^/?#:@]+)/i.exec(s)?.[1]?.toLowerCase();return o?!/\.(apps|apps-dev)\.chatic\.io$/.test(o)&&!/^app(-dev)?\.chatic\.io$/.test(o):!1},$=(s,o)=>{if(s===void 0)return!0;try{const l=JSON.stringify(s);return l!==void 0&&l.length<=o}catch{return!1}},k=(s,o)=>s==null||typeof s=="string"&&s.length<=o,F=s=>{let o="";for(let l=0;o.length<64;l++){let p=2166136261^l;for(let u=0;u<s.length;u++)p=Math.imul(p^s.charCodeAt(u),16777619);o+=(p>>>0).toString(16).padStart(8,"0")}return o.slice(0,64)},J=s=>{const o=/^https:\/\/([a-z0-9-]+)\.(apps|apps-dev)\.chatic\.io$/.exec(s);return o?`https://${o[2]==="apps"?"app":"app-dev"}.chatic.io/apps/${o[1]}`:s},P=(s={})=>{const o=new Set([...D,...(s.permissions??[]).map(r=>M[r])]),l=window.location.origin,p={protocolVersion:1,viewId:"mock-view",platform:"ios",appVersion:"0.0.0-mock",locale:"ko",theme:"light",params:{},appLink:J(l),...s.context},u=s.log===!1?()=>{}:(...r)=>console.info("[chatic-apps mock]",...r);let O=!1;const C=[];let T,b=null;const m={theme:p.theme,locale:p.locale};let v=!1,I=!1,V=null,N=0;const d=new Map,E={read:r=>d.get(r),write:(r,n)=>{d.set(r,n)},delete:r=>{d.delete(r)},keys:()=>[...d.keys()]},g=G.ruledStore(E);if(s.storage&&!g.set(s.storage).ok)throw new Error("[chatic-apps mock] options.storage must be JSON entries within the storage limits.");const W=r=>{const n=JSON.stringify(r);if(!O){C.push(n);return}setTimeout(()=>window.dispatchEvent(new MessageEvent("message",{data:n})),0)},y=(r,n)=>W({type:r,success:!0,data:n,refId:`mock-push-${Date.now().toString(36)}`}),c=(r,n,i={})=>W({type:r,success:!0,data:i,refId:n}),a=(r,n,i,e)=>W({type:r,success:!1,error:{code:i,message:e},refId:n}),A=r=>{let n;try{n=JSON.parse(r)}catch{return}const{type:i,refId:e}=n;if(typeof i!="string")return;const t=n.data??{};if(O||(O=!0,C.splice(0).forEach(S=>setTimeout(()=>window.dispatchEvent(new MessageEvent("message",{data:S})),0))),u("←",i,t),b)return i==="FinishSubWebView"?a("OnFinishSubWebView",e,"NOT_OPEN","The view has closed."):u("view closed; no answer to",i);if(r.length>U)return a("ERROR",e,"TOO_LARGE","The message is over 65,536 characters.");if(!o.has(i))return a("ERROR",e,"NOT_FOUND",`${i} is not answered for this page.`);switch(i){case"WebAppReady":return c("OnWebAppReady",e,{appVersion:"2.19.0",protocolVersion:"2.19.0",supportedWebMessages:[...o],supportedAppMessages:[],subWebView:{...p,...m}});case"Ping":return c("Pong",e,{payload:t.payload??""});case"FinishSubWebView":return $(t.result,x)?(b={by:"page",result:t.result},s.onClose?.(b),u("view finished",t.result),c("OnFinishSubWebView",e)):a("OnFinishSubWebView",e,"INVALID","result must be JSON of at most 16 KiB.");case"SetSubWebViewTitle":{const S=typeof t.title=="string"?t.title.trim():"";return!S||S.length>100?a("OnSetSubWebViewTitle",e,"INVALID","title must be 1 to 100 characters."):(T=S,c("OnSetSubWebViewTitle",e))}case"TriggerHaptic":return _.includes(t.kind)?c("OnTriggerHaptic",e):a("OnTriggerHaptic",e,"INVALID_KIND",`Unknown haptic kind: ${String(t.kind)}`);case"SetCanGoBack":return typeof t.canGoBack!="boolean"?a("OnSetCanGoBack",e,"INVALID","canGoBack must be a boolean."):(v=t.canGoBack,c("OnSetCanGoBack",e));case"SetSubWebViewCloseGuard":return typeof t.enabled!="boolean"?a("OnSetSubWebViewCloseGuard",e,"INVALID","enabled must be a boolean."):(I=t.enabled,c("OnSetSubWebViewCloseGuard",e));case"ReportSubWebViewError":return typeof t.message!="string"||!t.message.trim()?a("OnReportSubWebViewError",e,"INVALID","message must be a non-empty string."):N>=20?c("OnReportSubWebViewError",e,{recorded:!1}):(N+=1,console.warn("[chatic-apps mock] page error",t.message,t.stack??""),c("OnReportSubWebViewError",e,{recorded:!0}));case"CopyToClipboard":return typeof t.text!="string"?a("OnCopyToClipboard",e,"INVALID","text must be a string."):(navigator.clipboard?.writeText(t.text).catch(()=>{}),c("OnCopyToClipboard",e,{copied:!0}));case"OpenURL":return typeof t.url!="string"||!B(t.url)?a("OnOpenURL",e,"LINK_NOT_ALLOWED","This link cannot be opened from a page."):(window.open(t.url,"_blank","noopener,noreferrer"),c("OnOpenURL",e));case"OpenShareSheet":{const{title:S,message:h,url:w}=t,L=!(typeof h=="string"&&h.trim())&&w==null;return!k(S,100)||!k(h,4e3)||!k(w,2048)||w===""||L?a("OnOpenShareSheet",e,"INVALID","Share a message or a url within their limits."):typeof w=="string"&&!/^https?:\/\//i.test(w)?a("OnOpenShareSheet",e,"LINK_NOT_ALLOWED","Only an http or https url can be shared."):(u("share sheet",t),c("OnOpenShareSheet",e,{action:"sharedAction",activityType:null}))}case"GetSubWebViewStorage":case"SetSubWebViewStorage":case"RemoveSubWebViewStorage":case"ClearSubWebViewStorage":case"GetSubWebViewStorageInfo":{const h={GetSubWebViewStorage:()=>g.get(t.keys),SetSubWebViewStorage:()=>g.set(t.entries),RemoveSubWebViewStorage:()=>g.remove(t.keys),ClearSubWebViewStorage:()=>g.clear(),GetSubWebViewStorageInfo:()=>g.info()}[i]();return h.ok?c(`On${i}`,e,h.value):a(`On${i}`,e,h.code,h.code==="QUOTA_EXCEEDED"?"This would take the page's storage past 1,048,576 characters.":"Keys are 1 to 200 characters; values must be JSON.")}case"GetSubWebViewUserKey":return c("OnGetSubWebViewUserKey",e,{key:s.userKey??F(l)});default:return a("ERROR",e,"NOT_FOUND",`${i} is not answered for this page.`)}},f=window;f.ReactNativeWebView={postMessage:A},f.ChaticSubWebView=p;const R={get title(){return T},get closed(){return b},get storage(){return Object.fromEntries([...d].map(([r,n])=>[r,JSON.parse(n)]))},pressBack:()=>{b||(v?y("OnBackPressed",{}):history.length>1?history.back():R.requestClose("back"))},requestClose:(r="control")=>{if(b)return;const n=Date.now();if(I&&(V===null||n-V>K)){V=n,y("OnSubWebViewCloseRequested",{trigger:r});return}b={by:"user"},s.onClose?.(b),u("view closed by the user")},changeContext:r=>{Object.assign(m,r),y("OnSubWebViewContextChanged",{...m})},uninstall:()=>{delete f.ReactNativeWebView,delete f.ChaticSubWebView}};return R};exports.installChaticAppsMock=P;
|
package/mock.d.cts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** What the app tells the page about where it runs. A snapshot; changes arrive through `onContextChange`. */
|
|
2
|
+
declare type ChaticAppsContext = {
|
|
3
|
+
/** The protocol major the app speaks. */
|
|
4
|
+
protocolVersion: 1;
|
|
5
|
+
viewId: string;
|
|
6
|
+
platform: 'ios' | 'android';
|
|
7
|
+
/** The app's own version. */
|
|
8
|
+
appVersion: string;
|
|
9
|
+
/** The language the user chose in the app (`ko`, `en`). */
|
|
10
|
+
locale: string;
|
|
11
|
+
/** The app's theme, which can differ from the OS's. */
|
|
12
|
+
theme: Theme;
|
|
13
|
+
/** What whoever opened the page passed it; `{}` when nothing. */
|
|
14
|
+
params: {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
/** The link that opens this page in the app; absent from older apps. */
|
|
18
|
+
appLink?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** What the user did to ask for the close: the app's close control, or Android back. */
|
|
22
|
+
declare type CloseTrigger = 'control' | 'back';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Turns a browser tab into a stand-in for the app, so a page can be built and tried without it. Call
|
|
26
|
+
* it before `connect`, in development only. It answers as the app does — the base set, plus what
|
|
27
|
+
* `permissions` grants, and `NOT_FOUND` for the rest — and lets the developer play the user's side
|
|
28
|
+
* through the returned controller.
|
|
29
|
+
*
|
|
30
|
+
* It is a stand-in, not the app: the share sheet is logged rather than shown, the user key is not the
|
|
31
|
+
* app's, and nothing here proves a page works on a device.
|
|
32
|
+
*/
|
|
33
|
+
export declare const installChaticAppsMock: (options?: MockOptions) => MockController;
|
|
34
|
+
|
|
35
|
+
export declare interface MockController {
|
|
36
|
+
/** The title the page last asked for, if any. */
|
|
37
|
+
readonly title: string | undefined;
|
|
38
|
+
/** How the view closed, if it has: by the page (with its result) or by the user. */
|
|
39
|
+
readonly closed: {
|
|
40
|
+
by: 'page' | 'user';
|
|
41
|
+
result?: unknown;
|
|
42
|
+
} | null;
|
|
43
|
+
/** What the page's storage holds now. */
|
|
44
|
+
readonly storage: {
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
};
|
|
47
|
+
/** Android's back button: to the page if it took back, else back in history, else a close. */
|
|
48
|
+
pressBack(): void;
|
|
49
|
+
/** The user asks to close: to the page if it guards closing (a second ask within 3 s closes). */
|
|
50
|
+
requestClose(trigger?: CloseTrigger): void;
|
|
51
|
+
/** A theme or language change while the page shows. */
|
|
52
|
+
changeContext(change: Partial<Pick<ChaticAppsContext, 'theme' | 'locale'>>): void;
|
|
53
|
+
/** Removes the fake app. */
|
|
54
|
+
uninstall(): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export declare interface MockOptions {
|
|
58
|
+
/** What the page's manifest would grant. None by default, as for a page with no manifest. */
|
|
59
|
+
permissions?: MockPermission[];
|
|
60
|
+
/** Overrides for the context the page gets; the rest is filled in. */
|
|
61
|
+
context?: Partial<ChaticAppsContext>;
|
|
62
|
+
/** The key `getUserKey` answers; a stable one derived from the page's origin by default. */
|
|
63
|
+
userKey?: string;
|
|
64
|
+
/** Called when the view closes: by the page (`finish`, with its result) or by the user. */
|
|
65
|
+
onClose?: (closed: {
|
|
66
|
+
by: 'page' | 'user';
|
|
67
|
+
result?: unknown;
|
|
68
|
+
}) => void;
|
|
69
|
+
/** What the page's storage holds when the mock starts; empty by default. Kept in memory only. */
|
|
70
|
+
storage?: {
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
};
|
|
73
|
+
/** Log each request and reply to the console. On by default. */
|
|
74
|
+
log?: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A manifest permission, as the page would declare it in `/.well-known/chatic-app.json`. */
|
|
78
|
+
export declare type MockPermission = 'clipboard' | 'share' | 'openUrl' | 'userKey';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The shapes a page sees, declared here rather than imported: the app's message definitions are a
|
|
82
|
+
* private package, and a published library cannot point at it. `types.contract.test.ts` holds each one
|
|
83
|
+
* equal to its counterpart there, so the two cannot drift apart unnoticed.
|
|
84
|
+
*/
|
|
85
|
+
declare type Theme = 'light' | 'dark';
|
|
86
|
+
|
|
87
|
+
export { }
|
package/mock.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** What the app tells the page about where it runs. A snapshot; changes arrive through `onContextChange`. */
|
|
2
|
+
declare type ChaticAppsContext = {
|
|
3
|
+
/** The protocol major the app speaks. */
|
|
4
|
+
protocolVersion: 1;
|
|
5
|
+
viewId: string;
|
|
6
|
+
platform: 'ios' | 'android';
|
|
7
|
+
/** The app's own version. */
|
|
8
|
+
appVersion: string;
|
|
9
|
+
/** The language the user chose in the app (`ko`, `en`). */
|
|
10
|
+
locale: string;
|
|
11
|
+
/** The app's theme, which can differ from the OS's. */
|
|
12
|
+
theme: Theme;
|
|
13
|
+
/** What whoever opened the page passed it; `{}` when nothing. */
|
|
14
|
+
params: {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
/** The link that opens this page in the app; absent from older apps. */
|
|
18
|
+
appLink?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** What the user did to ask for the close: the app's close control, or Android back. */
|
|
22
|
+
declare type CloseTrigger = 'control' | 'back';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Turns a browser tab into a stand-in for the app, so a page can be built and tried without it. Call
|
|
26
|
+
* it before `connect`, in development only. It answers as the app does — the base set, plus what
|
|
27
|
+
* `permissions` grants, and `NOT_FOUND` for the rest — and lets the developer play the user's side
|
|
28
|
+
* through the returned controller.
|
|
29
|
+
*
|
|
30
|
+
* It is a stand-in, not the app: the share sheet is logged rather than shown, the user key is not the
|
|
31
|
+
* app's, and nothing here proves a page works on a device.
|
|
32
|
+
*/
|
|
33
|
+
export declare const installChaticAppsMock: (options?: MockOptions) => MockController;
|
|
34
|
+
|
|
35
|
+
export declare interface MockController {
|
|
36
|
+
/** The title the page last asked for, if any. */
|
|
37
|
+
readonly title: string | undefined;
|
|
38
|
+
/** How the view closed, if it has: by the page (with its result) or by the user. */
|
|
39
|
+
readonly closed: {
|
|
40
|
+
by: 'page' | 'user';
|
|
41
|
+
result?: unknown;
|
|
42
|
+
} | null;
|
|
43
|
+
/** What the page's storage holds now. */
|
|
44
|
+
readonly storage: {
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
};
|
|
47
|
+
/** Android's back button: to the page if it took back, else back in history, else a close. */
|
|
48
|
+
pressBack(): void;
|
|
49
|
+
/** The user asks to close: to the page if it guards closing (a second ask within 3 s closes). */
|
|
50
|
+
requestClose(trigger?: CloseTrigger): void;
|
|
51
|
+
/** A theme or language change while the page shows. */
|
|
52
|
+
changeContext(change: Partial<Pick<ChaticAppsContext, 'theme' | 'locale'>>): void;
|
|
53
|
+
/** Removes the fake app. */
|
|
54
|
+
uninstall(): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export declare interface MockOptions {
|
|
58
|
+
/** What the page's manifest would grant. None by default, as for a page with no manifest. */
|
|
59
|
+
permissions?: MockPermission[];
|
|
60
|
+
/** Overrides for the context the page gets; the rest is filled in. */
|
|
61
|
+
context?: Partial<ChaticAppsContext>;
|
|
62
|
+
/** The key `getUserKey` answers; a stable one derived from the page's origin by default. */
|
|
63
|
+
userKey?: string;
|
|
64
|
+
/** Called when the view closes: by the page (`finish`, with its result) or by the user. */
|
|
65
|
+
onClose?: (closed: {
|
|
66
|
+
by: 'page' | 'user';
|
|
67
|
+
result?: unknown;
|
|
68
|
+
}) => void;
|
|
69
|
+
/** What the page's storage holds when the mock starts; empty by default. Kept in memory only. */
|
|
70
|
+
storage?: {
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
};
|
|
73
|
+
/** Log each request and reply to the console. On by default. */
|
|
74
|
+
log?: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A manifest permission, as the page would declare it in `/.well-known/chatic-app.json`. */
|
|
78
|
+
export declare type MockPermission = 'clipboard' | 'share' | 'openUrl' | 'userKey';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The shapes a page sees, declared here rather than imported: the app's message definitions are a
|
|
82
|
+
* private package, and a published library cannot point at it. `types.contract.test.ts` holds each one
|
|
83
|
+
* equal to its counterpart there, so the two cannot drift apart unnoticed.
|
|
84
|
+
*/
|
|
85
|
+
declare type Theme = 'light' | 'dark';
|
|
86
|
+
|
|
87
|
+
export { }
|