@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,5 +1,5 @@
1
- import { A as AdapterCallContext, N as NormalizedEvent, a as NormalizedMarketplaceOrder, c as MarketplaceAdapter } from '../adapter-CjVdMhZ2.js';
2
- import { a as OpenDeliveryStop, O as OpenDeliveryApiBaseUrls } from '../client-DgzCkl8u.js';
1
+ import { A as AdapterCallContext, N as NormalizedEvent, a as NormalizedMarketplaceOrder, c as MarketplaceAdapter } from '../adapter-ZpAWKoCk.js';
2
+ import { a as OpenDeliveryStop, O as OpenDeliveryApiBaseUrls } from '../client-DpEq0yXb.js';
3
3
 
4
4
  /**
5
5
  * Keeta's MERCHANT AUTHORIZATION, automated from the software (Keeta's
@@ -13,7 +13,7 @@ import {
13
13
  openDeliveryRequestCancellation,
14
14
  openDeliveryStatus,
15
15
  openDeliverySwitchAvailability
16
- } from "../chunk-TRUK5ZBE.js";
16
+ } from "../chunk-3B5EULS6.js";
17
17
  import "../chunk-M2V4RFMA.js";
18
18
  import {
19
19
  asString,
@@ -23,7 +23,7 @@ import {
23
23
  } from "../chunk-E4XJXHUK.js";
24
24
  import {
25
25
  outboundResultOf
26
- } from "../chunk-BTKVZAJI.js";
26
+ } from "../chunk-ZT6TZTLD.js";
27
27
  import {
28
28
  __name
29
29
  } from "../chunk-7QVYU63E.js";
@@ -362,6 +362,12 @@ declare const marketplaceManifest: {
362
362
  verificationUrl: zod.ZodString;
363
363
  verificationUrlComplete: zod.ZodString;
364
364
  expiresAt: zod.ZodString;
365
+ mode: zod.ZodOptional<zod.ZodEnum<{
366
+ code: "code";
367
+ app: "app";
368
+ }>>;
369
+ seenAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
370
+ checkedAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
365
371
  }, zod_v4_core.$strip>>;
366
372
  }, zod_v4_core.$strip>;
367
373
  }, zod_v4_core.$strip>;
@@ -385,6 +391,8 @@ declare const marketplaceManifest: {
385
391
  id: zod.ZodString;
386
392
  name: zod.ZodNullable<zod.ZodString>;
387
393
  corporateName: zod.ZodNullable<zod.ZodString>;
394
+ address: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
395
+ taken: zod.ZodOptional<zod.ZodBoolean>;
388
396
  }, zod_v4_core.$strip>>;
389
397
  }, zod_v4_core.$strip>;
390
398
  readonly annotations: {
@@ -413,6 +421,12 @@ declare const marketplaceManifest: {
413
421
  verificationUrl: zod.ZodString;
414
422
  verificationUrlComplete: zod.ZodString;
415
423
  expiresAt: zod.ZodString;
424
+ mode: zod.ZodOptional<zod.ZodEnum<{
425
+ code: "code";
426
+ app: "app";
427
+ }>>;
428
+ seenAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
429
+ checkedAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
416
430
  }, zod_v4_core.$strip>;
417
431
  }, zod_v4_core.$strip>;
418
432
  readonly annotations: {
@@ -479,6 +493,8 @@ declare const marketplaceManifest: {
479
493
  id: zod.ZodString;
480
494
  name: zod.ZodNullable<zod.ZodString>;
481
495
  corporateName: zod.ZodNullable<zod.ZodString>;
496
+ address: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
497
+ taken: zod.ZodOptional<zod.ZodBoolean>;
482
498
  }, zod_v4_core.$strip>>>;
483
499
  }, zod_v4_core.$strip>;
484
500
  }, zod_v4_core.$strip>;
@@ -548,6 +564,68 @@ declare const marketplaceManifest: {
548
564
  readonly destructive: false;
549
565
  readonly openWorld: true;
550
566
  };
567
+ }, {
568
+ readonly operationId: "checkMarketplaceLink";
569
+ readonly method: "POST";
570
+ readonly path: "/admin/{tenantSlug}/marketplace/link/check";
571
+ readonly summary: "Ask the marketplace now, in one call, which stores the software's centralized app is authorized for (each `taken` when another store's connection holds it, with its address), and renew the linking in progress; `pending.seenAt` says when a store to pick first appeared. 409 UNAVAILABLE for a marketplace that links with a code.";
572
+ readonly tags: readonly ["marketplace"];
573
+ readonly params: zod.ZodObject<{
574
+ tenantSlug: zod.ZodString;
575
+ }, zod_v4_core.$strict>;
576
+ readonly body: zod.ZodObject<{
577
+ provider: zod.ZodString;
578
+ }, zod_v4_core.$strict>;
579
+ readonly response: zod.ZodObject<{
580
+ data: zod.ZodObject<{
581
+ pending: zod.ZodNullable<zod.ZodObject<{
582
+ userCode: zod.ZodString;
583
+ verificationUrl: zod.ZodString;
584
+ verificationUrlComplete: zod.ZodString;
585
+ expiresAt: zod.ZodString;
586
+ mode: zod.ZodOptional<zod.ZodEnum<{
587
+ code: "code";
588
+ app: "app";
589
+ }>>;
590
+ seenAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
591
+ checkedAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
592
+ }, zod_v4_core.$strip>>;
593
+ merchants: zod.ZodArray<zod.ZodObject<{
594
+ id: zod.ZodString;
595
+ name: zod.ZodNullable<zod.ZodString>;
596
+ corporateName: zod.ZodNullable<zod.ZodString>;
597
+ address: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
598
+ taken: zod.ZodOptional<zod.ZodBoolean>;
599
+ }, zod_v4_core.$strip>>;
600
+ }, zod_v4_core.$strip>;
601
+ }, zod_v4_core.$strip>;
602
+ readonly annotations: {
603
+ readonly readOnly: false;
604
+ readonly destructive: false;
605
+ readonly openWorld: true;
606
+ };
607
+ }, {
608
+ readonly operationId: "cancelMarketplaceLink";
609
+ readonly method: "POST";
610
+ readonly path: "/admin/{tenantSlug}/marketplace/link/cancel";
611
+ readonly summary: "End a store's linking in progress in one call (Cancelar). A connection already linked stays as it is.";
612
+ readonly tags: readonly ["marketplace"];
613
+ readonly params: zod.ZodObject<{
614
+ tenantSlug: zod.ZodString;
615
+ }, zod_v4_core.$strict>;
616
+ readonly body: zod.ZodObject<{
617
+ provider: zod.ZodString;
618
+ }, zod_v4_core.$strict>;
619
+ readonly response: zod.ZodObject<{
620
+ data: zod.ZodObject<{
621
+ cancelled: zod.ZodLiteral<true>;
622
+ }, zod_v4_core.$strip>;
623
+ }, zod_v4_core.$strip>;
624
+ readonly annotations: {
625
+ readonly readOnly: false;
626
+ readonly destructive: false;
627
+ readonly openWorld: false;
628
+ };
551
629
  }];
552
630
  };
553
631
  readonly db: {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MARKETPLACE_MCP_TOOLS,
3
3
  MARKETPLACE_PERMISSIONS
4
- } from "../chunk-SGOTN5PX.js";
4
+ } from "../chunk-LO7OKO6V.js";
5
5
  import "../chunk-7QVYU63E.js";
6
6
 
7
7
  // src/manifest/index.ts
@@ -1,7 +1,7 @@
1
- import { av as OutboundJobPayload, M as FetchOrderJobPayload, b as AcknowledgeJobPayload, k as CancellationReasonsJobPayload, t as CatalogueJobPayload, e as AvailabilityJobPayload } from '../engine-DSRj7qnC.js';
1
+ import { aI as OutboundJobPayload, V as FetchOrderJobPayload, b as AcknowledgeJobPayload, l as CancellationReasonsJobPayload, u as CatalogueJobPayload, f as AvailabilityJobPayload, N as DisputeAnswerJobPayload } from '../engine-DRRhAjZK.js';
2
2
  import * as _12_apps_wiring from '@12-apps/wiring';
3
3
  import { createApiMarketplace, MarketplaceJobDeps } from '../server/index.js';
4
- import '../adapter-CjVdMhZ2.js';
4
+ import '../adapter-ZpAWKoCk.js';
5
5
  import 'zod';
6
6
 
7
7
  declare const marketplaceServerManifest: {
@@ -22,6 +22,10 @@ declare const marketplaceServerManifest: {
22
22
  readonly "outbound-sweep": _12_apps_wiring.WireJobBlueprint<void, MarketplaceJobDeps>;
23
23
  readonly availability: _12_apps_wiring.WireJobBlueprint<AvailabilityJobPayload, MarketplaceJobDeps>;
24
24
  readonly "availability-sweep": _12_apps_wiring.WireJobBlueprint<void, MarketplaceJobDeps>;
25
+ readonly "link-check": _12_apps_wiring.WireJobBlueprint<{
26
+ half?: boolean;
27
+ } | undefined, MarketplaceJobDeps>;
28
+ readonly "dispute-answer": _12_apps_wiring.WireJobBlueprint<DisputeAnswerJobPayload, MarketplaceJobDeps>;
25
29
  };
26
30
  };
27
31
  };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  MARKETPLACE_JOBS,
3
3
  createApiMarketplace
4
- } from "../chunk-DJIMUEHT.js";
5
- import "../chunk-SGOTN5PX.js";
6
- import "../chunk-TICWLBSA.js";
7
- import "../chunk-H2VQRD3B.js";
4
+ } from "../chunk-BLHZ3MRB.js";
5
+ import "../chunk-LO7OKO6V.js";
6
+ import "../chunk-MDEIRGNL.js";
7
+ import "../chunk-Q5RMVNU5.js";
8
8
  import "../chunk-7QVYU63E.js";
9
9
 
10
10
  // src/manifest/server.ts
@@ -1,4 +1,4 @@
1
- import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-CjVdMhZ2.js';
1
+ import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-ZpAWKoCk.js';
2
2
 
3
3
  /**
4
4
  * The words the Rappi adapter needs from its host, and nothing else.
@@ -9,7 +9,7 @@ import {
9
9
  answered,
10
10
  outboundResultOf,
11
11
  tokenGrantResultOf
12
- } from "../chunk-BTKVZAJI.js";
12
+ } from "../chunk-ZT6TZTLD.js";
13
13
  import {
14
14
  __name
15
15
  } from "../chunk-7QVYU63E.js";
@@ -1,7 +1,7 @@
1
- import { I as DecisionProblemCode, i as BulkProblemCode, X as LinkRefusalCode, ac as MarketplaceEngine, ai as MarketplaceLogger, av as OutboundJobPayload, M as FetchOrderJobPayload, b as AcknowledgeJobPayload, k as CancellationReasonsJobPayload, t as CatalogueJobPayload, e as AvailabilityJobPayload } from '../engine-DSRj7qnC.js';
1
+ import { J as DecisionProblemCode, j as BulkProblemCode, a4 as LinkRefusalCode, ap as MarketplaceEngine, av as MarketplaceLogger, aI as OutboundJobPayload, V as FetchOrderJobPayload, b as AcknowledgeJobPayload, l as CancellationReasonsJobPayload, u as CatalogueJobPayload, f as AvailabilityJobPayload, N as DisputeAnswerJobPayload } from '../engine-DRRhAjZK.js';
2
2
  import { WireRoute, WireJobBlueprint } from '@12-apps/wiring';
3
3
  import { z } from 'zod';
4
- import '../adapter-CjVdMhZ2.js';
4
+ import '../adapter-ZpAWKoCk.js';
5
5
 
6
6
  /**
7
7
  * Every problem code a route words from `problems`, decisions and bulk writes
@@ -118,7 +118,7 @@ declare const MARKETPLACE_MANAGE = "marketplace:manage";
118
118
  declare const MARKETPLACE_DECIDE = "marketplace:decide";
119
119
 
120
120
  /**
121
- * The engine's ten jobs, declared here because every number in them is the
121
+ * The engine's eleven jobs, declared here because every number in them is the
122
122
  * engine's knowledge, not a host's:
123
123
  *
124
124
  * - `expire-acceptances`, every minute: the unit being measured is minutes (a
@@ -149,6 +149,9 @@ declare const MARKETPLACE_DECIDE = "marketplace:decide";
149
149
  * - `availability`, on demand: brings one marketplace in line with the host's
150
150
  * last pause or resume ask for one store (FUT-4851). Three attempts with
151
151
  * backoff; the last one stamps FAILED with a failure code.
152
+ * - `dispute-answer`, on demand: sends one store's answer to a buyer's
153
+ * dispute (FUT-6099). Three attempts with backoff; the last gives the
154
+ * answer back OPEN, and the outbound sweep re-queues one still owed.
152
155
  * - `availability-sweep`, every five minutes: resumes a pause past its
153
156
  * `until` (the host stopped renewing it), re-queues an ask still owed, and
154
157
  * gives up on one older than a day.
@@ -160,12 +163,13 @@ declare const MARKETPLACE_DECIDE = "marketplace:decide";
160
163
  * `marketplace.expire-acceptances`, `marketplace.reconcile-inbox`,
161
164
  * `marketplace.outbound`, `marketplace.fetch-order`, `marketplace.acknowledge`,
162
165
  * `marketplace.cancellation-reasons`, `marketplace.catalogue`,
163
- * `marketplace.outbound-sweep`, `marketplace.availability` and
164
- * `marketplace.availability-sweep`.
166
+ * `marketplace.outbound-sweep`, `marketplace.availability`,
167
+ * `marketplace.availability-sweep`, `marketplace.link-check` and
168
+ * `marketplace.dispute-answer`.
165
169
  */
