@aranova/tracking-next 0.7.2 → 0.9.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/dist/index.d.ts CHANGED
@@ -1232,6 +1232,353 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
1232
1232
  getVisitorId(): string;
1233
1233
  }
1234
1234
 
1235
+ /**
1236
+ * Sales / Conversions wire schemas — the client-side source of truth.
1237
+ *
1238
+ * `saleCreateSchema` is mirrored by `SaleCreateSchema` in
1239
+ * `apps/api/src/schemas/tracking_sales.py` and enforced by the backend drift
1240
+ * test (the `resources` section of `events.schema.json`). Keep them in lockstep.
1241
+ *
1242
+ * Money is **integer minor units (cents)**; `quantity` is a decimal string;
1243
+ * `currency` is the required `SupportedCurrency` enum.
1244
+ */
1245
+ declare const SUPPORTED_CURRENCIES: readonly ["USD", "CAD"];
1246
+ type SupportedCurrency = (typeof SUPPORTED_CURRENCIES)[number];
1247
+ declare const TRACKING_ENVIRONMENTS: readonly ["production", "development"];
1248
+ declare const saleItemSchema: z.ZodObject<{
1249
+ external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1250
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1251
+ category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1252
+ quantity: z.ZodString;
1253
+ unit_price_cents: z.ZodNumber;
1254
+ unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
1255
+ }, "strict", z.ZodTypeAny, {
1256
+ quantity: string;
1257
+ unit_price_cents: number;
1258
+ name?: string | null | undefined;
1259
+ external_item_id?: string | null | undefined;
1260
+ category?: string | null | undefined;
1261
+ unit_cost_cents?: number | null | undefined;
1262
+ }, {
1263
+ quantity: string;
1264
+ unit_price_cents: number;
1265
+ name?: string | null | undefined;
1266
+ external_item_id?: string | null | undefined;
1267
+ category?: string | null | undefined;
1268
+ unit_cost_cents?: number | null | undefined;
1269
+ }>;
1270
+ declare const saleCreateSchema: z.ZodObject<{
1271
+ external_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1272
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1273
+ service: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1274
+ currency: z.ZodEnum<["USD", "CAD"]>;
1275
+ amount_total_cents: z.ZodNumber;
1276
+ occurred_at: z.ZodString;
1277
+ environment: z.ZodDefault<z.ZodEnum<["production", "development"]>>;
1278
+ items: z.ZodDefault<z.ZodArray<z.ZodObject<{
1279
+ external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1280
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1281
+ category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1282
+ quantity: z.ZodString;
1283
+ unit_price_cents: z.ZodNumber;
1284
+ unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
1285
+ }, "strict", z.ZodTypeAny, {
1286
+ quantity: string;
1287
+ unit_price_cents: number;
1288
+ name?: string | null | undefined;
1289
+ external_item_id?: string | null | undefined;
1290
+ category?: string | null | undefined;
1291
+ unit_cost_cents?: number | null | undefined;
1292
+ }, {
1293
+ quantity: string;
1294
+ unit_price_cents: number;
1295
+ name?: string | null | undefined;
1296
+ external_item_id?: string | null | undefined;
1297
+ category?: string | null | undefined;
1298
+ unit_cost_cents?: number | null | undefined;
1299
+ }>, "many">>;
1300
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1301
+ customer_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1302
+ customer_phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1303
+ customer_email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1304
+ }, "strict", z.ZodTypeAny, {
1305
+ currency: "USD" | "CAD";
1306
+ amount_total_cents: number;
1307
+ occurred_at: string;
1308
+ environment: "production" | "development";
1309
+ items: {
1310
+ quantity: string;
1311
+ unit_price_cents: number;
1312
+ name?: string | null | undefined;
1313
+ external_item_id?: string | null | undefined;
1314
+ category?: string | null | undefined;
1315
+ unit_cost_cents?: number | null | undefined;
1316
+ }[];
1317
+ metadata?: Record<string, unknown> | null | undefined;
1318
+ external_id?: string | null | undefined;
1319
+ description?: string | null | undefined;
1320
+ service?: string | null | undefined;
1321
+ customer_name?: string | null | undefined;
1322
+ customer_phone?: string | null | undefined;
1323
+ customer_email?: string | null | undefined;
1324
+ }, {
1325
+ currency: "USD" | "CAD";
1326
+ amount_total_cents: number;
1327
+ occurred_at: string;
1328
+ metadata?: Record<string, unknown> | null | undefined;
1329
+ external_id?: string | null | undefined;
1330
+ description?: string | null | undefined;
1331
+ service?: string | null | undefined;
1332
+ environment?: "production" | "development" | undefined;
1333
+ items?: {
1334
+ quantity: string;
1335
+ unit_price_cents: number;
1336
+ name?: string | null | undefined;
1337
+ external_item_id?: string | null | undefined;
1338
+ category?: string | null | undefined;
1339
+ unit_cost_cents?: number | null | undefined;
1340
+ }[] | undefined;
1341
+ customer_name?: string | null | undefined;
1342
+ customer_phone?: string | null | undefined;
1343
+ customer_email?: string | null | undefined;
1344
+ }>;
1345
+ declare const saleUpdateSchema: z.ZodObject<{
1346
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1347
+ service: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1348
+ currency: z.ZodOptional<z.ZodEnum<["USD", "CAD"]>>;
1349
+ amount_total_cents: z.ZodOptional<z.ZodNumber>;
1350
+ occurred_at: z.ZodOptional<z.ZodString>;
1351
+ items: z.ZodOptional<z.ZodArray<z.ZodObject<{
1352
+ external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1353
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1354
+ category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1355
+ quantity: z.ZodString;
1356
+ unit_price_cents: z.ZodNumber;
1357
+ unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
1358
+ }, "strict", z.ZodTypeAny, {
1359
+ quantity: string;
1360
+ unit_price_cents: number;
1361
+ name?: string | null | undefined;
1362
+ external_item_id?: string | null | undefined;
1363
+ category?: string | null | undefined;
1364
+ unit_cost_cents?: number | null | undefined;
1365
+ }, {
1366
+ quantity: string;
1367
+ unit_price_cents: number;
1368
+ name?: string | null | undefined;
1369
+ external_item_id?: string | null | undefined;
1370
+ category?: string | null | undefined;
1371
+ unit_cost_cents?: number | null | undefined;
1372
+ }>, "many">>;
1373
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1374
+ customer_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1375
+ customer_phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1376
+ customer_email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1377
+ }, "strict", z.ZodTypeAny, {
1378
+ metadata?: Record<string, unknown> | null | undefined;
1379
+ description?: string | null | undefined;
1380
+ service?: string | null | undefined;
1381
+ currency?: "USD" | "CAD" | undefined;
1382
+ amount_total_cents?: number | undefined;
1383
+ occurred_at?: string | undefined;
1384
+ items?: {
1385
+ quantity: string;
1386
+ unit_price_cents: number;
1387
+ name?: string | null | undefined;
1388
+ external_item_id?: string | null | undefined;
1389
+ category?: string | null | undefined;
1390
+ unit_cost_cents?: number | null | undefined;
1391
+ }[] | undefined;
1392
+ customer_name?: string | null | undefined;
1393
+ customer_phone?: string | null | undefined;
1394
+ customer_email?: string | null | undefined;
1395
+ }, {
1396
+ metadata?: Record<string, unknown> | null | undefined;
1397
+ description?: string | null | undefined;
1398
+ service?: string | null | undefined;
1399
+ currency?: "USD" | "CAD" | undefined;
1400
+ amount_total_cents?: number | undefined;
1401
+ occurred_at?: string | undefined;
1402
+ items?: {
1403
+ quantity: string;
1404
+ unit_price_cents: number;
1405
+ name?: string | null | undefined;
1406
+ external_item_id?: string | null | undefined;
1407
+ category?: string | null | undefined;
1408
+ unit_cost_cents?: number | null | undefined;
1409
+ }[] | undefined;
1410
+ customer_name?: string | null | undefined;
1411
+ customer_phone?: string | null | undefined;
1412
+ customer_email?: string | null | undefined;
1413
+ }>;
1414
+ type SaleItemInput = z.input<typeof saleItemSchema>;
1415
+ type SaleInput = z.input<typeof saleCreateSchema>;
1416
+ type SaleUpdateInput = z.input<typeof saleUpdateSchema>;
1417
+ interface SaleItem {
1418
+ id: string;
1419
+ external_item_id: string | null;
1420
+ name: string | null;
1421
+ category: string | null;
1422
+ quantity: string;
1423
+ unit_price_cents: number;
1424
+ unit_cost_cents: number | null;
1425
+ }
1426
+ interface Sale {
1427
+ id: string;
1428
+ business_id: string;
1429
+ business_name?: string | null;
1430
+ external_id: string | null;
1431
+ currency: SupportedCurrency;
1432
+ amount_total_cents: number;
1433
+ description: string | null;
1434
+ service_id: string | null;
1435
+ service_key?: string | null;
1436
+ service_label?: string | null;
1437
+ occurred_at: string;
1438
+ environment: (typeof TRACKING_ENVIRONMENTS)[number];
1439
+ metadata: Record<string, unknown> | null;
1440
+ customer_name: string | null;
1441
+ customer_phone: string | null;
1442
+ customer_email: string | null;
1443
+ created_at: string;
1444
+ updated_at: string;
1445
+ items: SaleItem[];
1446
+ }
1447
+ interface SaleListPage {
1448
+ items: Sale[];
1449
+ total: number;
1450
+ }
1451
+ interface SaleCursorPage {
1452
+ items: Sale[];
1453
+ next_cursor: string | null;
1454
+ }
1455
+ /**
1456
+ * Comprehensive filter shape mirrored from the backend's `SaleQueryFilters`.
1457
+ *
1458
+ * `search` runs case-insensitively across `customer_name`, `customer_phone`,
1459
+ * `customer_email`, `description`, and `external_id` — the human-facing
1460
+ * columns. `service_id` is the resolved per-business service UUID (different
1461
+ * from the create-time `service` *key*).
1462
+ */
1463
+ interface SaleFilters {
1464
+ business_id?: string;
1465
+ external_id?: string;
1466
+ service_id?: string;
1467
+ currency?: SupportedCurrency;
1468
+ environment?: (typeof TRACKING_ENVIRONMENTS)[number];
1469
+ since?: string;
1470
+ until?: string;
1471
+ min_amount_cents?: number;
1472
+ max_amount_cents?: number;
1473
+ search?: string;
1474
+ }
1475
+ /**
1476
+ * Full query input for `SalesClient.list()` — filters + pagination.
1477
+ *
1478
+ * Pagination is **keyset (cursor)**: `next_cursor` returned by one page is
1479
+ * passed back as `cursor` on the next. `null` / undefined cursor = first page.
1480
+ *
1481
+ * Ordering on this endpoint is fixed at **`occurred_at DESC, id DESC`** — the
1482
+ * cursor encodes a position in that index, so a different sort would
1483
+ * invalidate cursors mid-pagination. For ad-hoc sorted reads use the
1484
+ * dashboard admin endpoint, which is offset-paginated.
1485
+ */
1486
+ interface SaleListQuery extends SaleFilters {
1487
+ limit?: number;
1488
+ cursor?: string | null;
1489
+ }
1490
+
1491
+ /** Shared config for every sales HTTP helper. */
1492
+ interface SalesTransportConfig {
1493
+ /** Public (`aranv_pk_…`) or secret (`aranv_sk_…`) API key. */
1494
+ apiKey: string;
1495
+ /**
1496
+ * Base tracking endpoint, e.g. `https://aranovainternal-production.up.railway.app/tracking`.
1497
+ * The `/sales` path is appended by the helpers.
1498
+ */
1499
+ endpoint: string;
1500
+ /** Optional SDK identity headers (mirrors the event ingest client). */
1501
+ sdkVersion?: string;
1502
+ packageName?: string;
1503
+ surface?: string;
1504
+ environment?: string;
1505
+ }
1506
+
1507
+ /** Config for {@link createSalesClient}. */
1508
+ interface SalesClientConfig extends SalesTransportConfig {
1509
+ /** Applied when an individual `record()` call omits `currency`. */
1510
+ defaultCurrency?: SupportedCurrency;
1511
+ }
1512
+ /**
1513
+ * One isomorphic sales client — what a key may *do* is enforced by the backend,
1514
+ * not by hiding methods. A **public** key (`aranv_pk_…`) may `record` (the
1515
+ * backend rejects reads/CRUD from it with a `403`); a **secret** key
1516
+ * (`aranv_sk_…`), used **server-side only**, gets full read/list/update/delete.
1517
+ * Never ship a secret key in a browser bundle.
1518
+ *
1519
+ * Generic over the service-key union `TService`: bind the type emitted by
1520
+ * `@aranova/tracking-cli gen` for compile-time-checked `service` values.
1521
+ */
1522
+ interface SalesClient<TService extends string = string> {
1523
+ record(input: Omit<SaleInput, 'currency' | 'occurred_at' | 'service'> & {
1524
+ service?: TService | null;
1525
+ currency?: SupportedCurrency;
1526
+ occurred_at?: string;
1527
+ }): Promise<Sale>;
1528
+ list(query?: SaleListQuery): Promise<SaleCursorPage>;
1529
+ get(id: string): Promise<Sale>;
1530
+ update(id: string, patch: Omit<SaleUpdateInput, 'service'> & {
1531
+ service?: TService | null;
1532
+ }): Promise<Sale>;
1533
+ delete(id: string): Promise<void>;
1534
+ }
1535
+ declare function createSalesClient<TService extends string = string>(config: SalesClientConfig): SalesClient<TService>;
1536
+
1537
+ /** A business's active service, as returned by `GET /tracking/services`. */
1538
+ interface PublicServiceItem {
1539
+ key: string;
1540
+ label: string;
1541
+ }
1542
+ /**
1543
+ * Fetch the caller's business's active service taxonomy. Accepts a public or
1544
+ * secret key (the taxonomy is low-sensitivity category names). Powers the
1545
+ * `@aranova/tracking-cli gen` codegen.
1546
+ */
1547
+ declare function fetchServices(config: SalesTransportConfig): Promise<PublicServiceItem[]>;
1548
+
1549
+ /**
1550
+ * Convert a major amount (dollars `250.5`) to integer minor units (`25050`).
1551
+ *
1552
+ * Convenience only — the wire is always integer cents. Uses float multiply +
1553
+ * `Math.round`, so values that aren't exactly representable in binary float
1554
+ * (e.g. `1.005`) can round to the neighbouring cent. If you already hold an
1555
+ * exact cents integer, pass it straight through and skip this helper.
1556
+ */
1557
+ declare function toMinor(amount: number, currency: SupportedCurrency): number;
1558
+ /** Convert integer minor units (`25050`) to a major amount (`250.5`). */
1559
+ declare function fromMinor(cents: number, currency: SupportedCurrency): number;
1560
+ /**
1561
+ * Format integer minor units as a localized currency string (e.g. `"$250.50"`).
1562
+ * Uses the built-in `Intl.NumberFormat` — no extra dependency.
1563
+ */
1564
+ declare function formatMoney(cents: number, currency: SupportedCurrency, locale?: string): string;
1565
+
1566
+ /**
1567
+ * Error thrown by the sales client (`createSalesClient`) on a
1568
+ * non-2xx response. Unlike the fire-and-forget event queue (which swallows
1569
+ * failures), a sale is a transaction the caller must be able to react to.
1570
+ */
1571
+ declare class AranovaApiError extends Error {
1572
+ readonly status: number;
1573
+ readonly code: string | undefined;
1574
+ readonly requestId: string | undefined;
1575
+ constructor(message: string, options: {
1576
+ status: number;
1577
+ code?: string;
1578
+ requestId?: string;
1579
+ });
1580
+ }
1581
+
1235
1582
  /**
1236
1583
  * Default non-blocking consent banner for Next.js installs.
1237
1584
  *
@@ -1345,4 +1692,4 @@ interface CreateTrackingResult<TRegistry extends TriggerRegistryConfig> {
1345
1692
  */
