@monetize.software/sdk-extension 3.0.0-alpha.8 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/ar-CViBaj16.js +2 -0
- package/dist/chunks/ar-CViBaj16.js.map +1 -0
- package/dist/chunks/{ar-nh4l4WDE.js → ar-ClwBmll7.js} +9 -4
- package/dist/chunks/ar-ClwBmll7.js.map +1 -0
- package/dist/chunks/chrome-port-BEMjZQAH.js +2 -0
- package/dist/chunks/chrome-port-BEMjZQAH.js.map +1 -0
- package/dist/chunks/{chrome-port-CxW3Pwc2.js → chrome-port-bfTUUDz_.js} +174 -138
- package/dist/chunks/chrome-port-bfTUUDz_.js.map +1 -0
- package/dist/chunks/{cs-2UYO2rWf.js → cs-Cc_D0W4S.js} +7 -2
- package/dist/chunks/cs-Cc_D0W4S.js.map +1 -0
- package/dist/chunks/cs-DQJWP65K.js +2 -0
- package/dist/chunks/cs-DQJWP65K.js.map +1 -0
- package/dist/chunks/{da-BD0O_HfV.js → da-BtKcMSxH.js} +7 -2
- package/dist/chunks/da-BtKcMSxH.js.map +1 -0
- package/dist/chunks/da-Cyr_IXhb.js +2 -0
- package/dist/chunks/da-Cyr_IXhb.js.map +1 -0
- package/dist/chunks/de-BOCUj1pF.js +2 -0
- package/dist/chunks/de-BOCUj1pF.js.map +1 -0
- package/dist/chunks/{de-BkCiXPsn.js → de-iwQW5eYl.js} +8 -2
- package/dist/chunks/de-iwQW5eYl.js.map +1 -0
- package/dist/chunks/{el-cIcxTp07.js → el-BoH65CeJ.js} +7 -2
- package/dist/chunks/el-BoH65CeJ.js.map +1 -0
- package/dist/chunks/el-C6jLHiEF.js +2 -0
- package/dist/chunks/el-C6jLHiEF.js.map +1 -0
- package/dist/chunks/es-CARHLxHR.js +2 -0
- package/dist/chunks/es-CARHLxHR.js.map +1 -0
- package/dist/chunks/{es-CJBC_jrV.js → es-CkP16_8K.js} +8 -2
- package/dist/chunks/es-CkP16_8K.js.map +1 -0
- package/dist/chunks/fi-B8OhRbwY.js +2 -0
- package/dist/chunks/fi-B8OhRbwY.js.map +1 -0
- package/dist/chunks/{fi-DyV7ynBf.js → fi-yUXSmK1E.js} +7 -2
- package/dist/chunks/fi-yUXSmK1E.js.map +1 -0
- package/dist/chunks/fr-CoM18zzM.js +2 -0
- package/dist/chunks/fr-CoM18zzM.js.map +1 -0
- package/dist/chunks/{fr-BLQ4AIu7.js → fr-DSZRGsxI.js} +8 -2
- package/dist/chunks/fr-DSZRGsxI.js.map +1 -0
- package/dist/chunks/he-DTDVc3lA.js +2 -0
- package/dist/chunks/he-DTDVc3lA.js.map +1 -0
- package/dist/chunks/{he-Bg-Bqi7r.js → he-ZUo7cQjk.js} +9 -4
- package/dist/chunks/he-ZUo7cQjk.js.map +1 -0
- package/dist/chunks/hi-BjnS9UeE.js +2 -0
- package/dist/chunks/hi-BjnS9UeE.js.map +1 -0
- package/dist/chunks/{hi-wQeE43oY.js → hi-CEutBKiG.js} +9 -4
- package/dist/chunks/hi-CEutBKiG.js.map +1 -0
- package/dist/chunks/hu-CN06FMhV.js +2 -0
- package/dist/chunks/hu-CN06FMhV.js.map +1 -0
- package/dist/chunks/{hu-D9qxzu0r.js → hu-DvEAWGS7.js} +7 -2
- package/dist/chunks/hu-DvEAWGS7.js.map +1 -0
- package/dist/chunks/id-BITgaBxq.js +2 -0
- package/dist/chunks/id-BITgaBxq.js.map +1 -0
- package/dist/chunks/{id-Rx_wYvqy.js → id-_eEMrYMW.js} +7 -2
- package/dist/chunks/id-_eEMrYMW.js.map +1 -0
- package/dist/chunks/{it-B1SRPZ3e.js → it-BAmsQbIl.js} +8 -2
- package/dist/chunks/it-BAmsQbIl.js.map +1 -0
- package/dist/chunks/it-DVcsq015.js +2 -0
- package/dist/chunks/it-DVcsq015.js.map +1 -0
- package/dist/chunks/ja-Bim7Ok2e.js +2 -0
- package/dist/chunks/ja-Bim7Ok2e.js.map +1 -0
- package/dist/chunks/{ja-DiItm8te.js → ja-BqCZWVKK.js} +10 -4
- package/dist/chunks/ja-BqCZWVKK.js.map +1 -0
- package/dist/chunks/{ko-CdGFWAKX.js → ko-CkIzeOzb.js} +10 -4
- package/dist/chunks/ko-CkIzeOzb.js.map +1 -0
- package/dist/chunks/ko-DqEfcVCB.js +2 -0
- package/dist/chunks/ko-DqEfcVCB.js.map +1 -0
- package/dist/chunks/nl-DSNuJWIo.js +2 -0
- package/dist/chunks/nl-DSNuJWIo.js.map +1 -0
- package/dist/chunks/{nl-CmZ3vEvj.js → nl-Mu_KNzli.js} +8 -2
- package/dist/chunks/nl-Mu_KNzli.js.map +1 -0
- package/dist/chunks/{no-BuxByZpq.js → no-9HMjljBs.js} +7 -2
- package/dist/chunks/no-9HMjljBs.js.map +1 -0
- package/dist/chunks/no-B5HY_A8_.js +2 -0
- package/dist/chunks/no-B5HY_A8_.js.map +1 -0
- package/dist/chunks/{pl-jZFCnDb8.js → pl-Cbr2qDwv.js} +7 -2
- package/dist/chunks/pl-Cbr2qDwv.js.map +1 -0
- package/dist/chunks/pl-ChGLn9Sy.js +2 -0
- package/dist/chunks/pl-ChGLn9Sy.js.map +1 -0
- package/dist/chunks/port-name-CF4WQQ3-.js +2 -0
- package/dist/chunks/port-name-CF4WQQ3-.js.map +1 -0
- package/dist/chunks/port-name-ervLBWAQ.js +6 -0
- package/dist/chunks/port-name-ervLBWAQ.js.map +1 -0
- package/dist/chunks/pt-CDLEktT9.js +2 -0
- package/dist/chunks/pt-CDLEktT9.js.map +1 -0
- package/dist/chunks/{pt-Cld7MwIW.js → pt-_jirA6IR.js} +8 -2
- package/dist/chunks/pt-_jirA6IR.js.map +1 -0
- package/dist/chunks/ro-BHCHiXY3.js +2 -0
- package/dist/chunks/ro-BHCHiXY3.js.map +1 -0
- package/dist/chunks/{ro-CuKDqj3C.js → ro-oZLxhwHc.js} +7 -2
- package/dist/chunks/ro-oZLxhwHc.js.map +1 -0
- package/dist/chunks/ru-B6HgmINj.js +2 -0
- package/dist/chunks/ru-B6HgmINj.js.map +1 -0
- package/dist/chunks/{ru-B7cjqJUm.js → ru-C2-sqY7B.js} +15 -2
- package/dist/chunks/ru-C2-sqY7B.js.map +1 -0
- package/dist/chunks/sv-DoSs4a9n.js +2 -0
- package/dist/chunks/sv-DoSs4a9n.js.map +1 -0
- package/dist/chunks/{sv-D9y-M1Fo.js → sv-y385MWVy.js} +7 -2
- package/dist/chunks/sv-y385MWVy.js.map +1 -0
- package/dist/chunks/{th-D9umBjEy.js → th-Bjbv4M1s.js} +7 -2
- package/dist/chunks/th-Bjbv4M1s.js.map +1 -0
- package/dist/chunks/th-UeweOhwg.js +2 -0
- package/dist/chunks/th-UeweOhwg.js.map +1 -0
- package/dist/chunks/tr-BbBr5tyB.js +2 -0
- package/dist/chunks/tr-BbBr5tyB.js.map +1 -0
- package/dist/chunks/{tr-BddMywiw.js → tr-DmHo9F8i.js} +9 -4
- package/dist/chunks/tr-DmHo9F8i.js.map +1 -0
- package/dist/chunks/uk-CJTA1SJK.js +2 -0
- package/dist/chunks/uk-CJTA1SJK.js.map +1 -0
- package/dist/chunks/{uk-Dbd31hFt.js → uk-DwvAoTe5.js} +15 -2
- package/dist/chunks/uk-DwvAoTe5.js.map +1 -0
- package/dist/chunks/{vi-Do3BMOdh.js → vi-BEpwsVLR.js} +7 -2
- package/dist/chunks/vi-BEpwsVLR.js.map +1 -0
- package/dist/chunks/vi-ZvBo7PbB.js +2 -0
- package/dist/chunks/vi-ZvBo7PbB.js.map +1 -0
- package/dist/chunks/zh-CPZBEb3d.js +2 -0
- package/dist/chunks/zh-CPZBEb3d.js.map +1 -0
- package/dist/chunks/{zh-gQSYLZI3.js → zh-DrG18oGe.js} +9 -3
- package/dist/chunks/zh-DrG18oGe.js.map +1 -0
- package/dist/content/PaywallUI.d.ts +1 -1
- package/dist/content/RemoteAuthClient.d.ts +3 -3
- package/dist/content/RemoteBillingClient.d.ts +7 -3
- package/dist/content/RemoteBillingClient.d.ts.map +1 -1
- package/dist/content/RemoteTrialStore.d.ts +2 -2
- package/dist/content.cjs +3 -3
- package/dist/content.cjs.map +1 -1
- package/dist/content.js +1289 -893
- package/dist/content.js.map +1 -1
- package/dist/offscreen/server.d.ts +3 -3
- package/dist/offscreen/server.d.ts.map +1 -1
- package/dist/offscreen.cjs +1 -1
- package/dist/offscreen.cjs.map +1 -1
- package/dist/offscreen.js +9 -9
- package/dist/offscreen.js.map +1 -1
- package/dist/shared/messages.d.ts +4 -4
- package/dist/shared/port-name.d.ts +1 -0
- package/dist/shared/port-name.d.ts.map +1 -1
- package/dist/sw.cjs +1 -1
- package/dist/sw.cjs.map +1 -1
- package/dist/sw.js +14 -14
- package/dist/sw.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunks/ar-BUQInJ5a.js +0 -2
- package/dist/chunks/ar-BUQInJ5a.js.map +0 -1
- package/dist/chunks/ar-nh4l4WDE.js.map +0 -1
- package/dist/chunks/chrome-port-CxW3Pwc2.js.map +0 -1
- package/dist/chunks/chrome-port-PhlW29BV.js +0 -2
- package/dist/chunks/chrome-port-PhlW29BV.js.map +0 -1
- package/dist/chunks/cs-2UYO2rWf.js.map +0 -1
- package/dist/chunks/cs-i5K4KTFV.js +0 -2
- package/dist/chunks/cs-i5K4KTFV.js.map +0 -1
- package/dist/chunks/da-BD0O_HfV.js.map +0 -1
- package/dist/chunks/da-CZbhtVJO.js +0 -2
- package/dist/chunks/da-CZbhtVJO.js.map +0 -1
- package/dist/chunks/de-Bc-GoLgC.js +0 -2
- package/dist/chunks/de-Bc-GoLgC.js.map +0 -1
- package/dist/chunks/de-BkCiXPsn.js.map +0 -1
- package/dist/chunks/el-CcMEbl_F.js +0 -2
- package/dist/chunks/el-CcMEbl_F.js.map +0 -1
- package/dist/chunks/el-cIcxTp07.js.map +0 -1
- package/dist/chunks/es-BvYmomAz.js +0 -2
- package/dist/chunks/es-BvYmomAz.js.map +0 -1
- package/dist/chunks/es-CJBC_jrV.js.map +0 -1
- package/dist/chunks/fi-DyV7ynBf.js.map +0 -1
- package/dist/chunks/fi-aZR-qmZN.js +0 -2
- package/dist/chunks/fi-aZR-qmZN.js.map +0 -1
- package/dist/chunks/fr-BLQ4AIu7.js.map +0 -1
- package/dist/chunks/fr-BgbFAgHx.js +0 -2
- package/dist/chunks/fr-BgbFAgHx.js.map +0 -1
- package/dist/chunks/he-Bg-Bqi7r.js.map +0 -1
- package/dist/chunks/he-CQ4yCuja.js +0 -2
- package/dist/chunks/he-CQ4yCuja.js.map +0 -1
- package/dist/chunks/hi-DtUsj1c-.js +0 -2
- package/dist/chunks/hi-DtUsj1c-.js.map +0 -1
- package/dist/chunks/hi-wQeE43oY.js.map +0 -1
- package/dist/chunks/hu-D9qxzu0r.js.map +0 -1
- package/dist/chunks/hu-DXtscQ8_.js +0 -2
- package/dist/chunks/hu-DXtscQ8_.js.map +0 -1
- package/dist/chunks/id-BByOYpeo.js +0 -2
- package/dist/chunks/id-BByOYpeo.js.map +0 -1
- package/dist/chunks/id-Rx_wYvqy.js.map +0 -1
- package/dist/chunks/it-52Ip42pa.js +0 -2
- package/dist/chunks/it-52Ip42pa.js.map +0 -1
- package/dist/chunks/it-B1SRPZ3e.js.map +0 -1
- package/dist/chunks/ja-CMC3Parn.js +0 -2
- package/dist/chunks/ja-CMC3Parn.js.map +0 -1
- package/dist/chunks/ja-DiItm8te.js.map +0 -1
- package/dist/chunks/ko-3qY21q40.js +0 -2
- package/dist/chunks/ko-3qY21q40.js.map +0 -1
- package/dist/chunks/ko-CdGFWAKX.js.map +0 -1
- package/dist/chunks/nl-Borc5nw1.js +0 -2
- package/dist/chunks/nl-Borc5nw1.js.map +0 -1
- package/dist/chunks/nl-CmZ3vEvj.js.map +0 -1
- package/dist/chunks/no-BuxByZpq.js.map +0 -1
- package/dist/chunks/no-Do2iGedg.js +0 -2
- package/dist/chunks/no-Do2iGedg.js.map +0 -1
- package/dist/chunks/pl-jZFCnDb8.js.map +0 -1
- package/dist/chunks/pl-mRaky_7k.js +0 -2
- package/dist/chunks/pl-mRaky_7k.js.map +0 -1
- package/dist/chunks/port-name-BPfQKtdb.js +0 -5
- package/dist/chunks/port-name-BPfQKtdb.js.map +0 -1
- package/dist/chunks/port-name-qwB109u9.js +0 -2
- package/dist/chunks/port-name-qwB109u9.js.map +0 -1
- package/dist/chunks/pt-Cld7MwIW.js.map +0 -1
- package/dist/chunks/pt-DilDTXfs.js +0 -2
- package/dist/chunks/pt-DilDTXfs.js.map +0 -1
- package/dist/chunks/ro-CuKDqj3C.js.map +0 -1
- package/dist/chunks/ro-DF2uzPIB.js +0 -2
- package/dist/chunks/ro-DF2uzPIB.js.map +0 -1
- package/dist/chunks/ru-B7cjqJUm.js.map +0 -1
- package/dist/chunks/ru-YeaXnTO-.js +0 -2
- package/dist/chunks/ru-YeaXnTO-.js.map +0 -1
- package/dist/chunks/sv-2pHEvuSe.js +0 -2
- package/dist/chunks/sv-2pHEvuSe.js.map +0 -1
- package/dist/chunks/sv-D9y-M1Fo.js.map +0 -1
- package/dist/chunks/th-D9umBjEy.js.map +0 -1
- package/dist/chunks/th-u2QSDF0G.js +0 -2
- package/dist/chunks/th-u2QSDF0G.js.map +0 -1
- package/dist/chunks/tr-BddMywiw.js.map +0 -1
- package/dist/chunks/tr-Bhgm6_ti.js +0 -2
- package/dist/chunks/tr-Bhgm6_ti.js.map +0 -1
- package/dist/chunks/uk-7vwqsaVK.js +0 -2
- package/dist/chunks/uk-7vwqsaVK.js.map +0 -1
- package/dist/chunks/uk-Dbd31hFt.js.map +0 -1
- package/dist/chunks/vi-CJefLP_g.js +0 -2
- package/dist/chunks/vi-CJefLP_g.js.map +0 -1
- package/dist/chunks/vi-Do3BMOdh.js.map +0 -1
- package/dist/chunks/zh-D5C3BzYL.js +0 -2
- package/dist/chunks/zh-D5C3BzYL.js.map +0 -1
- package/dist/chunks/zh-gQSYLZI3.js.map +0 -1
|
@@ -20,24 +20,24 @@ class P {
|
|
|
20
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 r = await this.opts.getAuthToken?.();
|
|
22
22
|
r && n.set("Authorization", `Bearer ${r}`);
|
|
23
|
-
const
|
|
24
|
-
e.body && !n.has("Content-Type") && !
|
|
25
|
-
let
|
|
23
|
+
const h = typeof FormData < "u" && e.body instanceof FormData;
|
|
24
|
+
e.body && !n.has("Content-Type") && !h && n.set("Content-Type", "application/json");
|
|
25
|
+
let f;
|
|
26
26
|
try {
|
|
27
|
-
|
|
27
|
+
f = await a(s, {
|
|
28
28
|
...e,
|
|
29
29
|
headers: n,
|
|
30
30
|
credentials: "omit"
|
|
31
31
|
});
|
|
32
|
-
} catch (
|
|
33
|
-
throw (
|
|
32
|
+
} catch (c) {
|
|
33
|
+
throw (c && typeof c == "object" && "name" in c ? c.name : void 0) === "AbortError" ? new o("aborted", "Request aborted", { cause: c }) : new o("network_error", "Network request failed", { cause: c });
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
37
|
-
const
|
|
38
|
-
throw new o(
|
|
35
|
+
const d = (f.headers.get("content-type") ?? "").includes("application/json") ? await f.json().catch(() => null) : null;
|
|
36
|
+
if (!f.ok) {
|
|
37
|
+
const c = d && typeof d == "object" && "code" in d && String(d.code) || `http_${f.status}`, g = d && typeof d == "object" && "message" in d && String(d.message) || f.statusText || "Request failed";
|
|
38
|
+
throw new o(c, g, { status: f.status, cause: d });
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return d;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
function x() {
|
|
@@ -101,18 +101,18 @@ const H = {
|
|
|
101
101
|
};
|
|
102
102
|
return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
|
|
103
103
|
}
|
|
104
|
-
},
|
|
104
|
+
}, I = /* @__PURE__ */ new Map(), V = {
|
|
105
105
|
async getItem(i) {
|
|
106
|
-
return
|
|
106
|
+
return I.get(i) ?? null;
|
|
107
107
|
},
|
|
108
108
|
async setItem(i, t) {
|
|
109
|
-
|
|
109
|
+
I.set(i, t);
|
|
110
110
|
},
|
|
111
111
|
async removeItem(i) {
|
|
112
|
-
|
|
112
|
+
I.delete(i);
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
|
-
function
|
|
115
|
+
function K(i) {
|
|
116
116
|
return i || (x() ? H : typeof window < "u" && "localStorage" in window ? J : V);
|
|
117
117
|
}
|
|
118
118
|
const u = {
|
|
@@ -145,7 +145,7 @@ const u = {
|
|
|
145
145
|
// (оптимистично через `decrementBalanceLocal`).
|
|
146
146
|
balances: (i, t) => `pw-${i}-${t}-balances-v1`
|
|
147
147
|
};
|
|
148
|
-
function
|
|
148
|
+
function R() {
|
|
149
149
|
const i = typeof globalThis < "u" ? globalThis.crypto : void 0;
|
|
150
150
|
if (i && typeof i.randomUUID == "function") return i.randomUUID();
|
|
151
151
|
const t = new Uint8Array(16);
|
|
@@ -157,20 +157,20 @@ function D() {
|
|
|
157
157
|
const e = Array.from(t, (s) => s.toString(16).padStart(2, "0")).join("");
|
|
158
158
|
return `${e.slice(0, 8)}-${e.slice(8, 12)}-${e.slice(12, 16)}-${e.slice(16, 20)}-${e.slice(20)}`;
|
|
159
159
|
}
|
|
160
|
-
async function
|
|
160
|
+
async function B(i) {
|
|
161
161
|
try {
|
|
162
162
|
const e = await i.getItem(u.visitorId);
|
|
163
163
|
if (e && typeof e == "string" && e.length >= 16) return e;
|
|
164
164
|
} catch {
|
|
165
165
|
}
|
|
166
|
-
const t =
|
|
166
|
+
const t = R();
|
|
167
167
|
try {
|
|
168
168
|
await i.setItem(u.visitorId, t);
|
|
169
169
|
} catch {
|
|
170
170
|
}
|
|
171
171
|
return t;
|
|
172
172
|
}
|
|
173
|
-
function
|
|
173
|
+
function D(i) {
|
|
174
174
|
const t = new Uint8Array(i), e = typeof globalThis < "u" ? globalThis.crypto : void 0;
|
|
175
175
|
if (e && typeof e.getRandomValues == "function")
|
|
176
176
|
e.getRandomValues(t);
|
|
@@ -178,23 +178,23 @@ function M(i) {
|
|
|
178
178
|
for (let s = 0; s < i; s++) t[s] = Math.floor(Math.random() * 256);
|
|
179
179
|
return t;
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function _(i) {
|
|
182
182
|
let t = "";
|
|
183
183
|
for (let e = 0; e < i.length; e++) t += String.fromCharCode(i[e]);
|
|
184
184
|
return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
185
185
|
}
|
|
186
186
|
function j() {
|
|
187
|
-
return
|
|
187
|
+
return _(D(64));
|
|
188
188
|
}
|
|
189
|
-
async function
|
|
189
|
+
async function X(i) {
|
|
190
190
|
const t = new TextEncoder().encode(i), e = globalThis.crypto;
|
|
191
191
|
if (!e?.subtle?.digest)
|
|
192
192
|
throw new Error("crypto.subtle is required for PKCE");
|
|
193
193
|
const s = await e.subtle.digest("SHA-256", t);
|
|
194
|
-
return
|
|
194
|
+
return _(new Uint8Array(s));
|
|
195
195
|
}
|
|
196
|
-
function
|
|
197
|
-
return
|
|
196
|
+
function G() {
|
|
197
|
+
return _(D(16));
|
|
198
198
|
}
|
|
199
199
|
const z = 6e4, Q = 600 * 1e3;
|
|
200
200
|
class mt {
|
|
@@ -206,7 +206,7 @@ class mt {
|
|
|
206
206
|
"invalid_config",
|
|
207
207
|
"apiOrigin is required. Pass the paywall custom_domain configured in the platform."
|
|
208
208
|
);
|
|
209
|
-
this.paywallId = t.paywallId, this.apiOrigin = t.apiOrigin, this.storage =
|
|
209
|
+
this.paywallId = t.paywallId, this.apiOrigin = t.apiOrigin, this.storage = K(t.storage), this.api = new P({
|
|
210
210
|
apiOrigin: this.apiOrigin,
|
|
211
211
|
paywallId: t.paywallId,
|
|
212
212
|
fetch: t.fetch
|
|
@@ -448,10 +448,8 @@ class mt {
|
|
|
448
448
|
* когда сервер начнёт возвращать challenge_required в риск-сценариях,
|
|
449
449
|
* SDK сможет передать proof-of-something обратно без breaking change.
|
|
450
450
|
*
|
|
451
|
-
* `
|
|
452
|
-
* нового anon-юзера). Используется в switch-account flow.
|
|
453
|
-
* остаётся `forceCaptcha`, хотя капчи там больше нет — менять имя ломает
|
|
454
|
-
* host-сигнатуру; смысл «принудительно новая anon-сессия» сохранён.
|
|
451
|
+
* `forceNewAnon: true` пропускает шаги 1-2 и сразу делает /signin (создаёт
|
|
452
|
+
* нового anon-юзера). Используется в switch-account flow.
|
|
455
453
|
*
|
|
456
454
|
* Параллельные вызовы дедуплицируются через `inflightAnonSignin` — два
|
|
457
455
|
* click'а на «Войти как гость» не создадут двух anon-юзеров (два /signup =
|
|
@@ -460,9 +458,9 @@ class mt {
|
|
|
460
458
|
async signInAnonymously(t = {}) {
|
|
461
459
|
if (this.inflightAnonSignin) return this.inflightAnonSignin;
|
|
462
460
|
this.inflightAnonSignin = (async () => {
|
|
463
|
-
if (await this.hydrated, !t.
|
|
461
|
+
if (await this.hydrated, !t.forceNewAnon && this.session?.user.is_anonymous === !0)
|
|
464
462
|
return this.session;
|
|
465
|
-
if (!t.
|
|
463
|
+
if (!t.forceNewAnon) {
|
|
466
464
|
const r = await this.resumeAnonymous();
|
|
467
465
|
if (r) return r;
|
|
468
466
|
}
|
|
@@ -565,8 +563,8 @@ class mt {
|
|
|
565
563
|
id: a.user.id,
|
|
566
564
|
email: a.user.email,
|
|
567
565
|
is_anonymous: a.user.is_anonymous ?? !1
|
|
568
|
-
},
|
|
569
|
-
return this.setSession(
|
|
566
|
+
}, h = { ...n, user: r };
|
|
567
|
+
return this.setSession(h, { event: "USER_UPDATED" }), await this.clearAnonRefreshToken(), { kind: "updated", session: h };
|
|
570
568
|
}
|
|
571
569
|
/**
|
|
572
570
|
* OAuth signin через popup с PKCE. Жизненный цикл:
|
|
@@ -623,9 +621,9 @@ class mt {
|
|
|
623
621
|
*/
|
|
624
622
|
async startOAuthFlow(t) {
|
|
625
623
|
await this.hydrated, this.gcOAuthFlows();
|
|
626
|
-
const e = j(), s = await
|
|
624
|
+
const e = j(), s = await X(e), a = G(), n = {}, r = await this.getAccessToken().catch(() => null);
|
|
627
625
|
r && (n.Authorization = `Bearer ${r}`);
|
|
628
|
-
const { authorize_url:
|
|
626
|
+
const { authorize_url: h } = await this.api.request(
|
|
629
627
|
`/api/v1/paywall/${this.paywallId}/auth/oauth/init`,
|
|
630
628
|
{
|
|
631
629
|
method: "POST",
|
|
@@ -643,7 +641,7 @@ class mt {
|
|
|
643
641
|
userMeta: t.userMeta,
|
|
644
642
|
provider: t.provider,
|
|
645
643
|
startedAt: Date.now()
|
|
646
|
-
}), this.recordLastLoginMethod(t.provider), { authorize_url:
|
|
644
|
+
}), this.recordLastLoginMethod(t.provider), { authorize_url: h, state: a };
|
|
647
645
|
}
|
|
648
646
|
/**
|
|
649
647
|
* Шаг 2 OAuth split-API: обменивает code (полученный из popup) на session,
|
|
@@ -958,19 +956,19 @@ function Z(i, t) {
|
|
|
958
956
|
return new Promise((e, s) => {
|
|
959
957
|
let a = !1;
|
|
960
958
|
const n = () => {
|
|
961
|
-
a = !0, window.removeEventListener("message", r), clearInterval(
|
|
962
|
-
}, r = (
|
|
959
|
+
a = !0, window.removeEventListener("message", r), clearInterval(h), clearTimeout(f);
|
|
960
|
+
}, r = (p) => {
|
|
963
961
|
if (a) return;
|
|
964
|
-
const
|
|
965
|
-
if (!(!
|
|
966
|
-
if (
|
|
962
|
+
const l = p.data;
|
|
963
|
+
if (!(!l || l.type !== "pw-oauth") && l.messageId === t) {
|
|
964
|
+
if (l.status === "success" && l.code) {
|
|
967
965
|
n();
|
|
968
966
|
try {
|
|
969
967
|
i.close();
|
|
970
968
|
} catch {
|
|
971
969
|
}
|
|
972
|
-
e(
|
|
973
|
-
} else if (
|
|
970
|
+
e(l.code);
|
|
971
|
+
} else if (l.status === "error") {
|
|
974
972
|
n();
|
|
975
973
|
try {
|
|
976
974
|
i.close();
|
|
@@ -979,21 +977,21 @@ function Z(i, t) {
|
|
|
979
977
|
s(
|
|
980
978
|
new o(
|
|
981
979
|
"oauth_failed",
|
|
982
|
-
|
|
980
|
+
l.description || l.error || "OAuth provider returned error"
|
|
983
981
|
)
|
|
984
982
|
);
|
|
985
983
|
}
|
|
986
984
|
}
|
|
987
|
-
},
|
|
985
|
+
}, h = setInterval(() => {
|
|
988
986
|
if (a) return;
|
|
989
|
-
let
|
|
987
|
+
let p;
|
|
990
988
|
try {
|
|
991
|
-
|
|
989
|
+
p = i.closed;
|
|
992
990
|
} catch {
|
|
993
991
|
return;
|
|
994
992
|
}
|
|
995
|
-
|
|
996
|
-
}, Y),
|
|
993
|
+
p && (n(), s(new o("oauth_cancelled", "auth popup was closed")));
|
|
994
|
+
}, Y), f = setTimeout(() => {
|
|
997
995
|
if (!a) {
|
|
998
996
|
n();
|
|
999
997
|
try {
|
|
@@ -1035,37 +1033,37 @@ class st {
|
|
|
1035
1033
|
a.set("X-SDK-Version", m), a.set("X-Paywall-Id", this.paywallId), this.capabilities?.length && a.set("X-SDK-Capabilities", this.capabilities.join(","));
|
|
1036
1034
|
const n = await this.auth?.getAccessToken();
|
|
1037
1035
|
n ? a.set("Authorization", `Bearer ${n}`) : this.userId && a.set("X-User-ID", this.userId);
|
|
1038
|
-
const r = typeof FormData < "u" && t.body instanceof FormData,
|
|
1036
|
+
const r = typeof FormData < "u" && t.body instanceof FormData, h = typeof Blob < "u" && t.body instanceof Blob, f = typeof ReadableStream < "u" && t.body instanceof ReadableStream, p = typeof t.body == "string";
|
|
1037
|
+
let l;
|
|
1038
|
+
t.body === void 0 || t.body === null ? l = void 0 : r || h || f || p ? l = t.body : (l = JSON.stringify(t.body), a.has("Content-Type") || a.set("Content-Type", "application/json"));
|
|
1039
|
+
const d = this.customFetch ?? fetch;
|
|
1039
1040
|
let c;
|
|
1040
|
-
t.body === void 0 || t.body === null ? c = void 0 : r || l || d || f ? c = t.body : (c = JSON.stringify(t.body), a.has("Content-Type") || a.set("Content-Type", "application/json"));
|
|
1041
|
-
const y = this.customFetch ?? fetch;
|
|
1042
|
-
let h;
|
|
1043
1041
|
try {
|
|
1044
|
-
|
|
1042
|
+
c = await d(s.toString(), {
|
|
1045
1043
|
method: t.method ?? "POST",
|
|
1046
1044
|
headers: a,
|
|
1047
|
-
body:
|
|
1045
|
+
body: l,
|
|
1048
1046
|
signal: t.signal,
|
|
1049
1047
|
credentials: "omit"
|
|
1050
1048
|
});
|
|
1051
|
-
} catch (
|
|
1052
|
-
const $ =
|
|
1053
|
-
throw new o("network_error", `Network request failed: ${$}`, { cause:
|
|
1049
|
+
} catch (y) {
|
|
1050
|
+
const $ = y instanceof Error ? y.message : String(y);
|
|
1051
|
+
throw new o("network_error", `Network request failed: ${$}`, { cause: y });
|
|
1054
1052
|
}
|
|
1055
|
-
if (
|
|
1056
|
-
const
|
|
1057
|
-
throw this.onQuotaExceeded?.(
|
|
1053
|
+
if (c.status === 402) {
|
|
1054
|
+
const y = await it(c);
|
|
1055
|
+
throw this.onQuotaExceeded?.(y), y;
|
|
1058
1056
|
}
|
|
1059
|
-
if (!
|
|
1060
|
-
const
|
|
1057
|
+
if (!c.ok) {
|
|
1058
|
+
const y = await at(c.clone());
|
|
1061
1059
|
throw new o(
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
{ status:
|
|
1060
|
+
y ?? `http_${c.status}`,
|
|
1061
|
+
c.statusText || "Gateway request failed",
|
|
1062
|
+
{ status: c.status }
|
|
1065
1063
|
);
|
|
1066
1064
|
}
|
|
1067
|
-
const g =
|
|
1068
|
-
return this.onChargeSuccess?.(g),
|
|
1065
|
+
const g = c.headers.get("X-Query-Type") ?? void 0;
|
|
1066
|
+
return this.onChargeSuccess?.(g), c;
|
|
1069
1067
|
}
|
|
1070
1068
|
}
|
|
1071
1069
|
async function it(i) {
|
|
@@ -1095,7 +1093,7 @@ async function at(i) {
|
|
|
1095
1093
|
return null;
|
|
1096
1094
|
}
|
|
1097
1095
|
}
|
|
1098
|
-
const nt = 5e3, rt = 30 * 6e4,
|
|
1096
|
+
const nt = 5e3, rt = 30 * 6e4, k = 60 * 6e4, ot = 5 * 6e4, S = {
|
|
1099
1097
|
has_active_subscription: !1,
|
|
1100
1098
|
purchases: [],
|
|
1101
1099
|
trial: null,
|
|
@@ -1108,14 +1106,14 @@ function ct(i, t) {
|
|
|
1108
1106
|
return i === t ? !0 : !i || !t ? !1 : JSON.stringify(i) === JSON.stringify(t);
|
|
1109
1107
|
}
|
|
1110
1108
|
const ht = 5e3, T = 5 * 6e4, lt = 3e4;
|
|
1111
|
-
function
|
|
1109
|
+
function dt(i, t) {
|
|
1112
1110
|
if (i === t) return !0;
|
|
1113
1111
|
if (!i || !t || i.length !== t.length) return !1;
|
|
1114
1112
|
for (let e = 0; e < i.length; e++)
|
|
1115
1113
|
if (i[e].type !== t[e].type || i[e].count !== t[e].count) return !1;
|
|
1116
1114
|
return !0;
|
|
1117
1115
|
}
|
|
1118
|
-
class
|
|
1116
|
+
class It {
|
|
1119
1117
|
constructor(t) {
|
|
1120
1118
|
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)
|
|
1121
1119
|
throw new o("invalid_config", "paywallId is required");
|
|
@@ -1128,7 +1126,7 @@ class St {
|
|
|
1128
1126
|
const e = t.auth?.getCachedUser();
|
|
1129
1127
|
this.identity = t.identity ?? (e ? O(e) : void 0), this.apiKey = t.apiKey, this.fetchImpl = t.fetch, t.apiKey && typeof window < "u" && typeof window.document < "u" && console.error(
|
|
1130
1128
|
"[paywall] SECURITY: BillingClient.apiKey detected in browser context. This is a server-SDK key and exposes your account. Remove apiKey or move BillingClient to a trusted backend."
|
|
1131
|
-
), this.storage =
|
|
1129
|
+
), this.storage = K(t.storage), this.api = new P({
|
|
1132
1130
|
apiOrigin: this.apiOrigin,
|
|
1133
1131
|
paywallId: t.paywallId,
|
|
1134
1132
|
capabilities: t.capabilities,
|
|
@@ -1139,8 +1137,8 @@ class St {
|
|
|
1139
1137
|
getAuthToken: t.auth ? () => t.auth.getAccessToken() : void 0
|
|
1140
1138
|
}), t.auth && (this.authUnsubscribe = t.auth.onAuthChange((s, a) => {
|
|
1141
1139
|
const n = a ? O(a.user) : void 0;
|
|
1142
|
-
|
|
1143
|
-
})), this.hydrateUserFromStorage(), this.hydrateBootstrapFromStorage(), this.subscribeBootstrapStorage(), this.hydrateBalancesFromStorage(), this.subscribeBalancesStorage(), this.visitorIdPromise =
|
|
1140
|
+
ut(this.identity, n) || this.setIdentity(n);
|
|
1141
|
+
})), this.hydrateUserFromStorage(), this.hydrateBootstrapFromStorage(), this.subscribeBootstrapStorage(), this.hydrateBalancesFromStorage(), this.subscribeBalancesStorage(), this.visitorIdPromise = B(this.storage).then((s) => (this.visitorId = s, s));
|
|
1144
1142
|
}
|
|
1145
1143
|
/**
|
|
1146
1144
|
* Stable visitor_id (UUID v4). Первый вызов awaitит первичный резолв из
|
|
@@ -1148,15 +1146,15 @@ class St {
|
|
|
1148
1146
|
* EventTracker'ом для атрибуции аналитики.
|
|
1149
1147
|
*/
|
|
1150
1148
|
async getVisitorId() {
|
|
1151
|
-
return this.visitorId ? this.visitorId : (this.visitorIdPromise || (this.visitorIdPromise =
|
|
1149
|
+
return this.visitorId ? this.visitorId : (this.visitorIdPromise || (this.visitorIdPromise = B(this.storage).then((t) => (this.visitorId = t, t))), this.visitorIdPromise);
|
|
1152
1150
|
}
|
|
1153
1151
|
/** Sync-доступ к visitor_id. null если ещё не зарезолвили (первые ms жизни). */
|
|
1154
1152
|
getCachedVisitorId() {
|
|
1155
1153
|
return this.visitorId;
|
|
1156
1154
|
}
|
|
1157
1155
|
setIdentity(t) {
|
|
1158
|
-
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
|
|
1159
|
-
});
|
|
1156
|
+
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(() => {
|
|
1157
|
+
}) : (this.applyUser(S), this.applyBalances([]));
|
|
1160
1158
|
}
|
|
1161
1159
|
/**
|
|
1162
1160
|
* Отписаться от auth-event'ов и сбросить listener'ы. Вызывать когда
|
|
@@ -1184,7 +1182,7 @@ class St {
|
|
|
1184
1182
|
"BillingClient in preview mode but cachedBootstrap is not seeded. Call setBootstrap(bootstrap) before open()."
|
|
1185
1183
|
);
|
|
1186
1184
|
}
|
|
1187
|
-
const s = Date.now(), a = this.cachedBootstrap && this.cachedBootstrapAt > 0 && s - this.cachedBootstrapAt <
|
|
1185
|
+
const s = Date.now(), a = this.cachedBootstrap && this.cachedBootstrapAt > 0 && s - this.cachedBootstrapAt < k;
|
|
1188
1186
|
return !e.force && a ? (s - this.cachedBootstrapAt > ot && this.revalidateBootstrap(e.signal).catch(() => {
|
|
1189
1187
|
}), { ...this.cachedBootstrap, user: this.cachedUser ?? void 0 }) : this.inflightBootstrap ? this.inflightBootstrap : (this.inflightBootstrap = this.fetchBootstrap({
|
|
1190
1188
|
ifVersion: e.force ? void 0 : this.cachedBootstrap?.version,
|
|
@@ -1289,7 +1287,7 @@ class St {
|
|
|
1289
1287
|
const t = await this.storage.getItem(u.bootstrap(this.paywallId));
|
|
1290
1288
|
if (!t) return;
|
|
1291
1289
|
const e = JSON.parse(t);
|
|
1292
|
-
if (!e?.bootstrap || Date.now() - e.at >
|
|
1290
|
+
if (!e?.bootstrap || Date.now() - e.at > k || this.cachedBootstrap) return;
|
|
1293
1291
|
w(e.bootstrap), this.cachedBootstrap = e.bootstrap, this.cachedBootstrapAt = e.at;
|
|
1294
1292
|
for (const s of this.bootstrapListeners)
|
|
1295
1293
|
try {
|
|
@@ -1354,6 +1352,15 @@ class St {
|
|
|
1354
1352
|
getCachedPrices() {
|
|
1355
1353
|
return this.cachedBootstrap?.prices ?? null;
|
|
1356
1354
|
}
|
|
1355
|
+
/** Sync-снимок офферов из последнего bootstrap'а. null = bootstrap ещё не
|
|
1356
|
+
* загружали, пустой массив = бэк отдал пейвол без офферов. Бэк уже
|
|
1357
|
+
* применил серверный таргетинг (target_countries / target_emails /
|
|
1358
|
+
* targeting_mode из offer_settings) — наружу выезжает только то, что
|
|
1359
|
+
* применимо к текущему юзеру. Клиентская сторона остаётся ответственной
|
|
1360
|
+
* за price_id-matching и countdown (см. core/offer.ts → resolveOffer). */
|
|
1361
|
+
getCachedOffers() {
|
|
1362
|
+
return this.cachedBootstrap?.offers ?? null;
|
|
1363
|
+
}
|
|
1357
1364
|
/**
|
|
1358
1365
|
* Снимок того, какой язык SDK сейчас считает «языком юзера». Полезно для
|
|
1359
1366
|
* синхронизации i18n хоста с тем, что фактически показывает пейвол — чтобы
|
|
@@ -1373,7 +1380,7 @@ class St {
|
|
|
1373
1380
|
* есть `navigator.language`.
|
|
1374
1381
|
*/
|
|
1375
1382
|
getUserLanguage() {
|
|
1376
|
-
const t = typeof navigator < "u" && navigator.language ? navigator.language : null, e = this.cachedBootstrap?.settings.locale_default ?? null, s = this.cachedBootstrap ?
|
|
1383
|
+
const t = typeof navigator < "u" && navigator.language ? navigator.language : null, e = this.cachedBootstrap?.settings.locale_default ?? null, s = this.cachedBootstrap ? M(this.cachedBootstrap) : null;
|
|
1377
1384
|
return { tag: s ?? t ?? e, applied: s, browserLanguage: t, countryLanguage: e };
|
|
1378
1385
|
}
|
|
1379
1386
|
/**
|
|
@@ -1388,7 +1395,7 @@ class St {
|
|
|
1388
1395
|
return !t && this.cachedUser && Date.now() - this.cachedUserAt < nt ? this.cachedUser : this.inflightUser ? this.inflightUser : (this.inflightUser = (async () => {
|
|
1389
1396
|
try {
|
|
1390
1397
|
if (!this.identity?.email)
|
|
1391
|
-
return this.applyUser(
|
|
1398
|
+
return this.applyUser(S), S;
|
|
1392
1399
|
const s = await this.api.request(
|
|
1393
1400
|
`/api/v1/paywall/${this.paywallId}/user-state`,
|
|
1394
1401
|
{ headers: { "X-User-Email": this.identity.email }, signal: e }
|
|
@@ -1598,7 +1605,7 @@ class St {
|
|
|
1598
1605
|
});
|
|
1599
1606
|
}
|
|
1600
1607
|
applyBalances(t, { persist: e = !0 } = {}) {
|
|
1601
|
-
const s = !
|
|
1608
|
+
const s = !dt(this.cachedBalances, t);
|
|
1602
1609
|
if (this.cachedBalances = t, this.cachedBalancesAt = Date.now(), e && this.persistBalances(t), s)
|
|
1603
1610
|
for (const a of this.balanceListeners)
|
|
1604
1611
|
try {
|
|
@@ -1662,23 +1669,27 @@ class St {
|
|
|
1662
1669
|
const e = t.idempotencyKey ?? `auto:${t.priceId}`, s = this.inflightCheckouts.get(e);
|
|
1663
1670
|
if (s) return s;
|
|
1664
1671
|
const n = {
|
|
1665
|
-
"Idempotency-Key": t.idempotencyKey ??
|
|
1672
|
+
"Idempotency-Key": t.idempotencyKey ?? R()
|
|
1666
1673
|
};
|
|
1667
1674
|
this.apiKey && (n["X-Api-Key"] = this.apiKey);
|
|
1668
|
-
const r = this.cachedBootstrap?.settings,
|
|
1675
|
+
const r = this.cachedBootstrap?.settings, h = t.successUrl ?? r?.success_redirect_url ?? void 0, f = t.shopUrl ?? r?.checkout_shop_url ?? void 0, l = this.cachedBootstrap?.prices.find(
|
|
1676
|
+
(c) => c.id === t.priceId
|
|
1677
|
+
)?.local?.currency ?? void 0, d = this.api.request(`/api/v1/paywall/${this.paywallId}/start-checkout`, {
|
|
1669
1678
|
method: "POST",
|
|
1670
1679
|
headers: n,
|
|
1671
1680
|
signal: t.signal,
|
|
1672
1681
|
body: JSON.stringify({
|
|
1673
1682
|
email: this.identity.email,
|
|
1674
1683
|
priceId: Number(t.priceId),
|
|
1675
|
-
|
|
1684
|
+
offerId: t.offerId,
|
|
1685
|
+
successUrl: h,
|
|
1676
1686
|
errorUrl: t.errorUrl,
|
|
1677
|
-
shopUrl:
|
|
1687
|
+
shopUrl: f,
|
|
1678
1688
|
productName: r?.checkout_product_name ?? void 0,
|
|
1679
1689
|
trial_days: t.trialDays,
|
|
1680
1690
|
ignoreActivePurchase: t.ignoreActivePurchase ? !0 : void 0,
|
|
1681
|
-
userMeta: this.identity.userId ? { userId: this.identity.userId } : void 0
|
|
1691
|
+
userMeta: this.identity.userId ? { userId: this.identity.userId } : void 0,
|
|
1692
|
+
localCurrency: l
|
|
1682
1693
|
})
|
|
1683
1694
|
}).then((c) => ({ url: c.checkoutUrl, acquiring: c.acquiring })).catch((c) => {
|
|
1684
1695
|
throw c instanceof o && c.status === 409 && c.cause && typeof c.cause == "object" && c.cause.hasActivePurchase === !0 ? new o(
|
|
@@ -1687,10 +1698,10 @@ class St {
|
|
|
1687
1698
|
{ status: 409, cause: c.cause }
|
|
1688
1699
|
) : c;
|
|
1689
1700
|
});
|
|
1690
|
-
return this.inflightCheckouts.set(e,
|
|
1691
|
-
this.inflightCheckouts.get(e) ===
|
|
1701
|
+
return this.inflightCheckouts.set(e, d), d.finally(() => {
|
|
1702
|
+
this.inflightCheckouts.get(e) === d && this.inflightCheckouts.delete(e);
|
|
1692
1703
|
}).catch(() => {
|
|
1693
|
-
}),
|
|
1704
|
+
}), d;
|
|
1694
1705
|
}
|
|
1695
1706
|
/**
|
|
1696
1707
|
* URL Stripe/Paddle/Chargebee customer portal — место, где залогиненный
|
|
@@ -1698,7 +1709,9 @@ class St {
|
|
|
1698
1709
|
* инвойсы). Опен-флоу управляется host'ом:
|
|
1699
1710
|
*
|
|
1700
1711
|
* ```ts
|
|
1701
|
-
* const { url } = await billing.getCustomerPortalUrl(
|
|
1712
|
+
* const { url } = await billing.getCustomerPortalUrl({
|
|
1713
|
+
* returnUrl: 'https://your-app.com/account'
|
|
1714
|
+
* });
|
|
1702
1715
|
* window.open(url, '_blank');
|
|
1703
1716
|
* ```
|
|
1704
1717
|
*
|
|
@@ -1716,9 +1729,10 @@ class St {
|
|
|
1716
1729
|
);
|
|
1717
1730
|
const e = {};
|
|
1718
1731
|
this.apiKey && (e["X-Api-Key"] = this.apiKey);
|
|
1719
|
-
const s = this.auth && this.auth.getCachedSession() ? {} : {
|
|
1732
|
+
const s = this.auth && this.auth.getCachedSession() ? { returnUrl: t.returnUrl } : {
|
|
1720
1733
|
email: this.identity?.email,
|
|
1721
|
-
userMeta: this.identity?.userId ? { userId: this.identity.userId } : void 0
|
|
1734
|
+
userMeta: this.identity?.userId ? { userId: this.identity.userId } : void 0,
|
|
1735
|
+
returnUrl: t.returnUrl
|
|
1722
1736
|
};
|
|
1723
1737
|
return { url: (await this.api.request(
|
|
1724
1738
|
`/api/v1/paywall/${this.paywallId}/get-customer-portal`,
|
|
@@ -1737,43 +1751,65 @@ class St {
|
|
|
1737
1751
|
* `/api/v1/paywall/[id]/user` без unstable_cache, потому что list для UI
|
|
1738
1752
|
* должен быть свежим после cancel-а.
|
|
1739
1753
|
*
|
|
1740
|
-
* Auth
|
|
1741
|
-
*
|
|
1754
|
+
* Auth (два пути):
|
|
1755
|
+
* - Bearer (через AuthClient) — user.id резолвится из сессии, identity
|
|
1756
|
+
* в query игнорируется.
|
|
1757
|
+
* - `apiKey` + `identity.email`/`identity.userId` — server-SDK путь для
|
|
1758
|
+
* интеграций со своей авторизацией. Бэк проверяет, что identity линкована
|
|
1759
|
+
* к этому пейволу (защита от cross-paywall lookup).
|
|
1760
|
+
* Без auth и без apiKey+identity — `identity_required`.
|
|
1742
1761
|
*/
|
|
1743
1762
|
async listPurchases(t = {}) {
|
|
1744
|
-
|
|
1763
|
+
const e = !!(this.identity?.email || this.identity?.userId);
|
|
1764
|
+
if (!this.auth && !(this.apiKey && e))
|
|
1745
1765
|
throw new o(
|
|
1746
|
-
"
|
|
1747
|
-
"listPurchases requires AuthClient (Bearer
|
|
1766
|
+
"identity_required",
|
|
1767
|
+
"listPurchases requires AuthClient (Bearer) or apiKey + identity.email/userId"
|
|
1748
1768
|
);
|
|
1749
|
-
|
|
1769
|
+
const s = {};
|
|
1770
|
+
this.apiKey && (s["X-Api-Key"] = this.apiKey);
|
|
1771
|
+
const a = new URLSearchParams();
|
|
1772
|
+
this.apiKey && this.identity?.email && a.set("email", this.identity.email), this.apiKey && this.identity?.userId && a.set("user_id", this.identity.userId);
|
|
1773
|
+
const n = a.toString(), r = n ? `/api/v1/paywall/${this.paywallId}/user?${n}` : `/api/v1/paywall/${this.paywallId}/user`;
|
|
1774
|
+
return (await this.api.request(r, {
|
|
1750
1775
|
method: "GET",
|
|
1776
|
+
headers: s,
|
|
1751
1777
|
signal: t.signal
|
|
1752
1778
|
})).purchases ?? [];
|
|
1753
1779
|
}
|
|
1754
1780
|
/**
|
|
1755
|
-
* Отменить подписку. Бэк
|
|
1756
|
-
*
|
|
1757
|
-
*
|
|
1781
|
+
* Отменить подписку. Бэк проверит, что subscription принадлежит юзеру
|
|
1782
|
+
* (Bearer-путь — из сессии; apiKey-путь — из identity), и сделает cancel у
|
|
1783
|
+
* acquiring'а (Stripe/Paddle/Chargebee/Overpay). По умолчанию cancel в
|
|
1784
|
+
* конце текущего периода — юзер сохраняет access до renewal date'ы.
|
|
1758
1785
|
*
|
|
1759
|
-
* `reason` обязательна (валидация на бэке).
|
|
1760
|
-
* причин в host-UI, как в legacy customer portal'е.
|
|
1786
|
+
* `reason` обязательна (валидация на бэке).
|
|
1761
1787
|
*
|
|
1762
|
-
* Auth
|
|
1788
|
+
* Auth (два пути):
|
|
1789
|
+
* - Bearer (через AuthClient) — стандартный путь для UI customer-portal'a.
|
|
1790
|
+
* - `apiKey` + `identity.email`/`identity.userId` — для self-service UI на
|
|
1791
|
+
* бэке клиента со своей авторизацией. Бэк дополнительно фильтрует
|
|
1792
|
+
* subscription по paywall_id, чтобы owner пейвола A не отменил подписку
|
|
1793
|
+
* пейвола B.
|
|
1763
1794
|
*/
|
|
1764
1795
|
async cancelSubscription(t) {
|
|
1765
|
-
|
|
1796
|
+
const e = !!(this.identity?.email || this.identity?.userId);
|
|
1797
|
+
if (!this.auth && !(this.apiKey && e))
|
|
1766
1798
|
throw new o(
|
|
1767
|
-
"
|
|
1768
|
-
"cancelSubscription requires AuthClient (Bearer
|
|
1799
|
+
"identity_required",
|
|
1800
|
+
"cancelSubscription requires AuthClient (Bearer) or apiKey + identity.email/userId"
|
|
1769
1801
|
);
|
|
1770
|
-
|
|
1802
|
+
const s = {};
|
|
1803
|
+
this.apiKey && (s["X-Api-Key"] = this.apiKey);
|
|
1804
|
+
const a = {
|
|
1805
|
+
subscriptionId: t.subscriptionId,
|
|
1806
|
+
paywallId: this.paywallId,
|
|
1807
|
+
cancellationReason: t.reason
|
|
1808
|
+
};
|
|
1809
|
+
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", {
|
|
1771
1810
|
method: "POST",
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
paywallId: this.paywallId,
|
|
1775
|
-
cancellationReason: t.reason
|
|
1776
|
-
}),
|
|
1811
|
+
headers: s,
|
|
1812
|
+
body: JSON.stringify(a),
|
|
1777
1813
|
signal: t.signal
|
|
1778
1814
|
});
|
|
1779
1815
|
}
|
|
@@ -1809,7 +1845,7 @@ class St {
|
|
|
1809
1845
|
function O(i) {
|
|
1810
1846
|
return { email: i.email, userId: i.id };
|
|
1811
1847
|
}
|
|
1812
|
-
function
|
|
1848
|
+
function ut(i, t) {
|
|
1813
1849
|
return i === t ? !0 : !i || !t ? !1 : i.email === t.email && i.userId === t.userId && i.anonymousId === t.anonymousId;
|
|
1814
1850
|
}
|
|
1815
1851
|
function U(i) {
|
|
@@ -1845,7 +1881,7 @@ function E(i, t) {
|
|
|
1845
1881
|
]
|
|
1846
1882
|
};
|
|
1847
1883
|
}
|
|
1848
|
-
function
|
|
1884
|
+
function M(i) {
|
|
1849
1885
|
const t = i.locales;
|
|
1850
1886
|
if (!t) return null;
|
|
1851
1887
|
const e = [];
|
|
@@ -1861,7 +1897,7 @@ function q(i) {
|
|
|
1861
1897
|
return null;
|
|
1862
1898
|
}
|
|
1863
1899
|
function w(i) {
|
|
1864
|
-
const t =
|
|
1900
|
+
const t = M(i);
|
|
1865
1901
|
if (!t) return;
|
|
1866
1902
|
const e = i.locales?.[t];
|
|
1867
1903
|
e && (e.layout && (i.layout = e.layout), e.prices && (i.prices = i.prices.map((s) => {
|
|
@@ -1872,7 +1908,7 @@ function w(i) {
|
|
|
1872
1908
|
})));
|
|
1873
1909
|
}
|
|
1874
1910
|
const yt = 1500, pt = 20, L = 200;
|
|
1875
|
-
class
|
|
1911
|
+
class St {
|
|
1876
1912
|
constructor(t) {
|
|
1877
1913
|
this.buffer = [], this.flushTimer = null, this.destroyed = !1, this.unloadHandler = null, this.visibilityHandler = null, this.opts = t, this.isEnabled() && this.attachUnloadHandlers();
|
|
1878
1914
|
}
|
|
@@ -1971,13 +2007,13 @@ class It {
|
|
|
1971
2007
|
}
|
|
1972
2008
|
}
|
|
1973
2009
|
const C = 3600 * 1e3;
|
|
1974
|
-
function
|
|
2010
|
+
function v(i) {
|
|
1975
2011
|
return `paywall-${i}-trial-time-first-open`;
|
|
1976
2012
|
}
|
|
1977
|
-
function
|
|
2013
|
+
function b(i) {
|
|
1978
2014
|
return `paywall-${i}-skip-times`;
|
|
1979
2015
|
}
|
|
1980
|
-
class
|
|
2016
|
+
class q {
|
|
1981
2017
|
constructor(t, e, s) {
|
|
1982
2018
|
this.storage = t, this.paywallId = e, this.config = s;
|
|
1983
2019
|
}
|
|
@@ -1988,10 +2024,10 @@ class K {
|
|
|
1988
2024
|
return this.config.mode === "time" ? this.recordTime() : this.recordOpens();
|
|
1989
2025
|
}
|
|
1990
2026
|
async reset() {
|
|
1991
|
-
await this.storage.removeItem(this.config.mode === "time" ?
|
|
2027
|
+
await this.storage.removeItem(this.config.mode === "time" ? v(this.paywallId) : b(this.paywallId));
|
|
1992
2028
|
}
|
|
1993
2029
|
async checkTime() {
|
|
1994
|
-
const t = this.config.payload * C, e = await this.storage.getItem(
|
|
2030
|
+
const t = this.config.payload * C, e = await this.storage.getItem(v(this.paywallId)), s = e ? Number(e) : null;
|
|
1995
2031
|
if (!s || !Number.isFinite(s))
|
|
1996
2032
|
return {
|
|
1997
2033
|
mode: "time",
|
|
@@ -2012,7 +2048,7 @@ class K {
|
|
|
2012
2048
|
};
|
|
2013
2049
|
}
|
|
2014
2050
|
async checkOpens() {
|
|
2015
|
-
const t = this.config.payload, e = await this.storage.getItem(
|
|
2051
|
+
const t = this.config.payload, e = await this.storage.getItem(b(this.paywallId)), s = e ? Number(e) : 0, a = Number.isFinite(s) ? s : 0, n = a < t, r = Math.max(0, t - a);
|
|
2016
2052
|
return {
|
|
2017
2053
|
mode: "opens",
|
|
2018
2054
|
blocked: n,
|
|
@@ -2021,7 +2057,7 @@ class K {
|
|
|
2021
2057
|
};
|
|
2022
2058
|
}
|
|
2023
2059
|
async recordTime() {
|
|
2024
|
-
const t = this.config.payload * C, e =
|
|
2060
|
+
const t = this.config.payload * C, e = v(this.paywallId), s = await this.storage.getItem(e);
|
|
2025
2061
|
let a = s ? Number(s) : null;
|
|
2026
2062
|
(!a || !Number.isFinite(a)) && (a = Date.now(), await this.storage.setItem(e, String(a)));
|
|
2027
2063
|
const n = a + t, r = Math.max(0, n - Date.now());
|
|
@@ -2035,13 +2071,13 @@ class K {
|
|
|
2035
2071
|
};
|
|
2036
2072
|
}
|
|
2037
2073
|
async recordOpens() {
|
|
2038
|
-
const t = this.config.payload, e =
|
|
2074
|
+
const t = this.config.payload, e = b(this.paywallId), s = await this.storage.getItem(e), a = s ? Number(s) : 0, n = Number.isFinite(a) ? a : 0, r = Math.min(t, n + 1);
|
|
2039
2075
|
await this.storage.setItem(e, String(r));
|
|
2040
|
-
const
|
|
2076
|
+
const h = Math.max(0, t - r);
|
|
2041
2077
|
return {
|
|
2042
2078
|
mode: "opens",
|
|
2043
2079
|
blocked: r < t,
|
|
2044
|
-
remainingActions:
|
|
2080
|
+
remainingActions: h,
|
|
2045
2081
|
totalActions: t
|
|
2046
2082
|
};
|
|
2047
2083
|
}
|
|
@@ -2051,7 +2087,7 @@ class gt {
|
|
|
2051
2087
|
constructor(t, e, s) {
|
|
2052
2088
|
N || (N = !0, console.warn(
|
|
2053
2089
|
'[paywall] trial.storage="server" is not implemented yet — falling back to client storage. State lives in localStorage; users can reset trial by clearing site data.'
|
|
2054
|
-
)), this.fallback = new
|
|
2090
|
+
)), this.fallback = new q(t, e, s);
|
|
2055
2091
|
}
|
|
2056
2092
|
check() {
|
|
2057
2093
|
return this.fallback.check();
|
|
@@ -2064,7 +2100,7 @@ class gt {
|
|
|
2064
2100
|
}
|
|
2065
2101
|
}
|
|
2066
2102
|
function vt(i, t, e) {
|
|
2067
|
-
return e.storage === "server" ? new gt(i, t, e) : new
|
|
2103
|
+
return e.storage === "server" ? new gt(i, t, e) : new q(i, t, e);
|
|
2068
2104
|
}
|
|
2069
2105
|
const bt = 1;
|
|
2070
2106
|
function _t(i) {
|
|
@@ -2096,7 +2132,7 @@ function Bt(i) {
|
|
|
2096
2132
|
function wt(i) {
|
|
2097
2133
|
let t = !1;
|
|
2098
2134
|
const e = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), a = (r) => {
|
|
2099
|
-
for (const
|
|
2135
|
+
for (const h of e) h(r);
|
|
2100
2136
|
}, n = () => {
|
|
2101
2137
|
if (!t) {
|
|
2102
2138
|
t = !0;
|
|
@@ -2109,8 +2145,8 @@ function wt(i) {
|
|
|
2109
2145
|
if (!t)
|
|
2110
2146
|
try {
|
|
2111
2147
|
i.postMessage(r);
|
|
2112
|
-
} catch (
|
|
2113
|
-
throw n(),
|
|
2148
|
+
} catch (h) {
|
|
2149
|
+
throw n(), h;
|
|
2114
2150
|
}
|
|
2115
2151
|
},
|
|
2116
2152
|
onMessage(r) {
|
|
@@ -2131,8 +2167,8 @@ function kt(i) {
|
|
|
2131
2167
|
}
|
|
2132
2168
|
export {
|
|
2133
2169
|
mt as A,
|
|
2134
|
-
|
|
2135
|
-
|
|
2170
|
+
It as B,
|
|
2171
|
+
St as E,
|
|
2136
2172
|
o as P,
|
|
2137
2173
|
bt as a,
|
|
2138
2174
|
kt as b,
|
|
@@ -2142,4 +2178,4 @@ export {
|
|
|
2142
2178
|
_t as s,
|
|
2143
2179
|
Z as w
|
|
2144
2180
|
};
|
|
2145
|
-
//# sourceMappingURL=chrome-port-
|
|
2181
|
+
//# sourceMappingURL=chrome-port-bfTUUDz_.js.map
|