@salesforce/core 4.0.0 → 4.1.0

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 (151) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +93 -44
  3. package/lib/config/authInfoConfig.d.ts +19 -0
  4. package/lib/config/authInfoConfig.js +35 -0
  5. package/lib/config/config.d.ts +87 -22
  6. package/lib/config/config.js +117 -65
  7. package/lib/config/configAggregator.d.ts +41 -35
  8. package/lib/config/configAggregator.js +102 -73
  9. package/lib/config/configFile.d.ts +2 -2
  10. package/lib/config/configFile.js +38 -29
  11. package/lib/config/configStore.d.ts +9 -9
  12. package/lib/config/configStore.js +17 -15
  13. package/lib/config/envVars.d.ts +15 -9
  14. package/lib/config/envVars.js +71 -47
  15. package/lib/config/orgUsersConfig.js +2 -0
  16. package/lib/config/sandboxOrgConfig.js +2 -0
  17. package/lib/config/sandboxProcessCache.d.ts +16 -0
  18. package/lib/config/sandboxProcessCache.js +38 -0
  19. package/lib/config/tokensConfig.d.ts +10 -0
  20. package/lib/config/tokensConfig.js +29 -0
  21. package/lib/config/ttlConfig.d.ts +34 -0
  22. package/lib/config/ttlConfig.js +50 -0
  23. package/lib/crypto/crypto.js +15 -22
  24. package/lib/crypto/keyChain.js +2 -3
  25. package/lib/crypto/keyChainImpl.d.ts +5 -3
  26. package/lib/crypto/keyChainImpl.js +58 -61
  27. package/lib/crypto/secureBuffer.d.ts +1 -1
  28. package/lib/deviceOauthService.d.ts +3 -3
  29. package/lib/deviceOauthService.js +27 -25
  30. package/lib/exported.d.ts +15 -12
  31. package/lib/exported.js +28 -16
  32. package/lib/global.d.ts +11 -3
  33. package/lib/global.js +39 -12
  34. package/lib/lifecycleEvents.d.ts +1 -1
  35. package/lib/lifecycleEvents.js +3 -0
  36. package/lib/logger.d.ts +19 -9
  37. package/lib/logger.js +112 -86
  38. package/lib/messages.d.ts +53 -36
  39. package/lib/messages.js +81 -91
  40. package/lib/org/authInfo.d.ts +56 -20
  41. package/lib/org/authInfo.js +232 -131
  42. package/lib/org/authRemover.d.ts +8 -7
  43. package/lib/org/authRemover.js +32 -28
  44. package/lib/org/connection.d.ts +13 -37
  45. package/lib/org/connection.js +78 -124
  46. package/lib/org/index.js +5 -1
  47. package/lib/org/org.d.ts +151 -48
  48. package/lib/org/org.js +468 -225
  49. package/lib/org/orgConfigProperties.d.ts +64 -3
  50. package/lib/org/orgConfigProperties.js +96 -4
  51. package/lib/org/permissionSetAssignment.js +4 -13
  52. package/lib/org/scratchOrgCache.d.ts +20 -0
  53. package/lib/org/scratchOrgCache.js +33 -0
  54. package/lib/org/scratchOrgCreate.d.ts +28 -17
  55. package/lib/org/scratchOrgCreate.js +125 -53
  56. package/lib/org/scratchOrgErrorCodes.d.ts +9 -3
  57. package/lib/org/scratchOrgErrorCodes.js +34 -17
  58. package/lib/org/scratchOrgFeatureDeprecation.js +1 -6
  59. package/lib/org/scratchOrgInfoApi.d.ts +21 -47
  60. package/lib/org/scratchOrgInfoApi.js +129 -63
  61. package/lib/org/scratchOrgInfoGenerator.d.ts +6 -5
  62. package/lib/org/scratchOrgInfoGenerator.js +76 -62
  63. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
  64. package/lib/org/scratchOrgLifecycleEvents.js +41 -0
  65. package/lib/org/scratchOrgSettingsGenerator.d.ts +44 -21
  66. package/lib/org/scratchOrgSettingsGenerator.js +165 -98
  67. package/lib/org/scratchOrgTypes.d.ts +43 -0
  68. package/lib/org/scratchOrgTypes.js +9 -0
  69. package/lib/org/user.d.ts +1 -1
  70. package/lib/org/user.js +25 -34
  71. package/lib/schema/printer.d.ts +6 -0
  72. package/lib/schema/printer.js +34 -31
  73. package/lib/schema/validator.d.ts +12 -10
  74. package/lib/schema/validator.js +56 -76
  75. package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -20
  76. package/lib/{sfdxError.js → sfError.js} +40 -30
  77. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
  78. package/lib/sfProject.js +651 -0
  79. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +129 -0
  80. package/lib/stateAggregator/accessors/aliasAccessor.js +263 -0
  81. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
  82. package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
  83. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
  84. package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
  85. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
  86. package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
  87. package/lib/stateAggregator/index.d.ts +4 -0
  88. package/lib/stateAggregator/index.js +27 -0
  89. package/lib/stateAggregator/stateAggregator.d.ts +25 -0
  90. package/lib/stateAggregator/stateAggregator.js +46 -0
  91. package/lib/status/myDomainResolver.d.ts +1 -1
  92. package/lib/status/myDomainResolver.js +4 -4
  93. package/lib/status/pollingClient.js +4 -4
  94. package/lib/status/streamingClient.d.ts +2 -2
  95. package/lib/status/streamingClient.js +58 -63
  96. package/lib/status/types.d.ts +2 -2
  97. package/lib/testSetup.d.ts +204 -75
  98. package/lib/testSetup.js +468 -164
  99. package/lib/util/cache.d.ts +2 -2
  100. package/lib/util/cache.js +6 -6
  101. package/lib/util/checkLightningDomain.js +3 -4
  102. package/lib/util/directoryWriter.d.ts +12 -0
  103. package/lib/util/directoryWriter.js +54 -0
  104. package/lib/util/getJwtAudienceUrl.js +1 -1
  105. package/lib/util/internal.d.ts +28 -2
  106. package/lib/util/internal.js +65 -8
  107. package/lib/util/jsonXmlTools.js +2 -4
  108. package/lib/util/mapKeys.d.ts +9 -9
  109. package/lib/util/mapKeys.js +13 -9
  110. package/lib/util/sfdc.d.ts +51 -51
  111. package/lib/util/sfdc.js +74 -79
  112. package/lib/util/sfdcUrl.d.ts +5 -19
  113. package/lib/util/sfdcUrl.js +40 -49
  114. package/lib/util/structuredWriter.d.ts +9 -0
  115. package/lib/util/structuredWriter.js +3 -0
  116. package/lib/util/zipWriter.d.ts +8 -6
  117. package/lib/util/zipWriter.js +13 -13
  118. package/lib/webOAuthServer.d.ts +20 -6
  119. package/lib/webOAuthServer.js +102 -56
  120. package/messageTransformer/messageTransformer.ts +93 -0
  121. package/messages/auth.md +9 -1
  122. package/messages/config.md +42 -6
  123. package/messages/connection.md +8 -0
  124. package/messages/core.md +10 -0
  125. package/messages/envVars.md +37 -3
  126. package/messages/org.md +21 -1
  127. package/messages/scratchOrgCreate.md +2 -6
  128. package/messages/scratchOrgErrorCodes.md +17 -1
  129. package/messages/scratchOrgInfoApi.md +9 -0
  130. package/messages/scratchOrgInfoGenerator.md +9 -1
  131. package/package.json +123 -46
  132. package/CHANGELOG.md +0 -1244
  133. package/lib/config/keychainConfig.d.ts +0 -19
  134. package/lib/config/keychainConfig.js +0 -43
  135. package/lib/globalInfo/accessors/aliasAccessor.d.ts +0 -83
  136. package/lib/globalInfo/accessors/aliasAccessor.js +0 -130
  137. package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
  138. package/lib/globalInfo/accessors/orgAccessor.js +0 -45
  139. package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
  140. package/lib/globalInfo/accessors/tokenAccessor.js +0 -35
  141. package/lib/globalInfo/globalInfoConfig.d.ts +0 -36
  142. package/lib/globalInfo/globalInfoConfig.js +0 -105
  143. package/lib/globalInfo/index.d.ts +0 -6
  144. package/lib/globalInfo/index.js +0 -29
  145. package/lib/globalInfo/sfdxDataHandler.d.ts +0 -43
  146. package/lib/globalInfo/sfdxDataHandler.js +0 -217
  147. package/lib/globalInfo/types.d.ts +0 -39
  148. package/lib/globalInfo/types.js +0 -10
  149. package/lib/sfdxProject.js +0 -557
  150. package/lib/util/fs.d.ts +0 -201
  151. package/lib/util/fs.js +0 -378