1346
1693
  declare function createTracking<TRegistry extends TriggerRegistryConfig>(options: CreateTrackingOptions<TRegistry>): CreateTrackingResult<TRegistry>;
1347
1694
 
1348
- export { type AutomaticEventName, ConsentBanner, ConsentState, type CreateTrackingOptions, type CreateTrackingResult, type CtaClickConfig, type CtaClickMetadata, type EventConfig, type EventMetadata, type EventName, type FormStartConfig, type FormStartMetadata, type FormSubmitConfig, type FormSubmitMetadata, GoogleAdsTracking, type GoogleAdsTrackingProps, type JsonValue, type ManualEventName, type MultiPageSessionConfig, type MultiPageSessionMetadata, type PageViewConfig, type PageViewMetadata, type PhoneClickConfig, type PhoneClickMetadata, type RegisteredAutomaticEvents, type RegisteredManualEvents, type ScrollDepthConfig, type ScrollDepthMetadata, type SpecificPageName, type SpecificPageVisitConfig, type SpecificPageVisitMetadata, TRACKING_PARAM_KEYS, type TimeOnSiteConfig, type TimeOnSiteMetadata, type TrackingClient, TrackingClientContext, TrackingEventCreatePayload, TrackingInstallSurface, TrackingParams, type TrackingProviderProps, TrackingSessionUpsertPayload, type TriggerRegistryConfig, type TypedTrackEventOptions, type TypedTrackingClient, captureTrackingParamsFromLocation, createTracking, createTrackingClientContext, createTrackingEventCreatePayload, createTrackingSessionUpsertPayload, getConsentState, setConsentState, useConsentState, useGclid, useTrackingParams };
1695
+ export { AranovaApiError, type AutomaticEventName, ConsentBanner, ConsentState, type CreateTrackingOptions, type CreateTrackingResult, type CtaClickConfig, type CtaClickMetadata, type EventConfig, type EventMetadata, type EventName, type FormStartConfig, type FormStartMetadata, type FormSubmitConfig, type FormSubmitMetadata, GoogleAdsTracking, type GoogleAdsTrackingProps, type JsonValue, type ManualEventName, type MultiPageSessionConfig, type MultiPageSessionMetadata, type PageViewConfig, type PageViewMetadata, type PhoneClickConfig, type PhoneClickMetadata, type PublicServiceItem, type RegisteredAutomaticEvents, type RegisteredManualEvents, type Sale, type SaleCursorPage, type SaleInput, type SaleItem, type SaleItemInput, type SaleListPage, type SaleListQuery, type SaleUpdateInput, type SalesClient, type SalesClientConfig, type SalesTransportConfig, type ScrollDepthConfig, type ScrollDepthMetadata, type SpecificPageName, type SpecificPageVisitConfig, type SpecificPageVisitMetadata, type SupportedCurrency, TRACKING_PARAM_KEYS, type TimeOnSiteConfig, type TimeOnSiteMetadata, type TrackingClient, TrackingClientContext, TrackingEventCreatePayload, TrackingInstallSurface, TrackingParams, type TrackingProviderProps, TrackingSessionUpsertPayload, type TriggerRegistryConfig, type TypedTrackEventOptions, type TypedTrackingClient, captureTrackingParamsFromLocation, createSalesClient, createTracking, createTrackingClientContext, createTrackingEventCreatePayload, createTrackingSessionUpsertPayload, fetchServices, formatMoney, fromMinor, getConsentState, setConsentState, toMinor, useConsentState, useGclid, useTrackingParams };
package/dist/index.js CHANGED
@@ -30,16 +30,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ AranovaApiError: () => AranovaApiError,
33
34
  ConsentBanner: () => ConsentBanner,
