@12-apps/marketplace 1.5.0 → 1.7.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 +1 -1
- package/dist/99food/index.d.ts +1 -1
- package/dist/99food/index.js +7 -4
- package/dist/99food/index.js.map +1 -1
- package/dist/{adapter-CCWMqt2g.d.ts → adapter-DOjTak1H.d.ts} +37 -2
- package/dist/{chunk-RGMSD7S7.js → chunk-L3DCOZUU.js} +7 -1
- package/dist/chunk-L3DCOZUU.js.map +1 -0
- package/dist/{chunk-FKUEFVVA.js → chunk-SJUKBCVO.js} +34 -17
- package/dist/chunk-SJUKBCVO.js.map +1 -0
- package/dist/{chunk-UONWZIBO.js → chunk-YVUZHXUF.js} +2 -2
- package/dist/{engine-C3uq_BJd.d.ts → engine-DG1fg43Y.d.ts} +32 -7
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +2 -2
- package/dist/ifood/index.d.ts +1 -1
- package/dist/ifood/index.js +38 -4
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +17 -7
- 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 +4 -3
- package/dist/rappi/index.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +2 -2
- package/package.json +1 -1
- package/prisma/marketplace.prisma +3 -3
- package/prisma/migrations/20261125180000_marketplace_cancellation_failure_reason_widen/migration.sql +16 -0
- package/src/99food/outbound.ts +7 -2
- package/src/core/adapter.ts +17 -2
- package/src/core/cancellation.ts +4 -1
- package/src/core/catalogue.ts +4 -3
- package/src/core/decisions.ts +3 -2
- package/src/core/fetch-order.ts +2 -2
- package/src/core/ingest.ts +32 -4
- package/src/core/order-fetch-marks.ts +13 -8
- package/src/core/outbound.ts +15 -11
- package/src/core/pipeline.ts +13 -1
- package/src/core/ports.ts +26 -4
- package/src/core/state.ts +1 -1
- package/src/core/types.ts +25 -0
- package/src/ifood/normalize.ts +53 -0
- package/src/ifood/outbound.ts +2 -1
- package/src/index.ts +3 -0
- package/src/rappi/outbound.ts +2 -1
- package/dist/chunk-FKUEFVVA.js.map +0 -1
- package/dist/chunk-RGMSD7S7.js.map +0 -1
- /package/dist/{chunk-UONWZIBO.js.map → chunk-YVUZHXUF.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { q as CatalogueItem, p as CatalogueImage, a as NormalizedMarketplaceOrder,
|
|
1
|
+
import { q as CatalogueItem, p as CatalogueImage, a as NormalizedMarketplaceOrder, T as MarketplaceHttp, c as MarketplaceAdapter, i as MarketplaceProvider, L as MarketplaceCredentials, H as CatalogueWarningCode, j as CancellationReason, $ as OutboundOrderRef, N as NormalizedEvent, b as CatalogueMenuOptions, w as CatalogueReadResult } from './adapter-DOjTak1H.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* What the engine needs FROM its host, and nothing more.
|
|
@@ -147,11 +147,22 @@ type MarketplaceAdmissionResult = {
|
|
|
147
147
|
/** Why the engine tells the host to refuse an order. Vocabulary, not copy. */
|
|
148
148
|
type MarketplaceRefusal = "REJECTED" | "EXPIRED" | "CANCELLED";
|
|
149
149
|
/**
|
|
150
|
-
* Why the store's own cancellation request FAILED
|
|
151
|
-
*
|
|
152
|
-
* marketplace
|
|
150
|
+
* Why the store's own cancellation request FAILED. Vocabulary, not copy.
|
|
151
|
+
*
|
|
152
|
+
* - `REFUSED`: the marketplace judged the request and denied it: its denial
|
|
153
|
+
* event, an answer that is its business refusal, or an adapter that has no
|
|
154
|
+
* cancellation API to call. An adapter that cannot tell a business 4xx from
|
|
155
|
+
* a malformed request (iFood, Rappi) reports every final 4xx as REFUSED.
|
|
156
|
+
* - `UNREACHABLE`: our own request never got a judgement: no credentials or
|
|
157
|
+
* ones that do not open, a token the marketplace did not grant, a request
|
|
158
|
+
* the marketplace calls malformed (99Food's 400), or every attempt failed
|
|
159
|
+
* on the network or a 5xx. Retrying, or fixing the connection, can help.
|
|
160
|
+
* - `TIMEOUT`: no answer inside the marketplace's cancellation window.
|
|
161
|
+
*
|
|
162
|
+
* A host written before `UNREACHABLE` existed treats an unknown value as it
|
|
163
|
+
* treats REFUSED: the order stays and a person finishes in the marketplace's app.
|
|
153
164
|
*/
|
|
154
|
-
type CancellationFailureReason = "REFUSED" | "TIMEOUT";
|
|
165
|
+
type CancellationFailureReason = "REFUSED" | "UNREACHABLE" | "TIMEOUT";
|
|
155
166
|
/**
|
|
156
167
|
* The host's domain, as five questions the engine asks and never answers.
|
|
157
168
|
*
|
|
@@ -180,6 +191,17 @@ interface MarketplaceOrderPort {
|
|
|
180
191
|
catalogHas(clientId: string, subjectRef: string): Promise<boolean>;
|
|
181
192
|
/** The store said yes, or the connection auto-accepts. */
|
|
182
193
|
onAccepted(clientId: string, orderId: string): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* OPTIONAL. May an arriving order of this tenant be accepted automatically?
|
|
196
|
+
* Asked once per NEW order of a connection with auto-accept on, before the
|
|
197
|
+
* ingest's transaction (never for a redelivery, never with auto-accept off).
|
|
198
|
+
* `false` declines the automatic acceptance: the order lands exactly as it
|
|
199
|
+
* would with auto-accept off — AWAITING on the clock, no confirm queued, no
|
|
200
|
+
* `onAccepted` — and a person decides it. The order itself is never refused.
|
|
201
|
+
* A throw is logged and declines too. Absent: every auto-accept proceeds.
|
|
202
|
+
* Answer it cheaply: it sits on the ingest path of every order.
|
|
203
|
+
*/
|
|
204
|
+
mayAutoAccept?(clientId: string): Promise<boolean>;
|
|
183
205
|
/** The store said no, the marketplace cancelled, or the clock lapsed. */
|
|
184
206
|
onRefused(clientId: string, orderId: string, reason: MarketplaceRefusal): Promise<void>;
|
|
185
207
|
/**
|
|
@@ -869,7 +891,10 @@ interface IngestResult {
|
|
|
869
891
|
created: boolean;
|
|
870
892
|
/** SKUs that arrived with nothing behind them, in this order. */
|
|
871
893
|
unmappedSkus: string[];
|
|
872
|
-
/**
|
|
894
|
+
/**
|
|
895
|
+
* Whether this order was born accepted: the connection auto-accepts AND the
|
|
896
|
+
* host's `mayAutoAccept`, when bound, allowed it.
|
|
897
|
+
*/
|
|
873
898
|
autoAccepted: boolean;
|
|
874
899
|
}
|
|
875
900
|
/** The store's operating decisions, read from the connection at ingest time. */
|
|
@@ -1184,7 +1209,7 @@ interface MarketplaceOrderState {
|
|
|
1184
1209
|
confirmFailedAt: Date | null;
|
|
1185
1210
|
cancellation: CancellationStatus | null;
|
|
1186
1211
|
cancellationReasonCode: string | null;
|
|
1187
|
-
/** Why the request FAILED (REFUSED or TIMEOUT); null unless `cancellation` is FAILED, and on rows from before it. */
|
|
1212
|
+
/** Why the request FAILED (REFUSED, UNREACHABLE or TIMEOUT); null unless `cancellation` is FAILED, and on rows from before it. */
|
|
1188
1213
|
cancellationFailure: CancellationFailureReason | null;
|
|
1189
1214
|
/** The adapter's app link, or null when no adapter is registered for it. */
|
|
1190
1215
|
appUrl: string | null;
|
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-DG1fg43Y.js';
|
|
4
|
+
import '../adapter-DOjTak1H.js';
|
|
5
5
|
import '@12-apps/wiring';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
package/dist/hono/index.js
CHANGED
package/dist/ifood/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NormalizedEvent, d as PushCatalogue, e as CatalogueItemOut, f as CatalogueReader, M as MarketplaceAvailability, A as AdapterCallContext, S as StorePauseRequest, g as StorePauseResult, h as StorePauseRef, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-
|
|
1
|
+
import { N as NormalizedEvent, d as PushCatalogue, e as CatalogueItemOut, f as CatalogueReader, M as MarketplaceAvailability, A as AdapterCallContext, S as StorePauseRequest, g as StorePauseResult, h as StorePauseRef, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-DOjTak1H.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The words the iFood adapter needs from its host, and nothing else.
|
package/dist/ifood/index.js
CHANGED
|
@@ -10,12 +10,14 @@ import {
|
|
|
10
10
|
firstDate,
|
|
11
11
|
firstString,
|
|
12
12
|
pick,
|
|
13
|
+
toCents,
|
|
13
14
|
verifyHmacSha256Hex
|
|
14
15
|
} from "../chunk-BD7DS3XM.js";
|
|
15
16
|
import {
|
|
16
17
|
answered,
|
|
17
|
-
outboundResultOf
|
|
18
|
-
|
|
18
|
+
outboundResultOf,
|
|
19
|
+
tokenGrantResultOf
|
|
20
|
+
} from "../chunk-L3DCOZUU.js";
|
|
19
21
|
import {
|
|
20
22
|
__name
|
|
21
23
|
} from "../chunk-7QVYU63E.js";
|
|
@@ -68,7 +70,7 @@ async function bearer(ctx) {
|
|
|
68
70
|
clientSecret: ctx.credentials.clientSecret
|
|
69
71
|
}).toString()
|
|
70
72
|
});
|
|
71
|
-
if (response.status < 200 || response.status >= 300) return
|
|
73
|
+
if (response.status < 200 || response.status >= 300) return tokenGrantResultOf(response);
|
|
72
74
|
const token = tokenOf(response.body);
|
|
73
75
|
if (!token) return { kind: "retry", reason: "iFood answered the token grant without a token" };
|
|
74
76
|
ctx.tokens.set(key, { token: token.token, expiresAt: ctx.now.getTime() + token.expiresInSeconds * 1e3 });
|
|
@@ -590,6 +592,28 @@ function readDeliveredBy(order) {
|
|
|
590
592
|
return stated === "MERCHANT" ? "MERCHANT" : null;
|
|
591
593
|
}
|
|
592
594
|
__name(readDeliveredBy, "readDeliveredBy");
|
|
595
|
+
function sponsorOf(name) {
|
|
596
|
+
const stated = name?.toUpperCase();
|
|
597
|
+
if (stated === "IFOOD") return "MARKETPLACE";
|
|
598
|
+
return stated === "MERCHANT" ? "MERCHANT" : "OTHER";
|
|
599
|
+
}
|
|
600
|
+
__name(sponsorOf, "sponsorOf");
|
|
601
|
+
function readDiscounts(order) {
|
|
602
|
+
const benefits = pick(order, "benefits");
|
|
603
|
+
if (!Array.isArray(benefits)) return void 0;
|
|
604
|
+
return benefits.flatMap((benefit) => {
|
|
605
|
+
const shares = pick(benefit, "sponsorshipValues");
|
|
606
|
+
const parts = Array.isArray(shares) ? shares.map((share) => ({
|
|
607
|
+
cents: toCents(pick(share, "value")),
|
|
608
|
+
sponsor: sponsorOf(firstString(share, [["name"]])),
|
|
609
|
+
name: firstString(share, [["description"]])
|
|
610
|
+
})) : [{ cents: toCents(pick(benefit, "value")), sponsor: "OTHER", name: null }];
|
|
611
|
+
return parts.flatMap(
|
|
612
|
+
(part) => part.cents === null || part.cents <= 0 ? [] : [{ cents: part.cents, sponsor: part.sponsor, ...part.name === null ? {} : { name: part.name } }]
|
|
613
|
+
);
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
__name(readDiscounts, "readDiscounts");
|
|
593
617
|
function readAddress(order, missingStreetNumber) {
|
|
594
618
|
const raw = pick(order, "delivery", "deliveryAddress");
|
|
595
619
|
const street = firstString(raw, [["streetName"], ["street"]]);
|
|
@@ -606,6 +630,10 @@ function readAddress(order, missingStreetNumber) {
|
|
|
606
630
|
};
|
|
607
631
|
}
|
|
608
632
|
__name(readAddress, "readAddress");
|
|
633
|
+
function optional(key, value) {
|
|
634
|
+
return value === void 0 ? {} : { [key]: value };
|
|
635
|
+
}
|
|
636
|
+
__name(optional, "optional");
|
|
609
637
|
function readOrder(payload, externalOrderId, missingStreetNumber) {
|
|
610
638
|
const order = pick(payload, "order") ?? payload;
|
|
611
639
|
const rawItems = pick(order, "items");
|
|
@@ -628,7 +656,13 @@ function readOrder(payload, externalOrderId, missingStreetNumber) {
|
|
|
628
656
|
placedAt: firstDate(order, [["createdAt"]]) ?? firstDate(payload, [["createdAt"]]) ?? /* @__PURE__ */ new Date(),
|
|
629
657
|
orderType: readOrderType(order),
|
|
630
658
|
deliveredBy: readDeliveredBy(order),
|
|
631
|
-
deliveryAddress: readAddress(order, missingStreetNumber)
|
|
659
|
+
deliveryAddress: readAddress(order, missingStreetNumber),
|
|
660
|
+
// ESTIMATED names (iFood's order-details guide: `total.deliveryFee`,
|
|
661
|
+
// `total.subTotal`, `benefits[]`). Fee and subtotal are null when unstated,
|
|
662
|
+
// never 0; `discounts` is absent when `benefits` is.
|
|
663
|
+
deliveryFeeCents: firstCents(order, [["total", "deliveryFee"]]),
|
|
664
|
+
subtotalCents: firstCents(order, [["total", "subTotal"]]),
|
|
665
|
+
...optional("discounts", readDiscounts(order))
|
|
632
666
|
};
|
|
633
667
|
}
|
|
634
668
|
__name(readOrder, "readOrder");
|