@contrail/cli 3.6.0-alpha-8-alpha.252e3f3 → 3.6.0-alpha-8-alpha.c613d8e
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 +31 -58
- package/dist/auth/login.js +8 -9
- package/dist/basecommand.js +2 -2
- 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/common.d.ts +0 -3
- package/dist/common.js +1 -18
- 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 +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/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +1 -1
- package/oclif.manifest.json +27 -99
- package/package.json +1 -1
- package/dist/commands/entities/grammar.spec.d.ts +0 -1
- package/dist/commands/entities/grammar.spec.js +0 -80
- package/dist/commands/entities/output.spec.d.ts +0 -1
- package/dist/commands/entities/output.spec.js +0 -72
- package/dist/logger.spec.d.ts +0 -1
- package/dist/logger.spec.js +0 -12
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +0 -34
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/image-search.js +0 -42
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/index.js +0 -17
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.c613d8e linux-x64 node-v24.22.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -52,9 +52,9 @@ To get instructions on how to set up autocomplete for your shell, run `contrail
|
|
|
52
52
|
* [`contrail config set`](#contrail-config-set)
|
|
53
53
|
* [`contrail config use [NAME]`](#contrail-config-use-name)
|
|
54
54
|
* [`contrail entities create PATH`](#contrail-entities-create-path)
|
|
55
|
-
* [`contrail entities delete ENTITYNAME
|
|
56
|
-
* [`contrail entities get TYPEPATH
|
|
57
|
-
* [`contrail entities update ENTITYNAME [
|
|
55
|
+
* [`contrail entities delete ENTITYNAME`](#contrail-entities-delete-entityname)
|
|
56
|
+
* [`contrail entities get TYPEPATH`](#contrail-entities-get-typepath)
|
|
57
|
+
* [`contrail entities update ENTITYNAME [ID]`](#contrail-entities-update-entityname-id)
|
|
58
58
|
* [`contrail feature-flags export`](#contrail-feature-flags-export)
|
|
59
59
|
* [`contrail feature-flags import`](#contrail-feature-flags-import)
|
|
60
60
|
* [`contrail file upload FILELOCATION CONTENTTYPE`](#contrail-file-upload-filelocation-contenttype)
|
|
@@ -545,18 +545,17 @@ EXAMPLES
|
|
|
545
545
|
|
|
546
546
|
## `contrail entities create PATH`
|
|
547
547
|
|
|
548
|
-
Create entities
|
|
548
|
+
(BETA) Create entities
|
|
549
549
|
|
|
550
550
|
```
|
|
551
551
|
USAGE
|
|
552
552
|
$ contrail entities create PATH [-l error|warn|info|debug] [-e true|false] [-n <value>] [-d] [-i <value>] [-o
|
|
553
|
-
<value>] [-g] [-r] [-
|
|
553
|
+
<value>] [-g] [-r] [-s]
|
|
554
554
|
|
|
555
555
|
ARGUMENTS
|
|
556
556
|
PATH Path of the entity type to create
|
|
557
557
|
|
|
558
558
|
FLAGS
|
|
559
|
-
-S, --skipHydrateRelationships If true, does not hydrate relationships for the created entities
|
|
560
559
|
-d, --dryRun If true, does not create the entity but simulates the creation
|
|
561
560
|
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
562
561
|
<options: true|false>
|
|
@@ -570,13 +569,10 @@ FLAGS
|
|
|
570
569
|
-n, --count=<value> Number of random entities to create
|
|
571
570
|
-o, --outputFile=<value> File to save the output (optional)
|
|
572
571
|
-r, --readableIds If true, uses readable IDs for the created entities
|
|
573
|
-
|
|
574
|
-
<options: 1|2>
|
|
575
|
-
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
576
|
-
/<entities>/synchronous)
|
|
572
|
+
-s, --skipHydrateRelationships If true, does not hydrate relationships for the created entities
|
|
577
573
|
|
|
578
574
|
DESCRIPTION
|
|
579
|
-
Create entities
|
|
575
|
+
(BETA) Create entities
|
|
580
576
|
|
|
581
577
|
EXAMPLES
|
|
582
578
|
$ contrail entities create color -g -n=10 # creates 10 random colors
|
|
@@ -598,55 +594,46 @@ EXAMPLES
|
|
|
598
594
|
$ contrail entities create color -o /tmp/colors.json -- name=Blue green=1 red=2 blue=3 # creates a color and saves the output to /tmp/colors.json
|
|
599
595
|
```
|
|
600
596
|
|
|
601
|
-
## `contrail entities delete ENTITYNAME
|
|
597
|
+
## `contrail entities delete ENTITYNAME`
|
|
602
598
|
|
|
603
|
-
Delete
|
|
599
|
+
(BETA) Delete an entity
|
|
604
600
|
|
|
605
601
|
```
|
|
606
602
|
USAGE
|
|
607
|
-
$ contrail entities delete ENTITYNAME [
|
|
608
|
-
<value>] [--apiVersion 1|2]
|
|
603
|
+
$ contrail entities delete ENTITYNAME [-l error|warn|info|debug] [-e true|false] [-d] [-i <value>] [--id <value>]
|
|
609
604
|
|
|
610
605
|
ARGUMENTS
|
|
611
606
|
ENTITYNAME The name of the entity type to delete
|
|
612
|
-
IDS One or more entity ids to delete
|
|
613
607
|
|
|
614
608
|
FLAGS
|
|
615
|
-
-d, --dryRun If true, does not delete the
|
|
609
|
+
-d, --dryRun If true, does not delete the entity but simulates the deletion
|
|
616
610
|
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
617
611
|
<options: true|false>
|
|
618
|
-
-i, --
|
|
619
|
-
|
|
612
|
+
-i, --input=<value> A JSON array of objects where each object is one entity to create. Cannot be used
|
|
613
|
+
with --count. Unless --precise is specified, any missing values will be populated
|
|
614
|
+
with random values.
|
|
620
615
|
-l, --logLevel=<option> The Log Level
|
|
621
616
|
<options: error|warn|info|debug>
|
|
622
|
-
--
|
|
623
|
-
<options: 1|2>
|
|
624
|
-
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
625
|
-
/<entities>/synchronous)
|
|
617
|
+
--id=<value> The unique identifier of the entity
|
|
626
618
|
|
|
627
619
|
DESCRIPTION
|
|
628
|
-
Delete
|
|
620
|
+
(BETA) Delete an entity
|
|
629
621
|
|
|
630
622
|
EXAMPLES
|
|
631
623
|
$ contrail entities delete color 123
|
|
632
|
-
|
|
633
|
-
$ contrail entities delete color id1 id2 id3
|
|
634
|
-
|
|
635
|
-
$ contrail entities delete item -i ids.json
|
|
636
624
|
```
|
|
637
625
|
|
|
638
|
-
## `contrail entities get TYPEPATH
|
|
626
|
+
## `contrail entities get TYPEPATH`
|
|
639
627
|
|
|
640
|
-
Get an entity
|
|
628
|
+
(BETA) Get an entity
|
|
641
629
|
|
|
642
630
|
```
|
|
643
631
|
USAGE
|
|
644
|
-
$ contrail entities get TYPEPATH [
|
|
645
|
-
|
|
632
|
+
$ contrail entities get TYPEPATH [-l error|warn|info|debug] [-e true|false] [-o <value>] [-p <value>] [-P] [-s
|
|
633
|
+
<value>] [-S] [-t <value>] [-r <value>]
|
|
646
634
|
|
|
647
635
|
ARGUMENTS
|
|
648
636
|
TYPEPATH The name of the entity type to fetch
|
|
649
|
-
IDS One or more entity ids; shorthand for the id/ids criteria
|
|
650
637
|
|
|
651
638
|
FLAGS
|
|
652
639
|
-P, --paginated If true, fetches all entities in a paginated manner
|
|
@@ -660,19 +647,11 @@ FLAGS
|
|
|
660
647
|
-r, --relations=<value> Comma-separated list of relations to include in the output
|
|
661
648
|
-s, --skip=<value> Number of entities to skip (used with paginated fetch)
|
|
662
649
|
-t, --take=<value> Number of entities to fetch in a single request (default is 100)
|
|
663
|
-
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
664
|
-
<options: 1|2>
|
|
665
|
-
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
666
|
-
/<entities>/synchronous)
|
|
667
650
|
|
|
668
651
|
DESCRIPTION
|
|
669
|
-
Get an entity
|
|
652
|
+
(BETA) Get an entity
|
|
670
653
|
|
|
671
654
|
EXAMPLES
|
|
672
|
-
$ contrail entities get color 123
|
|
673
|
-
|
|
674
|
-
$ contrail entities get color id1 id2 id3
|
|
675
|
-
|
|
676
655
|
$ contrail entities get color -- id=123
|
|
677
656
|
|
|
678
657
|
$ contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16
|
|
@@ -682,40 +661,34 @@ EXAMPLES
|
|
|
682
661
|
$ contrail entities get events -- timestamp=..2025-09-16T23:59:59Z
|
|
683
662
|
```
|
|
684
663
|
|
|
685
|
-
## `contrail entities update ENTITYNAME [
|
|
664
|
+
## `contrail entities update ENTITYNAME [ID]`
|
|
686
665
|
|
|
687
|
-
Update an entity
|
|
666
|
+
(BETA) Update an entity
|
|
688
667
|
|
|
689
668
|
```
|
|
690
669
|
USAGE
|
|
691
|
-
$ contrail entities update ENTITYNAME [
|
|
692
|
-
[--suffix <value>] [--apiVersion 1|2]
|
|
670
|
+
$ contrail entities update ENTITYNAME [ID] [-l error|warn|info|debug] [-e true|false] [-s] [-d] [-i <value>] [-F]
|
|
693
671
|
|
|
694
672
|
ARGUMENTS
|
|
695
673
|
ENTITYNAME The name of the entity type to update
|
|
696
|
-
|
|
674
|
+
ID The unique identifier of the entity
|
|
697
675
|
|
|
698
676
|
FLAGS
|
|
699
|
-
-
|
|
700
|
-
-d, --dryRun If true, does not
|
|
677
|
+
-F, --force Force update without validation. Internal use only
|
|
678
|
+
-d, --dryRun If true, does not create the entity but simulates the creation
|
|
701
679
|
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
702
680
|
<options: true|false>
|
|
703
|
-
-i, --inputFile=<value>
|
|
681
|
+
-i, --inputFile=<value> File containing properties to update the entity (optional)
|
|
704
682
|
-l, --logLevel=<option> The Log Level
|
|
705
683
|
<options: error|warn|info|debug>
|
|
706
|
-
|
|
707
|
-
<options: 1|2>
|
|
708
|
-
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
709
|
-
/<entities>/synchronous)
|
|
684
|
+
-s, --skipHydrateRelationships Skip hydrating relationships when updating the entity
|
|
710
685
|
|
|
711
686
|
DESCRIPTION
|
|
712
|
-
Update an entity
|
|
687
|
+
(BETA) Update an entity
|
|
713
688
|
|
|
714
689
|
EXAMPLES
|
|
715
690
|
$ contrail entities update color 123 -- name=obsidian hex=000000
|
|
716
691
|
|
|
717
|
-
$ contrail entities update item id1 id2 id3 -- status=archived # apply the same change to several entities
|
|
718
|
-
|
|
719
692
|
$ contrail entities update color 123 -- description= notes='""' # Unset description, set notes to empty string
|
|
720
693
|
```
|
|
721
694
|
|
package/dist/auth/login.js
CHANGED
|
@@ -3,6 +3,7 @@ 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"));
|
|
6
7
|
const sdk_1 = require("@contrail/sdk");
|
|
7
8
|
const config_1 = require("../helpers/config/config");
|
|
8
9
|
const logger_1 = tslib_1.__importDefault(require("../logger"));
|
|
@@ -62,7 +63,7 @@ exports.authUser = authUser;
|
|
|
62
63
|
async function getOrgSlug(config) {
|
|
63
64
|
const orgSlug = config?.orgSlug || process.env.CONTRAIL_CLI_ORG_SLUG;
|
|
64
65
|
if (!orgSlug) {
|
|
65
|
-
const answers = await
|
|
66
|
+
const answers = await inquirer_1.default.prompt([
|
|
66
67
|
{
|
|
67
68
|
type: 'input',
|
|
68
69
|
name: 'orgSlug',
|
|
@@ -111,7 +112,7 @@ async function authenticateWithUsernamePassword(config) {
|
|
|
111
112
|
message: 'Password',
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
|
-
const answers = await
|
|
115
|
+
const answers = await inquirer_1.default.prompt(questions);
|
|
115
116
|
const params = {
|
|
116
117
|
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
117
118
|
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
@@ -174,7 +175,7 @@ async function refreshCurrentUserOrg() {
|
|
|
174
175
|
const currentUser = await (0, sdk_1.getCurrentUser)().catch((e) => {
|
|
175
176
|
console.error('error getting current user', e.message);
|
|
176
177
|
if (isExpiredTokenError(e)) {
|
|
177
|
-
console.
|
|
178
|
+
console.log('try frefreshing');
|
|
178
179
|
return;
|
|
179
180
|
}
|
|
180
181
|
throw e;
|
|
@@ -189,7 +190,7 @@ async function refreshCurrentUserOrg() {
|
|
|
189
190
|
apiGateway: config.apiGateway,
|
|
190
191
|
orgSlug: config.orgSlug,
|
|
191
192
|
};
|
|
192
|
-
(
|
|
193
|
+
console.log('fetched new access token from refresh token', newVibeAccessToken);
|
|
193
194
|
}
|
|
194
195
|
catch (e) {
|
|
195
196
|
throw Error(`Could not get refresh token: ${e}`);
|
|
@@ -233,11 +234,9 @@ async function requestRefreshedAccessToken(vibeRefreshToken, apiGateway) {
|
|
|
233
234
|
},
|
|
234
235
|
body: JSON.stringify({ refreshToken: vibeRefreshToken }),
|
|
235
236
|
});
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
return data.accessToken;
|
|
237
|
+
return await response.json().then((data) => {
|
|
238
|
+
return data.accessToken;
|
|
239
|
+
});
|
|
241
240
|
}
|
|
242
241
|
function getVersionFromPackageJson() {
|
|
243
242
|
// Get the path to the package.json file
|
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");
|
|
7
6
|
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");
|
|
@@ -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 inquirer_1.default.prompt(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);
|
|
@@ -35,7 +35,7 @@ class GetAPIKeyApp extends basecommand_1.BaseCommand {
|
|
|
35
35
|
},
|
|
36
36
|
];
|
|
37
37
|
const answers = await inquirer_1.default.prompt(questions);
|
|
38
|
-
|
|
38
|
+
logger_1.default.info(`App API key: (app:${answers.appApiKey})`);
|
|
39
39
|
}
|
|
40
40
|
else {
|
|
41
41
|
const appFound = installedApps.find((x) => x.app.identifier === this.flags.appIdentifier);
|
|
@@ -43,7 +43,7 @@ class GetAPIKeyApp extends basecommand_1.BaseCommand {
|
|
|
43
43
|
logger_1.default.info('You do not have such an app installed');
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
logger_1.default.info(`App API key: (app:${appFound.apiKey.apiKey})`);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropertyLevel
|
|
1
|
+
import { PropertyLevel } from '@contrail/types';
|
|
2
2
|
import { ColonDelimited, TypeProperty as ExtendedTypeProperty, TypeReferencesCacheByPath } from '../../api/types';
|
|
3
3
|
import { TypeWithProperties } from '../../api/types';
|
|
4
4
|
import { BaseCommand } from '../../basecommand';
|
|
@@ -14,8 +14,6 @@ export default class CreateEntity extends BaseCommand {
|
|
|
14
14
|
generateValues: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
15
15
|
readableIds: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
16
|
skipHydrateRelationships: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
|
-
suffix: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
18
|
-
apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
19
17
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
20
18
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
21
19
|
};
|
|
@@ -23,17 +21,8 @@ export default class CreateEntity extends BaseCommand {
|
|
|
23
21
|
path: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
24
22
|
};
|
|
25
23
|
static strict: boolean;
|
|
26
|
-
init(): Promise<void>;
|
|
27
24
|
run(): Promise<void>;
|
|
28
25
|
}
|
|
29
|
-
export type CreateSummary = {
|
|
30
|
-
created: any[];
|
|
31
|
-
failed: {
|
|
32
|
-
input: any;
|
|
33
|
-
error: string;
|
|
34
|
-
}[];
|
|
35
|
-
};
|
|
36
|
-
export declare function summarizeSettledCreates(inputs: any[], settled: PromiseSettledResult<any>[]): CreateSummary;
|
|
37
26
|
export type WithId = {
|
|
38
27
|
id: string;
|
|
39
28
|
[key: string]: any;
|
|
@@ -41,7 +30,6 @@ export type WithId = {
|
|
|
41
30
|
export type ObjectReferenceCache = Map<string, WithId>;
|
|
42
31
|
type ObjectReferenceCachesByTypePath = Map<string, ObjectReferenceCache>;
|
|
43
32
|
export declare function pickRandomValueForProperty(property: ExtendedTypeProperty, objectReferencesCache: ObjectReferenceCachesByTypePath, typeReferencesCache: TypeReferencesCacheByPath): number | string | string[] | boolean | null;
|
|
44
|
-
export declare function castValueToPropertyType(value: string | number | string[] | number[], propertyType: PropertyType): any;
|
|
45
33
|
export declare function getReferencedObjectPaths(type: TypeWithProperties): ColonDelimited[];
|
|
46
34
|
export declare function buildObjectReferenceCache(entities: any[]): ObjectReferenceCache;
|
|
47
35
|
export declare function selectRandomObject(cache: ObjectReferenceCache): WithId;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.doesPropertyLevelMatchRole = exports.selectRandomObject = exports.buildObjectReferenceCache = exports.getReferencedObjectPaths = exports.
|
|
3
|
+
exports.doesPropertyLevelMatchRole = exports.selectRandomObject = exports.buildObjectReferenceCache = exports.getReferencedObjectPaths = exports.pickRandomValueForProperty = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
6
|
const unique_names_generator_1 = require("unique-names-generator");
|
|
@@ -10,7 +10,6 @@ const types_2 = require("../../api/types");
|
|
|
10
10
|
const core_1 = require("@oclif/core");
|
|
11
11
|
const types_3 = require("../../api/types");
|
|
12
12
|
const login_1 = require("../../auth/login");
|
|
13
|
-
const common_1 = require("../../common");
|
|
14
13
|
const basecommand_1 = require("../../basecommand");
|
|
15
14
|
const sdk_1 = require("@contrail/sdk");
|
|
16
15
|
const entities_1 = require("../../helpers/entities");
|
|
@@ -27,7 +26,7 @@ const baseValidationMap = {
|
|
|
27
26
|
itemId: async (_slug, itemId) => (0, entities_1.throwIfInvalidItemId)(itemId),
|
|
28
27
|
projectId: async (_slug, projectId) => (0, entities_1.throwIfInvalidProjectId)(projectId),
|
|
29
28
|
};
|
|
30
|
-
const throwIfInvalidPropertyLevelFn = async (_slug, maybeRoles) =>
|
|
29
|
+
const throwIfInvalidPropertyLevelFn = async (_slug, maybeRoles) => maybeRoles.forEach((maybeRole) => (0, entities_1.throwIfInvalidItemLevel)(maybeRole));
|
|
31
30
|
const throwIfInvalidUserOrgRoleFn = async (_slug, maybeRole) => {
|
|
32
31
|
if (maybeRole !== 'MEMBER' && maybeRole !== 'ADMIN') {
|
|
33
32
|
throw new Error(`${maybeRole} is not a valid User Org Role`); // TODO: get these roles from a shared library
|
|
@@ -145,7 +144,7 @@ const FIND_VALID_VALUE_MAP = {
|
|
|
145
144
|
],
|
|
146
145
|
};
|
|
147
146
|
class CreateEntity extends basecommand_1.BaseCommand {
|
|
148
|
-
static description = 'Create entities';
|
|
147
|
+
static description = '(BETA) Create entities';
|
|
149
148
|
static examples = [
|
|
150
149
|
'contrail entities create color -g -n=10 # creates 10 random colors',
|
|
151
150
|
'contrail entities create color -- name="Electric Blue" green=1 red=2 blue=3 # creates one color with specified properties only',
|
|
@@ -195,20 +194,11 @@ class CreateEntity extends basecommand_1.BaseCommand {
|
|
|
195
194
|
default: false,
|
|
196
195
|
}),
|
|
197
196
|
skipHydrateRelationships: core_1.Flags.boolean({
|
|
198
|
-
char: '
|
|
197
|
+
char: 's',
|
|
199
198
|
description: 'If true, does not hydrate relationships for the created entities',
|
|
200
199
|
required: false,
|
|
201
200
|
default: false,
|
|
202
201
|
}),
|
|
203
|
-
suffix: core_1.Flags.string({
|
|
204
|
-
description: 'Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets /<entities>/synchronous)',
|
|
205
|
-
required: false,
|
|
206
|
-
}),
|
|
207
|
-
apiVersion: core_1.Flags.string({
|
|
208
|
-
description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
|
|
209
|
-
options: ['1', '2'],
|
|
210
|
-
required: false,
|
|
211
|
-
}),
|
|
212
202
|
};
|
|
213
203
|
static args = {
|
|
214
204
|
path: core_1.Args.string({
|
|
@@ -218,14 +208,11 @@ class CreateEntity extends basecommand_1.BaseCommand {
|
|
|
218
208
|
}),
|
|
219
209
|
};
|
|
220
210
|
static strict = false;
|
|
221
|
-
async init() {
|
|
222
|
-
(0, common_1.routeConsoleLogToStderr)();
|
|
223
|
-
await super.init();
|
|
224
|
-
}
|
|
225
211
|
async run() {
|
|
212
|
+
this.log('🚨 This command is in BETA and may change or be removed at any time.');
|
|
226
213
|
await (0, login_1.authUser)();
|
|
227
214
|
const { flags, argv, args } = await this.parse(CreateEntity);
|
|
228
|
-
const { count, dryRun: isDryRun, inputFile: inputFilename, outputFile: outputFilename, generateValues: shouldGenerateMissingValues, readableIds: shouldUseReadableIds, skipHydrateRelationships,
|
|
215
|
+
const { count, dryRun: isDryRun, inputFile: inputFilename, outputFile: outputFilename, generateValues: shouldGenerateMissingValues, readableIds: shouldUseReadableIds, skipHydrateRelationships, } = flags;
|
|
229
216
|
const { path: entityTypePath } = args;
|
|
230
217
|
// Global flags is a little hacky, but it was easier
|
|
231
218
|
// and it doesn't see *that* bad because they are only valid
|
|
@@ -234,11 +221,10 @@ class CreateEntity extends basecommand_1.BaseCommand {
|
|
|
234
221
|
SHOULD_USE_READABLE_IDS = shouldUseReadableIds;
|
|
235
222
|
SHOULD_SKIP_HYDRATE_RELATIONSHIPS = skipHydrateRelationships;
|
|
236
223
|
SHOULD_GENERATE_MISSING_VALUES = shouldGenerateMissingValues;
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const propertySpecBySlug = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
224
|
+
const propertySpecificationArgs = argv
|
|
225
|
+
.slice(1, argv.length)
|
|
226
|
+
.filter(propertySpecifications_1.isValidPropertySpecification);
|
|
227
|
+
const propertySpecBySlug = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(propertySpecificationArgs);
|
|
242
228
|
// Validate args
|
|
243
229
|
if (!entityTypePath) {
|
|
244
230
|
this.error('You must specify an entity type path.');
|
|
@@ -271,20 +257,13 @@ class CreateEntity extends basecommand_1.BaseCommand {
|
|
|
271
257
|
}
|
|
272
258
|
try {
|
|
273
259
|
const entitiesToCreate = await buildEntitiesToCreate(entityTypePath, partialEntities, propertySpecBySlug);
|
|
274
|
-
const
|
|
275
|
-
suffix,
|
|
276
|
-
apiVersion: apiVersion,
|
|
277
|
-
});
|
|
260
|
+
const createdEntities = await createEntities(entityName, entitiesToCreate);
|
|
278
261
|
if (outputFilename) {
|
|
279
|
-
fs_1.default.writeFileSync(outputFilename, JSON.stringify(
|
|
280
|
-
|
|
262
|
+
fs_1.default.writeFileSync(outputFilename, JSON.stringify(createdEntities, null, 2));
|
|
263
|
+
this.log(`Output saved to ${outputFilename}`);
|
|
281
264
|
}
|
|
282
265
|
else {
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
if (summary.failed.length > 0) {
|
|
286
|
-
console.error(`${summary.failed.length} of ${entitiesToCreate.length} entities failed.`);
|
|
287
|
-
process.exitCode = 1;
|
|
266
|
+
console.log(`Created ${entityTypePath}(s), Entity: ${JSON.stringify(createdEntities, null, 2)}`);
|
|
288
267
|
}
|
|
289
268
|
}
|
|
290
269
|
catch (error) {
|
|
@@ -293,28 +272,15 @@ class CreateEntity extends basecommand_1.BaseCommand {
|
|
|
293
272
|
}
|
|
294
273
|
}
|
|
295
274
|
exports.default = CreateEntity;
|
|
296
|
-
function
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
created.push(result.value);
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
failed.push({ input: inputs[index], error: (0, common_1.sdkErrorMessage)(result.reason) });
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
return { created, failed };
|
|
308
|
-
}
|
|
309
|
-
exports.summarizeSettledCreates = summarizeSettledCreates;
|
|
310
|
-
async function createEntities(entityName, entities, routing = {}) {
|
|
275
|
+
async function createEntities(entityName, entities) {
|
|
276
|
+
const limit = (0, p_limit_1.default)(20);
|
|
277
|
+
const createdEntities = IS_DRY_RUN
|
|
278
|
+
? entities
|
|
279
|
+
: await Promise.allSettled(entities.map(async (e) => limit(() => createEntity(entityName, e))));
|
|
311
280
|
if (IS_DRY_RUN) {
|
|
312
|
-
console.
|
|
313
|
-
return { created: entities, failed: [] };
|
|
281
|
+
console.log(`Dry run mode: not creating entities, but simulating creation for ${entityName}`);
|
|
314
282
|
}
|
|
315
|
-
|
|
316
|
-
const settled = await Promise.allSettled(entities.map(async (e) => limit(() => createEntity(entityName, e, routing))));
|
|
317
|
-
return summarizeSettledCreates(entities, settled);
|
|
283
|
+
return createdEntities;
|
|
318
284
|
}
|
|
319
285
|
async function buildEntitiesToCreate(entityTypePath, entities, propertySpecificationBySlug) {
|
|
320
286
|
let type = await (0, types_3.getTypeByPath)(entityTypePath);
|
|
@@ -337,7 +303,7 @@ async function buildEntitiesToCreate(entityTypePath, entities, propertySpecifica
|
|
|
337
303
|
await Promise.all(populatedEntities.map(async () => limit(() => throwIfEntityIsInvalid)));
|
|
338
304
|
// Skip system value generation unless -g flag is set (generateValues mode)
|
|
339
305
|
if (!SHOULD_GENERATE_MISSING_VALUES) {
|
|
340
|
-
console.
|
|
306
|
+
console.log('Using only specified properties. Use --generate-values to auto-generate missing values.');
|
|
341
307
|
return populatedEntities;
|
|
342
308
|
}
|
|
343
309
|
// Add system values if needed
|
|
@@ -346,13 +312,13 @@ async function buildEntitiesToCreate(entityTypePath, entities, propertySpecifica
|
|
|
346
312
|
for (const { slug, findValidValuesFn, applyValueToEntityFn } of valueFinderApplierForEntity) {
|
|
347
313
|
// If the property is already specified in command-line args, skip it
|
|
348
314
|
if (propertySpecificationBySlug?.has(slug)) {
|
|
349
|
-
console.
|
|
315
|
+
console.log(`Skipping property ${slug} because it is already specified.`);
|
|
350
316
|
continue;
|
|
351
317
|
}
|
|
352
318
|
// If all entities already have this property, skip finding values
|
|
353
319
|
const allEntitiesHaveProperty = populatedEntities.every((entity) => entity[slug] !== undefined && entity[slug] !== null);
|
|
354
320
|
if (allEntitiesHaveProperty) {
|
|
355
|
-
console.
|
|
321
|
+
console.log(`Skipping property ${slug} because all entities already have this value.`);
|
|
356
322
|
continue;
|
|
357
323
|
}
|
|
358
324
|
const values = await findValidValuesFn(populatedEntities, entities.length);
|
|
@@ -366,16 +332,15 @@ async function buildEntitiesToCreate(entityTypePath, entities, propertySpecifica
|
|
|
366
332
|
return populatedEntities;
|
|
367
333
|
}
|
|
368
334
|
function createEntityWithPopulatedValues(type, typeReferencesCache, objectReferencesCache, propertySpecificationBySlug) {
|
|
369
|
-
const
|
|
370
|
-
const roles = rolesValue === undefined ? undefined : [].concat(rolesValue);
|
|
335
|
+
const roles = propertySpecificationBySlug?.get('roles');
|
|
371
336
|
const entity = SHOULD_GENERATE_MISSING_VALUES
|
|
372
337
|
? pickRandomPropertyValues(type, objectReferencesCache, typeReferencesCache, roles)
|
|
373
338
|
: {};
|
|
374
339
|
// Handle property specifications
|
|
375
340
|
for (const [propertySlug, specifiedValue] of propertySpecificationBySlug.entries()) {
|
|
376
341
|
const correspondingProperty = type.typeProperties.find((prop) => getPropertySlug(prop) === propertySlug);
|
|
377
|
-
if (specifiedValue
|
|
378
|
-
|
|
342
|
+
if (!specifiedValue) {
|
|
343
|
+
throw new Error(`Value for property ${propertySlug} is required`);
|
|
379
344
|
}
|
|
380
345
|
entity[propertySlug] = castValueToPropertyType(specifiedValue, correspondingProperty?.propertyType || types_1.PropertyType.String);
|
|
381
346
|
}
|
|
@@ -383,16 +348,6 @@ function createEntityWithPopulatedValues(type, typeReferencesCache, objectRefere
|
|
|
383
348
|
if (SHOULD_USE_READABLE_IDS) {
|
|
384
349
|
entity.specifiedId = generateRandomReadableString();
|
|
385
350
|
}
|
|
386
|
-
// roles is a multi-value system property with no type property to drive
|
|
387
|
-
// coercion; a single value still has to reach the API as an array
|
|
388
|
-
if (typeof entity.roles === 'string') {
|
|
389
|
-
if (entity.roles.includes(',')) {
|
|
390
|
-
console.error(`roles value "${entity.roles}" contains a comma and is treated as one literal value. To pass several roles, repeat the key: roles=${entity.roles
|
|
391
|
-
.split(',')
|
|
392
|
-
.join(' roles=')}`);
|
|
393
|
-
}
|
|
394
|
-
entity.roles = [entity.roles];
|
|
395
|
-
}
|
|
396
351
|
// Support specifiedId
|
|
397
352
|
if (propertySpecificationBySlug?.has('specifiedId')) {
|
|
398
353
|
const specifiedId = propertySpecificationBySlug.get('specifiedId');
|
|
@@ -524,9 +479,6 @@ function generateRandomDateString() {
|
|
|
524
479
|
return new Date().toISOString();
|
|
525
480
|
}
|
|
526
481
|
function castValueToPropertyType(value, propertyType) {
|
|
527
|
-
if (Array.isArray(value) && propertyType !== types_1.PropertyType.MultiSelect) {
|
|
528
|
-
return value.map((element) => castValueToPropertyType(element, propertyType));
|
|
529
|
-
}
|
|
530
482
|
switch (propertyType) {
|
|
531
483
|
case types_1.PropertyType.Boolean:
|
|
532
484
|
return value.toString().toLowerCase() === 'true';
|
|
@@ -538,35 +490,16 @@ function castValueToPropertyType(value, propertyType) {
|
|
|
538
490
|
return numValue;
|
|
539
491
|
case types_1.PropertyType.Date:
|
|
540
492
|
return new Date(value.toString()).toISOString();
|
|
541
|
-
case types_1.PropertyType.MultiSelect:
|
|
542
|
-
if (Array.isArray(value)) {
|
|
543
|
-
return value;
|
|
544
|
-
}
|
|
545
|
-
// the old comma syntax parses as one literal value; warn instead of guessing at a split
|
|
546
|
-
if (typeof value === 'string' && value.includes(',')) {
|
|
547
|
-
console.error(`Value "${value}" for a multi-value property contains a comma and is treated as one literal value. To pass several values, repeat the key: slug=${value
|
|
548
|
-
.split(',')
|
|
549
|
-
.join(' slug=')}`);
|
|
550
|
-
}
|
|
551
|
-
return [value];
|
|
552
493
|
default:
|
|
553
494
|
return value; // For string and other types, return as is
|
|
554
495
|
}
|
|
555
496
|
}
|
|
556
|
-
|
|
557
|
-
async function createEntity(entityName, entity, routing = {}) {
|
|
497
|
+
async function createEntity(entityName, entity) {
|
|
558
498
|
const client = new sdk_1.Entities();
|
|
559
499
|
const skipHydrateRelationships = SHOULD_SKIP_HYDRATE_RELATIONSHIPS;
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
const response = await client.create({
|
|
564
|
-
entityName,
|
|
565
|
-
object: entity,
|
|
566
|
-
skipHydrateRelationships,
|
|
567
|
-
suffix,
|
|
568
|
-
apiVersion,
|
|
569
|
-
});
|
|
500
|
+
if (entityName === 'assortment-item')
|
|
501
|
+
return (0, entities_1.createAssortmentItem)(entity, { skipHydrateRelationships }); // special case
|
|
502
|
+
const response = await client.create({ entityName, object: entity, skipHydrateRelationships });
|
|
570
503
|
return response;
|
|
571
504
|
}
|
|
572
505
|
function getReferencedObjectPaths(type) {
|
|
@@ -270,8 +270,8 @@ describe('Entity Creation E2E Happy Path', () => {
|
|
|
270
270
|
expect(result.get('quantity')).toBe('10');
|
|
271
271
|
expect(result.get('isActive')).toBe('true');
|
|
272
272
|
});
|
|
273
|
-
it('should
|
|
274
|
-
const specs = ['roles=option
|
|
273
|
+
it('should handle roles as comma-separated array', () => {
|
|
274
|
+
const specs = ['roles=option,family', 'name=Test'];
|
|
275
275
|
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
276
276
|
expect(result.get('roles')).toEqual(['option', 'family']);
|
|
277
277
|
expect(result.get('name')).toBe('Test');
|
|
@@ -333,7 +333,7 @@ describe('Entity Creation E2E Happy Path', () => {
|
|
|
333
333
|
const propertySpecs = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)([
|
|
334
334
|
'roles=option',
|
|
335
335
|
]);
|
|
336
|
-
const roles =
|
|
336
|
+
const roles = propertySpecs.get('roles');
|
|
337
337
|
// Test that property level matching works with specified roles
|
|
338
338
|
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OPTION, roles[0])).toBe(true);
|
|
339
339
|
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.FAMILY, roles[0])).toBe(false);
|
|
@@ -514,32 +514,3 @@ describe('Entity Creation E2E Happy Path', () => {
|
|
|
514
514
|
});
|
|
515
515
|
});
|
|
516
516
|
});
|
|
517
|
-
describe('castValueToPropertyType array coercion', () => {
|
|
518
|
-
it('should coerce a single value on a multi-value property to a one-element array', () => {
|
|
519
|
-
expect((0, create_1.castValueToPropertyType)('option', types_1.PropertyType.MultiSelect)).toEqual(['option']);
|
|
520
|
-
});
|
|
521
|
-
it('should pass arrays through on multi-value properties', () => {
|
|
522
|
-
expect((0, create_1.castValueToPropertyType)(['option', 'family'], types_1.PropertyType.MultiSelect)).toEqual([
|
|
523
|
-
'option',
|
|
524
|
-
'family',
|
|
525
|
-
]);
|
|
526
|
-
});
|
|
527
|
-
it('should keep a comma value literal on a multi-value property and warn with the repeated-key form', () => {
|
|
528
|
-
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
529
|
-
expect((0, create_1.castValueToPropertyType)('option,family', types_1.PropertyType.MultiSelect)).toEqual([
|
|
530
|
-
'option,family',
|
|
531
|
-
]);
|
|
532
|
-
expect(consoleError).toHaveBeenCalledWith(expect.stringContaining('slug=option slug=family'));
|
|
533
|
-
consoleError.mockRestore();
|
|
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
|
-
});
|
|
539
|
-
it('should keep commas literal on string properties without warning', () => {
|
|
540
|
-
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
541
|
-
expect((0, create_1.castValueToPropertyType)('my,name', types_1.PropertyType.String)).toBe('my,name');
|
|
542
|
-
expect(consoleError).not.toHaveBeenCalled();
|
|
543
|
-
consoleError.mockRestore();
|
|
544
|
-
});
|
|
545
|
-
});
|