@salesforce/sf-plugins-core 1.21.8 → 1.22.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.
@@ -36,6 +36,10 @@ export declare const requiredOrgFlagWithDeprecations: import("@oclif/core/lib/in
36
36
  * @deprecated
37
37
  */
38
38
  export declare const requiredHubFlagWithDeprecations: import("@oclif/core/lib/interfaces").OptionFlag<import("@salesforce/core").Org>;
39
+ /**
40
+ * @deprecated
41
+ */
42
+ export declare const optionalHubFlagWithDeprecations: import("@oclif/core/lib/interfaces").OptionFlag<import("@salesforce/core").Org | undefined>;
39
43
  export type ArrayWithDeprecationOptions = {
40
44
  multiple?: true;
41
45
  parse?: undefined;
@@ -6,7 +6,7 @@
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
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.arrayWithDeprecation = exports.requiredHubFlagWithDeprecations = exports.requiredOrgFlagWithDeprecations = exports.optionalOrgFlagWithDeprecations = exports.loglevel = exports.orgApiVersionFlagWithDeprecations = void 0;
9
+ exports.arrayWithDeprecation = exports.optionalHubFlagWithDeprecations = exports.requiredHubFlagWithDeprecations = exports.requiredOrgFlagWithDeprecations = exports.optionalOrgFlagWithDeprecations = exports.loglevel = exports.orgApiVersionFlagWithDeprecations = void 0;
10
10
  const core_1 = require("@oclif/core");
11
11
  const core_2 = require("@salesforce/core");
12
12
  const orgApiVersion_1 = require("./flags/orgApiVersion");
@@ -72,6 +72,14 @@ exports.requiredHubFlagWithDeprecations = (0, orgFlags_1.requiredHubFlag)({
72
72
  deprecateAliases: true,
73
73
  required: true,
74
74
  });
75
+ /**
76
+ * @deprecated
77
+ */
78
+ exports.optionalHubFlagWithDeprecations = (0, orgFlags_1.optionalHubFlag)({
79
+ aliases: ['targetdevhubusername'],
80
+ deprecateAliases: true,
81
+ required: false,
82
+ });
75
83
  /**
76
84
  * @deprecated
77
85
  */
package/lib/exported.d.ts CHANGED
@@ -29,5 +29,6 @@ export declare const Flags: {
29
29
  requiredOrg: import("@oclif/core/lib/interfaces").Definition<import("@salesforce/core").Org, Record<string, unknown>>;
30
30
  requiredHub: import("@oclif/core/lib/interfaces").Definition<import("@salesforce/core").Org, Record<string, unknown>>;
31
31
  optionalOrg: import("@oclif/core/lib/interfaces").Definition<import("@salesforce/core").Org | undefined, Record<string, unknown>>;
32
+ optionalHub: import("@oclif/core/lib/interfaces").Definition<import("@salesforce/core").Org | undefined, Record<string, unknown>>;
32
33
  };
33
34
  //# sourceMappingURL=exported.d.ts.map
package/lib/exported.js CHANGED
@@ -61,5 +61,6 @@ exports.Flags = {
61
61
  requiredOrg: orgFlags_1.requiredOrgFlag,
62
62
  requiredHub: orgFlags_1.requiredHubFlag,
63
63
  optionalOrg: orgFlags_1.optionalOrgFlag,
64
+ optionalHub: orgFlags_1.optionalHubFlag,
64
65
  };
65
66
  //# sourceMappingURL=exported.js.map
@@ -1,4 +1,10 @@
1
1
  import { Org } from '@salesforce/core';
2
+ export declare function maybeGetOrg(input: string): Promise<Org>;
3
+ export declare function maybeGetOrg(input: undefined): Promise<undefined>;
4
+ export declare function maybeGetOrg(input?: string | undefined): Promise<Org | undefined>;
5
+ export declare const maybeGetHub: (input?: string) => Promise<Org | undefined>;
6
+ export declare const getOrgOrThrow: (input?: string) => Promise<Org>;
7
+ export declare const getHubOrThrow: (aliasOrUsername?: string) => Promise<Org>;
2
8
  /**
3
9
  * An optional org specified by username or alias
4
10
  * Will default to the default org if one is not specified.
@@ -66,4 +72,26 @@ export declare const requiredOrgFlag: import("@oclif/core/lib/interfaces").Defin
66
72
  * ```
67
73
  */
68
74
  export declare const requiredHubFlag: import("@oclif/core/lib/interfaces").Definition<Org, Record<string, unknown>>;
75
+ /**
76
+ * An optional org that, if present, must be a devHub
77
+ * Will throw if the specified org does not exist
78
+ * Will default to the default dev hub if one is not specified
79
+ * Will NOT throw if no default deb hub exists and none is specified
80
+ *
81
+ * @example
82
+ *
83
+ * ```
84
+ * import { Flags } from '@salesforce/sf-plugins-core';
85
+ * public static flags = {
86
+ * // setting length or prefix
87
+ * 'target-org': optionalHubFlag(),
88
+ * // adding properties
89
+ * 'flag2': optionalHubFlag({
90
+ * description: 'flag2 description',
91
+ * char: 'h'
92
+ * }),
93
+ * }
94
+ * ```
95
+ */
96
+ export declare const optionalHubFlag: import("@oclif/core/lib/interfaces").Definition<Org | undefined, Record<string, unknown>>;
69
97
  //# sourceMappingURL=orgFlags.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requiredHubFlag = exports.requiredOrgFlag = exports.optionalOrgFlag = void 0;
3
+ exports.optionalHubFlag = exports.requiredHubFlag = exports.requiredOrgFlag = exports.optionalOrgFlag = exports.getHubOrThrow = exports.getOrgOrThrow = exports.maybeGetHub = exports.maybeGetOrg = void 0;
4
4
  /*
5
5
  * Copyright (c) 2020, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -11,7 +11,7 @@ const core_1 = require("@oclif/core");
11
11
  const core_2 = require("@salesforce/core");
12
12
  core_2.Messages.importMessagesDirectory(__dirname);
13
13
  const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
14
- const maybeGetOrg = async (input) => {
14
+ async function maybeGetOrg(input) {
15
15
  try {
16
16
  return await core_2.Org.create({ aliasOrUsername: input });
17
17
  }
@@ -23,7 +23,18 @@ const maybeGetOrg = async (input) => {
23
23
  throw e;
24
24
  }
25
25
  }
26
+ }
27
+ exports.maybeGetOrg = maybeGetOrg;
28
+ const maybeGetHub = async (input) => {
29
+ const org = await maybeGetOrg(input ?? (await getDefaultHub(false)));
30
+ if (org) {
31
+ return ensureDevHub(org, input ?? org.getUsername());
32
+ }
33
+ else {
34
+ return undefined;
35
+ }
26
36
  };
37
+ exports.maybeGetHub = maybeGetHub;
27
38
  const getOrgOrThrow = async (input) => {
28
39
  const org = await maybeGetOrg(input);
29
40
  if (!org) {
@@ -31,21 +42,28 @@ const getOrgOrThrow = async (input) => {
31
42
  }
32
43
  return org;
33
44
  };
34
- const getHubOrThrow = async (aliasOrUsername) => {
35
- if (!aliasOrUsername) {
36
- // check config for a default
37
- const config = await core_2.ConfigAggregator.create();
38
- aliasOrUsername = config.getInfo(core_2.OrgConfigProperties.TARGET_DEV_HUB)?.value;
39
- if (!aliasOrUsername) {
40
- throw messages.createError('errors.NoDefaultDevHub');
41
- }
42
- }
43
- const org = await core_2.Org.create({ aliasOrUsername });
45
+ exports.getOrgOrThrow = getOrgOrThrow;
46
+ const ensureDevHub = async (org, aliasOrUsername) => {
44
47
  if (await org.determineIfDevHubOrg()) {
45
48
  return org;
46
49
  }
47
- throw messages.createError('errors.NotADevHub', [aliasOrUsername]);
50
+ throw messages.createError('errors.NotADevHub', [aliasOrUsername ?? org.getUsername()]);
51
+ };
52
+ async function getDefaultHub(throwIfNotFound) {
53
+ // check config for a default
54
+ const config = await core_2.ConfigAggregator.create();
55
+ const aliasOrUsername = config.getInfo(core_2.OrgConfigProperties.TARGET_DEV_HUB)?.value;
56
+ if (throwIfNotFound && !aliasOrUsername) {
57
+ throw messages.createError('errors.NoDefaultDevHub');
58
+ }
59
+ return aliasOrUsername;
60
+ }
61
+ const getHubOrThrow = async (aliasOrUsername) => {
62
+ const resolved = aliasOrUsername ?? (await getDefaultHub(true));
63
+ const org = await core_2.Org.create({ aliasOrUsername: resolved, isDevHub: true });
64
+ return ensureDevHub(org, resolved);
48
65
  };
66
+ exports.getHubOrThrow = getHubOrThrow;
49
67
  /**
50
68
  * An optional org specified by username or alias
51
69
  * Will default to the default org if one is not specified.
@@ -97,9 +115,9 @@ exports.optionalOrgFlag = core_1.Flags.custom({
97
115
  exports.requiredOrgFlag = core_1.Flags.custom({
98
116
  char: 'o',
99
117
  summary: messages.getMessage('flags.targetOrg.summary'),
100
- parse: async (input) => getOrgOrThrow(input),
101
- default: async () => getOrgOrThrow(),
102
- defaultHelp: async () => (await getOrgOrThrow())?.getUsername(),
118
+ parse: async (input) => (0, exports.getOrgOrThrow)(input),
119
+ default: async () => (0, exports.getOrgOrThrow)(),
120
+ defaultHelp: async () => (await (0, exports.getOrgOrThrow)())?.getUsername(),
103
121
  required: true,
104
122
  });
105
123
  /**
@@ -127,9 +145,38 @@ exports.requiredOrgFlag = core_1.Flags.custom({
127
145
  exports.requiredHubFlag = core_1.Flags.custom({
128
146
  char: 'v',
129
147
  summary: messages.getMessage('flags.targetDevHubOrg.summary'),
130
- parse: async (input) => getHubOrThrow(input),
131
- default: async () => getHubOrThrow(),
132
- defaultHelp: async () => (await getHubOrThrow())?.getUsername(),
148
+ parse: async (input) => (0, exports.getHubOrThrow)(input),
149
+ default: async () => (0, exports.getHubOrThrow)(),
150
+ defaultHelp: async () => (await (0, exports.getHubOrThrow)())?.getUsername(),
133
151
  required: true,
134
152
  });
153
+ /**
154
+ * An optional org that, if present, must be a devHub
155
+ * Will throw if the specified org does not exist
156
+ * Will default to the default dev hub if one is not specified
157
+ * Will NOT throw if no default deb hub exists and none is specified
158
+ *
159
+ * @example
160
+ *
161
+ * ```
162
+ * import { Flags } from '@salesforce/sf-plugins-core';
163
+ * public static flags = {
164
+ * // setting length or prefix
165
+ * 'target-org': optionalHubFlag(),
166
+ * // adding properties
167
+ * 'flag2': optionalHubFlag({
168
+ * description: 'flag2 description',
169
+ * char: 'h'
170
+ * }),
171
+ * }
172
+ * ```
173
+ */
174
+ exports.optionalHubFlag = core_1.Flags.custom({
175
+ char: 'v',
176
+ summary: messages.getMessage('flags.targetDevHubOrg.summary'),
177
+ parse: async (input) => (0, exports.maybeGetHub)(input),
178
+ default: async () => (0, exports.maybeGetHub)(),
179
+ defaultHelp: async () => (await (0, exports.maybeGetHub)())?.getUsername(),
180
+ required: false,
181
+ });
135
182
  //# sourceMappingURL=orgFlags.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sf-plugins-core",
3
- "version": "1.21.8",
3
+ "version": "1.22.0",
4
4
  "description": "Utils for writing deploy and retrieve plugins",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",