@aranova/tracking-react 0.12.2 → 0.14.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/sales.d.ts CHANGED
@@ -1,784 +1,2 @@
1
- import { z } from 'zod';
2
-
3
- /**
4
- * Sales / Conversions wire schemas — the client-side source of truth.
5
- *
6
- * `saleCreateSchema` is mirrored by `SaleCreateSchema` in
7
- * `apps/api/src/schemas/tracking_sales.py` and enforced by the backend drift
8
- * test (the `resources` section of `events.schema.json`). Keep them in lockstep.
9
- *
10
- * Money is **integer minor units (cents)**; `quantity` is a decimal string;
11
- * `currency` is the required `SupportedCurrency` enum.
12
- */
13
- declare const SUPPORTED_CURRENCIES: readonly ["USD", "CAD"];
14
- type SupportedCurrency = (typeof SUPPORTED_CURRENCIES)[number];
15
- declare const TRACKING_ENVIRONMENTS: readonly ["production", "development"];
16
- declare const saleItemSchema: z.ZodObject<{
17
- external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
18
- name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
19
- category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
20
- quantity: z.ZodString;
21
- unit_price_cents: z.ZodNumber;
22
- unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
23
- }, "strict", z.ZodTypeAny, {
24
- quantity: string;
25
- unit_price_cents: number;
26
- name?: string | null | undefined;
27
- external_item_id?: string | null | undefined;
28
- category?: string | null | undefined;
29
- unit_cost_cents?: number | null | undefined;
30
- }, {
31
- quantity: string;
32
- unit_price_cents: number;
33
- name?: string | null | undefined;
34
- external_item_id?: string | null | undefined;
35
- category?: string | null | undefined;
36
- unit_cost_cents?: number | null | undefined;
37
- }>;
38
- declare const saleServiceSchema: z.ZodObject<{
39
- service: z.ZodString;
40
- amount_cents: z.ZodNumber;
41
- }, "strict", z.ZodTypeAny, {
42
- service: string;
43
- amount_cents: number;
44
- }, {
45
- service: string;
46
- amount_cents: number;
47
- }>;
48
- declare const saleCreateSchema: z.ZodEffects<z.ZodObject<{
49
- external_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
50
- description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
51
- service: z.ZodOptional<z.ZodNullable<z.ZodString>>;
52
- services: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
53
- service: z.ZodString;
54
- amount_cents: z.ZodNumber;
55
- }, "strict", z.ZodTypeAny, {
56
- service: string;
57
- amount_cents: number;
58
- }, {
59
- service: string;
60
- amount_cents: number;
61
- }>, "many">>>;
62
- currency: z.ZodEnum<["USD", "CAD"]>;
63
- amount_total_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
64
- occurred_at: z.ZodString;
65
- environment: z.ZodDefault<z.ZodEnum<["production", "development"]>>;
66
- items: z.ZodDefault<z.ZodArray<z.ZodObject<{
67
- external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
68
- name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
- category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
70
- quantity: z.ZodString;
71
- unit_price_cents: z.ZodNumber;
72
- unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
73
- }, "strict", z.ZodTypeAny, {
74
- quantity: string;
75
- unit_price_cents: number;
76
- name?: string | null | undefined;
77
- external_item_id?: string | null | undefined;
78
- category?: string | null | undefined;
79
- unit_cost_cents?: number | null | undefined;
80
- }, {
81
- quantity: string;
82
- unit_price_cents: number;
83
- name?: string | null | undefined;
84
- external_item_id?: string | null | undefined;
85
- category?: string | null | undefined;
86
- unit_cost_cents?: number | null | undefined;
87
- }>, "many">>;
88
- metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
89
- customer_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
90
- customer_phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
91
- customer_email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
92
- }, "strict", z.ZodTypeAny, {
93
- currency: "USD" | "CAD";
94
- occurred_at: string;
95
- environment: "production" | "development";
96
- items: {
97
- quantity: string;
98
- unit_price_cents: number;
99
- name?: string | null | undefined;
100
- external_item_id?: string | null | undefined;
101
- category?: string | null | undefined;
102
- unit_cost_cents?: number | null | undefined;
103
- }[];
104
- metadata?: Record<string, unknown> | null | undefined;
105
- service?: string | null | undefined;
106
- services?: {
107
- service: string;
108
- amount_cents: number;
109
- }[] | null | undefined;
110
- amount_total_cents?: number | null | undefined;
111
- external_id?: string | null | undefined;
112
- description?: string | null | undefined;
113
- customer_name?: string | null | undefined;
114
- customer_phone?: string | null | undefined;
115
- customer_email?: string | null | undefined;
116
- }, {
117
- currency: "USD" | "CAD";
118
- occurred_at: string;
119
- metadata?: Record<string, unknown> | null | undefined;
120
- service?: string | null | undefined;
121
- services?: {
122
- service: string;
123
- amount_cents: number;
124
- }[] | null | undefined;
125
- amount_total_cents?: number | null | undefined;
126
- external_id?: string | null | undefined;
127
- description?: string | null | undefined;
128
- environment?: "production" | "development" | undefined;
129
- items?: {
130
- quantity: string;
131
- unit_price_cents: number;
132
- name?: string | null | undefined;
133
- external_item_id?: string | null | undefined;
134
- category?: string | null | undefined;
135
- unit_cost_cents?: number | null | undefined;
136
- }[] | undefined;
137
- customer_name?: string | null | undefined;
138
- customer_phone?: string | null | undefined;
139
- customer_email?: string | null | undefined;
140
- }>, {
141
- currency: "USD" | "CAD";
142
- occurred_at: string;
143
- environment: "production" | "development";
144
- items: {
145
- quantity: string;
146
- unit_price_cents: number;
147
- name?: string | null | undefined;
148
- external_item_id?: string | null | undefined;
149
- category?: string | null | undefined;
150
- unit_cost_cents?: number | null | undefined;
151
- }[];
152
- metadata?: Record<string, unknown> | null | undefined;
153
- service?: string | null | undefined;
154
- services?: {
155
- service: string;
156
- amount_cents: number;
157
- }[] | null | undefined;
158
- amount_total_cents?: number | null | undefined;
159
- external_id?: string | null | undefined;
160
- description?: string | null | undefined;
161
- customer_name?: string | null | undefined;
162
- customer_phone?: string | null | undefined;
163
- customer_email?: string | null | undefined;
164
- }, {
165
- currency: "USD" | "CAD";
166
- occurred_at: string;
167
- metadata?: Record<string, unknown> | null | undefined;
168
- service?: string | null | undefined;
169
- services?: {
170
- service: string;
171
- amount_cents: number;
172
- }[] | null | undefined;
173
- amount_total_cents?: number | null | undefined;
174
- external_id?: string | null | undefined;
175
- description?: string | null | undefined;
176
- environment?: "production" | "development" | undefined;
177
- items?: {
178
- quantity: string;
179
- unit_price_cents: number;
180
- name?: string | null | undefined;
181
- external_item_id?: string | null | undefined;
182
- category?: string | null | undefined;
183
- unit_cost_cents?: number | null | undefined;
184
- }[] | undefined;
185
- customer_name?: string | null | undefined;
186
- customer_phone?: string | null | undefined;
187
- customer_email?: string | null | undefined;
188
- }>;
189
- declare const saleUpdateSchema: z.ZodEffects<z.ZodObject<{
190
- description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
191
- service: z.ZodOptional<z.ZodNullable<z.ZodString>>;
192
- services: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
193
- service: z.ZodString;
194
- amount_cents: z.ZodNumber;
195
- }, "strict", z.ZodTypeAny, {
196
- service: string;
197
- amount_cents: number;
198
- }, {
199
- service: string;
200
- amount_cents: number;
201
- }>, "many">>>;
202
- currency: z.ZodOptional<z.ZodEnum<["USD", "CAD"]>>;
203
- amount_total_cents: z.ZodOptional<z.ZodNumber>;
204
- occurred_at: z.ZodOptional<z.ZodString>;
205
- items: z.ZodOptional<z.ZodArray<z.ZodObject<{
206
- external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
207
- name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
208
- category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
209
- quantity: z.ZodString;
210
- unit_price_cents: z.ZodNumber;
211
- unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
212
- }, "strict", z.ZodTypeAny, {
213
- quantity: string;
214
- unit_price_cents: number;
215
- name?: string | null | undefined;
216
- external_item_id?: string | null | undefined;
217
- category?: string | null | undefined;
218
- unit_cost_cents?: number | null | undefined;
219
- }, {
220
- quantity: string;
221
- unit_price_cents: number;
222
- name?: string | null | undefined;
223
- external_item_id?: string | null | undefined;
224
- category?: string | null | undefined;
225
- unit_cost_cents?: number | null | undefined;
226
- }>, "many">>;
227
- metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
228
- customer_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
229
- customer_phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
230
- customer_email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
231
- }, "strict", z.ZodTypeAny, {
232
- metadata?: Record<string, unknown> | null | undefined;
233
- service?: string | null | undefined;
234
- services?: {
235
- service: string;
236
- amount_cents: number;
237
- }[] | null | undefined;
238
- amount_total_cents?: number | undefined;
239
- description?: string | null | undefined;
240
- currency?: "USD" | "CAD" | undefined;
241
- occurred_at?: string | undefined;
242
- items?: {
243
- quantity: string;
244
- unit_price_cents: number;
245
- name?: string | null | undefined;
246
- external_item_id?: string | null | undefined;
247
- category?: string | null | undefined;
248
- unit_cost_cents?: number | null | undefined;
249
- }[] | undefined;
250
- customer_name?: string | null | undefined;
251
- customer_phone?: string | null | undefined;
252
- customer_email?: string | null | undefined;
253
- }, {
254
- metadata?: Record<string, unknown> | null | undefined;
255
- service?: string | null | undefined;
256
- services?: {
257
- service: string;
258
- amount_cents: number;
259
- }[] | null | undefined;
260
- amount_total_cents?: number | undefined;
261
- description?: string | null | undefined;
262
- currency?: "USD" | "CAD" | undefined;
263
- occurred_at?: string | undefined;
264
- items?: {
265
- quantity: string;
266
- unit_price_cents: number;
267
- name?: string | null | undefined;
268
- external_item_id?: string | null | undefined;
269
- category?: string | null | undefined;
270
- unit_cost_cents?: number | null | undefined;
271
- }[] | undefined;
272
- customer_name?: string | null | undefined;
273
- customer_phone?: string | null | undefined;
274
- customer_email?: string | null | undefined;
275
- }>, {
276
- metadata?: Record<string, unknown> | null | undefined;
277
- service?: string | null | undefined;
278
- services?: {
279
- service: string;
280
- amount_cents: number;
281
- }[] | null | undefined;
282
- amount_total_cents?: number | undefined;
283
- description?: string | null | undefined;
284
- currency?: "USD" | "CAD" | undefined;
285
- occurred_at?: string | undefined;
286
- items?: {
287
- quantity: string;
288
- unit_price_cents: number;
289
- name?: string | null | undefined;
290
- external_item_id?: string | null | undefined;
291
- category?: string | null | undefined;
292
- unit_cost_cents?: number | null | undefined;
293
- }[] | undefined;
294
- customer_name?: string | null | undefined;
295
- customer_phone?: string | null | undefined;
296
- customer_email?: string | null | undefined;
297
- }, {
298
- metadata?: Record<string, unknown> | null | undefined;
299
- service?: string | null | undefined;
300
- services?: {
301
- service: string;
302
- amount_cents: number;
303
- }[] | null | undefined;
304
- amount_total_cents?: number | undefined;
305
- description?: string | null | undefined;
306
- currency?: "USD" | "CAD" | undefined;
307
- occurred_at?: string | undefined;
308
- items?: {
309
- quantity: string;
310
- unit_price_cents: number;
311
- name?: string | null | undefined;
312
- external_item_id?: string | null | undefined;
313
- category?: string | null | undefined;
314
- unit_cost_cents?: number | null | undefined;
315
- }[] | undefined;
316
- customer_name?: string | null | undefined;
317
- customer_phone?: string | null | undefined;
318
- customer_email?: string | null | undefined;
319
- }>;
320
- type SaleItemInput = z.input<typeof saleItemSchema>;
321
- type SaleServiceInput = z.input<typeof saleServiceSchema>;
322
- type SaleInput = z.input<typeof saleCreateSchema>;
323
- type SaleUpdateInput = z.input<typeof saleUpdateSchema>;
324
- interface SaleItem {
325
- id: string;
326
- external_item_id: string | null;
327
- name: string | null;
328
- category: string | null;
329
- quantity: string;
330
- unit_price_cents: number;
331
- unit_cost_cents: number | null;
332
- }
333
- interface SaleService {
334
- id: string;
335
- service_id: string;
336
- service_key: string;
337
- service_label: string;
338
- amount_cents: number;
339
- }
340
- interface Sale {
341
- id: string;
342
- business_id: string;
343
- business_name?: string | null;
344
- external_id: string | null;
345
- currency: SupportedCurrency;
346
- amount_total_cents: number;
347
- description: string | null;
348
- service_id: string | null;
349
- service_key?: string | null;
350
- service_label?: string | null;
351
- services: SaleService[];
352
- occurred_at: string;
353
- environment: (typeof TRACKING_ENVIRONMENTS)[number];
354
- metadata: Record<string, unknown> | null;
355
- customer_name: string | null;
356
- customer_phone: string | null;
357
- customer_email: string | null;
358
- created_at: string;
359
- updated_at: string;
360
- items: SaleItem[];
361
- }
362
- interface SaleListPage {
363
- items: Sale[];
364
- total: number;
365
- }
366
- interface SaleCursorPage {
367
- items: Sale[];
368
- next_cursor: string | null;
369
- /** Populated only when `want_total` was requested (a single indexed COUNT). */
370
- total_count?: number;
371
- has_more?: boolean;
372
- }
373
- /**
374
- * Sortable columns on the secret-key (keyset) and admin (offset) list endpoints.
375
- * `business_name` only applies to the cross-business admin list — it sorts the
376
- * joined `businesses.name` column.
377
- */
378
- type SaleSortField = "occurred_at" | "created_at" | "amount_total_cents" | "customer_name" | "business_name";
379
- type SaleSortOrder = "asc" | "desc";
380
- /**
381
- * Comprehensive filter shape mirrored from the backend's `SaleQueryFilters`.
382
- *
383
- * `search` runs case-insensitively across `customer_name`, `customer_phone`,
384
- * `customer_email`, `description`, and `external_id` — the human-facing
385
- * columns. `service_id` is the resolved per-business service UUID (different
386
- * from the create-time `service` *key*).
387
- */
388
- interface SaleFilters {
389
- business_id?: string;
390
- external_id?: string;
391
- service_id?: string;
392
- /** E.164 phone — the canonical customer key; filters sales for one customer. */
393
- customer_phone?: string;
394
- currency?: SupportedCurrency;
395
- environment?: (typeof TRACKING_ENVIRONMENTS)[number];
396
- since?: string;
397
- until?: string;
398
- min_amount_cents?: number;
399
- max_amount_cents?: number;
400
- search?: string;
401
- }
402
- /**
403
- * Full query input for `SalesClient.list()` — filters + pagination.
404
- *
405
- * Pagination is **keyset (cursor)**: `next_cursor` returned by one page is
406
- * passed back as `cursor` on the next. `null` / undefined cursor = first page.
407
- *
408
- * Ordering on this endpoint is fixed at **`occurred_at DESC, id DESC`** — the
409
- * cursor encodes a position in that index, so a different sort would
410
- * invalidate cursors mid-pagination. For ad-hoc sorted reads use the
411
- * dashboard admin endpoint, which is offset-paginated.
412
- */
413
- interface SaleListQuery extends SaleFilters {
414
- limit?: number;
415
- cursor?: string | null;
416
- }
417
- /** Keyset-safe sort columns (NOT-NULL, indexed). */
418
- type SaleKeysetSortField = "occurred_at" | "created_at" | "amount_total_cents";
419
- /** v2 list query — adds server sort + opt-in total. */
420
- interface SaleListQueryV2 extends SaleListQuery {
421
- sort?: SaleKeysetSortField;
422
- order?: SaleSortOrder;
423
- /** Opt-in: a single indexed COUNT over the filtered set. */
424
- want_total?: boolean;
425
- }
426
- declare const TRACKING_RANGES: readonly ["24h", "7d", "30d"];
427
- type TrackingOverviewRange = (typeof TRACKING_RANGES)[number];
428
- /** Query input for `SalesClient.summary()` — filters + range + options. */
429
- interface SaleSummaryQuery extends SaleFilters {
430
- range: TrackingOverviewRange;
431
- /** Include the per-category line-item breakdown (extra join; default false). */
432
- include_categories?: boolean;
433
- /** Surface soft-deleted services individually (flagged "(deleted)") instead of
434
- * rolling them into a single "Deleted services" bucket. Default false. */
435
- include_deleted_services?: boolean;
436
- /** Cap on the by-service / by-category rows (1–50, default 10). */
437
- top_n?: number;
438
- }
439
- interface CurrencyRevenue {
440
- currency: SupportedCurrency;
441
- sale_count: number;
442
- revenue_cents: number;
443
- average_order_value_cents: number;
444
- }
445
- interface SalesServiceBreakdown {
446
- service_id: string | null;
447
- service_key: string | null;
448
- /** "Unassigned" when the sale has no service. */
449
- service_label: string | null;
450
- currency: SupportedCurrency;
451
- sale_count: number;
452
- revenue_cents: number;
453
- }
454
- interface SalesCategoryBreakdown {
455
- category: string | null;
456
- currency: SupportedCurrency;
457
- /** sum(unit_price_cents * quantity) — advisory, not authoritative. */
458
- revenue_cents: number;
459
- /** Decimal string. */
460
- quantity: string;
461
- }
462
- interface SalesTrendPoint {
463
- bucket_start: string;
464
- currency: SupportedCurrency;
465
- sale_count: number;
466
- revenue_cents: number;
467
- }
468
- interface SaleSummary {
469
- range: TrackingOverviewRange;
470
- business_id: string | null;
471
- metrics: {
472
- sale_count: number;
473
- distinct_customers: number;
474
- by_currency: CurrencyRevenue[];
475
- };
476
- by_service: SalesServiceBreakdown[];
477
- by_currency: CurrencyRevenue[];
478
- by_category: SalesCategoryBreakdown[];
479
- series: SalesTrendPoint[];
480
- }
481
- declare const NAMED_RANGES: readonly ["today", "yesterday", "wtd", "mtd", "qtd", "ytd", "24h", "7d", "30d", "90d", "custom"];
482
- /** Superset of `TrackingOverviewRange` (`24h`/`7d`/`30d` stay valid). */
483
- type NamedRange = (typeof NAMED_RANGES)[number];
484
- type Granularity = "hour" | "day" | "week" | "month" | "auto";
485
- type CompareTo = "previous_period" | "previous_year" | "none";
486
- interface DistinctCustomersByCurrency {
487
- currency: SupportedCurrency;
488
- distinct_customers: number;
489
- }
490
- interface SummaryWindow {
491
- since: string;
492
- until: string;
493
- }
494
- interface SummaryCurrencyDelta {
495
- currency: SupportedCurrency;
496
- revenue_cents_delta: number;
497
- /** Ratio (0.12 = +12%); null when previous revenue was 0. */
498
- revenue_pct_delta: number | null;
499
- sale_count_delta: number;
500
- }
501
- interface SummaryDeltas {
502
- by_currency: SummaryCurrencyDelta[];
503
- sale_count_delta: number;
504
- distinct_customers_delta: number;
505
- }
506
- interface SaleSummaryPrevious {
507
- window: SummaryWindow;
508
- metrics: SaleSummaryV2["metrics"];
509
- by_currency: CurrencyRevenue[];
510
- series: SalesTrendPoint[];
511
- }
512
- /** Query input for `SalesClient.summary()` v2 — widened range + tz/compare options. */
513
- interface SaleSummaryQueryV2 extends SaleFilters {
514
- range?: NamedRange;
515
- /** Required when `range === 'custom'`. */
516
- since?: string;
517
- until?: string;
518
- /** IANA tz, e.g. `America/Toronto`. Default = business tz. */
519
- timezone?: string;
520
- granularity?: Granularity;
521
- compare_to?: CompareTo;
522
- include_categories?: boolean;
523
- include_deleted_services?: boolean;
524
- top_n?: number;
525
- }
526
- /** Superset of `SaleSummary` (assignable to it). */
527
- interface SaleSummaryV2 extends Omit<SaleSummary, "range" | "metrics"> {
528
- range: NamedRange;
529
- metrics: SaleSummary["metrics"] & {
530
- distinct_customers_by_currency: DistinctCustomersByCurrency[];
531
- };
532
- timezone: string | null;
533
- window: SummaryWindow | null;
534
- granularity: string | null;
535
- previous: SaleSummaryPrevious | null;
536
- deltas: SummaryDeltas | null;
537
- }
538
- type CustomerSegment = "new" | "returning" | "repeat" | "lapsed";
539
- type CustomerSortField = "total_spent" | "last_purchase" | "purchases" | "first_purchase";
540
- interface CustomerCurrencyTotal {
541
- currency: SupportedCurrency;
542
- revenue_cents: number;
543
- sale_count: number;
544
- average_order_value_cents: number;
545
- }
546
- interface CustomerSummary {
547
- /** The E.164 phone — the canonical customer id. */
548
- customer_id: string;
549
- display_name: string | null;
550
- email: string | null;
551
- phone: string;
552
- first_purchase_at: string;
553
- last_purchase_at: string;
554
- purchase_count: number;
555
- segment: CustomerSegment;
556
- totals: CustomerCurrencyTotal[];
557
- }
558
- type CustomerProfile = CustomerSummary;
559
- interface CustomerListQuery extends Omit<SaleFilters, "external_id"> {
560
- segment?: CustomerSegment;
561
- sort?: CustomerSortField;
562
- order?: SaleSortOrder;
563
- cursor?: string | null;
564
- limit?: number;
565
- want_total?: boolean;
566
- }
567
- interface CustomerListPage {
568
- items: CustomerSummary[];
569
- next_cursor: string | null;
570
- total_count: number | null;
571
- }
572
- interface CustomerGetOptions {
573
- include_sales?: boolean;
574
- limit?: number;
575
- cursor?: string | null;
576
- }
577
- interface CustomerGetResult {
578
- customer: CustomerProfile;
579
- /** Present only when `include_sales: true` (and a business-scoped key). */
580
- sales?: SaleCursorPage | null;
581
- }
582
- interface CustomerSummaryQuery extends SaleFilters {
583
- range?: NamedRange;
584
- since?: string;
585
- until?: string;
586
- timezone?: string;
587
- compare_to?: CompareTo;
588
- }
589
- interface CustomerSegmentCount {
590
- segment: CustomerSegment;
591
- count: number;
592
- }
593
- interface CustomerCurrencyDelta {
594
- currency: SupportedCurrency;
595
- revenue_cents_delta: number;
596
- /** Ratio (0.12 = +12%); null when previous revenue was 0. */
597
- revenue_pct_delta: number | null;
598
- }
599
- interface CustomerKpisDeltas {
600
- total_customers_delta: number;
601
- new_customers_delta: number;
602
- returning_customers_delta: number;
603
- repeat_rate_delta: number;
604
- ltv_by_currency: CustomerCurrencyDelta[];
605
- }
606
- interface CustomerKpisPrevious {
607
- window_since: string;
608
- window_until: string;
609
- total_customers: number;
610
- new_customers: number;
611
- returning_customers: number;
612
- repeat_rate: number;
613
- ltv_by_currency: CustomerCurrencyTotal[];
614
- }
615
- interface CustomerKpis {
616
- range: NamedRange;
617
- timezone: string;
618
- window_since: string;
619
- window_until: string;
620
- total_customers: number;
621
- new_customers: number;
622
- returning_customers: number;
623
- repeat_rate: number;
624
- by_segment: CustomerSegmentCount[];
625
- ltv_by_currency: CustomerCurrencyTotal[];
626
- /** Present only when `compare_to` is set. */
627
- previous?: CustomerKpisPrevious | null;
628
- deltas?: CustomerKpisDeltas | null;
629
- }
630
- interface BusinessConfigService {
631
- key: string;
632
- label: string;
633
- archived: boolean;
634
- }
635
- interface BusinessConfigFeatures {
636
- customers: boolean;
637
- comparisons: boolean;
638
- retention: boolean;
639
- }
640
- interface BusinessConfig {
641
- business_id: string;
642
- display_name: string;
643
- timezone: string;
644
- primary_currency: SupportedCurrency;
645
- currencies: SupportedCurrency[];
646
- default_phone_country: string | null;
647
- services: BusinessConfigService[];
648
- features: BusinessConfigFeatures;
649
- }
650
-
651
- /** Shared config for every sales HTTP helper. */
652
- interface SalesTransportConfig {
653
- /** Public (`aranv_pk_…`) or secret (`aranv_sk_…`) API key. */
654
- apiKey: string;
655
- /**
656
- * Base tracking endpoint, e.g. `https://aranovainternal-production.up.railway.app/tracking`.
657
- * The `/sales` path is appended by the helpers.
658
- */
659
- endpoint: string;
660
- /** Optional SDK identity headers (mirrors the event ingest client). */
661
- sdkVersion?: string;
662
- packageName?: string;
663
- surface?: string;
664
- environment?: string;
665
- }
666
- /**
667
- * Single awaited request used by every sales helper. Unlike the event queue,
668
- * this surfaces failures: any non-2xx rejects with an {@link AranovaApiError}.
669
- * Returns `undefined` for 204 No Content.
670
- */
671
- declare function salesRequest<T>(config: SalesTransportConfig, method: string, path: string, body?: unknown): Promise<T>;
672
-
673
- /** Config for {@link createSalesClient}. */
674
- interface SalesClientConfig extends SalesTransportConfig {
675
- /** Applied when an individual `record()` call omits `currency`. */
676
- defaultCurrency?: SupportedCurrency;
677
- }
678
- /** Phone-keyed customer rollups (sk-only; a public key gets a `403`). */
679
- interface SalesCustomersClient {
680
- list(query?: CustomerListQuery): Promise<CustomerListPage>;
681
- /** `id` is the customer's E.164 phone. */
682
- get(id: string, options?: CustomerGetOptions): Promise<CustomerGetResult>;
683
- summary(query?: CustomerSummaryQuery): Promise<CustomerKpis>;
684
- }
685
- /** Business config (low-sensitivity — accepts a public or secret key). */
686
- interface SalesBusinessClient {
687
- config(): Promise<BusinessConfig>;
688
- }
689
- /**
690
- * One isomorphic sales client — what a key may *do* is enforced by the backend,
691
- * not by hiding methods. A **public** key (`aranv_pk_…`) may `record` (the
692
- * backend rejects reads/CRUD from it with a `403`); a **secret** key
693
- * (`aranv_sk_…`), used **server-side only**, gets full read/list/update/delete.
694
- * Never ship a secret key in a browser bundle.
695
- *
696
- * Generic over the service-key union `TService`: bind the type emitted by
697
- * `@aranova/tracking-cli gen` for compile-time-checked `service` values.
698
- */
699
- interface SalesClient<TService extends string = string> {
700
- record(input: Omit<SaleInput, "currency" | "occurred_at" | "service" | "services"> & {
701
- service?: TService | null;
702
- services?: Array<{
703
- service: TService;
704
- amount_cents: number;
705
- }>;
706
- currency?: SupportedCurrency;
707
- occurred_at?: string;
708
- }): Promise<Sale>;
709
- /** Keyset list with optional server sort + opt-in `total_count`. */
710
- list(query?: SaleListQueryV2): Promise<SaleCursorPage>;
711
- /**
712
- * Currency-grouped aggregations for the key's business. Additive v2 options:
713
- * calendar/custom ranges, IANA `timezone`, `granularity`, and `compare_to`.
714
- * Legacy `24h/7d/30d` keep their exact prior numbers. Secret key only.
715
- */
716
- summary(query: SaleSummaryQueryV2): Promise<SaleSummaryV2>;
717
- get(id: string): Promise<Sale>;
718
- update(id: string, patch: Omit<SaleUpdateInput, "service" | "services"> & {
719
- service?: TService | null;
720
- services?: Array<{
721
- service: TService;
722
- amount_cents: number;
723
- }>;
724
- }): Promise<Sale>;
725
- delete(id: string): Promise<void>;
726
- /** Phone-keyed customer rollups (sk-only). */
727
- customers: SalesCustomersClient;
728
- /** Business config (pk or sk). */
729
- business: SalesBusinessClient;
730
- }
731
- declare function createSalesClient<TService extends string = string>(config: SalesClientConfig): SalesClient<TService>;
732
-
733
- /**
734
- * Error thrown by the sales client (`createSalesClient`) on a
735
- * non-2xx response. Unlike the fire-and-forget event queue (which swallows
736
- * failures), a sale is a transaction the caller must be able to react to.
737
- */
738
- declare class AranovaApiError extends Error {
739
- readonly status: number;
740
- readonly code: string | undefined;
741
- readonly requestId: string | undefined;
742
- constructor(message: string, options: {
743
- status: number;
744
- code?: string;
745
- requestId?: string;
746
- });
747
- }
748
-
749
- /**
750
- * Convert a major amount (dollars `250.5`) to integer minor units (`25050`).
751
- *
752
- * Convenience only — the wire is always integer cents. Uses float multiply +
753
- * `Math.round`, so values that aren't exactly representable in binary float
754
- * (e.g. `1.005`) can round to the neighbouring cent. If you already hold an
755
- * exact cents integer, pass it straight through and skip this helper.
756
- */
757
- declare function toMinor(amount: number, currency: SupportedCurrency): number;
758
- /** Convert integer minor units (`25050`) to a major amount (`250.5`). */
759
- declare function fromMinor(cents: number, currency: SupportedCurrency): number;
760
- /**
761
- * Format integer minor units as a localized currency string (e.g. `"$250.50"`).
762
- * Uses the built-in `Intl.NumberFormat` — no extra dependency.
763
- */
764
- declare function formatMoney(cents: number, currency: SupportedCurrency, locale?: string): string;
765
- /**
766
- * Format an ISO timestamp in a specific IANA time zone (e.g. `America/Toronto`),
767
- * so dashboards stop hand-rolling `Intl`. Defaults to a short date-time; pass
768
- * `opts` to override fields. The `timeZone` is always forced to the argument.
769
- */
770
- declare function formatDateInTz(iso: string, timeZone: string, opts?: Intl.DateTimeFormatOptions, locale?: string): string;
771
-
772
- /** A business's active service, as returned by `GET /tracking/services`. */
773
- interface PublicServiceItem {
774
- key: string;
775
- label: string;
776
- }
777
- /**
778
- * Fetch the caller's business's active service taxonomy. Accepts a public or
779
- * secret key (the taxonomy is low-sensitivity category names). Powers the
780
- * `@aranova/tracking-cli gen` codegen.
781
- */
782
- declare function fetchServices(config: SalesTransportConfig): Promise<PublicServiceItem[]>;
783
-
784
- export { AranovaApiError, type BusinessConfig, type BusinessConfigFeatures, type BusinessConfigService, type CompareTo, type CurrencyRevenue, type CustomerCurrencyDelta, type CustomerCurrencyTotal, type CustomerGetOptions, type CustomerGetResult, type CustomerKpis, type CustomerKpisDeltas, type CustomerKpisPrevious, type CustomerListPage, type CustomerListQuery, type CustomerProfile, type CustomerSegment, type CustomerSegmentCount, type CustomerSortField, type CustomerSummary, type CustomerSummaryQuery, type DistinctCustomersByCurrency, type Granularity, NAMED_RANGES, type NamedRange, type PublicServiceItem, SUPPORTED_CURRENCIES, type Sale, type SaleCursorPage, type SaleFilters, type SaleInput, type SaleItem, type SaleItemInput, type SaleKeysetSortField, type SaleListPage, type SaleListQuery, type SaleListQueryV2, type SaleService, type SaleServiceInput, type SaleSortField, type SaleSortOrder, type SaleSummary, type SaleSummaryPrevious, type SaleSummaryQuery, type SaleSummaryQueryV2, type SaleSummaryV2, type SaleUpdateInput, type SalesBusinessClient, type SalesCategoryBreakdown, type SalesClient, type SalesClientConfig, type SalesCustomersClient, type SalesServiceBreakdown, type SalesTransportConfig, type SalesTrendPoint, type SummaryCurrencyDelta, type SummaryDeltas, type SummaryWindow, type SupportedCurrency, TRACKING_RANGES, type TrackingOverviewRange, createSalesClient, fetchServices, formatDateInTz, formatMoney, fromMinor, saleCreateSchema, saleItemSchema, saleServiceSchema, saleUpdateSchema, salesRequest, toMinor };
1
+ export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, e as CurrencyRevenue, f as CustomerCurrencyDelta, g as CustomerCurrencyTotal, h as CustomerGetOptions, i as CustomerGetResult, j as CustomerKpis, k as CustomerKpisDeltas, l as CustomerKpisPrevious, m as CustomerListPage, n as CustomerListQuery, o as CustomerProfile, p as CustomerSegment, q as CustomerSegmentCount, r as CustomerSortField, s as CustomerSummary, t as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, u as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, v as Sale, w as SaleCursorPage, x as SaleFilters, y as SaleInput, z as SaleItem, E as SaleItemInput, F as SaleKeysetSortField, H as SaleListPage, I as SaleListQuery, J as SaleListQueryV2, K as SaleService, L as SaleServiceInput, M as SaleSortField, O as SaleSortOrder, Q as SaleSummary, R as SaleSummaryPrevious, T as SaleSummaryQuery, U as SaleSummaryQueryV2, V as SaleSummaryV2, W as SaleUpdateInput, X as SalesBusinessClient, Y as SalesCategoryBreakdown, Z as SalesClient, _ as SalesClientConfig, $ as SalesCustomersClient, a0 as SalesServiceBreakdown, a1 as SalesTransportConfig, a2 as SalesTrendPoint, a3 as SummaryCurrencyDelta, a4 as SummaryDeltas, a5 as SummaryWindow, a6 as SupportedCurrency, a7 as TRACKING_RANGES, a8 as TrackingOverviewRange, a9 as createSalesClient, aa as fetchServices, ab as formatDateInTz, ac as formatMoney, ad as fromMinor, af as saleCreateSchema, ag as saleItemSchema, ah as saleServiceSchema, ai as saleUpdateSchema, aj as salesRequest, ak as toMinor } from './sales-BsJodmh0.js';
2
+ import 'zod';