34
35
  GoogleAdsTracking: () => GoogleAdsTracking,
35
36
  TRACKING_PARAM_KEYS: () => TRACKING_PARAM_KEYS,
36
37
  captureTrackingParamsFromLocation: () => captureTrackingParamsFromLocation,
38
+ createSalesClient: () => createSalesClient,
37
39
  createTracking: () => createTracking,
38
40
  createTrackingClientContext: () => createTrackingClientContext,
39
41
  createTrackingEventCreatePayload: () => createTrackingEventCreatePayload,
40
42
  createTrackingSessionUpsertPayload: () => createTrackingSessionUpsertPayload,
43
+ fetchServices: () => fetchServices,
44
+ formatMoney: () => formatMoney,
45
+ fromMinor: () => fromMinor,
41
46
  getConsentState: () => getConsentState,
42
47
  setConsentState: () => setConsentState,
48
+ toMinor: () => toMinor,
43
49
  useConsentState: () => useConsentState,
44
50
  useGclid: () => useGclid,
45
51
  useTrackingParams: () => useTrackingParams
@@ -526,7 +532,7 @@ function createTrackingClient(config) {
526
532
  const activeGtagIds = config.activeGtagIds ?? null;
527
533
  const endpointBase = config.endpoint.replace(/\/$/, "");
528
534
  const eventsUrl = `${endpointBase}/events`;
529
- const identityHeaders = {
535
+ const identityHeaders2 = {
530
536
  sdkVersion: sdkVersion ?? "",
531
537
  packageName: packageName ?? "",
532
538
  surface: config.surface,
@@ -607,7 +613,7 @@ function createTrackingClient(config) {
607
613
  events
608
614
  };
609
615
  const serialized = JSON.stringify(body);
610
- await postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders, false);
616
+ await postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders2, false);
611
617
  }
