@12-apps/marketplace 1.13.0 → 1.15.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 (72) hide show
  1. package/ADOPTING.md +258 -3
  2. package/README.md +27 -2
  3. package/dist/99food/index.d.ts +2 -2
  4. package/dist/99food/index.js +3 -3
  5. package/dist/{adapter-CQ4QiZPi.d.ts → adapter-CjVdMhZ2.d.ts} +177 -4
  6. package/dist/{chunk-CEWTV2TC.js → chunk-B4DYPQFE.js} +657 -251
  7. package/dist/chunk-B4DYPQFE.js.map +1 -0
  8. package/dist/{chunk-4J2KJ3ZW.js → chunk-BTKVZAJI.js} +1 -1
  9. package/dist/chunk-BTKVZAJI.js.map +1 -0
  10. package/dist/{chunk-BD7DS3XM.js → chunk-E4XJXHUK.js} +20 -1
  11. package/dist/chunk-E4XJXHUK.js.map +1 -0
  12. package/dist/{chunk-W57TITU4.js → chunk-FQI56NGC.js} +53 -6
  13. package/dist/chunk-FQI56NGC.js.map +1 -0
  14. package/dist/chunk-H2VQRD3B.js +16 -0
  15. package/dist/chunk-H2VQRD3B.js.map +1 -0
  16. package/dist/{chunk-NFJQQWG4.js → chunk-TRUK5ZBE.js} +12 -4
  17. package/dist/chunk-TRUK5ZBE.js.map +1 -0
  18. package/dist/{client-CCSnylou.d.ts → client-DgzCkl8u.d.ts} +1 -1
  19. package/dist/{engine-1KlJ_8jK.d.ts → engine-BSLdhAGC.d.ts} +134 -3
  20. package/dist/hono/index.d.ts +2 -2
  21. package/dist/hono/index.js +3 -2
  22. package/dist/hono/index.js.map +1 -1
  23. package/dist/ifood/index.d.ts +13 -3
  24. package/dist/ifood/index.js +219 -29
  25. package/dist/ifood/index.js.map +1 -1
  26. package/dist/index.d.ts +29 -5
  27. package/dist/index.js +59 -7
  28. package/dist/index.js.map +1 -1
  29. package/dist/keeta/index.d.ts +2 -2
  30. package/dist/keeta/index.js +3 -3
  31. package/dist/manifest/server.d.ts +4 -2
  32. package/dist/manifest/server.js +3 -2
  33. package/dist/manifest/server.js.map +1 -1
  34. package/dist/rappi/index.d.ts +1 -1
  35. package/dist/rappi/index.js +2 -2
  36. package/dist/server/index.d.ts +14 -5
  37. package/dist/server/index.js +3 -2
  38. package/package.json +1 -1
  39. package/prisma/marketplace.prisma +17 -3
  40. package/prisma/migrations/20261202120000_marketplace_ifood_conformity/migration.sql +25 -0
  41. package/src/core/acceptance.ts +12 -6
  42. package/src/core/acknowledge.ts +189 -0
  43. package/src/core/adapter.ts +74 -1
  44. package/src/core/cancellation.ts +10 -6
  45. package/src/core/conformity.ts +63 -0
  46. package/src/core/engine.ts +3 -2
  47. package/src/core/ingest.ts +7 -0
  48. package/src/core/link-store.ts +2 -4
  49. package/src/core/marketplace-confirmed.ts +229 -0
  50. package/src/core/order-reasons.ts +119 -0
  51. package/src/core/order-types.ts +8 -0
  52. package/src/core/outbound.ts +5 -1
  53. package/src/core/payload-read.ts +24 -0
  54. package/src/core/pipeline.ts +27 -1
  55. package/src/core/ports.ts +2 -0
  56. package/src/core/registry.ts +28 -2
  57. package/src/core/state.ts +10 -0
  58. package/src/core/status-job.ts +86 -3
  59. package/src/core/types.ts +117 -2
  60. package/src/ifood/index.ts +27 -4
  61. package/src/ifood/normalize.ts +38 -5
  62. package/src/ifood/order-details.ts +120 -0
  63. package/src/ifood/outbound.ts +131 -27
  64. package/src/index.ts +24 -0
  65. package/src/open-delivery/normalize.ts +9 -0
  66. package/src/server/jobs.ts +57 -4
  67. package/src/server/webhook.ts +27 -4
  68. package/dist/chunk-4J2KJ3ZW.js.map +0 -1
  69. package/dist/chunk-BD7DS3XM.js.map +0 -1
  70. package/dist/chunk-CEWTV2TC.js.map +0 -1
  71. package/dist/chunk-NFJQQWG4.js.map +0 -1
  72. package/dist/chunk-W57TITU4.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { a8 as MarketplaceDeliveredBy, ae as MarketplaceLinkAttemptDelegate, u as CatalogueItem, t as CatalogueImage, a as NormalizedMarketplaceOrder, N as NormalizedEvent, ap as StatusStep, i as NormalizedCourierEvent, a3 as MarketplaceCourierFacts, a1 as MarketplaceCourierAnswer, an as PickupCodeValidation, aa as MarketplaceHttp, Z as MarketplaceAppCredentialsPort, c as MarketplaceAdapter, l as MarketplaceProvider, a7 as MarketplaceCredentials, Q as CatalogueWarningCode, Y as LinkedMerchant, ad as MarketplaceLifecycle, a4 as MarketplaceCourierStep, a2 as MarketplaceCourierEngine, m as CancellationReason, ak as OutboundOrderRef, b as CatalogueMenuOptions, B as CatalogueReadResult } from './adapter-CQ4QiZPi.js';
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';
2
2
 
