@salesforce/core 3.32.4 → 3.32.6
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.
package/lib/org/authInfo.d.ts
CHANGED
|
@@ -86,8 +86,7 @@ export declare type ConnectionOptions = AuthFields & {
|
|
|
86
86
|
};
|
|
87
87
|
export declare const DEFAULT_CONNECTED_APP_INFO: {
|
|
88
88
|
clientId: string;
|
|
89
|
-
|
|
90
|
-
legacyClientSecret: string;
|
|
89
|
+
clientSecret: string;
|
|
91
90
|
};
|
|
92
91
|
/**
|
|
93
92
|
* Handles persistence and fetching of user authentication information using
|
package/lib/org/authInfo.js
CHANGED
|
@@ -55,15 +55,7 @@ function parseIdUrl(idUrl) {
|
|
|
55
55
|
}
|
|
56
56
|
exports.DEFAULT_CONNECTED_APP_INFO = {
|
|
57
57
|
clientId: 'PlatformCLI',
|
|
58
|
-
|
|
59
|
-
// creates new AuthInfos. Currently that is the auth:* commands which
|
|
60
|
-
// aren't owned by this core library. These values need to be here
|
|
61
|
-
// for any old auth files where the id and secret aren't stored.
|
|
62
|
-
//
|
|
63
|
-
// Ideally, this would be removed at some point in the distant future
|
|
64
|
-
// when all auth files now have the clientId stored in it.
|
|
65
|
-
legacyClientId: 'SalesforceDevelopmentExperience',
|
|
66
|
-
legacyClientSecret: '1384510088588713504',
|
|
58
|
+
clientSecret: '',
|
|
67
59
|
};
|
|
68
60
|
/**
|
|
69
61
|
* Handles persistence and fetching of user authentication information using
|
|
@@ -398,7 +390,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
398
390
|
return opts;
|
|
399
391
|
}
|
|
400
392
|
getClientId() {
|
|
401
|
-
return this.getFields()?.clientId ?? exports.DEFAULT_CONNECTED_APP_INFO.
|
|
393
|
+
return this.getFields()?.clientId ?? exports.DEFAULT_CONNECTED_APP_INFO.clientId;
|
|
402
394
|
}
|
|
403
395
|
getRedirectUri() {
|
|
404
396
|
return 'http://localhost:1717/OauthRedirect';
|
|
@@ -729,8 +721,8 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
729
721
|
// Ideally, this would be removed at some point in the distant future when all auth files
|
|
730
722
|
// now have the clientId stored in it.
|
|
731
723
|
if (!options.clientId) {
|
|
732
|
-
options.clientId = exports.DEFAULT_CONNECTED_APP_INFO.
|
|
733
|
-
options.clientSecret = exports.DEFAULT_CONNECTED_APP_INFO.
|
|
724
|
+
options.clientId = exports.DEFAULT_CONNECTED_APP_INFO.clientId;
|
|
725
|
+
options.clientSecret = exports.DEFAULT_CONNECTED_APP_INFO.clientSecret;
|
|
734
726
|
}
|
|
735
727
|
if (!options.redirectUri) {
|
|
736
728
|
options.redirectUri = this.getRedirectUri();
|
package/lib/org/connection.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export declare class Connection<S extends Schema = Schema> extends JSForceConnec
|
|
|
40
40
|
private logger;
|
|
41
41
|
private options;
|
|
42
42
|
private username;
|
|
43
|
+
private hasResolved;
|
|
44
|
+
private maxApiVersion;
|
|
43
45
|
/**
|
|
44
46
|
* Constructor
|
|
45
47
|
* **Do not directly construct instances of this class -- use {@link Connection.create} instead.**
|
|
@@ -164,7 +166,7 @@ export declare class Connection<S extends Schema = Schema> extends JSForceConnec
|
|
|
164
166
|
* Useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes
|
|
165
167
|
*/
|
|
166
168
|
refreshAuth(): Promise<void>;
|
|
167
|
-
private
|
|
169
|
+
private getCachedApiVersion;
|
|
168
170
|
}
|
|
169
171
|
export declare const SingleRecordQueryErrors: {
|
|
170
172
|
NoRecords: string;
|
package/lib/org/connection.js
CHANGED
|
@@ -59,6 +59,8 @@ class Connection extends jsforce_1.Connection {
|
|
|
59
59
|
*/
|
|
60
60
|
constructor(options) {
|
|
61
61
|
super(options.connectionOptions ?? {});
|
|
62
|
+
// Save whether we've successfully resolved this connection's instance URL.
|
|
63
|
+
this.hasResolved = false;
|
|
62
64
|
this.options = options;
|
|
63
65
|
this.username = options.authInfo.getUsername();
|
|
64
66
|
}
|
|
@@ -93,10 +95,7 @@ class Connection extends jsforce_1.Connection {
|
|
|
93
95
|
try {
|
|
94
96
|
// No version passed in or in the config, so load one.
|
|
95
97
|
if (!baseOptions.version) {
|
|
96
|
-
|
|
97
|
-
if (cachedVersion) {
|
|
98
|
-
conn.setApiVersion(cachedVersion);
|
|
99
|
-
}
|
|
98
|
+
await conn.useLatestApiVersion();
|
|
100
99
|
}
|
|
101
100
|
else {
|
|
102
101
|
conn.logger.debug(`The org-api-version ${baseOptions.version} was found from ${options.connectionOptions?.version ? 'passed in options' : 'config'}`);
|
|
@@ -109,7 +108,7 @@ class Connection extends jsforce_1.Connection {
|
|
|
109
108
|
}
|
|
110
109
|
conn.logger.debug(`Error trying to load the API version: ${e.name} - ${e.message}`);
|
|
111
110
|
}
|
|
112
|
-
conn.logger.debug(`
|
|
111
|
+
conn.logger.debug(`Connection created with apiVersion ${conn.getApiVersion()}`);
|
|
113
112
|
return conn;
|
|
114
113
|
}
|
|
115
114
|
/**
|
|
@@ -184,7 +183,12 @@ class Connection extends jsforce_1.Connection {
|
|
|
184
183
|
* Retrieves the highest api version that is supported by the target server instance.
|
|
185
184
|
*/
|
|
186
185
|
async retrieveMaxApiVersion() {
|
|
186
|
+
// Check saved value first, then cache.
|
|
187
|
+
if ((this.maxApiVersion ?? (this.maxApiVersion = this.getCachedApiVersion()))) {
|
|
188
|
+
return this.maxApiVersion;
|
|
189
|
+
}
|
|
187
190
|
await this.isResolvable();
|
|
191
|
+
this.logger.debug(`Fetching API versions supported for org: ${this.getUsername()}`);
|
|
188
192
|
const versions = await this.request(`${this.instanceUrl}/services/data`);
|
|
189
193
|
// if the server doesn't return a list of versions, it's possibly a instanceUrl issue where the local file is out of date.
|
|
190
194
|
if (!Array.isArray(versions)) {
|
|
@@ -192,8 +196,15 @@ class Connection extends jsforce_1.Connection {
|
|
|
192
196
|
throw messages.createError('noApiVersionsError');
|
|
193
197
|
}
|
|
194
198
|
this.logger.debug(`response for org versions: ${versions.map((item) => item.version).join(',')}`);
|
|
195
|
-
|
|
196
|
-
|
|
199
|
+
this.maxApiVersion = (0, ts_types_1.ensure)((0, kit_1.maxBy)(versions, (version) => version.version)).version;
|
|
200
|
+
// cache the max API version just fetched
|
|
201
|
+
await this.options.authInfo.save({
|
|
202
|
+
instanceApiVersion: this.maxApiVersion,
|
|
203
|
+
// This will get messed up if the user changes their local time on their machine.
|
|
204
|
+
// Not a big deal since it will just get updated sooner/later.
|
|
205
|
+
instanceApiVersionLastRetrieved: new Date().toLocaleString(),
|
|
206
|
+
});
|
|
207
|
+
return this.maxApiVersion;
|
|
197
208
|
}
|
|
198
209
|
/**
|
|
199
210
|
* Use the latest API version available on `this.instanceUrl`.
|
|
@@ -215,6 +226,9 @@ class Connection extends jsforce_1.Connection {
|
|
|
215
226
|
* Verify that instance has a reachable DNS entry, otherwise will throw error
|
|
216
227
|
*/
|
|
217
228
|
async isResolvable() {
|
|
229
|
+
if (this.hasResolved) {
|
|
230
|
+
return this.hasResolved;
|
|
231
|
+
}
|
|
218
232
|
if (!this.options.connectionOptions?.instanceUrl) {
|
|
219
233
|
throw messages.createError('noInstanceUrlError');
|
|
220
234
|
}
|
|
@@ -223,6 +237,7 @@ class Connection extends jsforce_1.Connection {
|
|
|
223
237
|
});
|
|
224
238
|
try {
|
|
225
239
|
await resolver.resolve();
|
|
240
|
+
this.hasResolved = true;
|
|
226
241
|
return true;
|
|
227
242
|
}
|
|
228
243
|
catch (e) {
|
|
@@ -345,10 +360,16 @@ class Connection extends jsforce_1.Connection {
|
|
|
345
360
|
};
|
|
346
361
|
await this.request(requestInfo);
|
|
347
362
|
}
|
|
348
|
-
|
|
363
|
+
getCachedApiVersion() {
|
|
364
|
+
// Exit early if the API version cache is disabled.
|
|
365
|
+
if (kit_1.env.getBoolean('SFDX_IGNORE_API_VERSION_CACHE', false)) {
|
|
366
|
+
this.logger.debug('Using latest API version since SFDX_IGNORE_API_VERSION_CACHE = true');
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
// Get API version cache data
|
|
349
370
|
const authFileFields = this.options.authInfo.getFields();
|
|
350
371
|
const lastCheckedDateString = authFileFields.instanceApiVersionLastRetrieved;
|
|
351
|
-
|
|
372
|
+
const version = authFileFields.instanceApiVersion;
|
|
352
373
|
let lastChecked;
|
|
353
374
|
try {
|
|
354
375
|
if (lastCheckedDateString && (0, ts_types_1.isString)(lastCheckedDateString)) {
|
|
@@ -358,35 +379,20 @@ class Connection extends jsforce_1.Connection {
|
|
|
358
379
|
catch (e) {
|
|
359
380
|
/* Do nothing, it will just request the version again */
|
|
360
381
|
}
|
|
361
|
-
//
|
|
362
|
-
|
|
363
|
-
// verifies DNS
|
|
364
|
-
await this.useLatestApiVersion();
|
|
365
|
-
version = this.getApiVersion();
|
|
366
|
-
await this.options.authInfo.save({
|
|
367
|
-
instanceApiVersion: version,
|
|
368
|
-
// This will get messed up if the user changes their local time on their machine.
|
|
369
|
-
// Not a big deal since it will just get updated sooner/later.
|
|
370
|
-
instanceApiVersionLastRetrieved: new Date().toLocaleString(),
|
|
371
|
-
});
|
|
372
|
-
};
|
|
373
|
-
const ignoreCache = kit_1.env.getBoolean('SFDX_IGNORE_API_VERSION_CACHE', false);
|
|
374
|
-
if (lastChecked && !ignoreCache) {
|
|
382
|
+
// Check if the cache has expired
|
|
383
|
+
if (lastChecked) {
|
|
375
384
|
const now = new Date();
|
|
376
385
|
const has24HoursPastSinceLastCheck = now.getTime() - lastChecked > kit_1.Duration.hours(24).milliseconds;
|
|
377
|
-
this.logger.debug(`
|
|
378
|
-
if (has24HoursPastSinceLastCheck) {
|
|
379
|
-
|
|
386
|
+
this.logger.debug(`API version cache last checked on ${lastCheckedDateString} (now is ${now.toLocaleString()})`);
|
|
387
|
+
if (!has24HoursPastSinceLastCheck && version) {
|
|
388
|
+
// return cached API version
|
|
389
|
+
this.logger.debug(`Using cached API version: ${version}`);
|
|
390
|
+
return version;
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
this.logger.debug('API version cache expired. Re-fetching latest.');
|
|
380
394
|
}
|
|
381
395
|
}
|
|
382
|
-
else {
|
|
383
|
-
this.logger.debug(`Using the latest because lastChecked=${lastChecked} and SFDX_IGNORE_API_VERSION_CACHE=${ignoreCache}`);
|
|
384
|
-
// No version found in the file (we never checked before)
|
|
385
|
-
// so get the latest.
|
|
386
|
-
await useLatest();
|
|
387
|
-
}
|
|
388
|
-
this.logger.debug(`Loaded latest org-api-version ${version}`);
|
|
389
|
-
return version;
|
|
390
396
|
}
|
|
391
397
|
}
|
|
392
398
|
exports.Connection = Connection;
|
|
@@ -15,11 +15,7 @@ const webOAuthServer_1 = require("../webOAuthServer");
|
|
|
15
15
|
const messages_1 = require("../messages");
|
|
16
16
|
const sfError_1 = require("../sfError");
|
|
17
17
|
const scratchOrgFeatureDeprecation_1 = require("./scratchOrgFeatureDeprecation");
|
|
18
|
-
const
|
|
19
|
-
clientId: 'PlatformCLI',
|
|
20
|
-
legacyClientId: 'SalesforceDevelopmentExperience',
|
|
21
|
-
legacyClientSecret: '1384510088588713504',
|
|
22
|
-
};
|
|
18
|
+
const authInfo_1 = require("./authInfo");
|
|
23
19
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
24
20
|
const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgInfoGenerator');
|
|
25
21
|
const SNAPSHOT_UNSUPPORTED_OPTIONS = [
|
|
@@ -156,7 +152,7 @@ const generateScratchOrgInfo = async ({ hubOrg, scratchOrgInfoPayload, nonamespa
|
|
|
156
152
|
// Use the Hub org's client ID value, if one wasn't provided to us, or the default
|
|
157
153
|
if (!scratchOrgInfoPayload.connectedAppConsumerKey) {
|
|
158
154
|
scratchOrgInfoPayload.connectedAppConsumerKey =
|
|
159
|
-
hubOrg.getConnection().getAuthInfoFields().clientId ??
|
|
155
|
+
hubOrg.getConnection().getAuthInfoFields().clientId ?? authInfo_1.DEFAULT_CONNECTED_APP_INFO.clientId;
|
|
160
156
|
}
|
|
161
157
|
if (!nonamespace && sfProject?.get('namespace')) {
|
|
162
158
|
scratchOrgInfoPayload.namespace = sfProject.get('namespace');
|