@aranova/tracking-react 0.22.2 → 0.22.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -2,8 +2,8 @@ import * as react from 'react';
2
2
  import { ReactNode, CSSProperties, InputHTMLAttributes, ChangeEvent, FocusEvent } from 'react';
3
3
  import { T as TrackingParams, a as TrackingInstallSurface, b as TrackingEnvironment, c as TrackingClientContext, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, F as FormSubmitConfig, f as FormSubmitMetadata, G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, C as ConsentState, g as ConsentChoiceState, h as ConsentSource, P as PhoneConfig, i as ParsedPhone, j as PhoneDisplayFormat } from './phone-utils-BhWfNuPS.mjs';
4
4
  export { k as ConsentChoice, D as DEFAULT_DECLINE_TTL_DAYS, l as DEFAULT_PHONE_COUNTRY, J as JsonValue, S as SetConsentOptions, m as TrackedField, n as TrackingInitConfig, o as formSubmitConfigSchema, p as formSubmitMetadataSchema, q as formatPhone, r as formatPhoneAsTyped, s as getConsentChoice, t as getConsentState, u as jsonValueSchema, v as onConsentChange, w as optIn, x as optOut, y as parsePhone, z as phoneField, A as resetConsent, B as setConsentState, E as toE164 } from './phone-utils-BhWfNuPS.mjs';
5
- import { T as TrackingConfigReference, C as ConversionConfig } from './sales-BfmXpXem.mjs';
6
- export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as ConversionUserData, f as CurrencyRevenue, g as CustomerCurrencyDelta, h as CustomerCurrencyTotal, i as CustomerGetOptions, j as CustomerGetResult, k as CustomerKpis, l as CustomerKpisDeltas, m as CustomerKpisPrevious, n as CustomerListPage, o as CustomerListQuery, p as CustomerProfile, q as CustomerSegment, r as CustomerSegmentCount, s as CustomerSortField, t as CustomerSummary, u as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, v as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, w as Sale, x as SaleCursorPage, y as SaleFilters, z as SaleInput, E as SaleItem, F as SaleItemInput, H as SaleKeysetSortField, I as SaleListPage, J as SaleListQuery, K as SaleListQueryV2, L as SaleService, M as SaleServiceInput, O as SaleSortField, Q as SaleSortOrder, R as SaleSummary, U as SaleSummaryPrevious, V as SaleSummaryQuery, W as SaleSummaryQueryV2, X as SaleSummaryV2, Y as SaleUpdateInput, Z as SalesBusinessClient, _ as SalesCategoryBreakdown, $ as SalesClient, a0 as SalesClientConfig, a1 as SalesCustomersClient, a2 as SalesServiceBreakdown, a3 as SalesTransportConfig, a4 as SalesTrendPoint, a5 as SummaryCurrencyDelta, a6 as SummaryDeltas, a7 as SummaryWindow, a8 as SupportedCurrency, a9 as TRACKING_RANGES, aa as TrackingOverviewRange, ab as clearStashedUserData, ac as createSalesClient, ad as fetchServices, ae as formatDateInTz, af as formatMoney, ag as fromMinor, ah as getTrackingConfigRuntime, ai as resolveConversionConfig, aj as saleCreateSchema, ak as saleItemSchema, al as saleServiceSchema, am as saleUpdateSchema, an as salesRequest, ao as stashUserData, ap as toMinor } from './sales-BfmXpXem.mjs';
5
+ import { T as TrackingConfigReference, C as ConversionConfig } from './sales-hH-509J5.mjs';
6
+ export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as ConversionUserData, f as CurrencyRevenue, g as CustomerCurrencyDelta, h as CustomerCurrencyTotal, i as CustomerGetOptions, j as CustomerGetResult, k as CustomerKpis, l as CustomerKpisDeltas, m as CustomerKpisPrevious, n as CustomerListPage, o as CustomerListQuery, p as CustomerProfile, q as CustomerSegment, r as CustomerSegmentCount, s as CustomerSortField, t as CustomerSummary, u as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, v as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, w as Sale, x as SaleCursorPage, y as SaleFilters, z as SaleInput, E as SaleItem, F as SaleItemInput, H as SaleKeysetSortField, I as SaleListPage, J as SaleListQuery, K as SaleListQueryV2, L as SaleService, M as SaleServiceInput, O as SaleSortField, Q as SaleSortOrder, R as SaleSummary, U as SaleSummaryPrevious, V as SaleSummaryQuery, W as SaleSummaryQueryV2, X as SaleSummaryV2, Y as SaleUpdateInput, Z as SalesBusinessClient, _ as SalesCategoryBreakdown, $ as SalesClient, a0 as SalesClientConfig, a1 as SalesCustomersClient, a2 as SalesServiceBreakdown, a3 as SalesTransportConfig, a4 as SalesTrendPoint, a5 as SummaryCurrencyDelta, a6 as SummaryDeltas, a7 as SummaryWindow, a8 as SupportedCurrency, a9 as TRACKING_RANGES, aa as TrackingOverviewRange, ab as clearStashedUserData, ac as createSalesClient, ad as fetchServices, ae as formatDateInTz, af as formatMoney, ag as fromMinor, ah as getTrackingConfigRuntime, ai as resolveConversionConfig, aj as saleCreateSchema, ak as saleItemSchema, al as saleServiceSchema, am as saleUpdateSchema, an as salesRequest, ao as stashUserData, ap as toMinor } from './sales-hH-509J5.mjs';
7
7
  import * as src from 'src';
