@lemoncloud/chatic-apps-sdk 0.1.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/mock.js CHANGED
@@ -1,5 +1,24 @@
1
- import { r as A } from "./storage-BuvWwLx2.js";
2
- const G = [
1
+ import { r as fe, S as re } from "./storage-BXB76dd8.js";
2
+ const me = 16, le = (e) => e === 8205, oe = (e) => e >= 768 && e <= 879 || e >= 6832 && e <= 6911 || e >= 7616 && e <= 7679, $ = (e) => e >= 65024 && e <= 65039 || e >= 917760 && e <= 917999, x = (e) => e >= 127995 && e <= 127999, ie = (e) => e === 8419, ae = (e) => e >= 917536 && e <= 917631, pe = 127988, P = (e) => e >= 127462 && e <= 127487, ue = (e) => e === 169 || e === 174 || e === 8252 || e === 8265 || e === 8482 || e === 8505 || e >= 8592 && e <= 8703 || e >= 8960 && e <= 9215 || e === 9410 || e >= 9632 && e <= 10175 || e >= 10496 && e <= 10623 || e >= 11008 && e <= 11263 || e === 12336 || e === 12349 || e === 12951 || e === 12953 || e >= 126976 && e <= 129791 && !x(e) && !P(e), we = (e) => e === 35 || e === 42 || e >= 48 && e <= 57, Oe = (e) => e <= 32 || e >= 127 && e <= 160 || e === 173 || e === 847 || e === 1564 || e === 4447 || e === 4448 || e === 6158 || e >= 8192 && e <= 8207 || e >= 8232 && e <= 8239 || e >= 8287 && e <= 8303 || e === 12288 || e === 12644 || e >= 55296 && e <= 57343 || e >= 57344 && e <= 63743 || e === 65279 || e === 65440 || e >= 65520 && e <= 65535 || e >= 983040, Re = (e) => {
3
+ let t = 0;
4
+ const h = () => {
5
+ if (t >= e.length || !ue(e[t])) return !1;
6
+ const f = e[t];
7
+ if (t += 1, t < e.length && $(e[t]) && (t += 1), t < e.length && x(e[t]) && (t += 1), f === pe && t < e.length && ae(e[t])) {
8
+ for (; t < e.length && ae(e[t]); ) t += 1;
9
+ return e[t - 1] === 917631;
10
+ }
11
+ return !0;
12
+ };
13
+ if (!h()) return !1;
14
+ for (; t < e.length; )
15
+ if (!le(e[t]) || (t += 1, !h())) return !1;
16
+ return !0;
17
+ }, Ee = (e) => {
18
+ if (e.length === 0 || e.length > me) return !1;
19
+ const t = Array.from(e, (f) => f.codePointAt(0) ?? 0), h = t[0];
20
+ return Oe(h) ? !1 : P(h) ? t.length === 2 && P(t[1]) : we(h) && t.length > 1 ? t.length === 2 && ie(t[1]) || t.length === 3 && $(t[1]) && ie(t[2]) : ue(h) ? Re(t) : oe(h) || $(h) || x(h) || le(h) ? !1 : t.length <= 3 && t.slice(1).every(oe);
21
+ }, Ie = [
3
22
  "WebAppReady",
4
23
  "Ping",
5
24
  "FinishSubWebView",
@@ -12,37 +31,86 @@ const G = [
12
31
  "SetSubWebViewStorage",
13
32
  "RemoveSubWebViewStorage",
14
33
  "ClearSubWebViewStorage",
15
- "GetSubWebViewStorageInfo"
16
- ], D = {
34
+ "GetSubWebViewStorageInfo",
35
+ "GetSubWebViewPermission",
36
+ "RequestSubWebViewPermission",
37
+ "OpenSettings"
38
+ ], ye = {
17
39
  clipboard: "CopyToClipboard",
18
40
  share: "OpenShareSheet",
19
41
  openUrl: "OpenURL",
20
42
  userKey: "GetSubWebViewUserKey"
21
- }, _ = ["selection", "impact", "success", "warning", "error"], x = 64 * 1024, M = 16 * 1024, U = 3e3, K = (s) => {
22
- if (/^(mailto|tel|sms|itms-apps|market):/i.test(s)) return !0;
23
- const o = /^https?:\/\/([^/?#:@]+)/i.exec(s)?.[1]?.toLowerCase();
24
- return o ? !/\.(apps|apps-dev)\.chatic\.io$/.test(o) && !/^app(-dev)?\.chatic\.io$/.test(o) : !1;
25
- }, B = (s, o) => {
26
- if (s === void 0) return !0;
43
+ }, Ve = [
44
+ "session",
45
+ "cloud",
46
+ "place",
47
+ "channel",
48
+ "chat",
49
+ "user",
50
+ "chatSend",
51
+ "chatReact"
52
+ ], Te = ["RuntimeHello", "RuntimeCall", "RuntimeSubscribe", "RuntimeUnsubscribe"], Ae = ["camera", "microphone"], Ne = ["selection", "impact", "success", "warning", "error"], We = 64 * 1024, ve = 16 * 1024, Ce = 3e3, ke = 1e3, v = "chat.sendChat", C = "chat.setReaction", _e = 200, ce = { top: 47, right: 0, bottom: 34, left: 0 }, Le = { top: 0, right: 47, bottom: 21, left: 47 }, De = { top: 0, right: 0, bottom: 0, left: 0 }, Me = 200, Ue = (e) => {
53
+ if (/^(mailto|tel|sms|itms-apps|market):/i.test(e)) return !0;
54
+ const t = /^https?:\/\/([^/?#:@]+)/i.exec(e)?.[1]?.toLowerCase();
55
+ return t ? !/\.(apps|apps-dev)\.chatic\.io$/.test(t) && !/^app(-dev)?\.chatic\.io$/.test(t) : !1;
56
+ }, Ge = (e, t) => {
57
+ if (e === void 0) return !0;
27
58
  try {
28
- const l = JSON.stringify(s);
29
- return l !== void 0 && l.length <= o;
59
+ const h = JSON.stringify(e);
60
+ return h !== void 0 && h.length <= t;
30
61
  } catch {
31
62
  return !1;
32
63
  }
33
- }, k = (s, o) => s == null || typeof s == "string" && s.length <= o, F = (s) => {
34
- let o = "";
35
- for (let l = 0; o.length < 64; l++) {
36
- let p = 2166136261 ^ l;
37
- for (let u = 0; u < s.length; u++) p = Math.imul(p ^ s.charCodeAt(u), 16777619);
38
- o += (p >>> 0).toString(16).padStart(8, "0");
64
+ }, G = (e, t) => e == null || typeof e == "string" && e.length <= t, $e = (e) => {
65
+ let t = "";
66
+ for (let h = 0; t.length < 64; h++) {
67
+ let f = 2166136261 ^ h;
68
+ for (let p = 0; p < e.length; p++) f = Math.imul(f ^ e.charCodeAt(p), 16777619);
69
+ t += (f >>> 0).toString(16).padStart(8, "0");
39
70
  }
40
- return o.slice(0, 64);
41
- }, $ = (s) => {
42
- const o = /^https:\/\/([a-z0-9-]+)\.(apps|apps-dev)\.chatic\.io$/.exec(s);
43
- return o ? `https://${o[2] === "apps" ? "app" : "app-dev"}.chatic.io/apps/${o[1]}` : s;
44
- }, H = (s = {}) => {
45
- const o = /* @__PURE__ */ new Set([...G, ...(s.permissions ?? []).map((r) => D[r])]), l = window.location.origin, p = {
71
+ return t.slice(0, 64);
72
+ }, Pe = (e) => {
73
+ const t = /^https:\/\/([a-z0-9-]+)\.(apps|apps-dev)\.chatic\.io$/.exec(e);
74
+ return t ? `https://${t[2] === "apps" ? "app" : "app-dev"}.chatic.io/apps/${t[1]}` : e;
75
+ }, je = (e = {}) => {
76
+ const t = e.permissions ?? [], h = t.some((s) => Ve.includes(s)), f = /* @__PURE__ */ new Set([
77
+ ...Ie,
78
+ ...t.flatMap((s) => ye[s] ?? []),
79
+ ...h ? Te : []
80
+ ]), p = e.data ?? {}, I = /* @__PURE__ */ new Map(), K = [];
81
+ let de = 0;
82
+ const j = t.includes("chatSend"), R = { ...p.calls }, B = R[v], F = (s, r) => {
83
+ const i = Date.now();
84
+ return {
85
+ id: `mock-chat-${r}`,
86
+ cid: "mock-cloud",
87
+ channelId: s.channelId,
88
+ chatNo: r,
89
+ isPending: !1,
90
+ isFailed: !1,
91
+ createdAtMs: i,
92
+ updatedAtMs: i,
93
+ stereo: "user",
94
+ content: s.content
95
+ };
96
+ };
97
+ j && !B && (R[v] = F), j || delete R[v];
98
+ const q = t.includes("chatReact"), H = [], J = R[C], Q = (s) => {
99
+ const r = Date.now();
100
+ return {
101
+ id: s.chatId,
102
+ cid: "mock-cloud",
103
+ channelId: "mock-room",
104
+ chatNo: 1,
105
+ isPending: !1,
106
+ isFailed: !1,
107
+ createdAtMs: r,
108
+ updatedAtMs: r
109
+ };
110
+ };
111
+ q && !J && (R[C] = Q), q || delete R[C];
112
+ let k = !1;
113
+ const N = { camera: "prompt", microphone: "prompt" }, z = window.location.origin, m = {
46
114
  protocolVersion: 1,
47
115
  viewId: "mock-view",
48
116
  platform: "ios",
@@ -50,147 +118,288 @@ const G = [
50
118
  locale: "ko",
51
119
  theme: "light",
52
120
  params: {},
53
- appLink: $(l),
54
- ...s.context
55
- }, u = s.log === !1 ? () => {
56
- } : (...r) => console.info("[chatic-apps mock]", ...r);
57
- let O = !1;
58
- const C = [];
59
- let T, b = null;
60
- const m = { theme: p.theme, locale: p.locale };
61
- let I = !1, v = !1, V = null, N = 0;
62
- const d = /* @__PURE__ */ new Map(), g = A({
63
- read: (r) => d.get(r),
64
- write: (r, n) => {
65
- d.set(r, n);
121
+ appLink: Pe(z),
122
+ display: "clean",
123
+ ...e.context
124
+ }, _ = m.display === "immersive";
125
+ let L = !0;
126
+ e.context && "safeArea" in e.context || (m.safeArea = _ ? ce : De);
127
+ for (const s of ["display", "safeArea"]) m[s] === void 0 && delete m[s];
128
+ const X = (s) => {
129
+ if (!(!s || !_ || typeof document > "u"))
130
+ for (const r of ["top", "right", "bottom", "left"])
131
+ document.documentElement.style.setProperty(`--chatic-safe-area-inset-${r}`, `${s[r]}px`);
132
+ };
133
+ X(m.safeArea);
134
+ const w = e.log === !1 ? () => {
135
+ } : (...s) => console.info("[chatic-apps mock]", ...s);
136
+ let D = !1;
137
+ const Y = [];
138
+ let Z, E = null;
139
+ const y = { theme: m.theme, locale: m.locale, safeArea: m.safeArea };
140
+ let ee = !1, te = !1, M = null, ne = 0;
141
+ const A = /* @__PURE__ */ new Map(), V = fe({
142
+ read: (s) => A.get(s),
143
+ write: (s, r) => {
144
+ A.set(s, r);
66
145
  },
67
- delete: (r) => {
68
- d.delete(r);
146
+ delete: (s) => {
147
+ A.delete(s);
69
148
  },
70
- keys: () => [...d.keys()]
149
+ keys: () => [...A.keys()]
71
150
  });
72
- if (s.storage && !g.set(s.storage).ok)
151
+ if (e.storage && !V.set(e.storage).ok)
73
152
  throw new Error("[chatic-apps mock] options.storage must be JSON entries within the storage limits.");
74
- const W = (r) => {
75
- const n = JSON.stringify(r);
76
- if (!O) {
77
- C.push(n);
153
+ const U = (s) => {
154
+ const r = JSON.stringify(s);
155
+ if (!D) {
156
+ Y.push(r);
78
157
  return;
79
158
  }
80
- setTimeout(() => window.dispatchEvent(new MessageEvent("message", { data: n })), 0);
81
- }, 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 }), E = (r) => {
82
- let n;
159
+ setTimeout(() => window.dispatchEvent(new MessageEvent("message", { data: r })), 0);
160
+ }, T = (s, r) => U({ type: s, success: !0, data: r, refId: `mock-push-${Date.now().toString(36)}` }), u = (s, r, i = {}) => U({ type: s, success: !0, data: i, refId: r }), l = (s, r, i, n, o) => U({
161
+ type: s,
162
+ success: !1,
163
+ error: o === void 0 ? { code: i, message: n } : { code: i, message: n, details: o },
164
+ refId: r
165
+ }), he = (s) => {
166
+ let r;
83
167
  try {
84
- n = JSON.parse(r);
168
+ r = JSON.parse(s);
85
169
  } catch {
86
170
  return;
87
171
  }
88
- const { type: i, refId: e } = n;
172
+ const { type: i, refId: n } = r;
89
173
  if (typeof i != "string") return;
90
- const t = n.data ?? {};
91
- if (O || (O = !0, C.splice(0).forEach(
92
- (S) => setTimeout(() => window.dispatchEvent(new MessageEvent("message", { data: S })), 0)
93
- )), u("←", i, t), b)
94
- return i === "FinishSubWebView" ? a("OnFinishSubWebView", e, "NOT_OPEN", "The view has closed.") : u("view closed; no answer to", i);
95
- if (r.length > x)
96
- return a("ERROR", e, "TOO_LARGE", "The message is over 65,536 characters.");
97
- if (!o.has(i)) return a("ERROR", e, "NOT_FOUND", `${i} is not answered for this page.`);
174
+ const o = r.data ?? {};
175
+ if (D || (D = !0, Y.splice(0).forEach(
176
+ (c) => setTimeout(() => window.dispatchEvent(new MessageEvent("message", { data: c })), 0)
177
+ )), w("←", i, o), E)
178
+ return i === "FinishSubWebView" ? l("OnFinishSubWebView", n, "NOT_OPEN", "The view has closed.") : w("view closed; no answer to", i);
179
+ if (s.length > We)
180
+ return l("ERROR", n, "TOO_LARGE", "The message is over 65,536 characters.");
181
+ if (!f.has(i)) return l("ERROR", n, "NOT_FOUND", `${i} is not answered for this page.`);
98
182
  switch (i) {
99
183
  case "WebAppReady":
100
- return c("OnWebAppReady", e, {
101
- appVersion: "2.19.0",
102
- protocolVersion: "2.19.0",
103
- supportedWebMessages: [...o],
184
+ return u("OnWebAppReady", n, {
185
+ appVersion: re,
186
+ protocolVersion: re,
187
+ supportedWebMessages: [...f],
104
188
  supportedAppMessages: [],
105
- subWebView: { ...p, ...m }
189
+ subWebView: { ...m, ...y }
106
190
  });
107
191
  case "Ping":
108
- return c("Pong", e, { payload: t.payload ?? "" });
192
+ return u("Pong", n, { payload: o.payload ?? "" });
109
193
  case "FinishSubWebView":
110
- return B(t.result, M) ? (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.");
194
+ return Ge(o.result, ve) ? (E = { by: "page", result: o.result }, e.onClose?.(E), w("view finished", o.result), u("OnFinishSubWebView", n)) : l("OnFinishSubWebView", n, "INVALID", "result must be JSON of at most 16 KiB.");
111
195
  case "SetSubWebViewTitle": {
112
- const S = typeof t.title == "string" ? t.title.trim() : "";
113
- return !S || S.length > 100 ? a("OnSetSubWebViewTitle", e, "INVALID", "title must be 1 to 100 characters.") : (T = S, c("OnSetSubWebViewTitle", e));
196
+ const c = typeof o.title == "string" ? o.title.trim() : "";
197
+ return !c || c.length > 100 ? l("OnSetSubWebViewTitle", n, "INVALID", "title must be 1 to 100 characters.") : (Z = c, u("OnSetSubWebViewTitle", n));
114
198
  }
115
199
  case "TriggerHaptic":
116
- return _.includes(t.kind) ? c("OnTriggerHaptic", e) : a("OnTriggerHaptic", e, "INVALID_KIND", `Unknown haptic kind: ${String(t.kind)}`);
200
+ return Ne.includes(o.kind) ? u("OnTriggerHaptic", n) : l("OnTriggerHaptic", n, "INVALID_KIND", `Unknown haptic kind: ${String(o.kind)}`);
117
201
  case "SetCanGoBack":
118
- return typeof t.canGoBack != "boolean" ? a("OnSetCanGoBack", e, "INVALID", "canGoBack must be a boolean.") : (I = t.canGoBack, c("OnSetCanGoBack", e));
202
+ return typeof o.canGoBack != "boolean" ? l("OnSetCanGoBack", n, "INVALID", "canGoBack must be a boolean.") : (ee = o.canGoBack, u("OnSetCanGoBack", n));
119
203
  case "SetSubWebViewCloseGuard":
120
- return typeof t.enabled != "boolean" ? a("OnSetSubWebViewCloseGuard", e, "INVALID", "enabled must be a boolean.") : (v = t.enabled, c("OnSetSubWebViewCloseGuard", e));
204
+ return typeof o.enabled != "boolean" ? l("OnSetSubWebViewCloseGuard", n, "INVALID", "enabled must be a boolean.") : (te = o.enabled, u("OnSetSubWebViewCloseGuard", n));
121
205
  case "ReportSubWebViewError":
122
- 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 }));
206
+ return typeof o.message != "string" || !o.message.trim() ? l("OnReportSubWebViewError", n, "INVALID", "message must be a non-empty string.") : ne >= 20 ? u("OnReportSubWebViewError", n, { recorded: !1 }) : (ne += 1, console.warn("[chatic-apps mock] page error", o.message, o.stack ?? ""), u("OnReportSubWebViewError", n, { recorded: !0 }));
123
207
  case "CopyToClipboard":
124
- return typeof t.text != "string" ? a("OnCopyToClipboard", e, "INVALID", "text must be a string.") : (navigator.clipboard?.writeText(t.text).catch(() => {
125
- }), c("OnCopyToClipboard", e, { copied: !0 }));
208
+ return typeof o.text != "string" ? l("OnCopyToClipboard", n, "INVALID", "text must be a string.") : (navigator.clipboard?.writeText(o.text).catch(() => {
209
+ }), u("OnCopyToClipboard", n, { copied: !0 }));
126
210
  case "OpenURL":
127
- return typeof t.url != "string" || !K(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));
211
+ return typeof o.url != "string" || !Ue(o.url) ? l("OnOpenURL", n, "LINK_NOT_ALLOWED", "This link cannot be opened from a page.") : (window.open(o.url, "_blank", "noopener,noreferrer"), u("OnOpenURL", n));
128
212
  case "OpenShareSheet": {
129
- const { title: S, message: h, url: w } = t, L = !(typeof h == "string" && h.trim()) && w == null;
130
- 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(
213
+ const { title: c, message: a, url: d } = o, b = !(typeof a == "string" && a.trim()) && d == null;
214
+ return !G(c, 100) || !G(a, 4e3) || !G(d, 2048) || d === "" || b ? l("OnOpenShareSheet", n, "INVALID", "Share a message or a url within their limits.") : typeof d == "string" && !/^https?:\/\//i.test(d) ? l(
131
215
  "OnOpenShareSheet",
132
- e,
216
+ n,
133
217
  "LINK_NOT_ALLOWED",
134
218
  "Only an http or https url can be shared."
135
- ) : (u("share sheet", t), c("OnOpenShareSheet", e, { action: "sharedAction", activityType: null }));
219
+ ) : (w("share sheet", o), u("OnOpenShareSheet", n, { action: "sharedAction", activityType: null }));
136
220
  }
137
221
  case "GetSubWebViewStorage":
138
222
  case "SetSubWebViewStorage":
139
223
  case "RemoveSubWebViewStorage":
140
224
  case "ClearSubWebViewStorage":
141
225
  case "GetSubWebViewStorageInfo": {
142
- const h = {
143
- GetSubWebViewStorage: () => g.get(t.keys),
144
- SetSubWebViewStorage: () => g.set(t.entries),
145
- RemoveSubWebViewStorage: () => g.remove(t.keys),
146
- ClearSubWebViewStorage: () => g.clear(),
147
- GetSubWebViewStorageInfo: () => g.info()
226
+ const a = {
227
+ GetSubWebViewStorage: () => V.get(o.keys),
228
+ SetSubWebViewStorage: () => V.set(o.entries),
229
+ RemoveSubWebViewStorage: () => V.remove(o.keys),
230
+ ClearSubWebViewStorage: () => V.clear(),
231
+ GetSubWebViewStorageInfo: () => V.info()
148
232
  }[i]();
149
- return h.ok ? c(`On${i}`, e, h.value) : a(
233
+ return a.ok ? u(`On${i}`, n, a.value) : l(
150
234
  `On${i}`,
151
- e,
152
- h.code,
153
- 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."
235
+ n,
236
+ a.code,
237
+ a.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."
154
238
  );
155
239
  }
240
+ case "GetSubWebViewPermission":
241
+ case "RequestSubWebViewPermission": {
242
+ const c = o.kind;
243
+ if (!Ae.includes(c))
244
+ return l(`On${i}`, n, "INVALID", "kind must be camera or microphone.");
245
+ if (e.deviceAnswers?.[c] === "unavailable")
246
+ return l(`On${i}`, n, "UNAVAILABLE", "This device has no such hardware.");
247
+ if (i === "RequestSubWebViewPermission" && N[c] === "prompt") {
248
+ const a = e.deviceAnswers?.[c] ?? "allow";
249
+ N[c] = a === "allow" ? "granted" : a === "deny" ? "prompt" : "blocked", w("the user answered", c, a);
250
+ }
251
+ return u(`On${i}`, n, { state: N[c] });
252
+ }
253
+ case "OpenSettings":
254
+ return w("settings opened"), u("OnOpenSettings", n);
156
255
  case "GetSubWebViewUserKey":
157
- return c("OnGetSubWebViewUserKey", e, { key: s.userKey ?? F(l) });
256
+ return u("OnGetSubWebViewUserKey", n, { key: e.userKey ?? $e(z) });
257
+ case "RuntimeHello":
258
+ case "RuntimeCall":
259
+ case "RuntimeSubscribe":
260
+ case "RuntimeUnsubscribe":
261
+ return be(i, n, o);
158
262
  default:
159
- return a("ERROR", e, "NOT_FOUND", `${i} is not answered for this page.`);
263
+ return l("ERROR", n, "NOT_FOUND", `${i} is not answered for this page.`);
160
264
  }
161
- }, f = window;
162
- f.ReactNativeWebView = { postMessage: E }, f.ChaticSubWebView = p;
163
- const R = {
265
+ };
266
+ function be(s, r, i) {
267
+ const n = `On${s}`;
268
+ if (k && s !== "RuntimeUnsubscribe")
269
+ return l(n, r, "CLOUD_CHANGED", "The cloud this view opened on is no longer the selected one.");
270
+ const o = String(s === "RuntimeSubscribe" ? i.topic : i.method), c = (Array.isArray(i.args) ? i.args : []).filter(
271
+ (a) => !(typeof a == "object" && a !== null && a.$listener === !0)
272
+ );
273
+ switch (s) {
274
+ case "RuntimeHello":
275
+ return p.consent === "refuse" ? l(
276
+ n,
277
+ r,
278
+ "CONSENT_REFUSED",
279
+ "The user did not allow this page to read this cloud."
280
+ ) : u(n, r, {
281
+ sessionOwner: "native",
282
+ contract: 1,
283
+ seq: 0,
284
+ session: t.includes("session") ? p.session ?? null : null,
285
+ allowed: { calls: Object.keys(R), streams: Object.keys(p.streams ?? {}) }
286
+ });
287
+ case "RuntimeCall": {
288
+ const a = R[o];
289
+ if (i.target !== "data" || !a)
290
+ return l(n, r, "RUNTIME_NOT_ALLOWED", `${o} is not open to this page.`);
291
+ if (o === C) return ge(n, r, o, a, c);
292
+ if (o !== v)
293
+ return void Promise.resolve().then(() => a(...c)).then(
294
+ (g) => u(n, r, { value: g ?? null }),
295
+ (g) => l(n, r, "RUNTIME_ERROR", String(g?.message ?? g))
296
+ );
297
+ const d = c[0], b = d?.channelId, O = d?.content;
298
+ if (!(c.length === 1 && typeof d == "object" && d !== null && Object.keys(d).every((g) => g === "channelId" || g === "content") && typeof b == "string" && b.trim() !== "" && b.length <= Me && typeof O == "string" && O.trim() !== "" && O.length <= ke))
299
+ return l(n, r, "RUNTIME_NOT_ALLOWED", "Only plain text, up to 1000 characters.", {
300
+ target: "data",
301
+ method: o,
302
+ reason: "guard"
303
+ });
304
+ const Se = ++de;
305
+ return void Promise.resolve().then(() => B ? a(...c) : F({ channelId: b, content: O }, Se)).then(
306
+ (g) => {
307
+ K.push({ channelId: b, text: O }), w("message sent", b, O), u(n, r, { value: g ?? null });
308
+ },
309
+ (g) => l(n, r, "RUNTIME_ERROR", String(g?.message ?? g))
310
+ );
311
+ }
312
+ case "RuntimeSubscribe": {
313
+ const a = p.streams?.[o], d = String(i.subscriptionId);
314
+ if (i.target !== "data" || !a)
315
+ return l(n, r, "RUNTIME_NOT_ALLOWED", `${o} is not open to this page.`);
316
+ I.get(d)?.stop();
317
+ const b = { seq: 0, stop: () => {
318
+ } };
319
+ I.set(d, b);
320
+ const O = (...S) => {
321
+ I.get(d) === b && (b.seq += 1, T("OnRuntimeEvent", { subscriptionId: d, seq: b.seq, event: S }));
322
+ };
323
+ return b.stop = a(O, ...c) ?? (() => {
324
+ }), u(n, r);
325
+ }
326
+ default: {
327
+ const a = String(i.subscriptionId);
328
+ return I.get(a)?.stop(), I.delete(a), u(n, r);
329
+ }
330
+ }
331
+ }
332
+ function ge(s, r, i, n, o) {
333
+ const c = o[0], a = c?.chatId, d = c?.emoji, b = c?.action;
334
+ if (!(o.length === 1 && typeof c == "object" && c !== null && Object.keys(c).every((S) => S === "chatId" || S === "emoji" || S === "action") && typeof a == "string" && a.trim() !== "" && a.length <= _e && typeof d == "string" && Ee(d) && (b === "on" || b === "off")))
335
+ return l(s, r, "RUNTIME_NOT_ALLOWED", "One emoji, on or off, on one message.", {
336
+ target: "data",
337
+ method: i,
338
+ reason: "guard"
339
+ });
340
+ Promise.resolve().then(() => J ? n(...o) : Q({ chatId: a })).then(
341
+ (S) => {
342
+ H.push({ messageId: a, emoji: d, on: b === "on" }), w("reaction", b, a, d), u(s, r, { value: S ?? null });
343
+ },
344
+ (S) => l(s, r, "RUNTIME_ERROR", String(S?.message ?? S))
345
+ );
346
+ }
347
+ const W = window;
348
+ W.ReactNativeWebView = { postMessage: he }, W.ChaticSubWebView = m;
349
+ const se = {
164
350
  get title() {
165
- return T;
351
+ return Z;
166
352
  },
167
353
  get closed() {
168
- return b;
354
+ return E;
169
355
  },
170
356
  get storage() {
171
- return Object.fromEntries([...d].map(([r, n]) => [r, JSON.parse(n)]));
357
+ return Object.fromEntries([...A].map(([s, r]) => [s, JSON.parse(r)]));
358
+ },
359
+ get devices() {
360
+ return { ...N };
361
+ },
362
+ get sentMessages() {
363
+ return [...K];
364
+ },
365
+ get reactions() {
366
+ return [...H];
172
367
  },
173
368
  pressBack: () => {
174
- b || (I ? y("OnBackPressed", {}) : history.length > 1 ? history.back() : R.requestClose("back"));
369
+ E || (ee ? T("OnBackPressed", {}) : history.length > 1 ? history.back() : se.requestClose("back"));
175
370
  },
176
- requestClose: (r = "control") => {
177
- if (b) return;
178
- const n = Date.now();
179
- if (v && (V === null || n - V > U)) {
180
- V = n, y("OnSubWebViewCloseRequested", { trigger: r });
371
+ requestClose: (s = "control") => {
372
+ if (E) return;
373
+ const r = Date.now();
374
+ if (te && (M === null || r - M > Ce)) {
375
+ M = r, T("OnSubWebViewCloseRequested", { trigger: s });
181
376
  return;
182
377
  }
183
- b = { by: "user" }, s.onClose?.(b), u("view closed by the user");
378
+ E = { by: "user" }, e.onClose?.(E), w("view closed by the user");
379
+ },
380
+ changeContext: (s) => {
381
+ Object.assign(y, s), T("OnSubWebViewContextChanged", { ...y });
184
382
  },
185
- changeContext: (r) => {
186
- Object.assign(m, r), y("OnSubWebViewContextChanged", { ...m });
383
+ // The phone's own insets, upright and turned, whatever `context.safeArea` started with; pushed at
384
+ // once, where the app waits for the insets to hold still for 200 ms.
385
+ rotate: () => {
386
+ L = !L, !(!_ || !y.safeArea) && (y.safeArea = L ? ce : Le, X(y.safeArea), T("OnSubWebViewContextChanged", { ...y }));
387
+ },
388
+ changeCloud: () => {
389
+ k || (k = !0, I.forEach((s, r) => {
390
+ s.stop(), T("OnRuntimeEvent", {
391
+ subscriptionId: r,
392
+ seq: s.seq + 1,
393
+ event: { $ended: { code: "CLOUD_CHANGED", message: "The cloud changed." } }
394
+ });
395
+ }), I.clear());
187
396
  },
188
397
  uninstall: () => {
189
- delete f.ReactNativeWebView, delete f.ChaticSubWebView;
398
+ delete W.ReactNativeWebView, delete W.ChaticSubWebView;
190
399
  }
191
400
  };
192
- return R;
401
+ return se;
193
402
  };
194
403
  export {
195
- H as installChaticAppsMock
404
+ je as installChaticAppsMock
196
405
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemoncloud/chatic-apps-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Build pages that run inside the DoU app",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -38,7 +38,20 @@
38
38
  },
39
39
  "unpkg": "./chatic-apps-sdk.global.js",
40
40
  "jsdelivr": "./chatic-apps-sdk.global.js",
41
- "files": ["*.js", "*.cjs", "*.d.ts", "*.d.cts", "README.md"],
41
+ "files": [
42
+ "*.js",
43
+ "*.cjs",
44
+ "*.d.ts",
45
+ "*.d.cts",
46
+ "README.md",
47
+ "README.ko.md",
48
+ "GUIDE.md",
49
+ "GUIDE.ko.md",
50
+ "AGENTS.md",
51
+ "AGENTS.ko.md",
52
+ "skill/SKILL.md",
53
+ "skill/SKILL.ko.md"
54
+ ],
42
55
  "publishConfig": {
43
56
  "access": "public"
44
57
  },