@salesforce/core 6.7.5 → 6.7.7-qa.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/lib/config/authInfoConfig.js +1 -1
  2. package/lib/config/config.js +6 -5
  3. package/lib/config/configAggregator.js +7 -2
  4. package/lib/config/configFile.js +6 -2
  5. package/lib/config/configStore.js +17 -14
  6. package/lib/config/lwwMap.js +12 -19
  7. package/lib/config/lwwRegister.js +1 -0
  8. package/lib/crypto/crypto.js +3 -1
  9. package/lib/crypto/keyChainImpl.js +2 -0
  10. package/lib/crypto/secureBuffer.js +3 -4
  11. package/lib/deviceOauthService.d.ts +1 -1
  12. package/lib/deviceOauthService.js +8 -6
  13. package/lib/global.js +22 -22
  14. package/lib/index.d.ts +1 -1
  15. package/lib/lifecycleEvents.js +5 -2
  16. package/lib/logger/logger.js +31 -29
  17. package/lib/logger/memoryLogger.js +1 -1
  18. package/lib/messages.js +41 -30
  19. package/lib/org/authInfo.d.ts +1 -1
  20. package/lib/org/authInfo.js +65 -67
  21. package/lib/org/authRemover.js +7 -2
  22. package/lib/org/connection.d.ts +4 -4
  23. package/lib/org/connection.js +33 -22
  24. package/lib/org/org.js +30 -23
  25. package/lib/org/permissionSetAssignment.js +2 -0
  26. package/lib/org/scratchOrgFeatureDeprecation.js +1 -0
  27. package/lib/org/scratchOrgInfoApi.d.ts +1 -1
  28. package/lib/org/scratchOrgInfoApi.js +4 -5
  29. package/lib/org/scratchOrgInfoGenerator.d.ts +2 -2
  30. package/lib/org/scratchOrgInfoGenerator.js +13 -15
  31. package/lib/org/scratchOrgSettingsGenerator.d.ts +4 -4
  32. package/lib/org/scratchOrgSettingsGenerator.js +9 -2
  33. package/lib/org/user.js +24 -16
  34. package/lib/schema/validator.js +4 -0
  35. package/lib/sfError.d.ts +20 -6
  36. package/lib/sfError.js +48 -37
  37. package/lib/sfProject.d.ts +7 -0
  38. package/lib/sfProject.js +25 -15
  39. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +0 -35
  40. package/lib/stateAggregator/accessors/aliasAccessor.js +4 -68
  41. package/lib/stateAggregator/accessors/orgAccessor.js +5 -10
  42. package/lib/stateAggregator/stateAggregator.js +4 -1
  43. package/lib/status/myDomainResolver.js +3 -1
  44. package/lib/status/pollingClient.js +5 -0
  45. package/lib/status/streamingClient.js +16 -4
  46. package/lib/testSetup.d.ts +2 -2
  47. package/lib/testSetup.js +75 -29
  48. package/lib/util/cache.js +21 -35
  49. package/lib/util/directoryWriter.js +1 -0
  50. package/lib/util/getJwtAudienceUrl.d.ts +1 -1
  51. package/lib/util/sfdc.js +1 -1
  52. package/lib/util/sfdcUrl.js +7 -6
  53. package/lib/util/zipWriter.js +4 -1
  54. package/lib/webOAuthServer.js +20 -9
  55. package/package.json +62 -4
  56. package/lib/util/checkLightningDomain.d.ts +0 -2
  57. package/lib/util/checkLightningDomain.js +0 -30
