@monetize.software/sdk-extension 3.0.0-alpha.4 → 3.0.0-alpha.5

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.
@@ -3,7 +3,7 @@ class o extends Error {
3
3
  super(e), this.name = "PaywallError", this.code = t, this.status = s.status, this.cause = s.cause;
4
4
  }
5
5
  }
6
- class q extends o {
6
+ class F extends o {
7
7
  constructor(t) {
8
8
  super("not_enough_queries", t.message ?? "Not enough queries", {
9
9
  status: 402
@@ -11,7 +11,7 @@ class q extends o {
11
11
  }
12
12
  }
13
13
  const m = "3.0.0-alpha.0";
14
- class L {
14
+ class P {
15
15
  constructor(t) {
16
16
  this.opts = t;
17
17
  }
@@ -34,16 +34,16 @@ class L {
34
34
  }
35
35
  const f = (u.headers.get("content-type") ?? "").includes("application/json") ? await u.json().catch(() => null) : null;
36
36
  if (!u.ok) {
37
- const h = f && typeof f == "object" && "code" in f && String(f.code) || `http_${u.status}`, w = f && typeof f == "object" && "message" in f && String(f.message) || u.statusText || "Request failed";
38
- throw new o(h, w, { status: u.status, cause: f });
37
+ const h = f && typeof f == "object" && "code" in f && String(f.code) || `http_${u.status}`, g = f && typeof f == "object" && "message" in f && String(f.message) || u.statusText || "Request failed";
38
+ throw new o(h, g, { status: u.status, cause: f });
39
39
  }
40
40
  return f;
41
41
  }
42
42
  }
43
- function $() {
43
+ function x() {
44
44
  return typeof chrome < "u" && !!chrome?.storage?.local && !!chrome?.runtime?.id;
45
45
  }
46
- const x = {
46
+ const H = {
47
47
  getItem(i) {
48
48
  return new Promise((t) => {
49
49
  chrome.storage.local.get([i], (e) => {
@@ -73,7 +73,7 @@ const x = {
73
73
  };
74
74
  return e.addListener(s), () => e.removeListener(s);
75
75
  }
76
- }, H = {
76
+ }, J = {
77
77
  async getItem(i) {
78
78
  try {
79
79
  return window.localStorage.getItem(i);
@@ -101,19 +101,19 @@ const x = {
101
101
  };
102
102
  return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
103
103
  }
104
- }, I = /* @__PURE__ */ new Map(), J = {
104
+ }, S = /* @__PURE__ */ new Map(), V = {
105
105
  async getItem(i) {
106
- return I.get(i) ?? null;
106
+ return S.get(i) ?? null;
107
107
  },
108
108
  async setItem(i, t) {
109
- I.set(i, t);
109
+ S.set(i, t);
110
110
  },
111
111
  async removeItem(i) {
112
- I.delete(i);
112
+ S.delete(i);
113
113
  }
114
114
  };
115
115
  function R(i) {
116
- return i || ($() ? x : typeof window < "u" && "localStorage" in window ? H : J);
116
+ return i || (x() ? H : typeof window < "u" && "localStorage" in window ? J : V);
117
117
  }
118
118
  const y = {
119
119
  visitorId: "pw-visitor-id",
@@ -145,7 +145,7 @@ const y = {
145
145
  // (оптимистично через `decrementBalanceLocal`).
146
146
  balances: (i, t) => `pw-${i}-${t}-balances-v1`
147
147
  };
148
- function P() {
148
+ function D() {
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);
@@ -163,14 +163,14 @@ async function _(i) {
163
163
  if (e && typeof e == "string" && e.length >= 16) return e;
164
164
  } catch {
165
165
  }
166
- const t = P();
166
+ const t = D();
167
167
  try {
168
168
  await i.setItem(y.visitorId, t);
169
169
  } catch {
170
170
  }
171
171
  return t;
172
172
  }
173
- function D(i) {
173
+ function q(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,30 +178,35 @@ function D(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 b(i) {
181
+ function I(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
- function V() {
187
- return b(D(64));
186
+ function j() {
187
+ return I(q(64));
188
188
  }
189
- async function j(i) {
189
+ async function G(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 b(new Uint8Array(s));
194
+ return I(new Uint8Array(s));
195
195
  }
196
- function G() {
197
- return b(D(16));
196
+ function X() {
197
+ return I(q(16));
198
198
  }
199
- const X = "https://appbox.space", z = 6e4, Q = 600 * 1e3;
200
- class mt {
199
+ const z = 6e4, Q = 600 * 1e3;
200
+ class wt {
201
201
  constructor(t) {
202
202
  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)
203
203
  throw new o("invalid_config", "paywallId is required");
204
- this.paywallId = t.paywallId, this.apiOrigin = t.apiOrigin ?? X, this.storage = R(t.storage), this.api = new L({
204
+ if (!t.apiOrigin)
205
+ throw new o(
206
+ "invalid_config",
207
+ "apiOrigin is required. Pass the paywall custom_domain configured in the platform."
208
+ );
209
+ this.paywallId = t.paywallId, this.apiOrigin = t.apiOrigin, this.storage = R(t.storage), this.api = new P({
205
210
  apiOrigin: this.apiOrigin,
206
211
  paywallId: t.paywallId,
207
212
  fetch: t.fetch
@@ -618,7 +623,7 @@ class mt {
618
623
  */
619
624
  async startOAuthFlow(t) {
620
625
  await this.hydrated, this.gcOAuthFlows();
621
- const e = V(), s = await j(e), a = G(), n = {}, r = await this.getAccessToken().catch(() => null);
626
+ const e = j(), s = await G(e), a = X(), n = {}, r = await this.getAccessToken().catch(() => null);
622
627
  r && (n.Authorization = `Bearer ${r}`);
623
628
  const { authorize_url: l } = await this.api.request(
624
629
  `/api/v1/paywall/${this.paywallId}/auth/oauth/init`,
@@ -973,12 +978,16 @@ function Z(i, t) {
973
978
  function tt(i, t) {
974
979
  return i === t ? !0 : !i || !t ? !1 : i.access_token === t.access_token && i.refresh_token === t.refresh_token && i.expires_at === t.expires_at && i.user.id === t.user.id && i.user.email === t.user.email;
975
980
  }
976
- const et = "https://appbox.space";
977
- class st {
981
+ class et {
978
982
  constructor(t) {
979
983
  if (!t.paywallId)
980
984
  throw new o("invalid_config", "paywallId is required");
981
- this.paywallId = t.paywallId, this.apiOrigin = t.apiOrigin ?? et, this.auth = t.auth, this.userId = t.userId, this.capabilities = t.capabilities, this.customFetch = t.fetch, this.onChargeSuccess = t.onChargeSuccess, this.onQuotaExceeded = t.onQuotaExceeded, t.userId && !t.auth && typeof window < "u" && typeof window.document < "u" && console.warn(
985
+ if (!t.apiOrigin)
986
+ throw new o(
987
+ "invalid_config",
988
+ "apiOrigin is required. Pass the paywall custom_domain configured in the platform."
989
+ );
990
+ this.paywallId = t.paywallId, this.apiOrigin = t.apiOrigin, this.auth = t.auth, this.userId = t.userId, this.capabilities = t.capabilities, this.customFetch = t.fetch, this.onChargeSuccess = t.onChargeSuccess, this.onQuotaExceeded = t.onQuotaExceeded, t.userId && !t.auth && typeof window < "u" && typeof window.document < "u" && console.warn(
982
991
  "[paywall] WARNING: ApiGatewayClient.userId set without auth in browser. Client can spoof userId. Use AuthClient + Bearer for trusted user.id."
983
992
  );
984
993
  }
@@ -1006,26 +1015,26 @@ class st {
1006
1015
  credentials: "omit"
1007
1016
  });
1008
1017
  } catch (p) {
1009
- const K = p instanceof Error ? p.message : String(p);
1010
- throw new o("network_error", `Network request failed: ${K}`, { cause: p });
1018
+ const $ = p instanceof Error ? p.message : String(p);
1019
+ throw new o("network_error", `Network request failed: ${$}`, { cause: p });
1011
1020
  }
1012
1021
  if (h.status === 402) {
1013
- const p = await it(h);
1022
+ const p = await st(h);
1014
1023
  throw this.onQuotaExceeded?.(p), p;
1015
1024
  }
1016
1025
  if (!h.ok) {
1017
- const p = await at(h.clone());
1026
+ const p = await it(h.clone());
1018
1027
  throw new o(
1019
1028
  p ?? `http_${h.status}`,
1020
1029
  h.statusText || "Gateway request failed",
1021
1030
  { status: h.status }
1022
1031
  );
1023
1032
  }
1024
- const w = h.headers.get("X-Query-Type") ?? void 0;
1025
- return this.onChargeSuccess?.(w), h;
1033
+ const g = h.headers.get("X-Query-Type") ?? void 0;
1034
+ return this.onChargeSuccess?.(g), h;
1026
1035
  }
1027
1036
  }
1028
- async function it(i) {
1037
+ async function st(i) {
1029
1038
  let t = {};
1030
1039
  try {
1031
1040
  t = await i.json();
@@ -1037,13 +1046,13 @@ async function it(i) {
1037
1046
  const a = e[0];
1038
1047
  Array.isArray(a) ? s = a : a && Array.isArray(a.balances) && (s = a.balances);
1039
1048
  }
1040
- return new q({
1049
+ return new F({
1041
1050
  balances: s,
1042
1051
  queryType: t.details?.queryType ?? "",
1043
1052
  currentBalance: t.details?.currentBalance ?? null
1044
1053
  });
1045
1054
  }
1046
- async function at(i) {
1055
+ async function it(i) {
1047
1056
  if (!(i.headers.get("content-type") ?? "").includes("application/json")) return null;
1048
1057
  try {
1049
1058
  const e = await i.json();
@@ -1052,35 +1061,39 @@ async function at(i) {
1052
1061
  return null;
1053
1062
  }
1054
1063
  }
1055
- const nt = 5e3, rt = 30 * 6e4, B = 60 * 6e4, ot = 5 * 6e4, A = {
1064
+ const at = 5e3, nt = 30 * 6e4, B = 60 * 6e4, rt = 5 * 6e4, k = {
1056
1065
  has_active_subscription: !1,
1057
1066
  purchases: [],
1058
1067
  trial: null
1059
1068
  };
1060
- function k(i) {
1069
+ function A(i) {
1061
1070
  return i && (i.email || i.userId || i.anonymousId) || "guest";
1062
1071
  }
1063
- function ct(i, t) {
1072
+ function ot(i, t) {
1064
1073
  return i === t ? !0 : !i || !t ? !1 : JSON.stringify(i) === JSON.stringify(t);
1065
1074
  }
1066
- const ht = 5e3, T = 5 * 6e4, lt = 3e4;
1067
- function ut(i, t) {
1075
+ const ct = 5e3, T = 5 * 6e4, ht = 3e4;
1076
+ function lt(i, t) {
1068
1077
  if (i === t) return !0;
1069
1078
  if (!i || !t || i.length !== t.length) return !1;
1070
1079
  for (let e = 0; e < i.length; e++)
1071
1080
  if (i[e].type !== t[e].type || i[e].count !== t[e].count) return !1;
1072
1081
  return !0;
1073
1082
  }
1074
- const dt = "https://appbox.space";
1075
- class It {
1083
+ class mt {
1076
1084
  constructor(t) {
1077
1085
  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)
1078
1086
  throw new o("invalid_config", "paywallId is required");
1079
- this.paywallId = t.paywallId, this.apiOrigin = t.apiOrigin ?? dt, this.capabilities = t.capabilities, this.auth = t.auth, this.previewMode = t.preview === !0;
1087
+ if (!t.apiOrigin)
1088
+ throw new o(
1089
+ "invalid_config",
1090
+ '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.'
1091
+ );
1092
+ this.paywallId = t.paywallId, this.apiOrigin = t.apiOrigin, this.capabilities = t.capabilities, this.auth = t.auth, this.previewMode = t.preview === !0;
1080
1093
  const e = t.auth?.getCachedUser();
1081
- this.identity = t.identity ?? (e ? U(e) : void 0), this.apiKey = t.apiKey, this.fetchImpl = t.fetch, t.apiKey && typeof window < "u" && typeof window.document < "u" && console.error(
1094
+ 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(
1082
1095
  "[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."
1083
- ), this.storage = R(t.storage), this.api = new L({
1096
+ ), this.storage = R(t.storage), this.api = new P({
1084
1097
  apiOrigin: this.apiOrigin,
1085
1098
  paywallId: t.paywallId,
1086
1099
  capabilities: t.capabilities,
@@ -1090,8 +1103,8 @@ class It {
1090
1103
  // Authorization-хедер просто не выставится.
1091
1104
  getAuthToken: t.auth ? () => t.auth.getAccessToken() : void 0
1092
1105
  }), t.auth && (this.authUnsubscribe = t.auth.onAuthChange((s, a) => {
1093
- const n = a ? U(a.user) : void 0;
1094
- ft(this.identity, n) || this.setIdentity(n);
1106
+ const n = a ? O(a.user) : void 0;
1107
+ ut(this.identity, n) || this.setIdentity(n);
1095
1108
  })), this.hydrateUserFromStorage(), this.hydrateBootstrapFromStorage(), this.subscribeBootstrapStorage(), this.hydrateBalancesFromStorage(), this.subscribeBalancesStorage(), this.visitorIdPromise = _(this.storage).then((s) => (this.visitorId = s, s));
1096
1109
  }
1097
1110
  /**
@@ -1137,7 +1150,7 @@ class It {
1137
1150
  );
1138
1151
  }
1139
1152
  const s = Date.now(), a = this.cachedBootstrap && this.cachedBootstrapAt > 0 && s - this.cachedBootstrapAt < B;
1140
- return !e.force && a ? (s - this.cachedBootstrapAt > ot && this.revalidateBootstrap(e.signal).catch(() => {
1153
+ return !e.force && a ? (s - this.cachedBootstrapAt > rt && this.revalidateBootstrap(e.signal).catch(() => {
1141
1154
  }), { ...this.cachedBootstrap, user: this.cachedUser ?? void 0 }) : this.inflightBootstrap ? this.inflightBootstrap : (this.inflightBootstrap = this.fetchBootstrap({
1142
1155
  ifVersion: e.force ? void 0 : this.cachedBootstrap?.version,
1143
1156
  signal: e.signal
@@ -1186,7 +1199,7 @@ class It {
1186
1199
  offers: t.offers !== void 0 ? t.offers : e.offers,
1187
1200
  version: `preview:${++this.previewVersionCounter}`
1188
1201
  };
1189
- s.layout || (s.layout = O(s.settings, s.prices)), g(s), this.cachedBootstrap = s, this.cachedBootstrapAt = Date.now();
1202
+ s.layout || (s.layout = E(s.settings, s.prices)), w(s), this.cachedBootstrap = s, this.cachedBootstrapAt = Date.now();
1190
1203
  for (const a of this.bootstrapListeners)
1191
1204
  try {
1192
1205
  a(s);
@@ -1208,7 +1221,7 @@ class It {
1208
1221
  if ("unchanged" in a && a.unchanged)
1209
1222
  return this.cachedBootstrap ? (this.cachedBootstrapAt = Date.now(), a.user && this.applyUser(a.user), this.cachedBootstrap) : this.fetchBootstrap({ signal: t.signal });
1210
1223
  const n = a;
1211
- return n.layout || (n.layout = O(n.settings, n.prices)), g(n), this.applyBootstrap(n, { persist: !0 }), n.user && this.applyUser(n.user), n;
1224
+ return dt(n.settings.custom_domain, this.apiOrigin), n.layout || (n.layout = E(n.settings, n.prices)), w(n), this.applyBootstrap(n, { persist: !0 }), n.user && this.applyUser(n.user), n;
1212
1225
  }
1213
1226
  // Фоновый revalidate из stale-while-revalidate ветки. Дедуплицируется через
1214
1227
  // `inflightBootstrap`, чтобы параллельные revalidate'ы не пересекались.
@@ -1242,7 +1255,7 @@ class It {
1242
1255
  if (!t) return;
1243
1256
  const e = JSON.parse(t);
1244
1257
  if (!e?.bootstrap || Date.now() - e.at > B || this.cachedBootstrap) return;
1245
- g(e.bootstrap), this.cachedBootstrap = e.bootstrap, this.cachedBootstrapAt = e.at;
1258
+ w(e.bootstrap), this.cachedBootstrap = e.bootstrap, this.cachedBootstrapAt = e.at;
1246
1259
  for (const s of this.bootstrapListeners)
1247
1260
  try {
1248
1261
  s(e.bootstrap);
@@ -1278,7 +1291,7 @@ class It {
1278
1291
  this.cachedBootstrapAt = e.at;
1279
1292
  return;
1280
1293
  }
1281
- g(e.bootstrap), this.applyBootstrap(e.bootstrap, { persist: !1 });
1294
+ w(e.bootstrap), this.applyBootstrap(e.bootstrap, { persist: !1 });
1282
1295
  } catch {
1283
1296
  }
1284
1297
  }
@@ -1325,7 +1338,7 @@ class It {
1325
1338
  * есть `navigator.language`.
1326
1339
  */
1327
1340
  getUserLanguage() {
1328
- const t = typeof navigator < "u" && navigator.language ? navigator.language : null, e = this.cachedBootstrap?.settings.locale_default ?? null, s = this.cachedBootstrap ? M(this.cachedBootstrap) : null;
1341
+ const t = typeof navigator < "u" && navigator.language ? navigator.language : null, e = this.cachedBootstrap?.settings.locale_default ?? null, s = this.cachedBootstrap ? K(this.cachedBootstrap) : null;
1329
1342
  return { tag: s ?? t ?? e, applied: s, browserLanguage: t, countryLanguage: e };
1330
1343
  }
1331
1344
  /**
@@ -1337,10 +1350,10 @@ class It {
1337
1350
  * - Без identity возвращает empty-state (сервер тоже так делает).
1338
1351
  */
1339
1352
  async getUser({ force: t = !1, signal: e } = {}) {
1340
- return !t && this.cachedUser && Date.now() - this.cachedUserAt < nt ? this.cachedUser : this.inflightUser ? this.inflightUser : (this.inflightUser = (async () => {
1353
+ return !t && this.cachedUser && Date.now() - this.cachedUserAt < at ? this.cachedUser : this.inflightUser ? this.inflightUser : (this.inflightUser = (async () => {
1341
1354
  try {
1342
1355
  if (!this.identity?.email)
1343
- return this.applyUser(A), A;
1356
+ return this.applyUser(k), k;
1344
1357
  const s = await this.api.request(
1345
1358
  `/api/v1/paywall/${this.paywallId}/user-state`,
1346
1359
  { headers: { "X-User-Email": this.identity.email }, signal: e }
@@ -1393,7 +1406,7 @@ class It {
1393
1406
  return this.cachedUser;
1394
1407
  }
1395
1408
  applyUser(t) {
1396
- const e = !ct(this.cachedUser, t);
1409
+ const e = !ot(this.cachedUser, t);
1397
1410
  if (this.cachedUser = t, this.cachedUserAt = Date.now(), e) {
1398
1411
  this.persistUser(t);
1399
1412
  for (const s of this.userListeners)
@@ -1405,7 +1418,7 @@ class It {
1405
1418
  }
1406
1419
  }
1407
1420
  storageKey() {
1408
- return y.userState(this.paywallId, k(this.identity));
1421
+ return y.userState(this.paywallId, A(this.identity));
1409
1422
  }
1410
1423
  async hydrateUserFromStorage() {
1411
1424
  if (!this.cachedUser)
@@ -1413,7 +1426,7 @@ class It {
1413
1426
  const t = await this.storage.getItem(this.storageKey());
1414
1427
  if (!t) return;
1415
1428
  const e = JSON.parse(t);
1416
- if (!e?.user || Date.now() - e.at > rt || this.cachedUser) return;
1429
+ if (!e?.user || Date.now() - e.at > nt || this.cachedUser) return;
1417
1430
  this.applyUser(e.user);
1418
1431
  } catch {
1419
1432
  }
@@ -1442,7 +1455,7 @@ class It {
1442
1455
  */
1443
1456
  async getBalances({ force: t = !1, signal: e } = {}) {
1444
1457
  const s = Date.now(), a = this.cachedBalances ? s - this.cachedBalancesAt : 1 / 0;
1445
- return !t && this.cachedBalances && (a < ht || a < lt) ? this.cachedBalances : !t && this.cachedBalances && a < T ? (this.fetchBalances({ signal: e }).catch(() => {
1458
+ return !t && this.cachedBalances && (a < ct || a < ht) ? this.cachedBalances : !t && this.cachedBalances && a < T ? (this.fetchBalances({ signal: e }).catch(() => {
1446
1459
  }), this.cachedBalances) : this.inflightBalances ? this.inflightBalances : this.fetchBalances({ signal: e });
1447
1460
  }
1448
1461
  // Network primitive — единая точка для force/stale-revalidate/cold-start.
@@ -1533,7 +1546,7 @@ class It {
1533
1546
  */
1534
1547
  createApiGatewayClient(t = {}) {
1535
1548
  const e = t.onChargeSuccess, s = t.onQuotaExceeded;
1536
- return new st({
1549
+ return new et({
1537
1550
  paywallId: this.paywallId,
1538
1551
  apiOrigin: this.apiOrigin,
1539
1552
  auth: this.auth,
@@ -1550,7 +1563,7 @@ class It {
1550
1563
  });
1551
1564
  }
1552
1565
  applyBalances(t, { persist: e = !0 } = {}) {
1553
- const s = !ut(this.cachedBalances, t);
1566
+ const s = !lt(this.cachedBalances, t);
1554
1567
  if (this.cachedBalances = t, this.cachedBalancesAt = Date.now(), e && this.persistBalances(t), s)
1555
1568
  for (const a of this.balanceListeners)
1556
1569
  try {
@@ -1560,7 +1573,7 @@ class It {
1560
1573
  }
1561
1574
  }
1562
1575
  balancesStorageKey() {
1563
- return y.balances(this.paywallId, k(this.identity));
1576
+ return y.balances(this.paywallId, A(this.identity));
1564
1577
  }
1565
1578
  async hydrateBalancesFromStorage() {
1566
1579
  if (!this.cachedBalances)
@@ -1614,7 +1627,7 @@ class It {
1614
1627
  const e = t.idempotencyKey ?? `auto:${t.priceId}`, s = this.inflightCheckouts.get(e);
1615
1628
  if (s) return s;
1616
1629
  const n = {
1617
- "Idempotency-Key": t.idempotencyKey ?? P()
1630
+ "Idempotency-Key": t.idempotencyKey ?? D()
1618
1631
  };
1619
1632
  this.apiKey && (n["X-Api-Key"] = this.apiKey);
1620
1633
  const r = this.cachedBootstrap?.settings, l = t.successUrl ?? r?.success_redirect_url ?? void 0, u = t.shopUrl ?? r?.checkout_shop_url ?? void 0, d = this.api.request(`/api/v1/paywall/${this.paywallId}/start-checkout`, {
@@ -1758,23 +1771,43 @@ class It {
1758
1771
  });
1759
1772
  }
1760
1773
  }
1761
- function U(i) {
1774
+ function O(i) {
1762
1775
  return { email: i.email, userId: i.id };
1763
1776
  }
1764
- function ft(i, t) {
1777
+ function ut(i, t) {
1765
1778
  return i === t ? !0 : !i || !t ? !1 : i.email === t.email && i.userId === t.userId && i.anonymousId === t.anonymousId;
1766
1779
  }
1767
- function O(i, t) {
1780
+ function U(i) {
1781
+ if (!i) return null;
1782
+ const t = i.trim();
1783
+ if (!t) return null;
1784
+ try {
1785
+ return new URL(t.includes("://") ? t : `https://${t}`).origin;
1786
+ } catch {
1787
+ return null;
1788
+ }
1789
+ }
1790
+ function dt(i, t) {
1791
+ const e = U(i);
1792
+ if (!(!e || U(t) === e))
1793
+ throw new o(
1794
+ "invalid_config",
1795
+ `apiOrigin mismatch: SDK initialized with "${t}" but paywall is configured with custom_domain "${i}". Use the custom_domain from the platform paywall settings.`
1796
+ );
1797
+ }
1798
+ function E(i, t) {
1768
1799
  return {
1769
1800
  type: "modal",
1770
1801
  blocks: [
1771
1802
  { type: "heading", text: i.name || "Upgrade", level: 1 },
1772
1803
  { type: "price_grid", priceIds: t.map((e) => e.id) },
1773
- { type: "cta_button", label: "Continue", action: "checkout" }
1804
+ { type: "cta_button", label: "Continue", action: "checkout" },
1805
+ { type: "guarantee_badge" },
1806
+ { type: "current_session" }
1774
1807
  ]
1775
1808
  };
1776
1809
  }
1777
- function M(i) {
1810
+ function K(i) {
1778
1811
  const t = i.locales;
1779
1812
  if (!t) return null;
1780
1813
  const e = [];
@@ -1789,8 +1822,8 @@ function M(i) {
1789
1822
  if (a && Object.prototype.hasOwnProperty.call(t, a)) return a;
1790
1823
  return null;
1791
1824
  }
1792
- function g(i) {
1793
- const t = M(i);
1825
+ function w(i) {
1826
+ const t = K(i);
1794
1827
  if (!t) return;
1795
1828
  const e = i.locales?.[t];
1796
1829
  e && (e.layout && (i.layout = e.layout), e.prices && (i.prices = i.prices.map((s) => {
@@ -1800,7 +1833,7 @@ function g(i) {
1800
1833
  return "label" in a && (n.label = a.label ?? null), "description" in a && (n.description = a.description ?? null), n;
1801
1834
  })));
1802
1835
  }
1803
- const yt = 1500, pt = 20, E = 200;
1836
+ const ft = 1500, yt = 20, C = 200;
1804
1837
  class St {
1805
1838
  constructor(t) {
1806
1839
  this.buffer = [], this.flushTimer = null, this.destroyed = !1, this.unloadHandler = null, this.visibilityHandler = null, this.opts = t, this.isEnabled() && this.attachUnloadHandlers();
@@ -1811,16 +1844,16 @@ class St {
1811
1844
  track(t, e) {
1812
1845
  if (this.destroyed || !this.isEnabled() || typeof t != "string" || t.length === 0) return;
1813
1846
  this.buffer.push({ type: t, ts: Date.now(), props: e });
1814
- const s = this.opts.maxBufferSize ?? pt;
1847
+ const s = this.opts.maxBufferSize ?? yt;
1815
1848
  if (this.buffer.length >= s) {
1816
1849
  this.flush();
1817
1850
  return;
1818
1851
  }
1819
- this.buffer.length > E && (this.buffer = this.buffer.slice(-E)), this.scheduleFlush();
1852
+ this.buffer.length > C && (this.buffer = this.buffer.slice(-C)), this.scheduleFlush();
1820
1853
  }
1821
1854
  scheduleFlush() {
1822
1855
  if (this.flushTimer || this.destroyed) return;
1823
- const t = this.opts.flushIntervalMs ?? yt;
1856
+ const t = this.opts.flushIntervalMs ?? ft;
1824
1857
  this.flushTimer = setTimeout(() => {
1825
1858
  this.flushTimer = null, this.flush();
1826
1859
  }, t);
@@ -1899,14 +1932,14 @@ class St {
1899
1932
  this.destroyed || (this.destroyed = !0, this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.flush(), this.detachUnloadHandlers());
1900
1933
  }
1901
1934
  }
1902
- const C = 3600 * 1e3;
1903
- function S(i) {
1935
+ const N = 3600 * 1e3;
1936
+ function v(i) {
1904
1937
  return `paywall-${i}-trial-time-first-open`;
1905
1938
  }
1906
- function v(i) {
1939
+ function b(i) {
1907
1940
  return `paywall-${i}-skip-times`;
1908
1941
  }
1909
- class F {
1942
+ class M {
1910
1943
  constructor(t, e, s) {
1911
1944
  this.storage = t, this.paywallId = e, this.config = s;
1912
1945
  }
@@ -1917,10 +1950,10 @@ class F {
1917
1950
  return this.config.mode === "time" ? this.recordTime() : this.recordOpens();
1918
1951
  }
1919
1952
  async reset() {
1920
- await this.storage.removeItem(this.config.mode === "time" ? S(this.paywallId) : v(this.paywallId));
1953
+ await this.storage.removeItem(this.config.mode === "time" ? v(this.paywallId) : b(this.paywallId));
1921
1954
  }
1922
1955
  async checkTime() {
1923
- const t = this.config.payload * C, e = await this.storage.getItem(S(this.paywallId)), s = e ? Number(e) : null;
1956
+ const t = this.config.payload * N, e = await this.storage.getItem(v(this.paywallId)), s = e ? Number(e) : null;
1924
1957
  if (!s || !Number.isFinite(s))
1925
1958
  return {
1926
1959
  mode: "time",
@@ -1941,7 +1974,7 @@ class F {
1941
1974
  };
1942
1975
  }
1943
1976
  async checkOpens() {
1944
- const t = this.config.payload, e = await this.storage.getItem(v(this.paywallId)), s = e ? Number(e) : 0, a = Number.isFinite(s) ? s : 0, n = a < t, r = Math.max(0, t - a);
1977
+ 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);
1945
1978
  return {
1946
1979
  mode: "opens",
1947
1980
  blocked: n,
@@ -1950,7 +1983,7 @@ class F {
1950
1983
  };
1951
1984
  }
1952
1985
  async recordTime() {
1953
- const t = this.config.payload * C, e = S(this.paywallId), s = await this.storage.getItem(e);
1986
+ const t = this.config.payload * N, e = v(this.paywallId), s = await this.storage.getItem(e);
1954
1987
  let a = s ? Number(s) : null;
1955
1988
  (!a || !Number.isFinite(a)) && (a = Date.now(), await this.storage.setItem(e, String(a)));
1956
1989
  const n = a + t, r = Math.max(0, n - Date.now());
@@ -1964,7 +1997,7 @@ class F {
1964
1997
  };
1965
1998
  }
1966
1999
  async recordOpens() {
1967
- const t = this.config.payload, e = v(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);
2000
+ 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);
1968
2001
  await this.storage.setItem(e, String(r));
1969
2002
  const l = Math.max(0, t - r);
1970
2003
  return {
@@ -1975,12 +2008,12 @@ class F {
1975
2008
  };
1976
2009
  }
1977
2010
  }
1978
- let N = !1;
1979
- class wt {
2011
+ let L = !1;
2012
+ class pt {
1980
2013
  constructor(t, e, s) {
1981
- N || (N = !0, console.warn(
2014
+ L || (L = !0, console.warn(
1982
2015
  '[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.'
1983
- )), this.fallback = new F(t, e, s);
2016
+ )), this.fallback = new M(t, e, s);
1984
2017
  }
1985
2018
  check() {
1986
2019
  return this.fallback.check();
@@ -1993,10 +2026,10 @@ class wt {
1993
2026
  }
1994
2027
  }
1995
2028
  function vt(i, t, e) {
1996
- return e.storage === "server" ? new wt(i, t, e) : new F(i, t, e);
2029
+ return e.storage === "server" ? new pt(i, t, e) : new M(i, t, e);
1997
2030
  }
1998
2031
  const bt = 1;
1999
- function _t(i) {
2032
+ function It(i) {
2000
2033
  return i instanceof o ? {
2001
2034
  name: "PaywallError",
2002
2035
  code: i.code,
@@ -2014,7 +2047,7 @@ function _t(i) {
2014
2047
  message: typeof i == "string" ? i : "Unknown error"
2015
2048
  };
2016
2049
  }
2017
- function Bt(i) {
2050
+ function _t(i) {
2018
2051
  if (i.name === "PaywallError") {
2019
2052
  const e = new o(i.code, i.message, { status: i.status });
2020
2053
  return i.stack && (e.stack = i.stack), e;
@@ -2054,21 +2087,21 @@ function gt(i) {
2054
2087
  }
2055
2088
  };
2056
2089
  }
2057
- function At(i) {
2090
+ function Bt(i) {
2058
2091
  const t = chrome.runtime.connect({ name: i });
2059
2092
  return gt(t);
2060
2093
  }
2061
2094
  export {
2062
- mt as A,
2063
- It as B,
2095
+ wt as A,
2096
+ mt as B,
2064
2097
  St as E,
2065
2098
  o as P,
2066
2099
  bt as a,
2067
- At as b,
2100
+ Bt as b,
2068
2101
  vt as c,
2069
2102
  gt as p,
2070
- Bt as r,
2071
- _t as s,
2103
+ _t as r,
2104
+ It as s,
2072
2105
  Z as w
2073
2106
  };
2074
- //# sourceMappingURL=chrome-port-BAMwPMV0.js.map
2107
+ //# sourceMappingURL=chrome-port-rPi6zrjD.js.map