@12-apps/marketplace 1.18.0 → 1.18.1

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/README.md CHANGED
@@ -111,8 +111,8 @@ there, chosen in the adapter's code and marked so beside it.
111
111
  |---|---|
112
112
  | Base `https://merchant-api.ifood.com.br/catalog/v2.0/merchants/{merchantId}/…`; bearer token from the same OAuth grant as orders | CONFIRMED — [Introduction](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/introduction) |
113
113
  | Hierarchy catalog → context (DEFAULT delivery, WHITELABEL, INDOOR) → category → item → products / option groups / options; each level has its own status | CONFIRMED — [Fundamentals](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/fundamentals) |
114
- | `GET /catalogs`; `GET /categories` (`?include_items=true`); `POST /categories` `{ name, status, template: "DEFAULT" }` → `{ id, … }` | CONFIRMED — [Endpoints](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/endpoints) |
115
- | `PUT /items` with `item`, `products`, `optionGroups`, `options` (all four always sent) creates or REPLACES the whole item; the item appears at once (synchronous) | CONFIRMED — Introduction, Endpoints |
114
+ | `GET /catalogs` answers `[{ catalogId, context: ["DEFAULT"], status, … }]`; the categories live UNDER a catalog: `GET /catalogs/{catalogId}/categories` and `POST /catalogs/{catalogId}/categories` `{ name, status, template: "DEFAULT" }` → `{ id, … }`. There is no merchant-level `/categories` route: iFood answers it 404 `no Route matched with those values` (FUT-6146). The adapter works in the catalog whose `context` holds `DEFAULT`; a merchant with none is refused | CONFIRMED — live against iFood's sandbox, 2026-12-03 (FUT-6146: `/categories` 404, `/catalogs` 200, `/catalogs/{catalogId}/categories` 200); the same paths in the public [golang-ifood-sdk](https://pkg.go.dev/github.com/arxdsilva/golang-ifood-sdk@v1.1.1/services/catalog) (`category.go`) |
115
+ | `PUT /items` with `item`, `products`, `optionGroups`, `options` (all four always sent) creates or REPLACES the whole item; the item appears at once (synchronous). Merchant-level, not under a catalog, as are `PATCH /items/status` and `POST /image/upload` | CONFIRMED — Introduction, Endpoints |
116
116
  | `item.id` and `products[].id` are UUID v4 the software generates (another shape answers 404); `externalCode` is the software's code, unique per merchant (409 when reused); `status` AVAILABLE / UNAVAILABLE; `price` `{ value, originalValue? }` in the major unit | CONFIRMED — Fundamentals, Introduction |
117
117
  | `PATCH /items/status` `{ itemId, status }` and `PATCH /items/price` `{ itemId, price }`, synchronous; the batch forms (`/products/status`, `/products/price`) answer a `batchId` and run asynchronously | CONFIRMED — Endpoints, [Errors](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/errors-and-troubleshooting) |
118
118
  | `POST /image/upload` `{ image: "data:image/png;base64,…" }` → `{ imagePath }`, reusable across items; jpg/jpeg/png, at most 5 MB (413 above) | CONFIRMED — Endpoints, Errors |
@@ -187,7 +187,7 @@ const result = await engine.readCatalogue({ clientId, provider: "IFOOD" });
187
187
  | **The snapshot** | `categories[]` → `items[]`, each with `externalId`, `externalCode`, `name`, `description`, `priceCents` (null when none), `photoUrl` (absolute, or null), `available`, `optionGroups[]` (`name`, `min`, `max`, `options[]` with `name`, `priceDeltaCents`, `photoUrl`, `available`) and `warnings[]`. Sizes, flavours and add-ons are all option groups. |
188
188
  | **Money** | Integer cents of the menu's currency, `centsFromMajor(value)`: cut to 12 significant digits (no float error), then rounded half up to the cent (`1.005` → 101). A negative or non-numeric price is no price. |
