@contrail/cli 3.6.0-alpha.eec506e → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +182 -26
- package/dist/api/types.d.ts +35 -0
- package/dist/api/types.js +49 -1
- package/dist/auth/login.d.ts +0 -4
- package/dist/auth/login.js +52 -115
- package/dist/auth/login.spec.js +0 -100
- package/dist/basecommand.js +2 -2
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/entities/create.d.ts +49 -0
- package/dist/commands/entities/create.js +618 -0
- package/dist/commands/entities/create.spec.js +581 -0
- package/dist/commands/entities/delete.d.ts +20 -0
- package/dist/commands/entities/delete.js +146 -0
- package/dist/commands/entities/get.d.ts +25 -0
- package/dist/commands/entities/get.js +298 -0
- package/dist/commands/entities/grammar.spec.d.ts +1 -0
- package/dist/commands/entities/grammar.spec.js +79 -0
- package/dist/commands/entities/output.spec.d.ts +1 -0
- package/dist/commands/entities/output.spec.js +72 -0
- package/dist/commands/entities/update.d.ts +32 -0
- package/dist/commands/entities/update.js +212 -0
- package/dist/commands/webhooks/delete.js +2 -3
- package/dist/common.d.ts +10 -1
- package/dist/common.js +37 -1
- package/dist/common.spec.d.ts +1 -0
- package/dist/common.spec.js +40 -0
- package/dist/helpers/config/config.d.ts +3 -3
- package/dist/helpers/config/config.js +3 -3
- package/dist/helpers/entities/assortment-items.d.ts +11 -0
- package/dist/helpers/entities/assortment-items.js +76 -0
- package/dist/helpers/entities/batchFetch.d.ts +11 -0
- package/dist/helpers/entities/batchFetch.js +50 -0
- package/dist/helpers/entities/index.d.ts +3 -0
- package/dist/helpers/entities/index.js +6 -0
- package/dist/helpers/entities/items.d.ts +6 -0
- package/dist/helpers/entities/items.js +60 -0
- package/dist/helpers/entities/items.spec.d.ts +1 -0
- package/dist/helpers/entities/items.spec.js +19 -0
- package/dist/helpers/entities/project-items.d.ts +2 -0
- package/dist/helpers/entities/project-items.js +44 -0
- package/dist/helpers/file-helpers.d.ts +1 -0
- package/dist/helpers/file-helpers.js +20 -3
- package/dist/helpers/propertySpecifications/dateRanges.d.ts +34 -0
- package/dist/helpers/propertySpecifications/dateRanges.js +91 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.js +97 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +39 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.js +102 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +387 -0
- package/dist/helpers/propertySpecifications/propertyValues.d.ts +31 -0
- package/dist/helpers/propertySpecifications/propertyValues.js +132 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.js +156 -0
- package/dist/logger.js +4 -1
- package/dist/logger.spec.d.ts +1 -0
- package/dist/logger.spec.js +12 -0
- package/node_modules/@contrail/entity-compare/package.json +6 -3
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
- package/node_modules/@contrail/loader/lib/constants.js +1 -9
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +1 -4
- package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
- package/node_modules/@contrail/sdk/lib/config/config.d.ts +3 -0
- package/node_modules/@contrail/sdk/lib/config/config.js +13 -7
- package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
- package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
- package/node_modules/@contrail/sdk/lib/entities/entities.client.js +3 -1
- package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
- package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/index.js +1 -0
- package/node_modules/@contrail/sdk/package.json +1 -1
- package/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
- package/oclif.manifest.json +449 -50
- package/package.json +6 -12
- package/dist/auth/sso.d.ts +0 -36
- package/dist/auth/sso.js +0 -174
- package/dist/auth/sso.spec.js +0 -148
- package/dist/commands/login.d.ts +0 -12
- package/dist/commands/login.js +0 -25
- /package/dist/{auth/sso.spec.d.ts → commands/entities/create.spec.d.ts} +0 -0
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
|
|
20
|
+
@contrail/cli/3.6.0 linux-x64 node-v24.22.2
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -51,6 +51,10 @@ To get instructions on how to set up autocomplete for your shell, run `contrail
|
|
|
51
51
|
* [`contrail config list`](#contrail-config-list)
|
|
52
52
|
* [`contrail config set`](#contrail-config-set)
|
|
53
53
|
* [`contrail config use [NAME]`](#contrail-config-use-name)
|
|
54
|
+
* [`contrail entities create TYPEPATH`](#contrail-entities-create-typepath)
|
|
55
|
+
* [`contrail entities delete ENTITYNAME [IDS]`](#contrail-entities-delete-entityname-ids)
|
|
56
|
+
* [`contrail entities get ENTITYNAME [IDS]`](#contrail-entities-get-entityname-ids)
|
|
57
|
+
* [`contrail entities update ENTITYNAME [IDS]`](#contrail-entities-update-entityname-ids)
|
|
54
58
|
* [`contrail feature-flags export`](#contrail-feature-flags-export)
|
|
55
59
|
* [`contrail feature-flags import`](#contrail-feature-flags-import)
|
|
56
60
|
* [`contrail file upload FILELOCATION CONTENTTYPE`](#contrail-file-upload-filelocation-contenttype)
|
|
@@ -63,7 +67,6 @@ To get instructions on how to set up autocomplete for your shell, run `contrail
|
|
|
63
67
|
* [`contrail load custom-entity DATAFILE CONFIGFILE`](#contrail-load-custom-entity-datafile-configfile)
|
|
64
68
|
* [`contrail load line-sheet DATAFILE CONFIGFILE`](#contrail-load-line-sheet-datafile-configfile)
|
|
65
69
|
* [`contrail load upload-and-load INCOMINGFILE CONFIGFILENAME`](#contrail-load-upload-and-load-incomingfile-configfilename)
|
|
66
|
-
* [`contrail login`](#contrail-login)
|
|
67
70
|
* [`contrail org-config export`](#contrail-org-config-export)
|
|
68
71
|
* [`contrail org-config import`](#contrail-org-config-import)
|
|
69
72
|
* [`contrail projects export PROJECTNAME`](#contrail-projects-export-projectname)
|
|
@@ -540,6 +543,183 @@ EXAMPLES
|
|
|
540
543
|
$ contrail config use demo-org
|
|
541
544
|
```
|
|
542
545
|
|
|
546
|
+
## `contrail entities create TYPEPATH`
|
|
547
|
+
|
|
548
|
+
Create entities
|
|
549
|
+
|
|
550
|
+
```
|
|
551
|
+
USAGE
|
|
552
|
+
$ contrail entities create TYPEPATH [-l error|warn|info|debug] [-e true|false] [-n <value>] [-d] [-i <value>] [-o
|
|
553
|
+
<value>] [-g] [-r] [-S] [--suffix <value>] [--apiVersion 1|2]
|
|
554
|
+
|
|
555
|
+
ARGUMENTS
|
|
556
|
+
TYPEPATH The type path of the entity to create (e.g. color, custom-entity:franchise)
|
|
557
|
+
|
|
558
|
+
FLAGS
|
|
559
|
+
-S, --skipHydrateRelationships If true, does not hydrate relationships for the created entities
|
|
560
|
+
-d, --dryRun If true, does not create the entity but simulates the creation
|
|
561
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
562
|
+
<options: true|false>
|
|
563
|
+
-g, --generateValues If true, generates random values for properties that are not specified. By default,
|
|
564
|
+
only specified properties are used.
|
|
565
|
+
-i, --inputFile=<value> A file with a JSON array of objects where each object is one entity to create. Cannot
|
|
566
|
+
be used with --count. Unless --generateValues is specified, only the properties in
|
|
567
|
+
the file will be used.
|
|
568
|
+
-l, --logLevel=<option> The Log Level
|
|
569
|
+
<options: error|warn|info|debug>
|
|
570
|
+
-n, --count=<value> Number of random entities to create
|
|
571
|
+
-o, --outputFile=<value> File to save the output (optional)
|
|
572
|
+
-r, --readableIds If true, uses readable IDs for the created entities
|
|
573
|
+
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
574
|
+
<options: 1|2>
|
|
575
|
+
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
576
|
+
/<entities>/synchronous)
|
|
577
|
+
|
|
578
|
+
DESCRIPTION
|
|
579
|
+
Create entities
|
|
580
|
+
|
|
581
|
+
EXAMPLES
|
|
582
|
+
$ contrail entities create color -g -n=10 # creates 10 random colors
|
|
583
|
+
|
|
584
|
+
$ contrail entities create color -- name="Electric Blue" green=1 red=2 blue=3 # creates one color with specified properties only
|
|
585
|
+
|
|
586
|
+
$ contrail entities create custom-entity:franchise
|
|
587
|
+
|
|
588
|
+
$ contrail entities create project-item -n=10 -- projectId=abc # creates 10 project items within project ABC
|
|
589
|
+
|
|
590
|
+
$ contrail entities create color -g -r # creates a random color with a human readable ID
|
|
591
|
+
|
|
592
|
+
$ contrail entities create color -d -- name=test # simulates the creation of a color without actually creating it
|
|
593
|
+
|
|
594
|
+
$ contrail entities create custom-entity:franchise -S # creates an entity and the response does not contain hydrated relationships
|
|
595
|
+
|
|
596
|
+
$ contrail entities create color -g -- name="Electric Blue" # creates a color with the name specified and other properties auto-generated
|
|
597
|
+
|
|
598
|
+
$ 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
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
## `contrail entities delete ENTITYNAME [IDS]`
|
|
602
|
+
|
|
603
|
+
Delete entities by id
|
|
604
|
+
|
|
605
|
+
```
|
|
606
|
+
USAGE
|
|
607
|
+
$ contrail entities delete ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-d] [-i <value>] [--suffix
|
|
608
|
+
<value>] [--apiVersion 1|2]
|
|
609
|
+
|
|
610
|
+
ARGUMENTS
|
|
611
|
+
ENTITYNAME The name of the entity type to delete (type paths are not supported)
|
|
612
|
+
IDS One or more entity ids to delete
|
|
613
|
+
|
|
614
|
+
FLAGS
|
|
615
|
+
-d, --dryRun If true, does not delete the entities but simulates the deletion
|
|
616
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
617
|
+
<options: true|false>
|
|
618
|
+
-i, --inputFile=<value> A file with a JSON array of objects; only each object's id is used. Deletes every
|
|
619
|
+
entity in the file.
|
|
620
|
+
-l, --logLevel=<option> The Log Level
|
|
621
|
+
<options: error|warn|info|debug>
|
|
622
|
+
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
623
|
+
<options: 1|2>
|
|
624
|
+
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
625
|
+
/<entities>/synchronous)
|
|
626
|
+
|
|
627
|
+
DESCRIPTION
|
|
628
|
+
Delete entities by id
|
|
629
|
+
|
|
630
|
+
EXAMPLES
|
|
631
|
+
$ contrail entities delete color 123
|
|
632
|
+
|
|
633
|
+
$ contrail entities delete color id1 id2 id3
|
|
634
|
+
|
|
635
|
+
$ contrail entities delete item -i ids.json
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
## `contrail entities get ENTITYNAME [IDS]`
|
|
639
|
+
|
|
640
|
+
Get an entity
|
|
641
|
+
|
|
642
|
+
```
|
|
643
|
+
USAGE
|
|
644
|
+
$ contrail entities get ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-o <value>] [-p <value>]
|
|
645
|
+
[-P] [-s <value>] [-S] [-t <value>] [-r <value>] [--suffix <value>] [--apiVersion 1|2]
|
|
646
|
+
|
|
647
|
+
ARGUMENTS
|
|
648
|
+
ENTITYNAME The name of the entity type to fetch (type paths are not supported)
|
|
649
|
+
IDS One or more entity ids; shorthand for the id/ids criteria
|
|
650
|
+
|
|
651
|
+
FLAGS
|
|
652
|
+
-P, --paginated If true, fetches all entities in a paginated manner
|
|
653
|
+
-S, --skipHydrateRelationships Skip hydrating relationships when fetching the entity
|
|
654
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
655
|
+
<options: true|false>
|
|
656
|
+
-l, --logLevel=<option> The Log Level
|
|
657
|
+
<options: error|warn|info|debug>
|
|
658
|
+
-o, --outputFile=<value> File to save the output (optional)
|
|
659
|
+
-p, --propertySlugs=<value> Comma-separated list of property slugs to include in the output. Only some entity
|
|
660
|
+
types support this; the rest return full records.
|
|
661
|
+
-r, --relations=<value> Comma-separated list of relations to include in the output
|
|
662
|
+
-s, --skip=<value> Number of entities to skip
|
|
663
|
+
-t, --take=<value> Number of entities to fetch in a single request (default is 100)
|
|
664
|
+
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
665
|
+
<options: 1|2>
|
|
666
|
+
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
667
|
+
/<entities>/synchronous)
|
|
668
|
+
|
|
669
|
+
DESCRIPTION
|
|
670
|
+
Get an entity
|
|
671
|
+
|
|
672
|
+
EXAMPLES
|
|
673
|
+
$ contrail entities get color 123
|
|
674
|
+
|
|
675
|
+
$ contrail entities get color id1 id2 id3
|
|
676
|
+
|
|
677
|
+
$ contrail entities get color -- id=123
|
|
678
|
+
|
|
679
|
+
$ contrail entities get loader-process -- createdOn=2026-09-01..2026-09-11
|
|
680
|
+
|
|
681
|
+
$ contrail entities get loader-process -- createdOn=2026-09-05..
|
|
682
|
+
|
|
683
|
+
$ contrail entities get loader-process -- createdOn=..2026-09-05
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
## `contrail entities update ENTITYNAME [IDS]`
|
|
687
|
+
|
|
688
|
+
Update an entity
|
|
689
|
+
|
|
690
|
+
```
|
|
691
|
+
USAGE
|
|
692
|
+
$ contrail entities update ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-S] [-d] [-i <value>]
|
|
693
|
+
[--suffix <value>] [--apiVersion 1|2]
|
|
694
|
+
|
|
695
|
+
ARGUMENTS
|
|
696
|
+
ENTITYNAME The name of the entity type to update (type paths are not supported)
|
|
697
|
+
IDS One or more entity ids to update
|
|
698
|
+
|
|
699
|
+
FLAGS
|
|
700
|
+
-S, --skipHydrateRelationships Skip hydrating relationships when updating the entity
|
|
701
|
+
-d, --dryRun If true, does not update the entities but simulates the update
|
|
702
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
703
|
+
<options: true|false>
|
|
704
|
+
-i, --inputFile=<value> A file with a JSON array of {id, ...} objects; each object is one entity to update.
|
|
705
|
+
-l, --logLevel=<option> The Log Level
|
|
706
|
+
<options: error|warn|info|debug>
|
|
707
|
+
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
708
|
+
<options: 1|2>
|
|
709
|
+
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
710
|
+
/<entities>/synchronous)
|
|
711
|
+
|
|
712
|
+
DESCRIPTION
|
|
713
|
+
Update an entity
|
|
714
|
+
|
|
715
|
+
EXAMPLES
|
|
716
|
+
$ contrail entities update color 123 -- name=obsidian hex=000000
|
|
717
|
+
|
|
718
|
+
$ contrail entities update item id1 id2 id3 -- colorName=obsidian # apply the same change to several entities
|
|
719
|
+
|
|
720
|
+
$ contrail entities update color 123 -- federatedId= name='""' # Unset federatedId, set name to empty string
|
|
721
|
+
```
|
|
722
|
+
|
|
543
723
|
## `contrail feature-flags export`
|
|
544
724
|
|
|
545
725
|
Export the enabled feature flags for your Org
|
|
@@ -829,30 +1009,6 @@ EXAMPLES
|
|
|
829
1009
|
$ contrail load-processor upload-and-load <File Path> <Config Path>
|
|
830
1010
|
```
|
|
831
1011
|
|
|
832
|
-
## `contrail login`
|
|
833
|
-
|
|
834
|
-
Sign in to VibeIQ with SSO or your email and password
|
|
835
|
-
|
|
836
|
-
```
|
|
837
|
-
USAGE
|
|
838
|
-
$ contrail login [-l error|warn|info|debug] [-e true|false] [--browser]
|
|
839
|
-
|
|
840
|
-
FLAGS
|
|
841
|
-
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
842
|
-
<options: true|false>
|
|
843
|
-
-l, --logLevel=<option> The Log Level
|
|
844
|
-
<options: error|warn|info|debug>
|
|
845
|
-
--[no-]browser Open a browser for SSO. Use --no-browser to paste a sign-in code instead.
|
|
846
|
-
|
|
847
|
-
DESCRIPTION
|
|
848
|
-
Sign in to VibeIQ with SSO or your email and password
|
|
849
|
-
|
|
850
|
-
EXAMPLES
|
|
851
|
-
$ contrail login
|
|
852
|
-
|
|
853
|
-
$ contrail login --no-browser
|
|
854
|
-
```
|
|
855
|
-
|
|
856
1012
|
## `contrail org-config export`
|
|
857
1013
|
|
|
858
1014
|
Export the org config for your Org
|
package/dist/api/types.d.ts
CHANGED
|
@@ -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;
|
package/dist/auth/login.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import { AuthContext } from '@contrail/sdk';
|
|
2
|
-
export interface SignInOptions {
|
|
3
|
-
openBrowser: boolean;
|
|
4
|
-
}
|
|
5
2
|
export declare function authUser(): Promise<AuthContext>;
|
|
6
|
-
export declare function signIn(options: SignInOptions): Promise<AuthContext>;
|
|
7
3
|
export declare function getVersionFromPackageJson(): string;
|
package/dist/auth/login.js
CHANGED
|
@@ -1,35 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVersionFromPackageJson = exports.
|
|
3
|
+
exports.getVersionFromPackageJson = 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
|
-
const sso_1 = require("./sso");
|
|
11
9
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
10
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
11
|
+
const common_1 = require("../common");
|
|
13
12
|
const DEFAULT_API_GATEWAY = config_1.ENVIRONMENTS.prod;
|
|
14
13
|
const COGNITO_CONFIGS = {
|
|
15
|
-
dev: {
|
|
16
|
-
|
|
17
|
-
clientId: '209s9c62o165cqab0fu5ihjtu9',
|
|
18
|
-
sso: {
|
|
19
|
-
domain: 'https://dev-vibeiq.auth.us-east-1.amazoncognito.com',
|
|
20
|
-
clientId: '7qlu7d55oog9dv0kd3k30kjr2v',
|
|
21
|
-
pastedCodeCallbackUrl: 'https://login.dev.vibeiq.com/cli',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
prod: {
|
|
25
|
-
userPoolId: 'us-east-1_qIaNZdUfm',
|
|
26
|
-
clientId: '7knkt34gfacbgd0ghnuspefdfg',
|
|
27
|
-
sso: {
|
|
28
|
-
domain: 'https://prod-vibeiq.auth.us-east-1.amazoncognito.com',
|
|
29
|
-
clientId: 'PROD_CLI_CLIENT_ID',
|
|
30
|
-
pastedCodeCallbackUrl: 'https://login.vibeiq.com/cli',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
14
|
+
dev: { userPoolId: 'us-east-1_e2cA0nJWu', clientId: '209s9c62o165cqab0fu5ihjtu9' },
|
|
15
|
+
prod: { userPoolId: 'us-east-1_qIaNZdUfm', clientId: '7knkt34gfacbgd0ghnuspefdfg' },
|
|
33
16
|
};
|
|
34
17
|
async function authUser() {
|
|
35
18
|
logger_1.default.debug('authorizing user...');
|
|
@@ -54,7 +37,7 @@ async function authUser() {
|
|
|
54
37
|
};
|
|
55
38
|
(0, sdk_1.setConfig)(sdk_1.Auth.config);
|
|
56
39
|
try {
|
|
57
|
-
return await signInWithStoredTokens(
|
|
40
|
+
return await signInWithStoredTokens();
|
|
58
41
|
}
|
|
59
42
|
catch (e) {
|
|
60
43
|
logger_1.default.debug(`stored tokens rejected: ${e?.message}`);
|
|
@@ -65,77 +48,13 @@ async function authUser() {
|
|
|
65
48
|
logger_1.default.info('Token expired. Requesting auth credentials...');
|
|
66
49
|
}
|
|
67
50
|
}
|
|
68
|
-
return await
|
|
51
|
+
return await authenticateWithUsernamePassword(config);
|
|
69
52
|
}
|
|
70
53
|
exports.authUser = authUser;
|
|
71
|
-
async function signIn(options) {
|
|
72
|
-
const config = await (0, config_1.getConfig)();
|
|
73
|
-
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
|
-
}
|
|
78
|
-
const email = process.env.CONTRAIL_CLI_EMAIL || (await promptForEmail());
|
|
79
|
-
const params = {
|
|
80
|
-
email,
|
|
81
|
-
orgSlug: await getOrgSlug(config),
|
|
82
|
-
apiGateway,
|
|
83
|
-
environment,
|
|
84
|
-
};
|
|
85
|
-
if (process.env.CONTRAIL_CLI_PASSWORD) {
|
|
86
|
-
return authenticateWithUsernamePassword(params);
|
|
87
|
-
}
|
|
88
|
-
const domainCheck = await (0, sso_1.fetchSsoDomainCheck)(email, apiGateway);
|
|
89
|
-
if (domainCheck.kind === 'cognito') {
|
|
90
|
-
return signInWithSso(params, domainCheck.identityProvider, options);
|
|
91
|
-
}
|
|
92
|
-
if (domainCheck.kind === 'legacy') {
|
|
93
|
-
console.log('The CLI does not support your SSO provider yet. Sign in with your VibeIQ password, or set CONTRAIL_CLI_API_KEY.');
|
|
94
|
-
}
|
|
95
|
-
return authenticateWithUsernamePassword(params);
|
|
96
|
-
}
|
|
97
|
-
exports.signIn = signIn;
|
|
98
|
-
async function promptForEmail() {
|
|
99
|
-
const answers = await inquirer_1.default.prompt([
|
|
100
|
-
{ type: 'input', name: 'email', validate: (val) => !!val, message: 'Email' },
|
|
101
|
-
]);
|
|
102
|
-
return answers.email;
|
|
103
|
-
}
|
|
104
|
-
async function signInWithSso(params, identityProvider, options) {
|
|
105
|
-
const ssoClient = COGNITO_CONFIGS[params.environment].sso;
|
|
106
|
-
const pkce = (0, sso_1.createPkceChallenge)();
|
|
107
|
-
const usesLoopback = options.openBrowser && (0, sso_1.canOpenBrowser)();
|
|
108
|
-
const redirectUri = usesLoopback ? sso_1.LOOPBACK_CALLBACK_URL : ssoClient.pastedCodeCallbackUrl;
|
|
109
|
-
const authorizeUrl = (0, sso_1.buildAuthorizeUrl)(ssoClient, identityProvider, redirectUri, pkce);
|
|
110
|
-
let code;
|
|
111
|
-
if (usesLoopback) {
|
|
112
|
-
const loopbackListener = await (0, sso_1.listenForLoopbackCode)(pkce.state);
|
|
113
|
-
console.log(`Opening your browser to sign in. If it does not open, visit:\n${authorizeUrl}`);
|
|
114
|
-
await (0, sso_1.openBrowser)(authorizeUrl).catch(() => console.log('Could not open a browser. Open the URL above to sign in.'));
|
|
115
|
-
code = await loopbackListener.code;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
console.log(`Open this URL in any browser to sign in:\n${authorizeUrl}`);
|
|
119
|
-
const answers = await inquirer_1.default.prompt([
|
|
120
|
-
{ type: 'input', name: 'signInCode', validate: (val) => !!val, message: 'Sign-in code' },
|
|
121
|
-
]);
|
|
122
|
-
code = (0, sso_1.parsePastedSignInCode)(answers.signInCode, pkce.state);
|
|
123
|
-
}
|
|
124
|
-
const tokens = await (0, sso_1.exchangeCodeForTokens)(ssoClient, code, redirectUri, pkce.verifier);
|
|
125
|
-
sdk_1.Auth.config = {
|
|
126
|
-
apiUserToken: tokens.accessToken,
|
|
127
|
-
apiRefreshToken: tokens.refreshToken,
|
|
128
|
-
apiGateway: params.apiGateway,
|
|
129
|
-
orgSlug: params.orgSlug,
|
|
130
|
-
};
|
|
131
|
-
(0, sdk_1.setConfig)(sdk_1.Auth.config);
|
|
132
|
-
await (0, sdk_1.getCurrentUser)();
|
|
133
|
-
return returnAndStoreConfig(sdk_1.Auth.config, 'sso');
|
|
134
|
-
}
|
|
135
54
|
async function getOrgSlug(config) {
|
|
136
55
|
const orgSlug = config?.orgSlug || process.env.CONTRAIL_CLI_ORG_SLUG;
|
|
137
56
|
if (!orgSlug) {
|
|
138
|
-
const answers = await
|
|
57
|
+
const answers = await (0, common_1.promptOnStderr)([
|
|
139
58
|
{
|
|
140
59
|
type: 'input',
|
|
141
60
|
name: 'orgSlug',
|
|
@@ -159,9 +78,41 @@ async function authenticateWithApiKey(config, apiKey, orgSlug) {
|
|
|
159
78
|
await (0, sdk_1.getCurrentUser)();
|
|
160
79
|
return returnAndStoreConfig(sdk_1.Auth.config);
|
|
161
80
|
}
|
|
162
|
-
async function authenticateWithUsernamePassword(
|
|
163
|
-
const
|
|
164
|
-
const
|
|
81
|
+
async function authenticateWithUsernamePassword(config) {
|
|
82
|
+
const apiGateway = getApiGateway(config);
|
|
83
|
+
const environment = (0, config_1.findEnvironmentName)(apiGateway);
|
|
84
|
+
if (!environment) {
|
|
85
|
+
throw new Error(`No Cognito user pool is known for ${apiGateway}. Email and password sign-in works for ${Object.keys(COGNITO_CONFIGS).join(' and ')}; use CONTRAIL_CLI_API_KEY for other environments.`);
|
|
86
|
+
}
|
|
87
|
+
const cognitoConfig = COGNITO_CONFIGS[environment];
|
|
88
|
+
const questions = [];
|
|
89
|
+
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
90
|
+
questions.push({
|
|
91
|
+
type: 'input',
|
|
92
|
+
name: 'email',
|
|
93
|
+
validate: (val) => !!val,
|
|
94
|
+
message: 'Email',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (!process.env.CONTRAIL_CLI_PASSWORD) {
|
|
98
|
+
questions.push({
|
|
99
|
+
type: 'password',
|
|
100
|
+
name: 'password',
|
|
101
|
+
validate: (val) => !!val,
|
|
102
|
+
message: 'Password',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const answers = await (0, common_1.promptOnStderr)(questions);
|
|
106
|
+
const params = {
|
|
107
|
+
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
108
|
+
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
109
|
+
orgSlug: await getOrgSlug(config),
|
|
110
|
+
apiGateway,
|
|
111
|
+
environment,
|
|
112
|
+
};
|
|
113
|
+
if (!params.email || !params.password) {
|
|
114
|
+
throw new Error('Email and Password required');
|
|
115
|
+
}
|
|
165
116
|
const poolData = {
|
|
166
117
|
UserPoolId: cognitoConfig.userPoolId,
|
|
167
118
|
ClientId: cognitoConfig.clientId,
|
|
@@ -169,7 +120,7 @@ async function authenticateWithUsernamePassword(params) {
|
|
|
169
120
|
const userPool = new amazon_cognito_identity_js_1.CognitoUserPool(poolData);
|
|
170
121
|
const authData = {
|
|
171
122
|
Username: params.email,
|
|
172
|
-
Password: password,
|
|
123
|
+
Password: params.password,
|
|
173
124
|
};
|
|
174
125
|
const authDetails = new amazon_cognito_identity_js_1.AuthenticationDetails(authData);
|
|
175
126
|
const userData = {
|
|
@@ -189,7 +140,7 @@ async function authenticateWithUsernamePassword(params) {
|
|
|
189
140
|
},
|
|
190
141
|
onFailure: (err) => {
|
|
191
142
|
if (err?.code === 'ResourceNotFoundException') {
|
|
192
|
-
reject(new Error(`This version of the CLI has outdated ${
|
|
143
|
+
reject(new Error(`This version of the CLI has outdated ${environment} sign-in settings (${err.message}). Update the CLI: npm i -g @contrail/cli`));
|
|
193
144
|
return;
|
|
194
145
|
}
|
|
195
146
|
reject(err);
|
|
@@ -197,12 +148,6 @@ async function authenticateWithUsernamePassword(params) {
|
|
|
197
148
|
});
|
|
198
149
|
});
|
|
199
150
|
}
|
|
200
|
-
async function promptForPassword() {
|
|
201
|
-
const answers = await inquirer_1.default.prompt([
|
|
202
|
-
{ type: 'password', name: 'password', validate: (val) => !!val, message: 'Password' },
|
|
203
|
-
]);
|
|
204
|
-
return answers.password;
|
|
205
|
-
}
|
|
206
151
|
async function setAuthContext(user, params) {
|
|
207
152
|
const apiGateway = params.apiGateway;
|
|
208
153
|
const { vibeAccessToken, vibeRefreshToken } = await getVibeAccessTokenFromCognitoAccessToken(user.idToken.jwtToken, apiGateway, params.environment);
|
|
@@ -217,7 +162,7 @@ async function setAuthContext(user, params) {
|
|
|
217
162
|
(0, sdk_1.setConfig)(sdk_1.Auth.config);
|
|
218
163
|
return refreshCurrentUserOrg();
|
|
219
164
|
}
|
|
220
|
-
async function signInWithStoredTokens(
|
|
165
|
+
async function signInWithStoredTokens() {
|
|
221
166
|
try {
|
|
222
167
|
await (0, sdk_1.getCurrentUser)();
|
|
223
168
|
}
|
|
@@ -226,7 +171,7 @@ async function signInWithStoredTokens(signInMethod) {
|
|
|
226
171
|
throw e;
|
|
227
172
|
}
|
|
228
173
|
logger_1.default.debug('access token rejected, refreshing it...');
|
|
229
|
-
await refreshAccessToken(
|
|
174
|
+
await refreshAccessToken();
|
|
230
175
|
await (0, sdk_1.getCurrentUser)();
|
|
231
176
|
}
|
|
232
177
|
return returnAndStoreConfig(sdk_1.Auth.config);
|
|
@@ -237,21 +182,13 @@ async function refreshCurrentUserOrg() {
|
|
|
237
182
|
// TODO: To uncomment when telemetry backend is developed.
|
|
238
183
|
// const current_Version = getVersionFromPackageJson();
|
|
239
184
|
// await checkTelemetry(current_Version);
|
|
240
|
-
return returnAndStoreConfig(sdk_1.Auth.config
|
|
185
|
+
return returnAndStoreConfig(sdk_1.Auth.config);
|
|
241
186
|
}
|
|
242
|
-
async function refreshAccessToken(
|
|
243
|
-
const
|
|
244
|
-
sdk_1.Auth.config = { ...sdk_1.Auth.config, apiUserToken:
|
|
187
|
+
async function refreshAccessToken() {
|
|
188
|
+
const newVibeAccessToken = await requestRefreshedAccessToken(sdk_1.Auth.config.apiRefreshToken, sdk_1.Auth.config.apiGateway);
|
|
189
|
+
sdk_1.Auth.config = { ...sdk_1.Auth.config, apiUserToken: newVibeAccessToken };
|
|
245
190
|
(0, sdk_1.setConfig)(sdk_1.Auth.config);
|
|
246
191
|
}
|
|
247
|
-
async function fetchRefreshedAccessTokenForSignInMethod(signInMethod) {
|
|
248
|
-
const { apiRefreshToken, apiGateway } = sdk_1.Auth.config;
|
|
249
|
-
if (signInMethod === 'sso') {
|
|
250
|
-
const ssoClient = COGNITO_CONFIGS[(0, config_1.findEnvironmentName)(apiGateway)].sso;
|
|
251
|
-
return (0, sso_1.refreshSsoAccessToken)(ssoClient, apiRefreshToken);
|
|
252
|
-
}
|
|
253
|
-
return requestRefreshedAccessToken(apiRefreshToken, apiGateway);
|
|
254
|
-
}
|
|
255
192
|
function getApiGateway(config) {
|
|
256
193
|
return config?.apiGateway ?? DEFAULT_API_GATEWAY;
|
|
257
194
|
}
|
|
@@ -301,9 +238,9 @@ function getVersionFromPackageJson() {
|
|
|
301
238
|
return packageJson.version;
|
|
302
239
|
}
|
|
303
240
|
exports.getVersionFromPackageJson = getVersionFromPackageJson;
|
|
304
|
-
async function returnAndStoreConfig(config
|
|
241
|
+
async function returnAndStoreConfig(config) {
|
|
305
242
|
const configCopy = Object.assign({}, config);
|
|
306
|
-
await (0, config_1.storeConfig)(
|
|
243
|
+
await (0, config_1.storeConfig)(configCopy);
|
|
307
244
|
return configCopy;
|
|
308
245
|
}
|
|
309
246
|
function isNetworkConnectionError(e) {
|