@viceme-ai/sdk 0.6.1 → 0.6.2

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