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