@uniformdev/cli 18.16.1-alpha.6 → 18.18.1-alpha.12

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.mjs CHANGED
@@ -1,24 +1,3746 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ __privateAdd,
4
+ __privateGet,
5
+ __privateSet,
6
+ __privateWrapper,
3
7
  __require,
4
8
  __toESM,
5
- require_source
6
- } from "./chunk-IRPO3X2Q.mjs";
9
+ createArraySyncEngineDataSource,
10
+ createFileSyncEngineDataSource,
11
+ createSyncEngineConsoleLogger,
12
+ emitWithFormat,
13
+ isPathAPackageFile,
14
+ nodeFetchProxy,
15
+ paginateAsync,
16
+ readFileToObject,
17
+ readUniformPackage,
18
+ require_source,
19
+ syncEngine,
20
+ withApiOptions,
21
+ withDiffOptions,
22
+ withFormatOptions,
23
+ withProjectOptions,
24
+ writeUniformPackage
25
+ } from "./chunk-NNLVNLDW.mjs";
7
26
 
8
27
  // src/index.ts
28
+ import yargs17 from "yargs";
29
+
30
+ // src/commands/canvas/index.ts
31
+ import yargs4 from "yargs";
32
+
33
+ // src/commands/canvas/commands/component.ts
34
+ import yargs from "yargs";
35
+
36
+ // src/commands/canvas/commands/component/get.ts
37
+ import { UncachedCanvasClient } from "@uniformdev/canvas";
38
+ var ComponentGetModule = {
39
+ command: "get <id>",
40
+ describe: "Fetch a component definition",
41
+ builder: (yargs18) => withFormatOptions(
42
+ withApiOptions(
43
+ withProjectOptions(
44
+ yargs18.positional("id", { demandOption: true, describe: "Component definition public ID to fetch" })
45
+ )
46
+ )
47
+ ),
48
+ handler: async ({ apiHost, apiKey, proxy, id, format, project: projectId, filename }) => {
49
+ const fetch3 = nodeFetchProxy(proxy);
50
+ const client = new UncachedCanvasClient({ apiKey, apiHost, fetch: fetch3, projectId });
51
+ const res = await client.getComponentDefinitions({ componentId: id, limit: 1 });
52
+ if (res.componentDefinitions.length === 0) {
53
+ console.error("Component did not exist");
54
+ process.exit(1);
55
+ } else {
56
+ emitWithFormat(res.componentDefinitions[0], format, filename);
57
+ }
58
+ }
59
+ };
60
+
61
+ // src/commands/canvas/commands/component/list.ts
62
+ import { UncachedCanvasClient as UncachedCanvasClient2 } from "@uniformdev/canvas";
63
+ var ComponentListModule = {
64
+ command: "list",
65
+ describe: "List component definitions",
66
+ aliases: ["ls"],
67
+ builder: (yargs18) => withFormatOptions(
68
+ withApiOptions(
69
+ withProjectOptions(
70
+ yargs18.options({
71
+ offset: { describe: "Number of rows to skip before fetching", type: "number", default: 0 },
72
+ limit: { describe: "Number of rows to fetch", type: "number", default: 20 }
73
+ })
74
+ )
75
+ )
76
+ ),
77
+ handler: async ({ apiHost, apiKey, proxy, limit, offset, format, filename, project: projectId }) => {
78
+ const fetch3 = nodeFetchProxy(proxy);
79
+ const client = new UncachedCanvasClient2({ apiKey, apiHost, fetch: fetch3, projectId });
80
+ const res = await client.getComponentDefinitions({ limit, offset });
81
+ emitWithFormat(res.componentDefinitions, format, filename);
82
+ }
83
+ };
84
+
85
+ // src/commands/canvas/commands/component/pull.ts
86
+ import { UncachedCanvasClient as UncachedCanvasClient3 } from "@uniformdev/canvas";
87
+
88
+ // src/commands/canvas/commands/component/_util.ts
89
+ var selectIdentifier = (component) => component.id;
90
+ var selectDisplayName = (component) => `${component.name} (pid: ${component.id})`;
91
+
92
+ // src/commands/canvas/componentDefinitionEngineDataSource.ts
93
+ function createComponentDefinitionEngineDataSource({
94
+ client
95
+ }) {
96
+ async function* getObjects() {
97
+ const componentDefinitions = paginateAsync(
98
+ async (offset, limit) => (await client.getComponentDefinitions({ limit, offset })).componentDefinitions,
99
+ { pageSize: 100 }
100
+ );
101
+ for await (const def of componentDefinitions) {
102
+ const result = {
103
+ id: selectIdentifier(def),
104
+ displayName: selectDisplayName(def),
105
+ providerId: def.id,
106
+ object: def
107
+ };
108
+ yield result;
109
+ }
110
+ }
111
+ return {
112
+ objects: getObjects(),
113
+ deleteObject: async (providerId) => {
114
+ await client.removeComponentDefinition({ componentId: providerId });
115
+ },
116
+ writeObject: async (object) => {
117
+ await client.updateComponentDefinition({
118
+ componentDefinition: object.object
119
+ });
120
+ }
121
+ };
122
+ }
123
+
124
+ // src/commands/canvas/package.ts
125
+ function readCanvasPackage(filename, assertExists) {
126
+ return readUniformPackage(filename, assertExists);
127
+ }
128
+ function writeCanvasPackage(filename, packageContents) {
129
+ writeUniformPackage(filename, packageContents);
130
+ }
131
+
132
+ // src/commands/canvas/util.ts
133
+ import { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE } from "@uniformdev/canvas";
134
+
135
+ // ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
136
+ var Node = class {
137
+ value;
138
+ next;
139
+ constructor(value) {
140
+ this.value = value;
141
+ }
142
+ };
143
+ var _head, _tail, _size;
144
+ var Queue = class {
145
+ constructor() {
146
+ __privateAdd(this, _head, void 0);
147
+ __privateAdd(this, _tail, void 0);
148
+ __privateAdd(this, _size, void 0);
149
+ this.clear();
150
+ }
151
+ enqueue(value) {
152
+ const node = new Node(value);
153
+ if (__privateGet(this, _head)) {
154
+ __privateGet(this, _tail).next = node;
155
+ __privateSet(this, _tail, node);
156
+ } else {
157
+ __privateSet(this, _head, node);
158
+ __privateSet(this, _tail, node);
159
+ }
160
+ __privateWrapper(this, _size)._++;
161
+ }
162
+ dequeue() {
163
+ const current = __privateGet(this, _head);
164
+ if (!current) {
165
+ return;
166
+ }
167
+ __privateSet(this, _head, __privateGet(this, _head).next);
168
+ __privateWrapper(this, _size)._--;
169
+ return current.value;
170
+ }
171
+ clear() {
172
+ __privateSet(this, _head, void 0);
173
+ __privateSet(this, _tail, void 0);
174
+ __privateSet(this, _size, 0);
175
+ }
176
+ get size() {
177
+ return __privateGet(this, _size);
178
+ }
179
+ *[Symbol.iterator]() {
180
+ let current = __privateGet(this, _head);
181
+ while (current) {
182
+ yield current.value;
183
+ current = current.next;
184
+ }
185
+ }
186
+ };
187
+ _head = new WeakMap();
188
+ _tail = new WeakMap();
189
+ _size = new WeakMap();
190
+
191
+ // ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
192
+ function pLimit(concurrency) {
193
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
194
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
195
+ }
196
+ const queue = new Queue();
197
+ let activeCount = 0;
198
+ const next = () => {
199
+ activeCount--;
200
+ if (queue.size > 0) {
201
+ queue.dequeue()();
202
+ }
203
+ };
204
+ const run = async (fn, resolve, args) => {
205
+ activeCount++;
206
+ const result = (async () => fn(...args))();
207
+ resolve(result);
208
+ try {
209
+ await result;
210
+ } catch {
211
+ }
212
+ next();
213
+ };
214
+ const enqueue = (fn, resolve, args) => {
215
+ queue.enqueue(run.bind(void 0, fn, resolve, args));
216
+ (async () => {
217
+ await Promise.resolve();
218
+ if (activeCount < concurrency && queue.size > 0) {
219
+ queue.dequeue()();
220
+ }
221
+ })();
222
+ };
223
+ const generator = (fn, ...args) => new Promise((resolve) => {
224
+ enqueue(fn, resolve, args);
225
+ });
226
+ Object.defineProperties(generator, {
227
+ activeCount: {
228
+ get: () => activeCount
229
+ },
230
+ pendingCount: {
231
+ get: () => queue.size
232
+ },
233
+ clearQueue: {
234
+ value: () => {
235
+ queue.clear();
236
+ }
237
+ }
238
+ });
239
+ return generator;
240
+ }
241
+
242
+ // src/commands/canvas/util.ts
243
+ function prepCompositionForDisk(composition) {
244
+ const prepped = {
245
+ ...composition
246
+ };
247
+ delete prepped.projectId;
248
+ delete prepped.state;
249
+ return prepped;
250
+ }
251
+ function withStateOptions(yargs18) {
252
+ return yargs18.option("state", {
253
+ type: "string",
254
+ describe: `Composition state to fetch.`,
255
+ choices: ["preview", "published"],
256
+ default: "preview"
257
+ });
258
+ }
259
+ function convertCompositionState(state) {
260
+ const number = Number(state);
261
+ if (!isNaN(number)) {
262
+ return number;
263
+ }
264
+ if (!state) {
265
+ return CANVAS_PUBLISHED_STATE;
266
+ }
267
+ if (typeof state !== "string") {
268
+ throw new Error('state must be "published", "preview", or a number');
269
+ }
270
+ return state === "preview" ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE;
271
+ }
272
+ var limitPolicy = pLimit(8);
273
+
274
+ // src/commands/canvas/commands/component/pull.ts
275
+ var ComponentPullModule = {
276
+ command: "pull <directory>",
277
+ describe: "Pulls all component definitions to local files in a directory",
278
+ builder: (yargs18) => withApiOptions(
279
+ withProjectOptions(
280
+ withDiffOptions(
281
+ yargs18.positional("directory", {
282
+ describe: "Directory to save the component definitions to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
283
+ type: "string"
284
+ }).option("format", {
285
+ alias: ["f"],
286
+ describe: "Output format",
287
+ default: "yaml",
288
+ choices: ["yaml", "json"],
289
+ type: "string"
290
+ }).option("what-if", {
291
+ alias: ["w"],
292
+ describe: "What-if mode reports what would be done but changes no files",
293
+ default: false,
294
+ type: "boolean"
295
+ }).option("mode", {
296
+ alias: ["m"],
297
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
298
+ choices: ["create", "createOrUpdate", "mirror"],
299
+ default: "mirror",
300
+ type: "string"
301
+ })
302
+ )
303
+ )
304
+ ),
305
+ handler: async ({
306
+ apiHost,
307
+ apiKey,
308
+ proxy,
309
+ directory,
310
+ format,
311
+ mode,
312
+ whatIf,
313
+ project: projectId,
314
+ diff: diffMode
315
+ }) => {
316
+ var _a;
317
+ const fetch3 = nodeFetchProxy(proxy);
318
+ const client = new UncachedCanvasClient3({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy });
319
+ const source = createComponentDefinitionEngineDataSource({ client });
320
+ let target;
321
+ const isPackage = isPathAPackageFile(directory);
322
+ if (isPackage) {
323
+ const packageContents = readCanvasPackage(directory, false);
324
+ target = await createArraySyncEngineDataSource({
325
+ objects: (_a = packageContents.components) != null ? _a : [],
326
+ selectIdentifier,
327
+ selectDisplayName,
328
+ onSyncComplete: async (_, synced) => {
329
+ packageContents.components = synced;
330
+ writeCanvasPackage(directory, packageContents);
331
+ }
332
+ });
333
+ } else {
334
+ target = await createFileSyncEngineDataSource({
335
+ directory,
336
+ selectIdentifier,
337
+ selectDisplayName,
338
+ format
339
+ });
340
+ }
341
+ await syncEngine({
342
+ source,
343
+ target,
344
+ mode,
345
+ whatIf,
346
+ log: createSyncEngineConsoleLogger({ diffMode })
347
+ });
348
+ }
349
+ };
350
+
351
+ // src/commands/canvas/commands/component/push.ts
352
+ import { UncachedCanvasClient as UncachedCanvasClient4 } from "@uniformdev/canvas";
353
+ var ComponentPushModule = {
354
+ command: "push <directory>",
355
+ describe: "Pushes all component definitions from files in a directory to Uniform Canvas",
356
+ builder: (yargs18) => withApiOptions(
357
+ withProjectOptions(
358
+ withDiffOptions(
359
+ yargs18.positional("directory", {
360
+ describe: "Directory to read the component definitions from. If a filename is used, a package will be read instead.",
361
+ type: "string"
362
+ }).option("what-if", {
363
+ alias: ["w"],
364
+ describe: "What-if mode reports what would be done but changes nothing",
365
+ default: false,
366
+ type: "boolean"
367
+ }).option("mode", {
368
+ alias: ["m"],
369
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
370
+ choices: ["create", "createOrUpdate", "mirror"],
371
+ default: "mirror",
372
+ type: "string"
373
+ })
374
+ )
375
+ )
376
+ ),
377
+ handler: async ({
378
+ apiHost,
379
+ apiKey,
380
+ proxy,
381
+ directory,
382
+ mode,
383
+ whatIf,
384
+ project: projectId,
385
+ diff: diffMode
386
+ }) => {
387
+ var _a;
388
+ const fetch3 = nodeFetchProxy(proxy);
389
+ const client = new UncachedCanvasClient4({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy });
390
+ let source;
391
+ const isPackage = isPathAPackageFile(directory);
392
+ if (isPackage) {
393
+ const packageContents = readCanvasPackage(directory, true);
394
+ source = await createArraySyncEngineDataSource({
395
+ objects: (_a = packageContents.components) != null ? _a : [],
396
+ selectIdentifier,
397
+ selectDisplayName
398
+ });
399
+ } else {
400
+ source = await createFileSyncEngineDataSource({
401
+ directory,
402
+ selectIdentifier,
403
+ selectDisplayName
404
+ });
405
+ }
406
+ const target = createComponentDefinitionEngineDataSource({ client });
407
+ await syncEngine({
408
+ source,
409
+ target,
410
+ mode,
411
+ whatIf,
412
+ log: createSyncEngineConsoleLogger({ diffMode })
413
+ });
414
+ }
415
+ };
416
+
417
+ // src/commands/canvas/commands/component/remove.ts
418
+ import { UncachedCanvasClient as UncachedCanvasClient5 } from "@uniformdev/canvas";
419
+ var ComponentRemoveModule = {
420
+ command: "remove <id>",
421
+ aliases: ["delete", "rm"],
422
+ describe: "Delete a component definition",
423
+ builder: (yargs18) => withApiOptions(
424
+ withProjectOptions(
425
+ yargs18.positional("id", { demandOption: true, describe: "Component definition public ID to delete" })
426
+ )
427
+ ),
428
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
429
+ const fetch3 = nodeFetchProxy(proxy);
430
+ const client = new UncachedCanvasClient5({ apiKey, apiHost, fetch: fetch3, projectId });
431
+ await client.removeComponentDefinition({ componentId: id });
432
+ }
433
+ };
434
+
435
+ // src/commands/canvas/commands/component/update.ts
436
+ import { UncachedCanvasClient as UncachedCanvasClient6 } from "@uniformdev/canvas";
437
+ var ComponentUpdateModule = {
438
+ command: "update <filename>",
439
+ aliases: ["put"],
440
+ describe: "Insert or update a component definition",
441
+ builder: (yargs18) => withApiOptions(
442
+ withProjectOptions(
443
+ yargs18.positional("filename", { demandOption: true, describe: "Component definition file to put" })
444
+ )
445
+ ),
446
+ handler: async ({ apiHost, apiKey, proxy, filename, project: projectId }) => {
447
+ const fetch3 = nodeFetchProxy(proxy);
448
+ const client = new UncachedCanvasClient6({ apiKey, apiHost, fetch: fetch3, projectId });
449
+ const file = readFileToObject(filename);
450
+ await client.updateComponentDefinition({ componentDefinition: file });
451
+ }
452
+ };
453
+
454
+ // src/commands/canvas/commands/component.ts
455
+ var ComponentModule = {
456
+ command: "component <command>",
457
+ aliases: ["def"],
458
+ describe: "Commands for Canvas component definitions",
459
+ builder: (yargs18) => yargs18.command(ComponentPullModule).command(ComponentPushModule).command(ComponentGetModule).command(ComponentRemoveModule).command(ComponentListModule).command(ComponentUpdateModule).demandCommand(),
460
+ handler: () => {
461
+ yargs.help();
462
+ }
463
+ };
464
+
465
+ // src/commands/canvas/commands/composition.ts
466
+ import yargs2 from "yargs";
467
+
468
+ // src/commands/canvas/commands/composition/get.ts
469
+ import { UncachedCanvasClient as UncachedCanvasClient7 } from "@uniformdev/canvas";
470
+ var CompositionGetModule = {
471
+ command: "get <id>",
472
+ describe: "Fetch a composition",
473
+ builder: (yargs18) => withFormatOptions(
474
+ withApiOptions(
475
+ withProjectOptions(
476
+ withStateOptions(
477
+ yargs18.positional("id", { demandOption: true, describe: "Composition public ID to fetch" }).option({
478
+ resolvePatterns: {
479
+ type: "boolean",
480
+ default: false,
481
+ describe: "Resolve pattern references in the composition"
482
+ },
483
+ componentIDs: {
484
+ type: "boolean",
485
+ default: false,
486
+ describe: "Include individual component UIDs"
487
+ },
488
+ unstableResolveData: {
489
+ type: "boolean",
490
+ default: false,
491
+ describe: "Resolve all data resources used by the composition"
492
+ },
493
+ unstableDataDiagnostics: {
494
+ type: "boolean",
495
+ default: false,
496
+ describe: "Include diagnostics information when resolving data"
497
+ }
498
+ })
499
+ )
500
+ )
501
+ )
502
+ ),
503
+ handler: async ({
504
+ apiHost,
505
+ edgeApiHost,
506
+ apiKey,
507
+ proxy,
508
+ id,
509
+ format,
510
+ filename,
511
+ state,
512
+ project: projectId,
513
+ resolvePatterns,
514
+ componentIDs,
515
+ unstableResolveData,
516
+ unstableDataDiagnostics
517
+ }) => {
518
+ const fetch3 = nodeFetchProxy(proxy);
519
+ const client = new UncachedCanvasClient7({ apiKey, edgeApiHost, apiHost, fetch: fetch3, projectId });
520
+ const res = prepCompositionForDisk(
521
+ await client.getCompositionById({
522
+ compositionId: id,
523
+ state: convertCompositionState(state),
524
+ skipPatternResolution: !resolvePatterns,
525
+ withComponentIDs: componentIDs,
526
+ unstable_resolveData: unstableResolveData,
527
+ unstable_dataDiagnostics: unstableDataDiagnostics
528
+ })
529
+ );
530
+ emitWithFormat(res, format, filename);
531
+ }
532
+ };
533
+
534
+ // src/commands/canvas/commands/composition/list.ts
535
+ import { UncachedCanvasClient as UncachedCanvasClient8 } from "@uniformdev/canvas";
536
+ var CompositionListModule = {
537
+ command: "list",
538
+ describe: "List compositions",
539
+ aliases: ["ls"],
540
+ builder: (yargs18) => withFormatOptions(
541
+ withApiOptions(
542
+ withProjectOptions(
543
+ withStateOptions(
544
+ yargs18.options({
545
+ offset: { describe: "Number of rows to skip before fetching", type: "number", default: 0 },
546
+ limit: { describe: "Number of rows to fetch", type: "number", default: 20 },
547
+ resolvePatterns: {
548
+ type: "boolean",
549
+ default: false,
550
+ describe: "Resolve pattern references in the composition"
551
+ },
552
+ componentIDs: {
553
+ type: "boolean",
554
+ default: false,
555
+ describe: "Include individual component UIDs"
556
+ }
557
+ })
558
+ )
559
+ )
560
+ )
561
+ ),
562
+ handler: async ({
563
+ apiHost,
564
+ apiKey,
565
+ proxy,
566
+ limit,
567
+ offset,
568
+ format,
569
+ filename,
570
+ project: projectId,
571
+ state,
572
+ resolvePatterns,
573
+ componentIDs
574
+ }) => {
575
+ const fetch3 = nodeFetchProxy(proxy);
576
+ const client = new UncachedCanvasClient8({ apiKey, apiHost, fetch: fetch3, projectId });
577
+ const res = await client.getCompositionList({
578
+ limit,
579
+ offset,
580
+ state: convertCompositionState(state),
581
+ skipPatternResolution: !resolvePatterns,
582
+ withComponentIDs: componentIDs
583
+ });
584
+ emitWithFormat(res.compositions, format, filename);
585
+ }
586
+ };
587
+
588
+ // src/commands/canvas/commands/composition/publish.ts
589
+ import { UncachedCanvasClient as UncachedCanvasClient9 } from "@uniformdev/canvas";
590
+
591
+ // src/commands/canvas/commands/composition/_util.ts
592
+ var selectIdentifier2 = (component) => component.composition._id;
593
+ var selectDisplayName2 = (component) => {
594
+ var _a, _b;
595
+ return `${(_b = (_a = component.composition._name) != null ? _a : component.composition._slug) != null ? _b : component.composition._id} (pid: ${component.composition._id})`;
596
+ };
597
+
598
+ // src/commands/canvas/componentInstanceEngineDataSource.ts
599
+ function createComponentInstanceEngineDataSource({
600
+ client,
601
+ state,
602
+ ...clientOptions
603
+ }) {
604
+ const stateId = convertCompositionState(state);
605
+ async function* getObjects() {
606
+ const componentInstances = paginateAsync(
607
+ async (offset, limit) => (await client.getCompositionList({
608
+ ...clientOptions,
609
+ limit,
610
+ offset,
611
+ state: stateId,
612
+ skipPatternResolution: true,
613
+ skipParameterResolution: true,
614
+ withComponentIDs: true
615
+ })).compositions,
616
+ { pageSize: 100 }
617
+ );
618
+ for await (const compositionListItem of componentInstances) {
619
+ const result = {
620
+ id: selectIdentifier2(compositionListItem),
621
+ displayName: selectDisplayName2(compositionListItem),
622
+ providerId: compositionListItem.composition._id,
623
+ object: prepCompositionForDisk(compositionListItem)
624
+ };
625
+ yield result;
626
+ }
627
+ }
628
+ return {
629
+ objects: getObjects(),
630
+ deleteObject: async (providerId) => {
631
+ await client.removeComposition({ compositionId: providerId });
632
+ },
633
+ writeObject: async (object) => {
634
+ await client.updateComposition({ ...object.object, state: stateId });
635
+ }
636
+ };
637
+ }
638
+
639
+ // src/commands/canvas/commands/composition/publish.ts
640
+ var CompositionPublishModule = {
641
+ command: "publish [compositionIDs]",
642
+ describe: "Publishes compositions",
643
+ builder: (yargs18) => withApiOptions(
644
+ withProjectOptions(
645
+ withDiffOptions(
646
+ yargs18.positional("compositionIDs", {
647
+ describe: "Publishes composition(s) by ID. Comma-separate multiple IDs. Use --all to publish all instead.",
648
+ type: "string"
649
+ }).option("all", {
650
+ alias: ["a"],
651
+ describe: "Publishes all compositions. Use compositionId to publish one instead.",
652
+ default: false,
653
+ type: "boolean"
654
+ }).option("what-if", {
655
+ alias: ["w"],
656
+ describe: "What-if mode reports what would be done but does not perform any publishing",
657
+ default: false,
658
+ type: "boolean"
659
+ })
660
+ )
661
+ )
662
+ ),
663
+ handler: async ({
664
+ apiHost,
665
+ apiKey,
666
+ proxy,
667
+ compositionIDs,
668
+ all,
669
+ whatIf,
670
+ project: projectId,
671
+ diff: diffMode
672
+ }) => {
673
+ if (!all && !compositionIDs || all && compositionIDs) {
674
+ console.error(`Specify --all or composition ID(s) to publish.`);
675
+ process.exit(1);
676
+ }
677
+ const compositionIDsArray = compositionIDs ? compositionIDs.split(",").map((id) => id.trim()) : void 0;
678
+ const fetch3 = nodeFetchProxy(proxy);
679
+ const client = new UncachedCanvasClient9({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy });
680
+ const source = createComponentInstanceEngineDataSource({
681
+ client,
682
+ state: "preview",
683
+ compositionIDs: compositionIDsArray
684
+ });
685
+ const target = createComponentInstanceEngineDataSource({
686
+ client,
687
+ state: "published",
688
+ compositionIDs: compositionIDsArray
689
+ });
690
+ await syncEngine({
691
+ source,
692
+ target,
693
+ mode: "mirror",
694
+ whatIf,
695
+ log: createSyncEngineConsoleLogger({ diffMode })
696
+ });
697
+ }
698
+ };
699
+
700
+ // src/commands/canvas/commands/composition/pull.ts
701
+ import { UncachedCanvasClient as UncachedCanvasClient10 } from "@uniformdev/canvas";
702
+ var CompositionPullModule = {
703
+ command: "pull <directory>",
704
+ describe: "Pulls all compositions to local files in a directory",
705
+ builder: (yargs18) => withApiOptions(
706
+ withProjectOptions(
707
+ withStateOptions(
708
+ withDiffOptions(
709
+ yargs18.positional("directory", {
710
+ describe: "Directory to save the component definitions to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
711
+ type: "string"
712
+ }).option("format", {
713
+ alias: ["f"],
714
+ describe: "Output format",
715
+ default: "yaml",
716
+ choices: ["yaml", "json"],
717
+ type: "string"
718
+ }).option("what-if", {
719
+ alias: ["w"],
720
+ describe: "What-if mode reports what would be done but changes no files",
721
+ default: false,
722
+ type: "boolean"
723
+ }).option("mode", {
724
+ alias: ["m"],
725
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
726
+ choices: ["create", "createOrUpdate", "mirror"],
727
+ default: "mirror",
728
+ type: "string"
729
+ })
730
+ )
731
+ )
732
+ )
733
+ ),
734
+ handler: async ({
735
+ apiHost,
736
+ apiKey,
737
+ proxy,
738
+ directory,
739
+ format,
740
+ mode,
741
+ whatIf,
742
+ state,
743
+ project: projectId,
744
+ diff: diffMode
745
+ }) => {
746
+ var _a;
747
+ const fetch3 = nodeFetchProxy(proxy);
748
+ const client = new UncachedCanvasClient10({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy });
749
+ const source = createComponentInstanceEngineDataSource({ client, state });
750
+ const isPackage = isPathAPackageFile(directory);
751
+ let target;
752
+ if (isPackage) {
753
+ const packageContents = readCanvasPackage(directory, false);
754
+ target = await createArraySyncEngineDataSource({
755
+ objects: (_a = packageContents == null ? void 0 : packageContents.compositions) != null ? _a : [],
756
+ selectIdentifier: selectIdentifier2,
757
+ selectDisplayName: selectDisplayName2,
758
+ onSyncComplete: async (_, synced) => {
759
+ packageContents.compositions = synced;
760
+ writeCanvasPackage(directory, packageContents);
761
+ }
762
+ });
763
+ } else {
764
+ target = await createFileSyncEngineDataSource({
765
+ directory,
766
+ selectIdentifier: selectIdentifier2,
767
+ selectDisplayName: selectDisplayName2,
768
+ format
769
+ });
770
+ }
771
+ await syncEngine({
772
+ source,
773
+ target,
774
+ mode,
775
+ whatIf,
776
+ log: createSyncEngineConsoleLogger({ diffMode })
777
+ });
778
+ }
779
+ };
780
+
781
+ // src/commands/canvas/commands/composition/push.ts
782
+ import { UncachedCanvasClient as UncachedCanvasClient11 } from "@uniformdev/canvas";
783
+ var CompositionPushModule = {
784
+ command: "push <directory>",
785
+ describe: "Pushes all compositions from files in a directory to Uniform Canvas",
786
+ builder: (yargs18) => withApiOptions(
787
+ withProjectOptions(
788
+ withStateOptions(
789
+ withDiffOptions(
790
+ yargs18.positional("directory", {
791
+ describe: "Directory to read the component definitions from. If a filename is used, a package will be read instead.",
792
+ type: "string"
793
+ }).option("what-if", {
794
+ alias: ["w"],
795
+ describe: "What-if mode reports what would be done but changes nothing",
796
+ default: false,
797
+ type: "boolean"
798
+ }).option("mode", {
799
+ alias: ["m"],
800
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
801
+ choices: ["create", "createOrUpdate", "mirror"],
802
+ default: "mirror",
803
+ type: "string"
804
+ })
805
+ )
806
+ )
807
+ )
808
+ ),
809
+ handler: async ({
810
+ apiHost,
811
+ apiKey,
812
+ proxy,
813
+ directory,
814
+ mode,
815
+ whatIf,
816
+ state,
817
+ project: projectId,
818
+ diff: diffMode
819
+ }) => {
820
+ var _a;
821
+ const fetch3 = nodeFetchProxy(proxy);
822
+ const client = new UncachedCanvasClient11({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy });
823
+ let source;
824
+ const isPackage = isPathAPackageFile(directory);
825
+ if (isPackage) {
826
+ const packageContents = readCanvasPackage(directory, true);
827
+ source = await createArraySyncEngineDataSource({
828
+ objects: (_a = packageContents.compositions) != null ? _a : [],
829
+ selectIdentifier: selectIdentifier2,
830
+ selectDisplayName: selectDisplayName2
831
+ });
832
+ } else {
833
+ source = await createFileSyncEngineDataSource({
834
+ directory,
835
+ selectIdentifier: selectIdentifier2,
836
+ selectDisplayName: selectDisplayName2
837
+ });
838
+ }
839
+ const target = createComponentInstanceEngineDataSource({ client, state });
840
+ await syncEngine({
841
+ source,
842
+ target,
843
+ mode,
844
+ whatIf,
845
+ log: createSyncEngineConsoleLogger({ diffMode })
846
+ });
847
+ }
848
+ };
849
+
850
+ // src/commands/canvas/commands/composition/remove.ts
851
+ import { UncachedCanvasClient as UncachedCanvasClient12 } from "@uniformdev/canvas";
852
+ var CompositionRemoveModule = {
853
+ command: "remove <id>",
854
+ aliases: ["delete", "rm"],
855
+ describe: "Delete a composition",
856
+ builder: (yargs18) => withApiOptions(
857
+ withProjectOptions(
858
+ yargs18.positional("id", { demandOption: true, describe: "Composition public ID to delete" })
859
+ )
860
+ ),
861
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
862
+ const fetch3 = nodeFetchProxy(proxy);
863
+ const client = new UncachedCanvasClient12({ apiKey, apiHost, fetch: fetch3, projectId });
864
+ await client.removeComposition({ compositionId: id });
865
+ }
866
+ };
867
+
868
+ // src/commands/canvas/commands/composition/unpublish.ts
869
+ import { CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2, UncachedCanvasClient as UncachedCanvasClient13 } from "@uniformdev/canvas";
870
+ var CompositionUnpublishModule = {
871
+ command: "unpublish <id>",
872
+ describe: "Unpublish a composition",
873
+ builder: (yargs18) => withApiOptions(
874
+ withProjectOptions(
875
+ yargs18.positional("id", { demandOption: true, describe: "Composition public ID to unpublish" })
876
+ )
877
+ ),
878
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
879
+ const fetch3 = nodeFetchProxy(proxy);
880
+ const client = new UncachedCanvasClient13({ apiKey, apiHost, fetch: fetch3, projectId });
881
+ await client.removeComposition({ compositionId: id, state: CANVAS_PUBLISHED_STATE2 });
882
+ }
883
+ };
884
+
885
+ // src/commands/canvas/commands/composition/update.ts
886
+ import { UncachedCanvasClient as UncachedCanvasClient14 } from "@uniformdev/canvas";
887
+ var CompositionUpdateModule = {
888
+ command: "update <filename>",
889
+ aliases: ["put"],
890
+ describe: "Insert or update a composition",
891
+ builder: (yargs18) => withApiOptions(
892
+ withProjectOptions(
893
+ withStateOptions(
894
+ yargs18.positional("filename", { demandOption: true, describe: "Composition file to put" })
895
+ )
896
+ )
897
+ ),
898
+ handler: async ({ apiHost, apiKey, proxy, filename, project: projectId, state }) => {
899
+ const fetch3 = nodeFetchProxy(proxy);
900
+ const client = new UncachedCanvasClient14({ apiKey, apiHost, fetch: fetch3, projectId });
901
+ const file = readFileToObject(filename);
902
+ await client.updateComposition({ ...file, state: convertCompositionState(state) });
903
+ }
904
+ };
905
+
906
+ // src/commands/canvas/commands/composition.ts
907
+ var CompositionModule = {
908
+ command: "composition <command>",
909
+ describe: "Commands for Canvas compositions",
910
+ aliases: ["comp"],
911
+ builder: (yargs18) => yargs18.command(CompositionPullModule).command(CompositionPushModule).command(CompositionGetModule).command(CompositionRemoveModule).command(CompositionListModule).command(CompositionUpdateModule).command(CompositionPublishModule).command(CompositionUnpublishModule).demandCommand(),
912
+ handler: () => {
913
+ yargs2.help();
914
+ }
915
+ };
916
+
917
+ // src/commands/canvas/commands/dataType.ts
9
918
  import yargs3 from "yargs";