189
189
  | **Nothing dropped silently** | A field that cannot be mapped is a warning on its item (`PRICE_MISSING`, `OPTION_PRICE_MISSING`, `OPTION_GROUP_UNREADABLE`, `OPTION_UNREADABLE`, `PHOTO_UNREADABLE`, `ITEM_TYPE_UNSUPPORTED`), naming the group or option; an item or category that cannot be read at all is a notice on the snapshot (`ITEM_UNREADABLE`, `CATEGORY_UNREADABLE`). Codes are vocabulary: the host words them. |
190
- | **Failures** | Before any call the engine refuses `UNSUPPORTED` (no reader), `NOT_CONNECTED` (no live connection with a merchant id), `CREDENTIALS` (none on file, or they do not open), with `status`/`message` null. From the marketplace: `CREDENTIALS` (the token grant refused), `NOT_AUTHORIZED` (this app may not read this merchant), `REFUSED` (another final 4xx, or a category list that is not a list), or `retry`. One category answered in an unexpected shape is a `CATEGORY_UNREADABLE` notice, and the rest of the menu is still read. |
190
+ | **Failures** | Before any call the engine refuses `UNSUPPORTED` (no reader), `NOT_CONNECTED` (no live connection with a merchant id), `CREDENTIALS` (none on file, or they do not open), with `status`/`message` null. From the marketplace: `CREDENTIALS` (the token grant refused), `NOT_AUTHORIZED` (this app may not read this merchant), `REFUSED` (another final 4xx, a 404 included, a catalog list with no DEFAULT catalog, or a category list that is not a list), or `retry`. One category answered in an unexpected shape is a `CATEGORY_UNREADABLE` notice, and the rest of the menu is still read. |
191
191
 
192
192
  **iFood** (`src/ifood/catalogue-read.ts`, `src/ifood/catalogue-snapshot.ts`).
193
193
  Read 2026-11-16: the Catalog module's Introduction was read whole; its
