@lemoncloud/chatic-apps-sdk 0.2.0 → 0.3.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/index.js CHANGED
@@ -1,83 +1,156 @@
1
- import { C as u, b as I, s as k } from "./storage-BuvWwLx2.js";
2
- const V = "2.20.0", x = 1e4, N = 2e3;
3
- let W = 0;
4
- const q = () => `cas-${Date.now().toString(36)}-${(++W).toString(36)}`, R = () => typeof document < "u" && document.visibilityState === "hidden", U = (r, t = x) => {
5
- const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
6
- let h = !1;
7
- const v = (a, o) => {
8
- o.remaining === null || R() || (o.startedAt = Date.now(), o.timer = setTimeout(() => {
9
- n.delete(a), o.reject(new u("TIMEOUT", "The app did not answer in time."));
10
- }, o.remaining));
11
- }, w = () => {
12
- for (const [a, o] of n)
13
- o.remaining !== null && (R() ? (o.timer && clearTimeout(o.timer), o.timer = null, o.remaining = Math.max(0, o.remaining - (Date.now() - o.startedAt))) : o.timer || (o.remaining = Math.max(o.remaining, N), v(a, o)));
14
- };
15
- typeof document < "u" && document.addEventListener("visibilitychange", w);
16
- const g = r.listen((a) => {
17
- let o;
1
+ import { C as u, c as H, b as K, s as F } from "./storage-BXB76dd8.js";
2
+ import { S as fe } from "./storage-BXB76dd8.js";
3
+ const J = [1], z = Object.freeze({ $listener: !0 }), D = "data", Q = (e) => typeof e == "object" && e !== null && e.$listener === !0, X = (e) => {
4
+ if (e === null || typeof e != "object" || Array.isArray(e)) return null;
5
+ const t = e.$ended;
6
+ return t && typeof t == "object" ? t : null;
7
+ }, Y = (e, t, a) => {
8
+ let r = null, v = null, h = null, p = null, y = !1, g = 0;
9
+ const f = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Set(), R = /* @__PURE__ */ new Set(), m = (o) => {
18
10
  try {
19
- o = JSON.parse(a);
20
- } catch {
21
- return;
11
+ o();
12
+ } catch (s) {
13
+ a(s);
22
14
  }
23
- if (!o || typeof o != "object" || typeof o.type != "string") return;
24
- const d = typeof o.refId == "string" ? n.get(o.refId) : void 0;
25
- if (d && typeof o.refId == "string") {
26
- if (n.delete(o.refId), d.timer && clearTimeout(d.timer), o.success === !0)
27
- d.resolve(o.data);
28
- else {
29
- const p = typeof o.error?.code == "string" ? o.error.code : "INTERNAL_ERROR", m = typeof o.error?.message == "string" ? o.error.message : p;
30
- d.reject(new u(p, m));
31
- }
15
+ }, A = () => {
16
+ y || (y = !0, R.forEach((o) => m(o)));
17
+ }, w = (o) => {
18
+ throw o instanceof u && o.code === "CLOUD_CHANGED" && A(), o;
19
+ }, n = (o) => {
20
+ const s = [...f.values()];
21
+ f.clear(), s.forEach((c) => m(() => c.onEnd?.(o)));
22
+ }, i = e.onPush("OnRuntimeEvent", (o) => {
23
+ const { subscriptionId: s, event: c } = o ?? {}, E = typeof s == "string" ? f.get(s) : void 0;
24
+ if (!E || typeof s != "string") return;
25
+ const b = X(c);
26
+ if (b) {
27
+ f.delete(s);
28
+ const L = typeof b.code == "string" ? b.code : "INTERNAL_ERROR", B = typeof b.message == "string" ? b.message : L;
29
+ L === "CLOUD_CHANGED" && A(), m(() => E.onEnd?.(new u(L, B)));
32
30
  return;
33
31
  }
34
- s.get(o.type)?.forEach((p) => {
35
- try {
36
- p(o.data);
37
- } catch {
32
+ m(() => E.listener(...Array.isArray(c) ? c : [c]));
33
+ }), d = e.onPush("OnRuntimeSessionChanged", (o) => {
34
+ const { seq: s, session: c } = o ?? {};
35
+ !h || typeof s != "number" || s <= h.seq || (h = { ...h, seq: s }, p = c ?? null, S.forEach((E) => m(() => E(p))));
36
+ }), l = () => {
37
+ if (!t())
38
+ return Promise.reject(
39
+ new u("NOT_SUPPORTED", "This app does not answer this page's cloud data requests.")
40
+ );
41
+ if (!r) {
42
+ const o = new Promise((c, E) => {
43
+ v = E;
44
+ }), s = Promise.race([
45
+ e.request("RuntimeHello", { contracts: [...J] }, { timeoutMs: null }),
46
+ o
47
+ ]).then((c) => (r === s && (h = c, p = c.session ?? null), c)).catch((c) => (r === s && (r = null), w(c)));
48
+ r = s;
49
+ }
50
+ return r;
51
+ }, P = async (o, s) => {
52
+ if (!(await l()).allowed[o].includes(s))
53
+ throw new u(
54
+ "RUNTIME_NOT_ALLOWED",
55
+ `${s} is not one this page may ${o === "calls" ? "call" : "subscribe to"}.`
56
+ );
57
+ }, C = async (o, ...s) => (await P("calls", o), (await e.request("RuntimeCall", { target: D, method: o, args: s }).catch(w)).value), k = async (o, s, c, E) => {
58
+ await P("streams", o);
59
+ const b = `cas-s${(++g).toString(36)}`;
60
+ f.set(b, { listener: c, onEnd: E });
61
+ try {
62
+ await e.request("RuntimeSubscribe", {
63
+ subscriptionId: b,
64
+ target: D,
65
+ topic: o,
66
+ args: s.some(Q) ? s : [...s, z]
67
+ });
68
+ } catch (L) {
69
+ f.delete(b), w(L);
70
+ }
71
+ return {
72
+ stop: async () => {
73
+ f.delete(b) && await e.request("RuntimeUnsubscribe", { subscriptionId: b }).catch(() => {
74
+ });
38
75
  }
39
- });
40
- });
76
+ };
77
+ }, q = async () => {
78
+ await l();
79
+ const o = p?.committedSiteId;
80
+ if (!o)
81
+ throw new u(
82
+ "NOT_SUPPORTED",
83
+ "A place profile needs the session permission, while the session is on a place."
84
+ );
85
+ return o;
86
+ }, _ = async () => {
87
+ await l();
88
+ const o = p?.context.identity.userId;
89
+ if (!o) throw new u("NOT_SUPPORTED", "The user's own profile needs the session permission.");
90
+ return o;
91
+ }, V = async (o) => `${await q()}@${o}`, U = async (o) => C("profile.cacheRead", await V(o)), x = async (o, s, c) => k(
92
+ "profile.observeItem",
93
+ [await V(o)],
94
+ s,
95
+ c?.onEnd
96
+ );
41
97
  return {
42
- request: (a, o = {}, d = {}) => new Promise((p, m) => {
43
- if (h) {
44
- m(new u("DISCONNECTED", "The connection to the app was closed."));
45
- return;
46
- }
47
- const l = q(), e = d.timeoutMs === void 0 ? t : d.timeoutMs, i = {
48
- resolve: p,
49
- reject: m,
50
- remaining: e,
51
- startedAt: Date.now(),
52
- timer: null
53
- };
54
- n.set(l, i), v(l, i), r.send(JSON.stringify({ type: a, data: o, refId: l, version: V }));
55
- }),
56
- onPush: (a, o) => {
57
- let d = s.get(a);
58
- return d || s.set(a, d = /* @__PURE__ */ new Set()), d.add(o), () => d?.delete(o);
98
+ connect: () => l().then(({ contract: o, allowed: s }) => ({ contract: o, allowed: s })),
99
+ can: (o) => !!h && (h.allowed.calls.includes(o) || h.allowed.streams.includes(o)),
100
+ call: C,
101
+ subscribe: k,
102
+ sendMessage: (o, s) => C("chat.sendChat", { channelId: o, content: s }),
103
+ react: (o, s, c) => C("chat.setReaction", { chatId: o, emoji: s, action: c ? "on" : "off" }),
104
+ placeProfile: U,
105
+ placeProfiles: async () => C("profile.cacheReadList", { sid: await q() }),
106
+ observePlaceProfile: x,
107
+ myProfile: async () => U(await _()),
108
+ observeMyProfile: async (o, s) => x(await _(), o, s),
109
+ session: () => p,
110
+ onSessionChange: (o) => (S.add(o), () => S.delete(o)),
111
+ onCloudChanged: (o) => (R.add(o), () => R.delete(o)),
112
+ // A page restored from the back-forward cache meets a new host: its streams are gone there.
113
+ reset: () => {
114
+ v?.(
115
+ new u("DISCONNECTED", "The page was restored before the app answered. Connect again.")
116
+ ), v = null, r = null, h = null, p = null, n(new u("DISCONNECTED", "The page was restored; its streams ended. Subscribe again."));
59
117
  },
60
- close: () => {
61
- if (!h) {
62
- h = !0, g(), typeof document < "u" && document.removeEventListener("visibilitychange", w);
63
- for (const a of n.values())
64
- a.timer && clearTimeout(a.timer), a.reject(new u("DISCONNECTED", "The connection to the app was closed."));
65
- n.clear(), s.clear();
66
- }
118
+ dispose: () => {
119
+ i(), d(), f.clear();
67
120
  }
68
121
  };
69
- }, M = () => typeof window < "u" && !!window.ReactNativeWebView, _ = () => ({
70
- send: (r) => window.ReactNativeWebView?.postMessage(r),
71
- listen: (r) => {
72
- const t = (n) => {
73
- const s = n.data;
74
- typeof s == "string" && r(s);
122
+ }, Z = () => {
123
+ const e = () => Promise.reject(new u("NOT_IN_APP", "The app's data is read only in the app."));
124
+ return {
125
+ connect: e,
126
+ can: () => !1,
127
+ call: e,
128
+ subscribe: e,
129
+ sendMessage: e,
130
+ react: e,
131
+ placeProfile: e,
132
+ placeProfiles: e,
133
+ observePlaceProfile: e,
134
+ myProfile: e,
135
+ observeMyProfile: e,
136
+ session: () => null,
137
+ onSessionChange: () => () => {
138
+ },
139
+ onCloudChanged: () => () => {
140
+ }
141
+ };
142
+ }, ee = () => typeof window < "u" && !!window.ReactNativeWebView, te = () => ({
143
+ send: (e) => window.ReactNativeWebView?.postMessage(e),
144
+ listen: (e) => {
145
+ const t = (a) => {
146
+ const r = a.data;
147
+ typeof r == "string" && e(r);
75
148
  };
76
149
  return window.addEventListener("message", t), document.addEventListener("message", t), () => {
77
150
  window.removeEventListener("message", t), document.removeEventListener("message", t);
78
151
  };
79
152
  }
80
- }), b = {
153
+ }), O = {
81
154
  finish: "FinishSubWebView",
82
155
  title: "SetSubWebViewTitle",
83
156
  haptic: "TriggerHaptic",
@@ -89,243 +162,256 @@ const q = () => `cas-${Date.now().toString(36)}-${(++W).toString(36)}`, R = () =
89
162
  closeGuard: "SetSubWebViewCloseGuard",
90
163
  errorReport: "ReportSubWebViewError",
91
164
  storage: "GetSubWebViewStorage",
92
- permissions: "RequestSubWebViewPermission"
93
- }, O = 1, D = 1e3, $ = 4e3, A = () => typeof window < "u" && window.ChaticSubWebView || null, j = () => new Promise((r) => {
165
+ permissions: "RequestSubWebViewPermission",
166
+ data: "RuntimeHello"
167
+ }, W = 1, ne = 1e3, oe = 4e3, $ = () => typeof window < "u" && window.ChaticSubWebView || null, re = () => new Promise((e) => {
94
168
  if (typeof document > "u" || document.readyState === "complete") {
95
- r(A());
169
+ e($());
96
170
  return;
97
171
  }
98
- window.addEventListener("load", () => r(A()), { once: !0 });
99
- }), G = (r) => {
100
- let t, n;
172
+ window.addEventListener("load", () => e($()), { once: !0 });
173
+ }), se = (e) => {
174
+ let t, a;
101
175
  try {
102
- r instanceof Error ? (t = r.message || r.name, n = typeof r.stack == "string" ? r.stack : void 0) : typeof r == "string" ? t = r : t = `A non-Error value was thrown: ${Object.prototype.toString.call(r)}`;
176
+ e instanceof Error ? (t = e.message || e.name, a = typeof e.stack == "string" ? e.stack : void 0) : typeof e == "string" ? t = e : t = `A non-Error value was thrown: ${Object.prototype.toString.call(e)}`;
103
177
  } catch {
104
178
  t = "An error that could not be read was thrown";
105
179
  }
106
180
  return {
107
- message: (t || "Unknown error").slice(0, D),
108
- ...n ? { stack: n.slice(0, $) } : {}
181
+ message: (t || "Unknown error").slice(0, ne),
182
+ ...a ? { stack: a.slice(0, oe) } : {}
109
183
  };
110
- }, E = (r) => new u("NOT_SUPPORTED", `${r} is not available here: an older app, or not granted.`), S = (r) => Promise.reject(new u("NOT_IN_APP", `${r} needs the app; this page is in a browser.`)), L = (r = {}) => {
111
- if (r === null || typeof r != "object" || Array.isArray(r))
184
+ }, I = (e) => new u("NOT_SUPPORTED", `${e} is not available here: an older app, or not granted.`), N = (e) => Promise.reject(new u("NOT_IN_APP", `${e} needs the app; this page is in a browser.`)), j = (e = {}) => {
185
+ if (e === null || typeof e != "object" || Array.isArray(e))
112
186
  throw new u("INVALID", "link() takes an object of query params, such as { level: 3 }.");
113
187
  const t = new URLSearchParams();
114
- for (const [s, h] of Object.entries(r)) t.append(s, String(h));
115
- const n = t.toString();
116
- return n ? `?${n}` : "";
117
- }, P = (r) => typeof location > "u" ? `/${r}` : `${location.origin}/${r}`;
118
- let y = null;
119
- const Q = (r = {}) => (y || (y = (M() ? B(_(), r) : Promise.resolve(H())).catch((t) => {
120
- throw y = null, t;
121
- })), y), B = async (r, t = {}) => {
122
- const n = U(r, t.timeoutMs);
188
+ for (const [r, v] of Object.entries(e)) t.append(r, String(v));
189
+ const a = t.toString();
190
+ return a ? `?${a}` : "";
191
+ }, G = (e) => typeof location > "u" ? `/${e}` : `${location.origin}/${e}`;
192
+ let T = null;
193
+ const ue = (e = {}) => (T || (T = (ee() ? ae(te(), e) : Promise.resolve(de())).catch((t) => {
194
+ throw T = null, t;
195
+ })), T), ae = async (e, t = {}) => {
196
+ const a = H(e, t.timeoutMs);
123
197
  try {
124
- const s = await C(n, !0);
125
- return K(n, s, t);
126
- } catch (s) {
127
- throw n.close(), s;
198
+ const r = await M(a, !0);
199
+ return ie(a, r, t);
200
+ } catch (r) {
201
+ throw a.close(), r;
128
202
  }
129
- }, C = async (r, t) => {
130
- const n = await r.request("WebAppReady", {}), s = n.subWebView ?? (t ? await j() : null);
131
- if (s && s.protocolVersion !== O)
203
+ }, M = async (e, t) => {
204
+ const a = await e.request("WebAppReady", {}), r = a.subWebView ?? (t ? await re() : null);
205
+ if (r && r.protocolVersion !== W)
132
206
  throw new u(
133
207
  "UNSUPPORTED_PROTOCOL",
134
- `The app speaks protocol ${String(s.protocolVersion)}; this library speaks ${O}.`
208
+ `The app speaks protocol ${String(r.protocolVersion)}; this library speaks ${W}.`
135
209
  );
136
210
  return {
137
- supported: new Set(Array.isArray(n.supportedWebMessages) ? n.supportedWebMessages : []),
138
- context: s
211
+ supported: new Set(Array.isArray(a.supportedWebMessages) ? a.supportedWebMessages : []),
212
+ context: r
139
213
  };
140
- }, K = (r, t, n) => {
141
- let s = null, h = null;
142
- const v = /* @__PURE__ */ new Set(), w = [], g = (e) => t.supported.has(b[e]), a = (e, i, c, f) => {
143
- const T = f ?? b[e];
144
- return t.supported.has(T) ? r.request(T, i, c === void 0 ? {} : { timeoutMs: c }) : Promise.reject(E(e));
145
- }, o = (e, i) => g("storage") ? r.request(e, i) : Promise.reject(E("storage")), d = (e) => v.forEach((i) => {
214
+ }, ie = (e, t, a) => {
215
+ let r = null, v = null;
216
+ const h = /* @__PURE__ */ new Set(), p = [], y = (n) => t.supported.has(O[n]), g = (n, i, d, l) => {
217
+ const P = l ?? O[n];
218
+ return t.supported.has(P) ? e.request(P, i, d === void 0 ? {} : { timeoutMs: d }) : Promise.reject(I(n));
219
+ }, f = Y(
220
+ e,
221
+ () => y("data"),
222
+ (n) => {
223
+ w.reportError(n);
224
+ }
225
+ );
226
+ p.push(() => f.dispose());
227
+ const S = (n, i) => y("storage") ? e.request(n, i) : Promise.reject(I("storage")), R = (n) => h.forEach((i) => {
146
228
  try {
147
- i(e);
148
- } catch (c) {
149
- l.reportError(c);
229
+ i(n);
230
+ } catch (d) {
231
+ w.reportError(d);
150
232
  }
151
- }), p = () => {
152
- g("back") && r.request(b.back, { canGoBack: !!s }).catch(() => {
153
- }), g("closeGuard") && r.request(b.closeGuard, { enabled: !!h }).catch(() => {
233
+ }), m = () => {
234
+ y("back") && e.request(O.back, { canGoBack: !!r }).catch(() => {
235
+ }), y("closeGuard") && e.request(O.closeGuard, { enabled: !!v }).catch(() => {
154
236
  });
155
- }, m = (e) => {
156
- if (!e.persisted) {
157
- p();
237
+ }, A = (n) => {
238
+ if (!n.persisted) {
239
+ m();
158
240
  return;
159
241
  }
160
- C(r, !1).then((i) => {
161
- const c = t.context;
162
- t.supported = i.supported, i.context && (t.context = i.context), p();
163
- const f = t.context;
164
- f && (f.theme !== c?.theme || f.locale !== c?.locale) && d(f);
242
+ M(e, !1).then((i) => {
243
+ const d = t.context;
244
+ t.supported = i.supported, i.context && (t.context = i.context), m(), f.reset();
245
+ const l = t.context, P = l && (l.theme !== d?.theme || l.locale !== d?.locale || JSON.stringify(l.safeArea) !== JSON.stringify(d?.safeArea));
246
+ l && P && R(l);
165
247
  }).catch(() => {
166
248
  });
167
249
  };
168
- typeof window < "u" && (window.addEventListener("pageshow", m), w.push(() => window.removeEventListener("pageshow", m))), w.push(
169
- r.onPush("OnBackPressed", () => {
250
+ typeof window < "u" && (window.addEventListener("pageshow", A), p.push(() => window.removeEventListener("pageshow", A))), p.push(
251
+ e.onPush("OnBackPressed", () => {
170
252
  try {
171
- s?.();
172
- } catch (e) {
173
- l.reportError(e);
253
+ r?.();
254
+ } catch (n) {
255
+ w.reportError(n);
174
256
  }
175
257
  })
176
- ), w.push(
177
- r.onPush("OnSubWebViewCloseRequested", (e) => {
178
- const i = h;
258
+ ), p.push(
259
+ e.onPush("OnSubWebViewCloseRequested", (n) => {
260
+ const i = v;
179
261
  if (!i) return;
180
- const c = e?.trigger ?? "control";
181
- Promise.resolve().then(() => i(c)).then((f) => f ? l.finish() : void 0).catch((f) => l.reportError(f));
262
+ const d = n?.trigger ?? "control";
263
+ Promise.resolve().then(() => i(d)).then((l) => l ? w.finish() : void 0).catch((l) => w.reportError(l));
182
264
  })
183
- ), w.push(
184
- r.onPush("OnSubWebViewContextChanged", (e) => {
185
- t.context && (t.context = { ...t.context, ...e }, d(t.context));
265
+ ), p.push(
266
+ e.onPush("OnSubWebViewContextChanged", (n) => {
267
+ t.context && (t.context = { ...t.context, ...n }, R(t.context));
186
268
  })
187
269
  );
188
- const l = {
270
+ const w = {
189
271
  inApp: !0,
190
272
  get context() {
191
273
  return t.context;
192
274
  },
193
- supports: g,
194
- finish: (e) => a("finish", e === void 0 ? {} : { result: e }).then(() => {
275
+ supports: y,
276
+ finish: (n) => g("finish", n === void 0 ? {} : { result: n }).then(() => {
195
277
  }),
196
- setTitle: (e) => a("title", { title: e }).then(() => {
278
+ setTitle: (n) => g("title", { title: n }).then(() => {
197
279
  }),
198
- haptic: (e) => {
199
- g("haptic") && r.request(b.haptic, { kind: e }).catch(() => {
280
+ haptic: (n) => {
281
+ y("haptic") && e.request(O.haptic, { kind: n }).catch(() => {
200
282
  });
201
283
  },
202
- copy: (e) => a("clipboard", { text: e }).then(() => {
284
+ copy: (n) => g("clipboard", { text: n }).then(() => {
203
285
  }),
204
- openUrl: (e) => a("openUrl", { url: e }).then(() => {
286
+ openUrl: (n) => g("openUrl", { url: n }).then(() => {
205
287
  }),
206
- share: (e) => a("share", e, null).then(
288
+ share: (n) => g("share", n, null).then(
207
289
  (i) => i?.action === "dismissedAction" ? "dismissed" : "shared"
208
290
  ),
209
- getUserKey: () => a("userKey").then((e) => e.key),
291
+ getUserKey: () => g("userKey").then((n) => n.key),
210
292
  permissions: {
211
- query: (e) => a("permissions", { kind: e }, void 0, "GetSubWebViewPermission").then(
293
+ query: (n) => g("permissions", { kind: n }, void 0, "GetSubWebViewPermission").then(
212
294
  (i) => i.state
213
295
  ),
214
296
  // Waits for the user, however long they take.
215
- request: (e) => a("permissions", { kind: e }, null).then((i) => i.state)
297
+ request: (n) => g("permissions", { kind: n }, null).then((i) => i.state)
216
298
  },
217
- openSettings: () => a("permissions", {}, void 0, "OpenSettings").then(() => {
299
+ openSettings: () => g("permissions", {}, void 0, "OpenSettings").then(() => {
218
300
  }),
219
- reportError: (e) => g("errorReport") ? r.request(b.errorReport, G(e)).then((i) => !!i?.recorded).catch(() => !1) : Promise.resolve(!1),
220
- storage: k({
221
- get: (e) => o("GetSubWebViewStorage", { keys: e }),
222
- set: (e) => o("SetSubWebViewStorage", { entries: e }),
223
- remove: (e) => o("RemoveSubWebViewStorage", { keys: e }),
224
- clear: () => o("ClearSubWebViewStorage", {}),
225
- info: () => o("GetSubWebViewStorageInfo", {})
301
+ reportError: (n) => y("errorReport") ? e.request(O.errorReport, se(n)).then((i) => !!i?.recorded).catch(() => !1) : Promise.resolve(!1),
302
+ data: f,
303
+ storage: F({
304
+ get: (n) => S("GetSubWebViewStorage", { keys: n }),
305
+ set: (n) => S("SetSubWebViewStorage", { entries: n }),
306
+ remove: (n) => S("RemoveSubWebViewStorage", { keys: n }),
307
+ clear: () => S("ClearSubWebViewStorage", {}),
308
+ info: () => S("GetSubWebViewStorageInfo", {})
226
309
  }),
227
- onBack: (e) => {
228
- s = e, p();
310
+ onBack: (n) => {
311
+ r = n, m();
229
312
  },
230
- onCloseRequest: (e) => {
231
- h = e, p();
313
+ onCloseRequest: (n) => {
314
+ v = n, m();
232
315
  },
233
- onContextChange: (e) => (v.add(e), () => v.delete(e)),
234
- link: (e) => {
235
- const i = L(e), c = t.context?.appLink;
236
- return c ? `${c}${i}` : P(i);
316
+ onContextChange: (n) => (h.add(n), () => h.delete(n)),
317
+ link: (n) => {
318
+ const i = j(n), d = t.context?.appLink;
319
+ return d ? `${d}${i}` : G(i);
237
320
  },
238
321
  disconnect: () => {
239
- w.forEach((e) => e()), r.close(), y = null;
322
+ p.forEach((n) => n()), e.close(), T = null;
240
323
  }
241
324
  };
242
- if (n.reportErrors !== !1 && typeof window < "u") {
243
- const e = (c) => {
244
- l.reportError(c.error ?? c.message);
245
- }, i = (c) => {
246
- l.reportError(c.reason);
325
+ if (a.reportErrors !== !1 && typeof window < "u") {
326
+ const n = (d) => {
327
+ w.reportError(d.error ?? d.message);
328
+ }, i = (d) => {
329
+ w.reportError(d.reason);
247
330
  };
248
- window.addEventListener("error", e), window.addEventListener("unhandledrejection", i), w.push(() => {
249
- window.removeEventListener("error", e), window.removeEventListener("unhandledrejection", i);
331
+ window.addEventListener("error", n), window.addEventListener("unhandledrejection", i), p.push(() => {
332
+ window.removeEventListener("error", n), window.removeEventListener("unhandledrejection", i);
250
333
  });
251
334
  }
252
- return l;
253
- }, F = () => {
254
- const r = async (t) => {
335
+ return w;
336
+ }, ce = () => {
337
+ const e = async (t) => {
255
338
  try {
256
- const n = await navigator.permissions.query({ name: t });
257
- return n.state === "granted" ? "granted" : n.state === "denied" ? "blocked" : "prompt";
339
+ const a = await navigator.permissions.query({ name: t });
340
+ return a.state === "granted" ? "granted" : a.state === "denied" ? "blocked" : "prompt";
258
341
  } catch {
259
342
  return "prompt";
260
343
  }
261
344
  };
262
345
  return {
263
- query: r,
346
+ query: e,
264
347
  request: async (t) => {
265
348
  if (typeof navigator > "u" || !navigator.mediaDevices?.getUserMedia)
266
349
  throw new u("NOT_SUPPORTED", `This browser cannot capture the ${t}.`);
267
350
  try {
268
351
  return (await navigator.mediaDevices.getUserMedia(
269
352
  t === "camera" ? { video: !0 } : { audio: !0 }
270
- )).getTracks().forEach((s) => s.stop()), "granted";
271
- } catch (n) {
272
- const s = n?.name;
273
- if (s === "NotFoundError" || s === "OverconstrainedError")
353
+ )).getTracks().forEach((r) => r.stop()), "granted";
354
+ } catch (a) {
355
+ const r = a?.name;
356
+ if (r === "NotFoundError" || r === "OverconstrainedError")
274
357
  throw new u("UNAVAILABLE", `This device has no ${t}.`);
275
- if (s === "NotReadableError" || s === "SecurityError" || s === "TypeError" || s === "AbortError")
276
- throw new u("INTERNAL_ERROR", `The ${t} could not be used: ${s}.`);
277
- return await r(t) === "blocked" ? "blocked" : "prompt";
358
+ if (r === "NotReadableError" || r === "SecurityError" || r === "TypeError" || r === "AbortError")
359
+ throw new u("INTERNAL_ERROR", `The ${t} could not be used: ${r}.`);
360
+ return await e(t) === "blocked" ? "blocked" : "prompt";
278
361
  }
279
362
  }
280
363
  };
281
- }, H = () => {
282
- const r = (t) => typeof navigator < "u" && navigator.clipboard ? navigator.clipboard.writeText(t) : Promise.reject(E("The clipboard"));
364
+ }, de = () => {
365
+ const e = (t) => typeof navigator < "u" && navigator.clipboard ? navigator.clipboard.writeText(t) : Promise.reject(I("The clipboard"));
283
366
  return {
284
367
  inApp: !1,
285
368
  context: null,
286
369
  supports: () => !1,
287
- finish: () => S("Finishing the view"),
370
+ finish: () => N("Finishing the view"),
288
371
  setTitle: async (t) => {
289
372
  typeof document < "u" && (document.title = t);
290
373
  },
291
374
  haptic: () => {
292
375
  typeof navigator < "u" && navigator.vibrate?.(10);
293
376
  },
294
- copy: r,
377
+ copy: e,
295
378
  openUrl: async (t) => {
296
379
  typeof window < "u" && window.open(t, "_blank", "noopener,noreferrer");
297
380
  },
298
381
  share: async (t) => {
299
- const n = [t.message, t.url].filter(Boolean).join(" ");
300
- if (!n) throw new u("INVALID", "Share a message or a url.");
382
+ const a = [t.message, t.url].filter(Boolean).join(" ");
383
+ if (!a) throw new u("INVALID", "Share a message or a url.");
301
384
  if (typeof navigator < "u" && navigator.share)
302
385
  try {
303
386
  return await navigator.share(t), "shared";
304
- } catch (s) {
305
- if (s?.name === "AbortError") return "dismissed";
387
+ } catch (r) {
388
+ if (r?.name === "AbortError") return "dismissed";
306
389
  }
307
- return await r(n), "copied";
390
+ return await e(a), "copied";
308
391
  },
309
- getUserKey: () => S("A user key"),
310
- permissions: F(),
311
- openSettings: () => S("Opening the settings"),
392
+ getUserKey: () => N("A user key"),
393
+ permissions: ce(),
394
+ data: Z(),
395
+ openSettings: () => N("Opening the settings"),
312
396
  reportError: async (t) => (console.error(t), !1),
313
- storage: I(),
397
+ storage: K(),
314
398
  onBack: () => {
315
399
  },
316
400
  onCloseRequest: () => {
317
401
  },
318
402
  onContextChange: () => () => {
319
403
  },
320
- link: (t) => P(L(t)),
404
+ link: (t) => G(j(t)),
321
405
  disconnect: () => {
322
- y = null;
406
+ T = null;
323
407
  }
324
408
  };
325
409
  };
326
410
  export {
327
411
  u as ChaticAppsError,
328
- V as SDK_BRIDGE_VERSION,
329
- Q as connect,
330
- M as isInApp
412
+ z as LISTENER,
413
+ fe as SDK_BRIDGE_VERSION,
414
+ J as SDK_DATA_CONTRACTS,
415
+ ue as connect,
416
+ ee as isInApp
331
417
  };