@ultrst-armada/kloks 2.0.3 → 2.0.5
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/package.json +6 -1
- package/packages/backend/dist/api/index.js +2 -1
- package/packages/backend/dist/{chunk-5F5V7NAG.js → chunk-5Y7K7HAT.js} +4 -1
- package/packages/backend/dist/{chunk-SQKG3S6P.js → chunk-AUNIGE6Q.js} +2 -2
- package/packages/backend/dist/chunk-BRNWUIH5.js +197 -0
- package/packages/backend/dist/{chunk-NY2SQOXI.js → chunk-CDRHYO44.js} +4 -1
- package/packages/backend/dist/{chunk-ZBNSK26X.js → chunk-CV55JMT7.js} +6 -5
- package/packages/backend/dist/{chunk-OWMQLML7.js → chunk-EMSSTOOK.js} +33 -2
- package/packages/backend/dist/chunk-FSOOAU6G.js +1132 -0
- package/packages/backend/dist/chunk-GVMVYC6C.js +0 -0
- package/packages/backend/dist/chunk-I6T64MLT.js +171 -0
- package/packages/backend/dist/chunk-ICVDGH2I.js +889 -0
- package/packages/backend/dist/chunk-IP6XWQU2.js +48 -0
- package/packages/backend/dist/chunk-IRNQXVYA.js +746 -0
- package/packages/backend/dist/{chunk-POLVHTHJ.js → chunk-KCPQWJBO.js} +4 -1
- package/packages/backend/dist/chunk-LC6ULEM2.js +125 -0
- package/packages/backend/dist/{chunk-NTKUQVCQ.js → chunk-LMUMMVTU.js} +14 -2
- package/packages/backend/dist/chunk-LMY6MGFD.js +78 -0
- package/packages/backend/dist/{chunk-OQRQCDS6.js → chunk-TRJVVNO7.js} +2 -2
- package/packages/backend/dist/{chunk-KPLDYX5Z.js → chunk-TRP76UR2.js} +33 -26
- package/packages/backend/dist/{chunk-FK3OAUXM.js → chunk-WYEVA4RC.js} +4 -2
- package/packages/backend/dist/{chunk-Z6G32NQQ.js → chunk-XKUWLO2M.js} +12 -9
- package/packages/backend/dist/{chunk-OXEP3AP6.js → chunk-Z2CT2MJ2.js} +158 -1
- package/packages/backend/dist/control-plane/index.js +3 -1
- package/packages/backend/dist/core/b2DirectCore.test.d.ts +1 -0
- package/packages/backend/dist/core/cloudflareIntegrationCore.test.d.ts +1 -0
- package/packages/backend/dist/core/googleDriveOAuthCore.d.ts +51 -0
- package/packages/backend/dist/core/googleDriveOAuthCore.test.d.ts +1 -0
- package/packages/backend/dist/core/index.d.ts +3 -0
- package/packages/backend/dist/core/storageConnectionCore.d.ts +136 -0
- package/packages/backend/dist/core/storageConnectionCore.test.d.ts +1 -0
- package/packages/backend/dist/core/storageConnectionRuntimeCore.d.ts +57 -0
- package/packages/backend/dist/core/storageConnectionRuntimeCore.test.d.ts +1 -0
- package/packages/backend/dist/core/storageContracts.d.ts +77 -0
- package/packages/backend/dist/core/storageProviderRegistry.d.ts +7 -0
- package/packages/backend/dist/core/systemCredentialsCore.d.ts +46 -0
- package/packages/backend/dist/core/unifiedDb.d.ts +12 -2
- package/packages/backend/dist/core/unifiedDb.errors.test.d.ts +1 -0
- package/packages/backend/dist/core/unifiedDbNodeAdapter.d.ts +6 -0
- package/packages/backend/dist/core/workspaceBucketSyncCore.d.ts +3 -4
- package/packages/backend/dist/core/workspaceBucketSyncCore.test.d.ts +1 -0
- package/packages/backend/dist/core/workspaceCore.d.ts +25 -6
- package/packages/backend/dist/core/workspaceDataCore.test.d.ts +1 -0
- package/packages/backend/dist/core/workspaceFileCore.d.ts +25 -7
- package/packages/backend/dist/core/workspaceFileCore.test.d.ts +1 -0
- package/packages/backend/dist/core/workspaceFileNodeAdapter.d.ts +6 -0
- package/packages/backend/dist/core/workspaceStorageDetailsCore.d.ts +4 -8
- package/packages/backend/dist/core/workspaceStorageDetailsCore.test.d.ts +1 -0
- package/packages/backend/dist/development/index.js +1 -1
- package/packages/backend/dist/development/playwrightInspectionService.js +1 -1
- package/packages/backend/dist/development/playwrightInspectionSupport.d.ts +1 -0
- package/packages/backend/dist/index.js +22 -16
- package/packages/backend/dist/krnl-services.d.ts +0 -22
- package/packages/backend/dist/krnl-services.js +8 -19
- package/packages/backend/dist/krnl-services.node.d.ts +28 -0
- package/packages/backend/dist/node.d.ts +3 -0
- package/packages/backend/dist/node.js +645 -463
- package/packages/backend/dist/resolver/index.js +13 -0
- package/packages/backend/dist/resolver/systemDatabaseUrl.d.ts +16 -12
- package/packages/backend/dist/services/node.js +12 -10
- package/packages/backend/dist/srkl/index.js +6 -4
- package/packages/backend/dist/storage/B2DirectClient.d.ts +7 -13
- package/packages/backend/dist/storage/B2DirectClient.test.d.ts +1 -0
- package/packages/backend/dist/storage/GoogleDriveWorkspaceService.d.ts +5 -0
- package/packages/backend/dist/storage/index.js +4 -3
- package/packages/backend/dist/storage/node.js +7 -6
- package/packages/backend/dist/storage-workspace.js +1 -1
- package/packages/backend/dist/workspace/index.js +2 -1
- package/packages/backend/dist/workspace/node.js +12 -7
- package/packages/backend/dist/workspaceFileCore-UURQPP62.js +28 -0
- package/packages/backend/package.json +8 -3
- package/packages/services/dist/index.js +8 -2
- package/packages/state-graph/dist/browser.js +16 -16
- package/packages/state-graph/dist/index.js +16 -16
- package/packages/backend/dist/chunk-4QEMALXF.js +0 -90
- package/packages/backend/dist/chunk-AOZSDRNY.js +0 -159
- package/packages/backend/dist/chunk-GYSZ6CAX.js +0 -19
- package/packages/backend/dist/chunk-JCMB7BIM.js +0 -211
- package/packages/backend/dist/chunk-JGUWYVOL.js +0 -570
- package/packages/backend/dist/chunk-LMOM7CST.js +0 -427
- package/packages/state-graph/dist/{chunk-UKTICGGV.js → chunk-YUJC367F.js} +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultrst-armada/kloks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -87,6 +87,11 @@
|
|
|
87
87
|
"import": "./packages/backend/dist/krnl-services.js",
|
|
88
88
|
"default": "./packages/backend/dist/krnl-services.js"
|
|
89
89
|
},
|
|
90
|
+
"./backend/resolver": {
|
|
91
|
+
"types": "./packages/backend/dist/resolver/index.d.ts",
|
|
92
|
+
"import": "./packages/backend/dist/resolver/index.js",
|
|
93
|
+
"default": "./packages/backend/dist/resolver/index.js"
|
|
94
|
+
},
|
|
90
95
|
"./orchestrations": {
|
|
91
96
|
"types": "./packages/orchestrations/dist/index.d.ts",
|
|
92
97
|
"import": "./packages/orchestrations/dist/index.js",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
GoogleDriveStorageService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TRJVVNO7.js";
|
|
4
4
|
import {
|
|
5
5
|
normalizeBackblazeCredentials,
|
|
6
6
|
resolveBackblazeEndpoint
|
|
7
7
|
} from "./chunk-HUY4272L.js";
|
|
8
8
|
import {
|
|
9
9
|
BaseStorageAdapter
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-5Y7K7HAT.js";
|
|
11
11
|
|
|
12
12
|
// src/storage/LocalFSAdapter.ts
|
|
13
13
|
import { promises as fs } from "fs";
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createGoogleDriveWorkspaceClient,
|
|
3
|
+
queryUnifiedDb
|
|
4
|
+
} from "./chunk-FSOOAU6G.js";
|
|
5
|
+
import {
|
|
6
|
+
b2DeleteFileVersion,
|
|
7
|
+
b2DeleteFolder,
|
|
8
|
+
b2DownloadFile,
|
|
9
|
+
b2ListFileNames,
|
|
10
|
+
b2UploadFile
|
|
11
|
+
} from "./chunk-I6T64MLT.js";
|
|
12
|
+
|
|
13
|
+
// src/core/workspaceFileCore.ts
|
|
14
|
+
var localWorkspaceFileAdapter = null;
|
|
15
|
+
function configureLocalWorkspaceFileAdapter(adapter) {
|
|
16
|
+
localWorkspaceFileAdapter = adapter;
|
|
17
|
+
}
|
|
18
|
+
function normalizeWorkspaceStoragePath(value, allowEmpty = false) {
|
|
19
|
+
const normalized = String(value || "").replace(/\\/g, "/");
|
|
20
|
+
if (!normalized && allowEmpty) return "";
|
|
21
|
+
if (!normalized || normalized.startsWith("/") || /^[A-Za-z]:(?:$|\/)/.test(normalized) || normalized.includes("\0")) {
|
|
22
|
+
throw new Error("Storage path must be a safe workspace-relative path.");
|
|
23
|
+
}
|
|
24
|
+
const segments = normalized.split("/");
|
|
25
|
+
if (segments.some((segment) => !segment || segment === "." || segment === "..")) {
|
|
26
|
+
throw new Error("Storage path must not contain empty, current-directory, or parent-directory segments.");
|
|
27
|
+
}
|
|
28
|
+
return segments.join("/");
|
|
29
|
+
}
|
|
30
|
+
function getWorkspaceFolderPrefix(workspace) {
|
|
31
|
+
const raw = workspace?.localFolderKey || workspace?.localFolderName || (workspace?.workspacePath ? workspace.workspacePath.replace(/^\.\//, "") : workspace?.id);
|
|
32
|
+
return normalizeWorkspaceStoragePath(String(raw || ""));
|
|
33
|
+
}
|
|
34
|
+
function getWorkspaceFilePath(workspace, relativePath) {
|
|
35
|
+
return `${getWorkspaceFolderPrefix(workspace)}/${normalizeWorkspaceStoragePath(relativePath)}`;
|
|
36
|
+
}
|
|
37
|
+
function isB2Workspace(workspace, connection) {
|
|
38
|
+
return connection?.provider === "backblaze_b2" || connection?.provider === "BACKBLAZE_B2" || workspace?.storageProvider === "backblaze_b2";
|
|
39
|
+
}
|
|
40
|
+
function isGoogleDriveWorkspace(workspace, connection) {
|
|
41
|
+
return connection?.provider === "google_drive" || workspace?.storageProvider === "google_drive";
|
|
42
|
+
}
|
|
43
|
+
async function getGoogleDriveClient(workspace, connection, env) {
|
|
44
|
+
const userId = String(connection?.__ownerUserId || workspace?.__ownerUserId || "").trim();
|
|
45
|
+
const connectionId = String(connection?.id || workspace?.storageConnectionId || "").trim();
|
|
46
|
+
if (!userId || !connectionId) {
|
|
47
|
+
throw new Error("Google Drive workspace operations require an owned storage connection reference.");
|
|
48
|
+
}
|
|
49
|
+
return createGoogleDriveWorkspaceClient(
|
|
50
|
+
userId,
|
|
51
|
+
connectionId,
|
|
52
|
+
(sql, params) => queryUnifiedDb(sql, params, env),
|
|
53
|
+
workspace?.googleRootFolderId || connection?.googleRootFolderId || "root"
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
function getB2Settings(workspace, connection) {
|
|
57
|
+
const keyId = String(connection?.b2KeyId || connection?.keyId || connection?.accessKeyId || "").trim();
|
|
58
|
+
const applicationKey = String(
|
|
59
|
+
connection?.b2ApplicationKey || connection?.applicationKey || connection?.appKey || connection?.secretAccessKey || ""
|
|
60
|
+
).trim();
|
|
61
|
+
const bucketName = String(connection?.b2BucketName || connection?.bucketName || workspace?.b2BucketName || "").trim();
|
|
62
|
+
if (!keyId || !applicationKey || !bucketName) {
|
|
63
|
+
throw new Error("The Backblaze workspace connection is missing its server-side credentials or bucket.");
|
|
64
|
+
}
|
|
65
|
+
return { keyId, applicationKey, bucketName };
|
|
66
|
+
}
|
|
67
|
+
async function writeWorkspaceFile(workspace, connection, relativePath, content, contentType = "application/json", env) {
|
|
68
|
+
const targetPath = getWorkspaceFilePath(workspace, relativePath);
|
|
69
|
+
const bytes = typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
70
|
+
if (isGoogleDriveWorkspace(workspace, connection)) {
|
|
71
|
+
const drive = await getGoogleDriveClient(workspace, connection, env);
|
|
72
|
+
await drive.write(targetPath, bytes, contentType);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (isB2Workspace(workspace, connection)) {
|
|
76
|
+
const config = getB2Settings(workspace, connection);
|
|
77
|
+
await b2UploadFile(
|
|
78
|
+
config.keyId,
|
|
79
|
+
config.applicationKey,
|
|
80
|
+
config.bucketName,
|
|
81
|
+
targetPath,
|
|
82
|
+
bytes,
|
|
83
|
+
contentType
|
|
84
|
+
);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!localWorkspaceFileAdapter) throw new Error("Local filesystem operations require the explicit Kloks Node backend adapter.");
|
|
88
|
+
await localWorkspaceFileAdapter.write(targetPath, bytes);
|
|
89
|
+
}
|
|
90
|
+
async function readWorkspaceFile(workspace, connection, relativePath, env) {
|
|
91
|
+
const targetPath = getWorkspaceFilePath(workspace, relativePath);
|
|
92
|
+
if (isGoogleDriveWorkspace(workspace, connection)) {
|
|
93
|
+
const drive = await getGoogleDriveClient(workspace, connection, env);
|
|
94
|
+
try {
|
|
95
|
+
return await drive.read(targetPath);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error instanceof Error && /not found|HTTP 404/i.test(error.message)) return null;
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (isB2Workspace(workspace, connection)) {
|
|
102
|
+
const config = getB2Settings(workspace, connection);
|
|
103
|
+
return b2DownloadFile(config.keyId, config.applicationKey, config.bucketName, targetPath);
|
|
104
|
+
}
|
|
105
|
+
if (!localWorkspaceFileAdapter) return null;
|
|
106
|
+
return localWorkspaceFileAdapter.read(targetPath);
|
|
107
|
+
}
|
|
108
|
+
async function deleteWorkspaceFile(workspace, connection, relativePath, env) {
|
|
109
|
+
const targetPath = getWorkspaceFilePath(workspace, relativePath);
|
|
110
|
+
if (isGoogleDriveWorkspace(workspace, connection)) {
|
|
111
|
+
const drive = await getGoogleDriveClient(workspace, connection, env);
|
|
112
|
+
await drive.delete(targetPath);
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
if (isB2Workspace(workspace, connection)) {
|
|
116
|
+
const config = getB2Settings(workspace, connection);
|
|
117
|
+
const fullKey = targetPath;
|
|
118
|
+
const files = await b2ListFileNames(config.keyId, config.applicationKey, config.bucketName, fullKey);
|
|
119
|
+
const match = files.find((file) => file.fileName === fullKey);
|
|
120
|
+
if (!match) return false;
|
|
121
|
+
await b2DeleteFileVersion(config.keyId, config.applicationKey, match.fileName, match.fileId);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if (!localWorkspaceFileAdapter) return false;
|
|
125
|
+
return localWorkspaceFileAdapter.delete(targetPath);
|
|
126
|
+
}
|
|
127
|
+
async function listWorkspaceFiles(workspace, connection, subPrefix = "", env) {
|
|
128
|
+
const folderPrefix = getWorkspaceFolderPrefix(workspace);
|
|
129
|
+
const cleanSubPrefix = normalizeWorkspaceStoragePath(subPrefix, true);
|
|
130
|
+
const targetPrefix = cleanSubPrefix ? `${folderPrefix}/${cleanSubPrefix}` : folderPrefix;
|
|
131
|
+
if (isGoogleDriveWorkspace(workspace, connection)) {
|
|
132
|
+
const drive = await getGoogleDriveClient(workspace, connection, env);
|
|
133
|
+
const files2 = await drive.list(targetPrefix);
|
|
134
|
+
return files2.map((file) => ({
|
|
135
|
+
fileName: file.path.startsWith(folderPrefix + "/") ? file.path.slice(folderPrefix.length + 1) : file.path,
|
|
136
|
+
sizeBytes: file.size,
|
|
137
|
+
uploadTimestamp: file.modifiedAt
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
if (isB2Workspace(workspace, connection)) {
|
|
141
|
+
const config = getB2Settings(workspace, connection);
|
|
142
|
+
const b2TargetPrefix = cleanSubPrefix ? `${targetPrefix}/` : `${folderPrefix}/`;
|
|
143
|
+
const files2 = await b2ListFileNames(config.keyId, config.applicationKey, config.bucketName, b2TargetPrefix);
|
|
144
|
+
return files2.map((file) => ({
|
|
145
|
+
fileName: String(file.fileName || "").slice(folderPrefix.length + 1),
|
|
146
|
+
sizeBytes: Number(file.contentLength || 0),
|
|
147
|
+
uploadTimestamp: file.uploadTimestamp
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
if (!localWorkspaceFileAdapter) return [];
|
|
151
|
+
const files = await localWorkspaceFileAdapter.list(targetPrefix);
|
|
152
|
+
return files.map((file) => ({
|
|
153
|
+
...file,
|
|
154
|
+
fileName: file.fileName.startsWith(`${folderPrefix}/`) ? file.fileName.slice(folderPrefix.length + 1) : file.fileName
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
async function deleteWorkspaceFolder(workspace, connection, env) {
|
|
158
|
+
const folderPrefix = getWorkspaceFolderPrefix(workspace);
|
|
159
|
+
if (isGoogleDriveWorkspace(workspace, connection)) {
|
|
160
|
+
const drive = await getGoogleDriveClient(workspace, connection, env);
|
|
161
|
+
const removeTree = async (relativePath) => {
|
|
162
|
+
let entries = [];
|
|
163
|
+
try {
|
|
164
|
+
entries = await drive.list(relativePath);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error instanceof Error && /not found|HTTP 404/i.test(error.message)) return;
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
for (const entry of entries) {
|
|
170
|
+
if (entry.isFolder) await removeTree(entry.path);
|
|
171
|
+
else await drive.delete(entry.path);
|
|
172
|
+
}
|
|
173
|
+
if (relativePath) await drive.delete(relativePath);
|
|
174
|
+
};
|
|
175
|
+
await removeTree(folderPrefix);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (isB2Workspace(workspace, connection)) {
|
|
179
|
+
const config = getB2Settings(workspace, connection);
|
|
180
|
+
await b2DeleteFolder(config.keyId, config.applicationKey, config.bucketName, folderPrefix);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (localWorkspaceFileAdapter) await localWorkspaceFileAdapter.deleteFolder(folderPrefix);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export {
|
|
187
|
+
configureLocalWorkspaceFileAdapter,
|
|
188
|
+
normalizeWorkspaceStoragePath,
|
|
189
|
+
getWorkspaceFolderPrefix,
|
|
190
|
+
isB2Workspace,
|
|
191
|
+
isGoogleDriveWorkspace,
|
|
192
|
+
writeWorkspaceFile,
|
|
193
|
+
readWorkspaceFile,
|
|
194
|
+
deleteWorkspaceFile,
|
|
195
|
+
listWorkspaceFiles,
|
|
196
|
+
deleteWorkspaceFolder
|
|
197
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SkipoBase
|
|
3
|
+
} from "./chunk-LMY6MGFD.js";
|
|
4
|
+
|
|
1
5
|
// src/workspace/WorkspaceCloneSyncEngine.ts
|
|
2
|
-
import { SkipoBase } from "@ultrst-armada/kloks/functions/base";
|
|
3
6
|
var WorkspaceCloneSyncEngine = class extends SkipoBase {
|
|
4
7
|
constructor() {
|
|
5
8
|
super({ name: "WorkspaceCloneSyncEngine" });
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SkipoBase
|
|
3
|
+
} from "./chunk-LMY6MGFD.js";
|
|
4
|
+
|
|
1
5
|
// src/control-plane/AuditLogger.ts
|
|
2
6
|
import { promises as fs } from "fs";
|
|
3
7
|
import path from "path";
|
|
4
|
-
import { SkipoBase } from "@ultrst-armada/kloks/functions/base";
|
|
5
8
|
var AuditLogger = class extends SkipoBase {
|
|
6
9
|
logFile;
|
|
7
10
|
constructor(logFile = ".skipo/audit.jsonl") {
|
|
@@ -41,8 +44,7 @@ var AuditLogger = class extends SkipoBase {
|
|
|
41
44
|
};
|
|
42
45
|
|
|
43
46
|
// src/control-plane/DatabaseClusterManager.ts
|
|
44
|
-
|
|
45
|
-
var DatabaseClusterManager = class _DatabaseClusterManager extends SkipoBase2 {
|
|
47
|
+
var DatabaseClusterManager = class _DatabaseClusterManager extends SkipoBase {
|
|
46
48
|
config;
|
|
47
49
|
health = /* @__PURE__ */ new Map();
|
|
48
50
|
constructor(config) {
|
|
@@ -116,8 +118,7 @@ function resolveSystemDatabaseClusterNodes(env = process.env) {
|
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
// src/control-plane/ControlPlaneManager.ts
|
|
119
|
-
|
|
120
|
-
var ControlPlaneManager = class extends SkipoBase3 {
|
|
121
|
+
var ControlPlaneManager = class extends SkipoBase {
|
|
121
122
|
auth;
|
|
122
123
|
audit;
|
|
123
124
|
cluster;
|
|
@@ -42,7 +42,11 @@ function quoteDriveQuery(value) {
|
|
|
42
42
|
return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
43
43
|
}
|
|
44
44
|
async function parseJson(response) {
|
|
45
|
-
|
|
45
|
+
try {
|
|
46
|
+
return await response.json();
|
|
47
|
+
} catch {
|
|
48
|
+
throw new Error("Google Drive returned an invalid JSON response.");
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
51
|
async function persistTokensSafely(persistTokens, tokens) {
|
|
48
52
|
if (!persistTokens) return;
|
|
@@ -234,7 +238,10 @@ var GoogleDriveWorkspaceService = class _GoogleDriveWorkspaceService {
|
|
|
234
238
|
url.searchParams.set("includeItemsFromAllDrives", "true");
|
|
235
239
|
if (pageToken) url.searchParams.set("pageToken", pageToken);
|
|
236
240
|
const data = await parseJson(await this.api(url.toString()));
|
|
237
|
-
if (Array.isArray(data.files))
|
|
241
|
+
if (!Array.isArray(data.files)) {
|
|
242
|
+
throw new Error("Google Drive file listing returned an invalid response.");
|
|
243
|
+
}
|
|
244
|
+
files.push(...data.files);
|
|
238
245
|
pageToken = typeof data.nextPageToken === "string" ? data.nextPageToken : "";
|
|
239
246
|
} while (pageToken);
|
|
240
247
|
return files;
|
|
@@ -291,7 +298,31 @@ var GoogleDriveWorkspaceService = class _GoogleDriveWorkspaceService {
|
|
|
291
298
|
...typeof data.user?.emailAddress === "string" ? { email: data.user.emailAddress } : {}
|
|
292
299
|
};
|
|
293
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Folder browsing is always rooted at the persisted workspace root. A caller
|
|
303
|
+
* may browse a descendant, but cannot supply an unrelated Drive folder ID.
|
|
304
|
+
*/
|
|
305
|
+
async assertFolderWithinRoot(folderId) {
|
|
306
|
+
const rootId = this.options.rootFolderId || "root";
|
|
307
|
+
if (!folderId || folderId === rootId) return;
|
|
308
|
+
const pending = [folderId];
|
|
309
|
+
const visited = /* @__PURE__ */ new Set();
|
|
310
|
+
while (pending.length && visited.size < 128) {
|
|
311
|
+
const current = pending.shift();
|
|
312
|
+
if (current === rootId) return;
|
|
313
|
+
if (current === "root" && rootId !== "root") break;
|
|
314
|
+
if (visited.has(current)) continue;
|
|
315
|
+
visited.add(current);
|
|
316
|
+
const folder = await this.resolveFolder(current);
|
|
317
|
+
for (const parentId of folder.parentIds) {
|
|
318
|
+
if (parentId === rootId) return;
|
|
319
|
+
if (!visited.has(parentId)) pending.push(parentId);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
throw new Error("The selected Google Drive folder is outside the configured workspace root.");
|
|
323
|
+
}
|
|
294
324
|
async listFolders(parentFolderId = this.options.rootFolderId || "root") {
|
|
325
|
+
await this.assertFolderWithinRoot(parentFolderId);
|
|
295
326
|
const files = await this.listFiles(
|
|
296
327
|
parentFolderId,
|
|
297
328
|
`mimeType = '${FOLDER_MIME_TYPE}' and trashed = false`
|