8
8
  import { z } from 'zod';
9
9
  import { CountryCode } from 'libphonenumber-js';
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import * as react from 'react';
2
2
  import { ReactNode, CSSProperties, InputHTMLAttributes, ChangeEvent, FocusEvent } from 'react';
3
3
  import { T as TrackingParams, a as TrackingInstallSurface, b as TrackingEnvironment, c as TrackingClientContext, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, F as FormSubmitConfig, f as FormSubmitMetadata, G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, C as ConsentState, g as ConsentChoiceState, h as ConsentSource, P as PhoneConfig, i as ParsedPhone, j as PhoneDisplayFormat } from './phone-utils-BhWfNuPS.js';
4
4
  export { k as ConsentChoice, D as DEFAULT_DECLINE_TTL_DAYS, l as DEFAULT_PHONE_COUNTRY, J as JsonValue, S as SetConsentOptions, m as TrackedField, n as TrackingInitConfig, o as formSubmitConfigSchema, p as formSubmitMetadataSchema, q as formatPhone, r as formatPhoneAsTyped, s as getConsentChoice, t as getConsentState, u as jsonValueSchema, v as onConsentChange, w as optIn, x as optOut, y as parsePhone, z as phoneField, A as resetConsent, B as setConsentState, E as toE164 } from './phone-utils-BhWfNuPS.js';
5
- import { T as TrackingConfigReference, C as ConversionConfig } from './sales-BfmXpXem.js';
6
- export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as ConversionUserData, f as CurrencyRevenue, g as CustomerCurrencyDelta, h as CustomerCurrencyTotal, i as CustomerGetOptions, j as CustomerGetResult, k as CustomerKpis, l as CustomerKpisDeltas, m as CustomerKpisPrevious, n as CustomerListPage, o as CustomerListQuery, p as CustomerProfile, q as CustomerSegment, r as CustomerSegmentCount, s as CustomerSortField, t as CustomerSummary, u as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, v as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, w as Sale, x as SaleCursorPage, y as SaleFilters, z as SaleInput, E as SaleItem, F as SaleItemInput, H as SaleKeysetSortField, I as SaleListPage, J as SaleListQuery, K as SaleListQueryV2, L as SaleService, M as SaleServiceInput, O as SaleSortField, Q as SaleSortOrder, R as SaleSummary, U as SaleSummaryPrevious, V as SaleSummaryQuery, W as SaleSummaryQueryV2, X as SaleSummaryV2, Y as SaleUpdateInput, Z as SalesBusinessClient, _ as SalesCategoryBreakdown, $ as SalesClient, a0 as SalesClientConfig, a1 as SalesCustomersClient, a2 as SalesServiceBreakdown, a3 as SalesTransportConfig, a4 as SalesTrendPoint, a5 as SummaryCurrencyDelta, a6 as SummaryDeltas, a7 as SummaryWindow, a8 as SupportedCurrency, a9 as TRACKING_RANGES, aa as TrackingOverviewRange, ab as clearStashedUserData, ac as createSalesClient, ad as fetchServices, ae as formatDateInTz, af as formatMoney, ag as fromMinor, ah as getTrackingConfigRuntime, ai as resolveConversionConfig, aj as saleCreateSchema, ak as saleItemSchema, al as saleServiceSchema, am as saleUpdateSchema, an as salesRequest, ao as stashUserData, ap as toMinor } from './sales-BfmXpXem.js';
5
+ import { T as TrackingConfigReference, C as ConversionConfig } from './sales-hH-509J5.js';
6
+ export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as ConversionUserData, f as CurrencyRevenue, g as CustomerCurrencyDelta, h as CustomerCurrencyTotal, i as CustomerGetOptions, j as CustomerGetResult, k as CustomerKpis, l as CustomerKpisDeltas, m as CustomerKpisPrevious, n as CustomerListPage, o as CustomerListQuery, p as CustomerProfile, q as CustomerSegment, r as CustomerSegmentCount, s as CustomerSortField, t as CustomerSummary, u as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, v as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, w as Sale, x as SaleCursorPage, y as SaleFilters, z as SaleInput, E as SaleItem, F as SaleItemInput, H as SaleKeysetSortField, I as SaleListPage, J as SaleListQuery, K as SaleListQueryV2, L as SaleService, M as SaleServiceInput, O as SaleSortField, Q as SaleSortOrder, R as SaleSummary, U as SaleSummaryPrevious, V as SaleSummaryQuery, W as SaleSummaryQueryV2, X as SaleSummaryV2, Y as SaleUpdateInput, Z as SalesBusinessClient, _ as SalesCategoryBreakdown, $ as SalesClient, a0 as SalesClientConfig, a1 as SalesCustomersClient, a2 as SalesServiceBreakdown, a3 as SalesTransportConfig, a4 as SalesTrendPoint, a5 as SummaryCurrencyDelta, a6 as SummaryDeltas, a7 as SummaryWindow, a8 as SupportedCurrency, a9 as TRACKING_RANGES, aa as TrackingOverviewRange, ab as clearStashedUserData, ac as createSalesClient, ad as fetchServices, ae as formatDateInTz, af as formatMoney, ag as fromMinor, ah as getTrackingConfigRuntime, ai as resolveConversionConfig, aj as saleCreateSchema, ak as saleItemSchema, al as saleServiceSchema, am as saleUpdateSchema, an as salesRequest, ao as stashUserData, ap as toMinor } from './sales-hH-509J5.js';
7
7
  import * as src from 'src';
