@salesforce/core 4.0.0-v3.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +93 -44
  3. package/lib/config/aliasesConfig.d.ts +12 -0
  4. package/lib/config/aliasesConfig.js +28 -0
  5. package/lib/config/authInfoConfig.d.ts +19 -0
  6. package/lib/config/authInfoConfig.js +35 -0
  7. package/lib/config/config.d.ts +181 -48
  8. package/lib/config/config.js +382 -159
  9. package/lib/config/configAggregator.d.ts +59 -42
  10. package/lib/config/configAggregator.js +135 -82
  11. package/lib/config/configFile.d.ts +2 -2
  12. package/lib/config/configFile.js +40 -31
  13. package/lib/config/configGroup.d.ts +9 -9
  14. package/lib/config/configGroup.js +13 -11
  15. package/lib/config/configStore.d.ts +9 -9
  16. package/lib/config/configStore.js +29 -26
  17. package/lib/config/envVars.d.ts +102 -0
  18. package/lib/config/envVars.js +457 -0
  19. package/lib/config/orgUsersConfig.d.ts +8 -0
  20. package/lib/config/orgUsersConfig.js +12 -0
  21. package/lib/config/sandboxOrgConfig.d.ts +8 -0
  22. package/lib/config/sandboxOrgConfig.js +12 -0
  23. package/lib/config/sandboxProcessCache.d.ts +16 -0
  24. package/lib/config/sandboxProcessCache.js +38 -0
  25. package/lib/config/tokensConfig.d.ts +10 -0
  26. package/lib/config/tokensConfig.js +29 -0
  27. package/lib/config/ttlConfig.d.ts +34 -0
  28. package/lib/config/ttlConfig.js +50 -0
  29. package/lib/crypto/crypto.js +29 -16
  30. package/lib/crypto/keyChain.js +4 -4
  31. package/lib/crypto/keyChainImpl.d.ts +5 -3
  32. package/lib/crypto/keyChainImpl.js +65 -66
  33. package/lib/crypto/secureBuffer.d.ts +1 -1
  34. package/lib/crypto/secureBuffer.js +1 -1
  35. package/lib/deviceOauthService.d.ts +5 -5
  36. package/lib/deviceOauthService.js +37 -33
  37. package/lib/exported.d.ts +22 -15
  38. package/lib/exported.js +49 -25
  39. package/lib/global.d.ts +17 -3
  40. package/lib/global.js +46 -13
  41. package/lib/lifecycleEvents.d.ts +39 -2
  42. package/lib/lifecycleEvents.js +77 -3
  43. package/lib/logger.d.ts +21 -11
  44. package/lib/logger.js +121 -105
  45. package/lib/messages.d.ts +53 -36
  46. package/lib/messages.js +89 -97
  47. package/lib/org/authInfo.d.ts +84 -72
  48. package/lib/org/authInfo.js +326 -320
  49. package/lib/org/authRemover.d.ts +16 -23
  50. package/lib/org/authRemover.js +62 -60
  51. package/lib/org/connection.d.ts +33 -59
  52. package/lib/org/connection.js +129 -190
  53. package/lib/org/index.js +6 -2
  54. package/lib/org/org.d.ts +263 -38
  55. package/lib/org/org.js +734 -149
  56. package/lib/org/orgConfigProperties.d.ts +69 -0
  57. package/lib/org/orgConfigProperties.js +121 -0
  58. package/lib/org/permissionSetAssignment.js +6 -15
  59. package/lib/org/scratchOrgCache.d.ts +20 -0
  60. package/lib/org/scratchOrgCache.js +33 -0
  61. package/lib/org/scratchOrgCreate.d.ts +54 -0
  62. package/lib/org/scratchOrgCreate.js +214 -0
  63. package/lib/org/scratchOrgErrorCodes.d.ts +10 -0
  64. package/lib/org/scratchOrgErrorCodes.js +79 -0
  65. package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -0
  66. package/lib/org/scratchOrgFeatureDeprecation.js +105 -0
  67. package/lib/org/scratchOrgInfoApi.d.ts +68 -0
  68. package/lib/org/scratchOrgInfoApi.js +416 -0
  69. package/lib/org/scratchOrgInfoGenerator.d.ts +64 -0
  70. package/lib/org/scratchOrgInfoGenerator.js +237 -0
  71. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
  72. package/lib/org/scratchOrgLifecycleEvents.js +41 -0
  73. package/lib/org/scratchOrgSettingsGenerator.d.ts +79 -0
  74. package/lib/org/scratchOrgSettingsGenerator.js +277 -0
  75. package/lib/org/scratchOrgTypes.d.ts +43 -0
  76. package/lib/{status/client.js → org/scratchOrgTypes.js} +1 -1
  77. package/lib/org/user.d.ts +7 -2
  78. package/lib/org/user.js +78 -54
  79. package/lib/schema/printer.d.ts +6 -0
  80. package/lib/schema/printer.js +49 -46
  81. package/lib/schema/validator.d.ts +12 -10
  82. package/lib/schema/validator.js +56 -76
  83. package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -15
  84. package/lib/{sfdxError.js → sfError.js} +42 -24
  85. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
  86. package/lib/sfProject.js +651 -0
  87. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -0
  88. package/lib/stateAggregator/accessors/aliasAccessor.js +146 -0
  89. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
  90. package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
  91. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
  92. package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
  93. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
  94. package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
  95. package/lib/stateAggregator/index.d.ts +4 -0
  96. package/lib/stateAggregator/index.js +27 -0
  97. package/lib/stateAggregator/stateAggregator.d.ts +25 -0
  98. package/lib/stateAggregator/stateAggregator.js +46 -0
  99. package/lib/status/myDomainResolver.d.ts +1 -1
  100. package/lib/status/myDomainResolver.js +10 -10
  101. package/lib/status/pollingClient.d.ts +2 -6
  102. package/lib/status/pollingClient.js +38 -64
  103. package/lib/status/streamingClient.d.ts +5 -80
  104. package/lib/status/streamingClient.js +74 -94
  105. package/lib/status/types.d.ts +89 -0
  106. package/lib/status/types.js +18 -0
  107. package/lib/testSetup.d.ts +212 -79
  108. package/lib/testSetup.js +478 -182
  109. package/lib/util/cache.d.ts +11 -0
  110. package/lib/util/cache.js +70 -0
  111. package/lib/util/checkLightningDomain.d.ts +1 -0
  112. package/lib/util/checkLightningDomain.js +29 -0
  113. package/lib/util/directoryWriter.d.ts +12 -0
  114. package/lib/util/directoryWriter.js +54 -0
  115. package/lib/util/getJwtAudienceUrl.d.ts +4 -0
  116. package/lib/util/getJwtAudienceUrl.js +19 -0
  117. package/lib/util/internal.d.ts +28 -2
  118. package/lib/util/internal.js +65 -8
  119. package/lib/util/jsonXmlTools.d.ts +14 -0
  120. package/lib/util/jsonXmlTools.js +39 -0
  121. package/lib/util/mapKeys.d.ts +14 -0
  122. package/lib/util/mapKeys.js +52 -0
  123. package/lib/util/sfdc.d.ts +51 -63
  124. package/lib/util/sfdc.js +75 -127
  125. package/lib/util/sfdcUrl.d.ts +64 -0
  126. package/lib/util/sfdcUrl.js +197 -0
  127. package/lib/util/structuredWriter.d.ts +9 -0
  128. package/lib/util/structuredWriter.js +3 -0
  129. package/lib/util/zipWriter.d.ts +16 -0
  130. package/lib/util/zipWriter.js +68 -0
  131. package/lib/webOAuthServer.d.ts +20 -7
  132. package/lib/webOAuthServer.js +107 -60
  133. package/messageTransformer/messageTransformer.ts +93 -0
  134. package/messages/auth.md +11 -3
  135. package/messages/config.md +94 -6
  136. package/messages/connection.md +8 -0
  137. package/messages/core.json +3 -3
  138. package/messages/core.md +11 -1
  139. package/messages/envVars.md +313 -0
  140. package/messages/org.md +64 -0
  141. package/messages/scratchOrgCreate.md +23 -0
  142. package/messages/scratchOrgErrorCodes.md +115 -0
  143. package/messages/scratchOrgFeatureDeprecation.md +11 -0
  144. package/messages/scratchOrgInfoApi.md +20 -0
  145. package/messages/scratchOrgInfoGenerator.md +27 -0
  146. package/messages/user.md +12 -0
  147. package/package.json +138 -66
  148. package/CHANGELOG.md +0 -699
  149. package/lib/config/aliases.d.ts +0 -56
  150. package/lib/config/aliases.js +0 -96
  151. package/lib/config/globalInfoConfig.d.ts +0 -74
  152. package/lib/config/globalInfoConfig.js +0 -144
  153. package/lib/config/keychainConfig.d.ts +0 -19
  154. package/lib/config/keychainConfig.js +0 -43
  155. package/lib/config/sfdxDataHandler.d.ts +0 -36
  156. package/lib/config/sfdxDataHandler.js +0 -165
  157. package/lib/sfdxProject.js +0 -546
  158. package/lib/status/client.d.ts +0 -15
  159. package/lib/util/fs.d.ts +0 -198
  160. package/lib/util/fs.js +0 -374
