@salesforce/core 3.32.4 → 3.32.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/org/connection.d.ts +3 -1
- package/lib/org/connection.js +40 -34
- package/package.json +1 -1
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;
|