@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
|
@@ -1,31 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 = {
|
|
5
|
+
cn: q.cn,
|
|
6
|
+
global: q.global
|
|
6
7
|
};
|
|
7
|
-
function
|
|
8
|
+
function me(t) {
|
|
8
9
|
return j[t];
|
|
9
10
|
}
|
|
10
11
|
function B(t) {
|
|
11
|
-
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);
|
|
12
13
|
}
|
|
13
14
|
function Y(t) {
|
|
14
|
-
return typeof t == "string" &&
|
|
15
|
+
return typeof t == "string" && W.has(t);
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function he(t) {
|
|
17
18
|
if (typeof t != "object" || t === null)
|
|
18
|
-
throw
|
|
19
|
+
throw C("createViceMe expects a configuration object.");
|
|
19
20
|
const e = t, i = /* @__PURE__ */ new Set(["workKey", "region", "signal"]);
|
|
20
|
-
for (const
|
|
21
|
-
if (!i.has(
|
|
22
|
-
throw
|
|
21
|
+
for (const r of Object.keys(e))
|
|
22
|
+
if (!i.has(r))
|
|
23
|
+
throw C(`Unknown configuration field "${r}".`);
|
|
23
24
|
if (!B(e.workKey))
|
|
24
|
-
throw
|
|
25
|
+
throw C(
|
|
26
|
+
'Configuration field "workKey" must start with "wrk_test_" or "wrk_live_".'
|
|
27
|
+
);
|
|
25
28
|
if (!Y(e.region))
|
|
26
|
-
throw
|
|
29
|
+
throw C('Configuration field "region" must be "cn" or "global".');
|
|
27
30
|
if (e.signal !== void 0 && !(e.signal instanceof AbortSignal))
|
|
28
|
-
throw
|
|
31
|
+
throw C('Configuration field "signal" must be an AbortSignal.');
|
|
29
32
|
return {
|
|
30
33
|
workKey: e.workKey,
|
|
31
34
|
region: e.region,
|
|
@@ -50,7 +53,7 @@ class Q {
|
|
|
50
53
|
transition(e) {
|
|
51
54
|
if (e !== this.#e) {
|
|
52
55
|
if (!$[this.#e].includes(e))
|
|
53
|
-
throw new
|
|
56
|
+
throw new b({
|
|
54
57
|
code: "INTERNAL_ERROR",
|
|
55
58
|
message: `Illegal lifecycle transition ${this.#e} -> ${e}.`,
|
|
56
59
|
retryable: !1
|
|
@@ -61,7 +64,7 @@ class Q {
|
|
|
61
64
|
}
|
|
62
65
|
/** Any operation on a destroyed client must fail closed with this guard. */
|
|
63
66
|
assertAlive() {
|
|
64
|
-
if (this.destroyed) throw
|
|
67
|
+
if (this.destroyed) throw x();
|
|
65
68
|
}
|
|
66
69
|
subscribe(e) {
|
|
67
70
|
return this.#t.add(e), () => {
|
|
@@ -79,25 +82,25 @@ function X(t, e) {
|
|
|
79
82
|
if (typeof i.workKey != "string" || !Array.isArray(i.capabilities) || !i.capabilities.every((c) => typeof c == "string"))
|
|
80
83
|
throw R();
|
|
81
84
|
if (i.workKey !== e)
|
|
82
|
-
throw new
|
|
85
|
+
throw new b({
|
|
83
86
|
code: "WORK_NOT_FOUND",
|
|
84
87
|
message: "Work-session response did not match the requested work key.",
|
|
85
88
|
retryable: !1
|
|
86
89
|
});
|
|
87
|
-
const
|
|
90
|
+
const r = {
|
|
88
91
|
work: {
|
|
89
92
|
key: i.workKey,
|
|
90
93
|
capabilities: i.capabilities
|
|
91
94
|
}
|
|
92
95
|
};
|
|
93
|
-
if (typeof i.token == "string" && (
|
|
96
|
+
if (typeof i.token == "string" && (r.token = i.token), typeof i.expiresAt == "string") {
|
|
94
97
|
const c = new Date(i.expiresAt).getTime();
|
|
95
|
-
Number.isNaN(c) || (
|
|
98
|
+
Number.isNaN(c) || (r.expiresAt = c);
|
|
96
99
|
}
|
|
97
|
-
return
|
|
100
|
+
return r;
|
|
98
101
|
}
|
|
99
102
|
function R() {
|
|
100
|
-
return new
|
|
103
|
+
return new b({
|
|
101
104
|
code: "INTERNAL_ERROR",
|
|
102
105
|
message: "Malformed work-session response.",
|
|
103
106
|
retryable: !0
|
|
@@ -107,7 +110,7 @@ class J {
|
|
|
107
110
|
#e;
|
|
108
111
|
#t;
|
|
109
112
|
#i;
|
|
110
|
-
#
|
|
113
|
+
#r;
|
|
111
114
|
constructor(e) {
|
|
112
115
|
this.#e = e, this.#t = e.now ?? (() => Date.now());
|
|
113
116
|
}
|
|
@@ -115,7 +118,7 @@ class J {
|
|
|
115
118
|
return this.#i;
|
|
116
119
|
}
|
|
117
120
|
/** True when the cached snapshot's server-provided expiry has passed. */
|
|
118
|
-
#
|
|
121
|
+
#a() {
|
|
119
122
|
const e = this.#i?.expiresAt;
|
|
120
123
|
return e !== void 0 && e <= this.#t();
|
|
121
124
|
}
|
|
@@ -128,10 +131,10 @@ class J {
|
|
|
128
131
|
*/
|
|
129
132
|
establish() {
|
|
130
133
|
if (this.#i) {
|
|
131
|
-
if (!this.#
|
|
134
|
+
if (!this.#a()) return Promise.resolve(this.#i);
|
|
132
135
|
this.#i = void 0;
|
|
133
136
|
}
|
|
134
|
-
return this.#
|
|
137
|
+
return this.#r ??= this.#e.transport.request({
|
|
135
138
|
method: "POST",
|
|
136
139
|
path: "/v1/public/work-sdk/sessions",
|
|
137
140
|
body: { workKey: this.#e.workKey },
|
|
@@ -141,8 +144,8 @@ class J {
|
|
|
141
144
|
const i = X(e.body, this.#e.workKey);
|
|
142
145
|
return this.#i = i, i;
|
|
143
146
|
}).finally(() => {
|
|
144
|
-
this.#
|
|
145
|
-
}), this.#
|
|
147
|
+
this.#r = void 0;
|
|
148
|
+
}), this.#r;
|
|
146
149
|
}
|
|
147
150
|
async request(e) {
|
|
148
151
|
const i = await this.establish();
|
|
@@ -154,8 +157,8 @@ class J {
|
|
|
154
157
|
userAuthorization: i.userToken,
|
|
155
158
|
signal: this.#e.signal
|
|
156
159
|
});
|
|
157
|
-
} catch (
|
|
158
|
-
if (!(
|
|
160
|
+
} catch (r) {
|
|
161
|
+
if (!(r instanceof b) || r.code !== "SESSION_EXPIRED") throw r;
|
|
159
162
|
this.#i === i && this.invalidate();
|
|
160
163
|
const c = await this.establish();
|
|
161
164
|
if (!c.token) throw R();
|
|
@@ -184,10 +187,10 @@ class J {
|
|
|
184
187
|
}
|
|
185
188
|
/** Hard cleanup: forget the token and pending work. */
|
|
186
189
|
destroy() {
|
|
187
|
-
this.invalidate(), this.#
|
|
190
|
+
this.invalidate(), this.#r = void 0;
|
|
188
191
|
}
|
|
189
192
|
}
|
|
190
|
-
const
|
|
193
|
+
const M = "viceme-access-layer", U = 50;
|
|
191
194
|
function Z(t) {
|
|
192
195
|
switch (t) {
|
|
193
196
|
case "SIGN_IN":
|
|
@@ -223,12 +226,12 @@ function ee(t) {
|
|
|
223
226
|
}
|
|
224
227
|
}
|
|
225
228
|
function te() {
|
|
226
|
-
if (customElements.get(
|
|
229
|
+
if (customElements.get(M)) return;
|
|
227
230
|
class t extends HTMLElement {
|
|
228
231
|
interaction;
|
|
229
232
|
connectedCallback() {
|
|
230
|
-
const i = Z(this.interaction.action),
|
|
231
|
-
|
|
233
|
+
const i = Z(this.interaction.action), r = this.attachShadow({ mode: "open" });
|
|
234
|
+
r.innerHTML = `
|
|
232
235
|
<style>
|
|
233
236
|
:host {
|
|
234
237
|
position: fixed;
|
|
@@ -409,6 +412,9 @@ function te() {
|
|
|
409
412
|
}
|
|
410
413
|
[data-viceme='panel'][data-frame='true'] { width: min(30rem, 100%); }
|
|
411
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
|
+
}
|
|
412
418
|
}
|
|
413
419
|
@media (prefers-reduced-motion: no-preference) {
|
|
414
420
|
[data-viceme='panel'] { animation: viceme-enter 160ms ease-out; }
|
|
@@ -440,105 +446,105 @@ function te() {
|
|
|
440
446
|
<iframe data-viceme="frame" title="" referrerpolicy="no-referrer" allow="payment"></iframe>
|
|
441
447
|
</section>
|
|
442
448
|
`;
|
|
443
|
-
const c =
|
|
449
|
+
const c = r.querySelector("[data-viceme='panel']");
|
|
444
450
|
c.dataset.action = this.interaction.action, c.dataset.frame = "false";
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
const
|
|
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(
|
|
448
454
|
"[data-viceme='profile-description']"
|
|
449
|
-
),
|
|
450
|
-
|
|
451
|
-
const
|
|
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;
|
|
452
458
|
I.title = this.interaction.action === "SIGN_IN" ? "登录授权" : "支付";
|
|
453
459
|
const d = this.interaction.followTarget;
|
|
454
460
|
if (d) {
|
|
455
461
|
c.setAttribute(
|
|
456
462
|
"aria-label",
|
|
457
463
|
this.interaction.action === "SIGN_IN" ? `授权 ${d.displayName}` : `关注 ${d.displayName}`
|
|
458
|
-
),
|
|
464
|
+
), P.dataset.visible = "true", u.textContent = d.displayName;
|
|
459
465
|
const s = [...d.description ?? ""];
|
|
460
|
-
|
|
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);
|
|
461
467
|
}
|
|
462
|
-
let
|
|
463
|
-
const
|
|
468
|
+
let p = null;
|
|
469
|
+
const E = (s) => {
|
|
464
470
|
this.dispatchEvent(new CustomEvent("viceme:access-layer-close", { detail: s }));
|
|
465
|
-
},
|
|
466
|
-
|
|
471
|
+
}, y = () => {
|
|
472
|
+
p?.cancel(), E("dismissed");
|
|
467
473
|
};
|
|
468
|
-
L.addEventListener("click",
|
|
469
|
-
if (s.key === "Escape" &&
|
|
470
|
-
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") {
|
|
471
477
|
I.focus();
|
|
472
478
|
return;
|
|
473
479
|
}
|
|
474
|
-
const
|
|
475
|
-
if (
|
|
476
|
-
const
|
|
477
|
-
|
|
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();
|
|
478
484
|
}
|
|
479
485
|
});
|
|
480
|
-
const
|
|
481
|
-
|
|
486
|
+
const S = async () => {
|
|
487
|
+
f.disabled = !0, f.setAttribute("aria-busy", "true"), f.textContent = "正在打开…", T.textContent = "";
|
|
482
488
|
try {
|
|
483
489
|
const s = await this.interaction.perform();
|
|
484
|
-
s.type === "frame" ? (
|
|
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");
|
|
485
491
|
} catch (s) {
|
|
486
|
-
|
|
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();
|
|
487
493
|
}
|
|
488
494
|
};
|
|
489
|
-
|
|
495
|
+
f.addEventListener("click", S), queueMicrotask(() => f.focus());
|
|
490
496
|
}
|
|
491
497
|
}
|
|
492
|
-
customElements.define(
|
|
498
|
+
customElements.define(M, t);
|
|
493
499
|
}
|
|
494
|
-
const
|
|
500
|
+
const K = async (t) => {
|
|
495
501
|
if (typeof document > "u" || typeof customElements > "u")
|
|
496
502
|
return "dismissed";
|
|
497
503
|
te();
|
|
498
|
-
const e = document.createElement(
|
|
504
|
+
const e = document.createElement(M);
|
|
499
505
|
e.interaction = t;
|
|
500
|
-
const i = document.documentElement.style.overflow,
|
|
506
|
+
const i = document.documentElement.style.overflow, r = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
501
507
|
document.documentElement.style.overflow = "hidden", document.body.append(e);
|
|
502
508
|
try {
|
|
503
509
|
return await new Promise((c) => {
|
|
504
510
|
e.addEventListener(
|
|
505
511
|
"viceme:access-layer-close",
|
|
506
|
-
(
|
|
512
|
+
(N) => c(N.detail),
|
|
507
513
|
{ once: !0 }
|
|
508
514
|
);
|
|
509
515
|
});
|
|
510
516
|
} finally {
|
|
511
|
-
e.remove(), document.documentElement.style.overflow = i,
|
|
517
|
+
e.remove(), document.documentElement.style.overflow = i, r?.focus();
|
|
512
518
|
}
|
|
513
519
|
};
|
|
514
|
-
function
|
|
515
|
-
if (typeof t != "object" || t === null) throw
|
|
520
|
+
function k(t) {
|
|
521
|
+
if (typeof t != "object" || t === null) throw h();
|
|
516
522
|
return t;
|
|
517
523
|
}
|
|
518
|
-
function
|
|
519
|
-
return new
|
|
524
|
+
function h() {
|
|
525
|
+
return new b({
|
|
520
526
|
code: "INTERNAL_ERROR",
|
|
521
527
|
message: "Malformed public API response.",
|
|
522
528
|
retryable: !0
|
|
523
529
|
});
|
|
524
530
|
}
|
|
525
531
|
function ie(t) {
|
|
526
|
-
const e =
|
|
532
|
+
const e = k(t);
|
|
527
533
|
if (typeof e.id != "string" || !(typeof e.displayName == "string" || e.displayName === null) || !(typeof e.avatarUrl == "string" || e.avatarUrl === null))
|
|
528
|
-
throw
|
|
534
|
+
throw h();
|
|
529
535
|
return {
|
|
530
536
|
subject: e.id,
|
|
531
537
|
nickname: e.displayName,
|
|
532
538
|
avatarUrl: e.avatarUrl
|
|
533
539
|
};
|
|
534
540
|
}
|
|
535
|
-
function
|
|
536
|
-
const e =
|
|
541
|
+
function F(t) {
|
|
542
|
+
const e = k(t);
|
|
537
543
|
if (typeof e.following != "boolean" || !(typeof e.followedAt == "string" || e.followedAt === null))
|
|
538
|
-
throw
|
|
539
|
-
const i =
|
|
544
|
+
throw h();
|
|
545
|
+
const i = k(e.creator);
|
|
540
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)
|
|
541
|
-
throw
|
|
547
|
+
throw h();
|
|
542
548
|
return {
|
|
543
549
|
following: e.following,
|
|
544
550
|
followedAt: e.followedAt,
|
|
@@ -551,8 +557,8 @@ function P(t) {
|
|
|
551
557
|
}
|
|
552
558
|
};
|
|
553
559
|
}
|
|
554
|
-
function
|
|
555
|
-
const e =
|
|
560
|
+
function re(t) {
|
|
561
|
+
const e = k(t), i = /* @__PURE__ */ new Set([
|
|
556
562
|
"PUBLIC",
|
|
557
563
|
"OWNER",
|
|
558
564
|
"FOLLOWING",
|
|
@@ -562,22 +568,22 @@ function ae(t) {
|
|
|
562
568
|
"PURCHASE_REQUIRED",
|
|
563
569
|
"FEATURE_NOT_FOUND",
|
|
564
570
|
"FEATURE_DISABLED"
|
|
565
|
-
]),
|
|
566
|
-
if (typeof e.allowed != "boolean" || typeof e.reason != "string" || !i.has(e.reason) || !
|
|
567
|
-
throw
|
|
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();
|
|
568
574
|
return {
|
|
569
575
|
allowed: e.allowed,
|
|
570
576
|
reason: e.reason,
|
|
571
577
|
nextAction: e.nextAction
|
|
572
578
|
};
|
|
573
579
|
}
|
|
574
|
-
function
|
|
575
|
-
const e =
|
|
580
|
+
function ae(t) {
|
|
581
|
+
const e = k(t);
|
|
576
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"))
|
|
577
|
-
throw
|
|
578
|
-
const i = e.price === null ? null :
|
|
583
|
+
throw h();
|
|
584
|
+
const i = e.price === null ? null : k(e.price);
|
|
579
585
|
if (i !== null && (!Number.isInteger(i.amountCents) || i.amountCents <= 0 || i.currency !== "CNY") || e.policyType === "WORK_ENTITLEMENT" != (i !== null))
|
|
580
|
-
throw
|
|
586
|
+
throw h();
|
|
581
587
|
return {
|
|
582
588
|
featureKey: e.featureKey,
|
|
583
589
|
title: e.title,
|
|
@@ -585,11 +591,11 @@ function re(t) {
|
|
|
585
591
|
price: i === null ? null : { amountCents: i.amountCents, currency: "CNY" }
|
|
586
592
|
};
|
|
587
593
|
}
|
|
588
|
-
function
|
|
594
|
+
function ne() {
|
|
589
595
|
const t = crypto.getRandomValues(new Uint8Array(32));
|
|
590
|
-
return
|
|
596
|
+
return oe(t);
|
|
591
597
|
}
|
|
592
|
-
function
|
|
598
|
+
function oe(t) {
|
|
593
599
|
let e = "";
|
|
594
600
|
for (const i of t) e += String.fromCharCode(i);
|
|
595
601
|
return btoa(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
@@ -598,232 +604,254 @@ function se() {
|
|
|
598
604
|
return typeof document < "u" && document.documentElement.lang.toLowerCase() === "en-us" ? "en-US" : "zh-CN";
|
|
599
605
|
}
|
|
600
606
|
function ce(t) {
|
|
601
|
-
const e = () => new
|
|
607
|
+
const e = () => new b({
|
|
602
608
|
code: "AUTH_CANCELLED",
|
|
603
609
|
message: "The interactive action was cancelled.",
|
|
604
610
|
retryable: !1
|
|
605
|
-
}), i = (
|
|
611
|
+
}), i = (n, o, u, a, l, v) => {
|
|
606
612
|
if (typeof window > "u")
|
|
607
|
-
throw new
|
|
613
|
+
throw new b({
|
|
608
614
|
code: "CONFIG_INVALID",
|
|
609
615
|
message: "Interactive access requires a browser window.",
|
|
610
616
|
retryable: !1
|
|
611
617
|
});
|
|
612
|
-
let d = !0,
|
|
613
|
-
const
|
|
618
|
+
let d = !0, p, E;
|
|
619
|
+
const y = () => {
|
|
614
620
|
d && (d = !1, window.removeEventListener("message", s));
|
|
615
|
-
},
|
|
616
|
-
|
|
617
|
-
}), s = (
|
|
618
|
-
if (!d ||
|
|
619
|
-
const
|
|
620
|
-
if (!(
|
|
621
|
-
if (
|
|
622
|
-
|
|
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(
|
|
623
629
|
{
|
|
624
|
-
type: `viceme:${
|
|
630
|
+
type: `viceme:${a}:init`,
|
|
625
631
|
workKey: t.workKey,
|
|
626
|
-
channel:
|
|
627
|
-
...
|
|
632
|
+
channel: u,
|
|
633
|
+
...l
|
|
628
634
|
},
|
|
629
635
|
o
|
|
630
636
|
);
|
|
631
637
|
return;
|
|
632
638
|
}
|
|
633
|
-
if (
|
|
634
|
-
|
|
639
|
+
if (m.type === `viceme:${a}:cancelled`) {
|
|
640
|
+
y(), E(e());
|
|
635
641
|
return;
|
|
636
642
|
}
|
|
637
|
-
|
|
643
|
+
m.type === `viceme:${a}:complete` && (y(), v(m).then(p, E));
|
|
638
644
|
}
|
|
639
645
|
};
|
|
640
646
|
return window.addEventListener("message", s), {
|
|
641
647
|
type: "frame",
|
|
642
|
-
url:
|
|
643
|
-
completion:
|
|
648
|
+
url: n,
|
|
649
|
+
completion: S,
|
|
644
650
|
cancel() {
|
|
645
|
-
|
|
651
|
+
y(), p();
|
|
646
652
|
}
|
|
647
653
|
};
|
|
648
|
-
},
|
|
654
|
+
}, r = async () => {
|
|
649
655
|
if (await t.ready(), typeof window > "u")
|
|
650
|
-
throw new
|
|
656
|
+
throw new b({
|
|
651
657
|
code: "CONFIG_INVALID",
|
|
652
658
|
message: "Interactive access requires a browser window.",
|
|
653
659
|
retryable: !1
|
|
654
660
|
});
|
|
655
|
-
const
|
|
661
|
+
const n = ne(), o = new URL("/sdk/login", t.widgetOrigin);
|
|
656
662
|
o.search = new URLSearchParams({
|
|
657
663
|
workKey: t.workKey,
|
|
658
|
-
channel:
|
|
664
|
+
channel: n,
|
|
659
665
|
parentOrigin: window.location.origin,
|
|
660
666
|
locale: se()
|
|
661
667
|
}).toString();
|
|
662
|
-
const
|
|
663
|
-
if (!
|
|
668
|
+
const u = t.session.snapshot?.token;
|
|
669
|
+
if (!u) throw h();
|
|
664
670
|
return i(
|
|
665
671
|
o.toString(),
|
|
666
672
|
t.widgetOrigin,
|
|
667
|
-
|
|
673
|
+
n,
|
|
668
674
|
"auth",
|
|
669
|
-
{ workSessionToken:
|
|
670
|
-
async (
|
|
671
|
-
if (typeof
|
|
672
|
-
throw
|
|
673
|
-
t.session.authenticate({ userToken:
|
|
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) });
|
|
674
680
|
}
|
|
675
681
|
);
|
|
676
|
-
}, c = async () => (await t.ready(),
|
|
682
|
+
}, c = async () => (await t.ready(), F(
|
|
677
683
|
(await t.session.request({ method: "GET", path: "/v1/public/work-sdk/follow" })).body
|
|
678
|
-
)),
|
|
684
|
+
)), N = async () => (await t.ready(), F(
|
|
679
685
|
(await t.session.request({ method: "PUT", path: "/v1/public/work-sdk/follow" })).body
|
|
680
|
-
)),
|
|
686
|
+
)), f = {
|
|
681
687
|
async getState() {
|
|
682
688
|
await t.ready();
|
|
683
|
-
const
|
|
684
|
-
return { authenticated:
|
|
689
|
+
const n = t.session.snapshot?.user ?? null;
|
|
690
|
+
return { authenticated: n !== null, user: n };
|
|
685
691
|
},
|
|
686
692
|
async signIn() {
|
|
687
|
-
if (await (t.presenter ??
|
|
693
|
+
if (await (t.presenter ?? K)({
|
|
688
694
|
featureKey: "auth",
|
|
689
695
|
reason: "AUTH_REQUIRED",
|
|
690
696
|
action: "SIGN_IN",
|
|
691
|
-
perform:
|
|
697
|
+
perform: r
|
|
692
698
|
}) === "dismissed") throw e();
|
|
693
699
|
return this.getState();
|
|
694
700
|
},
|
|
695
701
|
async signOut() {
|
|
696
702
|
await t.ready(), await t.session.signOut();
|
|
697
703
|
}
|
|
698
|
-
},
|
|
704
|
+
}, O = {
|
|
699
705
|
getState: c,
|
|
700
|
-
follow:
|
|
706
|
+
follow: N,
|
|
701
707
|
unfollow: async () => {
|
|
702
|
-
throw new
|
|
708
|
+
throw new b({
|
|
703
709
|
code: "CAPABILITY_DISABLED",
|
|
704
710
|
message: "Unfollow is not exposed by website access.",
|
|
705
711
|
retryable: !1
|
|
706
712
|
});
|
|
707
713
|
}
|
|
708
|
-
},
|
|
714
|
+
}, A = async (n) => {
|
|
709
715
|
await t.ready();
|
|
710
|
-
const o =
|
|
716
|
+
const o = k(
|
|
711
717
|
(await t.session.request({
|
|
712
718
|
method: "POST",
|
|
713
719
|
path: "/v1/public/work-sdk/access/check",
|
|
714
|
-
body: { featureKeys:
|
|
720
|
+
body: { featureKeys: n }
|
|
715
721
|
})).body
|
|
716
|
-
),
|
|
722
|
+
), u = k(o.decisions);
|
|
717
723
|
return Object.fromEntries(
|
|
718
|
-
Object.entries(
|
|
724
|
+
Object.entries(u).map(([a, l]) => [a, re(l)])
|
|
719
725
|
);
|
|
720
|
-
}, L = async (
|
|
726
|
+
}, L = async (n, o = {}) => {
|
|
721
727
|
await t.ready();
|
|
722
|
-
const
|
|
723
|
-
featureKey:
|
|
728
|
+
const u = {
|
|
729
|
+
featureKey: n,
|
|
724
730
|
locale: o.locale ?? "zh-CN"
|
|
725
|
-
},
|
|
731
|
+
}, a = k(
|
|
726
732
|
(await t.session.request({
|
|
727
733
|
method: "POST",
|
|
728
734
|
path: "/v1/public/work-sdk/checkout",
|
|
729
|
-
body:
|
|
735
|
+
body: u
|
|
730
736
|
})).body
|
|
731
737
|
);
|
|
732
|
-
if (typeof
|
|
733
|
-
throw
|
|
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;
|
|
734
741
|
try {
|
|
735
|
-
new URL(
|
|
742
|
+
l = new URL(a.checkoutUrl);
|
|
736
743
|
} catch {
|
|
737
|
-
throw
|
|
744
|
+
throw h();
|
|
738
745
|
}
|
|
746
|
+
if (!a.alreadyOwned && (l.protocol !== "https:" || l.origin !== t.widgetOrigin))
|
|
747
|
+
throw h();
|
|
739
748
|
return {
|
|
740
|
-
checkoutUrl:
|
|
741
|
-
alreadyOwned:
|
|
749
|
+
checkoutUrl: a.checkoutUrl,
|
|
750
|
+
alreadyOwned: a.alreadyOwned,
|
|
751
|
+
expiresAt: a.expiresAt
|
|
742
752
|
};
|
|
743
|
-
},
|
|
744
|
-
if (
|
|
753
|
+
}, T = (n, o) => {
|
|
754
|
+
if (n.alreadyOwned) return { type: "completed" };
|
|
755
|
+
const u = Date.parse(n.expiresAt);
|
|
745
756
|
if (typeof window > "u")
|
|
746
|
-
throw new
|
|
757
|
+
throw new b({
|
|
747
758
|
code: "CONFIG_INVALID",
|
|
748
759
|
message: "Hosted checkout requires a browser window.",
|
|
749
760
|
retryable: !1
|
|
750
761
|
});
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
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)
|
|
763
787
|
try {
|
|
764
|
-
const
|
|
765
|
-
if (!
|
|
766
|
-
if (
|
|
767
|
-
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
770
|
-
if (l.closed) {
|
|
771
|
-
n = !1, d(e());
|
|
788
|
+
const g = (await A([o]))[o];
|
|
789
|
+
if (!g) throw h();
|
|
790
|
+
if (g.allowed) {
|
|
791
|
+
a = !1, y(), d();
|
|
772
792
|
return;
|
|
773
793
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
} catch (h) {
|
|
778
|
-
n = !1, d(h);
|
|
794
|
+
s();
|
|
795
|
+
} catch (g) {
|
|
796
|
+
a = !1, y(), p(g);
|
|
779
797
|
}
|
|
780
798
|
};
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
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,
|
|
786
814
|
cancel() {
|
|
787
|
-
|
|
815
|
+
a && (a = !1, y(), d());
|
|
788
816
|
}
|
|
789
817
|
};
|
|
790
818
|
};
|
|
791
|
-
return { auth:
|
|
819
|
+
return { auth: f, follow: O, access: {
|
|
792
820
|
async getFeatures() {
|
|
793
821
|
await t.ready();
|
|
794
|
-
const
|
|
822
|
+
const n = k(
|
|
795
823
|
(await t.session.request({
|
|
796
824
|
method: "GET",
|
|
797
825
|
path: "/v1/public/work-sdk/access/features"
|
|
798
826
|
})).body
|
|
799
827
|
);
|
|
800
|
-
if (!Array.isArray(
|
|
801
|
-
throw
|
|
802
|
-
return
|
|
828
|
+
if (!Array.isArray(n.features) || n.features.length > 100)
|
|
829
|
+
throw h();
|
|
830
|
+
return n.features.map(ae);
|
|
803
831
|
},
|
|
804
|
-
async check(
|
|
805
|
-
const
|
|
806
|
-
if (!
|
|
807
|
-
return
|
|
832
|
+
async check(n) {
|
|
833
|
+
const u = (await A([n]))[n];
|
|
834
|
+
if (!u) throw h();
|
|
835
|
+
return u;
|
|
808
836
|
},
|
|
809
|
-
checkMany:
|
|
810
|
-
async require(
|
|
811
|
-
let o = await this.check(
|
|
812
|
-
const
|
|
813
|
-
for (let
|
|
814
|
-
const
|
|
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;
|
|
815
843
|
if (d?.alreadyOwned) {
|
|
816
|
-
o = await this.check(
|
|
844
|
+
o = await this.check(n);
|
|
817
845
|
continue;
|
|
818
846
|
}
|
|
819
|
-
if (await
|
|
820
|
-
featureKey:
|
|
847
|
+
if (await u({
|
|
848
|
+
featureKey: n,
|
|
821
849
|
reason: o.reason,
|
|
822
|
-
action:
|
|
823
|
-
...
|
|
824
|
-
perform: async () =>
|
|
850
|
+
action: l,
|
|
851
|
+
...v ? { followTarget: v } : {},
|
|
852
|
+
perform: async () => l === "SIGN_IN" ? r() : l === "FOLLOW" ? (await O.follow(), { type: "completed" }) : T(d, n)
|
|
825
853
|
}) === "dismissed") return o;
|
|
826
|
-
o = await this.check(
|
|
854
|
+
o = await this.check(n);
|
|
827
855
|
}
|
|
828
856
|
return o;
|
|
829
857
|
},
|
|
@@ -831,14 +859,14 @@ function ce(t) {
|
|
|
831
859
|
await t.ready();
|
|
832
860
|
}
|
|
833
861
|
}, checkout: {
|
|
834
|
-
async open(
|
|
835
|
-
const o = await L(
|
|
862
|
+
async open(n) {
|
|
863
|
+
const o = await L(n.featureKey, n);
|
|
836
864
|
if (o.alreadyOwned) return o;
|
|
837
|
-
if (await (t.presenter ??
|
|
838
|
-
featureKey:
|
|
865
|
+
if (await (t.presenter ?? K)({
|
|
866
|
+
featureKey: n.featureKey,
|
|
839
867
|
reason: "PURCHASE_REQUIRED",
|
|
840
868
|
action: "CHECKOUT",
|
|
841
|
-
perform: async () =>
|
|
869
|
+
perform: async () => T(o, n.featureKey)
|
|
842
870
|
}) === "dismissed") throw e();
|
|
843
871
|
return o;
|
|
844
872
|
}
|
|
@@ -849,46 +877,47 @@ class le extends DOMException {
|
|
|
849
877
|
super("ViceMe client destroyed.", "AbortError");
|
|
850
878
|
}
|
|
851
879
|
}
|
|
852
|
-
class
|
|
880
|
+
class pe {
|
|
853
881
|
#e = new Q();
|
|
854
882
|
#t;
|
|
855
883
|
#i;
|
|
856
|
-
#
|
|
857
|
-
#
|
|
884
|
+
#r = new AbortController();
|
|
885
|
+
#a;
|
|
858
886
|
auth;
|
|
859
887
|
access;
|
|
860
888
|
checkout;
|
|
861
889
|
/** Detaches the caller-signal listener; undefined when none was attached. */
|
|
862
|
-
#
|
|
890
|
+
#n;
|
|
863
891
|
constructor(e) {
|
|
864
892
|
this.#i = e.config, this.#t = new J({
|
|
865
893
|
workKey: e.config.workKey,
|
|
866
894
|
transport: e.transport,
|
|
867
|
-
signal: this.#
|
|
895
|
+
signal: this.#r.signal,
|
|
868
896
|
...e.now !== void 0 ? { now: e.now } : {}
|
|
869
897
|
});
|
|
870
898
|
const i = ce({
|
|
871
899
|
session: this.#t,
|
|
872
900
|
workKey: e.config.workKey,
|
|
873
|
-
widgetOrigin:
|
|
901
|
+
widgetOrigin: z[e.config.region],
|
|
902
|
+
now: e.now ?? (() => Date.now()),
|
|
874
903
|
presenter: e.presenter,
|
|
875
|
-
ready: () => this.#
|
|
904
|
+
ready: () => this.#o()
|
|
876
905
|
});
|
|
877
906
|
this.auth = i.auth, this.access = i.access, this.checkout = i.checkout;
|
|
878
|
-
const
|
|
879
|
-
if (
|
|
907
|
+
const r = e.config.signal;
|
|
908
|
+
if (r) {
|
|
880
909
|
const c = () => {
|
|
881
|
-
this.#
|
|
882
|
-
|
|
910
|
+
this.#r.abort(
|
|
911
|
+
r.reason instanceof Error ? r.reason : new DOMException("Caller signal aborted.", "AbortError")
|
|
883
912
|
);
|
|
884
913
|
};
|
|
885
|
-
|
|
886
|
-
|
|
914
|
+
r.aborted ? c() : (r.addEventListener("abort", c, { once: !0 }), this.#n = () => {
|
|
915
|
+
r.removeEventListener("abort", c);
|
|
887
916
|
});
|
|
888
917
|
}
|
|
889
918
|
}
|
|
890
919
|
get version() {
|
|
891
|
-
return
|
|
920
|
+
return H;
|
|
892
921
|
}
|
|
893
922
|
get workKey() {
|
|
894
923
|
return this.#i.workKey;
|
|
@@ -901,18 +930,18 @@ class he {
|
|
|
901
930
|
}
|
|
902
931
|
/** Internal: public API major, used by the loader registry namespace. */
|
|
903
932
|
get apiMajor() {
|
|
904
|
-
return
|
|
933
|
+
return V;
|
|
905
934
|
}
|
|
906
935
|
ready() {
|
|
907
|
-
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);
|
|
908
937
|
}
|
|
909
|
-
async #
|
|
910
|
-
if (this.#e.destroyed) throw
|
|
938
|
+
async #o() {
|
|
939
|
+
if (this.#e.destroyed) throw x();
|
|
911
940
|
await this.ready();
|
|
912
941
|
try {
|
|
913
|
-
if (await this.#t.establish(), this.#e.destroyed) throw
|
|
942
|
+
if (await this.#t.establish(), this.#e.destroyed) throw x();
|
|
914
943
|
} catch (e) {
|
|
915
|
-
throw this.#e.destroyed ?
|
|
944
|
+
throw this.#e.destroyed ? x() : (this.#t.invalidate(), e);
|
|
916
945
|
}
|
|
917
946
|
}
|
|
918
947
|
hasCapability(e) {
|
|
@@ -936,14 +965,14 @@ class he {
|
|
|
936
965
|
return this.#t.snapshot;
|
|
937
966
|
}
|
|
938
967
|
destroy() {
|
|
939
|
-
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);
|
|
940
969
|
}
|
|
941
970
|
}
|
|
942
971
|
export {
|
|
943
|
-
|
|
972
|
+
pe as V,
|
|
944
973
|
Y as a,
|
|
945
974
|
B as i,
|
|
946
|
-
|
|
947
|
-
|
|
975
|
+
me as r,
|
|
976
|
+
he as v
|
|
948
977
|
};
|
|
949
|
-
//# sourceMappingURL=client-
|
|
978
|
+
//# sourceMappingURL=client-w9vih8Ng.js.map
|