@contrail/cli 3.6.0-alpha.f45f126 → 3.7.0-alpha.0d7ff29
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 +405 -71
- 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 +47 -29
- package/dist/auth/login.spec.js +48 -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/baseFlags.d.ts +4 -0
- package/dist/baseFlags.js +9 -1
- package/dist/basecommand.d.ts +5 -0
- package/dist/basecommand.js +17 -4
- package/dist/basecommand.spec.d.ts +1 -0
- package/dist/basecommand.spec.js +69 -0
- package/dist/commands/app/create.d.ts +1 -0
- package/dist/commands/app/delete.d.ts +1 -0
- package/dist/commands/app/extension/deploy.d.ts +1 -0
- package/dist/commands/app/extension/deployment/list.d.ts +1 -0
- package/dist/commands/app/getApiKey.d.ts +1 -0
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/app/init.d.ts +1 -0
- package/dist/commands/app/install.d.ts +1 -0
- package/dist/commands/app/publish.d.ts +1 -0
- package/dist/commands/app/uninstall.d.ts +1 -0
- package/dist/commands/app/upgrade.d.ts +1 -0
- package/dist/commands/app/version/major.d.ts +1 -0
- package/dist/commands/app/version/minor.d.ts +1 -0
- package/dist/commands/app/version/patch.d.ts +1 -0
- package/dist/commands/config/create.d.ts +2 -0
- package/dist/commands/config/create.js +1 -0
- package/dist/commands/config/describe.d.ts +2 -0
- package/dist/commands/config/describe.js +7 -4
- package/dist/commands/config/list.d.ts +2 -0
- package/dist/commands/config/list.js +2 -3
- package/dist/commands/config/set.d.ts +1 -0
- package/dist/commands/config/set.js +11 -6
- package/dist/commands/config/use.d.ts +2 -0
- package/dist/commands/config/use.js +4 -0
- package/dist/commands/entities/create.d.ts +50 -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 +21 -0
- package/dist/commands/entities/delete.js +146 -0
- package/dist/commands/entities/get.d.ts +26 -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 +33 -0
- package/dist/commands/entities/update.js +212 -0
- package/dist/commands/feature-flags/export.d.ts +1 -0
- package/dist/commands/feature-flags/import.d.ts +1 -0
- package/dist/commands/file/upload.d.ts +1 -0
- package/dist/commands/groups/export.d.ts +1 -0
- package/dist/commands/groups/import.d.ts +1 -0
- package/dist/commands/instance/export.d.ts +1 -0
- package/dist/commands/instance/import.d.ts +1 -0
- package/dist/commands/load/colors.d.ts +1 -0
- package/dist/commands/load/custom-entity.d.ts +1 -0
- package/dist/commands/load/line-sheet.d.ts +1 -0
- package/dist/commands/load/upload-and-load.d.ts +1 -0
- package/dist/commands/load-local/index.d.ts +1 -0
- package/dist/commands/login.d.ts +1 -0
- package/dist/commands/login.js +1 -1
- package/dist/commands/org-config/export.d.ts +1 -0
- package/dist/commands/org-config/import.d.ts +1 -0
- package/dist/commands/projects/export.d.ts +1 -0
- package/dist/commands/projects/list.d.ts +1 -0
- package/dist/commands/projects/load.d.ts +1 -0
- package/dist/commands/types/exportOptionSetHierarchies.d.ts +1 -0
- package/dist/commands/types/getAll.d.ts +1 -0
- package/dist/commands/types/getOptionSets.d.ts +1 -0
- package/dist/commands/types/loadAll.d.ts +1 -0
- package/dist/commands/types/mergeOptionSets.d.ts +1 -0
- package/dist/commands/types/mergeTypeProperties.d.ts +1 -0
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +1 -0
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.d.ts +1 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +1 -0
- package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +1 -0
- package/dist/commands/types/parseTypesFromFiles.d.ts +1 -0
- package/dist/commands/types/parseTypesFromLocalFiles.d.ts +1 -0
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +1 -0
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +1 -0
- package/dist/commands/types/uploadOptionSetHierarchies.d.ts +1 -0
- package/dist/commands/types/uploadOptionSets.d.ts +1 -0
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +1 -0
- package/dist/commands/types/uploadRuleSets.d.ts +1 -0
- package/dist/commands/types/uploadTypeOverrides.d.ts +1 -0
- package/dist/commands/types/uploadTypePolicies.d.ts +1 -0
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +1 -0
- package/dist/commands/types/uploadTypes.d.ts +1 -0
- package/dist/commands/users/export.d.ts +1 -0
- package/dist/commands/users/import.d.ts +1 -0
- package/dist/commands/webhooks/create.d.ts +1 -0
- package/dist/commands/webhooks/delete.d.ts +1 -0
- package/dist/commands/webhooks/delete.js +2 -3
- package/dist/commands/webhooks/getWebhookTrigger.d.ts +1 -0
- package/dist/commands/webhooks/list.d.ts +1 -0
- package/dist/commands/workflow-template-definitions/install.d.ts +1 -0
- package/dist/commands/workflow-template-definitions/list.d.ts +1 -0
- package/dist/commands/workflow-templates/delete.d.ts +1 -0
- package/dist/commands/workflow-templates/export.d.ts +1 -0
- package/dist/commands/workflow-templates/list.d.ts +1 -0
- package/dist/commands/workflow-templates/load.d.ts +1 -0
- 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 +4 -3
- package/dist/helpers/config/config.js +52 -45
- package/dist/helpers/config/config.spec.d.ts +1 -0
- package/dist/helpers/config/config.spec.js +79 -0
- package/dist/helpers/config/redact-tokens.d.ts +1 -0
- package/dist/helpers/config/redact-tokens.js +14 -0
- package/dist/helpers/config/redact-tokens.spec.d.ts +1 -0
- package/dist/helpers/config/redact-tokens.spec.js +24 -0
- 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 +969 -9
- package/package.json +6 -12
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,8 @@ 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
|
-
|
|
174
|
+
await (0, config_1.storeConfig)({ orgSlug, apiGateway });
|
|
175
|
+
return Object.assign({}, sdk_1.Auth.config);
|
|
161
176
|
}
|
|
162
177
|
async function authenticateWithUsernamePassword(params) {
|
|
163
178
|
const cognitoConfig = COGNITO_CONFIGS[params.environment];
|
|
@@ -198,7 +213,7 @@ async function authenticateWithUsernamePassword(params) {
|
|
|
198
213
|
});
|
|
199
214
|
}
|
|
200
215
|
async function promptForPassword() {
|
|
201
|
-
const answers = await
|
|
216
|
+
const answers = await (0, common_1.promptOnStderr)([
|
|
202
217
|
{ type: 'password', name: 'password', validate: (val) => !!val, message: 'Password' },
|
|
203
218
|
]);
|
|
204
219
|
return answers.password;
|
|
@@ -215,7 +230,7 @@ async function setAuthContext(user, params) {
|
|
|
215
230
|
};
|
|
216
231
|
// SET SDK CONFIG
|
|
217
232
|
(0, sdk_1.setConfig)(sdk_1.Auth.config);
|
|
218
|
-
return refreshCurrentUserOrg();
|
|
233
|
+
return refreshCurrentUserOrg('password');
|
|
219
234
|
}
|
|
220
235
|
async function signInWithStoredTokens(signInMethod) {
|
|
221
236
|
try {
|
|
@@ -229,15 +244,15 @@ async function signInWithStoredTokens(signInMethod) {
|
|
|
229
244
|
await refreshAccessToken(signInMethod);
|
|
230
245
|
await (0, sdk_1.getCurrentUser)();
|
|
231
246
|
}
|
|
232
|
-
return returnAndStoreConfig(sdk_1.Auth.config);
|
|
247
|
+
return returnAndStoreConfig(sdk_1.Auth.config, signInMethod);
|
|
233
248
|
}
|
|
234
|
-
async function refreshCurrentUserOrg() {
|
|
249
|
+
async function refreshCurrentUserOrg(signInMethod) {
|
|
235
250
|
logger_1.default.debug('refreshing current user org...');
|
|
236
251
|
await (0, sdk_1.getCurrentUser)();
|
|
237
252
|
// TODO: To uncomment when telemetry backend is developed.
|
|
238
253
|
// const current_Version = getVersionFromPackageJson();
|
|
239
254
|
// await checkTelemetry(current_Version);
|
|
240
|
-
return returnAndStoreConfig(sdk_1.Auth.config,
|
|
255
|
+
return returnAndStoreConfig(sdk_1.Auth.config, signInMethod);
|
|
241
256
|
}
|
|
242
257
|
async function refreshAccessToken(signInMethod) {
|
|
243
258
|
const newAccessToken = await fetchRefreshedAccessTokenForSignInMethod(signInMethod);
|
|
@@ -247,9 +262,12 @@ async function refreshAccessToken(signInMethod) {
|
|
|
247
262
|
async function fetchRefreshedAccessTokenForSignInMethod(signInMethod) {
|
|
248
263
|
const { apiRefreshToken, apiGateway } = sdk_1.Auth.config;
|
|
249
264
|
if (signInMethod === 'sso') {
|
|
250
|
-
const ssoClient = COGNITO_CONFIGS[(
|
|
265
|
+
const ssoClient = COGNITO_CONFIGS[getSignInEnvironment(apiGateway)].sso;
|
|
251
266
|
return (0, sso_1.refreshSsoAccessToken)(ssoClient, apiRefreshToken);
|
|
252
267
|
}
|
|
268
|
+
if (signInMethod === 'apiKey') {
|
|
269
|
+
throw new sign_in_error_1.SignInError('API_KEY_CANNOT_REFRESH', 'An API key cannot be refreshed. Set a new one.');
|
|
270
|
+
}
|
|
253
271
|
return requestRefreshedAccessToken(apiRefreshToken, apiGateway);
|
|
254
272
|
}
|
|
255
273
|
function getApiGateway(config) {
|
|
@@ -303,7 +321,7 @@ function getVersionFromPackageJson() {
|
|
|
303
321
|
exports.getVersionFromPackageJson = getVersionFromPackageJson;
|
|
304
322
|
async function returnAndStoreConfig(config, signInMethod) {
|
|
305
323
|
const configCopy = Object.assign({}, config);
|
|
306
|
-
await (0, config_1.storeConfig)(
|
|
324
|
+
await (0, config_1.storeConfig)({ ...configCopy, signInMethod });
|
|
307
325
|
return configCopy;
|
|
308
326
|
}
|
|
309
327
|
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 () => {
|
|
@@ -128,6 +130,23 @@ describe('authUser with email and password', () => {
|
|
|
128
130
|
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
129
131
|
});
|
|
130
132
|
});
|
|
133
|
+
describe('authUser with an API key', () => {
|
|
134
|
+
const originalApiKey = process.env.CONTRAIL_CLI_API_KEY;
|
|
135
|
+
beforeEach(() => {
|
|
136
|
+
jest.clearAllMocks();
|
|
137
|
+
process.env.CONTRAIL_CLI_API_KEY = 'api-key-from-env';
|
|
138
|
+
config_1.getConfig.mockResolvedValue({ apiGateway: DEV_GATEWAY, orgSlug: 'adam-zone-1' });
|
|
139
|
+
sdk_1.getCurrentUser.mockResolvedValue({ id: 'user-1' });
|
|
140
|
+
});
|
|
141
|
+
afterEach(() => {
|
|
142
|
+
restoreEnv('CONTRAIL_CLI_API_KEY', originalApiKey);
|
|
143
|
+
});
|
|
144
|
+
it('should sign in with the key and save only the org and environment', async () => {
|
|
145
|
+
const context = await (0, login_1.authUser)();
|
|
146
|
+
expect(context).toMatchObject({ apiUserToken: 'api-key-from-env', orgSlug: 'adam-zone-1' });
|
|
147
|
+
expect(config_1.storeConfig).toHaveBeenCalledWith({ orgSlug: 'adam-zone-1', apiGateway: DEV_GATEWAY });
|
|
148
|
+
});
|
|
149
|
+
});
|
|
131
150
|
describe('authUser with stored tokens', () => {
|
|
132
151
|
const originalFetch = global.fetch;
|
|
133
152
|
const originalEmail = process.env.CONTRAIL_CLI_EMAIL;
|
|
@@ -172,7 +191,7 @@ describe('authUser with stored tokens', () => {
|
|
|
172
191
|
const context = await (0, login_1.authUser)();
|
|
173
192
|
expect(fetchMock).toHaveBeenCalledWith(`${DEV_GATEWAY}/auth/jwt_refresh/`, expect.objectContaining({ body: JSON.stringify({ refreshToken: 'stored-refresh' }) }));
|
|
174
193
|
expect(context).toEqual({ ...storedConfig, apiUserToken: 'refreshed-access' });
|
|
175
|
-
expect(config_1.storeConfig).toHaveBeenCalledWith(context);
|
|
194
|
+
expect(config_1.storeConfig).toHaveBeenCalledWith({ ...context, signInMethod: 'password' });
|
|
176
195
|
});
|
|
177
196
|
it('should keep a still-valid access token without refreshing it', async () => {
|
|
178
197
|
acceptedTokens = ['expired-access'];
|
|
@@ -219,10 +238,11 @@ describe('signIn with SSO', () => {
|
|
|
219
238
|
const DEV_COGNITO_DOMAIN = 'https://dev-vibeiq.auth.us-east-1.amazoncognito.com';
|
|
220
239
|
let fetchMock;
|
|
221
240
|
let promptSpy;
|
|
241
|
+
let consoleLogSpy;
|
|
222
242
|
function pasteCodeFromPrintedSignInUrl() {
|
|
223
243
|
promptSpy.mockImplementation(async () => {
|
|
224
|
-
const
|
|
225
|
-
const signInUrl = new URL(
|
|
244
|
+
const printedOutput = consoleLogSpy.mock.calls.map(([message]) => message).join('\n');
|
|
245
|
+
const signInUrl = new URL(printedOutput.match(/https:\/\/\S+oauth2\/authorize\S+/)[0]);
|
|
226
246
|
return { signInCode: `pasted-code#${signInUrl.searchParams.get('state')}` };
|
|
227
247
|
});
|
|
228
248
|
}
|
|
@@ -233,13 +253,15 @@ describe('signIn with SSO', () => {
|
|
|
233
253
|
config_1.getConfig.mockResolvedValue({ apiGateway: DEV_GATEWAY, orgSlug: 'adam-zone-1' });
|
|
234
254
|
sdk_1.getCurrentUser.mockResolvedValue({ id: 'user-1' });
|
|
235
255
|
mockAuthenticateUser.mockImplementation((_details, callbacks) => callbacks.onSuccess({ idToken: { jwtToken: 'cognito-id-token' } }));
|
|
236
|
-
|
|
256
|
+
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
257
|
+
promptSpy = jest.spyOn(common, 'promptOnStderr');
|
|
237
258
|
pasteCodeFromPrintedSignInUrl();
|
|
238
259
|
fetchMock = jest.fn();
|
|
239
260
|
global.fetch = fetchMock;
|
|
240
261
|
});
|
|
241
262
|
afterEach(() => {
|
|
242
263
|
promptSpy.mockRestore();
|
|
264
|
+
consoleLogSpy.mockRestore();
|
|
243
265
|
global.fetch = originalFetch;
|
|
244
266
|
restoreEnv('CONTRAIL_CLI_EMAIL', originalEmail);
|
|
245
267
|
restoreEnv('CONTRAIL_CLI_PASSWORD', originalPassword);
|
|
@@ -248,8 +270,7 @@ describe('signIn with SSO', () => {
|
|
|
248
270
|
fetchMock
|
|
249
271
|
.mockResolvedValueOnce(jsonResponse(200, { identityProvider: 'sso-vibeiq-com' }))
|
|
250
272
|
.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`);
|
|
273
|
+
const context = await (0, login_1.signIn)({ shouldOpenBrowser: false });
|
|
253
274
|
const [tokenUrl, tokenRequest] = fetchMock.mock.calls[1];
|
|
254
275
|
const tokenForm = new URLSearchParams(tokenRequest.body);
|
|
255
276
|
expect(tokenUrl).toBe(`${DEV_COGNITO_DOMAIN}/oauth2/token`);
|
|
@@ -266,7 +287,9 @@ describe('signIn with SSO', () => {
|
|
|
266
287
|
it('should reject a pasted code from a different sign-in attempt without saving tokens', async () => {
|
|
267
288
|
fetchMock.mockResolvedValueOnce(jsonResponse(200, { identityProvider: 'sso-vibeiq-com' }));
|
|
268
289
|
promptSpy.mockResolvedValue({ signInCode: 'pasted-code#another-state' });
|
|
269
|
-
await expect((0, login_1.signIn)({
|
|
290
|
+
await expect((0, login_1.signIn)({ shouldOpenBrowser: false })).rejects.toMatchObject({
|
|
291
|
+
code: 'SSO_SIGN_IN_CODE_MISMATCH',
|
|
292
|
+
});
|
|
270
293
|
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
271
294
|
});
|
|
272
295
|
it('should ask for a password when the email domain has no SSO', async () => {
|
|
@@ -274,8 +297,7 @@ describe('signIn with SSO', () => {
|
|
|
274
297
|
.mockResolvedValueOnce(new Response('', { status: 200 }))
|
|
275
298
|
.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
276
299
|
promptSpy.mockResolvedValue({ password: 'secret' });
|
|
277
|
-
const context = await (0, login_1.signIn)({
|
|
278
|
-
expect(mockAuthenticateUser).toHaveBeenCalled();
|
|
300
|
+
const context = await (0, login_1.signIn)({ shouldOpenBrowser: false });
|
|
279
301
|
expect(context.apiUserToken).toBe('vibe-access');
|
|
280
302
|
expect(config_1.storeConfig).toHaveBeenCalledWith({ ...context, signInMethod: 'password' });
|
|
281
303
|
});
|
|
@@ -284,9 +306,9 @@ describe('signIn with SSO', () => {
|
|
|
284
306
|
.mockResolvedValueOnce(jsonResponse(200, { identityProvider: '', url: 'legacy' }))
|
|
285
307
|
.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
286
308
|
promptSpy.mockResolvedValue({ password: 'secret' });
|
|
287
|
-
const context = await (0, login_1.signIn)({
|
|
309
|
+
const context = await (0, login_1.signIn)({ shouldOpenBrowser: false });
|
|
288
310
|
expect(context.apiUserToken).toBe('vibe-access');
|
|
289
|
-
expect(
|
|
311
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('The CLI does not support your SSO provider yet.'));
|
|
290
312
|
});
|
|
291
313
|
it('should refresh a stored SSO token through Cognito instead of the VibeIQ refresh endpoint', async () => {
|
|
292
314
|
config_1.getConfig.mockResolvedValue({
|
|
@@ -306,6 +328,17 @@ describe('signIn with SSO', () => {
|
|
|
306
328
|
expect(new URLSearchParams(tokenRequest.body).get('refresh_token')).toBe('cognito-refresh');
|
|
307
329
|
expect(context.apiUserToken).toBe('refreshed-access');
|
|
308
330
|
});
|
|
331
|
+
it('should name the misconfiguration when a stored SSO token points at an unknown environment', async () => {
|
|
332
|
+
config_1.getConfig.mockResolvedValue({
|
|
333
|
+
apiUserToken: 'expired-access',
|
|
334
|
+
apiRefreshToken: 'cognito-refresh',
|
|
335
|
+
apiGateway: 'http://localhost:3000/api',
|
|
336
|
+
orgSlug: 'adam-zone-1',
|
|
337
|
+
signInMethod: 'sso',
|
|
338
|
+
});
|
|
339
|
+
sdk_1.getCurrentUser.mockRejectedValueOnce(new Error('Failed to fetch current user. Unauthorized'));
|
|
340
|
+
await expect((0, login_1.authUser)()).rejects.toMatchObject({ code: 'ENVIRONMENT_NOT_CONFIGURED' });
|
|
341
|
+
});
|
|
309
342
|
});
|
|
310
343
|
describe('getVersionFromPackageJson', () => {
|
|
311
344
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatErrorForTerminal = exports.SignInError = void 0;
|
|
4
|
+
class SignInError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
details;
|
|
7
|
+
constructor(code, message, details = {}) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.details = details;
|
|
11
|
+
this.name = 'SignInError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.SignInError = SignInError;
|
|
15
|
+
function formatErrorForTerminal(error) {
|
|
16
|
+
if (!(error instanceof SignInError)) {
|
|
17
|
+
return error.message;
|
|
18
|
+
}
|
|
19
|
+
const details = Object.entries(error.details)
|
|
20
|
+
.filter(([, value]) => value !== undefined)
|
|
21
|
+
.map(([name, value]) => `${name}: ${value}`);
|
|
22
|
+
return details.length ? `${error.message} (${details.join(', ')})` : error.message;
|
|
23
|
+
}
|
|
24
|
+
exports.formatErrorForTerminal = formatErrorForTerminal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sign_in_error_1 = require("./sign-in-error");
|
|
4
|
+
describe('formatErrorForTerminal', () => {
|
|
5
|
+
it('should follow a sign-in error message with its details', () => {
|
|
6
|
+
const error = new sign_in_error_1.SignInError('SSO_TOKEN_REQUEST_FAILED', 'Cognito rejected the token request.', {
|
|
7
|
+
status: 400,
|
|
8
|
+
oauthError: 'invalid_grant',
|
|
9
|
+
});
|
|
10
|
+
expect((0, sign_in_error_1.formatErrorForTerminal)(error)).toBe('Cognito rejected the token request. (status: 400, oauthError: invalid_grant)');
|
|
11
|
+
});
|
|
12
|
+
it('should leave out details that are not set', () => {
|
|
13
|
+
const error = new sign_in_error_1.SignInError('SSO_TOKEN_REQUEST_FAILED', 'Cognito rejected the token request.', {
|
|
14
|
+
status: 400,
|
|
15
|
+
oauthError: undefined,
|
|
16
|
+
});
|
|
17
|
+
expect((0, sign_in_error_1.formatErrorForTerminal)(error)).toBe('Cognito rejected the token request. (status: 400)');
|
|
18
|
+
});
|
|
19
|
+
it('should show only the message for other errors', () => {
|
|
20
|
+
expect((0, sign_in_error_1.formatErrorForTerminal)(new Error('Something else.'))).toBe('Something else.');
|
|
21
|
+
});
|
|
22
|
+
});
|
package/dist/auth/sso.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface SsoTokens {
|
|
|
9
9
|
accessToken: string;
|
|
10
10
|
refreshToken: string;
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
12
|
+
export interface SignInAttempt {
|
|
13
13
|
verifier: string;
|
|
14
14
|
challenge: string;
|
|
15
15
|
state: string;
|
|
@@ -23,14 +23,16 @@ export type SsoDomainCheck = {
|
|
|
23
23
|
kind: 'none';
|
|
24
24
|
};
|
|
25
25
|
export declare function fetchSsoDomainCheck(email: string, apiGateway: string): Promise<SsoDomainCheck>;
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function buildAuthorizeUrl(client: SsoClient, identityProvider: string, redirectUri: string,
|
|
26
|
+
export declare function createSignInAttempt(): SignInAttempt;
|
|
27
|
+
export declare function buildAuthorizeUrl(client: SsoClient, identityProvider: string, redirectUri: string, signInAttempt: SignInAttempt): string;
|
|
28
28
|
export declare function parsePastedSignInCode(pasted: string, expectedState: string): string;
|
|
29
29
|
export interface LoopbackListener {
|
|
30
30
|
code: Promise<string>;
|
|
31
|
+
stop: () => void;
|
|
31
32
|
}
|
|
32
33
|
export declare function listenForLoopbackCode(expectedState: string): Promise<LoopbackListener>;
|
|
33
34
|
export declare function canOpenBrowser(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
|
|
34
35
|
export declare function openBrowser(url: string): Promise<void>;
|
|
36
|
+
export declare function buildOpenBrowserCommand(url: string, platform: NodeJS.Platform): [string, string[]];
|
|
35
37
|
export declare function exchangeCodeForTokens(client: SsoClient, code: string, redirectUri: string, verifier: string): Promise<SsoTokens>;
|
|
36
38
|
export declare function refreshSsoAccessToken(client: SsoClient, refreshToken: string): Promise<string>;
|