@replayio/app-building 1.12.0 → 1.14.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/README.md +18 -8
- package/dist/secrets.d.ts +10 -3
- package/dist/secrets.js +28 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ npm install @replayio/app-building
|
|
|
14
14
|
import {
|
|
15
15
|
loadDotEnv,
|
|
16
16
|
FileContainerRegistry,
|
|
17
|
+
getInfisicalConfig,
|
|
18
|
+
resolveContainerSecrets,
|
|
17
19
|
createMachine,
|
|
18
20
|
destroyMachine,
|
|
19
21
|
type ContainerConfig,
|
|
@@ -23,14 +25,17 @@ import {
|
|
|
23
25
|
httpOptsFor,
|
|
24
26
|
} from "@replayio/app-building";
|
|
25
27
|
|
|
26
|
-
//
|
|
27
|
-
const
|
|
28
|
+
// Load orchestration vars from .env, then fetch build secrets from Infisical
|
|
29
|
+
const orchestrationVars = loadDotEnv("/path/to/project");
|
|
30
|
+
const infisicalConfig = getInfisicalConfig(orchestrationVars);
|
|
31
|
+
const containerSecrets = await resolveContainerSecrets(infisicalConfig);
|
|
32
|
+
|
|
28
33
|
const config: ContainerConfig = {
|
|
29
34
|
projectRoot: "/path/to/project", // optional — only needed for local Docker operations
|
|
30
|
-
envVars,
|
|
35
|
+
envVars: containerSecrets,
|
|
31
36
|
registry: new FileContainerRegistry("/path/to/.container-registry.jsonl"),
|
|
32
|
-
flyToken:
|
|
33
|
-
flyApp:
|
|
37
|
+
flyToken: orchestrationVars.FLY_API_TOKEN,
|
|
38
|
+
flyApp: orchestrationVars.FLY_APP_NAME,
|
|
34
39
|
};
|
|
35
40
|
|
|
36
41
|
// Create a Fly machine (automatically provisions a volume)
|
|
@@ -54,7 +59,7 @@ await destroyMachine(config.flyApp, config.flyToken, machineId, volumeId);
|
|
|
54
59
|
|
|
55
60
|
| Export | Description |
|
|
56
61
|
|---|---|
|
|
57
|
-
| `ContainerConfig` | Interface bundling all external state: optional `projectRoot` (only needed for local Docker operations), `envVars
|
|
62
|
+
| `ContainerConfig` | Interface bundling all external state: optional `projectRoot` (only needed for local Docker operations), `envVars` (build secrets from Infisical), `registry`, optional `flyToken`/`flyApp`/`imageRef`/`webhookUrl`/`webhookSecret`/`detached`/`initialPrompt`/`localPort`. See [Webhooks](#webhooks) and [Container lifecycle](#container-lifecycle) below. |
|
|
58
63
|
| `RepoOptions` | Per-invocation git settings: `repoUrl`, `cloneBranch`, `pushBranch`. |
|
|
59
64
|
| `ContainerRegistry` | Interface for container registry storage. Methods: `log`, `markStopped`, `clearStopped`, `getRecent`, `find`, `findAlive`. |
|
|
60
65
|
| `FileContainerRegistry` | Built-in file-backed implementation of `ContainerRegistry`, backed by a `.jsonl` file. |
|
|
@@ -183,7 +188,7 @@ so that interactive users can send follow-up messages at any time.
|
|
|
183
188
|
|
|
184
189
|
## Webhooks
|
|
185
190
|
|
|
186
|
-
Set `webhookUrl` on `ContainerConfig` to receive real-time notifications of container activity. The container POSTs JSON to that URL on key events (no retries; failures are logged to stderr).
|
|
191
|
+
Set `webhookUrl` on `ContainerConfig` to receive real-time notifications of container activity. The container POSTs JSON to that URL on key events (no retries; failures are logged to stderr). Set `webhookSecret` to include a `Bearer` token in the `Authorization` header for authenticating webhook requests.
|
|
187
192
|
|
|
188
193
|
### Payload format
|
|
189
194
|
|
|
@@ -224,10 +229,15 @@ Every POST body has this shape:
|
|
|
224
229
|
### Example
|
|
225
230
|
|
|
226
231
|
```ts
|
|
232
|
+
const orchestrationVars = loadDotEnv("/path/to/project");
|
|
233
|
+
const infisicalConfig = getInfisicalConfig(orchestrationVars);
|
|
234
|
+
const containerSecrets = await resolveContainerSecrets(infisicalConfig);
|
|
235
|
+
|
|
227
236
|
const config: ContainerConfig = {
|
|
228
237
|
projectRoot: "/path/to/project",
|
|
229
|
-
envVars:
|
|
238
|
+
envVars: containerSecrets,
|
|
230
239
|
registry: new FileContainerRegistry("/path/to/.container-registry.jsonl"),
|
|
231
240
|
webhookUrl: "https://example.com/hooks/container-events",
|
|
241
|
+
webhookSecret: "your-webhook-secret",
|
|
232
242
|
};
|
|
233
243
|
```
|
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.
|
|
@@ -23,7 +28,9 @@ export declare function fetchBranchSecrets(config: InfisicalConfig, branch: stri
|
|
|
23
28
|
*/
|
|
24
29
|
export declare function resolveContainerSecrets(config: InfisicalConfig): Promise<Record<string, string>>;
|
|
25
30
|
/**
|
|
26
|
-
* Extract Infisical config from environment variables.
|
|
27
|
-
*
|
|
31
|
+
* Extract Infisical config from environment variables and log in.
|
|
32
|
+
* Reads INFISICAL_CLIENT_ID, INFISICAL_CLIENT_SECRET, INFISICAL_PROJECT_ID,
|
|
33
|
+
* and INFISICAL_ENVIRONMENT from the env vars.
|
|
34
|
+
* Throws if any required var is missing.
|
|
28
35
|
*/
|
|
29
|
-
export declare function getInfisicalConfig(envVars: Record<string, string>): InfisicalConfig
|
|
36
|
+
export declare function getInfisicalConfig(envVars: Record<string, string>): Promise<InfisicalConfig>;
|
package/dist/secrets.js
CHANGED
|
@@ -12,6 +12,23 @@ function getRequiredSecretKeys() {
|
|
|
12
12
|
.filter((l) => l && l.includes("="))
|
|
13
13
|
.map((l) => l.split("=")[0].trim());
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Log in to Infisical using Universal Auth (Client ID + Client Secret).
|
|
17
|
+
* Returns a short-lived access token (default 30 day TTL).
|
|
18
|
+
*/
|
|
19
|
+
export async function infisicalLogin(clientId, clientSecret) {
|
|
20
|
+
const res = await fetch(`${INFISICAL_API_BASE}/api/v1/auth/universal-auth/login`, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: { "Content-Type": "application/json" },
|
|
23
|
+
body: JSON.stringify({ clientId, clientSecret }),
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
const body = await res.text().catch(() => "");
|
|
27
|
+
throw new Error(`Infisical login failed → ${res.status}: ${body}`);
|
|
28
|
+
}
|
|
29
|
+
const data = (await res.json());
|
|
30
|
+
return data.accessToken;
|
|
31
|
+
}
|
|
15
32
|
async function infisicalFetch(path, config) {
|
|
16
33
|
const res = await fetch(`${INFISICAL_API_BASE}${path}`, {
|
|
17
34
|
headers: {
|
|
@@ -76,20 +93,25 @@ export async function resolveContainerSecrets(config) {
|
|
|
76
93
|
return secrets;
|
|
77
94
|
}
|
|
78
95
|
/**
|
|
79
|
-
* Extract Infisical config from environment variables.
|
|
80
|
-
*
|
|
96
|
+
* Extract Infisical config from environment variables and log in.
|
|
97
|
+
* Reads INFISICAL_CLIENT_ID, INFISICAL_CLIENT_SECRET, INFISICAL_PROJECT_ID,
|
|
98
|
+
* and INFISICAL_ENVIRONMENT from the env vars.
|
|
99
|
+
* Throws if any required var is missing.
|
|
81
100
|
*/
|
|
82
|
-
export function getInfisicalConfig(envVars) {
|
|
83
|
-
const
|
|
101
|
+
export async function getInfisicalConfig(envVars) {
|
|
102
|
+
const clientId = envVars.INFISICAL_CLIENT_ID;
|
|
103
|
+
const clientSecret = envVars.INFISICAL_CLIENT_SECRET;
|
|
84
104
|
const projectId = envVars.INFISICAL_PROJECT_ID;
|
|
85
105
|
const environment = envVars.INFISICAL_ENVIRONMENT;
|
|
86
106
|
const missing = [
|
|
87
|
-
!
|
|
107
|
+
!clientId && "INFISICAL_CLIENT_ID",
|
|
108
|
+
!clientSecret && "INFISICAL_CLIENT_SECRET",
|
|
88
109
|
!projectId && "INFISICAL_PROJECT_ID",
|
|
89
110
|
!environment && "INFISICAL_ENVIRONMENT",
|
|
90
111
|
].filter(Boolean);
|
|
91
112
|
if (missing.length > 0) {
|
|
92
113
|
throw new Error(`Missing Infisical config in .env: ${missing.join(", ")}`);
|
|
93
114
|
}
|
|
94
|
-
|
|
115
|
+
const token = await infisicalLogin(clientId, clientSecret);
|
|
116
|
+
return { token, projectId: projectId, environment: environment };
|
|
95
117
|
}
|