@alineo-labs/vault 0.2.0 → 0.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.
- package/dist/index.d.mts +55 -59
- package/dist/index.mjs +28 -13
- package/package.json +7 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,64 +1,8 @@
|
|
|
1
1
|
import { CredentialBinding, CredentialBroker } from "@alineo-labs/core";
|
|
2
2
|
import { ControlClient } from "@alineo-labs/opensandbox";
|
|
3
|
-
|
|
4
|
-
//#region src/broker.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Thrown when a `CredentialBinding.injection` has no equivalent in the sidecar's real `Auth`
|
|
7
|
-
* model. Only header injection (`{ type: "header" }`) maps onto it today — it supports
|
|
8
|
-
* `bearer`/`basic`/`apiKey`/`customHeaders` header injection and placeholder `substitutions`
|
|
9
|
-
* (for path/query/body), but not an arbitrary named query param or path segment the way this
|
|
10
|
-
* package's `{ type: "query" }`/`{ type: "path" }` binding shapes imply. Wire those up to
|
|
11
|
-
* `substitutions` (which needs a literal placeholder string in the request, a different model
|
|
12
|
-
* from "inject a named param") before lifting this restriction.
|
|
13
|
-
*/
|
|
14
|
-
declare class UnsupportedInjectionError extends Error {
|
|
15
|
-
constructor(injectionType: string);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Default `CredentialBroker` implementation, backed by OpenSandbox's own Credential Vault.
|
|
19
|
-
*
|
|
20
|
-
* `Sandbox` (from `@alineo-labs/sandbox`) constructs one of these automatically, wired to its
|
|
21
|
-
* own internal `ControlClient`, when `SandboxClientOptions.credentialBroker` is omitted — most
|
|
22
|
-
* callers never need to construct this directly.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const sb = await client.sandbox({
|
|
27
|
-
* image: "node:22",
|
|
28
|
-
* resources: { cpu: "500m", memory: "512Mi" },
|
|
29
|
-
* networkPolicy: { defaultAction: "deny", egress: [{ action: "allow", target: "api.github.com" }] },
|
|
30
|
-
* credentialProxy: true,
|
|
31
|
-
* });
|
|
32
|
-
* await sb.credentials.set("github", process.env.GH_TOKEN!, {
|
|
33
|
-
* host: "api.github.com",
|
|
34
|
-
* injection: { type: "header", name: "Authorization" },
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
declare class OpenSandboxCredentialBroker implements CredentialBroker {
|
|
39
|
-
private readonly useServerProxy?;
|
|
40
|
-
private readonly vault;
|
|
41
|
-
constructor(control: ControlClient, useServerProxy?: boolean | undefined);
|
|
42
|
-
set(sandboxId: string, name: string, value: string, binding: CredentialBinding): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Both `changes.value` and `changes.binding` are required — the vault's `GET` response never
|
|
45
|
-
* echoes credential values back (by design, for security), so there is no way to preserve
|
|
46
|
-
* "the current value" while only replacing the binding, or vice versa. Pass both.
|
|
47
|
-
*/
|
|
48
|
-
patch(sandboxId: string, name: string, changes: Partial<{
|
|
49
|
-
value: string;
|
|
50
|
-
binding: CredentialBinding;
|
|
51
|
-
}>): Promise<void>;
|
|
52
|
-
remove(sandboxId: string, name: string): Promise<void>;
|
|
53
|
-
listBindings(sandboxId: string): Promise<Array<{
|
|
54
|
-
name: string;
|
|
55
|
-
binding: CredentialBinding;
|
|
56
|
-
}>>;
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
3
|
//#region src/vault-client.d.ts
|
|
60
4
|
/** Thrown for a non-2xx response from the egress sidecar's Credential Vault API. */
|
|
61
|
-
declare class VaultClientError extends Error {
|
|
5
|
+
export declare class VaultClientError extends Error {
|
|
62
6
|
readonly status: number;
|
|
63
7
|
constructor(message: string, status: number);
|
|
64
8
|
}
|
|
@@ -162,7 +106,7 @@ interface MutationRequest {
|
|
|
162
106
|
* (values and full auth config are never echoed back), and `DELETE /credential-vault` removes
|
|
163
107
|
* the whole vault — there is no per-credential DELETE route.
|
|
164
108
|
*/
|
|
165
|
-
declare class VaultClient {
|
|
109
|
+
export declare class VaultClient {
|
|
166
110
|
private readonly control;
|
|
167
111
|
private static readonly PORT;
|
|
168
112
|
constructor(control: ControlClient);
|
|
@@ -191,4 +135,56 @@ declare class VaultClient {
|
|
|
191
135
|
createOrPatch(sandboxId: string, credential: WireCredential, binding: WireBinding, useServerProxy?: boolean): Promise<VaultState>;
|
|
192
136
|
}
|
|
193
137
|
//#endregion
|
|
194
|
-
|
|
138
|
+
//#region src/broker.d.ts
|
|
139
|
+
/**
|
|
140
|
+
* Thrown when a wire `auth.type` read back from the vault has no `CredentialInjection` this
|
|
141
|
+
* package understands. Both injection shapes it *writes* — `{ type: "header" }` → `apiKey`,
|
|
142
|
+
* `{ type: "substitution" }` → `passthrough` — round-trip; anything else is a binding some
|
|
143
|
+
* other client created.
|
|
144
|
+
*/
|
|
145
|
+
export declare class UnsupportedInjectionError extends Error {
|
|
146
|
+
constructor(injectionType: string);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Default `CredentialBroker` implementation, backed by OpenSandbox's own Credential Vault.
|
|
150
|
+
*
|
|
151
|
+
* `Sandbox` (from `@alineo-labs/sandbox`) constructs one of these automatically, wired to its
|
|
152
|
+
* own internal `ControlClient`, when `SandboxClientOptions.credentialBroker` is omitted — most
|
|
153
|
+
* callers never need to construct this directly.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* const sb = await client.sandbox({
|
|
158
|
+
* image: "node:22",
|
|
159
|
+
* resources: { cpu: "500m", memory: "512Mi" },
|
|
160
|
+
* networkPolicy: { defaultAction: "deny", egress: [{ action: "allow", target: "api.github.com" }] },
|
|
161
|
+
* credentialProxy: true,
|
|
162
|
+
* });
|
|
163
|
+
* await sb.credentials.set("github", process.env.GH_TOKEN!, {
|
|
164
|
+
* host: "api.github.com",
|
|
165
|
+
* injection: { type: "header", name: "Authorization" },
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare class OpenSandboxCredentialBroker implements CredentialBroker {
|
|
170
|
+
private readonly useServerProxy?;
|
|
171
|
+
private readonly vault;
|
|
172
|
+
constructor(control: ControlClient, useServerProxy?: boolean | undefined);
|
|
173
|
+
set(sandboxId: string, name: string, value: string, binding: CredentialBinding): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Both `changes.value` and `changes.binding` are required — the vault's `GET` response never
|
|
176
|
+
* echoes credential values back (by design, for security), so there is no way to preserve
|
|
177
|
+
* "the current value" while only replacing the binding, or vice versa. Pass both.
|
|
178
|
+
*/
|
|
179
|
+
patch(sandboxId: string, name: string, changes: Partial<{
|
|
180
|
+
value: string;
|
|
181
|
+
binding: CredentialBinding;
|
|
182
|
+
}>): Promise<void>;
|
|
183
|
+
remove(sandboxId: string, name: string): Promise<void>;
|
|
184
|
+
listBindings(sandboxId: string): Promise<Array<{
|
|
185
|
+
name: string;
|
|
186
|
+
binding: CredentialBinding;
|
|
187
|
+
}>>;
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
export type { CreateRequest, MutationRequest, VaultState, WireAuth, WireBinding, WireCredential, WireCredentialSource, WireMatch };
|
package/dist/index.mjs
CHANGED
|
@@ -113,27 +113,31 @@ var VaultClient = class VaultClient {
|
|
|
113
113
|
//#endregion
|
|
114
114
|
//#region src/broker.ts
|
|
115
115
|
/**
|
|
116
|
-
* Thrown when a `
|
|
117
|
-
*
|
|
118
|
-
* `
|
|
119
|
-
*
|
|
120
|
-
* package's `{ type: "query" }`/`{ type: "path" }` binding shapes imply. Wire those up to
|
|
121
|
-
* `substitutions` (which needs a literal placeholder string in the request, a different model
|
|
122
|
-
* from "inject a named param") before lifting this restriction.
|
|
116
|
+
* Thrown when a wire `auth.type` read back from the vault has no `CredentialInjection` this
|
|
117
|
+
* package understands. Both injection shapes it *writes* — `{ type: "header" }` → `apiKey`,
|
|
118
|
+
* `{ type: "substitution" }` → `passthrough` — round-trip; anything else is a binding some
|
|
119
|
+
* other client created.
|
|
123
120
|
*/
|
|
124
121
|
var UnsupportedInjectionError = class extends Error {
|
|
125
122
|
constructor(injectionType) {
|
|
126
|
-
super(`Credential
|
|
123
|
+
super(`Credential vault auth type "${injectionType}" has no @alineo-labs/vault CredentialInjection equivalent — it was likely created by another client.`);
|
|
127
124
|
this.name = "UnsupportedInjectionError";
|
|
128
125
|
}
|
|
129
126
|
};
|
|
130
127
|
function toWireAuth(name, injection) {
|
|
131
|
-
if (injection.type
|
|
132
|
-
return {
|
|
128
|
+
if (injection.type === "header") return {
|
|
133
129
|
type: "apiKey",
|
|
134
130
|
name: injection.name,
|
|
135
131
|
credential: name
|
|
136
132
|
};
|
|
133
|
+
return {
|
|
134
|
+
type: "passthrough",
|
|
135
|
+
substitutions: [{
|
|
136
|
+
credential: name,
|
|
137
|
+
placeholder: injection.placeholder,
|
|
138
|
+
in: injection.in
|
|
139
|
+
}]
|
|
140
|
+
};
|
|
137
141
|
}
|
|
138
142
|
function toWireBinding(name, binding) {
|
|
139
143
|
return {
|
|
@@ -146,16 +150,27 @@ function toWireBinding(name, binding) {
|
|
|
146
150
|
};
|
|
147
151
|
}
|
|
148
152
|
function fromWireBindingMetadata(meta) {
|
|
149
|
-
if (meta.auth.type !== "apiKey" || !meta.auth.name) throw new UnsupportedInjectionError(meta.auth.type);
|
|
150
153
|
const path = meta.match.paths?.[0];
|
|
151
|
-
|
|
154
|
+
const base = {
|
|
152
155
|
host: meta.match.hosts[0] ?? "",
|
|
153
|
-
...path && path !== "/*" ? { pathPrefix: path.replace(/\*$/, "") } : {}
|
|
156
|
+
...path && path !== "/*" ? { pathPrefix: path.replace(/\*$/, "") } : {}
|
|
157
|
+
};
|
|
158
|
+
if (meta.auth.type === "apiKey" && meta.auth.name) return {
|
|
159
|
+
...base,
|
|
154
160
|
injection: {
|
|
155
161
|
type: "header",
|
|
156
162
|
name: meta.auth.name
|
|
157
163
|
}
|
|
158
164
|
};
|
|
165
|
+
if (meta.auth.type === "passthrough") return {
|
|
166
|
+
...base,
|
|
167
|
+
injection: {
|
|
168
|
+
type: "substitution",
|
|
169
|
+
placeholder: "",
|
|
170
|
+
in: []
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
throw new UnsupportedInjectionError(meta.auth.type);
|
|
159
174
|
}
|
|
160
175
|
/**
|
|
161
176
|
* Default `CredentialBroker` implementation, backed by OpenSandbox's own Credential Vault.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alineo-labs/vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,15 +24,16 @@
|
|
|
24
24
|
"provenance": true
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "tsdown"
|
|
27
|
+
"build": "tsdown",
|
|
28
|
+
"test": "bun test"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@alineo-labs/core": "0.
|
|
31
|
-
"@alineo-labs/opensandbox": "0.
|
|
31
|
+
"@alineo-labs/core": "0.4.1",
|
|
32
|
+
"@alineo-labs/opensandbox": "0.3.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"bun-types": "1.
|
|
35
|
-
"tsdown": "0.
|
|
35
|
+
"bun-types": "1.4.2",
|
|
36
|
+
"tsdown": "0.23.0",
|
|
36
37
|
"typescript": "6.0.3"
|
|
37
38
|
}
|
|
38
39
|
}
|