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