react-native-revnix 1.8.0 → 1.11.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/README.md CHANGED
@@ -104,6 +104,7 @@ Your API key and deployment URL are in the dashboard under Settings. See [API ke
104
104
  **Revnix handles the hard parts of subscriptions in a small, developer-friendly SDK.**
105
105
 
106
106
  - `purchase(productId)` runs the whole flow: store sheet, server-side receipt validation, entitlement, transaction finish. `restore()` brings purchases back on a new device.
107
+ - Consumables on Google Play: list their ids in `consumableProductIds` so they are consumed after Revnix records the purchase and can be bought again.
107
108
  - Renewals, purchases on other devices and Ask to Buy approvals arrive on their own and are registered automatically.
108
109
  - Entitlements and placements are cached on device, so paid users stay unlocked offline.
109
110
  - Failed registrations are retried automatically when the app comes back online.
@@ -9,6 +9,7 @@ import com.android.billingclient.api.BillingClient.ProductType
9
9
  import com.android.billingclient.api.BillingClientStateListener
10
10
  import com.android.billingclient.api.BillingFlowParams
11
11
  import com.android.billingclient.api.BillingResult
12
+ import com.android.billingclient.api.ConsumeParams
12
13
  import com.android.billingclient.api.PendingPurchasesParams
13
14
  import com.android.billingclient.api.ProductDetails
14
15
  import com.android.billingclient.api.Purchase
@@ -96,10 +97,9 @@ class RevnixStoreModule(context: ReactApplicationContext) :
96
97
  }
97
98
  }
98
99
 
99
- // ponytail: acknowledges every purchase; consumable INAPP products need consumeAsync to be bought again
100
100
  @ReactMethod
101
- fun finish(purchaseToken: String, promise: Promise) {
102
- if (purchaseToken in acknowledged) {
101
+ fun finish(purchaseToken: String, consume: Boolean, promise: Promise) {
102
+ if (!consume && purchaseToken in acknowledged) {
103
103
  promise.resolve(null)
104
104
  return
105
105
  }
@@ -108,13 +108,32 @@ class RevnixStoreModule(context: ReactApplicationContext) :
108
108
  promise.reject("store_error", "${setup.responseCode} ${setup.debugMessage}")
109
109
  return@withBilling
110
110
  }
111
- val params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchaseToken).build()
112
- billing.acknowledgePurchase(params) { result ->
113
- if (result.responseCode == BillingResponseCode.OK) {
111
+ val acknowledge = { onResult: (BillingResult) -> Unit ->
112
+ val params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchaseToken).build()
113
+ billing.acknowledgePurchase(params) { result ->
114
+ if (result.responseCode == BillingResponseCode.OK) acknowledged.add(purchaseToken)
115
+ onResult(result)
116
+ }
117
+ }
118
+ if (!consume) {
119
+ acknowledge { result ->
120
+ if (result.responseCode == BillingResponseCode.OK) promise.resolve(null)
121
+ else promise.reject("store_error", "acknowledgePurchase failed: ${result.responseCode} ${result.debugMessage}")
122
+ }
123
+ return@withBilling
124
+ }
125
+ val params = ConsumeParams.newBuilder().setPurchaseToken(purchaseToken).build()
126
+ billing.consumeAsync(params) { consumed, _ ->
127
+ if (consumed.responseCode == BillingResponseCode.OK) {
114
128
  acknowledged.add(purchaseToken)
115
129
  promise.resolve(null)
116
130
  } else {
117
- promise.reject("store_error", "acknowledgePurchase failed: ${result.responseCode} ${result.debugMessage}")
131
+ acknowledge { acked ->
132
+ promise.reject(
133
+ "store_error",
134
+ "consumeAsync failed: ${consumed.responseCode} ${consumed.debugMessage}; acknowledgePurchase fallback: ${acked.responseCode} ${acked.debugMessage}",
135
+ )
136
+ }
118
137
  }
119
138
  }
120
139
  }
@@ -193,7 +212,7 @@ class RevnixStoreModule(context: ReactApplicationContext) :
193
212
  if (result.responseCode == BillingResponseCode.OK) {
194
213
  queryPurchases(ProductType.SUBS) { subs ->
195
214
  queryPurchases(ProductType.INAPP) { inapp ->
196
- (subs + inapp).filterNot { it.isAcknowledged }.forEach { emit(toMap(it)) }
215
+ (subs.filterNot { it.isAcknowledged } + inapp).forEach { emit(toMap(it)) }
197
216
  }
198
217
  }
199
218
  }
@@ -210,7 +229,7 @@ class RevnixStoreModule(context: ReactApplicationContext) :
210
229
  BillingResponseCode.ITEM_ALREADY_OWNED -> queryPurchases(ProductType.SUBS) { subs ->
211
230
  queryPurchases(ProductType.INAPP) { inapp ->
212
231
  val owned = (subs + inapp).firstOrNull { waiting.productId in it.products }
213
- if (owned != null) waiting.promise.resolve(toMap(owned))
232
+ if (owned != null) waiting.promise.resolve(toMap(owned).apply { putBoolean("alreadyOwned", true) })
214
233
  else waiting.promise.reject("store_error", "${result.responseCode} ${result.debugMessage}")
215
234
  }
216
235
  }
@@ -274,6 +293,7 @@ class RevnixStoreModule(context: ReactApplicationContext) :
274
293
  putString("transactionId", purchase.purchaseToken)
275
294
  putString("token", purchase.purchaseToken)
276
295
  putDouble("occurredAt", purchase.purchaseTime.toDouble())
296
+ putBoolean("acknowledged", purchase.isAcknowledged)
277
297
  }
278
298
  }
279
299
 
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AdRevenue, AliasResult, CustomerEntitlements, IdentifyResult, IdentifyStrategy, IdentityInfo, LastDeepLink, MmpAttribution, PaywallInteraction, PlacementResolution, RegisterPurchaseInput, RegisterPurchaseResult, RevnixAttribution, RevnixConfig } from "./types.js";
1
+ import type { AdRevenue, AliasResult, CustomerEntitlements, IdentifyResult, IdentifyStrategy, IdentityInfo, LastDeepLink, MmpAttribution, PaywallInteraction, PaywallProductShown, PlacementResolution, RegisterPurchaseInput, RegisterPurchaseResult, RevnixAttribution, RevnixConfig } from "./types.js";
2
2
  export declare function paywallImageUrls(value: unknown): string[];
