@contrail/cli 3.6.0-alpha.f45f126 → 3.7.0-alpha.1c66a91

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.
Files changed (105) hide show
  1. package/README.md +207 -3
  2. package/dist/api/types.d.ts +35 -0
  3. package/dist/api/types.js +49 -1
  4. package/dist/auth/login.d.ts +1 -1
  5. package/dist/auth/login.js +46 -29
  6. package/dist/auth/login.spec.js +31 -15
  7. package/dist/auth/sign-in-error.d.ts +7 -0
  8. package/dist/auth/sign-in-error.js +24 -0
  9. package/dist/auth/sign-in-error.spec.d.ts +1 -0
  10. package/dist/auth/sign-in-error.spec.js +22 -0
  11. package/dist/auth/sso.d.ts +5 -3
  12. package/dist/auth/sso.js +34 -18
  13. package/dist/auth/sso.spec.js +63 -10
  14. package/dist/basecommand.d.ts +3 -0
  15. package/dist/basecommand.js +10 -3
  16. package/dist/commands/app/getApiKey.js +2 -2
  17. package/dist/commands/app/publish.js +1 -1
  18. package/dist/commands/app/version/prerelease.d.ts +11 -0
  19. package/dist/commands/app/version/prerelease.js +32 -0
  20. package/dist/commands/entities/create.d.ts +49 -0
  21. package/dist/commands/entities/create.js +618 -0
  22. package/dist/commands/entities/create.spec.d.ts +1 -0
  23. package/dist/commands/entities/create.spec.js +581 -0
  24. package/dist/commands/entities/delete.d.ts +20 -0
  25. package/dist/commands/entities/delete.js +146 -0
  26. package/dist/commands/entities/get.d.ts +25 -0
  27. package/dist/commands/entities/get.js +298 -0
  28. package/dist/commands/entities/grammar.spec.d.ts +1 -0
  29. package/dist/commands/entities/grammar.spec.js +79 -0
  30. package/dist/commands/entities/output.spec.d.ts +1 -0
  31. package/dist/commands/entities/output.spec.js +72 -0
  32. package/dist/commands/entities/update.d.ts +32 -0
  33. package/dist/commands/entities/update.js +212 -0
  34. package/dist/commands/login.js +1 -1
  35. package/dist/commands/webhooks/delete.js +2 -3
  36. package/dist/common.d.ts +10 -1
  37. package/dist/common.js +37 -1
  38. package/dist/common.spec.d.ts +1 -0
  39. package/dist/common.spec.js +40 -0
  40. package/dist/helpers/app/app-config-validators.js +4 -4
  41. package/dist/helpers/app/app-config-validators.spec.js +36 -0
  42. package/dist/helpers/app/app-deployer.d.ts +1 -0
  43. package/dist/helpers/app/app-deployer.js +34 -0
  44. package/dist/helpers/app/upgrade-version.d.ts +3 -1
  45. package/dist/helpers/app/upgrade-version.js +7 -8
  46. package/dist/helpers/app/upgrade-version.spec.js +15 -0
  47. package/dist/helpers/config/config.d.ts +3 -3
  48. package/dist/helpers/config/config.js +3 -3
  49. package/dist/helpers/entities/assortment-items.d.ts +11 -0
  50. package/dist/helpers/entities/assortment-items.js +76 -0
  51. package/dist/helpers/entities/batchFetch.d.ts +11 -0
  52. package/dist/helpers/entities/batchFetch.js +50 -0
  53. package/dist/helpers/entities/index.d.ts +3 -0
  54. package/dist/helpers/entities/index.js +6 -0
  55. package/dist/helpers/entities/items.d.ts +6 -0
  56. package/dist/helpers/entities/items.js +60 -0
  57. package/dist/helpers/entities/items.spec.d.ts +1 -0
  58. package/dist/helpers/entities/items.spec.js +19 -0
  59. package/dist/helpers/entities/project-items.d.ts +2 -0
  60. package/dist/helpers/entities/project-items.js +44 -0
  61. package/dist/helpers/file-helpers.d.ts +1 -0
  62. package/dist/helpers/file-helpers.js +20 -3
  63. package/dist/helpers/propertySpecifications/dateRanges.d.ts +34 -0
  64. package/dist/helpers/propertySpecifications/dateRanges.js +91 -0
  65. package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +1 -0
  66. package/dist/helpers/propertySpecifications/dateRanges.spec.js +97 -0
  67. package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +39 -0
  68. package/dist/helpers/propertySpecifications/propertySpecifications.js +102 -0
  69. package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +1 -0
  70. package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +387 -0
  71. package/dist/helpers/propertySpecifications/propertyValues.d.ts +31 -0
  72. package/dist/helpers/propertySpecifications/propertyValues.js +132 -0
  73. package/dist/helpers/propertySpecifications/propertyValues.spec.d.ts +1 -0
  74. package/dist/helpers/propertySpecifications/propertyValues.spec.js +156 -0
  75. package/dist/logger.js +4 -1
  76. package/dist/logger.spec.d.ts +1 -0
  77. package/dist/logger.spec.js +12 -0
  78. package/node_modules/@contrail/entity-compare/package.json +6 -3
  79. package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
  80. package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
  81. package/node_modules/@contrail/loader/lib/constants.js +1 -9
  82. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
  83. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
  84. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
  85. package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
  86. package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
  87. package/node_modules/@contrail/loader/package.json +2 -2
  88. package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +1 -4
  89. package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
  90. package/node_modules/@contrail/sdk/lib/config/config.d.ts +3 -0
  91. package/node_modules/@contrail/sdk/lib/config/config.js +13 -7
  92. package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
  93. package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
  94. package/node_modules/@contrail/sdk/lib/entities/entities.client.js +3 -1
  95. package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
  96. package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
  97. package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
  98. package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
  99. package/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
  100. package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
  101. package/node_modules/@contrail/sdk/lib/index.js +1 -0
  102. package/node_modules/@contrail/sdk/package.json +1 -1
  103. package/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
  104. package/oclif.manifest.json +492 -2
  105. package/package.json +6 -12
