@salesforce/core 3.7.9 → 3.9.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.
- package/CHANGELOG.md +19 -0
- package/lib/config/ttlConfig.d.ts +32 -0
- package/lib/config/ttlConfig.js +54 -0
- package/lib/exported.d.ts +2 -1
- package/lib/exported.js +3 -1
- package/lib/org/authInfo.d.ts +13 -0
- package/lib/org/authInfo.js +18 -0
- package/lib/testSetup.d.ts +5 -1
- package/lib/testSetup.js +9 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [3.9.0](https://github.com/forcedotcom/sfdx-core/compare/v3.8.1...v3.9.0) (2022-03-21)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- add TTLConfig ([#538](https://github.com/forcedotcom/sfdx-core/issues/538)) ([e623241](https://github.com/forcedotcom/sfdx-core/commit/e623241c7e513778c8f179dde4dc16e603a3778c))
|
|
10
|
+
|
|
11
|
+
### [3.8.1](https://github.com/forcedotcom/sfdx-core/compare/v3.8.0...v3.8.1) (2022-03-18)
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
- adjust mock org test data to conform to v3 ([38faf50](https://github.com/forcedotcom/sfdx-core/commit/38faf5063931955066312c24b4188b12c40098a5))
|
|
16
|
+
- side effects function should not save when no changes ([#541](https://github.com/forcedotcom/sfdx-core/issues/541)) ([6bfb841](https://github.com/forcedotcom/sfdx-core/commit/6bfb84172fdf74882102b9ffc6e6fbfe58e6ffbc))
|
|
17
|
+
|
|
18
|
+
## [3.8.0](https://github.com/forcedotcom/sfdx-core/compare/v3.7.9...v3.8.0) (2022-03-09)
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
- add handle side effect function to authinfo ([64c78e7](https://github.com/forcedotcom/sfdx-core/commit/64c78e74bc5e1cfb748fd2d64e4b1e8fc1062bf6))
|
|
23
|
+
|
|
5
24
|
### [3.7.9](https://github.com/forcedotcom/sfdx-core/compare/v3.7.8...v3.7.9) (2022-03-04)
|
|
6
25
|
|
|
7
26
|
### Bug Fixes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Duration } from '@salesforce/kit';
|
|
2
|
+
import { JsonMap, Nullable } from '@salesforce/ts-types';
|
|
3
|
+
import { ConfigFile } from './configFile';
|
|
4
|
+
/**
|
|
5
|
+
* A Time To Live configuration file where each entry is timestamped and removed once the TTL has expired.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { Duration } from '@salesforce/kit';
|
|
9
|
+
* const config = await TTLConfig.create({
|
|
10
|
+
* isGlobal: false,
|
|
11
|
+
* ttl: Duration.days(1)
|
|
12
|
+
* });
|
|
13
|
+
*/
|
|
14
|
+
export declare class TTLConfig<T extends TTLConfig.Options, P extends JsonMap> extends ConfigFile<T, TTLConfig.Contents<P>> {
|
|
15
|
+
set(key: string, value: Partial<TTLConfig.Entry<P>>): void;
|
|
16
|
+
getLatestEntry(): Nullable<[string, TTLConfig.Entry<P>]>;
|
|
17
|
+
getLatestKey(): Nullable<string>;
|
|
18
|
+
isExpired(dateTime: number, value: P & {
|
|
19
|
+
timestamp: string;
|
|
20
|
+
}): boolean;
|
|
21
|
+
protected init(): Promise<void>;
|
|
22
|
+
private timestamp;
|
|
23
|
+
}
|
|
24
|
+
export declare namespace TTLConfig {
|
|
25
|
+
type Options = ConfigFile.Options & {
|
|
26
|
+
ttl: Duration;
|
|
27
|
+
};
|
|
28
|
+
type Entry<T extends JsonMap> = T & {
|
|
29
|
+
timestamp: string;
|
|
30
|
+
};
|
|
31
|
+
type Contents<T extends JsonMap> = Record<string, Entry<T>>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022, 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.TTLConfig = void 0;
|
|
10
|
+
const configFile_1 = require("./configFile");
|
|
11
|
+
/**
|
|
12
|
+
* A Time To Live configuration file where each entry is timestamped and removed once the TTL has expired.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { Duration } from '@salesforce/kit';
|
|
16
|
+
* const config = await TTLConfig.create({
|
|
17
|
+
* isGlobal: false,
|
|
18
|
+
* ttl: Duration.days(1)
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
class TTLConfig extends configFile_1.ConfigFile {
|
|
22
|
+
set(key, value) {
|
|
23
|
+
super.set(key, this.timestamp(value));
|
|
24
|
+
}
|
|
25
|
+
getLatestEntry() {
|
|
26
|
+
const entries = this.entries();
|
|
27
|
+
const sorted = entries.sort(([, valueA], [, valueB]) => {
|
|
28
|
+
return new Date(valueB.timestamp).getTime() - new Date(valueA.timestamp).getTime();
|
|
29
|
+
});
|
|
30
|
+
return sorted.length > 0 ? sorted[0] : null;
|
|
31
|
+
}
|
|
32
|
+
getLatestKey() {
|
|
33
|
+
const [key] = this.getLatestEntry() || [null];
|
|
34
|
+
return key;
|
|
35
|
+
}
|
|
36
|
+
isExpired(dateTime, value) {
|
|
37
|
+
return dateTime - new Date(value.timestamp).getTime() > this.options.ttl.milliseconds;
|
|
38
|
+
}
|
|
39
|
+
async init() {
|
|
40
|
+
const contents = await this.read(this.options.throwOnNotFound);
|
|
41
|
+
const purged = {};
|
|
42
|
+
const date = new Date().getTime();
|
|
43
|
+
for (const [key, opts] of Object.entries(contents)) {
|
|
44
|
+
if (!this.isExpired(date, opts))
|
|
45
|
+
purged[key] = opts;
|
|
46
|
+
}
|
|
47
|
+
this.setContents(purged);
|
|
48
|
+
}
|
|
49
|
+
timestamp(value) {
|
|
50
|
+
return { ...value, timestamp: new Date().toISOString() };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.TTLConfig = TTLConfig;
|
|
54
|
+
//# sourceMappingURL=ttlConfig.js.map
|
package/lib/exported.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { OAuth2Config } from 'jsforce';
|
|
2
2
|
export { ConfigFile } from './config/configFile';
|
|
3
|
+
export { TTLConfig } from './config/ttlConfig';
|
|
3
4
|
export { envVars, EnvironmentVariable, SUPPORTED_ENV_VARS, EnvVars } from './config/envVars';
|
|
4
5
|
export { BaseConfigStore, ConfigContents, ConfigEntry, ConfigStore, ConfigValue } from './config/configStore';
|
|
5
6
|
export { GlobalInfo, SfEntry, SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfToken, SfTokens } from './globalInfo';
|
|
@@ -7,7 +8,7 @@ export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } fro
|
|
|
7
8
|
export { OrgUsersConfig } from './config/orgUsersConfig';
|
|
8
9
|
export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config, SfdxPropertyKeys, SFDX_ALLOWED_PROPERTIES, } from './config/config';
|
|
9
10
|
export { ConfigInfo, ConfigAggregator } from './config/configAggregator';
|
|
10
|
-
export { AuthFields, AuthInfo, OrgAuthorization } from './org/authInfo';
|
|
11
|
+
export { AuthFields, AuthInfo, AuthSideEffects, OrgAuthorization } from './org/authInfo';
|
|
11
12
|
export { AuthRemover } from './org/authRemover';
|
|
12
13
|
export { Connection, SFDX_HTTP_HEADERS } from './org/connection';
|
|
13
14
|
export { Mode, Global } from './global';
|
package/lib/exported.js
CHANGED
|
@@ -16,11 +16,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SfError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.SfProjectJson = exports.SfProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = exports.OrgTypes = exports.SandboxEvents = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.AuthInfo = exports.ConfigAggregator = exports.SFDX_ALLOWED_PROPERTIES = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.ConfigFile = void 0;
|
|
19
|
+
exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SfError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.SfProjectJson = exports.SfProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = exports.OrgTypes = exports.SandboxEvents = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.AuthInfo = exports.ConfigAggregator = exports.SFDX_ALLOWED_PROPERTIES = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.TTLConfig = exports.ConfigFile = void 0;
|
|
20
20
|
const messages_1 = require("./messages");
|
|
21
21
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
22
22
|
var configFile_1 = require("./config/configFile");
|
|
23
23
|
Object.defineProperty(exports, "ConfigFile", { enumerable: true, get: function () { return configFile_1.ConfigFile; } });
|
|
24
|
+
var ttlConfig_1 = require("./config/ttlConfig");
|
|
25
|
+
Object.defineProperty(exports, "TTLConfig", { enumerable: true, get: function () { return ttlConfig_1.TTLConfig; } });
|
|
24
26
|
var envVars_1 = require("./config/envVars");
|
|
25
27
|
Object.defineProperty(exports, "envVars", { enumerable: true, get: function () { return envVars_1.envVars; } });
|
|
26
28
|
Object.defineProperty(exports, "EnvironmentVariable", { enumerable: true, get: function () { return envVars_1.EnvironmentVariable; } });
|
package/lib/org/authInfo.d.ts
CHANGED
|
@@ -59,6 +59,11 @@ export interface AccessTokenOptions {
|
|
|
59
59
|
loginUrl?: string;
|
|
60
60
|
instanceUrl?: string;
|
|
61
61
|
}
|
|
62
|
+
export declare type AuthSideEffects = {
|
|
63
|
+
alias: string;
|
|
64
|
+
setDefault: boolean;
|
|
65
|
+
setDefaultDevHub: boolean;
|
|
66
|
+
};
|
|
62
67
|
/**
|
|
63
68
|
* A function to update a refresh token when the access token is expired.
|
|
64
69
|
*/
|
|
@@ -225,6 +230,14 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
|
|
|
225
230
|
* **See** [SFDX Authorization](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_auth.htm#cli_reference_force_auth)
|
|
226
231
|
*/
|
|
227
232
|
getSfdxAuthUrl(): string;
|
|
233
|
+
/**
|
|
234
|
+
* Convenience function to handle typical side effects encountered when dealing with an AuthInfo.
|
|
235
|
+
* Given the values supplied in parameter sideEffects, this function will set auth alias, default auth
|
|
236
|
+
* and default dev hub.
|
|
237
|
+
*
|
|
238
|
+
* @param sideEffects - instance of AuthSideEffects
|
|
239
|
+
*/
|
|
240
|
+
handleAliasAndDefaultSettings(sideEffects: AuthSideEffects): Promise<void>;
|
|
228
241
|
/**
|
|
229
242
|
* Set the target-env (default) or the target-dev-hub to the alias if
|
|
230
243
|
* it exists otherwise to the username. Method will try to set the local
|
package/lib/org/authInfo.js
CHANGED
|
@@ -398,6 +398,24 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
398
398
|
sfdxAuthUrl += `${(0, ts_types_1.ensure)(decryptedFields.refreshToken, 'undefined refreshToken')}@${instanceUrl}`;
|
|
399
399
|
return sfdxAuthUrl;
|
|
400
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Convenience function to handle typical side effects encountered when dealing with an AuthInfo.
|
|
403
|
+
* Given the values supplied in parameter sideEffects, this function will set auth alias, default auth
|
|
404
|
+
* and default dev hub.
|
|
405
|
+
*
|
|
406
|
+
* @param sideEffects - instance of AuthSideEffects
|
|
407
|
+
*/
|
|
408
|
+
async handleAliasAndDefaultSettings(sideEffects) {
|
|
409
|
+
if (sideEffects.alias || sideEffects.setDefault || sideEffects.setDefaultDevHub) {
|
|
410
|
+
if (sideEffects.alias)
|
|
411
|
+
await this.setAlias(sideEffects.alias);
|
|
412
|
+
if (sideEffects.setDefault)
|
|
413
|
+
await this.setAsDefault({ org: true });
|
|
414
|
+
if (sideEffects.setDefaultDevHub)
|
|
415
|
+
await this.setAsDefault({ devHub: true });
|
|
416
|
+
await this.save();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
401
419
|
/**
|
|
402
420
|
* Set the target-env (default) or the target-dev-hub to the alias if
|
|
403
421
|
* it exists otherwise to the username. Method will try to set the local
|
package/lib/testSetup.d.ts
CHANGED
|
@@ -377,7 +377,8 @@ export declare class StreamingMockCometClient extends CometClient {
|
|
|
377
377
|
*/
|
|
378
378
|
export declare class MockTestOrgData {
|
|
379
379
|
testId: string;
|
|
380
|
-
|
|
380
|
+
aliases?: string[];
|
|
381
|
+
configs?: string[];
|
|
381
382
|
username: string;
|
|
382
383
|
devHubUsername?: string;
|
|
383
384
|
orgId: string;
|
|
@@ -390,6 +391,9 @@ export declare class MockTestOrgData {
|
|
|
390
391
|
refreshToken: string;
|
|
391
392
|
userId: string;
|
|
392
393
|
redirectUri: string;
|
|
394
|
+
isDevHub?: boolean;
|
|
395
|
+
isScratchOrg?: boolean;
|
|
396
|
+
isExpired?: boolean | 'unknown';
|
|
393
397
|
constructor(id?: string, options?: {
|
|
394
398
|
username: string;
|
|
395
399
|
});
|
package/lib/testSetup.js
CHANGED
|
@@ -493,12 +493,13 @@ class MockTestOrgData {
|
|
|
493
493
|
this.devHubUsername = username;
|
|
494
494
|
}
|
|
495
495
|
makeDevHub() {
|
|
496
|
-
|
|
496
|
+
this.isDevHub = true;
|
|
497
497
|
}
|
|
498
498
|
createUser(user) {
|
|
499
499
|
const userMock = new MockTestOrgData();
|
|
500
500
|
userMock.username = user;
|
|
501
|
-
userMock.
|
|
501
|
+
userMock.aliases = this.aliases;
|
|
502
|
+
userMock.configs = this.configs;
|
|
502
503
|
userMock.devHubUsername = this.devHubUsername;
|
|
503
504
|
userMock.orgId = this.orgId;
|
|
504
505
|
userMock.loginUrl = this.loginUrl;
|
|
@@ -506,6 +507,9 @@ class MockTestOrgData {
|
|
|
506
507
|
userMock.clientId = this.clientId;
|
|
507
508
|
userMock.clientSecret = this.clientSecret;
|
|
508
509
|
userMock.redirectUri = this.redirectUri;
|
|
510
|
+
userMock.isDevHub = this.isDevHub;
|
|
511
|
+
userMock.isScratchOrg = this.isScratchOrg;
|
|
512
|
+
userMock.isExpired = this.isExpired;
|
|
509
513
|
return userMock;
|
|
510
514
|
}
|
|
511
515
|
getMockUserInfo() {
|
|
@@ -513,7 +517,8 @@ class MockTestOrgData {
|
|
|
513
517
|
Id: this.userId,
|
|
514
518
|
Username: this.username,
|
|
515
519
|
LastName: `user_lastname_${this.testId}`,
|
|
516
|
-
Alias: this.
|
|
520
|
+
Alias: this.aliases ? this.aliases[0] : 'user_alias_blah',
|
|
521
|
+
Configs: this.configs,
|
|
517
522
|
TimeZoneSidKey: `user_timezonesidkey_${this.testId}`,
|
|
518
523
|
LocaleSidKey: `user_localesidkey_${this.testId}`,
|
|
519
524
|
EmailEncodingKey: `user_emailencodingkey_${this.testId}`,
|
|
@@ -540,14 +545,10 @@ class MockTestOrgData {
|
|
|
540
545
|
config.createdOrgInstance = 'CS1';
|
|
541
546
|
config.created = '1519163543003';
|
|
542
547
|
config.userId = this.userId;
|
|
543
|
-
// config.devHubUsername = 'tn@su-blitz.org';
|
|
544
548
|
if (this.devHubUsername) {
|
|
545
549
|
config.devHubUsername = this.devHubUsername;
|
|
546
550
|
}
|
|
547
|
-
|
|
548
|
-
if (isDevHub) {
|
|
549
|
-
config.isDevHub = isDevHub;
|
|
550
|
-
}
|
|
551
|
+
config.isDevHub = this.isDevHub;
|
|
551
552
|
return config;
|
|
552
553
|
}
|
|
553
554
|
}
|