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