@omni-commerce/cli 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,2630 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/run.ts
4
+ import { stdin as input } from "process";
5
+ import { OmniClient, OmniError } from "@omni-commerce/sdk";
6
+
7
+ // src/argv.ts
8
+ var GLOBAL_TRUE_FLAGS = /* @__PURE__ */ new Set([
9
+ "help",
10
+ "h",
11
+ "schema",
12
+ "dry-run",
13
+ "version",
14
+ "v"
15
+ ]);
16
+ function parseArgv(argv) {
17
+ const trail = [];
18
+ const flags = {};
19
+ let help = false;
20
+ let schema = false;
21
+ let dryRun = false;
22
+ for (let index = 0; index < argv.length; index += 1) {
23
+ const token = argv[index];
24
+ if (token === "--") {
25
+ trail.push(...argv.slice(index + 1));
26
+ break;
27
+ }
28
+ if (token === "-h" || token === "--help") {
29
+ help = true;
30
+ continue;
31
+ }
32
+ if (token === "--schema") {
33
+ schema = true;
34
+ continue;
35
+ }
36
+ if (token === "--dry-run") {
37
+ dryRun = true;
38
+ continue;
39
+ }
40
+ if (token === "-v" || token === "--version") {
41
+ flags.version = true;
42
+ continue;
43
+ }
44
+ if (token.startsWith("--")) {
45
+ const stripped = token.slice(2);
46
+ const eq = stripped.indexOf("=");
47
+ if (eq >= 0) {
48
+ flags[stripped.slice(0, eq)] = stripped.slice(eq + 1);
49
+ continue;
50
+ }
51
+ const next = argv[index + 1];
52
+ if (!next || next.startsWith("-") && next !== "-" || GLOBAL_TRUE_FLAGS.has(stripped)) {
53
+ flags[stripped] = true;
54
+ continue;
55
+ }
56
+ flags[stripped] = next;
57
+ index += 1;
58
+ continue;
59
+ }
60
+ if (token.startsWith("-") && token.length === 2) {
61
+ continue;
62
+ }
63
+ trail.push(token);
64
+ }
65
+ return { trail, flags, help, schema, dryRun };
66
+ }
67
+ function flagString(flags, name) {
68
+ const value = flags[name];
69
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
70
+ }
71
+
72
+ // src/config.ts
73
+ import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
74
+ import { homedir } from "os";
75
+ import path from "path";
76
+ function configPath() {
77
+ return path.join(homedir(), ".omni", "config.json");
78
+ }
79
+ async function readConfig() {
80
+ try {
81
+ const raw = await readFile(configPath(), "utf8");
82
+ const parsed = JSON.parse(raw);
83
+ return parsed && typeof parsed === "object" ? parsed : {};
84
+ } catch {
85
+ return {};
86
+ }
87
+ }
88
+ async function writeConfig(config) {
89
+ const directory = path.dirname(configPath());
90
+ await mkdir(directory, { recursive: true });
91
+ await writeFile(configPath(), `${JSON.stringify(config, null, 2)}
92
+ `, "utf8");
93
+ await chmod(configPath(), 384);
94
+ }
95
+ async function clearConfig() {
96
+ await rm(configPath(), { force: true });
97
+ }
98
+ async function resolveCredentials(input2) {
99
+ const file = await readConfig();
100
+ const apiKey = input2.apiKey || process.env.OMNI_API_KEY || file.apiKey || void 0;
101
+ const source = input2.apiKey ? "flag" : process.env.OMNI_API_KEY ? "env" : file.apiKey ? "config" : "none";
102
+ const baseUrl = input2.baseUrl || process.env.OMNI_BASE_URL || file.baseUrl || "https://omnicommerce.sg";
103
+ return { apiKey, baseUrl, source };
104
+ }
105
+ function maskSecret(value) {
106
+ if (value.length <= 8) return "********";
107
+ return `${value.slice(0, 7)}\u2026${value.slice(-4)}`;
108
+ }
109
+
110
+ // src/execute.ts
111
+ function interpolatePath(template, values) {
112
+ return template.replace(/\{([^}]+)\}/g, (_, name) => {
113
+ const value = values[name];
114
+ if (!value) {
115
+ throw new Error(`Missing required path parameter: ${name}`);
116
+ }
117
+ return encodeURIComponent(value);
118
+ });
119
+ }
120
+ function stringValue(value, flag) {
121
+ if (typeof value !== "string" || value.trim() === "") {
122
+ throw new Error(`Missing required flag --${flag}`);
123
+ }
124
+ return value;
125
+ }
126
+ async function executeCommand(client, command, request) {
127
+ if (command.resourcePath[0] === "jobs" && command.methodName === "wait") {
128
+ const jobId = stringValue(request.jobId, "job-id");
129
+ const organizationId = typeof request.organizationId === "string" ? request.organizationId : void 0;
130
+ return client.jobs.wait({ jobId, organizationId });
131
+ }
132
+ const pathValues = {};
133
+ const query = {};
134
+ const consumed = /* @__PURE__ */ new Set();
135
+ for (const flag of command.flags) {
136
+ const value = request[flag.name];
137
+ if (value === void 0) continue;
138
+ consumed.add(flag.name);
139
+ if (flag.source === "path") {
140
+ pathValues[flag.name] = stringValue(value, flag.flag);
141
+ } else {
142
+ query[flag.name] = value;
143
+ }
144
+ }
145
+ const body = {};
146
+ for (const [key, value] of Object.entries(request)) {
147
+ if (!consumed.has(key)) body[key] = value;
148
+ }
149
+ return client.request({
150
+ method: command.httpMethod,
151
+ path: interpolatePath(command.path, pathValues),
152
+ query: Object.keys(query).length > 0 ? query : void 0,
153
+ body: command.acceptsJsonBody && Object.keys(body).length > 0 ? body : void 0
154
+ });
155
+ }
156
+
157
+ // src/format.ts
158
+ function resolveFormat(flag, stdoutIsTty) {
159
+ if (flag === "table" || flag === "json") return flag;
160
+ return stdoutIsTty ? "table" : "json";
161
+ }
162
+ function cell(value) {
163
+ if (value === null || value === void 0) return "";
164
+ if (typeof value === "string") return value;
165
+ if (typeof value === "number" || typeof value === "boolean") {
166
+ return String(value);
167
+ }
168
+ return JSON.stringify(value);
169
+ }
170
+ function isRecord(value) {
171
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
172
+ }
173
+ function formatOutput(value, format) {
174
+ if (format === "json") return `${JSON.stringify(value, null, 2)}
175
+ `;
176
+ if (Array.isArray(value) && value.every(isRecord)) {
177
+ if (value.length === 0) return "";
178
+ const keys = [...new Set(value.flatMap((row) => Object.keys(row)))].slice(
179
+ 0,
180
+ 8
181
+ );
182
+ const header = keys.join(" ");
183
+ const body = value.map((row) => keys.map((key) => cell(row[key])).join(" ")).join("\n");
184
+ return `${header}
185
+ ${body}
186
+ `;
187
+ }
188
+ if (isRecord(value)) {
189
+ return `${Object.entries(value).map(([key, entry]) => `${key} ${cell(entry)}`).join("\n")}
190
+ `;
191
+ }
192
+ return `${cell(value)}
193
+ `;
194
+ }
195
+
196
+ // src/generated/commands.ts
197
+ var COMMANDS = [
198
+ {
199
+ trail: ["api", "root"],
200
+ resourcePath: ["api"],
201
+ methodName: "root",
202
+ httpMethod: "GET",
203
+ path: "/api",
204
+ summary: "API Root",
205
+ flags: [],
206
+ acceptsJsonBody: false,
207
+ bodyRequired: false
208
+ },
209
+ {
210
+ trail: ["api", "v1"],
211
+ resourcePath: ["api"],
212
+ methodName: "v1",
213
+ httpMethod: "GET",
214
+ path: "/api/v1",
215
+ summary: "API v1 Root",
216
+ flags: [],
217
+ acceptsJsonBody: false,
218
+ bodyRequired: false
219
+ },
220
+ {
221
+ trail: ["aop", "get-config"],
222
+ resourcePath: ["aop"],
223
+ methodName: "getConfig",
224
+ httpMethod: "GET",
225
+ path: "/api/v1/aop/{aopId}/config",
226
+ summary: "Get AOP configuration",
227
+ flags: [
228
+ {
229
+ name: "aopId",
230
+ flag: "aop-id",
231
+ required: true,
232
+ source: "path"
233
+ },
234
+ {
235
+ name: "organizationId",
236
+ flag: "organization-id",
237
+ required: false,
238
+ source: "query"
239
+ }
240
+ ],
241
+ acceptsJsonBody: false,
242
+ bodyRequired: false
243
+ },
244
+ {
245
+ trail: ["aop", "update-config"],
246
+ resourcePath: ["aop"],
247
+ methodName: "updateConfig",
248
+ httpMethod: "PUT",
249
+ path: "/api/v1/aop/{aopId}/config",
250
+ summary: "Overwrite AOP configuration",
251
+ flags: [
252
+ {
253
+ name: "aopId",
254
+ flag: "aop-id",
255
+ required: true,
256
+ source: "path"
257
+ }
258
+ ],
259
+ acceptsJsonBody: true,
260
+ bodyRequired: true
261
+ },
262
+ {
263
+ trail: ["aop", "execute"],
264
+ resourcePath: ["aop"],
265
+ methodName: "execute",
266
+ httpMethod: "POST",
267
+ path: "/api/v1/aop/{aopId}/execute",
268
+ summary: "Execute an AOP",
269
+ flags: [
270
+ {
271
+ name: "aopId",
272
+ flag: "aop-id",
273
+ required: true,
274
+ source: "path"
275
+ }
276
+ ],
277
+ acceptsJsonBody: true,
278
+ bodyRequired: false
279
+ },
280
+ {
281
+ trail: ["aop", "create"],
282
+ resourcePath: ["aop"],
283
+ methodName: "create",
284
+ httpMethod: "POST",
285
+ path: "/api/v1/aop/create",
286
+ summary: "Create AOP",
287
+ flags: [],
288
+ acceptsJsonBody: true,
289
+ bodyRequired: true
290
+ },
291
+ {
292
+ trail: ["aop", "retry"],
293
+ resourcePath: ["aop"],
294
+ methodName: "retry",
295
+ httpMethod: "POST",
296
+ path: "/api/v1/aop/retry",
297
+ summary: "Retry a failed AOP execution",
298
+ flags: [],
299
+ acceptsJsonBody: true,
300
+ bodyRequired: true
301
+ },
302
+ {
303
+ trail: ["catalog", "list-items"],
304
+ resourcePath: ["catalog"],
305
+ methodName: "listItems",
306
+ httpMethod: "GET",
307
+ path: "/api/v1/catalog/items",
308
+ summary: "Export Catalog Items",
309
+ flags: [
310
+ {
311
+ name: "organizationId",
312
+ flag: "organization-id",
313
+ required: false,
314
+ source: "query"
315
+ },
316
+ {
317
+ name: "updatedSince",
318
+ flag: "updated-since",
319
+ required: false,
320
+ source: "query"
321
+ },
322
+ {
323
+ name: "cursor",
324
+ flag: "cursor",
325
+ required: false,
326
+ source: "query"
327
+ },
328
+ {
329
+ name: "limit",
330
+ flag: "limit",
331
+ required: false,
332
+ source: "query"
333
+ },
334
+ {
335
+ name: "format",
336
+ flag: "format",
337
+ required: false,
338
+ source: "query"
339
+ }
340
+ ],
341
+ acceptsJsonBody: false,
342
+ bodyRequired: false
343
+ },
344
+ {
345
+ trail: ["checkout-sessions", "create"],
346
+ resourcePath: ["checkoutSessions"],
347
+ methodName: "create",
348
+ httpMethod: "POST",
349
+ path: "/api/v1/checkout-sessions",
350
+ summary: "Create Agentic Checkout Session",
351
+ flags: [],
352
+ acceptsJsonBody: true,
353
+ bodyRequired: true
354
+ },
355
+ {
356
+ trail: ["checkout-sessions", "get"],
357
+ resourcePath: ["checkoutSessions"],
358
+ methodName: "get",
359
+ httpMethod: "GET",
360
+ path: "/api/v1/checkout-sessions/{sessionId}",
361
+ summary: "Get Agentic Checkout Session",
362
+ flags: [
363
+ {
364
+ name: "sessionId",
365
+ flag: "session-id",
366
+ required: true,
367
+ source: "path"
368
+ },
369
+ {
370
+ name: "organizationId",
371
+ flag: "organization-id",
372
+ required: false,
373
+ source: "query"
374
+ }
375
+ ],
376
+ acceptsJsonBody: false,
377
+ bodyRequired: false
378
+ },
379
+ {
380
+ trail: ["checkout-sessions", "update"],
381
+ resourcePath: ["checkoutSessions"],
382
+ methodName: "update",
383
+ httpMethod: "PATCH",
384
+ path: "/api/v1/checkout-sessions/{sessionId}",
385
+ summary: "Update Agentic Checkout Session",
386
+ flags: [
387
+ {
388
+ name: "sessionId",
389
+ flag: "session-id",
390
+ required: true,
391
+ source: "path"
392
+ },
393
+ {
394
+ name: "organizationId",
395
+ flag: "organization-id",
396
+ required: false,
397
+ source: "query"
398
+ }
399
+ ],
400
+ acceptsJsonBody: true,
401
+ bodyRequired: true
402
+ },
403
+ {
404
+ trail: ["checkout-sessions", "replace"],
405
+ resourcePath: ["checkoutSessions"],
406
+ methodName: "replace",
407
+ httpMethod: "PUT",
408
+ path: "/api/v1/checkout-sessions/{sessionId}",
409
+ summary: "Replace Agentic Checkout Session Fields",
410
+ flags: [
411
+ {
412
+ name: "sessionId",
413
+ flag: "session-id",
414
+ required: true,
415
+ source: "path"
416
+ },
417
+ {
418
+ name: "organizationId",
419
+ flag: "organization-id",
420
+ required: false,
421
+ source: "query"
422
+ }
423
+ ],
424
+ acceptsJsonBody: true,
425
+ bodyRequired: true
426
+ },
427
+ {
428
+ trail: ["checkout-sessions", "cancel"],
429
+ resourcePath: ["checkoutSessions"],
430
+ methodName: "cancel",
431
+ httpMethod: "POST",
432
+ path: "/api/v1/checkout-sessions/{sessionId}/cancel",
433
+ summary: "Cancel Agentic Checkout Session",
434
+ flags: [
435
+ {
436
+ name: "sessionId",
437
+ flag: "session-id",
438
+ required: true,
439
+ source: "path"
440
+ },
441
+ {
442
+ name: "organizationId",
443
+ flag: "organization-id",
444
+ required: false,
445
+ source: "query"
446
+ }
447
+ ],
448
+ acceptsJsonBody: true,
449
+ bodyRequired: false
450
+ },
451
+ {
452
+ trail: ["checkout-sessions", "complete"],
453
+ resourcePath: ["checkoutSessions"],
454
+ methodName: "complete",
455
+ httpMethod: "POST",
456
+ path: "/api/v1/checkout-sessions/{sessionId}/complete",
457
+ summary: "Complete Agentic Checkout Session",
458
+ flags: [
459
+ {
460
+ name: "sessionId",
461
+ flag: "session-id",
462
+ required: true,
463
+ source: "path"
464
+ },
465
+ {
466
+ name: "organizationId",
467
+ flag: "organization-id",
468
+ required: false,
469
+ source: "query"
470
+ }
471
+ ],
472
+ acceptsJsonBody: true,
473
+ bodyRequired: true
474
+ },
475
+ {
476
+ trail: ["compare", "get"],
477
+ resourcePath: ["compare"],
478
+ methodName: "get",
479
+ httpMethod: "GET",
480
+ path: "/api/v1/compare",
481
+ summary: "Compare Public Products",
482
+ flags: [
483
+ {
484
+ name: "products",
485
+ flag: "products",
486
+ required: true,
487
+ source: "query"
488
+ },
489
+ {
490
+ name: "language",
491
+ flag: "language",
492
+ required: false,
493
+ source: "query"
494
+ }
495
+ ],
496
+ acceptsJsonBody: false,
497
+ bodyRequired: false
498
+ },
499
+ {
500
+ trail: ["directory", "list"],
501
+ resourcePath: ["directory"],
502
+ methodName: "list",
503
+ httpMethod: "GET",
504
+ path: "/api/v1/directory",
505
+ summary: "List Public Merchants",
506
+ flags: [],
507
+ acceptsJsonBody: false,
508
+ bodyRequired: false
509
+ },
510
+ {
511
+ trail: ["evaluate", "run"],
512
+ resourcePath: ["evaluate"],
513
+ methodName: "run",
514
+ httpMethod: "POST",
515
+ path: "/api/v1/evaluate",
516
+ summary: "Evaluate SKU Readiness",
517
+ flags: [],
518
+ acceptsJsonBody: true,
519
+ bodyRequired: false
520
+ },
521
+ {
522
+ trail: ["feed", "get-llms-txt"],
523
+ resourcePath: ["feed"],
524
+ methodName: "getLlmsTxt",
525
+ httpMethod: "GET",
526
+ path: "/api/v1/feed/{domain}/llms.txt",
527
+ summary: "Get Merchant LLM Feed",
528
+ flags: [
529
+ {
530
+ name: "domain",
531
+ flag: "domain",
532
+ required: true,
533
+ source: "path"
534
+ },
535
+ {
536
+ name: "limit",
537
+ flag: "limit",
538
+ required: false,
539
+ source: "query"
540
+ }
541
+ ],
542
+ acceptsJsonBody: false,
543
+ bodyRequired: false
544
+ },
545
+ {
546
+ trail: ["images", "ghost-mannequin"],
547
+ resourcePath: ["images"],
548
+ methodName: "ghostMannequin",
549
+ httpMethod: "POST",
550
+ path: "/api/v1/images/ghost-mannequin",
551
+ summary: "Generate Ghost Mannequin Image",
552
+ flags: [],
553
+ acceptsJsonBody: true,
554
+ bodyRequired: true
555
+ },
556
+ {
557
+ trail: ["jobs", "get"],
558
+ resourcePath: ["jobs"],
559
+ methodName: "get",
560
+ httpMethod: "GET",
561
+ path: "/api/v1/jobs/{jobId}",
562
+ summary: "Get Developer Job Status",
563
+ flags: [
564
+ {
565
+ name: "jobId",
566
+ flag: "job-id",
567
+ required: true,
568
+ source: "path"
569
+ },
570
+ {
571
+ name: "organizationId",
572
+ flag: "organization-id",
573
+ required: false,
574
+ source: "query"
575
+ }
576
+ ],
577
+ acceptsJsonBody: false,
578
+ bodyRequired: false
579
+ },
580
+ {
581
+ trail: ["jobs", "cancel"],
582
+ resourcePath: ["jobs"],
583
+ methodName: "cancel",
584
+ httpMethod: "POST",
585
+ path: "/api/v1/jobs/{jobId}/cancel",
586
+ summary: "Cancel Developer Job",
587
+ flags: [
588
+ {
589
+ name: "jobId",
590
+ flag: "job-id",
591
+ required: true,
592
+ source: "path"
593
+ }
594
+ ],
595
+ acceptsJsonBody: true,
596
+ bodyRequired: false
597
+ },
598
+ {
599
+ trail: ["looks", "list"],
600
+ resourcePath: ["looks"],
601
+ methodName: "list",
602
+ httpMethod: "GET",
603
+ path: "/api/v1/looks",
604
+ summary: "List Looks",
605
+ flags: [
606
+ {
607
+ name: "q",
608
+ flag: "q",
609
+ required: false,
610
+ source: "query"
611
+ },
612
+ {
613
+ name: "status",
614
+ flag: "status",
615
+ required: false,
616
+ source: "query"
617
+ },
618
+ {
619
+ name: "limit",
620
+ flag: "limit",
621
+ required: false,
622
+ source: "query"
623
+ },
624
+ {
625
+ name: "offset",
626
+ flag: "offset",
627
+ required: false,
628
+ source: "query"
629
+ }
630
+ ],
631
+ acceptsJsonBody: false,
632
+ bodyRequired: false
633
+ },
634
+ {
635
+ trail: ["looks", "create"],
636
+ resourcePath: ["looks"],
637
+ methodName: "create",
638
+ httpMethod: "POST",
639
+ path: "/api/v1/looks",
640
+ summary: "Create Look",
641
+ flags: [],
642
+ acceptsJsonBody: true,
643
+ bodyRequired: true
644
+ },
645
+ {
646
+ trail: ["looks", "get"],
647
+ resourcePath: ["looks"],
648
+ methodName: "get",
649
+ httpMethod: "GET",
650
+ path: "/api/v1/looks/{lookId}",
651
+ summary: "Get Look",
652
+ flags: [
653
+ {
654
+ name: "lookId",
655
+ flag: "look-id",
656
+ required: true,
657
+ source: "path"
658
+ }
659
+ ],
660
+ acceptsJsonBody: false,
661
+ bodyRequired: false
662
+ },
663
+ {
664
+ trail: ["product-categories", "recommend"],
665
+ resourcePath: ["productCategories"],
666
+ methodName: "recommend",
667
+ httpMethod: "POST",
668
+ path: "/api/v1/manage-product-category/recommend",
669
+ summary: "Recommend Marketplace Product Categories",
670
+ flags: [],
671
+ acceptsJsonBody: true,
672
+ bodyRequired: true
673
+ },
674
+ {
675
+ trail: ["marketplaces", "list-connected"],
676
+ resourcePath: ["marketplaces"],
677
+ methodName: "listConnected",
678
+ httpMethod: "GET",
679
+ path: "/api/v1/marketplaces/connected",
680
+ summary: "List Connected Marketplaces",
681
+ flags: [
682
+ {
683
+ name: "organizationId",
684
+ flag: "organization-id",
685
+ required: false,
686
+ source: "query"
687
+ },
688
+ {
689
+ name: "marketplace",
690
+ flag: "marketplace",
691
+ required: false,
692
+ source: "query"
693
+ },
694
+ {
695
+ name: "country",
696
+ flag: "country",
697
+ required: false,
698
+ source: "query"
699
+ }
700
+ ],
701
+ acceptsJsonBody: false,
702
+ bodyRequired: false
703
+ },
704
+ {
705
+ trail: ["merchants", "get-manifest"],
706
+ resourcePath: ["merchants"],
707
+ methodName: "getManifest",
708
+ httpMethod: "GET",
709
+ path: "/api/v1/merchants/{merchantId}/manifest",
710
+ summary: "Get Public Merchant Manifest",
711
+ flags: [
712
+ {
713
+ name: "merchantId",
714
+ flag: "merchant-id",
715
+ required: true,
716
+ source: "path"
717
+ }
718
+ ],
719
+ acceptsJsonBody: false,
720
+ bodyRequired: false
721
+ },
722
+ {
723
+ trail: ["merchants", "list-products"],
724
+ resourcePath: ["merchants"],
725
+ methodName: "listProducts",
726
+ httpMethod: "GET",
727
+ path: "/api/v1/merchants/{merchantId}/products",
728
+ summary: "List Public Merchant Products",
729
+ flags: [
730
+ {
731
+ name: "merchantId",
732
+ flag: "merchant-id",
733
+ required: true,
734
+ source: "path"
735
+ },
736
+ {
737
+ name: "platform",
738
+ flag: "platform",
739
+ required: false,
740
+ source: "query"
741
+ },
742
+ {
743
+ name: "country",
744
+ flag: "country",
745
+ required: false,
746
+ source: "query"
747
+ },
748
+ {
749
+ name: "language",
750
+ flag: "language",
751
+ required: false,
752
+ source: "query"
753
+ },
754
+ {
755
+ name: "limit",
756
+ flag: "limit",
757
+ required: false,
758
+ source: "query"
759
+ },
760
+ {
761
+ name: "offset",
762
+ flag: "offset",
763
+ required: false,
764
+ source: "query"
765
+ }
766
+ ],
767
+ acceptsJsonBody: false,
768
+ bodyRequired: false
769
+ },
770
+ {
771
+ trail: ["merchants", "search"],
772
+ resourcePath: ["merchants"],
773
+ methodName: "search",
774
+ httpMethod: "GET",
775
+ path: "/api/v1/merchants/{merchantId}/search",
776
+ summary: "Search Within Public Merchant Catalog",
777
+ flags: [
778
+ {
779
+ name: "merchantId",
780
+ flag: "merchant-id",
781
+ required: true,
782
+ source: "path"
783
+ },
784
+ {
785
+ name: "q",
786
+ flag: "q",
787
+ required: false,
788
+ source: "query"
789
+ },
790
+ {
791
+ name: "category",
792
+ flag: "category",
793
+ required: false,
794
+ source: "query"
795
+ },
796
+ {
797
+ name: "brand",
798
+ flag: "brand",
799
+ required: false,
800
+ source: "query"
801
+ },
802
+ {
803
+ name: "min_price",
804
+ flag: "min-price",
805
+ required: false,
806
+ source: "query"
807
+ },
808
+ {
809
+ name: "max_price",
810
+ flag: "max-price",
811
+ required: false,
812
+ source: "query"
813
+ },
814
+ {
815
+ name: "in_stock",
816
+ flag: "in-stock",
817
+ required: false,
818
+ source: "query"
819
+ },
820
+ {
821
+ name: "sort",
822
+ flag: "sort",
823
+ required: false,
824
+ source: "query"
825
+ },
826
+ {
827
+ name: "platform",
828
+ flag: "platform",
829
+ required: false,
830
+ source: "query"
831
+ },
832
+ {
833
+ name: "country",
834
+ flag: "country",
835
+ required: false,
836
+ source: "query"
837
+ },
838
+ {
839
+ name: "language",
840
+ flag: "language",
841
+ required: false,
842
+ source: "query"
843
+ },
844
+ {
845
+ name: "include_intent",
846
+ flag: "include-intent",
847
+ required: false,
848
+ source: "query"
849
+ },
850
+ {
851
+ name: "limit",
852
+ flag: "limit",
853
+ required: false,
854
+ source: "query"
855
+ },
856
+ {
857
+ name: "offset",
858
+ flag: "offset",
859
+ required: false,
860
+ source: "query"
861
+ }
862
+ ],
863
+ acceptsJsonBody: false,
864
+ bodyRequired: false
865
+ },
866
+ {
867
+ trail: ["monitor", "run"],
868
+ resourcePath: ["monitor"],
869
+ methodName: "run",
870
+ httpMethod: "POST",
871
+ path: "/api/v1/monitor",
872
+ summary: "Run AI Shelf Share Monitor",
873
+ flags: [],
874
+ acceptsJsonBody: true,
875
+ bodyRequired: false
876
+ },
877
+ {
878
+ trail: ["oauth", "revoke"],
879
+ resourcePath: ["oauth"],
880
+ methodName: "revoke",
881
+ httpMethod: "POST",
882
+ path: "/api/v1/oauth/revoke",
883
+ summary: "Revoke Access Token",
884
+ flags: [],
885
+ acceptsJsonBody: true,
886
+ bodyRequired: true
887
+ },
888
+ {
889
+ trail: ["oauth", "token"],
890
+ resourcePath: ["oauth"],
891
+ methodName: "token",
892
+ httpMethod: "POST",
893
+ path: "/api/v1/oauth/token",
894
+ summary: "Get Access Token",
895
+ flags: [],
896
+ acceptsJsonBody: true,
897
+ bodyRequired: true
898
+ },
899
+ {
900
+ trail: ["orders", "list"],
901
+ resourcePath: ["orders"],
902
+ methodName: "list",
903
+ httpMethod: "GET",
904
+ path: "/api/v1/orders",
905
+ summary: "List Orders",
906
+ flags: [
907
+ {
908
+ name: "organizationId",
909
+ flag: "organization-id",
910
+ required: false,
911
+ source: "query"
912
+ },
913
+ {
914
+ name: "q",
915
+ flag: "q",
916
+ required: false,
917
+ source: "query"
918
+ },
919
+ {
920
+ name: "status",
921
+ flag: "status",
922
+ required: false,
923
+ source: "query"
924
+ },
925
+ {
926
+ name: "marketplace",
927
+ flag: "marketplace",
928
+ required: false,
929
+ source: "query"
930
+ },
931
+ {
932
+ name: "country",
933
+ flag: "country",
934
+ required: false,
935
+ source: "query"
936
+ },
937
+ {
938
+ name: "store",
939
+ flag: "store",
940
+ required: false,
941
+ source: "query"
942
+ },
943
+ {
944
+ name: "bundleType",
945
+ flag: "bundle-type",
946
+ required: false,
947
+ source: "query"
948
+ },
949
+ {
950
+ name: "sortBy",
951
+ flag: "sort-by",
952
+ required: false,
953
+ source: "query"
954
+ },
955
+ {
956
+ name: "dateFrom",
957
+ flag: "date-from",
958
+ required: false,
959
+ source: "query"
960
+ },
961
+ {
962
+ name: "dateTo",
963
+ flag: "date-to",
964
+ required: false,
965
+ source: "query"
966
+ },
967
+ {
968
+ name: "limit",
969
+ flag: "limit",
970
+ required: false,
971
+ source: "query"
972
+ },
973
+ {
974
+ name: "offset",
975
+ flag: "offset",
976
+ required: false,
977
+ source: "query"
978
+ }
979
+ ],
980
+ acceptsJsonBody: false,
981
+ bodyRequired: false
982
+ },
983
+ {
984
+ trail: ["orders", "create"],
985
+ resourcePath: ["orders"],
986
+ methodName: "create",
987
+ httpMethod: "POST",
988
+ path: "/api/v1/orders",
989
+ summary: "Create Order",
990
+ flags: [],
991
+ acceptsJsonBody: true,
992
+ bodyRequired: true
993
+ },
994
+ {
995
+ trail: ["orders", "get"],
996
+ resourcePath: ["orders"],
997
+ methodName: "get",
998
+ httpMethod: "GET",
999
+ path: "/api/v1/orders/{orderId}",
1000
+ summary: "Get Order",
1001
+ flags: [
1002
+ {
1003
+ name: "orderId",
1004
+ flag: "order-id",
1005
+ required: true,
1006
+ source: "path"
1007
+ },
1008
+ {
1009
+ name: "organizationId",
1010
+ flag: "organization-id",
1011
+ required: false,
1012
+ source: "query"
1013
+ }
1014
+ ],
1015
+ acceptsJsonBody: false,
1016
+ bodyRequired: false
1017
+ },
1018
+ {
1019
+ trail: ["orders", "update"],
1020
+ resourcePath: ["orders"],
1021
+ methodName: "update",
1022
+ httpMethod: "PATCH",
1023
+ path: "/api/v1/orders/{orderId}",
1024
+ summary: "Update Order",
1025
+ flags: [
1026
+ {
1027
+ name: "orderId",
1028
+ flag: "order-id",
1029
+ required: true,
1030
+ source: "path"
1031
+ }
1032
+ ],
1033
+ acceptsJsonBody: true,
1034
+ bodyRequired: true
1035
+ },
1036
+ {
1037
+ trail: ["organizations", "create"],
1038
+ resourcePath: ["organizations"],
1039
+ methodName: "create",
1040
+ httpMethod: "POST",
1041
+ path: "/api/v1/organizations",
1042
+ summary: "Create Organization",
1043
+ flags: [],
1044
+ acceptsJsonBody: true,
1045
+ bodyRequired: true
1046
+ },
1047
+ {
1048
+ trail: ["price-books", "list"],
1049
+ resourcePath: ["priceBooks"],
1050
+ methodName: "list",
1051
+ httpMethod: "GET",
1052
+ path: "/api/v1/price-books",
1053
+ summary: "List Price Book Rules",
1054
+ flags: [
1055
+ {
1056
+ name: "organizationId",
1057
+ flag: "organization-id",
1058
+ required: false,
1059
+ source: "query"
1060
+ },
1061
+ {
1062
+ name: "platform",
1063
+ flag: "platform",
1064
+ required: false,
1065
+ source: "query"
1066
+ },
1067
+ {
1068
+ name: "enabledOnly",
1069
+ flag: "enabled-only",
1070
+ required: false,
1071
+ source: "query"
1072
+ }
1073
+ ],
1074
+ acceptsJsonBody: false,
1075
+ bodyRequired: false
1076
+ },
1077
+ {
1078
+ trail: ["price-books", "create"],
1079
+ resourcePath: ["priceBooks"],
1080
+ methodName: "create",
1081
+ httpMethod: "POST",
1082
+ path: "/api/v1/price-books",
1083
+ summary: "Create Price Book Rule",
1084
+ flags: [],
1085
+ acceptsJsonBody: true,
1086
+ bodyRequired: true
1087
+ },
1088
+ {
1089
+ trail: ["price-books", "delete"],
1090
+ resourcePath: ["priceBooks"],
1091
+ methodName: "delete",
1092
+ httpMethod: "DELETE",
1093
+ path: "/api/v1/price-books/{ruleId}",
1094
+ summary: "Delete Price Book Rule",
1095
+ flags: [
1096
+ {
1097
+ name: "ruleId",
1098
+ flag: "rule-id",
1099
+ required: true,
1100
+ source: "path"
1101
+ },
1102
+ {
1103
+ name: "organizationId",
1104
+ flag: "organization-id",
1105
+ required: false,
1106
+ source: "query"
1107
+ }
1108
+ ],
1109
+ acceptsJsonBody: false,
1110
+ bodyRequired: false
1111
+ },
1112
+ {
1113
+ trail: ["price-books", "get"],
1114
+ resourcePath: ["priceBooks"],
1115
+ methodName: "get",
1116
+ httpMethod: "GET",
1117
+ path: "/api/v1/price-books/{ruleId}",
1118
+ summary: "Get Price Book Rule",
1119
+ flags: [
1120
+ {
1121
+ name: "ruleId",
1122
+ flag: "rule-id",
1123
+ required: true,
1124
+ source: "path"
1125
+ },
1126
+ {
1127
+ name: "organizationId",
1128
+ flag: "organization-id",
1129
+ required: false,
1130
+ source: "query"
1131
+ }
1132
+ ],
1133
+ acceptsJsonBody: false,
1134
+ bodyRequired: false
1135
+ },
1136
+ {
1137
+ trail: ["price-books", "update"],
1138
+ resourcePath: ["priceBooks"],
1139
+ methodName: "update",
1140
+ httpMethod: "PATCH",
1141
+ path: "/api/v1/price-books/{ruleId}",
1142
+ summary: "Update Price Book Rule",
1143
+ flags: [
1144
+ {
1145
+ name: "ruleId",
1146
+ flag: "rule-id",
1147
+ required: true,
1148
+ source: "path"
1149
+ },
1150
+ {
1151
+ name: "organizationId",
1152
+ flag: "organization-id",
1153
+ required: false,
1154
+ source: "query"
1155
+ }
1156
+ ],
1157
+ acceptsJsonBody: true,
1158
+ bodyRequired: true
1159
+ },
1160
+ {
1161
+ trail: ["price-books", "preview"],
1162
+ resourcePath: ["priceBooks"],
1163
+ methodName: "preview",
1164
+ httpMethod: "POST",
1165
+ path: "/api/v1/price-books/preview",
1166
+ summary: "Preview Channel List Price",
1167
+ flags: [],
1168
+ acceptsJsonBody: true,
1169
+ bodyRequired: true
1170
+ },
1171
+ {
1172
+ trail: ["products", "list"],
1173
+ resourcePath: ["products"],
1174
+ methodName: "list",
1175
+ httpMethod: "GET",
1176
+ path: "/api/v1/products",
1177
+ summary: "List Products",
1178
+ flags: [
1179
+ {
1180
+ name: "status",
1181
+ flag: "status",
1182
+ required: false,
1183
+ source: "query"
1184
+ },
1185
+ {
1186
+ name: "marketplace",
1187
+ flag: "marketplace",
1188
+ required: false,
1189
+ source: "query"
1190
+ },
1191
+ {
1192
+ name: "country",
1193
+ flag: "country",
1194
+ required: false,
1195
+ source: "query"
1196
+ },
1197
+ {
1198
+ name: "q",
1199
+ flag: "q",
1200
+ required: false,
1201
+ source: "query"
1202
+ },
1203
+ {
1204
+ name: "sku",
1205
+ flag: "sku",
1206
+ required: false,
1207
+ source: "query"
1208
+ },
1209
+ {
1210
+ name: "minPrice",
1211
+ flag: "min-price",
1212
+ required: false,
1213
+ source: "query"
1214
+ },
1215
+ {
1216
+ name: "maxPrice",
1217
+ flag: "max-price",
1218
+ required: false,
1219
+ source: "query"
1220
+ },
1221
+ {
1222
+ name: "sortBy",
1223
+ flag: "sort-by",
1224
+ required: false,
1225
+ source: "query"
1226
+ },
1227
+ {
1228
+ name: "limit",
1229
+ flag: "limit",
1230
+ required: false,
1231
+ source: "query"
1232
+ },
1233
+ {
1234
+ name: "offset",
1235
+ flag: "offset",
1236
+ required: false,
1237
+ source: "query"
1238
+ }
1239
+ ],
1240
+ acceptsJsonBody: false,
1241
+ bodyRequired: false
1242
+ },
1243
+ {
1244
+ trail: ["products", "create"],
1245
+ resourcePath: ["products"],
1246
+ methodName: "create",
1247
+ httpMethod: "POST",
1248
+ path: "/api/v1/products",
1249
+ summary: "Create Product",
1250
+ flags: [],
1251
+ acceptsJsonBody: true,
1252
+ bodyRequired: true
1253
+ },
1254
+ {
1255
+ trail: ["products", "delete"],
1256
+ resourcePath: ["products"],
1257
+ methodName: "delete",
1258
+ httpMethod: "DELETE",
1259
+ path: "/api/v1/products/{productId}",
1260
+ summary: "Delete Product",
1261
+ flags: [
1262
+ {
1263
+ name: "productId",
1264
+ flag: "product-id",
1265
+ required: true,
1266
+ source: "path"
1267
+ }
1268
+ ],
1269
+ acceptsJsonBody: false,
1270
+ bodyRequired: false
1271
+ },
1272
+ {
1273
+ trail: ["products", "get"],
1274
+ resourcePath: ["products"],
1275
+ methodName: "get",
1276
+ httpMethod: "GET",
1277
+ path: "/api/v1/products/{productId}",
1278
+ summary: "Get Product",
1279
+ flags: [
1280
+ {
1281
+ name: "productId",
1282
+ flag: "product-id",
1283
+ required: true,
1284
+ source: "path"
1285
+ }
1286
+ ],
1287
+ acceptsJsonBody: false,
1288
+ bodyRequired: false
1289
+ },
1290
+ {
1291
+ trail: ["products", "update"],
1292
+ resourcePath: ["products"],
1293
+ methodName: "update",
1294
+ httpMethod: "PATCH",
1295
+ path: "/api/v1/products/{productId}",
1296
+ summary: "Update Product",
1297
+ flags: [
1298
+ {
1299
+ name: "productId",
1300
+ flag: "product-id",
1301
+ required: true,
1302
+ source: "path"
1303
+ }
1304
+ ],
1305
+ acceptsJsonBody: true,
1306
+ bodyRequired: true
1307
+ },
1308
+ {
1309
+ trail: ["products", "update-cost"],
1310
+ resourcePath: ["products"],
1311
+ methodName: "updateCost",
1312
+ httpMethod: "PATCH",
1313
+ path: "/api/v1/products/{productId}/cost",
1314
+ summary: "Update Product Cost",
1315
+ flags: [
1316
+ {
1317
+ name: "productId",
1318
+ flag: "product-id",
1319
+ required: true,
1320
+ source: "path"
1321
+ }
1322
+ ],
1323
+ acceptsJsonBody: true,
1324
+ bodyRequired: true
1325
+ },
1326
+ {
1327
+ trail: ["products", "delist"],
1328
+ resourcePath: ["products"],
1329
+ methodName: "delist",
1330
+ httpMethod: "POST",
1331
+ path: "/api/v1/products/{productId}/delist",
1332
+ summary: "Delist Product",
1333
+ flags: [
1334
+ {
1335
+ name: "productId",
1336
+ flag: "product-id",
1337
+ required: true,
1338
+ source: "path"
1339
+ }
1340
+ ],
1341
+ acceptsJsonBody: true,
1342
+ bodyRequired: false
1343
+ },
1344
+ {
1345
+ trail: ["products", "update-inventory"],
1346
+ resourcePath: ["products"],
1347
+ methodName: "updateInventory",
1348
+ httpMethod: "PATCH",
1349
+ path: "/api/v1/products/{productId}/inventory",
1350
+ summary: "Update Product Inventory",
1351
+ flags: [
1352
+ {
1353
+ name: "productId",
1354
+ flag: "product-id",
1355
+ required: true,
1356
+ source: "path"
1357
+ }
1358
+ ],
1359
+ acceptsJsonBody: true,
1360
+ bodyRequired: true
1361
+ },
1362
+ {
1363
+ trail: ["products", "update-price"],
1364
+ resourcePath: ["products"],
1365
+ methodName: "updatePrice",
1366
+ httpMethod: "PATCH",
1367
+ path: "/api/v1/products/{productId}/price",
1368
+ summary: "Update Product Price",
1369
+ flags: [
1370
+ {
1371
+ name: "productId",
1372
+ flag: "product-id",
1373
+ required: true,
1374
+ source: "path"
1375
+ }
1376
+ ],
1377
+ acceptsJsonBody: true,
1378
+ bodyRequired: true
1379
+ },
1380
+ {
1381
+ trail: ["products", "publish"],
1382
+ resourcePath: ["products"],
1383
+ methodName: "publish",
1384
+ httpMethod: "POST",
1385
+ path: "/api/v1/products/{productId}/publish",
1386
+ summary: "Publish Product",
1387
+ flags: [
1388
+ {
1389
+ name: "productId",
1390
+ flag: "product-id",
1391
+ required: true,
1392
+ source: "path"
1393
+ }
1394
+ ],
1395
+ acceptsJsonBody: true,
1396
+ bodyRequired: false
1397
+ },
1398
+ {
1399
+ trail: ["products", "bulk-import"],
1400
+ resourcePath: ["products"],
1401
+ methodName: "bulkImport",
1402
+ httpMethod: "POST",
1403
+ path: "/api/v1/products/bulk-import",
1404
+ summary: "Bulk Import Products from JSON or CSV",
1405
+ flags: [],
1406
+ acceptsJsonBody: true,
1407
+ bodyRequired: true
1408
+ },
1409
+ {
1410
+ trail: ["products", "update-costs"],
1411
+ resourcePath: ["products"],
1412
+ methodName: "updateCosts",
1413
+ httpMethod: "POST",
1414
+ path: "/api/v1/products/cost",
1415
+ summary: "Batch Update Product Cost",
1416
+ flags: [],
1417
+ acceptsJsonBody: true,
1418
+ bodyRequired: true
1419
+ },
1420
+ {
1421
+ trail: ["products", "enrich"],
1422
+ resourcePath: ["products"],
1423
+ methodName: "enrich",
1424
+ httpMethod: "POST",
1425
+ path: "/api/v1/products/enrich",
1426
+ summary: "Queue Product Enrichment",
1427
+ flags: [],
1428
+ acceptsJsonBody: true,
1429
+ bodyRequired: true
1430
+ },
1431
+ {
1432
+ trail: ["promotions", "list"],
1433
+ resourcePath: ["promotions"],
1434
+ methodName: "list",
1435
+ httpMethod: "GET",
1436
+ path: "/api/v1/promotions",
1437
+ summary: "List Promotions",
1438
+ flags: [
1439
+ {
1440
+ name: "organizationId",
1441
+ flag: "organization-id",
1442
+ required: false,
1443
+ source: "query"
1444
+ },
1445
+ {
1446
+ name: "q",
1447
+ flag: "q",
1448
+ required: false,
1449
+ source: "query"
1450
+ },
1451
+ {
1452
+ name: "status",
1453
+ flag: "status",
1454
+ required: false,
1455
+ source: "query"
1456
+ },
1457
+ {
1458
+ name: "marketplace",
1459
+ flag: "marketplace",
1460
+ required: false,
1461
+ source: "query"
1462
+ },
1463
+ {
1464
+ name: "store",
1465
+ flag: "store",
1466
+ required: false,
1467
+ source: "query"
1468
+ },
1469
+ {
1470
+ name: "sortBy",
1471
+ flag: "sort-by",
1472
+ required: false,
1473
+ source: "query"
1474
+ },
1475
+ {
1476
+ name: "sortDir",
1477
+ flag: "sort-dir",
1478
+ required: false,
1479
+ source: "query"
1480
+ },
1481
+ {
1482
+ name: "limit",
1483
+ flag: "limit",
1484
+ required: false,
1485
+ source: "query"
1486
+ },
1487
+ {
1488
+ name: "offset",
1489
+ flag: "offset",
1490
+ required: false,
1491
+ source: "query"
1492
+ }
1493
+ ],
1494
+ acceptsJsonBody: false,
1495
+ bodyRequired: false
1496
+ },
1497
+ {
1498
+ trail: ["promotions", "create"],
1499
+ resourcePath: ["promotions"],
1500
+ methodName: "create",
1501
+ httpMethod: "POST",
1502
+ path: "/api/v1/promotions",
1503
+ summary: "Create Promotion",
1504
+ flags: [],
1505
+ acceptsJsonBody: true,
1506
+ bodyRequired: true
1507
+ },
1508
+ {
1509
+ trail: ["promotions", "delete"],
1510
+ resourcePath: ["promotions"],
1511
+ methodName: "delete",
1512
+ httpMethod: "DELETE",
1513
+ path: "/api/v1/promotions/{promotionId}",
1514
+ summary: "Delete Promotion",
1515
+ flags: [
1516
+ {
1517
+ name: "promotionId",
1518
+ flag: "promotion-id",
1519
+ required: true,
1520
+ source: "path"
1521
+ },
1522
+ {
1523
+ name: "organizationId",
1524
+ flag: "organization-id",
1525
+ required: false,
1526
+ source: "query"
1527
+ }
1528
+ ],
1529
+ acceptsJsonBody: false,
1530
+ bodyRequired: false
1531
+ },
1532
+ {
1533
+ trail: ["promotions", "get"],
1534
+ resourcePath: ["promotions"],
1535
+ methodName: "get",
1536
+ httpMethod: "GET",
1537
+ path: "/api/v1/promotions/{promotionId}",
1538
+ summary: "Get Promotion",
1539
+ flags: [
1540
+ {
1541
+ name: "promotionId",
1542
+ flag: "promotion-id",
1543
+ required: true,
1544
+ source: "path"
1545
+ },
1546
+ {
1547
+ name: "organizationId",
1548
+ flag: "organization-id",
1549
+ required: false,
1550
+ source: "query"
1551
+ }
1552
+ ],
1553
+ acceptsJsonBody: false,
1554
+ bodyRequired: false
1555
+ },
1556
+ {
1557
+ trail: ["promotions", "update"],
1558
+ resourcePath: ["promotions"],
1559
+ methodName: "update",
1560
+ httpMethod: "PATCH",
1561
+ path: "/api/v1/promotions/{promotionId}",
1562
+ summary: "Update Promotion",
1563
+ flags: [
1564
+ {
1565
+ name: "promotionId",
1566
+ flag: "promotion-id",
1567
+ required: true,
1568
+ source: "path"
1569
+ },
1570
+ {
1571
+ name: "organizationId",
1572
+ flag: "organization-id",
1573
+ required: false,
1574
+ source: "query"
1575
+ }
1576
+ ],
1577
+ acceptsJsonBody: true,
1578
+ bodyRequired: true
1579
+ },
1580
+ {
1581
+ trail: ["promotions", "remove-products"],
1582
+ resourcePath: ["promotions"],
1583
+ methodName: "removeProducts",
1584
+ httpMethod: "DELETE",
1585
+ path: "/api/v1/promotions/{promotionId}/products",
1586
+ summary: "Unassign Products from Promotion",
1587
+ flags: [
1588
+ {
1589
+ name: "promotionId",
1590
+ flag: "promotion-id",
1591
+ required: true,
1592
+ source: "path"
1593
+ },
1594
+ {
1595
+ name: "organizationId",
1596
+ flag: "organization-id",
1597
+ required: false,
1598
+ source: "query"
1599
+ }
1600
+ ],
1601
+ acceptsJsonBody: true,
1602
+ bodyRequired: true
1603
+ },
1604
+ {
1605
+ trail: ["promotions", "list-products"],
1606
+ resourcePath: ["promotions"],
1607
+ methodName: "listProducts",
1608
+ httpMethod: "GET",
1609
+ path: "/api/v1/promotions/{promotionId}/products",
1610
+ summary: "List Promotion Assignments",
1611
+ flags: [
1612
+ {
1613
+ name: "promotionId",
1614
+ flag: "promotion-id",
1615
+ required: true,
1616
+ source: "path"
1617
+ },
1618
+ {
1619
+ name: "organizationId",
1620
+ flag: "organization-id",
1621
+ required: false,
1622
+ source: "query"
1623
+ }
1624
+ ],
1625
+ acceptsJsonBody: false,
1626
+ bodyRequired: false
1627
+ },
1628
+ {
1629
+ trail: ["promotions", "add-products"],
1630
+ resourcePath: ["promotions"],
1631
+ methodName: "addProducts",
1632
+ httpMethod: "POST",
1633
+ path: "/api/v1/promotions/{promotionId}/products",
1634
+ summary: "Assign Products to Promotion",
1635
+ flags: [
1636
+ {
1637
+ name: "promotionId",
1638
+ flag: "promotion-id",
1639
+ required: true,
1640
+ source: "path"
1641
+ },
1642
+ {
1643
+ name: "organizationId",
1644
+ flag: "organization-id",
1645
+ required: false,
1646
+ source: "query"
1647
+ }
1648
+ ],
1649
+ acceptsJsonBody: true,
1650
+ bodyRequired: true
1651
+ },
1652
+ {
1653
+ trail: ["promotions", "sync"],
1654
+ resourcePath: ["promotions"],
1655
+ methodName: "sync",
1656
+ httpMethod: "POST",
1657
+ path: "/api/v1/promotions/{promotionId}/sync",
1658
+ summary: "Sync Promotion to Marketplaces",
1659
+ flags: [
1660
+ {
1661
+ name: "promotionId",
1662
+ flag: "promotion-id",
1663
+ required: true,
1664
+ source: "path"
1665
+ },
1666
+ {
1667
+ name: "organizationId",
1668
+ flag: "organization-id",
1669
+ required: false,
1670
+ source: "query"
1671
+ }
1672
+ ],
1673
+ acceptsJsonBody: true,
1674
+ bodyRequired: true
1675
+ },
1676
+ {
1677
+ trail: ["returns", "list"],
1678
+ resourcePath: ["returns"],
1679
+ methodName: "list",
1680
+ httpMethod: "GET",
1681
+ path: "/api/v1/returns",
1682
+ summary: "List Returns",
1683
+ flags: [
1684
+ {
1685
+ name: "organizationId",
1686
+ flag: "organization-id",
1687
+ required: false,
1688
+ source: "query"
1689
+ },
1690
+ {
1691
+ name: "marketplace",
1692
+ flag: "marketplace",
1693
+ required: false,
1694
+ source: "query"
1695
+ },
1696
+ {
1697
+ name: "accountId",
1698
+ flag: "account-id",
1699
+ required: false,
1700
+ source: "query"
1701
+ },
1702
+ {
1703
+ name: "externalOrderId",
1704
+ flag: "external-order-id",
1705
+ required: false,
1706
+ source: "query"
1707
+ },
1708
+ {
1709
+ name: "updatedSince",
1710
+ flag: "updated-since",
1711
+ required: false,
1712
+ source: "query"
1713
+ },
1714
+ {
1715
+ name: "cursor",
1716
+ flag: "cursor",
1717
+ required: false,
1718
+ source: "query"
1719
+ },
1720
+ {
1721
+ name: "limit",
1722
+ flag: "limit",
1723
+ required: false,
1724
+ source: "query"
1725
+ }
1726
+ ],
1727
+ acceptsJsonBody: false,
1728
+ bodyRequired: false
1729
+ },
1730
+ {
1731
+ trail: ["returns", "get"],
1732
+ resourcePath: ["returns"],
1733
+ methodName: "get",
1734
+ httpMethod: "GET",
1735
+ path: "/api/v1/returns/{returnId}",
1736
+ summary: "Get Return",
1737
+ flags: [
1738
+ {
1739
+ name: "returnId",
1740
+ flag: "return-id",
1741
+ required: true,
1742
+ source: "path"
1743
+ },
1744
+ {
1745
+ name: "organizationId",
1746
+ flag: "organization-id",
1747
+ required: false,
1748
+ source: "query"
1749
+ }
1750
+ ],
1751
+ acceptsJsonBody: false,
1752
+ bodyRequired: false
1753
+ },
1754
+ {
1755
+ trail: ["search", "list"],
1756
+ resourcePath: ["search"],
1757
+ methodName: "list",
1758
+ httpMethod: "GET",
1759
+ path: "/api/v1/search",
1760
+ summary: "Search Public Merchant Products",
1761
+ flags: [
1762
+ {
1763
+ name: "q",
1764
+ flag: "q",
1765
+ required: false,
1766
+ source: "query"
1767
+ },
1768
+ {
1769
+ name: "category",
1770
+ flag: "category",
1771
+ required: false,
1772
+ source: "query"
1773
+ },
1774
+ {
1775
+ name: "brand",
1776
+ flag: "brand",
1777
+ required: false,
1778
+ source: "query"
1779
+ },
1780
+ {
1781
+ name: "min_price",
1782
+ flag: "min-price",
1783
+ required: false,
1784
+ source: "query"
1785
+ },
1786
+ {
1787
+ name: "max_price",
1788
+ flag: "max-price",
1789
+ required: false,
1790
+ source: "query"
1791
+ },
1792
+ {
1793
+ name: "in_stock",
1794
+ flag: "in-stock",
1795
+ required: false,
1796
+ source: "query"
1797
+ },
1798
+ {
1799
+ name: "merchant_ids",
1800
+ flag: "merchant-ids",
1801
+ required: false,
1802
+ source: "query"
1803
+ },
1804
+ {
1805
+ name: "sort",
1806
+ flag: "sort",
1807
+ required: false,
1808
+ source: "query"
1809
+ },
1810
+ {
1811
+ name: "platform",
1812
+ flag: "platform",
1813
+ required: false,
1814
+ source: "query"
1815
+ },
1816
+ {
1817
+ name: "country",
1818
+ flag: "country",
1819
+ required: false,
1820
+ source: "query"
1821
+ },
1822
+ {
1823
+ name: "language",
1824
+ flag: "language",
1825
+ required: false,
1826
+ source: "query"
1827
+ },
1828
+ {
1829
+ name: "include_intent",
1830
+ flag: "include-intent",
1831
+ required: false,
1832
+ source: "query"
1833
+ },
1834
+ {
1835
+ name: "limit",
1836
+ flag: "limit",
1837
+ required: false,
1838
+ source: "query"
1839
+ },
1840
+ {
1841
+ name: "offset",
1842
+ flag: "offset",
1843
+ required: false,
1844
+ source: "query"
1845
+ }
1846
+ ],
1847
+ acceptsJsonBody: false,
1848
+ bodyRequired: false
1849
+ },
1850
+ {
1851
+ trail: ["search", "query"],
1852
+ resourcePath: ["search"],
1853
+ methodName: "query",
1854
+ httpMethod: "POST",
1855
+ path: "/api/v1/search",
1856
+ summary: "Search Public Merchant Products",
1857
+ flags: [
1858
+ {
1859
+ name: "q",
1860
+ flag: "q",
1861
+ required: false,
1862
+ source: "query"
1863
+ },
1864
+ {
1865
+ name: "category",
1866
+ flag: "category",
1867
+ required: false,
1868
+ source: "query"
1869
+ },
1870
+ {
1871
+ name: "brand",
1872
+ flag: "brand",
1873
+ required: false,
1874
+ source: "query"
1875
+ },
1876
+ {
1877
+ name: "min_price",
1878
+ flag: "min-price",
1879
+ required: false,
1880
+ source: "query"
1881
+ },
1882
+ {
1883
+ name: "max_price",
1884
+ flag: "max-price",
1885
+ required: false,
1886
+ source: "query"
1887
+ },
1888
+ {
1889
+ name: "in_stock",
1890
+ flag: "in-stock",
1891
+ required: false,
1892
+ source: "query"
1893
+ },
1894
+ {
1895
+ name: "merchant_ids",
1896
+ flag: "merchant-ids",
1897
+ required: false,
1898
+ source: "query"
1899
+ },
1900
+ {
1901
+ name: "sort",
1902
+ flag: "sort",
1903
+ required: false,
1904
+ source: "query"
1905
+ },
1906
+ {
1907
+ name: "platform",
1908
+ flag: "platform",
1909
+ required: false,
1910
+ source: "query"
1911
+ },
1912
+ {
1913
+ name: "country",
1914
+ flag: "country",
1915
+ required: false,
1916
+ source: "query"
1917
+ },
1918
+ {
1919
+ name: "language",
1920
+ flag: "language",
1921
+ required: false,
1922
+ source: "query"
1923
+ },
1924
+ {
1925
+ name: "include_intent",
1926
+ flag: "include-intent",
1927
+ required: false,
1928
+ source: "query"
1929
+ },
1930
+ {
1931
+ name: "limit",
1932
+ flag: "limit",
1933
+ required: false,
1934
+ source: "query"
1935
+ },
1936
+ {
1937
+ name: "offset",
1938
+ flag: "offset",
1939
+ required: false,
1940
+ source: "query"
1941
+ }
1942
+ ],
1943
+ acceptsJsonBody: true,
1944
+ bodyRequired: false
1945
+ },
1946
+ {
1947
+ trail: ["settlements", "list"],
1948
+ resourcePath: ["settlements"],
1949
+ methodName: "list",
1950
+ httpMethod: "GET",
1951
+ path: "/api/v1/settlements",
1952
+ summary: "List Settlements",
1953
+ flags: [
1954
+ {
1955
+ name: "organizationId",
1956
+ flag: "organization-id",
1957
+ required: false,
1958
+ source: "query"
1959
+ },
1960
+ {
1961
+ name: "marketplace",
1962
+ flag: "marketplace",
1963
+ required: false,
1964
+ source: "query"
1965
+ },
1966
+ {
1967
+ name: "accountId",
1968
+ flag: "account-id",
1969
+ required: false,
1970
+ source: "query"
1971
+ },
1972
+ {
1973
+ name: "orderId",
1974
+ flag: "order-id",
1975
+ required: false,
1976
+ source: "query"
1977
+ },
1978
+ {
1979
+ name: "externalOrderId",
1980
+ flag: "external-order-id",
1981
+ required: false,
1982
+ source: "query"
1983
+ },
1984
+ {
1985
+ name: "updatedSince",
1986
+ flag: "updated-since",
1987
+ required: false,
1988
+ source: "query"
1989
+ },
1990
+ {
1991
+ name: "cursor",
1992
+ flag: "cursor",
1993
+ required: false,
1994
+ source: "query"
1995
+ },
1996
+ {
1997
+ name: "limit",
1998
+ flag: "limit",
1999
+ required: false,
2000
+ source: "query"
2001
+ }
2002
+ ],
2003
+ acceptsJsonBody: false,
2004
+ bodyRequired: false
2005
+ },
2006
+ {
2007
+ trail: ["settlements", "create"],
2008
+ resourcePath: ["settlements"],
2009
+ methodName: "create",
2010
+ httpMethod: "POST",
2011
+ path: "/api/v1/settlements",
2012
+ summary: "Apply Settlements",
2013
+ flags: [],
2014
+ acceptsJsonBody: true,
2015
+ bodyRequired: true
2016
+ },
2017
+ {
2018
+ trail: ["settlements", "get"],
2019
+ resourcePath: ["settlements"],
2020
+ methodName: "get",
2021
+ httpMethod: "GET",
2022
+ path: "/api/v1/settlements/{settlementId}",
2023
+ summary: "Get Settlement",
2024
+ flags: [
2025
+ {
2026
+ name: "settlementId",
2027
+ flag: "settlement-id",
2028
+ required: true,
2029
+ source: "path"
2030
+ },
2031
+ {
2032
+ name: "organizationId",
2033
+ flag: "organization-id",
2034
+ required: false,
2035
+ source: "query"
2036
+ }
2037
+ ],
2038
+ acceptsJsonBody: false,
2039
+ bodyRequired: false
2040
+ },
2041
+ {
2042
+ trail: ["sync", "run"],
2043
+ resourcePath: ["sync"],
2044
+ methodName: "run",
2045
+ httpMethod: "POST",
2046
+ path: "/api/v1/sync",
2047
+ summary: "Sync Product Commercial Fields",
2048
+ flags: [],
2049
+ acceptsJsonBody: true,
2050
+ bodyRequired: false
2051
+ },
2052
+ {
2053
+ trail: ["threads", "get-status"],
2054
+ resourcePath: ["threads"],
2055
+ methodName: "getStatus",
2056
+ httpMethod: "GET",
2057
+ path: "/api/v1/threads/{thread_id}/status",
2058
+ summary: "Get Thread Status",
2059
+ flags: [
2060
+ {
2061
+ name: "thread_id",
2062
+ flag: "thread-id",
2063
+ required: true,
2064
+ source: "path"
2065
+ },
2066
+ {
2067
+ name: "include_messages",
2068
+ flag: "include-messages",
2069
+ required: false,
2070
+ source: "query"
2071
+ },
2072
+ {
2073
+ name: "organizationId",
2074
+ flag: "organization-id",
2075
+ required: false,
2076
+ source: "query"
2077
+ }
2078
+ ],
2079
+ acceptsJsonBody: false,
2080
+ bodyRequired: false
2081
+ },
2082
+ {
2083
+ trail: ["webhook-events", "list"],
2084
+ resourcePath: ["webhookEvents"],
2085
+ methodName: "list",
2086
+ httpMethod: "GET",
2087
+ path: "/api/v1/webhook-events",
2088
+ summary: "List Webhook Events",
2089
+ flags: [
2090
+ {
2091
+ name: "organizationId",
2092
+ flag: "organization-id",
2093
+ required: false,
2094
+ source: "query"
2095
+ },
2096
+ {
2097
+ name: "eventType",
2098
+ flag: "event-type",
2099
+ required: false,
2100
+ source: "query"
2101
+ },
2102
+ {
2103
+ name: "occurredSince",
2104
+ flag: "occurred-since",
2105
+ required: false,
2106
+ source: "query"
2107
+ },
2108
+ {
2109
+ name: "cursor",
2110
+ flag: "cursor",
2111
+ required: false,
2112
+ source: "query"
2113
+ },
2114
+ {
2115
+ name: "limit",
2116
+ flag: "limit",
2117
+ required: false,
2118
+ source: "query"
2119
+ }
2120
+ ],
2121
+ acceptsJsonBody: false,
2122
+ bodyRequired: false
2123
+ },
2124
+ {
2125
+ trail: ["webhooks", "list"],
2126
+ resourcePath: ["webhooks"],
2127
+ methodName: "list",
2128
+ httpMethod: "GET",
2129
+ path: "/api/v1/webhooks",
2130
+ summary: "List Developer Webhooks",
2131
+ flags: [],
2132
+ acceptsJsonBody: false,
2133
+ bodyRequired: false
2134
+ },
2135
+ {
2136
+ trail: ["webhooks", "create"],
2137
+ resourcePath: ["webhooks"],
2138
+ methodName: "create",
2139
+ httpMethod: "POST",
2140
+ path: "/api/v1/webhooks",
2141
+ summary: "Create Developer Webhook",
2142
+ flags: [],
2143
+ acceptsJsonBody: true,
2144
+ bodyRequired: true
2145
+ },
2146
+ {
2147
+ trail: ["zalora", "get-import"],
2148
+ resourcePath: ["zalora"],
2149
+ methodName: "getImport",
2150
+ httpMethod: "GET",
2151
+ path: "/api/v1/zalora/import",
2152
+ summary: "Get Selected Zalora Import Status",
2153
+ flags: [
2154
+ {
2155
+ name: "organizationId",
2156
+ flag: "organization-id",
2157
+ required: false,
2158
+ source: "query"
2159
+ },
2160
+ {
2161
+ name: "jobId",
2162
+ flag: "job-id",
2163
+ required: true,
2164
+ source: "query"
2165
+ },
2166
+ {
2167
+ name: "storeId",
2168
+ flag: "store-id",
2169
+ required: true,
2170
+ source: "query"
2171
+ },
2172
+ {
2173
+ name: "productSetIds",
2174
+ flag: "product-set-ids",
2175
+ required: true,
2176
+ source: "query"
2177
+ }
2178
+ ],
2179
+ acceptsJsonBody: false,
2180
+ bodyRequired: false
2181
+ },
2182
+ {
2183
+ trail: ["zalora", "import-products"],
2184
+ resourcePath: ["zalora"],
2185
+ methodName: "importProducts",
2186
+ httpMethod: "POST",
2187
+ path: "/api/v1/zalora/import",
2188
+ summary: "Import Selected Zalora Products",
2189
+ flags: [],
2190
+ acceptsJsonBody: true,
2191
+ bodyRequired: true
2192
+ },
2193
+ {
2194
+ trail: ["ucp", "checkout-sessions", "create"],
2195
+ resourcePath: ["ucp", "checkoutSessions"],
2196
+ methodName: "create",
2197
+ httpMethod: "POST",
2198
+ path: "/ucp/v1/checkout-sessions",
2199
+ summary: "Create UCP Checkout Session",
2200
+ flags: [],
2201
+ acceptsJsonBody: true,
2202
+ bodyRequired: true
2203
+ },
2204
+ {
2205
+ trail: ["ucp", "checkout-sessions", "get"],
2206
+ resourcePath: ["ucp", "checkoutSessions"],
2207
+ methodName: "get",
2208
+ httpMethod: "GET",
2209
+ path: "/ucp/v1/checkout-sessions/{sessionId}",
2210
+ summary: "Get UCP Checkout Session",
2211
+ flags: [
2212
+ {
2213
+ name: "sessionId",
2214
+ flag: "session-id",
2215
+ required: true,
2216
+ source: "path"
2217
+ },
2218
+ {
2219
+ name: "organizationId",
2220
+ flag: "organization-id",
2221
+ required: false,
2222
+ source: "query"
2223
+ }
2224
+ ],
2225
+ acceptsJsonBody: false,
2226
+ bodyRequired: false
2227
+ },
2228
+ {
2229
+ trail: ["ucp", "checkout-sessions", "update"],
2230
+ resourcePath: ["ucp", "checkoutSessions"],
2231
+ methodName: "update",
2232
+ httpMethod: "PATCH",
2233
+ path: "/ucp/v1/checkout-sessions/{sessionId}",
2234
+ summary: "Update UCP Checkout Session",
2235
+ flags: [
2236
+ {
2237
+ name: "sessionId",
2238
+ flag: "session-id",
2239
+ required: true,
2240
+ source: "path"
2241
+ },
2242
+ {
2243
+ name: "organizationId",
2244
+ flag: "organization-id",
2245
+ required: false,
2246
+ source: "query"
2247
+ }
2248
+ ],
2249
+ acceptsJsonBody: true,
2250
+ bodyRequired: true
2251
+ },
2252
+ {
2253
+ trail: ["ucp", "checkout-sessions", "replace"],
2254
+ resourcePath: ["ucp", "checkoutSessions"],
2255
+ methodName: "replace",
2256
+ httpMethod: "PUT",
2257
+ path: "/ucp/v1/checkout-sessions/{sessionId}",
2258
+ summary: "Replace UCP Checkout Session Fields",
2259
+ flags: [
2260
+ {
2261
+ name: "sessionId",
2262
+ flag: "session-id",
2263
+ required: true,
2264
+ source: "path"
2265
+ },
2266
+ {
2267
+ name: "organizationId",
2268
+ flag: "organization-id",
2269
+ required: false,
2270
+ source: "query"
2271
+ }
2272
+ ],
2273
+ acceptsJsonBody: true,
2274
+ bodyRequired: true
2275
+ },
2276
+ {
2277
+ trail: ["ucp", "checkout-sessions", "cancel"],
2278
+ resourcePath: ["ucp", "checkoutSessions"],
2279
+ methodName: "cancel",
2280
+ httpMethod: "POST",
2281
+ path: "/ucp/v1/checkout-sessions/{sessionId}/cancel",
2282
+ summary: "Cancel UCP Checkout Session",
2283
+ flags: [
2284
+ {
2285
+ name: "sessionId",
2286
+ flag: "session-id",
2287
+ required: true,
2288
+ source: "path"
2289
+ },
2290
+ {
2291
+ name: "organizationId",
2292
+ flag: "organization-id",
2293
+ required: false,
2294
+ source: "query"
2295
+ }
2296
+ ],
2297
+ acceptsJsonBody: true,
2298
+ bodyRequired: false
2299
+ },
2300
+ {
2301
+ trail: ["ucp", "checkout-sessions", "complete"],
2302
+ resourcePath: ["ucp", "checkoutSessions"],
2303
+ methodName: "complete",
2304
+ httpMethod: "POST",
2305
+ path: "/ucp/v1/checkout-sessions/{sessionId}/complete",
2306
+ summary: "Complete UCP Checkout Session",
2307
+ flags: [
2308
+ {
2309
+ name: "sessionId",
2310
+ flag: "session-id",
2311
+ required: true,
2312
+ source: "path"
2313
+ },
2314
+ {
2315
+ name: "organizationId",
2316
+ flag: "organization-id",
2317
+ required: false,
2318
+ source: "query"
2319
+ }
2320
+ ],
2321
+ acceptsJsonBody: true,
2322
+ bodyRequired: true
2323
+ },
2324
+ {
2325
+ trail: ["ucp", "orders", "get"],
2326
+ resourcePath: ["ucp", "orders"],
2327
+ methodName: "get",
2328
+ httpMethod: "GET",
2329
+ path: "/ucp/v1/orders/{orderId}",
2330
+ summary: "Get UCP Order",
2331
+ flags: [
2332
+ {
2333
+ name: "orderId",
2334
+ flag: "order-id",
2335
+ required: true,
2336
+ source: "path"
2337
+ },
2338
+ {
2339
+ name: "organizationId",
2340
+ flag: "organization-id",
2341
+ required: false,
2342
+ source: "query"
2343
+ }
2344
+ ],
2345
+ acceptsJsonBody: false,
2346
+ bodyRequired: false
2347
+ },
2348
+ {
2349
+ trail: ["jobs", "wait"],
2350
+ resourcePath: ["jobs"],
2351
+ methodName: "wait",
2352
+ httpMethod: "GET",
2353
+ path: "/api/v1/jobs/{jobId}",
2354
+ summary: "Poll a developer job until the nested status is terminal",
2355
+ flags: [
2356
+ {
2357
+ name: "jobId",
2358
+ flag: "job-id",
2359
+ required: true,
2360
+ source: "path"
2361
+ },
2362
+ {
2363
+ name: "organizationId",
2364
+ flag: "organization-id",
2365
+ required: false,
2366
+ source: "query"
2367
+ }
2368
+ ],
2369
+ acceptsJsonBody: false,
2370
+ bodyRequired: false
2371
+ }
2372
+ ];
2373
+
2374
+ // src/help.ts
2375
+ function printRootHelp(commands) {
2376
+ const groups = [
2377
+ ...new Set(commands.map((command) => command.trail[0]))
2378
+ ].sort();
2379
+ return `OmniCommerce CLI
2380
+
2381
+ Usage:
2382
+ omni <resource> <command> [flags]
2383
+ omni auth login --api-key omni_sk_...
2384
+ omni auth status
2385
+ omni auth logout
2386
+
2387
+ Resources:
2388
+ ${groups.map((group) => ` ${group}`).join("\n")}
2389
+
2390
+ Global flags:
2391
+ --api-key <key> API key (or OMNI_API_KEY / omni auth login)
2392
+ --base-url <url> API origin (default https://omnicommerce.sg)
2393
+ --json <object|-> JSON body, or - to read stdin
2394
+ --format json|table Output format (table on TTY, json when piped)
2395
+ --dry-run Print the request without sending it
2396
+ --schema Print flags for this command
2397
+ --timeout <seconds> Request timeout
2398
+ --help Show help
2399
+
2400
+ Examples:
2401
+ omni products list --q lamp
2402
+ omni products get --product-id prod_123
2403
+ omni products create --json '{"product":{"sku":"SKU-1","title":"Lamp"}}'
2404
+ omni jobs wait --job-id prod_123
2405
+ `;
2406
+ }
2407
+ function printCommandHelp(command) {
2408
+ const flags = command.flags.map((flag) => {
2409
+ const req = flag.required ? "required" : "optional";
2410
+ return ` --${flag.flag} <${flag.name}> ${req} ${flag.source}`;
2411
+ }).join("\n");
2412
+ const jsonLine = command.acceptsJsonBody ? ` --json <object|-> ${command.bodyRequired ? "required" : "optional"} body
2413
+ ` : "";
2414
+ return `omni ${command.trail.join(" ")}
2415
+
2416
+ ${command.summary}
2417
+
2418
+ ${command.httpMethod} ${command.path}
2419
+
2420
+ Flags:
2421
+ ${flags || " (none)"}${jsonLine ? `
2422
+ ${jsonLine}` : ""}
2423
+ `;
2424
+ }
2425
+ function matchCommands(commands, trail) {
2426
+ const prefix = commands.filter(
2427
+ (command) => trail.every((token, index) => command.trail[index] === token)
2428
+ );
2429
+ const exact = prefix.find((command) => command.trail.length === trail.length);
2430
+ return { exact, prefix };
2431
+ }
2432
+
2433
+ // src/version.ts
2434
+ var CLI_VERSION = "0.1.0";
2435
+
2436
+ // src/run.ts
2437
+ async function readStdin() {
2438
+ const chunks = [];
2439
+ for await (const chunk of input) {
2440
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
2441
+ }
2442
+ return Buffer.concat(chunks).toString("utf8");
2443
+ }
2444
+ async function parseJsonBody(raw) {
2445
+ if (!raw) return void 0;
2446
+ const text = raw === "-" ? await readStdin() : raw;
2447
+ const parsed = JSON.parse(text);
2448
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
2449
+ throw new Error("--json must be a JSON object");
2450
+ }
2451
+ return parsed;
2452
+ }
2453
+ function buildRequest(command, flags, body) {
2454
+ const request = { ...body };
2455
+ for (const flag of command.flags) {
2456
+ const value = flagString(flags, flag.flag);
2457
+ if (value === void 0) {
2458
+ if (flag.required) {
2459
+ throw new Error(`Missing required flag --${flag.flag}`);
2460
+ }
2461
+ continue;
2462
+ }
2463
+ request[flag.name] = value;
2464
+ }
2465
+ return request;
2466
+ }
2467
+ async function handleAuth(trail, flags) {
2468
+ const action = trail[1] ?? "status";
2469
+ if (action === "login") {
2470
+ const apiKey = flagString(flags, "api-key");
2471
+ if (!apiKey) {
2472
+ throw new Error("omni auth login requires --api-key");
2473
+ }
2474
+ const existing = await readConfig();
2475
+ await writeConfig({
2476
+ ...existing,
2477
+ apiKey,
2478
+ baseUrl: flagString(flags, "base-url") ?? existing.baseUrl
2479
+ });
2480
+ process.stdout.write(
2481
+ `Saved credentials to config (${maskSecret(apiKey)})
2482
+ `
2483
+ );
2484
+ return 0;
2485
+ }
2486
+ if (action === "logout") {
2487
+ await clearConfig();
2488
+ process.stdout.write("Removed saved credentials\n");
2489
+ return 0;
2490
+ }
2491
+ const resolved = await resolveCredentials({
2492
+ apiKey: flagString(flags, "api-key"),
2493
+ baseUrl: flagString(flags, "base-url")
2494
+ });
2495
+ process.stdout.write(
2496
+ `source ${resolved.source}
2497
+ baseUrl ${resolved.baseUrl}
2498
+ apiKey ${resolved.apiKey ? maskSecret(resolved.apiKey) : "(missing)"}
2499
+ `
2500
+ );
2501
+ return resolved.apiKey ? 0 : 1;
2502
+ }
2503
+ async function runCli(argv, options) {
2504
+ const parsed = parseArgv(argv);
2505
+ if (parsed.flags.version === true) {
2506
+ process.stdout.write(`${CLI_VERSION}
2507
+ `);
2508
+ return 0;
2509
+ }
2510
+ if (parsed.trail[0] === "auth") {
2511
+ return handleAuth(parsed.trail, parsed.flags);
2512
+ }
2513
+ if (parsed.trail.length === 0) {
2514
+ process.stdout.write(printRootHelp(COMMANDS));
2515
+ return parsed.help ? 0 : 1;
2516
+ }
2517
+ const matched = matchCommands(COMMANDS, parsed.trail);
2518
+ if (parsed.help && !matched.exact) {
2519
+ if (matched.prefix.length === 0) {
2520
+ process.stderr.write(`Unknown command: ${parsed.trail.join(" ")}
2521
+ `);
2522
+ process.stdout.write(printRootHelp(COMMANDS));
2523
+ return 1;
2524
+ }
2525
+ const unique = [
2526
+ ...new Set(matched.prefix.map((command2) => command2.trail.join(" ")))
2527
+ ];
2528
+ process.stdout.write(
2529
+ `omni ${parsed.trail.join(" ")}
2530
+
2531
+ Commands:
2532
+ ${unique.map((line) => ` omni ${line}`).join("\n")}
2533
+ `
2534
+ );
2535
+ return 0;
2536
+ }
2537
+ const command = matched.exact;
2538
+ if (!command) {
2539
+ process.stderr.write(`Unknown command: ${parsed.trail.join(" ")}
2540
+ `);
2541
+ process.stdout.write(printRootHelp(COMMANDS));
2542
+ return 1;
2543
+ }
2544
+ if (parsed.help) {
2545
+ process.stdout.write(printCommandHelp(command));
2546
+ return 0;
2547
+ }
2548
+ if (parsed.schema) {
2549
+ process.stdout.write(`${JSON.stringify(command, null, 2)}
2550
+ `);
2551
+ return 0;
2552
+ }
2553
+ const body = await parseJsonBody(flagString(parsed.flags, "json"));
2554
+ if (command.bodyRequired && !body) {
2555
+ throw new Error(`omni ${command.trail.join(" ")} requires --json`);
2556
+ }
2557
+ const request = buildRequest(command, parsed.flags, body);
2558
+ if (parsed.dryRun) {
2559
+ process.stdout.write(
2560
+ `${JSON.stringify(
2561
+ {
2562
+ method: command.httpMethod,
2563
+ path: command.path,
2564
+ request
2565
+ },
2566
+ null,
2567
+ 2
2568
+ )}
2569
+ `
2570
+ );
2571
+ return 0;
2572
+ }
2573
+ const credentials = await resolveCredentials({
2574
+ apiKey: flagString(parsed.flags, "api-key"),
2575
+ baseUrl: flagString(parsed.flags, "base-url")
2576
+ });
2577
+ if (!credentials.apiKey) {
2578
+ process.stderr.write(
2579
+ "Missing API key. Pass --api-key, set OMNI_API_KEY, or run omni auth login.\n"
2580
+ );
2581
+ return 1;
2582
+ }
2583
+ const timeoutRaw = flagString(parsed.flags, "timeout");
2584
+ const timeoutInSeconds = timeoutRaw ? Number(timeoutRaw) : void 0;
2585
+ const client = new OmniClient({
2586
+ apiKey: credentials.apiKey,
2587
+ baseUrl: credentials.baseUrl,
2588
+ timeoutInSeconds: timeoutInSeconds && Number.isFinite(timeoutInSeconds) ? timeoutInSeconds : void 0,
2589
+ fetch: options?.fetch
2590
+ });
2591
+ try {
2592
+ const result = await executeCommand(client, command, request);
2593
+ const format = resolveFormat(
2594
+ flagString(parsed.flags, "format"),
2595
+ options?.stdoutIsTty ?? Boolean(process.stdout.isTTY)
2596
+ );
2597
+ process.stdout.write(formatOutput(result, format));
2598
+ return 0;
2599
+ } catch (error) {
2600
+ if (error instanceof OmniError) {
2601
+ process.stderr.write(
2602
+ `${error.name}: ${error.message}${error.statusCode ? ` (${error.statusCode})` : ""}
2603
+ `
2604
+ );
2605
+ if (error.body) {
2606
+ process.stderr.write(`${JSON.stringify(error.body, null, 2)}
2607
+ `);
2608
+ }
2609
+ return 1;
2610
+ }
2611
+ throw error;
2612
+ }
2613
+ }
2614
+
2615
+ // src/index.ts
2616
+ var main = async () => {
2617
+ try {
2618
+ const code = await runCli(process.argv.slice(2), {
2619
+ stdoutIsTty: Boolean(process.stdout.isTTY)
2620
+ });
2621
+ process.exitCode = code;
2622
+ } catch (error) {
2623
+ const message = error instanceof Error ? error.message : String(error);
2624
+ process.stderr.write(`${message}
2625
+ `);
2626
+ process.exitCode = 1;
2627
+ }
2628
+ };
2629
+ void main();
2630
+ //# sourceMappingURL=index.js.map