@salesforce/core 4.0.0 → 4.1.0

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 (151) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +93 -44
  3. package/lib/config/authInfoConfig.d.ts +19 -0
  4. package/lib/config/authInfoConfig.js +35 -0
  5. package/lib/config/config.d.ts +87 -22
  6. package/lib/config/config.js +117 -65
  7. package/lib/config/configAggregator.d.ts +41 -35
  8. package/lib/config/configAggregator.js +102 -73
  9. package/lib/config/configFile.d.ts +2 -2
  10. package/lib/config/configFile.js +38 -29
  11. package/lib/config/configStore.d.ts +9 -9
  12. package/lib/config/configStore.js +17 -15
  13. package/lib/config/envVars.d.ts +15 -9
  14. package/lib/config/envVars.js +71 -47
  15. package/lib/config/orgUsersConfig.js +2 -0
  16. package/lib/config/sandboxOrgConfig.js +2 -0
  17. package/lib/config/sandboxProcessCache.d.ts +16 -0
  18. package/lib/config/sandboxProcessCache.js +38 -0
  19. package/lib/config/tokensConfig.d.ts +10 -0
  20. package/lib/config/tokensConfig.js +29 -0
  21. package/lib/config/ttlConfig.d.ts +34 -0
  22. package/lib/config/ttlConfig.js +50 -0
  23. package/lib/crypto/crypto.js +15 -22
  24. package/lib/crypto/keyChain.js +2 -3
  25. package/lib/crypto/keyChainImpl.d.ts +5 -3
  26. package/lib/crypto/keyChainImpl.js +58 -61
  27. package/lib/crypto/secureBuffer.d.ts +1 -1
  28. package/lib/deviceOauthService.d.ts +3 -3
  29. package/lib/deviceOauthService.js +27 -25
  30. package/lib/exported.d.ts +15 -12
  31. package/lib/exported.js +28 -16
  32. package/lib/global.d.ts +11 -3
  33. package/lib/global.js +39 -12
  34. package/lib/lifecycleEvents.d.ts +1 -1
  35. package/lib/lifecycleEvents.js +3 -0
  36. package/lib/logger.d.ts +19 -9
  37. package/lib/logger.js +112 -86
  38. package/lib/messages.d.ts +53 -36
  39. package/lib/messages.js +81 -91
  40. package/lib/org/authInfo.d.ts +56 -20
  41. package/lib/org/authInfo.js +232 -131
  42. package/lib/org/authRemover.d.ts +8 -7
  43. package/lib/org/authRemover.js +32 -28
  44. package/lib/org/connection.d.ts +13 -37
  45. package/lib/org/connection.js +78 -124
  46. package/lib/org/index.js +5 -1
  47. package/lib/org/org.d.ts +151 -48
  48. package/lib/org/org.js +468 -225
  49. package/lib/org/orgConfigProperties.d.ts +64 -3
  50. package/lib/org/orgConfigProperties.js +96 -4
  51. package/lib/org/permissionSetAssignment.js +4 -13
  52. package/lib/org/scratchOrgCache.d.ts +20 -0
  53. package/lib/org/scratchOrgCache.js +33 -0
  54. package/lib/org/scratchOrgCreate.d.ts +28 -17
  55. package/lib/org/scratchOrgCreate.js +125 -53
  56. package/lib/org/scratchOrgErrorCodes.d.ts +9 -3
  57. package/lib/org/scratchOrgErrorCodes.js +34 -17
  58. package/lib/org/scratchOrgFeatureDeprecation.js +1 -6
  59. package/lib/org/scratchOrgInfoApi.d.ts +21 -47
  60. package/lib/org/scratchOrgInfoApi.js +129 -63
  61. package/lib/org/scratchOrgInfoGenerator.d.ts +6 -5
  62. package/lib/org/scratchOrgInfoGenerator.js +76 -62
  63. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
  64. package/lib/org/scratchOrgLifecycleEvents.js +41 -0
  65. package/lib/org/scratchOrgSettingsGenerator.d.ts +44 -21
  66. package/lib/org/scratchOrgSettingsGenerator.js +165 -98
  67. package/lib/org/scratchOrgTypes.d.ts +43 -0
  68. package/lib/org/scratchOrgTypes.js +9 -0
  69. package/lib/org/user.d.ts +1 -1
  70. package/lib/org/user.js +25 -34
  71. package/lib/schema/printer.d.ts +6 -0
  72. package/lib/schema/printer.js +34 -31
  73. package/lib/schema/validator.d.ts +12 -10
  74. package/lib/schema/validator.js +56 -76
  75. package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -20
  76. package/lib/{sfdxError.js → sfError.js} +40 -30
  77. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
  78. package/lib/sfProject.js +651 -0
  79. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +129 -0
  80. package/lib/stateAggregator/accessors/aliasAccessor.js +263 -0
  81. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
  82. package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
  83. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
  84. package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
  85. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
  86. package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
  87. package/lib/stateAggregator/index.d.ts +4 -0
  88. package/lib/stateAggregator/index.js +27 -0
  89. package/lib/stateAggregator/stateAggregator.d.ts +25 -0
  90. package/lib/stateAggregator/stateAggregator.js +46 -0
  91. package/lib/status/myDomainResolver.d.ts +1 -1
  92. package/lib/status/myDomainResolver.js +4 -4
  93. package/lib/status/pollingClient.js +4 -4
  94. package/lib/status/streamingClient.d.ts +2 -2
  95. package/lib/status/streamingClient.js +58 -63
  96. package/lib/status/types.d.ts +2 -2
  97. package/lib/testSetup.d.ts +204 -75
  98. package/lib/testSetup.js +468 -164
  99. package/lib/util/cache.d.ts +2 -2
  100. package/lib/util/cache.js +6 -6
  101. package/lib/util/checkLightningDomain.js +3 -4
  102. package/lib/util/directoryWriter.d.ts +12 -0
  103. package/lib/util/directoryWriter.js +54 -0
  104. package/lib/util/getJwtAudienceUrl.js +1 -1
  105. package/lib/util/internal.d.ts +28 -2
  106. package/lib/util/internal.js +65 -8
  107. package/lib/util/jsonXmlTools.js +2 -4
  108. package/lib/util/mapKeys.d.ts +9 -9
  109. package/lib/util/mapKeys.js +13 -9
  110. package/lib/util/sfdc.d.ts +51 -51
  111. package/lib/util/sfdc.js +74 -79
  112. package/lib/util/sfdcUrl.d.ts +5 -19
  113. package/lib/util/sfdcUrl.js +40 -49
  114. package/lib/util/structuredWriter.d.ts +9 -0
  115. package/lib/util/structuredWriter.js +3 -0
  116. package/lib/util/zipWriter.d.ts +8 -6
  117. package/lib/util/zipWriter.js +13 -13
  118. package/lib/webOAuthServer.d.ts +20 -6
  119. package/lib/webOAuthServer.js +102 -56
  120. package/messageTransformer/messageTransformer.ts +93 -0
  121. package/messages/auth.md +9 -1
  122. package/messages/config.md +42 -6
  123. package/messages/connection.md +8 -0
  124. package/messages/core.md +10 -0
  125. package/messages/envVars.md +37 -3
  126. package/messages/org.md +21 -1
  127. package/messages/scratchOrgCreate.md +2 -6
  128. package/messages/scratchOrgErrorCodes.md +17 -1
  129. package/messages/scratchOrgInfoApi.md +9 -0
  130. package/messages/scratchOrgInfoGenerator.md +9 -1
  131. package/package.json +123 -46
  132. package/CHANGELOG.md +0 -1244
  133. package/lib/config/keychainConfig.d.ts +0 -19
  134. package/lib/config/keychainConfig.js +0 -43
  135. package/lib/globalInfo/accessors/aliasAccessor.d.ts +0 -83
  136. package/lib/globalInfo/accessors/aliasAccessor.js +0 -130
  137. package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
  138. package/lib/globalInfo/accessors/orgAccessor.js +0 -45
  139. package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
  140. package/lib/globalInfo/accessors/tokenAccessor.js +0 -35
  141. package/lib/globalInfo/globalInfoConfig.d.ts +0 -36
  142. package/lib/globalInfo/globalInfoConfig.js +0 -105
  143. package/lib/globalInfo/index.d.ts +0 -6
  144. package/lib/globalInfo/index.js +0 -29
  145. package/lib/globalInfo/sfdxDataHandler.d.ts +0 -43
  146. package/lib/globalInfo/sfdxDataHandler.js +0 -217
  147. package/lib/globalInfo/types.d.ts +0 -39
  148. package/lib/globalInfo/types.js +0 -10
  149. package/lib/sfdxProject.js +0 -557
  150. package/lib/util/fs.d.ts +0 -201
  151. package/lib/util/fs.js +0 -378
