@salesforce/core 3.30.14 → 3.31.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +11 -11
- package/README.md +222 -227
- package/lib/config/aliasesConfig.d.ts +12 -12
- package/lib/config/aliasesConfig.js +27 -27
- package/lib/config/authInfoConfig.d.ts +19 -19
- package/lib/config/authInfoConfig.js +34 -34
- package/lib/config/config.d.ts +311 -311
- package/lib/config/config.js +574 -574
- package/lib/config/configAggregator.d.ts +232 -232
- package/lib/config/configAggregator.js +379 -379
- package/lib/config/configFile.d.ts +199 -199
- package/lib/config/configFile.js +340 -340
- package/lib/config/configGroup.d.ts +141 -141
- package/lib/config/configGroup.js +224 -224
- package/lib/config/configStore.d.ts +241 -241
- package/lib/config/configStore.js +352 -352
- package/lib/config/envVars.d.ts +101 -101
- package/lib/config/envVars.js +456 -456
- package/lib/config/orgUsersConfig.d.ts +31 -31
- package/lib/config/orgUsersConfig.js +41 -41
- package/lib/config/sandboxOrgConfig.d.ts +37 -37
- package/lib/config/sandboxOrgConfig.js +50 -50
- package/lib/config/sandboxProcessCache.d.ts +16 -16
- package/lib/config/sandboxProcessCache.js +37 -37
- package/lib/config/tokensConfig.d.ts +10 -10
- package/lib/config/tokensConfig.js +28 -28
- package/lib/config/ttlConfig.d.ts +34 -34
- package/lib/config/ttlConfig.js +54 -54
- package/lib/crypto/crypto.d.ts +54 -54
- package/lib/crypto/crypto.js +220 -220
- package/lib/crypto/keyChain.d.ts +8 -8
- package/lib/crypto/keyChain.js +61 -61
- package/lib/crypto/keyChainImpl.d.ts +116 -116
- package/lib/crypto/keyChainImpl.js +486 -486
- package/lib/crypto/secureBuffer.d.ts +46 -46
- package/lib/crypto/secureBuffer.js +82 -82
- package/lib/deviceOauthService.d.ts +71 -71
- package/lib/deviceOauthService.js +191 -191
- package/lib/exported.d.ts +38 -38
- package/lib/exported.js +118 -118
- package/lib/global.d.ts +70 -70
- package/lib/global.js +109 -109
- package/lib/lifecycleEvents.d.ts +93 -93
- package/lib/lifecycleEvents.js +188 -188
- package/lib/logger.d.ts +381 -381
- package/lib/logger.js +734 -734
- package/lib/messages.d.ts +291 -291
- package/lib/messages.js +543 -543
- package/lib/org/authInfo.d.ts +344 -344
- package/lib/org/authInfo.js +892 -892
- package/lib/org/authRemover.d.ts +88 -88
- package/lib/org/authRemover.js +182 -182
- package/lib/org/connection.d.ts +197 -197
- package/lib/org/connection.js +395 -395
- package/lib/org/index.d.ts +6 -6
- package/lib/org/index.js +28 -28
- package/lib/org/org.d.ts +558 -558
- package/lib/org/org.js +1267 -1267
- package/lib/org/orgConfigProperties.d.ts +69 -69
- package/lib/org/orgConfigProperties.js +136 -136
- package/lib/org/permissionSetAssignment.d.ts +35 -35
- package/lib/org/permissionSetAssignment.js +125 -125
- package/lib/org/scratchOrgCache.d.ts +20 -20
- package/lib/org/scratchOrgCache.js +32 -32
- package/lib/org/scratchOrgCreate.d.ts +54 -54
- package/lib/org/scratchOrgCreate.js +216 -216
- package/lib/org/scratchOrgErrorCodes.d.ts +10 -10
- package/lib/org/scratchOrgErrorCodes.js +88 -88
- package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -26
- package/lib/org/scratchOrgFeatureDeprecation.js +109 -109
- package/lib/org/scratchOrgInfoApi.d.ts +68 -68
- package/lib/org/scratchOrgInfoApi.js +413 -413
- package/lib/org/scratchOrgInfoGenerator.d.ts +64 -64
- package/lib/org/scratchOrgInfoGenerator.js +241 -241
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -10
- package/lib/org/scratchOrgLifecycleEvents.js +40 -40
- package/lib/org/scratchOrgSettingsGenerator.d.ts +78 -78
- package/lib/org/scratchOrgSettingsGenerator.js +276 -276
- package/lib/org/scratchOrgTypes.d.ts +43 -43
- package/lib/org/scratchOrgTypes.js +8 -8
- package/lib/org/user.d.ts +187 -187
- package/lib/org/user.js +448 -448
- package/lib/schema/printer.d.ts +79 -79
- package/lib/schema/printer.js +260 -260
- package/lib/schema/validator.d.ts +70 -70
- package/lib/schema/validator.js +169 -169
- package/lib/sfError.d.ts +73 -73
- package/lib/sfError.js +136 -136
- package/lib/sfProject.d.ts +357 -357
- package/lib/sfProject.js +671 -671
- package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -98
- package/lib/stateAggregator/accessors/aliasAccessor.js +145 -145
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -101
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -240
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -8
- package/lib/stateAggregator/accessors/sandboxAccessor.js +27 -27
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -63
- package/lib/stateAggregator/accessors/tokenAccessor.js +79 -79
- package/lib/stateAggregator/index.d.ts +4 -4
- package/lib/stateAggregator/index.js +26 -26
- package/lib/stateAggregator/stateAggregator.d.ts +25 -25
- package/lib/stateAggregator/stateAggregator.js +45 -45
- package/lib/status/myDomainResolver.d.ts +66 -66
- package/lib/status/myDomainResolver.js +124 -124
- package/lib/status/pollingClient.d.ts +85 -85
- package/lib/status/pollingClient.js +115 -115
- package/lib/status/streamingClient.d.ts +244 -244
- package/lib/status/streamingClient.js +436 -436
- package/lib/status/types.d.ts +89 -89
- package/lib/status/types.js +17 -17
- package/lib/testSetup.d.ts +553 -530
- package/lib/testSetup.js +871 -727
- package/lib/util/cache.d.ts +11 -11
- package/lib/util/cache.js +69 -69
- package/lib/util/checkLightningDomain.d.ts +1 -1
- package/lib/util/checkLightningDomain.js +28 -28
- package/lib/util/directoryWriter.d.ts +12 -12
- package/lib/util/directoryWriter.js +53 -53
- package/lib/util/getJwtAudienceUrl.d.ts +4 -4
- package/lib/util/getJwtAudienceUrl.js +18 -18
- package/lib/util/internal.d.ts +58 -58
- package/lib/util/internal.js +118 -118
- package/lib/util/jsonXmlTools.d.ts +14 -14
- package/lib/util/jsonXmlTools.js +38 -38
- package/lib/util/mapKeys.d.ts +14 -14
- package/lib/util/mapKeys.js +51 -51
- package/lib/util/sfdc.d.ts +52 -52
- package/lib/util/sfdc.js +85 -85
- package/lib/util/sfdcUrl.d.ts +72 -72
- package/lib/util/sfdcUrl.js +215 -215
- package/lib/util/structuredWriter.d.ts +9 -9
- package/lib/util/structuredWriter.js +2 -2
- package/lib/util/zipWriter.d.ts +16 -16
- package/lib/util/zipWriter.js +67 -67
- package/lib/webOAuthServer.d.ts +156 -156
- package/lib/webOAuthServer.js +388 -388
- package/messages/auth.md +37 -37
- package/messages/config.md +156 -156
- package/messages/connection.md +30 -30
- package/messages/core.json +20 -20
- package/messages/core.md +67 -67
- package/messages/encryption.md +85 -85
- package/messages/envVars.md +303 -303
- package/messages/org.md +63 -63
- package/messages/permissionSetAssignment.md +31 -31
- package/messages/scratchOrgCreate.md +23 -23
- package/messages/scratchOrgErrorCodes.md +115 -115
- package/messages/scratchOrgFeatureDeprecation.md +11 -11
- package/messages/scratchOrgInfoApi.md +15 -15
- package/messages/scratchOrgInfoGenerator.md +23 -23
- package/messages/streaming.md +23 -23
- package/messages/user.md +35 -35
- package/package.json +97 -97
|
@@ -1,244 +1,244 @@
|
|
|
1
|
-
import { AsyncOptionalCreatable, Duration, Env } from '@salesforce/kit/lib';
|
|
2
|
-
import { AnyJson } from '@salesforce/ts-types/lib';
|
|
3
|
-
import { Org } from '../org/org';
|
|
4
|
-
import { CometClient, CometSubscription, Message, StatusResult, StreamingExtension, StreamProcessor } from './types';
|
|
5
|
-
export { CometClient, CometSubscription, Message, StatusResult, StreamingExtension, StreamProcessor };
|
|
6
|
-
/**
|
|
7
|
-
* Inner streaming client interface. This implements the Cometd behavior.
|
|
8
|
-
* Also allows for mocking the functional behavior.
|
|
9
|
-
*/
|
|
10
|
-
export interface StreamingClientIfc {
|
|
11
|
-
/**
|
|
12
|
-
* Returns a comet client implementation.
|
|
13
|
-
*
|
|
14
|
-
* @param url The target url of the streaming service endpoint.
|
|
15
|
-
*/
|
|
16
|
-
getCometClient: (url: string) => CometClient;
|
|
17
|
-
/**
|
|
18
|
-
* Sets the logger function for the CometClient.
|
|
19
|
-
*
|
|
20
|
-
* @param logLine A log message passed to the the assigned function.
|
|
21
|
-
*/
|
|
22
|
-
setLogger: (logLine: (message: string) => void) => void;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Api wrapper to support Salesforce streaming. The client contains an internal implementation of a cometd specification.
|
|
26
|
-
*
|
|
27
|
-
* Salesforce client and timeout information
|
|
28
|
-
*
|
|
29
|
-
* Streaming API imposes two timeouts, as supported in the Bayeux protocol.
|
|
30
|
-
*
|
|
31
|
-
* Socket timeout: 110 seconds
|
|
32
|
-
* A client receives events (JSON-formatted HTTP responses) while it waits on a connection. If no events are generated
|
|
33
|
-
* and the client is still waiting, the connection times out after 110 seconds and the server closes the connection.
|
|
34
|
-
* Clients should reconnect before two minutes to avoid the connection timeout.
|
|
35
|
-
*
|
|
36
|
-
* Reconnect timeout: 40 seconds
|
|
37
|
-
* After receiving the events, a client needs to reconnect to receive the next set of events. If the reconnection
|
|
38
|
-
* doesn't happen within 40 seconds, the server expires the subscription and the connection is closed. If this happens,
|
|
39
|
-
* the client must start again and handshake, subscribe, and connect. Each Streaming API client logs into an instance
|
|
40
|
-
* and maintains a session. When the client handshakes, connects, or subscribes, the session timeout is restarted. A
|
|
41
|
-
* client session times out if the client doesn’t reconnect to the server within 40 seconds after receiving a response
|
|
42
|
-
* (an event, subscribe result, and so on).
|
|
43
|
-
*
|
|
44
|
-
* Note that these timeouts apply to the Streaming API client session and not the Salesforce authentication session. If
|
|
45
|
-
* the client session times out, the authentication session remains active until the organization-specific timeout
|
|
46
|
-
* policy goes into effect.
|
|
47
|
-
*
|
|
48
|
-
* ```
|
|
49
|
-
* const streamProcessor = (message: JsonMap): StatusResult => {
|
|
50
|
-
* const payload = ensureJsonMap(message.payload);
|
|
51
|
-
* const id = ensureString(payload.id);
|
|
52
|
-
*
|
|
53
|
-
* if (payload.status !== 'Active') {
|
|
54
|
-
* return { completed: false };
|
|
55
|
-
* }
|
|
56
|
-
*
|
|
57
|
-
* return {
|
|
58
|
-
* completed: true,
|
|
59
|
-
* payload: id
|
|
60
|
-
* };
|
|
61
|
-
* };
|
|
62
|
-
*
|
|
63
|
-
* const org = await Org.create();
|
|
64
|
-
* const options = new StreamingClient.DefaultOptions(org, 'MyPushTopics', streamProcessor);
|
|
65
|
-
*
|
|
66
|
-
* const asyncStatusClient = await StreamingClient.create(options);
|
|
67
|
-
*
|
|
68
|
-
* await asyncStatusClient.handshake();
|
|
69
|
-
*
|
|
70
|
-
* const info: RequestInfo = {
|
|
71
|
-
* method: 'POST',
|
|
72
|
-
* url: `${org.getField(OrgFields.INSTANCE_URL)}/SomeService`,
|
|
73
|
-
* headers: { HEADER: 'HEADER_VALUE'},
|
|
74
|
-
* body: 'My content'
|
|
75
|
-
* };
|
|
76
|
-
*
|
|
77
|
-
* await asyncStatusClient.subscribe(async () => {
|
|
78
|
-
* const connection = await org.getConnection();
|
|
79
|
-
* // Now that we are subscribed, we can initiate the request that will cause the events to start streaming.
|
|
80
|
-
* const requestResponse: JsonCollection = await connection.request(info);
|
|
81
|
-
* const id = ensureJsonMap(requestResponse).id;
|
|
82
|
-
* console.log(`this.id: ${JSON.stringify(ensureString(id), null, 4)}`);
|
|
83
|
-
* });
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
export declare class StreamingClient extends AsyncOptionalCreatable<StreamingClient.Options> {
|
|
87
|
-
private readonly targetUrl;
|
|
88
|
-
private readonly options;
|
|
89
|
-
private logger;
|
|
90
|
-
private cometClient;
|
|
91
|
-
/**
|
|
92
|
-
* Constructor
|
|
93
|
-
*
|
|
94
|
-
* @param options Streaming client options
|
|
95
|
-
* {@link AsyncCreatable.create}
|
|
96
|
-
*/
|
|
97
|
-
constructor(options?: StreamingClient.Options);
|
|
98
|
-
/**
|
|
99
|
-
* Asynchronous initializer.
|
|
100
|
-
*/
|
|
101
|
-
init(): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* Allows replaying of of Streaming events starting with replayId.
|
|
104
|
-
*
|
|
105
|
-
* @param replayId The starting message id to replay from.
|
|
106
|
-
*/
|
|
107
|
-
replay(replayId: number): void;
|
|
108
|
-
/**
|
|
109
|
-
* Provides a convenient way to handshake with the server endpoint before trying to subscribe.
|
|
110
|
-
*/
|
|
111
|
-
handshake(): Promise<StreamingClient.ConnectionState>;
|
|
112
|
-
/**
|
|
113
|
-
* Subscribe to streaming events. When the streaming processor that's set in the options completes execution it
|
|
114
|
-
* returns a payload in the StatusResult object. The payload is just echoed here for convenience.
|
|
115
|
-
*
|
|
116
|
-
* **Throws** *{@link SfError}{ name: '{@link StreamingClient.TimeoutErrorType.SUBSCRIBE}'}* When the subscribe timeout occurs.
|
|
117
|
-
*
|
|
118
|
-
* @param streamInit This function should call the platform apis that result in streaming updates on push topics.
|
|
119
|
-
* {@link StatusResult}
|
|
120
|
-
*/
|
|
121
|
-
subscribe(streamInit?: () => Promise<void>): Promise<AnyJson | void>;
|
|
122
|
-
/**
|
|
123
|
-
* Handler for incoming streaming messages.
|
|
124
|
-
*
|
|
125
|
-
* @param message The message to process.
|
|
126
|
-
* @param cb The callback. Failure to call this can cause the internal comet client to hang.
|
|
127
|
-
*/
|
|
128
|
-
private incoming;
|
|
129
|
-
private doTimeout;
|
|
130
|
-
private disconnectClient;
|
|
131
|
-
private disconnect;
|
|
132
|
-
/**
|
|
133
|
-
* Simple inner log wrapper
|
|
134
|
-
*
|
|
135
|
-
* @param message The message to log
|
|
136
|
-
*/
|
|
137
|
-
private log;
|
|
138
|
-
}
|
|
139
|
-
export declare namespace StreamingClient {
|
|
140
|
-
/**
|
|
141
|
-
* Options for the StreamingClient
|
|
142
|
-
*
|
|
143
|
-
* @interface
|
|
144
|
-
*/
|
|
145
|
-
interface Options {
|
|
146
|
-
/**
|
|
147
|
-
* The org streaming target.
|
|
148
|
-
*/
|
|
149
|
-
org: Org;
|
|
150
|
-
/**
|
|
151
|
-
* The hard timeout that happens with subscribe
|
|
152
|
-
*/
|
|
153
|
-
subscribeTimeout: Duration;
|
|
154
|
-
/**
|
|
155
|
-
* The hard timeout that happens with a handshake.
|
|
156
|
-
*/
|
|
157
|
-
handshakeTimeout: Duration;
|
|
158
|
-
/**
|
|
159
|
-
* The streaming channel aka topic
|
|
160
|
-
*/
|
|
161
|
-
channel: string;
|
|
162
|
-
/**
|
|
163
|
-
* The salesforce api version
|
|
164
|
-
*/
|
|
165
|
-
apiVersion: string;
|
|
166
|
-
/**
|
|
167
|
-
* The function for processing streaming messages
|
|
168
|
-
*/
|
|
169
|
-
streamProcessor: StreamProcessor;
|
|
170
|
-
/**
|
|
171
|
-
* The function for build the inner client impl. Allows for mocking.
|
|
172
|
-
*/
|
|
173
|
-
streamingImpl: StreamingClientIfc;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Default Streaming Options. Uses Faye as the cometd impl.
|
|
177
|
-
*/
|
|
178
|
-
class DefaultOptions implements StreamingClient.Options {
|
|
179
|
-
static readonly SFDX_ENABLE_FAYE_COOKIES_ALLOW_ALL_PATHS = "SFDX_ENABLE_FAYE_REQUEST_RESPONSE_LOGGING";
|
|
180
|
-
static readonly SFDX_ENABLE_FAYE_REQUEST_RESPONSE_LOGGING = "SFDX_ENABLE_FAYE_REQUEST_RESPONSE_LOGGING";
|
|
181
|
-
static readonly DEFAULT_SUBSCRIBE_TIMEOUT: Duration;
|
|
182
|
-
static readonly DEFAULT_HANDSHAKE_TIMEOUT: Duration;
|
|
183
|
-
apiVersion: string;
|
|
184
|
-
org: Org;
|
|
185
|
-
streamProcessor: StreamProcessor;
|
|
186
|
-
subscribeTimeout: Duration;
|
|
187
|
-
handshakeTimeout: Duration;
|
|
188
|
-
channel: string;
|
|
189
|
-
streamingImpl: StreamingClientIfc;
|
|
190
|
-
/**
|
|
191
|
-
* Constructor for DefaultStreamingOptions
|
|
192
|
-
*
|
|
193
|
-
* @param org The streaming target org
|
|
194
|
-
* @param channel The streaming channel or topic. If the topic is a system topic then api 36.0 is used.
|
|
195
|
-
* System topics are deprecated.
|
|
196
|
-
* @param streamProcessor The function called that can process streaming messages.
|
|
197
|
-
* @param envDep
|
|
198
|
-
* @see {@link StatusResult}
|
|
199
|
-
*/
|
|
200
|
-
constructor(org: Org, channel: string, streamProcessor: StreamProcessor, envDep?: Env);
|
|
201
|
-
/**
|
|
202
|
-
* Setter for the subscribe timeout.
|
|
203
|
-
*
|
|
204
|
-
* **Throws** An error if the newTime is less than the default time.
|
|
205
|
-
*
|
|
206
|
-
* @param newTime The new subscribe timeout.
|
|
207
|
-
* {@link DefaultOptions.DEFAULT_SUBSCRIBE_TIMEOUT}
|
|
208
|
-
*/
|
|
209
|
-
setSubscribeTimeout(newTime: Duration): void;
|
|
210
|
-
/**
|
|
211
|
-
* Setter for the handshake timeout.
|
|
212
|
-
*
|
|
213
|
-
* **Throws** An error if the newTime is less than the default time.
|
|
214
|
-
*
|
|
215
|
-
* @param newTime The new handshake timeout
|
|
216
|
-
* {@link DefaultOptions.DEFAULT_HANDSHAKE_TIMEOUT}
|
|
217
|
-
*/
|
|
218
|
-
setHandshakeTimeout(newTime: Duration): void;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Connection state
|
|
222
|
-
*
|
|
223
|
-
* @see {@link StreamingClient.handshake}
|
|
224
|
-
*/
|
|
225
|
-
enum ConnectionState {
|
|
226
|
-
/**
|
|
227
|
-
* Used to indicated that the streaming client is connected.
|
|
228
|
-
*/
|
|
229
|
-
CONNECTED = 0
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Indicators to test error names for StreamingTimeouts
|
|
233
|
-
*/
|
|
234
|
-
enum TimeoutErrorType {
|
|
235
|
-
/**
|
|
236
|
-
* To indicate the error occurred on handshake
|
|
237
|
-
*/
|
|
238
|
-
HANDSHAKE = "GenericHandshakeTimeoutError",
|
|
239
|
-
/**
|
|
240
|
-
* To indicate the error occurred on subscribe
|
|
241
|
-
*/
|
|
242
|
-
SUBSCRIBE = "GenericTimeoutError"
|
|
243
|
-
}
|
|
244
|
-
}
|
|
1
|
+
import { AsyncOptionalCreatable, Duration, Env } from '@salesforce/kit/lib';
|
|
2
|
+
import { AnyJson } from '@salesforce/ts-types/lib';
|
|
3
|
+
import { Org } from '../org/org';
|
|
4
|
+
import { CometClient, CometSubscription, Message, StatusResult, StreamingExtension, StreamProcessor } from './types';
|
|
5
|
+
export { CometClient, CometSubscription, Message, StatusResult, StreamingExtension, StreamProcessor };
|
|
6
|
+
/**
|
|
7
|
+
* Inner streaming client interface. This implements the Cometd behavior.
|
|
8
|
+
* Also allows for mocking the functional behavior.
|
|
9
|
+
*/
|
|
10
|
+
export interface StreamingClientIfc {
|
|
11
|
+
/**
|
|
12
|
+
* Returns a comet client implementation.
|
|
13
|
+
*
|
|
14
|
+
* @param url The target url of the streaming service endpoint.
|
|
15
|
+
*/
|
|
16
|
+
getCometClient: (url: string) => CometClient;
|
|
17
|
+
/**
|
|
18
|
+
* Sets the logger function for the CometClient.
|
|
19
|
+
*
|
|
20
|
+
* @param logLine A log message passed to the the assigned function.
|
|
21
|
+
*/
|
|
22
|
+
setLogger: (logLine: (message: string) => void) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Api wrapper to support Salesforce streaming. The client contains an internal implementation of a cometd specification.
|
|
26
|
+
*
|
|
27
|
+
* Salesforce client and timeout information
|
|
28
|
+
*
|
|
29
|
+
* Streaming API imposes two timeouts, as supported in the Bayeux protocol.
|
|
30
|
+
*
|
|
31
|
+
* Socket timeout: 110 seconds
|
|
32
|
+
* A client receives events (JSON-formatted HTTP responses) while it waits on a connection. If no events are generated
|
|
33
|
+
* and the client is still waiting, the connection times out after 110 seconds and the server closes the connection.
|
|
34
|
+
* Clients should reconnect before two minutes to avoid the connection timeout.
|
|
35
|
+
*
|
|
36
|
+
* Reconnect timeout: 40 seconds
|
|
37
|
+
* After receiving the events, a client needs to reconnect to receive the next set of events. If the reconnection
|
|
38
|
+
* doesn't happen within 40 seconds, the server expires the subscription and the connection is closed. If this happens,
|
|
39
|
+
* the client must start again and handshake, subscribe, and connect. Each Streaming API client logs into an instance
|
|
40
|
+
* and maintains a session. When the client handshakes, connects, or subscribes, the session timeout is restarted. A
|
|
41
|
+
* client session times out if the client doesn’t reconnect to the server within 40 seconds after receiving a response
|
|
42
|
+
* (an event, subscribe result, and so on).
|
|
43
|
+
*
|
|
44
|
+
* Note that these timeouts apply to the Streaming API client session and not the Salesforce authentication session. If
|
|
45
|
+
* the client session times out, the authentication session remains active until the organization-specific timeout
|
|
46
|
+
* policy goes into effect.
|
|
47
|
+
*
|
|
48
|
+
* ```
|
|
49
|
+
* const streamProcessor = (message: JsonMap): StatusResult => {
|
|
50
|
+
* const payload = ensureJsonMap(message.payload);
|
|
51
|
+
* const id = ensureString(payload.id);
|
|
52
|
+
*
|
|
53
|
+
* if (payload.status !== 'Active') {
|
|
54
|
+
* return { completed: false };
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* return {
|
|
58
|
+
* completed: true,
|
|
59
|
+
* payload: id
|
|
60
|
+
* };
|
|
61
|
+
* };
|
|
62
|
+
*
|
|
63
|
+
* const org = await Org.create();
|
|
64
|
+
* const options = new StreamingClient.DefaultOptions(org, 'MyPushTopics', streamProcessor);
|
|
65
|
+
*
|
|
66
|
+
* const asyncStatusClient = await StreamingClient.create(options);
|
|
67
|
+
*
|
|
68
|
+
* await asyncStatusClient.handshake();
|
|
69
|
+
*
|
|
70
|
+
* const info: RequestInfo = {
|
|
71
|
+
* method: 'POST',
|
|
72
|
+
* url: `${org.getField(OrgFields.INSTANCE_URL)}/SomeService`,
|
|
73
|
+
* headers: { HEADER: 'HEADER_VALUE'},
|
|
74
|
+
* body: 'My content'
|
|
75
|
+
* };
|
|
76
|
+
*
|
|
77
|
+
* await asyncStatusClient.subscribe(async () => {
|
|
78
|
+
* const connection = await org.getConnection();
|
|
79
|
+
* // Now that we are subscribed, we can initiate the request that will cause the events to start streaming.
|
|
80
|
+
* const requestResponse: JsonCollection = await connection.request(info);
|
|
81
|
+
* const id = ensureJsonMap(requestResponse).id;
|
|
82
|
+
* console.log(`this.id: ${JSON.stringify(ensureString(id), null, 4)}`);
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare class StreamingClient extends AsyncOptionalCreatable<StreamingClient.Options> {
|
|
87
|
+
private readonly targetUrl;
|
|
88
|
+
private readonly options;
|
|
89
|
+
private logger;
|
|
90
|
+
private cometClient;
|
|
91
|
+
/**
|
|
92
|
+
* Constructor
|
|
93
|
+
*
|
|
94
|
+
* @param options Streaming client options
|
|
95
|
+
* {@link AsyncCreatable.create}
|
|
96
|
+
*/
|
|
97
|
+
constructor(options?: StreamingClient.Options);
|
|
98
|
+
/**
|
|
99
|
+
* Asynchronous initializer.
|
|
100
|
+
*/
|
|
101
|
+
init(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Allows replaying of of Streaming events starting with replayId.
|
|
104
|
+
*
|
|
105
|
+
* @param replayId The starting message id to replay from.
|
|
106
|
+
*/
|
|
107
|
+
replay(replayId: number): void;
|
|
108
|
+
/**
|
|
109
|
+
* Provides a convenient way to handshake with the server endpoint before trying to subscribe.
|
|
110
|
+
*/
|
|
111
|
+
handshake(): Promise<StreamingClient.ConnectionState>;
|
|
112
|
+
/**
|
|
113
|
+
* Subscribe to streaming events. When the streaming processor that's set in the options completes execution it
|
|
114
|
+
* returns a payload in the StatusResult object. The payload is just echoed here for convenience.
|
|
115
|
+
*
|
|
116
|
+
* **Throws** *{@link SfError}{ name: '{@link StreamingClient.TimeoutErrorType.SUBSCRIBE}'}* When the subscribe timeout occurs.
|
|
117
|
+
*
|
|
118
|
+
* @param streamInit This function should call the platform apis that result in streaming updates on push topics.
|
|
119
|
+
* {@link StatusResult}
|
|
120
|
+
*/
|
|
121
|
+
subscribe(streamInit?: () => Promise<void>): Promise<AnyJson | void>;
|
|
122
|
+
/**
|
|
123
|
+
* Handler for incoming streaming messages.
|
|
124
|
+
*
|
|
125
|
+
* @param message The message to process.
|
|
126
|
+
* @param cb The callback. Failure to call this can cause the internal comet client to hang.
|
|
127
|
+
*/
|
|
128
|
+
private incoming;
|
|
129
|
+
private doTimeout;
|
|
130
|
+
private disconnectClient;
|
|
131
|
+
private disconnect;
|
|
132
|
+
/**
|
|
133
|
+
* Simple inner log wrapper
|
|
134
|
+
*
|
|
135
|
+
* @param message The message to log
|
|
136
|
+
*/
|
|
137
|
+
private log;
|
|
138
|
+
}
|
|
139
|
+
export declare namespace StreamingClient {
|
|
140
|
+
/**
|
|
141
|
+
* Options for the StreamingClient
|
|
142
|
+
*
|
|
143
|
+
* @interface
|
|
144
|
+
*/
|
|
145
|
+
interface Options {
|
|
146
|
+
/**
|
|
147
|
+
* The org streaming target.
|
|
148
|
+
*/
|
|
149
|
+
org: Org;
|
|
150
|
+
/**
|
|
151
|
+
* The hard timeout that happens with subscribe
|
|
152
|
+
*/
|
|
153
|
+
subscribeTimeout: Duration;
|
|
154
|
+
/**
|
|
155
|
+
* The hard timeout that happens with a handshake.
|
|
156
|
+
*/
|
|
157
|
+
handshakeTimeout: Duration;
|
|
158
|
+
/**
|
|
159
|
+
* The streaming channel aka topic
|
|
160
|
+
*/
|
|
161
|
+
channel: string;
|
|
162
|
+
/**
|
|
163
|
+
* The salesforce api version
|
|
164
|
+
*/
|
|
165
|
+
apiVersion: string;
|
|
166
|
+
/**
|
|
167
|
+
* The function for processing streaming messages
|
|
168
|
+
*/
|
|
169
|
+
streamProcessor: StreamProcessor;
|
|
170
|
+
/**
|
|
171
|
+
* The function for build the inner client impl. Allows for mocking.
|
|
172
|
+
*/
|
|
173
|
+
streamingImpl: StreamingClientIfc;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Default Streaming Options. Uses Faye as the cometd impl.
|
|
177
|
+
*/
|
|
178
|
+
class DefaultOptions implements StreamingClient.Options {
|
|
179
|
+
static readonly SFDX_ENABLE_FAYE_COOKIES_ALLOW_ALL_PATHS = "SFDX_ENABLE_FAYE_REQUEST_RESPONSE_LOGGING";
|
|
180
|
+
static readonly SFDX_ENABLE_FAYE_REQUEST_RESPONSE_LOGGING = "SFDX_ENABLE_FAYE_REQUEST_RESPONSE_LOGGING";
|
|
181
|
+
static readonly DEFAULT_SUBSCRIBE_TIMEOUT: Duration;
|
|
182
|
+
static readonly DEFAULT_HANDSHAKE_TIMEOUT: Duration;
|
|
183
|
+
apiVersion: string;
|
|
184
|
+
org: Org;
|
|
185
|
+
streamProcessor: StreamProcessor;
|
|
186
|
+
subscribeTimeout: Duration;
|
|
187
|
+
handshakeTimeout: Duration;
|
|
188
|
+
channel: string;
|
|
189
|
+
streamingImpl: StreamingClientIfc;
|
|
190
|
+
/**
|
|
191
|
+
* Constructor for DefaultStreamingOptions
|
|
192
|
+
*
|
|
193
|
+
* @param org The streaming target org
|
|
194
|
+
* @param channel The streaming channel or topic. If the topic is a system topic then api 36.0 is used.
|
|
195
|
+
* System topics are deprecated.
|
|
196
|
+
* @param streamProcessor The function called that can process streaming messages.
|
|
197
|
+
* @param envDep
|
|
198
|
+
* @see {@link StatusResult}
|
|
199
|
+
*/
|
|
200
|
+
constructor(org: Org, channel: string, streamProcessor: StreamProcessor, envDep?: Env);
|
|
201
|
+
/**
|
|
202
|
+
* Setter for the subscribe timeout.
|
|
203
|
+
*
|
|
204
|
+
* **Throws** An error if the newTime is less than the default time.
|
|
205
|
+
*
|
|
206
|
+
* @param newTime The new subscribe timeout.
|
|
207
|
+
* {@link DefaultOptions.DEFAULT_SUBSCRIBE_TIMEOUT}
|
|
208
|
+
*/
|
|
209
|
+
setSubscribeTimeout(newTime: Duration): void;
|
|
210
|
+
/**
|
|
211
|
+
* Setter for the handshake timeout.
|
|
212
|
+
*
|
|
213
|
+
* **Throws** An error if the newTime is less than the default time.
|
|
214
|
+
*
|
|
215
|
+
* @param newTime The new handshake timeout
|
|
216
|
+
* {@link DefaultOptions.DEFAULT_HANDSHAKE_TIMEOUT}
|
|
217
|
+
*/
|
|
218
|
+
setHandshakeTimeout(newTime: Duration): void;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Connection state
|
|
222
|
+
*
|
|
223
|
+
* @see {@link StreamingClient.handshake}
|
|
224
|
+
*/
|
|
225
|
+
enum ConnectionState {
|
|
226
|
+
/**
|
|
227
|
+
* Used to indicated that the streaming client is connected.
|
|
228
|
+
*/
|
|
229
|
+
CONNECTED = 0
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Indicators to test error names for StreamingTimeouts
|
|
233
|
+
*/
|
|
234
|
+
enum TimeoutErrorType {
|
|
235
|
+
/**
|
|
236
|
+
* To indicate the error occurred on handshake
|
|
237
|
+
*/
|
|
238
|
+
HANDSHAKE = "GenericHandshakeTimeoutError",
|
|
239
|
+
/**
|
|
240
|
+
* To indicate the error occurred on subscribe
|
|
241
|
+
*/
|
|
242
|
+
SUBSCRIBE = "GenericTimeoutError"
|
|
243
|
+
}
|
|
244
|
+
}
|