@arela/uploader 0.2.6 → 0.2.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arela/uploader",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "CLI to upload files/directories to Arela",
5
5
  "bin": {
6
6
  "arela": "./src/index.js"
@@ -28,10 +28,10 @@ class Config {
28
28
  const __dirname = path.dirname(__filename);
29
29
  const packageJsonPath = path.resolve(__dirname, '../../package.json');
30
30
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
31
- return packageJson.version || '0.2.6';
31
+ return packageJson.version || '0.2.7';
32
32
  } catch (error) {
33
33
  console.warn('⚠️ Could not read package.json version, using fallback');
34
- return '0.2.6';
34
+ return '0.2.7';
35
35
  }
36
36
  }
37
37
 
@@ -104,16 +104,28 @@ export class DatabaseService {
104
104
  }
105
105
 
106
106
  // Initialize record with basic file stats
107
+ const fileExtension = path
108
+ .extname(file.path)
109
+ .toLowerCase()
110
+ .replace('.', '');
111
+ const filename = file.originalName || path.basename(file.path);
112
+
107
113
  const record = {
108
114
  document_type: null,
109
115
  size: stats.size,
110
116
  num_pedimento: null,
111
- filename: file.originalName || path.basename(file.path),
117
+ filename: filename,
112
118
  original_path: originalPath,
113
119
  arela_path: null,
114
120
  status: 'stats',
115
121
  rfc: null,
116
122
  message: null,
123
+ file_extension: fileExtension,
124
+ is_like_simplificado: fileExtension === 'pdf' &&
125
+ filename.toLowerCase().includes('simp'),
126
+ year: null,
127
+ created_at: new Date().toISOString(),
128
+ modified_at: stats.mtime.toISOString(),
117
129
  };
118
130
 
119
131
  // Try to detect document type for supported files
@@ -130,6 +142,10 @@ export class DatabaseService {
130
142
  record.arela_path = detection.arelaPath;
131
143
  }
132
144
 
145
+ if (detection.detectedPedimentoYear) {
146
+ record.year = detection.detectedPedimentoYear;
147
+ }
148
+
133
149
  const rfcField = detection.fields.find(
134
150
  (f) => f.name === 'rfc' && f.found,
135
151
  );
@@ -210,6 +226,9 @@ export class DatabaseService {
210
226
  file_extension: fileExtension,
211
227
  created_at: new Date().toISOString(),
212
228
  modified_at: stats.mtime.toISOString(),
229
+ is_like_simplificado: fileExtension === 'pdf' &&
230
+ (file.originalName || path.basename(file.path)).toLowerCase().includes('simp'),
231
+ year: null,
213
232
  };
214
233
 
215
234
  allRecords.push(record);
@@ -287,6 +306,8 @@ export class DatabaseService {
287
306
  modified_at: record.modified_at,
288
307
  filename: record.filename,
289
308
  file_extension: record.file_extension,
309
+ is_like_simplificado: record.is_like_simplificado,
310
+ year: record.year,
290
311
  })
291
312
  .eq('original_path', record.original_path);
292
313
 
@@ -329,7 +350,7 @@ export class DatabaseService {
329
350
 
330
351
  const processingBatchSize = parseInt(options.batchSize) || 10;
331
352
  // Reduced query batch size to avoid timeouts
332
- const queryBatchSize = 500; // Reduced from 1000 to 500
353
+ const queryBatchSize = 100; // Reduced from 500 to 100
333
354
 
334
355
  let totalDetected = 0;
335
356
  let totalProcessed = 0;
@@ -355,9 +376,9 @@ export class DatabaseService {
355
376
  .select('id, original_path, filename, file_extension, status')
356
377
  .eq('status', 'fs-stats')
357
378
  .eq('file_extension', 'pdf')
358
- .ilike('filename', '%simp%')
379
+ .eq('is_like_simplificado', true)
359
380
  .range(offset, offset + queryBatchSize - 1)
360
- .order('id'); // Add explicit ordering for consistent pagination
381
+ .order('created_at');
361
382
  }, `fetch PDF records chunk ${chunkNumber}`);
362
383
 
363
384
  if (queryError) {
@@ -416,6 +437,7 @@ export class DatabaseService {
416
437
  num_pedimento: detection.detectedPedimento,
417
438
  arela_path: detection.arelaPath,
418
439
  message: detection.error || null,
440
+ year: detection.detectedPedimentoYear || null,
419
441
  };
420
442
 
421
443
  if (detection.fields) {
@@ -522,13 +544,13 @@ export class DatabaseService {
522
544
  async propagateArelaPath(options = {}) {
523
545
  const supabase = await this.#getSupabaseClient();
524
546
 
525
- logger.info('Phase 3: Starting arela_path propagation process...');
526
- console.log('🔍 Finding pedimento_simplificado records with arela_path...');
547
+ logger.info('Phase 3: Starting arela_path and year propagation process...');
548
+ console.log('🔍 Finding pedimento_simplificado records with arela_path and year...');
527
549
 
528
550
  // Get all pedimento_simplificado records that have arela_path
529
551
  const { data: pedimentoRecords, error: pedimentoError } = await supabase
530
552
  .from('uploader')
531
- .select('id, original_path, arela_path, filename')
553
+ .select('id, original_path, arela_path, filename, year')
532
554
  .eq('document_type', 'pedimento_simplificado')
533
555
  .not('arela_path', 'is', null);
534
556
 
@@ -567,7 +589,7 @@ export class DatabaseService {
567
589
  const basePath = path.dirname(pedimento.original_path);
568
590
 
569
591
  logger.info(
570
- `Processing pedimento: ${pedimento.filename} | Base path: ${basePath}`,
592
+ `Processing pedimento: ${pedimento.filename} | Base path: ${basePath} | Year: ${pedimento.year || 'N/A'}`,
571
593
  );
572
594
 
573
595
  // Extract folder part from existing arela_path
@@ -618,7 +640,10 @@ export class DatabaseService {
618
640
  try {
619
641
  const { error: updateError } = await supabase
620
642
  .from('uploader')
621
- .update({ arela_path: folderArelaPath })
643
+ .update({
644
+ arela_path: folderArelaPath,
645
+ year: pedimento.year
646
+ })
622
647
  .in('id', batchIds);
623
648
 
624
649
  if (updateError) {
@@ -629,7 +654,7 @@ export class DatabaseService {
629
654
  } else {
630
655
  totalUpdated += batchIds.length;
631
656
  logger.info(
632
- `Successfully updated batch ${batchNumber}: ${batchIds.length} files`,
657
+ `Successfully updated batch ${batchNumber}: ${batchIds.length} files with arela_path and year`,
633
658
  );
634
659
  }
635
660
  } catch (batchError) {
@@ -654,7 +679,7 @@ export class DatabaseService {
654
679
  };
655
680
 
656
681
  logger.success(
657
- `Phase 3 Summary: ${totalProcessed} pedimentos processed, ${totalUpdated} files updated, ${totalErrors} errors`,
682
+ `Phase 3 Summary: ${totalProcessed} pedimentos processed, ${totalUpdated} files updated with arela_path and year, ${totalErrors} errors`,
658
683
  );
659
684
 
660
685
  return result;