@virex-tech/paywallo-sdk 1.4.0 → 1.4.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.js +45 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -15
- package/dist/index.mjs.map +1 -1
- package/ios/PaywalloFBBridge.swift +1 -1
- package/ios/PaywalloStoreKit.swift +17 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -619,17 +619,25 @@ var IAPService = class {
|
|
|
619
619
|
error: new PurchaseError(PURCHASE_ERROR_CODES.STORE_NOT_AVAILABLE, "In-app purchases are not available on this device")
|
|
620
620
|
};
|
|
621
621
|
}
|
|
622
|
+
const debug = PaywalloClient.getConfig()?.debug;
|
|
623
|
+
if (debug) console.info(`[Paywallo PURCHASE] starting ${productId}`);
|
|
622
624
|
try {
|
|
623
625
|
const purchase = await nativeStoreKit.purchase(productId);
|
|
624
626
|
if (!purchase) {
|
|
627
|
+
if (debug) console.info(`[Paywallo PURCHASE] ${productId} cancelled`);
|
|
625
628
|
return { success: false };
|
|
626
629
|
}
|
|
630
|
+
if (debug) console.info(`[Paywallo PURCHASE] ${productId} approved`, { transactionId: purchase.transactionId });
|
|
627
631
|
await this.finishTransaction(purchase.transactionId);
|
|
628
|
-
|
|
629
|
-
|
|
632
|
+
if (debug) console.info(`[Paywallo PURCHASE] ${productId} finished`);
|
|
633
|
+
this.validateWithServer(purchase, productId, options).then(() => {
|
|
634
|
+
if (debug) console.info(`[Paywallo PURCHASE] ${productId} server validated`);
|
|
635
|
+
}).catch((err) => {
|
|
636
|
+
if (debug) console.warn("[Paywallo PURCHASE] background validation failed", err);
|
|
630
637
|
});
|
|
631
638
|
return { success: true, purchase };
|
|
632
639
|
} catch (error) {
|
|
640
|
+
if (debug) console.warn(`[Paywallo PURCHASE] ${productId} failed`, error);
|
|
633
641
|
const e = error instanceof PurchaseError ? error : new PurchaseError(PURCHASE_ERROR_CODES.PURCHASE_FAILED, error instanceof Error ? error.message : String(error));
|
|
634
642
|
return { success: false, error: e };
|
|
635
643
|
}
|
|
@@ -2809,7 +2817,7 @@ var ApiCache = class {
|
|
|
2809
2817
|
};
|
|
2810
2818
|
|
|
2811
2819
|
// src/core/ApiClient.ts
|
|
2812
|
-
var SDK_VERSION = "1.4.
|
|
2820
|
+
var SDK_VERSION = "1.4.1";
|
|
2813
2821
|
var _ApiClient = class _ApiClient {
|
|
2814
2822
|
constructor(appKey, apiUrl, debug = false, environment = "Production", offlineQueueEnabled = true, timeout = 3e4) {
|
|
2815
2823
|
this.cache = new ApiCache();
|
|
@@ -2908,6 +2916,7 @@ var _ApiClient = class _ApiClient {
|
|
|
2908
2916
|
try {
|
|
2909
2917
|
const res = await this.get(`/api/v1/flags/${flagKey}?distinctId=${encodeURIComponent(distinctId)}`);
|
|
2910
2918
|
if (res.status === 404) {
|
|
2919
|
+
this.log("Flag not found (404):", flagKey);
|
|
2911
2920
|
const v = { variant: null };
|
|
2912
2921
|
this.cache.setVariant(key, v, this.cache.nullTTL);
|
|
2913
2922
|
return v;
|
|
@@ -2934,6 +2943,7 @@ var _ApiClient = class _ApiClient {
|
|
|
2934
2943
|
try {
|
|
2935
2944
|
const res = await this.get(`/api/v1/paywalls/${placement}`);
|
|
2936
2945
|
if (res.status === 404) {
|
|
2946
|
+
this.log("Paywall not found (404):", placement);
|
|
2937
2947
|
this.cache.setPaywall(placement, null, this.cache.nullTTL);
|
|
2938
2948
|
return null;
|
|
2939
2949
|
}
|
|
@@ -2985,6 +2995,7 @@ var _ApiClient = class _ApiClient {
|
|
|
2985
2995
|
try {
|
|
2986
2996
|
const res = await this.get(`/campaigns/public/primary?distinctId=${encodeURIComponent(distinctId)}`);
|
|
2987
2997
|
if (res.status === 404) {
|
|
2998
|
+
this.log("Primary campaign not found (404)");
|
|
2988
2999
|
this.cache.setCampaign(key, null, this.cache.nullTTL);
|
|
2989
3000
|
return null;
|
|
2990
3001
|
}
|
|
@@ -3035,7 +3046,7 @@ var _ApiClient = class _ApiClient {
|
|
|
3035
3046
|
headers: { "X-App-Key": this.appKey, "x-distinct-id": distinctId }
|
|
3036
3047
|
});
|
|
3037
3048
|
if (!res.ok) {
|
|
3038
|
-
this.log("
|
|
3049
|
+
this.log("evaluateFlags failed:", res.status, keys);
|
|
3039
3050
|
return {};
|
|
3040
3051
|
}
|
|
3041
3052
|
const raw = res.data;
|
|
@@ -4009,18 +4020,21 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4009
4020
|
}
|
|
4010
4021
|
async identify(options) {
|
|
4011
4022
|
this.ensureInitialized();
|
|
4023
|
+
if (this.config?.debug) console.info("[Paywallo IDENTIFY]", options);
|
|
4012
4024
|
await identityManager.identify(options);
|
|
4013
4025
|
}
|
|
4014
4026
|
async track(eventName, options) {
|
|
4015
4027
|
const apiClient = this.getApiClientOrThrow();
|
|
4016
4028
|
const distinctId = identityManager.getDistinctId();
|
|
4017
4029
|
if (!distinctId) {
|
|
4030
|
+
if (this.config?.debug) console.info(`[Paywallo TRACK] ${eventName} skipped (no distinctId)`);
|
|
4018
4031
|
return;
|
|
4019
4032
|
}
|
|
4020
4033
|
if (!isValidEventName(eventName)) {
|
|
4021
4034
|
const msg = `Invalid event name: "${eventName}". Use snake_case or $reserved_name.`;
|
|
4022
4035
|
throw new ClientError(CLIENT_ERROR_CODES.INVALID_EVENT_NAME, msg);
|
|
4023
4036
|
}
|
|
4037
|
+
if (this.config?.debug && eventName.startsWith("$purchase")) console.info(`[Paywallo TRACK] ${eventName}`, options?.properties ?? {});
|
|
4024
4038
|
const sessionId = sessionManager.getSessionId();
|
|
4025
4039
|
await apiClient.trackEvent(eventName, distinctId, {
|
|
4026
4040
|
...identityManager.getProperties(),
|
|
@@ -4041,14 +4055,10 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4041
4055
|
const now = Date.now();
|
|
4042
4056
|
const timeOnPreviousStep = this.lastOnboardingStepTimestamp !== null ? Math.round((now - this.lastOnboardingStepTimestamp) / 1e3) : 0;
|
|
4043
4057
|
this.lastOnboardingStepTimestamp = now;
|
|
4044
|
-
const sessionId = sessionManager.getSessionId();
|
|
4045
4058
|
await apiClient.trackEvent("$onboarding_step", distinctId, {
|
|
4046
|
-
...identityManager.getProperties(),
|
|
4047
4059
|
stepIndex: index,
|
|
4048
4060
|
stepName: name,
|
|
4049
|
-
|
|
4050
|
-
timeOnPreviousStep,
|
|
4051
|
-
...sessionId && { sessionId }
|
|
4061
|
+
timeOnPreviousStep
|
|
4052
4062
|
});
|
|
4053
4063
|
}
|
|
4054
4064
|
async coreAction(actionName) {
|
|
@@ -4083,10 +4093,14 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4083
4093
|
try {
|
|
4084
4094
|
const distinctId = identityManager.getDistinctId();
|
|
4085
4095
|
if (!distinctId) {
|
|
4096
|
+
if (this.config?.debug) console.info(`[Paywallo FLAG] ${flagKey} \u2192 null (no distinctId)`);
|
|
4086
4097
|
return { variant: null };
|
|
4087
4098
|
}
|
|
4088
|
-
|
|
4099
|
+
const result = await this.getApiClientOrThrow().getVariant(flagKey, distinctId);
|
|
4100
|
+
if (this.config?.debug) console.info(`[Paywallo FLAG] ${flagKey} \u2192`, result.variant);
|
|
4101
|
+
return result;
|
|
4089
4102
|
} catch (error) {
|
|
4103
|
+
if (this.config?.debug) console.warn(`[Paywallo FLAG] ${flagKey} \u2192 error`, error);
|
|
4090
4104
|
if (this.apiClient) void this.apiClient.reportError("GET_VARIANT_FAILED", error instanceof Error ? error.message : String(error));
|
|
4091
4105
|
return { variant: null };
|
|
4092
4106
|
}
|
|
@@ -4119,21 +4133,34 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4119
4133
|
}
|
|
4120
4134
|
async presentCampaign(placement, context) {
|
|
4121
4135
|
this.ensureInitialized();
|
|
4122
|
-
|
|
4136
|
+
if (this.config?.debug) console.info(`[Paywallo CAMPAIGN] presenting ${placement}`);
|
|
4137
|
+
const result = await campaignGateService.presentCampaign(this.getApiClientOrThrow(), placement, () => this.hasActiveSubscription(), this.paywallPresenter, this.campaignPresenter, context);
|
|
4138
|
+
if (this.config?.debug) {
|
|
4139
|
+
if (result.error) console.warn(`[Paywallo CAMPAIGN] ${placement} error:`, result.error.message);
|
|
4140
|
+
else console.info(`[Paywallo CAMPAIGN] ${placement} result:`, { purchased: result.purchased, cancelled: result.cancelled, restored: result.restored, skippedReason: result.skippedReason });
|
|
4141
|
+
}
|
|
4142
|
+
return result;
|
|
4123
4143
|
}
|
|
4124
4144
|
async hasActiveSubscription() {
|
|
4125
4145
|
this.ensureInitialized();
|
|
4126
4146
|
try {
|
|
4127
4147
|
if (this.activeChecker) {
|
|
4128
|
-
|
|
4148
|
+
const result = await this.activeChecker();
|
|
4149
|
+
const isActive2 = result === true;
|
|
4150
|
+
if (this.config?.debug) console.info("[Paywallo SUB] hasActiveSubscription (checker):", isActive2);
|
|
4151
|
+
return isActive2;
|
|
4129
4152
|
}
|
|
4130
4153
|
const distinctId = identityManager.getDistinctId();
|
|
4131
4154
|
if (!distinctId || !this.apiClient) {
|
|
4155
|
+
if (this.config?.debug) console.info("[Paywallo SUB] hasActiveSubscription: false (no distinctId/apiClient)");
|
|
4132
4156
|
return false;
|
|
4133
4157
|
}
|
|
4134
4158
|
const status = await this.apiClient.getSubscriptionStatus(distinctId);
|
|
4135
|
-
|
|
4159
|
+
const isActive = status.hasActiveSubscription === true;
|
|
4160
|
+
if (this.config?.debug) console.info("[Paywallo SUB] hasActiveSubscription (server):", isActive);
|
|
4161
|
+
return isActive;
|
|
4136
4162
|
} catch (error) {
|
|
4163
|
+
if (this.config?.debug) console.warn("[Paywallo SUB] hasActiveSubscription error", error);
|
|
4137
4164
|
if (this.apiClient) void this.apiClient.reportError("SUBSCRIPTION_CHECK_FAILED", error instanceof Error ? error.message : "hasActiveSubscription failed");
|
|
4138
4165
|
return false;
|
|
4139
4166
|
}
|
|
@@ -4154,7 +4181,10 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4154
4181
|
async restorePurchases() {
|
|
4155
4182
|
this.ensureInitialized();
|
|
4156
4183
|
if (!this.restoreHandler) throw new PaywallError(PAYWALL_ERROR_CODES.NOT_INITIALIZED, "PaywalloProvider not mounted. Wrap your app with <PaywalloProvider>");
|
|
4157
|
-
|
|
4184
|
+
if (this.config?.debug) console.info("[Paywallo RESTORE] starting");
|
|
4185
|
+
const result = await this.restoreHandler();
|
|
4186
|
+
if (this.config?.debug) console.info("[Paywallo RESTORE] result:", { success: result.success, restoredProducts: result.restoredProducts?.length ?? 0 });
|
|
4187
|
+
return result;
|
|
4158
4188
|
}
|
|
4159
4189
|
async reset() {
|
|
4160
4190
|
await identityManager.reset();
|
|
@@ -4894,7 +4924,7 @@ function useSubscriptionSync() {
|
|
|
4894
4924
|
cacheRef.current = { data: sub, expiresAt: Date.now() + CACHE_TTL_MS2 };
|
|
4895
4925
|
setSubscription(sub);
|
|
4896
4926
|
void subscriptionCache.set(distinctId, toDomainResponse(status));
|
|
4897
|
-
return status.hasActiveSubscription;
|
|
4927
|
+
return status.hasActiveSubscription === true;
|
|
4898
4928
|
} catch {
|
|
4899
4929
|
return await resolveOfflineFromCache(distinctId);
|
|
4900
4930
|
}
|