@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.js
CHANGED
|
@@ -696,17 +696,25 @@ var IAPService = class {
|
|
|
696
696
|
error: new PurchaseError(PURCHASE_ERROR_CODES.STORE_NOT_AVAILABLE, "In-app purchases are not available on this device")
|
|
697
697
|
};
|
|
698
698
|
}
|
|
699
|
+
const debug = PaywalloClient.getConfig()?.debug;
|
|
700
|
+
if (debug) console.info(`[Paywallo PURCHASE] starting ${productId}`);
|
|
699
701
|
try {
|
|
700
702
|
const purchase = await nativeStoreKit.purchase(productId);
|
|
701
703
|
if (!purchase) {
|
|
704
|
+
if (debug) console.info(`[Paywallo PURCHASE] ${productId} cancelled`);
|
|
702
705
|
return { success: false };
|
|
703
706
|
}
|
|
707
|
+
if (debug) console.info(`[Paywallo PURCHASE] ${productId} approved`, { transactionId: purchase.transactionId });
|
|
704
708
|
await this.finishTransaction(purchase.transactionId);
|
|
705
|
-
|
|
706
|
-
|
|
709
|
+
if (debug) console.info(`[Paywallo PURCHASE] ${productId} finished`);
|
|
710
|
+
this.validateWithServer(purchase, productId, options).then(() => {
|
|
711
|
+
if (debug) console.info(`[Paywallo PURCHASE] ${productId} server validated`);
|
|
712
|
+
}).catch((err) => {
|
|
713
|
+
if (debug) console.warn("[Paywallo PURCHASE] background validation failed", err);
|
|
707
714
|
});
|
|
708
715
|
return { success: true, purchase };
|
|
709
716
|
} catch (error) {
|
|
717
|
+
if (debug) console.warn(`[Paywallo PURCHASE] ${productId} failed`, error);
|
|
710
718
|
const e = error instanceof PurchaseError ? error : new PurchaseError(PURCHASE_ERROR_CODES.PURCHASE_FAILED, error instanceof Error ? error.message : String(error));
|
|
711
719
|
return { success: false, error: e };
|
|
712
720
|
}
|
|
@@ -2879,7 +2887,7 @@ var ApiCache = class {
|
|
|
2879
2887
|
};
|
|
2880
2888
|
|
|
2881
2889
|
// src/core/ApiClient.ts
|
|
2882
|
-
var SDK_VERSION = "1.4.
|
|
2890
|
+
var SDK_VERSION = "1.4.1";
|
|
2883
2891
|
var _ApiClient = class _ApiClient {
|
|
2884
2892
|
constructor(appKey, apiUrl, debug = false, environment = "Production", offlineQueueEnabled = true, timeout = 3e4) {
|
|
2885
2893
|
this.cache = new ApiCache();
|
|
@@ -2978,6 +2986,7 @@ var _ApiClient = class _ApiClient {
|
|
|
2978
2986
|
try {
|
|
2979
2987
|
const res = await this.get(`/api/v1/flags/${flagKey}?distinctId=${encodeURIComponent(distinctId)}`);
|
|
2980
2988
|
if (res.status === 404) {
|
|
2989
|
+
this.log("Flag not found (404):", flagKey);
|
|
2981
2990
|
const v = { variant: null };
|
|
2982
2991
|
this.cache.setVariant(key, v, this.cache.nullTTL);
|
|
2983
2992
|
return v;
|
|
@@ -3004,6 +3013,7 @@ var _ApiClient = class _ApiClient {
|
|
|
3004
3013
|
try {
|
|
3005
3014
|
const res = await this.get(`/api/v1/paywalls/${placement}`);
|
|
3006
3015
|
if (res.status === 404) {
|
|
3016
|
+
this.log("Paywall not found (404):", placement);
|
|
3007
3017
|
this.cache.setPaywall(placement, null, this.cache.nullTTL);
|
|
3008
3018
|
return null;
|
|
3009
3019
|
}
|
|
@@ -3055,6 +3065,7 @@ var _ApiClient = class _ApiClient {
|
|
|
3055
3065
|
try {
|
|
3056
3066
|
const res = await this.get(`/campaigns/public/primary?distinctId=${encodeURIComponent(distinctId)}`);
|
|
3057
3067
|
if (res.status === 404) {
|
|
3068
|
+
this.log("Primary campaign not found (404)");
|
|
3058
3069
|
this.cache.setCampaign(key, null, this.cache.nullTTL);
|
|
3059
3070
|
return null;
|
|
3060
3071
|
}
|
|
@@ -3105,7 +3116,7 @@ var _ApiClient = class _ApiClient {
|
|
|
3105
3116
|
headers: { "X-App-Key": this.appKey, "x-distinct-id": distinctId }
|
|
3106
3117
|
});
|
|
3107
3118
|
if (!res.ok) {
|
|
3108
|
-
this.log("
|
|
3119
|
+
this.log("evaluateFlags failed:", res.status, keys);
|
|
3109
3120
|
return {};
|
|
3110
3121
|
}
|
|
3111
3122
|
const raw = res.data;
|
|
@@ -4079,18 +4090,21 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4079
4090
|
}
|
|
4080
4091
|
async identify(options) {
|
|
4081
4092
|
this.ensureInitialized();
|
|
4093
|
+
if (this.config?.debug) console.info("[Paywallo IDENTIFY]", options);
|
|
4082
4094
|
await identityManager.identify(options);
|
|
4083
4095
|
}
|
|
4084
4096
|
async track(eventName, options) {
|
|
4085
4097
|
const apiClient = this.getApiClientOrThrow();
|
|
4086
4098
|
const distinctId = identityManager.getDistinctId();
|
|
4087
4099
|
if (!distinctId) {
|
|
4100
|
+
if (this.config?.debug) console.info(`[Paywallo TRACK] ${eventName} skipped (no distinctId)`);
|
|
4088
4101
|
return;
|
|
4089
4102
|
}
|
|
4090
4103
|
if (!isValidEventName(eventName)) {
|
|
4091
4104
|
const msg = `Invalid event name: "${eventName}". Use snake_case or $reserved_name.`;
|
|
4092
4105
|
throw new ClientError(CLIENT_ERROR_CODES.INVALID_EVENT_NAME, msg);
|
|
4093
4106
|
}
|
|
4107
|
+
if (this.config?.debug && eventName.startsWith("$purchase")) console.info(`[Paywallo TRACK] ${eventName}`, options?.properties ?? {});
|
|
4094
4108
|
const sessionId = sessionManager.getSessionId();
|
|
4095
4109
|
await apiClient.trackEvent(eventName, distinctId, {
|
|
4096
4110
|
...identityManager.getProperties(),
|
|
@@ -4111,14 +4125,10 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4111
4125
|
const now = Date.now();
|
|
4112
4126
|
const timeOnPreviousStep = this.lastOnboardingStepTimestamp !== null ? Math.round((now - this.lastOnboardingStepTimestamp) / 1e3) : 0;
|
|
4113
4127
|
this.lastOnboardingStepTimestamp = now;
|
|
4114
|
-
const sessionId = sessionManager.getSessionId();
|
|
4115
4128
|
await apiClient.trackEvent("$onboarding_step", distinctId, {
|
|
4116
|
-
...identityManager.getProperties(),
|
|
4117
4129
|
stepIndex: index,
|
|
4118
4130
|
stepName: name,
|
|
4119
|
-
|
|
4120
|
-
timeOnPreviousStep,
|
|
4121
|
-
...sessionId && { sessionId }
|
|
4131
|
+
timeOnPreviousStep
|
|
4122
4132
|
});
|
|
4123
4133
|
}
|
|
4124
4134
|
async coreAction(actionName) {
|
|
@@ -4153,10 +4163,14 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4153
4163
|
try {
|
|
4154
4164
|
const distinctId = identityManager.getDistinctId();
|
|
4155
4165
|
if (!distinctId) {
|
|
4166
|
+
if (this.config?.debug) console.info(`[Paywallo FLAG] ${flagKey} \u2192 null (no distinctId)`);
|
|
4156
4167
|
return { variant: null };
|
|
4157
4168
|
}
|
|
4158
|
-
|
|
4169
|
+
const result = await this.getApiClientOrThrow().getVariant(flagKey, distinctId);
|
|
4170
|
+
if (this.config?.debug) console.info(`[Paywallo FLAG] ${flagKey} \u2192`, result.variant);
|
|
4171
|
+
return result;
|
|
4159
4172
|
} catch (error) {
|
|
4173
|
+
if (this.config?.debug) console.warn(`[Paywallo FLAG] ${flagKey} \u2192 error`, error);
|
|
4160
4174
|
if (this.apiClient) void this.apiClient.reportError("GET_VARIANT_FAILED", error instanceof Error ? error.message : String(error));
|
|
4161
4175
|
return { variant: null };
|
|
4162
4176
|
}
|
|
@@ -4189,21 +4203,34 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4189
4203
|
}
|
|
4190
4204
|
async presentCampaign(placement, context) {
|
|
4191
4205
|
this.ensureInitialized();
|
|
4192
|
-
|
|
4206
|
+
if (this.config?.debug) console.info(`[Paywallo CAMPAIGN] presenting ${placement}`);
|
|
4207
|
+
const result = await campaignGateService.presentCampaign(this.getApiClientOrThrow(), placement, () => this.hasActiveSubscription(), this.paywallPresenter, this.campaignPresenter, context);
|
|
4208
|
+
if (this.config?.debug) {
|
|
4209
|
+
if (result.error) console.warn(`[Paywallo CAMPAIGN] ${placement} error:`, result.error.message);
|
|
4210
|
+
else console.info(`[Paywallo CAMPAIGN] ${placement} result:`, { purchased: result.purchased, cancelled: result.cancelled, restored: result.restored, skippedReason: result.skippedReason });
|
|
4211
|
+
}
|
|
4212
|
+
return result;
|
|
4193
4213
|
}
|
|
4194
4214
|
async hasActiveSubscription() {
|
|
4195
4215
|
this.ensureInitialized();
|
|
4196
4216
|
try {
|
|
4197
4217
|
if (this.activeChecker) {
|
|
4198
|
-
|
|
4218
|
+
const result = await this.activeChecker();
|
|
4219
|
+
const isActive2 = result === true;
|
|
4220
|
+
if (this.config?.debug) console.info("[Paywallo SUB] hasActiveSubscription (checker):", isActive2);
|
|
4221
|
+
return isActive2;
|
|
4199
4222
|
}
|
|
4200
4223
|
const distinctId = identityManager.getDistinctId();
|
|
4201
4224
|
if (!distinctId || !this.apiClient) {
|
|
4225
|
+
if (this.config?.debug) console.info("[Paywallo SUB] hasActiveSubscription: false (no distinctId/apiClient)");
|
|
4202
4226
|
return false;
|
|
4203
4227
|
}
|
|
4204
4228
|
const status = await this.apiClient.getSubscriptionStatus(distinctId);
|
|
4205
|
-
|
|
4229
|
+
const isActive = status.hasActiveSubscription === true;
|
|
4230
|
+
if (this.config?.debug) console.info("[Paywallo SUB] hasActiveSubscription (server):", isActive);
|
|
4231
|
+
return isActive;
|
|
4206
4232
|
} catch (error) {
|
|
4233
|
+
if (this.config?.debug) console.warn("[Paywallo SUB] hasActiveSubscription error", error);
|
|
4207
4234
|
if (this.apiClient) void this.apiClient.reportError("SUBSCRIPTION_CHECK_FAILED", error instanceof Error ? error.message : "hasActiveSubscription failed");
|
|
4208
4235
|
return false;
|
|
4209
4236
|
}
|
|
@@ -4224,7 +4251,10 @@ var _PaywalloClientClass = class _PaywalloClientClass {
|
|
|
4224
4251
|
async restorePurchases() {
|
|
4225
4252
|
this.ensureInitialized();
|
|
4226
4253
|
if (!this.restoreHandler) throw new PaywallError(PAYWALL_ERROR_CODES.NOT_INITIALIZED, "PaywalloProvider not mounted. Wrap your app with <PaywalloProvider>");
|
|
4227
|
-
|
|
4254
|
+
if (this.config?.debug) console.info("[Paywallo RESTORE] starting");
|
|
4255
|
+
const result = await this.restoreHandler();
|
|
4256
|
+
if (this.config?.debug) console.info("[Paywallo RESTORE] result:", { success: result.success, restoredProducts: result.restoredProducts?.length ?? 0 });
|
|
4257
|
+
return result;
|
|
4228
4258
|
}
|
|
4229
4259
|
async reset() {
|
|
4230
4260
|
await identityManager.reset();
|
|
@@ -4964,7 +4994,7 @@ function useSubscriptionSync() {
|
|
|
4964
4994
|
cacheRef.current = { data: sub, expiresAt: Date.now() + CACHE_TTL_MS2 };
|
|
4965
4995
|
setSubscription(sub);
|
|
4966
4996
|
void subscriptionCache.set(distinctId, toDomainResponse(status));
|
|
4967
|
-
return status.hasActiveSubscription;
|
|
4997
|
+
return status.hasActiveSubscription === true;
|
|
4968
4998
|
} catch {
|
|
4969
4999
|
return await resolveOfflineFromCache(distinctId);
|
|
4970
5000
|
}
|