@12-apps/marketplace 1.16.0 → 1.18.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.
Files changed (79) hide show
  1. package/ADOPTING.md +185 -0
  2. package/dist/99food/index.d.ts +2 -2
  3. package/dist/99food/index.js +2 -2
  4. package/dist/{adapter-CjVdMhZ2.d.ts → adapter-ZpAWKoCk.d.ts} +300 -3
  5. package/dist/{chunk-TRUK5ZBE.js → chunk-3B5EULS6.js} +2 -2
  6. package/dist/{chunk-DJIMUEHT.js → chunk-BLHZ3MRB.js} +79 -7
  7. package/dist/chunk-BLHZ3MRB.js.map +1 -0
  8. package/dist/{chunk-SGOTN5PX.js → chunk-LO7OKO6V.js} +45 -4
  9. package/dist/chunk-LO7OKO6V.js.map +1 -0
  10. package/dist/{chunk-TICWLBSA.js → chunk-MDEIRGNL.js} +1372 -823
  11. package/dist/chunk-MDEIRGNL.js.map +1 -0
  12. package/dist/{chunk-H2VQRD3B.js → chunk-Q5RMVNU5.js} +1 -1
  13. package/dist/chunk-Q5RMVNU5.js.map +1 -0
  14. package/dist/{chunk-BTKVZAJI.js → chunk-ZT6TZTLD.js} +1 -1
  15. package/dist/chunk-ZT6TZTLD.js.map +1 -0
  16. package/dist/{client-DgzCkl8u.d.ts → client-DpEq0yXb.d.ts} +1 -1
  17. package/dist/{engine-DSRj7qnC.d.ts → engine-DRRhAjZK.d.ts} +566 -293
  18. package/dist/hono/index.d.ts +2 -2
  19. package/dist/hono/index.js +4 -4
  20. package/dist/ifood/index.d.ts +14 -2
  21. package/dist/ifood/index.js +406 -120
  22. package/dist/ifood/index.js.map +1 -1
  23. package/dist/index.d.ts +21 -4
  24. package/dist/index.js +453 -43
  25. package/dist/index.js.map +1 -1
  26. package/dist/keeta/index.d.ts +2 -2
  27. package/dist/keeta/index.js +2 -2
  28. package/dist/manifest/index.d.ts +78 -0
  29. package/dist/manifest/index.js +1 -1
  30. package/dist/manifest/server.d.ts +6 -2
  31. package/dist/manifest/server.js +4 -4
  32. package/dist/rappi/index.d.ts +1 -1
  33. package/dist/rappi/index.js +1 -1
  34. package/dist/server/index.d.ts +93 -7
  35. package/dist/server/index.js +4 -4
  36. package/package.json +1 -1
  37. package/prisma/marketplace.prisma +70 -2
  38. package/prisma/migrations/20261203180000_marketplace_app_link_check/migration.sql +14 -0
  39. package/prisma/migrations/20261203190000_marketplace_disputes/migration.sql +96 -0
  40. package/prisma/migrations/20261203200000_marketplace_status_logistics_steps/migration.sql +12 -0
  41. package/src/core/adapter.ts +14 -2
  42. package/src/core/app-linking.ts +396 -0
  43. package/src/core/delivery-code.ts +119 -0
  44. package/src/core/dispute-engine.ts +32 -0
  45. package/src/core/dispute-job.ts +142 -0
  46. package/src/core/dispute-port.ts +133 -0
  47. package/src/core/dispute-store.ts +203 -0
  48. package/src/core/disputes.ts +263 -0
  49. package/src/core/engine.ts +12 -55
  50. package/src/core/integration.ts +3 -1
  51. package/src/core/link-engine.ts +176 -0
  52. package/src/core/link-store.ts +15 -0
  53. package/src/core/linking-port.ts +35 -1
  54. package/src/core/linking.ts +8 -0
  55. package/src/core/logistics.ts +388 -0
  56. package/src/core/outbound-queue.ts +6 -1
  57. package/src/core/outbound-sweep.ts +19 -6
  58. package/src/core/outbound.ts +4 -5
  59. package/src/core/pipeline.ts +14 -4
  60. package/src/core/ports.ts +20 -2
  61. package/src/core/status-job.ts +3 -0
  62. package/src/core/status-store.ts +2 -1
  63. package/src/core/types.ts +10 -0
  64. package/src/ifood/app-linking.ts +119 -0
  65. package/src/ifood/disputes.ts +209 -0
  66. package/src/ifood/index.ts +15 -1
  67. package/src/ifood/logistics.ts +38 -0
  68. package/src/ifood/normalize.ts +14 -1
  69. package/src/index.ts +44 -0
  70. package/src/server/jobs.ts +51 -3
  71. package/src/server/link-routes.ts +56 -4
  72. package/src/server/mcp-link.ts +44 -2
  73. package/src/server/mcp.ts +2 -1
  74. package/dist/chunk-BTKVZAJI.js.map +0 -1
  75. package/dist/chunk-DJIMUEHT.js.map +0 -1
  76. package/dist/chunk-H2VQRD3B.js.map +0 -1
  77. package/dist/chunk-SGOTN5PX.js.map +0 -1
  78. package/dist/chunk-TICWLBSA.js.map +0 -1
  79. /package/dist/{chunk-TRUK5ZBE.js.map → chunk-3B5EULS6.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import { a9 as MarketplaceDeliveredBy, ak as NormalizedLineOption, af as MarketplaceLinkAttemptDelegate, u as CatalogueItem, t as CatalogueImage, a as NormalizedMarketplaceOrder, N as NormalizedEvent, ay as StatusStep, i as NormalizedCourierEvent, a4 as MarketplaceCourierFacts, a2 as MarketplaceCourierAnswer, av as PickupCodeValidation, ab as MarketplaceHttp, _ as MarketplaceAppCredentialsPort, c as MarketplaceAdapter, l as MarketplaceProvider, a8 as MarketplaceCredentials, Q as CatalogueWarningCode, aw as PresenceProbe, m as CancellationReason, Y as LinkedMerchant, ae as MarketplaceLifecycle, a5 as MarketplaceCourierStep, a3 as MarketplaceCourierEngine, as as OutboundOrderRef, b as CatalogueMenuOptions, B as CatalogueReadResult } from './adapter-CjVdMhZ2.js';
1
+ import { aq as MarketplaceDeliveredBy, aH as NormalizedLineOption, az as MarketplaceLinkAttemptDelegate, au as MarketplaceDisputeDelegate, x as CatalogueItem, w as CatalogueImage, b0 as LogisticsPorts, b1 as LogisticsOrderPort, a as NormalizedMarketplaceOrder, N as NormalizedEvent, aV as StatusStep, j as NormalizedCourierEvent, al as MarketplaceCourierFacts, aj as MarketplaceCourierAnswer, aS as PickupCodeValidation, at as MarketplaceDisputeChange, av as MarketplaceHttp, af as MarketplaceAppCredentialsPort, c as MarketplaceAdapter, ac as LogisticsStep, ay as MarketplaceLifecycle, am as MarketplaceCourierStep, X as DeliveryCodeAnswer, n as MarketplaceProvider, ap as MarketplaceCredentials, U as CatalogueWarningCode, aT as PresenceProbe, o as CancellationReason, aa as LinkedMerchant, a0 as DisputeFailureCode, a1 as DisputeItem, Y as DisputeAlternative, a3 as DisputeReason, a2 as DisputeOutcome, ak as MarketplaceCourierEngine, b2 as MarketplaceLogisticsEngine, aP as OutboundOrderRef, b as CatalogueMenuOptions, G as CatalogueReadResult } from './adapter-ZpAWKoCk.js';
2
2
 
3
3
  /** What the engine tells the host about the order a lifecycle event names. */
4
4
  interface MarketplaceLifecycleFacts {
@@ -197,8 +197,14 @@ interface MarketplaceDb {
197
197
  updateMany(args: unknown): Promise<{
198
198
  count: number;
199
199
  }>;
200
+ /** OPTIONAL (FUT-6166): a Logistics run lets go of its claims when the order has no courier now. */
201
+ deleteMany?(args: unknown): Promise<{
202
+ count: number;
203
+ }>;
200
204
  };
201
205
  marketplaceLinkAttempt?: MarketplaceLinkAttemptDelegate;
206
+ /** OPTIONAL (FUT-6099): the buyer's disputes, migration `20261203190000_marketplace_disputes`. */
207
+ marketplaceDispute?: MarketplaceDisputeDelegate;
202
208
  }
203
209
  /** One decision as the host's admission sees it, BEFORE the claim commits. */
204
210
  interface MarketplaceAdmissionRequest {
@@ -221,7 +227,7 @@ interface MarketplaceAdmissionRequest {
221
227
  * transition has already been claimed and committed when they are called, and
222
228
  * a host that fails its half must not un-decide the acceptance.
223
229
  */
224
- interface MarketplaceOrderPort {
230
+ interface MarketplaceOrderPort extends LogisticsOrderPort {
225
231
  /**
226
232
  * Judge a decision BEFORE its claim commits, inside the claim's
227
233
  * transaction: the stock check (and the draw) of an accept, anything the
@@ -313,6 +319,12 @@ interface MarketplaceOrderPort {
313
319
  * logged. Absent: the verdict is only logged.
314
320
  */
315
321
  onPickupCodeValidated?(clientId: string, orderId: string, validation: PickupCodeValidation): Promise<void>;
322
+ /**
323
+ * OPTIONAL (FUT-6099). A dispute opened or closed on this order, after its
324
+ * commit: the host refreshes its board and tells a person. A throw is
325
+ * logged. Absent: only `publishChanged` is called.
326
+ */
327
+ onDispute?(clientId: string, orderId: string, change: MarketplaceDisputeChange): Promise<void>;
316
328
  /** Queue facts for a batch of orders, keyed by id. Missing ids are dropped. */
317
329
  summarize(clientId: string, orderIds: readonly string[]): Promise<Map<string, MarketplaceOrderSummary>>;
318
330
  }
@@ -382,7 +394,7 @@ interface MarketplaceCataloguePort {
382
394
  image(url: string): Promise<CatalogueImage | null>;
383
395
  }
384
396
  /** Everything the host plugs in. */
385
- interface MarketplacePorts {
397
+ interface MarketplacePorts extends LogisticsPorts {
386
398
  db: () => Promise<MarketplaceDb>;
387
399
  /**
388
400
  * Run `fn` in ONE database transaction and hand it the transaction's client
@@ -404,6 +416,12 @@ interface MarketplacePorts {
404
416
  * awaits it, and a dead bus costs latency, never a transition.
405
417
  */
406
418
  publishChanged: (clientId: string) => void;
419
+ /**
420
+ * OPTIONAL (FUT-5798). The periodic check saw the authorization of a store's
421
+ * centralized link arrive: the host hints that store's open screen to read
422
+ * its link again. Payload-free; absent, the screen sees it on its next read.
423
+ */
424
+ publishLinkSeen?: (clientId: string, provider: string) => void;
407
425
  /**
408
426
  * OPTIONAL. How long a store's cancellation request may wait for the
409
427
  * marketplace's answer before the outbound sweep fails it as TIMEOUT, in
@@ -431,6 +449,168 @@ interface MarketplaceEngineConfig extends MarketplacePorts {
431
449
  adapters: readonly MarketplaceAdapter[];
432
450
  }
433
451
 
452
+ /**
453
+ * The outbound job's name and payload — what a decision QUEUES.
454
+ *
455
+ * No path that answers a request ever calls a marketplace: an aceite, a
456
+ * refusal, a webhook and an ingest only enqueue this, and the job does the
457
+ * call. The payload carries identifiers only; the reason code and every
458
+ * outcome live on the acceptance row, so a replayed or duplicated job reads
459
+ * the truth rather than a stale copy of it.
460
+ */
461
+ /** The wire name, `<namespace>.<blueprint>` as the jobs contribution binds it. */
462
+ declare const MARKETPLACE_OUTBOUND_JOB = "marketplace.outbound";
463
+ /**
464
+ * What goes out: the store's aceite, the store's cancellation request, a
465
+ * step of the order the store reached (`status`, FUT-4653), or the pickup code
466
+ * the store checked at the hand-over (`validatePickupCode`, FUT-5665).
467
+ */
468
+ type OutboundAction = "confirm" | "requestCancellation" | "status" | "validatePickupCode" | "logistics";
469
+ /** The outbound job's payload. Identifiers only. */
470
+ interface OutboundJobPayload {
471
+ clientId: string;
472
+ orderId: string;
473
+ action: OutboundAction;
474
+ /** OPTIONAL. The step a `status` call tells the marketplace about; absent on every other action. */
475
+ step?: StatusStep;
476
+ /**
477
+ * OPTIONAL. The key of the move (or of the sweep's re-claim) a `status` call
478
+ * belongs to: the owner of its SENDING claim. Absent on every other action.
479
+ */
480
+ claimKey?: string;
481
+ /**
482
+ * OPTIONAL. The pickup code a `validatePickupCode` call sends; absent on every
483
+ * other action. The one non-identifier in the payload: a short-lived code the
484
+ * job needs to send, which no log line prints.
485
+ */
486
+ code?: string;
487
+ /** OPTIONAL (FUT-6166). The step a `logistics` call sends up to; absent on every other action. */
488
+ logisticsStep?: LogisticsStep;
489
+ }
490
+ /** The dedupe key: at most one queued call per (order, action). */
491
+ declare function outboundDedupeKey(payload: OutboundJobPayload): string;
492
+
493
+ /**
494
+ * Normalized marketplace order → the host's own order.
495
+ *
496
+ * The rule this module is written around, stated once so every decision below
497
+ * reads against it: **losing a paid marketplace order is the one unforgivable
498
+ * failure.** An unmapped SKU, a buyer with no name, a total that does not equal
499
+ * the line sum — none of them reject the order. They land, flagged, on a screen
500
+ * a human can act on. The only thing that stops an ingestion is a condition
501
+ * under which persisting would be WRONG rather than incomplete.
502
+ *
503
+ * Idempotent on `(provider, externalOrderId)`, which the acceptance table's
504
+ * unique enforces. That is what makes a redelivered webhook, a reconciliation
505
+ * poll racing it, and a retry after a crash all safe: each either creates the
506
+ * one order or finds it already there. The pre-read below is a fast path, not
507
+ * the guarantee — two concurrent deliveries both miss it and only one of them
508
+ * reaches a row.
509
+ */
510
+ /** What one ingestion did. */
511
+ interface IngestResult {
512
+ /** The HOST's order id. */
513
+ orderId: string;
514
+ /** False when the order already existed — a redelivery, not a second sale. */
515
+ created: boolean;
516
+ /** SKUs that arrived with nothing behind them, in this order. */
517
+ unmappedSkus: string[];
518
+ /**
519
+ * Whether this order was born accepted: the connection auto-accepts AND the
520
+ * host's `mayAutoAccept`, when bound, allowed it.
521
+ */
522
+ autoAccepted: boolean;
523
+ }
524
+ /** The store's operating decisions, read from the connection at ingest time. */
525
+ interface IngestSettings {
526
+ autoAccept: boolean;
527
+ ackSlaSeconds: number;
528
+ /**
529
+ * OPTIONAL. The connection's switch for following the marketplace's status
530
+ * (FUT-4653). Absent is OFF: a host that builds settings by hand keeps the
531
+ * behaviour it had before the switch existed.
532
+ */
533
+ followStatus?: boolean;
534
+ }
535
+
536
+ /** How a delivery ended. `duplicate` and `ignored` are both ordinary outcomes. */
537
+ type DeliveryOutcome = {
538
+ kind: "ingested";
539
+ orderId: string;
540
+ unmappedSkus: string[];
541
+ }
542
+ /** A lifecycle event moved the order forward, through the host's `onLifecycle` (FUT-4653). */
543
+ | {
544
+ kind: "moved";
545
+ orderId: string;
546
+ lifecycle: MarketplaceLifecycle;
547
+ }
548
+ /** The marketplace asked the customer's delivery code; the host stored it (FUT-6167). */
549
+ | {
550
+ kind: "deliveryCodeRequested";
551
+ orderId: string;
552
+ }
553
+ /** A courier event's facts were stored by the host's `onCourier` (FUT-5665). */
554
+ | {
555
+ kind: "courier";
556
+ orderId: string;
557
+ step: MarketplaceCourierStep;
558
+ }
559
+ /**
560
+ * The store accepted it in the marketplace's own app (FUT-5653): `accepted`
561
+ * when the host admitted it here too, else it waits AWAITING for a person
562
+ * (with the host's `refusal`, when it refused), never expired.
563
+ */
564
+ | {
565
+ kind: "confirmedByMarketplace";
566
+ orderId: string;
567
+ accepted: boolean;
568
+ refusal?: {
569
+ code: string;
570
+ message: string;
571
+ };
572
+ }
573
+ /** A dispute opened or closed on the order (FUT-6099); `unchanged` for a second event of one already kept. */
574
+ | {
575
+ kind: "dispute";
576
+ orderId: string;
577
+ disputeId: string;
578
+ change: "opened" | "settled" | "unchanged";
579
+ } | {
580
+ kind: "cancelled";
581
+ } | {
582
+ kind: "cancellationFailed";
583
+ }
584
+ /** Recorded; the order body is fetched by the `marketplace.fetch-order` job. */
585
+ | {
586
+ kind: "awaitingOrder";
587
+ } | {
588
+ kind: "duplicate";
589
+ } | {
590
+ kind: "ignored";
591
+ reason: string;
592
+ } | {
593
+ kind: "failed";
594
+ reason: string;
595
+ };
596
+
597
+ /** What the courier typed, for one of the host's orders. */
598
+ interface VerifyDeliveryCodeInput {
599
+ clientId: string;
600
+ /** The host's own order id. */
601
+ orderId: string;
602
+ code: string;
603
+ }
604
+ /** The engine's delivery-code half (`MarketplaceEngine` extends it). */
605
+ interface MarketplaceDeliveryCodeEngine {
606
+ /**
607
+ * Check the customer's delivery code with the marketplace (FUT-6167). Never
608
+ * throws; UNAVAILABLE says why nothing could be checked (no such order, the
609
+ * store does not carry it, no Logistics app, the marketplace did not answer).
610
+ */
611
+ verifyDeliveryCode(input: VerifyDeliveryCodeInput): Promise<DeliveryCodeAnswer>;
612
+ }
613
+
434
614
  /**
435
615
  * The acceptance clock — the store saying yes (or no) to an order.
436
616
  *
@@ -1005,79 +1185,393 @@ interface MarketplaceConformityEngine {
1005
1185
  runCancellationReasons(payload: CancellationReasonsJobPayload, attempt: Attempt): Promise<CancellationReasonsOutcome>;
1006
1186
  }
1007
1187
 
1008
- /**
1009
- * Fetching an order the event only announced — the engine's half of a
1010
- * marketplace whose events carry no order body (Open Delivery's `CREATED`).
1011
- *
1012
- * The rule this keeps: no path that answers a request calls a marketplace. So
1013
- * the webhook only RECORDS the delivery (PENDING, "order details to fetch")
1014
- * and queues `marketplace.fetch-order`; the job reads the row, asks the
1015
- * adapter's `fetchOrder` through the host's HTTP port with the store's own
1016
- * credentials, and ingests what comes back through the one ingest path. The
1017
- * inbox reconciliation sweep re-queues the job for a row that is still owed
1018
- * once it is older than the job's own retry span ({@link FETCH_REQUEUE_AGE_MS}),
1019
- * so a refused enqueue or a dead worker loses nothing — and it never fetches
1020
- * itself, so a host that holds the job (its enqueue port answers "held")
1021
- * holds every fetch.
1022
- *
1023
- * Two things are judged before a fetched order is ingested: a cancellation
1024
- * that outran the fetch (`./order-fetch-marks.ts`) wins, and an order naming a
1025
- * merchant other than the connection's is refused.
1026
- *
1027
- * Nothing here knows a marketplace: which events need a fetch is the adapter's
1028
- * `orderToFetch`, and how to fetch is its `fetchOrder`.
1029
- */
1030
- /** The wire name, `<namespace>.<blueprint>` as the jobs contribution binds it. */
1031
- declare const MARKETPLACE_FETCH_ORDER_JOB = "marketplace.fetch-order";
1032
- /** The job's payload. Identifiers only: the event itself is the inbox row's. */
1033
- interface FetchOrderJobPayload {
1034
- clientId: string;
1035
- inboxId: string;
1036
- }
1037
- /** What one run did. */
1038
- type FetchOrderOutcome = {
1039
- kind: "skipped";
1040
- reason: string;
1041
- } | {
1042
- kind: "ingested";
1043
- orderId: string;
1044
- unmappedSkus: string[];
1188
+ /** Why a linking call did nothing. Vocabulary, not copy: the host words each. */
1189
+ type LinkRefusalCode =
1190
+ /** No app configured for this marketplace, the adapter links nothing, or the host has no link table. */
1191
+ "UNAVAILABLE"
1192
+ /** `finish` with no `start` before it (or after another finish used it). */
1193
+ | "NO_LINK_IN_PROGRESS"
1194
+ /** The portal code's ten minutes are over: start again. */
1195
+ | "LINK_EXPIRED"
1196
+ /** The marketplace refused the authorization code (wrong, used, or for another code). */
1197
+ | "CODE_REFUSED"
1198
+ /** The marketplace refused another call (the code request, the merchant list). */
1199
+ | "MARKETPLACE_REFUSED"
1200
+ /** `selectMerchant` on a connection that is not linked, or is archived. */
1201
+ | "NOT_LINKED"
1202
+ /** The merchant is not one the grant covers. */
1203
+ | "UNKNOWN_MERCHANT"
1204
+ /** Another store's live connection already holds that merchant. */
1205
+ | "MERCHANT_TAKEN";
1206
+ /** A linking call that did nothing: refused for good, or worth trying again. */
1207
+ type LinkFailure = {
1208
+ kind: "refused";
1209
+ code: LinkRefusalCode;
1210
+ status: number | null;
1211
+ message: string | null;
1045
1212
  } | {
1046
- kind: "failed";
1213
+ kind: "retry";
1047
1214
  reason: string;
1048
1215
  };
1049
- /** Thrown so the queue retries the fetch. Its message is what the job log reads. */
1050
- declare class FetchOrderRetryError extends Error {
1051
- constructor(message: string);
1216
+ /** A linking in progress, as a person sees it: never the verifier. */
1217
+ interface LinkPendingView {
1218
+ userCode: string;
1219
+ verificationUrl: string;
1220
+ verificationUrlComplete: string;
1221
+ expiresAt: Date;
1222
+ /**
1223
+ * `app` for a centralized link (FUT-5798): no code (`userCode` is empty), the
1224
+ * portal is `verificationUrl`, and `seenAt` / `checkedAt` say when the app's
1225
+ * list first showed a store to pick and when it was last asked. Absent: a code.
1226
+ */
1227
+ mode?: "code" | "app";
1228
+ seenAt?: Date | null;
1229
+ checkedAt?: Date | null;
1230
+ }
1231
+ /** What `finishLink` answers: the connection, and the merchants the grant covers (null when they could not be listed). */
1232
+ interface LinkFinished {
1233
+ kind: "linked";
1234
+ integration: MarketplaceIntegrationView;
1235
+ merchants: LinkedMerchant[] | null;
1052
1236
  }
1053
1237
 
1054
1238
  /**
1055
- * The outbound sweep: nothing owed to a marketplace is lost.
1056
- *
1057
- * A decision queues its call right after the commit, but a queue can refuse
1058
- * the job, a process can die between the commit and the enqueue, and a job can
1059
- * die without stamping. The ROW still says what is owed — a PENDING request,
1060
- * or an ACCEPTED order with neither confirm stamp — so this pass re-queues
1061
- * every such row once it is older than the outbound job's own retry span.
1062
- *
1063
- * Bounded both ways:
1064
- * - younger than {@link OUTBOUND_STALE_MS}: the original job may still be
1065
- * retrying, so it is left alone;
1066
- * - older than {@link OUTBOUND_GIVE_UP_MS}: a marketplace has long since
1067
- * settled the order on its own clock. A request still waiting that old is
1068
- * stamped FAILED, TIMEOUT (a person finishes it on the marketplace, through
1069
- * the app link),
1070
- * and an accept that old is never confirmed — which is also what keeps a
1071
- * host's ACCEPTED history from before this engine from being confirmed on
1072
- * the first pass.
1073
- *
1074
- * For a host that REQUESTS FIRST (it binds `onCancellationConfirmed`; a 1.0.0
1075
- * host keeps the re-queue and the give-up below, unchanged), and before
1076
- * anything else, a store's cancellation request still waiting (PENDING:
1077
- * never delivered, or REQUESTED: delivered and unanswered) past its
1078
- * marketplace's answer window — the engine's `cancellationWindowMs`, else the
1079
- * adapter's `cancellationAnswerWindowMs`, counted from the request — is FAILED
1080
- * as TIMEOUT, and the host hears it through `onCancellationFailed` (FUT-4758,
1239
+ * The engine's linking surface (FUT-5613, centralized since FUT-5798): one
1240
+ * entry per call, dispatched to the centralized app's half (`./app-linking`)
1241
+ * when the adapter declares `appLinking`, else to the code flow (`./linking`).
1242
+ */
1243
+ interface MarketplaceLinkEngine {
1244
+ /**
1245
+ * Whether this store can link this marketplace through the software's own
1246
+ * app (FUT-5613), and the linking it left in progress. `available` is false
1247
+ * when the adapter links nothing, the host configured no app for it, or the
1248
+ * link table is not composed: the store's own credentials still work.
1249
+ */
1250
+ linkState(input: {
1251
+ clientId: string;
1252
+ provider: MarketplaceProvider;
1253
+ environment?: "SANDBOX" | "PRODUCTION";
1254
+ }): Promise<{
1255
+ available: boolean;
1256
+ pending: LinkPendingView | null;
1257
+ }>;
1258
+ /** Ask for the portal code; the verifier stays sealed server-side. Replaces an earlier attempt. */
1259
+ startLink(input: {
1260
+ clientId: string;
1261
+ provider: MarketplaceProvider;
1262
+ environment?: "SANDBOX" | "PRODUCTION";
1263
+ }): Promise<{
1264
+ kind: "started";
1265
+ pending: LinkPendingView;
1266
+ } | LinkFailure>;
1267
+ /** Exchange the pasted authorization code for the store's tokens; select the merchant when only one. */
1268
+ finishLink(input: {
1269
+ clientId: string;
1270
+ provider: MarketplaceProvider;
1271
+ authorizationCode: string;
1272
+ actorId: string | null;
1273
+ enabled?: boolean;
1274
+ }): Promise<LinkFinished | LinkFailure>;
1275
+ /** The merchants a linked connection's grant covers. */
1276
+ linkedMerchants(input: {
1277
+ clientId: string;
1278
+ provider: MarketplaceProvider;
1279
+ }): Promise<{
1280
+ kind: "listed";
1281
+ merchants: LinkedMerchant[];
1282
+ } | LinkFailure>;
1283
+ /** Choose the marketplace store of a linked connection whose grant covers several. */
1284
+ selectLinkedMerchant(input: {
1285
+ clientId: string;
1286
+ provider: MarketplaceProvider;
1287
+ merchantId: string;
1288
+ /** Who picked it, for the audit line of a connection unarchived by the pick (centralized linking). */
1289
+ actorId?: string | null;
1290
+ }): Promise<{
1291
+ kind: "selected";
1292
+ integration: MarketplaceIntegrationView;
1293
+ } | LinkFailure>;
1294
+ /**
1295
+ * Centralized linking (FUT-5798): ask the app's list NOW ("Já autorizei ·
1296
+ * verificar agora", the screen's first read and every read after a hint),
1297
+ * renewing the attempt. Refused UNAVAILABLE for a marketplace that links
1298
+ * through codes.
1299
+ */
1300
+ checkLink(input: {
1301
+ clientId: string;
1302
+ provider: MarketplaceProvider;
1303
+ }): Promise<{
1304
+ kind: "checked";
1305
+ pending: LinkPendingView | null;
1306
+ merchants: LinkedMerchant[];
1307
+ } | LinkFailure>;
1308
+ /** End this store's linking in progress (Cancelar). Nothing else changes. */
1309
+ cancelLink(input: {
1310
+ clientId: string;
1311
+ provider: MarketplaceProvider;
1312
+ }): Promise<void>;
1313
+ /**
1314
+ * The host's periodic job (every 30 s): every centralized attempt still
1315
+ * waiting asks the app's list; answers the stores whose authorization this
1316
+ * pass saw, for the host to hint their screens. Asks nothing when none waits.
1317
+ */
1318
+ sweepLinks(input?: {
1319
+ half?: boolean;
1320
+ }): Promise<{
1321
+ seen: {
1322
+ clientId: string;
1323
+ provider: string;
1324
+ }[];
1325
+ waiting: number;
1326
+ }>;
1327
+ }
1328
+
1329
+ /**
1330
+ * The `marketplace.dispute-answer` job (FUT-6099): sends one claimed answer
1331
+ * and stamps what the marketplace said. Idempotent by the row: only a SENDING
1332
+ * row is sent, so a duplicate run calls nobody.
1333
+ */
1334
+ /** The job's payload: identifiers only. */
1335
+ interface DisputeAnswerJobPayload {
1336
+ clientId: string;
1337
+ /** The marketplace's id for the dispute. */
1338
+ disputeId: string;
1339
+ }
1340
+ type DisputeAnswerOutcome = {
1341
+ kind: "skipped";
1342
+ reason: string;
1343
+ } | {
1344
+ kind: "answered";
1345
+ } | {
1346
+ kind: "failed";
1347
+ code: DisputeFailureCode;
1348
+ };
1349
+ /** Thrown so the queue retries. */
1350
+ declare class DisputeAnswerRetryError extends Error {
1351
+ constructor(message: string);
1352
+ }
1353
+
1354
+ /**
1355
+ * The dispute table (`marketplace_disputes`, FUT-6099): one row per dispute,
1356
+ * read into the view a host draws. OPEN → SENDING (an answer claimed and
1357
+ * queued) → ANSWERED (the marketplace took it) → SETTLED (the marketplace
1358
+ * closed it). A failed send goes back to OPEN with its `failure` code.
1359
+ */
1360
+ /** The wire name, `<namespace>.<blueprint>`. */
1361
+ declare const MARKETPLACE_DISPUTE_ANSWER_JOB = "marketplace.dispute-answer";
1362
+ type DisputeStatus = "OPEN" | "SENDING" | "ANSWERED" | "SETTLED";
1363
+ /** The store's answer as kept, with when it was given. */
1364
+ interface DisputeAnswerView {
1365
+ kind: "ACCEPT" | "REJECT" | "ALTERNATIVE";
1366
+ reasonCode: string | null;
1367
+ alternativeId: string | null;
1368
+ amountCents: number | null;
1369
+ minutes: number | null;
1370
+ at: Date;
1371
+ }
1372
+ /** One dispute, as a host draws it. The engine writes no sentence: every word is the host's or the marketplace's. */
1373
+ interface MarketplaceDisputeView {
1374
+ /** The marketplace's id for the dispute: the key `answerDispute` takes. */
1375
+ disputeId: string;
1376
+ orderId: string;
1377
+ provider: string;
1378
+ externalOrderId: string;
1379
+ status: DisputeStatus;
1380
+ action: string;
1381
+ handshakeType: string | null;
1382
+ reason: string | null;
1383
+ message: string | null;
1384
+ evidenceUrls: string[];
1385
+ items: DisputeItem[];
1386
+ requestedAmountCents: number | null;
1387
+ expiresAt: Date | null;
1388
+ openedAt: Date;
1389
+ timeoutAction: string | null;
1390
+ alternatives: DisputeAlternative[];
1391
+ rejectReasons: DisputeReason[];
1392
+ /** The answer sent or being sent; null while none stands (a failed one is cleared). */
1393
+ answer: DisputeAnswerView | null;
1394
+ /** Why the last answer did not land; with ALREADY_ANSWERED the status is ANSWERED (someone answered first). */
1395
+ failure: DisputeFailureCode | null;
1396
+ settlement: {
1397
+ outcome: DisputeOutcome;
1398
+ at: Date;
1399
+ amountCents: number | null;
1400
+ } | null;
1401
+ }
1402
+ /** A row as the delegate answers it. */
1403
+ interface DisputeRow {
1404
+ id: string;
1405
+ clientId: string;
1406
+ orderId: string;
1407
+ provider: string;
1408
+ externalOrderId: string;
1409
+ disputeId: string;
1410
+ status: string;
1411
+ action: string;
1412
+ handshakeType: string | null;
1413
+ reason: string | null;
1414
+ message: string | null;
1415
+ evidences: unknown;
1416
+ items: unknown;
1417
+ requestedAmountCents: number | null;
1418
+ expiresAt: Date | null;
1419
+ openedAt: Date;
1420
+ timeoutAction: string | null;
1421
+ alternatives: unknown;
1422
+ rejectReasons: unknown;
1423
+ acceptReasons: unknown;
1424
+ answer: string | null;
1425
+ answerReasonCode: string | null;
1426
+ answerAlternativeId: string | null;
1427
+ answerAmountCents: number | null;
1428
+ answerMinutes: number | null;
1429
+ answeredAt: Date | null;
1430
+ answerFailure: string | null;
1431
+ settlement: string | null;
1432
+ settledAt: Date | null;
1433
+ settledAmountCents: number | null;
1434
+ }
1435
+ /** A row as a host draws it. */
1436
+ declare function disputeView(row: DisputeRow): MarketplaceDisputeView;
1437
+
1438
+ /**
1439
+ * A marketplace's disputes (FUT-6099), the engine's half: the event that opens
1440
+ * or closes one is kept per order, and the store's answer is claimed here and
1441
+ * sent by the `marketplace.dispute-answer` job, never inside the request.
1442
+ *
1443
+ * A dispute never touches the order or its acceptance: it may arrive for an
1444
+ * order in any state (delivered, in preparation, late), and what the store
1445
+ * does about it is an answer to the marketplace, not a move of the order.
1446
+ */
1447
+ /** The answer a person gives, before the engine judges it. */
1448
+ type DisputeAnswerInput = {
1449
+ kind: "ACCEPT";
1450
+ } | {
1451
+ kind: "REJECT";
1452
+ reasonCode: string;
1453
+ } | {
1454
+ kind: "ALTERNATIVE";
1455
+ alternativeId: string;
1456
+ amountCents?: number | null;
1457
+ minutes?: number | null;
1458
+ };
1459
+ /** Why an answer is refused locally, before anything is queued. */
1460
+ type DisputeRefusalCode = "NOT_FOUND" | "ALREADY_ANSWERED" | "EXPIRED" | "UNSUPPORTED" | "INVALID_REASON" | "INVALID_ALTERNATIVE" | "INVALID_AMOUNT" | "INVALID_MINUTES";
1461
+ type AnswerDisputeResult = {
1462
+ kind: "queued";
1463
+ dispute: MarketplaceDisputeView;
1464
+ } | {
1465
+ kind: "refused";
1466
+ code: DisputeRefusalCode;
1467
+ };
1468
+
1469
+ /**
1470
+ * The engine's dispute calls (FUT-6099), bound to its context. ADOPTING §15
1471
+ * is the host's contract.
1472
+ */
1473
+ interface MarketplaceDisputeEngine {
1474
+ /**
1475
+ * The disputes to draw, oldest first: of these orders; or, with
1476
+ * `settledSince`, every one still open, being answered or waiting on the
1477
+ * marketplace, plus those settled since then. One statement.
1478
+ */
1479
+ disputes(input: {
1480
+ clientId: string;
1481
+ orderIds?: readonly string[];
1482
+ settledSince?: Date;
1483
+ }): Promise<MarketplaceDisputeView[]>;
1484
+ /**
1485
+ * The store's answer: judged, claimed and queued; refused locally with a code. No call to the marketplace.
1486
+ * With `orderId`, a dispute of another order is NOT_FOUND, before anything is claimed.
1487
+ */
1488
+ answerDispute(input: {
1489
+ clientId: string;
1490
+ disputeId: string;
1491
+ orderId?: string;
1492
+ answer: DisputeAnswerInput;
1493
+ now?: Date;
1494
+ }): Promise<AnswerDisputeResult>;
1495
+ /** Send one claimed answer (the `marketplace.dispute-answer` job's body). */
1496
+ runDisputeAnswer(payload: DisputeAnswerJobPayload, attempt: {
1497
+ attempt: number;
1498
+ maxAttempts: number;
1499
+ }): Promise<DisputeAnswerOutcome>;
1500
+ }
1501
+
1502
+ /**
1503
+ * Fetching an order the event only announced — the engine's half of a
1504
+ * marketplace whose events carry no order body (Open Delivery's `CREATED`).
1505
+ *
1506
+ * The rule this keeps: no path that answers a request calls a marketplace. So
1507
+ * the webhook only RECORDS the delivery (PENDING, "order details to fetch")
1508
+ * and queues `marketplace.fetch-order`; the job reads the row, asks the
1509
+ * adapter's `fetchOrder` through the host's HTTP port with the store's own
1510
+ * credentials, and ingests what comes back through the one ingest path. The
1511
+ * inbox reconciliation sweep re-queues the job for a row that is still owed
1512
+ * once it is older than the job's own retry span ({@link FETCH_REQUEUE_AGE_MS}),
1513
+ * so a refused enqueue or a dead worker loses nothing — and it never fetches
1514
+ * itself, so a host that holds the job (its enqueue port answers "held")
1515
+ * holds every fetch.
1516
+ *
1517
+ * Two things are judged before a fetched order is ingested: a cancellation
1518
+ * that outran the fetch (`./order-fetch-marks.ts`) wins, and an order naming a
1519
+ * merchant other than the connection's is refused.
1520
+ *
1521
+ * Nothing here knows a marketplace: which events need a fetch is the adapter's
1522
+ * `orderToFetch`, and how to fetch is its `fetchOrder`.
1523
+ */
1524
+ /** The wire name, `<namespace>.<blueprint>` as the jobs contribution binds it. */
1525
+ declare const MARKETPLACE_FETCH_ORDER_JOB = "marketplace.fetch-order";
1526
+ /** The job's payload. Identifiers only: the event itself is the inbox row's. */
1527
+ interface FetchOrderJobPayload {
1528
+ clientId: string;
1529
+ inboxId: string;
1530
+ }
1531
+ /** What one run did. */
1532
+ type FetchOrderOutcome = {
1533
+ kind: "skipped";
1534
+ reason: string;
1535
+ } | {
1536
+ kind: "ingested";
1537
+ orderId: string;
1538
+ unmappedSkus: string[];
1539
+ } | {
1540
+ kind: "failed";
1541
+ reason: string;
1542
+ };
1543
+ /** Thrown so the queue retries the fetch. Its message is what the job log reads. */
1544
+ declare class FetchOrderRetryError extends Error {
1545
+ constructor(message: string);
1546
+ }
1547
+
1548
+ /**
1549
+ * The outbound sweep: nothing owed to a marketplace is lost.
1550
+ *
1551
+ * A decision queues its call right after the commit, but a queue can refuse
1552
+ * the job, a process can die between the commit and the enqueue, and a job can
1553
+ * die without stamping. The ROW still says what is owed — a PENDING request,
1554
+ * or an ACCEPTED order with neither confirm stamp — so this pass re-queues
1555
+ * every such row once it is older than the outbound job's own retry span.
1556
+ *
1557
+ * Bounded both ways:
1558
+ * - younger than {@link OUTBOUND_STALE_MS}: the original job may still be
1559
+ * retrying, so it is left alone;
1560
+ * - older than {@link OUTBOUND_GIVE_UP_MS}: a marketplace has long since
1561
+ * settled the order on its own clock. A request still waiting that old is
1562
+ * stamped FAILED, TIMEOUT (a person finishes it on the marketplace, through
1563
+ * the app link),
1564
+ * and an accept that old is never confirmed — which is also what keeps a
1565
+ * host's ACCEPTED history from before this engine from being confirmed on
1566
+ * the first pass.
1567
+ *
1568
+ * For a host that REQUESTS FIRST (it binds `onCancellationConfirmed`; a 1.0.0
1569
+ * host keeps the re-queue and the give-up below, unchanged), and before
1570
+ * anything else, a store's cancellation request still waiting (PENDING:
1571
+ * never delivered, or REQUESTED: delivered and unanswered) past its
1572
+ * marketplace's answer window — the engine's `cancellationWindowMs`, else the
1573
+ * adapter's `cancellationAnswerWindowMs`, counted from the request — is FAILED
1574
+ * as TIMEOUT, and the host hears it through `onCancellationFailed` (FUT-4758,
1081
1575
  * the owner: "it cannot stay in that state with nothing happening"). The
1082
1576
  * store then cancels in the marketplace's own app. A PENDING request's
1083
1577
  * retries stop with it: the job re-reads the row and sends only from PENDING,
@@ -1114,130 +1608,6 @@ interface PendingInboxEvent {
1114
1608
  receivedAt?: Date | null;
1115
1609
  }
1116
1610
 
1117
- /**
1118
- * Normalized marketplace order → the host's own order.
1119
- *
1120
- * The rule this module is written around, stated once so every decision below
1121
- * reads against it: **losing a paid marketplace order is the one unforgivable
1122
- * failure.** An unmapped SKU, a buyer with no name, a total that does not equal
1123
- * the line sum — none of them reject the order. They land, flagged, on a screen
1124
- * a human can act on. The only thing that stops an ingestion is a condition
1125
- * under which persisting would be WRONG rather than incomplete.
1126
- *
1127
- * Idempotent on `(provider, externalOrderId)`, which the acceptance table's
1128
- * unique enforces. That is what makes a redelivered webhook, a reconciliation
1129
- * poll racing it, and a retry after a crash all safe: each either creates the
1130
- * one order or finds it already there. The pre-read below is a fast path, not
1131
- * the guarantee — two concurrent deliveries both miss it and only one of them
1132
- * reaches a row.
1133
- */
1134
- /** What one ingestion did. */
1135
- interface IngestResult {
1136
- /** The HOST's order id. */
1137
- orderId: string;
1138
- /** False when the order already existed — a redelivery, not a second sale. */
1139
- created: boolean;
1140
- /** SKUs that arrived with nothing behind them, in this order. */
1141
- unmappedSkus: string[];
1142
- /**
1143
- * Whether this order was born accepted: the connection auto-accepts AND the
1144
- * host's `mayAutoAccept`, when bound, allowed it.
1145
- */
1146
- autoAccepted: boolean;
1147
- }
1148
- /** The store's operating decisions, read from the connection at ingest time. */
1149
- interface IngestSettings {
1150
- autoAccept: boolean;
1151
- ackSlaSeconds: number;
1152
- /**
1153
- * OPTIONAL. The connection's switch for following the marketplace's status
1154
- * (FUT-4653). Absent is OFF: a host that builds settings by hand keeps the
1155
- * behaviour it had before the switch existed.
1156
- */
1157
- followStatus?: boolean;
1158
- }
1159
-
1160
- /** Why a linking call did nothing. Vocabulary, not copy: the host words each. */
1161
- type LinkRefusalCode =
1162
- /** No app configured for this marketplace, the adapter links nothing, or the host has no link table. */
1163
- "UNAVAILABLE"
1164
- /** `finish` with no `start` before it (or after another finish used it). */
1165
- | "NO_LINK_IN_PROGRESS"
1166
- /** The portal code's ten minutes are over: start again. */
1167
- | "LINK_EXPIRED"
1168
- /** The marketplace refused the authorization code (wrong, used, or for another code). */
1169
- | "CODE_REFUSED"
1170
- /** The marketplace refused another call (the code request, the merchant list). */
1171
- | "MARKETPLACE_REFUSED"
1172
- /** `selectMerchant` on a connection that is not linked, or is archived. */
1173
- | "NOT_LINKED"
1174
- /** The merchant is not one the grant covers. */
1175
- | "UNKNOWN_MERCHANT"
1176
- /** Another store's live connection already holds that merchant. */
1177
- | "MERCHANT_TAKEN";
1178
- /** A linking call that did nothing: refused for good, or worth trying again. */
1179
- type LinkFailure = {
1180
- kind: "refused";
1181
- code: LinkRefusalCode;
1182
- status: number | null;
1183
- message: string | null;
1184
- } | {
1185
- kind: "retry";
1186
- reason: string;
1187
- };
1188
- /** A linking in progress, as a person sees it: never the verifier. */
1189
- interface LinkPendingView {
1190
- userCode: string;
1191
- verificationUrl: string;
1192
- verificationUrlComplete: string;
1193
- expiresAt: Date;
1194
- }
1195
- /** What `finishLink` answers: the connection, and the merchants the grant covers (null when they could not be listed). */
1196
- interface LinkFinished {
1197
- kind: "linked";
1198
- integration: MarketplaceIntegrationView;
1199
- merchants: LinkedMerchant[] | null;
1200
- }
1201
-
1202
- /**
1203
- * The outbound job's name and payload — what a decision QUEUES.
1204
- *
1205
- * No path that answers a request ever calls a marketplace: an aceite, a
1206
- * refusal, a webhook and an ingest only enqueue this, and the job does the
1207
- * call. The payload carries identifiers only; the reason code and every
1208
- * outcome live on the acceptance row, so a replayed or duplicated job reads
1209
- * the truth rather than a stale copy of it.
1210
- */
1211
- /** The wire name, `<namespace>.<blueprint>` as the jobs contribution binds it. */
1212
- declare const MARKETPLACE_OUTBOUND_JOB = "marketplace.outbound";
1213
- /**
1214
- * What goes out: the store's aceite, the store's cancellation request, a
1215
- * step of the order the store reached (`status`, FUT-4653), or the pickup code
1216
- * the store checked at the hand-over (`validatePickupCode`, FUT-5665).
1217
- */
1218
- type OutboundAction = "confirm" | "requestCancellation" | "status" | "validatePickupCode";
1219
- /** The outbound job's payload. Identifiers only. */
1220
- interface OutboundJobPayload {
1221
- clientId: string;
1222
- orderId: string;
1223
- action: OutboundAction;
1224
- /** OPTIONAL. The step a `status` call tells the marketplace about; absent on every other action. */
1225
- step?: StatusStep;
1226
- /**
1227
- * OPTIONAL. The key of the move (or of the sweep's re-claim) a `status` call
1228
- * belongs to: the owner of its SENDING claim. Absent on every other action.
1229
- */
1230
- claimKey?: string;
1231
- /**
1232
- * OPTIONAL. The pickup code a `validatePickupCode` call sends; absent on every
1233
- * other action. The one non-identifier in the payload: a short-lived code the
1234
- * job needs to send, which no log line prints.
1235
- */
1236
- code?: string;
1237
- }
1238
- /** The dedupe key: at most one queued call per (order, action). */
1239
- declare function outboundDedupeKey(payload: OutboundJobPayload): string;
1240
-
1241
1611
  /**
1242
1612
  * The outbound engine: one queued call to a marketplace, start to finish.
1243
1613
  *
@@ -1500,55 +1870,6 @@ interface AvailabilitySweepResult {
1500
1870
  givenUp: number;
1501
1871
  }
1502
1872
 
1503
- /** How a delivery ended. `duplicate` and `ignored` are both ordinary outcomes. */
1504
- type DeliveryOutcome = {
1505
- kind: "ingested";
1506
- orderId: string;
1507
- unmappedSkus: string[];
1508
- }
1509
- /** A lifecycle event moved the order forward, through the host's `onLifecycle` (FUT-4653). */
1510
- | {
1511
- kind: "moved";
1512
- orderId: string;
1513
- lifecycle: MarketplaceLifecycle;
1514
- }
1515
- /** A courier event's facts were stored by the host's `onCourier` (FUT-5665). */
1516
- | {
1517
- kind: "courier";
1518
- orderId: string;
1519
- step: MarketplaceCourierStep;
1520
- }
1521
- /**
1522
- * The store accepted it in the marketplace's own app (FUT-5653): `accepted`
1523
- * when the host admitted it here too, else it waits AWAITING for a person
1524
- * (with the host's `refusal`, when it refused), never expired.
1525
- */
1526
- | {
1527
- kind: "confirmedByMarketplace";
1528
- orderId: string;
1529
- accepted: boolean;
1530
- refusal?: {
1531
- code: string;
1532
- message: string;
1533
- };
1534
- } | {
1535
- kind: "cancelled";
1536
- } | {
1537
- kind: "cancellationFailed";
1538
- }
1539
- /** Recorded; the order body is fetched by the `marketplace.fetch-order` job. */
1540
- | {
1541
- kind: "awaitingOrder";
1542
- } | {
1543
- kind: "duplicate";
1544
- } | {
1545
- kind: "ignored";
1546
- reason: string;
1547
- } | {
1548
- kind: "failed";
1549
- reason: string;
1550
- };
1551
-
1552
1873
  /**
1553
1874
  * What the host's order reads need to draw a marketplace order: where its
1554
1875
  * aceite and its cancellation request stand, and where a person goes when the
@@ -1576,7 +1897,7 @@ interface MarketplaceOrderState {
1576
1897
  }
1577
1898
 
1578
1899
  /** Everything the mounted engine can do, with the ports and adapters bound in. */
1579
- interface MarketplaceEngine extends MarketplaceCourierEngine, MarketplaceConformityEngine {
1900
+ interface MarketplaceEngine extends MarketplaceCourierEngine, MarketplaceConformityEngine, MarketplaceLinkEngine, MarketplaceDisputeEngine, MarketplaceLogisticsEngine, MarketplaceDeliveryCodeEngine {
1580
1901
  /** Every registered marketplace, in registration order. */
1581
1902
  providers(): readonly MarketplaceProvider[];
1582
1903
  /** Whether a provider id (a URL segment, a body field) names a registered adapter. */
@@ -1630,54 +1951,6 @@ interface MarketplaceEngine extends MarketplaceCourierEngine, MarketplaceConform
1630
1951
  rows: readonly IntegrationRowInput[];
1631
1952
  validateOnly?: boolean;
1632
1953
  }): Promise<BulkResult<MarketplaceIntegrationView>>;
1633
- /**
1634
- * Whether this store can link this marketplace through the software's own
1635
- * app (FUT-5613), and the linking it left in progress. `available` is false
1636
- * when the adapter links nothing, the host configured no app for it, or the
1637
- * link table is not composed: the store's own credentials still work.
1638
- */
1639
- linkState(input: {
1640
- clientId: string;
1641
- provider: MarketplaceProvider;
1642
- environment?: "SANDBOX" | "PRODUCTION";
1643
- }): Promise<{
1644
- available: boolean;
1645
- pending: LinkPendingView | null;
1646
- }>;
1647
- /** Ask for the portal code; the verifier stays sealed server-side. Replaces an earlier attempt. */
1648
- startLink(input: {
1649
- clientId: string;
1650
- provider: MarketplaceProvider;
1651
- environment?: "SANDBOX" | "PRODUCTION";
1652
- }): Promise<{
1653
- kind: "started";
1654
- pending: LinkPendingView;
1655
- } | LinkFailure>;
1656
- /** Exchange the pasted authorization code for the store's tokens; select the merchant when only one. */
1657
- finishLink(input: {
1658
- clientId: string;
1659
- provider: MarketplaceProvider;
1660
- authorizationCode: string;
1661
- actorId: string | null;
1662
- enabled?: boolean;
1663
- }): Promise<LinkFinished | LinkFailure>;
1664
- /** The merchants a linked connection's grant covers. */
1665
- linkedMerchants(input: {
1666
- clientId: string;
1667
- provider: MarketplaceProvider;
1668
- }): Promise<{
1669
- kind: "listed";
1670
- merchants: LinkedMerchant[];
1671
- } | LinkFailure>;
1672
- /** Choose the marketplace store of a linked connection whose grant covers several. */
1673
- selectLinkedMerchant(input: {
1674
- clientId: string;
1675
- provider: MarketplaceProvider;
1676
- merchantId: string;
1677
- }): Promise<{
1678
- kind: "selected";
1679
- integration: MarketplaceIntegrationView;
1680
- } | LinkFailure>;
1681
1954
  /** The SKU map. `unmappedOnly` is the store's attention list; `ids` narrows. */
1682
1955
  menuLinks(input: {
1683
1956
  clientId: string;
@@ -1813,4 +2086,4 @@ interface MarketplaceEngine extends MarketplaceCourierEngine, MarketplaceConform
1813
2086
  */
1814
2087
  declare function createMarketplaceEngine(config: MarketplaceEngineConfig): MarketplaceEngine;
1815
2088
 
1816
- export { MARKETPLACE_CATALOGUE_JOB as $, type AcceptanceDecision as A, type BulkProblem as B, type CancellationFailureReason as C, type CatalogueTarget as D, type DecideManyResult as E, type DecidedRow as F, type DecisionInput as G, type DecisionProblem as H, type DecisionProblemCode as I, type DecisionResult as J, type DeliveryOutcome as K, type ExpirySweepResult as L, type FetchOrderJobPayload as M, type FetchOrderOutcome as N, FetchOrderRetryError as O, type InformStatusInput as P, type IngestResult as Q, type IngestSettings as R, type IngestionTarget as S, type IntegrationRowInput as T, type LinkFailure as U, type LinkFinished as V, type LinkPendingView as W, type LinkRefusalCode as X, MARKETPLACE_ACKNOWLEDGE_JOB as Y, MARKETPLACE_AVAILABILITY_JOB as Z, MARKETPLACE_CANCELLATION_REASONS_JOB as _, type AcceptanceStatus as a, MARKETPLACE_FETCH_ORDER_JOB as a0, MARKETPLACE_OUTBOUND_JOB as a1, type MarketplaceAdmission as a2, type MarketplaceAdmissionRequest as a3, type MarketplaceAdmissionResult as a4, type MarketplaceAuditEntry as a5, type MarketplaceAuditPort as a6, type MarketplaceAuthMode as a7, type MarketplaceCataloguePort as a8, type MarketplaceClockPort as a9, type PauseStoreInput as aA, type PauseStoreResult as aB, type PendingAcceptance as aC, type PendingInboxEvent as aD, type ResolvedOrderLine as aE, type ResumeOutcome as aF, STORE_PAUSE_LEASE_MS as aG, type SaveMarketplaceIntegrationInput as aH, type StoreAvailabilityView as aI, type StorePauseFailureCode as aJ, type StorePauseState as aK, type StorePauseWanted as aL, availabilityDedupeKey as aM, catalogueDedupeKey as aN, createMarketplaceEngine as aO, outboundDedupeKey as aP, type MarketplaceConformityEngine as aa, type MarketplaceDb as ab, type MarketplaceEngine as ac, type MarketplaceEngineConfig as ad, type MarketplaceEnqueuePort as ae, type MarketplaceIntegrationView as af, type MarketplaceLifecycleAnswer as ag, type MarketplaceLifecycleFacts as ah, type MarketplaceLogger as ai, type MarketplaceMenuLinkView as aj, type MarketplaceOrderPort as ak, type MarketplaceOrderState as al, type MarketplaceOrderSummary as am, type MarketplacePorts as an, type MarketplaceRefusal as ao, type MarketplaceSecretsPort as ap, type MenuLinkRowInput as aq, OUTBOUND_GIVE_UP_MS as ar, OUTBOUND_STALE_MS as as, type OutboundAction as at, type OutboundAttempt as au, type OutboundJobPayload as av, type OutboundOutcome as aw, OutboundRetryError as ax, type OutboundSweepResult as ay, type PauseOutcome as az, type AcknowledgeJobPayload as b, type AcknowledgeOutcome as c, AcknowledgeRetryError as d, type AvailabilityJobPayload as e, type AvailabilityOutcome as f, AvailabilityRetryError as g, type AvailabilitySweepResult as h, type BulkProblemCode as i, type BulkResult as j, type CancellationReasonsJobPayload as k, type CancellationReasonsOutcome as l, CancellationReasonsRetryError as m, type CancellationStatus as n, type CatalogueAction as o, type CatalogueActionResult as p, type CatalogueDocumentResult as q, type CatalogueFailedAction as r, type CatalogueFailureCode as s, type CatalogueJobPayload as t, type CatalogueOutcome as u, type CataloguePublicationView as v, type CataloguePublishInput as w, type CatalogueRefusalCode as x, CatalogueRetryError as y, type CatalogueStatus as z };
2089
+ export { type IngestionTarget as $, type AcceptanceDecision as A, type BulkProblem as B, type CancellationFailureReason as C, type CatalogueStatus as D, type CatalogueTarget as E, type DecideManyResult as F, type DecidedRow as G, type DecisionInput as H, type DecisionProblem as I, type DecisionProblemCode as J, type DecisionResult as K, type DeliveryOutcome as L, type DisputeAnswerInput as M, type DisputeAnswerJobPayload as N, type DisputeAnswerOutcome as O, DisputeAnswerRetryError as P, type DisputeAnswerView as Q, type DisputeRefusalCode as R, type DisputeRow as S, type DisputeStatus as T, type ExpirySweepResult as U, type FetchOrderJobPayload as V, type FetchOrderOutcome as W, FetchOrderRetryError as X, type InformStatusInput as Y, type IngestResult as Z, type IngestSettings as _, type AcceptanceStatus as a, catalogueDedupeKey as a$, type IntegrationRowInput as a0, type LinkFailure as a1, type LinkFinished as a2, type LinkPendingView as a3, type LinkRefusalCode as a4, MARKETPLACE_ACKNOWLEDGE_JOB as a5, MARKETPLACE_AVAILABILITY_JOB as a6, MARKETPLACE_CANCELLATION_REASONS_JOB as a7, MARKETPLACE_CATALOGUE_JOB as a8, MARKETPLACE_DISPUTE_ANSWER_JOB as a9, type MarketplacePorts as aA, type MarketplaceRefusal as aB, type MarketplaceSecretsPort as aC, type MenuLinkRowInput as aD, OUTBOUND_GIVE_UP_MS as aE, OUTBOUND_STALE_MS as aF, type OutboundAction as aG, type OutboundAttempt as aH, type OutboundJobPayload as aI, type OutboundOutcome as aJ, OutboundRetryError as aK, type OutboundSweepResult as aL, type PauseOutcome as aM, type PauseStoreInput as aN, type PauseStoreResult as aO, type PendingAcceptance as aP, type PendingInboxEvent as aQ, type ResolvedOrderLine as aR, type ResumeOutcome as aS, STORE_PAUSE_LEASE_MS as aT, type SaveMarketplaceIntegrationInput as aU, type StoreAvailabilityView as aV, type StorePauseFailureCode as aW, type StorePauseState as aX, type StorePauseWanted as aY, type VerifyDeliveryCodeInput as aZ, availabilityDedupeKey as a_, MARKETPLACE_FETCH_ORDER_JOB as aa, MARKETPLACE_OUTBOUND_JOB as ab, type MarketplaceAdmission as ac, type MarketplaceAdmissionRequest as ad, type MarketplaceAdmissionResult as ae, type MarketplaceAuditEntry as af, type MarketplaceAuditPort as ag, type MarketplaceAuthMode as ah, type MarketplaceCataloguePort as ai, type MarketplaceClockPort as aj, type MarketplaceConformityEngine as ak, type MarketplaceDb as al, type MarketplaceDeliveryCodeEngine as am, type MarketplaceDisputeEngine as an, type MarketplaceDisputeView as ao, type MarketplaceEngine as ap, type MarketplaceEngineConfig as aq, type MarketplaceEnqueuePort as ar, type MarketplaceIntegrationView as as, type MarketplaceLifecycleAnswer as at, type MarketplaceLifecycleFacts as au, type MarketplaceLogger as av, type MarketplaceMenuLinkView as aw, type MarketplaceOrderPort as ax, type MarketplaceOrderState as ay, type MarketplaceOrderSummary as az, type AcknowledgeJobPayload as b, createMarketplaceEngine as b0, disputeView as b1, outboundDedupeKey as b2, type AcknowledgeOutcome as c, AcknowledgeRetryError as d, type AnswerDisputeResult as e, type AvailabilityJobPayload as f, type AvailabilityOutcome as g, AvailabilityRetryError as h, type AvailabilitySweepResult as i, type BulkProblemCode as j, type BulkResult as k, type CancellationReasonsJobPayload as l, type CancellationReasonsOutcome as m, CancellationReasonsRetryError as n, type CancellationStatus as o, type CatalogueAction as p, type CatalogueActionResult as q, type CatalogueDocumentResult as r, type CatalogueFailedAction as s, type CatalogueFailureCode as t, type CatalogueJobPayload as u, type CatalogueOutcome as v, type CataloguePublicationView as w, type CataloguePublishInput as x, type CatalogueRefusalCode as y, CatalogueRetryError as z };