3
3
  export declare class RevnixClient {
4
4
  private readonly apiKey;
@@ -27,6 +27,7 @@ export declare class RevnixClient {
27
27
  private readonly onDeferredDeepLink?;
28
28
  private readonly onAttribution?;
29
29
  private readonly deviceIntegrity?;
30
+ private readonly consumableProductIds;
30
31
  private integrityRequest;
31
32
  private deferredDeepLinkClaimed;
32
33
  private landingUrl;
@@ -106,6 +107,7 @@ export declare class RevnixClient {
106
107
  /** Re-registers every purchase the store still holds for this device and
107
108
  * resolves how many registered. Per-purchase failures go to onDiagnostic. */
108
109
  restore(): Promise<number>;
110
+ private isConsumable;
109
111
  private requireStore;
110
112
  private registerStoreTransaction;
111
113
  private postPurchase;
@@ -193,6 +195,10 @@ export declare class RevnixClient {
193
195
  logPaywallShown(options?: {
194
196
  placementKey?: string;
195
197
  paywallId?: string;
198
+ /** The plans the paywall drew, with the localized price each showed.
199
+ * RevnixPaywall fills this from its packages; a headless paywall passes
200
+ * what it rendered. */
201
+ productsShown?: PaywallProductShown[];
196
202
  }): string;
197
203
  /** Report that the customer dismissed a paywall (REV-252) — the other half
198
204
  * of a display's life. Fire-and-forget and idempotent per view id, exactly
package/dist/client.js CHANGED
@@ -97,6 +97,32 @@ const pendingKey = (p) => `${p.source}:${p.token}:${p.transactionId}`;
97
97
  // revoked key, blocked transfer) would be retried every launch forever;
98
98
  // unknown non-Revnix errors count as transient to err on the keeping side.
99
99
  const worthQueueing = (err) => !(err instanceof errors_js_1.RevnixError) || err.isRetryable;
100
+ const ATTRIBUTION_QUERY_PARAMS = new Set([
101
+ "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "utm_id", "campaign_id",
102
+ "pid", "source", "af_channel", "medium", "c", "campaign", "term", "af_ad",
103
+ "content", "gclid", "gbraid", "wbraid", "ttclid", "sccid", "twclid",
104
+ "revnix_link", "web_id",
105
+ ]);
106
+ function queryParamName(pair) {
107
+ const raw = pair.split("=")[0] ?? "";
108
+ try {
109
+ return decodeURIComponent(raw.replace(/\+/g, " ")).toLowerCase();
110
+ }
111
+ catch {
112
+ return raw.toLowerCase();
113
+ }
114
+ }
115
+ function attributionOnlyUrl(rawUrl) {
116
+ const url = rawUrl.trim();
117
+ const parts = /^([a-z][a-z0-9+.-]*:)(\/\/[^/?#]*)?([^?#]*)(?:\?([^#]*))?/i.exec(url);
118
+ if (!parts)
119
+ return url.split(/[?#]/)[0] ?? "";
120
+ const [, scheme, authority = "", path, query = ""] = parts;
121
+ const kept = query
122
+ .split("&")
123
+ .filter((pair) => ATTRIBUTION_QUERY_PARAMS.has(queryParamName(pair)));
124
+ return `${scheme}${authority.replace(/^\/\/.*@/, "//")}${path}${kept.length > 0 ? `?${kept.join("&")}` : ""}`;
125
+ }
100
126
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
101
127
  // REV-199 (CTO-R2 M24): ±20% on every scheduled delay.
102
128
  const jittered = (ms) => ms * (0.8 + Math.random() * 0.4);
@@ -117,6 +143,13 @@ function wellFormedIntegrity(evidence) {
117
143
  }
118
144
  return undefined;
119
145
  }
146
+ const MAX_PRODUCTS_SHOWN = 20;
147
+ const MAX_PRICE_LABEL_LENGTH = 64;
148
+ function boundedProductsShown(products) {
149
+ return products.slice(0, MAX_PRODUCTS_SHOWN).map((product) => product.priceLabel !== undefined
150
+ ? { ...product, priceLabel: product.priceLabel.slice(0, MAX_PRICE_LABEL_LENGTH) }
151
+ : product);
152
+ }
120
153
  class RevnixClient {
121
154
  constructor(config) {
122
155
  /** True while the current id is a generated anon id living on
@@ -207,6 +240,7 @@ class RevnixClient {
207
240
  this.onDeferredDeepLink = config.onDeferredDeepLink;
208
241
  this.onAttribution = config.onAttribution;
209
242
  this.deviceIntegrity = config.deviceIntegrity;
243
+ this.consumableProductIds = config.consumableProductIds ?? [];
210
244
  this.readYourWritesDelaysMs =
211
245
  config.readYourWritesDelaysMs ?? [250, 500, 1000, 2000];
212
246
  this.customerIdPromise = this.loadCustomerId(config.customerId);
@@ -217,7 +251,11 @@ class RevnixClient {
217
251
  this.reportAdvertisingId(config.advertisingId);
218
252
  const store = (0, store_js_1.getStoreAdapter)();
219
253
  if (store) {
220
- this.stopStoreObserver = store.observe((tx) => void this.registerStoreTransaction(store, tx).catch((err) => this.diag("storeObserver", err)));
254
+ this.stopStoreObserver = store.observe((tx) => {
255
+ if (tx.acknowledged && !this.isConsumable(tx))
256
+ return;
257
+ void this.registerStoreTransaction(store, tx).catch((err) => this.diag("storeObserver", err));
258
+ });
221
259
  }
222
260
  // REV-157: warm the placement cache at launch, so the first paywall of the
223
261
  // session can render offline. Fire-and-forget; a failed key just stays on
@@ -378,6 +416,10 @@ class RevnixClient {
378
416
  const tx = await store.purchase(productId, { customerId });
379
417
  if (!tx)
380
418
  return null;
419
+ if (tx.alreadyOwned && this.isConsumable(tx)) {
420
+ await this.registerStoreTransaction(store, tx, opts);
421
+ throw new errors_js_1.PurchaseAlreadyOwnedError(`Revnix: an earlier purchase of ${productId} was still owned and has been registered; buy again`);
422
+ }
381
423
  return this.registerStoreTransaction(store, tx, opts);
382
424
  }
383
425
  /** Re-registers every purchase the store still holds for this device and
@@ -396,6 +438,9 @@ class RevnixClient {
396
438
  }
397
439
  return restored;
398
440
  }
441
+ isConsumable(tx) {
442
+ return tx.store === "google" && this.consumableProductIds.includes(tx.productId);
443
+ }
399
444
  requireStore() {
400
445
  const store = (0, store_js_1.getStoreAdapter)();
401
446
  if (!store) {
@@ -404,8 +449,8 @@ class RevnixClient {
404
449
  return store;
405
450
  }
406
451
  async registerStoreTransaction(store, tx, opts, finish = true) {
407
- const finishTx = () => finish
408
- ? store.finish(tx.transactionId).catch((err) => this.diag("storeFinish", err))
452
+ const finishTx = (consume = false) => finish
453
+ ? store.finish(tx.transactionId, consume).catch((err) => this.diag("storeFinish", err))
409
454
  : undefined;
410
455
  try {
411
456
  const result = await this.registerPurchase({
@@ -418,7 +463,7 @@ class RevnixClient {
418
463
  signedTransactionInfo: tx.signedTransactionInfo,
419
464
  ...opts,
420
465
  });
421
- await finishTx();
466
+ await finishTx(this.isConsumable(tx));
422
467
  return result;
423
468
  }
424
469
  catch (err) {
@@ -736,6 +781,9 @@ class RevnixClient {
736
781
  sdkVersion: version_js_1.SDK_VERSION,
737
782
  ...(options?.placementKey ? { placementKey: options.placementKey } : {}),
738
783
  ...(options?.paywallId ? { paywallId: options.paywallId } : {}),
784
+ ...(options?.productsShown?.length
785
+ ? { productsShown: boundedProductsShown(options.productsShown) }
786
+ : {}),
739
787
  }))
740
788
  .catch((err) => this.diag("logPaywallShown", err));
741
789
  return viewId;
@@ -1099,7 +1147,7 @@ class RevnixClient {
1099
1147
  return;
1100
1148
  }
1101
1149
  void this.rememberDeepLink(url);
1102
- const extra = { url: url.slice(0, 1024) };
1150
+ const extra = { url: attributionOnlyUrl(url).slice(0, 1024) };
1103
1151
  const batch = this.launchBatch;
1104
1152
  if (batch === null) {
1105
1153
  this.fireImplicit("deeplink_open", extra);
package/dist/errors.d.ts CHANGED
@@ -11,6 +11,12 @@ export declare class RevnixError extends Error {
11
11
  export declare class PurchaseBlockedError extends RevnixError {
12
12
  constructor(message: string);
13
13
  }
14
+ /** purchase() found an earlier Google Play consumable of this product still
15
+ * owned. It was registered and consumed instead of charging again; ask the
16
+ * customer to buy again. */
17
+ export declare class PurchaseAlreadyOwnedError extends Error {
18
+ constructor(message: string);
19
+ }
14
20
  /** C7: the request didn't complete within the configured timeout (default
15
21
  * 10s). `fetch` has no default timeout on React Native / browsers, so without
16
22
  * this a slow or dead backend would hang the app until the OS TCP timeout. */
package/dist/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RevnixRateLimitError = exports.RevnixAuthError = exports.RevnixNetworkError = exports.RevnixTimeoutError = exports.PurchaseBlockedError = exports.RevnixError = void 0;
3
+ exports.RevnixRateLimitError = exports.RevnixAuthError = exports.RevnixNetworkError = exports.RevnixTimeoutError = exports.PurchaseAlreadyOwnedError = exports.PurchaseBlockedError = exports.RevnixError = void 0;
4
4
  class RevnixError extends Error {
5
5
  constructor(status, message) {
6
6
  super(message);
@@ -24,6 +24,16 @@ class PurchaseBlockedError extends RevnixError {
24
24
  }
25
25
  }
26
26
  exports.PurchaseBlockedError = PurchaseBlockedError;
27
+ /** purchase() found an earlier Google Play consumable of this product still
28
+ * owned. It was registered and consumed instead of charging again; ask the
29
+ * customer to buy again. */
30
+ class PurchaseAlreadyOwnedError extends Error {
31
+ constructor(message) {
32
+ super(message);
33
+ this.name = "PurchaseAlreadyOwnedError";
34
+ }
35
+ }
36
+ exports.PurchaseAlreadyOwnedError = PurchaseAlreadyOwnedError;
27
37
  /** C7: the request didn't complete within the configured timeout (default
28
38
  * 10s). `fetch` has no default timeout on React Native / browsers, so without
29
39
  * this a slow or dead backend would hang the app until the OS TCP timeout. */
@@ -1,4 +1,4 @@
1
- import { PurchaseBlockedError, RevnixAuthError, RevnixError, RevnixNetworkError, RevnixRateLimitError, RevnixTimeoutError, } from "./errors.js";
1
+ import { PurchaseAlreadyOwnedError, PurchaseBlockedError, RevnixAuthError, RevnixError, RevnixNetworkError, RevnixRateLimitError, RevnixTimeoutError, } from "./errors.js";
2
2
  import { generateAnonymousId, generateEventId, generateViewId, resolveStorage, } from "./storage.js";
3
3
  import { DEVICE_HEADER, INSTALLED_AT_KEY, compactPayload, detectDeviceFacts, encodeDeviceHeader, } from "./device.js";
4
4
  import { SDK_VERSION } from "./version.js";
@@ -93,6 +93,32 @@ const pendingKey = (p) => `${p.source}:${p.token}:${p.transactionId}`;
93
93
  // revoked key, blocked transfer) would be retried every launch forever;
94
94
  // unknown non-Revnix errors count as transient to err on the keeping side.
95
95
  const worthQueueing = (err) => !(err instanceof RevnixError) || err.isRetryable;
96
+ const ATTRIBUTION_QUERY_PARAMS = new Set([
97
+ "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "utm_id", "campaign_id",
98
+ "pid", "source", "af_channel", "medium", "c", "campaign", "term", "af_ad",
99
+ "content", "gclid", "gbraid", "wbraid", "ttclid", "sccid", "twclid",
100
+ "revnix_link", "web_id",
101
+ ]);
102
+ function queryParamName(pair) {
103
+ const raw = pair.split("=")[0] ?? "";
104
+ try {
105
+ return decodeURIComponent(raw.replace(/\+/g, " ")).toLowerCase();
106
+ }
107
+ catch {
108
+ return raw.toLowerCase();
109
+ }
110
+ }
111
+ function attributionOnlyUrl(rawUrl) {
112
+ const url = rawUrl.trim();
113
+ const parts = /^([a-z][a-z0-9+.-]*:)(\/\/[^/?#]*)?([^?#]*)(?:\?([^#]*))?/i.exec(url);
114
+ if (!parts)
115
+ return url.split(/[?#]/)[0] ?? "";
116
+ const [, scheme, authority = "", path, query = ""] = parts;
117
+ const kept = query
118
+ .split("&")
119
+ .filter((pair) => ATTRIBUTION_QUERY_PARAMS.has(queryParamName(pair)));
120
+ return `${scheme}${authority.replace(/^\/\/.*@/, "//")}${path}${kept.length > 0 ? `?${kept.join("&")}` : ""}`;
121
+ }
96
122
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
97
123
  // REV-199 (CTO-R2 M24): ±20% on every scheduled delay.
98
124
  const jittered = (ms) => ms * (0.8 + Math.random() * 0.4);
@@ -113,6 +139,13 @@ function wellFormedIntegrity(evidence) {
113
139
  }
114
140
  return undefined;
115
141
  }
142
+ const MAX_PRODUCTS_SHOWN = 20;
143
+ const MAX_PRICE_LABEL_LENGTH = 64;
144
+ function boundedProductsShown(products) {
145
+ return products.slice(0, MAX_PRODUCTS_SHOWN).map((product) => product.priceLabel !== undefined
146
+ ? { ...product, priceLabel: product.priceLabel.slice(0, MAX_PRICE_LABEL_LENGTH) }
147
+ : product);
148
+ }
116
149
  export class RevnixClient {
117
150
  constructor(config) {
118
151
  /** True while the current id is a generated anon id living on
@@ -203,6 +236,7 @@ export class RevnixClient {
203
236
  this.onDeferredDeepLink = config.onDeferredDeepLink;
204
237
  this.onAttribution = config.onAttribution;
205
238
  this.deviceIntegrity = config.deviceIntegrity;
239
+ this.consumableProductIds = config.consumableProductIds ?? [];
206
240
  this.readYourWritesDelaysMs =
207
241
  config.readYourWritesDelaysMs ?? [250, 500, 1000, 2000];
208
242
  this.customerIdPromise = this.loadCustomerId(config.customerId);
@@ -213,7 +247,11 @@ export class RevnixClient {
213
247
  this.reportAdvertisingId(config.advertisingId);
214
248
  const store = getStoreAdapter();
215
249
  if (store) {
216
- this.stopStoreObserver = store.observe((tx) => void this.registerStoreTransaction(store, tx).catch((err) => this.diag("storeObserver", err)));
250
+ this.stopStoreObserver = store.observe((tx) => {
251
+ if (tx.acknowledged && !this.isConsumable(tx))
252
+ return;
253
+ void this.registerStoreTransaction(store, tx).catch((err) => this.diag("storeObserver", err));
254
+ });
217
255
  }
218
256
  // REV-157: warm the placement cache at launch, so the first paywall of the
219
257
  // session can render offline. Fire-and-forget; a failed key just stays on
@@ -374,6 +412,10 @@ export class RevnixClient {
374
412
  const tx = await store.purchase(productId, { customerId });
375
413
  if (!tx)
376
414
  return null;
415
+ if (tx.alreadyOwned && this.isConsumable(tx)) {
416
+ await this.registerStoreTransaction(store, tx, opts);
417
+ throw new PurchaseAlreadyOwnedError(`Revnix: an earlier purchase of ${productId} was still owned and has been registered; buy again`);
418
+ }
377
419
  return this.registerStoreTransaction(store, tx, opts);
378
420
  }
379
421
  /** Re-registers every purchase the store still holds for this device and
@@ -392,6 +434,9 @@ export class RevnixClient {
392
434
  }
393
435
  return restored;
394
436
  }
437
+ isConsumable(tx) {
438
+ return tx.store === "google" && this.consumableProductIds.includes(tx.productId);
439
+ }
395
440
  requireStore() {
396
441
  const store = getStoreAdapter();
397
442
  if (!store) {
@@ -400,8 +445,8 @@ export class RevnixClient {
400
445
  return store;
401
446
  }
402
447
  async registerStoreTransaction(store, tx, opts, finish = true) {
403
- const finishTx = () => finish
404
- ? store.finish(tx.transactionId).catch((err) => this.diag("storeFinish", err))
448
+ const finishTx = (consume = false) => finish
449
+ ? store.finish(tx.transactionId, consume).catch((err) => this.diag("storeFinish", err))
405
450
  : undefined;
406
451
  try {
407
452
  const result = await this.registerPurchase({
@@ -414,7 +459,7 @@ export class RevnixClient {
414
459
  signedTransactionInfo: tx.signedTransactionInfo,
415
460
  ...opts,
416
461
  });
417
- await finishTx();
462
+ await finishTx(this.isConsumable(tx));
418
463
  return result;
419
464
  }
420
465
  catch (err) {
@@ -732,6 +777,9 @@ export class RevnixClient {
732
777
  sdkVersion: SDK_VERSION,
733
778
  ...(options?.placementKey ? { placementKey: options.placementKey } : {}),
734
779
  ...(options?.paywallId ? { paywallId: options.paywallId } : {}),
780
+ ...(options?.productsShown?.length
781
+ ? { productsShown: boundedProductsShown(options.productsShown) }
782
+ : {}),
735
783
  }))
736
784
  .catch((err) => this.diag("logPaywallShown", err));
737
785
  return viewId;
@@ -1095,7 +1143,7 @@ export class RevnixClient {
1095
1143
  return;
1096
1144
  }
1097
1145
  void this.rememberDeepLink(url);
1098
- const extra = { url: url.slice(0, 1024) };
1146
+ const extra = { url: attributionOnlyUrl(url).slice(0, 1024) };
1099
1147
  const batch = this.launchBatch;
1100
1148
  if (batch === null) {
1101
1149
  this.fireImplicit("deeplink_open", extra);
@@ -19,6 +19,15 @@ export class PurchaseBlockedError extends RevnixError {
19
19
  this.name = "PurchaseBlockedError";
20
20
  }
21
21
  }
22
+ /** purchase() found an earlier Google Play consumable of this product still
23
+ * owned. It was registered and consumed instead of charging again; ask the
24
+ * customer to buy again. */
25
+ export class PurchaseAlreadyOwnedError extends Error {
26
+ constructor(message) {
27
+ super(message);
28
+ this.name = "PurchaseAlreadyOwnedError";
29
+ }
30
+ }
22
31
  /** C7: the request didn't complete within the configured timeout (default
23
32
  * 10s). `fetch` has no default timeout on React Native / browsers, so without
24
33
  * this a slow or dead backend would hang the app until the OS TCP timeout. */
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { RevnixClient } from "./client.js";
2
2
  import { setLocale } from "./blocks/locale.js";
3
3
  export { RevnixClient } from "./client.js";
4
- export { PurchaseBlockedError, RevnixAuthError, RevnixError, RevnixNetworkError, RevnixRateLimitError, RevnixTimeoutError, } from "./errors.js";
4
+ export { PurchaseAlreadyOwnedError, PurchaseBlockedError, RevnixAuthError, RevnixError, RevnixNetworkError, RevnixRateLimitError, RevnixTimeoutError, } from "./errors.js";
5
5
  export { purchaseInputFromIap } from "./iap.js";
6
6
  export { setStoreAdapter, } from "./store.js";
7
7
  export { memoryStorage, generateAnonymousId } from "./storage.js";
@@ -6,7 +6,7 @@ export const RevnixStore = native
6
6
  ? {
7
7
  purchase: (productId, { customerId }) => native.purchase(productId, customerId),
8
8
  restore: () => native.restore(),
9
- finish: (transactionId) => native.finish(transactionId),
9
+ finish: (transactionId, consume) => native.finish(transactionId, consume === true),
10
10
  observe(onTransaction) {
11
11
  const sub = new NativeEventEmitter(NativeModules.RevnixStore).addListener("revnixStoreTransaction", (tx) => onTransaction(tx));
12
12
  return () => sub.remove();
@@ -82,6 +82,23 @@ const CARD_BG = { dark: "#181b22", light: "#f4f5f7" };
82
82
  export async function prefetchPaywallImages(resolution) {
83
83
  await Promise.all(paywallImageUrls(resolution?.paywall).map((url) => Image.prefetch(url).catch(() => false)));
84
84
  }
85
+ function visiblePackages(config, packages) {
86
+ return config.template === "minimal" && config.highlightPackageId
87
+ ? packages.filter((p) => p.packageId === config.highlightPackageId)
88
+ : packages;
89
+ }
90
+ function productsShownFrom(packages) {
91
+ return packages.flatMap((pkg) => pkg.productId
92
+ ? [
93
+ {
94
+ productId: pkg.productId,
95
+ priceLabel: pkg.priceLabel,
96
+ amountMinor: pkg.amountMinor,
97
+ currency: pkg.currency,
98
+ },
99
+ ]
100
+ : []);
101
+ }
85
102
  export function RevnixPaywall(props) {
86
103
  // One view per mount: remounting (a re-shown paywall) is a genuine new
87
104
  // display; re-renders are not.
@@ -92,7 +109,11 @@ export function RevnixPaywall(props) {
92
109
  React.useEffect(() => {
93
110
  if (!client || disableViewTracking)
94
111
  return;
95
- const id = client.logPaywallShown({ placementKey, paywallId });
112
+ const id = client.logPaywallShown({
113
+ placementKey,
114
+ paywallId,
115
+ productsShown: productsShownFrom(visiblePackages(props.config, props.packages)),
116
+ });
96
117
  // Pre-REV-252 clients return void; the close then still fires the host
97
118
  // callback, it just cannot be paired with this display.
98
119
  if (typeof id === "string")
@@ -322,9 +343,7 @@ function ClassicPaywall(props) {
322
343
  const layout = config.template;
323
344
  // Same template semantics as the dashboard preview: "minimal" shows only
324
345
  // the highlighted package; feature bullets render on the feature layouts.
325
- const shown = layout === "minimal" && config.highlightPackageId
326
- ? packages.filter((p) => p.packageId === config.highlightPackageId)
327
- : packages;
346
+ const shown = visiblePackages(config, packages);
328
347
  const [internalSelected, setInternalSelected] = React.useState(undefined);
329
348
  const fallbackSelected = shown.find((p) => p.packageId === config.highlightPackageId)?.packageId ??
330
349
  shown[0]?.packageId;
@@ -1,4 +1,4 @@
1
1
  // L3: the single source of the SDK version inside src/. Must match
2
2
  // package.json "version" — version.test.ts fails the build when they drift
3
3
  // (they had: client.ts said 0.7.0 while the package shipped 0.9.0).
4
- export const SDK_VERSION = "1.8.0";
4
+ export const SDK_VERSION = "1.11.0";
package/dist/index.d.ts CHANGED
@@ -2,14 +2,14 @@ import { RevnixClient } from "./client.js";
2
2
  import { setLocale } from "./blocks/locale.js";
3
3
  import type { RevnixConfig } from "./types.js";
4
4
  export { RevnixClient } from "./client.js";
5
- export { PurchaseBlockedError, RevnixAuthError, RevnixError, RevnixNetworkError, RevnixRateLimitError, RevnixTimeoutError, } from "./errors.js";
5
+ export { PurchaseAlreadyOwnedError, PurchaseBlockedError, RevnixAuthError, RevnixError, RevnixNetworkError, RevnixRateLimitError, RevnixTimeoutError, } from "./errors.js";
6
6
  export { purchaseInputFromIap, type IapPurchase } from "./iap.js";
7
7
  export { setStoreAdapter, type StoreAdapter, type StoreTransaction, } from "./store.js";
8
8
  export { memoryStorage, generateAnonymousId } from "./storage.js";
9
9
  export { SDK_VERSION } from "./version.js";
10
10
  export { DEVICE_HEADER, encodeDeviceHeader } from "./device.js";
11
11
  export { browserLifecycle, DEFAULT_SESSION_TIMEOUT_MS, HOST_CALL_PLACEMENT, IMPLICIT_PLACEMENTS, PREVIEW_PLACEMENT_KEY, type ImplicitPlacement, type ImplicitSkipReason, type ImplicitTrigger, type ImplicitTriggerResponse, type RevnixLifecycle, } from "./implicit.js";
12
- export type { AdRevenue, AliasResult, CustomerEntitlements, DeviceFacts, Entitlement, EntitlementSource, Environment, IdentifyResult, IdentifyStrategy, IdentityInfo, ImplicitResolution, IntegrityEvidence, LastDeepLink, MmpAttribution, MmpProvider, PaywallConfig, PaywallInteraction, PaywallPurchaseOutcome, PlacementOffering, PlacementPackage, PlacementPaywall, PlacementProduct, PlacementResolution, RegisterPurchaseInput, RegisterPurchaseResult, RevnixAttribution, RevnixConfig, RevnixDiagnostic, RevnixStorage, Store, } from "./types.js";
12
+ export type { AdRevenue, AliasResult, CustomerEntitlements, DeviceFacts, Entitlement, EntitlementSource, Environment, IdentifyResult, IdentifyStrategy, IdentityInfo, ImplicitResolution, IntegrityEvidence, LastDeepLink, MmpAttribution, MmpProvider, PaywallConfig, PaywallInteraction, PaywallProductShown, PaywallPurchaseOutcome, PlacementOffering, PlacementPackage, PlacementPaywall, PlacementProduct, PlacementResolution, RegisterPurchaseInput, RegisterPurchaseResult, RevnixAttribution, RevnixConfig, RevnixDiagnostic, RevnixStorage, Store, } from "./types.js";
13
13
  /** Singleton facade — configure once at app start, then import `Revnix`
14
14
  * anywhere. Prefer constructing RevnixClient directly in tests. */
15
15
  export declare const Revnix: {
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Revnix = exports.PREVIEW_PLACEMENT_KEY = exports.IMPLICIT_PLACEMENTS = exports.HOST_CALL_PLACEMENT = exports.DEFAULT_SESSION_TIMEOUT_MS = exports.browserLifecycle = exports.encodeDeviceHeader = exports.DEVICE_HEADER = exports.SDK_VERSION = exports.generateAnonymousId = exports.memoryStorage = exports.setStoreAdapter = exports.purchaseInputFromIap = exports.RevnixTimeoutError = exports.RevnixRateLimitError = exports.RevnixNetworkError = exports.RevnixError = exports.RevnixAuthError = exports.PurchaseBlockedError = exports.RevnixClient = void 0;
3
+ exports.Revnix = exports.PREVIEW_PLACEMENT_KEY = exports.IMPLICIT_PLACEMENTS = exports.HOST_CALL_PLACEMENT = exports.DEFAULT_SESSION_TIMEOUT_MS = exports.browserLifecycle = exports.encodeDeviceHeader = exports.DEVICE_HEADER = exports.SDK_VERSION = exports.generateAnonymousId = exports.memoryStorage = exports.setStoreAdapter = exports.purchaseInputFromIap = exports.RevnixTimeoutError = exports.RevnixRateLimitError = exports.RevnixNetworkError = exports.RevnixError = exports.RevnixAuthError = exports.PurchaseBlockedError = exports.PurchaseAlreadyOwnedError = exports.RevnixClient = void 0;
4
4
  const client_js_1 = require("./client.js");
5
5
  const locale_js_1 = require("./blocks/locale.js");
6
6
  var client_js_2 = require("./client.js");
7
7
  Object.defineProperty(exports, "RevnixClient", { enumerable: true, get: function () { return client_js_2.RevnixClient; } });
8
8
  var errors_js_1 = require("./errors.js");
9
+ Object.defineProperty(exports, "PurchaseAlreadyOwnedError", { enumerable: true, get: function () { return errors_js_1.PurchaseAlreadyOwnedError; } });
9
10
  Object.defineProperty(exports, "PurchaseBlockedError", { enumerable: true, get: function () { return errors_js_1.PurchaseBlockedError; } });
10
11
  Object.defineProperty(exports, "RevnixAuthError", { enumerable: true, get: function () { return errors_js_1.RevnixAuthError; } });
11
12
  Object.defineProperty(exports, "RevnixError", { enumerable: true, get: function () { return errors_js_1.RevnixError; } });
@@ -9,7 +9,7 @@ exports.RevnixStore = native
9
9
  ? {
10
10
  purchase: (productId, { customerId }) => native.purchase(productId, customerId),
11
11
  restore: () => native.restore(),
12
- finish: (transactionId) => native.finish(transactionId),
12
+ finish: (transactionId, consume) => native.finish(transactionId, consume === true),
13
13
  observe(onTransaction) {
14
14
  const sub = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.RevnixStore).addListener("revnixStoreTransaction", (tx) => onTransaction(tx));
15
15
  return () => sub.remove();
package/dist/store.d.ts CHANGED
@@ -12,6 +12,11 @@ export interface StoreTransaction {
12
12
  expiresAt?: number;
13
13
  /** Apple only: the StoreKit 2 JWS. */
14
14
  signedTransactionInfo?: string;
15
+ /** Google only: already acknowledged in Play. */
16
+ acknowledged?: boolean;
17
+ /** Google only: purchase() answered with an earlier purchase Play reported
18
+ * as already owned, not a new charge. */
19
+ alreadyOwned?: boolean;
15
20
  }
16
21
  export interface StoreAdapter {
17
22
  /** Resolves null when the customer cancelled or the purchase is pending. */
@@ -19,7 +24,8 @@ export interface StoreAdapter {
19
24
  customerId: string;
20
25
  }): Promise<StoreTransaction | null>;
21
26
  restore(): Promise<StoreTransaction[]>;
22
- finish(transactionId: string): Promise<void>;
27
+ /** `consume`: Google only, consume instead of acknowledge. */
28
+ finish(transactionId: string, consume?: boolean): Promise<void>;
23
29
  /** Transactions arriving outside purchase(): renewals, other devices, Ask
24
30
  * to Buy, refunds. Returns an unsubscribe. */
25
31
  observe(onTransaction: (tx: StoreTransaction) => void): () => void;
package/dist/types.d.ts CHANGED
@@ -149,6 +149,9 @@ export interface RevnixConfig {
149
149
  * read. A null answer deletes a previously stored `gps_adid`; a
150
150
  * rejection changes nothing and reports `op: "advertisingId"`. */
151
151
  advertisingId?: () => Promise<string | null | undefined>;
152
+ /** Google Play product ids sold as consumables. A registered purchase of
153
+ * one is consumed instead of acknowledged so it can be bought again. */
154
+ consumableProductIds?: string[];
152
155
  }
153
156
  /** Device integrity evidence for `POST /v1/installs` and `/v1/attribution`.
154
157
  * iOS: an App Attest key id and its attestation (standard base64) over
@@ -340,6 +343,15 @@ export interface PlacementPackage {
340
343
  metadata?: Record<string, unknown>;
341
344
  product: PlacementProduct | null;
342
345
  }
346
+ /** One plan as a paywall drew it, for `logPaywallShown`'s `productsShown`:
347
+ * the localized label the customer actually read, and the catalog price
348
+ * behind it. */
349
+ export interface PaywallProductShown {
350
+ productId: string;
351
+ priceLabel?: string;
352
+ amountMinor?: number;
353
+ currency?: string;
354
+ }
343
355
  export interface PlacementProduct {
344
356
  productId: string;
345
357
  displayName: string;
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { type StyleProp, type ViewStyle } from "react-native";
3
- import type { PaywallConfig, PaywallInteraction, PaywallPurchaseOutcome, PlacementResolution, RegisterPurchaseResult } from "../types.js";
3
+ import type { PaywallConfig, PaywallInteraction, PaywallProductShown, PaywallPurchaseOutcome, PlacementResolution, RegisterPurchaseResult } from "../types.js";
4
4
  import { type RevnixClient } from "../client.js";
5
5
  import type { FontFamilyMap } from "../blocks/style.js";
6
6
  import { type RevnixBlurComponent, type RevnixGradientComponent } from "./RevnixBlockPaywall.js";
@@ -90,6 +90,7 @@ export interface RevnixPaywallProps {
90
90
  logPaywallShown: (options?: {
91
91
  placementKey?: string;
92
92
  paywallId?: string;
93
+ productsShown?: PaywallProductShown[];
93
94
  }) => string | void;
94
95
  /** Older clients predate close reporting; the paywall still closes. */
95
96
  logPaywallClosed?: (viewId: string, options?: {
@@ -120,6 +120,23 @@ const CARD_BG = { dark: "#181b22", light: "#f4f5f7" };
120
120
  async function prefetchPaywallImages(resolution) {
121
121
  await Promise.all((0, client_js_1.paywallImageUrls)(resolution?.paywall).map((url) => react_native_1.Image.prefetch(url).catch(() => false)));
122
122
  }
123
+ function visiblePackages(config, packages) {
124
+ return config.template === "minimal" && config.highlightPackageId
125
+ ? packages.filter((p) => p.packageId === config.highlightPackageId)
126
+ : packages;
127
+ }
128
+ function productsShownFrom(packages) {
129
+ return packages.flatMap((pkg) => pkg.productId
130
+ ? [
131
+ {
132
+ productId: pkg.productId,
133
+ priceLabel: pkg.priceLabel,
134
+ amountMinor: pkg.amountMinor,
135
+ currency: pkg.currency,
136
+ },
137
+ ]
138
+ : []);
139
+ }
123
140
  function RevnixPaywall(props) {
124
141
  // One view per mount: remounting (a re-shown paywall) is a genuine new
125
142
  // display; re-renders are not.
@@ -130,7 +147,11 @@ function RevnixPaywall(props) {
130
147
  React.useEffect(() => {
131
148
  if (!client || disableViewTracking)
132
149
  return;
133
- const id = client.logPaywallShown({ placementKey, paywallId });
150
+ const id = client.logPaywallShown({
151
+ placementKey,
152
+ paywallId,
153
+ productsShown: productsShownFrom(visiblePackages(props.config, props.packages)),
154
+ });
134
155
  // Pre-REV-252 clients return void; the close then still fires the host
135
156
  // callback, it just cannot be paired with this display.
136
157
  if (typeof id === "string")
@@ -360,9 +381,7 @@ function ClassicPaywall(props) {
360
381
  const layout = config.template;
361
382
  // Same template semantics as the dashboard preview: "minimal" shows only
362
383
  // the highlighted package; feature bullets render on the feature layouts.
363
- const shown = layout === "minimal" && config.highlightPackageId
364
- ? packages.filter((p) => p.packageId === config.highlightPackageId)
365
- : packages;
384
+ const shown = visiblePackages(config, packages);
366
385
  const [internalSelected, setInternalSelected] = React.useState(undefined);
367
386
  const fallbackSelected = shown.find((p) => p.packageId === config.highlightPackageId)?.packageId ??
368
387
  shown[0]?.packageId;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.8.0";
1
+ export declare const SDK_VERSION = "1.11.0";
package/dist/version.js CHANGED
@@ -4,4 +4,4 @@ exports.SDK_VERSION = void 0;
4
4
  // L3: the single source of the SDK version inside src/. Must match
5
5
  // package.json "version" — version.test.ts fails the build when they drift
6
6
  // (they had: client.ts said 0.7.0 while the package shipped 0.9.0).
7
- exports.SDK_VERSION = "1.8.0";
7
+ exports.SDK_VERSION = "1.11.0";
package/ios/RevnixStore.m CHANGED
@@ -12,6 +12,7 @@ RCT_EXTERN_METHOD(restore:(RCTPromiseResolveBlock)resolve
12
12
  rejecter:(RCTPromiseRejectBlock)reject)
13
13
 
14
14
  RCT_EXTERN_METHOD(finish:(NSString *)transactionId
15
+ consume:(BOOL)consume
15
16
  resolver:(RCTPromiseResolveBlock)resolve
16
17
  rejecter:(RCTPromiseRejectBlock)reject)
17
18
 
@@ -20,7 +20,7 @@ class RevnixStore: RCTEventEmitter {
20
20
  override func startObserving() {
21
21
  updates?.cancel()
22
22
  updates = Task { [weak self] in
23
- for await update in Transaction.updates where update.unsafePayloadValue.revocationDate == nil {
23
+ for await update in Transaction.updates {
24
24
  self?.sendEvent(withName: "revnixStoreTransaction", body: RevnixStore.payload(update))
25
25
  }
26
26
  }
@@ -72,9 +72,10 @@ class RevnixStore: RCTEventEmitter {
72
72
  }
73
73
  }
74
74
 
75
- @objc(finish:resolver:rejecter:)
75
+ @objc(finish:consume:resolver:rejecter:)
76
76
  func finish(
77
77
  _ transactionId: String,
78
+ consume _: Bool,
78
79
  resolver resolve: @escaping RCTPromiseResolveBlock,
79
80
  rejecter reject: @escaping RCTPromiseRejectBlock
80
81
  ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-revnix",
3
- "version": "1.8.0",
3
+ "version": "1.11.0",
4
4
  "description": "Revnix SDK for React, React Native & Next.js: purchase registration, entitlements, identity, and placements over the Revnix /v1 API.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/client.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ PurchaseAlreadyOwnedError,
2
3
  PurchaseBlockedError,
3
4
  RevnixAuthError,
4
5
  RevnixError,
@@ -49,6 +50,7 @@ import type {
49
50
  LastDeepLink,
50
51
  MmpAttribution,
51
52
  PaywallInteraction,
53
+ PaywallProductShown,
52
54
  PlacementResolution,
53
55
  RegisterPurchaseInput,
54
56
  RegisterPurchaseResult,
@@ -193,6 +195,33 @@ const pendingKey = (p: RegisterPurchaseInput) =>
193
195
  const worthQueueing = (err: unknown): boolean =>
194
196
  !(err instanceof RevnixError) || err.isRetryable;
195
197
 
198
+ const ATTRIBUTION_QUERY_PARAMS = new Set([
199
+ "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "utm_id", "campaign_id",
200
+ "pid", "source", "af_channel", "medium", "c", "campaign", "term", "af_ad",
201
+ "content", "gclid", "gbraid", "wbraid", "ttclid", "sccid", "twclid",
202
+ "revnix_link", "web_id",
203
+ ]);
204
+
205
+ function queryParamName(pair: string): string {
206
+ const raw = pair.split("=")[0] ?? "";
207
+ try {
208
+ return decodeURIComponent(raw.replace(/\+/g, " ")).toLowerCase();
209
+ } catch {
210
+ return raw.toLowerCase();
211
+ }
212
+ }
213
+
214
+ function attributionOnlyUrl(rawUrl: string): string {
215
+ const url = rawUrl.trim();
216
+ const parts = /^([a-z][a-z0-9+.-]*:)(\/\/[^/?#]*)?([^?#]*)(?:\?([^#]*))?/i.exec(url);
217
+ if (!parts) return url.split(/[?#]/)[0] ?? "";
218
+ const [, scheme, authority = "", path, query = ""] = parts;
219
+ const kept = query
220
+ .split("&")
221
+ .filter((pair) => ATTRIBUTION_QUERY_PARAMS.has(queryParamName(pair)));
222
+ return `${scheme}${authority.replace(/^\/\/.*@/, "//")}${path}${kept.length > 0 ? `?${kept.join("&")}` : ""}`;
223
+ }
224
+
196
225
  const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
197
226
 
198
227
  // REV-199 (CTO-R2 M24): ±20% on every scheduled delay.
@@ -218,6 +247,19 @@ function wellFormedIntegrity(evidence: unknown): IntegrityEvidence | undefined {
218
247
  return undefined;
219
248
  }
220
249
 
250
+ const MAX_PRODUCTS_SHOWN = 20;
251
+ const MAX_PRICE_LABEL_LENGTH = 64;
252
+
253
+ function boundedProductsShown(
254
+ products: PaywallProductShown[]
255
+ ): PaywallProductShown[] {
256
+ return products.slice(0, MAX_PRODUCTS_SHOWN).map((product) =>
257
+ product.priceLabel !== undefined
258
+ ? { ...product, priceLabel: product.priceLabel.slice(0, MAX_PRICE_LABEL_LENGTH) }
259
+ : product
260
+ );
261
+ }
262
+
221
263
  export class RevnixClient {
222
264
  private readonly apiKey: string;
223
265
  private readonly baseUrl: string;
@@ -263,6 +305,7 @@ export class RevnixClient {
263
305
  private readonly onDeferredDeepLink?: RevnixConfig["onDeferredDeepLink"];
264
306
  private readonly onAttribution?: RevnixConfig["onAttribution"];
265
307
  private readonly deviceIntegrity?: RevnixConfig["deviceIntegrity"];
308
+ private readonly consumableProductIds: string[];
266
309
  private integrityRequest: {
267
310
  customerId: string;
268
311
  body: Promise<{ integrity?: IntegrityEvidence }>;
@@ -340,6 +383,7 @@ export class RevnixClient {
340
383
  this.onDeferredDeepLink = config.onDeferredDeepLink;
341
384
  this.onAttribution = config.onAttribution;
342
385
  this.deviceIntegrity = config.deviceIntegrity;
386
+ this.consumableProductIds = config.consumableProductIds ?? [];
343
387
  this.readYourWritesDelaysMs =
344
388
  config.readYourWritesDelaysMs ?? [250, 500, 1000, 2000];
345
389
  this.customerIdPromise = this.loadCustomerId(config.customerId);
@@ -351,11 +395,12 @@ export class RevnixClient {
351
395
  if (config.advertisingId) this.reportAdvertisingId(config.advertisingId);
352
396
  const store = getStoreAdapter();
353
397
  if (store) {
354
- this.stopStoreObserver = store.observe((tx) =>
398
+ this.stopStoreObserver = store.observe((tx) => {
399
+ if (tx.acknowledged && !this.isConsumable(tx)) return;
355
400
  void this.registerStoreTransaction(store, tx).catch((err) =>
356
401
  this.diag("storeObserver", err)
357
- )
358
- );
402
+ );
403
+ });
359
404
  }
360
405
  // REV-157: warm the placement cache at launch, so the first paywall of the
361
406
  // session can render offline. Fire-and-forget; a failed key just stays on
@@ -547,6 +592,12 @@ export class RevnixClient {
547
592
  const customerId = await this.customerIdPromise;
548
593
  const tx = await store.purchase(productId, { customerId });
549
594
  if (!tx) return null;
595
+ if (tx.alreadyOwned && this.isConsumable(tx)) {
596
+ await this.registerStoreTransaction(store, tx, opts);
597
+ throw new PurchaseAlreadyOwnedError(
598
+ `Revnix: an earlier purchase of ${productId} was still owned and has been registered; buy again`
599
+ );
600
+ }
550
601
  return this.registerStoreTransaction(store, tx, opts);
551
602
  }
552
603
 
@@ -566,6 +617,10 @@ export class RevnixClient {
566
617
  return restored;
567
618
  }
568
619
 
620
+ private isConsumable(tx: StoreTransaction): boolean {
621
+ return tx.store === "google" && this.consumableProductIds.includes(tx.productId);
622
+ }
623
+
569
624
  private requireStore(): StoreAdapter {
570
625
  const store = getStoreAdapter();
571
626
  if (!store) {
@@ -582,9 +637,9 @@ export class RevnixClient {
582
637
  opts?: Pick<RegisterPurchaseInput, "viewId" | "paywallId" | "placementKey">,
583
638
  finish = true
584
639
  ): Promise<RegisterPurchaseResult> {
585
- const finishTx = () =>
640
+ const finishTx = (consume = false) =>
586
641
  finish
587
- ? store.finish(tx.transactionId).catch((err) => this.diag("storeFinish", err))
642
+ ? store.finish(tx.transactionId, consume).catch((err) => this.diag("storeFinish", err))
588
643
  : undefined;
589
644
  try {
590
645
  const result = await this.registerPurchase({
@@ -597,7 +652,7 @@ export class RevnixClient {
597
652
  signedTransactionInfo: tx.signedTransactionInfo,
598
653
  ...opts,
599
654
  });
600
- await finishTx();
655
+ await finishTx(this.isConsumable(tx));
601
656
  return result;
602
657
  } catch (err) {
603
658
  if (!(err instanceof PurchaseBlockedError)) await finishTx();
@@ -955,6 +1010,10 @@ export class RevnixClient {
955
1010
  logPaywallShown(options?: {
956
1011
  placementKey?: string;
957
1012
  paywallId?: string;
1013
+ /** The plans the paywall drew, with the localized price each showed.
1014
+ * RevnixPaywall fills this from its packages; a headless paywall passes
1015
+ * what it rendered. */
1016
+ productsShown?: PaywallProductShown[];
958
1017
  }): string {
959
1018
  const viewId = generateViewId();
960
1019
  // REV-272 LOOP GUARD: a display whose placement is one of the six came
@@ -979,6 +1038,9 @@ export class RevnixClient {
979
1038
  sdkVersion: SDK_VERSION,
980
1039
  ...(options?.placementKey ? { placementKey: options.placementKey } : {}),
981
1040
  ...(options?.paywallId ? { paywallId: options.paywallId } : {}),
1041
+ ...(options?.productsShown?.length
1042
+ ? { productsShown: boundedProductsShown(options.productsShown) }
1043
+ : {}),
982
1044
  })
983
1045
  )
984
1046
  .catch((err) => this.diag("logPaywallShown", err));
@@ -1400,7 +1462,7 @@ export class RevnixClient {
1400
1462
  return;
1401
1463
  }
1402
1464
  void this.rememberDeepLink(url);
1403
- const extra = { url: url.slice(0, 1024) };
1465
+ const extra = { url: attributionOnlyUrl(url).slice(0, 1024) };
1404
1466
  const batch = this.launchBatch;
1405
1467
  if (batch === null) {
1406
1468
  this.fireImplicit("deeplink_open", extra);
package/src/errors.ts CHANGED
@@ -24,6 +24,16 @@ export class PurchaseBlockedError extends RevnixError {
24
24
  }
25
25
  }
26
26
 
27
+ /** purchase() found an earlier Google Play consumable of this product still
28
+ * owned. It was registered and consumed instead of charging again; ask the
29
+ * customer to buy again. */
30
+ export class PurchaseAlreadyOwnedError extends Error {
31
+ constructor(message: string) {
32
+ super(message);
33
+ this.name = "PurchaseAlreadyOwnedError";
34
+ }
35
+ }
36
+
27
37
  /** C7: the request didn't complete within the configured timeout (default
28
38
  * 10s). `fetch` has no default timeout on React Native / browsers, so without
29
39
  * this a slow or dead backend would hang the app until the OS TCP timeout. */
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ import type { RevnixConfig } from "./types.js";
4
4
 
5
5
  export { RevnixClient } from "./client.js";
6
6
  export {
7
+ PurchaseAlreadyOwnedError,
7
8
  PurchaseBlockedError,
8
9
  RevnixAuthError,
9
10
  RevnixError,
@@ -50,6 +51,7 @@ export type {
50
51
  MmpProvider,
51
52
  PaywallConfig,
52
53
  PaywallInteraction,
54
+ PaywallProductShown,
53
55
  PaywallPurchaseOutcome,
54
56
  PlacementOffering,
55
57
  PlacementPackage,
@@ -10,7 +10,7 @@ import type { IntegrityEvidence, RevnixConfig } from "../types.js";
10
10
  interface NativeRevnixStore {
11
11
  purchase(productId: string, customerId: string): Promise<StoreTransaction | null>;
12
12
  restore(): Promise<StoreTransaction[]>;
13
- finish(transactionId: string): Promise<void>;
13
+ finish(transactionId: string, consume: boolean): Promise<void>;
14
14
  deviceIntegrity?(customerId: string): Promise<IntegrityEvidence | null>;
15
15
  advertisingId?(): Promise<string | null>;
16
16
  }
@@ -28,7 +28,7 @@ export const RevnixStore: StoreAdapter = native
28
28
  ? {
29
29
  purchase: (productId, { customerId }) => native.purchase(productId, customerId),
30
30
  restore: () => native.restore(),
31
- finish: (transactionId) => native.finish(transactionId),
31
+ finish: (transactionId, consume) => native.finish(transactionId, consume === true),
32
32
  observe(onTransaction) {
33
33
  const sub = new NativeEventEmitter(NativeModules.RevnixStore).addListener(
34
34
  "revnixStoreTransaction",
package/src/store.ts CHANGED
@@ -13,6 +13,11 @@ export interface StoreTransaction {
13
13
  expiresAt?: number;
14
14
  /** Apple only: the StoreKit 2 JWS. */
15
15
  signedTransactionInfo?: string;
16
+ /** Google only: already acknowledged in Play. */
17
+ acknowledged?: boolean;
18
+ /** Google only: purchase() answered with an earlier purchase Play reported
19
+ * as already owned, not a new charge. */
20
+ alreadyOwned?: boolean;
16
21
  }
17
22
 
18
23
  export interface StoreAdapter {
@@ -22,7 +27,8 @@ export interface StoreAdapter {
22
27
  opts: { customerId: string }
23
28
  ): Promise<StoreTransaction | null>;
24
29
  restore(): Promise<StoreTransaction[]>;
25
- finish(transactionId: string): Promise<void>;
30
+ /** `consume`: Google only, consume instead of acknowledge. */
31
+ finish(transactionId: string, consume?: boolean): Promise<void>;
26
32
  /** Transactions arriving outside purchase(): renewals, other devices, Ask
27
33
  * to Buy, refunds. Returns an unsubscribe. */
28
34
  observe(onTransaction: (tx: StoreTransaction) => void): () => void;
package/src/types.ts CHANGED
@@ -161,6 +161,9 @@ export interface RevnixConfig {
161
161
  * read. A null answer deletes a previously stored `gps_adid`; a
162
162
  * rejection changes nothing and reports `op: "advertisingId"`. */
163
163
  advertisingId?: () => Promise<string | null | undefined>;
164
+ /** Google Play product ids sold as consumables. A registered purchase of
165
+ * one is consumed instead of acknowledged so it can be bought again. */
166
+ consumableProductIds?: string[];
164
167
  }
165
168
 
166
169
  /** Device integrity evidence for `POST /v1/installs` and `/v1/attribution`.
@@ -375,6 +378,16 @@ export interface PlacementPackage {
375
378
  product: PlacementProduct | null;
376
379
  }
377
380
 
381
+ /** One plan as a paywall drew it, for `logPaywallShown`'s `productsShown`:
382
+ * the localized label the customer actually read, and the catalog price
383
+ * behind it. */
384
+ export interface PaywallProductShown {
385
+ productId: string;
386
+ priceLabel?: string;
387
+ amountMinor?: number;
388
+ currency?: string;
389
+ }
390
+
378
391
  export interface PlacementProduct {
379
392
  productId: string;
380
393
  displayName: string;
@@ -33,6 +33,7 @@ import {
33
33
  import type {
34
34
  PaywallConfig,
35
35
  PaywallInteraction,
36
+ PaywallProductShown,
36
37
  PaywallPurchaseOutcome,
37
38
  PlacementResolution,
38
39
  RegisterPurchaseResult,
@@ -195,6 +196,7 @@ export interface RevnixPaywallProps {
195
196
  logPaywallShown: (options?: {
196
197
  placementKey?: string;
197
198
  paywallId?: string;
199
+ productsShown?: PaywallProductShown[];
198
200
  }) => string | void;
199
201
  /** Older clients predate close reporting; the paywall still closes. */
200
202
  logPaywallClosed?: (
@@ -278,6 +280,32 @@ export async function prefetchPaywallImages(
278
280
  );
279
281
  }
280
282
 
283
+ function visiblePackages(
284
+ config: PaywallConfig,
285
+ packages: RevnixPaywallPackage[]
286
+ ): RevnixPaywallPackage[] {
287
+ return config.template === "minimal" && config.highlightPackageId
288
+ ? packages.filter((p) => p.packageId === config.highlightPackageId)
289
+ : packages;
290
+ }
291
+
292
+ function productsShownFrom(
293
+ packages: RevnixPaywallPackage[]
294
+ ): PaywallProductShown[] {
295
+ return packages.flatMap((pkg) =>
296
+ pkg.productId
297
+ ? [
298
+ {
299
+ productId: pkg.productId,
300
+ priceLabel: pkg.priceLabel,
301
+ amountMinor: pkg.amountMinor,
302
+ currency: pkg.currency,
303
+ },
304
+ ]
305
+ : []
306
+ );
307
+ }
308
+
281
309
  export function RevnixPaywall(props: RevnixPaywallProps) {
282
310
  // One view per mount: remounting (a re-shown paywall) is a genuine new
283
311
  // display; re-renders are not.
@@ -287,7 +315,11 @@ export function RevnixPaywall(props: RevnixPaywallProps) {
287
315
  const viewIdRef = React.useRef<string | undefined>(undefined);
288
316
  React.useEffect(() => {
289
317
  if (!client || disableViewTracking) return;
290
- const id = client.logPaywallShown({ placementKey, paywallId });
318
+ const id = client.logPaywallShown({
319
+ placementKey,
320
+ paywallId,
321
+ productsShown: productsShownFrom(visiblePackages(props.config, props.packages)),
322
+ });
291
323
  // Pre-REV-252 clients return void; the close then still fires the host
292
324
  // callback, it just cannot be paired with this display.
293
325
  if (typeof id === "string") viewIdRef.current = id;
@@ -605,10 +637,7 @@ function ClassicPaywall(
605
637
 
606
638
  // Same template semantics as the dashboard preview: "minimal" shows only
607
639
  // the highlighted package; feature bullets render on the feature layouts.
608
- const shown =
609
- layout === "minimal" && config.highlightPackageId
610
- ? packages.filter((p) => p.packageId === config.highlightPackageId)
611
- : packages;
640
+ const shown = visiblePackages(config, packages);
612
641
 
613
642
  const [internalSelected, setInternalSelected] = React.useState<
614
643
  string | undefined
package/src/version.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  // L3: the single source of the SDK version inside src/. Must match
2
2
  // package.json "version" — version.test.ts fails the build when they drift
3
3
  // (they had: client.ts said 0.7.0 while the package shipped 0.9.0).
4
- export const SDK_VERSION = "1.8.0";
4
+ export const SDK_VERSION = "1.11.0";