@lemoncloud/chatic-apps-sdk 0.0.0-stage → 0.2.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/AGENTS.md +56 -0
- package/GUIDE.md +219 -0
- package/README.md +286 -2
- package/chatic-apps-sdk.global.js +1 -0
- package/index.cjs +1 -0
- package/index.d.cts +225 -0
- package/index.d.ts +225 -0
- package/index.js +331 -0
- package/mock.cjs +1 -0
- package/mock.d.cts +109 -0
- package/mock.d.ts +109 -0
- package/mock.js +217 -0
- package/package.json +45 -5
- package/storage-BuvWwLx2.js +104 -0
- package/storage-yeS4HWKZ.cjs +1 -0
package/index.d.cts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
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' | 'SETTINGS_ERROR';
|
|
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' | 'permissions';
|
|
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
|
+
/** The camera and the microphone. */
|
|
51
|
+
readonly permissions: ChaticAppsPermissions;
|
|
52
|
+
/** Opens the app's page in the OS settings, where a `blocked` permission can be turned back on. */
|
|
53
|
+
openSettings(): Promise<void>;
|
|
54
|
+
/** Hears a theme or language change while the page shows; returns the function that stops it. */
|
|
55
|
+
onContextChange(listener: (context: ChaticAppsContext) => void): () => void;
|
|
56
|
+
/**
|
|
57
|
+
* A link that opens this page in the app with `params` as its query:
|
|
58
|
+
* `https://app.chatic.io/apps/<appId>?level=3`. The page is always opened at its root, so read what
|
|
59
|
+
* a link carries from `location.search`. In a browser, or an app before `appLink`, this page's own
|
|
60
|
+
* root with the same query instead.
|
|
61
|
+
*/
|
|
62
|
+
link(params?: LinkParams): string;
|
|
63
|
+
/** Stops listening to the app. Pending calls fail with `DISCONNECTED`; the next `connect()` starts afresh. */
|
|
64
|
+
disconnect(): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What the app tells the page about where it runs. A snapshot; changes arrive through `onContextChange`. */
|
|
68
|
+
export declare type ChaticAppsContext = {
|
|
69
|
+
/** The protocol major the app speaks. */
|
|
70
|
+
protocolVersion: 1;
|
|
71
|
+
viewId: string;
|
|
72
|
+
platform: 'ios' | 'android';
|
|
73
|
+
/** The app's own version. */
|
|
74
|
+
appVersion: string;
|
|
75
|
+
/** The language the user chose in the app (`ko`, `en`). */
|
|
76
|
+
locale: string;
|
|
77
|
+
/** The app's theme, which can differ from the OS's. */
|
|
78
|
+
theme: Theme;
|
|
79
|
+
/** What whoever opened the page passed it; `{}` when nothing. */
|
|
80
|
+
params: {
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
};
|
|
83
|
+
/** The link that opens this page in the app; absent from older apps. */
|
|
84
|
+
appLink?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** Every failure this library reports. Branch on `code`; `message` is English for a developer. */
|
|
88
|
+
export declare class ChaticAppsError extends Error {
|
|
89
|
+
readonly code: ChaticAppsErrorCode;
|
|
90
|
+
constructor(code: ChaticAppsErrorCode, message: string);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What a call can fail with. The app's codes, plus five of this library's own:
|
|
95
|
+
* - `NOT_SUPPORTED` — this app cannot do it: an app built before it, a permission the page's manifest
|
|
96
|
+
* does not hold, or — in a browser — no clipboard;
|
|
97
|
+
* - `TIMEOUT` — the app did not answer in time;
|
|
98
|
+
* - `UNSUPPORTED_PROTOCOL` — the app speaks a protocol major this library does not know;
|
|
99
|
+
* - `NOT_IN_APP` — the call needs the app and the page is in a browser tab;
|
|
100
|
+
* - `DISCONNECTED` — the connection was closed with `disconnect()` before the app answered.
|
|
101
|
+
* A code this list does not name is still a failure of that call and nothing more.
|
|
102
|
+
*/
|
|
103
|
+
export declare type ChaticAppsErrorCode = AppErrorCode | 'NOT_SUPPORTED' | 'TIMEOUT' | 'UNSUPPORTED_PROTOCOL' | 'NOT_IN_APP' | 'DISCONNECTED' | (string & {});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The camera and the microphone. A page captures with the browser's own `getUserMedia`; the OS asks the
|
|
107
|
+
* user the first time, under the app's name. These calls let a page learn where it stands and ask when
|
|
108
|
+
* the user reaches for the feature, rather than meet the prompt in the middle of a capture.
|
|
109
|
+
*/
|
|
110
|
+
export declare interface ChaticAppsPermissions {
|
|
111
|
+
/** Where the app stands with the OS for `kind`, showing the user nothing. */
|
|
112
|
+
query(kind: DeviceKind): Promise<PermissionState_2>;
|
|
113
|
+
/**
|
|
114
|
+
* Asks the OS for `kind` and resolves once the user has answered: `granted`, `blocked` (it will not
|
|
115
|
+
* ask again; `openSettings()`), or `prompt` when the user refused this time and it may be asked
|
|
116
|
+
* again. Ask when the user reaches for the feature, not at start: an unexplained question is the
|
|
117
|
+
* one most often refused.
|
|
118
|
+
*/
|
|
119
|
+
request(kind: DeviceKind): Promise<PermissionState_2>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* This page's own storage in the app: kept on the device for the page's origin, shared by no other
|
|
124
|
+
* page, and kept when the user signs out. Values are JSON. At most 1,048,576 characters in all — keys
|
|
125
|
+
* plus values serialized — and at most 64 KiB in one call, the app's message limit.
|
|
126
|
+
*/
|
|
127
|
+
export declare interface ChaticAppsStorage {
|
|
128
|
+
/** The value stored under `key`, or `undefined` when there is none. */
|
|
129
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
130
|
+
/** The values stored under `keys`; a key with nothing stored is left out. */
|
|
131
|
+
getMany(keys: string[]): Promise<{
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
}>;
|
|
134
|
+
/** Stores `value` under `key`. Fails with `QUOTA_EXCEEDED` past the page's limit. */
|
|
135
|
+
set(key: string, value: unknown): Promise<void>;
|
|
136
|
+
/** Stores every entry, or — when one is refused, or together they go past the limit — none. */
|
|
137
|
+
setMany(entries: {
|
|
138
|
+
[key: string]: unknown;
|
|
139
|
+
}): Promise<void>;
|
|
140
|
+
/** Removes one key or several; a key with nothing stored is no failure. */
|
|
141
|
+
remove(keys: string | string[]): Promise<void>;
|
|
142
|
+
/** Every key this page has stored. */
|
|
143
|
+
keys(): Promise<string[]>;
|
|
144
|
+
/** Removes everything this page has stored. */
|
|
145
|
+
clear(): Promise<void>;
|
|
146
|
+
/** What the page's storage holds and may hold, in characters. */
|
|
147
|
+
usage(): Promise<StorageUsage>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** What the user did to ask for the close: the app's close control, or Android back. */
|
|
151
|
+
export declare type CloseTrigger = 'control' | 'back';
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Connects to the app, or — in a browser tab — to nothing, returning the same interface with browser
|
|
155
|
+
* fallbacks, so one page runs in both. In the app it shakes hands first: what the app answers, and the
|
|
156
|
+
* context, come from that reply.
|
|
157
|
+
*
|
|
158
|
+
* One connection per page: a second call returns the first one's result, so two parts of a page — or a
|
|
159
|
+
* component mounted twice — cannot undo each other's back handler or report every error twice.
|
|
160
|
+
*
|
|
161
|
+
* Rejects with `UNSUPPORTED_PROTOCOL` when the app speaks a protocol major this library does not know
|
|
162
|
+
* (update the library, and tell the user the page needs updating), and with `TIMEOUT` when the app
|
|
163
|
+
* does not answer — as for a page the view navigated to from the one it opened.
|
|
164
|
+
*/
|
|
165
|
+
export declare const connect: (options?: ConnectOptions) => Promise<ChaticApps>;
|
|
166
|
+
|
|
167
|
+
export declare interface ConnectOptions {
|
|
168
|
+
/** Default wait for a reply, in milliseconds, while the page is visible. 10 seconds. */
|
|
169
|
+
timeoutMs?: number;
|
|
170
|
+
/** Report uncaught errors and unhandled rejections to the app's log. On by default. */
|
|
171
|
+
reportErrors?: boolean;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A device a page captures from with `getUserMedia`. */
|
|
175
|
+
export declare type DeviceKind = 'camera' | 'microphone';
|
|
176
|
+
|
|
177
|
+
/** The feel of a haptic: a tick, a tap, or the outcome of something the user did. */
|
|
178
|
+
export declare type HapticKind = 'selection' | 'impact' | 'success' | 'warning' | 'error';
|
|
179
|
+
|
|
180
|
+
/** Whether this page runs inside the app's WebView, which defines this before the page's scripts. */
|
|
181
|
+
export declare const isInApp: () => boolean;
|
|
182
|
+
|
|
183
|
+
/** What a link hands the page it opens, as its query: `{ level: 3 }` opens the page at `/?level=3`. */
|
|
184
|
+
export declare type LinkParams = Readonly<Record<string, string | number | boolean>>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Where the app stands with the OS for one device:
|
|
188
|
+
* - `granted` — `getUserMedia` for it asks nothing further;
|
|
189
|
+
* - `prompt` — the OS has not been asked, or was refused and may be asked again;
|
|
190
|
+
* - `blocked` — only the OS settings can change it (`openSettings()`).
|
|
191
|
+
*/
|
|
192
|
+
declare type PermissionState_2 = 'granted' | 'prompt' | 'blocked';
|
|
193
|
+
export { PermissionState_2 as PermissionState }
|
|
194
|
+
|
|
195
|
+
/** The bridge version this library is written against, sent as each request's `version`. */
|
|
196
|
+
export declare const SDK_BRIDGE_VERSION = "2.20.0";
|
|
197
|
+
|
|
198
|
+
export declare interface ShareContent {
|
|
199
|
+
title?: string;
|
|
200
|
+
message?: string;
|
|
201
|
+
/** `http(s)` only. Share `apps.link(params)` so a tap opens the page in the app. */
|
|
202
|
+
url?: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* How a share went. `copied` is this library's fallback in a browser with no share sheet: the link
|
|
207
|
+
* or message went to the clipboard instead. On Android the app answers `shared` as soon as the chooser
|
|
208
|
+
* opens, whatever the user then does; only iOS reports `dismissed`.
|
|
209
|
+
*/
|
|
210
|
+
export declare type ShareOutcome = 'shared' | 'dismissed' | 'copied';
|
|
211
|
+
|
|
212
|
+
/** What the page's storage holds and may hold, in characters: keys plus values serialized. */
|
|
213
|
+
export declare type StorageUsage = {
|
|
214
|
+
used: number;
|
|
215
|
+
limit: number;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The shapes a page sees, declared here rather than imported: the app's message definitions are a
|
|
220
|
+
* private package, and a published library cannot point at it. `types.contract.test.ts` holds each one
|
|
221
|
+
* equal to its counterpart there, so the two cannot drift apart unnoticed.
|
|
222
|
+
*/
|
|
223
|
+
export declare type Theme = 'light' | 'dark';
|
|
224
|
+
|
|
225
|
+
export { }
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
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' | 'SETTINGS_ERROR';
|
|
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' | 'permissions';
|
|
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
|
+
/** The camera and the microphone. */
|
|
51
|
+
readonly permissions: ChaticAppsPermissions;
|
|
52
|
+
/** Opens the app's page in the OS settings, where a `blocked` permission can be turned back on. */
|
|
53
|
+
openSettings(): Promise<void>;
|
|
54
|
+
/** Hears a theme or language change while the page shows; returns the function that stops it. */
|
|
55
|
+
onContextChange(listener: (context: ChaticAppsContext) => void): () => void;
|
|
56
|
+
/**
|
|
57
|
+
* A link that opens this page in the app with `params` as its query:
|
|
58
|
+
* `https://app.chatic.io/apps/<appId>?level=3`. The page is always opened at its root, so read what
|
|
59
|
+
* a link carries from `location.search`. In a browser, or an app before `appLink`, this page's own
|
|
60
|
+
* root with the same query instead.
|
|
61
|
+
*/
|
|
62
|
+
link(params?: LinkParams): string;
|
|
63
|
+
/** Stops listening to the app. Pending calls fail with `DISCONNECTED`; the next `connect()` starts afresh. */
|
|
64
|
+
disconnect(): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What the app tells the page about where it runs. A snapshot; changes arrive through `onContextChange`. */
|
|
68
|
+
export declare type ChaticAppsContext = {
|
|
69
|
+
/** The protocol major the app speaks. */
|
|
70
|
+
protocolVersion: 1;
|
|
71
|
+
viewId: string;
|
|
72
|
+
platform: 'ios' | 'android';
|
|
73
|
+
/** The app's own version. */
|
|
74
|
+
appVersion: string;
|
|
75
|
+
/** The language the user chose in the app (`ko`, `en`). */
|
|
76
|
+
locale: string;
|
|
77
|
+
/** The app's theme, which can differ from the OS's. */
|
|
78
|
+
theme: Theme;
|
|
79
|
+
/** What whoever opened the page passed it; `{}` when nothing. */
|
|
80
|
+
params: {
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
};
|
|
83
|
+
/** The link that opens this page in the app; absent from older apps. */
|
|
84
|
+
appLink?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** Every failure this library reports. Branch on `code`; `message` is English for a developer. */
|
|
88
|
+
export declare class ChaticAppsError extends Error {
|
|
89
|
+
readonly code: ChaticAppsErrorCode;
|
|
90
|
+
constructor(code: ChaticAppsErrorCode, message: string);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What a call can fail with. The app's codes, plus five of this library's own:
|
|
95
|
+
* - `NOT_SUPPORTED` — this app cannot do it: an app built before it, a permission the page's manifest
|
|
96
|
+
* does not hold, or — in a browser — no clipboard;
|
|
97
|
+
* - `TIMEOUT` — the app did not answer in time;
|
|
98
|
+
* - `UNSUPPORTED_PROTOCOL` — the app speaks a protocol major this library does not know;
|
|
99
|
+
* - `NOT_IN_APP` — the call needs the app and the page is in a browser tab;
|
|
100
|
+
* - `DISCONNECTED` — the connection was closed with `disconnect()` before the app answered.
|
|
101
|
+
* A code this list does not name is still a failure of that call and nothing more.
|
|
102
|
+
*/
|
|
103
|
+
export declare type ChaticAppsErrorCode = AppErrorCode | 'NOT_SUPPORTED' | 'TIMEOUT' | 'UNSUPPORTED_PROTOCOL' | 'NOT_IN_APP' | 'DISCONNECTED' | (string & {});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The camera and the microphone. A page captures with the browser's own `getUserMedia`; the OS asks the
|
|
107
|
+
* user the first time, under the app's name. These calls let a page learn where it stands and ask when
|
|
108
|
+
* the user reaches for the feature, rather than meet the prompt in the middle of a capture.
|
|
109
|
+
*/
|
|
110
|
+
export declare interface ChaticAppsPermissions {
|
|
111
|
+
/** Where the app stands with the OS for `kind`, showing the user nothing. */
|
|
112
|
+
query(kind: DeviceKind): Promise<PermissionState_2>;
|
|
113
|
+
/**
|
|
114
|
+
* Asks the OS for `kind` and resolves once the user has answered: `granted`, `blocked` (it will not
|
|
115
|
+
* ask again; `openSettings()`), or `prompt` when the user refused this time and it may be asked
|
|
116
|
+
* again. Ask when the user reaches for the feature, not at start: an unexplained question is the
|
|
117
|
+
* one most often refused.
|
|
118
|
+
*/
|
|
119
|
+
request(kind: DeviceKind): Promise<PermissionState_2>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* This page's own storage in the app: kept on the device for the page's origin, shared by no other
|
|
124
|
+
* page, and kept when the user signs out. Values are JSON. At most 1,048,576 characters in all — keys
|
|
125
|
+
* plus values serialized — and at most 64 KiB in one call, the app's message limit.
|
|
126
|
+
*/
|
|
127
|
+
export declare interface ChaticAppsStorage {
|
|
128
|
+
/** The value stored under `key`, or `undefined` when there is none. */
|
|
129
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
130
|
+
/** The values stored under `keys`; a key with nothing stored is left out. */
|
|
131
|
+
getMany(keys: string[]): Promise<{
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
}>;
|
|
134
|
+
/** Stores `value` under `key`. Fails with `QUOTA_EXCEEDED` past the page's limit. */
|
|
135
|
+
set(key: string, value: unknown): Promise<void>;
|
|
136
|
+
/** Stores every entry, or — when one is refused, or together they go past the limit — none. */
|
|
137
|
+
setMany(entries: {
|
|
138
|
+
[key: string]: unknown;
|
|
139
|
+
}): Promise<void>;
|
|
140
|
+
/** Removes one key or several; a key with nothing stored is no failure. */
|
|
141
|
+
remove(keys: string | string[]): Promise<void>;
|
|
142
|
+
/** Every key this page has stored. */
|
|
143
|
+
keys(): Promise<string[]>;
|
|
144
|
+
/** Removes everything this page has stored. */
|
|
145
|
+
clear(): Promise<void>;
|
|
146
|
+
/** What the page's storage holds and may hold, in characters. */
|
|
147
|
+
usage(): Promise<StorageUsage>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** What the user did to ask for the close: the app's close control, or Android back. */
|
|
151
|
+
export declare type CloseTrigger = 'control' | 'back';
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Connects to the app, or — in a browser tab — to nothing, returning the same interface with browser
|
|
155
|
+
* fallbacks, so one page runs in both. In the app it shakes hands first: what the app answers, and the
|
|
156
|
+
* context, come from that reply.
|
|
157
|
+
*
|
|
158
|
+
* One connection per page: a second call returns the first one's result, so two parts of a page — or a
|
|
159
|
+
* component mounted twice — cannot undo each other's back handler or report every error twice.
|
|
160
|
+
*
|
|
161
|
+
* Rejects with `UNSUPPORTED_PROTOCOL` when the app speaks a protocol major this library does not know
|
|
162
|
+
* (update the library, and tell the user the page needs updating), and with `TIMEOUT` when the app
|
|
163
|
+
* does not answer — as for a page the view navigated to from the one it opened.
|
|
164
|
+
*/
|
|
165
|
+
export declare const connect: (options?: ConnectOptions) => Promise<ChaticApps>;
|
|
166
|
+
|
|
167
|
+
export declare interface ConnectOptions {
|
|
168
|
+
/** Default wait for a reply, in milliseconds, while the page is visible. 10 seconds. */
|
|
169
|
+
timeoutMs?: number;
|
|
170
|
+
/** Report uncaught errors and unhandled rejections to the app's log. On by default. */
|
|
171
|
+
reportErrors?: boolean;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A device a page captures from with `getUserMedia`. */
|
|
175
|
+
export declare type DeviceKind = 'camera' | 'microphone';
|
|
176
|
+
|
|
177
|
+
/** The feel of a haptic: a tick, a tap, or the outcome of something the user did. */
|
|
178
|
+
export declare type HapticKind = 'selection' | 'impact' | 'success' | 'warning' | 'error';
|
|
179
|
+
|
|
180
|
+
/** Whether this page runs inside the app's WebView, which defines this before the page's scripts. */
|
|
181
|
+
export declare const isInApp: () => boolean;
|
|
182
|
+
|
|
183
|
+
/** What a link hands the page it opens, as its query: `{ level: 3 }` opens the page at `/?level=3`. */
|
|
184
|
+
export declare type LinkParams = Readonly<Record<string, string | number | boolean>>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Where the app stands with the OS for one device:
|
|
188
|
+
* - `granted` — `getUserMedia` for it asks nothing further;
|
|
189
|
+
* - `prompt` — the OS has not been asked, or was refused and may be asked again;
|
|
190
|
+
* - `blocked` — only the OS settings can change it (`openSettings()`).
|
|
191
|
+
*/
|
|
192
|
+
declare type PermissionState_2 = 'granted' | 'prompt' | 'blocked';
|
|
193
|
+
export { PermissionState_2 as PermissionState }
|
|
194
|
+
|
|
195
|
+
/** The bridge version this library is written against, sent as each request's `version`. */
|
|
196
|
+
export declare const SDK_BRIDGE_VERSION = "2.20.0";
|
|
197
|
+
|
|
198
|
+
export declare interface ShareContent {
|
|
199
|
+
title?: string;
|
|
200
|
+
message?: string;
|
|
201
|
+
/** `http(s)` only. Share `apps.link(params)` so a tap opens the page in the app. */
|
|
202
|
+
url?: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* How a share went. `copied` is this library's fallback in a browser with no share sheet: the link
|
|
207
|
+
* or message went to the clipboard instead. On Android the app answers `shared` as soon as the chooser
|
|
208
|
+
* opens, whatever the user then does; only iOS reports `dismissed`.
|
|
209
|
+
*/
|
|
210
|
+
export declare type ShareOutcome = 'shared' | 'dismissed' | 'copied';
|
|
211
|
+
|
|
212
|
+
/** What the page's storage holds and may hold, in characters: keys plus values serialized. */
|
|
213
|
+
export declare type StorageUsage = {
|
|
214
|
+
used: number;
|
|
215
|
+
limit: number;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The shapes a page sees, declared here rather than imported: the app's message definitions are a
|
|
220
|
+
* private package, and a published library cannot point at it. `types.contract.test.ts` holds each one
|
|
221
|
+
* equal to its counterpart there, so the two cannot drift apart unnoticed.
|
|
222
|
+
*/
|
|
223
|
+
export declare type Theme = 'light' | 'dark';
|
|
224
|
+
|
|
225
|
+
export { }
|