sinfactura-types 1.10.280 → 1.10.281

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.
@@ -7,11 +7,21 @@ exports.AUTOMATION_RULE_STATUSES = exports.AUTOMATION_SEND_STATUSES = exports.AT
7
7
  * from ONE list instead of three copies that drift. Same shape and same reason
8
8
  * as `STOCK_ADJUSTMENT_REASONS` in `contracts/src/stock.ts`.
9
9
  *
10
- * `satisfies` is what keeps the two in step in BOTH directions: a member added
11
- * to the union and not here compiles (the tuple is still assignable), but a
12
- * member added HERE and not to the union does not.
10
+ * ⚠️ **This tuple is the SOURCE and {@link AutomationTrigger} is derived from
11
+ * it**, so there is only one direction to get wrong and it does not exist. It
12
+ * used to be the other way round — the union declared separately and this tuple
13
+ * merely `satisfies`-checked against it — which caught a member added here and
14
+ * missing from the union, and silently allowed the reverse. That reverse is the
15
+ * damaging one: the published union would promise a trigger the api's Zod enum
16
+ * rejects and the picker never offers.
17
+ *
18
+ * ⚠️ **`REORDER_DUE` is the reorder-reminder trigger**, emitted by the daily
19
+ * cadence sweep from a customer's own delivery rhythm — never a fixed interval.
20
+ * Adding a member here is additive for a reader and a WIDENING for anything
21
+ * exhaustive over it: a `Record<AutomationTrigger, …>` fails to compile until it
22
+ * is handled, which is the point.
13
23
  */
14
- exports.AUTOMATION_TRIGGERS = ['ABANDONED_CART'];
24
+ exports.AUTOMATION_TRIGGERS = ['ABANDONED_CART', 'REORDER_DUE'];
15
25
  /**
16
26
  * How long after a send an order may still be attributed to it, in HOURS.
17
27
  *
@@ -47,6 +47,22 @@ var NotificationTypeEnum;
47
47
  * fails silently.
48
48
  */
49
49
  NotificationTypeEnum["ABANDONED_CART"] = "ABANDONED_CART";
50
+ /**
51
+ * A customer whose own delivery rhythm says they are due to reorder.
52
+ *
53
+ * ⚠️ Additive, on the same grounds as `ABANDONED_CART`.
54
+ *
55
+ * ⚠️ **This is the OPERATOR-facing fact, not the customer's reminder.** "This
56
+ * customer is due to reorder" is something a shop legitimately wants told; the
57
+ * message the customer receives is the automation's business and its opt-out
58
+ * is `Customer.marketing`, never a staff preference. That is the same split
59
+ * that makes `ABANDONED_CART` legal here and keeps `APPOINTMENT_REMINDER` out.
60
+ *
61
+ * ⚠️ The member exists because `AUTOMATION_TRIGGERS` must be a subset of this
62
+ * enum's VALUES — `tests/unit/automationRulesCrud.test.ts` asserts it, which is
63
+ * the join obligation that replaces sharing one type between the two.
64
+ */
65
+ NotificationTypeEnum["REORDER_DUE"] = "REORDER_DUE";
50
66
  /**
51
67
  * A booking was confirmed, and its twin below when one is cancelled.
52
68
  *
@@ -244,9 +244,18 @@ declare global {
244
244
  * the two cannot drift apart silently.
245
245
  *
246
246
  * Widening is cheap and additive (same argument {@link CampaignChannel}
247
- * makes); having shipped a trigger nothing emits is not.
247
+ * makes); having shipped a trigger nothing emits is not. ⚠️ **So a member
248
+ * lands in the same change as the thing that emits it** — `REORDER_DUE`
249
+ * shipped with its cadence evaluator, and the next one owes the same.
250
+ *
251
+ * ⚠️ **DERIVED from {@link AUTOMATION_TRIGGERS}, and that direction is the
252
+ * fix rather than the style.** The two used to be declared separately with a
253
+ * one-way `satisfies`: a member added HERE and not to the tuple compiled
254
+ * clean, so the api's Zod enum and the configuration screen's picker would
255
+ * both have refused a value the published union promised. Edit the tuple,
256
+ * never this line.
248
257
  */
