@vellumai/credential-executor 0.11.6 → 0.11.7-dev.202608272311.f90ed23
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/node_modules/@vellumai/service-contracts/src/__tests__/ingress.test.ts +37 -0
- package/node_modules/@vellumai/service-contracts/src/__tests__/remote-web-pairing.test.ts +389 -0
- package/node_modules/@vellumai/service-contracts/src/ingress.ts +22 -0
- package/node_modules/@vellumai/service-contracts/src/remote-web-pairing.ts +508 -18
- package/node_modules/@vellumai/service-contracts/src/rpc.ts +174 -0
- package/package.json +1 -1
- package/src/__tests__/credential-record-store.test.ts +91 -0
- package/src/http/__tests__/metadata-routes.test.ts +84 -0
- package/src/http/metadata-routes.ts +197 -0
- package/src/main.ts +16 -2
- package/src/records/handlers.ts +58 -0
- package/src/records/metadata-store.ts +187 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CES-owned credential metadata store.
|
|
3
|
+
*
|
|
4
|
+
* Persists non-secret identity and policy (`allowedTools`, `allowedDomains`,
|
|
5
|
+
* `injectionTemplates`, plus catalog fields) at
|
|
6
|
+
* `<cesDataRoot>/metadata.json`. Secret values stay in `keys.enc`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
import {
|
|
11
|
+
existsSync,
|
|
12
|
+
mkdirSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
renameSync,
|
|
15
|
+
writeFileSync,
|
|
16
|
+
} from "node:fs";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
|
|
19
|
+
import type { CredentialRecord } from "@vellumai/service-contracts/credential-rpc";
|
|
20
|
+
|
|
21
|
+
import { getCesDataRoot } from "../paths.js";
|
|
22
|
+
|
|
23
|
+
export const METADATA_FILENAME = "metadata.json";
|
|
24
|
+
|
|
25
|
+
const CURRENT_VERSION = 5;
|
|
26
|
+
|
|
27
|
+
interface MetadataFile {
|
|
28
|
+
version: typeof CURRENT_VERSION;
|
|
29
|
+
credentials: CredentialRecord[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getMetadataPath(cesDataRoot: string): string {
|
|
33
|
+
return join(cesDataRoot, METADATA_FILENAME);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function parseCredentialAccount(
|
|
37
|
+
account: string,
|
|
38
|
+
): { service: string; field: string } | undefined {
|
|
39
|
+
const prefix = "credential/";
|
|
40
|
+
if (!account.startsWith(prefix)) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const rest = account.slice(prefix.length);
|
|
44
|
+
const slashIdx = rest.lastIndexOf("/");
|
|
45
|
+
if (slashIdx < 1 || slashIdx === rest.length - 1) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
service: rest.slice(0, slashIdx),
|
|
50
|
+
field: rest.slice(slashIdx + 1),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function accountForRecord(
|
|
55
|
+
record: Pick<CredentialRecord, "service" | "field">,
|
|
56
|
+
): string {
|
|
57
|
+
return `credential/${record.service}/${record.field}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isRecord(value: unknown): value is CredentialRecord {
|
|
61
|
+
if (typeof value !== "object" || value == null) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const record = value as Record<string, unknown>;
|
|
65
|
+
return (
|
|
66
|
+
typeof record.credentialId === "string" &&
|
|
67
|
+
typeof record.service === "string" &&
|
|
68
|
+
typeof record.field === "string" &&
|
|
69
|
+
Array.isArray(record.allowedTools) &&
|
|
70
|
+
Array.isArray(record.allowedDomains) &&
|
|
71
|
+
typeof record.createdAt === "number" &&
|
|
72
|
+
typeof record.updatedAt === "number"
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class CesMetadataStore {
|
|
77
|
+
constructor(private readonly metadataPath: string) {}
|
|
78
|
+
|
|
79
|
+
getPath(): string {
|
|
80
|
+
return this.metadataPath;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getByAccount(account: string): CredentialRecord | undefined {
|
|
84
|
+
const parsed = parseCredentialAccount(account);
|
|
85
|
+
if (!parsed) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
return this.load().credentials.find(
|
|
89
|
+
(record) =>
|
|
90
|
+
record.service === parsed.service && record.field === parsed.field,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setByAccount(account: string, record: CredentialRecord): boolean {
|
|
95
|
+
const parsed = parseCredentialAccount(account);
|
|
96
|
+
if (!parsed) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (parsed.service !== record.service || parsed.field !== record.field) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const data = this.load();
|
|
103
|
+
const copy: CredentialRecord = { ...record };
|
|
104
|
+
const idx = data.credentials.findIndex(
|
|
105
|
+
(entry) =>
|
|
106
|
+
entry.service === record.service && entry.field === record.field,
|
|
107
|
+
);
|
|
108
|
+
if (idx === -1) {
|
|
109
|
+
data.credentials.push(copy);
|
|
110
|
+
} else {
|
|
111
|
+
data.credentials[idx] = copy;
|
|
112
|
+
}
|
|
113
|
+
this.save(data);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
deleteByAccount(account: string): "deleted" | "not-found" | "error" {
|
|
118
|
+
const parsed = parseCredentialAccount(account);
|
|
119
|
+
if (!parsed) {
|
|
120
|
+
return "error";
|
|
121
|
+
}
|
|
122
|
+
const data = this.load();
|
|
123
|
+
const idx = data.credentials.findIndex(
|
|
124
|
+
(entry) =>
|
|
125
|
+
entry.service === parsed.service && entry.field === parsed.field,
|
|
126
|
+
);
|
|
127
|
+
if (idx === -1) {
|
|
128
|
+
return "not-found";
|
|
129
|
+
}
|
|
130
|
+
data.credentials.splice(idx, 1);
|
|
131
|
+
this.save(data);
|
|
132
|
+
return "deleted";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
list(): Array<{ account: string; record: CredentialRecord }> {
|
|
136
|
+
return this.load().credentials.map((record) => ({
|
|
137
|
+
account: accountForRecord(record),
|
|
138
|
+
record,
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private load(): MetadataFile {
|
|
143
|
+
if (!existsSync(this.metadataPath)) {
|
|
144
|
+
return { version: CURRENT_VERSION, credentials: [] };
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const parsed = JSON.parse(readFileSync(this.metadataPath, "utf-8")) as {
|
|
148
|
+
credentials?: unknown;
|
|
149
|
+
};
|
|
150
|
+
const credentials = Array.isArray(parsed.credentials)
|
|
151
|
+
? parsed.credentials.filter(isRecord)
|
|
152
|
+
: [];
|
|
153
|
+
return { version: CURRENT_VERSION, credentials };
|
|
154
|
+
} catch {
|
|
155
|
+
return { version: CURRENT_VERSION, credentials: [] };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private save(data: MetadataFile): void {
|
|
160
|
+
const dir = dirname(this.metadataPath);
|
|
161
|
+
if (!existsSync(dir)) {
|
|
162
|
+
mkdirSync(dir, { recursive: true });
|
|
163
|
+
}
|
|
164
|
+
const tmpPath = join(dir, `.tmp-${randomUUID()}`);
|
|
165
|
+
writeFileSync(tmpPath, JSON.stringify(data, null, 2), "utf-8");
|
|
166
|
+
renameSync(tmpPath, this.metadataPath);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let processStore: CesMetadataStore | undefined;
|
|
171
|
+
|
|
172
|
+
export function initMetadataStore(cesDataRoot: string): CesMetadataStore {
|
|
173
|
+
processStore = new CesMetadataStore(getMetadataPath(cesDataRoot));
|
|
174
|
+
return processStore;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function getMetadataStore(): CesMetadataStore {
|
|
178
|
+
if (!processStore) {
|
|
179
|
+
processStore = new CesMetadataStore(getMetadataPath(getCesDataRoot()));
|
|
180
|
+
}
|
|
181
|
+
return processStore;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Test-only: drop the process store so the next init uses a fresh path. */
|
|
185
|
+
export function resetMetadataStoreForTests(): void {
|
|
186
|
+
processStore = undefined;
|
|
187
|
+
}
|