@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.
- package/ADOPTING.md +27 -1
- package/README.md +103 -9
- package/dist/99food/index.d.ts +30 -54
- package/dist/99food/index.js +60 -418
- package/dist/99food/index.js.map +1 -1
- package/dist/{chunk-BMCERPQX.js → chunk-2BA2EHNF.js} +16 -6
- package/dist/chunk-2BA2EHNF.js.map +1 -0
- package/dist/chunk-PYHNM47K.js +478 -0
- package/dist/chunk-PYHNM47K.js.map +1 -0
- package/dist/{chunk-6N2HEV3U.js → chunk-WVZ2IXFH.js} +3 -3
- package/dist/{chunk-NP4EYKPO.js → chunk-ZO4S3LF4.js} +5 -3
- package/dist/chunk-ZO4S3LF4.js.map +1 -0
- package/dist/client-B4EQCRD_.d.ts +20 -0
- package/dist/{engine-wmW-VuBL.d.ts → engine-DK3iV_Kk.d.ts} +91 -60
- package/dist/hono/index.d.ts +1 -1
- package/dist/hono/index.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/dist/keeta/en-US.d.ts +19 -0
- package/dist/keeta/en-US.js +23 -0
- package/dist/keeta/en-US.js.map +1 -0
- package/dist/keeta/index.d.ts +253 -0
- package/dist/keeta/index.js +388 -0
- package/dist/keeta/index.js.map +1 -0
- package/dist/keeta/pt-BR.d.ts +23 -0
- package/dist/keeta/pt-BR.js +23 -0
- package/dist/keeta/pt-BR.js.map +1 -0
- package/dist/manifest/index.d.ts +4 -1
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/server.d.ts +1 -1
- package/dist/manifest/server.js +3 -3
- package/dist/server/index.d.ts +6 -2
- package/dist/server/index.js +3 -3
- package/package.json +14 -2
- package/prisma/marketplace.prisma +6 -0
- package/prisma/migrations/20261126230000_marketplace_menu_link_variation/migration.sql +11 -0
- package/src/99food/catalogue.ts +19 -89
- package/src/99food/copy.ts +4 -19
- package/src/99food/index.ts +28 -33
- package/src/99food/normalize.ts +11 -253
- package/src/99food/outbound.ts +29 -270
- package/src/99food/pause.ts +7 -22
- package/src/core/bulk.ts +34 -7
- package/src/core/ingest.ts +2 -1
- package/src/core/menu-links.ts +36 -6
- package/src/core/order-types.ts +74 -0
- package/src/core/ports.ts +23 -65
- package/src/index.ts +2 -1
- package/src/keeta/authorization.ts +226 -0
- package/src/keeta/copy.ts +27 -0
- package/src/keeta/en-US.ts +19 -0
- package/src/keeta/index.ts +162 -0
- package/src/keeta/merchant.ts +70 -0
- package/src/keeta/normalize.ts +131 -0
- package/src/keeta/outbound.ts +55 -0
- package/src/keeta/pt-BR.ts +23 -0
- package/src/keeta/signature.ts +85 -0
- package/src/open-delivery/client.ts +185 -0
- package/src/open-delivery/merchant.ts +126 -0
- package/src/open-delivery/normalize.ts +269 -0
- package/src/open-delivery/orders.ts +241 -0
- package/src/open-delivery/reasons.ts +26 -0
- package/src/server/mcp.ts +7 -2
- package/dist/chunk-BMCERPQX.js.map +0 -1
- package/dist/chunk-NP4EYKPO.js.map +0 -1
- /package/dist/{chunk-6N2HEV3U.js.map → chunk-WVZ2IXFH.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/contribution.ts","../src/server/mcp.ts"],"sourcesContent":["import type { WirePermissionsContribution } from \"@12-apps/wiring\";\n\n/**\n * THIS PACKAGE'S OWN PERMISSION CONTRIBUTION.\n *\n * Two privileges, kept apart on purpose (the ADR-0117 pattern of naming the\n * act, not the role):\n *\n * - `marketplace:manage` — CONNECT a marketplace (store its credentials, turn\n * it on, set auto-accept and the acceptance window) and MAP its SKUs to the\n * catalog. Committing the store to a commercial relationship and teaching\n * the engine what a SKU means are the same person's job.\n * - `marketplace:decide` — read the acceptance queue and answer it: accept or\n * refuse an order with a reason. That is whoever is on the floor when the\n * clock runs, and a queue only an owner could answer would lapse.\n *\n * Which roles hold either is the HOST's decision; the package only names\n * them. The shape is `@12-apps/rbac`'s `PermissionContribution`, taken from\n * the wiring contract's type-only twin. No labels: a label is a word in a\n * language, and the vocabulary a picker renders is the host's.\n */\nexport const MARKETPLACE_PERMISSIONS = {\n source: \"@12-apps/marketplace\",\n ids: [\"marketplace:manage\", \"marketplace:decide\"],\n permissions: {\n \"marketplace:manage\": { kind: \"class\" },\n \"marketplace:decide\": { kind: \"class\" },\n },\n} as const satisfies WirePermissionsContribution;\n\n/** Connect a marketplace and map its SKUs. */\nexport const MARKETPLACE_MANAGE = \"marketplace:manage\";\n/** Read and answer the acceptance queue. */\nexport const MARKETPLACE_DECIDE = \"marketplace:decide\";\n","import { z } from \"zod\";\n\nimport type { WireMcpTool } from \"@12-apps/wiring\";\n\n/**\n * The marketplace tool surface — authored ONCE, beside the route descriptors\n * it proxies to, and reused as the runtime validators. The advertised schema\n * and what a handler accepts are the same objects, so they cannot drift.\n *\n * The shape is the bulk-upsert protocol: ONE bulk write per entity\n * (connections, SKU links, decisions), each taking a list, all-or-nothing,\n * `validateOnly` supported, idempotent on the natural key, every refusal\n * returned with its path; a connection is ARCHIVED, never deleted. A read is\n * the entity's `list*` tool, taking `ids`.\n *\n * Every input is STRICT (an unknown key is refused, never stripped), and the\n * cross-row checks (a key twice in one call) are part of the schema. The\n * provider is checked for SHAPE here and for EXISTENCE at runtime, because\n * the set of marketplaces is the set of adapters a host registered.\n *\n * Paths are RELATIVE to the http capability's mount (`/api` in the origin\n * host). The webhook is not a tool: a marketplace's server-to-server callback\n * is not a capability anybody invokes.\n */\n\nconst providerSchema = z.string().regex(/^[A-Z][A-Z0-9_]*$/u);\nconst environmentSchema = z.enum([\"SANDBOX\", \"PRODUCTION\"]);\nconst booleanText = z.enum([\"true\", \"false\"]);\n/** A comma-separated id list in a query string: `ids=a,b`. */\nconst idsText = z\n .string()\n .transform((text) => text.split(\",\").map((id) => id.trim()).filter((id) => id !== \"\"))\n .pipe(z.array(z.string().min(1)).min(1).max(100));\n\n/** Flag every row whose key repeats an earlier one, at that row's path. */\nfunction noDuplicates<T>(list: string, field: string, keyOf: (row: T) => string) {\n return (rows: readonly T[], ctx: z.RefinementCtx): void => {\n const seen = new Set<string>();\n rows.forEach((row, index) => {\n const key = keyOf(row);\n if (seen.has(key)) {\n ctx.addIssue({ code: \"custom\", path: [index, field], message: `${field} repeats an earlier row of ${list}` });\n }\n seen.add(key);\n });\n };\n}\n\n/** Path params for the tenant-scoped marketplace resource. */\nexport const marketplaceParams = z.strictObject({\n tenantSlug: z.string().min(1),\n});\n\n/** Which connections to read. */\nexport const listMarketplaceIntegrationsQuery = z.strictObject({\n ids: idsText.optional(),\n includeArchived: booleanText.optional(),\n});\n\n/** The credential half of a save. Absent leaves the stored secrets alone. */\nconst credentialsInput = z.strictObject({\n clientId: z.string().trim().min(1),\n clientSecret: z.string().trim().min(1),\n webhookSecret: z.string().trim().min(1).nullable().optional(),\n});\n\n/** Create or patch one connection; any subset of its settings. */\nconst integrationUpsertInput = z.strictObject({\n operation: z.literal(\"upsert\").optional(),\n provider: providerSchema,\n enabled: z.boolean().optional(),\n environment: environmentSchema.optional(),\n externalMerchantId: z.string().trim().min(1).nullable().optional(),\n autoAccept: z.boolean().optional(),\n followStatus: z.boolean().optional(),\n // Below a minute nothing human can answer in time; above an hour the\n // deadline has stopped describing anything a marketplace would wait for.\n ackSlaSeconds: z.number().int().min(60).max(3600).optional(),\n credentials: credentialsInput.optional(),\n});\n\n/** Archive (reversible) or unarchive one connection, with an optional reason. */\nconst integrationArchiveInput = z.strictObject({\n operation: z.enum([\"archive\", \"unarchive\"]),\n provider: providerSchema,\n reason: z.string().trim().min(1).max(500).nullable().optional(),\n});\n\n/** Many connection changes, all-or-nothing. */\nexport const upsertMarketplaceIntegrationsBody = z.strictObject({\n validateOnly: z.boolean().optional(),\n integrations: z\n .array(z.union([integrationArchiveInput, integrationUpsertInput]))\n .min(1)\n .max(20)\n .superRefine(noDuplicates(\"integrations\", \"provider\", (row) => row.provider)),\n});\n\n/** Filters for the SKU map. `unmapped=true` IS the attention list. */\nexport const listMarketplaceMenuLinksQuery = z.strictObject({\n provider: providerSchema.optional(),\n // A query string is text: \"false\" must mean false.\n unmapped: booleanText.optional(),\n ids: idsText.optional(),\n});\n\n/**\n * Map one external SKU to a catalog id, or unmap it with `menuItemId: null`.\n * `variationId` narrows it to one variation of that id; absent or null maps the item alone.\n */\nconst menuLinkInput = z.strictObject({\n provider: providerSchema,\n externalSku: z.string().trim().min(1),\n externalName: z.string().trim().min(1).optional(),\n menuItemId: z.string().min(1).nullable(),\n variationId: z.string().min(1).nullable().optional(),\n});\n\n/** Many SKU links, all-or-nothing; idempotent on (provider, externalSku). */\nexport const upsertMarketplaceMenuLinksBody = z.strictObject({\n validateOnly: z.boolean().optional(),\n links: z\n .array(menuLinkInput)\n .min(1)\n .max(200)\n .superRefine(noDuplicates(\"links\", \"externalSku\", (row) => `${row.provider}\\u0000${row.externalSku}`)),\n});\n\n/** Which queued orders to read. */\nexport const listMarketplaceAcceptancesQuery = z.strictObject({\n ids: idsText.optional(),\n});\n\n/** What the person confirmed beside an accept, for the host's admission. */\nconst admissionInput = z.strictObject({\n admitStockPastZero: z.boolean().optional(),\n});\n\n/**\n * One decision. An accept may carry the admission and a preparation time; a\n * refusal one of the marketplace's reason codes (its first when omitted) and,\n * for a reason that needs them, the order's offending SKUs. A field of the\n * other kind is refused, not ignored.\n */\nconst decisionInput = z.discriminatedUnion(\"decision\", [\n z.strictObject({\n orderId: z.string().min(1),\n decision: z.literal(\"ACCEPT\"),\n admission: admissionInput.optional(),\n preparationMinutes: z.number().int().min(1).max(240).optional(),\n }),\n z.strictObject({\n orderId: z.string().min(1),\n decision: z.literal(\"REJECT\"),\n reasonCode: z.string().trim().min(1).optional(),\n offendingSkus: z.array(z.string().trim().min(1)).min(1).max(50).optional(),\n }),\n]);\n\n/** Many decisions, all-or-nothing, the host admitting each inside one transaction. */\nexport const decideMarketplaceOrdersBody = z.strictObject({\n validateOnly: z.boolean().optional(),\n decisions: z\n .array(decisionInput)\n .min(1)\n .max(50)\n .superRefine(noDuplicates(\"decisions\", \"orderId\", (row) => row.orderId)),\n});\n\nconst reasonSchema = z.object({\n code: z.string(),\n label: z.string(),\n itemUnavailable: z.boolean(),\n needsItems: z.boolean(),\n});\n\nconst capabilitiesSchema = z.object({\n apiConfirm: z.boolean(),\n apiCancel: z.boolean(),\n cancelAfterAccept: z.boolean(),\n asyncCancellationOutcome: z.boolean(),\n perOrderAppLink: z.boolean(),\n confirmTakesPreparationTime: z.boolean(),\n});\n\n/** A connection as every read returns it: `connected` stands in for the secrets. */\nconst integrationSchema = z.object({\n provider: z.string(),\n enabled: z.boolean(),\n environment: environmentSchema,\n status: z.enum([\"UNVERIFIED\", \"VERIFIED\", \"FAILED\"]),\n externalMerchantId: z.string().nullable(),\n autoAccept: z.boolean(),\n followStatus: z.boolean(),\n ackSlaSeconds: z.number().int(),\n connected: z.boolean(),\n lastEventAt: z.string().nullable(),\n lastVerifiedAt: z.string().nullable(),\n archivedAt: z.string().nullable(),\n capabilities: capabilitiesSchema.nullable(),\n reasons: z.array(reasonSchema),\n});\n\nconst menuLinkSchema = z.object({\n id: z.string(),\n provider: z.string(),\n externalSku: z.string(),\n externalName: z.string(),\n menuItemId: z.string().nullable(),\n variationId: z.string().nullable(),\n lastSeenAt: z.string(),\n});\n\nconst pendingAcceptanceSchema = z.object({\n id: z.string(),\n orderId: z.string(),\n provider: z.string(),\n externalOrderId: z.string(),\n externalDisplayId: z.string().nullable(),\n totalCents: z.number().int(),\n buyerName: z.string().nullable(),\n acknowledgeBy: z.string().nullable(),\n externalDueAt: z.string().nullable(),\n commissionCents: z.number().int().nullable(),\n unmappedLines: z.number().int(),\n createdAt: z.string().nullable(),\n});\n\nconst decidedSchema = z.object({\n orderId: z.string(),\n status: z.enum([\"ACCEPTED\", \"REJECTED\"]),\n cancellation: z.enum([\"PENDING\", \"REQUESTED\", \"CONFIRMED\", \"FAILED\"]).nullable(),\n reasonCode: z.string().nullable(),\n offendingSkus: z.array(z.string()),\n});\n\nconst BASE = \"/admin/{tenantSlug}/marketplace\";\n\n/** The six marketplace tools: a read and a bulk write per entity. */\nexport const MARKETPLACE_MCP_TOOLS = [\n {\n operationId: \"listMarketplaceIntegrations\",\n method: \"GET\",\n path: BASE,\n summary:\n \"List one or many of a store's marketplace connections (pass `ids` as provider ids, e.g. `ids=IFOOD`): whether each is enabled, its environment, auto-accept, the acknowledgement window, and each marketplace's capabilities and refusal reasons. Archived connections only with `includeArchived=true`. Never returns the stored credentials: `connected` says only whether a set is on file.\",\n tags: [\"marketplace\"],\n params: marketplaceParams,\n query: listMarketplaceIntegrationsQuery,\n response: z.object({ data: z.array(integrationSchema) }),\n annotations: { readOnly: true },\n },\n {\n operationId: \"upsertMarketplaceIntegrations\",\n method: \"PUT\",\n path: BASE,\n summary:\n \"Create, update, archive or unarchive one or many marketplace connections in one all-or-nothing call. A row is keyed by `provider`; `operation` is `upsert` (default: any subset of the settings; omitting `credentials` keeps the stored secrets, sending them resets the status to UNVERIFIED), `archive` or `unarchive` (reversible, audited, with an optional `reason`). Any problem writes nothing and every problem comes back with its path. `validateOnly: true` checks without writing.\",\n tags: [\"marketplace\"],\n params: marketplaceParams,\n body: upsertMarketplaceIntegrationsBody,\n response: z.object({ data: z.object({ validateOnly: z.boolean(), integrations: z.array(integrationSchema) }) }),\n annotations: { readOnly: false, destructive: false },\n },\n {\n operationId: \"listMarketplaceMenuLinks\",\n method: \"GET\",\n path: `${BASE}/menu-links`,\n summary:\n \"List a store's marketplace SKU map, or the links named by `ids`: every external SKU an incoming order has carried, and the catalog id it resolves to. `unmapped=true` is the attention list: the SKUs that arrived with nothing behind them, newest-seen first. An unmapped SKU never rejects an order.\",\n tags: [\"marketplace\"],\n params: marketplaceParams,\n query: listMarketplaceMenuLinksQuery,\n response: z.object({ data: z.array(menuLinkSchema) }),\n annotations: { readOnly: true },\n },\n {\n operationId: \"upsertMarketplaceMenuLinks\",\n method: \"PUT\",\n path: `${BASE}/menu-links`,\n summary:\n \"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.\",\n tags: [\"marketplace\"],\n params: marketplaceParams,\n body: upsertMarketplaceMenuLinksBody,\n response: z.object({ data: z.object({ validateOnly: z.boolean(), links: z.array(menuLinkSchema) }) }),\n annotations: { readOnly: false, destructive: false },\n },\n {\n operationId: \"listMarketplaceAcceptances\",\n method: \"GET\",\n path: `${BASE}/acceptances`,\n summary:\n \"List the marketplace orders waiting on the store's acceptance, soonest deadline first, or those named by `ids` (order ids). `acknowledgeBy` is the instant the marketplace cancels an unacknowledged order; `unmappedLines` counts the lines that arrived with nothing behind them.\",\n tags: [\"marketplace\"],\n params: marketplaceParams,\n query: listMarketplaceAcceptancesQuery,\n response: z.object({ data: z.array(pendingAcceptanceSchema) }),\n annotations: { readOnly: true },\n },\n {\n operationId: \"decideMarketplaceOrders\",\n method: \"POST\",\n path: `${BASE}/acceptances`,\n summary:\n \"Accept or refuse one or many marketplace orders on the acceptance clock, all-or-nothing. ACCEPT may carry `admission` (`admitStockPastZero: true` after the store was told an item is short) and `preparationMinutes`. REJECT cancels the order here and asks the marketplace to cancel it, with `reasonCode` from the marketplace's own list (see `listMarketplaceIntegrations`; its first reason when omitted) and, for a reason that needs them, `offendingSkus` from the order. Any problem writes nothing: an unknown code or item is a 422, an order no longer awaiting a decision a 409, and the store's own refusal a 409 with its code (e.g. `MARKETPLACE_STOCK_ASK` with the short items). `validateOnly: true` checks everything without writing.\",\n tags: [\"marketplace\"],\n params: marketplaceParams,\n body: decideMarketplaceOrdersBody,\n response: z.object({ data: z.object({ validateOnly: z.boolean(), decisions: z.array(decidedSchema) }) }),\n annotations: { readOnly: false, destructive: true, openWorld: true },\n },\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b,SACE;AAAA,IACF,MAAM,CAAC,aAAa;AAAA,IACpB,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,GAAG,OAAO,EAAE,MAAM,cAAc,EAAE,CAAC,EAAE,CAAC;AAAA,IACpG,aAAa,EAAE,UAAU,OAAO,aAAa,MAAM;AAAA,EACrD;AAAA,EACA;AAAA,IACE,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,MAAM,GAAG,IAAI;AAAA,IACb,SACE;AAAA,IACF,MAAM,CAAC,aAAa;AAAA,IACpB,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,EAAE,CAAC;AAAA,IAC7D,aAAa,EAAE,UAAU,KAAK;AAAA,EAChC;AAAA,EACA;AAAA,IACE,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,MAAM,GAAG,IAAI;AAAA,IACb,SACE;AAAA,IACF,MAAM,CAAC,aAAa;AAAA,IACpB,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,GAAG,WAAW,EAAE,MAAM,aAAa,EAAE,CAAC,EAAE,CAAC;AAAA,IACvG,aAAa,EAAE,UAAU,OAAO,aAAa,MAAM,WAAW,KAAK;AAAA,EACrE;AACF;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { O as OutboundResult } from './adapter-CYJzu1c9.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The HTTP half every Open Delivery adapter shares: the token grant and its
|
|
5
|
+
* cache, and one authenticated call. Not a subpath: an adapter folder
|
|
6
|
+
* (`../99food`, `../keeta`) builds a {@link OpenDeliveryDialect} and hands it
|
|
7
|
+
* to these functions, so the standard is written once and each marketplace's
|
|
8
|
+
* departures from it are data in its own folder.
|
|
9
|
+
*
|
|
10
|
+
* Open Delivery standardizes the PATHS under each Ordering Application's own
|
|
11
|
+
* base URL, so the base URL per environment is part of the dialect.
|
|
12
|
+
*/
|
|
13
|
+
/** Where an Ordering Application serves Open Delivery, per environment. */
|
|
14
|
+
type OpenDeliveryApiBaseUrls = Readonly<Record<"SANDBOX" | "PRODUCTION", string>>;
|
|
15
|
+
/** The result that ends a call before it was answered usefully. */
|
|
16
|
+
type OpenDeliveryStop = Exclude<OutboundResult, {
|
|
17
|
+
kind: "accepted";
|
|
18
|
+
}>;
|
|
19
|
+
|
|
20
|
+
export type { OpenDeliveryApiBaseUrls as O, OpenDeliveryStop as a };
|
|
@@ -17,6 +17,75 @@ type MarketplaceLifecycleAnswer = "moved" | "unchanged" | {
|
|
|
17
17
|
reason: string;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The order-side vocabulary the host's order port speaks: what a resolved line
|
|
22
|
+
* is, what the queue shows, what a person stated, and why an order or a
|
|
23
|
+
* cancellation ended. Plain data with no engine dependency; `./ports`
|
|
24
|
+
* re-exports every name, so a host imports them from there as before.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* One order line after the engine has matched it against the SKU map.
|
|
28
|
+
* `subjectRef` is the host catalog id, or null when the SKU was never mapped —
|
|
29
|
+
* never an error, and never a reason to refuse the order. `variationRef` is
|
|
30
|
+
* the variation of `subjectRef` the SKU was mapped to (FUT-4927), or null for
|
|
31
|
+
* the item alone and for every unmapped line.
|
|
32
|
+
*/
|
|
33
|
+
interface ResolvedOrderLine {
|
|
34
|
+
externalSku: string;
|
|
35
|
+
name: string;
|
|
36
|
+
quantity: number;
|
|
37
|
+
unitPriceCents: number;
|
|
38
|
+
note: string | null;
|
|
39
|
+
subjectRef: string | null;
|
|
40
|
+
variationRef: string | null;
|
|
41
|
+
}
|
|
42
|
+
/** What the acceptance queue shows about an order, resolved by the host. */
|
|
43
|
+
interface MarketplaceOrderSummary {
|
|
44
|
+
buyerName: string | null;
|
|
45
|
+
totalCents: number;
|
|
46
|
+
unmappedLines: number;
|
|
47
|
+
createdAt: string | null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* What a person stated beside an accept, for the host's admission to read.
|
|
51
|
+
* Every field is optional and the host decides what it means.
|
|
52
|
+
*/
|
|
53
|
+
interface MarketplaceAdmission {
|
|
54
|
+
/** "Accept anyway": the person was told the order is short and confirmed. */
|
|
55
|
+
admitStockPastZero?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** The host's answer: proceed, or refuse with its own coded reason. */
|
|
58
|
+
type MarketplaceAdmissionResult = {
|
|
59
|
+
admitted: true;
|
|
60
|
+
} | {
|
|
61
|
+
admitted: false;
|
|
62
|
+
/** The host's machine code (`MARKETPLACE_STOCK_ASK`). The route answers 409 with it. */
|
|
63
|
+
code: string;
|
|
64
|
+
/** The host's sentence, in the caller's language. */
|
|
65
|
+
message: string;
|
|
66
|
+
/** Anything the client needs to ask the person (the short lines). */
|
|
67
|
+
details?: unknown;
|
|
68
|
+
};
|
|
69
|
+
/** Why the engine tells the host to refuse an order. Vocabulary, not copy. */
|
|
70
|
+
type MarketplaceRefusal = "REJECTED" | "EXPIRED" | "CANCELLED";
|
|
71
|
+
/**
|
|
72
|
+
* Why the store's own cancellation request FAILED. Vocabulary, not copy.
|
|
73
|
+
*
|
|
74
|
+
* - `REFUSED`: the marketplace judged the request and denied it: its denial
|
|
75
|
+
* event, an answer that is its business refusal, or an adapter that has no
|
|
76
|
+
* cancellation API to call. An adapter that cannot tell a business 4xx from
|
|
77
|
+
* a malformed request (iFood, Rappi) reports every final 4xx as REFUSED.
|
|
78
|
+
* - `UNREACHABLE`: our own request never got a judgement: no credentials or
|
|
79
|
+
* ones that do not open, a token the marketplace did not grant, a request
|
|
80
|
+
* the marketplace calls malformed (99Food's 400), or every attempt failed
|
|
81
|
+
* on the network or a 5xx. Retrying, or fixing the connection, can help.
|
|
82
|
+
* - `TIMEOUT`: no answer inside the marketplace's cancellation window.
|
|
83
|
+
*
|
|
84
|
+
* A host written before `UNREACHABLE` existed treats an unknown value as it
|
|
85
|
+
* treats REFUSED: the order stays and a person finishes in the marketplace's app.
|
|
86
|
+
*/
|
|
87
|
+
type CancellationFailureReason = "REFUSED" | "UNREACHABLE" | "TIMEOUT";
|
|
88
|
+
|
|
20
89
|
/**
|
|
21
90
|
* What the engine needs FROM its host, and nothing more.
|
|
22
91
|
*
|
|
@@ -119,34 +188,6 @@ interface MarketplaceDb {
|
|
|
119
188
|
}>;
|
|
120
189
|
};
|
|
121
190
|
}
|
|
122
|
-
/**
|
|
123
|
-
* One order line after the engine has matched it against the SKU map.
|
|
124
|
-
* `subjectRef` is the host catalog id, or null when the SKU was never mapped —
|
|
125
|
-
* never an error, and never a reason to refuse the order.
|
|
126
|
-
*/
|
|
127
|
-
interface ResolvedOrderLine {
|
|
128
|
-
externalSku: string;
|
|
129
|
-
name: string;
|
|
130
|
-
quantity: number;
|
|
131
|
-
unitPriceCents: number;
|
|
132
|
-
note: string | null;
|
|
133
|
-
subjectRef: string | null;
|
|
134
|
-
}
|
|
135
|
-
/** What the acceptance queue shows about an order, resolved by the host. */
|
|
136
|
-
interface MarketplaceOrderSummary {
|
|
137
|
-
buyerName: string | null;
|
|
138
|
-
totalCents: number;
|
|
139
|
-
unmappedLines: number;
|
|
140
|
-
createdAt: string | null;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* What a person stated beside an accept, for the host's admission to read.
|
|
144
|
-
* Every field is optional and the host decides what it means.
|
|
145
|
-
*/
|
|
146
|
-
interface MarketplaceAdmission {
|
|
147
|
-
/** "Accept anyway": the person was told the order is short and confirmed. */
|
|
148
|
-
admitStockPastZero?: boolean;
|
|
149
|
-
}
|
|
150
191
|
/** One decision as the host's admission sees it, BEFORE the claim commits. */
|
|
151
192
|
interface MarketplaceAdmissionRequest {
|
|
152
193
|
clientId: string;
|
|
@@ -161,37 +202,6 @@ interface MarketplaceAdmissionRequest {
|
|
|
161
202
|
*/
|
|
162
203
|
db: MarketplaceDb;
|
|
163
204
|
}
|
|
164
|
-
/** The host's answer: proceed, or refuse with its own coded reason. */
|
|
165
|
-
type MarketplaceAdmissionResult = {
|
|
166
|
-
admitted: true;
|
|
167
|
-
} | {
|
|
168
|
-
admitted: false;
|
|
169
|
-
/** The host's machine code (`MARKETPLACE_STOCK_ASK`). The route answers 409 with it. */
|
|
170
|
-
code: string;
|
|
171
|
-
/** The host's sentence, in the caller's language. */
|
|
172
|
-
message: string;
|
|
173
|
-
/** Anything the client needs to ask the person (the short lines). */
|
|
174
|
-
details?: unknown;
|
|
175
|
-
};
|
|
176
|
-
/** Why the engine tells the host to refuse an order. Vocabulary, not copy. */
|
|
177
|
-
type MarketplaceRefusal = "REJECTED" | "EXPIRED" | "CANCELLED";
|
|
178
|
-
/**
|
|
179
|
-
* Why the store's own cancellation request FAILED. Vocabulary, not copy.
|
|
180
|
-
*
|
|
181
|
-
* - `REFUSED`: the marketplace judged the request and denied it: its denial
|
|
182
|
-
* event, an answer that is its business refusal, or an adapter that has no
|
|
183
|
-
* cancellation API to call. An adapter that cannot tell a business 4xx from
|
|
184
|
-
* a malformed request (iFood, Rappi) reports every final 4xx as REFUSED.
|
|
185
|
-
* - `UNREACHABLE`: our own request never got a judgement: no credentials or
|
|
186
|
-
* ones that do not open, a token the marketplace did not grant, a request
|
|
187
|
-
* the marketplace calls malformed (99Food's 400), or every attempt failed
|
|
188
|
-
* on the network or a 5xx. Retrying, or fixing the connection, can help.
|
|
189
|
-
* - `TIMEOUT`: no answer inside the marketplace's cancellation window.
|
|
190
|
-
*
|
|
191
|
-
* A host written before `UNREACHABLE` existed treats an unknown value as it
|
|
192
|
-
* treats REFUSED: the order stays and a person finishes in the marketplace's app.
|
|
193
|
-
*/
|
|
194
|
-
type CancellationFailureReason = "REFUSED" | "UNREACHABLE" | "TIMEOUT";
|
|
195
205
|
/**
|
|
196
206
|
* The host's domain, as five questions the engine asks and never answers.
|
|
197
207
|
*
|
|
@@ -218,6 +228,13 @@ interface MarketplaceOrderPort {
|
|
|
218
228
|
create(clientId: string, order: NormalizedMarketplaceOrder, lines: readonly ResolvedOrderLine[], db: MarketplaceDb): Promise<string>;
|
|
219
229
|
/** Does this catalog id exist and belong to this tenant? */
|
|
220
230
|
catalogHas(clientId: string, subjectRef: string): Promise<boolean>;
|
|
231
|
+
/**
|
|
232
|
+
* OPTIONAL. Is `variationRef` a variation of the catalog id `subjectRef`,
|
|
233
|
+
* and this tenant's? Asked before a SKU is mapped to a variation (FUT-4927);
|
|
234
|
+
* `subjectRef` has already passed `catalogHas`. Absent: a mapping that names
|
|
235
|
+
* a variation is refused, and mapping to the item alone works as before.
|
|
236
|
+
*/
|
|
237
|
+
catalogHasVariation?(clientId: string, subjectRef: string, variationRef: string): Promise<boolean>;
|
|
221
238
|
/** The store said yes, or the connection auto-accepts. */
|
|
222
239
|
onAccepted(clientId: string, orderId: string): Promise<void>;
|
|
223
240
|
/**
|
|
@@ -515,6 +532,13 @@ interface IngestionTarget {
|
|
|
515
532
|
* The package never dereferences `menuItemId`. It asks the host whether the id
|
|
516
533
|
* is theirs (`order.catalogHas`, in `./bulk.ts`) and stores it; what the id
|
|
517
534
|
* MEANS is the host's.
|
|
535
|
+
*
|
|
536
|
+
* A link may narrow the mapping to ONE variation of that id (`variationId`,
|
|
537
|
+
* FUT-4927): a marketplace SKU usually names one flavour or size, and the
|
|
538
|
+
* host's order line is then the item plus that variation. `variationId` null
|
|
539
|
+
* is the item alone, exactly as before it existed; it is never set without
|
|
540
|
+
* `menuItemId`, and the host answers whether it belongs to the item
|
|
541
|
+
* (`order.catalogHasVariation`).
|
|
518
542
|
*/
|
|
519
543
|
/** A link as every read surface sees it. */
|
|
520
544
|
interface MarketplaceMenuLinkView {
|
|
@@ -524,6 +548,8 @@ interface MarketplaceMenuLinkView {
|
|
|
524
548
|
externalName: string;
|
|
525
549
|
/** The host catalog id, or null while the SKU is unmapped. */
|
|
526
550
|
menuItemId: string | null;
|
|
551
|
+
/** The variation of `menuItemId` the SKU names, or null for the item alone. */
|
|
552
|
+
variationId: string | null;
|
|
527
553
|
lastSeenAt: Date;
|
|
528
554
|
}
|
|
529
555
|
|
|
@@ -559,12 +585,17 @@ type IntegrationRowInput = ({
|
|
|
559
585
|
provider: string;
|
|
560
586
|
reason?: string | null;
|
|
561
587
|
};
|
|
562
|
-
/**
|
|
588
|
+
/**
|
|
589
|
+
* One SKU link: map it to a catalog id, or unmap it with `menuItemId: null`.
|
|
590
|
+
* `variationId` narrows the mapping to one variation of that id (FUT-4927);
|
|
591
|
+
* absent or null maps the item alone, and it may not be set on an unmap.
|
|
592
|
+
*/
|
|
563
593
|
interface MenuLinkRowInput {
|
|
564
594
|
provider: string;
|
|
565
595
|
externalSku: string;
|
|
566
596
|
externalName?: string;
|
|
567
597
|
menuItemId: string | null;
|
|
598
|
+
variationId?: string | null;
|
|
568
599
|
}
|
|
569
600
|
|
|
570
601
|
/** Why a decision (or a store cancellation) was refused. Vocabulary, not copy. */
|
package/dist/hono/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hono, Context } from 'hono';
|
|
2
2
|
import { ApiMarketplace, MarketplaceApiConfig, MarketplaceActor } from '../server/index.js';
|
|
3
|
-
import '../engine-
|
|
3
|
+
import '../engine-DK3iV_Kk.js';
|
|
4
4
|
import '../adapter-CYJzu1c9.js';
|
|
5
5
|
import '@12-apps/wiring';
|
|
6
6
|
import 'zod';
|
package/dist/hono/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createApiMarketplace
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-WVZ2IXFH.js";
|
|
4
|
+
import "../chunk-ZO4S3LF4.js";
|
|
5
|
+
import "../chunk-2BA2EHNF.js";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "../chunk-7QVYU63E.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AcceptanceDecision, a as AcceptanceStatus, b as AvailabilityJobPayload, c as AvailabilityOutcome, d as AvailabilityRetryError, e as AvailabilitySweepResult, B as BulkProblem, f as BulkProblemCode, g as BulkResult, C as CancellationFailureReason, h as CancellationStatus, i as CatalogueAction, j as CatalogueActionResult, k as CatalogueDocumentResult, l as CatalogueFailedAction, m as CatalogueFailureCode, n as CatalogueJobPayload, o as CatalogueOutcome, p as CataloguePublicationView, q as CataloguePublishInput, r as CatalogueRefusalCode, s as CatalogueRetryError, t as CatalogueStatus, u as CatalogueTarget, D as DecideManyResult, v as DecidedRow, w as DecisionInput, x as DecisionProblem, y as DecisionProblemCode, z as DecisionResult, E as DeliveryOutcome, F as ExpirySweepResult, G as FetchOrderJobPayload, H as FetchOrderOutcome, I as FetchOrderRetryError, J as InformStatusInput, K as IngestResult, L as IngestSettings, M as IngestionTarget, N as IntegrationRowInput, O as MARKETPLACE_AVAILABILITY_JOB, P as MARKETPLACE_CATALOGUE_JOB, Q as MARKETPLACE_FETCH_ORDER_JOB, R as MARKETPLACE_OUTBOUND_JOB, S as MarketplaceAdmission, T as MarketplaceAdmissionRequest, U as MarketplaceAdmissionResult, V as MarketplaceAuditEntry, W as MarketplaceAuditPort, X as MarketplaceCataloguePort, Y as MarketplaceClockPort, Z as MarketplaceDb, _ as MarketplaceEngine, $ as MarketplaceEngineConfig, a0 as MarketplaceEnqueuePort, a1 as MarketplaceIntegrationView, a2 as MarketplaceLifecycleAnswer, a3 as MarketplaceLifecycleFacts, a4 as MarketplaceLogger, a5 as MarketplaceMenuLinkView, a6 as MarketplaceOrderPort, a7 as MarketplaceOrderState, a8 as MarketplaceOrderSummary, a9 as MarketplacePorts, aa as MarketplaceRefusal, ab as MarketplaceSecretsPort, ac as MenuLinkRowInput, ad as OUTBOUND_GIVE_UP_MS, ae as OUTBOUND_STALE_MS, af as OutboundAction, ag as OutboundAttempt, ah as OutboundJobPayload, ai as OutboundOutcome, aj as OutboundRetryError, ak as OutboundSweepResult, al as PauseOutcome, am as PauseStoreInput, an as PauseStoreResult, ao as PendingAcceptance, ap as PendingInboxEvent, aq as ResolvedOrderLine, ar as ResumeOutcome, as as STORE_PAUSE_LEASE_MS, at as SaveMarketplaceIntegrationInput, au as StoreAvailabilityView, av as StorePauseFailureCode, aw as StorePauseState, ax as StorePauseWanted, ay as availabilityDedupeKey, az as catalogueDedupeKey, aA as createMarketplaceEngine, aB as outboundDedupeKey } from './engine-
|
|
1
|
+
export { A as AcceptanceDecision, a as AcceptanceStatus, b as AvailabilityJobPayload, c as AvailabilityOutcome, d as AvailabilityRetryError, e as AvailabilitySweepResult, B as BulkProblem, f as BulkProblemCode, g as BulkResult, C as CancellationFailureReason, h as CancellationStatus, i as CatalogueAction, j as CatalogueActionResult, k as CatalogueDocumentResult, l as CatalogueFailedAction, m as CatalogueFailureCode, n as CatalogueJobPayload, o as CatalogueOutcome, p as CataloguePublicationView, q as CataloguePublishInput, r as CatalogueRefusalCode, s as CatalogueRetryError, t as CatalogueStatus, u as CatalogueTarget, D as DecideManyResult, v as DecidedRow, w as DecisionInput, x as DecisionProblem, y as DecisionProblemCode, z as DecisionResult, E as DeliveryOutcome, F as ExpirySweepResult, G as FetchOrderJobPayload, H as FetchOrderOutcome, I as FetchOrderRetryError, J as InformStatusInput, K as IngestResult, L as IngestSettings, M as IngestionTarget, N as IntegrationRowInput, O as MARKETPLACE_AVAILABILITY_JOB, P as MARKETPLACE_CATALOGUE_JOB, Q as MARKETPLACE_FETCH_ORDER_JOB, R as MARKETPLACE_OUTBOUND_JOB, S as MarketplaceAdmission, T as MarketplaceAdmissionRequest, U as MarketplaceAdmissionResult, V as MarketplaceAuditEntry, W as MarketplaceAuditPort, X as MarketplaceCataloguePort, Y as MarketplaceClockPort, Z as MarketplaceDb, _ as MarketplaceEngine, $ as MarketplaceEngineConfig, a0 as MarketplaceEnqueuePort, a1 as MarketplaceIntegrationView, a2 as MarketplaceLifecycleAnswer, a3 as MarketplaceLifecycleFacts, a4 as MarketplaceLogger, a5 as MarketplaceMenuLinkView, a6 as MarketplaceOrderPort, a7 as MarketplaceOrderState, a8 as MarketplaceOrderSummary, a9 as MarketplacePorts, aa as MarketplaceRefusal, ab as MarketplaceSecretsPort, ac as MenuLinkRowInput, ad as OUTBOUND_GIVE_UP_MS, ae as OUTBOUND_STALE_MS, af as OutboundAction, ag as OutboundAttempt, ah as OutboundJobPayload, ai as OutboundOutcome, aj as OutboundRetryError, ak as OutboundSweepResult, al as PauseOutcome, am as PauseStoreInput, an as PauseStoreResult, ao as PendingAcceptance, ap as PendingInboxEvent, aq as ResolvedOrderLine, ar as ResumeOutcome, as as STORE_PAUSE_LEASE_MS, at as SaveMarketplaceIntegrationInput, au as StoreAvailabilityView, av as StorePauseFailureCode, aw as StorePauseState, ax as StorePauseWanted, ay as availabilityDedupeKey, az as catalogueDedupeKey, aA as createMarketplaceEngine, aB as outboundDedupeKey } from './engine-DK3iV_Kk.js';
|
|
2
2
|
import { c as MarketplaceAdapter, i as MarketplaceProvider, j as CancellationReason } from './adapter-CYJzu1c9.js';
|
|
3
3
|
export { A as AdapterCallContext, k as AdapterTokenCache, l as CancellationOutcome, m as CancellationRequestInput, n as CatalogueCallContext, o as CatalogueFailure, p as CatalogueImage, q as CatalogueItem, e as CatalogueItemOut, r as CatalogueItemRef, C as CatalogueMenuEntry, b as CatalogueMenuOptions, s as CataloguePublishResult, t as CatalogueReadContext, u as CatalogueReadNotice, v as CatalogueReadRefusalCode, w as CatalogueReadResult, x as CatalogueReadWarning, y as CatalogueReadWarningCode, f as CatalogueReader, z as CatalogueSnapshot, B as CatalogueSnapshotCategory, D as CatalogueSnapshotItem, E as CatalogueSnapshotOption, F as CatalogueSnapshotOptionGroup, G as CatalogueStoredImage, H as CatalogueWarningCode, I as FetchOrderResult, M as MarketplaceAvailability, J as MarketplaceCapabilities, K as MarketplaceCatalogue, L as MarketplaceCredentials, Q as MarketplaceDeliveredBy, R as MarketplaceDiscountSponsor, T as MarketplaceHttp, U as MarketplaceHttpRequest, V as MarketplaceHttpResponse, W as MarketplaceLifecycle, X as MarketplaceOrderType, Y as NormalizedAddress, Z as NormalizedBuyer, N as NormalizedEvent, a as NormalizedMarketplaceOrder, _ as NormalizedOrderDiscount, $ as NormalizedOrderLine, a0 as OutboundOrderRef, O as OutboundResult, a1 as PROVIDER_ID_PATTERN, P as PullCatalogue, d as PushCatalogue, a2 as StatusFacts, a3 as StatusStep, h as StorePauseRef, S as StorePauseRequest, g as StorePauseResult, a4 as answered, a5 as centsFromMajor, a6 as outboundResultOf, a7 as tokenGrantResultOf } from './adapter-CYJzu1c9.js';
|
|
4
4
|
|
package/dist/index.js
CHANGED
|
@@ -72,7 +72,7 @@ import {
|
|
|
72
72
|
tellCancellationFailed,
|
|
73
73
|
upsertLink,
|
|
74
74
|
viewOf
|
|
75
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-2BA2EHNF.js";
|
|
76
76
|
import {
|
|
77
77
|
centsFromMajor
|
|
78
78
|
} from "./chunk-WN2EK4KX.js";
|
|
@@ -187,16 +187,27 @@ async function auditArchives(ctx, db, input, now) {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
__name(auditArchives, "auditArchives");
|
|
190
|
+
async function linkRowProblems(ctx, clientId, row, index) {
|
|
191
|
+
const variationPath = ["links", index, "variationId"];
|
|
192
|
+
const variationId = row.variationId ?? null;
|
|
193
|
+
if (row.menuItemId === null) {
|
|
194
|
+
return variationId === null ? [] : [{ path: variationPath, code: "CATALOG_ITEM_NOT_FOUND" }];
|
|
195
|
+
}
|
|
196
|
+
if (!await ctx.ports.order.catalogHas(clientId, row.menuItemId)) {
|
|
197
|
+
return [{ path: ["links", index, "menuItemId"], code: "CATALOG_ITEM_NOT_FOUND" }];
|
|
198
|
+
}
|
|
199
|
+
if (variationId === null) return [];
|
|
200
|
+
const order = ctx.ports.order;
|
|
201
|
+
const belongs = order.catalogHasVariation ? await order.catalogHasVariation(clientId, row.menuItemId, variationId) : false;
|
|
202
|
+
return belongs ? [] : [{ path: variationPath, code: "CATALOG_ITEM_NOT_FOUND" }];
|
|
203
|
+
}
|
|
204
|
+
__name(linkRowProblems, "linkRowProblems");
|
|
190
205
|
async function upsertMenuLinks(ctx, input) {
|
|
191
206
|
const problems = [
|
|
192
207
|
...duplicates(input.rows, (row) => `${row.provider}\0${row.externalSku}`, "links", "externalSku"),
|
|
193
208
|
...unknownProviders(ctx, input.rows, "links")
|
|
194
209
|
];
|
|
195
|
-
for (const [index, row] of input.rows.entries())
|
|
196
|
-
if (row.menuItemId !== null && !await ctx.ports.order.catalogHas(input.clientId, row.menuItemId)) {
|
|
197
|
-
problems.push({ path: ["links", index, "menuItemId"], code: "CATALOG_ITEM_NOT_FOUND" });
|
|
198
|
-
}
|
|
199
|
-
}
|
|
210
|
+
for (const [index, row] of input.rows.entries()) problems.push(...await linkRowProblems(ctx, input.clientId, row, index));
|
|
200
211
|
if (problems.length > 0) return { kind: "refused", problems };
|
|
201
212
|
const validateOnly = input.validateOnly === true;
|
|
202
213
|
const written = await inTransaction(ctx, validateOnly, async (db) => {
|