@viu/emporix-sdk 2.6.0 → 2.8.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/dist/index.cjs CHANGED
@@ -1124,26 +1124,67 @@ var CategoryService = class {
1124
1124
  const pageSize = params.pageSize ?? 50;
1125
1125
  return iterateAll((pageNumber) => this.list({ pageNumber, pageSize }, auth2));
1126
1126
  }
1127
- /** Fetches the category tree, optionally rooted at `rootId`. */
1128
- async tree(rootId, auth2 = ANON2) {
1127
+ /**
1128
+ * The catalogue's **root categories** — the published category trees
1129
+ * (`GET /category-trees`). Use these for top-level storefront navigation;
1130
+ * drill into a node's children with {@link subcategories}.
1131
+ */
1132
+ async tree(auth2 = ANON2) {
1129
1133
  return this.ctx.http.request({
1130
1134
  method: "GET",
1131
- path: `/category/${this.ctx.tenant}/categories/tree`,
1132
- query: rootId ? { rootId } : {},
1135
+ path: `/category/${this.ctx.tenant}/category-trees`,
1136
+ auth: auth2
1137
+ });
1138
+ }
1139
+ /**
1140
+ * Direct child categories of a category (for hierarchy drill-down). Mirrors
1141
+ * {@link productsIn}: reads the category's **assignments** and keeps the
1142
+ * `CATEGORY` references, resolving them to full categories. Returns an empty
1143
+ * array when the category has no child categories.
1144
+ */
1145
+ async subcategories(categoryId, params = {}, auth2 = ANON2) {
1146
+ const pageNumber = params.pageNumber ?? 1;
1147
+ const pageSize = params.pageSize ?? 50;
1148
+ const assignments = await this.ctx.http.request({
1149
+ method: "GET",
1150
+ path: `/category/${this.ctx.tenant}/categories/${categoryId}/assignments`,
1151
+ query: { pageNumber, pageSize },
1133
1152
  auth: auth2
1134
1153
  });
1154
+ const categoryIds = assignments.map((a) => a.ref?.type?.toUpperCase() === "CATEGORY" ? a.ref.id : void 0).filter((id) => Boolean(id));
1155
+ if (categoryIds.length === 0) return [];
1156
+ return this.searchByIds(categoryIds, {}, auth2);
1135
1157
  }
1136
- /** One page of products in a category. */
1158
+ /**
1159
+ * One page of products in a category. The category service exposes products
1160
+ * as **assignments** (`/categories/{id}/assignments`) — references, not full
1161
+ * products — so this fetches a page of assignments, keeps the `PRODUCT`
1162
+ * references, and resolves them to full products via `/products/search`.
1163
+ * `hasNextPage` reflects the assignments page (the source of truth for
1164
+ * pagination).
1165
+ */
1137
1166
  async productsIn(categoryId, params = {}, auth2 = ANON2) {
1138
1167
  const pageNumber = params.pageNumber ?? 1;
1139
1168
  const pageSize = params.pageSize ?? 50;
1140
- const items = await this.ctx.http.request({
1169
+ const assignments = await this.ctx.http.request({
1141
1170
  method: "GET",
1142
- path: `/category/${this.ctx.tenant}/categories/${categoryId}/products`,
1171
+ path: `/category/${this.ctx.tenant}/categories/${categoryId}/assignments`,
1143
1172
  query: { pageNumber, pageSize },
1144
1173
  auth: auth2
1145
1174
  });
1146
- return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
1175
+ const hasNextPage = assignments.length === pageSize;
1176
+ const productIds = assignments.map((a) => a.ref?.type?.toUpperCase() === "PRODUCT" ? a.ref.id : void 0).filter((id) => Boolean(id));
1177
+ if (productIds.length === 0) {
1178
+ return { items: [], pageNumber, pageSize, hasNextPage };
1179
+ }
1180
+ const items = await this.ctx.http.request({
1181
+ method: "POST",
1182
+ path: `/product/${this.ctx.tenant}/products/search`,
1183
+ query: { pageSize: productIds.length },
1184
+ auth: auth2,
1185
+ body: { q: `id:(${productIds.join(",")})` }
1186
+ });
1187
+ return { items, pageNumber, pageSize, hasNextPage };
1147
1188
  }
1148
1189
  /**
1149
1190
  * Bulk fetch by id. POSTs `/categories/search` with `q="id:(id1,id2,…)"`,
@@ -1261,13 +1302,19 @@ var CartService = class {
1261
1302
  body: items
1262
1303
  });
1263
1304
  }
1264
- /** Updates an item. */
1265
- async updateItem(cartId, itemId, patch, auth2) {
1305
+ /**
1306
+ * Updates an item. By default this is a **full replace** — the server expects
1307
+ * the complete item (e.g. `itemYrn` + the `price` row). Pass
1308
+ * `{ partial: true }` to send a **partial update** (`?partial=true`), e.g. a
1309
+ * quantity-only change with just `{ quantity }`.
1310
+ */
1311
+ async updateItem(cartId, itemId, patch, auth2, opts = {}) {
1266
1312
  return this.ctx.http.request({
1267
1313
  method: "PUT",
1268
1314
  path: `${this.base()}/${cartId}/items/${itemId}`,
1269
1315
  auth: requireCartAuth(auth2),
1270
- body: patch
1316
+ body: patch,
1317
+ ...opts.partial ? { query: { partial: "true" } } : {}
1271
1318
  });
1272
1319
  }
1273
1320
  /** Removes an item. */
@@ -4973,7 +5020,7 @@ var ApprovalService = class {
4973
5020
  };
4974
5021
 
4975
5022
  // package.json
4976
- var version = "2.6.0";
5023
+ var version = "2.8.0";
4977
5024
 
4978
5025
  // src/version.ts
4979
5026
  var SDK_VERSION = version;