@virex-tech/paywallo-sdk 1.0.0 → 1.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/LICENSE +1 -1
- package/{MonetySdk.podspec → PaywalloSdk.podspec} +4 -4
- package/README.md +19 -19
- package/android/build.gradle +1 -1
- package/dist/index.js +17 -121
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -121
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -5
- package/react-native.config.js +3 -3
- package/android/src/main/java/com/monety/sdk/MonetySdkPackage.kt +0 -16
- package/android/src/main/java/com/monety/sdk/PanelStoreKitModule.kt +0 -315
- package/android/src/main/java/com/monety/sdk/PanelWebView.kt +0 -74
- package/android/src/main/java/com/monety/sdk/PanelWebViewManager.kt +0 -52
- package/ios/PanelStoreKit.m +0 -21
- package/ios/PanelStoreKit.swift +0 -245
- package/ios/PanelWebView.h +0 -15
- package/ios/PanelWebView.m +0 -182
- package/ios/PanelWebViewManager.m +0 -41
- package/ios/PanelWebViewModule.h +0 -8
- package/ios/PanelWebViewModule.m +0 -42
package/dist/index.mjs
CHANGED
|
@@ -133,8 +133,8 @@ async function loadKeychain() {
|
|
|
133
133
|
}
|
|
134
134
|
var KEYCHAIN_SERVICE_PREFIX = "com.paywallo.sdk.";
|
|
135
135
|
var SecureStorage = class {
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
137
|
+
constructor(_debug = false) {
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* Get a value, trying Keychain first (survives reinstalls on iOS), then AsyncStorage.
|
|
@@ -142,18 +142,15 @@ var SecureStorage = class {
|
|
|
142
142
|
async get(key) {
|
|
143
143
|
const keychainValue = await this.getFromKeychain(key);
|
|
144
144
|
if (keychainValue) {
|
|
145
|
-
this.log(`Retrieved ${key} from keychain`);
|
|
146
145
|
return keychainValue;
|
|
147
146
|
}
|
|
148
147
|
try {
|
|
149
148
|
const value = await AsyncStorage.getItem(`@paywallo:${key}`);
|
|
150
149
|
if (value) {
|
|
151
|
-
this.log(`Retrieved ${key} from async storage`);
|
|
152
150
|
await this.setToKeychain(key, value);
|
|
153
151
|
}
|
|
154
152
|
return value;
|
|
155
|
-
} catch
|
|
156
|
-
this.log(`Storage read failed for ${key}:`, error);
|
|
153
|
+
} catch {
|
|
157
154
|
return null;
|
|
158
155
|
}
|
|
159
156
|
}
|
|
@@ -166,10 +163,8 @@ var SecureStorage = class {
|
|
|
166
163
|
AsyncStorage.setItem(`@paywallo:${key}`, value),
|
|
167
164
|
this.setToKeychain(key, value)
|
|
168
165
|
]);
|
|
169
|
-
this.log(`Stored ${key} in storage`);
|
|
170
166
|
return true;
|
|
171
|
-
} catch
|
|
172
|
-
this.log(`Storage write failed for ${key}:`, error);
|
|
167
|
+
} catch {
|
|
173
168
|
return false;
|
|
174
169
|
}
|
|
175
170
|
}
|
|
@@ -179,10 +174,8 @@ var SecureStorage = class {
|
|
|
179
174
|
AsyncStorage.removeItem(`@paywallo:${key}`),
|
|
180
175
|
this.removeFromKeychain(key)
|
|
181
176
|
]);
|
|
182
|
-
this.log(`Removed ${key} from storage`);
|
|
183
177
|
return true;
|
|
184
|
-
} catch
|
|
185
|
-
this.log(`Storage remove failed for ${key}:`, error);
|
|
178
|
+
} catch {
|
|
186
179
|
return false;
|
|
187
180
|
}
|
|
188
181
|
}
|
|
@@ -222,11 +215,6 @@ var SecureStorage = class {
|
|
|
222
215
|
return false;
|
|
223
216
|
}
|
|
224
217
|
}
|
|
225
|
-
log(...args) {
|
|
226
|
-
if (this.debug) {
|
|
227
|
-
console.warn("[Panel Storage]", ...args);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
218
|
};
|
|
231
219
|
var secureStorage = new SecureStorage();
|
|
232
220
|
|
|
@@ -551,21 +539,13 @@ var IAPService = class {
|
|
|
551
539
|
}
|
|
552
540
|
async loadProducts(productIds) {
|
|
553
541
|
if (!nativeStoreKit.isAvailable()) {
|
|
554
|
-
if (this.debug) console.warn("[Paywallo][Products] StoreKit not available");
|
|
555
542
|
return [];
|
|
556
543
|
}
|
|
557
544
|
try {
|
|
558
|
-
if (this.debug) console.warn("[Paywallo][Products] Loading from StoreKit:", productIds);
|
|
559
545
|
const products = await nativeStoreKit.getProducts(productIds);
|
|
560
|
-
if (this.debug) console.warn("[Paywallo][Products] StoreKit returned:", products.length, "products");
|
|
561
546
|
for (const product of products) {
|
|
562
|
-
if (this.debug) console.warn("[Paywallo][Products]", product.productId, "\u2192", product.localizedPrice, "(", product.currency, ")");
|
|
563
547
|
this.productsCache.set(product.productId, product);
|
|
564
548
|
}
|
|
565
|
-
if (products.length < productIds.length) {
|
|
566
|
-
const missing = productIds.filter((id) => !products.find((p) => p.productId === id));
|
|
567
|
-
if (this.debug) console.warn("[Paywallo][Products] Missing from StoreKit:", missing);
|
|
568
|
-
}
|
|
569
549
|
return products;
|
|
570
550
|
} catch (error) {
|
|
571
551
|
if (this.debug) console.warn("[Paywallo][Products] StoreKit error:", error);
|
|
@@ -583,7 +563,6 @@ var IAPService = class {
|
|
|
583
563
|
const product = this.productsCache.get(productId);
|
|
584
564
|
const platform = Platform2.OS;
|
|
585
565
|
const distinctId = PaywalloClient.getDistinctId();
|
|
586
|
-
if (this.debug) console.warn("[Paywallo][Purchase] Validating with server:", purchase.productId, "tx:", purchase.transactionId, "price:", product?.priceValue, product?.currency);
|
|
587
566
|
const validation = await apiClient.validatePurchase(
|
|
588
567
|
platform,
|
|
589
568
|
purchase.receipt,
|
|
@@ -596,33 +575,28 @@ var IAPService = class {
|
|
|
596
575
|
options?.paywallPlacement,
|
|
597
576
|
options?.variantKey
|
|
598
577
|
);
|
|
599
|
-
if (this.debug) console.warn("[Paywallo][Purchase] Server validation result:", JSON.stringify(validation));
|
|
600
578
|
return validation;
|
|
601
579
|
}
|
|
602
580
|
async finishTransaction(transactionId) {
|
|
603
581
|
try {
|
|
604
|
-
if (this.debug) console.warn("[Paywallo][Purchase] Finishing transaction:", transactionId);
|
|
605
582
|
await nativeStoreKit.finishTransaction(transactionId);
|
|
606
|
-
if (this.debug) console.warn("[Paywallo][Purchase] Transaction finished OK");
|
|
607
583
|
} catch (finishError) {
|
|
608
584
|
if (this.debug) console.warn("[Paywallo][Purchase] Failed to finish transaction:", finishError instanceof Error ? finishError.message : finishError);
|
|
609
585
|
}
|
|
610
586
|
}
|
|
611
587
|
async purchase(productId, options) {
|
|
612
588
|
if (!nativeStoreKit.isAvailable()) {
|
|
589
|
+
if (this.debug) console.warn("[Paywallo][Purchase] StoreKit not available");
|
|
613
590
|
return {
|
|
614
591
|
success: false,
|
|
615
592
|
error: new PurchaseError(PURCHASE_ERROR_CODES.STORE_NOT_AVAILABLE, "In-app purchases are not available on this device")
|
|
616
593
|
};
|
|
617
594
|
}
|
|
618
595
|
try {
|
|
619
|
-
if (this.debug) console.warn("[Paywallo][Purchase] StoreKit purchase starting:", productId);
|
|
620
596
|
const purchase = await nativeStoreKit.purchase(productId);
|
|
621
597
|
if (!purchase) {
|
|
622
|
-
if (this.debug) console.warn("[Paywallo][Purchase] StoreKit returned null (user cancelled or pending)");
|
|
623
598
|
return { success: false };
|
|
624
599
|
}
|
|
625
|
-
if (this.debug) console.warn("[Paywallo][Purchase] StoreKit OK \u2014 tx:", purchase.transactionId, "product:", purchase.productId, "receipt length:", purchase.receipt?.length);
|
|
626
600
|
let validation = null;
|
|
627
601
|
try {
|
|
628
602
|
validation = await this.validateWithServer(purchase, productId, options);
|
|
@@ -634,14 +608,12 @@ var IAPService = class {
|
|
|
634
608
|
};
|
|
635
609
|
}
|
|
636
610
|
if (!validation?.success) {
|
|
637
|
-
if (this.debug) console.warn("[Paywallo][Purchase] Validation returned failure:", validation?.error || "no validation result");
|
|
638
611
|
return {
|
|
639
612
|
success: false,
|
|
640
613
|
error: new PurchaseError(PURCHASE_ERROR_CODES.VALIDATION_FAILED, validation?.error ? `Server validation: ${validation.error}` : "Server validation failed")
|
|
641
614
|
};
|
|
642
615
|
}
|
|
643
616
|
await this.finishTransaction(purchase.transactionId);
|
|
644
|
-
if (this.debug) console.warn("[Paywallo][Purchase] COMPLETE \u2014 validated & finished:", purchase.productId);
|
|
645
617
|
return { success: true, purchase };
|
|
646
618
|
} catch (error) {
|
|
647
619
|
const e = error instanceof PurchaseError ? error : new PurchaseError(PURCHASE_ERROR_CODES.PURCHASE_FAILED, error instanceof Error ? error.message : String(error));
|
|
@@ -651,20 +623,16 @@ var IAPService = class {
|
|
|
651
623
|
}
|
|
652
624
|
async restore() {
|
|
653
625
|
if (!nativeStoreKit.isAvailable()) {
|
|
654
|
-
if (this.debug) console.warn("[Paywallo][Restore] StoreKit not available");
|
|
655
626
|
return [];
|
|
656
627
|
}
|
|
657
628
|
try {
|
|
658
|
-
if (this.debug) console.warn("[Paywallo][Restore] Getting active transactions...");
|
|
659
629
|
const transactions = await nativeStoreKit.getActiveTransactions();
|
|
660
|
-
if (this.debug) console.warn("[Paywallo][Restore] Found", transactions.length, "active transactions");
|
|
661
630
|
const apiClient = this.getApiClient();
|
|
662
631
|
const distinctId = PaywalloClient.getDistinctId();
|
|
663
632
|
const platform = Platform2.OS;
|
|
664
633
|
const results = await Promise.allSettled(
|
|
665
634
|
transactions.map((tx) => {
|
|
666
635
|
const product = this.productsCache.get(tx.productId);
|
|
667
|
-
if (this.debug) console.warn("[Paywallo][Restore] Validating tx:", tx.transactionId, "product:", tx.productId);
|
|
668
636
|
return apiClient.validatePurchase(
|
|
669
637
|
platform,
|
|
670
638
|
tx.receipt,
|
|
@@ -681,22 +649,18 @@ var IAPService = class {
|
|
|
681
649
|
for (let i = 0; i < results.length; i++) {
|
|
682
650
|
const r = results[i];
|
|
683
651
|
const tx = transactions[i];
|
|
684
|
-
if (this.debug) console.warn("[Paywallo][Restore] Validation:", r.status, r.status === "fulfilled" ? JSON.stringify(r.value) : r.reason?.message);
|
|
685
652
|
if (r.status === "fulfilled" && r.value.success) {
|
|
686
653
|
try {
|
|
687
654
|
await nativeStoreKit.finishTransaction(tx.transactionId);
|
|
688
|
-
if (this.debug) console.warn("[Paywallo][Restore] Finished tx:", tx.transactionId);
|
|
689
655
|
} catch (finishError) {
|
|
690
656
|
if (this.debug) console.warn("[Paywallo][Restore] Failed to finish tx:", tx.transactionId, finishError instanceof Error ? finishError.message : finishError);
|
|
691
657
|
}
|
|
692
658
|
validated.push(tx);
|
|
693
|
-
} else {
|
|
694
|
-
if (this.debug) console.warn("[Paywallo][Restore] Skipping unvalidated tx:", tx.transactionId);
|
|
695
659
|
}
|
|
696
660
|
}
|
|
697
661
|
return validated;
|
|
698
662
|
} catch (error) {
|
|
699
|
-
if (this.debug) console.warn("[Paywallo][Restore] FAILED:", error instanceof Error ? error.message : error);
|
|
663
|
+
if (this.debug) console.warn("[Paywallo][Restore] \u274C FAILED:", error instanceof Error ? error.message : error);
|
|
700
664
|
return [];
|
|
701
665
|
}
|
|
702
666
|
}
|
|
@@ -818,7 +782,6 @@ function usePaywallActions(placement, paywallConfig, onResult, variantKey, campa
|
|
|
818
782
|
}
|
|
819
783
|
onResult({ presented: true, purchased: false, cancelled: false, restored: true });
|
|
820
784
|
} else {
|
|
821
|
-
if (PaywalloClient.getConfig()?.debug) console.warn("[Paywallo] No purchases to restore");
|
|
822
785
|
onResult({ presented: true, purchased: false, cancelled: false, restored: false });
|
|
823
786
|
}
|
|
824
787
|
} catch (error) {
|
|
@@ -961,7 +924,7 @@ function buildPaywallInjectionScript(data) {
|
|
|
961
924
|
secondaryProductId: data.secondaryProductId
|
|
962
925
|
}
|
|
963
926
|
};
|
|
964
|
-
return `(function(){var d=${JSON.stringify(paywallData)},a=0,m=50;function t(){a++;if(window.receiveNativeMessage){window.receiveNativeMessage(d);return;}if(a<m){setTimeout(t,100);}else{console.warn('[
|
|
927
|
+
return `(function(){var d=${JSON.stringify(paywallData)},a=0,m=50;function t(){a++;if(window.receiveNativeMessage){window.receiveNativeMessage(d);return;}if(a<m){setTimeout(t,100);}else{console.warn('[Paywallo WV] FAILED to inject after '+m+' attempts');}}t();})();true;`;
|
|
965
928
|
}
|
|
966
929
|
function buildPurchaseStateScript(isPurchasing) {
|
|
967
930
|
return `if(window.receiveNativeMessage){window.receiveNativeMessage({type:"purchaseState",data:{isPurchasing:${isPurchasing}}});}true;`;
|
|
@@ -1120,16 +1083,13 @@ function PaywallModal({
|
|
|
1120
1083
|
const openAnim = useRef4(new Animated2.Value(SCREEN_HEIGHT2)).current;
|
|
1121
1084
|
useEffect3(() => {
|
|
1122
1085
|
if (visible) {
|
|
1123
|
-
if (PaywalloClient.getConfig()?.debug) console.warn("[Paywallo] PaywallModal opening \u2014 starting slide-up animation (550ms)");
|
|
1124
1086
|
openAnim.setValue(SCREEN_HEIGHT2);
|
|
1125
1087
|
Animated2.timing(openAnim, {
|
|
1126
1088
|
toValue: 0,
|
|
1127
1089
|
duration: 550,
|
|
1128
1090
|
easing: Easing.out(Easing.cubic),
|
|
1129
1091
|
useNativeDriver: true
|
|
1130
|
-
}).start(
|
|
1131
|
-
if (PaywalloClient.getConfig()?.debug) console.warn("[Paywallo] PaywallModal slide-up animation completed");
|
|
1132
|
-
});
|
|
1092
|
+
}).start();
|
|
1133
1093
|
}
|
|
1134
1094
|
}, [visible, openAnim]);
|
|
1135
1095
|
if (!visible) return null;
|
|
@@ -1533,8 +1493,7 @@ function buildConditionalFlagUrl(baseUrl, flagKey, context) {
|
|
|
1533
1493
|
}
|
|
1534
1494
|
|
|
1535
1495
|
// src/domains/iap/apiPurchaseMethods.ts
|
|
1536
|
-
async function validatePurchase(client, appKey, platform, receipt, productId, transactionId, priceLocal, currency, country, distinctId, paywallPlacement, variantKey
|
|
1537
|
-
if (debug) console.warn("[Paywallo][API] POST /purchases/validate", { platform, productId, transactionId, priceLocal, currency, country, distinctId, paywallPlacement, variantKey, receiptLen: receipt?.length });
|
|
1496
|
+
async function validatePurchase(client, appKey, platform, receipt, productId, transactionId, priceLocal, currency, country, distinctId, paywallPlacement, variantKey) {
|
|
1538
1497
|
const response = await client.post(
|
|
1539
1498
|
`/purchases/validate/${appKey}`,
|
|
1540
1499
|
{
|
|
@@ -1551,7 +1510,6 @@ async function validatePurchase(client, appKey, platform, receipt, productId, tr
|
|
|
1551
1510
|
},
|
|
1552
1511
|
false
|
|
1553
1512
|
);
|
|
1554
|
-
if (debug) console.warn("[Paywallo][API] Validation response:", JSON.stringify(response.data));
|
|
1555
1513
|
return response.data;
|
|
1556
1514
|
}
|
|
1557
1515
|
async function getSubscriptionStatus(client, baseUrl, appKey, distinctId) {
|
|
@@ -1629,11 +1587,6 @@ var HttpClient = class {
|
|
|
1629
1587
|
if (state.attempt < retryConfig.maxRetries) {
|
|
1630
1588
|
state.attempt++;
|
|
1631
1589
|
const delay = this.calculateDelay(state.attempt, retryConfig);
|
|
1632
|
-
this.log(`Retrying request (attempt ${state.attempt}/${retryConfig.maxRetries})`, {
|
|
1633
|
-
url,
|
|
1634
|
-
status: response.status,
|
|
1635
|
-
delay
|
|
1636
|
-
});
|
|
1637
1590
|
await this.sleep(delay);
|
|
1638
1591
|
continue;
|
|
1639
1592
|
}
|
|
@@ -1644,11 +1597,6 @@ var HttpClient = class {
|
|
|
1644
1597
|
if (this.isNetworkError(state.lastError) && state.attempt < retryConfig.maxRetries) {
|
|
1645
1598
|
state.attempt++;
|
|
1646
1599
|
const delay = this.calculateDelay(state.attempt, retryConfig);
|
|
1647
|
-
this.log(`Network error, retrying (attempt ${state.attempt}/${retryConfig.maxRetries})`, {
|
|
1648
|
-
url,
|
|
1649
|
-
error: state.lastError.message,
|
|
1650
|
-
delay
|
|
1651
|
-
});
|
|
1652
1600
|
await this.sleep(delay);
|
|
1653
1601
|
continue;
|
|
1654
1602
|
}
|
|
@@ -1666,11 +1614,6 @@ var HttpClient = class {
|
|
|
1666
1614
|
controller.abort();
|
|
1667
1615
|
}
|
|
1668
1616
|
}, timeout);
|
|
1669
|
-
this.log("Request starting", {
|
|
1670
|
-
url,
|
|
1671
|
-
method: options.method,
|
|
1672
|
-
headers: options.headers
|
|
1673
|
-
});
|
|
1674
1617
|
try {
|
|
1675
1618
|
const response = await fetch(url, {
|
|
1676
1619
|
...options,
|
|
@@ -1683,20 +1626,8 @@ var HttpClient = class {
|
|
|
1683
1626
|
data = await response.json();
|
|
1684
1627
|
} else {
|
|
1685
1628
|
const textData = await response.text();
|
|
1686
|
-
this.log("Non-JSON response received", {
|
|
1687
|
-
url,
|
|
1688
|
-
status: response.status,
|
|
1689
|
-
contentType,
|
|
1690
|
-
bodyPreview: textData.substring(0, 200)
|
|
1691
|
-
});
|
|
1692
1629
|
data = textData;
|
|
1693
1630
|
}
|
|
1694
|
-
this.log("Request completed", {
|
|
1695
|
-
url,
|
|
1696
|
-
status: response.status,
|
|
1697
|
-
ok: response.ok,
|
|
1698
|
-
contentType
|
|
1699
|
-
});
|
|
1700
1631
|
const headers = {};
|
|
1701
1632
|
response.headers.forEach((value, key) => {
|
|
1702
1633
|
headers[key] = value;
|
|
@@ -1979,7 +1910,6 @@ var OfflineQueueClass = class {
|
|
|
1979
1910
|
this.cleanupExpired();
|
|
1980
1911
|
this.cleanupTimer = setInterval(() => this.cleanupExpired(), 60 * 60 * 1e3);
|
|
1981
1912
|
this.initialized = true;
|
|
1982
|
-
this.log("OfflineQueue initialized", { queueSize: this.queue.length });
|
|
1983
1913
|
}
|
|
1984
1914
|
async loadFromStorage() {
|
|
1985
1915
|
try {
|
|
@@ -2010,7 +1940,6 @@ var OfflineQueueClass = class {
|
|
|
2010
1940
|
const before = this.queue.length;
|
|
2011
1941
|
this.queue = this.queue.filter((item) => Date.now() - item.timestamp < this.config.maxAge);
|
|
2012
1942
|
if (before !== this.queue.length) {
|
|
2013
|
-
this.log("Cleaned up expired items", { removed: before - this.queue.length });
|
|
2014
1943
|
void this.saveToStorage();
|
|
2015
1944
|
}
|
|
2016
1945
|
}
|
|
@@ -2027,7 +1956,6 @@ var OfflineQueueClass = class {
|
|
|
2027
1956
|
};
|
|
2028
1957
|
const existingIndex = this.findDuplicateIndex(item);
|
|
2029
1958
|
if (existingIndex !== -1) {
|
|
2030
|
-
this.log("Duplicate item found, updating timestamp", { id: this.queue[existingIndex].id });
|
|
2031
1959
|
this.queue[existingIndex].timestamp = Date.now();
|
|
2032
1960
|
await this.saveToStorage();
|
|
2033
1961
|
return this.queue[existingIndex];
|
|
@@ -2035,14 +1963,12 @@ var OfflineQueueClass = class {
|
|
|
2035
1963
|
if (this.queue.length >= this.config.maxItems) {
|
|
2036
1964
|
const removed = this.queue.shift();
|
|
2037
1965
|
if (removed) {
|
|
2038
|
-
this.log("Queue full, evicted oldest item:", removed.url);
|
|
2039
1966
|
this.emit({ type: "item:evicted", item: removed, queueSize: this.queue.length });
|
|
2040
1967
|
}
|
|
2041
1968
|
}
|
|
2042
1969
|
this.queue.push(item);
|
|
2043
1970
|
await this.saveToStorage();
|
|
2044
1971
|
this.emit({ type: "item:added", item, queueSize: this.queue.length });
|
|
2045
|
-
this.log("Item enqueued", { id: item.id, url: item.url });
|
|
2046
1972
|
return item;
|
|
2047
1973
|
}
|
|
2048
1974
|
findDuplicateIndex(item) {
|
|
@@ -2071,7 +1997,6 @@ var OfflineQueueClass = class {
|
|
|
2071
1997
|
this.processingLock = true;
|
|
2072
1998
|
this.processing = true;
|
|
2073
1999
|
this.emit({ type: "processing:start", queueSize: this.queue.length });
|
|
2074
|
-
this.log("Processing queue", { items: this.queue.length });
|
|
2075
2000
|
let processed = 0;
|
|
2076
2001
|
let failed = 0;
|
|
2077
2002
|
const delayMs = options?.delayBetweenItems ?? 100;
|
|
@@ -2088,7 +2013,6 @@ var OfflineQueueClass = class {
|
|
|
2088
2013
|
await this.removeItem(item.id);
|
|
2089
2014
|
processed++;
|
|
2090
2015
|
this.emit({ type: "item:success", item, queueSize: this.queue.length });
|
|
2091
|
-
this.log("Item processed successfully", { id: item.id });
|
|
2092
2016
|
} else {
|
|
2093
2017
|
const didFail = await this.handleItemFailure(item, void 0, permanent);
|
|
2094
2018
|
if (didFail) failed++;
|
|
@@ -2103,7 +2027,6 @@ var OfflineQueueClass = class {
|
|
|
2103
2027
|
this.processing = false;
|
|
2104
2028
|
this.processingLock = false;
|
|
2105
2029
|
this.emit({ type: "processing:end", queueSize: this.queue.length });
|
|
2106
|
-
this.log("Queue processing complete", { processed, failed, remaining: this.queue.length });
|
|
2107
2030
|
return { processed, failed };
|
|
2108
2031
|
}
|
|
2109
2032
|
/** Returns true if the item was permanently removed (counted as failed). */
|
|
@@ -2116,14 +2039,9 @@ var OfflineQueueClass = class {
|
|
|
2116
2039
|
error: error ?? new ClientError(CLIENT_ERROR_CODES.UNKNOWN, permanent ? "Permanent failure" : "Max attempts reached"),
|
|
2117
2040
|
queueSize: this.queue.length
|
|
2118
2041
|
});
|
|
2119
|
-
this.log(
|
|
2120
|
-
permanent ? "Item failed permanently - removed" : "Item failed after max attempts",
|
|
2121
|
-
{ id: item.id, attempts: item.attempts }
|
|
2122
|
-
);
|
|
2123
2042
|
return true;
|
|
2124
2043
|
}
|
|
2125
2044
|
await this.saveToStorage();
|
|
2126
|
-
this.log("Item will be retried", { id: item.id, attempts: item.attempts });
|
|
2127
2045
|
return false;
|
|
2128
2046
|
}
|
|
2129
2047
|
sleep(ms) {
|
|
@@ -2144,7 +2062,6 @@ var OfflineQueueClass = class {
|
|
|
2144
2062
|
async clear() {
|
|
2145
2063
|
this.queue = [];
|
|
2146
2064
|
await this.saveToStorage();
|
|
2147
|
-
this.log("Queue cleared");
|
|
2148
2065
|
}
|
|
2149
2066
|
async clearItemsWithInvalidAppKey(validAppKey) {
|
|
2150
2067
|
const before = this.queue.length;
|
|
@@ -2155,7 +2072,6 @@ var OfflineQueueClass = class {
|
|
|
2155
2072
|
const removed = before - this.queue.length;
|
|
2156
2073
|
if (removed > 0) {
|
|
2157
2074
|
await this.saveToStorage();
|
|
2158
|
-
this.log("Cleared items with invalid app key", { removed, validAppKey });
|
|
2159
2075
|
}
|
|
2160
2076
|
return removed;
|
|
2161
2077
|
}
|
|
@@ -2409,7 +2325,6 @@ var ApiClient = class {
|
|
|
2409
2325
|
this.environment = environment;
|
|
2410
2326
|
this.offlineQueueEnabled = offlineQueueEnabled;
|
|
2411
2327
|
this.httpClient = new HttpClient(this.baseUrl, { timeout, debug });
|
|
2412
|
-
this.log("ApiClient initialized", { baseUrl: this.baseUrl, environment, offlineQueueEnabled });
|
|
2413
2328
|
}
|
|
2414
2329
|
// ─── Infrastructure ──────────────────────────────────────────────────────────
|
|
2415
2330
|
/** Exposed only for QueueProcessor initialization. Prefer get()/post() for requests. */
|
|
@@ -2433,7 +2348,6 @@ var ApiClient = class {
|
|
|
2433
2348
|
}
|
|
2434
2349
|
setEnvironment(environment) {
|
|
2435
2350
|
this.environment = environment;
|
|
2436
|
-
this.log("Environment set to:", environment);
|
|
2437
2351
|
}
|
|
2438
2352
|
setDebug(debug) {
|
|
2439
2353
|
this.debug = debug;
|
|
@@ -2463,7 +2377,6 @@ var ApiClient = class {
|
|
|
2463
2377
|
}
|
|
2464
2378
|
// ─── Business methods ────────────────────────────────────────────────────────
|
|
2465
2379
|
async trackEvent(eventName, distinctId, properties, timestamp) {
|
|
2466
|
-
this.log("Tracking event:", eventName);
|
|
2467
2380
|
await this.postWithQueue("/api/v1/events", {
|
|
2468
2381
|
eventName,
|
|
2469
2382
|
distinctId,
|
|
@@ -2474,7 +2387,6 @@ var ApiClient = class {
|
|
|
2474
2387
|
}
|
|
2475
2388
|
async identify(distinctId, properties, email) {
|
|
2476
2389
|
await this.postWithQueue("/api/v1/identify", { distinctId, properties: properties ?? {}, email, platform: Platform3.OS }, "identify");
|
|
2477
|
-
this.log("Identity updated:", distinctId);
|
|
2478
2390
|
}
|
|
2479
2391
|
async startSession(distinctId, sessionId, platform) {
|
|
2480
2392
|
await this.postWithQueue("/api/v1/sessions/start", {
|
|
@@ -2483,12 +2395,10 @@ var ApiClient = class {
|
|
|
2483
2395
|
platform: platform ?? Platform3.OS,
|
|
2484
2396
|
environment: this.environment.toLowerCase()
|
|
2485
2397
|
}, `session.start:${sessionId}`);
|
|
2486
|
-
this.log("Session started:", sessionId);
|
|
2487
2398
|
return { success: true };
|
|
2488
2399
|
}
|
|
2489
2400
|
async endSession(sessionId, durationSeconds) {
|
|
2490
2401
|
await this.postWithQueue("/api/v1/sessions/end", { sessionId, durationSeconds }, `session.end:${sessionId}`);
|
|
2491
|
-
this.log("Session ended:", sessionId);
|
|
2492
2402
|
return { success: true };
|
|
2493
2403
|
}
|
|
2494
2404
|
async getVariant(flagKey, distinctId) {
|
|
@@ -2504,7 +2414,6 @@ var ApiClient = class {
|
|
|
2504
2414
|
this.cache.setVariant(key, v);
|
|
2505
2415
|
return v;
|
|
2506
2416
|
}
|
|
2507
|
-
this.log("Got variant:", flagKey, res.data);
|
|
2508
2417
|
this.cache.setVariant(key, res.data);
|
|
2509
2418
|
return res.data;
|
|
2510
2419
|
} catch (error) {
|
|
@@ -2523,7 +2432,6 @@ var ApiClient = class {
|
|
|
2523
2432
|
this.cache.setPaywall(placement, null);
|
|
2524
2433
|
return null;
|
|
2525
2434
|
}
|
|
2526
|
-
this.log("Got paywall:", placement);
|
|
2527
2435
|
this.cache.setPaywall(placement, res.data);
|
|
2528
2436
|
return res.data;
|
|
2529
2437
|
} catch (error) {
|
|
@@ -2572,8 +2480,7 @@ var ApiClient = class {
|
|
|
2572
2480
|
country,
|
|
2573
2481
|
distinctId,
|
|
2574
2482
|
paywallPlacement,
|
|
2575
|
-
variantKey
|
|
2576
|
-
this.debug
|
|
2483
|
+
variantKey
|
|
2577
2484
|
);
|
|
2578
2485
|
this.log("Purchase validated:", result.success);
|
|
2579
2486
|
return result;
|
|
@@ -2619,7 +2526,7 @@ var ApiClient = class {
|
|
|
2619
2526
|
}
|
|
2620
2527
|
}
|
|
2621
2528
|
log(...args) {
|
|
2622
|
-
if (this.debug) console.warn("[
|
|
2529
|
+
if (this.debug) console.warn("[Paywallo API]", ...args);
|
|
2623
2530
|
}
|
|
2624
2531
|
};
|
|
2625
2532
|
|
|
@@ -2945,7 +2852,6 @@ var SessionManager = class {
|
|
|
2945
2852
|
this.setupAppStateListener();
|
|
2946
2853
|
}
|
|
2947
2854
|
this.initialized = true;
|
|
2948
|
-
this.log("SessionManager initialized");
|
|
2949
2855
|
}
|
|
2950
2856
|
async startSession() {
|
|
2951
2857
|
this.ensureInitialized();
|
|
@@ -2961,7 +2867,6 @@ var SessionManager = class {
|
|
|
2961
2867
|
this.secureStorage.remove(EMERGENCY_PAYWALL_SHOWN_KEY)
|
|
2962
2868
|
]);
|
|
2963
2869
|
await this.trackSessionStart();
|
|
2964
|
-
this.log("Session started:", this.sessionId);
|
|
2965
2870
|
return this.sessionId;
|
|
2966
2871
|
}
|
|
2967
2872
|
async endSession() {
|
|
@@ -2976,7 +2881,6 @@ var SessionManager = class {
|
|
|
2976
2881
|
this.secureStorage.remove(SESSION_ID_KEY),
|
|
2977
2882
|
this.secureStorage.remove(SESSION_START_KEY)
|
|
2978
2883
|
]);
|
|
2979
|
-
this.log("Session ended");
|
|
2980
2884
|
}
|
|
2981
2885
|
getSessionId() {
|
|
2982
2886
|
return this.sessionId;
|
|
@@ -3172,12 +3076,8 @@ var InstallTracker = class {
|
|
|
3172
3076
|
attStatus: adIds.attStatus
|
|
3173
3077
|
});
|
|
3174
3078
|
const stored = await storage.set("install_tracked", String(installedAt));
|
|
3175
|
-
if (this.debug) {
|
|
3176
|
-
|
|
3177
|
-
console.warn("[Paywallo] Install event tracked");
|
|
3178
|
-
} else {
|
|
3179
|
-
console.warn("[Paywallo] Install event tracked but flag storage failed \u2014 may re-track on next launch");
|
|
3180
|
-
}
|
|
3079
|
+
if (this.debug && !stored) {
|
|
3080
|
+
console.warn("[Paywallo] Install event tracked but flag storage failed \u2014 may re-track on next launch");
|
|
3181
3081
|
}
|
|
3182
3082
|
} catch (error) {
|
|
3183
3083
|
if (this.debug) {
|
|
@@ -3264,7 +3164,6 @@ var PaywalloClientClass = class {
|
|
|
3264
3164
|
}
|
|
3265
3165
|
if (!isValidEventName(eventName)) {
|
|
3266
3166
|
const msg = `Invalid event name: "${eventName}". Use snake_case or $reserved_name.`;
|
|
3267
|
-
if (this.config?.debug) console.warn("[Paywallo]", msg);
|
|
3268
3167
|
throw new ClientError(CLIENT_ERROR_CODES.INVALID_EVENT_NAME, msg);
|
|
3269
3168
|
}
|
|
3270
3169
|
const sessionId = sessionManager.getSessionId();
|
|
@@ -3283,7 +3182,6 @@ var PaywalloClientClass = class {
|
|
|
3283
3182
|
}
|
|
3284
3183
|
if (!Number.isInteger(index) || index < 0) {
|
|
3285
3184
|
const msg = `Invalid stepIndex: "${index}". Must be a non-negative integer.`;
|
|
3286
|
-
if (this.config?.debug) console.warn("[Paywallo]", msg);
|
|
3287
3185
|
throw new AnalyticsError(ANALYTICS_ERROR_CODES.INVALID_STEP_INDEX, msg);
|
|
3288
3186
|
}
|
|
3289
3187
|
const now = Date.now();
|
|
@@ -3308,7 +3206,6 @@ var PaywalloClientClass = class {
|
|
|
3308
3206
|
}
|
|
3309
3207
|
if (!actionName || typeof actionName !== "string") {
|
|
3310
3208
|
const msg = `Invalid actionName: "${actionName}". Must be a non-empty string.`;
|
|
3311
|
-
if (this.config?.debug) console.warn("[Paywallo]", msg);
|
|
3312
3209
|
throw new AnalyticsError(ANALYTICS_ERROR_CODES.INVALID_ACTION_NAME, msg);
|
|
3313
3210
|
}
|
|
3314
3211
|
const sessionId = sessionManager.getSessionId();
|
|
@@ -3826,7 +3723,6 @@ var SubscriptionManagerClass = class {
|
|
|
3826
3723
|
if (config.cacheTTL) {
|
|
3827
3724
|
this.cache.setTTL(config.cacheTTL);
|
|
3828
3725
|
}
|
|
3829
|
-
this.log("SubscriptionManager initialized");
|
|
3830
3726
|
}
|
|
3831
3727
|
setUserId(userId) {
|
|
3832
3728
|
if (this.userId !== userId) {
|
|
@@ -4159,7 +4055,7 @@ function useProductLoader() {
|
|
|
4159
4055
|
for (const p of loaded) map.set(p.productId, p);
|
|
4160
4056
|
setProducts(map);
|
|
4161
4057
|
} catch (error) {
|
|
4162
|
-
if (PaywalloClient.getConfig()?.debug) console.warn("[
|
|
4058
|
+
if (PaywalloClient.getConfig()?.debug) console.warn("[Paywallo] Product load failed:", error);
|
|
4163
4059
|
} finally {
|
|
4164
4060
|
setIsLoadingProducts(false);
|
|
4165
4061
|
}
|
|
@@ -4198,7 +4094,7 @@ function usePurchaseOrchestrator(preloadedWebView, resolvePreloadedPaywall, clea
|
|
|
4198
4094
|
clearPreloadedWebView();
|
|
4199
4095
|
resolvePreloadedPaywall({ presented: true, purchased: true, cancelled: false, restored: false });
|
|
4200
4096
|
} catch (error) {
|
|
4201
|
-
if (PaywalloClient.getConfig()?.debug) console.warn("[
|
|
4097
|
+
if (PaywalloClient.getConfig()?.debug) console.warn("[Paywallo] Preloaded purchase error:", error);
|
|
4202
4098
|
setShowingPreloadedWebView(false);
|
|
4203
4099
|
clearPreloadedWebView();
|
|
4204
4100
|
resolvePreloadedPaywall({ presented: true, purchased: false, cancelled: false, restored: false });
|
|
@@ -4218,7 +4114,7 @@ function usePurchaseOrchestrator(preloadedWebView, resolvePreloadedPaywall, clea
|
|
|
4218
4114
|
clearPreloadedWebView();
|
|
4219
4115
|
resolvePreloadedPaywall({ presented: true, purchased: false, cancelled: false, restored: true });
|
|
4220
4116
|
} catch (error) {
|
|
4221
|
-
if (PaywalloClient.getConfig()?.debug) console.warn("[
|
|
4117
|
+
if (PaywalloClient.getConfig()?.debug) console.warn("[Paywallo] Preloaded restore error:", error);
|
|
4222
4118
|
setShowingPreloadedWebView(false);
|
|
4223
4119
|
clearPreloadedWebView();
|
|
4224
4120
|
resolvePreloadedPaywall({ presented: true, purchased: false, cancelled: false, restored: false });
|