@salesforce/core 3.30.10 → 3.30.11

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 (69) hide show
  1. package/README.md +3 -3
  2. package/lib/config/aliasesConfig.js +1 -0
  3. package/lib/config/config.js +6 -9
  4. package/lib/config/configAggregator.d.ts +3 -3
  5. package/lib/config/configAggregator.js +14 -14
  6. package/lib/config/configFile.js +7 -9
  7. package/lib/config/configGroup.js +8 -7
  8. package/lib/config/configStore.d.ts +4 -4
  9. package/lib/config/configStore.js +12 -9
  10. package/lib/config/envVars.js +1 -1
  11. package/lib/config/tokensConfig.js +1 -0
  12. package/lib/config/ttlConfig.d.ts +2 -0
  13. package/lib/config/ttlConfig.js +5 -4
  14. package/lib/crypto/crypto.js +9 -12
  15. package/lib/crypto/keyChainImpl.d.ts +2 -0
  16. package/lib/crypto/keyChainImpl.js +41 -34
  17. package/lib/deviceOauthService.js +5 -2
  18. package/lib/exported.js +5 -1
  19. package/lib/global.js +2 -0
  20. package/lib/lifecycleEvents.js +3 -0
  21. package/lib/logger.d.ts +2 -3
  22. package/lib/logger.js +57 -53
  23. package/lib/messages.js +2 -3
  24. package/lib/org/authInfo.js +40 -29
  25. package/lib/org/authRemover.js +11 -7
  26. package/lib/org/connection.d.ts +4 -4
  27. package/lib/org/connection.js +8 -6
  28. package/lib/org/index.js +5 -1
  29. package/lib/org/org.js +23 -15
  30. package/lib/org/scratchOrgCreate.js +2 -1
  31. package/lib/org/scratchOrgInfoApi.js +4 -6
  32. package/lib/org/scratchOrgInfoGenerator.d.ts +1 -0
  33. package/lib/org/scratchOrgInfoGenerator.js +28 -27
  34. package/lib/org/scratchOrgLifecycleEvents.js +2 -6
  35. package/lib/org/scratchOrgSettingsGenerator.js +9 -9
  36. package/lib/org/scratchOrgTypes.d.ts +1 -1
  37. package/lib/org/user.js +7 -6
  38. package/lib/schema/printer.d.ts +4 -0
  39. package/lib/schema/printer.js +30 -29
  40. package/lib/schema/validator.d.ts +1 -1
  41. package/lib/schema/validator.js +2 -1
  42. package/lib/sfError.d.ts +3 -6
  43. package/lib/sfError.js +26 -9
  44. package/lib/sfProject.js +14 -6
  45. package/lib/stateAggregator/accessors/aliasAccessor.js +2 -1
  46. package/lib/stateAggregator/accessors/orgAccessor.js +11 -6
  47. package/lib/stateAggregator/accessors/sandboxAccessor.js +1 -0
  48. package/lib/stateAggregator/index.js +5 -1
  49. package/lib/status/myDomainResolver.d.ts +1 -1
  50. package/lib/status/myDomainResolver.js +4 -4
  51. package/lib/status/streamingClient.js +51 -49
  52. package/lib/testSetup.d.ts +5 -1
  53. package/lib/testSetup.js +32 -21
  54. package/lib/util/cache.d.ts +2 -2
  55. package/lib/util/cache.js +6 -6
  56. package/lib/util/directoryWriter.d.ts +2 -1
  57. package/lib/util/directoryWriter.js +5 -3
  58. package/lib/util/jsonXmlTools.js +2 -4
  59. package/lib/util/mapKeys.d.ts +9 -9
  60. package/lib/util/mapKeys.js +13 -9
  61. package/lib/util/sfdc.d.ts +2 -2
  62. package/lib/util/sfdc.js +8 -17
  63. package/lib/util/sfdcUrl.d.ts +1 -1
  64. package/lib/util/sfdcUrl.js +2 -4
  65. package/lib/util/structuredWriter.d.ts +1 -0
  66. package/lib/util/zipWriter.d.ts +2 -1
  67. package/lib/util/zipWriter.js +5 -9
  68. package/lib/webOAuthServer.js +9 -3
  69. package/package.json +16 -17
