@salesforce/core 3.31.4 → 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.
Files changed (153) hide show
  1. package/LICENSE.txt +11 -11
  2. package/README.md +222 -222
  3. package/lib/config/aliasesConfig.d.ts +12 -12
  4. package/lib/config/aliasesConfig.js +27 -27
  5. package/lib/config/authInfoConfig.d.ts +19 -19
  6. package/lib/config/authInfoConfig.js +34 -34
  7. package/lib/config/config.d.ts +311 -311
  8. package/lib/config/config.js +574 -574
  9. package/lib/config/configAggregator.d.ts +232 -232
  10. package/lib/config/configAggregator.js +379 -379
  11. package/lib/config/configFile.d.ts +199 -199
  12. package/lib/config/configFile.js +340 -340
  13. package/lib/config/configGroup.d.ts +141 -141
  14. package/lib/config/configGroup.js +224 -224
  15. package/lib/config/configStore.d.ts +241 -241
  16. package/lib/config/configStore.js +352 -352
  17. package/lib/config/envVars.d.ts +101 -101
  18. package/lib/config/envVars.js +456 -456
  19. package/lib/config/orgUsersConfig.d.ts +31 -31
  20. package/lib/config/orgUsersConfig.js +41 -41
  21. package/lib/config/sandboxOrgConfig.d.ts +37 -37
  22. package/lib/config/sandboxOrgConfig.js +50 -50
  23. package/lib/config/sandboxProcessCache.d.ts +16 -16
  24. package/lib/config/sandboxProcessCache.js +37 -37
  25. package/lib/config/tokensConfig.d.ts +10 -10
  26. package/lib/config/tokensConfig.js +28 -28
  27. package/lib/config/ttlConfig.d.ts +34 -34
  28. package/lib/config/ttlConfig.js +54 -54
  29. package/lib/crypto/crypto.d.ts +54 -54
  30. package/lib/crypto/crypto.js +220 -220
  31. package/lib/crypto/keyChain.d.ts +8 -8
  32. package/lib/crypto/keyChain.js +61 -61
  33. package/lib/crypto/keyChainImpl.d.ts +116 -116
  34. package/lib/crypto/keyChainImpl.js +486 -486
  35. package/lib/crypto/secureBuffer.d.ts +46 -46
  36. package/lib/crypto/secureBuffer.js +82 -82
  37. package/lib/deviceOauthService.d.ts +71 -71
  38. package/lib/deviceOauthService.js +191 -191
  39. package/lib/exported.d.ts +38 -38
  40. package/lib/exported.js +118 -118
  41. package/lib/global.d.ts +70 -70
  42. package/lib/global.js +109 -109
  43. package/lib/lifecycleEvents.d.ts +93 -93
  44. package/lib/lifecycleEvents.js +188 -188
  45. package/lib/logger.d.ts +381 -381
  46. package/lib/logger.js +734 -734
  47. package/lib/messages.d.ts +291 -291
  48. package/lib/messages.js +543 -543
  49. package/lib/org/authInfo.d.ts +344 -344
  50. package/lib/org/authInfo.js +892 -892
  51. package/lib/org/authRemover.d.ts +88 -88
  52. package/lib/org/authRemover.js +182 -182
  53. package/lib/org/connection.d.ts +197 -197
  54. package/lib/org/connection.js +395 -395
  55. package/lib/org/index.d.ts +6 -6
  56. package/lib/org/index.js +28 -28
  57. package/lib/org/org.d.ts +558 -558
  58. package/lib/org/org.js +1267 -1267
  59. package/lib/org/orgConfigProperties.d.ts +69 -69
  60. package/lib/org/orgConfigProperties.js +136 -136
  61. package/lib/org/permissionSetAssignment.d.ts +35 -35
  62. package/lib/org/permissionSetAssignment.js +125 -125
  63. package/lib/org/scratchOrgCache.d.ts +20 -20
  64. package/lib/org/scratchOrgCache.js +32 -32
  65. package/lib/org/scratchOrgCreate.d.ts +54 -54
  66. package/lib/org/scratchOrgCreate.js +216 -216
  67. package/lib/org/scratchOrgErrorCodes.d.ts +10 -10
  68. package/lib/org/scratchOrgErrorCodes.js +88 -88
  69. package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -26
  70. package/lib/org/scratchOrgFeatureDeprecation.js +109 -109
  71. package/lib/org/scratchOrgInfoApi.d.ts +68 -68
  72. package/lib/org/scratchOrgInfoApi.js +413 -413
  73. package/lib/org/scratchOrgInfoGenerator.d.ts +64 -64
  74. package/lib/org/scratchOrgInfoGenerator.js +241 -241
  75. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -10
  76. package/lib/org/scratchOrgLifecycleEvents.js +40 -40
  77. package/lib/org/scratchOrgSettingsGenerator.d.ts +78 -78
  78. package/lib/org/scratchOrgSettingsGenerator.js +276 -276
  79. package/lib/org/scratchOrgTypes.d.ts +43 -43
  80. package/lib/org/scratchOrgTypes.js +8 -8
  81. package/lib/org/user.d.ts +187 -187
  82. package/lib/org/user.js +448 -448
  83. package/lib/schema/printer.d.ts +79 -79
  84. package/lib/schema/printer.js +260 -260
  85. package/lib/schema/validator.d.ts +70 -70
  86. package/lib/schema/validator.js +169 -169
  87. package/lib/sfError.d.ts +73 -73
  88. package/lib/sfError.js +136 -136
  89. package/lib/sfProject.d.ts +357 -357
  90. package/lib/sfProject.js +671 -671
  91. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -98
  92. package/lib/stateAggregator/accessors/aliasAccessor.js +145 -145
  93. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -101
  94. package/lib/stateAggregator/accessors/orgAccessor.js +240 -240
  95. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -8
  96. package/lib/stateAggregator/accessors/sandboxAccessor.js +27 -27
  97. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -63
  98. package/lib/stateAggregator/accessors/tokenAccessor.js +79 -79
  99. package/lib/stateAggregator/index.d.ts +4 -4
  100. package/lib/stateAggregator/index.js +26 -26
  101. package/lib/stateAggregator/stateAggregator.d.ts +25 -25
  102. package/lib/stateAggregator/stateAggregator.js +45 -45
  103. package/lib/status/myDomainResolver.d.ts +66 -66
  104. package/lib/status/myDomainResolver.js +124 -124
  105. package/lib/status/pollingClient.d.ts +85 -85
  106. package/lib/status/pollingClient.js +115 -115
  107. package/lib/status/streamingClient.d.ts +244 -244
  108. package/lib/status/streamingClient.js +436 -436
  109. package/lib/status/types.d.ts +89 -89
  110. package/lib/status/types.js +17 -17
  111. package/lib/testSetup.d.ts +553 -553
  112. package/lib/testSetup.js +871 -871
  113. package/lib/util/cache.d.ts +11 -11
  114. package/lib/util/cache.js +69 -69
  115. package/lib/util/checkLightningDomain.d.ts +1 -1
  116. package/lib/util/checkLightningDomain.js +28 -28
  117. package/lib/util/directoryWriter.d.ts +12 -12
  118. package/lib/util/directoryWriter.js +53 -53
  119. package/lib/util/getJwtAudienceUrl.d.ts +4 -4
  120. package/lib/util/getJwtAudienceUrl.js +18 -18
  121. package/lib/util/internal.d.ts +58 -58
  122. package/lib/util/internal.js +118 -118
  123. package/lib/util/jsonXmlTools.d.ts +14 -14
  124. package/lib/util/jsonXmlTools.js +38 -38
  125. package/lib/util/mapKeys.d.ts +14 -14
  126. package/lib/util/mapKeys.js +51 -51
  127. package/lib/util/sfdc.d.ts +52 -52
  128. package/lib/util/sfdc.js +85 -85
  129. package/lib/util/sfdcUrl.d.ts +72 -72
  130. package/lib/util/sfdcUrl.js +215 -215
  131. package/lib/util/structuredWriter.d.ts +9 -9
  132. package/lib/util/structuredWriter.js +2 -2
  133. package/lib/util/zipWriter.d.ts +16 -16
  134. package/lib/util/zipWriter.js +67 -67
  135. package/lib/webOAuthServer.d.ts +156 -156
  136. package/lib/webOAuthServer.js +388 -388
  137. package/messages/auth.md +37 -37
  138. package/messages/config.md +156 -156
  139. package/messages/connection.md +30 -30
  140. package/messages/core.json +20 -20
  141. package/messages/core.md +67 -67
  142. package/messages/encryption.md +85 -85
  143. package/messages/envVars.md +303 -303
  144. package/messages/org.md +63 -63
  145. package/messages/permissionSetAssignment.md +31 -31
  146. package/messages/scratchOrgCreate.md +23 -23
  147. package/messages/scratchOrgErrorCodes.md +115 -115
  148. package/messages/scratchOrgFeatureDeprecation.md +11 -11
  149. package/messages/scratchOrgInfoApi.md +15 -15
  150. package/messages/scratchOrgInfoGenerator.md +23 -23
  151. package/messages/streaming.md +23 -23
  152. package/messages/user.md +35 -35
  153. package/package.json +97 -97
