sinfactura-types 1.10.370 → 1.10.372

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.
@@ -4,3 +4,53 @@
4
4
  // per-tenant override use case identified for globals/flags (deliberate
5
5
  // divergence from the Literals model).
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ML_ORDER_RECONCILE_SUMMARY_KEYS = exports.INTEGRATION_EVENT_OUTCOMES = exports.INTEGRATION_EVENT_TYPES = void 0;
8
+ // ── Integration events log — the rows both read endpoints return ─────────
9
+ //
10
+ // `GET /platform/integrations/{provider}/events` (MANAGER, every tenant) and
11
+ // `GET /mercadolibre/events` (ADMIN, the caller's own store only) project the
12
+ // same stored row through ONE allow-list (`projectIntegrationEvent` in the
13
+ // api's integration-events service). Nothing else on the stored row reaches
14
+ // the wire: it can carry replay metadata, dedupe keys and the TTL.
15
+ /**
16
+ * Every persisted integration-event type. The read endpoints' `type` filters
17
+ * derive from this tuple, and so does the union below — three hand-kept
18
+ * copies of this list had already drifted apart once.
19
+ *
20
+ * ⚠️ It widens server-side. A consumer keying a lookup on it must fall back on
21
+ * an unknown value rather than assume the union is total.
22
+ */
23
+ exports.INTEGRATION_EVENT_TYPES = [
24
+ 'webhook',
25
+ 'token-refresh',
26
+ 'oauth-callback',
27
+ // Outbound marketplace pushes. Kept split by kind rather than folded into
28
+ // one `sync-push`: stock and price have independent retry budgets and
29
+ // independent pause controls, so an operator filtering the log almost
30
+ // always wants one or the other, never both.
31
+ 'stock-push',
32
+ 'price-push',
33
+ // Written by TWO sweeps, told apart by `provider` (see `IntegrationEvent`):
34
+ // MercadoLibre's order reconciliation (one summary row per run) and the
35
+ // read-only MercadoPago reconciliation (one row per settled payment this
36
+ // system holds no record of — a report, never a repair).
37
+ 'reconcile-sweep',
38
+ ];
39
+ /** Same drift risk as `INTEGRATION_EVENT_TYPES`, same fix. */
40
+ exports.INTEGRATION_EVENT_OUTCOMES = ['success', 'failure', 'retry', 'skipped'];
41
+ /**
42
+ * The keys of `MlOrderReconcileSummary`, as the runtime tuple the projection
43
+ * copies off a MercadoLibre `reconcile-sweep` row. A compile-time assertion
44
+ * pins it to the interface, so a field added to the summary without being
45
+ * added here fails `typecheck` instead of being dropped on the wire.
46
+ */
47
+ exports.ML_ORDER_RECONCILE_SUMMARY_KEYS = [
48
+ 'trigger',
49
+ 'window',
50
+ 'scanned',
51
+ 'created',
52
+ 'updated',
53
+ 'skippedPreConnect',
54
+ 'truncated',
55
+ 'jobId',
56
+ ];
@@ -1,3 +1,4 @@
1
+ import type { IntegrationEvent } from './platform.ts';
1
2
  declare global {
2
3
  interface MlOauthInitiateResponse {
3
4
  authorizationUrl: string;
@@ -117,8 +118,10 @@ declare global {
117
118
  /**
118
119
  * BE → FE `202` of `POST /mercadolibre/orders/sync`. The run is ASYNC (a
119
120
  * multi-page `orders/search` walk with 429 back-off does not fit the API's
120
- * 29 s cap); its outcome lands as one `MlOrderReconcileSummary` row in the
121
- * store's integration events log, tagged with this `jobId`.
121
+ * 29 s cap); its outcome lands as one `MlReconcileSweepEvent` row in the
122
+ * store's integration events log, carrying this `jobId`. Read it from
123
+ * `GET /mercadolibre/events?type=reconcile-sweep` and match on `jobId`; the
124
+ * row's `scanned` / `created` / `updated` are the run's result.
122
125
  */
123
126
  interface MlOrdersSyncResponse {
124
127
  jobId: string;
@@ -155,6 +158,29 @@ declare global {
155
158
  truncated?: boolean;
156
159
  jobId?: string;
157
160
  }
161
+ /**
162
+ * One row of `GET /mercadolibre/events` — the caller's own store only, so
163
+ * `storeId` is always the caller's. The platform row plus `topic` (the ML
164
+ * notification topic, or `'credit-note-manual'`) and `retryable`, which
165
+ * says whether `POST /mercadolibre/events { mode: 'retry' }` accepts the row.
166
+ * Narrow on `type === 'reconcile-sweep'` to read the reconciliation summary
167
+ * (`MlReconcileSweepEvent`): this endpoint only ever returns MercadoLibre rows.
168
+ */
169
+ type MlIntegrationEvent = Exclude<IntegrationEvent, {
170
+ provider: 'mercadopago';
171
+ }> & {
172
+ topic?: string;
173
+ retryable: boolean;
174
+ };
175
+ /**
176
+ * `GET /mercadolibre/events` — newest first, no `message`. `truncated` marks
177
+ * a page walk that stopped on its budget.
178
+ */
179
+ interface MlIntegrationEventsResponse {
180
+ data: MlIntegrationEvent[];
181
+ nextCursor?: string;
182
+ truncated?: boolean;
183
+ }
158
184
  /**
159
185
  * `errorCode` of the row written for each notification re-enqueued by the
160
186
  * reconnect replay (`storeId` set, so the tenant log shows what was
@@ -189,5 +215,24 @@ declare global {
189
215
  disconnected: true;
190
216
  storeId: string;
191
217
  }
218
+ interface MercadolibreStatus {
219
+ connected: boolean;
220
+ status: MercadolibreConnectionStatus;
221
+ userId?: string;
222
+ nickname?: string;
223
+ connectedAt?: number;
224
+ expiresAt?: number;
225
+ syncPolicy?: Mercadolibre['syncPolicy'];
226
+ health?: MercadolibreHealth;
227
+ }
228
+ type MercadolibreHealthReason = 'token-unusable' | 'routing-mismatch' | 'ingestion-dropped' | 'recovery-sweep-failing' | 'no-recent-events';
229
+ type MercadolibreHealthState = 'ok' | 'degraded' | 'broken';
230
+ interface MercadolibreHealth {
231
+ state: MercadolibreHealthState;
232
+ reasons: MercadolibreHealthReason[];
233
+ lastEventAt?: number;
234
+ lastDroppedAt?: number;
235
+ checkedAt: number;
236
+ }
192
237
  }
193
238
  export {};
@@ -845,4 +845,64 @@ export interface PlatformMetricsSnapshot {
845
845
  sessions: PlatformSessionMetrics | null;
846
846
  generatedAt: number;
847
847
  }
848
+ /**
849
+ * Every persisted integration-event type. The read endpoints' `type` filters
850
+ * derive from this tuple, and so does the union below — three hand-kept
851
+ * copies of this list had already drifted apart once.
852
+ *
853
+ * ⚠️ It widens server-side. A consumer keying a lookup on it must fall back on
854
+ * an unknown value rather than assume the union is total.
855
+ */
856
+ export declare const INTEGRATION_EVENT_TYPES: readonly ["webhook", "token-refresh", "oauth-callback", "stock-push", "price-push", "reconcile-sweep"];
857
+ export type IntegrationEventType = (typeof INTEGRATION_EVENT_TYPES)[number];
858
+ /** Same drift risk as `INTEGRATION_EVENT_TYPES`, same fix. */
859
+ export declare const INTEGRATION_EVENT_OUTCOMES: readonly ["success", "failure", "retry", "skipped"];
860
+ export type IntegrationEventOutcome = (typeof INTEGRATION_EVENT_OUTCOMES)[number];
861
+ /**
862
+ * The keys of `MlOrderReconcileSummary`, as the runtime tuple the projection
863
+ * copies off a MercadoLibre `reconcile-sweep` row. A compile-time assertion
864
+ * pins it to the interface, so a field added to the summary without being
865
+ * added here fails `typecheck` instead of being dropped on the wire.
866
+ */
867
+ export declare const ML_ORDER_RECONCILE_SUMMARY_KEYS: readonly ["trigger", "window", "scanned", "created", "updated", "skippedPreConnect", "truncated", "jobId"];
868
+ /** Fields every integration-event row carries, whatever its type. */
869
+ interface IntegrationEventCommon {
870
+ id: string;
871
+ /** Unix ms. */
872
+ ts: number;
873
+ provider: string;
874
+ outcome: IntegrationEventOutcome;
875
+ /** Absent on a row no store could be attributed to (an ML `unknown-seller` drop). */
876
+ storeId?: string;
877
+ durationMs: number;
878
+ errorCode?: string;
879
+ /** Truncated to 256 characters at write time. */
880
+ errorMessage?: string;
881
+ payloadSize?: number;
882
+ }
883
+ /**
884
+ * One MercadoLibre order-reconciliation run: the `MlOrderReconcileSummary` the
885
+ * run wrote, returned top-level beside the common fields. Match it to a
886
+ * `POST /mercadolibre/orders/sync` by `jobId`.
887
+ *
888
+ * ⚠️ `truncated` here is the RUN's budget stop (its counts cover only what was
889
+ * walked) — unrelated to the `truncated` flag beside `data` on the
890
+ * `GET /mercadolibre/events` envelope, which is the page walk's.
891
+ */
892
+ export type MlReconcileSweepEvent = IntegrationEventCommon & MlOrderReconcileSummary & {
893
+ provider: 'mercadolibre';
894
+ type: 'reconcile-sweep';
895
+ };
896
+ /**
897
+ * One row of `GET /platform/integrations/{provider}/events`. Discriminate on
898
+ * `type`, then on `provider` for `'reconcile-sweep'`: only MercadoLibre's
899
+ * sweep row carries the summary; MercadoPago's states its finding in
900
+ * `errorCode` / `errorMessage` and nothing else.
901
+ */
902
+ export type IntegrationEvent = (IntegrationEventCommon & {
903
+ type: Exclude<IntegrationEventType, 'reconcile-sweep'>;
904
+ }) | MlReconcileSweepEvent | (IntegrationEventCommon & {
905
+ provider: 'mercadopago';
906
+ type: 'reconcile-sweep';
907
+ });
848
908
  export {};
package/dist/platform.js CHANGED
@@ -2,4 +2,52 @@
2
2
  // GLOBALS/PLATFORM scope, unlike Literals' multi-scope override chain — no
3
3
  // per-tenant override use case identified for globals/flags (deliberate
4
4
  // divergence from the Literals model).
5
- export {};
5
+ // ── Integration events log — the rows both read endpoints return ─────────
6
+ //
7
+ // `GET /platform/integrations/{provider}/events` (MANAGER, every tenant) and
8
+ // `GET /mercadolibre/events` (ADMIN, the caller's own store only) project the
9
+ // same stored row through ONE allow-list (`projectIntegrationEvent` in the
10
+ // api's integration-events service). Nothing else on the stored row reaches
11
+ // the wire: it can carry replay metadata, dedupe keys and the TTL.
12
+ /**
13
+ * Every persisted integration-event type. The read endpoints' `type` filters
14
+ * derive from this tuple, and so does the union below — three hand-kept
15
+ * copies of this list had already drifted apart once.
16
+ *
17
+ * ⚠️ It widens server-side. A consumer keying a lookup on it must fall back on
18
+ * an unknown value rather than assume the union is total.
19
+ */
20
+ export const INTEGRATION_EVENT_TYPES = [
21
+ 'webhook',
22
+ 'token-refresh',
23
+ 'oauth-callback',
24
+ // Outbound marketplace pushes. Kept split by kind rather than folded into
25
+ // one `sync-push`: stock and price have independent retry budgets and
26
+ // independent pause controls, so an operator filtering the log almost
27
+ // always wants one or the other, never both.
28
+ 'stock-push',
29
+ 'price-push',
30
+ // Written by TWO sweeps, told apart by `provider` (see `IntegrationEvent`):
31
+ // MercadoLibre's order reconciliation (one summary row per run) and the
32
+ // read-only MercadoPago reconciliation (one row per settled payment this
33
+ // system holds no record of — a report, never a repair).
34
+ 'reconcile-sweep',
35
+ ];
36
+ /** Same drift risk as `INTEGRATION_EVENT_TYPES`, same fix. */
37
+ export const INTEGRATION_EVENT_OUTCOMES = ['success', 'failure', 'retry', 'skipped'];
38
+ /**
39
+ * The keys of `MlOrderReconcileSummary`, as the runtime tuple the projection
40
+ * copies off a MercadoLibre `reconcile-sweep` row. A compile-time assertion
41
+ * pins it to the interface, so a field added to the summary without being
42
+ * added here fails `typecheck` instead of being dropped on the wire.
43
+ */
44
+ export const ML_ORDER_RECONCILE_SUMMARY_KEYS = [
45
+ 'trigger',
46
+ 'window',
47
+ 'scanned',
48
+ 'created',
49
+ 'updated',
50
+ 'skippedPreConnect',
51
+ 'truncated',
52
+ 'jobId',
53
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinfactura-types",
3
- "version": "1.10.370",
3
+ "version": "1.10.372",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",