@salesforce/core 3.19.1 → 3.19.4
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 +14 -0
- package/README.md +6 -18
- package/lib/config/aliasesConfig.d.ts +12 -0
- package/lib/config/aliasesConfig.js +27 -0
- package/lib/config/authInfoConfig.d.ts +19 -0
- package/lib/config/authInfoConfig.js +35 -0
- package/lib/config/configAggregator.d.ts +5 -3
- package/lib/config/configAggregator.js +13 -1
- package/lib/config/configFile.js +2 -2
- package/lib/config/configGroup.d.ts +141 -0
- package/lib/config/configGroup.js +224 -0
- package/lib/config/configStore.d.ts +2 -2
- package/lib/config/configStore.js +1 -2
- package/lib/config/tokensConfig.d.ts +10 -0
- package/lib/config/tokensConfig.js +28 -0
- package/lib/crypto/keyChainImpl.js +1 -1
- package/lib/exported.d.ts +1 -1
- package/lib/exported.js +6 -5
- package/lib/global.d.ts +8 -0
- package/lib/global.js +10 -0
- package/lib/org/authInfo.d.ts +3 -2
- package/lib/org/authInfo.js +55 -37
- package/lib/org/authRemover.d.ts +6 -5
- package/lib/org/authRemover.js +22 -16
- package/lib/org/connection.js +1 -1
- package/lib/org/org.d.ts +12 -4
- package/lib/org/org.js +28 -26
- package/lib/org/scratchOrgCreate.js +5 -8
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +79 -1
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +119 -2
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +53 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +201 -0
- package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.d.ts +12 -1
- package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.js +22 -2
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +28 -0
- package/lib/{globalInfo → stateAggregator}/accessors/tokenAccessor.js +34 -2
- package/lib/{globalInfo → stateAggregator}/globalInfoConfig.d.ts +11 -8
- package/lib/{globalInfo → stateAggregator}/globalInfoConfig.js +7 -4
- package/lib/stateAggregator/index.d.ts +7 -0
- package/lib/{globalInfo → stateAggregator}/index.js +5 -1
- package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.d.ts +7 -1
- package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.js +25 -2
- package/lib/stateAggregator/stateAggregator.d.ts +20 -0
- package/lib/stateAggregator/stateAggregator.js +38 -0
- package/lib/{globalInfo → stateAggregator}/types.d.ts +25 -10
- package/lib/{globalInfo → stateAggregator}/types.js +3 -0
- package/lib/testSetup.d.ts +30 -6
- package/lib/testSetup.js +79 -11
- package/lib/util/sfdcUrl.d.ts +3 -9
- package/lib/util/sfdcUrl.js +29 -28
- package/messages/core.md +10 -0
- package/messages/scratchOrgCreate.md +0 -4
- package/messages/scratchOrgInfoApi.md +4 -0
- package/package.json +4 -4
- package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
- package/lib/globalInfo/accessors/orgAccessor.js +0 -45
- package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
- package/lib/globalInfo/index.d.ts +0 -6
package/lib/testSetup.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { ConfigContents } from './config/configStore';
|
|
|
6
6
|
import { Logger } from './logger';
|
|
7
7
|
import { SfError } from './sfError';
|
|
8
8
|
import { CometClient, CometSubscription, Message, StreamingExtension } from './status/streamingClient';
|
|
9
|
-
import {
|
|
9
|
+
import { AuthFields, SandboxFields } from './org';
|
|
10
|
+
import { AliasGroup } from './config/aliasesConfig';
|
|
10
11
|
/**
|
|
11
12
|
* Different parts of the system that are mocked out. They can be restored for
|
|
12
13
|
* individual tests. Test's stubs should always go on the DEFAULT which is exposed
|
|
@@ -19,6 +20,7 @@ export interface SandboxTypes {
|
|
|
19
20
|
PROJECT: sinon.SinonSandbox;
|
|
20
21
|
CONNECTION: sinon.SinonSandbox;
|
|
21
22
|
FS: sinonType.SinonSandbox;
|
|
23
|
+
ORGS: sinonType.SinonSandbox;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* Different hooks into {@link ConfigFile} used for testing instead of doing file IO.
|
|
@@ -83,11 +85,16 @@ export interface TestContext {
|
|
|
83
85
|
*/
|
|
84
86
|
configStubs: {
|
|
85
87
|
[configName: string]: Optional<ConfigStub>;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
SfProjectJson?: ConfigStub;
|
|
88
|
+
AliasesConfig?: ConfigStub;
|
|
89
|
+
AuthInfoConfig?: ConfigStub;
|
|
89
90
|
SfdxConfig?: ConfigStub;
|
|
91
|
+
SfProjectJson?: ConfigStub;
|
|
92
|
+
TokensConfig?: ConfigStub;
|
|
90
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* An record of stubs created during instantaion.
|
|
96
|
+
*/
|
|
97
|
+
stubs?: Record<string, sinonType.SinonStub>;
|
|
91
98
|
/**
|
|
92
99
|
* A function used when resolving the local path. Calls localPathResolverSync by default.
|
|
93
100
|
*
|
|
@@ -150,7 +157,11 @@ export interface TestContext {
|
|
|
150
157
|
*/
|
|
151
158
|
setConfigStubContents(name: string, value: ConfigContents): void;
|
|
152
159
|
inProject(inProject: boolean): void;
|
|
160
|
+
stubAuths(...orgs: MockTestOrgData[]): Promise<void>;
|
|
161
|
+
stubSandboxes(...orgs: MockTestSandboxData[]): Promise<void>;
|
|
162
|
+
stubAliases(aliases: Record<string, string>, group?: AliasGroup): void;
|
|
153
163
|
}
|
|
164
|
+
export declare const uniqid: () => string;
|
|
154
165
|
/**
|
|
155
166
|
* Instantiate a @salesforce/core test context. This is automatically created by `const $$ = testSetup()`
|
|
156
167
|
* but is useful if you don't want to have a global stub of @salesforce/core and you want to isolate it to
|
|
@@ -197,7 +208,7 @@ export declare const instantiateContext: (sinon?: any) => TestContext;
|
|
|
197
208
|
* ```
|
|
198
209
|
* @param testContext
|
|
199
210
|
*/
|
|
200
|
-
export declare const stubContext: (testContext: TestContext) =>
|
|
211
|
+
export declare const stubContext: (testContext: TestContext) => Record<string, sinonType.SinonStub>;
|
|
201
212
|
/**
|
|
202
213
|
* Restore a @salesforce/core test context. This is automatically stubbed in the global beforeEach created by
|
|
203
214
|
* `const $$ = testSetup()` but is useful if you don't want to have a global stub of @salesforce/core and you
|
|
@@ -402,5 +413,18 @@ export declare class MockTestOrgData {
|
|
|
402
413
|
makeDevHub(): void;
|
|
403
414
|
createUser(user: string): MockTestOrgData;
|
|
404
415
|
getMockUserInfo(): JsonMap;
|
|
405
|
-
getConfig(): Promise<
|
|
416
|
+
getConfig(): Promise<AuthFields>;
|
|
417
|
+
}
|
|
418
|
+
export declare class MockTestSandboxData {
|
|
419
|
+
id: string;
|
|
420
|
+
sandboxOrgId: string;
|
|
421
|
+
prodOrgUsername: string;
|
|
422
|
+
sandboxName?: string;
|
|
423
|
+
username?: string;
|
|
424
|
+
constructor(id?: string, options?: Partial<{
|
|
425
|
+
prodOrgUsername: string;
|
|
426
|
+
name: string;
|
|
427
|
+
username: string;
|
|
428
|
+
}>);
|
|
429
|
+
getConfig(): Promise<SandboxFields>;
|
|
406
430
|
}
|
package/lib/testSetup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MockTestOrgData = exports.StreamingMockCometClient = exports.StreamingMockCometSubscription = exports.StreamingMockSubscriptionCall = exports.shouldThrow = exports.unexpectedResult = exports.testSetup = exports.restoreContext = exports.stubContext = exports.instantiateContext = void 0;
|
|
3
|
+
exports.MockTestSandboxData = exports.MockTestOrgData = exports.StreamingMockCometClient = exports.StreamingMockCometSubscription = exports.StreamingMockSubscriptionCall = exports.shouldThrow = exports.unexpectedResult = exports.testSetup = exports.restoreContext = exports.stubContext = exports.instantiateContext = exports.uniqid = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
6
|
* All rights reserved.
|
|
@@ -24,22 +24,25 @@ const messages_1 = require("./messages");
|
|
|
24
24
|
const sfError_1 = require("./sfError");
|
|
25
25
|
const sfProject_1 = require("./sfProject");
|
|
26
26
|
const streamingClient_1 = require("./status/streamingClient");
|
|
27
|
-
const
|
|
27
|
+
const stateAggregator_1 = require("./stateAggregator");
|
|
28
|
+
const sandboxAccessor_1 = require("./stateAggregator/accessors/sandboxAccessor");
|
|
29
|
+
const aliasesConfig_1 = require("./config/aliasesConfig");
|
|
28
30
|
const global_1 = require("./global");
|
|
29
31
|
const uniqid = () => {
|
|
30
32
|
return (0, crypto_1.randomBytes)(16).toString('hex');
|
|
31
33
|
};
|
|
34
|
+
exports.uniqid = uniqid;
|
|
32
35
|
function getTestLocalPath(uid) {
|
|
33
36
|
return (0, path_1.join)((0, os_1.tmpdir)(), uid, 'sfdx_core', 'local');
|
|
34
37
|
}
|
|
35
38
|
function getTestGlobalPath(uid) {
|
|
36
39
|
return (0, path_1.join)((0, os_1.tmpdir)(), uid, 'sfdx_core', 'global');
|
|
37
40
|
}
|
|
38
|
-
function retrieveRootPathSync(isGlobal, uid = uniqid()) {
|
|
41
|
+
function retrieveRootPathSync(isGlobal, uid = (0, exports.uniqid)()) {
|
|
39
42
|
return isGlobal ? getTestGlobalPath(uid) : getTestLocalPath(uid);
|
|
40
43
|
}
|
|
41
44
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
42
|
-
async function retrieveRootPath(isGlobal, uid = uniqid()) {
|
|
45
|
+
async function retrieveRootPath(isGlobal, uid = (0, exports.uniqid)()) {
|
|
43
46
|
return retrieveRootPathSync(isGlobal, uid);
|
|
44
47
|
}
|
|
45
48
|
function defaultFakeConnectionRequest() {
|
|
@@ -90,12 +93,13 @@ const instantiateContext = (sinon) => {
|
|
|
90
93
|
CRYPTO: sinon.createSandbox(),
|
|
91
94
|
CONNECTION: sinon.createSandbox(),
|
|
92
95
|
FS: sinon.createSandbox(),
|
|
96
|
+
ORGS: sinon.createSandbox(),
|
|
93
97
|
},
|
|
94
98
|
TEST_LOGGER: new logger_1.Logger({
|
|
95
99
|
name: 'SFDX_Core_Test_Logger',
|
|
96
100
|
}).useMemoryLogging(),
|
|
97
|
-
id: uniqid(),
|
|
98
|
-
uniqid,
|
|
101
|
+
id: (0, exports.uniqid)(),
|
|
102
|
+
uniqid: exports.uniqid,
|
|
99
103
|
configStubs: {},
|
|
100
104
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
101
105
|
localPathRetriever: async (uid) => getTestLocalPath(uid),
|
|
@@ -134,6 +138,34 @@ const instantiateContext = (sinon) => {
|
|
|
134
138
|
testContext.SANDBOXES.PROJECT.stub(sfProject_1.SfProject, 'resolveProjectPathSync').throws(new sfError_1.SfError('', 'InvalidProjectWorkspaceError'));
|
|
135
139
|
}
|
|
136
140
|
},
|
|
141
|
+
async stubAuths(...orgs) {
|
|
142
|
+
const entries = (await Promise.all(orgs.map(async (org) => [org.username, await org.getConfig()])));
|
|
143
|
+
const orgMap = new Map(entries);
|
|
144
|
+
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'getAllFiles').returns([...orgMap.keys()].map((o) => `${o}.json`));
|
|
145
|
+
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'hasFile').callsFake((username) => {
|
|
146
|
+
return orgMap.has(username);
|
|
147
|
+
});
|
|
148
|
+
const retrieveContents = async function () {
|
|
149
|
+
var _a;
|
|
150
|
+
const username = (0, path_1.basename)(this.path.replace('.json', ''));
|
|
151
|
+
return Promise.resolve((_a = orgMap.get(username)) !== null && _a !== void 0 ? _a : {});
|
|
152
|
+
};
|
|
153
|
+
this.configStubs.AuthInfoConfig = { retrieveContents };
|
|
154
|
+
},
|
|
155
|
+
async stubSandboxes(...sandboxes) {
|
|
156
|
+
const entries = (await Promise.all(sandboxes.map(async (sanbox) => [sanbox.username, await sanbox.getConfig()])));
|
|
157
|
+
const sandboxMap = new Map(entries);
|
|
158
|
+
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, sandboxAccessor_1.SandboxAccessor.prototype, 'getAllFiles').returns([...sandboxMap.keys()].map((o) => `${o}.sandbox.json`));
|
|
159
|
+
const retrieveContents = async function () {
|
|
160
|
+
var _a;
|
|
161
|
+
const username = (0, path_1.basename)(this.path.replace('.sandbox.json', ''));
|
|
162
|
+
return Promise.resolve((_a = sandboxMap.get(username)) !== null && _a !== void 0 ? _a : {});
|
|
163
|
+
};
|
|
164
|
+
this.configStubs.SandboxOrgConfig = { retrieveContents };
|
|
165
|
+
},
|
|
166
|
+
stubAliases(aliases, group = aliasesConfig_1.AliasGroup.ORGS) {
|
|
167
|
+
this.configStubs.AliasesConfig = { contents: { [group]: aliases } };
|
|
168
|
+
},
|
|
137
169
|
};
|
|
138
170
|
return testContext;
|
|
139
171
|
};
|
|
@@ -166,6 +198,7 @@ const stubContext = (testContext) => {
|
|
|
166
198
|
// Turn off the interoperability feature so that we don't have to mock
|
|
167
199
|
// the old .sfdx config files
|
|
168
200
|
global_1.Global.SFDX_INTEROPERABILITY = false;
|
|
201
|
+
const stubs = {};
|
|
169
202
|
// Most core files create a child logger so stub this to return our test logger.
|
|
170
203
|
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'child').returns(Promise.resolve(testContext.TEST_LOGGER));
|
|
171
204
|
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'childFromRoot').returns(testContext.TEST_LOGGER);
|
|
@@ -230,8 +263,8 @@ const stubContext = (testContext) => {
|
|
|
230
263
|
writeSync.call(this);
|
|
231
264
|
}
|
|
232
265
|
};
|
|
233
|
-
(0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'writeSync').callsFake(writeSync);
|
|
234
|
-
(0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'write').callsFake(write);
|
|
266
|
+
stubs.configWriteSync = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'writeSync').callsFake(writeSync);
|
|
267
|
+
stubs.configWrite = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'write').callsFake(write);
|
|
235
268
|
(0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CRYPTO, crypto_2.Crypto.prototype, 'getKeyChain').callsFake(() => Promise.resolve({
|
|
236
269
|
setPassword: () => Promise.resolve(),
|
|
237
270
|
getPassword: (data, cb) => cb(undefined, '12345678901234567890123456789012'),
|
|
@@ -243,8 +276,23 @@ const stubContext = (testContext) => {
|
|
|
243
276
|
}
|
|
244
277
|
return testContext.fakeConnectionRequest.call(this, request, options);
|
|
245
278
|
});
|
|
279
|
+
stubs.configExists = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.ORGS, stateAggregator_1.OrgAccessor.prototype, 'exists').callsFake(async function (username) {
|
|
280
|
+
// @ts-expect-error because private member
|
|
281
|
+
if ([...this.contents.keys()].includes(username))
|
|
282
|
+
return Promise.resolve(true);
|
|
283
|
+
else
|
|
284
|
+
return Promise.resolve(false);
|
|
285
|
+
});
|
|
286
|
+
stubs.configRemove = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.ORGS, stateAggregator_1.OrgAccessor.prototype, 'remove').callsFake(async function (username) {
|
|
287
|
+
// @ts-expect-error because private member
|
|
288
|
+
if ([...this.contents.keys()].includes(username))
|
|
289
|
+
return Promise.resolve(true);
|
|
290
|
+
else
|
|
291
|
+
return Promise.resolve(false);
|
|
292
|
+
});
|
|
246
293
|
// Always start with the default and tests beforeEach or it methods can override it.
|
|
247
294
|
testContext.fakeConnectionRequest = defaultFakeConnectionRequest;
|
|
295
|
+
return stubs;
|
|
248
296
|
};
|
|
249
297
|
exports.stubContext = stubContext;
|
|
250
298
|
/**
|
|
@@ -271,7 +319,9 @@ const restoreContext = (testContext) => {
|
|
|
271
319
|
Object.values(testContext.SANDBOXES).forEach((theSandbox) => theSandbox.restore());
|
|
272
320
|
testContext.configStubs = {};
|
|
273
321
|
// Give each test run a clean GlobalInstance
|
|
274
|
-
|
|
322
|
+
stateAggregator_1.GlobalInfo.clearInstance();
|
|
323
|
+
// Give each test run a clean StateAggregator
|
|
324
|
+
stateAggregator_1.StateAggregator.clearInstance();
|
|
275
325
|
};
|
|
276
326
|
exports.restoreContext = restoreContext;
|
|
277
327
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -281,7 +331,7 @@ const _testSetup = (sinon) => {
|
|
|
281
331
|
// Allow each test to have their own config aggregator
|
|
282
332
|
// @ts-ignore clear for testing.
|
|
283
333
|
delete configAggregator_1.ConfigAggregator.instance;
|
|
284
|
-
(0, exports.stubContext)(testContext);
|
|
334
|
+
testContext.stubs = (0, exports.stubContext)(testContext);
|
|
285
335
|
});
|
|
286
336
|
afterEach(() => {
|
|
287
337
|
(0, exports.restoreContext)(testContext);
|
|
@@ -473,7 +523,7 @@ exports.StreamingMockCometClient = StreamingMockCometClient;
|
|
|
473
523
|
* Mock class for OrgData.
|
|
474
524
|
*/
|
|
475
525
|
class MockTestOrgData {
|
|
476
|
-
constructor(id = uniqid(), options) {
|
|
526
|
+
constructor(id = (0, exports.uniqid)(), options) {
|
|
477
527
|
this.testId = id;
|
|
478
528
|
this.userId = `user_id_${this.testId}`;
|
|
479
529
|
this.orgId = `${this.testId}`;
|
|
@@ -552,4 +602,22 @@ class MockTestOrgData {
|
|
|
552
602
|
}
|
|
553
603
|
}
|
|
554
604
|
exports.MockTestOrgData = MockTestOrgData;
|
|
605
|
+
class MockTestSandboxData {
|
|
606
|
+
constructor(id = (0, exports.uniqid)(), options) {
|
|
607
|
+
this.id = id;
|
|
608
|
+
this.sandboxOrgId = id;
|
|
609
|
+
this.prodOrgUsername = (options === null || options === void 0 ? void 0 : options.prodOrgUsername) || `admin_${id}@gb.org`;
|
|
610
|
+
this.sandboxName = (options === null || options === void 0 ? void 0 : options.name) || `sandbox_${id}`;
|
|
611
|
+
this.username = (options === null || options === void 0 ? void 0 : options.username) || `${this.prodOrgUsername}.sandbox`;
|
|
612
|
+
}
|
|
613
|
+
async getConfig() {
|
|
614
|
+
return {
|
|
615
|
+
sandboxOrgId: this.sandboxOrgId,
|
|
616
|
+
prodOrgUsername: this.prodOrgUsername,
|
|
617
|
+
sandboxName: this.sandboxName,
|
|
618
|
+
sandboxUsername: this.username,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
exports.MockTestSandboxData = MockTestSandboxData;
|
|
555
623
|
//# sourceMappingURL=testSetup.js.map
|
package/lib/util/sfdcUrl.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { URL } from 'url';
|
|
3
|
+
export declare function getLoginAudienceCombos(audienceUrl: string, loginUrl: string): [string, string][];
|
|
3
4
|
export declare class SfdcUrl extends URL {
|
|
4
5
|
/**
|
|
5
6
|
* Salesforce URLs
|
|
@@ -27,7 +28,7 @@ export declare class SfdcUrl extends URL {
|
|
|
27
28
|
/**
|
|
28
29
|
* Tests whether this url is an internal Salesforce domain
|
|
29
30
|
*
|
|
30
|
-
* @returns {boolean} true if this is
|
|
31
|
+
* @returns {boolean} true if this is an internal domain
|
|
31
32
|
*/
|
|
32
33
|
isInternalUrl(): boolean;
|
|
33
34
|
/**
|
|
@@ -57,6 +58,7 @@ export declare class SfdcUrl extends URL {
|
|
|
57
58
|
/**
|
|
58
59
|
* Tests whether this url is a sandbox url
|
|
59
60
|
*
|
|
61
|
+
* @Deprecated - identification of a sandbox instance by URL alone is not deterministic
|
|
60
62
|
* @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
|
|
61
63
|
* @returns {boolean}
|
|
62
64
|
*/
|
|
@@ -67,12 +69,4 @@ export declare class SfdcUrl extends URL {
|
|
|
67
69
|
* @returns {boolean} true if this domain is a lightning domain
|
|
68
70
|
*/
|
|
69
71
|
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
72
|
}
|
package/lib/util/sfdcUrl.js
CHANGED
|
@@ -6,13 +6,37 @@
|
|
|
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.SfdcUrl = void 0;
|
|
9
|
+
exports.SfdcUrl = exports.getLoginAudienceCombos = void 0;
|
|
10
10
|
const url_1 = require("url");
|
|
11
11
|
const kit_1 = require("@salesforce/kit");
|
|
12
12
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
13
13
|
const myDomainResolver_1 = require("../status/myDomainResolver");
|
|
14
14
|
const logger_1 = require("../logger");
|
|
15
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;
|
|
16
40
|
class SfdcUrl extends url_1.URL {
|
|
17
41
|
constructor(input, base) {
|
|
18
42
|
super(input.toString(), base);
|
|
@@ -45,13 +69,6 @@ class SfdcUrl extends url_1.URL {
|
|
|
45
69
|
this.logger.debug(`Audience URL overridden by env var SFDX_AUDIENCE_URL=${envVarVal}`);
|
|
46
70
|
return envVarVal;
|
|
47
71
|
}
|
|
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
72
|
if ((createdOrgInstance && /^gs1/gi.test(createdOrgInstance)) || /(gs1.my.salesforce.com)/gi.test(this.origin)) {
|
|
56
73
|
return 'https://gs1.salesforce.com';
|
|
57
74
|
}
|
|
@@ -81,7 +98,7 @@ class SfdcUrl extends url_1.URL {
|
|
|
81
98
|
/**
|
|
82
99
|
* Tests whether this url is an internal Salesforce domain
|
|
83
100
|
*
|
|
84
|
-
* @returns {boolean} true if this is
|
|
101
|
+
* @returns {boolean} true if this is an internal domain
|
|
85
102
|
*/
|
|
86
103
|
isInternalUrl() {
|
|
87
104
|
const INTERNAL_URL_PARTS = [
|
|
@@ -157,9 +174,11 @@ class SfdcUrl extends url_1.URL {
|
|
|
157
174
|
/**
|
|
158
175
|
* Tests whether this url is a sandbox url
|
|
159
176
|
*
|
|
177
|
+
* @Deprecated - identification of a sandbox instance by URL alone is not deterministic
|
|
160
178
|
* @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
|
|
161
179
|
* @returns {boolean}
|
|
162
180
|
*/
|
|
181
|
+
// TODO: how to get rid of this?
|
|
163
182
|
isSandboxUrl(createdOrgInstance) {
|
|
164
183
|
return ((createdOrgInstance && /^cs|s$/gi.test(createdOrgInstance)) ||
|
|
165
184
|
this.origin.endsWith('sandbox.my.salesforce.mil') ||
|
|
@@ -177,25 +196,7 @@ class SfdcUrl extends url_1.URL {
|
|
|
177
196
|
* @returns {boolean} true if this domain is a lightning domain
|
|
178
197
|
*/
|
|
179
198
|
isLightningDomain() {
|
|
180
|
-
return /\.lightning\.force\.com/.test(this.origin);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Tests whether this url is a sandbox url
|
|
184
|
-
* otherwise tries to resolve dns cnames and then look if any is sandbox url
|
|
185
|
-
*
|
|
186
|
-
* @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
|
|
187
|
-
* @returns {Promise<boolean>} true if this domain resolves to sanbox url
|
|
188
|
-
*/
|
|
189
|
-
async resolvesToSandbox(createdOrgInstance) {
|
|
190
|
-
if (this.isSandboxUrl(createdOrgInstance)) {
|
|
191
|
-
return true;
|
|
192
|
-
}
|
|
193
|
-
const myDomainResolver = await myDomainResolver_1.MyDomainResolver.create({ url: this });
|
|
194
|
-
const cnames = await myDomainResolver.getCnames();
|
|
195
|
-
return cnames.some((cname) => {
|
|
196
|
-
const url = new SfdcUrl(`https://${cname}`);
|
|
197
|
-
return url.isSandboxUrl();
|
|
198
|
-
});
|
|
199
|
+
return /\.lightning\.force\.com/.test(this.origin) || /\.lightning\.crmforce\.mil/.test(this.origin);
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
exports.SfdcUrl = SfdcUrl;
|
package/messages/core.md
CHANGED
|
@@ -24,6 +24,12 @@ Due to: %s
|
|
|
24
24
|
|
|
25
25
|
Error authenticating with JWT config due to: %s
|
|
26
26
|
|
|
27
|
+
# jwtAuthErrors
|
|
28
|
+
|
|
29
|
+
Error authenticating with JWT.
|
|
30
|
+
Errors encountered:
|
|
31
|
+
%s
|
|
32
|
+
|
|
27
33
|
# refreshTokenAuthError
|
|
28
34
|
|
|
29
35
|
Error authenticating with the refresh token due to: %s
|
|
@@ -55,3 +61,7 @@ Setting aliases must be in the format <key>=<value> but found: [%s].
|
|
|
55
61
|
|
|
56
62
|
All JSON input must have heads down camelcase keys. E.g., `{ sfdcLoginUrl: "https://login.salesforce.com" }`
|
|
57
63
|
Found "%s" at %s
|
|
64
|
+
|
|
65
|
+
# missingClientId
|
|
66
|
+
|
|
67
|
+
Client ID is required for JWT authentication.
|
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Org snapshots don’t support one or more options you specified: %s.
|
|
4
4
|
|
|
5
|
-
# SourceStatusResetFailureError
|
|
6
|
-
|
|
7
|
-
Successfully created org with ID: %s and name: %s. Unfortunately, source tracking isn’t working as expected. If you run force:source:status, the results may be incorrect. Try again by creating another scratch org.
|
|
8
|
-
|
|
9
5
|
# DurationDaysValidationMinError
|
|
10
6
|
|
|
11
7
|
Expected 'durationDays' greater than or equal to %s but received %s.
|
|
@@ -9,3 +9,7 @@ You cannot use 'settings' and `'orgPreferences' in your scratch definition file,
|
|
|
9
9
|
# DeprecatedPrefFormat
|
|
10
10
|
|
|
11
11
|
We've deprecated OrgPreferences. Update the scratch org definition file to replace OrgPreferences with their corresponding settings.
|
|
12
|
+
|
|
13
|
+
# SourceStatusResetFailureError
|
|
14
|
+
|
|
15
|
+
Successfully created org with ID: %s and name: %s. Unfortunately, source tracking isn’t working as expected. If you run force:source:status, the results may be incorrect. Try again by creating another scratch org.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/core",
|
|
3
|
-
"version": "3.19.
|
|
3
|
+
"version": "3.19.4",
|
|
4
4
|
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"types": "lib/exported.d.ts",
|
|
@@ -68,14 +68,14 @@
|
|
|
68
68
|
"@typescript-eslint/parser": "4.33.0",
|
|
69
69
|
"chai": "^4.3.4",
|
|
70
70
|
"commitizen": "^3.1.2",
|
|
71
|
-
"eslint": "^
|
|
71
|
+
"eslint": "^7.27.0",
|
|
72
72
|
"eslint-config-prettier": "^6.15.0",
|
|
73
73
|
"eslint-config-salesforce": "^0.1.6",
|
|
74
74
|
"eslint-config-salesforce-license": "^0.1.6",
|
|
75
75
|
"eslint-config-salesforce-typescript": "^0.2.8",
|
|
76
|
-
"eslint-plugin-header": "
|
|
76
|
+
"eslint-plugin-header": "3.0.0",
|
|
77
77
|
"eslint-plugin-import": "^2.25.4",
|
|
78
|
-
"eslint-plugin-jsdoc": "^
|
|
78
|
+
"eslint-plugin-jsdoc": "^35.1.2",
|
|
79
79
|
"eslint-plugin-prettier": "^3.1.3",
|
|
80
80
|
"husky": "^7.0.4",
|
|
81
81
|
"mocha": "^9.1.3",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Optional } from '@salesforce/ts-types';
|
|
2
|
-
import { GlobalInfo } from '../globalInfoConfig';
|
|
3
|
-
import { SfOrgs, SfOrg } from '../types';
|
|
4
|
-
export declare class OrgAccessor {
|
|
5
|
-
private globalInfo;
|
|
6
|
-
constructor(globalInfo: GlobalInfo);
|
|
7
|
-
getAll(decrypt?: boolean): SfOrgs;
|
|
8
|
-
get(username: string, decrypt?: boolean): Optional<SfOrg>;
|
|
9
|
-
has(username: string): boolean;
|
|
10
|
-
set(username: string, org: SfOrg): void;
|
|
11
|
-
update(username: string, org: Partial<SfOrg>): void;
|
|
12
|
-
unset(username: string): void;
|
|
13
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
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.OrgAccessor = void 0;
|
|
10
|
-
const types_1 = require("../types");
|
|
11
|
-
class OrgAccessor {
|
|
12
|
-
constructor(globalInfo) {
|
|
13
|
-
this.globalInfo = globalInfo;
|
|
14
|
-
}
|
|
15
|
-
getAll(decrypt = false) {
|
|
16
|
-
return this.globalInfo.get(types_1.SfInfoKeys.ORGS, decrypt);
|
|
17
|
-
}
|
|
18
|
-
get(username, decrypt = false) {
|
|
19
|
-
const auth = this.globalInfo.get(`${types_1.SfInfoKeys.ORGS}["${username}"]`, decrypt);
|
|
20
|
-
// For legacy, some things wants the username in the returned auth info.
|
|
21
|
-
if (auth && !auth.username)
|
|
22
|
-
auth.username = username;
|
|
23
|
-
return auth;
|
|
24
|
-
}
|
|
25
|
-
has(username) {
|
|
26
|
-
return !!this.getAll()[username];
|
|
27
|
-
}
|
|
28
|
-
set(username, org) {
|
|
29
|
-
// For legacy, and to keep things standard, some things wants the username in auth info.
|
|
30
|
-
if (!org.username)
|
|
31
|
-
org.username = username;
|
|
32
|
-
this.globalInfo.set(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
|
|
33
|
-
}
|
|
34
|
-
update(username, org) {
|
|
35
|
-
// For legacy, and to keep things standard, some things wants the username in auth info.
|
|
36
|
-
if (!org.username)
|
|
37
|
-
org.username = username;
|
|
38
|
-
this.globalInfo.update(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
|
|
39
|
-
}
|
|
40
|
-
unset(username) {
|
|
41
|
-
delete this.globalInfo.get(types_1.SfInfoKeys.ORGS)[username];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.OrgAccessor = OrgAccessor;
|
|
45
|
-
//# sourceMappingURL=orgAccessor.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Optional } from '@salesforce/ts-types';
|
|
2
|
-
import { GlobalInfo } from '../globalInfoConfig';
|
|
3
|
-
import { SfTokens, SfToken, Timestamp } from '../types';
|
|
4
|
-
export declare class TokenAccessor {
|
|
5
|
-
private globalInfo;
|
|
6
|
-
constructor(globalInfo: GlobalInfo);
|
|
7
|
-
getAll(decrypt?: boolean): SfTokens;
|
|
8
|
-
get(name: string, decrypt?: boolean): Optional<SfToken & Timestamp>;
|
|
9
|
-
has(name: string): boolean;
|
|
10
|
-
set(name: string, token: SfToken): void;
|
|
11
|
-
update(name: string, token: Partial<SfToken>): void;
|
|
12
|
-
unset(name: string): void;
|
|
13
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export * from './globalInfoConfig';
|
|
2
|
-
export * from './sfdxDataHandler';
|
|
3
|
-
export * from './types';
|
|
4
|
-
export { OrgAccessor } from './accessors/orgAccessor';
|
|
5
|
-
export { AliasAccessor } from './accessors/aliasAccessor';
|
|
6
|
-
export { TokenAccessor } from './accessors/tokenAccessor';
|