@@ -5,13 +5,17 @@
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
+ /* eslint-disable class-methods-use-this */
8
9
  Object.defineProperty(exports, "__esModule", { value: true });
9
10
  exports.SchemaPrinter = exports.SchemaPropertyRenderer = void 0;
10
11
  const ts_types_1 = require("@salesforce/ts-types");
11
- const sfdxError_1 = require("../sfdxError");
12
+ const sfError_1 = require("../sfError");
12
13
  /**
13
14
  * Renders schema properties. By default, this is simply an identity transform. Subclasses may provide more
14
15
  * interesting decorations of each values, such as ANSI coloring.
16
+ *
17
+ * @deprecated
18
+ *
15
19
  */
16
20
  class SchemaPropertyRenderer {
17
21
  /**
@@ -51,6 +55,9 @@ exports.SchemaPropertyRenderer = SchemaPropertyRenderer;
51
55
  /**
52
56
  * Prints a JSON schema in a human-friendly format.
53
57
  *
58
+ * @deprecated
59
+ * remaining reference: https://github.com/salesforcecli/plugin-data/blob/cc1bdfa2c707f93a6da96beea8117b25f9612d4a/src/commands/data/import/tree.ts#L75
60
+ *
54
61
  * ```
55
62
  * import chalk from 'chalk';
56
63
  * class MyPropertyRenderer extends SchemaPropertyRenderer {
@@ -78,7 +85,7 @@ class SchemaPrinter {
78
85
  // No need to add to messages, since this should never happen. In fact,
79
86
  // this will cause a test failure if there is a command that uses a schema
80
87
  // with no properties defined.
81
- throw new sfdxError_1.SfdxError('There is no purpose to print a schema with no properties or items');
88
+ throw new sfError_1.SfError('There is no purpose to print a schema with no properties or items');
82
89
  }
83
90
  const startLevel = 0;
84
91
  const add = this.addFn(startLevel);
@@ -178,40 +185,13 @@ class SchemaProperty {
178
185
  }
179
186
  const oneOfs = (0, ts_types_1.asJsonArray)(this.rawProperty.oneOf);
180
187
  if (oneOfs && !this.rawProperty.type) {
181
- this.rawProperty.type = oneOfs
182
- .map((value) => {
183
- return (0, ts_types_1.isJsonMap)(value) ? value.type || value.$ref : value;
184
- })
185
- .join('|');
188
+ this.rawProperty.type = oneOfs.map((value) => ((0, ts_types_1.isJsonMap)(value) ? value.type ?? value.$ref : value)).join('|');
186
189
  }
187
190
  // Handle items references
188
191
  if ((0, ts_types_1.isJsonMap)(this.items) && this.items && this.items.$ref) {
189
192
  Object.assign(this.items, resolveRef(this.schema, this.items));
190
193
  }
191
194
  }
192
- renderName() {
193
- return this.propertyRenderer.renderName(this.name);
194
- }
195
- renderTitle() {
196
- return this.propertyRenderer.renderTitle(this.title || '');
197
- }
198
- renderDescription() {
199
- return this.propertyRenderer.renderDescription(this.description || '');
200
- }
201
- renderType() {
202
- return this.propertyRenderer.renderType(this.type || '');
203
- }
204
- renderHeader() {
205
- return `${this.renderName()}(${this.renderType()}) - ${this.renderTitle()}: ${this.renderDescription()}`;
206
- }
207
- renderArrayHeader() {
208
- if (!this.items) {
209
- return '';
210
- }
211
- const minItems = this.minItems ? ` - min ${this.minItems}` : '';
212
- const prop = new SchemaProperty(this.logger, this.schema, 'items', this.items, this.propertyRenderer);
213
- return `items(${prop.renderType()}${minItems}) - ${prop.renderTitle()}: ${prop.renderDescription()}`;
214
- }
215
195
  get title() {
216
196
  return (0, ts_types_1.asString)(this.rawProperty.title);
217
197
  }
@@ -235,11 +215,34 @@ class SchemaProperty {
235
215
  }
236
216
  getProperty(key) {
237
217
  const properties = this.getProperties();
238
- return (0, ts_types_1.asJsonMap)(properties && properties[key]);
218
+ return (0, ts_types_1.asJsonMap)(properties?.[key]);
239
219
  }
240
220
  getProperties() {
241
221
  return (0, ts_types_1.asJsonMap)(this.rawProperty.properties);
242
222
  }
223
+ renderName() {
224
+ return this.propertyRenderer.renderName(this.name);
225
+ }
226
+ renderTitle() {
227
+ return this.propertyRenderer.renderTitle(this.title ?? '');
228
+ }
229
+ renderDescription() {
230
+ return this.propertyRenderer.renderDescription(this.description ?? '');
231
+ }
232
+ renderType() {
233
+ return this.propertyRenderer.renderType(this.type ?? '');
234
+ }
235
+ renderHeader() {
236
+ return `${this.renderName()}(${this.renderType()}) - ${this.renderTitle()}: ${this.renderDescription()}`;
237
+ }
238
+ renderArrayHeader() {
239
+ if (!this.items) {
240
+ return '';
241
+ }
242
+ const minItems = this.minItems ? ` - min ${this.minItems}` : '';
243
+ const prop = new SchemaProperty(this.logger, this.schema, 'items', this.items, this.propertyRenderer);
244
+ return `items(${prop.renderType()}${minItems}) - ${prop.renderTitle()}: ${prop.renderDescription()}`;
245
+ }
243
246
  }
244
247
  /**
245
248
  * Get the referenced definition by following the reference path on the current schema.
@@ -27,8 +27,8 @@ export declare class SchemaValidator {
27
27
  * Performs validation of JSON data against the schema located at the `schemaPath` value provided
28
28
  * at instantiation.
29
29
  *
30
- * **Throws** *{@link SfdxError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
31
- * **Throws** *{@link SfdxError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
30
+ * **Throws** *{@link SfError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
31
+ * **Throws** *{@link SfError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
32
32
  *
33
33
  * @param json A JSON value to validate against this instance's target schema.
34
34
  * @returns The validated JSON data.
@@ -38,18 +38,20 @@ export declare class SchemaValidator {
38
38
  * Performs validation of JSON data against the schema located at the `schemaPath` value provided
39
39
  * at instantiation.
40
40
  *
41
- * **Throws** *{@link SfdxError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
42
- * **Throws** *{@link SfdxError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
41
+ * **Throws** *{@link SfError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
42
+ * **Throws** *{@link SfError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
43
43
  *
44
44
  * @param json A JSON value to validate against this instance's target schema.
45
45
  * @returns The validated JSON data.
46
46
  */
47
- validateSync(json: AnyJson): AnyJson;
47
+ validateSync<T extends AnyJson>(json: T): T;
48
48
  /**
49
- * Loads local, external schemas from URIs relative to the local schema file. Does not support loading from
50
- * remote URIs. Returns a map of external schema local URIs to loaded schema JSON objects.
49
+ * Loads local, external schemas from URIs in the same directory as the local schema file.
50
+ * Does not support loading from remote URIs.
51
+ * Returns a map of external schema local URIs to loaded schema JSON objects.
51
52
  *
52
- * @param schema The main schema to validate against.
53
+ * @param schema The main schema to look up references ($ref) in.
54
+ * @returns An array of found referenced schemas.
53
55
  */
54
56
  private loadExternalSchemas;
55
57
  /**
@@ -60,9 +62,9 @@ export declare class SchemaValidator {
60
62
  private loadExternalSchema;
61
63
  /**
62
64
  * Get a string representation of the schema validation errors.
65
+ * Adds additional (human friendly) information to certain errors.
63
66
  *
64
- * @param errors An array of JsenValidateError objects.
65
- * @param schema The validation schema.
67
+ * @param errors An array of AJV (DefinedError) objects.
66
68
  */
67
69
  private getErrorsText;
68
70
  }
