@12-apps/marketplace 1.16.0 → 1.17.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.
Files changed (71) hide show
  1. package/ADOPTING.md +115 -0
  2. package/dist/99food/index.d.ts +2 -2
  3. package/dist/99food/index.js +2 -2
  4. package/dist/{adapter-CjVdMhZ2.d.ts → adapter-CxzF-qGx.d.ts} +185 -2
  5. package/dist/{chunk-TRUK5ZBE.js → chunk-7IYUO2KC.js} +2 -2
  6. package/dist/{chunk-BTKVZAJI.js → chunk-CF5BSXE5.js} +1 -1
  7. package/dist/chunk-CF5BSXE5.js.map +1 -0
  8. package/dist/{chunk-DJIMUEHT.js → chunk-EABVLQKK.js} +79 -7
  9. package/dist/chunk-EABVLQKK.js.map +1 -0
  10. package/dist/{chunk-H2VQRD3B.js → chunk-KKFMDV5K.js} +1 -1
  11. package/dist/chunk-KKFMDV5K.js.map +1 -0
  12. package/dist/{chunk-SGOTN5PX.js → chunk-LO7OKO6V.js} +45 -4
  13. package/dist/chunk-LO7OKO6V.js.map +1 -0
  14. package/dist/{chunk-TICWLBSA.js → chunk-UZO2NILN.js} +365 -6
  15. package/dist/chunk-UZO2NILN.js.map +1 -0
  16. package/dist/{client-DgzCkl8u.d.ts → client-C-4QvVq3.d.ts} +1 -1
  17. package/dist/{engine-DSRj7qnC.d.ts → engine-Y6Rpf5p7.d.ts} +430 -185
  18. package/dist/hono/index.d.ts +2 -2
  19. package/dist/hono/index.js +4 -4
  20. package/dist/ifood/index.d.ts +9 -2
  21. package/dist/ifood/index.js +271 -23
  22. package/dist/ifood/index.js.map +1 -1
  23. package/dist/index.d.ts +21 -4
  24. package/dist/index.js +381 -42
  25. package/dist/index.js.map +1 -1
  26. package/dist/keeta/index.d.ts +2 -2
  27. package/dist/keeta/index.js +2 -2
  28. package/dist/manifest/index.d.ts +78 -0
  29. package/dist/manifest/index.js +1 -1
  30. package/dist/manifest/server.d.ts +6 -2
  31. package/dist/manifest/server.js +4 -4
  32. package/dist/rappi/index.d.ts +1 -1
  33. package/dist/rappi/index.js +1 -1
  34. package/dist/server/index.d.ts +93 -7
  35. package/dist/server/index.js +4 -4
  36. package/package.json +1 -1
  37. package/prisma/marketplace.prisma +69 -1
  38. package/prisma/migrations/20261203180000_marketplace_app_link_check/migration.sql +14 -0
  39. package/prisma/migrations/20261203190000_marketplace_disputes/migration.sql +96 -0
  40. package/src/core/adapter.ts +12 -1
  41. package/src/core/app-linking.ts +396 -0
  42. package/src/core/dispute-engine.ts +32 -0
  43. package/src/core/dispute-job.ts +142 -0
  44. package/src/core/dispute-port.ts +133 -0
  45. package/src/core/dispute-store.ts +203 -0
  46. package/src/core/disputes.ts +263 -0
  47. package/src/core/engine.ts +4 -55
  48. package/src/core/integration.ts +3 -1
  49. package/src/core/link-engine.ts +176 -0
  50. package/src/core/link-store.ts +15 -0
  51. package/src/core/linking-port.ts +35 -1
  52. package/src/core/linking.ts +8 -0
  53. package/src/core/outbound-sweep.ts +9 -1
  54. package/src/core/pipeline.ts +8 -3
  55. package/src/core/ports.ts +15 -0
  56. package/src/core/types.ts +8 -0
  57. package/src/ifood/app-linking.ts +119 -0
  58. package/src/ifood/disputes.ts +209 -0
  59. package/src/ifood/index.ts +12 -1
  60. package/src/ifood/normalize.ts +3 -0
  61. package/src/index.ts +34 -0
  62. package/src/server/jobs.ts +51 -3
  63. package/src/server/link-routes.ts +56 -4
  64. package/src/server/mcp-link.ts +44 -2
  65. package/src/server/mcp.ts +2 -1
  66. package/dist/chunk-BTKVZAJI.js.map +0 -1
  67. package/dist/chunk-DJIMUEHT.js.map +0 -1
  68. package/dist/chunk-H2VQRD3B.js.map +0 -1
  69. package/dist/chunk-SGOTN5PX.js.map +0 -1
  70. package/dist/chunk-TICWLBSA.js.map +0 -1
  71. /package/dist/{chunk-TRUK5ZBE.js.map → chunk-7IYUO2KC.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { Hono, Context } from 'hono';
2
2
  import { ApiMarketplace, MarketplaceApiConfig, MarketplaceActor } from '../server/index.js';
3
- import '../engine-DSRj7qnC.js';
4
- import '../adapter-CjVdMhZ2.js';
3
+ import '../engine-Y6Rpf5p7.js';
4
+ import '../adapter-CxzF-qGx.js';
5
5
  import '@12-apps/wiring';
6
6
  import 'zod';
7
7
 
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createApiMarketplace
3
- } from "../chunk-DJIMUEHT.js";
4
- import "../chunk-SGOTN5PX.js";
5
- import "../chunk-TICWLBSA.js";
6
- import "../chunk-H2VQRD3B.js";
3
+ } from "../chunk-EABVLQKK.js";
4
+ import "../chunk-LO7OKO6V.js";
5
+ import "../chunk-UZO2NILN.js";
6
+ import "../chunk-KKFMDV5K.js";
7
7
  import {
8
8
  __name
9
9
  } from "../chunk-7QVYU63E.js";
