@salesforce/core 4.0.0-v3.0 → 4.0.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.
Files changed (125) hide show
  1. package/CHANGELOG.md +569 -24
  2. package/LICENSE.txt +1 -1
  3. package/lib/config/config.d.ts +110 -42
  4. package/lib/config/config.js +309 -138
  5. package/lib/config/configAggregator.d.ts +22 -11
  6. package/lib/config/configAggregator.js +50 -26
  7. package/lib/config/configFile.js +10 -10
  8. package/lib/config/configStore.js +15 -14
  9. package/lib/config/envVars.d.ts +96 -0
  10. package/lib/config/envVars.js +433 -0
  11. package/lib/config/keychainConfig.js +1 -1
  12. package/lib/config/orgUsersConfig.d.ts +8 -0
  13. package/lib/config/orgUsersConfig.js +10 -0
  14. package/lib/config/sandboxOrgConfig.d.ts +8 -0
  15. package/lib/config/sandboxOrgConfig.js +10 -0
  16. package/lib/crypto/crypto.js +28 -8
  17. package/lib/crypto/keyChain.js +2 -1
  18. package/lib/crypto/keyChainImpl.js +8 -6
  19. package/lib/crypto/secureBuffer.js +1 -1
  20. package/lib/deviceOauthService.d.ts +3 -3
  21. package/lib/deviceOauthService.js +22 -20
  22. package/lib/exported.d.ts +13 -9
  23. package/lib/exported.js +25 -13
  24. package/lib/global.d.ts +6 -0
  25. package/lib/global.js +7 -1
  26. package/lib/globalInfo/accessors/aliasAccessor.d.ts +83 -0
  27. package/lib/globalInfo/accessors/aliasAccessor.js +130 -0
  28. package/lib/globalInfo/accessors/orgAccessor.d.ts +13 -0
  29. package/lib/globalInfo/accessors/orgAccessor.js +45 -0
  30. package/lib/globalInfo/accessors/tokenAccessor.d.ts +13 -0
  31. package/lib/globalInfo/accessors/tokenAccessor.js +35 -0
  32. package/lib/globalInfo/globalInfoConfig.d.ts +36 -0
  33. package/lib/globalInfo/globalInfoConfig.js +105 -0
  34. package/lib/globalInfo/index.d.ts +6 -0
  35. package/lib/globalInfo/index.js +29 -0
  36. package/lib/{config → globalInfo}/sfdxDataHandler.d.ts +10 -3
  37. package/lib/{config → globalInfo}/sfdxDataHandler.js +71 -19
  38. package/lib/globalInfo/types.d.ts +39 -0
  39. package/lib/globalInfo/types.js +10 -0
  40. package/lib/lifecycleEvents.d.ts +38 -1
  41. package/lib/lifecycleEvents.js +74 -3
  42. package/lib/logger.d.ts +2 -2
  43. package/lib/logger.js +16 -26
  44. package/lib/messages.js +12 -10
  45. package/lib/org/authInfo.d.ts +41 -65
  46. package/lib/org/authInfo.js +138 -233
  47. package/lib/org/authRemover.d.ts +11 -19
  48. package/lib/org/authRemover.js +47 -49
  49. package/lib/org/connection.d.ts +24 -26
  50. package/lib/org/connection.js +77 -92
  51. package/lib/org/index.js +1 -1
  52. package/lib/org/org.d.ts +134 -12
  53. package/lib/org/org.js +436 -97
  54. package/lib/org/orgConfigProperties.d.ts +8 -0
  55. package/lib/org/orgConfigProperties.js +29 -0
  56. package/lib/org/permissionSetAssignment.js +3 -3
  57. package/lib/org/scratchOrgCreate.d.ts +43 -0
  58. package/lib/org/scratchOrgCreate.js +142 -0
  59. package/lib/org/scratchOrgErrorCodes.d.ts +4 -0
  60. package/lib/org/scratchOrgErrorCodes.js +62 -0
  61. package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -0
  62. package/lib/org/scratchOrgFeatureDeprecation.js +110 -0
  63. package/lib/org/scratchOrgInfoApi.d.ts +94 -0
  64. package/lib/org/scratchOrgInfoApi.js +350 -0
  65. package/lib/org/scratchOrgInfoGenerator.d.ts +63 -0
  66. package/lib/org/scratchOrgInfoGenerator.js +223 -0
  67. package/lib/org/scratchOrgSettingsGenerator.d.ts +56 -0
  68. package/lib/org/scratchOrgSettingsGenerator.js +210 -0
  69. package/lib/org/user.d.ts +6 -1
  70. package/lib/org/user.js +69 -36
  71. package/lib/schema/printer.js +18 -18
  72. package/lib/schema/validator.js +8 -8
  73. package/lib/sfdxError.d.ts +6 -1
  74. package/lib/sfdxError.js +10 -2
  75. package/lib/sfdxProject.js +33 -22
  76. package/lib/status/myDomainResolver.js +6 -6
  77. package/lib/status/pollingClient.d.ts +2 -6
  78. package/lib/status/pollingClient.js +37 -63
  79. package/lib/status/streamingClient.d.ts +5 -80
  80. package/lib/status/streamingClient.js +18 -33
  81. package/lib/status/types.d.ts +89 -0
  82. package/lib/status/types.js +18 -0
  83. package/lib/testSetup.d.ts +7 -5
  84. package/lib/testSetup.js +38 -40
  85. package/lib/util/cache.d.ts +11 -0
  86. package/lib/util/cache.js +70 -0
  87. package/lib/util/checkLightningDomain.d.ts +1 -0
  88. package/lib/util/checkLightningDomain.js +30 -0
  89. package/lib/util/fs.d.ts +3 -0
  90. package/lib/util/fs.js +16 -12
  91. package/lib/util/getJwtAudienceUrl.d.ts +4 -0
  92. package/lib/util/getJwtAudienceUrl.js +19 -0
  93. package/lib/util/jsonXmlTools.d.ts +14 -0
  94. package/lib/util/jsonXmlTools.js +41 -0
  95. package/lib/util/mapKeys.d.ts +14 -0
  96. package/lib/util/mapKeys.js +48 -0
  97. package/lib/util/sfdc.d.ts +1 -13
  98. package/lib/util/sfdc.js +5 -52
  99. package/lib/util/sfdcUrl.d.ts +78 -0
  100. package/lib/util/sfdcUrl.js +206 -0
  101. package/lib/util/zipWriter.d.ts +14 -0
  102. package/lib/util/zipWriter.js +68 -0
  103. package/lib/webOAuthServer.d.ts +2 -3
  104. package/lib/webOAuthServer.js +11 -10
  105. package/messages/auth.md +2 -2
  106. package/messages/config.md +58 -6
  107. package/messages/core.json +3 -3
  108. package/messages/core.md +1 -1
  109. package/messages/envVars.md +279 -0
  110. package/messages/org.md +44 -0
  111. package/messages/scratchOrgCreate.md +27 -0
  112. package/messages/scratchOrgErrorCodes.md +99 -0
  113. package/messages/scratchOrgFeatureDeprecation.md +11 -0
  114. package/messages/scratchOrgInfoApi.md +11 -0
  115. package/messages/scratchOrgInfoGenerator.md +19 -0
  116. package/messages/user.md +12 -0
  117. package/package.json +50 -53
  118. package/lib/config/aliases.d.ts +0 -56
  119. package/lib/config/aliases.js +0 -96
  120. package/lib/config/configGroup.d.ts +0 -141
  121. package/lib/config/configGroup.js +0 -223
  122. package/lib/config/globalInfoConfig.d.ts +0 -74
  123. package/lib/config/globalInfoConfig.js +0 -144
  124. package/lib/status/client.d.ts +0 -15
  125. package/lib/status/client.js +0 -9
