@salesforce/core 3.32.12 → 3.32.13

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/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2022, Salesforce.com, Inc.
1
+ Copyright (c) 2023, Salesforce.com, Inc.
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -150,7 +150,7 @@ exports.SFDX_ALLOWED_PROPERTIES = [
150
150
  hidden: true,
151
151
  input: {
152
152
  // If a value is provided validate it otherwise no value is unset.
153
- validator: (value) => value == null || ((0, ts_types_1.isString)(value) && sfdc_1.sfdc.validateApiVersion(value)),
153
+ validator: (value) => value == null || ((0, ts_types_1.isString)(value) && (0, sfdc_1.validateApiVersion)(value)),
154
154
  failedMessage: messages.getMessage('invalidApiVersion'),
155
155
  },
156
156
  },
@@ -282,7 +282,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
282
282
  static async queryScratchOrg(devHubUsername, scratchOrgId) {
283
283
  const devHubOrg = await org_1.Org.create({ aliasOrUsername: devHubUsername });
284
284
  const conn = devHubOrg.getConnection();
285
- const data = await conn.query(`select Id from ScratchOrgInfo where ScratchOrg = '${sfdc_1.sfdc.trimTo15(scratchOrgId)}'`);
285
+ const data = await conn.query(`select Id from ScratchOrgInfo where ScratchOrg = '${(0, sfdc_1.trimTo15)(scratchOrgId)}'`);
286
286
  return data;
287
287
  }
288
288
  /**
@@ -326,7 +326,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
326
326
  async save(authData) {
327
327
  this.update(authData);
328
328
  const username = (0, ts_types_1.ensure)(this.getUsername());
329
- if (sfdc_1.sfdc.matchesAccessToken(username)) {
329
+ if ((0, sfdc_1.matchesAccessToken)(username)) {
330
330
  this.logger.debug('Username is an accesstoken. Skip saving authinfo to disk.');
331
331
  return this;
332
332
  }
@@ -519,7 +519,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
519
519
  await this.stateAggregator.orgs.read(oauthUsername, false, false);
520
520
  } // Else it will be set in initAuthOptions below.
521
521
  // If the username is an access token, use that for auth and don't persist
522
- if ((0, ts_types_1.isString)(oauthUsername) && sfdc_1.sfdc.matchesAccessToken(oauthUsername)) {
522
+ if ((0, ts_types_1.isString)(oauthUsername) && (0, sfdc_1.matchesAccessToken)(oauthUsername)) {
523
523
  // Need to initAuthOptions the logger and authInfoCrypto since we don't call init()
524
524
  this.logger = await logger_1.Logger.child('AuthInfo');
525
525
  const aggregator = await configAggregator_1.ConfigAggregator.create();
@@ -258,7 +258,7 @@ class Connection extends jsforce_1.Connection {
258
258
  * @param version The API version.
259
259
  */