@@ -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 MarketplaceCourierApi, i as NormalizedCourierEvent, M as MarketplaceAvailability, S as StorePauseRequest, j as StorePauseResult, k as StorePauseRef, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-CjVdMhZ2.js';
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, c as MarketplaceAdapter } from '../adapter-CxzF-qGx.js';
2
2
 
3
3
  /**
4
4
  * The words the iFood adapter needs from its host, and nothing else.
@@ -76,6 +76,13 @@ declare const IFOOD_CATALOGUE_READER: CatalogueReader;
76
76
  /** The iFood adapter's linking half. */
77
77
  declare const IFOOD_LINKING: MarketplaceLinking;
78
78
 
79
+ /** Where a store authorizes the software's app: the Portal do Parceiro's apps page. */
80
+ declare const IFOOD_APPS_PORTAL_URL = "https://portal.ifood.com.br/apps";
81
+ /** "Rua Pernambuco, 1000 · Savassi": the street and number, then the district; null when the detail carries no street. */
82
+ declare function ifoodAddressLine(body: unknown): string | null;
83
+ /** The iFood adapter's centralized linking half. */
84
+ declare const IFOOD_APP_LINKING: MarketplaceAppLinking;
85
+
79
86
  /** The courier step an iFood event names, or null. */
80
87
  declare function readIfoodCourierEvent(payload: unknown, eventType: string): NormalizedCourierEvent | null;
81
88
  /** iFood's courier calls, for the adapter's `courier`. */
@@ -205,4 +212,4 @@ interface IfoodAdapterConfig {
205
212
  */
206
213
  declare function createIfoodAdapter(config: IfoodAdapterConfig): MarketplaceAdapter;
207
214
 
208
- export { IFOOD_AVAILABILITY, IFOOD_CANCELLATION_ANSWER_WINDOW_MS, IFOOD_CATALOGUE, IFOOD_CATALOGUE_READER, IFOOD_COURIER, IFOOD_IMAGE_BASE_URL, IFOOD_LINKING, 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, ifoodFetchOrder, ifoodItemBody, ifoodItemId, ifoodLocalTime, ifoodLogisticsAssignDriver, ifoodLogisticsStep, ifoodLogisticsStepsTo, ifoodLogisticsVerifyDeliveryCode, ifoodPause, ifoodProductId, ifoodResume, normalizeIfoodEvent, readIfoodCourierEvent, readIfoodOrder, readIfoodPresence, verifyIfoodSignature };
215
+ 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_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 };
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-WN2EK4KX.js";
4
4
  import {
5
5
  normalizedLineTotalCents
6
- } from "../chunk-H2VQRD3B.js";
6
+ } from "../chunk-KKFMDV5K.js";
7
7
  import {
8
8
  stableUuid
9
9
  } from "../chunk-M2V4RFMA.js";
