@monetize.software/sdk 3.0.0-alpha.8 → 3.0.0-alpha.9

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 (201) hide show
  1. package/dist/chunks/{PaywallUI-BrDiS6zg.js → PaywallUI-BhQpWSWN.js} +380 -375
  2. package/dist/chunks/PaywallUI-BhQpWSWN.js.map +1 -0
  3. package/dist/chunks/PaywallUI-C7Wp2TiR.js +26 -0
  4. package/dist/chunks/PaywallUI-C7Wp2TiR.js.map +1 -0
  5. package/dist/chunks/ar-7cgIM-Vl.js +2 -0
  6. package/dist/chunks/ar-7cgIM-Vl.js.map +1 -0
  7. package/dist/chunks/{ar-CHae8g-2.js → ar-B2Wg_IrC.js} +2 -2
  8. package/dist/chunks/ar-B2Wg_IrC.js.map +1 -0
  9. package/dist/chunks/{cs-eZTedzaK.js → cs-BNo9Dx0Q.js} +2 -2
  10. package/dist/chunks/cs-BNo9Dx0Q.js.map +1 -0
  11. package/dist/chunks/cs-S05PC5AC.js +2 -0
  12. package/dist/chunks/cs-S05PC5AC.js.map +1 -0
  13. package/dist/chunks/da-Bi4zBG14.js +2 -0
  14. package/dist/chunks/da-Bi4zBG14.js.map +1 -0
  15. package/dist/chunks/{da-Dca6j8fp.js → da-Do9Lq6En.js} +2 -2
  16. package/dist/chunks/da-Do9Lq6En.js.map +1 -0
  17. package/dist/chunks/{de-BCjn3PUI.js → de-C8pDZNvx.js} +2 -2
  18. package/dist/chunks/de-C8pDZNvx.js.map +1 -0
  19. package/dist/chunks/de-nCDB6D2W.js +2 -0
  20. package/dist/chunks/de-nCDB6D2W.js.map +1 -0
  21. package/dist/chunks/el-BrKaa978.js +2 -0
  22. package/dist/chunks/el-BrKaa978.js.map +1 -0
  23. package/dist/chunks/{el-BpXtDTez.js → el-DzMNX-_P.js} +2 -2
  24. package/dist/chunks/el-DzMNX-_P.js.map +1 -0
  25. package/dist/chunks/es-B-Wtyzrl.js +2 -0
  26. package/dist/chunks/es-B-Wtyzrl.js.map +1 -0
  27. package/dist/chunks/{es-B3P4nlMw.js → es-YrKt-q4w.js} +2 -2
  28. package/dist/chunks/es-YrKt-q4w.js.map +1 -0
  29. package/dist/chunks/{fi-BbQ_Bs0Z.js → fi-Bh44pwZ4.js} +2 -2
  30. package/dist/chunks/fi-Bh44pwZ4.js.map +1 -0
  31. package/dist/chunks/fi-D1SGXjnO.js +2 -0
  32. package/dist/chunks/fi-D1SGXjnO.js.map +1 -0
  33. package/dist/chunks/{fr-BKDUXceO.js → fr-Bc0pw4ws.js} +2 -2
  34. package/dist/chunks/fr-Bc0pw4ws.js.map +1 -0
  35. package/dist/chunks/fr-BhYf-iKk.js +2 -0
  36. package/dist/chunks/fr-BhYf-iKk.js.map +1 -0
  37. package/dist/chunks/he-BXAaFv6Y.js +2 -0
  38. package/dist/chunks/he-BXAaFv6Y.js.map +1 -0
  39. package/dist/chunks/{he-BVCHlTtT.js → he-Bfm-bhe3.js} +2 -2
  40. package/dist/chunks/he-Bfm-bhe3.js.map +1 -0
  41. package/dist/chunks/{hi-H_Hshh-7.js → hi-D-O-B9Dn.js} +2 -2
  42. package/dist/chunks/hi-D-O-B9Dn.js.map +1 -0
  43. package/dist/chunks/hi-xblDO0O7.js +2 -0
  44. package/dist/chunks/hi-xblDO0O7.js.map +1 -0
  45. package/dist/chunks/{hu-ZWiNfzvN.js → hu-CmIuAbLL.js} +2 -2
  46. package/dist/chunks/hu-CmIuAbLL.js.map +1 -0
  47. package/dist/chunks/hu-Wa46p0y4.js +2 -0
  48. package/dist/chunks/hu-Wa46p0y4.js.map +1 -0
  49. package/dist/chunks/id-CQEo5X94.js +2 -0
  50. package/dist/chunks/id-CQEo5X94.js.map +1 -0
  51. package/dist/chunks/{id-DeiRYsJ1.js → id-DN7IES-A.js} +2 -2
  52. package/dist/chunks/id-DN7IES-A.js.map +1 -0
  53. package/dist/chunks/it-8AYCm0xz.js +2 -0
  54. package/dist/chunks/it-8AYCm0xz.js.map +1 -0
  55. package/dist/chunks/{it-UH9OzFhg.js → it-Cz5Nmqx5.js} +2 -2
  56. package/dist/chunks/it-Cz5Nmqx5.js.map +1 -0
  57. package/dist/chunks/{ja-BYC8FRN8.js → ja-BH9BlBh2.js} +2 -2
  58. package/dist/chunks/ja-BH9BlBh2.js.map +1 -0
  59. package/dist/chunks/ja-q-COVayn.js +2 -0
  60. package/dist/chunks/ja-q-COVayn.js.map +1 -0
  61. package/dist/chunks/ko-B6HRCscZ.js +2 -0
  62. package/dist/chunks/ko-B6HRCscZ.js.map +1 -0
  63. package/dist/chunks/{ko-Bjs2ZRcF.js → ko-CYV9QuYs.js} +2 -2
  64. package/dist/chunks/ko-CYV9QuYs.js.map +1 -0
  65. package/dist/chunks/{nl-Ch5HFWQO.js → nl-BvkB900D.js} +2 -2
  66. package/dist/chunks/nl-BvkB900D.js.map +1 -0
  67. package/dist/chunks/nl-CAd6_xlm.js +2 -0
  68. package/dist/chunks/nl-CAd6_xlm.js.map +1 -0
  69. package/dist/chunks/{no-CljpinWz.js → no-3s9_ormb.js} +2 -2
  70. package/dist/chunks/no-3s9_ormb.js.map +1 -0
  71. package/dist/chunks/no-CAmz6bz6.js +2 -0
  72. package/dist/chunks/no-CAmz6bz6.js.map +1 -0
  73. package/dist/chunks/{pl-CUcSS0zZ.js → pl-C9WTGQtb.js} +2 -2
  74. package/dist/chunks/pl-C9WTGQtb.js.map +1 -0
  75. package/dist/chunks/pl-DqUSTCaF.js +2 -0
  76. package/dist/chunks/pl-DqUSTCaF.js.map +1 -0
  77. package/dist/chunks/pt-8ARZnH0_.js +2 -0
  78. package/dist/chunks/pt-8ARZnH0_.js.map +1 -0
  79. package/dist/chunks/{pt-BHK0LwkC.js → pt-uFVUv_Op.js} +2 -2
  80. package/dist/chunks/pt-uFVUv_Op.js.map +1 -0
  81. package/dist/chunks/{ro-Bj8cwU2n.js → ro-BrqQ8Au-.js} +2 -2
  82. package/dist/chunks/ro-BrqQ8Au-.js.map +1 -0
  83. package/dist/chunks/ro-D-NMbp2F.js +2 -0
  84. package/dist/chunks/ro-D-NMbp2F.js.map +1 -0
  85. package/dist/chunks/ru-8gbHPh0g.js +2 -0
  86. package/dist/chunks/ru-8gbHPh0g.js.map +1 -0
  87. package/dist/chunks/{ru-CgqNy0Gb.js → ru-DK594dA8.js} +2 -2
  88. package/dist/chunks/ru-DK594dA8.js.map +1 -0
  89. package/dist/chunks/{sv-H7jroOQ5.js → sv-CHNH8-mq.js} +2 -2
  90. package/dist/chunks/sv-CHNH8-mq.js.map +1 -0
  91. package/dist/chunks/sv-D8a8hmx9.js +2 -0
  92. package/dist/chunks/sv-D8a8hmx9.js.map +1 -0
  93. package/dist/chunks/th-DfjUK0Y7.js +2 -0
  94. package/dist/chunks/th-DfjUK0Y7.js.map +1 -0
  95. package/dist/chunks/{th-Dqm-gpGe.js → th-l24Pm5q-.js} +2 -2
  96. package/dist/chunks/th-l24Pm5q-.js.map +1 -0
  97. package/dist/chunks/{tr-D3zPcNtT.js → tr-ADpigSY5.js} +2 -2
  98. package/dist/chunks/tr-ADpigSY5.js.map +1 -0
  99. package/dist/chunks/tr-BdBpz4tL.js +2 -0
  100. package/dist/chunks/tr-BdBpz4tL.js.map +1 -0
  101. package/dist/chunks/{uk-CoIIs3QI.js → uk-CGqo4jek.js} +2 -2
  102. package/dist/chunks/uk-CGqo4jek.js.map +1 -0
  103. package/dist/chunks/uk-Cx1zv1ao.js +2 -0
  104. package/dist/chunks/uk-Cx1zv1ao.js.map +1 -0
  105. package/dist/chunks/{vi-C_fruIbh.js → vi-Dk9bTu6f.js} +2 -2
  106. package/dist/chunks/vi-Dk9bTu6f.js.map +1 -0
  107. package/dist/chunks/vi-oe2dW21I.js +2 -0
  108. package/dist/chunks/vi-oe2dW21I.js.map +1 -0
  109. package/dist/core.cjs +1 -1
  110. package/dist/core.cjs.map +1 -1
  111. package/dist/core.d.ts +21 -13
  112. package/dist/core.js +178 -158
  113. package/dist/core.js.map +1 -1
  114. package/dist/index.cjs +1 -1
  115. package/dist/index.d.ts +21 -13
  116. package/dist/index.js +1 -1
  117. package/dist/ui.cjs +1 -1
  118. package/dist/ui.d.ts +21 -13
  119. package/dist/ui.js +1 -1
  120. package/package.json +1 -1
  121. package/dist/chunks/PaywallUI-BrDiS6zg.js.map +0 -1
  122. package/dist/chunks/PaywallUI-Bvx8nRL0.js +0 -26
  123. package/dist/chunks/PaywallUI-Bvx8nRL0.js.map +0 -1
  124. package/dist/chunks/ar-CHae8g-2.js.map +0 -1
  125. package/dist/chunks/ar-E1mc8SO_.js +0 -2
  126. package/dist/chunks/ar-E1mc8SO_.js.map +0 -1
  127. package/dist/chunks/cs-Dccq6LAT.js +0 -2
  128. package/dist/chunks/cs-Dccq6LAT.js.map +0 -1
  129. package/dist/chunks/cs-eZTedzaK.js.map +0 -1
  130. package/dist/chunks/da-C_4MbEh5.js +0 -2
  131. package/dist/chunks/da-C_4MbEh5.js.map +0 -1
  132. package/dist/chunks/da-Dca6j8fp.js.map +0 -1
  133. package/dist/chunks/de-BCjn3PUI.js.map +0 -1
  134. package/dist/chunks/de-DulxcJj-.js +0 -2
  135. package/dist/chunks/de-DulxcJj-.js.map +0 -1
  136. package/dist/chunks/el-BpXtDTez.js.map +0 -1
  137. package/dist/chunks/el-CVG_1iKB.js +0 -2
  138. package/dist/chunks/el-CVG_1iKB.js.map +0 -1
  139. package/dist/chunks/es-B3P4nlMw.js.map +0 -1
  140. package/dist/chunks/es-ri0uKzUW.js +0 -2
  141. package/dist/chunks/es-ri0uKzUW.js.map +0 -1
  142. package/dist/chunks/fi-BbQ_Bs0Z.js.map +0 -1
  143. package/dist/chunks/fi-CNZqWHjw.js +0 -2
  144. package/dist/chunks/fi-CNZqWHjw.js.map +0 -1
  145. package/dist/chunks/fr-BKDUXceO.js.map +0 -1
  146. package/dist/chunks/fr-CfFOw4hD.js +0 -2
  147. package/dist/chunks/fr-CfFOw4hD.js.map +0 -1
  148. package/dist/chunks/he-BVCHlTtT.js.map +0 -1
  149. package/dist/chunks/he-DN2JEtQb.js +0 -2
  150. package/dist/chunks/he-DN2JEtQb.js.map +0 -1
  151. package/dist/chunks/hi-DxfOerNP.js +0 -2
  152. package/dist/chunks/hi-DxfOerNP.js.map +0 -1
  153. package/dist/chunks/hi-H_Hshh-7.js.map +0 -1
  154. package/dist/chunks/hu-BTImywuV.js +0 -2
  155. package/dist/chunks/hu-BTImywuV.js.map +0 -1
  156. package/dist/chunks/hu-ZWiNfzvN.js.map +0 -1
  157. package/dist/chunks/id-DeiRYsJ1.js.map +0 -1
  158. package/dist/chunks/id-YFuArJA6.js +0 -2
  159. package/dist/chunks/id-YFuArJA6.js.map +0 -1
  160. package/dist/chunks/it-UH9OzFhg.js.map +0 -1
  161. package/dist/chunks/it-mhkzXBM9.js +0 -2
  162. package/dist/chunks/it-mhkzXBM9.js.map +0 -1
  163. package/dist/chunks/ja-6l_z_G9k.js +0 -2
  164. package/dist/chunks/ja-6l_z_G9k.js.map +0 -1
  165. package/dist/chunks/ja-BYC8FRN8.js.map +0 -1
  166. package/dist/chunks/ko-Bjs2ZRcF.js.map +0 -1
  167. package/dist/chunks/ko-YAl4XwHu.js +0 -2
  168. package/dist/chunks/ko-YAl4XwHu.js.map +0 -1
  169. package/dist/chunks/nl-C-9zHtfb.js +0 -2
  170. package/dist/chunks/nl-C-9zHtfb.js.map +0 -1
  171. package/dist/chunks/nl-Ch5HFWQO.js.map +0 -1
  172. package/dist/chunks/no-CljpinWz.js.map +0 -1
  173. package/dist/chunks/no-qzPitLlx.js +0 -2
  174. package/dist/chunks/no-qzPitLlx.js.map +0 -1
  175. package/dist/chunks/pl-CUcSS0zZ.js.map +0 -1
  176. package/dist/chunks/pl-MAIYeuhW.js +0 -2
  177. package/dist/chunks/pl-MAIYeuhW.js.map +0 -1
  178. package/dist/chunks/pt-BHK0LwkC.js.map +0 -1
  179. package/dist/chunks/pt-DqDabE4v.js +0 -2
  180. package/dist/chunks/pt-DqDabE4v.js.map +0 -1
  181. package/dist/chunks/ro-BVs-lHH-.js +0 -2
  182. package/dist/chunks/ro-BVs-lHH-.js.map +0 -1
  183. package/dist/chunks/ro-Bj8cwU2n.js.map +0 -1
  184. package/dist/chunks/ru-CgqNy0Gb.js.map +0 -1
  185. package/dist/chunks/ru-DP7qDAmE.js +0 -2
  186. package/dist/chunks/ru-DP7qDAmE.js.map +0 -1
  187. package/dist/chunks/sv-B3QEYGgd.js +0 -2
  188. package/dist/chunks/sv-B3QEYGgd.js.map +0 -1
  189. package/dist/chunks/sv-H7jroOQ5.js.map +0 -1
  190. package/dist/chunks/th-Dqm-gpGe.js.map +0 -1
  191. package/dist/chunks/th-DzQau9aW.js +0 -2
  192. package/dist/chunks/th-DzQau9aW.js.map +0 -1
  193. package/dist/chunks/tr-D3zPcNtT.js.map +0 -1
  194. package/dist/chunks/tr-cG1YuE1E.js +0 -2
  195. package/dist/chunks/tr-cG1YuE1E.js.map +0 -1
  196. package/dist/chunks/uk-CoIIs3QI.js.map +0 -1
  197. package/dist/chunks/uk-Cvbo0IBW.js +0 -2
  198. package/dist/chunks/uk-Cvbo0IBW.js.map +0 -1
  199. package/dist/chunks/vi-BRtYSBUp.js +0 -2
  200. package/dist/chunks/vi-BRtYSBUp.js.map +0 -1
  201. package/dist/chunks/vi-C_fruIbh.js.map +0 -1