260
260
  setApiVersion(version) {
261
- if (!sfdc_1.sfdc.validateApiVersion(version)) {
261
+ if (!(0, sfdc_1.validateApiVersion)(version)) {
262
262
  throw messages.createError('incorrectAPIVersionError', [version]);
263
263
  }
264
264
  this.version = version;
package/lib/org/org.js CHANGED
@@ -288,7 +288,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
288
288
  }
289
289
  const devHubConnection = (await Org.create({ aliasOrUsername })).getConnection();
290
290
  const thisOrgAuthConfig = this.getConnection().getAuthInfoFields();
291
- const trimmedId = sfdc_1.sfdc.trimTo15(thisOrgAuthConfig.orgId);
291
+ const trimmedId = (0, sfdc_1.trimTo15)(thisOrgAuthConfig.orgId);
292
292
  const DEV_HUB_SOQL = `SELECT CreatedDate,Edition,ExpirationDate FROM ActiveScratchOrg WHERE ScratchOrg='${trimmedId}'`;
293
293
  try {
294
294
  const results = await devHubConnection.query(DEV_HUB_SOQL);
@@ -880,7 +880,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
880
880
  }
881
881
  catch {
882
882
  // if an error is thrown, don't panic yet. we'll try querying by orgId
883
- const trimmedId = sfdc_1.sfdc.trimTo15(this.getOrgId());
883
+ const trimmedId = (0, sfdc_1.trimTo15)(this.getOrgId());
884
884
  this.logger.debug(`defaulting to trimming id from ${this.getOrgId()} to ${trimmedId}`);
885
885
  try {
886
886
  result = await this.queryProduction(prodOrg, 'SandboxOrganization', trimmedId);
@@ -100,7 +100,7 @@ exports.ORG_CONFIG_ALLOWED_PROPERTIES = [
100
100
  hidden: true,
101
101
  input: {
102
102
  // If a value is provided validate it otherwise no value is unset.
103
- validator: (value) => value == null || ((0, ts_types_1.isString)(value) && sfdc_1.sfdc.validateApiVersion(value)),
103
+ validator: (value) => value == null || ((0, ts_types_1.isString)(value) && (0, sfdc_1.validateApiVersion)(value)),
104
104
  failedMessage: messages.getMessage('invalidApiVersion'),
105
105
  },
106
106
  },
package/lib/org/user.js CHANGED
@@ -71,7 +71,7 @@ async function retrieveUserFields(logger, username) {
71
71
  const connection = await connection_1.Connection.create({
72
72
  authInfo: await authInfo_1.AuthInfo.create({ username }),
73
73
  });
74
- if (sfdc_1.sfdc.matchesAccessToken(username)) {
74
+ if ((0, sfdc_1.matchesAccessToken)(username)) {
75
75
  logger.debug('received an accessToken for the username. Converting...');
76
76
  username = (await connection.identity()).username;
77
77
  logger.debug(`accessToken converted to ${username}`);
@@ -111,7 +111,7 @@ async function retrieveUserFields(logger, username) {
111
111
  * @param connection The connection for the query.
112
112
  */
113
113
  async function retrieveProfileId(name, connection) {
114
- if (!sfdc_1.sfdc.validateSalesforceId(name)) {
114
+ if (!(0, sfdc_1.validateSalesforceId)(name)) {
115
115
  const profileQuery = `SELECT Id FROM Profile WHERE name='${name}'`;
116
116
  const result = await connection.query(profileQuery);
117
117
  if (result.records.length > 0) {
package/lib/sfProject.js CHANGED
@@ -309,7 +309,7 @@ class SfProjectJson extends configFile_1.ConfigFile {
309
309
  }
310
310
  validateKeys() {
311
311
  // Verify that the configObject does not have upper case keys; throw if it does. Must be heads down camel case.
312
- const upperCaseKey = sfdc_1.sfdc.findUpperCaseKeys(this.toObject(), SfProjectJson.BLOCKLIST);
312
+ const upperCaseKey = (0, sfdc_1.findUpperCaseKeys)(this.toObject(), SfProjectJson.BLOCKLIST);
313
313
  if (upperCaseKey) {
314
314
  throw coreMessages.createError('invalidJsonCasing', [upperCaseKey, this.getPath()]);
315
315
  }
@@ -514,7 +514,7 @@ export declare class MockTestOrgData {
514
514
  clientSecret: string;
515
515
  authcode: string;
516
516
  accessToken: string;
517
- refreshToken: string;
517
+ refreshToken: string | undefined;
518
518
  tracksSource: boolean | undefined;
519
519
  userId: string;
520
520
  redirectUri: string;
package/lib/testSetup.js CHANGED
@@ -850,13 +850,13 @@ class MockTestOrgData {
850
850
  const crypto = await crypto_2.Crypto.create();
851
851
  const config = {};
852
852
  config.orgId = this.orgId;
853
+ config.clientId = this.clientId;
853
854
  const accessToken = crypto.encrypt(this.accessToken);
854
855
  if (accessToken) {
855
856
  config.accessToken = accessToken;
856
857
  }
857
- const refreshToken = crypto.encrypt(this.refreshToken);
858
- if (refreshToken) {
859
- config.refreshToken = refreshToken;
858
+ if (this.refreshToken) {
859
+ config.refreshToken = crypto.encrypt(this.refreshToken);
860
860
  }
861
861
  config.instanceUrl = this.instanceUrl;
862
862
  config.loginUrl = this.loginUrl;
@@ -14,7 +14,7 @@ async function checkLightningDomain(url) {
14
14
  const domain = `https://${/https?:\/\/([^.]*)/.exec(url)?.slice(1, 2).pop()}.lightning.force.com`;
15
15
  const quantity = new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240) ?? 0;
16
16
  const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
17
- if (sfdc_1.sfdc.isInternalUrl(url) || timeout.seconds === 0) {
17
+ if ((0, sfdc_1.isInternalUrl)(url) || timeout.seconds === 0) {
18
18
  return true;
19
19
  }
20
20
  const resolver = await myDomainResolver_1.MyDomainResolver.create({
@@ -1,52 +1,63 @@
1
1
  import { JsonMap, Optional } from '@salesforce/ts-types';
2
+ /**
3
+ * Converts an 18 character Salesforce ID to 15 characters.
4
+ *
5
+ * @param id The id to convert.
6
+ */
7
+ export declare function trimTo15(id: string): string;
8
+ export declare function trimTo15(id?: undefined): undefined;
9
+ export declare function trimTo15(id: string | undefined): string | undefined;
10
+ /**
11
+ * Tests whether an API version matches the format `i.0`.
12
+ *
13
+ * @param value The API version as a string.
14
+ */
15
+ export declare const validateApiVersion: (value: string) => boolean;
16
+ /**
17
+ * Tests whether an email matches the format `me@my.org`
18
+ *
19
+ * @param value The email as a string.
20
+ */
21
+ export declare const validateEmail: (value: string) => boolean;
22
+ /**
23
+ * Tests whether a given url is an internal Salesforce domain
24
+ *
25
+ * @param url
26
+ */
27
+ export declare const isInternalUrl: (url: string) => boolean;
28
+ /**
29
+ * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
30
+ *
31
+ * @param value The ID as a string.
32
+ */
33
+ export declare const validateSalesforceId: (value: string) => boolean;
34
+ /**
35
+ * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
36
+ *
37
+ * @param value The path as a string.
38
+ */
39
+ export declare const validatePathDoesNotContainInvalidChars: (value: string) => boolean;
40
+ /**
41
+ * Returns the first key within the object that has an upper case first letter.
42
+ *
43
+ * @param data The object in which to check key casing.
44
+ * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`.
45
+ */
46
+ export declare const findUpperCaseKeys: (data?: JsonMap, sectionBlocklist?: string[]) => Optional<string>;
47
+ /**
48
+ * Tests whether a given string is an access token
49
+ *
50
+ * @param value
51
+ */
52
+ export declare const matchesAccessToken: (value: string) => boolean;
53
+ /** @deprecated import the individual functions instead of the whole object */
2
54
  export declare const sfdc: {
3
- /**
4
- * Converts an 18 character Salesforce ID to 15 characters.
5
- *
6
- * @param id The id to convert.
7
- */
8
- trimTo15: (id?: string) => Optional<string>;
9
- /**
10
- * Tests whether an API version matches the format `i.0`.
11
- *
12
- * @param value The API version as a string.
13
- */
55
+ trimTo15: typeof trimTo15;
14
56
  validateApiVersion: (value: string) => boolean;
15
- /**
16
- * Tests whether an email matches the format `me@my.org`
17
- *
18
- * @param value The email as a string.
19
- */
20
57
  validateEmail: (value: string) => boolean;
21
- /**
22
- * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
23
- *
24
- * @param value The ID as a string.
25
- */
58
+ isInternalUrl: (url: string) => boolean;
59
+ matchesAccessToken: (value: string) => boolean;
26
60
  validateSalesforceId: (value: string) => boolean;
27
- /**
28
- * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
29
- *
30
- * @param value The path as a string.
31
- */
32
61
  validatePathDoesNotContainInvalidChars: (value: string) => boolean;
33
- /**
34
- * Returns the first key within the object that has an upper case first letter.
35
- *
36
- * @param data The object in which to check key casing.
37
- * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`.
38
- */
39
62
  findUpperCaseKeys: (data?: JsonMap, sectionBlocklist?: string[]) => Optional<string>;
40
- /**
41
- * Tests whether a given string is an access token
42
- *
43
- * @param value
44
- */
45
- matchesAccessToken: (value: string) => boolean;
46
- /**
47
- * Tests whether a given url is an internal Salesforce domain
48
- *
49
- * @param url
50
- */
51
- isInternalUrl: (url: string) => boolean;
52
63
  };
package/lib/util/sfdc.js CHANGED
@@ -6,81 +6,96 @@
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
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.sfdc = void 0;
9
+ exports.sfdc = exports.matchesAccessToken = exports.findUpperCaseKeys = exports.validatePathDoesNotContainInvalidChars = exports.validateSalesforceId = exports.isInternalUrl = exports.validateEmail = exports.validateApiVersion = exports.trimTo15 = void 0;
10
10
  const kit_1 = require("@salesforce/kit");
11
11
  const ts_types_1 = require("@salesforce/ts-types");
12
12
  const sfdcUrl_1 = require("./sfdcUrl");
13
- exports.sfdc = {
14
- /**
15
- * Converts an 18 character Salesforce ID to 15 characters.
16
- *
17
- * @param id The id to convert.
18
- */
19
- trimTo15: (id) => {
20
- if (id?.length && id.length > 15) {
21
- id = id.substring(0, 15);
13
+ function trimTo15(id) {
14
+ if (!id) {
15
+ return undefined;
16
+ }
17
+ if (id.length && id.length > 15) {
18
+ id = id.substring(0, 15);
19
+ }
20
+ return id;
21
+ }
22
+ exports.trimTo15 = trimTo15;
23
+ /**
24
+ * Tests whether an API version matches the format `i.0`.
25
+ *
26
+ * @param value The API version as a string.
27
+ */
28
+ const validateApiVersion = (value) => value == null || /^[1-9]\d\.0$/.test(value);
29
+ exports.validateApiVersion = validateApiVersion;
30
+ /**
31
+ * Tests whether an email matches the format `me@my.org`
32
+ *
33
+ * @param value The email as a string.
34
+ */
35
+ const validateEmail = (value) => /^[^.][^@]*@[^.]+(\.[^.\s]+)+$/.test(value);
36
+ exports.validateEmail = validateEmail;
37
+ /**
38
+ * Tests whether a given url is an internal Salesforce domain
39
+ *
40
+ * @param url
41
+ */
42
+ const isInternalUrl = (url) => new sfdcUrl_1.SfdcUrl(url).isInternalUrl();
43
+ exports.isInternalUrl = isInternalUrl;
44
+ /**
45
+ * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
46
+ *
47
+ * @param value The ID as a string.
48
+ */
49
+ const validateSalesforceId = (value) => /[a-zA-Z0-9]{18}|[a-zA-Z0-9]{15}/.test(value) && (value.length === 15 || value.length === 18);
50
+ exports.validateSalesforceId = validateSalesforceId;
51
+ /**
52
+ * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
53
+ *
54
+ * @param value The path as a string.
55
+ */
56
+ const validatePathDoesNotContainInvalidChars = (value) =>
57
+ // eslint-disable-next-line no-useless-escape
58
+ !/[\["\?<>\|\]]+/.test(value);
59
+ exports.validatePathDoesNotContainInvalidChars = validatePathDoesNotContainInvalidChars;
60
+ /**
61
+ * Returns the first key within the object that has an upper case first letter.
62
+ *
63
+ * @param data The object in which to check key casing.
64
+ * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`.
65
+ */
66
+ const findUpperCaseKeys = (data, sectionBlocklist = []) => {
67
+ let key;
68
+ (0, kit_1.findKey)(data, (val, k) => {
69
+ if (/^[A-Z]/.test(k)) {
70
+ key = k;
22
71
  }
23
- return id;
24
- },
25
- /**
26
- * Tests whether an API version matches the format `i.0`.
27
- *
28
- * @param value The API version as a string.
29
- */
30
- validateApiVersion: (value) => value == null || /^[1-9]\d\.0$/.test(value),
31
- /**
32
- * Tests whether an email matches the format `me@my.org`
33
- *
34
- * @param value The email as a string.
35
- */
36
- validateEmail: (value) => /^[^.][^@]*@[^.]+(\.[^.\s]+)+$/.test(value),
37
- /**
38
- * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
39
- *
40
- * @param value The ID as a string.
41
- */
42
- validateSalesforceId: (value) => /[a-zA-Z0-9]{18}|[a-zA-Z0-9]{15}/.test(value) && (value.length === 15 || value.length === 18),
43
- /**
44
- * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
45
- *
46
- * @param value The path as a string.
47
- */
48
- validatePathDoesNotContainInvalidChars: (value) =>
49
- // eslint-disable-next-line no-useless-escape
50
- !/[\["\?<>\|\]]+/.test(value),
51
- /**
52
- * Returns the first key within the object that has an upper case first letter.
53
- *
54
- * @param data The object in which to check key casing.
55
- * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`.
56
- */
57
- findUpperCaseKeys: (data, sectionBlocklist = []) => {
58
- let key;
59
- (0, kit_1.findKey)(data, (val, k) => {
60
- if (k.substr(0, 1) === k.substr(0, 1).toUpperCase()) {
61
- key = k;
62
- }
63
- else if ((0, ts_types_1.isJsonMap)(val)) {
64
- if (sectionBlocklist.includes(k)) {
65
- return key;
66
- }
67
- key = exports.sfdc.findUpperCaseKeys((0, ts_types_1.asJsonMap)(val));
72
+ else if ((0, ts_types_1.isJsonMap)(val)) {
73
+ if (sectionBlocklist.includes(k)) {
74
+ return key;
68
75
  }
69
- return key;
70
- });
76
+ key = (0, exports.findUpperCaseKeys)((0, ts_types_1.asJsonMap)(val));
77
+ }
71
78
  return key;
72
- },
73
- /**
74
- * Tests whether a given string is an access token
75
- *
76
- * @param value
77
- */
78
- matchesAccessToken: (value) => /^(00D\w{12,15})![.\w]*$/.test(value),
79
- /**
80
- * Tests whether a given url is an internal Salesforce domain
81
- *
82
- * @param url
83
- */
84
- isInternalUrl: (url) => new sfdcUrl_1.SfdcUrl(url).isInternalUrl(),
79
+ });
80
+ return key;
81
+ };
82
+ exports.findUpperCaseKeys = findUpperCaseKeys;
83
+ /**
84
+ * Tests whether a given string is an access token
85
+ *
86
+ * @param value
87
+ */
88
+ const matchesAccessToken = (value) => /^(00D\w{12,15})![.\w]*$/.test(value);
89
+ exports.matchesAccessToken = matchesAccessToken;
90
+ /** @deprecated import the individual functions instead of the whole object */
91
+ exports.sfdc = {
92
+ trimTo15,
93
+ validateApiVersion: exports.validateApiVersion,
94
+ validateEmail: exports.validateEmail,
95
+ isInternalUrl: exports.isInternalUrl,
96
+ matchesAccessToken: exports.matchesAccessToken,
97
+ validateSalesforceId: exports.validateSalesforceId,
98
+ validatePathDoesNotContainInvalidChars: exports.validatePathDoesNotContainInvalidChars,
99
+ findUpperCaseKeys: exports.findUpperCaseKeys,
85
100
  };
86
101
  //# sourceMappingURL=sfdc.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.32.12",
3
+ "version": "3.32.13",
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",
@@ -37,7 +37,7 @@
37
37
  "@salesforce/bunyan": "^2.0.0",
38
38
  "@salesforce/kit": "^1.8.0",
39
39
  "@salesforce/schemas": "^1.4.0",
40
- "@salesforce/ts-types": "^1.5.21",
40
+ "@salesforce/ts-types": "^1.7.2",
41
41
  "@types/graceful-fs": "^4.1.5",
42
42
  "@types/semver": "^7.3.13",
43
43
  "ajv": "^8.11.2",
@@ -65,11 +65,11 @@
65
65
  "@types/lodash": "^4.14.191",
66
66
  "@types/shelljs": "0.8.11",
67
67
  "@typescript-eslint/eslint-plugin": "^5.41.0",
68
- "@typescript-eslint/parser": "^5.46.1",
68
+ "@typescript-eslint/parser": "^5.47.1",
69
69
  "chai": "^4.3.7",
70
70
  "chai-string": "^1.5.0",
71
71
  "commitizen": "^3.1.2",
72
- "eslint": "^8.29.0",
72
+ "eslint": "^8.31.0",
73
73
  "eslint-config-prettier": "^8.5.0",
74
74
  "eslint-config-salesforce": "^1.1.0",
75
75
  "eslint-config-salesforce-license": "^0.1.6",