package/README.md CHANGED
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
17
17
  $ contrail COMMAND
18
18
  running command...
19
19
  $ contrail (--version)
20
- @contrail/cli/3.6.0-alpha.f45f126 linux-x64 node-v24.22.1
20
+ @contrail/cli/3.7.0-alpha.1c66a91 linux-x64 node-v24.22.2
21
21
  $ contrail --help [COMMAND]
22
22
  USAGE
23
23
  $ contrail COMMAND
@@ -45,12 +45,17 @@ To get instructions on how to set up autocomplete for your shell, run `contrail
45
45
  * [`contrail app version major`](#contrail-app-version-major)
46
46
  * [`contrail app version minor`](#contrail-app-version-minor)
47
47
  * [`contrail app version patch`](#contrail-app-version-patch)
48
+ * [`contrail app version prerelease`](#contrail-app-version-prerelease)
48
49
  * [`contrail autocomplete [SHELL]`](#contrail-autocomplete-shell)
49
50
  * [`contrail config create`](#contrail-config-create)
50
51
  * [`contrail config describe [NAME]`](#contrail-config-describe-name)
51
52
  * [`contrail config list`](#contrail-config-list)
52
53
  * [`contrail config set`](#contrail-config-set)
53
54
  * [`contrail config use [NAME]`](#contrail-config-use-name)
55
+ * [`contrail entities create TYPEPATH`](#contrail-entities-create-typepath)
56
+ * [`contrail entities delete ENTITYNAME [IDS]`](#contrail-entities-delete-entityname-ids)
57
+ * [`contrail entities get ENTITYNAME [IDS]`](#contrail-entities-get-entityname-ids)
58
+ * [`contrail entities update ENTITYNAME [IDS]`](#contrail-entities-update-entityname-ids)
54
59
  * [`contrail feature-flags export`](#contrail-feature-flags-export)
55
60
  * [`contrail feature-flags import`](#contrail-feature-flags-import)
56
61
  * [`contrail file upload FILELOCATION CONTENTTYPE`](#contrail-file-upload-filelocation-contenttype)
@@ -260,7 +265,7 @@ EXAMPLES
260
265
 
261
266
  ## `contrail app publish`
262
267
 
263
- Publish the app to the marketplace. This visibility of your app depends on the app.yml configuration ("visibility" property)
268
+ Publish the app to the marketplace. This visibility of your app depends on the app.yml configuration ("visibility" property). A pre-release version (e.g. "1.4.0-alpha.1") is published without becoming the latest version of the app.
264
269
 
265
270
  ```
266
271
  USAGE
@@ -278,7 +283,7 @@ FLAGS
278
283
 
279
284
  DESCRIPTION
280
285
  Publish the app to the marketplace. This visibility of your app depends on the app.yml configuration ("visibility"
281
- property)
286
+ property). A pre-release version (e.g. "1.4.0-alpha.1") is published without becoming the latest version of the app.
282
287
 
283
288
  EXAMPLES
284
289
  $ contrail app publish
