@monetize.software/sdk-extension 3.0.0-alpha.15 → 3.0.0-alpha.16
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-Dl-cLIZy.js} +2 -2
- package/dist/chunks/{chrome-port-BXK5myXz.js.map → chrome-port-Dl-cLIZy.js.map} +1 -1
- package/dist/chunks/{chrome-port-KYVwww_u.js → chrome-port-bqs4PVlp.js} +35 -34
- package/dist/chunks/{chrome-port-KYVwww_u.js.map → chrome-port-bqs4PVlp.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
|
@@ -22,9 +22,9 @@ 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 u;
|
|
26
26
|
try {
|
|
27
|
-
|
|
27
|
+
u = await a(s, {
|
|
28
28
|
...e,
|
|
29
29
|
headers: n,
|
|
30
30
|
credentials: "omit"
|
|
@@ -32,10 +32,10 @@ class K {
|
|
|
32
32
|
} catch (l) {
|
|
33
33
|
throw (l && typeof l == "object" && "name" in l ? l.name : void 0) === "AbortError" ? new o("aborted", "Request aborted", { cause: l }) : new o("network_error", "Network request failed", { cause: l });
|
|
34
34
|
}
|
|
35
|
-
const y = (
|
|
36
|
-
if (!
|
|
37
|
-
const l = y && typeof y == "object" && "code" in y && String(y.code) || `http_${
|
|
38
|
-
throw new o(l, g, { status:
|
|
35
|
+
const y = (u.headers.get("content-type") ?? "").includes("application/json") ? await u.json().catch(() => null) : null;
|
|
36
|
+
if (!u.ok) {
|
|
37
|
+
const l = 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 o(l, g, { status: u.status, cause: y });
|
|
39
39
|
}
|
|
40
40
|
return y;
|
|
41
41
|
}
|
|
@@ -115,7 +115,7 @@ const H = {
|
|
|
115
115
|
function P(i) {
|
|
116
116
|
return i || (x() ? H : typeof window < "u" && "localStorage" in window ? J : V);
|
|
117
117
|
}
|
|
118
|
-
const
|
|
118
|
+
const d = {
|
|
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(d.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(d.visitorId, t);
|
|
169
169
|
} catch {
|
|
170
170
|
}
|
|
171
171
|
return t;
|
|
@@ -828,7 +828,7 @@ class mt {
|
|
|
828
828
|
}
|
|
829
829
|
}
|
|
830
830
|
storageKey() {
|
|
831
|
-
return
|
|
831
|
+
return d.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(d.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
|
+
d.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
|
+
d.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(d.lastLoginMethod(this.paywallId)),
|
|
917
|
+
this.storage.getItem(d.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(d.lastLoginMethod(this.paywallId), t).catch(() => {
|
|
932
932
|
});
|
|
933
933
|
}
|
|
934
934
|
recordLastLoginEmail(t) {
|
|
935
|
-
this.storage.setItem(
|
|
935
|
+
this.storage.setItem(d.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(d.visitorId);
|
|
948
948
|
return typeof t == "string" && t.length >= 16 ? t : void 0;
|
|
949
949
|
} catch {
|
|
950
950
|
return;
|
|
@@ -956,7 +956,7 @@ 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(
|
|
959
|
+
a = !0, window.removeEventListener("message", r), clearInterval(h), clearTimeout(u);
|
|
960
960
|
}, r = (f) => {
|
|
961
961
|
if (a) return;
|
|
962
962
|
const c = f.data;
|
|
@@ -991,7 +991,7 @@ function Z(i, t) {
|
|
|
991
991
|
return;
|
|
992
992
|
}
|
|
993
993
|
f && (n(), s(new o("oauth_cancelled", "auth popup was closed")));
|
|
994
|
-
}, Y),
|
|
994
|
+
}, Y), u = setTimeout(() => {
|
|
995
995
|
if (!a) {
|
|
996
996
|
n();
|
|
997
997
|
try {
|
|
@@ -1033,9 +1033,9 @@ 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,
|
|
1036
|
+
const r = typeof FormData < "u" && t.body instanceof FormData, h = typeof Blob < "u" && t.body instanceof Blob, u = typeof ReadableStream < "u" && t.body instanceof ReadableStream, f = typeof t.body == "string";
|
|
1037
1037
|
let c;
|
|
1038
|
-
t.body === void 0 || t.body === null ? c = void 0 : r || h ||
|
|
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
1039
|
const y = this.customFetch ?? fetch;
|
|
1040
1040
|
let l;
|
|
1041
1041
|
try {
|
|
@@ -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++)
|
|
@@ -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
|
/**
|
|
@@ -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(d.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
|
+
d.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
|
+
d.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 d.userState(this.paywallId, A(this.identity));
|
|
1464
1464
|
}
|
|
1465
1465
|
async hydrateUserFromStorage() {
|
|
1466
1466
|
if (!this.cachedUser)
|
|
@@ -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 {
|
|
@@ -1615,7 +1615,7 @@ class It {
|
|
|
1615
1615
|
}
|
|
1616
1616
|
}
|
|
1617
1617
|
balancesStorageKey() {
|
|
1618
|
-
return
|
|
1618
|
+
return d.balances(this.paywallId, A(this.identity));
|
|
1619
1619
|
}
|
|
1620
1620
|
async hydrateBalancesFromStorage() {
|
|
1621
1621
|
if (!this.cachedBalances)
|
|
@@ -1672,16 +1672,17 @@ 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, u = t.shopUrl ?? r?.checkout_shop_url ?? void 0, f = this.api.request(`/api/v1/paywall/${this.paywallId}/start-checkout`, {
|
|
1676
1676
|
method: "POST",
|
|
1677
1677
|
headers: n,
|
|
1678
1678
|
signal: t.signal,
|
|
1679
1679
|
body: JSON.stringify({
|
|
1680
1680
|
email: this.identity.email,
|
|
1681
1681
|
priceId: Number(t.priceId),
|
|
1682
|
+
offerId: t.offerId,
|
|
1682
1683
|
successUrl: h,
|
|
1683
1684
|
errorUrl: t.errorUrl,
|
|
1684
|
-
shopUrl:
|
|
1685
|
+
shopUrl: u,
|
|
1685
1686
|
productName: r?.checkout_product_name ?? void 0,
|
|
1686
1687
|
trial_days: t.trialDays,
|
|
1687
1688
|
ignoreActivePurchase: t.ignoreActivePurchase ? !0 : void 0,
|
|
@@ -1838,7 +1839,7 @@ class It {
|
|
|
1838
1839
|
function O(i) {
|
|
1839
1840
|
return { email: i.email, userId: i.id };
|
|
1840
1841
|
}
|
|
1841
|
-
function
|
|
1842
|
+
function ut(i, t) {
|
|
1842
1843
|
return i === t ? !0 : !i || !t ? !1 : i.email === t.email && i.userId === t.userId && i.anonymousId === t.anonymousId;
|
|
1843
1844
|
}
|
|
1844
1845
|
function U(i) {
|
|
@@ -2171,4 +2172,4 @@ export {
|
|
|
2171
2172
|
_t as s,
|
|
2172
2173
|
Z as w
|
|
2173
2174
|
};
|
|
2174
|
-
//# sourceMappingURL=chrome-port-
|
|
2175
|
+
//# sourceMappingURL=chrome-port-bqs4PVlp.js.map
|