@@ -6,27 +6,212 @@
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.Config = void 0;
9
+ exports.SfdxConfig = exports.Config = exports.SfProperty = exports.SFDX_ALLOWED_PROPERTIES = exports.SfdxPropertyKeys = exports.SF_ALLOWED_PROPERTIES = exports.SfConfigProperties = void 0;
10
+ const path_1 = require("path");
11
+ const fs = require("fs");
10
12
  const kit_1 = require("@salesforce/kit");
11
13
  const ts_types_1 = require("@salesforce/ts-types");
14
+ const global_1 = require("../global");
12
15
  const logger_1 = require("../logger");
13
16
  const messages_1 = require("../messages");
14
17
  const sfdc_1 = require("../util/sfdc");
18
+ const sfdcUrl_1 = require("../util/sfdcUrl");
19
+ const orgConfigProperties_1 = require("../org/orgConfigProperties");
20
+ const lifecycleEvents_1 = require("../lifecycleEvents");
15
21
  const configFile_1 = require("./configFile");
16
- messages_1.Messages.importMessagesDirectory(__dirname);
17
- const messages = messages_1.Messages.load('@salesforce/core', 'config', [
18
- 'invalidInstanceUrl',
19
- 'invalidApiVersion',
20
- 'invalidIsvDebuggerSid',
21
- 'invalidIsvDebuggerUrl',
22
- 'invalidBooleanConfigValue',
23
- 'invalidNumberConfigValue',
24
- 'invalidWrite',
25
- 'unknownConfigKey',
26
- 'invalidConfigValue',
27
- ]);
28
- const log = logger_1.Logger.childFromRoot('core:config');
22
+ 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."]]));
29
23
  const SFDX_CONFIG_FILE_NAME = 'sfdx-config.json';
