@contrail/cli 3.6.0-alpha-8-alpha.2ab4f80 → 3.6.0-alpha.aae3e70

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 (163) hide show
  1. package/README.md +45 -151
  2. package/dist/api/feature-flags.d.ts +3 -0
  3. package/dist/api/feature-flags.js +29 -0
  4. package/dist/api/types.d.ts +0 -35
  5. package/dist/api/types.js +1 -49
  6. package/dist/api/users.d.ts +1 -0
  7. package/dist/api/users.js +10 -1
  8. package/dist/auth/login.d.ts +4 -0
  9. package/dist/auth/login.js +169 -94
  10. package/dist/auth/login.spec.js +305 -0
  11. package/dist/auth/sso.d.ts +36 -0
  12. package/dist/auth/sso.js +164 -0
  13. package/dist/auth/sso.spec.js +119 -0
  14. package/dist/basecommand.d.ts +1 -3
  15. package/dist/basecommand.js +4 -4
  16. package/dist/commands/app/getApiKey.js +2 -2
  17. package/dist/commands/config/set.js +1 -1
  18. package/dist/commands/feature-flags/export.d.ts +19 -0
  19. package/dist/commands/feature-flags/export.js +66 -0
  20. package/dist/commands/feature-flags/export.spec.js +109 -0
  21. package/dist/commands/feature-flags/import.d.ts +42 -0
  22. package/dist/commands/feature-flags/import.js +191 -0
  23. package/dist/commands/feature-flags/import.spec.js +194 -0
  24. package/dist/commands/instance/export.d.ts +9 -0
  25. package/dist/commands/instance/export.js +18 -3
  26. package/dist/commands/instance/export.spec.js +32 -0
  27. package/dist/commands/instance/import.d.ts +3 -0
  28. package/dist/commands/instance/import.js +5 -0
  29. package/dist/commands/instance/import.spec.js +4 -0
  30. package/dist/commands/login.d.ts +12 -0
  31. package/dist/commands/login.js +25 -0
  32. package/dist/common.d.ts +1 -4
  33. package/dist/common.js +1 -18
  34. package/dist/helpers/config/config.d.ts +5 -4
  35. package/dist/helpers/config/config.js +10 -12
  36. package/dist/helpers/file-helpers.d.ts +0 -1
  37. package/dist/helpers/file-helpers.js +3 -20
  38. package/dist/logger.js +1 -4
  39. package/node_modules/@contrail/entity-compare/package.json +3 -6
  40. package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
  41. package/node_modules/@contrail/loader/lib/constants.d.ts +8 -0
  42. package/node_modules/@contrail/loader/lib/constants.js +9 -1
  43. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +4 -0
  44. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +57 -0
  45. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +492 -34
  46. package/node_modules/@contrail/loader/lib/pipeline/validate.js +2 -52
  47. package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +0 -85
  48. package/node_modules/@contrail/loader/package.json +2 -2
  49. package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +4 -1
  50. package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
  51. package/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -3
  52. package/node_modules/@contrail/sdk/lib/config/config.js +7 -13
  53. package/node_modules/@contrail/sdk/lib/core/request.js +2 -6
  54. package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -2
  55. package/node_modules/@contrail/sdk/lib/entities/entities.client.js +1 -3
  56. package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -1
  57. package/node_modules/@contrail/sdk/package.json +1 -1
  58. package/oclif.manifest.json +75 -365
  59. package/package.json +15 -5
  60. package/dist/commands/entities/create.d.ts +0 -49
  61. package/dist/commands/entities/create.js +0 -643
  62. package/dist/commands/entities/create.spec.js +0 -545
  63. package/dist/commands/entities/delete.d.ts +0 -20
  64. package/dist/commands/entities/delete.js +0 -137
  65. package/dist/commands/entities/get.d.ts +0 -25
  66. package/dist/commands/entities/get.js +0 -276
  67. package/dist/commands/entities/grammar.spec.js +0 -80
  68. package/dist/commands/entities/output.spec.js +0 -72
  69. package/dist/commands/entities/update.d.ts +0 -32
  70. package/dist/commands/entities/update.js +0 -160
  71. package/dist/helpers/entities/assortment-items.d.ts +0 -12
  72. package/dist/helpers/entities/assortment-items.js +0 -87
  73. package/dist/helpers/entities/batchFetch.d.ts +0 -8
  74. package/dist/helpers/entities/batchFetch.js +0 -49
  75. package/dist/helpers/entities/index.d.ts +0 -3
  76. package/dist/helpers/entities/index.js +0 -6
  77. package/dist/helpers/entities/items.d.ts +0 -10
  78. package/dist/helpers/entities/items.js +0 -102
  79. package/dist/helpers/entities/project-items.d.ts +0 -3
  80. package/dist/helpers/entities/project-items.js +0 -65
  81. package/dist/helpers/propertySpecifications/dateRanges.d.ts +0 -38
  82. package/dist/helpers/propertySpecifications/dateRanges.js +0 -89
  83. package/dist/helpers/propertySpecifications/dateRanges.spec.js +0 -95
  84. package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +0 -40
  85. package/dist/helpers/propertySpecifications/propertySpecifications.js +0 -109
  86. package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +0 -1
  87. package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +0 -373
  88. package/dist/logger.spec.d.ts +0 -1
  89. package/dist/logger.spec.js +0 -12
  90. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/pull_request_template.md +0 -31
  91. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/check-code-formatting.yml +0 -34
  92. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/empty.yml +0 -10
  93. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/generate-sdk-docs.yml +0 -32
  94. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +0 -117
  95. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/sdk-lib.yml +0 -27
  96. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.prettierrc.yaml +0 -2
  97. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/README.md +0 -72
  98. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/home-hero.svg +0 -11
  99. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.d.ts +0 -9
  100. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.js +0 -54
  101. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.d.ts +0 -1
  102. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.js +0 -17
  103. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.d.ts +0 -10
  104. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.js +0 -6
  105. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.d.ts +0 -2
  106. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.js +0 -18
  107. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.d.ts +0 -10
  108. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.js +0 -209
  109. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -48
  110. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.js +0 -42
  111. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.d.ts +0 -1
  112. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.js +0 -17
  113. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.d.ts +0 -12
  114. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.js +0 -70
  115. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.d.ts +0 -1
  116. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.js +0 -17
  117. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.d.ts +0 -1
  118. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.js +0 -17
  119. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.d.ts +0 -15
  120. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.js +0 -241
  121. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -101
  122. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.js +0 -306
  123. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.d.ts +0 -9
  124. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.js +0 -86
  125. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.d.ts +0 -6
  126. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.js +0 -19
  127. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.d.ts +0 -5
  128. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -59
  129. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.d.ts +0 -3
  130. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.js +0 -19
  131. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.d.ts +0 -3
  132. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.js +0 -24
  133. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.d.ts +0 -19
  134. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.js +0 -151
  135. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.d.ts +0 -1
  136. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.js +0 -17
  137. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +0 -10
  138. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +0 -26
  139. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.d.ts +0 -1
  140. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.js +0 -17
  141. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.d.ts +0 -16
  142. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.js +0 -37
  143. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.d.ts +0 -1
  144. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.js +0 -17
  145. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.d.ts +0 -12
  146. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.js +0 -55
  147. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.d.ts +0 -9
  148. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.js +0 -74
  149. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.d.ts +0 -2
  150. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.js +0 -18
  151. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.d.ts +0 -18
  152. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.js +0 -98
  153. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.d.ts +0 -19
  154. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.js +0 -73
  155. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.d.ts +0 -42
  156. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.js +0 -217
  157. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +0 -64
  158. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
  159. package/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
  160. /package/dist/{commands/entities/create.spec.d.ts → auth/sso.spec.d.ts} +0 -0
  161. /package/dist/commands/{entities/grammar.spec.d.ts → feature-flags/export.spec.d.ts} +0 -0
  162. /package/dist/commands/{entities/output.spec.d.ts → feature-flags/import.spec.d.ts} +0 -0
  163. /package/dist/{helpers/propertySpecifications/dateRanges.spec.d.ts → commands/instance/export.spec.d.ts} +0 -0
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadFeatureFlags = exports.uploadFeatureFlagsIfPermitted = exports.assertCanManageFeatureFlags = exports.REQUIRED_PLATFORM_ROLES = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path = tslib_1.__importStar(require("path"));
6
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const fs_1 = tslib_1.__importDefault(require("fs"));
8
+ const login_1 = require("../../auth/login");
9
+ const core_1 = require("@oclif/core");
10
+ const file_helpers_1 = require("../../helpers/file-helpers");
11
+ const error_helpers_1 = require("../../helpers/error-helpers");
12
+ const feature_flags_1 = require("../../api/feature-flags");
13
+ const users_1 = require("../../api/users");
14
+ const export_1 = require("./export");
15
+ const basecommand_1 = require("../../basecommand");
16
+ const logger_1 = tslib_1.__importDefault(require("../../logger"));
17
+ exports.REQUIRED_PLATFORM_ROLES = ['PLATFORM_ADMIN', 'PLATFORM_MANAGER'];
18
+ class ImportFeatureFlags extends basecommand_1.BaseCommand {
19
+ static description = 'Upload an extracted set of feature flags';
20
+ static examples = [
21
+ `$ contrail feature-flags import
22
+ `,
23
+ ];
24
+ static flags = {
25
+ ...basecommand_1.BaseCommand.baseFlags,
26
+ dir: core_1.Flags.string({
27
+ char: 'd',
28
+ description: `The directory from which to import the feature flags. Defaults to the current directory. The feature flags will be loaded from $dir/${export_1.FEATURE_FLAGS_FILE}`,
29
+ required: false,
30
+ default: '.',
31
+ }),
32
+ };
33
+ async run() {
34
+ try {
35
+ await (0, login_1.authUser)();
36
+ await assertCanManageFeatureFlags();
37
+ this.log(`${chalk_1.default.blue.bold('START')} Uploading Feature Flags.`);
38
+ this.log(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Uploading`);
39
+ await uploadFeatureFlags(this.flags.dir);
40
+ this.log(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Uploaded`);
41
+ }
42
+ catch (e) {
43
+ this.log(`${chalk_1.default.red.bold('FAIL')} Feature Flags Upload Failed. ${(0, error_helpers_1.describeError)(e)}`);
44
+ process.exitCode = 1;
45
+ return;
46
+ }
47
+ this.log(`${chalk_1.default.green.bold('COMPLETE')} Feature Flags Upload Complete.`);
48
+ }
49
+ }
50
+ exports.default = ImportFeatureFlags;
51
+ async function getPlatformRoles() {
52
+ try {
53
+ const currentUser = await (0, users_1.getCurrentUserWithPlatformRoles)();
54
+ return normalizePlatformRoles(currentUser?.platformRoles);
55
+ }
56
+ catch (e) {
57
+ throw new Error(`Could not read your platform roles. ${(0, error_helpers_1.describeError)(e)}`);
58
+ }
59
+ }
60
+ /**
61
+ * The feature flags API only lets a platform admin/manager create or delete flags, and a
62
+ * missing role surfaces as a generic 403 partway through the run. Checking up front stops
63
+ * the command before it half-applies the file.
64
+ */
65
+ async function assertCanManageFeatureFlags() {
66
+ const platformRoles = await getPlatformRoles();
67
+ if (!platformRoles.some((role) => exports.REQUIRED_PLATFORM_ROLES.includes(role))) {
68
+ throw new Error(`Importing feature flags requires the ${exports.REQUIRED_PLATFORM_ROLES.join(' or ')} platform role. ` +
69
+ `Your roles: ${platformRoles.length ? platformRoles.join(', ') : 'none'}.`);
70
+ }
71
+ }
72
+ exports.assertCanManageFeatureFlags = assertCanManageFeatureFlags;
73
+ /**
74
+ * The `instance import` variant: feature flags are one step of a much larger config copy that
75
+ * org admins without a platform role are expected to run, so a missing role (or roles we could
76
+ * not read) logs and skips instead of failing the whole import. Errors from the flag upload
77
+ * itself still propagate — only the permission check is soft here.
78
+ *
79
+ * `contrail feature-flags import` deliberately does the opposite and fails, because there the
80
+ * flags are the entire point of the command.
81
+ */
82
+ async function uploadFeatureFlagsIfPermitted(dir) {
83
+ let platformRoles;
84
+ try {
85
+ platformRoles = await getPlatformRoles();
86
+ }
87
+ catch (e) {
88
+ logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Skipping feature flags: ${(0, error_helpers_1.describeError)(e)} ` +
89
+ `Ask a platform admin to run 'contrail feature-flags import -d ${dir}'.`);
90
+ return;
91
+ }
92
+ if (!platformRoles.some((role) => exports.REQUIRED_PLATFORM_ROLES.includes(role))) {
93
+ logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Skipping feature flags: this requires the ` +
94
+ `${exports.REQUIRED_PLATFORM_ROLES.join(' or ')} platform role and you have ` +
95
+ `${platformRoles.length ? platformRoles.join(', ') : 'none'}. ` +
96
+ `Ask a platform admin to run 'contrail feature-flags import -d ${dir}'.`);
97
+ return;
98
+ }
99
+ await uploadFeatureFlags(dir);
100
+ }
101
+ exports.uploadFeatureFlagsIfPermitted = uploadFeatureFlagsIfPermitted;
102
+ /**
103
+ * Makes the target org's enabled feature flags match $dir/feature-flags.yml: enables every
104
+ * flag in the file and disables any flag the target has that the file does not, the same
105
+ * way groups import reconciles groups. Feature flags are not editable in place, so there is
106
+ * no update step.
107
+ *
108
+ * Failures are collected and rethrown so an import never reports success while the org is
109
+ * missing flags.
110
+ *
111
+ * A file that lists no flags at all is skipped rather than applied: reconciling against an
112
+ * empty list would disable every flag in the target org, which is almost never what a copy
113
+ * is meant to do. Flags that should be off in the target have to be disabled by hand.
114
+ */
115
+ async function uploadFeatureFlags(dir) {
116
+ const filePath = path.join(dir, export_1.FEATURE_FLAGS_FILE);
117
+ if (!fs_1.default.existsSync(filePath)) {
118
+ logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} No feature flags found in ${dir}. Skipping.`);
119
+ return;
120
+ }
121
+ const data = (0, file_helpers_1.loadData)(filePath) ?? [];
122
+ if (!Array.isArray(data)) {
123
+ throw new Error(`${filePath} must contain a YAML list of feature flags`);
124
+ }
125
+ const featureNamesToEnable = new Set(data.map(toFeatureName).filter(Boolean));
126
+ if (featureNamesToEnable.size === 0) {
127
+ logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} ${filePath} lists no feature flags. Skipping, so ` +
128
+ 'the flags currently enabled in this org are left as they are.');
129
+ return;
130
+ }
131
+ const existingFlags = (await (0, feature_flags_1.getFeatureFlags)()) ?? [];
132
+ const enabledFeatureNames = new Set(existingFlags.map((flag) => flag?.featureName));
133
+ const toCreate = [...featureNamesToEnable].filter((name) => !enabledFeatureNames.has(name));
134
+ const toDelete = existingFlags.filter((flag) => !featureNamesToEnable.has(flag?.featureName));
135
+ const failures = [];
136
+ for (const featureName of toCreate) {
137
+ try {
138
+ await (0, feature_flags_1.createFeatureFlag)(featureName);
139
+ logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Enabled ${featureName}`);
140
+ }
141
+ catch (e) {
142
+ failures.push(`could not enable ${featureName}: ${(0, error_helpers_1.describeError)(e)}`);
143
+ }
144
+ }
145
+ const removed = [];
146
+ for (const flag of toDelete) {
147
+ try {
148
+ await (0, feature_flags_1.deleteFeatureFlag)(flag.id);
149
+ logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Disabled ${flag.featureName}`);
150
+ removed.push(flag.featureName);
151
+ }
152
+ catch (e) {
153
+ failures.push(`could not disable ${flag.featureName}: ${(0, error_helpers_1.describeError)(e)}`);
154
+ }
155
+ }
156
+ // call out the removals explicitly: they are the only destructive part of the import
157
+ if (removed.length) {
158
+ const removedList = removed.sort().join(', ');
159
+ logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} The following ${removed.length} flag(s) were ` +
160
+ `enabled in this org but not in the source, so they were removed: ${removedList}`);
161
+ }
162
+ if (failures.length) {
163
+ throw new Error(`Failed to apply feature flags. ${failures.join('; ')}`);
164
+ }
165
+ }
166
+ exports.uploadFeatureFlags = uploadFeatureFlags;
167
+ // the API returns platformRoles as an array, but some contexts carry it as a JSON string
168
+ function normalizePlatformRoles(platformRoles) {
169
+ if (Array.isArray(platformRoles)) {
170
+ return platformRoles;
171
+ }
172
+ if (typeof platformRoles === 'string') {
173
+ try {
174
+ const parsed = JSON.parse(platformRoles);
175
+ return Array.isArray(parsed) ? parsed : [];
176
+ }
177
+ catch {
178
+ return [];
179
+ }
180
+ }
181
+ return [];
182
+ }
183
+ // entries are exported as `- featureName: X`, but a hand written `- X` is accepted too
184
+ function toFeatureName(entry) {
185
+ const featureName = typeof entry === 'string' ? entry : entry?.featureName;
186
+ if (typeof featureName !== 'string' || !featureName.trim()) {
187
+ logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Skipping entry with no featureName`);
188
+ return undefined;
189
+ }
190
+ return featureName.trim();
191
+ }
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const fs_1 = tslib_1.__importDefault(require("fs"));
5
+ const import_1 = require("./import");
6
+ const file_helpers_1 = require("../../helpers/file-helpers");
7
+ const feature_flags_1 = require("../../api/feature-flags");
8
+ const users_1 = require("../../api/users");
9
+ const logger_1 = tslib_1.__importDefault(require("../../logger"));
10
+ jest.mock('../../helpers/file-helpers');
11
+ jest.mock('../../api/feature-flags');
12
+ jest.mock('../../api/users');
13
+ const mocked = (fn) => fn;
14
+ describe('assertCanManageFeatureFlags', () => {
15
+ beforeEach(() => {
16
+ jest.clearAllMocks();
17
+ });
18
+ it.each(['PLATFORM_ADMIN', 'PLATFORM_MANAGER'])('allows a %s', async (role) => {
19
+ mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({ platformRoles: [role] });
20
+ await expect((0, import_1.assertCanManageFeatureFlags)()).resolves.toBeUndefined();
21
+ });
22
+ it('accepts platformRoles serialized as a JSON string', async () => {
23
+ mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({
24
+ platformRoles: '["PLATFORM_MANAGER"]',
25
+ });
26
+ await expect((0, import_1.assertCanManageFeatureFlags)()).resolves.toBeUndefined();
27
+ });
28
+ it('rejects a user with no platform role', async () => {
29
+ mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({ platformRoles: [] });
30
+ await expect((0, import_1.assertCanManageFeatureFlags)()).rejects.toThrow('requires the PLATFORM_ADMIN or PLATFORM_MANAGER platform role');
31
+ });
32
+ it('rejects a user holding only some other platform role', async () => {
33
+ mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({
34
+ platformRoles: ['PLATFORM_USER'],
35
+ });
36
+ await expect((0, import_1.assertCanManageFeatureFlags)()).rejects.toThrow('Your roles: PLATFORM_USER.');
37
+ });
38
+ it('rejects when the roles could not be read', async () => {
39
+ mocked(users_1.getCurrentUserWithPlatformRoles).mockRejectedValue(new Error('Forbidden resource'));
40
+ await expect((0, import_1.assertCanManageFeatureFlags)()).rejects.toThrow('Could not read your platform roles. Forbidden resource');
41
+ });
42
+ });
43
+ describe('uploadFeatureFlags', () => {
44
+ let existsSyncSpy;
45
+ beforeEach(() => {
46
+ jest.clearAllMocks();
47
+ existsSyncSpy = jest.spyOn(fs_1.default, 'existsSync').mockReturnValue(true);
48
+ mocked(feature_flags_1.createFeatureFlag).mockResolvedValue({});
49
+ mocked(feature_flags_1.deleteFeatureFlag).mockResolvedValue({});
50
+ mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([]);
51
+ });
52
+ afterEach(() => {
53
+ existsSyncSpy.mockRestore();
54
+ });
55
+ it('skips when the export has no feature-flags.yml', async () => {
56
+ existsSyncSpy.mockReturnValue(false);
57
+ await (0, import_1.uploadFeatureFlags)('export-dir');
58
+ expect(mocked(feature_flags_1.getFeatureFlags)).not.toHaveBeenCalled();
59
+ expect(mocked(feature_flags_1.createFeatureFlag)).not.toHaveBeenCalled();
60
+ });
61
+ it('skips an export that lists no flags instead of disabling everything in the target org', async () => {
62
+ mocked(file_helpers_1.loadData).mockReturnValue([]);
63
+ mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([
64
+ { id: '1', featureName: 'SHOWROOM' },
65
+ { id: '2', featureName: 'DEV_TABS' },
66
+ ]);
67
+ const infoSpy = jest.spyOn(logger_1.default, 'info').mockImplementation(() => undefined);
68
+ await (0, import_1.uploadFeatureFlags)('export-dir');
69
+ expect(mocked(feature_flags_1.deleteFeatureFlag)).not.toHaveBeenCalled();
70
+ expect(mocked(feature_flags_1.createFeatureFlag)).not.toHaveBeenCalled();
71
+ expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('lists no feature flags'));
72
+ infoSpy.mockRestore();
73
+ });
74
+ it('treats a blank feature-flags.yml the same as an empty list', async () => {
75
+ mocked(file_helpers_1.loadData).mockReturnValue(undefined);
76
+ mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([{ id: '1', featureName: 'SHOWROOM' }]);
77
+ await (0, import_1.uploadFeatureFlags)('export-dir');
78
+ expect(mocked(feature_flags_1.getFeatureFlags)).not.toHaveBeenCalled();
79
+ expect(mocked(feature_flags_1.deleteFeatureFlag)).not.toHaveBeenCalled();
80
+ });
81
+ it('enables every flag from the export that the target org is missing', async () => {
82
+ mocked(file_helpers_1.loadData).mockReturnValue([{ featureName: 'SHOWROOM' }, { featureName: 'PROMOTE' }]);
83
+ mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([{ id: '1', featureName: 'SHOWROOM' }]);
84
+ await (0, import_1.uploadFeatureFlags)('export-dir');
85
+ expect(mocked(feature_flags_1.createFeatureFlag)).toHaveBeenCalledTimes(1);
86
+ expect(mocked(feature_flags_1.createFeatureFlag)).toHaveBeenCalledWith('PROMOTE');
87
+ });
88
+ it('disables flags the target org has that the export does not, so the orgs match', async () => {
89
+ mocked(file_helpers_1.loadData).mockReturnValue([{ featureName: 'SHOWROOM' }]);
90
+ mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([
91
+ { id: '1', featureName: 'SHOWROOM' },
92
+ { id: '2', featureName: 'DEV_TABS' },
93
+ ]);
94
+ await (0, import_1.uploadFeatureFlags)('export-dir');
95
+ expect(mocked(feature_flags_1.createFeatureFlag)).not.toHaveBeenCalled();
96
+ expect(mocked(feature_flags_1.deleteFeatureFlag)).toHaveBeenCalledTimes(1);
97
+ expect(mocked(feature_flags_1.deleteFeatureFlag)).toHaveBeenCalledWith('2');
98
+ });
99
+ it('summarizes what it removed, and why, at the end of the run', async () => {
100
+ const infoSpy = jest.spyOn(logger_1.default, 'info').mockImplementation(() => undefined);
101
+ mocked(file_helpers_1.loadData).mockReturnValue([{ featureName: 'SHOWROOM' }]);
102
+ mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([
103
+ { id: '1', featureName: 'SHOWROOM' },
104
+ { id: '2', featureName: 'PROMOTE' },
105
+ { id: '3', featureName: 'DEV_TABS' },
106
+ ]);
107
+ await (0, import_1.uploadFeatureFlags)('export-dir');
108
+ const summary = infoSpy.mock.calls.map(([message]) => String(message)).at(-1);
109
+ expect(summary).toContain('2 flag(s) were enabled in this org but not in the source');
110
+ expect(summary).toContain('DEV_TABS, PROMOTE');
111
+ infoSpy.mockRestore();
112
+ });
113
+ it('does not print a removal summary when nothing was removed', async () => {
114
+ const infoSpy = jest.spyOn(logger_1.default, 'info').mockImplementation(() => undefined);
115
+ mocked(file_helpers_1.loadData).mockReturnValue([{ featureName: 'SHOWROOM' }]);
116
+ mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([{ id: '1', featureName: 'SHOWROOM' }]);
117
+ await (0, import_1.uploadFeatureFlags)('export-dir');
118
+ const messages = infoSpy.mock.calls.map(([message]) => String(message));
119
+ expect(messages.some((message) => message.includes('so they were removed'))).toBe(false);
120
+ infoSpy.mockRestore();
121
+ });
122
+ it('accepts plain feature names and ignores entries with no featureName', async () => {
123
+ mocked(file_helpers_1.loadData).mockReturnValue(['SHOWROOM', { featureName: ' PROMOTE ' }, {}, null]);
124
+ await (0, import_1.uploadFeatureFlags)('export-dir');
125
+ expect(mocked(feature_flags_1.createFeatureFlag).mock.calls.map(([name]) => name)).toEqual([
126
+ 'SHOWROOM',
127
+ 'PROMOTE',
128
+ ]);
129
+ });
130
+ it('rejects when the file is not a list', async () => {
131
+ mocked(file_helpers_1.loadData).mockReturnValue({ featureName: 'SHOWROOM' });
132
+ await expect((0, import_1.uploadFeatureFlags)('export-dir')).rejects.toThrow('must contain a YAML list of feature flags');
133
+ });
134
+ it('applies what it can and then rejects, rather than reporting success', async () => {
135
+ mocked(file_helpers_1.loadData).mockReturnValue([{ featureName: 'SHOWROOM' }, { featureName: 'PROMOTE' }]);
136
+ mocked(feature_flags_1.createFeatureFlag).mockImplementation(async (featureName) => {
137
+ if (featureName === 'SHOWROOM') {
138
+ throw new Error('Forbidden resource');
139
+ }
140
+ return {};
141
+ });
142
+ await expect((0, import_1.uploadFeatureFlags)('export-dir')).rejects.toThrow('could not enable SHOWROOM: Forbidden resource');
143
+ expect(mocked(feature_flags_1.createFeatureFlag)).toHaveBeenCalledWith('PROMOTE');
144
+ });
145
+ });
146
+ describe('uploadFeatureFlagsIfPermitted', () => {
147
+ let existsSyncSpy;
148
+ let infoSpy;
149
+ beforeEach(() => {
150
+ jest.clearAllMocks();
151
+ existsSyncSpy = jest.spyOn(fs_1.default, 'existsSync').mockReturnValue(true);
152
+ infoSpy = jest.spyOn(logger_1.default, 'info').mockImplementation(() => undefined);
153
+ mocked(file_helpers_1.loadData).mockReturnValue([{ featureName: 'SHOWROOM' }]);
154
+ mocked(feature_flags_1.createFeatureFlag).mockResolvedValue({});
155
+ mocked(feature_flags_1.deleteFeatureFlag).mockResolvedValue({});
156
+ mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([]);
157
+ });
158
+ afterEach(() => {
159
+ existsSyncSpy.mockRestore();
160
+ infoSpy.mockRestore();
161
+ });
162
+ const messages = () => infoSpy.mock.calls.map(([message]) => String(message)).join('\n');
163
+ it('applies the flags when the user has a platform role', async () => {
164
+ mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({
165
+ platformRoles: ['PLATFORM_MANAGER'],
166
+ });
167
+ await (0, import_1.uploadFeatureFlagsIfPermitted)('export-dir');
168
+ expect(mocked(feature_flags_1.createFeatureFlag)).toHaveBeenCalledWith('SHOWROOM');
169
+ });
170
+ it('skips with a log instead of failing when the user has no platform role', async () => {
171
+ mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({ platformRoles: [] });
172
+ await expect((0, import_1.uploadFeatureFlagsIfPermitted)('export-dir')).resolves.toBeUndefined();
173
+ expect(mocked(feature_flags_1.getFeatureFlags)).not.toHaveBeenCalled();
174
+ expect(mocked(feature_flags_1.createFeatureFlag)).not.toHaveBeenCalled();
175
+ expect(mocked(feature_flags_1.deleteFeatureFlag)).not.toHaveBeenCalled();
176
+ expect(messages()).toContain('Skipping feature flags');
177
+ expect(messages()).toContain('PLATFORM_ADMIN or PLATFORM_MANAGER');
178
+ expect(messages()).toContain('contrail feature-flags import -d export-dir');
179
+ });
180
+ it('skips with a log when the platform roles cannot be read', async () => {
181
+ mocked(users_1.getCurrentUserWithPlatformRoles).mockRejectedValue(new Error('Forbidden resource'));
182
+ await expect((0, import_1.uploadFeatureFlagsIfPermitted)('export-dir')).resolves.toBeUndefined();
183
+ expect(mocked(feature_flags_1.createFeatureFlag)).not.toHaveBeenCalled();
184
+ expect(messages()).toContain('Skipping feature flags');
185
+ expect(messages()).toContain('Forbidden resource');
186
+ });
187
+ it('still propagates a failure from the upload itself', async () => {
188
+ mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({
189
+ platformRoles: ['PLATFORM_ADMIN'],
190
+ });
191
+ mocked(feature_flags_1.createFeatureFlag).mockRejectedValue(new Error('boom'));
192
+ await expect((0, import_1.uploadFeatureFlagsIfPermitted)('export-dir')).rejects.toThrow('could not enable SHOWROOM: boom');
193
+ });
194
+ });
@@ -10,3 +10,12 @@ export default class ExportInstance extends BaseCommand {
10
10
  };
