@sinoia/hubdoc-tools 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/plugins/alfresco/plugin.json +12 -0
- package/dist/plugins/aws-s3/plugin.json +12 -0
- package/dist/plugins/azure-blob/plugin.json +12 -0
- package/dist/plugins/box/plugin.json +12 -0
- package/dist/plugins/core/index.d.ts +25 -0
- package/dist/plugins/core/index.d.ts.map +1 -0
- package/dist/plugins/core/index.js +400 -0
- package/dist/plugins/core/index.js.map +1 -0
- package/dist/plugins/core/plugin.json +26 -0
- package/dist/plugins/dropbox/plugin.json +12 -0
- package/dist/plugins/filesystem/index.d.ts +22 -0
- package/dist/plugins/filesystem/index.d.ts.map +1 -0
- package/dist/plugins/filesystem/index.js +306 -0
- package/dist/plugins/filesystem/index.js.map +1 -0
- package/dist/plugins/filesystem/plugin.json +12 -0
- package/dist/plugins/googledrive/plugin.json +12 -0
- package/dist/plugins/nuxeo/plugin.json +12 -0
- package/dist/plugins/onedrive/plugin.json +12 -0
- package/dist/plugins/opentext/plugin.json +12 -0
- package/dist/plugins/sharepoint/plugin.json +12 -0
- package/dist/services/hubdoc-api.d.ts +1 -1
- package/dist/services/hubdoc-api.js +1 -1
- package/dist/services/oauth-token-service.d.ts +1 -1
- package/dist/services/oauth-token-service.js +2 -2
- package/dist/services/permission-manager.d.ts +1 -1
- package/dist/services/permission-manager.js +1 -1
- package/dist/src/types/plugins.d.ts +111 -0
- package/dist/src/types/plugins.d.ts.map +1 -0
- package/dist/src/types/plugins.js +3 -0
- package/dist/src/types/plugins.js.map +1 -0
- package/dist/src/utils/concurrent-processor.d.ts +63 -0
- package/dist/src/utils/concurrent-processor.d.ts.map +1 -0
- package/dist/src/utils/concurrent-processor.js +240 -0
- package/dist/src/utils/concurrent-processor.js.map +1 -0
- package/dist/src/utils/xml-metadata.d.ts +47 -0
- package/dist/src/utils/xml-metadata.d.ts.map +1 -0
- package/dist/src/utils/xml-metadata.js +200 -0
- package/dist/src/utils/xml-metadata.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export { CsvManager } from './utils/csv';
|
|
|
19
19
|
export { OperationLogger } from './utils/operation-logger';
|
|
20
20
|
export { ConcurrentProcessor } from './utils/concurrent-processor';
|
|
21
21
|
export type { HubDocConfig, HubDocDocument, HubDocFolder, HubDocBulkUpload, DocumentMapping, ImportOptions, ImportResult as HubDocImportResult, ImportProgressCallbacks } from './types';
|
|
22
|
-
export type { Workspace, BulkUpload, Document, Folder } from '
|
|
22
|
+
export type { Workspace, BulkUpload, Document, Folder } from '@api/models';
|
|
23
23
|
export type { DocumentSource, DocumentSourcePlugin, PluginConfig, PluginManifest, RegisteredPlugin, SourceConnection, ScanResult, ImportResult, ExportResult, PluginImportOptions, PluginExportOptions } from './types/plugins';
|
|
24
24
|
export type { TokenResponse } from './api/models';
|
|
25
25
|
export { DocumentsApi, FoldersApi, WorkspacesApi, BulkUploadsApi, PermissionsApi, AuthenticationApi } from './api/api';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aws-s3",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "AWS S3 document source plugin",
|
|
5
|
+
"author": "HubDoc Tools",
|
|
6
|
+
"main": "index.ts",
|
|
7
|
+
"hubdocToolVersion": "^1.0.0",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"aws-sdk": "^2.1000.0",
|
|
10
|
+
"fs-extra": "^11.1.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "azure-blob",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Azure Blob Storage document source plugin",
|
|
5
|
+
"author": "HubDoc Tools",
|
|
6
|
+
"main": "index.ts",
|
|
7
|
+
"hubdocToolVersion": "^1.0.0",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@azure/storage-blob": "^12.0.0",
|
|
10
|
+
"fs-extra": "^11.1.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DocumentSourcePlugin, DocumentSource, PluginConfig, ScanResult, PluginImportOptions, PluginExportOptions, ImportResult, ExportResult } from '../../src/types/plugins';
|
|
2
|
+
export default class CorePlugin implements DocumentSourcePlugin {
|
|
3
|
+
readonly name = "core";
|
|
4
|
+
readonly version = "1.0.0";
|
|
5
|
+
readonly description = "Core document management system source";
|
|
6
|
+
readonly supportedOperations: readonly ["import", "both"];
|
|
7
|
+
private config?;
|
|
8
|
+
private apiClient?;
|
|
9
|
+
testConnection(config: PluginConfig): Promise<boolean>;
|
|
10
|
+
scan(config: PluginConfig, options?: PluginImportOptions): Promise<ScanResult>;
|
|
11
|
+
import(config: PluginConfig, sources: DocumentSource[], targetDir: string, options?: PluginImportOptions): Promise<ImportResult[]>;
|
|
12
|
+
private importSingle;
|
|
13
|
+
export?(config: PluginConfig, localSources: DocumentSource[], options?: PluginExportOptions): Promise<ExportResult[]>;
|
|
14
|
+
getConfigSchema(): Record<string, any>;
|
|
15
|
+
initialize(config: PluginConfig): Promise<void>;
|
|
16
|
+
destroy(): Promise<void>;
|
|
17
|
+
private createApiClient;
|
|
18
|
+
private authenticate;
|
|
19
|
+
private buildDocumentPath;
|
|
20
|
+
private estimateDocumentSize;
|
|
21
|
+
private determineMimeType;
|
|
22
|
+
private shouldIncludeSource;
|
|
23
|
+
private sleep;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../plugins/core/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,mBAAmB,EACn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ault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const concurrent_processor_1 = require("../../src/utils/concurrent-processor");
|
|
10
|
+
class CorePlugin {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.name = 'core';
|
|
13
|
+
this.version = '1.0.0';
|
|
14
|
+
this.description = 'Core document management system source';
|
|
15
|
+
this.supportedOperations = ['import', 'both'];
|
|
16
|
+
}
|
|
17
|
+
async testConnection(config) {
|
|
18
|
+
try {
|
|
19
|
+
const coreConfig = config;
|
|
20
|
+
const client = await this.createApiClient(coreConfig);
|
|
21
|
+
// Test connection by trying to fetch docs (first page only)
|
|
22
|
+
const response = await client.get('/api/d2/docs', {
|
|
23
|
+
params: {
|
|
24
|
+
'[page][number]': 1,
|
|
25
|
+
'[page][size]': 1
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return response.status === 200;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error(`Core connection test failed: ${error.message}`);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async scan(config, options) {
|
|
36
|
+
this.config = config;
|
|
37
|
+
this.apiClient = await this.createApiClient(this.config);
|
|
38
|
+
const sources = [];
|
|
39
|
+
const errors = [];
|
|
40
|
+
let totalSize = 0;
|
|
41
|
+
try {
|
|
42
|
+
const limit = this.config.limit || options?.limit;
|
|
43
|
+
console.log(`🔍 Scanning Core documents${limit ? ` (limit: ${limit})` : ''}...`);
|
|
44
|
+
// Scan all pages of documents
|
|
45
|
+
let currentPage = 1;
|
|
46
|
+
let hasMorePages = true;
|
|
47
|
+
const pageSize = limit && limit < 100 ? limit : 100; // Use limit if smaller than default batch
|
|
48
|
+
while (hasMorePages && (!limit || sources.length < limit)) {
|
|
49
|
+
try {
|
|
50
|
+
const response = await this.apiClient.get('/api/d2/docs', {
|
|
51
|
+
params: {
|
|
52
|
+
'[page][number]': currentPage,
|
|
53
|
+
'[page][size]': pageSize,
|
|
54
|
+
// Add filters if provided in options
|
|
55
|
+
...(options?.filters?.path && { path: options.filters.path }),
|
|
56
|
+
...(options?.filters?.mimeTypes && { type: options.filters.mimeTypes.join(',') })
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const docs = response.data.data || [];
|
|
60
|
+
console.log(`📄 Processing page ${currentPage}: ${docs.length} documents`);
|
|
61
|
+
for (const doc of docs) {
|
|
62
|
+
if (doc.attributes && doc.attributes.title) {
|
|
63
|
+
const source = {
|
|
64
|
+
id: doc.id,
|
|
65
|
+
name: doc.attributes.title,
|
|
66
|
+
path: this.buildDocumentPath(doc),
|
|
67
|
+
size: this.estimateDocumentSize(doc),
|
|
68
|
+
mimeType: this.determineMimeType(doc),
|
|
69
|
+
lastModified: new Date(doc.attributes.updated_at || doc.attributes.created_at || Date.now()),
|
|
70
|
+
metadata: {
|
|
71
|
+
coreId: doc.id,
|
|
72
|
+
coreType: doc.attributes.type,
|
|
73
|
+
coreSubtype: doc.attributes.subtype,
|
|
74
|
+
corePath: doc.attributes.path,
|
|
75
|
+
tags: doc.attributes.tags,
|
|
76
|
+
hasAttachments: doc.attributes.has_attachments,
|
|
77
|
+
signed: doc.attributes.signed,
|
|
78
|
+
percent: doc.attributes.percent,
|
|
79
|
+
note: doc.attributes.note,
|
|
80
|
+
body: doc.attributes.body?.substring(0, 500) + '...' // Truncate body for metadata
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
// Apply filters
|
|
84
|
+
if (this.shouldIncludeSource(source, options)) {
|
|
85
|
+
sources.push(source);
|
|
86
|
+
totalSize += source.size;
|
|
87
|
+
// Stop if we've reached the limit
|
|
88
|
+
if (limit && sources.length >= limit) {
|
|
89
|
+
console.log(`📏 Reached limit of ${limit} documents`);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Check for more pages
|
|
96
|
+
const pagination = response.data.meta?.pagination;
|
|
97
|
+
if (pagination && pagination.page && pagination.pages) {
|
|
98
|
+
hasMorePages = pagination.page < pagination.pages;
|
|
99
|
+
currentPage++;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Fallback: if no docs returned, assume we've reached the end
|
|
103
|
+
hasMorePages = docs.length === pageSize;
|
|
104
|
+
if (hasMorePages)
|
|
105
|
+
currentPage++;
|
|
106
|
+
}
|
|
107
|
+
// Add small delay to respect API limits
|
|
108
|
+
await this.sleep(100);
|
|
109
|
+
}
|
|
110
|
+
catch (pageError) {
|
|
111
|
+
console.warn(`⚠️ Warning: Failed to fetch page ${currentPage}: ${pageError.message}`);
|
|
112
|
+
errors.push(`Failed to fetch page ${currentPage}: ${pageError.message}`);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
console.log(`✅ Scan completed: ${sources.length} documents found`);
|
|
117
|
+
return {
|
|
118
|
+
sources,
|
|
119
|
+
totalCount: sources.length,
|
|
120
|
+
totalSize,
|
|
121
|
+
errors
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
return {
|
|
126
|
+
sources: [],
|
|
127
|
+
totalCount: 0,
|
|
128
|
+
totalSize: 0,
|
|
129
|
+
errors: [`Core scan failed: ${error.message}`]
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async import(config, sources, targetDir, options) {
|
|
134
|
+
this.config = config;
|
|
135
|
+
this.apiClient = await this.createApiClient(this.config);
|
|
136
|
+
const concurrency = options?.concurrent || 1;
|
|
137
|
+
const tempDir = this.config.tempDir || path_1.default.join(targetDir, '.temp');
|
|
138
|
+
// Ensure temp directory exists
|
|
139
|
+
await fs_extra_1.default.ensureDir(tempDir);
|
|
140
|
+
console.log(`📥 Starting concurrent import of ${sources.length} documents from Core (${concurrency} jobs)`);
|
|
141
|
+
// Use concurrent processor
|
|
142
|
+
const processingResult = await concurrent_processor_1.ConcurrentProcessor.processWithProgress(sources, async (source, index) => {
|
|
143
|
+
const result = await this.importSingle(source, targetDir, tempDir);
|
|
144
|
+
// Rate limiting delay (only for concurrent > 1)
|
|
145
|
+
if (concurrency > 1) {
|
|
146
|
+
await this.sleep(100); // Reduced delay for concurrent operations
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}, {
|
|
150
|
+
concurrency,
|
|
151
|
+
operation: 'Import from Core',
|
|
152
|
+
itemName: 'documents'
|
|
153
|
+
});
|
|
154
|
+
// Cleanup temp directory
|
|
155
|
+
try {
|
|
156
|
+
await fs_extra_1.default.remove(tempDir);
|
|
157
|
+
console.log('🧹 Temporary files cleaned up');
|
|
158
|
+
}
|
|
159
|
+
catch (cleanupError) {
|
|
160
|
+
console.warn('⚠️ Warning: Failed to cleanup temporary directory');
|
|
161
|
+
}
|
|
162
|
+
// Filter valid results and handle errors
|
|
163
|
+
const validResults = processingResult.results.filter(r => r !== undefined);
|
|
164
|
+
const errorResults = processingResult.errors.map(({ item, error }) => ({
|
|
165
|
+
success: false,
|
|
166
|
+
source: item,
|
|
167
|
+
error: error.message
|
|
168
|
+
}));
|
|
169
|
+
return [...validResults, ...errorResults];
|
|
170
|
+
}
|
|
171
|
+
async importSingle(source, targetDir, tempDir) {
|
|
172
|
+
try {
|
|
173
|
+
if (!this.apiClient)
|
|
174
|
+
throw new Error('API client not initialized');
|
|
175
|
+
console.log(`📄 Importing: ${source.name}`);
|
|
176
|
+
// Step 1: Fetch document details and content from Core
|
|
177
|
+
const docResponse = await this.apiClient.get(`/api/d2/docs/${source.id}`);
|
|
178
|
+
const docData = docResponse.data.data;
|
|
179
|
+
if (!docData) {
|
|
180
|
+
throw new Error('Document not found in Core');
|
|
181
|
+
}
|
|
182
|
+
// Step 2: Create local buffer file
|
|
183
|
+
const tempFileName = `${source.id}_${source.name.replace(/[^a-zA-Z0-9.-]/g, '_')}`;
|
|
184
|
+
const tempFilePath = path_1.default.join(tempDir, tempFileName);
|
|
185
|
+
// Step 3: Generate document content (Core stores content in body field)
|
|
186
|
+
let content = '';
|
|
187
|
+
if (docData.attributes.body) {
|
|
188
|
+
content = docData.attributes.body;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
// Fallback: create a minimal document with metadata
|
|
192
|
+
content = `Document: ${source.name}\n\n`;
|
|
193
|
+
content += `Type: ${source.metadata?.coreType || 'unknown'}\n`;
|
|
194
|
+
content += `Subtype: ${source.metadata?.coreSubtype || 'unknown'}\n`;
|
|
195
|
+
content += `Created: ${source.lastModified.toISOString()}\n`;
|
|
196
|
+
if (source.metadata?.tags && Array.isArray(source.metadata.tags)) {
|
|
197
|
+
content += `Tags: ${source.metadata.tags.join(', ')}\n`;
|
|
198
|
+
}
|
|
199
|
+
content += `\nImported from Core (ID: ${source.id})`;
|
|
200
|
+
}
|
|
201
|
+
// Step 4: Write content to temporary file
|
|
202
|
+
await fs_extra_1.default.writeFile(tempFilePath, content, 'utf8');
|
|
203
|
+
// Step 5: Move to target directory with proper structure
|
|
204
|
+
const targetPath = path_1.default.join(targetDir, source.path);
|
|
205
|
+
const targetDirectory = path_1.default.dirname(targetPath);
|
|
206
|
+
await fs_extra_1.default.ensureDir(targetDirectory);
|
|
207
|
+
await fs_extra_1.default.move(tempFilePath, targetPath, { overwrite: true });
|
|
208
|
+
const stats = await fs_extra_1.default.stat(targetPath);
|
|
209
|
+
console.log(`✅ Imported: ${source.name} (${stats.size} bytes)`);
|
|
210
|
+
return {
|
|
211
|
+
success: true,
|
|
212
|
+
source,
|
|
213
|
+
localPath: targetPath,
|
|
214
|
+
bytesTransferred: stats.size
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
console.error(`❌ Failed to import ${source.name}: ${error.message}`);
|
|
219
|
+
return {
|
|
220
|
+
success: false,
|
|
221
|
+
source,
|
|
222
|
+
error: error.message
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Export is not supported for Core (documents are managed within Core)
|
|
227
|
+
async export(config, localSources, options) {
|
|
228
|
+
throw new Error('Export to Core is not supported. Core documents should be managed within the Core system.');
|
|
229
|
+
}
|
|
230
|
+
getConfigSchema() {
|
|
231
|
+
return {
|
|
232
|
+
type: 'object',
|
|
233
|
+
properties: {
|
|
234
|
+
baseUrl: {
|
|
235
|
+
type: 'string',
|
|
236
|
+
description: 'Core API base URL (e.g., https://your-core-instance.com)',
|
|
237
|
+
required: true
|
|
238
|
+
},
|
|
239
|
+
username: {
|
|
240
|
+
type: 'string',
|
|
241
|
+
description: 'Core username for authentication',
|
|
242
|
+
required: true
|
|
243
|
+
},
|
|
244
|
+
password: {
|
|
245
|
+
type: 'string',
|
|
246
|
+
description: 'Core password for authentication',
|
|
247
|
+
required: true
|
|
248
|
+
},
|
|
249
|
+
bearerToken: {
|
|
250
|
+
type: 'string',
|
|
251
|
+
description: 'Pre-obtained bearer token (optional, will be fetched if not provided)',
|
|
252
|
+
required: false
|
|
253
|
+
},
|
|
254
|
+
tempDir: {
|
|
255
|
+
type: 'string',
|
|
256
|
+
description: 'Temporary directory for local buffer files (optional)',
|
|
257
|
+
required: false
|
|
258
|
+
},
|
|
259
|
+
limit: {
|
|
260
|
+
type: 'integer',
|
|
261
|
+
description: 'Maximum number of documents to scan (useful for testing)',
|
|
262
|
+
required: false
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
required: ['baseUrl', 'username', 'password']
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
async initialize(config) {
|
|
269
|
+
this.config = config;
|
|
270
|
+
if (!this.config.baseUrl) {
|
|
271
|
+
throw new Error('Core plugin requires baseUrl');
|
|
272
|
+
}
|
|
273
|
+
if (!this.config.bearerToken && (!this.config.username || !this.config.password)) {
|
|
274
|
+
throw new Error('Core plugin requires either bearerToken or username/password');
|
|
275
|
+
}
|
|
276
|
+
// Test authentication
|
|
277
|
+
try {
|
|
278
|
+
this.apiClient = await this.createApiClient(this.config);
|
|
279
|
+
console.log('✅ Core plugin initialized successfully');
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
throw new Error(`Failed to initialize Core plugin: ${error.message}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
async destroy() {
|
|
286
|
+
this.config = undefined;
|
|
287
|
+
this.apiClient = undefined;
|
|
288
|
+
}
|
|
289
|
+
async createApiClient(config) {
|
|
290
|
+
let bearerToken = config.bearerToken;
|
|
291
|
+
// If no bearer token provided, authenticate to get one
|
|
292
|
+
if (!bearerToken && config.username && config.password) {
|
|
293
|
+
console.log('🔐 No bearer token provided, authenticating...');
|
|
294
|
+
bearerToken = await this.authenticate(config);
|
|
295
|
+
}
|
|
296
|
+
else if (!bearerToken) {
|
|
297
|
+
throw new Error('Either bearerToken or username/password must be provided');
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
console.log('🔑 Using provided bearer token');
|
|
301
|
+
}
|
|
302
|
+
return axios_1.default.create({
|
|
303
|
+
baseURL: config.baseUrl,
|
|
304
|
+
headers: {
|
|
305
|
+
'Authorization': `Bearer ${bearerToken}`,
|
|
306
|
+
'Content-Type': 'application/json'
|
|
307
|
+
},
|
|
308
|
+
timeout: 30000
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
async authenticate(config) {
|
|
312
|
+
try {
|
|
313
|
+
console.log('🔐 Authenticating with Core...');
|
|
314
|
+
const authClient = axios_1.default.create({
|
|
315
|
+
baseURL: config.baseUrl,
|
|
316
|
+
timeout: 30000
|
|
317
|
+
});
|
|
318
|
+
// Use the token endpoint from the swagger
|
|
319
|
+
const response = await authClient.post('/api/token', null, {
|
|
320
|
+
params: {
|
|
321
|
+
'auth[username]': config.username,
|
|
322
|
+
'auth[password]': config.password,
|
|
323
|
+
'grant_type': 'password'
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
if (response.data && response.data.access_token) {
|
|
327
|
+
console.log('✅ Core authentication successful');
|
|
328
|
+
return response.data.access_token;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
throw new Error('No access token received from Core API');
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
throw new Error(`Core authentication failed: ${error.response?.data?.message || error.message}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
buildDocumentPath(doc) {
|
|
339
|
+
// Build a meaningful path structure
|
|
340
|
+
const type = doc.attributes.type || 'unknown';
|
|
341
|
+
const subtype = doc.attributes.subtype || 'general';
|
|
342
|
+
const title = doc.attributes.title || doc.id;
|
|
343
|
+
// Clean title for filesystem
|
|
344
|
+
const cleanTitle = title.replace(/[^a-zA-Z0-9.-]/g, '_');
|
|
345
|
+
return `${type}/${subtype}/${cleanTitle}.txt`;
|
|
346
|
+
}
|
|
347
|
+
estimateDocumentSize(doc) {
|
|
348
|
+
// Estimate size based on content
|
|
349
|
+
let size = 0;
|
|
350
|
+
if (doc.attributes.body) {
|
|
351
|
+
size += doc.attributes.body.length;
|
|
352
|
+
}
|
|
353
|
+
if (doc.attributes.title) {
|
|
354
|
+
size += doc.attributes.title.length;
|
|
355
|
+
}
|
|
356
|
+
// Add base size for metadata
|
|
357
|
+
size += 500;
|
|
358
|
+
return Math.max(size, 100); // Minimum 100 bytes
|
|
359
|
+
}
|
|
360
|
+
determineMimeType(doc) {
|
|
361
|
+
const type = doc.attributes.type?.toLowerCase();
|
|
362
|
+
const subtype = doc.attributes.subtype?.toLowerCase();
|
|
363
|
+
// Map Core types to MIME types
|
|
364
|
+
if (type === 'document' || subtype === 'document') {
|
|
365
|
+
return 'text/plain';
|
|
366
|
+
}
|
|
367
|
+
else if (type === 'html' || subtype === 'html') {
|
|
368
|
+
return 'text/html';
|
|
369
|
+
}
|
|
370
|
+
else if (doc.attributes.has_attachments) {
|
|
371
|
+
return 'application/octet-stream';
|
|
372
|
+
}
|
|
373
|
+
// Default to plain text
|
|
374
|
+
return 'text/plain';
|
|
375
|
+
}
|
|
376
|
+
shouldIncludeSource(source, options) {
|
|
377
|
+
// Apply size filter
|
|
378
|
+
if (options?.filters?.maxSize && source.size > options.filters.maxSize) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
// Apply date range filter
|
|
382
|
+
if (options?.filters?.dateRange) {
|
|
383
|
+
const { from, to } = options.filters.dateRange;
|
|
384
|
+
if (from && source.lastModified < from)
|
|
385
|
+
return false;
|
|
386
|
+
if (to && source.lastModified > to)
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
// Apply MIME type filter
|
|
390
|
+
if (options?.filters?.mimeTypes && !options.filters.mimeTypes.includes(source.mimeType)) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
sleep(ms) {
|
|
396
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
exports.default = CorePlugin;
|
|
400
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../plugins/core/index.ts"],"names":[],"mappings":";;;;;AAAA,kDAA6C;AAC7C,wDAA0B;AAC1B,gDAAwB;AACxB,+EAA2E;AAoD3E,MAAqB,UAAU;IAA/B;QACW,SAAI,GAAG,MAAM,CAAC;QACd,YAAO,GAAG,OAAO,CAAC;QAClB,gBAAW,GAAG,wCAAwC,CAAC;QACvD,wBAAmB,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAU,CAAC;IAkc7D,CAAC;IA7bC,KAAK,CAAC,cAAc,CAAC,MAAoB;QACvC,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,MAAoB,CAAC;YACxC,MAAM,MAAM,GAAG,MAA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tools",
|
|
6
|
+
"main": "index.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"axios": "^1.5.0",
|
|
9
|
+
"fs-extra": "^11.1.0"
|
|
10
|
+
},
|
|
11
|
+
"hubdocToolVersion": "^1.0.0",
|
|
12
|
+
"capabilities": {
|
|
13
|
+
"scan": true,
|
|
14
|
+
"import": true,
|
|
15
|
+
"export": false
|
|
16
|
+
},
|
|
17
|
+
"apiEndpoints": {
|
|
18
|
+
"authentication": "/api/token",
|
|
19
|
+
"documents": "/api/d2/docs",
|
|
20
|
+
"documentDetail": "/api/d2/docs/{id}"
|
|
21
|
+
},
|
|
22
|
+
"configuration": {
|
|
23
|
+
"required": ["baseUrl", "username", "password"],
|
|
24
|
+
"optional": ["bearerToken", "tempDir"]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DocumentSourcePlugin, DocumentSource, PluginConfig, ScanResult, PluginImportOptions, PluginExportOptions, ImportResult, ExportResult } from '../../src/types/plugins';
|
|
2
|
+
export default class FileSystemPlugin implements DocumentSourcePlugin {
|
|
3
|
+
readonly name = "filesystem";
|
|
4
|
+
readonly version = "1.0.0";
|
|
5
|
+
readonly description = "Local filesystem document source";
|
|
6
|
+
readonly supportedOperations: readonly ["import", "export", "both"];
|
|
7
|
+
private config?;
|
|
8
|
+
testConnection(config: PluginConfig): Promise<boolean>;
|
|
9
|
+
scan(config: PluginConfig, options?: PluginImportOptions): Promise<ScanResult>;
|
|
10
|
+
import(config: PluginConfig, sources: DocumentSource[], targetDir: string, options?: PluginImportOptions): Promise<ImportResult[]>;
|
|
11
|
+
private importSingle;
|
|
12
|
+
export?(config: PluginConfig, localSources: DocumentSource[], options?: PluginExportOptions): Promise<ExportResult[]>;
|
|
13
|
+
getConfigSchema(): Record<string, any>;
|
|
14
|
+
initialize(config: PluginConfig): Promise<void>;
|
|
15
|
+
destroy(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a file is a metadata file and should be skipped from document processing
|
|
18
|
+
*/
|
|
19
|
+
private isMetadataFile;
|
|
20
|
+
private getMimeType;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../plugins/filesystem/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACb,MAAM,yBAAyB,CAAC;AAWjC,MAAM,CAAC,OAAO,OAAO,gBAAiB,YAAW,oBAAoB;IACnE,QAAQ,CAAC,IAAI,gBAAgB;IAC7B,QAAQ,CAAC,OAAO,WAAW;IAC3B,QAAQ,CAAC,WAAW,sCAAsC;IAC1D,QAAQ,CAAC,mBAAmB,wCAAyC;IAErE,OAAO,CAAC,MAAM,CAAC,CAAmB;IAE5B,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAUtD,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IAqH9E,MAAM,CACV,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,cAAc,EAAE,EACzB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,YAAY,EAAE,CAAC;YA2BZ,YAAY;IAyBpB,MAAM,CAAC,CACX,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,cAAc,EAAE,EAC9B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,YAAY,EAAE,CAAC;IAiD1B,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAkChC,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/C,OAAO,IA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