@@ -18,6 +18,8 @@ const messages = new messages_1.Messages('@salesforce/core', 'permissionSetAssig
18
18
  * A class for assigning a Salesforce User to one or more permission sets.
19
19
  */
20
20
  class PermissionSetAssignment {
21
+ logger;
22
+ org;
21
23
  constructor(org, logger) {
22
24
  this.logger = logger;
23
25
  this.org = org;
@@ -36,6 +36,7 @@ const FEATURE_TYPES = {
36
36
  ],
37
37
  };
38
38
  class ScratchOrgFeatureDeprecation {
39
+ featureTypes;
39
40
  // Allow override for testing.
40
41
  constructor(options = FEATURE_TYPES) {
41
42
  this.featureTypes = options;
@@ -1,5 +1,5 @@
1
1
  import { Duration } from '@salesforce/kit';
2
- import { SaveResult } from 'jsforce';
2
+ import { SaveResult } from '@jsforce/jsforce-node';
3
3
  import { AuthInfo } from './authInfo';
4
4
  import { Org } from './org';
5
5
  import SettingsGenerator from './scratchOrgSettingsGenerator';
@@ -228,10 +228,6 @@ const requestScratchOrgCreation = async (hubOrg, scratchOrgRequest, settings) =>
228
228
  if (!hubOrg.isDevHubOrg()) {
229
229
  throw messages.createError('hubOrgIsNotDevHub', [hubOrg.getUsername(), hubOrg.getOrgId()]);
230
230
  }
231
- // If these were present, they were already used to initialize the scratchOrgSettingsGenerator.
232
- // They shouldn't be submitted as part of the scratchOrgInfo.
233
- delete scratchOrgRequest.settings;
234
- delete scratchOrgRequest.objectSettings;
235
231
  // We do not allow you to specify the old and the new way of doing post create settings
236
232
  if (scratchOrgRequest.orgPreferences && settings.hasSettings()) {
237
233
  // This is not allowed
@@ -241,7 +237,10 @@ const requestScratchOrgCreation = async (hubOrg, scratchOrgRequest, settings) =>
241
237
  if (scratchOrgRequest.orgPreferences) {
242
238
  throw new sfError_1.SfError(messages.getMessage('DeprecatedPrefFormat'));
243
239
  }
244
- const scratchOrgInfo = (0, mapKeys_1.default)(scratchOrgRequest, kit_1.upperFirst, true);
240
+ const scratchOrgInfo = (0, mapKeys_1.default)(
241
+ // If these were present, they were already used to initialize the scratchOrgSettingsGenerator.
242
+ // They shouldn't be submitted as part of the scratchOrgInfo.
243
+ (0, kit_1.omit)(scratchOrgRequest, ['settings', 'objectSettings']), kit_1.upperFirst, true);
245
244
  if (typeof scratchOrgInfo.Username === 'string') {
246
245
  scratchOrgInfo.Username = scratchOrgInfo.Username.toLowerCase();
247
246
  }
@@ -30,8 +30,8 @@ export declare const getAncestorIds: (scratchOrgInfo: ScratchOrgInfoPayload, pro
30
30
  export declare const generateScratchOrgInfo: ({ hubOrg, scratchOrgInfoPayload, nonamespace, ignoreAncestorIds, }: {
31
31
  hubOrg: Org;
32
32
  scratchOrgInfoPayload: ScratchOrgInfoPayload;
33
- nonamespace?: boolean | undefined;
34
- ignoreAncestorIds?: boolean | undefined;
33
+ nonamespace?: boolean;
34
+ ignoreAncestorIds?: boolean;
35
35
  }) => Promise<ScratchOrgInfoPayload>;
36
36
  /**
37
37
  * Returns a valid signup json
@@ -144,22 +144,20 @@ const generateScratchOrgInfo = async ({ hubOrg, scratchOrgInfoPayload, nonamespa
144
144
  catch (e) {
145
145
  // project is not required
146
146
  }
147
- scratchOrgInfoPayload.orgName = scratchOrgInfoPayload.orgName ?? 'Company';
148
- scratchOrgInfoPayload.package2AncestorIds =
149
- !ignoreAncestorIds && sfProject?.hasPackages()
147
+ return {
148
+ ...scratchOrgInfoPayload,
149
+ orgName: scratchOrgInfoPayload.orgName ?? 'Company',
150
+ // we already have the info, and want to get rid of configApi, so this doesn't use that
151
+ connectedAppCallbackUrl: `http://localhost:${await webOAuthServer_1.WebOAuthServer.determineOauthPort()}/OauthRedirect`,
152
+ ...(!nonamespace && sfProject?.get('namespace') ? { namespace: sfProject.get('namespace') } : {}),
153
+ // Use the Hub org's client ID value, if one wasn't provided to us, or the default
154
+ connectedAppConsumerKey: scratchOrgInfoPayload.connectedAppConsumerKey ??
155
+ hubOrg.getConnection().getAuthInfoFields().clientId ??
156
+ authInfo_1.DEFAULT_CONNECTED_APP_INFO.clientId,
157
+ package2AncestorIds: !ignoreAncestorIds && sfProject?.hasPackages()
150
158
  ? await (0, exports.getAncestorIds)(scratchOrgInfoPayload, sfProject, hubOrg)
151
- : '';
152
- // Use the Hub org's client ID value, if one wasn't provided to us, or the default
153
- if (!scratchOrgInfoPayload.connectedAppConsumerKey) {
154
- scratchOrgInfoPayload.connectedAppConsumerKey =
155
- hubOrg.getConnection().getAuthInfoFields().clientId ?? authInfo_1.DEFAULT_CONNECTED_APP_INFO.clientId;
156
- }
157
- if (!nonamespace && sfProject?.get('namespace')) {
158
- scratchOrgInfoPayload.namespace = sfProject.get('namespace');
159
- }
160
- // we already have the info, and want to get rid of configApi, so this doesn't use that
161
- scratchOrgInfoPayload.connectedAppCallbackUrl = `http://localhost:${await webOAuthServer_1.WebOAuthServer.determineOauthPort()}/OauthRedirect`;
162
- return scratchOrgInfoPayload;
159
+ : '',
160
+ };
163
161
  };
164
162
  exports.generateScratchOrgInfo = generateScratchOrgInfo;
165
163
  /**
@@ -23,13 +23,13 @@ export interface PackageFile {
23
23
  version: string;
24
24
  }
25
25
  export declare const createObjectFileContent: ({ allRecordTypes, allBusinessProcesses, apiVersion, settingData, objectSettingsData, }: {
26
- allRecordTypes?: string[] | undefined;
27
- allBusinessProcesses?: string[] | undefined;
26
+ allRecordTypes?: string[];
27
+ allBusinessProcesses?: string[];
28
28
  apiVersion: string;
29
- settingData?: Record<string, unknown> | undefined;
29
+ settingData?: Record<string, unknown>;
30
30
  objectSettingsData?: {
31
31
  [objectName: string]: ObjectSetting;
32
- } | undefined;
32
+ };
33
33
  }) => PackageFile;
34
34
  export declare const createRecordTypeAndBusinessProcessFileContent: (objectName: string, json: Record<string, unknown>, allRecordTypes: string[], allBusinessProcesses: string[], capitalizeRecordTypes: boolean) => JsonMap;
35
35
  /**
@@ -166,9 +166,16 @@ exports.createRecordTypeAndBusinessProcessFileContent = createRecordTypeAndBusin
166
166
  * settings from the definition, how to expand them into a MD directory and how to generate a package.xml.
167
167
  */
168
168
  class SettingsGenerator {
169
+ settingData;
170
+ objectSettingsData;
171
+ logger;
172
+ writer;
173
+ allRecordTypes = [];
174
+ allBusinessProcesses = [];
175
+ shapeDirName;
176
+ packageFilePath;
177
+ capitalizeRecordTypes;
169
178
  constructor(options) {
170
- this.allRecordTypes = [];
171
- this.allBusinessProcesses = [];
172
179
  this.logger = logger_1.Logger.childFromRoot('SettingsGenerator');
173
180
  if (options?.capitalizeRecordTypes === undefined) {
174
181
  const messages = new messages_1.Messages('@salesforce/core', 'scratchOrgSettingsGenerator', new Map([["noCapitalizeRecordTypeConfigVar", "Record types defined in the scratch org definition file will stop being capitalized by default in a future release.\nSet the `org-capitalize-record-types` config var to `true` to enforce capitalization."]]));
package/lib/org/user.js CHANGED
@@ -10,7 +10,7 @@ exports.User = exports.DefaultUserFields = exports.REQUIRED_FIELDS = void 0;
10
10
  const node_os_1 = require("node:os");
11
11
  const kit_1 = require("@salesforce/kit");
12
12
  const ts_types_1 = require("@salesforce/ts-types");
13
- const http_api_1 = require("jsforce/lib/http-api");
13
+ const http_api_1 = require("@jsforce/jsforce-node/lib/http-api");
14
14
  const logger_1 = require("../logger/logger");
15
15
  const messages_1 = require("../messages");
16
16
  const secureBuffer_1 = require("../crypto/secureBuffer");
@@ -63,17 +63,9 @@ async function retrieveUserFields(logger, username) {
63
63
  const connection = await connection_1.Connection.create({
64
64
  authInfo: await authInfo_1.AuthInfo.create({ username }),
65
65
  });
66
- if ((0, sfdc_1.matchesAccessToken)(username)) {
67
- logger.debug('received an accessToken for the username. Converting...');
68
- username = (await connection.identity()).username;
69
- logger.debug(`accessToken converted to ${username}`);
70
- }
71
- else {
72
- logger.debug('not a accessToken');
73
- }
74
- const fromFields = Object.keys(exports.REQUIRED_FIELDS).map(kit_1.upperFirst);
75
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
76
- const requiredFieldsFromAdminQuery = `SELECT ${fromFields} FROM User WHERE Username='${username}'`;
66
+ const resolvedUsername = await resolveUsernameFromAccessToken(logger)(connection)(username);
67
+ const fromFields = Object.keys(exports.REQUIRED_FIELDS).map(kit_1.upperFirst).filter(ts_types_1.isString).join(', ');
68
+ const requiredFieldsFromAdminQuery = `SELECT ${fromFields} FROM User WHERE Username='${resolvedUsername}'`;
77
69
  const result = await connection.query(requiredFieldsFromAdminQuery);
78
70
  logger.debug('Successfully retrieved the admin user for this org.');
79
71
  if (result.totalSize === 1) {
@@ -93,7 +85,7 @@ async function retrieveUserFields(logger, username) {
93
85
  return fields;
94
86
  }
95
87
  else {
96
- throw messages.createError('userQueryFailed', [username]);
88
+ throw messages.createError('userQueryFailed', [resolvedUsername]);
97
89
  }
98
90
  }
99
91
  /**
@@ -128,6 +120,10 @@ async function retrieveProfileId(name, connection) {
128
120
  * ```
129
121
  */
130
122
  class DefaultUserFields extends kit_1.AsyncCreatable {
123
+ // Initialized in init
124
+ logger;
125
+ userFields;
126
+ options;
131
127
  /**
132
128
  * @ignore
133
129
  */
@@ -165,6 +161,8 @@ exports.DefaultUserFields = DefaultUserFields;
165
161
  * See methods for examples.
166
162
  */
167
163
  class User extends kit_1.AsyncCreatable {
164
+ org;
165
+ logger;
168
166
  /**
169
167
  * @ignore
170
168
  */
@@ -399,15 +397,15 @@ class User extends kit_1.AsyncCreatable {
399
397
  this.logger.debug(message);
400
398
  throw new sfError_1.SfError(message, 'UserCreateHttpError');
401
399
  }
402
- fields.id = (0, ts_types_1.ensureString)(responseBody.id);
403
- await this.updateRequiredUserFields(fields);
400
+ const fieldsWithId = { ...fields, id: (0, ts_types_1.ensureString)(responseBody.id) };
401
+ await this.updateRequiredUserFields(fieldsWithId);
404
402
  const buffer = new secureBuffer_1.SecureBuffer();
405
403
  const headers = (0, ts_types_1.ensureJsonMap)(response.headers);
406
404
  const autoApproveUser = (0, ts_types_1.ensureString)(headers['auto-approve-user']);
407
405
  buffer.consume(Buffer.from(autoApproveUser));
408
406
  return {
409
407
  buffer,
410
- userId: fields.id,
408
+ userId: fieldsWithId.id,
411
409
  };
412
410
  }
413
411
  // eslint-disable-next-line class-methods-use-this
@@ -437,4 +435,14 @@ class User extends kit_1.AsyncCreatable {
437
435
  }
438
436
  }
439
437
  exports.User = User;
438
+ const resolveUsernameFromAccessToken = (logger) => (conn) => async (usernameOrAccessToken) => {
439
+ if ((0, sfdc_1.matchesAccessToken)(usernameOrAccessToken)) {
440
+ logger.debug('received an accessToken for the username. Converting...');
441
+ const username = (await conn.identity()).username;
442
+ logger.debug(`accessToken converted to ${username}`);
443
+ return username;
444
+ }
445
+ logger.debug('not a accessToken');
446
+ return usernameOrAccessToken;
447
+ };
440
448
  //# sourceMappingURL=user.js.map
@@ -42,6 +42,10 @@ const sfError_1 = require("../sfError");
42
42
  * Loads a JSON schema and performs validations against JSON objects.
43
43
  */
44
44
  class SchemaValidator {
45
+ schemaPath;
46
+ schemasDir;
47
+ logger;
48
+ schema;
45
49
  /**
46
50
  * Creates a new `SchemaValidator` instance given a logger and path to a schema file.
47
51
  *
package/lib/sfError.d.ts CHANGED
@@ -1,5 +1,15 @@
1
- import { NamedError } from '@salesforce/kit';
2
- import { JsonMap } from '@salesforce/ts-types';
1
+ import { AnyJson, JsonMap } from '@salesforce/ts-types';
2
+ export type SfErrorOptions<T extends ErrorDataProperties = ErrorDataProperties> = {
3
+ message: string;
4
+ exitCode?: number;
5
+ name?: string;
6
+ data?: T;
7
+ /** pass an Error. For convenience in catch blocks, code will check that it is, in fact, an Error */
8
+ cause?: unknown;
9
+ context?: string;
10
+ actions?: string[];
11
+ };
12
+ type ErrorDataProperties = AnyJson;
3
13
  /**
4
14
  * A generalized sfdx error which also contains an action. The action is used in the
5
15
  * CLI to help guide users past the error.
@@ -16,8 +26,9 @@ import { JsonMap } from '@salesforce/ts-types';
16
26
  * throw new SfError(message.getMessage('myError'), 'MyErrorName');
17
27
  * ```
18
28
  */
19
- export declare class SfError<T = unknown> extends NamedError {
29
+ export declare class SfError<T extends ErrorDataProperties = ErrorDataProperties> extends Error {
20
30
  #private;
31
+ readonly name: string;
21
32
  /**
22
33
  * Action messages. Hints to the users regarding what can be done to fix related issues.
23
34
  */
@@ -40,15 +51,17 @@ export declare class SfError<T = unknown> extends NamedError {
40
51
  * @param exitCodeOrCause The exit code which will be used by SfdxCommand or he underlying error that caused this error to be raised.
41
52
  * @param cause The underlying error that caused this error to be raised.
42
53
  */
43
- constructor(message: string, name?: string, actions?: string[], exitCodeOrCause?: number | Error, cause?: Error);
44
- get code(): any;
54
+ constructor(message: string, name?: string, actions?: string[], exitCodeOrCause?: number | Error, cause?: unknown);
55
+ get code(): string;
45
56
  set code(code: string);
57
+ /** like the constructor, but takes an typed object and let you also set context and data properties */
58
+ static create<T extends ErrorDataProperties = ErrorDataProperties>(inputs: SfErrorOptions<T>): SfError<T>;
46
59
  /**
47
60
  * Convert an Error to an SfError.
48
61
  *
49
62
  * @param err The error to convert.
50
63
  */
51
- static wrap(err: Error | string): SfError;
64
+ static wrap<T extends ErrorDataProperties = ErrorDataProperties>(err: unknown): SfError<T>;
52
65
  /**
53
66
  * Sets the context of the error. For convenience `this` object is returned.
54
67
  *
@@ -66,3 +79,4 @@ export declare class SfError<T = unknown> extends NamedError {
66
79
  */
67
80
  toObject(): JsonMap;
68
81
  }
82
+ export {};
package/lib/sfError.js CHANGED
@@ -5,21 +5,8 @@
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;
20
8
  Object.defineProperty(exports, "__esModule", { value: true });
21
9
  exports.SfError = void 0;
22
- const kit_1 = require("@salesforce/kit");
23
10
  const ts_types_1 = require("@salesforce/ts-types");
24
11
  /**
25
12
  * A generalized sfdx error which also contains an action. The action is used in the
@@ -37,7 +24,26 @@ const ts_types_1 = require("@salesforce/ts-types");
37
24
  * throw new SfError(message.getMessage('myError'), 'MyErrorName');
38
25
  * ```
39
26
  */
40
- class SfError extends kit_1.NamedError {
27
+ class SfError extends Error {
28
+ name;
29
+ /**
30
+ * Action messages. Hints to the users regarding what can be done to fix related issues.
31
+ */
32
+ actions;
33
+ /**
34
+ * SfdxCommand can return this process exit code.
35
+ */
36
+ exitCode;
37
+ /**
38
+ * The related context for this error.
39
+ */
40
+ context;
41
+ // Additional data helpful for consumers of this error. E.g., API call result
42
+ data;
43
+ /**
44
+ * Some errors support `error.code` instead of `error.name`. This keeps backwards compatability.
45
+ */
46
+ #code;
41
47
  /**
42
48
  * Create an SfError.
43
49
  *
@@ -47,13 +53,13 @@ class SfError extends kit_1.NamedError {
47
53
  * @param exitCodeOrCause The exit code which will be used by SfdxCommand or he underlying error that caused this error to be raised.
48
54
  * @param cause The underlying error that caused this error to be raised.
49
55
  */
50
- constructor(message, name, actions, exitCodeOrCause, cause) {
51
- cause = exitCodeOrCause instanceof Error ? exitCodeOrCause : 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);
56
+ constructor(message, name = 'SfError', actions, exitCodeOrCause, cause) {
57
+ if (typeof cause !== 'undefined' && !(cause instanceof Error)) {
58
+ throw new TypeError(`The cause, if provided, must be an instance of Error. Received: ${typeof cause}`);
59
+ }
60
+ super(message);
61
+ this.name = name;
62
+ this.cause = exitCodeOrCause instanceof Error ? exitCodeOrCause : cause;
57
63
  this.actions = actions;
58
64
  if (typeof exitCodeOrCause === 'number') {
59
65
  this.exitCode = exitCodeOrCause;
@@ -62,12 +68,18 @@ class SfError extends kit_1.NamedError {
62
68
  this.exitCode = 1;
63
69
  }
64
70
  }
65
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
71
  get code() {
67
- return __classPrivateFieldGet(this, _SfError_code, "f") ?? this.name;
72
+ return this.#code ?? this.name;
68
73
  }
69
74
  set code(code) {
70
- __classPrivateFieldSet(this, _SfError_code, code, "f");
75
+ this.#code = code;
76
+ }
77
+ /** like the constructor, but takes an typed object and let you also set context and data properties */
78
+ static create(inputs) {
79
+ const error = new SfError(inputs.message, inputs.name, inputs.actions, inputs.exitCode, inputs.cause);
80
+ error.data = inputs.data;
81
+ error.context = inputs.context;
82
+ return error;
71
83
  }
72
84
  /**
73
85
  * Convert an Error to an SfError.
@@ -81,7 +93,15 @@ class SfError extends kit_1.NamedError {
81
93
  if (err instanceof SfError) {
82
94
  return err;
83
95
  }
84
- const sfError = new SfError(err.message, err.name, undefined, err);
96
+ const sfError = err instanceof Error
97
+ ? // a basic error with message and name. We make it the cause to preserve any other properties
98
+ SfError.create({
99
+ message: err.message,
100
+ name: err.name,
101
+ cause: err,
102
+ })
103
+ : // ok, something was throws that wasn't error or string. Convert it to an Error that preserves the information as the cause and wrap that.
104
+ SfError.wrap(new Error(`SfError.wrap received type ${typeof err} but expects type Error or string`, { cause: err }));
85
105
  // If the original error has a code, use that instead of name.
86
106
  if ((0, ts_types_1.hasString)(err, 'code')) {
87
107
  sfError.code = err.code;
@@ -110,24 +130,15 @@ class SfError extends kit_1.NamedError {
110
130
  * Convert an {@link SfError} state to an object. Returns a plain object representing the state of this error.
111
131
  */
112
132
  toObject() {
113
- const obj = {
133
+ return {
114
134
  name: this.name,
115
135
  message: this.message ?? this.name,
116
136
  exitCode: this.exitCode,
117
137
  actions: this.actions,
138
+ ...(this.context ? { context: this.context } : {}),
139
+ ...(this.data ? { data: this.data } : {}),
118
140
  };
119
- if (this.context) {
120
- obj.context = this.context;
121
- }
122
- if (this.data) {
123
- // DANGER: data was previously typed as `unknown` and this assertion was here on the toObject.
124
- // TODO in next major release: put proper type constraint on SfError.data to something that can serialize
125
- // while we're making breaking changes, provide a more definite type for toObject
126
- obj.data = this.data;
127
- }
128
- return obj;
129
141
  }
130
142
  }
131
143
  exports.SfError = SfError;
132
- _SfError_code = new WeakMap();
133
144
  //# sourceMappingURL=sfError.js.map
@@ -14,6 +14,10 @@ export type PackageDir = {
14
14
  dependencies?: PackageDirDependency[];
15
15
  includeProfileUserLicenses?: boolean;
16
16
  package?: string;
17
+ packageMetadataAccess?: {
18
+ permissionSets: string | string[];
19
+ permissionSetLicenses: string | string[];
20
+ };
17
21
  path: string;
18
22
  postInstallScript?: string;
19
23
  postInstallUrl?: string;
@@ -225,6 +229,9 @@ export declare class SfProject {
225
229
  * **See** [process.cwd()](https://nodejs.org/api/process.html#process_process_cwd)
226
230
  */
227
231
  static resolveProjectPathSync(dir?: string): string;
232
+ /** shared method for resolve and getInstance.
233
+ * Cannot be a module-level function because instances is private */
234
+ private static getMemoizedInstance;
228
235
  /**
229
236
  * Returns the project path.
230
237
  */
package/lib/sfProject.js CHANGED
@@ -63,6 +63,7 @@ const coreMessages = new messages_1.Messages('@salesforce/core', 'core', new Map
63
63
  * **See** [force:project:create](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_create_new.htm)
64
64
  */
65
65
  class SfProjectJson extends configFile_1.ConfigFile {
66
+ static BLOCKLIST = ['packageAliases'];
66
67
  static getFileName() {
67
68
  return internal_1.SFDX_PROJECT_JSON;
68
69
  }
@@ -313,7 +314,6 @@ class SfProjectJson extends configFile_1.ConfigFile {
313
314
  }
314
315
  }
315
316
  exports.SfProjectJson = SfProjectJson;
316
- SfProjectJson.BLOCKLIST = ['packageAliases'];
317
317
  /**
318
318
  * Represents an SFDX project directory. This directory contains a {@link SfProjectJson} config file as well as
319
319
  * a hidden .sfdx folder that contains all the other local project config files.
@@ -325,6 +325,17 @@ SfProjectJson.BLOCKLIST = ['packageAliases'];
325
325
  * ```
326
326
  */
327
327
  class SfProject {
328
+ path;
329
+ // Cache of SfProject instances per path.
330
+ static instances = new Map();
331
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
332
+ projectConfig;
333
+ // Dynamically referenced in retrieveSfProjectJson
334
+ sfProjectJson;
335
+ sfProjectJsonGlobal;
336
+ packageDirectories;
337
+ activePackage;
338
+ packageAliases;
328
339
  /**
329
340
  * Do not directly construct instances of this class -- use {@link SfProject.resolve} instead.
330
341
  *
@@ -341,12 +352,8 @@ class SfProject {
341
352
  * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
342
353
  */
343
354
  static async resolve(path) {
344
- path = await this.resolveProjectPath(path ?? process.cwd());
345
- if (!SfProject.instances.has(path)) {
346
- const project = new SfProject(path);
347
- SfProject.instances.set(path, project);
348
- }
349
- return (0, ts_types_1.ensure)(SfProject.instances.get(path));
355
+ const resolvedPath = await this.resolveProjectPath(path ?? process.cwd());
356
+ return this.getMemoizedInstance(resolvedPath);
350
357
  }
351
358
  /**
352
359
  * Get a Project from a given path or from the working directory.
@@ -357,12 +364,8 @@ class SfProject {
357
364
  */
358
365
  static getInstance(path) {
359
366
  // Store instance based on the path of the actual project.
360
- path = this.resolveProjectPathSync(path ?? process.cwd());
361
- if (!SfProject.instances.has(path)) {
362
- const project = new SfProject(path);
363
- SfProject.instances.set(path, project);
364
- }
365
- return (0, ts_types_1.ensure)(SfProject.instances.get(path));
367
+ const resolvedPath = this.resolveProjectPathSync(path ?? process.cwd());
368
+ return this.getMemoizedInstance(resolvedPath);
366
369
  }
367
370
  /**
368
371
  * Performs an upward directory search for an sfdx project file. Returns the absolute path to the project.
@@ -392,6 +395,15 @@ class SfProject {
392
395
  static resolveProjectPathSync(dir) {
393
396
  return (0, internal_1.resolveProjectPathSync)(dir);
394
397
  }
398
+ /** shared method for resolve and getInstance.
399
+ * Cannot be a module-level function because instances is private */
400
+ static getMemoizedInstance(path) {
401
+ if (!SfProject.instances.has(path)) {
402
+ const project = new SfProject(path);
403
+ SfProject.instances.set(path, project);
404
+ }
405
+ return (0, ts_types_1.ensure)(SfProject.instances.get(path));
406
+ }
395
407
  /**
396
408
  * Returns the project path.
397
409
  */
@@ -652,6 +664,4 @@ class SfProject {
652
664
  }
653
665
  }
654
666
  exports.SfProject = SfProject;
655
- // Cache of SfProject instances per path.
656
- SfProject.instances = new Map();
657
667
  //# sourceMappingURL=sfProject.js.map
@@ -58,14 +58,6 @@ export declare class AliasAccessor extends AsyncOptionalCreatable {
58
58
  * @param usernameOrAlias a string that might be a username or might be an alias
59
59
  */
60
60
  resolveAlias(usernameOrAlias: string): string | undefined;
61
- /**
62
- * Set an alias for the given aliasable entity. Writes to the file
63
- *
64
- * @deprecated use setAndSave
65
- * @param alias the alias you want to set
66
- * @param entity the aliasable entity that's being aliased
67
- */
68
- set(alias: string, entity: Aliasable): void;
69
61
  /**
70
62
  * Set an alias for the given aliasable entity. Writes to the file
71
63
  *
@@ -73,36 +65,17 @@ export declare class AliasAccessor extends AsyncOptionalCreatable {
73
65
  * @param entity the aliasable entity that's being aliased
74
66
  */
75
67
  setAndSave(alias: string, entity: Aliasable): Promise<void>;
76
- /**
77
- * Unset the given alias. Writes to the file
78
- *
79
- * @deprecated use unsetAndSave
80
- *
81
- */
82
- unset(alias: string): void;
83
68
  /**
84
69
  * Unset the given alias(es). Writes to the file
85
70
  *
86
71
  */
87
72
  unsetAndSave(alias: string): Promise<void>;
88
- /**
89
- * Unsets all the aliases for the given entity.
90
- *
91
- * @deprecated use unsetValuesAndSave
92
- *
93
- * @param entity the aliasable entity for which you want to unset all aliases
94
- */
95
- unsetAll(entity: Aliasable): void;
96
73
  /**
97
74
  * Unset all the aliases for the given array of entity.
98
75
  *
99
76
  * @param entity the aliasable entity for which you want to unset all aliases
100
77
  */
101
78
  unsetValuesAndSave(aliasees: Aliasable[]): Promise<void>;
102
- /**
103
- * @deprecated the set/unset methods now write to the file when called. Use (un)setAndSave instead of calling (un)set and then calling write()
104
- */
105
- write(): Promise<ConfigContents<string>>;
106
79
  /**
107
80
  * Returns true if the provided alias exists
108
81
  *
@@ -116,13 +89,5 @@ export declare class AliasAccessor extends AsyncOptionalCreatable {
116
89
  */
117
90
  private readFileToAliasStore;
118
91
  private saveAliasStoreToFile;
119
- /**
120
- * @deprecated use the async version of this method instead
121
- * provided for the legacy sync set/unset methods. */
122
- private readFileToAliasStoreSync;
123
- /**
124
- * @deprecated use the async version of this method instead
125
- * provided for the legacy sync set/unset methods */
126
- private saveAliasStoreToFileSync;
127
92
  }
128
93
  export declare const getFileLocation: () => string;