@12-apps/marketplace 1.19.0 → 1.19.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,7 +111,7 @@ 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` 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`) |
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` (when several do, the first `AVAILABLE` one, else the first: a choice, FUT-6257); 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
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) |
@@ -51,14 +51,17 @@ function defaultCatalogIdIn(body) {
51
51
  return null;
52
52
  }
53
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;
54
+ const defaults = parsed2.map(defaultEntryOf).filter((entry) => entry !== null);
55
+ return (defaults.find((entry) => entry.available) ?? defaults[0])?.catalogId ?? null;
60
56
  }
61
57
  __name(defaultCatalogIdIn, "defaultCatalogIdIn");
58
+ function defaultEntryOf(entry) {
59
+ if (typeof entry !== "object" || entry === null) return null;
60
+ const { catalogId, context, status } = entry;
61
+ if (typeof catalogId !== "string" || catalogId === "" || !Array.isArray(context) || !context.includes("DEFAULT")) return null;
62
+ return { catalogId, available: status === "AVAILABLE" };
63
+ }
64
+ __name(defaultEntryOf, "defaultEntryOf");
62
65
  var categoriesPath = /* @__PURE__ */ __name((catalogId) => `catalogs/${encodeURIComponent(catalogId)}/categories`, "categoriesPath");
63
66
 
64
67
  // src/ifood/outbound.ts
@@ -274,27 +277,25 @@ async function findCategoryIn(ctx, catalogId, name) {
274
277
  return { id: categoryIdIn(listed.body, name) };
275
278
  }
276
279
  __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
- }
281
- __name(findCategory, "findCategory");
282
- async function findOrCreateCategory(ctx, name) {
283
- const catalog = await catalogOf(ctx);
280
+ async function findOrCreateCategory(ctx, name, catalogId) {
281
+ const catalog = catalogId === void 0 ? await catalogOf(ctx) : { catalogId };
284
282
  if ("kind" in catalog) return catalog;
285
283
  const found = await findCategoryIn(ctx, catalog.catalogId, name);
286
284
  if ("kind" in found) return found;
287
- if (found.id) return { id: found.id };
288
- const created = await call(ctx, "POST", categoriesPath(catalog.catalogId), { name, status: "AVAILABLE", template: "DEFAULT" });
285
+ return found.id ? { id: found.id } : createCategoryIn(ctx, catalog.catalogId, name);
286
+ }
287
+ __name(findOrCreateCategory, "findOrCreateCategory");
288
+ async function createCategoryIn(ctx, catalogId, name) {
289
+ const created = await call(ctx, "POST", categoriesPath(catalogId), { name, status: "AVAILABLE", template: "DEFAULT" });
289
290
  if ("kind" in created) return created;
290
291
  if (!ok(created)) return failureOf(created);
291
292
  const id = parse(created.body)?.id;
292
293
  if (typeof id !== "string") return { kind: "retry", reason: "iFood created the category without an id" };
293
- const again = await findCategoryIn(ctx, catalog.catalogId, name);
294
+ const again = await findCategoryIn(ctx, catalogId, name);
294
295
  return "id" in again && again.id ? { id: again.id } : { id };
295
296
  }
296
- __name(findOrCreateCategory, "findOrCreateCategory");
297
- var categoryId = /* @__PURE__ */ __name((ctx, name) => ctx.category(name, () => findOrCreateCategory(ctx, name)), "categoryId");
297
+ __name(createCategoryIn, "createCategoryIn");
298
+ var categoryId = /* @__PURE__ */ __name((ctx, name, catalogId) => ctx.category(name, () => findOrCreateCategory(ctx, name, catalogId)), "categoryId");
298
299
  async function photoFor(ctx, item) {
299
300
  const stored = item.storedImage;
300
301
  if (item.imageUrl === null) return { image: null };
@@ -347,18 +348,22 @@ function ifoodItemBody(item, category, image) {
347
348
  }
348
349
  __name(ifoodItemBody, "ifoodItemBody");
349
350
  async function categoryWentStale(ctx, put, name, used) {
350
- if (put.status !== 400 && put.status !== 404) return false;
351
- const found = await findCategory(ctx, name);
352
- return !("kind" in found) && found.id !== used;
351
+ if (put.status !== 400 && put.status !== 404) return null;
352
+ const catalog = await catalogOf(ctx);
353
+ if ("kind" in catalog) return null;
354
+ const found = await findCategoryIn(ctx, catalog.catalogId, name);
355
+ return !("kind" in found) && found.id !== used ? catalog : null;
353
356
  }
354
357
  __name(categoryWentStale, "categoryWentStale");
355
358
  async function putItem(ctx, item, image) {
356
359
  const category = await categoryId(ctx, item.categoryName);
357
360
  if ("kind" in category) return category;
358
361
  const put = await call(ctx, "PUT", "items", ifoodItemBody(item, category.id, image));
359
- if ("kind" in put || ok(put) || !await categoryWentStale(ctx, put, item.categoryName, category.id)) return put;
362
+ if ("kind" in put || ok(put)) return put;
363
+ const stale = await categoryWentStale(ctx, put, item.categoryName, category.id);
364
+ if (stale === null) return put;
360
365
  await ctx.forgetCategory(item.categoryName);
361
- const again = await categoryId(ctx, item.categoryName);
366
+ const again = await categoryId(ctx, item.categoryName, stale.catalogId);
362
367
  if ("kind" in again) return again;
363
368
  return call(ctx, "PUT", "items", ifoodItemBody(item, again.id, image));
364
369
  }