sinfactura-types 1.10.306 → 1.10.307

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AUTOMATION_RULE_STATUSES = exports.AUTOMATION_SEND_STATUSES = exports.ATTRIBUTION_WINDOW_HOURS = exports.AUTOMATION_TRIGGERS = void 0;
3
+ exports.AUTOMATION_RULE_STATUSES = exports.AUTOMATION_SEND_STATUSES = exports.ATTRIBUTION_WINDOW_HOURS = exports.RFM_SEGMENT_LABELS = exports.AUTOMATION_TRIGGERS = void 0;
4
4
  /**
5
5
  * The {@link AutomationTrigger} vocabulary as a RUNTIME value, so the api's Zod
6
6
  * enum, the configuration screen's picker and the published union all derive
@@ -22,6 +22,26 @@ exports.AUTOMATION_RULE_STATUSES = exports.AUTOMATION_SEND_STATUSES = exports.AT
22
22
  * is handled, which is the point.
23
23
  */
24
24
  exports.AUTOMATION_TRIGGERS = ['ABANDONED_CART', 'REORDER_DUE'];
25
+ /**
26
+ * {@link RfmSegmentLabel} as a runtime value, so `isSegmentRuleValid`
27
+ * (`stacks/services/segments.ts`) and the nightly scoring pass
28
+ * (`stacks/lambdas/rfmSegmentationCron`) validate/emit against ONE list rather
29
+ * than a second hand-typed copy that can drift from the published union.
30
+ *
31
+ * `as const satisfies readonly RfmSegmentLabel[]` — the type is the source and
32
+ * this tuple is checked against it, the same direction
33
+ * {@link AUTOMATION_SEND_STATUSES} takes below and the OPPOSITE of
34
+ * {@link AUTOMATION_TRIGGERS} above; either direction catches a member added to
35
+ * one side and missing from the other, so which one is source is a style
36
+ * choice here, not a correctness one.
37
+ */
38
+ exports.RFM_SEGMENT_LABELS = [
39
+ 'champions',
40
+ 'loyal',
41
+ 'at-risk',
42
+ 'lost',
43
+ 'new',
44
+ ];
25
45
  /**
26
46
  * How long after a send an order may still be attributed to it, in HOURS.
27
47
  *
package/dist/cjs/wire.js CHANGED
@@ -18,7 +18,7 @@
18
18
  * describes the result in the same edit.
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.ROW_TTL_KEYS = exports.USER_TOTP_INTERNAL_KEYS = exports.STORE_WHATSAPP_SECRET_KEYS = exports.STORE_MERCADOLIBRE_SECRET_KEYS = exports.STORE_GMAIL_SECRET_KEYS = exports.STORE_MP_SECRET_KEYS = exports.STORE_AFIP_SECRET_KEYS = exports.RESPONSE_STRIPPED_KEYS = void 0;
21
+ exports.ROW_TTL_KEYS = exports.USER_TOTP_INTERNAL_KEYS = exports.STORE_TIENDANUBE_SECRET_KEYS = exports.STORE_WHATSAPP_SECRET_KEYS = exports.STORE_MERCADOLIBRE_SECRET_KEYS = exports.STORE_GMAIL_SECRET_KEYS = exports.STORE_MP_SECRET_KEYS = exports.STORE_AFIP_SECRET_KEYS = exports.RESPONSE_STRIPPED_KEYS = void 0;
22
22
  /**
23
23
  * The seven keys `response()` deletes from `body.data`.
24
24
  *
@@ -67,6 +67,12 @@ exports.STORE_MERCADOLIBRE_SECRET_KEYS = [
67
67
  ];
68
68
  /** WhatsApp's only secret field on `Store.integrations.whatsapp`. */
69
69
  exports.STORE_WHATSAPP_SECRET_KEYS = ['accessToken'];
