@12-apps/marketplace 1.8.0 → 1.10.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 (67) hide show
  1. package/ADOPTING.md +27 -1
  2. package/README.md +103 -9
  3. package/dist/99food/index.d.ts +30 -54
  4. package/dist/99food/index.js +60 -418
  5. package/dist/99food/index.js.map +1 -1
  6. package/dist/{chunk-BMCERPQX.js → chunk-2BA2EHNF.js} +16 -6
  7. package/dist/chunk-2BA2EHNF.js.map +1 -0
  8. package/dist/chunk-PYHNM47K.js +478 -0
  9. package/dist/chunk-PYHNM47K.js.map +1 -0
  10. package/dist/{chunk-6N2HEV3U.js → chunk-WVZ2IXFH.js} +3 -3
  11. package/dist/{chunk-NP4EYKPO.js → chunk-ZO4S3LF4.js} +5 -3
  12. package/dist/chunk-ZO4S3LF4.js.map +1 -0
  13. package/dist/client-B4EQCRD_.d.ts +20 -0
  14. package/dist/{engine-wmW-VuBL.d.ts → engine-DK3iV_Kk.d.ts} +91 -60
  15. package/dist/hono/index.d.ts +1 -1
  16. package/dist/hono/index.js +3 -3
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +17 -6
  19. package/dist/index.js.map +1 -1
  20. package/dist/keeta/en-US.d.ts +19 -0
  21. package/dist/keeta/en-US.js +23 -0
  22. package/dist/keeta/en-US.js.map +1 -0
  23. package/dist/keeta/index.d.ts +253 -0
  24. package/dist/keeta/index.js +388 -0
  25. package/dist/keeta/index.js.map +1 -0
  26. package/dist/keeta/pt-BR.d.ts +23 -0
  27. package/dist/keeta/pt-BR.js +23 -0
  28. package/dist/keeta/pt-BR.js.map +1 -0
  29. package/dist/manifest/index.d.ts +4 -1
  30. package/dist/manifest/index.js +1 -1
  31. package/dist/manifest/server.d.ts +1 -1
  32. package/dist/manifest/server.js +3 -3
  33. package/dist/server/index.d.ts +6 -2
  34. package/dist/server/index.js +3 -3
  35. package/package.json +14 -2
  36. package/prisma/marketplace.prisma +6 -0
  37. package/prisma/migrations/20261126230000_marketplace_menu_link_variation/migration.sql +11 -0
  38. package/src/99food/catalogue.ts +19 -89
  39. package/src/99food/copy.ts +4 -19
  40. package/src/99food/index.ts +28 -33
  41. package/src/99food/normalize.ts +11 -253
  42. package/src/99food/outbound.ts +29 -270
  43. package/src/99food/pause.ts +7 -22
  44. package/src/core/bulk.ts +34 -7
  45. package/src/core/ingest.ts +2 -1
  46. package/src/core/menu-links.ts +36 -6
  47. package/src/core/order-types.ts +74 -0
  48. package/src/core/ports.ts +23 -65
  49. package/src/index.ts +2 -1
  50. package/src/keeta/authorization.ts +226 -0
  51. package/src/keeta/copy.ts +27 -0
  52. package/src/keeta/en-US.ts +19 -0
  53. package/src/keeta/index.ts +162 -0
  54. package/src/keeta/merchant.ts +70 -0
  55. package/src/keeta/normalize.ts +131 -0
  56. package/src/keeta/outbound.ts +55 -0
  57. package/src/keeta/pt-BR.ts +23 -0
  58. package/src/keeta/signature.ts +85 -0
  59. package/src/open-delivery/client.ts +185 -0
  60. package/src/open-delivery/merchant.ts +126 -0
  61. package/src/open-delivery/normalize.ts +269 -0
  62. package/src/open-delivery/orders.ts +241 -0
  63. package/src/open-delivery/reasons.ts +26 -0
  64. package/src/server/mcp.ts +7 -2
  65. package/dist/chunk-BMCERPQX.js.map +0 -1
  66. package/dist/chunk-NP4EYKPO.js.map +0 -1
  67. /package/dist/{chunk-6N2HEV3U.js.map → chunk-WVZ2IXFH.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import { y as DecisionProblemCode, f as BulkProblemCode, _ as MarketplaceEngine, a4 as MarketplaceLogger, ah as OutboundJobPayload, G as FetchOrderJobPayload, n as CatalogueJobPayload, b as AvailabilityJobPayload } from '../engine-wmW-VuBL.js';
1
+ import { y as DecisionProblemCode, f as BulkProblemCode, _ as MarketplaceEngine, a4 as MarketplaceLogger, ah as OutboundJobPayload, G as FetchOrderJobPayload, n as CatalogueJobPayload, b as AvailabilityJobPayload } from '../engine-DK3iV_Kk.js';
2
2
  import { WireRoute, WireJobBlueprint } from '@12-apps/wiring';
3
3
  import { z } from 'zod';
4
4
  import '../adapter-CYJzu1c9.js';
@@ -225,6 +225,7 @@ declare const upsertMarketplaceMenuLinksBody: z.ZodObject<{
225
225
  externalSku: z.ZodString;
226
226
  externalName: z.ZodOptional<z.ZodString>;
227
227
  menuItemId: z.ZodNullable<z.ZodString>;
228
+ variationId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
228
229
  }, z.core.$strict>>;
229
230
  }, z.core.$strict>;