612
618
  function trackEvent(input) {
613
619
  if (destroyed)
@@ -638,7 +644,7 @@ function createTrackingClient(config) {
638
644
  events
639
645
  };
640
646
  const serialized = JSON.stringify(body);
641
- void postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders, true);
647
+ void postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders2, true);
642
648
  }
643
649
  if (typeof window !== "undefined") {
644
650
  window.addEventListener("pagehide", flushOnUnload);
@@ -1098,6 +1104,121 @@ function attachFormStart(client, config) {
1098
1104
  };
1099
1105
  }
1100
1106
 
1107
+ // ../tracking-core/src/resources/sales/errors.ts
1108
+ var AranovaApiError = class extends Error {
1109
+ constructor(message, options) {
1110
+ super(message);
1111
+ this.name = "AranovaApiError";
1112
+ this.status = options.status;
1113
+ this.code = options.code;
1114
+ this.requestId = options.requestId;
1115
+ }
1116
+ };
1117
+
1118
+ // ../tracking-core/src/resources/sales/transport.ts
1119
+ function identityHeaders(config) {
1120
+ const headers = { [API_KEY_HEADER]: config.apiKey };
1121
+ if (config.sdkVersion) headers[SDK_VERSION_HEADER] = config.sdkVersion;
1122
+ if (config.packageName) headers[SDK_PACKAGE_HEADER] = config.packageName;
1123
+ if (config.surface) headers[SDK_SURFACE_HEADER] = config.surface;
1124
+ if (config.environment) headers[SDK_ENVIRONMENT_HEADER] = config.environment;
1125
+ return headers;
1126
+ }
1127
+ function joinUrl(endpoint, path) {
1128
+ return `${endpoint.replace(/\/$/, "")}${path}`;
1129
+ }
1130
+ async function salesRequest(config, method, path, body) {
1131
+ const headers = identityHeaders(config);
1132
+ if (body !== void 0) headers["Content-Type"] = "application/json";
1133
+ const response = await fetch(joinUrl(config.endpoint, path), {
1134
+ method,
1135
+ headers,
1136
+ body: body === void 0 ? void 0 : JSON.stringify(body)
1137
+ });
1138
+ if (!response.ok) {
1139
+ let detail;
1140
+ let code;
1141
+ try {
1142
+ const parsed = await response.json();
1143
+ if (parsed && typeof parsed === "object") {
1144
+ const record = parsed;
1145
+ if (typeof record.detail === "string") detail = record.detail;
1146
+ if (typeof record.code === "string") code = record.code;
1147
+ }
1148
+ } catch {
1149
+ }
1150
+ throw new AranovaApiError(detail ?? response.statusText ?? "Request failed", {
1151
+ status: response.status,
1152
+ code,
1153
+ requestId: response.headers.get("x-request-id") ?? void 0
1154
+ });
1155
+ }
1156
+ if (response.status === 204) return void 0;
1157
+ return await response.json();
1158
+ }
1159
+
1160
+ // ../tracking-core/src/resources/sales/client.ts
1161
+ function createSalesClient(config) {
1162
+ return {
1163
+ async record(input) {
1164
+ const currency = input.currency ?? config.defaultCurrency;
1165
+ if (!currency) {
1166
+ throw new Error(
1167
+ "record: `currency` is required (pass it on the sale or set config.defaultCurrency)"
1168
+ );
1169
+ }
1170
+ const body = {
1171
+ ...input,
1172
+ currency,
1173
+ occurred_at: input.occurred_at ?? (/* @__PURE__ */ new Date()).toISOString()
1174
+ };
1175
+ return salesRequest(config, "POST", "/sales", body);
1176
+ },
1177
+ async list(query) {
1178
+ const { cursor, limit, ...filters } = query ?? {};
1179
+ return salesRequest(config, "POST", "/sales/query", {
1180
+ filters,
1181
+ ...limit !== void 0 ? { limit } : {},
1182
+ ...cursor !== void 0 ? { cursor } : {}
1183
+ });
1184
+ },
1185
+ async get(id) {
1186
+ return salesRequest(config, "GET", `/sales/${id}`);
1187
+ },
1188
+ async update(id, patch) {
1189
+ return salesRequest(config, "PATCH", `/sales/${id}`, patch);
1190
+ },
1191
+ async delete(id) {
1192
+ await salesRequest(config, "DELETE", `/sales/${id}`);
1193
+ }
1194
+ };
1195
+ }
1196
+
1197
+ // ../tracking-core/src/resources/services.ts
1198
+ async function fetchServices(config) {
1199
+ return salesRequest(config, "GET", "/services");
1200
+ }
1201
+
1202
+ // ../tracking-core/src/resources/sales/money.ts
1203
+ var MINOR_UNIT_EXPONENT = {
1204
+ USD: 2,
1205
+ CAD: 2
1206
+ };
1207
+ function exponentFor(currency) {
1208
+ return MINOR_UNIT_EXPONENT[currency] ?? 2;
1209
+ }
1210
+ function toMinor(amount, currency) {
1211
+ return Math.round(amount * 10 ** exponentFor(currency));
1212
+ }
1213
+ function fromMinor(cents, currency) {
1214
+ return cents / 10 ** exponentFor(currency);
1215
+ }
1216
+ function formatMoney(cents, currency, locale) {
1217
+ return new Intl.NumberFormat(locale, { style: "currency", currency }).format(
1218
+ fromMinor(cents, currency)
1219
+ );
1220
+ }
1221
+
1101
1222
  // src/ConsentBanner.tsx
