@12-apps/marketplace 1.3.0 → 1.5.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 (59) hide show
  1. package/ADOPTING.md +47 -0
  2. package/README.md +122 -1
  3. package/dist/99food/index.d.ts +33 -2
  4. package/dist/99food/index.js +34 -2
  5. package/dist/99food/index.js.map +1 -1
  6. package/dist/{adapter-0l_EmuJA.d.ts → adapter-CCWMqt2g.d.ts} +275 -3
  7. package/dist/{chunk-XUAFXNOH.js → chunk-FKUEFVVA.js} +396 -4
  8. package/dist/chunk-FKUEFVVA.js.map +1 -0
  9. package/dist/{chunk-RVBTARIY.js → chunk-RGMSD7S7.js} +1 -1
  10. package/dist/chunk-RGMSD7S7.js.map +1 -0
  11. package/dist/{chunk-AYYBRQJV.js → chunk-UONWZIBO.js} +43 -3
  12. package/dist/chunk-UONWZIBO.js.map +1 -0
  13. package/dist/chunk-WN2EK4KX.js +15 -0
  14. package/dist/chunk-WN2EK4KX.js.map +1 -0
  15. package/dist/{engine-CZsP8KWd.d.ts → engine-C3uq_BJd.d.ts} +252 -2
  16. package/dist/hono/index.d.ts +2 -2
  17. package/dist/hono/index.js +2 -2
  18. package/dist/ifood/index.d.ts +44 -2
  19. package/dist/ifood/index.js +441 -1
  20. package/dist/ifood/index.js.map +1 -1
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +342 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/manifest/server.d.ts +4 -2
  25. package/dist/manifest/server.js +2 -2
  26. package/dist/rappi/index.d.ts +15 -2
  27. package/dist/rappi/index.js +56 -2
  28. package/dist/rappi/index.js.map +1 -1
  29. package/dist/server/index.d.ts +18 -7
  30. package/dist/server/index.js +4 -2
  31. package/package.json +1 -1
  32. package/prisma/marketplace.prisma +67 -1
  33. package/prisma/migrations/20261113230000_marketplace_store_pause/migration.sql +70 -0
  34. package/src/99food/index.ts +10 -0
  35. package/src/99food/pause.ts +56 -0
  36. package/src/core/adapter.ts +19 -2
  37. package/src/core/catalogue-read-port.ts +151 -0
  38. package/src/core/catalogue-read.ts +51 -0
  39. package/src/core/engine.ts +46 -0
  40. package/src/core/pause-job.ts +381 -0
  41. package/src/core/pause-port.ts +110 -0
  42. package/src/core/pause-retired.ts +139 -0
  43. package/src/core/pause-store.ts +151 -0
  44. package/src/core/pause-sweep.ts +148 -0
  45. package/src/core/pause.ts +316 -0
  46. package/src/core/ports.ts +11 -0
  47. package/src/ifood/catalogue-read.ts +187 -0
  48. package/src/ifood/catalogue-snapshot.ts +246 -0
  49. package/src/ifood/index.ts +9 -0
  50. package/src/ifood/pause.ts +257 -0
  51. package/src/index.ts +39 -0
  52. package/src/rappi/index.ts +11 -0
  53. package/src/rappi/outbound.ts +2 -2
  54. package/src/rappi/pause.ts +98 -0
  55. package/src/server/index.ts +1 -0
  56. package/src/server/jobs.ts +64 -4
  57. package/dist/chunk-AYYBRQJV.js.map +0 -1
  58. package/dist/chunk-RVBTARIY.js.map +0 -1
  59. package/dist/chunk-XUAFXNOH.js.map +0 -1
@@ -1,3 +1,6 @@
1
+ import {
2
+ centsFromMajor
3
+ } from "../chunk-WN2EK4KX.js";
1
4
  import {
2
5
  stableUuid
3
6
  } from "../chunk-M2V4RFMA.js";
@@ -12,7 +15,7 @@ import {
12
15
  import {
13
16
  answered,
14
17
  outboundResultOf
15
- } from "../chunk-RVBTARIY.js";
18
+ } from "../chunk-RGMSD7S7.js";
16
19
  import {
17
20
  __name
18
21
  } from "../chunk-7QVYU63E.js";
