@viceme-ai/sdk 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -6
- package/dist/capability-mount.d.ts +2 -0
- package/dist/capability-mount.d.ts.map +1 -1
- package/dist/chunks/{client-DEg6YouY.js → client-C1Sw400H.js} +386 -300
- package/dist/chunks/client-C1Sw400H.js.map +1 -0
- package/dist/chunks/integration-CTsnJ8mN.js +38 -0
- package/dist/chunks/integration-CTsnJ8mN.js.map +1 -0
- package/dist/chunks/version-CAPPYmfK.js +6 -0
- package/dist/chunks/{version-BJiUVcir.js.map → version-CAPPYmfK.js.map} +1 -1
- package/dist/core/capabilities.d.ts.map +1 -1
- package/dist/core/presentation.d.ts +5 -0
- package/dist/core/presentation.d.ts.map +1 -1
- package/dist/danmaku/mount.d.ts.map +1 -1
- package/dist/danmaku.js +117 -91
- package/dist/danmaku.js.map +1 -1
- package/dist/engagement/integration.d.ts +15 -0
- package/dist/engagement/integration.d.ts.map +1 -0
- package/dist/generated/public-contract.d.ts +15 -1
- package/dist/generated/public-contract.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/loader/auto-loader.d.ts.map +1 -1
- package/dist/manifest.json +36 -27
- package/dist/session/session.d.ts +12 -0
- package/dist/session/session.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tip/index.d.ts +2 -0
- package/dist/tip/index.d.ts.map +1 -1
- package/dist/tip/mount.d.ts.map +1 -1
- package/dist/tip.js +211 -194
- package/dist/tip.js.map +1 -1
- package/dist/transport/transport.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/viceme.min.js +46 -4
- package/dist/viceme.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/client-DEg6YouY.js.map +0 -1
- package/dist/chunks/version-BJiUVcir.js +0 -6
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as
|
|
3
|
-
import { S as
|
|
4
|
-
const
|
|
5
|
-
cn:
|
|
6
|
-
global:
|
|
1
|
+
import { a as R, V as v, c as k, i as Y } from "./errors-C7DfLKcF.js";
|
|
2
|
+
import { a as W, B as $ } from "./build-endpoints-NrDmg6jf.js";
|
|
3
|
+
import { S as Q, A as X } from "./version-CAPPYmfK.js";
|
|
4
|
+
const J = /* @__PURE__ */ new Set(["cn", "global"]), Z = {
|
|
5
|
+
cn: W.cn,
|
|
6
|
+
global: W.global
|
|
7
7
|
};
|
|
8
|
-
function
|
|
9
|
-
return
|
|
8
|
+
function Ee(t) {
|
|
9
|
+
return Z[t];
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function ee(t) {
|
|
12
12
|
return typeof t == "string" && /^wrk_(?:test|live)_[A-Za-z0-9_-]{4,119}$/.test(t);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
return typeof t == "string" &&
|
|
14
|
+
function te(t) {
|
|
15
|
+
return typeof t == "string" && J.has(t);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function Se(t) {
|
|
18
18
|
if (typeof t != "object" || t === null)
|
|
19
|
-
throw
|
|
19
|
+
throw R("createViceMe expects a configuration object.");
|
|
20
20
|
const e = t, i = /* @__PURE__ */ new Set(["workKey", "region", "signal"]);
|
|
21
21
|
for (const r of Object.keys(e))
|
|
22
22
|
if (!i.has(r))
|
|
23
|
-
throw
|
|
24
|
-
if (!
|
|
25
|
-
throw
|
|
23
|
+
throw R(`Unknown configuration field "${r}".`);
|
|
24
|
+
if (!ee(e.workKey))
|
|
25
|
+
throw R(
|
|
26
26
|
'Configuration field "workKey" must start with "wrk_test_" or "wrk_live_".'
|
|
27
27
|
);
|
|
28
|
-
if (!
|
|
29
|
-
throw
|
|
28
|
+
if (!te(e.region))
|
|
29
|
+
throw R('Configuration field "region" must be "cn" or "global".');
|
|
30
30
|
if (e.signal !== void 0 && !(e.signal instanceof AbortSignal))
|
|
31
|
-
throw
|
|
31
|
+
throw R('Configuration field "signal" must be an AbortSignal.');
|
|
32
32
|
return {
|
|
33
33
|
workKey: e.workKey,
|
|
34
34
|
region: e.region,
|
|
35
35
|
signal: e.signal
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const ie = {
|
|
39
39
|
CREATED: ["READY", "DESTROYED"],
|
|
40
40
|
READY: ["DEGRADED", "DESTROYED"],
|
|
41
41
|
DEGRADED: ["DESTROYED"],
|
|
42
42
|
DESTROYED: []
|
|
43
43
|
};
|
|
44
|
-
class
|
|
44
|
+
class re {
|
|
45
45
|
#e = "CREATED";
|
|
46
46
|
#t = /* @__PURE__ */ new Set();
|
|
47
47
|
get state() {
|
|
@@ -52,8 +52,8 @@ class Q {
|
|
|
52
52
|
}
|
|
53
53
|
transition(e) {
|
|
54
54
|
if (e !== this.#e) {
|
|
55
|
-
if (
|
|
56
|
-
throw new
|
|
55
|
+
if (!ie[this.#e].includes(e))
|
|
56
|
+
throw new v({
|
|
57
57
|
code: "INTERNAL_ERROR",
|
|
58
58
|
message: `Illegal lifecycle transition ${this.#e} -> ${e}.`,
|
|
59
59
|
retryable: !1
|
|
@@ -64,7 +64,7 @@ class Q {
|
|
|
64
64
|
}
|
|
65
65
|
/** Any operation on a destroyed client must fail closed with this guard. */
|
|
66
66
|
assertAlive() {
|
|
67
|
-
if (this.destroyed) throw
|
|
67
|
+
if (this.destroyed) throw k();
|
|
68
68
|
}
|
|
69
69
|
subscribe(e) {
|
|
70
70
|
return this.#t.add(e), () => {
|
|
@@ -75,14 +75,14 @@ class Q {
|
|
|
75
75
|
this.#t.clear();
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function ae(t, e) {
|
|
79
79
|
if (typeof t != "object" || t === null)
|
|
80
|
-
throw
|
|
80
|
+
throw C();
|
|
81
81
|
const i = t;
|
|
82
|
-
if (typeof i.workKey != "string" || !Array.isArray(i.capabilities) || !i.capabilities.every((
|
|
83
|
-
throw
|
|
82
|
+
if (typeof i.workKey != "string" || !Array.isArray(i.capabilities) || !i.capabilities.every((s) => typeof s == "string"))
|
|
83
|
+
throw C();
|
|
84
84
|
if (i.workKey !== e)
|
|
85
|
-
throw new
|
|
85
|
+
throw new v({
|
|
86
86
|
code: "WORK_NOT_FOUND",
|
|
87
87
|
message: "Work-session response did not match the requested work key.",
|
|
88
88
|
retryable: !1
|
|
@@ -93,32 +93,59 @@ function X(t, e) {
|
|
|
93
93
|
capabilities: i.capabilities
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
+
if (i.creator !== void 0 || i.work !== void 0) {
|
|
97
|
+
const s = j(i.creator), w = j(i.work);
|
|
98
|
+
if (typeof s.displayName != "string" || s.displayName.length === 0 || !z(s.avatarUrl) || !Number.isInteger(s.publishedWorkCount) || s.publishedWorkCount < 0 || typeof w.title != "string" || w.title.length === 0 || typeof w.summary != "string" || !z(w.coverUrl))
|
|
99
|
+
throw C();
|
|
100
|
+
r.work.creator = {
|
|
101
|
+
displayName: s.displayName,
|
|
102
|
+
avatarUrl: s.avatarUrl,
|
|
103
|
+
publishedWorkCount: s.publishedWorkCount
|
|
104
|
+
}, r.work.details = {
|
|
105
|
+
title: w.title,
|
|
106
|
+
summary: w.summary,
|
|
107
|
+
coverUrl: w.coverUrl
|
|
108
|
+
};
|
|
109
|
+
}
|
|
96
110
|
if (typeof i.token == "string" && (r.token = i.token), typeof i.expiresAt == "string") {
|
|
97
|
-
const
|
|
98
|
-
Number.isNaN(
|
|
111
|
+
const s = new Date(i.expiresAt).getTime();
|
|
112
|
+
Number.isNaN(s) || (r.expiresAt = s);
|
|
99
113
|
}
|
|
100
114
|
return r;
|
|
101
115
|
}
|
|
102
|
-
function
|
|
103
|
-
|
|
116
|
+
function j(t) {
|
|
117
|
+
if (typeof t != "object" || t === null) throw C();
|
|
118
|
+
return t;
|
|
119
|
+
}
|
|
120
|
+
function z(t) {
|
|
121
|
+
if (t === null) return !0;
|
|
122
|
+
if (typeof t != "string") return !1;
|
|
123
|
+
try {
|
|
124
|
+
return new URL(t), !0;
|
|
125
|
+
} catch {
|
|
126
|
+
return !1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function C() {
|
|
130
|
+
return new v({
|
|
104
131
|
code: "INTERNAL_ERROR",
|
|
105
132
|
message: "Malformed work-session response.",
|
|
106
133
|
retryable: !0
|
|
107
134
|
});
|
|
108
135
|
}
|
|
109
|
-
function
|
|
110
|
-
return new
|
|
136
|
+
function oe() {
|
|
137
|
+
return new v({
|
|
111
138
|
code: "SESSION_EXPIRED",
|
|
112
139
|
message: "The work session was invalidated before it completed.",
|
|
113
140
|
retryable: !0
|
|
114
141
|
});
|
|
115
142
|
}
|
|
116
|
-
class
|
|
143
|
+
class ne {
|
|
117
144
|
#e;
|
|
118
145
|
#t;
|
|
119
146
|
#i;
|
|
120
147
|
#r;
|
|
121
|
-
#
|
|
148
|
+
#o = 0;
|
|
122
149
|
#a = !1;
|
|
123
150
|
constructor(e) {
|
|
124
151
|
this.#e = e, this.#t = e.now ?? (() => Date.now());
|
|
@@ -139,13 +166,13 @@ class Z {
|
|
|
139
166
|
* in-flight request (single flight).
|
|
140
167
|
*/
|
|
141
168
|
establish() {
|
|
142
|
-
if (this.#a) return Promise.reject(
|
|
169
|
+
if (this.#a) return Promise.reject(k());
|
|
143
170
|
if (this.#i) {
|
|
144
171
|
if (!this.#s()) return Promise.resolve(this.#i);
|
|
145
172
|
this.#i = void 0;
|
|
146
173
|
}
|
|
147
174
|
if (this.#r) return this.#r;
|
|
148
|
-
const e = this.#
|
|
175
|
+
const e = this.#o, i = this.#e.transport.request({
|
|
149
176
|
method: "POST",
|
|
150
177
|
path: "/v1/public/work-sdk/sessions",
|
|
151
178
|
body: { workKey: this.#e.workKey },
|
|
@@ -153,8 +180,8 @@ class Z {
|
|
|
153
180
|
timeoutMs: this.#e.timeoutMs
|
|
154
181
|
}).then((r) => {
|
|
155
182
|
this.#c(e);
|
|
156
|
-
const
|
|
157
|
-
return this.#c(e), this.#i =
|
|
183
|
+
const s = ae(r.body, this.#e.workKey);
|
|
184
|
+
return this.#c(e), this.#i = s, s;
|
|
158
185
|
}).finally(() => {
|
|
159
186
|
this.#r === i && (this.#r = void 0);
|
|
160
187
|
});
|
|
@@ -162,20 +189,20 @@ class Z {
|
|
|
162
189
|
}
|
|
163
190
|
async request(e) {
|
|
164
191
|
const i = await this.establish();
|
|
165
|
-
if (!i.token) throw
|
|
192
|
+
if (!i.token) throw C();
|
|
166
193
|
try {
|
|
167
194
|
return await this.#l(e, i);
|
|
168
195
|
} catch (r) {
|
|
169
|
-
if (this.#a) throw
|
|
170
|
-
if (!(r instanceof
|
|
196
|
+
if (this.#a) throw k();
|
|
197
|
+
if (!(r instanceof v) || r.code !== "SESSION_EXPIRED") throw r;
|
|
171
198
|
this.#i === i && this.invalidate();
|
|
172
|
-
const
|
|
173
|
-
if (!
|
|
174
|
-
return this.#l(e,
|
|
199
|
+
const s = await this.establish();
|
|
200
|
+
if (!s.token) throw C();
|
|
201
|
+
return this.#l(e, s);
|
|
175
202
|
}
|
|
176
203
|
}
|
|
177
204
|
authenticate(e) {
|
|
178
|
-
if (this.#
|
|
205
|
+
if (this.#n(), !this.#i) throw C();
|
|
179
206
|
this.#i = {
|
|
180
207
|
...this.#i,
|
|
181
208
|
userToken: e.userToken,
|
|
@@ -183,24 +210,24 @@ class Z {
|
|
|
183
210
|
};
|
|
184
211
|
}
|
|
185
212
|
async signOut() {
|
|
186
|
-
this.#
|
|
213
|
+
this.#n(), this.invalidate(), await this.establish();
|
|
187
214
|
}
|
|
188
215
|
/** Drop the token; next `establish()` re-authenticates. */
|
|
189
216
|
invalidate() {
|
|
190
|
-
this.#
|
|
217
|
+
this.#o += 1, this.#i = void 0, this.#r = void 0;
|
|
191
218
|
}
|
|
192
219
|
/** Hard cleanup: forget the token and pending work. */
|
|
193
220
|
destroy() {
|
|
194
|
-
this.#a || (this.#a = !0, this.#
|
|
221
|
+
this.#a || (this.#a = !0, this.#o += 1, this.#i = void 0, this.#r = void 0);
|
|
195
222
|
}
|
|
196
|
-
#
|
|
197
|
-
if (this.#a) throw
|
|
223
|
+
#n() {
|
|
224
|
+
if (this.#a) throw k();
|
|
198
225
|
}
|
|
199
226
|
#c(e) {
|
|
200
|
-
if (this.#
|
|
227
|
+
if (this.#n(), e !== this.#o) throw oe();
|
|
201
228
|
}
|
|
202
229
|
async #l(e, i) {
|
|
203
|
-
this.#
|
|
230
|
+
this.#n();
|
|
204
231
|
try {
|
|
205
232
|
const r = await this.#e.transport.request({
|
|
206
233
|
...e,
|
|
@@ -208,14 +235,14 @@ class Z {
|
|
|
208
235
|
userAuthorization: i.userToken,
|
|
209
236
|
signal: this.#e.signal
|
|
210
237
|
});
|
|
211
|
-
return this.#
|
|
238
|
+
return this.#n(), r;
|
|
212
239
|
} catch (r) {
|
|
213
|
-
throw this.#a ?
|
|
240
|
+
throw this.#a ? k() : r;
|
|
214
241
|
}
|
|
215
242
|
}
|
|
216
243
|
}
|
|
217
|
-
const
|
|
218
|
-
function
|
|
244
|
+
const q = "viceme-access-layer", M = 50;
|
|
245
|
+
function se(t) {
|
|
219
246
|
switch (t) {
|
|
220
247
|
case "SIGN_IN":
|
|
221
248
|
return {
|
|
@@ -234,8 +261,8 @@ function ee(t) {
|
|
|
234
261
|
};
|
|
235
262
|
}
|
|
236
263
|
}
|
|
237
|
-
function
|
|
238
|
-
if (!
|
|
264
|
+
function ce(t) {
|
|
265
|
+
if (!Y(t)) return "操作未完成,请重试。";
|
|
239
266
|
switch (t.code) {
|
|
240
267
|
case "CONFIG_INVALID":
|
|
241
268
|
return "微信授权配置无效,请稍后重试。";
|
|
@@ -249,12 +276,12 @@ function te(t) {
|
|
|
249
276
|
return t.requestId ? `操作未完成,请重试。请求 ID:${t.requestId}` : "操作未完成,请重试。";
|
|
250
277
|
}
|
|
251
278
|
}
|
|
252
|
-
function
|
|
253
|
-
if (customElements.get(
|
|
279
|
+
function le() {
|
|
280
|
+
if (customElements.get(q)) return;
|
|
254
281
|
class t extends HTMLElement {
|
|
255
282
|
interaction;
|
|
256
283
|
connectedCallback() {
|
|
257
|
-
const i =
|
|
284
|
+
const i = se(this.interaction.action), r = this.attachShadow({ mode: "open" });
|
|
258
285
|
r.innerHTML = `
|
|
259
286
|
<style>
|
|
260
287
|
:host {
|
|
@@ -374,8 +401,43 @@ function ie() {
|
|
|
374
401
|
font-size: 1.125rem;
|
|
375
402
|
}
|
|
376
403
|
[data-viceme='panel'][data-action='SIGN_IN'] [data-viceme='profile-description'] {
|
|
377
|
-
|
|
378
|
-
|
|
404
|
+
display: none;
|
|
405
|
+
}
|
|
406
|
+
[data-viceme='work'] {
|
|
407
|
+
display: none;
|
|
408
|
+
overflow: hidden;
|
|
409
|
+
margin-top: 1.25rem;
|
|
410
|
+
border: 1px solid #e4e4e7;
|
|
411
|
+
border-radius: 1rem;
|
|
412
|
+
background: #fafafa;
|
|
413
|
+
text-align: left;
|
|
414
|
+
}
|
|
415
|
+
[data-viceme='work'][data-visible='true'] { display: block; }
|
|
416
|
+
[data-viceme='work-cover'] {
|
|
417
|
+
display: block;
|
|
418
|
+
width: 100%;
|
|
419
|
+
aspect-ratio: 16 / 9;
|
|
420
|
+
object-fit: cover;
|
|
421
|
+
background: #f4f4f5;
|
|
422
|
+
}
|
|
423
|
+
[data-viceme='work-cover'][hidden] { display: none; }
|
|
424
|
+
[data-viceme='work-copy'] { padding: 1rem; }
|
|
425
|
+
[data-viceme='work-title'] {
|
|
426
|
+
margin: 0;
|
|
427
|
+
color: #18181b;
|
|
428
|
+
font-size: 1rem;
|
|
429
|
+
font-weight: 700;
|
|
430
|
+
line-height: 1.5;
|
|
431
|
+
}
|
|
432
|
+
[data-viceme='work-summary'] {
|
|
433
|
+
display: -webkit-box;
|
|
434
|
+
overflow: hidden;
|
|
435
|
+
margin: 0.375rem 0 0;
|
|
436
|
+
color: #71717a;
|
|
437
|
+
font-size: 0.875rem;
|
|
438
|
+
line-height: 1.5;
|
|
439
|
+
-webkit-box-orient: vertical;
|
|
440
|
+
-webkit-line-clamp: 2;
|
|
379
441
|
}
|
|
380
442
|
[data-viceme='panel'][data-action='SIGN_IN'] [data-viceme='action'] {
|
|
381
443
|
width: 100%;
|
|
@@ -462,6 +524,13 @@ function ie() {
|
|
|
462
524
|
</div>
|
|
463
525
|
<p data-viceme="profile-description"></p>
|
|
464
526
|
</section>
|
|
527
|
+
<article data-viceme="work">
|
|
528
|
+
<img data-viceme="work-cover" hidden />
|
|
529
|
+
<div data-viceme="work-copy">
|
|
530
|
+
<p data-viceme="work-title"></p>
|
|
531
|
+
<p data-viceme="work-summary"></p>
|
|
532
|
+
</div>
|
|
533
|
+
</article>
|
|
465
534
|
<p data-viceme="error" role="alert" aria-live="polite"></p>
|
|
466
535
|
<div data-viceme="actions">
|
|
467
536
|
<button data-viceme="action" type="button"></button>
|
|
@@ -470,74 +539,76 @@ function ie() {
|
|
|
470
539
|
<iframe data-viceme="frame" title="" referrerpolicy="no-referrer" allow="payment"></iframe>
|
|
471
540
|
</section>
|
|
472
541
|
`;
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
const f = r.querySelector("[data-viceme='action']"),
|
|
542
|
+
const s = r.querySelector("[data-viceme='panel']");
|
|
543
|
+
s.dataset.action = this.interaction.action, s.dataset.frame = "false";
|
|
544
|
+
const w = r.querySelector("[data-viceme='description']");
|
|
545
|
+
w.textContent = i.description;
|
|
546
|
+
const f = r.querySelector("[data-viceme='action']"), L = f.parentElement, D = r.querySelector("[data-viceme='close']"), T = r.querySelector("[data-viceme='backdrop']"), O = r.querySelector("[data-viceme='error']"), N = r.querySelector("[data-viceme='frame']"), U = r.querySelector("[data-viceme='profile']"), _ = r.querySelector("[data-viceme='avatar']"), K = r.querySelector("[data-viceme='avatar-fallback']"), a = r.querySelector("[data-viceme='profile-name']"), n = r.querySelector(
|
|
478
547
|
"[data-viceme='profile-description']"
|
|
479
|
-
),
|
|
480
|
-
f.textContent = i.label, f.hidden = !1,
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
const
|
|
484
|
-
if (
|
|
485
|
-
|
|
548
|
+
), d = r.querySelector("[data-viceme='profile-stats']"), o = r.querySelector("[data-viceme='work']"), l = r.querySelector("[data-viceme='work-cover']"), g = r.querySelector("[data-viceme='work-title']"), S = r.querySelector("[data-viceme='work-summary']");
|
|
549
|
+
f.textContent = i.label, f.hidden = !1, L.dataset.single = "true";
|
|
550
|
+
const A = i.label;
|
|
551
|
+
N.title = this.interaction.action === "SIGN_IN" ? "登录授权" : "支付";
|
|
552
|
+
const m = this.interaction.followTarget;
|
|
553
|
+
if (m) {
|
|
554
|
+
s.setAttribute(
|
|
486
555
|
"aria-label",
|
|
487
|
-
this.interaction.action === "SIGN_IN" ? `授权 ${
|
|
488
|
-
),
|
|
489
|
-
const
|
|
490
|
-
|
|
556
|
+
this.interaction.action === "SIGN_IN" ? `授权 ${m.displayName}` : `关注 ${m.displayName}`
|
|
557
|
+
), U.dataset.visible = "true", a.textContent = m.displayName;
|
|
558
|
+
const c = [...m.description ?? ""];
|
|
559
|
+
n.textContent = c.length > M ? `${c.slice(0, M).join("")}…` : c.join(""), c.length > M && (n.title = m.description), d.textContent = `${m.workCount} 个作品`, K.textContent = m.displayName.trim().slice(0, 1) || "V", m.avatarUrl && (_.src = m.avatarUrl, _.alt = `${m.displayName}的头像`, _.hidden = !1, K.hidden = !0);
|
|
491
560
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
561
|
+
const p = this.interaction.work;
|
|
562
|
+
p && (o.dataset.visible = "true", g.textContent = p.title, S.textContent = p.summary, p.coverUrl && (l.src = p.coverUrl, l.alt = p.title, l.hidden = !1));
|
|
563
|
+
let b = null, E = !1;
|
|
564
|
+
const y = (c) => {
|
|
565
|
+
E || (E = !0, this.interaction.signal?.removeEventListener("abort", u), this.dispatchEvent(new CustomEvent("viceme:access-layer-close", { detail: c })));
|
|
566
|
+
}, u = () => {
|
|
567
|
+
b?.cancel(), y("dismissed");
|
|
497
568
|
};
|
|
498
|
-
this.interaction.signal?.addEventListener("abort",
|
|
499
|
-
if (
|
|
500
|
-
if (
|
|
501
|
-
|
|
569
|
+
this.interaction.signal?.addEventListener("abort", u, { once: !0 }), this.interaction.signal?.aborted && queueMicrotask(u), T.addEventListener("click", u), D.addEventListener("click", u), this.addEventListener("keydown", (c) => {
|
|
570
|
+
if (c.key === "Escape" && u(), c.key === "Tab") {
|
|
571
|
+
if (c.preventDefault(), b?.type === "frame") {
|
|
572
|
+
N.focus();
|
|
502
573
|
return;
|
|
503
574
|
}
|
|
504
|
-
const
|
|
505
|
-
if (
|
|
506
|
-
const
|
|
507
|
-
|
|
575
|
+
const x = [D, ...f.hidden ? [] : [f]].filter((G) => !G.disabled && !G.hidden);
|
|
576
|
+
if (x.length === 0) return;
|
|
577
|
+
const V = x.indexOf(r.activeElement), B = c.shiftKey ? -1 : 1;
|
|
578
|
+
x[(V + B + x.length) % x.length]?.focus();
|
|
508
579
|
}
|
|
509
580
|
});
|
|
510
|
-
const
|
|
511
|
-
f.disabled = !0, f.setAttribute("aria-busy", "true"), f.textContent = "正在打开…",
|
|
581
|
+
const P = async () => {
|
|
582
|
+
f.disabled = !0, f.setAttribute("aria-busy", "true"), f.textContent = "正在打开…", O.textContent = "";
|
|
512
583
|
try {
|
|
513
|
-
const
|
|
514
|
-
if (
|
|
515
|
-
|
|
584
|
+
const c = await this.interaction.perform();
|
|
585
|
+
if (E || this.interaction.signal?.aborted) {
|
|
586
|
+
c.type !== "completed" && c.cancel();
|
|
516
587
|
return;
|
|
517
588
|
}
|
|
518
|
-
|
|
519
|
-
} catch (
|
|
520
|
-
if (
|
|
521
|
-
|
|
589
|
+
c.type === "frame" ? (b = c, s.dataset.frame = "true", N.src = c.url, N.focus(), await c.completion) : c.type === "external" && (b = c, await c.completion), y("acted");
|
|
590
|
+
} catch (c) {
|
|
591
|
+
if (E) return;
|
|
592
|
+
b?.cancel(), b = null, s.dataset.frame = "false", N.removeAttribute("src"), O.textContent = ce(c), f.hidden = !1, f.disabled = !1, f.removeAttribute("aria-busy"), f.textContent = A, f.focus();
|
|
522
593
|
}
|
|
523
594
|
};
|
|
524
|
-
f.addEventListener("click",
|
|
595
|
+
f.addEventListener("click", P), queueMicrotask(() => f.focus());
|
|
525
596
|
}
|
|
526
597
|
}
|
|
527
|
-
customElements.define(
|
|
598
|
+
customElements.define(q, t);
|
|
528
599
|
}
|
|
529
|
-
const
|
|
600
|
+
const de = async (t) => {
|
|
530
601
|
if (typeof document > "u" || typeof customElements > "u" || t.signal?.aborted) return "dismissed";
|
|
531
|
-
|
|
532
|
-
const e = document.createElement(
|
|
602
|
+
le();
|
|
603
|
+
const e = document.createElement(q);
|
|
533
604
|
e.interaction = t;
|
|
534
605
|
const i = document.documentElement.style.overflow, r = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
535
606
|
document.documentElement.style.overflow = "hidden", document.body.append(e);
|
|
536
607
|
try {
|
|
537
|
-
return await new Promise((
|
|
608
|
+
return await new Promise((s) => {
|
|
538
609
|
e.addEventListener(
|
|
539
610
|
"viceme:access-layer-close",
|
|
540
|
-
(
|
|
611
|
+
(w) => s(w.detail),
|
|
541
612
|
{ once: !0 }
|
|
542
613
|
);
|
|
543
614
|
});
|
|
@@ -545,19 +616,19 @@ const re = async (t) => {
|
|
|
545
616
|
e.remove(), document.documentElement.style.overflow = i, r?.focus();
|
|
546
617
|
}
|
|
547
618
|
};
|
|
548
|
-
function
|
|
619
|
+
function I(t) {
|
|
549
620
|
if (typeof t != "object" || t === null) throw h();
|
|
550
621
|
return t;
|
|
551
622
|
}
|
|
552
623
|
function h() {
|
|
553
|
-
return new
|
|
624
|
+
return new v({
|
|
554
625
|
code: "INTERNAL_ERROR",
|
|
555
626
|
message: "Malformed public API response.",
|
|
556
627
|
retryable: !0
|
|
557
628
|
});
|
|
558
629
|
}
|
|
559
|
-
function
|
|
560
|
-
const e =
|
|
630
|
+
function ue(t) {
|
|
631
|
+
const e = I(t);
|
|
561
632
|
if (typeof e.id != "string" || !(typeof e.displayName == "string" || e.displayName === null) || !(typeof e.avatarUrl == "string" || e.avatarUrl === null))
|
|
562
633
|
throw h();
|
|
563
634
|
return {
|
|
@@ -566,11 +637,11 @@ function ae(t) {
|
|
|
566
637
|
avatarUrl: e.avatarUrl
|
|
567
638
|
};
|
|
568
639
|
}
|
|
569
|
-
function
|
|
570
|
-
const e =
|
|
640
|
+
function H(t) {
|
|
641
|
+
const e = I(t);
|
|
571
642
|
if (typeof e.following != "boolean" || !(typeof e.followedAt == "string" || e.followedAt === null))
|
|
572
643
|
throw h();
|
|
573
|
-
const i =
|
|
644
|
+
const i = I(e.creator);
|
|
574
645
|
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)
|
|
575
646
|
throw h();
|
|
576
647
|
return {
|
|
@@ -585,8 +656,8 @@ function F(t) {
|
|
|
585
656
|
}
|
|
586
657
|
};
|
|
587
658
|
}
|
|
588
|
-
function
|
|
589
|
-
const e =
|
|
659
|
+
function fe(t) {
|
|
660
|
+
const e = I(t), i = /* @__PURE__ */ new Set([
|
|
590
661
|
"PUBLIC",
|
|
591
662
|
"OWNER",
|
|
592
663
|
"FOLLOWING",
|
|
@@ -605,11 +676,11 @@ function ne(t) {
|
|
|
605
676
|
nextAction: e.nextAction
|
|
606
677
|
};
|
|
607
678
|
}
|
|
608
|
-
function
|
|
609
|
-
const e =
|
|
679
|
+
function me(t) {
|
|
680
|
+
const e = I(t);
|
|
610
681
|
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"))
|
|
611
682
|
throw h();
|
|
612
|
-
const i = e.price === null ? null :
|
|
683
|
+
const i = e.price === null ? null : I(e.price);
|
|
613
684
|
if (i !== null && (!Number.isInteger(i.amountCents) || i.amountCents <= 0 || i.currency !== "CNY") || e.policyType === "WORK_ENTITLEMENT" != (i !== null))
|
|
614
685
|
throw h();
|
|
615
686
|
return {
|
|
@@ -619,334 +690,349 @@ function oe(t) {
|
|
|
619
690
|
price: i === null ? null : { amountCents: i.amountCents, currency: "CNY" }
|
|
620
691
|
};
|
|
621
692
|
}
|
|
622
|
-
function
|
|
693
|
+
function he() {
|
|
623
694
|
const t = crypto.getRandomValues(new Uint8Array(32));
|
|
624
|
-
return
|
|
695
|
+
return pe(t);
|
|
625
696
|
}
|
|
626
|
-
function
|
|
697
|
+
function pe(t) {
|
|
627
698
|
let e = "";
|
|
628
699
|
for (const i of t) e += String.fromCharCode(i);
|
|
629
700
|
return btoa(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
630
701
|
}
|
|
631
|
-
function
|
|
702
|
+
function ye() {
|
|
632
703
|
return typeof document < "u" && document.documentElement.lang.toLowerCase() === "en-us" ? "en-US" : "zh-CN";
|
|
633
704
|
}
|
|
634
|
-
function
|
|
635
|
-
const e = () => new
|
|
705
|
+
function we(t) {
|
|
706
|
+
const e = () => new v({
|
|
636
707
|
code: "AUTH_CANCELLED",
|
|
637
708
|
message: "The interactive action was cancelled.",
|
|
638
709
|
retryable: !1
|
|
639
|
-
}), i = (
|
|
640
|
-
if (t.signal.aborted) return Promise.reject(
|
|
641
|
-
let
|
|
642
|
-
const
|
|
643
|
-
|
|
710
|
+
}), i = (a) => {
|
|
711
|
+
if (t.signal.aborted) return Promise.reject(k());
|
|
712
|
+
let n;
|
|
713
|
+
const d = new Promise((l, g) => {
|
|
714
|
+
n = () => g(k()), t.signal.addEventListener("abort", n, { once: !0 }), t.signal.aborted && n();
|
|
644
715
|
});
|
|
645
|
-
let
|
|
716
|
+
let o;
|
|
646
717
|
try {
|
|
647
|
-
|
|
648
|
-
...
|
|
718
|
+
o = (t.presenter ?? de)({
|
|
719
|
+
...a,
|
|
649
720
|
signal: t.signal
|
|
650
721
|
});
|
|
651
|
-
} catch (
|
|
652
|
-
|
|
722
|
+
} catch (l) {
|
|
723
|
+
o = Promise.reject(l);
|
|
653
724
|
}
|
|
654
|
-
return Promise.race([
|
|
655
|
-
if (t.signal.aborted) throw
|
|
656
|
-
return
|
|
725
|
+
return Promise.race([o, d]).then((l) => {
|
|
726
|
+
if (t.signal.aborted) throw k();
|
|
727
|
+
return l;
|
|
657
728
|
}).finally(() => {
|
|
658
|
-
|
|
729
|
+
n && t.signal.removeEventListener("abort", n);
|
|
659
730
|
});
|
|
660
|
-
}, r = (
|
|
731
|
+
}, r = (a, n, d, o, l, g) => {
|
|
661
732
|
if (typeof window > "u")
|
|
662
|
-
throw new
|
|
733
|
+
throw new v({
|
|
663
734
|
code: "CONFIG_INVALID",
|
|
664
735
|
message: "Interactive access requires a browser window.",
|
|
665
736
|
retryable: !1
|
|
666
737
|
});
|
|
667
|
-
let
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
},
|
|
671
|
-
|
|
672
|
-
}),
|
|
673
|
-
if (!
|
|
674
|
-
const
|
|
675
|
-
if (!(
|
|
676
|
-
if (
|
|
677
|
-
|
|
738
|
+
let S = !0, A, m;
|
|
739
|
+
const p = () => {
|
|
740
|
+
S && (S = !1, window.removeEventListener("message", E));
|
|
741
|
+
}, b = new Promise((y, u) => {
|
|
742
|
+
A = y, m = u;
|
|
743
|
+
}), E = (y) => {
|
|
744
|
+
if (!S || y.origin !== n || typeof y.data != "object" || y.data === null) return;
|
|
745
|
+
const u = y.data;
|
|
746
|
+
if (!(u.workKey !== t.workKey || u.channel !== d)) {
|
|
747
|
+
if (u.type === `viceme:${o}:ready`) {
|
|
748
|
+
y.source && "postMessage" in y.source && y.source.postMessage(
|
|
678
749
|
{
|
|
679
|
-
type: `viceme:${
|
|
750
|
+
type: `viceme:${o}:init`,
|
|
680
751
|
workKey: t.workKey,
|
|
681
|
-
channel:
|
|
682
|
-
...
|
|
752
|
+
channel: d,
|
|
753
|
+
...l
|
|
683
754
|
},
|
|
684
|
-
|
|
755
|
+
n
|
|
685
756
|
);
|
|
686
757
|
return;
|
|
687
758
|
}
|
|
688
|
-
if (
|
|
689
|
-
|
|
759
|
+
if (u.type === `viceme:${o}:cancelled`) {
|
|
760
|
+
p(), m(e());
|
|
690
761
|
return;
|
|
691
762
|
}
|
|
692
|
-
|
|
763
|
+
u.type === `viceme:${o}:complete` && (p(), g(u).then(A, m));
|
|
693
764
|
}
|
|
694
765
|
};
|
|
695
|
-
return window.addEventListener("message",
|
|
766
|
+
return window.addEventListener("message", E), {
|
|
696
767
|
type: "frame",
|
|
697
|
-
url:
|
|
698
|
-
completion:
|
|
768
|
+
url: a,
|
|
769
|
+
completion: b,
|
|
699
770
|
cancel() {
|
|
700
|
-
|
|
771
|
+
p(), A();
|
|
701
772
|
}
|
|
702
773
|
};
|
|
703
|
-
},
|
|
774
|
+
}, s = async () => {
|
|
704
775
|
if (await t.ready(), typeof window > "u")
|
|
705
|
-
throw new
|
|
776
|
+
throw new v({
|
|
706
777
|
code: "CONFIG_INVALID",
|
|
707
778
|
message: "Interactive access requires a browser window.",
|
|
708
779
|
retryable: !1
|
|
709
780
|
});
|
|
710
|
-
const
|
|
711
|
-
|
|
781
|
+
const a = he(), n = new URL("/sdk/login", t.widgetOrigin);
|
|
782
|
+
n.search = new URLSearchParams({
|
|
712
783
|
workKey: t.workKey,
|
|
713
|
-
channel:
|
|
784
|
+
channel: a,
|
|
714
785
|
parentOrigin: window.location.origin,
|
|
715
|
-
locale:
|
|
786
|
+
locale: ye()
|
|
716
787
|
}).toString();
|
|
717
|
-
const
|
|
718
|
-
if (!
|
|
788
|
+
const d = t.session.snapshot?.token;
|
|
789
|
+
if (!d) throw h();
|
|
719
790
|
return r(
|
|
720
|
-
|
|
791
|
+
n.toString(),
|
|
721
792
|
t.widgetOrigin,
|
|
722
|
-
|
|
793
|
+
a,
|
|
723
794
|
"auth",
|
|
724
|
-
{ workSessionToken:
|
|
725
|
-
async (
|
|
726
|
-
if (typeof
|
|
795
|
+
{ workSessionToken: d },
|
|
796
|
+
async (o) => {
|
|
797
|
+
if (typeof o.userToken != "string")
|
|
727
798
|
throw h();
|
|
728
|
-
t.session.authenticate({ userToken:
|
|
799
|
+
t.session.authenticate({ userToken: o.userToken, user: ue(o.user) });
|
|
729
800
|
}
|
|
730
801
|
);
|
|
731
|
-
},
|
|
802
|
+
}, w = async () => (await t.ready(), H(
|
|
732
803
|
(await t.session.request({ method: "GET", path: "/v1/public/work-sdk/follow" })).body
|
|
733
|
-
)), f = async () => (await t.ready(),
|
|
804
|
+
)), f = async () => (await t.ready(), H(
|
|
734
805
|
(await t.session.request({ method: "PUT", path: "/v1/public/work-sdk/follow" })).body
|
|
735
|
-
)),
|
|
806
|
+
)), L = () => {
|
|
807
|
+
const a = t.session.snapshot?.work;
|
|
808
|
+
return {
|
|
809
|
+
...a?.creator ? {
|
|
810
|
+
followTarget: {
|
|
811
|
+
kind: "CREATOR",
|
|
812
|
+
displayName: a.creator.displayName,
|
|
813
|
+
avatarUrl: a.creator.avatarUrl,
|
|
814
|
+
description: null,
|
|
815
|
+
workCount: a.creator.publishedWorkCount
|
|
816
|
+
}
|
|
817
|
+
} : {},
|
|
818
|
+
...a?.details ? { work: a.details } : {}
|
|
819
|
+
};
|
|
820
|
+
}, D = {
|
|
736
821
|
async getState() {
|
|
737
822
|
await t.ready();
|
|
738
|
-
const
|
|
739
|
-
return { authenticated:
|
|
823
|
+
const a = t.session.snapshot?.user ?? null;
|
|
824
|
+
return { authenticated: a !== null, user: a };
|
|
740
825
|
},
|
|
741
826
|
async signIn() {
|
|
742
|
-
if (await i({
|
|
827
|
+
if (await t.ready(), await i({
|
|
743
828
|
featureKey: "auth",
|
|
744
829
|
reason: "AUTH_REQUIRED",
|
|
745
830
|
action: "SIGN_IN",
|
|
746
|
-
|
|
831
|
+
...L(),
|
|
832
|
+
perform: s
|
|
747
833
|
}) === "dismissed") throw e();
|
|
748
834
|
return this.getState();
|
|
749
835
|
},
|
|
750
836
|
async signOut() {
|
|
751
837
|
await t.ready(), await t.session.signOut();
|
|
752
838
|
}
|
|
753
|
-
},
|
|
754
|
-
getState:
|
|
839
|
+
}, T = {
|
|
840
|
+
getState: w,
|
|
755
841
|
follow: f,
|
|
756
842
|
unfollow: async () => {
|
|
757
|
-
throw new
|
|
843
|
+
throw new v({
|
|
758
844
|
code: "CAPABILITY_DISABLED",
|
|
759
845
|
message: "Unfollow is not exposed by website access.",
|
|
760
846
|
retryable: !1
|
|
761
847
|
});
|
|
762
848
|
}
|
|
763
|
-
},
|
|
849
|
+
}, O = async (a) => {
|
|
764
850
|
await t.ready();
|
|
765
|
-
const
|
|
851
|
+
const n = I(
|
|
766
852
|
(await t.session.request({
|
|
767
853
|
method: "POST",
|
|
768
854
|
path: "/v1/public/work-sdk/access/check",
|
|
769
|
-
body: { featureKeys:
|
|
855
|
+
body: { featureKeys: a }
|
|
770
856
|
})).body
|
|
771
|
-
),
|
|
857
|
+
), d = I(n.decisions);
|
|
772
858
|
return Object.fromEntries(
|
|
773
|
-
Object.entries(
|
|
859
|
+
Object.entries(d).map(([o, l]) => [o, fe(l)])
|
|
774
860
|
);
|
|
775
|
-
},
|
|
861
|
+
}, N = async (a, n = {}) => {
|
|
776
862
|
await t.ready();
|
|
777
|
-
const
|
|
778
|
-
featureKey:
|
|
779
|
-
locale:
|
|
780
|
-
},
|
|
863
|
+
const d = {
|
|
864
|
+
featureKey: a,
|
|
865
|
+
locale: n.locale ?? "zh-CN"
|
|
866
|
+
}, o = I(
|
|
781
867
|
(await t.session.request({
|
|
782
868
|
method: "POST",
|
|
783
869
|
path: "/v1/public/work-sdk/checkout",
|
|
784
|
-
body:
|
|
870
|
+
body: d
|
|
785
871
|
})).body
|
|
786
872
|
);
|
|
787
|
-
if (typeof
|
|
873
|
+
if (typeof o.checkoutUrl != "string" || typeof o.alreadyOwned != "boolean" || !(o.expiresAt === null || typeof o.expiresAt == "string" && !Number.isNaN(Date.parse(o.expiresAt))) || o.alreadyOwned !== (o.expiresAt === null))
|
|
788
874
|
throw h();
|
|
789
|
-
let
|
|
875
|
+
let l;
|
|
790
876
|
try {
|
|
791
|
-
|
|
877
|
+
l = new URL(o.checkoutUrl);
|
|
792
878
|
} catch {
|
|
793
879
|
throw h();
|
|
794
880
|
}
|
|
795
|
-
if (!
|
|
881
|
+
if (!o.alreadyOwned && (l.protocol !== "https:" || l.origin !== t.widgetOrigin))
|
|
796
882
|
throw h();
|
|
797
883
|
return {
|
|
798
|
-
checkoutUrl:
|
|
799
|
-
alreadyOwned:
|
|
800
|
-
expiresAt:
|
|
884
|
+
checkoutUrl: o.checkoutUrl,
|
|
885
|
+
alreadyOwned: o.alreadyOwned,
|
|
886
|
+
expiresAt: o.expiresAt
|
|
801
887
|
};
|
|
802
|
-
},
|
|
803
|
-
if (
|
|
804
|
-
const
|
|
888
|
+
}, U = (a, n) => {
|
|
889
|
+
if (a.alreadyOwned) return { type: "completed" };
|
|
890
|
+
const d = Date.parse(a.expiresAt);
|
|
805
891
|
if (typeof window > "u")
|
|
806
|
-
throw new
|
|
892
|
+
throw new v({
|
|
807
893
|
code: "CONFIG_INVALID",
|
|
808
894
|
message: "Hosted checkout requires a browser window.",
|
|
809
895
|
retryable: !1
|
|
810
896
|
});
|
|
811
|
-
let
|
|
812
|
-
const
|
|
813
|
-
|
|
814
|
-
}),
|
|
815
|
-
|
|
816
|
-
},
|
|
817
|
-
|
|
818
|
-
new
|
|
897
|
+
let o = !0, l, g, S, A;
|
|
898
|
+
const m = new Promise((c, F) => {
|
|
899
|
+
S = c, A = F;
|
|
900
|
+
}), p = () => {
|
|
901
|
+
l && clearTimeout(l), g && clearTimeout(g), document.removeEventListener("visibilitychange", u);
|
|
902
|
+
}, b = () => {
|
|
903
|
+
o && (o = !1, p(), A(
|
|
904
|
+
new v({
|
|
819
905
|
code: "SESSION_EXPIRED",
|
|
820
906
|
message: "Hosted checkout session expired.",
|
|
821
907
|
retryable: !0
|
|
822
908
|
})
|
|
823
909
|
));
|
|
824
|
-
},
|
|
825
|
-
if (!
|
|
826
|
-
const
|
|
827
|
-
if (
|
|
828
|
-
|
|
910
|
+
}, E = () => {
|
|
911
|
+
if (!o || document.visibilityState === "hidden") return;
|
|
912
|
+
const c = d - t.now();
|
|
913
|
+
if (c <= 0) {
|
|
914
|
+
b();
|
|
829
915
|
return;
|
|
830
916
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
}, Math.min(1500,
|
|
834
|
-
},
|
|
835
|
-
if (
|
|
917
|
+
l = setTimeout(() => {
|
|
918
|
+
y();
|
|
919
|
+
}, Math.min(1500, c));
|
|
920
|
+
}, y = async () => {
|
|
921
|
+
if (o)
|
|
836
922
|
try {
|
|
837
|
-
const
|
|
838
|
-
if (!
|
|
839
|
-
if (
|
|
840
|
-
|
|
923
|
+
const c = (await O([n]))[n];
|
|
924
|
+
if (!c) throw h();
|
|
925
|
+
if (c.allowed) {
|
|
926
|
+
o = !1, p(), S();
|
|
841
927
|
return;
|
|
842
928
|
}
|
|
843
|
-
|
|
844
|
-
} catch (
|
|
845
|
-
|
|
929
|
+
E();
|
|
930
|
+
} catch (c) {
|
|
931
|
+
o = !1, p(), A(c);
|
|
846
932
|
}
|
|
847
933
|
};
|
|
848
|
-
function
|
|
849
|
-
if (
|
|
934
|
+
function u() {
|
|
935
|
+
if (o) {
|
|
850
936
|
if (document.visibilityState === "hidden") {
|
|
851
|
-
|
|
937
|
+
l && clearTimeout(l), l = void 0;
|
|
852
938
|
return;
|
|
853
939
|
}
|
|
854
|
-
|
|
940
|
+
E();
|
|
855
941
|
}
|
|
856
942
|
}
|
|
857
|
-
document.addEventListener("visibilitychange",
|
|
858
|
-
const
|
|
859
|
-
return
|
|
943
|
+
document.addEventListener("visibilitychange", u);
|
|
944
|
+
const P = d - t.now();
|
|
945
|
+
return P <= 0 ? b() : (g = setTimeout(b, P), E()), {
|
|
860
946
|
type: "frame",
|
|
861
|
-
url:
|
|
862
|
-
completion:
|
|
947
|
+
url: a.checkoutUrl,
|
|
948
|
+
completion: m,
|
|
863
949
|
cancel() {
|
|
864
|
-
|
|
950
|
+
o && (o = !1, p(), S());
|
|
865
951
|
}
|
|
866
952
|
};
|
|
867
953
|
};
|
|
868
|
-
return { auth:
|
|
954
|
+
return { auth: D, follow: T, access: {
|
|
869
955
|
async getFeatures() {
|
|
870
956
|
await t.ready();
|
|
871
|
-
const
|
|
957
|
+
const a = I(
|
|
872
958
|
(await t.session.request({
|
|
873
959
|
method: "GET",
|
|
874
960
|
path: "/v1/public/work-sdk/access/features"
|
|
875
961
|
})).body
|
|
876
962
|
);
|
|
877
|
-
if (!Array.isArray(
|
|
963
|
+
if (!Array.isArray(a.features) || a.features.length > 100)
|
|
878
964
|
throw h();
|
|
879
|
-
return
|
|
965
|
+
return a.features.map(me);
|
|
880
966
|
},
|
|
881
|
-
async check(
|
|
882
|
-
const
|
|
883
|
-
if (!
|
|
884
|
-
return
|
|
967
|
+
async check(a) {
|
|
968
|
+
const d = (await O([a]))[a];
|
|
969
|
+
if (!d) throw h();
|
|
970
|
+
return d;
|
|
885
971
|
},
|
|
886
|
-
checkMany:
|
|
887
|
-
async require(
|
|
888
|
-
let
|
|
889
|
-
for (let
|
|
890
|
-
const
|
|
891
|
-
if (
|
|
892
|
-
|
|
972
|
+
checkMany: O,
|
|
973
|
+
async require(a) {
|
|
974
|
+
let n = await this.check(a);
|
|
975
|
+
for (let d = 0; !n.allowed && n.nextAction && d < 3; d += 1) {
|
|
976
|
+
const o = n.nextAction, l = o === "FOLLOW" ? (await T.getState()).target : void 0, g = o === "CHECKOUT" ? await N(a) : void 0;
|
|
977
|
+
if (g?.alreadyOwned) {
|
|
978
|
+
n = await this.check(a);
|
|
893
979
|
continue;
|
|
894
980
|
}
|
|
895
981
|
if (await i({
|
|
896
|
-
featureKey:
|
|
897
|
-
reason:
|
|
898
|
-
action:
|
|
899
|
-
...
|
|
900
|
-
perform: async () =>
|
|
901
|
-
}) === "dismissed") return
|
|
902
|
-
|
|
982
|
+
featureKey: a,
|
|
983
|
+
reason: n.reason,
|
|
984
|
+
action: o,
|
|
985
|
+
...o === "SIGN_IN" ? L() : l ? { followTarget: l } : {},
|
|
986
|
+
perform: async () => o === "SIGN_IN" ? s() : o === "FOLLOW" ? (await T.follow(), { type: "completed" }) : U(g, a)
|
|
987
|
+
}) === "dismissed") return n;
|
|
988
|
+
n = await this.check(a);
|
|
903
989
|
}
|
|
904
|
-
return
|
|
990
|
+
return n;
|
|
905
991
|
},
|
|
906
992
|
async refresh() {
|
|
907
993
|
await t.ready();
|
|
908
994
|
}
|
|
909
995
|
}, checkout: {
|
|
910
|
-
async open(
|
|
911
|
-
const
|
|
912
|
-
if (
|
|
996
|
+
async open(a) {
|
|
997
|
+
const n = await N(a.featureKey, a);
|
|
998
|
+
if (n.alreadyOwned) return n;
|
|
913
999
|
if (await i({
|
|
914
|
-
featureKey:
|
|
1000
|
+
featureKey: a.featureKey,
|
|
915
1001
|
reason: "PURCHASE_REQUIRED",
|
|
916
1002
|
action: "CHECKOUT",
|
|
917
|
-
perform: async () =>
|
|
1003
|
+
perform: async () => U(n, a.featureKey)
|
|
918
1004
|
}) === "dismissed") throw e();
|
|
919
|
-
return
|
|
1005
|
+
return n;
|
|
920
1006
|
}
|
|
921
1007
|
} };
|
|
922
1008
|
}
|
|
923
|
-
class
|
|
1009
|
+
class ge extends DOMException {
|
|
924
1010
|
constructor() {
|
|
925
1011
|
super("ViceMe client destroyed.", "AbortError");
|
|
926
1012
|
}
|
|
927
1013
|
}
|
|
928
|
-
class
|
|
929
|
-
#e = new
|
|
1014
|
+
class Ie {
|
|
1015
|
+
#e = new re();
|
|
930
1016
|
#t;
|
|
931
1017
|
#i;
|
|
932
1018
|
#r = new AbortController();
|
|
933
|
-
#
|
|
1019
|
+
#o;
|
|
934
1020
|
auth;
|
|
935
1021
|
access;
|
|
936
1022
|
checkout;
|
|
937
1023
|
/** Detaches the caller-signal listener; undefined when none was attached. */
|
|
938
1024
|
#a;
|
|
939
1025
|
constructor(e) {
|
|
940
|
-
this.#i = e.config, this.#t = new
|
|
1026
|
+
this.#i = e.config, this.#t = new ne({
|
|
941
1027
|
workKey: e.config.workKey,
|
|
942
1028
|
transport: e.transport,
|
|
943
1029
|
signal: this.#r.signal,
|
|
944
1030
|
...e.now !== void 0 ? { now: e.now } : {}
|
|
945
1031
|
});
|
|
946
|
-
const i =
|
|
1032
|
+
const i = we({
|
|
947
1033
|
session: this.#t,
|
|
948
1034
|
workKey: e.config.workKey,
|
|
949
|
-
widgetOrigin:
|
|
1035
|
+
widgetOrigin: $[e.config.region],
|
|
950
1036
|
now: e.now ?? (() => Date.now()),
|
|
951
1037
|
presenter: e.presenter,
|
|
952
1038
|
signal: this.#r.signal,
|
|
@@ -955,18 +1041,18 @@ class we {
|
|
|
955
1041
|
this.auth = i.auth, this.access = i.access, this.checkout = i.checkout;
|
|
956
1042
|
const r = e.config.signal;
|
|
957
1043
|
if (r) {
|
|
958
|
-
const
|
|
1044
|
+
const s = () => {
|
|
959
1045
|
this.#r.abort(
|
|
960
1046
|
r.reason instanceof Error ? r.reason : new DOMException("Caller signal aborted.", "AbortError")
|
|
961
1047
|
);
|
|
962
1048
|
};
|
|
963
|
-
r.aborted ?
|
|
964
|
-
r.removeEventListener("abort",
|
|
1049
|
+
r.aborted ? s() : (r.addEventListener("abort", s, { once: !0 }), this.#a = () => {
|
|
1050
|
+
r.removeEventListener("abort", s);
|
|
965
1051
|
});
|
|
966
1052
|
}
|
|
967
1053
|
}
|
|
968
1054
|
get version() {
|
|
969
|
-
return
|
|
1055
|
+
return Q;
|
|
970
1056
|
}
|
|
971
1057
|
get workKey() {
|
|
972
1058
|
return this.#i.workKey;
|
|
@@ -979,18 +1065,18 @@ class we {
|
|
|
979
1065
|
}
|
|
980
1066
|
/** Internal: public API major, used by the loader registry namespace. */
|
|
981
1067
|
get apiMajor() {
|
|
982
|
-
return
|
|
1068
|
+
return X;
|
|
983
1069
|
}
|
|
984
1070
|
ready() {
|
|
985
|
-
return this.#e.destroyed ? Promise.reject(
|
|
1071
|
+
return this.#e.destroyed ? Promise.reject(k()) : (this.#o || (this.#e.transition("READY"), this.#o = Promise.resolve()), this.#o);
|
|
986
1072
|
}
|
|
987
1073
|
async #s() {
|
|
988
|
-
if (this.#e.destroyed) throw
|
|
1074
|
+
if (this.#e.destroyed) throw k();
|
|
989
1075
|
await this.ready();
|
|
990
1076
|
try {
|
|
991
|
-
if (await this.#t.establish(), this.#e.destroyed) throw
|
|
1077
|
+
if (await this.#t.establish(), this.#e.destroyed) throw k();
|
|
992
1078
|
} catch (e) {
|
|
993
|
-
throw this.#e.destroyed ?
|
|
1079
|
+
throw this.#e.destroyed ? k() : (this.#t.invalidate(), e);
|
|
994
1080
|
}
|
|
995
1081
|
}
|
|
996
1082
|
hasCapability(e) {
|
|
@@ -1014,14 +1100,14 @@ class we {
|
|
|
1014
1100
|
return this.#t.snapshot;
|
|
1015
1101
|
}
|
|
1016
1102
|
destroy() {
|
|
1017
|
-
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#r.abort(new
|
|
1103
|
+
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#r.abort(new ge()), this.#t.destroy(), this.#e.clearListeners(), this.#o = void 0, this.#a?.(), this.#a = void 0);
|
|
1018
1104
|
}
|
|
1019
1105
|
}
|
|
1020
1106
|
export {
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1107
|
+
Ie as V,
|
|
1108
|
+
te as a,
|
|
1109
|
+
ee as i,
|
|
1110
|
+
Ee as r,
|
|
1111
|
+
Se as v
|
|
1026
1112
|
};
|
|
1027
|
-
//# sourceMappingURL=client-
|
|
1113
|
+
//# sourceMappingURL=client-C1Sw400H.js.map
|