@12-apps/marketplace 1.19.1 → 1.20.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 +60 -0
- package/dist/99food/index.d.ts +2 -2
- package/dist/{adapter-ZpAWKoCk.d.ts → adapter-lXWwuQQh.d.ts} +1 -1
- package/dist/{client-DpEq0yXb.d.ts → client-CSHcYu3w.d.ts} +1 -1
- package/dist/{engine-CaiVufoP.d.ts → engine-DH7H8m0B.d.ts} +1 -1
- package/dist/hono/index.d.ts +2 -2
- package/dist/ifood/index.d.ts +365 -2
- package/dist/ifood/index.js +509 -9
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/keeta/index.d.ts +2 -2
- package/dist/manifest/server.d.ts +2 -2
- package/dist/rappi/index.d.ts +1 -1
- package/dist/server/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/ifood/courier.ts +4 -3
- package/src/ifood/index.ts +49 -0
- package/src/ifood/shipping-address.ts +190 -0
- package/src/ifood/shipping-events.ts +126 -0
- package/src/ifood/shipping-orders.ts +213 -0
- package/src/ifood/shipping-wire.ts +274 -0
- package/src/ifood/shipping.ts +184 -0
package/ADOPTING.md
CHANGED
|
@@ -973,3 +973,63 @@ halves for it; a host binds neither and nothing changes.
|
|
|
973
973
|
store**: a close is never refused because the marketplace is away.
|
|
974
974
|
|
|
975
975
|
The code itself is never logged, stored or put in an error.
|
|
976
|
+
|
|
977
|
+
## 18. iFood Shipping: an iFood courier for a delivery (FUT-5667, FUT-5666)
|
|
978
|
+
|
|
979
|
+
iFood's **Shipping** module ("Entrega Sob Demanda") puts an iFood courier on a
|
|
980
|
+
delivery the store would otherwise carry. The engine ships the wire client
|
|
981
|
+
only (`src/ifood/shipping*.ts`, exported from `./ifood`); when a call is made,
|
|
982
|
+
the job that makes it and what the store sees are the host's.
|
|
983
|
+
|
|
984
|
+
- **Which app.** Shipping is a module of the store's PDV (Delivery) app: the
|
|
985
|
+
same credentials as the order calls, a linked store's grant included, with
|
|
986
|
+
the `shipping` scope the store authorized. Never the Logistics app.
|
|
987
|
+
- **Two kinds of order.** On the platform (an iFood order the store carries):
|
|
988
|
+
`ifoodShippingQuoteForOrder`, `ifoodRequestDriver`,
|
|
989
|
+
`ifoodCancelRequestDriver` (free, only before a courier accepts). Off the
|
|
990
|
+
platform (the store's own pedido): `ifoodShippingQuoteForAddress`,
|
|
991
|
+
`ifoodShippingCreateOrder` (answers iFood's id and `trackingUrl`),
|
|
992
|
+
`ifoodShippingCancellationReasons` (`not-cancellable` on iFood's 204) and
|
|
993
|
+
`ifoodShippingCancel`, the address calls (`ifoodShippingConfirmAddress`,
|
|
994
|
+
`ifoodShippingRequestAddressChange`, `ifoodShippingAcceptAddressChange`,
|
|
995
|
+
`ifoodShippingDenyAddressChange`) and `ifoodShippingSafeDelivery`. Both kinds
|
|
996
|
+
read `ifoodShippingTracking` (`notYet` before a courier is assigned).
|
|
997
|
+
- **Money in cents** both ways. A quote carries `netCents` (what the store
|
|
998
|
+
pays) and `expiresAt`; an expired quote is refused here, never sent.
|
|
999
|
+
- **Paid online only.** `ifoodShippingCreateOrder` never sends `payments`. A
|
|
1000
|
+
customer phone with its area code is required (10 or 11 digits, `55`
|
|
1001
|
+
optional; `invalid CUSTOMER_PHONE` otherwise) and goes as `type: CUSTOMER`.
|
|
1002
|
+
- **Addresses are never cut.** A field past iFood's documented length (street,
|
|
1003
|
+
neighbourhood, city and complement 50, reference 70; city at least 2) is
|
|
1004
|
+
`invalid ADDRESS`. Only an item name is cut to 50. A change request needs no
|
|
1005
|
+
postal code and no street number.
|
|
1006
|
+
- **Idempotency.** Every state-changing call takes the host's
|
|
1007
|
+
`idempotencyKey`, sent as `Idempotency-Key`. Make it stable for the logical
|
|
1008
|
+
operation (the pedido and the act), never per attempt.
|
|
1009
|
+
- **Results.** `unavailable` carries iFood's documented code
|
|
1010
|
+
(`IFOOD_SHIPPING_ERROR_CODES`, anything else `UNKNOWN`) and whether the
|
|
1011
|
+
guides say to try later (`transient`). `retry`: nothing changed, ask again
|
|
1012
|
+
after `ifoodShippingRetryDelayMs(attempt)` (immediate, 1, 2, 4, 8 s plus
|
|
1013
|
+
jitter; null after the 5th): a read answered 408, 425, 429 or 5xx, a
|
|
1014
|
+
state-changing call answered 425, 429 or 503, a lost read or token grant.
|
|
1015
|
+
**`uncertain`**: a state-changing request left and may have been applied:
|
|
1016
|
+
no answer came back, or it was answered 408, 500, 502, 504 (any 5xx but
|
|
1017
|
+
503). iFood does not document that it drops a duplicate by key, so never
|
|
1018
|
+
retry it as a new request: retry with the SAME key only once iFood confirms
|
|
1019
|
+
it deduplicates, or wait for its event. Reasons are fixed strings: the
|
|
1020
|
+
host's HTTP error text is never carried.
|
|
1021
|
+
- **Token.** A Shipping call renews a cached token within 5 minutes of its
|
|
1022
|
+
expiry (`IFOOD_SHIPPING_TOKEN_REFRESH_AHEAD_MS`, the Shipping homologation),
|
|
1023
|
+
and once on a 401. Shipping and the order calls share ONE token cache entry
|
|
1024
|
+
per app, so that early renewal also renews the token the order calls use,
|
|
1025
|
+
which the Order homologation says to renew only once expired (an open
|
|
1026
|
+
question to iFood).
|
|
1027
|
+
- **Events.** `readIfoodShippingEvent(payload)` reads the Shipping events of
|
|
1028
|
+
the stream the engine already polls and acknowledges: `REQUEST_DRIVER_*`,
|
|
1029
|
+
`DELIVERY_*`, the cancellation and address-change events, and the
|
|
1030
|
+
`ASSIGN_DRIVER` family through the courier reader. `salesChannel` is `POS`
|
|
1031
|
+
for an off-platform order. `CANCELLATION_REQUEST_FAILED` carries iFood's
|
|
1032
|
+
reason code. The drop code is never read.
|
|
1033
|
+
|
|
1034
|
+
Not the engine's: the 8 s bound on a quote, the 30 s schedule of tracking,
|
|
1035
|
+
logs kept 30 days and the alert after 5 polling failures in a row.
|
package/dist/99food/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, C as CatalogueMenuEntry, b as CatalogueMenuOptions, P as PullCatalogue, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-
|
|
2
|
-
import { O as OpenDeliveryApiBaseUrls } from '../client-
|
|
1
|
+
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, C as CatalogueMenuEntry, b as CatalogueMenuOptions, P as PullCatalogue, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-lXWwuQQh.js';
|
|
2
|
+
import { O as OpenDeliveryApiBaseUrls } from '../client-CSHcYu3w.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The words the 99Food adapter needs from its host, and nothing else.
|
|
@@ -1583,4 +1583,4 @@ declare function tokenGrantResultOf(response: MarketplaceHttpResponse): Outbound
|
|
|
1583
1583
|
/** A call that never got an answer is a retry, with the reason a log can read. */
|
|
1584
1584
|
declare function answered(call: () => Promise<OutboundResult>): Promise<OutboundResult>;
|
|
1585
1585
|
|
|
1586
|
-
export { type
|
|
1586
|
+
export { type DisputeAlternativeType as $, type AdapterCallContext as A, type CatalogueItemRef as B, type CatalogueMenuEntry as C, type CataloguePublishResult as D, type CatalogueReadContext as E, type FetchOrderResult as F, type CatalogueReadNotice as G, type CatalogueReadRefusalCode as H, type CatalogueReadResult as I, type CatalogueReadWarning as J, type CatalogueReadWarningCode as K, type CatalogueSnapshot as L, type MarketplaceAvailability as M, type NormalizedEvent as N, type OutboundResult as O, type PullCatalogue as P, type CatalogueSnapshotCategory as Q, type CatalogueSnapshotItem as R, type StorePauseRequest as S, type CatalogueSnapshotOption as T, type CatalogueSnapshotOptionGroup as U, type CatalogueStoredImage as V, type CatalogueWarningCode as W, type CourierTrackingCallResult as X, type CourierTrackingResult as Y, type DeliveryCodeAnswer as Z, type DisputeAlternative as _, type NormalizedMarketplaceOrder as a, tokenGrantResultOf as a$, type DisputeAnswer as a0, type DisputeAnswerResult as a1, type DisputeFailureCode as a2, type DisputeItem as a3, type DisputeOutcome as a4, type DisputeReason as a5, type InformLogisticsInput as a6, LOGISTICS_STEPS as a7, type LinkCallContext as a8, type LinkCode as a9, type MarketplaceLinkAttemptDelegate as aA, type MarketplaceOrderType as aB, type MarketplacePaymentMethod as aC, type NormalizedAddress as aD, type NormalizedBuyer as aE, type NormalizedDisputeEvent as aF, type NormalizedDisputeOpened as aG, type NormalizedDisputeSettled as aH, type NormalizedLineOption as aI, type NormalizedOrderDiscount as aJ, type NormalizedOrderFee as aK, type NormalizedOrderLine as aL, type NormalizedPaymentMethod as aM, type NormalizedPayments as aN, type OrderCancellationReasonsResult as aO, type OutboundOrderRef as aP, PROVIDER_ID_PATTERN as aQ, type PickupCodeCallResult as aR, type PickupCodeValidation as aS, type PresenceProbe as aT, type StatusFacts as aU, type StatusStep as aV, type ValidatePickupCodeInput as aW, answered as aX, centsFromMajor as aY, normalizedLineTotalCents as aZ, outboundResultOf as a_, type LinkGrant as aa, type LinkResult as ab, type LinkedMerchant as ac, type LogisticsDriver as ad, type LogisticsStep as ae, type LogisticsVehicle as af, type MarketplaceAcknowledgement as ag, type MarketplaceAppCredentialsPort as ah, type MarketplaceCapabilities as ai, type MarketplaceCatalogue as aj, type MarketplaceCourier as ak, type MarketplaceCourierAnswer as al, type MarketplaceCourierEngine as am, type MarketplaceCourierFacts as an, type MarketplaceCourierStep as ao, type MarketplaceCourierVehicle as ap, type MarketplaceCredentials as aq, type MarketplaceDeliveredBy as ar, type MarketplaceDiscountSponsor as as, type MarketplaceDisputeApi as at, type MarketplaceDisputeChange as au, type MarketplaceDisputeDelegate as av, type MarketplaceHttp as aw, type MarketplaceHttpRequest as ax, type MarketplaceHttpResponse as ay, type MarketplaceLifecycle as az, type CatalogueMenuOptions as b, type LogisticsPorts as b0, type LogisticsOrderPort as b1, type MarketplaceLogisticsEngine as b2, type MarketplaceAdapter as c, type PushCatalogue as d, type CatalogueItemOut as e, type CatalogueReader as f, type MarketplaceLinking as g, type MarketplaceAppLinking as h, type MarketplaceCourierApi as i, type NormalizedCourierEvent as j, type StorePauseResult as k, type StorePauseRef as l, type MarketplaceLogistics as m, type MarketplaceCourierTracking as n, type OrderCancellationReason as o, type MarketplaceProvider as p, type CancellationReason as q, type AdapterGrant as r, type AdapterTokenCache as s, type AppLinkCallContext as t, type CancellationOutcome as u, type CancellationRequestInput as v, type CatalogueCallContext as w, type CatalogueFailure as x, type CatalogueImage as y, type CatalogueItem as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ar as MarketplaceDeliveredBy, aI as NormalizedLineOption, aA as MarketplaceLinkAttemptDelegate, av as MarketplaceDisputeDelegate, z as CatalogueItem, y as CatalogueImage, b0 as LogisticsPorts, b1 as LogisticsOrderPort, a as NormalizedMarketplaceOrder, N as NormalizedEvent, aV as StatusStep, j as NormalizedCourierEvent, an as MarketplaceCourierFacts, al as MarketplaceCourierAnswer, aS as PickupCodeValidation, au as MarketplaceDisputeChange, aw as MarketplaceHttp, ah as MarketplaceAppCredentialsPort, c as MarketplaceAdapter, ae as LogisticsStep, az as MarketplaceLifecycle, ao as MarketplaceCourierStep, Z as DeliveryCodeAnswer, p as MarketplaceProvider, aq as MarketplaceCredentials, W as CatalogueWarningCode, aT as PresenceProbe, q as CancellationReason, ac as LinkedMerchant, a2 as DisputeFailureCode, a3 as DisputeItem, _ as DisputeAlternative, a5 as DisputeReason, a4 as DisputeOutcome, am as MarketplaceCourierEngine, b2 as MarketplaceLogisticsEngine, aP as OutboundOrderRef, b as CatalogueMenuOptions, I as CatalogueReadResult } from './adapter-lXWwuQQh.js';
|
|
2
2
|
|
|
3
3
|
/** What the engine tells the host about the order a lifecycle event names. */
|
|
4
4
|
interface MarketplaceLifecycleFacts {
|
package/dist/hono/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hono, Context } from 'hono';
|
|
2
2
|
import { ApiMarketplace, MarketplaceApiConfig, MarketplaceActor } from '../server/index.js';
|
|
3
|
-
import '../engine-
|
|
4
|
-
import '../adapter-
|
|
3
|
+
import '../engine-DH7H8m0B.js';
|
|
4
|
+
import '../adapter-lXWwuQQh.js';
|
|
5
5
|
import '@12-apps/wiring';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
package/dist/ifood/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, A as AdapterCallContext, F as FetchOrderResult, d as PushCatalogue, e as CatalogueItemOut, f as CatalogueReader, g as MarketplaceLinking, h as MarketplaceAppLinking, i as MarketplaceCourierApi, j as NormalizedCourierEvent, M as MarketplaceAvailability, S as StorePauseRequest, k as StorePauseResult, l as StorePauseRef, O as OutboundResult, m as MarketplaceLogistics, c as MarketplaceAdapter } from '../adapter-
|
|
1
|
+
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, A as AdapterCallContext, F as FetchOrderResult, d as PushCatalogue, e as CatalogueItemOut, f as CatalogueReader, g as MarketplaceLinking, h as MarketplaceAppLinking, i as MarketplaceCourierApi, j as NormalizedCourierEvent, M as MarketplaceAvailability, S as StorePauseRequest, k as StorePauseResult, l as StorePauseRef, O as OutboundResult, m as MarketplaceLogistics, n as MarketplaceCourierTracking, o as OrderCancellationReason, c as MarketplaceAdapter } from '../adapter-lXWwuQQh.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The words the iFood adapter needs from its host, and nothing else.
|
|
@@ -188,6 +188,369 @@ declare function ifoodLogisticsVerifyDeliveryCode(ctx: AdapterCallContext, exter
|
|
|
188
188
|
*/
|
|
189
189
|
declare const IFOOD_LOGISTICS: MarketplaceLogistics;
|
|
190
190
|
|
|
191
|
+
/**
|
|
192
|
+
* The wire half every iFood SHIPPING call shares (FUT-5667, FUT-5666): the
|
|
193
|
+
* base URL, the token, the idempotency key and how an answer reads. The calls
|
|
194
|
+
* themselves are `./shipping.ts` and `./shipping-orders.ts`.
|
|
195
|
+
*
|
|
196
|
+
* Read off iFood's Shipping guides on 2026-12-04, each page's markdown source:
|
|
197
|
+
*
|
|
198
|
+
* - https://developer.ifood.com.br/pt-BR/docs/food/guides/modules/shipping/endpoints
|
|
199
|
+
* - https://developer.ifood.com.br/pt-BR/docs/food/guides/modules/shipping/inside
|
|
200
|
+
* - https://developer.ifood.com.br/pt-BR/docs/food/guides/modules/shipping/outside
|
|
201
|
+
* - https://developer.ifood.com.br/pt-BR/docs/food/guides/modules/shipping/homologacao
|
|
202
|
+
* - https://developer.ifood.com.br/pt-BR/docs/food/guides/modules/shipping/best-practices-troubleshooting/boas-praticas-e-troubleshooting
|
|
203
|
+
*
|
|
204
|
+
* Which app: Shipping is a module of the store's PDV (Delivery) app, the one
|
|
205
|
+
* whose token carries the `shipping` scope for the stores that authorized it.
|
|
206
|
+
* The context is used as the host hands it, a linked store's grant included,
|
|
207
|
+
* unlike the Logistics module's own app (`./logistics.ts`).
|
|
208
|
+
*
|
|
209
|
+
* Tests never reach iFood: the HTTP client is the host's port.
|
|
210
|
+
*/
|
|
211
|
+
declare const IFOOD_SHIPPING_API = "https://merchant-api.ifood.com.br/shipping/v1.0";
|
|
212
|
+
/**
|
|
213
|
+
* The Shipping homologation's token rule: "Renove tokens antes do vencimento
|
|
214
|
+
* (recomendado: 5 minutos antes)". A Shipping call renews a cached token this
|
|
215
|
+
* close to its expiry; outside the window the cached one is used.
|
|
216
|
+
*/
|
|
217
|
+
declare const IFOOD_SHIPPING_TOKEN_REFRESH_AHEAD_MS: number;
|
|
218
|
+
/**
|
|
219
|
+
* Every error code the Shipping guides document for a 400 (and the address
|
|
220
|
+
* answers' 409s). Anything else iFood names is read as `UNKNOWN`, so a code a
|
|
221
|
+
* host branches on is always one of these.
|
|
222
|
+
*/
|
|
223
|
+
declare const IFOOD_SHIPPING_ERROR_CODES: readonly ["BadRequest", "BadRequestCustomer", "BadRequestMerchant", "DeliveryDistanceTooHigh", "OffOpeningHours", "OriginNotFound", "ServiceAreaMismatch", "HighDemand", "MerchantStatusAvailability", "MerchantEasyDeliveryDisabled", "InvalidPaymentMethods", "SaturatedOfflinePayment", "NRELimitExceeded", "UnavailableFleet", "PaymentMethodNotFound", "PaymentTotalInvalid", "OrderNotFound", "OrderWithoutSafeDelivery", "ChangeAddressOperationConflict", "ChangeAddressOperationNotStarted", "MaxDistanceHigherThanAllowed", "RegionMismatch"];
|
|
224
|
+
type IfoodShippingErrorCode = (typeof IFOOD_SHIPPING_ERROR_CODES)[number] | "UNKNOWN";
|
|
225
|
+
/** A call refused here, before reaching iFood: nothing was sent. */
|
|
226
|
+
interface IfoodShippingInvalid {
|
|
227
|
+
kind: "invalid";
|
|
228
|
+
reason: "IDEMPOTENCY_KEY" | "QUOTE_EXPIRED" | "COORDINATES" | "CUSTOMER_NAME" | "CUSTOMER_PHONE" | "ADDRESS" | "ADDRESS_TOO_FAR" | "MERCHANT_FEE" | "PREPARATION_TIME" | "ITEMS" | "DISPLAY_ID" | "CANCELLATION_CODE" | "CANCELLATION_REASON";
|
|
229
|
+
}
|
|
230
|
+
/** How a Shipping call can fail. */
|
|
231
|
+
type IfoodShippingFailure =
|
|
232
|
+
/** A documented "not now / not here" answer: iFood's code, and whether the guides say to try again later. */
|
|
233
|
+
{
|
|
234
|
+
kind: "unavailable";
|
|
235
|
+
status: number;
|
|
236
|
+
code: IfoodShippingErrorCode;
|
|
237
|
+
transient: boolean;
|
|
238
|
+
}
|
|
239
|
+
/** Any other final 4xx. The message names the status and code only: an answer body can echo a customer. */
|
|
240
|
+
| {
|
|
241
|
+
kind: "refused";
|
|
242
|
+
status: number;
|
|
243
|
+
message: string;
|
|
244
|
+
own?: true;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Nothing was changed, ask again (with backoff): a read answered 408, 425,
|
|
248
|
+
* 429 or 5xx, a POST answered 425, 429 or 503, a lost read, a lost token grant.
|
|
249
|
+
*/
|
|
250
|
+
| {
|
|
251
|
+
kind: "retry";
|
|
252
|
+
reason: string;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* A state-changing request was SENT and may have been applied: no answer
|
|
256
|
+
* came back, or a POST was answered 408, 500, 502, 504 (or another 5xx but
|
|
257
|
+
* 503). Never retried blindly; a retry goes with the SAME idempotency key.
|
|
258
|
+
*/
|
|
259
|
+
| {
|
|
260
|
+
kind: "uncertain";
|
|
261
|
+
reason: string;
|
|
262
|
+
} | IfoodShippingInvalid;
|
|
263
|
+
/** A state-changing call iFood took (2xx). Its outcome arrives as an event. */
|
|
264
|
+
interface IfoodShippingRequested {
|
|
265
|
+
kind: "requested";
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* How long to wait before an attempt (1-based) of a call that answered
|
|
269
|
+
* `retry`: the best-practices guide's table, 2x with jitter (immediate, 1 s,
|
|
270
|
+
* 2 s, 4 s, 8 s, each plus under a second), at most 5 attempts. Null: stop.
|
|
271
|
+
* The host's job schedules it; the client never sleeps.
|
|
272
|
+
*/
|
|
273
|
+
declare function ifoodShippingRetryDelayMs(attempt: number, random?: () => number): number | null;
|
|
274
|
+
|
|
275
|
+
/** One way the courier can be paid at the door, as the quote lists it. */
|
|
276
|
+
interface IfoodShippingPaymentMethod {
|
|
277
|
+
/** CREDIT, DEBIT or CASH. */
|
|
278
|
+
method: string;
|
|
279
|
+
/** OFFLINE: paid at the door. */
|
|
280
|
+
paymentType: string;
|
|
281
|
+
brand: string | null;
|
|
282
|
+
liability: string | null;
|
|
283
|
+
}
|
|
284
|
+
/** iFood's quote, money in cents. Valid until `expiresAt` (about 24 h); a later request is refused. */
|
|
285
|
+
interface IfoodShippingQuote {
|
|
286
|
+
/** The `quoteId` a request or an order names. */
|
|
287
|
+
id: string;
|
|
288
|
+
expiresAt: Date;
|
|
289
|
+
createdAt: Date | null;
|
|
290
|
+
distanceMeters: number | null;
|
|
291
|
+
/** The preparation time iFood suggests, in seconds. Only the off-platform quote states one. */
|
|
292
|
+
preparationTimeSeconds: number | null;
|
|
293
|
+
grossCents: number;
|
|
294
|
+
discountCents: number;
|
|
295
|
+
/** Only the off-platform quote states a raise; 0 otherwise. */
|
|
296
|
+
raiseCents: number;
|
|
297
|
+
/** What the store pays: `gross - discount + raise`, as iFood states it. */
|
|
298
|
+
netCents: number;
|
|
299
|
+
deliveryTimeSeconds: {
|
|
300
|
+
min: number | null;
|
|
301
|
+
max: number | null;
|
|
302
|
+
};
|
|
303
|
+
paymentMethods: IfoodShippingPaymentMethod[];
|
|
304
|
+
}
|
|
305
|
+
type IfoodShippingQuoteResult = {
|
|
306
|
+
kind: "quote";
|
|
307
|
+
quote: IfoodShippingQuote;
|
|
308
|
+
} | IfoodShippingFailure;
|
|
309
|
+
/**
|
|
310
|
+
* `GET /shipping/v1.0/orders/{orderId}/deliveryAvailabilities`: the quote for
|
|
311
|
+
* an order placed on the iFood platform (FUT-5666). Its 400 codes are the
|
|
312
|
+
* `inside` guide's list.
|
|
313
|
+
*/
|
|
314
|
+
declare function ifoodShippingQuoteForOrder(ctx: AdapterCallContext, externalOrderId: string): Promise<IfoodShippingQuoteResult>;
|
|
315
|
+
/**
|
|
316
|
+
* `GET /shipping/v1.0/merchants/{merchantId}/deliveryAvailabilities?latitude&longitude`:
|
|
317
|
+
* the quote for a door, for an order placed off the platform (FUT-5667).
|
|
318
|
+
*/
|
|
319
|
+
declare function ifoodShippingQuoteForAddress(ctx: AdapterCallContext, merchantId: string, point: {
|
|
320
|
+
latitude: number;
|
|
321
|
+
longitude: number;
|
|
322
|
+
}): Promise<IfoodShippingQuoteResult>;
|
|
323
|
+
/** The quote a request names. */
|
|
324
|
+
interface IfoodShippingQuoteRef {
|
|
325
|
+
id: string;
|
|
326
|
+
expiresAt: Date;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* `POST /shipping/v1.0/orders/{orderId}/requestDriver {quoteId}` (FUT-5666):
|
|
330
|
+
* 202, then `REQUEST_DRIVER_SUCCESS` or `REQUEST_DRIVER_FAILED` as an event.
|
|
331
|
+
* An expired quote is never sent ("Solicitar após é inválido").
|
|
332
|
+
*/
|
|
333
|
+
declare function ifoodRequestDriver(ctx: AdapterCallContext, input: {
|
|
334
|
+
externalOrderId: string;
|
|
335
|
+
quote: IfoodShippingQuoteRef;
|
|
336
|
+
idempotencyKey: string;
|
|
337
|
+
}): Promise<IfoodShippingRequested | IfoodShippingFailure>;
|
|
338
|
+
/**
|
|
339
|
+
* `POST /shipping/v1.0/orders/{orderId}/cancelRequestDriver`, no body: only
|
|
340
|
+
* before a courier accepts, free and irreversible. The outcome is
|
|
341
|
+
* `DELIVERY_CANCELLATION_REQUEST_ACCEPTED` or `..._REJECTED` (the courier had
|
|
342
|
+
* accepted: the order's own cancellation applies then).
|
|
343
|
+
*/
|
|
344
|
+
declare function ifoodCancelRequestDriver(ctx: AdapterCallContext, input: {
|
|
345
|
+
externalOrderId: string;
|
|
346
|
+
idempotencyKey: string;
|
|
347
|
+
}): Promise<IfoodShippingRequested | IfoodShippingFailure>;
|
|
348
|
+
type IfoodShippingTrackingResult = {
|
|
349
|
+
kind: "tracking";
|
|
350
|
+
tracking: MarketplaceCourierTracking;
|
|
351
|
+
}
|
|
352
|
+
/** 404: no courier assigned yet ("Nunca consultar tracking antes de REQUEST_DRIVER_SUCCESS"). */
|
|
353
|
+
| {
|
|
354
|
+
kind: "notYet";
|
|
355
|
+
} | IfoodShippingFailure;
|
|
356
|
+
/**
|
|
357
|
+
* `GET /shipping/v1.0/orders/{orderId}/tracking`, for either kind of order
|
|
358
|
+
* (the off-platform order by the id its creation answered). At most once per
|
|
359
|
+
* 30 s, which is the caller's schedule.
|
|
360
|
+
*/
|
|
361
|
+
declare function ifoodShippingTracking(ctx: AdapterCallContext, orderId: string): Promise<IfoodShippingTrackingResult>;
|
|
362
|
+
|
|
363
|
+
/** A delivery address, as the order and an address change carry it. */
|
|
364
|
+
interface IfoodShippingAddress {
|
|
365
|
+
/** 8 digits once sent; anything else in it is dropped. Not sent with a change request. */
|
|
366
|
+
postalCode: string;
|
|
367
|
+
/** Required on an order; optional on a change request. */
|
|
368
|
+
streetNumber: string;
|
|
369
|
+
/** At most 50 characters. */
|
|
370
|
+
streetName: string;
|
|
371
|
+
/** At most 50 characters. */
|
|
372
|
+
complement?: string;
|
|
373
|
+
/** At most 70 characters. */
|
|
374
|
+
reference?: string;
|
|
375
|
+
/** At most 50 characters. */
|
|
376
|
+
neighborhood: string;
|
|
377
|
+
/** 2 to 50 characters. */
|
|
378
|
+
city: string;
|
|
379
|
+
/** Two letters, e.g. SP. */
|
|
380
|
+
state: string;
|
|
381
|
+
/** Two letters, e.g. BR. */
|
|
382
|
+
country: string;
|
|
383
|
+
latitude: number;
|
|
384
|
+
longitude: number;
|
|
385
|
+
}
|
|
386
|
+
/** An address answer iFood refused: no change pending, another pending, too far, or another region. */
|
|
387
|
+
type IfoodAddressChangeResult = IfoodShippingRequested | {
|
|
388
|
+
kind: "address-change-refused";
|
|
389
|
+
status: number;
|
|
390
|
+
code: IfoodShippingErrorCode;
|
|
391
|
+
} | IfoodShippingFailure;
|
|
392
|
+
/** `POST …/userConfirmAddress`: the customer confirmed the original address. */
|
|
393
|
+
declare function ifoodShippingConfirmAddress(ctx: AdapterCallContext, orderId: string, idempotencyKey: string): Promise<IfoodAddressChangeResult>;
|
|
394
|
+
/** iFood's limit on a changed address: "máximo 500m da coordenada original". */
|
|
395
|
+
declare const IFOOD_SHIPPING_ADDRESS_CHANGE_MAX_METERS = 500;
|
|
396
|
+
/**
|
|
397
|
+
* `POST …/deliveryAddressChangeRequest`: a change asked through the
|
|
398
|
+
* integrator's own screen. Its body has no postal code and an optional street
|
|
399
|
+
* number. Given the `original` point, a move past 500 m is refused here,
|
|
400
|
+
* before iFood would (`MaxDistanceHigherThanAllowed`).
|
|
401
|
+
*/
|
|
402
|
+
declare function ifoodShippingRequestAddressChange(ctx: AdapterCallContext, orderId: string, address: IfoodShippingAddress, idempotencyKey: string, original?: {
|
|
403
|
+
latitude: number;
|
|
404
|
+
longitude: number;
|
|
405
|
+
}): Promise<IfoodAddressChangeResult>;
|
|
406
|
+
/** `POST …/acceptDeliveryAddressChange` (200): within 15 minutes of the request, or iFood rejects it. */
|
|
407
|
+
declare function ifoodShippingAcceptAddressChange(ctx: AdapterCallContext, orderId: string, idempotencyKey: string): Promise<IfoodAddressChangeResult>;
|
|
408
|
+
/** `POST …/denyDeliveryAddressChange` (202). */
|
|
409
|
+
declare function ifoodShippingDenyAddressChange(ctx: AdapterCallContext, orderId: string, idempotencyKey: string): Promise<IfoodAddressChangeResult>;
|
|
410
|
+
/** iFood's confidence in the delivery. */
|
|
411
|
+
type IfoodSafeDeliveryScore = "LOW" | "MODERATE" | "HIGH" | "VERY_HIGH";
|
|
412
|
+
type IfoodSafeDeliveryResult = {
|
|
413
|
+
kind: "score";
|
|
414
|
+
score: IfoodSafeDeliveryScore;
|
|
415
|
+
rules: Record<string, boolean>;
|
|
416
|
+
}
|
|
417
|
+
/** 400 `OrderWithoutSafeDelivery`: the order has no score. */
|
|
418
|
+
| {
|
|
419
|
+
kind: "none";
|
|
420
|
+
} | IfoodShippingFailure;
|
|
421
|
+
/** `GET /shipping/v1.0/orders/{orderId}/safeDelivery`. */
|
|
422
|
+
declare function ifoodShippingSafeDelivery(ctx: AdapterCallContext, orderId: string): Promise<IfoodSafeDeliveryResult>;
|
|
423
|
+
|
|
424
|
+
/** One line of the order. Money in cents. */
|
|
425
|
+
interface IfoodShippingItem {
|
|
426
|
+
id: string;
|
|
427
|
+
name: string;
|
|
428
|
+
externalCode?: string;
|
|
429
|
+
quantity: number;
|
|
430
|
+
unitPriceCents: number;
|
|
431
|
+
/** The line's complements, in total. */
|
|
432
|
+
optionsPriceCents: number;
|
|
433
|
+
}
|
|
434
|
+
/** What creating an order on demand takes. Money in cents. */
|
|
435
|
+
interface IfoodShippingOrderInput {
|
|
436
|
+
customer: {
|
|
437
|
+
name: string;
|
|
438
|
+
/** A Brazilian phone with its area code, in any punctuation, country code optional. Required. */
|
|
439
|
+
phone: string;
|
|
440
|
+
};
|
|
441
|
+
delivery: {
|
|
442
|
+
/** `merchantFee`: the delivery fee the store charged its customer. */
|
|
443
|
+
merchantFeeCents: number;
|
|
444
|
+
/** When iFood allocates the courier, in seconds; 0 or absent is at once. */
|
|
445
|
+
preparationTimeSeconds?: number;
|
|
446
|
+
quote: IfoodShippingQuoteRef;
|
|
447
|
+
address: IfoodShippingAddress;
|
|
448
|
+
};
|
|
449
|
+
items: IfoodShippingItem[];
|
|
450
|
+
/** A short id iFood shows, at most 4 characters. */
|
|
451
|
+
displayId?: string;
|
|
452
|
+
}
|
|
453
|
+
type IfoodShippingCreateResult =
|
|
454
|
+
/** 202: the order exists at iFood and a courier is being allocated. `trackingUrl` is null unless https. */
|
|
455
|
+
{
|
|
456
|
+
kind: "created";
|
|
457
|
+
id: string;
|
|
458
|
+
trackingUrl: string | null;
|
|
459
|
+
} | IfoodShippingFailure;
|
|
460
|
+
/**
|
|
461
|
+
* `POST /shipping/v1.0/merchants/{merchantId}/orders`: registers the order
|
|
462
|
+
* and starts the courier search; 202 `{id, trackingUrl}`. "Se a entrega não
|
|
463
|
+
* for viável, o pedido não será criado." A create whose answer was lost, or a
|
|
464
|
+
* 2xx without an id, is `uncertain`: the delivery may exist, so it is retried
|
|
465
|
+
* only with the same `idempotencyKey`, never as a new one.
|
|
466
|
+
*/
|
|
467
|
+
declare function ifoodShippingCreateOrder(ctx: AdapterCallContext, merchantId: string, input: IfoodShippingOrderInput, idempotencyKey: string): Promise<IfoodShippingCreateResult>;
|
|
468
|
+
type IfoodShippingReasonsResult = {
|
|
469
|
+
kind: "reasons";
|
|
470
|
+
reasons: OrderCancellationReason[];
|
|
471
|
+
}
|
|
472
|
+
/** 204: the order can no longer be cancelled (the courier left with it, or it is over). */
|
|
473
|
+
| {
|
|
474
|
+
kind: "not-cancellable";
|
|
475
|
+
} | IfoodShippingFailure;
|
|
476
|
+
/** `GET /shipping/v1.0/orders/{orderId}/cancellationReasons`: `[{cancelCodeId, description}]`, never hard-coded. */
|
|
477
|
+
declare function ifoodShippingCancellationReasons(ctx: AdapterCallContext, orderId: string): Promise<IfoodShippingReasonsResult>;
|
|
478
|
+
/**
|
|
479
|
+
* `POST /shipping/v1.0/orders/{orderId}/cancel {reason, cancellationCode}`:
|
|
480
|
+
* 202, then `CANCELLED` or `CANCELLATION_REQUEST_FAILED` (e.g. the courier
|
|
481
|
+
* already left) as an event.
|
|
482
|
+
*/
|
|
483
|
+
declare function ifoodShippingCancel(ctx: AdapterCallContext, orderId: string, input: {
|
|
484
|
+
code: string;
|
|
485
|
+
reason: string;
|
|
486
|
+
}, idempotencyKey: string): Promise<IfoodShippingRequested | IfoodShippingFailure>;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* The Shipping events iFood's stream carries (FUT-5667, FUT-5666), read off
|
|
490
|
+
* the `inside` and `outside` Shipping guides and the Order module's events page
|
|
491
|
+
* (https://developer.ifood.com.br/pt-BR/docs/food/guides/modules/order/events),
|
|
492
|
+
* 2026-12-04. The stream, its polling every 30 s, the acknowledgement and the
|
|
493
|
+
* deduplication by event id are the engine's existing ones; this only reads an
|
|
494
|
+
* event the host already has.
|
|
495
|
+
*
|
|
496
|
+
* `salesChannel` tells the two kinds apart: `POS` for an order placed off the
|
|
497
|
+
* platform, `IFOOD` for one placed on it. It is returned as it came; the host
|
|
498
|
+
* filters.
|
|
499
|
+
*
|
|
500
|
+
* `DELIVERY_DROP_CODE_REQUESTED` carries the customer's code in
|
|
501
|
+
* `metadata.CODE`; it is NOT read: the code stays on iFood's tracking page,
|
|
502
|
+
* and never reaches a result a log could print.
|
|
503
|
+
*/
|
|
504
|
+
/** The Shipping events that carry nothing past the order and the time. */
|
|
505
|
+
declare const IFOOD_SHIPPING_EVENT_TYPES: readonly ["REQUEST_DRIVER", "REQUEST_DRIVER_SUCCESS", "REQUEST_DRIVER_FAILED", "DELIVERY_DROP_CODE_REQUESTED", "DELIVERY_IN_TRANSIT", "DELIVERY_CONCLUDED", "DELIVERY_CANCELLED", "DELIVERY_CANCELLATION_REQUESTED", "DELIVERY_CANCELLATION_REQUEST_ACCEPTED", "DELIVERY_CANCELLATION_REQUEST_REJECTED", "CANCELLATION_REQUESTED", "CANCELLED", "DELIVERY_ADDRESS_CHANGE_USER_CONFIRMED", "DELIVERY_ADDRESS_CHANGE_ACCEPTED"];
|
|
506
|
+
type IfoodShippingEventType = (typeof IFOOD_SHIPPING_EVENT_TYPES)[number];
|
|
507
|
+
/** The address a change request names. */
|
|
508
|
+
interface IfoodShippingEventAddress {
|
|
509
|
+
streetName: string | null;
|
|
510
|
+
streetNumber: string | null;
|
|
511
|
+
complement: string | null;
|
|
512
|
+
reference: string | null;
|
|
513
|
+
neighborhood: string | null;
|
|
514
|
+
city: string | null;
|
|
515
|
+
state: string | null;
|
|
516
|
+
country: string | null;
|
|
517
|
+
latitude: number | null;
|
|
518
|
+
longitude: number | null;
|
|
519
|
+
}
|
|
520
|
+
interface EventBase {
|
|
521
|
+
eventId: string;
|
|
522
|
+
orderId: string;
|
|
523
|
+
salesChannel: string | null;
|
|
524
|
+
at: Date | null;
|
|
525
|
+
}
|
|
526
|
+
type IfoodShippingEvent = (EventBase & {
|
|
527
|
+
type: IfoodShippingEventType;
|
|
528
|
+
}) | (EventBase & {
|
|
529
|
+
type: "DELIVERY_ADDRESS_CHANGE_REQUESTED";
|
|
530
|
+
address: IfoodShippingEventAddress;
|
|
531
|
+
})
|
|
532
|
+
/**
|
|
533
|
+
* The order's cancel failed; `reason` is iFood's code from
|
|
534
|
+
* `metadata.CANCELLATION_REQUEST_FAILED_REASON` (e.g.
|
|
535
|
+
* `ACCOUNT_IS_NOT_LINKED_TO_THE_STORE`), a code, never customer data.
|
|
536
|
+
*/
|
|
537
|
+
| (EventBase & {
|
|
538
|
+
type: "CANCELLATION_REQUEST_FAILED";
|
|
539
|
+
reason: string | null;
|
|
540
|
+
})
|
|
541
|
+
/** `action` is `region-mismatch` when iFood denied it itself. */
|
|
542
|
+
| (EventBase & {
|
|
543
|
+
type: "DELIVERY_ADDRESS_CHANGE_DENIED";
|
|
544
|
+
action: string | null;
|
|
545
|
+
})
|
|
546
|
+
/** The `ASSIGN_DRIVER` family, read by the courier reader (FUT-5665). */
|
|
547
|
+
| (EventBase & {
|
|
548
|
+
type: "COURIER";
|
|
549
|
+
courier: NormalizedCourierEvent;
|
|
550
|
+
});
|
|
551
|
+
/** A Shipping event, or null for any other event, or one with no id or order. */
|
|
552
|
+
declare function readIfoodShippingEvent(payload: unknown): IfoodShippingEvent | null;
|
|
553
|
+
|
|
191
554
|
/**
|
|
192
555
|
* `@12-apps/marketplace/ifood` — iFood, as one adapter on the engine.
|
|
193
556
|
*
|
|
@@ -217,4 +580,4 @@ interface IfoodAdapterConfig {
|
|
|
217
580
|
*/
|
|
218
581
|
declare function createIfoodAdapter(config: IfoodAdapterConfig): MarketplaceAdapter;
|
|
219
582
|
|
|
220
|
-
export { IFOOD_APPS_PORTAL_URL, IFOOD_APP_LINKING, IFOOD_AVAILABILITY, IFOOD_CANCELLATION_ANSWER_WINDOW_MS, IFOOD_CATALOGUE, IFOOD_CATALOGUE_READER, IFOOD_COURIER, IFOOD_IMAGE_BASE_URL, IFOOD_LINKING, IFOOD_LOGISTICS, IFOOD_LOGISTICS_STEPS, IFOOD_LOGISTICS_VEHICLES, IFOOD_PROVIDER, IFOOD_REASON_CODES, type IfoodAdapterConfig, type IfoodAdapterCopy, type IfoodDeliveryCodeResult, type IfoodLogisticsDriver, type IfoodLogisticsInvalid, type IfoodLogisticsStep, type IfoodLogisticsVehicle, type IfoodReasonCode, createIfoodAdapter, ifoodAddressLine, ifoodFetchOrder, ifoodItemBody, ifoodItemId, ifoodLocalTime, ifoodLogisticsAssignDriver, ifoodLogisticsStep, ifoodLogisticsStepsTo, ifoodLogisticsVerifyDeliveryCode, ifoodPause, ifoodProductId, ifoodResume, normalizeIfoodEvent, readIfoodCourierEvent, readIfoodOrder, readIfoodPresence, verifyIfoodSignature };
|
|
583
|
+
export { IFOOD_APPS_PORTAL_URL, IFOOD_APP_LINKING, IFOOD_AVAILABILITY, IFOOD_CANCELLATION_ANSWER_WINDOW_MS, IFOOD_CATALOGUE, IFOOD_CATALOGUE_READER, IFOOD_COURIER, IFOOD_IMAGE_BASE_URL, IFOOD_LINKING, IFOOD_LOGISTICS, IFOOD_LOGISTICS_STEPS, IFOOD_LOGISTICS_VEHICLES, IFOOD_PROVIDER, IFOOD_REASON_CODES, IFOOD_SHIPPING_ADDRESS_CHANGE_MAX_METERS, IFOOD_SHIPPING_API, IFOOD_SHIPPING_ERROR_CODES, IFOOD_SHIPPING_EVENT_TYPES, IFOOD_SHIPPING_TOKEN_REFRESH_AHEAD_MS, type IfoodAdapterConfig, type IfoodAdapterCopy, type IfoodAddressChangeResult, type IfoodDeliveryCodeResult, type IfoodLogisticsDriver, type IfoodLogisticsInvalid, type IfoodLogisticsStep, type IfoodLogisticsVehicle, type IfoodReasonCode, type IfoodSafeDeliveryResult, type IfoodSafeDeliveryScore, type IfoodShippingAddress, type IfoodShippingCreateResult, type IfoodShippingErrorCode, type IfoodShippingEvent, type IfoodShippingEventAddress, type IfoodShippingEventType, type IfoodShippingFailure, type IfoodShippingInvalid, type IfoodShippingItem, type IfoodShippingOrderInput, type IfoodShippingPaymentMethod, type IfoodShippingQuote, type IfoodShippingQuoteRef, type IfoodShippingQuoteResult, type IfoodShippingReasonsResult, type IfoodShippingRequested, type IfoodShippingTrackingResult, createIfoodAdapter, ifoodAddressLine, ifoodCancelRequestDriver, ifoodFetchOrder, ifoodItemBody, ifoodItemId, ifoodLocalTime, ifoodLogisticsAssignDriver, ifoodLogisticsStep, ifoodLogisticsStepsTo, ifoodLogisticsVerifyDeliveryCode, ifoodPause, ifoodProductId, ifoodRequestDriver, ifoodResume, ifoodShippingAcceptAddressChange, ifoodShippingCancel, ifoodShippingCancellationReasons, ifoodShippingConfirmAddress, ifoodShippingCreateOrder, ifoodShippingDenyAddressChange, ifoodShippingQuoteForAddress, ifoodShippingQuoteForOrder, ifoodShippingRequestAddressChange, ifoodShippingRetryDelayMs, ifoodShippingSafeDelivery, ifoodShippingTracking, normalizeIfoodEvent, readIfoodCourierEvent, readIfoodOrder, readIfoodPresence, readIfoodShippingEvent, verifyIfoodSignature };
|