166
170
  /** What the host closes over at bind time: the mounted engine. */
167
171
  interface MarketplaceJobDeps {
168
- engine: Pick<MarketplaceEngine, "expireLapsed" | "retryable" | "reprocess" | "runOutbound" | "runFetchOrder" | "runAcknowledge" | "sweepAcknowledgements" | "runCancellationReasons" | "runCatalogue" | "sweepOutbound" | "runAvailability" | "sweepAvailability">;
172
+ engine: Pick<MarketplaceEngine, "expireLapsed" | "retryable" | "reprocess" | "runOutbound" | "runFetchOrder" | "runAcknowledge" | "sweepAcknowledgements" | "runCancellationReasons" | "runCatalogue" | "sweepOutbound" | "runAvailability" | "sweepAvailability" | "sweepLinks" | "runDisputeAnswer">;
169
173
  }
170
174
  /** The single-flight queue name (`@12-apps/jobs`' `SWEEP_QUEUE`), as a literal. */
171
175
  declare const MARKETPLACE_SWEEP_QUEUE = "sweeps";
@@ -189,6 +193,10 @@ declare const MARKETPLACE_JOBS: {
189
193
  readonly "outbound-sweep": WireJobBlueprint<void, MarketplaceJobDeps>;
190
194
  readonly availability: WireJobBlueprint<AvailabilityJobPayload, MarketplaceJobDeps>;
191
195
  readonly "availability-sweep": WireJobBlueprint<void, MarketplaceJobDeps>;
196
+ readonly "link-check": WireJobBlueprint<{
197
+ half?: boolean;
198
+ } | undefined, MarketplaceJobDeps>;
199
+ readonly "dispute-answer": WireJobBlueprint<DisputeAnswerJobPayload, MarketplaceJobDeps>;
192
200
  };
