@monetize.software/sdk-extension 3.0.0-alpha.16 → 3.0.0-alpha.18
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-Dl-cLIZy.js → chrome-port-CG8LYcKe.js} +2 -2
- package/dist/chunks/{chrome-port-Dl-cLIZy.js.map → chrome-port-CG8LYcKe.js.map} +1 -1
- package/dist/chunks/{chrome-port-bqs4PVlp.js → chrome-port-DKsnkWLb.js} +71 -68
- package/dist/chunks/{chrome-port-bqs4PVlp.js.map → chrome-port-DKsnkWLb.js.map} +1 -1
- package/dist/content.cjs +2 -2
- package/dist/content.cjs.map +1 -1
- package/dist/content.js +57 -15
- 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,10 +112,10 @@ 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
|
-
const
|
|
118
|
+
const u = {
|
|
119
119
|
visitorId: "pw-visitor-id",
|
|
120
120
|
lastLoginMethod: (i) => `pw-${i}-last-login-method`,
|
|
121
121
|
lastLoginEmail: (i) => `pw-${i}-last-login-email`,
|
|
@@ -159,13 +159,13 @@ function R() {
|
|
|
159
159
|
}
|
|
160
160
|
async function B(i) {
|
|
161
161
|
try {
|
|
162
|
-
const e = await i.getItem(
|
|
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
166
|
const t = R();
|
|
167
167
|
try {
|
|
168
|
-
await i.setItem(
|
|
168
|
+
await i.setItem(u.visitorId, t);
|
|
169
169
|
} catch {
|
|
170
170
|
}
|
|
171
171
|
return t;
|
|
@@ -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
|
|
@@ -828,7 +828,7 @@ class mt {
|
|
|
828
828
|
}
|
|
829
829
|
}
|
|
830
830
|
storageKey() {
|
|
831
|
-
return
|
|
831
|
+
return u.authSession(this.paywallId);
|
|
832
832
|
}
|
|
833
833
|
async hydrate() {
|
|
834
834
|
try {
|
|
@@ -882,7 +882,7 @@ class mt {
|
|
|
882
882
|
}
|
|
883
883
|
async readAnonRefreshToken() {
|
|
884
884
|
try {
|
|
885
|
-
const t = await this.storage.getItem(
|
|
885
|
+
const t = await this.storage.getItem(u.anonRefreshToken(this.paywallId));
|
|
886
886
|
return typeof t == "string" && t.length > 0 ? t : null;
|
|
887
887
|
} catch {
|
|
888
888
|
return null;
|
|
@@ -891,7 +891,7 @@ class mt {
|
|
|
891
891
|
async writeAnonRefreshToken(t) {
|
|
892
892
|
try {
|
|
893
893
|
await this.storage.setItem(
|
|
894
|
-
|
|
894
|
+
u.anonRefreshToken(this.paywallId),
|
|
895
895
|
t
|
|
896
896
|
);
|
|
897
897
|
} catch {
|
|
@@ -900,7 +900,7 @@ class mt {
|
|
|
900
900
|
async clearAnonRefreshToken() {
|
|
901
901
|
try {
|
|
902
902
|
await this.storage.removeItem(
|
|
903
|
-
|
|
903
|
+
u.anonRefreshToken(this.paywallId)
|
|
904
904
|
);
|
|
905
905
|
} catch {
|
|
906
906
|
}
|
|
@@ -913,8 +913,8 @@ class mt {
|
|
|
913
913
|
async getLastLogin() {
|
|
914
914
|
try {
|
|
915
915
|
const [t, e] = await Promise.all([
|
|
916
|
-
this.storage.getItem(
|
|
917
|
-
this.storage.getItem(
|
|
916
|
+
this.storage.getItem(u.lastLoginMethod(this.paywallId)),
|
|
917
|
+
this.storage.getItem(u.lastLoginEmail(this.paywallId))
|
|
918
918
|
]);
|
|
919
919
|
return !t || !tt(t) ? null : { method: t, email: typeof e == "string" && e ? e : null };
|
|
920
920
|
} catch {
|
|
@@ -928,11 +928,11 @@ class mt {
|
|
|
928
928
|
this.recordLastLoginMethod(t), e && this.recordLastLoginEmail(e);
|
|
929
929
|
}
|
|
930
930
|
recordLastLoginMethod(t) {
|
|
931
|
-
this.storage.setItem(
|
|
931
|
+
this.storage.setItem(u.lastLoginMethod(this.paywallId), t).catch(() => {
|
|
932
932
|
});
|
|
933
933
|
}
|
|
934
934
|
recordLastLoginEmail(t) {
|
|
935
|
-
this.storage.setItem(
|
|
935
|
+
this.storage.setItem(u.lastLoginEmail(this.paywallId), t).catch(() => {
|
|
936
936
|
});
|
|
937
937
|
}
|
|
938
938
|
/**
|
|
@@ -944,7 +944,7 @@ class mt {
|
|
|
944
944
|
*/
|
|
945
945
|
async readVisitorId() {
|
|
946
946
|
try {
|
|
947
|
-
const t = await this.storage.getItem(
|
|
947
|
+
const t = await this.storage.getItem(u.visitorId);
|
|
948
948
|
return typeof t == "string" && t.length >= 16 ? t : void 0;
|
|
949
949
|
} catch {
|
|
950
950
|
return;
|
|
@@ -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 || u || 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) {
|
|
@@ -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,
|
|
@@ -1284,7 +1284,7 @@ class It {
|
|
|
1284
1284
|
async hydrateBootstrapFromStorage() {
|
|
1285
1285
|
if (!this.cachedBootstrap)
|
|
1286
1286
|
try {
|
|
1287
|
-
const t = await this.storage.getItem(
|
|
1287
|
+
const t = await this.storage.getItem(u.bootstrap(this.paywallId));
|
|
1288
1288
|
if (!t) return;
|
|
1289
1289
|
const e = JSON.parse(t);
|
|
1290
1290
|
if (!e?.bootstrap || Date.now() - e.at > k || this.cachedBootstrap) return;
|
|
@@ -1303,7 +1303,7 @@ class It {
|
|
|
1303
1303
|
try {
|
|
1304
1304
|
const { user: e, ...s } = t;
|
|
1305
1305
|
await this.storage.setItem(
|
|
1306
|
-
|
|
1306
|
+
u.bootstrap(this.paywallId),
|
|
1307
1307
|
JSON.stringify({ at: Date.now(), bootstrap: s })
|
|
1308
1308
|
);
|
|
1309
1309
|
} catch {
|
|
@@ -1314,7 +1314,7 @@ class It {
|
|
|
1314
1314
|
// no-op, всё работает как раньше через сеть.
|
|
1315
1315
|
subscribeBootstrapStorage() {
|
|
1316
1316
|
typeof this.storage.watch == "function" && (this.bootstrapStorageUnwatch = this.storage.watch(
|
|
1317
|
-
|
|
1317
|
+
u.bootstrap(this.paywallId),
|
|
1318
1318
|
(t) => {
|
|
1319
1319
|
if (t)
|
|
1320
1320
|
try {
|
|
@@ -1460,7 +1460,7 @@ class It {
|
|
|
1460
1460
|
}
|
|
1461
1461
|
}
|
|
1462
1462
|
storageKey() {
|
|
1463
|
-
return
|
|
1463
|
+
return u.userState(this.paywallId, A(this.identity));
|
|
1464
1464
|
}
|
|
1465
1465
|
async hydrateUserFromStorage() {
|
|
1466
1466
|
if (!this.cachedUser)
|
|
@@ -1615,7 +1615,7 @@ class It {
|
|
|
1615
1615
|
}
|
|
1616
1616
|
}
|
|
1617
1617
|
balancesStorageKey() {
|
|
1618
|
-
return
|
|
1618
|
+
return u.balances(this.paywallId, A(this.identity));
|
|
1619
1619
|
}
|
|
1620
1620
|
async hydrateBalancesFromStorage() {
|
|
1621
1621
|
if (!this.cachedBalances)
|
|
@@ -1672,7 +1672,9 @@ 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,
|
|
@@ -1682,11 +1684,12 @@ class It {
|
|
|
1682
1684
|
offerId: t.offerId,
|
|
1683
1685
|
successUrl: h,
|
|
1684
1686
|
errorUrl: t.errorUrl,
|
|
1685
|
-
shopUrl:
|
|
1687
|
+
shopUrl: f,
|
|
1686
1688
|
productName: r?.checkout_product_name ?? void 0,
|
|
1687
1689
|
trial_days: t.trialDays,
|
|
1688
1690
|
ignoreActivePurchase: t.ignoreActivePurchase ? !0 : void 0,
|
|
1689
|
-
userMeta: this.identity.userId ? { userId: this.identity.userId } : void 0
|
|
1691
|
+
userMeta: this.identity.userId ? { userId: this.identity.userId } : void 0,
|
|
1692
|
+
localCurrency: l
|
|
1690
1693
|
})
|
|
1691
1694
|
}).then((c) => ({ url: c.checkoutUrl, acquiring: c.acquiring })).catch((c) => {
|
|
1692
1695
|
throw c instanceof o && c.status === 409 && c.cause && typeof c.cause == "object" && c.cause.hasActivePurchase === !0 ? new o(
|
|
@@ -1695,10 +1698,10 @@ class It {
|
|
|
1695
1698
|
{ status: 409, cause: c.cause }
|
|
1696
1699
|
) : c;
|
|
1697
1700
|
});
|
|
1698
|
-
return this.inflightCheckouts.set(e,
|
|
1699
|
-
this.inflightCheckouts.get(e) ===
|
|
1701
|
+
return this.inflightCheckouts.set(e, d), d.finally(() => {
|
|
1702
|
+
this.inflightCheckouts.get(e) === d && this.inflightCheckouts.delete(e);
|
|
1700
1703
|
}).catch(() => {
|
|
1701
|
-
}),
|
|
1704
|
+
}), d;
|
|
1702
1705
|
}
|
|
1703
1706
|
/**
|
|
1704
1707
|
* URL Stripe/Paddle/Chargebee customer portal — место, где залогиненный
|
|
@@ -2172,4 +2175,4 @@ export {
|
|
|
2172
2175
|
_t as s,
|
|
2173
2176
|
Z as w
|
|
2174
2177
|
};
|
|
2175
|
-
//# sourceMappingURL=chrome-port-
|
|
2178
|
+
//# sourceMappingURL=chrome-port-DKsnkWLb.js.map
|