@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/mock.js CHANGED
@@ -1,5 +1,24 @@
1
- import { r as G } from "./storage-BuvWwLx2.js";
2
- const D = [
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",
@@ -16,36 +35,82 @@ const D = [
16
35
  "GetSubWebViewPermission",
17
36
  "RequestSubWebViewPermission",
18
37
  "OpenSettings"
19
- ], _ = {
38
+ ], ye = {
20
39
  clipboard: "CopyToClipboard",
21
40
  share: "OpenShareSheet",
22
41
  openUrl: "OpenURL",
23
42
  userKey: "GetSubWebViewUserKey"
24
- }, U = ["camera", "microphone"], $ = ["selection", "impact", "success", "warning", "error"], x = 64 * 1024, K = 16 * 1024, M = 3e3, B = (r) => {
25
- if (/^(mailto|tel|sms|itms-apps|market):/i.test(r)) return !0;
26
- const a = /^https?:\/\/([^/?#:@]+)/i.exec(r)?.[1]?.toLowerCase();
27
- return a ? !/\.(apps|apps-dev)\.chatic\.io$/.test(a) && !/^app(-dev)?\.chatic\.io$/.test(a) : !1;
28
- }, F = (r, a) => {
29
- if (r === 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;
30
58
  try {
31
- const p = JSON.stringify(r);
32
- return p !== void 0 && p.length <= a;
59
+ const h = JSON.stringify(e);
60
+ return h !== void 0 && h.length <= t;
33
61
  } catch {
34
62
  return !1;
35
63
  }
36
- }, v = (r, a) => r == null || typeof r == "string" && r.length <= a, P = (r) => {
37
- let a = "";
38
- for (let p = 0; a.length < 64; p++) {
39
- let h = 2166136261 ^ p;
40
- for (let b = 0; b < r.length; b++) h = Math.imul(h ^ r.charCodeAt(b), 16777619);
41
- a += (h >>> 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");
42
70
  }
43
- return a.slice(0, 64);
44
- }, J = (r) => {
45
- const a = /^https:\/\/([a-z0-9-]+)\.(apps|apps-dev)\.chatic\.io$/.exec(r);
46
- return a ? `https://${a[2] === "apps" ? "app" : "app-dev"}.chatic.io/apps/${a[1]}` : r;
47
- }, j = (r = {}) => {
48
- const a = /* @__PURE__ */ new Set([...D, ...(r.permissions ?? []).map((s) => _[s])]), p = { camera: "prompt", microphone: "prompt" }, h = window.location.origin, b = {
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 = {
49
114
  protocolVersion: 1,
50
115
  viewId: "mock-view",
51
116
  platform: "ios",
@@ -53,165 +118,288 @@ const D = [
53
118
  locale: "ko",
54
119
  theme: "light",
55
120
  params: {},
56
- appLink: J(h),
57
- ...r.context
58
- }, d = r.log === !1 ? () => {
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 ? () => {
59
135
  } : (...s) => console.info("[chatic-apps mock]", ...s);
60
- let O = !1;
61
- const C = [];
62
- let I, S = null;
63
- const V = { theme: b.theme, locale: b.locale };
64
- let N = !1, R = !1, W = null, T = 0;
65
- const w = /* @__PURE__ */ new Map(), g = G({
66
- read: (s) => w.get(s),
67
- write: (s, n) => {
68
- w.set(s, n);
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);
69
145
  },
70
146
  delete: (s) => {
71
- w.delete(s);
147
+ A.delete(s);
72
148
  },
73
- keys: () => [...w.keys()]
149
+ keys: () => [...A.keys()]
74
150
  });
75
- if (r.storage && !g.set(r.storage).ok)
151
+ if (e.storage && !V.set(e.storage).ok)
76
152
  throw new Error("[chatic-apps mock] options.storage must be JSON entries within the storage limits.");
77
- const k = (s) => {
78
- const n = JSON.stringify(s);
79
- if (!O) {
80
- C.push(n);
153
+ const U = (s) => {
154
+ const r = JSON.stringify(s);
155
+ if (!D) {
156
+ Y.push(r);
81
157
  return;
82
158
  }
83
- setTimeout(() => window.dispatchEvent(new MessageEvent("message", { data: n })), 0);
84
- }, y = (s, n) => k({ type: s, success: !0, data: n, refId: `mock-push-${Date.now().toString(36)}` }), c = (s, n, o = {}) => k({ type: s, success: !0, data: o, refId: n }), i = (s, n, o, e) => k({ type: s, success: !1, error: { code: o, message: e }, refId: n }), A = (s) => {
85
- 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;
86
167
  try {
87
- n = JSON.parse(s);
168
+ r = JSON.parse(s);
88
169
  } catch {
89
170
  return;
90
171
  }
91
- const { type: o, refId: e } = n;
92
- if (typeof o != "string") return;
93
- const t = n.data ?? {};
94
- if (O || (O = !0, C.splice(0).forEach(
95
- (u) => setTimeout(() => window.dispatchEvent(new MessageEvent("message", { data: u })), 0)
96
- )), d("←", o, t), S)
97
- return o === "FinishSubWebView" ? i("OnFinishSubWebView", e, "NOT_OPEN", "The view has closed.") : d("view closed; no answer to", o);
98
- if (s.length > x)
99
- return i("ERROR", e, "TOO_LARGE", "The message is over 65,536 characters.");
100
- if (!a.has(o)) return i("ERROR", e, "NOT_FOUND", `${o} is not answered for this page.`);
101
- switch (o) {
172
+ const { type: i, refId: n } = r;
173
+ if (typeof i != "string") return;
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.`);
182
+ switch (i) {
102
183
  case "WebAppReady":
103
- return c("OnWebAppReady", e, {
104
- appVersion: "2.20.0",
105
- protocolVersion: "2.20.0",
106
- supportedWebMessages: [...a],
184
+ return u("OnWebAppReady", n, {
185
+ appVersion: re,
186
+ protocolVersion: re,
187
+ supportedWebMessages: [...f],
107
188
  supportedAppMessages: [],
108
- subWebView: { ...b, ...V }
189
+ subWebView: { ...m, ...y }
109
190
  });
110
191
  case "Ping":
111
- return c("Pong", e, { payload: t.payload ?? "" });
192
+ return u("Pong", n, { payload: o.payload ?? "" });
112
193
  case "FinishSubWebView":
113
- return F(t.result, K) ? (S = { by: "page", result: t.result }, r.onClose?.(S), d("view finished", t.result), c("OnFinishSubWebView", e)) : i("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.");
114
195
  case "SetSubWebViewTitle": {
115
- const u = typeof t.title == "string" ? t.title.trim() : "";
116
- return !u || u.length > 100 ? i("OnSetSubWebViewTitle", e, "INVALID", "title must be 1 to 100 characters.") : (I = u, 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));
117
198
  }
118
199
  case "TriggerHaptic":
119
- return $.includes(t.kind) ? c("OnTriggerHaptic", e) : i("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)}`);
120
201
  case "SetCanGoBack":
121
- return typeof t.canGoBack != "boolean" ? i("OnSetCanGoBack", e, "INVALID", "canGoBack must be a boolean.") : (N = 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));
122
203
  case "SetSubWebViewCloseGuard":
123
- return typeof t.enabled != "boolean" ? i("OnSetSubWebViewCloseGuard", e, "INVALID", "enabled must be a boolean.") : (R = 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));
124
205
  case "ReportSubWebViewError":
125
- return typeof t.message != "string" || !t.message.trim() ? i("OnReportSubWebViewError", e, "INVALID", "message must be a non-empty string.") : T >= 20 ? c("OnReportSubWebViewError", e, { recorded: !1 }) : (T += 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 }));
126
207
  case "CopyToClipboard":
127
- return typeof t.text != "string" ? i("OnCopyToClipboard", e, "INVALID", "text must be a string.") : (navigator.clipboard?.writeText(t.text).catch(() => {
128
- }), 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 }));
129
210
  case "OpenURL":
130
- return typeof t.url != "string" || !B(t.url) ? i("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));
131
212
  case "OpenShareSheet": {
132
- const { title: u, message: l, url: m } = t, L = !(typeof l == "string" && l.trim()) && m == null;
133
- return !v(u, 100) || !v(l, 4e3) || !v(m, 2048) || m === "" || L ? i("OnOpenShareSheet", e, "INVALID", "Share a message or a url within their limits.") : typeof m == "string" && !/^https?:\/\//i.test(m) ? i(
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(
134
215
  "OnOpenShareSheet",
135
- e,
216
+ n,
136
217
  "LINK_NOT_ALLOWED",
137
218
  "Only an http or https url can be shared."
138
- ) : (d("share sheet", t), c("OnOpenShareSheet", e, { action: "sharedAction", activityType: null }));
219
+ ) : (w("share sheet", o), u("OnOpenShareSheet", n, { action: "sharedAction", activityType: null }));
139
220
  }
140
221
  case "GetSubWebViewStorage":
141
222
  case "SetSubWebViewStorage":
142
223
  case "RemoveSubWebViewStorage":
143
224
  case "ClearSubWebViewStorage":
144
225
  case "GetSubWebViewStorageInfo": {
145
- const l = {
146
- GetSubWebViewStorage: () => g.get(t.keys),
147
- SetSubWebViewStorage: () => g.set(t.entries),
148
- RemoveSubWebViewStorage: () => g.remove(t.keys),
149
- ClearSubWebViewStorage: () => g.clear(),
150
- GetSubWebViewStorageInfo: () => g.info()
151
- }[o]();
152
- return l.ok ? c(`On${o}`, e, l.value) : i(
153
- `On${o}`,
154
- e,
155
- l.code,
156
- l.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."
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()
232
+ }[i]();
233
+ return a.ok ? u(`On${i}`, n, a.value) : l(
234
+ `On${i}`,
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."
157
238
  );
158
239
  }
159
240
  case "GetSubWebViewPermission":
160
241
  case "RequestSubWebViewPermission": {
161
- const u = t.kind;
162
- if (!U.includes(u))
163
- return i(`On${o}`, e, "INVALID", "kind must be camera or microphone.");
164
- if (r.deviceAnswers?.[u] === "unavailable")
165
- return i(`On${o}`, e, "UNAVAILABLE", "This device has no such hardware.");
166
- if (o === "RequestSubWebViewPermission" && p[u] === "prompt") {
167
- const l = r.deviceAnswers?.[u] ?? "allow";
168
- p[u] = l === "allow" ? "granted" : l === "deny" ? "prompt" : "blocked", d("the user answered", u, l);
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);
169
250
  }
170
- return c(`On${o}`, e, { state: p[u] });
251
+ return u(`On${i}`, n, { state: N[c] });
171
252
  }
172
253
  case "OpenSettings":
173
- return d("settings opened"), c("OnOpenSettings", e);
254
+ return w("settings opened"), u("OnOpenSettings", n);
174
255
  case "GetSubWebViewUserKey":
175
- return c("OnGetSubWebViewUserKey", e, { key: r.userKey ?? P(h) });
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);
176
262
  default:
177
- return i("ERROR", e, "NOT_FOUND", `${o} is not answered for this page.`);
263
+ return l("ERROR", n, "NOT_FOUND", `${i} is not answered for this page.`);
178
264
  }
179
- }, f = window;
180
- f.ReactNativeWebView = { postMessage: A }, f.ChaticSubWebView = b;
181
- const E = {
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 = {
182
350
  get title() {
183
- return I;
351
+ return Z;
184
352
  },
185
353
  get closed() {
186
- return S;
354
+ return E;
187
355
  },
188
356
  get storage() {
189
- return Object.fromEntries([...w].map(([s, n]) => [s, JSON.parse(n)]));
357
+ return Object.fromEntries([...A].map(([s, r]) => [s, JSON.parse(r)]));
190
358
  },
191
359
  get devices() {
192
- return { ...p };
360
+ return { ...N };
361
+ },
362
+ get sentMessages() {
363
+ return [...K];
364
+ },
365
+ get reactions() {
366
+ return [...H];
193
367
  },
194
368
  pressBack: () => {
195
- S || (N ? y("OnBackPressed", {}) : history.length > 1 ? history.back() : E.requestClose("back"));
369
+ E || (ee ? T("OnBackPressed", {}) : history.length > 1 ? history.back() : se.requestClose("back"));
196
370
  },
197
371
  requestClose: (s = "control") => {
198
- if (S) return;
199
- const n = Date.now();
200
- if (R && (W === null || n - W > M)) {
201
- W = n, y("OnSubWebViewCloseRequested", { trigger: s });
372
+ if (E) return;
373
+ const r = Date.now();
374
+ if (te && (M === null || r - M > Ce)) {
375
+ M = r, T("OnSubWebViewCloseRequested", { trigger: s });
202
376
  return;
203
377
  }
204
- S = { by: "user" }, r.onClose?.(S), d("view closed by the user");
378
+ E = { by: "user" }, e.onClose?.(E), w("view closed by the user");
205
379
  },
206
380
  changeContext: (s) => {
207
- Object.assign(V, s), y("OnSubWebViewContextChanged", { ...V });
381
+ Object.assign(y, s), T("OnSubWebViewContextChanged", { ...y });
382
+ },
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());
208
396
  },
209
397
  uninstall: () => {
210
- delete f.ReactNativeWebView, delete f.ChaticSubWebView;
398
+ delete W.ReactNativeWebView, delete W.ChaticSubWebView;
211
399
  }
212
400
  };
213
- return E;
401
+ return se;
214
402
  };
215
403
  export {
216
- j as installChaticAppsMock
404
+ je as installChaticAppsMock
217
405
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemoncloud/chatic-apps-sdk",
3
- "version": "0.2.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", "GUIDE.md", "AGENTS.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
  },