8
8
  import { z } from 'zod';
9
9
  import { CountryCode } from 'libphonenumber-js';
package/dist/index.js CHANGED
@@ -1120,6 +1120,9 @@ function formatMoney(cents, currency, locale) {
1120
1120
  // ../tracking-core/src/resources/tracking-config-runtime.ts
1121
1121
  var CACHE_PREFIX2 = "_aranova_cfg_runtime_";
1122
1122
  var AUTHORITY_TTL_MS = 6e4;
1123
+ var MAX_QUEUE_LENGTH = 50;
1124
+ var RETRY_BASE_MS = 5e3;
1125
+ var RETRY_MAX_MS = 5 * 6e4;
1123
1126
  var runtimes = /* @__PURE__ */ new Map();
1124
1127
  var configuredIds = /* @__PURE__ */ new Set();
1125
1128
  var scriptLoad = null;
@@ -1127,6 +1130,10 @@ var jsInitialized = false;
1127
1130
  function cacheKey2(url) {
1128
1131
  return `${CACHE_PREFIX2}${url}`;
1129
1132
  }
1133
+ function pushBounded(queue, item) {
1134
+ queue.push(item);
1135
+ if (queue.length > MAX_QUEUE_LENGTH) queue.splice(0, queue.length - MAX_QUEUE_LENGTH);
1136
+ }
1130
1137
  function readCache2(url) {
1131
1138
  if (typeof window === "undefined") return null;
1132
1139
  try {
@@ -1207,6 +1214,10 @@ var TrackingConfigRuntime = class {
1207
1214
  this.flushRequested = false;
1208
1215
  this.retryTimer = null;
1209
1216
  this.started = false;
1217
+ /** Consecutive failed authority attempts — drives the revalidate backoff. */
1218
+ this.authorityFailures = 0;
1219
+ /** Epoch ms before which `ensureAuthority` must not issue another request. */
1220
+ this.nextAuthorityAttemptAt = 0;
1210
1221
  this.conversionQueue = [];
1211
1222
  this.automaticQueue = [];
1212
1223
  this.pageQueue = [];
@@ -1245,6 +1256,15 @@ var TrackingConfigRuntime = class {
1245
1256
  }
1246
1257
  __unsafeExpireAuthorityForTests() {
1247
1258
  this.confirmedAt = Number.NEGATIVE_INFINITY;
1259
+ this.nextAuthorityAttemptAt = 0;
1260
+ }
1261
+ /** Queue depths — asserted by tests to pin the bound. */
1262
+ __queueDepthsForTests() {
1263
+ return {
1264
+ conversions: this.conversionQueue.length,
1265
+ automatic: this.automaticQueue.length,
1266
+ pages: this.pageQueue.length
1267
+ };
1248
1268
  }
1249
1269
  subscribe(listener) {
1250
1270
  this.listeners.add(listener);
@@ -1254,10 +1274,12 @@ var TrackingConfigRuntime = class {
1254
1274
  if (this.stateValue !== "unconfirmed" && Date.now() - this.confirmedAt < AUTHORITY_TTL_MS) {
1255
1275
  return true;
1256
1276
  }
1277
+ if (Date.now() < this.nextAuthorityAttemptAt) return false;
1257
1278
  await this.revalidateAuthority();
1258
1279
  return this.stateValue !== "unconfirmed" && Date.now() - this.confirmedAt < AUTHORITY_TTL_MS;
1259
1280
  }
1260
1281
  async revalidate() {
1282
+ this.nextAuthorityAttemptAt = 0;
1261
1283
  await this.revalidateAuthority();
1262
1284
  await this.flush();
1263
1285
  }
@@ -1271,15 +1293,20 @@ var TrackingConfigRuntime = class {
1271
1293
  }
1272
1294
  queuePageView(snapshot = pageViewSnapshot()) {
1273
1295
  if (!snapshot) return;
1274
- this.pageQueue.push(snapshot);
1296
+ pushBounded(this.pageQueue, snapshot);
1275
1297
  void this.flush();
1276
1298
  }
1277
1299
  fireConversion(key, options) {
1278
- this.conversionQueue.push({ key, ...options });
1300
+ pushBounded(this.conversionQueue, { key, ...options });
1279
1301
  void this.flush();
1280
1302
  }
1281
1303
  queueAutomaticEvent(eventType, metadata, transactionPath, transactionScope) {
1282
- this.automaticQueue.push({ eventType, metadata, transactionPath, transactionScope });
1304
+ pushBounded(this.automaticQueue, {
1305
+ eventType,
1306
+ metadata,
1307
+ transactionPath,
1308
+ transactionScope
1309
+ });
1283
1310
  void this.flush();
1284
1311
  }
1285
1312
  listGoals() {
@@ -1319,12 +1346,17 @@ var TrackingConfigRuntime = class {
1319
1346
  expireAuthority() {
1320
1347
  this.authorityGeneration += 1;
1321
1348
  if (this.stateValue !== "unconfirmed") this.stateValue = "unconfirmed";
1349
+ this.authorityFailures += 1;
1350
+ const delay = Math.min(RETRY_MAX_MS, RETRY_BASE_MS * 2 ** (this.authorityFailures - 1));
1351
+ this.nextAuthorityAttemptAt = Date.now() + delay;
1322
1352
  }
1323
1353
  confirm(config, etag) {
1324
1354
  this.authorityGeneration += 1;
1325
1355
  this.current = config;
1326
1356
  this.etag = etag;
1327
1357
  this.confirmedAt = Date.now();
1358
+ this.authorityFailures = 0;
1359
+ this.nextAuthorityAttemptAt = 0;
1328
1360
  this.stateValue = isTombstone(config) ? "tombstone" : "active";
1329
1361
  writeCache2(this.ref.cdnUrl, { etag, config });
1330
1362
  if (this.stateValue === "tombstone") {
@@ -1405,7 +1437,7 @@ var TrackingConfigRuntime = class {
1405
1437
  for (const goal of config.goals) {
1406
1438
  if (goal.kind !== "event" || !goal.firing) continue;
1407
1439
  if (!automaticThresholdMet(goal, event.eventType, event.metadata)) continue;
1408
- this.conversionQueue.push({
1440
+ pushBounded(this.conversionQueue, {
1409
1441
  key: goal.key,
1410
1442
  transactionId: getAutomaticTransactionId(
1411
1443
  event.transactionScope,
@@ -3397,7 +3429,12 @@ var saleCreateSchema = import_zod12.z.object({
3397
3429
  customer_email: customerEmailSchema.nullable().optional(),
3398
3430
  // CASL consent attestation: the customer agreed to receive SMS. Recorded
3399
3431
  // with a timestamp server-side; every SMS send path gates on it.
3400
- sms_consent: import_zod12.z.boolean().default(false)
3432
+ //
3433
+ // Tri-state: omit it (or send null) to let the server apply the business's
3434
+ // configured default-opt-in policy, honouring a returning customer's
3435
+ // remembered preference. Send an explicit boolean to assert consent state
3436
+ // yourself — `false` records a deliberate opt-out.
3437
+ sms_consent: import_zod12.z.boolean().nullable().optional()
3401
3438
  }).strict().superRefine((val, ctx) => refineServiceXor(val, ctx, { requireAmount: true }));
3402
3439
  var saleUpdateSchema = import_zod12.z.object({
3403
3440
  description: import_zod12.z.string().nullable().optional(),
@@ -3773,7 +3810,7 @@ function GoogleAdsTracking(props) {
3773
3810
  var import_react6 = require("react");
3774
3811
 
3775
3812
  // package.json
3776
- var version = "0.22.2";
3813
+ var version = "0.22.4";
3777
3814
 
3778
3815
  // ../tracking-core/src/phone-react.tsx
3779
3816
  var import_react5 = require("react");