@12-apps/marketplace 1.13.0 → 1.15.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 +258 -3
- package/README.md +27 -2
- package/dist/99food/index.d.ts +2 -2
- package/dist/99food/index.js +3 -3
- package/dist/{adapter-CQ4QiZPi.d.ts → adapter-CjVdMhZ2.d.ts} +177 -4
- package/dist/{chunk-CEWTV2TC.js → chunk-B4DYPQFE.js} +657 -251
- package/dist/chunk-B4DYPQFE.js.map +1 -0
- package/dist/{chunk-4J2KJ3ZW.js → chunk-BTKVZAJI.js} +1 -1
- package/dist/chunk-BTKVZAJI.js.map +1 -0
- package/dist/{chunk-BD7DS3XM.js → chunk-E4XJXHUK.js} +20 -1
- package/dist/chunk-E4XJXHUK.js.map +1 -0
- package/dist/{chunk-W57TITU4.js → chunk-FQI56NGC.js} +53 -6
- package/dist/chunk-FQI56NGC.js.map +1 -0
- package/dist/chunk-H2VQRD3B.js +16 -0
- package/dist/chunk-H2VQRD3B.js.map +1 -0
- package/dist/{chunk-NFJQQWG4.js → chunk-TRUK5ZBE.js} +12 -4
- package/dist/chunk-TRUK5ZBE.js.map +1 -0
- package/dist/{client-CCSnylou.d.ts → client-DgzCkl8u.d.ts} +1 -1
- package/dist/{engine-1KlJ_8jK.d.ts → engine-BSLdhAGC.d.ts} +134 -3
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +3 -2
- package/dist/hono/index.js.map +1 -1
- package/dist/ifood/index.d.ts +13 -3
- package/dist/ifood/index.js +219 -29
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +29 -5
- package/dist/index.js +59 -7
- package/dist/index.js.map +1 -1
- package/dist/keeta/index.d.ts +2 -2
- package/dist/keeta/index.js +3 -3
- package/dist/manifest/server.d.ts +4 -2
- package/dist/manifest/server.js +3 -2
- package/dist/manifest/server.js.map +1 -1
- package/dist/rappi/index.d.ts +1 -1
- package/dist/rappi/index.js +2 -2
- package/dist/server/index.d.ts +14 -5
- package/dist/server/index.js +3 -2
- package/package.json +1 -1
- package/prisma/marketplace.prisma +17 -3
- package/prisma/migrations/20261202120000_marketplace_ifood_conformity/migration.sql +25 -0
- package/src/core/acceptance.ts +12 -6
- package/src/core/acknowledge.ts +189 -0
- package/src/core/adapter.ts +74 -1
- package/src/core/cancellation.ts +10 -6
- package/src/core/conformity.ts +63 -0
- package/src/core/engine.ts +3 -2
- package/src/core/ingest.ts +7 -0
- package/src/core/link-store.ts +2 -4
- package/src/core/marketplace-confirmed.ts +229 -0
- package/src/core/order-reasons.ts +119 -0
- package/src/core/order-types.ts +8 -0
- package/src/core/outbound.ts +5 -1
- package/src/core/payload-read.ts +24 -0
- package/src/core/pipeline.ts +27 -1
- package/src/core/ports.ts +2 -0
- package/src/core/registry.ts +28 -2
- package/src/core/state.ts +10 -0
- package/src/core/status-job.ts +86 -3
- package/src/core/types.ts +117 -2
- package/src/ifood/index.ts +27 -4
- package/src/ifood/normalize.ts +38 -5
- package/src/ifood/order-details.ts +120 -0
- package/src/ifood/outbound.ts +131 -27
- package/src/index.ts +24 -0
- package/src/open-delivery/normalize.ts +9 -0
- package/src/server/jobs.ts +57 -4
- package/src/server/webhook.ts +27 -4
- package/dist/chunk-4J2KJ3ZW.js.map +0 -1
- package/dist/chunk-BD7DS3XM.js.map +0 -1
- package/dist/chunk-CEWTV2TC.js.map +0 -1
- package/dist/chunk-NFJQQWG4.js.map +0 -1
- package/dist/chunk-W57TITU4.js.map +0 -1
package/dist/ifood/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
centsFromMajor
|
|
3
3
|
} from "../chunk-WN2EK4KX.js";
|
|
4
|
+
import {
|
|
5
|
+
normalizedLineTotalCents
|
|
6
|
+
} from "../chunk-H2VQRD3B.js";
|
|
4
7
|
import {
|
|
5
8
|
stableUuid
|
|
6
9
|
} from "../chunk-M2V4RFMA.js";
|
|
@@ -9,15 +12,16 @@ import {
|
|
|
9
12
|
firstCents,
|
|
10
13
|
firstDate,
|
|
11
14
|
firstString,
|
|
15
|
+
firstTaxId,
|
|
12
16
|
pick,
|
|
13
17
|
toCents,
|
|
14
18
|
verifyHmacSha256Hex
|
|
15
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-E4XJXHUK.js";
|
|
16
20
|
import {
|
|
17
21
|
answered,
|
|
18
22
|
outboundResultOf,
|
|
19
23
|
tokenGrantResultOf
|
|
20
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-BTKVZAJI.js";
|
|
21
25
|
import {
|
|
22
26
|
__name
|
|
23
27
|
} from "../chunk-7QVYU63E.js";
|
|
@@ -43,7 +47,6 @@ var IFOOD_API = "https://merchant-api.ifood.com.br";
|
|
|
43
47
|
var TOKEN_URL = `${IFOOD_API}/authentication/v1.0/oauth/token`;
|
|
44
48
|
var orderUrl = /* @__PURE__ */ __name((externalOrderId, action) => `${IFOOD_API}/order/v1.0/orders/${encodeURIComponent(externalOrderId)}/${action}`, "orderUrl");
|
|
45
49
|
var IFOOD_PORTAL_URL = "https://portal.ifood.com.br/";
|
|
46
|
-
var TOKEN_MARGIN_MS = 6e4;
|
|
47
50
|
var ifoodTokenKey = /* @__PURE__ */ __name((ctx) => ctx.grant ? ctx.grant.key : `IFOOD:${ctx.environment}:${ctx.credentials.clientId}`, "ifoodTokenKey");
|
|
48
51
|
function tokenOf(body) {
|
|
49
52
|
try {
|
|
@@ -60,7 +63,7 @@ async function bearer(ctx) {
|
|
|
60
63
|
if (ctx.grant) return ctx.grant.accessToken();
|
|
61
64
|
const key = ifoodTokenKey(ctx);
|
|
62
65
|
const cached = ctx.tokens.get(key);
|
|
63
|
-
if (cached && cached.expiresAt > ctx.now.getTime()
|
|
66
|
+
if (cached && cached.expiresAt > ctx.now.getTime()) return { token: cached.token };
|
|
64
67
|
const response = await ctx.http({
|
|
65
68
|
method: "POST",
|
|
66
69
|
url: TOKEN_URL,
|
|
@@ -78,39 +81,109 @@ async function bearer(ctx) {
|
|
|
78
81
|
return { token: token.token };
|
|
79
82
|
}
|
|
80
83
|
__name(bearer, "bearer");
|
|
81
|
-
function
|
|
82
|
-
|
|
84
|
+
async function withIfoodToken(ctx, call5) {
|
|
85
|
+
for (let round = 0; round < 2; round += 1) {
|
|
83
86
|
const auth = await bearer(ctx);
|
|
84
87
|
if (!("token" in auth)) return auth;
|
|
85
|
-
const response = await
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
const response = await call5(auth.token);
|
|
89
|
+
if (response.status !== 401) return response;
|
|
90
|
+
ctx.tokens.delete(ifoodTokenKey(ctx));
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
__name(withIfoodToken, "withIfoodToken");
|
|
95
|
+
function callOrder(ctx, externalOrderId, action, body, method = "POST") {
|
|
96
|
+
return answered(async () => {
|
|
97
|
+
const response = await withIfoodToken(
|
|
98
|
+
ctx,
|
|
99
|
+
(token) => ctx.http({
|
|
100
|
+
method,
|
|
101
|
+
url: orderUrl(externalOrderId, action),
|
|
102
|
+
headers: {
|
|
103
|
+
Authorization: `Bearer ${token}`,
|
|
104
|
+
...body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
105
|
+
},
|
|
106
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
if (response === null) return { kind: "retry", reason: "iFood refused the token" };
|
|
110
|
+
return "kind" in response ? response : outboundResultOf(response);
|
|
96
111
|
});
|
|
97
112
|
}
|
|
113
|
+
__name(callOrder, "callOrder");
|
|
114
|
+
function postOrder(ctx, externalOrderId, action, body) {
|
|
115
|
+
return callOrder(ctx, externalOrderId, action, body);
|
|
116
|
+
}
|
|
98
117
|
__name(postOrder, "postOrder");
|
|
99
118
|
function ifoodConfirm(ctx, order) {
|
|
100
119
|
return postOrder(ctx, order.externalOrderId, "confirm");
|
|
101
120
|
}
|
|
102
121
|
__name(ifoodConfirm, "ifoodConfirm");
|
|
103
122
|
function ifoodRequestCancellation(ctx, order, input) {
|
|
104
|
-
return postOrder(ctx, order.externalOrderId, "requestCancellation", {
|
|
105
|
-
reason: input.text === "" ? input.reason.label : input.text,
|
|
106
|
-
cancellationCode: input.reason.code
|
|
107
|
-
});
|
|
123
|
+
return postOrder(ctx, order.externalOrderId, "requestCancellation", { reason: input.reason.code });
|
|
108
124
|
}
|
|
109
125
|
__name(ifoodRequestCancellation, "ifoodRequestCancellation");
|
|
126
|
+
function reasonsOf(body) {
|
|
127
|
+
try {
|
|
128
|
+
const parsed2 = JSON.parse(body);
|
|
129
|
+
const list2 = Array.isArray(parsed2) ? parsed2 : parsed2?.reasons;
|
|
130
|
+
if (!Array.isArray(list2)) return null;
|
|
131
|
+
return list2.flatMap((entry) => {
|
|
132
|
+
const { code, description } = entry ?? {};
|
|
133
|
+
if (typeof code !== "string" && typeof code !== "number") return [];
|
|
134
|
+
return [{ code: String(code), description: typeof description === "string" ? description : String(code) }];
|
|
135
|
+
});
|
|
136
|
+
} catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
__name(reasonsOf, "reasonsOf");
|
|
141
|
+
async function ifoodOrderCancellationReasons(ctx, order) {
|
|
142
|
+
let body = "";
|
|
143
|
+
const result = await answered(async () => {
|
|
144
|
+
const response = await withIfoodToken(
|
|
145
|
+
ctx,
|
|
146
|
+
(token) => ctx.http({ method: "GET", url: orderUrl(order.externalOrderId, "cancellationReasons"), headers: { Authorization: `Bearer ${token}` } })
|
|
147
|
+
);
|
|
148
|
+
if (response === null) return { kind: "retry", reason: "iFood refused the token" };
|
|
149
|
+
if ("kind" in response) return response;
|
|
150
|
+
body = response.body;
|
|
151
|
+
return outboundResultOf(response);
|
|
152
|
+
});
|
|
153
|
+
if (result.kind !== "accepted") return result;
|
|
154
|
+
const reasons = reasonsOf(body);
|
|
155
|
+
return reasons ? { kind: "reasons", reasons } : { kind: "retry", reason: "iFood answered the reasons with no list" };
|
|
156
|
+
}
|
|
157
|
+
__name(ifoodOrderCancellationReasons, "ifoodOrderCancellationReasons");
|
|
158
|
+
var IFOOD_EVENT_RETENTION_MS = 8 * 60 * 6e4;
|
|
159
|
+
var IFOOD_ACKNOWLEDGEMENT = {
|
|
160
|
+
batchSize: 2e3,
|
|
161
|
+
retentionMs: IFOOD_EVENT_RETENTION_MS,
|
|
162
|
+
send: /* @__PURE__ */ __name((ctx, eventIds) => answered(async () => {
|
|
163
|
+
const body = JSON.stringify(eventIds.map((id) => ({ id })));
|
|
164
|
+
const response = await withIfoodToken(
|
|
165
|
+
ctx,
|
|
166
|
+
(token) => ctx.http({
|
|
167
|
+
method: "POST",
|
|
168
|
+
url: `${IFOOD_API}/events/v1.0/events/acknowledgment`,
|
|
169
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
170
|
+
body
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
if (response === null) return { kind: "retry", reason: "iFood refused the token" };
|
|
174
|
+
return "kind" in response ? response : outboundResultOf(response);
|
|
175
|
+
}), "send")
|
|
176
|
+
};
|
|
110
177
|
var STATUS_ACTION = {
|
|
111
|
-
|
|
178
|
+
// Every order, the merchant's own bag included (FUT-5984, `endpoints.md`: "Para entrega própria,
|
|
179
|
+
// notifique o pedido pronto via `POST /orders/{id}/readyToPickup` antes de despachar via `/dispatch`").
|
|
180
|
+
READY: /* @__PURE__ */ __name(() => "readyToPickup", "READY"),
|
|
112
181
|
DISPATCHED: /* @__PURE__ */ __name((facts) => facts.deliveredBy === "MERCHANT" ? "dispatch" : null, "DISPATCHED")
|
|
113
182
|
};
|
|
183
|
+
function ifoodStatusPrerequisite(facts) {
|
|
184
|
+
return facts.step === "DISPATCHED" && facts.deliveredBy === "MERCHANT" ? "READY" : null;
|
|
185
|
+
}
|
|
186
|
+
__name(ifoodStatusPrerequisite, "ifoodStatusPrerequisite");
|
|
114
187
|
function ifoodStatusSupported(facts) {
|
|
115
188
|
return STATUS_ACTION[facts.step]?.(facts) != null;
|
|
116
189
|
}
|
|
@@ -702,9 +775,99 @@ async function tracking(ctx, order) {
|
|
|
702
775
|
__name(tracking, "tracking");
|
|
703
776
|
var IFOOD_COURIER = { validatePickupCode, tracking };
|
|
704
777
|
|
|
778
|
+
// src/ifood/order-details.ts
|
|
779
|
+
function countOf(source) {
|
|
780
|
+
const stated = Number(pick(source, "quantity") ?? 1);
|
|
781
|
+
return Number.isFinite(stated) && stated > 0 ? Math.round(stated) : 1;
|
|
782
|
+
}
|
|
783
|
+
__name(countOf, "countOf");
|
|
784
|
+
function priced(quantity, unit, total) {
|
|
785
|
+
if (unit !== null && unit * quantity === total) return [{ quantity, unitPriceCents: unit, totalCents: total }];
|
|
786
|
+
const floor = Math.floor(total / quantity);
|
|
787
|
+
const remainder = total - floor * quantity;
|
|
788
|
+
if (remainder === 0) return [{ quantity, unitPriceCents: floor, totalCents: total }];
|
|
789
|
+
const last = { quantity: 1, unitPriceCents: floor + remainder, totalCents: floor + remainder };
|
|
790
|
+
return quantity === 1 ? [last] : [{ quantity: quantity - 1, unitPriceCents: floor, totalCents: floor * (quantity - 1) }, last];
|
|
791
|
+
}
|
|
792
|
+
__name(priced, "priced");
|
|
793
|
+
function readOption(raw) {
|
|
794
|
+
const quantity = countOf(raw);
|
|
795
|
+
const unit = toCents(pick(raw, "unitPrice"));
|
|
796
|
+
const total = toCents(pick(raw, "price")) ?? (unit ?? 0) * quantity;
|
|
797
|
+
const name = firstString(raw, [["name"], ["externalCode"]]);
|
|
798
|
+
if (name === null && total === 0) return [];
|
|
799
|
+
const option = { externalCode: firstString(raw, [["externalCode"]]), name: name ?? "", groupName: firstString(raw, [["groupName"]]) };
|
|
800
|
+
return priced(quantity, unit, total).map((row) => ({ ...option, ...row }));
|
|
801
|
+
}
|
|
802
|
+
__name(readOption, "readOption");
|
|
803
|
+
function readIfoodOptions(item) {
|
|
804
|
+
const raw = pick(item, "options");
|
|
805
|
+
if (!Array.isArray(raw)) return void 0;
|
|
806
|
+
const options = raw.flatMap(readOption);
|
|
807
|
+
return options.length > 0 ? options : void 0;
|
|
808
|
+
}
|
|
809
|
+
__name(readIfoodOptions, "readIfoodOptions");
|
|
810
|
+
var METHODS = /* @__PURE__ */ new Set([
|
|
811
|
+
"CREDIT",
|
|
812
|
+
"DEBIT",
|
|
813
|
+
"MEAL_VOUCHER",
|
|
814
|
+
"FOOD_VOUCHER",
|
|
815
|
+
"PIX",
|
|
816
|
+
"CASH",
|
|
817
|
+
"DIGITAL_WALLET"
|
|
818
|
+
]);
|
|
819
|
+
function prepaidOf(raw) {
|
|
820
|
+
const type = firstString(raw, [["type"]])?.toUpperCase();
|
|
821
|
+
if (type === "ONLINE") return true;
|
|
822
|
+
if (type === "OFFLINE") return false;
|
|
823
|
+
const flag = pick(raw, "prepaid");
|
|
824
|
+
return typeof flag === "boolean" ? flag : null;
|
|
825
|
+
}
|
|
826
|
+
__name(prepaidOf, "prepaidOf");
|
|
827
|
+
function readMethod(raw) {
|
|
828
|
+
const stated = firstString(raw, [["method"]])?.toUpperCase() ?? null;
|
|
829
|
+
return {
|
|
830
|
+
method: stated !== null && METHODS.has(stated) ? stated : "OTHER",
|
|
831
|
+
statedMethod: stated,
|
|
832
|
+
prepaid: prepaidOf(raw),
|
|
833
|
+
valueCents: toCents(pick(raw, "value")) ?? 0,
|
|
834
|
+
cardBrand: firstString(raw, [["card", "brand"]]),
|
|
835
|
+
changeForCents: firstCents(raw, [["cash", "changeFor"], ["changeFor"]])
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
__name(readMethod, "readMethod");
|
|
839
|
+
function readIfoodPayments(order) {
|
|
840
|
+
const payments = pick(order, "payments");
|
|
841
|
+
if (typeof payments !== "object" || payments === null) return void 0;
|
|
842
|
+
const methods = pick(payments, "methods");
|
|
843
|
+
return {
|
|
844
|
+
prepaidCents: firstCents(payments, [["prepaid"]]),
|
|
845
|
+
pendingCents: firstCents(payments, [["pending"]]),
|
|
846
|
+
methods: Array.isArray(methods) ? methods.map(readMethod) : []
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
__name(readIfoodPayments, "readIfoodPayments");
|
|
850
|
+
function readIfoodAdditionalFees(order) {
|
|
851
|
+
const raw = pick(order, "additionalFees");
|
|
852
|
+
if (!Array.isArray(raw)) return void 0;
|
|
853
|
+
return raw.flatMap((fee) => {
|
|
854
|
+
const cents = toCents(pick(fee, "value"));
|
|
855
|
+
if (cents === null) return [];
|
|
856
|
+
const name = firstString(fee, [["description"]]);
|
|
857
|
+
return [{ kind: firstString(fee, [["type"]])?.toUpperCase() ?? "OTHER", cents, ...name === null ? {} : { name } }];
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
__name(readIfoodAdditionalFees, "readIfoodAdditionalFees");
|
|
861
|
+
function readIfoodBuyerDocument(order) {
|
|
862
|
+
return firstTaxId(order, [["customer", "documentNumber"], ["customer", "document"]]);
|
|
863
|
+
}
|
|
864
|
+
__name(readIfoodBuyerDocument, "readIfoodBuyerDocument");
|
|
865
|
+
|
|
705
866
|
// src/ifood/normalize.ts
|
|
706
867
|
var ORDER_PLACED = /* @__PURE__ */ new Set(["PLC", "PLACED", "ORDER_PLACED"]);
|
|
707
868
|
var ORDER_CANCELLED = /* @__PURE__ */ new Set(["CAN", "CANCELLED", "ORDER_CANCELLED"]);
|
|
869
|
+
var ORDER_CONFIRMED = /* @__PURE__ */ new Set(["CFM", "CONFIRMED"]);
|
|
870
|
+
var KEEPALIVE = "KEEPALIVE";
|
|
708
871
|
var CANCELLATION_REQUEST_FAILED = /* @__PURE__ */ new Set(["CARF", "CANCELLATION_REQUEST_FAILED"]);
|
|
709
872
|
var LIFECYCLE_OF = {
|
|
710
873
|
DSP: "DISPATCHED",
|
|
@@ -726,7 +889,9 @@ function readBuyer(order) {
|
|
|
726
889
|
phone: firstString(order, [
|
|
727
890
|
["customer", "phone", "number"],
|
|
728
891
|
["customer", "phone"]
|
|
729
|
-
])
|
|
892
|
+
]),
|
|
893
|
+
...optional("document", readIfoodBuyerDocument(order) ?? void 0),
|
|
894
|
+
...optional("phoneLocalizer", firstString(order, [["customer", "phone", "localizer"]]) ?? void 0)
|
|
730
895
|
};
|
|
731
896
|
}
|
|
732
897
|
__name(readBuyer, "readBuyer");
|
|
@@ -740,7 +905,8 @@ function readLine(item) {
|
|
|
740
905
|
name: name ?? sku,
|
|
741
906
|
quantity: Number.isFinite(quantity) && quantity > 0 ? Math.round(quantity) : 1,
|
|
742
907
|
unitPriceCents: firstCents(item, [["unitPrice"], ["price"]]) ?? 0,
|
|
743
|
-
note: firstString(item, [["observations"], ["note"]])
|
|
908
|
+
note: firstString(item, [["observations"], ["note"]]),
|
|
909
|
+
...optional("options", readIfoodOptions(item))
|
|
744
910
|
};
|
|
745
911
|
}
|
|
746
912
|
__name(readLine, "readLine");
|
|
@@ -748,9 +914,10 @@ function readCommission(order) {
|
|
|
748
914
|
return firstCents(order, [["total", "commission"], ["commission"], ["payments", "commission"]]);
|
|
749
915
|
}
|
|
750
916
|
__name(readCommission, "readCommission");
|
|
917
|
+
var ORDER_TYPES = /* @__PURE__ */ new Set(["DELIVERY", "TAKEOUT", "DINE_IN", "INDOOR"]);
|
|
751
918
|
function readOrderType(order) {
|
|
752
919
|
const stated = firstString(order, [["orderType"]])?.toUpperCase();
|
|
753
|
-
return stated
|
|
920
|
+
return stated !== void 0 && ORDER_TYPES.has(stated) ? stated : null;
|
|
754
921
|
}
|
|
755
922
|
__name(readOrderType, "readOrderType");
|
|
756
923
|
function readDeliveredBy(order) {
|
|
@@ -817,7 +984,7 @@ function readIfoodOrder(payload, externalOrderId, missingStreetNumber) {
|
|
|
817
984
|
// carries delivery fees, its promotions and its rounding, and it is the
|
|
818
985
|
// number on the buyer's receipt. Summing lines when iFood did say is how a
|
|
819
986
|
// store's revenue quietly stops matching its iFood statement.
|
|
820
|
-
totalCents: stated ?? lines.reduce((sum,
|
|
987
|
+
totalCents: stated ?? lines.reduce((sum, line) => sum + normalizedLineTotalCents(line), 0),
|
|
821
988
|
commissionCents: readCommission(order),
|
|
822
989
|
deliveryDueAt: firstDate(order, [["delivery", "deliveryDateTime"], ["preparationStartDateTime"]]),
|
|
823
990
|
placedAt: firstDate(order, [["createdAt"]]) ?? firstDate(payload, [["createdAt"]]) ?? /* @__PURE__ */ new Date(),
|
|
@@ -831,7 +998,10 @@ function readIfoodOrder(payload, externalOrderId, missingStreetNumber) {
|
|
|
831
998
|
subtotalCents: firstCents(order, [["total", "subTotal"]]),
|
|
832
999
|
...optional("discounts", readDiscounts(order)),
|
|
833
1000
|
// The code iFood's courier states at the counter (FUT-5665; confirmed field). Null when iFood asks none.
|
|
834
|
-
pickupCode: firstString(order, [["delivery", "pickupCode"]])
|
|
1001
|
+
pickupCode: firstString(order, [["delivery", "pickupCode"]]),
|
|
1002
|
+
// FUT-5803: how the buyer pays and the fees besides delivery; absent when unstated.
|
|
1003
|
+
...optional("payments", readIfoodPayments(order)),
|
|
1004
|
+
...optional("additionalFees", readIfoodAdditionalFees(order))
|
|
835
1005
|
};
|
|
836
1006
|
}
|
|
837
1007
|
__name(readIfoodOrder, "readIfoodOrder");
|
|
@@ -862,10 +1032,18 @@ function normalizeIfoodEvent(payload, options) {
|
|
|
862
1032
|
cancelled,
|
|
863
1033
|
cancellationOutcome: cancelled ? "CONFIRMED" : refusedRequest ? "FAILED" : null,
|
|
864
1034
|
...LIFECYCLE_OF[eventType.toUpperCase()] ? { lifecycle: LIFECYCLE_OF[eventType.toUpperCase()] } : {},
|
|
865
|
-
...optional("courier", readIfoodCourierEvent(payload, eventType) ?? void 0)
|
|
1035
|
+
...optional("courier", readIfoodCourierEvent(payload, eventType) ?? void 0),
|
|
1036
|
+
...ORDER_CONFIRMED.has(eventType.toUpperCase()) ? { marketplaceConfirmed: true } : {}
|
|
866
1037
|
};
|
|
867
1038
|
}
|
|
868
1039
|
__name(normalizeIfoodEvent, "normalizeIfoodEvent");
|
|
1040
|
+
function readIfoodPresence(payload) {
|
|
1041
|
+
const code = firstString(payload, [["fullCode"], ["code"]]);
|
|
1042
|
+
if (code?.toUpperCase() !== KEEPALIVE) return null;
|
|
1043
|
+
const ids = pick(payload, "merchantIds");
|
|
1044
|
+
return { merchantIds: Array.isArray(ids) ? ids.filter((id) => typeof id === "string") : null };
|
|
1045
|
+
}
|
|
1046
|
+
__name(readIfoodPresence, "readIfoodPresence");
|
|
869
1047
|
|
|
870
1048
|
// src/ifood/fetch-order.ts
|
|
871
1049
|
var orderResourceUrl = /* @__PURE__ */ __name((externalOrderId) => `${IFOOD_API}/order/v1.0/orders/${encodeURIComponent(externalOrderId)}`, "orderResourceUrl");
|
|
@@ -1228,7 +1406,13 @@ function createIfoodAdapter(config) {
|
|
|
1228
1406
|
// Told what iFood has an endpoint for (ESTIMATED, see `./outbound.ts`): ready for
|
|
1229
1407
|
// pickup, and dispatched for a merchant bag. Never "handed over": iFood's own
|
|
1230
1408
|
// CONCLUDED is that.
|
|
1231
|
-
statusSteps: ["READY", "DISPATCHED"]
|
|
1409
|
+
statusSteps: ["READY", "DISPATCHED"],
|
|
1410
|
+
// "Retorne `202 Accepted` em até 5 segundos" (Events `webhook-overview`, FUT-5984).
|
|
1411
|
+
webhookAnswerStatus: 202,
|
|
1412
|
+
// CFM: the store accepted on iFood's own app (FUT-5653).
|
|
1413
|
+
marketplaceConfirms: true,
|
|
1414
|
+
// A step is told only once iFood took the confirm (FUT-5673).
|
|
1415
|
+
statusAfterConfirm: true
|
|
1232
1416
|
},
|
|
1233
1417
|
normalize: /* @__PURE__ */ __name((payload) => normalizeIfoodEvent(payload, normalizeOptions), "normalize"),
|
|
1234
1418
|
readSignature: /* @__PURE__ */ __name((header) => header("x-ifood-signature") ?? header("x-signature"), "readSignature"),
|
|
@@ -1244,6 +1428,11 @@ function createIfoodAdapter(config) {
|
|
|
1244
1428
|
fetchOrder: /* @__PURE__ */ __name((ctx, order) => ifoodFetchOrder(ctx, order, normalizeOptions), "fetchOrder"),
|
|
1245
1429
|
statusSupported: ifoodStatusSupported,
|
|
1246
1430
|
informStatus: ifoodInformStatus,
|
|
1431
|
+
statusPrerequisite: ifoodStatusPrerequisite,
|
|
1432
|
+
// The presence heartbeat, the events' acknowledgment and each order's own reasons (FUT-5984).
|
|
1433
|
+
presence: readIfoodPresence,
|
|
1434
|
+
acknowledgement: IFOOD_ACKNOWLEDGEMENT,
|
|
1435
|
+
orderCancellationReasons: ifoodOrderCancellationReasons,
|
|
1247
1436
|
// The Merchant API's interruptions: an id and an end per closure (FUT-4851).
|
|
1248
1437
|
availability: IFOOD_AVAILABILITY,
|
|
1249
1438
|
// The distributed-app authorization: a store links the software's own app (FUT-5613).
|
|
@@ -1277,6 +1466,7 @@ export {
|
|
|
1277
1466
|
normalizeIfoodEvent,
|
|
1278
1467
|
readIfoodCourierEvent,
|
|
1279
1468
|
readIfoodOrder,
|
|
1469
|
+
readIfoodPresence,
|
|
1280
1470
|
verifyIfoodSignature
|
|
1281
1471
|
};
|
|
1282
1472
|
//# sourceMappingURL=index.js.map
|