@virex-tech/paywallo-sdk 2.4.0 → 2.4.1

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/index.mjs CHANGED
@@ -2405,8 +2405,8 @@ var init_NotificationHandlerSetup = __esm({
2405
2405
  // src/core/version.ts
2406
2406
  function resolveVersion() {
2407
2407
  try {
2408
- if ("2.4.0") {
2409
- return "2.4.0";
2408
+ if ("2.4.1") {
2409
+ return "2.4.1";
2410
2410
  }
2411
2411
  } catch {
2412
2412
  }
@@ -4531,11 +4531,11 @@ var init_OfflineQueue = __esm({
4531
4531
  });
4532
4532
  return true;
4533
4533
  }
4534
- const delay = Math.min(
4534
+ const delay2 = Math.min(
4535
4535
  this.config.baseRetryDelayMs * Math.pow(2, item.attempts - 1),
4536
4536
  this.config.maxRetryDelayMs
4537
4537
  );
4538
- item.nextRetryAt = Date.now() + delay;
4538
+ item.nextRetryAt = Date.now() + delay2;
4539
4539
  await this.storage.saveToStorage(this.queue);
4540
4540
  return false;
4541
4541
  }
@@ -7813,8 +7813,8 @@ var init_HttpClient = __esm({
7813
7813
  if (this.shouldRetry(response.status, retryConfig)) {
7814
7814
  if (state.attempt < retryConfig.maxRetries) {
7815
7815
  state.attempt++;
7816
- const delay = this.calculateDelayForResponse(state.attempt, response.headers, retryConfig);
7817
- await this.sleep(delay);
7816
+ const delay2 = this.calculateDelayForResponse(state.attempt, response.headers, retryConfig);
7817
+ await this.sleep(delay2);
7818
7818
  continue;
7819
7819
  }
7820
7820
  }
@@ -7823,8 +7823,8 @@ var init_HttpClient = __esm({
7823
7823
  state.lastError = error instanceof Error ? error : new ClientError(CLIENT_ERROR_CODES.UNKNOWN, String(error));
7824
7824
  if (this.isNetworkError(state.lastError) && state.attempt < retryConfig.maxRetries) {
7825
7825
  state.attempt++;
7826
- const delay = this.calculateDelay(state.attempt, retryConfig);
7827
- await this.sleep(delay);
7826
+ const delay2 = this.calculateDelay(state.attempt, retryConfig);
7827
+ await this.sleep(delay2);
7828
7828
  continue;
7829
7829
  }
7830
7830
  throw state.lastError;
@@ -8476,8 +8476,8 @@ async function initWithRetry(state, config) {
8476
8476
  } catch (error) {
8477
8477
  state.initAttempts++;
8478
8478
  if (state.initAttempts > MAX_INIT_RETRIES) throw error;
8479
- const delay = RETRY_DELAYS[state.initAttempts - 1] ?? 1e4;
8480
- await new Promise((resolve) => setTimeout(resolve, delay));
8479
+ const delay2 = RETRY_DELAYS[state.initAttempts - 1] ?? 1e4;
8480
+ await new Promise((resolve) => setTimeout(resolve, delay2));
8481
8481
  }
8482
8482
  }
8483
8483
  }
@@ -9754,12 +9754,17 @@ init_paywall();
9754
9754
 
9755
9755
  // src/domains/paywall/SuperwallAttributeBridge.ts
9756
9756
  init_identity();
9757
+ var CONFIG_POLL_INTERVAL_MS = 250;
9758
+ var CONFIG_POLL_MAX_ATTEMPTS = 40;
9757
9759
  var lastSignature = null;
9758
9760
  function log(debug, msg, data) {
9759
9761
  if (!debug) return;
9760
9762
  if (data !== void 0) console.log(`[Paywallo:SuperwallAttr] ${msg}`, data);
9761
9763
  else console.log(`[Paywallo:SuperwallAttr] ${msg}`);
9762
9764
  }
9765
+ function delay(ms) {
9766
+ return new Promise((resolve) => setTimeout(resolve, ms));
9767
+ }
9763
9768
  var PAID_MEDIUM = /cpc|ppc|cpm|cpa|paid|display/i;
9764
9769
  function deriveIsPaid(a) {
9765
9770
  if (a.fbclid || a.gclid || a.ttclid || a.tiktokCampaignId) return true;
@@ -9798,24 +9803,38 @@ function buildSuperwallAttributes(a) {
9798
9803
  out.pw_attributed_at = a.capturedAt;
9799
9804
  return out;
9800
9805
  }
9801
- function pickShared(mod) {
9802
- const shared = mod?.default?.shared ?? mod?.shared;
9803
- return shared && typeof shared.setUserAttributes === "function" ? shared : null;
9806
+ function pickNative(mod) {
9807
+ const native = mod?.SuperwallExpoModule ?? mod?.default?.SuperwallExpoModule;
9808
+ return native && typeof native.setUserAttributes === "function" && typeof native.getConfigurationStatus === "function" ? native : null;
9804
9809
  }
9805
- async function resolveSuperwallShared(debug) {
9806
- try {
9807
- const shared = pickShared(await import("expo-superwall/compat"));
9808
- if (shared) return shared;
9809
- } catch {
9810
- }
9810
+ async function resolveSuperwallNativeModule(debug) {
9811
9811
  try {
9812
- const shared = pickShared(await import("expo-superwall"));
9813
- if (shared) return shared;
9812
+ const native = pickNative(await import("expo-superwall"));
9813
+ if (native) return native;
9814
9814
  } catch {
9815
9815
  }
9816
- log(debug, "expo-superwall not available \u2014 attribute push skipped");
9816
+ log(debug, "expo-superwall native module not available \u2014 attribute push skipped");
9817
9817
  return null;
9818
9818
  }
9819
+ async function waitForConfigured(mod, debug) {
9820
+ for (let attempt = 0; attempt < CONFIG_POLL_MAX_ATTEMPTS; attempt++) {
9821
+ let status;
9822
+ try {
9823
+ status = String(await mod.getConfigurationStatus());
9824
+ } catch (err) {
9825
+ log(debug, "getConfigurationStatus error", { err: String(err) });
9826
+ return false;
9827
+ }
9828
+ if (status === "CONFIGURED") return true;
9829
+ if (status === "FAILED") {
9830
+ log(debug, "Superwall configuration FAILED \u2014 skipping attribute push");
9831
+ return false;
9832
+ }
9833
+ await delay(CONFIG_POLL_INTERVAL_MS);
9834
+ }
9835
+ log(debug, "Superwall not configured within timeout \u2014 skipping attribute push");
9836
+ return false;
9837
+ }
9819
9838
  async function pushAttributionToSuperwall(debug = false) {
9820
9839
  const attrs = buildSuperwallAttributes(attributionTracker.get());
9821
9840
  const signature = JSON.stringify(attrs);
@@ -9823,10 +9842,11 @@ async function pushAttributionToSuperwall(debug = false) {
9823
9842
  log(debug, "attributes unchanged \u2014 skipping push");
9824
9843
  return;
9825
9844
  }
9826
- const shared = await resolveSuperwallShared(debug);
9827
- if (!shared) return;
9845
+ const native = await resolveSuperwallNativeModule(debug);
9846
+ if (!native) return;
9847
+ if (!await waitForConfigured(native, debug)) return;
9828
9848
  try {
9829
- await shared.setUserAttributes(attrs);
9849
+ await native.setUserAttributes(attrs);
9830
9850
  lastSignature = signature;
9831
9851
  log(debug, "attributes pushed to Superwall", attrs);
9832
9852
  } catch (err) {