@aranova/tracking-react 0.26.0 → 1.0.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.
Files changed (35) hide show
  1. package/dist/client.d.mts +5 -4
  2. package/dist/client.d.ts +5 -4
  3. package/dist/client.js +207 -283
  4. package/dist/client.js.map +1 -1
  5. package/dist/client.mjs +169 -255
  6. package/dist/client.mjs.map +1 -1
  7. package/dist/index.d.mts +7 -6
  8. package/dist/index.d.ts +7 -6
  9. package/dist/index.js +275 -391
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +264 -391
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/ingest-typed-BdKmlouW.d.ts +791 -0
  14. package/dist/ingest-typed-Bo7WPmpU.d.mts +791 -0
  15. package/dist/{phone-utils-BVzSNBf1.d.mts → phone-utils-CubQif9Z.d.mts} +18 -78
  16. package/dist/{phone-utils-BVzSNBf1.d.ts → phone-utils-CubQif9Z.d.ts} +18 -78
  17. package/dist/phone.d.mts +2 -2
  18. package/dist/phone.d.ts +2 -2
  19. package/dist/phone.js +0 -462
  20. package/dist/phone.js.map +1 -1
  21. package/dist/phone.mjs +0 -462
  22. package/dist/phone.mjs.map +1 -1
  23. package/dist/{sales-1J-Z4AvL.d.ts → sales-Bhh9mLBA.d.ts} +90 -329
  24. package/dist/{sales-DzKvyVjY.d.mts → sales-C7Xjsq-a.d.mts} +90 -329
  25. package/dist/sales.d.mts +3 -3
  26. package/dist/sales.d.ts +3 -3
  27. package/dist/sales.js +265 -127
  28. package/dist/sales.js.map +1 -1
  29. package/dist/sales.mjs +254 -127
  30. package/dist/sales.mjs.map +1 -1
  31. package/dist/{tracking-config-runtime-BnUlS_Ae.d.mts → tracking-config-runtime-D7prdTE1.d.mts} +6 -0
  32. package/dist/{tracking-config-runtime-BnUlS_Ae.d.ts → tracking-config-runtime-D7prdTE1.d.ts} +6 -0
  33. package/package.json +2 -2
  34. package/dist/ingest-typed-BioxtBJD.d.mts +0 -1365
  35. package/dist/ingest-typed-C-SPiigr.d.ts +0 -1365
package/dist/index.mjs CHANGED
@@ -60,7 +60,7 @@ function normalizeEmail(raw) {
60
60
  return EMAIL_SHAPE.test(cleaned) ? cleaned : null;
61
61
  }
