@salesforce/sf-plugins-core 1.2.0 → 1.4.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.4.0](https://github.com/salesforcecli/sf-plugins-core/compare/v1.3.0...v1.4.0) (2022-03-02)
6
+
7
+ ### Features
8
+
9
+ - common salesforce flags ([00ab4fc](https://github.com/salesforcecli/sf-plugins-core/commit/00ab4fc94d268b44dccb6a2de02fe4f720ff0fc0))
10
+ - debugging ([cc3fd1e](https://github.com/salesforcecli/sf-plugins-core/commit/cc3fd1e46134c08a4d76e79c74605e90e09abbb3))
11
+ - duration flag ([b11eaab](https://github.com/salesforcecli/sf-plugins-core/commit/b11eaabb0050961094f412d85c2bbbf4b183cd40))
12
+
13
+ ### Bug Fixes
14
+
15
+ - error keys support createError ([f094c49](https://github.com/salesforcecli/sf-plugins-core/commit/f094c49f1ec1063fb05cdc74e1aab88e7ceb7f13))
16
+ - error message doesn't take params ([5d917bf](https://github.com/salesforcecli/sf-plugins-core/commit/5d917bf100d41077d2eaabcd89c41fa049ef6f21))
17
+ - wrong error name ([1b3bbbe](https://github.com/salesforcecli/sf-plugins-core/commit/1b3bbbeae9f3e888faf438fe8d1f4bfd6bdac2c9))
18
+
19
+ ## [1.3.0](https://github.com/salesforcecli/sf-plugins-core/compare/v1.2.1...v1.3.0) (2022-02-23)
20
+
21
+ ### Features
22
+
23
+ - add requiresProject property ([5ff0cf3](https://github.com/salesforcecli/sf-plugins-core/commit/5ff0cf34fffe896e1ed312585705ff13436e58cf))
24
+
25
+ ### [1.2.1](https://github.com/salesforcecli/sf-plugins-core/compare/v1.2.0...v1.2.1) (2022-01-27)
26
+
27
+ ### Bug Fixes
28
+
29
+ - protect against non-existent bar ([2d0dc37](https://github.com/salesforcecli/sf-plugins-core/commit/2d0dc37ce7fedfee4413ae91299de11c8cd9db93))
30
+
5
31
  ## [1.2.0](https://github.com/salesforcecli/sf-plugins-core/compare/v1.1.0...v1.2.0) (2022-01-27)
6
32
 
7
33
  ### Features
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Description
4
4
 
5
- The @salesforce/sf-pluins-core provides utilities for writing [sf](https://github.com/salesforcecli/cli) plugins.
5
+ The @salesforce/sf-plugins-core provides utilities for writing [sf](https://github.com/salesforcecli/cli) plugins.
6
6
 
7
7
  ## SfCommand Abstract Class
8
8
 
@@ -43,3 +43,35 @@ A general purpose class that prompts a user for information. See [inquirer NPM M
43
43
  ## Flags
44
44
 
45
45
  Flags is a convenience reference to [@oclif/core#Flags](https://github.com/oclif/core/blob/main/src/flags.ts)
46
+
47
+ ### Specialty Flags
48
+
49
+ These flags can be imported into a command and used like any other flag. See code examples in the links
50
+
51
+ - [orgApiVersionFlag](src/flags/apiVersion.ts)
52
+ - specifies a Salesforce API version.
53
+ - reads from Config (if available)
54
+ - validates version is still active
55
+ - warns if version if deprecated
56
+ - [requiredOrgFlag](src/flags/orgFlags.ts)
57
+ - accepts a username or alias
58
+ - aware of configuration defaults
59
+ - throws if org or default doesn't exist or can't be found
60
+ - [optionalOrgFlag](src/flags/orgFlags.ts)
61
+ - accepts a username or alias
62
+ - aware of configuration defaults
63
+ - might be undefined if an org isn't found
64
+ - [requiredHubFlag](src/flags/orgFlags.ts)
65
+ - accepts a username or alias
66
+ - aware of configuration defaults
67
+ - throws if org or default doesn't exist or can't be found
68
+ - throws if an org is found but is not a dev hub
69
+ - [durationFlag](src/flags/duration.ts)
70
+ - specify a unit
71
+ - optionally specify a min, max, and defaultValue
72
+ - returns a [Duration](https://github.com/forcedotcom/kit/blob/main/src/duration.ts)
73
+ - can be undefined if you don't set the default
74
+ - [salesforceIdFlag](src/flags/salesforceId.ts)
75
+ - validates that IDs are valid salesforce ID
76
+ - optionally restrict to 15/18 char
77
+ - optionally require it to be begin with a certain prefix
@@ -20,3 +20,4 @@ export declare namespace Deauthorizer {
20
20
  failures: string[];
21
21
  };
22
22
  }
23
+ //# sourceMappingURL=deauthorizer.d.ts.map
package/lib/deployer.d.ts CHANGED
@@ -71,3 +71,4 @@ export declare namespace Deployer {
71
71
  [key: string]: T;
72
72
  };
73
73
  }
74
+ //# sourceMappingURL=deployer.d.ts.map
package/lib/exported.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  export { toHelpSection } from './util';
2
3
  export { Deployable, Deployer } from './deployer';
3
4
  export { Deauthorizer } from './deauthorizer';
@@ -5,4 +6,22 @@ export { Progress, Prompter, generateTableChoices } from './ux';
5
6
  export { SfHook } from './hooks';
6
7
  export * from './types';
7
8
  export { SfCommand, SfCommandInterface } from './sfCommand';
8
- export { Flags } from '@oclif/core';
9
+ export declare const Flags: {
10
+ boolean: typeof import("@oclif/core/lib/parser/flags").boolean;
11
+ directory: (opts?: ({
12
+ exists?: boolean | undefined;
13
+ } & Partial<import("@oclif/core/lib/interfaces").OptionFlag<string>>) | undefined) => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
14
+ file: (opts?: ({
15
+ exists?: boolean | undefined;
16
+ } & Partial<import("@oclif/core/lib/interfaces").OptionFlag<string>>) | undefined) => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
17
+ integer: import("@oclif/core/lib/interfaces").Definition<number>;
18
+ string: import("@oclif/core/lib/interfaces").Definition<string>;
19
+ url: import("@oclif/core/lib/interfaces").Definition<import("url").URL>;
20
+ duration: (durationConfig: import("./flags/duration").DurationFlagConfig) => import("@oclif/core/lib/interfaces").OptionFlag<import("@salesforce/kit").Duration | undefined>;
21
+ salesforceId: (inputs?: import("./flags/salesforceId").IdFlagConfig) => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
22
+ orgApiVersion: import("@oclif/core/lib/interfaces").Definition<string>;
23
+ requiredOrg: import("@oclif/core/lib/interfaces").Definition<import("@salesforce/core").Org>;
24
+ requiredHub: import("@oclif/core/lib/interfaces").Definition<import("@salesforce/core").Org>;
25
+ optionalOrg: import("@oclif/core/lib/interfaces").Definition<import("@salesforce/core").Org | undefined>;
26
+ };
27
+ //# sourceMappingURL=exported.d.ts.map
package/lib/exported.js CHANGED
@@ -17,6 +17,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.Flags = exports.SfCommand = exports.SfHook = exports.generateTableChoices = exports.Prompter = exports.Progress = exports.Deauthorizer = exports.Deployer = exports.Deployable = exports.toHelpSection = void 0;
20
+ const core_1 = require("@oclif/core");
20
21
  var util_1 = require("./util");
21
22
  Object.defineProperty(exports, "toHelpSection", { enumerable: true, get: function () { return util_1.toHelpSection; } });
22
23
  var deployer_1 = require("./deployer");
@@ -33,6 +34,23 @@ Object.defineProperty(exports, "SfHook", { enumerable: true, get: function () {
33
34
  __exportStar(require("./types"), exports);
34
35
  var sfCommand_1 = require("./sfCommand");
35
36
  Object.defineProperty(exports, "SfCommand", { enumerable: true, get: function () { return sfCommand_1.SfCommand; } });
36
- var core_1 = require("@oclif/core");
37
- Object.defineProperty(exports, "Flags", { enumerable: true, get: function () { return core_1.Flags; } });
37
+ // custom flags
38
+ const orgFlags_1 = require("./flags/orgFlags");
39
+ const salesforceId_1 = require("./flags/salesforceId");
40
+ const orgApiVersion_1 = require("./flags/orgApiVersion");
41
+ const duration_1 = require("./flags/duration");
42
+ exports.Flags = {
43
+ boolean: core_1.Flags.boolean,
44
+ directory: core_1.Flags.directory,
45
+ file: core_1.Flags.file,
46
+ integer: core_1.Flags.integer,
47
+ string: core_1.Flags.string,
48
+ url: core_1.Flags.url,
49
+ duration: duration_1.durationFlag,
50
+ salesforceId: salesforceId_1.salesforceIdFlag,
51
+ orgApiVersion: orgApiVersion_1.orgApiVersionFlag,
52
+ requiredOrg: orgFlags_1.requiredOrgFlag,
53
+ requiredHub: orgFlags_1.requiredHubFlag,
54
+ optionalOrg: orgFlags_1.optionalOrgFlag,
55
+ };
38
56
  //# sourceMappingURL=exported.js.map
@@ -0,0 +1,29 @@
1
+ import { Interfaces } from '@oclif/core';
2
+ import { Duration } from '@salesforce/kit';
3
+ declare type DurationUnit = Lowercase<keyof typeof Duration.Unit>;
4
+ export interface DurationFlagConfig extends Partial<Interfaces.OptionFlagProps> {
5
+ unit: Required<DurationUnit>;
6
+ defaultValue?: number;
7
+ min?: number;
8
+ max?: number;
9
+ }
10
+ /**
11
+ * Duration flag with built-in default and min/max validation
12
+ * You must specify a unit
13
+ * Defaults to undefined if you don't specify a default
14
+ *
15
+ * @example
16
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
17
+ * public static flags = {
18
+ * 'wait': duration({
19
+ * min: 1,
20
+ * unit: 'minutes'
21
+ * defaultValue: 33,
22
+ * char: 'w',
23
+ * description: 'Wait time in minutes'
24
+ * }),
25
+ * }
26
+ */
27
+ export declare const durationFlag: (durationConfig: DurationFlagConfig) => Interfaces.OptionFlag<Duration | undefined>;
28
+ export {};
29
+ //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.durationFlag = void 0;
4
+ /*
5
+ * Copyright (c) 2020, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * Licensed under the BSD 3-Clause license.
8
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+ const core_1 = require("@oclif/core");
11
+ const core_2 = require("@salesforce/core");
12
+ const kit_1 = require("@salesforce/kit");
13
+ core_2.Messages.importMessagesDirectory(__dirname);
14
+ const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
15
+ /**
16
+ * Duration flag with built-in default and min/max validation
17
+ * You must specify a unit
18
+ * Defaults to undefined if you don't specify a default
19
+ *
20
+ * @example
21
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
22
+ * public static flags = {
23
+ * 'wait': duration({
24
+ * min: 1,
25
+ * unit: 'minutes'
26
+ * defaultValue: 33,
27
+ * char: 'w',
28
+ * description: 'Wait time in minutes'
29
+ * }),
30
+ * }
31
+ */
32
+ const durationFlag = (durationConfig) => {
33
+ const { defaultValue, min, max, unit, ...baseProps } = durationConfig;
34
+ return core_1.Flags.build({
35
+ ...baseProps,
36
+ parse: async (input) => validate(input, { min, max, unit }),
37
+ default: defaultValue ? async () => toDuration(defaultValue, unit) : undefined,
38
+ })();
39
+ };
40
+ exports.durationFlag = durationFlag;
41
+ const validate = (input, config) => {
42
+ const { min, max, unit } = config || {};
43
+ let parsedInput;
44
+ try {
45
+ parsedInput = parseInt(input, 10);
46
+ if (typeof parsedInput !== 'number' || isNaN(parsedInput)) {
47
+ throw messages.createError('errors.InvalidDuration');
48
+ }
49
+ }
50
+ catch (e) {
51
+ throw messages.createError('errors.InvalidDuration');
52
+ }
53
+ if (min && parsedInput < min) {
54
+ throw messages.createError('errors.DurationBounds', [min, max]);
55
+ }
56
+ if (max && parsedInput > max) {
57
+ throw messages.createError('errors.DurationBounds', [min, max]);
58
+ }
59
+ return toDuration(parsedInput, unit);
60
+ };
61
+ const toDuration = (parsedInput, unit) => {
62
+ return kit_1.Duration[unit](parsedInput);
63
+ };
64
+ //# sourceMappingURL=duration.js.map
@@ -0,0 +1,13 @@
1
+ export declare const minValidApiVersion = 21;
2
+ export declare const maxDeprecated = 30;
3
+ export declare const maxDeprecatedUrl = "https://help.salesforce.com/s/articleView?id=000354473&type=1;";
4
+ /**
5
+ * apiVersion for a salesforce org's rest api.
6
+ * Will validate format and that the api version is still supported.
7
+ * Will default to the version specified in Config, if it exists (and will provide an override warning)
8
+ *
9
+ * CAVEAT: unlike the apiversion flag on sfdxCommand, this does not set the version on the org/connection
10
+ * We leave this up to the plugins to implement
11
+ */
12
+ export declare const orgApiVersionFlag: import("@oclif/core/lib/interfaces").Definition<string>;
13
+ //# sourceMappingURL=orgApiVersion.d.ts.map
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.orgApiVersionFlag = exports.maxDeprecatedUrl = exports.maxDeprecated = exports.minValidApiVersion = void 0;
4
+ /*
5
+ * Copyright (c) 2020, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * Licensed under the BSD 3-Clause license.
8
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+ const core_1 = require("@oclif/core");
11
+ const core_2 = require("@salesforce/core");
12
+ core_2.Messages.importMessagesDirectory(__dirname);
13
+ const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
14
+ // versions below this are retired
15
+ exports.minValidApiVersion = 21;
16
+ // this and all un-retired versions below it are deprecated
17
+ exports.maxDeprecated = 30;
18
+ exports.maxDeprecatedUrl = 'https://help.salesforce.com/s/articleView?id=000354473&type=1;';
19
+ /**
20
+ * apiVersion for a salesforce org's rest api.
21
+ * Will validate format and that the api version is still supported.
22
+ * Will default to the version specified in Config, if it exists (and will provide an override warning)
23
+ *
24
+ * CAVEAT: unlike the apiversion flag on sfdxCommand, this does not set the version on the org/connection
25
+ * We leave this up to the plugins to implement
26
+ */
27
+ exports.orgApiVersionFlag = core_1.Flags.build({
28
+ parse: async (input) => validate(input),
29
+ default: async () => await getDefaultFromConfig(),
30
+ description: messages.getMessage('flags.apiVersion.description'),
31
+ });
32
+ const getDefaultFromConfig = async () => {
33
+ var _a;
34
+ // (perf) only import ConfigAggregator if necessary
35
+ const { ConfigAggregator } = await Promise.resolve().then(() => require('@salesforce/core'));
36
+ const config = await ConfigAggregator.create();
37
+ const apiVersionFromConfig = (_a = config.getInfo('apiVersion')) === null || _a === void 0 ? void 0 : _a.value;
38
+ if (apiVersionFromConfig) {
39
+ await core_2.Lifecycle.getInstance().emitWarning(messages.getMessage('flags.apiVersion.overrideWarning', [apiVersionFromConfig]));
40
+ return validate(apiVersionFromConfig);
41
+ }
42
+ };
43
+ const validate = async (input) => {
44
+ // basic format check
45
+ if (!core_2.sfdc.validateApiVersion(input)) {
46
+ throw messages.createError('errors.InvalidApiVersion', [input]);
47
+ }
48
+ const requestedVersion = parseInt(input, 10);
49
+ if (requestedVersion < exports.minValidApiVersion) {
50
+ throw messages.createError('errors.RetiredApiVersion', [exports.minValidApiVersion]);
51
+ }
52
+ if (requestedVersion <= exports.maxDeprecated) {
53
+ await core_2.Lifecycle.getInstance().emitWarning(messages.getMessage('flags.apiVersion.warning.deprecated', [exports.maxDeprecated, exports.maxDeprecatedUrl]));
54
+ }
55
+ return input;
56
+ };
57
+ //# sourceMappingURL=orgApiVersion.js.map
@@ -0,0 +1,60 @@
1
+ import { Org } from '@salesforce/core';
2
+ /**
3
+ * An optional org specified by username or alias
4
+ * Will default to the default org if one is not specified.
5
+ * Will not throw if the specified org and default do not exist
6
+ *
7
+ * @example
8
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
9
+ * public static flags = {
10
+ * // setting length or prefix
11
+ * 'target-org': Flags.optionalOrg(),
12
+ * // adding properties
13
+ * 'flag2': Flags.optionalOrg({
14
+ * required: true,
15
+ * description: 'flag2 description',
16
+ * }),
17
+ * }
18
+ */
19
+ export declare const optionalOrgFlag: import("@oclif/core/lib/interfaces").Definition<Org | undefined>;
20
+ /**
21
+ * An required org, specified by username or alias
22
+ * Will throw if the specified org default do not exist
23
+ * Will default to the default org if one is not specified.
24
+ * Will throw if no default org exists and none is specified
25
+ *
26
+ * @example
27
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
28
+ * public static flags = {
29
+ * // setting length or prefix
30
+ * 'target-org': Flags.requiredOrg(),
31
+ * // adding properties
32
+ * 'flag2': Flags.requiredOrg({
33
+ * required: true,
34
+ * description: 'flag2 description',
35
+ * char: 'o'
36
+ * }),
37
+ * }
38
+ */
39
+ export declare const requiredOrgFlag: import("@oclif/core/lib/interfaces").Definition<Org>;
40
+ /**
41
+ * An required org that is a devHub
42
+ * Will throw if the specified org does not exist
43
+ * Will default to the default dev hub if one is not specified
44
+ * Will throw if no default deb hub exists and none is specified
45
+ *
46
+ * @example
47
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
48
+ * public static flags = {
49
+ * // setting length or prefix
50
+ * 'target-org': requiredHub(),
51
+ * // adding properties
52
+ * 'flag2': requiredHub({
53
+ * required: true,
54
+ * description: 'flag2 description',
55
+ * char: 'h'
56
+ * }),
57
+ * }
58
+ */
59
+ export declare const requiredHubFlag: import("@oclif/core/lib/interfaces").Definition<Org>;
60
+ //# sourceMappingURL=orgFlags.d.ts.map
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requiredHubFlag = exports.requiredOrgFlag = exports.optionalOrgFlag = void 0;
4
+ /*
5
+ * Copyright (c) 2020, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * Licensed under the BSD 3-Clause license.
8
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+ const core_1 = require("@oclif/core");
11
+ const core_2 = require("@salesforce/core");
12
+ core_2.Messages.importMessagesDirectory(__dirname);
13
+ const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
14
+ const maybeGetOrg = async (input) => core_2.Org.create({ aliasOrUsername: input });
15
+ const getOrgOrThrow = async (input) => {
16
+ const org = await maybeGetOrg(input);
17
+ if (!org) {
18
+ throw messages.createError('errors.NoDefaultEnv');
19
+ }
20
+ return org;
21
+ };
22
+ const getHubOrThrow = async (aliasOrUsername) => {
23
+ var _a, _b, _c;
24
+ if (!aliasOrUsername) {
25
+ // check config for a default
26
+ const config = await core_2.ConfigAggregator.create();
27
+ aliasOrUsername =
28
+ (_b = (_a = config.getInfo('target-dev-hub')) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : (_c = config.getInfo('defaultdevhubusername')) === null || _c === void 0 ? void 0 : _c.value;
29
+ if (!aliasOrUsername) {
30
+ throw messages.createError('errors.NoDefaultDevHub');
31
+ }
32
+ }
33
+ const org = await core_2.Org.create({ aliasOrUsername });
34
+ // check the synchronous, cached version and only use "determine" if we didn't get a positive result
35
+ if (!org.isDevHubOrg() || !(await org.determineIfDevHubOrg())) {
36
+ throw messages.createError('errors.NotADevHub', [aliasOrUsername]);
37
+ }
38
+ return org;
39
+ };
40
+ /**
41
+ * An optional org specified by username or alias
42
+ * Will default to the default org if one is not specified.
43
+ * Will not throw if the specified org and default do not exist
44
+ *
45
+ * @example
46
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
47
+ * public static flags = {
48
+ * // setting length or prefix
49
+ * 'target-org': Flags.optionalOrg(),
50
+ * // adding properties
51
+ * 'flag2': Flags.optionalOrg({
52
+ * required: true,
53
+ * description: 'flag2 description',
54
+ * }),
55
+ * }
56
+ */
57
+ exports.optionalOrgFlag = core_1.Flags.build({
58
+ char: 'e',
59
+ parse: async (input) => await maybeGetOrg(input),
60
+ default: async () => await maybeGetOrg(),
61
+ });
62
+ /**
63
+ * An required org, specified by username or alias
64
+ * Will throw if the specified org default do not exist
65
+ * Will default to the default org if one is not specified.
66
+ * Will throw if no default org exists and none is specified
67
+ *
68
+ * @example
69
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
70
+ * public static flags = {
71
+ * // setting length or prefix
72
+ * 'target-org': Flags.requiredOrg(),
73
+ * // adding properties
74
+ * 'flag2': Flags.requiredOrg({
75
+ * required: true,
76
+ * description: 'flag2 description',
77
+ * char: 'o'
78
+ * }),
79
+ * }
80
+ */
81
+ exports.requiredOrgFlag = core_1.Flags.build({
82
+ char: 'e',
83
+ parse: async (input) => await getOrgOrThrow(input),
84
+ default: async () => await getOrgOrThrow(undefined),
85
+ });
86
+ /**
87
+ * An required org that is a devHub
88
+ * Will throw if the specified org does not exist
89
+ * Will default to the default dev hub if one is not specified
90
+ * Will throw if no default deb hub exists and none is specified
91
+ *
92
+ * @example
93
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
94
+ * public static flags = {
95
+ * // setting length or prefix
96
+ * 'target-org': requiredHub(),
97
+ * // adding properties
98
+ * 'flag2': requiredHub({
99
+ * required: true,
100
+ * description: 'flag2 description',
101
+ * char: 'h'
102
+ * }),
103
+ * }
104
+ */
105
+ exports.requiredHubFlag = core_1.Flags.build({
106
+ char: 'v',
107
+ parse: async (input) => await getHubOrThrow(input),
108
+ default: async () => await getHubOrThrow(undefined),
109
+ });
110
+ //# sourceMappingURL=orgFlags.js.map
@@ -0,0 +1,32 @@
1
+ import { Interfaces } from '@oclif/core';
2
+ export interface IdFlagConfig extends Partial<Interfaces.OptionFlagProps> {
3
+ /**
4
+ * Can specify if the version must be 15 or 18 characters long. Leave blank to allow either 15 or 18.
5
+ */
6
+ length?: 15 | 18;
7
+ /**
8
+ * If the ID belongs to a certain sobject type, specify the 3 character prefix.
9
+ */
10
+ startsWith?: string;
11
+ }
12
+ /**
13
+ * Id flag with built-in validation. Short character is `i`
14
+ *
15
+ * @example
16
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
17
+ * public static flags = {
18
+ * // set length or prefix
19
+ * 'flag-name': salesforceId({ length: 15, startsWith: '00D' }),
20
+ * // add flag properties
21
+ * 'flag2': salesforceId({
22
+ * required: true,
23
+ * description: 'flag2 description',
24
+ * }),
25
+ * // override the character i
26
+ * 'flag3': salesforceId({
27
+ * char: 'j',
28
+ * }),
29
+ * }
30
+ */
31
+ export declare const salesforceIdFlag: (inputs?: IdFlagConfig) => Interfaces.OptionFlag<string | undefined>;
32
+ //# sourceMappingURL=salesforceId.d.ts.map
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.salesforceIdFlag = void 0;
4
+ /*
5
+ * Copyright (c) 2020, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * Licensed under the BSD 3-Clause license.
8
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+ const core_1 = require("@oclif/core");
11
+ const core_2 = require("@salesforce/core");
12
+ core_2.Messages.importMessagesDirectory(__dirname);
13
+ const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
14
+ /**
15
+ * Id flag with built-in validation. Short character is `i`
16
+ *
17
+ * @example
18
+ * import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
19
+ * public static flags = {
20
+ * // set length or prefix
21
+ * 'flag-name': salesforceId({ length: 15, startsWith: '00D' }),
22
+ * // add flag properties
23
+ * 'flag2': salesforceId({
24
+ * required: true,
25
+ * description: 'flag2 description',
26
+ * }),
27
+ * // override the character i
28
+ * 'flag3': salesforceId({
29
+ * char: 'j',
30
+ * }),
31
+ * }
32
+ */
33
+ const salesforceIdFlag = (inputs = {}) => {
34
+ const { length, startsWith, ...baseProps } = inputs;
35
+ return core_1.Flags.build({
36
+ char: 'i',
37
+ ...baseProps,
38
+ parse: async (input) => validate(input, { length, startsWith }),
39
+ })();
40
+ };
41
+ exports.salesforceIdFlag = salesforceIdFlag;
42
+ const validate = (input, config) => {
43
+ const { length, startsWith } = config || {};
44
+ if (length && input.length !== length) {
45
+ throw messages.createError('errors.InvalidIdLength', [length]);
46
+ }
47
+ if (!length && ![15, 18].includes(input.length)) {
48
+ throw messages.createError('errors.InvalidIdLength', ['15 or 18']);
49
+ }
50
+ if (!core_2.sfdc.validateSalesforceId(input)) {
51
+ throw messages.createError('errors.InvalidId');
52
+ }
53
+ if (startsWith && !input.startsWith(startsWith)) {
54
+ throw messages.createError('errors.InvalidPrefix', [startsWith]);
55
+ }
56
+ return input;
57
+ };
58
+ //# sourceMappingURL=salesforceId.js.map
package/lib/hooks.d.ts CHANGED
@@ -28,3 +28,4 @@ export declare namespace SfHook {
28
28
  type Logout = Hook<'sf:logout', SfHooks>;
29
29
  }
30
30
  export {};
31
+ //# sourceMappingURL=hooks.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { CliUx, Command, Config, HelpSection, Interfaces } from '@oclif/core';
2
+ import { SfdxProject } from '@salesforce/core';
2
3
  import { AnyJson } from '@salesforce/ts-types';
3
4
  import { Progress, Prompter, Spinner, Ux } from './ux';
4
5
  export interface SfCommandInterface extends Interfaces.Command {
@@ -20,11 +21,15 @@ export declare abstract class SfCommand<T> extends Command {
20
21
  static envVariablesSection?: HelpSection;
21
22
  static errorCodes?: HelpSection;
22
23
  static tableFlags: typeof CliUx.Table.table.flags;
24
+ static requiresProject: boolean;
23
25
  spinner: Spinner;
24
26
  progress: Progress;
27
+ project: SfdxProject;
25
28
  private warnings;
26
29
  private ux;
27
30
  private prompter;
31
+ private lifecycle;
32
+ protected get statics(): typeof SfCommand;
28
33
  constructor(argv: string[], config: Config);
29
34
  /**
30
35
  * Log warning to users. If --json is enabled, then the warning
@@ -66,6 +71,7 @@ export declare abstract class SfCommand<T> extends Command {
66
71
  * }
67
72
  */
68
73
  prompt<R = Prompter.Answers>(questions: Prompter.Questions<R>, initialAnswers?: Partial<R>): Promise<R>;
74
+ _run<R>(): Promise<R | undefined>;
69
75
  /**
70
76
  * Wrap the command result into the standardized JSON structure.
71
77
  */
@@ -74,6 +80,7 @@ export declare abstract class SfCommand<T> extends Command {
74
80
  * Wrap the command error into the standardized JSON structure.
75
81
  */
76
82
  protected toErrorJson(error: Error): SfCommand.Error;
83
+ protected assignProject(): Promise<SfdxProject>;
77
84
  abstract run(): Promise<T>;
78
85
  }
79
86
  export declare namespace SfCommand {
@@ -91,3 +98,4 @@ export declare namespace SfCommand {
91
98
  warnings?: Warning[];
92
99
  }
93
100
  }
101
+ //# sourceMappingURL=sfCommand.d.ts.map
package/lib/sfCommand.js CHANGED
@@ -29,6 +29,10 @@ class SfCommand extends core_1.Command {
29
29
  this.progress = new ux_1.Progress(outputEnabled);
30
30
  this.ux = new ux_1.Ux(outputEnabled);
31
31
  this.prompter = new ux_1.Prompter();
32
+ this.lifecycle = core_2.Lifecycle.getInstance();
33
+ }
34
+ get statics() {
35
+ return this.constructor;
32
36
  }
33
37
  /**
34
38
  * Log warning to users. If --json is enabled, then the warning
@@ -87,6 +91,15 @@ class SfCommand extends core_1.Command {
87
91
  async prompt(questions, initialAnswers) {
88
92
  return this.prompter.prompt(questions, initialAnswers);
89
93
  }
94
+ async _run() {
95
+ if (this.statics.requiresProject) {
96
+ this.project = await this.assignProject();
97
+ }
98
+ this.lifecycle.onWarning(async (warning) => {
99
+ this.warn(warning);
100
+ });
101
+ return super._run();
102
+ }
90
103
  /**
91
104
  * Wrap the command result into the standardized JSON structure.
92
105
  */
@@ -111,6 +124,17 @@ class SfCommand extends core_1.Command {
111
124
  warnings: this.warnings,
112
125
  };
113
126
  }
127
+ async assignProject() {
128
+ try {
129
+ return await core_2.SfdxProject.resolve();
130
+ }
131
+ catch (err) {
132
+ if (err instanceof Error && err.name === 'InvalidProjectWorkspaceError') {
133
+ throw messages.createError('errors.RequiresProject');
134
+ }
135
+ throw err;
136
+ }
137
+ }
114
138
  }
115
139
  exports.SfCommand = SfCommand;
116
140
  SfCommand.enableJsonFlag = true;
@@ -111,3 +111,4 @@ export declare namespace Logout {
111
111
  return: T;
112
112
  };
113
113
  }
114
+ //# sourceMappingURL=index.d.ts.map
package/lib/util.d.ts CHANGED
@@ -10,3 +10,4 @@ import { OrgConfigProperties, SfdxPropertyKeys, EnvironmentVariable } from '@sal
10
10
  * @param vars
11
11
  */
12
12
  export declare function toHelpSection(header: string, ...vars: Array<OrgConfigProperties | SfdxPropertyKeys | EnvironmentVariable>): HelpSection;
13
+ //# sourceMappingURL=util.d.ts.map
package/lib/ux/base.d.ts CHANGED
@@ -4,3 +4,4 @@ export declare class UxBase {
4
4
  constructor(outputEnabled: boolean);
5
5
  protected maybeNoop(fn: AnyFunction<unknown>): void;
6
6
  }
7
+ //# sourceMappingURL=base.d.ts.map
package/lib/ux/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { Ux } from './ux';
3
3
  export { Progress } from './progress';
4
4
  export { Prompter, generateTableChoices } from './prompter';
5
5
  export { Spinner } from './spinner';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -46,3 +46,4 @@ export declare namespace Progress {
46
46
  };
47
47
  type Payload = Record<string, unknown>;
48
48
  }
49
+ //# sourceMappingURL=progress.d.ts.map
@@ -23,7 +23,8 @@ class Progress extends _1.UxBase {
23
23
  */
24
24
  setTotal(total) {
25
25
  this.total = total;
26
- this.bar.setTotal(total);
26
+ if (this.bar)
27
+ this.bar.setTotal(total);
27
28
  }
28
29
  /**
29
30
  * Start the progress bar.
@@ -38,7 +39,6 @@ class Progress extends _1.UxBase {
38
39
  linewrap: opts.linewrap,
39
40
  });
40
41
  this.bar.setTotal(total);
41
- // this.maybeNoop(() => startProgressBar(this.bar, total, payload));
42
42
  this.maybeNoop(() => {
43
43
  this._start(total, payload);
44
44
  });
@@ -47,20 +47,24 @@ class Progress extends _1.UxBase {
47
47
  * Update the progress bar.
48
48
  */
49
49
  update(num, payload = {}) {
50
- this.bar.update(num, payload);
50
+ if (this.bar)
51
+ this.bar.update(num, payload);
51
52
  }
52
53
  /**
53
54
  * Update the progress bar with the final number and stop it.
54
55
  */
55
56
  finish(payload = {}) {
56
- this.bar.update(this.total, payload);
57
- this.bar.stop();
57
+ if (this.bar) {
58
+ this.bar.update(this.total, payload);
59
+ this.bar.stop();
60
+ }
58
61
  }
59
62
  /**
60
63
  * Stop the progress bar.
61
64
  */
62
65
  stop() {
63
- this.bar.stop();
66
+ if (this.bar)
67
+ this.bar.stop();
64
68
  }
65
69
  _start(total, payload = {}) {
66
70
  const start = kit_1.once((bar, t, p = {}) => {
@@ -20,3 +20,4 @@ export declare namespace Prompter {
20
20
  * generateTableChoices(columns, options);
21
21
  */
22
22
  export declare function generateTableChoices<T>(columns: Dictionary<string>, choices: Array<Dictionary<Nullable<string> | T>>, padForCheckbox?: boolean): ChoiceBase[];
23
+ //# sourceMappingURL=prompter.d.ts.map
@@ -28,3 +28,4 @@ export declare class Spinner extends UxBase {
28
28
  */
29
29
  pause(fn: () => unknown, icon?: string): void;
30
30
  }
31
+ //# sourceMappingURL=spinner.d.ts.map
package/lib/ux/ux.d.ts CHANGED
@@ -15,3 +15,4 @@ export declare namespace Ux {
15
15
  type Options = CliUx.Table.table.Options;
16
16
  }
17
17
  }
18
+ //# sourceMappingURL=ux.d.ts.map
@@ -1,3 +1,59 @@
1
1
  # warning.security
2
2
 
3
- This command will expose sensitive information that allows for subsequent activity using your current authenticated session. Sharing this information is equivalent to logging someone in under the current credential, resulting in unintended access and escalation of privilege. For additional information, please review the authorization section of the https://developer.salesforce.com/docs/atlas.en-us.234.0.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_web_flow.htm
3
+ This command will expose sensitive information that allows for subsequent activity using your current authenticated session. Sharing this information is equivalent to logging someone in under the current credential, resulting in unintended access and escalation of privilege. For additional information, please review the authorization section of the <https://developer.salesforce.com/docs/atlas.en-us.234.0.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_web_flow.htm>
4
+
5
+ # errors.RequiresProject
6
+
7
+ This command is required to run from within a Salesforce project directory.
8
+
9
+ # errors.InvalidIdLength
10
+
11
+ The id must be %s characters.
12
+
13
+ # errors.InvalidId
14
+
15
+ The id is invalid.
16
+
17
+ # errors.InvalidPrefix
18
+
19
+ The id must begin with %s.
20
+
21
+ # errors.NoDefaultEnv
22
+
23
+ No default environment found. Use -e or --target-org to specify an environment.
24
+
25
+ # errors.NoDefaultDevHub
26
+
27
+ No default dev hub found. Use -v or --target-dev-hub to specify an environment.
28
+
29
+ # errors.NotADevHub
30
+
31
+ The specified org %s is not a Dev Hub.
32
+
33
+ # flags.apiVersion.description
34
+
35
+ Override the api version used for api requests made by this command
36
+
37
+ # flags.apiVersion.overrideWarning
38
+
39
+ apiVersion configuration overridden at %s
40
+
41
+ # flags.apiVersion.warning.deprecated
42
+
43
+ API versions up to %s are deprecated. See %s for more information.
44
+
45
+ # errors.InvalidApiVersion
46
+
47
+ %s is not a valid API version.
48
+
49
+ # errors.RetiredApiVersion
50
+
51
+ The API version must be greater than %s.
52
+
53
+ # errors.InvalidDuration
54
+
55
+ The value must be an integer.
56
+
57
+ # errors.DurationBounds
58
+
59
+ The value must be between %s and %s (inclusive).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sf-plugins-core",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Utils for writing deploy and retrieve plugins",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -32,8 +32,8 @@
32
32
  "/messages"
33
33
  ],
34
34
  "dependencies": {
35
- "@oclif/core": "^1.2.0",
36
- "@salesforce/core": "3.7.3",
35
+ "@oclif/core": "^1.5.0",
36
+ "@salesforce/core": "^3.7.6",
37
37
  "@salesforce/kit": "^1.5.17",
38
38
  "@salesforce/ts-types": "^1.5.20",
39
39
  "inquirer": "^8.2.0"