193
201
  };
194
202
 
@@ -550,8 +558,8 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
550
558
  decisions: z.ZodArray<z.ZodObject<{
551
559
  orderId: z.ZodString;
552
560
  status: z.ZodEnum<{
553
- REJECTED: "REJECTED";
554
561
  ACCEPTED: "ACCEPTED";
562
+ REJECTED: "REJECTED";
555
563
  }>;
556
564
  cancellation: z.ZodNullable<z.ZodEnum<{
557
565
  CONFIRMED: "CONFIRMED";
@@ -593,6 +601,12 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
593
601
  verificationUrl: z.ZodString;
594
602
  verificationUrlComplete: z.ZodString;
595
603
  expiresAt: z.ZodString;
604
+ mode: z.ZodOptional<z.ZodEnum<{
605
+ code: "code";
606
+ app: "app";
607
+ }>>;
608
+ seenAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
609
+ checkedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
596
610
  }, z.core.$strip>>;
597
611
  }, z.core.$strip>;
598
612
  }, z.core.$strip>;
@@ -616,6 +630,8 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
616
630
  id: z.ZodString;
617
631
  name: z.ZodNullable<z.ZodString>;
618
632
  corporateName: z.ZodNullable<z.ZodString>;
633
+ address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
634
+ taken: z.ZodOptional<z.ZodBoolean>;
619
635
  }, z.core.$strip>>;