70
+ /**
71
+ * KMS-ciphertext TiendaNube OAuth credential on `Store.integrations.tiendanube`.
72
+ * A single `accessTokenEncrypted` — TiendaNube issues no refresh token, so there
73
+ * is no sibling to strip alongside it (contrast {@link STORE_GMAIL_SECRET_KEYS}).
74
+ */
75
+ exports.STORE_TIENDANUBE_SECRET_KEYS = ['accessTokenEncrypted'];
70
76
  /**
71
77
  * The TOTP sub-keys `sanitizeUserRow` drops from `User.totp` before a USER row
72
78
  * crosses any wire.
@@ -172,6 +172,45 @@ declare global {
172
172
  favorites?: Partial<Product>[];
173
173
  fullName: string;
174
174
  lastBuy?: number;
175
+ /**
176
+ * The preset RFM label a nightly per-store pass last computed for this
177
+ * customer (`stacks/lambdas/rfmSegmentationCron`) — see
178
+ * `docs/MARKETING.md` § Behaviour contract for the R/F/M → segment mapping.
179
+ * The `SegmentField: 'rfmSegment'` rule evaluator reads this field
180
+ * VERBATIM, as a plain `eq`/`ne` string compare, and never recomputes a
181
+ * quintile itself.
182
+ *
183
+ * ⚠️ ABSENT MEANS UNSCORED, never a default bucket. Three cases all clear
184
+ * (never merely leave stale) this field rather than defaulting it: the
185
+ * customer had no order in the run's 365-day window, the issuing store's
186
+ * population that pass fell below the 5-distinct-buyer quintile floor, or
187
+ * the customer's own R/F/M combination matched none of the five presets.
188
+ * A reader must not treat absence as "Lost" or any other bucket.
189
+ *
190
+ * ⚠️ Forward-only, like every stamped field in this repo — a row predating
191
+ * this pass carries no attribute, and nothing backfills it; it is stamped
192
+ * only from the customer's first nightly pass onward.
193
+ */
194
+ rfmSegment?: RfmSegmentLabel;
195
+ /**
196
+ * ms epoch the nightly RFM pass last STAMPED a label for this customer —
197
+ * present IF AND ONLY IF {@link Customer.rfmSegment} is present, the same
198
+ * pairing `Product.abcClassifiedAt` keeps with `Product.abcClass`: both are
199
+ * SET together when a pass assigns a preset, and both are REMOVED together
200
+ * the moment a later pass no longer can (no order in the window, the
201
+ * store's population fell below the 5-buyer quintile floor, or the
202
+ * customer's own R/F/M combination now matches none of the five presets).
203
+ * There is no "scored but unassigned, with a timestamp" state.
204
+ *
205
+ * ⚠️ An UNCHANGED label is still re-stamped on every pass that assigns one,
206
+ * exactly as `abcClassifiedAt` is — so the most stable customers do not
207
+ * read as the stalest simply because their segment never moves.
208
+ *
209
+ * ⚠️ Absence means "never assigned a label, or a later pass cleared one" —
210
+ * never a default bucket, and never "unscored forever" on a row this field
211
+ * has not reached yet (forward-only; no backfill).
212
+ */
213
+ rfmScoredAt?: number;
175
214
  lastLog?: number;
176
215
  /**
177
216
  * ms epoch of the last COLLECTIONS chase, so the accounts report can show
@@ -135,34 +135,58 @@ declare global {
135
135
  /**
136
136
  * `within` / `olderThan` take a POSITIVE INTEGER NUMBER OF DAYS measured from
137
137
  * the evaluation instant (`lastBuy within 90` = bought in the last 90 days);
138
- * a stored `90` has always meant days. `includes` is RESERVED — every
139
- * `SegmentField` is a number or a boolean today, the handler refuses it on
140
- * write, and a string/array field lands together with it or not at all.
141
- * Absent fields: two DEFAULTS, seven NO-MATCH. An absent `marketing.*`
138
+ * a stored `90` has always meant days. `includes` is STILL RESERVED, for a
139
+ * future ARRAY field — `rfmSegment` is the first STRING `SegmentField` and it
140
+ * ships with `eq`/`ne` only, so "a string field lands together with `includes`
141
+ * or not at all" no longer holds and must not be inferred from its presence.
142
+ * Absent fields: two DEFAULTS, eight NO-MATCH. An absent `marketing.*`
142
143
  * channel and an absent `disabled` read as `false` (absence is never consent,
143
144
  * and a missing `disabled` is a live customer) — so `eq false` matches them
144
- * and `eq true` never can. `balance`, `creditLimit` and `lastBuy` absent match
145
- * NO comparison at all, `ne` included (no `creditLimit` is "no ceiling", not
146
- * zero).
145
+ * and `eq true` never can. `balance`, `creditLimit`, `lastBuy` and
146
+ * `rfmSegment` absent match NO comparison at all, `ne` included (no
147
+ * `creditLimit` is "no ceiling", not zero; a customer never scored — or
148
+ * excluded from a pass's quintile ranking — is not the same as matching
149
+ * `rfmSegment ne 'champions'`).
147
150
  */
