@arela/uploader 1.1.4 → 1.2.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/.claude/worktrees/agent-multi-profile/.env.template +224 -0
- package/.claude/worktrees/agent-multi-profile/.prettierrc +13 -0
- package/.claude/worktrees/agent-multi-profile/README.md +405 -0
- package/.claude/worktrees/agent-multi-profile/package-lock.json +7096 -0
- package/.claude/worktrees/agent-multi-profile/package.json +78 -0
- package/.claude/worktrees/agent-multi-profile/scripts/cleanup-ds-store.js +109 -0
- package/.claude/worktrees/agent-multi-profile/scripts/cleanup-system-files.js +69 -0
- package/.claude/worktrees/agent-multi-profile/scripts/scoring-compare.js +243 -0
- package/.claude/worktrees/agent-multi-profile/scripts/scoring-phase4-check.js +96 -0
- package/.claude/worktrees/agent-multi-profile/scripts/tests/phase-7-features.test.js +415 -0
- package/.claude/worktrees/agent-multi-profile/scripts/tests/signal-handling.test.js +275 -0
- package/.claude/worktrees/agent-multi-profile/scripts/tests/smart-watch-integration.test.js +554 -0
- package/.claude/worktrees/agent-multi-profile/scripts/tests/watch-service-integration.test.js +584 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/AgentCommand.js +229 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/AgentInitCommand.js +316 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/DatastageCommand.js +164 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/GDriveSyncCommand.js +475 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/IdentifyCommand.js +708 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/PollWorkerCommand.js +169 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/PropagateCommand.js +636 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/PushCommand.js +743 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/ScanCommand.js +722 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/UploadCommand.js +587 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/WatchCommand.js +1342 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/WorkerCommand.js +337 -0
- package/.claude/worktrees/agent-multi-profile/src/config/config.js +862 -0
- package/.claude/worktrees/agent-multi-profile/src/document-type-shared.js +131 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/_pedimento-shared-extractors.js +348 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/doda-pdf.js +121 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/doda-xml.js +118 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/factura-inter-agencia.js +186 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/facturas-comerciales.js +233 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/pedimento-completo-xml.js +372 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/pedimento-completo.js +108 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/pedimento-simplificado.js +76 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/proforma.js +29 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/support-document.js +200 -0
- package/.claude/worktrees/agent-multi-profile/src/errors/ErrorHandler.js +278 -0
- package/.claude/worktrees/agent-multi-profile/src/errors/ErrorTypes.js +104 -0
- package/.claude/worktrees/agent-multi-profile/src/file-detection.js +338 -0
- package/.claude/worktrees/agent-multi-profile/src/index.js +890 -0
- package/.claude/worktrees/agent-multi-profile/src/scoring/db-matcher-adapter.js +98 -0
- package/.claude/worktrees/agent-multi-profile/src/scoring/matchers-seed.js +386 -0
- package/.claude/worktrees/agent-multi-profile/src/scoring/scoring-engine.js +251 -0
- package/.claude/worktrees/agent-multi-profile/src/services/AdvancedFilterService.js +505 -0
- package/.claude/worktrees/agent-multi-profile/src/services/AutoProcessingService.js +749 -0
- package/.claude/worktrees/agent-multi-profile/src/services/BenchmarkingService.js +381 -0
- package/.claude/worktrees/agent-multi-profile/src/services/DatabaseService.js +2173 -0
- package/.claude/worktrees/agent-multi-profile/src/services/DatastageApiService.js +240 -0
- package/.claude/worktrees/agent-multi-profile/src/services/ErrorMonitor.js +275 -0
- package/.claude/worktrees/agent-multi-profile/src/services/GoogleDriveService.js +217 -0
- package/.claude/worktrees/agent-multi-profile/src/services/LoggingService.js +649 -0
- package/.claude/worktrees/agent-multi-profile/src/services/MonitoringService.js +401 -0
- package/.claude/worktrees/agent-multi-profile/src/services/PerformanceOptimizer.js +511 -0
- package/.claude/worktrees/agent-multi-profile/src/services/PipelineApiService.js +274 -0
- package/.claude/worktrees/agent-multi-profile/src/services/PipelineJobRunner.js +389 -0
- package/.claude/worktrees/agent-multi-profile/src/services/ProfileManager.js +164 -0
- package/.claude/worktrees/agent-multi-profile/src/services/ReportingService.js +511 -0
- package/.claude/worktrees/agent-multi-profile/src/services/ScanApiService.js +775 -0
- package/.claude/worktrees/agent-multi-profile/src/services/SignalHandler.js +255 -0
- package/.claude/worktrees/agent-multi-profile/src/services/SmartWatchDatabaseService.js +527 -0
- package/.claude/worktrees/agent-multi-profile/src/services/WatchService.js +783 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/ApiUploadService.js +676 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/BaseUploadService.js +36 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/MultiApiUploadService.js +233 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/SupabaseUploadService.js +148 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/UploadServiceFactory.js +100 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/CleanupManager.js +262 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/FileOperations.js +192 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/FileSanitizer.js +99 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/PathDetector.js +198 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/PathNormalizer.js +274 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/WatchEventHandler.js +522 -0
- package/.claude/worktrees/agent-multi-profile/supabase/migrations/001_create_initial_schema.sql +366 -0
- package/.claude/worktrees/agent-multi-profile/supabase/migrations/002_align_with_arela_api_schema.sql +145 -0
- package/.claude/worktrees/agent-multi-profile/tests/commands/IdentifyCommand.test.js +570 -0
- package/.claude/worktrees/agent-multi-profile/tests/commands/PropagateCommand.test.js +568 -0
- package/.claude/worktrees/agent-multi-profile/tests/commands/PushCommand.test.js +754 -0
- package/.claude/worktrees/agent-multi-profile/tests/commands/ScanCommand.test.js +382 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/PathAndTableNameGeneration.test.js +1211 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/factura-inter-agencia.test.js +218 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/pedimento-completo-xml-matcher.test.js +271 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/pedimento-simplificado-matcher.test.js +185 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/scoring-engine.test.js +221 -0
- package/README.md +65 -0
- package/package.json +1 -1
- package/src/commands/AgentCommand.js +210 -0
- package/src/commands/AgentInitCommand.js +316 -0
- package/src/commands/PollWorkerCommand.js +11 -322
- package/src/config/config.js +44 -6
- package/src/index.js +55 -0
- package/src/services/LoggingService.js +35 -0
- package/src/services/PipelineApiService.js +7 -1
- package/src/services/PipelineJobRunner.js +389 -0
- package/src/services/ProfileManager.js +164 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_PROFILES_PATH = '~/.arela/profiles.json';
|
|
6
|
+
export const DEFAULT_AGENT_LOG_PATH = '~/.arela/arela-agent.log';
|
|
7
|
+
const DEFAULT_POLL_INTERVAL_MS = 5000;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Expand a leading '~' to the user's home directory
|
|
11
|
+
* @param {string} inputPath
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
export function expandHome(inputPath) {
|
|
15
|
+
if (inputPath && inputPath.startsWith('~')) {
|
|
16
|
+
return path.join(os.homedir(), inputPath.slice(1));
|
|
17
|
+
}
|
|
18
|
+
return inputPath;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Profile Manager
|
|
23
|
+
* Loads and validates the agent's profiles.json — the only local configuration
|
|
24
|
+
* the multi-profile agent needs: one machine serverId plus {name, url, token}
|
|
25
|
+
* per tenant API. Everything else (scan directories, tuning, schedule) lives
|
|
26
|
+
* server-side in pipeline_config.
|
|
27
|
+
*
|
|
28
|
+
* Minimal schema:
|
|
29
|
+
* {
|
|
30
|
+
* "version": 1,
|
|
31
|
+
* "serverId": "PALCO-01",
|
|
32
|
+
* "pollIntervalMs": 5000, // optional
|
|
33
|
+
* "logFile": "~/.arela/arela-agent.log", // optional
|
|
34
|
+
* "profiles": [
|
|
35
|
+
* { "name": "ktj", "url": "https://…", "token": "ak_…" },
|
|
36
|
+
* {
|
|
37
|
+
* "name": "cem", "url": "https://…", "token": "ak_…",
|
|
38
|
+
* "targets": { "agencia": { "baseUrl": "https://…", "token": "ak_…" } },
|
|
39
|
+
* "env": { "SCAN_DIRECTORY_LEVEL": "2" }
|
|
40
|
+
* }
|
|
41
|
+
* ]
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
export class ProfileManager {
|
|
45
|
+
/**
|
|
46
|
+
* Load, validate and normalize the profiles file.
|
|
47
|
+
* @param {string} [configPath] - Path to profiles.json (supports '~')
|
|
48
|
+
* @returns {{serverId: string, pollIntervalMs: number, logFile: string, profiles: Object[]}}
|
|
49
|
+
*/
|
|
50
|
+
static loadProfiles(configPath = DEFAULT_PROFILES_PATH) {
|
|
51
|
+
const resolvedPath = path.resolve(expandHome(configPath));
|
|
52
|
+
|
|
53
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Profiles file not found: ${resolvedPath}. ` +
|
|
56
|
+
`Run 'arela agent init --from <dir...>' to generate one from existing .env folders.`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let raw;
|
|
61
|
+
try {
|
|
62
|
+
raw = JSON.parse(fs.readFileSync(resolvedPath, 'utf-8'));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new Error(`Invalid JSON in ${resolvedPath}: ${error.message}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!raw.serverId || typeof raw.serverId !== 'string') {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`${resolvedPath}: 'serverId' is required at the root level (one per machine, e.g. "PALCO-01")`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!Array.isArray(raw.profiles) || raw.profiles.length === 0) {
|
|
74
|
+
throw new Error(`${resolvedPath}: 'profiles' must be a non-empty array`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const seenNames = new Set();
|
|
78
|
+
const profiles = [];
|
|
79
|
+
|
|
80
|
+
raw.profiles.forEach((profile, index) => {
|
|
81
|
+
const label = `Profile ${profile?.name ? `'${profile.name}'` : `#${index + 1}`}`;
|
|
82
|
+
|
|
83
|
+
if (!profile.name || typeof profile.name !== 'string') {
|
|
84
|
+
throw new Error(`Profile #${index + 1}: 'name' is required`);
|
|
85
|
+
}
|
|
86
|
+
const name = profile.name.toLowerCase();
|
|
87
|
+
if (seenNames.has(name)) {
|
|
88
|
+
throw new Error(`${label}: duplicate profile name`);
|
|
89
|
+
}
|
|
90
|
+
seenNames.add(name);
|
|
91
|
+
|
|
92
|
+
if (profile.enabled === false) return;
|
|
93
|
+
|
|
94
|
+
this.#validateEndpoint(label, profile.url, profile.token);
|
|
95
|
+
|
|
96
|
+
const targets = {
|
|
97
|
+
// Same tenant answers under every symbolic name jobs may reference
|
|
98
|
+
agencia: { baseUrl: profile.url, token: profile.token },
|
|
99
|
+
cliente: { baseUrl: profile.url, token: profile.token },
|
|
100
|
+
[name]: { baseUrl: profile.url, token: profile.token },
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Explicit targets override symbolic names (real cross-tenant cases)
|
|
104
|
+
for (const [targetName, targetConfig] of Object.entries(
|
|
105
|
+
profile.targets || {},
|
|
106
|
+
)) {
|
|
107
|
+
this.#validateEndpoint(
|
|
108
|
+
`${label}: targets.${targetName}`,
|
|
109
|
+
targetConfig?.baseUrl,
|
|
110
|
+
targetConfig?.token,
|
|
111
|
+
);
|
|
112
|
+
targets[targetName.toLowerCase()] = {
|
|
113
|
+
baseUrl: targetConfig.baseUrl,
|
|
114
|
+
token: targetConfig.token,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (profile.env && typeof profile.env !== 'object') {
|
|
119
|
+
throw new Error(`${label}: 'env' must be an object of key/value pairs`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
profiles.push({
|
|
123
|
+
name,
|
|
124
|
+
url: profile.url,
|
|
125
|
+
token: profile.token,
|
|
126
|
+
serverId: raw.serverId,
|
|
127
|
+
targets,
|
|
128
|
+
env: profile.env || {},
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (profiles.length === 0) {
|
|
133
|
+
throw new Error(`${resolvedPath}: all profiles are disabled`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
serverId: raw.serverId,
|
|
138
|
+
pollIntervalMs:
|
|
139
|
+
parseInt(raw.pollIntervalMs) > 0
|
|
140
|
+
? parseInt(raw.pollIntervalMs)
|
|
141
|
+
: DEFAULT_POLL_INTERVAL_MS,
|
|
142
|
+
logFile: path.resolve(expandHome(raw.logFile || DEFAULT_AGENT_LOG_PATH)),
|
|
143
|
+
profiles,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Validate a {url, token} pair with a per-field error message
|
|
149
|
+
* @private
|
|
150
|
+
*/
|
|
151
|
+
static #validateEndpoint(label, url, token) {
|
|
152
|
+
if (!url || typeof url !== 'string') {
|
|
153
|
+
throw new Error(`${label}: 'url' is required`);
|
|
154
|
+
}
|
|
155
|
+
if (!/^https?:\/\//.test(url)) {
|
|
156
|
+
throw new Error(`${label}: 'url' must start with http:// or https://`);
|
|
157
|
+
}
|
|
158
|
+
if (!token || typeof token !== 'string') {
|
|
159
|
+
throw new Error(`${label}: 'token' is required`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export default ProfileManager;
|