620
636
  }, z.core.$strip>;
621
637
  readonly annotations: {
@@ -644,6 +660,12 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
644
660
  verificationUrl: z.ZodString;
645
661
  verificationUrlComplete: z.ZodString;
646
662
  expiresAt: z.ZodString;
663
+ mode: z.ZodOptional<z.ZodEnum<{
664
+ code: "code";
665
+ app: "app";
666
+ }>>;
667
+ seenAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
668
+ checkedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
647
669
  }, z.core.$strip>;
648
670
  }, z.core.$strip>;
649
671
  readonly annotations: {
@@ -710,6 +732,8 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
710
732
  id: z.ZodString;
711
733
  name: z.ZodNullable<z.ZodString>;
712
734
  corporateName: z.ZodNullable<z.ZodString>;
735
+ address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
736
+ taken: z.ZodOptional<z.ZodBoolean>;
713
737
  }, z.core.$strip>>>;
714
738
  }, z.core.$strip>;
715
739
  }, z.core.$strip>;
@@ -779,6 +803,68 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
779
803
  readonly destructive: false;
780
804
  readonly openWorld: true;
781
805
  };
806
+ }, {
807
+ readonly operationId: "checkMarketplaceLink";
808
+ readonly method: "POST";
809
+ readonly path: "/admin/{tenantSlug}/marketplace/link/check";
810
+ readonly summary: "Ask the marketplace now, in one call, which stores the software's centralized app is authorized for (each `taken` when another store's connection holds it, with its address), and renew the linking in progress; `pending.seenAt` says when a store to pick first appeared. 409 UNAVAILABLE for a marketplace that links with a code.";
811
+ readonly tags: readonly ["marketplace"];
812
+ readonly params: z.ZodObject<{
813
+ tenantSlug: z.ZodString;
814
+ }, z.core.$strict>;
815
+ readonly body: z.ZodObject<{
816
+ provider: z.ZodString;
817
+ }, z.core.$strict>;
818
+ readonly response: z.ZodObject<{
819
+ data: z.ZodObject<{
820
+ pending: z.ZodNullable<z.ZodObject<{
821
+ userCode: z.ZodString;
822
+ verificationUrl: z.ZodString;
823
+ verificationUrlComplete: z.ZodString;
824
+ expiresAt: z.ZodString;
825
+ mode: z.ZodOptional<z.ZodEnum<{
826
+ code: "code";
827
+ app: "app";
828
+ }>>;
829
+ seenAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
830
+ checkedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
831
+ }, z.core.$strip>>;
832
+ merchants: z.ZodArray<z.ZodObject<{
833
+ id: z.ZodString;
834
+ name: z.ZodNullable<z.ZodString>;
835
+ corporateName: z.ZodNullable<z.ZodString>;
836
+ address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
837
+ taken: z.ZodOptional<z.ZodBoolean>;
838
+ }, z.core.$strip>>;
839
+ }, z.core.$strip>;
840
+ }, z.core.$strip>;
841
+ readonly annotations: {
842
+ readonly readOnly: false;
843
+ readonly destructive: false;
844
+ readonly openWorld: true;
845
+ };
846
+ }, {
847
+ readonly operationId: "cancelMarketplaceLink";
848
+ readonly method: "POST";
849
+ readonly path: "/admin/{tenantSlug}/marketplace/link/cancel";
850
+ readonly summary: "End a store's linking in progress in one call (Cancelar). A connection already linked stays as it is.";
851
+ readonly tags: readonly ["marketplace"];
852
+ readonly params: z.ZodObject<{
853
+ tenantSlug: z.ZodString;
854
+ }, z.core.$strict>;
855
+ readonly body: z.ZodObject<{
856
+ provider: z.ZodString;
857
+ }, z.core.$strict>;
858
+ readonly response: z.ZodObject<{
859
+ data: z.ZodObject<{
860
+ cancelled: z.ZodLiteral<true>;
861
+ }, z.core.$strip>;
862
+ }, z.core.$strip>;
863
+ readonly annotations: {
864
+ readonly readOnly: false;
865
+ readonly destructive: false;
866
+ readonly openWorld: false;
867
+ };
782
868
  }];