24
+ const CONFIG_FILE_NAME = 'config.json';
25
+ var SfConfigProperties;
26
+ (function (SfConfigProperties) {
27
+ /**
28
+ * Disables telemetry reporting
29
+ */
30
+ SfConfigProperties["DISABLE_TELEMETRY"] = "disable-telemetry";
31
+ })(SfConfigProperties = exports.SfConfigProperties || (exports.SfConfigProperties = {}));
32
+ exports.SF_ALLOWED_PROPERTIES = [
33
+ {
34
+ key: SfConfigProperties.DISABLE_TELEMETRY,
35
+ description: messages.getMessage(SfConfigProperties.DISABLE_TELEMETRY),
36
+ input: {
37
+ validator: (value) => value == null || ['true', 'false'].includes(value.toString()),
38
+ failedMessage: messages.getMessage('invalidBooleanConfigValue'),
39
+ },
40
+ },
41
+ ];
42
+ var SfdxPropertyKeys;
43
+ (function (SfdxPropertyKeys) {
44
+ /**
45
+ * Username associated with the default dev hub org.
46
+ *
47
+ * @deprecated Replaced by OrgConfigProperties.TARGET_DEV_HUB in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
48
+ * will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
49
+ */
50
+ SfdxPropertyKeys["DEFAULT_DEV_HUB_USERNAME"] = "defaultdevhubusername";
51
+ /**
52
+ * Username associate with the default org.
53
+ *
54
+ * @deprecated Replaced by OrgConfigProperties.TARGET_ORG in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
55
+ * will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
56
+ */
57
+ SfdxPropertyKeys["DEFAULT_USERNAME"] = "defaultusername";
58
+ /**
59
+ * The sid for the debugger configuration.
60
+ *
61
+ * @deprecated Replaced by OrgConfigProperties.ORG_ISV_DEBUGGER_SID in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
62
+ */
63
+ SfdxPropertyKeys["ISV_DEBUGGER_SID"] = "isvDebuggerSid";
64
+ /**
65
+ * The url for the debugger configuration.
66
+ *
67
+ * @deprecated Replaced by OrgConfigProperties.ORG_ISV_DEBUGGER_URL in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
68
+ */
69
+ SfdxPropertyKeys["ISV_DEBUGGER_URL"] = "isvDebuggerUrl";
70
+ /**
71
+ * The api version
72
+ *
73
+ * @deprecated Replaced by OrgConfigProperties.ORG_API_VERSION in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
74
+ */
75
+ SfdxPropertyKeys["API_VERSION"] = "apiVersion";
76
+ /**
77
+ * Disables telemetry reporting
78
+ *
79
+ * @deprecated Replaced by SfPropertyKeys.DISABLE_TELEMETRY in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
80
+ */
81
+ SfdxPropertyKeys["DISABLE_TELEMETRY"] = "disableTelemetry";
82
+ /**
83
+ * Custom templates repo or local location.
84
+ *
85
+ * @deprecated Replaced by OrgConfigProperties.ORG_CUSTOM_METADATA_TEMPLATES in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
86
+ */
87
+ SfdxPropertyKeys["CUSTOM_ORG_METADATA_TEMPLATES"] = "customOrgMetadataTemplates";
88
+ /**
89
+ * allows users to override the 10,000 result query limit
90
+ *
91
+ * @deprecated Replaced by OrgConfigProperties.ORG_MAX_QUERY_LIMIT in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
92
+ */
93
+ SfdxPropertyKeys["MAX_QUERY_LIMIT"] = "maxQueryLimit";
94
+ /**
95
+ * @deprecated
96
+ */
97
+ SfdxPropertyKeys["REST_DEPLOY"] = "restDeploy";
98
+ /**
99
+ * @deprecated Replaced by OrgConfigProperties.ORG_INSTANCE_URL in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
100
+ */
101
+ SfdxPropertyKeys["INSTANCE_URL"] = "instanceUrl";
102
+ })(SfdxPropertyKeys = exports.SfdxPropertyKeys || (exports.SfdxPropertyKeys = {}));
103
+ exports.SFDX_ALLOWED_PROPERTIES = [
104
+ {
105
+ key: SfdxPropertyKeys.INSTANCE_URL,
106
+ description: messages.getMessage(SfdxPropertyKeys.INSTANCE_URL),
107
+ newKey: orgConfigProperties_1.OrgConfigProperties.ORG_INSTANCE_URL,
108
+ deprecated: true,
109
+ input: {
110
+ // If a value is provided validate it otherwise no value is unset.
111
+ validator: (value) => {
112
+ if (value == null)
113
+ return true;
114
+ // validate if the value is a string and is a valid url and is either a salesforce domain
115
+ // or an internal url.
116
+ return ((0, ts_types_1.isString)(value) &&
117
+ sfdcUrl_1.SfdcUrl.isValidUrl(value) &&
118
+ (new sfdcUrl_1.SfdcUrl(value).isSalesforceDomain() || new sfdcUrl_1.SfdcUrl(value).isInternalUrl()));
119
+ },
120
+ failedMessage: messages.getMessage('invalidInstanceUrl'),
121
+ },
122
+ },
123
+ {
124
+ key: SfdxPropertyKeys.API_VERSION,
125
+ newKey: orgConfigProperties_1.OrgConfigProperties.ORG_API_VERSION,
126
+ deprecated: true,
127
+ description: messages.getMessage(SfdxPropertyKeys.API_VERSION),
128
+ hidden: true,
129
+ input: {
130
+ // If a value is provided validate it otherwise no value is unset.
131
+ validator: (value) => value == null || ((0, ts_types_1.isString)(value) && (0, sfdc_1.validateApiVersion)(value)),
132
+ failedMessage: messages.getMessage('invalidApiVersion'),
133
+ },
134
+ },
135
+ {
136
+ // will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
137
+ key: SfdxPropertyKeys.DEFAULT_DEV_HUB_USERNAME,
138
+ newKey: orgConfigProperties_1.OrgConfigProperties.TARGET_DEV_HUB,
139
+ deprecated: true,
140
+ description: messages.getMessage('defaultDevHubUsername'),
141
+ },
142
+ {
143
+ // will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
144
+ key: SfdxPropertyKeys.DEFAULT_USERNAME,
145
+ newKey: orgConfigProperties_1.OrgConfigProperties.TARGET_ORG,
146
+ deprecated: true,
147
+ description: messages.getMessage('defaultUsername'),
148
+ },
149
+ {
150
+ key: SfdxPropertyKeys.ISV_DEBUGGER_SID,
151
+ newKey: orgConfigProperties_1.OrgConfigProperties.ORG_ISV_DEBUGGER_SID,
152
+ deprecated: true,
153
+ description: messages.getMessage(SfdxPropertyKeys.ISV_DEBUGGER_SID),
154
+ encrypted: true,
155
+ input: {
156
+ // If a value is provided validate it otherwise no value is unset.
157
+ validator: (value) => value == null || (0, ts_types_1.isString)(value),
158
+ failedMessage: messages.getMessage('invalidIsvDebuggerSid'),
159
+ },
160
+ },
161
+ {
162
+ key: SfdxPropertyKeys.ISV_DEBUGGER_URL,
163
+ newKey: orgConfigProperties_1.OrgConfigProperties.ORG_ISV_DEBUGGER_URL,
164
+ deprecated: true,
165
+ description: messages.getMessage(SfdxPropertyKeys.ISV_DEBUGGER_URL),
166
+ input: {
167
+ // If a value is provided validate it otherwise no value is unset.
168
+ validator: (value) => value == null || (0, ts_types_1.isString)(value),
169
+ failedMessage: messages.getMessage('invalidIsvDebuggerUrl'),
170
+ },
171
+ },
172
+ {
173
+ key: SfdxPropertyKeys.DISABLE_TELEMETRY,
174
+ newKey: SfConfigProperties.DISABLE_TELEMETRY,
175
+ deprecated: true,
176
+ description: messages.getMessage(SfdxPropertyKeys.DISABLE_TELEMETRY),
177
+ input: {
178
+ validator: (value) => value == null || ['true', 'false'].includes(value.toString()),
179
+ failedMessage: messages.getMessage('invalidBooleanConfigValue'),
180
+ },
181
+ },
182
+ {
183
+ key: SfdxPropertyKeys.CUSTOM_ORG_METADATA_TEMPLATES,
184
+ newKey: orgConfigProperties_1.OrgConfigProperties.ORG_CUSTOM_METADATA_TEMPLATES,
185
+ deprecated: true,
186
+ description: messages.getMessage(SfdxPropertyKeys.CUSTOM_ORG_METADATA_TEMPLATES),
187
+ },
188
+ {
189
+ key: SfdxPropertyKeys.REST_DEPLOY,
190
+ description: messages.getMessage(SfdxPropertyKeys.REST_DEPLOY),
191
+ hidden: true,
192
+ newKey: 'org-metadata-rest-deploy',
193
+ deprecated: true,
194
+ input: {
195
+ validator: (value) => value != null && ['true', 'false'].includes(value.toString()),
196
+ failedMessage: messages.getMessage('invalidBooleanConfigValue'),
197
+ },
198
+ },
199
+ {
200
+ key: SfdxPropertyKeys.MAX_QUERY_LIMIT,
201
+ description: messages.getMessage(SfdxPropertyKeys.MAX_QUERY_LIMIT),
202
+ hidden: true,
203
+ newKey: orgConfigProperties_1.OrgConfigProperties.ORG_MAX_QUERY_LIMIT,
204
+ deprecated: true,
205
+ input: {
206
+ // the bit shift will remove the negative bit, and any decimal numbers
207
+ // then the parseFloat will handle converting it to a number from a string
208
+ validator: (value) => value >>> 0 === parseFloat(value) && value > 0,
209
+ failedMessage: messages.getMessage('invalidNumberConfigValue'),
210
+ },
211
+ },
212
+ ];
213
+ // Generic global config properties. Specific properties can be loaded like orgConfigProperties.ts.
214
+ exports.SfProperty = {};
30
215
  /**
31
216
  * The files where sfdx config values are stored for projects and the global space.
32
217
  *
@@ -35,27 +220,33 @@ const SFDX_CONFIG_FILE_NAME = 'sfdx-config.json';
35
220
  *
36
221
  * ```
37
222
  * const localConfig = await Config.create();
38
- * localConfig.set('defaultusername', 'username@company.org');
223
+ * localConfig.set('target-org', 'username@company.org');
39
224
  * await localConfig.write();
40
225
  * ```
41
226
  * https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_config_values.htm
42
227
  */