@@ -198,8 +198,8 @@ reader that day, so what they would settle is ESTIMATED below (the push's
198
198
  | fact | status |
199
199
  |---|---|
200
200
  | Same base and bearer token as the push: `https://merchant-api.ifood.com.br/catalog/v2.0/merchants/{merchantId}/…`, client-credentials grant of the store's own app | CONFIRMED — [Introduction](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/introduction) |
201
- | `GET /categories` lists the merchant's categories | CONFIRMED — [Endpoints](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/endpoints), as read 2026-11-13 for the push |
202
- | `GET /categories/{categoryId}/items` lists a category's items "with their associated complements" | CONFIRMED — Introduction, step 5 |
201
+ | `GET /catalogs` then `GET /catalogs/{catalogId}/categories` (the `DEFAULT` context's catalog) lists the merchant's categories; the merchant-level `GET /categories` does not exist (404) | CONFIRMED — live against iFood's sandbox, 2026-12-03 (FUT-6146); see the push's table |
202
+ | `GET /categories/{categoryId}/items` (merchant-level) lists a category's items "with their associated complements" | CONFIRMED — Introduction, step 5 |
203
203
  | An item is `item` (id, type, categoryId, status, `price { value }` in the major unit, externalCode), `products` (id, name, description, externalCode, and `optionGroups: [{ id, min, max }]` linking a product to its groups), `optionGroups` (id, name, status, `optionIds`), `options` (id, `productId` naming the product with its name, status, `price { value }`) | CONFIRMED as the `PUT /items` payload — Introduction, steps 3 and 4 |
204
204
  | The category list answers an array of `{ id, name, status, externalCode }` | ESTIMATED (the push makes the same estimate) |
205
205
  | `GET /categories/{categoryId}/items` answers the PUT's four lists as `{ items, products, optionGroups, options }` | ESTIMATED |
@@ -208,10 +208,10 @@ reader that day, so what they would settle is ESTIMATED below (the push's
208
208
  | No pagination: neither call shows a page, size or cursor parameter, so the menu is read one category per call | ESTIMATED |
209
209
  | 401: the token is dropped and the call asked once more with a fresh one; a second 401 is a `retry` | choice (as the push's `call`) |
210
210
  | The token grant refused (400/401/403) is `CREDENTIALS`; 403 on a catalogue call (the Errors page: the module is not enabled for the app) is `NOT_AUTHORIZED`; 429, 408, 425 and 5xx are a `retry`; another 4xx is `REFUSED` | CONFIRMED for the statuses — [Errors](https://developer.ifood.com.br/en-US/docs/food/guides/modules/catalog/errors-and-troubleshooting), as read 2026-11-13; the mapping is a choice |
211
- | A 404 on the category list means this app has no such merchant: `NOT_AUTHORIZED`; a 404 on one category's items (deleted between the calls) leaves that category out with a `CATEGORY_UNREADABLE` notice | ESTIMATED |
211
+ | A 404 on the catalog or category list is `REFUSED` with iFood's status and words, never `NOT_AUTHORIZED`: a path or resource iFood does not have is not a permission problem (FUT-6146 read a wrong route as "not authorized"); a catalog list with no `DEFAULT` catalog is `REFUSED`; a 404 on one category's items (deleted between the calls) leaves that category out with a `CATEGORY_UNREADABLE` notice | choice (FUT-6146) |
212
212
  | A photo path is used as a URL path as it is (an encoded `%20` stays); only characters a URL may not carry are encoded | choice |
213
213
  | An item `type` other than `DEFAULT` (a pizza, a combo) is read as a plain item with `ITEM_TYPE_UNSUPPORTED` | choice |
214
- | The read covers the merchant-level categories (the DEFAULT, delivery, context); other catalogs and `contextModifiers` prices are not read | ESTIMATED |
214
+ | The read covers the DEFAULT (delivery) context's catalog; other catalogs and `contextModifiers` prices are not read | choice |
215
215
 
216
216
  99Food, Keeta and Rappi state no `catalogueReader`: `engine.readCatalogue` answers
217
217
  `UNSUPPORTED` for them.
@@ -42,6 +42,25 @@ var IFOOD_REASON_CODES = [
42
42
  "513"
43
43
  ];
44
44
 
45
+ // src/ifood/catalogs.ts
46
+ function defaultCatalogIdIn(body) {
47
+ let parsed2;
48
+ try {
49
+ parsed2 = JSON.parse(body);
50
+ } catch {
51
+ return null;
52
+ }
53
+ if (!Array.isArray(parsed2)) return null;
54
+ for (const entry of parsed2) {
55
+ if (typeof entry !== "object" || entry === null) continue;
56
+ const { catalogId, context } = entry;
57
+ if (typeof catalogId === "string" && catalogId !== "" && Array.isArray(context) && context.includes("DEFAULT")) return catalogId;
58
+ }
59
+ return null;
60
+ }
61
+ __name(defaultCatalogIdIn, "defaultCatalogIdIn");
62
+ var categoriesPath = /* @__PURE__ */ __name((catalogId) => `catalogs/${encodeURIComponent(catalogId)}/categories`, "categoriesPath");
63
+
45
64
  // src/ifood/outbound.ts
46
65
  var IFOOD_API = "https://merchant-api.ifood.com.br";
47
66
  var TOKEN_URL = `${IFOOD_API}/authentication/v1.0/oauth/token`;
@@ -240,23 +259,38 @@ function categoryIdIn(body, name) {
240
259
  return typeof found?.id === "string" ? found.id : null;
241
260
  }
242
261
  __name(categoryIdIn, "categoryIdIn");
243
- async function findCategory(ctx, name) {
244
- const listed = await call(ctx, "GET", "categories");
262
+ async function catalogOf(ctx) {
263
+ const listed = await call(ctx, "GET", "catalogs");
264
+ if ("kind" in listed) return listed;
265
+ if (!ok(listed)) return failureOf(listed);
266
+ const catalogId = defaultCatalogIdIn(listed.body);
267
+ return catalogId === null ? { kind: "refused", status: listed.status, message: `no DEFAULT catalog: ${listed.body.slice(0, 200)}` } : { catalogId };
268
+ }
269
+ __name(catalogOf, "catalogOf");
270
+ async function findCategoryIn(ctx, catalogId, name) {
271
+ const listed = await call(ctx, "GET", categoriesPath(catalogId));
245
272
  if ("kind" in listed) return listed;
246
273
  if (!ok(listed)) return failureOf(listed);
247
274
  return { id: categoryIdIn(listed.body, name) };
248
275
  }
276
+ __name(findCategoryIn, "findCategoryIn");
277
+ async function findCategory(ctx, name) {
278
+ const catalog = await catalogOf(ctx);
279
+ return "kind" in catalog ? catalog : findCategoryIn(ctx, catalog.catalogId, name);
280
+ }
249
281
  __name(findCategory, "findCategory");
250
282
  async function findOrCreateCategory(ctx, name) {
251
- const found = await findCategory(ctx, name);
283
+ const catalog = await catalogOf(ctx);
284
+ if ("kind" in catalog) return catalog;
285
+ const found = await findCategoryIn(ctx, catalog.catalogId, name);
252
286
  if ("kind" in found) return found;
253
287
  if (found.id) return { id: found.id };
254
- const created = await call(ctx, "POST", "categories", { name, status: "AVAILABLE", template: "DEFAULT" });
288
+ const created = await call(ctx, "POST", categoriesPath(catalog.catalogId), { name, status: "AVAILABLE", template: "DEFAULT" });
255
289
  if ("kind" in created) return created;
256
290
  if (!ok(created)) return failureOf(created);
257
291
  const id = parse(created.body)?.id;
258
292
  if (typeof id !== "string") return { kind: "retry", reason: "iFood created the category without an id" };
259
- const again = await findCategory(ctx, name);
293
+ const again = await findCategoryIn(ctx, catalog.catalogId, name);
260
294
  return "id" in again && again.id ? { id: again.id } : { id };
261
295
  }
262
296
  __name(findOrCreateCategory, "findOrCreateCategory");
@@ -524,7 +558,7 @@ __name(tokenFailure, "tokenFailure");
524
558
  function failureOf2(response) {
525
559
  const result = outboundResultOf(response);
526
560
  if (result.kind !== "refused") return { kind: "retry", reason: result.kind === "retry" ? result.reason : "unexpected answer" };
527
- const code = response.status === 403 || response.status === 404 ? "NOT_AUTHORIZED" : "REFUSED";
561
+ const code = response.status === 403 ? "NOT_AUTHORIZED" : "REFUSED";
528
562
  return { kind: "refused", code, status: result.status, message: result.message };
529
563
  }
530
564
  __name(failureOf2, "failureOf");
@@ -602,8 +636,18 @@ function itemsOf(rawBody, categoryId2, notices) {
602
636
  return items;
603
637
  }
604
638
  __name(itemsOf, "itemsOf");
639
+ async function catalogOf2(ctx) {
640
+ const listed = await get(ctx, "catalogs");
641
+ if ("kind" in listed) return listed;
642
+ if (!ok2(listed)) return failureOf2(listed);
643
+ const catalogId = defaultCatalogIdIn(listed.body);
644
+ return catalogId === null ? unexpected("catalog list (no DEFAULT catalog)", listed.body) : { catalogId };
645
+ }
646
+ __name(catalogOf2, "catalogOf");
605
647
  async function read(ctx) {
606
- const listed = await get(ctx, "categories");
648
+ const catalog = await catalogOf2(ctx);
649
+ if ("kind" in catalog) return catalog;
650
+ const listed = await get(ctx, categoriesPath(catalog.catalogId));
607
651
  if ("kind" in listed) return listed;
608
652
  if (!ok2(listed)) return failureOf2(listed);
609
653
  const parsed2 = parse2(listed.body);