@viu/emporix-sdk 2.0.0 → 2.1.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/CHANGELOG.md +18 -0
- package/README.md +13 -1
- package/dist/availability.cjs +101 -0
- package/dist/availability.cjs.map +1 -0
- package/dist/availability.d.cts +87 -0
- package/dist/availability.d.ts +87 -0
- package/dist/availability.js +4 -0
- package/dist/availability.js.map +1 -0
- package/dist/cart.d.cts +1 -1
- package/dist/cart.d.ts +1 -1
- package/dist/category.d.cts +1 -1
- package/dist/category.d.ts +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/{chunk-QDABAMVN.js → chunk-JTJV7WUW.js} +25 -2
- package/dist/chunk-JTJV7WUW.js.map +1 -0
- package/dist/chunk-SCI7D74B.js +91 -0
- package/dist/chunk-SCI7D74B.js.map +1 -0
- package/dist/chunk-XMEP74BU.js +60 -0
- package/dist/chunk-XMEP74BU.js.map +1 -0
- package/dist/companies.d.cts +1 -1
- package/dist/companies.d.ts +1 -1
- package/dist/contacts.d.cts +1 -1
- package/dist/contacts.d.ts +1 -1
- package/dist/{context-mMTqsW1Z.d.cts → context-CGuxSb56.d.cts} +1 -1
- package/dist/{context-mMTqsW1Z.d.ts → context-CGuxSb56.d.ts} +1 -1
- package/dist/customer-groups.d.cts +1 -1
- package/dist/customer-groups.d.ts +1 -1
- package/dist/customer.d.cts +1 -1
- package/dist/customer.d.ts +1 -1
- package/dist/index.cjs +125 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/locations.d.cts +1 -1
- package/dist/locations.d.ts +1 -1
- package/dist/media.d.cts +1 -1
- package/dist/media.d.ts +1 -1
- package/dist/orders.d.cts +1 -1
- package/dist/orders.d.ts +1 -1
- package/dist/payment.d.cts +1 -1
- package/dist/payment.d.ts +1 -1
- package/dist/price.cjs +44 -0
- package/dist/price.cjs.map +1 -1
- package/dist/price.d.cts +27 -2
- package/dist/price.d.ts +27 -2
- package/dist/price.js +1 -1
- package/dist/product.cjs +23 -0
- package/dist/product.cjs.map +1 -1
- package/dist/product.d.cts +18 -1
- package/dist/product.d.ts +18 -1
- package/dist/product.js +1 -1
- package/dist/segment.d.cts +1 -1
- package/dist/segment.d.ts +1 -1
- package/package.json +6 -1
- package/dist/chunk-HEO34WLO.js +0 -47
- package/dist/chunk-HEO34WLO.js.map +0 -1
- package/dist/chunk-QDABAMVN.js.map +0 -1
package/dist/companies.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CGuxSb56.cjs';
|
|
2
2
|
import { L as LegalEntity, f as LegalEntityCreate, h as LegalEntityUpdate } from './types.gen-D1QuqPLs.cjs';
|
|
3
3
|
export { A as AccountLimit, e as CustomerGroupRef, g as LegalEntityType, i as LegalInfo } from './types.gen-D1QuqPLs.cjs';
|
|
4
4
|
|
package/dist/companies.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CGuxSb56.js';
|
|
2
2
|
import { L as LegalEntity, f as LegalEntityCreate, h as LegalEntityUpdate } from './types.gen-D1QuqPLs.js';
|
|
3
3
|
export { A as AccountLimit, e as CustomerGroupRef, g as LegalEntityType, i as LegalInfo } from './types.gen-D1QuqPLs.js';
|
|
4
4
|
|
package/dist/contacts.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CGuxSb56.cjs';
|
|
2
2
|
import { C as ContactAssignment, a as ContactAssignmentCreate, c as ContactAssignmentUpdate } from './types.gen-D1QuqPLs.cjs';
|
|
3
3
|
export { b as ContactAssignmentType } from './types.gen-D1QuqPLs.cjs';
|
|
4
4
|
|
package/dist/contacts.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CGuxSb56.js';
|
|
2
2
|
import { C as ContactAssignment, a as ContactAssignmentCreate, c as ContactAssignmentUpdate } from './types.gen-D1QuqPLs.js';
|
|
3
3
|
export { b as ContactAssignmentType } from './types.gen-D1QuqPLs.js';
|
|
4
4
|
|
|
@@ -3,7 +3,7 @@ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "silent";
|
|
|
3
3
|
/** Numeric ordering used for fast comparison. */
|
|
4
4
|
declare const LEVEL: Record<LogLevel, number>;
|
|
5
5
|
/** Services that bind their own logger and are independently level-controllable. */
|
|
6
|
-
type ServiceName = "customer" | "product" | "category" | "cart" | "checkout" | "payment" | "price" | "media" | "segment" | "site" | "session-context" | "customer-management" | "iam" | "orders" | "sales-orders" | "http" | "auth";
|
|
6
|
+
type ServiceName = "customer" | "product" | "category" | "cart" | "checkout" | "payment" | "price" | "media" | "segment" | "site" | "session-context" | "customer-management" | "iam" | "orders" | "sales-orders" | "availability" | "http" | "auth";
|
|
7
7
|
/** Arbitrary structured fields attached to a log line. */
|
|
8
8
|
interface LogFields {
|
|
9
9
|
[key: string]: unknown;
|
|
@@ -3,7 +3,7 @@ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "silent";
|
|
|
3
3
|
/** Numeric ordering used for fast comparison. */
|
|
4
4
|
declare const LEVEL: Record<LogLevel, number>;
|
|
5
5
|
/** Services that bind their own logger and are independently level-controllable. */
|
|
6
|
-
type ServiceName = "customer" | "product" | "category" | "cart" | "checkout" | "payment" | "price" | "media" | "segment" | "site" | "session-context" | "customer-management" | "iam" | "orders" | "sales-orders" | "http" | "auth";
|
|
6
|
+
type ServiceName = "customer" | "product" | "category" | "cart" | "checkout" | "payment" | "price" | "media" | "segment" | "site" | "session-context" | "customer-management" | "iam" | "orders" | "sales-orders" | "availability" | "http" | "auth";
|
|
7
7
|
/** Arbitrary structured fields attached to a log line. */
|
|
8
8
|
interface LogFields {
|
|
9
9
|
[key: string]: unknown;
|
package/dist/customer.d.cts
CHANGED
package/dist/customer.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -996,6 +996,29 @@ var ProductService = class {
|
|
|
996
996
|
);
|
|
997
997
|
return pages.flat();
|
|
998
998
|
}
|
|
999
|
+
/**
|
|
1000
|
+
* Streams the VARIANT children of a PARENT_VARIANT product, page by page,
|
|
1001
|
+
* via the search query `productType:VARIANT parentVariantId:<id>`. Default
|
|
1002
|
+
* pageSize 200. The query syntax (space-separated fields = implicit AND) is
|
|
1003
|
+
* encapsulated here so consumers don't build it themselves.
|
|
1004
|
+
*/
|
|
1005
|
+
listVariantChildrenAll(parentVariantId, params = {}, auth2 = ANON) {
|
|
1006
|
+
const pageSize = params.pageSize ?? 200;
|
|
1007
|
+
const q = `productType:VARIANT parentVariantId:${parentVariantId}`;
|
|
1008
|
+
return iterateAll((pageNumber) => this.search(q, { pageNumber, pageSize }, auth2));
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Resolves ALL VARIANT children of a PARENT_VARIANT product into a flat
|
|
1012
|
+
* array (loads every page). Default pageSize 200. Returns `[]` when there are
|
|
1013
|
+
* no children — never throws.
|
|
1014
|
+
*/
|
|
1015
|
+
async listVariantChildren(parentVariantId, params = {}, auth2 = ANON) {
|
|
1016
|
+
const out = [];
|
|
1017
|
+
for await (const child of this.listVariantChildrenAll(parentVariantId, params, auth2)) {
|
|
1018
|
+
out.push(child);
|
|
1019
|
+
}
|
|
1020
|
+
return out;
|
|
1021
|
+
}
|
|
999
1022
|
};
|
|
1000
1023
|
|
|
1001
1024
|
// src/services/category.ts
|
|
@@ -1362,6 +1385,50 @@ var PriceService = class {
|
|
|
1362
1385
|
body: input
|
|
1363
1386
|
});
|
|
1364
1387
|
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Chunked variant of {@link matchByContext} for large `items` arrays. The
|
|
1390
|
+
* Emporix backend handles only a limited number of items per request
|
|
1391
|
+
* (production limit ~50), so this splits `input.items` into chunks and runs
|
|
1392
|
+
* `matchByContext` with bounded concurrency.
|
|
1393
|
+
*
|
|
1394
|
+
* By default a failing chunk is skipped (its items are absent from the
|
|
1395
|
+
* result) and `opts.onChunkError` is called once for it; pass
|
|
1396
|
+
* `throwOnAnyChunkError: true` to reject on the first failure instead.
|
|
1397
|
+
*
|
|
1398
|
+
* **Result order is not guaranteed** — match entries back to your items by
|
|
1399
|
+
* `priceId` / `itemRef.id`.
|
|
1400
|
+
*/
|
|
1401
|
+
async matchByContextChunked(input, opts = {}, auth2) {
|
|
1402
|
+
const chunkSize = opts.chunkSize ?? 50;
|
|
1403
|
+
const concurrency = opts.concurrency ?? 4;
|
|
1404
|
+
if (chunkSize < 1) throw new Error("chunkSize must be >= 1");
|
|
1405
|
+
if (concurrency < 1) throw new Error("concurrency must be >= 1");
|
|
1406
|
+
const items = input.items ?? [];
|
|
1407
|
+
if (items.length === 0) return [];
|
|
1408
|
+
const chunks = [];
|
|
1409
|
+
for (let i = 0; i < items.length; i += chunkSize) {
|
|
1410
|
+
chunks.push({ ...input, items: items.slice(i, i + chunkSize) });
|
|
1411
|
+
}
|
|
1412
|
+
const results = new Array(chunks.length);
|
|
1413
|
+
let cursor = 0;
|
|
1414
|
+
const worker = async () => {
|
|
1415
|
+
for (; ; ) {
|
|
1416
|
+
const idx = cursor++;
|
|
1417
|
+
const chunk = chunks[idx];
|
|
1418
|
+
if (chunk === void 0) return;
|
|
1419
|
+
try {
|
|
1420
|
+
results[idx] = await this.matchByContext(chunk, auth2);
|
|
1421
|
+
} catch (err) {
|
|
1422
|
+
if (opts.throwOnAnyChunkError) throw err;
|
|
1423
|
+
results[idx] = [];
|
|
1424
|
+
opts.onChunkError?.(err, idx);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
const workerCount = Math.min(concurrency, chunks.length);
|
|
1429
|
+
await Promise.all(Array.from({ length: workerCount }, () => worker()));
|
|
1430
|
+
return results.flat();
|
|
1431
|
+
}
|
|
1365
1432
|
};
|
|
1366
1433
|
|
|
1367
1434
|
// src/services/media.ts
|
|
@@ -2110,6 +2177,61 @@ var SalesOrdersService = class {
|
|
|
2110
2177
|
}
|
|
2111
2178
|
};
|
|
2112
2179
|
|
|
2180
|
+
// src/services/availability.ts
|
|
2181
|
+
var ANON6 = { kind: "anonymous" };
|
|
2182
|
+
var AvailabilityService = class {
|
|
2183
|
+
constructor(ctx) {
|
|
2184
|
+
this.ctx = ctx;
|
|
2185
|
+
}
|
|
2186
|
+
ctx;
|
|
2187
|
+
/**
|
|
2188
|
+
* Single product. Resolves the availability record, or — when
|
|
2189
|
+
* `opts.defaultAvailableOnNotFound` is set — a default available record on 404.
|
|
2190
|
+
*/
|
|
2191
|
+
async get(productId, siteCode, auth2 = ANON6, opts = {}) {
|
|
2192
|
+
try {
|
|
2193
|
+
return await this.ctx.http.request({
|
|
2194
|
+
method: "GET",
|
|
2195
|
+
path: `/availability/${this.ctx.tenant}/availability/${encodeURIComponent(
|
|
2196
|
+
productId
|
|
2197
|
+
)}/${encodeURIComponent(siteCode)}`,
|
|
2198
|
+
auth: auth2
|
|
2199
|
+
});
|
|
2200
|
+
} catch (err) {
|
|
2201
|
+
if (err instanceof EmporixNotFoundError && opts.defaultAvailableOnNotFound) {
|
|
2202
|
+
return { productId, site: siteCode, available: true };
|
|
2203
|
+
}
|
|
2204
|
+
throw err;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
/**
|
|
2208
|
+
* Batch read via `POST .../availability/search` (one request). Products with
|
|
2209
|
+
* no availability record are absent from the response; each is synthesized as
|
|
2210
|
+
* `{ available: false }` (or `{ available: true }` when
|
|
2211
|
+
* `opts.defaultAvailableOnNotFound` is set). The result preserves input order
|
|
2212
|
+
* and length. An empty `productIds` resolves to `[]` without a request.
|
|
2213
|
+
*/
|
|
2214
|
+
async getMany(productIds, siteCode, auth2 = ANON6, opts = {}) {
|
|
2215
|
+
if (productIds.length === 0) return [];
|
|
2216
|
+
const found = await this.ctx.http.request({
|
|
2217
|
+
method: "POST",
|
|
2218
|
+
path: `/availability/${this.ctx.tenant}/availability/search`,
|
|
2219
|
+
auth: auth2,
|
|
2220
|
+
query: { site: siteCode, pageSize: productIds.length },
|
|
2221
|
+
body: productIds
|
|
2222
|
+
});
|
|
2223
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2224
|
+
for (const a of found) if (a.productId) byId.set(a.productId, a);
|
|
2225
|
+
return productIds.map(
|
|
2226
|
+
(id) => byId.get(id) ?? {
|
|
2227
|
+
productId: id,
|
|
2228
|
+
site: siteCode,
|
|
2229
|
+
available: Boolean(opts.defaultAvailableOnNotFound)
|
|
2230
|
+
}
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
};
|
|
2234
|
+
|
|
2113
2235
|
// src/client.ts
|
|
2114
2236
|
var SDK_VERSION = "0.0.0";
|
|
2115
2237
|
var EmporixClient = class {
|
|
@@ -2130,6 +2252,7 @@ var EmporixClient = class {
|
|
|
2130
2252
|
customerGroups;
|
|
2131
2253
|
orders;
|
|
2132
2254
|
salesOrders;
|
|
2255
|
+
availability;
|
|
2133
2256
|
/** The validated tenant this client is bound to. */
|
|
2134
2257
|
tenant;
|
|
2135
2258
|
/**
|
|
@@ -2199,6 +2322,7 @@ var EmporixClient = class {
|
|
|
2199
2322
|
this.customerGroups = new CustomerGroupsService(mk("iam"));
|
|
2200
2323
|
this.orders = new OrdersService(mk("orders"));
|
|
2201
2324
|
this.salesOrders = new SalesOrdersService(mk("sales-orders"));
|
|
2325
|
+
this.availability = new AvailabilityService(mk("availability"));
|
|
2202
2326
|
}
|
|
2203
2327
|
/** Sets the runtime log level globally or for one service. */
|
|
2204
2328
|
setLogLevel(level, opts = {}) {
|
|
@@ -2210,6 +2334,7 @@ var EmporixClient = class {
|
|
|
2210
2334
|
}
|
|
2211
2335
|
};
|
|
2212
2336
|
|
|
2337
|
+
exports.AvailabilityService = AvailabilityService;
|
|
2213
2338
|
exports.CartService = CartService;
|
|
2214
2339
|
exports.CategoryService = CategoryService;
|
|
2215
2340
|
exports.CheckoutService = CheckoutService;
|