@viu/emporix-sdk 2.22.0 → 2.25.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 +144 -0
- package/README.md +16 -6
- package/dist/availability.cjs +118 -0
- package/dist/availability.cjs.map +1 -1
- package/dist/availability.d.cts +178 -2
- package/dist/availability.d.ts +178 -2
- package/dist/availability.js +1 -1
- package/dist/cart.cjs +156 -11
- package/dist/cart.cjs.map +1 -1
- package/dist/cart.d.cts +177 -4
- package/dist/cart.d.ts +177 -4
- package/dist/cart.js +1 -1
- package/dist/category.cjs +192 -2
- package/dist/category.cjs.map +1 -1
- package/dist/category.d.cts +399 -2
- package/dist/category.d.ts +399 -2
- package/dist/category.js +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/{chunk-HD5RBCM6.js → chunk-27NLS646.js} +10 -2
- package/dist/chunk-27NLS646.js.map +1 -0
- package/dist/{chunk-MMX5FGMI.js → chunk-6PJFOX3A.js} +109 -2
- package/dist/chunk-6PJFOX3A.js.map +1 -0
- package/dist/chunk-HWVFF6B2.js +378 -0
- package/dist/chunk-HWVFF6B2.js.map +1 -0
- package/dist/chunk-LQFRJSVT.js +224 -0
- package/dist/chunk-LQFRJSVT.js.map +1 -0
- package/dist/chunk-P7G4LOOV.js +264 -0
- package/dist/chunk-P7G4LOOV.js.map +1 -0
- package/dist/{chunk-44F52KRE.js → chunk-QQMLN76U.js} +27 -2
- package/dist/chunk-QQMLN76U.js.map +1 -0
- package/dist/chunk-UNW6SFSB.js +363 -0
- package/dist/chunk-UNW6SFSB.js.map +1 -0
- package/dist/chunk-V3275BA7.js +181 -0
- package/dist/chunk-V3275BA7.js.map +1 -0
- package/dist/chunk-W2KBVWJ2.js +323 -0
- package/dist/chunk-W2KBVWJ2.js.map +1 -0
- package/dist/{chunk-5DWCYDQD.js → chunk-YVZ6GOLE.js} +158 -13
- package/dist/chunk-YVZ6GOLE.js.map +1 -0
- package/dist/chunk-ZOFGDNSX.js +305 -0
- package/dist/chunk-ZOFGDNSX.js.map +1 -0
- package/dist/companies.cjs +25 -0
- package/dist/companies.cjs.map +1 -1
- package/dist/companies.d.cts +15 -1
- package/dist/companies.d.ts +15 -1
- package/dist/companies.js +1 -1
- package/dist/contacts.cjs +8 -0
- package/dist/contacts.cjs.map +1 -1
- package/dist/contacts.d.cts +3 -1
- package/dist/contacts.d.ts +3 -1
- package/dist/contacts.js +1 -1
- package/dist/{context-CfXJcYKP.d.cts → context-DC5gSgKK.d.cts} +18 -0
- package/dist/{context-CfXJcYKP.d.ts → context-DC5gSgKK.d.ts} +18 -0
- package/dist/customer-groups-BqYsPCA6.d.cts +706 -0
- package/dist/customer-groups-CLm6Gu9U.d.ts +706 -0
- package/dist/customer-groups.cjs +200 -17
- package/dist/customer-groups.cjs.map +1 -1
- package/dist/customer-groups.d.cts +2 -110
- package/dist/customer-groups.d.ts +2 -110
- package/dist/customer-groups.js +1 -1
- package/dist/customer.d.cts +1 -1
- package/dist/customer.d.ts +1 -1
- package/dist/index.cjs +2231 -395
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +435 -13
- package/dist/index.d.ts +435 -13
- package/dist/index.js +679 -344
- 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.cjs +160 -2
- package/dist/orders.cjs.map +1 -1
- package/dist/orders.d.cts +222 -2
- package/dist/orders.d.ts +222 -2
- package/dist/orders.js +1 -1
- package/dist/payment.cjs +107 -0
- package/dist/payment.cjs.map +1 -1
- package/dist/payment.d.cts +300 -2
- package/dist/payment.d.ts +300 -2
- package/dist/payment.js +1 -1
- package/dist/price.cjs +197 -0
- package/dist/price.cjs.map +1 -1
- package/dist/price.d.cts +578 -2
- package/dist/price.d.ts +578 -2
- package/dist/price.js +1 -1
- package/dist/product.cjs +190 -0
- package/dist/product.cjs.map +1 -1
- package/dist/product.d.cts +504 -2
- package/dist/product.d.ts +504 -2
- package/dist/product.js +1 -1
- package/dist/segment.cjs +179 -0
- package/dist/segment.cjs.map +1 -1
- package/dist/segment.d.cts +182 -2
- package/dist/segment.d.ts +182 -2
- package/dist/segment.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-36T4YPQJ.js +0 -106
- package/dist/chunk-36T4YPQJ.js.map +0 -1
- package/dist/chunk-3BTPX7IJ.js +0 -41
- package/dist/chunk-3BTPX7IJ.js.map +0 -1
- package/dist/chunk-44F52KRE.js.map +0 -1
- package/dist/chunk-5DWCYDQD.js.map +0 -1
- package/dist/chunk-A3LYJUD4.js +0 -108
- package/dist/chunk-A3LYJUD4.js.map +0 -1
- package/dist/chunk-DXOLWAOY.js +0 -188
- package/dist/chunk-DXOLWAOY.js.map +0 -1
- package/dist/chunk-FZMP5NQZ.js +0 -173
- package/dist/chunk-FZMP5NQZ.js.map +0 -1
- package/dist/chunk-HD5RBCM6.js.map +0 -1
- package/dist/chunk-IVCCGJN5.js +0 -63
- package/dist/chunk-IVCCGJN5.js.map +0 -1
- package/dist/chunk-MMX5FGMI.js.map +0 -1
- package/dist/chunk-NE7MIZPR.js +0 -144
- package/dist/chunk-NE7MIZPR.js.map +0 -1
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { iterateAll } from './chunk-GWJ2U2CP.js';
|
|
2
|
+
import { resolveQuery } from './chunk-S5HEIQDK.js';
|
|
3
|
+
|
|
4
|
+
// src/services/product.ts
|
|
5
|
+
var ANON = { kind: "anonymous" };
|
|
6
|
+
var SERVICE = { kind: "service" };
|
|
7
|
+
var ProductService = class {
|
|
8
|
+
constructor(ctx) {
|
|
9
|
+
this.ctx = ctx;
|
|
10
|
+
}
|
|
11
|
+
ctx;
|
|
12
|
+
static channel = "product";
|
|
13
|
+
/** Fetches one product by id. */
|
|
14
|
+
async get(productId, _opts, auth = ANON) {
|
|
15
|
+
return this.ctx.http.request({
|
|
16
|
+
method: "GET",
|
|
17
|
+
path: `/product/${this.ctx.tenant}/products/${productId}`,
|
|
18
|
+
auth
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** Fetches one product by its code. */
|
|
22
|
+
async getByCode(code, auth = ANON) {
|
|
23
|
+
const rows = await this.ctx.http.request({
|
|
24
|
+
method: "GET",
|
|
25
|
+
path: `/product/${this.ctx.tenant}/products`,
|
|
26
|
+
query: { q: `code:${code}` },
|
|
27
|
+
auth
|
|
28
|
+
});
|
|
29
|
+
const first = rows[0];
|
|
30
|
+
if (!first) throw new Error(`No product with code "${code}"`);
|
|
31
|
+
return first;
|
|
32
|
+
}
|
|
33
|
+
/** One page of products. */
|
|
34
|
+
async list(params = {}, auth = ANON) {
|
|
35
|
+
const pageNumber = params.pageNumber ?? 1;
|
|
36
|
+
const pageSize = params.pageSize ?? 50;
|
|
37
|
+
const items = await this.ctx.http.request({
|
|
38
|
+
method: "GET",
|
|
39
|
+
path: `/product/${this.ctx.tenant}/products`,
|
|
40
|
+
query: { pageNumber, pageSize },
|
|
41
|
+
auth
|
|
42
|
+
});
|
|
43
|
+
return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
|
|
44
|
+
}
|
|
45
|
+
/** Async-iterates every product across pages. */
|
|
46
|
+
listAll(params = {}, auth = ANON) {
|
|
47
|
+
const pageSize = params.pageSize ?? 50;
|
|
48
|
+
return iterateAll((pageNumber) => this.list({ pageNumber, pageSize }, auth));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Searches products by a `q` filter — a raw Emporix DSL string or a built
|
|
52
|
+
* filter (e.g. `@viu/emporix-mixins`' `mixinQuery(...)`). Product supports
|
|
53
|
+
* `compoundLogicalQuery`, so `or()` filters are allowed.
|
|
54
|
+
*/
|
|
55
|
+
async search(query, params = {}, auth = ANON) {
|
|
56
|
+
const q = resolveQuery(query, { compoundLogicalQuery: true });
|
|
57
|
+
const pageNumber = params.pageNumber ?? 1;
|
|
58
|
+
const pageSize = params.pageSize ?? 50;
|
|
59
|
+
const items = await this.ctx.http.request({
|
|
60
|
+
method: "GET",
|
|
61
|
+
path: `/product/${this.ctx.tenant}/products`,
|
|
62
|
+
query: { q, pageNumber, pageSize },
|
|
63
|
+
auth
|
|
64
|
+
});
|
|
65
|
+
return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Free-text product search by name. The product `q` is a `field:value` DSL,
|
|
69
|
+
* so a bare term (e.g. "in time") 400s with "No value for key …". This builds
|
|
70
|
+
* a `name:(~<term>)` regex filter (regex metacharacters escaped) and delegates
|
|
71
|
+
* to {@link search}.
|
|
72
|
+
*/
|
|
73
|
+
async searchByName(query, params = {}, auth = ANON) {
|
|
74
|
+
const escaped = query.trim().replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
75
|
+
return this.search(`name:(~${escaped})`, params, auth);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Bulk fetch by id. POSTs `/products/search` with `q="id:(id1,id2,…)"`,
|
|
79
|
+
* chunking when the list is larger than `options.chunkSize` (default
|
|
80
|
+
* 100). An empty list short-circuits with no HTTP call. **Order is not
|
|
81
|
+
* guaranteed** across chunks — re-index by `id` if order matters.
|
|
82
|
+
*/
|
|
83
|
+
async searchByIds(ids, options = {}, auth = ANON) {
|
|
84
|
+
if (ids.length === 0) return [];
|
|
85
|
+
const chunkSize = options.chunkSize ?? 100;
|
|
86
|
+
const chunks = [];
|
|
87
|
+
for (let i = 0; i < ids.length; i += chunkSize) {
|
|
88
|
+
chunks.push(ids.slice(i, i + chunkSize));
|
|
89
|
+
}
|
|
90
|
+
const pages = await Promise.all(
|
|
91
|
+
chunks.map(
|
|
92
|
+
(chunk) => this.ctx.http.request({
|
|
93
|
+
method: "POST",
|
|
94
|
+
path: `/product/${this.ctx.tenant}/products/search`,
|
|
95
|
+
query: { pageSize: chunk.length },
|
|
96
|
+
auth,
|
|
97
|
+
body: { q: `id:(${chunk.join(",")})` },
|
|
98
|
+
idempotent: true
|
|
99
|
+
// pure read over POST — safe to replay on 5xx/429
|
|
100
|
+
})
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
return pages.flat();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Bulk fetch by code. POSTs `/products/search` with `q="code:(c1,c2,…)"`,
|
|
107
|
+
* chunking when the list is larger than `options.chunkSize` (default 100).
|
|
108
|
+
* Duplicate codes are de-duplicated. Codes containing query-delimiter
|
|
109
|
+
* characters (`(`, `)`, `,`, whitespace, `"`) are dropped with a logged
|
|
110
|
+
* warning, because the Emporix `q` syntax uses them as delimiters and does
|
|
111
|
+
* not support escaping them in a plain IN-list. An empty list — or one with
|
|
112
|
+
* no safe codes — short-circuits with no HTTP call. **Order is not
|
|
113
|
+
* guaranteed** across chunks — re-index by `code` if order matters.
|
|
114
|
+
*/
|
|
115
|
+
async searchByCodes(codes, options = {}, auth = ANON) {
|
|
116
|
+
const unique = [...new Set(codes)];
|
|
117
|
+
const unsafe = /[(),"\s]/;
|
|
118
|
+
const safe = unique.filter((c) => !unsafe.test(c));
|
|
119
|
+
const dropped = unique.filter((c) => unsafe.test(c));
|
|
120
|
+
if (dropped.length > 0) {
|
|
121
|
+
this.ctx.logger.warn(
|
|
122
|
+
"products.searchByCodes: dropped codes containing query-delimiter characters",
|
|
123
|
+
{ dropped }
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (safe.length === 0) return [];
|
|
127
|
+
const chunkSize = options.chunkSize ?? 100;
|
|
128
|
+
const chunks = [];
|
|
129
|
+
for (let i = 0; i < safe.length; i += chunkSize) {
|
|
130
|
+
chunks.push(safe.slice(i, i + chunkSize));
|
|
131
|
+
}
|
|
132
|
+
const pages = await Promise.all(
|
|
133
|
+
chunks.map(
|
|
134
|
+
(chunk) => this.ctx.http.request({
|
|
135
|
+
method: "POST",
|
|
136
|
+
path: `/product/${this.ctx.tenant}/products/search`,
|
|
137
|
+
query: { pageSize: chunk.length },
|
|
138
|
+
auth,
|
|
139
|
+
body: { q: `code:(${chunk.join(",")})` },
|
|
140
|
+
idempotent: true
|
|
141
|
+
// pure read over POST — safe to replay on 5xx/429
|
|
142
|
+
})
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
return pages.flat();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Streams the VARIANT children of a PARENT_VARIANT product, page by page,
|
|
149
|
+
* via the search query `productType:VARIANT parentVariantId:<id>`. Default
|
|
150
|
+
* pageSize 200. The query syntax (space-separated fields = implicit AND) is
|
|
151
|
+
* encapsulated here so consumers don't build it themselves.
|
|
152
|
+
*/
|
|
153
|
+
listVariantChildrenAll(parentVariantId, params = {}, auth = ANON) {
|
|
154
|
+
const pageSize = params.pageSize ?? 200;
|
|
155
|
+
const q = `productType:VARIANT parentVariantId:${parentVariantId}`;
|
|
156
|
+
return iterateAll((pageNumber) => this.search(q, { pageNumber, pageSize }, auth));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Resolves ALL VARIANT children of a PARENT_VARIANT product into a flat
|
|
160
|
+
* array (loads every page). Default pageSize 200. Returns `[]` when there are
|
|
161
|
+
* no children — never throws.
|
|
162
|
+
*/
|
|
163
|
+
async listVariantChildren(parentVariantId, params = {}, auth = ANON) {
|
|
164
|
+
const out = [];
|
|
165
|
+
for await (const child of this.listVariantChildrenAll(parentVariantId, params, auth)) {
|
|
166
|
+
out.push(child);
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
// --- Admin writes. Default auth: service. ---
|
|
171
|
+
/**
|
|
172
|
+
* Creates a product (`POST /products`). Default auth: service. Accepts any of
|
|
173
|
+
* the five product shapes (basic, bundle, parent-variant, variant,
|
|
174
|
+
* dynamic-variant).
|
|
175
|
+
*/
|
|
176
|
+
async create(input, options = {}, auth = SERVICE) {
|
|
177
|
+
const query = {
|
|
178
|
+
...options.skipVariantGeneration === void 0 ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) },
|
|
179
|
+
...options.doIndex === void 0 ? {} : { doIndex: String(options.doIndex) },
|
|
180
|
+
...options.skipRelatedItemsValidation === void 0 ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }
|
|
181
|
+
};
|
|
182
|
+
return this.ctx.http.request({
|
|
183
|
+
method: "POST",
|
|
184
|
+
path: `/product/${this.ctx.tenant}/products`,
|
|
185
|
+
...Object.keys(query).length > 0 ? { query } : {},
|
|
186
|
+
body: input,
|
|
187
|
+
auth
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Partially updates a product (`PATCH /products/{productId}`). Default auth:
|
|
192
|
+
* service. Use {@link replace} for a full replace (PUT).
|
|
193
|
+
*/
|
|
194
|
+
async update(productId, input, options = {}, auth = SERVICE) {
|
|
195
|
+
const query = {
|
|
196
|
+
...options.skipVariantGeneration === void 0 ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) },
|
|
197
|
+
...options.doIndex === void 0 ? {} : { doIndex: String(options.doIndex) },
|
|
198
|
+
...options.skipRelatedItemsValidation === void 0 ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }
|
|
199
|
+
};
|
|
200
|
+
await this.ctx.http.request({
|
|
201
|
+
method: "PATCH",
|
|
202
|
+
path: `/product/${this.ctx.tenant}/products/${productId}`,
|
|
203
|
+
...Object.keys(query).length > 0 ? { query } : {},
|
|
204
|
+
body: input,
|
|
205
|
+
auth
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Full-replaces a product (`PUT /products/{productId}`). Returns the created
|
|
210
|
+
* resource on 201 (upsert) and nothing on 204. `options.partial` sends
|
|
211
|
+
* `?partial=true` for a merge-style replace. Default auth: service.
|
|
212
|
+
*/
|
|
213
|
+
async replace(productId, input, options = {}, auth = SERVICE) {
|
|
214
|
+
const query = {
|
|
215
|
+
...options.partial === void 0 ? {} : { partial: String(options.partial) },
|
|
216
|
+
...options.skipVariantGeneration === void 0 ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) },
|
|
217
|
+
...options.doIndex === void 0 ? {} : { doIndex: String(options.doIndex) },
|
|
218
|
+
...options.skipRelatedItemsValidation === void 0 ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }
|
|
219
|
+
};
|
|
220
|
+
return this.ctx.http.request({
|
|
221
|
+
method: "PUT",
|
|
222
|
+
path: `/product/${this.ctx.tenant}/products/${productId}`,
|
|
223
|
+
...Object.keys(query).length > 0 ? { query } : {},
|
|
224
|
+
body: input,
|
|
225
|
+
auth
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Deletes a product (`DELETE /products/{productId}`). `options.force` deletes
|
|
230
|
+
* even when the product is referenced. Default auth: service.
|
|
231
|
+
*/
|
|
232
|
+
async delete(productId, options = {}, auth = SERVICE) {
|
|
233
|
+
const query = {
|
|
234
|
+
...options.force === void 0 ? {} : { force: String(options.force) },
|
|
235
|
+
...options.doIndex === void 0 ? {} : { doIndex: String(options.doIndex) }
|
|
236
|
+
};
|
|
237
|
+
await this.ctx.http.request({
|
|
238
|
+
method: "DELETE",
|
|
239
|
+
path: `/product/${this.ctx.tenant}/products/${productId}`,
|
|
240
|
+
...Object.keys(query).length > 0 ? { query } : {},
|
|
241
|
+
auth
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Bulk-creates products (`POST /products/bulk`). Responds 207 Multi-Status:
|
|
246
|
+
* partial failures do **not** throw — inspect each entry. Default auth: service.
|
|
247
|
+
*/
|
|
248
|
+
async bulkCreate(input, options = {}, auth = SERVICE) {
|
|
249
|
+
const query = {
|
|
250
|
+
...options.skipVariantGeneration === void 0 ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) },
|
|
251
|
+
...options.doIndex === void 0 ? {} : { doIndex: String(options.doIndex) },
|
|
252
|
+
...options.skipRelatedItemsValidation === void 0 ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }
|
|
253
|
+
};
|
|
254
|
+
return this.ctx.http.request({
|
|
255
|
+
method: "POST",
|
|
256
|
+
path: `/product/${this.ctx.tenant}/products/bulk`,
|
|
257
|
+
...Object.keys(query).length > 0 ? { query } : {},
|
|
258
|
+
body: input,
|
|
259
|
+
auth
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Bulk-updates products (`PUT /products/bulk`). Responds 207 Multi-Status:
|
|
264
|
+
* partial failures do **not** throw — inspect each entry. Default auth: service.
|
|
265
|
+
*/
|
|
266
|
+
async bulkUpdate(input, options = {}, auth = SERVICE) {
|
|
267
|
+
const query = {
|
|
268
|
+
...options.skipVariantGeneration === void 0 ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) },
|
|
269
|
+
...options.doIndex === void 0 ? {} : { doIndex: String(options.doIndex) },
|
|
270
|
+
...options.skipRelatedItemsValidation === void 0 ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }
|
|
271
|
+
};
|
|
272
|
+
return this.ctx.http.request({
|
|
273
|
+
method: "PUT",
|
|
274
|
+
path: `/product/${this.ctx.tenant}/products/bulk`,
|
|
275
|
+
...Object.keys(query).length > 0 ? { query } : {},
|
|
276
|
+
body: input,
|
|
277
|
+
auth
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Triggers a dynamic-variant recalculation for the given product ids
|
|
282
|
+
* (`POST /products/recalculate`, 202). The result carries the created or
|
|
283
|
+
* already-referenced `jobs` plus `skippedProductIds` — products whose root
|
|
284
|
+
* already has a PENDING/PROCESSING job. Default auth: service.
|
|
285
|
+
*/
|
|
286
|
+
async recalculate(input, auth = SERVICE) {
|
|
287
|
+
return this.ctx.http.request({
|
|
288
|
+
method: "POST",
|
|
289
|
+
path: `/product/${this.ctx.tenant}/products/recalculate`,
|
|
290
|
+
body: input,
|
|
291
|
+
auth
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
/** Lists dynamic-variant recalculation jobs, optionally filtered by status. Default auth: anonymous. */
|
|
295
|
+
async listRecalculationJobs(params = {}, auth = ANON) {
|
|
296
|
+
return this.ctx.http.request({
|
|
297
|
+
method: "GET",
|
|
298
|
+
path: `/product/${this.ctx.tenant}/products/recalculate/jobs`,
|
|
299
|
+
...params.status === void 0 ? {} : { query: { status: params.status } },
|
|
300
|
+
auth
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
/** Fetches one dynamic-variant recalculation job by id. Default auth: anonymous. */
|
|
304
|
+
async getRecalculationJob(jobId, auth = ANON) {
|
|
305
|
+
return this.ctx.http.request({
|
|
306
|
+
method: "GET",
|
|
307
|
+
path: `/product/${this.ctx.tenant}/products/recalculate/jobs/${jobId}`,
|
|
308
|
+
auth
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Product templates (`/product-templates`). Reads default to anonymous,
|
|
313
|
+
* writes to service auth.
|
|
314
|
+
*/
|
|
315
|
+
templates = {
|
|
316
|
+
/** One page of product templates. Default auth: anonymous. */
|
|
317
|
+
list: async (params = {}, auth = ANON) => this.ctx.http.request({
|
|
318
|
+
method: "GET",
|
|
319
|
+
path: `/product/${this.ctx.tenant}/product-templates`,
|
|
320
|
+
query: {
|
|
321
|
+
...params.pageNumber === void 0 ? {} : { pageNumber: params.pageNumber },
|
|
322
|
+
...params.pageSize === void 0 ? {} : { pageSize: params.pageSize },
|
|
323
|
+
...params.sort === void 0 ? {} : { sort: params.sort },
|
|
324
|
+
...params.q === void 0 ? {} : { q: params.q }
|
|
325
|
+
},
|
|
326
|
+
auth
|
|
327
|
+
}),
|
|
328
|
+
/** Fetches one product template by id. Default auth: anonymous. */
|
|
329
|
+
get: async (templateId, auth = ANON) => this.ctx.http.request({
|
|
330
|
+
method: "GET",
|
|
331
|
+
path: `/product/${this.ctx.tenant}/product-templates/${templateId}`,
|
|
332
|
+
auth
|
|
333
|
+
}),
|
|
334
|
+
/** Creates a product template. Default auth: service. */
|
|
335
|
+
create: async (input, auth = SERVICE) => this.ctx.http.request({
|
|
336
|
+
method: "POST",
|
|
337
|
+
path: `/product/${this.ctx.tenant}/product-templates`,
|
|
338
|
+
body: input,
|
|
339
|
+
auth
|
|
340
|
+
}),
|
|
341
|
+
/** Full-replaces a product template (`PUT`). Default auth: service. */
|
|
342
|
+
update: async (templateId, input, auth = SERVICE) => {
|
|
343
|
+
await this.ctx.http.request({
|
|
344
|
+
method: "PUT",
|
|
345
|
+
path: `/product/${this.ctx.tenant}/product-templates/${templateId}`,
|
|
346
|
+
body: input,
|
|
347
|
+
auth
|
|
348
|
+
});
|
|
349
|
+
},
|
|
350
|
+
/** Deletes a product template. Default auth: service. */
|
|
351
|
+
delete: async (templateId, auth = SERVICE) => {
|
|
352
|
+
await this.ctx.http.request({
|
|
353
|
+
method: "DELETE",
|
|
354
|
+
path: `/product/${this.ctx.tenant}/product-templates/${templateId}`,
|
|
355
|
+
auth
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
export { ProductService };
|
|
362
|
+
//# sourceMappingURL=chunk-UNW6SFSB.js.map
|
|
363
|
+
//# sourceMappingURL=chunk-UNW6SFSB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/product.ts"],"names":[],"mappings":";;;;AAyBA,IAAM,IAAA,GAAoB,EAAE,IAAA,EAAM,WAAA,EAAY;AAC9C,IAAM,OAAA,GAAuB,EAAE,IAAA,EAAM,SAAA,EAAU;AA6DxC,IAAM,iBAAN,MAAqB;AAAA,EAE1B,YAA6B,GAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAAqB;AAAA,EAArB,GAAA;AAAA,EAD7B,OAAgB,OAAA,GAAU,SAAA;AAAA;AAAA,EAI1B,MAAM,GAAA,CACJ,SAAA,EACA,KAA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AA,CAAA;AAAA,MACjE;AAAA,KACD,CAAA;AAAA;AAAA,IAGH,MAAA,EAAQ,OACN,KAAA,EACA,IAAA,GAAoB,YAEpB,IAAA,CAAK,GAAA,CAAI,KAAK,OAAA,CAAgC;AAAA,MAC5C,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM,CAAA,SAAA,EAAY,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,kBAAA,CAAA;AAAA,MACjC,IAAA,EAAM,KAAA;AAAA,MACN;AAAA,KACD,CAAA;AAAA;AAAA,IAGH,MAAA,EAAQ,OACN,UAAA,EACA,KAAA,EACA,OAAoB,OAAA,KACF;AAClB,MAAA,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAc;AAAA,QAChC,MAAA,EAAQ,KAAA;AAAA,QACR,MAAM,CAAA,SAAA,EAAY,IAAA,CAAK,GAAA,CAAI,MAAM,sBAAsB,UAAU,CAAA,CAAA;AAAA,QACjE,IAAA,EAAM,KAAA;AAAA,QACN;AAAA,OACD,CAAA;AAAA,IACH,CAAA;AAAA;AAAA,IAGA,MAAA,EAAQ,OAAO,UAAA,EAAoB,IAAA,GAAoB,OAAA,KAA2B;AAChF,MAAA,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAc;AAAA,QAChC,MAAA,EAAQ,QAAA;AAAA,QACR,MAAM,CAAA,SAAA,EAAY,IAAA,CAAK,GAAA,CAAI,MAAM,sBAAsB,UAAU,CAAA,CAAA;AAAA,QACjE;AAAA,OACD,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"chunk-UNW6SFSB.js","sourcesContent":["import type { ClientContext, PaginatedItems } from \"../core/context\";\nimport { iterateAll } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { resolveQuery, type QueryFor } from \"../core/query\";\nimport type {\n BasicProductWithId,\n BundleProductWithId,\n ParentVariantProductWithId,\n ProductMedia,\n ProductCreateBody,\n ProductUpdateBody,\n ProductPartialUpdateBody,\n ProductBulkCreateBody,\n ProductBulkUpdateBody,\n BulkResponse,\n ResourceLocation,\n DynamicVariantRecalculationRequest,\n DynamicVariantRecalculationResponse,\n DynamicVariantRecalculationJobResponse,\n DynamicVariantRecalculationJobStatus,\n ProductTemplateResponse,\n ProductTemplateCreation,\n ProductTemplateUpdate,\n} from \"../generated/product\";\n\nconst ANON: AuthContext = { kind: \"anonymous\" };\nconst SERVICE: AuthContext = { kind: \"service\" };\n\n/** A product as returned by the Product service (all generated fields). */\nexport type Product = BasicProductWithId | BundleProductWithId | ParentVariantProductWithId;\n\n/** A single product media entry (generated; `ProductMedia` is the list type). */\nexport type Media = ProductMedia[number];\n\n/** Body for creating a product (`POST /products`) — any of the 5 product shapes. */\nexport type ProductCreateInput = ProductCreateBody;\n\n/** Body for a full product replace (`PUT /products/{id}`). */\nexport type ProductUpdateInput = ProductUpdateBody;\n\n/** Body for a partial product update (`PATCH /products/{id}`). */\nexport type ProductPatchInput = ProductPartialUpdateBody;\n\n/** Id/location envelope returned when a product is created. */\nexport type ProductCreated = ResourceLocation;\n\n/** Body for bulk-creating products (`POST /products/bulk`). */\nexport type ProductBulkCreateInput = ProductBulkCreateBody;\n\n/** Body for bulk-updating products (`PUT /products/bulk`). */\nexport type ProductBulkUpdateInput = ProductBulkUpdateBody;\n\n/** Per-entry result of a bulk product operation (207 Multi-Status). */\nexport type ProductBulkResult = BulkResponse;\n\n/** Body for triggering a dynamic-variant recalculation. */\nexport type ProductRecalculationInput = DynamicVariantRecalculationRequest;\n\n/** Result of triggering a recalculation — created jobs plus skipped product ids. */\nexport type ProductRecalculationResult = DynamicVariantRecalculationResponse;\n\n/** A dynamic-variant recalculation job. */\nexport type ProductRecalculationJob = DynamicVariantRecalculationJobResponse;\n\n/** Status of a recalculation job. */\nexport type ProductRecalculationJobStatus = DynamicVariantRecalculationJobStatus;\n\n/** A product template as returned by the Product service. */\nexport type ProductTemplate = ProductTemplateResponse;\n\n/** Body for creating a product template. */\nexport type ProductTemplateCreateInput = ProductTemplateCreation;\n\n/** Body for updating a product template (`PUT`, full replace). */\nexport type ProductTemplateUpdateInput = ProductTemplateUpdate;\n\n/** Id envelope returned when a product template is created. */\nexport type ProductTemplateCreated = { id?: string };\n\n/** Query flags shared by the product write endpoints. */\nexport interface ProductWriteOptions {\n skipVariantGeneration?: boolean;\n doIndex?: boolean;\n skipRelatedItemsValidation?: boolean;\n}\n\n/** Catalog reads. Default auth: anonymous; pass customer for personalized pricing. */\nexport class ProductService {\n static readonly channel = \"product\" as const;\n constructor(private readonly ctx: ClientContext) {}\n\n /** Fetches one product by id. */\n async get(\n productId: string,\n _opts?: Record<string, never>,\n auth: AuthContext = ANON,\n ): Promise<Product> {\n return this.ctx.http.request<Product>({\n method: \"GET\",\n path: `/product/${this.ctx.tenant}/products/${productId}`,\n auth,\n });\n }\n\n /** Fetches one product by its code. */\n async getByCode(code: string, auth: AuthContext = ANON): Promise<Product> {\n const rows = await this.ctx.http.request<Product[]>({\n method: \"GET\",\n path: `/product/${this.ctx.tenant}/products`,\n query: { q: `code:${code}` },\n auth,\n });\n const first = rows[0];\n if (!first) throw new Error(`No product with code \"${code}\"`);\n return first;\n }\n\n /** One page of products. */\n async list(\n params: { pageNumber?: number; pageSize?: number } = {},\n auth: AuthContext = ANON,\n ): Promise<PaginatedItems<Product>> {\n const pageNumber = params.pageNumber ?? 1;\n const pageSize = params.pageSize ?? 50;\n const items = await this.ctx.http.request<Product[]>({\n method: \"GET\",\n path: `/product/${this.ctx.tenant}/products`,\n query: { pageNumber, pageSize },\n auth,\n });\n return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };\n }\n\n /** Async-iterates every product across pages. */\n listAll(params: { pageSize?: number } = {}, auth: AuthContext = ANON): AsyncIterable<Product> {\n const pageSize = params.pageSize ?? 50;\n return iterateAll<Product>((pageNumber) => this.list({ pageNumber, pageSize }, auth));\n }\n\n /**\n * Searches products by a `q` filter — a raw Emporix DSL string or a built\n * filter (e.g. `@viu/emporix-mixins`' `mixinQuery(...)`). Product supports\n * `compoundLogicalQuery`, so `or()` filters are allowed.\n */\n async search(\n query: QueryFor<\"PRODUCT\">,\n params: { pageNumber?: number; pageSize?: number } = {},\n auth: AuthContext = ANON,\n ): Promise<PaginatedItems<Product>> {\n const q = resolveQuery(query, { compoundLogicalQuery: true });\n const pageNumber = params.pageNumber ?? 1;\n const pageSize = params.pageSize ?? 50;\n const items = await this.ctx.http.request<Product[]>({\n method: \"GET\",\n path: `/product/${this.ctx.tenant}/products`,\n query: { q, pageNumber, pageSize },\n auth,\n });\n return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };\n }\n\n /**\n * Free-text product search by name. The product `q` is a `field:value` DSL,\n * so a bare term (e.g. \"in time\") 400s with \"No value for key …\". This builds\n * a `name:(~<term>)` regex filter (regex metacharacters escaped) and delegates\n * to {@link search}.\n */\n async searchByName(\n query: string,\n params: { pageNumber?: number; pageSize?: number } = {},\n auth: AuthContext = ANON,\n ): Promise<PaginatedItems<Product>> {\n const escaped = query.trim().replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n return this.search(`name:(~${escaped})`, params, auth);\n }\n\n /**\n * Bulk fetch by id. POSTs `/products/search` with `q=\"id:(id1,id2,…)\"`,\n * chunking when the list is larger than `options.chunkSize` (default\n * 100). An empty list short-circuits with no HTTP call. **Order is not\n * guaranteed** across chunks — re-index by `id` if order matters.\n */\n async searchByIds(\n ids: string[],\n options: { chunkSize?: number } = {},\n auth: AuthContext = ANON,\n ): Promise<Product[]> {\n if (ids.length === 0) return [];\n const chunkSize = options.chunkSize ?? 100;\n const chunks: string[][] = [];\n for (let i = 0; i < ids.length; i += chunkSize) {\n chunks.push(ids.slice(i, i + chunkSize));\n }\n const pages = await Promise.all(\n chunks.map((chunk) =>\n this.ctx.http.request<Product[]>({\n method: \"POST\",\n path: `/product/${this.ctx.tenant}/products/search`,\n query: { pageSize: chunk.length },\n auth,\n body: { q: `id:(${chunk.join(\",\")})` },\n idempotent: true, // pure read over POST — safe to replay on 5xx/429\n }),\n ),\n );\n return pages.flat();\n }\n\n /**\n * Bulk fetch by code. POSTs `/products/search` with `q=\"code:(c1,c2,…)\"`,\n * chunking when the list is larger than `options.chunkSize` (default 100).\n * Duplicate codes are de-duplicated. Codes containing query-delimiter\n * characters (`(`, `)`, `,`, whitespace, `\"`) are dropped with a logged\n * warning, because the Emporix `q` syntax uses them as delimiters and does\n * not support escaping them in a plain IN-list. An empty list — or one with\n * no safe codes — short-circuits with no HTTP call. **Order is not\n * guaranteed** across chunks — re-index by `code` if order matters.\n */\n async searchByCodes(\n codes: string[],\n options: { chunkSize?: number } = {},\n auth: AuthContext = ANON,\n ): Promise<Product[]> {\n const unique = [...new Set(codes)];\n const unsafe = /[(),\"\\s]/;\n const safe = unique.filter((c) => !unsafe.test(c));\n const dropped = unique.filter((c) => unsafe.test(c));\n if (dropped.length > 0) {\n this.ctx.logger.warn(\n \"products.searchByCodes: dropped codes containing query-delimiter characters\",\n { dropped },\n );\n }\n if (safe.length === 0) return [];\n const chunkSize = options.chunkSize ?? 100;\n const chunks: string[][] = [];\n for (let i = 0; i < safe.length; i += chunkSize) {\n chunks.push(safe.slice(i, i + chunkSize));\n }\n const pages = await Promise.all(\n chunks.map((chunk) =>\n this.ctx.http.request<Product[]>({\n method: \"POST\",\n path: `/product/${this.ctx.tenant}/products/search`,\n query: { pageSize: chunk.length },\n auth,\n body: { q: `code:(${chunk.join(\",\")})` },\n idempotent: true, // pure read over POST — safe to replay on 5xx/429\n }),\n ),\n );\n return pages.flat();\n }\n\n /**\n * Streams the VARIANT children of a PARENT_VARIANT product, page by page,\n * via the search query `productType:VARIANT parentVariantId:<id>`. Default\n * pageSize 200. The query syntax (space-separated fields = implicit AND) is\n * encapsulated here so consumers don't build it themselves.\n */\n listVariantChildrenAll(\n parentVariantId: string,\n params: { pageSize?: number } = {},\n auth: AuthContext = ANON,\n ): AsyncIterable<Product> {\n const pageSize = params.pageSize ?? 200;\n const q = `productType:VARIANT parentVariantId:${parentVariantId}`;\n return iterateAll<Product>((pageNumber) => this.search(q, { pageNumber, pageSize }, auth));\n }\n\n /**\n * Resolves ALL VARIANT children of a PARENT_VARIANT product into a flat\n * array (loads every page). Default pageSize 200. Returns `[]` when there are\n * no children — never throws.\n */\n async listVariantChildren(\n parentVariantId: string,\n params: { pageSize?: number } = {},\n auth: AuthContext = ANON,\n ): Promise<Product[]> {\n const out: Product[] = [];\n for await (const child of this.listVariantChildrenAll(parentVariantId, params, auth)) {\n out.push(child);\n }\n return out;\n }\n\n // --- Admin writes. Default auth: service. ---\n\n /**\n * Creates a product (`POST /products`). Default auth: service. Accepts any of\n * the five product shapes (basic, bundle, parent-variant, variant,\n * dynamic-variant).\n */\n async create(\n input: ProductCreateInput,\n options: ProductWriteOptions = {},\n auth: AuthContext = SERVICE,\n ): Promise<ProductCreated> {\n const query = {\n ...(options.skipVariantGeneration === undefined ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) }),\n ...(options.doIndex === undefined ? {} : { doIndex: String(options.doIndex) }),\n ...(options.skipRelatedItemsValidation === undefined ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }),\n };\n return this.ctx.http.request<ProductCreated>({\n method: \"POST\",\n path: `/product/${this.ctx.tenant}/products`,\n ...(Object.keys(query).length > 0 ? { query } : {}),\n body: input,\n auth,\n });\n }\n\n /**\n * Partially updates a product (`PATCH /products/{productId}`). Default auth:\n * service. Use {@link replace} for a full replace (PUT).\n */\n async update(\n productId: string,\n input: ProductPatchInput,\n options: ProductWriteOptions = {},\n auth: AuthContext = SERVICE,\n ): Promise<void> {\n const query = {\n ...(options.skipVariantGeneration === undefined ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) }),\n ...(options.doIndex === undefined ? {} : { doIndex: String(options.doIndex) }),\n ...(options.skipRelatedItemsValidation === undefined ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }),\n };\n await this.ctx.http.request<void>({\n method: \"PATCH\",\n path: `/product/${this.ctx.tenant}/products/${productId}`,\n ...(Object.keys(query).length > 0 ? { query } : {}),\n body: input,\n auth,\n });\n }\n\n /**\n * Full-replaces a product (`PUT /products/{productId}`). Returns the created\n * resource on 201 (upsert) and nothing on 204. `options.partial` sends\n * `?partial=true` for a merge-style replace. Default auth: service.\n */\n async replace(\n productId: string,\n input: ProductUpdateInput,\n options: ProductWriteOptions & { partial?: boolean } = {},\n auth: AuthContext = SERVICE,\n ): Promise<ProductCreated | void> {\n const query = {\n ...(options.partial === undefined ? {} : { partial: String(options.partial) }),\n ...(options.skipVariantGeneration === undefined ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) }),\n ...(options.doIndex === undefined ? {} : { doIndex: String(options.doIndex) }),\n ...(options.skipRelatedItemsValidation === undefined ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }),\n };\n return this.ctx.http.request<ProductCreated | void>({\n method: \"PUT\",\n path: `/product/${this.ctx.tenant}/products/${productId}`,\n ...(Object.keys(query).length > 0 ? { query } : {}),\n body: input,\n auth,\n });\n }\n\n /**\n * Deletes a product (`DELETE /products/{productId}`). `options.force` deletes\n * even when the product is referenced. Default auth: service.\n */\n async delete(\n productId: string,\n options: { force?: boolean; doIndex?: boolean } = {},\n auth: AuthContext = SERVICE,\n ): Promise<void> {\n const query = {\n ...(options.force === undefined ? {} : { force: String(options.force) }),\n ...(options.doIndex === undefined ? {} : { doIndex: String(options.doIndex) }),\n };\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `/product/${this.ctx.tenant}/products/${productId}`,\n ...(Object.keys(query).length > 0 ? { query } : {}),\n auth,\n });\n }\n\n /**\n * Bulk-creates products (`POST /products/bulk`). Responds 207 Multi-Status:\n * partial failures do **not** throw — inspect each entry. Default auth: service.\n */\n async bulkCreate(\n input: ProductBulkCreateInput,\n options: ProductWriteOptions = {},\n auth: AuthContext = SERVICE,\n ): Promise<ProductBulkResult[]> {\n const query = {\n ...(options.skipVariantGeneration === undefined ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) }),\n ...(options.doIndex === undefined ? {} : { doIndex: String(options.doIndex) }),\n ...(options.skipRelatedItemsValidation === undefined ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }),\n };\n return this.ctx.http.request<ProductBulkResult[]>({\n method: \"POST\",\n path: `/product/${this.ctx.tenant}/products/bulk`,\n ...(Object.keys(query).length > 0 ? { query } : {}),\n body: input,\n auth,\n });\n }\n\n /**\n * Bulk-updates products (`PUT /products/bulk`). Responds 207 Multi-Status:\n * partial failures do **not** throw — inspect each entry. Default auth: service.\n */\n async bulkUpdate(\n input: ProductBulkUpdateInput,\n options: ProductWriteOptions = {},\n auth: AuthContext = SERVICE,\n ): Promise<ProductBulkResult[]> {\n const query = {\n ...(options.skipVariantGeneration === undefined ? {} : { skipVariantGeneration: String(options.skipVariantGeneration) }),\n ...(options.doIndex === undefined ? {} : { doIndex: String(options.doIndex) }),\n ...(options.skipRelatedItemsValidation === undefined ? {} : { skipRelatedItemsValidation: String(options.skipRelatedItemsValidation) }),\n };\n return this.ctx.http.request<ProductBulkResult[]>({\n method: \"PUT\",\n path: `/product/${this.ctx.tenant}/products/bulk`,\n ...(Object.keys(query).length > 0 ? { query } : {}),\n body: input,\n auth,\n });\n }\n\n /**\n * Triggers a dynamic-variant recalculation for the given product ids\n * (`POST /products/recalculate`, 202). The result carries the created or\n * already-referenced `jobs` plus `skippedProductIds` — products whose root\n * already has a PENDING/PROCESSING job. Default auth: service.\n */\n async recalculate(\n input: ProductRecalculationInput,\n auth: AuthContext = SERVICE,\n ): Promise<ProductRecalculationResult> {\n return this.ctx.http.request<ProductRecalculationResult>({\n method: \"POST\",\n path: `/product/${this.ctx.tenant}/products/recalculate`,\n body: input,\n auth,\n });\n }\n\n /** Lists dynamic-variant recalculation jobs, optionally filtered by status. Default auth: anonymous. */\n async listRecalculationJobs(\n params: { status?: ProductRecalculationJobStatus } = {},\n auth: AuthContext = ANON,\n ): Promise<ProductRecalculationJob[]> {\n return this.ctx.http.request<ProductRecalculationJob[]>({\n method: \"GET\",\n path: `/product/${this.ctx.tenant}/products/recalculate/jobs`,\n ...(params.status === undefined ? {} : { query: { status: params.status } }),\n auth,\n });\n }\n\n /** Fetches one dynamic-variant recalculation job by id. Default auth: anonymous. */\n async getRecalculationJob(jobId: string, auth: AuthContext = ANON): Promise<ProductRecalculationJob> {\n return this.ctx.http.request<ProductRecalculationJob>({\n method: \"GET\",\n path: `/product/${this.ctx.tenant}/products/recalculate/jobs/${jobId}`,\n auth,\n });\n }\n\n /**\n * Product templates (`/product-templates`). Reads default to anonymous,\n * writes to service auth.\n */\n readonly templates = {\n /** One page of product templates. Default auth: anonymous. */\n list: async (\n params: { pageNumber?: number; pageSize?: number; sort?: string; q?: string } = {},\n auth: AuthContext = ANON,\n ): Promise<ProductTemplate[]> =>\n this.ctx.http.request<ProductTemplate[]>({\n method: \"GET\",\n path: `/product/${this.ctx.tenant}/product-templates`,\n query: {\n ...(params.pageNumber === undefined ? {} : { pageNumber: params.pageNumber }),\n ...(params.pageSize === undefined ? {} : { pageSize: params.pageSize }),\n ...(params.sort === undefined ? {} : { sort: params.sort }),\n ...(params.q === undefined ? {} : { q: params.q }),\n },\n auth,\n }),\n\n /** Fetches one product template by id. Default auth: anonymous. */\n get: async (templateId: string, auth: AuthContext = ANON): Promise<ProductTemplate> =>\n this.ctx.http.request<ProductTemplate>({\n method: \"GET\",\n path: `/product/${this.ctx.tenant}/product-templates/${templateId}`,\n auth,\n }),\n\n /** Creates a product template. Default auth: service. */\n create: async (\n input: ProductTemplateCreateInput,\n auth: AuthContext = SERVICE,\n ): Promise<ProductTemplateCreated> =>\n this.ctx.http.request<ProductTemplateCreated>({\n method: \"POST\",\n path: `/product/${this.ctx.tenant}/product-templates`,\n body: input,\n auth,\n }),\n\n /** Full-replaces a product template (`PUT`). Default auth: service. */\n update: async (\n templateId: string,\n input: ProductTemplateUpdateInput,\n auth: AuthContext = SERVICE,\n ): Promise<void> => {\n await this.ctx.http.request<void>({\n method: \"PUT\",\n path: `/product/${this.ctx.tenant}/product-templates/${templateId}`,\n body: input,\n auth,\n });\n },\n\n /** Deletes a product template. Default auth: service. */\n delete: async (templateId: string, auth: AuthContext = SERVICE): Promise<void> => {\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `/product/${this.ctx.tenant}/product-templates/${templateId}`,\n auth,\n });\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { EmporixNotFoundError } from './chunk-UWGGF4MC.js';
|
|
2
|
+
|
|
3
|
+
// src/services/availability.ts
|
|
4
|
+
var ANON = { kind: "anonymous" };
|
|
5
|
+
var SERVICE = { kind: "service" };
|
|
6
|
+
var AvailabilityService = class {
|
|
7
|
+
constructor(ctx) {
|
|
8
|
+
this.ctx = ctx;
|
|
9
|
+
}
|
|
10
|
+
ctx;
|
|
11
|
+
static channel = "availability";
|
|
12
|
+
/**
|
|
13
|
+
* Single product. Resolves the availability record, or — when
|
|
14
|
+
* `opts.defaultAvailableOnNotFound` is set — a default available record on 404.
|
|
15
|
+
*/
|
|
16
|
+
async get(productId, siteCode, auth = ANON, opts = {}) {
|
|
17
|
+
try {
|
|
18
|
+
return await this.ctx.http.request({
|
|
19
|
+
method: "GET",
|
|
20
|
+
path: `/availability/${this.ctx.tenant}/availability/${encodeURIComponent(
|
|
21
|
+
productId
|
|
22
|
+
)}/${encodeURIComponent(siteCode)}`,
|
|
23
|
+
auth
|
|
24
|
+
});
|
|
25
|
+
} catch (err) {
|
|
26
|
+
if (err instanceof EmporixNotFoundError && opts.defaultAvailableOnNotFound) {
|
|
27
|
+
return { productId, site: siteCode, available: true };
|
|
28
|
+
}
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Batch read via `POST .../availability/search` (one request). Products with
|
|
34
|
+
* no availability record are absent from the response; each is synthesized as
|
|
35
|
+
* `{ available: false }` (or `{ available: true }` when
|
|
36
|
+
* `opts.defaultAvailableOnNotFound` is set). The result preserves input order
|
|
37
|
+
* and length. An empty `productIds` resolves to `[]` without a request.
|
|
38
|
+
*/
|
|
39
|
+
async getMany(productIds, siteCode, auth = ANON, opts = {}) {
|
|
40
|
+
if (productIds.length === 0) return [];
|
|
41
|
+
const found = await this.ctx.http.request({
|
|
42
|
+
method: "POST",
|
|
43
|
+
path: `/availability/${this.ctx.tenant}/availability/search`,
|
|
44
|
+
auth,
|
|
45
|
+
query: { site: siteCode, pageSize: productIds.length },
|
|
46
|
+
body: productIds,
|
|
47
|
+
idempotent: true
|
|
48
|
+
// pure read over POST — safe to replay on 5xx/429
|
|
49
|
+
});
|
|
50
|
+
const byId = /* @__PURE__ */ new Map();
|
|
51
|
+
for (const a of found) if (a.productId) byId.set(a.productId, a);
|
|
52
|
+
return productIds.map(
|
|
53
|
+
(id) => byId.get(id) ?? {
|
|
54
|
+
productId: id,
|
|
55
|
+
site: siteCode,
|
|
56
|
+
available: Boolean(opts.defaultAvailableOnNotFound)
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Lists every availability record for a site (`GET /availability/site/{site}`),
|
|
62
|
+
* wrapped into `PaginatedItems`. Default auth: anonymous.
|
|
63
|
+
*/
|
|
64
|
+
async listForSite(siteCode, params = {}, auth = ANON) {
|
|
65
|
+
const pageNumber = params.pageNumber ?? 1;
|
|
66
|
+
const pageSize = params.pageSize ?? 50;
|
|
67
|
+
const items = await this.ctx.http.request({
|
|
68
|
+
method: "GET",
|
|
69
|
+
path: `/availability/${this.ctx.tenant}/availability/site/${encodeURIComponent(siteCode)}`,
|
|
70
|
+
query: {
|
|
71
|
+
pageNumber,
|
|
72
|
+
pageSize,
|
|
73
|
+
...params.q === void 0 ? {} : { q: params.q },
|
|
74
|
+
...params.sort === void 0 ? {} : { sort: params.sort }
|
|
75
|
+
},
|
|
76
|
+
auth
|
|
77
|
+
});
|
|
78
|
+
return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
|
|
79
|
+
}
|
|
80
|
+
// --- Admin writes. Default auth: service. ---
|
|
81
|
+
/**
|
|
82
|
+
* Creates an availability record for a product on a site
|
|
83
|
+
* (`POST /availability/{productId}/{site}`). Responds 409 when the record
|
|
84
|
+
* already exists — use {@link update} to upsert. Default auth: service.
|
|
85
|
+
*/
|
|
86
|
+
async create(productId, siteCode, input, auth = SERVICE) {
|
|
87
|
+
return this.ctx.http.request({
|
|
88
|
+
method: "POST",
|
|
89
|
+
path: `/availability/${this.ctx.tenant}/availability/${encodeURIComponent(
|
|
90
|
+
productId
|
|
91
|
+
)}/${encodeURIComponent(siteCode)}`,
|
|
92
|
+
body: input,
|
|
93
|
+
auth
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Upserts a product's availability on a site
|
|
98
|
+
* (`PUT /availability/{productId}/{site}`). Returns the created record's id
|
|
99
|
+
* on 201 and nothing on 204. This endpoint has no PATCH counterpart.
|
|
100
|
+
* Default auth: service.
|
|
101
|
+
*/
|
|
102
|
+
async update(productId, siteCode, input, auth = SERVICE) {
|
|
103
|
+
return this.ctx.http.request({
|
|
104
|
+
method: "PUT",
|
|
105
|
+
path: `/availability/${this.ctx.tenant}/availability/${encodeURIComponent(
|
|
106
|
+
productId
|
|
107
|
+
)}/${encodeURIComponent(siteCode)}`,
|
|
108
|
+
body: input,
|
|
109
|
+
auth
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Deletes a product's availability on a site
|
|
114
|
+
* (`DELETE /availability/{productId}/{site}`). Default auth: service.
|
|
115
|
+
*/
|
|
116
|
+
async delete(productId, siteCode, auth = SERVICE) {
|
|
117
|
+
await this.ctx.http.request({
|
|
118
|
+
method: "DELETE",
|
|
119
|
+
path: `/availability/${this.ctx.tenant}/availability/${encodeURIComponent(
|
|
120
|
+
productId
|
|
121
|
+
)}/${encodeURIComponent(siteCode)}`,
|
|
122
|
+
auth
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Bulk-creates availability records (`POST /availability/bulk`). Responds 207
|
|
127
|
+
* Multi-Status: partial failures do **not** throw — inspect each entry.
|
|
128
|
+
*
|
|
129
|
+
* `options.vendorId` limits the operation to a vendor's products. It is sent
|
|
130
|
+
* as the `vendor-id` header. **Note:** the OpenAPI schema spells this header
|
|
131
|
+
* `venodr-id`, which is an evident upstream typo (the body field is
|
|
132
|
+
* `vendorId`); the SDK sends the corrected name. Unverified against the live
|
|
133
|
+
* API — if the service really expects the misspelling, the filter silently
|
|
134
|
+
* has no effect.
|
|
135
|
+
*
|
|
136
|
+
* Default auth: service.
|
|
137
|
+
*/
|
|
138
|
+
async bulkCreate(input, options = {}, auth = SERVICE) {
|
|
139
|
+
return this.ctx.http.request({
|
|
140
|
+
method: "POST",
|
|
141
|
+
path: `/availability/${this.ctx.tenant}/availability/bulk`,
|
|
142
|
+
...options.vendorId === void 0 ? {} : { headers: { "vendor-id": options.vendorId } },
|
|
143
|
+
body: input,
|
|
144
|
+
auth
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Bulk-updates availability records (`PUT /availability/bulk`). Responds 207
|
|
149
|
+
* Multi-Status: partial failures do **not** throw — inspect each entry. See
|
|
150
|
+
* {@link bulkCreate} for the `vendorId` header caveat. Default auth: service.
|
|
151
|
+
*/
|
|
152
|
+
async bulkUpdate(input, options = {}, auth = SERVICE) {
|
|
153
|
+
return this.ctx.http.request({
|
|
154
|
+
method: "PUT",
|
|
155
|
+
path: `/availability/${this.ctx.tenant}/availability/bulk`,
|
|
156
|
+
...options.vendorId === void 0 ? {} : { headers: { "vendor-id": options.vendorId } },
|
|
157
|
+
body: input,
|
|
158
|
+
auth
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Bulk-deletes availability records (`DELETE /availability/bulk`). Unusually
|
|
163
|
+
* for a DELETE, this endpoint takes a body listing the records to remove.
|
|
164
|
+
* Responds 207 Multi-Status: partial failures do **not** throw — inspect each
|
|
165
|
+
* entry. See {@link bulkCreate} for the `vendorId` header caveat. Default
|
|
166
|
+
* auth: service.
|
|
167
|
+
*/
|
|
168
|
+
async bulkDelete(input, options = {}, auth = SERVICE) {
|
|
169
|
+
return this.ctx.http.request({
|
|
170
|
+
method: "DELETE",
|
|
171
|
+
path: `/availability/${this.ctx.tenant}/availability/bulk`,
|
|
172
|
+
...options.vendorId === void 0 ? {} : { headers: { "vendor-id": options.vendorId } },
|
|
173
|
+
body: input,
|
|
174
|
+
auth
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export { AvailabilityService };
|
|
180
|
+
//# sourceMappingURL=chunk-V3275BA7.js.map
|
|
181
|
+
//# sourceMappingURL=chunk-V3275BA7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/availability.ts"],"names":[],"mappings":";;;AAgCA,IAAM,IAAA,GAAoB,EAAE,IAAA,EAAM,WAAA,EAAY;AAC9C,IAAM,OAAA,GAAuB,EAAE,IAAA,EAAM,SAAA,EAAU;AAQxC,IAAM,sBAAN,MAA0B;AAAA,EAE/B,YAA6B,GAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAAqB;AAAA,EAArB,GAAA;AAAA,EAD7B,OAAgB,OAAA,GAAU,cAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO1B,MAAM,IACJ,SAAA,EACA,QAAA,EACA,OAAoB,IAAA,EACpB,IAAA,GAA4B,EAAC,EACN;AACvB,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAsB;AAAA,QAC/C,MAAA,EAAQ,KAAA;AAAA,QACR,IAAA,EAAM,CAAA,cAAA,EAAiB,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,cAAA,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OAAA,CAAQ,QAAA,KAAa,MAAA,GAAY,EAAC,GAAI,EAAE,OAAA,EAAS,EAAE,WAAA,EAAa,OAAA,CAAQ,QAAA,EAAS,EAAE;AAAA,MACvF,IAAA,EAAM,KAAA;AAAA,MACN;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-V3275BA7.js","sourcesContent":["import type { ClientContext, PaginatedItems } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { EmporixNotFoundError } from \"../core/errors\";\nimport type {\n Availability,\n AvailabilityInput,\n AvailabilityCreated,\n AvailabilityBulkInput,\n AvailabilityBulkDeleteInput,\n AvailabilityBulkResult,\n} from \"./availability-types\";\n\nexport type {\n Availability,\n AvailabilityInput,\n AvailabilityCreated,\n AvailabilityBulkInput,\n AvailabilityBulkDeleteInput,\n AvailabilityBulkResult,\n} from \"./availability-types\";\n\n/** Shared options for {@link AvailabilityService} reads. */\nexport interface AvailabilityOptions {\n /**\n * When `true`, a product with no availability record resolves to a default\n * `{ available: true }` instead of throwing (single `get`) / being marked\n * unavailable (`getMany`). Off by default — opt in for tenants that sell\n * without stock management.\n */\n defaultAvailableOnNotFound?: boolean;\n}\n\nconst ANON: AuthContext = { kind: \"anonymous\" };\nconst SERVICE: AuthContext = { kind: \"service\" };\n\n/**\n * Reads product availability per site. Default auth is anonymous (like\n * `PriceService.matchByContext`); pass a customer/raw/service context to use a\n * different token. Requires the `availability.availability_view` scope on\n * whichever token is used.\n */\nexport class AvailabilityService {\n static readonly channel = \"availability\" as const;\n constructor(private readonly ctx: ClientContext) {}\n\n /**\n * Single product. Resolves the availability record, or — when\n * `opts.defaultAvailableOnNotFound` is set — a default available record on 404.\n */\n async get(\n productId: string,\n siteCode: string,\n auth: AuthContext = ANON,\n opts: AvailabilityOptions = {},\n ): Promise<Availability> {\n try {\n return await this.ctx.http.request<Availability>({\n method: \"GET\",\n path: `/availability/${this.ctx.tenant}/availability/${encodeURIComponent(\n productId,\n )}/${encodeURIComponent(siteCode)}`,\n auth,\n });\n } catch (err) {\n if (err instanceof EmporixNotFoundError && opts.defaultAvailableOnNotFound) {\n return { productId, site: siteCode, available: true };\n }\n throw err;\n }\n }\n\n /**\n * Batch read via `POST .../availability/search` (one request). Products with\n * no availability record are absent from the response; each is synthesized as\n * `{ available: false }` (or `{ available: true }` when\n * `opts.defaultAvailableOnNotFound` is set). The result preserves input order\n * and length. An empty `productIds` resolves to `[]` without a request.\n */\n async getMany(\n productIds: string[],\n siteCode: string,\n auth: AuthContext = ANON,\n opts: AvailabilityOptions = {},\n ): Promise<Availability[]> {\n if (productIds.length === 0) return [];\n const found = await this.ctx.http.request<Availability[]>({\n method: \"POST\",\n path: `/availability/${this.ctx.tenant}/availability/search`,\n auth,\n query: { site: siteCode, pageSize: productIds.length },\n body: productIds,\n idempotent: true, // pure read over POST — safe to replay on 5xx/429\n });\n const byId = new Map<string, Availability>();\n for (const a of found) if (a.productId) byId.set(a.productId, a);\n return productIds.map(\n (id) =>\n byId.get(id) ?? {\n productId: id,\n site: siteCode,\n available: Boolean(opts.defaultAvailableOnNotFound),\n },\n );\n }\n\n /**\n * Lists every availability record for a site (`GET /availability/site/{site}`),\n * wrapped into `PaginatedItems`. Default auth: anonymous.\n */\n async listForSite(\n siteCode: string,\n params: { pageNumber?: number; pageSize?: number; q?: string; sort?: string } = {},\n auth: AuthContext = ANON,\n ): Promise<PaginatedItems<Availability>> {\n const pageNumber = params.pageNumber ?? 1;\n const pageSize = params.pageSize ?? 50;\n const items = await this.ctx.http.request<Availability[]>({\n method: \"GET\",\n path: `/availability/${this.ctx.tenant}/availability/site/${encodeURIComponent(siteCode)}`,\n query: {\n pageNumber,\n pageSize,\n ...(params.q === undefined ? {} : { q: params.q }),\n ...(params.sort === undefined ? {} : { sort: params.sort }),\n },\n auth,\n });\n return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };\n }\n\n // --- Admin writes. Default auth: service. ---\n\n /**\n * Creates an availability record for a product on a site\n * (`POST /availability/{productId}/{site}`). Responds 409 when the record\n * already exists — use {@link update} to upsert. Default auth: service.\n */\n async create(\n productId: string,\n siteCode: string,\n input: AvailabilityInput,\n auth: AuthContext = SERVICE,\n ): Promise<AvailabilityCreated> {\n return this.ctx.http.request<AvailabilityCreated>({\n method: \"POST\",\n path: `/availability/${this.ctx.tenant}/availability/${encodeURIComponent(\n productId,\n )}/${encodeURIComponent(siteCode)}`,\n body: input,\n auth,\n });\n }\n\n /**\n * Upserts a product's availability on a site\n * (`PUT /availability/{productId}/{site}`). Returns the created record's id\n * on 201 and nothing on 204. This endpoint has no PATCH counterpart.\n * Default auth: service.\n */\n async update(\n productId: string,\n siteCode: string,\n input: AvailabilityInput,\n auth: AuthContext = SERVICE,\n ): Promise<AvailabilityCreated | void> {\n return this.ctx.http.request<AvailabilityCreated | void>({\n method: \"PUT\",\n path: `/availability/${this.ctx.tenant}/availability/${encodeURIComponent(\n productId,\n )}/${encodeURIComponent(siteCode)}`,\n body: input,\n auth,\n });\n }\n\n /**\n * Deletes a product's availability on a site\n * (`DELETE /availability/{productId}/{site}`). Default auth: service.\n */\n async delete(productId: string, siteCode: string, auth: AuthContext = SERVICE): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `/availability/${this.ctx.tenant}/availability/${encodeURIComponent(\n productId,\n )}/${encodeURIComponent(siteCode)}`,\n auth,\n });\n }\n\n /**\n * Bulk-creates availability records (`POST /availability/bulk`). Responds 207\n * Multi-Status: partial failures do **not** throw — inspect each entry.\n *\n * `options.vendorId` limits the operation to a vendor's products. It is sent\n * as the `vendor-id` header. **Note:** the OpenAPI schema spells this header\n * `venodr-id`, which is an evident upstream typo (the body field is\n * `vendorId`); the SDK sends the corrected name. Unverified against the live\n * API — if the service really expects the misspelling, the filter silently\n * has no effect.\n *\n * Default auth: service.\n */\n async bulkCreate(\n input: AvailabilityBulkInput[],\n options: { vendorId?: string } = {},\n auth: AuthContext = SERVICE,\n ): Promise<AvailabilityBulkResult[]> {\n return this.ctx.http.request<AvailabilityBulkResult[]>({\n method: \"POST\",\n path: `/availability/${this.ctx.tenant}/availability/bulk`,\n ...(options.vendorId === undefined ? {} : { headers: { \"vendor-id\": options.vendorId } }),\n body: input,\n auth,\n });\n }\n\n /**\n * Bulk-updates availability records (`PUT /availability/bulk`). Responds 207\n * Multi-Status: partial failures do **not** throw — inspect each entry. See\n * {@link bulkCreate} for the `vendorId` header caveat. Default auth: service.\n */\n async bulkUpdate(\n input: AvailabilityBulkInput[],\n options: { vendorId?: string } = {},\n auth: AuthContext = SERVICE,\n ): Promise<AvailabilityBulkResult[]> {\n return this.ctx.http.request<AvailabilityBulkResult[]>({\n method: \"PUT\",\n path: `/availability/${this.ctx.tenant}/availability/bulk`,\n ...(options.vendorId === undefined ? {} : { headers: { \"vendor-id\": options.vendorId } }),\n body: input,\n auth,\n });\n }\n\n /**\n * Bulk-deletes availability records (`DELETE /availability/bulk`). Unusually\n * for a DELETE, this endpoint takes a body listing the records to remove.\n * Responds 207 Multi-Status: partial failures do **not** throw — inspect each\n * entry. See {@link bulkCreate} for the `vendorId` header caveat. Default\n * auth: service.\n */\n async bulkDelete(\n input: AvailabilityBulkDeleteInput[],\n options: { vendorId?: string } = {},\n auth: AuthContext = SERVICE,\n ): Promise<AvailabilityBulkResult[]> {\n return this.ctx.http.request<AvailabilityBulkResult[]>({\n method: \"DELETE\",\n path: `/availability/${this.ctx.tenant}/availability/bulk`,\n ...(options.vendorId === undefined ? {} : { headers: { \"vendor-id\": options.vendorId } }),\n body: input,\n auth,\n });\n }\n}\n"]}
|