@salesforce/core 2.36.3 → 2.37.1

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.1](https://github.com/forcedotcom/sfdx-core/compare/v2.37.0...v2.37.1) (2022-05-04)
6
+
7
+ ### Bug Fixes
8
+
9
+ - disable schemaValidation ([#577](https://github.com/forcedotcom/sfdx-core/issues/577)) ([b2fe619](https://github.com/forcedotcom/sfdx-core/commit/b2fe619586dcba3de97100bf2a73a2d142883c7d))
10
+
11
+ ## [2.37.0](https://github.com/forcedotcom/sfdx-core/compare/v2.36.4...v2.37.0) (2022-05-03)
12
+
13
+ ### Features
14
+
15
+ - new cloneSandbox method ([69073dd](https://github.com/forcedotcom/sfdx-core/commit/69073dd71ee7372d13c86aaf052c798a4bea5176))
16
+
17
+ ### Bug Fixes
18
+
19
+ - use tooling api ([c32f19d](https://github.com/forcedotcom/sfdx-core/commit/c32f19d8de6a953f8390fd853d3be023db01d890))
20
+
21
+ ### [2.36.4](https://github.com/forcedotcom/sfdx-core/compare/v2.36.3...v2.36.4) (2022-04-28)
22
+
23
+ ### Bug Fixes
24
+
25
+ - disable strictSchema ([2f44345](https://github.com/forcedotcom/sfdx-core/commit/2f44345d6dc11673b921b6c65cd548b7f31a0dad))
26
+ - replace JSEN with AJV (wip) ([87ca60c](https://github.com/forcedotcom/sfdx-core/commit/87ca60c48a82618008d761bdd6086727f712aeff))
27
+ - schema comment ([a0868d1](https://github.com/forcedotcom/sfdx-core/commit/a0868d157fbc8757cdbd28472aecfbf597c0f9d2))
28
+ - test failures and cleanup ([95c0710](https://github.com/forcedotcom/sfdx-core/commit/95c0710938b399c858cddfdf5100892ee2e7cf90))
29
+
5
30
  ### [2.36.3](https://github.com/forcedotcom/sfdx-core/compare/v2.36.2...v2.36.3) (2022-04-21)
6
31
 
7
32
  ### Bug Fixes
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,57 @@ 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
+ // If we end up getting an npm-shrinkwrap working in the future we could turn this back off.
86
+ // https://github.com/forcedotcom/cli/issues/1493
87
+ validateSchema: false,
88
+ });
89
+ // JSEN to AJV migration note - regarding the following "TODO":
90
+ // I don't think that AJV has a way to throw an error if an additional property exists in the data
91
+ // It does however have a top level option for `removeAdditional` https://ajv.js.org/options.html#removeadditional
92
+ // Regardless, this would be a breaking changes and I do not think it should be implemented.
78
93
  // TODO: We should default to throw an error when a property is specified
79
94
  // that is not in the schema, but the only option to do this right now is
80
95
  // to specify "removeAdditional: false" in every object.
81
- const validate = validator(schema, {
82
- greedy: true,
83
- schemas: externalSchemas,
84
- });
85
- if (!validate(json)) {
96
+ const validate = ajv.compile(schema);
97
+ // AJV will modify the original json object. We need to make a clone of the
98
+ // json to keep this backwards compatible with JSEN functionality
99
+ const jsonClone = JSON.parse(JSON.stringify(json));
100
+ const valid = validate(jsonClone);
101
+ if (!valid) {
86
102
  if (validate.errors) {
87
- const errors = this.getErrorsText(validate.errors, schema);
103
+ const errors = this.getErrorsText(validate.errors);
88
104
  throw new sfdxError_1.SfdxError(`Validation errors:\n${errors}`, 'ValidationSchemaFieldErrors');
89
105
  }
90
106
  else {
91
107
  throw new sfdxError_1.SfdxError('Unknown schema validation error', 'ValidationSchemaUnknown');
92
108
  }
93
109
  }
94
- return validate.build(json);
110
+ // We return the cloned JSON because it will have defaults included
111
+ // This is configured with the 'useDefaults' option above.
112
+ return jsonClone;
95
113
  }
96
114
  /**
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.
115
+ * Loads local, external schemas from URIs in the same directory as the local schema file.
116
+ * Does not support loading from remote URIs.
117
+ * Returns a map of external schema local URIs to loaded schema JSON objects.
99
118
  *
100
- * @param schema The main schema to validate against.
119
+ * @param schema The main schema to look up references ($ref) in.
120
+ * @returns An array of found referenced schemas.
101
121
  */
102
122
  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))
123
+ return kit_1.getJsonValuesByName(schema, '$ref')
124
+ .map((ref) => ref && RegExp(/([\w\.]+)#/).exec(ref)) // eslint-disable-line no-useless-escape
107
125
  .map((match) => match && match[1])
108
126
  .filter((uri) => !!uri)
109
127
  .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
128
  }
120
129
  /**
121
130
  * Load another schema relative to the primary schema when referenced. Only supports local schema URIs.
@@ -125,7 +134,7 @@ class SchemaValidator {
125
134
  loadExternalSchema(uri) {
126
135
  const schemaPath = path.join(this.schemasDir, `${uri}.json`);
127
136
  try {
128
- return fs_1.fs.readJsonMapSync(schemaPath);
137
+ return kit_1.parseJsonMap(fs.readFileSync(schemaPath, 'utf8'));
129
138
  }
130
139
  catch (err) {
131
140
  if (err.code === 'ENOENT') {
@@ -136,52 +145,21 @@ class SchemaValidator {
136
145
  }
137
146
  /**
138
147
  * Get a string representation of the schema validation errors.
148
+ * Adds additional (human friendly) information to certain errors.
139
149
  *
140
- * @param errors An array of JsenValidateError objects.
141
- * @param schema The validation schema.
150
+ * @param errors An array of AJV (DefinedError) objects.
142
151
  */
143
- getErrorsText(errors, schema) {
152
+ getErrorsText(errors) {
144
153
  return errors
145
154
  .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
- };
155
+ const msg = `${error.schemaPath}: ${error.message}`;
164
156
  switch (error.keyword) {
165
157
  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`;
158
+ return `${msg} '${error.params.additionalProperty}'`;
177
159
  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
- }
160
+ return `${msg} '${error.params.allowedValues.join(', ')}'`;
183
161
  default:
184
- return `${error.path} invalid ${error.keyword}`;
162
+ return msg;
185
163
  }
186
164
  })
187
165
  .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.3",
3
+ "version": "2.37.1",
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",