@@ -269,6 +272,276 @@ var IFOOD_CATALOGUE = {
269
272
  withdrawItem: /* @__PURE__ */ __name((ctx, item) => answered(() => withdraw(ctx, item)), "withdrawItem")
270
273
  };
271
274
 
275
+ // src/ifood/catalogue-snapshot.ts
276
+ var IFOOD_IMAGE_BASE_URL = "https://static-images.ifood.com.br/image/upload/t_high/pratos/";
277
+ var record = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : null, "record");
278
+ var text = /* @__PURE__ */ __name((value) => typeof value === "string" && value.trim() !== "" ? value.trim() : null, "text");
279
+ function entriesOf(value) {
280
+ const entries = [];
281
+ const others = [];
282
+ for (const entry of Array.isArray(value) ? value : []) {
283
+ const object = record(entry);
284
+ if (object) entries.push(object);
285
+ else others.push(entry);
286
+ }
287
+ return { entries, others };
288
+ }
289
+ __name(entriesOf, "entriesOf");
290
+ var list = /* @__PURE__ */ __name((value) => entriesOf(value).entries, "list");
291
+ var availableOf = /* @__PURE__ */ __name((status) => status !== "UNAVAILABLE", "availableOf");
292
+ var byId = /* @__PURE__ */ __name((entries) => new Map(entries.flatMap((entry) => text(entry.id) ? [[text(entry.id), entry]] : [])), "byId");
293
+ function indexOf(answer) {
294
+ return { products: byId(list(answer.products)), optionGroups: byId(list(answer.optionGroups)), options: byId(list(answer.options)) };
295
+ }
296
+ __name(indexOf, "indexOf");
297
+ var priceCentsOf = /* @__PURE__ */ __name((price) => centsFromMajor(record(price)?.value), "priceCentsOf");
298
+ var warning = /* @__PURE__ */ __name((code, subject, detail = null) => ({
299
+ code,
300
+ subject,
301
+ detail: detail === null || detail === void 0 ? null : JSON.stringify(detail)
302
+ }), "warning");
303
+ function photoOf(imagePath, subject) {
304
+ if (imagePath === void 0 || imagePath === null || imagePath === "") return { url: null };
305
+ const path = text(imagePath);
306
+ if (path === null) return { url: null, warning: warning("PHOTO_UNREADABLE", subject, imagePath) };
307
+ if (/^https:\/\//i.test(path)) return { url: path };
308
+ if (/^[a-z][a-z0-9+.-]*:/i.test(path)) return { url: null, warning: warning("PHOTO_UNREADABLE", subject, path) };
309
+ return { url: `${IFOOD_IMAGE_BASE_URL}${urlSafePath(path.replace(/^\/+/, ""))}` };
310
+ }
311
+ __name(photoOf, "photoOf");
312
+ function urlSafePath(path) {
313
+ return path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25").replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@/%]/g, (character) => encodeURIComponent(character));
314
+ }
315
+ __name(urlSafePath, "urlSafePath");
316
+ function describedBy(index, own) {
317
+ const product = index.products.get(text(own.productId) ?? "") ?? {};
318
+ return {
319
+ name: text(product.name) ?? text(own.name),
320
+ description: text(product.description) ?? text(own.description),
321
+ externalCode: text(own.externalCode) ?? text(product.externalCode),
322
+ imagePath: product.imagePath ?? own.imagePath
323
+ };
324
+ }
325
+ __name(describedBy, "describedBy");
326
+ function photoInto(imagePath, subject, warnings) {
327
+ const photo = photoOf(imagePath, subject);
328
+ if (photo.warning) warnings.push(photo.warning);
329
+ return photo.url;
330
+ }
331
+ __name(photoInto, "photoInto");
332
+ function optionOf(id, index, warnings) {
333
+ const option = index.options.get(id);
334
+ const described = option ? describedBy(index, option) : null;
335
+ if (!option || !described || described.name === null) {
336
+ warnings.push(warning("OPTION_UNREADABLE", id, option));
337
+ return null;
338
+ }
339
+ const priceDeltaCents = priceCentsOf(option.price);
340
+ if (priceDeltaCents === null) warnings.push(warning("OPTION_PRICE_MISSING", id, option.price));
341
+ return {
342
+ externalId: id,
343
+ externalCode: described.externalCode,
344
+ name: described.name,
345
+ description: described.description,
346
+ priceDeltaCents,
347
+ photoUrl: photoInto(described.imagePath, id, warnings),
348
+ available: availableOf(option.status)
349
+ };
350
+ }
351
+ __name(optionOf, "optionOf");
352
+ function boundsOf(link, group) {
353
+ const min = link.min ?? group.min ?? 0;
354
+ const max = link.max ?? group.max;
355
+ if (!Number.isInteger(min) || !Number.isInteger(max)) return null;
356
+ const [low, high] = [min, max];
357
+ return low >= 0 && high >= 1 && high >= low ? { min: low, max: high } : null;
358
+ }
359
+ __name(boundsOf, "boundsOf");
360
+ function idsOf(groupId, value, warnings) {
361
+ const ids = [];
362
+ for (const entry of Array.isArray(value) ? value : []) {
363
+ const id = text(entry);
364
+ if (id === null) warnings.push(warning("OPTION_UNREADABLE", groupId, entry));
365
+ else ids.push(id);
366
+ }
367
+ return ids;
368
+ }
369
+ __name(idsOf, "idsOf");
370
+ function groupOf(link, index, warnings) {
371
+ const id = text(link.id);
372
+ const group = id === null ? void 0 : index.optionGroups.get(id);
373
+ const bounds = group ? boundsOf(link, group) : null;
374
+ const name = text(group?.name);
375
+ if (id === null || !group || name === null || bounds === null) {
376
+ warnings.push(warning("OPTION_GROUP_UNREADABLE", id, { link, group }));
377
+ return null;
378
+ }
379
+ const options = idsOf(id, group.optionIds, warnings).flatMap((optionId) => optionOf(optionId, index, warnings) ?? []);
380
+ if (options.length === 0) {
381
+ warnings.push(warning("OPTION_GROUP_UNREADABLE", id, "no readable option"));
382
+ return null;
383
+ }
384
+ return { externalId: id, externalCode: text(group.externalCode), name, ...bounds, available: availableOf(group.status), options };
385
+ }
386
+ __name(groupOf, "groupOf");
387
+ function itemWarnings(raw, priceCents) {
388
+ const warnings = [];
389
+ const type = text(raw.type);
390
+ if (type !== null && type !== "DEFAULT") warnings.push(warning("ITEM_TYPE_UNSUPPORTED", null, type));
391
+ if (priceCents === null) warnings.push(warning("PRICE_MISSING", null, raw.price));
392
+ return warnings;
393
+ }
394
+ __name(itemWarnings, "itemWarnings");
395
+ function linksOf(index, raw, warnings) {
396
+ const product = index.products.get(text(raw.productId) ?? "");
397
+ const value = product?.optionGroups ?? raw.optionGroups;
398
+ if (value !== void 0 && value !== null && !Array.isArray(value)) warnings.push(warning("OPTION_GROUP_UNREADABLE", null, value));
399
+ const { entries, others } = entriesOf(value);
400
+ for (const other of others) warnings.push(warning("OPTION_GROUP_UNREADABLE", null, other));
401
+ return entries;
402
+ }
403
+ __name(linksOf, "linksOf");
404
+ function itemOf(raw, index, categoryId2) {
405
+ const id = text(raw.id);
406
+ const described = describedBy(index, raw);
407
+ if (id === null || described.name === null) {
408
+ return { code: "ITEM_UNREADABLE", categoryExternalId: categoryId2, externalId: id, detail: JSON.stringify(raw).slice(0, 300) };
409
+ }
410
+ const priceCents = priceCentsOf(raw.price);
411
+ const warnings = itemWarnings(raw, priceCents);
412
+ const photoUrl = photoInto(described.imagePath, null, warnings);
413
+ const optionGroups = linksOf(index, raw, warnings).flatMap((link) => groupOf(link, index, warnings) ?? []);
414
+ return {
415
+ externalId: id,
416
+ externalCode: described.externalCode,
417
+ name: described.name,
418
+ description: described.description,
419
+ priceCents,
420
+ photoUrl,
421
+ available: availableOf(raw.status),
422
+ optionGroups,
423
+ warnings
424
+ };
425
+ }
426
+ __name(itemOf, "itemOf");
427
+
428
+ // src/ifood/catalogue-read.ts
429
+ var catalogUrl2 = /* @__PURE__ */ __name((merchantId, path) => `${IFOOD_API}/catalog/v2.0/merchants/${encodeURIComponent(merchantId)}/${path}`, "catalogUrl");
430
+ function tokenFailure(result) {
431
+ if (result.kind === "refused") return { kind: "refused", code: "CREDENTIALS", status: result.status, message: result.message };
432
+ return { kind: "retry", reason: result.kind === "retry" ? result.reason : "unexpected token answer" };
433
+ }
434
+ __name(tokenFailure, "tokenFailure");
435
+ function failureOf2(response) {
436
+ const result = outboundResultOf(response);
437
+ if (result.kind !== "refused") return { kind: "retry", reason: result.kind === "retry" ? result.reason : "unexpected answer" };
438
+ const code = response.status === 403 || response.status === 404 ? "NOT_AUTHORIZED" : "REFUSED";
439
+ return { kind: "refused", code, status: result.status, message: result.message };
440
+ }
441
+ __name(failureOf2, "failureOf");
442
+ async function get(ctx, path) {
443
+ for (let attempt = 0; attempt < 2; attempt += 1) {
444
+ const auth = await bearer(ctx);
445
+ if (!("token" in auth)) return tokenFailure(auth);
446
+ const response = await ctx.http({
447
+ method: "GET",
448
+ url: catalogUrl2(ctx.externalMerchantId, path),
449
+ headers: { Authorization: `Bearer ${auth.token}`, Accept: "application/json" }
450
+ });
451
+ if (response.status !== 401) return response;
452
+ ctx.tokens.delete(ifoodTokenKey(ctx));
453
+ }
454
+ return { kind: "retry", reason: "iFood refused a fresh token" };
455
+ }
456
+ __name(get, "get");
457
+ var ok2 = /* @__PURE__ */ __name((response) => response.status >= 200 && response.status < 300, "ok");
458
+ function parse2(body) {
459
+ try {
460
+ return JSON.parse(body);
461
+ } catch {
462
+ return null;
463
+ }
464
+ }
465
+ __name(parse2, "parse");
466
+ var unexpected = /* @__PURE__ */ __name((what, body) => ({
467
+ kind: "refused",
468
+ code: "REFUSED",
469
+ status: 200,
470
+ message: `unexpected ${what} answer: ${body.slice(0, 200)}`
471
+ }), "unexpected");
472
+ async function categoryOf(ctx, raw, notices) {
473
+ const id = text(raw.id);
474
+ const name = text(raw.name);
475
+ if (id === null || name === null) {
476
+ notices.push(unreadableCategory(id, raw));
477
+ return null;
478
+ }
479
+ const answered2 = await get(ctx, `categories/${encodeURIComponent(id)}/items`);
480
+ if ("kind" in answered2) return answered2;
481
+ if (answered2.status === 404) {
482
+ notices.push(unreadableCategory(id, "its items answered 404"));
483
+ return null;
484
+ }
485
+ if (!ok2(answered2)) return failureOf2(answered2);
486
+ const items = itemsOf(answered2.body, id, notices);
487
+ return items && { externalId: id, externalCode: text(raw.externalCode), name, available: availableOf(raw.status), items };
488
+ }
489
+ __name(categoryOf, "categoryOf");
490
+ var unreadableCategory = /* @__PURE__ */ __name((categoryExternalId, detail) => ({
491
+ code: "CATEGORY_UNREADABLE",
492
+ categoryExternalId,
493
+ externalId: null,
494
+ detail: (typeof detail === "string" ? detail : JSON.stringify(detail) ?? String(detail)).slice(0, 300)
495
+ }), "unreadableCategory");
496
+ function itemsOf(rawBody, categoryId2, notices) {
497
+ const body = record(parse2(rawBody));
498
+ if (!body || !Array.isArray(body.items)) {
499
+ notices.push(unreadableCategory(categoryId2, `unexpected items answer: ${rawBody}`));
500
+ return null;
501
+ }
502
+ const index = indexOf(body);
503
+ const { entries, others } = entriesOf(body.items);
504
+ for (const other of others) {
505
+ notices.push({ code: "ITEM_UNREADABLE", categoryExternalId: categoryId2, externalId: null, detail: String(JSON.stringify(other)).slice(0, 300) });
506
+ }
507
+ const items = [];
508
+ for (const entry of entries) {
509
+ const mapped = itemOf(entry, index, categoryId2);
510
+ if ("code" in mapped) notices.push(mapped);
511
+ else items.push(mapped);
512
+ }
513
+ return items;
514
+ }
515
+ __name(itemsOf, "itemsOf");
516
+ async function read(ctx) {
517
+ const listed = await get(ctx, "categories");
518
+ if ("kind" in listed) return listed;
519
+ if (!ok2(listed)) return failureOf2(listed);
520
+ const parsed = parse2(listed.body);
521
+ if (!Array.isArray(parsed)) return unexpected("category list", listed.body);
522
+ const categories = [];
523
+ const notices = [];
524
+ const { entries, others } = entriesOf(parsed);
525
+ for (const other of others) notices.push(unreadableCategory(null, other));
526
+ for (const raw of entries) {
527
+ const category = await categoryOf(ctx, raw, notices);
528
+ if (category === null) continue;
529
+ if ("kind" in category) return category;
530
+ categories.push(category);
531
+ }
532
+ return { kind: "snapshot", snapshot: { categories, notices } };
533
+ }
534
+ __name(read, "read");
535
+ var IFOOD_CATALOGUE_READER = {
536
+ read: /* @__PURE__ */ __name(async (ctx) => {
537
+ try {
538
+ return await read(ctx);
539
+ } catch (error) {
540
+ return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
541
+ }
542
+ }, "read")
543
+ };
544
+
272
545
  // src/ifood/normalize.ts
273
546
  var ORDER_PLACED = /* @__PURE__ */ new Set(["PLC", "PLACED", "ORDER_PLACED"]);
274
547
  var ORDER_CANCELLED = /* @__PURE__ */ new Set(["CAN", "CANCELLED", "ORDER_CANCELLED"]);
@@ -383,6 +656,163 @@ function normalizeIfoodEvent(payload, options) {
383
656
  }
384
657
  __name(normalizeIfoodEvent, "normalizeIfoodEvent");
385
658
 
659
+ // src/ifood/pause.ts
660
+ var interruptionsUrl = /* @__PURE__ */ __name((merchantId) => `${IFOOD_API}/merchant/v1.0/merchants/${encodeURIComponent(merchantId)}/interruptions`, "interruptionsUrl");
661
+ async function call2(ctx, request) {
662
+ const auth = await bearer(ctx);
663
+ if (!("token" in auth)) return auth.kind === "accepted" ? { kind: "retry", reason: "unexpected token answer" } : auth;
664
+ const response = await ctx.http({
665
+ method: request.method,
666
+ url: request.url,
667
+ headers: {
668
+ Authorization: `Bearer ${auth.token}`,
669
+ ...request.json === void 0 ? {} : { "Content-Type": "application/json" }
670
+ },
671
+ ...request.json === void 0 ? {} : { body: JSON.stringify(request.json) }
672
+ });
673
+ if (response.status !== 401) return response;
674
+ ctx.tokens.delete(ifoodTokenKey(ctx));
675
+ return { kind: "retry", reason: "iFood refused the token" };
676
+ }
677
+ __name(call2, "call");
678
+ var settled = /* @__PURE__ */ __name((value) => "kind" in value, "settled");
679
+ function notOk(response) {
680
+ const result = outboundResultOf(response);
681
+ return result.kind === "accepted" ? null : result;
682
+ }
683
+ __name(notOk, "notOk");
684
+ async function listInterruptions(ctx, merchantId) {
685
+ const response = await call2(ctx, { method: "GET", url: interruptionsUrl(merchantId) });
686
+ if (settled(response)) return response;
687
+ const failure = notOk(response);
688
+ if (failure) return failure;
689
+ try {
690
+ const parsed = JSON.parse(response.body === "" ? "[]" : response.body);
691
+ if (!Array.isArray(parsed)) return [];
692
+ return parsed.flatMap((entry) => {
693
+ const value = entry ?? {};
694
+ if (typeof value.id !== "string") return [];
695
+ return [
696
+ {
697
+ id: value.id,
698
+ end: typeof value.end === "string" ? value.end : null,
699
+ description: typeof value.description === "string" ? value.description : null
700
+ }
701
+ ];
702
+ });
703
+ } catch {
704
+ return { kind: "retry", reason: "iFood answered the interruption list with something that is not JSON" };
705
+ }
706
+ }
707
+ __name(listInterruptions, "listInterruptions");
708
+ function sameEnd(end, until, timeZone) {
709
+ const sent = ifoodLocalTime(until, timeZone);
710
+ if (end === sent) return true;
711
+ if (/(?:[zZ]|[+-]\d{2}:?\d{2})$/u.test(end)) {
712
+ const parsed = Date.parse(end);
713
+ return !Number.isNaN(parsed) && Math.floor(parsed / 1e3) === Math.floor(until.getTime() / 1e3);
714
+ }
715
+ return end.slice(0, 19) === sent.slice(0, 19);
716
+ }
717
+ __name(sameEnd, "sameEnd");
718
+ function ours(list2, key, sent, keep = []) {
719
+ const candidates = list2.filter((entry) => !keep.includes(entry.id));
720
+ const byKey = candidates.find((entry) => entry.id === key);
721
+ if (byKey || !sent) return byKey;
722
+ return candidates.find(
723
+ (entry) => entry.description === sent.reason && entry.end !== null && sameEnd(entry.end, sent.until, sent.timeZone)
724
+ );
725
+ }
726
+ __name(ours, "ours");
727
+ function wallClock(date, timeZone) {
728
+ const format = new Intl.DateTimeFormat("en-US", {
729
+ timeZone,
730
+ hourCycle: "h23",
731
+ year: "numeric",
732
+ month: "2-digit",
733
+ day: "2-digit",
734
+ hour: "2-digit",
735
+ minute: "2-digit",
736
+ second: "2-digit"
737
+ });
738
+ const clock = { year: 0, month: 1, day: 1, hour: 0, minute: 0, second: 0 };
739
+ for (const part of format.formatToParts(date)) {
740
+ if (part.type in clock) clock[part.type] = Number(part.value);
741
+ }
742
+ return clock;
743
+ }
744
+ __name(wallClock, "wallClock");
745
+ var pad = /* @__PURE__ */ __name((value, width = 2) => String(value).padStart(width, "0"), "pad");
746
+ function ifoodLocalTime(date, timeZone) {
747
+ const local = wallClock(date, timeZone);
748
+ const asUtc = Date.UTC(local.year, local.month - 1, local.day, local.hour, local.minute, local.second);
749
+ const offset = Math.round((asUtc - Math.floor(date.getTime() / 1e3) * 1e3) / 6e4);
750
+ const abs = Math.abs(offset);
751
+ return `${pad(local.year, 4)}-${pad(local.month)}-${pad(local.day)}T${pad(local.hour)}:${pad(local.minute)}:${pad(local.second)}${offset < 0 ? "-" : "+"}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
752
+ }
753
+ __name(ifoodLocalTime, "ifoodLocalTime");
754
+ function createdId(body, sent) {
755
+ try {
756
+ const id = JSON.parse(body).id;
757
+ return typeof id === "string" && id !== "" ? id : sent;
758
+ } catch {
759
+ return sent;
760
+ }
761
+ }
762
+ __name(createdId, "createdId");
763
+ function ifoodPause(ctx, request) {
764
+ return answeredPause(async () => {
765
+ const list2 = await listInterruptions(ctx, request.merchantId);
766
+ if (!Array.isArray(list2)) return list2;
767
+ const landed = ours(list2, request.key, { until: request.until, reason: request.reason, timeZone: request.timeZone }, request.keep);
768
+ if (landed) return { kind: "paused", externalId: landed.id, until: request.until };
769
+ const response = await call2(ctx, {
770
+ method: "POST",
771
+ url: interruptionsUrl(request.merchantId),
772
+ json: {
773
+ id: request.key,
774
+ description: request.reason,
775
+ start: ifoodLocalTime(ctx.now, request.timeZone),
776
+ end: ifoodLocalTime(request.until, request.timeZone)
777
+ }
778
+ });
779
+ if (settled(response)) return response;
780
+ const failure = notOk(response);
781
+ if (failure) return failure;
782
+ return { kind: "paused", externalId: createdId(response.body, request.key), until: request.until };
783
+ });
784
+ }
785
+ __name(ifoodPause, "ifoodPause");
786
+ function ifoodResume(ctx, ref) {
787
+ return answered(async () => {
788
+ let id = ref.externalId;
789
+ if (id === null && ref.key !== null) {
790
+ const list2 = await listInterruptions(ctx, ref.merchantId);
791
+ if (!Array.isArray(list2)) return list2;
792
+ id = ours(list2, ref.key, ref.sent, ref.keep)?.id ?? null;
793
+ }
794
+ if (id === null) return { kind: "accepted" };
795
+ const response = await call2(ctx, { method: "DELETE", url: `${interruptionsUrl(ref.merchantId)}/${encodeURIComponent(id)}` });
796
+ if (settled(response)) return response;
797
+ if (response.status === 404) return { kind: "accepted" };
798
+ return outboundResultOf(response);
799
+ });
800
+ }
801
+ __name(ifoodResume, "ifoodResume");
802
+ async function answeredPause(run) {
803
+ try {
804
+ return await run();
805
+ } catch (error) {
806
+ return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
807
+ }
808
+ }
809
+ __name(answeredPause, "answeredPause");
810
+ var IFOOD_AVAILABILITY = {
811
+ kind: "interruption",
812
+ pause: ifoodPause,
813
+ resume: ifoodResume
814
+ };
815
+
386
816
  // src/ifood/index.ts
387
817
  var IFOOD_PROVIDER = "IFOOD";
388
818
  var ITEM_UNAVAILABLE = "503";
@@ -417,8 +847,12 @@ function createIfoodAdapter(config) {
417
847
  cancellationReasons: /* @__PURE__ */ __name(() => reasons, "cancellationReasons"),
418
848
  // The Catalog API v2.0: each item is written and paused through the API (FUT-4768).
419
849
  catalogue: IFOOD_CATALOGUE,
850
+ // The same API read back: the menu the store keeps on iFood, for the host to import (FUT-951).
851
+ catalogueReader: IFOOD_CATALOGUE_READER,
420
852
  confirm: /* @__PURE__ */ __name((ctx, order) => ifoodConfirm(ctx, order), "confirm"),
421
853
  requestCancellation: ifoodRequestCancellation,
854
+ // The Merchant API's interruptions: an id and an end per closure (FUT-4851).
855
+ availability: IFOOD_AVAILABILITY,
422
856
  // No per-order deep link is known, so the portal, where a live order is
423
857
  // on the first screen.
424
858
  appLink: /* @__PURE__ */ __name(() => IFOOD_PORTAL_URL, "appLink")
@@ -426,14 +860,20 @@ function createIfoodAdapter(config) {
426
860
  }
427
861
  __name(createIfoodAdapter, "createIfoodAdapter");
428
862
  export {
863
+ IFOOD_AVAILABILITY,
429
864
  IFOOD_CANCELLATION_ANSWER_WINDOW_MS,
430
865
  IFOOD_CATALOGUE,
866
+ IFOOD_CATALOGUE_READER,
867
+ IFOOD_IMAGE_BASE_URL,
431
868
  IFOOD_PROVIDER,
432
869
  IFOOD_REASON_CODES,
433
870
  createIfoodAdapter,
434
871
  ifoodItemBody,
435
872
  ifoodItemId,
873
+ ifoodLocalTime,
874
+ ifoodPause,
436
875
  ifoodProductId,
876
+ ifoodResume,
437
877
  normalizeIfoodEvent,
438
878
  verifyIfoodSignature
439
879
  };