@@ -1,11 +1,11 @@
1
1
  export declare class Cache extends Map {
2
2
  #private;
3
3
  private constructor();
4
+ static get hits(): number;
5
+ static get lookups(): number;
4
6
  static instance(): Cache;
5
7
  static set<V>(key: string, value: V): void;
6
8
  static get<V>(key: string): V | undefined;
7
9
  static disable(): void;
8
10
  static enable(): void;
9
- static get hits(): number;
10
- static get lookups(): number;
11
11
  }
package/lib/util/cache.js CHANGED
@@ -28,6 +28,12 @@ class Cache extends Map {
28
28
  __classPrivateFieldSet(this, _Cache_hits, 0, "f");
29
29
  __classPrivateFieldSet(this, _Cache_lookups, 0, "f");
30
30
  }
31
+ static get hits() {
32
+ return __classPrivateFieldGet(Cache.instance(), _Cache_hits, "f");
33
+ }
34
+ static get lookups() {
35
+ return __classPrivateFieldGet(Cache.instance(), _Cache_lookups, "f");
36
+ }
31
37
  static instance() {
32
38
  if (!__classPrivateFieldGet(Cache, _a, "f", _Cache_instance)) {
33
39
  __classPrivateFieldSet(Cache, _a, true, "f", _Cache_enabled);
@@ -55,12 +61,6 @@ class Cache extends Map {
55
61
  static enable() {
56
62
  __classPrivateFieldSet(Cache, _a, true, "f", _Cache_enabled);
57
63
  }
58
- static get hits() {
59
- return __classPrivateFieldGet(Cache.instance(), _Cache_hits, "f");
60
- }
61
- static get lookups() {
62
- return __classPrivateFieldGet(Cache.instance(), _Cache_lookups, "f");
63
- }
64
64
  }
65
65
  exports.Cache = Cache;
66
66
  _a = Cache, _Cache_hits = new WeakMap(), _Cache_lookups = new WeakMap();
@@ -11,11 +11,10 @@ const kit_1 = require("@salesforce/kit");
11
11
  const myDomainResolver_1 = require("../status/myDomainResolver");
12
12
  const sfdc_1 = require("./sfdc");
13
13
  async function checkLightningDomain(url) {
14
- var _a, _b;
15
- const domain = `https://${(_a = /https?:\/\/([^.]*)/.exec(url)) === null || _a === void 0 ? void 0 : _a.slice(1, 2).pop()}.lightning.force.com`;
16
- const quantity = (_b = new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240)) !== null && _b !== void 0 ? _b : 0;
14
+ const domain = `https://${/https?:\/\/([^.]*)/.exec(url)?.slice(1, 2).pop()}.lightning.force.com`;
15
+ const quantity = new kit_1.Env().getNumber('SFDX_DOMAIN_RETRY', 240) ?? 0;
17
16
  const timeout = new kit_1.Duration(quantity, kit_1.Duration.Unit.SECONDS);
18
- if (sfdc_1.sfdc.isInternalUrl(url) || timeout.seconds === 0) {
17
+ if ((0, sfdc_1.isInternalUrl)(url) || timeout.seconds === 0) {
19
18
  return true;
20
19
  }
21
20
  const resolver = await myDomainResolver_1.MyDomainResolver.create({
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Readable } from 'stream';
4
+ import { StructuredWriter } from './structuredWriter';
5
+ export declare class DirectoryWriter implements StructuredWriter {
6
+ private readonly rootDestination?;
7
+ constructor(rootDestination?: string | undefined);
8
+ get buffer(): Buffer;
9
+ addToStore(contents: string | Readable | Buffer, targetPath: string): Promise<void>;
10
+ finalize(): Promise<void>;
11
+ getDestinationPath(): string | undefined;
12
+ }
@@ -0,0 +1,54 @@
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.DirectoryWriter = void 0;
10
+ const stream_1 = require("stream");
11
+ const fs = require("fs");
12
+ const os = require("os");
13
+ const path = require("path");
14
+ const util_1 = require("util");
15
+ const pipeline = (0, util_1.promisify)(stream_1.pipeline);
16
+ class DirectoryWriter {
17
+ constructor(rootDestination) {
18
+ this.rootDestination = rootDestination;
19
+ if (!this.rootDestination) {
20
+ this.rootDestination = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
21
+ }
22
+ else {
23
+ fs.mkdirSync(this.rootDestination, { recursive: true });
24
+ }
25
+ }
26
+ // eslint-disable-next-line class-methods-use-this
27
+ get buffer() {
28
+ throw new Error('Not implemented');
29
+ }
30
+ async addToStore(contents, targetPath) {
31
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
32
+ const destPath = path.join(this.rootDestination, targetPath);
33
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
34
+ if (contents instanceof stream_1.Readable) {
35
+ const writeStream = fs.createWriteStream(destPath);
36
+ await pipeline(contents, writeStream);
37
+ }
38
+ else if (typeof contents === 'string') {
39
+ fs.writeFileSync(destPath, contents);
40
+ }
41
+ else if (contents instanceof Buffer) {
42
+ fs.writeFileSync(destPath, contents);
43
+ }
44
+ }
45
+ // eslint-disable-next-line class-methods-use-this
46
+ finalize() {
47
+ return Promise.resolve(undefined);
48
+ }
49
+ getDestinationPath() {
50
+ return this.rootDestination;
51
+ }
52
+ }
53
+ exports.DirectoryWriter = DirectoryWriter;
54
+ //# sourceMappingURL=directoryWriter.js.map
@@ -11,7 +11,7 @@ const sfdcUrl_1 = require("./sfdcUrl");
11
11
  async function getJwtAudienceUrl(options) {
12
12
  if (options.loginUrl) {
13
13
  const url = new sfdcUrl_1.SfdcUrl(options.loginUrl);
14
- return await url.getJwtAudienceUrl(options.createdOrgInstance);
14
+ return url.getJwtAudienceUrl(options.createdOrgInstance);
15
15
  }
16
16
  return sfdcUrl_1.SfdcUrl.PRODUCTION;
17
17
  }
@@ -1,3 +1,4 @@
1
+ import { Optional } from '@salesforce/ts-types';
1
2
  /**
2
3
  * The name of the project config file.
3
4
  *
@@ -11,7 +12,7 @@ export declare const SFDX_PROJECT_JSON = "sfdx-project.json";
11
12
  *
12
13
  * **See** {@link traverseForFile}
13
14
  *
14
- * **Throws** *{@link SfdxError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
15
+ * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
15
16
  *
16
17
  * @param dir The directory path to start traversing from.
17
18
  * @ignore
@@ -24,9 +25,34 @@ export declare function resolveProjectPath(dir?: string): Promise<string>;
24
25
  *
25
26
  * **See** {@link traverseForFile}
26
27
  *
27
- * **Throws** *{@link SfdxError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
28
+ * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
28
29
  *
29
30
  * @param dir The directory path to start traversing from.
30
31
  * @ignore
31
32
  */
32
33
  export declare function resolveProjectPathSync(dir?: string): string;
34
+ /**
35
+ * These methods were moved from the deprecated 'fs' module in v2 and are only used in sfdx-core above
36
+ *
37
+ * They were migrated into the 'traverse' constant in order to stub them in unit tests
38
+ */
39
+ export declare const traverse: {
40
+ /**
41
+ * Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a
42
+ * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
43
+ * not found.
44
+ *
45
+ * @param dir The directory path in which to start the upward search.
46
+ * @param file The file name to look for.
47
+ */
48
+ forFile: (dir: string, file: string) => Promise<Optional<string>>;
49
+ /**
50
+ * Searches a file path synchronously in an ascending manner (until reaching the filesystem root) for the first occurrence a
51
+ * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
52
+ * not found.
53
+ *
54
+ * @param dir The directory path in which to start the upward search.
55
+ * @param file The file name to look for.
56
+ */
57
+ forFileSync: (dir: string, file: string) => Optional<string>;
58
+ };
@@ -6,11 +6,11 @@
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.resolveProjectPathSync = exports.resolveProjectPath = exports.SFDX_PROJECT_JSON = void 0;
9
+ exports.traverse = exports.resolveProjectPathSync = exports.resolveProjectPath = exports.SFDX_PROJECT_JSON = void 0;
10
+ const fs = require("fs");
11
+ const path_1 = require("path");
10
12
  const messages_1 = require("../messages");
11
- const fs_1 = require("./fs");
12
- messages_1.Messages.importMessagesDirectory(__dirname);
13
- const messages = messages_1.Messages.load('@salesforce/core', 'config', ['invalidProjectWorkspace']);
13
+ const messages = new messages_1.Messages('@salesforce/core', 'config', new Map([["unknownConfigKey", "Unknown config name: %s."], ["deprecatedConfigKey", "Deprecated config name: %s. Please use %s instead."], ["invalidWrite", "The writeSync method is not allowed on SfdxConfig. Use the async write method instead."], ["invalidConfigValue", "Invalid config value: %s."], ["invalidInstanceUrl", "Specify a valid Salesforce instance URL."], ["invalidApiVersion", "Specify a valid Salesforce API version, for example, 42.0."], ["invalidCustomOrgMetadataTemplates", "Specify a valid repository URL or directory for the custom org metadata templates."], ["invalidIsvDebuggerSid", "Specify a valid Debugger SID."], ["invalidIsvDebuggerUrl", "Specify a valid Debugger URL."], ["invalidNumberConfigValue", "Specify a valid positive integer, for example, 150000."], ["invalidBooleanConfigValue", "The config value can only be set to true or false."], ["invalidProjectWorkspace", "This directory does not contain a valid Salesforce DX project."], ["schemaValidationError", "The config file \"%s\" is not schema valid.\nDue to: %s"], ["schemaValidationError.actions", ["Fix the invalid entries at %s."]], ["missingDefaultPath", "In sfdx-project.json, be sure to specify which package directory (path) is the default. Example: `[{ \"path\": \"packageDirectory1\", \"default\": true }, { \"path\": \"packageDirectory2\" }]`"], ["missingPackageDirectory", "The path \"%s\", specified in sfdx-project.json, does not exist. Be sure this directory is included in your project root."], ["invalidPackageDirectory", "The path \"%s\", specified in sfdx-project.json, must be indicated as a relative path to the project root."], ["multipleDefaultPaths", "In sfdx-project.json, indicate only one package directory (path) as the default."], ["singleNonDefaultPackage", "The sfdx-project.json file must include one, and only one, default package directory (path). Because your sfdx-project.json file contains only one package directory, it must be the default. Remove the `\"default\": false` key and try again."], ["target-org", "Username or alias of the org that all commands run against by default. (sf only)"], ["target-dev-hub", "Username or alias of your default Dev Hub org. (sf only)"], ["defaultUsername", "Username or alias of the org that all commands run against by default. (sfdx only)"], ["defaultDevHubUsername", "Username or alias of your default Dev Hub org. (sfdx only)"], ["isvDebuggerSid", "ISV debugger SID (sfdx only)"], ["isvDebuggerUrl", "ISV debugger URL (sfdx only)"], ["org-isv-debugger-sid", "ISV debugger SID."], ["org-isv-debugger-url", "ISV debugger URL."], ["apiVersion", "API version of your project. Default: API version of your Dev Hub org. (sfdx only)"], ["org-api-version", "API version of your project. Default: API version of your Dev Hub org."], ["disableTelemetry", "Disables the collection of usage and user environment information, etc. Default: false. (sfdx only)"], ["disable-telemetry", "Disables the collection of usage and user environment information, etc. Default: false."], ["maxQueryLimit", "Maximum number of Salesforce records returned by a CLI command. Default: 10,000. (sfdx only)"], ["org-max-query-limit", "Maximum number of Salesforce records returned by a CLI command. Default: 10,000."], ["restDeploy", "Whether deployments use the Metadata REST API (true) or SOAP API (false, default value). (sfdx only)"], ["instanceUrl", "URL of the Salesforce instance hosting your org. Default: https://login.salesforce.com. (sfdx only)"], ["org-instance-url", "URL of the Salesforce instance hosting your org. Default: https://login.salesforce.com."], ["customOrgMetadataTemplates", "A valid repository URL or directory for the custom org metadata templates."], ["org-custom-metadata-templates", "A valid repository URL or directory for the custom org metadata templates."], ["invalidId", "The given id %s is not a valid 15 or 18 character Salesforce ID."]]));
14
14
  /**
15
15
  * The name of the project config file.
16
16
  *
@@ -25,13 +25,13 @@ exports.SFDX_PROJECT_JSON = 'sfdx-project.json';
25
25
  *
26
26
  * **See** {@link traverseForFile}
27
27
  *
28
- * **Throws** *{@link SfdxError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
28
+ * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
29
29
  *
30
30
  * @param dir The directory path to start traversing from.
31
31
  * @ignore
32
32
  */
33
33
  async function resolveProjectPath(dir = process.cwd()) {
34
- const projectPath = await fs_1.fs.traverseForFile(dir, exports.SFDX_PROJECT_JSON);
34
+ const projectPath = await exports.traverse.forFile(dir, exports.SFDX_PROJECT_JSON);
35
35
  if (!projectPath) {
36
36
  throw messages.createError('invalidProjectWorkspace');
37
37
  }
@@ -45,17 +45,74 @@ exports.resolveProjectPath = resolveProjectPath;
45
45
  *
46
46
  * **See** {@link traverseForFile}
47
47
  *
48
- * **Throws** *{@link SfdxError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
48
+ * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
49
49
  *
50
50
  * @param dir The directory path to start traversing from.
51
51
  * @ignore
52
52
  */
53
53
  function resolveProjectPathSync(dir = process.cwd()) {
54
- const projectPath = fs_1.fs.traverseForFileSync(dir, exports.SFDX_PROJECT_JSON);
54
+ const projectPath = exports.traverse.forFileSync(dir, exports.SFDX_PROJECT_JSON);
55
55
  if (!projectPath) {
56
56
  throw messages.createError('invalidProjectWorkspace');
57
57
  }
58
58
  return projectPath;
59
59
  }
60
60
  exports.resolveProjectPathSync = resolveProjectPathSync;
61
+ /**
62
+ * These methods were moved from the deprecated 'fs' module in v2 and are only used in sfdx-core above
63
+ *
64
+ * They were migrated into the 'traverse' constant in order to stub them in unit tests
65
+ */
66
+ exports.traverse = {
67
+ /**
68
+ * Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a
69
+ * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
70
+ * not found.
71
+ *
72
+ * @param dir The directory path in which to start the upward search.
73
+ * @param file The file name to look for.
74
+ */
75
+ forFile: async (dir, file) => {
76
+ let foundProjectDir;
77
+ try {
78
+ fs.statSync((0, path_1.join)(dir, file));
79
+ foundProjectDir = dir;
80
+ }
81
+ catch (err) {
82
+ if (err && err.code === 'ENOENT') {
83
+ const nextDir = (0, path_1.resolve)(dir, '..');
84
+ if (nextDir !== dir) {
85
+ // stop at root
86
+ foundProjectDir = await exports.traverse.forFile(nextDir, file);
87
+ }
88
+ }
89
+ }
90
+ return foundProjectDir;
91
+ },
92
+ /**
93
+ * Searches a file path synchronously in an ascending manner (until reaching the filesystem root) for the first occurrence a
94
+ * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
95
+ * not found.
96
+ *
97
+ * @param dir The directory path in which to start the upward search.
98
+ * @param file The file name to look for.
99
+ */
100
+ forFileSync: (dir, file) => {
101
+ let foundProjectDir;
102
+ try {
103
+ fs.statSync((0, path_1.join)(dir, file));
104
+ foundProjectDir = dir;
105
+ }
106
+ catch (err) {
107
+ if (err && err.code === 'ENOENT') {
108
+ const nextDir = (0, path_1.resolve)(dir, '..');
109
+ if (nextDir !== dir) {
110
+ // stop at root
111
+ foundProjectDir = exports.traverse.forFileSync(nextDir, file);
112
+ }
113
+ }
114
+ }
115
+ return foundProjectDir;
116
+ },
117
+ };
61
118
  //# sourceMappingURL=internal.js.map
@@ -21,12 +21,10 @@ exports.standardOptions = {
21
21
  };
22
22
  const writeJSONasXML = async ({ path, json, type, options = exports.standardOptions, }) => {
23
23
  const xml = jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
24
- return await fs_1.promises.writeFile(path, xml);
24
+ return fs_1.promises.writeFile(path, xml);
25
25
  };
26
26
  exports.writeJSONasXML = writeJSONasXML;
27
- const JsonAsXml = ({ json, type, options = exports.standardOptions }) => {
28
- return jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
29
- };
27
+ const JsonAsXml = ({ json, type, options = exports.standardOptions }) => jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
30
28
  exports.JsonAsXml = JsonAsXml;
31
29
  const fixExistingDollarSign = (existing) => {
32
30
  const existingCopy = { ...existing };
@@ -1,14 +1,14 @@
1
1
  /**
2
- * Use mapKeys to convert object keys to another format using the specified conversion function.
2
+ * Use mapKeys to convert object keys to another format using the specified conversion function.
3
3
  *
4
- * E.g., to deep convert all object keys to camelCase: mapKeys(myObj, _.camelCase, true)
5
- * to shallow convert object keys to lower case: mapKeys(myObj, _.toLower)
4
+ * E.g., to deep convert all object keys to camelCase: mapKeys(myObj, _.camelCase, true)
5
+ * to shallow convert object keys to lower case: mapKeys(myObj, _.toLower)
6
6
  *
7
- * NOTE: This mutates the object passed in for conversion.
7
+ * NOTE: This mutates the object passed in for conversion.
8
8
  *
9
- * @param target - {Object} The object to convert the keys
10
- * @param converter - {Function} The function that converts the object key
11
- * @param deep - {boolean} Whether to do a deep object key conversion
12
- * @return {Object} - the object with the converted keys
9
+ * @param target - {Object} The object to convert the keys
10
+ * @param converter - {Function} The function that converts the object key
11
+ * @param deep - {boolean} Whether to do a deep object key conversion
12
+ * @return {Object} - the object with the converted keys
13
13
  */
14
- export default function mapKeys(obj: any, converter: (key: string) => string, deep?: boolean): Record<string, unknown>;
14
+ export default function mapKeys<T>(obj: T, converter: (key: string) => string, deep?: boolean): Record<string, unknown>;
@@ -8,23 +8,26 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const ts_types_1 = require("@salesforce/ts-types");
10
10
  /**
11
- * Use mapKeys to convert object keys to another format using the specified conversion function.
11
+ * Use mapKeys to convert object keys to another format using the specified conversion function.
12
12
  *
13
- * E.g., to deep convert all object keys to camelCase: mapKeys(myObj, _.camelCase, true)
14
- * to shallow convert object keys to lower case: mapKeys(myObj, _.toLower)
13
+ * E.g., to deep convert all object keys to camelCase: mapKeys(myObj, _.camelCase, true)
14
+ * to shallow convert object keys to lower case: mapKeys(myObj, _.toLower)
15
15
  *
16
- * NOTE: This mutates the object passed in for conversion.
16
+ * NOTE: This mutates the object passed in for conversion.
17
17
  *
18
- * @param target - {Object} The object to convert the keys
19
- * @param converter - {Function} The function that converts the object key
20
- * @param deep - {boolean} Whether to do a deep object key conversion
21
- * @return {Object} - the object with the converted keys
18
+ * @param target - {Object} The object to convert the keys
19
+ * @param converter - {Function} The function that converts the object key
20
+ * @param deep - {boolean} Whether to do a deep object key conversion
21
+ * @return {Object} - the object with the converted keys
22
22
  */
23
23
  function mapKeys(
24
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
25
25
  obj, converter, deep) {
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
26
27
  const target = Object.assign({}, obj);
27
- return Object.fromEntries(Object.entries(target).map(([key, value]) => {
28
+ return Object.fromEntries(
29
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
30
+ Object.entries(target).map(([key, value]) => {
28
31
  const k = converter.call(null, key);
29
32
  if (deep) {
30
33
  let v = value;
@@ -33,6 +36,7 @@ obj, converter, deep) {
33
36
  if ((0, ts_types_1.isPlainObject)(v1)) {
34
37
  return mapKeys(v1, converter, deep);
35
38
  }
39
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
36
40
  return v1;
37
41
  });
38
42
  }
@@ -1,52 +1,52 @@
1
1
  import { JsonMap, Optional } from '@salesforce/ts-types';
2
- export declare const sfdc: {
3
- /**
4
- * Converts an 18 character Salesforce ID to 15 characters.
5
- *
6
- * @param id The id to convert.
7
- */
8
- trimTo15: (id?: string | undefined) => Optional<string>;
9
- /**
10
- * Tests whether an API version matches the format `i.0`.
11
- *
12
- * @param value The API version as a string.
13
- */
14
- validateApiVersion: (value: string) => boolean;
15
- /**
16
- * Tests whether an email matches the format `me@my.org`
17
- *
18
- * @param value The email as a string.
19
- */
20
- validateEmail: (value: string) => boolean;
21
- /**
22
- * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
23
- *
24
- * @param value The ID as a string.
25
- */
26
- validateSalesforceId: (value: string) => boolean;
27
- /**
28
- * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
29
- *
30
- * @param value The path as a string.
31
- */
32
- validatePathDoesNotContainInvalidChars: (value: string) => boolean;
33
- /**
34
- * Returns the first key within the object that has an upper case first letter.
35
- *
36
- * @param data The object in which to check key casing.
37
- * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`.
38
- */
39
- findUpperCaseKeys: (data?: JsonMap | undefined, sectionBlocklist?: string[]) => Optional<string>;
40
- /**
41
- * Tests whether a given string is an access token
42
- *
43
- * @param value
44
- */
45
- matchesAccessToken: (value: string) => boolean;
46
- /**
47
- * Tests whether a given url is an internal Salesforce domain
48
- *
49
- * @param url
50
- */
51
- isInternalUrl: (url: string) => boolean;
52
- };
2
+ /**
3
+ * Converts an 18 character Salesforce ID to 15 characters.
4
+ *
5
+ * @param id The id to convert.
6
+ */
7
+ export declare function trimTo15(id: string): string;
8
+ export declare function trimTo15(id?: undefined): undefined;
9
+ export declare function trimTo15(id: string | undefined): string | undefined;
10
+ /**
11
+ * Tests whether an API version matches the format `i.0`.
12
+ *
13
+ * @param value The API version as a string.
14
+ */
15
+ export declare const validateApiVersion: (value: string) => boolean;
16
+ /**
17
+ * Tests whether an email matches the format `me@my.org`
18
+ *
19
+ * @param value The email as a string.
20
+ */
21
+ export declare const validateEmail: (value: string) => boolean;
22
+ /**
23
+ * Tests whether a given url is an internal Salesforce domain
24
+ *
25
+ * @param url
26
+ */
27
+ export declare const isInternalUrl: (url: string) => boolean;
28
+ /**
29
+ * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
30
+ *
31
+ * @param value The ID as a string.
32
+ */
33
+ export declare const validateSalesforceId: (value: string) => boolean;
34
+ /**
35
+ * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
36
+ *
37
+ * @param value The path as a string.
38
+ */
39
+ export declare const validatePathDoesNotContainInvalidChars: (value: string) => boolean;
40
+ /**
41
+ * Returns the first key within the object that has an upper case first letter.
42
+ *
43
+ * @param data The object in which to check key casing.
44
+ * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`.
45
+ */
46
+ export declare const findUpperCaseKeys: (data?: JsonMap, sectionBlocklist?: string[]) => Optional<string>;
47
+ /**
48
+ * Tests whether a given string is an access token
49
+ *
50
+ * @param value
51
+ */
52
+ export declare const matchesAccessToken: (value: string) => boolean;
package/lib/util/sfdc.js CHANGED
@@ -6,90 +6,85 @@
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.sfdc = void 0;
9
+ exports.matchesAccessToken = exports.findUpperCaseKeys = exports.validatePathDoesNotContainInvalidChars = exports.validateSalesforceId = exports.isInternalUrl = exports.validateEmail = exports.validateApiVersion = exports.trimTo15 = void 0;
10
10
  const kit_1 = require("@salesforce/kit");
11
11
  const ts_types_1 = require("@salesforce/ts-types");
12
12
  const sfdcUrl_1 = require("./sfdcUrl");
13
- exports.sfdc = {
14
- /**
15
- * Converts an 18 character Salesforce ID to 15 characters.
16
- *
17
- * @param id The id to convert.
18
- */
19
- trimTo15: (id) => {
20
- if (id && id.length && id.length > 15) {
21
- id = id.substring(0, 15);
13
+ function trimTo15(id) {
14
+ if (!id) {
15
+ return undefined;
16
+ }
17
+ if (id.length && id.length > 15) {
18
+ id = id.substring(0, 15);
19
+ }
20
+ return id;
21
+ }
22
+ exports.trimTo15 = trimTo15;
23
+ /**
24
+ * Tests whether an API version matches the format `i.0`.
25
+ *
26
+ * @param value The API version as a string.
27
+ */
28
+ const validateApiVersion = (value) => value == null || /^[1-9]\d\.0$/.test(value);
29
+ exports.validateApiVersion = validateApiVersion;
30
+ /**
31
+ * Tests whether an email matches the format `me@my.org`
32
+ *
33
+ * @param value The email as a string.
34
+ */
35
+ const validateEmail = (value) => /^[^.][^@]*@[^.]+(\.[^.\s]+)+$/.test(value);
36
+ exports.validateEmail = validateEmail;
37
+ /**
38
+ * Tests whether a given url is an internal Salesforce domain
39
+ *
40
+ * @param url
41
+ */
42
+ const isInternalUrl = (url) => new sfdcUrl_1.SfdcUrl(url).isInternalUrl();
43
+ exports.isInternalUrl = isInternalUrl;
44
+ /**
45
+ * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
46
+ *
47
+ * @param value The ID as a string.
48
+ */
49
+ const validateSalesforceId = (value) => /[a-zA-Z0-9]{18}|[a-zA-Z0-9]{15}/.test(value) && (value.length === 15 || value.length === 18);
50
+ exports.validateSalesforceId = validateSalesforceId;
51
+ /**
52
+ * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
53
+ *
54
+ * @param value The path as a string.
55
+ */
56
+ const validatePathDoesNotContainInvalidChars = (value) =>
57
+ // eslint-disable-next-line no-useless-escape
58
+ !/[\["\?<>\|\]]+/.test(value);
59
+ exports.validatePathDoesNotContainInvalidChars = validatePathDoesNotContainInvalidChars;
60
+ /**
61
+ * Returns the first key within the object that has an upper case first letter.
62
+ *
63
+ * @param data The object in which to check key casing.
64
+ * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`.
65
+ */
66
+ const findUpperCaseKeys = (data, sectionBlocklist = []) => {
67
+ let key;
68
+ (0, kit_1.findKey)(data, (val, k) => {
69
+ if (/^[A-Z]/.test(k)) {
70
+ key = k;
22
71
  }
23
- return id;
24
- },
25
- /**
26
- * Tests whether an API version matches the format `i.0`.
27
- *
28
- * @param value The API version as a string.
29
- */
30
- validateApiVersion: (value) => {
31
- return value == null || /^[1-9]\d\.0$/.test(value);
32
- },
33
- /**
34
- * Tests whether an email matches the format `me@my.org`
35
- *
36
- * @param value The email as a string.
37
- */
38
- validateEmail: (value) => {
39
- return /^[^.][^@]*@[^.]+(\.[^.\s]+)+$/.test(value);
40
- },
41
- /**
42
- * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
43
- *
44
- * @param value The ID as a string.
45
- */
46
- validateSalesforceId: (value) => {
47
- return /[a-zA-Z0-9]{18}|[a-zA-Z0-9]{15}/.test(value) && (value.length === 15 || value.length === 18);
48
- },
49
- /**
50
- * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
51
- *
52
- * @param value The path as a string.
53
- */
54
- validatePathDoesNotContainInvalidChars: (value) => {
55
- // eslint-disable-next-line no-useless-escape
56
- return !/[\["\?<>\|\]]+/.test(value);
57
- },
58
- /**
59
- * Returns the first key within the object that has an upper case first letter.
60
- *
61
- * @param data The object in which to check key casing.
62
- * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`.
63
- */
64
- findUpperCaseKeys: (data, sectionBlocklist = []) => {
65
- let key;
66
- (0, kit_1.findKey)(data, (val, k) => {
67
- if (k.substr(0, 1) === k.substr(0, 1).toUpperCase()) {
68
- key = k;
69
- }
70
- else if ((0, ts_types_1.isJsonMap)(val)) {
71
- if (sectionBlocklist.includes(k)) {
72
- return key;
73
- }
74
- key = exports.sfdc.findUpperCaseKeys((0, ts_types_1.asJsonMap)(val));
72
+ else if ((0, ts_types_1.isJsonMap)(val)) {
73
+ if (sectionBlocklist.includes(k)) {
74
+ return key;
75
75
  }
76
- return key;
77
- });
76
+ key = (0, exports.findUpperCaseKeys)((0, ts_types_1.asJsonMap)(val));
77
+ }
78
78
  return key;
79
- },
80
- /**
81
- * Tests whether a given string is an access token
82
- *
83
- * @param value
84
- */
85
- matchesAccessToken: (value) => {
86
- return /^(00D\w{12,15})![.\w]*$/.test(value);
87
- },
88
- /**
89
- * Tests whether a given url is an internal Salesforce domain
90
- *
91
- * @param url
92
- */
93
- isInternalUrl: (url) => new sfdcUrl_1.SfdcUrl(url).isInternalUrl(),
79
+ });
80
+ return key;
94
81
  };
82
+ exports.findUpperCaseKeys = findUpperCaseKeys;
83
+ /**
84
+ * Tests whether a given string is an access token
85
+ *
86
+ * @param value
87
+ */
88
+ const matchesAccessToken = (value) => /^(00D\w{12,15})![.\w]*$/.test(value);
89
+ exports.matchesAccessToken = matchesAccessToken;
95
90
  //# sourceMappingURL=sfdc.js.map