@contrail/cli 3.7.0 → 3.8.0-alpha.8de44ff

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.
Files changed (118) hide show
  1. package/README.md +331 -81
  2. package/dist/auth/login.js +2 -1
  3. package/dist/auth/login.spec.js +17 -0
  4. package/dist/baseFlags.d.ts +4 -0
  5. package/dist/baseFlags.js +9 -1
  6. package/dist/basecommand.d.ts +2 -0
  7. package/dist/basecommand.js +7 -1
  8. package/dist/basecommand.spec.d.ts +1 -0
  9. package/dist/basecommand.spec.js +69 -0
  10. package/dist/commands/app/create.d.ts +1 -0
  11. package/dist/commands/app/delete.d.ts +1 -0
  12. package/dist/commands/app/extension/deploy.d.ts +1 -0
  13. package/dist/commands/app/extension/deployment/list.d.ts +1 -0
  14. package/dist/commands/app/getApiKey.d.ts +1 -0
  15. package/dist/commands/app/init.d.ts +1 -0
  16. package/dist/commands/app/install.d.ts +1 -0
  17. package/dist/commands/app/publish.d.ts +1 -0
  18. package/dist/commands/app/publish.js +1 -1
  19. package/dist/commands/app/uninstall.d.ts +1 -0
  20. package/dist/commands/app/upgrade.d.ts +1 -0
  21. package/dist/commands/app/version/major.d.ts +1 -0
  22. package/dist/commands/app/version/minor.d.ts +1 -0
  23. package/dist/commands/app/version/patch.d.ts +1 -0
  24. package/dist/commands/app/version/premajor.d.ts +12 -0
  25. package/dist/commands/app/version/premajor.js +32 -0
  26. package/dist/commands/app/version/preminor.d.ts +12 -0
  27. package/dist/commands/app/version/preminor.js +32 -0
  28. package/dist/commands/app/version/prepatch.d.ts +12 -0
  29. package/dist/commands/app/version/prepatch.js +32 -0
  30. package/dist/commands/app/version/prerelease.d.ts +12 -0
  31. package/dist/commands/app/version/prerelease.js +32 -0
  32. package/dist/commands/config/create.d.ts +2 -0
  33. package/dist/commands/config/create.js +1 -0
  34. package/dist/commands/config/describe.d.ts +2 -0
  35. package/dist/commands/config/describe.js +7 -4
  36. package/dist/commands/config/list.d.ts +2 -0
  37. package/dist/commands/config/list.js +2 -3
  38. package/dist/commands/config/set.d.ts +1 -0
  39. package/dist/commands/config/set.js +11 -6
  40. package/dist/commands/config/use.d.ts +2 -0
  41. package/dist/commands/config/use.js +4 -0
  42. package/dist/commands/entities/create.d.ts +1 -0
  43. package/dist/commands/entities/delete.d.ts +1 -0
  44. package/dist/commands/entities/get.d.ts +1 -0
  45. package/dist/commands/entities/update.d.ts +1 -0
  46. package/dist/commands/feature-flags/export.d.ts +1 -0
  47. package/dist/commands/feature-flags/import.d.ts +1 -0
  48. package/dist/commands/file/upload.d.ts +1 -0
  49. package/dist/commands/groups/export.d.ts +1 -0
  50. package/dist/commands/groups/import.d.ts +1 -0
  51. package/dist/commands/instance/export.d.ts +1 -0
  52. package/dist/commands/instance/import.d.ts +1 -0
  53. package/dist/commands/load/colors.d.ts +1 -0
  54. package/dist/commands/load/custom-entity.d.ts +1 -0
  55. package/dist/commands/load/line-sheet.d.ts +1 -0
  56. package/dist/commands/load/upload-and-load.d.ts +1 -0
  57. package/dist/commands/load-local/index.d.ts +1 -0
  58. package/dist/commands/login.d.ts +1 -0
  59. package/dist/commands/org-config/export.d.ts +1 -0
  60. package/dist/commands/org-config/import.d.ts +1 -0
  61. package/dist/commands/projects/export.d.ts +1 -0
  62. package/dist/commands/projects/list.d.ts +1 -0
  63. package/dist/commands/projects/load.d.ts +1 -0
  64. package/dist/commands/types/exportOptionSetHierarchies.d.ts +1 -0
  65. package/dist/commands/types/getAll.d.ts +1 -0
  66. package/dist/commands/types/getOptionSets.d.ts +1 -0
  67. package/dist/commands/types/loadAll.d.ts +1 -0
  68. package/dist/commands/types/mergeOptionSets.d.ts +1 -0
  69. package/dist/commands/types/mergeTypeProperties.d.ts +1 -0
  70. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +1 -0
  71. package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.d.ts +1 -0
  72. package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +1 -0
  73. package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +1 -0
  74. package/dist/commands/types/parseTypesFromFiles.d.ts +1 -0
  75. package/dist/commands/types/parseTypesFromLocalFiles.d.ts +1 -0
  76. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +1 -0
  77. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +1 -0
  78. package/dist/commands/types/uploadOptionSetHierarchies.d.ts +1 -0
  79. package/dist/commands/types/uploadOptionSets.d.ts +1 -0
  80. package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +1 -0
  81. package/dist/commands/types/uploadRuleSets.d.ts +1 -0
  82. package/dist/commands/types/uploadTypeOverrides.d.ts +1 -0
  83. package/dist/commands/types/uploadTypePolicies.d.ts +1 -0
  84. package/dist/commands/types/uploadTypePropertyPolicies.d.ts +1 -0
  85. package/dist/commands/types/uploadTypes.d.ts +1 -0
  86. package/dist/commands/users/export.d.ts +1 -0
  87. package/dist/commands/users/import.d.ts +1 -0
  88. package/dist/commands/webhooks/create.d.ts +1 -0
  89. package/dist/commands/webhooks/delete.d.ts +1 -0
  90. package/dist/commands/webhooks/getWebhookTrigger.d.ts +1 -0
  91. package/dist/commands/webhooks/list.d.ts +1 -0
  92. package/dist/commands/workflow-template-definitions/install.d.ts +1 -0
  93. package/dist/commands/workflow-template-definitions/list.d.ts +1 -0
  94. package/dist/commands/workflow-templates/delete.d.ts +1 -0
  95. package/dist/commands/workflow-templates/export.d.ts +1 -0
  96. package/dist/commands/workflow-templates/list.d.ts +1 -0
  97. package/dist/commands/workflow-templates/load.d.ts +1 -0
  98. package/dist/helpers/app/app-config-validators.js +4 -4
  99. package/dist/helpers/app/app-config-validators.spec.js +29 -0
  100. package/dist/helpers/app/app-deployer.d.ts +1 -0
  101. package/dist/helpers/app/app-deployer.js +35 -0
  102. package/dist/helpers/app/app-template-parsers.js +4 -1
  103. package/dist/helpers/app/app-template-parsers.spec.d.ts +1 -0
  104. package/dist/helpers/app/app-template-parsers.spec.js +15 -0
  105. package/dist/helpers/app/upgrade-version.d.ts +7 -1
  106. package/dist/helpers/app/upgrade-version.js +11 -8
  107. package/dist/helpers/app/upgrade-version.spec.js +26 -0
  108. package/dist/helpers/config/config.d.ts +3 -2
  109. package/dist/helpers/config/config.js +49 -42
  110. package/dist/helpers/config/config.spec.d.ts +1 -0
  111. package/dist/helpers/config/config.spec.js +79 -0
  112. package/dist/helpers/config/redact-tokens.d.ts +1 -0
  113. package/dist/helpers/config/redact-tokens.js +14 -0
  114. package/dist/helpers/config/redact-tokens.spec.d.ts +1 -0
  115. package/dist/helpers/config/redact-tokens.spec.js +24 -0
  116. package/dist/interfaces.d.ts +1 -0
  117. package/oclif.manifest.json +721 -13
  118. package/package.json +1 -1