783
869
 
784
870
  /**
@@ -6,7 +6,7 @@ import {
6
6
  MARKETPLACE_SWEEP_QUEUE,
7
7
  ORDER_NOT_PENDING_CODE,
8
8
  createApiMarketplace
9
- } from "../chunk-DJIMUEHT.js";
9
+ } from "../chunk-BLHZ3MRB.js";
10
10
  import {
11
11
  MARKETPLACE_DECIDE,
12
12
  MARKETPLACE_MANAGE,
@@ -19,9 +19,9 @@ import {
19
19
  marketplaceParams,
20
20
  upsertMarketplaceIntegrationsBody,
21
21
  upsertMarketplaceMenuLinksBody
22
- } from "../chunk-SGOTN5PX.js";
23
- import "../chunk-TICWLBSA.js";
24
- import "../chunk-H2VQRD3B.js";
22
+ } from "../chunk-LO7OKO6V.js";
23
+ import "../chunk-MDEIRGNL.js";
24
+ import "../chunk-Q5RMVNU5.js";
25
25
  import "../chunk-7QVYU63E.js";
26
26
  export {
27
27
  MARKETPLACE_AVAILABILITY_ATTEMPTS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@12-apps/marketplace",
3
- "version": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "One marketplace integration engine for every marketplace: the durable inbox, the ingest pipeline, the acceptance clock and its sweep, the SKU map, the integration settings with sealed credentials, and the outbound engine (confirm, cancellation request, retries), behind an adapter port. Each marketplace is an adapter at its own subpath (./ifood, ./99food and ./keeta on Open Delivery, ./rappi). Framework-neutral wiring route descriptors (./server) with a Hono adapter (./hono), dep-free job blueprints, MCP tools and the package-owned Prisma partial + migrations.",
@@ -1,7 +1,7 @@
1
1
  // ---------------------------------------------------------------------------
2
2
  // @12-apps/marketplace — CANONICAL Prisma model partial.
3
3
  //
4
- // The eight tables the marketplace engine owns. A host does NOT copy these
4
+ // The nine tables the marketplace engine owns. A host does NOT copy these
5
5
  // models by hand: it composes this file into its multi-file schema folder from
6
6
  // the `db` capability (`package.json` "wiring.db"), and discovers the
7
7
  // migrations beside it.
@@ -458,7 +458,7 @@ model MarketplaceStatusUpdate {
458
458
  orderId String @map("order_id")
459
459
  provider String
460
460
 
461
- /// READY | DISPATCHED | HANDED_OVER | CONCLUDED (CHECK).
461
+ /// READY | DISPATCHED | HANDED_OVER | CONCLUDED, or LOGISTICS_<STEP> (FUT-6166) (CHECK).
462
462
  step String
463
463
  /// STORE | MARKETPLACE (CHECK).
464
464
  source String
@@ -506,9 +506,77 @@ model MarketplaceLinkAttempt {
506
506
  verificationUrlComplete String @map("verification_url_complete")
507
507
  expiresAt DateTime @map("expires_at")
508
508
 
509
+ /// Centralized linking (FUT-5798): when the app's list first showed a store
510
+ /// this one may pick (the authorization arrived), and when it was last asked.
511
+ seenAt DateTime? @map("seen_at")
512
+ checkedAt DateTime? @map("checked_at")
513
+
509
514
  createdAt DateTime @default(now()) @map("created_at")
510
515
  updatedAt DateTime @updatedAt @map("updated_at")
511
516
 
512
517
  @@unique([clientId, provider])
518
+ @@index([expiresAt])
513
519
  @@map("marketplace_link_attempts")
514
520
  }
521
+
522
+ /// One buyer's dispute on one order (FUT-6099): iFood's Negotiation Platform,
523
+ /// where the buyer asks the marketplace for a refund or a change after the
524
+ /// order was placed and the store answers.
525
+ ///
526
+ /// OPEN (waiting on the store) → SENDING (an answer claimed and queued) →
527
+ /// ANSWERED (the marketplace took it) → SETTLED (the marketplace closed it,
528
+ /// `settlement` its outcome); a failed send goes back to OPEN with
529
+ /// `answerFailure`. What the marketplace sent is kept as it came (the reasons,
530
+ /// the alternatives, the photos, the disputed lines), so the answer is judged
531
+ /// against THIS dispute's offer and never a static list. Money in cents.
532
+ /// By-value `clientId` and `orderId`, no foreign key, as every table here.
533
+ model MarketplaceDispute {
534
+ id String @id @default(uuid())
535
+ clientId String @map("client_id")
536
+ orderId String @map("order_id")
537
+ provider String
538
+ externalOrderId String @map("external_order_id")
539
+ /// The marketplace's id for the dispute: the key every answer is sent to.
540
+ disputeId String @map("dispute_id")
541
+
542
+ /// OPEN | SENDING | ANSWERED | SETTLED (CHECK).
543
+ status String @default("OPEN")
544
+
545
+ action String
546
+ handshakeType String? @map("handshake_type")
547
+ reason String?
548
+ message String?
549
+ evidences Json @default("[]")
550
+ items Json @default("[]")
551
+ requestedAmountCents Int? @map("requested_amount_cents")
552
+ expiresAt DateTime? @map("expires_at")
553
+ openedAt DateTime @map("opened_at")
554
+ timeoutAction String? @map("timeout_action")
555
+ alternatives Json @default("[]")
556
+ rejectReasons Json @default("[]") @map("reject_reasons")
557
+ acceptReasons Json @default("[]") @map("accept_reasons")
558
+
559
+ /// ACCEPT | REJECT | ALTERNATIVE (CHECK), null while none stands.
560
+ answer String?
561
+ answerReasonCode String? @map("answer_reason_code")
562
+ answerAlternativeId String? @map("answer_alternative_id")
563
+ answerAmountCents Int? @map("answer_amount_cents")
564
+ answerMinutes Int? @map("answer_minutes")
565
+ answeredAt DateTime? @map("answered_at")
566
+ /// Why the last answer did not land (the engine's code), or null.
567
+ answerFailure String? @map("answer_failure")
568
+
569
+ /// ACCEPTED | REJECTED | EXPIRED | ALTERNATIVE_REPLIED | OTHER (CHECK), null until closed.
570
+ settlement String?
571
+ settledAt DateTime? @map("settled_at")
572
+ settledAmountCents Int? @map("settled_amount_cents")
573
+
574
+ createdAt DateTime @default(now()) @map("created_at")
575
+ updatedAt DateTime @updatedAt @map("updated_at")
576
+
577
+ @@unique([provider, disputeId])
578
+ @@index([clientId, orderId])
579
+ @@index([clientId, status])
580
+ @@index([clientId, settledAt])
581
+ @@map("marketplace_disputes")
582
+ }
@@ -0,0 +1,14 @@
1
+ -- @domains: marketplace
2
+ -- @12-apps/marketplace: linking a store through the software's CENTRALIZED app (FUT-5798).
3
+ -- Additive and replay-safe: two nullable columns and one index on
4
+ -- `marketplace_link_attempts`. Nothing the previous release reads changes.
5
+ --
6
+ -- `seen_at` is when the app's merchant list first showed a store this one may
7
+ -- pick (the authorization arrived); `checked_at` is when the list was last
8
+ -- asked, so the 30-second check skips an attempt asked moments ago. The index
9
+ -- serves that check's walk over the attempts still alive.
10
+
11
+ ALTER TABLE "marketplace_link_attempts" ADD COLUMN IF NOT EXISTS "seen_at" TIMESTAMP(3);
12
+ ALTER TABLE "marketplace_link_attempts" ADD COLUMN IF NOT EXISTS "checked_at" TIMESTAMP(3);
13
+
14
+ CREATE INDEX IF NOT EXISTS "marketplace_link_attempts_expires_at_idx" ON "marketplace_link_attempts"("expires_at");
@@ -0,0 +1,96 @@
1
+ -- @domains: marketplace
2
+ -- @12-apps/marketplace: the buyer's disputes (FUT-6099, iFood's Negotiation Platform).
3
+ -- Additive and replay-safe, like the engine's earlier migrations: one new table
4
+ -- with its CHECKs and indexes. No foreign key into a host table, and nothing the
5
+ -- previous release reads is changed.
6
+ --
7
+ -- `marketplace_disputes` holds one row per dispute: what the marketplace sent
8
+ -- (kept as it came, so an answer is judged against this dispute's own reasons
9
+ -- and alternatives), the store's answer and its fate, and the marketplace's
10
+ -- settlement. Money in cents.
11
+
12
+ CREATE TABLE IF NOT EXISTS "marketplace_disputes" (
13
+ "id" TEXT NOT NULL,
14
+ "client_id" TEXT NOT NULL,
15
+ "order_id" TEXT NOT NULL,
16
+ "provider" TEXT NOT NULL,
17
+ "external_order_id" TEXT NOT NULL,
18
+ "dispute_id" TEXT NOT NULL,
19
+ "status" TEXT NOT NULL DEFAULT 'OPEN',
20
+ "action" TEXT NOT NULL,
21
+ "handshake_type" TEXT,
22
+ "reason" TEXT,
23
+ "message" TEXT,
24
+ "evidences" JSONB NOT NULL DEFAULT '[]',
25
+ "items" JSONB NOT NULL DEFAULT '[]',
26
+ "requested_amount_cents" INTEGER,
27
+ "expires_at" TIMESTAMP(3),
28
+ "opened_at" TIMESTAMP(3) NOT NULL,
29
+ "timeout_action" TEXT,
30
+ "alternatives" JSONB NOT NULL DEFAULT '[]',
31
+ "reject_reasons" JSONB NOT NULL DEFAULT '[]',
32
+ "accept_reasons" JSONB NOT NULL DEFAULT '[]',
33
+ "answer" TEXT,
34
+ "answer_reason_code" TEXT,
35
+ "answer_alternative_id" TEXT,
36
+ "answer_amount_cents" INTEGER,
37
+ "answer_minutes" INTEGER,
38
+ "answered_at" TIMESTAMP(3),
39
+ "answer_failure" TEXT,
40
+ "settlement" TEXT,
41
+ "settled_at" TIMESTAMP(3),
42
+ "settled_amount_cents" INTEGER,
43
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
44
+ "updated_at" TIMESTAMP(3) NOT NULL,
45
+
46
+ CONSTRAINT "marketplace_disputes_pkey" PRIMARY KEY ("id")
47
+ );
48
+
49
+ DO $$ BEGIN
50
+ ALTER TABLE "marketplace_disputes" ADD CONSTRAINT "marketplace_disputes_provider_shape"
51
+ CHECK ("provider" ~ '^[A-Z][A-Z0-9_]*$');
52
+ EXCEPTION WHEN duplicate_object THEN NULL; END $$;
53
+
54
+ DO $$ BEGIN
55
+ ALTER TABLE "marketplace_disputes" ADD CONSTRAINT "marketplace_disputes_status_check"
56
+ CHECK ("status" IN ('OPEN', 'SENDING', 'ANSWERED', 'SETTLED'));
57
+ EXCEPTION WHEN duplicate_object THEN NULL; END $$;
58
+
59
+ DO $$ BEGIN
60
+ ALTER TABLE "marketplace_disputes" ADD CONSTRAINT "marketplace_disputes_answer_check"
61
+ CHECK ("answer" IS NULL OR "answer" IN ('ACCEPT', 'REJECT', 'ALTERNATIVE'));
62
+ EXCEPTION WHEN duplicate_object THEN NULL; END $$;
63
+
64
+ DO $$ BEGIN
65
+ ALTER TABLE "marketplace_disputes" ADD CONSTRAINT "marketplace_disputes_settlement_check"
66
+ CHECK ("settlement" IS NULL OR "settlement" IN ('ACCEPTED', 'REJECTED', 'EXPIRED', 'ALTERNATIVE_REPLIED', 'OTHER'));
67
+ EXCEPTION WHEN duplicate_object THEN NULL; END $$;
68
+
69
+ DO $$ BEGIN
70
+ ALTER TABLE "marketplace_disputes" ADD CONSTRAINT "marketplace_disputes_amounts_check"
71
+ CHECK (("requested_amount_cents" IS NULL OR "requested_amount_cents" >= 0)
72
+ AND ("answer_amount_cents" IS NULL OR "answer_amount_cents" > 0)
73
+ AND ("answer_minutes" IS NULL OR "answer_minutes" > 0)
74
+ AND ("settled_amount_cents" IS NULL OR "settled_amount_cents" >= 0));
75
+ EXCEPTION WHEN duplicate_object THEN NULL; END $$;
76
+
77
+ -- One row per dispute: the dedupe of a redelivered or repeated opening.
78
+ CREATE UNIQUE INDEX IF NOT EXISTS "marketplace_disputes_provider_dispute_id_key"
79
+ ON "marketplace_disputes"("provider", "dispute_id");
80
+
81
+ -- The order's disputes (the card, the panel).
82
+ CREATE INDEX IF NOT EXISTS "marketplace_disputes_client_id_order_id_idx"
83
+ ON "marketplace_disputes"("client_id", "order_id");
84
+
85
+ -- The board's read: the live ones…
86
+ CREATE INDEX IF NOT EXISTS "marketplace_disputes_client_id_status_idx"
87
+ ON "marketplace_disputes"("client_id", "status");
88
+
89
+ -- …and those settled since the shift began.
90
+ CREATE INDEX IF NOT EXISTS "marketplace_disputes_client_id_settled_at_idx"
91
+ ON "marketplace_disputes"("client_id", "settled_at");
92
+
93
+ -- The outbound sweep reads only answers still SENDING.
94
+ CREATE INDEX IF NOT EXISTS "marketplace_disputes_sending_idx"
95
+ ON "marketplace_disputes"("answered_at")
96
+ WHERE "status" = 'SENDING';
@@ -0,0 +1,12 @@
1
+ -- @domains: marketplace
2
+ -- @12-apps/marketplace: the store's own courier reported to a marketplace (FUT-6166).
3
+ -- Additive and replay-safe: the step CHECK of `marketplace_status_updates` is
4
+ -- widened with the five Logistics steps, each a claim row of the `logistics`
5
+ -- outbound job. The previous release never writes them, so it is unaffected.
6
+ ALTER TABLE "marketplace_status_updates" DROP CONSTRAINT IF EXISTS "marketplace_status_updates_step_check";
7
+ ALTER TABLE "marketplace_status_updates" ADD CONSTRAINT "marketplace_status_updates_step_check"
8
+ CHECK ("step" IN (
9
+ 'READY', 'DISPATCHED', 'HANDED_OVER', 'CONCLUDED',
10
+ 'LOGISTICS_ASSIGNED', 'LOGISTICS_GOING_TO_ORIGIN', 'LOGISTICS_ARRIVED_AT_ORIGIN',
11
+ 'LOGISTICS_DISPATCHED', 'LOGISTICS_ARRIVED_AT_DESTINATION'
12
+ ));