@viceme-ai/sdk 0.6.1 → 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 +29 -7
- package/dist/capability-mount.d.ts +2 -0
- package/dist/capability-mount.d.ts.map +1 -1
- package/dist/chunks/{client-w9vih8Ng.js → client-C1Sw400H.js} +429 -294
- 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-uPTHb89K.js.map → version-CAPPYmfK.js.map} +1 -1
- package/dist/core/capabilities.d.ts +1 -0
- package/dist/core/capabilities.d.ts.map +1 -1
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/presentation.d.ts +7 -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 +37 -28
- 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-w9vih8Ng.js.map +0 -1
- package/dist/chunks/version-uPTHb89K.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,24 +93,60 @@ 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
|
-
|
|
136
|
+
function oe() {
|
|
137
|
+
return new v({
|
|
138
|
+
code: "SESSION_EXPIRED",
|
|
139
|
+
message: "The work session was invalidated before it completed.",
|
|
140
|
+
retryable: !0
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
class ne {
|
|
110
144
|
#e;
|
|
111
145
|
#t;
|
|
112
146
|
#i;
|
|
113
147
|
#r;
|
|
148
|
+
#o = 0;
|
|
149
|
+
#a = !1;
|
|
114
150
|
constructor(e) {
|
|
115
151
|
this.#e = e, this.#t = e.now ?? (() => Date.now());
|
|
116
152
|
}
|
|
@@ -118,7 +154,7 @@ class J {
|
|
|
118
154
|
return this.#i;
|
|
119
155
|
}
|
|
120
156
|
/** True when the cached snapshot's server-provided expiry has passed. */
|
|
121
|
-
#
|
|
157
|
+
#s() {
|
|
122
158
|
const e = this.#i?.expiresAt;
|
|
123
159
|
return e !== void 0 && e <= this.#t();
|
|
124
160
|
}
|
|
@@ -130,48 +166,43 @@ class J {
|
|
|
130
166
|
* in-flight request (single flight).
|
|
131
167
|
*/
|
|
132
168
|
establish() {
|
|
169
|
+
if (this.#a) return Promise.reject(k());
|
|
133
170
|
if (this.#i) {
|
|
134
|
-
if (!this.#
|
|
171
|
+
if (!this.#s()) return Promise.resolve(this.#i);
|
|
135
172
|
this.#i = void 0;
|
|
136
173
|
}
|
|
137
|
-
|
|
174
|
+
if (this.#r) return this.#r;
|
|
175
|
+
const e = this.#o, i = this.#e.transport.request({
|
|
138
176
|
method: "POST",
|
|
139
177
|
path: "/v1/public/work-sdk/sessions",
|
|
140
178
|
body: { workKey: this.#e.workKey },
|
|
141
179
|
signal: this.#e.signal,
|
|
142
180
|
timeoutMs: this.#e.timeoutMs
|
|
143
|
-
}).then((
|
|
144
|
-
|
|
145
|
-
|
|
181
|
+
}).then((r) => {
|
|
182
|
+
this.#c(e);
|
|
183
|
+
const s = ae(r.body, this.#e.workKey);
|
|
184
|
+
return this.#c(e), this.#i = s, s;
|
|
146
185
|
}).finally(() => {
|
|
147
|
-
this.#r = void 0;
|
|
148
|
-
})
|
|
186
|
+
this.#r === i && (this.#r = void 0);
|
|
187
|
+
});
|
|
188
|
+
return this.#r = i, i;
|
|
149
189
|
}
|
|
150
190
|
async request(e) {
|
|
151
191
|
const i = await this.establish();
|
|
152
|
-
if (!i.token) throw
|
|
192
|
+
if (!i.token) throw C();
|
|
153
193
|
try {
|
|
154
|
-
return await this.#e
|
|
155
|
-
...e,
|
|
156
|
-
authorization: i.token,
|
|
157
|
-
userAuthorization: i.userToken,
|
|
158
|
-
signal: this.#e.signal
|
|
159
|
-
});
|
|
194
|
+
return await this.#l(e, i);
|
|
160
195
|
} catch (r) {
|
|
161
|
-
if (
|
|
196
|
+
if (this.#a) throw k();
|
|
197
|
+
if (!(r instanceof v) || r.code !== "SESSION_EXPIRED") throw r;
|
|
162
198
|
this.#i === i && this.invalidate();
|
|
163
|
-
const
|
|
164
|
-
if (!
|
|
165
|
-
return this.#e
|
|
166
|
-
...e,
|
|
167
|
-
authorization: c.token,
|
|
168
|
-
userAuthorization: c.userToken,
|
|
169
|
-
signal: this.#e.signal
|
|
170
|
-
});
|
|
199
|
+
const s = await this.establish();
|
|
200
|
+
if (!s.token) throw C();
|
|
201
|
+
return this.#l(e, s);
|
|
171
202
|
}
|
|
172
203
|
}
|
|
173
204
|
authenticate(e) {
|
|
174
|
-
if (!this.#i) throw
|
|
205
|
+
if (this.#n(), !this.#i) throw C();
|
|
175
206
|
this.#i = {
|
|
176
207
|
...this.#i,
|
|
177
208
|
userToken: e.userToken,
|
|
@@ -179,19 +210,39 @@ class J {
|
|
|
179
210
|
};
|
|
180
211
|
}
|
|
181
212
|
async signOut() {
|
|
182
|
-
this.invalidate(), await this.establish();
|
|
213
|
+
this.#n(), this.invalidate(), await this.establish();
|
|
183
214
|
}
|
|
184
215
|
/** Drop the token; next `establish()` re-authenticates. */
|
|
185
216
|
invalidate() {
|
|
186
|
-
this.#i = void 0;
|
|
217
|
+
this.#o += 1, this.#i = void 0, this.#r = void 0;
|
|
187
218
|
}
|
|
188
219
|
/** Hard cleanup: forget the token and pending work. */
|
|
189
220
|
destroy() {
|
|
190
|
-
this
|
|
221
|
+
this.#a || (this.#a = !0, this.#o += 1, this.#i = void 0, this.#r = void 0);
|
|
222
|
+
}
|
|
223
|
+
#n() {
|
|
224
|
+
if (this.#a) throw k();
|
|
225
|
+
}
|
|
226
|
+
#c(e) {
|
|
227
|
+
if (this.#n(), e !== this.#o) throw oe();
|
|
228
|
+
}
|
|
229
|
+
async #l(e, i) {
|
|
230
|
+
this.#n();
|
|
231
|
+
try {
|
|
232
|
+
const r = await this.#e.transport.request({
|
|
233
|
+
...e,
|
|
234
|
+
authorization: i.token,
|
|
235
|
+
userAuthorization: i.userToken,
|
|
236
|
+
signal: this.#e.signal
|
|
237
|
+
});
|
|
238
|
+
return this.#n(), r;
|
|
239
|
+
} catch (r) {
|
|
240
|
+
throw this.#a ? k() : r;
|
|
241
|
+
}
|
|
191
242
|
}
|
|
192
243
|
}
|
|
193
|
-
const
|
|
194
|
-
function
|
|
244
|
+
const q = "viceme-access-layer", M = 50;
|
|
245
|
+
function se(t) {
|
|
195
246
|
switch (t) {
|
|
196
247
|
case "SIGN_IN":
|
|
197
248
|
return {
|
|
@@ -210,8 +261,8 @@ function Z(t) {
|
|
|
210
261
|
};
|
|
211
262
|
}
|
|
212
263
|
}
|
|
213
|
-
function
|
|
214
|
-
if (!
|
|
264
|
+
function ce(t) {
|
|
265
|
+
if (!Y(t)) return "操作未完成,请重试。";
|
|
215
266
|
switch (t.code) {
|
|
216
267
|
case "CONFIG_INVALID":
|
|
217
268
|
return "微信授权配置无效,请稍后重试。";
|
|
@@ -225,12 +276,12 @@ function ee(t) {
|
|
|
225
276
|
return t.requestId ? `操作未完成,请重试。请求 ID:${t.requestId}` : "操作未完成,请重试。";
|
|
226
277
|
}
|
|
227
278
|
}
|
|
228
|
-
function
|
|
229
|
-
if (customElements.get(
|
|
279
|
+
function le() {
|
|
280
|
+
if (customElements.get(q)) return;
|
|
230
281
|
class t extends HTMLElement {
|
|
231
282
|
interaction;
|
|
232
283
|
connectedCallback() {
|
|
233
|
-
const i =
|
|
284
|
+
const i = se(this.interaction.action), r = this.attachShadow({ mode: "open" });
|
|
234
285
|
r.innerHTML = `
|
|
235
286
|
<style>
|
|
236
287
|
:host {
|
|
@@ -350,8 +401,43 @@ function te() {
|
|
|
350
401
|
font-size: 1.125rem;
|
|
351
402
|
}
|
|
352
403
|
[data-viceme='panel'][data-action='SIGN_IN'] [data-viceme='profile-description'] {
|
|
353
|
-
|
|
354
|
-
|
|
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;
|
|
355
441
|
}
|
|
356
442
|
[data-viceme='panel'][data-action='SIGN_IN'] [data-viceme='action'] {
|
|
357
443
|
width: 100%;
|
|
@@ -438,6 +524,13 @@ function te() {
|
|
|
438
524
|
</div>
|
|
439
525
|
<p data-viceme="profile-description"></p>
|
|
440
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>
|
|
441
534
|
<p data-viceme="error" role="alert" aria-live="polite"></p>
|
|
442
535
|
<div data-viceme="actions">
|
|
443
536
|
<button data-viceme="action" type="button"></button>
|
|
@@ -446,70 +539,76 @@ function te() {
|
|
|
446
539
|
<iframe data-viceme="frame" title="" referrerpolicy="no-referrer" allow="payment"></iframe>
|
|
447
540
|
</section>
|
|
448
541
|
`;
|
|
449
|
-
const
|
|
450
|
-
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
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(
|
|
454
547
|
"[data-viceme='profile-description']"
|
|
455
|
-
),
|
|
456
|
-
f.textContent = i.label, f.hidden = !1,
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
const
|
|
460
|
-
if (
|
|
461
|
-
|
|
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(
|
|
462
555
|
"aria-label",
|
|
463
|
-
this.interaction.action === "SIGN_IN" ? `授权 ${
|
|
464
|
-
),
|
|
465
|
-
const
|
|
466
|
-
|
|
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);
|
|
467
560
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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");
|
|
473
568
|
};
|
|
474
|
-
|
|
475
|
-
if (
|
|
476
|
-
if (
|
|
477
|
-
|
|
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();
|
|
478
573
|
return;
|
|
479
574
|
}
|
|
480
|
-
const
|
|
481
|
-
if (
|
|
482
|
-
const
|
|
483
|
-
|
|
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();
|
|
484
579
|
}
|
|
485
580
|
});
|
|
486
|
-
const
|
|
487
|
-
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 = "";
|
|
488
583
|
try {
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
584
|
+
const c = await this.interaction.perform();
|
|
585
|
+
if (E || this.interaction.signal?.aborted) {
|
|
586
|
+
c.type !== "completed" && c.cancel();
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
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();
|
|
493
593
|
}
|
|
494
594
|
};
|
|
495
|
-
f.addEventListener("click",
|
|
595
|
+
f.addEventListener("click", P), queueMicrotask(() => f.focus());
|
|
496
596
|
}
|
|
497
597
|
}
|
|
498
|
-
customElements.define(
|
|
598
|
+
customElements.define(q, t);
|
|
499
599
|
}
|
|
500
|
-
const
|
|
501
|
-
if (typeof document > "u" || typeof customElements > "u")
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const e = document.createElement(M);
|
|
600
|
+
const de = async (t) => {
|
|
601
|
+
if (typeof document > "u" || typeof customElements > "u" || t.signal?.aborted) return "dismissed";
|
|
602
|
+
le();
|
|
603
|
+
const e = document.createElement(q);
|
|
505
604
|
e.interaction = t;
|
|
506
605
|
const i = document.documentElement.style.overflow, r = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
507
606
|
document.documentElement.style.overflow = "hidden", document.body.append(e);
|
|
508
607
|
try {
|
|
509
|
-
return await new Promise((
|
|
608
|
+
return await new Promise((s) => {
|
|
510
609
|
e.addEventListener(
|
|
511
610
|
"viceme:access-layer-close",
|
|
512
|
-
(
|
|
611
|
+
(w) => s(w.detail),
|
|
513
612
|
{ once: !0 }
|
|
514
613
|
);
|
|
515
614
|
});
|
|
@@ -517,19 +616,19 @@ const K = async (t) => {
|
|
|
517
616
|
e.remove(), document.documentElement.style.overflow = i, r?.focus();
|
|
518
617
|
}
|
|
519
618
|
};
|
|
520
|
-
function
|
|
619
|
+
function I(t) {
|
|
521
620
|
if (typeof t != "object" || t === null) throw h();
|
|
522
621
|
return t;
|
|
523
622
|
}
|
|
524
623
|
function h() {
|
|
525
|
-
return new
|
|
624
|
+
return new v({
|
|
526
625
|
code: "INTERNAL_ERROR",
|
|
527
626
|
message: "Malformed public API response.",
|
|
528
627
|
retryable: !0
|
|
529
628
|
});
|
|
530
629
|
}
|
|
531
|
-
function
|
|
532
|
-
const e =
|
|
630
|
+
function ue(t) {
|
|
631
|
+
const e = I(t);
|
|
533
632
|
if (typeof e.id != "string" || !(typeof e.displayName == "string" || e.displayName === null) || !(typeof e.avatarUrl == "string" || e.avatarUrl === null))
|
|
534
633
|
throw h();
|
|
535
634
|
return {
|
|
@@ -538,11 +637,11 @@ function ie(t) {
|
|
|
538
637
|
avatarUrl: e.avatarUrl
|
|
539
638
|
};
|
|
540
639
|
}
|
|
541
|
-
function
|
|
542
|
-
const e =
|
|
640
|
+
function H(t) {
|
|
641
|
+
const e = I(t);
|
|
543
642
|
if (typeof e.following != "boolean" || !(typeof e.followedAt == "string" || e.followedAt === null))
|
|
544
643
|
throw h();
|
|
545
|
-
const i =
|
|
644
|
+
const i = I(e.creator);
|
|
546
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)
|
|
547
646
|
throw h();
|
|
548
647
|
return {
|
|
@@ -557,8 +656,8 @@ function F(t) {
|
|
|
557
656
|
}
|
|
558
657
|
};
|
|
559
658
|
}
|
|
560
|
-
function
|
|
561
|
-
const e =
|
|
659
|
+
function fe(t) {
|
|
660
|
+
const e = I(t), i = /* @__PURE__ */ new Set([
|
|
562
661
|
"PUBLIC",
|
|
563
662
|
"OWNER",
|
|
564
663
|
"FOLLOWING",
|
|
@@ -577,11 +676,11 @@ function re(t) {
|
|
|
577
676
|
nextAction: e.nextAction
|
|
578
677
|
};
|
|
579
678
|
}
|
|
580
|
-
function
|
|
581
|
-
const e =
|
|
679
|
+
function me(t) {
|
|
680
|
+
const e = I(t);
|
|
582
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"))
|
|
583
682
|
throw h();
|
|
584
|
-
const i = e.price === null ? null :
|
|
683
|
+
const i = e.price === null ? null : I(e.price);
|
|
585
684
|
if (i !== null && (!Number.isInteger(i.amountCents) || i.amountCents <= 0 || i.currency !== "CNY") || e.policyType === "WORK_ENTITLEMENT" != (i !== null))
|
|
586
685
|
throw h();
|
|
587
686
|
return {
|
|
@@ -591,333 +690,369 @@ function ae(t) {
|
|
|
591
690
|
price: i === null ? null : { amountCents: i.amountCents, currency: "CNY" }
|
|
592
691
|
};
|
|
593
692
|
}
|
|
594
|
-
function
|
|
693
|
+
function he() {
|
|
595
694
|
const t = crypto.getRandomValues(new Uint8Array(32));
|
|
596
|
-
return
|
|
695
|
+
return pe(t);
|
|
597
696
|
}
|
|
598
|
-
function
|
|
697
|
+
function pe(t) {
|
|
599
698
|
let e = "";
|
|
600
699
|
for (const i of t) e += String.fromCharCode(i);
|
|
601
700
|
return btoa(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
602
701
|
}
|
|
603
|
-
function
|
|
702
|
+
function ye() {
|
|
604
703
|
return typeof document < "u" && document.documentElement.lang.toLowerCase() === "en-us" ? "en-US" : "zh-CN";
|
|
605
704
|
}
|
|
606
|
-
function
|
|
607
|
-
const e = () => new
|
|
705
|
+
function we(t) {
|
|
706
|
+
const e = () => new v({
|
|
608
707
|
code: "AUTH_CANCELLED",
|
|
609
708
|
message: "The interactive action was cancelled.",
|
|
610
709
|
retryable: !1
|
|
611
|
-
}), i = (
|
|
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();
|
|
715
|
+
});
|
|
716
|
+
let o;
|
|
717
|
+
try {
|
|
718
|
+
o = (t.presenter ?? de)({
|
|
719
|
+
...a,
|
|
720
|
+
signal: t.signal
|
|
721
|
+
});
|
|
722
|
+
} catch (l) {
|
|
723
|
+
o = Promise.reject(l);
|
|
724
|
+
}
|
|
725
|
+
return Promise.race([o, d]).then((l) => {
|
|
726
|
+
if (t.signal.aborted) throw k();
|
|
727
|
+
return l;
|
|
728
|
+
}).finally(() => {
|
|
729
|
+
n && t.signal.removeEventListener("abort", n);
|
|
730
|
+
});
|
|
731
|
+
}, r = (a, n, d, o, l, g) => {
|
|
612
732
|
if (typeof window > "u")
|
|
613
|
-
throw new
|
|
733
|
+
throw new v({
|
|
614
734
|
code: "CONFIG_INVALID",
|
|
615
735
|
message: "Interactive access requires a browser window.",
|
|
616
736
|
retryable: !1
|
|
617
737
|
});
|
|
618
|
-
let
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
},
|
|
622
|
-
|
|
623
|
-
}),
|
|
624
|
-
if (!
|
|
625
|
-
const
|
|
626
|
-
if (!(
|
|
627
|
-
if (
|
|
628
|
-
|
|
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(
|
|
629
749
|
{
|
|
630
|
-
type: `viceme:${
|
|
750
|
+
type: `viceme:${o}:init`,
|
|
631
751
|
workKey: t.workKey,
|
|
632
|
-
channel:
|
|
752
|
+
channel: d,
|
|
633
753
|
...l
|
|
634
754
|
},
|
|
635
|
-
|
|
755
|
+
n
|
|
636
756
|
);
|
|
637
757
|
return;
|
|
638
758
|
}
|
|
639
|
-
if (
|
|
640
|
-
|
|
759
|
+
if (u.type === `viceme:${o}:cancelled`) {
|
|
760
|
+
p(), m(e());
|
|
641
761
|
return;
|
|
642
762
|
}
|
|
643
|
-
|
|
763
|
+
u.type === `viceme:${o}:complete` && (p(), g(u).then(A, m));
|
|
644
764
|
}
|
|
645
765
|
};
|
|
646
|
-
return window.addEventListener("message",
|
|
766
|
+
return window.addEventListener("message", E), {
|
|
647
767
|
type: "frame",
|
|
648
|
-
url:
|
|
649
|
-
completion:
|
|
768
|
+
url: a,
|
|
769
|
+
completion: b,
|
|
650
770
|
cancel() {
|
|
651
|
-
|
|
771
|
+
p(), A();
|
|
652
772
|
}
|
|
653
773
|
};
|
|
654
|
-
},
|
|
774
|
+
}, s = async () => {
|
|
655
775
|
if (await t.ready(), typeof window > "u")
|
|
656
|
-
throw new
|
|
776
|
+
throw new v({
|
|
657
777
|
code: "CONFIG_INVALID",
|
|
658
778
|
message: "Interactive access requires a browser window.",
|
|
659
779
|
retryable: !1
|
|
660
780
|
});
|
|
661
|
-
const
|
|
662
|
-
|
|
781
|
+
const a = he(), n = new URL("/sdk/login", t.widgetOrigin);
|
|
782
|
+
n.search = new URLSearchParams({
|
|
663
783
|
workKey: t.workKey,
|
|
664
|
-
channel:
|
|
784
|
+
channel: a,
|
|
665
785
|
parentOrigin: window.location.origin,
|
|
666
|
-
locale:
|
|
786
|
+
locale: ye()
|
|
667
787
|
}).toString();
|
|
668
|
-
const
|
|
669
|
-
if (!
|
|
670
|
-
return
|
|
671
|
-
|
|
788
|
+
const d = t.session.snapshot?.token;
|
|
789
|
+
if (!d) throw h();
|
|
790
|
+
return r(
|
|
791
|
+
n.toString(),
|
|
672
792
|
t.widgetOrigin,
|
|
673
|
-
|
|
793
|
+
a,
|
|
674
794
|
"auth",
|
|
675
|
-
{ workSessionToken:
|
|
676
|
-
async (
|
|
677
|
-
if (typeof
|
|
795
|
+
{ workSessionToken: d },
|
|
796
|
+
async (o) => {
|
|
797
|
+
if (typeof o.userToken != "string")
|
|
678
798
|
throw h();
|
|
679
|
-
t.session.authenticate({ userToken:
|
|
799
|
+
t.session.authenticate({ userToken: o.userToken, user: ue(o.user) });
|
|
680
800
|
}
|
|
681
801
|
);
|
|
682
|
-
},
|
|
802
|
+
}, w = async () => (await t.ready(), H(
|
|
683
803
|
(await t.session.request({ method: "GET", path: "/v1/public/work-sdk/follow" })).body
|
|
684
|
-
)),
|
|
804
|
+
)), f = async () => (await t.ready(), H(
|
|
685
805
|
(await t.session.request({ method: "PUT", path: "/v1/public/work-sdk/follow" })).body
|
|
686
|
-
)),
|
|
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 = {
|
|
687
821
|
async getState() {
|
|
688
822
|
await t.ready();
|
|
689
|
-
const
|
|
690
|
-
return { authenticated:
|
|
823
|
+
const a = t.session.snapshot?.user ?? null;
|
|
824
|
+
return { authenticated: a !== null, user: a };
|
|
691
825
|
},
|
|
692
826
|
async signIn() {
|
|
693
|
-
if (await
|
|
827
|
+
if (await t.ready(), await i({
|
|
694
828
|
featureKey: "auth",
|
|
695
829
|
reason: "AUTH_REQUIRED",
|
|
696
830
|
action: "SIGN_IN",
|
|
697
|
-
|
|
831
|
+
...L(),
|
|
832
|
+
perform: s
|
|
698
833
|
}) === "dismissed") throw e();
|
|
699
834
|
return this.getState();
|
|
700
835
|
},
|
|
701
836
|
async signOut() {
|
|
702
837
|
await t.ready(), await t.session.signOut();
|
|
703
838
|
}
|
|
704
|
-
},
|
|
705
|
-
getState:
|
|
706
|
-
follow:
|
|
839
|
+
}, T = {
|
|
840
|
+
getState: w,
|
|
841
|
+
follow: f,
|
|
707
842
|
unfollow: async () => {
|
|
708
|
-
throw new
|
|
843
|
+
throw new v({
|
|
709
844
|
code: "CAPABILITY_DISABLED",
|
|
710
845
|
message: "Unfollow is not exposed by website access.",
|
|
711
846
|
retryable: !1
|
|
712
847
|
});
|
|
713
848
|
}
|
|
714
|
-
},
|
|
849
|
+
}, O = async (a) => {
|
|
715
850
|
await t.ready();
|
|
716
|
-
const
|
|
851
|
+
const n = I(
|
|
717
852
|
(await t.session.request({
|
|
718
853
|
method: "POST",
|
|
719
854
|
path: "/v1/public/work-sdk/access/check",
|
|
720
|
-
body: { featureKeys:
|
|
855
|
+
body: { featureKeys: a }
|
|
721
856
|
})).body
|
|
722
|
-
),
|
|
857
|
+
), d = I(n.decisions);
|
|
723
858
|
return Object.fromEntries(
|
|
724
|
-
Object.entries(
|
|
859
|
+
Object.entries(d).map(([o, l]) => [o, fe(l)])
|
|
725
860
|
);
|
|
726
|
-
},
|
|
861
|
+
}, N = async (a, n = {}) => {
|
|
727
862
|
await t.ready();
|
|
728
|
-
const
|
|
729
|
-
featureKey:
|
|
730
|
-
locale:
|
|
731
|
-
},
|
|
863
|
+
const d = {
|
|
864
|
+
featureKey: a,
|
|
865
|
+
locale: n.locale ?? "zh-CN"
|
|
866
|
+
}, o = I(
|
|
732
867
|
(await t.session.request({
|
|
733
868
|
method: "POST",
|
|
734
869
|
path: "/v1/public/work-sdk/checkout",
|
|
735
|
-
body:
|
|
870
|
+
body: d
|
|
736
871
|
})).body
|
|
737
872
|
);
|
|
738
|
-
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))
|
|
739
874
|
throw h();
|
|
740
875
|
let l;
|
|
741
876
|
try {
|
|
742
|
-
l = new URL(
|
|
877
|
+
l = new URL(o.checkoutUrl);
|
|
743
878
|
} catch {
|
|
744
879
|
throw h();
|
|
745
880
|
}
|
|
746
|
-
if (!
|
|
881
|
+
if (!o.alreadyOwned && (l.protocol !== "https:" || l.origin !== t.widgetOrigin))
|
|
747
882
|
throw h();
|
|
748
883
|
return {
|
|
749
|
-
checkoutUrl:
|
|
750
|
-
alreadyOwned:
|
|
751
|
-
expiresAt:
|
|
884
|
+
checkoutUrl: o.checkoutUrl,
|
|
885
|
+
alreadyOwned: o.alreadyOwned,
|
|
886
|
+
expiresAt: o.expiresAt
|
|
752
887
|
};
|
|
753
|
-
},
|
|
754
|
-
if (
|
|
755
|
-
const
|
|
888
|
+
}, U = (a, n) => {
|
|
889
|
+
if (a.alreadyOwned) return { type: "completed" };
|
|
890
|
+
const d = Date.parse(a.expiresAt);
|
|
756
891
|
if (typeof window > "u")
|
|
757
|
-
throw new
|
|
892
|
+
throw new v({
|
|
758
893
|
code: "CONFIG_INVALID",
|
|
759
894
|
message: "Hosted checkout requires a browser window.",
|
|
760
895
|
retryable: !1
|
|
761
896
|
});
|
|
762
|
-
let
|
|
763
|
-
const
|
|
764
|
-
|
|
765
|
-
}),
|
|
766
|
-
l && clearTimeout(l),
|
|
767
|
-
},
|
|
768
|
-
|
|
769
|
-
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({
|
|
770
905
|
code: "SESSION_EXPIRED",
|
|
771
906
|
message: "Hosted checkout session expired.",
|
|
772
907
|
retryable: !0
|
|
773
908
|
})
|
|
774
909
|
));
|
|
775
|
-
},
|
|
776
|
-
if (!
|
|
777
|
-
const
|
|
778
|
-
if (
|
|
779
|
-
|
|
910
|
+
}, E = () => {
|
|
911
|
+
if (!o || document.visibilityState === "hidden") return;
|
|
912
|
+
const c = d - t.now();
|
|
913
|
+
if (c <= 0) {
|
|
914
|
+
b();
|
|
780
915
|
return;
|
|
781
916
|
}
|
|
782
917
|
l = setTimeout(() => {
|
|
783
|
-
|
|
784
|
-
}, Math.min(1500,
|
|
785
|
-
},
|
|
786
|
-
if (
|
|
918
|
+
y();
|
|
919
|
+
}, Math.min(1500, c));
|
|
920
|
+
}, y = async () => {
|
|
921
|
+
if (o)
|
|
787
922
|
try {
|
|
788
|
-
const
|
|
789
|
-
if (!
|
|
790
|
-
if (
|
|
791
|
-
|
|
923
|
+
const c = (await O([n]))[n];
|
|
924
|
+
if (!c) throw h();
|
|
925
|
+
if (c.allowed) {
|
|
926
|
+
o = !1, p(), S();
|
|
792
927
|
return;
|
|
793
928
|
}
|
|
794
|
-
|
|
795
|
-
} catch (
|
|
796
|
-
|
|
929
|
+
E();
|
|
930
|
+
} catch (c) {
|
|
931
|
+
o = !1, p(), A(c);
|
|
797
932
|
}
|
|
798
933
|
};
|
|
799
|
-
function
|
|
800
|
-
if (
|
|
934
|
+
function u() {
|
|
935
|
+
if (o) {
|
|
801
936
|
if (document.visibilityState === "hidden") {
|
|
802
937
|
l && clearTimeout(l), l = void 0;
|
|
803
938
|
return;
|
|
804
939
|
}
|
|
805
|
-
|
|
940
|
+
E();
|
|
806
941
|
}
|
|
807
942
|
}
|
|
808
|
-
document.addEventListener("visibilitychange",
|
|
809
|
-
const
|
|
810
|
-
return
|
|
943
|
+
document.addEventListener("visibilitychange", u);
|
|
944
|
+
const P = d - t.now();
|
|
945
|
+
return P <= 0 ? b() : (g = setTimeout(b, P), E()), {
|
|
811
946
|
type: "frame",
|
|
812
|
-
url:
|
|
813
|
-
completion:
|
|
947
|
+
url: a.checkoutUrl,
|
|
948
|
+
completion: m,
|
|
814
949
|
cancel() {
|
|
815
|
-
|
|
950
|
+
o && (o = !1, p(), S());
|
|
816
951
|
}
|
|
817
952
|
};
|
|
818
953
|
};
|
|
819
|
-
return { auth:
|
|
954
|
+
return { auth: D, follow: T, access: {
|
|
820
955
|
async getFeatures() {
|
|
821
956
|
await t.ready();
|
|
822
|
-
const
|
|
957
|
+
const a = I(
|
|
823
958
|
(await t.session.request({
|
|
824
959
|
method: "GET",
|
|
825
960
|
path: "/v1/public/work-sdk/access/features"
|
|
826
961
|
})).body
|
|
827
962
|
);
|
|
828
|
-
if (!Array.isArray(
|
|
963
|
+
if (!Array.isArray(a.features) || a.features.length > 100)
|
|
829
964
|
throw h();
|
|
830
|
-
return
|
|
965
|
+
return a.features.map(me);
|
|
831
966
|
},
|
|
832
|
-
async check(
|
|
833
|
-
const
|
|
834
|
-
if (!
|
|
835
|
-
return
|
|
967
|
+
async check(a) {
|
|
968
|
+
const d = (await O([a]))[a];
|
|
969
|
+
if (!d) throw h();
|
|
970
|
+
return d;
|
|
836
971
|
},
|
|
837
|
-
checkMany:
|
|
838
|
-
async require(
|
|
839
|
-
let
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
o = await this.check(n);
|
|
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);
|
|
845
979
|
continue;
|
|
846
980
|
}
|
|
847
|
-
if (await
|
|
848
|
-
featureKey:
|
|
849
|
-
reason:
|
|
850
|
-
action:
|
|
851
|
-
...
|
|
852
|
-
perform: async () =>
|
|
853
|
-
}) === "dismissed") return
|
|
854
|
-
|
|
981
|
+
if (await i({
|
|
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);
|
|
855
989
|
}
|
|
856
|
-
return
|
|
990
|
+
return n;
|
|
857
991
|
},
|
|
858
992
|
async refresh() {
|
|
859
993
|
await t.ready();
|
|
860
994
|
}
|
|
861
995
|
}, checkout: {
|
|
862
|
-
async open(
|
|
863
|
-
const
|
|
864
|
-
if (
|
|
865
|
-
if (await (
|
|
866
|
-
featureKey:
|
|
996
|
+
async open(a) {
|
|
997
|
+
const n = await N(a.featureKey, a);
|
|
998
|
+
if (n.alreadyOwned) return n;
|
|
999
|
+
if (await i({
|
|
1000
|
+
featureKey: a.featureKey,
|
|
867
1001
|
reason: "PURCHASE_REQUIRED",
|
|
868
1002
|
action: "CHECKOUT",
|
|
869
|
-
perform: async () =>
|
|
1003
|
+
perform: async () => U(n, a.featureKey)
|
|
870
1004
|
}) === "dismissed") throw e();
|
|
871
|
-
return
|
|
1005
|
+
return n;
|
|
872
1006
|
}
|
|
873
1007
|
} };
|
|
874
1008
|
}
|
|
875
|
-
class
|
|
1009
|
+
class ge extends DOMException {
|
|
876
1010
|
constructor() {
|
|
877
1011
|
super("ViceMe client destroyed.", "AbortError");
|
|
878
1012
|
}
|
|
879
1013
|
}
|
|
880
|
-
class
|
|
881
|
-
#e = new
|
|
1014
|
+
class Ie {
|
|
1015
|
+
#e = new re();
|
|
882
1016
|
#t;
|
|
883
1017
|
#i;
|
|
884
1018
|
#r = new AbortController();
|
|
885
|
-
#
|
|
1019
|
+
#o;
|
|
886
1020
|
auth;
|
|
887
1021
|
access;
|
|
888
1022
|
checkout;
|
|
889
1023
|
/** Detaches the caller-signal listener; undefined when none was attached. */
|
|
890
|
-
#
|
|
1024
|
+
#a;
|
|
891
1025
|
constructor(e) {
|
|
892
|
-
this.#i = e.config, this.#t = new
|
|
1026
|
+
this.#i = e.config, this.#t = new ne({
|
|
893
1027
|
workKey: e.config.workKey,
|
|
894
1028
|
transport: e.transport,
|
|
895
1029
|
signal: this.#r.signal,
|
|
896
1030
|
...e.now !== void 0 ? { now: e.now } : {}
|
|
897
1031
|
});
|
|
898
|
-
const i =
|
|
1032
|
+
const i = we({
|
|
899
1033
|
session: this.#t,
|
|
900
1034
|
workKey: e.config.workKey,
|
|
901
|
-
widgetOrigin:
|
|
1035
|
+
widgetOrigin: $[e.config.region],
|
|
902
1036
|
now: e.now ?? (() => Date.now()),
|
|
903
1037
|
presenter: e.presenter,
|
|
904
|
-
|
|
1038
|
+
signal: this.#r.signal,
|
|
1039
|
+
ready: () => this.#s()
|
|
905
1040
|
});
|
|
906
1041
|
this.auth = i.auth, this.access = i.access, this.checkout = i.checkout;
|
|
907
1042
|
const r = e.config.signal;
|
|
908
1043
|
if (r) {
|
|
909
|
-
const
|
|
1044
|
+
const s = () => {
|
|
910
1045
|
this.#r.abort(
|
|
911
1046
|
r.reason instanceof Error ? r.reason : new DOMException("Caller signal aborted.", "AbortError")
|
|
912
1047
|
);
|
|
913
1048
|
};
|
|
914
|
-
r.aborted ?
|
|
915
|
-
r.removeEventListener("abort",
|
|
1049
|
+
r.aborted ? s() : (r.addEventListener("abort", s, { once: !0 }), this.#a = () => {
|
|
1050
|
+
r.removeEventListener("abort", s);
|
|
916
1051
|
});
|
|
917
1052
|
}
|
|
918
1053
|
}
|
|
919
1054
|
get version() {
|
|
920
|
-
return
|
|
1055
|
+
return Q;
|
|
921
1056
|
}
|
|
922
1057
|
get workKey() {
|
|
923
1058
|
return this.#i.workKey;
|
|
@@ -930,18 +1065,18 @@ class pe {
|
|
|
930
1065
|
}
|
|
931
1066
|
/** Internal: public API major, used by the loader registry namespace. */
|
|
932
1067
|
get apiMajor() {
|
|
933
|
-
return
|
|
1068
|
+
return X;
|
|
934
1069
|
}
|
|
935
1070
|
ready() {
|
|
936
|
-
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);
|
|
937
1072
|
}
|
|
938
|
-
async #
|
|
939
|
-
if (this.#e.destroyed) throw
|
|
1073
|
+
async #s() {
|
|
1074
|
+
if (this.#e.destroyed) throw k();
|
|
940
1075
|
await this.ready();
|
|
941
1076
|
try {
|
|
942
|
-
if (await this.#t.establish(), this.#e.destroyed) throw
|
|
1077
|
+
if (await this.#t.establish(), this.#e.destroyed) throw k();
|
|
943
1078
|
} catch (e) {
|
|
944
|
-
throw this.#e.destroyed ?
|
|
1079
|
+
throw this.#e.destroyed ? k() : (this.#t.invalidate(), e);
|
|
945
1080
|
}
|
|
946
1081
|
}
|
|
947
1082
|
hasCapability(e) {
|
|
@@ -965,14 +1100,14 @@ class pe {
|
|
|
965
1100
|
return this.#t.snapshot;
|
|
966
1101
|
}
|
|
967
1102
|
destroy() {
|
|
968
|
-
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);
|
|
969
1104
|
}
|
|
970
1105
|
}
|
|
971
1106
|
export {
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1107
|
+
Ie as V,
|
|
1108
|
+
te as a,
|
|
1109
|
+
ee as i,
|
|
1110
|
+
Ee as r,
|
|
1111
|
+
Se as v
|
|
977
1112
|
};
|
|
978
|
-
//# sourceMappingURL=client-
|
|
1113
|
+
//# sourceMappingURL=client-C1Sw400H.js.map
|