@salesforce/core 3.30.9 → 3.30.11
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/README.md +3 -3
- package/lib/config/aliasesConfig.js +1 -0
- package/lib/config/config.js +6 -9
- package/lib/config/configAggregator.d.ts +3 -3
- package/lib/config/configAggregator.js +14 -14
- package/lib/config/configFile.js +7 -9
- package/lib/config/configGroup.js +8 -7
- package/lib/config/configStore.d.ts +4 -4
- package/lib/config/configStore.js +12 -9
- package/lib/config/envVars.js +1 -1
- package/lib/config/tokensConfig.js +1 -0
- package/lib/config/ttlConfig.d.ts +2 -0
- package/lib/config/ttlConfig.js +5 -4
- package/lib/crypto/crypto.js +9 -12
- package/lib/crypto/keyChainImpl.d.ts +2 -0
- package/lib/crypto/keyChainImpl.js +41 -34
- package/lib/deviceOauthService.js +5 -2
- package/lib/exported.js +5 -1
- package/lib/global.js +2 -0
- package/lib/lifecycleEvents.js +3 -0
- package/lib/logger.d.ts +2 -3
- package/lib/logger.js +57 -53
- package/lib/messages.js +2 -3
- package/lib/org/authInfo.js +40 -29
- package/lib/org/authRemover.js +11 -7
- package/lib/org/connection.d.ts +4 -4
- package/lib/org/connection.js +14 -6
- package/lib/org/index.js +5 -1
- package/lib/org/org.js +23 -15
- package/lib/org/scratchOrgCreate.js +2 -1
- package/lib/org/scratchOrgInfoApi.js +4 -6
- package/lib/org/scratchOrgInfoGenerator.d.ts +1 -0
- package/lib/org/scratchOrgInfoGenerator.js +28 -27
- package/lib/org/scratchOrgLifecycleEvents.js +2 -6
- package/lib/org/scratchOrgSettingsGenerator.js +9 -9
- package/lib/org/scratchOrgTypes.d.ts +1 -1
- package/lib/org/user.js +7 -6
- package/lib/schema/printer.d.ts +4 -0
- package/lib/schema/printer.js +30 -29
- package/lib/schema/validator.d.ts +1 -1
- package/lib/schema/validator.js +2 -1
- package/lib/sfError.d.ts +3 -6
- package/lib/sfError.js +26 -9
- package/lib/sfProject.js +14 -6
- package/lib/stateAggregator/accessors/aliasAccessor.js +2 -1
- package/lib/stateAggregator/accessors/orgAccessor.js +11 -6
- package/lib/stateAggregator/accessors/sandboxAccessor.js +1 -0
- package/lib/stateAggregator/index.js +5 -1
- package/lib/status/myDomainResolver.d.ts +1 -1
- package/lib/status/myDomainResolver.js +4 -4
- package/lib/status/streamingClient.js +51 -49
- package/lib/testSetup.d.ts +5 -1
- package/lib/testSetup.js +32 -21
- package/lib/util/cache.d.ts +2 -2
- package/lib/util/cache.js +6 -6
- package/lib/util/directoryWriter.d.ts +2 -1
- package/lib/util/directoryWriter.js +5 -3
- package/lib/util/jsonXmlTools.js +2 -4
- package/lib/util/mapKeys.d.ts +9 -9
- package/lib/util/mapKeys.js +13 -9
- package/lib/util/sfdc.d.ts +2 -2
- package/lib/util/sfdc.js +8 -17
- package/lib/util/sfdcUrl.d.ts +1 -1
- package/lib/util/sfdcUrl.js +2 -4
- package/lib/util/structuredWriter.d.ts +1 -0
- package/lib/util/zipWriter.d.ts +2 -1
- package/lib/util/zipWriter.js +5 -9
- package/lib/webOAuthServer.js +9 -3
- package/messages/connection.md +8 -0
- package/package.json +16 -17
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Licensed under the BSD 3-Clause license.
|
|
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
|
+
/* eslint-disable class-methods-use-this */
|
|
8
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
10
|
exports.SandboxAccessor = void 0;
|
|
10
11
|
const sandboxOrgConfig_1 = require("../../config/sandboxOrgConfig");
|
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
9
|
if (k2 === undefined) k2 = k;
|
|
10
|
-
Object.
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
11
15
|
}) : (function(o, m, k, k2) {
|
|
12
16
|
if (k2 === undefined) k2 = k;
|
|
13
17
|
o[k2] = m[k];
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { URL } from 'url';
|
|
3
3
|
import { AsyncOptionalCreatable, Duration } from '@salesforce/kit';
|
|
4
4
|
/**
|
|
5
|
-
* A class used to resolve MyDomains. After a ScratchOrg is created
|
|
5
|
+
* A class used to resolve MyDomains. After a ScratchOrg is created its host name my not be propagated to the
|
|
6
6
|
* Salesforce DNS service. This service is not exclusive to Salesforce My Domain URL and could be used for any hostname.
|
|
7
7
|
*
|
|
8
8
|
* ```
|
|
@@ -20,7 +20,7 @@ const DNS_TIMEOUT = Math.max(3, new kit_1.Env().getNumber('SFDX_DNS_TIMEOUT', 3)
|
|
|
20
20
|
// Retry frequency for DNS lookup polling defaults to 1 second and should be at least 1 second
|
|
21
21
|
const DNS_RETRY_FREQ = Math.max(1, new kit_1.Env().getNumber('SFDX_DNS_RETRY_FREQUENCY', 1));
|
|
22
22
|
/**
|
|
23
|
-
* A class used to resolve MyDomains. After a ScratchOrg is created
|
|
23
|
+
* A class used to resolve MyDomains. After a ScratchOrg is created its host name my not be propagated to the
|
|
24
24
|
* Salesforce DNS service. This service is not exclusive to Salesforce My Domain URL and could be used for any hostname.
|
|
25
25
|
*
|
|
26
26
|
* ```
|
|
@@ -45,13 +45,13 @@ class MyDomainResolver extends kit_1.AsyncOptionalCreatable {
|
|
|
45
45
|
*/
|
|
46
46
|
constructor(options) {
|
|
47
47
|
super(options);
|
|
48
|
-
this.options = options
|
|
48
|
+
this.options = options ?? { url: MyDomainResolver.DEFAULT_DOMAIN };
|
|
49
49
|
}
|
|
50
50
|
getTimeout() {
|
|
51
|
-
return this.options.timeout
|
|
51
|
+
return this.options.timeout ?? kit_1.Duration.seconds(DNS_TIMEOUT);
|
|
52
52
|
}
|
|
53
53
|
getFrequency() {
|
|
54
|
-
return this.options.frequency
|
|
54
|
+
return this.options.frequency ?? kit_1.Duration.seconds(DNS_RETRY_FREQ);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Method that performs the dns lookup of the host. If the lookup fails the internal polling client will try again
|
|
@@ -211,54 +211,52 @@ class StreamingClient extends lib_1.AsyncOptionalCreatable {
|
|
|
211
211
|
// This outer promise is to hold the streaming promise chain open until the streaming processor
|
|
212
212
|
// says it's complete.
|
|
213
213
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
214
|
-
return new Promise((subscribeResolve, subscribeReject) =>
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
clearTimeout(timeout);
|
|
230
|
-
this.disconnectClient();
|
|
231
|
-
subscribeResolve(result.payload);
|
|
232
|
-
} // This 'if' is intended to be evaluated until it's completed or until the timeout fires.
|
|
233
|
-
}
|
|
234
|
-
catch (e) {
|
|
235
|
-
// it's completely valid for the stream processor to throw an error. If it does we will
|
|
236
|
-
// reject the outer promise. Keep in mind if we are here the subscription was resolved.
|
|
214
|
+
return new Promise((subscribeResolve, subscribeReject) =>
|
|
215
|
+
// This is the inner promise chain that's satisfied when the client impl (Faye/Mock) says it's subscribed.
|
|
216
|
+
new Promise((subscriptionResolve, subscriptionReject) => {
|
|
217
|
+
timeout = setTimeout(() => {
|
|
218
|
+
const timeoutError = messages.createError('genericTimeout');
|
|
219
|
+
this.doTimeout(timeout, timeoutError);
|
|
220
|
+
subscribeReject(timeoutError);
|
|
221
|
+
}, this.options.subscribeTimeout.milliseconds);
|
|
222
|
+
// Initialize the subscription.
|
|
223
|
+
const subscription = this.cometClient.subscribe(this.options.channel, (message) => {
|
|
224
|
+
try {
|
|
225
|
+
// The result of the stream processor determines the state of the outer promise.
|
|
226
|
+
const result = this.options.streamProcessor(message);
|
|
227
|
+
// The stream processor says it's complete. Clean up and resolve the outer promise.
|
|
228
|
+
if (result?.completed) {
|
|
237
229
|
clearTimeout(timeout);
|
|
238
230
|
this.disconnectClient();
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
.then(() => {
|
|
250
|
-
// Now that we successfully have a subscription started up we are safe to initialize the function that
|
|
251
|
-
// will affect the streaming events. I.E. create an org or run apex tests.
|
|
252
|
-
return streamInit && streamInit();
|
|
253
|
-
})
|
|
254
|
-
.catch((error) => {
|
|
255
|
-
this.disconnect();
|
|
256
|
-
// Need to catch the subscription rejection or it will result in an unhandled rejection error.
|
|
257
|
-
clearTimeout(timeout);
|
|
258
|
-
// No subscription so we can reject the out promise as well.
|
|
259
|
-
subscribeReject(error);
|
|
231
|
+
subscribeResolve(result.payload);
|
|
232
|
+
} // This 'if' is intended to be evaluated until it's completed or until the timeout fires.
|
|
233
|
+
}
|
|
234
|
+
catch (e) {
|
|
235
|
+
// it's completely valid for the stream processor to throw an error. If it does we will
|
|
236
|
+
// reject the outer promise. Keep in mind if we are here the subscription was resolved.
|
|
237
|
+
clearTimeout(timeout);
|
|
238
|
+
this.disconnectClient();
|
|
239
|
+
subscribeReject(e);
|
|
240
|
+
}
|
|
260
241
|
});
|
|
261
|
-
|
|
242
|
+
subscription.callback(() => {
|
|
243
|
+
subscriptionResolve();
|
|
244
|
+
});
|
|
245
|
+
subscription.errback((error) => {
|
|
246
|
+
subscriptionReject(error);
|
|
247
|
+
});
|
|
248
|
+
})
|
|
249
|
+
.then(() =>
|
|
250
|
+
// Now that we successfully have a subscription started up we are safe to initialize the function that
|
|
251
|
+
// will affect the streaming events. I.E. create an org or run apex tests.
|
|
252
|
+
streamInit?.())
|
|
253
|
+
.catch((error) => {
|
|
254
|
+
this.disconnect();
|
|
255
|
+
// Need to catch the subscription rejection or it will result in an unhandled rejection error.
|
|
256
|
+
clearTimeout(timeout);
|
|
257
|
+
// No subscription so we can reject the out promise as well.
|
|
258
|
+
subscribeReject(error);
|
|
259
|
+
}));
|
|
262
260
|
}
|
|
263
261
|
/**
|
|
264
262
|
* Handler for incoming streaming messages.
|
|
@@ -296,12 +294,17 @@ class StreamingClient extends lib_1.AsyncOptionalCreatable {
|
|
|
296
294
|
// unauthenticated connections are being made to salesforce. Let's close the dispatcher if it exists and
|
|
297
295
|
// has no clientId.
|
|
298
296
|
// @ts-ignore
|
|
297
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
299
298
|
if (this.cometClient._dispatcher) {
|
|
300
299
|
this.log('Closing the faye dispatcher');
|
|
301
300
|
// @ts-ignore
|
|
301
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, no-underscore-dangle
|
|
302
302
|
const dispatcher = this.cometClient._dispatcher;
|
|
303
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access
|
|
303
304
|
this.log(`dispatcher.clientId: ${dispatcher.clientId}`);
|
|
305
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
304
306
|
if (!dispatcher.clientId) {
|
|
307
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
305
308
|
dispatcher.close();
|
|
306
309
|
}
|
|
307
310
|
else {
|
|
@@ -363,10 +366,9 @@ exports.StreamingClient = StreamingClient;
|
|
|
363
366
|
this.subscribeTimeout = StreamingClient.DefaultOptions.DEFAULT_SUBSCRIBE_TIMEOUT;
|
|
364
367
|
this.handshakeTimeout = StreamingClient.DefaultOptions.DEFAULT_HANDSHAKE_TIMEOUT;
|
|
365
368
|
this.streamingImpl = {
|
|
366
|
-
getCometClient: (url) =>
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
},
|
|
369
|
+
getCometClient: (url) =>
|
|
370
|
+
// @ts-ignore
|
|
371
|
+
new Faye.Client(url),
|
|
370
372
|
setLogger: (logLine) => {
|
|
371
373
|
// @ts-ignore
|
|
372
374
|
Faye.logger = {};
|
package/lib/testSetup.d.ts
CHANGED
|
@@ -183,7 +183,7 @@ export interface TestContext {
|
|
|
183
183
|
/**
|
|
184
184
|
* Stub contents in the config file.
|
|
185
185
|
*/
|
|
186
|
-
stubConfig(config: Record<string, string>): void
|
|
186
|
+
stubConfig(config: Record<string, string>): Promise<void>;
|
|
187
187
|
/**
|
|
188
188
|
* Stub the tokens in the global token config file.
|
|
189
189
|
*/
|
|
@@ -450,8 +450,10 @@ export declare class StreamingMockCometClient extends CometClient {
|
|
|
450
450
|
* Mock class for Salesforce Orgs.
|
|
451
451
|
*
|
|
452
452
|
* @example
|
|
453
|
+
* ```
|
|
453
454
|
* const testOrg = new MockTestOrgData();
|
|
454
455
|
* await $$.stubAuths(testOrg)
|
|
456
|
+
* ```
|
|
455
457
|
*/
|
|
456
458
|
export declare class MockTestOrgData {
|
|
457
459
|
testId: string;
|
|
@@ -505,8 +507,10 @@ export declare class MockTestOrgData {
|
|
|
505
507
|
* Mock class for Salesforce Sandboxes.
|
|
506
508
|
*
|
|
507
509
|
* @example
|
|
510
|
+
* ```
|
|
508
511
|
* const testOrg = new MockTestSandboxData();
|
|
509
512
|
* await $$.stubSandboxes(testOrg)
|
|
513
|
+
* ```
|
|
510
514
|
*/
|
|
511
515
|
export declare class MockTestSandboxData {
|
|
512
516
|
id: string;
|
package/lib/testSetup.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MockTestSandboxData = exports.MockTestOrgData = exports.StreamingMockCometClient = exports.StreamingMockCometSubscription = exports.StreamingMockSubscriptionCall = exports.shouldThrowSync = exports.shouldThrow = exports.unexpectedResult = exports.testSetup = exports.restoreContext = exports.stubContext = exports.instantiateContext = exports.uniqid = void 0;
|
|
4
2
|
/*
|
|
5
3
|
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
4
|
* All rights reserved.
|
|
@@ -8,6 +6,12 @@ exports.MockTestSandboxData = exports.MockTestOrgData = exports.StreamingMockCom
|
|
|
8
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
7
|
*/
|
|
10
8
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
9
|
+
/* eslint-disable class-methods-use-this */
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.MockTestSandboxData = exports.MockTestOrgData = exports.StreamingMockCometClient = exports.StreamingMockCometSubscription = exports.StreamingMockSubscriptionCall = exports.shouldThrowSync = exports.shouldThrow = exports.unexpectedResult = exports.testSetup = exports.restoreContext = exports.stubContext = exports.instantiateContext = exports.uniqid = void 0;
|
|
11
15
|
const crypto_1 = require("crypto");
|
|
12
16
|
const events_1 = require("events");
|
|
13
17
|
const os_1 = require("os");
|
|
@@ -133,7 +137,7 @@ const instantiateContext = (sinon) => {
|
|
|
133
137
|
fakeConnectionRequest: defaultFakeConnectionRequest,
|
|
134
138
|
getConfigStubContents(name, group) {
|
|
135
139
|
const stub = this.configStubs[name];
|
|
136
|
-
if (stub
|
|
140
|
+
if (stub?.contents) {
|
|
137
141
|
if (group && stub.contents[group]) {
|
|
138
142
|
return (0, ts_types_1.ensureJsonMap)(stub.contents[group]);
|
|
139
143
|
}
|
|
@@ -160,12 +164,10 @@ const instantiateContext = (sinon) => {
|
|
|
160
164
|
}
|
|
161
165
|
},
|
|
162
166
|
async stubAuths(...orgs) {
|
|
163
|
-
const entries =
|
|
167
|
+
const entries = await Promise.all(orgs.map(async (org) => [org.username, await org.getConfig()]));
|
|
164
168
|
const orgMap = new Map(entries);
|
|
165
|
-
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'getAllFiles').
|
|
166
|
-
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'hasFile').callsFake((username) =>
|
|
167
|
-
return orgMap.has(username);
|
|
168
|
-
});
|
|
169
|
+
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'getAllFiles').resolves([...orgMap.keys()].map((o) => `${o}.json`));
|
|
170
|
+
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'hasFile').callsFake((username) => orgMap.has(username));
|
|
169
171
|
const retrieveContents = async function () {
|
|
170
172
|
const username = (0, path_1.basename)(this.path.replace('.json', ''));
|
|
171
173
|
return Promise.resolve(orgMap.get(username) ?? {});
|
|
@@ -175,7 +177,7 @@ const instantiateContext = (sinon) => {
|
|
|
175
177
|
async stubSandboxes(...sandboxes) {
|
|
176
178
|
const entries = (await Promise.all(sandboxes.map(async (sanbox) => [sanbox.username, await sanbox.getConfig()])));
|
|
177
179
|
const sandboxMap = new Map(entries);
|
|
178
|
-
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, sandboxAccessor_1.SandboxAccessor.prototype, 'getAllFiles').
|
|
180
|
+
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, sandboxAccessor_1.SandboxAccessor.prototype, 'getAllFiles').resolves([...sandboxMap.keys()].map((o) => `${o}.sandbox.json`));
|
|
179
181
|
const retrieveContents = async function () {
|
|
180
182
|
const username = (0, path_1.basename)(this.path.replace('.sandbox.json', ''));
|
|
181
183
|
return Promise.resolve(sandboxMap.get(username) ?? {});
|
|
@@ -185,8 +187,11 @@ const instantiateContext = (sinon) => {
|
|
|
185
187
|
stubAliases(aliases, group = aliasesConfig_1.AliasGroup.ORGS) {
|
|
186
188
|
this.configStubs.AliasesConfig = { contents: { [group]: aliases } };
|
|
187
189
|
},
|
|
188
|
-
stubConfig(config) {
|
|
190
|
+
async stubConfig(config) {
|
|
189
191
|
this.configStubs.Config = { contents: config };
|
|
192
|
+
// configAggregator may have already loaded an instance. We're not sure why this happens.
|
|
193
|
+
// This seems to solve the problem by forcing a load of the new stubbed config.
|
|
194
|
+
await configAggregator_1.ConfigAggregator.create();
|
|
190
195
|
},
|
|
191
196
|
stubTokens(tokens) {
|
|
192
197
|
this.configStubs.TokensConfig = { contents: tokens };
|
|
@@ -225,14 +230,14 @@ const stubContext = (testContext) => {
|
|
|
225
230
|
global_1.Global.SFDX_INTEROPERABILITY = false;
|
|
226
231
|
const stubs = {};
|
|
227
232
|
// Most core files create a child logger so stub this to return our test logger.
|
|
228
|
-
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'child').
|
|
233
|
+
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'child').resolves(testContext.TEST_LOGGER);
|
|
229
234
|
(0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'childFromRoot').returns(testContext.TEST_LOGGER);
|
|
230
235
|
testContext.inProject(true);
|
|
231
236
|
testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile, 'resolveRootFolder').callsFake((isGlobal) => testContext.rootPathRetriever(isGlobal, testContext.id));
|
|
232
237
|
testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile, 'resolveRootFolderSync').callsFake((isGlobal) => testContext.rootPathRetrieverSync(isGlobal, testContext.id));
|
|
233
238
|
(0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.PROJECT, sfProject_1.SfProjectJson.prototype, 'doesPackageExist').callsFake(() => true);
|
|
234
239
|
const initStubForRead = (configFile) => {
|
|
235
|
-
const stub = testContext.configStubs[configFile.constructor.name]
|
|
240
|
+
const stub = testContext.configStubs[configFile.constructor.name] ?? {};
|
|
236
241
|
// init calls read calls getPath which sets the path on the config file the first time.
|
|
237
242
|
// Since read is now stubbed, make sure to call getPath to initialize it.
|
|
238
243
|
configFile.getPath();
|
|
@@ -242,13 +247,13 @@ const stubContext = (testContext) => {
|
|
|
242
247
|
};
|
|
243
248
|
const readSync = function (newContents) {
|
|
244
249
|
const stub = initStubForRead(this);
|
|
245
|
-
this.setContentsFromObject(newContents
|
|
250
|
+
this.setContentsFromObject(newContents ?? stub.contents ?? {});
|
|
246
251
|
return this.getContents();
|
|
247
252
|
};
|
|
248
253
|
const read = async function () {
|
|
249
254
|
const stub = initStubForRead(this);
|
|
250
255
|
if (stub.readFn) {
|
|
251
|
-
return
|
|
256
|
+
return stub.readFn.call(this);
|
|
252
257
|
}
|
|
253
258
|
if (stub.retrieveContents) {
|
|
254
259
|
return readSync.call(this, await stub.retrieveContents.call(this));
|
|
@@ -268,7 +273,7 @@ const stubContext = (testContext) => {
|
|
|
268
273
|
const stub = testContext.configStubs[this.constructor.name];
|
|
269
274
|
if (!stub)
|
|
270
275
|
return;
|
|
271
|
-
this.setContents(newContents
|
|
276
|
+
this.setContents(newContents ?? this.getContents());
|
|
272
277
|
stub.contents = this.toObject();
|
|
273
278
|
};
|
|
274
279
|
const write = async function (newContents) {
|
|
@@ -279,7 +284,7 @@ const stubContext = (testContext) => {
|
|
|
279
284
|
if (!stub)
|
|
280
285
|
return;
|
|
281
286
|
if (stub.writeFn) {
|
|
282
|
-
return
|
|
287
|
+
return stub.writeFn.call(this, newContents);
|
|
283
288
|
}
|
|
284
289
|
if (stub.updateContents) {
|
|
285
290
|
writeSync.call(this, await stub.updateContents.call(this));
|
|
@@ -341,13 +346,14 @@ exports.stubContext = stubContext;
|
|
|
341
346
|
*/
|
|
342
347
|
const restoreContext = (testContext) => {
|
|
343
348
|
testContext.SANDBOX.restore();
|
|
349
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
344
350
|
Object.values(testContext.SANDBOXES).forEach((theSandbox) => theSandbox.restore());
|
|
345
351
|
testContext.configStubs = {};
|
|
346
352
|
// Give each test run a clean StateAggregator
|
|
347
353
|
stateAggregator_1.StateAggregator.clearInstance();
|
|
348
354
|
};
|
|
349
355
|
exports.restoreContext = restoreContext;
|
|
350
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
356
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-underscore-dangle
|
|
351
357
|
const _testSetup = (sinon) => {
|
|
352
358
|
const testContext = (0, exports.instantiateContext)(sinon);
|
|
353
359
|
beforeEach(() => {
|
|
@@ -582,15 +588,17 @@ exports.StreamingMockCometClient = StreamingMockCometClient;
|
|
|
582
588
|
* Mock class for Salesforce Orgs.
|
|
583
589
|
*
|
|
584
590
|
* @example
|
|
591
|
+
* ```
|
|
585
592
|
* const testOrg = new MockTestOrgData();
|
|
586
593
|
* await $$.stubAuths(testOrg)
|
|
594
|
+
* ```
|
|
587
595
|
*/
|
|
588
596
|
class MockTestOrgData {
|
|
589
597
|
constructor(id = uniqid(), options) {
|
|
590
598
|
this.testId = id;
|
|
591
599
|
this.userId = `user_id_${this.testId}`;
|
|
592
600
|
this.orgId = `${this.testId}`;
|
|
593
|
-
this.username = options?.username
|
|
601
|
+
this.username = options?.username ?? `admin_${this.testId}@gb.org`;
|
|
594
602
|
this.loginUrl = `https://login.${this.testId}.salesforce.com`;
|
|
595
603
|
this.instanceUrl = `https://instance.${this.testId}.salesforce.com`;
|
|
596
604
|
this.clientId = `${this.testId}/client_id`;
|
|
@@ -690,20 +698,23 @@ exports.MockTestOrgData = MockTestOrgData;
|
|
|
690
698
|
* Mock class for Salesforce Sandboxes.
|
|
691
699
|
*
|
|
692
700
|
* @example
|
|
701
|
+
* ```
|
|
693
702
|
* const testOrg = new MockTestSandboxData();
|
|
694
703
|
* await $$.stubSandboxes(testOrg)
|
|
704
|
+
* ```
|
|
695
705
|
*/
|
|
696
706
|
class MockTestSandboxData {
|
|
697
707
|
constructor(id = uniqid(), options) {
|
|
698
708
|
this.id = id;
|
|
699
709
|
this.sandboxOrgId = id;
|
|
700
|
-
this.prodOrgUsername = options?.prodOrgUsername
|
|
701
|
-
this.sandboxName = options?.name
|
|
702
|
-
this.username = options?.username
|
|
710
|
+
this.prodOrgUsername = options?.prodOrgUsername ?? `admin_${id}@gb.org`;
|
|
711
|
+
this.sandboxName = options?.name ?? `sandbox_${id}`;
|
|
712
|
+
this.username = options?.username ?? `${this.prodOrgUsername}.sandbox`;
|
|
703
713
|
}
|
|
704
714
|
/**
|
|
705
715
|
* Return the auth config file contents.
|
|
706
716
|
*/
|
|
717
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
707
718
|
async getConfig() {
|
|
708
719
|
return {
|
|
709
720
|
sandboxOrgId: this.sandboxOrgId,
|
package/lib/util/cache.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare class Cache extends Map {
|
|
2
2
|
#private;
|
|
3
3
|
private constructor();
|
|
4
|
+
static get hits(): number;
|
|
5
|
+
static get lookups(): number;
|
|
4
6
|
static instance(): Cache;
|
|
5
7
|
static set<V>(key: string, value: V): void;
|
|
6
8
|
static get<V>(key: string): V | undefined;
|
|
7
9
|
static disable(): void;
|
|
8
10
|
static enable(): void;
|
|
9
|
-
static get hits(): number;
|
|
10
|
-
static get lookups(): number;
|
|
11
11
|
}
|
package/lib/util/cache.js
CHANGED
|
@@ -28,6 +28,12 @@ class Cache extends Map {
|
|
|
28
28
|
__classPrivateFieldSet(this, _Cache_hits, 0, "f");
|
|
29
29
|
__classPrivateFieldSet(this, _Cache_lookups, 0, "f");
|
|
30
30
|
}
|
|
31
|
+
static get hits() {
|
|
32
|
+
return __classPrivateFieldGet(Cache.instance(), _Cache_hits, "f");
|
|
33
|
+
}
|
|
34
|
+
static get lookups() {
|
|
35
|
+
return __classPrivateFieldGet(Cache.instance(), _Cache_lookups, "f");
|
|
36
|
+
}
|
|
31
37
|
static instance() {
|
|
32
38
|
if (!__classPrivateFieldGet(Cache, _a, "f", _Cache_instance)) {
|
|
33
39
|
__classPrivateFieldSet(Cache, _a, true, "f", _Cache_enabled);
|
|
@@ -55,12 +61,6 @@ class Cache extends Map {
|
|
|
55
61
|
static enable() {
|
|
56
62
|
__classPrivateFieldSet(Cache, _a, true, "f", _Cache_enabled);
|
|
57
63
|
}
|
|
58
|
-
static get hits() {
|
|
59
|
-
return __classPrivateFieldGet(Cache.instance(), _Cache_hits, "f");
|
|
60
|
-
}
|
|
61
|
-
static get lookups() {
|
|
62
|
-
return __classPrivateFieldGet(Cache.instance(), _Cache_lookups, "f");
|
|
63
|
-
}
|
|
64
64
|
}
|
|
65
65
|
exports.Cache = Cache;
|
|
66
66
|
_a = Cache, _Cache_hits = new WeakMap(), _Cache_lookups = new WeakMap();
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { Readable } from 'stream';
|
|
3
4
|
import { StructuredWriter } from './structuredWriter';
|
|
4
5
|
export declare class DirectoryWriter implements StructuredWriter {
|
|
5
6
|
private readonly rootDestination?;
|
|
6
7
|
constructor(rootDestination?: string | undefined);
|
|
8
|
+
get buffer(): Buffer;
|
|
7
9
|
addToStore(contents: string | Readable | Buffer, targetPath: string): Promise<void>;
|
|
8
10
|
finalize(): Promise<void>;
|
|
9
11
|
getDestinationPath(): string | undefined;
|
|
10
|
-
get buffer(): Buffer;
|
|
11
12
|
}
|
|
@@ -23,6 +23,10 @@ class DirectoryWriter {
|
|
|
23
23
|
fs.mkdirSync(this.rootDestination, { recursive: true });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
// eslint-disable-next-line class-methods-use-this
|
|
27
|
+
get buffer() {
|
|
28
|
+
throw new Error('Not implemented');
|
|
29
|
+
}
|
|
26
30
|
async addToStore(contents, targetPath) {
|
|
27
31
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
28
32
|
const destPath = path.join(this.rootDestination, targetPath);
|
|
@@ -38,15 +42,13 @@ class DirectoryWriter {
|
|
|
38
42
|
fs.writeFileSync(destPath, contents);
|
|
39
43
|
}
|
|
40
44
|
}
|
|
45
|
+
// eslint-disable-next-line class-methods-use-this
|
|
41
46
|
finalize() {
|
|
42
47
|
return Promise.resolve(undefined);
|
|
43
48
|
}
|
|
44
49
|
getDestinationPath() {
|
|
45
50
|
return this.rootDestination;
|
|
46
51
|
}
|
|
47
|
-
get buffer() {
|
|
48
|
-
throw new Error('Not implemented');
|
|
49
|
-
}
|
|
50
52
|
}
|
|
51
53
|
exports.DirectoryWriter = DirectoryWriter;
|
|
52
54
|
//# sourceMappingURL=directoryWriter.js.map
|
package/lib/util/jsonXmlTools.js
CHANGED
|
@@ -21,12 +21,10 @@ exports.standardOptions = {
|
|
|
21
21
|
};
|
|
22
22
|
const writeJSONasXML = async ({ path, json, type, options = exports.standardOptions, }) => {
|
|
23
23
|
const xml = jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
|
|
24
|
-
return
|
|
24
|
+
return fs_1.promises.writeFile(path, xml);
|
|
25
25
|
};
|
|
26
26
|
exports.writeJSONasXML = writeJSONasXML;
|
|
27
|
-
const JsonAsXml = ({ json, type, options = exports.standardOptions }) =>
|
|
28
|
-
return jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
|
|
29
|
-
};
|
|
27
|
+
const JsonAsXml = ({ json, type, options = exports.standardOptions }) => jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
|
|
30
28
|
exports.JsonAsXml = JsonAsXml;
|
|
31
29
|
const fixExistingDollarSign = (existing) => {
|
|
32
30
|
const existingCopy = { ...existing };
|
package/lib/util/mapKeys.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Use mapKeys to convert object keys to another format using the specified conversion function.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* NOTE: This mutates the object passed in for conversion.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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
13
|
*/
|
|
14
|
-
export default function mapKeys(obj:
|
|
14
|
+
export default function mapKeys<T>(obj: T, converter: (key: string) => string, deep?: boolean): Record<string, unknown>;
|
package/lib/util/mapKeys.js
CHANGED
|
@@ -8,23 +8,26 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Use mapKeys to convert object keys to another format using the specified conversion function.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* NOTE: This mutates the object passed in for conversion.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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
22
|
*/
|
|
23
23
|
function mapKeys(
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
25
25
|
obj, converter, deep) {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
26
27
|
const target = Object.assign({}, obj);
|
|
27
|
-
return Object.fromEntries(
|
|
28
|
+
return Object.fromEntries(
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
30
|
+
Object.entries(target).map(([key, value]) => {
|
|
28
31
|
const k = converter.call(null, key);
|
|
29
32
|
if (deep) {
|
|
30
33
|
let v = value;
|
|
@@ -33,6 +36,7 @@ obj, converter, deep) {
|
|
|
33
36
|
if ((0, ts_types_1.isPlainObject)(v1)) {
|
|
34
37
|
return mapKeys(v1, converter, deep);
|
|
35
38
|
}
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
36
40
|
return v1;
|
|
37
41
|
});
|
|
38
42
|
}
|
package/lib/util/sfdc.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const sfdc: {
|
|
|
5
5
|
*
|
|
6
6
|
* @param id The id to convert.
|
|
7
7
|
*/
|
|
8
|
-
trimTo15: (id?: string
|
|
8
|
+
trimTo15: (id?: string) => Optional<string>;
|
|
9
9
|
/**
|
|
10
10
|
* Tests whether an API version matches the format `i.0`.
|
|
11
11
|
*
|
|
@@ -36,7 +36,7 @@ export declare const sfdc: {
|
|
|
36
36
|
* @param data The object in which to check key casing.
|
|
37
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`.
|
|
38
38
|
*/
|
|
39
|
-
findUpperCaseKeys: (data?: JsonMap
|
|
39
|
+
findUpperCaseKeys: (data?: JsonMap, sectionBlocklist?: string[]) => Optional<string>;
|
|
40
40
|
/**
|
|
41
41
|
* Tests whether a given string is an access token
|
|
42
42
|
*
|
package/lib/util/sfdc.js
CHANGED
|
@@ -17,7 +17,7 @@ exports.sfdc = {
|
|
|
17
17
|
* @param id The id to convert.
|
|
18
18
|
*/
|
|
19
19
|
trimTo15: (id) => {
|
|
20
|
-
if (id
|
|
20
|
+
if (id?.length && id.length > 15) {
|
|
21
21
|
id = id.substring(0, 15);
|
|
22
22
|
}
|
|
23
23
|
return id;
|
|
@@ -27,34 +27,27 @@ exports.sfdc = {
|
|
|
27
27
|
*
|
|
28
28
|
* @param value The API version as a string.
|
|
29
29
|
*/
|
|
30
|
-
validateApiVersion: (value) =>
|
|
31
|
-
return value == null || /^[1-9]\d\.0$/.test(value);
|
|
32
|
-
},
|
|
30
|
+
validateApiVersion: (value) => value == null || /^[1-9]\d\.0$/.test(value),
|
|
33
31
|
/**
|
|
34
32
|
* Tests whether an email matches the format `me@my.org`
|
|
35
33
|
*
|
|
36
34
|
* @param value The email as a string.
|
|
37
35
|
*/
|
|
38
|
-
validateEmail: (value) =>
|
|
39
|
-
return /^[^.][^@]*@[^.]+(\.[^.\s]+)+$/.test(value);
|
|
40
|
-
},
|
|
36
|
+
validateEmail: (value) => /^[^.][^@]*@[^.]+(\.[^.\s]+)+$/.test(value),
|
|
41
37
|
/**
|
|
42
38
|
* Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
|
|
43
39
|
*
|
|
44
40
|
* @param value The ID as a string.
|
|
45
41
|
*/
|
|
46
|
-
validateSalesforceId: (value) => {
|
|
47
|
-
return /[a-zA-Z0-9]{18}|[a-zA-Z0-9]{15}/.test(value) && (value.length === 15 || value.length === 18);
|
|
48
|
-
},
|
|
42
|
+
validateSalesforceId: (value) => /[a-zA-Z0-9]{18}|[a-zA-Z0-9]{15}/.test(value) && (value.length === 15 || value.length === 18),
|
|
49
43
|
/**
|
|
50
44
|
* Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
|
|
51
45
|
*
|
|
52
46
|
* @param value The path as a string.
|
|
53
47
|
*/
|
|
54
|
-
validatePathDoesNotContainInvalidChars: (value) =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
48
|
+
validatePathDoesNotContainInvalidChars: (value) =>
|
|
49
|
+
// eslint-disable-next-line no-useless-escape
|
|
50
|
+
!/[\["\?<>\|\]]+/.test(value),
|
|
58
51
|
/**
|
|
59
52
|
* Returns the first key within the object that has an upper case first letter.
|
|
60
53
|
*
|
|
@@ -82,9 +75,7 @@ exports.sfdc = {
|
|
|
82
75
|
*
|
|
83
76
|
* @param value
|
|
84
77
|
*/
|
|
85
|
-
matchesAccessToken: (value) => {
|
|
86
|
-
return /^(00D\w{12,15})![.\w]*$/.test(value);
|
|
87
|
-
},
|
|
78
|
+
matchesAccessToken: (value) => /^(00D\w{12,15})![.\w]*$/.test(value),
|
|
88
79
|
/**
|
|
89
80
|
* Tests whether a given url is an internal Salesforce domain
|
|
90
81
|
*
|