@monetize.software/sdk-extension 3.0.0-alpha.15 → 3.0.0-alpha.17
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/{chrome-port-BXK5myXz.js → chrome-port-CG8LYcKe.js} +2 -2
- package/dist/chunks/{chrome-port-BXK5myXz.js.map → chrome-port-CG8LYcKe.js.map} +1 -1
- package/dist/chunks/{chrome-port-KYVwww_u.js → chrome-port-DKsnkWLb.js} +59 -55
- package/dist/chunks/{chrome-port-KYVwww_u.js.map → chrome-port-DKsnkWLb.js.map} +1 -1
- package/dist/content.cjs +3 -3
- package/dist/content.cjs.map +1 -1
- package/dist/content.js +790 -626
- package/dist/content.js.map +1 -1
- package/dist/offscreen.cjs +1 -1
- package/dist/offscreen.js +1 -1
- package/package.json +3 -3
|
@@ -11,7 +11,7 @@ class F extends o {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
const m = "3.0.0-alpha.0";
|
|
14
|
-
class
|
|
14
|
+
class P {
|
|
15
15
|
constructor(t) {
|
|
16
16
|
this.opts = t;
|
|
17
17
|
}
|
|
@@ -22,22 +22,22 @@ class K {
|
|
|
22
22
|
r && n.set("Authorization", `Bearer ${r}`);
|
|
23
23
|
const h = typeof FormData < "u" && e.body instanceof FormData;
|
|
24
24
|
e.body && !n.has("Content-Type") && !h && n.set("Content-Type", "application/json");
|
|
25
|
-
let
|
|
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() {
|
|
@@ -112,7 +112,7 @@ const H = {
|
|
|
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 = {
|
|
@@ -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
|
|
@@ -956,19 +956,19 @@ function Z(i, t) {
|
|
|
956
956
|
return new Promise((e, s) => {
|
|
957
957
|
let a = !1;
|
|
958
958
|
const n = () => {
|
|
959
|
-
a = !0, window.removeEventListener("message", r), clearInterval(h), clearTimeout(
|
|
960
|
-
}, r = (
|
|
959
|
+
a = !0, window.removeEventListener("message", r), clearInterval(h), clearTimeout(f);
|
|
960
|
+
}, r = (p) => {
|
|
961
961
|
if (a) return;
|
|
962
|
-
const
|
|
963
|
-
if (!(!
|
|
964
|
-
if (
|
|
962
|
+
const l = p.data;
|
|
963
|
+
if (!(!l || l.type !== "pw-oauth") && l.messageId === t) {
|
|
964
|
+
if (l.status === "success" && l.code) {
|
|
965
965
|
n();
|
|
966
966
|
try {
|
|
967
967
|
i.close();
|
|
968
968
|
} catch {
|
|
969
969
|
}
|
|
970
|
-
e(
|
|
971
|
-
} else if (
|
|
970
|
+
e(l.code);
|
|
971
|
+
} else if (l.status === "error") {
|
|
972
972
|
n();
|
|
973
973
|
try {
|
|
974
974
|
i.close();
|
|
@@ -977,21 +977,21 @@ function Z(i, t) {
|
|
|
977
977
|
s(
|
|
978
978
|
new o(
|
|
979
979
|
"oauth_failed",
|
|
980
|
-
|
|
980
|
+
l.description || l.error || "OAuth provider returned error"
|
|
981
981
|
)
|
|
982
982
|
);
|
|
983
983
|
}
|
|
984
984
|
}
|
|
985
985
|
}, h = setInterval(() => {
|
|
986
986
|
if (a) return;
|
|
987
|
-
let
|
|
987
|
+
let p;
|
|
988
988
|
try {
|
|
989
|
-
|
|
989
|
+
p = i.closed;
|
|
990
990
|
} catch {
|
|
991
991
|
return;
|
|
992
992
|
}
|
|
993
|
-
|
|
994
|
-
}, Y),
|
|
993
|
+
p && (n(), s(new o("oauth_cancelled", "auth popup was closed")));
|
|
994
|
+
}, Y), f = setTimeout(() => {
|
|
995
995
|
if (!a) {
|
|
996
996
|
n();
|
|
997
997
|
try {
|
|
@@ -1033,37 +1033,37 @@ class st {
|
|
|
1033
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(","));
|
|
1034
1034
|
const n = await this.auth?.getAccessToken();
|
|
1035
1035
|
n ? a.set("Authorization", `Bearer ${n}`) : this.userId && a.set("X-User-ID", this.userId);
|
|
1036
|
-
const r = typeof FormData < "u" && t.body instanceof FormData, h = typeof Blob < "u" && t.body instanceof Blob,
|
|
1037
|
-
let c;
|
|
1038
|
-
t.body === void 0 || t.body === null ? c = void 0 : r || h || d || f ? c = t.body : (c = JSON.stringify(t.body), a.has("Content-Type") || a.set("Content-Type", "application/json"));
|
|
1039
|
-
const y = this.customFetch ?? fetch;
|
|
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";
|
|
1040
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;
|
|
1040
|
+
let c;
|
|
1041
1041
|
try {
|
|
1042
|
-
|
|
1042
|
+
c = await d(s.toString(), {
|
|
1043
1043
|
method: t.method ?? "POST",
|
|
1044
1044
|
headers: a,
|
|
1045
|
-
body:
|
|
1045
|
+
body: l,
|
|
1046
1046
|
signal: t.signal,
|
|
1047
1047
|
credentials: "omit"
|
|
1048
1048
|
});
|
|
1049
|
-
} catch (
|
|
1050
|
-
const $ =
|
|
1051
|
-
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 });
|
|
1052
1052
|
}
|
|
1053
|
-
if (
|
|
1054
|
-
const
|
|
1055
|
-
throw this.onQuotaExceeded?.(
|
|
1053
|
+
if (c.status === 402) {
|
|
1054
|
+
const y = await it(c);
|
|
1055
|
+
throw this.onQuotaExceeded?.(y), y;
|
|
1056
1056
|
}
|
|
1057
|
-
if (!
|
|
1058
|
-
const
|
|
1057
|
+
if (!c.ok) {
|
|
1058
|
+
const y = await at(c.clone());
|
|
1059
1059
|
throw new o(
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
{ status:
|
|
1060
|
+
y ?? `http_${c.status}`,
|
|
1061
|
+
c.statusText || "Gateway request failed",
|
|
1062
|
+
{ status: c.status }
|
|
1063
1063
|
);
|
|
1064
1064
|
}
|
|
1065
|
-
const g =
|
|
1066
|
-
return this.onChargeSuccess?.(g),
|
|
1065
|
+
const g = c.headers.get("X-Query-Type") ?? void 0;
|
|
1066
|
+
return this.onChargeSuccess?.(g), c;
|
|
1067
1067
|
}
|
|
1068
1068
|
}
|
|
1069
1069
|
async function it(i) {
|
|
@@ -1106,7 +1106,7 @@ function ct(i, t) {
|
|
|
1106
1106
|
return i === t ? !0 : !i || !t ? !1 : JSON.stringify(i) === JSON.stringify(t);
|
|
1107
1107
|
}
|
|
1108
1108
|
const ht = 5e3, T = 5 * 6e4, lt = 3e4;
|
|
1109
|
-
function
|
|
1109
|
+
function dt(i, t) {
|
|
1110
1110
|
if (i === t) return !0;
|
|
1111
1111
|
if (!i || !t || i.length !== t.length) return !1;
|
|
1112
1112
|
for (let e = 0; e < i.length; e++)
|
|
@@ -1126,7 +1126,7 @@ class It {
|
|
|
1126
1126
|
const e = t.auth?.getCachedUser();
|
|
1127
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(
|
|
1128
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."
|
|
1129
|
-
), this.storage =
|
|
1129
|
+
), this.storage = K(t.storage), this.api = new P({
|
|
1130
1130
|
apiOrigin: this.apiOrigin,
|
|
1131
1131
|
paywallId: t.paywallId,
|
|
1132
1132
|
capabilities: t.capabilities,
|
|
@@ -1137,7 +1137,7 @@ class It {
|
|
|
1137
1137
|
getAuthToken: t.auth ? () => t.auth.getAccessToken() : void 0
|
|
1138
1138
|
}), t.auth && (this.authUnsubscribe = t.auth.onAuthChange((s, a) => {
|
|
1139
1139
|
const n = a ? O(a.user) : void 0;
|
|
1140
|
-
|
|
1140
|
+
ut(this.identity, n) || this.setIdentity(n);
|
|
1141
1141
|
})), this.hydrateUserFromStorage(), this.hydrateBootstrapFromStorage(), this.subscribeBootstrapStorage(), this.hydrateBalancesFromStorage(), this.subscribeBalancesStorage(), this.visitorIdPromise = B(this.storage).then((s) => (this.visitorId = s, s));
|
|
1142
1142
|
}
|
|
1143
1143
|
/**
|
|
@@ -1605,7 +1605,7 @@ class It {
|
|
|
1605
1605
|
});
|
|
1606
1606
|
}
|
|
1607
1607
|
applyBalances(t, { persist: e = !0 } = {}) {
|
|
1608
|
-
const s = !
|
|
1608
|
+
const s = !dt(this.cachedBalances, t);
|
|
1609
1609
|
if (this.cachedBalances = t, this.cachedBalancesAt = Date.now(), e && this.persistBalances(t), s)
|
|
1610
1610
|
for (const a of this.balanceListeners)
|
|
1611
1611
|
try {
|
|
@@ -1672,20 +1672,24 @@ class It {
|
|
|
1672
1672
|
"Idempotency-Key": t.idempotencyKey ?? R()
|
|
1673
1673
|
};
|
|
1674
1674
|
this.apiKey && (n["X-Api-Key"] = this.apiKey);
|
|
1675
|
-
const r = this.cachedBootstrap?.settings, h = t.successUrl ?? r?.success_redirect_url ?? void 0,
|
|
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`, {
|
|
1676
1678
|
method: "POST",
|
|
1677
1679
|
headers: n,
|
|
1678
1680
|
signal: t.signal,
|
|
1679
1681
|
body: JSON.stringify({
|
|
1680
1682
|
email: this.identity.email,
|
|
1681
1683
|
priceId: Number(t.priceId),
|
|
1684
|
+
offerId: t.offerId,
|
|
1682
1685
|
successUrl: h,
|
|
1683
1686
|
errorUrl: t.errorUrl,
|
|
1684
|
-
shopUrl:
|
|
1687
|
+
shopUrl: f,
|
|
1685
1688
|
productName: r?.checkout_product_name ?? void 0,
|
|
1686
1689
|
trial_days: t.trialDays,
|
|
1687
1690
|
ignoreActivePurchase: t.ignoreActivePurchase ? !0 : void 0,
|
|
1688
|
-
userMeta: this.identity.userId ? { userId: this.identity.userId } : void 0
|
|
1691
|
+
userMeta: this.identity.userId ? { userId: this.identity.userId } : void 0,
|
|
1692
|
+
localCurrency: l
|
|
1689
1693
|
})
|
|
1690
1694
|
}).then((c) => ({ url: c.checkoutUrl, acquiring: c.acquiring })).catch((c) => {
|
|
1691
1695
|
throw c instanceof o && c.status === 409 && c.cause && typeof c.cause == "object" && c.cause.hasActivePurchase === !0 ? new o(
|
|
@@ -1694,10 +1698,10 @@ class It {
|
|
|
1694
1698
|
{ status: 409, cause: c.cause }
|
|
1695
1699
|
) : c;
|
|
1696
1700
|
});
|
|
1697
|
-
return this.inflightCheckouts.set(e,
|
|
1698
|
-
this.inflightCheckouts.get(e) ===
|
|
1701
|
+
return this.inflightCheckouts.set(e, d), d.finally(() => {
|
|
1702
|
+
this.inflightCheckouts.get(e) === d && this.inflightCheckouts.delete(e);
|
|
1699
1703
|
}).catch(() => {
|
|
1700
|
-
}),
|
|
1704
|
+
}), d;
|
|
1701
1705
|
}
|
|
1702
1706
|
/**
|
|
1703
1707
|
* URL Stripe/Paddle/Chargebee customer portal — место, где залогиненный
|
|
@@ -1838,7 +1842,7 @@ class It {
|
|
|
1838
1842
|
function O(i) {
|
|
1839
1843
|
return { email: i.email, userId: i.id };
|
|
1840
1844
|
}
|
|
1841
|
-
function
|
|
1845
|
+
function ut(i, t) {
|
|
1842
1846
|
return i === t ? !0 : !i || !t ? !1 : i.email === t.email && i.userId === t.userId && i.anonymousId === t.anonymousId;
|
|
1843
1847
|
}
|
|
1844
1848
|
function U(i) {
|
|
@@ -2171,4 +2175,4 @@ export {
|
|
|
2171
2175
|
_t as s,
|
|
2172
2176
|
Z as w
|
|
2173
2177
|
};
|
|
2174
|
-
//# sourceMappingURL=chrome-port-
|
|
2178
|
+
//# sourceMappingURL=chrome-port-DKsnkWLb.js.map
|