@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/AGENTS.ko.md +82 -0
- package/AGENTS.md +34 -7
- package/GUIDE.ko.md +419 -0
- package/GUIDE.md +218 -6
- package/README.ko.md +582 -0
- package/README.md +364 -46
- package/chatic-apps-sdk.global.js +1 -1
- package/index.cjs +1 -1
- package/index.d.cts +1295 -6
- package/index.d.ts +1295 -6
- package/index.js +282 -196
- package/mock.cjs +1 -1
- package/mock.d.cts +1203 -3
- package/mock.d.ts +1203 -3
- package/mock.js +306 -118
- package/package.json +15 -2
- package/skill/SKILL.ko.md +263 -0
- package/skill/SKILL.md +275 -0
- package/storage-BXB76dd8.js +175 -0
- package/storage-C42PwRjA.cjs +1 -0
- package/storage-BuvWwLx2.js +0 -104
- package/storage-yeS4HWKZ.cjs +0 -1
package/mock.js
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import { r as
|
|
2
|
-
const
|
|
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
|
-
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
32
|
-
return
|
|
59
|
+
const h = JSON.stringify(e);
|
|
60
|
+
return h !== void 0 && h.length <= t;
|
|
33
61
|
} catch {
|
|
34
62
|
return !1;
|
|
35
63
|
}
|
|
36
|
-
},
|
|
37
|
-
let
|
|
38
|
-
for (let
|
|
39
|
-
let
|
|
40
|
-
for (let
|
|
41
|
-
|
|
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
|
|
44
|
-
},
|
|
45
|
-
const
|
|
46
|
-
return
|
|
47
|
-
},
|
|
48
|
-
const
|
|
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:
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
61
|
-
const
|
|
62
|
-
let
|
|
63
|
-
const
|
|
64
|
-
let
|
|
65
|
-
const
|
|
66
|
-
read: (s) =>
|
|
67
|
-
write: (s,
|
|
68
|
-
|
|
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
|
-
|
|
147
|
+
A.delete(s);
|
|
72
148
|
},
|
|
73
|
-
keys: () => [...
|
|
149
|
+
keys: () => [...A.keys()]
|
|
74
150
|
});
|
|
75
|
-
if (
|
|
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
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
80
|
-
|
|
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:
|
|
84
|
-
},
|
|
85
|
-
|
|
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
|
-
|
|
168
|
+
r = JSON.parse(s);
|
|
88
169
|
} catch {
|
|
89
170
|
return;
|
|
90
171
|
}
|
|
91
|
-
const { type:
|
|
92
|
-
if (typeof
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
(
|
|
96
|
-
)),
|
|
97
|
-
return
|
|
98
|
-
if (s.length >
|
|
99
|
-
return
|
|
100
|
-
if (!
|
|
101
|
-
switch (
|
|
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
|
|
104
|
-
appVersion:
|
|
105
|
-
protocolVersion:
|
|
106
|
-
supportedWebMessages: [...
|
|
184
|
+
return u("OnWebAppReady", n, {
|
|
185
|
+
appVersion: re,
|
|
186
|
+
protocolVersion: re,
|
|
187
|
+
supportedWebMessages: [...f],
|
|
107
188
|
supportedAppMessages: [],
|
|
108
|
-
subWebView: { ...
|
|
189
|
+
subWebView: { ...m, ...y }
|
|
109
190
|
});
|
|
110
191
|
case "Ping":
|
|
111
|
-
return
|
|
192
|
+
return u("Pong", n, { payload: o.payload ?? "" });
|
|
112
193
|
case "FinishSubWebView":
|
|
113
|
-
return
|
|
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
|
|
116
|
-
return !
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
128
|
-
}),
|
|
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
|
|
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:
|
|
133
|
-
return !
|
|
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
|
-
|
|
216
|
+
n,
|
|
136
217
|
"LINK_NOT_ALLOWED",
|
|
137
218
|
"Only an http or https url can be shared."
|
|
138
|
-
) : (
|
|
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
|
|
146
|
-
GetSubWebViewStorage: () =>
|
|
147
|
-
SetSubWebViewStorage: () =>
|
|
148
|
-
RemoveSubWebViewStorage: () =>
|
|
149
|
-
ClearSubWebViewStorage: () =>
|
|
150
|
-
GetSubWebViewStorageInfo: () =>
|
|
151
|
-
}[
|
|
152
|
-
return
|
|
153
|
-
`On${
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
|
162
|
-
if (!
|
|
163
|
-
return
|
|
164
|
-
if (
|
|
165
|
-
return
|
|
166
|
-
if (
|
|
167
|
-
const
|
|
168
|
-
|
|
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
|
|
251
|
+
return u(`On${i}`, n, { state: N[c] });
|
|
171
252
|
}
|
|
172
253
|
case "OpenSettings":
|
|
173
|
-
return
|
|
254
|
+
return w("settings opened"), u("OnOpenSettings", n);
|
|
174
255
|
case "GetSubWebViewUserKey":
|
|
175
|
-
return
|
|
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
|
|
263
|
+
return l("ERROR", n, "NOT_FOUND", `${i} is not answered for this page.`);
|
|
178
264
|
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
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
|
|
351
|
+
return Z;
|
|
184
352
|
},
|
|
185
353
|
get closed() {
|
|
186
|
-
return
|
|
354
|
+
return E;
|
|
187
355
|
},
|
|
188
356
|
get storage() {
|
|
189
|
-
return Object.fromEntries([...
|
|
357
|
+
return Object.fromEntries([...A].map(([s, r]) => [s, JSON.parse(r)]));
|
|
190
358
|
},
|
|
191
359
|
get devices() {
|
|
192
|
-
return { ...
|
|
360
|
+
return { ...N };
|
|
361
|
+
},
|
|
362
|
+
get sentMessages() {
|
|
363
|
+
return [...K];
|
|
364
|
+
},
|
|
365
|
+
get reactions() {
|
|
366
|
+
return [...H];
|
|
193
367
|
},
|
|
194
368
|
pressBack: () => {
|
|
195
|
-
|
|
369
|
+
E || (ee ? T("OnBackPressed", {}) : history.length > 1 ? history.back() : se.requestClose("back"));
|
|
196
370
|
},
|
|
197
371
|
requestClose: (s = "control") => {
|
|
198
|
-
if (
|
|
199
|
-
const
|
|
200
|
-
if (
|
|
201
|
-
|
|
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
|
-
|
|
378
|
+
E = { by: "user" }, e.onClose?.(E), w("view closed by the user");
|
|
205
379
|
},
|
|
206
380
|
changeContext: (s) => {
|
|
207
|
-
Object.assign(
|
|
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
|
|
398
|
+
delete W.ReactNativeWebView, delete W.ChaticSubWebView;
|
|
211
399
|
}
|
|
212
400
|
};
|
|
213
|
-
return
|
|
401
|
+
return se;
|
|
214
402
|
};
|
|
215
403
|
export {
|
|
216
|
-
|
|
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.
|
|
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": [
|
|
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
|
},
|