11
11
  run(): Promise<void>;
12
12
  }
13
+ /**
14
+ * Exports everything `contrail instance import` loads back: types, users, groups and the
15
+ * org's enabled feature flags. Org config (branding, sorting, admin-console settings) is
16
+ * written by getAllTypes, so it is not repeated here.
17
+ *
18
+ * Exporting feature flags is a plain read, so it works for any user — only the import side
19
+ * needs a platform role.
20
+ */
21
+ export declare function exportInstance(outDir: string, overwrite: boolean): Promise<void>;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportInstance = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  const path = tslib_1.__importStar(require("path"));
5
6
  const core_1 = require("@oclif/core");
6
7
  const getAll_1 = require("../types/getAll");
7
8
  const export_1 = require("../users/export");
8
9
  const export_2 = require("../groups/export");
10
+ const export_3 = require("../feature-flags/export");
9
11
  const basecommand_1 = require("../../basecommand");
10
12
  class ExportInstance extends basecommand_1.BaseCommand {
11
13
  static description = 'Exports an data of an instance including types and users';
@@ -29,9 +31,22 @@ class ExportInstance extends basecommand_1.BaseCommand {
29
31
  }),
30
32
  };
31
33
  async run() {
32
- await (0, getAll_1.getAll)(this.flags.outDir, this.flags.overwrite);
33
- await (0, export_1.exportUsers)(path.join(this.flags.outDir, 'users.yml'), this.flags.overwrite);
34
- await (0, export_2.exportGroups)(path.join(this.flags.outDir, 'groups.yml'), this.flags.overwrite);
34
+ await exportInstance(this.flags.outDir, this.flags.overwrite);
35
35
  }