148
151
  type SegmentOperator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'within' | 'olderThan' | 'includes';
152
+ /**
153
+ * Preset label a nightly RFM pass stamps onto a `Customer` row
154
+ * (`Customer.rfmSegment`) — see `docs/MARKETING.md` § Behaviour contract for
155
+ * the exact R/F/M → segment mapping and the 365-day store-relative quintile
156
+ * pass (`stacks/lambdas/rfmSegmentationCron`) that computes it. Closed for the
157
+ * same reason `SegmentField` itself is: a typo'd label would compile, store,
158
+ * and match nobody forever.
159
+ *
160
+ * ⚠️ Lowercase and hyphenated — NOT the Title Case the mapping table uses in
161
+ * prose ("Champions", "At-Risk"). This is the WIRE value a stored segment
162
+ * rule and the stamped `Customer` row both compare; it is fixed here rather
163
+ * than derived from any display string.
164
+ */
165
+ type RfmSegmentLabel = 'champions' | 'loyal' | 'at-risk' | 'lost' | 'new';
149
166
  /**
150
167
  * What a segment rule may target. Closed deliberately: an open `string`
151
168
  * would be the same unversioned escape hatch as an untyped criteria object,
152
169
  * just spread across three fields — a typo'd field name would compile, store,
153
170
  * and silently match zero customers forever.
154
171
  *
155
- * ⚠️ Limited to what is queryable on `Customer` TODAY. No product or order
156
- * predicates ("bought category X"), because no domain logic exists to
157
- * evaluate them — a v1 boundary, not an oversight.
172
+ * ⚠️ Limited to what is queryable on `Customer` TODAY. No LIVE product or
173
+ * order predicates ("bought category X"), because no domain logic exists to
174
+ * evaluate one at rule-evaluation time — a v1 boundary, not an oversight.
175
+ * `rfmSegment` does not reopen this: it targets a label a nightly job already
176
+ * PRECOMPUTED and stamped, so evaluating the rule still costs nothing but an
177
+ * `eq`/`ne` string compare.
158
178
  *
159
- * ⚠️ RFM (`recency` / `frequency` / `monetary`) is deliberately ABSENT. It
160
- * has no evaluator, and reserving a word costs nothing to defer while
161
- * shipping it costs a stored segment whose meaning is undefined until
162
- * somebody picks semantics — at which point every stored row silently
163
- * changes meaning. Adding a member is a patch bump; un-defining one is not.
179
+ * ⚠️ RFM (`recency` / `frequency` / `monetary`) is no longer absent, and
180
+ * `rfmSegment` is the whole of what shipped: ONE member, targeting the
181
+ * five-way {@link RfmSegmentLabel} preset — never the raw `recency` /
182
+ * `frequency` / `monetary` numbers or their 1–5 quintile scores. Exposing
183
+ * those as filterable fields would let a stored segment silently reprice
184
+ * itself the day the platform's cut-points move; a label is a stamped fact
185
+ * about a specific nightly pass, so a stored `rfmSegment eq 'champions'` rule
186
+ * keeps meaning the same thing on every future evaluation because the PASS —
187
+ * never the rule — owns the mapping.
164
188
  */
165
- type SegmentField = 'balance' | 'creditLimit' | 'lastBuy' | 'disabled' | 'marketing.adds' | 'marketing.email' | 'marketing.phone' | 'marketing.sms' | 'marketing.whatsapp';
189
+ type SegmentField = 'balance' | 'creditLimit' | 'lastBuy' | 'disabled' | 'marketing.adds' | 'marketing.email' | 'marketing.phone' | 'marketing.sms' | 'marketing.whatsapp' | 'rfmSegment';
166
190
  /**
167
191
  * ⚠️ The type cannot express which operators suit which field — `disabled`
168
192
  * with `gt` compiles. The handler validates the pairing; the type only bounds
@@ -667,6 +691,20 @@ declare global {
667
691
  * is handled, which is the point.
668
692
  */
