@omni-commerce/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,2734 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all) => {
5
+ for (var name in all)
6
+ __defProp(target, name, { get: all[name], enumerable: true });
7
+ };
8
+
9
+ // src/BaseClient.ts
10
+ function normalizeClientOptions(options = {}) {
11
+ const fetchImpl = options.fetch ?? globalThis.fetch;
12
+ if (typeof fetchImpl !== "function") {
13
+ throw new Error(
14
+ "No fetch implementation found. Pass `fetch` in OmniClient options."
15
+ );
16
+ }
17
+ return {
18
+ environment: options.environment,
19
+ baseUrl: options.baseUrl,
20
+ apiKey: options.apiKey,
21
+ headers: options.headers,
22
+ timeoutInSeconds: options.timeoutInSeconds ?? 60,
23
+ maxRetries: options.maxRetries ?? 2,
24
+ fetch: fetchImpl
25
+ };
26
+ }
27
+
28
+ // src/version.ts
29
+ var SDK_VERSION = "0.1.0";
30
+ var SDK_USER_AGENT = `omnicommerce-js/${SDK_VERSION}`;
31
+
32
+ // src/environments.ts
33
+ var OmniEnvironment = {
34
+ Production: "https://omnicommerce.sg",
35
+ Local: "http://localhost:3000"
36
+ };
37
+
38
+ // src/errors/OmniError.ts
39
+ var OmniError = class extends Error {
40
+ statusCode;
41
+ body;
42
+ rawResponse;
43
+ constructor({
44
+ message,
45
+ statusCode,
46
+ body,
47
+ rawResponse
48
+ }) {
49
+ super(message ?? defaultErrorMessage(statusCode, body));
50
+ this.name = "OmniError";
51
+ this.statusCode = statusCode;
52
+ this.body = body;
53
+ this.rawResponse = rawResponse;
54
+ }
55
+ };
56
+ function defaultErrorMessage(statusCode, body) {
57
+ const fromBody = extractErrorMessage(body);
58
+ if (fromBody) return fromBody;
59
+ if (statusCode) return `Omni API error (${statusCode})`;
60
+ return "Omni API error";
61
+ }
62
+ function extractErrorMessage(body) {
63
+ if (typeof body === "string" && body.trim()) return body;
64
+ if (!body || typeof body !== "object") return void 0;
65
+ const record = body;
66
+ for (const key of ["error", "message", "detail"]) {
67
+ const value = record[key];
68
+ if (typeof value === "string" && value.trim()) return value;
69
+ }
70
+ return void 0;
71
+ }
72
+
73
+ // src/errors/OmniTimeoutError.ts
74
+ var OmniTimeoutError = class extends Error {
75
+ constructor(message = "Request timed out") {
76
+ super(message);
77
+ this.name = "OmniTimeoutError";
78
+ }
79
+ };
80
+
81
+ // src/errors/status.ts
82
+ var BadRequestError = class extends OmniError {
83
+ constructor(body, rawResponse) {
84
+ super({ message: "Bad request", statusCode: 400, body, rawResponse });
85
+ this.name = "BadRequestError";
86
+ }
87
+ };
88
+ var UnauthorizedError = class extends OmniError {
89
+ constructor(body, rawResponse) {
90
+ super({ message: "Unauthorized", statusCode: 401, body, rawResponse });
91
+ this.name = "UnauthorizedError";
92
+ }
93
+ };
94
+ var ForbiddenError = class extends OmniError {
95
+ constructor(body, rawResponse) {
96
+ super({ message: "Forbidden", statusCode: 403, body, rawResponse });
97
+ this.name = "ForbiddenError";
98
+ }
99
+ };
100
+ var NotFoundError = class extends OmniError {
101
+ constructor(body, rawResponse) {
102
+ super({ message: "Not found", statusCode: 404, body, rawResponse });
103
+ this.name = "NotFoundError";
104
+ }
105
+ };
106
+ var UnprocessableEntityError = class extends OmniError {
107
+ constructor(body, rawResponse) {
108
+ super({
109
+ message: "Unprocessable entity",
110
+ statusCode: 422,
111
+ body,
112
+ rawResponse
113
+ });
114
+ this.name = "UnprocessableEntityError";
115
+ }
116
+ };
117
+ var TooManyRequestsError = class extends OmniError {
118
+ constructor(body, rawResponse) {
119
+ super({
120
+ message: "Too many requests",
121
+ statusCode: 429,
122
+ body,
123
+ rawResponse
124
+ });
125
+ this.name = "TooManyRequestsError";
126
+ }
127
+ };
128
+ var InternalServerError = class extends OmniError {
129
+ constructor(body, rawResponse) {
130
+ super({
131
+ message: "Internal server error",
132
+ statusCode: 500,
133
+ body,
134
+ rawResponse
135
+ });
136
+ this.name = "InternalServerError";
137
+ }
138
+ };
139
+ var BadGatewayError = class extends OmniError {
140
+ constructor(body, rawResponse) {
141
+ super({ message: "Bad gateway", statusCode: 502, body, rawResponse });
142
+ this.name = "BadGatewayError";
143
+ }
144
+ };
145
+ var ServiceUnavailableError = class extends OmniError {
146
+ constructor(body, rawResponse) {
147
+ super({
148
+ message: "Service unavailable",
149
+ statusCode: 503,
150
+ body,
151
+ rawResponse
152
+ });
153
+ this.name = "ServiceUnavailableError";
154
+ }
155
+ };
156
+ function errorFromStatus(statusCode, body, rawResponse) {
157
+ switch (statusCode) {
158
+ case 400:
159
+ return new BadRequestError(body, rawResponse);
160
+ case 401:
161
+ return new UnauthorizedError(body, rawResponse);
162
+ case 403:
163
+ return new ForbiddenError(body, rawResponse);
164
+ case 404:
165
+ return new NotFoundError(body, rawResponse);
166
+ case 422:
167
+ return new UnprocessableEntityError(body, rawResponse);
168
+ case 429:
169
+ return new TooManyRequestsError(body, rawResponse);
170
+ case 500:
171
+ return new InternalServerError(body, rawResponse);
172
+ case 502:
173
+ return new BadGatewayError(body, rawResponse);
174
+ case 503:
175
+ return new ServiceUnavailableError(body, rawResponse);
176
+ default:
177
+ return new OmniError({ statusCode, body, rawResponse });
178
+ }
179
+ }
180
+
181
+ // src/core/supplier.ts
182
+ async function getSupplierValue(value) {
183
+ if (value === void 0) return void 0;
184
+ if (typeof value === "function") {
185
+ return await value();
186
+ }
187
+ return value;
188
+ }
189
+
190
+ // src/core/query.ts
191
+ var isPlainObject = (value) => Boolean(value) && Object.getPrototypeOf(value) === Object.prototype;
192
+ function toQueryString(query) {
193
+ if (!query) return "";
194
+ const params = new URLSearchParams();
195
+ for (const [key, value] of Object.entries(query)) {
196
+ appendQueryParam(params, key, value);
197
+ }
198
+ return params.toString();
199
+ }
200
+ function appendQueryParam(params, key, value) {
201
+ if (value === void 0 || value === null) return;
202
+ if (Array.isArray(value)) {
203
+ for (const item of value) appendQueryParam(params, key, item);
204
+ return;
205
+ }
206
+ if (typeof value === "boolean" || typeof value === "number") {
207
+ params.append(key, String(value));
208
+ return;
209
+ }
210
+ if (typeof value === "string") {
211
+ params.append(key, value);
212
+ return;
213
+ }
214
+ if (isPlainObject(value) || Array.isArray(value)) {
215
+ params.append(key, JSON.stringify(value));
216
+ return;
217
+ }
218
+ params.append(key, String(value));
219
+ }
220
+ function joinUrl(baseUrl, path, query) {
221
+ const trimmedBase = baseUrl.replace(/\/+$/, "");
222
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
223
+ const url = `${trimmedBase}${normalizedPath}`;
224
+ return query ? `${url}?${query}` : url;
225
+ }
226
+
227
+ // src/core/http-response-promise.ts
228
+ var HttpResponsePromise = class _HttpResponsePromise extends Promise {
229
+ #response;
230
+ constructor(executor, response) {
231
+ super(executor);
232
+ this.#response = response;
233
+ }
234
+ static from(response) {
235
+ return new _HttpResponsePromise((resolve, reject) => {
236
+ void response.then((result) => resolve(result.data), reject);
237
+ }, response);
238
+ }
239
+ withRawResponse() {
240
+ return this.#response;
241
+ }
242
+ };
243
+ function toRawResponse(response) {
244
+ return {
245
+ status: response.status,
246
+ headers: response.headers,
247
+ url: response.url
248
+ };
249
+ }
250
+
251
+ // src/core/fetcher.ts
252
+ var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]);
253
+ var OmniHttp = class {
254
+ constructor(options) {
255
+ this.options = options;
256
+ }
257
+ options;
258
+ request(init) {
259
+ return HttpResponsePromise.from(this.requestWithRaw(init));
260
+ }
261
+ async requestWithRaw(init) {
262
+ const url = await this.buildUrl(init);
263
+ const headers = await this.buildHeaders(init);
264
+ const serialized = serializeBody(init.body, headers);
265
+ const timeoutMs = (init.timeoutInSeconds ?? this.options.timeoutInSeconds) * 1e3;
266
+ const maxRetries = init.maxRetries ?? this.options.maxRetries;
267
+ const fetchImpl = this.options.fetch;
268
+ let lastError;
269
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
270
+ const controller = new AbortController();
271
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
272
+ const onAbort = () => controller.abort();
273
+ init.abortSignal?.addEventListener("abort", onAbort, { once: true });
274
+ try {
275
+ const response = await fetchImpl(url, {
276
+ method: init.method,
277
+ headers,
278
+ body: serialized.body,
279
+ signal: controller.signal
280
+ });
281
+ const rawResponse = toRawResponse(response);
282
+ if (response.ok) {
283
+ const data = await parseSuccessBody(response);
284
+ return { data, rawResponse };
285
+ }
286
+ const errorBody = await parseErrorBody(response);
287
+ if (attempt < maxRetries && shouldRetry(init.method, response.status)) {
288
+ await sleep(
289
+ retryDelayMs(attempt, response.headers.get("retry-after"))
290
+ );
291
+ continue;
292
+ }
293
+ throw errorFromStatus(response.status, errorBody, rawResponse);
294
+ } catch (error) {
295
+ lastError = error;
296
+ if (error instanceof OmniError) throw error;
297
+ const aborted = error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
298
+ if (aborted && init.abortSignal?.aborted) {
299
+ throw error;
300
+ }
301
+ if (aborted) {
302
+ lastError = new OmniTimeoutError(
303
+ `Request timed out after ${timeoutMs}ms`
304
+ );
305
+ }
306
+ if (attempt >= maxRetries || !shouldRetry(init.method, void 0)) {
307
+ throw lastError;
308
+ }
309
+ await sleep(retryDelayMs(attempt, null));
310
+ } finally {
311
+ clearTimeout(timeout);
312
+ init.abortSignal?.removeEventListener("abort", onAbort);
313
+ }
314
+ }
315
+ throw lastError;
316
+ }
317
+ async buildUrl(init) {
318
+ const baseUrl = await getSupplierValue(this.options.baseUrl) ?? await getSupplierValue(this.options.environment) ?? OmniEnvironment.Production;
319
+ const query = toQueryString({
320
+ ...init.query,
321
+ ...init.queryParams
322
+ });
323
+ return joinUrl(baseUrl, init.path, query);
324
+ }
325
+ async buildHeaders(init) {
326
+ const headers = {
327
+ Accept: "application/json",
328
+ "User-Agent": SDK_USER_AGENT
329
+ };
330
+ const apiKey = await getSupplierValue(this.options.apiKey) ?? readEnvApiKey();
331
+ if (apiKey) {
332
+ headers.Authorization = `Bearer ${apiKey}`;
333
+ }
334
+ if (this.options.headers) {
335
+ for (const [key, value] of Object.entries(this.options.headers)) {
336
+ const resolved = await getSupplierValue(value ?? void 0);
337
+ if (resolved) headers[key] = resolved;
338
+ }
339
+ }
340
+ if (init.headers) {
341
+ for (const [key, value] of Object.entries(init.headers)) {
342
+ if (value) headers[key] = value;
343
+ }
344
+ }
345
+ return headers;
346
+ }
347
+ };
348
+ function mergeRequestOptions(requestOptions) {
349
+ return {
350
+ timeoutInSeconds: requestOptions?.timeoutInSeconds,
351
+ maxRetries: requestOptions?.maxRetries,
352
+ abortSignal: requestOptions?.abortSignal,
353
+ queryParams: requestOptions?.queryParams,
354
+ headers: requestOptions?.headers
355
+ };
356
+ }
357
+ function readEnvApiKey() {
358
+ if (typeof process === "undefined" || !process.env) return void 0;
359
+ const value = process.env.OMNI_API_KEY;
360
+ return value && value.trim() ? value : void 0;
361
+ }
362
+ function serializeBody(body, headers) {
363
+ if (body === void 0 || body === null) return {};
364
+ if (typeof FormData !== "undefined" && body instanceof FormData) {
365
+ return { body };
366
+ }
367
+ if (typeof URLSearchParams !== "undefined" && body instanceof URLSearchParams) {
368
+ if (!headers["Content-Type"]) {
369
+ headers["Content-Type"] = "application/x-www-form-urlencoded";
370
+ }
371
+ return { body };
372
+ }
373
+ if (typeof Blob !== "undefined" && body instanceof Blob) {
374
+ return { body };
375
+ }
376
+ if (typeof body === "string") {
377
+ if (!headers["Content-Type"]) headers["Content-Type"] = "application/json";
378
+ return { body };
379
+ }
380
+ if (!headers["Content-Type"]) headers["Content-Type"] = "application/json";
381
+ return { body: JSON.stringify(body) };
382
+ }
383
+ async function parseSuccessBody(response) {
384
+ if (response.status === 204) return void 0;
385
+ const contentType = response.headers.get("content-type") ?? "";
386
+ if (contentType.includes("application/json")) {
387
+ const text2 = await response.text();
388
+ if (!text2) return void 0;
389
+ return JSON.parse(text2);
390
+ }
391
+ if (contentType.includes("text/")) {
392
+ return response.text();
393
+ }
394
+ const text = await response.text();
395
+ if (!text) return void 0;
396
+ try {
397
+ return JSON.parse(text);
398
+ } catch {
399
+ return text;
400
+ }
401
+ }
402
+ async function parseErrorBody(response) {
403
+ const text = await response.text();
404
+ if (!text) return void 0;
405
+ try {
406
+ return JSON.parse(text);
407
+ } catch {
408
+ return text;
409
+ }
410
+ }
411
+ function shouldRetry(method, status) {
412
+ if (status === 408 || status === 429) return true;
413
+ const idempotent = IDEMPOTENT_METHODS.has(method.toUpperCase());
414
+ if (status !== void 0) {
415
+ return idempotent && status >= 500;
416
+ }
417
+ return idempotent;
418
+ }
419
+ function retryDelayMs(attempt, retryAfter) {
420
+ if (retryAfter) {
421
+ const seconds = Number(retryAfter);
422
+ if (Number.isFinite(seconds) && seconds >= 0) {
423
+ return Math.min(seconds * 1e3, 3e4);
424
+ }
425
+ }
426
+ const base = Math.min(500 * 2 ** attempt, 8e3);
427
+ return base + Math.random() * base * 0.2;
428
+ }
429
+ function sleep(ms) {
430
+ return new Promise((resolve) => setTimeout(resolve, ms));
431
+ }
432
+
433
+ // src/core/path.ts
434
+ function encodePathParam(name, value) {
435
+ if (typeof value !== "string" || value.trim() === "") {
436
+ throw new Error(`Missing required path parameter: ${name}`);
437
+ }
438
+ return encodeURIComponent(value);
439
+ }
440
+
441
+ // src/jobs.ts
442
+ var SUCCESS_STATUSES = /* @__PURE__ */ new Set([
443
+ "completed",
444
+ "complete",
445
+ "succeeded",
446
+ "success"
447
+ ]);
448
+ var FAILURE_STATUSES = /* @__PURE__ */ new Set(["failed", "error"]);
449
+ var CANCELLED_STATUSES = /* @__PURE__ */ new Set(["cancelled", "canceled"]);
450
+ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
451
+ ...SUCCESS_STATUSES,
452
+ ...FAILURE_STATUSES,
453
+ ...CANCELLED_STATUSES
454
+ ]);
455
+ var JobFailedError = class extends OmniError {
456
+ jobStatus;
457
+ constructor(jobStatus, body) {
458
+ super({
459
+ message: `Job ended with status "${jobStatus}"`,
460
+ body
461
+ });
462
+ this.name = "JobFailedError";
463
+ this.jobStatus = jobStatus;
464
+ }
465
+ };
466
+ function readJobStatus(payload) {
467
+ if (!payload || typeof payload !== "object") return void 0;
468
+ const record = payload;
469
+ const nested = record.data;
470
+ if (nested && typeof nested === "object") {
471
+ const nestedStatus = nested.status;
472
+ if (typeof nestedStatus === "string" && nestedStatus.trim()) {
473
+ return nestedStatus;
474
+ }
475
+ }
476
+ if (typeof record.status === "string" && record.status.trim()) {
477
+ return record.status;
478
+ }
479
+ return void 0;
480
+ }
481
+ async function waitForJob(http, request, options) {
482
+ const intervalMs = options?.intervalMs ?? 2e3;
483
+ const timeoutMs = (options?.timeoutInSeconds ?? 300) * 1e3;
484
+ const started = Date.now();
485
+ while (true) {
486
+ const result = await http.requestWithRaw({
487
+ method: "GET",
488
+ path: `/api/v1/jobs/${encodeURIComponent(request.jobId)}`,
489
+ query: request.organizationId ? { organizationId: request.organizationId } : void 0,
490
+ timeoutInSeconds: options?.timeoutInSeconds,
491
+ maxRetries: options?.maxRetries,
492
+ abortSignal: options?.abortSignal,
493
+ queryParams: options?.queryParams,
494
+ headers: options?.headers
495
+ });
496
+ const status = readJobStatus(result.data)?.toLowerCase();
497
+ if (status && TERMINAL_STATUSES.has(status)) {
498
+ if (SUCCESS_STATUSES.has(status)) return result.data;
499
+ throw new JobFailedError(status, result.data);
500
+ }
501
+ if (Date.now() - started + intervalMs > timeoutMs) {
502
+ throw new OmniError({
503
+ message: `Timed out waiting for job ${request.jobId}`,
504
+ body: result.data
505
+ });
506
+ }
507
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
508
+ }
509
+ }
510
+
511
+ // src/generated/resources.ts
512
+ var AopClient = class {
513
+ constructor(_http) {
514
+ this._http = _http;
515
+ }
516
+ _http;
517
+ /**
518
+ * Get AOP configuration
519
+ *
520
+ * Retrieve prompt, agent, structured inputs/output, and notification settings. Requires `aops:read`.
521
+ *
522
+ * `GET /api/v1/aop/{aopId}/config`
523
+ */
524
+ getConfig(request, requestOptions) {
525
+ const { aopId, organizationId } = request ?? {};
526
+ return this._http.request({
527
+ method: "GET",
528
+ path: `/api/v1/aop/${encodePathParam("aopId", aopId)}/config`,
529
+ query: { organizationId },
530
+ body: void 0,
531
+ ...mergeRequestOptions(requestOptions)
532
+ });
533
+ }
534
+ /**
535
+ * Overwrite AOP configuration
536
+ *
537
+ * Updates AOP configuration. Omitted fields keep their current values. Send `user_notification_configs: null` to clear notification overrides. Requires `aops:write`.
538
+ *
539
+ * `PUT /api/v1/aop/{aopId}/config`
540
+ */
541
+ updateConfig(request, requestOptions) {
542
+ const { aopId, ...body } = request ?? {};
543
+ return this._http.request({
544
+ method: "PUT",
545
+ path: `/api/v1/aop/${encodePathParam("aopId", aopId)}/config`,
546
+ query: void 0,
547
+ body,
548
+ ...mergeRequestOptions(requestOptions)
549
+ });
550
+ }
551
+ /**
552
+ * Execute an AOP
553
+ *
554
+ * Start an AOP run and return immediately with a `thread_id`. Poll `GET /api/v1/threads/{thread_id}/status`. Requires `aops:write`.
555
+ *
556
+ * `POST /api/v1/aop/{aopId}/execute`
557
+ */
558
+ execute(request, requestOptions) {
559
+ const { aopId, ...body } = request ?? {};
560
+ return this._http.request({
561
+ method: "POST",
562
+ path: `/api/v1/aop/${encodePathParam("aopId", aopId)}/execute`,
563
+ query: void 0,
564
+ body,
565
+ ...mergeRequestOptions(requestOptions)
566
+ });
567
+ }
568
+ /**
569
+ * Create AOP
570
+ *
571
+ * Create an organization-scoped AOP. Use `[[ placeholder ]]` in the prompt for user inputs supplied at execution time. Requires `aops:write`.
572
+ *
573
+ * `POST /api/v1/aop/create`
574
+ */
575
+ create(request, requestOptions) {
576
+ const { ...body } = request ?? {};
577
+ return this._http.request({
578
+ method: "POST",
579
+ path: "/api/v1/aop/create",
580
+ query: void 0,
581
+ body,
582
+ ...mergeRequestOptions(requestOptions)
583
+ });
584
+ }
585
+ /**
586
+ * Retry a failed AOP execution
587
+ *
588
+ * Looks up a failed AOP thread, then enqueues a new run. Requires `aops:write`.
589
+ *
590
+ * `POST /api/v1/aop/retry`
591
+ */
592
+ retry(request, requestOptions) {
593
+ const { ...body } = request ?? {};
594
+ return this._http.request({
595
+ method: "POST",
596
+ path: "/api/v1/aop/retry",
597
+ query: void 0,
598
+ body,
599
+ ...mergeRequestOptions(requestOptions)
600
+ });
601
+ }
602
+ };
603
+ var ApiClient = class {
604
+ constructor(_http) {
605
+ this._http = _http;
606
+ }
607
+ _http;
608
+ /**
609
+ * API Root
610
+ *
611
+ * Public API discovery root. Merchant payments are handled by organization-scoped checkout session endpoints.
612
+ *
613
+ * `GET /api`
614
+ */
615
+ root(requestOptions) {
616
+ return this._http.request({
617
+ method: "GET",
618
+ path: "/api",
619
+ query: void 0,
620
+ body: void 0,
621
+ ...mergeRequestOptions(requestOptions)
622
+ });
623
+ }
624
+ /**
625
+ * API v1 Root
626
+ *
627
+ * Public API v1 discovery root. Merchant payments are handled by organization-scoped checkout session endpoints.
628
+ *
629
+ * `GET /api/v1`
630
+ */
631
+ v1(requestOptions) {
632
+ return this._http.request({
633
+ method: "GET",
634
+ path: "/api/v1",
635
+ query: void 0,
636
+ body: void 0,
637
+ ...mergeRequestOptions(requestOptions)
638
+ });
639
+ }
640
+ };
641
+ var CatalogClient = class {
642
+ constructor(_http) {
643
+ this._http = _http;
644
+ }
645
+ _http;
646
+ /**
647
+ * Export Catalog Items
648
+ *
649
+ * Cursor-page the authenticated organization's product and variant catalog for pricing systems. Requires `catalog:read`.
650
+
651
+ Each item includes product-family identity, SKU/UPC, cost, current, sale, compare-at, MAP, and MSRP prices, inventory, active promotion context, and exact marketplace identifiers. Set `format=csv` for a flat catalog-intake CSV shape.
652
+ *
653
+ * `GET /api/v1/catalog/items`
654
+ */
655
+ listItems(request = {}, requestOptions) {
656
+ const { organizationId, updatedSince, cursor, limit, format } = request ?? {};
657
+ return this._http.request({
658
+ method: "GET",
659
+ path: "/api/v1/catalog/items",
660
+ query: { organizationId, updatedSince, cursor, limit, format },
661
+ body: void 0,
662
+ ...mergeRequestOptions(requestOptions)
663
+ });
664
+ }
665
+ };
666
+ var CheckoutSessionsClient = class {
667
+ constructor(_http) {
668
+ this._http = _http;
669
+ }
670
+ _http;
671
+ /**
672
+ * Create Agentic Checkout Session
673
+ *
674
+ * Create a merchant-fulfilled checkout session, reserve inventory, and return rail-specific payment requirements. Requires an OAuth client token with `checkout:write`.
675
+ *
676
+ * `POST /api/v1/checkout-sessions`
677
+ */
678
+ create(request, requestOptions) {
679
+ const { ...body } = request ?? {};
680
+ return this._http.request({
681
+ method: "POST",
682
+ path: "/api/v1/checkout-sessions",
683
+ query: void 0,
684
+ body,
685
+ ...mergeRequestOptions(requestOptions)
686
+ });
687
+ }
688
+ /**
689
+ * Get Agentic Checkout Session
690
+ *
691
+ * Fetch the current checkout session, cart items, totals, payment requirements, and linked order when completed.
692
+ *
693
+ * `GET /api/v1/checkout-sessions/{sessionId}`
694
+ */
695
+ get(request, requestOptions) {
696
+ const { sessionId, organizationId } = request ?? {};
697
+ return this._http.request({
698
+ method: "GET",
699
+ path: `/api/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}`,
700
+ query: { organizationId },
701
+ body: void 0,
702
+ ...mergeRequestOptions(requestOptions)
703
+ });
704
+ }
705
+ /**
706
+ * Update Agentic Checkout Session
707
+ *
708
+ * Update cart/contact fields, recompute totals, and refresh inventory reservations before payment. Requires `checkout:write`.
709
+ *
710
+ * `PATCH /api/v1/checkout-sessions/{sessionId}`
711
+ */
712
+ update(request, requestOptions) {
713
+ const { sessionId, organizationId, ...body } = request ?? {};
714
+ return this._http.request({
715
+ method: "PATCH",
716
+ path: `/api/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}`,
717
+ query: { organizationId },
718
+ body,
719
+ ...mergeRequestOptions(requestOptions)
720
+ });
721
+ }
722
+ /**
723
+ * Replace Agentic Checkout Session Fields
724
+ *
725
+ * UCP-compatible update method for cart/contact fields. The current implementation applies provided fields and leaves omitted fields unchanged. Requires `checkout:write`.
726
+ *
727
+ * `PUT /api/v1/checkout-sessions/{sessionId}`
728
+ */
729
+ replace(request, requestOptions) {
730
+ const { sessionId, organizationId, ...body } = request ?? {};
731
+ return this._http.request({
732
+ method: "PUT",
733
+ path: `/api/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}`,
734
+ query: { organizationId },
735
+ body,
736
+ ...mergeRequestOptions(requestOptions)
737
+ });
738
+ }
739
+ /**
740
+ * Cancel Agentic Checkout Session
741
+ *
742
+ * Cancel a ready-for-payment checkout session and release reserved inventory. This operation is exposed for UCP REST clients and requires `checkout:write`.
743
+ *
744
+ * `POST /api/v1/checkout-sessions/{sessionId}/cancel`
745
+ */
746
+ cancel(request, requestOptions) {
747
+ const { sessionId, organizationId, ...body } = request ?? {};
748
+ return this._http.request({
749
+ method: "POST",
750
+ path: `/api/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}/cancel`,
751
+ query: { organizationId },
752
+ body,
753
+ ...mergeRequestOptions(requestOptions)
754
+ });
755
+ }
756
+ /**
757
+ * Complete Agentic Checkout Session
758
+ *
759
+ * Settle the selected rail and create a native `agentic` order. Settlement failures return 402 and leave the session in `ready_for_payment`.
760
+ *
761
+ * `POST /api/v1/checkout-sessions/{sessionId}/complete`
762
+ */
763
+ complete(request, requestOptions) {
764
+ const { sessionId, organizationId, ...body } = request ?? {};
765
+ return this._http.request({
766
+ method: "POST",
767
+ path: `/api/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}/complete`,
768
+ query: { organizationId },
769
+ body,
770
+ ...mergeRequestOptions(requestOptions)
771
+ });
772
+ }
773
+ };
774
+ var CompareClient = class {
775
+ constructor(_http) {
776
+ this._http = _http;
777
+ }
778
+ _http;
779
+ /**
780
+ * Compare Public Products
781
+ *
782
+ * Compare 2 to 10 public products side-by-side across price, ACO readiness, marketplace coverage, and inventory.
783
+ *
784
+ * `GET /api/v1/compare`
785
+ */
786
+ get(request, requestOptions) {
787
+ const { products, language } = request ?? {};
788
+ return this._http.request({
789
+ method: "GET",
790
+ path: "/api/v1/compare",
791
+ query: { products, language },
792
+ body: void 0,
793
+ ...mergeRequestOptions(requestOptions)
794
+ });
795
+ }
796
+ };
797
+ var DirectoryClient = class {
798
+ constructor(_http) {
799
+ this._http = _http;
800
+ }
801
+ _http;
802
+ /**
803
+ * List Public Merchants
804
+ *
805
+ * Discover merchants with public products available through OmniCommerce's public agent APIs.
806
+ *
807
+ * `GET /api/v1/directory`
808
+ */
809
+ list(requestOptions) {
810
+ return this._http.request({
811
+ method: "GET",
812
+ path: "/api/v1/directory",
813
+ query: void 0,
814
+ body: void 0,
815
+ ...mergeRequestOptions(requestOptions)
816
+ });
817
+ }
818
+ };
819
+ var EvaluateClient = class {
820
+ constructor(_http) {
821
+ this._http = _http;
822
+ }
823
+ _http;
824
+ /**
825
+ * Evaluate SKU Readiness
826
+ *
827
+ * Score a persisted product or inline SKU payload for agentic commerce readiness, engine eligibility, and recommended fixes.
828
+ *
829
+ * `POST /api/v1/evaluate`
830
+ */
831
+ run(request = {}, requestOptions) {
832
+ const { ...body } = request ?? {};
833
+ return this._http.request({
834
+ method: "POST",
835
+ path: "/api/v1/evaluate",
836
+ query: void 0,
837
+ body,
838
+ ...mergeRequestOptions(requestOptions)
839
+ });
840
+ }
841
+ };
842
+ var FeedClient = class {
843
+ constructor(_http) {
844
+ this._http = _http;
845
+ }
846
+ _http;
847
+ /**
848
+ * Get Merchant LLM Feed
849
+ *
850
+ * Return a plain-text, LLM-optimized merchant feed keyed by website domain.
851
+ *
852
+ * `GET /api/v1/feed/{domain}/llms.txt`
853
+ */
854
+ getLlmsTxt(request, requestOptions) {
855
+ const { domain, limit } = request ?? {};
856
+ return this._http.request({
857
+ method: "GET",
858
+ path: `/api/v1/feed/${encodePathParam("domain", domain)}/llms.txt`,
859
+ query: { limit },
860
+ body: void 0,
861
+ ...mergeRequestOptions(requestOptions)
862
+ });
863
+ }
864
+ };
865
+ var ImagesClient = class {
866
+ constructor(_http) {
867
+ this._http = _http;
868
+ }
869
+ _http;
870
+ /**
871
+ * Generate Ghost Mannequin Image
872
+ *
873
+ * Remove the visible mannequin from a product photo and return the generated image URL. The source image must be an HTTP(S) URL; data URIs are rejected. Authenticate with an OmniCommerce API key that has the `catalog:enrich` scope.
874
+ *
875
+ * `POST /api/v1/images/ghost-mannequin`
876
+ */
877
+ ghostMannequin(request, requestOptions) {
878
+ const { ...body } = request ?? {};
879
+ return this._http.request({
880
+ method: "POST",
881
+ path: "/api/v1/images/ghost-mannequin",
882
+ query: void 0,
883
+ body,
884
+ ...mergeRequestOptions(requestOptions)
885
+ });
886
+ }
887
+ };
888
+ var JobsClient = class {
889
+ constructor(_http) {
890
+ this._http = _http;
891
+ }
892
+ _http;
893
+ /**
894
+ * Get Developer Job Status
895
+ *
896
+ * Fetch shared async status for developer-platform operations, including product workflow jobs, bulk CSV import jobs, Look generation jobs, import jobs, enrichment jobs, and sync jobs.
897
+ *
898
+ * `GET /api/v1/jobs/{jobId}`
899
+ */
900
+ get(request, requestOptions) {
901
+ const { jobId, organizationId } = request ?? {};
902
+ return this._http.request({
903
+ method: "GET",
904
+ path: `/api/v1/jobs/${encodePathParam("jobId", jobId)}`,
905
+ query: { organizationId },
906
+ body: void 0,
907
+ ...mergeRequestOptions(requestOptions)
908
+ });
909
+ }
910
+ /**
911
+ * Cancel Developer Job
912
+ *
913
+ * Request cancellation for a running or pending developer job.
914
+
915
+ Supported jobs:
916
+
917
+ - Product workflows returned by `POST /api/v1/products`
918
+
919
+ - Bulk CSV imports returned by `POST /api/v1/products/bulk-import`
920
+
921
+ - Look generation returned by `POST /api/v1/looks`
922
+
923
+ Completed or failed jobs cannot be cancelled and are returned with their current terminal status.
924
+ *
925
+ * `POST /api/v1/jobs/{jobId}/cancel`
926
+ */
927
+ cancel(request, requestOptions) {
928
+ const { jobId, ...body } = request ?? {};
929
+ return this._http.request({
930
+ method: "POST",
931
+ path: `/api/v1/jobs/${encodePathParam("jobId", jobId)}/cancel`,
932
+ query: void 0,
933
+ body,
934
+ ...mergeRequestOptions(requestOptions)
935
+ });
936
+ }
937
+ /**
938
+ * Poll `GET /api/v1/jobs/{jobId}` until the nested job status is terminal.
939
+ */
940
+ wait(request, requestOptions) {
941
+ return waitForJob(this._http, request, requestOptions);
942
+ }
943
+ };
944
+ var LooksClient = class {
945
+ constructor(_http) {
946
+ this._http = _http;
947
+ }
948
+ _http;
949
+ /**
950
+ * List Looks
951
+ *
952
+ * List AI-styled product Looks for the authenticated organization, newest first. Use query parameters for search, status filtering, and pagination.
953
+ *
954
+ * `GET /api/v1/looks`
955
+ */
956
+ list(request = {}, requestOptions) {
957
+ const { q, status, limit, offset } = request ?? {};
958
+ return this._http.request({
959
+ method: "GET",
960
+ path: "/api/v1/looks",
961
+ query: { q, status, limit, offset },
962
+ body: void 0,
963
+ ...mergeRequestOptions(requestOptions)
964
+ });
965
+ }
966
+ /**
967
+ * Create Look
968
+ *
969
+ * Create a Look from existing catalog products and queue AI image generation for a fast preview. The response is asynchronous: poll `GET /api/v1/jobs/{jobId}?organizationId={organizationId}` until the `look_...` job completes, then fetch the generated Look with `GET /api/v1/looks/{lookId}`.
970
+ *
971
+ * `POST /api/v1/looks`
972
+ */
973
+ create(request, requestOptions) {
974
+ const { ...body } = request ?? {};
975
+ return this._http.request({
976
+ method: "POST",
977
+ path: "/api/v1/looks",
978
+ query: void 0,
979
+ body,
980
+ ...mergeRequestOptions(requestOptions)
981
+ });
982
+ }
983
+ /**
984
+ * Get Look
985
+ *
986
+ * Fetch a single Look by ID, including the generated hero image URL and the shoppable product cards used in the Look.
987
+ *
988
+ * `GET /api/v1/looks/{lookId}`
989
+ */
990
+ get(request, requestOptions) {
991
+ const { lookId } = request ?? {};
992
+ return this._http.request({
993
+ method: "GET",
994
+ path: `/api/v1/looks/${encodePathParam("lookId", lookId)}`,
995
+ query: void 0,
996
+ body: void 0,
997
+ ...mergeRequestOptions(requestOptions)
998
+ });
999
+ }
1000
+ };
1001
+ var MarketplacesClient = class {
1002
+ constructor(_http) {
1003
+ this._http = _http;
1004
+ }
1005
+ _http;
1006
+ /**
1007
+ * List Connected Marketplaces
1008
+ *
1009
+ * List connected marketplace stores for the authenticated organization. Results are scoped to the API key organization unless `organizationId` is supplied for session-authenticated calls.
1010
+ *
1011
+ * `GET /api/v1/marketplaces/connected`
1012
+ */
1013
+ listConnected(request = {}, requestOptions) {
1014
+ const { organizationId, marketplace, country } = request ?? {};
1015
+ return this._http.request({
1016
+ method: "GET",
1017
+ path: "/api/v1/marketplaces/connected",
1018
+ query: { organizationId, marketplace, country },
1019
+ body: void 0,
1020
+ ...mergeRequestOptions(requestOptions)
1021
+ });
1022
+ }
1023
+ };
1024
+ var MerchantsClient = class {
1025
+ constructor(_http) {
1026
+ this._http = _http;
1027
+ }
1028
+ _http;
1029
+ /**
1030
+ * Get Public Merchant Manifest
1031
+ *
1032
+ * Return machine-readable capability and endpoint metadata for a single public merchant.
1033
+ *
1034
+ * `GET /api/v1/merchants/{merchantId}/manifest`
1035
+ */
1036
+ getManifest(request, requestOptions) {
1037
+ const { merchantId } = request ?? {};
1038
+ return this._http.request({
1039
+ method: "GET",
1040
+ path: `/api/v1/merchants/${encodePathParam("merchantId", merchantId)}/manifest`,
1041
+ query: void 0,
1042
+ body: void 0,
1043
+ ...mergeRequestOptions(requestOptions)
1044
+ });
1045
+ }
1046
+ /**
1047
+ * List Public Merchant Products
1048
+ *
1049
+ * Browse a single merchant's public product feed with optional marketplace and localization filters.
1050
+ *
1051
+ * `GET /api/v1/merchants/{merchantId}/products`
1052
+ */
1053
+ listProducts(request, requestOptions) {
1054
+ const { merchantId, platform, country, language, limit, offset } = request ?? {};
1055
+ return this._http.request({
1056
+ method: "GET",
1057
+ path: `/api/v1/merchants/${encodePathParam("merchantId", merchantId)}/products`,
1058
+ query: { platform, country, language, limit, offset },
1059
+ body: void 0,
1060
+ ...mergeRequestOptions(requestOptions)
1061
+ });
1062
+ }
1063
+ /**
1064
+ * Search Within Public Merchant Catalog
1065
+ *
1066
+ * Search within a single merchant's public product feed using the same filter model as the cross-merchant search API.
1067
+ *
1068
+ * `GET /api/v1/merchants/{merchantId}/search`
1069
+ */
1070
+ search(request, requestOptions) {
1071
+ const {
1072
+ merchantId,
1073
+ q,
1074
+ category,
1075
+ brand,
1076
+ min_price,
1077
+ max_price,
1078
+ in_stock,
1079
+ sort,
1080
+ platform,
1081
+ country,
1082
+ language,
1083
+ include_intent,
1084
+ limit,
1085
+ offset
1086
+ } = request ?? {};
1087
+ return this._http.request({
1088
+ method: "GET",
1089
+ path: `/api/v1/merchants/${encodePathParam("merchantId", merchantId)}/search`,
1090
+ query: {
1091
+ q,
1092
+ category,
1093
+ brand,
1094
+ min_price,
1095
+ max_price,
1096
+ in_stock,
1097
+ sort,
1098
+ platform,
1099
+ country,
1100
+ language,
1101
+ include_intent,
1102
+ limit,
1103
+ offset
1104
+ },
1105
+ body: void 0,
1106
+ ...mergeRequestOptions(requestOptions)
1107
+ });
1108
+ }
1109
+ };
1110
+ var MonitorClient = class {
1111
+ constructor(_http) {
1112
+ this._http = _http;
1113
+ }
1114
+ _http;
1115
+ /**
1116
+ * Run AI Shelf Share Monitor
1117
+ *
1118
+ * Queue AI Shelf Share replay/monitoring for a product, query, or organization catalog.
1119
+ *
1120
+ * `POST /api/v1/monitor`
1121
+ */
1122
+ run(request = {}, requestOptions) {
1123
+ const { ...body } = request ?? {};
1124
+ return this._http.request({
1125
+ method: "POST",
1126
+ path: "/api/v1/monitor",
1127
+ query: void 0,
1128
+ body,
1129
+ ...mergeRequestOptions(requestOptions)
1130
+ });
1131
+ }
1132
+ };
1133
+ var OauthClient = class {
1134
+ constructor(_http) {
1135
+ this._http = _http;
1136
+ }
1137
+ _http;
1138
+ /**
1139
+ * Revoke Access Token
1140
+ *
1141
+ * Revoke an OAuth bearer access token using client_secret_post authentication.
1142
+ *
1143
+ * `POST /api/v1/oauth/revoke`
1144
+ */
1145
+ revoke(request, requestOptions) {
1146
+ const { ...body } = request ?? {};
1147
+ return this._http.request({
1148
+ method: "POST",
1149
+ path: "/api/v1/oauth/revoke",
1150
+ query: void 0,
1151
+ body,
1152
+ ...mergeRequestOptions(requestOptions)
1153
+ });
1154
+ }
1155
+ /**
1156
+ * Get Access Token
1157
+ *
1158
+ * Exchange client credentials for an access token using OAuth 2.0 client_credentials grant. Tokens are valid for 1 hour.
1159
+ *
1160
+ * `POST /api/v1/oauth/token`
1161
+ */
1162
+ token(request, requestOptions) {
1163
+ const { ...body } = request ?? {};
1164
+ return this._http.request({
1165
+ method: "POST",
1166
+ path: "/api/v1/oauth/token",
1167
+ query: void 0,
1168
+ body,
1169
+ ...mergeRequestOptions(requestOptions)
1170
+ });
1171
+ }
1172
+ };
1173
+ var OrdersClient = class {
1174
+ constructor(_http) {
1175
+ this._http = _http;
1176
+ }
1177
+ _http;
1178
+ /**
1179
+ * List Orders
1180
+ *
1181
+ * List orders for the authenticated organization using the same filters, sorting, and pagination semantics as the workspace Orders listing page. Requires `orders:read`.
1182
+ *
1183
+ * `GET /api/v1/orders`
1184
+ */
1185
+ list(request = {}, requestOptions) {
1186
+ const {
1187
+ organizationId,
1188
+ q,
1189
+ status,
1190
+ marketplace,
1191
+ country,
1192
+ store,
1193
+ bundleType,
1194
+ sortBy,
1195
+ dateFrom,
1196
+ dateTo,
1197
+ limit,
1198
+ offset
1199
+ } = request ?? {};
1200
+ return this._http.request({
1201
+ method: "GET",
1202
+ path: "/api/v1/orders",
1203
+ query: {
1204
+ organizationId,
1205
+ q,
1206
+ status,
1207
+ marketplace,
1208
+ country,
1209
+ store,
1210
+ bundleType,
1211
+ sortBy,
1212
+ dateFrom,
1213
+ dateTo,
1214
+ limit,
1215
+ offset
1216
+ },
1217
+ body: void 0,
1218
+ ...mergeRequestOptions(requestOptions)
1219
+ });
1220
+ }
1221
+ /**
1222
+ * Create Order
1223
+ *
1224
+ * Create a native `agentic` order with line items. This operation uses the same upsert path as agentic checkout completion.
1225
+
1226
+ ### Authentication
1227
+
1228
+ Requires `orders:write`.
1229
+
1230
+ ### Upsert behavior
1231
+
1232
+ - Reusing an `externalOrderId` updates the existing order instead of creating a duplicate.
1233
+ - For one-row-per-SKU integrations, use the marketplace order ID as `externalOrderId` and the row ID as `items[].externalOrderItemId`.
1234
+ - When `totalAmount` is omitted, OmniCommerce recomputes it from all order lines after the upsert.
1235
+
1236
+ ### Pricing and catalog defaults
1237
+
1238
+ - Each line can provide `price`, `unitPrice`, `paidPrice`, and `costPrice`.
1239
+ - When `productId` is provided, missing price or currency values may resolve from the product catalog.
1240
+ - An explicit `costPrice` updates `product_data.costPrice` and is snaps
1241
+ *
1242
+ * `POST /api/v1/orders`
1243
+ */
1244
+ create(request, requestOptions) {
1245
+ const { ...body } = request ?? {};
1246
+ return this._http.request({
1247
+ method: "POST",
1248
+ path: "/api/v1/orders",
1249
+ query: void 0,
1250
+ body,
1251
+ ...mergeRequestOptions(requestOptions)
1252
+ });
1253
+ }
1254
+ /**
1255
+ * Get Order
1256
+ *
1257
+ * Get one order by its OmniCommerce UUID for the authenticated organization.
1258
+
1259
+ ### Authentication
1260
+
1261
+ Requires `orders:read`.
1262
+
1263
+ ### Response
1264
+
1265
+ The organization-scoped detail includes:
1266
+
1267
+ - Line items and normalized status
1268
+ - Buyer and contact fields
1269
+ - Shipping and billing addresses
1270
+ - Return context
1271
+ - Finance breakdown
1272
+ - Settlement projection, when available
1273
+
1274
+ Orders outside the authenticated organization are not exposed and return `404 Not Found`.
1275
+ *
1276
+ * `GET /api/v1/orders/{orderId}`
1277
+ */
1278
+ get(request, requestOptions) {
1279
+ const { orderId, organizationId } = request ?? {};
1280
+ return this._http.request({
1281
+ method: "GET",
1282
+ path: `/api/v1/orders/${encodePathParam("orderId", orderId)}`,
1283
+ query: { organizationId },
1284
+ body: void 0,
1285
+ ...mergeRequestOptions(requestOptions)
1286
+ });
1287
+ }
1288
+ /**
1289
+ * Update Order
1290
+ *
1291
+ * Update a native **agentic** order.
1292
+
1293
+ ### Authentication
1294
+
1295
+ Requires `orders:write`.
1296
+
1297
+ ### Supported changes
1298
+
1299
+ - External order identifiers, status, currency, and country
1300
+ - `totalAmount`, `shippingFee`, and `discountAmount`
1301
+ - Metadata and `orderCreatedAt`
1302
+ - Line identifiers, prices, COGS, currency, status, and quantity
1303
+
1304
+ ### Line upserts
1305
+
1306
+ - A matching `externalOrderItemId` updates the existing line.
1307
+ - A new `externalOrderItemId` with `productName` and `quantity` appends a line.
1308
+ - When lines change and `totalAmount` is omitted, OmniCommerce recomputes the total from all lines.
1309
+
1310
+ ### Country resolution
1311
+
1312
+ When `country` is omitted and the stored country is empty, OmniCommerce may derive it from an unambiguous resulting order currency.
1313
+
1314
+ ### Restrictions and events
1315
+
1316
+ Marketplace-owned orders from Shopee,
1317
+ *
1318
+ * `PATCH /api/v1/orders/{orderId}`
1319
+ */
1320
+ update(request, requestOptions) {
1321
+ const { orderId, ...body } = request ?? {};
1322
+ return this._http.request({
1323
+ method: "PATCH",
1324
+ path: `/api/v1/orders/${encodePathParam("orderId", orderId)}`,
1325
+ query: void 0,
1326
+ body,
1327
+ ...mergeRequestOptions(requestOptions)
1328
+ });
1329
+ }
1330
+ };
1331
+ var OrganizationsClient = class {
1332
+ constructor(_http) {
1333
+ this._http = _http;
1334
+ }
1335
+ _http;
1336
+ /**
1337
+ * Create Organization
1338
+ *
1339
+ * Create a new organization for the signed-in user. This endpoint uses first-party session authentication because API keys are scoped to an existing organization.
1340
+ *
1341
+ * `POST /api/v1/organizations`
1342
+ */
1343
+ create(request, requestOptions) {
1344
+ const { ...body } = request ?? {};
1345
+ return this._http.request({
1346
+ method: "POST",
1347
+ path: "/api/v1/organizations",
1348
+ query: void 0,
1349
+ body,
1350
+ ...mergeRequestOptions(requestOptions)
1351
+ });
1352
+ }
1353
+ };
1354
+ var PriceBooksClient = class {
1355
+ constructor(_http) {
1356
+ this._http = _http;
1357
+ }
1358
+ _http;
1359
+ /**
1360
+ * List Price Book Rules
1361
+ *
1362
+ * List marketplace price book rules for the authenticated organization. A rule applies either a buyer formula or a markup percent to the catalog price at publish time, by platform and optional store/country. Requires `price_books:read`.
1363
+ *
1364
+ * `GET /api/v1/price-books`
1365
+ */
1366
+ list(request = {}, requestOptions) {
1367
+ const { organizationId, platform, enabledOnly } = request ?? {};
1368
+ return this._http.request({
1369
+ method: "GET",
1370
+ path: "/api/v1/price-books",
1371
+ query: { organizationId, platform, enabledOnly },
1372
+ body: void 0,
1373
+ ...mergeRequestOptions(requestOptions)
1374
+ });
1375
+ }
1376
+ /**
1377
+ * Create Price Book Rule
1378
+ *
1379
+ * Create a marketplace price book rule for a platform (optional store and country). Does not change Omni product prices. Requires `price_books:write`.
1380
+
1381
+ `expression` is the buyer formula and replaces markup percent. `price` in that formula is the catalog price, not cost price. Without an expression, `marginValue` is the markup percent.
1382
+ *
1383
+ * `POST /api/v1/price-books`
1384
+ */
1385
+ create(request, requestOptions) {
1386
+ const { ...body } = request ?? {};
1387
+ return this._http.request({
1388
+ method: "POST",
1389
+ path: "/api/v1/price-books",
1390
+ query: void 0,
1391
+ body,
1392
+ ...mergeRequestOptions(requestOptions)
1393
+ });
1394
+ }
1395
+ /**
1396
+ * Delete Price Book Rule
1397
+ *
1398
+ * Delete a marketplace price book rule by ID. Requires `price_books:write`.
1399
+ *
1400
+ * `DELETE /api/v1/price-books/{ruleId}`
1401
+ */
1402
+ delete(request, requestOptions) {
1403
+ const { ruleId, organizationId } = request ?? {};
1404
+ return this._http.request({
1405
+ method: "DELETE",
1406
+ path: `/api/v1/price-books/${encodePathParam("ruleId", ruleId)}`,
1407
+ query: { organizationId },
1408
+ body: void 0,
1409
+ ...mergeRequestOptions(requestOptions)
1410
+ });
1411
+ }
1412
+ /**
1413
+ * Get Price Book Rule
1414
+ *
1415
+ * Fetch one marketplace price book rule by ID. Requires `price_books:read`.
1416
+ *
1417
+ * `GET /api/v1/price-books/{ruleId}`
1418
+ */
1419
+ get(request, requestOptions) {
1420
+ const { ruleId, organizationId } = request ?? {};
1421
+ return this._http.request({
1422
+ method: "GET",
1423
+ path: `/api/v1/price-books/${encodePathParam("ruleId", ruleId)}`,
1424
+ query: { organizationId },
1425
+ body: void 0,
1426
+ ...mergeRequestOptions(requestOptions)
1427
+ });
1428
+ }
1429
+ /**
1430
+ * Update Price Book Rule
1431
+ *
1432
+ * Update store, country, markup, buyer formula, rounding, currency, or enabled flag for a price book rule. Platform cannot be changed; create a new rule instead. Requires `price_books:write`.
1433
+ *
1434
+ * `PATCH /api/v1/price-books/{ruleId}`
1435
+ */
1436
+ update(request, requestOptions) {
1437
+ const { ruleId, organizationId, ...body } = request ?? {};
1438
+ return this._http.request({
1439
+ method: "PATCH",
1440
+ path: `/api/v1/price-books/${encodePathParam("ruleId", ruleId)}`,
1441
+ query: { organizationId },
1442
+ body,
1443
+ ...mergeRequestOptions(requestOptions)
1444
+ });
1445
+ }
1446
+ /**
1447
+ * Preview Channel List Price
1448
+ *
1449
+ * Compute channel list price from a canonical list price using matching enabled rules (or a forced ruleId). Requires `price_books:read`.
1450
+ *
1451
+ * `POST /api/v1/price-books/preview`
1452
+ */
1453
+ preview(request, requestOptions) {
1454
+ const { ...body } = request ?? {};
1455
+ return this._http.request({
1456
+ method: "POST",
1457
+ path: "/api/v1/price-books/preview",
1458
+ query: void 0,
1459
+ body,
1460
+ ...mergeRequestOptions(requestOptions)
1461
+ });
1462
+ }
1463
+ };
1464
+ var ProductCategoriesClient = class {
1465
+ constructor(_http) {
1466
+ this._http = _http;
1467
+ }
1468
+ _http;
1469
+ /**
1470
+ * Recommend Marketplace Product Categories
1471
+ *
1472
+ * Suggest best-fit marketplace categories and category attribute values for a persisted product using semantic taxonomy search. Authenticate with an OmniCommerce API key as `Authorization: Bearer omni_sk_...`.
1473
+ *
1474
+ * `POST /api/v1/manage-product-category/recommend`
1475
+ */
1476
+ recommend(request, requestOptions) {
1477
+ const { ...body } = request ?? {};
1478
+ return this._http.request({
1479
+ method: "POST",
1480
+ path: "/api/v1/manage-product-category/recommend",
1481
+ query: void 0,
1482
+ body,
1483
+ ...mergeRequestOptions(requestOptions)
1484
+ });
1485
+ }
1486
+ };
1487
+ var ProductsClient = class {
1488
+ constructor(_http) {
1489
+ this._http = _http;
1490
+ }
1491
+ _http;
1492
+ /**
1493
+ * List Products
1494
+ *
1495
+ * List products for the authenticated organization with optional filters and pagination. Authenticate with an API key or OAuth bearer token. The organization is taken from that credential; do not send `organizationId`.
1496
+ *
1497
+ * `GET /api/v1/products`
1498
+ */
1499
+ list(request = {}, requestOptions) {
1500
+ const {
1501
+ status,
1502
+ marketplace,
1503
+ country,
1504
+ q,
1505
+ sku,
1506
+ minPrice,
1507
+ maxPrice,
1508
+ sortBy,
1509
+ limit,
1510
+ offset
1511
+ } = request ?? {};
1512
+ return this._http.request({
1513
+ method: "GET",
1514
+ path: "/api/v1/products",
1515
+ query: {
1516
+ status,
1517
+ marketplace,
1518
+ country,
1519
+ q,
1520
+ sku,
1521
+ minPrice,
1522
+ maxPrice,
1523
+ sortBy,
1524
+ limit,
1525
+ offset
1526
+ },
1527
+ body: void 0,
1528
+ ...mergeRequestOptions(requestOptions)
1529
+ });
1530
+ }
1531
+ /**
1532
+ * Create Product
1533
+ *
1534
+ * Queue a single-product create workflow for the authenticated organization. Product enrichment is disabled by default; set `workflow.enrich` to `true` to enable it.
1535
+
1536
+ ### Request behavior
1537
+
1538
+ - `product` contains developer-supplied fields. Unknown fields are preserved as enrichment context.
1539
+ - SKU is the unique product upsert identifier.
1540
+ - Externally hosted HTTP(S) images are copied to managed R2 storage.
1541
+ - `targetMarketplaces` and `targetCountries` are optional; enrichment can run without publishing targets.
1542
+
1543
+ ### Asynchronous result
1544
+
1545
+ The API returns a job ID. Poll `GET /api/v1/jobs/{jobId}` for completion. Product creation, image ingestion, enrichment, and taxonomy assignment run in the same product workflow job. ACO generation runs separately when enabled; poll `result.geoJobId` for its comple
1546
+ *
1547
+ * `POST /api/v1/products`
1548
+ */
1549
+ create(request, requestOptions) {
1550
+ const { ...body } = request ?? {};
1551
+ return this._http.request({
1552
+ method: "POST",
1553
+ path: "/api/v1/products",
1554
+ query: void 0,
1555
+ body,
1556
+ ...mergeRequestOptions(requestOptions)
1557
+ });
1558
+ }
1559
+ /**
1560
+ * Delete Product
1561
+ *
1562
+ * Soft-delete a product by ID. The product will be marked as deleted but not permanently removed. Call again on a deleted product to permanently delete it. Supports API key Bearer token authentication.
1563
+ *
1564
+ * `DELETE /api/v1/products/{productId}`
1565
+ */
1566
+ delete(request, requestOptions) {
1567
+ const { productId } = request ?? {};
1568
+ return this._http.request({
1569
+ method: "DELETE",
1570
+ path: `/api/v1/products/${encodePathParam("productId", productId)}`,
1571
+ query: void 0,
1572
+ body: void 0,
1573
+ ...mergeRequestOptions(requestOptions)
1574
+ });
1575
+ }
1576
+ /**
1577
+ * Get Product
1578
+ *
1579
+ * Retrieve a single product by ID for the authenticated organization.
1580
+
1581
+ Authenticate with an API key using Bearer token authentication.
1582
+
1583
+ When available, the response includes generated Agentic Commerce Optimization (ACO) data:
1584
+
1585
+ - Profile metadata and FAQs
1586
+ - Localization content and cultural notes
1587
+ - Intent queries and signals
1588
+ - Sources and claims
1589
+ *
1590
+ * `GET /api/v1/products/{productId}`
1591
+ */
1592
+ get(request, requestOptions) {
1593
+ const { productId } = request ?? {};
1594
+ return this._http.request({
1595
+ method: "GET",
1596
+ path: `/api/v1/products/${encodePathParam("productId", productId)}`,
1597
+ query: void 0,
1598
+ body: void 0,
1599
+ ...mergeRequestOptions(requestOptions)
1600
+ });
1601
+ }
1602
+ /**
1603
+ * Update Product
1604
+ *
1605
+ * Update an existing product by ID. Only provided fields will be updated. Supports API key Bearer token authentication.
1606
+ *
1607
+ * `PATCH /api/v1/products/{productId}`
1608
+ */
1609
+ update(request, requestOptions) {
1610
+ const { productId, ...body } = request ?? {};
1611
+ return this._http.request({
1612
+ method: "PATCH",
1613
+ path: `/api/v1/products/${encodePathParam("productId", productId)}`,
1614
+ query: void 0,
1615
+ body,
1616
+ ...mergeRequestOptions(requestOptions)
1617
+ });
1618
+ }
1619
+ /**
1620
+ * Update Product Cost
1621
+ *
1622
+ * Set catalog cost for one simple product or variant UUID. Cost is Omni-only and never syncs to marketplaces. Prefer `POST /api/v1/products/cost` for Windmill or other bulk jobs.
1623
+
1624
+ Requires `catalog:write`. When `costPriceCurrency` differs from the product selling currency and `costPriceFxRate` is omitted, Omni stores an FX quote on the product.
1625
+ *
1626
+ * `PATCH /api/v1/products/{productId}/cost`
1627
+ */
1628
+ updateCost(request, requestOptions) {
1629
+ const { productId, ...body } = request ?? {};
1630
+ return this._http.request({
1631
+ method: "PATCH",
1632
+ path: `/api/v1/products/${encodePathParam("productId", productId)}/cost`,
1633
+ query: void 0,
1634
+ body,
1635
+ ...mergeRequestOptions(requestOptions)
1636
+ });
1637
+ }
1638
+ /**
1639
+ * Delist Product
1640
+ *
1641
+ * Queue delist for one product on the marketplaces you name. `marketplaces` accepts one or more of shopee, lazada, tiktok, shopify, whatsapp, zalora, amazon, and ebay. Each named marketplace must already have a listing; other channels are left untouched. Omit `marketplaces` to delist every existing listing. This does not delete the OmniCommerce product. Poll GET /api/v1/jobs/{jobId} until data.status is succeeded, partial, or failed. Accepted means the job was queued, not that the marketplace has removed the listing.
1642
+ *
1643
+ * `POST /api/v1/products/{productId}/delist`
1644
+ */
1645
+ delist(request, requestOptions) {
1646
+ const { productId, ...body } = request ?? {};
1647
+ return this._http.request({
1648
+ method: "POST",
1649
+ path: `/api/v1/products/${encodePathParam("productId", productId)}/delist`,
1650
+ query: void 0,
1651
+ body,
1652
+ ...mergeRequestOptions(requestOptions)
1653
+ });
1654
+ }
1655
+ /**
1656
+ * Update Product Inventory
1657
+ *
1658
+ * Update canonical on-hand inventory for a simple product or variant UUID. Multi-variant parent products must be updated through their variant IDs. A successful quantity change emits `product.inventory.changed` to matching developer webhook subscriptions.
1659
+
1660
+ ### Authorization
1661
+
1662
+ Requires an API credential with `catalog:write`. OmniCommerce derives `organizationId` from that credential; the request body cannot select or override an organization. ERP-managed and multi-source inventory keeps its existing ownership protections.
1663
+
1664
+ ### Marketplace sync
1665
+
1666
+ The update is Omni-only by default. Set `syncToMarketplaces` to `true` to create one durable inventory outbox job per marketplace account. Omit `targets` to sync every enabled, published account for the product, or provide exact `{ platform, accountId }
1667
+ *
1668
+ * `PATCH /api/v1/products/{productId}/inventory`
1669
+ */
1670
+ updateInventory(request, requestOptions) {
1671
+ const { productId, ...body } = request ?? {};
1672
+ return this._http.request({
1673
+ method: "PATCH",
1674
+ path: `/api/v1/products/${encodePathParam("productId", productId)}/inventory`,
1675
+ query: void 0,
1676
+ body,
1677
+ ...mergeRequestOptions(requestOptions)
1678
+ });
1679
+ }
1680
+ /**
1681
+ * Update Product Price
1682
+ *
1683
+ * Update the canonical catalog price for a simple product or variant UUID. Multi-variant parent products must be updated through their variant IDs. A successful change emits `product.price.changed` to matching developer webhook subscriptions.
1684
+
1685
+ ### Authorization
1686
+
1687
+ Requires an API credential with `catalog:write`. OmniCommerce derives `organizationId` from that credential; the request body cannot select or override an organization.
1688
+
1689
+ ### Marketplace sync
1690
+
1691
+ The update is Omni-only by default. Set `syncToMarketplaces` to `true` to queue durable marketplace work. Omit `targets` to sync every enabled, published account for the product, or provide exact `{ platform, accountId }` targets. Every explicit target is validated before the catalog changes. The response contains pollable job IDs and immediate
1692
+ *
1693
+ * `PATCH /api/v1/products/{productId}/price`
1694
+ */
1695
+ updatePrice(request, requestOptions) {
1696
+ const { productId, ...body } = request ?? {};
1697
+ return this._http.request({
1698
+ method: "PATCH",
1699
+ path: `/api/v1/products/${encodePathParam("productId", productId)}/price`,
1700
+ query: void 0,
1701
+ body,
1702
+ ...mergeRequestOptions(requestOptions)
1703
+ });
1704
+ }
1705
+ /**
1706
+ * Publish Product
1707
+ *
1708
+ * Queue marketplace publish jobs for a product by productId. OmniCommerce publishes to the marketplaces already enabled on the product and uses the product's store selection or a single/default connected store.
1709
+ *
1710
+ * `POST /api/v1/products/{productId}/publish`
1711
+ */
1712
+ publish(request, requestOptions) {
1713
+ const { productId, ...body } = request ?? {};
1714
+ return this._http.request({
1715
+ method: "POST",
1716
+ path: `/api/v1/products/${encodePathParam("productId", productId)}/publish`,
1717
+ query: void 0,
1718
+ body,
1719
+ ...mergeRequestOptions(requestOptions)
1720
+ });
1721
+ }
1722
+ /**
1723
+ * Bulk Import Products from JSON or CSV
1724
+ *
1725
+ * Queue a bulk product import for the authenticated organization.
1726
+
1727
+ ### Input options
1728
+
1729
+ - Upload a CSV (2 MiB) or JSON products file (8 MiB) using `multipart/form-data`.
1730
+ - Send JSON with a `products` array of 1–1,000 flat product objects (8 MiB request maximum).
1731
+ - Send JSON with inline `csvText`.
1732
+ - Send JSON referencing a stored `documentId`.
1733
+
1734
+ ### Asynchronous result
1735
+
1736
+ The API creates import rows, then queues draft creation and AI Review through Inngest. Completed import jobs expose `reviewBatchIds`, `reviewUrls`, and `reviewWarnings`; generated changes require Review approval. Poll the returned `bulk_...` job with `GET /api/v1/jobs/{jobId}`.
1737
+
1738
+ Cancel an in-flight import with `POST /api/v1/jobs/{jobId}/cancel`.
1739
+ *
1740
+ * `POST /api/v1/products/bulk-import`
1741
+ */
1742
+ bulkImport(request, requestOptions) {
1743
+ const { ...body } = request ?? {};
1744
+ return this._http.request({
1745
+ method: "POST",
1746
+ path: "/api/v1/products/bulk-import",
1747
+ query: void 0,
1748
+ body,
1749
+ ...mergeRequestOptions(requestOptions)
1750
+ });
1751
+ }
1752
+ /**
1753
+ * Batch Update Product Cost
1754
+ *
1755
+ * Set catalog cost price and currency for one or more products. Cost is Omni-only and never syncs to marketplaces.
1756
+
1757
+ Each update targets `productId` or `sku` (Omni `products.sku`). Provide `costPrice` with `costPriceCurrency` when the source amount is not in the product selling currency. If `costPriceFxRate` is omitted and the currencies differ, Omni quotes FX via the canonical FX service and stores the rate on the product.
1758
+
1759
+ ### Authorization
1760
+
1761
+ Requires `catalog:write`. `organizationId` comes from the credential; the body cannot select an organization.
1762
+
1763
+ ### Limits
1764
+
1765
+ `updates` is required, 1–200 items. Duplicate product IDs fail after the first occurrence. `costPrice: null` clears cost and FX.
1766
+ *
1767
+ * `POST /api/v1/products/cost`
1768
+ */
1769
+ updateCosts(request, requestOptions) {
1770
+ const { ...body } = request ?? {};
1771
+ return this._http.request({
1772
+ method: "POST",
1773
+ path: "/api/v1/products/cost",
1774
+ query: void 0,
1775
+ body,
1776
+ ...mergeRequestOptions(requestOptions)
1777
+ });
1778
+ }
1779
+ /**
1780
+ * Queue Product Enrichment
1781
+ *
1782
+ * Requires catalog:enrich. Queue content enrichment for 1–1,000 existing Omni product IDs across all supported marketplaces. Returns 202 after queue submission without awaiting AI completion or publishing.
1783
+
1784
+ ### Enrichment options
1785
+
1786
+ Fields, instructions and auto-apply settings use the canonical enrichment service. Exclude name from selectedFields to preserve titles. Weight and dimensions are always included; image and taxonomy workflows are not queued here.
1787
+
1788
+ autoApplyHighConfidence defaults to false. When enabled, the supplied threshold (0.62–1) or organization threshold applies; low-confidence or blocked proposals remain in Review. AI usage is billed to the authenticated organization. Open links.review to inspect results.
1789
+ *
1790
+ * `POST /api/v1/products/enrich`
1791
+ */
1792
+ enrich(request, requestOptions) {
1793
+ const { ...body } = request ?? {};
1794
+ return this._http.request({
1795
+ method: "POST",
1796
+ path: "/api/v1/products/enrich",
1797
+ query: void 0,
1798
+ body,
1799
+ ...mergeRequestOptions(requestOptions)
1800
+ });
1801
+ }
1802
+ };
1803
+ var PromotionsClient = class {
1804
+ constructor(_http) {
1805
+ this._http = _http;
1806
+ }
1807
+ _http;
1808
+ /**
1809
+ * List Promotions
1810
+ *
1811
+ * List central promotions for the authenticated organization with filters and offset pagination matching the workspace Promotions listing. Requires `promotions:read`.
1812
+ *
1813
+ * `GET /api/v1/promotions`
1814
+ */
1815
+ list(request = {}, requestOptions) {
1816
+ const {
1817
+ organizationId,
1818
+ q,
1819
+ status,
1820
+ marketplace,
1821
+ store,
1822
+ sortBy,
1823
+ sortDir,
1824
+ limit,
1825
+ offset
1826
+ } = request ?? {};
1827
+ return this._http.request({
1828
+ method: "GET",
1829
+ path: "/api/v1/promotions",
1830
+ query: {
1831
+ organizationId,
1832
+ q,
1833
+ status,
1834
+ marketplace,
1835
+ store,
1836
+ sortBy,
1837
+ sortDir,
1838
+ limit,
1839
+ offset
1840
+ },
1841
+ body: void 0,
1842
+ ...mergeRequestOptions(requestOptions)
1843
+ });
1844
+ }
1845
+ /**
1846
+ * Create Promotion
1847
+ *
1848
+ * Create a central promotion targeting connected stores. Requires `promotions:write`. Fixed-amount discounts resolve currency from the selected store countries.
1849
+ *
1850
+ * `POST /api/v1/promotions`
1851
+ */
1852
+ create(request, requestOptions) {
1853
+ const { ...body } = request ?? {};
1854
+ return this._http.request({
1855
+ method: "POST",
1856
+ path: "/api/v1/promotions",
1857
+ query: void 0,
1858
+ body,
1859
+ ...mergeRequestOptions(requestOptions)
1860
+ });
1861
+ }
1862
+ /**
1863
+ * Delete Promotion
1864
+ *
1865
+ * Delete a promotion by ID. Requires `promotions:write`.
1866
+ *
1867
+ * `DELETE /api/v1/promotions/{promotionId}`
1868
+ */
1869
+ delete(request, requestOptions) {
1870
+ const { promotionId, organizationId } = request ?? {};
1871
+ return this._http.request({
1872
+ method: "DELETE",
1873
+ path: `/api/v1/promotions/${encodePathParam("promotionId", promotionId)}`,
1874
+ query: { organizationId },
1875
+ body: void 0,
1876
+ ...mergeRequestOptions(requestOptions)
1877
+ });
1878
+ }
1879
+ /**
1880
+ * Get Promotion
1881
+ *
1882
+ * Fetch one promotion by ID, including effective status. Requires `promotions:read`.
1883
+ *
1884
+ * `GET /api/v1/promotions/{promotionId}`
1885
+ */
1886
+ get(request, requestOptions) {
1887
+ const { promotionId, organizationId } = request ?? {};
1888
+ return this._http.request({
1889
+ method: "GET",
1890
+ path: `/api/v1/promotions/${encodePathParam("promotionId", promotionId)}`,
1891
+ query: { organizationId },
1892
+ body: void 0,
1893
+ ...mergeRequestOptions(requestOptions)
1894
+ });
1895
+ }
1896
+ /**
1897
+ * Update Promotion
1898
+ *
1899
+ * Update promotion fields (name, discount, schedule, status, stores). Requires `promotions:write`.
1900
+ *
1901
+ * `PATCH /api/v1/promotions/{promotionId}`
1902
+ */
1903
+ update(request, requestOptions) {
1904
+ const { promotionId, organizationId, ...body } = request ?? {};
1905
+ return this._http.request({
1906
+ method: "PATCH",
1907
+ path: `/api/v1/promotions/${encodePathParam("promotionId", promotionId)}`,
1908
+ query: { organizationId },
1909
+ body,
1910
+ ...mergeRequestOptions(requestOptions)
1911
+ });
1912
+ }
1913
+ /**
1914
+ * Unassign Products from Promotion
1915
+ *
1916
+ * Remove product assignments and queue marketplace teardown. Requires `promotions:write`.
1917
+ *
1918
+ * `DELETE /api/v1/promotions/{promotionId}/products`
1919
+ */
1920
+ removeProducts(request, requestOptions) {
1921
+ const { promotionId, organizationId, ...body } = request ?? {};
1922
+ return this._http.request({
1923
+ method: "DELETE",
1924
+ path: `/api/v1/promotions/${encodePathParam("promotionId", promotionId)}/products`,
1925
+ query: { organizationId },
1926
+ body,
1927
+ ...mergeRequestOptions(requestOptions)
1928
+ });
1929
+ }
1930
+ /**
1931
+ * List Promotion Assignments
1932
+ *
1933
+ * List products assigned to a promotion. Requires `promotions:read`.
1934
+ *
1935
+ * `GET /api/v1/promotions/{promotionId}/products`
1936
+ */
1937
+ listProducts(request, requestOptions) {
1938
+ const { promotionId, organizationId } = request ?? {};
1939
+ return this._http.request({
1940
+ method: "GET",
1941
+ path: `/api/v1/promotions/${encodePathParam("promotionId", promotionId)}/products`,
1942
+ query: { organizationId },
1943
+ body: void 0,
1944
+ ...mergeRequestOptions(requestOptions)
1945
+ });
1946
+ }
1947
+ /**
1948
+ * Assign Products to Promotion
1949
+ *
1950
+ * Assign one or more products to a promotion. Creates pending marketplace sync rows; call sync after assign. Requires `promotions:write`.
1951
+ *
1952
+ * `POST /api/v1/promotions/{promotionId}/products`
1953
+ */
1954
+ addProducts(request, requestOptions) {
1955
+ const { promotionId, organizationId, ...body } = request ?? {};
1956
+ return this._http.request({
1957
+ method: "POST",
1958
+ path: `/api/v1/promotions/${encodePathParam("promotionId", promotionId)}/products`,
1959
+ query: { organizationId },
1960
+ body,
1961
+ ...mergeRequestOptions(requestOptions)
1962
+ });
1963
+ }
1964
+ /**
1965
+ * Sync Promotion to Marketplaces
1966
+ *
1967
+ * Queue marketplace push for assigned products (Shopee promotion, Lazada Store Flash Sale/voucher/Flexicombo, TikTok activity, or Shopify discount). Requires `promotions:write`.
1968
+ *
1969
+ * `POST /api/v1/promotions/{promotionId}/sync`
1970
+ */
1971
+ sync(request, requestOptions) {
1972
+ const { promotionId, organizationId, ...body } = request ?? {};
1973
+ return this._http.request({
1974
+ method: "POST",
1975
+ path: `/api/v1/promotions/${encodePathParam("promotionId", promotionId)}/sync`,
1976
+ query: { organizationId },
1977
+ body,
1978
+ ...mergeRequestOptions(requestOptions)
1979
+ });
1980
+ }
1981
+ };
1982
+ var ReturnsClient = class {
1983
+ constructor(_http) {
1984
+ this._http = _http;
1985
+ }
1986
+ _http;
1987
+ /**
1988
+ * List Returns
1989
+ *
1990
+ * List normalized, PII-free marketplace returns with SKU-level lines. Requires `returns:read`. Use updatedSince and cursor for bootstrap/recovery alongside return webhooks.
1991
+ *
1992
+ * `GET /api/v1/returns`
1993
+ */
1994
+ list(request = {}, requestOptions) {
1995
+ const {
1996
+ organizationId,
1997
+ marketplace,
1998
+ accountId,
1999
+ externalOrderId,
2000
+ updatedSince,
2001
+ cursor,
2002
+ limit
2003
+ } = request ?? {};
2004
+ return this._http.request({
2005
+ method: "GET",
2006
+ path: "/api/v1/returns",
2007
+ query: {
2008
+ organizationId,
2009
+ marketplace,
2010
+ accountId,
2011
+ externalOrderId,
2012
+ updatedSince,
2013
+ cursor,
2014
+ limit
2015
+ },
2016
+ body: void 0,
2017
+ ...mergeRequestOptions(requestOptions)
2018
+ });
2019
+ }
2020
+ /**
2021
+ * Get Return
2022
+ *
2023
+ * Get one normalized, PII-free return by OmniCommerce UUID. Requires `returns:read`; another organization's return returns 404.
2024
+ *
2025
+ * `GET /api/v1/returns/{returnId}`
2026
+ */
2027
+ get(request, requestOptions) {
2028
+ const { returnId, organizationId } = request ?? {};
2029
+ return this._http.request({
2030
+ method: "GET",
2031
+ path: `/api/v1/returns/${encodePathParam("returnId", returnId)}`,
2032
+ query: { organizationId },
2033
+ body: void 0,
2034
+ ...mergeRequestOptions(requestOptions)
2035
+ });
2036
+ }
2037
+ };
2038
+ var SearchClient = class {
2039
+ constructor(_http) {
2040
+ this._http = _http;
2041
+ }
2042
+ _http;
2043
+ /**
2044
+ * Search Public Merchant Products
2045
+ *
2046
+ * Search across all public merchants and products with optional merchant, pricing, stock, marketplace, and localization filters.
2047
+ *
2048
+ * `GET /api/v1/search`
2049
+ */
2050
+ list(request = {}, requestOptions) {
2051
+ const {
2052
+ q,
2053
+ category,
2054
+ brand,
2055
+ min_price,
2056
+ max_price,
2057
+ in_stock,
2058
+ merchant_ids,
2059
+ sort,
2060
+ platform,
2061
+ country,
2062
+ language,
2063
+ include_intent,
2064
+ limit,
2065
+ offset
2066
+ } = request ?? {};
2067
+ return this._http.request({
2068
+ method: "GET",
2069
+ path: "/api/v1/search",
2070
+ query: {
2071
+ q,
2072
+ category,
2073
+ brand,
2074
+ min_price,
2075
+ max_price,
2076
+ in_stock,
2077
+ merchant_ids,
2078
+ sort,
2079
+ platform,
2080
+ country,
2081
+ language,
2082
+ include_intent,
2083
+ limit,
2084
+ offset
2085
+ },
2086
+ body: void 0,
2087
+ ...mergeRequestOptions(requestOptions)
2088
+ });
2089
+ }
2090
+ /**
2091
+ * Search Public Merchant Products
2092
+ *
2093
+ * Search across all public merchants and products with optional merchant, pricing, stock, marketplace, and localization filters.
2094
+ *
2095
+ * `POST /api/v1/search`
2096
+ */
2097
+ query(request = {}, requestOptions) {
2098
+ const {
2099
+ q,
2100
+ category,
2101
+ brand,
2102
+ min_price,
2103
+ max_price,
2104
+ in_stock,
2105
+ merchant_ids,
2106
+ sort,
2107
+ platform,
2108
+ country,
2109
+ language,
2110
+ include_intent,
2111
+ limit,
2112
+ offset,
2113
+ ...body
2114
+ } = request ?? {};
2115
+ return this._http.request({
2116
+ method: "POST",
2117
+ path: "/api/v1/search",
2118
+ query: {
2119
+ q,
2120
+ category,
2121
+ brand,
2122
+ min_price,
2123
+ max_price,
2124
+ in_stock,
2125
+ merchant_ids,
2126
+ sort,
2127
+ platform,
2128
+ country,
2129
+ language,
2130
+ include_intent,
2131
+ limit,
2132
+ offset
2133
+ },
2134
+ body,
2135
+ ...mergeRequestOptions(requestOptions)
2136
+ });
2137
+ }
2138
+ };
2139
+ var SettlementsClient = class {
2140
+ constructor(_http) {
2141
+ this._http = _http;
2142
+ }
2143
+ _http;
2144
+ /**
2145
+ * List Settlements
2146
+ *
2147
+ * List the latest normalized order-settlement snapshots created by finance ingestion. Requires `settlements:read`. Use updatedSince and cursor for recovery; money remains partitioned by currency.
2148
+ *
2149
+ * `GET /api/v1/settlements`
2150
+ */
2151
+ list(request = {}, requestOptions) {
2152
+ const {
2153
+ organizationId,
2154
+ marketplace,
2155
+ accountId,
2156
+ orderId,
2157
+ externalOrderId,
2158
+ updatedSince,
2159
+ cursor,
2160
+ limit
2161
+ } = request ?? {};
2162
+ return this._http.request({
2163
+ method: "GET",
2164
+ path: "/api/v1/settlements",
2165
+ query: {
2166
+ organizationId,
2167
+ marketplace,
2168
+ accountId,
2169
+ orderId,
2170
+ externalOrderId,
2171
+ updatedSince,
2172
+ cursor,
2173
+ limit
2174
+ },
2175
+ body: void 0,
2176
+ ...mergeRequestOptions(requestOptions)
2177
+ });
2178
+ }
2179
+ /**
2180
+ * Apply Settlements
2181
+ *
2182
+ * Apply marketplace-agnostic settlement lines to existing orders.
2183
+
2184
+ ### Authentication
2185
+
2186
+ Requires `orders:write`.
2187
+
2188
+ ### What this endpoint does
2189
+
2190
+ - Stores every submitted line as marketplace financial evidence.
2191
+ - Projects **settled** rows into the order finance ledger.
2192
+ - Keeps pending, reversed, and voided rows as evidence only, removing any earlier developer API ledger projection for the same `sourceEventKey`.
2193
+ - Recomputes Payment received when a marketplace-specific formula exists. Zalora is currently supported.
2194
+
2195
+ ### Order matching
2196
+
2197
+ Orders are matched by organization, marketplace platform, and exact `externalOrderId`. Include `externalOrderItemId` when an order has multiple lines.
2198
+
2199
+ - `accountId` is an exact store match, never a wildcard.
2200
+ - `marketplace=zalora` can match Zalora Seller Center or
2201
+ *
2202
+ * `POST /api/v1/settlements`
2203
+ */
2204
+ create(request, requestOptions) {
2205
+ const { ...body } = request ?? {};
2206
+ return this._http.request({
2207
+ method: "POST",
2208
+ path: "/api/v1/settlements",
2209
+ query: void 0,
2210
+ body,
2211
+ ...mergeRequestOptions(requestOptions)
2212
+ });
2213
+ }
2214
+ /**
2215
+ * Get Settlement
2216
+ *
2217
+ * Get the latest normalized settlement snapshot by stable settlement ID. Requires `settlements:read`.
2218
+ *
2219
+ * `GET /api/v1/settlements/{settlementId}`
2220
+ */
2221
+ get(request, requestOptions) {
2222
+ const { settlementId, organizationId } = request ?? {};
2223
+ return this._http.request({
2224
+ method: "GET",
2225
+ path: `/api/v1/settlements/${encodePathParam("settlementId", settlementId)}`,
2226
+ query: { organizationId },
2227
+ body: void 0,
2228
+ ...mergeRequestOptions(requestOptions)
2229
+ });
2230
+ }
2231
+ };
2232
+ var SyncClient = class {
2233
+ constructor(_http) {
2234
+ this._http = _http;
2235
+ }
2236
+ _http;
2237
+ /**
2238
+ * Sync Product Commercial Fields
2239
+ *
2240
+ * Update price, sale price, or stock quantity in OmniCommerce and queue marketplace sync workers where applicable.
2241
+ *
2242
+ * `POST /api/v1/sync`
2243
+ */
2244
+ run(request = {}, requestOptions) {
2245
+ const { ...body } = request ?? {};
2246
+ return this._http.request({
2247
+ method: "POST",
2248
+ path: "/api/v1/sync",
2249
+ query: void 0,
2250
+ body,
2251
+ ...mergeRequestOptions(requestOptions)
2252
+ });
2253
+ }
2254
+ };
2255
+ var ThreadsClient = class {
2256
+ constructor(_http) {
2257
+ this._http = _http;
2258
+ }
2259
+ _http;
2260
+ /**
2261
+ * Get Thread Status
2262
+ *
2263
+ * Poll an AOP execution started by `POST /api/v1/aop/{aopId}/execute`. Requires `aops:read`. Status values are `running`, `completed`, or `failed`.
2264
+ *
2265
+ * `GET /api/v1/threads/{thread_id}/status`
2266
+ */
2267
+ getStatus(request, requestOptions) {
2268
+ const {
2269
+ thread_id: threadId,
2270
+ include_messages,
2271
+ organizationId
2272
+ } = request ?? {};
2273
+ return this._http.request({
2274
+ method: "GET",
2275
+ path: `/api/v1/threads/${encodePathParam("thread_id", threadId)}/status`,
2276
+ query: { include_messages, organizationId },
2277
+ body: void 0,
2278
+ ...mergeRequestOptions(requestOptions)
2279
+ });
2280
+ }
2281
+ };
2282
+ var UcpCheckoutSessionsClient = class {
2283
+ constructor(_http) {
2284
+ this._http = _http;
2285
+ }
2286
+ _http;
2287
+ /**
2288
+ * Create UCP Checkout Session
2289
+ *
2290
+ * Create a UCP shopping checkout session against the authenticated organization. The facade translates UCP line items to native agentic checkout sessions, reserves inventory, and returns a UCP checkout resource. Requires `UCP-Agent` and OAuth `checkout:write`.
2291
+ *
2292
+ * `POST /ucp/v1/checkout-sessions`
2293
+ */
2294
+ create(request, requestOptions) {
2295
+ const { ...body } = request ?? {};
2296
+ return this._http.request({
2297
+ method: "POST",
2298
+ path: "/ucp/v1/checkout-sessions",
2299
+ query: void 0,
2300
+ body,
2301
+ ...mergeRequestOptions(requestOptions)
2302
+ });
2303
+ }
2304
+ /**
2305
+ * Get UCP Checkout Session
2306
+ *
2307
+ * Fetch the current UCP checkout resource for a native agentic checkout session. Requires `UCP-Agent` and bearer authentication.
2308
+ *
2309
+ * `GET /ucp/v1/checkout-sessions/{sessionId}`
2310
+ */
2311
+ get(request, requestOptions) {
2312
+ const { sessionId, organizationId } = request ?? {};
2313
+ return this._http.request({
2314
+ method: "GET",
2315
+ path: `/ucp/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}`,
2316
+ query: { organizationId },
2317
+ body: void 0,
2318
+ ...mergeRequestOptions(requestOptions)
2319
+ });
2320
+ }
2321
+ /**
2322
+ * Update UCP Checkout Session
2323
+ *
2324
+ * Update UCP cart, buyer, fulfillment, or payment rail fields. Provided fields are applied to the native checkout session and inventory reservations are refreshed when line items change. Requires `UCP-Agent` and OAuth `checkout:write`.
2325
+ *
2326
+ * `PATCH /ucp/v1/checkout-sessions/{sessionId}`
2327
+ */
2328
+ update(request, requestOptions) {
2329
+ const { sessionId, organizationId, ...body } = request ?? {};
2330
+ return this._http.request({
2331
+ method: "PATCH",
2332
+ path: `/ucp/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}`,
2333
+ query: { organizationId },
2334
+ body,
2335
+ ...mergeRequestOptions(requestOptions)
2336
+ });
2337
+ }
2338
+ /**
2339
+ * Replace UCP Checkout Session Fields
2340
+ *
2341
+ * UCP-compatible update method. Current behavior matches PATCH: provided fields are applied and omitted fields remain unchanged. Requires `UCP-Agent` and OAuth `checkout:write`.
2342
+ *
2343
+ * `PUT /ucp/v1/checkout-sessions/{sessionId}`
2344
+ */
2345
+ replace(request, requestOptions) {
2346
+ const { sessionId, organizationId, ...body } = request ?? {};
2347
+ return this._http.request({
2348
+ method: "PUT",
2349
+ path: `/ucp/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}`,
2350
+ query: { organizationId },
2351
+ body,
2352
+ ...mergeRequestOptions(requestOptions)
2353
+ });
2354
+ }
2355
+ /**
2356
+ * Cancel UCP Checkout Session
2357
+ *
2358
+ * Cancel a ready-for-payment UCP checkout session and release reserved inventory. Requires `UCP-Agent` and OAuth `checkout:write`.
2359
+ *
2360
+ * `POST /ucp/v1/checkout-sessions/{sessionId}/cancel`
2361
+ */
2362
+ cancel(request, requestOptions) {
2363
+ const { sessionId, organizationId, ...body } = request ?? {};
2364
+ return this._http.request({
2365
+ method: "POST",
2366
+ path: `/ucp/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}/cancel`,
2367
+ query: { organizationId },
2368
+ body,
2369
+ ...mergeRequestOptions(requestOptions)
2370
+ });
2371
+ }
2372
+ /**
2373
+ * Complete UCP Checkout Session
2374
+ *
2375
+ * Settle the selected rail and create a native `agentic` order. Settlement failures return HTTP 402 with the checkout still ready for payment. Requires `UCP-Agent` and OAuth `checkout:write`.
2376
+ *
2377
+ * `POST /ucp/v1/checkout-sessions/{sessionId}/complete`
2378
+ */
2379
+ complete(request, requestOptions) {
2380
+ const { sessionId, organizationId, ...body } = request ?? {};
2381
+ return this._http.request({
2382
+ method: "POST",
2383
+ path: `/ucp/v1/checkout-sessions/${encodePathParam("sessionId", sessionId)}/complete`,
2384
+ query: { organizationId },
2385
+ body,
2386
+ ...mergeRequestOptions(requestOptions)
2387
+ });
2388
+ }
2389
+ };
2390
+ var UcpOrdersClient = class {
2391
+ constructor(_http) {
2392
+ this._http = _http;
2393
+ }
2394
+ _http;
2395
+ /**
2396
+ * Get UCP Order
2397
+ *
2398
+ * Fetch the native OmniCommerce order created by a completed UCP checkout session. Only `agentic` orders are exposed through this facade.
2399
+ *
2400
+ * `GET /ucp/v1/orders/{orderId}`
2401
+ */
2402
+ get(request, requestOptions) {
2403
+ const { orderId, organizationId } = request ?? {};
2404
+ return this._http.request({
2405
+ method: "GET",
2406
+ path: `/ucp/v1/orders/${encodePathParam("orderId", orderId)}`,
2407
+ query: { organizationId },
2408
+ body: void 0,
2409
+ ...mergeRequestOptions(requestOptions)
2410
+ });
2411
+ }
2412
+ };
2413
+ var UcpClient = class {
2414
+ constructor(_http) {
2415
+ this._http = _http;
2416
+ this.checkoutSessions = new UcpCheckoutSessionsClient(this._http);
2417
+ this.orders = new UcpOrdersClient(this._http);
2418
+ }
2419
+ _http;
2420
+ checkoutSessions;
2421
+ orders;
2422
+ };
2423
+ var WebhookEventsClient = class {
2424
+ constructor(_http) {
2425
+ this._http = _http;
2426
+ }
2427
+ _http;
2428
+ /**
2429
+ * List Webhook Events
2430
+ *
2431
+ * Pull immutable webhook events for recovery or scheduled reconciliation. Requires `webhooks:manage`. Results are organization-scoped and ordered oldest first; continue with the opaque cursor. This is the pull fallback for a receiver that missed push deliveries.
2432
+ *
2433
+ * `GET /api/v1/webhook-events`
2434
+ */
2435
+ list(request = {}, requestOptions) {
2436
+ const { organizationId, eventType, occurredSince, cursor, limit } = request ?? {};
2437
+ return this._http.request({
2438
+ method: "GET",
2439
+ path: "/api/v1/webhook-events",
2440
+ query: { organizationId, eventType, occurredSince, cursor, limit },
2441
+ body: void 0,
2442
+ ...mergeRequestOptions(requestOptions)
2443
+ });
2444
+ }
2445
+ };
2446
+ var WebhooksClient = class {
2447
+ constructor(_http) {
2448
+ this._http = _http;
2449
+ }
2450
+ _http;
2451
+ /**
2452
+ * List Developer Webhooks
2453
+ *
2454
+ * List configured developer webhook subscriptions for the authenticated organization.
2455
+ *
2456
+ * `GET /api/v1/webhooks`
2457
+ */
2458
+ list(requestOptions) {
2459
+ return this._http.request({
2460
+ method: "GET",
2461
+ path: "/api/v1/webhooks",
2462
+ query: void 0,
2463
+ body: void 0,
2464
+ ...mergeRequestOptions(requestOptions)
2465
+ });
2466
+ }
2467
+ /**
2468
+ * Create Developer Webhook
2469
+ *
2470
+ * Create a developer webhook subscription for the authenticated organization. The signing secret is returned only once.
2471
+ *
2472
+ * `POST /api/v1/webhooks`
2473
+ */
2474
+ create(request, requestOptions) {
2475
+ const { ...body } = request ?? {};
2476
+ return this._http.request({
2477
+ method: "POST",
2478
+ path: "/api/v1/webhooks",
2479
+ query: void 0,
2480
+ body,
2481
+ ...mergeRequestOptions(requestOptions)
2482
+ });
2483
+ }
2484
+ };
2485
+ var ZaloraClient = class {
2486
+ constructor(_http) {
2487
+ this._http = _http;
2488
+ }
2489
+ _http;
2490
+ /**
2491
+ * Get Selected Zalora Import Status
2492
+ *
2493
+ * Requires catalog:read. Follow the unchanged links.job URL returned by POST. Reads current state once without waiting.
2494
+
2495
+ ### Completion
2496
+
2497
+ data.status is pending, running, success, or error; data.terminal and data.success identify completion. data.productIds contains mapped Omni IDs for the supplied product sets. Failed imports remain explicit, including missingExternalIds. The top-level completed status describes this status request, not the import.
2498
+
2499
+ Keep the original target IDs: the status lookup resolves those targets and does not prove that a modified selection was part of this job.
2500
+ *
2501
+ * `GET /api/v1/zalora/import`
2502
+ */
2503
+ getImport(request, requestOptions) {
2504
+ const { organizationId, jobId, storeId, productSetIds } = request ?? {};
2505
+ return this._http.request({
2506
+ method: "GET",
2507
+ path: "/api/v1/zalora/import",
2508
+ query: { organizationId, jobId, storeId, productSetIds },
2509
+ body: void 0,
2510
+ ...mergeRequestOptions(requestOptions)
2511
+ });
2512
+ }
2513
+ /**
2514
+ * Import Selected Zalora Products
2515
+ *
2516
+ * Requires catalog:write. Queue an exact import of 1–25 Zalora productSetIds from a connected store. Omit storeId only when one store or one default store is unambiguous.
2517
+
2518
+ Returns 202 with links.job for optional status checks and retrieval of Omni product IDs. Only one import may run per store at a time. This endpoint does not invoke an AOP, enrich products, or publish listings.
2519
+ *
2520
+ * `POST /api/v1/zalora/import`
2521
+ */
2522
+ importProducts(request, requestOptions) {
2523
+ const { ...body } = request ?? {};
2524
+ return this._http.request({
2525
+ method: "POST",
2526
+ path: "/api/v1/zalora/import",
2527
+ query: void 0,
2528
+ body,
2529
+ ...mergeRequestOptions(requestOptions)
2530
+ });
2531
+ }
2532
+ };
2533
+ var OmniGeneratedClient = class {
2534
+ constructor(_http) {
2535
+ this._http = _http;
2536
+ this.aop = new AopClient(this._http);
2537
+ this.api = new ApiClient(this._http);
2538
+ this.catalog = new CatalogClient(this._http);
2539
+ this.checkoutSessions = new CheckoutSessionsClient(this._http);
2540
+ this.compare = new CompareClient(this._http);
2541
+ this.directory = new DirectoryClient(this._http);
2542
+ this.evaluate = new EvaluateClient(this._http);
2543
+ this.feed = new FeedClient(this._http);
2544
+ this.images = new ImagesClient(this._http);
2545
+ this.jobs = new JobsClient(this._http);
2546
+ this.looks = new LooksClient(this._http);
2547
+ this.marketplaces = new MarketplacesClient(this._http);
2548
+ this.merchants = new MerchantsClient(this._http);
2549
+ this.monitor = new MonitorClient(this._http);
2550
+ this.oauth = new OauthClient(this._http);
2551
+ this.orders = new OrdersClient(this._http);
2552
+ this.organizations = new OrganizationsClient(this._http);
2553
+ this.priceBooks = new PriceBooksClient(this._http);
2554
+ this.productCategories = new ProductCategoriesClient(this._http);
2555
+ this.products = new ProductsClient(this._http);
2556
+ this.promotions = new PromotionsClient(this._http);
2557
+ this.returns = new ReturnsClient(this._http);
2558
+ this.search = new SearchClient(this._http);
2559
+ this.settlements = new SettlementsClient(this._http);
2560
+ this.sync = new SyncClient(this._http);
2561
+ this.threads = new ThreadsClient(this._http);
2562
+ this.ucp = new UcpClient(this._http);
2563
+ this.webhookEvents = new WebhookEventsClient(this._http);
2564
+ this.webhooks = new WebhooksClient(this._http);
2565
+ this.zalora = new ZaloraClient(this._http);
2566
+ }
2567
+ _http;
2568
+ aop;
2569
+ api;
2570
+ catalog;
2571
+ checkoutSessions;
2572
+ compare;
2573
+ directory;
2574
+ evaluate;
2575
+ feed;
2576
+ images;
2577
+ jobs;
2578
+ looks;
2579
+ marketplaces;
2580
+ merchants;
2581
+ monitor;
2582
+ oauth;
2583
+ orders;
2584
+ organizations;
2585
+ priceBooks;
2586
+ productCategories;
2587
+ products;
2588
+ promotions;
2589
+ returns;
2590
+ search;
2591
+ settlements;
2592
+ sync;
2593
+ threads;
2594
+ ucp;
2595
+ webhookEvents;
2596
+ webhooks;
2597
+ zalora;
2598
+ };
2599
+
2600
+ // src/Client.ts
2601
+ var OmniClient = class extends OmniGeneratedClient {
2602
+ constructor(options = {}) {
2603
+ super(new OmniHttp(normalizeClientOptions(options)));
2604
+ }
2605
+ request(init) {
2606
+ return this._http.request(init);
2607
+ }
2608
+ };
2609
+
2610
+ // src/webhooks.ts
2611
+ var encoder = new TextEncoder();
2612
+ var WEBHOOK_SIGNATURE_HEADER = "x-omni-signature";
2613
+ var WEBHOOK_TIMESTAMP_HEADER = "x-omni-timestamp";
2614
+ var WEBHOOK_EVENT_ID_HEADER = "x-omni-event-id";
2615
+ var WEBHOOK_EVENT_TYPE_HEADER = "x-omni-event-type";
2616
+ function headerValue(headers, name) {
2617
+ if (typeof Headers !== "undefined" && headers instanceof Headers) {
2618
+ return headers.get(name) ?? headers.get(name.toLowerCase()) ?? void 0;
2619
+ }
2620
+ const record = headers;
2621
+ const direct = record[name] ?? record[name.toLowerCase()];
2622
+ if (Array.isArray(direct)) return direct[0];
2623
+ return direct ?? void 0;
2624
+ }
2625
+ function toHex(bytes) {
2626
+ return [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
2627
+ }
2628
+ function timingSafeEqual(left, right) {
2629
+ if (left.length !== right.length) return false;
2630
+ let mismatch = 0;
2631
+ for (let i = 0; i < left.length; i++) {
2632
+ mismatch |= left.charCodeAt(i) ^ right.charCodeAt(i);
2633
+ }
2634
+ return mismatch === 0;
2635
+ }
2636
+ async function signWebhookPayload(input) {
2637
+ const key = await crypto.subtle.importKey(
2638
+ "raw",
2639
+ encoder.encode(input.secret),
2640
+ { name: "HMAC", hash: "SHA-256" },
2641
+ false,
2642
+ ["sign"]
2643
+ );
2644
+ const signature = await crypto.subtle.sign(
2645
+ "HMAC",
2646
+ key,
2647
+ encoder.encode(`${input.timestamp}.${input.payload}`)
2648
+ );
2649
+ return toHex(signature);
2650
+ }
2651
+ async function verifyWebhookSignature(input) {
2652
+ const expected = await signWebhookPayload(input);
2653
+ return timingSafeEqual(expected.toLowerCase(), input.signature.toLowerCase());
2654
+ }
2655
+ async function constructEvent(payload, headers, secret, options) {
2656
+ const rawBody = typeof payload === "string" ? payload : new TextDecoder().decode(payload);
2657
+ const signature = headerValue(headers, WEBHOOK_SIGNATURE_HEADER);
2658
+ const timestampRaw = headerValue(headers, WEBHOOK_TIMESTAMP_HEADER);
2659
+ if (!signature || !timestampRaw) {
2660
+ throw new Error(
2661
+ "Webhook signature verification failed: missing X-Omni-Signature or X-Omni-Timestamp."
2662
+ );
2663
+ }
2664
+ const timestamp = Number(timestampRaw);
2665
+ if (!Number.isFinite(timestamp)) {
2666
+ throw new Error(
2667
+ "Webhook signature verification failed: invalid timestamp."
2668
+ );
2669
+ }
2670
+ const tolerance = options?.toleranceInSeconds ?? 300;
2671
+ const now = Math.floor(Date.now() / 1e3);
2672
+ if (Math.abs(now - timestamp) > tolerance) {
2673
+ throw new Error(
2674
+ "Webhook signature verification failed: timestamp outside tolerance."
2675
+ );
2676
+ }
2677
+ const valid = await verifyWebhookSignature({
2678
+ secret,
2679
+ timestamp,
2680
+ payload: rawBody,
2681
+ signature
2682
+ });
2683
+ if (!valid) {
2684
+ throw new Error(
2685
+ "Webhook signature verification failed: invalid signature."
2686
+ );
2687
+ }
2688
+ let parsed = rawBody;
2689
+ try {
2690
+ parsed = JSON.parse(rawBody);
2691
+ } catch {
2692
+ throw new Error("Webhook signature verification failed: body is not JSON.");
2693
+ }
2694
+ return {
2695
+ eventId: headerValue(headers, WEBHOOK_EVENT_ID_HEADER),
2696
+ eventType: headerValue(headers, WEBHOOK_EVENT_TYPE_HEADER),
2697
+ timestamp,
2698
+ payload: parsed,
2699
+ rawBody
2700
+ };
2701
+ }
2702
+
2703
+ // src/api/index.ts
2704
+ var api_exports = {};
2705
+ __export(api_exports, {
2706
+ OmniGeneratedClient: () => OmniGeneratedClient
2707
+ });
2708
+
2709
+ exports.BadGatewayError = BadGatewayError;
2710
+ exports.BadRequestError = BadRequestError;
2711
+ exports.ForbiddenError = ForbiddenError;
2712
+ exports.HttpResponsePromise = HttpResponsePromise;
2713
+ exports.InternalServerError = InternalServerError;
2714
+ exports.JobFailedError = JobFailedError;
2715
+ exports.NotFoundError = NotFoundError;
2716
+ exports.Omni = api_exports;
2717
+ exports.OmniClient = OmniClient;
2718
+ exports.OmniEnvironment = OmniEnvironment;
2719
+ exports.OmniError = OmniError;
2720
+ exports.OmniTimeoutError = OmniTimeoutError;
2721
+ exports.SDK_VERSION = SDK_VERSION;
2722
+ exports.ServiceUnavailableError = ServiceUnavailableError;
2723
+ exports.TooManyRequestsError = TooManyRequestsError;
2724
+ exports.UnauthorizedError = UnauthorizedError;
2725
+ exports.UnprocessableEntityError = UnprocessableEntityError;
2726
+ exports.WEBHOOK_EVENT_ID_HEADER = WEBHOOK_EVENT_ID_HEADER;
2727
+ exports.WEBHOOK_EVENT_TYPE_HEADER = WEBHOOK_EVENT_TYPE_HEADER;
2728
+ exports.WEBHOOK_SIGNATURE_HEADER = WEBHOOK_SIGNATURE_HEADER;
2729
+ exports.WEBHOOK_TIMESTAMP_HEADER = WEBHOOK_TIMESTAMP_HEADER;
2730
+ exports.constructEvent = constructEvent;
2731
+ exports.signWebhookPayload = signWebhookPayload;
2732
+ exports.verifyWebhookSignature = verifyWebhookSignature;
2733
+ //# sourceMappingURL=index.cjs.map
2734
+ //# sourceMappingURL=index.cjs.map