@fractary/core 0.3.3 → 0.5.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/__tests__/factories.test.d.ts +5 -0
- package/dist/__tests__/factories.test.d.ts.map +1 -0
- package/dist/__tests__/factories.test.js +66 -0
- package/dist/__tests__/factories.test.js.map +1 -0
- package/dist/auth/__tests__/create-token-provider.test.d.ts +5 -0
- package/dist/auth/__tests__/create-token-provider.test.d.ts.map +1 -0
- package/dist/auth/__tests__/create-token-provider.test.js +104 -0
- package/dist/auth/__tests__/create-token-provider.test.js.map +1 -0
- package/dist/auth/__tests__/github-app-auth.test.d.ts +5 -0
- package/dist/auth/__tests__/github-app-auth.test.d.ts.map +1 -0
- package/dist/auth/__tests__/github-app-auth.test.js +293 -0
- package/dist/auth/__tests__/github-app-auth.test.js.map +1 -0
- package/dist/auth/__tests__/static-token-provider.test.d.ts +5 -0
- package/dist/auth/__tests__/static-token-provider.test.d.ts.map +1 -0
- package/dist/auth/__tests__/static-token-provider.test.js +54 -0
- package/dist/auth/__tests__/static-token-provider.test.js.map +1 -0
- package/dist/auth/github-app-auth.d.ts +109 -0
- package/dist/auth/github-app-auth.d.ts.map +1 -0
- package/dist/auth/github-app-auth.js +262 -0
- package/dist/auth/github-app-auth.js.map +1 -0
- package/dist/auth/github-app-token-provider.d.ts +59 -0
- package/dist/auth/github-app-token-provider.d.ts.map +1 -0
- package/dist/auth/github-app-token-provider.js +68 -0
- package/dist/auth/github-app-token-provider.js.map +1 -0
- package/dist/auth/index.d.ts +45 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +74 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/static-token-provider.d.ts +35 -0
- package/dist/auth/static-token-provider.d.ts.map +1 -0
- package/dist/auth/static-token-provider.js +45 -0
- package/dist/auth/static-token-provider.js.map +1 -0
- package/dist/auth/types.d.ts +49 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +8 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/common/__tests__/secrets.test.d.ts +7 -0
- package/dist/common/__tests__/secrets.test.d.ts.map +1 -0
- package/dist/common/__tests__/secrets.test.js +320 -0
- package/dist/common/__tests__/secrets.test.js.map +1 -0
- package/dist/common/config.d.ts +6 -4
- package/dist/common/config.d.ts.map +1 -1
- package/dist/common/config.js +4 -30
- package/dist/common/config.js.map +1 -1
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +1 -0
- package/dist/common/index.js.map +1 -1
- package/dist/common/secrets.d.ts +68 -0
- package/dist/common/secrets.d.ts.map +1 -0
- package/dist/common/secrets.js +180 -0
- package/dist/common/secrets.js.map +1 -0
- package/dist/common/yaml-config.d.ts +10 -0
- package/dist/common/yaml-config.d.ts.map +1 -1
- package/dist/common/yaml-config.js.map +1 -1
- package/dist/config/__tests__/loader.test.d.ts +5 -0
- package/dist/config/__tests__/loader.test.d.ts.map +1 -0
- package/dist/config/__tests__/loader.test.js +129 -0
- package/dist/config/__tests__/loader.test.js.map +1 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +27 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +126 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +277 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/docs/index.d.ts +5 -0
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +6 -1
- package/dist/docs/index.js.map +1 -1
- package/dist/docs/manager.d.ts +27 -0
- package/dist/docs/manager.d.ts.map +1 -1
- package/dist/docs/manager.js +168 -15
- package/dist/docs/manager.js.map +1 -1
- package/dist/docs/type-registry.d.ts +123 -0
- package/dist/docs/type-registry.d.ts.map +1 -0
- package/dist/docs/type-registry.js +393 -0
- package/dist/docs/type-registry.js.map +1 -0
- package/dist/docs/types.d.ts +93 -0
- package/dist/docs/types.d.ts.map +1 -1
- package/dist/factories.d.ts +89 -0
- package/dist/factories.d.ts.map +1 -0
- package/dist/factories.js +228 -0
- package/dist/factories.js.map +1 -0
- package/dist/file/factory.d.ts +41 -0
- package/dist/file/factory.d.ts.map +1 -0
- package/dist/file/factory.js +237 -0
- package/dist/file/factory.js.map +1 -0
- package/dist/file/gcs.d.ts +66 -0
- package/dist/file/gcs.d.ts.map +1 -0
- package/dist/file/gcs.js +226 -0
- package/dist/file/gcs.js.map +1 -0
- package/dist/file/gdrive.d.ts +78 -0
- package/dist/file/gdrive.d.ts.map +1 -0
- package/dist/file/gdrive.js +302 -0
- package/dist/file/gdrive.js.map +1 -0
- package/dist/file/index.d.ts +13 -1
- package/dist/file/index.d.ts.map +1 -1
- package/dist/file/index.js +25 -1
- package/dist/file/index.js.map +1 -1
- package/dist/file/manager.d.ts +83 -2
- package/dist/file/manager.d.ts.map +1 -1
- package/dist/file/manager.js +125 -4
- package/dist/file/manager.js.map +1 -1
- package/dist/file/r2.d.ts +56 -0
- package/dist/file/r2.d.ts.map +1 -0
- package/dist/file/r2.js +96 -0
- package/dist/file/r2.js.map +1 -0
- package/dist/file/s3.d.ts +61 -0
- package/dist/file/s3.d.ts.map +1 -0
- package/dist/file/s3.js +258 -0
- package/dist/file/s3.js.map +1 -0
- package/dist/file/types.d.ts +145 -2
- package/dist/file/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/logs/index.d.ts +1 -0
- package/dist/logs/index.d.ts.map +1 -1
- package/dist/logs/index.js +3 -1
- package/dist/logs/index.js.map +1 -1
- package/dist/logs/manager.d.ts +29 -2
- package/dist/logs/manager.d.ts.map +1 -1
- package/dist/logs/manager.js +48 -7
- package/dist/logs/manager.js.map +1 -1
- package/dist/logs/type-registry.d.ts +180 -0
- package/dist/logs/type-registry.d.ts.map +1 -0
- package/dist/logs/type-registry.js +421 -0
- package/dist/logs/type-registry.js.map +1 -0
- package/dist/logs/type-registry.test.d.ts +5 -0
- package/dist/logs/type-registry.test.d.ts.map +1 -0
- package/dist/logs/type-registry.test.js +671 -0
- package/dist/logs/type-registry.test.js.map +1 -0
- package/dist/logs/types.d.ts +2 -0
- package/dist/logs/types.d.ts.map +1 -1
- package/package.json +76 -8
package/dist/file/gcs.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fractary/core - GCS Storage Implementation
|
|
4
|
+
*
|
|
5
|
+
* Google Cloud Storage backend for file operations.
|
|
6
|
+
* Uses @google-cloud/storage with lazy loading.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.GCSStorage = void 0;
|
|
43
|
+
/**
|
|
44
|
+
* Google Cloud Storage implementation
|
|
45
|
+
*/
|
|
46
|
+
class GCSStorage {
|
|
47
|
+
config;
|
|
48
|
+
storageClient = null;
|
|
49
|
+
bucket = null;
|
|
50
|
+
constructor(config) {
|
|
51
|
+
this.config = config;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get or create the GCS client (lazy loaded)
|
|
55
|
+
*/
|
|
56
|
+
async getClient() {
|
|
57
|
+
if (this.storageClient && this.bucket) {
|
|
58
|
+
return { storage: this.storageClient, bucket: this.bucket };
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
// Dynamic import to avoid hard dependency
|
|
62
|
+
const { Storage: GCStorage } = await Promise.resolve().then(() => __importStar(require('@google-cloud/storage')));
|
|
63
|
+
const clientConfig = {
|
|
64
|
+
projectId: this.config.projectId,
|
|
65
|
+
};
|
|
66
|
+
// Use key file if provided
|
|
67
|
+
if (this.config.keyFilePath) {
|
|
68
|
+
clientConfig.keyFilename = this.config.keyFilePath;
|
|
69
|
+
}
|
|
70
|
+
// Otherwise, use Application Default Credentials (ADC)
|
|
71
|
+
this.storageClient = new GCStorage(clientConfig);
|
|
72
|
+
this.bucket = this.storageClient.bucket(this.config.bucket);
|
|
73
|
+
return { storage: this.storageClient, bucket: this.bucket };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new Error('Google Cloud Storage SDK not available. Install with: npm install @google-cloud/storage');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the full GCS path with optional prefix
|
|
81
|
+
*/
|
|
82
|
+
getPath(id) {
|
|
83
|
+
if (this.config.prefix) {
|
|
84
|
+
return `${this.config.prefix.replace(/\/$/, '')}/${id}`;
|
|
85
|
+
}
|
|
86
|
+
return id;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check if an error is a "not found" error
|
|
90
|
+
* Google Cloud SDK uses error.code (number) or error.errors[].reason
|
|
91
|
+
*/
|
|
92
|
+
isNotFoundError(error) {
|
|
93
|
+
return (error.code === 404 ||
|
|
94
|
+
error.code === 'ENOENT' ||
|
|
95
|
+
error.errors?.some((e) => e.reason === 'notFound'));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Write content to GCS
|
|
99
|
+
*/
|
|
100
|
+
async write(id, content) {
|
|
101
|
+
const { bucket } = await this.getClient();
|
|
102
|
+
const path = this.getPath(id);
|
|
103
|
+
const file = bucket.file(path);
|
|
104
|
+
await file.save(content, {
|
|
105
|
+
contentType: 'text/plain; charset=utf-8',
|
|
106
|
+
resumable: false,
|
|
107
|
+
});
|
|
108
|
+
return `gs://${this.config.bucket}/${path}`;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Read content from GCS
|
|
112
|
+
*/
|
|
113
|
+
async read(id) {
|
|
114
|
+
const { bucket } = await this.getClient();
|
|
115
|
+
const path = this.getPath(id);
|
|
116
|
+
const file = bucket.file(path);
|
|
117
|
+
try {
|
|
118
|
+
const [exists] = await file.exists();
|
|
119
|
+
if (!exists) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const [contents] = await file.download();
|
|
123
|
+
return contents.toString('utf-8');
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (this.isNotFoundError(error)) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if object exists in GCS
|
|
134
|
+
*/
|
|
135
|
+
async exists(id) {
|
|
136
|
+
const { bucket } = await this.getClient();
|
|
137
|
+
const path = this.getPath(id);
|
|
138
|
+
const file = bucket.file(path);
|
|
139
|
+
try {
|
|
140
|
+
const [exists] = await file.exists();
|
|
141
|
+
return exists;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
// Only treat "not found" as false, rethrow other errors
|
|
145
|
+
if (this.isNotFoundError(error)) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* List objects in GCS with optional prefix
|
|
153
|
+
*/
|
|
154
|
+
async list(prefix) {
|
|
155
|
+
const { bucket } = await this.getClient();
|
|
156
|
+
const fullPrefix = prefix ? this.getPath(prefix) : this.config.prefix || '';
|
|
157
|
+
const [files] = await bucket.getFiles({
|
|
158
|
+
prefix: fullPrefix,
|
|
159
|
+
});
|
|
160
|
+
return files.map((file) => {
|
|
161
|
+
let name = file.name;
|
|
162
|
+
// Remove the configured prefix from the path for consistency
|
|
163
|
+
if (this.config.prefix && name.startsWith(this.config.prefix)) {
|
|
164
|
+
name = name.slice(this.config.prefix.length).replace(/^\//, '');
|
|
165
|
+
}
|
|
166
|
+
return name;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Delete object from GCS
|
|
171
|
+
*/
|
|
172
|
+
async delete(id) {
|
|
173
|
+
const { bucket } = await this.getClient();
|
|
174
|
+
const path = this.getPath(id);
|
|
175
|
+
const file = bucket.file(path);
|
|
176
|
+
try {
|
|
177
|
+
await file.delete();
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
// Ignore if file doesn't exist
|
|
181
|
+
if (!this.isNotFoundError(error)) {
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get a signed URL for the object
|
|
188
|
+
*/
|
|
189
|
+
async getUrl(id, expiresIn = 86400) {
|
|
190
|
+
const { bucket } = await this.getClient();
|
|
191
|
+
const path = this.getPath(id);
|
|
192
|
+
const file = bucket.file(path);
|
|
193
|
+
try {
|
|
194
|
+
const [url] = await file.getSignedUrl({
|
|
195
|
+
version: 'v4',
|
|
196
|
+
action: 'read',
|
|
197
|
+
expires: Date.now() + expiresIn * 1000,
|
|
198
|
+
});
|
|
199
|
+
return url;
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
// Fall back to gs:// URI if signing fails (e.g., no key file)
|
|
203
|
+
return `gs://${this.config.bucket}/${path}`;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get the bucket name
|
|
208
|
+
*/
|
|
209
|
+
getBucket() {
|
|
210
|
+
return this.config.bucket;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get the project ID
|
|
214
|
+
*/
|
|
215
|
+
getProjectId() {
|
|
216
|
+
return this.config.projectId;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get the configured prefix
|
|
220
|
+
*/
|
|
221
|
+
getPrefix() {
|
|
222
|
+
return this.config.prefix;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.GCSStorage = GCSStorage;
|
|
226
|
+
//# sourceMappingURL=gcs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gcs.js","sourceRoot":"","sources":["../../src/file/gcs.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQH;;GAEG;AACH,MAAa,UAAU;IACb,MAAM,CAAmB;IACzB,aAAa,GAAqB,IAAI,CAAC;IACvC,MAAM,GAAqB,IAAI,CAAC;IAExC,YAAY,MAAwB;QAClC,IAAI,CAA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,IAAI,CAAC,YAAY,CAAC;gBACpC,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI;aACvC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,8DAA8D;YAC9D,OAAO,QAAQ,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;CACF;AA5MD,gCA4MC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fractary/core - Google Drive Storage Implementation
|
|
3
|
+
*
|
|
4
|
+
* Google Drive storage backend for file operations.
|
|
5
|
+
* Uses googleapis with lazy loading.
|
|
6
|
+
*
|
|
7
|
+
* Note: Google Drive doesn't use traditional file paths. This implementation
|
|
8
|
+
* maps path-like identifiers to Google Drive files by name within a folder.
|
|
9
|
+
*/
|
|
10
|
+
import { Storage, GDriveStorageConfig } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* Google Drive storage implementation
|
|
13
|
+
*/
|
|
14
|
+
export declare class GDriveStorage implements Storage {
|
|
15
|
+
private config;
|
|
16
|
+
private driveClient;
|
|
17
|
+
constructor(config: GDriveStorageConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Get or create the Google Drive client (lazy loaded)
|
|
20
|
+
*/
|
|
21
|
+
private getClient;
|
|
22
|
+
/**
|
|
23
|
+
* Get the parent folder ID (internal helper)
|
|
24
|
+
*/
|
|
25
|
+
private getParentFolderId;
|
|
26
|
+
/**
|
|
27
|
+
* Extract file name from path-like ID
|
|
28
|
+
*/
|
|
29
|
+
private getFileName;
|
|
30
|
+
/**
|
|
31
|
+
* Escape a string for use in Google Drive query syntax
|
|
32
|
+
* Single quotes must be escaped with backslash
|
|
33
|
+
*/
|
|
34
|
+
private escapeQueryString;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a string looks like a Google Drive file ID
|
|
37
|
+
* Drive file IDs are typically 28-44 characters, alphanumeric with - and _
|
|
38
|
+
*/
|
|
39
|
+
private isFileId;
|
|
40
|
+
/**
|
|
41
|
+
* Check if an error is a "not found" error
|
|
42
|
+
* Google APIs uses error.code (number) or error.errors[].reason
|
|
43
|
+
*/
|
|
44
|
+
private isNotFoundError;
|
|
45
|
+
/**
|
|
46
|
+
* Find a file by name in the configured folder
|
|
47
|
+
*/
|
|
48
|
+
private findFile;
|
|
49
|
+
/**
|
|
50
|
+
* Write content to Google Drive
|
|
51
|
+
*/
|
|
52
|
+
write(id: string, content: string): Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Read content from Google Drive
|
|
55
|
+
*/
|
|
56
|
+
read(id: string): Promise<string | null>;
|
|
57
|
+
/**
|
|
58
|
+
* Check if file exists in Google Drive
|
|
59
|
+
*/
|
|
60
|
+
exists(id: string): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* List files in the configured Google Drive folder
|
|
63
|
+
*/
|
|
64
|
+
list(prefix?: string): Promise<string[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Delete file from Google Drive
|
|
67
|
+
*/
|
|
68
|
+
delete(id: string): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Get a shareable URL for the file
|
|
71
|
+
*/
|
|
72
|
+
getUrl(id: string, _expiresIn?: number): Promise<string | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Get the configured folder ID
|
|
75
|
+
*/
|
|
76
|
+
getFolderId(): string;
|
|
77
|
+
}
|
|
78
|
+
//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0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fractary/core - Google Drive Storage Implementation
|
|
4
|
+
*
|
|
5
|
+
* Google Drive storage backend for file operations.
|
|
6
|
+
* Uses googleapis with lazy loading.
|
|
7
|
+
*
|
|
8
|
+
* Note: Google Drive doesn't use traditional file paths. This implementation
|
|
9
|
+
* maps path-like identifiers to Google Drive files by name within a folder.
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.GDriveStorage = void 0;
|
|
46
|
+
/**
|
|
47
|
+
* Google Drive storage implementation
|
|
48
|
+
*/
|
|
49
|
+
class GDriveStorage {
|
|
50
|
+
config;
|
|
51
|
+
driveClient = null;
|
|
52
|
+
constructor(config) {
|
|
53
|
+
this.config = config;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get or create the Google Drive client (lazy loaded)
|
|
57
|
+
*/
|
|
58
|
+
async getClient() {
|
|
59
|
+
if (this.driveClient) {
|
|
60
|
+
return this.driveClient;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
// Dynamic import to avoid hard dependency
|
|
64
|
+
const { google } = await Promise.resolve().then(() => __importStar(require('googleapis')));
|
|
65
|
+
// Check if we have OAuth credentials
|
|
66
|
+
if (this.config.clientId && this.config.clientSecret && this.config.refreshToken) {
|
|
67
|
+
const oauth2Client = new google.auth.OAuth2(this.config.clientId, this.config.clientSecret);
|
|
68
|
+
oauth2Client.setCredentials({
|
|
69
|
+
refresh_token: this.config.refreshToken,
|
|
70
|
+
});
|
|
71
|
+
this.driveClient = google.drive({ version: 'v3', auth: oauth2Client });
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// Use Application Default Credentials
|
|
75
|
+
const googleAuth = new google.auth.GoogleAuth({
|
|
76
|
+
scopes: ['https://www.googleapis.com/auth/drive'],
|
|
77
|
+
});
|
|
78
|
+
const authClient = await googleAuth.getClient();
|
|
79
|
+
this.driveClient = google.drive({
|
|
80
|
+
version: 'v3',
|
|
81
|
+
auth: authClient,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return this.driveClient;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
throw new Error('Google APIs SDK not available. Install with: npm install googleapis');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the parent folder ID (internal helper)
|
|
92
|
+
*/
|
|
93
|
+
getParentFolderId() {
|
|
94
|
+
return this.config.folderId || 'root';
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Extract file name from path-like ID
|
|
98
|
+
*/
|
|
99
|
+
getFileName(id) {
|
|
100
|
+
// Take the last part of the path as the file name
|
|
101
|
+
const parts = id.split('/');
|
|
102
|
+
return parts[parts.length - 1];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Escape a string for use in Google Drive query syntax
|
|
106
|
+
* Single quotes must be escaped with backslash
|
|
107
|
+
*/
|
|
108
|
+
escapeQueryString(str) {
|
|
109
|
+
return str.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if a string looks like a Google Drive file ID
|
|
113
|
+
* Drive file IDs are typically 28-44 characters, alphanumeric with - and _
|
|
114
|
+
*/
|
|
115
|
+
isFileId(id) {
|
|
116
|
+
// More permissive regex to handle various Google Drive ID formats
|
|
117
|
+
return /^[a-zA-Z0-9_-]{20,50}$/.test(id) && !id.includes('/');
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if an error is a "not found" error
|
|
121
|
+
* Google APIs uses error.code (number) or error.errors[].reason
|
|
122
|
+
*/
|
|
123
|
+
isNotFoundError(error) {
|
|
124
|
+
return (error.code === 404 ||
|
|
125
|
+
error.status === 404 ||
|
|
126
|
+
error.errors?.some((e) => e.reason === 'notFound'));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Find a file by name in the configured folder
|
|
130
|
+
*/
|
|
131
|
+
async findFile(id) {
|
|
132
|
+
const drive = await this.getClient();
|
|
133
|
+
const fileName = this.getFileName(id);
|
|
134
|
+
const escapedFileName = this.escapeQueryString(fileName);
|
|
135
|
+
const folderId = this.getParentFolderId();
|
|
136
|
+
const response = await drive.files.list({
|
|
137
|
+
q: `name = '${escapedFileName}' and '${folderId}' in parents and trashed = false`,
|
|
138
|
+
fields: 'files(id, name)',
|
|
139
|
+
spaces: 'drive',
|
|
140
|
+
});
|
|
141
|
+
if (response.data.files && response.data.files.length > 0) {
|
|
142
|
+
return response.data.files[0].id ?? null;
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Write content to Google Drive
|
|
148
|
+
*/
|
|
149
|
+
async write(id, content) {
|
|
150
|
+
const drive = await this.getClient();
|
|
151
|
+
const fileName = this.getFileName(id);
|
|
152
|
+
const folderId = this.getParentFolderId();
|
|
153
|
+
// Check if file already exists
|
|
154
|
+
const existingFileId = await this.findFile(id);
|
|
155
|
+
const media = {
|
|
156
|
+
mimeType: 'text/plain',
|
|
157
|
+
body: content,
|
|
158
|
+
};
|
|
159
|
+
let fileId;
|
|
160
|
+
if (existingFileId) {
|
|
161
|
+
// Update existing file
|
|
162
|
+
const response = await drive.files.update({
|
|
163
|
+
fileId: existingFileId,
|
|
164
|
+
media,
|
|
165
|
+
fields: 'id',
|
|
166
|
+
});
|
|
167
|
+
if (!response.data.id) {
|
|
168
|
+
throw new Error('Failed to update file: no file ID returned');
|
|
169
|
+
}
|
|
170
|
+
fileId = response.data.id;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// Create new file
|
|
174
|
+
const fileMetadata = {
|
|
175
|
+
name: fileName,
|
|
176
|
+
parents: [folderId],
|
|
177
|
+
};
|
|
178
|
+
const response = await drive.files.create({
|
|
179
|
+
requestBody: fileMetadata,
|
|
180
|
+
media,
|
|
181
|
+
fields: 'id',
|
|
182
|
+
});
|
|
183
|
+
if (!response.data.id) {
|
|
184
|
+
throw new Error('Failed to create file: no file ID returned');
|
|
185
|
+
}
|
|
186
|
+
fileId = response.data.id;
|
|
187
|
+
}
|
|
188
|
+
return `gdrive://${fileId}`;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Read content from Google Drive
|
|
192
|
+
*/
|
|
193
|
+
async read(id) {
|
|
194
|
+
const drive = await this.getClient();
|
|
195
|
+
// Check if id is a direct file ID or a path-like name
|
|
196
|
+
let fileId = id;
|
|
197
|
+
if (!this.isFileId(id)) {
|
|
198
|
+
// Looks like a path, search for the file
|
|
199
|
+
fileId = (await this.findFile(id)) || id;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const response = await drive.files.get({
|
|
203
|
+
fileId,
|
|
204
|
+
alt: 'media',
|
|
205
|
+
});
|
|
206
|
+
return response.data;
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (this.isNotFoundError(error)) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Check if file exists in Google Drive
|
|
217
|
+
*/
|
|
218
|
+
async exists(id) {
|
|
219
|
+
try {
|
|
220
|
+
const fileId = await this.findFile(id);
|
|
221
|
+
return fileId !== null;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
// Only treat "not found" as false, rethrow other errors
|
|
225
|
+
if (this.isNotFoundError(error)) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* List files in the configured Google Drive folder
|
|
233
|
+
*/
|
|
234
|
+
async list(prefix) {
|
|
235
|
+
const drive = await this.getClient();
|
|
236
|
+
const folderId = this.getParentFolderId();
|
|
237
|
+
const results = [];
|
|
238
|
+
let pageToken;
|
|
239
|
+
do {
|
|
240
|
+
let query = `'${folderId}' in parents and trashed = false`;
|
|
241
|
+
if (prefix) {
|
|
242
|
+
const escapedPrefix = this.escapeQueryString(prefix);
|
|
243
|
+
query += ` and name contains '${escapedPrefix}'`;
|
|
244
|
+
}
|
|
245
|
+
const response = await drive.files.list({
|
|
246
|
+
q: query,
|
|
247
|
+
fields: 'nextPageToken, files(id, name)',
|
|
248
|
+
spaces: 'drive',
|
|
249
|
+
pageToken,
|
|
250
|
+
});
|
|
251
|
+
if (response.data.files) {
|
|
252
|
+
for (const file of response.data.files) {
|
|
253
|
+
if (file.name) {
|
|
254
|
+
results.push(file.name);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
pageToken = response.data.nextPageToken ?? undefined;
|
|
259
|
+
} while (pageToken);
|
|
260
|
+
return results;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Delete file from Google Drive
|
|
264
|
+
*/
|
|
265
|
+
async delete(id) {
|
|
266
|
+
const drive = await this.getClient();
|
|
267
|
+
// Check if id is a direct file ID or a path-like name
|
|
268
|
+
let fileId = id;
|
|
269
|
+
if (!this.isFileId(id)) {
|
|
270
|
+
fileId = (await this.findFile(id)) || id;
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
await drive.files.delete({ fileId });
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
// Ignore if file doesn't exist
|
|
277
|
+
if (!this.isNotFoundError(error)) {
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Get a shareable URL for the file
|
|
284
|
+
*/
|
|
285
|
+
async getUrl(id, _expiresIn) {
|
|
286
|
+
// Check if id is a direct file ID or a path-like name
|
|
287
|
+
let fileId = id;
|
|
288
|
+
if (!this.isFileId(id)) {
|
|
289
|
+
fileId = (await this.findFile(id)) || id;
|
|
290
|
+
}
|
|
291
|
+
// Return the standard Google Drive view URL
|
|
292
|
+
return `https://drive.google.com/file/d/${fileId}/view`;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Get the configured folder ID
|
|
296
|
+
*/
|
|
297
|
+
getFolderId() {
|
|
298
|
+
return this.config.folderId || 'root';
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.GDriveStorage = GDriveStorage;
|
|
302
|
+
//# sourceMappingURL=gdrive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gdrive.js","sourceRoot":"","sources":["../../src/file/gdrive.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQH;;GAEG;AACH,MAAa,aAAa;IAChB,MAAM,CAAsB;IAC5B,WAAW,GAAuB,IAAI,CAAC;IAE/C,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,SAAS;QACrB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;QAED,IAAI,CAAC;YACH,0CAA0C;YAC1C,MAAM,EAAE,MAAM,EAAE,GAAG,wDAAa,YAAY,GAAC,CAAC;YAE9C,qCAAqC;YACrC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;gBACjF,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CACzC,IAAI,CAAC,MAAM,CAAC,QAAQ,EACpB,IAAI,CAAC,MAAM,CAAC,YAAY,CACzB,CAAC;gBAEF,YAAY,CAAC,cAAc,CAAC;oBAC1B,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;iBACxC,CAAC,CAAC;gBAEH,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;YACzE,CAAC;iBAAM,CAAC;gBACN,sCAAsC;gBACtC,MAAM,UAAU,GAAG,IAAI,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AAU,EAAE,UAAmB;QAC1C,sDAAsD;QACtD,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YACvB,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3C,CAAC;QAED,4CAA4C;QAC5C,OAAO,mCAAmC,MAAM,OAAO,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC;IACxC,CAAC;CACF;AArSD,sCAqSC"}
|
package/dist/file/index.d.ts
CHANGED
|
@@ -2,8 +2,20 @@
|
|
|
2
2
|
* @fractary/core - File Module
|
|
3
3
|
*
|
|
4
4
|
* File storage operations across local and cloud storage backends.
|
|
5
|
+
*
|
|
6
|
+
* Supported backends:
|
|
7
|
+
* - LocalStorage: Local filesystem
|
|
8
|
+
* - S3Storage: AWS S3 (requires @aws-sdk/client-s3)
|
|
9
|
+
* - R2Storage: Cloudflare R2 (requires @aws-sdk/client-s3)
|
|
10
|
+
* - GCSStorage: Google Cloud Storage (requires @google-cloud/storage)
|
|
11
|
+
* - GDriveStorage: Google Drive (requires googleapis)
|
|
5
12
|
*/
|
|
6
|
-
export { FileManager } from './manager';
|
|
13
|
+
export { FileManager, FileManagerOptions } from './manager';
|
|
7
14
|
export { LocalStorage } from './local';
|
|
15
|
+
export { S3Storage } from './s3';
|
|
16
|
+
export { R2Storage } from './r2';
|
|
17
|
+
export { GCSStorage } from './gcs';
|
|
18
|
+
export { GDriveStorage } from './gdrive';
|
|
19
|
+
export { createStorage, createStorageFromSource, sourceConfigToStorageConfig, getDefaultStorageType, } from './factory';
|
|
8
20
|
export * from './types';
|
|
9
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/file/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAGnB,cAAc,SAAS,CAAC"}
|