@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
@@ -10,19 +10,13 @@ exports.getScratchOrgInfoPayload = exports.generateScratchOrgInfo = exports.getA
10
10
  const fs_1 = require("fs");
11
11
  const kit_1 = require("@salesforce/kit");
12
12
  const ts_types_1 = require("@salesforce/ts-types");
13
- const sfdc_1 = require("../util/sfdc");
14
- const sfdxProject_1 = require("../sfdxProject");
13
+ const sfProject_1 = require("../sfProject");
15
14
  const webOAuthServer_1 = require("../webOAuthServer");
16
15
  const messages_1 = require("../messages");
17
- const sfdxError_1 = require("../sfdxError");
16
+ const sfError_1 = require("../sfError");
18
17
  const scratchOrgFeatureDeprecation_1 = require("./scratchOrgFeatureDeprecation");
19
- const defaultConnectedAppInfo = {
20
- clientId: 'PlatformCLI',
21
- legacyClientId: 'SalesforceDevelopmentExperience',
22
- legacyClientSecret: '1384510088588713504',
23
- };
24
- messages_1.Messages.importMessagesDirectory(__dirname);
25
- const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgInfoGenerator');
18
+ const authInfo_1 = require("./authInfo");
19
+ const messages = new messages_1.Messages('@salesforce/core', 'scratchOrgInfoGenerator', new Map([["Package2AncestorsIdsKeyNotSupportedError", "The package2AncestorIds key is no longer supported in a scratch org definition. Ancestors defined in sfdx-project.json will be included in the scratch org.\","], ["InvalidAncestorVersionFormatError", "The ancestor versionNumber must be in the format major.minor.patch but the value found is %s\","], ["NoMatchingAncestorError", "The ancestor for ancestorVersion %s can't be found. Package ID %s.\","], ["NoMatchingAncestorIdError", "The ancestor for ancestorId [%s] can't be found. Package ID %s.\""], ["AncestorNotReleasedError", "The ancestor package version [%s] specified in the sfdx-project.json file may exist hasn\u2019t been promoted and released. Release the ancestor package version before specifying it as the ancestor in a new package or patch version.\","], ["AncestorIdVersionMismatchError", "The ancestorVersion in sfdx-project.json is not the version expected for the ancestorId you supplied. ancestorVersion %s. ancestorID %s.\""], ["unsupportedSnapshotOrgCreateOptions", "Org snapshots don\u2019t support one or more options you specified: %s"]]));
26
20
  const SNAPSHOT_UNSUPPORTED_OPTIONS = [
27
21
  'features',
28
22
  'orgPreferences',
@@ -38,12 +32,12 @@ const SNAPSHOT_UNSUPPORTED_OPTIONS = [
38
32
  // executed within the ctor and also after parsing/normalization of the definition file.
39
33
  const optionsValidator = (key, scratchOrgInfoPayload) => {
40
34
  if (key.toLowerCase() === 'durationdays') {
41
- throw new sfdxError_1.SfdxError('unrecognizedScratchOrgOption', 'durationDays');
35
+ throw new sfError_1.SfError('unrecognizedScratchOrgOption', 'durationDays');
42
36
  }
43
37
  if (key.toLowerCase() === 'snapshot') {
44
38
  const foundInvalidFields = SNAPSHOT_UNSUPPORTED_OPTIONS.filter((invalidField) => invalidField in scratchOrgInfoPayload);
45
39
  if (foundInvalidFields.length > 0) {
46
- throw new sfdxError_1.SfdxError(messages.getMessage('unsupportedSnapshotOrgCreateOptions', [foundInvalidFields.join(', ')]), 'orgSnapshot');
40
+ throw new sfError_1.SfError(messages.getMessage('unsupportedSnapshotOrgCreateOptions', [foundInvalidFields.join(', ')]), 'orgSnapshot');
47
41
  }
48
42
  }
49
43
  };
@@ -51,30 +45,50 @@ const optionsValidator = (key, scratchOrgInfoPayload) => {
51
45
  * Generates the package2AncestorIds scratch org property
52
46
  *
53
47
  * @param scratchOrgInfo - the scratchOrgInfo passed in by the user
54
- * @param projectJson - sfdxProjectJson
48
+ * @param projectJson - sfProjectJson
55
49
  * @param hubOrg - the hub org, in case we need to do queries
56
50
  */
57
51
  const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
58
52
  if (Reflect.has(scratchOrgInfo, 'package2AncestorIds')) {
59
- throw new sfdxError_1.SfdxError(messages.getMessage('Package2AncestorsIdsKeyNotSupportedError'), 'DeprecationError');
53
+ throw new sfError_1.SfError(messages.getMessage('Package2AncestorsIdsKeyNotSupportedError'), 'DeprecationError');
60
54
  }
61
55
  const packagesWithAncestors = (await projectJson.getPackageDirectories())
62
56
  // check that the package has any ancestor types (id or version)
63
- .filter((packageDir) => packageDir.ancestorId || packageDir.ancestorVersion);
57
+ .filter((packageDir) => packageDir.ancestorId ?? packageDir.ancestorVersion);
64
58
  if (packagesWithAncestors.length === 0) {
65
59
  return '';
66
60
  }
67
61
  const ancestorIds = await Promise.all(packagesWithAncestors.map(async (packageDir) => {
68
- var _a, _b, _c;
69
62
  // ancestorID can be 05i, or 04t, alias; OR "ancestorVersion": "4.6.0.1"
70
63
  // according to docs, 05i is not ok: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev2gp_config_file.htm
64
+ // package can be an ID, but not according to docs
65
+ const packageAliases = projectJson.get('packageAliases');
66
+ const packageId = packageAliases[(0, ts_types_1.ensureString)(packageDir.package)] ?? packageDir.package;
67
+ // Handle HIGHEST and NONE in ancestor(Version|Id).
68
+ // Precedence chain: NONE -> HIGHEST -> ancestorVersion & ancestoryId
69
+ if (packageDir.ancestorVersion === 'NONE' || packageDir.ancestorId === 'NONE') {
70
+ return '';
71
+ }
72
+ else if (packageDir.ancestorVersion === 'HIGHEST' || packageDir.ancestorId === 'HIGHEST') {
73
+ const query = 'SELECT Id FROM Package2Version ' +
74
+ `WHERE Package2Id = '${packageId}' AND IsReleased = True AND IsDeprecated = False AND PatchVersion = 0 ` +
75
+ 'ORDER BY MajorVersion Desc, MinorVersion Desc, PatchVersion Desc, BuildNumber Desc LIMIT 1';
76
+ try {
77
+ return (await hubOrg.getConnection().singleRecordQuery(query, { tooling: true })).Id;
78
+ }
79
+ catch (err) {
80
+ if (packageDir.ancestorVersion === 'HIGHEST') {
81
+ throw new sfError_1.SfError(messages.getMessage('NoMatchingAncestorError', [packageDir.ancestorVersion, packageDir.package]), 'NoMatchingAncestorError', [messages.getMessage('AncestorNotReleasedError', [packageDir.ancestorVersion])]);
82
+ }
83
+ else {
84
+ throw new sfError_1.SfError(messages.getMessage('NoMatchingAncestorIdError', [packageDir.ancestorId, packageDir.package]), 'NoMatchingAncestorIdError', [messages.getMessage('AncestorNotReleasedError', [packageDir.ancestorId])]);
85
+ }
86
+ }
87
+ }
71
88
  if (packageDir.ancestorVersion) {
72
89
  if (!/^[0-9]+.[0-9]+.[0-9]+(.[0-9]+)?$/.test(packageDir.ancestorVersion)) {
73
90
  throw messages.createError('InvalidAncestorVersionFormatError', [packageDir.ancestorVersion]);
74
91
  }
75
- // package can be an ID, but not according to docs
76
- const packageAliases = projectJson.get('packageAliases');
77
- const packageId = (_a = packageAliases[(0, ts_types_1.ensureString)(packageDir.package)]) !== null && _a !== void 0 ? _a : packageDir.package;
78
92
  const [major, minor, patch] = packageDir.ancestorVersion.split('.');
79
93
  let releasedAncestor;
80
94
  try {
@@ -83,7 +97,7 @@ const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
83
97
  .singleRecordQuery(`SELECT Id, IsReleased FROM Package2Version WHERE Package2Id = '${packageId}' AND MajorVersion = ${major} AND MinorVersion = ${minor} AND PatchVersion = ${patch} and IsReleased = true`, { tooling: true });
84
98
  }
85
99
  catch (err) {
86
- throw new sfdxError_1.SfdxError(messages.getMessage('NoMatchingAncestorError', [packageDir.ancestorVersion, packageDir.package]), 'NoMatchingAncestorError', [messages.getMessage('AncestorNotReleasedError', [packageDir.ancestorVersion])]);
100
+ throw new sfError_1.SfError(messages.getMessage('NoMatchingAncestorError', [packageDir.ancestorVersion, packageDir.package]), 'NoMatchingAncestorError', [messages.getMessage('AncestorNotReleasedError', [packageDir.ancestorVersion])]);
87
101
  }
88
102
  if (packageDir.ancestorId && packageDir.ancestorId !== releasedAncestor.Id) {
89
103
  throw messages.createError('AncestorIdVersionMismatchError', [
@@ -93,24 +107,24 @@ const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
93
107
  }
94
108
  return releasedAncestor.Id;
95
109
  }
96
- if ((_b = packageDir === null || packageDir === void 0 ? void 0 : packageDir.ancestorId) === null || _b === void 0 ? void 0 : _b.startsWith('05i')) {
110
+ if (packageDir?.ancestorId?.startsWith('05i')) {
97
111
  // if it's already a 05i return it, otherwise query for it
98
112
  return packageDir.ancestorId;
99
113
  }
100
- if ((_c = packageDir === null || packageDir === void 0 ? void 0 : packageDir.ancestorId) === null || _c === void 0 ? void 0 : _c.startsWith('04t')) {
114
+ if (packageDir?.ancestorId?.startsWith('04t')) {
101
115
  // query for the Id
102
116
  return (await hubOrg
103
117
  .getConnection()
104
118
  .singleRecordQuery(`SELECT Id FROM Package2Version WHERE SubscriberPackageVersionId = '${packageDir.ancestorId}'`, { tooling: true })).Id;
105
119
  }
106
- // ancestorID can be an alias get it from projectJson
107
- const packageAliases = projectJson.get('packageAliases');
108
- if (packageDir.ancestorId && (packageAliases === null || packageAliases === void 0 ? void 0 : packageAliases[packageDir.ancestorId])) {
120
+ // ancestorID can be an alias; get it from projectJson
121
+ if (packageDir.ancestorId && packageAliases?.[packageDir.ancestorId]) {
109
122
  return packageAliases[packageDir.ancestorId];
110
123
  }
111
- throw new sfdxError_1.SfdxError(`Invalid ancestorId ${packageDir.ancestorId}`, 'InvalidAncestorId');
124
+ throw new sfError_1.SfError(`Invalid ancestorId ${packageDir.ancestorId}`, 'InvalidAncestorId');
112
125
  }));
113
- return Array.from(new Set(ancestorIds)).join(';');
126
+ // strip out '' due to NONE
127
+ return Array.from(new Set(ancestorIds.filter((id) => id !== ''))).join(';');
114
128
  };
115
129
  exports.getAncestorIds = getAncestorIds;
116
130
  /**
@@ -122,26 +136,25 @@ exports.getAncestorIds = getAncestorIds;
122
136
  * @param ignoreAncestorIds true if the sfdx-project.json ancestorId keys should be ignored
123
137
  */
124
138
  const generateScratchOrgInfo = async ({ hubOrg, scratchOrgInfoPayload, nonamespace, ignoreAncestorIds, }) => {
125
- var _a, _b;
126
- let sfdxProject;
139
+ let sfProject;
127
140
  try {
128
- sfdxProject = await sfdxProject_1.SfdxProjectJson.create({});
141
+ sfProject = await sfProject_1.SfProjectJson.create({});
129
142
  }
130
143
  catch (e) {
131
144
  // project is not required
132
145
  }
133
- scratchOrgInfoPayload.orgName = (_a = scratchOrgInfoPayload.orgName) !== null && _a !== void 0 ? _a : 'Company';
146
+ scratchOrgInfoPayload.orgName = scratchOrgInfoPayload.orgName ?? 'Company';
134
147
  scratchOrgInfoPayload.package2AncestorIds =
135
- !ignoreAncestorIds && (sfdxProject === null || sfdxProject === void 0 ? void 0 : sfdxProject.hasPackages())
136
- ? await (0, exports.getAncestorIds)(scratchOrgInfoPayload, sfdxProject, hubOrg)
148
+ !ignoreAncestorIds && sfProject?.hasPackages()
149
+ ? await (0, exports.getAncestorIds)(scratchOrgInfoPayload, sfProject, hubOrg)
137
150
  : '';
138
151
  // Use the Hub org's client ID value, if one wasn't provided to us, or the default
139
152
  if (!scratchOrgInfoPayload.connectedAppConsumerKey) {
140
153
  scratchOrgInfoPayload.connectedAppConsumerKey =
141
- (_b = hubOrg.getConnection().getAuthInfoFields().clientId) !== null && _b !== void 0 ? _b : defaultConnectedAppInfo.clientId;
154
+ hubOrg.getConnection().getAuthInfoFields().clientId ?? authInfo_1.DEFAULT_CONNECTED_APP_INFO.clientId;
142
155
  }
143
- if (!nonamespace && (sfdxProject === null || sfdxProject === void 0 ? void 0 : sfdxProject.get('namespace'))) {
144
- scratchOrgInfoPayload.namespace = sfdxProject.get('namespace');
156
+ if (!nonamespace && sfProject?.get('namespace')) {
157
+ scratchOrgInfoPayload.namespace = sfProject.get('namespace');
145
158
  }
146
159
  // we already have the info, and want to get rid of configApi, so this doesn't use that
147
160
  scratchOrgInfoPayload.connectedAppCallbackUrl = `http://localhost:${await webOAuthServer_1.WebOAuthServer.determineOauthPort()}/OauthRedirect`;
@@ -164,33 +177,20 @@ exports.generateScratchOrgInfo = generateScratchOrgInfo;
164
177
  warnings: string[];
165
178
  */
166
179
  const getScratchOrgInfoPayload = async (options) => {
167
- var _a;
168
180
  let warnings = [];
169
- // orgConfig input overrides definitionjson (-j option; hidden/deprecated)
170
- const definitionJson = options.definitionjson ? JSON.parse(options.definitionjson) : {};
171
- const orgConfigInput = { ...definitionJson, ...((_a = options.orgConfig) !== null && _a !== void 0 ? _a : {}) };
172
- let scratchOrgInfoPayload = orgConfigInput;
173
- // the -f option
174
- if (options.definitionfile) {
175
- try {
176
- const fileData = await fs_1.promises.readFile(options.definitionfile, 'utf8');
177
- const defFileContents = (0, kit_1.parseJson)(fileData);
178
- // definitionjson and orgConfig override file input
179
- scratchOrgInfoPayload = { ...defFileContents, ...orgConfigInput };
180
- }
181
- catch (err) {
182
- const error = err;
183
- if (error.name === 'JsonParseError') {
184
- throw new sfdxError_1.SfdxError(`An error occurred parsing ${options.definitionfile}`);
185
- }
186
- throw sfdxError_1.SfdxError.wrap(error);
187
- }
188
- }
181
+ // orgConfig input overrides definitionjson (-j option; hidden/deprecated) overrides definitionfile (-f option)
182
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
183
+ const scratchOrgInfoPayload = {
184
+ ...(options.definitionfile ? await parseDefinitionFile(options.definitionfile) : {}),
185
+ ...(options.definitionjson ? JSON.parse(options.definitionjson) : {}),
186
+ ...(options.orgConfig ?? {}),
187
+ };
189
188
  // scratchOrgInfoPayload must be heads down camelcase.
190
- const upperCaseKey = sfdc_1.sfdc.findUpperCaseKeys(scratchOrgInfoPayload);
191
- if (upperCaseKey) {
192
- throw new sfdxError_1.SfdxError('InvalidJsonCasing', upperCaseKey);
193
- }
189
+ Object.keys(scratchOrgInfoPayload).forEach((key) => {
190
+ if (key[0].toUpperCase() === key[0]) {
191
+ throw new sfError_1.SfError('InvalidJsonCasing', key);
192
+ }
193
+ });
194
194
  // Now run the fully resolved user input against the validator
195
195
  Object.keys(scratchOrgInfoPayload).forEach((key) => {
196
196
  optionsValidator(key, scratchOrgInfoPayload);
@@ -215,9 +215,23 @@ const getScratchOrgInfoPayload = async (options) => {
215
215
  return {
216
216
  scratchOrgInfoPayload,
217
217
  // Ignore ancestor ids only when 'nonamespace' or 'noancestors' options are specified
218
- ignoreAncestorIds: options.nonamespace || options.noancestors || false,
218
+ ignoreAncestorIds: options.nonamespace ?? options.noancestors ?? false,
219
219
  warnings,
220
220
  };
221
221
  };
222
222
  exports.getScratchOrgInfoPayload = getScratchOrgInfoPayload;
223
+ const parseDefinitionFile = async (definitionFile) => {
224
+ try {
225
+ const fileData = await fs_1.promises.readFile(definitionFile, 'utf8');
226
+ const defFileContents = (0, kit_1.parseJson)(fileData);
227
+ return defFileContents;
228
+ }
229
+ catch (err) {
230
+ const error = err;
231
+ if (error.name === 'JsonParseError') {
232
+ throw new sfError_1.SfError(`An error occurred parsing ${definitionFile}`);
233
+ }
234
+ throw sfError_1.SfError.wrap(error);
235
+ }
236
+ };
223
237
  //# sourceMappingURL=scratchOrgInfoGenerator.js.map
@@ -0,0 +1,10 @@
1
+ import { AuthFields } from './authInfo';
2
+ import { ScratchOrgInfo } from './scratchOrgTypes';
3
+ export declare const scratchOrgLifecycleEventName = "scratchOrgLifecycleEvent";
4
+ export declare const scratchOrgLifecycleStages: readonly ["prepare request", "send request", "wait for org", "available", "authenticate", "deploy settings", "done"];
5
+ export interface ScratchOrgLifecycleEvent {
6
+ stage: typeof scratchOrgLifecycleStages[number];
7
+ scratchOrgInfo?: ScratchOrgInfo;
8
+ }
9
+ export declare const emit: (event: ScratchOrgLifecycleEvent) => Promise<void>;
10
+ export declare const emitPostOrgCreate: (authFields: AuthFields) => Promise<void>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitPostOrgCreate = exports.emit = exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = void 0;
4
+ /*
5
+ * Copyright (c) 2020, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * Licensed under the BSD 3-Clause license.
8
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+ const lifecycleEvents_1 = require("../lifecycleEvents");
11
+ const emitter = lifecycleEvents_1.Lifecycle.getInstance();
12
+ exports.scratchOrgLifecycleEventName = 'scratchOrgLifecycleEvent';
13
+ exports.scratchOrgLifecycleStages = [
14
+ 'prepare request',
15
+ 'send request',
16
+ 'wait for org',
17
+ 'available',
18
+ 'authenticate',
19
+ 'deploy settings',
20
+ 'done',
21
+ ];
22
+ const emit = async (event) => emitter.emit(exports.scratchOrgLifecycleEventName, event);
23
+ exports.emit = emit;
24
+ const postOrgCreateHookFields = [
25
+ 'accessToken',
26
+ 'clientId',
27
+ 'created',
28
+ 'createdOrgInstance',
29
+ 'devHubUsername',
30
+ 'expirationDate',
31
+ 'instanceUrl',
32
+ 'loginUrl',
33
+ 'orgId',
34
+ 'username',
35
+ ];
36
+ const isHookField = (key) => postOrgCreateHookFields.includes(key);
37
+ const emitPostOrgCreate = async (authFields) => {
38
+ await emitter.emit('postorgcreate', Object.fromEntries(Object.entries(authFields).filter(([key]) => isHookField(key))));
39
+ };
40
+ exports.emitPostOrgCreate = emitPostOrgCreate;
41
+ //# sourceMappingURL=scratchOrgLifecycleEvents.js.map
@@ -1,5 +1,6 @@
1
+ import { Duration } from '@salesforce/kit';
1
2
  import { JsonMap } from '@salesforce/ts-types';
2
- import { ScratchOrgInfo } from './scratchOrgInfoApi';
3
+ import { ScratchOrgInfo, ObjectSetting } from './scratchOrgTypes';
3
4
  import { Org } from './org';
4
5
  export declare enum RequestStatus {
5
6
  Pending = "Pending",
@@ -10,20 +11,27 @@ export declare enum RequestStatus {
10
11
  Canceling = "Canceling",
11
12
  Canceled = "Canceled"
12
13
  }
13
- export interface ObjectSetting extends JsonMap {
14
- sharingModel?: string;
15
- defaultRecordType?: string;
14
+ export interface SettingType {
15
+ members: string[];
16
+ name: 'CustomObject' | 'RecordType' | 'BusinessProcess' | 'Settings';
16
17
  }
17
- export interface BusinessProcessFileContent extends JsonMap {
18
- fullName: string;
19
- isActive: boolean;
20
- values: [
21
- {
22
- fullName: string;
23
- default?: boolean;
24
- }
25
- ];
18
+ export interface PackageFile {
19
+ '@': {
20
+ xmlns: string;
21
+ };
22
+ types: SettingType[];
23
+ version: string;
26
24
  }
25
+ export declare const createObjectFileContent: ({ allRecordTypes, allBusinessProcesses, apiVersion, settingData, objectSettingsData, }: {
26
+ allRecordTypes?: string[] | undefined;
27
+ allBusinessProcesses?: string[] | undefined;
28
+ apiVersion: string;
29
+ settingData?: Record<string, unknown> | undefined;
30
+ objectSettingsData?: {
31
+ [objectName: string]: ObjectSetting;
32
+ } | undefined;
33
+ }) => PackageFile;
34
+ export declare const createRecordTypeAndBusinessProcessFileContent: (objectName: string, json: Record<string, unknown>, allRecordTypes: string[], allBusinessProcesses: string[]) => JsonMap;
27
35
  /**
28
36
  * Helper class for dealing with the settings that are defined in a scratch definition file. This class knows how to extract the
29
37
  * settings from the definition, how to expand them into a MD directory and how to generate a package.xml.
@@ -33,10 +41,22 @@ export default class SettingsGenerator {
33
41
  private objectSettingsData?;
34
42
  private logger;
35
43
  private writer;
36
- private shapeDirName;
37
- constructor();
44
+ private allRecordTypes;
45
+ private allBusinessProcesses;
46
+ private readonly shapeDirName;
47
+ private readonly packageFilePath;
48
+ constructor(options?: {
49
+ mdApiTmpDir?: string;
50
+ shapeDirName?: string;
51
+ asDirectory?: boolean;
52
+ });
38
53
  /** extract the settings from the scratch def file, if they are present. */
39
- extract(scratchDef: ScratchOrgInfo): Promise<void>;
54
+ extract(scratchDef: ScratchOrgInfo): Promise<{
55
+ settings: Record<string, unknown> | undefined;
56
+ objectSettings: {
57
+ [objectName: string]: ObjectSetting;
58
+ } | undefined;
59
+ }>;
40
60
  /** True if we are currently tracking setting or object setting data. */
41
61
  hasSettings(): boolean;
42
62
  /** Create temporary deploy directory used to upload the scratch org shape.
@@ -46,11 +66,14 @@ export default class SettingsGenerator {
46
66
  /**
47
67
  * Deploys the settings to the org.
48
68
  */
49
- deploySettingsViaFolder(scratchOrg: Org, apiVersion: string): Promise<void>;
69
+ deploySettingsViaFolder(scratchOrg: Org, apiVersion: string, timeout?: Duration): Promise<void>;
70
+ createDeployPackageContents(apiVersion: string): Promise<void>;
71
+ getShapeDirName(): string;
72
+ /**
73
+ * Returns the destination where the writer placed the settings content.
74
+ *
75
+ */
76
+ getDestinationPath(): string | undefined;
50
77
  private writeObjectSettingsIfNeeded;
51
78
  private writeSettingsIfNeeded;
52
- private createPackageXml;
53
- private createObjectFileContent;
54
- private createRecordTypeFileContent;
55
- private createBusinessProcessFileContent;
56
79
  }