@salesforce/sf-plugins-core 1.14.1 → 1.15.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/README.md CHANGED
@@ -13,7 +13,7 @@ The SfCommand abstract class extends [@oclif/core's Command class](https://githu
13
13
  - Enable the json flag support by default
14
14
  - Provides functions that help place success messages, warnings and errors into the correct location in JSON results
15
15
  - Enables additional help sections to the standard oclif command help output
16
- - Provides access to the [cli-ux cli actions](https://github.com/oclif/cli-ux#cliaction) via the public property `spinner` in SfCommand. This avoids having to import that interface from cli-ux.
16
+ - Provides access to the [cli-ux cli actions](https://github.com/oclif/cli-ux#cliaction). This avoids having to import that interface from cli-ux and manually handling the `--json` flag.
17
17
 
18
18
  ## Sf Hooks
19
19
 
@@ -1,7 +1,6 @@
1
1
  import { JsonMap } from '@salesforce/ts-types';
2
2
  /**
3
- * The Deauthorizer is an abstract class that is used to implement a concrete implementations
4
- * of deauthorizing an environment.
3
+ * The Deauthorizer is an abstract class that is used to implement a concrete implementation of deauthorizing an environment.
5
4
  */
6
5
  export declare abstract class Deauthorizer<T = JsonMap> {
7
6
  removeAll(): Promise<Deauthorizer.Result>;
@@ -8,8 +8,7 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Deauthorizer = void 0;
10
10
  /**
11
- * The Deauthorizer is an abstract class that is used to implement a concrete implementations
12
- * of deauthorizing an environment.
11
+ * The Deauthorizer is an abstract class that is used to implement a concrete implementation of deauthorizing an environment.
13
12
  */
14
13
  class Deauthorizer {
15
14
  async removeAll() {
@@ -20,6 +19,8 @@ class Deauthorizer {
20
19
  const environments = await this.find();
21
20
  for (const id of Object.keys(environments)) {
22
21
  try {
22
+ // avoid configFile collision bug
23
+ // eslint-disable-next-line no-await-in-loop
23
24
  await this.remove(id);
24
25
  result.successes.push(id);
25
26
  }
package/lib/deployer.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
3
  import { AnyJson, JsonMap } from '@salesforce/ts-types';
4
- import { QuestionCollection } from 'inquirer';
4
+ import { QuestionCollection, Answers } from 'inquirer';
5
5
  export declare type DeployerResult = {
6
6
  exitCode: number;
7
7
  };
@@ -33,7 +33,7 @@ export declare abstract class Deployer extends EventEmitter {
33
33
  /**
34
34
  * Prompt user for additional information
35
35
  */
36
- prompt<T>(questions: QuestionCollection<T>, initialAnswers?: Partial<T>): Promise<T>;
36
+ prompt<T extends Answers>(questions: QuestionCollection<T>, initialAnswers?: Partial<T>): Promise<T>;
37
37
  /**
38
38
  * Overwrite the deployables property on the class.
39
39
  */
@@ -62,6 +62,9 @@ export declare namespace Deployer {
62
62
  };
63
63
  /**
64
64
  * This interface represents the aggregation of all deployer options, e.g.
65
+ *
66
+ * @example
67
+ * ```
65
68
  * {
66
69
  * 'Salesforce Apps': {
67
70
  * testLevel: 'RunLocalTests',
@@ -69,6 +72,7 @@ export declare namespace Deployer {
69
72
  * },
70
73
  * 'Salesforce Functions': { username: 'user@salesforce.com' },
71
74
  * }
75
+ * ```
72
76
  */
73
77
  type Options<T = AnyJson> = JsonMap & {
74
78
  [key: string]: T;
package/lib/deployer.js CHANGED
@@ -5,6 +5,7 @@
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
+ /* eslint-disable @typescript-eslint/explicit-member-accessibility */
8
9
  Object.defineProperty(exports, "__esModule", { value: true });
9
10
  exports.Deployer = exports.Deployable = void 0;
10
11
  const events_1 = require("events");
@@ -30,11 +31,12 @@ class Deployer extends events_1.EventEmitter {
30
31
  /**
31
32
  * Method for displaying deploy progress to the user
32
33
  */
33
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
34
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function, class-methods-use-this
34
35
  progress(current, total, message) { }
35
36
  /**
36
37
  * Log messages to the console
37
38
  */
39
+ // eslint-disable-next-line class-methods-use-this
38
40
  log(msg, ...args) {
39
41
  core_1.CliUx.ux.log(msg, ...args);
40
42
  }
package/lib/exported.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Flags as OclifFlags } from '@oclif/core';
3
- export { toHelpSection } from './util';
3
+ export { toHelpSection, parseVarArgs } from './util';
4
4
  export { Deployable, Deployer, DeployerResult } from './deployer';
5
5
  export { Deauthorizer } from './deauthorizer';
6
6
  export { Progress, Prompter, generateTableChoices } from './ux';
package/lib/exported.js CHANGED
@@ -20,10 +20,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
20
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.Flags = exports.StandardColors = exports.SfCommand = exports.SfHook = exports.generateTableChoices = exports.Prompter = exports.Progress = exports.Deauthorizer = exports.Deployer = exports.Deployable = exports.toHelpSection = void 0;
23
+ exports.Flags = exports.StandardColors = exports.SfCommand = exports.SfHook = exports.generateTableChoices = exports.Prompter = exports.Progress = exports.Deauthorizer = exports.Deployer = exports.Deployable = exports.parseVarArgs = exports.toHelpSection = void 0;
24
24
  const core_1 = require("@oclif/core");
25
25
  var util_1 = require("./util");
26
26
  Object.defineProperty(exports, "toHelpSection", { enumerable: true, get: function () { return util_1.toHelpSection; } });
27
+ Object.defineProperty(exports, "parseVarArgs", { enumerable: true, get: function () { return util_1.parseVarArgs; } });
27
28
  var deployer_1 = require("./deployer");
28
29
  Object.defineProperty(exports, "Deployable", { enumerable: true, get: function () { return deployer_1.Deployable; } });
29
30
  Object.defineProperty(exports, "Deployer", { enumerable: true, get: function () { return deployer_1.Deployer; } });
@@ -12,9 +12,11 @@ export declare type DurationFlagConfig = {
12
12
  * Defaults to undefined if you don't specify a default
13
13
  *
14
14
  * @example
15
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
15
+ *
16
+ * ```
17
+ * import { Flags } from '@salesforce/sf-plugins-core';
16
18
  * public static flags = {
17
- * 'wait': duration({
19
+ * wait: Flags.duration({
18
20
  * min: 1,
19
21
  * unit: 'minutes'
20
22
  * defaultValue: 33,
@@ -22,6 +24,7 @@ export declare type DurationFlagConfig = {
22
24
  * description: 'Wait time in minutes'
23
25
  * }),
24
26
  * }
27
+ * ```
25
28
  */
26
29
  export declare const durationFlag: import("@oclif/core/lib/interfaces").Definition<Duration, DurationFlagConfig>;
27
30
  export {};
@@ -18,9 +18,11 @@ const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'me
18
18
  * Defaults to undefined if you don't specify a default
19
19
  *
20
20
  * @example
21
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
21
+ *
22
+ * ```
23
+ * import { Flags } from '@salesforce/sf-plugins-core';
22
24
  * public static flags = {
23
- * 'wait': duration({
25
+ * wait: Flags.duration({
24
26
  * min: 1,
25
27
  * unit: 'minutes'
26
28
  * defaultValue: 33,
@@ -28,12 +30,11 @@ const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'me
28
30
  * description: 'Wait time in minutes'
29
31
  * }),
30
32
  * }
33
+ * ```
31
34
  */
32
35
  exports.durationFlag = core_1.Flags.custom({
33
36
  parse: async (input, _, opts) => validate(input, opts),
34
- default: async (context) => {
35
- return context.options.defaultValue ? toDuration(context.options.defaultValue, context.options.unit) : undefined;
36
- },
37
+ default: async (context) => context.options.defaultValue ? toDuration(context.options.defaultValue, context.options.unit) : undefined,
37
38
  });
38
39
  const validate = (input, config) => {
39
40
  const { min, max, unit } = config || {};
@@ -55,7 +56,5 @@ const validate = (input, config) => {
55
56
  }
56
57
  return toDuration(parsedInput, unit);
57
58
  };
58
- const toDuration = (parsedInput, unit) => {
59
- return kit_1.Duration[unit](parsedInput);
60
- };
59
+ const toDuration = (parsedInput, unit) => kit_1.Duration[unit](parsedInput);
61
60
  //# sourceMappingURL=duration.js.map
@@ -8,6 +8,18 @@ export declare const maxDeprecatedUrl = "https://help.salesforce.com/s/articleVi
8
8
  *
9
9
  * CAVEAT: unlike the apiversion flag on sfdxCommand, this does not set the version on the org/connection
10
10
  * We leave this up to the plugins to implement
11
+ *
12
+ * @example
13
+ *
14
+ * ```
15
+ * import { Flags } from '@salesforce/sf-plugins-core';
16
+ * public static flags = {
17
+ * 'api-version': Flags.orgApiVersion({
18
+ * char: 'a',
19
+ * description: 'api version for the org'
20
+ * }),
21
+ * }
22
+ * ```
11
23
  */
12
24
  export declare const orgApiVersionFlag: import("@oclif/core/lib/interfaces").Definition<string, Record<string, unknown>>;
13
25
  //# sourceMappingURL=orgApiVersion.d.ts.map
@@ -23,18 +23,29 @@ exports.maxDeprecatedUrl = 'https://help.salesforce.com/s/articleView?id=0003544
23
23
  *
24
24
  * CAVEAT: unlike the apiversion flag on sfdxCommand, this does not set the version on the org/connection
25
25
  * We leave this up to the plugins to implement
26
+ *
27
+ * @example
28
+ *
29
+ * ```
30
+ * import { Flags } from '@salesforce/sf-plugins-core';
31
+ * public static flags = {
32
+ * 'api-version': Flags.orgApiVersion({
33
+ * char: 'a',
34
+ * description: 'api version for the org'
35
+ * }),
36
+ * }
37
+ * ```
26
38
  */
27
39
  exports.orgApiVersionFlag = core_1.Flags.custom({
28
40
  parse: async (input) => validate(input),
29
- default: async () => await getDefaultFromConfig(),
41
+ default: async () => getDefaultFromConfig(),
30
42
  description: messages.getMessage('flags.apiVersion.description'),
31
43
  });
32
44
  const getDefaultFromConfig = async () => {
33
- var _a;
34
45
  // (perf) only import ConfigAggregator if necessary
35
46
  const { ConfigAggregator } = await Promise.resolve().then(() => require('@salesforce/core'));
36
47
  const config = await ConfigAggregator.create();
37
- const apiVersionFromConfig = (_a = config.getInfo(core_2.OrgConfigProperties.ORG_API_VERSION)) === null || _a === void 0 ? void 0 : _a.value;
48
+ const apiVersionFromConfig = config.getInfo(core_2.OrgConfigProperties.ORG_API_VERSION)?.value;
38
49
  if (apiVersionFromConfig) {
39
50
  await core_2.Lifecycle.getInstance().emitWarning(messages.getMessage('flags.apiVersion.overrideWarning', [apiVersionFromConfig]));
40
51
  return validate(apiVersionFromConfig);
@@ -5,7 +5,9 @@ import { Org } from '@salesforce/core';
5
5
  * Will not throw if the specified org and default do not exist
6
6
  *
7
7
  * @example
8
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
8
+ *
9
+ * ```
10
+ * import { Flags } from '@salesforce/sf-plugins-core';
9
11
  * public static flags = {
10
12
  * // setting length or prefix
11
13
  * 'target-org': Flags.optionalOrg(),
@@ -15,6 +17,7 @@ import { Org } from '@salesforce/core';
15
17
  * description: 'flag2 description',
16
18
  * }),
17
19
  * }
20
+ * ```
18
21
  */
19
22
  export declare const optionalOrgFlag: import("@oclif/core/lib/interfaces").Definition<Org | undefined, Record<string, unknown>>;
20
23
  /**
@@ -24,7 +27,9 @@ export declare const optionalOrgFlag: import("@oclif/core/lib/interfaces").Defin
24
27
  * Will throw if no default org exists and none is specified
25
28
  *
26
29
  * @example
27
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
30
+ *
31
+ * ```
32
+ * import { Flags } from '@salesforce/sf-plugins-core';
28
33
  * public static flags = {
29
34
  * // setting length or prefix
30
35
  * 'target-org': Flags.requiredOrg(),
@@ -35,6 +40,7 @@ export declare const optionalOrgFlag: import("@oclif/core/lib/interfaces").Defin
35
40
  * char: 'o'
36
41
  * }),
37
42
  * }
43
+ * ```
38
44
  */
39
45
  export declare const requiredOrgFlag: import("@oclif/core/lib/interfaces").Definition<Org, Record<string, unknown>>;
40
46
  /**
@@ -44,7 +50,9 @@ export declare const requiredOrgFlag: import("@oclif/core/lib/interfaces").Defin
44
50
  * Will throw if no default deb hub exists and none is specified
45
51
  *
46
52
  * @example
47
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
53
+ *
54
+ * ```
55
+ * import { Flags } from '@salesforce/sf-plugins-core';
48
56
  * public static flags = {
49
57
  * // setting length or prefix
50
58
  * 'target-org': requiredHub(),
@@ -55,6 +63,7 @@ export declare const requiredOrgFlag: import("@oclif/core/lib/interfaces").Defin
55
63
  * char: 'h'
56
64
  * }),
57
65
  * }
66
+ * ```
58
67
  */
59
68
  export declare const requiredHubFlag: import("@oclif/core/lib/interfaces").Definition<Org, Record<string, unknown>>;
60
69
  //# sourceMappingURL=orgFlags.d.ts.map
@@ -32,11 +32,10 @@ const getOrgOrThrow = async (input) => {
32
32
  return org;
33
33
  };
34
34
  const getHubOrThrow = async (aliasOrUsername) => {
35
- var _a;
36
35
  if (!aliasOrUsername) {
37
36
  // check config for a default
38
37
  const config = await core_2.ConfigAggregator.create();
39
- aliasOrUsername = (_a = config.getInfo(core_2.OrgConfigProperties.TARGET_DEV_HUB)) === null || _a === void 0 ? void 0 : _a.value;
38
+ aliasOrUsername = config.getInfo(core_2.OrgConfigProperties.TARGET_DEV_HUB)?.value;
40
39
  if (!aliasOrUsername) {
41
40
  throw messages.createError('errors.NoDefaultDevHub');
42
41
  }
@@ -53,7 +52,9 @@ const getHubOrThrow = async (aliasOrUsername) => {
53
52
  * Will not throw if the specified org and default do not exist
54
53
  *
55
54
  * @example
56
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
55
+ *
56
+ * ```
57
+ * import { Flags } from '@salesforce/sf-plugins-core';
57
58
  * public static flags = {
58
59
  * // setting length or prefix
59
60
  * 'target-org': Flags.optionalOrg(),
@@ -63,12 +64,13 @@ const getHubOrThrow = async (aliasOrUsername) => {
63
64
  * description: 'flag2 description',
64
65
  * }),
65
66
  * }
67
+ * ```
66
68
  */
67
69
  exports.optionalOrgFlag = core_1.Flags.custom({
68
70
  char: 'e',
69
- parse: async (input) => await maybeGetOrg(input),
70
- default: async () => await maybeGetOrg(),
71
- defaultHelp: async () => { var _a; return (_a = (await maybeGetOrg())) === null || _a === void 0 ? void 0 : _a.getUsername(); },
71
+ parse: async (input) => maybeGetOrg(input),
72
+ default: async () => maybeGetOrg(),
73
+ defaultHelp: async () => (await maybeGetOrg())?.getUsername(),
72
74
  });
73
75
  /**
74
76
  * A required org, specified by username or alias
@@ -77,7 +79,9 @@ exports.optionalOrgFlag = core_1.Flags.custom({
77
79
  * Will throw if no default org exists and none is specified
78
80
  *
79
81
  * @example
80
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
82
+ *
83
+ * ```
84
+ * import { Flags } from '@salesforce/sf-plugins-core';
81
85
  * public static flags = {
82
86
  * // setting length or prefix
83
87
  * 'target-org': Flags.requiredOrg(),
@@ -88,12 +92,13 @@ exports.optionalOrgFlag = core_1.Flags.custom({
88
92
  * char: 'o'
89
93
  * }),
90
94
  * }
95
+ * ```
91
96
  */
92
97
  exports.requiredOrgFlag = core_1.Flags.custom({
93
98
  char: 'e',
94
- parse: async (input) => await getOrgOrThrow(input),
95
- default: async () => await getOrgOrThrow(),
96
- defaultHelp: async () => { var _a; return (_a = (await getOrgOrThrow())) === null || _a === void 0 ? void 0 : _a.getUsername(); },
99
+ parse: async (input) => getOrgOrThrow(input),
100
+ default: async () => getOrgOrThrow(),
101
+ defaultHelp: async () => (await getOrgOrThrow())?.getUsername(),
97
102
  });
98
103
  /**
99
104
  * A required org that is a devHub
@@ -102,7 +107,9 @@ exports.requiredOrgFlag = core_1.Flags.custom({
102
107
  * Will throw if no default deb hub exists and none is specified
103
108
  *
104
109
  * @example
105
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
110
+ *
111
+ * ```
112
+ * import { Flags } from '@salesforce/sf-plugins-core';
106
113
  * public static flags = {
107
114
  * // setting length or prefix
108
115
  * 'target-org': requiredHub(),
@@ -113,11 +120,12 @@ exports.requiredOrgFlag = core_1.Flags.custom({
113
120
  * char: 'h'
114
121
  * }),
115
122
  * }
123
+ * ```
116
124
  */
117
125
  exports.requiredHubFlag = core_1.Flags.custom({
118
126
  char: 'v',
119
- parse: async (input) => await getHubOrThrow(input),
120
- default: async () => await getHubOrThrow(),
121
- defaultHelp: async () => { var _a; return (_a = (await getHubOrThrow())) === null || _a === void 0 ? void 0 : _a.getUsername(); },
127
+ parse: async (input) => getHubOrThrow(input),
128
+ default: async () => getHubOrThrow(),
129
+ defaultHelp: async () => (await getHubOrThrow())?.getUsername(),
122
130
  });
123
131
  //# sourceMappingURL=orgFlags.js.map
@@ -12,7 +12,9 @@ export declare type IdFlagConfig = {
12
12
  * Id flag with built-in validation. Short character is `i`
13
13
  *
14
14
  * @example
15
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
15
+ *
16
+ * ```
17
+ * import { Flags } from '@salesforce/sf-plugins-core';
16
18
  * public static flags = {
17
19
  * // set length or prefix
18
20
  * 'flag-name': salesforceId({ length: 15, startsWith: '00D' }),
@@ -26,6 +28,7 @@ export declare type IdFlagConfig = {
26
28
  * char: 'j',
27
29
  * }),
28
30
  * }
31
+ * ```
29
32
  */
30
33
  export declare const salesforceIdFlag: import("@oclif/core/lib/interfaces").Definition<string, IdFlagConfig>;
31
34
  //# sourceMappingURL=salesforceId.d.ts.map
@@ -15,7 +15,9 @@ const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'me
15
15
  * Id flag with built-in validation. Short character is `i`
16
16
  *
17
17
  * @example
18
- * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
18
+ *
19
+ * ```
20
+ * import { Flags } from '@salesforce/sf-plugins-core';
19
21
  * public static flags = {
20
22
  * // set length or prefix
21
23
  * 'flag-name': salesforceId({ length: 15, startsWith: '00D' }),
@@ -29,13 +31,14 @@ const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'me
29
31
  * char: 'j',
30
32
  * }),
31
33
  * }
34
+ * ```
32
35
  */
33
36
  exports.salesforceIdFlag = core_1.Flags.custom({
34
37
  parse: async (input, _ctx, opts) => validate(input, opts),
35
38
  char: 'i',
36
39
  });
37
40
  const validate = (input, config) => {
38
- const { length, startsWith } = config || {};
41
+ const { length, startsWith } = config ?? {};
39
42
  if (length && input.length !== length) {
40
43
  throw messages.createError('errors.InvalidIdLength', [length]);
41
44
  }
package/lib/hooks.d.ts CHANGED
@@ -15,9 +15,12 @@ interface SfHooks<T = unknown> extends Hooks {
15
15
  }
16
16
  declare type GenericHook<T extends keyof SfHooks, P> = Hook<T, SfHooks<P>>;
17
17
  /**
18
- * Class that provides a static method to run a well known hook.
18
+ * Class that provides a static method to run a pre-defined sf hook. See {@link SfHooks}.
19
19
  */
20
20
  export declare class SfHook {
21
+ /**
22
+ * Executes a well known Unified CLI hook. See {@link SfHooks}.
23
+ */
21
24
  static run<T extends keyof SfHooks>(config: Config, hookName: T, options?: SfHooks[T]['options']): Promise<Hook.Result<SfHooks[T]['return']>>;
22
25
  }
23
26
  export declare namespace SfHook {
package/lib/hooks.js CHANGED
@@ -10,11 +10,14 @@ exports.SfHook = void 0;
10
10
  const kit_1 = require("@salesforce/kit");
11
11
  const core_1 = require("@oclif/core");
12
12
  /**
13
- * Class that provides a static method to run a well known hook.
13
+ * Class that provides a static method to run a pre-defined sf hook. See {@link SfHooks}.
14
14
  */
15
15
  class SfHook {
16
+ /**
17
+ * Executes a well known Unified CLI hook. See {@link SfHooks}.
18
+ */
16
19
  static async run(config, hookName, options = {}) {
17
- const timeout = kit_1.Duration.milliseconds(kit_1.env.getNumber('SF_HOOK_TIMEOUT_MS') || 5000);
20
+ const timeout = kit_1.Duration.milliseconds(kit_1.env.getNumber('SF_HOOK_TIMEOUT_MS') ?? 5000);
18
21
  const results = await config.runHook(hookName, options, timeout.milliseconds);
19
22
  results.failures.forEach((failure) => {
20
23
  core_1.CliUx.ux.debug(`Failed to run ${hookName} hook for ${failure.plugin.name}`);