@salesforce/core 6.7.6 → 6.7.7-qa.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/lib/config/authInfoConfig.js +1 -1
- package/lib/config/config.d.ts +4 -4
- package/lib/config/config.js +6 -5
- package/lib/config/configAggregator.d.ts +2 -2
- package/lib/config/configAggregator.js +7 -2
- package/lib/config/configFile.d.ts +2 -2
- package/lib/config/configFile.js +6 -2
- package/lib/config/configStore.d.ts +4 -4
- package/lib/config/configStore.js +17 -14
- package/lib/config/lwwMap.js +12 -19
- package/lib/config/lwwRegister.js +1 -0
- package/lib/config/orgUsersConfig.d.ts +2 -2
- package/lib/config/sandboxOrgConfig.d.ts +2 -2
- package/lib/crypto/crypto.d.ts +2 -2
- package/lib/crypto/crypto.js +3 -1
- package/lib/crypto/keyChainImpl.d.ts +6 -6
- package/lib/crypto/keyChainImpl.js +2 -0
- package/lib/crypto/secureBuffer.js +3 -4
- package/lib/deviceOauthService.d.ts +5 -5
- package/lib/deviceOauthService.js +8 -6
- package/lib/global.js +22 -22
- package/lib/index.d.ts +1 -1
- package/lib/lifecycleEvents.js +5 -2
- package/lib/logger/logger.d.ts +4 -4
- package/lib/logger/logger.js +31 -29
- package/lib/logger/memoryLogger.js +1 -1
- package/lib/messageTransformer.d.ts +1 -1
- package/lib/messageTransformer.js +17 -37
- package/lib/messages.js +41 -30
- package/lib/org/authInfo.d.ts +5 -5
- package/lib/org/authInfo.js +65 -67
- package/lib/org/authRemover.js +7 -2
- package/lib/org/connection.d.ts +8 -8
- package/lib/org/connection.js +33 -22
- package/lib/org/org.d.ts +10 -10
- package/lib/org/org.js +30 -23
- package/lib/org/permissionSetAssignment.d.ts +2 -2
- package/lib/org/permissionSetAssignment.js +2 -0
- package/lib/org/scratchOrgCreate.d.ts +4 -4
- package/lib/org/scratchOrgFeatureDeprecation.d.ts +2 -2
- package/lib/org/scratchOrgFeatureDeprecation.js +1 -0
- package/lib/org/scratchOrgInfoApi.d.ts +1 -1
- package/lib/org/scratchOrgInfoApi.js +4 -5
- package/lib/org/scratchOrgInfoGenerator.d.ts +4 -4
- package/lib/org/scratchOrgInfoGenerator.js +13 -15
- package/lib/org/scratchOrgLifecycleEvents.d.ts +2 -2
- package/lib/org/scratchOrgSettingsGenerator.d.ts +8 -8
- package/lib/org/scratchOrgSettingsGenerator.js +9 -2
- package/lib/org/scratchOrgTypes.d.ts +4 -4
- package/lib/org/user.d.ts +6 -6
- package/lib/org/user.js +24 -16
- package/lib/schema/validator.js +4 -0
- package/lib/sfError.d.ts +20 -6
- package/lib/sfError.js +48 -37
- package/lib/sfProject.d.ts +3 -0
- package/lib/sfProject.js +25 -15
- package/lib/stateAggregator/accessors/aliasAccessor.d.ts +0 -35
- package/lib/stateAggregator/accessors/aliasAccessor.js +4 -68
- package/lib/stateAggregator/accessors/orgAccessor.js +5 -10
- package/lib/stateAggregator/stateAggregator.js +4 -1
- package/lib/status/myDomainResolver.d.ts +2 -2
- package/lib/status/myDomainResolver.js +3 -1
- package/lib/status/pollingClient.d.ts +2 -2
- package/lib/status/pollingClient.js +5 -0
- package/lib/status/streamingClient.d.ts +4 -4
- package/lib/status/streamingClient.js +16 -4
- package/lib/status/types.d.ts +6 -6
- package/lib/testSetup.d.ts +8 -8
- package/lib/testSetup.js +75 -29
- package/lib/util/cache.js +21 -35
- package/lib/util/directoryWriter.js +1 -0
- package/lib/util/getJwtAudienceUrl.d.ts +1 -1
- package/lib/util/sfdc.js +1 -1
- package/lib/util/sfdcUrl.js +7 -6
- package/lib/util/structuredWriter.d.ts +2 -2
- package/lib/util/zipWriter.js +4 -1
- package/lib/webOAuthServer.d.ts +4 -4
- package/lib/webOAuthServer.js +20 -9
- package/package.json +20 -5
- package/lib/util/checkLightningDomain.d.ts +0 -2
- package/lib/util/checkLightningDomain.js +0 -30
package/lib/org/user.d.ts
CHANGED
|
@@ -62,15 +62,15 @@ export declare namespace DefaultUserFields {
|
|
|
62
62
|
* Used to initialize default values for fields based on a templateUser user. This user will be part of the
|
|
63
63
|
* Standard User profile.
|
|
64
64
|
*/
|
|
65
|
-
|
|
65
|
+
type Options = {
|
|
66
66
|
templateUser: string;
|
|
67
67
|
newUserName?: string;
|
|
68
|
-
}
|
|
68
|
+
};
|
|
69
69
|
}
|
|
70
|
-
export
|
|
70
|
+
export type PasswordConditions = {
|
|
71
71
|
length: number;
|
|
72
72
|
complexity: number;
|
|
73
|
-
}
|
|
73
|
+
};
|
|
74
74
|
/**
|
|
75
75
|
* A class for creating a User, generating a password for a user, and assigning a user to one or more permission sets.
|
|
76
76
|
* See methods for examples.
|
|
@@ -181,7 +181,7 @@ export declare namespace User {
|
|
|
181
181
|
* Used to initialize default values for fields based on a templateUser user. This user will be part of the
|
|
182
182
|
* Standard User profile.
|
|
183
183
|
*/
|
|
184
|
-
|
|
184
|
+
type Options = {
|
|
185
185
|
org: Org;
|
|
186
|
-
}
|
|
186
|
+
};
|
|
187
187
|
}
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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', [
|
|
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
|
|
403
|
-
await this.updateRequiredUserFields(
|
|
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:
|
|
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
|
package/lib/schema/validator.js
CHANGED
|
@@ -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 {
|
|
2
|
-
|
|
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 =
|
|
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?:
|
|
44
|
-
get code():
|
|
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:
|
|
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
|
|
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
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
72
|
+
return this.#code ?? this.name;
|
|
68
73
|
}
|
|
69
74
|
set code(code) {
|
|
70
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
package/lib/sfProject.d.ts
CHANGED
|
@@ -229,6 +229,9 @@ export declare class SfProject {
|
|
|
229
229
|
* **See** [process.cwd()](https://nodejs.org/api/process.html#process_process_cwd)
|
|
230
230
|
*/
|
|
231
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;
|
|
232
235
|
/**
|
|
233
236
|
* Returns the project path.
|
|
234
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
|
-
|
|
345
|
-
|
|
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
|
-
|
|
361
|
-
|
|
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;
|
|
@@ -10,7 +10,6 @@ exports.getFileLocation = exports.AliasAccessor = exports.FILENAME = exports.DEF
|
|
|
10
10
|
const node_path_1 = require("node:path");
|
|
11
11
|
const node_os_1 = require("node:os");
|
|
12
12
|
const promises_1 = require("node:fs/promises");
|
|
13
|
-
const node_fs_1 = require("node:fs");
|
|
14
13
|
const proper_lockfile_1 = require("proper-lockfile");
|
|
15
14
|
const kit_1 = require("@salesforce/kit");
|
|
16
15
|
const global_1 = require("../../global");
|
|
@@ -19,6 +18,10 @@ const lockRetryOptions_1 = require("../../util/lockRetryOptions");
|
|
|
19
18
|
exports.DEFAULT_GROUP = 'orgs';
|
|
20
19
|
exports.FILENAME = 'alias.json';
|
|
21
20
|
class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
21
|
+
// set in init method
|
|
22
|
+
fileLocation;
|
|
23
|
+
/** orgs is the default group */
|
|
24
|
+
aliasStore;
|
|
22
25
|
getAll(entity) {
|
|
23
26
|
// This will only return aliases under "orgs". This will need to be modified
|
|
24
27
|
// if/when we want to support more aliases groups.
|
|
@@ -83,19 +86,6 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
83
86
|
return usernameOrAlias;
|
|
84
87
|
return Array.from(this.aliasStore.entries()).find(([, value]) => value === usernameOrAlias)?.[0];
|
|
85
88
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Set an alias for the given aliasable entity. Writes to the file
|
|
88
|
-
*
|
|
89
|
-
* @deprecated use setAndSave
|
|
90
|
-
* @param alias the alias you want to set
|
|
91
|
-
* @param entity the aliasable entity that's being aliased
|
|
92
|
-
*/
|
|
93
|
-
set(alias, entity) {
|
|
94
|
-
// get a very fresh copy to merge with to avoid conflicts
|
|
95
|
-
this.readFileToAliasStoreSync();
|
|
96
|
-
this.aliasStore.set(alias, getNameOf(entity));
|
|
97
|
-
this.saveAliasStoreToFileSync();
|
|
98
|
-
}
|
|
99
89
|
/**
|
|
100
90
|
* Set an alias for the given aliasable entity. Writes to the file
|
|
101
91
|
*
|
|
@@ -108,17 +98,6 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
108
98
|
this.aliasStore.set(alias, getNameOf(entity));
|
|
109
99
|
return this.saveAliasStoreToFile();
|
|
110
100
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Unset the given alias. Writes to the file
|
|
113
|
-
*
|
|
114
|
-
* @deprecated use unsetAndSave
|
|
115
|
-
*
|
|
116
|
-
*/
|
|
117
|
-
unset(alias) {
|
|
118
|
-
this.readFileToAliasStoreSync();
|
|
119
|
-
this.aliasStore.delete(alias);
|
|
120
|
-
this.saveAliasStoreToFileSync();
|
|
121
|
-
}
|
|
122
101
|
/**
|
|
123
102
|
* Unset the given alias(es). Writes to the file
|
|
124
103
|
*
|
|
@@ -128,19 +107,6 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
128
107
|
this.aliasStore.delete(alias);
|
|
129
108
|
return this.saveAliasStoreToFile();
|
|
130
109
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Unsets all the aliases for the given entity.
|
|
133
|
-
*
|
|
134
|
-
* @deprecated use unsetValuesAndSave
|
|
135
|
-
*
|
|
136
|
-
* @param entity the aliasable entity for which you want to unset all aliases
|
|
137
|
-
*/
|
|
138
|
-
unsetAll(entity) {
|
|
139
|
-
this.readFileToAliasStoreSync();
|
|
140
|
-
const aliases = this.getAll(entity);
|
|
141
|
-
aliases.forEach((a) => this.aliasStore.delete(a));
|
|
142
|
-
this.saveAliasStoreToFileSync();
|
|
143
|
-
}
|
|
144
110
|
/**
|
|
145
111
|
* Unset all the aliases for the given array of entity.
|
|
146
112
|
*
|
|
@@ -153,12 +119,6 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
153
119
|
.map((a) => this.aliasStore.delete(a));
|
|
154
120
|
return this.saveAliasStoreToFile();
|
|
155
121
|
}
|
|
156
|
-
/**
|
|
157
|
-
* @deprecated the set/unset methods now write to the file when called. Use (un)setAndSave instead of calling (un)set and then calling write()
|
|
158
|
-
*/
|
|
159
|
-
async write() {
|
|
160
|
-
return Promise.resolve(this.getAll());
|
|
161
|
-
}
|
|
162
122
|
/**
|
|
163
123
|
* Returns true if the provided alias exists
|
|
164
124
|
*
|
|
@@ -198,30 +158,6 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
198
158
|
await (0, promises_1.writeFile)(this.fileLocation, aliasStoreToRawFileContents(this.aliasStore));
|
|
199
159
|
return unlockIfLocked(this.fileLocation);
|
|
200
160
|
}
|
|
201
|
-
/**
|
|
202
|
-
* @deprecated use the async version of this method instead
|
|
203
|
-
* provided for the legacy sync set/unset methods. */
|
|
204
|
-
readFileToAliasStoreSync() {
|
|
205
|
-
// the file is guaranteed to exist because this init method ensures it
|
|
206
|
-
// put a lock in place. This method is only used by legacy set/unset methods.
|
|
207
|
-
(0, proper_lockfile_1.lockSync)(this.fileLocation, lockRetryOptions_1.lockOptions);
|
|
208
|
-
this.aliasStore = fileContentsRawToAliasStore((0, node_fs_1.readFileSync)(this.fileLocation, 'utf-8'));
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* @deprecated use the async version of this method instead
|
|
212
|
-
* provided for the legacy sync set/unset methods */
|
|
213
|
-
saveAliasStoreToFileSync() {
|
|
214
|
-
(0, node_fs_1.writeFileSync)(this.fileLocation, aliasStoreToRawFileContents(this.aliasStore));
|
|
215
|
-
try {
|
|
216
|
-
(0, proper_lockfile_1.unlockSync)(this.fileLocation);
|
|
217
|
-
}
|
|
218
|
-
catch (e) {
|
|
219
|
-
// ignore the error. If it wasn't locked, that's what we wanted
|
|
220
|
-
if (errorIsNotAcquired(e))
|
|
221
|
-
return;
|
|
222
|
-
throw e;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
161
|
}
|
|
226
162
|
exports.AliasAccessor = AliasAccessor;
|
|
227
163
|
/**
|
|
@@ -46,12 +46,10 @@ function chunk(array, chunkSize) {
|
|
|
46
46
|
return final;
|
|
47
47
|
}
|
|
48
48
|
class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.contents = new Map();
|
|
54
|
-
}
|
|
49
|
+
configs = new Map();
|
|
50
|
+
/** map of Org files by username */
|
|
51
|
+
contents = new Map();
|
|
52
|
+
logger;
|
|
55
53
|
/**
|
|
56
54
|
* Read the auth file for the given username. Once the file has been read, it can be re-accessed with the `get` method.
|
|
57
55
|
*
|
|
@@ -187,10 +185,7 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
187
185
|
}
|
|
188
186
|
}
|
|
189
187
|
else {
|
|
190
|
-
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
org.username ??= username;
|
|
193
|
-
this.contents.set(username, org);
|
|
188
|
+
this.contents.set(username, { ...org, username: org.username ?? username });
|
|
194
189
|
}
|
|
195
190
|
}
|
|
196
191
|
/**
|
|
@@ -13,6 +13,10 @@ const aliasAccessor_1 = require("./accessors/aliasAccessor");
|
|
|
13
13
|
const orgAccessor_1 = require("./accessors/orgAccessor");
|
|
14
14
|
const sandboxAccessor_1 = require("./accessors/sandboxAccessor");
|
|
15
15
|
class StateAggregator extends kit_1.AsyncOptionalCreatable {
|
|
16
|
+
static instanceMap = new Map();
|
|
17
|
+
aliases;
|
|
18
|
+
orgs;
|
|
19
|
+
sandboxes;
|
|
16
20
|
/**
|
|
17
21
|
* Reuse a StateAggregator if one was already created for the current global state directory
|
|
18
22
|
* Otherwise, create one and adds it to map for future reuse.
|
|
@@ -40,5 +44,4 @@ class StateAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
exports.StateAggregator = StateAggregator;
|
|
43
|
-
StateAggregator.instanceMap = new Map();
|
|
44
47
|
//# sourceMappingURL=stateAggregator.js.map
|
|
@@ -49,7 +49,7 @@ export declare namespace MyDomainResolver {
|
|
|
49
49
|
/**
|
|
50
50
|
* Options for the MyDomain DNS resolver.
|
|
51
51
|
*/
|
|
52
|
-
|
|
52
|
+
type Options = {
|
|
53
53
|
/**
|
|
54
54
|
* The host to resolve.
|
|
55
55
|
*/
|
|
@@ -62,5 +62,5 @@ export declare namespace MyDomainResolver {
|
|
|
62
62
|
* The retry timeout.
|
|
63
63
|
*/
|
|
64
64
|
frequency?: Duration;
|
|
65
|
-
}
|
|
65
|
+
};
|
|
66
66
|
}
|