@12-apps/marketplace 1.0.0 → 1.2.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 +44 -9
- package/README.md +149 -4
- package/dist/99food/en-US.d.ts +19 -0
- package/dist/99food/en-US.js +23 -0
- package/dist/99food/en-US.js.map +1 -0
- package/dist/99food/index.d.ts +116 -0
- package/dist/99food/index.js +361 -0
- package/dist/99food/index.js.map +1 -0
- package/dist/99food/pt-BR.d.ts +23 -0
- package/dist/99food/pt-BR.js +23 -0
- package/dist/99food/pt-BR.js.map +1 -0
- package/dist/{adapter-CgCAYBSJ.d.ts → adapter-_iuSxvVD.d.ts} +41 -1
- package/dist/{chunk-OEKTWUQH.js → chunk-24RQZPSV.js} +1 -1
- package/dist/chunk-24RQZPSV.js.map +1 -0
- package/dist/chunk-BD7DS3XM.js +78 -0
- package/dist/chunk-BD7DS3XM.js.map +1 -0
- package/dist/{chunk-BEMTRJYM.js → chunk-CRYFYDQ2.js} +28 -4
- package/dist/{chunk-BEMTRJYM.js.map → chunk-CRYFYDQ2.js.map} +1 -1
- package/dist/chunk-D2X7TOR6.js +1240 -0
- package/dist/chunk-D2X7TOR6.js.map +1 -0
- package/dist/{engine-DDE0mnTu.d.ts → engine-D-a4mttc.d.ts} +117 -17
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +2 -2
- package/dist/ifood/index.d.ts +10 -12
- package/dist/ifood/index.js +19 -61
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +113 -497
- package/dist/index.js.map +1 -1
- package/dist/manifest/server.d.ts +3 -2
- package/dist/manifest/server.js +2 -2
- package/dist/rappi/en-US.d.ts +14 -0
- package/dist/rappi/en-US.js +18 -0
- package/dist/rappi/en-US.js.map +1 -0
- package/dist/rappi/index.d.ts +190 -0
- package/dist/rappi/index.js +353 -0
- package/dist/rappi/index.js.map +1 -0
- package/dist/rappi/pt-BR.d.ts +18 -0
- package/dist/rappi/pt-BR.js +18 -0
- package/dist/rappi/pt-BR.js.map +1 -0
- package/dist/server/index.d.ts +12 -5
- package/dist/server/index.js +4 -2
- package/package.json +26 -2
- package/prisma/marketplace.prisma +12 -1
- package/prisma/migrations/20261112120000_marketplace_cancellation_failure/migration.sql +21 -0
- package/src/99food/copy.ts +36 -0
- package/src/99food/en-US.ts +19 -0
- package/src/99food/index.ts +121 -0
- package/src/99food/normalize.ts +263 -0
- package/src/99food/outbound.ts +220 -0
- package/src/99food/pt-BR.ts +23 -0
- package/src/core/acceptance.ts +30 -14
- package/src/core/adapter.ts +23 -1
- package/src/core/cancellation-outcome.ts +92 -0
- package/src/core/cancellation.ts +46 -15
- package/src/core/decisions.ts +94 -19
- package/src/core/engine.ts +8 -0
- package/src/core/fetch-order.ts +253 -0
- package/src/core/inbox.ts +8 -2
- package/src/core/ingest.ts +10 -2
- package/src/core/integration.ts +30 -1
- package/src/core/order-fetch-marks.ts +63 -0
- package/src/core/outbound-sweep.ts +87 -8
- package/src/core/outbound.ts +103 -7
- package/src/core/payload-read.ts +101 -0
- package/src/core/pipeline.ts +64 -15
- package/src/core/ports.ts +32 -0
- package/src/core/state.ts +6 -1
- package/src/core/types.ts +14 -0
- package/src/ifood/index.ts +9 -0
- package/src/ifood/normalize.ts +15 -88
- package/src/index.ts +10 -1
- package/src/rappi/copy.ts +39 -0
- package/src/rappi/en-US.ts +14 -0
- package/src/rappi/index.ts +155 -0
- package/src/rappi/normalize.ts +314 -0
- package/src/rappi/outbound.ts +182 -0
- package/src/rappi/pt-BR.ts +18 -0
- package/src/server/index.ts +1 -0
- package/src/server/jobs.ts +38 -4
- package/dist/chunk-6OODIO3E.js +0 -395
- package/dist/chunk-6OODIO3E.js.map +0 -1
- package/dist/chunk-OEKTWUQH.js.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Rappi adapter's pt-BR pack: Rappi's reject types in the words a store
|
|
3
|
+
* reads. A host passes this pack by hand: choosing the language is a line in
|
|
4
|
+
* the host's diff.
|
|
5
|
+
*/
|
|
6
|
+
declare const RAPPI_ADAPTER_COPY_PT_BR: {
|
|
7
|
+
readonly reasonLabels: {
|
|
8
|
+
readonly ITEM_OUT_OF_STOCK: "Item indisponível";
|
|
9
|
+
readonly ITEM_NOT_FOUND: "Item não encontrado";
|
|
10
|
+
readonly ITEM_WRONG_PRICE: "Preço do item errado";
|
|
11
|
+
readonly ORDER_MISSING_INFORMATION: "Faltam informações no pedido";
|
|
12
|
+
readonly ORDER_MISSING_ADDRESS_INFORMATION: "Faltam informações do endereço";
|
|
13
|
+
readonly ORDER_TOTAL_INCORRECT: "Total do pedido incorreto";
|
|
14
|
+
};
|
|
15
|
+
readonly missingStreetNumber: "s/n";
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { RAPPI_ADAPTER_COPY_PT_BR };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "../chunk-7QVYU63E.js";
|
|
2
|
+
|
|
3
|
+
// src/rappi/pt-BR.ts
|
|
4
|
+
var RAPPI_ADAPTER_COPY_PT_BR = {
|
|
5
|
+
reasonLabels: {
|
|
6
|
+
ITEM_OUT_OF_STOCK: "Item indispon\xEDvel",
|
|
7
|
+
ITEM_NOT_FOUND: "Item n\xE3o encontrado",
|
|
8
|
+
ITEM_WRONG_PRICE: "Pre\xE7o do item errado",
|
|
9
|
+
ORDER_MISSING_INFORMATION: "Faltam informa\xE7\xF5es no pedido",
|
|
10
|
+
ORDER_MISSING_ADDRESS_INFORMATION: "Faltam informa\xE7\xF5es do endere\xE7o",
|
|
11
|
+
ORDER_TOTAL_INCORRECT: "Total do pedido incorreto"
|
|
12
|
+
},
|
|
13
|
+
missingStreetNumber: "s/n"
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
RAPPI_ADAPTER_COPY_PT_BR
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=pt-BR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/rappi/pt-BR.ts"],"sourcesContent":["import type { RappiAdapterCopy } from \"./copy\";\n\n/**\n * The Rappi adapter's pt-BR pack: Rappi's reject types in the words a store\n * reads. A host passes this pack by hand: choosing the language is a line in\n * the host's diff.\n */\nexport const RAPPI_ADAPTER_COPY_PT_BR = {\n reasonLabels: {\n ITEM_OUT_OF_STOCK: \"Item indisponível\",\n ITEM_NOT_FOUND: \"Item não encontrado\",\n ITEM_WRONG_PRICE: \"Preço do item errado\",\n ORDER_MISSING_INFORMATION: \"Faltam informações no pedido\",\n ORDER_MISSING_ADDRESS_INFORMATION: \"Faltam informações do endereço\",\n ORDER_TOTAL_INCORRECT: \"Total do pedido incorreto\",\n },\n missingStreetNumber: \"s/n\",\n} as const satisfies RappiAdapterCopy;\n"],"mappings":";;;AAOO,IAAM,2BAA2B;AAAA,EACtC,cAAc;AAAA,IACZ,mBAAmB;AAAA,IACnB,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,IAClB,2BAA2B;AAAA,IAC3B,mCAAmC;AAAA,IACnC,uBAAuB;AAAA,EACzB;AAAA,EACA,qBAAqB;AACvB;","names":[]}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as DecisionProblemCode, b as BulkProblemCode, x as MarketplaceEngine, H as MarketplaceLogger, W as OutboundJobPayload, F as FetchOrderJobPayload } from '../engine-D-a4mttc.js';
|
|
2
2
|
import { WireRoute, WireJobBlueprint } from '@12-apps/wiring';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import '../adapter-
|
|
4
|
+
import '../adapter-_iuSxvVD.js';
|
|
5
5
|
|
|
6
6
|
/** Every problem code a route can answer, decisions and bulk writes alike. */
|
|
7
7
|
type MarketplaceProblemCode = DecisionProblemCode | BulkProblemCode;
|
|
@@ -114,6 +114,9 @@ declare const MARKETPLACE_DECIDE = "marketplace:decide";
|
|
|
114
114
|
* - `outbound`, on demand: one call to a marketplace, three attempts with
|
|
115
115
|
* backoff. Its idempotency is the ROW's (the engine re-reads it), never the
|
|
116
116
|
* queue's dedupe alone.
|
|
117
|
+
* - `fetch-order`, on demand: one GET of an order a marketplace's event only
|
|
118
|
+
* announced (`orderToFetch`), then the one ingest path. Three attempts with
|
|
119
|
+
* backoff; the reconciliation sweep re-queues a row still owed.
|
|
117
120
|
* - `outbound-sweep`, every five minutes: re-queues every call a row still
|
|
118
121
|
* owes (a PENDING request, an accept with no confirm stamp) once it is older
|
|
119
122
|
* than the job's own retry span, so a refused enqueue or a dead process
|
|
@@ -124,16 +127,19 @@ declare const MARKETPLACE_DECIDE = "marketplace:decide";
|
|
|
124
127
|
*
|
|
125
128
|
* Bound with `{ engine }`, these arrive at a runner as
|
|
126
129
|
* `marketplace.expire-acceptances`, `marketplace.reconcile-inbox`,
|
|
127
|
-
* `marketplace.outbound
|
|
130
|
+
* `marketplace.outbound`, `marketplace.fetch-order` and
|
|
131
|
+
* `marketplace.outbound-sweep`.
|
|
128
132
|
*/
|
|
129
133
|
/** What the host closes over at bind time: the mounted engine. */
|
|
130
134
|
interface MarketplaceJobDeps {
|
|
131
|
-
engine: Pick<MarketplaceEngine, "expireLapsed" | "retryable" | "reprocess" | "runOutbound" | "sweepOutbound">;
|
|
135
|
+
engine: Pick<MarketplaceEngine, "expireLapsed" | "retryable" | "reprocess" | "runOutbound" | "runFetchOrder" | "sweepOutbound">;
|
|
132
136
|
}
|
|
133
137
|
/** The single-flight queue name (`@12-apps/jobs`' `SWEEP_QUEUE`), as a literal. */
|
|
134
138
|
declare const MARKETPLACE_SWEEP_QUEUE = "sweeps";
|
|
135
139
|
/** The outbound job's attempts: the last one stamps the failure. */
|
|
136
140
|
declare const MARKETPLACE_OUTBOUND_ATTEMPTS = 3;
|
|
141
|
+
/** The fetch job's attempts: the last one settles the inbox row FAILED. */
|
|
142
|
+
declare const MARKETPLACE_FETCH_ORDER_ATTEMPTS = 3;
|
|
137
143
|
/** The jobs contribution. */
|
|
138
144
|
declare const MARKETPLACE_JOBS: {
|
|
139
145
|
readonly namespace: "marketplace";
|
|
@@ -141,6 +147,7 @@ declare const MARKETPLACE_JOBS: {
|
|
|
141
147
|
readonly "expire-acceptances": WireJobBlueprint<void, MarketplaceJobDeps>;
|
|
142
148
|
readonly "reconcile-inbox": WireJobBlueprint<void, MarketplaceJobDeps>;
|
|
143
149
|
readonly outbound: WireJobBlueprint<OutboundJobPayload, MarketplaceJobDeps>;
|
|
150
|
+
readonly "fetch-order": WireJobBlueprint<FetchOrderJobPayload, MarketplaceJobDeps>;
|
|
144
151
|
readonly "outbound-sweep": WireJobBlueprint<void, MarketplaceJobDeps>;
|
|
145
152
|
};
|
|
146
153
|
};
|
|
@@ -526,4 +533,4 @@ interface ApiMarketplace {
|
|
|
526
533
|
/** Build the route table over a mounted engine. */
|
|
527
534
|
declare function createApiMarketplace(config: MarketplaceApiConfig): ApiMarketplace;
|
|
528
535
|
|
|
529
|
-
export { type ApiMarketplace, MARKETPLACE_DECIDE, MARKETPLACE_JOBS, MARKETPLACE_MANAGE, MARKETPLACE_MCP_TOOLS, MARKETPLACE_OUTBOUND_ATTEMPTS, MARKETPLACE_PERMISSIONS, MARKETPLACE_SWEEP_QUEUE, type MarketplaceActor, type MarketplaceApiConfig, type MarketplaceJobDeps, type MarketplaceProblemCode, type MarketplaceRoute, type MarketplaceServerCopy, ORDER_NOT_PENDING_CODE, createApiMarketplace, decideMarketplaceOrdersBody, listMarketplaceAcceptancesQuery, listMarketplaceIntegrationsQuery, listMarketplaceMenuLinksQuery, marketplaceParams, upsertMarketplaceIntegrationsBody, upsertMarketplaceMenuLinksBody };
|
|
536
|
+
export { type ApiMarketplace, MARKETPLACE_DECIDE, MARKETPLACE_FETCH_ORDER_ATTEMPTS, MARKETPLACE_JOBS, MARKETPLACE_MANAGE, MARKETPLACE_MCP_TOOLS, MARKETPLACE_OUTBOUND_ATTEMPTS, MARKETPLACE_PERMISSIONS, MARKETPLACE_SWEEP_QUEUE, type MarketplaceActor, type MarketplaceApiConfig, type MarketplaceJobDeps, type MarketplaceProblemCode, type MarketplaceRoute, type MarketplaceServerCopy, ORDER_NOT_PENDING_CODE, createApiMarketplace, decideMarketplaceOrdersBody, listMarketplaceAcceptancesQuery, listMarketplaceIntegrationsQuery, listMarketplaceMenuLinksQuery, marketplaceParams, upsertMarketplaceIntegrationsBody, upsertMarketplaceMenuLinksBody };
|
package/dist/server/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
MARKETPLACE_FETCH_ORDER_ATTEMPTS,
|
|
2
3
|
MARKETPLACE_JOBS,
|
|
3
4
|
MARKETPLACE_OUTBOUND_ATTEMPTS,
|
|
4
5
|
MARKETPLACE_SWEEP_QUEUE,
|
|
5
6
|
ORDER_NOT_PENDING_CODE,
|
|
6
7
|
createApiMarketplace
|
|
7
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-CRYFYDQ2.js";
|
|
8
9
|
import {
|
|
9
10
|
MARKETPLACE_DECIDE,
|
|
10
11
|
MARKETPLACE_MANAGE,
|
|
@@ -18,10 +19,11 @@ import {
|
|
|
18
19
|
upsertMarketplaceIntegrationsBody,
|
|
19
20
|
upsertMarketplaceMenuLinksBody
|
|
20
21
|
} from "../chunk-UYFYGGCS.js";
|
|
21
|
-
import "../chunk-
|
|
22
|
+
import "../chunk-D2X7TOR6.js";
|
|
22
23
|
import "../chunk-7QVYU63E.js";
|
|
23
24
|
export {
|
|
24
25
|
MARKETPLACE_DECIDE,
|
|
26
|
+
MARKETPLACE_FETCH_ORDER_ATTEMPTS,
|
|
25
27
|
MARKETPLACE_JOBS,
|
|
26
28
|
MARKETPLACE_MANAGE,
|
|
27
29
|
MARKETPLACE_MCP_TOOLS,
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@12-apps/marketplace",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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). 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 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",
|
|
@@ -21,6 +21,30 @@
|
|
|
21
21
|
"types": "./dist/ifood/en-US.d.ts",
|
|
22
22
|
"default": "./dist/ifood/en-US.js"
|
|
23
23
|
},
|
|
24
|
+
"./99food": {
|
|
25
|
+
"types": "./dist/99food/index.d.ts",
|
|
26
|
+
"default": "./dist/99food/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./99food/pt-BR": {
|
|
29
|
+
"types": "./dist/99food/pt-BR.d.ts",
|
|
30
|
+
"default": "./dist/99food/pt-BR.js"
|
|
31
|
+
},
|
|
32
|
+
"./99food/en-US": {
|
|
33
|
+
"types": "./dist/99food/en-US.d.ts",
|
|
34
|
+
"default": "./dist/99food/en-US.js"
|
|
35
|
+
},
|
|
36
|
+
"./rappi": {
|
|
37
|
+
"types": "./dist/rappi/index.d.ts",
|
|
38
|
+
"default": "./dist/rappi/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./rappi/pt-BR": {
|
|
41
|
+
"types": "./dist/rappi/pt-BR.d.ts",
|
|
42
|
+
"default": "./dist/rappi/pt-BR.js"
|
|
43
|
+
},
|
|
44
|
+
"./rappi/en-US": {
|
|
45
|
+
"types": "./dist/rappi/en-US.d.ts",
|
|
46
|
+
"default": "./dist/rappi/en-US.js"
|
|
47
|
+
},
|
|
24
48
|
"./server": {
|
|
25
49
|
"types": "./dist/server/index.d.ts",
|
|
26
50
|
"default": "./dist/server/index.js"
|
|
@@ -216,14 +216,22 @@ model MarketplaceAcceptance {
|
|
|
216
216
|
/// The store's own cancellation request: PENDING (asked here, not
|
|
217
217
|
/// yet sent) → REQUESTED (the marketplace took the request) → CONFIRMED (it
|
|
218
218
|
/// cancelled) | FAILED (it refused, or every attempt failed). CHECK in the
|
|
219
|
-
/// migration; NULL when the store never asked
|
|
219
|
+
/// migration; NULL when the store never asked, or when an accept cleared a
|
|
220
|
+
/// FAILED request (`cancellationRequestedAt` then stays as its tombstone).
|
|
221
|
+
/// CONFIRMED is terminal.
|
|
220
222
|
cancellationStatus String? @map("cancellation_status")
|
|
221
223
|
/// The marketplace's own reason code the request carries, sent verbatim. Lives on the row, never in a job payload.
|
|
222
224
|
cancellationReasonCode String? @map("cancellation_reason_code")
|
|
223
225
|
/// The SKUs the request names, for a reason that needs them (a JSON array).
|
|
224
226
|
cancellationOffendingSkus Json? @map("cancellation_offending_skus")
|
|
225
227
|
/// When the request was stamped PENDING: what the outbound sweep ages it by.
|
|
228
|
+
/// With a NULL status it is a TOMBSTONE: the request an accept cleared,
|
|
229
|
+
/// which a synchronous marketplace's late "cancelled" can still match.
|
|
226
230
|
cancellationRequestedAt DateTime? @map("cancellation_requested_at")
|
|
231
|
+
/// Why the request FAILED: REFUSED (the marketplace said no, or every
|
|
232
|
+
/// attempt failed) or TIMEOUT (no answer inside its window). CHECK in the
|
|
233
|
+
/// migration; NULL unless `cancellationStatus` is FAILED.
|
|
234
|
+
cancellationFailureReason String? @map("cancellation_failure_reason")
|
|
227
235
|
/// The preparation time the accept stated, for a confirm that takes one.
|
|
228
236
|
preparationMinutes Int? @map("preparation_minutes")
|
|
229
237
|
/// The order's SKUs as the marketplace sent them (a JSON array): what
|
|
@@ -237,5 +245,8 @@ model MarketplaceAcceptance {
|
|
|
237
245
|
@@index([clientId, status])
|
|
238
246
|
@@index([acknowledgeBy])
|
|
239
247
|
@@index([cancellationRequestedAt])
|
|
248
|
+
// Also `marketplace_acceptances_cancellation_waiting_idx`, a PARTIAL index on
|
|
249
|
+
// cancellation_requested_at WHERE cancellation_status IN ('PENDING','REQUESTED'):
|
|
250
|
+
// SQL-only (migration 20261112120000), since Prisma cannot express the WHERE.
|
|
240
251
|
@@map("marketplace_acceptances")
|
|
241
252
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- @domains: marketplace
|
|
2
|
+
-- @12-apps/marketplace: why a store's cancellation request FAILED (FUT-4758).
|
|
3
|
+
-- Additive and replay-safe, like the engine's first migration: one nullable
|
|
4
|
+
-- column, its CHECK, and an index for the expiry of requests still waiting.
|
|
5
|
+
--
|
|
6
|
+
-- `cancellation_failure_reason` is REFUSED (the marketplace said no, or every
|
|
7
|
+
-- attempt failed) or TIMEOUT (no answer inside the marketplace's window). NULL
|
|
8
|
+
-- whenever `cancellation_status` is not FAILED, and on rows from before it.
|
|
9
|
+
|
|
10
|
+
ALTER TABLE "marketplace_acceptances" ADD COLUMN IF NOT EXISTS "cancellation_failure_reason" TEXT;
|
|
11
|
+
|
|
12
|
+
DO $$ BEGIN
|
|
13
|
+
ALTER TABLE "marketplace_acceptances" ADD CONSTRAINT "marketplace_acceptances_cancellation_failure_reason_check"
|
|
14
|
+
CHECK ("cancellation_failure_reason" IS NULL
|
|
15
|
+
OR "cancellation_failure_reason" IN ('REFUSED', 'TIMEOUT'));
|
|
16
|
+
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
|
|
17
|
+
|
|
18
|
+
-- The expiry reads only requests still waiting on the marketplace.
|
|
19
|
+
CREATE INDEX IF NOT EXISTS "marketplace_acceptances_cancellation_waiting_idx"
|
|
20
|
+
ON "marketplace_acceptances"("cancellation_requested_at")
|
|
21
|
+
WHERE "cancellation_status" IN ('PENDING', 'REQUESTED');
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words the 99Food adapter needs from its host, and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* Required and defaultless, like every copy port in this repo: the adapter
|
|
5
|
+
* ships no language of its own. Two packs sit beside it (`./pt-BR`,
|
|
6
|
+
* `./en-US`); a host passes one by hand, or its own.
|
|
7
|
+
*/
|
|
8
|
+
|
|
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;
|
|
28
|
+
|
|
29
|
+
export type NinetyNineFoodReasonCode = (typeof NINETY_NINE_FOOD_REASON_CODES)[number];
|
|
30
|
+
|
|
31
|
+
export interface NinetyNineFoodAdapterCopy {
|
|
32
|
+
/** One label per reason code. Sent as the request's `reason` text when the store wrote none. */
|
|
33
|
+
reasonLabels: Readonly<Record<NinetyNineFoodReasonCode, string>>;
|
|
34
|
+
/** What an address with no street number says instead. */
|
|
35
|
+
missingStreetNumber: string;
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NinetyNineFoodAdapterCopy } from "./copy";
|
|
2
|
+
|
|
3
|
+
/** The 99Food adapter's en-US pack: the same reasons, in English. */
|
|
4
|
+
export const NINETY_NINE_FOOD_ADAPTER_COPY_EN_US = {
|
|
5
|
+
reasonLabels: {
|
|
6
|
+
SYSTEMIC_ISSUES: "System problems",
|
|
7
|
+
DUPLICATE_APPLICATION: "Duplicate order",
|
|
8
|
+
UNAVAILABLE_ITEM: "Item unavailable",
|
|
9
|
+
RESTAURANT_WITHOUT_DELIVERY_PERSON: "No courier available",
|
|
10
|
+
OUTDATED_MENU: "Menu out of date",
|
|
11
|
+
ORDER_OUTSIDE_THE_DELIVERY_AREA: "Address outside the delivery area",
|
|
12
|
+
BLOCKED_CUSTOMER: "Blocked customer",
|
|
13
|
+
OUTSIDE_DELIVERY_HOURS: "Outside delivery hours",
|
|
14
|
+
INTERNAL_DIFFICULTIES_OF_THE_RESTAURANT: "Internal difficulties",
|
|
15
|
+
RISK_AREA: "Risk area",
|
|
16
|
+
DELIVERY_PROBLEM: "Delivery problem",
|
|
17
|
+
},
|
|
18
|
+
missingStreetNumber: "no number",
|
|
19
|
+
} as const satisfies NinetyNineFoodAdapterCopy;
|
|
@@ -0,0 +1,121 @@
|
|
|
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 { NINETY_NINE_FOOD_PROVIDER, normalizeOpenDeliveryEvent, verifyOpenDeliverySignature } from "./normalize";
|
|
8
|
+
import {
|
|
9
|
+
openDeliveryConfirm,
|
|
10
|
+
openDeliveryFetchOrder,
|
|
11
|
+
openDeliveryRequestCancellation,
|
|
12
|
+
type NinetyNineFoodApiBaseUrls,
|
|
13
|
+
} from "./outbound";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* `@12-apps/marketplace/99food` — 99Food, as one adapter on the engine.
|
|
17
|
+
*
|
|
18
|
+
* 99Food completed Open Delivery (Abrasel) adherence, so this adapter speaks
|
|
19
|
+
* Open Delivery v1.7.1: the signed webhook, `CREATED` → fetch the order,
|
|
20
|
+
* confirm, requestCancellation with the spec's codes. Everything 99Food is
|
|
21
|
+
* under this folder; the engine reaches it only through the
|
|
22
|
+
* {@link MarketplaceAdapter} port, and registering it is the whole cost:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { createNinetyNineFoodAdapter } from "@12-apps/marketplace/99food";
|
|
26
|
+
* import { NINETY_NINE_FOOD_ADAPTER_COPY_PT_BR } from "@12-apps/marketplace/99food/pt-BR";
|
|
27
|
+
*
|
|
28
|
+
* createMarketplaceEngine({
|
|
29
|
+
* …ports,
|
|
30
|
+
* adapters: [
|
|
31
|
+
* createIfoodAdapter({ copy: IFOOD_ADAPTER_COPY_PT_BR }),
|
|
32
|
+
* createNinetyNineFoodAdapter({ copy: NINETY_NINE_FOOD_ADAPTER_COPY_PT_BR, apiBaseUrl, portalUrl }),
|
|
33
|
+
* ],
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* Its webhook is the engine's one route, `POST
|
|
38
|
+
* /webhooks/marketplace/:tenantSlug/NINETY_NINE_FOOD`.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
export { NINETY_NINE_FOOD_PROVIDER } from "./normalize";
|
|
42
|
+
|
|
43
|
+
/** How long 99Food may take to answer a cancellation request. ESTIMATED: the spec names no deadline. */
|
|
44
|
+
export const NINETY_NINE_FOOD_CANCELLATION_ANSWER_WINDOW_MS = 5 * 60_000;
|
|
45
|
+
|
|
46
|
+
/** The one reason that means "an item is unavailable". */
|
|
47
|
+
const ITEM_UNAVAILABLE: NinetyNineFoodReasonCode = "UNAVAILABLE_ITEM";
|
|
48
|
+
|
|
49
|
+
export interface NinetyNineFoodAdapterConfig {
|
|
50
|
+
/** The words the adapter needs: reason labels and the missing-number text. Required. */
|
|
51
|
+
copy: NinetyNineFoodAdapterCopy;
|
|
52
|
+
/**
|
|
53
|
+
* Where 99Food serves Open Delivery, per environment: the base the spec's
|
|
54
|
+
* paths (`/oauth/token`, `/v1/orders/…`) hang from. Given to a partner at
|
|
55
|
+
* onboarding and not public, so required and defaultless. https only.
|
|
56
|
+
*/
|
|
57
|
+
apiBaseUrl: NinetyNineFoodApiBaseUrls;
|
|
58
|
+
/**
|
|
59
|
+
* Where "open it on 99Food" goes: the merchant portal. Open Delivery names no
|
|
60
|
+
* per-order deep link, so the link is the portal. Required; https only.
|
|
61
|
+
*/
|
|
62
|
+
portalUrl: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function assertHttps(name: string, url: string): void {
|
|
66
|
+
let parsed: URL;
|
|
67
|
+
try {
|
|
68
|
+
parsed = new URL(url);
|
|
69
|
+
} catch {
|
|
70
|
+
throw new Error(`@12-apps/marketplace/99food: ${name} is not a URL.`);
|
|
71
|
+
}
|
|
72
|
+
if (parsed.protocol !== "https:") throw new Error(`@12-apps/marketplace/99food: ${name} must be https.`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Build the 99Food adapter. Its reasons are static: a dialog never waits on 99Food. */
|
|
76
|
+
export function createNinetyNineFoodAdapter(config: NinetyNineFoodAdapterConfig): MarketplaceAdapter {
|
|
77
|
+
assertHttps("apiBaseUrl.SANDBOX", config.apiBaseUrl.SANDBOX);
|
|
78
|
+
assertHttps("apiBaseUrl.PRODUCTION", config.apiBaseUrl.PRODUCTION);
|
|
79
|
+
assertHttps("portalUrl", config.portalUrl);
|
|
80
|
+
const bases = { ...config.apiBaseUrl };
|
|
81
|
+
const reasons: readonly CancellationReason[] = NINETY_NINE_FOOD_REASON_CODES.map((code) => ({
|
|
82
|
+
code,
|
|
83
|
+
label: config.copy.reasonLabels[code],
|
|
84
|
+
itemUnavailable: code === ITEM_UNAVAILABLE,
|
|
85
|
+
// `outOfStockItems` is optional in the spec (see `./outbound.ts`).
|
|
86
|
+
needsItems: false,
|
|
87
|
+
}));
|
|
88
|
+
const normalizeOptions = { missingStreetNumber: config.copy.missingStreetNumber };
|
|
89
|
+
return {
|
|
90
|
+
provider: NINETY_NINE_FOOD_PROVIDER,
|
|
91
|
+
capabilities: {
|
|
92
|
+
apiConfirm: true,
|
|
93
|
+
apiCancel: true,
|
|
94
|
+
// The spec lets a merchant request a cancellation before or after the
|
|
95
|
+
// confirm ("rules may vary depending on the timing"); the answer says.
|
|
96
|
+
cancelAfterAccept: true,
|
|
97
|
+
// 202, then a CANCELLED or CANCELLATION_REQUEST_DENIED event.
|
|
98
|
+
asyncCancellationOutcome: true,
|
|
99
|
+
perOrderAppLink: false,
|
|
100
|
+
// `OrderConfirmed.preparationTime`, in minutes.
|
|
101
|
+
confirmTakesPreparationTime: true,
|
|
102
|
+
cancellationAnswerWindowMs: NINETY_NINE_FOOD_CANCELLATION_ANSWER_WINDOW_MS,
|
|
103
|
+
},
|
|
104
|
+
normalize: normalizeOpenDeliveryEvent,
|
|
105
|
+
readSignature: (header) => header("x-app-signature"),
|
|
106
|
+
verifySignature: verifyOpenDeliverySignature,
|
|
107
|
+
cancellationReasons: () => reasons,
|
|
108
|
+
fetchOrder: (ctx, order) => openDeliveryFetchOrder(ctx, bases, order, normalizeOptions),
|
|
109
|
+
confirm: (ctx, order, input) => openDeliveryConfirm(ctx, bases, order, input),
|
|
110
|
+
requestCancellation: (ctx, order, input) => openDeliveryRequestCancellation(ctx, bases, order, input),
|
|
111
|
+
appLink: () => config.portalUrl,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
NINETY_NINE_FOOD_REASON_CODES,
|
|
117
|
+
type NinetyNineFoodAdapterCopy,
|
|
118
|
+
type NinetyNineFoodReasonCode,
|
|
119
|
+
} from "./copy";
|
|
120
|
+
export { normalizeOpenDeliveryEvent, normalizeOpenDeliveryOrder, verifyOpenDeliverySignature } from "./normalize";
|
|
121
|
+
export type { NinetyNineFoodApiBaseUrls } from "./outbound";
|