10
919
 
11
- // src/commands/optimize.ts
12
- import yargs2 from "yargs";
920
+ // src/commands/canvas/commands/dataType/get.ts
921
+ import { DataTypeClient } from "@uniformdev/canvas";
922
+ var DataTypeGetModule = {
923
+ command: "get <id>",
924
+ describe: "Get a data type",
925
+ aliases: ["ls"],
926
+ builder: (yargs18) => withFormatOptions(
927
+ withApiOptions(
928
+ withProjectOptions(
929
+ yargs18.positional("id", { demandOption: true, describe: "Data type public ID to fetch" })
930
+ )
931
+ )
932
+ ),
933
+ handler: async ({ apiHost, apiKey, proxy, id, format, filename, project: projectId }) => {
934
+ const fetch3 = nodeFetchProxy(proxy);
935
+ const client = new DataTypeClient({ apiKey, apiHost, fetch: fetch3, projectId, bypassCache: true });
936
+ const res = await client.get();
937
+ const found = res.results.find((f) => f.id === id);
938
+ if (!found) {
939
+ throw new Error(`Data type with ID ${id} not found`);
940
+ }
941
+ emitWithFormat(found, format, filename);
942
+ }
943
+ };
944
+
945
+ // src/commands/canvas/commands/dataType/list.ts
946
+ import { DataTypeClient as DataTypeClient2 } from "@uniformdev/canvas";
947
+ var DataTypeListModule = {
948
+ command: "list",
949
+ describe: "List data types",
950
+ aliases: ["ls"],
951
+ builder: (yargs18) => withFormatOptions(withApiOptions(withProjectOptions(yargs18))),
952
+ handler: async ({ apiHost, apiKey, proxy, format, filename, project: projectId }) => {
953
+ const fetch3 = nodeFetchProxy(proxy);
954
+ const client = new DataTypeClient2({ apiKey, apiHost, fetch: fetch3, projectId, bypassCache: true });
955
+ const res = await client.get();
956
+ emitWithFormat(res.results, format, filename);
957
+ }
958
+ };
959
+
960
+ // src/commands/canvas/commands/dataType/pull.ts
961
+ import { DataTypeClient as DataTypeClient3 } from "@uniformdev/canvas";
962
+
963
+ // src/commands/canvas/commands/dataType/_util.ts
964
+ var selectIdentifier3 = (dataType) => dataType.id;
965
+ var selectDisplayName3 = (dataType) => `${dataType.displayName} (pid: ${dataType.id})`;
966
+
967
+ // src/commands/canvas/dataTypeEngineDataSource.ts
968
+ function createDataTypeEngineDataSource({
969
+ client
970
+ }) {
971
+ async function* getObjects() {
972
+ const dataTypes = (await client.get()).results;
973
+ for await (const dataType of dataTypes) {
974
+ const result = {
975
+ id: selectIdentifier3(dataType),
976
+ displayName: selectDisplayName3(dataType),
977
+ providerId: dataType.id,
978
+ object: dataType
979
+ };
980
+ yield result;
981
+ }
982
+ }
983
+ return {
984
+ objects: getObjects(),
985
+ deleteObject: async (providerId) => {
986
+ await client.remove({ typeId: providerId });
987
+ },
988
+ writeObject: async (object) => {
989
+ await client.upsert({
990
+ data: object.object
991
+ });
992
+ }
993
+ };
994
+ }
995
+
996
+ // src/commands/canvas/commands/dataType/pull.ts
997
+ var DataTypePullModule = {
998
+ command: "pull <directory>",
999
+ describe: "Pulls all data types to local files in a directory",
1000
+ builder: (yargs18) => withApiOptions(
1001
+ withProjectOptions(
1002
+ withDiffOptions(
1003
+ yargs18.positional("directory", {
1004
+ describe: "Directory to save the data types to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
1005
+ type: "string"
1006
+ }).option("format", {
1007
+ alias: ["f"],
1008
+ describe: "Output format",
1009
+ default: "yaml",
1010
+ choices: ["yaml", "json"],
1011
+ type: "string"
1012
+ }).option("what-if", {
1013
+ alias: ["w"],
1014
+ describe: "What-if mode reports what would be done but changes no files",
1015
+ default: false,
1016
+ type: "boolean"
1017
+ }).option("mode", {
1018
+ alias: ["m"],
1019
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
1020
+ choices: ["create", "createOrUpdate", "mirror"],
1021
+ default: "mirror",
1022
+ type: "string"
1023
+ })
1024
+ )
1025
+ )
1026
+ ),
1027
+ handler: async ({
1028
+ apiHost,
1029
+ apiKey,
1030
+ proxy,
1031
+ directory,
1032
+ format,
1033
+ mode,
1034
+ whatIf,
1035
+ project: projectId,
1036
+ diff: diffMode
1037
+ }) => {
1038
+ var _a;
1039
+ const fetch3 = nodeFetchProxy(proxy);
1040
+ const client = new DataTypeClient3({
1041
+ apiKey,
1042
+ apiHost,
1043
+ fetch: fetch3,
1044
+ projectId,
1045
+ limitPolicy,
1046
+ bypassCache: true
1047
+ });
1048
+ const source = createDataTypeEngineDataSource({ client });
1049
+ let target;
1050
+ const isPackage = isPathAPackageFile(directory);
1051
+ if (isPackage) {
1052
+ const packageContents = readCanvasPackage(directory, false);
1053
+ target = await createArraySyncEngineDataSource({
1054
+ objects: (_a = packageContents.dataTypes) != null ? _a : [],
1055
+ selectIdentifier: selectIdentifier3,
1056
+ selectDisplayName: selectDisplayName3,
1057
+ onSyncComplete: async (_, synced) => {
1058
+ packageContents.dataTypes = synced;
1059
+ writeCanvasPackage(directory, packageContents);
1060
+ }
1061
+ });
1062
+ } else {
1063
+ target = await createFileSyncEngineDataSource({
1064
+ directory,
1065
+ selectIdentifier: selectIdentifier3,
1066
+ selectDisplayName: selectDisplayName3,
1067
+ format
1068
+ });
1069
+ }
1070
+ await syncEngine({
1071
+ source,
1072
+ target,
1073
+ mode,
1074
+ whatIf,
1075
+ log: createSyncEngineConsoleLogger({ diffMode })
1076
+ });
1077
+ }
1078
+ };
1079
+
1080
+ // src/commands/canvas/commands/dataType/push.ts
1081
+ import { DataTypeClient as DataTypeClient4 } from "@uniformdev/canvas";
1082
+ var DataTypePushModule = {
1083
+ command: "push <directory>",
1084
+ describe: "Pushes all data types from files in a directory to Uniform",
1085
+ builder: (yargs18) => withApiOptions(
1086
+ withProjectOptions(
1087
+ withDiffOptions(
1088
+ yargs18.positional("directory", {
1089
+ describe: "Directory to read the data types from. If a filename is used, a package will be read instead.",
1090
+ type: "string"
1091
+ }).option("what-if", {
1092
+ alias: ["w"],
1093
+ describe: "What-if mode reports what would be done but changes nothing",
1094
+ default: false,
1095
+ type: "boolean"
1096
+ }).option("mode", {
1097
+ alias: ["m"],
1098
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
1099
+ choices: ["create", "createOrUpdate", "mirror"],
1100
+ default: "mirror",
1101
+ type: "string"
1102
+ })
1103
+ )
1104
+ )
1105
+ ),
1106
+ handler: async ({
1107
+ apiHost,
1108
+ apiKey,
1109
+ proxy,
1110
+ directory,
1111
+ mode,
1112
+ whatIf,
1113
+ project: projectId,
1114
+ diff: diffMode
1115
+ }) => {
1116
+ var _a;
1117
+ const fetch3 = nodeFetchProxy(proxy);
1118
+ const client = new DataTypeClient4({
1119
+ apiKey,
1120
+ apiHost,
1121
+ fetch: fetch3,
1122
+ projectId,
1123
+ limitPolicy,
1124
+ bypassCache: true
1125
+ });
1126
+ let source;
1127
+ const isPackage = isPathAPackageFile(directory);
1128
+ if (isPackage) {
1129
+ const packageContents = readCanvasPackage(directory, true);
1130
+ source = await createArraySyncEngineDataSource({
1131
+ objects: (_a = packageContents.dataTypes) != null ? _a : [],
1132
+ selectIdentifier: selectIdentifier3,
1133
+ selectDisplayName: selectDisplayName3
1134
+ });
1135
+ } else {
1136
+ source = await createFileSyncEngineDataSource({
1137
+ directory,
1138
+ selectIdentifier: selectIdentifier3,
1139
+ selectDisplayName: selectDisplayName3
1140
+ });
1141
+ }
1142
+ const target = createDataTypeEngineDataSource({ client });
1143
+ await syncEngine({
1144
+ source,
1145
+ target,
1146
+ mode,
1147
+ whatIf,
1148
+ log: createSyncEngineConsoleLogger({ diffMode })
1149
+ });
1150
+ }
1151
+ };
1152
+
1153
+ // src/commands/canvas/commands/dataType/remove.ts
1154
+ import { DataTypeClient as DataTypeClient5 } from "@uniformdev/canvas";
1155
+ var DataTypeRemoveModule = {
1156
+ command: "remove <id>",
1157
+ aliases: ["delete", "rm"],
1158
+ describe: "Delete a data type",
1159
+ builder: (yargs18) => withApiOptions(
1160
+ withProjectOptions(
1161
+ yargs18.positional("id", { demandOption: true, describe: "Data type public ID to delete" })
1162
+ )
1163
+ ),
1164
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
1165
+ const fetch3 = nodeFetchProxy(proxy);
1166
+ const client = new DataTypeClient5({ apiKey, apiHost, fetch: fetch3, projectId, bypassCache: true });
1167
+ await client.remove({ typeId: id });
1168
+ }
1169
+ };
1170
+
1171
+ // src/commands/canvas/commands/dataType/update.ts
1172
+ import { DataTypeClient as DataTypeClient6 } from "@uniformdev/canvas";
1173
+ var DataTypeUpdateModule = {
1174
+ command: "update <filename>",
1175
+ aliases: ["put"],
1176
+ describe: "Insert or update a data type",
1177
+ builder: (yargs18) => withApiOptions(
1178
+ withProjectOptions(
1179
+ yargs18.positional("filename", { demandOption: true, describe: "Data type file to put" })
1180
+ )
1181
+ ),
1182
+ handler: async ({ apiHost, apiKey, proxy, filename, project: projectId }) => {
1183
+ const fetch3 = nodeFetchProxy(proxy);
1184
+ const client = new DataTypeClient6({ apiKey, apiHost, fetch: fetch3, projectId, bypassCache: true });
1185
+ const file = readFileToObject(filename);
1186
+ await client.upsert({ data: file });
1187
+ }
1188
+ };
1189
+
1190
+ // src/commands/canvas/commands/dataType.ts
1191
+ var DataTypeModule = {
1192
+ command: "datatype <command>",
1193
+ aliases: ["dt"],
1194
+ describe: "Commands for Data Type definitions",
1195
+ builder: (yargs18) => yargs18.command(DataTypeGetModule).command(DataTypePullModule).command(DataTypePushModule).command(DataTypeRemoveModule).command(DataTypeListModule).command(DataTypeUpdateModule).demandCommand(),
1196
+ handler: () => {
1197
+ yargs3.help();
1198
+ }
1199
+ };
1200
+
1201
+ // src/commands/canvas/index.ts
1202
+ var CanvasCommand = {
1203
+ command: "canvas <command>",
1204
+ aliases: ["cv", "pm", "presentation"],
1205
+ describe: "Uniform Canvas commands",
1206
+ builder: (yargs18) => yargs18.command(CompositionModule).command(ComponentModule).command(DataTypeModule).demandCommand(),
1207
+ handler: () => {
1208
+ yargs4.showHelp();
1209
+ }
1210
+ };
1211
+
1212
+ // src/commands/context/index.ts
1213
+ import yargs11 from "yargs";
1214
+
1215
+ // src/commands/context/commands/aggregate.ts
1216
+ import yargs5 from "yargs";
1217
+
1218
+ // src/commands/context/commands/aggregate/get.ts
1219
+ import { UncachedAggregateClient } from "@uniformdev/context/api";
1220
+ var AggregateGetModule = {
1221
+ command: "get <id>",
1222
+ describe: "Fetch an aggregate",
1223
+ builder: (yargs18) => withFormatOptions(
1224
+ withApiOptions(
1225
+ withProjectOptions(
1226
+ yargs18.positional("id", { demandOption: true, describe: "Aggregate public ID to fetch" })
1227
+ )
1228
+ )
1229
+ ),
1230
+ handler: async ({ apiHost, apiKey, proxy, id, format, project: projectId, filename }) => {
1231
+ const fetch3 = nodeFetchProxy(proxy);
1232
+ const client = new UncachedAggregateClient({ apiKey, apiHost, fetch: fetch3, projectId });
1233
+ const res = await client.get({ aggregateId: id });
1234
+ if (res.aggregates.length === 0) {
1235
+ console.error("Aggregate did not exist");
1236
+ process.exit(1);
1237
+ } else {
1238
+ emitWithFormat(res.aggregates[0], format, filename);
1239
+ }
1240
+ }
1241
+ };
1242
+
1243
+ // src/commands/context/commands/aggregate/list.ts
1244
+ import { UncachedAggregateClient as UncachedAggregateClient2 } from "@uniformdev/context/api";
1245
+ var AggregateListModule = {
1246
+ command: "list",
1247
+ describe: "List aggregates",
1248
+ aliases: ["ls"],
1249
+ builder: (yargs18) => withFormatOptions(withApiOptions(withProjectOptions(yargs18))),
1250
+ handler: async ({ apiHost, apiKey, proxy, format, filename, project: projectId }) => {
1251
+ const fetch3 = nodeFetchProxy(proxy);
1252
+ const client = new UncachedAggregateClient2({ apiKey, apiHost, fetch: fetch3, projectId });
1253
+ const res = await client.get({});
1254
+ emitWithFormat(res.aggregates, format, filename);
1255
+ }
1256
+ };
1257
+
1258
+ // src/commands/context/commands/aggregate/pull.ts
1259
+ import { UncachedAggregateClient as UncachedAggregateClient3 } from "@uniformdev/context/api";
1260
+
1261
+ // src/commands/context/commands/aggregate/_util.ts
1262
+ var selectIdentifier4 = (source) => source.id;
1263
+ var selectDisplayName4 = (source) => `${source.name} (pid: ${source.id})`;
1264
+
1265
+ // src/commands/context/aggregateEngineDataSource.ts
1266
+ function createAggregateEngineDataSource({
1267
+ client,
1268
+ type
1269
+ }) {
1270
+ async function* getObjects() {
1271
+ const aggregates = (await client.get({ type })).aggregates;
1272
+ for await (const def of aggregates) {
1273
+ const result = {
1274
+ id: selectIdentifier4(def),
1275
+ displayName: selectDisplayName4(def),
1276
+ providerId: def.id,
1277
+ object: def
1278
+ };
1279
+ yield result;
1280
+ }
1281
+ }
1282
+ const writtenObjects = [];
1283
+ return {
1284
+ objects: getObjects(),
1285
+ deleteObject: async (providerId) => {
1286
+ await client.remove({ aggregateId: providerId });
1287
+ },
1288
+ writeObject: async (object) => {
1289
+ await client.upsert({
1290
+ aggregate: object.object,
1291
+ skipInputs: true
1292
+ });
1293
+ writtenObjects.push(object.object);
1294
+ },
1295
+ complete: async () => {
1296
+ await Promise.all(
1297
+ writtenObjects.map((object) => client.upsert({ aggregate: object, skipInputs: false }))
1298
+ );
1299
+ }
1300
+ };
1301
+ }
1302
+
1303
+ // src/commands/context/package.ts
1304
+ function readContextPackage(filename, assertExists) {
1305
+ return readUniformPackage(filename, assertExists);
1306
+ }
1307
+ function writeContextPackage(filename, packageContents) {
1308
+ writeUniformPackage(filename, packageContents);
1309
+ }
1310
+
1311
+ // src/commands/context/util.ts
1312
+ var limitPolicy2 = pLimit(8);
1313
+
1314
+ // src/commands/context/commands/aggregate/pull.ts
1315
+ var AggregatePullModule = {
1316
+ command: "pull <directory>",
1317
+ describe: "Pulls all aggregates to local files in a directory",
1318
+ builder: (yargs18) => withApiOptions(
1319
+ withProjectOptions(
1320
+ withDiffOptions(
1321
+ yargs18.positional("directory", {
1322
+ describe: "Directory to save the aggregates to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
1323
+ type: "string"
1324
+ }).option("format", {
1325
+ alias: ["f"],
1326
+ describe: "Output format",
1327
+ default: "yaml",
1328
+ choices: ["yaml", "json"],
1329
+ type: "string"
1330
+ }).option("what-if", {
1331
+ alias: ["w"],
1332
+ describe: "What-if mode reports what would be done but changes no files",
1333
+ default: false,
1334
+ type: "boolean"
1335
+ }).option("mode", {
1336
+ alias: ["m"],
1337
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
1338
+ choices: ["create", "createOrUpdate", "mirror"],
1339
+ default: "mirror",
1340
+ type: "string"
1341
+ })
1342
+ )
1343
+ )
1344
+ ),
1345
+ handler: async ({
1346
+ apiHost,
1347
+ apiKey,
1348
+ proxy,
1349
+ directory,
1350
+ format,
1351
+ mode,
1352
+ whatIf,
1353
+ project: projectId,
1354
+ diff: diffMode
1355
+ }) => {
1356
+ var _a;
1357
+ const fetch3 = nodeFetchProxy(proxy);
1358
+ const client = new UncachedAggregateClient3({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
1359
+ const source = createAggregateEngineDataSource({ client });
1360
+ let target;
1361
+ const isPackage = isPathAPackageFile(directory);
1362
+ if (isPackage) {
1363
+ const packageContents = readContextPackage(directory, false);
1364
+ target = await createArraySyncEngineDataSource({
1365
+ objects: (_a = packageContents.aggregates) != null ? _a : [],
1366
+ selectIdentifier: selectIdentifier4,
1367
+ selectDisplayName: selectDisplayName4,
1368
+ onSyncComplete: async (_, synced) => {
1369
+ packageContents.aggregates = synced;
1370
+ writeContextPackage(directory, packageContents);
1371
+ }
1372
+ });
1373
+ } else {
1374
+ target = await createFileSyncEngineDataSource({
1375
+ directory,
1376
+ selectIdentifier: selectIdentifier4,
1377
+ selectDisplayName: selectDisplayName4,
1378
+ format
1379
+ });
1380
+ }
1381
+ await syncEngine({
1382
+ source,
1383
+ target,
1384
+ mode,
1385
+ whatIf,
1386
+ log: createSyncEngineConsoleLogger({ diffMode })
1387
+ });
1388
+ }
1389
+ };
1390
+
1391
+ // src/commands/context/commands/aggregate/push.ts
1392
+ import { UncachedAggregateClient as UncachedAggregateClient4 } from "@uniformdev/context/api";
1393
+ var AggregatePushModule = {
1394
+ command: "push <directory>",
1395
+ describe: "Pushes all aggregates from files in a directory or package to Uniform",
1396
+ builder: (yargs18) => withApiOptions(
1397
+ withProjectOptions(
1398
+ withDiffOptions(
1399
+ yargs18.positional("directory", {
1400
+ describe: "Directory to read the aggregates from. If a filename is used, a package will be read instead.",
1401
+ type: "string"
1402
+ }).option("what-if", {
1403
+ alias: ["w"],
1404
+ describe: "What-if mode reports what would be done but changes nothing",
1405
+ default: false,
1406
+ type: "boolean"
1407
+ }).option("mode", {
1408
+ alias: ["m"],
1409
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
1410
+ choices: ["create", "createOrUpdate", "mirror"],
1411
+ default: "mirror",
1412
+ type: "string"
1413
+ })
1414
+ )
1415
+ )
1416
+ ),
1417
+ handler: async ({
1418
+ apiHost,
1419
+ apiKey,
1420
+ proxy,
1421
+ directory,
1422
+ mode,
1423
+ whatIf,
1424
+ project: projectId,
1425
+ diff: diffMode
1426
+ }) => {
1427
+ var _a;
1428
+ const fetch3 = nodeFetchProxy(proxy);
1429
+ const client = new UncachedAggregateClient4({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
1430
+ let source;
1431
+ const isPackage = isPathAPackageFile(directory);
1432
+ if (isPackage) {
1433
+ const packageContents = readContextPackage(directory, true);
1434
+ source = await createArraySyncEngineDataSource({
1435
+ objects: (_a = packageContents.aggregates) != null ? _a : [],
1436
+ selectIdentifier: selectIdentifier4,
1437
+ selectDisplayName: selectDisplayName4
1438
+ });
1439
+ } else {
1440
+ source = await createFileSyncEngineDataSource({
1441
+ directory,
1442
+ selectIdentifier: selectIdentifier4,
1443
+ selectDisplayName: selectDisplayName4
1444
+ });
1445
+ }
1446
+ const target = createAggregateEngineDataSource({ client });
1447
+ await syncEngine({
1448
+ source,
1449
+ target,
1450
+ mode,
1451
+ whatIf,
1452
+ log: createSyncEngineConsoleLogger({ diffMode })
1453
+ });
1454
+ await target.complete();
1455
+ }
1456
+ };
1457
+
1458
+ // src/commands/context/commands/aggregate/remove.ts
1459
+ import { UncachedAggregateClient as UncachedAggregateClient5 } from "@uniformdev/context/api";
1460
+ var AggregateRemoveModule = {
1461
+ command: "remove <id>",
1462
+ aliases: ["delete", "rm"],
1463
+ describe: "Delete an aggregate",
1464
+ builder: (yargs18) => withApiOptions(
1465
+ withProjectOptions(
1466
+ yargs18.positional("id", { demandOption: true, describe: "Aggregate public ID to delete" })
1467
+ )
1468
+ ),
1469
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
1470
+ const fetch3 = nodeFetchProxy(proxy);
1471
+ const client = new UncachedAggregateClient5({ apiKey, apiHost, fetch: fetch3, projectId });
1472
+ await client.remove({ aggregateId: id });
1473
+ }
1474
+ };
1475
+
1476
+ // src/commands/context/commands/aggregate/update.ts
1477
+ import { UncachedAggregateClient as UncachedAggregateClient6 } from "@uniformdev/context/api";
1478
+ var AggregateUpdateModule = {
1479
+ command: "update <filename>",
1480
+ aliases: ["put"],
1481
+ describe: "Insert or update an aggregate",
1482
+ builder: (yargs18) => withApiOptions(
1483
+ withProjectOptions(
1484
+ yargs18.positional("filename", { demandOption: true, describe: "Aggregate file to put" })
1485
+ )
1486
+ ),
1487
+ handler: async ({ apiHost, apiKey, proxy, filename, project: projectId }) => {
1488
+ const fetch3 = nodeFetchProxy(proxy);
1489
+ const client = new UncachedAggregateClient6({ apiKey, apiHost, fetch: fetch3, projectId });
1490
+ const file = readFileToObject(filename);
1491
+ await client.upsert({ aggregate: file });
1492
+ }
1493
+ };
1494
+
1495
+ // src/commands/context/commands/aggregate.ts
1496
+ var AggregateModule = {
1497
+ command: "aggregate <command>",
1498
+ aliases: ["agg", "intent", "audience"],
1499
+ describe: "Commands for Context aggregates (intents, audiences)",
1500
+ builder: (yargs18) => yargs18.command(AggregatePullModule).command(AggregatePushModule).command(AggregateGetModule).command(AggregateRemoveModule).command(AggregateListModule).command(AggregateUpdateModule).demandCommand(),
1501
+ handler: () => {
1502
+ yargs5.help();
1503
+ }
1504
+ };
1505
+
1506
+ // src/commands/context/commands/enrichment.ts
1507
+ import yargs6 from "yargs";
1508
+
1509
+ // src/commands/context/commands/enrichment/get.ts
1510
+ import { UncachedEnrichmentClient } from "@uniformdev/context/api";
1511
+ var EnrichmentGetModule = {
1512
+ command: "get <id>",
1513
+ describe: "Fetch an enrichment category and its values",
1514
+ builder: (yargs18) => withFormatOptions(
1515
+ withApiOptions(
1516
+ withProjectOptions(
1517
+ yargs18.positional("id", { demandOption: true, describe: "Enrichment category public ID to fetch" })
1518
+ )
1519
+ )
1520
+ ),
1521
+ handler: async ({ apiHost, apiKey, proxy, id, format, project: projectId, filename }) => {
1522
+ var _a, _b;
1523
+ const fetch3 = nodeFetchProxy(proxy);
1524
+ const client = new UncachedEnrichmentClient({ apiKey, apiHost, fetch: fetch3, projectId });
1525
+ const res = (_b = (_a = await client.get()) == null ? void 0 : _a.enrichments) == null ? void 0 : _b.filter((enr) => enr.id === id);
1526
+ if (res.length === 0) {
1527
+ console.error("Enrichment did not exist");
1528
+ process.exit(1);
1529
+ } else {
1530
+ emitWithFormat(res[0], format, filename);
1531
+ }
1532
+ }
1533
+ };
1534
+
1535
+ // src/commands/context/commands/enrichment/list.ts
1536
+ import { UncachedEnrichmentClient as UncachedEnrichmentClient2 } from "@uniformdev/context/api";
1537
+ var EnrichmentListModule = {
1538
+ command: "list",
1539
+ describe: "List enrichments",
1540
+ aliases: ["ls"],
1541
+ builder: (yargs18) => withFormatOptions(withApiOptions(withProjectOptions(yargs18))),
1542
+ handler: async ({ apiHost, apiKey, proxy, format, filename, project: projectId }) => {
1543
+ const fetch3 = nodeFetchProxy(proxy);
1544
+ const client = new UncachedEnrichmentClient2({ apiKey, apiHost, fetch: fetch3, projectId });
1545
+ const res = await client.get();
1546
+ emitWithFormat(res.enrichments, format, filename);
1547
+ }
1548
+ };
1549
+
1550
+ // src/commands/context/commands/enrichment/pull.ts
1551
+ import { UncachedEnrichmentClient as UncachedEnrichmentClient3 } from "@uniformdev/context/api";
1552
+
1553
+ // src/commands/context/commands/enrichment/_util.ts
1554
+ var selectIdentifier5 = (source) => source.id;
1555
+ var selectDisplayName5 = (source) => `${source.name} (pid: ${source.id})`;
1556
+
1557
+ // src/commands/context/enrichmentEngineDataSource.ts
1558
+ function createEnrichmentEngineDataSource({
1559
+ client
1560
+ }) {
1561
+ async function* getObjects() {
1562
+ const enrichments = (await client.get()).enrichments;
1563
+ for await (const def of enrichments) {
1564
+ const result = {
1565
+ id: selectIdentifier5(def),
1566
+ displayName: selectDisplayName5(def),
1567
+ providerId: def.id,
1568
+ object: def
1569
+ };
1570
+ yield result;
1571
+ }
1572
+ }
1573
+ return {
1574
+ objects: getObjects(),
1575
+ deleteObject: async (providerId) => {
1576
+ await client.removeCategory({ enrichmentId: providerId });
1577
+ },
1578
+ writeObject: async (object, existingObject) => {
1579
+ var _a, _b;
1580
+ await client.upsertCategory({
1581
+ enrichment: object.object
1582
+ });
1583
+ const source = createEnrichmentValueEngineDataSource({
1584
+ categoryId: object.id,
1585
+ values: object.object.values
1586
+ });
1587
+ const target = createEnrichmentValueEngineDataSource({
1588
+ categoryId: object.id,
1589
+ values: (_b = (_a = existingObject == null ? void 0 : existingObject.object) == null ? void 0 : _a.values) != null ? _b : [],
1590
+ client
1591
+ });
1592
+ await syncEngine({
1593
+ source,
1594
+ target,
1595
+ mode: "mirror",
1596
+ whatIf: false,
1597
+ log: createSyncEngineConsoleLogger({
1598
+ diffMode: "off",
1599
+ prefix: ` ${object.displayName} value`,
1600
+ indent: "> "
1601
+ })
1602
+ });
1603
+ }
1604
+ };
1605
+ }
1606
+ var createEnrichmentValueEngineDataSource = ({
1607
+ client,
1608
+ categoryId,
1609
+ values
1610
+ }) => {
1611
+ const iterator = async function* () {
1612
+ for (const value of values) {
1613
+ yield {
1614
+ id: value.id,
1615
+ providerId: value.id,
1616
+ object: value,
1617
+ displayName: `${value.value} (pid: ${value.id})`
1618
+ };
1619
+ }
1620
+ };
1621
+ return {
1622
+ objects: iterator(),
1623
+ deleteObject: async (providerId) => {
1624
+ if (!client) {
1625
+ throw new Error("Provider is read only");
1626
+ }
1627
+ await client.removeValue({ enrichmentId: categoryId, enrichmentValueId: providerId });
1628
+ },
1629
+ writeObject: async (object) => {
1630
+ if (!client) {
1631
+ throw new Error("Provider is read only");
1632
+ }
1633
+ await client.upsertValue({ enrichmentId: categoryId, enrichmentValue: object.object });
1634
+ }
1635
+ };
1636
+ };
1637
+
1638
+ // src/commands/context/commands/enrichment/pull.ts
1639
+ var EnrichmentPullModule = {
1640
+ command: "pull <directory>",
1641
+ describe: "Pulls all enrichments to local files in a directory",
1642
+ builder: (yargs18) => withApiOptions(
1643
+ withProjectOptions(
1644
+ withDiffOptions(
1645
+ yargs18.positional("directory", {
1646
+ describe: "Directory to save the enrichments to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
1647
+ type: "string"
1648
+ }).option("format", {
1649
+ alias: ["f"],
1650
+ describe: "Output format",
1651
+ default: "yaml",
1652
+ choices: ["yaml", "json"],
1653
+ type: "string"
1654
+ }).option("what-if", {
1655
+ alias: ["w"],
1656
+ describe: "What-if mode reports what would be done but changes no files",
1657
+ default: false,
1658
+ type: "boolean"
1659
+ }).option("mode", {
1660
+ alias: ["m"],
1661
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
1662
+ choices: ["create", "createOrUpdate", "mirror"],
1663
+ default: "mirror",
1664
+ type: "string"
1665
+ })
1666
+ )
1667
+ )
1668
+ ),
1669
+ handler: async ({
1670
+ apiHost,
1671
+ apiKey,
1672
+ proxy,
1673
+ directory,
1674
+ format,
1675
+ mode,
1676
+ whatIf,
1677
+ project: projectId,
1678
+ diff: diffMode
1679
+ }) => {
1680
+ var _a;
1681
+ const fetch3 = nodeFetchProxy(proxy);
1682
+ const client = new UncachedEnrichmentClient3({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
1683
+ const source = createEnrichmentEngineDataSource({ client });
1684
+ let target;
1685
+ const isPackage = isPathAPackageFile(directory);
1686
+ if (isPackage) {
1687
+ const packageContents = readContextPackage(directory, false);
1688
+ target = await createArraySyncEngineDataSource({
1689
+ objects: (_a = packageContents.enrichments) != null ? _a : [],
1690
+ selectIdentifier: selectIdentifier5,
1691
+ selectDisplayName: selectDisplayName5,
1692
+ onSyncComplete: async (_, synced) => {
1693
+ packageContents.enrichments = synced;
1694
+ writeContextPackage(directory, packageContents);
1695
+ }
1696
+ });
1697
+ } else {
1698
+ target = await createFileSyncEngineDataSource({
1699
+ directory,
1700
+ selectIdentifier: selectIdentifier5,
1701
+ selectDisplayName: selectDisplayName5,
1702
+ format
1703
+ });
1704
+ }
1705
+ await syncEngine({
1706
+ source,
1707
+ target,
1708
+ mode,
1709
+ whatIf,
1710
+ log: createSyncEngineConsoleLogger({ diffMode })
1711
+ });
1712
+ }
1713
+ };
1714
+
1715
+ // src/commands/context/commands/enrichment/push.ts
1716
+ import { UncachedEnrichmentClient as UncachedEnrichmentClient4 } from "@uniformdev/context/api";
1717
+ var EnrichmentPushModule = {
1718
+ command: "push <directory>",
1719
+ describe: "Pushes all enrichments from files in a directory or package to Uniform",
1720
+ builder: (yargs18) => withApiOptions(
1721
+ withProjectOptions(
1722
+ withDiffOptions(
1723
+ yargs18.positional("directory", {
1724
+ describe: "Directory to read the enrichments from. If a filename is used, a package will be read instead.",
1725
+ type: "string"
1726
+ }).option("what-if", {
1727
+ alias: ["w"],
1728
+ describe: "What-if mode reports what would be done but changes nothing",
1729
+ default: false,
1730
+ type: "boolean"
1731
+ }).option("mode", {
1732
+ alias: ["m"],
1733
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
1734
+ choices: ["create", "createOrUpdate", "mirror"],
1735
+ default: "mirror",
1736
+ type: "string"
1737
+ })
1738
+ )
1739
+ )
1740
+ ),
1741
+ handler: async ({
1742
+ apiHost,
1743
+ apiKey,
1744
+ proxy,
1745
+ directory,
1746
+ mode,
1747
+ whatIf,
1748
+ project: projectId,
1749
+ diff: diffMode
1750
+ }) => {
1751
+ var _a;
1752
+ const fetch3 = nodeFetchProxy(proxy);
1753
+ const client = new UncachedEnrichmentClient4({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
1754
+ let source;
1755
+ const isPackage = isPathAPackageFile(directory);
1756
+ if (isPackage) {
1757
+ const packageContents = readContextPackage(directory, true);
1758
+ source = await createArraySyncEngineDataSource({
1759
+ objects: (_a = packageContents.enrichments) != null ? _a : [],
1760
+ selectIdentifier: selectIdentifier5,
1761
+ selectDisplayName: selectDisplayName5
1762
+ });
1763
+ } else {
1764
+ source = await createFileSyncEngineDataSource({
1765
+ directory,
1766
+ selectIdentifier: selectIdentifier5,
1767
+ selectDisplayName: selectDisplayName5
1768
+ });
1769
+ }
1770
+ const target = createEnrichmentEngineDataSource({ client });
1771
+ await syncEngine({
1772
+ source,
1773
+ target,
1774
+ mode,
1775
+ whatIf,
1776
+ log: createSyncEngineConsoleLogger({ diffMode })
1777
+ });
1778
+ }
1779
+ };
1780
+
1781
+ // src/commands/context/commands/enrichment/remove.ts
1782
+ import { UncachedEnrichmentClient as UncachedEnrichmentClient5 } from "@uniformdev/context/api";
1783
+ var EnrichmentRemoveModule = {
1784
+ command: "remove <id>",
1785
+ aliases: ["delete", "rm"],
1786
+ describe: "Delete an enrichment category and its values",
1787
+ builder: (yargs18) => withApiOptions(
1788
+ withProjectOptions(
1789
+ yargs18.positional("id", { demandOption: true, describe: "Enrichment category public ID to delete" })
1790
+ )
1791
+ ),
1792
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
1793
+ const fetch3 = nodeFetchProxy(proxy);
1794
+ const client = new UncachedEnrichmentClient5({ apiKey, apiHost, fetch: fetch3, projectId });
1795
+ await client.removeCategory({ enrichmentId: id });
1796
+ }
1797
+ };
1798
+
1799
+ // src/commands/context/commands/enrichment.ts
1800
+ var EnrichmentModule = {
1801
+ command: "enrichment <command>",
1802
+ aliases: ["enr"],
1803
+ describe: "Commands for Context enrichments",
1804
+ builder: (yargs18) => yargs18.command(EnrichmentPullModule).command(EnrichmentPushModule).command(EnrichmentGetModule).command(EnrichmentRemoveModule).command(EnrichmentListModule).demandCommand(),
1805
+ handler: () => {
1806
+ yargs6.help();
1807
+ }
1808
+ };
1809
+
1810
+ // src/commands/context/commands/manifest.ts
1811
+ import yargs7 from "yargs";
1812
+
1813
+ // src/commands/context/commands/manifest/get.ts
1814
+ var import_chalk = __toESM(require_source());
1815
+ import { ApiClientError, UncachedManifestClient } from "@uniformdev/context/api";
1816
+ import { writeFile } from "fs";
1817
+ import { exit } from "process";
1818
+ var ManifestGetModule = {
1819
+ command: "get [output]",
1820
+ aliases: ["dl", "download"],
1821
+ describe: "Download the Uniform Context manifest for a project",
1822
+ builder: (yargs18) => withApiOptions(
1823
+ withProjectOptions(
1824
+ yargs18.option("preview", {
1825
+ describe: "If set, fetches the unpublished preview manifest (The API key must have permission)",
1826
+ default: false,
1827
+ type: "boolean",
1828
+ alias: ["d"]
1829
+ }).option("output", {
1830
+ string: true,
1831
+ alias: "o",
1832
+ default: process.env.UNIFORM_MANIFEST_PATH,
1833
+ describe: "Path to write manifest to. Defaults to UNIFORM_MANIFEST_PATH env if set.",
1834
+ demandOption: true
1835
+ })
1836
+ )
1837
+ ),
1838
+ handler: async ({ apiKey, apiHost, proxy, output, project, preview }) => {
1839
+ const fetch3 = nodeFetchProxy(proxy);
1840
+ const client = new UncachedManifestClient({
1841
+ apiHost,
1842
+ projectId: project,
1843
+ apiKey,
1844
+ fetch: fetch3
1845
+ });
1846
+ try {
1847
+ const manifest = await client.get({ preview });
1848
+ const text = JSON.stringify(manifest, null, 2);
1849
+ if (output) {
1850
+ writeFile(output, text, (error) => {
1851
+ if (error) {
1852
+ console.error(`Error writing file to ${output}
1853
+ `, error);
1854
+ exit(1);
1855
+ }
1856
+ console.log(import_chalk.default.green(`\u2705 ${output} has been updated from ${apiHost}`));
1857
+ });
1858
+ } else {
1859
+ console.log(text);
1860
+ }
1861
+ } catch (e) {
1862
+ let message;
1863
+ if (e instanceof ApiClientError) {
1864
+ if (e.statusCode === 403) {
1865
+ message = `The API key ${apiKey} did not have permissions to fetch the manifest. Ensure ${preview ? "Uniform Context > Read Drafts" : "Uniform Context > Manifest > Read"} permissions are granted.`;
1866
+ }
1867
+ message = e.message;
1868
+ } else {
1869
+ message = e.toString();
1870
+ }
1871
+ console.error(import_chalk.default.red(`\u26A0 Error fetching Context manifest`));
1872
+ console.error(import_chalk.default.gray(` \u2757 ${message}`));
1873
+ exit(1);
1874
+ }
1875
+ }
1876
+ };
1877
+
1878
+ // src/commands/context/commands/manifest/publish.ts
1879
+ var import_chalk2 = __toESM(require_source());
1880
+ import { ApiClientError as ApiClientError2, UncachedManifestClient as UncachedManifestClient2 } from "@uniformdev/context/api";
1881
+ import { exit as exit2 } from "process";
1882
+ var ManifestPublishModule = {
1883
+ command: "publish",
1884
+ describe: "Publish the Uniform Context manifest for a project",
1885
+ builder: (yargs18) => withApiOptions(withProjectOptions(yargs18)),
1886
+ handler: async ({ apiKey, apiHost, proxy, project }) => {
1887
+ const fetch3 = nodeFetchProxy(proxy);
1888
+ try {
1889
+ const client = new UncachedManifestClient2({
1890
+ apiHost,
1891
+ projectId: project,
1892
+ apiKey,
1893
+ fetch: fetch3
1894
+ });
1895
+ await client.publish();
1896
+ } catch (e) {
1897
+ let message;
1898
+ if (e instanceof ApiClientError2) {
1899
+ if (e.statusCode === 403) {
1900
+ message = `The API key ${apiKey} did not have permissions to publish the manifest. Ensure Uniform Context > Manifest > Publish permissions are granted.`;
1901
+ }
1902
+ message = e.message;
1903
+ } else {
1904
+ message = e.toString();
1905
+ }
1906
+ console.error(import_chalk2.default.red(`\u26A0 Error publishing Context manifest`));
1907
+ console.error(import_chalk2.default.gray(` \u2757 ${message}`));
1908
+ exit2(1);
1909
+ }
1910
+ }
1911
+ };
1912
+
1913
+ // src/commands/context/commands/manifest.ts
1914
+ var ManifestModule = {
1915
+ command: "manifest <command>",
1916
+ describe: "Commands for context manifests",
1917
+ aliases: ["man"],
1918
+ builder: (yargs18) => yargs18.command(ManifestGetModule).command(ManifestPublishModule).demandCommand(),
1919
+ handler: () => {
1920
+ yargs7.help();
1921
+ }
1922
+ };
1923
+
1924
+ // src/commands/context/commands/quirk.ts
1925
+ import yargs8 from "yargs";
1926
+
1927
+ // src/commands/context/commands/quirk/get.ts
1928
+ import { UncachedQuirkClient } from "@uniformdev/context/api";
1929
+ var QuirkGetModule = {
1930
+ command: "get <id>",
1931
+ describe: "Fetch a quirk",
1932
+ builder: (yargs18) => withFormatOptions(
1933
+ withApiOptions(
1934
+ withProjectOptions(
1935
+ yargs18.positional("id", { demandOption: true, describe: "Quirk public ID to fetch" })
1936
+ )
1937
+ )
1938
+ ),
1939
+ handler: async ({ apiHost, apiKey, proxy, id, format, project: projectId, filename }) => {
1940
+ const fetch3 = nodeFetchProxy(proxy);
1941
+ const client = new UncachedQuirkClient({ apiKey, apiHost, fetch: fetch3, projectId });
1942
+ const res = await client.get({ quirkId: id, withIntegrations: true });
1943
+ if (res.quirks.length === 0) {
1944
+ console.error("Quirk did not exist");
1945
+ process.exit(1);
1946
+ } else {
1947
+ emitWithFormat(res.quirks[0], format, filename);
1948
+ }
1949
+ }
1950
+ };
1951
+
1952
+ // src/commands/context/commands/quirk/list.ts
1953
+ import { UncachedQuirkClient as UncachedQuirkClient2 } from "@uniformdev/context/api";
1954
+ var QuirkListModule = {
1955
+ command: "list",
1956
+ describe: "List quirks",
1957
+ aliases: ["ls"],
1958
+ builder: (yargs18) => withFormatOptions(
1959
+ withApiOptions(
1960
+ withProjectOptions(
1961
+ yargs18.option("withIntegrations", {
1962
+ alias: ["i"],
1963
+ describe: "Whether to include meta-quirks created by integrations in the list. Defaults to false.",
1964
+ type: "boolean"
1965
+ })
1966
+ )
1967
+ )
1968
+ ),
1969
+ handler: async ({ apiHost, apiKey, proxy, format, filename, project: projectId, withIntegrations }) => {
1970
+ const fetch3 = nodeFetchProxy(proxy);
1971
+ const client = new UncachedQuirkClient2({ apiKey, apiHost, fetch: fetch3, projectId });
1972
+ const res = await client.get({ withIntegrations });
1973
+ emitWithFormat(res.quirks, format, filename);
1974
+ }
1975
+ };
1976
+
1977
+ // src/commands/context/commands/quirk/pull.ts
1978
+ import { UncachedQuirkClient as UncachedQuirkClient3 } from "@uniformdev/context/api";
1979
+
1980
+ // src/commands/context/commands/quirk/_util.ts
1981
+ var selectIdentifier6 = (source) => source.id;
1982
+ var selectDisplayName6 = (source) => `${source.name} (pid: ${source.id})`;
1983
+
1984
+ // src/commands/context/quirkEngineDataSource.ts
1985
+ function createQuirkEngineDataSource({
1986
+ client
1987
+ }) {
1988
+ async function* getObjects() {
1989
+ const quirks = (await client.get({ withIntegrations: false })).quirks;
1990
+ for await (const def of quirks) {
1991
+ const result = {
1992
+ id: selectIdentifier6(def),
1993
+ displayName: selectDisplayName6(def),
1994
+ providerId: def.id,
1995
+ object: def
1996
+ };
1997
+ yield result;
1998
+ }
1999
+ }
2000
+ return {
2001
+ objects: getObjects(),
2002
+ deleteObject: async (providerId) => {
2003
+ await client.remove({ quirkId: providerId });
2004
+ },
2005
+ writeObject: async (object) => {
2006
+ await client.upsert({
2007
+ quirk: object.object
2008
+ });
2009
+ }
2010
+ };
2011
+ }
2012
+
2013
+ // src/commands/context/commands/quirk/pull.ts
2014
+ var QuirkPullModule = {
2015
+ command: "pull <directory>",
2016
+ describe: "Pulls all quirks to local files in a directory",
2017
+ builder: (yargs18) => withApiOptions(
2018
+ withProjectOptions(
2019
+ withDiffOptions(
2020
+ yargs18.positional("directory", {
2021
+ describe: "Directory to save the quirks to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
2022
+ type: "string"
2023
+ }).option("format", {
2024
+ alias: ["f"],
2025
+ describe: "Output format",
2026
+ default: "yaml",
2027
+ choices: ["yaml", "json"],
2028
+ type: "string"
2029
+ }).option("what-if", {
2030
+ alias: ["w"],
2031
+ describe: "What-if mode reports what would be done but changes no files",
2032
+ default: false,
2033
+ type: "boolean"
2034
+ }).option("mode", {
2035
+ alias: ["m"],
2036
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
2037
+ choices: ["create", "createOrUpdate", "mirror"],
2038
+ default: "mirror",
2039
+ type: "string"
2040
+ })
2041
+ )
2042
+ )
2043
+ ),
2044
+ handler: async ({
2045
+ apiHost,
2046
+ apiKey,
2047
+ proxy,
2048
+ directory,
2049
+ format,
2050
+ mode,
2051
+ whatIf,
2052
+ project: projectId,
2053
+ diff: diffMode
2054
+ }) => {
2055
+ var _a;
2056
+ const fetch3 = nodeFetchProxy(proxy);
2057
+ const client = new UncachedQuirkClient3({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
2058
+ const source = createQuirkEngineDataSource({ client });
2059
+ let target;
2060
+ const isPackage = isPathAPackageFile(directory);
2061
+ if (isPackage) {
2062
+ const packageContents = readContextPackage(directory, false);
2063
+ target = await createArraySyncEngineDataSource({
2064
+ objects: (_a = packageContents.quirks) != null ? _a : [],
2065
+ selectIdentifier: selectIdentifier6,
2066
+ selectDisplayName: selectDisplayName6,
2067
+ onSyncComplete: async (_, synced) => {
2068
+ packageContents.quirks = synced;
2069
+ writeContextPackage(directory, packageContents);
2070
+ }
2071
+ });
2072
+ } else {
2073
+ target = await createFileSyncEngineDataSource({
2074
+ directory,
2075
+ selectIdentifier: selectIdentifier6,
2076
+ selectDisplayName: selectDisplayName6,
2077
+ format
2078
+ });
2079
+ }
2080
+ await syncEngine({
2081
+ source,
2082
+ target,
2083
+ mode,
2084
+ whatIf,
2085
+ log: createSyncEngineConsoleLogger({ diffMode })
2086
+ });
2087
+ }
2088
+ };
2089
+
2090
+ // src/commands/context/commands/quirk/push.ts
2091
+ import { UncachedQuirkClient as UncachedQuirkClient4 } from "@uniformdev/context/api";
2092
+ var QuirkPushModule = {
2093
+ command: "push <directory>",
2094
+ describe: "Pushes all quirks from files in a directory or package to Uniform",
2095
+ builder: (yargs18) => withApiOptions(
2096
+ withProjectOptions(
2097
+ withDiffOptions(
2098
+ yargs18.positional("directory", {
2099
+ describe: "Directory to read the quirks from. If a filename is used, a package will be read instead.",
2100
+ type: "string"
2101
+ }).option("what-if", {
2102
+ alias: ["w"],
2103
+ describe: "What-if mode reports what would be done but changes nothing",
2104
+ default: false,
2105
+ type: "boolean"
2106
+ }).option("mode", {
2107
+ alias: ["m"],
2108
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
2109
+ choices: ["create", "createOrUpdate", "mirror"],
2110
+ default: "mirror",
2111
+ type: "string"
2112
+ })
2113
+ )
2114
+ )
2115
+ ),
2116
+ handler: async ({
2117
+ apiHost,
2118
+ apiKey,
2119
+ proxy,
2120
+ directory,
2121
+ mode,
2122
+ whatIf,
2123
+ project: projectId,
2124
+ diff: diffMode
2125
+ }) => {
2126
+ var _a;
2127
+ const fetch3 = nodeFetchProxy(proxy);
2128
+ const client = new UncachedQuirkClient4({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
2129
+ let source;
2130
+ const isPackage = isPathAPackageFile(directory);
2131
+ if (isPackage) {
2132
+ const packageContents = readContextPackage(directory, true);
2133
+ source = await createArraySyncEngineDataSource({
2134
+ objects: (_a = packageContents.quirks) != null ? _a : [],
2135
+ selectIdentifier: selectIdentifier6,
2136
+ selectDisplayName: selectDisplayName6
2137
+ });
2138
+ } else {
2139
+ source = await createFileSyncEngineDataSource({
2140
+ directory,
2141
+ selectIdentifier: selectIdentifier6,
2142
+ selectDisplayName: selectDisplayName6
2143
+ });
2144
+ }
2145
+ const target = createQuirkEngineDataSource({ client });
2146
+ await syncEngine({
2147
+ source,
2148
+ target,
2149
+ mode,
2150
+ whatIf,
2151
+ log: createSyncEngineConsoleLogger({ diffMode })
2152
+ });
2153
+ }
2154
+ };
2155
+
2156
+ // src/commands/context/commands/quirk/remove.ts
2157
+ import { UncachedQuirkClient as UncachedQuirkClient5 } from "@uniformdev/context/api";
2158
+ var QuirkRemoveModule = {
2159
+ command: "remove <id>",
2160
+ aliases: ["delete", "rm"],
2161
+ describe: "Delete a quirk",
2162
+ builder: (yargs18) => withApiOptions(
2163
+ withProjectOptions(
2164
+ yargs18.positional("id", { demandOption: true, describe: "Quirk public ID to delete" })
2165
+ )
2166
+ ),
2167
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
2168
+ const fetch3 = nodeFetchProxy(proxy);
2169
+ const client = new UncachedQuirkClient5({ apiKey, apiHost, fetch: fetch3, projectId });
2170
+ await client.remove({ quirkId: id });
2171
+ }
2172
+ };
2173
+
2174
+ // src/commands/context/commands/quirk/update.ts
2175
+ import { UncachedQuirkClient as UncachedQuirkClient6 } from "@uniformdev/context/api";
2176
+ var QuirkUpdateModule = {
2177
+ command: "update <filename>",
2178
+ aliases: ["put"],
2179
+ describe: "Insert or update a quirk",
2180
+ builder: (yargs18) => withApiOptions(
2181
+ withProjectOptions(yargs18.positional("filename", { demandOption: true, describe: "Quirk file to put" }))
2182
+ ),
2183
+ handler: async ({ apiHost, apiKey, proxy, filename, project: projectId }) => {
2184
+ const fetch3 = nodeFetchProxy(proxy);
2185
+ const client = new UncachedQuirkClient6({ apiKey, apiHost, fetch: fetch3, projectId });
2186
+ const file = readFileToObject(filename);
2187
+ await client.upsert({ quirk: file });
2188
+ }
2189
+ };
2190
+
2191
+ // src/commands/context/commands/quirk.ts
2192
+ var QuirkModule = {
2193
+ command: "quirk <command>",
2194
+ aliases: ["qk"],
2195
+ describe: "Commands for Context quirks",
2196
+ builder: (yargs18) => yargs18.command(QuirkPullModule).command(QuirkPushModule).command(QuirkGetModule).command(QuirkRemoveModule).command(QuirkListModule).command(QuirkUpdateModule).demandCommand(),
2197
+ handler: () => {
2198
+ yargs8.help();
2199
+ }
2200
+ };
2201
+
2202
+ // src/commands/context/commands/signal.ts
2203
+ import yargs9 from "yargs";
2204
+
2205
+ // src/commands/context/commands/signal/get.ts
2206
+ import { UncachedSignalClient } from "@uniformdev/context/api";
2207
+ var SignalGetModule = {
2208
+ command: "get <id>",
2209
+ describe: "Fetch a signal",
2210
+ builder: (yargs18) => withFormatOptions(
2211
+ withApiOptions(
2212
+ withProjectOptions(
2213
+ yargs18.positional("id", { demandOption: true, describe: "Signal public ID to fetch" })
2214
+ )
2215
+ )
2216
+ ),
2217
+ handler: async ({ apiHost, apiKey, proxy, id, format, project: projectId, filename }) => {
2218
+ const fetch3 = nodeFetchProxy(proxy);
2219
+ const client = new UncachedSignalClient({ apiKey, apiHost, fetch: fetch3, projectId });
2220
+ const res = await client.get({ signalId: id });
2221
+ if (res.signals.length === 0) {
2222
+ console.error("Signal did not exist");
2223
+ process.exit(1);
2224
+ } else {
2225
+ emitWithFormat(res.signals[0], format, filename);
2226
+ }
2227
+ }
2228
+ };
2229
+
2230
+ // src/commands/context/commands/signal/list.ts
2231
+ import { UncachedSignalClient as UncachedSignalClient2 } from "@uniformdev/context/api";
2232
+ var SignalListModule = {
2233
+ command: "list",
2234
+ describe: "List signals",
2235
+ aliases: ["ls"],
2236
+ builder: (yargs18) => withFormatOptions(withApiOptions(withProjectOptions(yargs18))),
2237
+ handler: async ({ apiHost, apiKey, proxy, format, filename, project: projectId }) => {
2238
+ const fetch3 = nodeFetchProxy(proxy);
2239
+ const client = new UncachedSignalClient2({ apiKey, apiHost, fetch: fetch3, projectId });
2240
+ const res = await client.get();
2241
+ emitWithFormat(res.signals, format, filename);
2242
+ }
2243
+ };
2244
+
2245
+ // src/commands/context/commands/signal/pull.ts
2246
+ import { UncachedSignalClient as UncachedSignalClient3 } from "@uniformdev/context/api";
2247
+
2248
+ // src/commands/context/commands/signal/_util.ts
2249
+ var selectIdentifier7 = (source) => source.id;
2250
+ var selectDisplayName7 = (source) => `${source.name} (pid: ${source.id})`;
2251
+
2252
+ // src/commands/context/signalEngineDataSource.ts
2253
+ function createSignalEngineDataSource({
2254
+ client
2255
+ }) {
2256
+ async function* getObjects() {
2257
+ const signals = (await client.get()).signals;
2258
+ for await (const def of signals) {
2259
+ const result = {
2260
+ id: selectIdentifier7(def),
2261
+ displayName: selectDisplayName7(def),
2262
+ providerId: def.id,
2263
+ object: def
2264
+ };
2265
+ yield result;
2266
+ }
2267
+ }
2268
+ return {
2269
+ objects: getObjects(),
2270
+ deleteObject: async (providerId) => {
2271
+ await client.remove({ signalId: providerId });
2272
+ },
2273
+ writeObject: async (object) => {
2274
+ await client.upsert({
2275
+ signal: object.object
2276
+ });
2277
+ }
2278
+ };
2279
+ }
2280
+
2281
+ // src/commands/context/commands/signal/pull.ts
2282
+ var SignalPullModule = {
2283
+ command: "pull <directory>",
2284
+ describe: "Pulls all signals to local files in a directory",
2285
+ builder: (yargs18) => withApiOptions(
2286
+ withProjectOptions(
2287
+ withDiffOptions(
2288
+ yargs18.positional("directory", {
2289
+ describe: "Directory to save the signals to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
2290
+ type: "string"
2291
+ }).option("format", {
2292
+ alias: ["f"],
2293
+ describe: "Output format",
2294
+ default: "yaml",
2295
+ choices: ["yaml", "json"],
2296
+ type: "string"
2297
+ }).option("what-if", {
2298
+ alias: ["w"],
2299
+ describe: "What-if mode reports what would be done but changes no files",
2300
+ default: false,
2301
+ type: "boolean"
2302
+ }).option("mode", {
2303
+ alias: ["m"],
2304
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
2305
+ choices: ["create", "createOrUpdate", "mirror"],
2306
+ default: "mirror",
2307
+ type: "string"
2308
+ })
2309
+ )
2310
+ )
2311
+ ),
2312
+ handler: async ({
2313
+ apiHost,
2314
+ apiKey,
2315
+ proxy,
2316
+ directory,
2317
+ format,
2318
+ mode,
2319
+ whatIf,
2320
+ project: projectId,
2321
+ diff: diffMode
2322
+ }) => {
2323
+ var _a;
2324
+ const fetch3 = nodeFetchProxy(proxy);
2325
+ const client = new UncachedSignalClient3({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
2326
+ const source = createSignalEngineDataSource({ client });
2327
+ let target;
2328
+ const isPackage = isPathAPackageFile(directory);
2329
+ if (isPackage) {
2330
+ const packageContents = readContextPackage(directory, false);
2331
+ target = await createArraySyncEngineDataSource({
2332
+ objects: (_a = packageContents.signals) != null ? _a : [],
2333
+ selectIdentifier: selectIdentifier7,
2334
+ selectDisplayName: selectDisplayName7,
2335
+ onSyncComplete: async (_, synced) => {
2336
+ packageContents.signals = synced;
2337
+ writeContextPackage(directory, packageContents);
2338
+ }
2339
+ });
2340
+ } else {
2341
+ target = await createFileSyncEngineDataSource({
2342
+ directory,
2343
+ selectIdentifier: selectIdentifier7,
2344
+ selectDisplayName: selectDisplayName7,
2345
+ format
2346
+ });
2347
+ }
2348
+ await syncEngine({
2349
+ source,
2350
+ target,
2351
+ mode,
2352
+ whatIf,
2353
+ log: createSyncEngineConsoleLogger({ diffMode })
2354
+ });
2355
+ }
2356
+ };
2357
+
2358
+ // src/commands/context/commands/signal/push.ts
2359
+ import { UncachedSignalClient as UncachedSignalClient4 } from "@uniformdev/context/api";
2360
+ var SignalPushModule = {
2361
+ command: "push <directory>",
2362
+ describe: "Pushes all signals from files in a directory or package to Uniform",
2363
+ builder: (yargs18) => withApiOptions(
2364
+ withProjectOptions(
2365
+ withDiffOptions(
2366
+ yargs18.positional("directory", {
2367
+ describe: "Directory to read the signals from. If a filename is used, a package will be read instead.",
2368
+ type: "string"
2369
+ }).option("what-if", {
2370
+ alias: ["w"],
2371
+ describe: "What-if mode reports what would be done but changes nothing",
2372
+ default: false,
2373
+ type: "boolean"
2374
+ }).option("mode", {
2375
+ alias: ["m"],
2376
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
2377
+ choices: ["create", "createOrUpdate", "mirror"],
2378
+ default: "mirror",
2379
+ type: "string"
2380
+ })
2381
+ )
2382
+ )
2383
+ ),
2384
+ handler: async ({
2385
+ apiHost,
2386
+ apiKey,
2387
+ proxy,
2388
+ directory,
2389
+ mode,
2390
+ whatIf,
2391
+ project: projectId,
2392
+ diff: diffMode
2393
+ }) => {
2394
+ var _a;
2395
+ const fetch3 = nodeFetchProxy(proxy);
2396
+ const client = new UncachedSignalClient4({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
2397
+ let source;
2398
+ const isPackage = isPathAPackageFile(directory);
2399
+ if (isPackage) {
2400
+ const packageContents = readContextPackage(directory, true);
2401
+ source = await createArraySyncEngineDataSource({
2402
+ objects: (_a = packageContents.signals) != null ? _a : [],
2403
+ selectIdentifier: selectIdentifier7,
2404
+ selectDisplayName: selectDisplayName7
2405
+ });
2406
+ } else {
2407
+ source = await createFileSyncEngineDataSource({
2408
+ directory,
2409
+ selectIdentifier: selectIdentifier7,
2410
+ selectDisplayName: selectDisplayName7
2411
+ });
2412
+ }
2413
+ const target = createSignalEngineDataSource({ client });
2414
+ await syncEngine({
2415
+ source,
2416
+ target,
2417
+ mode,
2418
+ whatIf,
2419
+ log: createSyncEngineConsoleLogger({ diffMode })
2420
+ });
2421
+ }
2422
+ };
2423
+
2424
+ // src/commands/context/commands/signal/remove.ts
2425
+ import { UncachedSignalClient as UncachedSignalClient5 } from "@uniformdev/context/api";
2426
+ var SignalRemoveModule = {
2427
+ command: "remove <id>",
2428
+ aliases: ["delete", "rm"],
2429
+ describe: "Delete a signal",
2430
+ builder: (yargs18) => withApiOptions(
2431
+ withProjectOptions(
2432
+ yargs18.positional("id", { demandOption: true, describe: "Signal public ID to delete" })
2433
+ )
2434
+ ),
2435
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
2436
+ const fetch3 = nodeFetchProxy(proxy);
2437
+ const client = new UncachedSignalClient5({ apiKey, apiHost, fetch: fetch3, projectId });
2438
+ await client.remove({ signalId: id });
2439
+ }
2440
+ };
2441
+
2442
+ // src/commands/context/commands/signal/update.ts
2443
+ import { UncachedSignalClient as UncachedSignalClient6 } from "@uniformdev/context/api";
2444
+ var SignalUpdateModule = {
2445
+ command: "update <filename>",
2446
+ aliases: ["put"],
2447
+ describe: "Insert or update a signal",
2448
+ builder: (yargs18) => withApiOptions(
2449
+ withProjectOptions(yargs18.positional("filename", { demandOption: true, describe: "Signal file to put" }))
2450
+ ),
2451
+ handler: async ({ apiHost, apiKey, proxy, filename, project: projectId }) => {
2452
+ const fetch3 = nodeFetchProxy(proxy);
2453
+ const client = new UncachedSignalClient6({ apiKey, apiHost, fetch: fetch3, projectId });
2454
+ const file = readFileToObject(filename);
2455
+ await client.upsert({ signal: file });
2456
+ }
2457
+ };
2458
+
2459
+ // src/commands/context/commands/signal.ts
2460
+ var SignalModule = {
2461
+ command: "signal <command>",
2462
+ aliases: ["sig"],
2463
+ describe: "Commands for Context signals",
2464
+ builder: (yargs18) => yargs18.command(SignalPullModule).command(SignalPushModule).command(SignalGetModule).command(SignalRemoveModule).command(SignalListModule).command(SignalUpdateModule).demandCommand(),
2465
+ handler: () => {
2466
+ yargs9.help();
2467
+ }
2468
+ };
2469
+
2470
+ // src/commands/context/commands/test.ts
2471
+ import yargs10 from "yargs";
2472
+
2473
+ // src/commands/context/commands/test/get.ts
2474
+ import { UncachedTestClient } from "@uniformdev/context/api";
2475
+ var TestGetModule = {
2476
+ command: "get <id>",
2477
+ describe: "Fetch a test",
2478
+ builder: (yargs18) => withFormatOptions(
2479
+ withApiOptions(
2480
+ withProjectOptions(
2481
+ yargs18.positional("id", { demandOption: true, describe: "Test public ID to fetch" })
2482
+ )
2483
+ )
2484
+ ),
2485
+ handler: async ({ apiHost, apiKey, proxy, id, format, project: projectId, filename }) => {
2486
+ const fetch3 = nodeFetchProxy(proxy);
2487
+ const client = new UncachedTestClient({ apiKey, apiHost, fetch: fetch3, projectId });
2488
+ const res = await client.get({ testId: id });
2489
+ if (res.tests.length === 0) {
2490
+ console.error("Test did not exist");
2491
+ process.exit(1);
2492
+ } else {
2493
+ emitWithFormat(res.tests[0], format, filename);
2494
+ }
2495
+ }
2496
+ };
2497
+
2498
+ // src/commands/context/commands/test/list.ts
2499
+ import { UncachedTestClient as UncachedTestClient2 } from "@uniformdev/context/api";
2500
+ var TestListModule = {
2501
+ command: "list",
2502
+ describe: "List tests",
2503
+ aliases: ["ls"],
2504
+ builder: (yargs18) => withFormatOptions(withApiOptions(withProjectOptions(yargs18))),
2505
+ handler: async ({ apiHost, apiKey, proxy, format, filename, project: projectId }) => {
2506
+ const fetch3 = nodeFetchProxy(proxy);
2507
+ const client = new UncachedTestClient2({ apiKey, apiHost, fetch: fetch3, projectId });
2508
+ const res = await client.get();
2509
+ emitWithFormat(res.tests, format, filename);
2510
+ }
2511
+ };
2512
+
2513
+ // src/commands/context/commands/test/pull.ts
2514
+ import { UncachedTestClient as UncachedTestClient3 } from "@uniformdev/context/api";
2515
+
2516
+ // src/commands/context/commands/test/_util.ts
2517
+ var selectIdentifier8 = (source) => source.id;
2518
+ var selectDisplayName8 = (source) => `${source.name} (pid: ${source.id})`;
2519
+
2520
+ // src/commands/context/testEngineDataSource.ts
2521
+ function createTestEngineDataSource({
2522
+ client
2523
+ }) {
2524
+ async function* getObjects() {
2525
+ const tests = (await client.get()).tests;
2526
+ for await (const def of tests) {
2527
+ const result = {
2528
+ id: selectIdentifier8(def),
2529
+ displayName: selectDisplayName8(def),
2530
+ providerId: def.id,
2531
+ object: def
2532
+ };
2533
+ yield result;
2534
+ }
2535
+ }
2536
+ return {
2537
+ objects: getObjects(),
2538
+ deleteObject: async (providerId) => {
2539
+ await client.remove({ testId: providerId });
2540
+ },
2541
+ writeObject: async (object) => {
2542
+ await client.upsert({
2543
+ test: object.object
2544
+ });
2545
+ }
2546
+ };
2547
+ }
2548
+
2549
+ // src/commands/context/commands/test/pull.ts
2550
+ var TestPullModule = {
2551
+ command: "pull <directory>",
2552
+ describe: "Pulls all tests to local files in a directory",
2553
+ builder: (yargs18) => withApiOptions(
2554
+ withProjectOptions(
2555
+ withDiffOptions(
2556
+ yargs18.positional("directory", {
2557
+ describe: "Directory to save the tests to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
2558
+ type: "string"
2559
+ }).option("format", {
2560
+ alias: ["f"],
2561
+ describe: "Output format",
2562
+ default: "yaml",
2563
+ choices: ["yaml", "json"],
2564
+ type: "string"
2565
+ }).option("what-if", {
2566
+ alias: ["w"],
2567
+ describe: "What-if mode reports what would be done but changes no files",
2568
+ default: false,
2569
+ type: "boolean"
2570
+ }).option("mode", {
2571
+ alias: ["m"],
2572
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
2573
+ choices: ["create", "createOrUpdate", "mirror"],
2574
+ default: "mirror",
2575
+ type: "string"
2576
+ })
2577
+ )
2578
+ )
2579
+ ),
2580
+ handler: async ({
2581
+ apiHost,
2582
+ apiKey,
2583
+ proxy,
2584
+ directory,
2585
+ format,
2586
+ mode,
2587
+ whatIf,
2588
+ project: projectId,
2589
+ diff: diffMode
2590
+ }) => {
2591
+ var _a;
2592
+ const fetch3 = nodeFetchProxy(proxy);
2593
+ const client = new UncachedTestClient3({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
2594
+ const source = createTestEngineDataSource({ client });
2595
+ let target;
2596
+ const isPackage = isPathAPackageFile(directory);
2597
+ if (isPackage) {
2598
+ const packageContents = readContextPackage(directory, false);
2599
+ target = await createArraySyncEngineDataSource({
2600
+ objects: (_a = packageContents.tests) != null ? _a : [],
2601
+ selectIdentifier: selectIdentifier8,
2602
+ selectDisplayName: selectDisplayName8,
2603
+ onSyncComplete: async (_, synced) => {
2604
+ packageContents.tests = synced;
2605
+ writeContextPackage(directory, packageContents);
2606
+ }
2607
+ });
2608
+ } else {
2609
+ target = await createFileSyncEngineDataSource({
2610
+ directory,
2611
+ selectIdentifier: selectIdentifier8,
2612
+ selectDisplayName: selectDisplayName8,
2613
+ format
2614
+ });
2615
+ }
2616
+ await syncEngine({
2617
+ source,
2618
+ target,
2619
+ mode,
2620
+ whatIf,
2621
+ log: createSyncEngineConsoleLogger({ diffMode })
2622
+ });
2623
+ }
2624
+ };
2625
+
2626
+ // src/commands/context/commands/test/push.ts
2627
+ import { UncachedTestClient as UncachedTestClient4 } from "@uniformdev/context/api";
2628
+ var TestPushModule = {
2629
+ command: "push <directory>",
2630
+ describe: "Pushes all tests from files in a directory or package to Uniform",
2631
+ builder: (yargs18) => withApiOptions(
2632
+ withProjectOptions(
2633
+ withDiffOptions(
2634
+ yargs18.positional("directory", {
2635
+ describe: "Directory to read the tests from. If a filename is used, a package will be read instead.",
2636
+ type: "string"
2637
+ }).option("what-if", {
2638
+ alias: ["w"],
2639
+ describe: "What-if mode reports what would be done but changes nothing",
2640
+ default: false,
2641
+ type: "boolean"
2642
+ }).option("mode", {
2643
+ alias: ["m"],
2644
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
2645
+ choices: ["create", "createOrUpdate", "mirror"],
2646
+ default: "mirror",
2647
+ type: "string"
2648
+ })
2649
+ )
2650
+ )
2651
+ ),
2652
+ handler: async ({
2653
+ apiHost,
2654
+ apiKey,
2655
+ proxy,
2656
+ directory,
2657
+ mode,
2658
+ whatIf,
2659
+ project: projectId,
2660
+ diff: diffMode
2661
+ }) => {
2662
+ var _a;
2663
+ const fetch3 = nodeFetchProxy(proxy);
2664
+ const client = new UncachedTestClient4({ apiKey, apiHost, fetch: fetch3, projectId, limitPolicy: limitPolicy2 });
2665
+ let source;
2666
+ const isPackage = isPathAPackageFile(directory);
2667
+ if (isPackage) {
2668
+ const packageContents = readContextPackage(directory, true);
2669
+ source = await createArraySyncEngineDataSource({
2670
+ objects: (_a = packageContents.tests) != null ? _a : [],
2671
+ selectIdentifier: selectIdentifier8,
2672
+ selectDisplayName: selectDisplayName8
2673
+ });
2674
+ } else {
2675
+ source = await createFileSyncEngineDataSource({
2676
+ directory,
2677
+ selectIdentifier: selectIdentifier8,
2678
+ selectDisplayName: selectDisplayName8
2679
+ });
2680
+ }
2681
+ const target = createTestEngineDataSource({ client });
2682
+ await syncEngine({
2683
+ source,
2684
+ target,
2685
+ mode,
2686
+ whatIf,
2687
+ log: createSyncEngineConsoleLogger({ diffMode })
2688
+ });
2689
+ }
2690
+ };
2691
+
2692
+ // src/commands/context/commands/test/remove.ts
2693
+ import { UncachedTestClient as UncachedTestClient5 } from "@uniformdev/context/api";
2694
+ var TestRemoveModule = {
2695
+ command: "remove <id>",
2696
+ aliases: ["delete", "rm"],
2697
+ describe: "Delete a test",
2698
+ builder: (yargs18) => withApiOptions(
2699
+ withProjectOptions(yargs18.positional("id", { demandOption: true, describe: "Test public ID to delete" }))
2700
+ ),
2701
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
2702
+ const fetch3 = nodeFetchProxy(proxy);
2703
+ const client = new UncachedTestClient5({ apiKey, apiHost, fetch: fetch3, projectId });
2704
+ await client.remove({ testId: id });
2705
+ }
2706
+ };
2707
+
2708
+ // src/commands/context/commands/test/update.ts
2709
+ import { UncachedTestClient as UncachedTestClient6 } from "@uniformdev/context/api";
2710
+ var TestUpdateModule = {
2711
+ command: "update <filename>",
2712
+ aliases: ["put"],
2713
+ describe: "Insert or update a test",
2714
+ builder: (yargs18) => withApiOptions(
2715
+ withProjectOptions(yargs18.positional("filename", { demandOption: true, describe: "Test file to put" }))
2716
+ ),
2717
+ handler: async ({ apiHost, apiKey, proxy, filename, project: projectId }) => {
2718
+ const fetch3 = nodeFetchProxy(proxy);
2719
+ const client = new UncachedTestClient6({ apiKey, apiHost, fetch: fetch3, projectId });
2720
+ const file = readFileToObject(filename);
2721
+ await client.upsert({ test: file });
2722
+ }
2723
+ };
2724
+
2725
+ // src/commands/context/commands/test.ts
2726
+ var TestModule = {
2727
+ command: "test <command>",
2728
+ describe: "Commands for Context A/B tests",
2729
+ builder: (yargs18) => yargs18.command(TestPullModule).command(TestPushModule).command(TestGetModule).command(TestRemoveModule).command(TestListModule).command(TestUpdateModule).demandCommand(),
2730
+ handler: () => {
2731
+ yargs10.help();
2732
+ }
2733
+ };
2734
+
2735
+ // src/commands/context/index.ts
2736
+ var ContextCommand = {
2737
+ command: "context <command>",
2738
+ aliases: ["ctx"],
2739
+ describe: "Uniform Context commands",
2740
+ builder: (yargs18) => yargs18.command(ManifestModule).command(SignalModule).command(EnrichmentModule).command(AggregateModule).command(QuirkModule).command(TestModule).demandCommand(),
2741
+ handler: () => {
2742
+ yargs11.showHelp();
2743
+ }
2744
+ };
2745
+
2746
+ // src/spinner.ts
2747
+ var makeSpinner = () => {
2748
+ const spinners = [];
2749
+ const stopAllSpinners = () => spinners.forEach((spinner) => spinner.stop());
2750
+ const spin = async (text) => {
2751
+ const spinner = await Promise.resolve().then(() => __toESM(__require("ora"))).then((ora) => ora.default(text).start());
2752
+ spinners.push(spinner);
2753
+ const minWait = new Promise((resolve) => setTimeout(resolve, 500));
2754
+ return async () => {
2755
+ await minWait;
2756
+ spinner.stop();
2757
+ };
2758
+ };
2759
+ return { stopAllSpinners, spin };
2760
+ };
2761
+
2762
+ // src/telemetry/telemetry.ts
2763
+ import crypto from "crypto";
2764
+ import { PostHog } from "posthog-node";
2765
+
2766
+ // package.json
2767
+ var package_default = {
2768
+ name: "@uniformdev/cli",
2769
+ version: "18.18.0",
2770
+ description: "Uniform command line interface tool",
2771
+ license: "SEE LICENSE IN LICENSE.txt",
2772
+ main: "./cli.js",
2773
+ types: "./dist/index.d.ts",
2774
+ sideEffects: false,
2775
+ scripts: {
2776
+ uniform: "node ./cli.js",
2777
+ build: "tsup",
2778
+ dev: "tsup --watch",
2779
+ clean: "rimraf dist",
2780
+ test: "jest --maxWorkers=1 --passWithNoTests",
2781
+ lint: 'eslint "src/**/*.{js,ts,tsx}"',
2782
+ format: 'prettier --write "src/**/*.{js,ts,tsx}"'
2783
+ },
2784
+ dependencies: {
2785
+ "@uniformdev/canvas": "workspace:*",
2786
+ "@uniformdev/context": "workspace:*",
2787
+ "@uniformdev/project-map": "workspace:*",
2788
+ execa: "5.1.1",
2789
+ "fs-jetpack": "5.1.0",
2790
+ graphql: "16.6.0",
2791
+ "graphql-request": "5.1.0",
2792
+ inquirer: "8.2.5",
2793
+ "isomorphic-git": "1.21.0",
2794
+ jsonwebtoken: "9.0.0",
2795
+ open: "8.4.0",
2796
+ ora: "6.1.2",
2797
+ "posthog-node": "2.2.3",
2798
+ slugify: "1.6.5",
2799
+ diff: "^5.0.0",
2800
+ dotenv: "^16.0.3",
2801
+ "https-proxy-agent": "^5.0.1",
2802
+ "isomorphic-unfetch": "^3.1.0",
2803
+ "js-yaml": "^4.1.0",
2804
+ "lodash.isequalwith": "^4.4.0",
2805
+ yargs: "^17.6.2",
2806
+ zod: "3.20.6"
2807
+ },
2808
+ devDependencies: {
2809
+ "@types/inquirer": "9.0.3",
2810
+ "@types/jsonwebtoken": "9.0.1",
2811
+ "@types/node": "18.11.17",
2812
+ "@types/diff": "5.0.2",
2813
+ "@types/js-yaml": "4.0.5",
2814
+ "@types/lodash.isequalwith": "4.4.7",
2815
+ "@types/yargs": "17.0.22",
2816
+ "p-limit": "4.0.0"
2817
+ },
2818
+ bin: {
2819
+ uniform: "./cli.js"
2820
+ },
2821
+ files: [
2822
+ "/dist"
2823
+ ],
2824
+ publishConfig: {
2825
+ access: "public"
2826
+ }
2827
+ };
2828
+
2829
+ // src/telemetry/telemetry.ts
2830
+ var POSTHOG_WRITE_ONLY_KEY = "phc_c8YoKI9984KOHBfNrCRfIKvL56aYd5OpYxOdYexRzH7";
2831
+ var Telemetry = class {
2832
+ constructor(prefix, disable = false) {
2833
+ this.prefix = prefix;
2834
+ this.distinctId = crypto.randomBytes(20).toString("hex");
2835
+ if (!disable) {
2836
+ this.posthog = new PostHog(POSTHOG_WRITE_ONLY_KEY, {
2837
+ flushAt: 1,
2838
+ flushInterval: 1
2839
+ });
2840
+ this.send("started");
2841
+ }
2842
+ }
2843
+ login(sub, user) {
2844
+ if (!this.posthog) {
2845
+ return;
2846
+ }
2847
+ const alias = this.distinctId;
2848
+ this.distinctId = sub;
2849
+ this.posthog.alias({ distinctId: this.distinctId, alias });
2850
+ this.posthog.identify({
2851
+ distinctId: this.distinctId,
2852
+ properties: {
2853
+ email: user.email_address,
2854
+ sub,
2855
+ teamCount: user.teams.length
2856
+ }
2857
+ });
2858
+ this.send("logged in");
2859
+ }
2860
+ send(event, properties = {}) {
2861
+ var _a;
2862
+ (_a = this.posthog) == null ? void 0 : _a.capture({
2863
+ distinctId: this.distinctId,
2864
+ event: [this.prefix, event].join(" "),
2865
+ properties: {
2866
+ version: package_default.version,
2867
+ ...properties
2868
+ }
2869
+ });
2870
+ }
2871
+ shutdown() {
2872
+ var _a;
2873
+ this.send("exited", { exitCode: process.exitCode });
2874
+ return (_a = this.posthog) == null ? void 0 : _a.shutdownAsync();
2875
+ }
2876
+ };
2877
+
2878
+ // src/commands/new/commands/new.ts
2879
+ import inquirer4 from "inquirer";
2880
+
2881
+ // src/auth/getBearerToken.ts
2882
+ import inquirer from "inquirer";
2883
+ import jwt from "jsonwebtoken";
2884
+ import open from "open";
2885
+
2886
+ // src/url.ts
2887
+ var makeUrl = (baseUrl, path4) => [baseUrl.trim().replace(/\/+$/, ""), path4.trim().replace(/^\/+/, "")].join("/");
2888
+
2889
+ // src/auth/getBearerToken.ts
2890
+ async function getBearerToken(baseUrl) {
2891
+ const { canOpen } = await inquirer.prompt([
2892
+ {
2893
+ type: "confirm",
2894
+ name: "canOpen",
2895
+ message: "Can we open a browser window to get a Uniform auth token?"
2896
+ }
2897
+ ]);
2898
+ if (canOpen) {
2899
+ open(makeUrl(baseUrl, "/cli-login"));
2900
+ }
2901
+ const tokenAnswer = await inquirer.prompt([
2902
+ {
2903
+ type: "password",
2904
+ name: "authToken",
2905
+ message: "Paste your Uniform auth token"
2906
+ }
2907
+ ]);
2908
+ const authToken = tokenAnswer.authToken.trim();
2909
+ if (!authToken) {
2910
+ throw new Error("No auth token provided.");
2911
+ }
2912
+ const decoded = jwt.decode(authToken, { complete: false });
2913
+ if (!decoded) {
2914
+ throw new Error("Could not parse the token pasted.");
2915
+ }
2916
+ if (typeof decoded.sub !== "string" || typeof decoded === "string") {
2917
+ throw new Error("Invalid token pasted.");
2918
+ }
2919
+ return {
2920
+ authToken,
2921
+ decoded: { ...decoded, sub: decoded.sub }
2922
+ };
2923
+ }
2924
+
2925
+ // src/client.ts
2926
+ import { z } from "zod";
2927
+
2928
+ // src/auth/api-key.ts
2929
+ var READ_PERMISSIONS = ["PROJECT", "UPM_PUB", "OPT_PUB", "OPT_READ", "UPM_READ"];
2930
+ var WRITE_PERMISSIONS = [
2931
+ "PROJECT",
2932
+ "UPM_SCHEMA",
2933
+ "UPM_READ",
2934
+ "UPM_PUB",
2935
+ "UPM_CREATE",
2936
+ "UPM_WRITE",
2937
+ "UPM_DELETE",
2938
+ "UPM_PUBLISH",
2939
+ "OPT_READ",
2940
+ "OPT_CREATE_ENRICHMENTS",
2941
+ "OPT_WRITE_ENRICHMENTS",
2942
+ "OPT_DELETE_ENRICHMENTS",
2943
+ "OPT_CREATE_INTENTS",
2944
+ "OPT_WRITE_INTENTS",
2945
+ "OPT_DELETE_INTENTS",
2946
+ "OPT_PUB",
2947
+ "OPT_PUBLISH",
2948
+ "OPT_CREATE_QUIRKS",
2949
+ "OPT_WRITE_QUIRKS",
2950
+ "OPT_DELETE_QUIRKS",
2951
+ "OPT_CREATE_SIGNALS",
2952
+ "OPT_WRITE_SIGNALS",
2953
+ "OPT_DELETE_SIGNALS",
2954
+ "OPT_CREATE_TESTS",
2955
+ "OPT_WRITE_TESTS",
2956
+ "OPT_DELETE_TESTS"
2957
+ ];
2958
+ var makeApiKey = (teamId, projectId, name, permissions) => ({
2959
+ name,
2960
+ teamId,
2961
+ projects: [
2962
+ {
2963
+ projectId,
2964
+ permissions,
2965
+ roles: [],
2966
+ useCustom: true
2967
+ }
2968
+ ],
2969
+ email: "",
2970
+ identity_subject: "",
2971
+ isAdmin: false
2972
+ });
2973
+ var makeReadApiKey = (teamId, projectId) => makeApiKey(teamId, projectId, "Created by Uniform New (read)", READ_PERMISSIONS);
2974
+ var makeWriteApiKey = (teamId, projectId) => makeApiKey(teamId, projectId, "Created by Uniform New (write)", WRITE_PERMISSIONS);
2975
+
2976
+ // src/client.ts
2977
+ var createTeamOrProjectSchema = z.object({ id: z.string().min(1) });
2978
+ var createApiKeySchema = z.object({ apiKey: z.string().min(1) });
2979
+ var getLimitsSchema = z.object({
2980
+ limits: z.object({
2981
+ projects: z.array(
2982
+ z.object({ id: z.string().min(1), name: z.string().min(1), used: z.number(), limit: z.number() })
2983
+ )
2984
+ })
2985
+ });
2986
+ var createClient = (baseUrl, authToken) => {
2987
+ const request2 = async (path4, opts) => {
2988
+ const res = await fetch(makeUrl(baseUrl, path4), {
2989
+ ...opts,
2990
+ headers: { Authorization: `Bearer ${authToken}` }
2991
+ });
2992
+ if (res.ok) {
2993
+ return res;
2994
+ } else {
2995
+ throw new Error(
2996
+ `Non-2xx API response: ${opts.method} ${path4} responded with ${res.status} ${res.statusText}`
2997
+ );
2998
+ }
2999
+ };
3000
+ const requestJson = async (path4, opts, schema2) => {
3001
+ const res = await request2(path4, opts);
3002
+ const data = await res.json();
3003
+ const parseResult = schema2.safeParse(data);
3004
+ if (parseResult.success) {
3005
+ return parseResult.data;
3006
+ } else {
3007
+ throw new Error(`Invalid ${opts.method} ${path4} response: ${parseResult.error.message}`);
3008
+ }
3009
+ };
3010
+ return {
3011
+ createTeam: async (name) => {
3012
+ try {
3013
+ const result = await requestJson(
3014
+ "/api/v1/team",
3015
+ { method: "POST", body: JSON.stringify({ name }) },
3016
+ createTeamOrProjectSchema
3017
+ );
3018
+ return result.id;
3019
+ } catch (err) {
3020
+ throw new Error(`Failed to create team:
3021
+ ${err.message}`);
3022
+ }
3023
+ },
3024
+ createProject: async (teamId, name, previewUrl) => {
3025
+ try {
3026
+ const { limits } = await requestJson(
3027
+ `/api/v1/limits?teamId=${teamId}`,
3028
+ { method: "POST" },
3029
+ getLimitsSchema
3030
+ );
3031
+ const projectTypeBelowLimit = limits.projects.find((project) => project.used < project.limit);
3032
+ if (!projectTypeBelowLimit) {
3033
+ throw new Error("Usage exceeded.");
3034
+ }
3035
+ const result = await requestJson(
3036
+ "/api/v1/project",
3037
+ {
3038
+ method: "POST",
3039
+ body: JSON.stringify({
3040
+ organization_id: teamId,
3041
+ name,
3042
+ site_type_id: projectTypeBelowLimit.id,
3043
+ ui_version: 3,
3044
+ preview_url: previewUrl
3045
+ })
3046
+ },
3047
+ createTeamOrProjectSchema
3048
+ );
3049
+ return result.id;
3050
+ } catch (err) {
3051
+ throw new Error(`Failed to create project:
3052
+ ${err.message}`);
3053
+ }
3054
+ },
3055
+ createApiKeys: async (teamId, projectId) => {
3056
+ try {
3057
+ const { apiKey: readApiKey } = await requestJson(
3058
+ "/api/v1/members",
3059
+ {
3060
+ method: "PUT",
3061
+ body: JSON.stringify(makeReadApiKey(teamId, projectId))
3062
+ },
3063
+ createApiKeySchema
3064
+ );
3065
+ const { apiKey: writeApiKey } = await requestJson(
3066
+ "/api/v1/members",
3067
+ {
3068
+ method: "PUT",
3069
+ body: JSON.stringify(makeWriteApiKey(teamId, projectId))
3070
+ },
3071
+ createApiKeySchema
3072
+ );
3073
+ return { readApiKey, writeApiKey };
3074
+ } catch (err) {
3075
+ throw new Error(`Failed to create API key:
3076
+ ${err.message}`);
3077
+ }
3078
+ },
3079
+ installCanvas: async (projectId) => {
3080
+ try {
3081
+ await request2(`/api/v1/integrations?integration=canvas&action=install&site=${projectId}`, {
3082
+ method: "POST"
3083
+ });
3084
+ } catch (err) {
3085
+ throw new Error(`Failed to install Canvas:
3086
+ ${err.message}`);
3087
+ }
3088
+ },
3089
+ registerMeshIntegration: async ({ teamId, manifest }) => {
3090
+ try {
3091
+ const { type } = await requestJson(
3092
+ "/api/v1/integration-definitions",
3093
+ {
3094
+ method: "PUT",
3095
+ body: JSON.stringify({ teamId, data: manifest })
3096
+ },
3097
+ z.object({ type: z.string() })
3098
+ );
3099
+ return type;
3100
+ } catch (err) {
3101
+ throw new Error(`Failed to register integration:
3102
+ ${err.message}`);
3103
+ }
3104
+ },
3105
+ installIntegration: async ({ projectId, type }) => {
3106
+ try {
3107
+ await request2("/api/v1/integration-installations", {
3108
+ method: "PUT",
3109
+ body: JSON.stringify({ projectId, type })
3110
+ });
3111
+ } catch (err) {
3112
+ throw new Error(`Failed to install integration to project:
3113
+ ${err.message}`);
3114
+ }
3115
+ }
3116
+ };
3117
+ };
3118
+
3119
+ // src/npm.ts
3120
+ import execa from "execa";
3121
+ var runNpm = async (workDir, args, { inherit, env } = {}) => {
3122
+ let result;
3123
+ try {
3124
+ result = await execa("npm", args, {
3125
+ cwd: workDir,
3126
+ env: env != null ? env : {},
3127
+ ...inherit ? { stdout: "inherit", stderr: "inherit" } : {}
3128
+ });
3129
+ } catch (err) {
3130
+ throw new Error(`Failed to execute npm ${args.join(" ")}
3131
+ ${err.message}`);
3132
+ }
3133
+ if (result.exitCode !== 0) {
3134
+ throw new Error(`Command npm ${args.join(" ")} exitted with code ${result == null ? void 0 : result.exitCode}}: ${result.stderr}`);
3135
+ }
3136
+ return result.stdout;
3137
+ };
3138
+
3139
+ // src/projects/cloneStarter.ts
3140
+ import crypto2 from "crypto";
3141
+ import fs from "fs";
3142
+ import { copy } from "fs-jetpack";
3143
+ import * as git from "isomorphic-git";
3144
+ import * as http from "isomorphic-git/http/node";
3145
+ import os from "os";
3146
+ import path from "path";
3147
+ async function cloneStarter({
3148
+ spin,
3149
+ githubPath,
3150
+ targetDir,
3151
+ dotEnvFile
3152
+ }) {
3153
+ const done = await spin("Fetching starter code...");
3154
+ const cloneDir = path.join(os.tmpdir(), `uniform-new-${crypto2.randomBytes(20).toString("hex")}`);
3155
+ const [user, repo, ...pathSegments] = githubPath.split("/");
3156
+ try {
3157
+ await git.clone({
3158
+ fs,
3159
+ http,
3160
+ url: `https://github.com/${user}/${repo}`,
3161
+ dir: cloneDir,
3162
+ singleBranch: true,
3163
+ depth: 1
3164
+ });
3165
+ } catch (err) {
3166
+ throw new Error(`Failed to fetch starter code: ${err.message}`);
3167
+ }
3168
+ await done();
3169
+ if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
3170
+ throw new Error(`"${targetDir}" is not empty`);
3171
+ }
3172
+ const starterDir = path.join(cloneDir, ...pathSegments);
3173
+ copy(starterDir, targetDir, { overwrite: true });
3174
+ if (dotEnvFile) {
3175
+ fs.writeFileSync(path.resolve(targetDir, ".env"), dotEnvFile, "utf-8");
3176
+ }
3177
+ console.log(`
3178
+ Your project now lives in ${targetDir} \u2728`);
3179
+ return {
3180
+ runNpmInstall: async () => {
3181
+ console.log(`
3182
+ Installing project dependencies...
3183
+
3184
+ `);
3185
+ await runNpm(targetDir, ["i"], { inherit: true });
3186
+ }
3187
+ };
3188
+ }
3189
+
3190
+ // src/projects/getOrCreateProject.ts
3191
+ import fs2, { existsSync, mkdirSync } from "fs";
3192
+ import inquirer2 from "inquirer";
3193
+ import path2 from "path";
3194
+ import slugify from "slugify";
3195
+ var newProjectId = "$new";
3196
+ async function getOrCreateProject({
3197
+ chooseExisting,
3198
+ createNew,
3199
+ teamId,
3200
+ user,
3201
+ explicitName,
3202
+ client,
3203
+ spin,
3204
+ checkTargetDir,
3205
+ explicitTargetDir,
3206
+ previewUrl,
3207
+ telemetry
3208
+ }) {
3209
+ if (explicitName && !createNew) {
3210
+ throw new Error("Tried to specify explicit new project name when adding new project is not enabled.");
3211
+ }
3212
+ if (!createNew && !chooseExisting) {
3213
+ throw new Error("Must allow adding new, creating existing, or both.");
3214
+ }
3215
+ if (chooseExisting) {
3216
+ const { projectId, projectName } = await chooseExistingProject({ createNew, teamId, user });
3217
+ if (projectId !== newProjectId && projectName) {
3218
+ const targetDir = validateProjectName(projectName, checkTargetDir, explicitTargetDir);
3219
+ telemetry.send("project picked", { projectId, targetDir });
3220
+ return {
3221
+ projectId,
3222
+ projectName,
3223
+ targetDir
3224
+ };
3225
+ }
3226
+ }
3227
+ if (createNew) {
3228
+ const { projectName, targetDir } = await getNewProjectName({
3229
+ explicitName,
3230
+ checkTargetDir,
3231
+ explicitTargetDir
3232
+ });
3233
+ const projectId = await createProject({ client, projectName, spin, teamId, previewUrl });
3234
+ telemetry.send("project created", { projectId, targetDir });
3235
+ return {
3236
+ projectId,
3237
+ projectName,
3238
+ targetDir
3239
+ };
3240
+ }
3241
+ throw new Error("Insanity!");
3242
+ }
3243
+ async function getNewProjectName({
3244
+ explicitName,
3245
+ checkTargetDir,
3246
+ explicitTargetDir
3247
+ }) {
3248
+ let projectName = explicitName;
3249
+ if (!projectName) {
3250
+ const answer = await inquirer2.prompt([
3251
+ {
3252
+ type: "input",
3253
+ name: "name",
3254
+ message: "What's your project name?",
3255
+ validate(input) {
3256
+ try {
3257
+ validateProjectName(input, checkTargetDir, explicitTargetDir);
3258
+ return true;
3259
+ } catch (e) {
3260
+ return e.message;
3261
+ }
3262
+ }
3263
+ }
3264
+ ]);
3265
+ projectName = answer.name;
3266
+ }
3267
+ projectName = projectName.trim();
3268
+ const targetDir = validateProjectName(projectName, checkTargetDir, explicitTargetDir);
3269
+ return { projectName, targetDir };
3270
+ }
3271
+ async function createProject({
3272
+ projectName,
3273
+ teamId,
3274
+ spin,
3275
+ client,
3276
+ previewUrl
3277
+ }) {
3278
+ const done = await spin("Creating your new project...");
3279
+ const projectId = await client.createProject(teamId, projectName, previewUrl);
3280
+ await done();
3281
+ return projectId;
3282
+ }
3283
+ async function chooseExistingProject({
3284
+ createNew,
3285
+ teamId,
3286
+ user
3287
+ }) {
3288
+ var _a, _b, _c;
3289
+ const projects = ((_b = (_a = user.teams.find((t) => t.team.id === teamId)) == null ? void 0 : _a.team.sites) != null ? _b : []).map((t) => ({
3290
+ name: t.name,
3291
+ value: t.id
3292
+ }));
3293
+ const choices = createNew ? [{ name: "Create new project...", value: newProjectId }].concat(projects) : projects;
3294
+ const result = await inquirer2.prompt([
3295
+ {
3296
+ type: "list",
3297
+ name: "projectId",
3298
+ message: "Choose a project",
3299
+ choices
3300
+ }
3301
+ ]);
3302
+ return {
3303
+ projectId: result.projectId,
3304
+ projectName: (_c = projects.find((p) => p.value === result.projectId)) == null ? void 0 : _c.name
3305
+ };
3306
+ }
3307
+ function validateProjectName(projectName, checkTargetDir, explicitTargetDir) {
3308
+ projectName = projectName.trim();
3309
+ const projectNameSlug = slugify(projectName);
3310
+ if (projectName.length < 3 || projectNameSlug.length < 3) {
3311
+ throw new Error("Project name cannot be shorter than 3 characters.");
3312
+ }
3313
+ if (checkTargetDir) {
3314
+ let targetDir = explicitTargetDir != null ? explicitTargetDir : process.cwd();
3315
+ if (!existsSync(targetDir)) {
3316
+ mkdirSync(targetDir, { recursive: true });
3317
+ }
3318
+ if (fs2.readdirSync(targetDir).length > 0) {
3319
+ targetDir = path2.resolve(targetDir, projectNameSlug);
3320
+ if (fs2.existsSync(targetDir)) {
3321
+ throw new Error(`${targetDir} already exists, choose a different name.`);
3322
+ }
3323
+ }
3324
+ return targetDir;
3325
+ }
3326
+ }
3327
+
3328
+ // src/teams/chooseTeam.ts
3329
+ import inquirer3 from "inquirer";
3330
+ async function chooseTeam(user, prompt, telemetry) {
3331
+ const result = await inquirer3.prompt([
3332
+ {
3333
+ type: "list",
3334
+ name: "teamId",
3335
+ message: prompt,
3336
+ choices: user.teams.map((team) => ({
3337
+ name: team.team.name,
3338
+ value: team.team.id
3339
+ }))
3340
+ }
3341
+ ]);
3342
+ telemetry.send("team picked", { teamId: result.teamId });
3343
+ return result;
3344
+ }
3345
+
3346
+ // src/auth/user-info.ts
3347
+ import { gql, request } from "graphql-request";
3348
+ import { z as z2 } from "zod";
3349
+ var query = gql`
3350
+ query GetUserInfo($subject: String!) {
3351
+ info: identities_by_pk(subject: $subject) {
3352
+ name
3353
+ email_address
3354
+ teams: organizations_identities {
3355
+ team: organization {
3356
+ name
3357
+ id
3358
+ sites {
3359
+ name
3360
+ id
3361
+ }
3362
+ }
3363
+ }
3364
+ }
3365
+ }
3366
+ `;
3367
+ var schema = z2.object({
3368
+ info: z2.object({
3369
+ name: z2.string().min(1),
3370
+ email_address: z2.string().min(1),
3371
+ teams: z2.array(
3372
+ z2.object({
3373
+ team: z2.object({
3374
+ name: z2.string().min(1),
3375
+ id: z2.string().min(1),
3376
+ sites: z2.array(
3377
+ z2.object({
3378
+ name: z2.string().min(1),
3379
+ id: z2.string().min(1)
3380
+ })
3381
+ )
3382
+ })
3383
+ })
3384
+ )
3385
+ })
3386
+ });
3387
+ var getUserInfo = async (baseUrl, authToken, subject) => {
3388
+ try {
3389
+ const endpoint = makeUrl(baseUrl, "/v1/graphql");
3390
+ const res = await request(endpoint, query, { subject }, { Authorization: `Bearer ${authToken}` });
3391
+ const parseResult = schema.safeParse(res);
3392
+ if (parseResult.success) {
3393
+ return parseResult.data.info;
3394
+ } else {
3395
+ throw new Error(`Invalid GraphQL response: ${parseResult.error.message}`);
3396
+ }
3397
+ } catch (err) {
3398
+ throw new Error(`Failed to fetch user account:
3399
+ ${err.message}`);
3400
+ }
3401
+ };
3402
+
3403
+ // src/teams/fetchUserAndEnsureTeamExists.ts
3404
+ async function fetchUserAndEnsureFirstTeamExists({
3405
+ baseUrl,
3406
+ auth: { authToken, decoded },
3407
+ spin,
3408
+ telemetry
3409
+ }) {
3410
+ const uniformClient = createClient(baseUrl, authToken);
3411
+ const done = await spin("Fetching user information...");
3412
+ let user = await getUserInfo(baseUrl, authToken, decoded.sub);
3413
+ if (user.teams.length < 1) {
3414
+ await uniformClient.createTeam(`${user.name}'s team`);
3415
+ user = await getUserInfo(baseUrl, authToken, decoded.sub);
3416
+ }
3417
+ await done();
3418
+ telemetry.login(decoded.sub, user);
3419
+ return user;
3420
+ }
3421
+
3422
+ // src/commands/new/commands/new.ts
3423
+ async function newHandler({
3424
+ spin,
3425
+ projectName,
3426
+ apiHost,
3427
+ outputPath,
3428
+ telemetry
3429
+ }) {
3430
+ console.info(
3431
+ `Welcome to Uniform New! Let's create ${projectName ? `"${projectName}"` : "a new project"}... \u2764\uFE0F`
3432
+ );
3433
+ const auth = await getBearerToken(apiHost);
3434
+ const { authToken } = auth;
3435
+ const uniformClient = createClient(apiHost, authToken);
3436
+ const user = await fetchUserAndEnsureFirstTeamExists({ auth, baseUrl: apiHost, spin, telemetry });
3437
+ const { teamId } = await chooseTeam(
3438
+ user,
3439
+ `Hey ${user.name}! Choose a Uniform team for your new project`,
3440
+ telemetry
3441
+ );
3442
+ const {
3443
+ starter: { githubUri, serverUrl, previewPath, installEnv }
3444
+ } = await inquirer4.prompt([
3445
+ {
3446
+ type: "list",
3447
+ name: "starter",
3448
+ message: "Choose your preferred framework",
3449
+ choices: [
3450
+ {
3451
+ name: "Next.js",
3452
+ value: {
3453
+ githubUri: "uniformdev/examples/examples/nextjs-starter",
3454
+ serverUrl: "http://localhost:3000",
3455
+ previewPath: "/api/preview?secret=hello-world",
3456
+ installEnv: []
3457
+ }
3458
+ },
3459
+ {
3460
+ name: "Nuxt.js",
3461
+ value: {
3462
+ githubUri: "uniformdev/examples/examples/nuxtjs-starter",
3463
+ serverUrl: "http://localhost:3000",
3464
+ previewPath: "/?preview=true",
3465
+ installEnv: [["NUXT_TELEMETRY_DISABLED", "1"]]
3466
+ }
3467
+ }
3468
+ ]
3469
+ }
3470
+ ]);
3471
+ telemetry.send("starter picked", { githubUri });
3472
+ const { projectId, targetDir } = await getOrCreateProject({
3473
+ client: uniformClient,
3474
+ createNew: true,
3475
+ chooseExisting: false,
3476
+ spin,
3477
+ teamId,
3478
+ user,
3479
+ explicitName: projectName,
3480
+ targetDir: outputPath,
3481
+ checkTargetDir: true,
3482
+ previewUrl: serverUrl + previewPath,
3483
+ telemetry
3484
+ });
3485
+ let done = await spin("Generating API keys...");
3486
+ const { readApiKey, writeApiKey } = await uniformClient.createApiKeys(teamId, projectId);
3487
+ await done();
3488
+ const dotEnvFile = [
3489
+ ["UNIFORM_PROJECT_ID", projectId],
3490
+ ["UNIFORM_API_KEY", readApiKey],
3491
+ ["UNIFORM_CLI_API_KEY", writeApiKey],
3492
+ ...installEnv
3493
+ ].concat(
3494
+ apiHost !== "https://uniform.app" ? [
3495
+ ["UNIFORM_CLI_BASE_URL", apiHost],
3496
+ ["UNIFORM_API_HOST", apiHost]
3497
+ ] : []
3498
+ ).map(([name, value]) => `${name}='${value}'`).join("\n") + "\n";
3499
+ done = await spin("Installing Canvas...");
3500
+ await uniformClient.installCanvas(projectId);
3501
+ await done();
3502
+ const cloneStartTimestamp = Date.now();
3503
+ const { runNpmInstall } = await cloneStarter({
3504
+ githubPath: githubUri,
3505
+ spin,
3506
+ targetDir,
3507
+ dotEnvFile
3508
+ });
3509
+ telemetry.send("starter cloned", { duration: Date.now() - cloneStartTimestamp });
3510
+ const installStartTimestamp = Date.now();
3511
+ await runNpmInstall();
3512
+ telemetry.send("deps installed", { duration: Date.now() - installStartTimestamp });
3513
+ done = await spin("Creating components and compositions");
3514
+ await runNpm(targetDir, ["run", "uniform:push"]);
3515
+ await runNpm(targetDir, ["run", "uniform:publish"]);
3516
+ await done();
3517
+ telemetry.send("flow finished");
3518
+ console.log(`
3519
+ See your Uniform project and edit compositions by visiting:
3520
+ ${makeUrl(apiHost, `/projects/${projectId}`)}
3521
+
3522
+ `);
3523
+ if (process.platform.startsWith("win")) {
3524
+ console.log(`
3525
+ Start your app server by executing:
3526
+ cd ${targetDir}
3527
+ npm run dev
3528
+ `);
3529
+ } else {
3530
+ console.log(`
3531
+ Hit Ctrl+C to exit; to run the server again execute:
3532
+ cd ${targetDir}
3533
+ npm run dev
3534
+ `);
3535
+ console.log(`Your app is running at ${serverUrl} \u{1F389}
3536
+ `);
3537
+ telemetry.send("server started");
3538
+ await runNpm(targetDir, ["run", "dev"]);
3539
+ }
3540
+ }
3541
+
3542
+ // src/commands/new/commands/new-mesh-integration.ts
3543
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readdirSync, readFileSync, writeFileSync } from "fs";
3544
+ import inquirer5 from "inquirer";
3545
+ import path3 from "path";
3546
+ import slugify2 from "slugify";
3547
+ async function newMeshIntegrationHandler({
3548
+ spin,
3549
+ apiHost,
3550
+ outputPath,
3551
+ telemetry
3552
+ }) {
3553
+ console.info(`Welcome to Uniform New Integration! Let's create a new Uniform integration... \u2764\uFE0F`);
3554
+ const auth = await getBearerToken(apiHost);
3555
+ const { authToken } = auth;
3556
+ const uniformClient = createClient(apiHost, authToken);
3557
+ const user = await fetchUserAndEnsureFirstTeamExists({ auth, baseUrl: apiHost, spin, telemetry });
3558
+ const { teamId } = await chooseTeam(
3559
+ user,
3560
+ `Hey ${user.name}! Choose a Uniform team to register your integration`,
3561
+ telemetry
3562
+ );
3563
+ const answer = await inquirer5.prompt([
3564
+ {
3565
+ type: "input",
3566
+ name: "name",
3567
+ message: "Please name your integration",
3568
+ validate(input) {
3569
+ try {
3570
+ validateIntegrationName(input, outputPath);
3571
+ return true;
3572
+ } catch (e) {
3573
+ return e.message;
3574
+ }
3575
+ }
3576
+ }
3577
+ ]);
3578
+ const name = answer.name;
3579
+ const { targetDir, typeSlug } = validateIntegrationName(answer.name, outputPath);
3580
+ const { runNpmInstall } = await cloneStarter({
3581
+ githubPath: `uniformdev/examples/examples/mesh-integration`,
3582
+ spin,
3583
+ targetDir
3584
+ });
3585
+ let done = await spin("Registering integration to team...");
3586
+ const pathToManifest = path3.resolve(targetDir, "mesh-manifest.json");
3587
+ if (!existsSync2(pathToManifest)) {
3588
+ throw new Error("Invalid integration starter cloned: missing `mesh-manifest.json`");
3589
+ }
3590
+ const manifestContents = readFileSync(pathToManifest, "utf-8");
3591
+ const manifestJson = JSON.parse(manifestContents);
3592
+ manifestJson.type = typeSlug;
3593
+ manifestJson.displayName = name;
3594
+ writeFileSync(pathToManifest, JSON.stringify(manifestJson, null, 2), "utf-8");
3595
+ const packageJsonPath = path3.resolve(targetDir, "package.json");
3596
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
3597
+ packageJson.name = typeSlug;
3598
+ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf-8");
3599
+ const fullMeshAppKey = await uniformClient.registerMeshIntegration({ teamId, manifest: manifestJson });
3600
+ await done();
3601
+ await runNpmInstall();
3602
+ console.log("\n\nChoose or create a project to install your integration to");
3603
+ const { projectId } = await getOrCreateProject({
3604
+ client: uniformClient,
3605
+ createNew: true,
3606
+ chooseExisting: true,
3607
+ spin,
3608
+ teamId,
3609
+ user,
3610
+ checkTargetDir: false,
3611
+ telemetry
3612
+ });
3613
+ done = await spin("Installing integration to project...");
3614
+ await uniformClient.installIntegration({ projectId, type: typeSlug });
3615
+ await done();
3616
+ console.log(`
3617
+ Hit Ctrl/Cmd+C to exit; to run the mesh integration application again, execute:
3618
+
3619
+ cd ${targetDir}
3620
+ npm run dev
3621
+
3622
+ See your integration registration by visiting:
3623
+
3624
+ ${makeUrl(apiHost, `/teams/${teamId}/settings/custom-integrations`)}
3625
+
3626
+ See your integration's settings location by visiting:
3627
+
3628
+ ${makeUrl(apiHost, `/projects/${projectId}/integrations/${fullMeshAppKey}`)}
3629
+
3630
+ `);
3631
+ console.log("Your integration is running at http://localhost:9000 \u{1F389}\n");
3632
+ await runNpm(targetDir, ["run", "dev"], { inherit: true });
3633
+ }
3634
+ function validateIntegrationName(integrationName, explicitOutputPath) {
3635
+ integrationName = integrationName.trim();
3636
+ const typeSlug = slugify2(integrationName, { lower: true });
3637
+ if (integrationName.length < 6 || typeSlug.length < 6) {
3638
+ throw new Error("Integration name cannot be shorter than 6 characters.");
3639
+ }
3640
+ let targetDir = explicitOutputPath != null ? explicitOutputPath : process.cwd();
3641
+ if (!existsSync2(targetDir)) {
3642
+ mkdirSync2(targetDir, { recursive: true });
3643
+ }
3644
+ if (readdirSync(targetDir).length > 0) {
3645
+ targetDir = path3.resolve(targetDir, typeSlug);
3646
+ if (existsSync2(targetDir)) {
3647
+ throw new Error(`${targetDir} directory already exists, choose a different name.`);
3648
+ }
3649
+ }
3650
+ return { targetDir, typeSlug };
3651
+ }
3652
+
3653
+ // src/commands/new/index.ts
3654
+ var stableApiHost = "https://uniform.app";
3655
+ var apiHostDefault = process.env.UNIFORM_CLI_BASE_URL || stableApiHost;
3656
+ var disableTelemetryDefault = !["", "0", "false", "no"].includes(
3657
+ process.env.UNIFORM_CLI_DISABLE_TELEMETRY || ""
3658
+ );
3659
+ var NewCmd = {
3660
+ command: "new [name]",
3661
+ builder: (y) => y.positional("name", {
3662
+ describe: "Name of a project",
3663
+ type: "string"
3664
+ }).option("apiHost", {
3665
+ describe: `Uniform host. Defaults to UNIFORM_CLI_BASE_URL env or ${stableApiHost}. Supports dotenv.`,
3666
+ default: apiHostDefault,
3667
+ demandOption: true,
3668
+ type: "string"
3669
+ }).option("outputPath", {
3670
+ alias: "o",
3671
+ description: "Specify where to store integration files. Defaults to cwd.",
3672
+ type: "string"
3673
+ }).option("disableTelemetry", {
3674
+ describe: "By default, usage information is sent to Uniform. Use this option or set UNIFORM_CLI_DISABLE_TELEMETRY to disable telemetry.",
3675
+ default: disableTelemetryDefault,
3676
+ demandOption: true,
3677
+ type: "boolean"
3678
+ }),
3679
+ describe: "Start a new Uniform project",
3680
+ handler: async function({ name, apiHost, outputPath, disableTelemetry }) {
3681
+ const { stopAllSpinners, spin } = makeSpinner();
3682
+ const telemetry = new Telemetry("cli new", disableTelemetry || apiHost !== stableApiHost);
3683
+ try {
3684
+ await newHandler({ spin, projectName: name, apiHost, outputPath, telemetry });
3685
+ stopAllSpinners();
3686
+ process.exit(0);
3687
+ } catch (err) {
3688
+ stopAllSpinners();
3689
+ telemetry.send("flow errored", { message: err.message });
3690
+ console.error(err.message);
3691
+ process.exitCode = 1;
3692
+ } finally {
3693
+ await telemetry.shutdown();
3694
+ }
3695
+ }
3696
+ };
3697
+ var NewMeshCmd = {
3698
+ command: "new-integration",
3699
+ builder: (y) => y.option("apiHost", {
3700
+ describe: `Uniform host. Defaults to UNIFORM_CLI_BASE_URL env or ${stableApiHost}. Supports dotenv.`,
3701
+ default: apiHostDefault,
3702
+ demandOption: true,
3703
+ type: "string"
3704
+ }).option("outputPath", {
3705
+ alias: "o",
3706
+ description: "Specify where to store integration files. Defaults to cwd.",
3707
+ type: "string"
3708
+ }).option("disableTelemetry", {
3709
+ describe: "By default, usage information is sent to Uniform. Use this option or set UNIFORM_CLI_DISABLE_TELEMETRY to disable telemetry.",
3710
+ default: disableTelemetryDefault,
3711
+ demandOption: true,
3712
+ type: "boolean"
3713
+ }),
3714
+ describe: "Start a new Uniform project",
3715
+ handler: async function({ apiHost, outputPath, disableTelemetry }) {
3716
+ const { stopAllSpinners, spin } = makeSpinner();
3717
+ const telemetry = new Telemetry("cli new mesh", disableTelemetry || apiHost !== stableApiHost);
3718
+ try {
3719
+ await newMeshIntegrationHandler({ spin, apiHost, outputPath, telemetry });
3720
+ stopAllSpinners();
3721
+ process.exit(0);
3722
+ } catch (err) {
3723
+ stopAllSpinners();
3724
+ telemetry.send("flow errored", { message: err.message });
3725
+ console.error(err.message);
3726
+ process.exitCode = 1;
3727
+ } finally {
3728
+ await telemetry.shutdown();
3729
+ }
3730
+ }
3731
+ };
3732
+
3733
+ // src/commands/optimize/index.ts
3734
+ import yargs13 from "yargs";
13
3735
 
14
3736
  // src/commands/optimize/manifest.ts
15
- import yargs from "yargs";
3737
+ import yargs12 from "yargs";
16
3738
 
17
3739
  // src/commands/optimize/manifest/download.ts
18
- var import_chalk = __toESM(require_source());
19
- import { writeFile } from "fs";
20
- import fetch from "isomorphic-unfetch";
21
- import { exit } from "process";
3740
+ var import_chalk3 = __toESM(require_source());
3741
+ import { writeFile as writeFile2 } from "fs";
3742
+ import fetch2 from "isomorphic-unfetch";
3743
+ import { exit as exit3 } from "process";
22
3744
 
23
3745
  // src/constants.ts
24
3746
  var UniformBaseUrl = "https://uniform.app";
@@ -27,9 +3749,9 @@ var UniformBaseUrl = "https://uniform.app";
27
3749
  var module = {
28
3750
  command: "download [output]",
29
3751
  describe: "Download intent manifest",
30
- builder: (yargs4) => {
3752
+ builder: (yargs18) => {
31
3753
  var _a;
32
- return yargs4.option("apiKey", {
3754
+ return yargs18.option("apiKey", {
33
3755
  alias: "k",
34
3756
  demandOption: true,
35
3757
  string: true,
@@ -58,13 +3780,13 @@ var module = {
58
3780
  );
59
3781
  if (isLegacyApiKey) {
60
3782
  console.error(
61
- import_chalk.default.yellow(
3783
+ import_chalk3.default.yellow(
62
3784
  "WARNING: you appear to be using a deprecated type of API key. Keys like this will stop working soon; please create new keys on uniform.app."
63
3785
  )
64
3786
  );
65
3787
  } else if (!project) {
66
- console.error(import_chalk.default.red("You must specify the project ID"));
67
- exit(1);
3788
+ console.error(import_chalk3.default.red("You must specify the project ID"));
3789
+ exit3(1);
68
3790
  }
69
3791
  const baseUrl = resolveBaseUrl();
70
3792
  const qs = new URLSearchParams();
@@ -77,7 +3799,7 @@ var module = {
77
3799
  const manifestUrl = `${baseUrl}api/v1/manifest?${qs.toString()}`;
78
3800
  let fetchResponse = void 0;
79
3801
  try {
80
- fetchResponse = await fetch(manifestUrl, {
3802
+ fetchResponse = await fetch2(manifestUrl, {
81
3803
  headers: {
82
3804
  "x-api-key": apiKey
83
3805
  }
@@ -89,28 +3811,28 @@ var module = {
89
3811
  throw `${fetchResponse.status} ${fetchResponse.statusText}, content ${await fetchResponse.text()}`;
90
3812
  }
91
3813
  } catch (e) {
92
- console.error(import_chalk.default.red(`\u26A0 Error fetching intent manifest ${manifestUrl}`));
93
- console.error(import_chalk.default.gray(` \u2757 ${e}`));
94
- exit(1);
3814
+ console.error(import_chalk3.default.red(`\u26A0 Error fetching intent manifest ${manifestUrl}`));
3815
+ console.error(import_chalk3.default.gray(` \u2757 ${e}`));
3816
+ exit3(1);
95
3817
  }
96
3818
  let json;
97
3819
  try {
98
3820
  json = await fetchResponse.json();
99
3821
  } catch (e) {
100
- console.error(import_chalk.default.red(import_chalk.default.red(`\u26A0 Error parsing intent manifest ${manifestUrl}`)));
101
- console.error(import_chalk.default.gray(` \u2757 ${e}`));
3822
+ console.error(import_chalk3.default.red(import_chalk3.default.red(`\u26A0 Error parsing intent manifest ${manifestUrl}`)));
3823
+ console.error(import_chalk3.default.gray(` \u2757 ${e}`));
102
3824
  console.error(`Response: ${await fetchResponse.text()}`);
103
- exit(1);
3825
+ exit3(1);
104
3826
  }
105
3827
  const text = JSON.stringify(json, null, 2);
106
3828
  if (output) {
107
- writeFile(output, text, (error) => {
3829
+ writeFile2(output, text, (error) => {
108
3830
  if (error) {
109
3831
  console.error(`Error writing file to ${output}
110
3832
  `, error);
111
- exit(1);
3833
+ exit3(1);
112
3834
  }
113
- console.log(import_chalk.default.green(`\u2705 ${output} has been updated from ${manifestUrl}`));
3835
+ console.log(import_chalk3.default.green(`\u2705 ${output} has been updated from ${manifestUrl}`));
114
3836
  });
115
3837
  } else {
116
3838
  console.log(text);
@@ -131,45 +3853,620 @@ var module2 = {
131
3853
  command: "manifest <command>",
132
3854
  describe: "Intent manifest commands",
133
3855
  builder: () => {
134
- return yargs.command(download_default);
3856
+ return yargs12.command(download_default);
135
3857
  },
136
3858
  handler: () => {
137
- return yargs.showHelp();
3859
+ yargs12.showHelp();
138
3860
  }
139
3861
  };
140
3862
  var manifest_default = module2;
141
3863
 
142
- // src/commands/optimize.ts
143
- var command = {
3864
+ // src/commands/optimize/index.ts
3865
+ var OptimizeCommand = {
144
3866
  command: "optimize <command>",
145
3867
  aliases: ["opt"],
146
3868
  describe: "Uniform Optimize commands",
147
3869
  builder: () => {
148
- return yargs2.command(manifest_default);
3870
+ return yargs13.command(manifest_default);
149
3871
  },
150
3872
  handler: () => {
151
- return yargs2.showHelp();
3873
+ yargs13.showHelp();
152
3874
  }
153
3875
  };
154
- var optimize_default = command;
155
3876
 
156
- // src/index.ts
157
- __require("dotenv").config();
158
- var plugins = [
159
- "@uniformdev/canvas/cli",
160
- "@uniformdev/context/cli",
161
- "@uniformdev/project-map/cli",
162
- "@uniformdev/uniform-new"
163
- ];
164
- var yarggery = yargs3.scriptName("uniform");
165
- plugins.flatMap((plugin) => {
166
- try {
167
- const commands = __require(plugin).uniformCLI.commands;
168
- const commandsToAdd = Array.isArray(commands) ? commands : [];
169
- commandsToAdd.forEach((command2) => {
170
- yarggery = yarggery.command(command2);
3877
+ // src/commands/project-map/index.ts
3878
+ import yargs16 from "yargs";
3879
+
3880
+ // src/commands/project-map/commands/projectMapDefinition.ts
3881
+ import yargs14 from "yargs";
3882
+
3883
+ // src/commands/project-map/commands/ProjectMapDefinition/get.ts
3884
+ import { UncachedProjectMapClient } from "@uniformdev/project-map";
3885
+ var ProjectMapDefinitionGetModule = {
3886
+ command: "get <id>",
3887
+ describe: "Fetch a project map",
3888
+ builder: (yargs18) => withFormatOptions(
3889
+ withApiOptions(
3890
+ withProjectOptions(
3891
+ yargs18.positional("id", { demandOption: true, describe: "ProjectMap UUID to fetch" })
3892
+ )
3893
+ )
3894
+ ),
3895
+ handler: async ({ apiHost, apiKey, proxy, id, format, project: projectId, filename }) => {
3896
+ const fetch3 = nodeFetchProxy(proxy);
3897
+ const client = new UncachedProjectMapClient({ apiKey, apiHost, fetch: fetch3, projectId });
3898
+ const res = await client.getProjectMapDefinition({ projectMapId: id });
3899
+ if (res.projectMaps.length === 0) {
3900
+ console.error("ProjectMap does not exist");
3901
+ process.exit(1);
3902
+ } else {
3903
+ emitWithFormat(res.projectMaps[0], format, filename);
3904
+ }
3905
+ }
3906
+ };
3907
+
3908
+ // src/commands/project-map/commands/ProjectMapDefinition/list.ts
3909
+ import { UncachedProjectMapClient as UncachedProjectMapClient2 } from "@uniformdev/project-map";
3910
+ var ProjectMapDefinitionListModule = {
3911
+ command: "list",
3912
+ describe: "List of project maps",
3913
+ aliases: ["ls"],
3914
+ builder: (yargs18) => withFormatOptions(withApiOptions(withProjectOptions(yargs18))),
3915
+ handler: async ({ apiHost, apiKey, proxy, format, filename, project: projectId }) => {
3916
+ const fetch3 = nodeFetchProxy(proxy);
3917
+ const client = new UncachedProjectMapClient2({ apiKey, apiHost, fetch: fetch3, projectId });
3918
+ const res = await client.getProjectMapDefinitions();
3919
+ emitWithFormat(res.projectMaps, format, filename);
3920
+ }
3921
+ };
3922
+
3923
+ // src/commands/project-map/commands/ProjectMapDefinition/pull.ts
3924
+ import { UncachedProjectMapClient as UncachedProjectMapClient3 } from "@uniformdev/project-map";
3925
+
3926
+ // src/commands/project-map/package.ts
3927
+ function readContextPackage2(filename, assertExists) {
3928
+ return readUniformPackage(filename, assertExists);
3929
+ }
3930
+ function writeContextPackage2(filename, packageContents) {
3931
+ writeUniformPackage(filename, packageContents);
3932
+ }
3933
+
3934
+ // src/commands/project-map/commands/ProjectMapDefinition/_util.ts
3935
+ var selectIdentifier9 = (source) => source.id;
3936
+ var selectDisplayName9 = (source) => `${source.name} (pid: ${source.id})`;
3937
+
3938
+ // src/commands/project-map/ProjectMapDefinitionEngineDataSource.ts
3939
+ function createProjectMapDefinitionEngineDataSource({
3940
+ client
3941
+ }) {
3942
+ async function* getObjects() {
3943
+ const projectMaps = (await client.getProjectMapDefinitions()).projectMaps;
3944
+ for await (const def of projectMaps) {
3945
+ const result = {
3946
+ id: selectIdentifier9(def),
3947
+ displayName: selectDisplayName9(def),
3948
+ providerId: selectIdentifier9(def),
3949
+ object: def
3950
+ };
3951
+ yield result;
3952
+ }
3953
+ }
3954
+ return {
3955
+ objects: getObjects(),
3956
+ deleteObject: async (providerId) => {
3957
+ await client.deleteProjectMap({ projectMapId: providerId });
3958
+ },
3959
+ writeObject: async (object) => {
3960
+ await client.upsertProjectMap({
3961
+ projectMap: object.object
3962
+ });
3963
+ }
3964
+ };
3965
+ }
3966
+
3967
+ // src/commands/project-map/commands/ProjectMapDefinition/pull.ts
3968
+ var ProjectMapDefinitionPullModule = {
3969
+ command: "pull <directory>",
3970
+ describe: "Pulls all project maps to local files in a directory",
3971
+ builder: (yargs18) => withApiOptions(
3972
+ withProjectOptions(
3973
+ withDiffOptions(
3974
+ yargs18.positional("directory", {
3975
+ describe: "Directory to save project maps to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
3976
+ type: "string"
3977
+ }).option("format", {
3978
+ alias: ["f"],
3979
+ describe: "Output format",
3980
+ default: "yaml",
3981
+ choices: ["yaml", "json"],
3982
+ type: "string"
3983
+ }).option("what-if", {
3984
+ alias: ["w"],
3985
+ describe: "What-if mode reports what would be done but changes no files",
3986
+ default: false,
3987
+ type: "boolean"
3988
+ }).option("mode", {
3989
+ alias: ["m"],
3990
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
3991
+ choices: ["create", "createOrUpdate", "mirror"],
3992
+ default: "mirror",
3993
+ type: "string"
3994
+ })
3995
+ )
3996
+ )
3997
+ ),
3998
+ handler: async ({
3999
+ apiHost,
4000
+ apiKey,
4001
+ proxy,
4002
+ directory,
4003
+ format,
4004
+ mode,
4005
+ whatIf,
4006
+ project: projectId,
4007
+ diff: diffMode
4008
+ }) => {
4009
+ var _a;
4010
+ const fetch3 = nodeFetchProxy(proxy);
4011
+ const client = new UncachedProjectMapClient3({ apiKey, apiHost, fetch: fetch3, projectId });
4012
+ const source = createProjectMapDefinitionEngineDataSource({ client });
4013
+ let target;
4014
+ const isPackage = isPathAPackageFile(directory);
4015
+ if (isPackage) {
4016
+ const packageContents = readContextPackage2(directory, false);
4017
+ target = await createArraySyncEngineDataSource({
4018
+ objects: (_a = packageContents.projectMaps) != null ? _a : [],
4019
+ selectIdentifier: selectIdentifier9,
4020
+ selectDisplayName: selectDisplayName9,
4021
+ onSyncComplete: async (_, synced) => {
4022
+ packageContents.projectMaps = synced;
4023
+ writeContextPackage2(directory, packageContents);
4024
+ }
4025
+ });
4026
+ } else {
4027
+ target = await createFileSyncEngineDataSource({
4028
+ directory,
4029
+ selectIdentifier: selectIdentifier9,
4030
+ selectDisplayName: selectDisplayName9,
4031
+ format
4032
+ });
4033
+ }
4034
+ await syncEngine({
4035
+ source,
4036
+ target,
4037
+ mode,
4038
+ whatIf,
4039
+ log: createSyncEngineConsoleLogger({ diffMode })
171
4040
  });
172
- } catch (e) {
173
4041
  }
174
- });
175
- yarggery.command(optimize_default).demandCommand(1, "").strict().help().argv;
4042
+ };
4043
+
4044
+ // src/commands/project-map/commands/ProjectMapDefinition/push.ts
4045
+ import { UncachedProjectMapClient as UncachedProjectMapClient4 } from "@uniformdev/project-map";
4046
+ var ProjectMapDefinitionPushModule = {
4047
+ command: "push <directory>",
4048
+ describe: "Pushes all project maps from files in a directory or package to Uniform",
4049
+ builder: (yargs18) => withApiOptions(
4050
+ withProjectOptions(
4051
+ withDiffOptions(
4052
+ yargs18.positional("directory", {
4053
+ describe: "Directory to read project maps from. If a filename is used, a package will be read instead.",
4054
+ type: "string"
4055
+ }).option("what-if", {
4056
+ alias: ["w"],
4057
+ describe: "What-if mode reports what would be done but changes nothing",
4058
+ default: false,
4059
+ type: "boolean"
4060
+ }).option("mode", {
4061
+ alias: ["m"],
4062
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
4063
+ choices: ["create", "createOrUpdate", "mirror"],
4064
+ default: "mirror",
4065
+ type: "string"
4066
+ })
4067
+ )
4068
+ )
4069
+ ),
4070
+ handler: async ({
4071
+ apiHost,
4072
+ apiKey,
4073
+ proxy,
4074
+ directory,
4075
+ mode,
4076
+ whatIf,
4077
+ project: projectId,
4078
+ diff: diffMode
4079
+ }) => {
4080
+ var _a;
4081
+ const fetch3 = nodeFetchProxy(proxy);
4082
+ const client = new UncachedProjectMapClient4({ apiKey, apiHost, fetch: fetch3, projectId });
4083
+ let source;
4084
+ const isPackage = isPathAPackageFile(directory);
4085
+ if (isPackage) {
4086
+ const packageContents = readContextPackage2(directory, true);
4087
+ source = await createArraySyncEngineDataSource({
4088
+ objects: (_a = packageContents.projectMaps) != null ? _a : [],
4089
+ selectIdentifier: selectIdentifier9,
4090
+ selectDisplayName: selectDisplayName9
4091
+ });
4092
+ } else {
4093
+ source = await createFileSyncEngineDataSource({
4094
+ directory,
4095
+ selectIdentifier: selectIdentifier9,
4096
+ selectDisplayName: selectDisplayName9
4097
+ });
4098
+ }
4099
+ const target = createProjectMapDefinitionEngineDataSource({ client });
4100
+ await syncEngine({
4101
+ source,
4102
+ target,
4103
+ mode,
4104
+ whatIf,
4105
+ log: createSyncEngineConsoleLogger({ diffMode })
4106
+ });
4107
+ }
4108
+ };
4109
+
4110
+ // src/commands/project-map/commands/ProjectMapDefinition/remove.ts
4111
+ import { UncachedProjectMapClient as UncachedProjectMapClient5 } from "@uniformdev/project-map";
4112
+ var ProjectMapDefinitionRemoveModule = {
4113
+ command: "remove <id>",
4114
+ aliases: ["delete", "rm"],
4115
+ describe: "Delete a project map",
4116
+ builder: (yargs18) => withApiOptions(
4117
+ withProjectOptions(yargs18.positional("id", { demandOption: true, describe: " UUID to delete" }))
4118
+ ),
4119
+ handler: async ({ apiHost, apiKey, proxy, id, project: projectId }) => {
4120
+ const fetch3 = nodeFetchProxy(proxy);
4121
+ const client = new UncachedProjectMapClient5({ apiKey, apiHost, fetch: fetch3, projectId });
4122
+ await client.deleteProjectMap({ projectMapId: id });
4123
+ }
4124
+ };
4125
+
4126
+ // src/commands/project-map/commands/ProjectMapDefinition/update.ts
4127
+ import { UncachedProjectMapClient as UncachedProjectMapClient6 } from "@uniformdev/project-map";
4128
+ var ProjectMapDefinitionUpdateModule = {
4129
+ command: "update <filename>",
4130
+ aliases: ["put"],
4131
+ describe: "Insert or update a project map",
4132
+ builder: (yargs18) => withApiOptions(
4133
+ withProjectOptions(
4134
+ yargs18.positional("filename", { demandOption: true, describe: "Project map file to put" })
4135
+ )
4136
+ ),
4137
+ handler: async ({ apiHost, apiKey, proxy, filename, project: projectId }) => {
4138
+ const fetch3 = nodeFetchProxy(proxy);
4139
+ const client = new UncachedProjectMapClient6({ apiKey, apiHost, fetch: fetch3, projectId });
4140
+ const file = readFileToObject(filename);
4141
+ await client.upsertProjectMap({ projectMap: file });
4142
+ }
4143
+ };
4144
+
4145
+ // src/commands/project-map/commands/projectMapDefinition.ts
4146
+ var ProjectMapDefinitionModule = {
4147
+ command: "definition <command>",
4148
+ describe: "Commands for ProjectMap Definitions",
4149
+ builder: (yargs18) => yargs18.command(ProjectMapDefinitionPullModule).command(ProjectMapDefinitionPushModule).command(ProjectMapDefinitionGetModule).command(ProjectMapDefinitionRemoveModule).command(ProjectMapDefinitionListModule).command(ProjectMapDefinitionUpdateModule).demandCommand(),
4150
+ handler: () => {
4151
+ yargs14.help();
4152
+ }
4153
+ };
4154
+
4155
+ // src/commands/project-map/commands/projectMapNode.ts
4156
+ import yargs15 from "yargs";
4157
+
4158
+ // src/commands/project-map/commands/ProjectMapNode/get.ts
4159
+ import { UncachedProjectMapClient as UncachedProjectMapClient7 } from "@uniformdev/project-map";
4160
+ var ProjectMapNodeGetModule = {
4161
+ command: "get <id> <projectMapId>",
4162
+ describe: "Fetch a project map node",
4163
+ builder: (yargs18) => withFormatOptions(
4164
+ withApiOptions(
4165
+ withProjectOptions(
4166
+ yargs18.positional("id", { demandOption: true, describe: "ProjectMap Node UUID to fetch" }).positional("projectMapId", { demandOption: true, describe: "ProjectMap UUID to fetch from" })
4167
+ )
4168
+ )
4169
+ ),
4170
+ handler: async ({ apiHost, apiKey, proxy, id, projectMapId, format, project: projectId, filename }) => {
4171
+ var _a, _b;
4172
+ const fetch3 = nodeFetchProxy(proxy);
4173
+ const client = new UncachedProjectMapClient7({ apiKey, apiHost, fetch: fetch3, projectId });
4174
+ console.log("Debugging params for node get", { projectMapId, id, projectId });
4175
+ const res = await client.getNodes({ projectMapId, id });
4176
+ if (((_a = res.nodes) == null ? void 0 : _a.length) === 0) {
4177
+ console.error("Project map node does not exist");
4178
+ process.exit(1);
4179
+ } else {
4180
+ emitWithFormat({ nodes: (_b = res.nodes) != null ? _b : [], projectMapId }, format, filename);
4181
+ }
4182
+ }
4183
+ };
4184
+
4185
+ // src/commands/project-map/commands/ProjectMapNode/list.ts
4186
+ import { UncachedProjectMapClient as UncachedProjectMapClient8 } from "@uniformdev/project-map";
4187
+ var ProjectMapNodeListModule = {
4188
+ command: "list <projectMapId>",
4189
+ describe: "List project map nodes",
4190
+ aliases: ["ls"],
4191
+ builder: (yargs18) => withFormatOptions(
4192
+ withApiOptions(
4193
+ withProjectOptions(
4194
+ yargs18.positional("projectMapId", { demandOption: true, describe: "ProjectMap UUID to fetch from" })
4195
+ )
4196
+ )
4197
+ ),
4198
+ handler: async ({ apiHost, apiKey, proxy, projectMapId, format, filename, project: projectId }) => {
4199
+ var _a;
4200
+ const fetch3 = nodeFetchProxy(proxy);
4201
+ const client = new UncachedProjectMapClient8({ apiKey, apiHost, fetch: fetch3, projectId });
4202
+ const res = await client.getNodes({ projectMapId });
4203
+ emitWithFormat({ nodes: (_a = res.nodes) != null ? _a : [], projectMapId }, format, filename);
4204
+ }
4205
+ };
4206
+
4207
+ // src/commands/project-map/commands/ProjectMapNode/pull.ts
4208
+ import { UncachedProjectMapClient as UncachedProjectMapClient9 } from "@uniformdev/project-map";
4209
+
4210
+ // src/commands/project-map/commands/ProjectMapNode/_util.ts
4211
+ var selectIdentifier10 = (source, projectId) => projectId + source.projectMapId + source.id + source.path;
4212
+ var selectFilename = (source) => `${source.pathSegment}_${source.id}`;
4213
+ var selectDisplayName10 = (source) => `${source.name} (pid: ${source.id})`;
4214
+
4215
+ // src/commands/project-map/ProjectMapNodeEngineDataSource.ts
4216
+ function createProjectMapNodeEngineDataSource({
4217
+ client,
4218
+ projectId
4219
+ }) {
4220
+ async function* getObjects() {
4221
+ const projectMaps = (await client.getProjectMapDefinitions()).projectMaps;
4222
+ for (const projectMap of projectMaps) {
4223
+ const nodes = (await client.getNodes({ projectMapId: projectMap.id })).nodes;
4224
+ for await (const def of nodes != null ? nodes : []) {
4225
+ if (def) {
4226
+ const result = {
4227
+ id: selectIdentifier10({ ...def, projectMapId: projectMap.id }, projectId),
4228
+ displayName: selectDisplayName10(def),
4229
+ providerId: selectIdentifier10({ ...def, projectMapId: projectMap.id }, projectId),
4230
+ object: { ...def, projectMapId: projectMap.id }
4231
+ };
4232
+ yield result;
4233
+ }
4234
+ }
4235
+ }
4236
+ }
4237
+ return {
4238
+ objects: getObjects(),
4239
+ deleteObject: async (providerId, object) => {
4240
+ await client.deleteProjectMapNode({
4241
+ nodeId: object.object.id,
4242
+ projectMapId: object.object.projectMapId
4243
+ });
4244
+ },
4245
+ writeObject: async (object) => {
4246
+ const nodeToUpsert = { ...object.object };
4247
+ await client.upsertProjectMapNodes({
4248
+ projectMapId: object.object.projectMapId,
4249
+ nodes: [{ node: nodeToUpsert }]
4250
+ });
4251
+ }
4252
+ };
4253
+ }
4254
+
4255
+ // src/commands/project-map/commands/ProjectMapNode/pull.ts
4256
+ var ProjectMapNodePullModule = {
4257
+ command: "pull <directory>",
4258
+ describe: "Pulls all project maps nodes to local files in a directory",
4259
+ builder: (yargs18) => withApiOptions(
4260
+ withProjectOptions(
4261
+ withDiffOptions(
4262
+ yargs18.positional("directory", {
4263
+ describe: "Directory to save project maps to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",
4264
+ type: "string"
4265
+ }).option("format", {
4266
+ alias: ["f"],
4267
+ describe: "Output format",
4268
+ default: "yaml",
4269
+ choices: ["yaml", "json"],
4270
+ type: "string"
4271
+ }).option("what-if", {
4272
+ alias: ["w"],
4273
+ describe: "What-if mode reports what would be done but changes no files",
4274
+ default: false,
4275
+ type: "boolean"
4276
+ }).option("mode", {
4277
+ alias: ["m"],
4278
+ describe: 'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',
4279
+ choices: ["create", "createOrUpdate", "mirror"],
4280
+ default: "mirror",
4281
+ type: "string"
4282
+ })
4283
+ )
4284
+ )
4285
+ ),
4286
+ handler: async ({
4287
+ apiHost,
4288
+ apiKey,
4289
+ proxy,
4290
+ directory,
4291
+ format,
4292
+ mode,
4293
+ whatIf,
4294
+ project: projectId,
4295
+ diff: diffMode
4296
+ }) => {
4297
+ var _a;
4298
+ const fetch3 = nodeFetchProxy(proxy);
4299
+ const client = new UncachedProjectMapClient9({ apiKey, apiHost, fetch: fetch3, projectId });
4300
+ const source = createProjectMapNodeEngineDataSource({ client, projectId });
4301
+ let target;
4302
+ const isPackage = isPathAPackageFile(directory);
4303
+ const expandedSelectIdentifier = (object) => {
4304
+ return selectIdentifier10(object, projectId);
4305
+ };
4306
+ if (isPackage) {
4307
+ const packageContents = readContextPackage2(directory, false);
4308
+ target = await createArraySyncEngineDataSource({
4309
+ objects: (_a = packageContents.projectMapNodes) != null ? _a : [],
4310
+ selectIdentifier: expandedSelectIdentifier,
4311
+ selectDisplayName: selectDisplayName10,
4312
+ onSyncComplete: async (_, synced) => {
4313
+ packageContents.projectMapNodes = synced;
4314
+ writeContextPackage2(directory, packageContents);
4315
+ }
4316
+ });
4317
+ } else {
4318
+ target = await createFileSyncEngineDataSource({
4319
+ directory,
4320
+ selectIdentifier: expandedSelectIdentifier,
4321
+ selectDisplayName: selectDisplayName10,
4322
+ format,
4323
+ selectFilename
4324
+ });
4325
+ }
4326
+ await syncEngine({
4327
+ source,
4328
+ target,
4329
+ mode,
4330
+ whatIf,
4331
+ log: createSyncEngineConsoleLogger({ diffMode })
4332
+ });
4333
+ }
4334
+ };
4335
+
4336
+ // src/commands/project-map/commands/ProjectMapNode/push.ts
4337
+ import { UncachedProjectMapClient as UncachedProjectMapClient10 } from "@uniformdev/project-map";
4338
+ var ProjectMapNodePushModule = {
4339
+ command: "push <directory>",
4340
+ describe: "Pushes all project maps nodes from files in a directory or package to Uniform",
4341
+ builder: (yargs18) => withApiOptions(
4342
+ withProjectOptions(
4343
+ withDiffOptions(
4344
+ yargs18.positional("directory", {
4345
+ describe: "Directory to read project maps from. If a filename is used, a package will be read instead.",
4346
+ type: "string"
4347
+ }).option("what-if", {
4348
+ alias: ["w"],
4349
+ describe: "What-if mode reports what would be done but changes nothing",
4350
+ default: false,
4351
+ type: "boolean"
4352
+ }).option("mode", {
4353
+ alias: ["m"],
4354
+ describe: 'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',
4355
+ choices: ["create", "createOrUpdate", "mirror"],
4356
+ default: "mirror",
4357
+ type: "string"
4358
+ })
4359
+ )
4360
+ )
4361
+ ),
4362
+ handler: async ({
4363
+ apiHost,
4364
+ apiKey,
4365
+ proxy,
4366
+ directory,
4367
+ mode,
4368
+ whatIf,
4369
+ project: projectId,
4370
+ diff: diffMode
4371
+ }) => {
4372
+ var _a;
4373
+ const fetch3 = nodeFetchProxy(proxy);
4374
+ const client = new UncachedProjectMapClient10({
4375
+ apiKey,
4376
+ apiHost,
4377
+ fetch: fetch3,
4378
+ projectId
4379
+ });
4380
+ let source;
4381
+ const isPackage = isPathAPackageFile(directory);
4382
+ const expandedSelectIdentifier = (object) => {
4383
+ return selectIdentifier10(object, projectId);
4384
+ };
4385
+ if (isPackage) {
4386
+ const packageContents = readContextPackage2(directory, true);
4387
+ source = await createArraySyncEngineDataSource({
4388
+ objects: (_a = packageContents.projectMapNodes) != null ? _a : [],
4389
+ selectIdentifier: expandedSelectIdentifier,
4390
+ selectDisplayName: selectDisplayName10
4391
+ });
4392
+ } else {
4393
+ source = await createFileSyncEngineDataSource({
4394
+ directory,
4395
+ selectIdentifier: expandedSelectIdentifier,
4396
+ selectDisplayName: selectDisplayName10,
4397
+ selectFilename
4398
+ });
4399
+ }
4400
+ const target = createProjectMapNodeEngineDataSource({ client, projectId });
4401
+ await syncEngine({
4402
+ source,
4403
+ target,
4404
+ mode,
4405
+ whatIf,
4406
+ log: createSyncEngineConsoleLogger({ diffMode })
4407
+ });
4408
+ }
4409
+ };
4410
+
4411
+ // src/commands/project-map/commands/ProjectMapNode/remove.ts
4412
+ import { UncachedProjectMapClient as UncachedProjectMapClient11 } from "@uniformdev/project-map";
4413
+ var ProjectMapNodeRemoveModule = {
4414
+ command: "remove <id> <projectMapId>",
4415
+ aliases: ["delete", "rm"],
4416
+ describe: "Delete a project map node",
4417
+ builder: (yargs18) => withApiOptions(
4418
+ withProjectOptions(
4419
+ yargs18.positional("id", { demandOption: true, describe: "ProjectMap Node UUID to delete" }).positional("projectMapId", { demandOption: true, describe: "ProjectMap UUID to delete from" })
4420
+ )
4421
+ ),
4422
+ handler: async ({ apiHost, apiKey, proxy, projectMapId, id, project: projectId }) => {
4423
+ const fetch3 = nodeFetchProxy(proxy);
4424
+ const client = new UncachedProjectMapClient11({ apiKey, apiHost, fetch: fetch3, projectId });
4425
+ await client.deleteProjectMapNode({ projectMapId, nodeId: id });
4426
+ }
4427
+ };
4428
+
4429
+ // src/commands/project-map/commands/ProjectMapNode/update.ts
4430
+ import { UncachedProjectMapClient as UncachedProjectMapClient12 } from "@uniformdev/project-map";
4431
+ var ProjectMapNodeUpdateModule = {
4432
+ command: "update <filename> <projectMapId>",
4433
+ aliases: ["put"],
4434
+ describe: "Insert or update a project map node",
4435
+ builder: (yargs18) => withApiOptions(
4436
+ withProjectOptions(
4437
+ yargs18.positional("filename", { demandOption: true, describe: "ProjectMap node file with nodes data" }).positional("projectMapId", { demandOption: true, describe: "ProjectMap UUID to put into" })
4438
+ )
4439
+ ),
4440
+ handler: async ({ apiHost, apiKey, proxy, projectMapId, filename, project: projectId }) => {
4441
+ const fetch3 = nodeFetchProxy(proxy);
4442
+ const client = new UncachedProjectMapClient12({ apiKey, apiHost, fetch: fetch3, projectId });
4443
+ const file = readFileToObject(filename);
4444
+ await client.upsertProjectMapNodes({ nodes: [{ node: file }], projectMapId });
4445
+ }
4446
+ };
4447
+
4448
+ // src/commands/project-map/commands/projectMapNode.ts
4449
+ var ProjectMapNodeModule = {
4450
+ command: "node <command>",
4451
+ describe: "Commands for ProjectMap Nodes",
4452
+ builder: (yargs18) => yargs18.command(ProjectMapNodePullModule).command(ProjectMapNodePushModule).command(ProjectMapNodeGetModule).command(ProjectMapNodeRemoveModule).command(ProjectMapNodeListModule).command(ProjectMapNodeUpdateModule).demandCommand(),
4453
+ handler: () => {
4454
+ yargs15.help();
4455
+ }
4456
+ };
4457
+
4458
+ // src/commands/project-map/index.ts
4459
+ var ProjectMapCommand = {
4460
+ command: "project-map <command>",
4461
+ aliases: ["prm"],
4462
+ describe: "Uniform ProjectMap commands",
4463
+ builder: (yargs18) => yargs18.command(ProjectMapNodeModule).command(ProjectMapDefinitionModule).demandCommand(),
4464
+ handler: () => {
4465
+ yargs16.showHelp();
4466
+ }
4467
+ };
4468
+
4469
+ // src/index.ts
4470
+ __require("dotenv").config();
4471
+ var yarggery = yargs17.scriptName("uniform");
4472
+ yarggery.command(CanvasCommand).command(ContextCommand).command(ProjectMapCommand).command(NewCmd).command(NewMeshCmd).command(OptimizeCommand).demandCommand(1, "").strict().help().argv;