@12-apps/marketplace 1.10.0 → 1.12.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 +126 -1
- package/README.md +100 -1
- package/dist/99food/index.d.ts +2 -2
- package/dist/99food/index.js +2 -2
- package/dist/{adapter-CYJzu1c9.d.ts → adapter-nUyZpLzz.d.ts} +448 -173
- package/dist/{chunk-2BA2EHNF.js → chunk-45ZVN5XI.js} +316 -42
- package/dist/chunk-45ZVN5XI.js.map +1 -0
- package/dist/{chunk-PYHNM47K.js → chunk-L6FG6T4S.js} +2 -2
- package/dist/{chunk-HEXLCTOG.js → chunk-LACBT6NC.js} +1 -1
- package/dist/chunk-LACBT6NC.js.map +1 -0
- package/dist/{chunk-WVZ2IXFH.js → chunk-MIPNQ7X5.js} +190 -12
- package/dist/chunk-MIPNQ7X5.js.map +1 -0
- package/dist/chunk-SGOTN5PX.js +345 -0
- package/dist/chunk-SGOTN5PX.js.map +1 -0
- package/dist/{client-B4EQCRD_.d.ts → client-Ctas7WCS.d.ts} +1 -1
- package/dist/{engine-DK3iV_Kk.d.ts → engine-CIy9P7Cq.d.ts} +149 -8
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +3 -3
- package/dist/ifood/index.d.ts +10 -2
- package/dist/ifood/index.js +297 -25
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +23 -4
- package/dist/index.js +424 -84
- package/dist/index.js.map +1 -1
- package/dist/keeta/index.d.ts +2 -18
- package/dist/keeta/index.js +12 -3
- package/dist/keeta/index.js.map +1 -1
- package/dist/manifest/index.d.ts +219 -1
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/server.d.ts +2 -2
- package/dist/manifest/server.js +3 -3
- package/dist/rappi/index.d.ts +1 -1
- package/dist/rappi/index.js +1 -1
- package/dist/server/en-US.d.ts +13 -0
- package/dist/server/en-US.js +13 -0
- package/dist/server/en-US.js.map +1 -1
- package/dist/server/index.d.ts +241 -7
- package/dist/server/index.js +3 -3
- package/dist/server/pt-BR.d.ts +13 -0
- package/dist/server/pt-BR.js +13 -0
- package/dist/server/pt-BR.js.map +1 -1
- package/package.json +1 -1
- package/prisma/marketplace.prisma +41 -0
- package/prisma/migrations/20261127090000_marketplace_app_link/migration.sql +81 -0
- package/src/core/adapter.ts +27 -0
- package/src/core/bulk.ts +43 -8
- package/src/core/courier-port.ts +100 -0
- package/src/core/courier.ts +153 -0
- package/src/core/engine.ts +63 -4
- package/src/core/integration.ts +60 -32
- package/src/core/lifecycle.ts +27 -4
- package/src/core/link-store.ts +170 -0
- package/src/core/linking-port.ts +100 -0
- package/src/core/linking.ts +363 -0
- package/src/core/merchant-claim.ts +106 -0
- package/src/core/outbound-queue.ts +24 -11
- package/src/core/outbound.ts +8 -6
- package/src/core/pickup-code.ts +136 -0
- package/src/core/pipeline.ts +15 -6
- package/src/core/ports.ts +26 -1
- package/src/core/status-store.ts +2 -3
- package/src/core/types.ts +56 -4
- package/src/ifood/courier.ts +210 -0
- package/src/ifood/index.ts +8 -0
- package/src/ifood/linking.ts +170 -0
- package/src/ifood/normalize.ts +7 -0
- package/src/ifood/outbound.ts +10 -3
- package/src/index.ts +30 -0
- package/src/keeta/normalize.ts +21 -6
- package/src/server/copy.ts +20 -2
- package/src/server/en-US.ts +13 -0
- package/src/server/index.ts +1 -1
- package/src/server/link-routes.ts +140 -0
- package/src/server/mcp-link.ts +103 -0
- package/src/server/mcp.ts +6 -2
- package/src/server/pt-BR.ts +13 -0
- package/src/server/routes.ts +5 -2
- package/src/server/webhook.ts +86 -0
- package/dist/chunk-2BA2EHNF.js.map +0 -1
- package/dist/chunk-HEXLCTOG.js.map +0 -1
- package/dist/chunk-WVZ2IXFH.js.map +0 -1
- package/dist/chunk-ZO4S3LF4.js +0 -254
- package/dist/chunk-ZO4S3LF4.js.map +0 -1
- /package/dist/{chunk-PYHNM47K.js.map → chunk-L6FG6T4S.js.map} +0 -0
package/dist/ifood/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
answered,
|
|
18
18
|
outboundResultOf,
|
|
19
19
|
tokenGrantResultOf
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-LACBT6NC.js";
|
|
21
21
|
import {
|
|
22
22
|
__name
|
|
23
23
|
} from "../chunk-7QVYU63E.js";
|
|
@@ -44,19 +44,20 @@ var TOKEN_URL = `${IFOOD_API}/authentication/v1.0/oauth/token`;
|
|
|
44
44
|
var orderUrl = /* @__PURE__ */ __name((externalOrderId, action) => `${IFOOD_API}/order/v1.0/orders/${encodeURIComponent(externalOrderId)}/${action}`, "orderUrl");
|
|
45
45
|
var IFOOD_PORTAL_URL = "https://portal.ifood.com.br/";
|
|
46
46
|
var TOKEN_MARGIN_MS = 6e4;
|
|
47
|
-
var ifoodTokenKey = /* @__PURE__ */ __name((ctx) => `IFOOD:${ctx.environment}:${ctx.credentials.clientId}`, "ifoodTokenKey");
|
|
47
|
+
var ifoodTokenKey = /* @__PURE__ */ __name((ctx) => ctx.grant ? ctx.grant.key : `IFOOD:${ctx.environment}:${ctx.credentials.clientId}`, "ifoodTokenKey");
|
|
48
48
|
function tokenOf(body) {
|
|
49
49
|
try {
|
|
50
|
-
const
|
|
51
|
-
if (typeof
|
|
52
|
-
const expires = typeof
|
|
53
|
-
return { token:
|
|
50
|
+
const parsed2 = JSON.parse(body);
|
|
51
|
+
if (typeof parsed2.accessToken !== "string" || parsed2.accessToken === "") return null;
|
|
52
|
+
const expires = typeof parsed2.expiresIn === "number" && parsed2.expiresIn > 0 ? parsed2.expiresIn : 3600;
|
|
53
|
+
return { token: parsed2.accessToken, expiresInSeconds: expires };
|
|
54
54
|
} catch {
|
|
55
55
|
return null;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
__name(tokenOf, "tokenOf");
|
|
59
59
|
async function bearer(ctx) {
|
|
60
|
+
if (ctx.grant) return ctx.grant.accessToken();
|
|
60
61
|
const key = ifoodTokenKey(ctx);
|
|
61
62
|
const cached = ctx.tokens.get(key);
|
|
62
63
|
if (cached && cached.expiresAt > ctx.now.getTime() + TOKEN_MARGIN_MS) return { token: cached.token };
|
|
@@ -157,10 +158,10 @@ function parse(body) {
|
|
|
157
158
|
}
|
|
158
159
|
__name(parse, "parse");
|
|
159
160
|
function categoryIdIn(body, name) {
|
|
160
|
-
const
|
|
161
|
-
if (!Array.isArray(
|
|
161
|
+
const parsed2 = parse(body);
|
|
162
|
+
if (!Array.isArray(parsed2)) return null;
|
|
162
163
|
const wanted = name.trim().toLowerCase();
|
|
163
|
-
const found =
|
|
164
|
+
const found = parsed2.find(
|
|
164
165
|
(entry) => typeof entry === "object" && entry !== null && String(entry.name ?? "").trim().toLowerCase() === wanted
|
|
165
166
|
);
|
|
166
167
|
return typeof found?.id === "string" ? found.id : null;
|
|
@@ -532,11 +533,11 @@ async function read(ctx) {
|
|
|
532
533
|
const listed = await get(ctx, "categories");
|
|
533
534
|
if ("kind" in listed) return listed;
|
|
534
535
|
if (!ok2(listed)) return failureOf2(listed);
|
|
535
|
-
const
|
|
536
|
-
if (!Array.isArray(
|
|
536
|
+
const parsed2 = parse2(listed.body);
|
|
537
|
+
if (!Array.isArray(parsed2)) return unexpected("category list", listed.body);
|
|
537
538
|
const categories = [];
|
|
538
539
|
const notices = [];
|
|
539
|
-
const { entries, others } = entriesOf(
|
|
540
|
+
const { entries, others } = entriesOf(parsed2);
|
|
540
541
|
for (const other of others) notices.push(unreadableCategory(null, other));
|
|
541
542
|
for (const raw of entries) {
|
|
542
543
|
const category = await categoryOf(ctx, raw, notices);
|
|
@@ -557,6 +558,264 @@ var IFOOD_CATALOGUE_READER = {
|
|
|
557
558
|
}, "read")
|
|
558
559
|
};
|
|
559
560
|
|
|
561
|
+
// src/ifood/courier.ts
|
|
562
|
+
var COURIER_STEP_OF = {
|
|
563
|
+
ADR: "ASSIGNED",
|
|
564
|
+
ASSIGN_DRIVER: "ASSIGNED",
|
|
565
|
+
GTO: "GOING_TO_ORIGIN",
|
|
566
|
+
GOING_TO_ORIGIN: "GOING_TO_ORIGIN",
|
|
567
|
+
AAO: "ARRIVED_AT_ORIGIN",
|
|
568
|
+
ARRIVED_AT_ORIGIN: "ARRIVED_AT_ORIGIN",
|
|
569
|
+
CLT: "COLLECTED",
|
|
570
|
+
COLLECTED: "COLLECTED",
|
|
571
|
+
DELIVERY_RETURNING_TO_ORIGIN: "RETURNING_TO_ORIGIN",
|
|
572
|
+
DELIVERY_RETURNED_TO_ORIGIN: "RETURNED_TO_ORIGIN"
|
|
573
|
+
};
|
|
574
|
+
var VEHICLE_OF = {
|
|
575
|
+
MOTORCYCLE: "MOTORCYCLE",
|
|
576
|
+
MOTORBIKE: "MOTORCYCLE",
|
|
577
|
+
MOTO: "MOTORCYCLE",
|
|
578
|
+
BICYCLE: "BICYCLE",
|
|
579
|
+
BIKE: "BICYCLE",
|
|
580
|
+
CAR: "CAR",
|
|
581
|
+
CARRO: "CAR"
|
|
582
|
+
};
|
|
583
|
+
var IFOOD_COURIER_NAME_MAX = 120;
|
|
584
|
+
var IFOOD_COURIER_PHOTO_URL_MAX = 2048;
|
|
585
|
+
function httpsUrl(value) {
|
|
586
|
+
if (!value || value.length > IFOOD_COURIER_PHOTO_URL_MAX) return null;
|
|
587
|
+
try {
|
|
588
|
+
return new URL(value).protocol === "https:" ? value : null;
|
|
589
|
+
} catch {
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
__name(httpsUrl, "httpsUrl");
|
|
594
|
+
function metadataOf(payload) {
|
|
595
|
+
const raw = pick(payload, "metadata");
|
|
596
|
+
if (typeof raw !== "string") return raw;
|
|
597
|
+
try {
|
|
598
|
+
return JSON.parse(raw);
|
|
599
|
+
} catch {
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
__name(metadataOf, "metadataOf");
|
|
604
|
+
function readCourier(payload) {
|
|
605
|
+
const metadata = metadataOf(payload);
|
|
606
|
+
const name = firstString(metadata, [["workerName"]])?.slice(0, IFOOD_COURIER_NAME_MAX) ?? null;
|
|
607
|
+
const photoUrl = httpsUrl(firstString(metadata, [["workerPhotoUrl"]]));
|
|
608
|
+
const stated = firstString(metadata, [["workerVehicleType"]])?.toUpperCase() ?? null;
|
|
609
|
+
const vehicle = stated === null ? null : VEHICLE_OF[stated] ?? "OTHER";
|
|
610
|
+
return name === null && photoUrl === null && vehicle === null ? null : { name, photoUrl, vehicle };
|
|
611
|
+
}
|
|
612
|
+
__name(readCourier, "readCourier");
|
|
613
|
+
function readIfoodCourierEvent(payload, eventType) {
|
|
614
|
+
const step = COURIER_STEP_OF[eventType.toUpperCase()];
|
|
615
|
+
if (!step) return null;
|
|
616
|
+
return {
|
|
617
|
+
step,
|
|
618
|
+
at: firstDate(payload, [["createdAt"]]),
|
|
619
|
+
courier: step === "ASSIGNED" ? readCourier(payload) : null,
|
|
620
|
+
returning: step === "RETURNING_TO_ORIGIN" ? "RETURNING" : step === "RETURNED_TO_ORIGIN" ? "RETURNED" : null
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
__name(readIfoodCourierEvent, "readIfoodCourierEvent");
|
|
624
|
+
var orderUrl2 = /* @__PURE__ */ __name((ref, action) => `${IFOOD_API}/order/v1.0/orders/${encodeURIComponent(ref.externalOrderId)}/${action}`, "orderUrl");
|
|
625
|
+
async function call2(ctx, request) {
|
|
626
|
+
const auth = await bearer(ctx);
|
|
627
|
+
if (!("token" in auth)) return auth.kind === "accepted" ? { kind: "retry", reason: "no token" } : auth;
|
|
628
|
+
const response = await ctx.http({
|
|
629
|
+
method: request.method,
|
|
630
|
+
url: request.url,
|
|
631
|
+
headers: {
|
|
632
|
+
Authorization: `Bearer ${auth.token}`,
|
|
633
|
+
...request.body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
634
|
+
},
|
|
635
|
+
...request.body === void 0 ? {} : { body: JSON.stringify(request.body) }
|
|
636
|
+
});
|
|
637
|
+
if (response.status !== 401) return response;
|
|
638
|
+
ctx.tokens.delete(ifoodTokenKey(ctx));
|
|
639
|
+
return { kind: "retry", reason: "iFood refused the token" };
|
|
640
|
+
}
|
|
641
|
+
__name(call2, "call");
|
|
642
|
+
function parsed(body) {
|
|
643
|
+
try {
|
|
644
|
+
return JSON.parse(body);
|
|
645
|
+
} catch {
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
__name(parsed, "parsed");
|
|
650
|
+
async function validatePickupCode(ctx, order, input) {
|
|
651
|
+
try {
|
|
652
|
+
const response = await call2(ctx, { method: "POST", url: orderUrl2(order, "validatePickupCode"), body: { code: input.code } });
|
|
653
|
+
if ("kind" in response) return response;
|
|
654
|
+
const read2 = outboundResultOf(response);
|
|
655
|
+
if (read2.kind !== "accepted") return read2;
|
|
656
|
+
const valid = pick(parsed(response.body), "valid");
|
|
657
|
+
return typeof valid === "boolean" ? { kind: "answered", valid } : { kind: "refused", status: response.status, message: "iFood answered without a verdict", own: true };
|
|
658
|
+
} catch (error) {
|
|
659
|
+
return retryOf(error);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
__name(validatePickupCode, "validatePickupCode");
|
|
663
|
+
function retryOf(error) {
|
|
664
|
+
return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
|
|
665
|
+
}
|
|
666
|
+
__name(retryOf, "retryOf");
|
|
667
|
+
function numberAt(source, key) {
|
|
668
|
+
const value = pick(source, key);
|
|
669
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
670
|
+
}
|
|
671
|
+
__name(numberAt, "numberAt");
|
|
672
|
+
function plusSeconds(base, seconds) {
|
|
673
|
+
return seconds === null ? null : new Date(base.getTime() + seconds * 1e3);
|
|
674
|
+
}
|
|
675
|
+
__name(plusSeconds, "plusSeconds");
|
|
676
|
+
function readTracking(body, now) {
|
|
677
|
+
const trackedAt = firstDate(body, [["trackDate"]]);
|
|
678
|
+
const base = trackedAt ?? now;
|
|
679
|
+
const pickupSeconds = numberAt(body, "pickupEtaStart") ?? numberAt(body, "pickupEta");
|
|
680
|
+
const deliverySeconds = numberAt(body, "deliveryEtaEnd") ?? numberAt(body, "deliveryEta");
|
|
681
|
+
return {
|
|
682
|
+
pickupEtaAt: plusSeconds(base, pickupSeconds),
|
|
683
|
+
deliveryEtaAt: firstDate(body, [["expectedDelivery"]]) ?? plusSeconds(base, deliverySeconds),
|
|
684
|
+
latitude: numberAt(body, "latitude"),
|
|
685
|
+
longitude: numberAt(body, "longitude"),
|
|
686
|
+
trackedAt
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
__name(readTracking, "readTracking");
|
|
690
|
+
async function tracking(ctx, order) {
|
|
691
|
+
try {
|
|
692
|
+
const response = await call2(ctx, { method: "GET", url: orderUrl2(order, "tracking") });
|
|
693
|
+
if ("kind" in response) return response;
|
|
694
|
+
if (response.status === 404) return { kind: "notYet" };
|
|
695
|
+
const read2 = outboundResultOf(response);
|
|
696
|
+
if (read2.kind !== "accepted") return read2;
|
|
697
|
+
return { kind: "tracking", tracking: readTracking(parsed(response.body), ctx.now) };
|
|
698
|
+
} catch (error) {
|
|
699
|
+
return retryOf(error);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
__name(tracking, "tracking");
|
|
703
|
+
var IFOOD_COURIER = { validatePickupCode, tracking };
|
|
704
|
+
|
|
705
|
+
// src/ifood/linking.ts
|
|
706
|
+
var USER_CODE_URL = `${IFOOD_API}/authentication/v1.0/oauth/userCode`;
|
|
707
|
+
var TOKEN_URL2 = `${IFOOD_API}/authentication/v1.0/oauth/token`;
|
|
708
|
+
var MERCHANTS_URL = `${IFOOD_API}/merchant/v1.0/merchants`;
|
|
709
|
+
var USER_CODE_SECONDS = 600;
|
|
710
|
+
var ACCESS_TOKEN_SECONDS = 21600;
|
|
711
|
+
var MERCHANT_PAGE_SIZE = 100;
|
|
712
|
+
var MAX_MERCHANT_PAGES = 20;
|
|
713
|
+
var FORM = { "Content-Type": "application/x-www-form-urlencoded" };
|
|
714
|
+
function json(body) {
|
|
715
|
+
try {
|
|
716
|
+
return body === "" ? null : JSON.parse(body);
|
|
717
|
+
} catch {
|
|
718
|
+
return null;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
__name(json, "json");
|
|
722
|
+
async function call3(ctx, request, read2) {
|
|
723
|
+
try {
|
|
724
|
+
const response = await ctx.http(request);
|
|
725
|
+
const result = outboundResultOf(response);
|
|
726
|
+
if (result.kind !== "accepted") return result;
|
|
727
|
+
const value = read2(json(response.body));
|
|
728
|
+
return value === null ? { kind: "refused", status: response.status, message: "iFood's answer is not the documented shape" } : { kind: "ok", value };
|
|
729
|
+
} catch (error) {
|
|
730
|
+
return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
__name(call3, "call");
|
|
734
|
+
var positive = /* @__PURE__ */ __name((value, fallback) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback, "positive");
|
|
735
|
+
function codeOf(body) {
|
|
736
|
+
const userCode = asString(pick(body, "userCode"));
|
|
737
|
+
const verifier = asString(pick(body, "authorizationCodeVerifier"));
|
|
738
|
+
const verificationUrl = asString(pick(body, "verificationUrl"));
|
|
739
|
+
if (!userCode || !verifier || !verificationUrl) return null;
|
|
740
|
+
return {
|
|
741
|
+
userCode,
|
|
742
|
+
verifier,
|
|
743
|
+
verificationUrl,
|
|
744
|
+
verificationUrlComplete: asString(pick(body, "verificationUrlComplete")) ?? verificationUrl,
|
|
745
|
+
expiresInSeconds: positive(pick(body, "expiresIn"), USER_CODE_SECONDS)
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
__name(codeOf, "codeOf");
|
|
749
|
+
function grantOf(body, requireRefresh) {
|
|
750
|
+
const accessToken = asString(pick(body, "accessToken"));
|
|
751
|
+
const refreshToken = asString(pick(body, "refreshToken")) ?? asString(pick(body, "refresh_token"));
|
|
752
|
+
if (!accessToken || requireRefresh && !refreshToken) return null;
|
|
753
|
+
return { accessToken, refreshToken, expiresInSeconds: positive(pick(body, "expiresIn"), ACCESS_TOKEN_SECONDS) };
|
|
754
|
+
}
|
|
755
|
+
__name(grantOf, "grantOf");
|
|
756
|
+
function merchantsOf(body) {
|
|
757
|
+
if (!Array.isArray(body)) return null;
|
|
758
|
+
return body.flatMap((raw) => {
|
|
759
|
+
const id = asString(pick(raw, "id"));
|
|
760
|
+
return id ? [{ id, name: asString(pick(raw, "name")), corporateName: asString(pick(raw, "corporateName")) }] : [];
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
__name(merchantsOf, "merchantsOf");
|
|
764
|
+
var tokenRequest = /* @__PURE__ */ __name((fields) => ({
|
|
765
|
+
method: "POST",
|
|
766
|
+
url: TOKEN_URL2,
|
|
767
|
+
headers: FORM,
|
|
768
|
+
body: new URLSearchParams(fields).toString()
|
|
769
|
+
}), "tokenRequest");
|
|
770
|
+
async function listMerchants(ctx, accessToken) {
|
|
771
|
+
const all = [];
|
|
772
|
+
for (let page = 1; page <= MAX_MERCHANT_PAGES; page += 1) {
|
|
773
|
+
const answer = await call3(
|
|
774
|
+
ctx,
|
|
775
|
+
{
|
|
776
|
+
method: "GET",
|
|
777
|
+
url: `${MERCHANTS_URL}?page=${page}&size=${MERCHANT_PAGE_SIZE}`,
|
|
778
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
779
|
+
},
|
|
780
|
+
merchantsOf
|
|
781
|
+
);
|
|
782
|
+
if (answer.kind !== "ok") return answer;
|
|
783
|
+
all.push(...answer.value);
|
|
784
|
+
if (answer.value.length < MERCHANT_PAGE_SIZE) break;
|
|
785
|
+
}
|
|
786
|
+
return { kind: "ok", value: all };
|
|
787
|
+
}
|
|
788
|
+
__name(listMerchants, "listMerchants");
|
|
789
|
+
var IFOOD_LINKING = {
|
|
790
|
+
requestCode: /* @__PURE__ */ __name((ctx) => call3(
|
|
791
|
+
ctx,
|
|
792
|
+
{ method: "POST", url: USER_CODE_URL, headers: FORM, body: new URLSearchParams({ clientId: ctx.credentials.clientId }).toString() },
|
|
793
|
+
codeOf
|
|
794
|
+
), "requestCode"),
|
|
795
|
+
exchange: /* @__PURE__ */ __name((ctx, input) => call3(
|
|
796
|
+
ctx,
|
|
797
|
+
tokenRequest({
|
|
798
|
+
grantType: "authorization_code",
|
|
799
|
+
clientId: ctx.credentials.clientId,
|
|
800
|
+
clientSecret: ctx.credentials.clientSecret,
|
|
801
|
+
authorizationCode: input.authorizationCode,
|
|
802
|
+
authorizationCodeVerifier: input.verifier
|
|
803
|
+
}),
|
|
804
|
+
(body) => grantOf(body, true)
|
|
805
|
+
), "exchange"),
|
|
806
|
+
refresh: /* @__PURE__ */ __name((ctx, input) => call3(
|
|
807
|
+
ctx,
|
|
808
|
+
tokenRequest({
|
|
809
|
+
grantType: "refresh_token",
|
|
810
|
+
clientId: ctx.credentials.clientId,
|
|
811
|
+
clientSecret: ctx.credentials.clientSecret,
|
|
812
|
+
refreshToken: input.refreshToken
|
|
813
|
+
}),
|
|
814
|
+
(body) => grantOf(body, false)
|
|
815
|
+
), "refresh"),
|
|
816
|
+
merchants: /* @__PURE__ */ __name((ctx, input) => listMerchants(ctx, input.accessToken), "merchants")
|
|
817
|
+
};
|
|
818
|
+
|
|
560
819
|
// src/ifood/normalize.ts
|
|
561
820
|
var ORDER_PLACED = /* @__PURE__ */ new Set(["PLC", "PLACED", "ORDER_PLACED"]);
|
|
562
821
|
var ORDER_CANCELLED = /* @__PURE__ */ new Set(["CAN", "CANCELLED", "ORDER_CANCELLED"]);
|
|
@@ -565,7 +824,10 @@ var LIFECYCLE_OF = {
|
|
|
565
824
|
DSP: "DISPATCHED",
|
|
566
825
|
DISPATCHED: "DISPATCHED",
|
|
567
826
|
CON: "CONCLUDED",
|
|
568
|
-
CONCLUDED: "CONCLUDED"
|
|
827
|
+
CONCLUDED: "CONCLUDED",
|
|
828
|
+
// iFood's courier has the bag (FUT-5665): for a fleet bag, the same hand-over as DSP.
|
|
829
|
+
CLT: "COLLECTED",
|
|
830
|
+
COLLECTED: "COLLECTED"
|
|
569
831
|
};
|
|
570
832
|
function verifyIfoodSignature(rawBody, signature, webhookSecret) {
|
|
571
833
|
return verifyHmacSha256Hex(rawBody, signature, webhookSecret);
|
|
@@ -681,7 +943,9 @@ function readOrder(payload, externalOrderId, missingStreetNumber) {
|
|
|
681
943
|
// never 0; `discounts` is absent when `benefits` is.
|
|
682
944
|
deliveryFeeCents: firstCents(order, [["total", "deliveryFee"]]),
|
|
683
945
|
subtotalCents: firstCents(order, [["total", "subTotal"]]),
|
|
684
|
-
...optional("discounts", readDiscounts(order))
|
|
946
|
+
...optional("discounts", readDiscounts(order)),
|
|
947
|
+
// The code iFood's courier states at the counter (FUT-5665; confirmed field). Null when iFood asks none.
|
|
948
|
+
pickupCode: firstString(order, [["delivery", "pickupCode"]])
|
|
685
949
|
};
|
|
686
950
|
}
|
|
687
951
|
__name(readOrder, "readOrder");
|
|
@@ -705,14 +969,15 @@ function normalizeIfoodEvent(payload, options) {
|
|
|
705
969
|
order: placed ? readOrder(payload, externalOrderId, options.missingStreetNumber) : null,
|
|
706
970
|
cancelled,
|
|
707
971
|
cancellationOutcome: cancelled ? "CONFIRMED" : refusedRequest ? "FAILED" : null,
|
|
708
|
-
...LIFECYCLE_OF[eventType.toUpperCase()] ? { lifecycle: LIFECYCLE_OF[eventType.toUpperCase()] } : {}
|
|
972
|
+
...LIFECYCLE_OF[eventType.toUpperCase()] ? { lifecycle: LIFECYCLE_OF[eventType.toUpperCase()] } : {},
|
|
973
|
+
...optional("courier", readIfoodCourierEvent(payload, eventType) ?? void 0)
|
|
709
974
|
};
|
|
710
975
|
}
|
|
711
976
|
__name(normalizeIfoodEvent, "normalizeIfoodEvent");
|
|
712
977
|
|
|
713
978
|
// src/ifood/pause.ts
|
|
714
979
|
var interruptionsUrl = /* @__PURE__ */ __name((merchantId) => `${IFOOD_API}/merchant/v1.0/merchants/${encodeURIComponent(merchantId)}/interruptions`, "interruptionsUrl");
|
|
715
|
-
async function
|
|
980
|
+
async function call4(ctx, request) {
|
|
716
981
|
const auth = await bearer(ctx);
|
|
717
982
|
if (!("token" in auth)) return auth.kind === "accepted" ? { kind: "retry", reason: "unexpected token answer" } : auth;
|
|
718
983
|
const response = await ctx.http({
|
|
@@ -728,7 +993,7 @@ async function call2(ctx, request) {
|
|
|
728
993
|
ctx.tokens.delete(ifoodTokenKey(ctx));
|
|
729
994
|
return { kind: "retry", reason: "iFood refused the token" };
|
|
730
995
|
}
|
|
731
|
-
__name(
|
|
996
|
+
__name(call4, "call");
|
|
732
997
|
var settled = /* @__PURE__ */ __name((value) => "kind" in value, "settled");
|
|
733
998
|
function notOk(response) {
|
|
734
999
|
const result = outboundResultOf(response);
|
|
@@ -736,14 +1001,14 @@ function notOk(response) {
|
|
|
736
1001
|
}
|
|
737
1002
|
__name(notOk, "notOk");
|
|
738
1003
|
async function listInterruptions(ctx, merchantId) {
|
|
739
|
-
const response = await
|
|
1004
|
+
const response = await call4(ctx, { method: "GET", url: interruptionsUrl(merchantId) });
|
|
740
1005
|
if (settled(response)) return response;
|
|
741
1006
|
const failure = notOk(response);
|
|
742
1007
|
if (failure) return failure;
|
|
743
1008
|
try {
|
|
744
|
-
const
|
|
745
|
-
if (!Array.isArray(
|
|
746
|
-
return
|
|
1009
|
+
const parsed2 = JSON.parse(response.body === "" ? "[]" : response.body);
|
|
1010
|
+
if (!Array.isArray(parsed2)) return [];
|
|
1011
|
+
return parsed2.flatMap((entry) => {
|
|
747
1012
|
const value = entry ?? {};
|
|
748
1013
|
if (typeof value.id !== "string") return [];
|
|
749
1014
|
return [
|
|
@@ -763,8 +1028,8 @@ function sameEnd(end, until, timeZone) {
|
|
|
763
1028
|
const sent = ifoodLocalTime(until, timeZone);
|
|
764
1029
|
if (end === sent) return true;
|
|
765
1030
|
if (/(?:[zZ]|[+-]\d{2}:?\d{2})$/u.test(end)) {
|
|
766
|
-
const
|
|
767
|
-
return !Number.isNaN(
|
|
1031
|
+
const parsed2 = Date.parse(end);
|
|
1032
|
+
return !Number.isNaN(parsed2) && Math.floor(parsed2 / 1e3) === Math.floor(until.getTime() / 1e3);
|
|
768
1033
|
}
|
|
769
1034
|
return end.slice(0, 19) === sent.slice(0, 19);
|
|
770
1035
|
}
|
|
@@ -820,7 +1085,7 @@ function ifoodPause(ctx, request) {
|
|
|
820
1085
|
if (!Array.isArray(list2)) return list2;
|
|
821
1086
|
const landed = ours(list2, request.key, { until: request.until, reason: request.reason, timeZone: request.timeZone }, request.keep);
|
|
822
1087
|
if (landed) return { kind: "paused", externalId: landed.id, until: request.until };
|
|
823
|
-
const response = await
|
|
1088
|
+
const response = await call4(ctx, {
|
|
824
1089
|
method: "POST",
|
|
825
1090
|
url: interruptionsUrl(request.merchantId),
|
|
826
1091
|
json: {
|
|
@@ -846,7 +1111,7 @@ function ifoodResume(ctx, ref) {
|
|
|
846
1111
|
id = ours(list2, ref.key, ref.sent, ref.keep)?.id ?? null;
|
|
847
1112
|
}
|
|
848
1113
|
if (id === null) return { kind: "accepted" };
|
|
849
|
-
const response = await
|
|
1114
|
+
const response = await call4(ctx, { method: "DELETE", url: `${interruptionsUrl(ref.merchantId)}/${encodeURIComponent(id)}` });
|
|
850
1115
|
if (settled(response)) return response;
|
|
851
1116
|
if (response.status === 404) return { kind: "accepted" };
|
|
852
1117
|
return outboundResultOf(response);
|
|
@@ -913,6 +1178,10 @@ function createIfoodAdapter(config) {
|
|
|
913
1178
|
informStatus: ifoodInformStatus,
|
|
914
1179
|
// The Merchant API's interruptions: an id and an end per closure (FUT-4851).
|
|
915
1180
|
availability: IFOOD_AVAILABILITY,
|
|
1181
|
+
// The distributed-app authorization: a store links the software's own app (FUT-5613).
|
|
1182
|
+
linking: IFOOD_LINKING,
|
|
1183
|
+
// iFood's fleet: the pickup-code check and the courier's tracking (FUT-5665).
|
|
1184
|
+
courier: IFOOD_COURIER,
|
|
916
1185
|
// No per-order deep link is known, so the portal, where a live order is
|
|
917
1186
|
// on the first screen.
|
|
918
1187
|
appLink: /* @__PURE__ */ __name(() => IFOOD_PORTAL_URL, "appLink")
|
|
@@ -924,7 +1193,9 @@ export {
|
|
|
924
1193
|
IFOOD_CANCELLATION_ANSWER_WINDOW_MS,
|
|
925
1194
|
IFOOD_CATALOGUE,
|
|
926
1195
|
IFOOD_CATALOGUE_READER,
|
|
1196
|
+
IFOOD_COURIER,
|
|
927
1197
|
IFOOD_IMAGE_BASE_URL,
|
|
1198
|
+
IFOOD_LINKING,
|
|
928
1199
|
IFOOD_PROVIDER,
|
|
929
1200
|
IFOOD_REASON_CODES,
|
|
930
1201
|
createIfoodAdapter,
|
|
@@ -935,6 +1206,7 @@ export {
|
|
|
935
1206
|
ifoodProductId,
|
|
936
1207
|
ifoodResume,
|
|
937
1208
|
normalizeIfoodEvent,
|
|
1209
|
+
readIfoodCourierEvent,
|
|
938
1210
|
verifyIfoodSignature
|
|
939
1211
|
};
|
|
940
1212
|
//# sourceMappingURL=index.js.map
|