@salesforce/core 3.19.2 → 3.19.5

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 (54) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +6 -18
  3. package/lib/config/aliasesConfig.d.ts +12 -0
  4. package/lib/config/aliasesConfig.js +27 -0
  5. package/lib/config/authInfoConfig.d.ts +19 -0
  6. package/lib/config/authInfoConfig.js +35 -0
  7. package/lib/config/configAggregator.d.ts +5 -3
  8. package/lib/config/configAggregator.js +13 -1
  9. package/lib/config/configFile.js +2 -2
  10. package/lib/config/configGroup.d.ts +141 -0
  11. package/lib/config/configGroup.js +224 -0
  12. package/lib/config/configStore.d.ts +2 -2
  13. package/lib/config/configStore.js +1 -2
  14. package/lib/config/tokensConfig.d.ts +10 -0
  15. package/lib/config/tokensConfig.js +28 -0
  16. package/lib/crypto/keyChainImpl.js +1 -1
  17. package/lib/exported.d.ts +1 -1
  18. package/lib/exported.js +6 -5
  19. package/lib/global.d.ts +8 -0
  20. package/lib/global.js +10 -0
  21. package/lib/org/authInfo.d.ts +1 -1
  22. package/lib/org/authInfo.js +22 -22
  23. package/lib/org/authRemover.d.ts +6 -5
  24. package/lib/org/authRemover.js +22 -16
  25. package/lib/org/connection.js +1 -1
  26. package/lib/org/org.d.ts +12 -4
  27. package/lib/org/org.js +28 -26
  28. package/lib/org/scratchOrgCreate.js +5 -7
  29. package/lib/org/scratchOrgInfoApi.js +1 -1
  30. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +79 -1
  31. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +119 -2
  32. package/lib/stateAggregator/accessors/orgAccessor.d.ts +53 -0
  33. package/lib/stateAggregator/accessors/orgAccessor.js +201 -0
  34. package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.d.ts +12 -1
  35. package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.js +22 -2
  36. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +28 -0
  37. package/lib/{globalInfo → stateAggregator}/accessors/tokenAccessor.js +34 -2
  38. package/lib/{globalInfo → stateAggregator}/globalInfoConfig.d.ts +11 -8
  39. package/lib/{globalInfo → stateAggregator}/globalInfoConfig.js +7 -4
  40. package/lib/stateAggregator/index.d.ts +7 -0
  41. package/lib/{globalInfo → stateAggregator}/index.js +5 -1
  42. package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.d.ts +7 -1
  43. package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.js +25 -2
  44. package/lib/stateAggregator/stateAggregator.d.ts +20 -0
  45. package/lib/stateAggregator/stateAggregator.js +38 -0
  46. package/lib/{globalInfo → stateAggregator}/types.d.ts +25 -10
  47. package/lib/{globalInfo → stateAggregator}/types.js +3 -0
  48. package/lib/testSetup.d.ts +30 -6
  49. package/lib/testSetup.js +79 -11
  50. package/package.json +1 -1
  51. package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
  52. package/lib/globalInfo/accessors/orgAccessor.js +0 -45
  53. package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
  54. package/lib/globalInfo/index.d.ts +0 -6
@@ -1,12 +1,15 @@
1
1
  import { AnyJson } from '@salesforce/ts-types';
2
2
  import { ConfigFile } from '../config/configFile';
3
3
  import { ConfigValue } from '../config/configStore';
4
- import { OrgAccessor } from './accessors/orgAccessor';
5
- import { TokenAccessor } from './accessors/tokenAccessor';
6
- import { AliasAccessor } from './accessors/aliasAccessor';
4
+ import { GlobalInfoOrgAccessor } from './accessors/orgAccessor';
5
+ import { GlobaInfoTokenAccessor } from './accessors/tokenAccessor';
6
+ import { GlobalInfoAliasAccessor } from './accessors/aliasAccessor';
7
7
  import { SfInfo } from './types';
8
- import { SandboxAccessor } from './accessors/sandboxAccessor';
8
+ import { GlobalInfoSandboxAccessor } from './accessors/sandboxAccessor';
9
9
  export declare function deepCopy<T extends AnyJson>(data: T): T;
