@viu/emporix-sdk 2.1.0 → 2.3.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 +75 -0
- package/dist/availability.d.cts +1 -1
- package/dist/availability.d.ts +1 -1
- 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-JTJV7WUW.js → chunk-5JHTZBOC.js} +42 -2
- package/dist/chunk-5JHTZBOC.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-CGuxSb56.d.cts → context-CQFcPZnt.d.cts} +1 -1
- package/dist/{context-CGuxSb56.d.ts → context-CQFcPZnt.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 +1028 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2014 -3
- package/dist/index.d.ts +2014 -3
- package/dist/index.js +983 -10
- 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.d.cts +1 -1
- package/dist/price.d.ts +1 -1
- package/dist/product.cjs +40 -0
- package/dist/product.cjs.map +1 -1
- package/dist/product.d.cts +14 -1
- package/dist/product.d.ts +14 -1
- package/dist/product.js +1 -1
- package/dist/segment.d.cts +1 -1
- package/dist/segment.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-JTJV7WUW.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -996,6 +996,46 @@ var ProductService = class {
|
|
|
996
996
|
);
|
|
997
997
|
return pages.flat();
|
|
998
998
|
}
|
|
999
|
+
/**
|
|
1000
|
+
* Bulk fetch by code. POSTs `/products/search` with `q="code:(c1,c2,…)"`,
|
|
1001
|
+
* chunking when the list is larger than `options.chunkSize` (default 100).
|
|
1002
|
+
* Duplicate codes are de-duplicated. Codes containing query-delimiter
|
|
1003
|
+
* characters (`(`, `)`, `,`, whitespace, `"`) are dropped with a logged
|
|
1004
|
+
* warning, because the Emporix `q` syntax uses them as delimiters and does
|
|
1005
|
+
* not support escaping them in a plain IN-list. An empty list — or one with
|
|
1006
|
+
* no safe codes — short-circuits with no HTTP call. **Order is not
|
|
1007
|
+
* guaranteed** across chunks — re-index by `code` if order matters.
|
|
1008
|
+
*/
|
|
1009
|
+
async searchByCodes(codes, options = {}, auth2 = ANON) {
|
|
1010
|
+
const unique = [...new Set(codes)];
|
|
1011
|
+
const unsafe = /[(),"\s]/;
|
|
1012
|
+
const safe = unique.filter((c) => !unsafe.test(c));
|
|
1013
|
+
const dropped = unique.filter((c) => unsafe.test(c));
|
|
1014
|
+
if (dropped.length > 0) {
|
|
1015
|
+
this.ctx.logger.warn(
|
|
1016
|
+
"products.searchByCodes: dropped codes containing query-delimiter characters",
|
|
1017
|
+
{ dropped }
|
|
1018
|
+
);
|
|
1019
|
+
}
|
|
1020
|
+
if (safe.length === 0) return [];
|
|
1021
|
+
const chunkSize = options.chunkSize ?? 100;
|
|
1022
|
+
const chunks = [];
|
|
1023
|
+
for (let i = 0; i < safe.length; i += chunkSize) {
|
|
1024
|
+
chunks.push(safe.slice(i, i + chunkSize));
|
|
1025
|
+
}
|
|
1026
|
+
const pages = await Promise.all(
|
|
1027
|
+
chunks.map(
|
|
1028
|
+
(chunk) => this.ctx.http.request({
|
|
1029
|
+
method: "POST",
|
|
1030
|
+
path: `/product/${this.ctx.tenant}/products/search`,
|
|
1031
|
+
query: { pageSize: chunk.length },
|
|
1032
|
+
auth: auth2,
|
|
1033
|
+
body: { q: `code:(${chunk.join(",")})` }
|
|
1034
|
+
})
|
|
1035
|
+
)
|
|
1036
|
+
);
|
|
1037
|
+
return pages.flat();
|
|
1038
|
+
}
|
|
999
1039
|
/**
|
|
1000
1040
|
* Streams the VARIANT children of a PARENT_VARIANT product, page by page,
|
|
1001
1041
|
* via the search query `productType:VARIANT parentVariantId:<id>`. Default
|
|
@@ -1880,12 +1920,12 @@ var SessionContextService = class {
|
|
|
1880
1920
|
* update). Non-404 errors propagate.
|
|
1881
1921
|
*/
|
|
1882
1922
|
async patch(input, authCtx = ANON5) {
|
|
1883
|
-
let
|
|
1884
|
-
if (
|
|
1923
|
+
let version2 = input.version;
|
|
1924
|
+
if (version2 === void 0) {
|
|
1885
1925
|
const current = await this.get(authCtx);
|
|
1886
1926
|
if (current === null) return false;
|
|
1887
|
-
|
|
1888
|
-
if (
|
|
1927
|
+
version2 = current.metadata?.version;
|
|
1928
|
+
if (version2 === void 0) {
|
|
1889
1929
|
throw new Error(
|
|
1890
1930
|
"SessionContextService.patch: no metadata.version in server response"
|
|
1891
1931
|
);
|
|
@@ -1897,7 +1937,7 @@ var SessionContextService = class {
|
|
|
1897
1937
|
path: `/session-context/${this.ctx.tenant}/me/context`,
|
|
1898
1938
|
body: {
|
|
1899
1939
|
...fields,
|
|
1900
|
-
metadata: { version }
|
|
1940
|
+
metadata: { version: version2 }
|
|
1901
1941
|
},
|
|
1902
1942
|
auth: authCtx
|
|
1903
1943
|
});
|
|
@@ -2232,8 +2272,963 @@ var AvailabilityService = class {
|
|
|
2232
2272
|
}
|
|
2233
2273
|
};
|
|
2234
2274
|
|
|
2275
|
+
// src/services/tenant-config.ts
|
|
2276
|
+
var SERVICE3 = { kind: "service" };
|
|
2277
|
+
var TenantConfigService = class {
|
|
2278
|
+
constructor(ctx) {
|
|
2279
|
+
this.ctx = ctx;
|
|
2280
|
+
}
|
|
2281
|
+
ctx;
|
|
2282
|
+
base() {
|
|
2283
|
+
return `/configuration/${this.ctx.tenant}/configurations`;
|
|
2284
|
+
}
|
|
2285
|
+
/** List tenant configurations, optionally filtered by `keys`. */
|
|
2286
|
+
async list(opts = {}, auth2 = SERVICE3) {
|
|
2287
|
+
const query = opts.keys && opts.keys.length > 0 ? { keys: opts.keys.join(",") } : void 0;
|
|
2288
|
+
return this.ctx.http.request({
|
|
2289
|
+
method: "GET",
|
|
2290
|
+
path: this.base(),
|
|
2291
|
+
auth: auth2,
|
|
2292
|
+
...query ? { query } : {}
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
/** Retrieve one tenant configuration by key. */
|
|
2296
|
+
async get(key, auth2 = SERVICE3) {
|
|
2297
|
+
return this.ctx.http.request({
|
|
2298
|
+
method: "GET",
|
|
2299
|
+
path: `${this.base()}/${encodeURIComponent(key)}`,
|
|
2300
|
+
auth: auth2
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
/** Create one or more tenant configurations (array in, array out). */
|
|
2304
|
+
async create(drafts, auth2 = SERVICE3) {
|
|
2305
|
+
return this.ctx.http.request({
|
|
2306
|
+
method: "POST",
|
|
2307
|
+
path: this.base(),
|
|
2308
|
+
auth: auth2,
|
|
2309
|
+
body: drafts
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
/** Update one tenant configuration by key. */
|
|
2313
|
+
async update(key, draft, auth2 = SERVICE3) {
|
|
2314
|
+
return this.ctx.http.request({
|
|
2315
|
+
method: "PUT",
|
|
2316
|
+
path: `${this.base()}/${encodeURIComponent(key)}`,
|
|
2317
|
+
auth: auth2,
|
|
2318
|
+
body: draft
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
/** Delete one tenant configuration by key. */
|
|
2322
|
+
async delete(key, auth2 = SERVICE3) {
|
|
2323
|
+
await this.ctx.http.request({
|
|
2324
|
+
method: "DELETE",
|
|
2325
|
+
path: `${this.base()}/${encodeURIComponent(key)}`,
|
|
2326
|
+
auth: auth2
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2329
|
+
};
|
|
2330
|
+
|
|
2331
|
+
// src/services/client-config.ts
|
|
2332
|
+
var SERVICE4 = { kind: "service" };
|
|
2333
|
+
var ClientConfigService = class {
|
|
2334
|
+
constructor(ctx) {
|
|
2335
|
+
this.ctx = ctx;
|
|
2336
|
+
}
|
|
2337
|
+
ctx;
|
|
2338
|
+
base(client) {
|
|
2339
|
+
return `/configuration/${this.ctx.tenant}/clients/${encodeURIComponent(client)}/configurations`;
|
|
2340
|
+
}
|
|
2341
|
+
/** List a client's configurations, optionally filtered by `keys`. */
|
|
2342
|
+
async list(client, opts = {}, auth2 = SERVICE4) {
|
|
2343
|
+
const query = opts.keys && opts.keys.length > 0 ? { keys: opts.keys.join(",") } : void 0;
|
|
2344
|
+
return this.ctx.http.request({
|
|
2345
|
+
method: "GET",
|
|
2346
|
+
path: this.base(client),
|
|
2347
|
+
auth: auth2,
|
|
2348
|
+
...query ? { query } : {}
|
|
2349
|
+
});
|
|
2350
|
+
}
|
|
2351
|
+
/** Retrieve one client configuration by key. */
|
|
2352
|
+
async get(client, key, auth2 = SERVICE4) {
|
|
2353
|
+
return this.ctx.http.request({
|
|
2354
|
+
method: "GET",
|
|
2355
|
+
path: `${this.base(client)}/${encodeURIComponent(key)}`,
|
|
2356
|
+
auth: auth2
|
|
2357
|
+
});
|
|
2358
|
+
}
|
|
2359
|
+
/** Create one or more client configurations. Injects `client` into each item. */
|
|
2360
|
+
async create(client, drafts, auth2 = SERVICE4) {
|
|
2361
|
+
const body = drafts.map((d) => ({ ...d, client }));
|
|
2362
|
+
return this.ctx.http.request({
|
|
2363
|
+
method: "POST",
|
|
2364
|
+
path: this.base(client),
|
|
2365
|
+
auth: auth2,
|
|
2366
|
+
body
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
/** Update one client configuration by key. Injects `client` into the body. */
|
|
2370
|
+
async update(client, key, draft, auth2 = SERVICE4) {
|
|
2371
|
+
return this.ctx.http.request({
|
|
2372
|
+
method: "PUT",
|
|
2373
|
+
path: `${this.base(client)}/${encodeURIComponent(key)}`,
|
|
2374
|
+
auth: auth2,
|
|
2375
|
+
body: { ...draft, client }
|
|
2376
|
+
});
|
|
2377
|
+
}
|
|
2378
|
+
/** Delete one client configuration by key. */
|
|
2379
|
+
async delete(client, key, auth2 = SERVICE4) {
|
|
2380
|
+
await this.ctx.http.request({
|
|
2381
|
+
method: "DELETE",
|
|
2382
|
+
path: `${this.base(client)}/${encodeURIComponent(key)}`,
|
|
2383
|
+
auth: auth2
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
};
|
|
2387
|
+
|
|
2388
|
+
// src/services/shopping-list.ts
|
|
2389
|
+
var RESERVED = /* @__PURE__ */ new Set(["customerId", "metadata"]);
|
|
2390
|
+
var ShoppingListService = class {
|
|
2391
|
+
constructor(ctx) {
|
|
2392
|
+
this.ctx = ctx;
|
|
2393
|
+
}
|
|
2394
|
+
ctx;
|
|
2395
|
+
base() {
|
|
2396
|
+
return `/shoppinglist/${this.ctx.tenant}/shopping-lists`;
|
|
2397
|
+
}
|
|
2398
|
+
/** The caller's lists (or, with employee scope, all), normalized to an array. */
|
|
2399
|
+
async list(auth2, opts = {}) {
|
|
2400
|
+
const envelopes = await this.ctx.http.request({
|
|
2401
|
+
method: "GET",
|
|
2402
|
+
path: this.base(),
|
|
2403
|
+
auth: auth2,
|
|
2404
|
+
...opts.name ? { query: { name: opts.name } } : {}
|
|
2405
|
+
});
|
|
2406
|
+
const out = [];
|
|
2407
|
+
for (const env of envelopes ?? []) {
|
|
2408
|
+
for (const [key, value] of Object.entries(env)) {
|
|
2409
|
+
if (RESERVED.has(key) || value === null || typeof value !== "object") continue;
|
|
2410
|
+
const v = value;
|
|
2411
|
+
out.push({
|
|
2412
|
+
key,
|
|
2413
|
+
name: v.name ?? key,
|
|
2414
|
+
items: v.items ?? [],
|
|
2415
|
+
...v.mixins ? { mixins: v.mixins } : {},
|
|
2416
|
+
...v.metadata ? { metadata: v.metadata } : {}
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
return out;
|
|
2421
|
+
}
|
|
2422
|
+
/** Create a list; returns the new list id. */
|
|
2423
|
+
async create(draft, auth2) {
|
|
2424
|
+
return this.ctx.http.request({
|
|
2425
|
+
method: "POST",
|
|
2426
|
+
path: this.base(),
|
|
2427
|
+
auth: auth2,
|
|
2428
|
+
body: draft
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
/** Replace the named list (low-level PUT). */
|
|
2432
|
+
async replace(customerId, draft, auth2) {
|
|
2433
|
+
await this.ctx.http.request({
|
|
2434
|
+
method: "PUT",
|
|
2435
|
+
path: `${this.base()}/${encodeURIComponent(customerId)}`,
|
|
2436
|
+
auth: auth2,
|
|
2437
|
+
body: draft
|
|
2438
|
+
});
|
|
2439
|
+
}
|
|
2440
|
+
/** Delete the named list, or all the customer's lists when `name` is omitted. */
|
|
2441
|
+
async delete(customerId, auth2, opts = {}) {
|
|
2442
|
+
await this.ctx.http.request({
|
|
2443
|
+
method: "DELETE",
|
|
2444
|
+
path: `${this.base()}/${encodeURIComponent(customerId)}`,
|
|
2445
|
+
auth: auth2,
|
|
2446
|
+
...opts.name ? { query: { name: opts.name } } : {}
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
async loadList(listName, auth2) {
|
|
2450
|
+
const lists = await this.list(auth2, { name: listName });
|
|
2451
|
+
const found = lists.find((l) => l.name === listName);
|
|
2452
|
+
if (!found) throw new EmporixNotFoundError(`Shopping list "${listName}" not found`, 404);
|
|
2453
|
+
return found;
|
|
2454
|
+
}
|
|
2455
|
+
async put(customerId, list, items, auth2) {
|
|
2456
|
+
await this.replace(
|
|
2457
|
+
customerId,
|
|
2458
|
+
{ name: list.name, items, ...list.mixins ? { mixins: list.mixins } : {} },
|
|
2459
|
+
auth2
|
|
2460
|
+
);
|
|
2461
|
+
}
|
|
2462
|
+
/** Add/replace an item by `productId` (read-modify-write, last-write-wins). */
|
|
2463
|
+
async addItem(customerId, listName, item, auth2) {
|
|
2464
|
+
const list = await this.loadList(listName, auth2);
|
|
2465
|
+
const items = [...list.items.filter((i) => i.productId !== item.productId), item];
|
|
2466
|
+
await this.put(customerId, list, items, auth2);
|
|
2467
|
+
}
|
|
2468
|
+
/** Remove an item by `productId` (no-op if absent). */
|
|
2469
|
+
async removeItem(customerId, listName, productId, auth2) {
|
|
2470
|
+
const list = await this.loadList(listName, auth2);
|
|
2471
|
+
const items = list.items.filter((i) => i.productId !== productId);
|
|
2472
|
+
await this.put(customerId, list, items, auth2);
|
|
2473
|
+
}
|
|
2474
|
+
/** Set an item's quantity; `quantity <= 0` removes it. Adds the item if absent. */
|
|
2475
|
+
async setItemQuantity(customerId, listName, productId, quantity, auth2) {
|
|
2476
|
+
if (quantity <= 0) return this.removeItem(customerId, listName, productId, auth2);
|
|
2477
|
+
const list = await this.loadList(listName, auth2);
|
|
2478
|
+
let items = list.items.map((i) => i.productId === productId ? { ...i, quantity } : i);
|
|
2479
|
+
if (!items.some((i) => i.productId === productId)) items = [...items, { productId, quantity }];
|
|
2480
|
+
await this.put(customerId, list, items, auth2);
|
|
2481
|
+
}
|
|
2482
|
+
};
|
|
2483
|
+
|
|
2484
|
+
// src/services/ai-rag-indexer.ts
|
|
2485
|
+
var SERVICE5 = { kind: "service" };
|
|
2486
|
+
var RagIndexerService = class {
|
|
2487
|
+
constructor(ctx) {
|
|
2488
|
+
this.ctx = ctx;
|
|
2489
|
+
}
|
|
2490
|
+
ctx;
|
|
2491
|
+
base(type) {
|
|
2492
|
+
return `/ai-rag-indexer/${this.ctx.tenant}/${encodeURIComponent(type)}`;
|
|
2493
|
+
}
|
|
2494
|
+
/** The indexable embedding field names for `type` (default `"PRODUCT"`). */
|
|
2495
|
+
async ragMetadata(type = "PRODUCT", auth2 = SERVICE5) {
|
|
2496
|
+
return this.ctx.http.request({
|
|
2497
|
+
method: "GET",
|
|
2498
|
+
path: `${this.base(type)}/rag-metadata`,
|
|
2499
|
+
auth: auth2
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
/** The filterable metadata fields for `type` (default `"PRODUCT"`). */
|
|
2503
|
+
async filterMetadata(type = "PRODUCT", auth2 = SERVICE5) {
|
|
2504
|
+
return this.ctx.http.request({
|
|
2505
|
+
method: "GET",
|
|
2506
|
+
path: `${this.base(type)}/filter-metadata`,
|
|
2507
|
+
auth: auth2
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
/**
|
|
2511
|
+
* Schedule a full asynchronous re-index for `type` (default `"PRODUCT"`).
|
|
2512
|
+
* Resolves once the rebuild is *scheduled* (HTTP 204); there is no progress
|
|
2513
|
+
* to await or poll. Costly — avoid calling on a hot path.
|
|
2514
|
+
*/
|
|
2515
|
+
async reindex(type = "PRODUCT", auth2 = SERVICE5) {
|
|
2516
|
+
await this.ctx.http.request({
|
|
2517
|
+
method: "POST",
|
|
2518
|
+
path: `${this.base(type)}/reindex`,
|
|
2519
|
+
auth: auth2
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
};
|
|
2523
|
+
|
|
2524
|
+
// src/services/sequential-id.ts
|
|
2525
|
+
var SERVICE6 = { kind: "service" };
|
|
2526
|
+
var SequentialIdService = class {
|
|
2527
|
+
constructor(ctx) {
|
|
2528
|
+
this.ctx = ctx;
|
|
2529
|
+
}
|
|
2530
|
+
ctx;
|
|
2531
|
+
base() {
|
|
2532
|
+
return `/sequential-id/${this.ctx.tenant}/schemas`;
|
|
2533
|
+
}
|
|
2534
|
+
/** List all sequence schemas for the tenant. */
|
|
2535
|
+
async listSchemas(auth2 = SERVICE6) {
|
|
2536
|
+
return this.ctx.http.request({
|
|
2537
|
+
method: "GET",
|
|
2538
|
+
path: this.base(),
|
|
2539
|
+
auth: auth2
|
|
2540
|
+
});
|
|
2541
|
+
}
|
|
2542
|
+
/** Retrieve one sequence schema by id. */
|
|
2543
|
+
async getSchema(schemaId, auth2 = SERVICE6) {
|
|
2544
|
+
return this.ctx.http.request({
|
|
2545
|
+
method: "GET",
|
|
2546
|
+
path: `${this.base()}/${encodeURIComponent(schemaId)}`,
|
|
2547
|
+
auth: auth2
|
|
2548
|
+
});
|
|
2549
|
+
}
|
|
2550
|
+
/** Create a sequence schema. Schemas are immutable — there is no update. */
|
|
2551
|
+
async createSchema(schema, auth2 = SERVICE6) {
|
|
2552
|
+
return this.ctx.http.request({
|
|
2553
|
+
method: "POST",
|
|
2554
|
+
path: this.base(),
|
|
2555
|
+
auth: auth2,
|
|
2556
|
+
body: schema
|
|
2557
|
+
});
|
|
2558
|
+
}
|
|
2559
|
+
/** Delete a sequence schema by id. */
|
|
2560
|
+
async deleteSchema(schemaId, auth2 = SERVICE6) {
|
|
2561
|
+
await this.ctx.http.request({
|
|
2562
|
+
method: "DELETE",
|
|
2563
|
+
path: `${this.base()}/${encodeURIComponent(schemaId)}`,
|
|
2564
|
+
auth: auth2
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
/** Mark a schema active for its type (only one schema may be active per type). */
|
|
2568
|
+
async setActiveSchema(schemaId, auth2 = SERVICE6) {
|
|
2569
|
+
await this.ctx.http.request({
|
|
2570
|
+
method: "POST",
|
|
2571
|
+
path: `${this.base()}/${encodeURIComponent(schemaId)}/setActive`,
|
|
2572
|
+
auth: auth2
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2575
|
+
/** Get the active schema for a given schema type. */
|
|
2576
|
+
async listSchemasByType(schemaType, auth2 = SERVICE6) {
|
|
2577
|
+
return this.ctx.http.request({
|
|
2578
|
+
method: "GET",
|
|
2579
|
+
path: `${this.base()}/types/${encodeURIComponent(schemaType)}`,
|
|
2580
|
+
auth: auth2
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
/**
|
|
2584
|
+
* Generate the next id for a schema type. `body` carries an optional
|
|
2585
|
+
* `sequenceKey` (independent sub-pool counter) and `placeholders`.
|
|
2586
|
+
* `opts.siteCode` derives time/country placeholders from the site's settings.
|
|
2587
|
+
*/
|
|
2588
|
+
async nextId(schemaType, body = {}, opts = {}, auth2 = SERVICE6) {
|
|
2589
|
+
const query = opts.siteCode ? { siteCode: opts.siteCode } : void 0;
|
|
2590
|
+
return this.ctx.http.request({
|
|
2591
|
+
method: "POST",
|
|
2592
|
+
path: `${this.base()}/types/${encodeURIComponent(schemaType)}/nextId`,
|
|
2593
|
+
auth: auth2,
|
|
2594
|
+
body,
|
|
2595
|
+
...query ? { query } : {}
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
/**
|
|
2599
|
+
* Generate next ids for multiple schema types in one call. NOTE: the batch
|
|
2600
|
+
* endpoint path omits the `{tenant}` segment — the service derives the
|
|
2601
|
+
* tenant from the token.
|
|
2602
|
+
*/
|
|
2603
|
+
async nextIdsBatch(req, auth2 = SERVICE6) {
|
|
2604
|
+
return this.ctx.http.request({
|
|
2605
|
+
method: "POST",
|
|
2606
|
+
path: `/sequential-id/sequenceSchemaBatch/nextIds`,
|
|
2607
|
+
auth: auth2,
|
|
2608
|
+
body: req
|
|
2609
|
+
});
|
|
2610
|
+
}
|
|
2611
|
+
};
|
|
2612
|
+
|
|
2613
|
+
// src/services/fee.ts
|
|
2614
|
+
var SERVICE7 = { kind: "service" };
|
|
2615
|
+
var FeeService = class {
|
|
2616
|
+
constructor(ctx) {
|
|
2617
|
+
this.ctx = ctx;
|
|
2618
|
+
}
|
|
2619
|
+
ctx;
|
|
2620
|
+
feesBase() {
|
|
2621
|
+
return `/fee/${this.ctx.tenant}/fees`;
|
|
2622
|
+
}
|
|
2623
|
+
itemFeesBase() {
|
|
2624
|
+
return `/fee/${this.ctx.tenant}/itemFees`;
|
|
2625
|
+
}
|
|
2626
|
+
productFeesBase() {
|
|
2627
|
+
return `/fee/${this.ctx.tenant}/productFees`;
|
|
2628
|
+
}
|
|
2629
|
+
// --- Fee definitions ---
|
|
2630
|
+
/**
|
|
2631
|
+
* List fee definitions, wrapped in the shared {@link PaginatedItems}
|
|
2632
|
+
* envelope (same heuristic as `media.list`: `hasNextPage` is true when the
|
|
2633
|
+
* returned page is full). Defaults match Emporix server defaults
|
|
2634
|
+
* (`pageNumber: 1`, `pageSize: 60`).
|
|
2635
|
+
*/
|
|
2636
|
+
async list(query = {}, auth2 = SERVICE7) {
|
|
2637
|
+
const pageNumber = query.pageNumber ?? 1;
|
|
2638
|
+
const pageSize = query.pageSize ?? 60;
|
|
2639
|
+
const items = await this.ctx.http.request({
|
|
2640
|
+
method: "GET",
|
|
2641
|
+
path: this.feesBase(),
|
|
2642
|
+
auth: auth2,
|
|
2643
|
+
query: { ...query, pageNumber, pageSize }
|
|
2644
|
+
});
|
|
2645
|
+
return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
|
|
2646
|
+
}
|
|
2647
|
+
/** Retrieve one fee definition by id. */
|
|
2648
|
+
async get(id, auth2 = SERVICE7) {
|
|
2649
|
+
return this.ctx.http.request({
|
|
2650
|
+
method: "GET",
|
|
2651
|
+
path: `${this.feesBase()}/${encodeURIComponent(id)}`,
|
|
2652
|
+
auth: auth2
|
|
2653
|
+
});
|
|
2654
|
+
}
|
|
2655
|
+
/** Create a fee definition. */
|
|
2656
|
+
async create(draft, auth2 = SERVICE7) {
|
|
2657
|
+
return this.ctx.http.request({
|
|
2658
|
+
method: "POST",
|
|
2659
|
+
path: this.feesBase(),
|
|
2660
|
+
auth: auth2,
|
|
2661
|
+
body: draft
|
|
2662
|
+
});
|
|
2663
|
+
}
|
|
2664
|
+
/** Update a fee definition by id. */
|
|
2665
|
+
async update(id, draft, auth2 = SERVICE7) {
|
|
2666
|
+
return this.ctx.http.request({
|
|
2667
|
+
method: "PUT",
|
|
2668
|
+
path: `${this.feesBase()}/${encodeURIComponent(id)}`,
|
|
2669
|
+
auth: auth2,
|
|
2670
|
+
body: draft
|
|
2671
|
+
});
|
|
2672
|
+
}
|
|
2673
|
+
/** Delete a fee definition by id. */
|
|
2674
|
+
async delete(id, auth2 = SERVICE7) {
|
|
2675
|
+
await this.ctx.http.request({
|
|
2676
|
+
method: "DELETE",
|
|
2677
|
+
path: `${this.feesBase()}/${encodeURIComponent(id)}`,
|
|
2678
|
+
auth: auth2
|
|
2679
|
+
});
|
|
2680
|
+
}
|
|
2681
|
+
// --- Item-fee mappings ---
|
|
2682
|
+
/** List all item-fee mappings. */
|
|
2683
|
+
async listItemFees(auth2 = SERVICE7) {
|
|
2684
|
+
return this.ctx.http.request({
|
|
2685
|
+
method: "GET",
|
|
2686
|
+
path: this.itemFeesBase(),
|
|
2687
|
+
auth: auth2
|
|
2688
|
+
});
|
|
2689
|
+
}
|
|
2690
|
+
/** Fee mappings for one item YRN. */
|
|
2691
|
+
async getItemFees(itemYrn, auth2 = SERVICE7) {
|
|
2692
|
+
return this.ctx.http.request({
|
|
2693
|
+
method: "GET",
|
|
2694
|
+
path: `${this.itemFeesBase()}/${encodeURIComponent(itemYrn)}/fees`,
|
|
2695
|
+
auth: auth2
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
/** Create an item-fee mapping. */
|
|
2699
|
+
async createItemFee(draft, auth2 = SERVICE7) {
|
|
2700
|
+
return this.ctx.http.request({
|
|
2701
|
+
method: "POST",
|
|
2702
|
+
path: this.itemFeesBase(),
|
|
2703
|
+
auth: auth2,
|
|
2704
|
+
body: draft
|
|
2705
|
+
});
|
|
2706
|
+
}
|
|
2707
|
+
/**
|
|
2708
|
+
* Set the fee list for an item YRN. Destructive replace by default; pass
|
|
2709
|
+
* `{ partial: true }` to merge (`?partial=true`).
|
|
2710
|
+
*/
|
|
2711
|
+
async setItemFees(itemYrn, feeIds, opts = {}, auth2 = SERVICE7) {
|
|
2712
|
+
return this.ctx.http.request({
|
|
2713
|
+
method: "PUT",
|
|
2714
|
+
path: `${this.itemFeesBase()}/${encodeURIComponent(itemYrn)}/fees`,
|
|
2715
|
+
auth: auth2,
|
|
2716
|
+
body: { feeIds },
|
|
2717
|
+
...opts.partial ? { query: { partial: "true" } } : {}
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
/**
|
|
2721
|
+
* Delete item-fee mappings for a YRN. Without `feeId`, removes all mappings
|
|
2722
|
+
* for the YRN; with `feeId`, removes that single fee from the mapping.
|
|
2723
|
+
*/
|
|
2724
|
+
async deleteItemFees(itemYrn, feeId, auth2 = SERVICE7) {
|
|
2725
|
+
const base = `${this.itemFeesBase()}/${encodeURIComponent(itemYrn)}/fees`;
|
|
2726
|
+
await this.ctx.http.request({
|
|
2727
|
+
method: "DELETE",
|
|
2728
|
+
path: feeId ? `${base}/${encodeURIComponent(feeId)}` : base,
|
|
2729
|
+
auth: auth2
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
/** Search item-fee mappings by item YRNs + site. */
|
|
2733
|
+
async searchItemFees(search, auth2 = SERVICE7) {
|
|
2734
|
+
return this.ctx.http.request({
|
|
2735
|
+
method: "POST",
|
|
2736
|
+
path: `${this.itemFeesBase()}/search`,
|
|
2737
|
+
auth: auth2,
|
|
2738
|
+
body: search
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
// --- Product-fee mappings ---
|
|
2742
|
+
/** Fee mappings for a product id. */
|
|
2743
|
+
async getProductFees(productId, auth2 = SERVICE7) {
|
|
2744
|
+
return this.ctx.http.request({
|
|
2745
|
+
method: "GET",
|
|
2746
|
+
path: `${this.productFeesBase()}/${encodeURIComponent(productId)}/fees`,
|
|
2747
|
+
auth: auth2
|
|
2748
|
+
});
|
|
2749
|
+
}
|
|
2750
|
+
/**
|
|
2751
|
+
* Set the fee list for a product id. Destructive replace by default; pass
|
|
2752
|
+
* `{ partial: true }` to merge (`?partial=true`).
|
|
2753
|
+
*/
|
|
2754
|
+
async setProductFees(productId, feeIds, opts = {}, auth2 = SERVICE7) {
|
|
2755
|
+
return this.ctx.http.request({
|
|
2756
|
+
method: "PUT",
|
|
2757
|
+
path: `${this.productFeesBase()}/${encodeURIComponent(productId)}/fees`,
|
|
2758
|
+
auth: auth2,
|
|
2759
|
+
body: { feeIds },
|
|
2760
|
+
...opts.partial ? { query: { partial: "true" } } : {}
|
|
2761
|
+
});
|
|
2762
|
+
}
|
|
2763
|
+
/** Delete all fee mappings for a product id. */
|
|
2764
|
+
async deleteProductFees(productId, auth2 = SERVICE7) {
|
|
2765
|
+
await this.ctx.http.request({
|
|
2766
|
+
method: "DELETE",
|
|
2767
|
+
path: `${this.productFeesBase()}/${encodeURIComponent(productId)}/fees`,
|
|
2768
|
+
auth: auth2
|
|
2769
|
+
});
|
|
2770
|
+
}
|
|
2771
|
+
};
|
|
2772
|
+
|
|
2773
|
+
// src/services/webhook.ts
|
|
2774
|
+
var SERVICE8 = { kind: "service" };
|
|
2775
|
+
var WebhookService = class {
|
|
2776
|
+
constructor(ctx) {
|
|
2777
|
+
this.ctx = ctx;
|
|
2778
|
+
}
|
|
2779
|
+
ctx;
|
|
2780
|
+
base() {
|
|
2781
|
+
return `/webhook/${this.ctx.tenant}`;
|
|
2782
|
+
}
|
|
2783
|
+
/** List the event-subscription catalog with each event's on/off state. */
|
|
2784
|
+
async listEventSubscriptions(auth2 = SERVICE8) {
|
|
2785
|
+
return this.ctx.http.request({
|
|
2786
|
+
method: "GET",
|
|
2787
|
+
path: `${this.base()}/event-subscriptions`,
|
|
2788
|
+
auth: auth2
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
/**
|
|
2792
|
+
* Batch subscribe/unsubscribe events. Returns the **207** per-item result
|
|
2793
|
+
* array verbatim — the batch can partially fail, so inspect each element's
|
|
2794
|
+
* `code`/`status` (e.g. `results.filter(r => (r.code ?? 0) >= 400)`). Does
|
|
2795
|
+
* NOT throw on a 207 with failed items; only a non-2xx HTTP status throws.
|
|
2796
|
+
*/
|
|
2797
|
+
async updateEventSubscriptions(items, auth2 = SERVICE8) {
|
|
2798
|
+
return this.ctx.http.request({
|
|
2799
|
+
method: "PATCH",
|
|
2800
|
+
path: `${this.base()}/event-subscriptions`,
|
|
2801
|
+
auth: auth2,
|
|
2802
|
+
body: items
|
|
2803
|
+
});
|
|
2804
|
+
}
|
|
2805
|
+
/** List delivery configurations. */
|
|
2806
|
+
async listConfigs(auth2 = SERVICE8) {
|
|
2807
|
+
return this.ctx.http.request({
|
|
2808
|
+
method: "GET",
|
|
2809
|
+
path: `${this.base()}/config`,
|
|
2810
|
+
auth: auth2
|
|
2811
|
+
});
|
|
2812
|
+
}
|
|
2813
|
+
/** Retrieve one delivery configuration by code. */
|
|
2814
|
+
async getConfig(code, auth2 = SERVICE8) {
|
|
2815
|
+
return this.ctx.http.request({
|
|
2816
|
+
method: "GET",
|
|
2817
|
+
path: `${this.base()}/config/${encodeURIComponent(code)}`,
|
|
2818
|
+
auth: auth2
|
|
2819
|
+
});
|
|
2820
|
+
}
|
|
2821
|
+
/** Create a delivery configuration. Returns the server-assigned `{ code }`. */
|
|
2822
|
+
async createConfig(draft, auth2 = SERVICE8) {
|
|
2823
|
+
return this.ctx.http.request({
|
|
2824
|
+
method: "POST",
|
|
2825
|
+
path: `${this.base()}/config`,
|
|
2826
|
+
auth: auth2,
|
|
2827
|
+
body: draft
|
|
2828
|
+
});
|
|
2829
|
+
}
|
|
2830
|
+
/** Replace a delivery configuration by code (204). */
|
|
2831
|
+
async replaceConfig(code, draft, auth2 = SERVICE8) {
|
|
2832
|
+
await this.ctx.http.request({
|
|
2833
|
+
method: "PUT",
|
|
2834
|
+
path: `${this.base()}/config/${encodeURIComponent(code)}`,
|
|
2835
|
+
auth: auth2,
|
|
2836
|
+
body: draft
|
|
2837
|
+
});
|
|
2838
|
+
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Partially update a delivery configuration by code (204). The body is an
|
|
2841
|
+
* **array** of `{ op, path, value }` operations (UPSERT / REMOVE).
|
|
2842
|
+
*/
|
|
2843
|
+
async patchConfig(code, patches, auth2 = SERVICE8) {
|
|
2844
|
+
await this.ctx.http.request({
|
|
2845
|
+
method: "PATCH",
|
|
2846
|
+
path: `${this.base()}/config/${encodeURIComponent(code)}`,
|
|
2847
|
+
auth: auth2,
|
|
2848
|
+
body: patches
|
|
2849
|
+
});
|
|
2850
|
+
}
|
|
2851
|
+
/**
|
|
2852
|
+
* Delete a delivery configuration by code. Pass `{ force: true }` to delete
|
|
2853
|
+
* the currently-active config (the server otherwise rejects it).
|
|
2854
|
+
*/
|
|
2855
|
+
async deleteConfig(code, opts = {}, auth2 = SERVICE8) {
|
|
2856
|
+
await this.ctx.http.request({
|
|
2857
|
+
method: "DELETE",
|
|
2858
|
+
path: `${this.base()}/config/${encodeURIComponent(code)}`,
|
|
2859
|
+
auth: auth2,
|
|
2860
|
+
...opts.force === true ? { query: { force: "true" } } : {}
|
|
2861
|
+
});
|
|
2862
|
+
}
|
|
2863
|
+
/** Read delivery statistics over an optional `YYYY-MM` range. */
|
|
2864
|
+
async getStatistics(query = {}, auth2 = SERVICE8) {
|
|
2865
|
+
const q = {};
|
|
2866
|
+
if (query.fromYearMonth) q.fromYearMonth = query.fromYearMonth;
|
|
2867
|
+
if (query.toYearMonth) q.toYearMonth = query.toYearMonth;
|
|
2868
|
+
return this.ctx.http.request({
|
|
2869
|
+
method: "GET",
|
|
2870
|
+
path: `${this.base()}/statistics`,
|
|
2871
|
+
auth: auth2,
|
|
2872
|
+
...Object.keys(q).length > 0 ? { query: q } : {}
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2875
|
+
/** Obtain Svix dashboard access (URL / token). */
|
|
2876
|
+
async getDashboardAccess(auth2 = SERVICE8) {
|
|
2877
|
+
return this.ctx.http.request({
|
|
2878
|
+
method: "GET",
|
|
2879
|
+
path: `${this.base()}/dashboard-access`,
|
|
2880
|
+
auth: auth2
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
};
|
|
2884
|
+
|
|
2885
|
+
// src/services/schema.ts
|
|
2886
|
+
var SERVICE9 = { kind: "service" };
|
|
2887
|
+
var SchemaService = class {
|
|
2888
|
+
constructor(ctx) {
|
|
2889
|
+
this.ctx = ctx;
|
|
2890
|
+
}
|
|
2891
|
+
ctx;
|
|
2892
|
+
schemasBase() {
|
|
2893
|
+
return `/schema/${this.ctx.tenant}/schemas`;
|
|
2894
|
+
}
|
|
2895
|
+
entitiesBase() {
|
|
2896
|
+
return `/schema/${this.ctx.tenant}/custom-entities`;
|
|
2897
|
+
}
|
|
2898
|
+
instancesBase(type) {
|
|
2899
|
+
return `${this.entitiesBase()}/${encodeURIComponent(type)}/instances`;
|
|
2900
|
+
}
|
|
2901
|
+
// --- (A) Schemas ---------------------------------------------------------
|
|
2902
|
+
/**
|
|
2903
|
+
* List schemas, wrapped in the shared {@link PaginatedItems} envelope.
|
|
2904
|
+
* `hasNextPage` is the standard SDK heuristic (`items.length === pageSize`).
|
|
2905
|
+
* Pagination defaults match the rest of the SDK (`pageNumber: 1`,
|
|
2906
|
+
* `pageSize: 60`).
|
|
2907
|
+
*/
|
|
2908
|
+
async listSchemas(query = {}, auth2 = SERVICE9) {
|
|
2909
|
+
const pageNumber = query.pageNumber ?? 1;
|
|
2910
|
+
const pageSize = query.pageSize ?? 60;
|
|
2911
|
+
const q = { pageNumber, pageSize };
|
|
2912
|
+
if (query.q) q.q = query.q;
|
|
2913
|
+
if (query.type) q.type = query.type;
|
|
2914
|
+
const items = await this.ctx.http.request({
|
|
2915
|
+
method: "GET",
|
|
2916
|
+
path: this.schemasBase(),
|
|
2917
|
+
auth: auth2,
|
|
2918
|
+
query: q
|
|
2919
|
+
});
|
|
2920
|
+
return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
|
|
2921
|
+
}
|
|
2922
|
+
/** Retrieve one schema by id. */
|
|
2923
|
+
async getSchema(id, auth2 = SERVICE9) {
|
|
2924
|
+
return this.ctx.http.request({
|
|
2925
|
+
method: "GET",
|
|
2926
|
+
path: `${this.schemasBase()}/${encodeURIComponent(id)}`,
|
|
2927
|
+
auth: auth2
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2930
|
+
/** Create a schema. */
|
|
2931
|
+
async createSchema(draft, auth2 = SERVICE9) {
|
|
2932
|
+
return this.ctx.http.request({
|
|
2933
|
+
method: "POST",
|
|
2934
|
+
path: this.schemasBase(),
|
|
2935
|
+
auth: auth2,
|
|
2936
|
+
body: draft
|
|
2937
|
+
});
|
|
2938
|
+
}
|
|
2939
|
+
/**
|
|
2940
|
+
* Update a schema. The upstream API requires `draft.metadata.version`; a
|
|
2941
|
+
* stale version yields 409 Conflict (propagated as the standard conflict
|
|
2942
|
+
* error).
|
|
2943
|
+
*/
|
|
2944
|
+
async updateSchema(id, draft, auth2 = SERVICE9) {
|
|
2945
|
+
return this.ctx.http.request({
|
|
2946
|
+
method: "PUT",
|
|
2947
|
+
path: `${this.schemasBase()}/${encodeURIComponent(id)}`,
|
|
2948
|
+
auth: auth2,
|
|
2949
|
+
body: draft
|
|
2950
|
+
});
|
|
2951
|
+
}
|
|
2952
|
+
/** Delete a schema by id. */
|
|
2953
|
+
async deleteSchema(id, auth2 = SERVICE9) {
|
|
2954
|
+
await this.ctx.http.request({
|
|
2955
|
+
method: "DELETE",
|
|
2956
|
+
path: `${this.schemasBase()}/${encodeURIComponent(id)}`,
|
|
2957
|
+
auth: auth2
|
|
2958
|
+
});
|
|
2959
|
+
}
|
|
2960
|
+
/**
|
|
2961
|
+
* Validate a schema document without persisting it (`POST /schemas/file`).
|
|
2962
|
+
* Returns the server's validation result verbatim.
|
|
2963
|
+
*/
|
|
2964
|
+
async validateSchemaFile(body, auth2 = SERVICE9) {
|
|
2965
|
+
return this.ctx.http.request({
|
|
2966
|
+
method: "POST",
|
|
2967
|
+
path: `${this.schemasBase()}/file`,
|
|
2968
|
+
auth: auth2,
|
|
2969
|
+
body
|
|
2970
|
+
});
|
|
2971
|
+
}
|
|
2972
|
+
// --- (B) Types -----------------------------------------------------------
|
|
2973
|
+
/** List entity types that currently have at least one schema. */
|
|
2974
|
+
async listTypes(auth2 = SERVICE9) {
|
|
2975
|
+
return this.ctx.http.request({
|
|
2976
|
+
method: "GET",
|
|
2977
|
+
path: `/schema/${this.ctx.tenant}/types`,
|
|
2978
|
+
auth: auth2
|
|
2979
|
+
});
|
|
2980
|
+
}
|
|
2981
|
+
/** Set the entity types a schema applies to (`PUT /schemas/{id}/types`). */
|
|
2982
|
+
async setSchemaTypes(id, types, auth2 = SERVICE9) {
|
|
2983
|
+
return this.ctx.http.request({
|
|
2984
|
+
method: "PUT",
|
|
2985
|
+
path: `${this.schemasBase()}/${encodeURIComponent(id)}/types`,
|
|
2986
|
+
auth: auth2,
|
|
2987
|
+
body: { types }
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
// --- (C) Custom entities -------------------------------------------------
|
|
2991
|
+
/** List custom-entity definitions. `expandSchemas` inlines each schema body. */
|
|
2992
|
+
async listCustomEntities(opts = {}, auth2 = SERVICE9) {
|
|
2993
|
+
return this.ctx.http.request({
|
|
2994
|
+
method: "GET",
|
|
2995
|
+
path: this.entitiesBase(),
|
|
2996
|
+
auth: auth2,
|
|
2997
|
+
...opts.expandSchemas ? { query: { expandSchemas: "true" } } : {}
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3000
|
+
/** Retrieve one custom-entity definition by id. */
|
|
3001
|
+
async getCustomEntity(id, auth2 = SERVICE9) {
|
|
3002
|
+
return this.ctx.http.request({
|
|
3003
|
+
method: "GET",
|
|
3004
|
+
path: `${this.entitiesBase()}/${encodeURIComponent(id)}`,
|
|
3005
|
+
auth: auth2
|
|
3006
|
+
});
|
|
3007
|
+
}
|
|
3008
|
+
/** Create a custom-entity definition. */
|
|
3009
|
+
async createCustomEntity(draft, auth2 = SERVICE9) {
|
|
3010
|
+
return this.ctx.http.request({
|
|
3011
|
+
method: "POST",
|
|
3012
|
+
path: this.entitiesBase(),
|
|
3013
|
+
auth: auth2,
|
|
3014
|
+
body: draft
|
|
3015
|
+
});
|
|
3016
|
+
}
|
|
3017
|
+
/** Update a custom-entity definition. */
|
|
3018
|
+
async updateCustomEntity(id, draft, auth2 = SERVICE9) {
|
|
3019
|
+
return this.ctx.http.request({
|
|
3020
|
+
method: "PUT",
|
|
3021
|
+
path: `${this.entitiesBase()}/${encodeURIComponent(id)}`,
|
|
3022
|
+
auth: auth2,
|
|
3023
|
+
body: draft
|
|
3024
|
+
});
|
|
3025
|
+
}
|
|
3026
|
+
/**
|
|
3027
|
+
* Delete a custom-entity definition. The server rejects with 409 if
|
|
3028
|
+
* instances or schemas still reference it (propagated as the standard
|
|
3029
|
+
* conflict error).
|
|
3030
|
+
*/
|
|
3031
|
+
async deleteCustomEntity(id, auth2 = SERVICE9) {
|
|
3032
|
+
await this.ctx.http.request({
|
|
3033
|
+
method: "DELETE",
|
|
3034
|
+
path: `${this.entitiesBase()}/${encodeURIComponent(id)}`,
|
|
3035
|
+
auth: auth2
|
|
3036
|
+
});
|
|
3037
|
+
}
|
|
3038
|
+
// --- (D) Custom instances ------------------------------------------------
|
|
3039
|
+
/**
|
|
3040
|
+
* List a custom entity's instances, wrapped in {@link PaginatedItems}.
|
|
3041
|
+
* `type` is the custom-entity type and is always the first argument.
|
|
3042
|
+
*/
|
|
3043
|
+
async listInstances(type, query = {}, auth2 = SERVICE9) {
|
|
3044
|
+
const pageNumber = query.pageNumber ?? 1;
|
|
3045
|
+
const pageSize = query.pageSize ?? 60;
|
|
3046
|
+
const items = await this.ctx.http.request({
|
|
3047
|
+
method: "GET",
|
|
3048
|
+
path: this.instancesBase(type),
|
|
3049
|
+
auth: auth2,
|
|
3050
|
+
query: { ...query, pageNumber, pageSize }
|
|
3051
|
+
});
|
|
3052
|
+
return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
|
|
3053
|
+
}
|
|
3054
|
+
/** Retrieve one instance by id. */
|
|
3055
|
+
async getInstance(type, id, auth2 = SERVICE9) {
|
|
3056
|
+
return this.ctx.http.request({
|
|
3057
|
+
method: "GET",
|
|
3058
|
+
path: `${this.instancesBase(type)}/${encodeURIComponent(id)}`,
|
|
3059
|
+
auth: auth2
|
|
3060
|
+
});
|
|
3061
|
+
}
|
|
3062
|
+
/** Create an instance of a custom entity. */
|
|
3063
|
+
async createInstance(type, draft, auth2 = SERVICE9) {
|
|
3064
|
+
return this.ctx.http.request({
|
|
3065
|
+
method: "POST",
|
|
3066
|
+
path: this.instancesBase(type),
|
|
3067
|
+
auth: auth2,
|
|
3068
|
+
body: draft
|
|
3069
|
+
});
|
|
3070
|
+
}
|
|
3071
|
+
/** Replace an instance (full `PUT`). */
|
|
3072
|
+
async replaceInstance(type, id, draft, auth2 = SERVICE9) {
|
|
3073
|
+
return this.ctx.http.request({
|
|
3074
|
+
method: "PUT",
|
|
3075
|
+
path: `${this.instancesBase(type)}/${encodeURIComponent(id)}`,
|
|
3076
|
+
auth: auth2,
|
|
3077
|
+
body: draft
|
|
3078
|
+
});
|
|
3079
|
+
}
|
|
3080
|
+
/** Partially update an instance (`PATCH`). */
|
|
3081
|
+
async patchInstance(type, id, patch, auth2 = SERVICE9) {
|
|
3082
|
+
return this.ctx.http.request({
|
|
3083
|
+
method: "PATCH",
|
|
3084
|
+
path: `${this.instancesBase(type)}/${encodeURIComponent(id)}`,
|
|
3085
|
+
auth: auth2,
|
|
3086
|
+
body: patch
|
|
3087
|
+
});
|
|
3088
|
+
}
|
|
3089
|
+
/** Delete an instance by id. */
|
|
3090
|
+
async deleteInstance(type, id, auth2 = SERVICE9) {
|
|
3091
|
+
await this.ctx.http.request({
|
|
3092
|
+
method: "DELETE",
|
|
3093
|
+
path: `${this.instancesBase(type)}/${encodeURIComponent(id)}`,
|
|
3094
|
+
auth: auth2
|
|
3095
|
+
});
|
|
3096
|
+
}
|
|
3097
|
+
/**
|
|
3098
|
+
* Structured search over a custom entity's instances
|
|
3099
|
+
* (`POST /instances/search`), wrapped in {@link PaginatedItems}.
|
|
3100
|
+
*/
|
|
3101
|
+
async searchInstances(type, body, auth2 = SERVICE9) {
|
|
3102
|
+
const items = await this.ctx.http.request({
|
|
3103
|
+
method: "POST",
|
|
3104
|
+
path: `${this.instancesBase(type)}/search`,
|
|
3105
|
+
auth: auth2,
|
|
3106
|
+
body
|
|
3107
|
+
});
|
|
3108
|
+
return { items, pageNumber: 1, pageSize: items.length, hasNextPage: false };
|
|
3109
|
+
}
|
|
3110
|
+
};
|
|
3111
|
+
|
|
3112
|
+
// src/services/ai.ts
|
|
3113
|
+
var SERVICE10 = { kind: "service" };
|
|
3114
|
+
var AiService = class {
|
|
3115
|
+
constructor(ctx) {
|
|
3116
|
+
this.ctx = ctx;
|
|
3117
|
+
}
|
|
3118
|
+
ctx;
|
|
3119
|
+
base() {
|
|
3120
|
+
return `/ai-service/${this.ctx.tenant}`;
|
|
3121
|
+
}
|
|
3122
|
+
/** Generate text from a single prompt (`POST /texts`). Honors `maxTokens`. */
|
|
3123
|
+
async generateText(input, auth2 = SERVICE10) {
|
|
3124
|
+
return this.ctx.http.request({
|
|
3125
|
+
method: "POST",
|
|
3126
|
+
path: `${this.base()}/texts`,
|
|
3127
|
+
auth: auth2,
|
|
3128
|
+
body: input
|
|
3129
|
+
});
|
|
3130
|
+
}
|
|
3131
|
+
/** Run a chat completion over a message list (`POST /completions`). No `maxTokens`. */
|
|
3132
|
+
async complete(input, auth2 = SERVICE10) {
|
|
3133
|
+
return this.ctx.http.request({
|
|
3134
|
+
method: "POST",
|
|
3135
|
+
path: `${this.base()}/completions`,
|
|
3136
|
+
auth: auth2,
|
|
3137
|
+
body: input
|
|
3138
|
+
});
|
|
3139
|
+
}
|
|
3140
|
+
/** List all agentic agents. */
|
|
3141
|
+
async listAgents(auth2 = SERVICE10) {
|
|
3142
|
+
return this.ctx.http.request({
|
|
3143
|
+
method: "GET",
|
|
3144
|
+
path: `${this.base()}/agentic/agents`,
|
|
3145
|
+
auth: auth2
|
|
3146
|
+
});
|
|
3147
|
+
}
|
|
3148
|
+
/** Retrieve one agent by id. */
|
|
3149
|
+
async getAgent(id, auth2 = SERVICE10) {
|
|
3150
|
+
return this.ctx.http.request({
|
|
3151
|
+
method: "GET",
|
|
3152
|
+
path: `${this.base()}/agentic/agents/${encodeURIComponent(id)}`,
|
|
3153
|
+
auth: auth2
|
|
3154
|
+
});
|
|
3155
|
+
}
|
|
3156
|
+
/** Create-or-replace an agent by id (`PUT`). Takes the agent write shape. */
|
|
3157
|
+
async upsertAgent(id, agent, auth2 = SERVICE10) {
|
|
3158
|
+
return this.ctx.http.request({
|
|
3159
|
+
method: "PUT",
|
|
3160
|
+
path: `${this.base()}/agentic/agents/${encodeURIComponent(id)}`,
|
|
3161
|
+
auth: auth2,
|
|
3162
|
+
body: agent
|
|
3163
|
+
});
|
|
3164
|
+
}
|
|
3165
|
+
/**
|
|
3166
|
+
* Patch an agent with an op array (`PATCH`). `ops` use the upstream
|
|
3167
|
+
* UPPERCASE enum (`ADD | REMOVE | REPLACE`) and are sent verbatim — this is
|
|
3168
|
+
* NOT RFC-6902 JSON-Patch.
|
|
3169
|
+
*/
|
|
3170
|
+
async patchAgent(id, ops, auth2 = SERVICE10) {
|
|
3171
|
+
return this.ctx.http.request({
|
|
3172
|
+
method: "PATCH",
|
|
3173
|
+
path: `${this.base()}/agentic/agents/${encodeURIComponent(id)}`,
|
|
3174
|
+
auth: auth2,
|
|
3175
|
+
body: ops
|
|
3176
|
+
});
|
|
3177
|
+
}
|
|
3178
|
+
/**
|
|
3179
|
+
* Delete an agent by id. Pass `{ force: true }` to delete an agent that is
|
|
3180
|
+
* still referenced elsewhere (`?force=true`).
|
|
3181
|
+
*/
|
|
3182
|
+
async deleteAgent(id, auth2 = SERVICE10, opts = {}) {
|
|
3183
|
+
await this.ctx.http.request({
|
|
3184
|
+
method: "DELETE",
|
|
3185
|
+
path: `${this.base()}/agentic/agents/${encodeURIComponent(id)}`,
|
|
3186
|
+
auth: auth2,
|
|
3187
|
+
...opts.force ? { query: { force: "true" } } : {}
|
|
3188
|
+
});
|
|
3189
|
+
}
|
|
3190
|
+
/** Server-side agent search (`POST /agentic/agents/search`). */
|
|
3191
|
+
async searchAgents(query, auth2 = SERVICE10) {
|
|
3192
|
+
return this.ctx.http.request({
|
|
3193
|
+
method: "POST",
|
|
3194
|
+
path: `${this.base()}/agentic/agents/search`,
|
|
3195
|
+
auth: auth2,
|
|
3196
|
+
body: query
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3199
|
+
/**
|
|
3200
|
+
* Synchronous agent chat (`POST /agentic/chat`). Returns the response
|
|
3201
|
+
* ARRAY verbatim (the upstream contract is an array, not a single object).
|
|
3202
|
+
*/
|
|
3203
|
+
async chat(input, auth2 = SERVICE10) {
|
|
3204
|
+
return this.ctx.http.request({
|
|
3205
|
+
method: "POST",
|
|
3206
|
+
path: `${this.base()}/agentic/chat`,
|
|
3207
|
+
auth: auth2,
|
|
3208
|
+
body: input
|
|
3209
|
+
});
|
|
3210
|
+
}
|
|
3211
|
+
/**
|
|
3212
|
+
* Fire-and-forget agent chat (`POST /agentic/chat-async`, HTTP 201).
|
|
3213
|
+
* Returns the job-id ARRAY verbatim.
|
|
3214
|
+
*/
|
|
3215
|
+
async chatAsync(input, auth2 = SERVICE10) {
|
|
3216
|
+
return this.ctx.http.request({
|
|
3217
|
+
method: "POST",
|
|
3218
|
+
path: `${this.base()}/agentic/chat-async`,
|
|
3219
|
+
auth: auth2,
|
|
3220
|
+
body: input
|
|
3221
|
+
});
|
|
3222
|
+
}
|
|
3223
|
+
};
|
|
3224
|
+
|
|
3225
|
+
// package.json
|
|
3226
|
+
var version = "2.3.0";
|
|
3227
|
+
|
|
3228
|
+
// src/version.ts
|
|
3229
|
+
var SDK_VERSION = version;
|
|
3230
|
+
|
|
2235
3231
|
// src/client.ts
|
|
2236
|
-
var SDK_VERSION = "0.0.0";
|
|
2237
3232
|
var EmporixClient = class {
|
|
2238
3233
|
customers;
|
|
2239
3234
|
products;
|
|
@@ -2253,6 +3248,15 @@ var EmporixClient = class {
|
|
|
2253
3248
|
orders;
|
|
2254
3249
|
salesOrders;
|
|
2255
3250
|
availability;
|
|
3251
|
+
tenantConfig;
|
|
3252
|
+
clientConfig;
|
|
3253
|
+
shoppingLists;
|
|
3254
|
+
ragIndexer;
|
|
3255
|
+
sequentialIds;
|
|
3256
|
+
fees;
|
|
3257
|
+
webhooks;
|
|
3258
|
+
schemas;
|
|
3259
|
+
ai;
|
|
2256
3260
|
/** The validated tenant this client is bound to. */
|
|
2257
3261
|
tenant;
|
|
2258
3262
|
/**
|
|
@@ -2323,6 +3327,15 @@ var EmporixClient = class {
|
|
|
2323
3327
|
this.orders = new OrdersService(mk("orders"));
|
|
2324
3328
|
this.salesOrders = new SalesOrdersService(mk("sales-orders"));
|
|
2325
3329
|
this.availability = new AvailabilityService(mk("availability"));
|
|
3330
|
+
this.tenantConfig = new TenantConfigService(mk("configuration"));
|
|
3331
|
+
this.clientConfig = new ClientConfigService(mk("configuration"));
|
|
3332
|
+
this.shoppingLists = new ShoppingListService(mk("shopping-list"));
|
|
3333
|
+
this.ragIndexer = new RagIndexerService(mk("ai-rag-indexer"));
|
|
3334
|
+
this.sequentialIds = new SequentialIdService(mk("sequential-id"));
|
|
3335
|
+
this.fees = new FeeService(mk("fee"));
|
|
3336
|
+
this.webhooks = new WebhookService(mk("webhook"));
|
|
3337
|
+
this.schemas = new SchemaService(mk("schema"));
|
|
3338
|
+
this.ai = new AiService(mk("ai"));
|
|
2326
3339
|
}
|
|
2327
3340
|
/** Sets the runtime log level globally or for one service. */
|
|
2328
3341
|
setLogLevel(level, opts = {}) {
|
|
@@ -2334,10 +3347,12 @@ var EmporixClient = class {
|
|
|
2334
3347
|
}
|
|
2335
3348
|
};
|
|
2336
3349
|
|
|
3350
|
+
exports.AiService = AiService;
|
|
2337
3351
|
exports.AvailabilityService = AvailabilityService;
|
|
2338
3352
|
exports.CartService = CartService;
|
|
2339
3353
|
exports.CategoryService = CategoryService;
|
|
2340
3354
|
exports.CheckoutService = CheckoutService;
|
|
3355
|
+
exports.ClientConfigService = ClientConfigService;
|
|
2341
3356
|
exports.CompaniesService = CompaniesService;
|
|
2342
3357
|
exports.ContactsService = ContactsService;
|
|
2343
3358
|
exports.CustomerGroupsService = CustomerGroupsService;
|
|
@@ -2352,6 +3367,7 @@ exports.EmporixInsufficientScopeError = EmporixInsufficientScopeError;
|
|
|
2352
3367
|
exports.EmporixNotFoundError = EmporixNotFoundError;
|
|
2353
3368
|
exports.EmporixServerError = EmporixServerError;
|
|
2354
3369
|
exports.EmporixValidationError = EmporixValidationError;
|
|
3370
|
+
exports.FeeService = FeeService;
|
|
2355
3371
|
exports.HttpClient = HttpClient;
|
|
2356
3372
|
exports.LEVEL = LEVEL;
|
|
2357
3373
|
exports.LevelResolver = LevelResolver;
|
|
@@ -2361,10 +3377,16 @@ exports.OrdersService = OrdersService;
|
|
|
2361
3377
|
exports.PaymentGatewayService = PaymentGatewayService;
|
|
2362
3378
|
exports.PriceService = PriceService;
|
|
2363
3379
|
exports.ProductService = ProductService;
|
|
3380
|
+
exports.RagIndexerService = RagIndexerService;
|
|
2364
3381
|
exports.SalesOrdersService = SalesOrdersService;
|
|
3382
|
+
exports.SchemaService = SchemaService;
|
|
2365
3383
|
exports.SegmentService = SegmentService;
|
|
3384
|
+
exports.SequentialIdService = SequentialIdService;
|
|
2366
3385
|
exports.SessionContextService = SessionContextService;
|
|
3386
|
+
exports.ShoppingListService = ShoppingListService;
|
|
2367
3387
|
exports.SiteService = SiteService;
|
|
3388
|
+
exports.TenantConfigService = TenantConfigService;
|
|
3389
|
+
exports.WebhookService = WebhookService;
|
|
2368
3390
|
exports.auth = auth;
|
|
2369
3391
|
exports.createConsoleLogger = createConsoleLogger;
|
|
2370
3392
|
exports.createNoopLogger = createNoopLogger;
|