@programisto/edrm-storage 0.3.1

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.
Files changed (68) hide show
  1. package/README.md +135 -0
  2. package/dist/bin/www.d.ts +2 -0
  3. package/dist/bin/www.js +13 -0
  4. package/dist/modules/edrm-exams/lib/openai/correctQuestion.txt +9 -0
  5. package/dist/modules/edrm-exams/lib/openai/createQuestion.txt +6 -0
  6. package/dist/modules/edrm-exams/lib/openai.d.ts +37 -0
  7. package/dist/modules/edrm-exams/lib/openai.js +135 -0
  8. package/dist/modules/edrm-exams/listeners/correct.listener.d.ts +2 -0
  9. package/dist/modules/edrm-exams/listeners/correct.listener.js +167 -0
  10. package/dist/modules/edrm-exams/models/candidate.model.d.ts +21 -0
  11. package/dist/modules/edrm-exams/models/candidate.model.js +75 -0
  12. package/dist/modules/edrm-exams/models/candidate.models.d.ts +21 -0
  13. package/dist/modules/edrm-exams/models/candidate.models.js +75 -0
  14. package/dist/modules/edrm-exams/models/company.model.d.ts +8 -0
  15. package/dist/modules/edrm-exams/models/company.model.js +34 -0
  16. package/dist/modules/edrm-exams/models/contact.model.d.ts +14 -0
  17. package/dist/modules/edrm-exams/models/contact.model.js +60 -0
  18. package/dist/modules/edrm-exams/models/test-category.models.d.ts +7 -0
  19. package/dist/modules/edrm-exams/models/test-category.models.js +29 -0
  20. package/dist/modules/edrm-exams/models/test-job.model.d.ts +7 -0
  21. package/dist/modules/edrm-exams/models/test-job.model.js +29 -0
  22. package/dist/modules/edrm-exams/models/test-question.model.d.ts +25 -0
  23. package/dist/modules/edrm-exams/models/test-question.model.js +70 -0
  24. package/dist/modules/edrm-exams/models/test-result.model.d.ts +26 -0
  25. package/dist/modules/edrm-exams/models/test-result.model.js +70 -0
  26. package/dist/modules/edrm-exams/models/test.model.d.ts +47 -0
  27. package/dist/modules/edrm-exams/models/test.model.js +133 -0
  28. package/dist/modules/edrm-exams/models/user.model.d.ts +18 -0
  29. package/dist/modules/edrm-exams/models/user.model.js +73 -0
  30. package/dist/modules/edrm-exams/routes/company.router.d.ts +7 -0
  31. package/dist/modules/edrm-exams/routes/company.router.js +108 -0
  32. package/dist/modules/edrm-exams/routes/exams-candidate.router.d.ts +7 -0
  33. package/dist/modules/edrm-exams/routes/exams-candidate.router.js +448 -0
  34. package/dist/modules/edrm-exams/routes/exams.router.d.ts +8 -0
  35. package/dist/modules/edrm-exams/routes/exams.router.js +1343 -0
  36. package/dist/modules/edrm-exams/routes/result.router.d.ts +7 -0
  37. package/dist/modules/edrm-exams/routes/result.router.js +370 -0
  38. package/dist/modules/edrm-exams/routes/user.router.d.ts +7 -0
  39. package/dist/modules/edrm-exams/routes/user.router.js +96 -0
  40. package/dist/modules/edrm-storage/config/edrm-storage.config.d.ts +29 -0
  41. package/dist/modules/edrm-storage/config/edrm-storage.config.js +31 -0
  42. package/dist/modules/edrm-storage/config/environment.example.d.ts +54 -0
  43. package/dist/modules/edrm-storage/config/environment.example.js +130 -0
  44. package/dist/modules/edrm-storage/examples/usage.example.d.ts +52 -0
  45. package/dist/modules/edrm-storage/examples/usage.example.js +156 -0
  46. package/dist/modules/edrm-storage/index.d.ts +5 -0
  47. package/dist/modules/edrm-storage/index.js +8 -0
  48. package/dist/modules/edrm-storage/integration/edrm-storage-integration.d.ts +53 -0
  49. package/dist/modules/edrm-storage/integration/edrm-storage-integration.js +132 -0
  50. package/dist/modules/edrm-storage/interfaces/storage-provider.interface.d.ts +35 -0
  51. package/dist/modules/edrm-storage/interfaces/storage-provider.interface.js +1 -0
  52. package/dist/modules/edrm-storage/migrations/edrm-storage.migration.d.ts +6 -0
  53. package/dist/modules/edrm-storage/migrations/edrm-storage.migration.js +151 -0
  54. package/dist/modules/edrm-storage/models/file.model.d.ts +78 -0
  55. package/dist/modules/edrm-storage/models/file.model.js +190 -0
  56. package/dist/modules/edrm-storage/providers/s3-storage.provider.d.ts +18 -0
  57. package/dist/modules/edrm-storage/providers/s3-storage.provider.js +95 -0
  58. package/dist/modules/edrm-storage/routes/edrm-storage.router.d.ts +8 -0
  59. package/dist/modules/edrm-storage/routes/edrm-storage.router.js +155 -0
  60. package/dist/modules/edrm-storage/scripts/quick-start.d.ts +7 -0
  61. package/dist/modules/edrm-storage/scripts/quick-start.js +114 -0
  62. package/dist/modules/edrm-storage/services/edrm-storage.service.d.ts +29 -0
  63. package/dist/modules/edrm-storage/services/edrm-storage.service.js +188 -0
  64. package/dist/modules/edrm-storage/tests/edrm-storage.service.test.d.ts +1 -0
  65. package/dist/modules/edrm-storage/tests/edrm-storage.service.test.js +143 -0
  66. package/dist/modules/edrm-storage/tests/integration.test.d.ts +1 -0
  67. package/dist/modules/edrm-storage/tests/integration.test.js +141 -0
  68. package/package.json +81 -0
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Configuration d'environnement pour le module EDRM Storage
3
+ * Copiez ce fichier vers .env et configurez vos valeurs
4
+ */
5
+ export const EdrmStorageEnvironment = {
6
+ // Configuration AWS S3
7
+ AWS: {
8
+ REGION: process.env.AWS_REGION || 'us-east-1',
9
+ ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID || '',
10
+ SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY || '',
11
+ BUCKET: process.env.S3_BUCKET || 'edrm-storage'
12
+ },
13
+ // Configuration MinIO (optionnel)
14
+ MINIO: {
15
+ ENDPOINT: process.env.MINIO_ENDPOINT || 'http://localhost:9000',
16
+ ACCESS_KEY: process.env.MINIO_ACCESS_KEY || '',
17
+ SECRET_KEY: process.env.MINIO_SECRET_KEY || '',
18
+ BUCKET: process.env.MINIO_BUCKET || 'edrm-storage',
19
+ USE_SSL: process.env.MINIO_USE_SSL === 'true'
20
+ },
21
+ // Configuration générale
22
+ GENERAL: {
23
+ DEFAULT_PROVIDER: process.env.EDRM_STORAGE_PROVIDER || 'S3',
24
+ MAX_FILE_SIZE: parseInt(process.env.EDRM_MAX_FILE_SIZE || '104857600'), // 100MB
25
+ UPLOAD_EXPIRES_IN: parseInt(process.env.EDRM_UPLOAD_EXPIRES_IN || '3600'), // 1 heure
26
+ DOWNLOAD_EXPIRES_IN: parseInt(process.env.EDRM_DOWNLOAD_EXPIRES_IN || '3600'), // 1 heure
27
+ ALLOWED_MIME_TYPES: process.env.EDRM_ALLOWED_MIME_TYPES?.split(',') || [
28
+ 'application/pdf',
29
+ 'application/msword',
30
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
31
+ 'image/jpeg',
32
+ 'image/png',
33
+ 'image/gif',
34
+ 'text/plain',
35
+ 'application/zip',
36
+ 'application/x-zip-compressed'
37
+ ]
38
+ },
39
+ // Configuration des événements
40
+ EVENTS: {
41
+ ENABLED: process.env.EDRM_EVENTS_ENABLED !== 'false',
42
+ EMIT_FILE_STORED: process.env.EDRM_EMIT_FILE_STORED !== 'false',
43
+ EMIT_FILE_DELETED: process.env.EDRM_EMIT_FILE_DELETED !== 'false',
44
+ EMIT_FILE_ACCESSED: process.env.EDRM_EMIT_FILE_ACCESSED !== 'false'
45
+ },
46
+ // Configuration de sécurité
47
+ SECURITY: {
48
+ PRESIGNED_URL_EXPIRES_IN: parseInt(process.env.EDRM_PRESIGNED_URL_EXPIRES_IN || '3600'),
49
+ MAX_CONCURRENT_UPLOADS: parseInt(process.env.EDRM_MAX_CONCURRENT_UPLOADS || '100'),
50
+ ENABLE_ANTIVIRUS: process.env.EDRM_ENABLE_ANTIVIRUS === 'true',
51
+ ENABLE_WATERMARKING: process.env.EDRM_ENABLE_WATERMARKING === 'true'
52
+ },
53
+ // Configuration de monitoring
54
+ MONITORING: {
55
+ ENABLE_METRICS: process.env.EDRM_ENABLE_METRICS !== 'false',
56
+ LOG_LEVEL: process.env.EDRM_LOG_LEVEL || 'info',
57
+ ENABLE_AUDIT_LOG: process.env.EDRM_ENABLE_AUDIT_LOG === 'true'
58
+ }
59
+ };
60
+ /**
61
+ * Validation de la configuration
62
+ */
63
+ export function validateEdrmStorageConfig() {
64
+ const errors = [];
65
+ // Vérifier les variables AWS requises
66
+ if (!EdrmStorageEnvironment.AWS.ACCESS_KEY_ID) {
67
+ errors.push('AWS_ACCESS_KEY_ID est requis');
68
+ }
69
+ if (!EdrmStorageEnvironment.AWS.SECRET_ACCESS_KEY) {
70
+ errors.push('AWS_SECRET_ACCESS_KEY est requis');
71
+ }
72
+ if (!EdrmStorageEnvironment.AWS.BUCKET) {
73
+ errors.push('S3_BUCKET est requis');
74
+ }
75
+ // Vérifier les valeurs numériques
76
+ if (EdrmStorageEnvironment.GENERAL.MAX_FILE_SIZE <= 0) {
77
+ errors.push('EDRM_MAX_FILE_SIZE doit être positif');
78
+ }
79
+ if (EdrmStorageEnvironment.GENERAL.UPLOAD_EXPIRES_IN <= 0) {
80
+ errors.push('EDRM_UPLOAD_EXPIRES_IN doit être positif');
81
+ }
82
+ if (EdrmStorageEnvironment.GENERAL.DOWNLOAD_EXPIRES_IN <= 0) {
83
+ errors.push('EDRM_DOWNLOAD_EXPIRES_IN doit être positif');
84
+ }
85
+ return {
86
+ valid: errors.length === 0,
87
+ errors
88
+ };
89
+ }
90
+ /**
91
+ * Exemple de fichier .env
92
+ */
93
+ export const ENV_EXAMPLE = `
94
+ # Configuration AWS S3
95
+ AWS_REGION=us-east-1
96
+ AWS_ACCESS_KEY_ID=your_access_key_here
97
+ AWS_SECRET_ACCESS_KEY=your_secret_key_here
98
+ S3_BUCKET=edrm-storage
99
+
100
+ # Configuration MinIO (optionnel)
101
+ MINIO_ENDPOINT=http://localhost:9000
102
+ MINIO_ACCESS_KEY=your_minio_key
103
+ MINIO_SECRET_KEY=your_minio_secret
104
+ MINIO_BUCKET=edrm-storage
105
+ MINIO_USE_SSL=false
106
+
107
+ # Configuration générale
108
+ EDRM_STORAGE_PROVIDER=S3
109
+ EDRM_MAX_FILE_SIZE=104857600
110
+ EDRM_UPLOAD_EXPIRES_IN=3600
111
+ EDRM_DOWNLOAD_EXPIRES_IN=3600
112
+ EDRM_ALLOWED_MIME_TYPES=application/pdf,image/jpeg,image/png
113
+
114
+ # Configuration des événements
115
+ EDRM_EVENTS_ENABLED=true
116
+ EDRM_EMIT_FILE_STORED=true
117
+ EDRM_EMIT_FILE_DELETED=true
118
+ EDRM_EMIT_FILE_ACCESSED=true
119
+
120
+ # Configuration de sécurité
121
+ EDRM_PRESIGNED_URL_EXPIRES_IN=3600
122
+ EDRM_MAX_CONCURRENT_UPLOADS=100
123
+ EDRM_ENABLE_ANTIVIRUS=false
124
+ EDRM_ENABLE_WATERMARKING=false
125
+
126
+ # Configuration de monitoring
127
+ EDRM_ENABLE_METRICS=true
128
+ EDRM_LOG_LEVEL=info
129
+ EDRM_ENABLE_AUDIT_LOG=false
130
+ `;
@@ -0,0 +1,52 @@
1
+ import { FileProvider } from '../models/file.model.js';
2
+ export declare class ExampleUsage {
3
+ private storageService;
4
+ constructor();
5
+ /**
6
+ * Exemple d'upload d'un CV pour une candidature
7
+ */
8
+ uploadCVForApplication(applicationId: string, originalName: string, mimeType: string, size: number): Promise<any>;
9
+ /**
10
+ * Exemple de récupération d'une URL de téléchargement
11
+ */
12
+ getDownloadUrl(fileId: string, filename?: string): Promise<any>;
13
+ /**
14
+ * Exemple de listing des fichiers d'une entité
15
+ */
16
+ listEntityFiles(entityName: string, entityId: string): Promise<{
17
+ files: any[];
18
+ total: number;
19
+ page: number;
20
+ totalPages: number;
21
+ }>;
22
+ /**
23
+ * Exemple d'upload de document de mission
24
+ */
25
+ uploadMissionDocument(applicationId: string, originalName: string, mimeType: string, size: number): Promise<{
26
+ fileId: import("mongoose").Types.ObjectId;
27
+ uploadId: string;
28
+ presignedUrl: string;
29
+ expiresAt: Date;
30
+ bucket: string;
31
+ key: string;
32
+ }>;
33
+ /**
34
+ * Exemple de suppression d'un fichier
35
+ */
36
+ deleteFile(fileId: string): Promise<boolean>;
37
+ /**
38
+ * Exemple d'utilisation avec différents providers
39
+ */
40
+ uploadWithDifferentProvider(originalName: string, mimeType: string, size: number, provider: FileProvider): Promise<{
41
+ fileId: import("mongoose").Types.ObjectId;
42
+ uploadId: string;
43
+ presignedUrl: string;
44
+ expiresAt: Date;
45
+ bucket: string;
46
+ key: string;
47
+ }>;
48
+ }
49
+ export declare const exampleRouterUsage: {
50
+ initUpload: (req: any, res: any) => Promise<void>;
51
+ downloadFile: (req: any, res: any) => Promise<void>;
52
+ };
@@ -0,0 +1,156 @@
1
+ // Exemple d'utilisation du module EDRM Storage
2
+ // Ce fichier montre comment intégrer le module dans un autre module Endurance
3
+ import { EdrmStorageService } from '../services/edrm-storage.service.js';
4
+ import { FileProvider } from '../models/file.model.js';
5
+ export class ExampleUsage {
6
+ storageService;
7
+ constructor() {
8
+ this.storageService = new EdrmStorageService();
9
+ }
10
+ /**
11
+ * Exemple d'upload d'un CV pour une candidature
12
+ */
13
+ async uploadCVForApplication(applicationId, originalName, mimeType, size) {
14
+ try {
15
+ // 1. Initialiser l'upload
16
+ const uploadResult = await this.storageService.initUpload(originalName, mimeType, size, 'endurance', // tenantId
17
+ 'job-application', applicationId.toString(), FileProvider.S3, {
18
+ category: 'cv',
19
+ applicationId,
20
+ type: 'resume'
21
+ }, ['cv', 'resume', 'application']);
22
+ console.log('Upload initialisé:', uploadResult);
23
+ // 2. Le client utilise l'URL présignée pour uploader directement vers S3
24
+ // uploadResult.presignedUrl
25
+ // 3. Finaliser l'upload après que le client ait uploadé
26
+ const completedFile = await this.storageService.completeUpload(uploadResult.fileId.toString());
27
+ console.log('Upload finalisé:', completedFile);
28
+ return completedFile;
29
+ }
30
+ catch (error) {
31
+ console.error('Erreur lors de l\'upload:', error);
32
+ throw error;
33
+ }
34
+ }
35
+ /**
36
+ * Exemple de récupération d'une URL de téléchargement
37
+ */
38
+ async getDownloadUrl(fileId, filename) {
39
+ try {
40
+ const downloadResult = await this.storageService.getDownloadUrl(fileId, filename, 3600 // 1 heure
41
+ );
42
+ console.log('URL de téléchargement générée:', downloadResult);
43
+ return downloadResult;
44
+ }
45
+ catch (error) {
46
+ console.error('Erreur lors de la génération de l\'URL:', error);
47
+ throw error;
48
+ }
49
+ }
50
+ /**
51
+ * Exemple de listing des fichiers d'une entité
52
+ */
53
+ async listEntityFiles(entityName, entityId) {
54
+ try {
55
+ const files = await this.storageService.listFiles('endurance', entityName, entityId, undefined, // status
56
+ 1, // page
57
+ 20 // limit
58
+ );
59
+ console.log('Fichiers trouvés:', files);
60
+ return files;
61
+ }
62
+ catch (error) {
63
+ console.error('Erreur lors du listing:', error);
64
+ throw error;
65
+ }
66
+ }
67
+ /**
68
+ * Exemple d'upload de document de mission
69
+ */
70
+ async uploadMissionDocument(applicationId, originalName, mimeType, size) {
71
+ try {
72
+ const uploadResult = await this.storageService.initUpload(originalName, mimeType, size, 'endurance', 'job-application', applicationId.toString(), FileProvider.S3, {
73
+ category: 'mission-doc',
74
+ applicationId,
75
+ type: 'mission'
76
+ }, ['mission', 'document', 'application']);
77
+ console.log('Upload document mission initialisé:', uploadResult);
78
+ return uploadResult;
79
+ }
80
+ catch (error) {
81
+ console.error('Erreur lors de l\'upload du document mission:', error);
82
+ throw error;
83
+ }
84
+ }
85
+ /**
86
+ * Exemple de suppression d'un fichier
87
+ */
88
+ async deleteFile(fileId) {
89
+ try {
90
+ await this.storageService.deleteFile(fileId);
91
+ console.log('Fichier supprimé avec succès');
92
+ return true;
93
+ }
94
+ catch (error) {
95
+ console.error('Erreur lors de la suppression:', error);
96
+ throw error;
97
+ }
98
+ }
99
+ /**
100
+ * Exemple d'utilisation avec différents providers
101
+ */
102
+ async uploadWithDifferentProvider(originalName, mimeType, size, provider) {
103
+ try {
104
+ const uploadResult = await this.storageService.initUpload(originalName, mimeType, size, 'endurance', 'test-entity', 'test-id', provider, {
105
+ category: 'test',
106
+ provider
107
+ }, ['test', provider.toLowerCase()]);
108
+ console.log(`Upload avec provider ${provider}:`, uploadResult);
109
+ return uploadResult;
110
+ }
111
+ catch (error) {
112
+ console.error(`Erreur avec provider ${provider}:`, error);
113
+ throw error;
114
+ }
115
+ }
116
+ }
117
+ // Exemple d'utilisation dans un routeur Express
118
+ export const exampleRouterUsage = {
119
+ // Route pour initialiser un upload
120
+ initUpload: async (req, res) => {
121
+ const example = new ExampleUsage();
122
+ try {
123
+ const { originalName, mimeType, size, entityId } = req.body;
124
+ const result = await example.uploadCVForApplication(entityId, originalName, mimeType, size);
125
+ res.json({
126
+ success: true,
127
+ data: result
128
+ });
129
+ }
130
+ catch (error) {
131
+ res.status(500).json({
132
+ success: false,
133
+ message: 'Erreur lors de l\'initialisation de l\'upload'
134
+ });
135
+ }
136
+ },
137
+ // Route pour télécharger un fichier
138
+ downloadFile: async (req, res) => {
139
+ const example = new ExampleUsage();
140
+ try {
141
+ const { fileId } = req.params;
142
+ const { filename } = req.query;
143
+ const result = await example.getDownloadUrl(fileId, filename);
144
+ res.json({
145
+ success: true,
146
+ data: result
147
+ });
148
+ }
149
+ catch (error) {
150
+ res.status(500).json({
151
+ success: false,
152
+ message: 'Erreur lors de la génération de l\'URL de téléchargement'
153
+ });
154
+ }
155
+ }
156
+ };
@@ -0,0 +1,5 @@
1
+ export { default as FileModel, FileStatus, FileProvider, FileType } from './models/file.model.js';
2
+ export type { StorageProvider, UploadInitResponse, DownloadUrlResponse, FileMetadata } from './interfaces/storage-provider.interface.js';
3
+ export { S3StorageProvider } from './providers/s3-storage.provider.js';
4
+ export { EdrmStorageService } from './services/edrm-storage.service.js';
5
+ export { default as EdrmStorageRouter } from './routes/edrm-storage.router.js';
@@ -0,0 +1,8 @@
1
+ // Modèles
2
+ export { default as FileModel, FileStatus, FileProvider, FileType } from './models/file.model.js';
3
+ // Providers
4
+ export { S3StorageProvider } from './providers/s3-storage.provider.js';
5
+ // Services
6
+ export { EdrmStorageService } from './services/edrm-storage.service.js';
7
+ // Routes
8
+ export { default as EdrmStorageRouter } from './routes/edrm-storage.router.js';
@@ -0,0 +1,53 @@
1
+ import EdrmStorageRouter from '../routes/edrm-storage.router.js';
2
+ /**
3
+ * Classe d'intégration pour le module EDRM Storage
4
+ * Gère l'initialisation et l'intégration du module dans l'application principale
5
+ */
6
+ export declare class EdrmStorageIntegration {
7
+ private static instance;
8
+ private isInitialized;
9
+ private constructor();
10
+ static getInstance(): EdrmStorageIntegration;
11
+ /**
12
+ * Initialise le module edrm-storage
13
+ * - Exécute les migrations nécessaires
14
+ * - Configure les variables d'environnement
15
+ * - Prépare les routeurs
16
+ */
17
+ initialize(): Promise<void>;
18
+ /**
19
+ * Valide les variables d'environnement requises
20
+ */
21
+ private validateEnvironmentVariables;
22
+ /**
23
+ * Exécute les migrations nécessaires
24
+ */
25
+ private runMigrations;
26
+ /**
27
+ * Configure les événements du module
28
+ */
29
+ private setupEvents;
30
+ /**
31
+ * Retourne le routeur principal du module
32
+ */
33
+ getRouter(): EdrmStorageRouter;
34
+ /**
35
+ * Retourne les informations de statut du module
36
+ */
37
+ getStatus(): {
38
+ initialized: boolean;
39
+ config: any;
40
+ };
41
+ /**
42
+ * Nettoie les ressources du module
43
+ */
44
+ cleanup(): Promise<void>;
45
+ }
46
+ /**
47
+ * Fonction utilitaire pour initialiser le module depuis l'application principale
48
+ */
49
+ export declare function initializeEdrmStorage(): Promise<EdrmStorageIntegration>;
50
+ /**
51
+ * Fonction utilitaire pour obtenir le routeur du module
52
+ */
53
+ export declare function getEdrmStorageRouter(): EdrmStorageRouter;
@@ -0,0 +1,132 @@
1
+ import EdrmStorageRouter from '../routes/edrm-storage.router.js';
2
+ import { runEdrmStorageMigrations } from '../migrations/edrm-storage.migration.js';
3
+ /**
4
+ * Classe d'intégration pour le module EDRM Storage
5
+ * Gère l'initialisation et l'intégration du module dans l'application principale
6
+ */
7
+ export class EdrmStorageIntegration {
8
+ static instance;
9
+ isInitialized = false;
10
+ constructor() { }
11
+ static getInstance() {
12
+ if (!EdrmStorageIntegration.instance) {
13
+ EdrmStorageIntegration.instance = new EdrmStorageIntegration();
14
+ }
15
+ return EdrmStorageIntegration.instance;
16
+ }
17
+ /**
18
+ * Initialise le module edrm-storage
19
+ * - Exécute les migrations nécessaires
20
+ * - Configure les variables d'environnement
21
+ * - Prépare les routeurs
22
+ */
23
+ async initialize() {
24
+ if (this.isInitialized) {
25
+ console.log('Module EDRM Storage déjà initialisé');
26
+ return;
27
+ }
28
+ try {
29
+ console.log('Initialisation du module EDRM Storage...');
30
+ // Vérifier les variables d'environnement requises
31
+ this.validateEnvironmentVariables();
32
+ // Exécuter les migrations
33
+ await this.runMigrations();
34
+ // Configurer les événements
35
+ this.setupEvents();
36
+ this.isInitialized = true;
37
+ console.log('Module EDRM Storage initialisé avec succès');
38
+ }
39
+ catch (error) {
40
+ console.error('Erreur lors de l\'initialisation du module EDRM Storage:', error);
41
+ throw error;
42
+ }
43
+ }
44
+ /**
45
+ * Valide les variables d'environnement requises
46
+ */
47
+ validateEnvironmentVariables() {
48
+ const requiredVars = [
49
+ 'AWS_REGION',
50
+ 'AWS_ACCESS_KEY_ID',
51
+ 'AWS_SECRET_ACCESS_KEY',
52
+ 'S3_BUCKET'
53
+ ];
54
+ const missingVars = requiredVars.filter(varName => !process.env[varName]);
55
+ if (missingVars.length > 0) {
56
+ console.warn('Variables d\'environnement manquantes pour EDRM Storage:', missingVars);
57
+ console.warn('Le module peut ne pas fonctionner correctement');
58
+ }
59
+ // Définir des valeurs par défaut si nécessaire
60
+ if (!process.env.AWS_REGION) {
61
+ process.env.AWS_REGION = 'us-east-1';
62
+ }
63
+ if (!process.env.S3_BUCKET) {
64
+ process.env.S3_BUCKET = 'edrm-storage';
65
+ }
66
+ }
67
+ /**
68
+ * Exécute les migrations nécessaires
69
+ */
70
+ async runMigrations() {
71
+ try {
72
+ await runEdrmStorageMigrations();
73
+ }
74
+ catch (error) {
75
+ console.error('Erreur lors des migrations EDRM Storage:', error);
76
+ // Ne pas faire échouer l'initialisation si les migrations échouent
77
+ // Les migrations peuvent être exécutées manuellement plus tard
78
+ }
79
+ }
80
+ /**
81
+ * Configure les événements du module
82
+ */
83
+ setupEvents() {
84
+ // Ici on peut configurer des événements globaux si nécessaire
85
+ // Par exemple, des listeners pour les événements de fichiers
86
+ console.log('Événements EDRM Storage configurés');
87
+ }
88
+ /**
89
+ * Retourne le routeur principal du module
90
+ */
91
+ getRouter() {
92
+ if (!this.isInitialized) {
93
+ throw new Error('Module EDRM Storage non initialisé. Appelez initialize() d\'abord.');
94
+ }
95
+ return new EdrmStorageRouter();
96
+ }
97
+ /**
98
+ * Retourne les informations de statut du module
99
+ */
100
+ getStatus() {
101
+ return {
102
+ initialized: this.isInitialized,
103
+ config: {
104
+ awsRegion: process.env.AWS_REGION,
105
+ s3Bucket: process.env.S3_BUCKET,
106
+ hasAwsCredentials: !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY)
107
+ }
108
+ };
109
+ }
110
+ /**
111
+ * Nettoie les ressources du module
112
+ */
113
+ async cleanup() {
114
+ console.log('Nettoyage du module EDRM Storage...');
115
+ this.isInitialized = false;
116
+ }
117
+ }
118
+ /**
119
+ * Fonction utilitaire pour initialiser le module depuis l'application principale
120
+ */
121
+ export async function initializeEdrmStorage() {
122
+ const integration = EdrmStorageIntegration.getInstance();
123
+ await integration.initialize();
124
+ return integration;
125
+ }
126
+ /**
127
+ * Fonction utilitaire pour obtenir le routeur du module
128
+ */
129
+ export function getEdrmStorageRouter() {
130
+ const integration = EdrmStorageIntegration.getInstance();
131
+ return integration.getRouter();
132
+ }
@@ -0,0 +1,35 @@
1
+ import { FileProvider } from '../models/file.model.js';
2
+ export interface UploadInitResponse {
3
+ uploadId: string;
4
+ presignedUrl: string;
5
+ fields?: Record<string, string>;
6
+ expiresAt: Date;
7
+ bucket: string;
8
+ key: string;
9
+ }
10
+ export interface DownloadUrlResponse {
11
+ url: string;
12
+ expiresAt: Date;
13
+ filename: string;
14
+ contentType: string;
15
+ }
16
+ export interface FileMetadata {
17
+ size: number;
18
+ etag: string;
19
+ lastModified: Date;
20
+ contentType: string;
21
+ metadata?: Record<string, string>;
22
+ }
23
+ export interface StorageProvider {
24
+ provider: FileProvider;
25
+ initUpload(bucket: string, key: string, contentType: string, expiresIn?: number): Promise<UploadInitResponse>;
26
+ getFileMetadata(bucket: string, key: string): Promise<FileMetadata>;
27
+ getDownloadUrl(bucket: string, key: string, filename?: string, expiresIn?: number): Promise<DownloadUrlResponse>;
28
+ deleteFile(bucket: string, key: string): Promise<void>;
29
+ copyFile(sourceBucket: string, sourceKey: string, destBucket: string, destKey: string): Promise<void>;
30
+ listFiles(bucket: string, prefix?: string, maxKeys?: number): Promise<{
31
+ key: string;
32
+ size: number;
33
+ lastModified: Date;
34
+ }[]>;
35
+ }
@@ -0,0 +1,6 @@
1
+ import mongoose from 'mongoose';
2
+ export declare function createFilesCollection(): Promise<void>;
3
+ export declare function cleanupExpiredFiles(): Promise<void>;
4
+ export declare function createFileStatistics(): Promise<mongoose.mongo.BSON.Document>;
5
+ export declare function migrateExistingFiles(): Promise<void>;
6
+ export declare function runEdrmStorageMigrations(): Promise<void>;