@salesforce/core 2.36.2 → 2.37.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [2.37.0](https://github.com/forcedotcom/sfdx-core/compare/v2.36.4...v2.37.0) (2022-05-03)
6
+
7
+ ### Features
8
+
9
+ - new cloneSandbox method ([69073dd](https://github.com/forcedotcom/sfdx-core/commit/69073dd71ee7372d13c86aaf052c798a4bea5176))
10
+
11
+ ### Bug Fixes
12
+
13
+ - use tooling api ([c32f19d](https://github.com/forcedotcom/sfdx-core/commit/c32f19d8de6a953f8390fd853d3be023db01d890))
14
+
15
+ ### [2.36.4](https://github.com/forcedotcom/sfdx-core/compare/v2.36.3...v2.36.4) (2022-04-28)
16
+
17
+ ### Bug Fixes
18
+
19
+ - disable strictSchema ([2f44345](https://github.com/forcedotcom/sfdx-core/commit/2f44345d6dc11673b921b6c65cd548b7f31a0dad))
20
+ - replace JSEN with AJV (wip) ([87ca60c](https://github.com/forcedotcom/sfdx-core/commit/87ca60c48a82618008d761bdd6086727f712aeff))
21
+ - schema comment ([a0868d1](https://github.com/forcedotcom/sfdx-core/commit/a0868d157fbc8757cdbd28472aecfbf597c0f9d2))
22
+ - test failures and cleanup ([95c0710](https://github.com/forcedotcom/sfdx-core/commit/95c0710938b399c858cddfdf5100892ee2e7cf90))
23
+
24
+ ### [2.36.3](https://github.com/forcedotcom/sfdx-core/compare/v2.36.2...v2.36.3) (2022-04-21)
25
+
26
+ ### Bug Fixes
27
+
28
+ - log rotation errors ([#562](https://github.com/forcedotcom/sfdx-core/issues/562)) ([16a5423](https://github.com/forcedotcom/sfdx-core/commit/16a5423079daad37e1ada6d47767923ec0b7cc94))
29
+
5
30
  ### [2.36.2](https://github.com/forcedotcom/sfdx-core/compare/v2.36.1...v2.36.2) (2022-04-20)
6
31
 
7
32
  ### [2.36.1](https://github.com/forcedotcom/sfdx-core/compare/v2.36.0...v2.36.1) (2022-04-14)
@@ -16,7 +16,6 @@ const sfdxError_1 = require("../sfdxError");
16
16
  const sfdc_1 = require("../util/sfdc");
17
17
  const sfdcUrl_1 = require("../util/sfdcUrl");
18
18
  const configFile_1 = require("./configFile");
19
- const log = logger_1.Logger.childFromRoot('core:config');
20
19
  const SFDX_CONFIG_FILE_NAME = 'sfdx-config.json';
21
20
  /**
22
21
  * The files where sfdx config values are stored for projects and the global space.
@@ -64,9 +63,12 @@ class Config extends configFile_1.ConfigFile {
64
63
  */
65
64
  static addAllowedProperties(metas) {
66
65
  const currentMetaKeys = Object.keys(Config.propertyConfigMap);
66
+ // If logger is needed elsewhere in this file, do not move this outside of the Config class.
67
+ // It was causing issues with Bunyan log rotation. See https://github.com/forcedotcom/sfdx-core/pull/562
68
+ const logger = logger_1.Logger.childFromRoot('core:config');
67
69
  metas.forEach((meta) => {
68
70
  if (currentMetaKeys.includes(meta.key)) {
69
- log.info(`Key ${meta.key} already exists in allowedProperties, skipping.`);
71
+ logger.info(`Key ${meta.key} already exists in allowedProperties, skipping.`);
70
72
  return;
71
73
  }
72
74
  Config.allowedProperties.push(meta);
package/lib/org.d.ts CHANGED
@@ -105,6 +105,17 @@ export declare class Org extends AsyncCreatable<Org.Options> {
105
105
  wait?: Duration;
106
106
  interval?: Duration;
107
107
  }): Promise<SandboxProcessObject>;
108
+ /**
109
+ *
110
+ * @param sandboxReq SandboxRequest options to create the sandbox with
111
+ * @param sandboxName
112
+ * @param options Wait: The amount of time to wait before timing out, defaults to 0, Interval: The time interval between polling defaults to 30 seconds
113
+ * @returns {SandboxProcessObject} the newly created sandbox process object
114
+ */
115
+ cloneSandbox(sandboxReq: SandboxRequest, sandboxName: string, options: {
116
+ wait?: Duration;
117
+ interval?: Duration;
118
+ }): Promise<SandboxProcessObject>;
108
119
  /**
109
120
  * Creates a scratchOrg
110
121
  * 'this' needs to be a valid dev-hub
@@ -358,6 +369,12 @@ export declare class Org extends AsyncCreatable<Org.Options> {
358
369
  * @private
359
370
  */
360
371
  private querySandboxProcess;
372
+ /**
373
+ *
374
+ * @param sandboxNameIn
375
+ * @returns sandboxInfoId
376
+ */
377
+ private querySandboxInfoIdBySandboxName;
361
378
  /**
362
379
  * determines if the sandbox has successfully been created
363
380
  *
package/lib/org.js CHANGED
@@ -100,6 +100,18 @@ class Org extends kit_1.AsyncCreatable {
100
100
  pollInterval,
101
101
  });
102
102
  }
103
+ /**
104
+ *
105
+ * @param sandboxReq SandboxRequest options to create the sandbox with
106
+ * @param sandboxName
107
+ * @param options Wait: The amount of time to wait before timing out, defaults to 0, Interval: The time interval between polling defaults to 30 seconds
108
+ * @returns {SandboxProcessObject} the newly created sandbox process object
109
+ */
110
+ async cloneSandbox(sandboxReq, sandboxName, options) {
111
+ sandboxReq.SourceId = await this.querySandboxInfoIdBySandboxName(sandboxName);
112
+ this.logger.debug('Clone sandbox sourceId %s', sandboxReq.SourceId);
113
+ return this.createSandbox(sandboxReq, options);
114
+ }
103
115
  /**
104
116
  * Creates a scratchOrg
105
117
  * 'this' needs to be a valid dev-hub
@@ -861,6 +873,27 @@ class Org extends kit_1.AsyncCreatable {
861
873
  tooling: true,
862
874
  });
863
875
  }
876
+ /**
877
+ *
878
+ * @param sandboxNameIn
879
+ * @returns sandboxInfoId
880
+ */
881
+ async querySandboxInfoIdBySandboxName(sandboxNameIn) {
882
+ var _a;
883
+ this.logger.debug('QuerySandboxInfoIdBySandboxName called with SandboxName: %s ', sandboxNameIn);
884
+ const queryStr = `SELECT Id, SandboxName FROM SandboxInfo WHERE SandboxName='${sandboxNameIn}'`;
885
+ const queryResult = await this.connection.tooling.query(queryStr);
886
+ this.logger.debug('Return from calling queryToolingApi: %s ', JSON.stringify(queryResult));
887
+ if (((_a = queryResult === null || queryResult === void 0 ? void 0 : queryResult.records) === null || _a === void 0 ? void 0 : _a.length) === 1) {
888
+ return (queryResult === null || queryResult === void 0 ? void 0 : queryResult.records[0]).Id;
889
+ }
890
+ else if (queryResult.records && queryResult.records.length > 1) {
891
+ throw sfdxError_1.SfdxError.create('@salesforce/core', 'org', 'MultiSandboxInfoNotFoundBySandboxName', [sandboxNameIn]);
892
+ }
893
+ else {
894
+ throw sfdxError_1.SfdxError.create('@salesforce/core', 'org', 'SandboxInfoNotFoundBySandboxName', [sandboxNameIn]);
895
+ }
896
+ }
864
897
  /**
865
898
  * determines if the sandbox has successfully been created
866
899
  *
@@ -46,10 +46,12 @@ export declare class SchemaValidator {
46
46
  */
47
47
  validateSync(json: AnyJson): AnyJson;
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
  }
@@ -7,12 +7,11 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.SchemaValidator = void 0;
10
+ const fs = require("fs");
10
11
  const path = require("path");
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
14
  const sfdxError_1 = require("../sfdxError");
15
- const fs_1 = require("../util/fs");
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 = 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 = 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;
@@ -75,47 +74,54 @@ 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
+ schemas: externalSchemas,
80
+ useDefaults: true,
81
+ // TODO: We may someday want to enable strictSchema. This is disabled for now
82
+ // because the CLI team does not "own" the @salesforce/schemas repository.
83
+ // Invalid schema would cause errors wherever SchemaValidator is used.
84
+ strictSchema: false,
85
+ });
86
+ // JSEN to AJV migration note - regarding the following "TODO":
87
+ // I don't think that AJV has a way to throw an error if an additional property exists in the data
88
+ // It does however have a top level option for `removeAdditional` https://ajv.js.org/options.html#removeadditional
89
+ // Regardless, this would be a breaking changes and I do not think it should be implemented.
78
90
  // TODO: We should default to throw an error when a property is specified
79
91
  // that is not in the schema, but the only option to do this right now is
80
92
  // to specify "removeAdditional: false" in every object.
81
- const validate = validator(schema, {
82
- greedy: true,
83
- schemas: externalSchemas,
84
- });
85
- if (!validate(json)) {
93
+ const validate = ajv.compile(schema);
94
+ // AJV will modify the original json object. We need to make a clone of the
95
+ // json to keep this backwards compatible with JSEN functionality
96
+ const jsonClone = JSON.parse(JSON.stringify(json));
97
+ const valid = validate(jsonClone);
98
+ if (!valid) {
86
99
  if (validate.errors) {
87
- const errors = this.getErrorsText(validate.errors, schema);
100
+ const errors = this.getErrorsText(validate.errors);
88
101
  throw new sfdxError_1.SfdxError(`Validation errors:\n${errors}`, 'ValidationSchemaFieldErrors');
89
102
  }
90
103
  else {
91
104
  throw new sfdxError_1.SfdxError('Unknown schema validation error', 'ValidationSchemaUnknown');
92
105
  }
93
106
  }
94
- return validate.build(json);
107
+ // We return the cloned JSON because it will have defaults included
108
+ // This is configured with the 'useDefaults' option above.
109
+ return jsonClone;
95
110
  }
96
111
  /**
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.
112
+ * Loads local, external schemas from URIs in the same directory as the local schema file.
113
+ * Does not support loading from remote URIs.
114
+ * Returns a map of external schema local URIs to loaded schema JSON objects.
99
115
  *
100
- * @param schema The main schema to validate against.
116
+ * @param schema The main schema to look up references ($ref) in.
117
+ * @returns An array of found referenced schemas.
101
118
  */
102
119
  loadExternalSchemas(schema) {
103
- const externalSchemas = {};
104
- const schemas = kit_1.getJsonValuesByName(schema, '$ref')
105
- // eslint-disable-next-line no-useless-escape
106
- .map((ref) => ref && RegExp(/([\w\.]+)#/).exec(ref))
120
+ return kit_1.getJsonValuesByName(schema, '$ref')
121
+ .map((ref) => ref && RegExp(/([\w\.]+)#/).exec(ref)) // eslint-disable-line no-useless-escape
107
122
  .map((match) => match && match[1])
108
123
  .filter((uri) => !!uri)
109
124
  .map((uri) => this.loadExternalSchema(uri));
110
- schemas.forEach((externalSchema) => {
111
- if (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
125
  }
120
126
  /**
121
127
  * Load another schema relative to the primary schema when referenced. Only supports local schema URIs.
@@ -125,7 +131,7 @@ class SchemaValidator {
125
131
  loadExternalSchema(uri) {
126
132
  const schemaPath = path.join(this.schemasDir, `${uri}.json`);
127
133
  try {
128
- return fs_1.fs.readJsonMapSync(schemaPath);
134
+ return kit_1.parseJsonMap(fs.readFileSync(schemaPath, 'utf8'));
129
135
  }
130
136
  catch (err) {
131
137
  if (err.code === 'ENOENT') {
@@ -136,52 +142,21 @@ class SchemaValidator {
136
142
  }
137
143
  /**
138
144
  * Get a string representation of the schema validation errors.
145
+ * Adds additional (human friendly) information to certain errors.
139
146
  *
140
- * @param errors An array of JsenValidateError objects.
141
- * @param schema The validation schema.
147
+ * @param errors An array of AJV (DefinedError) objects.
142
148
  */
143
- getErrorsText(errors, schema) {
149
+ getErrorsText(errors) {
144
150
  return errors
145
151
  .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 (!ts_types_1.isJsonMap(obj))
151
- return;
152
- if (ts_types_1.isJsonMap(obj.properties))
153
- return obj.properties[name];
154
- if (name === '0')
155
- return 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 = ts_types_1.asJsonMap(getPropValue('enum'));
162
- return (enumSchema && ts_types_1.getJsonArray(enumSchema, 'enum', []).join(', ')) || '';
163
- };
152
+ const msg = `${error.schemaPath}: ${error.message}`;
164
153
  switch (error.keyword) {
165
154
  case 'additionalProperties':
166
- // Missing Typing
167
- // eslint-disable-next-line no-case-declarations
168
- const additionalProperties = 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`;
155
+ return `${msg} '${error.params.additionalProperty}'`;
177
156
  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
- }
157
+ return `${msg} '${error.params.allowedValues.join(', ')}'`;
183
158
  default:
184
- return `${error.path} invalid ${error.keyword}`;
159
+ return msg;
185
160
  }
186
161
  })
187
162
  .join('\n');
@@ -81,7 +81,7 @@ export declare class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
81
81
  * Set the `SFDX_PROJECT_JSON_VALIDATION` environment variable to `true` to throw an error when schema validation fails.
82
82
  * A warning is logged by default when the file is invalid.
83
83
  *
84
- * ***See*** [sfdx-project.schema.json] (https://raw.githubusercontent.com/forcedotcom/schemas/master/schemas/sfdx-project.schema.json)
84
+ * ***See*** [sfdx-project.schema.json] (https://github.com/forcedotcom/schemas/blob/main/sfdx-project.schema.json)
85
85
  */
86
86
  schemaValidate(): Promise<void>;
87
87
  /**
@@ -95,7 +95,7 @@ export declare class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
95
95
  * Set the `SFDX_PROJECT_JSON_VALIDATION` environment variable to `true` to throw an error when schema validation fails.
96
96
  * A warning is logged by default when the file is invalid.
97
97
  *
98
- * ***See*** [sfdx-project.schema.json] (https://raw.githubusercontent.com/forcedotcom/schemas/master/schemas/sfdx-project.schema.json)
98
+ * ***See*** [sfdx-project.schema.json] (https://github.com/forcedotcom/schemas/blob/main/sfdx-project.schema.json)
99
99
  */
100
100
  schemaValidateSync(): void;
101
101
  /**
@@ -87,7 +87,7 @@ class SfdxProjectJson extends configFile_1.ConfigFile {
87
87
  * Set the `SFDX_PROJECT_JSON_VALIDATION` environment variable to `true` to throw an error when schema validation fails.
88
88
  * A warning is logged by default when the file is invalid.
89
89
  *
90
- * ***See*** [sfdx-project.schema.json] (https://raw.githubusercontent.com/forcedotcom/schemas/master/schemas/sfdx-project.schema.json)
90
+ * ***See*** [sfdx-project.schema.json] (https://github.com/forcedotcom/schemas/blob/main/sfdx-project.schema.json)
91
91
  */
92
92
  async schemaValidate() {
93
93
  if (!this.hasRead) {
@@ -98,7 +98,6 @@ class SfdxProjectJson extends configFile_1.ConfigFile {
98
98
  try {
99
99
  const projectJsonSchemaPath = require.resolve('@salesforce/schemas/sfdx-project.schema.json');
100
100
  const validator = new validator_1.SchemaValidator(this.logger, projectJsonSchemaPath);
101
- await validator.load();
102
101
  await validator.validate(this.getContents());
103
102
  }
104
103
  catch (err) {
@@ -129,7 +128,7 @@ class SfdxProjectJson extends configFile_1.ConfigFile {
129
128
  * Set the `SFDX_PROJECT_JSON_VALIDATION` environment variable to `true` to throw an error when schema validation fails.
130
129
  * A warning is logged by default when the file is invalid.
131
130
  *
132
- * ***See*** [sfdx-project.schema.json] (https://raw.githubusercontent.com/forcedotcom/schemas/master/schemas/sfdx-project.schema.json)
131
+ * ***See*** [sfdx-project.schema.json] (https://github.com/forcedotcom/schemas/blob/main/sfdx-project.schema.json)
133
132
  */
134
133
  schemaValidateSync() {
135
134
  if (!this.hasRead) {
@@ -140,7 +139,6 @@ class SfdxProjectJson extends configFile_1.ConfigFile {
140
139
  try {
141
140
  const projectJsonSchemaPath = require.resolve('@salesforce/schemas/sfdx-project.schema.json');
142
141
  const validator = new validator_1.SchemaValidator(this.logger, projectJsonSchemaPath);
143
- validator.loadSync();
144
142
  validator.validateSync(this.getContents());
145
143
  }
146
144
  catch (err) {
package/messages/org.json CHANGED
@@ -11,5 +11,7 @@
11
11
  "MissingAuthUsername": "The sandbox %s does not have an authorized username.",
12
12
  "OrgPollingTimeout": "Sandbox status is %s; timed out waiting for completion.",
13
13
  "SandboxProcessNotFoundBySandboxName": "We can't find a SandboxProcess with the SandboxName %s.",
14
- "MultiSandboxProcessNotFoundBySandboxName": "We found more than one SandboxProcess with the SandboxName %s."
14
+ "SandboxInfoNotFoundBySandboxName": "We can't find a SandboxInfo with the SandboxName %s.",
15
+ "MultiSandboxProcessNotFoundBySandboxName": "We found more than one SandboxProcess with the SandboxName %s.",
16
+ "MultiSandboxInfoNotFoundBySandboxName": "We found more than one SandboxInfo with the SandboxName %s."
15
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "2.36.2",
3
+ "version": "2.37.0",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -41,12 +41,12 @@
41
41
  "@types/graceful-fs": "^4.1.5",
42
42
  "@types/jsforce": "^1.9.41",
43
43
  "@types/mkdirp": "^1.0.1",
44
+ "ajv": "^8.11.0",
44
45
  "archiver": "^5.3.0",
45
46
  "debug": "^3.1.0",
46
47
  "faye": "^1.4.0",
47
48
  "graceful-fs": "^4.2.4",
48
49
  "js2xmlparser": "^4.0.1",
49
- "jsen": "0.6.6",
50
50
  "jsforce": "^1.11.0",
51
51
  "jsonwebtoken": "8.5.0",
52
52
  "mkdirp": "1.0.4",
@@ -60,7 +60,6 @@
60
60
  "@salesforce/ts-sinon": "1.3.21",
61
61
  "@types/archiver": "^5.1.1",
62
62
  "@types/debug": "0.0.30",
63
- "@types/jsen": "0.0.19",
64
63
  "@types/jsonwebtoken": "8.3.2",
65
64
  "@types/semver": "^7.3.9",
66
65
  "@types/shelljs": "0.7.8",