@ultrst-armada/kloks 3.0.0 → 3.0.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/.krusbl-release-attestation.json +3 -3
- package/package.json +1 -1
- package/packages/backend/dist/{chunk-UI7AYFAU.js → chunk-363J52AF.js} +0 -48
- package/packages/backend/dist/{chunk-GCVR257U.js → chunk-3SDRLTD6.js} +1 -1
- package/packages/backend/dist/chunk-7HD7OEUY.js +177 -0
- package/packages/backend/dist/chunk-B5DCG4UC.js +602 -0
- package/packages/backend/dist/{chunk-7XTURV44.js → chunk-F7BO3GLA.js} +2 -2
- package/packages/backend/dist/{chunk-RHW75K46.js → chunk-IAW6N73D.js} +49 -1
- package/packages/backend/dist/{chunk-IRKJ6HKP.js → chunk-IXEKOWY4.js} +1 -1
- package/packages/backend/dist/{chunk-4X4QGVAO.js → chunk-NRW4TECO.js} +1 -1
- package/packages/backend/dist/{chunk-3ZL2DX73.js → chunk-PAU25K7F.js} +5 -172
- package/packages/backend/dist/{chunk-NUBA6A5T.js → chunk-VN2NR3KT.js} +1 -1
- package/packages/backend/dist/{chunk-B6BQPDJE.js → chunk-YFISFDBW.js} +5 -5
- package/packages/backend/dist/index.js +7 -7
- package/packages/backend/dist/krnl-services.js +6 -5
- package/packages/backend/dist/node.js +19 -10
- package/packages/backend/dist/provider-services/index.js +7 -7
- package/packages/backend/dist/provider-services/node.d.ts +2 -0
- package/packages/backend/dist/provider-services/node.js +15 -4
- package/packages/backend/dist/provider-services/saved-account-crypto.d.ts +19 -0
- package/packages/backend/dist/provider-services/saved-account-probe.d.ts +26 -0
- package/packages/backend/dist/provider-services/saved-account-store.d.ts +29 -0
- package/packages/backend/dist/provider-services/saved-account-store.test.d.ts +1 -0
- package/packages/backend/dist/services/node.js +5 -4
- package/packages/backend/dist/srkl/index.js +3 -2
- package/packages/backend/dist/workspace/node.js +5 -4
- package/packages/backend/dist/{workspaceFileCore-XPT6WTFY.js → workspaceFileCore-2KCVSECY.js} +3 -2
- package/packages/backend/dist/chunk-U5VPYALB.js +0 -261
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchCloudflareCapacity,
|
|
3
|
+
fetchVercelCapacity,
|
|
4
|
+
getRailwayAccount,
|
|
5
|
+
listFlyApps,
|
|
6
|
+
listGoogleCloudRunServices,
|
|
7
|
+
listRenderServices
|
|
8
|
+
} from "./chunk-IAW6N73D.js";
|
|
9
|
+
import {
|
|
10
|
+
getGeminiQuotaStatus,
|
|
11
|
+
listGeminiModels
|
|
12
|
+
} from "./chunk-GIUAFRAA.js";
|
|
13
|
+
import {
|
|
14
|
+
getGoogleAccountProfile,
|
|
15
|
+
listCloudflareAccounts,
|
|
16
|
+
listCloudflarePages,
|
|
17
|
+
listCloudflareWorkers,
|
|
18
|
+
listVercelDeployments,
|
|
19
|
+
listVercelProjects
|
|
20
|
+
} from "./chunk-LAKCKX3I.js";
|
|
21
|
+
import {
|
|
22
|
+
continueDropboxFolder,
|
|
23
|
+
listDropboxFolder,
|
|
24
|
+
listGitHubRepositories,
|
|
25
|
+
listGitHubRepositoryContents,
|
|
26
|
+
listGitLabProjects,
|
|
27
|
+
listGitLabRepositoryTree
|
|
28
|
+
} from "./chunk-AMI5MY6E.js";
|
|
29
|
+
import {
|
|
30
|
+
getProviderService
|
|
31
|
+
} from "./chunk-G6FLQJS6.js";
|
|
32
|
+
import {
|
|
33
|
+
getOrCreateStorageConnectionEncryptionKey,
|
|
34
|
+
getStorageConnectionEncryptionKey
|
|
35
|
+
} from "./chunk-7HD7OEUY.js";
|
|
36
|
+
import {
|
|
37
|
+
queryUnifiedDb
|
|
38
|
+
} from "./chunk-3RTRATDJ.js";
|
|
39
|
+
import {
|
|
40
|
+
b2ListBuckets,
|
|
41
|
+
b2ListFileNames
|
|
42
|
+
} from "./chunk-I6T64MLT.js";
|
|
43
|
+
import {
|
|
44
|
+
GoogleDriveWorkspaceService
|
|
45
|
+
} from "./chunk-EMSSTOOK.js";
|
|
46
|
+
|
|
47
|
+
// src/provider-services/facades.ts
|
|
48
|
+
import { createService, createServiceDefinition } from "@ultrst-armada/krnl";
|
|
49
|
+
var defs = {
|
|
50
|
+
cloudflare: createServiceDefinition({
|
|
51
|
+
id: "kloks.external.cloudflare",
|
|
52
|
+
name: "Cloudflare Provider Service",
|
|
53
|
+
version: "1.0.0",
|
|
54
|
+
operations: {
|
|
55
|
+
listAccounts: {
|
|
56
|
+
id: "cloudflare.listAccounts",
|
|
57
|
+
name: "listAccounts",
|
|
58
|
+
handler: (input) => listCloudflareAccounts(input.connection)
|
|
59
|
+
},
|
|
60
|
+
listWorkers: {
|
|
61
|
+
id: "cloudflare.listWorkers",
|
|
62
|
+
name: "listWorkers",
|
|
63
|
+
handler: (input) => listCloudflareWorkers(input.connection)
|
|
64
|
+
},
|
|
65
|
+
listPages: {
|
|
66
|
+
id: "cloudflare.listPages",
|
|
67
|
+
name: "listPages",
|
|
68
|
+
handler: (input) => listCloudflarePages(input.connection)
|
|
69
|
+
},
|
|
70
|
+
quota: {
|
|
71
|
+
id: "cloudflare.quota",
|
|
72
|
+
name: "quota",
|
|
73
|
+
handler: (input) => fetchCloudflareCapacity(input.connection, input.plan)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
vercel: createServiceDefinition({
|
|
78
|
+
id: "kloks.external.vercel",
|
|
79
|
+
name: "Vercel Provider Service",
|
|
80
|
+
version: "1.0.0",
|
|
81
|
+
operations: {
|
|
82
|
+
listProjects: {
|
|
83
|
+
id: "vercel.listProjects",
|
|
84
|
+
name: "listProjects",
|
|
85
|
+
handler: (input) => listVercelProjects(input.connection)
|
|
86
|
+
},
|
|
87
|
+
listDeployments: {
|
|
88
|
+
id: "vercel.listDeployments",
|
|
89
|
+
name: "listDeployments",
|
|
90
|
+
handler: (input) => listVercelDeployments(input.connection)
|
|
91
|
+
},
|
|
92
|
+
quota: {
|
|
93
|
+
id: "vercel.quota",
|
|
94
|
+
name: "quota",
|
|
95
|
+
handler: (input) => fetchVercelCapacity(input.connection, input.options)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
google: createServiceDefinition({
|
|
100
|
+
id: "kloks.external.google",
|
|
101
|
+
name: "Google Account Service",
|
|
102
|
+
version: "1.0.0",
|
|
103
|
+
operations: {
|
|
104
|
+
profile: {
|
|
105
|
+
id: "google.profile",
|
|
106
|
+
name: "profile",
|
|
107
|
+
handler: (input) => getGoogleAccountProfile(input.connection)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
gemini: createServiceDefinition({
|
|
112
|
+
id: "kloks.external.google.gemini",
|
|
113
|
+
name: "Google Gemini Service",
|
|
114
|
+
version: "1.0.0",
|
|
115
|
+
operations: {
|
|
116
|
+
listModels: {
|
|
117
|
+
id: "gemini.listModels",
|
|
118
|
+
name: "listModels",
|
|
119
|
+
handler: (input) => listGeminiModels(input.connection)
|
|
120
|
+
},
|
|
121
|
+
quota: {
|
|
122
|
+
id: "gemini.quota",
|
|
123
|
+
name: "quota",
|
|
124
|
+
handler: (input) => getGeminiQuotaStatus(input.connection.accountId)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
};
|
|
129
|
+
function facade(definition) {
|
|
130
|
+
const instance = createService(definition);
|
|
131
|
+
return {
|
|
132
|
+
id: definition.id,
|
|
133
|
+
name: definition.name,
|
|
134
|
+
version: definition.version,
|
|
135
|
+
runtime: "server",
|
|
136
|
+
deployment: "local",
|
|
137
|
+
definition,
|
|
138
|
+
get telemetry() {
|
|
139
|
+
return instance.telemetry;
|
|
140
|
+
},
|
|
141
|
+
createInstance: () => createService(definition),
|
|
142
|
+
execute: async (operation, input) => {
|
|
143
|
+
await instance.start();
|
|
144
|
+
return instance.call(operation, input);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
var CloudflareProviderService = facade(defs.cloudflare);
|
|
149
|
+
var VercelProviderService = facade(defs.vercel);
|
|
150
|
+
var GoogleAccountProviderService = facade(defs.google);
|
|
151
|
+
var GeminiProviderService = facade(defs.gemini);
|
|
152
|
+
|
|
153
|
+
// src/provider-services/storage-facades.ts
|
|
154
|
+
import { createService as createService2, createServiceDefinition as createServiceDefinition2 } from "@ultrst-armada/krnl";
|
|
155
|
+
var github = createServiceDefinition2({
|
|
156
|
+
id: "kloks.external.github",
|
|
157
|
+
name: "GitHub Provider Service",
|
|
158
|
+
version: "1.0.0",
|
|
159
|
+
operations: {
|
|
160
|
+
listRepositories: {
|
|
161
|
+
id: "github.listRepositories",
|
|
162
|
+
name: "listRepositories",
|
|
163
|
+
handler: ({ connection }) => listGitHubRepositories(connection)
|
|
164
|
+
},
|
|
165
|
+
listContents: {
|
|
166
|
+
id: "github.listContents",
|
|
167
|
+
name: "listContents",
|
|
168
|
+
handler: (input) => listGitHubRepositoryContents(input.connection, input.owner, input.repo, input.path)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
var gitlab = createServiceDefinition2({
|
|
173
|
+
id: "kloks.external.gitlab",
|
|
174
|
+
name: "GitLab Provider Service",
|
|
175
|
+
version: "1.0.0",
|
|
176
|
+
operations: {
|
|
177
|
+
listProjects: {
|
|
178
|
+
id: "gitlab.listProjects",
|
|
179
|
+
name: "listProjects",
|
|
180
|
+
handler: ({ connection }) => listGitLabProjects(connection)
|
|
181
|
+
},
|
|
182
|
+
listTree: {
|
|
183
|
+
id: "gitlab.listTree",
|
|
184
|
+
name: "listTree",
|
|
185
|
+
handler: (input) => listGitLabRepositoryTree(input.connection, input.project, input.path)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
var dropbox = createServiceDefinition2({
|
|
190
|
+
id: "kloks.external.dropbox",
|
|
191
|
+
name: "Dropbox Provider Service",
|
|
192
|
+
version: "1.0.0",
|
|
193
|
+
operations: {
|
|
194
|
+
listFolder: {
|
|
195
|
+
id: "dropbox.listFolder",
|
|
196
|
+
name: "listFolder",
|
|
197
|
+
handler: (input) => listDropboxFolder(input.connection, input.path)
|
|
198
|
+
},
|
|
199
|
+
continueFolder: {
|
|
200
|
+
id: "dropbox.continueFolder",
|
|
201
|
+
name: "continueFolder",
|
|
202
|
+
handler: (input) => continueDropboxFolder(input.connection, input.cursor)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
var backblaze = createServiceDefinition2({
|
|
207
|
+
id: "kloks.external.backblaze-b2",
|
|
208
|
+
name: "Backblaze B2 Provider Service",
|
|
209
|
+
version: "1.0.0",
|
|
210
|
+
operations: {
|
|
211
|
+
listBuckets: {
|
|
212
|
+
id: "backblaze.listBuckets",
|
|
213
|
+
name: "listBuckets",
|
|
214
|
+
handler: (input) => b2ListBuckets(input.keyId, input.applicationKey)
|
|
215
|
+
},
|
|
216
|
+
listFiles: {
|
|
217
|
+
id: "backblaze.listFiles",
|
|
218
|
+
name: "listFiles",
|
|
219
|
+
handler: (input) => b2ListFileNames(input.keyId, input.applicationKey, input.bucketName)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
var drive = createServiceDefinition2({
|
|
224
|
+
id: "kloks.external.google.drive",
|
|
225
|
+
name: "Google Drive Provider Service",
|
|
226
|
+
version: "1.0.0",
|
|
227
|
+
operations: {
|
|
228
|
+
listFolders: {
|
|
229
|
+
id: "google.drive.listFolders",
|
|
230
|
+
name: "listFolders",
|
|
231
|
+
handler: (input) => new GoogleDriveWorkspaceService(input.options).listFolders(input.parentFolderId)
|
|
232
|
+
},
|
|
233
|
+
listFiles: {
|
|
234
|
+
id: "google.drive.listFiles",
|
|
235
|
+
name: "listFiles",
|
|
236
|
+
handler: (input) => new GoogleDriveWorkspaceService(input.options).list(input.path)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
function serviceFacade(definition) {
|
|
241
|
+
const instance = createService2(definition);
|
|
242
|
+
return {
|
|
243
|
+
id: definition.id,
|
|
244
|
+
name: definition.name,
|
|
245
|
+
version: definition.version,
|
|
246
|
+
runtime: "server",
|
|
247
|
+
deployment: "local",
|
|
248
|
+
definition,
|
|
249
|
+
get telemetry() {
|
|
250
|
+
return instance.telemetry;
|
|
251
|
+
},
|
|
252
|
+
createInstance: () => createService2(definition),
|
|
253
|
+
execute: async (operation, input) => {
|
|
254
|
+
await instance.start();
|
|
255
|
+
return instance.call(operation, input);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
var GitHubProviderService = serviceFacade(github);
|
|
260
|
+
var GitLabProviderService = serviceFacade(gitlab);
|
|
261
|
+
var DropboxProviderService = serviceFacade(dropbox);
|
|
262
|
+
var BackblazeB2ProviderService = serviceFacade(backblaze);
|
|
263
|
+
var GoogleDriveProviderService = serviceFacade(drive);
|
|
264
|
+
|
|
265
|
+
// src/provider-services/saved-account-crypto.ts
|
|
266
|
+
var encoder = new TextEncoder();
|
|
267
|
+
var bytes = (value) => {
|
|
268
|
+
const buffer = new ArrayBuffer(value.byteLength);
|
|
269
|
+
new Uint8Array(buffer).set(value);
|
|
270
|
+
return buffer;
|
|
271
|
+
};
|
|
272
|
+
function b64(bytesValue) {
|
|
273
|
+
let raw = "";
|
|
274
|
+
for (const byte of bytesValue) raw += String.fromCharCode(byte);
|
|
275
|
+
return btoa(raw).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
276
|
+
}
|
|
277
|
+
function unb64(value) {
|
|
278
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(value))
|
|
279
|
+
throw new Error("INVALID_PROVIDER_CIPHERTEXT");
|
|
280
|
+
return Uint8Array.from(
|
|
281
|
+
atob(value.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(value.length / 4) * 4, "=")),
|
|
282
|
+
(char) => char.charCodeAt(0)
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
function aad(bound) {
|
|
286
|
+
return bytes(encoder.encode(JSON.stringify([
|
|
287
|
+
"ultrst-provider-account:v1",
|
|
288
|
+
bound.ownerUserId,
|
|
289
|
+
bound.workspaceId,
|
|
290
|
+
bound.id,
|
|
291
|
+
bound.providerId,
|
|
292
|
+
bound.resourceKind,
|
|
293
|
+
bound.accountScope,
|
|
294
|
+
bound.projectId,
|
|
295
|
+
bound.region
|
|
296
|
+
])));
|
|
297
|
+
}
|
|
298
|
+
async function importWrappingKey(key) {
|
|
299
|
+
if (!/^[a-zA-Z0-9_-]{43}$/.test(key))
|
|
300
|
+
throw new Error("PROVIDER_ENCRYPTION_KEY_INVALID");
|
|
301
|
+
const raw = unb64(key);
|
|
302
|
+
if (raw.byteLength !== 32) throw new Error("PROVIDER_ENCRYPTION_KEY_INVALID");
|
|
303
|
+
return crypto.subtle.importKey("raw", bytes(raw), { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
|
|
304
|
+
}
|
|
305
|
+
async function encryptSavedCredential(secret, key, bound) {
|
|
306
|
+
if (!secret || typeof secret !== "string")
|
|
307
|
+
throw new Error("PROVIDER_CREDENTIAL_REQUIRED");
|
|
308
|
+
const imported = await importWrappingKey(key);
|
|
309
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
310
|
+
const payload = await crypto.subtle.encrypt({
|
|
311
|
+
name: "AES-GCM",
|
|
312
|
+
iv: bytes(iv),
|
|
313
|
+
additionalData: aad(bound)
|
|
314
|
+
}, imported, bytes(encoder.encode(secret)));
|
|
315
|
+
return {
|
|
316
|
+
version: 1,
|
|
317
|
+
algorithm: "AES-GCM-256",
|
|
318
|
+
iv: b64(iv),
|
|
319
|
+
ciphertext: b64(new Uint8Array(payload))
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
async function decryptSavedCredential(envelope, key, bound) {
|
|
323
|
+
if (!envelope || envelope.version !== 1 || envelope.algorithm !== "AES-GCM-256" || typeof envelope.iv !== "string" || typeof envelope.ciphertext !== "string")
|
|
324
|
+
throw new Error("INVALID_PROVIDER_CIPHERTEXT");
|
|
325
|
+
try {
|
|
326
|
+
const iv = unb64(envelope.iv);
|
|
327
|
+
if (iv.byteLength !== 12) throw new Error("Invalid IV");
|
|
328
|
+
const plaintext = await crypto.subtle.decrypt({
|
|
329
|
+
name: "AES-GCM",
|
|
330
|
+
iv: bytes(iv),
|
|
331
|
+
additionalData: aad(bound)
|
|
332
|
+
}, await importWrappingKey(key), bytes(unb64(envelope.ciphertext)));
|
|
333
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(plaintext);
|
|
334
|
+
} catch {
|
|
335
|
+
throw new Error("PROVIDER_CREDENTIAL_DECRYPTION_DENIED");
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// src/provider-services/saved-account-probe.ts
|
|
340
|
+
var allowed = {
|
|
341
|
+
cloudflare: ["workers", "pages"],
|
|
342
|
+
vercel: ["projects", "deployments"],
|
|
343
|
+
fly: ["apps"],
|
|
344
|
+
railway: ["identity"],
|
|
345
|
+
render: ["services"],
|
|
346
|
+
"google-cloud-run": ["services"]
|
|
347
|
+
};
|
|
348
|
+
function validateSavedProviderInput(value) {
|
|
349
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
350
|
+
throw new Error("INVALID_PROVIDER_ACCOUNT");
|
|
351
|
+
const data = value;
|
|
352
|
+
const providerId = data.providerId;
|
|
353
|
+
const resourceKind = data.resourceKind;
|
|
354
|
+
if (typeof providerId !== "string" || typeof resourceKind !== "string" || !(providerId in allowed) || !allowed[providerId].includes(resourceKind))
|
|
355
|
+
throw new Error("UNSUPPORTED_PROVIDER_SCOPE");
|
|
356
|
+
const definition = getProviderService(providerId);
|
|
357
|
+
if (!definition || definition.status !== "ready" || !definition.apiImplemented)
|
|
358
|
+
throw new Error("PROVIDER_API_UNAVAILABLE");
|
|
359
|
+
if (typeof data.credential !== "string" || data.credential.length < 8 || data.credential.length > 4096 || !/^[\x21-\x7e]+$/.test(data.credential))
|
|
360
|
+
throw new Error("INVALID_PROVIDER_TOKEN");
|
|
361
|
+
const label = data.label === void 0 ? providerId : data.label;
|
|
362
|
+
const scope = data.accountScope === void 0 ? "" : data.accountScope;
|
|
363
|
+
const project = data.projectId === void 0 ? "" : data.projectId;
|
|
364
|
+
const region = data.region === void 0 ? "" : data.region;
|
|
365
|
+
if (typeof label !== "string" || !label.trim() || label.length > 120 || typeof scope !== "string" || scope.length > 128 || typeof project !== "string" || typeof region !== "string")
|
|
366
|
+
throw new Error("INVALID_PROVIDER_METADATA");
|
|
367
|
+
if (providerId === "cloudflare") {
|
|
368
|
+
if (!/^[a-fA-F0-9]{32}$/.test(scope)) throw new Error("CLOUDFLARE_ACCOUNT_REQUIRED");
|
|
369
|
+
} else if (providerId === "vercel") {
|
|
370
|
+
if (scope && !/^[a-zA-Z0-9_-]{1,128}$/.test(scope))
|
|
371
|
+
throw new Error("INVALID_VERCEL_TEAM");
|
|
372
|
+
} else if (scope) throw new Error("UNSUPPORTED_ACCOUNT_SCOPE");
|
|
373
|
+
if (providerId === "google-cloud-run") {
|
|
374
|
+
if (!/^[a-z][a-z0-9-]{4,61}[a-z0-9]$/.test(project) || !/^[a-z][a-z0-9-]{1,40}$/.test(region))
|
|
375
|
+
throw new Error("CLOUD_RUN_SCOPE_REQUIRED");
|
|
376
|
+
} else if (project || region) throw new Error("UNSUPPORTED_CLOUD_RUN_SCOPE");
|
|
377
|
+
return {
|
|
378
|
+
providerId,
|
|
379
|
+
resourceKind,
|
|
380
|
+
credential: data.credential,
|
|
381
|
+
label: label.trim(),
|
|
382
|
+
accountScope: scope,
|
|
383
|
+
projectId: project,
|
|
384
|
+
region
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
async function readProviderInventory(input, transport = fetch) {
|
|
388
|
+
const connection = {
|
|
389
|
+
providerId: input.providerId,
|
|
390
|
+
accountId: "verified-provider-connection",
|
|
391
|
+
credential: input.credential,
|
|
392
|
+
...input.accountScope ? { accountScope: input.accountScope } : {}
|
|
393
|
+
};
|
|
394
|
+
let values;
|
|
395
|
+
switch (input.providerId + ":" + input.resourceKind) {
|
|
396
|
+
case "cloudflare:workers":
|
|
397
|
+
values = (await listCloudflareWorkers(connection, transport)).map((r) => ({ id: r.id, name: r.id }));
|
|
398
|
+
break;
|
|
399
|
+
case "cloudflare:pages":
|
|
400
|
+
values = (await listCloudflarePages(connection, transport)).map((r) => ({ id: r.id || r.name, name: r.name }));
|
|
401
|
+
break;
|
|
402
|
+
case "vercel:projects":
|
|
403
|
+
values = (await listVercelProjects(connection, transport)).map((r) => ({ id: r.id, name: r.name }));
|
|
404
|
+
break;
|
|
405
|
+
case "vercel:deployments":
|
|
406
|
+
values = (await listVercelDeployments(connection, transport)).map((r) => ({ id: r.uid, name: r.name }));
|
|
407
|
+
break;
|
|
408
|
+
case "fly:apps":
|
|
409
|
+
values = (await listFlyApps(connection, transport)).map((r) => ({ id: r.name, name: r.name }));
|
|
410
|
+
break;
|
|
411
|
+
case "render:services":
|
|
412
|
+
values = (await listRenderServices(connection, transport)).map((r) => ({ id: r.service?.id, name: r.service?.name }));
|
|
413
|
+
break;
|
|
414
|
+
case "railway:identity": {
|
|
415
|
+
await getRailwayAccount(connection, transport);
|
|
416
|
+
values = [{ id: "verified", name: "Railway account authenticated" }];
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
case "google-cloud-run:services":
|
|
420
|
+
values = (await listGoogleCloudRunServices(
|
|
421
|
+
connection,
|
|
422
|
+
input.projectId,
|
|
423
|
+
input.region,
|
|
424
|
+
transport
|
|
425
|
+
)).map((r) => ({ id: r.name, name: r.name.split("/").pop() }));
|
|
426
|
+
break;
|
|
427
|
+
default:
|
|
428
|
+
throw new Error("UNSUPPORTED_PROVIDER_SCOPE");
|
|
429
|
+
}
|
|
430
|
+
if (!Array.isArray(values)) throw new Error("PROVIDER_RESPONSE_INVALID");
|
|
431
|
+
function safe(value) {
|
|
432
|
+
if (typeof value !== "string" || !value || value.length > 512)
|
|
433
|
+
throw new Error("PROVIDER_RESPONSE_INVALID");
|
|
434
|
+
return value.replaceAll(input.credential, "[redacted]");
|
|
435
|
+
}
|
|
436
|
+
return {
|
|
437
|
+
providerId: input.providerId,
|
|
438
|
+
resourceKind: input.resourceKind,
|
|
439
|
+
resources: values.slice(0, 50).map((r) => ({ id: safe(r.id), name: safe(r.name) })),
|
|
440
|
+
complete: false,
|
|
441
|
+
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/provider-services/saved-account-store.ts
|
|
446
|
+
var defaultQuery = (sql, params) => queryUnifiedDb(sql, params || []);
|
|
447
|
+
function assertOwner(owner) {
|
|
448
|
+
if (typeof owner !== "string" || !/^[a-zA-Z0-9_-]{1,160}$/.test(owner))
|
|
449
|
+
throw new Error("VERIFIED_OWNER_REQUIRED");
|
|
450
|
+
return owner;
|
|
451
|
+
}
|
|
452
|
+
function assertWorkspace(value) {
|
|
453
|
+
if (typeof value !== "string" || !/^[a-zA-Z0-9_-]{1,120}$/.test(value))
|
|
454
|
+
throw new Error("VERIFIED_WORKSPACE_REQUIRED");
|
|
455
|
+
return value;
|
|
456
|
+
}
|
|
457
|
+
function assertId(id) {
|
|
458
|
+
if (typeof id !== "string" || !/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i.test(id))
|
|
459
|
+
throw new Error("INVALID_PROVIDER_CONNECTION_ID");
|
|
460
|
+
return id;
|
|
461
|
+
}
|
|
462
|
+
function binding(row) {
|
|
463
|
+
return {
|
|
464
|
+
ownerUserId: row.owner_user_id,
|
|
465
|
+
workspaceId: row.workspace_id,
|
|
466
|
+
id: row.id,
|
|
467
|
+
providerId: row.provider_id,
|
|
468
|
+
resourceKind: row.resource_kind,
|
|
469
|
+
accountScope: row.account_scope,
|
|
470
|
+
projectId: row.project_id,
|
|
471
|
+
region: row.region
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function publicAccount(row) {
|
|
475
|
+
return {
|
|
476
|
+
id: row.id,
|
|
477
|
+
workspaceId: row.workspace_id,
|
|
478
|
+
providerId: row.provider_id,
|
|
479
|
+
resourceKind: row.resource_kind,
|
|
480
|
+
accountScope: row.account_scope,
|
|
481
|
+
projectId: row.project_id,
|
|
482
|
+
region: row.region,
|
|
483
|
+
label: row.label,
|
|
484
|
+
enabled: row.enabled,
|
|
485
|
+
checkedAt: new Date(row.checked_at).toISOString(),
|
|
486
|
+
createdAt: new Date(row.created_at).toISOString()
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
async function saveVerifiedProviderAccount(ownerUserId, workspaceId, input, options = {}) {
|
|
490
|
+
const owner = assertOwner(ownerUserId);
|
|
491
|
+
const workspace = assertWorkspace(workspaceId);
|
|
492
|
+
const parsed = validateSavedProviderInput(input);
|
|
493
|
+
const proof = await readProviderInventory(parsed, options.transport);
|
|
494
|
+
const query = options.query || defaultQuery;
|
|
495
|
+
const key = await getOrCreateStorageConnectionEncryptionKey(query);
|
|
496
|
+
const id = crypto.randomUUID();
|
|
497
|
+
const row = {
|
|
498
|
+
id,
|
|
499
|
+
owner_user_id: owner,
|
|
500
|
+
workspace_id: workspace,
|
|
501
|
+
provider_id: parsed.providerId,
|
|
502
|
+
resource_kind: parsed.resourceKind,
|
|
503
|
+
account_scope: parsed.accountScope,
|
|
504
|
+
project_id: parsed.projectId,
|
|
505
|
+
region: parsed.region,
|
|
506
|
+
label: parsed.label,
|
|
507
|
+
enabled: true,
|
|
508
|
+
checked_at: proof.checkedAt,
|
|
509
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
510
|
+
credential_envelope: {
|
|
511
|
+
version: 1,
|
|
512
|
+
algorithm: "AES-GCM-256",
|
|
513
|
+
iv: "",
|
|
514
|
+
ciphertext: ""
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
const envelope = await encryptSavedCredential(parsed.credential, key, binding(row));
|
|
518
|
+
const result = await query(
|
|
519
|
+
"INSERT INTO public.frnes_provider_accounts (id,owner_user_id,workspace_id,provider_id,resource_kind,account_scope,project_id,region,label,enabled,checked_at,credential_envelope) VALUES ($1::uuid,$2,$3,$4,$5,$6,$7,$8,$9,true,$10::timestamptz,$11::jsonb) RETURNING id,owner_user_id,workspace_id,provider_id,resource_kind,account_scope,project_id,region,label,enabled,checked_at,created_at",
|
|
520
|
+
[
|
|
521
|
+
id,
|
|
522
|
+
owner,
|
|
523
|
+
workspace,
|
|
524
|
+
parsed.providerId,
|
|
525
|
+
parsed.resourceKind,
|
|
526
|
+
parsed.accountScope,
|
|
527
|
+
parsed.projectId,
|
|
528
|
+
parsed.region,
|
|
529
|
+
parsed.label,
|
|
530
|
+
proof.checkedAt,
|
|
531
|
+
JSON.stringify(envelope)
|
|
532
|
+
]
|
|
533
|
+
);
|
|
534
|
+
if (!result.rows[0]) throw new Error("PROVIDER_ACCOUNT_PERSISTENCE_FAILED");
|
|
535
|
+
return publicAccount(result.rows[0]);
|
|
536
|
+
}
|
|
537
|
+
async function listSavedProviderAccounts(ownerUserId, workspaceId, query = defaultQuery) {
|
|
538
|
+
const owner = assertOwner(ownerUserId);
|
|
539
|
+
const workspace = assertWorkspace(workspaceId);
|
|
540
|
+
const result = await query(
|
|
541
|
+
"SELECT id,owner_user_id,workspace_id,provider_id,resource_kind,account_scope,project_id,region,label,enabled,checked_at,created_at FROM public.frnes_provider_accounts WHERE owner_user_id=$1 AND workspace_id=$2 AND revoked_at IS NULL ORDER BY created_at DESC LIMIT 100",
|
|
542
|
+
[owner, workspace]
|
|
543
|
+
);
|
|
544
|
+
return result.rows.map((row) => publicAccount(row));
|
|
545
|
+
}
|
|
546
|
+
async function resolveSavedProviderToken(ownerUserId, workspaceId, id, query) {
|
|
547
|
+
const owner = assertOwner(ownerUserId);
|
|
548
|
+
const workspace = assertWorkspace(workspaceId);
|
|
549
|
+
assertId(id);
|
|
550
|
+
const result = await query(
|
|
551
|
+
"SELECT id,owner_user_id,workspace_id,provider_id,resource_kind,account_scope,project_id,region,label,enabled,checked_at,created_at,credential_envelope FROM public.frnes_provider_accounts WHERE owner_user_id=$1 AND workspace_id=$2 AND id=$3::uuid AND enabled=true AND revoked_at IS NULL LIMIT 1",
|
|
552
|
+
[owner, workspace, id]
|
|
553
|
+
);
|
|
554
|
+
const row = result.rows[0];
|
|
555
|
+
if (!row) throw new Error("SAVED_PROVIDER_ACCESS_DENIED");
|
|
556
|
+
const key = await getStorageConnectionEncryptionKey(query);
|
|
557
|
+
const credential = await decryptSavedCredential(row.credential_envelope, key, binding(row));
|
|
558
|
+
return validateSavedProviderInput({
|
|
559
|
+
providerId: row.provider_id,
|
|
560
|
+
resourceKind: row.resource_kind,
|
|
561
|
+
label: row.label,
|
|
562
|
+
accountScope: row.account_scope,
|
|
563
|
+
projectId: row.project_id,
|
|
564
|
+
region: row.region,
|
|
565
|
+
credential
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
async function readSavedProviderAccount(ownerUserId, workspaceId, id, options = {}) {
|
|
569
|
+
const parsed = await resolveSavedProviderToken(
|
|
570
|
+
ownerUserId,
|
|
571
|
+
workspaceId,
|
|
572
|
+
id,
|
|
573
|
+
options.query || defaultQuery
|
|
574
|
+
);
|
|
575
|
+
return readProviderInventory(parsed, options.transport);
|
|
576
|
+
}
|
|
577
|
+
async function revokeSavedProviderAccount(ownerUserId, workspaceId, id, query = defaultQuery) {
|
|
578
|
+
const owner = assertOwner(ownerUserId);
|
|
579
|
+
const workspace = assertWorkspace(workspaceId);
|
|
580
|
+
assertId(id);
|
|
581
|
+
const result = await query(
|
|
582
|
+
"UPDATE public.frnes_provider_accounts SET revoked_at=now(),enabled=false WHERE owner_user_id=$1 AND workspace_id=$2 AND id=$3::uuid AND revoked_at IS NULL RETURNING id",
|
|
583
|
+
[owner, workspace, id]
|
|
584
|
+
);
|
|
585
|
+
return result.rows.length === 1;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export {
|
|
589
|
+
CloudflareProviderService,
|
|
590
|
+
VercelProviderService,
|
|
591
|
+
GoogleAccountProviderService,
|
|
592
|
+
GeminiProviderService,
|
|
593
|
+
GitHubProviderService,
|
|
594
|
+
GitLabProviderService,
|
|
595
|
+
DropboxProviderService,
|
|
596
|
+
BackblazeB2ProviderService,
|
|
597
|
+
GoogleDriveProviderService,
|
|
598
|
+
saveVerifiedProviderAccount,
|
|
599
|
+
listSavedProviderAccounts,
|
|
600
|
+
readSavedProviderAccount,
|
|
601
|
+
revokeSavedProviderAccount
|
|
602
|
+
};
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
deleteWorkspaceFolder,
|
|
3
3
|
readWorkspaceFile,
|
|
4
4
|
writeWorkspaceFile
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-3SDRLTD6.js";
|
|
6
6
|
import {
|
|
7
7
|
createGoogleDriveWorkspaceClient,
|
|
8
8
|
listUserStorageConnections,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
resolveUserWorkspaceStorageAssociation,
|
|
11
11
|
testBackblazeCredentials,
|
|
12
12
|
toPublicStorageConnection
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-PAU25K7F.js";
|
|
14
14
|
import {
|
|
15
15
|
queryUnifiedDb
|
|
16
16
|
} from "./chunk-3RTRATDJ.js";
|
|
@@ -151,7 +151,55 @@ async function fetchVercelCapacity(connection, options, now = /* @__PURE__ */ ne
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
// src/provider-services/compute-operations.ts
|
|
155
|
+
function connectionFor(input, expected) {
|
|
156
|
+
if (input.providerId !== expected) throw new Error("Credential/provider mismatch");
|
|
157
|
+
return input;
|
|
158
|
+
}
|
|
159
|
+
function requiredProject(input, name, pattern) {
|
|
160
|
+
if (!pattern.test(input)) throw new Error("Invalid " + name);
|
|
161
|
+
return input;
|
|
162
|
+
}
|
|
163
|
+
async function getRailwayAccount(connection, transport = fetch) {
|
|
164
|
+
const client = createProviderClient(connectionFor(connection, "railway"), transport);
|
|
165
|
+
const { data } = await client.request({
|
|
166
|
+
path: "/graphql/v2",
|
|
167
|
+
method: "POST",
|
|
168
|
+
body: { query: "query FrnesIdentity { me { name email } }" }
|
|
169
|
+
});
|
|
170
|
+
if (data.errors?.length || !data.data?.me || typeof data.data.me !== "object" || !(typeof data.data.me.email === "string" && data.data.me.email.trim() || typeof data.data.me.name === "string" && data.data.me.name.trim()))
|
|
171
|
+
throw new Error("Railway account token could not be authorized");
|
|
172
|
+
return data.data.me;
|
|
173
|
+
}
|
|
174
|
+
async function listFlyApps(connection, transport = fetch) {
|
|
175
|
+
const client = createProviderClient(connectionFor(connection, "fly"), transport);
|
|
176
|
+
const { data } = await client.request({ path: "/v1/apps" });
|
|
177
|
+
if (!Array.isArray(data?.apps) || data.apps.some((item) => typeof item.name !== "string" || !item.name))
|
|
178
|
+
throw new Error("Invalid Fly Machines app listing");
|
|
179
|
+
return data.apps;
|
|
180
|
+
}
|
|
181
|
+
async function listRenderServices(connection, transport = fetch) {
|
|
182
|
+
const client = createProviderClient(connectionFor(connection, "render"), transport);
|
|
183
|
+
const { data } = await client.request({ path: "/v1/services", query: { limit: 20 } });
|
|
184
|
+
if (!Array.isArray(data) || data.some((item) => typeof item.service?.id !== "string" || !item.service.id || typeof item.service.name !== "string" || !item.service.name))
|
|
185
|
+
throw new Error("Invalid Render services response");
|
|
186
|
+
return data;
|
|
187
|
+
}
|
|
188
|
+
async function listGoogleCloudRunServices(connection, project, region, transport = fetch) {
|
|
189
|
+
connectionFor(connection, "google-cloud-run");
|
|
190
|
+
const projectId = requiredProject(project, "Google project ID", /^[a-z][a-z0-9-]{4,61}[a-z0-9]$/);
|
|
191
|
+
const location = requiredProject(region, "Google Cloud location", /^[a-z][a-z0-9-]{1,40}$/);
|
|
192
|
+
const { data } = await createProviderClient(connection, transport).request({ path: `/v2/projects/${projectId}/locations/${location}/services` });
|
|
193
|
+
if (!data || data.services !== void 0 && (!Array.isArray(data.services) || data.services.some((item) => typeof item.name !== "string" || !item.name)))
|
|
194
|
+
throw new Error("Invalid Cloud Run service listing");
|
|
195
|
+
return data.services || [];
|
|
196
|
+
}
|
|
197
|
+
|
|
154
198
|
export {
|
|
155
199
|
fetchCloudflareCapacity,
|
|
156
|
-
fetchVercelCapacity
|
|
200
|
+
fetchVercelCapacity,
|
|
201
|
+
getRailwayAccount,
|
|
202
|
+
listFlyApps,
|
|
203
|
+
listRenderServices,
|
|
204
|
+
listGoogleCloudRunServices
|
|
157
205
|
};
|