230
231
  /** Which queued orders to read. */
@@ -410,6 +411,7 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
410
411
  externalSku: z.ZodString;
411
412
  externalName: z.ZodString;
412
413
  menuItemId: z.ZodNullable<z.ZodString>;
414
+ variationId: z.ZodNullable<z.ZodString>;
413
415
  lastSeenAt: z.ZodString;
414
416
  }, z.core.$strip>>;
415
417
  }, z.core.$strip>;
@@ -420,7 +422,7 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
420
422
  readonly operationId: "upsertMarketplaceMenuLinks";
421
423
  readonly method: "PUT";
422
424
  readonly path: "/admin/{tenantSlug}/marketplace/menu-links";
423
- readonly summary: "Map one or many external marketplace SKUs to the store's catalog ids, or unmap them with `menuItemId: null`, in one all-or-nothing call keyed by (`provider`, `externalSku`). A SKU never seen is created, so a store can map ahead of the first order. Applies to orders ingested from now on. Any problem (a catalog id that is not the store's, a repeated SKU) writes nothing; `validateOnly: true` checks without writing.";
425
+ readonly summary: "Map one or many external marketplace SKUs to the store's catalog ids, or unmap them with `menuItemId: null`; `variationId` maps a SKU to one variation of its catalog id instead of the item alone, in one all-or-nothing call keyed by (`provider`, `externalSku`). A SKU never seen is created, so a store can map ahead of the first order. Applies to orders ingested from now on. Any problem (a catalog id that is not the store's, a variation that is not one of its catalog id's, a repeated SKU) writes nothing; `validateOnly: true` checks without writing.";
424
426
  readonly tags: readonly ["marketplace"];
425
427
  readonly params: z.ZodObject<{
426
428
  tenantSlug: z.ZodString;
@@ -432,6 +434,7 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
432
434
  externalSku: z.ZodString;
433
435
  externalName: z.ZodOptional<z.ZodString>;
434
436
  menuItemId: z.ZodNullable<z.ZodString>;
437
+ variationId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
435
438
  }, z.core.$strict>>;
436
439
  }, z.core.$strict>;
437
440
  readonly response: z.ZodObject<{
@@ -443,6 +446,7 @@ declare const MARKETPLACE_MCP_TOOLS: readonly [{
443
446
  externalSku: z.ZodString;
444
447
  externalName: z.ZodString;
445
448
  menuItemId: z.ZodNullable<z.ZodString>;
449
+ variationId: z.ZodNullable<z.ZodString>;
446
450
  lastSeenAt: z.ZodString;
447
451
  }, z.core.$strip>>;
448
452
  }, z.core.$strip>;
@@ -6,7 +6,7 @@ import {
6
6
  MARKETPLACE_SWEEP_QUEUE,
7
7
  ORDER_NOT_PENDING_CODE,
8
8
  createApiMarketplace
9
- } from "../chunk-6N2HEV3U.js";
9
+ } from "../chunk-WVZ2IXFH.js";
10
10
  import {
11
11
  MARKETPLACE_DECIDE,
12
12
  MARKETPLACE_MANAGE,
@@ -19,8 +19,8 @@ import {
19
19
  marketplaceParams,
20
20
  upsertMarketplaceIntegrationsBody,
21
21
  upsertMarketplaceMenuLinksBody
22
- } from "../chunk-NP4EYKPO.js";
23
- import "../chunk-BMCERPQX.js";
22
+ } from "../chunk-ZO4S3LF4.js";
23
+ import "../chunk-2BA2EHNF.js";
24
24
  import "../chunk-7QVYU63E.js";
