@diia-inhouse/env 2.8.25 → 3.3.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.
@@ -0,0 +1,3 @@
1
+ import { Env, GetSecretOps, GetTransitKeyOps, GetTransitKeyReadResult, GetTransitKeyResult, ProcessedTransitKey } from "./interfaces/index.js";
2
+ import { EnvService } from "./services/env.js";
3
+ export { Env, EnvService, GetSecretOps, GetTransitKeyOps, GetTransitKeyReadResult, GetTransitKeyResult, ProcessedTransitKey };
package/dist/index.js CHANGED
@@ -1,21 +1,8 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const dotenv_flow_1 = require("dotenv-flow");
18
- (0, dotenv_flow_1.config)({ silent: true });
19
- __exportStar(require("./interfaces"), exports);
20
- __exportStar(require("./services"), exports);
21
- //# sourceMappingURL=index.js.map
1
+ import { Env } from "./interfaces/index.js";
2
+ import { EnvService } from "./services/env.js";
3
+ import "./services/index.js";
4
+ import { config } from "dotenv-flow";
5
+ //#region src/index.ts
6
+ config({ silent: true });
7
+ //#endregion
8
+ export { Env, EnvService };
@@ -0,0 +1,30 @@
1
+ //#region src/interfaces/index.d.ts
2
+ declare enum Env {
3
+ Local = "local",
4
+ Test = "test",
5
+ Dev = "dev",
6
+ Sandbox = "sandbox",
7
+ Stage = "stage",
8
+ Prod = "prod"
9
+ }
10
+ interface GetSecretOps {
11
+ accessor?: string;
12
+ nullable?: boolean;
13
+ }
14
+ type GetTransitKeyResult = {
15
+ keys: Record<number, string>;
16
+ name: string;
17
+ type: string;
18
+ };
19
+ type GetTransitKeyReadResult = Record<string, unknown> & {
20
+ data: GetTransitKeyResult;
21
+ };
22
+ interface GetTransitKeyOps {
23
+ keyVersion?: string;
24
+ }
25
+ interface ProcessedTransitKey {
26
+ fullKeyName: string;
27
+ key: string;
28
+ }
29
+ //#endregion
30
+ export { Env, GetSecretOps, GetTransitKeyOps, GetTransitKeyReadResult, GetTransitKeyResult, ProcessedTransitKey };
@@ -1,13 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Env = void 0;
4
- var Env;
5
- (function (Env) {
6
- Env["Local"] = "local";
7
- Env["Test"] = "test";
8
- Env["Dev"] = "dev";
9
- Env["Sandbox"] = "sandbox";
10
- Env["Stage"] = "stage";
11
- Env["Prod"] = "prod";
12
- })(Env || (exports.Env = Env = {}));
13
- //# sourceMappingURL=index.js.map
1
+ //#region src/interfaces/index.ts
2
+ let Env = /* @__PURE__ */ function(Env) {
3
+ Env["Local"] = "local";
4
+ Env["Test"] = "test";
5
+ Env["Dev"] = "dev";
6
+ Env["Sandbox"] = "sandbox";
7
+ Env["Stage"] = "stage";
8
+ Env["Prod"] = "prod";
9
+ return Env;
10
+ }({});
11
+ //#endregion
12
+ export { Env };
@@ -1,6 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vaultRequestsTotalMetric = void 0;
4
- const diia_metrics_1 = require("@diia-inhouse/diia-metrics");
5
- exports.vaultRequestsTotalMetric = new diia_metrics_1.Counter('vault_requests_total', ['status', 'method']);
6
- //# sourceMappingURL=index.js.map
1
+ import { Counter } from "@diia-inhouse/diia-metrics";
2
+ //#region src/metrics/index.ts
3
+ const vaultRequestsTotalMetric = new Counter("vault_requests_total", ["status", "method"]);
4
+ //#endregion
5
+ export { vaultRequestsTotalMetric };
@@ -0,0 +1,38 @@
1
+ import { Env, GetSecretOps, GetTransitKeyOps, ProcessedTransitKey } from "../interfaces/index.js";
2
+ import { Logger, OnDestroy } from "@diia-inhouse/types";
3
+
4
+ //#region src/services/env.d.ts
5
+ declare class EnvService implements OnDestroy {
6
+ private logger;
7
+ private readonly kubernetesPath;
8
+ private readonly isVaultEnabled;
9
+ private readonly renewalLeaseLifetime;
10
+ private readonly renewalMaxDelay;
11
+ private readonly rawSecrets;
12
+ private vault;
13
+ constructor(logger: Logger);
14
+ static getVar(name: string, type: "boolean", defaultValue?: boolean | null): boolean;
15
+ static getVar(name: string, type: "number", defaultValue?: number | null): number;
16
+ static getVar(name: string, type?: "string", defaultValue?: string | null): string;
17
+ static getVar<T extends unknown[]>(name: string, type: "object", defaultValue?: T | null): T;
18
+ static getVar<T extends Record<string, unknown>>(name: string, type: "object", defaultValue?: T | null): T;
19
+ init(): Promise<void>;
20
+ onDestroy(): Promise<void>;
21
+ getSecret(envName: string, ops?: GetSecretOps): Promise<string>;
22
+ getTransitKey(keyId: string, ops?: GetTransitKeyOps): Promise<ProcessedTransitKey>;
23
+ isLocal(): boolean;
24
+ isTest(): boolean;
25
+ isSandbox(): boolean;
26
+ isStage(): boolean;
27
+ isDev(): boolean;
28
+ isProd(): boolean;
29
+ getEnv(): Env;
30
+ private renewToken;
31
+ private renewLease;
32
+ private scheduleTokenRenewal;
33
+ private scheduleLeaseRenewal;
34
+ private getRenewalDelay;
35
+ private revokeToken;
36
+ }
37
+ //#endregion
38
+ export { EnvService };
@@ -1,215 +1,202 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ import "../interfaces/index.js";
2
+ import { vaultRequestsTotalMetric } from "../metrics/index.js";
3
+ import { VaultClient } from "./vaultClient.js";
4
+ import fs from "node:fs/promises";
5
+ import { setTimeout as setTimeout$1 } from "node:timers/promises";
6
+ import get from "lodash.get";
7
+ import { DurationMs } from "@diia-inhouse/types";
8
+ //#region src/services/env.ts
9
+ var EnvService = class EnvService {
10
+ logger;
11
+ kubernetesPath = "kubernetes";
12
+ isVaultEnabled = EnvService.getVar("VAULT_ENABLED", "boolean", false);
13
+ renewalLeaseLifetime = EnvService.getVar("VAULT_RENEWAL_LEASE_LIFETIME", "number", .6);
14
+ renewalMaxDelay = EnvService.getVar("VAULT_RENEWAL_MAX_DELAY", "number", DurationMs.Minute);
15
+ rawSecrets = /* @__PURE__ */ new Map();
16
+ vault = null;
17
+ constructor(logger) {
18
+ this.logger = logger;
19
+ if (!this.isVaultEnabled) return;
20
+ this.vault = new VaultClient(EnvService.getVar("VAULT_ADDR"));
21
+ }
22
+ static getVar(name, type = "string", defaultValue) {
23
+ const value = process.env[name];
24
+ if (!value) {
25
+ if (defaultValue || defaultValue !== void 0) return defaultValue;
26
+ throw new Error(`Env variable ${name} is not defined`);
27
+ }
28
+ if (type === "string") return value;
29
+ try {
30
+ const parsedValue = JSON.parse(value);
31
+ if (typeof parsedValue !== type) throw new TypeError(`Unexpected typeof ${name} variable; Current typeof ${typeof parsedValue}`);
32
+ return parsedValue;
33
+ } catch (err) {
34
+ throw new Error(`Error while parsing ${name} variable. Current value: ${value}; ${String(err)}`, { cause: err });
35
+ }
36
+ }
37
+ async init() {
38
+ if (!this.vault) return;
39
+ try {
40
+ const tokenPath = EnvService.getVar("KUBERNETES_TOKEN_PATH", "string", "/var/run/secrets/kubernetes.io/serviceaccount/token");
41
+ const k8sToken = await fs.readFile(tokenPath, "utf8");
42
+ const { auth: { client_token: token, lease_duration: leaseDuration, accessor, service_account_name } } = await this.vault.kubernetesLogin({
43
+ jwt: k8sToken,
44
+ kubernetesPath: this.kubernetesPath,
45
+ role: EnvService.getVar("VAULT_ROLE")
46
+ });
47
+ this.logger = this.logger.child({ vaultServiceAccountName: service_account_name });
48
+ this.logger.info("Vault token accessor", { accessor });
49
+ this.vault.token = token;
50
+ this.scheduleTokenRenewal(leaseDuration);
51
+ } catch (err) {
52
+ this.logger.error("Failed to init vault", { err });
53
+ throw err;
54
+ }
55
+ }
56
+ async onDestroy() {
57
+ await this.revokeToken();
58
+ }
59
+ async getSecret(envName, ops = {}) {
60
+ const { accessor = `data.${envName}`, nullable } = ops;
61
+ const envValue = EnvService.getVar(envName, "string", nullable ? null : void 0);
62
+ if (!this.vault) return envValue;
63
+ const cachedRawSecret = this.rawSecrets.get(envValue);
64
+ if (cachedRawSecret) return get(cachedRawSecret, accessor);
65
+ try {
66
+ const { data, lease_id: leaseId, lease_duration: leaseDuration } = await this.vault.read(envValue);
67
+ if (leaseId) this.scheduleLeaseRenewal(leaseId, leaseDuration);
68
+ this.rawSecrets.set(envValue, data);
69
+ vaultRequestsTotalMetric.increment({
70
+ status: "success",
71
+ method: "get_secret"
72
+ });
73
+ return get(data, accessor);
74
+ } catch (err) {
75
+ vaultRequestsTotalMetric.increment({
76
+ status: "failure",
77
+ method: "get_secret"
78
+ });
79
+ this.logger.error("Failed to get vault secret", {
80
+ err,
81
+ envName,
82
+ envValue
83
+ });
84
+ throw err;
85
+ }
86
+ }
87
+ async getTransitKey(keyId, ops = {}) {
88
+ const { keyVersion } = ops;
89
+ if (!this.vault) throw new Error("Vault is not initialized. Failed to get transit key");
90
+ try {
91
+ const vaultPath = keyVersion ? `${keyId}/${keyVersion}` : keyId;
92
+ const { data } = await this.vault.read(vaultPath);
93
+ const highestKeyVersion = Object.keys(data.keys).sort((a, b) => Number(b) - Number(a))[0];
94
+ if (!highestKeyVersion) throw new Error(`No key versions found for key ${keyId}`);
95
+ const key = data.keys[Number(highestKeyVersion)];
96
+ return {
97
+ fullKeyName: `${keyId}/${highestKeyVersion}`,
98
+ key
99
+ };
100
+ } catch (err) {
101
+ this.logger.error("Failed to get transit key", {
102
+ err,
103
+ path: keyId
104
+ });
105
+ throw err;
106
+ }
107
+ }
108
+ isLocal() {
109
+ return this.getEnv() === "local";
110
+ }
111
+ isTest() {
112
+ return this.getEnv() === "test";
113
+ }
114
+ isSandbox() {
115
+ return this.getEnv() === "sandbox";
116
+ }
117
+ isStage() {
118
+ return this.getEnv() === "stage";
119
+ }
120
+ isDev() {
121
+ return this.getEnv() === "dev";
122
+ }
123
+ isProd() {
124
+ return this.getEnv() === "prod";
125
+ }
126
+ getEnv() {
127
+ return process.env.NODE_ENV;
128
+ }
129
+ async renewToken(retryDelay = DurationMs.Second) {
130
+ if (!this.vault) return;
131
+ this.logger.info("Start vault token renewing");
132
+ try {
133
+ const { auth: { lease_duration: leaseDuration } } = await this.vault.tokenRenewSelf();
134
+ this.scheduleTokenRenewal(leaseDuration);
135
+ vaultRequestsTotalMetric.increment({
136
+ status: "success",
137
+ method: "renew_token"
138
+ });
139
+ } catch (err) {
140
+ if (err instanceof Error && err.message.includes("permission denied")) {
141
+ this.logger.error("Vault token is revoked. Exiting", { err });
142
+ process.emit("SIGINT");
143
+ return;
144
+ }
145
+ vaultRequestsTotalMetric.increment({
146
+ status: "failure",
147
+ method: "renew_token"
148
+ });
149
+ if (retryDelay > this.renewalMaxDelay) retryDelay = this.renewalMaxDelay;
150
+ this.logger.error(`Failed to renew vault token. Retrying in ${retryDelay}ms`, { err });
151
+ await setTimeout$1(retryDelay, null, { ref: false });
152
+ await this.renewToken(retryDelay * 2);
153
+ }
154
+ }
155
+ async renewLease(leaseId, retryDelay = DurationMs.Second) {
156
+ if (!this.vault) return;
157
+ this.logger.info("Start vault lease renewing", { leaseId });
158
+ try {
159
+ const { lease_duration: leaseDuration } = await this.vault.write("sys/leases/renew", { lease_id: leaseId });
160
+ this.scheduleLeaseRenewal(leaseId, leaseDuration);
161
+ vaultRequestsTotalMetric.increment({
162
+ status: "success",
163
+ method: "renew_lease"
164
+ });
165
+ } catch (err) {
166
+ if (err instanceof Error && err.message.includes("lease not found")) {
167
+ this.logger.error("Vault lease is revoked. Exiting", {
168
+ err,
169
+ leaseId
170
+ });
171
+ process.emit("SIGINT");
172
+ return;
173
+ }
174
+ vaultRequestsTotalMetric.increment({
175
+ status: "failure",
176
+ method: "renew_lease"
177
+ });
178
+ this.logger.error(`Failed to renew vault lease. Retrying in ${retryDelay}ms`, {
179
+ err,
180
+ leaseId
181
+ });
182
+ if (retryDelay > this.renewalMaxDelay) retryDelay = this.renewalMaxDelay;
183
+ await setTimeout$1(retryDelay, null, { ref: false });
184
+ await this.renewLease(leaseId, retryDelay * 2);
185
+ }
186
+ }
187
+ scheduleTokenRenewal(leaseDuration) {
188
+ setTimeout(async () => await this.renewToken(), this.getRenewalDelay(leaseDuration)).unref();
189
+ }
190
+ scheduleLeaseRenewal(leaseId, leaseDuration) {
191
+ setTimeout(async () => await this.renewLease(leaseId), this.getRenewalDelay(leaseDuration)).unref();
192
+ }
193
+ getRenewalDelay(leaseDurationS) {
194
+ return leaseDurationS * DurationMs.Second * this.renewalLeaseLifetime;
195
+ }
196
+ async revokeToken() {
197
+ if (!this.vault) return;
198
+ await this.vault.tokenRevokeSelf();
199
+ }
4
200
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.EnvService = void 0;
7
- const promises_1 = __importDefault(require("node:fs/promises"));
8
- const promises_2 = require("node:timers/promises");
9
- const lodash_get_1 = __importDefault(require("lodash.get"));
10
- const types_1 = require("@diia-inhouse/types");
11
- const interfaces_1 = require("../interfaces");
12
- const metrics_1 = require("../metrics");
13
- const vaultClient_1 = require("./vaultClient");
14
- class EnvService {
15
- logger;
16
- kubernetesPath = 'kubernetes';
17
- isVaultEnabled = EnvService.getVar('VAULT_ENABLED', 'boolean', false);
18
- renewalLeaseLifetime = EnvService.getVar('VAULT_RENEWAL_LEASE_LIFETIME', 'number', 0.6);
19
- renewalMaxDelay = EnvService.getVar('VAULT_RENEWAL_MAX_DELAY', 'number', types_1.DurationMs.Minute);
20
- rawSecrets = new Map();
21
- vault = null;
22
- constructor(logger) {
23
- this.logger = logger;
24
- if (!this.isVaultEnabled) {
25
- return;
26
- }
27
- this.vault = new vaultClient_1.VaultClient(EnvService.getVar('VAULT_ADDR'));
28
- }
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- static getVar(name, type = 'string', defaultValue) {
31
- const value = process.env[name];
32
- if (!value) {
33
- if (defaultValue || defaultValue !== undefined) {
34
- return defaultValue;
35
- }
36
- throw new Error(`Env variable ${name} is not defined`);
37
- }
38
- if (type === 'string') {
39
- return value;
40
- }
41
- try {
42
- const parsedValue = JSON.parse(value);
43
- if (typeof parsedValue !== type) {
44
- throw new TypeError(`Unexpected typeof ${name} variable; Current typeof ${typeof parsedValue}`);
45
- }
46
- return parsedValue;
47
- }
48
- catch (err) {
49
- throw new Error(`Error while parsing ${name} variable. Current value: ${value}; ${err}`);
50
- }
51
- }
52
- async init() {
53
- if (!this.vault) {
54
- return;
55
- }
56
- try {
57
- const tokenPath = EnvService.getVar('KUBERNETES_TOKEN_PATH', 'string', '/var/run/secrets/kubernetes.io/serviceaccount/token');
58
- // eslint-disable-next-line security/detect-non-literal-fs-filename
59
- const k8sToken = await promises_1.default.readFile(tokenPath, 'utf8'); // nosemgrep: eslint.detect-non-literal-fs-filename
60
- const loginResult = await this.vault.kubernetesLogin({
61
- jwt: k8sToken,
62
- kubernetesPath: this.kubernetesPath,
63
- role: EnvService.getVar('VAULT_ROLE'),
64
- });
65
- const { auth: { client_token: token, lease_duration: leaseDuration, accessor, service_account_name }, } = loginResult;
66
- this.logger = this.logger.child({ vaultServiceAccountName: service_account_name });
67
- this.logger.info('Vault token accessor', { accessor });
68
- this.vault.token = token;
69
- this.scheduleTokenRenewal(leaseDuration);
70
- }
71
- catch (err) {
72
- this.logger.error('Failed to init vault', { err });
73
- throw err;
74
- }
75
- }
76
- async onDestroy() {
77
- await this.revokeToken();
78
- }
79
- async getSecret(envName, ops = {}) {
80
- const { accessor = `data.${envName}`, nullable } = ops;
81
- const envValue = EnvService.getVar(envName, 'string', nullable ? null : undefined);
82
- if (!this.vault) {
83
- return envValue;
84
- }
85
- const cachedRawSecret = this.rawSecrets.get(envValue);
86
- if (cachedRawSecret) {
87
- return (0, lodash_get_1.default)(cachedRawSecret, accessor);
88
- }
89
- try {
90
- const result = await this.vault.read(envValue);
91
- const { data, lease_id: leaseId, lease_duration: leaseDuration } = result;
92
- if (leaseId) {
93
- this.scheduleLeaseRenewal(leaseId, leaseDuration);
94
- }
95
- this.rawSecrets.set(envValue, data);
96
- metrics_1.vaultRequestsTotalMetric.increment({ status: 'success', method: 'get_secret' });
97
- return (0, lodash_get_1.default)(data, accessor);
98
- }
99
- catch (err) {
100
- metrics_1.vaultRequestsTotalMetric.increment({ status: 'failure', method: 'get_secret' });
101
- this.logger.error('Failed to get vault secret', { err, envName, envValue });
102
- throw err;
103
- }
104
- }
105
- async getTransitKey(keyId, ops = {}) {
106
- const { keyVersion } = ops;
107
- if (!this.vault) {
108
- throw new Error('Vault is not initialized. Failed to get transit key');
109
- }
110
- try {
111
- const vaultPath = keyVersion ? `${keyId}/${keyVersion}` : keyId;
112
- const { data } = await this.vault.read(vaultPath);
113
- const keyVersions = Object.keys(data.keys);
114
- const highestKeyVersion = keyVersions.sort((a, b) => Number(b) - Number(a))[0];
115
- if (!highestKeyVersion) {
116
- throw new Error(`No key versions found for key ${keyId}`);
117
- }
118
- const key = data.keys[Number(highestKeyVersion)];
119
- const fullKeyName = `${keyId}/${highestKeyVersion}`;
120
- return { fullKeyName, key };
121
- }
122
- catch (err) {
123
- this.logger.error('Failed to get transit key', { err, path: keyId });
124
- throw err;
125
- }
126
- }
127
- isLocal() {
128
- return this.getEnv() === interfaces_1.Env.Local;
129
- }
130
- isTest() {
131
- return this.getEnv() === interfaces_1.Env.Test;
132
- }
133
- isSandbox() {
134
- return this.getEnv() === interfaces_1.Env.Sandbox;
135
- }
136
- isStage() {
137
- return this.getEnv() === interfaces_1.Env.Stage;
138
- }
139
- isDev() {
140
- return this.getEnv() === interfaces_1.Env.Dev;
141
- }
142
- isProd() {
143
- return this.getEnv() === interfaces_1.Env.Prod;
144
- }
145
- getEnv() {
146
- return process.env.NODE_ENV;
147
- }
148
- async renewToken(retryDelay = types_1.DurationMs.Second) {
149
- if (!this.vault) {
150
- return;
151
- }
152
- this.logger.info('Start vault token renewing');
153
- try {
154
- const { auth: { lease_duration: leaseDuration }, } = await this.vault.tokenRenewSelf();
155
- this.scheduleTokenRenewal(leaseDuration);
156
- metrics_1.vaultRequestsTotalMetric.increment({ status: 'success', method: 'renew_token' });
157
- }
158
- catch (err) {
159
- if (err instanceof Error && err.message.includes('permission denied')) {
160
- this.logger.error('Vault token is revoked. Exiting', { err });
161
- process.emit('SIGINT');
162
- return;
163
- }
164
- metrics_1.vaultRequestsTotalMetric.increment({ status: 'failure', method: 'renew_token' });
165
- if (retryDelay > this.renewalMaxDelay) {
166
- retryDelay = this.renewalMaxDelay;
167
- }
168
- this.logger.error(`Failed to renew vault token. Retrying in ${retryDelay}ms`, { err });
169
- await (0, promises_2.setTimeout)(retryDelay, null, { ref: false });
170
- await this.renewToken(retryDelay * 2);
171
- }
172
- }
173
- async renewLease(leaseId, retryDelay = types_1.DurationMs.Second) {
174
- if (!this.vault) {
175
- return;
176
- }
177
- this.logger.info('Start vault lease renewing', { leaseId });
178
- try {
179
- const { lease_duration: leaseDuration } = await this.vault.write('sys/leases/renew', { lease_id: leaseId });
180
- this.scheduleLeaseRenewal(leaseId, leaseDuration);
181
- metrics_1.vaultRequestsTotalMetric.increment({ status: 'success', method: 'renew_lease' });
182
- }
183
- catch (err) {
184
- if (err instanceof Error && err.message.includes('lease not found')) {
185
- this.logger.error('Vault lease is revoked. Exiting', { err, leaseId });
186
- process.emit('SIGINT');
187
- return;
188
- }
189
- metrics_1.vaultRequestsTotalMetric.increment({ status: 'failure', method: 'renew_lease' });
190
- this.logger.error(`Failed to renew vault lease. Retrying in ${retryDelay}ms`, { err, leaseId });
191
- if (retryDelay > this.renewalMaxDelay) {
192
- retryDelay = this.renewalMaxDelay;
193
- }
194
- await (0, promises_2.setTimeout)(retryDelay, null, { ref: false });
195
- await this.renewLease(leaseId, retryDelay * 2);
196
- }
197
- }
198
- scheduleTokenRenewal(leaseDuration) {
199
- setTimeout(async () => await this.renewToken(), this.getRenewalDelay(leaseDuration)).unref();
200
- }
201
- scheduleLeaseRenewal(leaseId, leaseDuration) {
202
- setTimeout(async () => await this.renewLease(leaseId), this.getRenewalDelay(leaseDuration)).unref();
203
- }
204
- getRenewalDelay(leaseDurationS) {
205
- return leaseDurationS * types_1.DurationMs.Second * this.renewalLeaseLifetime;
206
- }
207
- async revokeToken() {
208
- if (!this.vault) {
209
- return;
210
- }
211
- await this.vault.tokenRevokeSelf();
212
- }
213
- }
214
- exports.EnvService = EnvService;
215
- //# sourceMappingURL=env.js.map
201
+ //#endregion
202
+ export { EnvService };
@@ -0,0 +1 @@
1
+ import { EnvService } from "./env.js";
@@ -1,18 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./env"), exports);
18
- //# sourceMappingURL=index.js.map
1
+ import "./env.js";
2
+ export {};
@@ -1,56 +1,48 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultClient = void 0;
4
- class VaultClient {
5
- endpoint;
6
- token = null;
7
- constructor(endpoint) {
8
- this.endpoint = endpoint;
9
- }
10
- async kubernetesLogin(opts) {
11
- return await this.request('POST', `auth/${opts.kubernetesPath}/login`, {
12
- jwt: opts.jwt,
13
- role: opts.role,
14
- });
15
- }
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- async read(path) {
18
- return await this.request('GET', path);
19
- }
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- async write(path, body) {
22
- return await this.request('POST', path, body);
23
- }
24
- async tokenRenewSelf() {
25
- return await this.request('POST', 'auth/token/renew-self');
26
- }
27
- async tokenRevokeSelf() {
28
- return await this.request('POST', 'auth/token/revoke-self');
29
- }
30
- async request(method, path, body) {
31
- const url = `${this.endpoint}/v1/${path}`;
32
- const res = await fetch(url, {
33
- method,
34
- headers: this.getHeaders(body !== undefined),
35
- body: body === undefined ? undefined : JSON.stringify(body),
36
- });
37
- const json = res.status === 204 ? null : await res.json();
38
- if (!res.ok) {
39
- const msg = json?.errors?.[0] ?? res.statusText;
40
- throw new Error(msg);
41
- }
42
- return json;
43
- }
44
- getHeaders(hasBody) {
45
- const h = {};
46
- if (this.token) {
47
- h['X-Vault-Token'] = this.token;
48
- }
49
- if (hasBody) {
50
- h['Content-Type'] = 'application/json';
51
- }
52
- return h;
53
- }
54
- }
55
- exports.VaultClient = VaultClient;
56
- //# sourceMappingURL=vaultClient.js.map
1
+ //#region src/services/vaultClient.ts
2
+ var VaultClient = class {
3
+ endpoint;
4
+ token = null;
5
+ constructor(endpoint) {
6
+ this.endpoint = endpoint;
7
+ }
8
+ async kubernetesLogin(opts) {
9
+ return await this.request("POST", `auth/${opts.kubernetesPath}/login`, {
10
+ jwt: opts.jwt,
11
+ role: opts.role
12
+ });
13
+ }
14
+ async read(path) {
15
+ return await this.request("GET", path);
16
+ }
17
+ async write(path, body) {
18
+ return await this.request("POST", path, body);
19
+ }
20
+ async tokenRenewSelf() {
21
+ return await this.request("POST", "auth/token/renew-self");
22
+ }
23
+ async tokenRevokeSelf() {
24
+ return await this.request("POST", "auth/token/revoke-self");
25
+ }
26
+ async request(method, path, body) {
27
+ const url = `${this.endpoint}/v1/${path}`;
28
+ const res = await fetch(url, {
29
+ method,
30
+ headers: this.getHeaders(body !== void 0),
31
+ body: body === void 0 ? void 0 : JSON.stringify(body)
32
+ });
33
+ const json = res.status === 204 ? null : await res.json();
34
+ if (!res.ok) {
35
+ const msg = json?.errors?.[0] ?? res.statusText;
36
+ throw new Error(msg);
37
+ }
38
+ return json;
39
+ }
40
+ getHeaders(hasBody) {
41
+ const h = {};
42
+ if (this.token) h["X-Vault-Token"] = this.token;
43
+ if (hasBody) h["Content-Type"] = "application/json";
44
+ return h;
45
+ }
46
+ };
47
+ //#endregion
48
+ export { VaultClient };
package/package.json CHANGED
@@ -1,25 +1,32 @@
1
1
  {
2
2
  "name": "@diia-inhouse/env",
3
- "version": "2.8.25",
3
+ "version": "3.3.1",
4
+ "type": "module",
4
5
  "description": "Environment checking service",
5
6
  "main": "dist/index.js",
6
- "types": "dist/types/index.d.ts",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
7
15
  "repository": "https://github.com/diia-open-source/be-pkg-env",
8
16
  "author": "Diia",
9
- "license": "SEE LICENSE IN LICENSE.md",
10
17
  "files": [
11
18
  "dist"
12
19
  ],
13
20
  "engines": {
14
- "node": ">=22"
21
+ "node": ">=24"
15
22
  },
16
23
  "scripts": {
17
24
  "prebuild": "rimraf dist",
18
- "build": "tsc",
25
+ "build": "tsdown",
19
26
  "semantic-release": "semantic-release",
20
27
  "start": "npm run build && node dist/index.js",
21
- "lint": "eslint . && prettier --check .",
22
- "lint-fix": "eslint --fix . && prettier --write .",
28
+ "lint": "oxlint && oxfmt --check .",
29
+ "lint-fix": "oxlint --fix && oxfmt .",
23
30
  "lint:lockfile": "lockfile-lint --path package-lock.json --allowed-hosts registry.npmjs.org --validate-https",
24
31
  "prepare": "npm run build",
25
32
  "test": "vitest run",
@@ -27,30 +34,33 @@
27
34
  "find-circulars": "madge --circular --extensions ts ./"
28
35
  },
29
36
  "dependencies": {
30
- "@diia-inhouse/diia-metrics": "6.5.38",
37
+ "@diia-inhouse/diia-metrics": "7.1.5",
31
38
  "dotenv-flow": "4.1.0",
32
39
  "lodash.get": "4.4.2"
33
40
  },
34
41
  "devDependencies": {
35
- "@diia-inhouse/configs": "6.1.1",
36
- "@diia-inhouse/diia-logger": "3.20.13",
37
- "@diia-inhouse/errors": "1.18.23",
38
- "@diia-inhouse/eslint-config": "8.8.2",
39
- "@diia-inhouse/test": "7.3.24",
40
- "@diia-inhouse/types": "12.0.5",
42
+ "@diia-inhouse/configs": "7.0.0",
43
+ "@diia-inhouse/diia-logger": "4.2.4",
44
+ "@diia-inhouse/errors": "2.1.1",
45
+ "@diia-inhouse/oxc-config": "1.10.0",
46
+ "@diia-inhouse/test": "8.2.1",
47
+ "@diia-inhouse/types": "13.2.0",
41
48
  "@types/dotenv-flow": "3.3.3",
42
49
  "@types/lodash.get": "4.4.9",
43
- "@vitest/coverage-v8": "4.0.18",
44
- "@vitest/ui": "4.0.18",
45
- "eslint": "9.39.2",
46
- "lockfile-lint": "4.14.1",
50
+ "@vitest/coverage-v8": "4.1.5",
51
+ "@vitest/ui": "4.1.5",
52
+ "lockfile-lint": "5.0.0",
47
53
  "madge": "8.0.0",
54
+ "oxfmt": "0.48.0",
55
+ "oxlint": "1.63.0",
56
+ "oxlint-tsgolint": "0.22.1",
48
57
  "rimraf": "6.1.3",
58
+ "tsdown": "0.22.0",
49
59
  "vite-tsconfig-paths": "6.1.1",
50
- "vitest": "4.0.18"
60
+ "vitest": "4.1.5"
51
61
  },
52
62
  "peerDependencies": {
53
- "@diia-inhouse/types": ">=4.4.1"
63
+ "@diia-inhouse/types": ">=13.1.1"
54
64
  },
55
65
  "release": {
56
66
  "extends": "@diia-inhouse/configs/dist/semantic-release/package",
@@ -61,11 +71,8 @@
61
71
  "commitlint": {
62
72
  "extends": "@diia-inhouse/configs/dist/commitlint"
63
73
  },
64
- "jest": {
65
- "preset": "@diia-inhouse/configs/dist/jest"
66
- },
67
- "prettier": "@diia-inhouse/eslint-config/prettier",
68
74
  "madge": {
69
75
  "tsConfig": "./tsconfig.json"
70
- }
76
+ },
77
+ "license": "SEE LICENSE IN LICENSE.md"
71
78
  }
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAAoC;AAEpC,IAAA,oBAAM,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;AAExB,+CAA4B;AAE5B,6CAA0B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,IAAY,GAOX;AAPD,WAAY,GAAG;IACX,sBAAe,CAAA;IACf,oBAAa,CAAA;IACb,kBAAW,CAAA;IACX,0BAAmB,CAAA;IACnB,sBAAe,CAAA;IACf,oBAAa,CAAA;AACjB,CAAC,EAPW,GAAG,mBAAH,GAAG,QAOd"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/metrics/index.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":";;;AAEA,6DAAoD;AAEvC,QAAA,wBAAwB,GAAG,IAAI,sBAAO,CAA8B,sBAAsB,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/services/env.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAiC;AACjC,mDAA0D;AAE1D,4DAA4B;AAE5B,+CAAmE;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AAoB,CAAC,aAAqB;QAC9C,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,EAAE,CAAA;IAChG,CAAC;IAEO,oBAAoB,CAAC,OAAe,EAAE,aAAqB;QAC/D,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,EAAE,CAAA;IACvG,CAAC;IAEO,eAAe,CAAC,cAAsB;QAC1C,OAAO,cAAc,GAAG,kBAAU,CAAC,MAAM,GAAG,IAAI,CAAC,oBAAoB,CAAA;IACzE,CAAC;IAEO,KAAK,CAAC,WAAW;QACrB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACd,OAAM;QACV,CAAC;QAED,MAAM,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAA;IACtC,CAAC;CACJ;AAnQD,gCAmQC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAqB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"vaultClient.js","sourceRoot":"","sources":["../../src/services/vaultClient.ts"],"names":[],"mappings":";;;AAAA,MAAa,WAAW;IAGS;IAF7B,KAAK,GAAkB,IAAI,CAAA;IAE3B,YAA6B,QAAgB;QAAhB,aAAQ,GAAR,QAAQ,CAAQ;IAAG,CAAC;IAEjD,KAAK,CAAC,eAAe,CAAC,IAA2D;QAQ7E,OAAO,MAAM,IAAI,CAAC,OAAO,CAOtB,MAAM,EAAE,QAAQ,IAAI,CAAC,cAAc,QAAQ,EAAE;YAC5C,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;SAClB,CA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AK,CAAC,GAAG,CAAC,CAAA;QACxB,CAAC;QAED,OAAO,IAAS,CAAA;IACpB,CAAC;IAEO,UAAU,CAAC,OAAgB;QAC/B,MAAM,CAAC,GAA2B,EAAE,CAAA;QAEpC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,CAAC,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;QACnC,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACV,CAAC,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAA;QAC1C,CAAC;QAED,OAAO,CAAC,CAAA;IACZ,CAAC;CACJ;AA1ED,kCA0EC"}
@@ -1,2 +0,0 @@
1
- export * from './interfaces';
2
- export * from './services';
@@ -1,27 +0,0 @@
1
- export declare enum Env {
2
- Local = "local",
3
- Test = "test",
4
- Dev = "dev",
5
- Sandbox = "sandbox",
6
- Stage = "stage",
7
- Prod = "prod"
8
- }
9
- export interface GetSecretOps {
10
- accessor?: string;
11
- nullable?: boolean;
12
- }
13
- export type GetTransitKeyResult = {
14
- keys: Record<number, string>;
15
- name: string;
16
- type: string;
17
- };
18
- export type GetTransitKeyReadResult = Record<string, unknown> & {
19
- data: GetTransitKeyResult;
20
- };
21
- export interface GetTransitKeyOps {
22
- keyVersion?: string;
23
- }
24
- export interface ProcessedTransitKey {
25
- fullKeyName: string;
26
- key: string;
27
- }
@@ -1,4 +0,0 @@
1
- export interface VaultRequestsTotalLabelsMap {
2
- status: 'success' | 'failure';
3
- method: 'renew_token' | 'get_secret' | 'renew_lease';
4
- }
@@ -1,3 +0,0 @@
1
- import { VaultRequestsTotalLabelsMap } from 'src/interfaces/metrics';
2
- import { Counter } from '@diia-inhouse/diia-metrics';
3
- export declare const vaultRequestsTotalMetric: Counter<VaultRequestsTotalLabelsMap>;
@@ -1,34 +0,0 @@
1
- import { Logger, OnDestroy } from '@diia-inhouse/types';
2
- import { Env, GetSecretOps, GetTransitKeyOps, ProcessedTransitKey } from '../interfaces';
3
- export declare class EnvService implements OnDestroy {
4
- private logger;
5
- private readonly kubernetesPath;
6
- private readonly isVaultEnabled;
7
- private readonly renewalLeaseLifetime;
8
- private readonly renewalMaxDelay;
9
- private readonly rawSecrets;
10
- private vault;
11
- constructor(logger: Logger);
12
- static getVar(name: string, type: 'boolean', defaultValue?: boolean | null): boolean;
13
- static getVar(name: string, type: 'number', defaultValue?: number | null): number;
14
- static getVar(name: string, type?: 'string', defaultValue?: string | null): string;
15
- static getVar<T extends unknown[]>(name: string, type: 'object', defaultValue?: T | null): T;
16
- static getVar<T extends Record<string, unknown>>(name: string, type: 'object', defaultValue?: T | null): T;
17
- init(): Promise<void>;
18
- onDestroy(): Promise<void>;
19
- getSecret(envName: string, ops?: GetSecretOps): Promise<string>;
20
- getTransitKey(keyId: string, ops?: GetTransitKeyOps): Promise<ProcessedTransitKey>;
21
- isLocal(): boolean;
22
- isTest(): boolean;
23
- isSandbox(): boolean;
24
- isStage(): boolean;
25
- isDev(): boolean;
26
- isProd(): boolean;
27
- getEnv(): Env;
28
- private renewToken;
29
- private renewLease;
30
- private scheduleTokenRenewal;
31
- private scheduleLeaseRenewal;
32
- private getRenewalDelay;
33
- private revokeToken;
34
- }
@@ -1 +0,0 @@
1
- export * from './env';
@@ -1,27 +0,0 @@
1
- export declare class VaultClient {
2
- private readonly endpoint;
3
- token: string | null;
4
- constructor(endpoint: string);
5
- kubernetesLogin(opts: {
6
- jwt: string;
7
- role: string;
8
- kubernetesPath: string;
9
- }): Promise<{
10
- auth: {
11
- client_token: string;
12
- lease_duration: number;
13
- accessor: string;
14
- service_account_name: string;
15
- };
16
- }>;
17
- read(path: string): Promise<any>;
18
- write(path: string, body: Record<string, unknown>): Promise<any>;
19
- tokenRenewSelf(): Promise<{
20
- auth: {
21
- lease_duration: number;
22
- };
23
- }>;
24
- tokenRevokeSelf(): Promise<void>;
25
- private request;
26
- private getHeaders;
27
- }