@viceme-ai/sdk 0.4.0 → 0.6.1
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/README.md +105 -16
- package/dist/browser-events.d.ts +5 -2
- package/dist/browser-events.d.ts.map +1 -1
- package/dist/chunks/build-endpoints-NrDmg6jf.js +12 -0
- package/dist/chunks/build-endpoints-NrDmg6jf.js.map +1 -0
- package/dist/chunks/{client-Cbldd7F2.js → client-w9vih8Ng.js} +267 -238
- package/dist/chunks/client-w9vih8Ng.js.map +1 -0
- package/dist/chunks/{errors-B-Qv_azy.js → errors-C7DfLKcF.js} +14 -22
- package/dist/chunks/errors-C7DfLKcF.js.map +1 -0
- package/dist/chunks/validation-patAYhXC.js +43 -0
- package/dist/chunks/validation-patAYhXC.js.map +1 -0
- package/dist/chunks/version-uPTHb89K.js +6 -0
- package/dist/chunks/{version-C8DeBm39.js.map → version-uPTHb89K.js.map} +1 -1
- package/dist/core/capabilities.d.ts +2 -0
- package/dist/core/capabilities.d.ts.map +1 -1
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/presentation.d.ts.map +1 -1
- package/dist/danmaku.js +5 -4
- package/dist/danmaku.js.map +1 -1
- package/dist/generated/public-contract.d.ts +108 -1
- package/dist/generated/public-contract.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +49 -37
- package/dist/testing.js +14 -14
- package/dist/testing.js.map +1 -1
- package/dist/tip/headless.d.ts +4 -0
- package/dist/tip/headless.d.ts.map +1 -0
- package/dist/tip/index.d.ts +47 -2
- package/dist/tip/index.d.ts.map +1 -1
- package/dist/tip/mount.d.ts.map +1 -1
- package/dist/tip/testing.d.ts +9 -0
- package/dist/tip/testing.d.ts.map +1 -0
- package/dist/tip/testing.js +43 -0
- package/dist/tip/testing.js.map +1 -0
- package/dist/tip/validation.d.ts +7 -0
- package/dist/tip/validation.d.ts.map +1 -0
- package/dist/tip.js +419 -84
- package/dist/tip.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/viceme.min.js +5 -2
- package/dist/viceme.min.js.map +1 -1
- package/package.json +7 -6
- package/dist/bootstrap.min.js +0 -2
- package/dist/bootstrap.min.js.map +0 -1
- package/dist/chunks/client-Cbldd7F2.js.map +0 -1
- package/dist/chunks/errors-B-Qv_azy.js.map +0 -1
- package/dist/chunks/version-C8DeBm39.js +0 -6
- package/dist/loader/bootstrap.d.ts +0 -1
- package/dist/loader/bootstrap.d.ts.map +0 -1
package/dist/tip.js
CHANGED
|
@@ -1,5 +1,319 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { B as Y } from "./chunks/build-endpoints-NrDmg6jf.js";
|
|
2
|
+
import { c as E, V as h } from "./chunks/errors-C7DfLKcF.js";
|
|
3
|
+
import { p as Z, t as M, i as U, a as ee } from "./chunks/validation-patAYhXC.js";
|
|
4
|
+
const te = ["work", "workKey", "environment", "currency", "amount", "providers"], J = ["id", "title"], re = ["minCents", "maxCents", "stepCents"], oe = ["statusCode", "code", "message", "requestId"], ie = ["type", "channel", "workKey"], ae = [
|
|
5
|
+
"type",
|
|
6
|
+
"channel",
|
|
7
|
+
"workKey",
|
|
8
|
+
"status",
|
|
9
|
+
"work",
|
|
10
|
+
"amountCents",
|
|
11
|
+
"currency"
|
|
12
|
+
], ne = ["type", "channel", "workKey", "status"], se = 8e3, ce = 8e3, V = 16 * 1024, le = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
13
|
+
function I(e, t) {
|
|
14
|
+
if (typeof e != "object" || e === null || Array.isArray(e)) return !1;
|
|
15
|
+
const o = Object.keys(e);
|
|
16
|
+
return o.length === t.length && t.every((a) => o.includes(a));
|
|
17
|
+
}
|
|
18
|
+
function p() {
|
|
19
|
+
return new h({
|
|
20
|
+
code: "TIP_CONFIG_INVALID",
|
|
21
|
+
message: "Shop returned an invalid Tip configuration.",
|
|
22
|
+
retryable: !1,
|
|
23
|
+
capability: "tip"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function de(e) {
|
|
27
|
+
return I(e, oe) ? e.statusCode === 400 && e.code === "TIP_CONFIG_CREDENTIALS_NOT_ALLOWED" && typeof e.message == "string" && typeof e.requestId == "string" && e.requestId.length >= 1 && e.requestId.length <= 128 : !1;
|
|
28
|
+
}
|
|
29
|
+
function ye(e) {
|
|
30
|
+
return new h({
|
|
31
|
+
code: "TIP_CONFIG_CREDENTIALS_NOT_ALLOWED",
|
|
32
|
+
message: "Tip configuration requests must not include credentials.",
|
|
33
|
+
retryable: !1,
|
|
34
|
+
requestId: e,
|
|
35
|
+
capability: "tip"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function we(e, t) {
|
|
39
|
+
if (!I(e, te) || !I(e.work, J) || typeof e.work.id != "string" || !le.test(e.work.id) || !U(e.work.title) || e.workKey !== t || e.environment !== "SANDBOX" && e.environment !== "PRODUCTION" || e.workKey.startsWith("wrk_test_") && e.environment !== "SANDBOX" || e.workKey.startsWith("wrk_live_") && e.environment !== "PRODUCTION" || e.currency !== "CNY" || !I(e.amount, re) || e.amount.minCents !== 100 || e.amount.maxCents !== 2e4 || e.amount.stepCents !== 1 || !Array.isArray(e.providers) || e.providers.length < 1 || !e.providers.every(ee) || new Set(e.providers).size !== e.providers.length)
|
|
40
|
+
throw p();
|
|
41
|
+
return {
|
|
42
|
+
work: { id: e.work.id, title: e.work.title },
|
|
43
|
+
workKey: e.workKey,
|
|
44
|
+
environment: e.environment,
|
|
45
|
+
currency: e.currency,
|
|
46
|
+
amount: { minCents: 100, maxCents: 2e4, stepCents: 1 },
|
|
47
|
+
providers: [...e.providers]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function ue(e, t, o, a) {
|
|
51
|
+
if (typeof e != "object" || e === null || Array.isArray(e)) return;
|
|
52
|
+
const i = e;
|
|
53
|
+
if (!(i.type !== "viceme:tip-headless-result" || i.channel !== t || i.workKey !== o.workKey)) {
|
|
54
|
+
if (i.status === "PAID")
|
|
55
|
+
return !I(i, ae) || !I(i.work, J) || i.work.id !== o.work.id || i.work.title !== o.work.title || i.amountCents !== a || i.currency !== "CNY" ? void 0 : {
|
|
56
|
+
status: "PAID",
|
|
57
|
+
work: { id: o.work.id, title: o.work.title },
|
|
58
|
+
amountCents: a,
|
|
59
|
+
currency: "CNY"
|
|
60
|
+
};
|
|
61
|
+
if ((i.status === "CANCELLED" || i.status === "UNKNOWN") && I(i, ne))
|
|
62
|
+
return { status: i.status };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function _() {
|
|
66
|
+
return new h({
|
|
67
|
+
code: "INTERNAL_ERROR",
|
|
68
|
+
message: "Unable to open the hosted Tip flow.",
|
|
69
|
+
capability: "tip"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function D() {
|
|
73
|
+
return new h({
|
|
74
|
+
code: "CAPABILITY_DISABLED",
|
|
75
|
+
message: "Tip is not available for this Work or region.",
|
|
76
|
+
retryable: !1,
|
|
77
|
+
capability: "tip"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async function z(e) {
|
|
81
|
+
const t = e.headers.get("content-length");
|
|
82
|
+
if (t !== null) {
|
|
83
|
+
const y = Number(t);
|
|
84
|
+
if (!Number.isInteger(y) || y < 0 || y > V)
|
|
85
|
+
throw await e.body?.cancel().catch(() => {
|
|
86
|
+
}), p();
|
|
87
|
+
}
|
|
88
|
+
const o = e.body?.getReader();
|
|
89
|
+
if (!o) throw p();
|
|
90
|
+
const a = new TextDecoder("utf-8", { fatal: !0 });
|
|
91
|
+
let i = 0, c = "";
|
|
92
|
+
try {
|
|
93
|
+
for (; ; ) {
|
|
94
|
+
const y = await o.read();
|
|
95
|
+
if (y.done) break;
|
|
96
|
+
if (i += y.value.byteLength, i > V)
|
|
97
|
+
throw await o.cancel().catch(() => {
|
|
98
|
+
}), p();
|
|
99
|
+
try {
|
|
100
|
+
c += a.decode(y.value, { stream: !0 });
|
|
101
|
+
} catch {
|
|
102
|
+
throw await o.cancel().catch(() => {
|
|
103
|
+
}), p();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
c += a.decode();
|
|
108
|
+
} catch {
|
|
109
|
+
throw await o.cancel().catch(() => {
|
|
110
|
+
}), p();
|
|
111
|
+
}
|
|
112
|
+
} finally {
|
|
113
|
+
o.releaseLock();
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
return JSON.parse(c);
|
|
117
|
+
} catch {
|
|
118
|
+
throw p();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function fe(e, t) {
|
|
122
|
+
if (await e.ready(), !e.hasCapability("tip") || e.region !== "cn") throw D();
|
|
123
|
+
if (t.aborted) throw E();
|
|
124
|
+
const o = new AbortController(), a = () => o.abort();
|
|
125
|
+
t.addEventListener("abort", a, { once: !0 });
|
|
126
|
+
const i = globalThis.setTimeout(() => o.abort(), ce), c = Y[e.region], y = new URL(
|
|
127
|
+
`/v1/work-sdk/${encodeURIComponent(e.workKey)}/tip-config`,
|
|
128
|
+
c
|
|
129
|
+
);
|
|
130
|
+
try {
|
|
131
|
+
const n = await fetch(y.toString(), {
|
|
132
|
+
method: "GET",
|
|
133
|
+
credentials: "omit",
|
|
134
|
+
redirect: "error",
|
|
135
|
+
headers: { accept: "application/json" },
|
|
136
|
+
signal: o.signal
|
|
137
|
+
}), u = n.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
|
|
138
|
+
let l;
|
|
139
|
+
try {
|
|
140
|
+
l = n.url ? new URL(n.url).origin : void 0;
|
|
141
|
+
} catch {
|
|
142
|
+
l = "invalid";
|
|
143
|
+
}
|
|
144
|
+
if (n.status !== 200) {
|
|
145
|
+
if (n.status === 404)
|
|
146
|
+
throw await n.body?.cancel().catch(() => {
|
|
147
|
+
}), D();
|
|
148
|
+
if (n.status === 400 && u === "application/json" && (!l || l === c)) {
|
|
149
|
+
let v;
|
|
150
|
+
try {
|
|
151
|
+
v = await z(n);
|
|
152
|
+
} catch {
|
|
153
|
+
throw _();
|
|
154
|
+
}
|
|
155
|
+
if (de(v))
|
|
156
|
+
throw ye(v.requestId);
|
|
157
|
+
} else
|
|
158
|
+
await n.body?.cancel().catch(() => {
|
|
159
|
+
});
|
|
160
|
+
throw new h({
|
|
161
|
+
code: "INTERNAL_ERROR",
|
|
162
|
+
message: "Unable to load Tip configuration.",
|
|
163
|
+
capability: "tip"
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (u !== "application/json" || l && l !== c)
|
|
167
|
+
throw await n.body?.cancel().catch(() => {
|
|
168
|
+
}), p();
|
|
169
|
+
const w = await z(n);
|
|
170
|
+
return we(w, e.workKey);
|
|
171
|
+
} catch (n) {
|
|
172
|
+
throw t.aborted ? E() : n instanceof h ? n : _();
|
|
173
|
+
} finally {
|
|
174
|
+
o.abort(), globalThis.clearTimeout(i), t.removeEventListener("abort", a);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function me(e) {
|
|
178
|
+
return {
|
|
179
|
+
work: { ...e.work },
|
|
180
|
+
workKey: e.workKey,
|
|
181
|
+
environment: e.environment,
|
|
182
|
+
currency: e.currency,
|
|
183
|
+
amount: { ...e.amount },
|
|
184
|
+
providers: [...e.providers]
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function pe(e) {
|
|
188
|
+
let t = !1, o, a;
|
|
189
|
+
const i = new AbortController(), c = () => t || e.state === "DESTROYED", y = () => {
|
|
190
|
+
if (!a) {
|
|
191
|
+
const n = fe(e, i.signal);
|
|
192
|
+
a = n, n.then(
|
|
193
|
+
() => {
|
|
194
|
+
a === n && (a = void 0);
|
|
195
|
+
},
|
|
196
|
+
() => {
|
|
197
|
+
a === n && (a = void 0);
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
return a;
|
|
202
|
+
};
|
|
203
|
+
return {
|
|
204
|
+
async getConfig() {
|
|
205
|
+
if (c()) throw E();
|
|
206
|
+
const n = await y();
|
|
207
|
+
if (c()) throw E();
|
|
208
|
+
return me(n);
|
|
209
|
+
},
|
|
210
|
+
open(n) {
|
|
211
|
+
if (c()) return Promise.reject(E());
|
|
212
|
+
if (o)
|
|
213
|
+
return Promise.reject(
|
|
214
|
+
new h({
|
|
215
|
+
code: "TIP_OPEN_IN_PROGRESS",
|
|
216
|
+
message: "This Tip client already has an open flow.",
|
|
217
|
+
retryable: !1,
|
|
218
|
+
capability: "tip"
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
if (!e.hasCapability("tip") || e.region !== "cn") return Promise.reject(D());
|
|
222
|
+
let u;
|
|
223
|
+
try {
|
|
224
|
+
u = Z(n);
|
|
225
|
+
} catch (s) {
|
|
226
|
+
return Promise.reject(s);
|
|
227
|
+
}
|
|
228
|
+
if (typeof document > "u")
|
|
229
|
+
return Promise.reject(M());
|
|
230
|
+
const l = document, w = l.defaultView;
|
|
231
|
+
if (!l.body || !w) return Promise.reject(M());
|
|
232
|
+
const v = Y[e.region], d = l.documentElement.lang || w.navigator.language, O = u.locale ?? (d.toLowerCase().startsWith("zh") ? "zh-CN" : "en-US"), L = u.appearance ?? "auto", S = L === "auto" ? w.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" : L;
|
|
233
|
+
let C, K;
|
|
234
|
+
try {
|
|
235
|
+
const s = new Uint8Array(16);
|
|
236
|
+
w.crypto.getRandomValues(s), C = Array.from(s, (b) => b.toString(16).padStart(2, "0")).join(""), K = e.ready();
|
|
237
|
+
} catch {
|
|
238
|
+
return Promise.reject(_());
|
|
239
|
+
}
|
|
240
|
+
const m = l.createElement("div");
|
|
241
|
+
m.dataset.vicemeTipHeadless = "open", m.style.all = "initial", m.style.position = "fixed", m.style.inset = "0", m.style.display = "block", m.style.width = "100vw", m.style.height = "100vh", m.style.zIndex = "2147483647";
|
|
242
|
+
const f = l.createElement("iframe"), T = new URL(`/widget/tip/${encodeURIComponent(e.workKey)}`, v);
|
|
243
|
+
T.searchParams.set("mode", "headless"), T.searchParams.set("channel", C), T.searchParams.set("appearance", S), T.searchParams.set("locale", O), f.title = "ViceMe Tip", f.src = T.toString(), f.loading = "eager", f.referrerPolicy = "strict-origin", f.setAttribute(
|
|
244
|
+
"sandbox",
|
|
245
|
+
"allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"
|
|
246
|
+
), f.setAttribute("allow", "payment"), f.style.display = "block", f.style.width = "100%", f.style.height = "100%", f.style.border = "0", f.style.background = "transparent", f.style.colorScheme = S, m.attachShadow({ mode: "open" }).append(f);
|
|
247
|
+
let k = !1, g = !1, r = !1, R, A, j, W;
|
|
248
|
+
const Q = new Promise((s, b) => {
|
|
249
|
+
j = s, W = b;
|
|
250
|
+
}), x = () => {
|
|
251
|
+
A !== void 0 && (w.clearTimeout(A), A = void 0), w.removeEventListener("message", H), m.remove(), o === B && (o = void 0);
|
|
252
|
+
}, G = (s) => {
|
|
253
|
+
k || (k = !0, x(), j(s));
|
|
254
|
+
}, N = (s) => {
|
|
255
|
+
k || (k = !0, x(), W(s));
|
|
256
|
+
}, B = () => G({ status: "UNKNOWN" }), q = () => {
|
|
257
|
+
if (!g || !R || r || k) return;
|
|
258
|
+
if (u.provider && !R.providers.includes(u.provider)) {
|
|
259
|
+
N(M());
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
r = !0;
|
|
263
|
+
const s = {
|
|
264
|
+
type: "viceme:tip-headless-init",
|
|
265
|
+
channel: C,
|
|
266
|
+
workKey: e.workKey,
|
|
267
|
+
amountCents: u.amountCents,
|
|
268
|
+
...u.provider === void 0 ? {} : { provider: u.provider },
|
|
269
|
+
locale: O,
|
|
270
|
+
appearance: S
|
|
271
|
+
};
|
|
272
|
+
try {
|
|
273
|
+
const b = f.contentWindow;
|
|
274
|
+
if (!b) {
|
|
275
|
+
N(_());
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
b.postMessage(s, v);
|
|
279
|
+
} catch {
|
|
280
|
+
N(_());
|
|
281
|
+
}
|
|
282
|
+
}, H = (s) => {
|
|
283
|
+
if (s.origin !== v || s.source !== f.contentWindow) return;
|
|
284
|
+
if (!r) {
|
|
285
|
+
if (!I(s.data, ie) || s.data.type !== "viceme:tip-headless-ready" || s.data.channel !== C || s.data.workKey !== e.workKey)
|
|
286
|
+
return;
|
|
287
|
+
g = !0, A !== void 0 && (w.clearTimeout(A), A = void 0), q();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (!R) return;
|
|
291
|
+
const b = ue(s.data, C, R, u.amountCents);
|
|
292
|
+
b && b.status !== "UNKNOWN" && G(b);
|
|
293
|
+
};
|
|
294
|
+
return o = B, w.addEventListener("message", H), A = w.setTimeout(() => {
|
|
295
|
+
N(
|
|
296
|
+
new h({
|
|
297
|
+
code: "TIP_READY_TIMEOUT",
|
|
298
|
+
message: "Hosted Tip did not become ready in time.",
|
|
299
|
+
retryable: !0,
|
|
300
|
+
capability: "tip"
|
|
301
|
+
})
|
|
302
|
+
);
|
|
303
|
+
}, se), l.body.append(m), K.catch((s) => {
|
|
304
|
+
N(s instanceof h ? s : _());
|
|
305
|
+
}), y().then((s) => {
|
|
306
|
+
R = s, q();
|
|
307
|
+
}).catch((s) => {
|
|
308
|
+
N(s instanceof h ? s : _());
|
|
309
|
+
}), Q;
|
|
310
|
+
},
|
|
311
|
+
destroy() {
|
|
312
|
+
t || (t = !0, i.abort(), o?.());
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
const he = /* @__PURE__ */ new Map([
|
|
3
317
|
["viceme:ready", /* @__PURE__ */ new Set(["clientKey", "workKey", "capabilities", "version"])],
|
|
4
318
|
["viceme:capability-ready", /* @__PURE__ */ new Set(["clientKey", "instanceKey", "capability", "version"])],
|
|
5
319
|
[
|
|
@@ -8,130 +322,151 @@ const M = /* @__PURE__ */ new Map([
|
|
|
8
322
|
],
|
|
9
323
|
["viceme:destroyed", /* @__PURE__ */ new Set(["clientKey", "instanceKey", "capability"])],
|
|
10
324
|
["viceme:widget-close", /* @__PURE__ */ new Set(["workId"])],
|
|
11
|
-
["viceme:tip-paid", /* @__PURE__ */ new Set(["
|
|
325
|
+
["viceme:tip-paid", /* @__PURE__ */ new Set(["status", "work", "amountCents", "currency"])]
|
|
12
326
|
]);
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
327
|
+
function ge(e, t) {
|
|
328
|
+
if (e === "viceme:tip-paid") {
|
|
329
|
+
const i = t;
|
|
330
|
+
return {
|
|
331
|
+
status: i.status,
|
|
332
|
+
work: { id: i.work.id, title: i.work.title },
|
|
333
|
+
amountCents: i.amountCents,
|
|
334
|
+
currency: i.currency
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
const o = he.get(e), a = {};
|
|
338
|
+
for (const [i, c] of Object.entries(t))
|
|
339
|
+
o.has(i) && c !== void 0 && (a[i] = c);
|
|
340
|
+
return a;
|
|
341
|
+
}
|
|
342
|
+
function F(e, t, o) {
|
|
343
|
+
const a = new CustomEvent(t, {
|
|
344
|
+
detail: ge(t, o),
|
|
22
345
|
bubbles: !0,
|
|
23
346
|
composed: !0,
|
|
24
347
|
cancelable: !1
|
|
25
348
|
});
|
|
26
|
-
|
|
349
|
+
e.dispatchEvent(a);
|
|
27
350
|
}
|
|
28
|
-
const
|
|
29
|
-
function
|
|
30
|
-
|
|
351
|
+
const be = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, ve = 100, ke = 2e4, Ee = 2048, Te = 8e3, Ie = ["type", "workId", "work", "height"], Ce = ["type", "workId"], Ae = ["type", "workKey", "status", "work", "amountCents", "currency"], $ = ["id", "title"];
|
|
352
|
+
function P(e, t) {
|
|
353
|
+
if (typeof e != "object" || e === null || Array.isArray(e)) return !1;
|
|
354
|
+
const o = Object.keys(e);
|
|
355
|
+
return o.length === t.length && t.every((a) => o.includes(a));
|
|
31
356
|
}
|
|
32
|
-
async function
|
|
33
|
-
if (t.signal?.aborted) throw
|
|
34
|
-
if (await
|
|
35
|
-
if (!
|
|
36
|
-
throw new
|
|
357
|
+
async function _e(e, t) {
|
|
358
|
+
if (t.signal?.aborted) throw E();
|
|
359
|
+
if (await e.ready(), t.signal?.aborted) throw E();
|
|
360
|
+
if (!e.hasCapability("tip"))
|
|
361
|
+
throw new h({
|
|
37
362
|
code: "CAPABILITY_DISABLED",
|
|
38
363
|
message: "Tip is not available in this SDK build.",
|
|
39
364
|
retryable: !1,
|
|
40
365
|
capability: "tip"
|
|
41
366
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
367
|
+
if (e.region !== "cn")
|
|
368
|
+
throw new h({
|
|
369
|
+
code: "CAPABILITY_DISABLED",
|
|
370
|
+
message: "Tip is not available in this region.",
|
|
371
|
+
retryable: !1,
|
|
372
|
+
capability: "tip"
|
|
373
|
+
});
|
|
374
|
+
const o = t.target.ownerDocument, a = o.defaultView;
|
|
375
|
+
if (!a)
|
|
376
|
+
throw new h({
|
|
45
377
|
code: "CONFIG_INVALID",
|
|
46
378
|
message: "Tip requires a browser document.",
|
|
47
379
|
retryable: !1,
|
|
48
380
|
capability: "tip"
|
|
49
381
|
});
|
|
50
|
-
const
|
|
51
|
-
let
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
382
|
+
const i = Y[e.region], c = t.theme === "auto" ? a.matchMedia("(prefers-color-scheme: dark)") : void 0;
|
|
383
|
+
let y = t.theme === "auto" ? c?.matches ? "dark" : "light" : t.theme, n = !1, u, l;
|
|
384
|
+
const w = o.createElement("div");
|
|
385
|
+
w.dataset.vicemeTip = "mounted", w.style.all = "initial", w.style.display = "block", w.style.width = "100%", w.style.maxWidth = "100%", w.style.contain = "layout style";
|
|
386
|
+
const v = w.attachShadow({ mode: "open" }), d = o.createElement("iframe"), O = new URL(`/widget/tip/${encodeURIComponent(e.workKey)}`, i);
|
|
387
|
+
O.searchParams.set("appearance", y), d.title = "ViceMe Tip", d.src = O.toString(), d.loading = "eager", d.referrerPolicy = "strict-origin", d.setAttribute(
|
|
56
388
|
"sandbox",
|
|
57
389
|
"allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"
|
|
58
|
-
),
|
|
59
|
-
let
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
new
|
|
390
|
+
), d.setAttribute("allow", "payment"), d.style.boxSizing = "border-box", d.style.display = "block", d.style.width = "100%", d.style.height = "0px", d.style.margin = "0", d.style.border = "0", d.style.background = "transparent", d.style.colorScheme = y, d.style.pointerEvents = "none", v.append(d);
|
|
391
|
+
let L, S;
|
|
392
|
+
const C = new Promise((g, r) => {
|
|
393
|
+
L = g, S = r, u = a.setTimeout(() => {
|
|
394
|
+
r(
|
|
395
|
+
new h({
|
|
64
396
|
code: "INTERNAL_ERROR",
|
|
65
397
|
message: "Hosted Tip widget did not become ready in time.",
|
|
66
398
|
retryable: !0,
|
|
67
399
|
capability: "tip"
|
|
68
400
|
})
|
|
69
401
|
);
|
|
70
|
-
},
|
|
71
|
-
}),
|
|
72
|
-
if (
|
|
73
|
-
const
|
|
74
|
-
if (!(
|
|
75
|
-
if (
|
|
76
|
-
if (typeof
|
|
402
|
+
}, Te);
|
|
403
|
+
}), K = (g) => {
|
|
404
|
+
if (g.origin !== i || g.source !== d.contentWindow) return;
|
|
405
|
+
const r = g.data;
|
|
406
|
+
if (!(typeof r != "object" || r === null || Array.isArray(r))) {
|
|
407
|
+
if (P(r, Ie) && r.type === "viceme:widget-resize") {
|
|
408
|
+
if (typeof r.workId != "string" || !be.test(r.workId) || !P(r.work, $) || r.work.id !== r.workId || !U(r.work.title) || typeof r.height != "number" || !Number.isInteger(r.height) || r.height < 1 || r.height > Ee || l !== void 0 && (r.work.id !== l.id || r.work.title !== l.title))
|
|
77
409
|
return;
|
|
78
|
-
|
|
410
|
+
d.style.height = `${r.height}px`, l === void 0 && (l = { id: r.workId, title: r.work.title }, d.style.pointerEvents = "auto", u !== void 0 && (a.clearTimeout(u), u = void 0), L?.());
|
|
79
411
|
return;
|
|
80
412
|
}
|
|
81
|
-
if (
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
e.type === "viceme:tip-paid" && typeof e.orderNo == "string" && S.test(e.orderNo) && e.status === "PAID" && typeof e.amountCents == "number" && Number.isInteger(e.amountCents) && e.amountCents >= C && e.amountCents <= O && k(t.target, "viceme:tip-paid", {
|
|
87
|
-
workId: e.workId,
|
|
88
|
-
orderNo: e.orderNo,
|
|
89
|
-
status: "PAID",
|
|
90
|
-
amountCents: e.amountCents
|
|
91
|
-
});
|
|
413
|
+
if (P(r, Ce) && r.type === "viceme:widget-close") {
|
|
414
|
+
if (typeof r.workId != "string" || r.workId !== l?.id) return;
|
|
415
|
+
F(t.target, "viceme:widget-close", { workId: r.workId });
|
|
416
|
+
return;
|
|
92
417
|
}
|
|
418
|
+
P(r, Ae) && r.type === "viceme:tip-paid" && r.workKey === e.workKey && P(r.work, $) && l !== void 0 && typeof r.work.id == "string" && r.work.id === l.id && U(r.work.title) && r.work.title === l.title && r.status === "PAID" && typeof r.amountCents == "number" && Number.isInteger(r.amountCents) && r.amountCents >= ve && r.amountCents <= ke && r.currency === "CNY" && F(t.target, "viceme:tip-paid", {
|
|
419
|
+
status: "PAID",
|
|
420
|
+
work: { id: r.work.id, title: r.work.title },
|
|
421
|
+
amountCents: r.amountCents,
|
|
422
|
+
currency: "CNY"
|
|
423
|
+
});
|
|
93
424
|
}
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
{ type: "viceme:widget-appearance", appearance:
|
|
97
|
-
|
|
425
|
+
}, m = (g) => {
|
|
426
|
+
y = g.matches ? "dark" : "light", d.style.colorScheme = y, d.contentWindow?.postMessage(
|
|
427
|
+
{ type: "viceme:widget-appearance", appearance: y },
|
|
428
|
+
i
|
|
98
429
|
);
|
|
99
430
|
};
|
|
100
|
-
let
|
|
431
|
+
let f;
|
|
101
432
|
const T = () => {
|
|
102
|
-
|
|
103
|
-
},
|
|
104
|
-
|
|
433
|
+
S?.(E()), k();
|
|
434
|
+
}, k = () => {
|
|
435
|
+
n || (n = !0, u !== void 0 && a.clearTimeout(u), a.removeEventListener("message", K), f?.(), t.signal?.removeEventListener("abort", T), w.remove());
|
|
105
436
|
};
|
|
106
437
|
try {
|
|
107
|
-
if (
|
|
108
|
-
t.target.appendChild(
|
|
109
|
-
} catch (
|
|
110
|
-
throw
|
|
438
|
+
if (a.addEventListener("message", K), c && (typeof c.addEventListener == "function" ? (c.addEventListener("change", m), f = () => c.removeEventListener("change", m)) : (c.addListener(m), f = () => c.removeListener(m))), t.signal?.addEventListener("abort", T, { once: !0 }), t.signal?.aborted) throw E();
|
|
439
|
+
t.target.appendChild(w), await C;
|
|
440
|
+
} catch (g) {
|
|
441
|
+
throw k(), g;
|
|
111
442
|
}
|
|
112
|
-
return { capability: "tip", destroy:
|
|
113
|
-
}
|
|
114
|
-
const
|
|
115
|
-
function
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
443
|
+
return { capability: "tip", destroy: k };
|
|
444
|
+
}
|
|
445
|
+
const X = /* @__PURE__ */ new WeakMap();
|
|
446
|
+
function Le(e) {
|
|
447
|
+
return pe(e);
|
|
448
|
+
}
|
|
449
|
+
function Ke(e, t) {
|
|
450
|
+
let o = X.get(e);
|
|
451
|
+
o || (o = /* @__PURE__ */ new WeakMap(), X.set(e, o));
|
|
452
|
+
const a = o.get(t.target);
|
|
453
|
+
if (a) return a;
|
|
454
|
+
const i = _e(e, t).then((c) => {
|
|
455
|
+
let y = !1;
|
|
456
|
+
const n = {
|
|
123
457
|
capability: "tip",
|
|
124
458
|
destroy() {
|
|
125
|
-
|
|
459
|
+
y || (y = !0, t.signal?.removeEventListener("abort", n.destroy), o.get(t.target) === i && o.delete(t.target), c.destroy());
|
|
126
460
|
}
|
|
127
461
|
};
|
|
128
|
-
return t.signal?.addEventListener("abort",
|
|
129
|
-
}).catch((
|
|
130
|
-
throw
|
|
462
|
+
return t.signal?.addEventListener("abort", n.destroy, { once: !0 }), t.signal?.aborted && n.destroy(), n;
|
|
463
|
+
}).catch((c) => {
|
|
464
|
+
throw o.get(t.target) === i && o.delete(t.target), c;
|
|
131
465
|
});
|
|
132
|
-
return
|
|
466
|
+
return o.set(t.target, i), i;
|
|
133
467
|
}
|
|
134
468
|
export {
|
|
135
|
-
|
|
469
|
+
Le as createTip,
|
|
470
|
+
Ke as mountTip
|
|
136
471
|
};
|
|
137
472
|
//# sourceMappingURL=tip.js.map
|