@@ -10,7 +10,6 @@ exports.getScratchOrgInfoPayload = exports.generateScratchOrgInfo = exports.getA
10
10
  const fs_1 = require("fs");
11
11
  const kit_1 = require("@salesforce/kit");
12
12
  const ts_types_1 = require("@salesforce/ts-types");
13
- const sfdc_1 = require("../util/sfdc");
14
13
  const sfProject_1 = require("../sfProject");
15
14
  const webOAuthServer_1 = require("../webOAuthServer");
16
15
  const messages_1 = require("../messages");
@@ -60,7 +59,7 @@ const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
60
59
  }
61
60
  const packagesWithAncestors = (await projectJson.getPackageDirectories())
62
61
  // check that the package has any ancestor types (id or version)
63
- .filter((packageDir) => packageDir.ancestorId || packageDir.ancestorVersion);
62
+ .filter((packageDir) => packageDir.ancestorId ?? packageDir.ancestorVersion);
64
63
  if (packagesWithAncestors.length === 0) {
65
64
  return '';
66
65
  }
@@ -184,31 +183,19 @@ exports.generateScratchOrgInfo = generateScratchOrgInfo;
184
183
  */
185
184
  const getScratchOrgInfoPayload = async (options) => {
186
185
  let warnings = [];
187
- // orgConfig input overrides definitionjson (-j option; hidden/deprecated)
188
- const definitionJson = options.definitionjson ? JSON.parse(options.definitionjson) : {};
189
- const orgConfigInput = { ...definitionJson, ...(options.orgConfig ?? {}) };
190
- let scratchOrgInfoPayload = orgConfigInput;
191
- // the -f option
192
- if (options.definitionfile) {
193
- try {
194
- const fileData = await fs_1.promises.readFile(options.definitionfile, 'utf8');
195
- const defFileContents = (0, kit_1.parseJson)(fileData);
196
- // definitionjson and orgConfig override file input
197
- scratchOrgInfoPayload = { ...defFileContents, ...orgConfigInput };
198
- }
199
- catch (err) {
200
- const error = err;
201
- if (error.name === 'JsonParseError') {
202
- throw new sfError_1.SfError(`An error occurred parsing ${options.definitionfile}`);
203
- }
204
- throw sfError_1.SfError.wrap(error);
205
- }
206
- }
186
+ // orgConfig input overrides definitionjson (-j option; hidden/deprecated) overrides definitionfile (-f option)
187
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
188
+ const scratchOrgInfoPayload = {
189
+ ...(options.definitionfile ? await parseDefinitionFile(options.definitionfile) : {}),
190
+ ...(options.definitionjson ? JSON.parse(options.definitionjson) : {}),
191
+ ...(options.orgConfig ?? {}),
192
+ };
207
193
  // scratchOrgInfoPayload must be heads down camelcase.
208
- const upperCaseKey = sfdc_1.sfdc.findUpperCaseKeys(scratchOrgInfoPayload);
209
- if (upperCaseKey) {
210
- throw new sfError_1.SfError('InvalidJsonCasing', upperCaseKey);
211
- }
194
+ Object.keys(scratchOrgInfoPayload).forEach((key) => {
195
+ if (key[0].toUpperCase() === key[0]) {
196
+ throw new sfError_1.SfError('InvalidJsonCasing', key);
197
+ }
198
+ });
212
199
  // Now run the fully resolved user input against the validator
213
200
  Object.keys(scratchOrgInfoPayload).forEach((key) => {
214
201
  optionsValidator(key, scratchOrgInfoPayload);
@@ -233,9 +220,23 @@ const getScratchOrgInfoPayload = async (options) => {
233
220
  return {
234
221
  scratchOrgInfoPayload,
235
222
  // Ignore ancestor ids only when 'nonamespace' or 'noancestors' options are specified
236
- ignoreAncestorIds: options.nonamespace || options.noancestors || false,
223
+ ignoreAncestorIds: options.nonamespace ?? options.noancestors ?? false,
237
224
  warnings,
238
225
  };
239
226
  };
240
227
  exports.getScratchOrgInfoPayload = getScratchOrgInfoPayload;
228
+ const parseDefinitionFile = async (definitionFile) => {
229
+ try {
230
+ const fileData = await fs_1.promises.readFile(definitionFile, 'utf8');
231
+ const defFileContents = (0, kit_1.parseJson)(fileData);
232
+ return defFileContents;
233
+ }
234
+ catch (err) {
235
+ const error = err;
236
+ if (error.name === 'JsonParseError') {
237
+ throw new sfError_1.SfError(`An error occurred parsing ${definitionFile}`);
238
+ }
239
+ throw sfError_1.SfError.wrap(error);
240
+ }
241
+ };
241
242
  //# sourceMappingURL=scratchOrgInfoGenerator.js.map
@@ -19,9 +19,7 @@ exports.scratchOrgLifecycleStages = [
19
19
  'deploy settings',
20
20
  'done',
21
21
  ];
22
- const emit = async (event) => {
23
- emitter.emit(exports.scratchOrgLifecycleEventName, event);
24
- };
22
+ const emit = async (event) => emitter.emit(exports.scratchOrgLifecycleEventName, event);
25
23
  exports.emit = emit;
26
24
  const postOrgCreateHookFields = [
27
25
  'accessToken',
@@ -35,9 +33,7 @@ const postOrgCreateHookFields = [
35
33
  'orgId',
36
34
  'username',
37
35
  ];
38
- const isHookField = (key) => {
39
- return postOrgCreateHookFields.includes(key);
40
- };
36
+ const isHookField = (key) => postOrgCreateHookFields.includes(key);
41
37
  const emitPostOrgCreate = async (authFields) => {
42
38
  await emitter.emit('postorgcreate', Object.fromEntries(Object.entries(authFields).filter(([key]) => isHookField(key))));
43
39
  };
@@ -141,8 +141,8 @@ class SettingsGenerator {
141
141
  this.allBusinessProcesses = [];
142
142
  this.logger = logger_1.Logger.childFromRoot('SettingsGenerator');
143
143
  // If SFDX_MDAPI_TEMP_DIR is set, copy settings to that dir for people to inspect.
144
- const mdApiTmpDir = options?.mdApiTmpDir || kit_1.env.getString('SFDX_MDAPI_TEMP_DIR');
145
- this.shapeDirName = options?.shapeDirName || `shape_${Date.now()}`;
144
+ const mdApiTmpDir = options?.mdApiTmpDir ?? kit_1.env.getString('SFDX_MDAPI_TEMP_DIR');
145
+ this.shapeDirName = options?.shapeDirName ?? `shape_${Date.now()}`;
146
146
  this.packageFilePath = path.join(this.shapeDirName, 'package.xml');
147
147
  let storePath;
148
148
  if (!options?.asDirectory) {
@@ -155,6 +155,7 @@ class SettingsGenerator {
155
155
  }
156
156
  }
157
157
  /** extract the settings from the scratch def file, if they are present. */
158
+ // eslint-disable-next-line @typescript-eslint/require-await
158
159
  async extract(scratchDef) {
159
160
  this.logger.debug('extracting settings from scratch definition file');
160
161
  this.settingData = scratchDef.settings;
@@ -254,22 +255,21 @@ class SettingsGenerator {
254
255
  }
255
256
  async writeObjectSettingsIfNeeded(objectsDir, allRecordTypes, allbusinessProcesses) {
256
257
  if (this.objectSettingsData) {
257
- for (const [item, value] of Object.entries(this.objectSettingsData)) {
258
+ await Promise.all(Object.entries(this.objectSettingsData).map(([item, value]) => {
258
259
  const fileContent = (0, exports.createRecordTypeAndBusinessProcessFileContent)(item, value, allRecordTypes, allbusinessProcesses);
259
260
  const xml = js2xmlparser.parse('CustomObject', fileContent);
260
- await this.writer.addToStore(xml, path.join(objectsDir, (0, kit_1.upperFirst)(item) + '.object'));
261
- }
261
+ return this.writer.addToStore(xml, path.join(objectsDir, (0, kit_1.upperFirst)(item) + '.object'));
262
+ }));
262
263
  }
263
264
  }
264
265
  async writeSettingsIfNeeded(settingsDir) {
265
266
  if (this.settingData) {
266
- for (const item of Object.keys(this.settingData)) {
267
- const value = (0, ts_types_1.getObject)(this.settingData, item);
267
+ await Promise.all(Object.entries(this.settingData).map(([item, value]) => {
268
268
  const typeName = (0, kit_1.upperFirst)(item);
269
269
  const fname = typeName.replace('Settings', '');
270
270
  const fileContent = js2xmlparser.parse(typeName, value);
271
- await this.writer.addToStore(fileContent, path.join(settingsDir, fname + '.settings'));
272
- }
271
+ return this.writer.addToStore(fileContent, path.join(settingsDir, fname + '.settings'));
272
+ }));
273
273
  }
274
274
  }
275
275
  }
@@ -6,7 +6,7 @@ export interface ScratchOrgInfo {
6
6
  ConnectedAppConsumerKey?: string;
7
7
  Country?: string;
8
8
  Description?: string;
9
- DurationDays?: string;
9
+ DurationDays?: number;
10
10
  Edition?: string;
11
11
  readonly ErrorCode?: string;
12
12
  readonly ExpirationDate?: string;
package/lib/org/user.js CHANGED
@@ -80,6 +80,7 @@ async function retrieveUserFields(logger, username) {
80
80
  logger.debug('not a accessToken');
81
81
  }
82
82
  const fromFields = Object.keys(exports.REQUIRED_FIELDS).map(kit_1.upperFirst);
83
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
83
84
  const requiredFieldsFromAdminQuery = `SELECT ${fromFields} FROM User WHERE Username='${username}'`;
84
85
  const result = await connection.query(requiredFieldsFromAdminQuery);
85
86
  logger.debug('Successfully retrieved the admin user for this org.');
@@ -265,9 +266,7 @@ class User extends kit_1.AsyncCreatable {
265
266
  throw messages.createError('permsetNamesAreRequired');
266
267
  }
267
268
  const assignments = await permissionSetAssignment_1.PermissionSetAssignment.init(this.org);
268
- for (const permsetName of permsetNames) {
269
- await assignments.create(id, permsetName);
270
- }
269
+ await Promise.all(permsetNames.map((permsetName) => assignments.create(id, permsetName)));
271
270
  }
272
271
  /**
273
272
  * Method for creating a new User.
@@ -337,7 +336,7 @@ class User extends kit_1.AsyncCreatable {
337
336
  * ```
338
337
  */
339
338
  async retrieve(username) {
340
- return await retrieveUserFields(this.logger, username);
339
+ return retrieveUserFields(this.logger, username);
341
340
  }
342
341
  /**
343
342
  * Helper method that verifies the server's User object is available and if so allows persisting the Auth information.
@@ -348,7 +347,7 @@ class User extends kit_1.AsyncCreatable {
348
347
  const connection = await connection_1.Connection.create({ authInfo: newUserAuthInfo });
349
348
  this.logger.debug(`Created connection for user: ${newUserAuthInfo.getUsername()}`);
350
349
  const userDescribe = await connection.describe('User');
351
- if (userDescribe && userDescribe.fields) {
350
+ if (userDescribe?.fields) {
352
351
  await newUserAuthInfo.save();
353
352
  return newUserAuthInfo;
354
353
  }
@@ -401,6 +400,7 @@ class User extends kit_1.AsyncCreatable {
401
400
  errors.forEach((singleMessage) => {
402
401
  if (!(0, ts_types_1.isJsonMap)(singleMessage))
403
402
  return;
403
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
404
404
  message = `${message}${os_1.EOL}${singleMessage.description}`;
405
405
  });
406
406
  }
@@ -419,9 +419,10 @@ class User extends kit_1.AsyncCreatable {
419
419
  userId: fields.id,
420
420
  };
421
421
  }
422
+ // eslint-disable-next-line class-methods-use-this
422
423
  async rawRequest(conn, options) {
423
424
  return new Promise((resolve, reject) => {
424
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
425
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
425
426
  const httpApi = new http_api_1.HttpApi(conn, options);
426
427
  httpApi.on('response', (response) => resolve(response));
427
428
  httpApi.request(options).catch(reject);
@@ -3,6 +3,8 @@ import { Logger } from '../logger';
3
3
  /**
4
4
  * Renders schema properties. By default, this is simply an identity transform. Subclasses may provide more
5
5
  * interesting decorations of each values, such as ANSI coloring.
6
+ *
7
+ * @deprecated
6
8
  */
7
9
  export declare class SchemaPropertyRenderer {
8
10
  /**
@@ -33,6 +35,8 @@ export declare class SchemaPropertyRenderer {
33
35
  /**
34
36
  * Prints a JSON schema in a human-friendly format.
35
37
  *
38
+ * @deprecated
39
+ *
36
40
  * ```
37
41
  * import chalk from 'chalk';
38
42
  * class MyPropertyRenderer extends SchemaPropertyRenderer {
@@ -5,6 +5,7 @@
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");
@@ -12,6 +13,8 @@ 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
15
18
  */
16
19
  class SchemaPropertyRenderer {
17
20
  /**
@@ -51,6 +54,8 @@ exports.SchemaPropertyRenderer = SchemaPropertyRenderer;
51
54
  /**
52
55
  * Prints a JSON schema in a human-friendly format.
53
56
  *
57
+ * @deprecated
58
+ *
54
59
  * ```
55
60
  * import chalk from 'chalk';
56
61
  * class MyPropertyRenderer extends SchemaPropertyRenderer {
@@ -178,40 +183,13 @@ class SchemaProperty {
178
183
  }
179
184
  const oneOfs = (0, ts_types_1.asJsonArray)(this.rawProperty.oneOf);
180
185
  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('|');
186
+ this.rawProperty.type = oneOfs.map((value) => ((0, ts_types_1.isJsonMap)(value) ? value.type ?? value.$ref : value)).join('|');
186
187
  }
187
188
  // Handle items references
188
189
  if ((0, ts_types_1.isJsonMap)(this.items) && this.items && this.items.$ref) {
189
190
  Object.assign(this.items, resolveRef(this.schema, this.items));
190
191
  }
191
192
  }
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
193
  get title() {
216
194
  return (0, ts_types_1.asString)(this.rawProperty.title);
217
195
  }
@@ -235,11 +213,34 @@ class SchemaProperty {
235
213
  }
236
214
  getProperty(key) {
237
215
  const properties = this.getProperties();
238
- return (0, ts_types_1.asJsonMap)(properties && properties[key]);
216
+ return (0, ts_types_1.asJsonMap)(properties?.[key]);
239
217
  }
240
218
  getProperties() {
241
219
  return (0, ts_types_1.asJsonMap)(this.rawProperty.properties);
242
220
  }
221
+ renderName() {
222
+ return this.propertyRenderer.renderName(this.name);
223
+ }
224
+ renderTitle() {
225
+ return this.propertyRenderer.renderTitle(this.title ?? '');
226
+ }
227
+ renderDescription() {
228
+ return this.propertyRenderer.renderDescription(this.description ?? '');
229
+ }
230
+ renderType() {
231
+ return this.propertyRenderer.renderType(this.type ?? '');
232
+ }
233
+ renderHeader() {
234
+ return `${this.renderName()}(${this.renderType()}) - ${this.renderTitle()}: ${this.renderDescription()}`;
235
+ }
236
+ renderArrayHeader() {
237
+ if (!this.items) {
238
+ return '';
239
+ }
240
+ const minItems = this.minItems ? ` - min ${this.minItems}` : '';
241
+ const prop = new SchemaProperty(this.logger, this.schema, 'items', this.items, this.propertyRenderer);
242
+ return `items(${prop.renderType()}${minItems}) - ${prop.renderTitle()}: ${prop.renderDescription()}`;
243
+ }
243
244
  }
244
245
  /**
245
246
  * Get the referenced definition by following the reference path on the current schema.
@@ -44,7 +44,7 @@ export declare class SchemaValidator {
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
49
  * Loads local, external schemas from URIs in the same directory as the local schema file.
50
50
  * Does not support loading from remote URIs.
@@ -122,7 +122,7 @@ class SchemaValidator {
122
122
  loadExternalSchemas(schema) {
123
123
  return (0, kit_1.getJsonValuesByName)(schema, '$ref')
124
124
  .map((ref) => ref && RegExp(/([\w\.]+)#/).exec(ref)) // eslint-disable-line no-useless-escape
125
- .map((match) => match && match[1])
125
+ .map((match) => match?.[1])
126
126
  .filter((uri) => !!uri)
127
127
  .map((uri) => this.loadExternalSchema(uri));
128
128
  }
@@ -149,6 +149,7 @@ class SchemaValidator {
149
149
  *
150
150
  * @param errors An array of AJV (DefinedError) objects.
151
151
  */
152
+ // eslint-disable-next-line class-methods-use-this
152
153
  getErrorsText(errors) {
153
154
  return errors
154
155
  .map((error) => {
package/lib/sfError.d.ts CHANGED
@@ -17,6 +17,7 @@ import { JsonMap } from '@salesforce/ts-types';
17
17
  * ```
18
18
  */
19
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
  */
@@ -30,10 +31,6 @@ export declare class SfError extends NamedError {
30
31
  */
31
32
  context?: string;
32
33
  data?: unknown;
33
- /**
34
- * Some errors support `error.code` instead of `error.name`. This keeps backwards compatability.
35
- */
36
- private _code?;
37
34
  /**
38
35
  * Create an SfError.
39
36
  *
@@ -44,14 +41,14 @@ export declare class SfError extends NamedError {
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
47
  * Convert an Error to an SfError.
49
48
  *
50
49
  * @param err The error to convert.
51
50
  */
52
51
  static wrap(err: Error | string): SfError;
53
- get code(): string | undefined | any;
54
- set code(code: string);
55
52
  /**
56
53
  * Sets the context of the error. For convenience `this` object is returned.
57
54
  *
package/lib/sfError.js CHANGED
@@ -5,6 +5,18 @@
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
21
  exports.SfdxError = exports.SfError = void 0;
10
22
  const kit_1 = require("@salesforce/kit");
@@ -37,7 +49,11 @@ class SfError extends kit_1.NamedError {
37
49
  */
38
50
  constructor(message, name, actions, exitCodeOrCause, cause) {
39
51
  cause = exitCodeOrCause instanceof Error ? exitCodeOrCause : cause;
40
- super(name || 'SfError', 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,6 +62,13 @@ class SfError 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
73
  * Convert an Error to an SfError.
51
74
  *
@@ -65,13 +88,6 @@ class SfError extends kit_1.NamedError {
65
88
  }
66
89
  return sfError;
67
90
  }
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;
74
- }
75
91
  /**
76
92
  * Sets the context of the error. For convenience `this` object is returned.
77
93
  *
@@ -104,13 +120,14 @@ class SfError 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
128
  }
113
129
  exports.SfError = SfError;
130
+ _SfError_code = new WeakMap();
114
131
  /**
115
132
  * @deprecated use SfError instead
116
133
  */
package/lib/sfProject.js CHANGED
@@ -87,11 +87,12 @@ class SfProjectJson extends configFile_1.ConfigFile {
87
87
  getContents() {
88
88
  return super.getContents();
89
89
  }
90
+ // eslint-disable-next-line class-methods-use-this
90
91
  getDefaultOptions(options) {
91
92
  const defaultOptions = {
92
93
  isState: false,
93
94
  };
94
- Object.assign(defaultOptions, options || {});
95
+ Object.assign(defaultOptions, options ?? {});
95
96
  return defaultOptions;
96
97
  }
97
98
  /**
@@ -253,8 +254,9 @@ class SfProjectJson extends configFile_1.ConfigFile {
253
254
  /**
254
255
  * Has at least one package alias defined in the project.
255
256
  */
257
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/require-await
256
258
  async hasPackageAliases() {
257
- return Object.keys(this.getContents().packageAliases || {}).length > 0;
259
+ return Object.keys(this.getContents().packageAliases ?? {}).length > 0;
258
260
  }
259
261
  /**
260
262
  * Get package aliases defined in the project.
@@ -309,6 +311,7 @@ class SfProjectJson extends configFile_1.ConfigFile {
309
311
  this.getContents().packageDirectories.push(packageDirEntry);
310
312
  }
311
313
  }
314
+ // eslint-disable-next-line class-methods-use-this
312
315
  doesPackageExist(packagePath) {
313
316
  return fs.existsSync(packagePath);
314
317
  }
@@ -349,7 +352,7 @@ class SfProject {
349
352
  * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
350
353
  */
351
354
  static async resolve(path) {
352
- path = await this.resolveProjectPath(path || process.cwd());
355
+ path = await this.resolveProjectPath(path ?? process.cwd());
353
356
  if (!SfProject.instances.has(path)) {
354
357
  const project = new SfProject(path);
355
358
  SfProject.instances.set(path, project);
@@ -365,7 +368,7 @@ class SfProject {
365
368
  */
366
369
  static getInstance(path) {
367
370
  // Store instance based on the path of the actual project.
368
- path = this.resolveProjectPathSync(path || process.cwd());
371
+ path = this.resolveProjectPathSync(path ?? process.cwd());
369
372
  if (!SfProject.instances.has(path)) {
370
373
  const project = new SfProject(path);
371
374
  SfProject.instances.set(path, project);
@@ -508,7 +511,7 @@ class SfProject {
508
511
  */
509
512
  getPackageNameFromPath(path) {
510
513
  const packageDir = this.getPackageFromPath(path);
511
- return packageDir ? packageDir.package || packageDir.path : undefined;
514
+ return packageDir ? packageDir.package ?? packageDir.path : undefined;
512
515
  }
513
516
  /**
514
517
  * Returns the package directory.
@@ -579,7 +582,7 @@ class SfProject {
579
582
  throw new sfError_1.SfError('The sfdx-project.json does not have any packageDirectories defined.');
580
583
  }
581
584
  const defaultPackage = this.findPackage((packageDir) => packageDir.default === true);
582
- return defaultPackage || this.getPackageDirectories()[0];
585
+ return defaultPackage ?? this.getPackageDirectories()[0];
583
586
  }
584
587
  /**
585
588
  * The project config is resolved from local and global {@link SfProjectJson},
@@ -605,18 +608,23 @@ class SfProject {
605
608
  // Add fields in sfdx-config.json
606
609
  Object.assign(this.projectConfig, configAggregator.getConfig());
607
610
  // we don't have a login url yet, so use instanceUrl from config or default
611
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
608
612
  if (!this.projectConfig.sfdcLoginUrl) {
613
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
609
614
  this.projectConfig.sfdcLoginUrl = configAggregator.getConfig()['org-instance-url'] ?? sfdcUrl_1.SfdcUrl.PRODUCTION;
610
615
  }
611
616
  // LEGACY - Allow override of sfdcLoginUrl via env var FORCE_SFDC_LOGIN_URL
612
617
  if (process.env.FORCE_SFDC_LOGIN_URL) {
618
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
613
619
  this.projectConfig.sfdcLoginUrl = process.env.FORCE_SFDC_LOGIN_URL;
614
620
  }
615
621
  // Allow override of signupTargetLoginUrl via env var SFDX_SCRATCH_ORG_CREATION_LOGIN_URL
616
622
  if (process.env.SFDX_SCRATCH_ORG_CREATION_LOGIN_URL) {
623
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
617
624
  this.projectConfig.signupTargetLoginUrl = process.env.SFDX_SCRATCH_ORG_CREATION_LOGIN_URL;
618
625
  }
619
626
  }
627
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
620
628
  return this.projectConfig;
621
629
  }
622
630
  async hasPackageAliases() {
@@ -14,7 +14,7 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
14
14
  getAll(entity) {
15
15
  // This will only return aliases under "orgs". This will need to be modified
16
16
  // if/when we want to support more aliases groups.
17
- const all = (this.config.getGroup() || {});
17
+ const all = (this.config.getGroup() ?? {});
18
18
  if (entity) {
19
19
  const value = this.getNameOf(entity);
20
20
  return Object.entries(all)
@@ -131,6 +131,7 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
131
131
  /**
132
132
  * Returns the username of given aliasable entity
133
133
  */
134
+ // eslint-disable-next-line class-methods-use-this
134
135
  getNameOf(entity) {
135
136
  if (typeof entity === 'string')
136
137
  return entity;
@@ -56,6 +56,7 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
56
56
  const config = await this.initAuthFile(username);
57
57
  this.configs.set(username, config);
58
58
  });
59
+ // eslint-disable-next-line no-await-in-loop
59
60
  await Promise.all(promises);
60
61
  }
61
62
  return this.getAll(decrypt);
@@ -105,7 +106,7 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
105
106
  */
106
107
  async exists(username) {
107
108
  const config = this.configs.get(username);
108
- return config ? await config.exists() : false;
109
+ return config ? config.exists() : false;
109
110
  }
110
111
  /**
111
112
  * Return the file stats for a given userame's auth file.
@@ -114,7 +115,7 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
114
115
  */
115
116
  async stat(username) {
116
117
  const config = this.configs.get(username);
117
- return config ? await config.stat() : null;
118
+ return config ? config.stat() : null;
118
119
  }
119
120
  /**
120
121
  * Returns true if there is an auth file for the given username
@@ -152,6 +153,7 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
152
153
  this.contents.set(username, contents);
153
154
  }
154
155
  else {
156
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
155
157
  // @ts-ignore
156
158
  org.username ?? (org.username = username);
157
159
  this.contents.set(username, org);
@@ -189,12 +191,12 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
189
191
  return (await config.write());
190
192
  }
191
193
  else {
192
- const contents = this.contents.get(username) || {};
194
+ const contents = this.contents.get(username) ?? {};
193
195
  await this.read(username, false, false);
194
196
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
195
- const config = this.configs.get(username);
196
- config.setContentsFromObject(contents);
197
- return (await config.write());
197
+ const readConfig = this.configs.get(username);
198
+ readConfig.setContentsFromObject(contents);
199
+ return (await readConfig.write());
198
200
  }
199
201
  }
200
202
  async init() {
@@ -218,16 +220,19 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
218
220
  }
219
221
  exports.BaseOrgAccessor = BaseOrgAccessor;
220
222
  class OrgAccessor extends BaseOrgAccessor {
223
+ // eslint-disable-next-line class-methods-use-this
221
224
  async initAuthFile(username, throwOnNotFound = false) {
222
225
  return authInfoConfig_1.AuthInfoConfig.create({
223
226
  ...authInfoConfig_1.AuthInfoConfig.getOptions(username),
224
227
  throwOnNotFound,
225
228
  });
226
229
  }
230
+ // eslint-disable-next-line class-methods-use-this
227
231
  getFileRegex() {
228
232
  // The regular expression that filters files stored in $HOME/.sfdx
229
233
  return /^[^.][^@]*@[^.]+(\.[^.\s]+)+\.json$/;
230
234
  }
235
+ // eslint-disable-next-line class-methods-use-this
231
236
  getFileExtension() {
232
237
  return '.json';
233
238
  }