@alineo-labs/vault 0.2.0 → 0.3.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/index.d.mts CHANGED
@@ -1,61 +1,6 @@
1
1
  import { CredentialBinding, CredentialBroker } from "@alineo-labs/core";
2
2
  import { ControlClient } from "@alineo-labs/opensandbox";
3
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
4
  //#region src/vault-client.d.ts
60
5
  /** Thrown for a non-2xx response from the egress sidecar's Credential Vault API. */
61
6
  declare class VaultClientError extends Error {
@@ -191,4 +136,56 @@ declare class VaultClient {
191
136
  createOrPatch(sandboxId: string, credential: WireCredential, binding: WireBinding, useServerProxy?: boolean): Promise<VaultState>;
192
137
  }
193
138
  //#endregion
139
+ //#region src/broker.d.ts
140
+ /**
141
+ * Thrown when a wire `auth.type` read back from the vault has no `CredentialInjection` this
142
+ * package understands. Both injection shapes it *writes* — `{ type: "header" }` → `apiKey`,
143
+ * `{ type: "substitution" }` → `passthrough` — round-trip; anything else is a binding some
144
+ * other client created.
145
+ */
146
+ declare class UnsupportedInjectionError extends Error {
147
+ constructor(injectionType: string);
148
+ }
149
+ /**
150
+ * Default `CredentialBroker` implementation, backed by OpenSandbox's own Credential Vault.
151
+ *
152
+ * `Sandbox` (from `@alineo-labs/sandbox`) constructs one of these automatically, wired to its
153
+ * own internal `ControlClient`, when `SandboxClientOptions.credentialBroker` is omitted — most
154
+ * callers never need to construct this directly.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * const sb = await client.sandbox({
159
+ * image: "node:22",
160
+ * resources: { cpu: "500m", memory: "512Mi" },
161
+ * networkPolicy: { defaultAction: "deny", egress: [{ action: "allow", target: "api.github.com" }] },
162
+ * credentialProxy: true,
163
+ * });
164
+ * await sb.credentials.set("github", process.env.GH_TOKEN!, {
165
+ * host: "api.github.com",
166
+ * injection: { type: "header", name: "Authorization" },
167
+ * });
168
+ * ```
169
+ */
170
+ declare class OpenSandboxCredentialBroker implements CredentialBroker {
171
+ private readonly useServerProxy?;
172
+ private readonly vault;
173
+ constructor(control: ControlClient, useServerProxy?: boolean | undefined);
174
+ set(sandboxId: string, name: string, value: string, binding: CredentialBinding): Promise<void>;
175
+ /**
176
+ * Both `changes.value` and `changes.binding` are required — the vault's `GET` response never
177
+ * echoes credential values back (by design, for security), so there is no way to preserve
178
+ * "the current value" while only replacing the binding, or vice versa. Pass both.
179
+ */
180
+ patch(sandboxId: string, name: string, changes: Partial<{
181
+ value: string;
182
+ binding: CredentialBinding;
183
+ }>): Promise<void>;
184
+ remove(sandboxId: string, name: string): Promise<void>;
185
+ listBindings(sandboxId: string): Promise<Array<{
186
+ name: string;
187
+ binding: CredentialBinding;
188
+ }>>;
189
+ }
190
+ //#endregion
194
191
  export { type CreateRequest, type MutationRequest, OpenSandboxCredentialBroker, UnsupportedInjectionError, VaultClient, VaultClientError, type VaultState, type WireAuth, type WireBinding, type WireCredential, type WireCredentialSource, type 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 `CredentialBinding.injection` has no equivalent in the sidecar's real `Auth`
117
- * model. Only header injection (`{ type: "header" }`) maps onto it today — it supports
118
- * `bearer`/`basic`/`apiKey`/`customHeaders` header injection and placeholder `substitutions`
119
- * (for path/query/body), but not an arbitrary named query param or path segment the way this
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 injection type "${injectionType}" is not yet supported by @alineo-labs/vault — only { type: "header" } maps onto the egress sidecar's real Credential Vault API today.`);
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 !== "header") throw new UnsupportedInjectionError(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
- return {
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.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,11 +24,12 @@
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.3.0",
31
- "@alineo-labs/opensandbox": "0.2.0"
31
+ "@alineo-labs/core": "0.4.0",
32
+ "@alineo-labs/opensandbox": "0.3.0"
32
33
  },
33
34
  "devDependencies": {
34
35
  "bun-types": "1.3.14",