@@ -21,7 +21,7 @@ import {
21
21
  answered,
22
22
  outboundResultOf,
23
23
  tokenGrantResultOf
24
- } from "../chunk-BTKVZAJI.js";
24
+ } from "../chunk-CF5BSXE5.js";
25
25
  import {
26
26
  __name
27
27
  } from "../chunk-7QVYU63E.js";
@@ -775,6 +775,159 @@ async function tracking(ctx, order) {
775
775
  __name(tracking, "tracking");
776
776
  var IFOOD_COURIER = { validatePickupCode, tracking };
777
777
 
778
+ // src/ifood/disputes.ts
779
+ var DISPUTE_OPENED = /* @__PURE__ */ new Set(["HSD", "HANDSHAKE_DISPUTE"]);
780
+ var DISPUTE_SETTLED = /* @__PURE__ */ new Set(["HSS", "HANDSHAKE_SETTLEMENT"]);
781
+ var OUTCOMES = /* @__PURE__ */ new Set(["ACCEPTED", "REJECTED", "EXPIRED", "ALTERNATIVE_REPLIED"]);
782
+ function centsOf(money) {
783
+ const raw = typeof money === "object" && money !== null ? pick(money, "value") : money;
784
+ const numeric = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
785
+ return typeof numeric === "number" && Number.isInteger(numeric) && numeric >= 0 ? numeric : null;
786
+ }
787
+ __name(centsOf, "centsOf");
788
+ function listOf(source, key) {
789
+ const value = pick(source, key);
790
+ return Array.isArray(value) ? value : [];
791
+ }
792
+ __name(listOf, "listOf");
793
+ function readReason(entry) {
794
+ if (typeof entry === "string") return entry ? [{ code: entry, description: entry }] : [];
795
+ const code = firstString(entry, [["code"], ["reason"], ["id"]]);
796
+ if (!code) return [];
797
+ return [{ code, description: firstString(entry, [["description"], ["label"], ["name"]]) ?? code }];
798
+ }
799
+ __name(readReason, "readReason");
800
+ function readItem(entry) {
801
+ const name = firstString(entry, [["name"], ["description"]]);
802
+ if (!name) return [];
803
+ const quantity = Number(pick(entry, "quantity") ?? 1);
804
+ return [
805
+ {
806
+ name,
807
+ quantity: Number.isFinite(quantity) && quantity > 0 ? Math.round(quantity) : 1,
808
+ amountCents: centsOf(pick(entry, "amount")) ?? centsOf(pick(entry, "totalPrice"))
809
+ }
810
+ ];
811
+ }
812
+ __name(readItem, "readItem");
813
+ var ALTERNATIVE_TYPES = /* @__PURE__ */ new Set(["REFUND", "BENEFIT", "ADDITIONAL_TIME"]);
814
+ function readAlternative(entry) {
815
+ const id = firstString(entry, [["id"]]);
816
+ const type = firstString(entry, [["type"]])?.toUpperCase();
817
+ if (!id || !type || !ALTERNATIVE_TYPES.has(type)) return [];
818
+ const metadata = pick(entry, "metadata");
819
+ const stated = pick(metadata, "maxAmount");
820
+ const maxAmountCents = centsOf(stated);
821
+ if (stated !== void 0 && stated !== null && maxAmountCents === null) return [];
822
+ const minutes = listOf(metadata, "allowedsAdditionalTimeInMinutes").map(Number).filter((value) => Number.isInteger(value) && value > 0);
823
+ return [
824
+ {
825
+ id,
826
+ type,
827
+ maxAmountCents,
828
+ allowedMinutes: minutes
829
+ }
830
+ ];
831
+ }
832
+ __name(readAlternative, "readAlternative");
833
+ function readEvidences(metadata) {
834
+ return listOf(metadata, "evidences").map((entry) => typeof entry === "string" ? entry : asString(pick(entry, "url"))).filter((url) => typeof url === "string" && url.startsWith("https://"));
835
+ }
836
+ __name(readEvidences, "readEvidences");
837
+ function sumOf(items) {
838
+ const amounts = items.map((item) => item.amountCents);
839
+ return amounts.length > 0 && amounts.every((value) => value !== null) ? amounts.reduce((a, b) => a + b, 0) : null;
840
+ }
841
+ __name(sumOf, "sumOf");
842
+ function readOpened(payload, metadata, disputeId) {
843
+ const items = listOf(metadata, "garnishItems").flatMap(readItem);
844
+ return {
845
+ kind: "opened",
846
+ dispute: {
847
+ disputeId,
848
+ action: firstString(metadata, [["action"]]) ?? "UNKNOWN",
849
+ handshakeType: firstString(metadata, [["handshakeType"]]),
850
+ reason: firstString(metadata, [["reason"], ["handshakeGroup"]]),
851
+ message: firstString(metadata, [["message"]]),
852
+ evidenceUrls: readEvidences(metadata),
853
+ items,
854
+ requestedAmountCents: centsOf(pick(metadata, "amount")) ?? sumOf(items),
855
+ expiresAt: firstDate(metadata, [["expiresAt"]]),
856
+ openedAt: firstDate(metadata, [["createdAt"]]) ?? firstDate(payload, [["createdAt"]]),
857
+ timeoutAction: firstString(metadata, [["timeoutAction"]]),
858
+ alternatives: listOf(metadata, "alternatives").flatMap(readAlternative),
859
+ rejectReasons: listOf(metadata, "negotiationReasons").flatMap(readReason),
860
+ acceptReasons: listOf(metadata, "acceptCancellationReasons").flatMap(readReason)
861
+ }
862
+ };
863
+ }
864
+ __name(readOpened, "readOpened");
865
+ function readSettled(payload, metadata, disputeId) {
866
+ const status = firstString(metadata, [["status"]])?.toUpperCase() ?? "";
867
+ const selected = pick(metadata, "selectedDisputeAlternative");
868
+ return {
869
+ kind: "settled",
870
+ settlement: {
871
+ disputeId,
872
+ outcome: OUTCOMES.has(status) ? status : "OTHER",
873
+ at: firstDate(metadata, [["createdAt"]]) ?? firstDate(payload, [["createdAt"]]),
874
+ amountCents: centsOf(pick(selected, "metadata", "amount")) ?? centsOf(pick(metadata, "amount"))
875
+ }
876
+ };
877
+ }
878
+ __name(readSettled, "readSettled");
879
+ function readIfoodDispute(payload, eventType) {
880
+ const code = eventType.toUpperCase();
881
+ const opened = DISPUTE_OPENED.has(code);
882
+ if (!opened && !DISPUTE_SETTLED.has(code)) return null;
883
+ const metadata = pick(payload, "metadata");
884
+ const disputeId = firstString(metadata, [["disputeId"], ["id"]]);
885
+ if (!disputeId) return null;
886
+ return opened ? readOpened(payload, metadata, disputeId) : readSettled(payload, metadata, disputeId);
887
+ }
888
+ __name(readIfoodDispute, "readIfoodDispute");
889
+ function requestOf(answer) {
890
+ if (answer.kind === "ACCEPT") return { path: "accept", body: answer.reasonCode ? { reason: answer.reasonCode } : void 0 };
891
+ if (answer.kind === "REJECT") return { path: "reject", body: { reason: answer.reasonCode } };
892
+ const { alternative } = answer;
893
+ const metadata = alternative.type === "ADDITIONAL_TIME" ? { additionalTimeInMinutes: answer.minutes } : { amount: { value: String(answer.amountCents), currency: "BRL" } };
894
+ return { path: `alternatives/${encodeURIComponent(alternative.id)}`, body: { type: alternative.type, metadata } };
895
+ }
896
+ __name(requestOf, "requestOf");
897
+ var FAILURE_OF = [
898
+ ["DISPUTE_ALREADY_ANSWERED", "ALREADY_ANSWERED"],
899
+ ["DISPUTE_NOT_FOUND", "NOT_FOUND"],
900
+ ["INVALID_REASON", "INVALID_REASON"],
901
+ ["INVALID_AMOUNT", "INVALID_AMOUNT"]
902
+ ];
903
+ function failureOf3(status, message) {
904
+ const named = FAILURE_OF.find(([code]) => message.includes(code));
905
+ if (named) return named[1];
906
+ if (status === 422) return "ALREADY_ANSWERED";
907
+ return status === 404 ? "NOT_FOUND" : "REFUSED";
908
+ }
909
+ __name(failureOf3, "failureOf");
910
+ async function answerIfoodDispute(ctx, target, answer) {
911
+ const { path, body } = requestOf(answer);
912
+ const result = await answered(async () => {
913
+ const response = await withIfoodToken(
914
+ ctx,
915
+ (token) => ctx.http({
916
+ method: "POST",
917
+ url: `${IFOOD_API}/order/v1.0/disputes/${encodeURIComponent(target.disputeId)}/${path}`,
918
+ headers: { Authorization: `Bearer ${token}`, ...body === void 0 ? {} : { "Content-Type": "application/json" } },
919
+ ...body === void 0 ? {} : { body: JSON.stringify(body) }
920
+ })
921
+ );
922
+ if (response === null) return { kind: "retry", reason: "iFood refused the token" };
923
+ return "kind" in response ? response : outboundResultOf(response);
924
+ });
925
+ if (result.kind !== "refused") return result;
926
+ return { kind: "refused", status: result.status, message: result.message, code: result.own ? "REFUSED" : failureOf3(result.status, result.message) };
927
+ }
928
+ __name(answerIfoodDispute, "answerIfoodDispute");
929
+ var IFOOD_DISPUTES = { answer: answerIfoodDispute };
930
+
778
931
  // src/ifood/order-details.ts
779
932
  function countOf(source) {
780
933
  const stated = Number(pick(source, "quantity") ?? 1);
@@ -1033,7 +1186,9 @@ function normalizeIfoodEvent(payload, options) {
1033
1186
  cancellationOutcome: cancelled ? "CONFIRMED" : refusedRequest ? "FAILED" : null,
1034
1187
  ...LIFECYCLE_OF[eventType.toUpperCase()] ? { lifecycle: LIFECYCLE_OF[eventType.toUpperCase()] } : {},
1035
1188
  ...optional("courier", readIfoodCourierEvent(payload, eventType) ?? void 0),
1036
- ...ORDER_CONFIRMED.has(eventType.toUpperCase()) ? { marketplaceConfirmed: true } : {}
1189
+ ...ORDER_CONFIRMED.has(eventType.toUpperCase()) ? { marketplaceConfirmed: true } : {},
1190
+ // The Negotiation Platform's HSD / HSS (FUT-6099): a dispute opened or closed, never an order body.
1191
+ ...optional("dispute", readIfoodDispute(payload, eventType) ?? void 0)
1037
1192
  };
1038
1193
  }
1039
1194
  __name(normalizeIfoodEvent, "normalizeIfoodEvent");
@@ -1076,7 +1231,7 @@ function orderOf(body, externalOrderId, missingStreetNumber) {
1076
1231
  return { kind: "order", order: { ...order, externalMerchantId: firstString(parsed2, [["merchant", "id"]]) } };
1077
1232
  }
1078
1233
  __name(orderOf, "orderOf");
1079
- function failureOf3(response) {
1234
+ function failureOf4(response) {
1080
1235
  const message = response.body.slice(0, 300);
1081
1236
  if (response.status === 401 || response.status === 403) {
1082
1237
  return { kind: "refused", status: response.status, message, own: true };
@@ -1085,7 +1240,7 @@ function failureOf3(response) {
1085
1240
  const result = outboundResultOf(response);
1086
1241
  return result.kind === "accepted" ? { kind: "retry", reason: `status ${response.status}` } : result;
1087
1242
  }
1088
- __name(failureOf3, "failureOf");
1243
+ __name(failureOf4, "failureOf");
1089
1244
  async function ifoodFetchOrder(ctx, ref, options) {
1090
1245
  try {
1091
1246
  let answer = await getOrder(ctx, ref.externalOrderId);
@@ -1098,36 +1253,118 @@ async function ifoodFetchOrder(ctx, ref, options) {
1098
1253
  if (response.status >= 200 && response.status < 300) {
1099
1254
  return orderOf(response.body, ref.externalOrderId, options.missingStreetNumber);
1100
1255
  }
1101
- return failureOf3(response);
1256
+ return failureOf4(response);
1102
1257
  } catch (error) {
1103
1258
  return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
1104
1259
  }
1105
1260
  }
1106
1261
  __name(ifoodFetchOrder, "ifoodFetchOrder");
1107
1262
 
1263
+ // src/ifood/app-linking.ts
1264
+ var MERCHANTS_URL = `${IFOOD_API}/merchant/v1.0/merchants`;
1265
+ var MERCHANT_PAGE_SIZE = 100;
1266
+ var MAX_MERCHANT_PAGES = 20;
1267
+ var IFOOD_APPS_PORTAL_URL = "https://portal.ifood.com.br/apps";
1268
+ function json(body) {
1269
+ try {
1270
+ return body === "" ? null : JSON.parse(body);
1271
+ } catch {
1272
+ return null;
1273
+ }
1274
+ }
1275
+ __name(json, "json");
1276
+ var adapterContext = /* @__PURE__ */ __name((ctx) => ({
1277
+ http: ctx.http,
1278
+ credentials: ctx.credentials,
1279
+ environment: ctx.environment,
1280
+ tokens: ctx.tokens,
1281
+ now: ctx.now
1282
+ }), "adapterContext");
1283
+ async function get2(ctx, url, read2) {
1284
+ try {
1285
+ const response = await withIfoodToken(
1286
+ adapterContext(ctx),
1287
+ (token) => ctx.http({ method: "GET", url, headers: { Authorization: `Bearer ${token}` } })
1288
+ );
1289
+ if (response === null) return { kind: "refused", status: 401, message: "iFood refused the app's token" };
1290
+ if ("kind" in response) return response.kind === "accepted" ? { kind: "retry", reason: "no answer" } : response;
1291
+ const result = outboundResultOf(response);
1292
+ if (result.kind !== "accepted") return result;
1293
+ const value = read2(json(response.body));
1294
+ return value === null ? { kind: "refused", status: response.status, message: "iFood's answer is not the documented shape" } : { kind: "ok", value };
1295
+ } catch (error) {
1296
+ return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
1297
+ }
1298
+ }
1299
+ __name(get2, "get");
1300
+ function merchantsOf(body) {
1301
+ if (!Array.isArray(body)) return null;
1302
+ return body.flatMap((raw) => {
1303
+ const id = asString(pick(raw, "id"));
1304
+ return id ? [{ id, name: asString(pick(raw, "name")), corporateName: asString(pick(raw, "corporateName")) }] : [];
1305
+ });
1306
+ }
1307
+ __name(merchantsOf, "merchantsOf");
1308
+ var first = /* @__PURE__ */ __name((raw, ...keys) => {
1309
+ for (const key of keys) {
1310
+ const value = pick(raw, key);
1311
+ const text2 = typeof value === "number" ? String(value) : asString(value);
1312
+ if (text2 && text2.trim() !== "") return text2.trim();
1313
+ }
1314
+ return null;
1315
+ }, "first");
1316
+ function ifoodAddressLine(body) {
1317
+ const address = pick(body, "address");
1318
+ const street = first(address, "street", "streetName");
1319
+ if (!street) return null;
1320
+ const number = first(address, "number", "streetNumber");
1321
+ const district = first(address, "district", "neighborhood");
1322
+ const line = number && !street.includes(number) ? `${street}, ${number}` : street;
1323
+ return district && !line.includes(district) ? `${line} \xB7 ${district}` : line;
1324
+ }
1325
+ __name(ifoodAddressLine, "ifoodAddressLine");
1326
+ async function listMerchants(ctx) {
1327
+ const all = [];
1328
+ for (let page = 1; page <= MAX_MERCHANT_PAGES; page += 1) {
1329
+ const answer = await get2(ctx, `${MERCHANTS_URL}?page=${page}&size=${MERCHANT_PAGE_SIZE}`, merchantsOf);
1330
+ if (answer.kind !== "ok") return answer;
1331
+ all.push(...answer.value);
1332
+ if (answer.value.length < MERCHANT_PAGE_SIZE) break;
1333
+ }
1334
+ return { kind: "ok", value: all };
1335
+ }
1336
+ __name(listMerchants, "listMerchants");
1337
+ var IFOOD_APP_LINKING = {
1338
+ portalUrl: IFOOD_APPS_PORTAL_URL,
1339
+ merchants: listMerchants,
1340
+ address: /* @__PURE__ */ __name((ctx, merchantId) => get2(ctx, `${MERCHANTS_URL}/${encodeURIComponent(merchantId)}`, (body) => body === null ? null : { line: ifoodAddressLine(body) }).then(
1341
+ (answer) => answer.kind === "ok" ? { kind: "ok", value: answer.value.line } : answer
1342
+ ), "address")
1343
+ };
1344
+
1108
1345
  // src/ifood/linking.ts
1109
1346
  var USER_CODE_URL = `${IFOOD_API}/authentication/v1.0/oauth/userCode`;
1110
1347
  var TOKEN_URL2 = `${IFOOD_API}/authentication/v1.0/oauth/token`;
1111
- var MERCHANTS_URL = `${IFOOD_API}/merchant/v1.0/merchants`;
1348
+ var MERCHANTS_URL2 = `${IFOOD_API}/merchant/v1.0/merchants`;
1112
1349
  var USER_CODE_SECONDS = 600;
1113
1350
  var ACCESS_TOKEN_SECONDS = 21600;
1114
- var MERCHANT_PAGE_SIZE = 100;
1115
- var MAX_MERCHANT_PAGES = 20;
1351
+ var MERCHANT_PAGE_SIZE2 = 100;
1352
+ var MAX_MERCHANT_PAGES2 = 20;
1116
1353
  var FORM = { "Content-Type": "application/x-www-form-urlencoded" };
1117
- function json(body) {
1354
+ function json2(body) {
1118
1355
  try {
1119
1356
  return body === "" ? null : JSON.parse(body);
1120
1357
  } catch {
1121
1358
  return null;
1122
1359
  }
1123
1360
  }
1124
- __name(json, "json");
1361
+ __name(json2, "json");
1125
1362
  async function call3(ctx, request, read2) {
1126
1363
  try {
1127
1364
  const response = await ctx.http(request);
1128
1365
  const result = outboundResultOf(response);
1129
1366
  if (result.kind !== "accepted") return result;
1130
- const value = read2(json(response.body));
1367
+ const value = read2(json2(response.body));
1131
1368
  return value === null ? { kind: "refused", status: response.status, message: "iFood's answer is not the documented shape" } : { kind: "ok", value };
1132
1369
  } catch (error) {
1133
1370
  return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
@@ -1156,39 +1393,39 @@ function grantOf(body, requireRefresh) {
1156
1393
  return { accessToken, refreshToken, expiresInSeconds: positive(pick(body, "expiresIn"), ACCESS_TOKEN_SECONDS) };
1157
1394
  }
1158
1395
  __name(grantOf, "grantOf");
1159
- function merchantsOf(body) {
1396
+ function merchantsOf2(body) {
1160
1397
  if (!Array.isArray(body)) return null;
1161
1398
  return body.flatMap((raw) => {
1162
1399
  const id = asString(pick(raw, "id"));
1163
1400
  return id ? [{ id, name: asString(pick(raw, "name")), corporateName: asString(pick(raw, "corporateName")) }] : [];
1164
1401
  });
1165
1402
  }
1166
- __name(merchantsOf, "merchantsOf");
1403
+ __name(merchantsOf2, "merchantsOf");
1167
1404
  var tokenRequest = /* @__PURE__ */ __name((fields) => ({
1168
1405
  method: "POST",
1169
1406
  url: TOKEN_URL2,
1170
1407
  headers: FORM,
1171
1408
  body: new URLSearchParams(fields).toString()
1172
1409
  }), "tokenRequest");
1173
- async function listMerchants(ctx, accessToken) {
1410
+ async function listMerchants2(ctx, accessToken) {
1174
1411
  const all = [];
1175
- for (let page = 1; page <= MAX_MERCHANT_PAGES; page += 1) {
1412
+ for (let page = 1; page <= MAX_MERCHANT_PAGES2; page += 1) {
1176
1413
  const answer = await call3(
1177
1414
  ctx,
1178
1415
  {
1179
1416
  method: "GET",
1180
- url: `${MERCHANTS_URL}?page=${page}&size=${MERCHANT_PAGE_SIZE}`,
1417
+ url: `${MERCHANTS_URL2}?page=${page}&size=${MERCHANT_PAGE_SIZE2}`,
1181
1418
  headers: { Authorization: `Bearer ${accessToken}` }
1182
1419
  },
1183
- merchantsOf
1420
+ merchantsOf2
1184
1421
  );
1185
1422
  if (answer.kind !== "ok") return answer;
1186
1423
  all.push(...answer.value);
1187
- if (answer.value.length < MERCHANT_PAGE_SIZE) break;
1424
+ if (answer.value.length < MERCHANT_PAGE_SIZE2) break;
1188
1425
  }
1189
1426
  return { kind: "ok", value: all };
1190
1427
  }
1191
- __name(listMerchants, "listMerchants");
1428
+ __name(listMerchants2, "listMerchants");
1192
1429
  var IFOOD_LINKING = {
1193
1430
  requestCode: /* @__PURE__ */ __name((ctx) => call3(
1194
1431
  ctx,
@@ -1216,7 +1453,7 @@ var IFOOD_LINKING = {
1216
1453
  }),
1217
1454
  (body) => grantOf(body, false)
1218
1455
  ), "refresh"),
1219
- merchants: /* @__PURE__ */ __name((ctx, input) => listMerchants(ctx, input.accessToken), "merchants")
1456
+ merchants: /* @__PURE__ */ __name((ctx, input) => listMerchants2(ctx, input.accessToken), "merchants")
1220
1457
  };
1221
1458
 
1222
1459
  // src/ifood/pause.ts
@@ -1509,7 +1746,9 @@ function createIfoodAdapter(config) {
1509
1746
  // CFM: the store accepted on iFood's own app (FUT-5653).
1510
1747
  marketplaceConfirms: true,
1511
1748
  // A step is told only once iFood took the confirm (FUT-5673).
1512
- statusAfterConfirm: true
1749
+ statusAfterConfirm: true,
1750
+ // The Negotiation Platform (FUT-6099): HSD / HSS events, answered through `disputes`.
1751
+ disputes: true
1513
1752
  },
1514
1753
  normalize: /* @__PURE__ */ __name((payload) => normalizeIfoodEvent(payload, normalizeOptions), "normalize"),
1515
1754
  readSignature: /* @__PURE__ */ __name((header) => header("x-ifood-signature") ?? header("x-signature"), "readSignature"),
@@ -1532,10 +1771,16 @@ function createIfoodAdapter(config) {
1532
1771
  orderCancellationReasons: ifoodOrderCancellationReasons,
1533
1772
  // The Merchant API's interruptions: an id and an end per closure (FUT-4851).
1534
1773
  availability: IFOOD_AVAILABILITY,
1535
- // The distributed-app authorization: a store links the software's own app (FUT-5613).
1774
+ // The CENTRALIZED app (FUT-5798): a store authorizes the software's app on the portal and picks
1775
+ // its store from the app's list; iFood's webhook serves centralized apps only. It wins at every
1776
+ // entry point. The distributed half (FUT-5613) stays declared: a store linked through it keeps
1777
+ // refreshing its own token until it links again.
1778
+ appLinking: IFOOD_APP_LINKING,
1536
1779
  linking: IFOOD_LINKING,
1537
1780
  // iFood's fleet: the pickup-code check and the courier's tracking (FUT-5665).
1538
1781
  courier: IFOOD_COURIER,
1782
+ // The buyer's disputes: accept, reject with iFood's reason, or one of its alternatives (FUT-6099).
1783
+ disputes: IFOOD_DISPUTES,
1539
1784
  // No per-order deep link is known, so the portal, where a live order is
1540
1785
  // on the first screen.
1541
1786
  appLink: /* @__PURE__ */ __name(() => IFOOD_PORTAL_URL, "appLink")
@@ -1543,6 +1788,8 @@ function createIfoodAdapter(config) {
1543
1788
  }
1544
1789
  __name(createIfoodAdapter, "createIfoodAdapter");
1545
1790
  export {
1791
+ IFOOD_APPS_PORTAL_URL,
1792
+ IFOOD_APP_LINKING,
1546
1793
  IFOOD_AVAILABILITY,
1547
1794
  IFOOD_CANCELLATION_ANSWER_WINDOW_MS,
1548
1795
  IFOOD_CATALOGUE,
@@ -1555,6 +1802,7 @@ export {
1555
1802
  IFOOD_PROVIDER,
1556
1803
  IFOOD_REASON_CODES,
1557
1804
  createIfoodAdapter,
1805
+ ifoodAddressLine,
1558
1806
  ifoodFetchOrder,
1559
1807
  ifoodItemBody,
1560
1808
  ifoodItemId,