@salesforce/core 3.30.14 → 3.31.7
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/LICENSE.txt +11 -11
- package/README.md +222 -227
- package/lib/config/aliasesConfig.d.ts +12 -12
- package/lib/config/aliasesConfig.js +27 -27
- package/lib/config/authInfoConfig.d.ts +19 -19
- package/lib/config/authInfoConfig.js +34 -34
- package/lib/config/config.d.ts +311 -311
- package/lib/config/config.js +574 -574
- package/lib/config/configAggregator.d.ts +232 -232
- package/lib/config/configAggregator.js +379 -379
- package/lib/config/configFile.d.ts +199 -199
- package/lib/config/configFile.js +340 -340
- package/lib/config/configGroup.d.ts +141 -141
- package/lib/config/configGroup.js +224 -224
- package/lib/config/configStore.d.ts +241 -241
- package/lib/config/configStore.js +352 -352
- package/lib/config/envVars.d.ts +101 -101
- package/lib/config/envVars.js +456 -456
- package/lib/config/orgUsersConfig.d.ts +31 -31
- package/lib/config/orgUsersConfig.js +41 -41
- package/lib/config/sandboxOrgConfig.d.ts +37 -37
- package/lib/config/sandboxOrgConfig.js +50 -50
- package/lib/config/sandboxProcessCache.d.ts +16 -16
- package/lib/config/sandboxProcessCache.js +37 -37
- package/lib/config/tokensConfig.d.ts +10 -10
- package/lib/config/tokensConfig.js +28 -28
- package/lib/config/ttlConfig.d.ts +34 -34
- package/lib/config/ttlConfig.js +54 -54
- package/lib/crypto/crypto.d.ts +54 -54
- package/lib/crypto/crypto.js +220 -220
- package/lib/crypto/keyChain.d.ts +8 -8
- package/lib/crypto/keyChain.js +61 -61
- package/lib/crypto/keyChainImpl.d.ts +116 -116
- package/lib/crypto/keyChainImpl.js +486 -486
- package/lib/crypto/secureBuffer.d.ts +46 -46
- package/lib/crypto/secureBuffer.js +82 -82
- package/lib/deviceOauthService.d.ts +71 -71
- package/lib/deviceOauthService.js +191 -191
- package/lib/exported.d.ts +38 -38
- package/lib/exported.js +118 -118
- package/lib/global.d.ts +70 -70
- package/lib/global.js +109 -109
- package/lib/lifecycleEvents.d.ts +93 -93
- package/lib/lifecycleEvents.js +188 -188
- package/lib/logger.d.ts +381 -381
- package/lib/logger.js +734 -734
- package/lib/messages.d.ts +291 -291
- package/lib/messages.js +543 -543
- package/lib/org/authInfo.d.ts +344 -344
- package/lib/org/authInfo.js +892 -892
- package/lib/org/authRemover.d.ts +88 -88
- package/lib/org/authRemover.js +182 -182
- package/lib/org/connection.d.ts +197 -197
- package/lib/org/connection.js +395 -395
- package/lib/org/index.d.ts +6 -6
- package/lib/org/index.js +28 -28
- package/lib/org/org.d.ts +558 -558
- package/lib/org/org.js +1267 -1267
- package/lib/org/orgConfigProperties.d.ts +69 -69
- package/lib/org/orgConfigProperties.js +136 -136
- package/lib/org/permissionSetAssignment.d.ts +35 -35
- package/lib/org/permissionSetAssignment.js +125 -125
- package/lib/org/scratchOrgCache.d.ts +20 -20
- package/lib/org/scratchOrgCache.js +32 -32
- package/lib/org/scratchOrgCreate.d.ts +54 -54
- package/lib/org/scratchOrgCreate.js +216 -216
- package/lib/org/scratchOrgErrorCodes.d.ts +10 -10
- package/lib/org/scratchOrgErrorCodes.js +88 -88
- package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -26
- package/lib/org/scratchOrgFeatureDeprecation.js +109 -109
- package/lib/org/scratchOrgInfoApi.d.ts +68 -68
- package/lib/org/scratchOrgInfoApi.js +413 -413
- package/lib/org/scratchOrgInfoGenerator.d.ts +64 -64
- package/lib/org/scratchOrgInfoGenerator.js +241 -241
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -10
- package/lib/org/scratchOrgLifecycleEvents.js +40 -40
- package/lib/org/scratchOrgSettingsGenerator.d.ts +78 -78
- package/lib/org/scratchOrgSettingsGenerator.js +276 -276
- package/lib/org/scratchOrgTypes.d.ts +43 -43
- package/lib/org/scratchOrgTypes.js +8 -8
- package/lib/org/user.d.ts +187 -187
- package/lib/org/user.js +448 -448
- package/lib/schema/printer.d.ts +79 -79
- package/lib/schema/printer.js +260 -260
- package/lib/schema/validator.d.ts +70 -70
- package/lib/schema/validator.js +169 -169
- package/lib/sfError.d.ts +73 -73
- package/lib/sfError.js +136 -136
- package/lib/sfProject.d.ts +357 -357
- package/lib/sfProject.js +671 -671
- package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -98
- package/lib/stateAggregator/accessors/aliasAccessor.js +145 -145
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -101
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -240
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -8
- package/lib/stateAggregator/accessors/sandboxAccessor.js +27 -27
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -63
- package/lib/stateAggregator/accessors/tokenAccessor.js +79 -79
- package/lib/stateAggregator/index.d.ts +4 -4
- package/lib/stateAggregator/index.js +26 -26
- package/lib/stateAggregator/stateAggregator.d.ts +25 -25
- package/lib/stateAggregator/stateAggregator.js +45 -45
- package/lib/status/myDomainResolver.d.ts +66 -66
- package/lib/status/myDomainResolver.js +124 -124
- package/lib/status/pollingClient.d.ts +85 -85
- package/lib/status/pollingClient.js +115 -115
- package/lib/status/streamingClient.d.ts +244 -244
- package/lib/status/streamingClient.js +436 -436
- package/lib/status/types.d.ts +89 -89
- package/lib/status/types.js +17 -17
- package/lib/testSetup.d.ts +553 -530
- package/lib/testSetup.js +871 -727
- package/lib/util/cache.d.ts +11 -11
- package/lib/util/cache.js +69 -69
- package/lib/util/checkLightningDomain.d.ts +1 -1
- package/lib/util/checkLightningDomain.js +28 -28
- package/lib/util/directoryWriter.d.ts +12 -12
- package/lib/util/directoryWriter.js +53 -53
- package/lib/util/getJwtAudienceUrl.d.ts +4 -4
- package/lib/util/getJwtAudienceUrl.js +18 -18
- package/lib/util/internal.d.ts +58 -58
- package/lib/util/internal.js +118 -118
- package/lib/util/jsonXmlTools.d.ts +14 -14
- package/lib/util/jsonXmlTools.js +38 -38
- package/lib/util/mapKeys.d.ts +14 -14
- package/lib/util/mapKeys.js +51 -51
- package/lib/util/sfdc.d.ts +52 -52
- package/lib/util/sfdc.js +85 -85
- package/lib/util/sfdcUrl.d.ts +72 -72
- package/lib/util/sfdcUrl.js +215 -215
- package/lib/util/structuredWriter.d.ts +9 -9
- package/lib/util/structuredWriter.js +2 -2
- package/lib/util/zipWriter.d.ts +16 -16
- package/lib/util/zipWriter.js +67 -67
- package/lib/webOAuthServer.d.ts +156 -156
- package/lib/webOAuthServer.js +388 -388
- package/messages/auth.md +37 -37
- package/messages/config.md +156 -156
- package/messages/connection.md +30 -30
- package/messages/core.json +20 -20
- package/messages/core.md +67 -67
- package/messages/encryption.md +85 -85
- package/messages/envVars.md +303 -303
- package/messages/org.md +63 -63
- package/messages/permissionSetAssignment.md +31 -31
- package/messages/scratchOrgCreate.md +23 -23
- package/messages/scratchOrgErrorCodes.md +115 -115
- package/messages/scratchOrgFeatureDeprecation.md +11 -11
- package/messages/scratchOrgInfoApi.md +15 -15
- package/messages/scratchOrgInfoGenerator.md +23 -23
- package/messages/streaming.md +23 -23
- package/messages/user.md +35 -35
- package/package.json +97 -97
package/lib/util/sfdcUrl.js
CHANGED
|
@@ -1,216 +1,216 @@
|
|
|
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 = exports.getLoginAudienceCombos = 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
|
-
function getLoginAudienceCombos(audienceUrl, loginUrl) {
|
|
17
|
-
const filtered = [
|
|
18
|
-
[loginUrl, loginUrl],
|
|
19
|
-
[SfdcUrl.SANDBOX, SfdcUrl.SANDBOX],
|
|
20
|
-
[SfdcUrl.PRODUCTION, SfdcUrl.PRODUCTION],
|
|
21
|
-
[audienceUrl, audienceUrl],
|
|
22
|
-
[audienceUrl, SfdcUrl.PRODUCTION],
|
|
23
|
-
[audienceUrl, SfdcUrl.SANDBOX],
|
|
24
|
-
[loginUrl, audienceUrl],
|
|
25
|
-
[loginUrl, SfdcUrl.PRODUCTION],
|
|
26
|
-
[loginUrl, SfdcUrl.SANDBOX],
|
|
27
|
-
[SfdcUrl.PRODUCTION, audienceUrl],
|
|
28
|
-
[SfdcUrl.SANDBOX, audienceUrl],
|
|
29
|
-
].filter(([login, audience]) => !((login === SfdcUrl.PRODUCTION && audience === SfdcUrl.SANDBOX) ||
|
|
30
|
-
(login === SfdcUrl.SANDBOX && audience === SfdcUrl.PRODUCTION)));
|
|
31
|
-
const reduced = filtered.reduce((acc, [login, audience]) => {
|
|
32
|
-
const l = new url_1.URL(login);
|
|
33
|
-
const a = new url_1.URL(audience);
|
|
34
|
-
acc.set(`${l.origin}:${a.origin}`, [login, audience]);
|
|
35
|
-
return acc;
|
|
36
|
-
}, new Map());
|
|
37
|
-
return [...reduced.values()];
|
|
38
|
-
}
|
|
39
|
-
exports.getLoginAudienceCombos = getLoginAudienceCombos;
|
|
40
|
-
class SfdcUrl extends url_1.URL {
|
|
41
|
-
constructor(input, base) {
|
|
42
|
-
super(input.toString(), base);
|
|
43
|
-
if (this.protocol !== 'https:' && !SfdcUrl.cache.has(this.origin)) {
|
|
44
|
-
SfdcUrl.cache.add(this.origin);
|
|
45
|
-
void lifecycleEvents_1.Lifecycle.getInstance().emitWarning(`Using insecure protocol: ${this.protocol} on url: ${this.origin}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
static isValidUrl(input) {
|
|
49
|
-
try {
|
|
50
|
-
new url_1.URL(input.toString());
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Returns the appropriate jwt audience url for this url
|
|
59
|
-
* Use SFDX_AUDIENCE_URL env var to override the audience url
|
|
60
|
-
*
|
|
61
|
-
* @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
|
|
62
|
-
* @return {Promise<string>} The audience url
|
|
63
|
-
*/
|
|
64
|
-
async getJwtAudienceUrl(createdOrgInstance) {
|
|
65
|
-
this.logger = await logger_1.Logger.child('SfdcUrl');
|
|
66
|
-
// environment variable is used as an override
|
|
67
|
-
const envVarVal = new kit_1.Env().getString('SFDX_AUDIENCE_URL', '');
|
|
68
|
-
if (envVarVal) {
|
|
69
|
-
this.logger.debug(`Audience URL overridden by env var SFDX_AUDIENCE_URL=${envVarVal}`);
|
|
70
|
-
return envVarVal;
|
|
71
|
-
}
|
|
72
|
-
if ((createdOrgInstance && /^gs1/gi.test(createdOrgInstance)) || /(gs1.my.salesforce.com)/gi.test(this.origin)) {
|
|
73
|
-
return 'https://gs1.salesforce.com';
|
|
74
|
-
}
|
|
75
|
-
return SfdcUrl.PRODUCTION;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Tests whether this url contains a Salesforce owned domain
|
|
79
|
-
*
|
|
80
|
-
* @return {boolean} true if this is a salesforce domain
|
|
81
|
-
*/
|
|
82
|
-
isSalesforceDomain() {
|
|
83
|
-
// Source https://help.salesforce.com/articleView?id=000003652&type=1
|
|
84
|
-
const allowlistOfSalesforceDomainPatterns = [
|
|
85
|
-
'.cloudforce.com',
|
|
86
|
-
'.content.force.com',
|
|
87
|
-
'.force.com',
|
|
88
|
-
'.salesforce.com',
|
|
89
|
-
'.salesforceliveagent.com',
|
|
90
|
-
'.secure.force.com',
|
|
91
|
-
'crmforce.mil',
|
|
92
|
-
];
|
|
93
|
-
const allowlistOfSalesforceHosts = ['developer.salesforce.com', 'trailhead.salesforce.com'];
|
|
94
|
-
return allowlistOfSalesforceDomainPatterns.some((pattern) => this.hostname.endsWith(pattern) || allowlistOfSalesforceHosts.includes(this.hostname));
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Tests whether this url is an internal Salesforce domain
|
|
98
|
-
*
|
|
99
|
-
* @returns {boolean} true if this is an internal domain
|
|
100
|
-
*/
|
|
101
|
-
isInternalUrl() {
|
|
102
|
-
const INTERNAL_URL_PARTS = [
|
|
103
|
-
'.vpod.',
|
|
104
|
-
'stm.salesforce.com',
|
|
105
|
-
'stm.force.com',
|
|
106
|
-
'.blitz.salesforce.com',
|
|
107
|
-
'.stm.salesforce.ms',
|
|
108
|
-
'.pc-rnd.force.com',
|
|
109
|
-
'.pc-rnd.salesforce.com',
|
|
110
|
-
];
|
|
111
|
-
return (this.origin.startsWith('https://gs1.') ||
|
|
112
|
-
this.isLocalUrl() ||
|
|
113
|
-
INTERNAL_URL_PARTS.some((part) => this.origin.includes(part)));
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Tests whether this url runs on a local machine
|
|
117
|
-
*
|
|
118
|
-
* @returns {boolean} true if this is a local machine
|
|
119
|
-
*/
|
|
120
|
-
isLocalUrl() {
|
|
121
|
-
const LOCAL_PARTS = ['localhost.sfdcdev.', '.internal.'];
|
|
122
|
-
return LOCAL_PARTS.some((part) => this.origin.includes(part));
|
|
123
|
-
}
|
|
124
|
-
toLightningDomain() {
|
|
125
|
-
if (this.origin.endsWith('.my.salesforce.mil')) {
|
|
126
|
-
return this.origin.replace('.my.salesforce.mil', '.lightning.crmforce.mil');
|
|
127
|
-
}
|
|
128
|
-
// enhanced domains
|
|
129
|
-
// ex: sandbox.my.salesforce.com, scratch.my.salesforce.com, etc
|
|
130
|
-
if (this.origin.endsWith('.my.salesforce.com')) {
|
|
131
|
-
return this.origin.replace('.my.salesforce.com', '.lightning.force.com');
|
|
132
|
-
}
|
|
133
|
-
// alternative domains
|
|
134
|
-
if (this.origin.endsWith('.my-salesforce.com')) {
|
|
135
|
-
return this.origin.replace('.my-salesforce.com', '.my-lightning.com');
|
|
136
|
-
}
|
|
137
|
-
// all non-mil domains
|
|
138
|
-
return `https://${(0, ts_types_1.ensureArray)(/https?:\/\/([^.]*)/.exec(this.origin))
|
|
139
|
-
.slice(1, 2)
|
|
140
|
-
.pop()}.lightning.force.com`;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Tests whether this url has the lightning domain extension
|
|
144
|
-
* 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
|
|
145
|
-
* If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
|
|
146
|
-
*
|
|
147
|
-
* @returns {Promise<true | never>} The resolved ip address or never
|
|
148
|
-
* @throws {@link SfError} If can't resolve DNS.
|
|
149
|
-
*/
|
|
150
|
-
async checkLightningDomain() {
|
|
151
|
-
const quantity = (0, ts_types_1.ensureNumber)(new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240));
|
|
152
|
-
const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
|
|
153
|
-
if (this.isInternalUrl() || timeout.seconds === 0) {
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
const resolver = await myDomainResolver_1.MyDomainResolver.create({
|
|
157
|
-
url: new url_1.URL(this.toLightningDomain()),
|
|
158
|
-
timeout,
|
|
159
|
-
frequency: new kit_1.Duration(1, kit_1.Duration.Unit.SECONDS),
|
|
160
|
-
});
|
|
161
|
-
await resolver.resolve();
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again until timeout
|
|
166
|
-
* If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
|
|
167
|
-
*
|
|
168
|
-
* @returns the resolved ip address.
|
|
169
|
-
* @throws {@link SfError} If can't resolve DNS.
|
|
170
|
-
*/
|
|
171
|
-
async lookup() {
|
|
172
|
-
const quantity = (0, ts_types_1.ensureNumber)(new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240));
|
|
173
|
-
const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
|
|
174
|
-
const resolver = await myDomainResolver_1.MyDomainResolver.create({
|
|
175
|
-
url: new url_1.URL(this.origin),
|
|
176
|
-
timeout,
|
|
177
|
-
frequency: new kit_1.Duration(1, kit_1.Duration.Unit.SECONDS),
|
|
178
|
-
});
|
|
179
|
-
return resolver.resolve();
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Tests whether this url is a sandbox url
|
|
183
|
-
*
|
|
184
|
-
* @Deprecated - identification of a sandbox instance by URL alone is not deterministic
|
|
185
|
-
* @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
|
|
186
|
-
* @returns {boolean}
|
|
187
|
-
*/
|
|
188
|
-
// TODO: how to get rid of this?
|
|
189
|
-
isSandboxUrl(createdOrgInstance) {
|
|
190
|
-
return ((createdOrgInstance && /^cs|s$/gi.test(createdOrgInstance)) ||
|
|
191
|
-
this.origin.endsWith('sandbox.my.salesforce.mil') ||
|
|
192
|
-
/sandbox\.my\.salesforce\.com/gi.test(this.origin) || // enhanced domains >= 230
|
|
193
|
-
/(cs[0-9]+(\.my|)\.salesforce\.com)/gi.test(this.origin) || // my domains on CS instance OR CS instance without my domain
|
|
194
|
-
/(cs[0-9]+\.force\.com)/gi.test(this.origin) || // sandboxes have cnames like cs123.force.com
|
|
195
|
-
/(\w+--\w+\.my\.salesforce\.com)/gi.test(this.origin) || // sandboxes myDomain like foo--bar.my.salesforce.com
|
|
196
|
-
/([a-z]{3}[0-9]+s\.sfdc-.+\.salesforce\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
|
|
197
|
-
/([a-z]{3}[0-9]+s\.sfdc-.+\.force\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.force.com
|
|
198
|
-
this.hostname === 'test.salesforce.com');
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Test whether this url represents a lightning domain
|
|
202
|
-
*
|
|
203
|
-
* @returns {boolean} true if this domain is a lightning domain
|
|
204
|
-
*/
|
|
205
|
-
isLightningDomain() {
|
|
206
|
-
return this.origin.includes('.lightning.force.com') || this.origin.includes('.lightning.crmforce.mil');
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
exports.SfdcUrl = SfdcUrl;
|
|
210
|
-
/**
|
|
211
|
-
* Salesforce URLs
|
|
212
|
-
*/
|
|
213
|
-
SfdcUrl.SANDBOX = 'https://test.salesforce.com';
|
|
214
|
-
SfdcUrl.PRODUCTION = 'https://login.salesforce.com';
|
|
215
|
-
SfdcUrl.cache = new Set();
|
|
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 = exports.getLoginAudienceCombos = 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
|
+
function getLoginAudienceCombos(audienceUrl, loginUrl) {
|
|
17
|
+
const filtered = [
|
|
18
|
+
[loginUrl, loginUrl],
|
|
19
|
+
[SfdcUrl.SANDBOX, SfdcUrl.SANDBOX],
|
|
20
|
+
[SfdcUrl.PRODUCTION, SfdcUrl.PRODUCTION],
|
|
21
|
+
[audienceUrl, audienceUrl],
|
|
22
|
+
[audienceUrl, SfdcUrl.PRODUCTION],
|
|
23
|
+
[audienceUrl, SfdcUrl.SANDBOX],
|
|
24
|
+
[loginUrl, audienceUrl],
|
|
25
|
+
[loginUrl, SfdcUrl.PRODUCTION],
|
|
26
|
+
[loginUrl, SfdcUrl.SANDBOX],
|
|
27
|
+
[SfdcUrl.PRODUCTION, audienceUrl],
|
|
28
|
+
[SfdcUrl.SANDBOX, audienceUrl],
|
|
29
|
+
].filter(([login, audience]) => !((login === SfdcUrl.PRODUCTION && audience === SfdcUrl.SANDBOX) ||
|
|
30
|
+
(login === SfdcUrl.SANDBOX && audience === SfdcUrl.PRODUCTION)));
|
|
31
|
+
const reduced = filtered.reduce((acc, [login, audience]) => {
|
|
32
|
+
const l = new url_1.URL(login);
|
|
33
|
+
const a = new url_1.URL(audience);
|
|
34
|
+
acc.set(`${l.origin}:${a.origin}`, [login, audience]);
|
|
35
|
+
return acc;
|
|
36
|
+
}, new Map());
|
|
37
|
+
return [...reduced.values()];
|
|
38
|
+
}
|
|
39
|
+
exports.getLoginAudienceCombos = getLoginAudienceCombos;
|
|
40
|
+
class SfdcUrl extends url_1.URL {
|
|
41
|
+
constructor(input, base) {
|
|
42
|
+
super(input.toString(), base);
|
|
43
|
+
if (this.protocol !== 'https:' && !SfdcUrl.cache.has(this.origin)) {
|
|
44
|
+
SfdcUrl.cache.add(this.origin);
|
|
45
|
+
void lifecycleEvents_1.Lifecycle.getInstance().emitWarning(`Using insecure protocol: ${this.protocol} on url: ${this.origin}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
static isValidUrl(input) {
|
|
49
|
+
try {
|
|
50
|
+
new url_1.URL(input.toString());
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns the appropriate jwt audience url for this url
|
|
59
|
+
* Use SFDX_AUDIENCE_URL env var to override the audience url
|
|
60
|
+
*
|
|
61
|
+
* @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
|
|
62
|
+
* @return {Promise<string>} The audience url
|
|
63
|
+
*/
|
|
64
|
+
async getJwtAudienceUrl(createdOrgInstance) {
|
|
65
|
+
this.logger = await logger_1.Logger.child('SfdcUrl');
|
|
66
|
+
// environment variable is used as an override
|
|
67
|
+
const envVarVal = new kit_1.Env().getString('SFDX_AUDIENCE_URL', '');
|
|
68
|
+
if (envVarVal) {
|
|
69
|
+
this.logger.debug(`Audience URL overridden by env var SFDX_AUDIENCE_URL=${envVarVal}`);
|
|
70
|
+
return envVarVal;
|
|
71
|
+
}
|
|
72
|
+
if ((createdOrgInstance && /^gs1/gi.test(createdOrgInstance)) || /(gs1.my.salesforce.com)/gi.test(this.origin)) {
|
|
73
|
+
return 'https://gs1.salesforce.com';
|
|
74
|
+
}
|
|
75
|
+
return SfdcUrl.PRODUCTION;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Tests whether this url contains a Salesforce owned domain
|
|
79
|
+
*
|
|
80
|
+
* @return {boolean} true if this is a salesforce domain
|
|
81
|
+
*/
|
|
82
|
+
isSalesforceDomain() {
|
|
83
|
+
// Source https://help.salesforce.com/articleView?id=000003652&type=1
|
|
84
|
+
const allowlistOfSalesforceDomainPatterns = [
|
|
85
|
+
'.cloudforce.com',
|
|
86
|
+
'.content.force.com',
|
|
87
|
+
'.force.com',
|
|
88
|
+
'.salesforce.com',
|
|
89
|
+
'.salesforceliveagent.com',
|
|
90
|
+
'.secure.force.com',
|
|
91
|
+
'crmforce.mil',
|
|
92
|
+
];
|
|
93
|
+
const allowlistOfSalesforceHosts = ['developer.salesforce.com', 'trailhead.salesforce.com'];
|
|
94
|
+
return allowlistOfSalesforceDomainPatterns.some((pattern) => this.hostname.endsWith(pattern) || allowlistOfSalesforceHosts.includes(this.hostname));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Tests whether this url is an internal Salesforce domain
|
|
98
|
+
*
|
|
99
|
+
* @returns {boolean} true if this is an internal domain
|
|
100
|
+
*/
|
|
101
|
+
isInternalUrl() {
|
|
102
|
+
const INTERNAL_URL_PARTS = [
|
|
103
|
+
'.vpod.',
|
|
104
|
+
'stm.salesforce.com',
|
|
105
|
+
'stm.force.com',
|
|
106
|
+
'.blitz.salesforce.com',
|
|
107
|
+
'.stm.salesforce.ms',
|
|
108
|
+
'.pc-rnd.force.com',
|
|
109
|
+
'.pc-rnd.salesforce.com',
|
|
110
|
+
];
|
|
111
|
+
return (this.origin.startsWith('https://gs1.') ||
|
|
112
|
+
this.isLocalUrl() ||
|
|
113
|
+
INTERNAL_URL_PARTS.some((part) => this.origin.includes(part)));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Tests whether this url runs on a local machine
|
|
117
|
+
*
|
|
118
|
+
* @returns {boolean} true if this is a local machine
|
|
119
|
+
*/
|
|
120
|
+
isLocalUrl() {
|
|
121
|
+
const LOCAL_PARTS = ['localhost.sfdcdev.', '.internal.'];
|
|
122
|
+
return LOCAL_PARTS.some((part) => this.origin.includes(part));
|
|
123
|
+
}
|
|
124
|
+
toLightningDomain() {
|
|
125
|
+
if (this.origin.endsWith('.my.salesforce.mil')) {
|
|
126
|
+
return this.origin.replace('.my.salesforce.mil', '.lightning.crmforce.mil');
|
|
127
|
+
}
|
|
128
|
+
// enhanced domains
|
|
129
|
+
// ex: sandbox.my.salesforce.com, scratch.my.salesforce.com, etc
|
|
130
|
+
if (this.origin.endsWith('.my.salesforce.com')) {
|
|
131
|
+
return this.origin.replace('.my.salesforce.com', '.lightning.force.com');
|
|
132
|
+
}
|
|
133
|
+
// alternative domains
|
|
134
|
+
if (this.origin.endsWith('.my-salesforce.com')) {
|
|
135
|
+
return this.origin.replace('.my-salesforce.com', '.my-lightning.com');
|
|
136
|
+
}
|
|
137
|
+
// all non-mil domains
|
|
138
|
+
return `https://${(0, ts_types_1.ensureArray)(/https?:\/\/([^.]*)/.exec(this.origin))
|
|
139
|
+
.slice(1, 2)
|
|
140
|
+
.pop()}.lightning.force.com`;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Tests whether this url has the lightning domain extension
|
|
144
|
+
* 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
|
|
145
|
+
* If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
|
|
146
|
+
*
|
|
147
|
+
* @returns {Promise<true | never>} The resolved ip address or never
|
|
148
|
+
* @throws {@link SfError} If can't resolve DNS.
|
|
149
|
+
*/
|
|
150
|
+
async checkLightningDomain() {
|
|
151
|
+
const quantity = (0, ts_types_1.ensureNumber)(new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240));
|
|
152
|
+
const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
|
|
153
|
+
if (this.isInternalUrl() || timeout.seconds === 0) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
const resolver = await myDomainResolver_1.MyDomainResolver.create({
|
|
157
|
+
url: new url_1.URL(this.toLightningDomain()),
|
|
158
|
+
timeout,
|
|
159
|
+
frequency: new kit_1.Duration(1, kit_1.Duration.Unit.SECONDS),
|
|
160
|
+
});
|
|
161
|
+
await resolver.resolve();
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again until timeout
|
|
166
|
+
* If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
|
|
167
|
+
*
|
|
168
|
+
* @returns the resolved ip address.
|
|
169
|
+
* @throws {@link SfError} If can't resolve DNS.
|
|
170
|
+
*/
|
|
171
|
+
async lookup() {
|
|
172
|
+
const quantity = (0, ts_types_1.ensureNumber)(new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240));
|
|
173
|
+
const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
|
|
174
|
+
const resolver = await myDomainResolver_1.MyDomainResolver.create({
|
|
175
|
+
url: new url_1.URL(this.origin),
|
|
176
|
+
timeout,
|
|
177
|
+
frequency: new kit_1.Duration(1, kit_1.Duration.Unit.SECONDS),
|
|
178
|
+
});
|
|
179
|
+
return resolver.resolve();
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Tests whether this url is a sandbox url
|
|
183
|
+
*
|
|
184
|
+
* @Deprecated - identification of a sandbox instance by URL alone is not deterministic
|
|
185
|
+
* @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
|
|
186
|
+
* @returns {boolean}
|
|
187
|
+
*/
|
|
188
|
+
// TODO: how to get rid of this?
|
|
189
|
+
isSandboxUrl(createdOrgInstance) {
|
|
190
|
+
return ((createdOrgInstance && /^cs|s$/gi.test(createdOrgInstance)) ||
|
|
191
|
+
this.origin.endsWith('sandbox.my.salesforce.mil') ||
|
|
192
|
+
/sandbox\.my\.salesforce\.com/gi.test(this.origin) || // enhanced domains >= 230
|
|
193
|
+
/(cs[0-9]+(\.my|)\.salesforce\.com)/gi.test(this.origin) || // my domains on CS instance OR CS instance without my domain
|
|
194
|
+
/(cs[0-9]+\.force\.com)/gi.test(this.origin) || // sandboxes have cnames like cs123.force.com
|
|
195
|
+
/(\w+--\w+\.my\.salesforce\.com)/gi.test(this.origin) || // sandboxes myDomain like foo--bar.my.salesforce.com
|
|
196
|
+
/([a-z]{3}[0-9]+s\.sfdc-.+\.salesforce\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
|
|
197
|
+
/([a-z]{3}[0-9]+s\.sfdc-.+\.force\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.force.com
|
|
198
|
+
this.hostname === 'test.salesforce.com');
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Test whether this url represents a lightning domain
|
|
202
|
+
*
|
|
203
|
+
* @returns {boolean} true if this domain is a lightning domain
|
|
204
|
+
*/
|
|
205
|
+
isLightningDomain() {
|
|
206
|
+
return this.origin.includes('.lightning.force.com') || this.origin.includes('.lightning.crmforce.mil');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.SfdcUrl = SfdcUrl;
|
|
210
|
+
/**
|
|
211
|
+
* Salesforce URLs
|
|
212
|
+
*/
|
|
213
|
+
SfdcUrl.SANDBOX = 'https://test.salesforce.com';
|
|
214
|
+
SfdcUrl.PRODUCTION = 'https://login.salesforce.com';
|
|
215
|
+
SfdcUrl.cache = new Set();
|
|
216
216
|
//# sourceMappingURL=sfdcUrl.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { Readable } from 'stream';
|
|
4
|
-
export interface StructuredWriter {
|
|
5
|
-
addToStore(contents: string | Readable | Buffer, path: string): Promise<void>;
|
|
6
|
-
finalize(): Promise<void>;
|
|
7
|
-
getDestinationPath(): string | undefined;
|
|
8
|
-
get buffer(): Buffer;
|
|
9
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
export interface StructuredWriter {
|
|
5
|
+
addToStore(contents: string | Readable | Buffer, path: string): Promise<void>;
|
|
6
|
+
finalize(): Promise<void>;
|
|
7
|
+
getDestinationPath(): string | undefined;
|
|
8
|
+
get buffer(): Buffer;
|
|
9
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=structuredWriter.js.map
|
package/lib/util/zipWriter.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { Readable, Writable } from 'stream';
|
|
4
|
-
import { StructuredWriter } from './structuredWriter';
|
|
5
|
-
export declare class ZipWriter extends Writable implements StructuredWriter {
|
|
6
|
-
private readonly rootDestination?;
|
|
7
|
-
private zip;
|
|
8
|
-
private buffers;
|
|
9
|
-
constructor(rootDestination?: string | undefined);
|
|
10
|
-
get buffer(): Buffer;
|
|
11
|
-
addToStore(contents: string | Readable | Buffer, path: string): Promise<void>;
|
|
12
|
-
finalize(): Promise<void>;
|
|
13
|
-
getDestinationPath(): string | undefined;
|
|
14
|
-
private getOutputStream;
|
|
15
|
-
private getInputBuffer;
|
|
16
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable, Writable } from 'stream';
|
|
4
|
+
import { StructuredWriter } from './structuredWriter';
|
|
5
|
+
export declare class ZipWriter extends Writable implements StructuredWriter {
|
|
6
|
+
private readonly rootDestination?;
|
|
7
|
+
private zip;
|
|
8
|
+
private buffers;
|
|
9
|
+
constructor(rootDestination?: string | undefined);
|
|
10
|
+
get buffer(): Buffer;
|
|
11
|
+
addToStore(contents: string | Readable | Buffer, path: string): Promise<void>;
|
|
12
|
+
finalize(): Promise<void>;
|
|
13
|
+
getDestinationPath(): string | undefined;
|
|
14
|
+
private getOutputStream;
|
|
15
|
+
private getInputBuffer;
|
|
16
|
+
}
|
package/lib/util/zipWriter.js
CHANGED
|
@@ -1,68 +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 = 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
|
-
const 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 pipeline(this.zip, this.getOutputStream());
|
|
25
|
-
}
|
|
26
|
-
get buffer() {
|
|
27
|
-
return Buffer.concat(this.buffers);
|
|
28
|
-
}
|
|
29
|
-
async addToStore(contents, path) {
|
|
30
|
-
this.zip.append(contents, { name: path });
|
|
31
|
-
return Promise.resolve();
|
|
32
|
-
}
|
|
33
|
-
async finalize() {
|
|
34
|
-
await this.zip.finalize();
|
|
35
|
-
await this.getInputBuffer();
|
|
36
|
-
}
|
|
37
|
-
getDestinationPath() {
|
|
38
|
-
return this.rootDestination;
|
|
39
|
-
}
|
|
40
|
-
getOutputStream() {
|
|
41
|
-
if (this.rootDestination) {
|
|
42
|
-
return (0, fs_1.createWriteStream)(this.rootDestination);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const bufferWritable = new stream_1.Writable();
|
|
46
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
47
|
-
bufferWritable._write = (chunk, encoding, cb) => {
|
|
48
|
-
this.buffers.push(chunk);
|
|
49
|
-
cb();
|
|
50
|
-
};
|
|
51
|
-
return bufferWritable;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async getInputBuffer() {
|
|
55
|
-
if (this.rootDestination) {
|
|
56
|
-
const inputStream = (0, fs_1.createReadStream)(this.rootDestination);
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
inputStream.on('data', (chunk) => {
|
|
59
|
-
this.buffers.push(chunk);
|
|
60
|
-
});
|
|
61
|
-
inputStream.once('end', () => resolve());
|
|
62
|
-
inputStream.once('error', (error) => reject(error));
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.ZipWriter = ZipWriter;
|
|
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 = 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
|
+
const 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 pipeline(this.zip, this.getOutputStream());
|
|
25
|
+
}
|
|
26
|
+
get buffer() {
|
|
27
|
+
return Buffer.concat(this.buffers);
|
|
28
|
+
}
|
|
29
|
+
async addToStore(contents, path) {
|
|
30
|
+
this.zip.append(contents, { name: path });
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
}
|
|
33
|
+
async finalize() {
|
|
34
|
+
await this.zip.finalize();
|
|
35
|
+
await this.getInputBuffer();
|
|
36
|
+
}
|
|
37
|
+
getDestinationPath() {
|
|
38
|
+
return this.rootDestination;
|
|
39
|
+
}
|
|
40
|
+
getOutputStream() {
|
|
41
|
+
if (this.rootDestination) {
|
|
42
|
+
return (0, fs_1.createWriteStream)(this.rootDestination);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const bufferWritable = new stream_1.Writable();
|
|
46
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
47
|
+
bufferWritable._write = (chunk, encoding, cb) => {
|
|
48
|
+
this.buffers.push(chunk);
|
|
49
|
+
cb();
|
|
50
|
+
};
|
|
51
|
+
return bufferWritable;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async getInputBuffer() {
|
|
55
|
+
if (this.rootDestination) {
|
|
56
|
+
const inputStream = (0, fs_1.createReadStream)(this.rootDestination);
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
inputStream.on('data', (chunk) => {
|
|
59
|
+
this.buffers.push(chunk);
|
|
60
|
+
});
|
|
61
|
+
inputStream.once('end', () => resolve());
|
|
62
|
+
inputStream.once('error', (error) => reject(error));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ZipWriter = ZipWriter;
|
|
68
68
|
//# sourceMappingURL=zipWriter.js.map
|