249
- type AutomationTrigger = 'ABANDONED_CART';
258
+ type AutomationTrigger = (typeof AUTOMATION_TRIGGERS)[number];
250
259
  /**
251
260
  * `'paused'` — authored, never fires. `'active'` — armed. `'archived'` —
252
261
  * retired, the terminal state (this domain ships no DELETE; see
@@ -401,6 +410,23 @@ declare global {
401
410
  * computed against, since the catalogue moves underneath it.
402
411
  */
403
412
  productIds?: string[];
413
+ /**
414
+ * Why a `'REORDER_DUE'` send arrived — the customer's own measured rhythm
415
+ * at the moment it was armed. Absent on every other trigger.
416
+ *
417
+ * ⚠️ **Stored rather than re-derived, and that is the whole reason it is
418
+ * on the row.** The derivation reads the customer's delivered-order
419
+ * history, which keeps moving: a support question asked a week later
420
+ * ("why did this person get a reminder?") cannot be answered by running
421
+ * the evaluator again, because the answer it gives is about today. This is
422
+ * also what lets the dispersion cut be recalibrated from real sends
423
+ * instead of from argument.
424
+ *
425
+ * ⚠️ **A SNAPSHOT, never a live figure.** It is not updated when the
426
+ * customer's rhythm changes, and nothing should read it as the customer's
427
+ * current cadence.
428
+ */
429
+ reorderContext?: ReorderCadence;
404
430
  /**
405
431
  * The order attributed to this send, if one was.
406
432
  *
@@ -518,8 +544,107 @@ declare global {
518
544
  /** Unix MILLISECONDS the figures were read at. */
519
545
  generatedAt: number;
520
546
  }
547
+ /**
548
+ * A customer's measured reorder rhythm, as the `'REORDER_DUE'` evaluator
549
+ * computed it — carried on {@link AutomationSend.reorderContext}.
550
+ *
551
+ * ⚠️ **The MEDIAN of the gaps, never the mean, and never a span mean.** One
552
+ * anomalous gap — a holiday, a bulk buy — drags a mean further than the
553
+ * jitter the reminder is trying to anticipate. A SPAN mean
554
+ * (`(last − first) / (n − 1)`) is worse still: it is blind to regularity, so
555
+ * deliveries on days 0/1/2/300 and on days 0/100/200/300 both return 100 and
556
+ * only one of those customers has a rhythm.
557
+ */
558
+ interface ReorderCadence {
559
+ /** The median gap between consecutive delivered orders, in DAYS. */
560
+ medianGapDays: number;
561
+ /**
562
+ * How many gaps the median was taken over — one fewer than the number of
563
+ * delivered orders read.
564
+ *
565
+ * ⚠️ At least **3** (four delivered orders) for a customer to qualify.
566
+ * Two gaps is enough for a central measure and not enough to tell whether
567
+ * the gaps AGREE, which is the question that separates a rhythm from a
568
+ * coincidence.
569
+ */
570
+ gapCount: number;
571
+ /** Unix MILLISECONDS of the delivery the due date was computed from. */
572
+ lastDeliveredAt: number;
573
+ }
521
574
  /** Look-back window for {@link CampaignEmailMetricsResponse}. */
522
575
  type CampaignEmailMetricWindow = '24h' | '7d' | '30d';
