@replayio/app-building 1.13.0 → 1.15.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/dist/secrets.d.ts +10 -9
- package/dist/secrets.js +27 -38
- package/package.json +1 -1
package/dist/secrets.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ export interface InfisicalConfig {
|
|
|
3
3
|
projectId: string;
|
|
4
4
|
environment: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Log in to Infisical using Universal Auth (Client ID + Client Secret).
|
|
8
|
+
* Returns a short-lived access token (default 30 day TTL).
|
|
9
|
+
*/
|
|
10
|
+
export declare function infisicalLogin(clientId: string, clientSecret: string): Promise<string>;
|
|
6
11
|
/**
|
|
7
12
|
* Fetch secrets from an Infisical folder path.
|
|
8
13
|
* Returns a key-value record of secret names to values.
|
|
@@ -17,13 +22,9 @@ export declare function fetchGlobalSecrets(config: InfisicalConfig): Promise<Rec
|
|
|
17
22
|
*/
|
|
18
23
|
export declare function fetchBranchSecrets(config: InfisicalConfig, branch: string): Promise<Record<string, string>>;
|
|
19
24
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
export declare function resolveContainerSecrets(config: InfisicalConfig): Promise<Record<string, string>>;
|
|
25
|
-
/**
|
|
26
|
-
* Extract Infisical config from environment variables.
|
|
27
|
-
* Throws if any required Infisical var is missing.
|
|
25
|
+
* Extract Infisical config from environment variables and log in.
|
|
26
|
+
* Reads INFISICAL_CLIENT_ID, INFISICAL_CLIENT_SECRET, INFISICAL_PROJECT_ID,
|
|
27
|
+
* and INFISICAL_ENVIRONMENT from the env vars.
|
|
28
|
+
* Throws if any required var is missing.
|
|
28
29
|
*/
|
|
29
|
-
export declare function getInfisicalConfig(envVars: Record<string, string>): InfisicalConfig
|
|
30
|
+
export declare function getInfisicalConfig(envVars: Record<string, string>): Promise<InfisicalConfig>;
|
package/dist/secrets.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
|
-
import { resolve, dirname } from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
5
1
|
const INFISICAL_API_BASE = "https://app.infisical.com";
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Log in to Infisical using Universal Auth (Client ID + Client Secret).
|
|
4
|
+
* Returns a short-lived access token (default 30 day TTL).
|
|
5
|
+
*/
|
|
6
|
+
export async function infisicalLogin(clientId, clientSecret) {
|
|
7
|
+
const res = await fetch(`${INFISICAL_API_BASE}/api/v1/auth/universal-auth/login`, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
headers: { "Content-Type": "application/json" },
|
|
10
|
+
body: JSON.stringify({ clientId, clientSecret }),
|
|
11
|
+
});
|
|
12
|
+
if (!res.ok) {
|
|
13
|
+
const body = await res.text().catch(() => "");
|
|
14
|
+
throw new Error(`Infisical login failed → ${res.status}: ${body}`);
|
|
15
|
+
}
|
|
16
|
+
const data = (await res.json());
|
|
17
|
+
return data.accessToken;
|
|
14
18
|
}
|
|
15
19
|
async function infisicalFetch(path, config) {
|
|
16
20
|
const res = await fetch(`${INFISICAL_API_BASE}${path}`, {
|
|
@@ -56,40 +60,25 @@ export async function fetchBranchSecrets(config, branch) {
|
|
|
56
60
|
return fetchInfisicalSecrets(config, `/branches/${branch}/`);
|
|
57
61
|
}
|
|
58
62
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
export async function resolveContainerSecrets(config) {
|
|
64
|
-
const globals = await fetchGlobalSecrets(config);
|
|
65
|
-
const secrets = {
|
|
66
|
-
...globals,
|
|
67
|
-
INFISICAL_TOKEN: config.token,
|
|
68
|
-
INFISICAL_PROJECT_ID: config.projectId,
|
|
69
|
-
INFISICAL_ENVIRONMENT: config.environment,
|
|
70
|
-
};
|
|
71
|
-
const required = getRequiredSecretKeys();
|
|
72
|
-
const missing = required.filter((k) => !secrets[k]);
|
|
73
|
-
if (missing.length > 0) {
|
|
74
|
-
throw new Error(`Missing required secrets in Infisical /global/: ${missing.join(", ")}`);
|
|
75
|
-
}
|
|
76
|
-
return secrets;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Extract Infisical config from environment variables.
|
|
80
|
-
* Throws if any required Infisical var is missing.
|
|
63
|
+
* Extract Infisical config from environment variables and log in.
|
|
64
|
+
* Reads INFISICAL_CLIENT_ID, INFISICAL_CLIENT_SECRET, INFISICAL_PROJECT_ID,
|
|
65
|
+
* and INFISICAL_ENVIRONMENT from the env vars.
|
|
66
|
+
* Throws if any required var is missing.
|
|
81
67
|
*/
|
|
82
|
-
export function getInfisicalConfig(envVars) {
|
|
83
|
-
const
|
|
68
|
+
export async function getInfisicalConfig(envVars) {
|
|
69
|
+
const clientId = envVars.INFISICAL_CLIENT_ID;
|
|
70
|
+
const clientSecret = envVars.INFISICAL_CLIENT_SECRET;
|
|
84
71
|
const projectId = envVars.INFISICAL_PROJECT_ID;
|
|
85
72
|
const environment = envVars.INFISICAL_ENVIRONMENT;
|
|
86
73
|
const missing = [
|
|
87
|
-
!
|
|
74
|
+
!clientId && "INFISICAL_CLIENT_ID",
|
|
75
|
+
!clientSecret && "INFISICAL_CLIENT_SECRET",
|
|
88
76
|
!projectId && "INFISICAL_PROJECT_ID",
|
|
89
77
|
!environment && "INFISICAL_ENVIRONMENT",
|
|
90
78
|
].filter(Boolean);
|
|
91
79
|
if (missing.length > 0) {
|
|
92
80
|
throw new Error(`Missing Infisical config in .env: ${missing.join(", ")}`);
|
|
93
81
|
}
|
|
94
|
-
|
|
82
|
+
const token = await infisicalLogin(clientId, clientSecret);
|
|
83
|
+
return { token, projectId: projectId, environment: environment };
|
|
95
84
|
}
|