62
62
  function stashUserData(data, country) {
63
- const email = normalizeEmail(data.email);
63
+ const email3 = normalizeEmail(data.email);
64
64
  let phoneNumber = null;
65
65
  if (typeof data.phone === "string" && data.phone.length > 0) {
66
66
  try {
@@ -70,7 +70,7 @@ function stashUserData(data, country) {
70
70
  }
71
71
  }
72
72
  stash = {
73
- email: email ?? stash.email,
73
+ email: email3 ?? stash.email,
74
74
  phoneNumber: phoneNumber ?? stash.phoneNumber
75
75
  };
76
76
  }
@@ -79,11 +79,11 @@ function clearStashedUserData() {
79
79
  }
80
80
  function applyUserDataForConversion(explicit, country) {
81
81
  if (typeof window === "undefined" || typeof window.gtag !== "function") return false;
82
- let email = stash.email;
82
+ let email3 = stash.email;
83
83
  let phoneNumber = stash.phoneNumber;
84
84
  if (explicit) {
85
85
  const normalizedEmail = normalizeEmail(explicit.email);
86
- if (normalizedEmail) email = normalizedEmail;
86
+ if (normalizedEmail) email3 = normalizedEmail;
87
87
  if (typeof explicit.phone === "string" && explicit.phone.length > 0) {
88
88
  try {
89
89
  phoneNumber = toE164(explicit.phone, country) ?? phoneNumber;
@@ -91,10 +91,10 @@ function applyUserDataForConversion(explicit, country) {
91
91
  }
92
92
  }
93
93
  }
94
- if (email === null && phoneNumber === null) return false;
94
+ if (email3 === null && phoneNumber === null) return false;
95
95
  try {
96
96
  window.gtag("set", "user_data", {
97
- ...email !== null ? { email } : {},
97
+ ...email3 !== null ? { email: email3 } : {},
98
98
  ...phoneNumber !== null ? { phone_number: phoneNumber } : {}
99
99
  });
100
100
  return true;
@@ -450,10 +450,10 @@ function readStoredRecord() {
450
450
  return null;
451
451
  }
452
452
  }
453
- function writeRecord(record) {
454
- memoryRecord = record;
453
+ function writeRecord(record3) {
454
+ memoryRecord = record3;
455
455
  try {
456
- window.localStorage.setItem(LANDING_STORAGE_KEY, JSON.stringify(record));
456
+ window.localStorage.setItem(LANDING_STORAGE_KEY, JSON.stringify(record3));
457
457
  } catch {
458
458
  }
459
459
  }
@@ -475,9 +475,9 @@ function getOrCaptureLandingParams(sessionId, url) {
475
475
  if (memoryRecord && memoryRecord.session_id === sessionId) {
476
476
  return memoryRecord.params;
477
477
  }
478
- const record = { session_id: sessionId, params: captureFromUrl(url) };
479
- writeRecord(record);
480
- return record.params;
478
+ const record3 = { session_id: sessionId, params: captureFromUrl(url) };
479
+ writeRecord(record3);
480
+ return record3.params;
481
481
  }
482
482
  function buildLandingPayloadFields(sessionId, override) {
483
483
  const params = override ?? (typeof window === "undefined" ? null : getOrCaptureLandingParams(sessionId));
@@ -854,9 +854,9 @@ function automaticThresholdMet(goal, eventType, metadata) {
854
854
  }
855
855
 
856
856
  // ../tracking-core/src/resources/intl/date.ts
857
- function formatDateInTz(iso, timeZone, opts, locale) {
858
- const date = new Date(iso);
859
- if (Number.isNaN(date.getTime())) return iso;
857
+ function formatDateInTz(iso3, timeZone, opts, locale) {
858
+ const date = new Date(iso3);
859
+ if (Number.isNaN(date.getTime())) return iso3;
860
860
  return new Intl.DateTimeFormat(locale, {
861
861
  year: "numeric",
862
862
  month: "short",
@@ -890,14 +890,15 @@ function formatMoney(cents, currency, locale) {
890
890
 
891
891
  // ../tracking-core/src/resources/tracking-config-runtime.ts
892
892
  var DEFAULT_CDN_BASE_URL = "https://demos.aranova.io";
893
- function trackingConfigKey(businessId, environment) {
894
- return `tracking-config/v1/${businessId}-${environment}.json`;
893
+ function trackingConfigKey(ref) {
894
+ if (ref.siteId) return `tracking-config/v1/sites/${ref.siteId}-${ref.environment}.json`;
895
+ return `tracking-config/v1/${ref.businessId}-${ref.environment}.json`;
895
896
  }
896
897
  function resolveTrackingConfigUrl(ref) {
897
898
  if (ref.cdnUrl) return ref.cdnUrl;
898
899
  const configured = ref.cdnBaseUrl?.trim();
899
900
  const base = (configured || DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
900
- return `${base}/${trackingConfigKey(ref.businessId, ref.environment)}`;
901
+ return `${base}/${trackingConfigKey(ref)}`;
901
902
  }
902
903
  var CACHE_PREFIX2 = "_aranova_cfg_runtime_";
903
904
  var AUTHORITY_TTL_MS = 6e4;
@@ -1267,29 +1268,6 @@ function getTrackingConfigRuntime(ref, fetchImpl) {
1267
1268
  return runtime;
1268
1269
  }
1269
1270
 
1270
- // ../tracking-core/src/session.ts
1271
- var SESSION_IDLE_MS = 30 * 60 * 1e3;
1272
-
1273
- // ../tracking-core/src/events/page-view.ts
1274
- import { z } from "zod";
1275
- var pageViewMetadataSchema = z.object({
1276
- page: z.object({
1277
- title: z.string().nullable(),
1278
- path: z.string(),
1279
- search: z.string(),
1280
- hash: z.string()
1281
- }).strict(),
1282
- referrer: z.string().nullable(),
1283
- // `.nullable().optional()` — absent (undefined) OR explicit null OR a
1284
- // real viewport object. Mirrors Pydantic's `_Viewport | None = None`
1285
- // on the backend side so the drift test stays clean.
1286
- viewport: z.object({
1287
- w: z.number(),
1288
- h: z.number()
1289
- }).strict().nullable().optional()
1290
- }).strict();
1291
- var pageViewConfigSchema = z.object({}).strict();
1292
-
1293
1271
  // ../tracking-core/src/ingest.ts
1294
1272
  var API_KEY_HEADER = "X-Aranova-Api-Key";
1295
1273
  var SDK_VERSION_HEADER = "X-Aranova-Sdk-Version";
@@ -1297,185 +1275,6 @@ var SDK_PACKAGE_HEADER = "X-Aranova-Sdk-Package";
1297
1275
  var SDK_SURFACE_HEADER = "X-Aranova-Sdk-Surface";
1298
1276
  var SDK_ENVIRONMENT_HEADER = "X-Aranova-Sdk-Environment";
1299
1277
 
1300
- // ../tracking-core/src/events/cta-click.ts
1301
- import { z as z2 } from "zod";
1302
- var ctaClickMetadataSchema = z2.object({
1303
- cta_name: z2.string(),
1304
- page: z2.object({
1305
- path: z2.string()
1306
- }).strict(),
1307
- section: z2.string().nullable().optional(),
1308
- destination_url: z2.string().nullable().optional(),
1309
- // Set by auto-capture (and available to manual callers): the link target
1310
- // and a short element descriptor (tag#id) for tying clicks to specific UI.
1311
- href: z2.string().nullable().optional(),
1312
- element: z2.string().nullable().optional()
1313
- }).strict();
1314
- var ctaClickConfigSchema = z2.object({
1315
- autoCapture: z2.object({
1316
- selector: z2.string().optional()
1317
- }).strict().optional()
1318
- }).strict();
1319
-
1320
- // ../tracking-core/src/events/sdk-heartbeat.ts
1321
- import { z as z3 } from "zod";
1322
- var sdkHeartbeatTriggersSchema = z3.object({
1323
- automatic: z3.array(z3.string()),
1324
- manual: z3.array(z3.string())
1325
- }).strict();
1326
- var sdkHeartbeatMetadataSchema = z3.object({
1327
- sdk_version: z3.string(),
1328
- package_name: z3.string().nullable(),
1329
- surface: z3.enum(["next", "react", "script"]),
1330
- triggers: sdkHeartbeatTriggersSchema,
1331
- trigger_config: z3.record(z3.string(), z3.record(z3.string(), z3.unknown())).nullable().optional(),
1332
- configured_gtag_ids: z3.record(z3.string(), z3.string()).nullable().optional()
1333
- }).strict();
1334
- var sdkHeartbeatConfigSchema = z3.object({}).strict();
1335
-
1336
- // ../tracking-core/src/events/form-start.ts
1337
- import { z as z4 } from "zod";
1338
- var formStartMetadataSchema = z4.object({
1339
- form: z4.object({
1340
- id: z4.string(),
1341
- action: z4.string().nullable()
1342
- }).strict(),
1343
- page: z4.object({
1344
- path: z4.string()
1345
- }).strict()
1346
- }).strict();
1347
- var formStartConfigSchema = z4.object({
1348
- selector: z4.string().optional()
1349
- }).strict();
1350
-
1351
- // ../tracking-core/src/events/form-submit.ts
1352
- import { z as z5 } from "zod";
1353
- var jsonValueSchema = z5.lazy(
1354
- () => z5.union([
1355
- z5.string(),
1356
- z5.number().finite(),
1357
- z5.boolean(),
1358
- z5.null(),
1359
- z5.array(jsonValueSchema),
1360
- z5.record(jsonValueSchema)
1361
- ])
1362
- );
1363
- var formSubmitMetadataSchema = z5.object({
1364
- form: z5.object({
1365
- id: z5.string(),
1366
- action: z5.string().nullable(),
1367
- fields: z5.array(
1368
- z5.object({
1369
- name: z5.string(),
1370
- type: z5.string(),
1371
- label: z5.string().nullable(),
1372
- value: jsonValueSchema
1373
- }).strict()
1374
- ).optional()
1375
- }).strict(),
1376
- page: z5.object({
1377
- path: z5.string()
1378
- }).strict()
1379
- }).strict();
1380
- var formSubmitConfigSchema = z5.object({}).strict();
1381
-
1382
- // ../tracking-core/src/events/multi-page-session.ts
1383
- import { z as z6 } from "zod";
1384
- var multiPageSessionMetadataSchema = z6.object({
1385
- page_count: z6.number().int().min(2),
1386
- page: z6.object({
1387
- path: z6.string()
1388
- }).strict()
1389
- }).strict();
1390
- var multiPageSessionConfigSchema = z6.object({
1391
- pageThreshold: z6.number().int().min(2)
1392
- }).strict();
1393
-
1394
- // ../tracking-core/src/events/page-exit.ts
1395
- import { z as z7 } from "zod";
1396
- var pageExitMetadataSchema = z7.object({
1397
- dwell_ms: z7.number().int().min(0),
1398
- // null = left without any scroll signal; floor is 0 so a valid 0% is never
1399
- // rejected (a single bad field 422s the whole keepalive beacon batch).
1400
- max_scroll_percent: z7.number().int().min(0).max(100).nullable(),
1401
- // The gating baseline: the fraction of the page visible at load with
1402
- // zero scrolling — or, for pages that grew after the post-paint snapshot
1403
- // (skeleton/streaming renders), the first-scroll position that
1404
- // established it. null = page had no scrollable range, or the segment
1405
- // ended before the snapshot. `.optional()` is load-bearing: SDK builds
1406
- // predating this field keep POSTing page_exit without the key —
1407
- // requiring it would 422 whole keepalive beacon batches.
1408
- scroll_baseline_percent: z7.number().int().min(0).max(100).nullable().optional(),
1409
- page: z7.object({
1410
- path: z7.string()
1411
- }).strict()
1412
- }).strict();
1413
- var pageExitConfigSchema = z7.object({}).strict();
1414
-
1415
- // ../tracking-core/src/events/phone-click.ts
1416
- import { z as z8 } from "zod";
1417
- var phoneClickMetadataSchema = z8.object({
1418
- phone_number: z8.string(),
1419
- page: z8.object({
1420
- path: z8.string()
1421
- }).strict(),
1422
- section: z8.string().nullable().optional()
1423
- }).strict();
1424
- var phoneClickConfigSchema = z8.object({
1425
- autoCapture: z8.object({
1426
- selector: z8.string().optional()
1427
- }).strict().optional()
1428
- }).strict();
1429
-
1430
- // ../tracking-core/src/events/scroll-depth.ts
1431
- import { z as z9 } from "zod";
1432
- var scrollDepthMetadataSchema = z9.object({
1433
- depth_percent: z9.number().int().min(1).max(100),
1434
- page: z9.object({
1435
- path: z9.string()
1436
- }).strict()
1437
- }).strict();
1438
- var scrollDepthConfigSchema = z9.object({
1439
- thresholds: z9.array(z9.number().int().min(1).max(100)).min(1)
1440
- }).strict();
1441
-
1442
- // ../tracking-core/src/events/specific-page-visit.ts
1443
- import { z as z10 } from "zod";
1444
- var PAGE_IDENTITY_MAX_LENGTH = 64;
1445
- var PAGE_IDENTITY_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
1446
- var pageIdentitySchema = z10.string().max(PAGE_IDENTITY_MAX_LENGTH).regex(PAGE_IDENTITY_PATTERN, {
1447
- message: "page identity must be lowercase snake_case, start with a letter, and contain at most 64 characters"
1448
- });
1449
- var specificPageNameSchema = pageIdentitySchema;
1450
- var specificPageVisitMetadataSchema = z10.object({
1451
- page_name: specificPageNameSchema,
1452
- page: z10.object({
1453
- path: z10.string()
1454
- }).strict()
1455
- }).strict();
1456
- var specificPageVisitConfigSchema = z10.object({
1457
- pages: z10.array(
1458
- z10.object({
1459
- name: specificPageNameSchema,
1460
- pathPattern: z10.custom((value) => value instanceof RegExp, {
1461
- message: "pathPattern must be a RegExp"
1462
- })
1463
- }).strict()
1464
- ).min(1)
1465
- }).strict();
1466
-
1467
- // ../tracking-core/src/events/time-on-site.ts
1468
- import { z as z11 } from "zod";
1469
- var timeOnSiteMetadataSchema = z11.object({
1470
- duration_ms: z11.number().int().nonnegative(),
1471
- page: z11.object({
1472
- path: z11.string()
1473
- }).strict()
1474
- }).strict();
1475
- var timeOnSiteConfigSchema = z11.object({
1476
- thresholdSeconds: z11.number().int().positive()
1477
- }).strict();
1478
-
1479
1278
  // ../tracking-core/src/events/semantics.ts
1480
1279
  var EVENT_SEMANTICS = {
1481
1280
  page_view: {
@@ -1549,82 +1348,6 @@ function getEventSemantics(eventName) {
1549
1348
  return eventName in EVENT_SEMANTICS ? EVENT_SEMANTICS[eventName] : null;
1550
1349
  }
1551
1350
 
1552
- // ../tracking-core/src/events/registry.ts
1553
- var EVENT_REGISTRY = {
1554
- // --- automatic triggers ---
1555
- page_view: {
1556
- kind: "automatic",
1557
- semantics: EVENT_SEMANTICS.page_view,
1558
- metadataSchema: pageViewMetadataSchema,
1559
- configSchema: pageViewConfigSchema
1560
- },
1561
- time_on_site: {
1562
- kind: "automatic",
1563
- semantics: EVENT_SEMANTICS.time_on_site,
1564
- metadataSchema: timeOnSiteMetadataSchema,
1565
- configSchema: timeOnSiteConfigSchema
1566
- },
1567
- specific_page_visit: {
1568
- kind: "automatic",
1569
- semantics: EVENT_SEMANTICS.specific_page_visit,
1570
- metadataSchema: specificPageVisitMetadataSchema,
1571
- configSchema: specificPageVisitConfigSchema
1572
- },
1573
- scroll_depth: {
1574
- kind: "automatic",
1575
- semantics: EVENT_SEMANTICS.scroll_depth,
1576
- metadataSchema: scrollDepthMetadataSchema,
1577
- configSchema: scrollDepthConfigSchema
1578
- },
1579
- multi_page_session: {
1580
- kind: "automatic",
1581
- semantics: EVENT_SEMANTICS.multi_page_session,
1582
- metadataSchema: multiPageSessionMetadataSchema,
1583
- configSchema: multiPageSessionConfigSchema
1584
- },
1585
- form_start: {
1586
- kind: "automatic",
1587
- semantics: EVENT_SEMANTICS.form_start,
1588
- metadataSchema: formStartMetadataSchema,
1589
- configSchema: formStartConfigSchema
1590
- },
1591
- // --- SDK-internal automatic (not consumer-configurable) ---
1592
- sdk_heartbeat: {
1593
- kind: "automatic",
1594
- semantics: EVENT_SEMANTICS.sdk_heartbeat,
1595
- metadataSchema: sdkHeartbeatMetadataSchema,
1596
- configSchema: sdkHeartbeatConfigSchema
1597
- },
1598
- page_exit: {
1599
- kind: "automatic",
1600
- semantics: EVENT_SEMANTICS.page_exit,
1601
- metadataSchema: pageExitMetadataSchema,
1602
- configSchema: pageExitConfigSchema
1603
- },
1604
- // --- manual triggers ---
1605
- form_submit: {
1606
- kind: "manual",
1607
- semantics: EVENT_SEMANTICS.form_submit,
1608
- metadataSchema: formSubmitMetadataSchema,
1609
- configSchema: formSubmitConfigSchema
1610
- },
1611
- phone_click: {
1612
- kind: "manual",
1613
- semantics: EVENT_SEMANTICS.phone_click,
1614
- metadataSchema: phoneClickMetadataSchema,
1615
- configSchema: phoneClickConfigSchema
1616
- },
1617
- cta_click: {
1618
- kind: "manual",
1619
- semantics: EVENT_SEMANTICS.cta_click,
1620
- metadataSchema: ctaClickMetadataSchema,
1621
- configSchema: ctaClickConfigSchema
1622
- }
1623
- };
1624
- var ALL_AUTOMATIC_EVENT_NAMES = Object.entries(EVENT_REGISTRY).filter(([, def]) => def.kind === "automatic").map(([name]) => name);
1625
- var ALL_MANUAL_EVENT_NAMES = Object.entries(EVENT_REGISTRY).filter(([, def]) => def.kind === "manual").map(([name]) => name);
1626
- var ALL_LEAD_EVENT_NAMES = Object.entries(EVENT_REGISTRY).filter(([, def]) => def.semantics.outcomeRole === "lead").map(([name]) => name);
1627
-
1628
1351
  // ../tracking-core/src/resources/http/errors.ts
1629
1352
  var AranovaApiError = class extends Error {
1630
1353
  constructor(message, options) {
@@ -1662,9 +1385,9 @@ async function apiRequest(config, method, path, body, extraHeaders) {
1662
1385
  try {
1663
1386
  const parsed = await response.json();
1664
1387
  if (parsed && typeof parsed === "object") {
1665
- const record = parsed;
1666
- if (typeof record.detail === "string") detail = record.detail;
1667
- if (typeof record.code === "string") code = record.code;
1388
+ const record3 = parsed;
1389
+ if (typeof record3.detail === "string") detail = record3.detail;
1390
+ if (typeof record3.code === "string") code = record3.code;
1668
1391
  }
1669
1392
  } catch {
1670
1393
  }
@@ -1713,7 +1436,7 @@ function fireRecordedConversions(firing, input, recorded, sale, currency) {
1713
1436
  }
1714
1437
  function createSalesClient(config) {
1715
1438
  if (config.firing) registerCapability("conversion_goals_manual");
1716
- async function record(input) {
1439
+ async function record3(input) {
1717
1440
  const currency = input.currency ?? config.defaultCurrency;
1718
1441
  if (!currency) {
1719
1442
  throw new Error(
@@ -1739,9 +1462,9 @@ function createSalesClient(config) {
1739
1462
  return sale;
1740
1463
  }
1741
1464
  return {
1742
- record,
1465
+ record: record3,
1743
1466
  // recordSale is the intent-revealing alias — same behavior, clearer call site.
1744
- recordSale: record,
1467
+ recordSale: record3,
1745
1468
  trackConversion(key, options) {
1746
1469
  if (config.firing && "fireConversion" in config.firing) {
1747
1470
  if (options?.userData && getConsentState() !== "denied") stashUserData(options.userData);
@@ -1860,115 +1583,264 @@ function createSalesClient(config) {
1860
1583
  }
1861
1584
 
1862
1585
  // ../tracking-core/src/resources/sales/schema.ts
1863
- import { z as z12 } from "zod";
1864
- var SUPPORTED_CURRENCIES = ["USD", "CAD"];
1865
- var TRACKING_ENVIRONMENTS = ["production", "development"];
1866
- var currencySchema = z12.enum(SUPPORTED_CURRENCIES);
1867
- var centsSchema = z12.number().int().nonnegative();
1868
- var quantitySchema = z12.string().regex(/^\d+(\.\d{1,3})?$/);
1869
- var metadataSchema = z12.record(z12.unknown());
1870
- var saleItemSchema = z12.object({
1871
- external_item_id: z12.string().nullable().optional(),
1872
- name: z12.string().nullable().optional(),
1873
- category: z12.string().nullable().optional(),
1874
- quantity: quantitySchema,
1875
- unit_price_cents: centsSchema,
1876
- // Non-negativity validated on the wire — same contract as the other cents
1877
- // fields — and backstopped by the DB CHECK.
1878
- unit_cost_cents: centsSchema.nullable().optional()
1879
- }).strict();
1880
- var saleServiceSchema = z12.object({
1881
- service: z12.string(),
1882
- amount_cents: centsSchema
1883
- }).strict();
1884
- var customerNameSchema = z12.string().max(200);
1885
- var customerPhoneSchema = z12.string().max(64);
1886
- var customerEmailSchema = z12.string().max(320).email();
1586
+ import * as z2 from "zod/mini";
1587
+
1588
+ // ../tracking-core/src/resources/sales/generated/zod.gen.ts
1589
+ import * as z from "zod/mini";
1590
+ var zErrorCode = z.enum([
1591
+ "missing_credentials",
1592
+ "invalid_api_key",
1593
+ "not_authenticated",
1594
+ "wrong_key_type",
1595
+ "origin_missing",
1596
+ "origin_not_allowed",
1597
+ "capability_denied",
1598
+ "session_required",
1599
+ "operator_only",
1600
+ "cross_tenant",
1601
+ "business_id_required",
1602
+ "bad_request",
1603
+ "not_found",
1604
+ "conflict",
1605
+ "incompatible_payload",
1606
+ "repeat_confirmation_required",
1607
+ "idempotency_conflict",
1608
+ "validation_error",
1609
+ "unknown_service",
1610
+ "invalid_sale_properties",
1611
+ "invalid_cursor",
1612
+ "rate_limited",
1613
+ "internal_error"
1614
+ ]);
1615
+ var zSaleItemEntitySchema = z.object({
1616
+ category: z.nullable(z.string()),
1617
+ external_item_id: z.nullable(z.string()),
1618
+ id: z.uuid(),
1619
+ name: z.nullable(z.string()),
1620
+ quantity: z.string().check(z.regex(/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/)),
1621
+ unit_cost_cents: z.nullable(z.int()),
1622
+ unit_price_cents: z.int()
1623
+ });
1624
+ var zSaleItemInputSchema = z.strictObject({
1625
+ category: z.nullish(z.string()),
1626
+ external_item_id: z.nullish(z.string()),
1627
+ name: z.nullish(z.string()),
1628
+ quantity: z.string().check(z.regex(/^\d+(\.\d{1,3})?$/)),
1629
+ unit_cost_cents: z.nullish(z.int().check(z.gte(0))),
1630
+ unit_price_cents: z.int().check(z.gte(0))
1631
+ });
1632
+ var zSaleServiceEntitySchema = z.object({
1633
+ amount_cents: z.int(),
1634
+ id: z.uuid(),
1635
+ mapped: z.nullable(z.boolean()),
1636
+ service_id: z.uuid(),
1637
+ service_key: z.string(),
1638
+ service_label: z.string()
1639
+ });
1640
+ var zSaleServiceInputSchema = z.strictObject({
1641
+ amount_cents: z.int().check(z.gte(0)),
1642
+ service: z.string()
1643
+ });
1644
+ var zSmsAutomationState = z.enum([
1645
+ "needs_check",
1646
+ "failed",
1647
+ "undelivered",
1648
+ "blocked_opted_out",
1649
+ "withheld",
1650
+ "queued",
1651
+ "sent",
1652
+ "delivered",
1653
+ "eligible",
1654
+ "not_applicable"
1655
+ ]);
1656
+ var zSmsWithheldReason = z.enum([
1657
+ "automation_disabled",
1658
+ "sms_disabled",
1659
+ "no_phone",
1660
+ "no_consent",
1661
+ "no_customer_identity",
1662
+ "missing_customer_name",
1663
+ "placeholder_customer_name",
1664
+ "opted_out",
1665
+ "already_messaged",
1666
+ "sender_not_ready",
1667
+ "missing_review_url",
1668
+ "no_handler",
1669
+ "dispatch_already_recorded"
1670
+ ]);
1671
+ var zSaleSmsStatusSchema = z.object({
1672
+ can_send_now: z._default(z.boolean(), false),
1673
+ last_message_at: z.nullable(z.iso.datetime({ offset: true })),
1674
+ reason_detail: z.nullable(z.string()),
1675
+ state: zSmsAutomationState,
1676
+ suppressed_by_other_sale: z._default(z.boolean(), false),
1677
+ withheld_reason: z.nullable(zSmsWithheldReason)
1678
+ });
1679
+ var zSupportedCurrency = z.enum(["USD", "CAD"]);
1680
+ var zTrackingEnvironment = z.enum(["production", "development"]);
1681
+ var zSaleCreateSchema = z.strictObject({
1682
+ amount_total_cents: z.nullish(z.int().check(z.gte(0))),
1683
+ currency: zSupportedCurrency,
1684
+ customer_email: z.nullish(z.email().check(z.maxLength(320))),
1685
+ customer_name: z.nullish(z.string().check(z.maxLength(200))),
1686
+ customer_phone: z.nullish(z.string().check(z.maxLength(64))),
1687
+ description: z.nullish(z.string()),
1688
+ environment: z._default(z.optional(zTrackingEnvironment), "production"),
1689
+ external_id: z.nullish(z.string()),
1690
+ items: z.optional(z.array(zSaleItemInputSchema)),
1691
+ metadata: z.nullish(z.record(z.string(), z.unknown())),
1692
+ occurred_at: z.iso.datetime({ offset: true }),
1693
+ service: z.nullish(z.string()),
1694
+ services: z.nullish(z.array(zSaleServiceInputSchema)),
1695
+ sms_consent: z.nullish(z.boolean())
1696
+ });
1697
+ var zValidationError = z.object({
1698
+ ctx: z.optional(z.record(z.string(), z.unknown())),
1699
+ input: z.optional(z.unknown()),
1700
+ loc: z.array(z.union([z.string(), z.int()])),
1701
+ msg: z.string(),
1702
+ type: z.string()
1703
+ });
1704
+ var zHttpValidationError = z.object({
1705
+ detail: z.optional(z.array(zValidationError))
1706
+ });
1707
+ var zValidationErrorItem = z.object({
1708
+ loc: z.array(z.union([z.string(), z.int()])),
1709
+ msg: z.string(),
1710
+ type: z.string()
1711
+ });
1712
+ var zApiErrorSchema = z.object({
1713
+ code: zErrorCode,
1714
+ context: z._default(z.nullish(z.record(z.string(), z.unknown())), null),
1715
+ detail: z.string(),
1716
+ errors: z._default(z.nullish(z.array(zValidationErrorItem)), null),
1717
+ request_id: z._default(z.nullish(z.string()), null)
1718
+ });
1719
+ var zWritebackEmailSource = z.enum(["NONE", "SALE", "CUSTOMER", "HARVESTED"]);
1720
+ var zWritebackEnrichmentStatus = z.enum(["NONE", "MATCHED", "AMBIGUOUS"]);
1721
+ var zWritebackSaleUploadCounts = z.object({
1722
+ failed: z._default(z.int(), 0),
1723
+ pending: z._default(z.int(), 0),
1724
+ skipped: z._default(z.int(), 0),
1725
+ submitted: z._default(z.int(), 0),
1726
+ total: z._default(z.int(), 0),
1727
+ uploaded: z._default(z.int(), 0)
1728
+ });
1729
+ var zSaleWritebackStatusSchema = z.object({
1730
+ blocked_reason: z.nullable(z.string()),
1731
+ can_dispatch: z._default(z.boolean(), false),
1732
+ email_source: z.nullable(zWritebackEmailSource),
1733
+ enrichment_status: z.nullable(zWritebackEnrichmentStatus),
1734
+ gclid_attached: z._default(z.boolean(), false),
1735
+ identifiers_sent: z.nullable(z.string()),
1736
+ mapped_service_ids: z.array(z.uuid()),
1737
+ matched_submit_count: z.nullable(z.int()),
1738
+ needs_force: z._default(z.boolean(), false),
1739
+ rollup: z.enum([
1740
+ "failed",
1741
+ "skipped",
1742
+ "pending",
1743
+ "submitted",
1744
+ "uploaded",
1745
+ "not_uploaded",
1746
+ "out_of_window",
1747
+ "blocked"
1748
+ ]),
1749
+ stale: z._default(z.boolean(), false),
1750
+ uncovered_service_ids: z.array(z.uuid()),
1751
+ uploads: zWritebackSaleUploadCounts
1752
+ });
1753
+ var zSaleEntitySchema = z.object({
1754
+ amount_total_cents: z.int(),
1755
+ business_id: z.uuid(),
1756
+ business_name: z.nullable(z.string()),
1757
+ created_at: z.iso.datetime({ offset: true }),
1758
+ currency: z.string(),
1759
+ customer_email: z.nullable(z.string()),
1760
+ customer_name: z.nullable(z.string()),
1761
+ customer_name_placeholder_confirmed: z._default(z.boolean(), false),
1762
+ customer_name_placeholder_confirmed_at: z.nullable(z.iso.datetime({ offset: true })),
1763
+ customer_phone: z.nullable(z.string()),
1764
+ description: z.nullable(z.string()),
1765
+ environment: zTrackingEnvironment,
1766
+ external_id: z.nullable(z.string()),
1767
+ id: z.uuid(),
1768
+ items: z.array(zSaleItemEntitySchema),
1769
+ metadata: z.nullable(z.record(z.string(), z.unknown())),
1770
+ occurred_at: z.iso.datetime({ offset: true }),
1771
+ service_id: z.nullable(z.uuid()),
1772
+ service_key: z.nullable(z.string()),
1773
+ service_label: z.nullable(z.string()),
1774
+ services: z.array(zSaleServiceEntitySchema),
1775
+ sms_automation: z.nullable(zSaleSmsStatusSchema),
1776
+ sms_consent: z._default(z.boolean(), false),
1777
+ sms_consent_granted_at: z.nullable(z.iso.datetime({ offset: true })),
1778
+ updated_at: z.iso.datetime({ offset: true }),
1779
+ writeback: z.nullable(zSaleWritebackStatusSchema)
1780
+ });
1781
+
1782
+ // ../tracking-core/src/resources/sales/schema.ts
1783
+ var saleItemSchema = zSaleItemInputSchema;
1784
+ var saleServiceSchema = zSaleServiceInputSchema;
1785
+ var currencySchema = zSupportedCurrency;
1786
+ var SUPPORTED_CURRENCIES = currencySchema.options;
1787
+ var centsSchema = z2.int().check(z2.gte(0));
1788
+ var metadataSchema = z2.record(z2.string(), z2.unknown());
1789
+ var customerNameSchema = z2.string().check(z2.maxLength(200));
1790
+ var customerPhoneSchema = z2.string().check(z2.maxLength(64));
1791
+ var customerEmailSchema = z2.email().check(z2.maxLength(320));
1792
+ function addIssue(ctx, path, message) {
1793
+ ctx.issues.push({ code: "custom", input: ctx.value, path, message });
1794
+ }
1887
1795
  function refineServiceXor(val, ctx, { requireAmount }) {
1888
1796
  if (val.services != null) {
1889
1797
  if (val.service != null) {
1890
- ctx.addIssue({
1891
- code: z12.ZodIssueCode.custom,
1892
- message: "pass either `service` or `services`, not both",
1893
- path: ["services"]
1894
- });
1798
+ addIssue(ctx, ["services"], "pass either `service` or `services`, not both");
1895
1799
  }
1896
1800
  if (val.services.length === 0) {
1897
- ctx.addIssue({
1898
- code: z12.ZodIssueCode.custom,
1899
- message: "`services` must not be empty",
1900
- path: ["services"]
1901
- });
1801
+ addIssue(ctx, ["services"], "`services` must not be empty");
1902
1802
  }
1903
1803
  const keys = val.services.map((s) => s.service);
1904
1804
  if (new Set(keys).size !== keys.length) {
1905
- ctx.addIssue({
1906
- code: z12.ZodIssueCode.custom,
1907
- message: "`services` must not list the same service more than once",
1908
- path: ["services"]
1909
- });
1805
+ addIssue(ctx, ["services"], "`services` must not list the same service more than once");
1910
1806
  }
1911
1807
  if (val.amount_total_cents != null) {
1912
1808
  const sum = val.services.reduce((acc, s) => acc + s.amount_cents, 0);
1913
1809
  if (val.amount_total_cents !== sum) {
1914
- ctx.addIssue({
1915
- code: z12.ZodIssueCode.custom,
1916
- message: "amount_total_cents must equal the sum of the services amounts (omit it to derive it automatically)",
1917
- path: ["amount_total_cents"]
1918
- });
1810
+ addIssue(
1811
+ ctx,
1812
+ ["amount_total_cents"],
1813
+ "amount_total_cents must equal the sum of the services amounts (omit it to derive it automatically)"
1814
+ );
1919
1815
  }
1920
1816
  }
1921
1817
  } else if (requireAmount && val.amount_total_cents == null) {
1922
- ctx.addIssue({
1923
- code: z12.ZodIssueCode.custom,
1924
- message: "amount_total_cents is required unless `services` is provided",
1925
- path: ["amount_total_cents"]
1926
- });
1818
+ addIssue(
1819
+ ctx,
1820
+ ["amount_total_cents"],
1821
+ "amount_total_cents is required unless `services` is provided"
1822
+ );
1927
1823
  }
1928
1824
  }
1929
- var saleCreateSchema = z12.object({
1930
- external_id: z12.string().nullable().optional(),
1931
- description: z12.string().nullable().optional(),
1932
- service: z12.string().nullable().optional(),
1933
- services: z12.array(saleServiceSchema).nullable().optional(),
1934
- currency: currencySchema,
1935
- // Optional only because the plural `services` form derives it from the sum
1936
- // (see refineServiceXor); the singular/serviceless path still requires it.
1937
- amount_total_cents: centsSchema.nullable().optional(),
1938
- occurred_at: z12.string().datetime(),
1939
- environment: z12.enum(TRACKING_ENVIRONMENTS).default("production"),
1940
- items: z12.array(saleItemSchema).default([]),
1941
- metadata: metadataSchema.nullable().optional(),
1942
- customer_name: customerNameSchema.nullable().optional(),
1943
- customer_phone: customerPhoneSchema.nullable().optional(),
1944
- customer_email: customerEmailSchema.nullable().optional(),
1945
- // CASL consent attestation: the customer agreed to receive SMS. Recorded
1946
- // with a timestamp server-side; every SMS send path gates on it.
1947
- //
1948
- // Tri-state: omit it (or send null) to let the server apply the business's
1949
- // configured default-opt-in policy, honouring a returning customer's
1950
- // remembered preference. Send an explicit boolean to assert consent state
1951
- // yourself — `false` records a deliberate opt-out.
1952
- sms_consent: z12.boolean().nullable().optional()
1953
- }).strict().superRefine((val, ctx) => refineServiceXor(val, ctx, { requireAmount: true }));
1954
- var saleUpdateSchema = z12.object({
1955
- description: z12.string().nullable().optional(),
1956
- service: z12.string().nullable().optional(),
1957
- services: z12.array(saleServiceSchema).nullable().optional(),
1958
- currency: currencySchema.optional(),
1959
- amount_total_cents: centsSchema.optional(),
1960
- occurred_at: z12.string().datetime().optional(),
1961
- items: z12.array(saleItemSchema).optional(),
1962
- metadata: metadataSchema.nullable().optional(),
1963
- customer_name: customerNameSchema.nullable().optional(),
1825
+ var saleCreateSchema = z2.extend(zSaleCreateSchema, { items: z2._default(z2.array(saleItemSchema), []) }).check((ctx) => refineServiceXor(ctx.value, ctx, { requireAmount: true }));
1826
+ var saleUpdateSchema = z2.strictObject({
1827
+ description: z2.nullish(z2.string()),
1828
+ service: z2.nullish(z2.string()),
1829
+ services: z2.nullish(z2.array(saleServiceSchema)),
1830
+ currency: z2.optional(currencySchema),
1831
+ amount_total_cents: z2.optional(centsSchema),
1832
+ occurred_at: z2.optional(z2.iso.datetime()),
1833
+ items: z2.optional(z2.array(saleItemSchema)),
1834
+ metadata: z2.nullish(metadataSchema),
1835
+ customer_name: z2.nullish(customerNameSchema),
1964
1836
  // Re-attest when changing a filler-looking name; the server clears the
1965
1837
  // prior attestation whenever `customer_name` changes.
1966
- customer_name_placeholder_confirmed: z12.boolean().optional(),
1967
- customer_phone: customerPhoneSchema.nullable().optional(),
1968
- customer_email: customerEmailSchema.nullable().optional(),
1838
+ customer_name_placeholder_confirmed: z2.optional(z2.boolean()),
1839
+ customer_phone: z2.nullish(customerPhoneSchema),
1840
+ customer_email: z2.nullish(customerEmailSchema),
1969
1841
  // NOT NULL server-side: omit to leave unchanged (explicit null is rejected).
1970
- sms_consent: z12.boolean().optional()
1971
- }).strict().superRefine((val, ctx) => refineServiceXor(val, ctx, { requireAmount: false }));
1842
+ sms_consent: z2.optional(z2.boolean())
1843
+ }).check((ctx) => refineServiceXor(ctx.value, ctx, { requireAmount: false }));
1972
1844
  var TRACKING_RANGES = ["24h", "7d", "30d"];
1973
1845
  var NAMED_RANGES = [
1974
1846
  "today",
@@ -2020,6 +1892,7 @@ export {
2020
1892
  createTrackingClientContext,
2021
1893
  createTrackingEventCreatePayload,
2022
1894
  createTrackingSessionUpsertPayload,
1895
+ currencySchema,
2023
1896
  fetchServices,
2024
1897
  formatDateInTz,
2025
1898
  formatMoney,