@contrail/cli 3.6.0-alpha.f45f126 → 3.7.0-alpha.1c66a91
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 +207 -3
- package/dist/api/types.d.ts +35 -0
- package/dist/api/types.js +49 -1
- package/dist/auth/login.d.ts +1 -1
- package/dist/auth/login.js +46 -29
- package/dist/auth/login.spec.js +31 -15
- package/dist/auth/sign-in-error.d.ts +7 -0
- package/dist/auth/sign-in-error.js +24 -0
- package/dist/auth/sign-in-error.spec.d.ts +1 -0
- package/dist/auth/sign-in-error.spec.js +22 -0
- package/dist/auth/sso.d.ts +5 -3
- package/dist/auth/sso.js +34 -18
- package/dist/auth/sso.spec.js +63 -10
- package/dist/basecommand.d.ts +3 -0
- package/dist/basecommand.js +10 -3
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/app/publish.js +1 -1
- package/dist/commands/app/version/prerelease.d.ts +11 -0
- package/dist/commands/app/version/prerelease.js +32 -0
- package/dist/commands/entities/create.d.ts +49 -0
- package/dist/commands/entities/create.js +618 -0
- package/dist/commands/entities/create.spec.d.ts +1 -0
- package/dist/commands/entities/create.spec.js +581 -0
- package/dist/commands/entities/delete.d.ts +20 -0
- package/dist/commands/entities/delete.js +146 -0
- package/dist/commands/entities/get.d.ts +25 -0
- package/dist/commands/entities/get.js +298 -0
- package/dist/commands/entities/grammar.spec.d.ts +1 -0
- package/dist/commands/entities/grammar.spec.js +79 -0
- package/dist/commands/entities/output.spec.d.ts +1 -0
- package/dist/commands/entities/output.spec.js +72 -0
- package/dist/commands/entities/update.d.ts +32 -0
- package/dist/commands/entities/update.js +212 -0
- package/dist/commands/login.js +1 -1
- package/dist/commands/webhooks/delete.js +2 -3
- package/dist/common.d.ts +10 -1
- package/dist/common.js +37 -1
- package/dist/common.spec.d.ts +1 -0
- package/dist/common.spec.js +40 -0
- package/dist/helpers/app/app-config-validators.js +4 -4
- package/dist/helpers/app/app-config-validators.spec.js +36 -0
- package/dist/helpers/app/app-deployer.d.ts +1 -0
- package/dist/helpers/app/app-deployer.js +34 -0
- package/dist/helpers/app/upgrade-version.d.ts +3 -1
- package/dist/helpers/app/upgrade-version.js +7 -8
- package/dist/helpers/app/upgrade-version.spec.js +15 -0
- package/dist/helpers/config/config.d.ts +3 -3
- package/dist/helpers/config/config.js +3 -3
- package/dist/helpers/entities/assortment-items.d.ts +11 -0
- package/dist/helpers/entities/assortment-items.js +76 -0
- package/dist/helpers/entities/batchFetch.d.ts +11 -0
- package/dist/helpers/entities/batchFetch.js +50 -0
- package/dist/helpers/entities/index.d.ts +3 -0
- package/dist/helpers/entities/index.js +6 -0
- package/dist/helpers/entities/items.d.ts +6 -0
- package/dist/helpers/entities/items.js +60 -0
- package/dist/helpers/entities/items.spec.d.ts +1 -0
- package/dist/helpers/entities/items.spec.js +19 -0
- package/dist/helpers/entities/project-items.d.ts +2 -0
- package/dist/helpers/entities/project-items.js +44 -0
- package/dist/helpers/file-helpers.d.ts +1 -0
- package/dist/helpers/file-helpers.js +20 -3
- package/dist/helpers/propertySpecifications/dateRanges.d.ts +34 -0
- package/dist/helpers/propertySpecifications/dateRanges.js +91 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.js +97 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +39 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.js +102 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +387 -0
- package/dist/helpers/propertySpecifications/propertyValues.d.ts +31 -0
- package/dist/helpers/propertySpecifications/propertyValues.js +132 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.js +156 -0
- package/dist/logger.js +4 -1
- package/dist/logger.spec.d.ts +1 -0
- package/dist/logger.spec.js +12 -0
- package/node_modules/@contrail/entity-compare/package.json +6 -3
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
- package/node_modules/@contrail/loader/lib/constants.js +1 -9
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +1 -4
- package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
- package/node_modules/@contrail/sdk/lib/config/config.d.ts +3 -0
- package/node_modules/@contrail/sdk/lib/config/config.js +13 -7
- package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
- package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
- package/node_modules/@contrail/sdk/lib/entities/entities.client.js +3 -1
- package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
- package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/index.js +1 -0
- package/node_modules/@contrail/sdk/package.json +1 -1
- package/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
- package/oclif.manifest.json +492 -2
- package/package.json +6 -12
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.summarizeSettledUpdates = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const p_limit_1 = tslib_1.__importDefault(require("p-limit"));
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const basecommand_1 = require("../../basecommand");
|
|
8
|
+
const sdk_1 = require("@contrail/sdk");
|
|
9
|
+
const login_1 = require("../../auth/login");
|
|
10
|
+
const common_1 = require("../../common");
|
|
11
|
+
const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
|
|
12
|
+
const file_helpers_1 = require("../../helpers/file-helpers");
|
|
13
|
+
const propertyValues_1 = require("../../helpers/propertySpecifications/propertyValues");
|
|
14
|
+
const types_1 = require("../../api/types");
|
|
15
|
+
class UpdateEntity extends basecommand_1.BaseCommand {
|
|
16
|
+
static description = 'Update an entity';
|
|
17
|
+
static examples = [
|
|
18
|
+
'contrail entities update color 123 -- name=obsidian hex=000000',
|
|
19
|
+
'contrail entities update item id1 id2 id3 -- colorName=obsidian # apply the same change to several entities',
|
|
20
|
+
'contrail entities update color 123 -- federatedId= name=\'""\' # Unset federatedId, set name to empty string',
|
|
21
|
+
];
|
|
22
|
+
static flags = {
|
|
23
|
+
...basecommand_1.BaseCommand.baseFlags,
|
|
24
|
+
skipHydrateRelationships: core_1.Flags.boolean({
|
|
25
|
+
char: 'S',
|
|
26
|
+
description: 'Skip hydrating relationships when updating the entity',
|
|
27
|
+
required: false,
|
|
28
|
+
default: false,
|
|
29
|
+
}),
|
|
30
|
+
dryRun: core_1.Flags.boolean({
|
|
31
|
+
char: 'd',
|
|
32
|
+
description: 'If true, does not update the entities but simulates the update',
|
|
33
|
+
required: false,
|
|
34
|
+
default: false,
|
|
35
|
+
}),
|
|
36
|
+
inputFile: core_1.Flags.string({
|
|
37
|
+
char: 'i',
|
|
38
|
+
description: 'A file with a JSON array of {id, ...} objects; each object is one entity to update.',
|
|
39
|
+
required: false,
|
|
40
|
+
}),
|
|
41
|
+
suffix: core_1.Flags.string({
|
|
42
|
+
description: 'Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets /<entities>/synchronous)',
|
|
43
|
+
required: false,
|
|
44
|
+
}),
|
|
45
|
+
apiVersion: core_1.Flags.string({
|
|
46
|
+
description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
|
|
47
|
+
options: ['1', '2'],
|
|
48
|
+
required: false,
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
static args = {
|
|
52
|
+
entityName: core_1.Args.string({
|
|
53
|
+
description: 'The name of the entity type to update (type paths are not supported)',
|
|
54
|
+
required: true,
|
|
55
|
+
}),
|
|
56
|
+
ids: core_1.Args.string({
|
|
57
|
+
description: 'One or more entity ids to update',
|
|
58
|
+
required: false,
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
static strict = false;
|
|
62
|
+
async init() {
|
|
63
|
+
(0, common_1.routeConsoleLogToStderr)();
|
|
64
|
+
await super.init();
|
|
65
|
+
}
|
|
66
|
+
async run() {
|
|
67
|
+
await (0, login_1.authUser)();
|
|
68
|
+
const { args, argv } = await this.parse(UpdateEntity);
|
|
69
|
+
const { entityName } = args;
|
|
70
|
+
const idParsedAsFlag = (0, common_1.findIdParsedAsFlag)(process.argv, 'il');
|
|
71
|
+
if (idParsedAsFlag) {
|
|
72
|
+
this.error(`${idParsedAsFlag} starts with a hyphen, so it is read as flags rather than an id. Pass it after -- instead, or use an input file (-i).`);
|
|
73
|
+
}
|
|
74
|
+
const { dryRun: isDryRun, inputFile: inputFilename, skipHydrateRelationships, suffix, apiVersion, } = this.flags;
|
|
75
|
+
if (entityName.includes(':')) {
|
|
76
|
+
this.error(`update takes an entity name, not a type path. Use: contrail entities update ${entityName.split(':')[0]} <ID...>`);
|
|
77
|
+
}
|
|
78
|
+
const { ids: positionalIds, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(argv.slice(1));
|
|
79
|
+
const propertySpec = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
80
|
+
if (propertySpec.has('id') || propertySpec.has('ids')) {
|
|
81
|
+
this.error('The -- payload is values to write. Pass ids positionally: contrail entities update <entityName> <ID...> -- slug=value');
|
|
82
|
+
}
|
|
83
|
+
if (inputFilename && positionalIds.length > 0) {
|
|
84
|
+
this.error('You cannot use --inputFile and positional ids together. Please specify one or the other.');
|
|
85
|
+
}
|
|
86
|
+
if (!inputFilename && positionalIds.length === 0) {
|
|
87
|
+
this.error('You must provide one or more ids or an input file (-i) of entities to update.');
|
|
88
|
+
}
|
|
89
|
+
if (positionalIds.length > 0 && propertySpec.size === 0) {
|
|
90
|
+
this.error('Nothing to update: pass values to write after --, e.g. -- name=jet');
|
|
91
|
+
}
|
|
92
|
+
const entitiesToUpdate = inputFilename
|
|
93
|
+
? (0, file_helpers_1.parseFileAsJsonArray)(inputFilename)
|
|
94
|
+
: positionalIds.map((id) => ({ id }));
|
|
95
|
+
const skipped = entitiesToUpdate.filter(({ id }) => !id).length;
|
|
96
|
+
const entitiesWithId = entitiesToUpdate.filter(({ id }) => id);
|
|
97
|
+
if (Array.isArray(propertySpec.get('typePath'))) {
|
|
98
|
+
this.error('typePath takes a single value. Repeat the key only for multi-value properties.');
|
|
99
|
+
}
|
|
100
|
+
// cast against each record's own subtype: the API converts numeric strings itself
|
|
101
|
+
// but rejects boolean ones, so an uncast isArchived=false comes back as a 400
|
|
102
|
+
const typePropertiesById = await resolvePropertiesByEntityId(entityName, entitiesWithId.map(({ id }) => id));
|
|
103
|
+
// JSON.stringify drops undefined keys, so an unset has to travel as an explicit null
|
|
104
|
+
const unsetValues = Object.fromEntries([...propertySpec.keys()]
|
|
105
|
+
.filter((slug) => propertySpec.get(slug) === undefined)
|
|
106
|
+
.map((slug) => [slug, null]));
|
|
107
|
+
const specifiedValues = new Map([...propertySpec.entries()].filter(([, value]) => value !== undefined));
|
|
108
|
+
async function updateEntity(entity) {
|
|
109
|
+
const id = entity.id;
|
|
110
|
+
const newEntityState = {
|
|
111
|
+
...entity,
|
|
112
|
+
...(0, propertyValues_1.castValuesToPropertyTypes)(specifiedValues, typePropertiesById.get(id)),
|
|
113
|
+
...unsetValues,
|
|
114
|
+
};
|
|
115
|
+
return isDryRun
|
|
116
|
+
? mockUpdateById(entityName, id, newEntityState, { skipHydrateRelationships })
|
|
117
|
+
: updateEntityById(entityName, id, newEntityState, {
|
|
118
|
+
skipHydrateRelationships,
|
|
119
|
+
suffix,
|
|
120
|
+
apiVersion: apiVersion,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const limit = (0, p_limit_1.default)(20);
|
|
125
|
+
const settled = await Promise.allSettled(entitiesWithId.map((entity) => limit(() => updateEntity(entity))));
|
|
126
|
+
const summary = summarizeSettledUpdates(entitiesWithId, settled, skipped);
|
|
127
|
+
if (isDryRun) {
|
|
128
|
+
console.error('Dry run. Update skipped. Changes would be:');
|
|
129
|
+
}
|
|
130
|
+
this.log(JSON.stringify(summary, null, 2));
|
|
131
|
+
if (summary.failed.length > 0) {
|
|
132
|
+
console.error(`${summary.failed.length} of ${entitiesWithId.length} updates failed.`);
|
|
133
|
+
process.exitCode = 1;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
this.error(`Error updating entities: ${e.message}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.default = UpdateEntity;
|
|
142
|
+
// The ids criterion travels in the URL, which the gateway rejects somewhere past
|
|
143
|
+
// 5k characters, so the lookup goes out in chunks.
|
|
144
|
+
const ID_LOOKUP_CHUNK_SIZE = 250;
|
|
145
|
+
async function resolvePropertiesByEntityId(entityName, ids) {
|
|
146
|
+
const rootType = await (0, types_1.getTypeByPath)(entityName).catch(() => undefined);
|
|
147
|
+
const typePathById = await fetchTypePathsByIds(entityName, ids);
|
|
148
|
+
const distinctPaths = [...new Set([...typePathById.values()])];
|
|
149
|
+
const propertiesByPath = new Map();
|
|
150
|
+
await Promise.all(distinctPaths.map(async (path) => {
|
|
151
|
+
const type = await (0, types_1.getTypeByPath)(path).catch(() => undefined);
|
|
152
|
+
propertiesByPath.set(path, type?.typeProperties ?? rootType?.typeProperties);
|
|
153
|
+
}));
|
|
154
|
+
// an id the lookup did not return falls back to the root type; the write reports its own 404
|
|
155
|
+
return new Map(ids.map((id) => [id, propertiesByPath.get(typePathById.get(id)) ?? rootType?.typeProperties]));
|
|
156
|
+
}
|
|
157
|
+
async function fetchTypePathsByIds(entityName, ids) {
|
|
158
|
+
const client = new sdk_1.Entities();
|
|
159
|
+
const chunks = [];
|
|
160
|
+
for (let i = 0; i < ids.length; i += ID_LOOKUP_CHUNK_SIZE) {
|
|
161
|
+
chunks.push(ids.slice(i, i + ID_LOOKUP_CHUNK_SIZE));
|
|
162
|
+
}
|
|
163
|
+
const pages = await Promise.all(chunks.map((chunk) => client
|
|
164
|
+
.get({
|
|
165
|
+
entityName,
|
|
166
|
+
criteria: { ids: chunk },
|
|
167
|
+
customParams: { propertySlugs: 'id,typePath' },
|
|
168
|
+
})
|
|
169
|
+
.catch(() => [])));
|
|
170
|
+
return new Map(pages
|
|
171
|
+
.flat()
|
|
172
|
+
.filter((entity) => entity?.id && entity?.typePath)
|
|
173
|
+
.map((entity) => [entity.id, entity.typePath]));
|
|
174
|
+
}
|
|
175
|
+
function summarizeSettledUpdates(inputs, settled, skipped) {
|
|
176
|
+
const updated = [];
|
|
177
|
+
const failed = [];
|
|
178
|
+
settled.forEach((result, index) => {
|
|
179
|
+
if (result.status === 'fulfilled') {
|
|
180
|
+
updated.push(result.value);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
failed.push({
|
|
184
|
+
id: inputs[index].id,
|
|
185
|
+
error: (0, common_1.sdkErrorMessage)(result.reason),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
return { updated, failed, skipped };
|
|
190
|
+
}
|
|
191
|
+
exports.summarizeSettledUpdates = summarizeSettledUpdates;
|
|
192
|
+
async function updateEntityById(entityName, id, changes, options = {}) {
|
|
193
|
+
const client = new sdk_1.Entities();
|
|
194
|
+
const { skipHydrateRelationships, suffix, apiVersion } = options;
|
|
195
|
+
return client.update({
|
|
196
|
+
entityName,
|
|
197
|
+
id,
|
|
198
|
+
object: changes,
|
|
199
|
+
skipHydrateRelationships,
|
|
200
|
+
suffix,
|
|
201
|
+
apiVersion,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
async function mockUpdateById(entityName, id, changes, options = {}) {
|
|
205
|
+
const client = new sdk_1.Entities();
|
|
206
|
+
const { skipHydrateRelationships } = options;
|
|
207
|
+
const entity = await client.get({ entityName, id, skipHydrateRelationships });
|
|
208
|
+
if (!entity) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
return { ...entity, ...changes };
|
|
212
|
+
}
|
package/dist/commands/login.js
CHANGED
|
@@ -18,7 +18,7 @@ class Login extends basecommand_1.BaseCommand {
|
|
|
18
18
|
}),
|
|
19
19
|
};
|
|
20
20
|
async run() {
|
|
21
|
-
const context = await (0, login_1.signIn)({
|
|
21
|
+
const context = await (0, login_1.signIn)({ shouldOpenBrowser: this.flags.browser });
|
|
22
22
|
logger_1.default.info(`Signed in to ${context.orgSlug}.`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -6,7 +6,6 @@ const login_1 = require("../../auth/login");
|
|
|
6
6
|
const webhooks_1 = require("../../api/webhooks");
|
|
7
7
|
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
8
8
|
const basecommand_1 = require("../../basecommand");
|
|
9
|
-
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
10
9
|
class DeleteWebhooks extends basecommand_1.BaseCommand {
|
|
11
10
|
static description = 'Delete an existing webhook. To delete a single webhook, pass its ID. To delete multiple webhooks, do not pass a value for the ID, and select multiple using the interactive selector';
|
|
12
11
|
static examples = [
|
|
@@ -43,10 +42,10 @@ class DeleteWebhooks extends basecommand_1.BaseCommand {
|
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
if (this.flags.json) {
|
|
46
|
-
|
|
45
|
+
this.log(JSON.stringify(deletedWebhooks, null, 2));
|
|
47
46
|
}
|
|
48
47
|
else {
|
|
49
|
-
|
|
48
|
+
this.log(deletedWebhooks.map((x) => x.id).join('\n'));
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
}
|
package/dist/common.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
export declare function getSeparatorByPlatform(): string;
|
|
3
3
|
export declare function delay(ms: number): Promise<NodeJS.Timeout>;
|
|
4
|
-
export declare function removeSlash(string:
|
|
4
|
+
export declare function removeSlash(string: string): string;
|
|
5
|
+
export declare function routeConsoleLogToStderr(): void;
|
|
6
|
+
export declare function sdkErrorMessage(reason: any): string;
|
|
7
|
+
export declare const promptOnStderr: any;
|
|
8
|
+
/**
|
|
9
|
+
* An id beginning with a hyphen is consumed as flags before a command sees it,
|
|
10
|
+
* which can silently switch on a boolean flag and shift the remaining arguments.
|
|
11
|
+
* Platform ids are long enough to tell apart from a cluster of short flags.
|
|
12
|
+
*/
|
|
13
|
+
export declare function findIdParsedAsFlag(argv: string[], shortFlagsTakingValues?: string): string | undefined;
|
package/dist/common.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeSlash = exports.delay = exports.getSeparatorByPlatform = void 0;
|
|
3
|
+
exports.findIdParsedAsFlag = exports.promptOnStderr = exports.sdkErrorMessage = exports.routeConsoleLogToStderr = exports.removeSlash = exports.delay = exports.getSeparatorByPlatform = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
4
6
|
function getSeparatorByPlatform() {
|
|
5
7
|
const isWin = process.platform === 'win32';
|
|
6
8
|
const separator = isWin ? '\\' : '/';
|
|
@@ -16,3 +18,37 @@ function removeSlash(string) {
|
|
|
16
18
|
return string.replace(re, '-');
|
|
17
19
|
}
|
|
18
20
|
exports.removeSlash = removeSlash;
|
|
21
|
+
// The SDK and auth flow print request logs and token messages via bare
|
|
22
|
+
// console.log. A command whose stdout is a data contract must route those to
|
|
23
|
+
// stderr before any of that code runs.
|
|
24
|
+
function routeConsoleLogToStderr() {
|
|
25
|
+
console.log = (...args) => console.error(...args);
|
|
26
|
+
}
|
|
27
|
+
exports.routeConsoleLogToStderr = routeConsoleLogToStderr;
|
|
28
|
+
// SDK errors can carry an empty message with the response body in details
|
|
29
|
+
function sdkErrorMessage(reason) {
|
|
30
|
+
return reason?.message || reason?.details || String(reason);
|
|
31
|
+
}
|
|
32
|
+
exports.sdkErrorMessage = sdkErrorMessage;
|
|
33
|
+
// inquirer renders prompt UI to its output stream directly, bypassing the
|
|
34
|
+
// console.log redirect; stdout must stay data-only
|
|
35
|
+
exports.promptOnStderr = inquirer_1.default.createPromptModule({ output: process.stderr });
|
|
36
|
+
/**
|
|
37
|
+
* An id beginning with a hyphen is consumed as flags before a command sees it,
|
|
38
|
+
* which can silently switch on a boolean flag and shift the remaining arguments.
|
|
39
|
+
* Platform ids are long enough to tell apart from a cluster of short flags.
|
|
40
|
+
*/
|
|
41
|
+
function findIdParsedAsFlag(argv, shortFlagsTakingValues = '') {
|
|
42
|
+
const separator = argv.indexOf('--');
|
|
43
|
+
const beforeSeparator = separator === -1 ? argv : argv.slice(0, separator);
|
|
44
|
+
return beforeSeparator.find((token) => {
|
|
45
|
+
// a long flag could never have been a short-flag cluster, and oclif rejects
|
|
46
|
+
// an unknown one itself
|
|
47
|
+
if (token.startsWith('--') || !/^-[A-Za-z0-9_-]{8,}$/.test(token)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
// oclif reads -rvalue as a flag with an attached value
|
|
51
|
+
return !shortFlagsTakingValues.includes(token[1]);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.findIdParsedAsFlag = findIdParsedAsFlag;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("./common");
|
|
4
|
+
describe('findIdParsedAsFlag', () => {
|
|
5
|
+
const GET_SHORT_FLAGS_WITH_VALUES = 'loprst';
|
|
6
|
+
it('should find an id that a short flag cluster would swallow', () => {
|
|
7
|
+
expect((0, common_1.findIdParsedAsFlag)(['delete', 'item', '-d3YBdV-d8PXI88U'])).toBe('-d3YBdV-d8PXI88U');
|
|
8
|
+
});
|
|
9
|
+
it('should ignore long flags, whatever their length', () => {
|
|
10
|
+
const longFlags = [
|
|
11
|
+
'--paginated',
|
|
12
|
+
'--inputFile',
|
|
13
|
+
'--outputFile',
|
|
14
|
+
'--relations',
|
|
15
|
+
'--propertySlugs',
|
|
16
|
+
'--skipHydrateRelationships',
|
|
17
|
+
'--alwaysConfirmEnv',
|
|
18
|
+
'--apiVersion',
|
|
19
|
+
'--logLevel',
|
|
20
|
+
'--dryRun',
|
|
21
|
+
'--suffix',
|
|
22
|
+
];
|
|
23
|
+
longFlags.forEach((flag) => {
|
|
24
|
+
expect((0, common_1.findIdParsedAsFlag)(['get', 'color', flag])).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('should ignore a short flag carrying an attached value', () => {
|
|
28
|
+
expect((0, common_1.findIdParsedAsFlag)(['get', 'color', '-rprojectItems'], GET_SHORT_FLAGS_WITH_VALUES)).toBeUndefined();
|
|
29
|
+
expect((0, common_1.findIdParsedAsFlag)(['get', 'color', '-ooutput12345'], GET_SHORT_FLAGS_WITH_VALUES)).toBeUndefined();
|
|
30
|
+
});
|
|
31
|
+
it('should still flag an id whose first character is not a value-taking flag', () => {
|
|
32
|
+
expect((0, common_1.findIdParsedAsFlag)(['get', 'color', '-d3YBdV-d8PX'], GET_SHORT_FLAGS_WITH_VALUES)).toBe('-d3YBdV-d8PX');
|
|
33
|
+
});
|
|
34
|
+
it('should ignore everything after the -- separator', () => {
|
|
35
|
+
expect((0, common_1.findIdParsedAsFlag)(['get', 'color', '--', '-nJkS_UQjgRHrENJ'])).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
it('should ignore short flag clusters and ordinary arguments', () => {
|
|
38
|
+
expect((0, common_1.findIdParsedAsFlag)(['get', 'color', '-dS', '-t', '5', 'someId'])).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateAccessGrants = exports.visibilityValidator = exports.appVersionValidator = exports.validateAppConfig = exports.ERROR_MESSAGES = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const semver_1 = tslib_1.__importDefault(require("semver"));
|
|
5
6
|
const interfaces_1 = require("../../interfaces");
|
|
6
7
|
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
7
8
|
const VALIDATORS = [appVersionValidator, visibilityValidator, validateAccessGrants];
|
|
8
9
|
exports.ERROR_MESSAGES = {
|
|
9
|
-
missingVersionField: 'Missing "version" field". Semantic App Version looks like "1.0.0". Use "contrail app version [patch|minor|major]" to update the app version.',
|
|
10
|
+
missingVersionField: 'Missing "version" field". Semantic App Version looks like "1.0.0". Use "contrail app version [patch|minor|major|prerelease]" to update the app version.',
|
|
10
11
|
invalidVersionField: '"version" field is not a string. Expecting a version like "1.0.0". Manually update the "version" field to be a string in the app.yml file.',
|
|
11
|
-
invalidAppVersion: 'Invalid app version. Semantic App Version looks like "1.0.0". Use "contrail app version [patch|minor|major]" to update the app version.',
|
|
12
|
+
invalidAppVersion: 'Invalid app version. Semantic App Version looks like "1.0.0", or "1.0.0-alpha.1" for a pre-release. Use "contrail app version [patch|minor|major|prerelease]" to update the app version.',
|
|
12
13
|
accessGrantsArray: 'accessGrants must be an array.',
|
|
13
14
|
invalidOrgSlug: 'Invalid or missing orgSlug in one of the accessGrants objects.',
|
|
14
15
|
emptyPermissionsArray: 'Permissions must be a non-empty array in one of the accessGrants objects.',
|
|
@@ -45,8 +46,7 @@ function appVersionValidator(appDeclaration) {
|
|
|
45
46
|
errors.push(exports.ERROR_MESSAGES.invalidVersionField);
|
|
46
47
|
return { errors, warnings };
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
-
if (parts.length !== 3) {
|
|
49
|
+
if (semver_1.default.valid(appDeclaration.version) !== appDeclaration.version.split('+')[0]) {
|
|
50
50
|
errors.push(exports.ERROR_MESSAGES.invalidAppVersion);
|
|
51
51
|
}
|
|
52
52
|
return { errors, warnings };
|
|
@@ -33,6 +33,42 @@ describe('appVersionValidator', () => {
|
|
|
33
33
|
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
34
34
|
expect(validationResult).toEqual(validResult);
|
|
35
35
|
});
|
|
36
|
+
it('should not return an error if app version is a pre-release', () => {
|
|
37
|
+
const appDeclaration = {
|
|
38
|
+
version: '1.4.0-alpha.1',
|
|
39
|
+
};
|
|
40
|
+
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
41
|
+
expect(validationResult).toEqual(validResult);
|
|
42
|
+
});
|
|
43
|
+
it('should not return an error if app version has build metadata', () => {
|
|
44
|
+
const appDeclaration = {
|
|
45
|
+
version: '1.4.0+build123',
|
|
46
|
+
};
|
|
47
|
+
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
48
|
+
expect(validationResult).toEqual(validResult);
|
|
49
|
+
});
|
|
50
|
+
it('should return an error if app version has a leading v', () => {
|
|
51
|
+
const appDeclaration = {
|
|
52
|
+
version: 'v1.4.0',
|
|
53
|
+
};
|
|
54
|
+
const expectedError = {
|
|
55
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidAppVersion],
|
|
56
|
+
warnings: [],
|
|
57
|
+
};
|
|
58
|
+
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
59
|
+
expect(validationResult).toEqual(expectedError);
|
|
60
|
+
});
|
|
61
|
+
it('should return an error if a version part is not a number', () => {
|
|
62
|
+
const appDeclaration = {
|
|
63
|
+
version: '1.0.x',
|
|
64
|
+
};
|
|
65
|
+
const expectedError = {
|
|
66
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidAppVersion],
|
|
67
|
+
warnings: [],
|
|
68
|
+
};
|
|
69
|
+
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
70
|
+
expect(validationResult).toEqual(expectedError);
|
|
71
|
+
});
|
|
36
72
|
it('should gracefully handle bad versions', () => {
|
|
37
73
|
const appDeclaration = {
|
|
38
74
|
version: '1',
|
|
@@ -7,6 +7,7 @@ export declare class AppDeployer {
|
|
|
7
7
|
getExistingApp(appDeclaration: AppDeclaration): Promise<App>;
|
|
8
8
|
private createNewApp;
|
|
9
9
|
updateExistingApp(appDeclaration: AppDeclaration, existingApp: any): Promise<App>;
|
|
10
|
+
private publishPrereleaseVersion;
|
|
10
11
|
remove(appDeclaration: AppDeclaration): Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
export declare function createNodePackage(appIdentifier: string, debug: boolean, dryRun: boolean): Promise<AppCodePackage>;
|
|
@@ -15,6 +15,7 @@ const child_process_1 = tslib_1.__importDefault(require("child_process"));
|
|
|
15
15
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
16
16
|
const extensions_deployer_1 = require("./extensions-deployer");
|
|
17
17
|
const metadata_extractor_1 = require("./metadata-extractor");
|
|
18
|
+
const semver_1 = tslib_1.__importDefault(require("semver"));
|
|
18
19
|
class AppDeployer {
|
|
19
20
|
debug;
|
|
20
21
|
dryRun;
|
|
@@ -29,6 +30,10 @@ class AppDeployer {
|
|
|
29
30
|
logger_1.default.info(`${chalk_1.default.yellow.bold('APP')} Creating new app.`);
|
|
30
31
|
app = await this.createNewApp(appDeclaration);
|
|
31
32
|
}
|
|
33
|
+
else if (semver_1.default.prerelease(appDeclaration.version)) {
|
|
34
|
+
logger_1.default.info(`${chalk_1.default.yellow.bold('APP')} Publishing pre-release version.`);
|
|
35
|
+
app = await this.publishPrereleaseVersion(appDeclaration, app);
|
|
36
|
+
}
|
|
32
37
|
else {
|
|
33
38
|
logger_1.default.info(`${chalk_1.default.yellow.bold('APP')} Updating existing app.`);
|
|
34
39
|
app = await this.updateExistingApp(appDeclaration, app);
|
|
@@ -146,6 +151,35 @@ class AppDeployer {
|
|
|
146
151
|
logger_1.default.info(`${chalk_1.default.yellow.bold('APP')} Updated app: ${app.name}`);
|
|
147
152
|
return app;
|
|
148
153
|
}
|
|
154
|
+
async publishPrereleaseVersion(appDeclaration, existingApp) {
|
|
155
|
+
const appCodePackage = await createNodePackage(appDeclaration.appIdentifier, this.debug, this.dryRun);
|
|
156
|
+
if (this.dryRun) {
|
|
157
|
+
logger_1.default.info('Dry run, not creating app version');
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
const appVersion = await new sdk_1.Entities().create({
|
|
161
|
+
entityName: 'app-version',
|
|
162
|
+
object: {
|
|
163
|
+
appId: existingApp.id,
|
|
164
|
+
semver: appDeclaration.version,
|
|
165
|
+
eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
|
|
166
|
+
configProperties: appDeclaration.appConfiguration
|
|
167
|
+
? app_template_parsers_1.ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration)
|
|
168
|
+
: undefined,
|
|
169
|
+
triggerKeyDefinitions: appDeclaration.triggers
|
|
170
|
+
? app_template_parsers_1.TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration)
|
|
171
|
+
: undefined,
|
|
172
|
+
externalLinks: appDeclaration.externalLinks
|
|
173
|
+
? app_template_parsers_1.ExternalLinkParser.validateAndGetExternalLinks(appDeclaration.externalLinks)
|
|
174
|
+
: [],
|
|
175
|
+
appCodePackageId: appCodePackage.id,
|
|
176
|
+
frameworkVersion: 2,
|
|
177
|
+
nodeRuntime: appDeclaration.nodeRuntime ?? existingApp.nodeRuntime,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
logger_1.default.info(`${chalk_1.default.yellow.bold('APP')} Published pre-release version: ${appVersion.semver}`);
|
|
181
|
+
return { ...existingApp, latestAppVersionId: appVersion.id };
|
|
182
|
+
}
|
|
149
183
|
async remove(appDeclaration) {
|
|
150
184
|
let app = await this.getExistingApp(appDeclaration);
|
|
151
185
|
if (app) {
|
|
@@ -3,7 +3,9 @@ import semver from 'semver';
|
|
|
3
3
|
* Upgrades a semantic version based on a specified release type.
|
|
4
4
|
*
|
|
5
5
|
* @param {string} currentVersion - The current semantic version string.
|
|
6
|
-
* @param {semver.ReleaseType} type - The type of release ('major', 'minor', 'patch').
|
|
6
|
+
* @param {semver.ReleaseType} type - The type of release ('major', 'minor', 'patch', 'prerelease').
|
|
7
|
+
* 'prerelease' starts an alpha (1.2.3 becomes 1.2.4-alpha.0) or bumps the existing pre-release tag
|
|
8
|
+
* (1.2.4-alpha.0 becomes 1.2.4-alpha.1).
|
|
7
9
|
* @returns {string} The upgraded semantic version.
|
|
8
10
|
* @throws {Error} If the provided currentVersion is not a valid semantic version.
|
|
9
11
|
*
|
|
@@ -7,7 +7,9 @@ const semver_1 = tslib_1.__importDefault(require("semver"));
|
|
|
7
7
|
* Upgrades a semantic version based on a specified release type.
|
|
8
8
|
*
|
|
9
9
|
* @param {string} currentVersion - The current semantic version string.
|
|
10
|
-
* @param {semver.ReleaseType} type - The type of release ('major', 'minor', 'patch').
|
|
10
|
+
* @param {semver.ReleaseType} type - The type of release ('major', 'minor', 'patch', 'prerelease').
|
|
11
|
+
* 'prerelease' starts an alpha (1.2.3 becomes 1.2.4-alpha.0) or bumps the existing pre-release tag
|
|
12
|
+
* (1.2.4-alpha.0 becomes 1.2.4-alpha.1).
|
|
11
13
|
* @returns {string} The upgraded semantic version.
|
|
12
14
|
* @throws {Error} If the provided currentVersion is not a valid semantic version.
|
|
13
15
|
*
|
|
@@ -19,16 +21,13 @@ const semver_1 = tslib_1.__importDefault(require("semver"));
|
|
|
19
21
|
*/
|
|
20
22
|
function upgradeVersion(currentVersion, type) {
|
|
21
23
|
try {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
.split('.')
|
|
25
|
-
.concat(new Array(3).fill(0).map(String))
|
|
26
|
-
.slice(0, 3)
|
|
27
|
-
.join('.');
|
|
24
|
+
const version = currentVersion.toString();
|
|
25
|
+
const paddedVersion = semver_1.default.valid(version) ??
|
|
26
|
+
version.split('.').concat(new Array(3).fill(0).map(String)).slice(0, 3).join('.');
|
|
28
27
|
if (!semver_1.default.valid(paddedVersion)) {
|
|
29
28
|
throw new Error('Invalid version string');
|
|
30
29
|
}
|
|
31
|
-
return semver_1.default.inc(paddedVersion, type);
|
|
30
|
+
return semver_1.default.inc(paddedVersion, type, semver_1.default.prerelease(paddedVersion) ? undefined : 'alpha');
|
|
32
31
|
}
|
|
33
32
|
catch (e) {
|
|
34
33
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -25,6 +25,21 @@ describe('upgradeVersion', () => {
|
|
|
25
25
|
const expectedVersion = semver_1.default.inc(currentVersion, releaseType);
|
|
26
26
|
expect(upgradedVersion).toBe(expectedVersion);
|
|
27
27
|
});
|
|
28
|
+
it('should start an alpha pre-release of the next patch from a stable version', () => {
|
|
29
|
+
expect((0, upgrade_version_1.upgradeVersion)('1.3.0', 'prerelease')).toBe('1.3.1-alpha.0');
|
|
30
|
+
});
|
|
31
|
+
it('should bump the number of an existing pre-release', () => {
|
|
32
|
+
expect((0, upgrade_version_1.upgradeVersion)('1.4.0-alpha.1', 'prerelease')).toBe('1.4.0-alpha.2');
|
|
33
|
+
});
|
|
34
|
+
it('should keep the existing pre-release tag when it is not alpha', () => {
|
|
35
|
+
expect((0, upgrade_version_1.upgradeVersion)('1.4.0-beta.1', 'prerelease')).toBe('1.4.0-beta.2');
|
|
36
|
+
});
|
|
37
|
+
it('should pad a short version before upgrading it', () => {
|
|
38
|
+
expect((0, upgrade_version_1.upgradeVersion)('1.2', 'patch')).toBe('1.2.1');
|
|
39
|
+
});
|
|
40
|
+
it('should upgrade a pre-release to its stable version', () => {
|
|
41
|
+
expect((0, upgrade_version_1.upgradeVersion)('1.4.0-alpha.1', 'patch')).toBe('1.4.0');
|
|
42
|
+
});
|
|
28
43
|
it('should throw an error for an invalid semantic version input', () => {
|
|
29
44
|
const currentVersion = 'invalidVersion';
|
|
30
45
|
const releaseType = 'patch';
|
|
@@ -9,10 +9,10 @@ export declare function readVibeIQConfig(): Promise<any>;
|
|
|
9
9
|
export declare function writeVibeIQConfig(config: any): Promise<void>;
|
|
10
10
|
export declare function storeVibeIQConfig(incomingConfig: any): Promise<void>;
|
|
11
11
|
export declare function createConfig(fileName: any): Promise<void>;
|
|
12
|
-
export declare function writeConfig(config: any, configName?: string): Promise<void>;
|
|
12
|
+
export declare function writeConfig(config: any, configName?: string | null): Promise<void>;
|
|
13
13
|
export declare function getConfig(): Promise<any>;
|
|
14
|
-
export declare function storeConfig(incomingConfig: any, configName?: string, merge?: boolean): Promise<void>;
|
|
14
|
+
export declare function storeConfig(incomingConfig: any, configName?: string | null, merge?: boolean): Promise<void>;
|
|
15
15
|
export declare function getConfigFiles(): Promise<any>;
|
|
16
16
|
export declare function getConfigContent(fileName: string): Promise<any>;
|
|
17
|
-
export declare function validateEnvironments(envName?:
|
|
17
|
+
export declare function validateEnvironments(envName?: string | null): Promise<any>;
|
|
18
18
|
export declare function checkTelemetry(cliVersion: string): Promise<void>;
|
|
@@ -46,13 +46,13 @@ exports.initializeVibeIQConfig = initializeVibeIQConfig;
|
|
|
46
46
|
async function readVibeIQConfig() {
|
|
47
47
|
let fileContent;
|
|
48
48
|
try {
|
|
49
|
-
fileContent =
|
|
49
|
+
fileContent = (await node_fs_1.promises.readFile(configFileLocation)).toString();
|
|
50
50
|
}
|
|
51
51
|
catch {
|
|
52
52
|
logger_1.default.debug(`failed to open config file (${configFileLocation}) for reading.`);
|
|
53
53
|
logger_1.default.debug('trying to initialize config file');
|
|
54
54
|
await initializeVibeIQConfig();
|
|
55
|
-
fileContent =
|
|
55
|
+
fileContent = (await node_fs_1.promises.readFile(configFileLocation)).toString();
|
|
56
56
|
}
|
|
57
57
|
try {
|
|
58
58
|
return JSON.parse(fileContent);
|
|
@@ -165,7 +165,7 @@ async function getConfigContent(fileName) {
|
|
|
165
165
|
return JSON.parse(fileContent);
|
|
166
166
|
}
|
|
167
167
|
catch (error) {
|
|
168
|
-
logger_1.default.error(`Failed to open/parse config file (${fileName}) might be malformed or not found
|
|
168
|
+
logger_1.default.error(`Failed to open/parse config file (${fileName}) might be malformed or not found. Path: ${configFilePath}, error: ${error}`);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
exports.getConfigContent = getConfigContent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Item } from '@contrail/entity-types';
|
|
2
|
+
import { API_VERSION } from '@contrail/sdk';
|
|
3
|
+
export declare function createAssortmentItem(assortmentItem: {
|
|
4
|
+
assortmentId: string;
|
|
5
|
+
itemId: string;
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}, options?: {
|
|
8
|
+
skipHydrateRelationships?: boolean;
|
|
9
|
+
apiVersion?: API_VERSION;
|
|
10
|
+
}): Promise<any>;
|
|
11
|
+
export declare function findItemsNotInAssortment(assortmentId: string, count?: number): Promise<Item[]>;
|