@@ -393,6 +398,28 @@ EXAMPLES
393
398
  $ contrail app version patch
394
399
  ```
395
400
 
401
+ ## `contrail app version prerelease`
402
+
403
+ Upgrade the Pre-release app version. A stable version becomes the first alpha of the next patch (1.2.3 to 1.2.4-alpha.0). A pre-release version gets its number bumped (1.2.4-alpha.0 to 1.2.4-alpha.1).
404
+
405
+ ```
406
+ USAGE
407
+ $ contrail app version prerelease [-l error|warn|info|debug] [-e true|false]
408
+
409
+ FLAGS
410
+ -e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
411
+ <options: true|false>
412
+ -l, --logLevel=<option> The Log Level
413
+ <options: error|warn|info|debug>
414
+
415
+ DESCRIPTION
416
+ Upgrade the Pre-release app version. A stable version becomes the first alpha of the next patch (1.2.3 to
417
+ 1.2.4-alpha.0). A pre-release version gets its number bumped (1.2.4-alpha.0 to 1.2.4-alpha.1).
418
+
419
+ EXAMPLES
420
+ $ contrail app version prerelease
421
+ ```
422
+
396
423
  ## `contrail autocomplete [SHELL]`
397
424
 
398
425
  display autocomplete installation instructions
@@ -540,6 +567,183 @@ EXAMPLES
540
567
  $ contrail config use demo-org
541
568
  ```
542
569
 
