@digitraffic/common 2025.4.29-1 → 2025.5.5-1

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.
@@ -17,7 +17,9 @@ export declare class SecretHolder<Secret extends GenericSecret> {
17
17
  private readonly secretId;
18
18
  private readonly prefix;
19
19
  private readonly expectedKeys;
20
- private readonly secretCache;
20
+ private cachedSecret?;
21
+ private expirationTime;
22
+ private readonly ttl;
21
23
  constructor(secretId: string, prefix?: string, expectedKeys?: string[], configuration?: typeof DEFAULT_CONFIGURATION);
22
24
  private initSecret;
23
25
  static create<S extends GenericSecret>(prefix?: string, expectedKeys?: string[]): SecretHolder<S>;
@@ -2,9 +2,7 @@ import { getSecret } from "./secret.js";
2
2
  import { checkExpectedSecretKeys } from "./dbsecret.js";
3
3
  import { getEnvVariable } from "../../../utils/utils.js";
4
4
  import { logger } from "../dt-logger-default.js";
5
- import NodeTtl from "node-ttl";
6
5
  const DEFAULT_PREFIX = "";
7
- const DEFAULT_SECRET_KEY = "SECRET";
8
6
  const DEFAULT_CONFIGURATION = {
9
7
  ttl: 5 * 60, // timeout secrets in 5 minutes
10
8
  };
@@ -23,12 +21,15 @@ export class SecretHolder {
23
21
  secretId;
24
22
  prefix;
25
23
  expectedKeys;
26
- secretCache;
24
+ cachedSecret;
25
+ expirationTime;
26
+ ttl; // seconds
27
27
  constructor(secretId, prefix = "", expectedKeys = [], configuration = DEFAULT_CONFIGURATION) {
28
28
  this.secretId = secretId;
29
29
  this.prefix = prefix;
30
30
  this.expectedKeys = expectedKeys;
31
- this.secretCache = new NodeTtl(configuration);
31
+ this.expirationTime = new Date(0);
32
+ this.ttl = configuration.ttl;
32
33
  }
33
34
  async initSecret() {
34
35
  const secretValue = await getSecret(this.secretId);
@@ -36,7 +37,8 @@ export class SecretHolder {
36
37
  method: "SecretHolder.initSecret",
37
38
  message: "Refreshing secret " + this.secretId,
38
39
  });
39
- this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
40
+ this.cachedSecret = secretValue;
41
+ this.expirationTime = new Date(Date.now() + this.ttl * 1000);
40
42
  }
41
43
  static create(prefix = DEFAULT_PREFIX, expectedKeys = []) {
42
44
  return new SecretHolder(getEnvVariable("SECRET_ID"), prefix, expectedKeys);
@@ -67,11 +69,13 @@ export class SecretHolder {
67
69
  return parsed;
68
70
  }
69
71
  async getSecret() {
70
- const secret = this.secretCache.get(DEFAULT_SECRET_KEY);
71
- if (!secret) {
72
+ if (this.expirationTime.getTime() < Date.now()) {
72
73
  await this.initSecret();
73
74
  }
74
- return secret ?? this.secretCache.get(DEFAULT_SECRET_KEY);
75
+ if (this.cachedSecret === undefined) {
76
+ throw new Error("SecretHolder in illegal state");
77
+ }
78
+ return this.cachedSecret;
75
79
  }
76
80
  }
77
81
  //# sourceMappingURL=secret-holder.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2025.4.29-1",
3
+ "version": "2025.5.5-1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {
@@ -104,14 +104,14 @@
104
104
  "./dist/aws/runtime/digitraffic-integration-response": "./dist/aws/runtime/digitraffic-integration-response.js"
105
105
  },
106
106
  "peerDependencies": {
107
- "@aws-sdk/client-api-gateway": "^3.777.0",
108
- "@aws-sdk/client-s3": "^3.777.0",
109
- "@aws-sdk/client-secrets-manager": "^3.777.0",
110
- "@aws-sdk/client-sns": "^3.777.0",
111
- "@aws-sdk/lib-storage": "^3.777.0",
107
+ "@aws-sdk/client-api-gateway": "^3.799.0",
108
+ "@aws-sdk/client-s3": "^3.799.0",
109
+ "@aws-sdk/client-secrets-manager": "^3.799.0",
110
+ "@aws-sdk/client-sns": "^3.799.0",
111
+ "@aws-sdk/lib-storage": "^3.799.0",
112
112
  "@date-fns/tz": "1.2.0",
113
113
  "@smithy/fetch-http-handler": "5.0.2",
114
- "aws-cdk-lib": "^2.189.0",
114
+ "aws-cdk-lib": "^2.194.0",
115
115
  "change-case": "^5.4.4",
116
116
  "constructs": "~10.4.2",
117
117
  "date-fns": "~4.1.0",
@@ -119,39 +119,37 @@
119
119
  "geojson-validation": "^1.0.2",
120
120
  "ky": "^1.7.5",
121
121
  "lodash-es": "^4.17.21",
122
- "node-ttl": "^0.2.0",
123
- "pg-native": "^3.3.0",
122
+ "pg-native": "^3.4.5",
124
123
  "pg-promise": "^11.13.0",
125
- "pg-query-stream": "4.8.1",
126
- "zod": "^3.24.2"
124
+ "zod": "^3.24.3"
127
125
  },
128
126
  "devDependencies": {
129
- "@aws-sdk/client-api-gateway": "^3.777.0",
130
- "@aws-sdk/client-s3": "^3.777.0",
131
- "@aws-sdk/client-secrets-manager": "^3.777.0",
132
- "@aws-sdk/client-sns": "^3.777.0",
133
- "@aws-sdk/lib-storage": "^3.777.0",
127
+ "@aws-sdk/client-api-gateway": "^3.799.0",
128
+ "@aws-sdk/client-s3": "^3.800.0",
129
+ "@aws-sdk/client-secrets-manager": "^3.799.0",
130
+ "@aws-sdk/client-sns": "^3.799.0",
131
+ "@aws-sdk/lib-storage": "^3.800.0",
134
132
  "@date-fns/tz": "1.2.0",
135
133
  "@digitraffic/eslint-config": "^3.1.1",
136
134
  "@jest/globals": "^29.7.0",
137
135
  "@rushstack/eslint-config": "^3.7.1",
138
- "@rushstack/heft": "^0.71.1",
136
+ "@rushstack/heft": "^0.71.2",
139
137
  "@rushstack/heft-jest-plugin": "^0.15.3",
140
- "@rushstack/heft-lint-plugin": "^0.5.29",
141
- "@rushstack/heft-typescript-plugin": "^0.8.1",
138
+ "@rushstack/heft-lint-plugin": "^0.5.37",
139
+ "@rushstack/heft-typescript-plugin": "^0.8.2",
142
140
  "@smithy/fetch-http-handler": "5.0.2",
143
141
  "@smithy/types": "^4.2.0",
144
- "@types/aws-lambda": "8.10.148",
142
+ "@types/aws-lambda": "8.10.149",
145
143
  "@types/etag": "^1.8.3",
146
144
  "@types/geojson": "7946.0.16",
147
145
  "@types/geojson-validation": "^1.0.3",
148
146
  "@types/jest": "29.5.14",
149
147
  "@types/lodash-es": "4.17.12",
150
148
  "@types/madge": "5.0.3",
151
- "@types/node": "22.13.14",
149
+ "@types/node": "22.15.2",
152
150
  "@typescript-eslint/eslint-plugin": "~7.14.1",
153
151
  "@typescript-eslint/parser": "^7.18.0",
154
- "aws-cdk-lib": "^2.189.0",
152
+ "aws-cdk-lib": "^2.194.0",
155
153
  "aws-sdk": "^2.1692.0",
156
154
  "change-case": "^5.4.4",
157
155
  "constructs": "~10.4.2",
@@ -163,20 +161,18 @@
163
161
  "geojson-validation": "^1.0.2",
164
162
  "jest": "^29.7.0",
165
163
  "jest-junit": "^16.0.0",
166
- "ky": "^1.7.5",
167
- "lefthook": "^1.11.5",
164
+ "ky": "^1.8.1",
165
+ "lefthook": "^1.11.12",
168
166
  "lodash": "^4.17.21",
169
167
  "lodash-es": "^4.17.21",
170
168
  "madge": "^8.0.0",
171
- "node-ttl": "^0.2.0",
172
- "pg-native": "^3.3.0",
169
+ "pg-native": "^3.4.5",
173
170
  "pg-promise": "^11.13.0",
174
- "pg-query-stream": "4.8.1",
175
171
  "rimraf": "^6.0.1",
176
- "ts-jest": "^29.3.0",
177
- "typescript": "~5.6.3",
178
- "velocityjs": "^2.0.6",
179
- "zod": "^3.24.2"
172
+ "ts-jest": "^29.3.2",
173
+ "typescript": "~5.8.3",
174
+ "velocityjs": "^2.1.5",
175
+ "zod": "~3.24.3"
180
176
  },
181
177
  "scripts": {
182
178
  "build": "heft build --clean",