25
25
  export {
26
26
  MARKETPLACE_AVAILABILITY_ATTEMPTS,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@12-apps/marketplace",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
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 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.",
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.",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
@@ -45,6 +45,18 @@
45
45
  "types": "./dist/rappi/en-US.d.ts",
46
46
  "default": "./dist/rappi/en-US.js"
47
47
  },
48
+ "./keeta": {
49
+ "types": "./dist/keeta/index.d.ts",
50
+ "default": "./dist/keeta/index.js"
51
+ },
52
+ "./keeta/pt-BR": {
53
+ "types": "./dist/keeta/pt-BR.d.ts",
54
+ "default": "./dist/keeta/pt-BR.js"
55
+ },
56
+ "./keeta/en-US": {
57
+ "types": "./dist/keeta/en-US.d.ts",
58
+ "default": "./dist/keeta/en-US.js"
59
+ },
48
60
  "./server": {
49
61
  "types": "./dist/server/index.d.ts",
50
62
  "default": "./dist/server/index.js"
@@ -93,6 +93,9 @@ model MarketplaceIntegration {
93
93
  ///
94
94
  /// `lastSeenAt` is what the list sorts by, so a store fixing five mappings
95
95
  /// fixes the five costing them money rather than the five added first.
96
+ ///
97
+ /// `variationId` narrows the mapping to one variation of the item: the host
98
+ /// asks its own catalog whether it belongs (`order.catalogHasVariation`).
96
99
  model MarketplaceMenuLink {
97
100
  id String @id @default(uuid())
98
101
  clientId String @map("client_id")
@@ -105,6 +108,9 @@ model MarketplaceMenuLink {
105
108
 
106
109
  /// The host catalog row this SKU means, or NULL while nothing does.
107
110
  menuItemId String? @map("menu_item_id")
111
+ /// The variation of `menuItemId` this SKU names, or NULL for the parent
112
+ /// item alone. Never set without `menuItemId` (FUT-4927).
113
+ variationId String? @map("variation_id")
108
114
 
109
115
  lastSeenAt DateTime @default(now()) @map("last_seen_at")
110
116
 
@@ -0,0 +1,11 @@
1
+ -- @domains: marketplace
2
+ -- @12-apps/marketplace: a SKU may map to one variation of a catalog item (FUT-4927).
3
+ -- Additive and replay-safe, like the engine's earlier migrations: one nullable
4
+ -- column. No foreign key into a host table, and nothing the previous release
5
+ -- reads is changed: every existing link keeps `variation_id` NULL, which is
6
+ -- the parent-only mapping it already was.
7
+ --
8
+ -- `variation_id` is the host's id of the variation the SKU names, beside the
9
+ -- `menu_item_id` it belongs to. NULL maps the SKU to the parent item alone.
10
+
11
+ ALTER TABLE "marketplace_menu_links" ADD COLUMN IF NOT EXISTS "variation_id" TEXT;
@@ -1,7 +1,6 @@
1
- import { answered, outboundResultOf, type OutboundResult } from "../core/adapter";
2
- import { stableUuid } from "../core/catalogue-ids";
3
- import type { CatalogueCallContext, CatalogueMenuEntry, CatalogueMenuOptions, PullCatalogue } from "../core/catalogue-port";
4
- import { baseOf, bearer, tokenKey, type NinetyNineFoodApiBaseUrls } from "./outbound";
1
+ import type { PullCatalogue } from "../core/catalogue-port";
2
+ import { openDeliveryMenuDocument, openDeliveryMerchantUpdate } from "../open-delivery/merchant";
3
+ import { ninetyNineFoodDialect, type NinetyNineFoodApiBaseUrls } from "./outbound";
5
4
 
6
5
  /**
7
6
  * The 99Food adapter's CATALOGUE half, on Open Delivery v1.7.1: PULL (FUT-4768).
@@ -9,16 +8,16 @@ import { baseOf, bearer, tokenKey, type NinetyNineFoodApiBaseUrls } from "./outb
9
8
  * In Open Delivery the store's software does not write the menu to the
10
9
  * marketplace. The SOFTWARE SERVICE (the host) serves `GET /v1/merchant`, a
11
10
  * `Merchant` document carrying `menus`, `categories`, `items` and
12
- * `itemOffers` (the price lives on the offer), and the ORDERING APPLICATION
13
- * (99Food) pulls it, again when its `TTL` runs out or when told the merchant
14
- * changed (`POST /v1/merchantUpdate`, sent with an empty body: "pull
15
- * everything again"). Spec: https://abrasel-nacional.github.io/opendelivery/openapi.yaml
11
+ * `itemOffers`, and the ORDERING APPLICATION (99Food) pulls it, again when its
12
+ * `TTL` runs out or when told the merchant changed (`POST
13
+ * /v1/merchantUpdate`, sent with an empty body: "pull everything again").
14
+ * Spec: https://abrasel-nacional.github.io/opendelivery/openapi.yaml
16
15
  *
17
16
  * So the adapter does two things: build the menu part of that document from
18
- * the items the store switched on (`menuDocument`, pure; the host merges it
19
- * into the rest of the `Merchant`, which is its own: `basicInfo`, `services`,
20
- * `lastUpdate`, `TTL`, `status`), and tell 99Food the menu changed
21
- * (`notifyMenuChanged`).
17
+ * the items the store switched on (`menuDocument`, pure, shared:
18
+ * `../open-delivery/merchant.ts`; the host merges it into the rest of the
19
+ * `Merchant`, which is its own: `basicInfo`, `services`, `lastUpdate`, `TTL`,
20
+ * `status`), and tell 99Food the menu changed (`notifyMenuChanged`).
22
21
  *
23
22
  * ESTIMATED, to be checked once 99Food grants partner access:
24
23
  * - the path: the spec's route table and prose name `POST /merchantUpdate`
@@ -28,90 +27,21 @@ import { baseOf, bearer, tokenKey, type NinetyNineFoodApiBaseUrls } from "./outb
28
27
  * client app may serve many merchants, so it is sent to name which;
29
28
  * - that 99Food reads the whole `Merchant` on that notification (scenario 1
30
29
  * of the operation) rather than needing `entityType`/`updatedObjects`.
31
- *
32
- * Every id in the document is a UUID the software generates (the spec's
33
- * `format: uuid`), derived from the publication's stable reference, so the
34
- * same product keeps the same ids across pulls.
35
30
  */
36
31
 
37
- /** One category per host category name, in first-seen order. */
38
- function categoriesOf(merchantId: string, entries: readonly CatalogueMenuEntry[]) {
39
- const byName = new Map<string, { id: string; name: string; offers: string[] }>();
40
- for (const entry of entries) {
41
- const name = entry.categoryName.trim();
42
- const category = byName.get(name) ?? { id: stableUuid(`${merchantId}:category:${name}`), name, offers: [] };
43
- category.offers.push(stableUuid(`${entry.ref}:offer`));
44
- byName.set(name, category);
45
- }
46
- return [...byName.values()];
47
- }
48
-
49
- /** The menu part of Open Delivery's `Merchant`: `menus`, `categories`, `items`, `itemOffers`. */
50
- export function openDeliveryMenuDocument(input: {
51
- externalMerchantId: string;
52
- entries: readonly CatalogueMenuEntry[];
53
- options: CatalogueMenuOptions;
54
- }) {
55
- const { externalMerchantId: merchantId, entries, options } = input;
56
- const categories = categoriesOf(merchantId, entries);
57
- return {
58
- menus: [
59
- {
60
- id: stableUuid(`${merchantId}:menu`),
61
- name: options.menuName,
62
- externalCode: "menu",
63
- categoryId: categories.map((category) => category.id),
64
- },
65
- ],
66
- categories: categories.map((category, index) => ({
67
- id: category.id,
68
- index,
69
- name: category.name,
70
- externalCode: category.name,
71
- status: "AVAILABLE",
72
- itemOfferId: category.offers,
73
- })),
74
- items: entries.map((entry) => ({
75
- id: stableUuid(`${entry.ref}:item`),
76
- name: entry.name,
77
- description: entry.description ?? "",
78
- externalCode: entry.productId,
79
- status: "AVAILABLE",
80
- unit: "UN",
81
- ...(entry.imageUrl === null ? {} : { image: { URL: entry.imageUrl } }),
82
- })),
83
- itemOffers: entries.map((entry, index) => {
84
- const value = Math.round(entry.priceCents) / 100;
85
- return {
86
- id: stableUuid(`${entry.ref}:offer`),
87
- itemId: stableUuid(`${entry.ref}:item`),
88
- index,
89
- status: "AVAILABLE",
90
- price: { value, originalValue: value, currency: options.currency },
91
- };
92
- }),
93
- };
94
- }
95
-
96
- /** `POST /v1/merchantUpdate` with no body: 99Food pulls the whole `Merchant` again. 200 or 204. */
97
- async function notify(ctx: CatalogueCallContext, bases: NinetyNineFoodApiBaseUrls): Promise<OutboundResult> {
98
- const auth = await bearer(ctx, bases);
99
- if (!("token" in auth)) return auth;
100
- const response = await ctx.http({
101
- method: "POST",
102
- url: `${baseOf(ctx, bases)}/v1/merchantUpdate`,
103
- headers: { Authorization: `Bearer ${auth.token}`, "X-App-MerchantId": ctx.externalMerchantId },
104
- });
105
- if (response.status !== 401) return outboundResultOf(response);
106
- ctx.tokens.delete(tokenKey(ctx));
107
- return { kind: "retry", reason: "99Food refused the token" };
108
- }
32
+ export { openDeliveryMenuDocument } from "../open-delivery/merchant";
109
33
 
110
34
  /** 99Food's catalogue capability, for the base URLs it was given. */
111
35
  export function openDeliveryCatalogue(bases: NinetyNineFoodApiBaseUrls): PullCatalogue {
36
+ const dialect = ninetyNineFoodDialect(bases);
112
37
  return {
113
38
  mode: "pull",
114
39
  menuDocument: openDeliveryMenuDocument,
115
- notifyMenuChanged: (ctx) => answered(() => notify(ctx, bases)),
40
+ // No body: 99Food pulls the whole `Merchant` again. 200 or 204.
41
+ notifyMenuChanged: (ctx) =>
42
+ openDeliveryMerchantUpdate(ctx, dialect, {
43
+ path: "/v1/merchantUpdate",
44
+ headers: { "X-App-MerchantId": ctx.externalMerchantId },
45
+ }),
116
46
  };
117
47
  }
@@ -1,3 +1,5 @@
1
+ import { OPEN_DELIVERY_MERCHANT_REASON_CODES } from "../open-delivery/reasons";
2
+
1
3
  /**
2
4
  * The words the 99Food adapter needs from its host, and nothing else.
3
5
  *
@@ -6,25 +8,8 @@
6
8
  * `./en-US`); a host passes one by hand, or its own.
7
9
  */
8
10
 
9
- /**
10
- * The cancellation codes a merchant may send, verbatim from Open Delivery
11
- * v1.7.1 (`RequestCancelled.code`). Pinned by the spec, not estimated. The two
12
- * codes only the marketplace sends (`CONSUMER_CANCELLATION_REQUESTED`,
13
- * `OTHER_CANCELLATION_REASON`) are not a store's to choose and are left out.
14
- */
15
- export const NINETY_NINE_FOOD_REASON_CODES = [
16
- "SYSTEMIC_ISSUES",
17
- "DUPLICATE_APPLICATION",
18
- "UNAVAILABLE_ITEM",
19
- "RESTAURANT_WITHOUT_DELIVERY_PERSON",
20
- "OUTDATED_MENU",
21
- "ORDER_OUTSIDE_THE_DELIVERY_AREA",
22
- "BLOCKED_CUSTOMER",
23
- "OUTSIDE_DELIVERY_HOURS",
24
- "INTERNAL_DIFFICULTIES_OF_THE_RESTAURANT",
25
- "RISK_AREA",
26
- "DELIVERY_PROBLEM",
27
- ] as const;
11
+ /** The cancellation codes a merchant may send: Open Delivery v1.7.1's (`../open-delivery/reasons.ts`). */
12
+ export const NINETY_NINE_FOOD_REASON_CODES = OPEN_DELIVERY_MERCHANT_REASON_CODES;
28
13
 
29
14
  export type NinetyNineFoodReasonCode = (typeof NINETY_NINE_FOOD_REASON_CODES)[number];
30
15
 
@@ -1,19 +1,16 @@
1
1
  import type { CancellationReason, MarketplaceAdapter } from "../core/adapter";
2
- import {
3
- NINETY_NINE_FOOD_REASON_CODES,
4
- type NinetyNineFoodAdapterCopy,
5
- type NinetyNineFoodReasonCode,
6
- } from "./copy";
7
- import { openDeliveryCatalogue } from "./catalogue";
8
- import { NINETY_NINE_FOOD_PROVIDER, normalizeOpenDeliveryEvent, verifyOpenDeliverySignature } from "./normalize";
9
2
  import {
10
3
  openDeliveryConfirm,
11
4
  openDeliveryFetchOrder,
12
- openDeliveryInformStatus,
13
5
  openDeliveryRequestCancellation,
14
- openDeliveryStatusSupported,
15
- type NinetyNineFoodApiBaseUrls,
16
- } from "./outbound";
6
+ openDeliveryStatus,
7
+ } from "../open-delivery/orders";
8
+ import { assertHttpsUrl } from "../open-delivery/client";
9
+ import { OPEN_DELIVERY_ITEM_UNAVAILABLE } from "../open-delivery/reasons";
10
+ import { NINETY_NINE_FOOD_REASON_CODES, type NinetyNineFoodAdapterCopy } from "./copy";
11
+ import { openDeliveryCatalogue } from "./catalogue";
12
+ import { NINETY_NINE_FOOD_PROVIDER, normalizeOpenDeliveryEvent, normalizeOpenDeliveryOrder, verifyOpenDeliverySignature } from "./normalize";
13
+ import { ninetyNineFoodDialect, type NinetyNineFoodApiBaseUrls } from "./outbound";
17
14
  import { openDeliveryAvailability } from "./pause";
18
15
 
19
16
  /**
@@ -21,8 +18,9 @@ import { openDeliveryAvailability } from "./pause";
21
18
  *
22
19
  * 99Food completed Open Delivery (Abrasel) adherence, so this adapter speaks
23
20
  * Open Delivery v1.7.1: the signed webhook, `CREATED` → fetch the order,
24
- * confirm, requestCancellation with the spec's codes. Everything 99Food is
25
- * under this folder; the engine reaches it only through the
21
+ * confirm, requestCancellation with the spec's codes. The standard's calls
22
+ * and readers are `../open-delivery/`, shared with Keeta; what is 99Food's
23
+ * (its dialect, its copy, its ESTIMATED choices) is under this folder; the engine reaches it only through the
26
24
  * {@link MarketplaceAdapter} port, and registering it is the whole cost:
27
25
  *
28
26
  * ```ts
@@ -47,8 +45,8 @@ export { NINETY_NINE_FOOD_PROVIDER } from "./normalize";
47
45
  /** How long 99Food may take to answer a cancellation request. ESTIMATED: the spec names no deadline. */
48
46
  export const NINETY_NINE_FOOD_CANCELLATION_ANSWER_WINDOW_MS = 5 * 60_000;
49
47
 
50
- /** The one reason that means "an item is unavailable". */
51
- const ITEM_UNAVAILABLE: NinetyNineFoodReasonCode = "UNAVAILABLE_ITEM";
48
+ /** 99Food serves `pickedUp` for a take-out (v1.7.1). */
49
+ const STATUS = openDeliveryStatus({ takeoutPickedUp: true });
52
50
 
53
51
  export interface NinetyNineFoodAdapterConfig {
54
52
  /** The words the adapter needs: reason labels and the missing-number text. Required. */
@@ -73,30 +71,26 @@ export interface NinetyNineFoodAdapterConfig {
73
71
  pauseByStoreSwitch?: boolean;
74
72
  }
75
73
 
76
- function assertHttps(name: string, url: string): void {
77
- let parsed: URL;
78
- try {
79
- parsed = new URL(url);
80
- } catch {
81
- throw new Error(`@12-apps/marketplace/99food: ${name} is not a URL.`);
82
- }
83
- if (parsed.protocol !== "https:") throw new Error(`@12-apps/marketplace/99food: ${name} must be https.`);
84
- }
74
+ const assertHttps = (name: string, url: string): void => assertHttpsUrl("@12-apps/marketplace/99food", name, url);
85
75
 
86
76
  /** Build the 99Food adapter. Its reasons are static: a dialog never waits on 99Food. */
87
77
  export function createNinetyNineFoodAdapter(config: NinetyNineFoodAdapterConfig): MarketplaceAdapter {
88
78
  assertHttps("apiBaseUrl.SANDBOX", config.apiBaseUrl.SANDBOX);
89
79
  assertHttps("apiBaseUrl.PRODUCTION", config.apiBaseUrl.PRODUCTION);
90
80
  assertHttps("portalUrl", config.portalUrl);
91
- const bases = { ...config.apiBaseUrl };
81
+ const dialect = ninetyNineFoodDialect({ ...config.apiBaseUrl });
82
+ const bases = dialect.bases;
92
83
  const reasons: readonly CancellationReason[] = NINETY_NINE_FOOD_REASON_CODES.map((code) => ({
93
84
  code,
94
85
  label: config.copy.reasonLabels[code],
95
- itemUnavailable: code === ITEM_UNAVAILABLE,
96
- // `outOfStockItems` is optional in the spec (see `./outbound.ts`).
86
+ itemUnavailable: code === OPEN_DELIVERY_ITEM_UNAVAILABLE,
87
+ // `outOfStockItems` is optional in the spec, and not sent (see `cancellation` below).
97
88
  needsItems: false,
98
89
  }));
99
90
  const normalizeOptions = { missingStreetNumber: config.copy.missingStreetNumber };
91
+ const fetchOptions = { normalize: (order: unknown) => normalizeOpenDeliveryOrder(order, normalizeOptions) };
92
+ // `outOfStockItems` wants 99Food's item uuids; the engine keeps SKUs (`externalCode`). Not sent.
93
+ const cancellation = { outOfStockAsSkus: false };
100
94
  return {
101
95
  provider: NINETY_NINE_FOOD_PROVIDER,
102
96
  capabilities: {
@@ -111,7 +105,7 @@ export function createNinetyNineFoodAdapter(config: NinetyNineFoodAdapterConfig)
111
105
  // `OrderConfirmed.preparationTime`, in minutes.
112
106
  confirmTakesPreparationTime: true,
113
107
  cancellationAnswerWindowMs: NINETY_NINE_FOOD_CANCELLATION_ANSWER_WINDOW_MS,
114
- // Open Delivery's readyForPickup, dispatch and delivered / pickedUp (see `./outbound.ts`).
108
+ // Open Delivery's readyForPickup, dispatch and delivered / pickedUp (`../open-delivery/orders.ts`).
115
109
  statusSteps: ["READY", "DISPATCHED", "HANDED_OVER"],
116
110
  },
117
111
  normalize: normalizeOpenDeliveryEvent,
@@ -120,11 +114,12 @@ export function createNinetyNineFoodAdapter(config: NinetyNineFoodAdapterConfig)
120
114
  cancellationReasons: () => reasons,
121
115
  // PULL: 99Food reads the menu the host serves (`GET /v1/merchant`) and is told when it changed (FUT-4768).
122
116
  catalogue: openDeliveryCatalogue(bases),
123
- fetchOrder: (ctx, order) => openDeliveryFetchOrder(ctx, bases, order, normalizeOptions),
124
- confirm: (ctx, order, input) => openDeliveryConfirm(ctx, bases, order, input),
125
- requestCancellation: (ctx, order, input) => openDeliveryRequestCancellation(ctx, bases, order, input),
126
- statusSupported: openDeliveryStatusSupported,
127
- informStatus: (ctx, order, facts) => openDeliveryInformStatus(ctx, bases, order, facts),
117
+ fetchOrder: (ctx, order) => openDeliveryFetchOrder(ctx, dialect, order, fetchOptions),
118
+ confirm: (ctx, order, input) => openDeliveryConfirm(ctx, dialect, order, input),
119
+ requestCancellation: (ctx, order, input) =>
120
+ openDeliveryRequestCancellation(ctx, dialect, order, input, cancellation),
121
+ statusSupported: STATUS.supported,
122
+ informStatus: (ctx, order, facts) => STATUS.inform(ctx, dialect, order, facts),
128
123
  appLink: () => config.portalUrl,
129
124
  ...(config.pauseByStoreSwitch ? { availability: openDeliveryAvailability(bases) } : {}),
130
125
  };