43
228
  class Config extends configFile_1.ConfigFile {
44
229
  constructor(options) {
45
- super(options || Config.getDefaultOptions(false));
230
+ super(Object.assign({
231
+ isGlobal: false,
232
+ }, options ?? {}, {
233
+ // Don't let consumers of config override this. If they really really want to,
234
+ // they can extend this class.
235
+ isState: true,
236
+ filename: Config.getFileName(),
237
+ stateFolder: global_1.Global.SF_STATE_FOLDER,
238
+ }));
46
239
  // Resolve the config path on creation.
47
240
  this.getPath();
48
- }
49
- static get propertyConfigMap() {
50
- return kit_1.keyBy(Config.allowedProperties, 'key');
241
+ this.sfdxConfig = new SfdxConfig(this.options, this);
51
242
  }
52
243
  /**
53
244
  * Returns the default file name for a config file.
54
245
  *
55
- * **See** {@link SFDX_CONFIG_FILE_NAME}
246
+ * **See** {@link CONFIG_FILE_NAME}
56
247
  */
57
248
  static getFileName() {
58
- return SFDX_CONFIG_FILE_NAME;
249
+ return CONFIG_FILE_NAME;
59
250
  }
60
251
  /**
61
252
  * Returns an array of objects representing the allowed config properties.
@@ -69,28 +260,18 @@ class Config extends configFile_1.ConfigFile {
69
260
  * @param metas Array of objects to set as the allowed config properties.
70
261
  */
71
262
  static addAllowedProperties(metas) {
72
- const currentMetaKeys = Object.keys(Config.propertyConfigMap);
263
+ const currentMetaKeys = Object.keys(Config.propertyConfigMap());
264
+ // If logger is needed elsewhere in this file, do not move this outside of the Config class.
265
+ // It was causing issues with Bunyan log rotation. See https://github.com/forcedotcom/sfdx-core/pull/562
266
+ const logger = logger_1.Logger.childFromRoot('core:config');
73
267
  metas.forEach((meta) => {
74
268
  if (currentMetaKeys.includes(meta.key)) {
75
- log.info(`Key ${meta.key} already exists in allowedProperties, skipping.`);
269
+ logger.info(`Key ${meta.key} already exists in allowedProperties, skipping.`);
76
270
  return;
77
271
  }
78
272
  Config.allowedProperties.push(meta);
79
273
  });
80
274
  }
81
- /**
82
- * Gets default options.
83
- *
84
- * @param isGlobal Make the config global.
85
- * @param filename Override the default file. {@link Config.getFileName}
86
- */
87
- static getDefaultOptions(isGlobal = false, filename) {
88
- return {
89
- isGlobal,
90
- isState: true,
91
- filename: filename || this.getFileName(),
92
- };
93
- }
94
275
  /**
95
276
  * The value of a supported config property.
96
277
  *
@@ -99,13 +280,13 @@ class Config extends configFile_1.ConfigFile {
99
280
  * @param value The property value.
100
281
  */
101
282
  static async update(isGlobal, propertyName, value) {
102
- const config = await Config.create(Config.getDefaultOptions(isGlobal));
283
+ const config = await Config.create({ isGlobal });
103
284
  const content = await config.read();
104
285
  if (value == null) {
105
286
  delete content[propertyName];
106
287
  }
107
288
  else {
108
- kit_1.set(content, propertyName, value);
289
+ (0, kit_1.set)(content, propertyName, value);
109
290
  }
110
291
  return config.write(content);
111
292
  }
@@ -113,19 +294,32 @@ class Config extends configFile_1.ConfigFile {
113
294
  * Clear all the configured properties both local and global.
114
295
  */
115
296
  static async clear() {
116
- let config = await Config.create(Config.getDefaultOptions(true));
117
- config.clear();
118
- await config.write();
119
- config = await Config.create(Config.getDefaultOptions(false));
120
- config.clear();
121
- await config.write();
297
+ const globalConfig = await Config.create({ isGlobal: true });
298
+ globalConfig.clear();
299
+ await globalConfig.write();
300
+ const localConfig = await Config.create();
301
+ localConfig.clear();
302
+ await localConfig.write();
303
+ }
304
+ static getPropertyConfigMeta(propertyName) {
305
+ const prop = Config.propertyConfigMap()[propertyName];
306
+ if (prop?.deprecated && prop?.newKey) {
307
+ return Config.propertyConfigMap()[prop.newKey];
308
+ }
309
+ return prop;
310
+ }
311
+ static propertyConfigMap() {
312
+ return (0, kit_1.keyBy)(Config.allowedProperties, 'key');
122
313
  }
123
314
  /**
124
315
  * Read, assign, and return the config contents.
125
316
  */
126
317
  async read(force = true) {
127
318
  try {
128
- await super.read(false, force);
319
+ const config = await super.read(false, force);
320
+ // Merge .sfdx/sfdx-config.json and .sf/config.json
321
+ const merged = this.sfdxConfig.merge(config);
322
+ this.setContents(merged);
129
323
  await this.cryptProperties(false);
130
324
  return this.getContents();
131
325
  }
@@ -133,6 +327,13 @@ class Config extends configFile_1.ConfigFile {
133
327
  await this.clearCrypto();
134
328
  }
135
329
  }
330
+ readSync(force = true) {
331
+ const config = super.readSync(false, force);
332
+ // Merge .sfdx/sfdx-config.json and .sf/config.json
333
+ const merged = this.sfdxConfig.merge(config);
334
+ this.setContents(merged);
335
+ return this.getContents();
336
+ }
136
337
  /**
137
338
  * Writes Config properties taking into account encrypted properties.
138
339
  *
@@ -144,6 +345,8 @@ class Config extends configFile_1.ConfigFile {
144
345
  }
145
346
  await this.cryptProperties(true);
146
347
  await super.write();
348
+ if (global_1.Global.SFDX_INTEROPERABILITY)
349
+ await this.sfdxConfig.write();
147
350
  await this.cryptProperties(false);
148
351
  return this.getContents();
149
352
  }
@@ -151,35 +354,45 @@ class Config extends configFile_1.ConfigFile {
151
354
  * DO NOT CALL - The config file needs to encrypt values which can only be done asynchronously.
152
355
  * Call {@link SfdxConfig.write} instead.
153
356
  *
154
- * **Throws** *{@link SfdxError}{ name: 'InvalidWriteError' }* Always.
357
+ * **Throws** *{@link SfError}{ name: 'InvalidWriteError' }* Always.
155
358
  *
156
359
  * @param newContents Contents to write
157
360
  */
158
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
361
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
159
362
  writeSync(newContents) {
160
363
  throw messages.createError('invalidWrite');
161
364
  }
162
365
  /**
163
366
  * Sets a value for a property.
164
367
  *
165
- * **Throws** *{@link SfdxError}{ name: 'UnknownConfigKeyError' }* An attempt to get a property that's not supported.
166
- * **Throws** *{@link SfdxError}{ name: 'InvalidConfigValueError' }* If the input validator fails.
368
+ * **Throws** *{@link SfError}{ name: 'UnknownConfigKeyError' }* An attempt to get a property that's not supported.
369
+ * **Throws** *{@link SfError}{ name: 'InvalidConfigValueError' }* If the input validator fails.
167
370
  *
168
371
  * @param key The property to set.
169
372
  * @param value The value of the property.
170
373
  */
171
374
  set(key, value) {
172
- var _a;
173
375
  const property = Config.allowedProperties.find((allowedProp) => allowedProp.key === key);
174
376
  if (!property) {
175
377
  throw messages.createError('unknownConfigKey', [key]);
176
378
  }
379
+ if (property.deprecated && property.newKey) {
380
+ // you're trying to set a deprecated key, but we'll set the new key instead
381
+ void lifecycleEvents_1.Lifecycle.getInstance().emitWarning(messages.getMessage('deprecatedConfigKey', [key, property.newKey]));
382
+ return this.set(property.newKey, value);
383
+ }
177
384
  if (property.input) {
178
- if (property.input && property.input.validator(value)) {
385
+ if (property.input?.validator(value)) {
179
386
  super.set(property.key, value);
180
387
  }
181
388
  else {
182
- throw messages.createError('invalidConfigValue', [(_a = property.input.failedMessage) !== null && _a !== void 0 ? _a : '']);
389
+ let valueError = value?.toString() ?? '';
390
+ if (property.input.failedMessage) {
391
+ valueError = (0, ts_types_1.isString)(property.input.failedMessage)
392
+ ? property.input.failedMessage
393
+ : property.input.failedMessage(value);
394
+ }
395
+ throw messages.createError('invalidConfigValue', [valueError]);
183
396
  }
184
397
  }
185
398
  else {
@@ -190,7 +403,7 @@ class Config extends configFile_1.ConfigFile {
190
403
  /**
191
404
  * Unsets a value for a property.
192
405
  *
193
- * **Throws** *{@link SfdxError}{ name: 'UnknownConfigKeyError' }* If the input validator fails.
406
+ * **Throws** *{@link SfError}{ name: 'UnknownConfigKeyError' }* If the input validator fails.
194
407
  *
195
408
  * @param key The property to unset.
196
409
  */
@@ -199,141 +412,151 @@ class Config extends configFile_1.ConfigFile {
199
412
  if (!property) {
200
413
  throw messages.createError('unknownConfigKey', [key]);
201
414
  }
415
+ if (property.deprecated && property.newKey) {
416
+ // you're trying to set a deprecated key, so we'll ALSO unset the new key
417
+ void lifecycleEvents_1.Lifecycle.getInstance().emitWarning(messages.getMessage('deprecatedConfigKey', [key, property.newKey]));
418
+ super.unset(property.key);
419
+ return this.unset(property.newKey);
420
+ }
202
421
  return super.unset(property.key);
203
422
  }
204
- /**
205
- * Initializer for supported config types.
206
- */
207
- async init() {
208
- // Super ConfigFile calls read, which has a dependency on crypto, which finally has a dependency on
209
- // Config.propertyConfigMap being set. This is why init is called after the setup.
210
- await super.init();
211
- }
212
423
  /**
213
424
  * Get an individual property config.
214
425
  *
215
- * **Throws** *{@link SfdxError}{ name: 'UnknownConfigKeyError' }* An attempt to get a property that's not supported.
426
+ * **Throws** *{@link SfError}{ name: 'UnknownConfigKeyError' }* An attempt to get a property that's not supported.
216
427
  *
217
428
  * @param propertyName The name of the property.
218
429
  */
430
+ // eslint-disable-next-line class-methods-use-this
219
431
  getPropertyConfig(propertyName) {
220
- const prop = Config.propertyConfigMap[propertyName];
432
+ const prop = Config.propertyConfigMap()[propertyName];
221
433
  if (!prop) {
434
+ const newEquivalent = Config.allowedProperties.find((p) => p.newKey);
435
+ if (newEquivalent) {
436
+ return this.getPropertyConfig(newEquivalent.key);
437
+ }
222
438
  throw messages.createError('unknownConfigKey', [propertyName]);
223
439
  }
224
440
  return prop;
225
441
  }
442
+ /**
443
+ * Initializer for supported config types.
444
+ */
445
+ async init() {
446
+ // Super ConfigFile calls read, which has a dependency on crypto, which finally has a dependency on
447
+ // Config.propertyConfigMap being set. This is why init is called after the setup.
448
+ await super.init();
449
+ }
226
450
  /**
227
451
  * Encrypts and content properties that have a encryption attribute.
228
452
  *
229
453
  * @param encrypt `true` to encrypt.
230
454
  */
231
455
  async cryptProperties(encrypt) {
232
- const hasEncryptedProperties = this.entries().some(([key]) => {
233
- var _a;
234
- return !!((_a = Config.propertyConfigMap[key]) === null || _a === void 0 ? void 0 : _a.encrypted);
235
- });
456
+ const hasEncryptedProperties = this.entries().some(([key]) => !!Config.propertyConfigMap()[key]?.encrypted);
236
457
  if (hasEncryptedProperties) {
237
458
  await this.initCrypto();
238
- const crypto = ts_types_1.ensure(this.crypto);
459
+ const crypto = (0, ts_types_1.ensure)(this.crypto);
239
460
  this.forEach((key, value) => {
240
- if (this.getPropertyConfig(key).encrypted && ts_types_1.isString(value)) {
241
- this.set(key, ts_types_1.ensure(encrypt ? crypto.encrypt(value) : crypto.decrypt(value)));
461
+ if (this.getPropertyConfig(key).encrypted && (0, ts_types_1.isString)(value)) {
462
+ this.set(key, (0, ts_types_1.ensure)(encrypt ? crypto.encrypt(value) : crypto.decrypt(value)));
242
463
  }
243
464
  });
244
465
  }
245
466
  }
246
467
  }
247
468
  exports.Config = Config;
248
- /**
249
- * Username associated with the default dev hub org.
250
- */
251
- Config.DEFAULT_DEV_HUB_USERNAME = 'defaultdevhubusername';
252
- /**
253
- * Username associate with the default org.
254
- */
255
- Config.DEFAULT_USERNAME = 'defaultusername';
256
- /**
257
- * The sid for the debugger configuration.
258
- */
259
- Config.ISV_DEBUGGER_SID = 'isvDebuggerSid';
260
- /**
261
- * The url for the debugger configuration.
262
- */
263
- Config.ISV_DEBUGGER_URL = 'isvDebuggerUrl';
264
- /**
265
- * The api version
266
- */
267
- Config.API_VERSION = 'apiVersion';
268
- /**
269
- * Disables telemetry reporting
270
- */
271
- Config.DISABLE_TELEMETRY = 'disableTelemetry';
272
- /**
273
- * allows users to override the 10,000 result query limit
274
- */
275
- Config.MAX_QUERY_LIMIT = 'maxQueryLimit';
276
469
  Config.allowedProperties = [
277
- {
278
- key: 'instanceUrl',
279
- input: {
280
- // If a value is provided validate it otherwise no value is unset.
281
- validator: (value) => value == null || (ts_types_1.isString(value) && sfdc_1.sfdc.isSalesforceDomain(value)),
282
- failedMessage: messages.getMessage('invalidInstanceUrl'),
283
- },
284
- },
285
- {
286
- key: Config.API_VERSION,
287
- hidden: true,
288
- input: {
289
- // If a value is provided validate it otherwise no value is unset.
290
- validator: (value) => value == null || (ts_types_1.isString(value) && sfdc_1.sfdc.validateApiVersion(value)),
291
- failedMessage: messages.getMessage('invalidApiVersion'),
292
- },
293
- },
294
- { key: Config.DEFAULT_DEV_HUB_USERNAME },
295
- { key: Config.DEFAULT_USERNAME },
296
- {
297
- key: Config.ISV_DEBUGGER_SID,
298
- encrypted: true,
299
- input: {
300
- // If a value is provided validate it otherwise no value is unset.
301
- validator: (value) => value == null || ts_types_1.isString(value),
302
- failedMessage: messages.getMessage('invalidIsvDebuggerSid'),
303
- },
304
- },
305
- {
306
- key: Config.ISV_DEBUGGER_URL,
307
- input: {
308
- // If a value is provided validate it otherwise no value is unset.
309
- validator: (value) => value == null || ts_types_1.isString(value),
310
- failedMessage: messages.getMessage('invalidIsvDebuggerUrl'),
311
- },
312
- },
313
- {
314
- key: Config.DISABLE_TELEMETRY,
315
- input: {
316
- validator: (value) => value == null || ['true', 'false'].includes(value.toString()),
317
- failedMessage: messages.getMessage('invalidBooleanConfigValue'),
318
- },
319
- },
320
- // This should be brought in by a plugin, but there isn't a way to do that right now.
321
- {
322
- key: 'restDeploy',
323
- hidden: true,
324
- input: {
325
- validator: (value) => value != null && ['true', 'false'].includes(value.toString()),
326
- failedMessage: messages.getMessage('invalidBooleanConfigValue'),
327
- },
328
- },
329
- {
330
- key: Config.MAX_QUERY_LIMIT,
331
- input: {
332
- // the bit shift will remove the negative bit, and any decimal numbers
333
- // then the parseFloat will handle converting it to a number from a string
334
- validator: (value) => value >>> 0 === parseFloat(value) && value > 0,
335
- failedMessage: messages.getMessage('invalidNumberConfigValue'),
336
- },
337
- },
470
+ ...exports.SFDX_ALLOWED_PROPERTIES,
471
+ ...exports.SF_ALLOWED_PROPERTIES,
472
+ ...orgConfigProperties_1.ORG_CONFIG_ALLOWED_PROPERTIES,
338
473
  ];
474
+ class SfdxConfig {
475
+ constructor(options = {}, config) {
476
+ this.options = options;
477
+ this.config = config;
478
+ this.sfdxPath = this.getSfdxPath();
479
+ }
480
+ /**
481
+ * If Global.SFDX_INTEROPERABILITY is enabled, merge the sfdx config into the sf config
482
+ */
483
+ merge(config) {
484
+ if (!global_1.Global.SFDX_INTEROPERABILITY)
485
+ return config;
486
+ const sfdxConfig = this.readSync();
487
+ const sfdxPropKeys = Object.values(SfdxPropertyKeys);
488
+ // Get a list of config keys that are NOT provided by SfdxPropertyKeys
489
+ const nonSfdxPropKeys = Config.getAllowedProperties()
490
+ .filter((p) => !sfdxPropKeys.includes(p.key))
491
+ .map((p) => p.key);
492
+ // Remove any config from .sf that isn't also in .sfdx
493
+ // This handles the scenario where a config has been deleted
494
+ // from .sfdx and we want to mirror that change in .sf
495
+ for (const key of nonSfdxPropKeys) {
496
+ if (!sfdxConfig[key])
497
+ delete config[key];
498
+ }
499
+ return Object.assign(config, sfdxConfig);
500
+ }
501
+ async write(config = this.config.toObject()) {
502
+ try {
503
+ const translated = this.translate(config, 'toOld');
504
+ const sfdxPath = this.getSfdxPath();
505
+ await fs.promises.mkdir((0, path_1.dirname)(sfdxPath), { recursive: true });
506
+ await fs.promises.writeFile(sfdxPath, JSON.stringify(translated, null, 2));
507
+ }
508
+ catch (error) {
509
+ /* Do nothing */
510
+ }
511
+ }
512
+ readSync() {
513
+ try {
514
+ const contents = (0, kit_1.parseJsonMap)(fs.readFileSync(this.getSfdxPath(), 'utf8'));
515
+ return this.translate(contents, 'toNew');
516
+ }
517
+ catch (error) {
518
+ /* Do nothing */
519
+ return {};
520
+ }
521
+ }
522
+ getSfdxPath() {
523
+ if (!this.sfdxPath) {
524
+ const stateFolder = global_1.Global.SFDX_STATE_FOLDER;
525
+ const fileName = SFDX_CONFIG_FILE_NAME;
526
+ // Don't let users store config files in homedir without being in the state folder.
527
+ let configRootFolder = this.options.rootFolder
528
+ ? this.options.rootFolder
529
+ : configFile_1.ConfigFile.resolveRootFolderSync(!!this.options.isGlobal);
530
+ if (this.options.isGlobal === true || this.options.isState === true) {
531
+ configRootFolder = (0, path_1.join)(configRootFolder, stateFolder);
532
+ }
533
+ this.sfdxPath = (0, path_1.join)(configRootFolder, fileName);
534
+ }
535
+ return this.sfdxPath;
536
+ }
537
+ /**
538
+ * If toNew is specified: migrate all deprecated configs with a newKey to the newKey.
539
+ * - For example, defaultusername will be renamed to target-org.
540
+ *
541
+ * If toOld is specified: migrate all deprecated configs back to their original key.
542
+ * - For example, target-org will be renamed to defaultusername.
543
+ */
544
+ translate(contents, direction) {
545
+ const translated = {};
546
+ for (const [key, value] of Object.entries(contents)) {
547
+ const propConfig = direction === 'toNew'
548
+ ? this.config.getPropertyConfig(key)
549
+ : Config.getAllowedProperties().find((c) => c.newKey === key) ?? {};
550
+ if (propConfig.deprecated && propConfig.newKey) {
551
+ const normalizedKey = direction === 'toNew' ? propConfig.newKey : propConfig.key;
552
+ translated[normalizedKey] = value;
553
+ }
554
+ else {
555
+ translated[key] = value;
556
+ }
557
+ }
558
+ return translated;
559
+ }
560
+ }
561
+ exports.SfdxConfig = SfdxConfig;
339
562
  //# sourceMappingURL=config.js.map