669
693
  export declare const AUTOMATION_TRIGGERS: readonly ["ABANDONED_CART", "REORDER_DUE"];
694
+ /**
695
+ * {@link RfmSegmentLabel} as a runtime value, so `isSegmentRuleValid`
696
+ * (`stacks/services/segments.ts`) and the nightly scoring pass
697
+ * (`stacks/lambdas/rfmSegmentationCron`) validate/emit against ONE list rather
698
+ * than a second hand-typed copy that can drift from the published union.
699
+ *
700
+ * `as const satisfies readonly RfmSegmentLabel[]` — the type is the source and
701
+ * this tuple is checked against it, the same direction
702
+ * {@link AUTOMATION_SEND_STATUSES} takes below and the OPPOSITE of
703
+ * {@link AUTOMATION_TRIGGERS} above; either direction catches a member added to
704
+ * one side and missing from the other, so which one is source is a style
705
+ * choice here, not a correctness one.
706
+ */
707
+ export declare const RFM_SEGMENT_LABELS: readonly ["champions", "loyal", "at-risk", "lost", "new"];
670
708
  /**
671
709
  * How long after a send an order may still be attributed to it, in HOURS.
672
710
  *
package/dist/marketing.js CHANGED
@@ -19,6 +19,26 @@
19
19
  * is handled, which is the point.
20
20
  */
21
21
  export const AUTOMATION_TRIGGERS = ['ABANDONED_CART', 'REORDER_DUE'];
22
+ /**
23
+ * {@link RfmSegmentLabel} as a runtime value, so `isSegmentRuleValid`
24
+ * (`stacks/services/segments.ts`) and the nightly scoring pass
25
+ * (`stacks/lambdas/rfmSegmentationCron`) validate/emit against ONE list rather
26
+ * than a second hand-typed copy that can drift from the published union.
27
+ *
28
+ * `as const satisfies readonly RfmSegmentLabel[]` — the type is the source and
29
+ * this tuple is checked against it, the same direction
30
+ * {@link AUTOMATION_SEND_STATUSES} takes below and the OPPOSITE of
31
+ * {@link AUTOMATION_TRIGGERS} above; either direction catches a member added to
32
+ * one side and missing from the other, so which one is source is a style
33
+ * choice here, not a correctness one.
34
+ */
35
+ export const RFM_SEGMENT_LABELS = [
36
+ 'champions',
37
+ 'loyal',
38
+ 'at-risk',
39
+ 'lost',
40
+ 'new',
41
+ ];
22
42
  /**
23
43
  * How long after a send an order may still be attributed to it, in HOURS.
24
44
  *
package/dist/store.d.ts CHANGED
@@ -689,6 +689,7 @@ declare global {
689
689
  sms?: SmsIntegration;
690
690
  gmail?: Gmail;
691
691
  mercadolibre?: Mercadolibre;
692
+ tiendanube?: Tiendanube;
692
693
  }
693
694
  interface SmsIntegration {
694
695
  /** When true, the store may send SMS through the shared platform account. */
@@ -865,6 +866,29 @@ declare global {
865
866
  */
866
867
  settlementCheckpoint?: number;
867
868
  }
