@salesforce/core 4.0.0 → 4.0.1
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 +1 -1
- package/README.md +93 -44
- package/lib/config/aliasesConfig.d.ts +12 -0
- package/lib/config/aliasesConfig.js +28 -0
- package/lib/config/authInfoConfig.d.ts +19 -0
- package/lib/config/authInfoConfig.js +35 -0
- package/lib/config/config.d.ts +87 -22
- package/lib/config/config.js +117 -65
- package/lib/config/configAggregator.d.ts +41 -35
- package/lib/config/configAggregator.js +102 -73
- package/lib/config/configFile.d.ts +2 -2
- package/lib/config/configFile.js +38 -29
- package/lib/config/configGroup.d.ts +141 -0
- package/lib/config/configGroup.js +225 -0
- package/lib/config/configStore.d.ts +9 -9
- package/lib/config/configStore.js +17 -15
- package/lib/config/envVars.d.ts +15 -9
- package/lib/config/envVars.js +71 -47
- package/lib/config/orgUsersConfig.js +2 -0
- package/lib/config/sandboxOrgConfig.js +2 -0
- package/lib/config/sandboxProcessCache.d.ts +16 -0
- package/lib/config/sandboxProcessCache.js +38 -0
- package/lib/config/tokensConfig.d.ts +10 -0
- package/lib/config/tokensConfig.js +29 -0
- package/lib/config/ttlConfig.d.ts +34 -0
- package/lib/config/ttlConfig.js +50 -0
- package/lib/crypto/crypto.js +15 -22
- package/lib/crypto/keyChain.js +2 -3
- package/lib/crypto/keyChainImpl.d.ts +5 -3
- package/lib/crypto/keyChainImpl.js +58 -61
- package/lib/crypto/secureBuffer.d.ts +1 -1
- package/lib/deviceOauthService.d.ts +3 -3
- package/lib/deviceOauthService.js +27 -25
- package/lib/exported.d.ts +15 -12
- package/lib/exported.js +28 -16
- package/lib/global.d.ts +11 -3
- package/lib/global.js +39 -12
- package/lib/lifecycleEvents.d.ts +1 -1
- package/lib/lifecycleEvents.js +3 -0
- package/lib/logger.d.ts +19 -9
- package/lib/logger.js +112 -86
- package/lib/messages.d.ts +53 -36
- package/lib/messages.js +81 -91
- package/lib/org/authInfo.d.ts +56 -20
- package/lib/org/authInfo.js +232 -131
- package/lib/org/authRemover.d.ts +8 -7
- package/lib/org/authRemover.js +32 -28
- package/lib/org/connection.d.ts +13 -37
- package/lib/org/connection.js +78 -124
- package/lib/org/index.js +5 -1
- package/lib/org/org.d.ts +151 -48
- package/lib/org/org.js +466 -220
- package/lib/org/orgConfigProperties.d.ts +64 -3
- package/lib/org/orgConfigProperties.js +96 -4
- package/lib/org/permissionSetAssignment.js +4 -13
- package/lib/org/scratchOrgCache.d.ts +20 -0
- package/lib/org/scratchOrgCache.js +33 -0
- package/lib/org/scratchOrgCreate.d.ts +28 -17
- package/lib/org/scratchOrgCreate.js +125 -53
- package/lib/org/scratchOrgErrorCodes.d.ts +9 -3
- package/lib/org/scratchOrgErrorCodes.js +34 -17
- package/lib/org/scratchOrgFeatureDeprecation.js +1 -6
- package/lib/org/scratchOrgInfoApi.d.ts +21 -47
- package/lib/org/scratchOrgInfoApi.js +129 -63
- package/lib/org/scratchOrgInfoGenerator.d.ts +6 -5
- package/lib/org/scratchOrgInfoGenerator.js +76 -62
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
- package/lib/org/scratchOrgLifecycleEvents.js +41 -0
- package/lib/org/scratchOrgSettingsGenerator.d.ts +44 -21
- package/lib/org/scratchOrgSettingsGenerator.js +165 -98
- package/lib/org/scratchOrgTypes.d.ts +43 -0
- package/lib/org/scratchOrgTypes.js +9 -0
- package/lib/org/user.d.ts +1 -1
- package/lib/org/user.js +25 -34
- package/lib/schema/printer.d.ts +6 -0
- package/lib/schema/printer.js +34 -31
- package/lib/schema/validator.d.ts +12 -10
- package/lib/schema/validator.js +56 -76
- package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -20
- package/lib/{sfdxError.js → sfError.js} +40 -30
- package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
- package/lib/sfProject.js +651 -0
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +27 -12
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +47 -31
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
- package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
- package/lib/stateAggregator/index.d.ts +4 -0
- package/lib/stateAggregator/index.js +27 -0
- package/lib/stateAggregator/stateAggregator.d.ts +25 -0
- package/lib/stateAggregator/stateAggregator.js +46 -0
- package/lib/status/myDomainResolver.d.ts +1 -1
- package/lib/status/myDomainResolver.js +4 -4
- package/lib/status/pollingClient.js +4 -4
- package/lib/status/streamingClient.d.ts +2 -2
- package/lib/status/streamingClient.js +58 -63
- package/lib/status/types.d.ts +2 -2
- package/lib/testSetup.d.ts +206 -75
- package/lib/testSetup.js +463 -165
- package/lib/util/cache.d.ts +2 -2
- package/lib/util/cache.js +6 -6
- package/lib/util/checkLightningDomain.js +3 -4
- package/lib/util/directoryWriter.d.ts +12 -0
- package/lib/util/directoryWriter.js +54 -0
- package/lib/util/getJwtAudienceUrl.js +1 -1
- package/lib/util/internal.d.ts +28 -2
- package/lib/util/internal.js +65 -8
- 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 +51 -51
- package/lib/util/sfdc.js +74 -79
- package/lib/util/sfdcUrl.d.ts +5 -19
- package/lib/util/sfdcUrl.js +40 -49
- package/lib/util/structuredWriter.d.ts +9 -0
- package/lib/util/structuredWriter.js +3 -0
- package/lib/util/zipWriter.d.ts +8 -6
- package/lib/util/zipWriter.js +13 -13
- package/lib/webOAuthServer.d.ts +20 -6
- package/lib/webOAuthServer.js +102 -56
- package/messageTransformer/messageTransformer.ts +93 -0
- package/messages/auth.md +9 -1
- package/messages/config.md +42 -6
- package/messages/connection.md +8 -0
- package/messages/core.md +10 -0
- package/messages/envVars.md +37 -3
- package/messages/org.md +21 -1
- package/messages/scratchOrgCreate.md +2 -6
- package/messages/scratchOrgErrorCodes.md +17 -1
- package/messages/scratchOrgInfoApi.md +9 -0
- package/messages/scratchOrgInfoGenerator.md +9 -1
- package/package.json +121 -46
- package/CHANGELOG.md +0 -1244
- package/lib/config/keychainConfig.d.ts +0 -19
- package/lib/config/keychainConfig.js +0 -43
- 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/accessors/tokenAccessor.js +0 -35
- package/lib/globalInfo/globalInfoConfig.d.ts +0 -36
- package/lib/globalInfo/globalInfoConfig.js +0 -105
- package/lib/globalInfo/index.d.ts +0 -6
- package/lib/globalInfo/index.js +0 -29
- package/lib/globalInfo/sfdxDataHandler.d.ts +0 -43
- package/lib/globalInfo/sfdxDataHandler.js +0 -217
- package/lib/globalInfo/types.d.ts +0 -39
- package/lib/globalInfo/types.js +0 -10
- package/lib/sfdxProject.js +0 -557
- package/lib/util/fs.d.ts +0 -201
- package/lib/util/fs.js +0 -378
|
@@ -0,0 +1,80 @@
|
|
|
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.TokenAccessor = void 0;
|
|
10
|
+
const kit_1 = require("@salesforce/kit");
|
|
11
|
+
const tokensConfig_1 = require("../../config/tokensConfig");
|
|
12
|
+
class TokenAccessor extends kit_1.AsyncOptionalCreatable {
|
|
13
|
+
/**
|
|
14
|
+
* Return all tokens.
|
|
15
|
+
*
|
|
16
|
+
* @param decrypt
|
|
17
|
+
* @returns {SfTokens}
|
|
18
|
+
*/
|
|
19
|
+
getAll(decrypt = false) {
|
|
20
|
+
return this.config.getContents(decrypt) || {};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Return a token for the provided name.
|
|
24
|
+
*
|
|
25
|
+
* @param name
|
|
26
|
+
* @param decrypt
|
|
27
|
+
* @returns {Optional<SfToken>}
|
|
28
|
+
*/
|
|
29
|
+
get(name, decrypt = false) {
|
|
30
|
+
return this.config.get(name, decrypt);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Return true if a given name has a token associated with it.
|
|
34
|
+
*
|
|
35
|
+
* @param name
|
|
36
|
+
* @returns {boolean}
|
|
37
|
+
*/
|
|
38
|
+
has(name) {
|
|
39
|
+
return !!this.getAll()[name];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Set the token for the provided name.
|
|
43
|
+
*
|
|
44
|
+
* @param name
|
|
45
|
+
* @param token
|
|
46
|
+
*/
|
|
47
|
+
set(name, token) {
|
|
48
|
+
this.config.set(name, token);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Update the token for the provided name.
|
|
52
|
+
*
|
|
53
|
+
* @param name
|
|
54
|
+
* @param token
|
|
55
|
+
*/
|
|
56
|
+
update(name, token) {
|
|
57
|
+
this.config.update(name, token);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Unet the token for the provided name.
|
|
61
|
+
*
|
|
62
|
+
* @param name
|
|
63
|
+
*/
|
|
64
|
+
unset(name) {
|
|
65
|
+
this.config.unset(name);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Write the contents to the token file.
|
|
69
|
+
*
|
|
70
|
+
* @returns {Promise<SfTokens>}
|
|
71
|
+
*/
|
|
72
|
+
async write() {
|
|
73
|
+
return this.config.write();
|
|
74
|
+
}
|
|
75
|
+
async init() {
|
|
76
|
+
this.config = await tokensConfig_1.TokensConfig.create();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.TokenAccessor = TokenAccessor;
|
|
80
|
+
//# sourceMappingURL=tokenAccessor.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./accessors/orgAccessor"), exports);
|
|
24
|
+
__exportStar(require("./accessors/aliasAccessor"), exports);
|
|
25
|
+
__exportStar(require("./accessors/tokenAccessor"), exports);
|
|
26
|
+
__exportStar(require("./stateAggregator"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
2
|
+
import { AliasAccessor } from './accessors/aliasAccessor';
|
|
3
|
+
import { OrgAccessor } from './accessors/orgAccessor';
|
|
4
|
+
import { SandboxAccessor } from './accessors/sandboxAccessor';
|
|
5
|
+
import { TokenAccessor } from './accessors/tokenAccessor';
|
|
6
|
+
export declare class StateAggregator extends AsyncOptionalCreatable {
|
|
7
|
+
private static instanceMap;
|
|
8
|
+
aliases: AliasAccessor;
|
|
9
|
+
orgs: OrgAccessor;
|
|
10
|
+
sandboxes: SandboxAccessor;
|
|
11
|
+
tokens: TokenAccessor;
|
|
12
|
+
/**
|
|
13
|
+
* Reuse a StateAggregator if one was already created for the current global state directory
|
|
14
|
+
* Otherwise, create one and adds it to map for future reuse.
|
|
15
|
+
* HomeDir might be stubbed in tests
|
|
16
|
+
*/
|
|
17
|
+
static getInstance(): Promise<StateAggregator>;
|
|
18
|
+
/**
|
|
19
|
+
* Clear the cache to force reading from disk.
|
|
20
|
+
*
|
|
21
|
+
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
22
|
+
*/
|
|
23
|
+
static clearInstance(path?: string): void;
|
|
24
|
+
protected init(): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022, 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.StateAggregator = void 0;
|
|
10
|
+
const kit_1 = require("@salesforce/kit");
|
|
11
|
+
const global_1 = require("../global");
|
|
12
|
+
const aliasAccessor_1 = require("./accessors/aliasAccessor");
|
|
13
|
+
const orgAccessor_1 = require("./accessors/orgAccessor");
|
|
14
|
+
const sandboxAccessor_1 = require("./accessors/sandboxAccessor");
|
|
15
|
+
const tokenAccessor_1 = require("./accessors/tokenAccessor");
|
|
16
|
+
class StateAggregator extends kit_1.AsyncOptionalCreatable {
|
|
17
|
+
/**
|
|
18
|
+
* Reuse a StateAggregator if one was already created for the current global state directory
|
|
19
|
+
* Otherwise, create one and adds it to map for future reuse.
|
|
20
|
+
* HomeDir might be stubbed in tests
|
|
21
|
+
*/
|
|
22
|
+
static async getInstance() {
|
|
23
|
+
if (!StateAggregator.instanceMap.has(global_1.Global.DIR)) {
|
|
24
|
+
StateAggregator.instanceMap.set(global_1.Global.DIR, await StateAggregator.create());
|
|
25
|
+
}
|
|
26
|
+
// TS assertion is valid because there either was one OR it was just now instantiated
|
|
27
|
+
return StateAggregator.instanceMap.get(global_1.Global.DIR);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Clear the cache to force reading from disk.
|
|
31
|
+
*
|
|
32
|
+
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
33
|
+
*/
|
|
34
|
+
static clearInstance(path = global_1.Global.DIR) {
|
|
35
|
+
StateAggregator.instanceMap.delete(path);
|
|
36
|
+
}
|
|
37
|
+
async init() {
|
|
38
|
+
this.orgs = await orgAccessor_1.OrgAccessor.create();
|
|
39
|
+
this.sandboxes = await sandboxAccessor_1.SandboxAccessor.create();
|
|
40
|
+
this.aliases = await aliasAccessor_1.AliasAccessor.create();
|
|
41
|
+
this.tokens = await tokenAccessor_1.TokenAccessor.create();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.StateAggregator = StateAggregator;
|
|
45
|
+
StateAggregator.instanceMap = new Map();
|
|
46
|
+
//# sourceMappingURL=stateAggregator.js.map
|
|
@@ -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
|
|
@@ -11,7 +11,7 @@ const kit_1 = require("@salesforce/kit");
|
|
|
11
11
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
12
|
const ts_retry_promise_1 = require("ts-retry-promise");
|
|
13
13
|
const logger_1 = require("../logger");
|
|
14
|
-
const
|
|
14
|
+
const sfError_1 = require("../sfError");
|
|
15
15
|
const lifecycleEvents_1 = require("../lifecycleEvents");
|
|
16
16
|
/**
|
|
17
17
|
* This is a polling client that can be used to poll the status of long running tasks. It can be used as a replacement
|
|
@@ -53,7 +53,6 @@ class PollingClient extends kit_1.AsyncOptionalCreatable {
|
|
|
53
53
|
* in the polling options.
|
|
54
54
|
*/
|
|
55
55
|
async subscribe() {
|
|
56
|
-
var _a;
|
|
57
56
|
let errorInPollingFunction; // keep this around for returning in the catch block
|
|
58
57
|
const doPoll = async () => {
|
|
59
58
|
let result;
|
|
@@ -65,7 +64,7 @@ class PollingClient extends kit_1.AsyncOptionalCreatable {
|
|
|
65
64
|
if (['ETIMEDOUT', 'ENOTFOUND', 'ECONNRESET', 'socket hang up'].some((retryableNetworkError) => err.message.includes(retryableNetworkError))) {
|
|
66
65
|
this.logger.debug('Network error on the request', err);
|
|
67
66
|
await lifecycleEvents_1.Lifecycle.getInstance().emitWarning('Network error occurred. Continuing to poll.');
|
|
68
|
-
throw
|
|
67
|
+
throw sfError_1.SfError.wrap(err);
|
|
69
68
|
}
|
|
70
69
|
// there was an actual error thrown, so we don't want to keep retrying
|
|
71
70
|
throw new ts_retry_promise_1.NotRetryableError(err.name);
|
|
@@ -87,8 +86,9 @@ class PollingClient extends kit_1.AsyncOptionalCreatable {
|
|
|
87
86
|
if (errorInPollingFunction) {
|
|
88
87
|
throw errorInPollingFunction;
|
|
89
88
|
}
|
|
89
|
+
await lifecycleEvents_1.Lifecycle.getInstance().emit('POLLING_TIME_OUT', error);
|
|
90
90
|
this.logger.debug('Polling timed out');
|
|
91
|
-
throw new
|
|
91
|
+
throw new sfError_1.SfError('The client has timed out.', this.options.timeoutErrorName ?? 'PollingClientTimeout');
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncOptionalCreatable, Duration, Env } from '@salesforce/kit/lib';
|
|
2
2
|
import { AnyJson } from '@salesforce/ts-types/lib';
|
|
3
|
-
import { Org } from '../org';
|
|
3
|
+
import { Org } from '../org/org';
|
|
4
4
|
import { CometClient, CometSubscription, Message, StatusResult, StreamingExtension, StreamProcessor } from './types';
|
|
5
5
|
export { CometClient, CometSubscription, Message, StatusResult, StreamingExtension, StreamProcessor };
|
|
6
6
|
/**
|
|
@@ -113,7 +113,7 @@ export declare class StreamingClient extends AsyncOptionalCreatable<StreamingCli
|
|
|
113
113
|
* Subscribe to streaming events. When the streaming processor that's set in the options completes execution it
|
|
114
114
|
* returns a payload in the StatusResult object. The payload is just echoed here for convenience.
|
|
115
115
|
*
|
|
116
|
-
* **Throws** *{@link
|
|
116
|
+
* **Throws** *{@link SfError}{ name: '{@link StreamingClient.TimeoutErrorType.SUBSCRIBE}'}* When the subscribe timeout occurs.
|
|
117
117
|
*
|
|
118
118
|
* @param streamInit This function should call the platform apis that result in streaming updates on push topics.
|
|
119
119
|
* {@link StatusResult}
|
|
@@ -13,18 +13,11 @@ const lib_1 = require("@salesforce/kit/lib");
|
|
|
13
13
|
const lib_2 = require("@salesforce/ts-types/lib");
|
|
14
14
|
const Faye = require("faye");
|
|
15
15
|
const logger_1 = require("../logger");
|
|
16
|
-
const
|
|
16
|
+
const sfError_1 = require("../sfError");
|
|
17
17
|
const messages_1 = require("../messages");
|
|
18
18
|
const types_1 = require("./types");
|
|
19
19
|
Object.defineProperty(exports, "CometClient", { enumerable: true, get: function () { return types_1.CometClient; } });
|
|
20
|
-
messages_1.Messages.
|
|
21
|
-
const messages = messages_1.Messages.load('@salesforce/core', 'streaming', [
|
|
22
|
-
'waitParamValidValueError',
|
|
23
|
-
'genericHandshakeTimeout',
|
|
24
|
-
'invalidApiVersion',
|
|
25
|
-
'genericTimeout',
|
|
26
|
-
'handshakeApiVersionError',
|
|
27
|
-
]);
|
|
20
|
+
const messages = new messages_1.Messages('@salesforce/core', 'streaming', new Map([["genericTimeout", "Socket timeout occurred while listening for results."], ["genericHandshakeTimeout", "The streaming request failed to handshake at %s."], ["handshakeApiVersionError", "Invalid API version specified for streaming connection handshake: %s"], ["handshakeApiVersionError.actions", ["Set the API version to match the org as an environment variable (e.g., SFDX_API_VERSION=XX.0)."]], ["waitParamValidValueError", "Invalid value was specified for wait. Please provide a wait value greater than %s minutes."], ["invalidApiVersion", "Invalid api version is being reported by config (apiVersion=%s)."]]));
|
|
28
21
|
/**
|
|
29
22
|
* Validation helper
|
|
30
23
|
*
|
|
@@ -151,7 +144,7 @@ class StreamingClient extends lib_1.AsyncOptionalCreatable {
|
|
|
151
144
|
this.cometClient.setHeader('Authorization', `OAuth ${accessToken}`);
|
|
152
145
|
}
|
|
153
146
|
else {
|
|
154
|
-
throw new
|
|
147
|
+
throw new sfError_1.SfError('Missing or invalid access token', 'MissingOrInvalidAccessToken');
|
|
155
148
|
}
|
|
156
149
|
this.log(`Streaming client target url: ${this.targetUrl}`);
|
|
157
150
|
this.log(`options.subscribeTimeout (ms): ${this.options.subscribeTimeout.milliseconds}`);
|
|
@@ -201,7 +194,7 @@ class StreamingClient extends lib_1.AsyncOptionalCreatable {
|
|
|
201
194
|
* Subscribe to streaming events. When the streaming processor that's set in the options completes execution it
|
|
202
195
|
* returns a payload in the StatusResult object. The payload is just echoed here for convenience.
|
|
203
196
|
*
|
|
204
|
-
* **Throws** *{@link
|
|
197
|
+
* **Throws** *{@link SfError}{ name: '{@link StreamingClient.TimeoutErrorType.SUBSCRIBE}'}* When the subscribe timeout occurs.
|
|
205
198
|
*
|
|
206
199
|
* @param streamInit This function should call the platform apis that result in streaming updates on push topics.
|
|
207
200
|
* {@link StatusResult}
|
|
@@ -211,54 +204,52 @@ class StreamingClient extends lib_1.AsyncOptionalCreatable {
|
|
|
211
204
|
// This outer promise is to hold the streaming promise chain open until the streaming processor
|
|
212
205
|
// says it's complete.
|
|
213
206
|
// 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.
|
|
207
|
+
return new Promise((subscribeResolve, subscribeReject) =>
|
|
208
|
+
// This is the inner promise chain that's satisfied when the client impl (Faye/Mock) says it's subscribed.
|
|
209
|
+
new Promise((subscriptionResolve, subscriptionReject) => {
|
|
210
|
+
timeout = setTimeout(() => {
|
|
211
|
+
const timeoutError = messages.createError('genericTimeout');
|
|
212
|
+
this.doTimeout(timeout, timeoutError);
|
|
213
|
+
subscribeReject(timeoutError);
|
|
214
|
+
}, this.options.subscribeTimeout.milliseconds);
|
|
215
|
+
// Initialize the subscription.
|
|
216
|
+
const subscription = this.cometClient.subscribe(this.options.channel, (message) => {
|
|
217
|
+
try {
|
|
218
|
+
// The result of the stream processor determines the state of the outer promise.
|
|
219
|
+
const result = this.options.streamProcessor(message);
|
|
220
|
+
// The stream processor says it's complete. Clean up and resolve the outer promise.
|
|
221
|
+
if (result?.completed) {
|
|
237
222
|
clearTimeout(timeout);
|
|
238
223
|
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);
|
|
224
|
+
subscribeResolve(result.payload);
|
|
225
|
+
} // This 'if' is intended to be evaluated until it's completed or until the timeout fires.
|
|
226
|
+
}
|
|
227
|
+
catch (e) {
|
|
228
|
+
// it's completely valid for the stream processor to throw an error. If it does we will
|
|
229
|
+
// reject the outer promise. Keep in mind if we are here the subscription was resolved.
|
|
230
|
+
clearTimeout(timeout);
|
|
231
|
+
this.disconnectClient();
|
|
232
|
+
subscribeReject(e);
|
|
233
|
+
}
|
|
260
234
|
});
|
|
261
|
-
|
|
235
|
+
subscription.callback(() => {
|
|
236
|
+
subscriptionResolve();
|
|
237
|
+
});
|
|
238
|
+
subscription.errback((error) => {
|
|
239
|
+
subscriptionReject(error);
|
|
240
|
+
});
|
|
241
|
+
})
|
|
242
|
+
.then(() =>
|
|
243
|
+
// Now that we successfully have a subscription started up we are safe to initialize the function that
|
|
244
|
+
// will affect the streaming events. I.E. create an org or run apex tests.
|
|
245
|
+
streamInit?.())
|
|
246
|
+
.catch((error) => {
|
|
247
|
+
this.disconnect();
|
|
248
|
+
// Need to catch the subscription rejection or it will result in an unhandled rejection error.
|
|
249
|
+
clearTimeout(timeout);
|
|
250
|
+
// No subscription so we can reject the out promise as well.
|
|
251
|
+
subscribeReject(error);
|
|
252
|
+
}));
|
|
262
253
|
}
|
|
263
254
|
/**
|
|
264
255
|
* Handler for incoming streaming messages.
|
|
@@ -296,12 +287,17 @@ class StreamingClient extends lib_1.AsyncOptionalCreatable {
|
|
|
296
287
|
// unauthenticated connections are being made to salesforce. Let's close the dispatcher if it exists and
|
|
297
288
|
// has no clientId.
|
|
298
289
|
// @ts-ignore
|
|
290
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
299
291
|
if (this.cometClient._dispatcher) {
|
|
300
292
|
this.log('Closing the faye dispatcher');
|
|
301
293
|
// @ts-ignore
|
|
294
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, no-underscore-dangle
|
|
302
295
|
const dispatcher = this.cometClient._dispatcher;
|
|
296
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access
|
|
303
297
|
this.log(`dispatcher.clientId: ${dispatcher.clientId}`);
|
|
298
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
304
299
|
if (!dispatcher.clientId) {
|
|
300
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
305
301
|
dispatcher.close();
|
|
306
302
|
}
|
|
307
303
|
else {
|
|
@@ -342,13 +338,13 @@ exports.StreamingClient = StreamingClient;
|
|
|
342
338
|
logger.warn('envDep is deprecated');
|
|
343
339
|
}
|
|
344
340
|
if (!streamProcessor) {
|
|
345
|
-
throw new
|
|
341
|
+
throw new sfError_1.SfError('Missing stream processor', 'MissingArg');
|
|
346
342
|
}
|
|
347
343
|
if (!org) {
|
|
348
|
-
throw new
|
|
344
|
+
throw new sfError_1.SfError('Missing org', 'MissingArg');
|
|
349
345
|
}
|
|
350
346
|
if (!channel) {
|
|
351
|
-
throw new
|
|
347
|
+
throw new sfError_1.SfError('Missing streaming channel', 'MissingArg');
|
|
352
348
|
}
|
|
353
349
|
this.org = org;
|
|
354
350
|
this.apiVersion = org.getConnection().getApiVersion();
|
|
@@ -363,10 +359,9 @@ exports.StreamingClient = StreamingClient;
|
|
|
363
359
|
this.subscribeTimeout = StreamingClient.DefaultOptions.DEFAULT_SUBSCRIBE_TIMEOUT;
|
|
364
360
|
this.handshakeTimeout = StreamingClient.DefaultOptions.DEFAULT_HANDSHAKE_TIMEOUT;
|
|
365
361
|
this.streamingImpl = {
|
|
366
|
-
getCometClient: (url) =>
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
},
|
|
362
|
+
getCometClient: (url) =>
|
|
363
|
+
// @ts-ignore
|
|
364
|
+
new Faye.Client(url),
|
|
370
365
|
setLogger: (logLine) => {
|
|
371
366
|
// @ts-ignore
|
|
372
367
|
Faye.logger = {};
|
package/lib/status/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { AnyFunction, AnyJson, JsonMap } from '@salesforce/ts-types';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
4
|
+
export type Message = JsonMap;
|
|
5
|
+
export type Callback<T = unknown> = (...args: any[]) => T;
|
|
6
6
|
export interface StatusResult {
|
|
7
7
|
/**
|
|
8
8
|
* If the result of the streaming or polling client is expected to return a result
|