@contrail/cli 3.6.0-alpha.f45f126 → 3.7.0-alpha.fef3ff4
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 -1
- package/dist/api/types.d.ts +35 -0
- package/dist/api/types.js +49 -1
- package/dist/auth/login.d.ts +1 -1
- package/dist/auth/login.js +46 -29
- package/dist/auth/login.spec.js +31 -15
- package/dist/auth/sign-in-error.d.ts +7 -0
- package/dist/auth/sign-in-error.js +24 -0
- package/dist/auth/sign-in-error.spec.d.ts +1 -0
- package/dist/auth/sign-in-error.spec.js +22 -0
- package/dist/auth/sso.d.ts +5 -3
- package/dist/auth/sso.js +34 -18
- package/dist/auth/sso.spec.js +63 -10
- package/dist/basecommand.d.ts +3 -0
- package/dist/basecommand.js +10 -3
- 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.d.ts +1 -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/login.js +1 -1
- 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 -1
- 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.
|
|
20
|
+
@contrail/cli/3.7.0-alpha.fef3ff4 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)
|
|
@@ -540,6 +544,183 @@ EXAMPLES
|
|
|
540
544
|
$ contrail config use demo-org
|
|
541
545
|
```
|
|
542
546
|
|
|
547
|
+
## `contrail entities create TYPEPATH`
|
|
548
|
+
|
|
549
|
+
Create entities
|
|
550
|
+
|
|
551
|
+
```
|
|
552
|
+
USAGE
|
|
553
|
+
$ contrail entities create TYPEPATH [-l error|warn|info|debug] [-e true|false] [-n <value>] [-d] [-i <value>] [-o
|
|
554
|
+
<value>] [-g] [-r] [-S] [--suffix <value>] [--apiVersion 1|2]
|
|
555
|
+
|
|
556
|
+
ARGUMENTS
|
|
557
|
+
TYPEPATH The type path of the entity to create (e.g. color, custom-entity:franchise)
|
|
558
|
+
|
|
559
|
+
FLAGS
|
|
560
|
+
-S, --skipHydrateRelationships If true, does not hydrate relationships for the created entities
|
|
561
|
+
-d, --dryRun If true, does not create the entity but simulates the creation
|
|
562
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
563
|
+
<options: true|false>
|
|
564
|
+
-g, --generateValues If true, generates random values for properties that are not specified. By default,
|
|
565
|
+
only specified properties are used.
|
|
566
|
+
-i, --inputFile=<value> A file with a JSON array of objects where each object is one entity to create. Cannot
|
|
567
|
+
be used with --count. Unless --generateValues is specified, only the properties in
|
|
568
|
+
the file will be used.
|
|
569
|
+
-l, --logLevel=<option> The Log Level
|
|
570
|
+
<options: error|warn|info|debug>
|
|
571
|
+
-n, --count=<value> Number of random entities to create
|
|
572
|
+
-o, --outputFile=<value> File to save the output (optional)
|
|
573
|
+
-r, --readableIds If true, uses readable IDs for the created entities
|
|
574
|
+
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
575
|
+
<options: 1|2>
|
|
576
|
+
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
577
|
+
/<entities>/synchronous)
|
|
578
|
+
|
|
579
|
+
DESCRIPTION
|
|
580
|
+
Create entities
|
|
581
|
+
|
|
582
|
+
EXAMPLES
|
|
583
|
+
$ contrail entities create color -g -n=10 # creates 10 random colors
|
|
584
|
+
|
|
585
|
+
$ contrail entities create color -- name="Electric Blue" green=1 red=2 blue=3 # creates one color with specified properties only
|
|
586
|
+
|
|
587
|
+
$ contrail entities create custom-entity:franchise
|
|
588
|
+
|
|
589
|
+
$ contrail entities create project-item -n=10 -- projectId=abc # creates 10 project items within project ABC
|
|
590
|
+
|
|
591
|
+
$ contrail entities create color -g -r # creates a random color with a human readable ID
|
|
592
|
+
|
|
593
|
+
$ contrail entities create color -d -- name=test # simulates the creation of a color without actually creating it
|
|
594
|
+
|
|
595
|
+
$ contrail entities create custom-entity:franchise -S # creates an entity and the response does not contain hydrated relationships
|
|
596
|
+
|
|
597
|
+
$ contrail entities create color -g -- name="Electric Blue" # creates a color with the name specified and other properties auto-generated
|
|
598
|
+
|
|
599
|
+
$ 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
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
## `contrail entities delete ENTITYNAME [IDS]`
|
|
603
|
+
|
|
604
|
+
Delete entities by id
|
|
605
|
+
|
|
606
|
+
```
|
|
607
|
+
USAGE
|
|
608
|
+
$ contrail entities delete ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-d] [-i <value>] [--suffix
|
|
609
|
+
<value>] [--apiVersion 1|2]
|
|
610
|
+
|
|
611
|
+
ARGUMENTS
|
|
612
|
+
ENTITYNAME The name of the entity type to delete (type paths are not supported)
|
|
613
|
+
IDS One or more entity ids to delete
|
|
614
|
+
|
|
615
|
+
FLAGS
|
|
616
|
+
-d, --dryRun If true, does not delete the entities but simulates the deletion
|
|
617
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
618
|
+
<options: true|false>
|
|
619
|
+
-i, --inputFile=<value> A file with a JSON array of objects; only each object's id is used. Deletes every
|
|
620
|
+
entity in the file.
|
|
621
|
+
-l, --logLevel=<option> The Log Level
|
|
622
|
+
<options: error|warn|info|debug>
|
|
623
|
+
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
624
|
+
<options: 1|2>
|
|
625
|
+
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
626
|
+
/<entities>/synchronous)
|
|
627
|
+
|
|
628
|
+
DESCRIPTION
|
|
629
|
+
Delete entities by id
|
|
630
|
+
|
|
631
|
+
EXAMPLES
|
|
632
|
+
$ contrail entities delete color 123
|
|
633
|
+
|
|
634
|
+
$ contrail entities delete color id1 id2 id3
|
|
635
|
+
|
|
636
|
+
$ contrail entities delete item -i ids.json
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
## `contrail entities get ENTITYNAME [IDS]`
|
|
640
|
+
|
|
641
|
+
Get an entity
|
|
642
|
+
|
|
643
|
+
```
|
|
644
|
+
USAGE
|
|
645
|
+
$ contrail entities get ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-o <value>] [-p <value>]
|
|
646
|
+
[-P] [-s <value>] [-S] [-t <value>] [-r <value>] [--suffix <value>] [--apiVersion 1|2]
|
|
647
|
+
|
|
648
|
+
ARGUMENTS
|
|
649
|
+
ENTITYNAME The name of the entity type to fetch (type paths are not supported)
|
|
650
|
+
IDS One or more entity ids; shorthand for the id/ids criteria
|
|
651
|
+
|
|
652
|
+
FLAGS
|
|
653
|
+
-P, --paginated If true, fetches all entities in a paginated manner
|
|
654
|
+
-S, --skipHydrateRelationships Skip hydrating relationships when fetching the entity
|
|
655
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
656
|
+
<options: true|false>
|
|
657
|
+
-l, --logLevel=<option> The Log Level
|
|
658
|
+
<options: error|warn|info|debug>
|
|
659
|
+
-o, --outputFile=<value> File to save the output (optional)
|
|
660
|
+
-p, --propertySlugs=<value> Comma-separated list of property slugs to include in the output. Only some entity
|
|
661
|
+
types support this; the rest return full records.
|
|
662
|
+
-r, --relations=<value> Comma-separated list of relations to include in the output
|
|
663
|
+
-s, --skip=<value> Number of entities to skip
|
|
664
|
+
-t, --take=<value> Number of entities to fetch in a single request (default is 100)
|
|
665
|
+
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
666
|
+
<options: 1|2>
|
|
667
|
+
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
668
|
+
/<entities>/synchronous)
|
|
669
|
+
|
|
670
|
+
DESCRIPTION
|
|
671
|
+
Get an entity
|
|
672
|
+
|
|
673
|
+
EXAMPLES
|
|
674
|
+
$ contrail entities get color 123
|
|
675
|
+
|
|
676
|
+
$ contrail entities get color id1 id2 id3
|
|
677
|
+
|
|
678
|
+
$ contrail entities get color -- id=123
|
|
679
|
+
|
|
680
|
+
$ contrail entities get loader-process -- createdOn=2026-09-01..2026-09-11
|
|
681
|
+
|
|
682
|
+
$ contrail entities get loader-process -- createdOn=2026-09-05..
|
|
683
|
+
|
|
684
|
+
$ contrail entities get loader-process -- createdOn=..2026-09-05
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
## `contrail entities update ENTITYNAME [IDS]`
|
|
688
|
+
|
|
689
|
+
Update an entity
|
|
690
|
+
|
|
691
|
+
```
|
|
692
|
+
USAGE
|
|
693
|
+
$ contrail entities update ENTITYNAME [IDS] [-l error|warn|info|debug] [-e true|false] [-S] [-d] [-i <value>]
|
|
694
|
+
[--suffix <value>] [--apiVersion 1|2]
|
|
695
|
+
|
|
696
|
+
ARGUMENTS
|
|
697
|
+
ENTITYNAME The name of the entity type to update (type paths are not supported)
|
|
698
|
+
IDS One or more entity ids to update
|
|
699
|
+
|
|
700
|
+
FLAGS
|
|
701
|
+
-S, --skipHydrateRelationships Skip hydrating relationships when updating the entity
|
|
702
|
+
-d, --dryRun If true, does not update the entities but simulates the update
|
|
703
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
704
|
+
<options: true|false>
|
|
705
|
+
-i, --inputFile=<value> A file with a JSON array of {id, ...} objects; each object is one entity to update.
|
|
706
|
+
-l, --logLevel=<option> The Log Level
|
|
707
|
+
<options: error|warn|info|debug>
|
|
708
|
+
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
709
|
+
<options: 1|2>
|
|
710
|
+
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
711
|
+
/<entities>/synchronous)
|
|
712
|
+
|
|
713
|
+
DESCRIPTION
|
|
714
|
+
Update an entity
|
|
715
|
+
|
|
716
|
+
EXAMPLES
|
|
717
|
+
$ contrail entities update color 123 -- name=obsidian hex=000000
|
|
718
|
+
|
|
719
|
+
$ contrail entities update item id1 id2 id3 -- colorName=obsidian # apply the same change to several entities
|
|
720
|
+
|
|
721
|
+
$ contrail entities update color 123 -- federatedId= name='""' # Unset federatedId, set name to empty string
|
|
722
|
+
```
|
|
723
|
+
|
|
543
724
|
## `contrail feature-flags export`
|
|
544
725
|
|
|
545
726
|
Export the enabled feature flags 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,6 +1,6 @@
|
|
|
1
1
|
import { AuthContext } from '@contrail/sdk';
|
|
2
2
|
export interface SignInOptions {
|
|
3
|
-
|
|
3
|
+
shouldOpenBrowser: boolean;
|
|
4
4
|
}
|
|
5
5
|
export declare function authUser(): Promise<AuthContext>;
|
|
6
6
|
export declare function signIn(options: SignInOptions): Promise<AuthContext>;
|
package/dist/auth/login.js
CHANGED
|
@@ -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: '
|
|
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: '
|
|
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({
|
|
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 = (
|
|
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
|
-
|
|
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
|
|
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
|
|
107
|
-
const usesLoopback = options.
|
|
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,
|
|
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)(
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
119
|
-
const answers = await
|
|
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,
|
|
136
|
+
code = (0, sso_1.parsePastedSignInCode)(answers.signInCode, signInAttempt.state);
|
|
123
137
|
}
|
|
124
|
-
const tokens = await (0, sso_1.exchangeCodeForTokens)(ssoClient, code, redirectUri,
|
|
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
|
|
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
|
|
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,
|
|
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[(
|
|
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)(
|
|
323
|
+
await (0, config_1.storeConfig)({ ...configCopy, signInMethod });
|
|
307
324
|
return configCopy;
|
|
308
325
|
}
|
|
309
326
|
function isNetworkConnectionError(e) {
|
package/dist/auth/login.spec.js
CHANGED
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const amazon_cognito_identity_js_1 = require("amazon-cognito-identity-js");
|
|
5
5
|
const sdk_1 = require("@contrail/sdk");
|
|
6
|
-
const
|
|
6
|
+
const common = tslib_1.__importStar(require("../common"));
|
|
7
7
|
const config_1 = require("../helpers/config/config");
|
|
8
|
-
const logger_1 = tslib_1.__importDefault(require("../logger"));
|
|
9
8
|
const login_1 = require("./login");
|
|
10
9
|
const mockAuthenticateUser = jest.fn();
|
|
11
10
|
jest.mock('amazon-cognito-identity-js', () => ({
|
|
@@ -104,14 +103,17 @@ describe('authUser with email and password', () => {
|
|
|
104
103
|
apiGateway: 'api.dev.vibeiq.com/dev/api',
|
|
105
104
|
orgSlug: 'adam-zone-1',
|
|
106
105
|
});
|
|
107
|
-
await expect((0, login_1.authUser)()).rejects.
|
|
106
|
+
await expect((0, login_1.authUser)()).rejects.toMatchObject({
|
|
107
|
+
code: 'ENVIRONMENT_NOT_CONFIGURED',
|
|
108
|
+
details: { apiGateway: 'api.dev.vibeiq.com/dev/api' },
|
|
109
|
+
});
|
|
108
110
|
});
|
|
109
111
|
it('should fail without saving tokens when no pool is known for the environment', async () => {
|
|
110
112
|
config_1.getConfig.mockResolvedValue({
|
|
111
113
|
apiGateway: 'http://localhost:3000/api',
|
|
112
114
|
orgSlug: 'adam-zone-1',
|
|
113
115
|
});
|
|
114
|
-
await expect((0, login_1.authUser)()).rejects.
|
|
116
|
+
await expect((0, login_1.authUser)()).rejects.toMatchObject({ code: 'ENVIRONMENT_NOT_CONFIGURED' });
|
|
115
117
|
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
116
118
|
});
|
|
117
119
|
it('should tell the user to update the CLI when its Cognito client or pool no longer exists', async () => {
|
|
@@ -172,7 +174,7 @@ describe('authUser with stored tokens', () => {
|
|
|
172
174
|
const context = await (0, login_1.authUser)();
|
|
173
175
|
expect(fetchMock).toHaveBeenCalledWith(`${DEV_GATEWAY}/auth/jwt_refresh/`, expect.objectContaining({ body: JSON.stringify({ refreshToken: 'stored-refresh' }) }));
|
|
174
176
|
expect(context).toEqual({ ...storedConfig, apiUserToken: 'refreshed-access' });
|
|
175
|
-
expect(config_1.storeConfig).toHaveBeenCalledWith(context);
|
|
177
|
+
expect(config_1.storeConfig).toHaveBeenCalledWith({ ...context, signInMethod: 'password' });
|
|
176
178
|
});
|
|
177
179
|
it('should keep a still-valid access token without refreshing it', async () => {
|
|
178
180
|
acceptedTokens = ['expired-access'];
|
|
@@ -219,10 +221,11 @@ describe('signIn with SSO', () => {
|
|
|
219
221
|
const DEV_COGNITO_DOMAIN = 'https://dev-vibeiq.auth.us-east-1.amazoncognito.com';
|
|
220
222
|
let fetchMock;
|
|
221
223
|
let promptSpy;
|
|
224
|
+
let consoleLogSpy;
|
|
222
225
|
function pasteCodeFromPrintedSignInUrl() {
|
|
223
226
|
promptSpy.mockImplementation(async () => {
|
|
224
|
-
const
|
|
225
|
-
const signInUrl = new URL(
|
|
227
|
+
const printedOutput = consoleLogSpy.mock.calls.map(([message]) => message).join('\n');
|
|
228
|
+
const signInUrl = new URL(printedOutput.match(/https:\/\/\S+oauth2\/authorize\S+/)[0]);
|
|
226
229
|
return { signInCode: `pasted-code#${signInUrl.searchParams.get('state')}` };
|
|
227
230
|
});
|
|
228
231
|
}
|
|
@@ -233,13 +236,15 @@ describe('signIn with SSO', () => {
|
|
|
233
236
|
config_1.getConfig.mockResolvedValue({ apiGateway: DEV_GATEWAY, orgSlug: 'adam-zone-1' });
|
|
234
237
|
sdk_1.getCurrentUser.mockResolvedValue({ id: 'user-1' });
|
|
235
238
|
mockAuthenticateUser.mockImplementation((_details, callbacks) => callbacks.onSuccess({ idToken: { jwtToken: 'cognito-id-token' } }));
|
|
236
|
-
|
|
239
|
+
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
240
|
+
promptSpy = jest.spyOn(common, 'promptOnStderr');
|
|
237
241
|
pasteCodeFromPrintedSignInUrl();
|
|
238
242
|
fetchMock = jest.fn();
|
|
239
243
|
global.fetch = fetchMock;
|
|
240
244
|
});
|
|
241
245
|
afterEach(() => {
|
|
242
246
|
promptSpy.mockRestore();
|
|
247
|
+
consoleLogSpy.mockRestore();
|
|
243
248
|
global.fetch = originalFetch;
|
|
244
249
|
restoreEnv('CONTRAIL_CLI_EMAIL', originalEmail);
|
|
245
250
|
restoreEnv('CONTRAIL_CLI_PASSWORD', originalPassword);
|
|
@@ -248,8 +253,7 @@ describe('signIn with SSO', () => {
|
|
|
248
253
|
fetchMock
|
|
249
254
|
.mockResolvedValueOnce(jsonResponse(200, { identityProvider: 'sso-vibeiq-com' }))
|
|
250
255
|
.mockResolvedValueOnce(jsonResponse(200, { access_token: 'cognito-access', refresh_token: 'cognito-refresh' }));
|
|
251
|
-
const context = await (0, login_1.signIn)({
|
|
252
|
-
expect(fetchMock.mock.calls[0][0]).toBe(`${DEV_GATEWAY}/sso-login/domain-check/vibeiq.com`);
|
|
256
|
+
const context = await (0, login_1.signIn)({ shouldOpenBrowser: false });
|
|
253
257
|
const [tokenUrl, tokenRequest] = fetchMock.mock.calls[1];
|
|
254
258
|
const tokenForm = new URLSearchParams(tokenRequest.body);
|
|
255
259
|
expect(tokenUrl).toBe(`${DEV_COGNITO_DOMAIN}/oauth2/token`);
|
|
@@ -266,7 +270,9 @@ describe('signIn with SSO', () => {
|
|
|
266
270
|
it('should reject a pasted code from a different sign-in attempt without saving tokens', async () => {
|
|
267
271
|
fetchMock.mockResolvedValueOnce(jsonResponse(200, { identityProvider: 'sso-vibeiq-com' }));
|
|
268
272
|
promptSpy.mockResolvedValue({ signInCode: 'pasted-code#another-state' });
|
|
269
|
-
await expect((0, login_1.signIn)({
|
|
273
|
+
await expect((0, login_1.signIn)({ shouldOpenBrowser: false })).rejects.toMatchObject({
|
|
274
|
+
code: 'SSO_SIGN_IN_CODE_MISMATCH',
|
|
275
|
+
});
|
|
270
276
|
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
271
277
|
});
|
|
272
278
|
it('should ask for a password when the email domain has no SSO', async () => {
|
|
@@ -274,8 +280,7 @@ describe('signIn with SSO', () => {
|
|
|
274
280
|
.mockResolvedValueOnce(new Response('', { status: 200 }))
|
|
275
281
|
.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
276
282
|
promptSpy.mockResolvedValue({ password: 'secret' });
|
|
277
|
-
const context = await (0, login_1.signIn)({
|
|
278
|
-
expect(mockAuthenticateUser).toHaveBeenCalled();
|
|
283
|
+
const context = await (0, login_1.signIn)({ shouldOpenBrowser: false });
|
|
279
284
|
expect(context.apiUserToken).toBe('vibe-access');
|
|
280
285
|
expect(config_1.storeConfig).toHaveBeenCalledWith({ ...context, signInMethod: 'password' });
|
|
281
286
|
});
|
|
@@ -284,9 +289,9 @@ describe('signIn with SSO', () => {
|
|
|
284
289
|
.mockResolvedValueOnce(jsonResponse(200, { identityProvider: '', url: 'legacy' }))
|
|
285
290
|
.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
286
291
|
promptSpy.mockResolvedValue({ password: 'secret' });
|
|
287
|
-
const context = await (0, login_1.signIn)({
|
|
292
|
+
const context = await (0, login_1.signIn)({ shouldOpenBrowser: false });
|
|
288
293
|
expect(context.apiUserToken).toBe('vibe-access');
|
|
289
|
-
expect(
|
|
294
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('The CLI does not support your SSO provider yet.'));
|
|
290
295
|
});
|
|
291
296
|
it('should refresh a stored SSO token through Cognito instead of the VibeIQ refresh endpoint', async () => {
|
|
292
297
|
config_1.getConfig.mockResolvedValue({
|
|
@@ -306,6 +311,17 @@ describe('signIn with SSO', () => {
|
|
|
306
311
|
expect(new URLSearchParams(tokenRequest.body).get('refresh_token')).toBe('cognito-refresh');
|
|
307
312
|
expect(context.apiUserToken).toBe('refreshed-access');
|
|
308
313
|
});
|
|
314
|
+
it('should name the misconfiguration when a stored SSO token points at an unknown environment', async () => {
|
|
315
|
+
config_1.getConfig.mockResolvedValue({
|
|
316
|
+
apiUserToken: 'expired-access',
|
|
317
|
+
apiRefreshToken: 'cognito-refresh',
|
|
318
|
+
apiGateway: 'http://localhost:3000/api',
|
|
319
|
+
orgSlug: 'adam-zone-1',
|
|
320
|
+
signInMethod: 'sso',
|
|
321
|
+
});
|
|
322
|
+
sdk_1.getCurrentUser.mockRejectedValueOnce(new Error('Failed to fetch current user. Unauthorized'));
|
|
323
|
+
await expect((0, login_1.authUser)()).rejects.toMatchObject({ code: 'ENVIRONMENT_NOT_CONFIGURED' });
|
|
324
|
+
});
|
|
309
325
|
});
|
|
310
326
|
describe('getVersionFromPackageJson', () => {
|
|
311
327
|
it('should return the version value from package.json', () => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type SignInErrorCode = 'ENVIRONMENT_NOT_CONFIGURED' | 'SSO_DOMAIN_CHECK_FAILED' | 'SSO_SIGN_IN_CODE_MISMATCH' | 'SSO_SIGN_IN_REJECTED' | 'SSO_UNEXPECTED_CALLBACK' | 'SSO_SIGN_IN_TIMED_OUT' | 'SSO_LOOPBACK_PORT_IN_USE' | 'SSO_TOKEN_REQUEST_FAILED' | 'API_KEY_CANNOT_REFRESH';
|
|
2
|
+
export declare class SignInError extends Error {
|
|
3
|
+
readonly code: SignInErrorCode;
|
|
4
|
+
readonly details: Record<string, string | number | undefined>;
|
|
5
|
+
constructor(code: SignInErrorCode, message: string, details?: Record<string, string | number | undefined>);
|
|
6
|
+
}
|
|
7
|
+
export declare function formatErrorForTerminal(error: Error): string;
|