@12-apps/marketplace 1.4.0 → 1.6.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 +1 -0
- package/README.md +52 -2
- package/dist/99food/index.d.ts +1 -1
- package/dist/99food/index.js +1 -1
- package/dist/{adapter-B8QtQ2RA.d.ts → adapter-CCWMqt2g.d.ts} +150 -1
- package/dist/{chunk-DPCZVN2C.js → chunk-4CJ7B5OR.js} +2 -2
- package/dist/{chunk-EBAIZQPB.js → chunk-NFZT5TWR.js} +19 -5
- package/dist/chunk-NFZT5TWR.js.map +1 -0
- package/dist/{chunk-SZRZTLVU.js → chunk-RGMSD7S7.js} +1 -1
- package/dist/chunk-RGMSD7S7.js.map +1 -0
- package/dist/chunk-WN2EK4KX.js +15 -0
- package/dist/chunk-WN2EK4KX.js.map +1 -0
- package/dist/{engine-o5cm54vC.d.ts → engine-w2TgRrlc.d.ts} +26 -2
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +2 -2
- package/dist/ifood/index.d.ts +32 -2
- package/dist/ifood/index.js +286 -9
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +44 -2
- package/dist/index.js.map +1 -1
- package/dist/manifest/server.d.ts +2 -2
- package/dist/manifest/server.js +2 -2
- package/dist/rappi/index.d.ts +1 -1
- package/dist/rappi/index.js +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +2 -2
- package/package.json +1 -1
- package/src/core/adapter.ts +7 -0
- package/src/core/catalogue-read-port.ts +151 -0
- package/src/core/catalogue-read.ts +51 -0
- package/src/core/engine.ts +9 -0
- package/src/core/ingest.ts +32 -4
- package/src/core/ports.ts +11 -0
- package/src/ifood/catalogue-read.ts +187 -0
- package/src/ifood/catalogue-snapshot.ts +246 -0
- package/src/ifood/index.ts +5 -0
- package/src/index.ts +15 -0
- package/dist/chunk-EBAIZQPB.js.map +0 -1
- package/dist/chunk-SZRZTLVU.js.map +0 -1
- /package/dist/{chunk-DPCZVN2C.js.map → chunk-4CJ7B5OR.js.map} +0 -0
package/ADOPTING.md
CHANGED
|
@@ -17,6 +17,7 @@ error at mount, never a default that quietly adopts another host's policy.
|
|
|
17
17
|
| `order.create` | `(clientId, order: NormalizedMarketplaceOrder, lines: readonly ResolvedOrderLine[], db: MarketplaceDb) => Promise<string>` | Create the host's own order from a normalized one; return its id. `lines[i].subjectRef` is the mapped catalog id or null (never refuse the order for a null). `db` is the ingest's transaction client: write the order through it, so the order and the acceptance row commit together (a lost race rolls the host's order back instead of leaving an orphan a redelivery would duplicate). |
|
|
18
18
|
| `order.catalogHas` | `(clientId, subjectRef) => Promise<boolean>` | Does this catalog id exist and belong to this tenant? Asked before a SKU is mapped. |
|
|
19
19
|
| `order.onAccepted` | `(clientId, orderId) => Promise<void>` | The store accepted, or the connection auto-accepts. Start whatever accepting means here (the ticket, the board). Runs after the commit and AFTER the confirm is queued; a throw is logged and cannot un-accept or lose the confirm. Atomic work (the stock draw) belongs in `admit`. |
|
|
20
|
+
| `order.mayAutoAccept` | OPTIONAL. `(clientId) => Promise<boolean>` | May a NEW order of this tenant be accepted automatically? Asked once per order, before the ingest's transaction, and only when the connection auto-accepts (never for a redelivery). `false` declines the automatic acceptance: the order lands exactly as with auto-accept off (AWAITING on the clock, no confirm queued, no `onAccepted`) and a person decides it; the order is never refused for it. A throw is logged and declines too. Not bound: every auto-accept proceeds, as before. It sits on every order's ingest, so answer it from something already in hand rather than a fresh query. |
|
|
20
21
|
| `order.onRefused` | `(clientId, orderId, reason: "REJECTED" \| "EXPIRED" \| "CANCELLED") => Promise<void>` | Refuse/cancel the host order: the store refused on the clock, the clock lapsed, or the marketplace cancelled. After the commit and after the cancellation request is queued; a throw on a decision is logged. NOT called for `recordStoreCancellation`. A host that binds `onCancellationConfirmed` (request first) does not get `"REJECTED"` from `decide` either, nor `"CANCELLED"` for a cancellation the store asked for: `onCancellationConfirmed` replaces both. |
|
|
21
22
|
| `order.onCancellationConfirmed` | OPTIONAL — binding it OPTS IN to request first. `(clientId, orderId) => Promise<void>` | The marketplace CONFIRMED the store's own cancellation request (its event, or the job's answer for a marketplace that answers in the response); the row is REJECTED/CONFIRMED by then. Run the host's cancel here. Bound: the store's refusals and cancels (`decide` REJECT, `recordStoreCancellation`) only REQUEST the cancellation and keep the order as it was until this is called, once (a redelivered confirmation calls nothing), INSTEAD of `onRefused`. Not bound (a 1.0.0 host): everything as 1.0.0 — REJECTED at request time, `onRefused(…, "REJECTED")` from `decide`, and `onRefused(…, "CANCELLED")` on the confirmation. A throw is logged. |
|
|
22
23
|
| `order.onCancellationFailed` | OPTIONAL. `(clientId, orderId, reason: "REFUSED" \| "TIMEOUT") => Promise<void>` | The store's request FAILED: REFUSED (the marketplace's refusal event, the job's 4xx, its last attempt dying, or — request first — a marketplace whose API cannot take it, at once) or TIMEOUT (the outbound sweep, past the marketplace's answer window, or the 24-hour give-up). Called once, by the path that moved the row. Request first: the order stays as it was (AWAITING or ACCEPTED) and may be accepted again; show the adapter's app link and tell the person. A throw is logged. |
|
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ engine code (`src/__tests__/second-adapter.test.ts`).
|
|
|
39
39
|
| **Canonical types** | `NormalizedEvent`, `NormalizedMarketplaceOrder`: what every adapter normalizes into. Poorer than any marketplace's payload on purpose; the raw payload stays in the inbox row. |
|
|
40
40
|
| **Inbox** | Every delivery recorded before it is processed, deduped on `(provider, eventId)`. A redelivery is a DB-level no-op; a crash mid-ingest leaves a PENDING row the sweep retries. |
|
|
41
41
|
| **Pipeline** | normalize → inbox → ingest / cancel / cancellation-refused / ignore. Never throws. |
|
|
42
|
-
| **Ingest** | Idempotent on `(provider, externalOrderId)`. Unmapped SKUs are rows on the attention list, never a rejection. The deadline is stamped at ingest; auto-accept is born accepted in one write and queues the confirm. |
|
|
42
|
+
| **Ingest** | Idempotent on `(provider, externalOrderId)`. Unmapped SKUs are rows on the attention list, never a rejection. The deadline is stamped at ingest; auto-accept is born accepted in one write and queues the confirm, unless the host's optional `order.mayAutoAccept` declines it, and then the order lands AWAITING as if auto-accept were off. |
|
|
43
43
|
| **Acceptance clock** | `AWAITING → ACCEPTED | REJECTED | EXPIRED`, every transition predicated on the current state. The sweep never touches an accepted order. |
|
|
44
44
|
| **Decisions** | Many at once, all-or-nothing: accept (with the person's admission and a preparation time), or refuse with a reason code validated against the adapter's own list and, for a reason that needs them, the order's offending SKUs. The host admits each decision inside the claim's transaction (`order.admit`: the stock ask, the draw). For a host that binds `onCancellationConfirmed`, the store's refusal or cancel is a REQUEST: only the request moves, the order stays as it was until the marketplace answers, and the host hears the answer through the optional `onCancellationConfirmed` / `onCancellationFailed` (REFUSED or TIMEOUT). `suggestReason` preselects the item-unavailable reason when the host says stock is short. |
|
|
45
45
|
| **SKU map** | External SKU → host catalog id, every SKU ever seen a row; mapping checks the id is the tenant's. |
|
|
@@ -48,7 +48,7 @@ engine code (`src/__tests__/second-adapter.test.ts`).
|
|
|
48
48
|
| **Order fetch** | For a marketplace whose events name an order without carrying it (Open Delivery's `CREATED`), the adapter marks the event `orderToFetch`: the webhook records it PENDING and queues `marketplace.fetch-order`, which calls the adapter's `fetchOrder` and ingests through the same ingest path. No request calls out; the reconciliation sweep re-queues a row still owed, and a host that holds the job holds every fetch. |
|
|
49
49
|
| **Inbound outcomes** | A marketplace CANCELLED confirms a pending request; CANCELLATION_REQUEST_FAILED marks it FAILED; CONFIRMED is terminal. |
|
|
50
50
|
| **Catalogue publishing** | A store turns a product ON or OFF per connected marketplace, with an optional price for that marketplace. One row per (store, marketplace, product): PUBLISHING → PUBLISHED, WITHDRAWING → WITHDRAWN, FAILED with a failure code (and the marketplace's own words for a refusal). The `marketplace.catalogue` job makes the call; the sweep re-queues what is owed. Push or pull is the adapter's. See [Catalogue publishing](#catalogue-publishing). |
|
|
51
|
-
| **Adapter port** | `MarketplaceAdapter`: `normalize`, `readSignature`, `verifySignature`, `cancellationReasons`, `confirm`, `requestCancellation`, `appLink`, `capabilities`, and the optional `fetchOrder` and `
|
|
51
|
+
| **Adapter port** | `MarketplaceAdapter`: `normalize`, `readSignature`, `verifySignature`, `cancellationReasons`, `confirm`, `requestCancellation`, `appLink`, `capabilities`, and the optional `fetchOrder`, `catalogue` and `catalogueReader`. |
|
|
52
52
|
|
|
53
53
|
## Subpaths
|
|
54
54
|
|
|
@@ -153,6 +153,56 @@ and the host shows Rappi as not publishable. Supporting it later is a pull-like
|
|
|
153
153
|
whole-menu mode over the same rows, once a store accepts that its Rappi menu
|
|
154
154
|
is exactly what it switches on here.
|
|
155
155
|
|
|
156
|
+
## Catalogue reading
|
|
157
|
+
|
|
158
|
+
FUT-951: during onboarding a store imports the menu it already keeps on a
|
|
159
|
+
marketplace. The engine reads it through the store's OWN connection (its
|
|
160
|
+
merchant id and sealed credentials, the same client-credentials grant the
|
|
161
|
+
orders use): no platform app, no homologation credentials. Nothing is stamped
|
|
162
|
+
or queued; the host asks while the store waits.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
const result = await engine.readCatalogue({ clientId, provider: "IFOOD" });
|
|
166
|
+
// { kind: "snapshot", snapshot: { categories, notices } }
|
|
167
|
+
// { kind: "refused", code: "UNSUPPORTED" | "NOT_CONNECTED" | "CREDENTIALS" | "NOT_AUTHORIZED" | "REFUSED", status, message }
|
|
168
|
+
// { kind: "retry", reason } // 429, 5xx, a timeout: ask again later
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
| part | what it is |
|
|
172
|
+
|---|---|
|
|
173
|
+
| **The port** | `adapter.catalogueReader.read(ctx)` (`CatalogueReader`), optional and independent of `catalogue`: a marketplace may be read without being published to. `ctx` is the outbound context plus `externalMerchantId`. |
|
|
174
|
+
| **The snapshot** | `categories[]` → `items[]`, each with `externalId`, `externalCode`, `name`, `description`, `priceCents` (null when none), `photoUrl` (absolute, or null), `available`, `optionGroups[]` (`name`, `min`, `max`, `options[]` with `name`, `priceDeltaCents`, `photoUrl`, `available`) and `warnings[]`. Sizes, flavours and add-ons are all option groups. |
|
|
175
|
+
| **Money** | Integer cents of the menu's currency, `centsFromMajor(value)`: cut to 12 significant digits (no float error), then rounded half up to the cent (`1.005` → 101). A negative or non-numeric price is no price. |
|
|
176
|
+
| **Nothing dropped silently** | A field that cannot be mapped is a warning on its item (`PRICE_MISSING`, `OPTION_PRICE_MISSING`, `OPTION_GROUP_UNREADABLE`, `OPTION_UNREADABLE`, `PHOTO_UNREADABLE`, `ITEM_TYPE_UNSUPPORTED`), naming the group or option; an item or category that cannot be read at all is a notice on the snapshot (`ITEM_UNREADABLE`, `CATEGORY_UNREADABLE`). Codes are vocabulary: the host words them. |
|
|
177
|
+
| **Failures** | Before any call the engine refuses `UNSUPPORTED` (no reader), `NOT_CONNECTED` (no live connection with a merchant id), `CREDENTIALS` (none on file, or they do not open), with `status`/`message` null. From the marketplace: `CREDENTIALS` (the token grant refused), `NOT_AUTHORIZED` (this app may not read this merchant), `REFUSED` (another final 4xx, or a category list that is not a list), or `retry`. One category answered in an unexpected shape is a `CATEGORY_UNREADABLE` notice, and the rest of the menu is still read. |
|
|
178
|
+
|
|
179
|
+
**iFood** (`src/ifood/catalogue-read.ts`, `src/ifood/catalogue-snapshot.ts`).
|
|
180
|
+
Read 2026-11-16: the Catalog module's Introduction was read whole; its
|
|
181
|
+
Endpoints, Fundamentals, How it works and Errors pages answered 403 to our
|
|
182
|
+
reader that day, so what they would settle is ESTIMATED below (the push's
|
|
183
|
+
2026-11-13 reading of them is cited where it applies).
|
|
184
|
+
|
|
185
|
+
| fact | status |
|
|
186
|
+
|---|---|
|
|
187
|
+
| Same base and bearer token as the push: `https://merchant-api.ifood.com.br/catalog/v2.0/merchants/{merchantId}/…`, client-credentials grant of the store's own app | CONFIRMED — [Introduction](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/introduction) |
|
|
188
|
+
| `GET /categories` lists the merchant's categories | CONFIRMED — [Endpoints](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/endpoints), as read 2026-11-13 for the push |
|
|
189
|
+
| `GET /categories/{categoryId}/items` lists a category's items "with their associated complements" | CONFIRMED — Introduction, step 5 |
|
|
190
|
+
| An item is `item` (id, type, categoryId, status, `price { value }` in the major unit, externalCode), `products` (id, name, description, externalCode, and `optionGroups: [{ id, min, max }]` linking a product to its groups), `optionGroups` (id, name, status, `optionIds`), `options` (id, `productId` naming the product with its name, status, `price { value }`) | CONFIRMED as the `PUT /items` payload — Introduction, steps 3 and 4 |
|
|
191
|
+
| The category list answers an array of `{ id, name, status, externalCode }` | ESTIMATED (the push makes the same estimate) |
|
|
192
|
+
| `GET /categories/{categoryId}/items` answers the PUT's four lists as `{ items, products, optionGroups, options }` | ESTIMATED |
|
|
193
|
+
| `item.productId` names the item's product (its name, description, photo); without it the item's own `name` is used | ESTIMATED (the push sends the same field) |
|
|
194
|
+
| `products[].imagePath` is the photo, served under `https://static-images.ifood.com.br/image/upload/t_high/pratos/` (`IFOOD_IMAGE_BASE_URL`); an absolute https path is used as it is | ESTIMATED (the pages read name `imagePath` but not its host; the host is the one iFood's own app loads dish photos from) |
|
|
195
|
+
| No pagination: neither call shows a page, size or cursor parameter, so the menu is read one category per call | ESTIMATED |
|
|
196
|
+
| 401: the token is dropped and the call asked once more with a fresh one; a second 401 is a `retry` | choice (as the push's `call`) |
|
|
197
|
+
| The token grant refused (400/401/403) is `CREDENTIALS`; 403 on a catalogue call (the Errors page: the module is not enabled for the app) is `NOT_AUTHORIZED`; 429, 408, 425 and 5xx are a `retry`; another 4xx is `REFUSED` | CONFIRMED for the statuses — [Errors](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/errors-and-troubleshooting), as read 2026-11-13; the mapping is a choice |
|
|
198
|
+
| A 404 on the category list means this app has no such merchant: `NOT_AUTHORIZED`; a 404 on one category's items (deleted between the calls) leaves that category out with a `CATEGORY_UNREADABLE` notice | ESTIMATED |
|
|
199
|
+
| A photo path is used as a URL path as it is (an encoded `%20` stays); only characters a URL may not carry are encoded | choice |
|
|
200
|
+
| An item `type` other than `DEFAULT` (a pizza, a combo) is read as a plain item with `ITEM_TYPE_UNSUPPORTED` | choice |
|
|
201
|
+
| The read covers the merchant-level categories (the DEFAULT, delivery, context); other catalogs and `contextModifiers` prices are not read | ESTIMATED |
|
|
202
|
+
|
|
203
|
+
99Food and Rappi state no `catalogueReader`: `engine.readCatalogue` answers
|
|
204
|
+
`UNSUPPORTED` for them.
|
|
205
|
+
|
|
156
206
|
## iFood is unverified
|
|
157
207
|
|
|
158
208
|
iFood's developer portal refused our reader, so the iFood adapter's ORDER URLs,
|
package/dist/99food/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, P as PullCatalogue, C as CatalogueMenuEntry, b as CatalogueMenuOptions, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-
|
|
1
|
+
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, P as PullCatalogue, C as CatalogueMenuEntry, b as CatalogueMenuOptions, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-CCWMqt2g.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The words the 99Food adapter needs from its host, and nothing else.
|
package/dist/99food/index.js
CHANGED
|
@@ -160,6 +160,149 @@ interface PullCatalogue {
|
|
|
160
160
|
/** The catalogue capability an adapter states, or leaves out. */
|
|
161
161
|
type MarketplaceCatalogue = PushCatalogue | PullCatalogue;
|
|
162
162
|
|
|
163
|
+
/**
|
|
164
|
+
* The catalogue READ half of the adapter port (FUT-951): the menu a store
|
|
165
|
+
* already keeps on a marketplace, read through the store's own connection, so
|
|
166
|
+
* the host can import it (onboarding: "bring my menu over").
|
|
167
|
+
*
|
|
168
|
+
* The opposite direction of `catalogue-port.ts` and independent of it: an
|
|
169
|
+
* adapter may read a menu it cannot publish to, or publish to one it cannot
|
|
170
|
+
* read. Nothing here names a marketplace; each adapter maps its own catalogue
|
|
171
|
+
* into the {@link CatalogueSnapshot} below.
|
|
172
|
+
*
|
|
173
|
+
* Money is integer cents of the menu's currency ({@link centsFromMajor}).
|
|
174
|
+
* Nothing the adapter cannot map is dropped silently: a field it could not read
|
|
175
|
+
* is a {@link CatalogueReadWarning} on the item, and an item or category it
|
|
176
|
+
* could not read at all is a {@link CatalogueReadNotice} on the snapshot.
|
|
177
|
+
*/
|
|
178
|
+
/** Why part of an item could not be mapped. Vocabulary, not copy: the host words it. */
|
|
179
|
+
type CatalogueReadWarningCode =
|
|
180
|
+
/** The item carries no readable price: `priceCents` is null. */
|
|
181
|
+
"PRICE_MISSING"
|
|
182
|
+
/** An option carries no readable price: its `priceDeltaCents` is null. */
|
|
183
|
+
| "OPTION_PRICE_MISSING"
|
|
184
|
+
/** A group of choices could not be read (no name, no options, bounds that make no sense): left out. */
|
|
185
|
+
| "OPTION_GROUP_UNREADABLE"
|
|
186
|
+
/** One choice of a group could not be read (no name): left out of its group. */
|
|
187
|
+
| "OPTION_UNREADABLE"
|
|
188
|
+
/** The photo reference is there but is not a path or URL the adapter can resolve: `photoUrl` is null. */
|
|
189
|
+
| "PHOTO_UNREADABLE"
|
|
190
|
+
/** The item is of a kind this reader maps only partly (a combo, a pizza by halves): read as a plain item. */
|
|
191
|
+
| "ITEM_TYPE_UNSUPPORTED";
|
|
192
|
+
/** One thing about an item the read could not map. */
|
|
193
|
+
interface CatalogueReadWarning {
|
|
194
|
+
code: CatalogueReadWarningCode;
|
|
195
|
+
/** The marketplace's id of the group or option concerned, or null when it is the item itself. */
|
|
196
|
+
subject: string | null;
|
|
197
|
+
/** What the marketplace sent, for a developer (never shown as copy). */
|
|
198
|
+
detail: string | null;
|
|
199
|
+
}
|
|
200
|
+
/** One choice of a group: a size, a flavour, an add-on. */
|
|
201
|
+
interface CatalogueSnapshotOption {
|
|
202
|
+
externalId: string;
|
|
203
|
+
/** The store's own code for it on the marketplace, when it set one. */
|
|
204
|
+
externalCode: string | null;
|
|
205
|
+
name: string;
|
|
206
|
+
description: string | null;
|
|
207
|
+
/** What choosing it adds to the item's price, in cents (0 = free); null when the marketplace sent none. */
|
|
208
|
+
priceDeltaCents: number | null;
|
|
209
|
+
photoUrl: string | null;
|
|
210
|
+
available: boolean;
|
|
211
|
+
}
|
|
212
|
+
/** A group of choices on an item: "Size" (min 1, max 1), "Extras" (min 0, max 3). */
|
|
213
|
+
interface CatalogueSnapshotOptionGroup {
|
|
214
|
+
externalId: string;
|
|
215
|
+
externalCode: string | null;
|
|
216
|
+
name: string;
|
|
217
|
+
/** At least this many choices (0 = optional). */
|
|
218
|
+
min: number;
|
|
219
|
+
/** At most this many choices (always >= `min` and >= 1). */
|
|
220
|
+
max: number;
|
|
221
|
+
available: boolean;
|
|
222
|
+
options: CatalogueSnapshotOption[];
|
|
223
|
+
}
|
|
224
|
+
/** One item as the marketplace sells it. */
|
|
225
|
+
interface CatalogueSnapshotItem {
|
|
226
|
+
externalId: string;
|
|
227
|
+
externalCode: string | null;
|
|
228
|
+
name: string;
|
|
229
|
+
description: string | null;
|
|
230
|
+
/** The item's own price in cents; null when the marketplace sent none (with a PRICE_MISSING warning). */
|
|
231
|
+
priceCents: number | null;
|
|
232
|
+
/** An absolute https URL of the photo, or null when the item has none. */
|
|
233
|
+
photoUrl: string | null;
|
|
234
|
+
/** Whether the marketplace sells it now (a paused item is still read). */
|
|
235
|
+
available: boolean;
|
|
236
|
+
optionGroups: CatalogueSnapshotOptionGroup[];
|
|
237
|
+
warnings: CatalogueReadWarning[];
|
|
238
|
+
}
|
|
239
|
+
/** One category, its items in the marketplace's order. */
|
|
240
|
+
interface CatalogueSnapshotCategory {
|
|
241
|
+
externalId: string;
|
|
242
|
+
externalCode: string | null;
|
|
243
|
+
name: string;
|
|
244
|
+
available: boolean;
|
|
245
|
+
items: CatalogueSnapshotItem[];
|
|
246
|
+
}
|
|
247
|
+
/** An item or a category the read could not map at all, said rather than dropped. */
|
|
248
|
+
interface CatalogueReadNotice {
|
|
249
|
+
code: "ITEM_UNREADABLE" | "CATEGORY_UNREADABLE";
|
|
250
|
+
/** The category it was found in (the category itself for CATEGORY_UNREADABLE), or null when it had no id. */
|
|
251
|
+
categoryExternalId: string | null;
|
|
252
|
+
/** The item's id, when it had one; null for a category. */
|
|
253
|
+
externalId: string | null;
|
|
254
|
+
detail: string;
|
|
255
|
+
}
|
|
256
|
+
/** The store's menu on a marketplace, as read. */
|
|
257
|
+
interface CatalogueSnapshot {
|
|
258
|
+
categories: CatalogueSnapshotCategory[];
|
|
259
|
+
notices: CatalogueReadNotice[];
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Why a read failed for good. Vocabulary, not copy.
|
|
263
|
+
* - `UNSUPPORTED`: the marketplace's adapter states no catalogue read.
|
|
264
|
+
* - `NOT_CONNECTED`: no live connection with a merchant id for that marketplace.
|
|
265
|
+
* - `CREDENTIALS`: no credentials on file, they do not open, or the marketplace refused them.
|
|
266
|
+
* - `NOT_AUTHORIZED`: the marketplace refused this merchant to this app (not
|
|
267
|
+
* authorized, the catalogue module not enabled, an unknown merchant id).
|
|
268
|
+
* - `REFUSED`: any other final refusal.
|
|
269
|
+
*/
|
|
270
|
+
type CatalogueReadRefusalCode = "UNSUPPORTED" | "NOT_CONNECTED" | "CREDENTIALS" | "NOT_AUTHORIZED" | "REFUSED";
|
|
271
|
+
/** What a read answers: the snapshot, a final refusal, or a failure worth asking again later (429, 5xx, a timeout). */
|
|
272
|
+
type CatalogueReadResult = {
|
|
273
|
+
kind: "snapshot";
|
|
274
|
+
snapshot: CatalogueSnapshot;
|
|
275
|
+
}
|
|
276
|
+
/** `status` and `message` are the marketplace's answer; null when the engine refused before calling. */
|
|
277
|
+
| {
|
|
278
|
+
kind: "refused";
|
|
279
|
+
code: CatalogueReadRefusalCode;
|
|
280
|
+
status: number | null;
|
|
281
|
+
message: string | null;
|
|
282
|
+
} | {
|
|
283
|
+
kind: "retry";
|
|
284
|
+
reason: string;
|
|
285
|
+
};
|
|
286
|
+
/** What one catalogue read is handed: the outbound context plus the connection's merchant id. */
|
|
287
|
+
interface CatalogueReadContext extends AdapterCallContext {
|
|
288
|
+
externalMerchantId: string;
|
|
289
|
+
}
|
|
290
|
+
/** A marketplace whose menu can be read. */
|
|
291
|
+
interface CatalogueReader {
|
|
292
|
+
/** Read the whole menu. Never throws: a call with no answer is a `retry`. */
|
|
293
|
+
read(ctx: CatalogueReadContext): Promise<CatalogueReadResult>;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* A price in the currency's MAJOR unit (`25.9`) as integer cents (`2590`), or
|
|
297
|
+
* null when it is not a finite, non-negative number.
|
|
298
|
+
*
|
|
299
|
+
* Rounding is explicit: the product is first cut to 12 significant digits,
|
|
300
|
+
* which removes binary floating-point error (`1.005 * 100` is
|
|
301
|
+
* `100.49999999999999`), and then rounded half up to the cent (`1.005` →
|
|
302
|
+
* `101`, `0.125` → `13`).
|
|
303
|
+
*/
|
|
304
|
+
declare function centsFromMajor(value: unknown): number | null;
|
|
305
|
+
|
|
163
306
|
/**
|
|
164
307
|
* The adapter port's OPTIONAL availability capability: closing a store on a
|
|
165
308
|
* marketplace for a while, and opening it again (FUT-4851).
|
|
@@ -590,6 +733,12 @@ interface MarketplaceAdapter {
|
|
|
590
733
|
* marketplace cannot be published to, and the host says so.
|
|
591
734
|
*/
|
|
592
735
|
readonly catalogue?: MarketplaceCatalogue;
|
|
736
|
+
/**
|
|
737
|
+
* OPTIONAL. Reading the menu the store already keeps on this marketplace,
|
|
738
|
+
* through its own connection, for the host to import (FUT-951). Absent: the
|
|
739
|
+
* menu cannot be read through an API, and the host says so.
|
|
740
|
+
*/
|
|
741
|
+
readonly catalogueReader?: CatalogueReader;
|
|
593
742
|
/**
|
|
594
743
|
* OPTIONAL. Closing the store on this marketplace for a while, and opening
|
|
595
744
|
* it again (FUT-4851). Absent: the marketplace cannot be paused through an
|
|
@@ -609,4 +758,4 @@ declare function outboundResultOf(response: MarketplaceHttpResponse): OutboundRe
|
|
|
609
758
|
/** A call that never got an answer is a retry, with the reason a log can read. */
|
|
610
759
|
declare function answered(call: () => Promise<OutboundResult>): Promise<OutboundResult>;
|
|
611
760
|
|
|
612
|
-
export { type AdapterCallContext as A, type
|
|
761
|
+
export { answered as $, type AdapterCallContext as A, type CatalogueSnapshotCategory as B, type CatalogueMenuEntry as C, type CatalogueSnapshotItem as D, type CatalogueSnapshotOption as E, type CatalogueSnapshotOptionGroup as F, type CatalogueStoredImage as G, type CatalogueWarningCode as H, type FetchOrderResult as I, type MarketplaceCapabilities as J, type MarketplaceCatalogue as K, type MarketplaceCredentials as L, type MarketplaceAvailability as M, type NormalizedEvent as N, type OutboundResult as O, type PullCatalogue as P, type MarketplaceDeliveredBy as Q, type MarketplaceHttp as R, type StorePauseRequest as S, type MarketplaceHttpRequest as T, type MarketplaceHttpResponse as U, type MarketplaceOrderType as V, type NormalizedAddress as W, type NormalizedBuyer as X, type NormalizedOrderLine as Y, type OutboundOrderRef as Z, PROVIDER_ID_PATTERN as _, type NormalizedMarketplaceOrder as a, centsFromMajor as a0, outboundResultOf as a1, type CatalogueMenuOptions as b, type MarketplaceAdapter as c, type PushCatalogue as d, type CatalogueItemOut as e, type CatalogueReader as f, type StorePauseResult as g, type StorePauseRef as h, type MarketplaceProvider as i, type CancellationReason as j, type AdapterTokenCache as k, type CancellationOutcome as l, type CancellationRequestInput as m, type CatalogueCallContext as n, type CatalogueFailure as o, type CatalogueImage as p, type CatalogueItem as q, type CatalogueItemRef as r, type CataloguePublishResult as s, type CatalogueReadContext as t, type CatalogueReadNotice as u, type CatalogueReadRefusalCode as v, type CatalogueReadResult as w, type CatalogueReadWarning as x, type CatalogueReadWarningCode as y, type CatalogueSnapshot as z };
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
CatalogueRetryError,
|
|
14
14
|
FetchOrderRetryError,
|
|
15
15
|
OutboundRetryError
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-NFZT5TWR.js";
|
|
17
17
|
import {
|
|
18
18
|
__name
|
|
19
19
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -473,4 +473,4 @@ export {
|
|
|
473
473
|
MARKETPLACE_JOBS,
|
|
474
474
|
createApiMarketplace
|
|
475
475
|
};
|
|
476
|
-
//# sourceMappingURL=chunk-
|
|
476
|
+
//# sourceMappingURL=chunk-4CJ7B5OR.js.map
|
|
@@ -760,8 +760,7 @@ async function composeLines(db, clientId, order, seenAt) {
|
|
|
760
760
|
}));
|
|
761
761
|
}
|
|
762
762
|
__name(composeLines, "composeLines");
|
|
763
|
-
function acceptanceData(clientId, orderId, order, settings, now, clockStartsAt) {
|
|
764
|
-
const accepted = settings.autoAccept;
|
|
763
|
+
function acceptanceData(clientId, orderId, order, settings, accepted, now, clockStartsAt) {
|
|
765
764
|
return {
|
|
766
765
|
clientId,
|
|
767
766
|
orderId,
|
|
@@ -780,6 +779,20 @@ function acceptanceData(clientId, orderId, order, settings, now, clockStartsAt)
|
|
|
780
779
|
};
|
|
781
780
|
}
|
|
782
781
|
__name(acceptanceData, "acceptanceData");
|
|
782
|
+
async function hostAllowsAutoAccept(ctx, clientId, order) {
|
|
783
|
+
const ask = ctx.ports.order.mayAutoAccept;
|
|
784
|
+
if (!ask) return true;
|
|
785
|
+
try {
|
|
786
|
+
return await ask.call(ctx.ports.order, clientId);
|
|
787
|
+
} catch (error) {
|
|
788
|
+
ctx.ports.logger.warn(
|
|
789
|
+
`marketplace: mayAutoAccept threw for ${order.provider} order ${order.externalOrderId}; it lands awaiting a decision`,
|
|
790
|
+
error
|
|
791
|
+
);
|
|
792
|
+
return false;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
__name(hostAllowsAutoAccept, "hostAllowsAutoAccept");
|
|
783
796
|
async function ingestMarketplaceOrder(ctx, input) {
|
|
784
797
|
const { clientId, order, settings } = input;
|
|
785
798
|
const now = input.now ?? ctx.ports.clock.now();
|
|
@@ -792,11 +805,11 @@ async function ingestMarketplaceOrder(ctx, input) {
|
|
|
792
805
|
if (existing) {
|
|
793
806
|
return { orderId: existing.orderId, created: false, unmappedSkus: [], autoAccepted: false };
|
|
794
807
|
}
|
|
795
|
-
const accepted = settings.autoAccept;
|
|
808
|
+
const accepted = settings.autoAccept && await hostAllowsAutoAccept(ctx, clientId, order);
|
|
796
809
|
const { orderId, unmappedSkus } = await ctx.ports.transaction(async (tx) => {
|
|
797
810
|
const lines = await composeLines(tx, clientId, order, now);
|
|
798
811
|
const created = await ctx.ports.order.create(clientId, order, lines, tx);
|
|
799
|
-
await tx.marketplaceAcceptance.create({ data: acceptanceData(clientId, created, order, settings, now, clockStartsAt) });
|
|
812
|
+
await tx.marketplaceAcceptance.create({ data: acceptanceData(clientId, created, order, settings, accepted, now, clockStartsAt) });
|
|
800
813
|
await markMarketplaceEventSeen(tx, clientId, order.provider, now);
|
|
801
814
|
return { orderId: created, unmappedSkus: lines.filter((l) => l.subjectRef === null).map((l) => l.externalSku) };
|
|
802
815
|
});
|
|
@@ -1947,6 +1960,7 @@ export {
|
|
|
1947
1960
|
connectionMerchantId,
|
|
1948
1961
|
resolveIngestionTarget,
|
|
1949
1962
|
resolveTenantByMerchant,
|
|
1963
|
+
readOutboundConnection,
|
|
1950
1964
|
listMarketplaceMenuLinks,
|
|
1951
1965
|
upsertLink,
|
|
1952
1966
|
MARKETPLACE_OUTBOUND_JOB,
|
|
@@ -1992,4 +2006,4 @@ export {
|
|
|
1992
2006
|
AvailabilityRetryError,
|
|
1993
2007
|
runAvailability
|
|
1994
2008
|
};
|
|
1995
|
-
//# sourceMappingURL=chunk-
|
|
2009
|
+
//# sourceMappingURL=chunk-NFZT5TWR.js.map
|