@viceme-ai/sdk 0.3.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 +158 -44
- package/dist/browser-events.d.ts +52 -0
- package/dist/browser-events.d.ts.map +1 -0
- package/dist/capability-mount.d.ts +15 -0
- package/dist/capability-mount.d.ts.map +1 -0
- package/dist/chunks/build-endpoints-NrDmg6jf.js +12 -0
- package/dist/chunks/build-endpoints-NrDmg6jf.js.map +1 -0
- package/dist/chunks/{client-DKsaEtwq.js → client-w9vih8Ng.js} +386 -349
- package/dist/chunks/client-w9vih8Ng.js.map +1 -0
- package/dist/chunks/{version-C3KVoLNb.js → errors-C7DfLKcF.js} +14 -25
- 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-uPTHb89K.js.map +1 -0
- package/dist/core/build-endpoints.d.ts +2 -0
- package/dist/core/build-endpoints.d.ts.map +1 -1
- package/dist/core/capabilities.d.ts +4 -2
- package/dist/core/capabilities.d.ts.map +1 -1
- package/dist/core/client.d.ts +4 -2
- 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/lifecycle.d.ts +2 -4
- package/dist/core/lifecycle.d.ts.map +1 -1
- package/dist/core/presentation.d.ts +7 -2
- package/dist/core/presentation.d.ts.map +1 -1
- package/dist/danmaku/index.d.ts +1 -0
- package/dist/danmaku/index.d.ts.map +1 -1
- package/dist/danmaku/mount.d.ts +1 -1
- package/dist/danmaku/mount.d.ts.map +1 -1
- package/dist/danmaku.js +128 -121
- package/dist/danmaku.js.map +1 -1
- package/dist/generated/public-contract.d.ts +124 -373
- package/dist/generated/public-contract.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -21
- package/dist/index.js.map +1 -1
- package/dist/loader/attributes.d.ts +3 -2
- package/dist/loader/attributes.d.ts.map +1 -1
- package/dist/loader/auto-loader.d.ts +1 -1
- package/dist/loader/auto-loader.d.ts.map +1 -1
- package/dist/loader/events.d.ts +1 -44
- package/dist/loader/events.d.ts.map +1 -1
- package/dist/loader/registry.d.ts +2 -1
- package/dist/loader/registry.d.ts.map +1 -1
- package/dist/manifest.json +60 -35
- package/dist/session/session.d.ts +7 -6
- package/dist/session/session.d.ts.map +1 -1
- package/dist/testing/test-adapter.d.ts +1 -1
- package/dist/testing/test-adapter.d.ts.map +1 -1
- package/dist/testing.js +18 -17
- 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 +67 -0
- package/dist/tip/index.d.ts.map +1 -0
- package/dist/tip/mount.d.ts +5 -0
- package/dist/tip/mount.d.ts.map +1 -0
- 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 +472 -0
- package/dist/tip.js.map +1 -0
- package/dist/transport/transport.d.ts +3 -1
- package/dist/transport/transport.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/viceme.min.js +5 -22
- package/dist/viceme.min.js.map +1 -1
- package/package.json +12 -7
- package/dist/bootstrap.min.js +0 -2
- package/dist/bootstrap.min.js.map +0 -1
- package/dist/chunks/client-DKsaEtwq.js.map +0 -1
- package/dist/chunks/version-C3KVoLNb.js.map +0 -1
- package/dist/loader/bootstrap.d.ts +0 -1
- package/dist/loader/bootstrap.d.ts.map +0 -1
- package/dist/loader/mount-handle.d.ts +0 -25
- package/dist/loader/mount-handle.d.ts.map +0 -1
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
1
|
+
import { a as C, V as b, c as x, i as G } from "./errors-C7DfLKcF.js";
|
|
2
|
+
import { a as q, B as z } from "./build-endpoints-NrDmg6jf.js";
|
|
3
|
+
import { S as H, A as V } from "./version-uPTHb89K.js";
|
|
4
|
+
const W = /* @__PURE__ */ new Set(["cn", "global"]), j = {
|
|
3
5
|
cn: q.cn,
|
|
4
6
|
global: q.global
|
|
5
7
|
};
|
|
6
|
-
function
|
|
7
|
-
return
|
|
8
|
+
function me(t) {
|
|
9
|
+
return j[t];
|
|
8
10
|
}
|
|
9
11
|
function B(t) {
|
|
10
|
-
return typeof t == "string" && /^wrk_[A-Za-z0-9_-]{4,
|
|
12
|
+
return typeof t == "string" && /^wrk_(?:test|live)_[A-Za-z0-9_-]{4,119}$/.test(t);
|
|
11
13
|
}
|
|
12
|
-
function
|
|
13
|
-
return typeof t == "string" &&
|
|
14
|
+
function Y(t) {
|
|
15
|
+
return typeof t == "string" && W.has(t);
|
|
14
16
|
}
|
|
15
|
-
function
|
|
17
|
+
function he(t) {
|
|
16
18
|
if (typeof t != "object" || t === null)
|
|
17
19
|
throw C("createViceMe expects a configuration object.");
|
|
18
20
|
const e = t, i = /* @__PURE__ */ new Set(["workKey", "region", "signal"]);
|
|
19
|
-
for (const
|
|
20
|
-
if (!i.has(
|
|
21
|
-
throw C(`Unknown configuration field "${
|
|
21
|
+
for (const r of Object.keys(e))
|
|
22
|
+
if (!i.has(r))
|
|
23
|
+
throw C(`Unknown configuration field "${r}".`);
|
|
22
24
|
if (!B(e.workKey))
|
|
23
|
-
throw C(
|
|
24
|
-
|
|
25
|
+
throw C(
|
|
26
|
+
'Configuration field "workKey" must start with "wrk_test_" or "wrk_live_".'
|
|
27
|
+
);
|
|
28
|
+
if (!Y(e.region))
|
|
25
29
|
throw C('Configuration field "region" must be "cn" or "global".');
|
|
26
30
|
if (e.signal !== void 0 && !(e.signal instanceof AbortSignal))
|
|
27
31
|
throw C('Configuration field "signal" must be an AbortSignal.');
|
|
@@ -31,15 +35,13 @@ function me(t) {
|
|
|
31
35
|
signal: e.signal
|
|
32
36
|
};
|
|
33
37
|
}
|
|
34
|
-
const
|
|
35
|
-
CREATED: ["
|
|
36
|
-
INITIALIZING: ["READY", "FAILED", "DESTROYED"],
|
|
38
|
+
const $ = {
|
|
39
|
+
CREATED: ["READY", "DESTROYED"],
|
|
37
40
|
READY: ["DEGRADED", "DESTROYED"],
|
|
38
41
|
DEGRADED: ["DESTROYED"],
|
|
39
|
-
FAILED: ["INITIALIZING", "DESTROYED"],
|
|
40
42
|
DESTROYED: []
|
|
41
43
|
};
|
|
42
|
-
class
|
|
44
|
+
class Q {
|
|
43
45
|
#e = "CREATED";
|
|
44
46
|
#t = /* @__PURE__ */ new Set();
|
|
45
47
|
get state() {
|
|
@@ -50,7 +52,7 @@ class X {
|
|
|
50
52
|
}
|
|
51
53
|
transition(e) {
|
|
52
54
|
if (e !== this.#e) {
|
|
53
|
-
if (
|
|
55
|
+
if (!$[this.#e].includes(e))
|
|
54
56
|
throw new b({
|
|
55
57
|
code: "INTERNAL_ERROR",
|
|
56
58
|
message: `Illegal lifecycle transition ${this.#e} -> ${e}.`,
|
|
@@ -62,7 +64,7 @@ class X {
|
|
|
62
64
|
}
|
|
63
65
|
/** Any operation on a destroyed client must fail closed with this guard. */
|
|
64
66
|
assertAlive() {
|
|
65
|
-
if (this.destroyed) throw
|
|
67
|
+
if (this.destroyed) throw x();
|
|
66
68
|
}
|
|
67
69
|
subscribe(e) {
|
|
68
70
|
return this.#t.add(e), () => {
|
|
@@ -73,38 +75,42 @@ class X {
|
|
|
73
75
|
this.#t.clear();
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
|
-
function
|
|
78
|
+
function X(t, e) {
|
|
77
79
|
if (typeof t != "object" || t === null)
|
|
78
|
-
throw
|
|
79
|
-
const i = t
|
|
80
|
-
if (typeof
|
|
81
|
-
throw
|
|
82
|
-
if (
|
|
80
|
+
throw R();
|
|
81
|
+
const i = t;
|
|
82
|
+
if (typeof i.workKey != "string" || !Array.isArray(i.capabilities) || !i.capabilities.every((c) => typeof c == "string"))
|
|
83
|
+
throw R();
|
|
84
|
+
if (i.workKey !== e)
|
|
83
85
|
throw new b({
|
|
84
86
|
code: "WORK_NOT_FOUND",
|
|
85
87
|
message: "Work-session response did not match the requested work key.",
|
|
86
88
|
retryable: !1
|
|
87
89
|
});
|
|
88
|
-
const
|
|
90
|
+
const r = {
|
|
89
91
|
work: {
|
|
90
|
-
key:
|
|
91
|
-
capabilities:
|
|
92
|
+
key: i.workKey,
|
|
93
|
+
capabilities: i.capabilities
|
|
92
94
|
}
|
|
93
95
|
};
|
|
94
|
-
|
|
96
|
+
if (typeof i.token == "string" && (r.token = i.token), typeof i.expiresAt == "string") {
|
|
97
|
+
const c = new Date(i.expiresAt).getTime();
|
|
98
|
+
Number.isNaN(c) || (r.expiresAt = c);
|
|
99
|
+
}
|
|
100
|
+
return r;
|
|
95
101
|
}
|
|
96
|
-
function
|
|
102
|
+
function R() {
|
|
97
103
|
return new b({
|
|
98
104
|
code: "INTERNAL_ERROR",
|
|
99
105
|
message: "Malformed work-session response.",
|
|
100
106
|
retryable: !0
|
|
101
107
|
});
|
|
102
108
|
}
|
|
103
|
-
class
|
|
109
|
+
class J {
|
|
104
110
|
#e;
|
|
105
111
|
#t;
|
|
106
112
|
#i;
|
|
107
|
-
#
|
|
113
|
+
#r;
|
|
108
114
|
constructor(e) {
|
|
109
115
|
this.#e = e, this.#t = e.now ?? (() => Date.now());
|
|
110
116
|
}
|
|
@@ -112,7 +118,7 @@ class ee {
|
|
|
112
118
|
return this.#i;
|
|
113
119
|
}
|
|
114
120
|
/** True when the cached snapshot's server-provided expiry has passed. */
|
|
115
|
-
#
|
|
121
|
+
#a() {
|
|
116
122
|
const e = this.#i?.expiresAt;
|
|
117
123
|
return e !== void 0 && e <= this.#t();
|
|
118
124
|
}
|
|
@@ -125,49 +131,50 @@ class ee {
|
|
|
125
131
|
*/
|
|
126
132
|
establish() {
|
|
127
133
|
if (this.#i) {
|
|
128
|
-
if (!this.#
|
|
134
|
+
if (!this.#a()) return Promise.resolve(this.#i);
|
|
129
135
|
this.#i = void 0;
|
|
130
136
|
}
|
|
131
|
-
return this.#
|
|
137
|
+
return this.#r ??= this.#e.transport.request({
|
|
132
138
|
method: "POST",
|
|
133
|
-
path: "/v1/public/
|
|
139
|
+
path: "/v1/public/work-sdk/sessions",
|
|
134
140
|
body: { workKey: this.#e.workKey },
|
|
135
141
|
signal: this.#e.signal,
|
|
136
142
|
timeoutMs: this.#e.timeoutMs
|
|
137
143
|
}).then((e) => {
|
|
138
|
-
const i =
|
|
144
|
+
const i = X(e.body, this.#e.workKey);
|
|
139
145
|
return this.#i = i, i;
|
|
140
146
|
}).finally(() => {
|
|
141
|
-
this.#
|
|
142
|
-
}), this.#
|
|
147
|
+
this.#r = void 0;
|
|
148
|
+
}), this.#r;
|
|
143
149
|
}
|
|
144
150
|
async request(e) {
|
|
145
151
|
const i = await this.establish();
|
|
146
|
-
if (!i.token) throw
|
|
152
|
+
if (!i.token) throw R();
|
|
147
153
|
try {
|
|
148
154
|
return await this.#e.transport.request({
|
|
149
155
|
...e,
|
|
150
156
|
authorization: i.token,
|
|
157
|
+
userAuthorization: i.userToken,
|
|
151
158
|
signal: this.#e.signal
|
|
152
159
|
});
|
|
153
|
-
} catch (
|
|
154
|
-
if (!(
|
|
160
|
+
} catch (r) {
|
|
161
|
+
if (!(r instanceof b) || r.code !== "SESSION_EXPIRED") throw r;
|
|
155
162
|
this.#i === i && this.invalidate();
|
|
156
|
-
const
|
|
157
|
-
if (!
|
|
163
|
+
const c = await this.establish();
|
|
164
|
+
if (!c.token) throw R();
|
|
158
165
|
return this.#e.transport.request({
|
|
159
166
|
...e,
|
|
160
|
-
authorization:
|
|
167
|
+
authorization: c.token,
|
|
168
|
+
userAuthorization: c.userToken,
|
|
161
169
|
signal: this.#e.signal
|
|
162
170
|
});
|
|
163
171
|
}
|
|
164
172
|
}
|
|
165
173
|
authenticate(e) {
|
|
166
|
-
if (!this.#i) throw
|
|
174
|
+
if (!this.#i) throw R();
|
|
167
175
|
this.#i = {
|
|
168
176
|
...this.#i,
|
|
169
|
-
|
|
170
|
-
expiresAt: e.expiresAt,
|
|
177
|
+
userToken: e.userToken,
|
|
171
178
|
user: e.user
|
|
172
179
|
};
|
|
173
180
|
}
|
|
@@ -180,26 +187,31 @@ class ee {
|
|
|
180
187
|
}
|
|
181
188
|
/** Hard cleanup: forget the token and pending work. */
|
|
182
189
|
destroy() {
|
|
183
|
-
this.invalidate(), this.#
|
|
190
|
+
this.invalidate(), this.#r = void 0;
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
|
-
const
|
|
187
|
-
function
|
|
193
|
+
const M = "viceme-access-layer", U = 50;
|
|
194
|
+
function Z(t) {
|
|
188
195
|
switch (t) {
|
|
189
196
|
case "SIGN_IN":
|
|
190
197
|
return {
|
|
191
198
|
description: "",
|
|
192
199
|
label: "授权"
|
|
193
200
|
};
|
|
201
|
+
case "FOLLOW":
|
|
202
|
+
return {
|
|
203
|
+
description: "",
|
|
204
|
+
label: "关注"
|
|
205
|
+
};
|
|
194
206
|
case "CHECKOUT":
|
|
195
207
|
return {
|
|
196
208
|
description: "",
|
|
197
|
-
label: "
|
|
209
|
+
label: "打开支付"
|
|
198
210
|
};
|
|
199
211
|
}
|
|
200
212
|
}
|
|
201
|
-
function
|
|
202
|
-
if (!
|
|
213
|
+
function ee(t) {
|
|
214
|
+
if (!G(t)) return "操作未完成,请重试。";
|
|
203
215
|
switch (t.code) {
|
|
204
216
|
case "CONFIG_INVALID":
|
|
205
217
|
return "微信授权配置无效,请稍后重试。";
|
|
@@ -213,13 +225,13 @@ function ie(t) {
|
|
|
213
225
|
return t.requestId ? `操作未完成,请重试。请求 ID:${t.requestId}` : "操作未完成,请重试。";
|
|
214
226
|
}
|
|
215
227
|
}
|
|
216
|
-
function
|
|
217
|
-
if (customElements.get(
|
|
228
|
+
function te() {
|
|
229
|
+
if (customElements.get(M)) return;
|
|
218
230
|
class t extends HTMLElement {
|
|
219
231
|
interaction;
|
|
220
232
|
connectedCallback() {
|
|
221
|
-
const i =
|
|
222
|
-
|
|
233
|
+
const i = Z(this.interaction.action), r = this.attachShadow({ mode: "open" });
|
|
234
|
+
r.innerHTML = `
|
|
223
235
|
<style>
|
|
224
236
|
:host {
|
|
225
237
|
position: fixed;
|
|
@@ -325,25 +337,6 @@ function ae() {
|
|
|
325
337
|
font-size: 0.875rem;
|
|
326
338
|
}
|
|
327
339
|
[data-viceme='profile-header'] { min-width: 0; }
|
|
328
|
-
[data-viceme='profile-covers'] {
|
|
329
|
-
display: none;
|
|
330
|
-
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
331
|
-
gap: 0.75rem;
|
|
332
|
-
margin-top: 1.25rem;
|
|
333
|
-
border-radius: 0.875rem;
|
|
334
|
-
padding: 0.75rem;
|
|
335
|
-
background: #f4f4f5;
|
|
336
|
-
}
|
|
337
|
-
[data-viceme='profile-covers'][data-visible='true'] { display: grid; }
|
|
338
|
-
[data-viceme='profile-cover'] {
|
|
339
|
-
display: block;
|
|
340
|
-
width: 100%;
|
|
341
|
-
aspect-ratio: 16 / 9;
|
|
342
|
-
border: 1px solid #e4e4e7;
|
|
343
|
-
border-radius: 0.625rem;
|
|
344
|
-
object-fit: cover;
|
|
345
|
-
background: #ffffff;
|
|
346
|
-
}
|
|
347
340
|
[data-viceme='panel'][data-action='SIGN_IN'] [data-viceme='description'] { display: none; }
|
|
348
341
|
[data-viceme='panel'][data-action='SIGN_IN'] [data-viceme='profile'][data-visible='true'] {
|
|
349
342
|
display: block;
|
|
@@ -419,6 +412,9 @@ function ae() {
|
|
|
419
412
|
}
|
|
420
413
|
[data-viceme='panel'][data-frame='true'] { width: min(30rem, 100%); }
|
|
421
414
|
[data-viceme='panel'][data-action='SIGN_IN'] { width: min(30rem, 100%); }
|
|
415
|
+
[data-viceme='panel'][data-action='CHECKOUT'][data-frame='true'] {
|
|
416
|
+
width: min(42rem, 100%);
|
|
417
|
+
}
|
|
422
418
|
}
|
|
423
419
|
@media (prefers-reduced-motion: no-preference) {
|
|
424
420
|
[data-viceme='panel'] { animation: viceme-enter 160ms ease-out; }
|
|
@@ -441,7 +437,6 @@ function ae() {
|
|
|
441
437
|
</div>
|
|
442
438
|
</div>
|
|
443
439
|
<p data-viceme="profile-description"></p>
|
|
444
|
-
<div data-viceme="profile-covers" aria-label="作品封面"></div>
|
|
445
440
|
</section>
|
|
446
441
|
<p data-viceme="error" role="alert" aria-live="polite"></p>
|
|
447
442
|
<div data-viceme="actions">
|
|
@@ -451,435 +446,478 @@ function ae() {
|
|
|
451
446
|
<iframe data-viceme="frame" title="" referrerpolicy="no-referrer" allow="payment"></iframe>
|
|
452
447
|
</section>
|
|
453
448
|
`;
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
const f =
|
|
449
|
+
const c = r.querySelector("[data-viceme='panel']");
|
|
450
|
+
c.dataset.action = this.interaction.action, c.dataset.frame = "false";
|
|
451
|
+
const N = r.querySelector("[data-viceme='description']");
|
|
452
|
+
N.textContent = i.description;
|
|
453
|
+
const f = r.querySelector("[data-viceme='action']"), O = f.parentElement, A = r.querySelector("[data-viceme='close']"), L = r.querySelector("[data-viceme='backdrop']"), T = r.querySelector("[data-viceme='error']"), I = r.querySelector("[data-viceme='frame']"), P = r.querySelector("[data-viceme='profile']"), n = r.querySelector("[data-viceme='avatar']"), o = r.querySelector("[data-viceme='avatar-fallback']"), u = r.querySelector("[data-viceme='profile-name']"), a = r.querySelector(
|
|
459
454
|
"[data-viceme='profile-description']"
|
|
460
|
-
),
|
|
461
|
-
f.textContent = i.label, f.hidden =
|
|
462
|
-
const
|
|
463
|
-
I.title = this.interaction.action === "SIGN_IN" ? "
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
466
|
-
|
|
455
|
+
), l = r.querySelector("[data-viceme='profile-stats']");
|
|
456
|
+
f.textContent = i.label, f.hidden = !1, O.dataset.single = "true";
|
|
457
|
+
const v = i.label;
|
|
458
|
+
I.title = this.interaction.action === "SIGN_IN" ? "登录授权" : "支付";
|
|
459
|
+
const d = this.interaction.followTarget;
|
|
460
|
+
if (d) {
|
|
461
|
+
c.setAttribute(
|
|
467
462
|
"aria-label",
|
|
468
|
-
this.interaction.action === "SIGN_IN" ? `授权 ${
|
|
469
|
-
),
|
|
470
|
-
const s = [...
|
|
471
|
-
|
|
472
|
-
p.remove();
|
|
473
|
-
else {
|
|
474
|
-
for (const [O, k] of u.coverUrls.entries()) {
|
|
475
|
-
const A = document.createElement("img");
|
|
476
|
-
A.dataset.viceme = "profile-cover", A.src = k, A.alt = `${u.displayName}的作品封面 ${O + 1}`, p.append(A);
|
|
477
|
-
}
|
|
478
|
-
p.dataset.visible = "true";
|
|
479
|
-
}
|
|
480
|
-
n.textContent = u.displayName.trim().slice(0, 1) || "V", u.avatarUrl && (r.src = u.avatarUrl, r.alt = `${u.displayName}的头像`, r.hidden = !1, n.hidden = !0);
|
|
463
|
+
this.interaction.action === "SIGN_IN" ? `授权 ${d.displayName}` : `关注 ${d.displayName}`
|
|
464
|
+
), P.dataset.visible = "true", u.textContent = d.displayName;
|
|
465
|
+
const s = [...d.description ?? ""];
|
|
466
|
+
a.textContent = s.length > U ? `${s.slice(0, U).join("")}…` : s.join(""), s.length > U && (a.title = d.description), l.textContent = `${d.workCount} 个作品`, o.textContent = d.displayName.trim().slice(0, 1) || "V", d.avatarUrl && (n.src = d.avatarUrl, n.alt = `${d.displayName}的头像`, n.hidden = !1, o.hidden = !0);
|
|
481
467
|
}
|
|
482
|
-
let
|
|
483
|
-
const
|
|
468
|
+
let p = null;
|
|
469
|
+
const E = (s) => {
|
|
484
470
|
this.dispatchEvent(new CustomEvent("viceme:access-layer-close", { detail: s }));
|
|
485
|
-
},
|
|
486
|
-
|
|
471
|
+
}, y = () => {
|
|
472
|
+
p?.cancel(), E("dismissed");
|
|
487
473
|
};
|
|
488
|
-
|
|
489
|
-
if (s.key === "Escape" &&
|
|
490
|
-
if (s.preventDefault(),
|
|
474
|
+
L.addEventListener("click", y), A.addEventListener("click", y), this.addEventListener("keydown", (s) => {
|
|
475
|
+
if (s.key === "Escape" && y(), s.key === "Tab") {
|
|
476
|
+
if (s.preventDefault(), p?.type === "frame") {
|
|
491
477
|
I.focus();
|
|
492
478
|
return;
|
|
493
479
|
}
|
|
494
|
-
const
|
|
495
|
-
if (
|
|
496
|
-
const
|
|
497
|
-
|
|
480
|
+
const m = [A, ...f.hidden ? [] : [f]].filter((_) => !_.disabled && !_.hidden);
|
|
481
|
+
if (m.length === 0) return;
|
|
482
|
+
const D = m.indexOf(r.activeElement), g = s.shiftKey ? -1 : 1;
|
|
483
|
+
m[(D + g + m.length) % m.length]?.focus();
|
|
498
484
|
}
|
|
499
485
|
});
|
|
500
|
-
const
|
|
501
|
-
f.disabled = !0, f.setAttribute("aria-busy", "true"), f.textContent = "正在打开…",
|
|
486
|
+
const S = async () => {
|
|
487
|
+
f.disabled = !0, f.setAttribute("aria-busy", "true"), f.textContent = "正在打开…", T.textContent = "";
|
|
502
488
|
try {
|
|
503
489
|
const s = await this.interaction.perform();
|
|
504
|
-
|
|
505
|
-
if (w = s, this.interaction.action === "SIGN_IN") {
|
|
506
|
-
const O = l.getBoundingClientRect().height;
|
|
507
|
-
O > 0 && (l.style.height = `${O}px`);
|
|
508
|
-
}
|
|
509
|
-
l.dataset.frame = "true", I.src = s.url, I.focus(), await s.completion;
|
|
510
|
-
}
|
|
511
|
-
D("acted");
|
|
490
|
+
s.type === "frame" ? (p = s, c.dataset.frame = "true", I.src = s.url, I.focus(), await s.completion) : s.type === "external" && (p = s, await s.completion), E("acted");
|
|
512
491
|
} catch (s) {
|
|
513
|
-
|
|
492
|
+
p?.cancel(), p = null, c.dataset.frame = "false", I.removeAttribute("src"), T.textContent = ee(s), f.hidden = !1, f.disabled = !1, f.removeAttribute("aria-busy"), f.textContent = v, f.focus();
|
|
514
493
|
}
|
|
515
494
|
};
|
|
516
|
-
f.addEventListener("click",
|
|
517
|
-
g();
|
|
518
|
-
}) : queueMicrotask(() => f.focus());
|
|
495
|
+
f.addEventListener("click", S), queueMicrotask(() => f.focus());
|
|
519
496
|
}
|
|
520
497
|
}
|
|
521
|
-
customElements.define(
|
|
498
|
+
customElements.define(M, t);
|
|
522
499
|
}
|
|
523
|
-
const
|
|
500
|
+
const K = async (t) => {
|
|
524
501
|
if (typeof document > "u" || typeof customElements > "u")
|
|
525
502
|
return "dismissed";
|
|
526
|
-
|
|
527
|
-
const e = document.createElement(
|
|
503
|
+
te();
|
|
504
|
+
const e = document.createElement(M);
|
|
528
505
|
e.interaction = t;
|
|
529
|
-
const i = document.documentElement.style.overflow,
|
|
506
|
+
const i = document.documentElement.style.overflow, r = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
530
507
|
document.documentElement.style.overflow = "hidden", document.body.append(e);
|
|
531
508
|
try {
|
|
532
|
-
return await new Promise((
|
|
509
|
+
return await new Promise((c) => {
|
|
533
510
|
e.addEventListener(
|
|
534
511
|
"viceme:access-layer-close",
|
|
535
|
-
(
|
|
512
|
+
(N) => c(N.detail),
|
|
536
513
|
{ once: !0 }
|
|
537
514
|
);
|
|
538
515
|
});
|
|
539
516
|
} finally {
|
|
540
|
-
e.remove(), document.documentElement.style.overflow = i,
|
|
517
|
+
e.remove(), document.documentElement.style.overflow = i, r?.focus();
|
|
541
518
|
}
|
|
542
519
|
};
|
|
543
|
-
function
|
|
544
|
-
if (typeof t != "object" || t === null) throw
|
|
520
|
+
function k(t) {
|
|
521
|
+
if (typeof t != "object" || t === null) throw h();
|
|
545
522
|
return t;
|
|
546
523
|
}
|
|
547
|
-
function
|
|
524
|
+
function h() {
|
|
548
525
|
return new b({
|
|
549
526
|
code: "INTERNAL_ERROR",
|
|
550
527
|
message: "Malformed public API response.",
|
|
551
528
|
retryable: !0
|
|
552
529
|
});
|
|
553
530
|
}
|
|
554
|
-
function
|
|
555
|
-
const e =
|
|
556
|
-
if (typeof e.
|
|
557
|
-
throw
|
|
531
|
+
function ie(t) {
|
|
532
|
+
const e = k(t);
|
|
533
|
+
if (typeof e.id != "string" || !(typeof e.displayName == "string" || e.displayName === null) || !(typeof e.avatarUrl == "string" || e.avatarUrl === null))
|
|
534
|
+
throw h();
|
|
558
535
|
return {
|
|
559
|
-
subject: e.
|
|
560
|
-
nickname: e.
|
|
536
|
+
subject: e.id,
|
|
537
|
+
nickname: e.displayName,
|
|
561
538
|
avatarUrl: e.avatarUrl
|
|
562
539
|
};
|
|
563
540
|
}
|
|
564
|
-
function
|
|
565
|
-
const e =
|
|
541
|
+
function F(t) {
|
|
542
|
+
const e = k(t);
|
|
566
543
|
if (typeof e.following != "boolean" || !(typeof e.followedAt == "string" || e.followedAt === null))
|
|
567
|
-
throw
|
|
568
|
-
const i =
|
|
569
|
-
if (
|
|
570
|
-
throw
|
|
544
|
+
throw h();
|
|
545
|
+
const i = k(e.creator);
|
|
546
|
+
if (typeof i.displayName != "string" || !(typeof i.avatarUrl == "string" || i.avatarUrl === null) || !(typeof i.description == "string" || i.description === null) || !Number.isInteger(i.publishedWorkCount) || i.publishedWorkCount < 0)
|
|
547
|
+
throw h();
|
|
571
548
|
return {
|
|
572
549
|
following: e.following,
|
|
573
550
|
followedAt: e.followedAt,
|
|
574
551
|
target: {
|
|
575
|
-
kind:
|
|
552
|
+
kind: "CREATOR",
|
|
576
553
|
displayName: i.displayName,
|
|
577
554
|
avatarUrl: i.avatarUrl,
|
|
578
555
|
description: i.description,
|
|
579
|
-
workCount: i.
|
|
580
|
-
coverUrls: i.coverUrls
|
|
556
|
+
workCount: i.publishedWorkCount
|
|
581
557
|
}
|
|
582
558
|
};
|
|
583
559
|
}
|
|
584
|
-
function
|
|
585
|
-
const e =
|
|
560
|
+
function re(t) {
|
|
561
|
+
const e = k(t), i = /* @__PURE__ */ new Set([
|
|
562
|
+
"PUBLIC",
|
|
586
563
|
"OWNER",
|
|
587
564
|
"FOLLOWING",
|
|
588
|
-
"PURCHASED",
|
|
589
565
|
"ENTITLED",
|
|
590
566
|
"AUTH_REQUIRED",
|
|
591
567
|
"FOLLOW_REQUIRED",
|
|
592
568
|
"PURCHASE_REQUIRED",
|
|
593
569
|
"FEATURE_NOT_FOUND",
|
|
594
|
-
"FEATURE_DISABLED"
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
throw m();
|
|
570
|
+
"FEATURE_DISABLED"
|
|
571
|
+
]), r = /* @__PURE__ */ new Set([null, "SIGN_IN", "FOLLOW", "CHECKOUT"]);
|
|
572
|
+
if (typeof e.allowed != "boolean" || typeof e.reason != "string" || !i.has(e.reason) || !r.has(e.nextAction))
|
|
573
|
+
throw h();
|
|
599
574
|
return {
|
|
600
575
|
allowed: e.allowed,
|
|
601
576
|
reason: e.reason,
|
|
602
577
|
nextAction: e.nextAction
|
|
603
578
|
};
|
|
604
579
|
}
|
|
605
|
-
function
|
|
606
|
-
const e =
|
|
607
|
-
if (typeof e.featureKey != "string" || !/^[a-z][a-z0-9_-]{1,63}$/.test(e.featureKey) || typeof e.title != "string" || e.title.trim().length === 0 || e.title.length > 120 || !(
|
|
608
|
-
throw
|
|
609
|
-
const
|
|
610
|
-
if (
|
|
611
|
-
throw
|
|
580
|
+
function ae(t) {
|
|
581
|
+
const e = k(t);
|
|
582
|
+
if (typeof e.featureKey != "string" || !/^[a-z][a-z0-9_-]{1,63}$/.test(e.featureKey) || typeof e.title != "string" || e.title.trim().length === 0 || e.title.length > 120 || !(e.policyType === "PUBLIC" || e.policyType === "FOLLOW_OWNER" || e.policyType === "WORK_ENTITLEMENT"))
|
|
583
|
+
throw h();
|
|
584
|
+
const i = e.price === null ? null : k(e.price);
|
|
585
|
+
if (i !== null && (!Number.isInteger(i.amountCents) || i.amountCents <= 0 || i.currency !== "CNY") || e.policyType === "WORK_ENTITLEMENT" != (i !== null))
|
|
586
|
+
throw h();
|
|
612
587
|
return {
|
|
613
588
|
featureKey: e.featureKey,
|
|
614
589
|
title: e.title,
|
|
615
|
-
policy: { type:
|
|
616
|
-
price:
|
|
590
|
+
policy: { type: e.policyType },
|
|
591
|
+
price: i === null ? null : { amountCents: i.amountCents, currency: "CNY" }
|
|
617
592
|
};
|
|
618
593
|
}
|
|
619
|
-
function
|
|
620
|
-
if (typeof t != "string") throw m();
|
|
621
|
-
try {
|
|
622
|
-
const e = new URL(t).origin;
|
|
623
|
-
if (e !== t) throw m();
|
|
624
|
-
return e;
|
|
625
|
-
} catch (e) {
|
|
626
|
-
throw e instanceof b ? e : m();
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
function j() {
|
|
594
|
+
function ne() {
|
|
630
595
|
const t = crypto.getRandomValues(new Uint8Array(32));
|
|
631
|
-
return
|
|
596
|
+
return oe(t);
|
|
632
597
|
}
|
|
633
|
-
function
|
|
598
|
+
function oe(t) {
|
|
634
599
|
let e = "";
|
|
635
600
|
for (const i of t) e += String.fromCharCode(i);
|
|
636
601
|
return btoa(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
637
602
|
}
|
|
638
|
-
function
|
|
603
|
+
function se() {
|
|
639
604
|
return typeof document < "u" && document.documentElement.lang.toLowerCase() === "en-us" ? "en-US" : "zh-CN";
|
|
640
605
|
}
|
|
641
|
-
function
|
|
642
|
-
const e =
|
|
643
|
-
const o = h(
|
|
644
|
-
(await t.session.request({
|
|
645
|
-
method: "POST",
|
|
646
|
-
path: "/v1/public/v1/auth/exchange",
|
|
647
|
-
body: { code: r, codeVerifier: n }
|
|
648
|
-
})).body
|
|
649
|
-
);
|
|
650
|
-
if (typeof o.token != "string" || typeof o.expiresAt != "number")
|
|
651
|
-
throw m();
|
|
652
|
-
const d = re(o.user);
|
|
653
|
-
return t.session.authenticate({ token: o.token, expiresAt: o.expiresAt, user: d }), { authenticated: !0, user: d };
|
|
654
|
-
}, i = () => new b({
|
|
606
|
+
function ce(t) {
|
|
607
|
+
const e = () => new b({
|
|
655
608
|
code: "AUTH_CANCELLED",
|
|
656
609
|
message: "The interactive action was cancelled.",
|
|
657
610
|
retryable: !1
|
|
658
|
-
}),
|
|
611
|
+
}), i = (n, o, u, a, l, v) => {
|
|
659
612
|
if (typeof window > "u")
|
|
660
613
|
throw new b({
|
|
661
614
|
code: "CONFIG_INVALID",
|
|
662
615
|
message: "Interactive access requires a browser window.",
|
|
663
616
|
retryable: !1
|
|
664
617
|
});
|
|
665
|
-
let
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
},
|
|
669
|
-
|
|
670
|
-
}),
|
|
671
|
-
if (!
|
|
672
|
-
const
|
|
673
|
-
if (!(
|
|
674
|
-
if (
|
|
675
|
-
w
|
|
618
|
+
let d = !0, p, E;
|
|
619
|
+
const y = () => {
|
|
620
|
+
d && (d = !1, window.removeEventListener("message", s));
|
|
621
|
+
}, S = new Promise((w, m) => {
|
|
622
|
+
p = w, E = m;
|
|
623
|
+
}), s = (w) => {
|
|
624
|
+
if (!d || w.origin !== o || typeof w.data != "object" || w.data === null) return;
|
|
625
|
+
const m = w.data;
|
|
626
|
+
if (!(m.workKey !== t.workKey || m.channel !== u)) {
|
|
627
|
+
if (m.type === `viceme:${a}:ready`) {
|
|
628
|
+
w.source && "postMessage" in w.source && w.source.postMessage(
|
|
629
|
+
{
|
|
630
|
+
type: `viceme:${a}:init`,
|
|
631
|
+
workKey: t.workKey,
|
|
632
|
+
channel: u,
|
|
633
|
+
...l
|
|
634
|
+
},
|
|
635
|
+
o
|
|
636
|
+
);
|
|
676
637
|
return;
|
|
677
638
|
}
|
|
678
|
-
|
|
639
|
+
if (m.type === `viceme:${a}:cancelled`) {
|
|
640
|
+
y(), E(e());
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
m.type === `viceme:${a}:complete` && (y(), v(m).then(p, E));
|
|
679
644
|
}
|
|
680
645
|
};
|
|
681
|
-
return window.addEventListener("message",
|
|
646
|
+
return window.addEventListener("message", s), {
|
|
682
647
|
type: "frame",
|
|
683
|
-
url:
|
|
684
|
-
completion:
|
|
648
|
+
url: n,
|
|
649
|
+
completion: S,
|
|
685
650
|
cancel() {
|
|
686
|
-
|
|
651
|
+
y(), p();
|
|
687
652
|
}
|
|
688
653
|
};
|
|
689
|
-
},
|
|
690
|
-
await t.ready()
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
654
|
+
}, r = async () => {
|
|
655
|
+
if (await t.ready(), typeof window > "u")
|
|
656
|
+
throw new b({
|
|
657
|
+
code: "CONFIG_INVALID",
|
|
658
|
+
message: "Interactive access requires a browser window.",
|
|
659
|
+
retryable: !1
|
|
660
|
+
});
|
|
661
|
+
const n = ne(), o = new URL("/sdk/login", t.widgetOrigin);
|
|
662
|
+
o.search = new URLSearchParams({
|
|
663
|
+
workKey: t.workKey,
|
|
664
|
+
channel: n,
|
|
665
|
+
parentOrigin: window.location.origin,
|
|
666
|
+
locale: se()
|
|
667
|
+
}).toString();
|
|
668
|
+
const u = t.session.snapshot?.token;
|
|
669
|
+
if (!u) throw h();
|
|
670
|
+
return i(
|
|
671
|
+
o.toString(),
|
|
672
|
+
t.widgetOrigin,
|
|
705
673
|
n,
|
|
706
674
|
"auth",
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
675
|
+
{ workSessionToken: u },
|
|
676
|
+
async (a) => {
|
|
677
|
+
if (typeof a.userToken != "string")
|
|
678
|
+
throw h();
|
|
679
|
+
t.session.authenticate({ userToken: a.userToken, user: ie(a.user) });
|
|
711
680
|
}
|
|
712
681
|
);
|
|
713
|
-
},
|
|
714
|
-
(await t.session.request({ method: "GET", path: "/v1/public/
|
|
715
|
-
)),
|
|
716
|
-
(await t.session.request({ method:
|
|
717
|
-
)),
|
|
682
|
+
}, c = async () => (await t.ready(), F(
|
|
683
|
+
(await t.session.request({ method: "GET", path: "/v1/public/work-sdk/follow" })).body
|
|
684
|
+
)), N = async () => (await t.ready(), F(
|
|
685
|
+
(await t.session.request({ method: "PUT", path: "/v1/public/work-sdk/follow" })).body
|
|
686
|
+
)), f = {
|
|
718
687
|
async getState() {
|
|
719
688
|
await t.ready();
|
|
720
|
-
const
|
|
721
|
-
return { authenticated:
|
|
689
|
+
const n = t.session.snapshot?.user ?? null;
|
|
690
|
+
return { authenticated: n !== null, user: n };
|
|
722
691
|
},
|
|
723
692
|
async signIn() {
|
|
724
|
-
|
|
725
|
-
if (await r({
|
|
693
|
+
if (await (t.presenter ?? K)({
|
|
726
694
|
featureKey: "auth",
|
|
727
695
|
reason: "AUTH_REQUIRED",
|
|
728
696
|
action: "SIGN_IN",
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
await f("PUT");
|
|
732
|
-
})
|
|
733
|
-
}) === "dismissed") throw i();
|
|
697
|
+
perform: r
|
|
698
|
+
}) === "dismissed") throw e();
|
|
734
699
|
return this.getState();
|
|
735
700
|
},
|
|
736
701
|
async signOut() {
|
|
737
702
|
await t.ready(), await t.session.signOut();
|
|
738
703
|
}
|
|
739
|
-
},
|
|
740
|
-
getState:
|
|
741
|
-
follow:
|
|
742
|
-
unfollow: () =>
|
|
743
|
-
|
|
704
|
+
}, O = {
|
|
705
|
+
getState: c,
|
|
706
|
+
follow: N,
|
|
707
|
+
unfollow: async () => {
|
|
708
|
+
throw new b({
|
|
709
|
+
code: "CAPABILITY_DISABLED",
|
|
710
|
+
message: "Unfollow is not exposed by website access.",
|
|
711
|
+
retryable: !1
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
}, A = async (n) => {
|
|
744
715
|
await t.ready();
|
|
745
|
-
const
|
|
716
|
+
const o = k(
|
|
746
717
|
(await t.session.request({
|
|
747
718
|
method: "POST",
|
|
748
|
-
path: "/v1/public/
|
|
749
|
-
body: { featureKeys:
|
|
719
|
+
path: "/v1/public/work-sdk/access/check",
|
|
720
|
+
body: { featureKeys: n }
|
|
750
721
|
})).body
|
|
751
|
-
),
|
|
722
|
+
), u = k(o.decisions);
|
|
752
723
|
return Object.fromEntries(
|
|
753
|
-
Object.entries(
|
|
724
|
+
Object.entries(u).map(([a, l]) => [a, re(l)])
|
|
754
725
|
);
|
|
755
|
-
},
|
|
726
|
+
}, L = async (n, o = {}) => {
|
|
756
727
|
await t.ready();
|
|
757
|
-
const
|
|
758
|
-
featureKey:
|
|
759
|
-
locale:
|
|
760
|
-
|
|
761
|
-
}, c = h(
|
|
728
|
+
const u = {
|
|
729
|
+
featureKey: n,
|
|
730
|
+
locale: o.locale ?? "zh-CN"
|
|
731
|
+
}, a = k(
|
|
762
732
|
(await t.session.request({
|
|
763
733
|
method: "POST",
|
|
764
|
-
path: "/v1/public/
|
|
765
|
-
body:
|
|
734
|
+
path: "/v1/public/work-sdk/checkout",
|
|
735
|
+
body: u
|
|
766
736
|
})).body
|
|
767
737
|
);
|
|
768
|
-
if (typeof
|
|
769
|
-
throw
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
}
|
|
738
|
+
if (typeof a.checkoutUrl != "string" || typeof a.alreadyOwned != "boolean" || !(a.expiresAt === null || typeof a.expiresAt == "string" && !Number.isNaN(Date.parse(a.expiresAt))) || a.alreadyOwned !== (a.expiresAt === null))
|
|
739
|
+
throw h();
|
|
740
|
+
let l;
|
|
741
|
+
try {
|
|
742
|
+
l = new URL(a.checkoutUrl);
|
|
743
|
+
} catch {
|
|
744
|
+
throw h();
|
|
745
|
+
}
|
|
746
|
+
if (!a.alreadyOwned && (l.protocol !== "https:" || l.origin !== t.widgetOrigin))
|
|
747
|
+
throw h();
|
|
774
748
|
return {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
749
|
+
checkoutUrl: a.checkoutUrl,
|
|
750
|
+
alreadyOwned: a.alreadyOwned,
|
|
751
|
+
expiresAt: a.expiresAt
|
|
752
|
+
};
|
|
753
|
+
}, T = (n, o) => {
|
|
754
|
+
if (n.alreadyOwned) return { type: "completed" };
|
|
755
|
+
const u = Date.parse(n.expiresAt);
|
|
756
|
+
if (typeof window > "u")
|
|
757
|
+
throw new b({
|
|
758
|
+
code: "CONFIG_INVALID",
|
|
759
|
+
message: "Hosted checkout requires a browser window.",
|
|
760
|
+
retryable: !1
|
|
761
|
+
});
|
|
762
|
+
let a = !0, l, v, d, p;
|
|
763
|
+
const E = new Promise((g, _) => {
|
|
764
|
+
d = g, p = _;
|
|
765
|
+
}), y = () => {
|
|
766
|
+
l && clearTimeout(l), v && clearTimeout(v), document.removeEventListener("visibilitychange", m);
|
|
767
|
+
}, S = () => {
|
|
768
|
+
a && (a = !1, y(), p(
|
|
769
|
+
new b({
|
|
770
|
+
code: "SESSION_EXPIRED",
|
|
771
|
+
message: "Hosted checkout session expired.",
|
|
772
|
+
retryable: !0
|
|
773
|
+
})
|
|
774
|
+
));
|
|
775
|
+
}, s = () => {
|
|
776
|
+
if (!a || document.visibilityState === "hidden") return;
|
|
777
|
+
const g = u - t.now();
|
|
778
|
+
if (g <= 0) {
|
|
779
|
+
S();
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
l = setTimeout(() => {
|
|
783
|
+
w();
|
|
784
|
+
}, Math.min(1500, g));
|
|
785
|
+
}, w = async () => {
|
|
786
|
+
if (a)
|
|
787
|
+
try {
|
|
788
|
+
const g = (await A([o]))[o];
|
|
789
|
+
if (!g) throw h();
|
|
790
|
+
if (g.allowed) {
|
|
791
|
+
a = !1, y(), d();
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
s();
|
|
795
|
+
} catch (g) {
|
|
796
|
+
a = !1, y(), p(g);
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
function m() {
|
|
800
|
+
if (a) {
|
|
801
|
+
if (document.visibilityState === "hidden") {
|
|
802
|
+
l && clearTimeout(l), l = void 0;
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
s();
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
document.addEventListener("visibilitychange", m);
|
|
809
|
+
const D = u - t.now();
|
|
810
|
+
return D <= 0 ? S() : (v = setTimeout(S, D), s()), {
|
|
811
|
+
type: "frame",
|
|
812
|
+
url: n.checkoutUrl,
|
|
813
|
+
completion: E,
|
|
814
|
+
cancel() {
|
|
815
|
+
a && (a = !1, y(), d());
|
|
816
|
+
}
|
|
778
817
|
};
|
|
779
818
|
};
|
|
780
|
-
return { auth:
|
|
819
|
+
return { auth: f, follow: O, access: {
|
|
781
820
|
async getFeatures() {
|
|
782
821
|
await t.ready();
|
|
783
|
-
const
|
|
784
|
-
(await t.session.request({
|
|
822
|
+
const n = k(
|
|
823
|
+
(await t.session.request({
|
|
824
|
+
method: "GET",
|
|
825
|
+
path: "/v1/public/work-sdk/access/features"
|
|
826
|
+
})).body
|
|
785
827
|
);
|
|
786
|
-
if (!Array.isArray(
|
|
787
|
-
throw
|
|
788
|
-
return
|
|
828
|
+
if (!Array.isArray(n.features) || n.features.length > 100)
|
|
829
|
+
throw h();
|
|
830
|
+
return n.features.map(ae);
|
|
789
831
|
},
|
|
790
|
-
async check(
|
|
791
|
-
const
|
|
792
|
-
if (!
|
|
793
|
-
return
|
|
832
|
+
async check(n) {
|
|
833
|
+
const u = (await A([n]))[n];
|
|
834
|
+
if (!u) throw h();
|
|
835
|
+
return u;
|
|
794
836
|
},
|
|
795
|
-
checkMany:
|
|
796
|
-
async require(
|
|
797
|
-
let
|
|
798
|
-
const
|
|
799
|
-
for (let
|
|
800
|
-
const
|
|
801
|
-
if (
|
|
802
|
-
|
|
837
|
+
checkMany: A,
|
|
838
|
+
async require(n) {
|
|
839
|
+
let o = await this.check(n);
|
|
840
|
+
const u = t.presenter ?? K;
|
|
841
|
+
for (let a = 0; !o.allowed && o.nextAction && a < 3; a += 1) {
|
|
842
|
+
const l = o.nextAction, v = l === "FOLLOW" ? (await O.getState()).target : void 0, d = l === "CHECKOUT" ? await L(n) : void 0;
|
|
843
|
+
if (d?.alreadyOwned) {
|
|
844
|
+
o = await this.check(n);
|
|
803
845
|
continue;
|
|
804
846
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
}) : (await N(r)).action
|
|
814
|
-
}) === "dismissed") return n;
|
|
815
|
-
n = await this.check(r);
|
|
847
|
+
if (await u({
|
|
848
|
+
featureKey: n,
|
|
849
|
+
reason: o.reason,
|
|
850
|
+
action: l,
|
|
851
|
+
...v ? { followTarget: v } : {},
|
|
852
|
+
perform: async () => l === "SIGN_IN" ? r() : l === "FOLLOW" ? (await O.follow(), { type: "completed" }) : T(d, n)
|
|
853
|
+
}) === "dismissed") return o;
|
|
854
|
+
o = await this.check(n);
|
|
816
855
|
}
|
|
817
|
-
return
|
|
856
|
+
return o;
|
|
818
857
|
},
|
|
819
858
|
async refresh() {
|
|
820
859
|
await t.ready();
|
|
821
860
|
}
|
|
822
861
|
}, checkout: {
|
|
823
|
-
async open(
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
if (await
|
|
827
|
-
featureKey:
|
|
862
|
+
async open(n) {
|
|
863
|
+
const o = await L(n.featureKey, n);
|
|
864
|
+
if (o.alreadyOwned) return o;
|
|
865
|
+
if (await (t.presenter ?? K)({
|
|
866
|
+
featureKey: n.featureKey,
|
|
828
867
|
reason: "PURCHASE_REQUIRED",
|
|
829
868
|
action: "CHECKOUT",
|
|
830
|
-
perform: async () =>
|
|
831
|
-
|
|
832
|
-
return o = c.result, c.action;
|
|
833
|
-
}
|
|
834
|
-
}) === "dismissed" || !o) throw i();
|
|
869
|
+
perform: async () => T(o, n.featureKey)
|
|
870
|
+
}) === "dismissed") throw e();
|
|
835
871
|
return o;
|
|
836
872
|
}
|
|
837
873
|
} };
|
|
838
874
|
}
|
|
839
|
-
class
|
|
875
|
+
class le extends DOMException {
|
|
840
876
|
constructor() {
|
|
841
877
|
super("ViceMe client destroyed.", "AbortError");
|
|
842
878
|
}
|
|
843
879
|
}
|
|
844
|
-
class
|
|
845
|
-
#e = new
|
|
880
|
+
class pe {
|
|
881
|
+
#e = new Q();
|
|
846
882
|
#t;
|
|
847
883
|
#i;
|
|
848
|
-
#
|
|
849
|
-
#
|
|
884
|
+
#r = new AbortController();
|
|
885
|
+
#a;
|
|
850
886
|
auth;
|
|
851
887
|
access;
|
|
852
888
|
checkout;
|
|
853
889
|
/** Detaches the caller-signal listener; undefined when none was attached. */
|
|
854
890
|
#n;
|
|
855
891
|
constructor(e) {
|
|
856
|
-
this.#i = e.config, this.#t = new
|
|
892
|
+
this.#i = e.config, this.#t = new J({
|
|
857
893
|
workKey: e.config.workKey,
|
|
858
894
|
transport: e.transport,
|
|
859
|
-
signal: this.#
|
|
895
|
+
signal: this.#r.signal,
|
|
860
896
|
...e.now !== void 0 ? { now: e.now } : {}
|
|
861
897
|
});
|
|
862
|
-
const i =
|
|
898
|
+
const i = ce({
|
|
863
899
|
session: this.#t,
|
|
864
900
|
workKey: e.config.workKey,
|
|
901
|
+
widgetOrigin: z[e.config.region],
|
|
902
|
+
now: e.now ?? (() => Date.now()),
|
|
865
903
|
presenter: e.presenter,
|
|
866
|
-
ready: () => this
|
|
904
|
+
ready: () => this.#o()
|
|
867
905
|
});
|
|
868
906
|
this.auth = i.auth, this.access = i.access, this.checkout = i.checkout;
|
|
869
|
-
const
|
|
870
|
-
if (
|
|
871
|
-
const
|
|
872
|
-
this.#
|
|
873
|
-
|
|
907
|
+
const r = e.config.signal;
|
|
908
|
+
if (r) {
|
|
909
|
+
const c = () => {
|
|
910
|
+
this.#r.abort(
|
|
911
|
+
r.reason instanceof Error ? r.reason : new DOMException("Caller signal aborted.", "AbortError")
|
|
874
912
|
);
|
|
875
913
|
};
|
|
876
|
-
|
|
877
|
-
|
|
914
|
+
r.aborted ? c() : (r.addEventListener("abort", c, { once: !0 }), this.#n = () => {
|
|
915
|
+
r.removeEventListener("abort", c);
|
|
878
916
|
});
|
|
879
917
|
}
|
|
880
918
|
}
|
|
881
919
|
get version() {
|
|
882
|
-
return
|
|
920
|
+
return H;
|
|
883
921
|
}
|
|
884
922
|
get workKey() {
|
|
885
923
|
return this.#i.workKey;
|
|
@@ -892,25 +930,24 @@ class he {
|
|
|
892
930
|
}
|
|
893
931
|
/** Internal: public API major, used by the loader registry namespace. */
|
|
894
932
|
get apiMajor() {
|
|
895
|
-
return
|
|
933
|
+
return V;
|
|
896
934
|
}
|
|
897
935
|
ready() {
|
|
898
|
-
return this.#e.destroyed ? Promise.reject(
|
|
936
|
+
return this.#e.destroyed ? Promise.reject(x()) : (this.#a || (this.#e.transition("READY"), this.#a = Promise.resolve()), this.#a);
|
|
899
937
|
}
|
|
900
938
|
async #o() {
|
|
901
|
-
if (this.#e.destroyed) throw
|
|
902
|
-
this
|
|
939
|
+
if (this.#e.destroyed) throw x();
|
|
940
|
+
await this.ready();
|
|
903
941
|
try {
|
|
904
|
-
if (await this.#t.establish(), this.#e.destroyed) throw
|
|
905
|
-
this.#e.transition("READY");
|
|
942
|
+
if (await this.#t.establish(), this.#e.destroyed) throw x();
|
|
906
943
|
} catch (e) {
|
|
907
|
-
throw this.#e.destroyed ?
|
|
944
|
+
throw this.#e.destroyed ? x() : (this.#t.invalidate(), e);
|
|
908
945
|
}
|
|
909
946
|
}
|
|
910
947
|
hasCapability(e) {
|
|
911
948
|
if (this.#e.destroyed) return !1;
|
|
912
949
|
const i = this.#t.snapshot?.work.capabilities;
|
|
913
|
-
return
|
|
950
|
+
return e === "danmaku" || e === "tip" || i?.includes(e) === !0;
|
|
914
951
|
}
|
|
915
952
|
/** Names of capabilities enabled for this work (empty before `ready()`). */
|
|
916
953
|
get capabilities() {
|
|
@@ -928,14 +965,14 @@ class he {
|
|
|
928
965
|
return this.#t.snapshot;
|
|
929
966
|
}
|
|
930
967
|
destroy() {
|
|
931
|
-
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#
|
|
968
|
+
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#r.abort(new le()), this.#t.destroy(), this.#e.clearListeners(), this.#a = void 0, this.#n?.(), this.#n = void 0);
|
|
932
969
|
}
|
|
933
970
|
}
|
|
934
971
|
export {
|
|
935
|
-
|
|
936
|
-
|
|
972
|
+
pe as V,
|
|
973
|
+
Y as a,
|
|
937
974
|
B as i,
|
|
938
|
-
|
|
939
|
-
|
|
975
|
+
me as r,
|
|
976
|
+
he as v
|
|
940
977
|
};
|
|
941
|
-
//# sourceMappingURL=client-
|
|
978
|
+
//# sourceMappingURL=client-w9vih8Ng.js.map
|