@@ -0,0 +1,41 @@
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.fixExistingDollarSign = exports.JsonAsXml = exports.writeJSONasXML = exports.standardOptions = void 0;
10
+ const fs_1 = require("fs");
11
+ const jsToXml = require("js2xmlparser");
12
+ exports.standardOptions = {
13
+ declaration: {
14
+ include: true,
15
+ encoding: 'UTF-8',
16
+ version: '1.0',
17
+ },
18
+ format: {
19
+ doubleQuotes: true,
20
+ },
21
+ };
22
+ const writeJSONasXML = async ({ path, json, type, options = exports.standardOptions, }) => {
23
+ const xml = jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
24
+ return await fs_1.promises.writeFile(path, xml);
25
+ };
26
+ exports.writeJSONasXML = writeJSONasXML;
27
+ const JsonAsXml = ({ json, type, options = exports.standardOptions }) => {
28
+ return jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
29
+ };
30
+ exports.JsonAsXml = JsonAsXml;
31
+ const fixExistingDollarSign = (existing) => {
32
+ const existingCopy = { ...existing };
33
+ if (existingCopy.$) {
34
+ const temp = existingCopy.$;
35
+ delete existingCopy.$;
36
+ existingCopy['@'] = temp;
37
+ }
38
+ return existingCopy;
39
+ };
40
+ exports.fixExistingDollarSign = fixExistingDollarSign;
41
+ //# sourceMappingURL=jsonXmlTools.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Use mapKeys to convert object keys to another format using the specified conversion function.
3
+ *
4
+ * E.g., to deep convert all object keys to camelCase: mapKeys(myObj, _.camelCase, true)
5
+ * to shallow convert object keys to lower case: mapKeys(myObj, _.toLower)
6
+ *
7
+ * NOTE: This mutates the object passed in for conversion.
8
+ *
9
+ * @param target - {Object} The object to convert the keys
10
+ * @param converter - {Function} The function that converts the object key
11
+ * @param deep - {boolean} Whether to do a deep object key conversion
12
+ * @return {Object} - the object with the converted keys
13
+ */
14
+ export default function mapKeys(obj: any, converter: (key: string) => string, deep?: boolean): Record<string, unknown>;
@@ -0,0 +1,48 @@
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
+ const ts_types_1 = require("@salesforce/ts-types");
10
+ /**
11
+ * Use mapKeys to convert object keys to another format using the specified conversion function.
12
+ *
13
+ * E.g., to deep convert all object keys to camelCase: mapKeys(myObj, _.camelCase, true)
14
+ * to shallow convert object keys to lower case: mapKeys(myObj, _.toLower)
15
+ *
16
+ * NOTE: This mutates the object passed in for conversion.
17
+ *
18
+ * @param target - {Object} The object to convert the keys
19
+ * @param converter - {Function} The function that converts the object key
20
+ * @param deep - {boolean} Whether to do a deep object key conversion
21
+ * @return {Object} - the object with the converted keys
22
+ */
23
+ function mapKeys(
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
25
+ obj, converter, deep) {
26
+ const target = Object.assign({}, obj);
27
+ return Object.fromEntries(Object.entries(target).map(([key, value]) => {
28
+ const k = converter.call(null, key);
29
+ if (deep) {
30
+ let v = value;
31
+ if (Array.isArray(value)) {
32
+ v = value.map((v1) => {
33
+ if ((0, ts_types_1.isPlainObject)(v1)) {
34
+ return mapKeys(v1, converter, deep);
35
+ }
36
+ return v1;
37
+ });
38
+ }
39
+ else if ((0, ts_types_1.isPlainObject)(value)) {
40
+ v = mapKeys(value, converter, deep);
41
+ }
42
+ return [k, v];
43
+ }
44
+ return [k, value];
45
+ }));
46
+ }
47
+ exports.default = mapKeys;
48
+ //# sourceMappingURL=mapKeys.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
  *
