@virex-tech/paywallo-sdk 1.1.3 → 1.3.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.d.mts CHANGED
@@ -116,6 +116,7 @@ interface ServerProductInfo {
116
116
  }
117
117
  interface CampaignResponse {
118
118
  campaignId: string;
119
+ placement?: string;
119
120
  variantKey: string;
120
121
  paywall: {
121
122
  id: string;
@@ -183,6 +184,31 @@ interface EmergencyPaywallResponse {
183
184
  paywall?: PaywallConfig;
184
185
  }
185
186
 
187
+ declare class PaywalloError extends Error {
188
+ readonly code: string;
189
+ readonly domain: string;
190
+ constructor(domain: string, code: string, message: string);
191
+ }
192
+
193
+ declare class PurchaseError extends PaywalloError {
194
+ readonly userCancelled: boolean;
195
+ constructor(code: string, message: string, userCancelled?: boolean);
196
+ }
197
+ declare const PURCHASE_ERROR_CODES: {
198
+ readonly NOT_INITIALIZED: "PURCHASE_NOT_INITIALIZED";
199
+ readonly PRODUCT_NOT_FOUND: "PRODUCT_NOT_FOUND";
200
+ readonly PURCHASE_FAILED: "PURCHASE_FAILED";
201
+ readonly RESTORE_FAILED: "RESTORE_FAILED";
202
+ readonly VALIDATION_FAILED: "VALIDATION_FAILED";
203
+ readonly USER_CANCELLED: "USER_CANCELLED";
204
+ readonly NETWORK_ERROR: "PURCHASE_NETWORK_ERROR";
205
+ readonly STORE_ERROR: "PURCHASE_STORE_ERROR";
206
+ readonly PENDING_PURCHASE: "PURCHASE_PENDING";
207
+ readonly DEFERRED_PURCHASE: "PURCHASE_DEFERRED";
208
+ readonly STORE_NOT_AVAILABLE: "PURCHASE_STORE_NOT_AVAILABLE";
209
+ };
210
+ declare function createPurchaseError(code: keyof typeof PURCHASE_ERROR_CODES, message?: string): PurchaseError;
211
+
186
212
  interface Product {
187
213
  productId: string;
188
214
  title: string;
@@ -196,6 +222,7 @@ interface Product {
196
222
  introductoryPrice?: string;
197
223
  introductoryPriceValue?: number;
198
224
  freeTrialPeriod?: string;
225
+ trialDays?: number;
199
226
  pricePerMonth?: string;
200
227
  pricePerWeek?: string;
201
228
  pricePerDay?: string;
@@ -212,7 +239,7 @@ interface Purchase {
212
239
  interface PurchaseResult {
213
240
  success: boolean;
214
241
  purchase?: Purchase;
215
- error?: Error;
242
+ error?: PurchaseError;
216
243
  }
217
244
  interface ValidatePurchaseResponse {
218
245
  success: boolean;
@@ -252,10 +279,16 @@ interface ApiClientConfig {
252
279
  offlineQueueEnabled?: boolean;
253
280
  timeout?: number;
254
281
  }
282
+ interface PaywallErrorStrings$1 {
283
+ title?: string;
284
+ retry?: string;
285
+ close?: string;
286
+ }
255
287
  interface PaywalloConfig {
256
288
  appKey: string;
257
289
  debug?: boolean;
258
290
  environment?: Environment;
291
+ errorStrings?: PaywallErrorStrings$1;
259
292
  }
260
293
  interface UserProperties {
261
294
  [key: string]: string | number | boolean | null;
@@ -367,6 +400,7 @@ interface PreloadResult {
367
400
  interface PaywalloContextValue {
368
401
  config: PaywalloConfig | null;
369
402
  isInitialized: boolean;
403
+ isReady: boolean;
370
404
  initError: Error | null;
371
405
  distinctId: string | null;
372
406
  subscription: Subscription | null;
@@ -386,12 +420,6 @@ interface PaywalloContextValue {
386
420
  }
387
421
  declare const PaywalloContext: React.Context<PaywalloContextValue | null>;
388
422
 
389
- declare class PaywalloError extends Error {
390
- readonly code: string;
391
- readonly domain: string;
392
- constructor(domain: string, code: string, message: string);
393
- }
394
-
395
423
  declare class PaywallError extends PaywalloError {
396
424
  constructor(code: string, message: string);
397
425
  }
@@ -459,8 +487,8 @@ declare class ApiClient {
459
487
  private httpClient;
460
488
  private readonly cache;
461
489
  constructor(appKey: string, debug?: boolean, environment?: Environment, offlineQueueEnabled?: boolean, timeout?: number);
462
- /** Exposed only for QueueProcessor initialization. Prefer get()/post() for requests. */
463
490
  getHttpClient(): HttpClient;
491
+ getBaseUrl(): string;
464
492
  getWebUrl(): string;
465
493
  getEnvironment(): Environment;
466
494
  getQueueSize(): number;
@@ -473,7 +501,7 @@ declare class ApiClient {
473
501
  post<T>(path: string, body: unknown, skipRetry?: boolean): Promise<HttpResponse<T>>;
474
502
  reportError(errorType: string, message: string, context?: Record<string, unknown>): Promise<void>;
475
503
  trackEvent(eventName: string, distinctId: string, properties?: UserProperties, timestamp?: number): Promise<void>;
476
- identify(distinctId: string, properties?: UserProperties, email?: string): Promise<void>;
504
+ identify(distinctId: string, properties?: UserProperties, email?: string, deviceId?: string): Promise<void>;
477
505
  startSession(distinctId: string, sessionId: string, platform?: string): Promise<{
478
506
  success: boolean;
479
507
  }>;
@@ -484,23 +512,15 @@ declare class ApiClient {
484
512
  getPaywall(placement: string): Promise<PaywallConfig | null>;
485
513
  getEmergencyPaywall(): Promise<EmergencyPaywallResponse>;
486
514
  getCampaign(placement: string, distinctId: string, context?: Record<string, unknown>): Promise<CampaignResponse | null>;
515
+ getPrimaryCampaign(distinctId: string): Promise<CampaignResponse | null>;
487
516
  validatePurchase(platform: "ios" | "android", receipt: string, productId: string, transactionId: string, priceLocal: number, currency: string, country: string, distinctId?: string, paywallPlacement?: string, variantKey?: string): Promise<ValidatePurchaseResponse>;
488
517
  getSubscriptionStatus(distinctId: string): Promise<SubscriptionStatusResponse$1>;
489
518
  evaluateFlags(keys: string[], distinctId: string): Promise<Record<string, string | null>>;
490
519
  getConditionalFlag(flagKey: string, context: ConditionalFlagContext): Promise<ConditionalFlagResult>;
491
- /**
492
- * Reads a flag variant from cache layers only — no network call.
493
- * Checks in-memory cache first, then SecureStorage.
494
- * Returns null when both layers miss.
495
- */
496
520
  getVariantFromCache(flagKey: string, distinctId: string): Promise<FlagVariant | null>;
497
521
  private static readonly FLAG_MAX_AGE_MS;
498
522
  private readFlagFromStorage;
499
523
  private writeFlagToStorage;
500
- /**
501
- * POST with offline queue fallback. Enqueues when offline or on network failure.
502
- * Throws only when offlineQueueEnabled is false and the request fails.
503
- */
504
524
  private postWithQueue;
505
525
  private log;
506
526
  }
@@ -594,11 +614,13 @@ declare class IAPService {
594
614
  loadProducts(productIds: string[]): Promise<Product[]>;
595
615
  getProduct(productId: string): Product | undefined;
596
616
  getCachedProducts(): Map<string, Product>;
617
+ private validateWithRetry;
597
618
  private validateWithServer;
598
619
  private finishTransaction;
599
620
  purchase(productId: string, options?: {
600
621
  paywallPlacement?: string;
601
622
  variantKey?: string;
623
+ onValidating?: () => void;
602
624
  }): Promise<PurchaseResult>;
603
625
  restore(): Promise<Purchase[]>;
604
626
  }
@@ -613,7 +635,7 @@ declare const nativeStoreKit: {
613
635
  getActiveTransactions(): Promise<Purchase[]>;
614
636
  };
615
637
 
616
- type PurchaseState = "idle" | "loading" | "purchasing" | "restoring" | "error";
638
+ type PurchaseState = "idle" | "loading" | "purchasing" | "validating" | "restoring" | "error";
617
639
  interface IAPProduct {
618
640
  productId: string;
619
641
  price: string;
@@ -630,6 +652,7 @@ interface IAPProduct {
630
652
  introductoryPriceNumberOfPeriodsIOS?: string;
631
653
  introductoryPriceSubscriptionPeriodIOS?: string;
632
654
  freeTrialPeriodAndroid?: string;
655
+ trialDays: number;
633
656
  }
634
657
  interface IAPPurchase {
635
658
  productId: string;
@@ -653,25 +676,6 @@ interface ProductPriceInfo {
653
676
  pricePerDay?: string;
654
677
  }
655
678
 
656
- declare class PurchaseError extends PaywalloError {
657
- readonly userCancelled: boolean;
658
- constructor(code: string, message: string, userCancelled?: boolean);
659
- }
660
- declare const PURCHASE_ERROR_CODES: {
661
- readonly NOT_INITIALIZED: "PURCHASE_NOT_INITIALIZED";
662
- readonly PRODUCT_NOT_FOUND: "PRODUCT_NOT_FOUND";
663
- readonly PURCHASE_FAILED: "PURCHASE_FAILED";
664
- readonly RESTORE_FAILED: "RESTORE_FAILED";
665
- readonly VALIDATION_FAILED: "VALIDATION_FAILED";
666
- readonly USER_CANCELLED: "USER_CANCELLED";
667
- readonly NETWORK_ERROR: "PURCHASE_NETWORK_ERROR";
668
- readonly STORE_ERROR: "PURCHASE_STORE_ERROR";
669
- readonly PENDING_PURCHASE: "PURCHASE_PENDING";
670
- readonly DEFERRED_PURCHASE: "PURCHASE_DEFERRED";
671
- readonly STORE_NOT_AVAILABLE: "PURCHASE_STORE_NOT_AVAILABLE";
672
- };
673
- declare function createPurchaseError(code: keyof typeof PURCHASE_ERROR_CODES, message?: string): PurchaseError;
674
-
675
679
  interface IdentityState {
676
680
  deviceId: string;
677
681
  email: string | null;
@@ -679,6 +683,7 @@ interface IdentityState {
679
683
  }
680
684
  declare class IdentityManager {
681
685
  private deviceId;
686
+ private anonId;
682
687
  private email;
683
688
  private properties;
684
689
  private apiClient;
@@ -697,7 +702,6 @@ declare class IdentityManager {
697
702
  isSecureStorageAvailable(): boolean;
698
703
  private loadPersistedState;
699
704
  private ensureInitialized;
700
- private log;
701
705
  }
702
706
  declare const identityManager: IdentityManager;
703
707
 
@@ -812,16 +816,26 @@ interface PreloadCampaignResult {
812
816
  success: boolean;
813
817
  error?: Error;
814
818
  }
819
+ interface PaywallErrorStrings {
820
+ title?: string;
821
+ retry?: string;
822
+ close?: string;
823
+ }
815
824
  interface PaywalloInitConfig extends PaywalloConfig {
816
825
  sessionConfig?: SessionConfig;
817
826
  autoStartSession?: boolean;
818
827
  offlineQueueEnabled?: boolean;
819
828
  timeout?: number;
820
- /** Request ATT permission during init (iOS only). Default: false. */
821
829
  requestATT?: boolean;
830
+ errorStrings?: PaywallErrorStrings;
831
+ sessionFlags?: string[];
832
+ subscriptionCacheTTL?: number;
833
+ autoPreloadCampaign?: string;
822
834
  }
823
835
  interface IPaywalloClient {
824
836
  init(config: PaywalloInitConfig): Promise<void>;
837
+ isReady(): boolean;
838
+ waitUntilReady(): Promise<void>;
825
839
  identify(options?: IdentifyOptions | UserProperties): Promise<void>;
826
840
  track(eventName: string, options?: TrackEventOptions): Promise<void>;
827
841
  getVariantCached(flagKey: string, defaultValue?: string): Promise<FlagVariant>;
@@ -862,6 +876,7 @@ interface IPaywalloClient {
862
876
  registerActiveChecker(checker: () => Promise<boolean>): void;
863
877
  registerRestoreHandler(handler: () => Promise<RestoreResult>): void;
864
878
  registerEmergencyPaywallHandler(handler: EmergencyPaywallHandler): void;
879
+ getSessionFlag(key: string): string | null;
865
880
  isOnline(): boolean;
866
881
  getOfflineQueueSize(): number;
867
882
  clearOfflineQueue(): Promise<void>;
@@ -871,6 +886,9 @@ interface IPaywalloClient {
871
886
  }>;
872
887
  onboardingStep(index: number, name: string): Promise<void>;
873
888
  coreAction(actionName: string): Promise<void>;
889
+ isPreloaded(placement: string): boolean;
890
+ getAutoPreloadedPlacement(): string | null;
891
+ waitForAutoPreloadedPlacement(): Promise<string | null>;
874
892
  }
875
893
 
876
894
  declare const PaywalloClient: IPaywalloClient;
@@ -913,7 +931,7 @@ declare class OfflineQueueClass {
913
931
  private loadFromStorage;
914
932
  private saveToStorage;
915
933
  private cleanupExpired;
916
- enqueue(method: "POST" | "PUT", url: string, body: unknown, headers?: Record<string, string>): Promise<QueueItem>;
934
+ enqueue(method: "POST" | "PUT", url: string, body: unknown, headers?: Record<string, string>, id?: string): Promise<QueueItem>;
917
935
  private findDuplicateIndex;
918
936
  dequeue(): Promise<QueueItem | null>;
919
937
  removeItem(id: string): Promise<boolean>;
@@ -926,7 +944,6 @@ declare class OfflineQueueClass {
926
944
  processed: number;
927
945
  failed: number;
928
946
  }>;
929
- /** Returns true if the item was permanently removed (counted as failed). */
930
947
  private handleItemFailure;
931
948
  private sleep;
932
949
  getQueue(): ReadonlyArray<QueueItem>;
@@ -1003,6 +1020,7 @@ interface FormattedProduct extends ProductPriceInfo {
1003
1020
  subscriptionPeriod?: string;
1004
1021
  introductoryPrice?: string;
1005
1022
  freeTrialPeriod?: string;
1023
+ trialDays: number;
1006
1024
  }
1007
1025
 
1008
1026
  interface UseProductsResult {
@@ -1017,13 +1035,19 @@ interface UseProductsResult {
1017
1035
  }
1018
1036
  declare function useProducts(initialProductIds?: string[]): UseProductsResult;
1019
1037
 
1038
+ interface PurchaseOutcome {
1039
+ status: "success" | "cancelled" | "failed";
1040
+ purchase?: IAPPurchase;
1041
+ error?: PurchaseError;
1042
+ }
1020
1043
  interface UsePurchaseResult {
1021
1044
  state: PurchaseState;
1022
- purchase: (productId: string) => Promise<IAPPurchase>;
1045
+ purchase: (productId: string) => Promise<PurchaseOutcome>;
1023
1046
  restore: () => Promise<IAPPurchase[]>;
1024
1047
  error: PurchaseError | null;
1025
1048
  isLoading: boolean;
1026
1049
  isPurchasing: boolean;
1050
+ isValidating: boolean;
1027
1051
  isRestoring: boolean;
1028
1052
  }
1029
1053
  declare function usePurchase(): UsePurchaseResult;
@@ -1082,10 +1106,13 @@ declare class SubscriptionCache {
1082
1106
  private ttl;
1083
1107
  private memoryCache;
1084
1108
  private storage;
1109
+ private legacyCleanupDone;
1085
1110
  constructor(ttl?: number);
1086
- get(): Promise<CachedSubscription | null>;
1087
- set(data: SubscriptionStatusResponse): Promise<void>;
1088
- invalidate(): Promise<void>;
1111
+ private cleanupLegacyCache;
1112
+ get(distinctId: string): Promise<CachedSubscription | null>;
1113
+ set(distinctId: string, data: SubscriptionStatusResponse): Promise<void>;
1114
+ invalidate(distinctId: string): Promise<void>;
1115
+ invalidateAll(): Promise<void>;
1089
1116
  private isExpired;
1090
1117
  setTTL(ttl: number): void;
1091
1118
  }
@@ -1097,6 +1124,7 @@ declare class SubscriptionManagerClass {
1097
1124
  private listeners;
1098
1125
  private userId;
1099
1126
  constructor();
1127
+ private cacheKey;
1100
1128
  init(config: SubscriptionManagerConfig): void;
1101
1129
  setUserId(userId: string | null): void;
1102
1130
  hasActiveSubscription(forceRefresh?: boolean): Promise<boolean>;
@@ -1149,4 +1177,4 @@ declare function hasVariables(text: string): boolean;
1149
1177
 
1150
1178
  declare const Paywallo: IPaywalloClient;
1151
1179
 
1152
- export { AFFILIATE_ERROR_CODES, ANALYTICS_ERROR_CODES, type AffiliateBalance, type AffiliateCommission, type AffiliateCoupon, AffiliateError, AffiliateManager, AnalyticsError, ApiClient, type ApiClientConfig, type BlockType, type BoxSpacing, CAMPAIGN_ERROR_CODES, type CachedSubscription, CampaignError, type CampaignPresentOptions, type CampaignResponse, type CampaignResult, type ConditionalFlagContext, type ConditionalFlagResult, PURCHASE_ERROR_CODES as ERROR_CODES, type Environment, type FlagVariant, HttpClient, type HttpClientConfig, type HttpResponse, type IAPProduct, type IAPPurchase, IAPService, IDENTITY_ERROR_CODES, type IPaywalloClient, type IdentifyOptions, IdentityError, IdentityManager, type IdentityState, type LocalizedText, type NetworkListener, type NetworkMonitorConfig, type NetworkState, type OfflineQueueConfig, PAYWALL_ERROR_CODES, PURCHASE_ERROR_CODES, type PaywallBlockConfig, type PaywallConfig, PaywallContext, PaywallError, PaywallModal, type PaywallNode, type PaywallPresentOptions, type PaywallResult, type PaywallState, Paywallo, PaywalloAffiliate, PaywalloClient, type PaywalloConfig, PaywalloContext, PaywalloError, type PaywalloInitConfig, PaywalloProvider, type PreloadCampaignResult, type PreloadResult, type Product, type ProductPriceInfo, type Purchase, type PurchaseControllerConfig, PurchaseError, type PurchaseResult, type PurchaseState, type QueueEvent, type QueueItem, type QueueListener, type QueueProcessorConfig, type RequestOptions, type RestoreResult, type RetryConfig, SESSION_ERROR_CODES, type SessionConfig, SessionError, SessionManager, type SessionState, type Subscription, SubscriptionCache, type SubscriptionInfo, type SubscriptionManagerConfig, type SubscriptionPlatform, type SubscriptionStatus$1 as SubscriptionStatus, type SubscriptionStatusResponse$1 as SubscriptionStatusResponse, type TapBehavior, type TrackEventOptions, type UserProperties, type ValidatePurchaseResponse, type VariableContext, type WithdrawalRequest, affiliateManager, createPurchaseError, Paywallo as default, detectDeviceLanguage, getCurrentLanguage, getDefaultLanguage, getIAPService, getLocalizedString, hasVariables, identityManager, initLocalization, nativeStoreKit, networkMonitor, offlineQueue, parseVariables, queueProcessor, resolveText, sessionManager, setCurrentLanguage, setDefaultLanguage, subscriptionManager, usePaywallContext, usePaywallo, useProducts, usePurchase, useSubscription };
1180
+ export { AFFILIATE_ERROR_CODES, ANALYTICS_ERROR_CODES, type AffiliateBalance, type AffiliateCommission, type AffiliateCoupon, AffiliateError, AffiliateManager, AnalyticsError, ApiClient, type ApiClientConfig, type BlockType, type BoxSpacing, CAMPAIGN_ERROR_CODES, type CachedSubscription, CampaignError, type CampaignPresentOptions, type CampaignResponse, type CampaignResult, type ConditionalFlagContext, type ConditionalFlagResult, PURCHASE_ERROR_CODES as ERROR_CODES, type Environment, type FlagVariant, HttpClient, type HttpClientConfig, type HttpResponse, type IAPProduct, type IAPPurchase, IAPService, IDENTITY_ERROR_CODES, type IPaywalloClient, type IdentifyOptions, IdentityError, IdentityManager, type IdentityState, type LocalizedText, type NetworkListener, type NetworkMonitorConfig, type NetworkState, type OfflineQueueConfig, PAYWALL_ERROR_CODES, PURCHASE_ERROR_CODES, type PaywallBlockConfig, type PaywallConfig, PaywallContext, PaywallError, type PaywallErrorStrings$1 as PaywallErrorStrings, PaywallModal, type PaywallNode, type PaywallPresentOptions, type PaywallResult, type PaywallState, Paywallo, PaywalloAffiliate, PaywalloClient, type PaywalloConfig, PaywalloContext, PaywalloError, type PaywalloInitConfig, PaywalloProvider, type PaywalloProviderProps, type PreloadCampaignResult, type PreloadResult, type Product, type ProductPriceInfo, type Purchase, type PurchaseControllerConfig, PurchaseError, type PurchaseResult, type PurchaseState, type QueueEvent, type QueueItem, type QueueListener, type QueueProcessorConfig, type RequestOptions, type RestoreResult, type RetryConfig, SESSION_ERROR_CODES, type SessionConfig, SessionError, SessionManager, type SessionState, type Subscription, SubscriptionCache, type SubscriptionInfo, type SubscriptionManagerConfig, type SubscriptionPlatform, type SubscriptionStatus$1 as SubscriptionStatus, type SubscriptionStatusResponse$1 as SubscriptionStatusResponse, type TapBehavior, type TrackEventOptions, type UserProperties, type ValidatePurchaseResponse, type VariableContext, type WithdrawalRequest, affiliateManager, createPurchaseError, Paywallo as default, detectDeviceLanguage, getCurrentLanguage, getDefaultLanguage, getIAPService, getLocalizedString, hasVariables, identityManager, initLocalization, nativeStoreKit, networkMonitor, offlineQueue, parseVariables, queueProcessor, resolveText, sessionManager, setCurrentLanguage, setDefaultLanguage, subscriptionManager, usePaywallContext, usePaywallo, useProducts, usePurchase, useSubscription };
package/dist/index.d.ts CHANGED
@@ -116,6 +116,7 @@ interface ServerProductInfo {
116
116
  }
117
117
  interface CampaignResponse {
118
118
  campaignId: string;
119
+ placement?: string;
119
120
  variantKey: string;
120
121
  paywall: {
121
122
  id: string;
@@ -183,6 +184,31 @@ interface EmergencyPaywallResponse {
183
184
  paywall?: PaywallConfig;
184
185
  }
185
186
 
187
+ declare class PaywalloError extends Error {
188
+ readonly code: string;
189
+ readonly domain: string;
190
+ constructor(domain: string, code: string, message: string);
191
+ }
192
+
193
+ declare class PurchaseError extends PaywalloError {
194
+ readonly userCancelled: boolean;
195
+ constructor(code: string, message: string, userCancelled?: boolean);
196
+ }
197
+ declare const PURCHASE_ERROR_CODES: {
198
+ readonly NOT_INITIALIZED: "PURCHASE_NOT_INITIALIZED";
199
+ readonly PRODUCT_NOT_FOUND: "PRODUCT_NOT_FOUND";
200
+ readonly PURCHASE_FAILED: "PURCHASE_FAILED";
201
+ readonly RESTORE_FAILED: "RESTORE_FAILED";
202
+ readonly VALIDATION_FAILED: "VALIDATION_FAILED";
203
+ readonly USER_CANCELLED: "USER_CANCELLED";
204
+ readonly NETWORK_ERROR: "PURCHASE_NETWORK_ERROR";
205
+ readonly STORE_ERROR: "PURCHASE_STORE_ERROR";
206
+ readonly PENDING_PURCHASE: "PURCHASE_PENDING";
207
+ readonly DEFERRED_PURCHASE: "PURCHASE_DEFERRED";
208
+ readonly STORE_NOT_AVAILABLE: "PURCHASE_STORE_NOT_AVAILABLE";
209
+ };
210
+ declare function createPurchaseError(code: keyof typeof PURCHASE_ERROR_CODES, message?: string): PurchaseError;
211
+
186
212
  interface Product {
187
213
  productId: string;
188
214
  title: string;
@@ -196,6 +222,7 @@ interface Product {
196
222
  introductoryPrice?: string;
197
223
  introductoryPriceValue?: number;
198
224
  freeTrialPeriod?: string;
225
+ trialDays?: number;
199
226
  pricePerMonth?: string;
200
227
  pricePerWeek?: string;
201
228
  pricePerDay?: string;
@@ -212,7 +239,7 @@ interface Purchase {
212
239
  interface PurchaseResult {
213
240
  success: boolean;
214
241
  purchase?: Purchase;
215
- error?: Error;
242
+ error?: PurchaseError;
216
243
  }
217
244
  interface ValidatePurchaseResponse {
218
245
  success: boolean;
@@ -252,10 +279,16 @@ interface ApiClientConfig {
252
279
  offlineQueueEnabled?: boolean;
253
280
  timeout?: number;
254
281
  }
282
+ interface PaywallErrorStrings$1 {
283
+ title?: string;
284
+ retry?: string;
285
+ close?: string;
286
+ }
255
287
  interface PaywalloConfig {
256
288
  appKey: string;
257
289
  debug?: boolean;
258
290
  environment?: Environment;
291
+ errorStrings?: PaywallErrorStrings$1;
259
292
  }
260
293
  interface UserProperties {
261
294
  [key: string]: string | number | boolean | null;
@@ -367,6 +400,7 @@ interface PreloadResult {
367
400
  interface PaywalloContextValue {
368
401
  config: PaywalloConfig | null;
369
402
  isInitialized: boolean;
403
+ isReady: boolean;
370
404
  initError: Error | null;
371
405
  distinctId: string | null;
372
406
  subscription: Subscription | null;
@@ -386,12 +420,6 @@ interface PaywalloContextValue {
386
420
  }
387
421
  declare const PaywalloContext: React.Context<PaywalloContextValue | null>;
388
422
 
389
- declare class PaywalloError extends Error {
390
- readonly code: string;
391
- readonly domain: string;
392
- constructor(domain: string, code: string, message: string);
393
- }
394
-
395
423
  declare class PaywallError extends PaywalloError {
396
424
  constructor(code: string, message: string);
397
425
  }
@@ -459,8 +487,8 @@ declare class ApiClient {
459
487
  private httpClient;
460
488
  private readonly cache;
461
489
  constructor(appKey: string, debug?: boolean, environment?: Environment, offlineQueueEnabled?: boolean, timeout?: number);
462
- /** Exposed only for QueueProcessor initialization. Prefer get()/post() for requests. */
463
490
  getHttpClient(): HttpClient;
491
+ getBaseUrl(): string;
464
492
  getWebUrl(): string;
465
493
  getEnvironment(): Environment;
466
494
  getQueueSize(): number;
@@ -473,7 +501,7 @@ declare class ApiClient {
473
501
  post<T>(path: string, body: unknown, skipRetry?: boolean): Promise<HttpResponse<T>>;
474
502
  reportError(errorType: string, message: string, context?: Record<string, unknown>): Promise<void>;
475
503
  trackEvent(eventName: string, distinctId: string, properties?: UserProperties, timestamp?: number): Promise<void>;
476
- identify(distinctId: string, properties?: UserProperties, email?: string): Promise<void>;
504
+ identify(distinctId: string, properties?: UserProperties, email?: string, deviceId?: string): Promise<void>;
477
505
  startSession(distinctId: string, sessionId: string, platform?: string): Promise<{
478
506
  success: boolean;
479
507
  }>;
@@ -484,23 +512,15 @@ declare class ApiClient {
484
512
  getPaywall(placement: string): Promise<PaywallConfig | null>;
485
513
  getEmergencyPaywall(): Promise<EmergencyPaywallResponse>;
486
514
  getCampaign(placement: string, distinctId: string, context?: Record<string, unknown>): Promise<CampaignResponse | null>;
515
+ getPrimaryCampaign(distinctId: string): Promise<CampaignResponse | null>;
487
516
  validatePurchase(platform: "ios" | "android", receipt: string, productId: string, transactionId: string, priceLocal: number, currency: string, country: string, distinctId?: string, paywallPlacement?: string, variantKey?: string): Promise<ValidatePurchaseResponse>;
488
517
  getSubscriptionStatus(distinctId: string): Promise<SubscriptionStatusResponse$1>;
489
518
  evaluateFlags(keys: string[], distinctId: string): Promise<Record<string, string | null>>;
490
519
  getConditionalFlag(flagKey: string, context: ConditionalFlagContext): Promise<ConditionalFlagResult>;
491
- /**
492
- * Reads a flag variant from cache layers only — no network call.
493
- * Checks in-memory cache first, then SecureStorage.
494
- * Returns null when both layers miss.
495
- */
496
520
  getVariantFromCache(flagKey: string, distinctId: string): Promise<FlagVariant | null>;
497
521
  private static readonly FLAG_MAX_AGE_MS;
498
522
  private readFlagFromStorage;
499
523
  private writeFlagToStorage;
500
- /**
501
- * POST with offline queue fallback. Enqueues when offline or on network failure.
502
- * Throws only when offlineQueueEnabled is false and the request fails.
503
- */
504
524
  private postWithQueue;
505
525
  private log;
506
526
  }
@@ -594,11 +614,13 @@ declare class IAPService {
594
614
  loadProducts(productIds: string[]): Promise<Product[]>;
595
615
  getProduct(productId: string): Product | undefined;
596
616
  getCachedProducts(): Map<string, Product>;
617
+ private validateWithRetry;
597
618
  private validateWithServer;
598
619
  private finishTransaction;
599
620
  purchase(productId: string, options?: {
600
621
  paywallPlacement?: string;
601
622
  variantKey?: string;
623
+ onValidating?: () => void;
602
624
  }): Promise<PurchaseResult>;
603
625
  restore(): Promise<Purchase[]>;
604
626
  }
@@ -613,7 +635,7 @@ declare const nativeStoreKit: {
613
635
  getActiveTransactions(): Promise<Purchase[]>;
614
636
  };
615
637
 
616
- type PurchaseState = "idle" | "loading" | "purchasing" | "restoring" | "error";
638
+ type PurchaseState = "idle" | "loading" | "purchasing" | "validating" | "restoring" | "error";
617
639
  interface IAPProduct {
618
640
  productId: string;
619
641
  price: string;
@@ -630,6 +652,7 @@ interface IAPProduct {
630
652
  introductoryPriceNumberOfPeriodsIOS?: string;
631
653
  introductoryPriceSubscriptionPeriodIOS?: string;
632
654
  freeTrialPeriodAndroid?: string;
655
+ trialDays: number;
633
656
  }
634
657
  interface IAPPurchase {
635
658
  productId: string;
@@ -653,25 +676,6 @@ interface ProductPriceInfo {
653
676
  pricePerDay?: string;
654
677
  }
655
678
 
656
- declare class PurchaseError extends PaywalloError {
657
- readonly userCancelled: boolean;
658
- constructor(code: string, message: string, userCancelled?: boolean);
659
- }
660
- declare const PURCHASE_ERROR_CODES: {
661
- readonly NOT_INITIALIZED: "PURCHASE_NOT_INITIALIZED";
662
- readonly PRODUCT_NOT_FOUND: "PRODUCT_NOT_FOUND";
663
- readonly PURCHASE_FAILED: "PURCHASE_FAILED";
664
- readonly RESTORE_FAILED: "RESTORE_FAILED";
665
- readonly VALIDATION_FAILED: "VALIDATION_FAILED";
666
- readonly USER_CANCELLED: "USER_CANCELLED";
667
- readonly NETWORK_ERROR: "PURCHASE_NETWORK_ERROR";
668
- readonly STORE_ERROR: "PURCHASE_STORE_ERROR";
669
- readonly PENDING_PURCHASE: "PURCHASE_PENDING";
670
- readonly DEFERRED_PURCHASE: "PURCHASE_DEFERRED";
671
- readonly STORE_NOT_AVAILABLE: "PURCHASE_STORE_NOT_AVAILABLE";
672
- };
673
- declare function createPurchaseError(code: keyof typeof PURCHASE_ERROR_CODES, message?: string): PurchaseError;
674
-
675
679
  interface IdentityState {
676
680
  deviceId: string;
677
681
  email: string | null;
@@ -679,6 +683,7 @@ interface IdentityState {
679
683
  }
680
684
  declare class IdentityManager {
681
685
  private deviceId;
686
+ private anonId;
682
687
  private email;
683
688
  private properties;
684
689
  private apiClient;
@@ -697,7 +702,6 @@ declare class IdentityManager {
697
702
  isSecureStorageAvailable(): boolean;
698
703
  private loadPersistedState;
699
704
  private ensureInitialized;
700
- private log;
701
705
  }
702
706
  declare const identityManager: IdentityManager;
703
707
 
@@ -812,16 +816,26 @@ interface PreloadCampaignResult {
812
816
  success: boolean;
813
817
  error?: Error;
814
818
  }
819
+ interface PaywallErrorStrings {
820
+ title?: string;
821
+ retry?: string;
822
+ close?: string;
823
+ }
815
824
  interface PaywalloInitConfig extends PaywalloConfig {
816
825
  sessionConfig?: SessionConfig;
817
826
  autoStartSession?: boolean;
818
827
  offlineQueueEnabled?: boolean;
819
828
  timeout?: number;
820
- /** Request ATT permission during init (iOS only). Default: false. */
821
829
  requestATT?: boolean;
830
+ errorStrings?: PaywallErrorStrings;
831
+ sessionFlags?: string[];
832
+ subscriptionCacheTTL?: number;
833
+ autoPreloadCampaign?: string;
822
834
  }
823
835
  interface IPaywalloClient {
824
836
  init(config: PaywalloInitConfig): Promise<void>;
837
+ isReady(): boolean;
838
+ waitUntilReady(): Promise<void>;
825
839
  identify(options?: IdentifyOptions | UserProperties): Promise<void>;
826
840
  track(eventName: string, options?: TrackEventOptions): Promise<void>;
827
841
  getVariantCached(flagKey: string, defaultValue?: string): Promise<FlagVariant>;
@@ -862,6 +876,7 @@ interface IPaywalloClient {
862
876
  registerActiveChecker(checker: () => Promise<boolean>): void;
863
877
  registerRestoreHandler(handler: () => Promise<RestoreResult>): void;
864
878
  registerEmergencyPaywallHandler(handler: EmergencyPaywallHandler): void;
879
+ getSessionFlag(key: string): string | null;
865
880
  isOnline(): boolean;
866
881
  getOfflineQueueSize(): number;
867
882
  clearOfflineQueue(): Promise<void>;
@@ -871,6 +886,9 @@ interface IPaywalloClient {
871
886
  }>;
872
887
  onboardingStep(index: number, name: string): Promise<void>;
873
888
  coreAction(actionName: string): Promise<void>;
889
+ isPreloaded(placement: string): boolean;
890
+ getAutoPreloadedPlacement(): string | null;
891
+ waitForAutoPreloadedPlacement(): Promise<string | null>;
874
892
  }
875
893
 
876
894
  declare const PaywalloClient: IPaywalloClient;
@@ -913,7 +931,7 @@ declare class OfflineQueueClass {
913
931
  private loadFromStorage;
914
932
  private saveToStorage;
915
933
  private cleanupExpired;
916
- enqueue(method: "POST" | "PUT", url: string, body: unknown, headers?: Record<string, string>): Promise<QueueItem>;
934
+ enqueue(method: "POST" | "PUT", url: string, body: unknown, headers?: Record<string, string>, id?: string): Promise<QueueItem>;
917
935
  private findDuplicateIndex;
918
936
  dequeue(): Promise<QueueItem | null>;
919
937
  removeItem(id: string): Promise<boolean>;
@@ -926,7 +944,6 @@ declare class OfflineQueueClass {
926
944
  processed: number;
927
945
  failed: number;
928
946
  }>;
929
- /** Returns true if the item was permanently removed (counted as failed). */
930
947
  private handleItemFailure;
931
948
  private sleep;
932
949
  getQueue(): ReadonlyArray<QueueItem>;
@@ -1003,6 +1020,7 @@ interface FormattedProduct extends ProductPriceInfo {
1003
1020
  subscriptionPeriod?: string;
1004
1021
  introductoryPrice?: string;
1005
1022
  freeTrialPeriod?: string;
1023
+ trialDays: number;
1006
1024
  }
1007
1025
 
1008
1026
  interface UseProductsResult {
@@ -1017,13 +1035,19 @@ interface UseProductsResult {
1017
1035
  }
1018
1036
  declare function useProducts(initialProductIds?: string[]): UseProductsResult;
1019
1037
 
1038
+ interface PurchaseOutcome {
1039
+ status: "success" | "cancelled" | "failed";
1040
+ purchase?: IAPPurchase;
1041
+ error?: PurchaseError;
1042
+ }
1020
1043
  interface UsePurchaseResult {
1021
1044
  state: PurchaseState;
1022
- purchase: (productId: string) => Promise<IAPPurchase>;
1045
+ purchase: (productId: string) => Promise<PurchaseOutcome>;
1023
1046
  restore: () => Promise<IAPPurchase[]>;
1024
1047
  error: PurchaseError | null;
1025
1048
  isLoading: boolean;
1026
1049
  isPurchasing: boolean;
1050
+ isValidating: boolean;
1027
1051
  isRestoring: boolean;
1028
1052
  }
1029
1053
  declare function usePurchase(): UsePurchaseResult;
@@ -1082,10 +1106,13 @@ declare class SubscriptionCache {
1082
1106
  private ttl;
1083
1107
  private memoryCache;
1084
1108
  private storage;
1109
+ private legacyCleanupDone;
1085
1110
  constructor(ttl?: number);
1086
- get(): Promise<CachedSubscription | null>;
1087
- set(data: SubscriptionStatusResponse): Promise<void>;
1088
- invalidate(): Promise<void>;
1111
+ private cleanupLegacyCache;
1112
+ get(distinctId: string): Promise<CachedSubscription | null>;
1113
+ set(distinctId: string, data: SubscriptionStatusResponse): Promise<void>;
1114
+ invalidate(distinctId: string): Promise<void>;
1115
+ invalidateAll(): Promise<void>;
1089
1116
  private isExpired;
1090
1117
  setTTL(ttl: number): void;
1091
1118
  }
@@ -1097,6 +1124,7 @@ declare class SubscriptionManagerClass {
1097
1124
  private listeners;
1098
1125
  private userId;
1099
1126
  constructor();
1127
+ private cacheKey;
1100
1128
  init(config: SubscriptionManagerConfig): void;
1101
1129
  setUserId(userId: string | null): void;
1102
1130
  hasActiveSubscription(forceRefresh?: boolean): Promise<boolean>;
@@ -1149,4 +1177,4 @@ declare function hasVariables(text: string): boolean;
1149
1177
 
1150
1178
  declare const Paywallo: IPaywalloClient;
1151
1179
 
1152
- export { AFFILIATE_ERROR_CODES, ANALYTICS_ERROR_CODES, type AffiliateBalance, type AffiliateCommission, type AffiliateCoupon, AffiliateError, AffiliateManager, AnalyticsError, ApiClient, type ApiClientConfig, type BlockType, type BoxSpacing, CAMPAIGN_ERROR_CODES, type CachedSubscription, CampaignError, type CampaignPresentOptions, type CampaignResponse, type CampaignResult, type ConditionalFlagContext, type ConditionalFlagResult, PURCHASE_ERROR_CODES as ERROR_CODES, type Environment, type FlagVariant, HttpClient, type HttpClientConfig, type HttpResponse, type IAPProduct, type IAPPurchase, IAPService, IDENTITY_ERROR_CODES, type IPaywalloClient, type IdentifyOptions, IdentityError, IdentityManager, type IdentityState, type LocalizedText, type NetworkListener, type NetworkMonitorConfig, type NetworkState, type OfflineQueueConfig, PAYWALL_ERROR_CODES, PURCHASE_ERROR_CODES, type PaywallBlockConfig, type PaywallConfig, PaywallContext, PaywallError, PaywallModal, type PaywallNode, type PaywallPresentOptions, type PaywallResult, type PaywallState, Paywallo, PaywalloAffiliate, PaywalloClient, type PaywalloConfig, PaywalloContext, PaywalloError, type PaywalloInitConfig, PaywalloProvider, type PreloadCampaignResult, type PreloadResult, type Product, type ProductPriceInfo, type Purchase, type PurchaseControllerConfig, PurchaseError, type PurchaseResult, type PurchaseState, type QueueEvent, type QueueItem, type QueueListener, type QueueProcessorConfig, type RequestOptions, type RestoreResult, type RetryConfig, SESSION_ERROR_CODES, type SessionConfig, SessionError, SessionManager, type SessionState, type Subscription, SubscriptionCache, type SubscriptionInfo, type SubscriptionManagerConfig, type SubscriptionPlatform, type SubscriptionStatus$1 as SubscriptionStatus, type SubscriptionStatusResponse$1 as SubscriptionStatusResponse, type TapBehavior, type TrackEventOptions, type UserProperties, type ValidatePurchaseResponse, type VariableContext, type WithdrawalRequest, affiliateManager, createPurchaseError, Paywallo as default, detectDeviceLanguage, getCurrentLanguage, getDefaultLanguage, getIAPService, getLocalizedString, hasVariables, identityManager, initLocalization, nativeStoreKit, networkMonitor, offlineQueue, parseVariables, queueProcessor, resolveText, sessionManager, setCurrentLanguage, setDefaultLanguage, subscriptionManager, usePaywallContext, usePaywallo, useProducts, usePurchase, useSubscription };
1180
+ export { AFFILIATE_ERROR_CODES, ANALYTICS_ERROR_CODES, type AffiliateBalance, type AffiliateCommission, type AffiliateCoupon, AffiliateError, AffiliateManager, AnalyticsError, ApiClient, type ApiClientConfig, type BlockType, type BoxSpacing, CAMPAIGN_ERROR_CODES, type CachedSubscription, CampaignError, type CampaignPresentOptions, type CampaignResponse, type CampaignResult, type ConditionalFlagContext, type ConditionalFlagResult, PURCHASE_ERROR_CODES as ERROR_CODES, type Environment, type FlagVariant, HttpClient, type HttpClientConfig, type HttpResponse, type IAPProduct, type IAPPurchase, IAPService, IDENTITY_ERROR_CODES, type IPaywalloClient, type IdentifyOptions, IdentityError, IdentityManager, type IdentityState, type LocalizedText, type NetworkListener, type NetworkMonitorConfig, type NetworkState, type OfflineQueueConfig, PAYWALL_ERROR_CODES, PURCHASE_ERROR_CODES, type PaywallBlockConfig, type PaywallConfig, PaywallContext, PaywallError, type PaywallErrorStrings$1 as PaywallErrorStrings, PaywallModal, type PaywallNode, type PaywallPresentOptions, type PaywallResult, type PaywallState, Paywallo, PaywalloAffiliate, PaywalloClient, type PaywalloConfig, PaywalloContext, PaywalloError, type PaywalloInitConfig, PaywalloProvider, type PaywalloProviderProps, type PreloadCampaignResult, type PreloadResult, type Product, type ProductPriceInfo, type Purchase, type PurchaseControllerConfig, PurchaseError, type PurchaseResult, type PurchaseState, type QueueEvent, type QueueItem, type QueueListener, type QueueProcessorConfig, type RequestOptions, type RestoreResult, type RetryConfig, SESSION_ERROR_CODES, type SessionConfig, SessionError, SessionManager, type SessionState, type Subscription, SubscriptionCache, type SubscriptionInfo, type SubscriptionManagerConfig, type SubscriptionPlatform, type SubscriptionStatus$1 as SubscriptionStatus, type SubscriptionStatusResponse$1 as SubscriptionStatusResponse, type TapBehavior, type TrackEventOptions, type UserProperties, type ValidatePurchaseResponse, type VariableContext, type WithdrawalRequest, affiliateManager, createPurchaseError, Paywallo as default, detectDeviceLanguage, getCurrentLanguage, getDefaultLanguage, getIAPService, getLocalizedString, hasVariables, identityManager, initLocalization, nativeStoreKit, networkMonitor, offlineQueue, parseVariables, queueProcessor, resolveText, sessionManager, setCurrentLanguage, setDefaultLanguage, subscriptionManager, usePaywallContext, usePaywallo, useProducts, usePurchase, useSubscription };