1102
1223
  var import_react = require("react");
1103
1224
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -1202,7 +1323,7 @@ function GoogleAdsTracking(props) {
1202
1323
  var import_navigation = require("next/navigation");
1203
1324
 
1204
1325
  // package.json
1205
- var version = "0.7.2";
1326
+ var version = "0.9.0";
1206
1327
 
1207
1328
  // src/factory.tsx
1208
1329
  var import_react3 = require("react");
@@ -1408,16 +1529,22 @@ function createTracking(options) {
1408
1529
  }
1409
1530
  // Annotate the CommonJS export names for ESM import in node:
1410
1531
  0 && (module.exports = {
1532
+ AranovaApiError,
1411
1533
  ConsentBanner,
1412
1534
  GoogleAdsTracking,
1413
1535
  TRACKING_PARAM_KEYS,
1414
1536
  captureTrackingParamsFromLocation,
1537
+ createSalesClient,
1415
1538
  createTracking,
1416
1539
  createTrackingClientContext,
1417
1540
  createTrackingEventCreatePayload,
1418
1541
  createTrackingSessionUpsertPayload,
1542
+ fetchServices,
1543
+ formatMoney,
1544
+ fromMinor,
1419
1545
  getConsentState,
1420
1546
  setConsentState,
1547
+ toMinor,
1421
1548
  useConsentState,
1422
1549
  useGclid,
1423
1550
  useTrackingParams