package/dist/core.js CHANGED
@@ -1,9 +1,9 @@
1
- class n extends Error {
1
+ class r extends Error {
2
2
  constructor(t, e, s = {}) {
3
3
  super(e), this.name = "PaywallError", this.code = t, this.status = s.status, this.cause = s.cause;
4
4
  }
5
5
  }
6
- class D extends n {
6
+ class R extends r {
7
7
  constructor(t) {
8
8
  super("not_enough_queries", t.message ?? "Not enough queries", {
9
9
  status: 402
@@ -16,36 +16,36 @@ class E {
16
16
  this.opts = t;
17
17
  }
18
18
  async request(t, e = {}) {
19
- const s = new URL(t, this.opts.apiOrigin).toString(), a = this.opts.fetch ?? fetch, r = new Headers(e.headers);
20
- r.set("Accept", "application/json"), r.set("X-SDK-Version", m), r.set("X-Paywall-Id", this.opts.paywallId), this.opts.capabilities?.length && r.set("X-SDK-Capabilities", this.opts.capabilities.join(","));
19
+ const s = new URL(t, this.opts.apiOrigin).toString(), a = this.opts.fetch ?? fetch, n = new Headers(e.headers);
20
+ n.set("Accept", "application/json"), n.set("X-SDK-Version", m), n.set("X-Paywall-Id", this.opts.paywallId), this.opts.capabilities?.length && n.set("X-SDK-Capabilities", this.opts.capabilities.join(","));
21
21
  const o = await this.opts.getAuthToken?.();
22
- o && r.set("Authorization", `Bearer ${o}`);
22
+ o && n.set("Authorization", `Bearer ${o}`);
23
23
  const d = typeof FormData < "u" && e.body instanceof FormData;
24
- e.body && !r.has("Content-Type") && !d && r.set("Content-Type", "application/json");
24
+ e.body && !n.has("Content-Type") && !d && n.set("Content-Type", "application/json");
25
25
  let u;
26
26
  try {
27
27
  u = await a(s, {
28
28
  ...e,
29
- headers: r,
29
+ headers: n,
30
30
  credentials: "omit"
31
31
  });
32
32
  } catch (c) {
33
- throw (c && typeof c == "object" && "name" in c ? c.name : void 0) === "AbortError" ? new n("aborted", "Request aborted", { cause: c }) : new n("network_error", "Network request failed", { cause: c });
33
+ throw (c && typeof c == "object" && "name" in c ? c.name : void 0) === "AbortError" ? new r("aborted", "Request aborted", { cause: c }) : new r("network_error", "Network request failed", { cause: c });
34
34
  }
35
35
  const y = (u.headers.get("content-type") ?? "").includes("application/json") ? await u.json().catch(() => null) : null;
36
36
  if (!u.ok) {
37
37
  const c = y && typeof y == "object" && "code" in y && String(y.code) || `http_${u.status}`, g = y && typeof y == "object" && "message" in y && String(y.message) || u.statusText || "Request failed";
38
- throw new n(c, g, { status: u.status, cause: y });
38
+ throw new r(c, g, { status: u.status, cause: y });
39
39
  }
40
40
  return y;
41
41
  }
42
42
  }
43
- class q {
43
+ class D {
44
44
  constructor(t) {
45
45
  if (!t.paywallId)
46
- throw new n("invalid_config", "paywallId is required");
46
+ throw new r("invalid_config", "paywallId is required");
47
47
  if (!t.apiOrigin)
48
- throw new n(
48
+ throw new r(
49
49
  "invalid_config",
50
50
  "apiOrigin is required. Pass the paywall custom_domain configured in the platform."
51
51
  );
@@ -61,8 +61,8 @@ class q {
61
61
  s.searchParams.set("paywall_id", this.paywallId);
62
62
  const a = new Headers(t.headers);
63
63
  a.set("X-SDK-Version", m), a.set("X-Paywall-Id", this.paywallId), this.capabilities?.length && a.set("X-SDK-Capabilities", this.capabilities.join(","));
64
- const r = await this.auth?.getAccessToken();
65
- r ? a.set("Authorization", `Bearer ${r}`) : this.userId && a.set("X-User-ID", this.userId);
64
+ const n = await this.auth?.getAccessToken();
65
+ n ? a.set("Authorization", `Bearer ${n}`) : this.userId && a.set("X-User-ID", this.userId);
66
66
  const o = typeof FormData < "u" && t.body instanceof FormData, d = typeof Blob < "u" && t.body instanceof Blob, u = typeof ReadableStream < "u" && t.body instanceof ReadableStream, f = typeof t.body == "string";
67
67
  let h;
68
68
  t.body === void 0 || t.body === null ? h = void 0 : o || d || u || f ? h = t.body : (h = JSON.stringify(t.body), a.has("Content-Type") || a.set("Content-Type", "application/json"));
@@ -77,16 +77,16 @@ class q {
77
77
  credentials: "omit"
78
78
  });
79
79
  } catch (p) {
80
- const R = p instanceof Error ? p.message : String(p);
81
- throw new n("network_error", `Network request failed: ${R}`, { cause: p });
80
+ const P = p instanceof Error ? p.message : String(p);
81
+ throw new r("network_error", `Network request failed: ${P}`, { cause: p });
82
82
  }
83
83
  if (c.status === 402) {
84
- const p = await K(c);
84
+ const p = await q(c);
85
85
  throw this.onQuotaExceeded?.(p), p;
86
86
  }
87
87
  if (!c.ok) {
88
88
  const p = await $(c.clone());
89
- throw new n(
89
+ throw new r(
90
90
  p ?? `http_${c.status}`,
91
91
  c.statusText || "Gateway request failed",
92
92
  { status: c.status }
@@ -96,7 +96,7 @@ class q {
96
96
  return this.onChargeSuccess?.(g), c;
97
97
  }
98
98
  }
99
- async function K(i) {
99
+ async function q(i) {
100
100
  let t = {};
101
101
  try {
102
102
  t = await i.json();
@@ -108,7 +108,7 @@ async function K(i) {
108
108
  const a = e[0];
109
109
  Array.isArray(a) ? s = a : a && Array.isArray(a.balances) && (s = a.balances);
110
110
  }
111
- return new D({
111
+ return new R({
112
112
  balances: s,
113
113
  queryType: t.details?.queryType ?? "",
114
114
  currentBalance: t.details?.currentBalance ?? null
@@ -149,8 +149,8 @@ const M = {
149
149
  const e = chrome?.storage?.onChanged;
150
150
  if (!e) return () => {
151
151
  };
152
- const s = (a, r) => {
153
- if (r !== "local") return;
152
+ const s = (a, n) => {
153
+ if (n !== "local") return;
154
154
  const o = a[i];
155
155
  o && t(typeof o.newValue == "string" ? o.newValue : null);
156
156
  };
@@ -184,15 +184,15 @@ const M = {
184
184
  };
185
185
  return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
186
186
  }
187
- }, v = /* @__PURE__ */ new Map(), J = {
187
+ }, I = /* @__PURE__ */ new Map(), J = {
188
188
  async getItem(i) {
189
- return v.get(i) ?? null;
189
+ return I.get(i) ?? null;
190
190
  },
191
191
  async setItem(i, t) {
192
- v.set(i, t);
192
+ I.set(i, t);
193
193
  },
194
194
  async removeItem(i) {
195
- v.delete(i);
195
+ I.delete(i);
196
196
  }
197
197
  };
198
198
  function L(i) {
@@ -253,7 +253,7 @@ async function b(i) {
253
253
  }
254
254
  return t;
255
255
  }
256
- const H = 5e3, V = 30 * 6e4, _ = 60 * 6e4, j = 5 * 6e4, S = {
256
+ const H = 5e3, V = 30 * 6e4, _ = 60 * 6e4, j = 5 * 6e4, v = {
257
257
  has_active_subscription: !1,
258
258
  purchases: [],
259
259
  trial: null,
@@ -262,10 +262,10 @@ const H = 5e3, V = 30 * 6e4, _ = 60 * 6e4, j = 5 * 6e4, S = {
262
262
  function B(i) {
263
263
  return i && (i.email || i.userId || i.anonymousId) || "guest";
264
264
  }
265
- function G(i, t) {
265
+ function X(i, t) {
266
266
  return i === t ? !0 : !i || !t ? !1 : JSON.stringify(i) === JSON.stringify(t);
267
267
  }
268
- const X = 5e3, A = 5 * 6e4, z = 3e4;
268
+ const G = 5e3, A = 5 * 6e4, z = 3e4;
269
269
  function Q(i, t) {
270
270
  if (i === t) return !0;
271
271
  if (!i || !t || i.length !== t.length) return !1;
@@ -273,12 +273,12 @@ function Q(i, t) {
273
273
  if (i[e].type !== t[e].type || i[e].count !== t[e].count) return !1;
274
274
  return !0;
275
275
  }
276
- class ut {
276
+ class dt {
277
277
  constructor(t) {
278
278
  if (this.cachedBootstrap = null, this.cachedBootstrapAt = 0, this.inflightBootstrap = null, this.bootstrapListeners = /* @__PURE__ */ new Set(), this.bootstrapStorageUnwatch = null, this.authUnsubscribe = null, this.cachedUser = null, this.cachedUserAt = 0, this.inflightUser = null, this.userListeners = /* @__PURE__ */ new Set(), this.visitorIdPromise = null, this.visitorId = null, this.inflightCheckouts = /* @__PURE__ */ new Map(), this.cachedBalances = null, this.cachedBalancesAt = 0, this.balancesStorageUnwatch = null, this.inflightBalances = null, this.balanceListeners = /* @__PURE__ */ new Set(), this.previewVersionCounter = 0, !t.paywallId)
279
- throw new n("invalid_config", "paywallId is required");
279
+ throw new r("invalid_config", "paywallId is required");
280
280
  if (!t.apiOrigin)
281
- throw new n(
281
+ throw new r(
282
282
  "invalid_config",
283
283
  'apiOrigin is required. Pass the paywall custom_domain configured in the platform (e.g. "https://pay.your-domain.com"). The legacy "appbox.space" fallback is not used in SDK 3.0.'
284
284
  );
@@ -296,8 +296,8 @@ class ut {
296
296
  // Authorization-хедер просто не выставится.
297
297
  getAuthToken: t.auth ? () => t.auth.getAccessToken() : void 0
298
298
  }), t.auth && (this.authUnsubscribe = t.auth.onAuthChange((s, a) => {
299
- const r = a ? T(a.user) : void 0;
300
- W(this.identity, r) || this.setIdentity(r);
299
+ const n = a ? T(a.user) : void 0;
300
+ W(this.identity, n) || this.setIdentity(n);
301
301
  })), this.hydrateUserFromStorage(), this.hydrateBootstrapFromStorage(), this.subscribeBootstrapStorage(), this.hydrateBalancesFromStorage(), this.subscribeBalancesStorage(), this.visitorIdPromise = b(this.storage).then((s) => (this.visitorId = s, s));
302
302
  }
303
303
  /**
@@ -314,7 +314,7 @@ class ut {
314
314
  }
315
315
  setIdentity(t) {
316
316
  this.identity = t, this.cachedUser = null, this.cachedUserAt = 0, this.inflightUser = null, this.cachedBalances = null, this.cachedBalancesAt = 0, this.inflightBalances = null, this.balancesStorageUnwatch && (this.balancesStorageUnwatch(), this.balancesStorageUnwatch = null), this.hydrateBalancesFromStorage(), this.subscribeBalancesStorage(), this.hydrateUserFromStorage(), t ? this.getUser({ force: !0 }).catch(() => {
317
- }) : (this.applyUser(S), this.applyBalances([]));
317
+ }) : (this.applyUser(v), this.applyBalances([]));
318
318
  }
319
319
  /**
320
320
  * Отписаться от auth-event'ов и сбросить listener'ы. Вызывать когда
@@ -337,7 +337,7 @@ class ut {
337
337
  const e = typeof t == "boolean" ? { force: t } : t;
338
338
  if (this.previewMode) {
339
339
  if (this.cachedBootstrap) return this.cachedBootstrap;
340
- throw new n(
340
+ throw new r(
341
341
  "invalid_config",
342
342
  "BillingClient in preview mode but cachedBootstrap is not seeded. Call setBootstrap(bootstrap) before open()."
343
343
  );
@@ -396,8 +396,8 @@ class ut {
396
396
  for (const a of this.bootstrapListeners)
397
397
  try {
398
398
  a(s);
399
- } catch (r) {
400
- console.warn("[paywall] onBootstrapChange listener threw", r);
399
+ } catch (n) {
400
+ console.warn("[paywall] onBootstrapChange listener threw", n);
401
401
  }
402
402
  }
403
403
  // Network primitive — единая точка для force-запроса, revalidate'а и
@@ -413,8 +413,8 @@ class ut {
413
413
  });
414
414
  if ("unchanged" in a && a.unchanged)
415
415
  return this.cachedBootstrap ? (this.cachedBootstrapAt = Date.now(), a.user && this.applyUser(a.user), this.cachedBootstrap) : this.fetchBootstrap({ signal: t.signal });
416
- const r = a;
417
- return Y(r.settings.custom_domain, this.apiOrigin), r.layout || (r.layout = O(r.settings, r.prices)), w(r), this.applyBootstrap(r, { persist: !0 }), r.user && this.applyUser(r.user), r;
416
+ const n = a;
417
+ return Y(n.settings.custom_domain, this.apiOrigin), n.layout || (n.layout = O(n.settings, n.prices)), w(n), this.applyBootstrap(n, { persist: !0 }), n.user && this.applyUser(n.user), n;
418
418
  }
419
419
  // Фоновый revalidate из stale-while-revalidate ветки. Дедуплицируется через
420
420
  // `inflightBootstrap`, чтобы параллельные revalidate'ы не пересекались.
@@ -437,8 +437,8 @@ class ut {
437
437
  for (const a of this.bootstrapListeners)
438
438
  try {
439
439
  a(t);
440
- } catch (r) {
441
- console.warn("[paywall] onBootstrapChange listener threw", r);
440
+ } catch (n) {
441
+ console.warn("[paywall] onBootstrapChange listener threw", n);
442
442
  }
443
443
  }
444
444
  async hydrateBootstrapFromStorage() {
@@ -531,7 +531,7 @@ class ut {
531
531
  * есть `navigator.language`.
532
532
  */
533
533
  getUserLanguage() {
534
- const t = typeof navigator < "u" && navigator.language ? navigator.language : null, e = this.cachedBootstrap?.settings.locale_default ?? null, s = this.cachedBootstrap ? N(this.cachedBootstrap) : null;
534
+ const t = typeof navigator < "u" && navigator.language ? navigator.language : null, e = this.cachedBootstrap?.settings.locale_default ?? null, s = this.cachedBootstrap ? K(this.cachedBootstrap) : null;
535
535
  return { tag: s ?? t ?? e, applied: s, browserLanguage: t, countryLanguage: e };
536
536
  }
537
537
  /**
@@ -546,7 +546,7 @@ class ut {
546
546
  return !t && this.cachedUser && Date.now() - this.cachedUserAt < H ? this.cachedUser : this.inflightUser ? this.inflightUser : (this.inflightUser = (async () => {
547
547
  try {
548
548
  if (!this.identity?.email)
549
- return this.applyUser(S), S;
549
+ return this.applyUser(v), v;
550
550
  const s = await this.api.request(
551
551
  `/api/v1/paywall/${this.paywallId}/user-state`,
552
552
  { headers: { "X-User-Email": this.identity.email }, signal: e }
@@ -582,8 +582,8 @@ class ut {
582
582
  if (s === "sync")
583
583
  try {
584
584
  t(a);
585
- } catch (r) {
586
- console.warn("[paywall] onUserChange initial sync threw", r);
585
+ } catch (n) {
586
+ console.warn("[paywall] onUserChange initial sync threw", n);
587
587
  }
588
588
  else
589
589
  queueMicrotask(() => {
@@ -599,7 +599,7 @@ class ut {
599
599
  return this.cachedUser;
600
600
  }
601
601
  applyUser(t) {
602
- const e = !G(this.cachedUser, t);
602
+ const e = !X(this.cachedUser, t);
603
603
  if (this.cachedUser = t, this.cachedUserAt = Date.now(), e) {
604
604
  this.persistUser(t);
605
605
  for (const s of this.userListeners)
@@ -648,7 +648,7 @@ class ut {
648
648
  */
649
649
  async getBalances({ force: t = !1, signal: e } = {}) {
650
650
  const s = Date.now(), a = this.cachedBalances ? s - this.cachedBalancesAt : 1 / 0;
651
- return !t && this.cachedBalances && (a < X || a < z) ? this.cachedBalances : !t && this.cachedBalances && a < A ? (this.fetchBalances({ signal: e }).catch(() => {
651
+ return !t && this.cachedBalances && (a < G || a < z) ? this.cachedBalances : !t && this.cachedBalances && a < A ? (this.fetchBalances({ signal: e }).catch(() => {
652
652
  }), this.cachedBalances) : this.inflightBalances ? this.inflightBalances : this.fetchBalances({ signal: e });
653
653
  }
654
654
  // Network primitive — единая точка для force/stale-revalidate/cold-start.
@@ -683,8 +683,8 @@ class ut {
683
683
  if (s === "sync")
684
684
  try {
685
685
  t(a);
686
- } catch (r) {
687
- console.warn("[paywall] onBalanceChange initial sync threw", r);
686
+ } catch (n) {
687
+ console.warn("[paywall] onBalanceChange initial sync threw", n);
688
688
  }
689
689
  else
690
690
  queueMicrotask(() => {
@@ -715,10 +715,10 @@ class ut {
715
715
  return;
716
716
  }
717
717
  if (!this.cachedBalances) return;
718
- const e = this.cachedBalances.findIndex((r) => r.type === t);
718
+ const e = this.cachedBalances.findIndex((n) => n.type === t);
719
719
  if (e < 0 || this.cachedBalances[e].count <= 0) return;
720
720
  const a = this.cachedBalances.map(
721
- (r, o) => o === e ? { ...r, count: r.count - 1 } : r
721
+ (n, o) => o === e ? { ...n, count: n.count - 1 } : n
722
722
  );
723
723
  this.applyBalances(a);
724
724
  }
@@ -739,7 +739,7 @@ class ut {
739
739
  */
740
740
  createApiGatewayClient(t = {}) {
741
741
  const e = t.onChargeSuccess, s = t.onQuotaExceeded;
742
- return new q({
742
+ return new D({
743
743
  paywallId: this.paywallId,
744
744
  apiOrigin: this.apiOrigin,
745
745
  auth: this.auth,
@@ -761,8 +761,8 @@ class ut {
761
761
  for (const a of this.balanceListeners)
762
762
  try {
763
763
  a(t);
764
- } catch (r) {
765
- console.warn("[paywall] onBalanceChange listener threw", r);
764
+ } catch (n) {
765
+ console.warn("[paywall] onBalanceChange listener threw", n);
766
766
  }
767
767
  }
768
768
  balancesStorageKey() {
@@ -813,19 +813,19 @@ class ut {
813
813
  }
814
814
  async createCheckout(t) {
815
815
  if (!this.identity?.email)
816
- throw new n(
816
+ throw new r(
817
817
  "identity_required",
818
818
  "createCheckout requires identity with email"
819
819
  );
820
820
  const e = t.idempotencyKey ?? `auto:${t.priceId}`, s = this.inflightCheckouts.get(e);
821
821
  if (s) return s;
822
- const r = {
822
+ const n = {
823
823
  "Idempotency-Key": t.idempotencyKey ?? C()
824
824
  };
825
- this.apiKey && (r["X-Api-Key"] = this.apiKey);
825
+ this.apiKey && (n["X-Api-Key"] = this.apiKey);
826
826
  const o = this.cachedBootstrap?.settings, d = t.successUrl ?? o?.success_redirect_url ?? void 0, u = t.shopUrl ?? o?.checkout_shop_url ?? void 0, f = this.api.request(`/api/v1/paywall/${this.paywallId}/start-checkout`, {
827
827
  method: "POST",
828
- headers: r,
828
+ headers: n,
829
829
  signal: t.signal,
830
830
  body: JSON.stringify({
831
831
  email: this.identity.email,
@@ -839,7 +839,7 @@ class ut {
839
839
  userMeta: this.identity.userId ? { userId: this.identity.userId } : void 0
840
840
  })
841
841
  }).then((h) => ({ url: h.checkoutUrl, acquiring: h.acquiring })).catch((h) => {
842
- throw h instanceof n && h.status === 409 && h.cause && typeof h.cause == "object" && h.cause.hasActivePurchase === !0 ? new n(
842
+ throw h instanceof r && h.status === 409 && h.cause && typeof h.cause == "object" && h.cause.hasActivePurchase === !0 ? new r(
843
843
  "already_purchased",
844
844
  "You already have an active subscription",
845
845
  { status: 409, cause: h.cause }
@@ -868,7 +868,7 @@ class ut {
868
868
  */
869
869
  async getCustomerPortalUrl(t = {}) {
870
870
  if (!this.auth && !this.apiKey && !this.identity?.email)
871
- throw new n(
871
+ throw new r(
872
872
  "identity_required",
873
873
  "getCustomerPortalUrl requires auth, apiKey, or identity.email"
874
874
  );
@@ -895,43 +895,65 @@ class ut {
895
895
  * `/api/v1/paywall/[id]/user` без unstable_cache, потому что list для UI
896
896
  * должен быть свежим после cancel-а.
897
897
  *
898
- * Auth: Bearer обязателен (через AuthClient). Без Bearer — 401 от бэка,
899
- * пробрасываем как PaywallError('http_401'). Гость пустой список.
898
+ * Auth (два пути):
899
+ * - Bearer (через AuthClient) — user.id резолвится из сессии, identity
900
+ * в query игнорируется.
901
+ * - `apiKey` + `identity.email`/`identity.userId` — server-SDK путь для
902
+ * интеграций со своей авторизацией. Бэк проверяет, что identity линкована
903
+ * к этому пейволу (защита от cross-paywall lookup).
904
+ * Без auth и без apiKey+identity — `identity_required`.
900
905
  */
901
906
  async listPurchases(t = {}) {
902
- if (!this.auth)
903
- throw new n(
904
- "auth_required",
905
- "listPurchases requires AuthClient (Bearer auth)"
907
+ const e = !!(this.identity?.email || this.identity?.userId);
908
+ if (!this.auth && !(this.apiKey && e))
909
+ throw new r(
910
+ "identity_required",
911
+ "listPurchases requires AuthClient (Bearer) or apiKey + identity.email/userId"
906
912
  );
907
- return (await this.api.request(`/api/v1/paywall/${this.paywallId}/user`, {
913
+ const s = {};
914
+ this.apiKey && (s["X-Api-Key"] = this.apiKey);
915
+ const a = new URLSearchParams();
916
+ this.apiKey && this.identity?.email && a.set("email", this.identity.email), this.apiKey && this.identity?.userId && a.set("user_id", this.identity.userId);
917
+ const n = a.toString(), o = n ? `/api/v1/paywall/${this.paywallId}/user?${n}` : `/api/v1/paywall/${this.paywallId}/user`;
918
+ return (await this.api.request(o, {
908
919
  method: "GET",
920
+ headers: s,
909
921
  signal: t.signal
910
922
  })).purchases ?? [];
911
923
  }
912
924
  /**
913
- * Отменить подписку. Бэк проверит что subscription принадлежит auth-юзеру
914
- * и сделает cancel у acquiring'а (Stripe/Paddle/Chargebee). По умолчанию
915
- * cancel в конце текущего периода — юзер сохраняет access до renewal date'ы.
925
+ * Отменить подписку. Бэк проверит, что subscription принадлежит юзеру
926
+ * (Bearer-путь из сессии; apiKey-путь — из identity), и сделает cancel у
927
+ * acquiring'а (Stripe/Paddle/Chargebee/Overpay). По умолчанию cancel в
928
+ * конце текущего периода — юзер сохраняет access до renewal date'ы.
916
929
  *
917
- * `reason` обязательна (валидация на бэке). Удобно собрать через select
918
- * причин в host-UI, как в legacy customer portal'е.
930
+ * `reason` обязательна (валидация на бэке).
919
931
  *
920
- * Auth: Bearer обязателен.
932
+ * Auth (два пути):
933
+ * - Bearer (через AuthClient) — стандартный путь для UI customer-portal'a.
934
+ * - `apiKey` + `identity.email`/`identity.userId` — для self-service UI на
935
+ * бэке клиента со своей авторизацией. Бэк дополнительно фильтрует
936
+ * subscription по paywall_id, чтобы owner пейвола A не отменил подписку
937
+ * пейвола B.
921
938
  */
922
939
  async cancelSubscription(t) {
923
- if (!this.auth)
924
- throw new n(
925
- "auth_required",
926
- "cancelSubscription requires AuthClient (Bearer auth)"
940
+ const e = !!(this.identity?.email || this.identity?.userId);
941
+ if (!this.auth && !(this.apiKey && e))
942
+ throw new r(
943
+ "identity_required",
944
+ "cancelSubscription requires AuthClient (Bearer) or apiKey + identity.email/userId"
927
945
  );
928
- return this.api.request("/api/paywall/cancel-subscription", {
946
+ const s = {};
947
+ this.apiKey && (s["X-Api-Key"] = this.apiKey);
948
+ const a = {
949
+ subscriptionId: t.subscriptionId,
950
+ paywallId: this.paywallId,
951
+ cancellationReason: t.reason
952
+ };
953
+ return this.apiKey && this.identity?.email && (a.email = this.identity.email), this.apiKey && this.identity?.userId && (a.userId = this.identity.userId), this.api.request("/api/paywall/cancel-subscription", {
929
954
  method: "POST",
930
- body: JSON.stringify({
931
- subscriptionId: t.subscriptionId,
932
- paywallId: this.paywallId,
933
- cancellationReason: t.reason
934
- }),
955
+ headers: s,
956
+ body: JSON.stringify(a),
935
957
  signal: t.signal
936
958
  });
937
959
  }
@@ -946,12 +968,12 @@ class ut {
946
968
  async createSupportTicket(t) {
947
969
  const e = t.email ?? this.identity?.email ?? null, s = `/api/v1/paywall/${this.paywallId}/support/ticket`;
948
970
  if (!!t.files && t.files.length > 0) {
949
- const r = new FormData();
950
- r.set("subject", t.subject), r.set("content", t.content), e && r.set("customer_email", e);
951
- for (const o of t.files) r.append("files", o);
971
+ const n = new FormData();
972
+ n.set("subject", t.subject), n.set("content", t.content), e && n.set("customer_email", e);
973
+ for (const o of t.files) n.append("files", o);
952
974
  return this.api.request(s, {
953
975
  method: "POST",
954
- body: r
976
+ body: n
955
977
  });
956
978
  }
957
979
  return this.api.request(s, {
@@ -983,7 +1005,7 @@ function U(i) {
983
1005
  function Y(i, t) {
984
1006
  const e = U(i);
985
1007
  if (!(!e || U(t) === e))
986
- throw new n(
1008
+ throw new r(
987
1009
  "invalid_config",
988
1010
  `apiOrigin mismatch: SDK initialized with "${t}" but paywall is configured with custom_domain "${i}". Use the custom_domain from the platform paywall settings.`
989
1011
  );
@@ -1003,7 +1025,7 @@ function O(i, t) {
1003
1025
  ]
1004
1026
  };
1005
1027
  }
1006
- function N(i) {
1028
+ function K(i) {
1007
1029
  const t = i.locales;
1008
1030
  if (!t) return null;
1009
1031
  const e = [];
@@ -1019,17 +1041,17 @@ function N(i) {
1019
1041
  return null;
1020
1042
  }
1021
1043
  function w(i) {
1022
- const t = N(i);
1044
+ const t = K(i);
1023
1045
  if (!t) return;
1024
1046
  const e = i.locales?.[t];
1025
1047
  e && (e.layout && (i.layout = e.layout), e.prices && (i.prices = i.prices.map((s) => {
1026
1048
  const a = e.prices?.[s.id];
1027
1049
  if (!a) return s;
1028
- const r = { ...s };
1029
- return "label" in a && (r.label = a.label ?? null), "description" in a && (r.description = a.description ?? null), r;
1050
+ const n = { ...s };
1051
+ return "label" in a && (n.label = a.label ?? null), "description" in a && (n.description = a.description ?? null), n;
1030
1052
  })));
1031
1053
  }
1032
- function P(i) {
1054
+ function N(i) {
1033
1055
  const t = new Uint8Array(i), e = typeof globalThis < "u" ? globalThis.crypto : void 0;
1034
1056
  if (e && typeof e.getRandomValues == "function")
1035
1057
  e.getRandomValues(t);
@@ -1037,31 +1059,31 @@ function P(i) {
1037
1059
  for (let s = 0; s < i; s++) t[s] = Math.floor(Math.random() * 256);
1038
1060
  return t;
1039
1061
  }
1040
- function I(i) {
1062
+ function S(i) {
1041
1063
  let t = "";
1042
1064
  for (let e = 0; e < i.length; e++) t += String.fromCharCode(i[e]);
1043
1065
  return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1044
1066
  }
1045
1067
  function Z() {
1046
- return I(P(64));
1068
+ return S(N(64));
1047
1069
  }
1048
1070
  async function tt(i) {
1049
1071
  const t = new TextEncoder().encode(i), e = globalThis.crypto;
1050
1072
  if (!e?.subtle?.digest)
1051
1073
  throw new Error("crypto.subtle is required for PKCE");
1052
1074
  const s = await e.subtle.digest("SHA-256", t);
1053
- return I(new Uint8Array(s));
1075
+ return S(new Uint8Array(s));
1054
1076
  }
1055
1077
  function et() {
1056
- return I(P(16));
1078
+ return S(N(16));
1057
1079
  }
1058
1080
  const st = 6e4, it = 600 * 1e3;
1059
- class dt {
1081
+ class ut {
1060
1082
  constructor(t) {
1061
1083
  if (this.session = null, this.inflightRefresh = null, this.inflightAnonSignin = null, this.listeners = /* @__PURE__ */ new Set(), this.storageUnwatch = null, this.destroyed = !1, this.oauthFlows = /* @__PURE__ */ new Map(), !t.paywallId)
1062
- throw new n("invalid_config", "paywallId is required");
1084
+ throw new r("invalid_config", "paywallId is required");
1063
1085
  if (!t.apiOrigin)
1064
- throw new n(
1086
+ throw new r(
1065
1087
  "invalid_config",
1066
1088
  "apiOrigin is required. Pass the paywall custom_domain configured in the platform."
1067
1089
  );
@@ -1155,8 +1177,8 @@ class dt {
1155
1177
  user_meta: t.userMeta
1156
1178
  })
1157
1179
  }
1158
- ), r = this.toSession(a, a.user);
1159
- return this.setSession(r, { event: "SIGNED_IN" }), this.recordLastLogin("email", t.email), r;
1180
+ ), n = this.toSession(a, a.user);
1181
+ return this.setSession(n, { event: "SIGNED_IN" }), this.recordLastLogin("email", t.email), n;
1160
1182
  }
1161
1183
  /**
1162
1184
  * Signup. Если в Supabase включён email confirm — сервер возвращает
@@ -1183,8 +1205,8 @@ class dt {
1183
1205
  );
1184
1206
  if (a.status === "confirmation_required")
1185
1207
  return this.recordLastLogin("email", t.email), { kind: "confirmation_required", user: a.user };
1186
- const r = this.toSession(a, a.user);
1187
- return this.setSession(r, { event: "SIGNED_IN" }), this.recordLastLogin("email", t.email), { kind: "signed_in", session: r };
1208
+ const n = this.toSession(a, a.user);
1209
+ return this.setSession(n, { event: "SIGNED_IN" }), this.recordLastLogin("email", t.email), { kind: "signed_in", session: n };
1188
1210
  }
1189
1211
  /**
1190
1212
  * Повторная отправка confirmation-email после signUp с включённым
@@ -1247,8 +1269,8 @@ class dt {
1247
1269
  user_meta: t.userMeta
1248
1270
  })
1249
1271
  }
1250
- ), a = this.toSession(s, s.user), r = t.type === "recovery" ? "PASSWORD_RECOVERY" : "SIGNED_IN";
1251
- return this.setSession(a, { event: r }), a;
1272
+ ), a = this.toSession(s, s.user), n = t.type === "recovery" ? "PASSWORD_RECOVERY" : "SIGNED_IN";
1273
+ return this.setSession(a, { event: n }), a;
1252
1274
  }
1253
1275
  /**
1254
1276
  * Запрос recovery email. Бэк всегда ok, чтобы не палить enumeration.
@@ -1274,7 +1296,7 @@ class dt {
1274
1296
  await this.hydrated;
1275
1297
  const e = await this.getAccessToken();
1276
1298
  if (!e)
1277
- throw new n("not_authenticated", "no active session");
1299
+ throw new r("not_authenticated", "no active session");
1278
1300
  await this.api.request(
1279
1301
  `/api/v1/paywall/${this.paywallId}/auth/password/update`,
1280
1302
  {
@@ -1307,10 +1329,8 @@ class dt {
1307
1329
  * когда сервер начнёт возвращать challenge_required в риск-сценариях,
1308
1330
  * SDK сможет передать proof-of-something обратно без breaking change.
1309
1331
  *
1310
- * `forceCaptcha: true` пропускает шаги 1-2 и сразу делает /signin (создаёт
1311
- * нового anon-юзера). Используется в switch-account flow. Имя поля исторически
1312
- * остаётся `forceCaptcha`, хотя капчи там больше нет — менять имя ломает
1313
- * host-сигнатуру; смысл «принудительно новая anon-сессия» сохранён.
1332
+ * `forceNewAnon: true` пропускает шаги 1-2 и сразу делает /signin (создаёт
1333
+ * нового anon-юзера). Используется в switch-account flow.
1314
1334
  *
1315
1335
  * Параллельные вызовы дедуплицируются через `inflightAnonSignin` — два
1316
1336
  * click'а на «Войти как гость» не создадут двух anon-юзеров (два /signup =
@@ -1319,9 +1339,9 @@ class dt {
1319
1339
  async signInAnonymously(t = {}) {
1320
1340
  if (this.inflightAnonSignin) return this.inflightAnonSignin;
1321
1341
  this.inflightAnonSignin = (async () => {
1322
- if (await this.hydrated, !t.forceCaptcha && this.session?.user.is_anonymous === !0)
1342
+ if (await this.hydrated, !t.forceNewAnon && this.session?.user.is_anonymous === !0)
1323
1343
  return this.session;
1324
- if (!t.forceCaptcha) {
1344
+ if (!t.forceNewAnon) {
1325
1345
  const o = await this.resumeAnonymous();
1326
1346
  if (o) return o;
1327
1347
  }
@@ -1339,8 +1359,8 @@ class dt {
1339
1359
  ...s.user,
1340
1360
  email: s.user.email ?? null,
1341
1361
  is_anonymous: !0
1342
- }, r = this.toSession(s, a);
1343
- return this.setSession(r, { event: "SIGNED_IN" }), await this.writeAnonRefreshToken(r.refresh_token), r;
1362
+ }, n = this.toSession(s, a);
1363
+ return this.setSession(n, { event: "SIGNED_IN" }), await this.writeAnonRefreshToken(n.refresh_token), n;
1344
1364
  })();
1345
1365
  try {
1346
1366
  return await this.inflightAnonSignin;
@@ -1364,7 +1384,7 @@ class dt {
1364
1384
  ), s = this.session?.user.is_anonymous === !0 ? this.session.user : { id: "", email: null, is_anonymous: !0 }, a = this.toSession(e, s);
1365
1385
  return this.setSession(a, { event: "SIGNED_IN" }), await this.writeAnonRefreshToken(a.refresh_token), a;
1366
1386
  } catch (e) {
1367
- if (e instanceof n && e.status === 401)
1387
+ if (e instanceof r && e.status === 401)
1368
1388
  return await this.clearAnonRefreshToken(), null;
1369
1389
  throw e;
1370
1390
  }
@@ -1394,7 +1414,7 @@ class dt {
1394
1414
  await this.hydrated;
1395
1415
  const e = await this.getAccessToken();
1396
1416
  if (!e)
1397
- throw new n("not_authenticated", "no active session");
1417
+ throw new r("not_authenticated", "no active session");
1398
1418
  const s = {
1399
1419
  Authorization: `Bearer ${e}`
1400
1420
  };
@@ -1413,18 +1433,18 @@ class dt {
1413
1433
  );
1414
1434
  if (a.status === "confirmation_required")
1415
1435
  return { kind: "confirmation_required", email: a.email };
1416
- const r = this.session;
1417
- if (!r)
1418
- throw new n(
1436
+ const n = this.session;
1437
+ if (!n)
1438
+ throw new r(
1419
1439
  "not_authenticated",
1420
1440
  "session disappeared during upgrade"
1421
1441
  );
1422
1442
  const o = {
1423
- ...r.user,
1443
+ ...n.user,
1424
1444
  id: a.user.id,
1425
1445
  email: a.user.email,
1426
1446
  is_anonymous: a.user.is_anonymous ?? !1
1427
- }, d = { ...r, user: o };
1447
+ }, d = { ...n, user: o };
1428
1448
  return this.setSession(d, { event: "USER_UPDATED" }), await this.clearAnonRefreshToken(), { kind: "updated", session: d };
1429
1449
  }
1430
1450
  /**
@@ -1449,22 +1469,22 @@ class dt {
1449
1469
  */
1450
1470
  async signInWithOAuth(t) {
1451
1471
  if (typeof window > "u")
1452
- throw new n("oauth_unavailable", "window is required for OAuth");
1472
+ throw new r("oauth_unavailable", "window is required for OAuth");
1453
1473
  const { authorize_url: e, state: s } = await this.startOAuthFlow({
1454
1474
  provider: t.provider,
1455
1475
  scopes: t.scopes,
1456
1476
  userMeta: t.userMeta
1457
1477
  }), a = this.openPopup(e, `pw-oauth-${s}`);
1458
1478
  if (!a)
1459
- throw this.oauthFlows.delete(s), new n(
1479
+ throw this.oauthFlows.delete(s), new r(
1460
1480
  "popup_blocked",
1461
1481
  "browser blocked auth popup — call from a user gesture"
1462
1482
  );
1463
1483
  t.onPopupOpened?.();
1464
- const r = await nt(a, s);
1484
+ const n = await rt(a, s);
1465
1485
  if (this.destroyed)
1466
- throw this.oauthFlows.delete(s), new n("aborted", "AuthClient destroyed mid-flow");
1467
- return this.completeOAuthFlow({ state: s, code: r });
1486
+ throw this.oauthFlows.delete(s), new r("aborted", "AuthClient destroyed mid-flow");
1487
+ return this.completeOAuthFlow({ state: s, code: n });
1468
1488
  }
1469
1489
  /**
1470
1490
  * Шаг 1 OAuth split-API: инициирует flow на бэке, генерит PKCE verifier
@@ -1482,13 +1502,13 @@ class dt {
1482
1502
  */
1483
1503
  async startOAuthFlow(t) {
1484
1504
  await this.hydrated, this.gcOAuthFlows();
1485
- const e = Z(), s = await tt(e), a = et(), r = {}, o = await this.getAccessToken().catch(() => null);
1486
- o && (r.Authorization = `Bearer ${o}`);
1505
+ const e = Z(), s = await tt(e), a = et(), n = {}, o = await this.getAccessToken().catch(() => null);
1506
+ o && (n.Authorization = `Bearer ${o}`);
1487
1507
  const { authorize_url: d } = await this.api.request(
1488
1508
  `/api/v1/paywall/${this.paywallId}/auth/oauth/init`,
1489
1509
  {
1490
1510
  method: "POST",
1491
- headers: Object.keys(r).length ? r : void 0,
1511
+ headers: Object.keys(n).length ? n : void 0,
1492
1512
  body: JSON.stringify({
1493
1513
  provider: t.provider,
1494
1514
  code_challenge: s,
@@ -1517,7 +1537,7 @@ class dt {
1517
1537
  await this.hydrated;
1518
1538
  const e = this.oauthFlows.get(t.state);
1519
1539
  if (!e)
1520
- throw new n(
1540
+ throw new r(
1521
1541
  "oauth_invalid_state",
1522
1542
  "OAuth flow not found — start with startOAuthFlow first or check TTL"
1523
1543
  );
@@ -1535,9 +1555,9 @@ class dt {
1535
1555
  }
1536
1556
  );
1537
1557
  if (this.destroyed)
1538
- throw new n("aborted", "AuthClient destroyed mid-flow");
1539
- const r = this.toSession(a, a.user);
1540
- return this.setSession(r, { event: "SIGNED_IN" }), r.user.email && this.recordLastLoginEmail(r.user.email), r;
1558
+ throw new r("aborted", "AuthClient destroyed mid-flow");
1559
+ const n = this.toSession(a, a.user);
1560
+ return this.setSession(n, { event: "SIGNED_IN" }), n.user.email && this.recordLastLoginEmail(n.user.email), n;
1541
1561
  }
1542
1562
  gcOAuthFlows() {
1543
1563
  const t = Date.now() - it;
@@ -1568,7 +1588,7 @@ class dt {
1568
1588
  ), a = this.toSession(s, e);
1569
1589
  return this.setSession(a, { event: "TOKEN_REFRESHED" }), e.is_anonymous === !0 && await this.writeAnonRefreshToken(a.refresh_token), a;
1570
1590
  } catch (s) {
1571
- if (s instanceof n && s.status === 401)
1591
+ if (s instanceof r && s.status === 401)
1572
1592
  return e.is_anonymous === !0 && await this.clearAnonRefreshToken(), this.setSession(null, { event: "SIGNED_OUT" }), null;
1573
1593
  throw s;
1574
1594
  } finally {
@@ -1595,7 +1615,7 @@ class dt {
1595
1615
  await this.hydrated;
1596
1616
  const t = this.session?.access_token;
1597
1617
  if (!t)
1598
- throw new n("not_authenticated", "no active session");
1618
+ throw new r("not_authenticated", "no active session");
1599
1619
  await this.api.request(
1600
1620
  `/api/v1/paywall/${this.paywallId}/auth/revoke-all`,
1601
1621
  {
@@ -1812,31 +1832,31 @@ class dt {
1812
1832
  }
1813
1833
  }
1814
1834
  }
1815
- const at = 5 * 6e4, rt = 500;
1816
- function nt(i, t) {
1835
+ const at = 5 * 6e4, nt = 500;
1836
+ function rt(i, t) {
1817
1837
  return new Promise((e, s) => {
1818
1838
  let a = !1;
1819
- const r = () => {
1839
+ const n = () => {
1820
1840
  a = !0, window.removeEventListener("message", o), clearInterval(d), clearTimeout(u);
1821
1841
  }, o = (f) => {
1822
1842
  if (a) return;
1823
1843
  const h = f.data;
1824
1844
  if (!(!h || h.type !== "pw-oauth") && h.messageId === t) {
1825
1845
  if (h.status === "success" && h.code) {
1826
- r();
1846
+ n();
1827
1847
  try {
1828
1848
  i.close();
1829
1849
  } catch {
1830
1850
  }
1831
1851
  e(h.code);
1832
1852
  } else if (h.status === "error") {
1833
- r();
1853
+ n();
1834
1854
  try {
1835
1855
  i.close();
1836
1856
  } catch {
1837
1857
  }
1838
1858
  s(
1839
- new n(
1859
+ new r(
1840
1860
  "oauth_failed",
1841
1861
  h.description || h.error || "OAuth provider returned error"
1842
1862
  )
@@ -1851,15 +1871,15 @@ function nt(i, t) {
1851
1871
  } catch {
1852
1872
  return;
1853
1873
  }
1854
- f && (r(), s(new n("oauth_cancelled", "auth popup was closed")));
1855
- }, rt), u = setTimeout(() => {
1874
+ f && (n(), s(new r("oauth_cancelled", "auth popup was closed")));
1875
+ }, nt), u = setTimeout(() => {
1856
1876
  if (!a) {
1857
- r();
1877
+ n();
1858
1878
  try {
1859
1879
  i.close();
1860
1880
  } catch {
1861
1881
  }
1862
- s(new n("oauth_timeout", "OAuth flow timed out"));
1882
+ s(new r("oauth_timeout", "OAuth flow timed out"));
1863
1883
  }
1864
1884
  }, at);
1865
1885
  window.addEventListener("message", o);
@@ -1902,9 +1922,9 @@ class ft {
1902
1922
  const t = this.buffer;
1903
1923
  this.buffer = [];
1904
1924
  try {
1905
- const e = await this.opts.getVisitorId(), s = this.opts.getUserId?.() ?? null, a = JSON.stringify({ events: t }), r = this.opts.fetch ?? (typeof fetch < "u" ? fetch : void 0);
1906
- if (!r) return;
1907
- await r(this.opts.endpoint, {
1925
+ const e = await this.opts.getVisitorId(), s = this.opts.getUserId?.() ?? null, a = JSON.stringify({ events: t }), n = this.opts.fetch ?? (typeof fetch < "u" ? fetch : void 0);
1926
+ if (!n) return;
1927
+ await n(this.opts.endpoint, {
1908
1928
  method: "POST",
1909
1929
  credentials: "omit",
1910
1930
  keepalive: !0,
@@ -1938,13 +1958,13 @@ class ft {
1938
1958
  sdk_version: m,
1939
1959
  paywall_id: this.opts.paywallId,
1940
1960
  capabilities: this.opts.capabilities?.join(",") ?? ""
1941
- }), r = this.opts.sendBeacon ?? (typeof navigator < "u" && typeof navigator.sendBeacon == "function" ? navigator.sendBeacon.bind(navigator) : null);
1942
- if (!r) {
1961
+ }), n = this.opts.sendBeacon ?? (typeof navigator < "u" && typeof navigator.sendBeacon == "function" ? navigator.sendBeacon.bind(navigator) : null);
1962
+ if (!n) {
1943
1963
  this.buffer.unshift(...t), this.flush();
1944
1964
  return;
1945
1965
  }
1946
1966
  try {
1947
- r(this.opts.endpoint, a) || (this.buffer.unshift(...t), this.flush());
1967
+ n(this.opts.endpoint, a) || (this.buffer.unshift(...t), this.flush());
1948
1968
  } catch {
1949
1969
  this.buffer.unshift(...t), this.flush();
1950
1970
  }
@@ -1972,12 +1992,12 @@ class ft {
1972
1992
  }
1973
1993
  export {
1974
1994
  E as ApiClient,
1975
- q as ApiGatewayClient,
1976
- dt as AuthClient,
1977
- ut as BillingClient,
1995
+ D as ApiGatewayClient,
1996
+ ut as AuthClient,
1997
+ dt as BillingClient,
1978
1998
  ft as EventTracker,
1979
- n as PaywallError,
1980
- D as QuotaExceededError,
1999
+ r as PaywallError,
2000
+ R as QuotaExceededError,
1981
2001
  m as SDK_VERSION,
1982
2002
  l as STORAGE_KEYS,
1983
2003
  L as createStorage,