36
36
  }
37
37
  exports.default = ExportInstance;
38
+ /**
39
+ * Exports everything `contrail instance import` loads back: types, users, groups and the
40
+ * org's enabled feature flags. Org config (branding, sorting, admin-console settings) is
41
+ * written by getAllTypes, so it is not repeated here.
42
+ *
43
+ * Exporting feature flags is a plain read, so it works for any user — only the import side
44
+ * needs a platform role.
45
+ */
46
+ async function exportInstance(outDir, overwrite) {
47
+ await (0, getAll_1.getAll)(outDir, overwrite);
48
+ await (0, export_1.exportUsers)(path.join(outDir, 'users.yml'), overwrite);
49
+ await (0, export_2.exportGroups)(path.join(outDir, 'groups.yml'), overwrite);
50
+ await (0, export_3.exportFeatureFlags)(outDir, overwrite);
51
+ }
52
+ exports.exportInstance = exportInstance;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const export_1 = require("./export");
4
+ const getAll_1 = require("../types/getAll");
5
+ const export_2 = require("../users/export");
6
+ const export_3 = require("../groups/export");
7
+ const export_4 = require("../feature-flags/export");
8
+ jest.mock('../types/getAll');
9
+ jest.mock('../users/export');
10
+ jest.mock('../groups/export');
11
+ jest.mock('../feature-flags/export');
12
+ const mocked = (fn) => fn;
13
+ const STEPS = [getAll_1.getAll, export_2.exportUsers, export_3.exportGroups, export_4.exportFeatureFlags];
14
+ describe('exportInstance', () => {
15
+ beforeEach(() => {
16
+ jest.clearAllMocks();
17
+ for (const fn of STEPS) {
18
+ mocked(fn).mockResolvedValue(undefined);
19
+ }
20
+ });
21
+ it('exports everything the import loads back, including feature flags', async () => {
22
+ await (0, export_1.exportInstance)('out-dir', true);
23
+ expect(mocked(getAll_1.getAll)).toHaveBeenCalledWith('out-dir', true);
24
+ expect(mocked(export_2.exportUsers)).toHaveBeenCalledWith('out-dir/users.yml', true);
25
+ expect(mocked(export_3.exportGroups)).toHaveBeenCalledWith('out-dir/groups.yml', true);
26
+ expect(mocked(export_4.exportFeatureFlags)).toHaveBeenCalledWith('out-dir', true);
27
+ });
28
+ it('passes the overwrite flag through to the feature flags export', async () => {
29
+ await (0, export_1.exportInstance)('out-dir', false);
30
+ expect(mocked(export_4.exportFeatureFlags)).toHaveBeenCalledWith('out-dir', false);
31
+ });
32
+ });
@@ -17,6 +17,9 @@ export default class ImportInstance extends BaseCommand {
17
17
  * 4. type overrides — after policies, because they reference policies, rule sets and option
18
18
  * set hierarchies by slug and the API rejects the whole upload if any of them is missing
19
19
  * 5. org config
20
+ * 6. feature flags — skipped with a log message when the user has no platform role,
21
+ * since applying them needs PLATFORM_ADMIN/PLATFORM_MANAGER but the rest of the
22
+ * import does not, and org admins are expected to run this command
20
23
  *
21
24
  * Fails (rejects) if the type overrides could not be applied, so the import does not
22
25
  * report success while the org is missing customizations carried by overrides
@@ -11,6 +11,7 @@ const uploadTypePropertyPolicies_1 = require("../types/uploadTypePropertyPolicie
11
11
  const uploadTypePolicies_1 = require("../types/uploadTypePolicies");
12
12
  const uploadTypeOverrides_1 = require("../types/uploadTypeOverrides");
13
13
  const import_3 = require("../org-config/import");
14
+ const import_4 = require("../feature-flags/import");
14
15
  const basecommand_1 = require("../../basecommand");
15
16
  class ImportInstance extends basecommand_1.BaseCommand {
16
17
  static description = 'Import the data to an instance, including types and users';
@@ -40,6 +41,9 @@ exports.default = ImportInstance;
40
41
  * 4. type overrides — after policies, because they reference policies, rule sets and option
41
42
  * set hierarchies by slug and the API rejects the whole upload if any of them is missing
42
43
  * 5. org config
44
+ * 6. feature flags — skipped with a log message when the user has no platform role,
45
+ * since applying them needs PLATFORM_ADMIN/PLATFORM_MANAGER but the rest of the
46
+ * import does not, and org admins are expected to run this command
43
47
  *
44
48
  * Fails (rejects) if the type overrides could not be applied, so the import does not
45
49
  * report success while the org is missing customizations carried by overrides
@@ -53,5 +57,6 @@ async function importInstance(dir) {
53
57
  await (0, uploadTypePolicies_1.uploadTypePolicies)(dir);
54
58
  await (0, uploadTypeOverrides_1.uploadTypeOverrides)(dir);
55
59
  await (0, import_3.uploadOrgConfig)(dir);
60
+ await (0, import_4.uploadFeatureFlagsIfPermitted)(dir);
56
61
  }
57
62
  exports.importInstance = importInstance;
@@ -8,6 +8,7 @@ const uploadTypePropertyPolicies_1 = require("../types/uploadTypePropertyPolicie
8
8
  const uploadTypePolicies_1 = require("../types/uploadTypePolicies");
9
9
  const uploadTypeOverrides_1 = require("../types/uploadTypeOverrides");
10
10
  const import_4 = require("../org-config/import");
11
+ const import_5 = require("../feature-flags/import");
11
12
  jest.mock('../types/loadAll');
12
13
  jest.mock('../users/import');
13
14
  jest.mock('../groups/import');
@@ -15,6 +16,7 @@ jest.mock('../types/uploadTypePropertyPolicies');
15
16
  jest.mock('../types/uploadTypePolicies');
16
17
  jest.mock('../types/uploadTypeOverrides');
17
18
  jest.mock('../org-config/import');
19
+ jest.mock('../feature-flags/import');
18
20
  const mocked = (fn) => fn;
19
21
  const STEPS = [
20
22
  loadAll_1.loadAll,
@@ -24,6 +26,7 @@ const STEPS = [
24
26
  uploadTypePolicies_1.uploadTypePolicies,
25
27
  uploadTypeOverrides_1.uploadTypeOverrides,
26
28
  import_4.uploadOrgConfig,
29
+ import_5.uploadFeatureFlagsIfPermitted,
27
30
  ];
28
31
  describe('importInstance', () => {
29
32
  beforeEach(() => {
@@ -37,6 +40,7 @@ describe('importInstance', () => {
37
40
  expect(mocked(loadAll_1.loadAll)).toHaveBeenCalledWith('export-dir', true, false);
38
41
  expect(mocked(uploadTypeOverrides_1.uploadTypeOverrides)).toHaveBeenCalledWith('export-dir');
39
42
  expect(mocked(import_4.uploadOrgConfig)).toHaveBeenCalledWith('export-dir');
43
+ expect(mocked(import_5.uploadFeatureFlagsIfPermitted)).toHaveBeenCalledWith('export-dir');
40
44
  const order = STEPS.map((fn) => mocked(fn).mock.invocationCallOrder[0]);
41
45
  // strictly increasing => called in exactly this order
42
46
  for (let i = 1; i < order.length; i++) {
@@ -0,0 +1,12 @@
1
+ import { BaseCommand } from '../basecommand';
2
+ export default class Login extends BaseCommand {
3
+ static description: string;
4
+ skipConfirmEnv: boolean;
5
+ static examples: string[];
6
+ static flags: {
7
+ browser: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ };
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const basecommand_1 = require("../basecommand");
6
+ const login_1 = require("../auth/login");
7
+ const logger_1 = tslib_1.__importDefault(require("../logger"));
8
+ class Login extends basecommand_1.BaseCommand {
9
+ static description = 'Sign in to VibeIQ with SSO or your email and password';
10
+ skipConfirmEnv = true;
11
+ static examples = ['$ contrail login', '$ contrail login --no-browser'];
12
+ static flags = {
13
+ ...basecommand_1.BaseCommand.baseFlags,
14
+ browser: core_1.Flags.boolean({
15
+ description: 'Open a browser for SSO. Use --no-browser to paste a sign-in code instead.',
16
+ default: true,
17
+ allowNo: true,
18
+ }),
19
+ };
20
+ async run() {
21
+ const context = await (0, login_1.signIn)({ openBrowser: this.flags.browser });
22
+ logger_1.default.info(`Signed in to ${context.orgSlug}.`);
23
+ }
24
+ }
25
+ exports.default = Login;
package/dist/common.d.ts CHANGED
@@ -1,7 +1,4 @@
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: string): string;
5
- export declare function routeConsoleLogToStderr(): void;
6
- export declare function sdkErrorMessage(reason: any): string;
7
- export declare const promptOnStderr: any;
4
+ export declare function removeSlash(string: any): string;
package/dist/common.js CHANGED
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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"));
3
+ exports.removeSlash = exports.delay = exports.getSeparatorByPlatform = void 0;
6
4
  function getSeparatorByPlatform() {
7
5
  const isWin = process.platform === 'win32';
8
6
  const separator = isWin ? '\\' : '/';
@@ -18,18 +16,3 @@ function removeSlash(string) {
18
16
  return string.replace(re, '-');
19
17
  }
20
18
  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 });
@@ -1,17 +1,18 @@
1
1
  export declare const ENVIRONMENTS: {
2
2
  dev: string;
3
3
  prod: string;
4
- local: string;
5
4
  };
5
+ export type EnvironmentName = keyof typeof ENVIRONMENTS;
6
+ export declare function findEnvironmentName(apiGateway: string): EnvironmentName | undefined;
6
7
  export declare function initializeVibeIQConfig(): Promise<void>;
7
8
  export declare function readVibeIQConfig(): Promise<any>;
8
9
  export declare function writeVibeIQConfig(config: any): Promise<void>;
9
10
  export declare function storeVibeIQConfig(incomingConfig: any): Promise<void>;
10
11
  export declare function createConfig(fileName: any): Promise<void>;
11
- export declare function writeConfig(config: any, configName?: string | null): Promise<void>;
12
+ export declare function writeConfig(config: any, configName?: string): Promise<void>;
12
13
  export declare function getConfig(): Promise<any>;
13
- export declare function storeConfig(incomingConfig: any, configName?: string | null, merge?: boolean): Promise<void>;
14
+ export declare function storeConfig(incomingConfig: any, configName?: string, merge?: boolean): Promise<void>;
14
15
  export declare function getConfigFiles(): Promise<any>;
15
16
  export declare function getConfigContent(fileName: string): Promise<any>;
16
- export declare function validateEnvironments(envName?: string | null): Promise<any>;
17
+ export declare function validateEnvironments(envName?: any): Promise<any>;
17
18
  export declare function checkTelemetry(cliVersion: string): Promise<void>;