@justworkflowit/cdk-constructs 0.0.40 → 0.0.42
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.
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { JustWorkflowIt } from '@justworkflowit/api-client';
|
|
2
2
|
import { AssertiveClient } from '@smithy/types';
|
|
3
|
+
/**
|
|
4
|
+
* Fetch a secret value by its name from AWS Secrets Manager.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getSecretValueByName: (secretName: string) => Promise<string | undefined>;
|
|
3
7
|
export declare const getErrorMessage: (err: unknown) => string;
|
|
4
8
|
export declare const getApiClient: () => AssertiveClient<JustWorkflowIt>;
|
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getApiClient = exports.getErrorMessage = void 0;
|
|
3
|
+
exports.getApiClient = exports.getErrorMessage = exports.getSecretValueByName = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
const api_client_1 = require("@justworkflowit/api-client");
|
|
6
6
|
const justWorkflowItApiExceptions_1 = require("./justWorkflowItApiExceptions");
|
|
7
|
+
const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
|
|
7
8
|
const endpoint = process.env.API_BASE_URL;
|
|
9
|
+
// Helper to cache the client (no repeated instantiation)
|
|
10
|
+
let secretsManager;
|
|
11
|
+
const getSecretsManager = () => {
|
|
12
|
+
if (!secretsManager) {
|
|
13
|
+
secretsManager = new client_secrets_manager_1.SecretsManagerClient({});
|
|
14
|
+
}
|
|
15
|
+
return secretsManager;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Fetch a secret value by its name from AWS Secrets Manager.
|
|
19
|
+
*/
|
|
20
|
+
const getSecretValueByName = async (secretName) => {
|
|
21
|
+
const client = getSecretsManager();
|
|
22
|
+
const cmd = new client_secrets_manager_1.GetSecretValueCommand({ SecretId: secretName });
|
|
23
|
+
const resp = await client.send(cmd);
|
|
24
|
+
return resp.SecretString;
|
|
25
|
+
};
|
|
26
|
+
exports.getSecretValueByName = getSecretValueByName;
|
|
27
|
+
// Swap getAccessToken to use getSecretValueByName
|
|
8
28
|
const getAccessToken = async () => {
|
|
9
|
-
|
|
29
|
+
const secretName = process.env.AUTH_SECRET_NAME;
|
|
30
|
+
if (!secretName)
|
|
31
|
+
throw new Error("AUTH_SECRET_NAME env var not set");
|
|
32
|
+
const secret = await (0, exports.getSecretValueByName)(secretName);
|
|
33
|
+
if (!secret)
|
|
34
|
+
throw new Error("Could not fetch access token secret");
|
|
35
|
+
return secret;
|
|
10
36
|
};
|
|
11
37
|
const cognitoIdentityProviderFactory = (_config) => {
|
|
12
38
|
const identityProvider = async (_props) => {
|