@@ -8,11 +8,10 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.SchemaValidator = void 0;
10
10
  const path = require("path");
11
+ const fs = require("fs");
12
+ const ajv_1 = require("ajv");
11
13
  const kit_1 = require("@salesforce/kit");
12
- const ts_types_1 = require("@salesforce/ts-types");
13
- const validator = require("jsen");
14
- const sfdxError_1 = require("../sfdxError");
15
- const fs_1 = require("../util/fs");
14
+ const sfError_1 = require("../sfError");
16
15
  /**
17
16
  * Loads a JSON schema and performs validations against JSON objects.
18
17
  */
@@ -33,7 +32,7 @@ class SchemaValidator {
33
32
  */
34
33
  async load() {
35
34
  if (!this.schema) {
36
- this.schema = await fs_1.fs.readJsonMap(this.schemaPath);
35
+ this.schema = (0, kit_1.parseJsonMap)(await fs.promises.readFile(this.schemaPath, 'utf8'));
37
36
  this.logger.debug(`Schema loaded for ${this.schemaPath}`);
38
37
  }
39
38
  return this.schema;
@@ -43,7 +42,7 @@ class SchemaValidator {
43
42
  */
44
43
  loadSync() {
45
44
  if (!this.schema) {
46
- this.schema = fs_1.fs.readJsonMapSync(this.schemaPath);
45
+ this.schema = (0, kit_1.parseJsonMap)(fs.readFileSync(this.schemaPath, 'utf8'));
47
46
  this.logger.debug(`Schema loaded for ${this.schemaPath}`);
48
47
  }
49
48
  return this.schema;
@@ -52,8 +51,8 @@ class SchemaValidator {
52
51
  * Performs validation of JSON data against the schema located at the `schemaPath` value provided
53
52
  * at instantiation.
54
53
  *
55
- * **Throws** *{@link SfdxError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
56
- * **Throws** *{@link SfdxError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
54
+ * **Throws** *{@link SfError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
55
+ * **Throws** *{@link SfError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
57
56
  *
58
57
  * @param json A JSON value to validate against this instance's target schema.
59
58
  * @returns The validated JSON data.
@@ -66,8 +65,8 @@ class SchemaValidator {
66
65
  * Performs validation of JSON data against the schema located at the `schemaPath` value provided
67
66
  * at instantiation.
68
67
  *
69
- * **Throws** *{@link SfdxError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
70
- * **Throws** *{@link SfdxError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
68
+ * **Throws** *{@link SfError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
69
+ * **Throws** *{@link SfError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
71
70
  *
72
71
  * @param json A JSON value to validate against this instance's target schema.
73
72
  * @returns The validated JSON data.
@@ -75,47 +74,58 @@ class SchemaValidator {
75
74
  validateSync(json) {
76
75
  const schema = this.loadSync();
77
76
  const externalSchemas = this.loadExternalSchemas(schema);
77
+ const ajv = new ajv_1.default({
78
+ allErrors: true,
79
+ allowUnionTypes: true,
80
+ schemas: externalSchemas,
81
+ useDefaults: true,
82
+ // TODO: We may someday want to enable strictSchema. This is disabled for now
83
+ // because the CLI team does not "own" the @salesforce/schemas repository.
84
+ // Invalid schema would cause errors wherever SchemaValidator is used.
85
+ strictSchema: false,
86
+ // If we end up getting an npm-shrinkwrap working in the future we could turn this back off.
87
+ // https://github.com/forcedotcom/cli/issues/1493
88
+ validateSchema: false,
89
+ });
90
+ // JSEN to AJV migration note - regarding the following "TODO":
91
+ // I don't think that AJV has a way to throw an error if an additional property exists in the data
92
+ // It does however have a top level option for `removeAdditional` https://ajv.js.org/options.html#removeadditional
93
+ // Regardless, this would be a breaking changes and I do not think it should be implemented.
78
94
  // TODO: We should default to throw an error when a property is specified
79
95
  // that is not in the schema, but the only option to do this right now is
80
96
  // to specify "removeAdditional: false" in every object.
81
- const validate = validator(schema, {
82
- greedy: true,
83
- schemas: externalSchemas,
84
- });
85
- if (!validate(json)) {
97
+ const validate = ajv.compile(schema);
98
+ // AJV will modify the original json object. We need to make a clone of the
99
+ // json to keep this backwards compatible with JSEN functionality
100
+ const jsonClone = JSON.parse(JSON.stringify(json));
101
+ const valid = validate(jsonClone);
102
+ if (!valid) {
86
103
  if (validate.errors) {
87
- const errors = this.getErrorsText(validate.errors, schema);
88
- throw new sfdxError_1.SfdxError(`Validation errors:\n${errors}`, 'ValidationSchemaFieldError');
104
+ const errors = this.getErrorsText(validate.errors);
105
+ throw new sfError_1.SfError(`Validation errors:\n${errors}`, 'ValidationSchemaFieldError');
89
106
  }
90
107
  else {
91
- throw new sfdxError_1.SfdxError('Unknown schema validation error', 'ValidationSchemaUnknownError');
108
+ throw new sfError_1.SfError('Unknown schema validation error', 'ValidationSchemaUnknownError');
92
109
  }
93
110
  }
94
- return validate.build(json);
111
+ // We return the cloned JSON because it will have defaults included
112
+ // This is configured with the 'useDefaults' option above.
113
+ return jsonClone;
95
114
  }
96
115
  /**
97
- * Loads local, external schemas from URIs relative to the local schema file. Does not support loading from
98
- * remote URIs. Returns a map of external schema local URIs to loaded schema JSON objects.
116
+ * Loads local, external schemas from URIs in the same directory as the local schema file.
117
+ * Does not support loading from remote URIs.
118
+ * Returns a map of external schema local URIs to loaded schema JSON objects.
99
119
  *
100
- * @param schema The main schema to validate against.
120
+ * @param schema The main schema to look up references ($ref) in.
121
+ * @returns An array of found referenced schemas.
101
122
  */
102
123
  loadExternalSchemas(schema) {
103
- const externalSchemas = {};
104
- const schemas = (0, kit_1.getJsonValuesByName)(schema, '$ref')
105
- // eslint-disable-next-line no-useless-escape
106
- .map((ref) => ref && RegExp(/([\w\.]+)#/).exec(ref))
107
- .map((match) => match && match[1])
124
+ return (0, kit_1.getJsonValuesByName)(schema, '$ref')
125
+ .map((ref) => ref && RegExp(/([\w\.]+)#/).exec(ref)) // eslint-disable-line no-useless-escape
126
+ .map((match) => match?.[1])
108
127
  .filter((uri) => !!uri)
109
128
  .map((uri) => this.loadExternalSchema(uri));
110
- schemas.forEach((externalSchema) => {
111
- if ((0, ts_types_1.isString)(externalSchema.id)) {
112
- externalSchemas[externalSchema.id] = externalSchema;
113
- }
114
- else {
115
- throw new sfdxError_1.SfdxError(`Unexpected external schema id type: ${typeof externalSchema.id}`, 'ValidationSchemaTypeError');
116
- }
117
- });
118
- return externalSchemas;
119
129
  }
120
130
  /**
121
131
  * Load another schema relative to the primary schema when referenced. Only supports local schema URIs.
@@ -125,63 +135,33 @@ class SchemaValidator {
125
135
  loadExternalSchema(uri) {
126
136
  const schemaPath = path.join(this.schemasDir, `${uri}.json`);
127
137
  try {
128
- return fs_1.fs.readJsonMapSync(schemaPath);
138
+ return (0, kit_1.parseJsonMap)(fs.readFileSync(schemaPath, 'utf8'));
129
139
  }
130
140
  catch (err) {
131
141
  if (err.code === 'ENOENT') {
132
- throw new sfdxError_1.SfdxError(`Schema not found: ${schemaPath}`, 'ValidationSchemaNotFound');
142
+ throw new sfError_1.SfError(`Schema not found: ${schemaPath}`, 'ValidationSchemaNotFound');
133
143
  }
134
144
  throw err;
135
145
  }
136
146
  }
137
147
  /**
138
148
  * Get a string representation of the schema validation errors.
149
+ * Adds additional (human friendly) information to certain errors.
139
150
  *
140
- * @param errors An array of JsenValidateError objects.
141
- * @param schema The validation schema.
151
+ * @param errors An array of AJV (DefinedError) objects.
142
152
  */
143
- getErrorsText(errors, schema) {
153
+ // eslint-disable-next-line class-methods-use-this
154
+ getErrorsText(errors) {
144
155
  return errors
145
156
  .map((error) => {
146
- // eslint-disable-next-line no-useless-escape
147
- const property = RegExp(/^([a-zA-Z0-9\.]+)\.([a-zA-Z0-9]+)$/).exec(error.path);
148
- const getPropValue = (prop) => {
149
- const reducer = (obj, name) => {
150
- if (!(0, ts_types_1.isJsonMap)(obj))
151
- return;
152
- if ((0, ts_types_1.isJsonMap)(obj.properties))
153
- return obj.properties[name];
154
- if (name === '0')
155
- return (0, ts_types_1.asJsonArray)(obj.items);
156
- return obj[name] || obj[prop];
157
- };
158
- return error.path.split('.').reduce(reducer, schema);
159
- };
160
- const getEnumValues = () => {
161
- const enumSchema = (0, ts_types_1.asJsonMap)(getPropValue('enum'));
162
- return (enumSchema && (0, ts_types_1.getJsonArray)(enumSchema, 'enum', []).join(', ')) || '';
163
- };
157
+ const msg = `${error.schemaPath}: ${error.message}`;
164
158
  switch (error.keyword) {
165
159
  case 'additionalProperties':
166
- // Missing Typing
167
- // eslint-disable-next-line no-case-declarations
168
- const additionalProperties = (0, ts_types_1.get)(error, 'additionalProperties');
169
- return `${error.path} should NOT have additional properties '${additionalProperties}'`;
170
- case 'required':
171
- if (property) {
172
- return `${property[1]} should have required property ${property[2]}`;
173
- }
174
- return `should have required property '${error.path}'`;
175
- case 'oneOf':
176
- return `${error.path} should match exactly one schema in oneOf`;
160
+ return `${msg} '${error.params.additionalProperty}'`;
177
161
  case 'enum':
178
- return `${error.path} should be equal to one of the allowed values ${getEnumValues()}`;
179
- case 'type': {
180
- const _path = error.path === '' ? 'Root of JSON object' : error.path;
181
- return `${_path} is an invalid type. Expected type [${getPropValue('type')}]`;
182
- }
162
+ return `${msg} '${error.params.allowedValues.join(', ')}'`;
183
163
  default:
184
- return `${error.path} invalid ${error.keyword}`;
164
+ return msg;
185
165
  }
186
166
  })
187
167
  .join('\n');
@@ -13,10 +13,11 @@ import { JsonMap } from '@salesforce/ts-types';
13
13
  * const messages = Messages.load('myPackageName', 'myBundleName');
14
14
  *
15
15
  * // To throw a non-bundle based error:
16
- * throw new SfdxError(message.getMessage('myError'), 'MyErrorName');
16
+ * throw new SfError(message.getMessage('myError'), 'MyErrorName');
17
17
  * ```
18
18
  */
19
- export declare class SfdxError extends NamedError {
19
+ export declare class SfError extends NamedError {
20
+ #private;
20
21
  /**
21
22
  * Action messages. Hints to the users regarding what can be done to fix related issues.
22
23
  */
@@ -31,46 +32,37 @@ export declare class SfdxError extends NamedError {
31
32
  context?: string;
32
33
  data?: unknown;
33
34
  /**
34
- * Some errors support `error.code` instead of `error.name`. This keeps backwards compatability.
35
- */
36
- private _code?;
37
- /**
38
- * Create an SfdxError.
35
+ * Create an SfError.
39
36
  *
40
37
  * @param message The error message.
41
- * @param name The error name. Defaults to 'SfdxError'.
38
+ * @param name The error name. Defaults to 'SfError'.
42
39
  * @param actions The action message(s).
43
40
  * @param exitCodeOrCause The exit code which will be used by SfdxCommand or he underlying error that caused this error to be raised.
44
41
  * @param cause The underlying error that caused this error to be raised.
45
42
  */
46
43
  constructor(message: string, name?: string, actions?: string[], exitCodeOrCause?: number | Error, cause?: Error);
44
+ get code(): string | undefined | any;
45
+ set code(code: string);
47
46
  /**
48
- * Convert an Error to an SfdxError.
47
+ * Convert an Error to an SfError.
49
48
  *
50
49
  * @param err The error to convert.
51
50
  */
52
- static wrap(err: Error | string): SfdxError;
53
- get code(): string | undefined | any;
54
- set code(code: string);
51
+ static wrap(err: Error | string): SfError;
55
52
  /**
56
53
  * Sets the context of the error. For convenience `this` object is returned.
57
54
  *
58
55
  * @param context The command name.
59
56
  */
60
- setContext(context: string): SfdxError;
57
+ setContext(context: string): SfError;
61
58
  /**
62
59
  * An additional payload for the error. For convenience `this` object is returned.
63
60
  *
64
61
  * @param data The payload data.
65
62
  */
66
- setData(data: unknown): SfdxError;
63
+ setData(data: unknown): SfError;
67
64
  /**
68
- * Convert an {@link SfdxError} state to an object. Returns a plain object representing the state of this error.
65
+ * Convert an {@link SfError} state to an object. Returns a plain object representing the state of this error.
69
66
  */
70
67
  toObject(): JsonMap;
71
- /**
72
- * @deprecated Does nothing. Do not use. This is kept around to support older versions of SfdxCommand.
73
- * @param commandName
74
- */
75
- setCommandName(): void;
76
68
  }
@@ -5,8 +5,20 @@
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
14
+ if (kind === "m") throw new TypeError("Private method is not writable");
15
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
16
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
17
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
18
+ };
19
+ var _SfError_code;
8
20
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.SfdxError = void 0;
21
+ exports.SfError = void 0;
10
22
  const kit_1 = require("@salesforce/kit");
11
23
  const ts_types_1 = require("@salesforce/ts-types");
12
24
  /**
@@ -22,22 +34,26 @@ const ts_types_1 = require("@salesforce/ts-types");
22
34
  * const messages = Messages.load('myPackageName', 'myBundleName');
23
35
  *
24
36
  * // To throw a non-bundle based error:
25
- * throw new SfdxError(message.getMessage('myError'), 'MyErrorName');
37
+ * throw new SfError(message.getMessage('myError'), 'MyErrorName');
26
38
  * ```
27
39
  */
28
- class SfdxError extends kit_1.NamedError {
40
+ class SfError extends kit_1.NamedError {
29
41
  /**
30
- * Create an SfdxError.
42
+ * Create an SfError.
31
43
  *
32
44
  * @param message The error message.
33
- * @param name The error name. Defaults to 'SfdxError'.
45
+ * @param name The error name. Defaults to 'SfError'.
34
46
  * @param actions The action message(s).
35
47
  * @param exitCodeOrCause The exit code which will be used by SfdxCommand or he underlying error that caused this error to be raised.
36
48
  * @param cause The underlying error that caused this error to be raised.
37
49
  */
38
50
  constructor(message, name, actions, exitCodeOrCause, cause) {
39
51
  cause = exitCodeOrCause instanceof Error ? exitCodeOrCause : cause;
40
- super(name || 'SfdxError', message || name, cause);
52
+ super(name ?? 'SfError', message || name, cause);
53
+ /**
54
+ * Some errors support `error.code` instead of `error.name`. This keeps backwards compatability.
55
+ */
56
+ _SfError_code.set(this, void 0);
41
57
  this.actions = actions;
42
58
  if (typeof exitCodeOrCause === 'number') {
43
59
  this.exitCode = exitCodeOrCause;
@@ -46,31 +62,31 @@ class SfdxError extends kit_1.NamedError {
46
62
  this.exitCode = 1;
47
63
  }
48
64
  }
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
+ get code() {
67
+ return __classPrivateFieldGet(this, _SfError_code, "f") ?? this.name;
68
+ }
69
+ set code(code) {
70
+ __classPrivateFieldSet(this, _SfError_code, code, "f");
71
+ }
49
72
  /**
50
- * Convert an Error to an SfdxError.
73
+ * Convert an Error to an SfError.
51
74
  *
52
75
  * @param err The error to convert.
53
76
  */
54
77
  static wrap(err) {
55
78
  if ((0, ts_types_1.isString)(err)) {
56
- return new SfdxError(err);
79
+ return new SfError(err);
57
80
  }
58
- if (err instanceof SfdxError) {
81
+ if (err instanceof SfError) {
59
82
  return err;
60
83
  }
61
- const sfdxError = new SfdxError(err.message, err.name, undefined, err);
84
+ const sfError = new SfError(err.message, err.name, undefined, err);
62
85
  // If the original error has a code, use that instead of name.
63
86
  if ((0, ts_types_1.hasString)(err, 'code')) {
64
- sfdxError.code = err.code;
87
+ sfError.code = err.code;
65
88
  }
66
- return sfdxError;
67
- }
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
- get code() {
70
- return this._code || this.name;
71
- }
72
- set code(code) {
73
- this._code = code;
89
+ return sfError;
74
90
  }
75
91
  /**
76
92
  * Sets the context of the error. For convenience `this` object is returned.
@@ -91,7 +107,7 @@ class SfdxError extends kit_1.NamedError {
91
107
  return this;
92
108
  }
93
109
  /**
94
- * Convert an {@link SfdxError} state to an object. Returns a plain object representing the state of this error.
110
+ * Convert an {@link SfError} state to an object. Returns a plain object representing the state of this error.
95
111
  */
96
112
  toObject() {
97
113
  const obj = {
@@ -104,18 +120,12 @@ class SfdxError extends kit_1.NamedError {
104
120
  obj.context = this.context;
105
121
  }
106
122
  if (this.data) {
107
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
108
124
  obj.data = this.data;
109
125
  }
110
126
  return obj;
111
127
  }
112
- /**
113
- * @deprecated Does nothing. Do not use. This is kept around to support older versions of SfdxCommand.
114
- * @param commandName
115
- */
116
- setCommandName() {
117
- /** Do nothing. */
118
- }
119
128
  }
120
- exports.SfdxError = SfdxError;
121
- //# sourceMappingURL=sfdxError.js.map
129
+ exports.SfError = SfError;
130
+ _SfError_code = new WeakMap();
131
+ //# sourceMappingURL=sfError.js.map