3
3
  /** What the engine tells the host about the order a lifecycle event names. */
4
4
  interface MarketplaceLifecycleFacts {
@@ -23,6 +23,7 @@ type MarketplaceLifecycleAnswer = "moved" | "unchanged" | {
23
23
  * cancellation ended. Plain data with no engine dependency; `./ports`
24
24
  * re-exports every name, so a host imports them from there as before.
25
25
  */
26
+
26
27
  /**
27
28
  * One order line after the engine has matched it against the SKU map.
28
29
  * `subjectRef` is the host catalog id, or null when the SKU was never mapped —
@@ -38,6 +39,12 @@ interface ResolvedOrderLine {
38
39
  note: string | null;
39
40
  subjectRef: string | null;
40
41
  variationRef: string | null;
42
+ /**
43
+ * OPTIONAL (FUT-5803). The line's options, as the marketplace priced them;
44
+ * present only when the normalized line carries some. `unitPriceCents` is
45
+ * then the item alone (`normalizedLineTotalCents`).
46
+ */
47
+ options?: NormalizedLineOption[];
41
48
  }
42
49
  /** What the acceptance queue shows about an order, resolved by the host. */
43
50
  interface MarketplaceOrderSummary {
@@ -132,6 +139,10 @@ interface MarketplaceDb {
132
139
  findMany(args: unknown): Promise<unknown[]>;
133
140
  create(args: unknown): Promise<unknown>;
134
141
  update(args: unknown): Promise<unknown>;
142
+ /** The acknowledgment's stamp (FUT-5984). */
143
+ updateMany(args: unknown): Promise<{
144
+ count: number;
145
+ }>;
135
146
  };
136
147
  marketplaceAcceptance: {
137
148
  findFirst(args: unknown): Promise<unknown>;
@@ -884,6 +895,107 @@ declare class CatalogueRetryError extends Error {
884
895
  /** The dedupe key: one queued run per (row, ask). A re-ask carries a new instant, so it is never swallowed. */
885
896
  declare function catalogueDedupeKey(payload: CatalogueJobPayload, requestedAt: Date): string;
886
897
 
898
+ /**
899
+ * Acknowledging recorded events to the marketplace (FUT-5984, iFood's
900
+ * `POST /events/v1.0/events/acknowledgment`).
901
+ *
902
+ * The webhook request only QUEUES it, after the inbox row is written: one
903
+ * `marketplace.acknowledge` job per fresh delivery, keyed by its row. The job
904
+ * sends every event of that store still owed (recorded inside the
905
+ * marketplace's retention, `acknowledged_at` null) in one call, up to the
906
+ * adapter's batch size, and stamps exactly those rows. The stamp is the
907
+ * marker: a second run finds nothing and calls nobody; a failed call leaves
908
+ * the rows owed, and the reconcile pass re-queues a job per store that still
909
+ * owes some. Nothing here ever holds or fails an ingest.
910
+ */
911
+ /** The wire name, `<namespace>.<blueprint>`. */
912
+ declare const MARKETPLACE_ACKNOWLEDGE_JOB = "marketplace.acknowledge";
913
+ /** The job's payload: whose events, on which marketplace. Identifiers only. */
914
+ interface AcknowledgeJobPayload {
915
+ clientId: string;
916
+ provider: string;
917
+ }
918
+ /** What one run did. */
919
+ type AcknowledgeOutcome = {
920
+ kind: "skipped";
921
+ reason: string;
922
+ } | {
923
+ kind: "done";
924
+ acknowledged: number;
925
+ } | {
926
+ kind: "failed";
927
+ reason: string;
928
+ };
929
+ /** Thrown so the queue retries. */
930
+ declare class AcknowledgeRetryError extends Error {
931
+ constructor(message: string);
932
+ }
933
+
934
+ /**
935
+ * An order's own cancellation reasons (FUT-5984, iFood's
936
+ * `GET /order/v1.0/orders/{id}/cancellationReasons`): read once, in the
937
+ * `marketplace.cancellation-reasons` job queued after the ingest's commit, and
938
+ * kept on the acceptance row (`cancellation_reasons`) for the order's life.
939
+ * The adapter's static list is the fallback while, or when, that read did not
940
+ * land: a refusal is never held on the marketplace.
941
+ */
942
+ /** The wire name, `<namespace>.<blueprint>`. */
943
+ declare const MARKETPLACE_CANCELLATION_REASONS_JOB = "marketplace.cancellation-reasons";
944
+ /** The job's payload: identifiers only. */
945
+ interface CancellationReasonsJobPayload {
946
+ clientId: string;
947
+ orderId: string;
948
+ }
949
+ /** What one run did. */
950
+ type CancellationReasonsOutcome = {
951
+ kind: "skipped";
952
+ reason: string;
953
+ } | {
954
+ kind: "done";
955
+ count: number;
956
+ } | {
957
+ kind: "failed";
958
+ reason: string;
959
+ };
960
+ /** Thrown so the queue retries. */
961
+ declare class CancellationReasonsRetryError extends Error {
962
+ constructor(message: string);
963
+ }
964
+
965
+ /** A job run's attempt, as the runner says. */
966
+ interface Attempt {
967
+ attempt: number;
968
+ maxAttempts: number;
969
+ }
970
+ /**
971
+ * The engine calls of the iFood homologation conformity (FUT-5984): the
972
+ * webhook's answer status and presence heartbeat, the events'
973
+ * acknowledgment, and each order's own cancellation reasons. Provider-neutral:
974
+ * every answer is the adapter's.
975
+ */
976
+ interface MarketplaceConformityEngine {
977
+ /** The status a recorded delivery is answered with: the adapter's, else 200. */
978
+ answerStatus(provider: string): number;
979
+ /** The delivery is the marketplace's presence heartbeat, not an event, or null. */
980
+ presence(provider: string, payload: unknown): PresenceProbe | null;
981
+ /**
982
+ * Is this delivery signed by the software's own app on this marketplace, in
983
+ * either environment (`appCredentials`)? No statement: what proves a
984
+ * heartbeat that names no store.
985
+ */
986
+ signedByApp(provider: string, rawBody: string, signature: string | null): Promise<boolean>;
987
+ /** One order's reasons for the refusal dialog: its own, read from the marketplace, else the static list. */
988
+ orderReasons(clientId: string, orderId: string): Promise<readonly CancellationReason[]>;
989
+ /** Run one acknowledgment (the `marketplace.acknowledge` job's body). */
990
+ runAcknowledge(payload: AcknowledgeJobPayload, attempt: Attempt): Promise<AcknowledgeOutcome>;
991
+ /** Re-queue the stores still owing an acknowledgment (run by the reconcile pass). */
992
+ sweepAcknowledgements(): Promise<{
993
+ requeued: number;
994
+ }>;
995
+ /** Read one order's reasons (the `marketplace.cancellation-reasons` job's body). */
996
+ runCancellationReasons(payload: CancellationReasonsJobPayload, attempt: Attempt): Promise<CancellationReasonsOutcome>;
997
+ }
998
+
887
999
  /**
888
1000
  * Fetching an order the event only announced — the engine's half of a
889
1001
  * marketplace whose events carry no order body (Open Delivery's `CREATED`).
@@ -1396,6 +1508,20 @@ type DeliveryOutcome = {
1396
1508
  kind: "courier";
1397
1509
  orderId: string;
1398
1510
  step: MarketplaceCourierStep;
1511
+ }
1512
+ /**
1513
+ * The store accepted it in the marketplace's own app (FUT-5653): `accepted`
1514
+ * when the host admitted it here too, else it waits AWAITING for a person
1515
+ * (with the host's `refusal`, when it refused), never expired.
1516
+ */
1517
+ | {
1518
+ kind: "confirmedByMarketplace";
1519
+ orderId: string;
1520
+ accepted: boolean;
1521
+ refusal?: {
1522
+ code: string;
1523
+ message: string;
1524
+ };
1399
1525
  } | {
1400
1526
  kind: "cancelled";
1401
1527
  } | {
@@ -1433,10 +1559,15 @@ interface MarketplaceOrderState {
1433
1559
  cancellationFailure: CancellationFailureReason | null;
1434
1560
  /** The adapter's app link, or null when no adapter is registered for it. */
1435
1561
  appUrl: string | null;
1562
+ /**
1563
+ * This order's own reasons, read from the marketplace (FUT-5984); null while
1564
+ * or when they were not read: the adapter's static `reasons(provider)` then.
1565
+ */
1566
+ cancellationReasons: readonly CancellationReason[] | null;
1436
1567
  }
1437
1568
 
1438
1569
  /** Everything the mounted engine can do, with the ports and adapters bound in. */
1439
- interface MarketplaceEngine extends MarketplaceCourierEngine {
1570
+ interface MarketplaceEngine extends MarketplaceCourierEngine, MarketplaceConformityEngine {
1440
1571
  /** Every registered marketplace, in registration order. */
1441
1572
  providers(): readonly MarketplaceProvider[];
1442
1573
  /** Whether a provider id (a URL segment, a body field) names a registered adapter. */
@@ -1673,4 +1804,4 @@ interface MarketplaceEngine extends MarketplaceCourierEngine {
1673
1804
  */
1674
1805
  declare function createMarketplaceEngine(config: MarketplaceEngineConfig): MarketplaceEngine;
1675
1806
 
1676
- export { type MarketplaceAuthMode as $, type AcceptanceDecision as A, type BulkProblem as B, type CancellationFailureReason as C, type DecideManyResult as D, type DeliveryOutcome as E, type ExpirySweepResult as F, type FetchOrderJobPayload as G, type FetchOrderOutcome as H, FetchOrderRetryError as I, type InformStatusInput as J, type IngestResult as K, type IngestSettings as L, type IngestionTarget as M, type IntegrationRowInput as N, type LinkFailure as O, type LinkFinished as P, type LinkPendingView as Q, type LinkRefusalCode as R, MARKETPLACE_AVAILABILITY_JOB as S, MARKETPLACE_CATALOGUE_JOB as T, MARKETPLACE_FETCH_ORDER_JOB as U, MARKETPLACE_OUTBOUND_JOB as V, type MarketplaceAdmission as W, type MarketplaceAdmissionRequest as X, type MarketplaceAdmissionResult as Y, type MarketplaceAuditEntry as Z, type MarketplaceAuditPort as _, type AcceptanceStatus as a, type MarketplaceCataloguePort as a0, type MarketplaceClockPort as a1, type MarketplaceDb as a2, type MarketplaceEngine as a3, type MarketplaceEngineConfig as a4, type MarketplaceEnqueuePort as a5, type MarketplaceIntegrationView as a6, type MarketplaceLifecycleAnswer as a7, type MarketplaceLifecycleFacts as a8, type MarketplaceLogger as a9, type StorePauseFailureCode as aA, type StorePauseState as aB, type StorePauseWanted as aC, availabilityDedupeKey as aD, catalogueDedupeKey as aE, createMarketplaceEngine as aF, outboundDedupeKey as aG, type MarketplaceMenuLinkView as aa, type MarketplaceOrderPort as ab, type MarketplaceOrderState as ac, type MarketplaceOrderSummary as ad, type MarketplacePorts as ae, type MarketplaceRefusal as af, type MarketplaceSecretsPort as ag, type MenuLinkRowInput as ah, OUTBOUND_GIVE_UP_MS as ai, OUTBOUND_STALE_MS as aj, type OutboundAction as ak, type OutboundAttempt as al, type OutboundJobPayload as am, type OutboundOutcome as an, OutboundRetryError as ao, type OutboundSweepResult as ap, type PauseOutcome as aq, type PauseStoreInput as ar, type PauseStoreResult as as, type PendingAcceptance as at, type PendingInboxEvent as au, type ResolvedOrderLine as av, type ResumeOutcome as aw, STORE_PAUSE_LEASE_MS as ax, type SaveMarketplaceIntegrationInput as ay, type StoreAvailabilityView as az, type AvailabilityJobPayload as b, type AvailabilityOutcome as c, AvailabilityRetryError as d, type AvailabilitySweepResult as e, type BulkProblemCode as f, type BulkResult as g, type CancellationStatus as h, type CatalogueAction as i, type CatalogueActionResult as j, type CatalogueDocumentResult as k, type CatalogueFailedAction as l, type CatalogueFailureCode as m, type CatalogueJobPayload as n, type CatalogueOutcome as o, type CataloguePublicationView as p, type CataloguePublishInput as q, type CatalogueRefusalCode as r, CatalogueRetryError as s, type CatalogueStatus as t, type CatalogueTarget as u, type DecidedRow as v, type DecisionInput as w, type DecisionProblem as x, type DecisionProblemCode as y, type DecisionResult as z };
1807
+ 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 };
@@ -1,7 +1,7 @@
1
1
  import { Hono, Context } from 'hono';
2
2
  import { ApiMarketplace, MarketplaceApiConfig, MarketplaceActor } from '../server/index.js';
3
- import '../engine-1KlJ_8jK.js';
4
- import '../adapter-CQ4QiZPi.js';
3
+ import '../engine-BSLdhAGC.js';
4
+ import '../adapter-CjVdMhZ2.js';
5
5
  import '@12-apps/wiring';
6
6
  import 'zod';
7
7
 
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  createApiMarketplace
3
- } from "../chunk-W57TITU4.js";
3
+ } from "../chunk-FQI56NGC.js";
4
4
  import "../chunk-SGOTN5PX.js";
5
- import "../chunk-CEWTV2TC.js";
5
+ import "../chunk-B4DYPQFE.js";
6
+ import "../chunk-H2VQRD3B.js";
6
7
  import {
7
8
  __name
8
9
  } from "../chunk-7QVYU63E.js";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/index.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { Context } from \"hono\";\n\nimport type { WireRoute } from \"@12-apps/wiring\";\n\nimport { createApiMarketplace, type ApiMarketplace, type MarketplaceActor, type MarketplaceApiConfig } from \"../server\";\n\n/**\n * `@12-apps/marketplace/hono` — the marketplace routes as one mountable\n * router.\n *\n * The framework-neutral descriptors in `./server` are the contract; this is\n * the adapter for the framework the origin host runs, behind its own subpath\n * with `hono` as an OPTIONAL peer. A host writes:\n *\n * const marketplace = marketplaceRouter({ engine, copy, tenantBySlug, logger, resolveActor });\n * app.route(\"/api\", marketplace.router);\n *\n * and keeps what is genuinely its own: who the caller is, and whether they\n * hold the route's declared permission (`authorize`). The webhook is never\n * guarded: it is a marketplace's server, verified by signature inside.\n */\n\n/** Resolve the caller for an authenticated route. `null` answers 401. */\nexport type ResolveMarketplaceActor = (\n c: Context,\n permission: string | undefined,\n) => Promise<MarketplaceActor | null> | MarketplaceActor | null;\n\nexport interface MarketplaceHonoConfig extends MarketplaceApiConfig {\n /**\n * Who the caller is, given the permission the route declares. The host\n * resolves the tenant from `:tenantSlug` and refuses a caller without the\n * permission by answering null (401) — or by throwing its own 403.\n */\n resolveActor: ResolveMarketplaceActor;\n}\n\nexport interface MarketplaceHono extends ApiMarketplace {\n router: Hono;\n}\n\n/** A JSON body, only when the caller said it was JSON. */\nasync function readBody(c: Context): Promise<unknown> {\n if (c.req.method === \"GET\" || c.req.method === \"DELETE\") return undefined;\n const type = (c.req.header(\"content-type\") ?? \"\").split(\";\")[0]?.trim().toLowerCase() ?? \"\";\n if (type !== \"application/json\" && !type.endsWith(\"+json\")) return undefined;\n try {\n return await c.req.json();\n } catch {\n return undefined;\n }\n}\n\nexport function marketplaceRouter(config: MarketplaceHonoConfig): MarketplaceHono {\n const api = createApiMarketplace(config);\n const router = new Hono();\n\n // Mounted IN DESCRIPTOR ORDER, which any adapter must preserve.\n for (const route of api.routes) {\n const handler = async (c: Context): Promise<Response> => {\n const params = c.req.param() as Record<string, string | undefined>;\n const query = c.req.query() as Record<string, string | undefined>;\n if (route.kind === \"webhook\") {\n // The raw request, untouched: the signature is over these bytes.\n const webhook = route as WireRoute<unknown>;\n const answer = await webhook.handle({ actor: undefined, params, query, request: c.req.raw });\n return c.json(answer.body as Record<string, unknown>, answer.status as 200);\n }\n const actor = await config.resolveActor(c, route.permission);\n if (!actor) return c.json({ error: \"unauthorized\" }, 401);\n const guarded = route as WireRoute<MarketplaceActor>;\n const answer = await guarded.handle({ actor, params, query, body: await readBody(c) });\n return c.json(answer.body as Record<string, unknown>, answer.status as 200);\n };\n switch (route.method) {\n case \"GET\":\n router.get(route.path, handler);\n break;\n case \"POST\":\n router.post(route.path, handler);\n break;\n case \"PUT\":\n router.put(route.path, handler);\n break;\n case \"DELETE\":\n router.delete(route.path, handler);\n break;\n default:\n throw new Error(`@12-apps/marketplace/hono cannot mount ${route.method} ${route.path}. Add a case.`);\n }\n }\n\n return { ...api, router };\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,YAAY;AA2CrB,eAAe,SAAS,GAA8B;AACpD,MAAI,EAAE,IAAI,WAAW,SAAS,EAAE,IAAI,WAAW,SAAU,QAAO;AAChE,QAAM,QAAQ,EAAE,IAAI,OAAO,cAAc,KAAK,IAAI,MAAM,GAAG,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,KAAK;AACzF,MAAI,SAAS,sBAAsB,CAAC,KAAK,SAAS,OAAO,EAAG,QAAO;AACnE,MAAI;AACF,WAAO,MAAM,EAAE,IAAI,KAAK;AAAA,EAC1B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AATe;AAWR,SAAS,kBAAkB,QAAgD;AAChF,QAAM,MAAM,qBAAqB,MAAM;AACvC,QAAM,SAAS,IAAI,KAAK;AAGxB,aAAW,SAAS,IAAI,QAAQ;AAC9B,UAAM,UAAU,8BAAO,MAAkC;AACvD,YAAM,SAAS,EAAE,IAAI,MAAM;AAC3B,YAAM,QAAQ,EAAE,IAAI,MAAM;AAC1B,UAAI,MAAM,SAAS,WAAW;AAE5B,cAAM,UAAU;AAChB,cAAMA,UAAS,MAAM,QAAQ,OAAO,EAAE,OAAO,QAAW,QAAQ,OAAO,SAAS,EAAE,IAAI,IAAI,CAAC;AAC3F,eAAO,EAAE,KAAKA,QAAO,MAAiCA,QAAO,MAAa;AAAA,MAC5E;AACA,YAAM,QAAQ,MAAM,OAAO,aAAa,GAAG,MAAM,UAAU;AAC3D,UAAI,CAAC,MAAO,QAAO,EAAE,KAAK,EAAE,OAAO,eAAe,GAAG,GAAG;AACxD,YAAM,UAAU;AAChB,YAAM,SAAS,MAAM,QAAQ,OAAO,EAAE,OAAO,QAAQ,OAAO,MAAM,MAAM,SAAS,CAAC,EAAE,CAAC;AACrF,aAAO,EAAE,KAAK,OAAO,MAAiC,OAAO,MAAa;AAAA,IAC5E,GAdgB;AAehB,YAAQ,MAAM,QAAQ;AAAA,MACpB,KAAK;AACH,eAAO,IAAI,MAAM,MAAM,OAAO;AAC9B;AAAA,MACF,KAAK;AACH,eAAO,KAAK,MAAM,MAAM,OAAO;AAC/B;AAAA,MACF,KAAK;AACH,eAAO,IAAI,MAAM,MAAM,OAAO;AAC9B;AAAA,MACF,KAAK;AACH,eAAO,OAAO,MAAM,MAAM,OAAO;AACjC;AAAA,MACF;AACE,cAAM,IAAI,MAAM,0CAA0C,MAAM,MAAM,IAAI,MAAM,IAAI,eAAe;AAAA,IACvG;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,KAAK,OAAO;AAC1B;AAxCgB;","names":["answer"]}
1
+ {"version":3,"sources":["../../src/hono/index.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { Context } from \"hono\";\n\nimport type { WireRoute } from \"@12-apps/wiring\";\n\nimport { createApiMarketplace, type ApiMarketplace, type MarketplaceActor, type MarketplaceApiConfig } from \"../server\";\n\n/**\n * `@12-apps/marketplace/hono` — the marketplace routes as one mountable\n * router.\n *\n * The framework-neutral descriptors in `./server` are the contract; this is\n * the adapter for the framework the origin host runs, behind its own subpath\n * with `hono` as an OPTIONAL peer. A host writes:\n *\n * const marketplace = marketplaceRouter({ engine, copy, tenantBySlug, logger, resolveActor });\n * app.route(\"/api\", marketplace.router);\n *\n * and keeps what is genuinely its own: who the caller is, and whether they\n * hold the route's declared permission (`authorize`). The webhook is never\n * guarded: it is a marketplace's server, verified by signature inside.\n */\n\n/** Resolve the caller for an authenticated route. `null` answers 401. */\nexport type ResolveMarketplaceActor = (\n c: Context,\n permission: string | undefined,\n) => Promise<MarketplaceActor | null> | MarketplaceActor | null;\n\nexport interface MarketplaceHonoConfig extends MarketplaceApiConfig {\n /**\n * Who the caller is, given the permission the route declares. The host\n * resolves the tenant from `:tenantSlug` and refuses a caller without the\n * permission by answering null (401) — or by throwing its own 403.\n */\n resolveActor: ResolveMarketplaceActor;\n}\n\nexport interface MarketplaceHono extends ApiMarketplace {\n router: Hono;\n}\n\n/** A JSON body, only when the caller said it was JSON. */\nasync function readBody(c: Context): Promise<unknown> {\n if (c.req.method === \"GET\" || c.req.method === \"DELETE\") return undefined;\n const type = (c.req.header(\"content-type\") ?? \"\").split(\";\")[0]?.trim().toLowerCase() ?? \"\";\n if (type !== \"application/json\" && !type.endsWith(\"+json\")) return undefined;\n try {\n return await c.req.json();\n } catch {\n return undefined;\n }\n}\n\nexport function marketplaceRouter(config: MarketplaceHonoConfig): MarketplaceHono {\n const api = createApiMarketplace(config);\n const router = new Hono();\n\n // Mounted IN DESCRIPTOR ORDER, which any adapter must preserve.\n for (const route of api.routes) {\n const handler = async (c: Context): Promise<Response> => {\n const params = c.req.param() as Record<string, string | undefined>;\n const query = c.req.query() as Record<string, string | undefined>;\n if (route.kind === \"webhook\") {\n // The raw request, untouched: the signature is over these bytes.\n const webhook = route as WireRoute<unknown>;\n const answer = await webhook.handle({ actor: undefined, params, query, request: c.req.raw });\n return c.json(answer.body as Record<string, unknown>, answer.status as 200);\n }\n const actor = await config.resolveActor(c, route.permission);\n if (!actor) return c.json({ error: \"unauthorized\" }, 401);\n const guarded = route as WireRoute<MarketplaceActor>;\n const answer = await guarded.handle({ actor, params, query, body: await readBody(c) });\n return c.json(answer.body as Record<string, unknown>, answer.status as 200);\n };\n switch (route.method) {\n case \"GET\":\n router.get(route.path, handler);\n break;\n case \"POST\":\n router.post(route.path, handler);\n break;\n case \"PUT\":\n router.put(route.path, handler);\n break;\n case \"DELETE\":\n router.delete(route.path, handler);\n break;\n default:\n throw new Error(`@12-apps/marketplace/hono cannot mount ${route.method} ${route.path}. Add a case.`);\n }\n }\n\n return { ...api, router };\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,YAAY;AA2CrB,eAAe,SAAS,GAA8B;AACpD,MAAI,EAAE,IAAI,WAAW,SAAS,EAAE,IAAI,WAAW,SAAU,QAAO;AAChE,QAAM,QAAQ,EAAE,IAAI,OAAO,cAAc,KAAK,IAAI,MAAM,GAAG,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,KAAK;AACzF,MAAI,SAAS,sBAAsB,CAAC,KAAK,SAAS,OAAO,EAAG,QAAO;AACnE,MAAI;AACF,WAAO,MAAM,EAAE,IAAI,KAAK;AAAA,EAC1B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AATe;AAWR,SAAS,kBAAkB,QAAgD;AAChF,QAAM,MAAM,qBAAqB,MAAM;AACvC,QAAM,SAAS,IAAI,KAAK;AAGxB,aAAW,SAAS,IAAI,QAAQ;AAC9B,UAAM,UAAU,8BAAO,MAAkC;AACvD,YAAM,SAAS,EAAE,IAAI,MAAM;AAC3B,YAAM,QAAQ,EAAE,IAAI,MAAM;AAC1B,UAAI,MAAM,SAAS,WAAW;AAE5B,cAAM,UAAU;AAChB,cAAMA,UAAS,MAAM,QAAQ,OAAO,EAAE,OAAO,QAAW,QAAQ,OAAO,SAAS,EAAE,IAAI,IAAI,CAAC;AAC3F,eAAO,EAAE,KAAKA,QAAO,MAAiCA,QAAO,MAAa;AAAA,MAC5E;AACA,YAAM,QAAQ,MAAM,OAAO,aAAa,GAAG,MAAM,UAAU;AAC3D,UAAI,CAAC,MAAO,QAAO,EAAE,KAAK,EAAE,OAAO,eAAe,GAAG,GAAG;AACxD,YAAM,UAAU;AAChB,YAAM,SAAS,MAAM,QAAQ,OAAO,EAAE,OAAO,QAAQ,OAAO,MAAM,MAAM,SAAS,CAAC,EAAE,CAAC;AACrF,aAAO,EAAE,KAAK,OAAO,MAAiC,OAAO,MAAa;AAAA,IAC5E,GAdgB;AAehB,YAAQ,MAAM,QAAQ;AAAA,MACpB,KAAK;AACH,eAAO,IAAI,MAAM,MAAM,OAAO;AAC9B;AAAA,MACF,KAAK;AACH,eAAO,KAAK,MAAM,MAAM,OAAO;AAC/B;AAAA,MACF,KAAK;AACH,eAAO,IAAI,MAAM,MAAM,OAAO;AAC9B;AAAA,MACF,KAAK;AACH,eAAO,OAAO,MAAM,MAAM,OAAO;AACjC;AAAA,MACF;AACE,cAAM,IAAI,MAAM,0CAA0C,MAAM,MAAM,IAAI,MAAM,IAAI,eAAe;AAAA,IACvG;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,KAAK,OAAO;AAC1B;AAxCgB;","names":["answer"]}
@@ -1,4 +1,4 @@
1
- import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, A as AdapterCallContext, F as FetchOrderResult, d as PushCatalogue, e as CatalogueItemOut, f as CatalogueReader, g as MarketplaceLinking, h as MarketplaceCourierApi, i as NormalizedCourierEvent, M as MarketplaceAvailability, S as StorePauseRequest, j as StorePauseResult, k as StorePauseRef, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-CQ4QiZPi.js';
1
+ import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, A as AdapterCallContext, F as FetchOrderResult, d as PushCatalogue, e as CatalogueItemOut, f as CatalogueReader, g as MarketplaceLinking, h as MarketplaceCourierApi, i as NormalizedCourierEvent, M as MarketplaceAvailability, S as StorePauseRequest, j as StorePauseResult, k as StorePauseRef, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-CjVdMhZ2.js';
2
2
 
3
3
  /**
4
4
  * The words the iFood adapter needs from its host, and nothing else.
@@ -47,6 +47,13 @@ declare function readIfoodOrder(payload: unknown, externalOrderId: string, missi
47
47
  declare function normalizeIfoodEvent(payload: unknown, options: {
48
48
  missingStreetNumber: string;
49
49
  }): NormalizedEvent | null;
50
+ /**
51
+ * iFood's `KEEPALIVE` (FUT-5984): `{ code, fullCode, id }`, and `merchantIds`
52
+ * in the per-merchant mode. Null for any other delivery.
53
+ */
54
+ declare function readIfoodPresence(payload: unknown): {
55
+ merchantIds: readonly string[] | null;
56
+ } | null;
50
57
 
51
58
  /** Fetch one order iFood's event only named. Never throws: no answer is a retry. */
52
59
  declare function ifoodFetchOrder(ctx: AdapterCallContext, ref: {
@@ -136,7 +143,10 @@ interface IfoodAdapterConfig {
136
143
  /** The words the adapter needs: reason labels and the missing-number text. Required. */
137
144
  copy: IfoodAdapterCopy;
138
145
  }
139
- /** Build the iFood adapter. Its reasons are static: a dialog never waits on iFood. */
146
+ /**
147
+ * Build the iFood adapter. Its static reasons are the fallback: each order's
148
+ * own are read from iFood in a job after its ingest (FUT-5984).
149
+ */
140
150
  declare function createIfoodAdapter(config: IfoodAdapterConfig): MarketplaceAdapter;
141
151
 
142
- export { IFOOD_AVAILABILITY, IFOOD_CANCELLATION_ANSWER_WINDOW_MS, IFOOD_CATALOGUE, IFOOD_CATALOGUE_READER, IFOOD_COURIER, IFOOD_IMAGE_BASE_URL, IFOOD_LINKING, IFOOD_PROVIDER, IFOOD_REASON_CODES, type IfoodAdapterConfig, type IfoodAdapterCopy, type IfoodReasonCode, createIfoodAdapter, ifoodFetchOrder, ifoodItemBody, ifoodItemId, ifoodLocalTime, ifoodPause, ifoodProductId, ifoodResume, normalizeIfoodEvent, readIfoodCourierEvent, readIfoodOrder, verifyIfoodSignature };
152
+ export { IFOOD_AVAILABILITY, IFOOD_CANCELLATION_ANSWER_WINDOW_MS, IFOOD_CATALOGUE, IFOOD_CATALOGUE_READER, IFOOD_COURIER, IFOOD_IMAGE_BASE_URL, IFOOD_LINKING, IFOOD_PROVIDER, IFOOD_REASON_CODES, type IfoodAdapterConfig, type IfoodAdapterCopy, type IfoodReasonCode, createIfoodAdapter, ifoodFetchOrder, ifoodItemBody, ifoodItemId, ifoodLocalTime, ifoodPause, ifoodProductId, ifoodResume, normalizeIfoodEvent, readIfoodCourierEvent, readIfoodOrder, readIfoodPresence, verifyIfoodSignature };