@salesforce/core 2.26.1 → 2.28.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,36 @@
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
+ ## [2.28.0](https://github.com/forcedotcom/sfdx-core/compare/v2.27.2...v2.28.0) (2021-09-16)
6
+
7
+
8
+ ### Features
9
+
10
+ * add custom templates config ([3cf8a8c](https://github.com/forcedotcom/sfdx-core/commit/3cf8a8cee1e7196efced989dcca9b545e1283386))
11
+ * add validator for custom templates config ([dd2bcfe](https://github.com/forcedotcom/sfdx-core/commit/dd2bcfe8e7fee5c5c1c6321189ec04288103d5b6))
12
+ * update config name ([72e84bf](https://github.com/forcedotcom/sfdx-core/commit/72e84bfacef48a1c2d00a61ebbae3f632601abbd))
13
+
14
+ ### [2.27.2](https://github.com/forcedotcom/sfdx-core/compare/v2.27.1...v2.27.2) (2021-08-05)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * improve error handling while removing config props ([eecf7b0](https://github.com/forcedotcom/sfdx-core/commit/eecf7b0d0cf14e1371dc4c5ef03a413f864b0a8b))
20
+
21
+ ### [2.27.1](https://github.com/forcedotcom/sfdx-core/compare/v2.27.0...v2.27.1) (2021-08-05)
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * dont fail when trying to unset sf config keys ([#456](https://github.com/forcedotcom/sfdx-core/issues/456)) ([8aff9fd](https://github.com/forcedotcom/sfdx-core/commit/8aff9fd4bdb73ec20e58f5a16a8192a8eecba912))
27
+
28
+ ## [2.27.0](https://github.com/forcedotcom/sfdx-core/compare/v2.26.1...v2.27.0) (2021-07-29)
29
+
30
+
31
+ ### Features
32
+
33
+ * Core URL class SfdcUrl ([#420](https://github.com/forcedotcom/sfdx-core/issues/420)) ([66881ea](https://github.com/forcedotcom/sfdx-core/commit/66881eae2f30215c862ea398bfc1630d9a5898fe))
34
+
5
35
  ### [2.26.1](https://github.com/forcedotcom/sfdx-core/compare/v2.26.0...v2.26.1) (2021-07-19)
6
36
 
7
37
 
package/lib/authInfo.d.ts CHANGED
@@ -99,16 +99,6 @@ export declare class OAuth2WithVerifier extends OAuth2 {
99
99
  */
100
100
  protected _postParams(params: Record<string, unknown>, callback: AnyFunction): Promise<any>;
101
101
  }
102
- /**
103
- * Salesforce URLs.
104
- */
105
- export declare enum SfdcUrl {
106
- SANDBOX = "https://test.salesforce.com",
107
- PRODUCTION = "https://login.salesforce.com"
108
- }
109
- export declare function getJwtAudienceUrl(options: OAuth2Options & {
110
- createdOrgInstance?: string;
111
- }): Promise<string>;
112
102
  export declare const DEFAULT_CONNECTED_APP_INFO: {
113
103
  clientId: string;
114
104
  legacyClientId: string;
@@ -173,6 +163,8 @@ export declare class AuthInfo extends AsyncCreatable<AuthInfo.Options> {
173
163
  * Get a list of all auth files stored in the global directory.
174
164
  *
175
165
  * @returns {Promise<string[]>}
166
+ *
167
+ * @deprecated Removed in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#globalinfo}
176
168
  */
177
169
  static listAllAuthFiles(): Promise<string[]>;
178
170
  /**
@@ -197,6 +189,8 @@ export declare class AuthInfo extends AsyncCreatable<AuthInfo.Options> {
197
189
  * Forces the auth file to be re-read from disk for a given user. Returns `true` if a value was removed.
198
190
  *
199
191
  * @param username The username for the auth info to re-read.
192
+ *
193
+ * @deprecated Removed in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#configstore-configfile-authinfo-and-encrypting-values}
200
194
  */
201
195
  static clearCache(username: string): boolean;
202
196
  /**
@@ -324,7 +318,6 @@ export declare class AuthInfo extends AsyncCreatable<AuthInfo.Options> {
324
318
  * @private
325
319
  */
326
320
  private throwUserGetException;
327
- private lookup;
328
321
  }
329
322
  export declare namespace AuthInfo {
330
323
  /**
package/lib/authInfo.js CHANGED
@@ -6,13 +6,10 @@
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.AuthInfo = exports.DEFAULT_CONNECTED_APP_INFO = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.OAuth2WithVerifier = void 0;
9
+ exports.AuthInfo = exports.DEFAULT_CONNECTED_APP_INFO = exports.OAuth2WithVerifier = void 0;
10
10
  const crypto_1 = require("crypto");
11
- const url_1 = require("url");
12
- const dns = require("dns");
13
11
  const path_1 = require("path");
14
12
  const path_2 = require("path");
15
- const url_2 = require("url");
16
13
  const os = require("os");
17
14
  const kit_1 = require("@salesforce/kit");
18
15
  const ts_types_1 = require("@salesforce/ts-types");
@@ -32,7 +29,7 @@ const logger_1 = require("./logger");
32
29
  const sfdxError_1 = require("./sfdxError");
33
30
  const fs_1 = require("./util/fs");
34
31
  const sfdc_1 = require("./util/sfdc");
35
- const myDomainResolver_1 = require("./status/myDomainResolver");
32
+ const sfdcUrl_1 = require("./util/sfdcUrl");
36
33
  // Extend OAuth2 to add JWT Bearer Token Flow support.
37
34
  class JwtOAuth2 extends jsforce_1.OAuth2 {
38
35
  constructor(options) {
@@ -97,56 +94,6 @@ class OAuth2WithVerifier extends jsforce_1.OAuth2 {
97
94
  }
98
95
  }
99
96
  exports.OAuth2WithVerifier = OAuth2WithVerifier;
100
- /**
101
- * Salesforce URLs.
102
- */
103
- var SfdcUrl;
104
- (function (SfdcUrl) {
105
- SfdcUrl["SANDBOX"] = "https://test.salesforce.com";
106
- SfdcUrl["PRODUCTION"] = "https://login.salesforce.com";
107
- })(SfdcUrl = exports.SfdcUrl || (exports.SfdcUrl = {}));
108
- function isSandboxUrl(options) {
109
- var _a;
110
- const createdOrgInstance = ts_types_1.getString(options, 'createdOrgInstance', '').trim().toLowerCase();
111
- const loginUrl = (_a = options.loginUrl) !== null && _a !== void 0 ? _a : '';
112
- return (/^cs|s$/gi.test(createdOrgInstance) ||
113
- /sandbox\.my\.salesforce\.com/gi.test(loginUrl) || // enhanced domains >= 230
114
- /(cs[0-9]+(\.my|)\.salesforce\.com)/gi.test(loginUrl) || // my domains on CS instance OR CS instance without my domain
115
- /([a-z]{3}[0-9]+s\.sfdc-.+\.salesforce\.com)/gi.test(loginUrl) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
116
- /([a-z]{3}[0-9]+s\.sfdc-.+\.force\.com)/gi.test(loginUrl) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
117
- url_2.parse(loginUrl).hostname === 'test.salesforce.com');
118
- }
119
- async function resolvesToSandbox(options) {
120
- if (isSandboxUrl(options)) {
121
- return true;
122
- }
123
- let cnames = [];
124
- if (options.loginUrl) {
125
- const myDomainResolver = await myDomainResolver_1.MyDomainResolver.create({ url: new url_1.URL(options.loginUrl) });
126
- cnames = await myDomainResolver.getCnames();
127
- }
128
- return cnames.some((cname) => isSandboxUrl({ ...options, loginUrl: cname }));
129
- }
130
- async function getJwtAudienceUrl(options) {
131
- var _a;
132
- // environment variable is used as an override
133
- if (process.env.SFDX_AUDIENCE_URL) {
134
- return process.env.SFDX_AUDIENCE_URL;
135
- }
136
- if (options.loginUrl && sfdc_1.sfdc.isInternalUrl(options.loginUrl)) {
137
- // This is for internal developers when just doing authorize;
138
- return options.loginUrl;
139
- }
140
- if (await resolvesToSandbox(options)) {
141
- return SfdcUrl.SANDBOX;
142
- }
143
- const createdOrgInstance = ts_types_1.getString(options, 'createdOrgInstance', '').trim().toLowerCase();
144
- if (/^gs1/gi.test(createdOrgInstance) || /(gs1.my.salesforce.com)/gi.test((_a = options.loginUrl) !== null && _a !== void 0 ? _a : '')) {
145
- return 'https://gs1.salesforce.com';
146
- }
147
- return SfdcUrl.PRODUCTION;
148
- }
149
- exports.getJwtAudienceUrl = getJwtAudienceUrl;
150
97
  // parses the id field returned from jsForce oauth2 methods to get
151
98
  // user ID and org ID.
152
99
  function parseIdUrl(idUrl) {
@@ -263,12 +210,14 @@ class AuthInfo extends kit_1.AsyncCreatable {
263
210
  */
264
211
  static getDefaultInstanceUrl() {
265
212
  const configuredInstanceUrl = configAggregator_1.ConfigAggregator.getValue('instanceUrl').value;
266
- return configuredInstanceUrl || SfdcUrl.PRODUCTION;
213
+ return configuredInstanceUrl || sfdcUrl_1.SfdcUrl.PRODUCTION;
267
214
  }
268
215
  /**
269
216
  * Get a list of all auth files stored in the global directory.
270
217
  *
271
218
  * @returns {Promise<string[]>}
219
+ *
220
+ * @deprecated Removed in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#globalinfo}
272
221
  */
273
222
  static async listAllAuthFiles() {
274
223
  const globalFiles = await fs_1.fs.readdir(global_1.Global.DIR);
@@ -359,6 +308,8 @@ class AuthInfo extends kit_1.AsyncCreatable {
359
308
  * Forces the auth file to be re-read from disk for a given user. Returns `true` if a value was removed.
360
309
  *
361
310
  * @param username The username for the auth info to re-read.
311
+ *
312
+ * @deprecated Removed in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#configstore-configfile-authinfo-and-encrypting-values}
362
313
  */
363
314
  static clearCache(username) {
364
315
  if (username) {
@@ -491,7 +442,7 @@ class AuthInfo extends kit_1.AsyncCreatable {
491
442
  // Decrypt a user provided client secret or use the default.
492
443
  opts = {
493
444
  oauth2: {
494
- loginUrl: instanceUrl || SfdcUrl.PRODUCTION,
445
+ loginUrl: instanceUrl || sfdcUrl_1.SfdcUrl.PRODUCTION,
495
446
  clientId: this.fields.clientId || exports.DEFAULT_CONNECTED_APP_INFO.legacyClientId,
496
447
  redirectUri: 'http://localhost:1717/OauthRedirect',
497
448
  },
@@ -621,7 +572,7 @@ class AuthInfo extends kit_1.AsyncCreatable {
621
572
  }
622
573
  getInstanceUrl(options, aggregator) {
623
574
  const instanceUrl = ts_types_1.getString(options, 'instanceUrl') || aggregator.getPropertyValue('instanceUrl');
624
- return instanceUrl || SfdcUrl.PRODUCTION;
575
+ return instanceUrl || sfdcUrl_1.SfdcUrl.PRODUCTION;
625
576
  }
626
577
  /**
627
578
  * Initialize this AuthInfo instance with the specified options. If options are not provided, initialize it from cache
@@ -756,7 +707,10 @@ class AuthInfo extends kit_1.AsyncCreatable {
756
707
  // Build OAuth config for a JWT auth flow
757
708
  async buildJwtConfig(options) {
758
709
  const privateKeyContents = await fs_1.fs.readFile(ts_types_1.ensure(options.privateKey), 'utf8');
759
- const audienceUrl = await getJwtAudienceUrl(options);
710
+ const { loginUrl = sfdcUrl_1.SfdcUrl.PRODUCTION } = options;
711
+ const url = new sfdcUrl_1.SfdcUrl(loginUrl);
712
+ const createdOrgInstance = ts_types_1.getString(options, 'createdOrgInstance', '').trim().toLowerCase();
713
+ const audienceUrl = await url.getJwtAudienceUrl(createdOrgInstance);
760
714
  const jwtToken = jwt.sign({
761
715
  iss: options.clientId,
762
716
  sub: this.getUsername(),
@@ -781,10 +735,10 @@ class AuthInfo extends kit_1.AsyncCreatable {
781
735
  clientId: options.clientId,
782
736
  };
783
737
  const instanceUrl = ts_types_1.ensureString(authFieldsBuilder.instance_url);
784
- const parsedUrl = url_2.parse(instanceUrl);
738
+ const sfdcUrl = new sfdcUrl_1.SfdcUrl(instanceUrl);
785
739
  try {
786
740
  // Check if the url is resolvable. This can fail when my-domains have not been replicated.
787
- await this.lookup(ts_types_1.ensure(parsedUrl.hostname));
741
+ await sfdcUrl.lookup();
788
742
  authFields.instanceUrl = instanceUrl;
789
743
  }
790
744
  catch (err) {
@@ -875,7 +829,7 @@ class AuthInfo extends kit_1.AsyncCreatable {
875
829
  // within this file to support it.
876
830
  const apiVersion = 'v51.0'; // hardcoding to v51.0 just for this call is okay.
877
831
  const instance = ts_types_1.ensure(instanceUrl);
878
- const baseUrl = new url_1.URL(instance);
832
+ const baseUrl = new sfdcUrl_1.SfdcUrl(instance);
879
833
  const userInfoUrl = `${baseUrl}services/oauth2/userinfo`;
880
834
  const headers = Object.assign({ Authorization: `Bearer ${accessToken}` }, connection_1.SFDX_HTTP_HEADERS);
881
835
  try {
@@ -929,19 +883,6 @@ class AuthInfo extends kit_1.AsyncCreatable {
929
883
  }
930
884
  throw new sfdxError_1.SfdxError(messages);
931
885
  }
932
- // See https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback
933
- async lookup(host) {
934
- return new Promise((resolve, reject) => {
935
- dns.lookup(host, (err, address, family) => {
936
- if (err) {
937
- reject(err);
938
- }
939
- else {
940
- resolve({ address, family });
941
- }
942
- });
943
- });
944
- }
945
886
  }
946
887
  exports.AuthInfo = AuthInfo;
947
888
  // The regular expression that filters files stored in $HOME/.sfdx
@@ -209,7 +209,14 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
209
209
  .reduce((x, y) => x.concat(y), []);
210
210
  const allKeys = keysWithUsername.concat(keysWithAlias);
211
211
  this.logger.debug(`Found these config keys to remove: ${allKeys}`);
212
- allKeys.forEach((key) => config.unset(key));
212
+ allKeys.forEach((key) => {
213
+ try {
214
+ config.unset(key);
215
+ }
216
+ catch {
217
+ this.logger.debug(`Failed to remove ${key}`);
218
+ }
219
+ });
213
220
  await config.write();
214
221
  }
215
222
  }
@@ -22,6 +22,8 @@ export declare enum AliasGroup {
22
22
  * const username: string = await Aliases.fetch('myAlias');
23
23
  * ```
24
24
  * https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_usernames_orgs.htm
25
+ *
26
+ * @deprecated Replaced by GlobalInfo in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#globalinfo}
25
27
  */
26
28
  export declare class Aliases extends ConfigGroup<ConfigGroup.Options> {
27
29
  /**
@@ -33,6 +33,8 @@ var AliasGroup;
33
33
  * const username: string = await Aliases.fetch('myAlias');
34
34
  * ```
35
35
  * https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_usernames_orgs.htm
36
+ *
37
+ * @deprecated Replaced by GlobalInfo in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#globalinfo}
36
38
  */
37
39
  class Aliases extends configGroup_1.ConfigGroup {
38
40
  /**
@@ -6,6 +6,8 @@ import { ConfigFile } from './configFile';
6
6
  * ```
7
7
  * const authInfo = await AuthInfoConfig.create(AuthInfoConfig.getOptions(username));
8
8
  * ```
9
+ *
10
+ * @deprecated Replaced by GlobalInfo in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#globalinfo}
9
11
  */
10
12
  export declare class AuthInfoConfig extends ConfigFile<ConfigFile.Options> {
11
13
  /**
@@ -15,6 +15,8 @@ const configFile_1 = require("./configFile");
15
15
  * ```
16
16
  * const authInfo = await AuthInfoConfig.create(AuthInfoConfig.getOptions(username));
17
17
  * ```
18
+ *
19
+ * @deprecated Replaced by GlobalInfo in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#globalinfo}
18
20
  */
19
21
  class AuthInfoConfig extends configFile_1.ConfigFile {
20
22
  /**
@@ -52,10 +52,14 @@ export interface ConfigPropertyMetaInput {
52
52
  export declare class Config extends ConfigFile<ConfigFile.Options> {
53
53
  /**
54
54
  * Username associated with the default dev hub org.
55
+ *
56
+ * @deprecated Replaced by OrgConfigProperties.TARGET_DEV_HUB in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
55
57
  */
56
58
  static readonly DEFAULT_DEV_HUB_USERNAME: string;
57
59
  /**
58
60
  * Username associate with the default org.
61
+ *
62
+ * @deprecated Replaced by OrgConfigProperties.TARGET_ORG in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
59
63
  */
60
64
  static readonly DEFAULT_USERNAME: string;
61
65
  /**
@@ -74,6 +78,10 @@ export declare class Config extends ConfigFile<ConfigFile.Options> {
74
78
  * Disables telemetry reporting
75
79
  */
76
80
  static readonly DISABLE_TELEMETRY = "disableTelemetry";
81
+ /**
82
+ * Custom templates repo or local location.
83
+ */
84
+ static readonly CUSTOM_ORG_METADATA_TEMPLATES = "customOrgMetadataTemplates";
77
85
  /**
78
86
  * allows users to override the 10,000 result query limit
79
87
  */
@@ -14,6 +14,7 @@ const crypto_1 = require("../crypto");
14
14
  const messages_1 = require("../messages");
15
15
  const sfdxError_1 = require("../sfdxError");
16
16
  const sfdc_1 = require("../util/sfdc");
17
+ const sfdcUrl_1 = require("../util/sfdcUrl");
17
18
  const configFile_1 = require("./configFile");
18
19
  const log = logger_1.Logger.childFromRoot('core:config');
19
20
  const SFDX_CONFIG_FILE_NAME = 'sfdx-config.json';
@@ -257,10 +258,14 @@ class Config extends configFile_1.ConfigFile {
257
258
  exports.Config = Config;
258
259
  /**
259
260
  * Username associated with the default dev hub org.
261
+ *
262
+ * @deprecated Replaced by OrgConfigProperties.TARGET_DEV_HUB in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
260
263
  */
261
264
  Config.DEFAULT_DEV_HUB_USERNAME = 'defaultdevhubusername';
262
265
  /**
263
266
  * Username associate with the default org.
267
+ *
268
+ * @deprecated Replaced by OrgConfigProperties.TARGET_ORG in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
264
269
  */
265
270
  Config.DEFAULT_USERNAME = 'defaultusername';
266
271
  /**
@@ -279,6 +284,10 @@ Config.API_VERSION = 'apiVersion';
279
284
  * Disables telemetry reporting
280
285
  */
281
286
  Config.DISABLE_TELEMETRY = 'disableTelemetry';
287
+ /**
288
+ * Custom templates repo or local location.
289
+ */
290
+ Config.CUSTOM_ORG_METADATA_TEMPLATES = 'customOrgMetadataTemplates';
282
291
  /**
283
292
  * allows users to override the 10,000 result query limit
284
293
  */
@@ -288,7 +297,7 @@ Config.allowedProperties = [
288
297
  key: 'instanceUrl',
289
298
  input: {
290
299
  // If a value is provided validate it otherwise no value is unset.
291
- validator: (value) => value == null || (ts_types_1.isString(value) && sfdc_1.sfdc.isSalesforceDomain(value)),
300
+ validator: (value) => value == null || (ts_types_1.isString(value) && new sfdcUrl_1.SfdcUrl(value).isSalesforceDomain()),
292
301
  get failedMessage() {
293
302
  var _a;
294
303
  return (_a = Config.messages) === null || _a === void 0 ? void 0 : _a.getMessage('InvalidInstanceUrl');
@@ -307,6 +316,17 @@ Config.allowedProperties = [
307
316
  },
308
317
  },
309
318
  },
319
+ {
320
+ key: Config.CUSTOM_ORG_METADATA_TEMPLATES,
321
+ input: {
322
+ // If a value is provided validate it otherwise no value is unset.
323
+ validator: (value) => value == null || ts_types_1.isString(value),
324
+ get failedMessage() {
325
+ var _a;
326
+ return (_a = Config.messages) === null || _a === void 0 ? void 0 : _a.getMessage('InvalidCustomOrgMetadataTemplates');
327
+ },
328
+ },
329
+ },
310
330
  { key: Config.DEFAULT_DEV_HUB_USERNAME },
311
331
  { key: Config.DEFAULT_USERNAME },
312
332
  {
package/lib/exported.d.ts CHANGED
@@ -8,12 +8,14 @@ export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } fro
8
8
  export { OrgUsersConfig } from './config/orgUsersConfig';
9
9
  export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config } from './config/config';
10
10
  export { ConfigInfo, ConfigAggregator } from './config/configAggregator';
11
- export { Authorization, AuthFields, AuthInfo, OAuth2WithVerifier, SfdcUrl, getJwtAudienceUrl } from './authInfo';
11
+ export { Authorization, AuthFields, AuthInfo, OAuth2WithVerifier } from './authInfo';
12
12
  export { AuthConfigs, AuthRemover } from './authRemover';
13
13
  export { Connection, SFDX_HTTP_HEADERS } from './connection';
14
14
  export { Mode, Global } from './global';
15
15
  export { Lifecycle } from './lifecycleEvents';
16
16
  export { WebOAuthServer } from './webOAuthServer';
17
+ export { SfdcUrl } from './util/sfdcUrl';
18
+ export { getJwtAudienceUrl } from './util/getJwtAudienceUrl';
17
19
  export { Fields, FieldValue, LoggerLevel, LoggerLevelValue, LogLine, LoggerOptions, LoggerStream, Logger, } from './logger';
18
20
  export { Messages } from './messages';
19
21
  export { Org } from './org';
package/lib/exported.js CHANGED
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxErrorConfig = exports.SfdxError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.OAuth2WithVerifier = exports.AuthInfo = exports.ConfigAggregator = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.BaseConfigStore = exports.ConfigGroup = exports.ConfigFile = exports.AuthInfoConfig = exports.AliasGroup = exports.Aliases = void 0;
19
+ exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxErrorConfig = exports.SfdxError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.OAuth2WithVerifier = exports.AuthInfo = exports.ConfigAggregator = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.BaseConfigStore = exports.ConfigGroup = exports.ConfigFile = exports.AuthInfoConfig = exports.AliasGroup = exports.Aliases = void 0;
20
20
  const messages_1 = require("./messages");
21
21
  messages_1.Messages.importMessagesDirectory(__dirname);
22
22
  var aliases_1 = require("./config/aliases");
@@ -41,8 +41,6 @@ Object.defineProperty(exports, "ConfigAggregator", { enumerable: true, get: func
41
41
  var authInfo_1 = require("./authInfo");
42
42
  Object.defineProperty(exports, "AuthInfo", { enumerable: true, get: function () { return authInfo_1.AuthInfo; } });
43
43
  Object.defineProperty(exports, "OAuth2WithVerifier", { enumerable: true, get: function () { return authInfo_1.OAuth2WithVerifier; } });
44
- Object.defineProperty(exports, "SfdcUrl", { enumerable: true, get: function () { return authInfo_1.SfdcUrl; } });
45
- Object.defineProperty(exports, "getJwtAudienceUrl", { enumerable: true, get: function () { return authInfo_1.getJwtAudienceUrl; } });
46
44
  var authRemover_1 = require("./authRemover");
47
45
  Object.defineProperty(exports, "AuthRemover", { enumerable: true, get: function () { return authRemover_1.AuthRemover; } });
48
46
  var connection_1 = require("./connection");
@@ -55,6 +53,10 @@ var lifecycleEvents_1 = require("./lifecycleEvents");
55
53
  Object.defineProperty(exports, "Lifecycle", { enumerable: true, get: function () { return lifecycleEvents_1.Lifecycle; } });
56
54
  var webOAuthServer_1 = require("./webOAuthServer");
57
55
  Object.defineProperty(exports, "WebOAuthServer", { enumerable: true, get: function () { return webOAuthServer_1.WebOAuthServer; } });
56
+ var sfdcUrl_1 = require("./util/sfdcUrl");
57
+ Object.defineProperty(exports, "SfdcUrl", { enumerable: true, get: function () { return sfdcUrl_1.SfdcUrl; } });
58
+ var getJwtAudienceUrl_1 = require("./util/getJwtAudienceUrl");
59
+ Object.defineProperty(exports, "getJwtAudienceUrl", { enumerable: true, get: function () { return getJwtAudienceUrl_1.getJwtAudienceUrl; } });
58
60
  var logger_1 = require("./logger");
59
61
  Object.defineProperty(exports, "LoggerLevel", { enumerable: true, get: function () { return logger_1.LoggerLevel; } });
60
62
  Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
@@ -10,7 +10,6 @@ exports.SfdxProject = exports.SfdxProjectJson = void 0;
10
10
  const path_1 = require("path");
11
11
  const kit_1 = require("@salesforce/kit");
12
12
  const ts_types_1 = require("@salesforce/ts-types");
13
- const authInfo_1 = require("./authInfo");
14
13
  const configAggregator_1 = require("./config/configAggregator");
15
14
  const configFile_1 = require("./config/configFile");
16
15
  const validator_1 = require("./schema/validator");
@@ -18,6 +17,7 @@ const fs_1 = require("./util/fs");
18
17
  const internal_1 = require("./util/internal");
19
18
  const sfdxError_1 = require("./sfdxError");
20
19
  const sfdc_1 = require("./util/sfdc");
20
+ const sfdcUrl_1 = require("./util/sfdcUrl");
21
21
  /**
22
22
  * The sfdx-project.json config object. This file determines if a folder is a valid sfdx project.
23
23
  *
@@ -533,7 +533,7 @@ class SfdxProject {
533
533
  Object.assign(this.projectConfig, configAggregator.getConfig());
534
534
  // we don't have a login url yet, so use instanceUrl from config or default
535
535
  if (!this.projectConfig.sfdcLoginUrl) {
536
- this.projectConfig.sfdcLoginUrl = (_a = configAggregator.getConfig().instanceUrl) !== null && _a !== void 0 ? _a : authInfo_1.SfdcUrl.PRODUCTION;
536
+ this.projectConfig.sfdcLoginUrl = (_a = configAggregator.getConfig().instanceUrl) !== null && _a !== void 0 ? _a : sfdcUrl_1.SfdcUrl.PRODUCTION;
537
537
  }
538
538
  // LEGACY - Allow override of sfdcLoginUrl via env var FORCE_SFDC_LOGIN_URL
539
539
  if (process.env.FORCE_SFDC_LOGIN_URL) {
@@ -13,7 +13,7 @@ const util_1 = require("util");
13
13
  const ts_types_1 = require("@salesforce/ts-types");
14
14
  const kit_1 = require("@salesforce/kit");
15
15
  const logger_1 = require("../logger");
16
- const sfdc_1 = require("../util/sfdc");
16
+ const sfdcUrl_1 = require("../util/sfdcUrl");
17
17
  const pollingClient_1 = require("./pollingClient");
18
18
  // Timeout for DNS lookup polling defaults to 3 seconds and should always be at least 3 seconds
19
19
  const DNS_TIMEOUT = Math.max(3, new kit_1.Env().getNumber('SFDX_DNS_TIMEOUT', 3));
@@ -63,11 +63,11 @@ class MyDomainResolver extends kit_1.AsyncOptionalCreatable {
63
63
  const self = this;
64
64
  const pollingOptions = {
65
65
  async poll() {
66
- const host = self.options.url.host;
66
+ const { host } = self.options.url;
67
67
  let dnsResult;
68
68
  try {
69
69
  self.logger.debug(`Attempting to resolve url: ${host}`);
70
- if (sfdc_1.sfdc.isLocalUrl(host)) {
70
+ if (new sfdcUrl_1.SfdcUrl(self.options.url).isLocalUrl()) {
71
71
  return {
72
72
  completed: true,
73
73
  payload: '127.0.0.1',
package/lib/util/fs.d.ts CHANGED
@@ -10,6 +10,9 @@ export declare type WriteJsonOptions = {
10
10
  */
11
11
  space?: number;
12
12
  };
13
+ /**
14
+ * @deprecated Use fs/promises instead
15
+ */
13
16
  export declare const fs: typeof fsLib & {
14
17
  /**
15
18
  * The default file system mode to use when creating directories.
package/lib/util/fs.js CHANGED
@@ -14,6 +14,9 @@ const kit_1 = require("@salesforce/kit");
14
14
  const fsLib = require("graceful-fs");
15
15
  const mkdirpLib = require("mkdirp");
16
16
  const sfdxError_1 = require("../sfdxError");
17
+ /**
18
+ * @deprecated Use fs/promises instead
19
+ */
17
20
  exports.fs = Object.assign({}, fsLib, {
18
21
  /**
19
22
  * The default file system mode to use when creating directories.
@@ -0,0 +1,4 @@
1
+ import { OAuth2Options } from 'jsforce';
2
+ export declare function getJwtAudienceUrl(options: OAuth2Options & {
3
+ createdOrgInstance?: string;
4
+ }): Promise<string>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getJwtAudienceUrl = void 0;
10
+ const sfdcUrl_1 = require("./sfdcUrl");
11
+ async function getJwtAudienceUrl(options) {
12
+ if (options.loginUrl) {
13
+ const url = new sfdcUrl_1.SfdcUrl(options.loginUrl);
14
+ return await url.getJwtAudienceUrl(options.createdOrgInstance);
15
+ }
16
+ return sfdcUrl_1.SfdcUrl.PRODUCTION;
17
+ }
18
+ exports.getJwtAudienceUrl = getJwtAudienceUrl;
19
+ //# sourceMappingURL=getJwtAudienceUrl.js.map
@@ -1,11 +1,5 @@
1
1
  import { JsonMap, Optional } from '@salesforce/ts-types';
2
2
  export declare const sfdc: {
3
- /**
4
- * Returns `true` if a provided URL contains a Salesforce owned domain.
5
- *
6
- * @param urlString The URL to inspect.
7
- */
8
- isSalesforceDomain: (urlString: string) => boolean;
9
3
  /**
10
4
  * Converts an 18 character Salesforce ID to 15 characters.
11
5
  *
@@ -55,10 +49,4 @@ export declare const sfdc: {
55
49
  * @param url
56
50
  */
57
51
  isInternalUrl: (url: string) => boolean;
58
- /**
59
- * Tests whether a given internal url runs on a local machine
60
- *
61
- * @param url
62
- */
63
- isLocalUrl: (url: string) => boolean;
64
52
  };
package/lib/util/sfdc.js CHANGED
@@ -7,37 +7,10 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.sfdc = void 0;
10
- const url_1 = require("url");
11
10
  const kit_1 = require("@salesforce/kit");
12
11
  const ts_types_1 = require("@salesforce/ts-types");
12
+ const sfdcUrl_1 = require("./sfdcUrl");
13
13
  exports.sfdc = {
14
- /**
15
- * Returns `true` if a provided URL contains a Salesforce owned domain.
16
- *
17
- * @param urlString The URL to inspect.
18
- */
19
- isSalesforceDomain: (urlString) => {
20
- let url;
21
- try {
22
- url = new url_1.URL(urlString);
23
- }
24
- catch (e) {
25
- return false;
26
- }
27
- // Source https://help.salesforce.com/articleView?id=000003652&type=1
28
- const allowlistOfSalesforceDomainPatterns = [
29
- '.cloudforce.com',
30
- '.content.force.com',
31
- '.force.com',
32
- '.salesforce.com',
33
- '.salesforceliveagent.com',
34
- '.secure.force.com',
35
- ];
36
- const allowlistOfSalesforceHosts = ['developer.salesforce.com', 'trailhead.salesforce.com'];
37
- return allowlistOfSalesforceDomainPatterns.some((pattern) => {
38
- return url.hostname.endsWith(pattern) || allowlistOfSalesforceHosts.includes(url.hostname);
39
- });
40
- },
41
14
  /**
42
15
  * Converts an 18 character Salesforce ID to 15 characters.
43
16
  *
@@ -117,26 +90,6 @@ exports.sfdc = {
117
90
  *
118
91
  * @param url
119
92
  */
120
- isInternalUrl: (url) => {
121
- const INTERNAL_URL_PARTS = [
122
- '.vpod.',
123
- 'stm.salesforce.com',
124
- 'stm.force.com',
125
- '.blitz.salesforce.com',
126
- '.stm.salesforce.ms',
127
- '.pc-rnd.force.com',
128
- '.pc-rnd.salesforce.com',
129
- ];
130
- return (url.startsWith('https://gs1.') || exports.sfdc.isLocalUrl(url) || INTERNAL_URL_PARTS.some((part) => url.includes(part)));
131
- },
132
- /**
133
- * Tests whether a given internal url runs on a local machine
134
- *
135
- * @param url
136
- */
137
- isLocalUrl: (url) => {
138
- const LOCAL_PARTS = ['localhost.sfdcdev.', '.internal.'];
139
- return LOCAL_PARTS.some((part) => url.includes(part));
140
- },
93
+ isInternalUrl: (url) => new sfdcUrl_1.SfdcUrl(url).isInternalUrl(),
141
94
  };
142
95
  //# sourceMappingURL=sfdc.js.map
@@ -0,0 +1,70 @@
1
+ /// <reference types="node" />
2
+ import { URL } from 'url';
3
+ export declare class SfdcUrl extends URL {
4
+ /**
5
+ * Salesforce URLs
6
+ */
7
+ static readonly SANDBOX = "https://test.salesforce.com";
8
+ static readonly PRODUCTION = "https://login.salesforce.com";
9
+ private static readonly cache;
10
+ private logger;
11
+ constructor(input: string | URL, base?: string | URL);
12
+ /**
13
+ * Returns the appropiate jwt audience url for this url
14
+ * Use SFDX_AUDIENCE_URL env var to override the audience url
15
+ *
16
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
17
+ * @return {Promise<string>} The audience url
18
+ */
19
+ getJwtAudienceUrl(createdOrgInstance?: string): Promise<string>;
20
+ /**
21
+ * Tests whether this url contains a Salesforce owned domain
22
+ *
23
+ * @return {boolean} true if this is a salesforce domain
24
+ */
25
+ isSalesforceDomain(): boolean;
26
+ /**
27
+ * Tests whether this url is an internal Salesforce domain
28
+ *
29
+ * @returns {boolean} true if this is a internal domain
30
+ */
31
+ isInternalUrl(): boolean;
32
+ /**
33
+ * Tests whether this url runs on a local machine
34
+ *
35
+ * @returns {boolean} true if this is a local machine
36
+ */
37
+ isLocalUrl(): boolean;
38
+ /**
39
+ * Tests whether this url has the lightning domain extension
40
+ * This method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again untill timeout
41
+ * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
42
+ *
43
+ * @returns {Promise<true | never>} The resolved ip address or never
44
+ * @throws {@link SfdxError} If can't resolve DNS.
45
+ */
46
+ checkLightningDomain(): Promise<true | never>;
47
+ /**
48
+ * Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again untill timeout
49
+ * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
50
+ *
51
+ * @returns the resolved ip address.
52
+ * @throws {@link SfdxError} If can't resolve DNS.
53
+ */
54
+ lookup(): Promise<string>;
55
+ /**
56
+ * Tests whether this url is a sandbox url
57
+ *
58
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
59
+ * @returns {boolean}
60
+ */
61
+ isSandboxUrl(createdOrgInstance?: string): boolean;
62
+ /**
63
+ * Tests whether this url is a sandbox url
64
+ * otherwise tryies to resolve dns cnames and then look if any is sandbox url
65
+ *
66
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
67
+ * @returns {Promise<boolean>} true if this domain resolves to sanbox url
68
+ */
69
+ private resolvesToSandbox;
70
+ }
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.SfdcUrl = void 0;
10
+ const url_1 = require("url");
11
+ const kit_1 = require("@salesforce/kit");
12
+ const ts_types_1 = require("@salesforce/ts-types");
13
+ const myDomainResolver_1 = require("../status/myDomainResolver");
14
+ const logger_1 = require("../logger");
15
+ class SfdcUrl extends url_1.URL {
16
+ constructor(input, base) {
17
+ super(input.toString(), base);
18
+ if (this.protocol !== 'https:' && !SfdcUrl.cache.has(this.origin)) {
19
+ SfdcUrl.cache.add(this.origin);
20
+ process.emitWarning('Using insecure protocol: ' + this.protocol + ' on url: ' + this.origin);
21
+ }
22
+ }
23
+ /**
24
+ * Returns the appropiate jwt audience url for this url
25
+ * Use SFDX_AUDIENCE_URL env var to override the audience url
26
+ *
27
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
28
+ * @return {Promise<string>} The audience url
29
+ */
30
+ async getJwtAudienceUrl(createdOrgInstance) {
31
+ this.logger = await logger_1.Logger.child('SfdcUrl');
32
+ // environment variable is used as an override
33
+ const envVarVal = new kit_1.Env().getString('SFDX_AUDIENCE_URL', '');
34
+ if (envVarVal) {
35
+ this.logger.debug(`Audience URL overriden by env var SFDX_AUDIENCE_URL=${envVarVal}`);
36
+ return envVarVal;
37
+ }
38
+ if (this.isInternalUrl()) {
39
+ // This is for internal developers when just doing authorize
40
+ return this.origin;
41
+ }
42
+ if (await this.resolvesToSandbox(createdOrgInstance)) {
43
+ return SfdcUrl.SANDBOX;
44
+ }
45
+ if ((createdOrgInstance && /^gs1/gi.test(createdOrgInstance)) || /(gs1.my.salesforce.com)/gi.test(this.origin)) {
46
+ return 'https://gs1.salesforce.com';
47
+ }
48
+ return SfdcUrl.PRODUCTION;
49
+ }
50
+ /**
51
+ * Tests whether this url contains a Salesforce owned domain
52
+ *
53
+ * @return {boolean} true if this is a salesforce domain
54
+ */
55
+ isSalesforceDomain() {
56
+ // Source https://help.salesforce.com/articleView?id=000003652&type=1
57
+ const allowlistOfSalesforceDomainPatterns = [
58
+ '.cloudforce.com',
59
+ '.content.force.com',
60
+ '.force.com',
61
+ '.salesforce.com',
62
+ '.salesforceliveagent.com',
63
+ '.secure.force.com',
64
+ ];
65
+ const allowlistOfSalesforceHosts = ['developer.salesforce.com', 'trailhead.salesforce.com'];
66
+ return allowlistOfSalesforceDomainPatterns.some((pattern) => {
67
+ return this.hostname.endsWith(pattern) || allowlistOfSalesforceHosts.includes(this.hostname);
68
+ });
69
+ }
70
+ /**
71
+ * Tests whether this url is an internal Salesforce domain
72
+ *
73
+ * @returns {boolean} true if this is a internal domain
74
+ */
75
+ isInternalUrl() {
76
+ const INTERNAL_URL_PARTS = [
77
+ '.vpod.',
78
+ 'stm.salesforce.com',
79
+ 'stm.force.com',
80
+ '.blitz.salesforce.com',
81
+ '.stm.salesforce.ms',
82
+ '.pc-rnd.force.com',
83
+ '.pc-rnd.salesforce.com',
84
+ ];
85
+ return (this.origin.startsWith('https://gs1.') ||
86
+ this.isLocalUrl() ||
87
+ INTERNAL_URL_PARTS.some((part) => this.origin.includes(part)));
88
+ }
89
+ /**
90
+ * Tests whether this url runs on a local machine
91
+ *
92
+ * @returns {boolean} true if this is a local machine
93
+ */
94
+ isLocalUrl() {
95
+ const LOCAL_PARTS = ['localhost.sfdcdev.', '.internal.'];
96
+ return LOCAL_PARTS.some((part) => this.origin.includes(part));
97
+ }
98
+ /**
99
+ * Tests whether this url has the lightning domain extension
100
+ * This method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again untill timeout
101
+ * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
102
+ *
103
+ * @returns {Promise<true | never>} The resolved ip address or never
104
+ * @throws {@link SfdxError} If can't resolve DNS.
105
+ */
106
+ async checkLightningDomain() {
107
+ const domain = `https://${ts_types_1.ensureArray(/https?:\/\/([^.]*)/.exec(this.origin))
108
+ .slice(1, 2)
109
+ .pop()}.lightning.force.com`;
110
+ const quantity = ts_types_1.ensureNumber(new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240));
111
+ const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
112
+ if (this.isInternalUrl() || timeout.seconds === 0) {
113
+ return true;
114
+ }
115
+ const resolver = await myDomainResolver_1.MyDomainResolver.create({
116
+ url: new url_1.URL(domain),
117
+ timeout,
118
+ frequency: new kit_1.Duration(1, kit_1.Duration.Unit.SECONDS),
119
+ });
120
+ await resolver.resolve();
121
+ return true;
122
+ }
123
+ /**
124
+ * Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again untill timeout
125
+ * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
126
+ *
127
+ * @returns the resolved ip address.
128
+ * @throws {@link SfdxError} If can't resolve DNS.
129
+ */
130
+ async lookup() {
131
+ const quantity = ts_types_1.ensureNumber(new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240));
132
+ const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
133
+ const resolver = await myDomainResolver_1.MyDomainResolver.create({
134
+ url: new url_1.URL(this.origin),
135
+ timeout,
136
+ frequency: new kit_1.Duration(1, kit_1.Duration.Unit.SECONDS),
137
+ });
138
+ return resolver.resolve();
139
+ }
140
+ /**
141
+ * Tests whether this url is a sandbox url
142
+ *
143
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
144
+ * @returns {boolean}
145
+ */
146
+ isSandboxUrl(createdOrgInstance) {
147
+ return ((createdOrgInstance && /^cs|s$/gi.test(createdOrgInstance)) ||
148
+ /sandbox\.my\.salesforce\.com/gi.test(this.origin) || // enhanced domains >= 230
149
+ /(cs[0-9]+(\.my|)\.salesforce\.com)/gi.test(this.origin) || // my domains on CS instance OR CS instance without my domain
150
+ /([a-z]{3}[0-9]+s\.sfdc-.+\.salesforce\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
151
+ /([a-z]{3}[0-9]+s\.sfdc-.+\.force\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.force.com
152
+ this.hostname === 'test.salesforce.com');
153
+ }
154
+ /**
155
+ * Tests whether this url is a sandbox url
156
+ * otherwise tryies to resolve dns cnames and then look if any is sandbox url
157
+ *
158
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
159
+ * @returns {Promise<boolean>} true if this domain resolves to sanbox url
160
+ */
161
+ async resolvesToSandbox(createdOrgInstance) {
162
+ if (this.isSandboxUrl(createdOrgInstance)) {
163
+ return true;
164
+ }
165
+ const myDomainResolver = await myDomainResolver_1.MyDomainResolver.create({ url: this });
166
+ const cnames = await myDomainResolver.getCnames();
167
+ return cnames.some((cname) => {
168
+ const url = new SfdcUrl(`https://${cname}`);
169
+ return url.isSandboxUrl();
170
+ });
171
+ }
172
+ }
173
+ exports.SfdcUrl = SfdcUrl;
174
+ /**
175
+ * Salesforce URLs
176
+ */
177
+ SfdcUrl.SANDBOX = 'https://test.salesforce.com';
178
+ SfdcUrl.PRODUCTION = 'https://login.salesforce.com';
179
+ SfdcUrl.cache = new Set();
180
+ //# sourceMappingURL=sfdcUrl.js.map
@@ -3,6 +3,7 @@
3
3
  "InvalidConfigValue": "Invalid config value. %s",
4
4
  "InvalidInstanceUrl": "Specify a valid Salesforce instance URL",
5
5
  "InvalidApiVersion": "Specify a valid Salesforce API version, for example, 42.0",
6
+ "InvalidCustomOrgMetadataTemplates": "Specify a valid repository URL or directory for the custom org metadata templates.",
6
7
  "InvalidIsvDebuggerSid": "Specify a valid Debugger SID",
7
8
  "InvalidIsvDebuggerUrl": "Specify a valid Debugger URL",
8
9
  "InvalidNumberConfigValue": "Specify a valid positive integer, for example, 150000",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "2.26.1",
3
+ "version": "2.28.0",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "license": "BSD-3-Clause",
@@ -1 +0,0 @@
1
- export default function checkLightningDomain(url: string): Promise<boolean>;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /*
4
- * Copyright (c) 2021, salesforce.com, inc.
5
- * All rights reserved.
6
- * Licensed under the BSD 3-Clause license.
7
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
- */
9
- const url_1 = require("url");
10
- const kit_1 = require("@salesforce/kit");
11
- const myDomainResolver_1 = require("../status/myDomainResolver");
12
- const sfdc_1 = require("./sfdc");
13
- async function checkLightningDomain(url) {
14
- var _a, _b;
15
- const domain = `https://${(_a = /https?:\/\/([^.]*)/.exec(url)) === null || _a === void 0 ? void 0 : _a.slice(1, 2).pop()}.lightning.force.com`;
16
- const quantity = (_b = new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240)) !== null && _b !== void 0 ? _b : 0;
17
- const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
18
- if (sfdc_1.sfdc.isInternalUrl(url) || timeout.seconds === 0) {
19
- return true;
20
- }
21
- const resolver = await myDomainResolver_1.MyDomainResolver.create({
22
- url: new url_1.URL(domain),
23
- timeout,
24
- frequency: new kit_1.Duration(1, kit_1.Duration.Unit.SECONDS),
25
- });
26
- await resolver.resolve();
27
- return true;
28
- }
29
- exports.default = checkLightningDomain;
30
- //# sourceMappingURL=checkLightningDomain.js.map