570
+ ## `contrail entities create TYPEPATH`
571
+
572
+ Create entities
573
+
574
+ ```
575
+ USAGE
576
+ $ contrail entities create TYPEPATH [-l error|warn|info|debug] [-e true|false] [-n <value>] [-d] [-i <value>] [-o
577
+ <value>] [-g] [-r] [-S] [--suffix <value>] [--apiVersion 1|2]
578
+
579
+ ARGUMENTS
580
+ TYPEPATH The type path of the entity to create (e.g. color, custom-entity:franchise)
581
+
582
+ FLAGS
583
+ -S, --skipHydrateRelationships If true, does not hydrate relationships for the created entities
584
+ -d, --dryRun If true, does not create the entity but simulates the creation
585
+ -e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
586
+ <options: true|false>
587
+ -g, --generateValues If true, generates random values for properties that are not specified. By default,
588
+ only specified properties are used.
589
+ -i, --inputFile=<value> A file with a JSON array of objects where each object is one entity to create. Cannot
590
+ be used with --count. Unless --generateValues is specified, only the properties in
591
+ the file will be used.
592
+ -l, --logLevel=<option> The Log Level
593
+ <options: error|warn|info|debug>
594
+ -n, --count=<value> Number of random entities to create
595
+ -o, --outputFile=<value> File to save the output (optional)
596
+ -r, --readableIds If true, uses readable IDs for the created entities
597
+ --apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
598
+ <options: 1|2>
599
+ --suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
600
+ /<entities>/synchronous)
601
+
602
+ DESCRIPTION
603
+ Create entities
604
+
605
+ EXAMPLES
606
+ $ contrail entities create color -g -n=10 # creates 10 random colors
607
+
608
+ $ contrail entities create color -- name="Electric Blue" green=1 red=2 blue=3 # creates one color with specified properties only
609
+
610
+ $ contrail entities create custom-entity:franchise
611
+
612
+ $ contrail entities create project-item -n=10 -- projectId=abc # creates 10 project items within project ABC
613
+
614
+ $ contrail entities create color -g -r # creates a random color with a human readable ID
615
+
616
+ $ contrail entities create color -d -- name=test # simulates the creation of a color without actually creating it
617
+
618
+ $ contrail entities create custom-entity:franchise -S # creates an entity and the response does not contain hydrated relationships
619
+
620
+ $ contrail entities create color -g -- name="Electric Blue" # creates a color with the name specified and other properties auto-generated
621
+
622
+ $ contrail entities create color -o /tmp/colors.json -- name=Blue green=1 red=2 blue=3 # creates a color and saves the output to /tmp/colors.json
623
+ ```
624
+
625
+ ## `contrail entities delete ENTITYNAME [IDS]`
626
+
627
+ Delete entities by id
628
+
629
+ ```
630
+ USAGE
631
+ $ contrail entities delete ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-d] [-i <value>] [--suffix
632
+ <value>] [--apiVersion 1|2]
633
+
634
+ ARGUMENTS
635
+ ENTITYNAME The name of the entity type to delete (type paths are not supported)
636
+ IDS One or more entity ids to delete
637
+
638
+ FLAGS
639
+ -d, --dryRun If true, does not delete the entities but simulates the deletion
640
+ -e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
641
+ <options: true|false>
642
+ -i, --inputFile=<value> A file with a JSON array of objects; only each object's id is used. Deletes every
643
+ entity in the file.
644
+ -l, --logLevel=<option> The Log Level
645
+ <options: error|warn|info|debug>
646
+ --apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
647
+ <options: 1|2>
648
+ --suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
649
+ /<entities>/synchronous)
650
+
651
+ DESCRIPTION
652
+ Delete entities by id
653
+
654
+ EXAMPLES
655
+ $ contrail entities delete color 123
656
+
657
+ $ contrail entities delete color id1 id2 id3
658
+
659
+ $ contrail entities delete item -i ids.json
660
+ ```
661
+
662
+ ## `contrail entities get ENTITYNAME [IDS]`
663
+
664
+ Get an entity
665
+
666
+ ```
667
+ USAGE
668
+ $ contrail entities get ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-o <value>] [-p <value>]
669
+ [-P] [-s <value>] [-S] [-t <value>] [-r <value>] [--suffix <value>] [--apiVersion 1|2]
670
+
671
+ ARGUMENTS
672
+ ENTITYNAME The name of the entity type to fetch (type paths are not supported)
673
+ IDS One or more entity ids; shorthand for the id/ids criteria
674
+
675
+ FLAGS
676
+ -P, --paginated If true, fetches all entities in a paginated manner
677
+ -S, --skipHydrateRelationships Skip hydrating relationships when fetching the entity
678
+ -e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
679
+ <options: true|false>
680
+ -l, --logLevel=<option> The Log Level
681
+ <options: error|warn|info|debug>
682
+ -o, --outputFile=<value> File to save the output (optional)
683
+ -p, --propertySlugs=<value> Comma-separated list of property slugs to include in the output. Only some entity
684
+ types support this; the rest return full records.
685
+ -r, --relations=<value> Comma-separated list of relations to include in the output
686
+ -s, --skip=<value> Number of entities to skip
687
+ -t, --take=<value> Number of entities to fetch in a single request (default is 100)
688
+ --apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
689
+ <options: 1|2>
690
+ --suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
691
+ /<entities>/synchronous)
692
+
693
+ DESCRIPTION
694
+ Get an entity
695
+
696
+ EXAMPLES
697
+ $ contrail entities get color 123
698
+
699
+ $ contrail entities get color id1 id2 id3
700
+
701
+ $ contrail entities get color -- id=123
702
+
703
+ $ contrail entities get loader-process -- createdOn=2026-09-01..2026-09-11
704
+
705
+ $ contrail entities get loader-process -- createdOn=2026-09-05..
706
+
707
+ $ contrail entities get loader-process -- createdOn=..2026-09-05
708
+ ```
709
+
710
+ ## `contrail entities update ENTITYNAME [IDS]`
711
+
712
+ Update an entity
713
+
714
+ ```
715
+ USAGE
716
+ $ contrail entities update ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-S] [-d] [-i <value>]
717
+ [--suffix <value>] [--apiVersion 1|2]
718
+
719
+ ARGUMENTS
720
+ ENTITYNAME The name of the entity type to update (type paths are not supported)
721
+ IDS One or more entity ids to update
722
+
723
+ FLAGS
724
+ -S, --skipHydrateRelationships Skip hydrating relationships when updating the entity
725
+ -d, --dryRun If true, does not update the entities but simulates the update
726
+ -e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
727
+ <options: true|false>
728
+ -i, --inputFile=<value> A file with a JSON array of {id, ...} objects; each object is one entity to update.
729
+ -l, --logLevel=<option> The Log Level
730
+ <options: error|warn|info|debug>
731
+ --apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
732
+ <options: 1|2>
733
+ --suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
734
+ /<entities>/synchronous)
735
+
736
+ DESCRIPTION
737
+ Update an entity
738
+
739
+ EXAMPLES
740
+ $ contrail entities update color 123 -- name=obsidian hex=000000
741
+
742
+ $ contrail entities update item id1 id2 id3 -- colorName=obsidian # apply the same change to several entities
743
+
744
+ $ contrail entities update color 123 -- federatedId= name='""' # Unset federatedId, set name to empty string
745
+ ```
746
+
543
747
  ## `contrail feature-flags export`
544
748
 
545
749
  Export the enabled feature flags for your Org
