@contrail/cli 3.6.0-alpha-8-alpha.2ab4f80 → 3.6.0-alpha-8-alpha.351376b
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 +80 -58
- 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 +44 -26
- package/dist/auth/login.spec.js +124 -0
- package/dist/basecommand.js +3 -3
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/entities/create.d.ts +1 -13
- package/dist/commands/entities/create.js +31 -98
- package/dist/commands/entities/create.spec.js +3 -32
- package/dist/commands/entities/delete.d.ts +2 -6
- package/dist/commands/entities/delete.js +53 -72
- package/dist/commands/entities/get.d.ts +0 -4
- package/dist/commands/entities/get.js +15 -66
- package/dist/commands/entities/update.d.ts +2 -15
- package/dist/commands/entities/update.js +44 -80
- 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.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.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.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 +0 -3
- package/dist/common.js +1 -18
- 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 +2 -4
- package/dist/helpers/entities/assortment-items.js +1 -4
- package/dist/helpers/file-helpers.js +2 -2
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +0 -8
- package/dist/helpers/propertySpecifications/propertySpecifications.js +9 -21
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +10 -20
- package/dist/logger.js +1 -4
- 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 +137 -99
- package/package.json +4 -1
- package/dist/commands/entities/grammar.spec.js +0 -80
- package/dist/commands/entities/output.spec.js +0 -72
- package/dist/logger.spec.js +0 -12
- /package/dist/commands/{entities/grammar.spec.d.ts → feature-flags/export.spec.d.ts} +0 -0
- /package/dist/commands/{entities/output.spec.d.ts → feature-flags/import.spec.d.ts} +0 -0
- /package/dist/{logger.spec.d.ts → commands/instance/export.spec.d.ts} +0 -0
|
@@ -6,17 +6,14 @@ const core_1 = require("@oclif/core");
|
|
|
6
6
|
const basecommand_1 = require("../../basecommand");
|
|
7
7
|
const sdk_1 = require("@contrail/sdk");
|
|
8
8
|
const login_1 = require("../../auth/login");
|
|
9
|
-
const common_1 = require("../../common");
|
|
10
9
|
const types_1 = require("../../api/types");
|
|
11
10
|
const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
|
|
12
11
|
const batchFetch_1 = require("../../helpers/entities/batchFetch");
|
|
13
12
|
let SHOULD_USE_PAGINATED_FIND = false;
|
|
14
13
|
let MAX_NUMBER_OF_ENTITIES_TO_FETCH = undefined;
|
|
15
14
|
class GetEntity extends basecommand_1.BaseCommand {
|
|
16
|
-
static description = 'Get an entity';
|
|
15
|
+
static description = '(BETA) Get an entity';
|
|
17
16
|
static examples = [
|
|
18
|
-
'contrail entities get color 123',
|
|
19
|
-
'contrail entities get color id1 id2 id3',
|
|
20
17
|
'contrail entities get color -- id=123',
|
|
21
18
|
'contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16',
|
|
22
19
|
'contrail entities get orders -- updatedAt=2025-09-15T04:00:00Z..',
|
|
@@ -62,56 +59,28 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
62
59
|
description: 'Comma-separated list of relations to include in the output',
|
|
63
60
|
required: false,
|
|
64
61
|
}),
|
|
65
|
-
suffix: core_1.Flags.string({
|
|
66
|
-
description: 'Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets /<entities>/synchronous)',
|
|
67
|
-
required: false,
|
|
68
|
-
}),
|
|
69
|
-
apiVersion: core_1.Flags.string({
|
|
70
|
-
description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
|
|
71
|
-
options: ['1', '2'],
|
|
72
|
-
required: false,
|
|
73
|
-
}),
|
|
74
62
|
};
|
|
75
63
|
static args = {
|
|
76
64
|
typePath: core_1.Args.string({
|
|
77
65
|
description: 'The name of the entity type to fetch',
|
|
78
66
|
required: true,
|
|
79
67
|
}),
|
|
80
|
-
ids: core_1.Args.string({
|
|
81
|
-
description: 'One or more entity ids; shorthand for the id/ids criteria',
|
|
82
|
-
required: false,
|
|
83
|
-
}),
|
|
84
68
|
};
|
|
85
69
|
static strict = false;
|
|
86
|
-
async init() {
|
|
87
|
-
(0, common_1.routeConsoleLogToStderr)();
|
|
88
|
-
await super.init();
|
|
89
|
-
}
|
|
90
70
|
async run() {
|
|
71
|
+
this.log('🚨 This command is in BETA and may change or be removed at any time.');
|
|
91
72
|
await (0, login_1.authUser)();
|
|
92
73
|
const { args, flags, argv } = await this.parse(GetEntity);
|
|
93
74
|
const { typePath } = args;
|
|
94
|
-
const { outputFile, paginated: shouldUsePaginatedFind, propertySlugs, relations: relationString, skip, skipHydrateRelationships,
|
|
75
|
+
const { outputFile, paginated: shouldUsePaginatedFind, propertySlugs, relations: relationString, skip, skipHydrateRelationships, take, } = flags;
|
|
95
76
|
SHOULD_USE_PAGINATED_FIND = shouldUsePaginatedFind;
|
|
96
77
|
MAX_NUMBER_OF_ENTITIES_TO_FETCH = take;
|
|
97
78
|
if (MAX_NUMBER_OF_ENTITIES_TO_FETCH)
|
|
98
|
-
console.
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.error('Pass ids positionally or as -- id=/ids= criteria, not both.');
|
|
104
|
-
}
|
|
105
|
-
if (propertySpecBySlug.size > 0) {
|
|
106
|
-
this.error('Positional ids cannot be combined with other -- criteria. Use -- ids= alongside the other criteria instead.');
|
|
107
|
-
}
|
|
108
|
-
if (positionalIds.length === 1) {
|
|
109
|
-
propertySpecBySlug.set('id', positionalIds[0]);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
propertySpecBySlug.set('ids', positionalIds);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
79
|
+
console.log(`Will limit output to ${MAX_NUMBER_OF_ENTITIES_TO_FETCH} entities.`);
|
|
80
|
+
const propertySpecificationArgs = argv
|
|
81
|
+
.slice(1, argv.length)
|
|
82
|
+
.filter(propertySpecifications_1.isValidPropertySpecification);
|
|
83
|
+
const propertySpecBySlug = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(propertySpecificationArgs);
|
|
115
84
|
const relations = relationString
|
|
116
85
|
? relationString
|
|
117
86
|
.split(',')
|
|
@@ -132,8 +101,6 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
132
101
|
criteria: convertPropertySpecIntoCriteria(propertySpecBySlug),
|
|
133
102
|
skipHydrateRelationships,
|
|
134
103
|
skip,
|
|
135
|
-
suffix,
|
|
136
|
-
apiVersion: apiVersion,
|
|
137
104
|
relations,
|
|
138
105
|
propertySlugs: propertySlugsArray,
|
|
139
106
|
});
|
|
@@ -148,7 +115,7 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
148
115
|
}
|
|
149
116
|
writer.write('\n]\n');
|
|
150
117
|
if (outputFile)
|
|
151
|
-
|
|
118
|
+
this.log(`Output saved to ${outputFile}`);
|
|
152
119
|
}
|
|
153
120
|
else {
|
|
154
121
|
const response = await getEntityByTypePath(typePath, propertySpecBySlug, {
|
|
@@ -156,16 +123,11 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
156
123
|
relations,
|
|
157
124
|
propertySlugs: propertySlugsArray,
|
|
158
125
|
skip,
|
|
159
|
-
suffix,
|
|
160
|
-
apiVersion: apiVersion,
|
|
161
126
|
take,
|
|
162
127
|
});
|
|
163
|
-
if (response === null) {
|
|
164
|
-
this.error(`Entity not found: ${propertySpecBySlug.get('id')}`, { exit: 1 });
|
|
165
|
-
}
|
|
166
128
|
if (outputFile) {
|
|
167
129
|
fs_1.default.writeFileSync(outputFile, JSON.stringify(response, null, 2));
|
|
168
|
-
|
|
130
|
+
this.log(`Output saved to ${outputFile}`);
|
|
169
131
|
}
|
|
170
132
|
else {
|
|
171
133
|
this.log(JSON.stringify(response, null, 2));
|
|
@@ -173,16 +135,13 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
173
135
|
}
|
|
174
136
|
}
|
|
175
137
|
catch (e) {
|
|
176
|
-
if (e.message?.startsWith('Entity not found:')) {
|
|
177
|
-
throw e;
|
|
178
|
-
}
|
|
179
138
|
this.error(`Error fetching entity: ${e.message}`);
|
|
180
139
|
}
|
|
181
140
|
}
|
|
182
141
|
}
|
|
183
142
|
exports.default = GetEntity;
|
|
184
143
|
async function getEntityByTypePath(typePath, propertySpec, options = {}) {
|
|
185
|
-
const { propertySlugs, relations, skipHydrateRelationships, skip,
|
|
144
|
+
const { propertySlugs, relations, skipHydrateRelationships, skip, take } = options;
|
|
186
145
|
const id = propertySpec?.get('id')?.toString() || undefined;
|
|
187
146
|
const criteria = convertPropertySpecIntoCriteria(propertySpec || new Map());
|
|
188
147
|
const { root: entityName } = (0, types_1.parseTypePath)(typePath);
|
|
@@ -191,15 +150,11 @@ async function getEntityByTypePath(typePath, propertySpec, options = {}) {
|
|
|
191
150
|
}
|
|
192
151
|
return find(entityName, {
|
|
193
152
|
id,
|
|
194
|
-
// a missing id returns null (no retries); the command turns it into a clean not-found error
|
|
195
|
-
ignore404: id !== undefined,
|
|
196
153
|
skipHydrateRelationships,
|
|
197
154
|
relations,
|
|
198
155
|
propertySlugs,
|
|
199
156
|
criteria,
|
|
200
157
|
skip,
|
|
201
|
-
suffix,
|
|
202
|
-
apiVersion,
|
|
203
158
|
take,
|
|
204
159
|
});
|
|
205
160
|
}
|
|
@@ -212,24 +167,19 @@ function convertPropertySpecIntoCriteria(propertySpec) {
|
|
|
212
167
|
}
|
|
213
168
|
async function find(entityName, options = {}) {
|
|
214
169
|
const client = new sdk_1.Entities();
|
|
215
|
-
const { criteria, id,
|
|
170
|
+
const { criteria, id, propertySlugs, skipHydrateRelationships, relations, skip, take } = options;
|
|
216
171
|
const queryOptions = {
|
|
217
172
|
entityName,
|
|
218
|
-
ignore404,
|
|
219
173
|
skipHydrateRelationships,
|
|
220
174
|
relations,
|
|
221
175
|
skip,
|
|
222
|
-
suffix,
|
|
223
|
-
apiVersion,
|
|
224
176
|
take,
|
|
225
177
|
};
|
|
226
178
|
if (propertySlugs && propertySlugs.length > 0) {
|
|
227
179
|
queryOptions.customParams = { propertySlugs: propertySlugs.join(',') };
|
|
228
180
|
}
|
|
229
181
|
const payload = id ? { id, ...queryOptions } : { criteria, ...queryOptions };
|
|
230
|
-
|
|
231
|
-
// through the plain client (batch-fetch only understands criteria)
|
|
232
|
-
if ((0, batchFetch_1.canBatchFetchEntity)(entityName) && !suffix && !id) {
|
|
182
|
+
if ((0, batchFetch_1.canBatchFetchEntity)(entityName)) {
|
|
233
183
|
return (0, batchFetch_1.batchFetch)(entityName, payload);
|
|
234
184
|
}
|
|
235
185
|
else {
|
|
@@ -245,8 +195,7 @@ async function* streamPaginatedFind(typePath, options = {}) {
|
|
|
245
195
|
const opts = {
|
|
246
196
|
...options,
|
|
247
197
|
entityName,
|
|
248
|
-
|
|
249
|
-
apiVersion: options.apiVersion ?? sdk_1.API_VERSION.V2,
|
|
198
|
+
apiVersion: sdk_1.API_VERSION.V2,
|
|
250
199
|
nextPageKey,
|
|
251
200
|
};
|
|
252
201
|
if (options.propertySlugs?.length > 0) {
|
|
@@ -263,7 +212,7 @@ async function* streamPaginatedFind(typePath, options = {}) {
|
|
|
263
212
|
if (MAX_NUMBER_OF_ENTITIES_TO_FETCH && count >= MAX_NUMBER_OF_ENTITIES_TO_FETCH)
|
|
264
213
|
return;
|
|
265
214
|
}
|
|
266
|
-
console.
|
|
215
|
+
console.log(`Fetched ${count} entities`);
|
|
267
216
|
if (!nextPageKey || results.length === 0)
|
|
268
217
|
return;
|
|
269
218
|
}
|
|
@@ -6,27 +6,14 @@ export default class UpdateEntity extends BaseCommand {
|
|
|
6
6
|
skipHydrateRelationships: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
7
|
dryRun: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
8
8
|
inputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
-
|
|
10
|
-
apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
+
force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
10
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
11
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
12
|
};
|
|
14
13
|
static args: {
|
|
15
14
|
entityName: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
16
|
-
|
|
15
|
+
id: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
17
16
|
};
|
|
18
17
|
static strict: boolean;
|
|
19
|
-
init(): Promise<void>;
|
|
20
18
|
run(): Promise<void>;
|
|
21
19
|
}
|
|
22
|
-
export type UpdateSummary = {
|
|
23
|
-
updated: any[];
|
|
24
|
-
failed: {
|
|
25
|
-
id: string;
|
|
26
|
-
error: string;
|
|
27
|
-
}[];
|
|
28
|
-
skipped: number;
|
|
29
|
-
};
|
|
30
|
-
export declare function summarizeSettledUpdates(inputs: {
|
|
31
|
-
id: string;
|
|
32
|
-
}[], settled: PromiseSettledResult<any>[], skipped: number): UpdateSummary;
|
|
@@ -1,48 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.summarizeSettledUpdates = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
4
|
const p_limit_1 = tslib_1.__importDefault(require("p-limit"));
|
|
6
5
|
const core_1 = require("@oclif/core");
|
|
7
6
|
const basecommand_1 = require("../../basecommand");
|
|
8
7
|
const sdk_1 = require("@contrail/sdk");
|
|
9
8
|
const login_1 = require("../../auth/login");
|
|
10
|
-
const common_1 = require("../../common");
|
|
11
9
|
const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
|
|
12
10
|
const file_helpers_1 = require("../../helpers/file-helpers");
|
|
13
11
|
class UpdateEntity extends basecommand_1.BaseCommand {
|
|
14
|
-
static description = 'Update an entity';
|
|
12
|
+
static description = '(BETA) Update an entity';
|
|
15
13
|
static examples = [
|
|
16
14
|
'contrail entities update color 123 -- name=obsidian hex=000000',
|
|
17
|
-
'contrail entities update item id1 id2 id3 -- status=archived # apply the same change to several entities',
|
|
18
15
|
'contrail entities update color 123 -- description= notes=\'""\' # Unset description, set notes to empty string',
|
|
19
16
|
];
|
|
20
17
|
static flags = {
|
|
21
18
|
...basecommand_1.BaseCommand.baseFlags,
|
|
22
19
|
skipHydrateRelationships: core_1.Flags.boolean({
|
|
23
|
-
char: '
|
|
20
|
+
char: 's',
|
|
24
21
|
description: 'Skip hydrating relationships when updating the entity',
|
|
25
22
|
required: false,
|
|
26
23
|
default: false,
|
|
27
24
|
}),
|
|
28
25
|
dryRun: core_1.Flags.boolean({
|
|
29
26
|
char: 'd',
|
|
30
|
-
description: 'If true, does not
|
|
27
|
+
description: 'If true, does not create the entity but simulates the creation',
|
|
31
28
|
required: false,
|
|
32
29
|
default: false,
|
|
33
30
|
}),
|
|
34
31
|
inputFile: core_1.Flags.string({
|
|
35
32
|
char: 'i',
|
|
36
|
-
description: '
|
|
33
|
+
description: 'File containing properties to update the entity (optional)',
|
|
37
34
|
required: false,
|
|
38
35
|
}),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}),
|
|
43
|
-
apiVersion: core_1.Flags.string({
|
|
44
|
-
description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
|
|
45
|
-
options: ['1', '2'],
|
|
36
|
+
force: core_1.Flags.boolean({
|
|
37
|
+
char: 'F',
|
|
38
|
+
description: 'Force update without validation. Internal use only',
|
|
46
39
|
required: false,
|
|
47
40
|
}),
|
|
48
41
|
};
|
|
@@ -51,40 +44,33 @@ class UpdateEntity extends basecommand_1.BaseCommand {
|
|
|
51
44
|
description: 'The name of the entity type to update',
|
|
52
45
|
required: true,
|
|
53
46
|
}),
|
|
54
|
-
|
|
55
|
-
description: '
|
|
47
|
+
id: core_1.Args.string({
|
|
48
|
+
description: 'The unique identifier of the entity',
|
|
56
49
|
required: false,
|
|
57
50
|
}),
|
|
58
51
|
};
|
|
59
52
|
static strict = false;
|
|
60
|
-
async init() {
|
|
61
|
-
(0, common_1.routeConsoleLogToStderr)();
|
|
62
|
-
await super.init();
|
|
63
|
-
}
|
|
64
53
|
async run() {
|
|
54
|
+
this.log('🚨 This command is in BETA and may change or be removed at any time.');
|
|
65
55
|
await (0, login_1.authUser)();
|
|
66
56
|
const { args, argv } = await this.parse(UpdateEntity);
|
|
67
|
-
const { entityName } = args;
|
|
68
|
-
const { dryRun: isDryRun, inputFile: inputFilename, skipHydrateRelationships,
|
|
69
|
-
const
|
|
70
|
-
const propertySpec = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
if (inputFilename && positionalIds.length > 0) {
|
|
75
|
-
this.error('You cannot use --inputFile and positional ids together. Please specify one or the other.');
|
|
76
|
-
}
|
|
77
|
-
if (!inputFilename && positionalIds.length === 0) {
|
|
78
|
-
this.error('You must provide one or more ids or an input file (-i) of entities to update.');
|
|
79
|
-
}
|
|
80
|
-
if (positionalIds.length > 0 && propertySpec.size === 0) {
|
|
81
|
-
this.error('Nothing to update: pass values to write after --, e.g. -- name=jet');
|
|
57
|
+
const { id: specifiedId, entityName } = args;
|
|
58
|
+
const { dryRun: isDryRun, inputFile: inputFilename, skipHydrateRelationships, force, } = this.flags;
|
|
59
|
+
const propertySpecArgs = argv.slice(1, argv.length).filter(propertySpecifications_1.isValidPropertySpecification);
|
|
60
|
+
const propertySpec = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(propertySpecArgs);
|
|
61
|
+
if (inputFilename && specifiedId) {
|
|
62
|
+
throw new Error('You cannot use --input and --id together. Please specify one or the other.');
|
|
82
63
|
}
|
|
83
64
|
const entitiesToUpdate = inputFilename
|
|
84
65
|
? (0, file_helpers_1.parseFileAsJsonArray)(inputFilename)
|
|
85
|
-
:
|
|
86
|
-
const
|
|
66
|
+
: [{ id: specifiedId }];
|
|
67
|
+
const results = {
|
|
68
|
+
idsSuccessfullyUpdated: new Set(),
|
|
69
|
+
idsFailedToUpdate: new Set(),
|
|
70
|
+
numEntriesSkipped: entitiesToUpdate.filter(({ id }) => !id).length,
|
|
71
|
+
};
|
|
87
72
|
const entitiesWithId = entitiesToUpdate.filter(({ id }) => id);
|
|
73
|
+
propertySpec.delete('id'); // Remove 'id' from the property spec if it exists
|
|
88
74
|
// will be applied to all entities
|
|
89
75
|
const fixedValues = [...propertySpec.entries()].reduce((acc, [key, value]) => {
|
|
90
76
|
acc[key] = value;
|
|
@@ -93,61 +79,39 @@ class UpdateEntity extends basecommand_1.BaseCommand {
|
|
|
93
79
|
async function updateEntity(entity) {
|
|
94
80
|
const newEntityState = { ...entity, ...fixedValues };
|
|
95
81
|
const id = entity.id;
|
|
96
|
-
|
|
82
|
+
const promise = isDryRun
|
|
97
83
|
? mockUpdateById(entityName, id, newEntityState, { skipHydrateRelationships })
|
|
98
|
-
: updateEntityById(entityName, id, newEntityState, {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
84
|
+
: updateEntityById(entityName, id, newEntityState, { skipHydrateRelationships, force });
|
|
85
|
+
promise
|
|
86
|
+
.catch(() => {
|
|
87
|
+
results.idsFailedToUpdate.add(id);
|
|
88
|
+
})
|
|
89
|
+
.then(() => {
|
|
90
|
+
results.idsSuccessfullyUpdated.add(id);
|
|
91
|
+
});
|
|
92
|
+
return promise;
|
|
103
93
|
}
|
|
104
94
|
try {
|
|
105
95
|
const limit = (0, p_limit_1.default)(20);
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
this.log(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
process.exitCode = 1;
|
|
115
|
-
}
|
|
96
|
+
const responses = await Promise.all(entitiesWithId.map((entity) => limit(() => updateEntity(entity))));
|
|
97
|
+
const messagePrefix = isDryRun
|
|
98
|
+
? 'Dry run. Update skipped. Changes would be:'
|
|
99
|
+
: 'Entity updated successfully:';
|
|
100
|
+
this.log(`${messagePrefix}\n\n${JSON.stringify(responses, null, 2)}`);
|
|
101
|
+
this.log(`\nIDs successfully updated: ${Array.from(results.idsSuccessfullyUpdated).join(', ')}`);
|
|
102
|
+
this.log(`IDs failed to update: ${Array.from(results.idsFailedToUpdate).join(', ')}`);
|
|
103
|
+
this.log(`Number of entries skipped due to missing IDs: ${results.numEntriesSkipped}`);
|
|
116
104
|
}
|
|
117
105
|
catch (e) {
|
|
118
|
-
this.error(`Error
|
|
106
|
+
this.error(`Error fetching entity: ${e.message}`);
|
|
119
107
|
}
|
|
120
108
|
}
|
|
121
109
|
}
|
|
122
110
|
exports.default = UpdateEntity;
|
|
123
|
-
function summarizeSettledUpdates(inputs, settled, skipped) {
|
|
124
|
-
const updated = [];
|
|
125
|
-
const failed = [];
|
|
126
|
-
settled.forEach((result, index) => {
|
|
127
|
-
if (result.status === 'fulfilled') {
|
|
128
|
-
updated.push(result.value);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
failed.push({
|
|
132
|
-
id: inputs[index].id,
|
|
133
|
-
error: (0, common_1.sdkErrorMessage)(result.reason),
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
return { updated, failed, skipped };
|
|
138
|
-
}
|
|
139
|
-
exports.summarizeSettledUpdates = summarizeSettledUpdates;
|
|
140
111
|
async function updateEntityById(entityName, id, changes, options = {}) {
|
|
141
112
|
const client = new sdk_1.Entities();
|
|
142
|
-
const { skipHydrateRelationships,
|
|
143
|
-
return client.update({
|
|
144
|
-
entityName,
|
|
145
|
-
id,
|
|
146
|
-
object: changes,
|
|
147
|
-
skipHydrateRelationships,
|
|
148
|
-
suffix,
|
|
149
|
-
apiVersion,
|
|
150
|
-
});
|
|
113
|
+
const { skipHydrateRelationships, force } = options;
|
|
114
|
+
return client.update({ entityName, id, object: changes, skipHydrateRelationships });
|
|
151
115
|
}
|
|
152
116
|
async function mockUpdateById(entityName, id, changes, options = {}) {
|
|
153
117
|
const client = new sdk_1.Entities();
|
|
@@ -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,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
|
+
const export_1 = tslib_1.__importStar(require("./export"));
|
|
6
|
+
const file_helpers_1 = require("../../helpers/file-helpers");
|
|
7
|
+
const feature_flags_1 = require("../../api/feature-flags");
|
|
8
|
+
const login_1 = require("../../auth/login");
|
|
9
|
+
jest.mock('../../helpers/file-helpers');
|
|
10
|
+
jest.mock('../../api/feature-flags');
|
|
11
|
+
jest.mock('../../auth/login');
|
|
12
|
+
const mocked = (fn) => fn;
|
|
13
|
+
describe('exportFeatureFlags', () => {
|
|
14
|
+
let mkdirSyncSpy;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
jest.clearAllMocks();
|
|
17
|
+
mkdirSyncSpy = jest.spyOn(fs_1.default, 'mkdirSync').mockReturnValue(undefined);
|
|
18
|
+
mocked(file_helpers_1.saveData).mockResolvedValue(undefined);
|
|
19
|
+
});
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
mkdirSyncSpy.mockRestore();
|
|
22
|
+
});
|
|
23
|
+
it('writes the enabled flags sorted, without org specific fields', async () => {
|
|
24
|
+
mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([
|
|
25
|
+
{ id: '1', orgId: 'org-a', featureName: 'SHOWROOM' },
|
|
26
|
+
{ id: '2', orgId: 'org-a', featureName: 'DEV_TABS' },
|
|
27
|
+
]);
|
|
28
|
+
await (0, export_1.exportFeatureFlags)('out-dir', true);
|
|
29
|
+
expect(mocked(file_helpers_1.saveData)).toHaveBeenCalledWith([{ featureName: 'DEV_TABS' }, { featureName: 'SHOWROOM' }], 'out-dir/feature-flags.yml', true);
|
|
30
|
+
});
|
|
31
|
+
it('still writes a file when no flags are enabled, so the export is a full snapshot', async () => {
|
|
32
|
+
mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([]);
|
|
33
|
+
await (0, export_1.exportFeatureFlags)('out-dir', false);
|
|
34
|
+
expect(mocked(file_helpers_1.saveData)).toHaveBeenCalledWith([], 'out-dir/feature-flags.yml', false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('ExportFeatureFlags command', () => {
|
|
38
|
+
let mkdirSyncSpy;
|
|
39
|
+
let logs;
|
|
40
|
+
// oclif's init() parses argv and reads the on-disk config, so drive run() with flags set directly
|
|
41
|
+
const runCommand = async () => {
|
|
42
|
+
const command = new export_1.default([], {});
|
|
43
|
+
command.flags = { outDir: 'out-dir', overwrite: true };
|
|
44
|
+
jest.spyOn(command, 'log').mockImplementation((message) => logs.push(String(message)));
|
|
45
|
+
await command.run();
|
|
46
|
+
};
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
jest.clearAllMocks();
|
|
49
|
+
logs = [];
|
|
50
|
+
process.exitCode = undefined;
|
|
51
|
+
mkdirSyncSpy = jest.spyOn(fs_1.default, 'mkdirSync').mockReturnValue(undefined);
|
|
52
|
+
mocked(login_1.authUser).mockResolvedValue({});
|
|
53
|
+
mocked(file_helpers_1.saveData).mockResolvedValue(undefined);
|
|
54
|
+
mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([]);
|
|
55
|
+
});
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
mkdirSyncSpy.mockRestore();
|
|
58
|
+
process.exitCode = undefined;
|
|
59
|
+
});
|
|
60
|
+
it('leaves the exit code alone on success', async () => {
|
|
61
|
+
await runCommand();
|
|
62
|
+
expect(process.exitCode).toBeUndefined();
|
|
63
|
+
expect(logs.join('\n')).toContain('Feature Flags Export Complete');
|
|
64
|
+
});
|
|
65
|
+
const failures = [
|
|
66
|
+
[
|
|
67
|
+
'authentication fails',
|
|
68
|
+
() => {
|
|
69
|
+
mocked(login_1.authUser).mockRejectedValue(new Error('boom'));
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
'the API read fails',
|
|
74
|
+
() => {
|
|
75
|
+
mocked(feature_flags_1.getFeatureFlags).mockRejectedValue(new Error('boom'));
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
'the directory cannot be created',
|
|
80
|
+
() => {
|
|
81
|
+
mkdirSyncSpy.mockImplementation(() => {
|
|
82
|
+
throw new Error('boom');
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
'the file write fails',
|
|
88
|
+
() => {
|
|
89
|
+
mocked(file_helpers_1.saveData).mockRejectedValue(new Error('boom'));
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
];
|
|
93
|
+
it.each(failures)('exits non-zero when %s, so automation does not read it as a success', async (_, fail) => {
|
|
94
|
+
fail();
|
|
95
|
+
await runCommand();
|
|
96
|
+
expect(process.exitCode).toBe(1);
|
|
97
|
+
const output = logs.join('\n');
|
|
98
|
+
expect(output).toContain('Feature Flags Export Failed');
|
|
99
|
+
expect(output).not.toContain('Feature Flags Export Complete');
|
|
100
|
+
});
|
|
101
|
+
it('reports the API message rather than a bare "Error"', async () => {
|
|
102
|
+
// the SDK's ApiError has an undefined message and keeps the body in details
|
|
103
|
+
mocked(feature_flags_1.getFeatureFlags).mockRejectedValue({
|
|
104
|
+
details: '{"message":"Forbidden resource","statusCode":403}',
|
|
105
|
+
});
|
|
106
|
+
await runCommand();
|
|
107
|
+
expect(logs.join('\n')).toContain('Forbidden resource');
|
|
108
|
+
});
|
|
109
|
+
});
|