@virex-tech/paywallo-sdk 1.0.1 → 1.1.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.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +190 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +190 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -246,7 +246,6 @@ interface RestoreResult {
|
|
|
246
246
|
type Environment = "Production" | "Sandbox";
|
|
247
247
|
interface ApiClientConfig {
|
|
248
248
|
appKey: string;
|
|
249
|
-
baseUrl?: string;
|
|
250
249
|
debug?: boolean;
|
|
251
250
|
environment?: Environment;
|
|
252
251
|
offlineQueueEnabled?: boolean;
|
|
@@ -254,7 +253,6 @@ interface ApiClientConfig {
|
|
|
254
253
|
}
|
|
255
254
|
interface PaywalloConfig {
|
|
256
255
|
appKey: string;
|
|
257
|
-
baseUrl?: string;
|
|
258
256
|
debug?: boolean;
|
|
259
257
|
environment?: Environment;
|
|
260
258
|
}
|
|
@@ -459,7 +457,7 @@ declare class ApiClient {
|
|
|
459
457
|
private offlineQueueEnabled;
|
|
460
458
|
private httpClient;
|
|
461
459
|
private readonly cache;
|
|
462
|
-
constructor(appKey: string,
|
|
460
|
+
constructor(appKey: string, debug?: boolean, environment?: Environment, offlineQueueEnabled?: boolean, timeout?: number);
|
|
463
461
|
/** Exposed only for QueueProcessor initialization. Prefer get()/post() for requests. */
|
|
464
462
|
getHttpClient(): HttpClient;
|
|
465
463
|
getWebUrl(): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -246,7 +246,6 @@ interface RestoreResult {
|
|
|
246
246
|
type Environment = "Production" | "Sandbox";
|
|
247
247
|
interface ApiClientConfig {
|
|
248
248
|
appKey: string;
|
|
249
|
-
baseUrl?: string;
|
|
250
249
|
debug?: boolean;
|
|
251
250
|
environment?: Environment;
|
|
252
251
|
offlineQueueEnabled?: boolean;
|
|
@@ -254,7 +253,6 @@ interface ApiClientConfig {
|
|
|
254
253
|
}
|
|
255
254
|
interface PaywalloConfig {
|
|
256
255
|
appKey: string;
|
|
257
|
-
baseUrl?: string;
|
|
258
256
|
debug?: boolean;
|
|
259
257
|
environment?: Environment;
|
|
260
258
|
}
|
|
@@ -459,7 +457,7 @@ declare class ApiClient {
|
|
|
459
457
|
private offlineQueueEnabled;
|
|
460
458
|
private httpClient;
|
|
461
459
|
private readonly cache;
|
|
462
|
-
constructor(appKey: string,
|
|
460
|
+
constructor(appKey: string, debug?: boolean, environment?: Environment, offlineQueueEnabled?: boolean, timeout?: number);
|
|
463
461
|
/** Exposed only for QueueProcessor initialization. Prefer get()/post() for requests. */
|
|
464
462
|
getHttpClient(): HttpClient;
|
|
465
463
|
getWebUrl(): string;
|
package/dist/index.js
CHANGED
|
@@ -951,6 +951,11 @@ function usePaywallLoader(placement, visible, preloadedConfig, preloadedProducts
|
|
|
951
951
|
const storeProducts = await getIAPService().loadProducts(productIds);
|
|
952
952
|
const map = /* @__PURE__ */ new Map();
|
|
953
953
|
for (const p of storeProducts) map.set(p.productId, p);
|
|
954
|
+
if (PaywalloClient.getConfig()?.debug) {
|
|
955
|
+
for (const [id, p] of map) {
|
|
956
|
+
console.warn(`[Paywallo][CURRENCY-CHECK] product=${id} currency=${p.currency} price="${p.price}" localizedPrice="${p.localizedPrice}" priceValue=${p.priceValue} fallbackUSD=${!p.currency || p.currency === "USD" ? "POSSIBLE" : "NO"}`);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
954
959
|
setProducts(map);
|
|
955
960
|
} catch {
|
|
956
961
|
setProducts(/* @__PURE__ */ new Map());
|
|
@@ -2336,6 +2341,8 @@ var ApiCache = class {
|
|
|
2336
2341
|
constructor() {
|
|
2337
2342
|
this.CACHE_TTL = 3e5;
|
|
2338
2343
|
// 5 minutes
|
|
2344
|
+
this.CACHE_NULL_TTL = 3e4;
|
|
2345
|
+
// 30 seconds — for null/404 variants
|
|
2339
2346
|
this.MAX_SIZE = 200;
|
|
2340
2347
|
this.variantCache = /* @__PURE__ */ new Map();
|
|
2341
2348
|
this.paywallCache = /* @__PURE__ */ new Map();
|
|
@@ -2344,27 +2351,34 @@ var ApiCache = class {
|
|
|
2344
2351
|
getCached(cache, key) {
|
|
2345
2352
|
const entry = cache.get(key);
|
|
2346
2353
|
if (!entry) return void 0;
|
|
2347
|
-
|
|
2354
|
+
const ttl = entry.ttl ?? this.CACHE_TTL;
|
|
2355
|
+
if (Date.now() - entry.ts < ttl) return entry.value;
|
|
2348
2356
|
cache.delete(key);
|
|
2349
2357
|
return void 0;
|
|
2350
2358
|
}
|
|
2351
|
-
setCached(cache, key, value) {
|
|
2352
|
-
|
|
2359
|
+
setCached(cache, key, value, ttlOverride) {
|
|
2360
|
+
const entry = { value, ts: Date.now() };
|
|
2361
|
+
if (ttlOverride !== void 0) entry.ttl = ttlOverride;
|
|
2362
|
+
cache.set(key, entry);
|
|
2353
2363
|
}
|
|
2354
2364
|
evictExpiredEntries(cache) {
|
|
2355
2365
|
if (cache.size <= this.MAX_SIZE) return;
|
|
2356
2366
|
const now = Date.now();
|
|
2357
2367
|
for (const [key, entry] of cache) {
|
|
2358
|
-
|
|
2368
|
+
const ttl = entry.ttl ?? this.CACHE_TTL;
|
|
2369
|
+
if (now - entry.ts > ttl) cache.delete(key);
|
|
2359
2370
|
}
|
|
2360
2371
|
}
|
|
2361
2372
|
getVariant(key) {
|
|
2362
2373
|
return this.getCached(this.variantCache, key);
|
|
2363
2374
|
}
|
|
2364
|
-
setVariant(key, value) {
|
|
2365
|
-
this.setCached(this.variantCache, key, value);
|
|
2375
|
+
setVariant(key, value, ttlOverride) {
|
|
2376
|
+
this.setCached(this.variantCache, key, value, ttlOverride);
|
|
2366
2377
|
this.evictExpiredEntries(this.variantCache);
|
|
2367
2378
|
}
|
|
2379
|
+
get nullTTL() {
|
|
2380
|
+
return this.CACHE_NULL_TTL;
|
|
2381
|
+
}
|
|
2368
2382
|
getStaleVariant(key) {
|
|
2369
2383
|
const entry = this.variantCache.get(key);
|
|
2370
2384
|
if (entry && Date.now() - entry.ts < 864e5) return entry.value;
|
|
@@ -2373,8 +2387,8 @@ var ApiCache = class {
|
|
|
2373
2387
|
getPaywall(key) {
|
|
2374
2388
|
return this.getCached(this.paywallCache, key);
|
|
2375
2389
|
}
|
|
2376
|
-
setPaywall(key, value) {
|
|
2377
|
-
this.setCached(this.paywallCache, key, value);
|
|
2390
|
+
setPaywall(key, value, ttlOverride) {
|
|
2391
|
+
this.setCached(this.paywallCache, key, value, ttlOverride);
|
|
2378
2392
|
this.evictExpiredEntries(this.paywallCache);
|
|
2379
2393
|
}
|
|
2380
2394
|
getStalePaywall(key) {
|
|
@@ -2400,10 +2414,10 @@ var ApiCache = class {
|
|
|
2400
2414
|
var SDK_VERSION = "1.0.0";
|
|
2401
2415
|
var DEFAULT_BASE_URL = "https://panel.lucasqueiroga.shop";
|
|
2402
2416
|
var ApiClient = class {
|
|
2403
|
-
constructor(appKey,
|
|
2417
|
+
constructor(appKey, debug = false, environment = "Production", offlineQueueEnabled = true, timeout = 3e4) {
|
|
2404
2418
|
this.cache = new ApiCache();
|
|
2405
2419
|
this.appKey = appKey;
|
|
2406
|
-
this.baseUrl =
|
|
2420
|
+
this.baseUrl = DEFAULT_BASE_URL;
|
|
2407
2421
|
this.webUrl = deriveWebUrl(this.baseUrl);
|
|
2408
2422
|
this.debug = debug;
|
|
2409
2423
|
this.environment = environment;
|
|
@@ -2490,14 +2504,18 @@ var ApiClient = class {
|
|
|
2490
2504
|
const hit = this.cache.getVariant(key);
|
|
2491
2505
|
if (hit !== void 0) return hit;
|
|
2492
2506
|
try {
|
|
2493
|
-
const
|
|
2494
|
-
url.searchParams.set("distinctId", distinctId);
|
|
2495
|
-
const res = await this.get(url.toString());
|
|
2507
|
+
const res = await this.get(`/api/v1/flags/${flagKey}?distinctId=${encodeURIComponent(distinctId)}`);
|
|
2496
2508
|
if (res.status === 404) {
|
|
2497
2509
|
const v = { variant: null };
|
|
2498
|
-
this.cache.setVariant(key, v);
|
|
2510
|
+
this.cache.setVariant(key, v, this.cache.nullTTL);
|
|
2499
2511
|
return v;
|
|
2500
2512
|
}
|
|
2513
|
+
if (!res.ok) {
|
|
2514
|
+
this.log("Non-OK response for variant:", flagKey, res.status);
|
|
2515
|
+
const stale = this.cache.getStaleVariant(key);
|
|
2516
|
+
if (stale !== void 0) return stale;
|
|
2517
|
+
return { variant: null };
|
|
2518
|
+
}
|
|
2501
2519
|
this.cache.setVariant(key, res.data);
|
|
2502
2520
|
return res.data;
|
|
2503
2521
|
} catch (error) {
|
|
@@ -2513,7 +2531,13 @@ var ApiClient = class {
|
|
|
2513
2531
|
try {
|
|
2514
2532
|
const res = await this.get(`/api/v1/paywalls/${placement}`);
|
|
2515
2533
|
if (res.status === 404) {
|
|
2516
|
-
this.cache.setPaywall(placement, null);
|
|
2534
|
+
this.cache.setPaywall(placement, null, this.cache.nullTTL);
|
|
2535
|
+
return null;
|
|
2536
|
+
}
|
|
2537
|
+
if (!res.ok) {
|
|
2538
|
+
this.log("Non-OK response for paywall:", placement, res.status);
|
|
2539
|
+
const stale = this.cache.getStalePaywall(placement);
|
|
2540
|
+
if (stale !== void 0) return stale;
|
|
2517
2541
|
return null;
|
|
2518
2542
|
}
|
|
2519
2543
|
this.cache.setPaywall(placement, res.data);
|
|
@@ -2579,6 +2603,10 @@ var ApiClient = class {
|
|
|
2579
2603
|
const url = buildConditionalFlagUrl(this.baseUrl, flagKey, context);
|
|
2580
2604
|
const response = await this.get(url);
|
|
2581
2605
|
if (response.status === 404) return { value: false, flagKey };
|
|
2606
|
+
if (!response.ok) {
|
|
2607
|
+
this.log("Non-OK response for conditional flag:", flagKey, response.status);
|
|
2608
|
+
return { value: false, flagKey };
|
|
2609
|
+
}
|
|
2582
2610
|
this.log("Got conditional flag:", flagKey, response.data.value);
|
|
2583
2611
|
return { value: response.data.value, flagKey };
|
|
2584
2612
|
} catch {
|
|
@@ -3099,6 +3127,13 @@ var InstallTracker = class {
|
|
|
3099
3127
|
const storage = new SecureStorage(this.debug);
|
|
3100
3128
|
const alreadyTracked = await storage.get("install_tracked");
|
|
3101
3129
|
if (alreadyTracked) return;
|
|
3130
|
+
let fallbackTracked = null;
|
|
3131
|
+
try {
|
|
3132
|
+
const AsyncStorage3 = (await import("@react-native-async-storage/async-storage")).default;
|
|
3133
|
+
fallbackTracked = await AsyncStorage3.getItem("@paywallo:install_tracked");
|
|
3134
|
+
} catch {
|
|
3135
|
+
}
|
|
3136
|
+
if (fallbackTracked) return;
|
|
3102
3137
|
const distinctId = identityManager.getDistinctId();
|
|
3103
3138
|
const sessionId = sessionManager.getSessionId();
|
|
3104
3139
|
const installedAt = Date.now();
|
|
@@ -3160,6 +3195,11 @@ var InstallTracker = class {
|
|
|
3160
3195
|
attStatus: adIds.attStatus
|
|
3161
3196
|
});
|
|
3162
3197
|
const stored = await storage.set("install_tracked", String(installedAt));
|
|
3198
|
+
try {
|
|
3199
|
+
const AsyncStorage3 = (await import("@react-native-async-storage/async-storage")).default;
|
|
3200
|
+
await AsyncStorage3.setItem("@paywallo:install_tracked", String(installedAt));
|
|
3201
|
+
} catch {
|
|
3202
|
+
}
|
|
3163
3203
|
if (this.debug && !stored) {
|
|
3164
3204
|
console.warn("[Paywallo] Install event tracked but flag storage failed \u2014 may re-track on next launch");
|
|
3165
3205
|
}
|
|
@@ -3176,7 +3216,7 @@ function isValidEventName(name) {
|
|
|
3176
3216
|
if (name.startsWith("$")) return /^\$[a-z][a-z0-9]*(_[a-z0-9]+)*$/.test(name);
|
|
3177
3217
|
return /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/.test(name);
|
|
3178
3218
|
}
|
|
3179
|
-
var
|
|
3219
|
+
var _PaywalloClientClass = class _PaywalloClientClass {
|
|
3180
3220
|
constructor() {
|
|
3181
3221
|
this.config = null;
|
|
3182
3222
|
this.apiClient = null;
|
|
@@ -3187,45 +3227,121 @@ var PaywalloClientClass = class {
|
|
|
3187
3227
|
this.activeChecker = null;
|
|
3188
3228
|
this.restoreHandler = null;
|
|
3189
3229
|
this.lastOnboardingStepTimestamp = null;
|
|
3230
|
+
this.pendingConfig = null;
|
|
3231
|
+
this.networkCleanup = null;
|
|
3232
|
+
this.initAttempts = 0;
|
|
3190
3233
|
}
|
|
3191
3234
|
async init(config) {
|
|
3192
|
-
|
|
3235
|
+
console.warn("[Paywallo INIT]", "init() called \u2014 appKey:", config.appKey ? config.appKey.substring(0, 8) + "..." : "MISSING");
|
|
3236
|
+
if (this.config && this.apiClient) {
|
|
3237
|
+
console.warn("[Paywallo INIT]", "Already initialized \u2014 skipping");
|
|
3238
|
+
return;
|
|
3239
|
+
}
|
|
3193
3240
|
if (this.initPromise) {
|
|
3241
|
+
console.warn("[Paywallo INIT]", "Init already in progress \u2014 awaiting...");
|
|
3194
3242
|
await this.initPromise;
|
|
3243
|
+
console.warn("[Paywallo INIT]", "Awaited existing init \u2014 done");
|
|
3195
3244
|
return;
|
|
3196
3245
|
}
|
|
3197
3246
|
if (!config.appKey) throw new ClientError(CLIENT_ERROR_CODES.MISSING_APP_KEY, "appKey is required");
|
|
3198
|
-
|
|
3247
|
+
console.warn("[Paywallo INIT]", "Starting fresh init...");
|
|
3248
|
+
this.pendingConfig = config;
|
|
3249
|
+
this.initAttempts = 0;
|
|
3250
|
+
this.initPromise = this.initWithRetry(config);
|
|
3199
3251
|
try {
|
|
3200
3252
|
await this.initPromise;
|
|
3253
|
+
console.warn("[Paywallo INIT]", "init() SUCCESS");
|
|
3201
3254
|
} catch (error) {
|
|
3255
|
+
console.warn("[Paywallo INIT]", "init() FAILED:", error instanceof Error ? error.message : String(error));
|
|
3202
3256
|
this.initPromise = null;
|
|
3203
3257
|
this.config = null;
|
|
3204
3258
|
this.apiClient = null;
|
|
3259
|
+
this.reportInitFailure(config, error, "ALL_RETRIES_EXHAUSTED");
|
|
3260
|
+
this.setupNetworkRecovery(config);
|
|
3261
|
+
throw error;
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
async initWithRetry(config) {
|
|
3265
|
+
while (this.initAttempts <= _PaywalloClientClass.MAX_INIT_RETRIES) {
|
|
3205
3266
|
try {
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3267
|
+
await this.doInit(config);
|
|
3268
|
+
if (this.initAttempts > 0) {
|
|
3269
|
+
this.reportInitSuccess(config, this.initAttempts);
|
|
3270
|
+
}
|
|
3271
|
+
this.cleanupNetworkRecovery();
|
|
3272
|
+
this.pendingConfig = null;
|
|
3273
|
+
return;
|
|
3274
|
+
} catch (error) {
|
|
3275
|
+
this.initAttempts++;
|
|
3276
|
+
if (this.initAttempts > _PaywalloClientClass.MAX_INIT_RETRIES) throw error;
|
|
3277
|
+
const delay = _PaywalloClientClass.RETRY_DELAYS[this.initAttempts - 1] ?? 1e4;
|
|
3278
|
+
if (config.debug) console.warn("[Paywallo]", `Init attempt ${this.initAttempts} failed, retrying in ${delay}ms`, error);
|
|
3279
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
3209
3280
|
}
|
|
3210
|
-
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
setupNetworkRecovery(config) {
|
|
3284
|
+
if (this.networkCleanup) return;
|
|
3285
|
+
if (!networkMonitor.isInitialized()) return;
|
|
3286
|
+
this.networkCleanup = networkMonitor.addListener((state) => {
|
|
3287
|
+
if (state !== "online") return;
|
|
3288
|
+
if (this.config && this.apiClient) return;
|
|
3289
|
+
if (config.debug) console.warn("[Paywallo]", "Network recovered \u2014 retrying init");
|
|
3290
|
+
this.initPromise = this.initWithRetry(config);
|
|
3291
|
+
this.initPromise.then(() => {
|
|
3292
|
+
if (config.debug) console.warn("[Paywallo]", "Init succeeded after network recovery");
|
|
3293
|
+
}).catch(() => {
|
|
3294
|
+
this.reportInitFailure(config, null, "NETWORK_RECOVERY_FAILED");
|
|
3295
|
+
});
|
|
3296
|
+
});
|
|
3297
|
+
}
|
|
3298
|
+
cleanupNetworkRecovery() {
|
|
3299
|
+
if (this.networkCleanup) {
|
|
3300
|
+
this.networkCleanup();
|
|
3301
|
+
this.networkCleanup = null;
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
reportInitFailure(config, error, reason) {
|
|
3305
|
+
try {
|
|
3306
|
+
const tempClient = new ApiClient(config.appKey, config.debug);
|
|
3307
|
+
void tempClient.reportError("INIT_FAILED", reason, {
|
|
3308
|
+
attempts: this.initAttempts,
|
|
3309
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3310
|
+
});
|
|
3311
|
+
} catch {
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
reportInitSuccess(config, attempts) {
|
|
3315
|
+
try {
|
|
3316
|
+
if (this.apiClient) {
|
|
3317
|
+
void this.apiClient.reportError("INIT_RECOVERED", `Succeeded after ${attempts} retries`, { attempts });
|
|
3318
|
+
}
|
|
3319
|
+
} catch {
|
|
3211
3320
|
}
|
|
3212
3321
|
}
|
|
3213
3322
|
async doInit(config) {
|
|
3214
3323
|
const environment = config.environment ?? (typeof __DEV__ !== "undefined" && __DEV__ ? "Sandbox" : "Production");
|
|
3215
3324
|
const offlineQueueEnabled = config.offlineQueueEnabled !== false;
|
|
3325
|
+
console.warn("[Paywallo INIT]", "Step 1: networkMonitor + offlineQueue...");
|
|
3216
3326
|
await Promise.all([
|
|
3217
3327
|
networkMonitor.initialize({ debug: config.debug }),
|
|
3218
3328
|
offlineQueue.initialize({ debug: config.debug }).then(
|
|
3219
3329
|
() => offlineQueue.clearItemsWithInvalidAppKey(config.appKey)
|
|
3220
3330
|
)
|
|
3221
3331
|
]);
|
|
3222
|
-
|
|
3332
|
+
console.warn("[Paywallo INIT]", "Step 1 DONE");
|
|
3333
|
+
console.warn("[Paywallo INIT]", "Step 2: ApiClient + queueProcessor + affiliate...");
|
|
3334
|
+
this.apiClient = new ApiClient(config.appKey, config.debug, environment, offlineQueueEnabled, config.timeout);
|
|
3223
3335
|
queueProcessor.initialize(this.apiClient.getHttpClient(), { debug: config.debug });
|
|
3224
3336
|
affiliateManager.initialize(this.apiClient, config.debug);
|
|
3337
|
+
console.warn("[Paywallo INIT]", "Step 2 DONE");
|
|
3338
|
+
console.warn("[Paywallo INIT]", "Step 3: identityManager + sessionManager...");
|
|
3225
3339
|
await Promise.all([
|
|
3226
3340
|
identityManager.initialize(this.apiClient, config.debug),
|
|
3227
3341
|
sessionManager.initialize(this.apiClient, config.sessionConfig, config.debug)
|
|
3228
3342
|
]);
|
|
3343
|
+
const distinctId = identityManager.getDistinctId();
|
|
3344
|
+
console.warn("[Paywallo INIT]", "Step 3 DONE \u2014 distinctId:", distinctId ? distinctId.substring(0, 8) + "..." : "EMPTY");
|
|
3229
3345
|
if (config.autoStartSession !== false) {
|
|
3230
3346
|
sessionManager.startSession().catch(() => {
|
|
3231
3347
|
if (config.debug) console.warn("[Paywallo]", "Session start failed during init \u2014 continuing");
|
|
@@ -3234,6 +3350,7 @@ var PaywalloClientClass = class {
|
|
|
3234
3350
|
new InstallTracker(config.debug).trackIfNeeded(this.apiClient, config.requestATT === true).catch(() => {
|
|
3235
3351
|
});
|
|
3236
3352
|
this.config = config;
|
|
3353
|
+
console.warn("[Paywallo INIT]", "COMPLETE \u2014 SDK ready, environment:", environment);
|
|
3237
3354
|
}
|
|
3238
3355
|
async identify(options) {
|
|
3239
3356
|
this.ensureInitialized();
|
|
@@ -3243,7 +3360,7 @@ var PaywalloClientClass = class {
|
|
|
3243
3360
|
const apiClient = this.getApiClientOrThrow();
|
|
3244
3361
|
const distinctId = identityManager.getDistinctId();
|
|
3245
3362
|
if (!distinctId) {
|
|
3246
|
-
|
|
3363
|
+
console.warn("[Paywallo TRACK]", "SKIPPED \u2014 no distinctId", eventName);
|
|
3247
3364
|
return;
|
|
3248
3365
|
}
|
|
3249
3366
|
if (!isValidEventName(eventName)) {
|
|
@@ -3251,6 +3368,25 @@ var PaywalloClientClass = class {
|
|
|
3251
3368
|
throw new ClientError(CLIENT_ERROR_CODES.INVALID_EVENT_NAME, msg);
|
|
3252
3369
|
}
|
|
3253
3370
|
const sessionId = sessionManager.getSessionId();
|
|
3371
|
+
if (eventName === "$purchase_completed") {
|
|
3372
|
+
console.warn("[Paywallo PURCHASE]", "tracking purchase:", JSON.stringify({
|
|
3373
|
+
distinctId: distinctId.substring(0, 8) + "...",
|
|
3374
|
+
productId: options?.properties?.productId,
|
|
3375
|
+
priceUsd: options?.properties?.priceUsd,
|
|
3376
|
+
price: options?.properties?.price,
|
|
3377
|
+
currency: options?.properties?.currency,
|
|
3378
|
+
placement: options?.properties?.placement
|
|
3379
|
+
}));
|
|
3380
|
+
} else if (eventName === "$paywall_viewed" || eventName === "$paywall_closed") {
|
|
3381
|
+
console.warn("[Paywallo PAYWALL]", eventName, JSON.stringify({
|
|
3382
|
+
distinctId: distinctId.substring(0, 8) + "...",
|
|
3383
|
+
placement: options?.properties?.placement,
|
|
3384
|
+
variantKey: options?.properties?.variantKey,
|
|
3385
|
+
timeOnPaywall: options?.properties?.timeOnPaywall
|
|
3386
|
+
}));
|
|
3387
|
+
} else {
|
|
3388
|
+
console.warn("[Paywallo TRACK]", eventName, "distinctId:", distinctId.substring(0, 8) + "...");
|
|
3389
|
+
}
|
|
3254
3390
|
await apiClient.trackEvent(eventName, distinctId, {
|
|
3255
3391
|
...identityManager.getProperties(),
|
|
3256
3392
|
...options?.properties,
|
|
@@ -3301,15 +3437,32 @@ var PaywalloClientClass = class {
|
|
|
3301
3437
|
});
|
|
3302
3438
|
}
|
|
3303
3439
|
async getVariant(flagKey) {
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3440
|
+
try {
|
|
3441
|
+
const distinctId = identityManager.getDistinctId();
|
|
3442
|
+
if (!distinctId) {
|
|
3443
|
+
console.warn("[Paywallo AB]", "getVariant SKIPPED \u2014 no distinctId", flagKey);
|
|
3444
|
+
return { variant: null };
|
|
3445
|
+
}
|
|
3446
|
+
const result = await this.getApiClientOrThrow().getVariant(flagKey, distinctId);
|
|
3447
|
+
console.warn("[Paywallo AB]", `getVariant("${flagKey}") =`, result.variant);
|
|
3448
|
+
return result;
|
|
3449
|
+
} catch (error) {
|
|
3450
|
+
if (this.config?.debug) console.warn("[Paywallo]", "getVariant failed \u2014 returning null", error);
|
|
3451
|
+
if (this.apiClient) void this.apiClient.reportError("GET_VARIANT_FAILED", error instanceof Error ? error.message : String(error));
|
|
3452
|
+
return { variant: null };
|
|
3453
|
+
}
|
|
3307
3454
|
}
|
|
3308
3455
|
async getConditionalFlag(flagKey, context) {
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3456
|
+
try {
|
|
3457
|
+
const distinctId = identityManager.getDistinctId();
|
|
3458
|
+
if (!distinctId) return false;
|
|
3459
|
+
const result = await this.getApiClientOrThrow().getConditionalFlag(flagKey, { distinctId, ...context });
|
|
3460
|
+
return result.value;
|
|
3461
|
+
} catch (error) {
|
|
3462
|
+
if (this.config?.debug) console.warn("[Paywallo]", "getConditionalFlag failed \u2014 returning false", error);
|
|
3463
|
+
if (this.apiClient) void this.apiClient.reportError("GET_CONDITIONAL_FLAG_FAILED", error instanceof Error ? error.message : String(error));
|
|
3464
|
+
return false;
|
|
3465
|
+
}
|
|
3313
3466
|
}
|
|
3314
3467
|
async getPaywall(placement) {
|
|
3315
3468
|
return this.getApiClientOrThrow().getPaywall(placement);
|
|
@@ -3369,9 +3522,12 @@ var PaywalloClientClass = class {
|
|
|
3369
3522
|
offlineQueue.dispose();
|
|
3370
3523
|
networkMonitor.dispose();
|
|
3371
3524
|
campaignGateService.clearPreloaded();
|
|
3525
|
+
this.cleanupNetworkRecovery();
|
|
3372
3526
|
this.apiClient = null;
|
|
3373
3527
|
this.config = null;
|
|
3374
3528
|
this.initPromise = null;
|
|
3529
|
+
this.pendingConfig = null;
|
|
3530
|
+
this.initAttempts = 0;
|
|
3375
3531
|
this.paywallPresenter = null;
|
|
3376
3532
|
this.campaignPresenter = null;
|
|
3377
3533
|
this.subscriptionGetter = null;
|
|
@@ -3487,6 +3643,9 @@ var PaywalloClientClass = class {
|
|
|
3487
3643
|
if (!this.config || !this.apiClient) throw new ClientError(CLIENT_ERROR_CODES.NOT_INITIALIZED, "SDK not initialized. Call Paywallo.init() first");
|
|
3488
3644
|
}
|
|
3489
3645
|
};
|
|
3646
|
+
_PaywalloClientClass.MAX_INIT_RETRIES = 3;
|
|
3647
|
+
_PaywalloClientClass.RETRY_DELAYS = [2e3, 5e3, 1e4];
|
|
3648
|
+
var PaywalloClientClass = _PaywalloClientClass;
|
|
3490
3649
|
var PaywalloClient = new PaywalloClientClass();
|
|
3491
3650
|
|
|
3492
3651
|
// src/context/PaywalloContext.ts
|