@aranova/tracking-next 0.7.1 → 0.8.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 +47 -1
- package/dist/index.d.mts +302 -1
- package/dist/index.d.ts +302 -1
- package/dist/index.js +146 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +140 -5
- package/dist/index.mjs.map +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1232,6 +1232,307 @@ 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
|
+
}, "strict", z.ZodTypeAny, {
|
|
1302
|
+
currency: "USD" | "CAD";
|
|
1303
|
+
amount_total_cents: number;
|
|
1304
|
+
occurred_at: string;
|
|
1305
|
+
environment: "production" | "development";
|
|
1306
|
+
items: {
|
|
1307
|
+
quantity: string;
|
|
1308
|
+
unit_price_cents: number;
|
|
1309
|
+
name?: string | null | undefined;
|
|
1310
|
+
external_item_id?: string | null | undefined;
|
|
1311
|
+
category?: string | null | undefined;
|
|
1312
|
+
unit_cost_cents?: number | null | undefined;
|
|
1313
|
+
}[];
|
|
1314
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
1315
|
+
external_id?: string | null | undefined;
|
|
1316
|
+
description?: string | null | undefined;
|
|
1317
|
+
service?: string | null | undefined;
|
|
1318
|
+
}, {
|
|
1319
|
+
currency: "USD" | "CAD";
|
|
1320
|
+
amount_total_cents: number;
|
|
1321
|
+
occurred_at: string;
|
|
1322
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
1323
|
+
external_id?: string | null | undefined;
|
|
1324
|
+
description?: string | null | undefined;
|
|
1325
|
+
service?: string | null | undefined;
|
|
1326
|
+
environment?: "production" | "development" | undefined;
|
|
1327
|
+
items?: {
|
|
1328
|
+
quantity: string;
|
|
1329
|
+
unit_price_cents: number;
|
|
1330
|
+
name?: string | null | undefined;
|
|
1331
|
+
external_item_id?: string | null | undefined;
|
|
1332
|
+
category?: string | null | undefined;
|
|
1333
|
+
unit_cost_cents?: number | null | undefined;
|
|
1334
|
+
}[] | undefined;
|
|
1335
|
+
}>;
|
|
1336
|
+
declare const saleUpdateSchema: z.ZodObject<{
|
|
1337
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1338
|
+
service: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1339
|
+
currency: z.ZodOptional<z.ZodEnum<["USD", "CAD"]>>;
|
|
1340
|
+
amount_total_cents: z.ZodOptional<z.ZodNumber>;
|
|
1341
|
+
occurred_at: z.ZodOptional<z.ZodString>;
|
|
1342
|
+
items: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1343
|
+
external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1344
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1345
|
+
category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1346
|
+
quantity: z.ZodString;
|
|
1347
|
+
unit_price_cents: z.ZodNumber;
|
|
1348
|
+
unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
1349
|
+
}, "strict", z.ZodTypeAny, {
|
|
1350
|
+
quantity: string;
|
|
1351
|
+
unit_price_cents: number;
|
|
1352
|
+
name?: string | null | undefined;
|
|
1353
|
+
external_item_id?: string | null | undefined;
|
|
1354
|
+
category?: string | null | undefined;
|
|
1355
|
+
unit_cost_cents?: number | null | undefined;
|
|
1356
|
+
}, {
|
|
1357
|
+
quantity: string;
|
|
1358
|
+
unit_price_cents: number;
|
|
1359
|
+
name?: string | null | undefined;
|
|
1360
|
+
external_item_id?: string | null | undefined;
|
|
1361
|
+
category?: string | null | undefined;
|
|
1362
|
+
unit_cost_cents?: number | null | undefined;
|
|
1363
|
+
}>, "many">>;
|
|
1364
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
1365
|
+
}, "strict", z.ZodTypeAny, {
|
|
1366
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
1367
|
+
description?: string | null | undefined;
|
|
1368
|
+
service?: string | null | undefined;
|
|
1369
|
+
currency?: "USD" | "CAD" | undefined;
|
|
1370
|
+
amount_total_cents?: number | undefined;
|
|
1371
|
+
occurred_at?: string | undefined;
|
|
1372
|
+
items?: {
|
|
1373
|
+
quantity: string;
|
|
1374
|
+
unit_price_cents: number;
|
|
1375
|
+
name?: string | null | undefined;
|
|
1376
|
+
external_item_id?: string | null | undefined;
|
|
1377
|
+
category?: string | null | undefined;
|
|
1378
|
+
unit_cost_cents?: number | null | undefined;
|
|
1379
|
+
}[] | undefined;
|
|
1380
|
+
}, {
|
|
1381
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
1382
|
+
description?: string | null | undefined;
|
|
1383
|
+
service?: string | null | undefined;
|
|
1384
|
+
currency?: "USD" | "CAD" | undefined;
|
|
1385
|
+
amount_total_cents?: number | undefined;
|
|
1386
|
+
occurred_at?: string | undefined;
|
|
1387
|
+
items?: {
|
|
1388
|
+
quantity: string;
|
|
1389
|
+
unit_price_cents: number;
|
|
1390
|
+
name?: string | null | undefined;
|
|
1391
|
+
external_item_id?: string | null | undefined;
|
|
1392
|
+
category?: string | null | undefined;
|
|
1393
|
+
unit_cost_cents?: number | null | undefined;
|
|
1394
|
+
}[] | undefined;
|
|
1395
|
+
}>;
|
|
1396
|
+
type SaleItemInput = z.input<typeof saleItemSchema>;
|
|
1397
|
+
type SaleInput = z.input<typeof saleCreateSchema>;
|
|
1398
|
+
type SaleUpdateInput = z.input<typeof saleUpdateSchema>;
|
|
1399
|
+
interface SaleItem {
|
|
1400
|
+
id: string;
|
|
1401
|
+
external_item_id: string | null;
|
|
1402
|
+
name: string | null;
|
|
1403
|
+
category: string | null;
|
|
1404
|
+
quantity: string;
|
|
1405
|
+
unit_price_cents: number;
|
|
1406
|
+
unit_cost_cents: number | null;
|
|
1407
|
+
}
|
|
1408
|
+
interface Sale {
|
|
1409
|
+
id: string;
|
|
1410
|
+
business_id: string;
|
|
1411
|
+
business_name?: string | null;
|
|
1412
|
+
external_id: string | null;
|
|
1413
|
+
currency: SupportedCurrency;
|
|
1414
|
+
amount_total_cents: number;
|
|
1415
|
+
description: string | null;
|
|
1416
|
+
service_id: string | null;
|
|
1417
|
+
service_key?: string | null;
|
|
1418
|
+
service_label?: string | null;
|
|
1419
|
+
occurred_at: string;
|
|
1420
|
+
environment: (typeof TRACKING_ENVIRONMENTS)[number];
|
|
1421
|
+
metadata: Record<string, unknown> | null;
|
|
1422
|
+
created_at: string;
|
|
1423
|
+
updated_at: string;
|
|
1424
|
+
items: SaleItem[];
|
|
1425
|
+
}
|
|
1426
|
+
interface SaleListPage {
|
|
1427
|
+
items: Sale[];
|
|
1428
|
+
total: number;
|
|
1429
|
+
}
|
|
1430
|
+
interface SaleCursorPage {
|
|
1431
|
+
items: Sale[];
|
|
1432
|
+
next_cursor: string | null;
|
|
1433
|
+
}
|
|
1434
|
+
interface SaleListQuery {
|
|
1435
|
+
business_id?: string;
|
|
1436
|
+
external_id?: string;
|
|
1437
|
+
currency?: SupportedCurrency;
|
|
1438
|
+
environment?: (typeof TRACKING_ENVIRONMENTS)[number];
|
|
1439
|
+
since?: string;
|
|
1440
|
+
until?: string;
|
|
1441
|
+
limit?: number;
|
|
1442
|
+
cursor?: string | null;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
/** Shared config for every sales HTTP helper. */
|
|
1446
|
+
interface SalesTransportConfig {
|
|
1447
|
+
/** Public (`aranv_pk_…`) or secret (`aranv_sk_…`) API key. */
|
|
1448
|
+
apiKey: string;
|
|
1449
|
+
/**
|
|
1450
|
+
* Base tracking endpoint, e.g. `https://aranovainternal-production.up.railway.app/tracking`.
|
|
1451
|
+
* The `/sales` path is appended by the helpers.
|
|
1452
|
+
*/
|
|
1453
|
+
endpoint: string;
|
|
1454
|
+
/** Optional SDK identity headers (mirrors the event ingest client). */
|
|
1455
|
+
sdkVersion?: string;
|
|
1456
|
+
packageName?: string;
|
|
1457
|
+
surface?: string;
|
|
1458
|
+
environment?: string;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/** Config for {@link createSalesClient}. */
|
|
1462
|
+
interface SalesClientConfig extends SalesTransportConfig {
|
|
1463
|
+
/** Applied when an individual `record()` call omits `currency`. */
|
|
1464
|
+
defaultCurrency?: SupportedCurrency;
|
|
1465
|
+
}
|
|
1466
|
+
/**
|
|
1467
|
+
* One isomorphic sales client — what a key may *do* is enforced by the backend,
|
|
1468
|
+
* not by hiding methods. A **public** key (`aranv_pk_…`) may `record` (the
|
|
1469
|
+
* backend rejects reads/CRUD from it with a `403`); a **secret** key
|
|
1470
|
+
* (`aranv_sk_…`), used **server-side only**, gets full read/list/update/delete.
|
|
1471
|
+
* Never ship a secret key in a browser bundle.
|
|
1472
|
+
*
|
|
1473
|
+
* Generic over the service-key union `TService`: bind the type emitted by
|
|
1474
|
+
* `@aranova/tracking-cli gen` for compile-time-checked `service` values.
|
|
1475
|
+
*/
|
|
1476
|
+
interface SalesClient<TService extends string = string> {
|
|
1477
|
+
record(input: Omit<SaleInput, 'currency' | 'occurred_at' | 'service'> & {
|
|
1478
|
+
service?: TService | null;
|
|
1479
|
+
currency?: SupportedCurrency;
|
|
1480
|
+
occurred_at?: string;
|
|
1481
|
+
}): Promise<Sale>;
|
|
1482
|
+
list(query?: SaleListQuery): Promise<SaleCursorPage>;
|
|
1483
|
+
get(id: string): Promise<Sale>;
|
|
1484
|
+
update(id: string, patch: Omit<SaleUpdateInput, 'service'> & {
|
|
1485
|
+
service?: TService | null;
|
|
1486
|
+
}): Promise<Sale>;
|
|
1487
|
+
delete(id: string): Promise<void>;
|
|
1488
|
+
}
|
|
1489
|
+
declare function createSalesClient<TService extends string = string>(config: SalesClientConfig): SalesClient<TService>;
|
|
1490
|
+
|
|
1491
|
+
/** A business's active service, as returned by `GET /tracking/services`. */
|
|
1492
|
+
interface PublicServiceItem {
|
|
1493
|
+
key: string;
|
|
1494
|
+
label: string;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Fetch the caller's business's active service taxonomy. Accepts a public or
|
|
1498
|
+
* secret key (the taxonomy is low-sensitivity category names). Powers the
|
|
1499
|
+
* `@aranova/tracking-cli gen` codegen.
|
|
1500
|
+
*/
|
|
1501
|
+
declare function fetchServices(config: SalesTransportConfig): Promise<PublicServiceItem[]>;
|
|
1502
|
+
|
|
1503
|
+
/**
|
|
1504
|
+
* Convert a major amount (dollars `250.5`) to integer minor units (`25050`).
|
|
1505
|
+
*
|
|
1506
|
+
* Convenience only — the wire is always integer cents. Uses float multiply +
|
|
1507
|
+
* `Math.round`, so values that aren't exactly representable in binary float
|
|
1508
|
+
* (e.g. `1.005`) can round to the neighbouring cent. If you already hold an
|
|
1509
|
+
* exact cents integer, pass it straight through and skip this helper.
|
|
1510
|
+
*/
|
|
1511
|
+
declare function toMinor(amount: number, currency: SupportedCurrency): number;
|
|
1512
|
+
/** Convert integer minor units (`25050`) to a major amount (`250.5`). */
|
|
1513
|
+
declare function fromMinor(cents: number, currency: SupportedCurrency): number;
|
|
1514
|
+
/**
|
|
1515
|
+
* Format integer minor units as a localized currency string (e.g. `"$250.50"`).
|
|
1516
|
+
* Uses the built-in `Intl.NumberFormat` — no extra dependency.
|
|
1517
|
+
*/
|
|
1518
|
+
declare function formatMoney(cents: number, currency: SupportedCurrency, locale?: string): string;
|
|
1519
|
+
|
|
1520
|
+
/**
|
|
1521
|
+
* Error thrown by the sales client (`createSalesClient`) on a
|
|
1522
|
+
* non-2xx response. Unlike the fire-and-forget event queue (which swallows
|
|
1523
|
+
* failures), a sale is a transaction the caller must be able to react to.
|
|
1524
|
+
*/
|
|
1525
|
+
declare class AranovaApiError extends Error {
|
|
1526
|
+
readonly status: number;
|
|
1527
|
+
readonly code: string | undefined;
|
|
1528
|
+
readonly requestId: string | undefined;
|
|
1529
|
+
constructor(message: string, options: {
|
|
1530
|
+
status: number;
|
|
1531
|
+
code?: string;
|
|
1532
|
+
requestId?: string;
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1235
1536
|
/**
|
|
1236
1537
|
* Default non-blocking consent banner for Next.js installs.
|
|
1237
1538
|
*
|
|
@@ -1345,4 +1646,4 @@ interface CreateTrackingResult<TRegistry extends TriggerRegistryConfig> {
|
|
|
1345
1646
|
*/
|
|
1346
1647
|
declare function createTracking<TRegistry extends TriggerRegistryConfig>(options: CreateTrackingOptions<TRegistry>): CreateTrackingResult<TRegistry>;
|
|
1347
1648
|
|
|
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 };
|
|
1649
|
+
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
|
|
@@ -445,6 +451,10 @@ var DEFAULT_FLUSH_INTERVAL_MS = 2e3;
|
|
|
445
451
|
var DEFAULT_MAX_QUEUE_SIZE = 10;
|
|
446
452
|
var HARD_MAX_BATCH = 50;
|
|
447
453
|
var API_KEY_HEADER = "X-Aranova-Api-Key";
|
|
454
|
+
var SDK_VERSION_HEADER = "X-Aranova-Sdk-Version";
|
|
455
|
+
var SDK_PACKAGE_HEADER = "X-Aranova-Sdk-Package";
|
|
456
|
+
var SDK_SURFACE_HEADER = "X-Aranova-Sdk-Surface";
|
|
457
|
+
var SDK_ENVIRONMENT_HEADER = "X-Aranova-Sdk-Environment";
|
|
448
458
|
function buildContext(surface, sdkVersion, packageName, environment, activeGtagIds) {
|
|
449
459
|
return {
|
|
450
460
|
surface,
|
|
@@ -473,7 +483,7 @@ function consentSnapshot() {
|
|
|
473
483
|
return null;
|
|
474
484
|
}
|
|
475
485
|
}
|
|
476
|
-
async function postWithFetch(url, body, apiKey, keepalive) {
|
|
486
|
+
async function postWithFetch(url, body, apiKey, identity, keepalive) {
|
|
477
487
|
if (typeof fetch !== "function")
|
|
478
488
|
return;
|
|
479
489
|
try {
|
|
@@ -481,7 +491,11 @@ async function postWithFetch(url, body, apiKey, keepalive) {
|
|
|
481
491
|
method: "POST",
|
|
482
492
|
headers: {
|
|
483
493
|
"Content-Type": "application/json",
|
|
484
|
-
[API_KEY_HEADER]: apiKey
|
|
494
|
+
[API_KEY_HEADER]: apiKey,
|
|
495
|
+
[SDK_VERSION_HEADER]: identity.sdkVersion,
|
|
496
|
+
[SDK_PACKAGE_HEADER]: identity.packageName,
|
|
497
|
+
[SDK_SURFACE_HEADER]: identity.surface,
|
|
498
|
+
[SDK_ENVIRONMENT_HEADER]: identity.environment
|
|
485
499
|
},
|
|
486
500
|
body,
|
|
487
501
|
keepalive,
|
|
@@ -518,6 +532,12 @@ function createTrackingClient(config) {
|
|
|
518
532
|
const activeGtagIds = config.activeGtagIds ?? null;
|
|
519
533
|
const endpointBase = config.endpoint.replace(/\/$/, "");
|
|
520
534
|
const eventsUrl = `${endpointBase}/events`;
|
|
535
|
+
const identityHeaders2 = {
|
|
536
|
+
sdkVersion: sdkVersion ?? "",
|
|
537
|
+
packageName: packageName ?? "",
|
|
538
|
+
surface: config.surface,
|
|
539
|
+
environment
|
|
540
|
+
};
|
|
521
541
|
let queue = [];
|
|
522
542
|
let flushTimer = null;
|
|
523
543
|
let firstPage = null;
|
|
@@ -593,7 +613,7 @@ function createTrackingClient(config) {
|
|
|
593
613
|
events
|
|
594
614
|
};
|
|
595
615
|
const serialized = JSON.stringify(body);
|
|
596
|
-
await postWithFetch(eventsUrl, serialized, config.apiKey, false);
|
|
616
|
+
await postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders2, false);
|
|
597
617
|
}
|
|
598
618
|
function trackEvent(input) {
|
|
599
619
|
if (destroyed)
|
|
@@ -624,7 +644,7 @@ function createTrackingClient(config) {
|
|
|
624
644
|
events
|
|
625
645
|
};
|
|
626
646
|
const serialized = JSON.stringify(body);
|
|
627
|
-
void postWithFetch(eventsUrl, serialized, config.apiKey, true);
|
|
647
|
+
void postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders2, true);
|
|
628
648
|
}
|
|
629
649
|
if (typeof window !== "undefined") {
|
|
630
650
|
window.addEventListener("pagehide", flushOnUnload);
|
|
@@ -1084,6 +1104,121 @@ function attachFormStart(client, config) {
|
|
|
1084
1104
|
};
|
|
1085
1105
|
}
|
|
1086
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
|
+
|
|
1087
1222
|
// src/ConsentBanner.tsx
|
|
1088
1223
|
var import_react = require("react");
|
|
1089
1224
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1188,7 +1323,7 @@ function GoogleAdsTracking(props) {
|
|
|
1188
1323
|
var import_navigation = require("next/navigation");
|
|
1189
1324
|
|
|
1190
1325
|
// package.json
|
|
1191
|
-
var version = "0.
|
|
1326
|
+
var version = "0.8.0";
|
|
1192
1327
|
|
|
1193
1328
|
// src/factory.tsx
|
|
1194
1329
|
var import_react3 = require("react");
|
|
@@ -1394,16 +1529,22 @@ function createTracking(options) {
|
|
|
1394
1529
|
}
|
|
1395
1530
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1396
1531
|
0 && (module.exports = {
|
|
1532
|
+
AranovaApiError,
|
|
1397
1533
|
ConsentBanner,
|
|
1398
1534
|
GoogleAdsTracking,
|
|
1399
1535
|
TRACKING_PARAM_KEYS,
|
|
1400
1536
|
captureTrackingParamsFromLocation,
|
|
1537
|
+
createSalesClient,
|
|
1401
1538
|
createTracking,
|
|
1402
1539
|
createTrackingClientContext,
|
|
1403
1540
|
createTrackingEventCreatePayload,
|
|
1404
1541
|
createTrackingSessionUpsertPayload,
|
|
1542
|
+
fetchServices,
|
|
1543
|
+
formatMoney,
|
|
1544
|
+
fromMinor,
|
|
1405
1545
|
getConsentState,
|
|
1406
1546
|
setConsentState,
|
|
1547
|
+
toMinor,
|
|
1407
1548
|
useConsentState,
|
|
1408
1549
|
useGclid,
|
|
1409
1550
|
useTrackingParams
|