869
+ type TiendanubeConnectionStatus = 'connected' | 'disconnected' | 'error' | 'never';
870
+ /**
871
+ * `Store.integrations.tiendanube` — the connect-slice leaf only (product
872
+ * catalog sync, order import, customer sync, fulfilment and webhook
873
+ * ingestion are each their own future ticket; see api's TiendaNube OAuth
874
+ * connect issue). Unlike {@link Mercadopago}/{@link Mercadolibre}/{@link Gmail},
875
+ * there is no `expiresAt`/`lastTokenRefreshAt`/`tokenRefreshFailures` triad:
876
+ * TiendaNube's OAuth access token does not expire and TiendaNube issues no
877
+ * refresh token, so there is nothing to refresh and nothing to expire.
878
+ */
879
+ interface Tiendanube {
880
+ /**
881
+ * TiendaNube's own store id (`user_id` on the token-exchange response),
882
+ * stringified for the same precision-safety reason as
883
+ * {@link Mercadopago.userId} / {@link Mercadolibre.userId}. This is what
884
+ * the connect screen renders as the linked TiendaNube store.
885
+ */
886
+ tiendanubeStoreId?: string;
887
+ connected?: boolean;
888
+ connectedAt?: number;
889
+ status?: TiendanubeConnectionStatus;
890
+ disconnectedAt?: number;
891
+ }
868
892
  /**
869
893
  * Wire/write shape for `mercadolibre.syncPolicy` accepted by `PATCH /store` —
870
894
  * distinct from the read-side `Mercadolibre['syncPolicy']` because each knob
package/dist/wire.d.ts CHANGED
@@ -44,6 +44,12 @@ export declare const STORE_GMAIL_SECRET_KEYS: readonly ["refreshTokenEncrypted",
44
44
  export declare const STORE_MERCADOLIBRE_SECRET_KEYS: readonly ["accessTokenEncrypted", "refreshTokenEncrypted", "refreshAttemptAt"];
45
45
  /** WhatsApp's only secret field on `Store.integrations.whatsapp`. */
46
46
  export declare const STORE_WHATSAPP_SECRET_KEYS: readonly ["accessToken"];
47
+ /**
48
+ * KMS-ciphertext TiendaNube OAuth credential on `Store.integrations.tiendanube`.
49
+ * A single `accessTokenEncrypted` — TiendaNube issues no refresh token, so there
50
+ * is no sibling to strip alongside it (contrast {@link STORE_GMAIL_SECRET_KEYS}).
51
+ */
52
+ export declare const STORE_TIENDANUBE_SECRET_KEYS: readonly ["accessTokenEncrypted"];
47
53
  /**
48
54
  * The TOTP sub-keys `sanitizeUserRow` drops from `User.totp` before a USER row
49
55
  * crosses any wire.
@@ -89,6 +95,8 @@ declare global {
89
95
  type StoreMercadolibreSecretKey = (typeof STORE_MERCADOLIBRE_SECRET_KEYS)[number];
90
96
  /** The one credential key stripped from `Store.integrations.whatsapp` before it crosses a wire. */
91
97
  type StoreWhatsappSecretKey = (typeof STORE_WHATSAPP_SECRET_KEYS)[number];
98
+ /** The one KMS-ciphertext key stripped from `Store.integrations.tiendanube` before it crosses a wire. */
99
+ type StoreTiendanubeSecretKey = (typeof STORE_TIENDANUBE_SECRET_KEYS)[number];
92
100
  /** A TOTP sub-key stripped from `User.totp` before a USER row crosses a wire. */
93
101
  type UserTotpInternalKey = (typeof USER_TOTP_INTERNAL_KEYS)[number];
94
102
  /** The DynamoDB housekeeping key stripped per entity at the read projection. */
package/dist/wire.js CHANGED
@@ -64,6 +64,12 @@ export const STORE_MERCADOLIBRE_SECRET_KEYS = [
64
64
  ];
65
65
  /** WhatsApp's only secret field on `Store.integrations.whatsapp`. */
66
66
  export const STORE_WHATSAPP_SECRET_KEYS = ['accessToken'];
67
+ /**
68
+ * KMS-ciphertext TiendaNube OAuth credential on `Store.integrations.tiendanube`.
69
+ * A single `accessTokenEncrypted` — TiendaNube issues no refresh token, so there
70
+ * is no sibling to strip alongside it (contrast {@link STORE_GMAIL_SECRET_KEYS}).
71
+ */
72
+ export const STORE_TIENDANUBE_SECRET_KEYS = ['accessTokenEncrypted'];
67
73
  /**
68
74
  * The TOTP sub-keys `sanitizeUserRow` drops from `User.totp` before a USER row
69
75
  * crosses any wire.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinfactura-types",
3
- "version": "1.10.306",
3
+ "version": "1.10.307",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",