@virex-tech/paywallo-sdk 2.0.1 → 2.1.0

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
@@ -1539,7 +1539,7 @@ var init_QueueProcessor = __esm({
1539
1539
  }
1540
1540
  const allItems = offlineQueue.getQueue();
1541
1541
  const eventItems = allItems.filter(
1542
- (i) => (i.url.includes("/api/v1/events") || i.url.includes("/api/v2/ingest")) && !i.url.includes("/batch")
1542
+ (i) => (i.url.includes("/events") || i.url.includes("/ingest")) && !i.url.includes("/batch")
1543
1543
  );
1544
1544
  const eventItemIds = new Set(eventItems.map((i) => i.id));
1545
1545
  const { processed: batchProcessed, failed: batchFailed, retryIds } = await this.processEventBatches(eventItems);
@@ -1579,7 +1579,7 @@ var init_QueueProcessor = __esm({
1579
1579
  const freshHeaders = this.config.getFreshHeaders?.() ?? {};
1580
1580
  const headers = { ...persistedHeaders, ...freshHeaders };
1581
1581
  this.log("Sending event batch", { size: batch.length, batchIndex: Math.floor(i / BATCH_SIZE) });
1582
- const response = await this.httpClient.request("/api/v1/events/batch", {
1582
+ const response = await this.httpClient.request("/sdk/events/batch", {
1583
1583
  method: "POST",
1584
1584
  body: { events: bodies },
1585
1585
  headers,
@@ -4239,7 +4239,7 @@ var init_InstallTracker = __esm({
4239
4239
  const baseUrl = apiClient.getBaseUrl();
4240
4240
  const appKey = apiClient.getAppKey();
4241
4241
  const referrer = await installReferrerManager.getReferrer();
4242
- await fetch(`${baseUrl}/api/v1/attribution/deferred-match/${appKey}`, {
4242
+ await fetch(`${baseUrl}/attribution/deferred-match/${appKey}`, {
4243
4243
  method: "POST",
4244
4244
  headers: { "Content-Type": "application/json", "X-App-Key": appKey },
4245
4245
  body: JSON.stringify({
@@ -4497,6 +4497,7 @@ var init_BackgroundHandler = __esm({
4497
4497
  });
4498
4498
 
4499
4499
  // src/domains/notifications/NotificationEventTracker.ts
4500
+ import { Platform as Platform9 } from "react-native";
4500
4501
  function getTimezone() {
4501
4502
  try {
4502
4503
  return Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
@@ -4505,12 +4506,7 @@ function getTimezone() {
4505
4506
  }
4506
4507
  }
4507
4508
  function detectPlatform() {
4508
- try {
4509
- const { Platform: Platform13 } = __require("react-native");
4510
- return Platform13.OS === "ios" ? "ios" : "android";
4511
- } catch {
4512
- return "android";
4513
- }
4509
+ return Platform9.OS === "ios" ? "ios" : "android";
4514
4510
  }
4515
4511
  var SEEN_MESSAGES_KEY, SEEN_TTL_MS, MAX_SEEN_SIZE, NotificationEventTracker;
4516
4512
  var init_NotificationEventTracker = __esm({
@@ -4753,7 +4749,7 @@ var init_NotificationHandlerSetup = __esm({
4753
4749
  });
4754
4750
 
4755
4751
  // src/domains/notifications/PermissionManager.ts
4756
- import { Platform as Platform9 } from "react-native";
4752
+ import { Platform as Platform10 } from "react-native";
4757
4753
  function mapPermissionStatus(status) {
4758
4754
  switch (status) {
4759
4755
  case AUTH_STATUS.AUTHORIZED:
@@ -4767,7 +4763,7 @@ function mapPermissionStatus(status) {
4767
4763
  }
4768
4764
  }
4769
4765
  function getPlatform() {
4770
- return Platform9;
4766
+ return Platform10;
4771
4767
  }
4772
4768
  function needsAndroidRuntimePermission(platform) {
4773
4769
  if (platform.OS !== "android") return false;
@@ -4891,6 +4887,16 @@ var init_PermissionManager = __esm({
4891
4887
  }
4892
4888
  });
4893
4889
 
4890
+ // src/core/constants.ts
4891
+ var DEFAULT_API_URL, DEFAULT_WEB_URL;
4892
+ var init_constants = __esm({
4893
+ "src/core/constants.ts"() {
4894
+ "use strict";
4895
+ DEFAULT_API_URL = "https://panel.lucasqueiroga.shop";
4896
+ DEFAULT_WEB_URL = "https://paywallo.com.br";
4897
+ }
4898
+ });
4899
+
4894
4900
  // src/domains/notifications/config.ts
4895
4901
  function resolveApiBaseUrl(config) {
4896
4902
  if (config.apiBaseUrl) return config.apiBaseUrl;
@@ -4901,8 +4907,9 @@ var DEFAULT_API_BASE_URL, SANDBOX_API_BASE_URL;
4901
4907
  var init_config = __esm({
4902
4908
  "src/domains/notifications/config.ts"() {
4903
4909
  "use strict";
4904
- DEFAULT_API_BASE_URL = "https://api.paywallo.com.br";
4905
- SANDBOX_API_BASE_URL = "https://sandbox.paywallo.com.br";
4910
+ init_constants();
4911
+ DEFAULT_API_BASE_URL = DEFAULT_API_URL;
4912
+ SANDBOX_API_BASE_URL = DEFAULT_API_URL;
4906
4913
  }
4907
4914
  });
4908
4915
 
@@ -4939,6 +4946,7 @@ var init_NotificationsError = __esm({
4939
4946
  });
4940
4947
 
4941
4948
  // src/domains/notifications/utils.ts
4949
+ import { Platform as Platform11 } from "react-native";
4942
4950
  function sleep(ms, signal) {
4943
4951
  return new Promise((resolve, reject) => {
4944
4952
  if (signal?.aborted) {
@@ -4994,12 +5002,10 @@ function mapPermissionStatus2(status) {
4994
5002
  }
4995
5003
  }
4996
5004
  function detectPlatform2() {
4997
- try {
4998
- const { Platform: Platform13 } = __require("react-native");
4999
- return Platform13.OS === "ios" ? "ios" : "android";
5000
- } catch {
5001
- return "android";
5002
- }
5005
+ return Platform11.OS === "ios" ? "ios" : "android";
5006
+ }
5007
+ function detectEnvironment() {
5008
+ return typeof __DEV__ !== "undefined" && __DEV__ ? "sandbox" : "production";
5003
5009
  }
5004
5010
  async function getAppVersion() {
5005
5011
  try {
@@ -5028,8 +5034,8 @@ var init_utils = __esm({
5028
5034
  // src/core/version.ts
5029
5035
  function resolveVersion() {
5030
5036
  try {
5031
- if ("2.0.1") {
5032
- return "2.0.1";
5037
+ if ("2.1.0") {
5038
+ return "2.1.0";
5033
5039
  }
5034
5040
  } catch {
5035
5041
  }
@@ -5068,7 +5074,8 @@ async function buildRegistration(token, getDeviceId, getDistinctId) {
5068
5074
  sdk_version: SDK_VERSION,
5069
5075
  deviceId: getDeviceId?.() ?? void 0,
5070
5076
  locale: getLocale(),
5071
- timezone: getTimezone2()
5077
+ timezone: getTimezone2(),
5078
+ environment: detectEnvironment()
5072
5079
  };
5073
5080
  }
5074
5081
  async function registerToken(deps, token) {
@@ -5110,7 +5117,7 @@ var init_TokenRegistration = __esm({
5110
5117
  init_utils();
5111
5118
  init_version();
5112
5119
  FCM_TOKEN_KEY = "@panel:push_token";
5113
- TOKEN_ENDPOINT = "/api/v2/push-tokens";
5120
+ TOKEN_ENDPOINT = "/push-tokens";
5114
5121
  }
5115
5122
  });
5116
5123
 
@@ -5755,18 +5762,17 @@ function deriveWebUrl(baseUrl) {
5755
5762
  }
5756
5763
  }
5757
5764
  function buildConditionalFlagUrl(baseUrl, flagKey, context) {
5758
- const url = new URL(`${baseUrl}/api/v1/conditional-flags/${flagKey}`);
5765
+ const url = new URL(`${baseUrl}/sdk/conditional-flags/${flagKey}`);
5759
5766
  if (context.platform) url.searchParams.set("platform", context.platform);
5760
5767
  if (context.appVersion) url.searchParams.set("appVersion", context.appVersion);
5761
5768
  if (context.country) url.searchParams.set("country", context.country);
5762
5769
  if (context.distinctId) url.searchParams.set("distinctId", context.distinctId);
5763
5770
  return url.toString();
5764
5771
  }
5765
- var DEFAULT_WEB_URL;
5766
5772
  var init_apiUrlUtils = __esm({
5767
5773
  "src/core/apiUrlUtils.ts"() {
5768
5774
  "use strict";
5769
- DEFAULT_WEB_URL = "https://paywallo.com.br";
5775
+ init_constants();
5770
5776
  }
5771
5777
  });
5772
5778
 
@@ -5811,7 +5817,7 @@ async function getVariant(deps, flagKey, distinctId) {
5811
5817
  return persisted;
5812
5818
  }
5813
5819
  try {
5814
- const res = await deps.get(`/api/v1/flags/${flagKey}?distinctId=${encodeURIComponent(distinctId)}`);
5820
+ const res = await deps.get(`/sdk/flags/${flagKey}?distinctId=${encodeURIComponent(distinctId)}`);
5815
5821
  if (res.status === 404) {
5816
5822
  const v = { variant: null };
5817
5823
  deps.cache.setVariant(key, v, deps.cache.nullTTL);
@@ -5832,7 +5838,7 @@ async function getVariant(deps, flagKey, distinctId) {
5832
5838
  async function evaluateFlags(deps, keys, distinctId) {
5833
5839
  const query = keys.map(encodeURIComponent).join(",");
5834
5840
  try {
5835
- const res = await deps.httpClient.get(`/api/v1/flags/evaluate?keys=${query}`, {
5841
+ const res = await deps.httpClient.get(`/sdk/flags/evaluate?keys=${query}`, {
5836
5842
  headers: { "X-App-Key": deps.appKey, "x-distinct-id": distinctId }
5837
5843
  });
5838
5844
  if (!res.ok || typeof res.data !== "object" || res.data === null || Array.isArray(res.data)) return {};
@@ -5883,7 +5889,7 @@ var init_ApiClientFlags = __esm({
5883
5889
  // src/domains/iap/apiPurchaseMethods.ts
5884
5890
  async function validatePurchase(client, appKey, platform, receipt, productId, transactionId, priceLocal, currency, country, distinctId, paywallPlacement, variantKey) {
5885
5891
  const response = await client.post(
5886
- `/purchases/validate`,
5892
+ `/sdk/purchases/validate`,
5887
5893
  {
5888
5894
  platform,
5889
5895
  receipt,
@@ -5909,7 +5915,7 @@ async function validatePurchase(client, appKey, platform, receipt, productId, tr
5909
5915
  return response.data;
5910
5916
  }
5911
5917
  async function getSubscriptionStatus(client, baseUrl, appKey, distinctId) {
5912
- const url = new URL(`${baseUrl}/purchases/status`);
5918
+ const url = new URL(`${baseUrl}/sdk/purchases/status`);
5913
5919
  url.searchParams.set("distinctId", distinctId);
5914
5920
  const response = await client.get(url.toString());
5915
5921
  if (!response.ok) {
@@ -5919,7 +5925,7 @@ async function getSubscriptionStatus(client, baseUrl, appKey, distinctId) {
5919
5925
  }
5920
5926
  async function getEmergencyPaywall(client) {
5921
5927
  try {
5922
- const response = await client.get("/api/v1/emergency-paywall");
5928
+ const response = await client.get("/emergency-paywall");
5923
5929
  if (response.status === 404) return { enabled: false };
5924
5930
  return response.data;
5925
5931
  } catch {
@@ -5927,7 +5933,7 @@ async function getEmergencyPaywall(client) {
5927
5933
  }
5928
5934
  }
5929
5935
  async function getCampaignData(client, baseUrl, placement, distinctId, context) {
5930
- const url = new URL(`${baseUrl}/api/v1/campaigns/${placement}`);
5936
+ const url = new URL(`${baseUrl}/sdk/campaigns/${placement}`);
5931
5937
  url.searchParams.set("distinctId", distinctId);
5932
5938
  if (context) url.searchParams.set("context", JSON.stringify(context));
5933
5939
  const response = await client.get(url.toString());
@@ -6417,7 +6423,7 @@ var init_events = __esm({
6417
6423
 
6418
6424
  // src/core/eventEnvelopeV2.ts
6419
6425
  import { z as z2 } from "zod";
6420
- import { Platform as Platform10 } from "react-native";
6426
+ import { Platform as Platform12 } from "react-native";
6421
6427
  function buildV2Envelope(events, providerContext) {
6422
6428
  const context = { ...providerContext };
6423
6429
  const v2Events = events.map((event) => {
@@ -6440,7 +6446,7 @@ function buildV2Envelope(events, providerContext) {
6440
6446
  };
6441
6447
  });
6442
6448
  if (context.sdk_version === void 0) context.sdk_version = SDK_VERSION;
6443
- if (context.platform === void 0) context.platform = Platform10.OS;
6449
+ if (context.platform === void 0) context.platform = Platform12.OS;
6444
6450
  if (context.distinct_id === void 0 && events.length > 0) {
6445
6451
  context.distinct_id = events[0].distinctId;
6446
6452
  }
@@ -6526,7 +6532,7 @@ var init_eventEnvelopeV2 = __esm({
6526
6532
  });
6527
6533
 
6528
6534
  // src/core/EventBatcher.ts
6529
- import { Platform as Platform11 } from "react-native";
6535
+ import { Platform as Platform13 } from "react-native";
6530
6536
  var BATCH_MAX_SIZE, BATCH_FLUSH_MS, EVENT_NAME_REGEX, V2_BATCH_ENDPOINT, V1_BATCH_ENDPOINT, V1_SINGLE_ENDPOINT, EventBatcher;
6531
6537
  var init_EventBatcher = __esm({
6532
6538
  "src/core/EventBatcher.ts"() {
@@ -6536,9 +6542,9 @@ var init_EventBatcher = __esm({
6536
6542
  BATCH_MAX_SIZE = 25;
6537
6543
  BATCH_FLUSH_MS = 1e4;
6538
6544
  EVENT_NAME_REGEX = /^(\$[a-zA-Z0-9_]+|[a-z][a-z0-9_]*)$/;
6539
- V2_BATCH_ENDPOINT = "/api/v2/ingest/batch";
6540
- V1_BATCH_ENDPOINT = "/api/v1/events/batch";
6541
- V1_SINGLE_ENDPOINT = "/api/v1/events";
6545
+ V2_BATCH_ENDPOINT = "/ingest/batch";
6546
+ V1_BATCH_ENDPOINT = "/sdk/events/batch";
6547
+ V1_SINGLE_ENDPOINT = "/sdk/events";
6542
6548
  EventBatcher = class {
6543
6549
  constructor(post, debug = false, contextProvider = null) {
6544
6550
  this.criticalQueue = [];
@@ -6582,7 +6588,7 @@ var init_EventBatcher = __esm({
6582
6588
  const event = {
6583
6589
  eventName,
6584
6590
  distinctId,
6585
- properties: { ...properties, platform: Platform11.OS },
6591
+ properties: { ...properties, platform: Platform13.OS },
6586
6592
  timestamp: timestamp ?? Date.now(),
6587
6593
  environment: environment.toLowerCase()
6588
6594
  };
@@ -6665,8 +6671,8 @@ var init_EventBatcher = __esm({
6665
6671
  }
6666
6672
  }
6667
6673
  /**
6668
- * POST the batch with V2 envelope semantics. Tries `/api/v2/ingest/batch`
6669
- * first; on failure (404/network) falls back to `/api/v1/events/batch`
6674
+ * POST the batch with V2 envelope semantics. Tries `/ingest/batch`
6675
+ * first; on failure (404/network) falls back to `/events/batch`
6670
6676
  * with the legacy per-event shape for retrocompat.
6671
6677
  *
6672
6678
  * After a single V2 failure we flip `v2Disabled` and stop trying V2 for
@@ -6696,7 +6702,7 @@ var init_EventBatcher = __esm({
6696
6702
  this.v2Disabled = true;
6697
6703
  if (this.debug) {
6698
6704
  console.log(
6699
- `[Paywallo EVENTS] V2 ingest unavailable, falling back to /api/v1/events/batch:`,
6705
+ `[Paywallo EVENTS] V2 ingest unavailable, falling back to /events/batch:`,
6700
6706
  error
6701
6707
  );
6702
6708
  }
@@ -6749,7 +6755,7 @@ var init_ApiClientQueue = __esm({
6749
6755
  });
6750
6756
 
6751
6757
  // src/core/ApiClient.ts
6752
- import { Platform as Platform12 } from "react-native";
6758
+ import { Platform as Platform14 } from "react-native";
6753
6759
  var ApiClient;
6754
6760
  var init_ApiClient = __esm({
6755
6761
  "src/core/ApiClient.ts"() {
@@ -6855,7 +6861,7 @@ var init_ApiClient = __esm({
6855
6861
  buildSdkHeaders() {
6856
6862
  return {
6857
6863
  "x-sdk-version": SDK_VERSION,
6858
- "x-sdk-platform": Platform12.OS,
6864
+ "x-sdk-platform": Platform14.OS,
6859
6865
  "x-sdk-environment": this.environment
6860
6866
  };
6861
6867
  }
@@ -6880,12 +6886,12 @@ var init_ApiClient = __esm({
6880
6886
  }
6881
6887
  async reportError(errorType, message, context) {
6882
6888
  try {
6883
- await this.post("/api/v1/sdk/errors", {
6889
+ await this.post("/sdk/errors", {
6884
6890
  errorType,
6885
6891
  message,
6886
6892
  context,
6887
6893
  sdkVersion: SDK_VERSION,
6888
- platform: Platform12.OS
6894
+ platform: Platform14.OS
6889
6895
  }, true);
6890
6896
  } catch (err) {
6891
6897
  if (this.debug) console.log("[Paywallo:ApiClient] reportError failed", err);
@@ -6908,8 +6914,8 @@ var init_ApiClient = __esm({
6908
6914
  isDebug: () => this.debug,
6909
6915
  post: (path, body, skipRetry) => this.post(path, body, skipRetry)
6910
6916
  },
6911
- "/api/v1/identify",
6912
- { distinctId, properties: properties ?? {}, email, platform: Platform12.OS, ...deviceId && { deviceId } },
6917
+ "/identify",
6918
+ { distinctId, properties: properties ?? {}, email, platform: Platform14.OS, ...deviceId && { deviceId } },
6913
6919
  "identify"
6914
6920
  );
6915
6921
  }
@@ -6924,7 +6930,7 @@ var init_ApiClient = __esm({
6924
6930
  const hit = this.cache.getPaywall(placement);
6925
6931
  if (hit !== void 0) return hit;
6926
6932
  try {
6927
- const res = await this.get(`/api/v1/paywalls/${placement}`);
6933
+ const res = await this.get(`/sdk/paywalls/${placement}`);
6928
6934
  if (res.status === 404) {
6929
6935
  this.cache.setPaywall(placement, null, this.cache.nullTTL);
6930
6936
  return null;
@@ -7260,7 +7266,6 @@ function setupAutoPreload(state, apiClient, config, distinctId) {
7260
7266
  return null;
7261
7267
  }).catch(() => null);
7262
7268
  }
7263
- var DEFAULT_API_URL;
7264
7269
  var init_PaywalloInitHelpers = __esm({
7265
7270
  "src/core/PaywalloInitHelpers.ts"() {
7266
7271
  "use strict";
@@ -7268,7 +7273,7 @@ var init_PaywalloInitHelpers = __esm({
7268
7273
  init_identity();
7269
7274
  init_notifications();
7270
7275
  init_SecureStorage();
7271
- DEFAULT_API_URL = "https://paywallo.com.br";
7276
+ init_constants();
7272
7277
  }
7273
7278
  });
7274
7279
 
@@ -7317,7 +7322,7 @@ function reportInitFailure(state, config, error, reason) {
7317
7322
  try {
7318
7323
  const tempClient = new ApiClient(
7319
7324
  config.appKey,
7320
- config.apiUrl ?? DEFAULT_API_URL2,
7325
+ config.apiUrl ?? DEFAULT_API_URL,
7321
7326
  config.debug
7322
7327
  );
7323
7328
  void tempClient.reportError("INIT_FAILED", reason, {
@@ -7361,7 +7366,7 @@ async function doInit(state, config) {
7361
7366
  ]);
7362
7367
  const apiClient = new ApiClient(
7363
7368
  config.appKey,
7364
- config.apiUrl ?? DEFAULT_API_URL2,
7369
+ config.apiUrl ?? DEFAULT_API_URL,
7365
7370
  config.debug,
7366
7371
  environment,
7367
7372
  offlineQueueEnabled,
@@ -7467,7 +7472,6 @@ async function doInit(state, config) {
7467
7472
  }
7468
7473
  setupAutoPreload(state, apiClient, config, distinctId);
7469
7474
  }
7470
- var DEFAULT_API_URL2;
7471
7475
  var init_PaywalloInitializer = __esm({
7472
7476
  "src/core/PaywalloInitializer.ts"() {
7473
7477
  "use strict";
@@ -7486,7 +7490,7 @@ var init_PaywalloInitializer = __esm({
7486
7490
  init_eventPipelineBridge();
7487
7491
  init_PaywalloState();
7488
7492
  init_PaywalloInitHelpers();
7489
- DEFAULT_API_URL2 = "https://paywallo.com.br";
7493
+ init_constants();
7490
7494
  }
7491
7495
  });
7492
7496