@viceme-ai/sdk 0.4.0 → 0.6.2
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 +116 -17
- 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-DEg6YouY.js} +350 -272
- package/dist/chunks/client-DEg6YouY.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-BJiUVcir.js +6 -0
- package/dist/chunks/{version-C8DeBm39.js.map → version-BJiUVcir.js.map} +1 -1
- package/dist/core/capabilities.d.ts +3 -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 +2 -0
- 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/loader/auto-loader.d.ts.map +1 -1
- package/dist/manifest.json +50 -38
- package/dist/session/session.d.ts.map +1 -1
- 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 L, V as b, c as v, i as G } from "./errors-C7DfLKcF.js";
|
|
2
|
+
import { a as q, B as j } from "./build-endpoints-NrDmg6jf.js";
|
|
3
|
+
import { S as W, A as H } from "./version-BJiUVcir.js";
|
|
4
|
+
const V = /* @__PURE__ */ new Set(["cn", "global"]), z = {
|
|
5
|
+
cn: q.cn,
|
|
6
|
+
global: q.global
|
|
6
7
|
};
|
|
7
|
-
function
|
|
8
|
-
return
|
|
8
|
+
function pe(t) {
|
|
9
|
+
return z[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
15
|
return typeof t == "string" && V.has(t);
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function ye(t) {
|
|
17
18
|
if (typeof t != "object" || t === null)
|
|
18
|
-
throw
|
|
19
|
+
throw L("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 L(`Unknown configuration field "${r}".`);
|
|
23
24
|
if (!B(e.workKey))
|
|
24
|
-
throw
|
|
25
|
+
throw L(
|
|
26
|
+
'Configuration field "workKey" must start with "wrk_test_" or "wrk_live_".'
|
|
27
|
+
);
|
|
25
28
|
if (!Y(e.region))
|
|
26
|
-
throw
|
|
29
|
+
throw L('Configuration field "region" must be "cn" or "global".');
|
|
27
30
|
if (e.signal !== void 0 && !(e.signal instanceof AbortSignal))
|
|
28
|
-
throw
|
|
31
|
+
throw L('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 v();
|
|
65
68
|
}
|
|
66
69
|
subscribe(e) {
|
|
67
70
|
return this.#t.add(e), () => {
|
|
@@ -79,35 +82,44 @@ 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
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
|
-
|
|
109
|
+
function J() {
|
|
110
|
+
return new b({
|
|
111
|
+
code: "SESSION_EXPIRED",
|
|
112
|
+
message: "The work session was invalidated before it completed.",
|
|
113
|
+
retryable: !0
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
class Z {
|
|
107
117
|
#e;
|
|
108
118
|
#t;
|
|
109
119
|
#i;
|
|
110
|
-
#
|
|
120
|
+
#r;
|
|
121
|
+
#n = 0;
|
|
122
|
+
#a = !1;
|
|
111
123
|
constructor(e) {
|
|
112
124
|
this.#e = e, this.#t = e.now ?? (() => Date.now());
|
|
113
125
|
}
|
|
@@ -115,7 +127,7 @@ class J {
|
|
|
115
127
|
return this.#i;
|
|
116
128
|
}
|
|
117
129
|
/** True when the cached snapshot's server-provided expiry has passed. */
|
|
118
|
-
#
|
|
130
|
+
#s() {
|
|
119
131
|
const e = this.#i?.expiresAt;
|
|
120
132
|
return e !== void 0 && e <= this.#t();
|
|
121
133
|
}
|
|
@@ -127,48 +139,43 @@ class J {
|
|
|
127
139
|
* in-flight request (single flight).
|
|
128
140
|
*/
|
|
129
141
|
establish() {
|
|
142
|
+
if (this.#a) return Promise.reject(v());
|
|
130
143
|
if (this.#i) {
|
|
131
|
-
if (!this.#
|
|
144
|
+
if (!this.#s()) return Promise.resolve(this.#i);
|
|
132
145
|
this.#i = void 0;
|
|
133
146
|
}
|
|
134
|
-
|
|
147
|
+
if (this.#r) return this.#r;
|
|
148
|
+
const e = this.#n, i = this.#e.transport.request({
|
|
135
149
|
method: "POST",
|
|
136
150
|
path: "/v1/public/work-sdk/sessions",
|
|
137
151
|
body: { workKey: this.#e.workKey },
|
|
138
152
|
signal: this.#e.signal,
|
|
139
153
|
timeoutMs: this.#e.timeoutMs
|
|
140
|
-
}).then((
|
|
141
|
-
|
|
142
|
-
|
|
154
|
+
}).then((r) => {
|
|
155
|
+
this.#c(e);
|
|
156
|
+
const c = X(r.body, this.#e.workKey);
|
|
157
|
+
return this.#c(e), this.#i = c, c;
|
|
143
158
|
}).finally(() => {
|
|
144
|
-
this.#
|
|
145
|
-
})
|
|
159
|
+
this.#r === i && (this.#r = void 0);
|
|
160
|
+
});
|
|
161
|
+
return this.#r = i, i;
|
|
146
162
|
}
|
|
147
163
|
async request(e) {
|
|
148
164
|
const i = await this.establish();
|
|
149
165
|
if (!i.token) throw R();
|
|
150
166
|
try {
|
|
151
|
-
return await this.#e
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
signal: this.#e.signal
|
|
156
|
-
});
|
|
157
|
-
} catch (a) {
|
|
158
|
-
if (!(a instanceof w) || a.code !== "SESSION_EXPIRED") throw a;
|
|
167
|
+
return await this.#l(e, i);
|
|
168
|
+
} catch (r) {
|
|
169
|
+
if (this.#a) throw v();
|
|
170
|
+
if (!(r instanceof b) || r.code !== "SESSION_EXPIRED") throw r;
|
|
159
171
|
this.#i === i && this.invalidate();
|
|
160
172
|
const c = await this.establish();
|
|
161
173
|
if (!c.token) throw R();
|
|
162
|
-
return this.#e
|
|
163
|
-
...e,
|
|
164
|
-
authorization: c.token,
|
|
165
|
-
userAuthorization: c.userToken,
|
|
166
|
-
signal: this.#e.signal
|
|
167
|
-
});
|
|
174
|
+
return this.#l(e, c);
|
|
168
175
|
}
|
|
169
176
|
}
|
|
170
177
|
authenticate(e) {
|
|
171
|
-
if (!this.#i) throw R();
|
|
178
|
+
if (this.#o(), !this.#i) throw R();
|
|
172
179
|
this.#i = {
|
|
173
180
|
...this.#i,
|
|
174
181
|
userToken: e.userToken,
|
|
@@ -176,19 +183,39 @@ class J {
|
|
|
176
183
|
};
|
|
177
184
|
}
|
|
178
185
|
async signOut() {
|
|
179
|
-
this.invalidate(), await this.establish();
|
|
186
|
+
this.#o(), this.invalidate(), await this.establish();
|
|
180
187
|
}
|
|
181
188
|
/** Drop the token; next `establish()` re-authenticates. */
|
|
182
189
|
invalidate() {
|
|
183
|
-
this.#i = void 0;
|
|
190
|
+
this.#n += 1, this.#i = void 0, this.#r = void 0;
|
|
184
191
|
}
|
|
185
192
|
/** Hard cleanup: forget the token and pending work. */
|
|
186
193
|
destroy() {
|
|
187
|
-
this
|
|
194
|
+
this.#a || (this.#a = !0, this.#n += 1, this.#i = void 0, this.#r = void 0);
|
|
195
|
+
}
|
|
196
|
+
#o() {
|
|
197
|
+
if (this.#a) throw v();
|
|
198
|
+
}
|
|
199
|
+
#c(e) {
|
|
200
|
+
if (this.#o(), e !== this.#n) throw J();
|
|
201
|
+
}
|
|
202
|
+
async #l(e, i) {
|
|
203
|
+
this.#o();
|
|
204
|
+
try {
|
|
205
|
+
const r = await this.#e.transport.request({
|
|
206
|
+
...e,
|
|
207
|
+
authorization: i.token,
|
|
208
|
+
userAuthorization: i.userToken,
|
|
209
|
+
signal: this.#e.signal
|
|
210
|
+
});
|
|
211
|
+
return this.#o(), r;
|
|
212
|
+
} catch (r) {
|
|
213
|
+
throw this.#a ? v() : r;
|
|
214
|
+
}
|
|
188
215
|
}
|
|
189
216
|
}
|
|
190
|
-
const
|
|
191
|
-
function
|
|
217
|
+
const K = "viceme-access-layer", P = 50;
|
|
218
|
+
function ee(t) {
|
|
192
219
|
switch (t) {
|
|
193
220
|
case "SIGN_IN":
|
|
194
221
|
return {
|
|
@@ -207,7 +234,7 @@ function Z(t) {
|
|
|
207
234
|
};
|
|
208
235
|
}
|
|
209
236
|
}
|
|
210
|
-
function
|
|
237
|
+
function te(t) {
|
|
211
238
|
if (!G(t)) return "操作未完成,请重试。";
|
|
212
239
|
switch (t.code) {
|
|
213
240
|
case "CONFIG_INVALID":
|
|
@@ -222,13 +249,13 @@ function ee(t) {
|
|
|
222
249
|
return t.requestId ? `操作未完成,请重试。请求 ID:${t.requestId}` : "操作未完成,请重试。";
|
|
223
250
|
}
|
|
224
251
|
}
|
|
225
|
-
function
|
|
226
|
-
if (customElements.get(
|
|
252
|
+
function ie() {
|
|
253
|
+
if (customElements.get(K)) return;
|
|
227
254
|
class t extends HTMLElement {
|
|
228
255
|
interaction;
|
|
229
256
|
connectedCallback() {
|
|
230
|
-
const i =
|
|
231
|
-
|
|
257
|
+
const i = ee(this.interaction.action), r = this.attachShadow({ mode: "open" });
|
|
258
|
+
r.innerHTML = `
|
|
232
259
|
<style>
|
|
233
260
|
:host {
|
|
234
261
|
position: fixed;
|
|
@@ -409,6 +436,9 @@ function te() {
|
|
|
409
436
|
}
|
|
410
437
|
[data-viceme='panel'][data-frame='true'] { width: min(30rem, 100%); }
|
|
411
438
|
[data-viceme='panel'][data-action='SIGN_IN'] { width: min(30rem, 100%); }
|
|
439
|
+
[data-viceme='panel'][data-action='CHECKOUT'][data-frame='true'] {
|
|
440
|
+
width: min(42rem, 100%);
|
|
441
|
+
}
|
|
412
442
|
}
|
|
413
443
|
@media (prefers-reduced-motion: no-preference) {
|
|
414
444
|
[data-viceme='panel'] { animation: viceme-enter 160ms ease-out; }
|
|
@@ -440,105 +470,109 @@ function te() {
|
|
|
440
470
|
<iframe data-viceme="frame" title="" referrerpolicy="no-referrer" allow="payment"></iframe>
|
|
441
471
|
</section>
|
|
442
472
|
`;
|
|
443
|
-
const c =
|
|
473
|
+
const c = r.querySelector("[data-viceme='panel']");
|
|
444
474
|
c.dataset.action = this.interaction.action, c.dataset.frame = "false";
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
const
|
|
475
|
+
const O = r.querySelector("[data-viceme='description']");
|
|
476
|
+
O.textContent = i.description;
|
|
477
|
+
const f = r.querySelector("[data-viceme='action']"), U = f.parentElement, N = r.querySelector("[data-viceme='close']"), T = r.querySelector("[data-viceme='backdrop']"), C = r.querySelector("[data-viceme='error']"), S = r.querySelector("[data-viceme='frame']"), M = r.querySelector("[data-viceme='profile']"), x = r.querySelector("[data-viceme='avatar']"), n = r.querySelector("[data-viceme='avatar-fallback']"), o = r.querySelector("[data-viceme='profile-name']"), l = r.querySelector(
|
|
448
478
|
"[data-viceme='profile-description']"
|
|
449
|
-
),
|
|
450
|
-
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
if (
|
|
479
|
+
), a = r.querySelector("[data-viceme='profile-stats']");
|
|
480
|
+
f.textContent = i.label, f.hidden = !1, U.dataset.single = "true";
|
|
481
|
+
const d = i.label;
|
|
482
|
+
S.title = this.interaction.action === "SIGN_IN" ? "登录授权" : "支付";
|
|
483
|
+
const u = this.interaction.followTarget;
|
|
484
|
+
if (u) {
|
|
455
485
|
c.setAttribute(
|
|
456
486
|
"aria-label",
|
|
457
|
-
this.interaction.action === "SIGN_IN" ? `授权 ${
|
|
458
|
-
),
|
|
459
|
-
const s = [...
|
|
460
|
-
|
|
487
|
+
this.interaction.action === "SIGN_IN" ? `授权 ${u.displayName}` : `关注 ${u.displayName}`
|
|
488
|
+
), M.dataset.visible = "true", o.textContent = u.displayName;
|
|
489
|
+
const s = [...u.description ?? ""];
|
|
490
|
+
l.textContent = s.length > P ? `${s.slice(0, P).join("")}…` : s.join(""), s.length > P && (l.title = u.description), a.textContent = `${u.workCount} 个作品`, n.textContent = u.displayName.trim().slice(0, 1) || "V", u.avatarUrl && (x.src = u.avatarUrl, x.alt = `${u.displayName}的头像`, x.hidden = !1, n.hidden = !0);
|
|
461
491
|
}
|
|
462
|
-
let
|
|
463
|
-
const
|
|
464
|
-
this.dispatchEvent(new CustomEvent("viceme:access-layer-close", { detail: s }));
|
|
465
|
-
},
|
|
466
|
-
|
|
492
|
+
let p = null, w = !1;
|
|
493
|
+
const I = (s) => {
|
|
494
|
+
w || (w = !0, this.interaction.signal?.removeEventListener("abort", y), this.dispatchEvent(new CustomEvent("viceme:access-layer-close", { detail: s })));
|
|
495
|
+
}, y = () => {
|
|
496
|
+
p?.cancel(), I("dismissed");
|
|
467
497
|
};
|
|
468
|
-
|
|
469
|
-
if (s.key === "Escape" &&
|
|
470
|
-
if (s.preventDefault(),
|
|
471
|
-
|
|
498
|
+
this.interaction.signal?.addEventListener("abort", y, { once: !0 }), this.interaction.signal?.aborted && queueMicrotask(y), T.addEventListener("click", y), N.addEventListener("click", y), this.addEventListener("keydown", (s) => {
|
|
499
|
+
if (s.key === "Escape" && y(), s.key === "Tab") {
|
|
500
|
+
if (s.preventDefault(), p?.type === "frame") {
|
|
501
|
+
S.focus();
|
|
472
502
|
return;
|
|
473
503
|
}
|
|
474
|
-
const
|
|
475
|
-
if (
|
|
476
|
-
const
|
|
477
|
-
|
|
504
|
+
const m = [N, ...f.hidden ? [] : [f]].filter((_) => !_.disabled && !_.hidden);
|
|
505
|
+
if (m.length === 0) return;
|
|
506
|
+
const D = m.indexOf(r.activeElement), E = s.shiftKey ? -1 : 1;
|
|
507
|
+
m[(D + E + m.length) % m.length]?.focus();
|
|
478
508
|
}
|
|
479
509
|
});
|
|
480
|
-
const
|
|
481
|
-
|
|
510
|
+
const A = async () => {
|
|
511
|
+
f.disabled = !0, f.setAttribute("aria-busy", "true"), f.textContent = "正在打开…", C.textContent = "";
|
|
482
512
|
try {
|
|
483
513
|
const s = await this.interaction.perform();
|
|
484
|
-
|
|
514
|
+
if (w || this.interaction.signal?.aborted) {
|
|
515
|
+
s.type !== "completed" && s.cancel();
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
s.type === "frame" ? (p = s, c.dataset.frame = "true", S.src = s.url, S.focus(), await s.completion) : s.type === "external" && (p = s, await s.completion), I("acted");
|
|
485
519
|
} catch (s) {
|
|
486
|
-
|
|
520
|
+
if (w) return;
|
|
521
|
+
p?.cancel(), p = null, c.dataset.frame = "false", S.removeAttribute("src"), C.textContent = te(s), f.hidden = !1, f.disabled = !1, f.removeAttribute("aria-busy"), f.textContent = d, f.focus();
|
|
487
522
|
}
|
|
488
523
|
};
|
|
489
|
-
|
|
524
|
+
f.addEventListener("click", A), queueMicrotask(() => f.focus());
|
|
490
525
|
}
|
|
491
526
|
}
|
|
492
|
-
customElements.define(
|
|
527
|
+
customElements.define(K, t);
|
|
493
528
|
}
|
|
494
|
-
const
|
|
495
|
-
if (typeof document > "u" || typeof customElements > "u")
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
const e = document.createElement(_);
|
|
529
|
+
const re = async (t) => {
|
|
530
|
+
if (typeof document > "u" || typeof customElements > "u" || t.signal?.aborted) return "dismissed";
|
|
531
|
+
ie();
|
|
532
|
+
const e = document.createElement(K);
|
|
499
533
|
e.interaction = t;
|
|
500
|
-
const i = document.documentElement.style.overflow,
|
|
534
|
+
const i = document.documentElement.style.overflow, r = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
501
535
|
document.documentElement.style.overflow = "hidden", document.body.append(e);
|
|
502
536
|
try {
|
|
503
537
|
return await new Promise((c) => {
|
|
504
538
|
e.addEventListener(
|
|
505
539
|
"viceme:access-layer-close",
|
|
506
|
-
(
|
|
540
|
+
(O) => c(O.detail),
|
|
507
541
|
{ once: !0 }
|
|
508
542
|
);
|
|
509
543
|
});
|
|
510
544
|
} finally {
|
|
511
|
-
e.remove(), document.documentElement.style.overflow = i,
|
|
545
|
+
e.remove(), document.documentElement.style.overflow = i, r?.focus();
|
|
512
546
|
}
|
|
513
547
|
};
|
|
514
|
-
function
|
|
515
|
-
if (typeof t != "object" || t === null) throw
|
|
548
|
+
function k(t) {
|
|
549
|
+
if (typeof t != "object" || t === null) throw h();
|
|
516
550
|
return t;
|
|
517
551
|
}
|
|
518
|
-
function
|
|
519
|
-
return new
|
|
552
|
+
function h() {
|
|
553
|
+
return new b({
|
|
520
554
|
code: "INTERNAL_ERROR",
|
|
521
555
|
message: "Malformed public API response.",
|
|
522
556
|
retryable: !0
|
|
523
557
|
});
|
|
524
558
|
}
|
|
525
|
-
function
|
|
526
|
-
const e =
|
|
559
|
+
function ae(t) {
|
|
560
|
+
const e = k(t);
|
|
527
561
|
if (typeof e.id != "string" || !(typeof e.displayName == "string" || e.displayName === null) || !(typeof e.avatarUrl == "string" || e.avatarUrl === null))
|
|
528
|
-
throw
|
|
562
|
+
throw h();
|
|
529
563
|
return {
|
|
530
564
|
subject: e.id,
|
|
531
565
|
nickname: e.displayName,
|
|
532
566
|
avatarUrl: e.avatarUrl
|
|
533
567
|
};
|
|
534
568
|
}
|
|
535
|
-
function
|
|
536
|
-
const e =
|
|
569
|
+
function F(t) {
|
|
570
|
+
const e = k(t);
|
|
537
571
|
if (typeof e.following != "boolean" || !(typeof e.followedAt == "string" || e.followedAt === null))
|
|
538
|
-
throw
|
|
539
|
-
const i =
|
|
572
|
+
throw h();
|
|
573
|
+
const i = k(e.creator);
|
|
540
574
|
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
|
|
575
|
+
throw h();
|
|
542
576
|
return {
|
|
543
577
|
following: e.following,
|
|
544
578
|
followedAt: e.followedAt,
|
|
@@ -551,8 +585,8 @@ function P(t) {
|
|
|
551
585
|
}
|
|
552
586
|
};
|
|
553
587
|
}
|
|
554
|
-
function
|
|
555
|
-
const e =
|
|
588
|
+
function ne(t) {
|
|
589
|
+
const e = k(t), i = /* @__PURE__ */ new Set([
|
|
556
590
|
"PUBLIC",
|
|
557
591
|
"OWNER",
|
|
558
592
|
"FOLLOWING",
|
|
@@ -562,22 +596,22 @@ function ae(t) {
|
|
|
562
596
|
"PURCHASE_REQUIRED",
|
|
563
597
|
"FEATURE_NOT_FOUND",
|
|
564
598
|
"FEATURE_DISABLED"
|
|
565
|
-
]),
|
|
566
|
-
if (typeof e.allowed != "boolean" || typeof e.reason != "string" || !i.has(e.reason) || !
|
|
567
|
-
throw
|
|
599
|
+
]), r = /* @__PURE__ */ new Set([null, "SIGN_IN", "FOLLOW", "CHECKOUT"]);
|
|
600
|
+
if (typeof e.allowed != "boolean" || typeof e.reason != "string" || !i.has(e.reason) || !r.has(e.nextAction))
|
|
601
|
+
throw h();
|
|
568
602
|
return {
|
|
569
603
|
allowed: e.allowed,
|
|
570
604
|
reason: e.reason,
|
|
571
605
|
nextAction: e.nextAction
|
|
572
606
|
};
|
|
573
607
|
}
|
|
574
|
-
function
|
|
575
|
-
const e =
|
|
608
|
+
function oe(t) {
|
|
609
|
+
const e = k(t);
|
|
576
610
|
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 :
|
|
611
|
+
throw h();
|
|
612
|
+
const i = e.price === null ? null : k(e.price);
|
|
579
613
|
if (i !== null && (!Number.isInteger(i.amountCents) || i.amountCents <= 0 || i.currency !== "CNY") || e.policyType === "WORK_ENTITLEMENT" != (i !== null))
|
|
580
|
-
throw
|
|
614
|
+
throw h();
|
|
581
615
|
return {
|
|
582
616
|
featureKey: e.featureKey,
|
|
583
617
|
title: e.title,
|
|
@@ -585,245 +619,287 @@ function re(t) {
|
|
|
585
619
|
price: i === null ? null : { amountCents: i.amountCents, currency: "CNY" }
|
|
586
620
|
};
|
|
587
621
|
}
|
|
588
|
-
function
|
|
622
|
+
function se() {
|
|
589
623
|
const t = crypto.getRandomValues(new Uint8Array(32));
|
|
590
|
-
return
|
|
624
|
+
return ce(t);
|
|
591
625
|
}
|
|
592
|
-
function
|
|
626
|
+
function ce(t) {
|
|
593
627
|
let e = "";
|
|
594
628
|
for (const i of t) e += String.fromCharCode(i);
|
|
595
629
|
return btoa(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
596
630
|
}
|
|
597
|
-
function
|
|
631
|
+
function le() {
|
|
598
632
|
return typeof document < "u" && document.documentElement.lang.toLowerCase() === "en-us" ? "en-US" : "zh-CN";
|
|
599
633
|
}
|
|
600
|
-
function
|
|
601
|
-
const e = () => new
|
|
634
|
+
function de(t) {
|
|
635
|
+
const e = () => new b({
|
|
602
636
|
code: "AUTH_CANCELLED",
|
|
603
637
|
message: "The interactive action was cancelled.",
|
|
604
638
|
retryable: !1
|
|
605
|
-
}), i = (
|
|
639
|
+
}), i = (n) => {
|
|
640
|
+
if (t.signal.aborted) return Promise.reject(v());
|
|
641
|
+
let o;
|
|
642
|
+
const l = new Promise((d, u) => {
|
|
643
|
+
o = () => u(v()), t.signal.addEventListener("abort", o, { once: !0 }), t.signal.aborted && o();
|
|
644
|
+
});
|
|
645
|
+
let a;
|
|
646
|
+
try {
|
|
647
|
+
a = (t.presenter ?? re)({
|
|
648
|
+
...n,
|
|
649
|
+
signal: t.signal
|
|
650
|
+
});
|
|
651
|
+
} catch (d) {
|
|
652
|
+
a = Promise.reject(d);
|
|
653
|
+
}
|
|
654
|
+
return Promise.race([a, l]).then((d) => {
|
|
655
|
+
if (t.signal.aborted) throw v();
|
|
656
|
+
return d;
|
|
657
|
+
}).finally(() => {
|
|
658
|
+
o && t.signal.removeEventListener("abort", o);
|
|
659
|
+
});
|
|
660
|
+
}, r = (n, o, l, a, d, u) => {
|
|
606
661
|
if (typeof window > "u")
|
|
607
|
-
throw new
|
|
662
|
+
throw new b({
|
|
608
663
|
code: "CONFIG_INVALID",
|
|
609
664
|
message: "Interactive access requires a browser window.",
|
|
610
665
|
retryable: !1
|
|
611
666
|
});
|
|
612
|
-
let
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
},
|
|
616
|
-
|
|
667
|
+
let p = !0, w, I;
|
|
668
|
+
const y = () => {
|
|
669
|
+
p && (p = !1, window.removeEventListener("message", s));
|
|
670
|
+
}, A = new Promise((g, m) => {
|
|
671
|
+
w = g, I = m;
|
|
617
672
|
}), s = (g) => {
|
|
618
|
-
if (!
|
|
619
|
-
const
|
|
620
|
-
if (!(
|
|
621
|
-
if (
|
|
673
|
+
if (!p || g.origin !== o || typeof g.data != "object" || g.data === null) return;
|
|
674
|
+
const m = g.data;
|
|
675
|
+
if (!(m.workKey !== t.workKey || m.channel !== l)) {
|
|
676
|
+
if (m.type === `viceme:${a}:ready`) {
|
|
622
677
|
g.source && "postMessage" in g.source && g.source.postMessage(
|
|
623
678
|
{
|
|
624
|
-
type: `viceme:${
|
|
679
|
+
type: `viceme:${a}:init`,
|
|
625
680
|
workKey: t.workKey,
|
|
626
681
|
channel: l,
|
|
627
|
-
...
|
|
682
|
+
...d
|
|
628
683
|
},
|
|
629
684
|
o
|
|
630
685
|
);
|
|
631
686
|
return;
|
|
632
687
|
}
|
|
633
|
-
if (
|
|
634
|
-
|
|
688
|
+
if (m.type === `viceme:${a}:cancelled`) {
|
|
689
|
+
y(), I(e());
|
|
635
690
|
return;
|
|
636
691
|
}
|
|
637
|
-
|
|
692
|
+
m.type === `viceme:${a}:complete` && (y(), u(m).then(w, I));
|
|
638
693
|
}
|
|
639
694
|
};
|
|
640
695
|
return window.addEventListener("message", s), {
|
|
641
696
|
type: "frame",
|
|
642
|
-
url:
|
|
643
|
-
completion:
|
|
697
|
+
url: n,
|
|
698
|
+
completion: A,
|
|
644
699
|
cancel() {
|
|
645
|
-
|
|
700
|
+
y(), w();
|
|
646
701
|
}
|
|
647
702
|
};
|
|
648
|
-
},
|
|
703
|
+
}, c = async () => {
|
|
649
704
|
if (await t.ready(), typeof window > "u")
|
|
650
|
-
throw new
|
|
705
|
+
throw new b({
|
|
651
706
|
code: "CONFIG_INVALID",
|
|
652
707
|
message: "Interactive access requires a browser window.",
|
|
653
708
|
retryable: !1
|
|
654
709
|
});
|
|
655
|
-
const
|
|
710
|
+
const n = se(), o = new URL("/sdk/login", t.widgetOrigin);
|
|
656
711
|
o.search = new URLSearchParams({
|
|
657
712
|
workKey: t.workKey,
|
|
658
|
-
channel:
|
|
713
|
+
channel: n,
|
|
659
714
|
parentOrigin: window.location.origin,
|
|
660
|
-
locale:
|
|
715
|
+
locale: le()
|
|
661
716
|
}).toString();
|
|
662
717
|
const l = t.session.snapshot?.token;
|
|
663
|
-
if (!l) throw
|
|
664
|
-
return
|
|
718
|
+
if (!l) throw h();
|
|
719
|
+
return r(
|
|
665
720
|
o.toString(),
|
|
666
721
|
t.widgetOrigin,
|
|
667
|
-
|
|
722
|
+
n,
|
|
668
723
|
"auth",
|
|
669
724
|
{ workSessionToken: l },
|
|
670
|
-
async (
|
|
671
|
-
if (typeof
|
|
672
|
-
throw
|
|
673
|
-
t.session.authenticate({ userToken:
|
|
725
|
+
async (a) => {
|
|
726
|
+
if (typeof a.userToken != "string")
|
|
727
|
+
throw h();
|
|
728
|
+
t.session.authenticate({ userToken: a.userToken, user: ae(a.user) });
|
|
674
729
|
}
|
|
675
730
|
);
|
|
676
|
-
},
|
|
731
|
+
}, O = async () => (await t.ready(), F(
|
|
677
732
|
(await t.session.request({ method: "GET", path: "/v1/public/work-sdk/follow" })).body
|
|
678
|
-
)),
|
|
733
|
+
)), f = async () => (await t.ready(), F(
|
|
679
734
|
(await t.session.request({ method: "PUT", path: "/v1/public/work-sdk/follow" })).body
|
|
680
|
-
)),
|
|
735
|
+
)), U = {
|
|
681
736
|
async getState() {
|
|
682
737
|
await t.ready();
|
|
683
|
-
const
|
|
684
|
-
return { authenticated:
|
|
738
|
+
const n = t.session.snapshot?.user ?? null;
|
|
739
|
+
return { authenticated: n !== null, user: n };
|
|
685
740
|
},
|
|
686
741
|
async signIn() {
|
|
687
|
-
if (await (
|
|
742
|
+
if (await i({
|
|
688
743
|
featureKey: "auth",
|
|
689
744
|
reason: "AUTH_REQUIRED",
|
|
690
745
|
action: "SIGN_IN",
|
|
691
|
-
perform:
|
|
746
|
+
perform: c
|
|
692
747
|
}) === "dismissed") throw e();
|
|
693
748
|
return this.getState();
|
|
694
749
|
},
|
|
695
750
|
async signOut() {
|
|
696
751
|
await t.ready(), await t.session.signOut();
|
|
697
752
|
}
|
|
698
|
-
},
|
|
699
|
-
getState:
|
|
700
|
-
follow:
|
|
753
|
+
}, N = {
|
|
754
|
+
getState: O,
|
|
755
|
+
follow: f,
|
|
701
756
|
unfollow: async () => {
|
|
702
|
-
throw new
|
|
757
|
+
throw new b({
|
|
703
758
|
code: "CAPABILITY_DISABLED",
|
|
704
759
|
message: "Unfollow is not exposed by website access.",
|
|
705
760
|
retryable: !1
|
|
706
761
|
});
|
|
707
762
|
}
|
|
708
|
-
},
|
|
763
|
+
}, T = async (n) => {
|
|
709
764
|
await t.ready();
|
|
710
|
-
const o =
|
|
765
|
+
const o = k(
|
|
711
766
|
(await t.session.request({
|
|
712
767
|
method: "POST",
|
|
713
768
|
path: "/v1/public/work-sdk/access/check",
|
|
714
|
-
body: { featureKeys:
|
|
769
|
+
body: { featureKeys: n }
|
|
715
770
|
})).body
|
|
716
|
-
), l =
|
|
771
|
+
), l = k(o.decisions);
|
|
717
772
|
return Object.fromEntries(
|
|
718
|
-
Object.entries(l).map(([
|
|
773
|
+
Object.entries(l).map(([a, d]) => [a, ne(d)])
|
|
719
774
|
);
|
|
720
|
-
},
|
|
775
|
+
}, C = async (n, o = {}) => {
|
|
721
776
|
await t.ready();
|
|
722
777
|
const l = {
|
|
723
|
-
featureKey:
|
|
778
|
+
featureKey: n,
|
|
724
779
|
locale: o.locale ?? "zh-CN"
|
|
725
|
-
},
|
|
780
|
+
}, a = k(
|
|
726
781
|
(await t.session.request({
|
|
727
782
|
method: "POST",
|
|
728
783
|
path: "/v1/public/work-sdk/checkout",
|
|
729
784
|
body: l
|
|
730
785
|
})).body
|
|
731
786
|
);
|
|
732
|
-
if (typeof
|
|
733
|
-
throw
|
|
787
|
+
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))
|
|
788
|
+
throw h();
|
|
789
|
+
let d;
|
|
734
790
|
try {
|
|
735
|
-
new URL(
|
|
791
|
+
d = new URL(a.checkoutUrl);
|
|
736
792
|
} catch {
|
|
737
|
-
throw
|
|
793
|
+
throw h();
|
|
738
794
|
}
|
|
795
|
+
if (!a.alreadyOwned && (d.protocol !== "https:" || d.origin !== t.widgetOrigin))
|
|
796
|
+
throw h();
|
|
739
797
|
return {
|
|
740
|
-
checkoutUrl:
|
|
741
|
-
alreadyOwned:
|
|
798
|
+
checkoutUrl: a.checkoutUrl,
|
|
799
|
+
alreadyOwned: a.alreadyOwned,
|
|
800
|
+
expiresAt: a.expiresAt
|
|
742
801
|
};
|
|
743
|
-
},
|
|
744
|
-
if (
|
|
802
|
+
}, S = (n, o) => {
|
|
803
|
+
if (n.alreadyOwned) return { type: "completed" };
|
|
804
|
+
const l = Date.parse(n.expiresAt);
|
|
745
805
|
if (typeof window > "u")
|
|
746
|
-
throw new
|
|
806
|
+
throw new b({
|
|
747
807
|
code: "CONFIG_INVALID",
|
|
748
808
|
message: "Hosted checkout requires a browser window.",
|
|
749
809
|
retryable: !1
|
|
750
810
|
});
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
811
|
+
let a = !0, d, u, p, w;
|
|
812
|
+
const I = new Promise((E, _) => {
|
|
813
|
+
p = E, w = _;
|
|
814
|
+
}), y = () => {
|
|
815
|
+
d && clearTimeout(d), u && clearTimeout(u), document.removeEventListener("visibilitychange", m);
|
|
816
|
+
}, A = () => {
|
|
817
|
+
a && (a = !1, y(), w(
|
|
818
|
+
new b({
|
|
819
|
+
code: "SESSION_EXPIRED",
|
|
820
|
+
message: "Hosted checkout session expired.",
|
|
821
|
+
retryable: !0
|
|
822
|
+
})
|
|
823
|
+
));
|
|
824
|
+
}, s = () => {
|
|
825
|
+
if (!a || document.visibilityState === "hidden") return;
|
|
826
|
+
const E = l - t.now();
|
|
827
|
+
if (E <= 0) {
|
|
828
|
+
A();
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
d = setTimeout(() => {
|
|
832
|
+
g();
|
|
833
|
+
}, Math.min(1500, E));
|
|
834
|
+
}, g = async () => {
|
|
835
|
+
if (a)
|
|
763
836
|
try {
|
|
764
|
-
const
|
|
765
|
-
if (!
|
|
766
|
-
if (
|
|
767
|
-
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
770
|
-
if (l.closed) {
|
|
771
|
-
n = !1, d(e());
|
|
837
|
+
const E = (await T([o]))[o];
|
|
838
|
+
if (!E) throw h();
|
|
839
|
+
if (E.allowed) {
|
|
840
|
+
a = !1, y(), p();
|
|
772
841
|
return;
|
|
773
842
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
} catch (h) {
|
|
778
|
-
n = !1, d(h);
|
|
843
|
+
s();
|
|
844
|
+
} catch (E) {
|
|
845
|
+
a = !1, y(), w(E);
|
|
779
846
|
}
|
|
780
847
|
};
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
848
|
+
function m() {
|
|
849
|
+
if (a) {
|
|
850
|
+
if (document.visibilityState === "hidden") {
|
|
851
|
+
d && clearTimeout(d), d = void 0;
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
s();
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
document.addEventListener("visibilitychange", m);
|
|
858
|
+
const D = l - t.now();
|
|
859
|
+
return D <= 0 ? A() : (u = setTimeout(A, D), s()), {
|
|
860
|
+
type: "frame",
|
|
861
|
+
url: n.checkoutUrl,
|
|
862
|
+
completion: I,
|
|
786
863
|
cancel() {
|
|
787
|
-
|
|
864
|
+
a && (a = !1, y(), p());
|
|
788
865
|
}
|
|
789
866
|
};
|
|
790
867
|
};
|
|
791
|
-
return { auth:
|
|
868
|
+
return { auth: U, follow: N, access: {
|
|
792
869
|
async getFeatures() {
|
|
793
870
|
await t.ready();
|
|
794
|
-
const
|
|
871
|
+
const n = k(
|
|
795
872
|
(await t.session.request({
|
|
796
873
|
method: "GET",
|
|
797
874
|
path: "/v1/public/work-sdk/access/features"
|
|
798
875
|
})).body
|
|
799
876
|
);
|
|
800
|
-
if (!Array.isArray(
|
|
801
|
-
throw
|
|
802
|
-
return
|
|
877
|
+
if (!Array.isArray(n.features) || n.features.length > 100)
|
|
878
|
+
throw h();
|
|
879
|
+
return n.features.map(oe);
|
|
803
880
|
},
|
|
804
|
-
async check(
|
|
805
|
-
const l = (await
|
|
806
|
-
if (!l) throw
|
|
881
|
+
async check(n) {
|
|
882
|
+
const l = (await T([n]))[n];
|
|
883
|
+
if (!l) throw h();
|
|
807
884
|
return l;
|
|
808
885
|
},
|
|
809
|
-
checkMany:
|
|
810
|
-
async require(
|
|
811
|
-
let o = await this.check(
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
o = await this.check(r);
|
|
886
|
+
checkMany: T,
|
|
887
|
+
async require(n) {
|
|
888
|
+
let o = await this.check(n);
|
|
889
|
+
for (let l = 0; !o.allowed && o.nextAction && l < 3; l += 1) {
|
|
890
|
+
const a = o.nextAction, d = a === "FOLLOW" ? (await N.getState()).target : void 0, u = a === "CHECKOUT" ? await C(n) : void 0;
|
|
891
|
+
if (u?.alreadyOwned) {
|
|
892
|
+
o = await this.check(n);
|
|
817
893
|
continue;
|
|
818
894
|
}
|
|
819
|
-
if (await
|
|
820
|
-
featureKey:
|
|
895
|
+
if (await i({
|
|
896
|
+
featureKey: n,
|
|
821
897
|
reason: o.reason,
|
|
822
|
-
action:
|
|
823
|
-
...
|
|
824
|
-
perform: async () =>
|
|
898
|
+
action: a,
|
|
899
|
+
...d ? { followTarget: d } : {},
|
|
900
|
+
perform: async () => a === "SIGN_IN" ? c() : a === "FOLLOW" ? (await N.follow(), { type: "completed" }) : S(u, n)
|
|
825
901
|
}) === "dismissed") return o;
|
|
826
|
-
o = await this.check(
|
|
902
|
+
o = await this.check(n);
|
|
827
903
|
}
|
|
828
904
|
return o;
|
|
829
905
|
},
|
|
@@ -831,64 +907,66 @@ function ce(t) {
|
|
|
831
907
|
await t.ready();
|
|
832
908
|
}
|
|
833
909
|
}, checkout: {
|
|
834
|
-
async open(
|
|
835
|
-
const o = await
|
|
910
|
+
async open(n) {
|
|
911
|
+
const o = await C(n.featureKey, n);
|
|
836
912
|
if (o.alreadyOwned) return o;
|
|
837
|
-
if (await (
|
|
838
|
-
featureKey:
|
|
913
|
+
if (await i({
|
|
914
|
+
featureKey: n.featureKey,
|
|
839
915
|
reason: "PURCHASE_REQUIRED",
|
|
840
916
|
action: "CHECKOUT",
|
|
841
|
-
perform: async () =>
|
|
917
|
+
perform: async () => S(o, n.featureKey)
|
|
842
918
|
}) === "dismissed") throw e();
|
|
843
919
|
return o;
|
|
844
920
|
}
|
|
845
921
|
} };
|
|
846
922
|
}
|
|
847
|
-
class
|
|
923
|
+
class ue extends DOMException {
|
|
848
924
|
constructor() {
|
|
849
925
|
super("ViceMe client destroyed.", "AbortError");
|
|
850
926
|
}
|
|
851
927
|
}
|
|
852
|
-
class
|
|
928
|
+
class we {
|
|
853
929
|
#e = new Q();
|
|
854
930
|
#t;
|
|
855
931
|
#i;
|
|
856
|
-
#
|
|
857
|
-
#
|
|
932
|
+
#r = new AbortController();
|
|
933
|
+
#n;
|
|
858
934
|
auth;
|
|
859
935
|
access;
|
|
860
936
|
checkout;
|
|
861
937
|
/** Detaches the caller-signal listener; undefined when none was attached. */
|
|
862
|
-
#
|
|
938
|
+
#a;
|
|
863
939
|
constructor(e) {
|
|
864
|
-
this.#i = e.config, this.#t = new
|
|
940
|
+
this.#i = e.config, this.#t = new Z({
|
|
865
941
|
workKey: e.config.workKey,
|
|
866
942
|
transport: e.transport,
|
|
867
|
-
signal: this.#
|
|
943
|
+
signal: this.#r.signal,
|
|
868
944
|
...e.now !== void 0 ? { now: e.now } : {}
|
|
869
945
|
});
|
|
870
|
-
const i =
|
|
946
|
+
const i = de({
|
|
871
947
|
session: this.#t,
|
|
872
948
|
workKey: e.config.workKey,
|
|
873
|
-
widgetOrigin:
|
|
949
|
+
widgetOrigin: j[e.config.region],
|
|
950
|
+
now: e.now ?? (() => Date.now()),
|
|
874
951
|
presenter: e.presenter,
|
|
875
|
-
|
|
952
|
+
signal: this.#r.signal,
|
|
953
|
+
ready: () => this.#s()
|
|
876
954
|
});
|
|
877
955
|
this.auth = i.auth, this.access = i.access, this.checkout = i.checkout;
|
|
878
|
-
const
|
|
879
|
-
if (
|
|
956
|
+
const r = e.config.signal;
|
|
957
|
+
if (r) {
|
|
880
958
|
const c = () => {
|
|
881
|
-
this.#
|
|
882
|
-
|
|
959
|
+
this.#r.abort(
|
|
960
|
+
r.reason instanceof Error ? r.reason : new DOMException("Caller signal aborted.", "AbortError")
|
|
883
961
|
);
|
|
884
962
|
};
|
|
885
|
-
|
|
886
|
-
|
|
963
|
+
r.aborted ? c() : (r.addEventListener("abort", c, { once: !0 }), this.#a = () => {
|
|
964
|
+
r.removeEventListener("abort", c);
|
|
887
965
|
});
|
|
888
966
|
}
|
|
889
967
|
}
|
|
890
968
|
get version() {
|
|
891
|
-
return
|
|
969
|
+
return W;
|
|
892
970
|
}
|
|
893
971
|
get workKey() {
|
|
894
972
|
return this.#i.workKey;
|
|
@@ -904,15 +982,15 @@ class he {
|
|
|
904
982
|
return H;
|
|
905
983
|
}
|
|
906
984
|
ready() {
|
|
907
|
-
return this.#e.destroyed ? Promise.reject(
|
|
985
|
+
return this.#e.destroyed ? Promise.reject(v()) : (this.#n || (this.#e.transition("READY"), this.#n = Promise.resolve()), this.#n);
|
|
908
986
|
}
|
|
909
|
-
async #
|
|
910
|
-
if (this.#e.destroyed) throw
|
|
987
|
+
async #s() {
|
|
988
|
+
if (this.#e.destroyed) throw v();
|
|
911
989
|
await this.ready();
|
|
912
990
|
try {
|
|
913
|
-
if (await this.#t.establish(), this.#e.destroyed) throw
|
|
991
|
+
if (await this.#t.establish(), this.#e.destroyed) throw v();
|
|
914
992
|
} catch (e) {
|
|
915
|
-
throw this.#e.destroyed ?
|
|
993
|
+
throw this.#e.destroyed ? v() : (this.#t.invalidate(), e);
|
|
916
994
|
}
|
|
917
995
|
}
|
|
918
996
|
hasCapability(e) {
|
|
@@ -936,14 +1014,14 @@ class he {
|
|
|
936
1014
|
return this.#t.snapshot;
|
|
937
1015
|
}
|
|
938
1016
|
destroy() {
|
|
939
|
-
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#
|
|
1017
|
+
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#r.abort(new ue()), this.#t.destroy(), this.#e.clearListeners(), this.#n = void 0, this.#a?.(), this.#a = void 0);
|
|
940
1018
|
}
|
|
941
1019
|
}
|
|
942
1020
|
export {
|
|
943
|
-
|
|
1021
|
+
we as V,
|
|
944
1022
|
Y as a,
|
|
945
1023
|
B as i,
|
|
946
|
-
|
|
947
|
-
|
|
1024
|
+
pe as r,
|
|
1025
|
+
ye as v
|
|
948
1026
|
};
|
|
949
|
-
//# sourceMappingURL=client-
|
|
1027
|
+
//# sourceMappingURL=client-DEg6YouY.js.map
|