@salesforce/core 3.7.6 → 3.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +4 -4
- package/lib/config/config.d.ts +7 -5
- package/lib/config/config.js +14 -9
- package/lib/config/configAggregator.d.ts +2 -2
- package/lib/config/configAggregator.js +2 -2
- package/lib/config/configFile.d.ts +2 -2
- package/lib/config/configFile.js +22 -20
- package/lib/config/configStore.js +5 -5
- package/lib/config/keychainConfig.js +4 -3
- package/lib/crypto/keyChainImpl.js +12 -10
- package/lib/deviceOauthService.js +2 -2
- package/lib/exported.d.ts +3 -4
- package/lib/exported.js +9 -7
- package/lib/global.js +2 -2
- package/lib/globalInfo/accessors/aliasAccessor.js +2 -2
- package/lib/globalInfo/sfdxDataHandler.d.ts +1 -1
- package/lib/globalInfo/sfdxDataHandler.js +5 -4
- package/lib/logger.d.ts +3 -3
- package/lib/logger.js +21 -19
- package/lib/messages.d.ts +42 -3
- package/lib/messages.js +55 -12
- package/lib/org/authInfo.d.ts +1 -1
- package/lib/org/authInfo.js +6 -6
- package/lib/org/authRemover.d.ts +2 -2
- package/lib/org/authRemover.js +2 -2
- package/lib/org/connection.d.ts +1 -1
- package/lib/org/connection.js +4 -4
- package/lib/org/org.d.ts +4 -4
- package/lib/org/org.js +16 -16
- package/lib/org/permissionSetAssignment.js +2 -2
- package/lib/org/scratchOrgCreate.js +4 -4
- package/lib/org/scratchOrgErrorCodes.js +6 -6
- package/lib/org/scratchOrgInfoApi.js +16 -16
- package/lib/org/scratchOrgInfoGenerator.d.ts +3 -3
- package/lib/org/scratchOrgInfoGenerator.js +17 -17
- package/lib/org/scratchOrgSettingsGenerator.js +2 -2
- package/lib/org/user.js +4 -4
- package/lib/schema/printer.js +2 -2
- package/lib/schema/validator.d.ts +4 -4
- package/lib/schema/validator.js +13 -13
- package/lib/{sfdxError.d.ts → sfError.d.ts} +14 -14
- package/lib/{sfdxError.js → sfError.js} +20 -21
- package/lib/{sfdxProject.d.ts → sfProject.d.ts} +37 -27
- package/lib/{sfdxProject.js → sfProject.js} +77 -65
- package/lib/status/pollingClient.js +3 -3
- package/lib/status/streamingClient.d.ts +2 -2
- package/lib/status/streamingClient.js +6 -6
- package/lib/testSetup.d.ts +4 -4
- package/lib/testSetup.js +8 -8
- package/lib/util/internal.d.ts +28 -2
- package/lib/util/internal.js +64 -6
- package/lib/util/sfdcUrl.d.ts +2 -2
- package/lib/util/sfdcUrl.js +2 -2
- package/lib/webOAuthServer.js +10 -10
- package/package.json +5 -5
- package/lib/util/fs.d.ts +0 -201
- package/lib/util/fs.js +0 -378
package/lib/global.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.Global = exports.Mode = void 0;
|
|
|
10
10
|
const os = require("os");
|
|
11
11
|
const path = require("path");
|
|
12
12
|
const kit_1 = require("@salesforce/kit");
|
|
13
|
-
const
|
|
13
|
+
const mkdirp = require("mkdirp");
|
|
14
14
|
/**
|
|
15
15
|
* Represents an environment mode. Supports `production`, `development`, `demo`, and `test`
|
|
16
16
|
* with the default mode being `production`.
|
|
@@ -46,7 +46,7 @@ class Global {
|
|
|
46
46
|
*/
|
|
47
47
|
static async createDir(dirPath) {
|
|
48
48
|
dirPath = dirPath ? path.join(Global.SFDX_DIR, dirPath) : Global.SFDX_DIR;
|
|
49
|
-
await
|
|
49
|
+
await mkdirp(dirPath, '700');
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
exports.Global = Global;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AliasAccessor = void 0;
|
|
10
|
-
const
|
|
10
|
+
const sfError_1 = require("../../sfError");
|
|
11
11
|
const types_1 = require("../types");
|
|
12
12
|
class AliasAccessor {
|
|
13
13
|
constructor(globalInfo) {
|
|
@@ -121,7 +121,7 @@ class AliasAccessor {
|
|
|
121
121
|
return entity;
|
|
122
122
|
const aliaseeName = (_a = entity.username) !== null && _a !== void 0 ? _a : entity.user;
|
|
123
123
|
if (!aliaseeName) {
|
|
124
|
-
throw new
|
|
124
|
+
throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
|
|
125
125
|
}
|
|
126
126
|
return aliaseeName;
|
|
127
127
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConfigFile } from '../config/configFile';
|
|
2
|
-
import {
|
|
2
|
+
import { SfInfo, SfInfoKeys, SfOrg, SfOrgs } from './types';
|
|
3
3
|
interface Handler<T extends SfInfoKeys> {
|
|
4
4
|
sfKey: T;
|
|
5
5
|
merge: (sfData: SfInfo) => Promise<Partial<SfInfo>>;
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AliasesHandler = exports.AuthHandler = exports.SfdxDataHandler = void 0;
|
|
10
10
|
const path_1 = require("path");
|
|
11
|
+
const fs = require("fs");
|
|
11
12
|
const kit_1 = require("@salesforce/kit");
|
|
12
13
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
13
14
|
const global_1 = require("../global");
|
|
14
|
-
const fs_1 = require("../util/fs");
|
|
15
15
|
const configFile_1 = require("../config/configFile");
|
|
16
16
|
const globalInfoConfig_1 = require("./globalInfoConfig");
|
|
17
17
|
const types_1 = require("./types");
|
|
@@ -141,7 +141,7 @@ class AuthHandler extends BaseHandler {
|
|
|
141
141
|
return config;
|
|
142
142
|
}
|
|
143
143
|
async listAllAuthFiles() {
|
|
144
|
-
const globalFiles = await
|
|
144
|
+
const globalFiles = await fs.promises.readdir(global_1.Global.SFDX_DIR);
|
|
145
145
|
return globalFiles.filter((file) => file.match(AuthHandler.authFilenameFilterRegEx));
|
|
146
146
|
}
|
|
147
147
|
async listAllAuthorizations() {
|
|
@@ -169,7 +169,8 @@ class AliasesHandler extends BaseHandler {
|
|
|
169
169
|
async migrate() {
|
|
170
170
|
const aliasesFilePath = (0, path_1.join)(global_1.Global.SFDX_DIR, AliasesHandler.SFDX_ALIASES_FILENAME);
|
|
171
171
|
try {
|
|
172
|
-
const
|
|
172
|
+
const x = await fs.promises.readFile(aliasesFilePath, 'utf8');
|
|
173
|
+
const sfdxAliases = (0, kit_1.parseJson)(x).orgs;
|
|
173
174
|
return { [this.sfKey]: { ...sfdxAliases } };
|
|
174
175
|
}
|
|
175
176
|
catch (e) {
|
|
@@ -209,7 +210,7 @@ class AliasesHandler extends BaseHandler {
|
|
|
209
210
|
}
|
|
210
211
|
async write(latest) {
|
|
211
212
|
const aliasesFilePath = (0, path_1.join)(global_1.Global.SFDX_DIR, AliasesHandler.SFDX_ALIASES_FILENAME);
|
|
212
|
-
|
|
213
|
+
await fs.promises.writeFile(aliasesFilePath, JSON.stringify({ orgs: latest[types_1.SfInfoKeys.ALIASES] }, null, 2));
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
216
|
exports.AliasesHandler = AliasesHandler;
|
package/lib/logger.d.ts
CHANGED
|
@@ -174,7 +174,7 @@ export declare class Logger {
|
|
|
174
174
|
*
|
|
175
175
|
* @param optionsOrName A set of `LoggerOptions` or name to use with the default options.
|
|
176
176
|
*
|
|
177
|
-
* **Throws** *{@link
|
|
177
|
+
* **Throws** *{@link SfError}{ name: 'RedundantRootLoggerError' }* More than one attempt is made to construct the root
|
|
178
178
|
* `Logger`.
|
|
179
179
|
*/
|
|
180
180
|
constructor(optionsOrName: LoggerOptions | string);
|
|
@@ -211,7 +211,7 @@ export declare class Logger {
|
|
|
211
211
|
*
|
|
212
212
|
* @param {string} levelName The level name to convert to a `LoggerLevel` enum value.
|
|
213
213
|
*
|
|
214
|
-
* **Throws** *{@link
|
|
214
|
+
* **Throws** *{@link SfError}{ name: 'UnrecognizedLoggerLevelNameError' }* The level name was not case-insensitively recognized as a valid `LoggerLevel` value.
|
|
215
215
|
* @see {@Link LoggerLevel}
|
|
216
216
|
*/
|
|
217
217
|
static getLevelByName(levelName: string): LoggerLevelValue;
|
|
@@ -249,7 +249,7 @@ export declare class Logger {
|
|
|
249
249
|
*
|
|
250
250
|
* @param {LoggerLevelValue} [level] The logger level.
|
|
251
251
|
*
|
|
252
|
-
* **Throws** *{@link
|
|
252
|
+
* **Throws** *{@link SfError}{ name: 'UnrecognizedLoggerLevelNameError' }* A value of `level` read from `SFDX_LOG_LEVEL`
|
|
253
253
|
* was invalid.
|
|
254
254
|
*
|
|
255
255
|
* ```
|
package/lib/logger.js
CHANGED
|
@@ -11,14 +11,16 @@ const events_1 = require("events");
|
|
|
11
11
|
const os = require("os");
|
|
12
12
|
const path = require("path");
|
|
13
13
|
const stream_1 = require("stream");
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
16
|
// @ts-ignore
|
|
15
17
|
const Bunyan = require("@salesforce/bunyan");
|
|
16
18
|
const kit_1 = require("@salesforce/kit");
|
|
17
19
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
18
20
|
const Debug = require("debug");
|
|
21
|
+
const mkdirp = require("mkdirp");
|
|
19
22
|
const global_1 = require("./global");
|
|
20
|
-
const
|
|
21
|
-
const fs_1 = require("./util/fs");
|
|
23
|
+
const sfError_1 = require("./sfError");
|
|
22
24
|
/**
|
|
23
25
|
* Standard `Logger` levels.
|
|
24
26
|
*
|
|
@@ -68,7 +70,7 @@ class Logger {
|
|
|
68
70
|
*
|
|
69
71
|
* @param optionsOrName A set of `LoggerOptions` or name to use with the default options.
|
|
70
72
|
*
|
|
71
|
-
* **Throws** *{@link
|
|
73
|
+
* **Throws** *{@link SfError}{ name: 'RedundantRootLoggerError' }* More than one attempt is made to construct the root
|
|
72
74
|
* `Logger`.
|
|
73
75
|
*/
|
|
74
76
|
constructor(optionsOrName) {
|
|
@@ -102,7 +104,7 @@ class Logger {
|
|
|
102
104
|
options = optionsOrName;
|
|
103
105
|
}
|
|
104
106
|
if (Logger.rootLogger && options.name === Logger.ROOT_NAME) {
|
|
105
|
-
throw new
|
|
107
|
+
throw new sfError_1.SfError('Can not create another root logger.', 'RedundantRootLoggerError');
|
|
106
108
|
}
|
|
107
109
|
// Inspect format to know what logging format to use then delete from options to
|
|
108
110
|
// ensure it doesn't conflict with Bunyan.
|
|
@@ -198,13 +200,13 @@ class Logger {
|
|
|
198
200
|
*
|
|
199
201
|
* @param {string} levelName The level name to convert to a `LoggerLevel` enum value.
|
|
200
202
|
*
|
|
201
|
-
* **Throws** *{@link
|
|
203
|
+
* **Throws** *{@link SfError}{ name: 'UnrecognizedLoggerLevelNameError' }* The level name was not case-insensitively recognized as a valid `LoggerLevel` value.
|
|
202
204
|
* @see {@Link LoggerLevel}
|
|
203
205
|
*/
|
|
204
206
|
static getLevelByName(levelName) {
|
|
205
207
|
levelName = levelName.toUpperCase();
|
|
206
208
|
if (!(0, ts_types_1.isKeyOf)(LoggerLevel, levelName)) {
|
|
207
|
-
throw new
|
|
209
|
+
throw new sfError_1.SfError(`Invalid log level "${levelName}".`, 'UnrecognizedLoggerLevelNameError');
|
|
208
210
|
}
|
|
209
211
|
return LoggerLevel[levelName];
|
|
210
212
|
}
|
|
@@ -228,22 +230,22 @@ class Logger {
|
|
|
228
230
|
async addLogFileStream(logFile) {
|
|
229
231
|
try {
|
|
230
232
|
// Check if we have write access to the log file (i.e., we created it already)
|
|
231
|
-
await
|
|
233
|
+
await fs.promises.access(logFile, fs.constants.W_OK);
|
|
232
234
|
}
|
|
233
235
|
catch (err1) {
|
|
234
236
|
try {
|
|
235
|
-
await
|
|
236
|
-
mode:
|
|
237
|
+
await mkdirp(path.dirname(logFile), {
|
|
238
|
+
mode: '700',
|
|
237
239
|
});
|
|
238
240
|
}
|
|
239
241
|
catch (err2) {
|
|
240
242
|
// noop; directory exists already
|
|
241
243
|
}
|
|
242
244
|
try {
|
|
243
|
-
await
|
|
245
|
+
await fs.promises.writeFile(logFile, '', { mode: '600' });
|
|
244
246
|
}
|
|
245
247
|
catch (err3) {
|
|
246
|
-
throw
|
|
248
|
+
throw sfError_1.SfError.wrap(err3);
|
|
247
249
|
}
|
|
248
250
|
}
|
|
249
251
|
// avoid multiple streams to same log file
|
|
@@ -268,22 +270,22 @@ class Logger {
|
|
|
268
270
|
addLogFileStreamSync(logFile) {
|
|
269
271
|
try {
|
|
270
272
|
// Check if we have write access to the log file (i.e., we created it already)
|
|
271
|
-
|
|
273
|
+
fs.accessSync(logFile, fs.constants.W_OK);
|
|
272
274
|
}
|
|
273
275
|
catch (err1) {
|
|
274
276
|
try {
|
|
275
|
-
|
|
276
|
-
mode:
|
|
277
|
+
mkdirp.sync(path.dirname(logFile), {
|
|
278
|
+
mode: '700',
|
|
277
279
|
});
|
|
278
280
|
}
|
|
279
281
|
catch (err2) {
|
|
280
282
|
// noop; directory exists already
|
|
281
283
|
}
|
|
282
284
|
try {
|
|
283
|
-
|
|
285
|
+
fs.writeFileSync(logFile, '', { mode: '600' });
|
|
284
286
|
}
|
|
285
287
|
catch (err3) {
|
|
286
|
-
throw
|
|
288
|
+
throw sfError_1.SfError.wrap(err3);
|
|
287
289
|
}
|
|
288
290
|
}
|
|
289
291
|
// avoid multiple streams to same log file
|
|
@@ -319,7 +321,7 @@ class Logger {
|
|
|
319
321
|
*
|
|
320
322
|
* @param {LoggerLevelValue} [level] The logger level.
|
|
321
323
|
*
|
|
322
|
-
* **Throws** *{@link
|
|
324
|
+
* **Throws** *{@link SfError}{ name: 'UnrecognizedLoggerLevelNameError' }* A value of `level` read from `SFDX_LOG_LEVEL`
|
|
323
325
|
* was invalid.
|
|
324
326
|
*
|
|
325
327
|
* ```
|
|
@@ -400,7 +402,7 @@ class Logger {
|
|
|
400
402
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
401
403
|
this.bunyan.streams.forEach(async (stream) => {
|
|
402
404
|
if (stream.type === 'file') {
|
|
403
|
-
content += await
|
|
405
|
+
content += await fs.promises.readFile(stream.path, 'utf8');
|
|
404
406
|
}
|
|
405
407
|
});
|
|
406
408
|
return content;
|
|
@@ -452,7 +454,7 @@ class Logger {
|
|
|
452
454
|
*/
|
|
453
455
|
child(name, fields = {}) {
|
|
454
456
|
if (!name) {
|
|
455
|
-
throw new
|
|
457
|
+
throw new sfError_1.SfError('LoggerNameRequired');
|
|
456
458
|
}
|
|
457
459
|
fields.log = name;
|
|
458
460
|
const child = new Logger(name);
|
package/lib/messages.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { AnyJson } from '@salesforce/ts-types';
|
|
2
|
-
import {
|
|
2
|
+
import { SfError } from './sfError';
|
|
3
3
|
export declare type Tokens = Array<string | boolean | number | null | undefined>;
|
|
4
|
+
export declare type StructuredMessage = {
|
|
5
|
+
message: string;
|
|
6
|
+
name: string;
|
|
7
|
+
actions?: string[];
|
|
8
|
+
};
|
|
4
9
|
/**
|
|
5
10
|
* A loader function to return messages.
|
|
6
11
|
*
|
|
@@ -244,9 +249,43 @@ export declare class Messages<T extends string> {
|
|
|
244
249
|
* @param key The key of the error message.
|
|
245
250
|
* @param tokens The error message tokens.
|
|
246
251
|
* @param actionTokens The action messages tokens.
|
|
247
|
-
* @param exitCodeOrCause The exit code which will be used by SfdxCommand or
|
|
252
|
+
* @param exitCodeOrCause The exit code which will be used by SfdxCommand or the underlying error that caused this error to be raised.
|
|
248
253
|
* @param cause The underlying error that caused this error to be raised.
|
|
249
254
|
*/
|
|
250
|
-
createError(key: T, tokens?: Tokens, actionTokens?: Tokens, exitCodeOrCause?: number | Error, cause?: Error):
|
|
255
|
+
createError(key: T, tokens?: Tokens, actionTokens?: Tokens, exitCodeOrCause?: number | Error, cause?: Error): SfError;
|
|
256
|
+
/**
|
|
257
|
+
* Convenience method to create warning using message labels.
|
|
258
|
+
*
|
|
259
|
+
* `warning.name` will be the upper-cased key, remove prefixed `warning.` and will always end in Warning.
|
|
260
|
+
* `warning.actions` will be loaded using `${key}.actions` if available.
|
|
261
|
+
*
|
|
262
|
+
* @param key The key of the warning message.
|
|
263
|
+
* @param tokens The warning message tokens.
|
|
264
|
+
* @param actionTokens The action messages tokens.
|
|
265
|
+
*/
|
|
266
|
+
createWarning(key: T, tokens?: Tokens, actionTokens?: Tokens): StructuredMessage;
|
|
267
|
+
/**
|
|
268
|
+
* Convenience method to create info using message labels.
|
|
269
|
+
*
|
|
270
|
+
* `info.name` will be the upper-cased key, remove prefixed `info.` and will always end in Info.
|
|
271
|
+
* `info.actions` will be loaded using `${key}.actions` if available.
|
|
272
|
+
*
|
|
273
|
+
* @param key The key of the warning message.
|
|
274
|
+
* @param tokens The warning message tokens.
|
|
275
|
+
* @param actionTokens The action messages tokens.
|
|
276
|
+
*/
|
|
277
|
+
createInfo(key: T, tokens?: Tokens, actionTokens?: Tokens): StructuredMessage;
|
|
278
|
+
/**
|
|
279
|
+
* Formats message contents given a message type, key, tokens and actions tokens
|
|
280
|
+
*
|
|
281
|
+
* `<type>.name` will be the upper-cased key, remove prefixed `<type>.` and will always end in 'Error | Warning | Info.
|
|
282
|
+
* `<type>.actions` will be loaded using `${key}.actions` if available.
|
|
283
|
+
*
|
|
284
|
+
* @param type The type of the message set must 'error' | 'warning' | 'info'.
|
|
285
|
+
* @param key The key of the warning message.
|
|
286
|
+
* @param tokens The warning message tokens.
|
|
287
|
+
* @param actionTokens The action messages tokens.
|
|
288
|
+
*/
|
|
289
|
+
private formatMessageContents;
|
|
251
290
|
private getMessageWithMap;
|
|
252
291
|
}
|
package/lib/messages.js
CHANGED
|
@@ -13,7 +13,7 @@ const path = require("path");
|
|
|
13
13
|
const util = require("util");
|
|
14
14
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
15
15
|
const kit_1 = require("@salesforce/kit");
|
|
16
|
-
const
|
|
16
|
+
const sfError_1 = require("./sfError");
|
|
17
17
|
class Key {
|
|
18
18
|
constructor(packageName, bundleName) {
|
|
19
19
|
this.packageName = packageName;
|
|
@@ -57,7 +57,7 @@ const markdownLoader = (filePath, fileContents) => {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
// use error instead of
|
|
60
|
+
// use error instead of SfError because messages.js should have no internal dependencies.
|
|
61
61
|
throw new Error(`Invalid markdown message file: ${filePath}\nThe line "# <key>" must be immediately followed by the message on a new line.`);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -217,7 +217,7 @@ class Messages {
|
|
|
217
217
|
if (!fileContents || fileContents.trim().length === 0) {
|
|
218
218
|
// messages.js should have no internal dependencies.
|
|
219
219
|
const error = new Error(`Invalid message file: ${filePath}. No content.`);
|
|
220
|
-
error.name = '
|
|
220
|
+
error.name = 'SfError';
|
|
221
221
|
throw error;
|
|
222
222
|
}
|
|
223
223
|
const map = parser(filePath, fileContents);
|
|
@@ -438,25 +438,68 @@ class Messages {
|
|
|
438
438
|
* @param key The key of the error message.
|
|
439
439
|
* @param tokens The error message tokens.
|
|
440
440
|
* @param actionTokens The action messages tokens.
|
|
441
|
-
* @param exitCodeOrCause The exit code which will be used by SfdxCommand or
|
|
441
|
+
* @param exitCodeOrCause The exit code which will be used by SfdxCommand or the underlying error that caused this error to be raised.
|
|
442
442
|
* @param cause The underlying error that caused this error to be raised.
|
|
443
443
|
*/
|
|
444
444
|
createError(key, tokens = [], actionTokens = [], exitCodeOrCause, cause) {
|
|
445
|
+
const structuredMessage = this.formatMessageContents('error', key, tokens, actionTokens);
|
|
446
|
+
return new sfError_1.SfError(structuredMessage.message, structuredMessage.name, structuredMessage.actions, exitCodeOrCause, cause);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Convenience method to create warning using message labels.
|
|
450
|
+
*
|
|
451
|
+
* `warning.name` will be the upper-cased key, remove prefixed `warning.` and will always end in Warning.
|
|
452
|
+
* `warning.actions` will be loaded using `${key}.actions` if available.
|
|
453
|
+
*
|
|
454
|
+
* @param key The key of the warning message.
|
|
455
|
+
* @param tokens The warning message tokens.
|
|
456
|
+
* @param actionTokens The action messages tokens.
|
|
457
|
+
*/
|
|
458
|
+
createWarning(key, tokens = [], actionTokens = []) {
|
|
459
|
+
return this.formatMessageContents('warning', key, tokens, actionTokens);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Convenience method to create info using message labels.
|
|
463
|
+
*
|
|
464
|
+
* `info.name` will be the upper-cased key, remove prefixed `info.` and will always end in Info.
|
|
465
|
+
* `info.actions` will be loaded using `${key}.actions` if available.
|
|
466
|
+
*
|
|
467
|
+
* @param key The key of the warning message.
|
|
468
|
+
* @param tokens The warning message tokens.
|
|
469
|
+
* @param actionTokens The action messages tokens.
|
|
470
|
+
*/
|
|
471
|
+
createInfo(key, tokens = [], actionTokens = []) {
|
|
472
|
+
return this.formatMessageContents('info', key, tokens, actionTokens);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Formats message contents given a message type, key, tokens and actions tokens
|
|
476
|
+
*
|
|
477
|
+
* `<type>.name` will be the upper-cased key, remove prefixed `<type>.` and will always end in 'Error | Warning | Info.
|
|
478
|
+
* `<type>.actions` will be loaded using `${key}.actions` if available.
|
|
479
|
+
*
|
|
480
|
+
* @param type The type of the message set must 'error' | 'warning' | 'info'.
|
|
481
|
+
* @param key The key of the warning message.
|
|
482
|
+
* @param tokens The warning message tokens.
|
|
483
|
+
* @param actionTokens The action messages tokens.
|
|
484
|
+
*/
|
|
485
|
+
formatMessageContents(type, key, tokens = [], actionTokens = []) {
|
|
486
|
+
const label = (0, kit_1.upperFirst)(type);
|
|
487
|
+
const labelRegExp = new RegExp(`${label}$`);
|
|
488
|
+
const searchValue = type === 'error' ? /^error.*\./ : new RegExp(`^${type}.`);
|
|
445
489
|
// Convert key to name:
|
|
446
|
-
// 'myMessage' -> `
|
|
490
|
+
// 'myMessage' -> `MyMessageWarning`
|
|
447
491
|
// 'myMessageError' -> `MyMessageError`
|
|
448
|
-
// '
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
let errActions;
|
|
492
|
+
// 'warning.myMessage' -> `MyMessageWarning`
|
|
493
|
+
const name = `${(0, kit_1.upperFirst)(key.replace(searchValue, ''))}${labelRegExp.exec(key) ? '' : label}`;
|
|
494
|
+
const message = this.getMessage(key, tokens);
|
|
495
|
+
let actions;
|
|
453
496
|
try {
|
|
454
|
-
|
|
497
|
+
actions = this.getMessageWithMap(`${key}.actions`, actionTokens, this.messages);
|
|
455
498
|
}
|
|
456
499
|
catch (e) {
|
|
457
500
|
/* just ignore if actions aren't found */
|
|
458
501
|
}
|
|
459
|
-
return
|
|
502
|
+
return { message, name, actions };
|
|
460
503
|
}
|
|
461
504
|
getMessageWithMap(key, tokens = [], map) {
|
|
462
505
|
// Allow nested keys for better grouping
|
package/lib/org/authInfo.d.ts
CHANGED
|
@@ -253,7 +253,7 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
|
|
|
253
253
|
*
|
|
254
254
|
* @param options Options to be used for creating an OAuth2 instance.
|
|
255
255
|
*
|
|
256
|
-
* **Throws** *{@link
|
|
256
|
+
* **Throws** *{@link SfError}{ name: 'NamedOrgNotFoundError' }* Org information does not exist.
|
|
257
257
|
* @returns {Promise<AuthInfo>}
|
|
258
258
|
*/
|
|
259
259
|
private initAuthOptions;
|
package/lib/org/authInfo.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.AuthInfo = exports.DEFAULT_CONNECTED_APP_INFO = void 0;
|
|
|
10
10
|
const crypto_1 = require("crypto");
|
|
11
11
|
const path_1 = require("path");
|
|
12
12
|
const os = require("os");
|
|
13
|
+
const fs = require("fs");
|
|
13
14
|
const kit_1 = require("@salesforce/kit");
|
|
14
15
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
15
16
|
const jsforce_1 = require("jsforce");
|
|
@@ -18,8 +19,7 @@ const jwt = require("jsonwebtoken");
|
|
|
18
19
|
const config_1 = require("../config/config");
|
|
19
20
|
const configAggregator_1 = require("../config/configAggregator");
|
|
20
21
|
const logger_1 = require("../logger");
|
|
21
|
-
const
|
|
22
|
-
const fs_1 = require("../util/fs");
|
|
22
|
+
const sfError_1 = require("../sfError");
|
|
23
23
|
const sfdc_1 = require("../util/sfdc");
|
|
24
24
|
const globalInfo_1 = require("../globalInfo");
|
|
25
25
|
const messages_1 = require("../messages");
|
|
@@ -236,7 +236,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
236
236
|
static parseSfdxAuthUrl(sfdxAuthUrl) {
|
|
237
237
|
const match = sfdxAuthUrl.match(/^force:\/\/([a-zA-Z0-9._-]+):([a-zA-Z0-9._-]*):([a-zA-Z0-9._-]+={0,2})@([a-zA-Z0-9._-]+)/);
|
|
238
238
|
if (!match) {
|
|
239
|
-
throw new
|
|
239
|
+
throw new sfError_1.SfError('Invalid SFDX auth URL. Must be in the format "force://<clientId>:<clientSecret>:<refreshToken>@<instanceUrl>". Note that the SFDX auth URL uses the "force" protocol, and not "http" or "https". Also note that the "instanceUrl" inside the SFDX auth URL doesn\'t include the protocol ("https://").', 'INVALID_SFDX_AUTH_URL');
|
|
240
240
|
}
|
|
241
241
|
const [, clientId, clientSecret, refreshToken, loginUrl] = match;
|
|
242
242
|
return {
|
|
@@ -489,7 +489,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
489
489
|
*
|
|
490
490
|
* @param options Options to be used for creating an OAuth2 instance.
|
|
491
491
|
*
|
|
492
|
-
* **Throws** *{@link
|
|
492
|
+
* **Throws** *{@link SfError}{ name: 'NamedOrgNotFoundError' }* Org information does not exist.
|
|
493
493
|
* @returns {Promise<AuthInfo>}
|
|
494
494
|
*/
|
|
495
495
|
async initAuthOptions(options) {
|
|
@@ -584,7 +584,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
584
584
|
}
|
|
585
585
|
// Build OAuth config for a JWT auth flow
|
|
586
586
|
async buildJwtConfig(options) {
|
|
587
|
-
const privateKeyContents = await
|
|
587
|
+
const privateKeyContents = await fs.promises.readFile((0, ts_types_1.ensure)(options.privateKey), 'utf8');
|
|
588
588
|
const { loginUrl = sfdcUrl_1.SfdcUrl.PRODUCTION } = options;
|
|
589
589
|
const url = new sfdcUrl_1.SfdcUrl(loginUrl);
|
|
590
590
|
const createdOrgInstance = (0, ts_types_1.getString)(options, 'createdOrgInstance', '').trim().toLowerCase();
|
|
@@ -768,7 +768,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
768
768
|
catch (err) {
|
|
769
769
|
errorMsg = `${bodyAsString}`;
|
|
770
770
|
}
|
|
771
|
-
throw new
|
|
771
|
+
throw new sfError_1.SfError(errorMsg);
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
774
|
exports.AuthInfo = AuthInfo;
|
package/lib/org/authRemover.d.ts
CHANGED
|
@@ -39,8 +39,8 @@ export declare class AuthRemover extends AsyncOptionalCreatable {
|
|
|
39
39
|
removeAllAuths(): Promise<void>;
|
|
40
40
|
/**
|
|
41
41
|
* Finds authorization files for username/alias in the global .sfdx folder
|
|
42
|
-
* **Throws** *{@link
|
|
43
|
-
* **Throws** *{@link
|
|
42
|
+
* **Throws** *{@link SfError}{ name: 'TargetOrgNotSetError' }* if no target-org
|
|
43
|
+
* **Throws** *{@link SfError}{ name: 'NamedOrgNotFoundError' }* if specified user is not found
|
|
44
44
|
*
|
|
45
45
|
* @param usernameOrAlias username or alias of the auth you want to find, defaults to the configured target-org
|
|
46
46
|
* @returns {Promise<SfOrg>}
|
package/lib/org/authRemover.js
CHANGED
|
@@ -66,8 +66,8 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
|
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Finds authorization files for username/alias in the global .sfdx folder
|
|
69
|
-
* **Throws** *{@link
|
|
70
|
-
* **Throws** *{@link
|
|
69
|
+
* **Throws** *{@link SfError}{ name: 'TargetOrgNotSetError' }* if no target-org
|
|
70
|
+
* **Throws** *{@link SfError}{ name: 'NamedOrgNotFoundError' }* if specified user is not found
|
|
71
71
|
*
|
|
72
72
|
* @param usernameOrAlias username or alias of the auth you want to find, defaults to the configured target-org
|
|
73
73
|
* @returns {Promise<SfOrg>}
|
package/lib/org/connection.d.ts
CHANGED
|
@@ -123,7 +123,7 @@ export declare class Connection<S extends Schema = Schema> extends JSForceConnec
|
|
|
123
123
|
/**
|
|
124
124
|
* Set the API version for all connection requests.
|
|
125
125
|
*
|
|
126
|
-
* **Throws** *{@link
|
|
126
|
+
* **Throws** *{@link SfError}{ name: 'IncorrectAPIVersionError' }* Incorrect API version.
|
|
127
127
|
*
|
|
128
128
|
* @param version The API version.
|
|
129
129
|
*/
|
package/lib/org/connection.js
CHANGED
|
@@ -17,7 +17,7 @@ const tooling_1 = require("jsforce/lib/api/tooling");
|
|
|
17
17
|
const myDomainResolver_1 = require("../status/myDomainResolver");
|
|
18
18
|
const configAggregator_1 = require("../config/configAggregator");
|
|
19
19
|
const logger_1 = require("../logger");
|
|
20
|
-
const
|
|
20
|
+
const sfError_1 = require("../sfError");
|
|
21
21
|
const sfdc_1 = require("../util/sfdc");
|
|
22
22
|
const messages_1 = require("../messages");
|
|
23
23
|
const lifecycleEvents_1 = require("../lifecycleEvents");
|
|
@@ -274,7 +274,7 @@ class Connection extends jsforce_1.Connection {
|
|
|
274
274
|
/**
|
|
275
275
|
* Set the API version for all connection requests.
|
|
276
276
|
*
|
|
277
|
-
* **Throws** *{@link
|
|
277
|
+
* **Throws** *{@link SfError}{ name: 'IncorrectAPIVersionError' }* Incorrect API version.
|
|
278
278
|
*
|
|
279
279
|
* @param version The API version.
|
|
280
280
|
*/
|
|
@@ -357,10 +357,10 @@ class Connection extends jsforce_1.Connection {
|
|
|
357
357
|
}) {
|
|
358
358
|
const result = options.tooling ? await this.tooling.query(soql) : await this.query(soql);
|
|
359
359
|
if (result.totalSize === 0) {
|
|
360
|
-
throw new
|
|
360
|
+
throw new sfError_1.SfError(`No record found for ${soql}`, exports.SingleRecordQueryErrors.NoRecords);
|
|
361
361
|
}
|
|
362
362
|
if (result.totalSize > 1) {
|
|
363
|
-
throw new
|
|
363
|
+
throw new sfError_1.SfError(options.returnChoicesOnMultiple
|
|
364
364
|
? `Multiple records found. ${result.records.map((item) => item[options.choiceField]).join(',')}`
|
|
365
365
|
: 'The query returned more than 1 record', exports.SingleRecordQueryErrors.MultipleRecords);
|
|
366
366
|
}
|
package/lib/org/org.d.ts
CHANGED
|
@@ -148,9 +148,9 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
|
|
|
148
148
|
/**
|
|
149
149
|
* Check that this org is a scratch org by asking the dev hub if it knows about it.
|
|
150
150
|
*
|
|
151
|
-
* **Throws** *{@link
|
|
151
|
+
* **Throws** *{@link SfError}{ name: 'NotADevHubError' }* Not a Dev Hub.
|
|
152
152
|
*
|
|
153
|
-
* **Throws** *{@link
|
|
153
|
+
* **Throws** *{@link SfError}{ name: 'NoResultsError' }* No results.
|
|
154
154
|
*
|
|
155
155
|
* @param devHubUsernameOrAlias The username or alias of the dev hub org.
|
|
156
156
|
*/
|
|
@@ -253,7 +253,7 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
|
|
|
253
253
|
/**
|
|
254
254
|
* Removes a username from the user config for this object. For convenience `this` object is returned.
|
|
255
255
|
*
|
|
256
|
-
* **Throws** *{@link
|
|
256
|
+
* **Throws** *{@link SfError}{ name: 'MissingAuthInfoError' }* Auth info is missing.
|
|
257
257
|
*
|
|
258
258
|
* @param {AuthInfo | string} auth The AuthInfo containing the username to remove.
|
|
259
259
|
*/
|
|
@@ -305,7 +305,7 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
|
|
|
305
305
|
*/
|
|
306
306
|
protected init(): Promise<void>;
|
|
307
307
|
/**
|
|
308
|
-
* **Throws** *{@link
|
|
308
|
+
* **Throws** *{@link SfError}{ name: 'NotSupportedError' }* Throws an unsupported error.
|
|
309
309
|
*/
|
|
310
310
|
protected getDefaultOptions(): Org.Options;
|
|
311
311
|
private queryProduction;
|