@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.
- package/dist/chunks/{PaywallUI-BrDiS6zg.js → PaywallUI-BhQpWSWN.js} +380 -375
- package/dist/chunks/PaywallUI-BhQpWSWN.js.map +1 -0
- package/dist/chunks/PaywallUI-C7Wp2TiR.js +26 -0
- package/dist/chunks/PaywallUI-C7Wp2TiR.js.map +1 -0
- package/dist/chunks/ar-7cgIM-Vl.js +2 -0
- package/dist/chunks/ar-7cgIM-Vl.js.map +1 -0
- package/dist/chunks/{ar-CHae8g-2.js → ar-B2Wg_IrC.js} +2 -2
- package/dist/chunks/ar-B2Wg_IrC.js.map +1 -0
- package/dist/chunks/{cs-eZTedzaK.js → cs-BNo9Dx0Q.js} +2 -2
- package/dist/chunks/cs-BNo9Dx0Q.js.map +1 -0
- package/dist/chunks/cs-S05PC5AC.js +2 -0
- package/dist/chunks/cs-S05PC5AC.js.map +1 -0
- package/dist/chunks/da-Bi4zBG14.js +2 -0
- package/dist/chunks/da-Bi4zBG14.js.map +1 -0
- package/dist/chunks/{da-Dca6j8fp.js → da-Do9Lq6En.js} +2 -2
- package/dist/chunks/da-Do9Lq6En.js.map +1 -0
- package/dist/chunks/{de-BCjn3PUI.js → de-C8pDZNvx.js} +2 -2
- package/dist/chunks/de-C8pDZNvx.js.map +1 -0
- package/dist/chunks/de-nCDB6D2W.js +2 -0
- package/dist/chunks/de-nCDB6D2W.js.map +1 -0
- package/dist/chunks/el-BrKaa978.js +2 -0
- package/dist/chunks/el-BrKaa978.js.map +1 -0
- package/dist/chunks/{el-BpXtDTez.js → el-DzMNX-_P.js} +2 -2
- package/dist/chunks/el-DzMNX-_P.js.map +1 -0
- package/dist/chunks/es-B-Wtyzrl.js +2 -0
- package/dist/chunks/es-B-Wtyzrl.js.map +1 -0
- package/dist/chunks/{es-B3P4nlMw.js → es-YrKt-q4w.js} +2 -2
- package/dist/chunks/es-YrKt-q4w.js.map +1 -0
- package/dist/chunks/{fi-BbQ_Bs0Z.js → fi-Bh44pwZ4.js} +2 -2
- package/dist/chunks/fi-Bh44pwZ4.js.map +1 -0
- package/dist/chunks/fi-D1SGXjnO.js +2 -0
- package/dist/chunks/fi-D1SGXjnO.js.map +1 -0
- package/dist/chunks/{fr-BKDUXceO.js → fr-Bc0pw4ws.js} +2 -2
- package/dist/chunks/fr-Bc0pw4ws.js.map +1 -0
- package/dist/chunks/fr-BhYf-iKk.js +2 -0
- package/dist/chunks/fr-BhYf-iKk.js.map +1 -0
- package/dist/chunks/he-BXAaFv6Y.js +2 -0
- package/dist/chunks/he-BXAaFv6Y.js.map +1 -0
- package/dist/chunks/{he-BVCHlTtT.js → he-Bfm-bhe3.js} +2 -2
- package/dist/chunks/he-Bfm-bhe3.js.map +1 -0
- package/dist/chunks/{hi-H_Hshh-7.js → hi-D-O-B9Dn.js} +2 -2
- package/dist/chunks/hi-D-O-B9Dn.js.map +1 -0
- package/dist/chunks/hi-xblDO0O7.js +2 -0
- package/dist/chunks/hi-xblDO0O7.js.map +1 -0
- package/dist/chunks/{hu-ZWiNfzvN.js → hu-CmIuAbLL.js} +2 -2
- package/dist/chunks/hu-CmIuAbLL.js.map +1 -0
- package/dist/chunks/hu-Wa46p0y4.js +2 -0
- package/dist/chunks/hu-Wa46p0y4.js.map +1 -0
- package/dist/chunks/id-CQEo5X94.js +2 -0
- package/dist/chunks/id-CQEo5X94.js.map +1 -0
- package/dist/chunks/{id-DeiRYsJ1.js → id-DN7IES-A.js} +2 -2
- package/dist/chunks/id-DN7IES-A.js.map +1 -0
- package/dist/chunks/it-8AYCm0xz.js +2 -0
- package/dist/chunks/it-8AYCm0xz.js.map +1 -0
- package/dist/chunks/{it-UH9OzFhg.js → it-Cz5Nmqx5.js} +2 -2
- package/dist/chunks/it-Cz5Nmqx5.js.map +1 -0
- package/dist/chunks/{ja-BYC8FRN8.js → ja-BH9BlBh2.js} +2 -2
- package/dist/chunks/ja-BH9BlBh2.js.map +1 -0
- package/dist/chunks/ja-q-COVayn.js +2 -0
- package/dist/chunks/ja-q-COVayn.js.map +1 -0
- package/dist/chunks/ko-B6HRCscZ.js +2 -0
- package/dist/chunks/ko-B6HRCscZ.js.map +1 -0
- package/dist/chunks/{ko-Bjs2ZRcF.js → ko-CYV9QuYs.js} +2 -2
- package/dist/chunks/ko-CYV9QuYs.js.map +1 -0
- package/dist/chunks/{nl-Ch5HFWQO.js → nl-BvkB900D.js} +2 -2
- package/dist/chunks/nl-BvkB900D.js.map +1 -0
- package/dist/chunks/nl-CAd6_xlm.js +2 -0
- package/dist/chunks/nl-CAd6_xlm.js.map +1 -0
- package/dist/chunks/{no-CljpinWz.js → no-3s9_ormb.js} +2 -2
- package/dist/chunks/no-3s9_ormb.js.map +1 -0
- package/dist/chunks/no-CAmz6bz6.js +2 -0
- package/dist/chunks/no-CAmz6bz6.js.map +1 -0
- package/dist/chunks/{pl-CUcSS0zZ.js → pl-C9WTGQtb.js} +2 -2
- package/dist/chunks/pl-C9WTGQtb.js.map +1 -0
- package/dist/chunks/pl-DqUSTCaF.js +2 -0
- package/dist/chunks/pl-DqUSTCaF.js.map +1 -0
- package/dist/chunks/pt-8ARZnH0_.js +2 -0
- package/dist/chunks/pt-8ARZnH0_.js.map +1 -0
- package/dist/chunks/{pt-BHK0LwkC.js → pt-uFVUv_Op.js} +2 -2
- package/dist/chunks/pt-uFVUv_Op.js.map +1 -0
- package/dist/chunks/{ro-Bj8cwU2n.js → ro-BrqQ8Au-.js} +2 -2
- package/dist/chunks/ro-BrqQ8Au-.js.map +1 -0
- package/dist/chunks/ro-D-NMbp2F.js +2 -0
- package/dist/chunks/ro-D-NMbp2F.js.map +1 -0
- package/dist/chunks/ru-8gbHPh0g.js +2 -0
- package/dist/chunks/ru-8gbHPh0g.js.map +1 -0
- package/dist/chunks/{ru-CgqNy0Gb.js → ru-DK594dA8.js} +2 -2
- package/dist/chunks/ru-DK594dA8.js.map +1 -0
- package/dist/chunks/{sv-H7jroOQ5.js → sv-CHNH8-mq.js} +2 -2
- package/dist/chunks/sv-CHNH8-mq.js.map +1 -0
- package/dist/chunks/sv-D8a8hmx9.js +2 -0
- package/dist/chunks/sv-D8a8hmx9.js.map +1 -0
- package/dist/chunks/th-DfjUK0Y7.js +2 -0
- package/dist/chunks/th-DfjUK0Y7.js.map +1 -0
- package/dist/chunks/{th-Dqm-gpGe.js → th-l24Pm5q-.js} +2 -2
- package/dist/chunks/th-l24Pm5q-.js.map +1 -0
- package/dist/chunks/{tr-D3zPcNtT.js → tr-ADpigSY5.js} +2 -2
- package/dist/chunks/tr-ADpigSY5.js.map +1 -0
- package/dist/chunks/tr-BdBpz4tL.js +2 -0
- package/dist/chunks/tr-BdBpz4tL.js.map +1 -0
- package/dist/chunks/{uk-CoIIs3QI.js → uk-CGqo4jek.js} +2 -2
- package/dist/chunks/uk-CGqo4jek.js.map +1 -0
- package/dist/chunks/uk-Cx1zv1ao.js +2 -0
- package/dist/chunks/uk-Cx1zv1ao.js.map +1 -0
- package/dist/chunks/{vi-C_fruIbh.js → vi-Dk9bTu6f.js} +2 -2
- package/dist/chunks/vi-Dk9bTu6f.js.map +1 -0
- package/dist/chunks/vi-oe2dW21I.js +2 -0
- package/dist/chunks/vi-oe2dW21I.js.map +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +21 -13
- package/dist/core.js +178 -158
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +21 -13
- package/dist/index.js +1 -1
- package/dist/ui.cjs +1 -1
- package/dist/ui.d.ts +21 -13
- package/dist/ui.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/PaywallUI-BrDiS6zg.js.map +0 -1
- package/dist/chunks/PaywallUI-Bvx8nRL0.js +0 -26
- package/dist/chunks/PaywallUI-Bvx8nRL0.js.map +0 -1
- package/dist/chunks/ar-CHae8g-2.js.map +0 -1
- package/dist/chunks/ar-E1mc8SO_.js +0 -2
- package/dist/chunks/ar-E1mc8SO_.js.map +0 -1
- package/dist/chunks/cs-Dccq6LAT.js +0 -2
- package/dist/chunks/cs-Dccq6LAT.js.map +0 -1
- package/dist/chunks/cs-eZTedzaK.js.map +0 -1
- package/dist/chunks/da-C_4MbEh5.js +0 -2
- package/dist/chunks/da-C_4MbEh5.js.map +0 -1
- package/dist/chunks/da-Dca6j8fp.js.map +0 -1
- package/dist/chunks/de-BCjn3PUI.js.map +0 -1
- package/dist/chunks/de-DulxcJj-.js +0 -2
- package/dist/chunks/de-DulxcJj-.js.map +0 -1
- package/dist/chunks/el-BpXtDTez.js.map +0 -1
- package/dist/chunks/el-CVG_1iKB.js +0 -2
- package/dist/chunks/el-CVG_1iKB.js.map +0 -1
- package/dist/chunks/es-B3P4nlMw.js.map +0 -1
- package/dist/chunks/es-ri0uKzUW.js +0 -2
- package/dist/chunks/es-ri0uKzUW.js.map +0 -1
- package/dist/chunks/fi-BbQ_Bs0Z.js.map +0 -1
- package/dist/chunks/fi-CNZqWHjw.js +0 -2
- package/dist/chunks/fi-CNZqWHjw.js.map +0 -1
- package/dist/chunks/fr-BKDUXceO.js.map +0 -1
- package/dist/chunks/fr-CfFOw4hD.js +0 -2
- package/dist/chunks/fr-CfFOw4hD.js.map +0 -1
- package/dist/chunks/he-BVCHlTtT.js.map +0 -1
- package/dist/chunks/he-DN2JEtQb.js +0 -2
- package/dist/chunks/he-DN2JEtQb.js.map +0 -1
- package/dist/chunks/hi-DxfOerNP.js +0 -2
- package/dist/chunks/hi-DxfOerNP.js.map +0 -1
- package/dist/chunks/hi-H_Hshh-7.js.map +0 -1
- package/dist/chunks/hu-BTImywuV.js +0 -2
- package/dist/chunks/hu-BTImywuV.js.map +0 -1
- package/dist/chunks/hu-ZWiNfzvN.js.map +0 -1
- package/dist/chunks/id-DeiRYsJ1.js.map +0 -1
- package/dist/chunks/id-YFuArJA6.js +0 -2
- package/dist/chunks/id-YFuArJA6.js.map +0 -1
- package/dist/chunks/it-UH9OzFhg.js.map +0 -1
- package/dist/chunks/it-mhkzXBM9.js +0 -2
- package/dist/chunks/it-mhkzXBM9.js.map +0 -1
- package/dist/chunks/ja-6l_z_G9k.js +0 -2
- package/dist/chunks/ja-6l_z_G9k.js.map +0 -1
- package/dist/chunks/ja-BYC8FRN8.js.map +0 -1
- package/dist/chunks/ko-Bjs2ZRcF.js.map +0 -1
- package/dist/chunks/ko-YAl4XwHu.js +0 -2
- package/dist/chunks/ko-YAl4XwHu.js.map +0 -1
- package/dist/chunks/nl-C-9zHtfb.js +0 -2
- package/dist/chunks/nl-C-9zHtfb.js.map +0 -1
- package/dist/chunks/nl-Ch5HFWQO.js.map +0 -1
- package/dist/chunks/no-CljpinWz.js.map +0 -1
- package/dist/chunks/no-qzPitLlx.js +0 -2
- package/dist/chunks/no-qzPitLlx.js.map +0 -1
- package/dist/chunks/pl-CUcSS0zZ.js.map +0 -1
- package/dist/chunks/pl-MAIYeuhW.js +0 -2
- package/dist/chunks/pl-MAIYeuhW.js.map +0 -1
- package/dist/chunks/pt-BHK0LwkC.js.map +0 -1
- package/dist/chunks/pt-DqDabE4v.js +0 -2
- package/dist/chunks/pt-DqDabE4v.js.map +0 -1
- package/dist/chunks/ro-BVs-lHH-.js +0 -2
- package/dist/chunks/ro-BVs-lHH-.js.map +0 -1
- package/dist/chunks/ro-Bj8cwU2n.js.map +0 -1
- package/dist/chunks/ru-CgqNy0Gb.js.map +0 -1
- package/dist/chunks/ru-DP7qDAmE.js +0 -2
- package/dist/chunks/ru-DP7qDAmE.js.map +0 -1
- package/dist/chunks/sv-B3QEYGgd.js +0 -2
- package/dist/chunks/sv-B3QEYGgd.js.map +0 -1
- package/dist/chunks/sv-H7jroOQ5.js.map +0 -1
- package/dist/chunks/th-Dqm-gpGe.js.map +0 -1
- package/dist/chunks/th-DzQau9aW.js +0 -2
- package/dist/chunks/th-DzQau9aW.js.map +0 -1
- package/dist/chunks/tr-D3zPcNtT.js.map +0 -1
- package/dist/chunks/tr-cG1YuE1E.js +0 -2
- package/dist/chunks/tr-cG1YuE1E.js.map +0 -1
- package/dist/chunks/uk-CoIIs3QI.js.map +0 -1
- package/dist/chunks/uk-Cvbo0IBW.js +0 -2
- package/dist/chunks/uk-Cvbo0IBW.js.map +0 -1
- package/dist/chunks/vi-BRtYSBUp.js +0 -2
- package/dist/chunks/vi-BRtYSBUp.js.map +0 -1
- package/dist/chunks/vi-C_fruIbh.js.map +0 -1
package/dist/core.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
class
|
|
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
|
|
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,
|
|
20
|
-
|
|
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 &&
|
|
22
|
+
o && n.set("Authorization", `Bearer ${o}`);
|
|
23
23
|
const d = typeof FormData < "u" && e.body instanceof FormData;
|
|
24
|
-
e.body && !
|
|
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:
|
|
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
|
|
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
|
|
38
|
+
throw new r(c, g, { status: u.status, cause: y });
|
|
39
39
|
}
|
|
40
40
|
return y;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
class
|
|
43
|
+
class D {
|
|
44
44
|
constructor(t) {
|
|
45
45
|
if (!t.paywallId)
|
|
46
|
-
throw new
|
|
46
|
+
throw new r("invalid_config", "paywallId is required");
|
|
47
47
|
if (!t.apiOrigin)
|
|
48
|
-
throw new
|
|
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
|
|
65
|
-
|
|
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
|
|
81
|
-
throw new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
153
|
-
if (
|
|
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
|
-
},
|
|
187
|
+
}, I = /* @__PURE__ */ new Map(), J = {
|
|
188
188
|
async getItem(i) {
|
|
189
|
-
return
|
|
189
|
+
return I.get(i) ?? null;
|
|
190
190
|
},
|
|
191
191
|
async setItem(i, t) {
|
|
192
|
-
|
|
192
|
+
I.set(i, t);
|
|
193
193
|
},
|
|
194
194
|
async removeItem(i) {
|
|
195
|
-
|
|
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,
|
|
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
|
|
265
|
+
function X(i, t) {
|
|
266
266
|
return i === t ? !0 : !i || !t ? !1 : JSON.stringify(i) === JSON.stringify(t);
|
|
267
267
|
}
|
|
268
|
-
const
|
|
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
|
|
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
|
|
279
|
+
throw new r("invalid_config", "paywallId is required");
|
|
280
280
|
if (!t.apiOrigin)
|
|
281
|
-
throw new
|
|
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
|
|
300
|
-
W(this.identity,
|
|
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(
|
|
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
|
|
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 (
|
|
400
|
-
console.warn("[paywall] onBootstrapChange listener threw",
|
|
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
|
|
417
|
-
return Y(
|
|
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 (
|
|
441
|
-
console.warn("[paywall] onBootstrapChange listener threw",
|
|
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 ?
|
|
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(
|
|
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 (
|
|
586
|
-
console.warn("[paywall] onUserChange initial sync threw",
|
|
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 = !
|
|
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 <
|
|
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 (
|
|
687
|
-
console.warn("[paywall] onBalanceChange initial sync threw",
|
|
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((
|
|
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
|
-
(
|
|
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
|
|
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 (
|
|
765
|
-
console.warn("[paywall] onBalanceChange listener threw",
|
|
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
|
|
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
|
|
822
|
+
const n = {
|
|
823
823
|
"Idempotency-Key": t.idempotencyKey ?? C()
|
|
824
824
|
};
|
|
825
|
-
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:
|
|
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
|
|
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
|
|
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
|
|
899
|
-
*
|
|
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
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
"
|
|
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
|
-
|
|
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
|
-
* Отменить подписку. Бэк
|
|
914
|
-
*
|
|
915
|
-
*
|
|
925
|
+
* Отменить подписку. Бэк проверит, что subscription принадлежит юзеру
|
|
926
|
+
* (Bearer-путь — из сессии; apiKey-путь — из identity), и сделает cancel у
|
|
927
|
+
* acquiring'а (Stripe/Paddle/Chargebee/Overpay). По умолчанию cancel в
|
|
928
|
+
* конце текущего периода — юзер сохраняет access до renewal date'ы.
|
|
916
929
|
*
|
|
917
|
-
* `reason` обязательна (валидация на бэке).
|
|
918
|
-
* причин в host-UI, как в legacy customer portal'е.
|
|
930
|
+
* `reason` обязательна (валидация на бэке).
|
|
919
931
|
*
|
|
920
|
-
* Auth
|
|
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
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
"
|
|
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
|
-
|
|
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
|
-
|
|
931
|
-
|
|
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
|
|
950
|
-
|
|
951
|
-
for (const o of t.files)
|
|
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:
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
1029
|
-
return "label" in a && (
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1075
|
+
return S(new Uint8Array(s));
|
|
1054
1076
|
}
|
|
1055
1077
|
function et() {
|
|
1056
|
-
return
|
|
1078
|
+
return S(N(16));
|
|
1057
1079
|
}
|
|
1058
1080
|
const st = 6e4, it = 600 * 1e3;
|
|
1059
|
-
class
|
|
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
|
|
1084
|
+
throw new r("invalid_config", "paywallId is required");
|
|
1063
1085
|
if (!t.apiOrigin)
|
|
1064
|
-
throw new
|
|
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
|
-
),
|
|
1159
|
-
return this.setSession(
|
|
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
|
|
1187
|
-
return this.setSession(
|
|
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),
|
|
1251
|
-
return this.setSession(a, { event:
|
|
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
|
|
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
|
-
* `
|
|
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.
|
|
1342
|
+
if (await this.hydrated, !t.forceNewAnon && this.session?.user.is_anonymous === !0)
|
|
1323
1343
|
return this.session;
|
|
1324
|
-
if (!t.
|
|
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
|
-
},
|
|
1343
|
-
return this.setSession(
|
|
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
|
|
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
|
|
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
|
|
1417
|
-
if (!
|
|
1418
|
-
throw new
|
|
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
|
-
...
|
|
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 = { ...
|
|
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
|
|
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
|
|
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
|
|
1484
|
+
const n = await rt(a, s);
|
|
1465
1485
|
if (this.destroyed)
|
|
1466
|
-
throw this.oauthFlows.delete(s), new
|
|
1467
|
-
return this.completeOAuthFlow({ state: s, code:
|
|
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(),
|
|
1486
|
-
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(
|
|
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
|
|
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
|
|
1539
|
-
const
|
|
1540
|
-
return this.setSession(
|
|
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
|
|
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
|
|
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,
|
|
1816
|
-
function
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
1853
|
+
n();
|
|
1834
1854
|
try {
|
|
1835
1855
|
i.close();
|
|
1836
1856
|
} catch {
|
|
1837
1857
|
}
|
|
1838
1858
|
s(
|
|
1839
|
-
new
|
|
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 && (
|
|
1855
|
-
},
|
|
1874
|
+
f && (n(), s(new r("oauth_cancelled", "auth popup was closed")));
|
|
1875
|
+
}, nt), u = setTimeout(() => {
|
|
1856
1876
|
if (!a) {
|
|
1857
|
-
|
|
1877
|
+
n();
|
|
1858
1878
|
try {
|
|
1859
1879
|
i.close();
|
|
1860
1880
|
} catch {
|
|
1861
1881
|
}
|
|
1862
|
-
s(new
|
|
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 }),
|
|
1906
|
-
if (!
|
|
1907
|
-
await
|
|
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
|
-
}),
|
|
1942
|
-
if (!
|
|
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
|
-
|
|
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
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1995
|
+
D as ApiGatewayClient,
|
|
1996
|
+
ut as AuthClient,
|
|
1997
|
+
dt as BillingClient,
|
|
1978
1998
|
ft as EventTracker,
|
|
1979
|
-
|
|
1980
|
-
|
|
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,
|