@@ -42,7 +36,7 @@ export declare const sfdc: {
42
36
  * @param data The object in which to check key casing.
43
37
  * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`.
44
38
  */
45
- findUpperCaseKeys: (data?: Optional<JsonMap>, sectionBlocklist?: string[]) => Optional<string>;
39
+ findUpperCaseKeys: (data?: JsonMap | undefined, sectionBlocklist?: string[]) => Optional<string>;
46
40
  /**
47
41
  * Tests whether a given string is an access token
48
42
  *
@@ -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
  *
@@ -90,15 +63,15 @@ exports.sfdc = {
90
63
  */
91
64
  findUpperCaseKeys: (data, sectionBlocklist = []) => {
92
65
  let key;
93
- kit_1.findKey(data, (val, k) => {
66
+ (0, kit_1.findKey)(data, (val, k) => {
94
67
  if (k.substr(0, 1) === k.substr(0, 1).toUpperCase()) {
95
68
  key = k;
96
69
  }
97
- else if (ts_types_1.isJsonMap(val)) {
70
+ else if ((0, ts_types_1.isJsonMap)(val)) {
98
71
  if (sectionBlocklist.includes(k)) {
99
72
  return key;
100
73
  }
101
- key = exports.sfdc.findUpperCaseKeys(ts_types_1.asJsonMap(val));
74
+ key = exports.sfdc.findUpperCaseKeys((0, ts_types_1.asJsonMap)(val));
102
75
  }
103
76
  return key;
104
77
  });
@@ -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,78 @@
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
+ static isValidUrl(input: string | URL): boolean;
13
+ /**
14
+ * Returns the appropriate jwt audience url for this url
15
+ * Use SFDX_AUDIENCE_URL env var to override the audience url
16
+ *
17
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
18
+ * @return {Promise<string>} The audience url
19
+ */
20
+ getJwtAudienceUrl(createdOrgInstance?: string): Promise<string>;
21
+ /**
22
+ * Tests whether this url contains a Salesforce owned domain
23
+ *
24
+ * @return {boolean} true if this is a salesforce domain
25
+ */
26
+ isSalesforceDomain(): boolean;
27
+ /**
28
+ * Tests whether this url is an internal Salesforce domain
29
+ *
30
+ * @returns {boolean} true if this is a internal domain
31
+ */
32
+ isInternalUrl(): boolean;
33
+ /**
34
+ * Tests whether this url runs on a local machine
35
+ *
36
+ * @returns {boolean} true if this is a local machine
37
+ */
38
+ isLocalUrl(): boolean;
39
+ toLightningDomain(): string;
40
+ /**
41
+ * Tests whether this url has the lightning domain extension
42
+ * This method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again until timeout
43
+ * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
44
+ *
45
+ * @returns {Promise<true | never>} The resolved ip address or never
46
+ * @throws {@link SfdxError} If can't resolve DNS.
47
+ */
48
+ checkLightningDomain(): Promise<true | never>;
49
+ /**
50
+ * Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again untill timeout
51
+ * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
52
+ *
53
+ * @returns the resolved ip address.
54
+ * @throws {@link SfdxError} If can't resolve DNS.
55
+ */
56
+ lookup(): Promise<string>;
57
+ /**
58
+ * Tests whether this url is a sandbox url
59
+ *
60
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
61
+ * @returns {boolean}
62
+ */
63
+ isSandboxUrl(createdOrgInstance?: string): boolean;
64
+ /**
65
+ * Test whether this url represents a lightning domain
66
+ *
67
+ * @returns {boolean} true if this domain is a lightning domain
68
+ */
69
+ isLightningDomain(): boolean;
70
+ /**
71
+ * Tests whether this url is a sandbox url
72
+ * otherwise tries to resolve dns cnames and then look if any is sandbox url
73
+ *
74
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
75
+ * @returns {Promise<boolean>} true if this domain resolves to sanbox url
76
+ */
77
+ private resolvesToSandbox;
78
+ }
@@ -0,0 +1,206 @@
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
+ const lifecycleEvents_1 = require("../lifecycleEvents");
16
+ class SfdcUrl extends url_1.URL {
17
+ constructor(input, base) {
18
+ super(input.toString(), base);
19
+ if (this.protocol !== 'https:' && !SfdcUrl.cache.has(this.origin)) {
20
+ SfdcUrl.cache.add(this.origin);
21
+ void lifecycleEvents_1.Lifecycle.getInstance().emitWarning(`Using insecure protocol: ${this.protocol} on url: ${this.origin}`);
22
+ }
23
+ }
24
+ static isValidUrl(input) {
25
+ try {
26
+ new url_1.URL(input.toString());
27
+ return true;
28
+ }
29
+ catch {
30
+ return false;
31
+ }
32
+ }
33
+ /**
34
+ * Returns the appropriate jwt audience url for this url
35
+ * Use SFDX_AUDIENCE_URL env var to override the audience url
36
+ *
37
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
38
+ * @return {Promise<string>} The audience url
39
+ */
40
+ async getJwtAudienceUrl(createdOrgInstance) {
41
+ this.logger = await logger_1.Logger.child('SfdcUrl');
42
+ // environment variable is used as an override
43
+ const envVarVal = new kit_1.Env().getString('SFDX_AUDIENCE_URL', '');
44
+ if (envVarVal) {
45
+ this.logger.debug(`Audience URL overridden by env var SFDX_AUDIENCE_URL=${envVarVal}`);
46
+ return envVarVal;
47
+ }
48
+ if (this.isInternalUrl()) {
49
+ // This is for internal developers when just doing authorize
50
+ return this.origin;
51
+ }
52
+ if (await this.resolvesToSandbox(createdOrgInstance)) {
53
+ return SfdcUrl.SANDBOX;
54
+ }
55
+ if ((createdOrgInstance && /^gs1/gi.test(createdOrgInstance)) || /(gs1.my.salesforce.com)/gi.test(this.origin)) {
56
+ return 'https://gs1.salesforce.com';
57
+ }
58
+ return SfdcUrl.PRODUCTION;
59
+ }
60
+ /**
61
+ * Tests whether this url contains a Salesforce owned domain
62
+ *
63
+ * @return {boolean} true if this is a salesforce domain
64
+ */
65
+ isSalesforceDomain() {
66
+ // Source https://help.salesforce.com/articleView?id=000003652&type=1
67
+ const allowlistOfSalesforceDomainPatterns = [
68
+ '.cloudforce.com',
69
+ '.content.force.com',
70
+ '.force.com',
71
+ '.salesforce.com',
72
+ '.salesforceliveagent.com',
73
+ '.secure.force.com',
74
+ 'crmforce.mil',
75
+ ];
76
+ const allowlistOfSalesforceHosts = ['developer.salesforce.com', 'trailhead.salesforce.com'];
77
+ return allowlistOfSalesforceDomainPatterns.some((pattern) => {
78
+ return this.hostname.endsWith(pattern) || allowlistOfSalesforceHosts.includes(this.hostname);
79
+ });
80
+ }
81
+ /**
82
+ * Tests whether this url is an internal Salesforce domain
83
+ *
84
+ * @returns {boolean} true if this is a internal domain
85
+ */
86
+ isInternalUrl() {
87
+ const INTERNAL_URL_PARTS = [
88
+ '.vpod.',
89
+ 'stm.salesforce.com',
90
+ 'stm.force.com',
91
+ '.blitz.salesforce.com',
92
+ '.stm.salesforce.ms',
93
+ '.pc-rnd.force.com',
94
+ '.pc-rnd.salesforce.com',
95
+ ];
96
+ return (this.origin.startsWith('https://gs1.') ||
97
+ this.isLocalUrl() ||
98
+ INTERNAL_URL_PARTS.some((part) => this.origin.includes(part)));
99
+ }
100
+ /**
101
+ * Tests whether this url runs on a local machine
102
+ *
103
+ * @returns {boolean} true if this is a local machine
104
+ */
105
+ isLocalUrl() {
106
+ const LOCAL_PARTS = ['localhost.sfdcdev.', '.internal.'];
107
+ return LOCAL_PARTS.some((part) => this.origin.includes(part));
108
+ }
109
+ toLightningDomain() {
110
+ if (this.origin.endsWith('.my.salesforce.mil')) {
111
+ return this.origin.replace('.my.salesforce.mil', '.lightning.crmforce.mil');
112
+ }
113
+ // all non-mil domains
114
+ return `https://${(0, ts_types_1.ensureArray)(/https?:\/\/([^.]*)/.exec(this.origin))
115
+ .slice(1, 2)
116
+ .pop()}.lightning.force.com`;
117
+ }
118
+ /**
119
+ * Tests whether this url has the lightning domain extension
120
+ * This method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again until timeout
121
+ * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
122
+ *
123
+ * @returns {Promise<true | never>} The resolved ip address or never
124
+ * @throws {@link SfdxError} If can't resolve DNS.
125
+ */
126
+ async checkLightningDomain() {
127
+ const quantity = (0, ts_types_1.ensureNumber)(new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240));
128
+ const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
129
+ if (this.isInternalUrl() || timeout.seconds === 0) {
130
+ return true;
131
+ }
132
+ const resolver = await myDomainResolver_1.MyDomainResolver.create({
133
+ url: new url_1.URL(this.toLightningDomain()),
134
+ timeout,
135
+ frequency: new kit_1.Duration(1, kit_1.Duration.Unit.SECONDS),
136
+ });
137
+ await resolver.resolve();
138
+ return true;
139
+ }
140
+ /**
141
+ * Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again untill timeout
142
+ * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
143
+ *
144
+ * @returns the resolved ip address.
145
+ * @throws {@link SfdxError} If can't resolve DNS.
146
+ */
147
+ async lookup() {
148
+ const quantity = (0, ts_types_1.ensureNumber)(new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240));
149
+ const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
150
+ const resolver = await myDomainResolver_1.MyDomainResolver.create({
151
+ url: new url_1.URL(this.origin),
152
+ timeout,
153
+ frequency: new kit_1.Duration(1, kit_1.Duration.Unit.SECONDS),
154
+ });
155
+ return resolver.resolve();
156
+ }
157
+ /**
158
+ * Tests whether this url is a sandbox url
159
+ *
160
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
161
+ * @returns {boolean}
162
+ */
163
+ isSandboxUrl(createdOrgInstance) {
164
+ return ((createdOrgInstance && /^cs|s$/gi.test(createdOrgInstance)) ||
165
+ this.origin.endsWith('sandbox.my.salesforce.mil') ||
166
+ /sandbox\.my\.salesforce\.com/gi.test(this.origin) || // enhanced domains >= 230
167
+ /(cs[0-9]+(\.my|)\.salesforce\.com)/gi.test(this.origin) || // my domains on CS instance OR CS instance without my domain
168
+ /([a-z]{3}[0-9]+s\.sfdc-.+\.salesforce\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
169
+ /([a-z]{3}[0-9]+s\.sfdc-.+\.force\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.force.com
170
+ this.hostname === 'test.salesforce.com');
171
+ }
172
+ /**
173
+ * Test whether this url represents a lightning domain
174
+ *
175
+ * @returns {boolean} true if this domain is a lightning domain
176
+ */
177
+ isLightningDomain() {
178
+ return /\.lightning\.force\.com/.test(this.origin);
179
+ }
180
+ /**
181
+ * Tests whether this url is a sandbox url
182
+ * otherwise tries to resolve dns cnames and then look if any is sandbox url
183
+ *
184
+ * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
185
+ * @returns {Promise<boolean>} true if this domain resolves to sanbox url
186
+ */
187
+ async resolvesToSandbox(createdOrgInstance) {
188
+ if (this.isSandboxUrl(createdOrgInstance)) {
189
+ return true;
190
+ }
191
+ const myDomainResolver = await myDomainResolver_1.MyDomainResolver.create({ url: this });
192
+ const cnames = await myDomainResolver.getCnames();
193
+ return cnames.some((cname) => {
194
+ const url = new SfdcUrl(`https://${cname}`);
195
+ return url.isSandboxUrl();
196
+ });
197
+ }
198
+ }
199
+ exports.SfdcUrl = SfdcUrl;
200
+ /**
201
+ * Salesforce URLs
202
+ */
203
+ SfdcUrl.SANDBOX = 'https://test.salesforce.com';
204
+ SfdcUrl.PRODUCTION = 'https://login.salesforce.com';
205
+ SfdcUrl.cache = new Set();
206
+ //# sourceMappingURL=sfdcUrl.js.map
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { pipeline as cbPipeline, Readable, Writable } from 'stream';
3
+ export declare const pipeline: typeof cbPipeline.__promisify__;
4
+ export declare class ZipWriter extends Writable {
5
+ private rootDestination?;
6
+ private zip;
7
+ private buffers;
8
+ constructor(rootDestination?: string | undefined);
9
+ addToZip(contents: string | Readable | Buffer, path: string): void;
10
+ finalize(): Promise<void>;
11
+ private getOutputStream;
12
+ private getInputBuffer;
13
+ get buffer(): Buffer;
14
+ }
@@ -0,0 +1,68 @@
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.ZipWriter = exports.pipeline = void 0;
10
+ const fs_1 = require("fs");
11
+ const stream_1 = require("stream");
12
+ const util_1 = require("util");
13
+ const archiver_1 = require("archiver");
14
+ exports.pipeline = (0, util_1.promisify)(stream_1.pipeline);
15
+ class ZipWriter extends stream_1.Writable {
16
+ constructor(rootDestination) {
17
+ super({ objectMode: true });
18
+ this.rootDestination = rootDestination;
19
+ // compression-/speed+ (0)<---(3)---------->(9) compression+/speed-
20
+ // 3 appears to be a decent balance of compression and speed. It felt like
21
+ // higher values = diminishing returns on compression and made conversion slower
22
+ this.zip = (0, archiver_1.create)('zip', { zlib: { level: 3 } });
23
+ this.buffers = [];
24
+ void (0, exports.pipeline)(this.zip, this.getOutputStream());
25
+ }
26
+ addToZip(contents, path) {
27
+ this.zip.append(contents, { name: path });
28
+ }
29
+ async finalize() {
30
+ await this.zip.finalize();
31
+ await this.getInputBuffer();
32
+ }
33
+ getOutputStream() {
34
+ if (this.rootDestination) {
35
+ return (0, fs_1.createWriteStream)(this.rootDestination);
36
+ }
37
+ else {
38
+ const bufferWritable = new stream_1.Writable();
39
+ // eslint-disable-next-line no-underscore-dangle
40
+ bufferWritable._write = (chunk, encoding, cb) => {
41
+ this.buffers.push(chunk);
42
+ cb();
43
+ };
44
+ return bufferWritable;
45
+ }
46
+ }
47
+ async getInputBuffer() {
48
+ if (this.rootDestination) {
49
+ const inputStream = (0, fs_1.createReadStream)(this.rootDestination);
50
+ return new Promise((resolve, reject) => {
51
+ inputStream.on('data', (chunk) => {
52
+ this.buffers.push(chunk);
53
+ });
54
+ inputStream.once('end', () => {
55
+ return resolve();
56
+ });
57
+ inputStream.once('error', (error) => {
58
+ return reject(error);
59
+ });
60
+ });
61
+ }
62
+ }
63
+ get buffer() {
64
+ return Buffer.concat(this.buffers);
65
+ }
66
+ }
67
+ exports.ZipWriter = ZipWriter;
68
+ //# sourceMappingURL=zipWriter.js.map
@@ -1,8 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import * as http from 'http';
3
3
  import { AsyncCreatable } from '@salesforce/kit';
4
- import { OAuth2Options } from 'jsforce';
5
- import { AuthInfo } from './org/authInfo';
4
+ import { AuthInfo, OAuth2Config } from './org/authInfo';
6
5
  /**
7
6
  * Handles the creation of a web server for web based login flows.
8
7
  *
@@ -80,7 +79,7 @@ export declare class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Option
80
79
  }
81
80
  export declare namespace WebOAuthServer {
82
81
  interface Options {
83
- oauthConfig: OAuth2Options;
82
+ oauthConfig: OAuth2Config;
84
83
  }
85
84
  type Request = http.IncomingMessage & {
86
85
  query: {