576
+ /**
577
+ * What one pass of the automation DUE sweep did — the body of its
578
+ * operator-facing `response()`.
579
+ *
580
+ * ⚠️ Published rather than declared in the handler because it reaches the
581
+ * wire: an operator surface reads these counters to answer "did the sweep
582
+ * run, and did it finish". Declared under `stacks/` a consumer's only
583
+ * options are to hand-copy the shape or lose it to `unknown`.
584
+ *
585
+ * ⚠️ **Deliberately NOT shared with {@link ReorderDueCronTotals}**, which
586
+ * carries a similar-looking set of counters for the other cron. The two
587
+ * measure different things — this one counts SENDS drained, that one counts
588
+ * CUSTOMERS evaluated — and unifying them would hand every consumer four
589
+ * fields that are absent on half the responses.
590
+ */
591
+ interface AutomationDueCronTotals {
592
+ /** Tenants visited this pass. */
593
+ stores: number;
594
+ /** The store roster hit its page bound, so some tenants went unvisited. */
595
+ rosterTruncated: boolean;
596
+ /** Due rows read. */
597
+ due: number;
598
+ /** Sends handed to the transport queue. */
599
+ enqueued: number;
600
+ /** Due rows withheld, each with its own recorded reason. */
601
+ skipped: number;
602
+ /**
603
+ * The pass reached the end of its work rather than stopping on its own
604
+ * clock reserve. ⚠️ `false` is NORMAL under load and is not an error — it
605
+ * means the next run resumes, which is why it is reported rather than
606
+ * inferred from the counters.
607
+ */
608
+ complete: boolean;
609
+ }
610
+ /**
611
+ * What one pass of the reorder-reminder EMITTER did — the body of its
612
+ * operator-facing `response()`.
613
+ *
614
+ * ⚠️ See {@link AutomationDueCronTotals} for why these are two types and not
615
+ * one.
616
+ */
617
+ interface ReorderDueCronTotals {
618
+ /** Tenants visited this pass. */
619
+ stores: number;
620
+ /**
621
+ * Of those, the few carrying an ACTIVE `'REORDER_DUE'` rule — the only
622
+ * ones whose deliveries are read at all. ⚠️ The gap between this and
623
+ * {@link ReorderDueCronTotals.stores} is the point of the counter: it is
624
+ * what shows the pass is cheap because most tenants are skipped, not
625
+ * because it is failing to find them.
626
+ */
627
+ storesWithRules: number;
628
+ /** The store roster hit its page bound, so some tenants went unvisited. */
629
+ rosterTruncated: boolean;
630
+ /** Customers whose delivery history was evaluated. */
631
+ candidates: number;
632
+ /** Candidates given a send dated at their own next gap. */
633
+ armed: number;
634
+ /**
635
+ * Candidates refused, for any reason in the evaluator's vocabulary —
636
+ * too few deliveries, gaps that do not agree, a history that could not be
637
+ * read. ⚠️ A high count here is the EXPECTED steady state, not a fault:
638
+ * most customers have no measurable rhythm.
639
+ */
640
+ ineligible: number;
641
+ /**
642
+ * The pass reached the end of its roster rather than stopping on its own
643
+ * clock reserve. ⚠️ `false` is normal and means the next daily run picks
644
+ * up where this one stopped.
645
+ */
646
+ complete: boolean;
647
+ }
523
648
  }
524
649
  /**
525
650
  * The {@link AutomationTrigger} vocabulary as a RUNTIME value, so the api's Zod
@@ -527,11 +652,21 @@ declare global {
527
652
  * from ONE list instead of three copies that drift. Same shape and same reason
528
653
  * as `STOCK_ADJUSTMENT_REASONS` in `contracts/src/stock.ts`.
529
654
  *
530
- * `satisfies` is what keeps the two in step in BOTH directions: a member added
531
- * to the union and not here compiles (the tuple is still assignable), but a
532
- * member added HERE and not to the union does not.
655
+ * ⚠️ **This tuple is the SOURCE and {@link AutomationTrigger} is derived from
656
+ * it**, so there is only one direction to get wrong and it does not exist. It
657
+ * used to be the other way round — the union declared separately and this tuple
658
+ * merely `satisfies`-checked against it — which caught a member added here and
659
+ * missing from the union, and silently allowed the reverse. That reverse is the
660
+ * damaging one: the published union would promise a trigger the api's Zod enum
661
+ * rejects and the picker never offers.
662
+ *
663
+ * ⚠️ **`REORDER_DUE` is the reorder-reminder trigger**, emitted by the daily
664
+ * cadence sweep from a customer's own delivery rhythm — never a fixed interval.
665
+ * Adding a member here is additive for a reader and a WIDENING for anything
666
+ * exhaustive over it: a `Record<AutomationTrigger, …>` fails to compile until it
667
+ * is handled, which is the point.
533
668
  */
