@contrail/cli 3.6.0-alpha-8-alpha.694fd70 → 3.6.0-alpha-8-alpha.252e3f3
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 +50 -1
- package/dist/api/feature-flags.d.ts +3 -0
- package/dist/api/feature-flags.js +29 -0
- package/dist/api/users.d.ts +1 -0
- package/dist/api/users.js +10 -1
- package/dist/auth/login.js +38 -20
- package/dist/auth/login.spec.js +124 -0
- package/dist/basecommand.js +3 -3
- package/dist/commands/entities/create.d.ts +1 -0
- package/dist/commands/entities/create.js +8 -4
- package/dist/commands/entities/create.spec.js +4 -0
- package/dist/commands/entities/delete.d.ts +1 -0
- package/dist/commands/entities/delete.js +5 -2
- package/dist/commands/entities/get.d.ts +1 -0
- package/dist/commands/entities/get.js +4 -1
- package/dist/commands/entities/update.d.ts +1 -0
- package/dist/commands/entities/update.js +4 -1
- package/dist/commands/feature-flags/export.d.ts +19 -0
- package/dist/commands/feature-flags/export.js +66 -0
- package/dist/commands/feature-flags/export.spec.d.ts +1 -0
- package/dist/commands/feature-flags/export.spec.js +109 -0
- package/dist/commands/feature-flags/import.d.ts +42 -0
- package/dist/commands/feature-flags/import.js +191 -0
- package/dist/commands/feature-flags/import.spec.d.ts +1 -0
- package/dist/commands/feature-flags/import.spec.js +194 -0
- package/dist/commands/instance/export.d.ts +9 -0
- package/dist/commands/instance/export.js +18 -3
- package/dist/commands/instance/export.spec.d.ts +1 -0
- package/dist/commands/instance/export.spec.js +32 -0
- package/dist/commands/instance/import.d.ts +3 -0
- package/dist/commands/instance/import.js +5 -0
- package/dist/commands/instance/import.spec.js +4 -0
- package/dist/common.d.ts +1 -0
- package/dist/common.js +6 -1
- package/dist/helpers/config/config.d.ts +2 -0
- package/dist/helpers/config/config.js +6 -1
- package/dist/helpers/entities/assortment-items.d.ts +4 -2
- package/dist/helpers/entities/assortment-items.js +4 -1
- package/dist/helpers/file-helpers.js +2 -2
- package/node_modules/@contrail/entity-compare/package.json +3 -6
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +8 -0
- package/node_modules/@contrail/loader/lib/constants.js +9 -1
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +4 -0
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +57 -0
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +492 -34
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +2 -52
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +0 -85
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +1 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +1 -1
- package/oclif.manifest.json +111 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
|
|
|
17
17
|
$ contrail COMMAND
|
|
18
18
|
running command...
|
|
19
19
|
$ contrail (--version)
|
|
20
|
-
@contrail/cli/3.6.0-alpha-8-alpha.
|
|
20
|
+
@contrail/cli/3.6.0-alpha-8-alpha.252e3f3 linux-x64 node-v24.22.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -55,6 +55,8 @@ To get instructions on how to set up autocomplete for your shell, run `contrail
|
|
|
55
55
|
* [`contrail entities delete ENTITYNAME [IDS]`](#contrail-entities-delete-entityname-ids)
|
|
56
56
|
* [`contrail entities get TYPEPATH [IDS]`](#contrail-entities-get-typepath-ids)
|
|
57
57
|
* [`contrail entities update ENTITYNAME [IDS]`](#contrail-entities-update-entityname-ids)
|
|
58
|
+
* [`contrail feature-flags export`](#contrail-feature-flags-export)
|
|
59
|
+
* [`contrail feature-flags import`](#contrail-feature-flags-import)
|
|
58
60
|
* [`contrail file upload FILELOCATION CONTENTTYPE`](#contrail-file-upload-filelocation-contenttype)
|
|
59
61
|
* [`contrail groups export`](#contrail-groups-export)
|
|
60
62
|
* [`contrail groups import GROUPSFILE`](#contrail-groups-import-groupsfile)
|
|
@@ -717,6 +719,53 @@ EXAMPLES
|
|
|
717
719
|
$ contrail entities update color 123 -- description= notes='""' # Unset description, set notes to empty string
|
|
718
720
|
```
|
|
719
721
|
|
|
722
|
+
## `contrail feature-flags export`
|
|
723
|
+
|
|
724
|
+
Export the enabled feature flags for your Org
|
|
725
|
+
|
|
726
|
+
```
|
|
727
|
+
USAGE
|
|
728
|
+
$ contrail feature-flags export [-l error|warn|info|debug] [-e true|false] [-d <value>] [-f]
|
|
729
|
+
|
|
730
|
+
FLAGS
|
|
731
|
+
-d, --outDir=<value> [default: .] The directory to which to export the feature flags. Defaults to the
|
|
732
|
+
current directory
|
|
733
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
734
|
+
<options: true|false>
|
|
735
|
+
-f, --overwrite Replaces any existing export files in outDir
|
|
736
|
+
-l, --logLevel=<option> The Log Level
|
|
737
|
+
<options: error|warn|info|debug>
|
|
738
|
+
|
|
739
|
+
DESCRIPTION
|
|
740
|
+
Export the enabled feature flags for your Org
|
|
741
|
+
|
|
742
|
+
EXAMPLES
|
|
743
|
+
$ contrail feature-flags export
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
## `contrail feature-flags import`
|
|
747
|
+
|
|
748
|
+
Upload an extracted set of feature flags
|
|
749
|
+
|
|
750
|
+
```
|
|
751
|
+
USAGE
|
|
752
|
+
$ contrail feature-flags import [-l error|warn|info|debug] [-e true|false] [-d <value>]
|
|
753
|
+
|
|
754
|
+
FLAGS
|
|
755
|
+
-d, --dir=<value> [default: .] The directory from which to import the feature flags. Defaults to the
|
|
756
|
+
current directory. The feature flags will be loaded from $dir/feature-flags.yml
|
|
757
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
758
|
+
<options: true|false>
|
|
759
|
+
-l, --logLevel=<option> The Log Level
|
|
760
|
+
<options: error|warn|info|debug>
|
|
761
|
+
|
|
762
|
+
DESCRIPTION
|
|
763
|
+
Upload an extracted set of feature flags
|
|
764
|
+
|
|
765
|
+
EXAMPLES
|
|
766
|
+
$ contrail feature-flags import
|
|
767
|
+
```
|
|
768
|
+
|
|
720
769
|
## `contrail file upload FILELOCATION CONTENTTYPE`
|
|
721
770
|
|
|
722
771
|
Uploads a file to the VibeIQ platform
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteFeatureFlag = exports.createFeatureFlag = exports.getFeatureFlags = void 0;
|
|
4
|
+
const sdk_1 = require("@contrail/sdk");
|
|
5
|
+
// a feature flag record exists only for features that are turned ON for the org,
|
|
6
|
+
// and carries no configuration beyond its featureName
|
|
7
|
+
async function getFeatureFlags(options) {
|
|
8
|
+
return new sdk_1.Entities().get({
|
|
9
|
+
entityName: 'feature-flag',
|
|
10
|
+
...options,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
exports.getFeatureFlags = getFeatureFlags;
|
|
14
|
+
// the API treats create as an upsert on featureName, so creating an already
|
|
15
|
+
// enabled flag returns the existing record instead of failing
|
|
16
|
+
async function createFeatureFlag(featureName) {
|
|
17
|
+
return new sdk_1.Entities().create({
|
|
18
|
+
entityName: 'feature-flag',
|
|
19
|
+
object: { featureName },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.createFeatureFlag = createFeatureFlag;
|
|
23
|
+
async function deleteFeatureFlag(id) {
|
|
24
|
+
return new sdk_1.Entities().delete({
|
|
25
|
+
entityName: 'feature-flag',
|
|
26
|
+
id,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.deleteFeatureFlag = deleteFeatureFlag;
|
package/dist/api/users.d.ts
CHANGED
package/dist/api/users.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getGroups = exports.getUserOrgs = void 0;
|
|
3
|
+
exports.getCurrentUserWithPlatformRoles = exports.getGroups = exports.getUserOrgs = void 0;
|
|
4
4
|
const sdk_1 = require("@contrail/sdk");
|
|
5
5
|
async function getUserOrgs(options) {
|
|
6
6
|
return new sdk_1.Entities().get({
|
|
@@ -16,3 +16,12 @@ async function getGroups(options) {
|
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
exports.getGroups = getGroups;
|
|
19
|
+
// GET /users/current only populates platformRoles when it is asked for as a relation
|
|
20
|
+
async function getCurrentUserWithPlatformRoles() {
|
|
21
|
+
return new sdk_1.Entities().get({
|
|
22
|
+
entityName: 'user',
|
|
23
|
+
id: 'current',
|
|
24
|
+
relations: ['platformRoles'],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.getCurrentUserWithPlatformRoles = getCurrentUserWithPlatformRoles;
|
package/dist/auth/login.js
CHANGED
|
@@ -3,17 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
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
9
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
10
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
12
11
|
const common_1 = require("../common");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const DEFAULT_API_GATEWAY = config_1.ENVIRONMENTS.prod;
|
|
13
|
+
const COGNITO_CONFIGS = {
|
|
14
|
+
dev: { userPoolId: 'us-east-1_e2cA0nJWu', clientId: '209s9c62o165cqab0fu5ihjtu9' },
|
|
15
|
+
prod: { userPoolId: 'us-east-1_qIaNZdUfm', clientId: '7knkt34gfacbgd0ghnuspefdfg' },
|
|
17
16
|
};
|
|
18
17
|
async function authUser() {
|
|
19
18
|
logger_1.default.debug('authorizing user...');
|
|
@@ -63,7 +62,7 @@ exports.authUser = authUser;
|
|
|
63
62
|
async function getOrgSlug(config) {
|
|
64
63
|
const orgSlug = config?.orgSlug || process.env.CONTRAIL_CLI_ORG_SLUG;
|
|
65
64
|
if (!orgSlug) {
|
|
66
|
-
const answers = await
|
|
65
|
+
const answers = await (0, common_1.promptOnStderr)([
|
|
67
66
|
{
|
|
68
67
|
type: 'input',
|
|
69
68
|
name: 'orgSlug',
|
|
@@ -76,7 +75,7 @@ async function getOrgSlug(config) {
|
|
|
76
75
|
return orgSlug;
|
|
77
76
|
}
|
|
78
77
|
async function authenticateWithApiKey(config, apiKey, orgSlug) {
|
|
79
|
-
const apiGateway = config
|
|
78
|
+
const apiGateway = getApiGateway(config);
|
|
80
79
|
sdk_1.Auth.config = {
|
|
81
80
|
apiUserToken: apiKey,
|
|
82
81
|
apiRefreshToken: undefined,
|
|
@@ -89,6 +88,12 @@ async function authenticateWithApiKey(config, apiKey, orgSlug) {
|
|
|
89
88
|
return Object.assign({}, sdk_1.Auth.config);
|
|
90
89
|
}
|
|
91
90
|
async function authenticateWithUsernamePassword(config) {
|
|
91
|
+
const apiGateway = getApiGateway(config);
|
|
92
|
+
const environment = (0, config_1.findEnvironmentName)(apiGateway);
|
|
93
|
+
const cognitoConfig = environment ? COGNITO_CONFIGS[environment] : undefined;
|
|
94
|
+
if (!environment || !cognitoConfig) {
|
|
95
|
+
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.`);
|
|
96
|
+
}
|
|
92
97
|
const questions = [];
|
|
93
98
|
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
94
99
|
questions.push({
|
|
@@ -106,19 +111,20 @@ async function authenticateWithUsernamePassword(config) {
|
|
|
106
111
|
message: 'Password',
|
|
107
112
|
});
|
|
108
113
|
}
|
|
109
|
-
const answers = await
|
|
114
|
+
const answers = await (0, common_1.promptOnStderr)(questions);
|
|
110
115
|
const params = {
|
|
111
116
|
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
112
117
|
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
113
118
|
orgSlug: await getOrgSlug(config),
|
|
114
|
-
|
|
119
|
+
apiGateway,
|
|
120
|
+
environment,
|
|
115
121
|
};
|
|
116
122
|
if (!params.email || !params.password) {
|
|
117
123
|
throw new Error('Email and Password required');
|
|
118
124
|
}
|
|
119
125
|
const poolData = {
|
|
120
|
-
UserPoolId:
|
|
121
|
-
ClientId:
|
|
126
|
+
UserPoolId: cognitoConfig.userPoolId,
|
|
127
|
+
ClientId: cognitoConfig.clientId,
|
|
122
128
|
};
|
|
123
129
|
const userPool = new amazon_cognito_identity_js_1.CognitoUserPool(poolData);
|
|
124
130
|
const authData = {
|
|
@@ -134,19 +140,26 @@ async function authenticateWithUsernamePassword(config) {
|
|
|
134
140
|
return new Promise((resolve, reject) => {
|
|
135
141
|
cognitoUser.authenticateUser(authDetails, {
|
|
136
142
|
onSuccess: async (result) => {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
try {
|
|
144
|
+
resolve(await setAuthContext(result, params));
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
reject(e);
|
|
148
|
+
}
|
|
140
149
|
},
|
|
141
150
|
onFailure: (err) => {
|
|
151
|
+
if (err?.code === 'ResourceNotFoundException') {
|
|
152
|
+
reject(new Error(`This version of the CLI has outdated ${environment} sign-in settings (${err.message}). Update the CLI: npm i -g @contrail/cli`));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
142
155
|
reject(err);
|
|
143
156
|
},
|
|
144
157
|
});
|
|
145
158
|
});
|
|
146
159
|
}
|
|
147
160
|
async function setAuthContext(user, params) {
|
|
148
|
-
const apiGateway = params
|
|
149
|
-
const { vibeAccessToken, vibeRefreshToken } = await getVibeAccessTokenFromCognitoAccessToken(user.idToken.jwtToken, apiGateway);
|
|
161
|
+
const apiGateway = params.apiGateway;
|
|
162
|
+
const { vibeAccessToken, vibeRefreshToken } = await getVibeAccessTokenFromCognitoAccessToken(user.idToken.jwtToken, apiGateway, params.environment);
|
|
150
163
|
sdk_1.Auth.config = {
|
|
151
164
|
apiUserToken: vibeAccessToken,
|
|
152
165
|
apiRefreshToken: vibeRefreshToken,
|
|
@@ -191,7 +204,10 @@ async function refreshCurrentUserOrg() {
|
|
|
191
204
|
function isExpiredTokenError(e) {
|
|
192
205
|
return e?.message?.includes('token is expired');
|
|
193
206
|
}
|
|
194
|
-
|
|
207
|
+
function getApiGateway(config) {
|
|
208
|
+
return config?.apiGateway ?? DEFAULT_API_GATEWAY;
|
|
209
|
+
}
|
|
210
|
+
async function getVibeAccessTokenFromCognitoAccessToken(cognitoAccessToken, apiGateway, environment) {
|
|
195
211
|
const url = `${apiGateway}/auth/cognito/`;
|
|
196
212
|
const response = await fetch(url, {
|
|
197
213
|
method: 'POST',
|
|
@@ -201,9 +217,11 @@ async function getVibeAccessTokenFromCognitoAccessToken(cognitoAccessToken, apiG
|
|
|
201
217
|
},
|
|
202
218
|
body: JSON.stringify({ accessToken: cognitoAccessToken }),
|
|
203
219
|
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
220
|
+
if (!response.ok) {
|
|
221
|
+
throw new Error(`${environment} rejected the sign-in (${response.status}).`);
|
|
222
|
+
}
|
|
223
|
+
const data = await response.json();
|
|
224
|
+
return { vibeAccessToken: data.accessToken, vibeRefreshToken: data.refreshToken };
|
|
207
225
|
}
|
|
208
226
|
async function requestRefreshedAccessToken(vibeRefreshToken, apiGateway) {
|
|
209
227
|
const url = `${apiGateway}/auth/jwt_refresh/`;
|
package/dist/auth/login.spec.js
CHANGED
|
@@ -1,6 +1,130 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const amazon_cognito_identity_js_1 = require("amazon-cognito-identity-js");
|
|
4
|
+
const sdk_1 = require("@contrail/sdk");
|
|
5
|
+
const config_1 = require("../helpers/config/config");
|
|
3
6
|
const login_1 = require("./login");
|
|
7
|
+
const mockAuthenticateUser = jest.fn();
|
|
8
|
+
jest.mock('amazon-cognito-identity-js', () => ({
|
|
9
|
+
CognitoUserPool: jest.fn(),
|
|
10
|
+
AuthenticationDetails: jest.fn(),
|
|
11
|
+
CognitoUser: jest.fn().mockImplementation(() => ({
|
|
12
|
+
authenticateUser: (details, callbacks) => mockAuthenticateUser(details, callbacks),
|
|
13
|
+
})),
|
|
14
|
+
}));
|
|
15
|
+
jest.mock('@contrail/sdk', () => ({
|
|
16
|
+
Auth: { config: {} },
|
|
17
|
+
getCurrentUser: jest.fn(),
|
|
18
|
+
setConfig: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
jest.mock('../helpers/config/config', () => ({
|
|
21
|
+
...jest.requireActual('../helpers/config/config'),
|
|
22
|
+
getConfig: jest.fn(),
|
|
23
|
+
storeConfig: jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
jest.mock('../logger', () => ({
|
|
26
|
+
__esModule: true,
|
|
27
|
+
default: { debug: jest.fn(), info: jest.fn() },
|
|
28
|
+
}));
|
|
29
|
+
const DEV_GATEWAY = 'https://api.dev.vibeiq.com/dev/api';
|
|
30
|
+
function restoreEnv(name, value) {
|
|
31
|
+
if (value === undefined) {
|
|
32
|
+
delete process.env[name];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
process.env[name] = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function jsonResponse(status, body = {}) {
|
|
39
|
+
return new Response(JSON.stringify(body), { status });
|
|
40
|
+
}
|
|
41
|
+
describe('authUser with email and password', () => {
|
|
42
|
+
const originalFetch = global.fetch;
|
|
43
|
+
const originalEmail = process.env.CONTRAIL_CLI_EMAIL;
|
|
44
|
+
const originalPassword = process.env.CONTRAIL_CLI_PASSWORD;
|
|
45
|
+
let fetchMock;
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
jest.clearAllMocks();
|
|
48
|
+
process.env.CONTRAIL_CLI_EMAIL = 'dev@vibeiq.com';
|
|
49
|
+
process.env.CONTRAIL_CLI_PASSWORD = 'secret';
|
|
50
|
+
config_1.getConfig.mockResolvedValue({ apiGateway: DEV_GATEWAY, orgSlug: 'adam-zone-1' });
|
|
51
|
+
sdk_1.getCurrentUser.mockResolvedValue({ id: 'user-1' });
|
|
52
|
+
mockAuthenticateUser.mockImplementation((_details, callbacks) => callbacks.onSuccess({ idToken: { jwtToken: 'cognito-id-token' } }));
|
|
53
|
+
fetchMock = jest.fn();
|
|
54
|
+
global.fetch = fetchMock;
|
|
55
|
+
});
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
global.fetch = originalFetch;
|
|
58
|
+
restoreEnv('CONTRAIL_CLI_EMAIL', originalEmail);
|
|
59
|
+
restoreEnv('CONTRAIL_CLI_PASSWORD', originalPassword);
|
|
60
|
+
});
|
|
61
|
+
it('should sign in through the dev pool when the config points at dev', async () => {
|
|
62
|
+
fetchMock.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
63
|
+
const context = await (0, login_1.authUser)();
|
|
64
|
+
expect(amazon_cognito_identity_js_1.CognitoUserPool).toHaveBeenCalledWith({
|
|
65
|
+
UserPoolId: 'us-east-1_e2cA0nJWu',
|
|
66
|
+
ClientId: '209s9c62o165cqab0fu5ihjtu9',
|
|
67
|
+
});
|
|
68
|
+
expect(context).toEqual({
|
|
69
|
+
apiUserToken: 'vibe-access',
|
|
70
|
+
apiRefreshToken: 'vibe-refresh',
|
|
71
|
+
apiGateway: DEV_GATEWAY,
|
|
72
|
+
orgSlug: 'adam-zone-1',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it('should sign in through the prod pool when the config points at prod', async () => {
|
|
76
|
+
config_1.getConfig.mockResolvedValue({
|
|
77
|
+
apiGateway: 'https://api.vibeiq.com/prod/api',
|
|
78
|
+
orgSlug: 'adam-zone-1',
|
|
79
|
+
});
|
|
80
|
+
fetchMock.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
81
|
+
await (0, login_1.authUser)();
|
|
82
|
+
expect(amazon_cognito_identity_js_1.CognitoUserPool).toHaveBeenCalledWith({
|
|
83
|
+
UserPoolId: 'us-east-1_qIaNZdUfm',
|
|
84
|
+
ClientId: '7knkt34gfacbgd0ghnuspefdfg',
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('should match the dev pool despite a trailing slash or different case in the gateway', async () => {
|
|
88
|
+
config_1.getConfig.mockResolvedValue({
|
|
89
|
+
apiGateway: 'https://API.dev.vibeiq.com/dev/api/',
|
|
90
|
+
orgSlug: 'adam-zone-1',
|
|
91
|
+
});
|
|
92
|
+
fetchMock.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
93
|
+
await (0, login_1.authUser)();
|
|
94
|
+
expect(amazon_cognito_identity_js_1.CognitoUserPool).toHaveBeenCalledWith({
|
|
95
|
+
UserPoolId: 'us-east-1_e2cA0nJWu',
|
|
96
|
+
ClientId: '209s9c62o165cqab0fu5ihjtu9',
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
it('should explain an unknown gateway even when it has no scheme', async () => {
|
|
100
|
+
config_1.getConfig.mockResolvedValue({
|
|
101
|
+
apiGateway: 'api.dev.vibeiq.com/dev/api',
|
|
102
|
+
orgSlug: 'adam-zone-1',
|
|
103
|
+
});
|
|
104
|
+
await expect((0, login_1.authUser)()).rejects.toThrow('No Cognito user pool is known for api.dev.vibeiq.com/dev/api.');
|
|
105
|
+
});
|
|
106
|
+
it('should fail without saving tokens when no pool is known for the environment', async () => {
|
|
107
|
+
config_1.getConfig.mockResolvedValue({
|
|
108
|
+
apiGateway: 'http://localhost:3000/api',
|
|
109
|
+
orgSlug: 'adam-zone-1',
|
|
110
|
+
});
|
|
111
|
+
await expect((0, login_1.authUser)()).rejects.toThrow('No Cognito user pool is known for http://localhost:3000/api.');
|
|
112
|
+
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
113
|
+
});
|
|
114
|
+
it('should tell the user to update the CLI when its Cognito client or pool no longer exists', async () => {
|
|
115
|
+
mockAuthenticateUser.mockImplementation((_details, callbacks) => callbacks.onFailure({
|
|
116
|
+
code: 'ResourceNotFoundException',
|
|
117
|
+
message: 'User pool client 209s9c62o165cqab0fu5ihjtu9 does not exist.',
|
|
118
|
+
}));
|
|
119
|
+
await expect((0, login_1.authUser)()).rejects.toThrow('This version of the CLI has outdated dev sign-in settings (User pool client 209s9c62o165cqab0fu5ihjtu9 does not exist.). Update the CLI: npm i -g @contrail/cli');
|
|
120
|
+
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
121
|
+
});
|
|
122
|
+
it('should fail without saving tokens when the environment rejects the sign-in', async () => {
|
|
123
|
+
fetchMock.mockResolvedValueOnce(jsonResponse(401, { message: 'Unauthorized' }));
|
|
124
|
+
await expect((0, login_1.authUser)()).rejects.toThrow('dev rejected the sign-in (401).');
|
|
125
|
+
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
4
128
|
describe('getVersionFromPackageJson', () => {
|
|
5
129
|
it('should return the version value from package.json', () => {
|
|
6
130
|
const version = (0, login_1.getVersionFromPackageJson)();
|
package/dist/basecommand.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const common_1 = require("./common");
|
|
6
7
|
const logger_1 = tslib_1.__importDefault(require("./logger"));
|
|
7
|
-
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
8
8
|
const config_1 = require("./helpers/config/config");
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
10
10
|
const login_1 = require("./auth/login");
|
|
@@ -60,7 +60,7 @@ class BaseCommand extends core_1.Command {
|
|
|
60
60
|
const data = (0, lodash_1.pick)(config, ['orgSlug', 'apiGateway']);
|
|
61
61
|
let env = '';
|
|
62
62
|
if (data.apiGateway) {
|
|
63
|
-
env =
|
|
63
|
+
env = (0, config_1.findEnvironmentName)(data.apiGateway);
|
|
64
64
|
}
|
|
65
65
|
data.environment = env;
|
|
66
66
|
delete data.apiGateway;
|
|
@@ -73,7 +73,7 @@ class BaseCommand extends core_1.Command {
|
|
|
73
73
|
choices: ['yes', 'no'],
|
|
74
74
|
default: 'no',
|
|
75
75
|
});
|
|
76
|
-
const { confirm } = await
|
|
76
|
+
const { confirm } = await (0, common_1.promptOnStderr)(questions);
|
|
77
77
|
if (confirm === 'no') {
|
|
78
78
|
logger_1.default.info('Please use `contrail config use` command to choose the configuration or `contrail config set --environment=prod` to set different environment.');
|
|
79
79
|
this.exit(1);
|
|
@@ -23,6 +23,7 @@ export default class CreateEntity extends BaseCommand {
|
|
|
23
23
|
path: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
24
24
|
};
|
|
25
25
|
static strict: boolean;
|
|
26
|
+
init(): Promise<void>;
|
|
26
27
|
run(): Promise<void>;
|
|
27
28
|
}
|
|
28
29
|
export type CreateSummary = {
|
|
@@ -218,8 +218,11 @@ class CreateEntity extends basecommand_1.BaseCommand {
|
|
|
218
218
|
}),
|
|
219
219
|
};
|
|
220
220
|
static strict = false;
|
|
221
|
-
async
|
|
221
|
+
async init() {
|
|
222
222
|
(0, common_1.routeConsoleLogToStderr)();
|
|
223
|
+
await super.init();
|
|
224
|
+
}
|
|
225
|
+
async run() {
|
|
223
226
|
await (0, login_1.authUser)();
|
|
224
227
|
const { flags, argv, args } = await this.parse(CreateEntity);
|
|
225
228
|
const { count, dryRun: isDryRun, inputFile: inputFilename, outputFile: outputFilename, generateValues: shouldGenerateMissingValues, readableIds: shouldUseReadableIds, skipHydrateRelationships, suffix, apiVersion, } = flags;
|
|
@@ -371,8 +374,6 @@ function createEntityWithPopulatedValues(type, typeReferencesCache, objectRefere
|
|
|
371
374
|
// Handle property specifications
|
|
372
375
|
for (const [propertySlug, specifiedValue] of propertySpecificationBySlug.entries()) {
|
|
373
376
|
const correspondingProperty = type.typeProperties.find((prop) => getPropertySlug(prop) === propertySlug);
|
|
374
|
-
// slug= means unset; on create there is nothing to unset, so skip it.
|
|
375
|
-
// slug='""' is the empty string and is written like any other value.
|
|
376
377
|
if (specifiedValue === undefined) {
|
|
377
378
|
continue;
|
|
378
379
|
}
|
|
@@ -523,6 +524,9 @@ function generateRandomDateString() {
|
|
|
523
524
|
return new Date().toISOString();
|
|
524
525
|
}
|
|
525
526
|
function castValueToPropertyType(value, propertyType) {
|
|
527
|
+
if (Array.isArray(value) && propertyType !== types_1.PropertyType.MultiSelect) {
|
|
528
|
+
return value.map((element) => castValueToPropertyType(element, propertyType));
|
|
529
|
+
}
|
|
526
530
|
switch (propertyType) {
|
|
527
531
|
case types_1.PropertyType.Boolean:
|
|
528
532
|
return value.toString().toLowerCase() === 'true';
|
|
@@ -555,7 +559,7 @@ async function createEntity(entityName, entity, routing = {}) {
|
|
|
555
559
|
const skipHydrateRelationships = SHOULD_SKIP_HYDRATE_RELATIONSHIPS;
|
|
556
560
|
const { suffix, apiVersion } = routing;
|
|
557
561
|
if (entityName === 'assortment-item' && !suffix)
|
|
558
|
-
return (0, entities_1.createAssortmentItem)(entity, { skipHydrateRelationships }); // special case
|
|
562
|
+
return (0, entities_1.createAssortmentItem)(entity, { skipHydrateRelationships, apiVersion }); // special case
|
|
559
563
|
const response = await client.create({
|
|
560
564
|
entityName,
|
|
561
565
|
object: entity,
|
|
@@ -532,6 +532,10 @@ describe('castValueToPropertyType array coercion', () => {
|
|
|
532
532
|
expect(consoleError).toHaveBeenCalledWith(expect.stringContaining('slug=option slug=family'));
|
|
533
533
|
consoleError.mockRestore();
|
|
534
534
|
});
|
|
535
|
+
it('should cast each element of a repeated-key array on scalar property types', () => {
|
|
536
|
+
expect((0, create_1.castValueToPropertyType)(['1', '2'], types_1.PropertyType.Number)).toEqual([1, 2]);
|
|
537
|
+
expect((0, create_1.castValueToPropertyType)(['true', 'false'], types_1.PropertyType.Boolean)).toEqual([true, false]);
|
|
538
|
+
});
|
|
535
539
|
it('should keep commas literal on string properties without warning', () => {
|
|
536
540
|
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
537
541
|
expect((0, create_1.castValueToPropertyType)('my,name', types_1.PropertyType.String)).toBe('my,name');
|
|
@@ -51,8 +51,11 @@ class DeleteEntity extends basecommand_1.BaseCommand {
|
|
|
51
51
|
}),
|
|
52
52
|
};
|
|
53
53
|
static strict = false;
|
|
54
|
-
async
|
|
54
|
+
async init() {
|
|
55
55
|
(0, common_1.routeConsoleLogToStderr)();
|
|
56
|
+
await super.init();
|
|
57
|
+
}
|
|
58
|
+
async run() {
|
|
56
59
|
await (0, login_1.authUser)();
|
|
57
60
|
const { args, flags, argv } = await this.parse(DeleteEntity);
|
|
58
61
|
const { entityName } = args;
|
|
@@ -114,7 +117,7 @@ async function deleteEntityByIds(entityName, ids, routing = {}) {
|
|
|
114
117
|
}
|
|
115
118
|
deletedIds.push(id);
|
|
116
119
|
}, (error) => {
|
|
117
|
-
if (error.message
|
|
120
|
+
if (error.message?.includes('not found')) {
|
|
118
121
|
notFoundIds.push(id);
|
|
119
122
|
}
|
|
120
123
|
else {
|
|
@@ -83,8 +83,11 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
83
83
|
}),
|
|
84
84
|
};
|
|
85
85
|
static strict = false;
|
|
86
|
-
async
|
|
86
|
+
async init() {
|
|
87
87
|
(0, common_1.routeConsoleLogToStderr)();
|
|
88
|
+
await super.init();
|
|
89
|
+
}
|
|
90
|
+
async run() {
|
|
88
91
|
await (0, login_1.authUser)();
|
|
89
92
|
const { args, flags, argv } = await this.parse(GetEntity);
|
|
90
93
|
const { typePath } = args;
|
|
@@ -16,6 +16,7 @@ export default class UpdateEntity extends BaseCommand {
|
|
|
16
16
|
ids: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
17
17
|
};
|
|
18
18
|
static strict: boolean;
|
|
19
|
+
init(): Promise<void>;
|
|
19
20
|
run(): Promise<void>;
|
|
20
21
|
}
|
|
21
22
|
export type UpdateSummary = {
|
|
@@ -57,8 +57,11 @@ class UpdateEntity extends basecommand_1.BaseCommand {
|
|
|
57
57
|
}),
|
|
58
58
|
};
|
|
59
59
|
static strict = false;
|
|
60
|
-
async
|
|
60
|
+
async init() {
|
|
61
61
|
(0, common_1.routeConsoleLogToStderr)();
|
|
62
|
+
await super.init();
|
|
63
|
+
}
|
|
64
|
+
async run() {
|
|
62
65
|
await (0, login_1.authUser)();
|
|
63
66
|
const { args, argv } = await this.parse(UpdateEntity);
|
|
64
67
|
const { entityName } = args;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseCommand } from '../../basecommand';
|
|
2
|
+
export declare const FEATURE_FLAGS_FILE = "feature-flags.yml";
|
|
3
|
+
export default class ExportFeatureFlags extends BaseCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
outDir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
+
overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
+
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Writes the org's enabled feature flags to $outDir/feature-flags.yml as a list of
|
|
16
|
+
* `- featureName: X` entries. An org with no flags enabled still gets a file (an empty
|
|
17
|
+
* list), so the export stays a faithful snapshot of what is turned on.
|
|
18
|
+
*/
|
|
19
|
+
export declare function exportFeatureFlags(outDir: string, overwrite: boolean): Promise<void>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exportFeatureFlags = exports.FEATURE_FLAGS_FILE = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
8
|
+
const login_1 = require("../../auth/login");
|
|
9
|
+
const core_1 = require("@oclif/core");
|
|
10
|
+
const file_helpers_1 = require("../../helpers/file-helpers");
|
|
11
|
+
const error_helpers_1 = require("../../helpers/error-helpers");
|
|
12
|
+
const feature_flags_1 = require("../../api/feature-flags");
|
|
13
|
+
const basecommand_1 = require("../../basecommand");
|
|
14
|
+
exports.FEATURE_FLAGS_FILE = 'feature-flags.yml';
|
|
15
|
+
class ExportFeatureFlags extends basecommand_1.BaseCommand {
|
|
16
|
+
static description = 'Export the enabled feature flags for your Org';
|
|
17
|
+
static examples = [
|
|
18
|
+
`$ contrail feature-flags export
|
|
19
|
+
`,
|
|
20
|
+
];
|
|
21
|
+
static flags = {
|
|
22
|
+
...basecommand_1.BaseCommand.baseFlags,
|
|
23
|
+
outDir: core_1.Flags.string({
|
|
24
|
+
char: 'd',
|
|
25
|
+
description: 'The directory to which to export the feature flags. Defaults to the current directory',
|
|
26
|
+
required: false,
|
|
27
|
+
default: '.',
|
|
28
|
+
}),
|
|
29
|
+
overwrite: core_1.Flags.boolean({
|
|
30
|
+
char: 'f',
|
|
31
|
+
description: 'Replaces any existing export files in outDir',
|
|
32
|
+
required: false,
|
|
33
|
+
default: false,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
async run() {
|
|
37
|
+
try {
|
|
38
|
+
await (0, login_1.authUser)();
|
|
39
|
+
this.log(`${chalk_1.default.blue.bold('START')} Getting Feature Flags.`);
|
|
40
|
+
this.log(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Exporting`);
|
|
41
|
+
await exportFeatureFlags(this.flags.outDir, this.flags.overwrite);
|
|
42
|
+
this.log(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Exported`);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
this.log(`${chalk_1.default.red.bold('FAIL')} Feature Flags Export Failed. ${(0, error_helpers_1.describeError)(e)}`);
|
|
46
|
+
process.exitCode = 1;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.log(`${chalk_1.default.green.bold('COMPLETE')} Feature Flags Export Complete.`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = ExportFeatureFlags;
|
|
53
|
+
/**
|
|
54
|
+
* Writes the org's enabled feature flags to $outDir/feature-flags.yml as a list of
|
|
55
|
+
* `- featureName: X` entries. An org with no flags enabled still gets a file (an empty
|
|
56
|
+
* list), so the export stays a faithful snapshot of what is turned on.
|
|
57
|
+
*/
|
|
58
|
+
async function exportFeatureFlags(outDir, overwrite) {
|
|
59
|
+
const featureFlags = await (0, feature_flags_1.getFeatureFlags)();
|
|
60
|
+
const featureNames = [
|
|
61
|
+
...new Set((featureFlags ?? []).map((flag) => flag?.featureName).filter(Boolean)),
|
|
62
|
+
].sort();
|
|
63
|
+
fs_1.default.mkdirSync(path.resolve(outDir), { recursive: true });
|
|
64
|
+
await (0, file_helpers_1.saveData)(featureNames.map((featureName) => ({ featureName })), path.join(outDir, exports.FEATURE_FLAGS_FILE), overwrite);
|
|
65
|
+
}
|
|
66
|
+
exports.exportFeatureFlags = exportFeatureFlags;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|