@@ -1,3 +1,5 @@
1
+ import { TypeProperty as SDKTypeProperty } from '@contrail/types';
2
+ import { PropertyLevel, PropertyType, Type } from '@contrail/types';
1
3
  export declare function getOptionSets(): Promise<any[]>;
2
4
  export declare function getUserLists(): Promise<any[]>;
3
5
  export declare function getOptionSetHierarchies(): Promise<any[]>;
@@ -6,3 +8,36 @@ export declare function getTypePropertyPolicies(): Promise<any[]>;
6
8
  export declare function getTypePolicies(): Promise<any[]>;
7
9
  export declare function getTypeOverrideCopies(): Promise<any[]>;
8
10
  export declare function uploadTypeOverrideObjects(reducedOverrides: any): Promise<void>;
11
+ type ColonDelimitedHelper<S extends string> = S extends `${infer Head}:${infer Tail}` ? `${Head}:${ColonDelimitedHelper<Tail>}` : S;
12
+ export type ColonDelimited = ColonDelimitedHelper<string>;
13
+ export type TypeWithProperties = Type & {
14
+ typeProperties: TypeProperty[];
15
+ };
16
+ export interface Option {
17
+ value: string;
18
+ display: string;
19
+ disabled?: boolean;
20
+ }
21
+ export interface TypeProperty extends SDKTypeProperty {
22
+ propertyType?: PropertyType;
23
+ referencedTypePath?: string;
24
+ referencedTypeRootSlug?: string;
25
+ propertyLevel?: PropertyLevel;
26
+ }
27
+ export interface TypePropertyOptionSet {
28
+ id?: string;
29
+ orgId?: string;
30
+ name: string;
31
+ slug: string;
32
+ optionSet: Option[];
33
+ isArchived?: boolean;
34
+ }
35
+ export type TypeReferencesCacheByPath = Map<string, TypeWithProperties>;
36
+ export declare function getTypeByPath(path: ColonDelimited): Promise<TypeWithProperties>;
37
+ export declare function buildLocalTypesCache(paths: ColonDelimited[]): Promise<TypeReferencesCacheByPath>;
38
+ export declare function parseTypePath(path: ColonDelimited): {
39
+ root: string;
40
+ path: string;
41
+ };
42
+ export declare function getReferencedTypePaths(type: TypeWithProperties): ColonDelimited[];
43
+ export {};
package/dist/api/types.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadTypeOverrideObjects = exports.getTypeOverrideCopies = exports.getTypePolicies = exports.getTypePropertyPolicies = exports.getRuleSets = exports.getOptionSetHierarchies = exports.getUserLists = exports.getOptionSets = void 0;
3
+ exports.getReferencedTypePaths = exports.parseTypePath = exports.buildLocalTypesCache = exports.getTypeByPath = exports.uploadTypeOverrideObjects = exports.getTypeOverrideCopies = exports.getTypePolicies = exports.getTypePropertyPolicies = exports.getRuleSets = exports.getOptionSetHierarchies = exports.getUserLists = exports.getOptionSets = void 0;
4
4
  const sdk_1 = require("@contrail/sdk");
