@salesforce/core 3.8.1 → 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 CHANGED
@@ -2,6 +2,12 @@
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
+
5
11
  ### [3.8.1](https://github.com/forcedotcom/sfdx-core/compare/v3.8.0...v3.8.1) (2022-03-18)
6
12
 
7
13
  ### 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';
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.8.1",
3
+ "version": "3.9.0",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",