@12-apps/marketplace 1.3.0 → 1.5.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 +47 -0
- package/README.md +122 -1
- package/dist/99food/index.d.ts +33 -2
- package/dist/99food/index.js +34 -2
- package/dist/99food/index.js.map +1 -1
- package/dist/{adapter-0l_EmuJA.d.ts → adapter-CCWMqt2g.d.ts} +275 -3
- package/dist/{chunk-XUAFXNOH.js → chunk-FKUEFVVA.js} +396 -4
- package/dist/chunk-FKUEFVVA.js.map +1 -0
- package/dist/{chunk-RVBTARIY.js → chunk-RGMSD7S7.js} +1 -1
- package/dist/chunk-RGMSD7S7.js.map +1 -0
- package/dist/{chunk-AYYBRQJV.js → chunk-UONWZIBO.js} +43 -3
- package/dist/chunk-UONWZIBO.js.map +1 -0
- package/dist/chunk-WN2EK4KX.js +15 -0
- package/dist/chunk-WN2EK4KX.js.map +1 -0
- package/dist/{engine-CZsP8KWd.d.ts → engine-C3uq_BJd.d.ts} +252 -2
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +2 -2
- package/dist/ifood/index.d.ts +44 -2
- package/dist/ifood/index.js +441 -1
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +342 -3
- package/dist/index.js.map +1 -1
- package/dist/manifest/server.d.ts +4 -2
- package/dist/manifest/server.js +2 -2
- package/dist/rappi/index.d.ts +15 -2
- package/dist/rappi/index.js +56 -2
- package/dist/rappi/index.js.map +1 -1
- package/dist/server/index.d.ts +18 -7
- package/dist/server/index.js +4 -2
- package/package.json +1 -1
- package/prisma/marketplace.prisma +67 -1
- package/prisma/migrations/20261113230000_marketplace_store_pause/migration.sql +70 -0
- package/src/99food/index.ts +10 -0
- package/src/99food/pause.ts +56 -0
- package/src/core/adapter.ts +19 -2
- package/src/core/catalogue-read-port.ts +151 -0
- package/src/core/catalogue-read.ts +51 -0
- package/src/core/engine.ts +46 -0
- package/src/core/pause-job.ts +381 -0
- package/src/core/pause-port.ts +110 -0
- package/src/core/pause-retired.ts +139 -0
- package/src/core/pause-store.ts +151 -0
- package/src/core/pause-sweep.ts +148 -0
- package/src/core/pause.ts +316 -0
- 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 +9 -0
- package/src/ifood/pause.ts +257 -0
- package/src/index.ts +39 -0
- package/src/rappi/index.ts +11 -0
- package/src/rappi/outbound.ts +2 -2
- package/src/rappi/pause.ts +98 -0
- package/src/server/index.ts +1 -0
- package/src/server/jobs.ts +64 -4
- package/dist/chunk-AYYBRQJV.js.map +0 -1
- package/dist/chunk-RVBTARIY.js.map +0 -1
- package/dist/chunk-XUAFXNOH.js.map +0 -1
|
@@ -160,6 +160,263 @@ 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
|
+
|
|
306
|
+
/**
|
|
307
|
+
* The adapter port's OPTIONAL availability capability: closing a store on a
|
|
308
|
+
* marketplace for a while, and opening it again (FUT-4851).
|
|
309
|
+
*
|
|
310
|
+
* The owner's rules (2026-11-12), translated:
|
|
311
|
+
*
|
|
312
|
+
* 1. "When the kitchen is paused, the store is paused on every connected
|
|
313
|
+
* marketplace. The interruption carries the kitchen's estimated reopening
|
|
314
|
+
* time as its end, is renewed while the kitchen stays paused, and is
|
|
315
|
+
* deleted the moment the pause is over. The store is never closed on a
|
|
316
|
+
* marketplace longer than the kitchen's own pause."
|
|
317
|
+
* 2. The debounce is the host's; the engine receives pause(until) and resume.
|
|
318
|
+
* 3. "Never reopen a store the owner closed by hand on the marketplace, and
|
|
319
|
+
* never close one beyond what the kitchen's pause asked": the engine only
|
|
320
|
+
* deletes what IT created.
|
|
321
|
+
*
|
|
322
|
+
* Marketplaces close a store in one of two shapes, stated by the adapter as
|
|
323
|
+
* {@link MarketplaceAvailability.kind}:
|
|
324
|
+
*
|
|
325
|
+
* - `interruption`: the marketplace keeps a closure with its OWN id and an
|
|
326
|
+
* END (iFood's interruptions). The engine stores the id and deletes only
|
|
327
|
+
* that id; a closure the owner made by hand is another id and is never
|
|
328
|
+
* touched. If every call after the pause is lost, the marketplace still
|
|
329
|
+
* opens the store at the end it was given.
|
|
330
|
+
* - `switch`: a store-wide on/off with no id and no end (Rappi's store
|
|
331
|
+
* availability, Open Delivery's `merchantStatus`). The engine turns a store
|
|
332
|
+
* on only if its own record says it turned it off, and turns it on again by
|
|
333
|
+
* itself once the `until` it was given has passed without a renewal. What a
|
|
334
|
+
* switch cannot tell apart: an owner who ALSO closed the store by hand while
|
|
335
|
+
* the kitchen's pause stood is reopened with it. That is why a switch
|
|
336
|
+
* adapter offers the capability only when its host opts in.
|
|
337
|
+
*/
|
|
338
|
+
/** What a pause asks of one marketplace. */
|
|
339
|
+
interface StorePauseRequest {
|
|
340
|
+
/** The store on the marketplace: the connection's `externalMerchantId`. */
|
|
341
|
+
merchantId: string;
|
|
342
|
+
/** When the store should open again on its own: the kitchen's estimated reopening time. */
|
|
343
|
+
until: Date;
|
|
344
|
+
/** The host's words for the closure, shown to the merchant where the marketplace shows one. */
|
|
345
|
+
reason: string;
|
|
346
|
+
/**
|
|
347
|
+
* A stable key for THIS closure, the same on every retry of it. An adapter
|
|
348
|
+
* that can name its own closure sends it; one that can list closures finds
|
|
349
|
+
* the closure a lost answer already created, by the key or, where the
|
|
350
|
+
* marketplace assigns its own id, by the end and the reason it carries, so
|
|
351
|
+
* a retry never creates a second one.
|
|
352
|
+
*/
|
|
353
|
+
key: string;
|
|
354
|
+
/** The store's IANA time zone, for a marketplace that reads times as the store's wall clock. */
|
|
355
|
+
timeZone: string;
|
|
356
|
+
/**
|
|
357
|
+
* OPTIONAL. The marketplace ids the engine already holds (the current
|
|
358
|
+
* closure, the replaced ones it is about to delete): a closure found again
|
|
359
|
+
* for this create is never one of them.
|
|
360
|
+
*/
|
|
361
|
+
keep?: readonly string[];
|
|
362
|
+
}
|
|
363
|
+
/** The closure the engine holds on one marketplace, as a resume or an extend names it. */
|
|
364
|
+
interface StorePauseRef {
|
|
365
|
+
merchantId: string;
|
|
366
|
+
/** The marketplace's own id for the closure; null for a switch, or when the create's answer was lost. */
|
|
367
|
+
externalId: string | null;
|
|
368
|
+
/** The key the closure was created under; null once nothing of ours is in doubt. */
|
|
369
|
+
key: string | null;
|
|
370
|
+
/**
|
|
371
|
+
* What the create under `key` carried, for a marketplace that names a
|
|
372
|
+
* closure with its own id: the closure whose end and description are these
|
|
373
|
+
* is the one a lost answer created. Null with no key in doubt.
|
|
374
|
+
*/
|
|
375
|
+
sent: {
|
|
376
|
+
until: Date;
|
|
377
|
+
reason: string;
|
|
378
|
+
timeZone: string;
|
|
379
|
+
} | null;
|
|
380
|
+
/**
|
|
381
|
+
* OPTIONAL. The marketplace ids the engine already holds (the current
|
|
382
|
+
* closure, the replaced ones): a closure found under `key` is never one of
|
|
383
|
+
* them, so deleting a lost create can never delete the closure that stands.
|
|
384
|
+
*/
|
|
385
|
+
keep?: readonly string[];
|
|
386
|
+
}
|
|
387
|
+
/** One pause or extend's answer. */
|
|
388
|
+
type StorePauseResult =
|
|
389
|
+
/** The store is closed on the marketplace until `until`. `externalId` is null for a switch. */
|
|
390
|
+
{
|
|
391
|
+
kind: "paused";
|
|
392
|
+
externalId: string | null;
|
|
393
|
+
until: Date;
|
|
394
|
+
} | Exclude<OutboundResult, {
|
|
395
|
+
kind: "accepted";
|
|
396
|
+
}>;
|
|
397
|
+
/** A marketplace's way of closing a store for a while. */
|
|
398
|
+
interface MarketplaceAvailability {
|
|
399
|
+
/** How the marketplace holds a closure: an `interruption` with its own id and end, or a store-wide `switch`. */
|
|
400
|
+
readonly kind: "interruption" | "switch";
|
|
401
|
+
/**
|
|
402
|
+
* Close the store until `request.until`. Idempotent under `request.key`
|
|
403
|
+
* where the marketplace allows it (a stable id, or a list before the create).
|
|
404
|
+
*/
|
|
405
|
+
pause(ctx: AdapterCallContext, request: StorePauseRequest): Promise<StorePauseResult>;
|
|
406
|
+
/**
|
|
407
|
+
* OPTIONAL. Move the end of the closure the engine holds. Absent: the engine
|
|
408
|
+
* creates a new closure with the later end and then deletes the old one, so
|
|
409
|
+
* the store is never open in between.
|
|
410
|
+
*/
|
|
411
|
+
extend?(ctx: AdapterCallContext, ref: StorePauseRef, request: StorePauseRequest): Promise<StorePauseResult>;
|
|
412
|
+
/**
|
|
413
|
+
* Open the store: delete THIS closure, and nothing else. A closure already
|
|
414
|
+
* gone (it ended, or a person removed it) is `accepted`: there is nothing of
|
|
415
|
+
* ours left to delete.
|
|
416
|
+
*/
|
|
417
|
+
resume(ctx: AdapterCallContext, ref: StorePauseRef): Promise<OutboundResult>;
|
|
418
|
+
}
|
|
419
|
+
|
|
163
420
|
/**
|
|
164
421
|
* The canonical shape every marketplace adapter normalizes INTO.
|
|
165
422
|
*
|
|
@@ -335,8 +592,11 @@ interface MarketplaceCredentials {
|
|
|
335
592
|
}
|
|
336
593
|
/** What the host's HTTP client takes. */
|
|
337
594
|
interface MarketplaceHttpRequest {
|
|
338
|
-
/**
|
|
339
|
-
|
|
595
|
+
/**
|
|
596
|
+
* `PATCH` since FUT-4768: iFood's catalogue sets an item's status with it.
|
|
597
|
+
* `DELETE` since FUT-4851: iFood removes an interruption with it.
|
|
598
|
+
*/
|
|
599
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
340
600
|
url: string;
|
|
341
601
|
headers: Record<string, string>;
|
|
342
602
|
body?: string;
|
|
@@ -473,6 +733,18 @@ interface MarketplaceAdapter {
|
|
|
473
733
|
* marketplace cannot be published to, and the host says so.
|
|
474
734
|
*/
|
|
475
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;
|
|
742
|
+
/**
|
|
743
|
+
* OPTIONAL. Closing the store on this marketplace for a while, and opening
|
|
744
|
+
* it again (FUT-4851). Absent: the marketplace cannot be paused through an
|
|
745
|
+
* API, and the host says so.
|
|
746
|
+
*/
|
|
747
|
+
readonly availability?: MarketplaceAvailability;
|
|
476
748
|
/** Where "open it on the marketplace" goes: the order when `perOrderAppLink`, else the portal. Always https. */
|
|
477
749
|
appLink(order: Pick<OutboundOrderRef, "externalOrderId" | "externalDisplayId">): string;
|
|
478
750
|
}
|
|
@@ -486,4 +758,4 @@ declare function outboundResultOf(response: MarketplaceHttpResponse): OutboundRe
|
|
|
486
758
|
/** A call that never got an answer is a retry, with the reason a log can read. */
|
|
487
759
|
declare function answered(call: () => Promise<OutboundResult>): Promise<OutboundResult>;
|
|
488
760
|
|
|
489
|
-
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 };
|