5
+ const types_1 = require("@contrail/types");
5
6
  async function getOptionSets() {
6
7
  return await new sdk_1.Entities().get({
7
8
  entityName: 'type-property-option-set',
@@ -58,3 +59,50 @@ async function uploadTypeOverrideObjects(reducedOverrides) {
58
59
  });
59
60
  }
60
61
  exports.uploadTypeOverrideObjects = uploadTypeOverrideObjects;
62
+ const TYPES_CACHE_BY_PATH = new Map();
63
+ async function fetchTypeByPath(path) {
64
+ const { root } = parseTypePath(path);
65
+ const client = new sdk_1.Entities();
66
+ const type = await client.get({
67
+ entityName: 'type',
68
+ suffix: `roots/${root}/path/${path}`,
69
+ relations: ['typeProperties'],
70
+ });
71
+ return type;
72
+ }
73
+ async function getTypeByPath(path) {
74
+ if (TYPES_CACHE_BY_PATH.has(path)) {
75
+ return TYPES_CACHE_BY_PATH.get(path);
76
+ }
77
+ const type = await fetchTypeByPath(path);
78
+ TYPES_CACHE_BY_PATH.set(path, type);
79
+ return type;
80
+ }
81
+ exports.getTypeByPath = getTypeByPath;
82
+ async function buildLocalTypesCache(paths) {
83
+ const types = await Promise.all(paths.map((path) => getTypeByPath(path)));
84
+ const newCache = types.reduce((acc, type) => {
85
+ if (!type)
86
+ return acc;
87
+ acc.set(type.typePath, type);
88
+ return acc;
89
+ }, new Map());
90
+ return newCache;
91
+ }
92
+ exports.buildLocalTypesCache = buildLocalTypesCache;
93
+ function parseTypePath(path) {
94
+ const parts = path.split(':').filter(Boolean);
95
+ if (parts.length === 0) {
96
+ throw new Error('Path cannot be empty');
97
+ }
98
+ const root = parts[0];
99
+ return { root, path };
100
+ }
101
+ exports.parseTypePath = parseTypePath;
102
+ function getReferencedTypePaths(type) {
103
+ const properties = type.typeProperties || [];
104
+ return properties
105
+ .filter((prop) => prop.propertyType === types_1.PropertyType.TypeReference)
106
+ .map(({ referencedTypePath }) => referencedTypePath);
107
+ }
108
+ exports.getReferencedTypePaths = getReferencedTypePaths;
@@ -1,6 +1,6 @@
1
1
  import { AuthContext } from '@contrail/sdk';
2
2
  export interface SignInOptions {
3
- openBrowser: boolean;
3
+ shouldOpenBrowser: boolean;
4
4
  }
5
5
  export declare function authUser(): Promise<AuthContext>;
6
6
  export declare function signIn(options: SignInOptions): Promise<AuthContext>;
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getVersionFromPackageJson = exports.signIn = exports.authUser = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const amazon_cognito_identity_js_1 = require("amazon-cognito-identity-js");
6
- const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
7
6
  const sdk_1 = require("@contrail/sdk");
8
7
  const config_1 = require("../helpers/config/config");
9
8
  const logger_1 = tslib_1.__importDefault(require("../logger"));
10
9
  const sso_1 = require("./sso");
10
+ const sign_in_error_1 = require("./sign-in-error");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const fs_1 = tslib_1.__importDefault(require("fs"));
13
+ const common_1 = require("../common");
13
14
  const DEFAULT_API_GATEWAY = config_1.ENVIRONMENTS.prod;
14
15
  const COGNITO_CONFIGS = {
15
16
  dev: {
@@ -17,7 +18,7 @@ const COGNITO_CONFIGS = {
17
18
  clientId: '209s9c62o165cqab0fu5ihjtu9',
18
19
  sso: {
19
20
  domain: 'https://dev-vibeiq.auth.us-east-1.amazoncognito.com',
20
- clientId: '37m7g73hfetr5ab4o5b2ocv1j9',
21
+ clientId: '2d1cke4drm5rd1mcvpcq3d6sq6',
21
22
  pastedCodeCallbackUrl: 'https://login.dev.vibeiq.com/cli',
22
23
  },
23
24
  },
@@ -26,7 +27,7 @@ const COGNITO_CONFIGS = {
26
27
  clientId: '7knkt34gfacbgd0ghnuspefdfg',
27
28
  sso: {
28
29
  domain: 'https://prod-vibeiq.auth.us-east-1.amazoncognito.com',
29
- clientId: 'PROD_CLI_CLIENT_ID',
30
+ clientId: '49dr6o3kv1ot88evq0cfblnb83',
30
31
  pastedCodeCallbackUrl: 'https://login.vibeiq.com/cli',
31
32
  },
32
33
  },
@@ -65,16 +66,13 @@ async function authUser() {
65
66
  logger_1.default.info('Token expired. Requesting auth credentials...');
66
67
  }
67
68
  }
68
- return await signIn({ openBrowser: true });
69
+ return await signIn({ shouldOpenBrowser: true });
69
70
  }
70
71
  exports.authUser = authUser;
71
72
  async function signIn(options) {
72
73
  const config = await (0, config_1.getConfig)();
73
74
  const apiGateway = getApiGateway(config);
74
- const environment = (0, config_1.findEnvironmentName)(apiGateway);
75
- if (!environment) {
76
- throw new Error(`No Cognito user pool is known for ${apiGateway}. Sign-in works for ${Object.keys(COGNITO_CONFIGS).join(' and ')}; use CONTRAIL_CLI_API_KEY for other environments.`);
77
- }
75
+ const environment = getSignInEnvironment(apiGateway);
78
76
  const email = process.env.CONTRAIL_CLI_EMAIL || (await promptForEmail());
79
77
  const params = {
80
78
  email,
@@ -90,38 +88,54 @@ async function signIn(options) {
90
88
  return signInWithSso(params, domainCheck.identityProvider, options);
91
89
  }
92
90
  if (domainCheck.kind === 'legacy') {
93
- logger_1.default.info('The CLI does not support your SSO provider yet. Sign in with your VibeIQ password, or set CONTRAIL_CLI_API_KEY.');
91
+ console.log('The CLI does not support your SSO provider yet. Sign in with your VibeIQ password, or set CONTRAIL_CLI_API_KEY.');
94
92
  }
95
93
  return authenticateWithUsernamePassword(params);
96
94
  }
97
95
  exports.signIn = signIn;
96
+ function getSignInEnvironment(apiGateway) {
97
+ const environment = (0, config_1.findEnvironmentName)(apiGateway);
98
+ if (!environment) {
99
+ throw new sign_in_error_1.SignInError('ENVIRONMENT_NOT_CONFIGURED', 'Sign-in works only for dev and prod. Use CONTRAIL_CLI_API_KEY for other environments.', { apiGateway });
100
+ }
101
+ return environment;
102
+ }
98
103
  async function promptForEmail() {
99
- const answers = await inquirer_1.default.prompt([
104
+ const answers = await (0, common_1.promptOnStderr)([
100
105
  { type: 'input', name: 'email', validate: (val) => !!val, message: 'Email' },
101
106
  ]);
102
107
  return answers.email;
103
108
  }
104
109
  async function signInWithSso(params, identityProvider, options) {
105
110
  const ssoClient = COGNITO_CONFIGS[params.environment].sso;
106
- const pkce = (0, sso_1.createPkceChallenge)();
107
- const usesLoopback = options.openBrowser && (0, sso_1.canOpenBrowser)();
111
+ const signInAttempt = (0, sso_1.createSignInAttempt)();
112
+ const usesLoopback = options.shouldOpenBrowser && (0, sso_1.canOpenBrowser)();
108
113
  const redirectUri = usesLoopback ? sso_1.LOOPBACK_CALLBACK_URL : ssoClient.pastedCodeCallbackUrl;
109
- const authorizeUrl = (0, sso_1.buildAuthorizeUrl)(ssoClient, identityProvider, redirectUri, pkce);
114
+ const authorizeUrl = (0, sso_1.buildAuthorizeUrl)(ssoClient, identityProvider, redirectUri, signInAttempt);
110
115
  let code;
111
116
  if (usesLoopback) {
112
- const loopbackListener = await (0, sso_1.listenForLoopbackCode)(pkce.state);
113
- logger_1.default.info(`Opening your browser to sign in. If it does not open, visit:\n${authorizeUrl}`);
114
- await (0, sso_1.openBrowser)(authorizeUrl).catch(() => logger_1.default.info('Could not open a browser. Open the URL above to sign in.'));
117
+ const loopbackListener = await (0, sso_1.listenForLoopbackCode)(signInAttempt.state);
118
+ console.log(`Opening your browser to sign in. If it does not open, visit:\n${authorizeUrl}`);
119
+ try {
120
+ await (0, sso_1.openBrowser)(authorizeUrl);
121
+ }
122
+ catch (error) {
123
+ if (error?.code !== 'ENOENT') {
124
+ loopbackListener.stop();
125
+ throw error;
126
+ }
127
+ console.log('Could not find a browser to open. Open the URL above to sign in.');
128
+ }
115
129
  code = await loopbackListener.code;
116
130
  }
117
131
  else {
118
- logger_1.default.info(`Open this URL in any browser to sign in:\n${authorizeUrl}`);
119
- const answers = await inquirer_1.default.prompt([
132
+ console.log(`Open this URL in any browser to sign in:\n${authorizeUrl}`);
133
+ const answers = await (0, common_1.promptOnStderr)([
120
134
  { type: 'input', name: 'signInCode', validate: (val) => !!val, message: 'Sign-in code' },
121
135
  ]);
122
- code = (0, sso_1.parsePastedSignInCode)(answers.signInCode, pkce.state);
136
+ code = (0, sso_1.parsePastedSignInCode)(answers.signInCode, signInAttempt.state);
123
137
  }
124
- const tokens = await (0, sso_1.exchangeCodeForTokens)(ssoClient, code, redirectUri, pkce.verifier);
138
+ const tokens = await (0, sso_1.exchangeCodeForTokens)(ssoClient, code, redirectUri, signInAttempt.verifier);
125
139
  sdk_1.Auth.config = {
126
140
  apiUserToken: tokens.accessToken,
127
141
  apiRefreshToken: tokens.refreshToken,
@@ -135,7 +149,7 @@ async function signInWithSso(params, identityProvider, options) {
135
149
  async function getOrgSlug(config) {
136
150
  const orgSlug = config?.orgSlug || process.env.CONTRAIL_CLI_ORG_SLUG;
137
151
  if (!orgSlug) {
138
- const answers = await inquirer_1.default.prompt([
152
+ const answers = await (0, common_1.promptOnStderr)([
139
153
  {
140
154
  type: 'input',
141
155
  name: 'orgSlug',
@@ -157,7 +171,7 @@ async function authenticateWithApiKey(config, apiKey, orgSlug) {
157
171
  };
158
172
  (0, sdk_1.setConfig)(sdk_1.Auth.config);
159
173
  await (0, sdk_1.getCurrentUser)();
160
- return returnAndStoreConfig(sdk_1.Auth.config);
174
+ return returnAndStoreConfig(sdk_1.Auth.config, 'apiKey');
161
175
  }
162
176
  async function authenticateWithUsernamePassword(params) {
163
177
  const cognitoConfig = COGNITO_CONFIGS[params.environment];
@@ -198,7 +212,7 @@ async function authenticateWithUsernamePassword(params) {
198
212
  });
199
213
  }
200
214
  async function promptForPassword() {
201
- const answers = await inquirer_1.default.prompt([
215
+ const answers = await (0, common_1.promptOnStderr)([
202
216
  { type: 'password', name: 'password', validate: (val) => !!val, message: 'Password' },
203
217
  ]);
204
218
  return answers.password;
@@ -215,7 +229,7 @@ async function setAuthContext(user, params) {
215
229
  };
216
230
  // SET SDK CONFIG
217
231
  (0, sdk_1.setConfig)(sdk_1.Auth.config);
218
- return refreshCurrentUserOrg();
232
+ return refreshCurrentUserOrg('password');
219
233
  }
220
234
  async function signInWithStoredTokens(signInMethod) {
221
235
  try {
@@ -229,15 +243,15 @@ async function signInWithStoredTokens(signInMethod) {
229
243
  await refreshAccessToken(signInMethod);
230
244
  await (0, sdk_1.getCurrentUser)();
231
245
  }
232
- return returnAndStoreConfig(sdk_1.Auth.config);
246
+ return returnAndStoreConfig(sdk_1.Auth.config, signInMethod);
233
247
  }
234
- async function refreshCurrentUserOrg() {
248
+ async function refreshCurrentUserOrg(signInMethod) {
235
249
  logger_1.default.debug('refreshing current user org...');
236
250
  await (0, sdk_1.getCurrentUser)();
237
251
  // TODO: To uncomment when telemetry backend is developed.
238
252
  // const current_Version = getVersionFromPackageJson();
239
253
  // await checkTelemetry(current_Version);
240
- return returnAndStoreConfig(sdk_1.Auth.config, 'password');
254
+ return returnAndStoreConfig(sdk_1.Auth.config, signInMethod);
241
255
  }
242
256
  async function refreshAccessToken(signInMethod) {
243
257
  const newAccessToken = await fetchRefreshedAccessTokenForSignInMethod(signInMethod);
@@ -247,9 +261,12 @@ async function refreshAccessToken(signInMethod) {
247
261
  async function fetchRefreshedAccessTokenForSignInMethod(signInMethod) {
248
262
  const { apiRefreshToken, apiGateway } = sdk_1.Auth.config;
249
263
  if (signInMethod === 'sso') {
250
- const ssoClient = COGNITO_CONFIGS[(0, config_1.findEnvironmentName)(apiGateway)].sso;
264
+ const ssoClient = COGNITO_CONFIGS[getSignInEnvironment(apiGateway)].sso;
251
265
  return (0, sso_1.refreshSsoAccessToken)(ssoClient, apiRefreshToken);
252
266
  }
267
+ if (signInMethod === 'apiKey') {
268
+ throw new sign_in_error_1.SignInError('API_KEY_CANNOT_REFRESH', 'An API key cannot be refreshed. Set a new one.');
269
+ }
253
270
  return requestRefreshedAccessToken(apiRefreshToken, apiGateway);
254
271
  }
255
272
  function getApiGateway(config) {
@@ -303,7 +320,7 @@ function getVersionFromPackageJson() {
303
320
  exports.getVersionFromPackageJson = getVersionFromPackageJson;
304
321
  async function returnAndStoreConfig(config, signInMethod) {
305
322
  const configCopy = Object.assign({}, config);
306
- await (0, config_1.storeConfig)(signInMethod ? { ...configCopy, signInMethod } : configCopy);
323
+ await (0, config_1.storeConfig)({ ...configCopy, signInMethod });
307
324
  return configCopy;
308
325
  }
309
326
  function isNetworkConnectionError(e) {