534
- export declare const AUTOMATION_TRIGGERS: readonly ["ABANDONED_CART"];
669
+ export declare const AUTOMATION_TRIGGERS: readonly ["ABANDONED_CART", "REORDER_DUE"];
535
670
  /**
536
671
  * How long after a send an order may still be attributed to it, in HOURS.
537
672
  *
package/dist/marketing.js CHANGED
@@ -4,11 +4,21 @@
4
4
  * from ONE list instead of three copies that drift. Same shape and same reason
5
5
  * as `STOCK_ADJUSTMENT_REASONS` in `contracts/src/stock.ts`.
6
6
  *
7
- * `satisfies` is what keeps the two in step in BOTH directions: a member added
8
- * to the union and not here compiles (the tuple is still assignable), but a
9
- * member added HERE and not to the union does not.
7
+ * ⚠️ **This tuple is the SOURCE and {@link AutomationTrigger} is derived from
8
+ * it**, so there is only one direction to get wrong and it does not exist. It
9
+ * used to be the other way round — the union declared separately and this tuple
10
+ * merely `satisfies`-checked against it — which caught a member added here and
11
+ * missing from the union, and silently allowed the reverse. That reverse is the
12
+ * damaging one: the published union would promise a trigger the api's Zod enum
13
+ * rejects and the picker never offers.
14
+ *
15
+ * ⚠️ **`REORDER_DUE` is the reorder-reminder trigger**, emitted by the daily
16
+ * cadence sweep from a customer's own delivery rhythm — never a fixed interval.
17
+ * Adding a member here is additive for a reader and a WIDENING for anything
18
+ * exhaustive over it: a `Record<AutomationTrigger, …>` fails to compile until it
19
+ * is handled, which is the point.
10
20
  */
11
- export const AUTOMATION_TRIGGERS = ['ABANDONED_CART'];
21
+ export const AUTOMATION_TRIGGERS = ['ABANDONED_CART', 'REORDER_DUE'];
12
22
  /**
13
23
  * How long after a send an order may still be attributed to it, in HOURS.
14
24
  *
@@ -27,6 +27,22 @@ export declare enum NotificationTypeEnum {
27
27
  * fails silently.
28
28
  */
29
29
  ABANDONED_CART = "ABANDONED_CART",
30
+ /**
31
+ * A customer whose own delivery rhythm says they are due to reorder.
32
+ *
33
+ * ⚠️ Additive, on the same grounds as `ABANDONED_CART`.
34
+ *
35
+ * ⚠️ **This is the OPERATOR-facing fact, not the customer's reminder.** "This
36
+ * customer is due to reorder" is something a shop legitimately wants told; the
37
+ * message the customer receives is the automation's business and its opt-out
38
+ * is `Customer.marketing`, never a staff preference. That is the same split
39
+ * that makes `ABANDONED_CART` legal here and keeps `APPOINTMENT_REMINDER` out.
40
+ *
41
+ * ⚠️ The member exists because `AUTOMATION_TRIGGERS` must be a subset of this
42
+ * enum's VALUES — `tests/unit/automationRulesCrud.test.ts` asserts it, which is
43
+ * the join obligation that replaces sharing one type between the two.
44
+ */
45
+ REORDER_DUE = "REORDER_DUE",
30
46
  /**
31
47
  * A booking was confirmed, and its twin below when one is cancelled.
32
48
  *
@@ -44,6 +44,22 @@ export var NotificationTypeEnum;
44
44
  * fails silently.
45
45
  */
46
46
  NotificationTypeEnum["ABANDONED_CART"] = "ABANDONED_CART";
47
+ /**
48
+ * A customer whose own delivery rhythm says they are due to reorder.
49
+ *
50
+ * ⚠️ Additive, on the same grounds as `ABANDONED_CART`.
51
+ *
52
+ * ⚠️ **This is the OPERATOR-facing fact, not the customer's reminder.** "This
53
+ * customer is due to reorder" is something a shop legitimately wants told; the
54
+ * message the customer receives is the automation's business and its opt-out
55
+ * is `Customer.marketing`, never a staff preference. That is the same split
56
+ * that makes `ABANDONED_CART` legal here and keeps `APPOINTMENT_REMINDER` out.
57
+ *
58
+ * ⚠️ The member exists because `AUTOMATION_TRIGGERS` must be a subset of this
59
+ * enum's VALUES — `tests/unit/automationRulesCrud.test.ts` asserts it, which is
60
+ * the join obligation that replaces sharing one type between the two.
61
+ */
62
+ NotificationTypeEnum["REORDER_DUE"] = "REORDER_DUE";
47
63
  /**
48
64
  * A booking was confirmed, and its twin below when one is cancelled.
49
65
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinfactura-types",
3
- "version": "1.10.280",
3
+ "version": "1.10.281",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",