@@ -3,6 +3,7 @@ export default class InstallWorkflowTemplateDefinitions extends BaseCommand {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
7
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
8
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
9
  };
@@ -3,6 +3,7 @@ export default class ListWorkflowTemplateDefinitions extends BaseCommand {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
7
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
8
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
9
  };
@@ -3,6 +3,7 @@ export default class DeleteWorkflowTemplates extends BaseCommand {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
7
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
8
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
9
  };
@@ -6,6 +6,7 @@ export default class ExportWorkflows extends BaseCommand {
6
6
  static flags: {
7
7
  outFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
8
  overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
10
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
11
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
12
  };
@@ -3,6 +3,7 @@ export default class ListWorkflowTemplates extends BaseCommand {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
7
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
8
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
9
  };
@@ -3,6 +3,7 @@ export default class LoadWorkflowTemplates extends BaseCommand {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
7
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
8
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
9
  };
@@ -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
- const parts = appDeclaration.version.split('.');
49
- if (parts.length !== 3) {
49
+ if (semver_1.default.valid(appDeclaration.version) !== appDeclaration.version) {
50
50
  errors.push(exports.ERROR_MESSAGES.invalidAppVersion);
51
51
  }
52
52
  return { errors, warnings };
@@ -33,6 +33,35 @@ 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 return an error if app version has build metadata', () => {
44
+ const appDeclaration = {
45
+ version: '1.4.0+build123',
46
+ };
47
+ const expectedError = {
48
+ errors: [app_config_validators_1.ERROR_MESSAGES.invalidAppVersion],
49
+ warnings: [],
50
+ };
51
+ const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
52
+ expect(validationResult).toEqual(expectedError);
53
+ });
54
+ it('should return an error if a version part is not a number', () => {
55
+ const appDeclaration = {
56
+ version: '1.0.x',
57
+ };
58
+ const expectedError = {
59
+ errors: [app_config_validators_1.ERROR_MESSAGES.invalidAppVersion],
60
+ warnings: [],
61
+ };
62
+ const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
63
+ expect(validationResult).toEqual(expectedError);
64
+ });
36
65
  it('should gracefully handle bad versions', () => {
37
66
  const appDeclaration = {
38
67
  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,36 @@ 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 externalLinks = appDeclaration.externalLinks
156
+ ? app_template_parsers_1.ExternalLinkParser.validateAndGetExternalLinks(appDeclaration.externalLinks)
157
+ : [];
158
+ const appCodePackage = await createNodePackage(appDeclaration.appIdentifier, this.debug, this.dryRun);
159
+ if (this.dryRun) {
160
+ logger_1.default.info('Dry run, not creating app version');
161
+ return {};
162
+ }
163
+ const appVersion = await new sdk_1.Entities().create({
164
+ entityName: 'app-version',
165
+ object: {
166
+ appId: existingApp.id,
167
+ semver: appDeclaration.version,
168
+ eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
169
+ configProperties: appDeclaration.appConfiguration
170
+ ? app_template_parsers_1.ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration)
171
+ : undefined,
172
+ triggerKeyDefinitions: appDeclaration.triggers
173
+ ? app_template_parsers_1.TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration)
174
+ : undefined,
175
+ externalLinks,
176
+ appCodePackageId: appCodePackage.id,
177
+ frameworkVersion: 2,
178
+ nodeRuntime: appDeclaration.nodeRuntime ?? existingApp.nodeRuntime,
179
+ },
180
+ });
181
+ logger_1.default.info(`${chalk_1.default.yellow.bold('APP')} Published pre-release version: ${appVersion.semver}`);
182
+ return { ...existingApp, latestAppVersionId: appVersion.id };
183
+ }
149
184
  async remove(appDeclaration) {
150
185
  let app = await this.getExistingApp(appDeclaration);
151
186
  if (app) {
@@ -53,7 +53,10 @@ class ExternalLinkParser {
53
53
  }
54
54
  for (const link of externalLinks) {
55
55
  if (!link.name || typeof link.name !== 'string') {
56
- throw new Error('externalLinks must have a url property (string)');
56
+ throw new Error('externalLinks must have a name property (string)');
57
+ }
58
+ if (!link.label || typeof link.label !== 'string') {
59
+ throw new Error('externalLinks must have a label property (string)');
57
60
  }
58
61
  if (!link.link || typeof link.link !== 'string') {
59
62
  throw new Error('externalLinks must have a link property (string)');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const app_template_parsers_1 = require("./app-template-parsers");
4
+ describe('ExternalLinkParser', () => {
5
+ const externalLink = { name: 'docs', label: 'Docs', link: 'https://example.com' };
6
+ it('should return the external links when each has a name, label and link', () => {
7
+ expect(app_template_parsers_1.ExternalLinkParser.validateAndGetExternalLinks([externalLink])).toEqual([externalLink]);
8
+ });
9
+ it('should throw if an external link has no label', () => {
10
+ expect(() => app_template_parsers_1.ExternalLinkParser.validateAndGetExternalLinks([{ ...externalLink, label: undefined }])).toThrow('externalLinks must have a label property (string)');
11
+ });
12
+ it('should throw if an external link has no name', () => {
13
+ expect(() => app_template_parsers_1.ExternalLinkParser.validateAndGetExternalLinks([{ ...externalLink, name: undefined }])).toThrow('externalLinks must have a name property (string)');
14
+ });
15
+ });
@@ -3,7 +3,13 @@ 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', 'premajor',
7
+ * 'preminor', 'prepatch', 'prerelease').
8
+ * 'prerelease' starts an alpha (1.2.3 becomes 1.2.4-alpha.0) or bumps the existing pre-release tag
9
+ * (1.2.4-alpha.0 becomes 1.2.4-alpha.1).
10
+ * 'premajor', 'preminor' and 'prepatch' always start the first alpha of the next major, minor or
11
+ * patch version (1.2.3 becomes 2.0.0-alpha.0, 1.3.0-alpha.0 or 1.2.4-alpha.0). The results match
12
+ * `npm version <type> --preid=alpha`.
7
13
  * @returns {string} The upgraded semantic version.
8
14
  * @throws {Error} If the provided currentVersion is not a valid semantic version.
9
15
  *
@@ -7,7 +7,13 @@ 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', 'premajor',
11
+ * 'preminor', 'prepatch', 'prerelease').
12
+ * 'prerelease' starts an alpha (1.2.3 becomes 1.2.4-alpha.0) or bumps the existing pre-release tag
13
+ * (1.2.4-alpha.0 becomes 1.2.4-alpha.1).
14
+ * 'premajor', 'preminor' and 'prepatch' always start the first alpha of the next major, minor or
15
+ * patch version (1.2.3 becomes 2.0.0-alpha.0, 1.3.0-alpha.0 or 1.2.4-alpha.0). The results match
16
+ * `npm version <type> --preid=alpha`.
11
17
  * @returns {string} The upgraded semantic version.
12
18
  * @throws {Error} If the provided currentVersion is not a valid semantic version.
13
19
  *
@@ -19,16 +25,13 @@ const semver_1 = tslib_1.__importDefault(require("semver"));
19
25
  */
20
26
  function upgradeVersion(currentVersion, type) {
21
27
  try {
22
- const paddedVersion = currentVersion
23
- .toString()
24
- .split('.')
25
- .concat(new Array(3).fill(0).map(String))
26
- .slice(0, 3)
27
- .join('.');
28
+ const version = currentVersion.toString();
29
+ const paddedVersion = semver_1.default.valid(version) ??
30
+ version.split('.').concat(new Array(3).fill(0).map(String)).slice(0, 3).join('.');
28
31
  if (!semver_1.default.valid(paddedVersion)) {
29
32
  throw new Error('Invalid version string');
30
33
  }
31
- return semver_1.default.inc(paddedVersion, type);
34
+ return semver_1.default.inc(paddedVersion, type, type === 'prerelease' && semver_1.default.prerelease(paddedVersion) ? undefined : 'alpha');
32
35
  }
33
36
  catch (e) {
34
37
  throw new Error(`ERROR PARSING YAML: ${e}`);
@@ -25,6 +25,32 @@ 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.each([
38
+ ['premajor', '1.2.3', '2.0.0-alpha.0'],
39
+ ['preminor', '1.2.3', '1.3.0-alpha.0'],
40
+ ['prepatch', '1.2.3', '1.2.4-alpha.0'],
41
+ ['premajor', '1.2.4-alpha.1', '2.0.0-alpha.0'],
42
+ ['preminor', '1.2.4-alpha.1', '1.3.0-alpha.0'],
43
+ ['prepatch', '1.2.4-alpha.1', '1.2.5-alpha.0'],
44
+ ['premajor', '2.0.0-beta.1', '3.0.0-alpha.0'],
45
+ ])('should apply %s to %s the way npm version does', (type, current, expected) => {
46
+ expect((0, upgrade_version_1.upgradeVersion)(current, type)).toBe(expected);
47
+ });
48
+ it('should pad a short version before upgrading it', () => {
49
+ expect((0, upgrade_version_1.upgradeVersion)('1.2', 'patch')).toBe('1.2.1');
50
+ });
51
+ it('should upgrade a pre-release to its stable version', () => {
52
+ expect((0, upgrade_version_1.upgradeVersion)('1.4.0-alpha.1', 'patch')).toBe('1.4.0');
53
+ });
28
54
  it('should throw an error for an invalid semantic version input', () => {
29
55
  const currentVersion = 'invalidVersion';
30
56
  const releaseType = 'patch';
@@ -9,9 +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 | null): Promise<void>;
12
+ export declare function selectConfigForRun(configName: string | undefined): void;
13
+ export declare function fetchConfigNameForRun(): Promise<string>;
13
14
  export declare function getConfig(): Promise<any>;
14
- export declare function storeConfig(incomingConfig: any, configName?: string | null, merge?: boolean): Promise<void>;
15
+ export declare function storeConfig(incomingConfig: any): Promise<void>;
15
16
  export declare function getConfigFiles(): Promise<any>;
16
17
  export declare function getConfigContent(fileName: string): Promise<any>;
17
18
  export declare function validateEnvironments(envName?: string | null): Promise<any>;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkTelemetry = exports.validateEnvironments = exports.getConfigContent = exports.getConfigFiles = exports.storeConfig = exports.getConfig = exports.writeConfig = exports.createConfig = exports.storeVibeIQConfig = exports.writeVibeIQConfig = exports.readVibeIQConfig = exports.initializeVibeIQConfig = exports.findEnvironmentName = exports.ENVIRONMENTS = void 0;
3
+ exports.checkTelemetry = exports.validateEnvironments = exports.getConfigContent = exports.getConfigFiles = exports.storeConfig = exports.getConfig = exports.fetchConfigNameForRun = exports.selectConfigForRun = exports.createConfig = exports.storeVibeIQConfig = exports.writeVibeIQConfig = exports.readVibeIQConfig = exports.initializeVibeIQConfig = exports.findEnvironmentName = exports.ENVIRONMENTS = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const node_fs_1 = require("node:fs");
6
6
  const node_path_1 = require("node:path");
7
7
  const node_os_1 = require("node:os");
8
+ const node_crypto_1 = require("node:crypto");
8
9
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
9
10
  const configFileName = 'config.json';
10
11
  const defaultConfigFileName = 'default.json';
@@ -12,6 +13,8 @@ const userHomeDir = (0, node_os_1.homedir)();
12
13
  const configDirectoryLocation = (0, node_path_1.join)(userHomeDir, '.vibeiq', 'configs');
13
14
  const configFileLocation = (0, node_path_1.join)(configDirectoryLocation, configFileName);
14
15
  const defaultConfigFileLocation = (0, node_path_1.join)(configDirectoryLocation, defaultConfigFileName);
16
+ let requestedConfigName;
17
+ let configNameForRun;
15
18
  exports.ENVIRONMENTS = {
16
19
  dev: 'https://api.dev.vibeiq.com/dev/api',
17
20
  prod: 'https://api.vibeiq.com/prod/api',
@@ -34,8 +37,8 @@ async function initializeVibeIQConfig() {
34
37
  configInUse: (0, node_path_1.parse)(defaultConfigFileName).name,
35
38
  logLevel: 'debug',
36
39
  };
37
- await node_fs_1.promises.writeFile(configFileLocation, JSON.stringify(config, null, 2));
38
- await node_fs_1.promises.writeFile(defaultConfigFileLocation, '{}');
40
+ await writeFileAtomically(configFileLocation, JSON.stringify(config, null, 2));
41
+ await writeFileAtomically(defaultConfigFileLocation, '{}');
39
42
  }
40
43
  catch (error) {
41
44
  logger_1.default.error(`could not initialize config file (${configFileLocation}).`);
@@ -64,7 +67,7 @@ async function readVibeIQConfig() {
64
67
  exports.readVibeIQConfig = readVibeIQConfig;
65
68
  async function writeVibeIQConfig(config) {
66
69
  try {
67
- await node_fs_1.promises.writeFile(configFileLocation, JSON.stringify(config, null, 2));
70
+ await writeFileAtomically(configFileLocation, JSON.stringify(config, null, 2));
68
71
  }
69
72
  catch (error) {
70
73
  logger_1.default.error(`Could not open config file (${configFileLocation}) for writing.`);
@@ -82,7 +85,7 @@ async function storeVibeIQConfig(incomingConfig) {
82
85
  exports.storeVibeIQConfig = storeVibeIQConfig;
83
86
  async function createConfig(fileName) {
84
87
  try {
85
- await node_fs_1.promises.writeFile((0, node_path_1.join)(configDirectoryLocation, `${fileName}.json`), '{}');
88
+ await writeFileAtomically((0, node_path_1.join)(configDirectoryLocation, `${fileName}.json`), '{}');
86
89
  }
87
90
  catch (error) {
88
91
  logger_1.default.error('Could not create config file.');
@@ -90,59 +93,63 @@ async function createConfig(fileName) {
90
93
  }
91
94
  }
92
95
  exports.createConfig = createConfig;
93
- async function writeConfig(config, configName = null) {
96
+ async function writeConfig(config, configName) {
94
97
  try {
95
- let configFileName = configName;
96
- if (!configName) {
97
- const fileContent = await readVibeIQConfig();
98
- configFileName = fileContent.configInUse;
99
- }
100
- await node_fs_1.promises.writeFile((0, node_path_1.join)(configDirectoryLocation, `${configFileName}.json`), JSON.stringify(config, null, 2));
98
+ await writeFileAtomically((0, node_path_1.join)(configDirectoryLocation, `${configName}.json`), JSON.stringify(config, null, 2));
101
99
  }
102
100
  catch (error) {
103
101
  logger_1.default.error('Could not open config file for writing.');
104
102
  throw error;
105
103
  }
106
104
  }
107
- exports.writeConfig = writeConfig;
108
- async function getConfig() {
109
- let fileContent;
110
- try {
111
- fileContent = (await node_fs_1.promises.readFile(configFileLocation)).toString();
112
- }
113
- catch {
114
- logger_1.default.debug(`failed to open config file (${configFileLocation}) for reading.`);
115
- logger_1.default.debug('trying to initialize config file');
116
- await initializeVibeIQConfig();
117
- fileContent = (await node_fs_1.promises.readFile(configFileLocation)).toString();
118
- }
119
- try {
120
- const configFileJSON = JSON.parse(fileContent);
121
- return getConfigContent(configFileJSON.configInUse);
105
+ function selectConfigForRun(configName) {
106
+ requestedConfigName = configName;
107
+ configNameForRun = undefined;
108
+ }
109
+ exports.selectConfigForRun = selectConfigForRun;
110
+ function fetchConfigNameForRun() {
111
+ configNameForRun ??= fetchConfigNameFromFlagOrPointer();
112
+ return configNameForRun;
113
+ }
114
+ exports.fetchConfigNameForRun = fetchConfigNameForRun;
115
+ async function fetchConfigNameFromFlagOrPointer() {
116
+ if (!requestedConfigName) {
117
+ const configInUse = (await readVibeIQConfig())?.configInUse;
118
+ if (!configInUse) {
119
+ throw new Error('No config selected. Pass --config, set CONTRAIL_CLI_CONFIG, or run `contrail config use`.');
120
+ }
121
+ return configInUse;
122
122
  }
123
- catch {
124
- logger_1.default.error('Could not parse local vibeiq config.');
123
+ const configNames = await getConfigFiles();
124
+ if (!configNames?.includes(requestedConfigName)) {
125
+ throw new Error(`No config named "${requestedConfigName}". Pass --config or set CONTRAIL_CLI_CONFIG to one of: ${configNames?.join(', ')}`);
125
126
  }
127
+ return requestedConfigName;
128
+ }
129
+ async function getConfig() {
130
+ return getConfigContent(await fetchConfigNameForRun());
126
131
  }
127
132
  exports.getConfig = getConfig;
128
- async function storeConfig(incomingConfig, configName = null, merge = true) {
129
- let configContent;
130
- if (!configName) {
131
- configContent = await getConfig();
132
- }
133
- else {
134
- configContent = await getConfigContent(configName);
135
- }
136
- let config = {
137
- ...configContent,
133
+ async function storeConfig(incomingConfig) {
134
+ const configName = await fetchConfigNameForRun();
135
+ const config = {
136
+ ...(await getConfigContent(configName)),
138
137
  ...incomingConfig,
139
138
  };
140
- if (!merge) {
141
- config = incomingConfig;
142
- }
143
139
  await writeConfig(config, configName);
144
140
  }
145
141
  exports.storeConfig = storeConfig;
142
+ async function writeFileAtomically(path, content) {
143
+ const tempPath = `${path}.${(0, node_crypto_1.randomUUID)()}.tmp`;
144
+ try {
145
+ await node_fs_1.promises.writeFile(tempPath, content, { mode: 0o600 });
146
+ await node_fs_1.promises.rename(tempPath, path);
147
+ }
148
+ catch (error) {
149
+ await node_fs_1.promises.rm(tempPath, { force: true });
150
+ throw error;
151
+ }
152
+ }
146
153
  async function getConfigFiles() {
147
154
  try {
148
155
  const dirContent = (await node_fs_1.promises.readdir(configDirectoryLocation, { withFileTypes: true }))
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs_1 = require("fs");
4
+ const os_1 = require("os");
5
+ const path_1 = require("path");
6
+ let mockHome;
7
+ jest.mock('node:os', () => ({
8
+ ...jest.requireActual('node:os'),
9
+ homedir: () => mockHome,
10
+ }));
11
+ jest.mock('../../logger', () => ({
12
+ __esModule: true,
13
+ default: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() },
14
+ }));
15
+ const DEV = { apiGateway: 'https://api.dev.vibeiq.com/dev/api', orgSlug: 'adam-zone-1' };
16
+ const PROD = { apiGateway: 'https://api.vibeiq.com/prod/api', orgSlug: 'adam-prod-1' };
17
+ describe('config selection', () => {
18
+ let configDir;
19
+ let config;
20
+ const writeJson = (name, content) => (0, fs_1.writeFileSync)((0, path_1.join)(configDir, `${name}.json`), JSON.stringify(content));
21
+ const readJson = (name) => JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(configDir, `${name}.json`)).toString());
22
+ const switchPointerTo = (name) => writeJson('config', { configInUse: name });
23
+ beforeEach(() => {
24
+ mockHome = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'contrail-cli-config-'));
25
+ configDir = (0, path_1.join)(mockHome, '.vibeiq', 'configs');
26
+ (0, fs_1.mkdirSync)(configDir, { recursive: true });
27
+ writeJson('dev', DEV);
28
+ writeJson('prod', PROD);
29
+ switchPointerTo('dev');
30
+ jest.isolateModules(() => {
31
+ config = require('./config');
32
+ });
33
+ });
34
+ afterEach(() => {
35
+ jest.restoreAllMocks();
36
+ (0, fs_1.rmSync)(mockHome, { recursive: true, force: true });
37
+ });
38
+ it('should use the config chosen with config use when none is named', async () => {
39
+ config.selectConfigForRun(undefined);
40
+ expect(await config.getConfig()).toEqual(DEV);
41
+ });
42
+ it('should use the named config over the one chosen with config use', async () => {
43
+ config.selectConfigForRun('prod');
44
+ expect(await config.getConfig()).toEqual(PROD);
45
+ });
46
+ it('should keep reading and saving the config it started with after another terminal switches', async () => {
47
+ config.selectConfigForRun(undefined);
48
+ await config.getConfig();
49
+ switchPointerTo('prod');
50
+ await config.storeConfig({ apiUserToken: 'refreshed-dev-token' });
51
+ expect(await config.getConfig()).toEqual({ ...DEV, apiUserToken: 'refreshed-dev-token' });
52
+ expect(readJson('prod')).toEqual(PROD);
53
+ });
54
+ it('should fail when no config is named and none is chosen with config use', async () => {
55
+ writeJson('config', {});
56
+ config.selectConfigForRun(undefined);
57
+ await expect(config.getConfig()).rejects.toThrow('No config selected.');
58
+ });
59
+ it('should fail and list the configs when the named config does not exist', async () => {
60
+ config.selectConfigForRun('staging');
61
+ await expect(config.getConfig()).rejects.toThrow('No config named "staging". Pass --config or set CONTRAIL_CLI_CONFIG to one of: dev, prod');
62
+ });
63
+ it('should leave the previous config intact when a save dies partway', async () => {
64
+ config.selectConfigForRun('dev');
65
+ const realWriteFile = fs_1.promises.writeFile;
66
+ jest.spyOn(fs_1.promises, 'writeFile').mockImplementationOnce(async (path) => {
67
+ await realWriteFile(path, '{"apiGatew');
68
+ throw new Error('ENOSPC: no space left on device');
69
+ });
70
+ await expect(config.storeConfig({ apiUserToken: 'new-token' })).rejects.toThrow('ENOSPC');
71
+ expect(readJson('dev')).toEqual(DEV);
72
+ expect((0, fs_1.readdirSync)(configDir).filter((file) => file.endsWith('.tmp'))).toEqual([]);
73
+ });
74
+ it('should keep a saved config readable only by its owner', async () => {
75
+ config.selectConfigForRun('dev');
76
+ await config.storeConfig({ apiUserToken: 'new-token' });
77
+ expect((0, fs_1.statSync)((0, path_1.join)(configDir, 'dev.json')).mode & 0o777).toBe(0o600);
78
+ });
79
+ });
@@ -0,0 +1 @@
1
+ export declare function redactTokens(config: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redactTokens = void 0;
4
+ const TOKEN_FIELDS = ['apiUserToken', 'apiRefreshToken'];
5
+ function redactTokens(config) {
6
+ const redacted = { ...config };
7
+ for (const field of TOKEN_FIELDS) {
8
+ if (redacted[field]) {
9
+ redacted[field] = '[redacted]';
10
+ }
11
+ }
12
+ return redacted;
13
+ }
14
+ exports.redactTokens = redactTokens;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const redact_tokens_1 = require("./redact-tokens");
4
+ describe('redactTokens', () => {
5
+ it('should hide the access and refresh tokens and keep the org and environment', () => {
6
+ expect((0, redact_tokens_1.redactTokens)({
7
+ apiGateway: 'https://api.dev.vibeiq.com/dev/api',
8
+ orgSlug: 'adam-zone-1',
9
+ apiUserToken: 'secret-access',
10
+ apiRefreshToken: 'secret-refresh',
11
+ })).toEqual({
12
+ apiGateway: 'https://api.dev.vibeiq.com/dev/api',
13
+ orgSlug: 'adam-zone-1',
14
+ apiUserToken: '[redacted]',
15
+ apiRefreshToken: '[redacted]',
16
+ });
17
+ });
18
+ it('should leave a config without tokens unchanged', () => {
19
+ expect((0, redact_tokens_1.redactTokens)({ orgSlug: 'adam-zone-1', apiRefreshToken: null })).toEqual({
20
+ orgSlug: 'adam-zone-1',
21
+ apiRefreshToken: null,
22
+ });
23
+ });
24
+ });
@@ -151,6 +151,7 @@ export interface App {
151
151
  configProperties?: ConfigProperty[];
152
152
  triggerKeyDefinitions?: TriggerKeyDefinition[];
153
153
  latestAppVersionId?: string;
154
+ nodeRuntime?: NodeRuntime;
154
155
  }
155
156
  export interface AppOrg {
156
157
  id: string;