10
+ /**
11
+ * @deprecated use StateAggregator instead.
12
+ */
10
13
  export declare class GlobalInfo extends ConfigFile<ConfigFile.Options, SfInfo> {
11
14
  protected static encryptedKeys: RegExp[];
12
15
  private static EMPTY_DATA_MODEL;
@@ -25,10 +28,10 @@ export declare class GlobalInfo extends ConfigFile<ConfigFile.Options, SfInfo> {
25
28
  * Gets default options for the SfConfig
26
29
  */
27
30
  static getDefaultOptions(): ConfigFile.Options;
28
- get orgs(): OrgAccessor;
29
- get tokens(): TokenAccessor;
30
- get aliases(): AliasAccessor;
31
- get sandboxes(): SandboxAccessor;
31
+ get orgs(): GlobalInfoOrgAccessor;
32
+ get tokens(): GlobaInfoTokenAccessor;
33
+ get aliases(): GlobalInfoAliasAccessor;
34
+ get sandboxes(): GlobalInfoSandboxAccessor;
32
35
  set(key: string, value: ConfigValue): void;
33
36
  write(newContents?: SfInfo): Promise<SfInfo>;
34
37
  protected init(): Promise<void>;
@@ -20,6 +20,9 @@ function deepCopy(data) {
20
20
  return JSON.parse(JSON.stringify(data));
21
21
  }
22
22
  exports.deepCopy = deepCopy;
23
+ /**
24
+ * @deprecated use StateAggregator instead.
25
+ */
23
26
  class GlobalInfo extends configFile_1.ConfigFile {
24
27
  constructor() {
25
28
  super(...arguments);
@@ -57,16 +60,16 @@ class GlobalInfo extends configFile_1.ConfigFile {
57
60
  };
58
61
  }
59
62
  get orgs() {
60
- return new orgAccessor_1.OrgAccessor(this);
63
+ return new orgAccessor_1.GlobalInfoOrgAccessor(this);
61
64
  }
62
65
  get tokens() {
63
- return new tokenAccessor_1.TokenAccessor(this);
66
+ return new tokenAccessor_1.GlobaInfoTokenAccessor(this);
64
67
  }
65
68
  get aliases() {
66
- return new aliasAccessor_1.AliasAccessor(this);
69
+ return new aliasAccessor_1.GlobalInfoAliasAccessor(this);
67
70
  }
68
71
  get sandboxes() {
69
- return new sandboxAccessor_1.SandboxAccessor(this);
72
+ return new sandboxAccessor_1.GlobalInfoSandboxAccessor(this);
70
73
  }
71
74
  set(key, value) {
72
75
  if ((0, ts_types_1.isPlainObject)(value)) {
@@ -0,0 +1,7 @@
1
+ export * from './globalInfoConfig';
2
+ export * from './sfdxDataHandler';
3
+ export * from './types';
4
+ export { GlobalInfoOrgAccessor, OrgAccessor } from './accessors/orgAccessor';
5
+ export { GlobalInfoAliasAccessor, AliasAccessor } from './accessors/aliasAccessor';
6
+ export { GlobaInfoTokenAccessor, TokenAccessor } from './accessors/tokenAccessor';
7
+ export * from './stateAggregator';
@@ -16,14 +16,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.TokenAccessor = exports.AliasAccessor = exports.OrgAccessor = void 0;
19
+ exports.TokenAccessor = exports.GlobaInfoTokenAccessor = exports.AliasAccessor = exports.GlobalInfoAliasAccessor = exports.OrgAccessor = exports.GlobalInfoOrgAccessor = void 0;
20
20
  __exportStar(require("./globalInfoConfig"), exports);
21
21
  __exportStar(require("./sfdxDataHandler"), exports);
22
22
  __exportStar(require("./types"), exports);
23
23
  var orgAccessor_1 = require("./accessors/orgAccessor");
24
+ Object.defineProperty(exports, "GlobalInfoOrgAccessor", { enumerable: true, get: function () { return orgAccessor_1.GlobalInfoOrgAccessor; } });
24
25
  Object.defineProperty(exports, "OrgAccessor", { enumerable: true, get: function () { return orgAccessor_1.OrgAccessor; } });
25
26
  var aliasAccessor_1 = require("./accessors/aliasAccessor");
27
+ Object.defineProperty(exports, "GlobalInfoAliasAccessor", { enumerable: true, get: function () { return aliasAccessor_1.GlobalInfoAliasAccessor; } });
26
28
  Object.defineProperty(exports, "AliasAccessor", { enumerable: true, get: function () { return aliasAccessor_1.AliasAccessor; } });
27
29
  var tokenAccessor_1 = require("./accessors/tokenAccessor");
30
+ Object.defineProperty(exports, "GlobaInfoTokenAccessor", { enumerable: true, get: function () { return tokenAccessor_1.GlobaInfoTokenAccessor; } });
28
31
  Object.defineProperty(exports, "TokenAccessor", { enumerable: true, get: function () { return tokenAccessor_1.TokenAccessor; } });
32
+ __exportStar(require("./stateAggregator"), exports);
29
33
  //# sourceMappingURL=index.js.map
@@ -11,7 +11,7 @@ interface Changes<T> {
11
11
  deleted: string[];
12
12
  }
13
13
  export declare class SfdxDataHandler {
14
- handlers: (AuthHandler | AliasesHandler | SandboxesHandler)[];
14
+ handlers: (AuthHandler | AliasesHandler | SandboxesHandler | TokensHandler)[];
15
15
  private original;
16
16
  write(latest?: SfInfo): Promise<void>;
17
17
  merge(sfData?: SfInfo): Promise<SfInfo>;
@@ -50,4 +50,10 @@ export declare class SandboxesHandler extends BaseHandler<SfInfoKeys.SANDBOXES>
50
50
  listAllSandboxes(): Promise<SfSandbox[]>;
51
51
  private findChanges;
52
52
  }
53
+ export declare class TokensHandler extends BaseHandler<SfInfoKeys.TOKENS> {
54
+ private static SFDX_TOKENS_FILENAME;
55
+ sfKey: typeof SfInfoKeys.TOKENS;
56
+ migrate(): Promise<Pick<SfInfo, SfInfoKeys.TOKENS>>;
57
+ write(latest: SfInfo): Promise<void>;
58
+ }
53
59
  export {};
@@ -6,7 +6,7 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.SandboxesHandler = exports.AliasesHandler = exports.AuthHandler = exports.SfdxDataHandler = void 0;
9
+ exports.TokensHandler = exports.SandboxesHandler = exports.AliasesHandler = exports.AuthHandler = exports.SfdxDataHandler = void 0;
10
10
  const path_1 = require("path");
11
11
  const fs = require("fs");
12
12
  const kit_1 = require("@salesforce/kit");
@@ -29,7 +29,7 @@ function isEqual(object1, object2) {
29
29
  }
30
30
  class SfdxDataHandler {
31
31
  constructor() {
32
- this.handlers = [new AuthHandler(), new AliasesHandler(), new SandboxesHandler()];
32
+ this.handlers = [new AuthHandler(), new AliasesHandler(), new SandboxesHandler(), new TokensHandler()];
33
33
  }
34
34
  async write(latest = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
35
35
  await Promise.all(this.handlers.map((handler) => handler.write(latest, this.original)));
@@ -306,4 +306,27 @@ class SandboxesHandler extends BaseHandler {
306
306
  exports.SandboxesHandler = SandboxesHandler;
307
307
  // The regular expression that filters files stored in $HOME/.sfdx
308
308
  SandboxesHandler.sandboxFilenameFilterRegEx = /^(00D.*?)\.sandbox\.json$/;
309
+ class TokensHandler extends BaseHandler {
310
+ constructor() {
311
+ super(...arguments);
312
+ this.sfKey = types_1.SfInfoKeys.TOKENS;
313
+ }
314
+ async migrate() {
315
+ const filePath = (0, path_1.join)(global_1.Global.SFDX_DIR, TokensHandler.SFDX_TOKENS_FILENAME);
316
+ try {
317
+ const x = await fs.promises.readFile(filePath, 'utf8');
318
+ const tokens = (0, kit_1.parseJson)(x);
319
+ return { [this.sfKey]: tokens };
320
+ }
321
+ catch (e) {
322
+ return { [this.sfKey]: {} };
323
+ }
324
+ }
325
+ async write(latest) {
326
+ const filePath = (0, path_1.join)(global_1.Global.SFDX_DIR, TokensHandler.SFDX_TOKENS_FILENAME);
327
+ await fs.promises.writeFile(filePath, JSON.stringify(latest[types_1.SfInfoKeys.TOKENS], null, 2));
328
+ }
329
+ }
330
+ exports.TokensHandler = TokensHandler;
331
+ TokensHandler.SFDX_TOKENS_FILENAME = 'tokens.json';
309
332
  //# sourceMappingURL=sfdxDataHandler.js.map
@@ -0,0 +1,20 @@
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 instance;
8
+ aliases: AliasAccessor;
9
+ orgs: OrgAccessor;
10
+ sandboxes: SandboxAccessor;
11
+ tokens: TokenAccessor;
12
+ static getInstance(): Promise<StateAggregator>;
13
+ /**
14
+ * Clear the cache to force reading from disk.
15
+ *
16
+ * *NOTE: Only call this method if you must and you know what you are doing.*
17
+ */
18
+ static clearInstance(): void;
19
+ protected init(): Promise<void>;
20
+ }
@@ -0,0 +1,38 @@
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 aliasAccessor_1 = require("./accessors/aliasAccessor");
12
+ const orgAccessor_1 = require("./accessors/orgAccessor");
13
+ const sandboxAccessor_1 = require("./accessors/sandboxAccessor");
14
+ const tokenAccessor_1 = require("./accessors/tokenAccessor");
15
+ class StateAggregator extends kit_1.AsyncOptionalCreatable {
16
+ static async getInstance() {
17
+ if (!StateAggregator.instance) {
18
+ StateAggregator.instance = await StateAggregator.create();
19
+ }
20
+ return StateAggregator.instance;
21
+ }
22
+ /**
23
+ * Clear the cache to force reading from disk.
24
+ *
25
+ * *NOTE: Only call this method if you must and you know what you are doing.*
26
+ */
27
+ static clearInstance() {
28
+ delete StateAggregator.instance;
29
+ }
30
+ async init() {
31
+ this.orgs = await orgAccessor_1.OrgAccessor.create();
32
+ this.sandboxes = await sandboxAccessor_1.SandboxAccessor.create();
33
+ this.aliases = await aliasAccessor_1.AliasAccessor.create();
34
+ this.tokens = await tokenAccessor_1.TokenAccessor.create();
35
+ }
36
+ }
37
+ exports.StateAggregator = StateAggregator;
38
+ //# sourceMappingURL=stateAggregator.js.map
@@ -1,4 +1,8 @@
1
1
  import { JsonMap } from '@salesforce/ts-types';
2
+ import { AuthFields } from '../org';
3
+ /**
4
+ * @deprecated
5
+ */
2
6
  export declare enum SfInfoKeys {
3
7
  ORGS = "orgs",
4
8
  TOKENS = "tokens",
@@ -9,12 +13,13 @@ export declare type Timestamp = {
9
13
  timestamp: string;
10
14
  };
11
15
  export declare type SfEntry = JsonMap;
12
- export declare type SfOrg = {
13
- username: string;
14
- orgId: string;
15
- instanceUrl: string;
16
- accessToken?: string;
17
- } & SfEntry;
16
+ /**
17
+ * @deprecated
18
+ */
19
+ export declare type SfOrg = AuthFields & SfEntry;
20
+ /**
21
+ * @deprecated
22
+ */
18
23
  export interface SfOrgs {
19
24
  [key: string]: SfOrg & Timestamp;
20
25
  }
@@ -23,16 +28,21 @@ export declare type SfToken = {
23
28
  url: string;
24
29
  user?: string;
25
30
  } & SfEntry;
26
- export interface SfTokens {
31
+ /**
32
+ */
33
+ export declare type SfTokens = {
27
34
  [key: string]: SfToken & Timestamp;
28
- }
35
+ };
29
36
  /**
30
37
  * The key will always be the alias and the value will always be the username, e.g.
31
38
  * { "MyAlias": "user@salesforce.com" }
32
39
  */
33
- export interface SfAliases {
40
+ export declare type SfAliases = {
34
41
  [alias: string]: string;
35
- }
42
+ };
43
+ /**
44
+ * @deprecated
45
+ */
36
46
  export declare type SfSandbox = {
37
47
  sandboxOrgId: string;
38
48
  prodOrgUsername: string;
@@ -45,10 +55,15 @@ export declare type SfSandbox = {
45
55
  * The key will always be the sandbox username and the value will always be the
46
56
  * production org username
47
57
  * { "user@salesforce.com.mysandbox": "user@salesforce.com" }
58
+ *
59
+ * @deprecated
48
60
  */
49
61
  export interface SfSandboxes {
50
62
  [sandboxOrgId: string]: SfSandbox;
51
63
  }
64
+ /**
65
+ * @deprecated
66
+ */
52
67
  export declare type SfInfo = {
53
68
  [SfInfoKeys.ORGS]: SfOrgs;
54
69
  [SfInfoKeys.TOKENS]: SfTokens;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SfInfoKeys = void 0;
4
+ /**
5
+ * @deprecated
6
+ */
4
7
  var SfInfoKeys;
5
8
  (function (SfInfoKeys) {
6
9
  SfInfoKeys["ORGS"] = "orgs";
@@ -6,7 +6,8 @@ import { ConfigContents } from './config/configStore';
6
6
  import { Logger } from './logger';
7
7
  import { SfError } from './sfError';
8
8
  import { CometClient, CometSubscription, Message, StreamingExtension } from './status/streamingClient';
9
- import { SfOrg } from './globalInfo';
9
+ import { AuthFields, SandboxFields } from './org';
10
+ import { AliasGroup } from './config/aliasesConfig';
10
11
  /**
11
12
  * Different parts of the system that are mocked out. They can be restored for
12
13
  * individual tests. Test's stubs should always go on the DEFAULT which is exposed
@@ -19,6 +20,7 @@ export interface SandboxTypes {
19
20
  PROJECT: sinon.SinonSandbox;
20
21
  CONNECTION: sinon.SinonSandbox;
21
22
  FS: sinonType.SinonSandbox;
23
+ ORGS: sinonType.SinonSandbox;
22
24
  }
23
25
  /**
24
26
  * Different hooks into {@link ConfigFile} used for testing instead of doing file IO.
@@ -83,11 +85,16 @@ export interface TestContext {
83
85
  */
84
86
  configStubs: {
85
87
  [configName: string]: Optional<ConfigStub>;
86
- GlobalInfo?: ConfigStub;
87
- Aliases?: ConfigStub;
88
- SfProjectJson?: ConfigStub;
88
+ AliasesConfig?: ConfigStub;
89
+ AuthInfoConfig?: ConfigStub;
89
90
  SfdxConfig?: ConfigStub;
91
+ SfProjectJson?: ConfigStub;
92
+ TokensConfig?: ConfigStub;
90
93
  };
94
+ /**
95
+ * An record of stubs created during instantaion.
96
+ */
97
+ stubs?: Record<string, sinonType.SinonStub>;
91
98
  /**
92
99
  * A function used when resolving the local path. Calls localPathResolverSync by default.
93
100
  *
@@ -150,7 +157,11 @@ export interface TestContext {
150
157
  */
151
158
  setConfigStubContents(name: string, value: ConfigContents): void;
152
159
  inProject(inProject: boolean): void;
160
+ stubAuths(...orgs: MockTestOrgData[]): Promise<void>;
161
+ stubSandboxes(...orgs: MockTestSandboxData[]): Promise<void>;
162
+ stubAliases(aliases: Record<string, string>, group?: AliasGroup): void;
153
163
  }
164
+ export declare const uniqid: () => string;
154
165
  /**
155
166
  * Instantiate a @salesforce/core test context. This is automatically created by `const $$ = testSetup()`
156
167
  * but is useful if you don't want to have a global stub of @salesforce/core and you want to isolate it to
@@ -197,7 +208,7 @@ export declare const instantiateContext: (sinon?: any) => TestContext;
197
208
  * ```
198
209
  * @param testContext
199
210
  */
200
- export declare const stubContext: (testContext: TestContext) => void;
211
+ export declare const stubContext: (testContext: TestContext) => Record<string, sinonType.SinonStub>;
201
212
  /**
202
213
  * Restore a @salesforce/core test context. This is automatically stubbed in the global beforeEach created by
203
214
  * `const $$ = testSetup()` but is useful if you don't want to have a global stub of @salesforce/core and you
@@ -402,5 +413,18 @@ export declare class MockTestOrgData {
402
413
  makeDevHub(): void;
403
414
  createUser(user: string): MockTestOrgData;
404
415
  getMockUserInfo(): JsonMap;
405
- getConfig(): Promise<SfOrg>;
416
+ getConfig(): Promise<AuthFields>;
417
+ }
418
+ export declare class MockTestSandboxData {
419
+ id: string;
420
+ sandboxOrgId: string;
421
+ prodOrgUsername: string;
422
+ sandboxName?: string;
423
+ username?: string;
424
+ constructor(id?: string, options?: Partial<{
425
+ prodOrgUsername: string;
426
+ name: string;
427
+ username: string;
428
+ }>);
429
+ getConfig(): Promise<SandboxFields>;
406
430
  }
package/lib/testSetup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MockTestOrgData = exports.StreamingMockCometClient = exports.StreamingMockCometSubscription = exports.StreamingMockSubscriptionCall = exports.shouldThrow = exports.unexpectedResult = exports.testSetup = exports.restoreContext = exports.stubContext = exports.instantiateContext = void 0;
3
+ exports.MockTestSandboxData = exports.MockTestOrgData = exports.StreamingMockCometClient = exports.StreamingMockCometSubscription = exports.StreamingMockSubscriptionCall = exports.shouldThrow = exports.unexpectedResult = exports.testSetup = exports.restoreContext = exports.stubContext = exports.instantiateContext = exports.uniqid = void 0;
4
4
  /*
5
5
  * Copyright (c) 2020, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -24,22 +24,25 @@ const messages_1 = require("./messages");
24
24
  const sfError_1 = require("./sfError");
25
25
  const sfProject_1 = require("./sfProject");
26
26
  const streamingClient_1 = require("./status/streamingClient");
27
- const globalInfo_1 = require("./globalInfo");
27
+ const stateAggregator_1 = require("./stateAggregator");
28
+ const sandboxAccessor_1 = require("./stateAggregator/accessors/sandboxAccessor");
29
+ const aliasesConfig_1 = require("./config/aliasesConfig");
28
30
  const global_1 = require("./global");
29
31
  const uniqid = () => {
30
32
  return (0, crypto_1.randomBytes)(16).toString('hex');
31
33
  };
34
+ exports.uniqid = uniqid;
32
35
  function getTestLocalPath(uid) {
33
36
  return (0, path_1.join)((0, os_1.tmpdir)(), uid, 'sfdx_core', 'local');
34
37
  }
35
38
  function getTestGlobalPath(uid) {
36
39
  return (0, path_1.join)((0, os_1.tmpdir)(), uid, 'sfdx_core', 'global');
37
40
  }
38
- function retrieveRootPathSync(isGlobal, uid = uniqid()) {
41
+ function retrieveRootPathSync(isGlobal, uid = (0, exports.uniqid)()) {
39
42
  return isGlobal ? getTestGlobalPath(uid) : getTestLocalPath(uid);
40
43
  }
41
44
  // eslint-disable-next-line @typescript-eslint/require-await
42
- async function retrieveRootPath(isGlobal, uid = uniqid()) {
45
+ async function retrieveRootPath(isGlobal, uid = (0, exports.uniqid)()) {
43
46
  return retrieveRootPathSync(isGlobal, uid);
44
47
  }
45
48
  function defaultFakeConnectionRequest() {
@@ -90,12 +93,13 @@ const instantiateContext = (sinon) => {
90
93
  CRYPTO: sinon.createSandbox(),
91
94
  CONNECTION: sinon.createSandbox(),
92
95
  FS: sinon.createSandbox(),
96
+ ORGS: sinon.createSandbox(),
93
97
  },
94
98
  TEST_LOGGER: new logger_1.Logger({
95
99
  name: 'SFDX_Core_Test_Logger',
96
100
  }).useMemoryLogging(),
97
- id: uniqid(),
98
- uniqid,
101
+ id: (0, exports.uniqid)(),
102
+ uniqid: exports.uniqid,
99
103
  configStubs: {},
100
104
  // eslint-disable-next-line @typescript-eslint/require-await
101
105
  localPathRetriever: async (uid) => getTestLocalPath(uid),
@@ -134,6 +138,34 @@ const instantiateContext = (sinon) => {
134
138
  testContext.SANDBOXES.PROJECT.stub(sfProject_1.SfProject, 'resolveProjectPathSync').throws(new sfError_1.SfError('', 'InvalidProjectWorkspaceError'));
135
139
  }
136
140
  },
141
+ async stubAuths(...orgs) {
142
+ const entries = (await Promise.all(orgs.map(async (org) => [org.username, await org.getConfig()])));
143
+ const orgMap = new Map(entries);
144
+ (0, ts_sinon_1.stubMethod)(testContext.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'getAllFiles').returns([...orgMap.keys()].map((o) => `${o}.json`));
145
+ (0, ts_sinon_1.stubMethod)(testContext.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'hasFile').callsFake((username) => {
146
+ return orgMap.has(username);
147
+ });
148
+ const retrieveContents = async function () {
149
+ var _a;
150
+ const username = (0, path_1.basename)(this.path.replace('.json', ''));
151
+ return Promise.resolve((_a = orgMap.get(username)) !== null && _a !== void 0 ? _a : {});
152
+ };
153
+ this.configStubs.AuthInfoConfig = { retrieveContents };
154
+ },
155
+ async stubSandboxes(...sandboxes) {
156
+ const entries = (await Promise.all(sandboxes.map(async (sanbox) => [sanbox.username, await sanbox.getConfig()])));
157
+ const sandboxMap = new Map(entries);
158
+ (0, ts_sinon_1.stubMethod)(testContext.SANDBOX, sandboxAccessor_1.SandboxAccessor.prototype, 'getAllFiles').returns([...sandboxMap.keys()].map((o) => `${o}.sandbox.json`));
159
+ const retrieveContents = async function () {
160
+ var _a;
161
+ const username = (0, path_1.basename)(this.path.replace('.sandbox.json', ''));
162
+ return Promise.resolve((_a = sandboxMap.get(username)) !== null && _a !== void 0 ? _a : {});
163
+ };
164
+ this.configStubs.SandboxOrgConfig = { retrieveContents };
165
+ },
166
+ stubAliases(aliases, group = aliasesConfig_1.AliasGroup.ORGS) {
167
+ this.configStubs.AliasesConfig = { contents: { [group]: aliases } };
168
+ },
137
169
  };
138
170
  return testContext;
139
171
  };
@@ -166,6 +198,7 @@ const stubContext = (testContext) => {
166
198
  // Turn off the interoperability feature so that we don't have to mock
167
199
  // the old .sfdx config files
168
200
  global_1.Global.SFDX_INTEROPERABILITY = false;
201
+ const stubs = {};
169
202
  // Most core files create a child logger so stub this to return our test logger.
170
203
  (0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'child').returns(Promise.resolve(testContext.TEST_LOGGER));
171
204
  (0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'childFromRoot').returns(testContext.TEST_LOGGER);
@@ -230,8 +263,8 @@ const stubContext = (testContext) => {
230
263
  writeSync.call(this);
231
264
  }
232
265
  };
233
- (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'writeSync').callsFake(writeSync);
234
- (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'write').callsFake(write);
266
+ stubs.configWriteSync = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'writeSync').callsFake(writeSync);
267
+ stubs.configWrite = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'write').callsFake(write);
235
268
  (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CRYPTO, crypto_2.Crypto.prototype, 'getKeyChain').callsFake(() => Promise.resolve({
236
269
  setPassword: () => Promise.resolve(),
237
270
  getPassword: (data, cb) => cb(undefined, '12345678901234567890123456789012'),
@@ -243,8 +276,23 @@ const stubContext = (testContext) => {
243
276
  }
244
277
  return testContext.fakeConnectionRequest.call(this, request, options);
245
278
  });
279
+ stubs.configExists = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.ORGS, stateAggregator_1.OrgAccessor.prototype, 'exists').callsFake(async function (username) {
280
+ // @ts-expect-error because private member
281
+ if ([...this.contents.keys()].includes(username))
282
+ return Promise.resolve(true);
283
+ else
284
+ return Promise.resolve(false);
285
+ });
286
+ stubs.configRemove = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.ORGS, stateAggregator_1.OrgAccessor.prototype, 'remove').callsFake(async function (username) {
287
+ // @ts-expect-error because private member
288
+ if ([...this.contents.keys()].includes(username))
289
+ return Promise.resolve(true);
290
+ else
291
+ return Promise.resolve(false);
292
+ });
246
293
  // Always start with the default and tests beforeEach or it methods can override it.
247
294
  testContext.fakeConnectionRequest = defaultFakeConnectionRequest;
295
+ return stubs;
248
296
  };
249
297
  exports.stubContext = stubContext;
250
298
  /**
@@ -271,7 +319,9 @@ const restoreContext = (testContext) => {
271
319
  Object.values(testContext.SANDBOXES).forEach((theSandbox) => theSandbox.restore());
272
320
  testContext.configStubs = {};
273
321
  // Give each test run a clean GlobalInstance
274
- globalInfo_1.GlobalInfo.clearInstance();
322
+ stateAggregator_1.GlobalInfo.clearInstance();
323
+ // Give each test run a clean StateAggregator
324
+ stateAggregator_1.StateAggregator.clearInstance();
275
325
  };
276
326
  exports.restoreContext = restoreContext;
277
327
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -281,7 +331,7 @@ const _testSetup = (sinon) => {
281
331
  // Allow each test to have their own config aggregator
282
332
  // @ts-ignore clear for testing.
283
333
  delete configAggregator_1.ConfigAggregator.instance;
284
- (0, exports.stubContext)(testContext);
334
+ testContext.stubs = (0, exports.stubContext)(testContext);
285
335
  });
286
336
  afterEach(() => {
287
337
  (0, exports.restoreContext)(testContext);
@@ -473,7 +523,7 @@ exports.StreamingMockCometClient = StreamingMockCometClient;
473
523
  * Mock class for OrgData.
474
524
  */
475
525
  class MockTestOrgData {
476
- constructor(id = uniqid(), options) {
526
+ constructor(id = (0, exports.uniqid)(), options) {
477
527
  this.testId = id;
478
528
  this.userId = `user_id_${this.testId}`;
479
529
  this.orgId = `${this.testId}`;
@@ -552,4 +602,22 @@ class MockTestOrgData {
552
602
  }
553
603
  }
554
604
  exports.MockTestOrgData = MockTestOrgData;
605
+ class MockTestSandboxData {
606
+ constructor(id = (0, exports.uniqid)(), options) {
607
+ this.id = id;
608
+ this.sandboxOrgId = id;
609
+ this.prodOrgUsername = (options === null || options === void 0 ? void 0 : options.prodOrgUsername) || `admin_${id}@gb.org`;
610
+ this.sandboxName = (options === null || options === void 0 ? void 0 : options.name) || `sandbox_${id}`;
611
+ this.username = (options === null || options === void 0 ? void 0 : options.username) || `${this.prodOrgUsername}.sandbox`;
612
+ }
613
+ async getConfig() {
614
+ return {
615
+ sandboxOrgId: this.sandboxOrgId,
616
+ prodOrgUsername: this.prodOrgUsername,
617
+ sandboxName: this.sandboxName,
618
+ sandboxUsername: this.username,
619
+ };
620
+ }
621
+ }
622
+ exports.MockTestSandboxData = MockTestSandboxData;
555
623
  //# sourceMappingURL=testSetup.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.19.2",
3
+ "version": "3.19.5",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -1,13 +0,0 @@
1
- import { Optional } from '@salesforce/ts-types';
2
- import { GlobalInfo } from '../globalInfoConfig';
3
- import { SfOrgs, SfOrg } from '../types';
4
- export declare class OrgAccessor {
5
- private globalInfo;
6
- constructor(globalInfo: GlobalInfo);
7
- getAll(decrypt?: boolean): SfOrgs;
8
- get(username: string, decrypt?: boolean): Optional<SfOrg>;
9
- has(username: string): boolean;
10
- set(username: string, org: SfOrg): void;
11
- update(username: string, org: Partial<SfOrg>): void;
12
- unset(username: string): void;
13
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2021, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.OrgAccessor = void 0;
10
- const types_1 = require("../types");
11
- class OrgAccessor {
12
- constructor(globalInfo) {
13
- this.globalInfo = globalInfo;
14
- }
15
- getAll(decrypt = false) {
16
- return this.globalInfo.get(types_1.SfInfoKeys.ORGS, decrypt);
17
- }
18
- get(username, decrypt = false) {
19
- const auth = this.globalInfo.get(`${types_1.SfInfoKeys.ORGS}["${username}"]`, decrypt);
20
- // For legacy, some things wants the username in the returned auth info.
21
- if (auth && !auth.username)
22
- auth.username = username;
23
- return auth;
24
- }
25
- has(username) {
26
- return !!this.getAll()[username];
27
- }
28
- set(username, org) {
29
- // For legacy, and to keep things standard, some things wants the username in auth info.
30
- if (!org.username)
31
- org.username = username;
32
- this.globalInfo.set(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
33
- }
34
- update(username, org) {
35
- // For legacy, and to keep things standard, some things wants the username in auth info.
36
- if (!org.username)
37
- org.username = username;
38
- this.globalInfo.update(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
39
- }
40
- unset(username) {
41
- delete this.globalInfo.get(types_1.SfInfoKeys.ORGS)[username];
42
- }
43
- }
44
- exports.OrgAccessor = OrgAccessor;
45
- //# sourceMappingURL=orgAccessor.js.map
@@ -1,13 +0,0 @@
1
- import { Optional } from '@salesforce/ts-types';
2
- import { GlobalInfo } from '../globalInfoConfig';
3
- import { SfTokens, SfToken, Timestamp } from '../types';
4
- export declare class TokenAccessor {
5
- private globalInfo;
6
- constructor(globalInfo: GlobalInfo);
7
- getAll(decrypt?: boolean): SfTokens;
8
- get(name: string, decrypt?: boolean): Optional<SfToken & Timestamp>;
9
- has(name: string): boolean;
10
- set(name: string, token: SfToken): void;
11
- update(name: string, token: Partial<SfToken>): void;
12
- unset(name: string): void;
13
- }
@@ -1,6 +0,0 @@
1
- export * from './globalInfoConfig';
2
- export * from './sfdxDataHandler';
3
- export * from './types';
4
- export { OrgAccessor } from './accessors/orgAccessor';
5
- export { AliasAccessor } from './accessors/aliasAccessor';
6
- export { TokenAccessor } from './accessors/tokenAccessor';