@virex-tech/paywallo-sdk 2.0.0 → 2.0.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
@@ -4420,8 +4420,15 @@ var init_NativePushBridge = __esm({
4420
4420
  const mod = NativeModules7.PaywalloNotifications;
4421
4421
  if (!mod) return -1;
4422
4422
  const status = await mod.requestPermission(options ?? {});
4423
+ if (status === "granted" || status === "provisional") {
4424
+ try {
4425
+ await mod.registerForPush();
4426
+ } catch {
4427
+ }
4428
+ }
4423
4429
  return mapStatusToNumber(status);
4424
- } catch {
4430
+ } catch (err) {
4431
+ console.warn("[NativePushBridge] requestPermission error:", err instanceof Error ? err.message : String(err));
4425
4432
  return -1;
4426
4433
  }
4427
4434
  }
@@ -4796,11 +4803,18 @@ var init_PermissionManager = __esm({
4796
4803
  const platform = this.platformOverride ?? getPlatform();
4797
4804
  if (this.debug) console.warn("[paywallo-push] platform detected:", platform.OS, "version:", String(platform.Version ?? "n/a"));
4798
4805
  if (platform.OS === "ios") {
4799
- if (this.debug) console.log("[paywallo-push] requestPermission iOS", options);
4800
- const raw2 = await this.bridge.requestPermission(options);
4801
- const status2 = mapPermissionStatus(raw2);
4802
- this.emitOsEvent(status2);
4803
- return status2;
4806
+ if (this.debug) console.warn("[paywallo-push] requestPermission iOS \u2014 calling bridge...");
4807
+ try {
4808
+ const raw2 = await this.bridge.requestPermission(options);
4809
+ if (this.debug) console.warn("[paywallo-push] bridge returned raw:", raw2);
4810
+ const status2 = mapPermissionStatus(raw2);
4811
+ if (this.debug) console.warn("[paywallo-push] mapped status:", status2);
4812
+ this.emitOsEvent(status2);
4813
+ return status2;
4814
+ } catch (err) {
4815
+ console.warn("[paywallo-push] requestPermission iOS CRASHED:", err instanceof Error ? err.message : String(err));
4816
+ throw err;
4817
+ }
4804
4818
  }
4805
4819
  if (!needsAndroidRuntimePermission(platform)) {
4806
4820
  if (this.debug) console.log("[paywallo-push] Android <13: auto-granted");
@@ -5014,8 +5028,8 @@ var init_utils = __esm({
5014
5028
  // src/core/version.ts
5015
5029
  function resolveVersion() {
5016
5030
  try {
5017
- if ("2.0.0") {
5018
- return "2.0.0";
5031
+ if ("2.0.1") {
5032
+ return "2.0.1";
5019
5033
  }
5020
5034
  } catch {
5021
5035
  }
@@ -5293,14 +5307,23 @@ var init_NotificationsManager = __esm({
5293
5307
  }
5294
5308
  /** Requests OS permission and, on success, captures + registers the push token. */
5295
5309
  async requestPushPermission(options) {
5296
- const status = await this.permissionManager.requestPermission(options);
5297
- this.permissionStatus = status;
5298
- if (status === "granted" || status === "provisional") {
5299
- await this.captureAndRegisterToken();
5300
- } else if (this.debug) {
5301
- console.log("[Paywallo PUSH] permission not granted, skipping token register:", status);
5310
+ if (this.debug) console.warn("[Paywallo PUSH] requestPushPermission called");
5311
+ try {
5312
+ const status = await this.permissionManager.requestPermission(options);
5313
+ if (this.debug) console.warn("[Paywallo PUSH] permissionManager returned:", status);
5314
+ this.permissionStatus = status;
5315
+ if (status === "granted" || status === "provisional") {
5316
+ if (this.debug) console.warn("[Paywallo PUSH] permission granted \u2014 capturing token...");
5317
+ await this.captureAndRegisterToken();
5318
+ if (this.debug) console.warn("[Paywallo PUSH] token capture complete");
5319
+ } else {
5320
+ if (this.debug) console.warn("[Paywallo PUSH] permission not granted, skipping token register:", status);
5321
+ }
5322
+ return status;
5323
+ } catch (err) {
5324
+ console.warn("[Paywallo PUSH] requestPushPermission CRASHED:", err instanceof Error ? err.message : String(err));
5325
+ throw err;
5302
5326
  }
5303
- return status;
5304
5327
  }
5305
5328
  async captureAndRegisterToken() {
5306
5329
  await captureAndRegisterToken(
@@ -7328,17 +7351,14 @@ async function resolveSessionFlags(state, keys, apiClient, distinctId) {
7328
7351
  }
7329
7352
  }
7330
7353
  async function doInit(state, config) {
7331
- console.warn("[Paywallo INIT] starting... debug=" + String(config.debug) + " env=" + String(config.environment ?? "auto"));
7332
7354
  const environment = config.environment ?? (typeof __DEV__ !== "undefined" && __DEV__ ? "Sandbox" : "Production");
7333
7355
  const offlineQueueEnabled = config.offlineQueueEnabled !== false;
7334
- if (config.debug) console.warn("[Paywallo INIT] step 1: network + queue");
7335
7356
  await Promise.all([
7336
7357
  networkMonitor.initialize({ debug: config.debug }),
7337
7358
  offlineQueue.initialize({ debug: config.debug }).then(
7338
7359
  () => offlineQueue.clearItemsWithInvalidAppKey(config.appKey)
7339
7360
  )
7340
7361
  ]);
7341
- if (config.debug) console.warn("[Paywallo INIT] step 1 done");
7342
7362
  const apiClient = new ApiClient(
7343
7363
  config.appKey,
7344
7364
  config.apiUrl ?? DEFAULT_API_URL2,
@@ -7361,9 +7381,7 @@ async function doInit(state, config) {
7361
7381
  cacheTTL: config.subscriptionCacheTTL,
7362
7382
  debug: config.debug
7363
7383
  });
7364
- if (config.debug) console.warn("[Paywallo INIT] step 2: identity");
7365
7384
  await identityManager.initialize(apiClient, config.debug);
7366
- if (config.debug) console.warn("[Paywallo INIT] step 2 done");
7367
7385
  if (state.pendingIdentifies.length > 0) {
7368
7386
  for (const pending of state.pendingIdentifies) {
7369
7387
  try {
@@ -7406,22 +7424,18 @@ async function doInit(state, config) {
7406
7424
  ...attribution && Object.keys(attribution).length > 0 && { attribution }
7407
7425
  };
7408
7426
  });
7409
- if (config.debug) console.warn("[Paywallo INIT] step 3: session");
7410
7427
  await sessionManager.initialize(
7411
7428
  apiClient,
7412
7429
  config.sessionConfig,
7413
7430
  config.debug,
7414
7431
  () => identityManager.getDistinctId()
7415
7432
  );
7416
- if (config.debug) console.warn("[Paywallo INIT] step 3 done");
7417
7433
  const eventPipeline = createEventPipelineBridge(apiClient);
7418
7434
  onboardingManager.injectDeps({
7419
7435
  pipeline: eventPipeline,
7420
7436
  debug: config.debug
7421
7437
  });
7422
- if (config.debug) console.warn("[Paywallo INIT] step 4: notifications");
7423
7438
  setupNotifications(apiClient, config, environment, eventPipeline);
7424
- if (config.debug) console.warn("[Paywallo INIT] step 4 done");
7425
7439
  if (config.autoStartSession !== false) {
7426
7440
  sessionManager.startSession().catch((err) => {
7427
7441
  if (config.debug) console.warn("[Paywallo INIT] autoStart session error", err);
@@ -7732,29 +7746,23 @@ var init_PaywalloClient = __esm({
7732
7746
  }
7733
7747
  async init(config) {
7734
7748
  const s = this.state;
7735
- console.warn("[Paywallo SDK] init() called, debug=" + String(config.debug) + ", appKey=" + (config.appKey ? config.appKey.substring(0, 8) + "..." : "EMPTY"));
7736
7749
  if (!s.readyPromise) s.readyPromise = new Promise((resolve) => {
7737
7750
  s.resolveReady = resolve;
7738
7751
  });
7739
7752
  if (s.config && s.apiClient) {
7740
- console.warn("[Paywallo SDK] init() skipped \u2014 already initialized");
7741
7753
  return;
7742
7754
  }
7743
7755
  if (s.initPromise) {
7744
- console.warn("[Paywallo SDK] init() skipped \u2014 already in progress");
7745
7756
  await s.initPromise;
7746
7757
  return;
7747
7758
  }
7748
7759
  if (!config.appKey) throw new ClientError(CLIENT_ERROR_CODES.MISSING_APP_KEY, "appKey is required");
7749
7760
  s.pendingConfig = config;
7750
7761
  s.initAttempts = 0;
7751
- console.warn("[Paywallo SDK] init() calling initWithRetry...");
7752
7762
  s.initPromise = initWithRetry(s, config);
7753
7763
  try {
7754
7764
  await s.initPromise;
7755
- console.warn("[Paywallo SDK] init() completed successfully");
7756
7765
  } catch (error) {
7757
- console.warn("[Paywallo SDK] init() FAILED:", error instanceof Error ? error.message : String(error));
7758
7766
  s.initPromise = null;
7759
7767
  s.config = null;
7760
7768
  s.apiClient = null;