@@ -1,553 +1,553 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { SinonSandbox, SinonStatic, SinonStub } from 'sinon';
4
- import { AnyJson, JsonMap, Optional } from '@salesforce/ts-types';
5
- import { ConfigContents } from './config/configStore';
6
- import { Connection } from './org/connection';
7
- import { Logger } from './logger';
8
- import { SfError } from './sfError';
9
- import { CometClient, CometSubscription, Message, StreamingExtension } from './status/streamingClient';
10
- import { AuthFields, SandboxFields } from './org';
11
- import { AliasGroup } from './config/aliasesConfig';
12
- /**
13
- * Different parts of the system that are mocked out. They can be restored for
14
- * individual tests. Test's stubs should always go on the DEFAULT which is exposed
15
- * on the TestContext.
16
- */
17
- export interface SandboxTypes {
18
- DEFAULT: SinonSandbox;
19
- CRYPTO: SinonSandbox;
20
- CONFIG: SinonSandbox;
21
- PROJECT: SinonSandbox;
22
- CONNECTION: SinonSandbox;
23
- FS: SinonSandbox;
24
- ORGS: SinonSandbox;
25
- }
26
- /**
27
- * Different hooks into {@link ConfigFile} used for testing instead of doing file IO.
28
- */
29
- export interface ConfigStub {
30
- /**
31
- * readFn A function that controls all aspect of {@link ConfigFile.read}. For example, it won't set the contents
32
- * unless explicitly done. Only use this if you know what you are doing. Use retrieveContents
33
- * instead.
34
- */
35
- readFn?: () => Promise<ConfigContents>;
36
- /**
37
- * A function that controls all aspects of {@link ConfigFile.write}. For example, it won't read the contents unless
38
- * explicitly done. Only use this if you know what you are doing. Use updateContents instead.
39
- */
40
- writeFn?: (contents?: AnyJson) => Promise<void>;
41
- /**
42
- * The contents that are used with @{link ConfigFile.readSync} and @{link ConfigFile.read}. If retrieveContents is set,
43
- * it will use that instead of @{link ConfigFile.read} but NOT @{link ConfigFile.readSync}. This will also contain the
44
- * new config when @{link ConfigFile.write} or @{link ConfigFile.writeSync} is called. This will persist through config instances,
45
- * such as {@link Alias.update} and {@link Alias.fetch}.
46
- */
47
- contents?: ConfigContents;
48
- /**
49
- * A function to conditionally read based on the config instance. The `this` value will be the config instance.
50
- */
51
- retrieveContents?: () => Promise<JsonMap>;
52
- /**
53
- * A function to conditionally set based on the config instance. The `this` value will be the config instance.
54
- */
55
- updateContents?: () => Promise<JsonMap>;
56
- }
57
- /**
58
- * Instantiate a @salesforce/core test context.
59
- */
60
- export declare class TestContext {
61
- /**
62
- * The default sandbox is cleared out before each test run.
63
- *
64
- * **See** [sinon sandbox]{@link https://sinonjs.org/releases/v14/sandbox/}.
65
- */
66
- SANDBOX: SinonSandbox;
67
- /**
68
- * An object of different sandboxes. Used when
69
- * needing to restore parts of the system for customized testing.
70
- */
71
- SANDBOXES: SandboxTypes;
72
- /**
73
- * The test logger that is used when {@link Logger.child} is used anywhere. It uses memory logging.
74
- */
75
- TEST_LOGGER: Logger;
76
- /**
77
- * id A unique id for the test run.
78
- */
79
- id: string;
80
- /**
81
- * An object used in tests that interact with config files.
82
- */
83
- configStubs: {
84
- [configName: string]: Optional<ConfigStub>;
85
- AliasesConfig?: ConfigStub;
86
- AuthInfoConfig?: ConfigStub;
87
- Config?: ConfigStub;
88
- SfProjectJson?: ConfigStub;
89
- TokensConfig?: ConfigStub;
90
- };
91
- /**
92
- * A record of stubs created during instantiation.
93
- */
94
- stubs: Record<string, SinonStub>;
95
- constructor(options?: {
96
- sinon?: SinonStatic;
97
- sandbox?: SinonSandbox;
98
- setup?: boolean;
99
- });
100
- /**
101
- * Generate unique string.
102
- */
103
- uniqid(): string;
104
- /**
105
- * A function used when resolving the local path. Calls localPathResolverSync by default.
106
- *
107
- * @param uid Unique id.
108
- */
109
- localPathRetriever(uid: string): Promise<string>;
110
- /**
111
- * A function used when resolving the local path.
112
- *
113
- * @param uid Unique id.
114
- */
115
- localPathRetrieverSync(uid: string): string;
116
- /**
117
- * A function used when resolving the global path. Calls globalPathResolverSync by default.
118
- *
119
- * @param uid Unique id.
120
- */
121
- globalPathRetriever(uid: string): Promise<string>;
122
- /**
123
- * A function used when resolving the global path.
124
- *
125
- * @param uid Unique id.
126
- */
127
- globalPathRetrieverSync(uid: string): string;
128
- /**
129
- * A function used for resolving paths. Calls localPathRetriever and globalPathRetriever.
130
- *
131
- * @param isGlobal `true` if the config is global.
132
- * @param uid user id.
133
- */
134
- rootPathRetriever(isGlobal: boolean, uid?: string): Promise<string>;
135
- /**
136
- * A function used for resolving paths. Calls localPathRetrieverSync and globalPathRetrieverSync.
137
- *
138
- * @param isGlobal `true` if the config is global.
139
- * @param uid user id.
140
- */
141
- rootPathRetrieverSync(isGlobal: boolean, uid?: string): string;
142
- /**
143
- * Used to mock http request to Salesforce.
144
- *
145
- * @param request An HttpRequest.
146
- * @param options Additional options.
147
- *
148
- * **See** {@link Connection.request}
149
- */
150
- fakeConnectionRequest(request: AnyJson, options?: AnyJson): Promise<AnyJson>;
151
- /**
152
- * Gets a config stub contents by name.
153
- *
154
- * @param name The name of the config.
155
- * @param group If the config supports groups.
156
- */
157
- getConfigStubContents(name: string, group?: string): ConfigContents;
158
- /**
159
- * Sets a config stub contents by name
160
- *
161
- * @param name The name of the config stub.
162
- * @param value The actual stub contents. The Mock data.
163
- */
164
- setConfigStubContents(name: string, value: ConfigContents): void;
165
- /**
166
- * Set stubs for working in the context of a SfProject
167
- */
168
- inProject(inProject?: boolean): void;
169
- /**
170
- * Stub salesforce org authorizations.
171
- */
172
- stubAuths(...orgs: MockTestOrgData[]): Promise<void>;
173
- /**
174
- * Stub salesforce sandbox authorizations.
175
- */
176
- stubSandboxes(...sandboxes: MockTestSandboxData[]): Promise<void>;
177
- /**
178
- * Stub the aliases in the global aliases config file.
179
- */
180
- stubAliases(aliases: Record<string, string>, group?: AliasGroup): void;
181
- /**
182
- * Stub contents in the config file.
183
- */
184
- stubConfig(config: Record<string, string>): Promise<void>;
185
- /**
186
- * Stub the tokens in the global token config file.
187
- */
188
- stubTokens(tokens: Record<string, string>): void;
189
- restore(): void;
190
- init(): void;
191
- /**
192
- * Add beforeEach and afterEach hooks to init the stubs and restore them.
193
- * This is called automatically when the class is instantiated unless the setup option is set to false.
194
- */
195
- setup(): void;
196
- private requireSinon;
197
- }
198
- /**
199
- * A function to generate a unique id and return it in the context of a template, if supplied.
200
- *
201
- * A template is a string that can contain `${%s}` to be replaced with a unique id.
202
- * If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
203
- *
204
- * @param options an object with the following properties:
205
- * - template: a template string.
206
- * - length: the length of the unique id as presented in hexadecimal.
207
- */
208
- export declare function uniqid(options?: {
209
- template?: string;
210
- length?: number;
211
- }): string;
212
- /**
213
- * Instantiate a @salesforce/core test context. This is automatically created by `const $$ = testSetup()`
214
- * but is useful if you don't want to have a global stub of @salesforce/core and you want to isolate it to
215
- * a single describe.
216
- *
217
- * **Note:** Call `stubContext` in your beforeEach to have clean stubs of @salesforce/core every test run.
218
- *
219
- * @example
220
- * ```
221
- * const $$ = instantiateContext();
222
- *
223
- * beforeEach(() => {
224
- * $$.init()
225
- * });
226
- *
227
- * afterEach(() => {
228
- * $$.restore();
229
- * });
230
- * ```
231
- * @param sinon
232
- */
233
- export declare const instantiateContext: (sinon?: SinonStatic) => TestContext;
234
- /**
235
- * Stub a @salesforce/core test context. This will mock out logging to a file, config file reading and writing,
236
- * local and global path resolution, and http request using connection (soon)*.
237
- *
238
- * This is automatically stubbed in the global beforeEach created by
239
- * `const $$ = testSetup()` but is useful if you don't want to have a global stub of @salesforce/core and you
240
- * want to isolate it to a single describe.
241
- *
242
- * **Note:** Always call `restoreContext` in your afterEach.
243
- *
244
- * @example
245
- * ```
246
- * const $$ = instantiateContext();
247
- *
248
- * beforeEach(() => {
249
- * $$.init()
250
- * });
251
- *
252
- * afterEach(() => {
253
- * $$.restore();
254
- * });
255
- * ```
256
- * @param testContext
257
- */
258
- export declare const stubContext: (testContext: TestContext) => Record<string, SinonStub>;
259
- /**
260
- * Restore a @salesforce/core test context. This is automatically stubbed in the global beforeEach created by
261
- * `const $$ = testSetup()` but is useful if you don't want to have a global stub of @salesforce/core and you
262
- * want to isolate it to a single describe.
263
- *
264
- * @example
265
- * ```
266
- * const $$ = instantiateContext();
267
- *
268
- * beforeEach(() => {
269
- * $$.init()
270
- * });
271
- *
272
- * afterEach(() => {
273
- * $$.restore();
274
- * });
275
- * ```
276
- * @param testContext
277
- */
278
- export declare const restoreContext: (testContext: TestContext) => void;
279
- /**
280
- * @deprecated Use TestContext instead.
281
- * Using testSetup will create globals stubs that could lead to erratic test behavior.
282
- *
283
- * This example shows you how to use TestContext:
284
- * @example
285
- * ```
286
- * const $$ = new TestContext();
287
- *
288
- * beforeEach(() => {
289
- * $$.init();
290
- * });
291
- *
292
- * afterEach(() => {
293
- * $$.restore();
294
- * });
295
- * ```
296
- *
297
- * Use to mock out different pieces of sfdx-core to make testing easier. This will mock out
298
- * logging to a file, config file reading and writing, local and global path resolution, and
299
- * *http request using connection (soon)*.
300
- *
301
- * **Note:** The testSetup should be outside of the describe. If you need to stub per test, use
302
- * `TestContext`.
303
- * ```
304
- * // In a mocha tests
305
- * import testSetup from '@salesforce/core/lib/testSetup';
306
- *
307
- * const $$ = testSetup();
308
- *
309
- * describe(() => {
310
- * it('test', () => {
311
- * // Stub out your own method
312
- * $$.SANDBOX.stub(MyClass.prototype, 'myMethod').returnsFake(() => {});
313
- *
314
- * // Set the contents that is used when aliases are read. Same for all config files.
315
- * $$.stubAliases({ 'myTestAlias': 'user@company.com' });
316
- *
317
- * // Will use the contents set above.
318
- * const username = (await StateAggregator.getInstance()).aliases.resolveUsername('myTestAlias');
319
- * expect(username).to.equal('user@company.com');
320
- * });
321
- * });
322
- * ```
323
- */
324
- export declare const testSetup: (sinon?: SinonStatic) => TestContext;
325
- /**
326
- * A pre-canned error for try/catch testing.
327
- *
328
- * **See** {@link shouldThrow}
329
- */
330
- export declare const unexpectedResult: SfError;
331
- /**
332
- * Use for this testing pattern:
333
- * ```
334
- * try {
335
- * await call()
336
- * assert.fail('this should never happen');
337
- * } catch (e) {
338
- * ...
339
- * }
340
- *
341
- * Just do this
342
- *
343
- * try {
344
- * await shouldThrow(call()); // If this succeeds unexpectedResultError is thrown.
345
- * } catch(e) {
346
- * ...
347
- * }
348
- * ```
349
- *
350
- * @param f The async function that is expected to throw.
351
- */
352
- export declare function shouldThrow(f: Promise<unknown>, message?: string): Promise<never>;
353
- /**
354
- * Use for this testing pattern:
355
- * ```
356
- * try {
357
- * call()
358
- * assert.fail('this should never happen');
359
- * } catch (e) {
360
- * ...
361
- * }
362
- *
363
- * Just do this
364
- *
365
- * try {
366
- * shouldThrowSync(call); // If this succeeds unexpectedResultError is thrown.
367
- * } catch(e) {
368
- * ...
369
- * }
370
- * ```
371
- *
372
- * @param f The function that is expected to throw.
373
- */
374
- export declare function shouldThrowSync(f: () => unknown, message?: string): never;
375
- /**
376
- * A helper to determine if a subscription will use callback or errorback.
377
- * Enable errback to simulate a subscription failure.
378
- */
379
- export declare enum StreamingMockSubscriptionCall {
380
- CALLBACK = 0,
381
- ERRORBACK = 1
382
- }
383
- /**
384
- * Additional subscription options for the StreamingMock.
385
- */
386
- export interface StreamingMockCometSubscriptionOptions {
387
- /**
388
- * Target URL.
389
- */
390
- url: string;
391
- /**
392
- * Simple id to associate with this instance.
393
- */
394
- id: string;
395
- /**
396
- * What is the subscription outcome a successful callback or an error?.
397
- */
398
- subscriptionCall: StreamingMockSubscriptionCall;
399
- /**
400
- * If it's an error that states what that error should be.
401
- */
402
- subscriptionErrbackError?: SfError;
403
- /**
404
- * A list of messages to playback for the client. One message per process tick.
405
- */
406
- messagePlaylist?: Message[];
407
- }
408
- /**
409
- * Simulates a comet subscription to a streaming channel.
410
- */
411
- export declare class StreamingMockCometSubscription extends EventEmitter implements CometSubscription {
412
- static SUBSCRIPTION_COMPLETE: string;
413
- static SUBSCRIPTION_FAILED: string;
414
- private options;
415
- constructor(options: StreamingMockCometSubscriptionOptions);
416
- /**
417
- * Sets up a streaming subscription callback to occur after the setTimeout event loop phase.
418
- *
419
- * @param callback The function to invoke.
420
- */
421
- callback(callback: () => void): void;
422
- /**
423
- * Sets up a streaming subscription errback to occur after the setTimeout event loop phase.
424
- *
425
- * @param callback The function to invoke.
426
- */
427
- errback(callback: (error: Error) => void): void;
428
- }
429
- /**
430
- * Simulates a comet client. To the core streaming client this mocks the internal comet impl.
431
- * The uses setTimeout(0ms) event loop phase just so the client can simulate actual streaming without the response
432
- * latency.
433
- */
434
- export declare class StreamingMockCometClient extends CometClient {
435
- private readonly options;
436
- /**
437
- * Constructor
438
- *
439
- * @param {StreamingMockCometSubscriptionOptions} options Extends the StreamingClient options.
440
- */
441
- constructor(options: StreamingMockCometSubscriptionOptions);
442
- /**
443
- * Fake addExtension. Does nothing.
444
- */
445
- addExtension(extension: StreamingExtension): void;
446
- /**
447
- * Fake disable. Does nothing.
448
- */
449
- disable(label: string): void;
450
- /**
451
- * Fake handshake that invoke callback after the setTimeout event phase.
452
- *
453
- * @param callback The function to invoke.
454
- */
455
- handshake(callback: () => void): void;
456
- /**
457
- * Fake setHeader. Does nothing,
458
- */
459
- setHeader(name: string, value: string): void;
460
- /**
461
- * Fake subscription that completed after the setTimout event phase.
462
- *
463
- * @param channel The streaming channel.
464
- * @param callback The function to invoke after the subscription completes.
465
- */
466
- subscribe(channel: string, callback: (message: Message) => void): CometSubscription;
467
- /**
468
- * Fake disconnect. Does Nothing.
469
- */
470
- disconnect(): Promise<void>;
471
- }
472
- /**
473
- * Mock class for Salesforce Orgs.
474
- *
475
- * @example
476
- * ```
477
- * const testOrg = new MockTestOrgData();
478
- * await $$.stubAuths(testOrg)
479
- * ```
480
- */
481
- export declare class MockTestOrgData {
482
- testId: string;
483
- aliases?: string[];
484
- configs?: string[];
485
- username: string;
486
- devHubUsername?: string;
487
- orgId: string;
488
- loginUrl: string;
489
- instanceUrl: string;
490
- clientId: string;
491
- clientSecret: string;
492
- authcode: string;
493
- accessToken: string;
494
- refreshToken: string;
495
- tracksSource: boolean | undefined;
496
- userId: string;
497
- redirectUri: string;
498
- isDevHub?: boolean;
499
- isScratchOrg?: boolean;
500
- isExpired?: boolean | 'unknown';
501
- constructor(id?: string, options?: {
502
- username: string;
503
- });
504
- /**
505
- * Add devhub username to properties.
506
- */
507
- createDevHubUsername(username: string): void;
508
- /**
509
- * Mark this org as a devhub.
510
- */
511
- makeDevHub(): void;
512
- /**
513
- * Returns a MockTestOrgData that represents a user created in the org.
514
- */
515
- createUser(user: string): MockTestOrgData;
516
- /**
517
- * Return mock user information based on this org.
518
- */
519
- getMockUserInfo(): JsonMap;
520
- /**
521
- * Return the auth config file contents.
522
- */
523
- getConfig(): Promise<AuthFields>;
524
- /**
525
- * Return the Connection for the org.
526
- */
527
- getConnection(): Promise<Connection>;
528
- }
529
- /**
530
- * Mock class for Salesforce Sandboxes.
531
- *
532
- * @example
533
- * ```
534
- * const testOrg = new MockTestSandboxData();
535
- * await $$.stubSandboxes(testOrg)
536
- * ```
537
- */
538
- export declare class MockTestSandboxData {
539
- id: string;
540
- sandboxOrgId: string;
541
- prodOrgUsername: string;
542
- sandboxName?: string;
543
- username?: string;
544
- constructor(id?: string, options?: Partial<{
545
- prodOrgUsername: string;
546
- name: string;
547
- username: string;
548
- }>);
549
- /**
550
- * Return the auth config file contents.
551
- */
552
- getConfig(): Promise<SandboxFields>;
553
- }
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { SinonSandbox, SinonStatic, SinonStub } from 'sinon';
4
+ import { AnyJson, JsonMap, Optional } from '@salesforce/ts-types';
5
+ import { ConfigContents } from './config/configStore';
6
+ import { Connection } from './org/connection';
7
+ import { Logger } from './logger';
8
+ import { SfError } from './sfError';
9
+ import { CometClient, CometSubscription, Message, StreamingExtension } from './status/streamingClient';
10
+ import { AuthFields, SandboxFields } from './org';
11
+ import { AliasGroup } from './config/aliasesConfig';
12
+ /**
13
+ * Different parts of the system that are mocked out. They can be restored for
14
+ * individual tests. Test's stubs should always go on the DEFAULT which is exposed
15
+ * on the TestContext.
16
+ */
17
+ export interface SandboxTypes {
18
+ DEFAULT: SinonSandbox;
19
+ CRYPTO: SinonSandbox;
20
+ CONFIG: SinonSandbox;
21
+ PROJECT: SinonSandbox;
22
+ CONNECTION: SinonSandbox;
23
+ FS: SinonSandbox;
24
+ ORGS: SinonSandbox;
25
+ }
26
+ /**
27
+ * Different hooks into {@link ConfigFile} used for testing instead of doing file IO.
28
+ */
29
+ export interface ConfigStub {
30
+ /**
31
+ * readFn A function that controls all aspect of {@link ConfigFile.read}. For example, it won't set the contents
32
+ * unless explicitly done. Only use this if you know what you are doing. Use retrieveContents
33
+ * instead.
34
+ */
35
+ readFn?: () => Promise<ConfigContents>;
36
+ /**
37
+ * A function that controls all aspects of {@link ConfigFile.write}. For example, it won't read the contents unless
38
+ * explicitly done. Only use this if you know what you are doing. Use updateContents instead.
39
+ */
40
+ writeFn?: (contents?: AnyJson) => Promise<void>;
41
+ /**
42
+ * The contents that are used with @{link ConfigFile.readSync} and @{link ConfigFile.read}. If retrieveContents is set,
43
+ * it will use that instead of @{link ConfigFile.read} but NOT @{link ConfigFile.readSync}. This will also contain the
44
+ * new config when @{link ConfigFile.write} or @{link ConfigFile.writeSync} is called. This will persist through config instances,
45
+ * such as {@link Alias.update} and {@link Alias.fetch}.
46
+ */
47
+ contents?: ConfigContents;
48
+ /**
49
+ * A function to conditionally read based on the config instance. The `this` value will be the config instance.
50
+ */
51
+ retrieveContents?: () => Promise<JsonMap>;
52
+ /**
53
+ * A function to conditionally set based on the config instance. The `this` value will be the config instance.
54
+ */
55
+ updateContents?: () => Promise<JsonMap>;
56
+ }
57
+ /**
58
+ * Instantiate a @salesforce/core test context.
59
+ */
60
+ export declare class TestContext {
61
+ /**
62
+ * The default sandbox is cleared out before each test run.
63
+ *
64
+ * **See** [sinon sandbox]{@link https://sinonjs.org/releases/v14/sandbox/}.
65
+ */
66
+ SANDBOX: SinonSandbox;
67
+ /**
68
+ * An object of different sandboxes. Used when
69
+ * needing to restore parts of the system for customized testing.
70
+ */
71
+ SANDBOXES: SandboxTypes;
72
+ /**
73
+ * The test logger that is used when {@link Logger.child} is used anywhere. It uses memory logging.
74
+ */
75
+ TEST_LOGGER: Logger;
76
+ /**
77
+ * id A unique id for the test run.
78
+ */
79
+ id: string;
80
+ /**
81
+ * An object used in tests that interact with config files.
82
+ */
83
+ configStubs: {
84
+ [configName: string]: Optional<ConfigStub>;
85
+ AliasesConfig?: ConfigStub;
86
+ AuthInfoConfig?: ConfigStub;
87
+ Config?: ConfigStub;
88
+ SfProjectJson?: ConfigStub;
89
+ TokensConfig?: ConfigStub;
90
+ };
91
+ /**
92
+ * A record of stubs created during instantiation.
93
+ */
94
+ stubs: Record<string, SinonStub>;
95
+ constructor(options?: {
96
+ sinon?: SinonStatic;
97
+ sandbox?: SinonSandbox;
98
+ setup?: boolean;
99
+ });
100
+ /**
101
+ * Generate unique string.
102
+ */
103
+ uniqid(): string;
104
+ /**
105
+ * A function used when resolving the local path. Calls localPathResolverSync by default.
106
+ *
107
+ * @param uid Unique id.
108
+ */
109
+ localPathRetriever(uid: string): Promise<string>;
110
+ /**
111
+ * A function used when resolving the local path.
112
+ *
113
+ * @param uid Unique id.
114
+ */
115
+ localPathRetrieverSync(uid: string): string;
116
+ /**
117
+ * A function used when resolving the global path. Calls globalPathResolverSync by default.
118
+ *
119
+ * @param uid Unique id.
120
+ */
121
+ globalPathRetriever(uid: string): Promise<string>;
122
+ /**
123
+ * A function used when resolving the global path.
124
+ *
125
+ * @param uid Unique id.
126
+ */
127
+ globalPathRetrieverSync(uid: string): string;
128
+ /**
129
+ * A function used for resolving paths. Calls localPathRetriever and globalPathRetriever.
130
+ *
131
+ * @param isGlobal `true` if the config is global.
132
+ * @param uid user id.
133
+ */
134
+ rootPathRetriever(isGlobal: boolean, uid?: string): Promise<string>;
135
+ /**
136
+ * A function used for resolving paths. Calls localPathRetrieverSync and globalPathRetrieverSync.
137
+ *
138
+ * @param isGlobal `true` if the config is global.
139
+ * @param uid user id.
140
+ */
141
+ rootPathRetrieverSync(isGlobal: boolean, uid?: string): string;
142
+ /**
143
+ * Used to mock http request to Salesforce.
144
+ *
145
+ * @param request An HttpRequest.
146
+ * @param options Additional options.
147
+ *
148
+ * **See** {@link Connection.request}
149
+ */
150
+ fakeConnectionRequest(request: AnyJson, options?: AnyJson): Promise<AnyJson>;
151
+ /**
152
+ * Gets a config stub contents by name.
153
+ *
154
+ * @param name The name of the config.
155
+ * @param group If the config supports groups.
156
+ */
157
+ getConfigStubContents(name: string, group?: string): ConfigContents;
158
+ /**
159
+ * Sets a config stub contents by name
160
+ *
161
+ * @param name The name of the config stub.
162
+ * @param value The actual stub contents. The Mock data.
163
+ */
164
+ setConfigStubContents(name: string, value: ConfigContents): void;
165
+ /**
166
+ * Set stubs for working in the context of a SfProject
167
+ */
168
+ inProject(inProject?: boolean): void;
169
+ /**
170
+ * Stub salesforce org authorizations.
171
+ */
172
+ stubAuths(...orgs: MockTestOrgData[]): Promise<void>;
173
+ /**
174
+ * Stub salesforce sandbox authorizations.
175
+ */
176
+ stubSandboxes(...sandboxes: MockTestSandboxData[]): Promise<void>;
177
+ /**
178
+ * Stub the aliases in the global aliases config file.
179
+ */
180
+ stubAliases(aliases: Record<string, string>, group?: AliasGroup): void;
181
+ /**
182
+ * Stub contents in the config file.
183
+ */
184
+ stubConfig(config: Record<string, string>): Promise<void>;
185
+ /**
186
+ * Stub the tokens in the global token config file.
187
+ */
188
+ stubTokens(tokens: Record<string, string>): void;
189
+ restore(): void;
190
+ init(): void;
191
+ /**
192
+ * Add beforeEach and afterEach hooks to init the stubs and restore them.
193
+ * This is called automatically when the class is instantiated unless the setup option is set to false.
194
+ */
195
+ setup(): void;
196
+ private requireSinon;
197
+ }
198
+ /**
199
+ * A function to generate a unique id and return it in the context of a template, if supplied.
200
+ *
201
+ * A template is a string that can contain `${%s}` to be replaced with a unique id.
202
+ * If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
203
+ *
204
+ * @param options an object with the following properties:
205
+ * - template: a template string.
206
+ * - length: the length of the unique id as presented in hexadecimal.
207
+ */
208
+ export declare function uniqid(options?: {
209
+ template?: string;
210
+ length?: number;
211
+ }): string;
212
+ /**
213
+ * Instantiate a @salesforce/core test context. This is automatically created by `const $$ = testSetup()`
214
+ * but is useful if you don't want to have a global stub of @salesforce/core and you want to isolate it to
215
+ * a single describe.
216
+ *
217
+ * **Note:** Call `stubContext` in your beforeEach to have clean stubs of @salesforce/core every test run.
218
+ *
219
+ * @example
220
+ * ```
221
+ * const $$ = instantiateContext();
222
+ *
223
+ * beforeEach(() => {
224
+ * $$.init()
225
+ * });
226
+ *
227
+ * afterEach(() => {
228
+ * $$.restore();
229
+ * });
230
+ * ```
231
+ * @param sinon
232
+ */
233
+ export declare const instantiateContext: (sinon?: SinonStatic) => TestContext;
234
+ /**
235
+ * Stub a @salesforce/core test context. This will mock out logging to a file, config file reading and writing,
236
+ * local and global path resolution, and http request using connection (soon)*.
237
+ *
238
+ * This is automatically stubbed in the global beforeEach created by
239
+ * `const $$ = testSetup()` but is useful if you don't want to have a global stub of @salesforce/core and you
240
+ * want to isolate it to a single describe.
241
+ *
242
+ * **Note:** Always call `restoreContext` in your afterEach.
243
+ *
244
+ * @example
245
+ * ```
246
+ * const $$ = instantiateContext();
247
+ *
248
+ * beforeEach(() => {
249
+ * $$.init()
250
+ * });
251
+ *
252
+ * afterEach(() => {
253
+ * $$.restore();
254
+ * });
255
+ * ```
256
+ * @param testContext
257
+ */
258
+ export declare const stubContext: (testContext: TestContext) => Record<string, SinonStub>;
259
+ /**
260
+ * Restore a @salesforce/core test context. This is automatically stubbed in the global beforeEach created by
261
+ * `const $$ = testSetup()` but is useful if you don't want to have a global stub of @salesforce/core and you
262
+ * want to isolate it to a single describe.
263
+ *
264
+ * @example
265
+ * ```
266
+ * const $$ = instantiateContext();
267
+ *
268
+ * beforeEach(() => {
269
+ * $$.init()
270
+ * });
271
+ *
272
+ * afterEach(() => {
273
+ * $$.restore();
274
+ * });
275
+ * ```
276
+ * @param testContext
277
+ */
278
+ export declare const restoreContext: (testContext: TestContext) => void;
279
+ /**
280
+ * @deprecated Use TestContext instead.
281
+ * Using testSetup will create globals stubs that could lead to erratic test behavior.
282
+ *
283
+ * This example shows you how to use TestContext:
284
+ * @example
285
+ * ```
286
+ * const $$ = new TestContext();
287
+ *
288
+ * beforeEach(() => {
289
+ * $$.init();
290
+ * });
291
+ *
292
+ * afterEach(() => {
293
+ * $$.restore();
294
+ * });
295
+ * ```
296
+ *
297
+ * Use to mock out different pieces of sfdx-core to make testing easier. This will mock out
298
+ * logging to a file, config file reading and writing, local and global path resolution, and
299
+ * *http request using connection (soon)*.
300
+ *
301
+ * **Note:** The testSetup should be outside of the describe. If you need to stub per test, use
302
+ * `TestContext`.
303
+ * ```
304
+ * // In a mocha tests
305
+ * import testSetup from '@salesforce/core/lib/testSetup';
306
+ *
307
+ * const $$ = testSetup();
308
+ *
309
+ * describe(() => {
310
+ * it('test', () => {
311
+ * // Stub out your own method
312
+ * $$.SANDBOX.stub(MyClass.prototype, 'myMethod').returnsFake(() => {});
313
+ *
314
+ * // Set the contents that is used when aliases are read. Same for all config files.
315
+ * $$.stubAliases({ 'myTestAlias': 'user@company.com' });
316
+ *
317
+ * // Will use the contents set above.
318
+ * const username = (await StateAggregator.getInstance()).aliases.resolveUsername('myTestAlias');
319
+ * expect(username).to.equal('user@company.com');
320
+ * });
321
+ * });
322
+ * ```
323
+ */
324
+ export declare const testSetup: (sinon?: SinonStatic) => TestContext;
325
+ /**
326
+ * A pre-canned error for try/catch testing.
327
+ *
328
+ * **See** {@link shouldThrow}
329
+ */
330
+ export declare const unexpectedResult: SfError;
331
+ /**
332
+ * Use for this testing pattern:
333
+ * ```
334
+ * try {
335
+ * await call()
336
+ * assert.fail('this should never happen');
337
+ * } catch (e) {
338
+ * ...
339
+ * }
340
+ *
341
+ * Just do this
342
+ *
343
+ * try {
344
+ * await shouldThrow(call()); // If this succeeds unexpectedResultError is thrown.
345
+ * } catch(e) {
346
+ * ...
347
+ * }
348
+ * ```
349
+ *
350
+ * @param f The async function that is expected to throw.
351
+ */
352
+ export declare function shouldThrow(f: Promise<unknown>, message?: string): Promise<never>;
353
+ /**
354
+ * Use for this testing pattern:
355
+ * ```
356
+ * try {
357
+ * call()
358
+ * assert.fail('this should never happen');
359
+ * } catch (e) {
360
+ * ...
361
+ * }
362
+ *
363
+ * Just do this
364
+ *
365
+ * try {
366
+ * shouldThrowSync(call); // If this succeeds unexpectedResultError is thrown.
367
+ * } catch(e) {
368
+ * ...
369
+ * }
370
+ * ```
371
+ *
372
+ * @param f The function that is expected to throw.
373
+ */
374
+ export declare function shouldThrowSync(f: () => unknown, message?: string): never;
375
+ /**
376
+ * A helper to determine if a subscription will use callback or errorback.
377
+ * Enable errback to simulate a subscription failure.
378
+ */
379
+ export declare enum StreamingMockSubscriptionCall {
380
+ CALLBACK = 0,
381
+ ERRORBACK = 1
382
+ }
383
+ /**
384
+ * Additional subscription options for the StreamingMock.
385
+ */
386
+ export interface StreamingMockCometSubscriptionOptions {
387
+ /**
388
+ * Target URL.
389
+ */
390
+ url: string;
391
+ /**
392
+ * Simple id to associate with this instance.
393
+ */
394
+ id: string;
395
+ /**
396
+ * What is the subscription outcome a successful callback or an error?.
397
+ */
398
+ subscriptionCall: StreamingMockSubscriptionCall;
399
+ /**
400
+ * If it's an error that states what that error should be.
401
+ */
402
+ subscriptionErrbackError?: SfError;
403
+ /**
404
+ * A list of messages to playback for the client. One message per process tick.
405
+ */
406
+ messagePlaylist?: Message[];
407
+ }
408
+ /**
409
+ * Simulates a comet subscription to a streaming channel.
410
+ */
411
+ export declare class StreamingMockCometSubscription extends EventEmitter implements CometSubscription {
412
+ static SUBSCRIPTION_COMPLETE: string;
413
+ static SUBSCRIPTION_FAILED: string;
414
+ private options;
415
+ constructor(options: StreamingMockCometSubscriptionOptions);
416
+ /**
417
+ * Sets up a streaming subscription callback to occur after the setTimeout event loop phase.
418
+ *
419
+ * @param callback The function to invoke.
420
+ */
421
+ callback(callback: () => void): void;
422
+ /**
423
+ * Sets up a streaming subscription errback to occur after the setTimeout event loop phase.
424
+ *
425
+ * @param callback The function to invoke.
426
+ */
427
+ errback(callback: (error: Error) => void): void;
428
+ }
429
+ /**
430
+ * Simulates a comet client. To the core streaming client this mocks the internal comet impl.
431
+ * The uses setTimeout(0ms) event loop phase just so the client can simulate actual streaming without the response
432
+ * latency.
433
+ */
434
+ export declare class StreamingMockCometClient extends CometClient {
435
+ private readonly options;
436
+ /**
437
+ * Constructor
438
+ *
439
+ * @param {StreamingMockCometSubscriptionOptions} options Extends the StreamingClient options.
440
+ */
441
+ constructor(options: StreamingMockCometSubscriptionOptions);
442
+ /**
443
+ * Fake addExtension. Does nothing.
444
+ */
445
+ addExtension(extension: StreamingExtension): void;
446
+ /**
447
+ * Fake disable. Does nothing.
448
+ */
449
+ disable(label: string): void;
450
+ /**
451
+ * Fake handshake that invoke callback after the setTimeout event phase.
452
+ *
453
+ * @param callback The function to invoke.
454
+ */
455
+ handshake(callback: () => void): void;
456
+ /**
457
+ * Fake setHeader. Does nothing,
458
+ */
459
+ setHeader(name: string, value: string): void;
460
+ /**
461
+ * Fake subscription that completed after the setTimout event phase.
462
+ *
463
+ * @param channel The streaming channel.
464
+ * @param callback The function to invoke after the subscription completes.
465
+ */
466
+ subscribe(channel: string, callback: (message: Message) => void): CometSubscription;
467
+ /**
468
+ * Fake disconnect. Does Nothing.
469
+ */
470
+ disconnect(): Promise<void>;
471
+ }
472
+ /**
473
+ * Mock class for Salesforce Orgs.
474
+ *
475
+ * @example
476
+ * ```
477
+ * const testOrg = new MockTestOrgData();
478
+ * await $$.stubAuths(testOrg)
479
+ * ```
480
+ */
481
+ export declare class MockTestOrgData {
482
+ testId: string;
483
+ aliases?: string[];
484
+ configs?: string[];
485
+ username: string;
486
+ devHubUsername?: string;
487
+ orgId: string;
488
+ loginUrl: string;
489
+ instanceUrl: string;
490
+ clientId: string;
491
+ clientSecret: string;
492
+ authcode: string;
493
+ accessToken: string;
494
+ refreshToken: string;
495
+ tracksSource: boolean | undefined;
496
+ userId: string;
497
+ redirectUri: string;
498
+ isDevHub?: boolean;
499
+ isScratchOrg?: boolean;
500
+ isExpired?: boolean | 'unknown';
501
+ constructor(id?: string, options?: {
502
+ username: string;
503
+ });
504
+ /**
505
+ * Add devhub username to properties.
506
+ */
507
+ createDevHubUsername(username: string): void;
508
+ /**
509
+ * Mark this org as a devhub.
510
+ */
511
+ makeDevHub(): void;
512
+ /**
513
+ * Returns a MockTestOrgData that represents a user created in the org.
514
+ */
515
+ createUser(user: string): MockTestOrgData;
516
+ /**
517
+ * Return mock user information based on this org.
518
+ */
519
+ getMockUserInfo(): JsonMap;
520
+ /**
521
+ * Return the auth config file contents.
522
+ */
523
+ getConfig(): Promise<AuthFields>;
524
+ /**
525
+ * Return the Connection for the org.
526
+ */
527
+ getConnection(): Promise<Connection>;
528
+ }
529
+ /**
530
+ * Mock class for Salesforce Sandboxes.
531
+ *
532
+ * @example
533
+ * ```
534
+ * const testOrg = new MockTestSandboxData();
535
+ * await $$.stubSandboxes(testOrg)
536
+ * ```
537
+ */
538
+ export declare class MockTestSandboxData {
539
+ id: string;
540
+ sandboxOrgId: string;
541
+ prodOrgUsername: string;
542
+ sandboxName?: string;
543
+ username?: string;
544
+ constructor(id?: string, options?: Partial<{
545
+ prodOrgUsername: string;
546
+ name: string;
547
+ username: string;
548
+ }>);
549
+ /**
550
+ * Return the auth config file contents.
551
+ */
552
+ getConfig(): Promise<SandboxFields>;
553
+ }