@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.
- package/README.md +135 -0
- package/dist/bin/www.d.ts +2 -0
- package/dist/bin/www.js +13 -0
- package/dist/modules/edrm-exams/lib/openai/correctQuestion.txt +9 -0
- package/dist/modules/edrm-exams/lib/openai/createQuestion.txt +6 -0
- package/dist/modules/edrm-exams/lib/openai.d.ts +37 -0
- package/dist/modules/edrm-exams/lib/openai.js +135 -0
- package/dist/modules/edrm-exams/listeners/correct.listener.d.ts +2 -0
- package/dist/modules/edrm-exams/listeners/correct.listener.js +167 -0
- package/dist/modules/edrm-exams/models/candidate.model.d.ts +21 -0
- package/dist/modules/edrm-exams/models/candidate.model.js +75 -0
- package/dist/modules/edrm-exams/models/candidate.models.d.ts +21 -0
- package/dist/modules/edrm-exams/models/candidate.models.js +75 -0
- package/dist/modules/edrm-exams/models/company.model.d.ts +8 -0
- package/dist/modules/edrm-exams/models/company.model.js +34 -0
- package/dist/modules/edrm-exams/models/contact.model.d.ts +14 -0
- package/dist/modules/edrm-exams/models/contact.model.js +60 -0
- package/dist/modules/edrm-exams/models/test-category.models.d.ts +7 -0
- package/dist/modules/edrm-exams/models/test-category.models.js +29 -0
- package/dist/modules/edrm-exams/models/test-job.model.d.ts +7 -0
- package/dist/modules/edrm-exams/models/test-job.model.js +29 -0
- package/dist/modules/edrm-exams/models/test-question.model.d.ts +25 -0
- package/dist/modules/edrm-exams/models/test-question.model.js +70 -0
- package/dist/modules/edrm-exams/models/test-result.model.d.ts +26 -0
- package/dist/modules/edrm-exams/models/test-result.model.js +70 -0
- package/dist/modules/edrm-exams/models/test.model.d.ts +47 -0
- package/dist/modules/edrm-exams/models/test.model.js +133 -0
- package/dist/modules/edrm-exams/models/user.model.d.ts +18 -0
- package/dist/modules/edrm-exams/models/user.model.js +73 -0
- package/dist/modules/edrm-exams/routes/company.router.d.ts +7 -0
- package/dist/modules/edrm-exams/routes/company.router.js +108 -0
- package/dist/modules/edrm-exams/routes/exams-candidate.router.d.ts +7 -0
- package/dist/modules/edrm-exams/routes/exams-candidate.router.js +448 -0
- package/dist/modules/edrm-exams/routes/exams.router.d.ts +8 -0
- package/dist/modules/edrm-exams/routes/exams.router.js +1343 -0
- package/dist/modules/edrm-exams/routes/result.router.d.ts +7 -0
- package/dist/modules/edrm-exams/routes/result.router.js +370 -0
- package/dist/modules/edrm-exams/routes/user.router.d.ts +7 -0
- package/dist/modules/edrm-exams/routes/user.router.js +96 -0
- package/dist/modules/edrm-storage/config/edrm-storage.config.d.ts +29 -0
- package/dist/modules/edrm-storage/config/edrm-storage.config.js +31 -0
- package/dist/modules/edrm-storage/config/environment.example.d.ts +54 -0
- package/dist/modules/edrm-storage/config/environment.example.js +130 -0
- package/dist/modules/edrm-storage/examples/usage.example.d.ts +52 -0
- package/dist/modules/edrm-storage/examples/usage.example.js +156 -0
- package/dist/modules/edrm-storage/index.d.ts +5 -0
- package/dist/modules/edrm-storage/index.js +8 -0
- package/dist/modules/edrm-storage/integration/edrm-storage-integration.d.ts +53 -0
- package/dist/modules/edrm-storage/integration/edrm-storage-integration.js +132 -0
- package/dist/modules/edrm-storage/interfaces/storage-provider.interface.d.ts +35 -0
- package/dist/modules/edrm-storage/interfaces/storage-provider.interface.js +1 -0
- package/dist/modules/edrm-storage/migrations/edrm-storage.migration.d.ts +6 -0
- package/dist/modules/edrm-storage/migrations/edrm-storage.migration.js +151 -0
- package/dist/modules/edrm-storage/models/file.model.d.ts +78 -0
- package/dist/modules/edrm-storage/models/file.model.js +190 -0
- package/dist/modules/edrm-storage/providers/s3-storage.provider.d.ts +18 -0
- package/dist/modules/edrm-storage/providers/s3-storage.provider.js +95 -0
- package/dist/modules/edrm-storage/routes/edrm-storage.router.d.ts +8 -0
- package/dist/modules/edrm-storage/routes/edrm-storage.router.js +155 -0
- package/dist/modules/edrm-storage/scripts/quick-start.d.ts +7 -0
- package/dist/modules/edrm-storage/scripts/quick-start.js +114 -0
- package/dist/modules/edrm-storage/services/edrm-storage.service.d.ts +29 -0
- package/dist/modules/edrm-storage/services/edrm-storage.service.js +188 -0
- package/dist/modules/edrm-storage/tests/edrm-storage.service.test.d.ts +1 -0
- package/dist/modules/edrm-storage/tests/edrm-storage.service.test.js +143 -0
- package/dist/modules/edrm-storage/tests/integration.test.d.ts +1 -0
- package/dist/modules/edrm-storage/tests/integration.test.js +141 -0
- package/package.json +81 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { EdrmStorageService } from '../services/edrm-storage.service.js';
|
|
2
|
+
import { FileProvider } from '../models/file.model.js';
|
|
3
|
+
import { validateEdrmStorageConfig } from '../config/environment.example.js';
|
|
4
|
+
describe('EDRM Storage Integration Tests', () => {
|
|
5
|
+
let storageService;
|
|
6
|
+
beforeAll(async () => {
|
|
7
|
+
// Vérifier la configuration
|
|
8
|
+
const configValidation = validateEdrmStorageConfig();
|
|
9
|
+
if (!configValidation.valid) {
|
|
10
|
+
console.warn('Configuration invalide:', configValidation.errors);
|
|
11
|
+
}
|
|
12
|
+
storageService = new EdrmStorageService();
|
|
13
|
+
});
|
|
14
|
+
describe('Configuration', () => {
|
|
15
|
+
it('devrait valider la configuration d\'environnement', () => {
|
|
16
|
+
const validation = validateEdrmStorageConfig();
|
|
17
|
+
expect(validation.valid).toBeDefined();
|
|
18
|
+
expect(Array.isArray(validation.errors)).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe('Service Initialization', () => {
|
|
22
|
+
it('devrait initialiser le service sans erreur', () => {
|
|
23
|
+
expect(storageService).toBeDefined();
|
|
24
|
+
expect(storageService).toBeInstanceOf(EdrmStorageService);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('Upload Flow', () => {
|
|
28
|
+
it('devrait initialiser un upload avec succès', async () => {
|
|
29
|
+
const testData = {
|
|
30
|
+
originalName: 'test-integration.pdf',
|
|
31
|
+
mimeType: 'application/pdf',
|
|
32
|
+
size: 1024,
|
|
33
|
+
tenantId: 'test-tenant',
|
|
34
|
+
entityName: 'test-entity',
|
|
35
|
+
entityId: 'test-id-123'
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
const result = await storageService.initUpload(testData.originalName, testData.mimeType, testData.size, testData.tenantId, testData.entityName, testData.entityId, FileProvider.S3);
|
|
39
|
+
expect(result).toBeDefined();
|
|
40
|
+
expect(result.fileId).toBeDefined();
|
|
41
|
+
expect(result.presignedUrl).toBeDefined();
|
|
42
|
+
expect(result.bucket).toBeDefined();
|
|
43
|
+
expect(result.key).toBeDefined();
|
|
44
|
+
console.log('Upload initialisé avec succès:', {
|
|
45
|
+
fileId: result.fileId,
|
|
46
|
+
bucket: result.bucket,
|
|
47
|
+
key: result.key
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// Si les credentials AWS ne sont pas configurés, c'est normal
|
|
52
|
+
console.log('Test d\'upload ignoré - credentials AWS non configurés');
|
|
53
|
+
}
|
|
54
|
+
}, 10000);
|
|
55
|
+
it('devrait gérer les erreurs de paramètres invalides', async () => {
|
|
56
|
+
await expect(storageService.initUpload('', // nom vide
|
|
57
|
+
'application/pdf', 1024, 'tenant', 'entity', 'id')).rejects.toThrow();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('File Management', () => {
|
|
61
|
+
it('devrait lister les fichiers', async () => {
|
|
62
|
+
try {
|
|
63
|
+
const result = await storageService.listFiles('test-tenant', 'test-entity', 'test-id', undefined, 1, 10);
|
|
64
|
+
expect(result).toBeDefined();
|
|
65
|
+
expect(result.files).toBeDefined();
|
|
66
|
+
expect(Array.isArray(result.files)).toBe(true);
|
|
67
|
+
expect(result.total).toBeDefined();
|
|
68
|
+
expect(result.page).toBe(1);
|
|
69
|
+
expect(result.totalPages).toBeDefined();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.log('Test de listing ignoré - base de données non connectée');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
it('devrait gérer les erreurs de fichier inexistant', async () => {
|
|
76
|
+
await expect(storageService.getFileById('non-existent-id')).rejects.toThrow('Fichier non trouvé');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('Provider Management', () => {
|
|
80
|
+
it('devrait supporter le provider S3', () => {
|
|
81
|
+
// Le provider S3 devrait être disponible par défaut
|
|
82
|
+
expect(FileProvider.S3).toBe('S3');
|
|
83
|
+
});
|
|
84
|
+
it('devrait gérer les providers non supportés', async () => {
|
|
85
|
+
// Test avec un provider inexistant
|
|
86
|
+
await expect(storageService.initUpload('test.pdf', 'application/pdf', 1024, 'tenant', 'entity', 'id', 'INVALID_PROVIDER')).rejects.toThrow('Provider INVALID_PROVIDER non supporté');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe('Error Handling', () => {
|
|
90
|
+
it('devrait gérer les erreurs de connexion S3', async () => {
|
|
91
|
+
// Test avec des credentials invalides
|
|
92
|
+
const originalAccessKey = process.env.AWS_ACCESS_KEY_ID;
|
|
93
|
+
const originalSecretKey = process.env.AWS_SECRET_ACCESS_KEY;
|
|
94
|
+
// Simuler des credentials invalides
|
|
95
|
+
process.env.AWS_ACCESS_KEY_ID = 'invalid';
|
|
96
|
+
process.env.AWS_SECRET_ACCESS_KEY = 'invalid';
|
|
97
|
+
try {
|
|
98
|
+
await storageService.initUpload('test.pdf', 'application/pdf', 1024, 'tenant', 'entity', 'id');
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
expect(error).toBeDefined();
|
|
102
|
+
console.log('Erreur S3 attendue avec credentials invalides');
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
// Restaurer les credentials originaux
|
|
106
|
+
if (originalAccessKey)
|
|
107
|
+
process.env.AWS_ACCESS_KEY_ID = originalAccessKey;
|
|
108
|
+
if (originalSecretKey)
|
|
109
|
+
process.env.AWS_SECRET_ACCESS_KEY = originalSecretKey;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('Performance', () => {
|
|
114
|
+
it('devrait gérer les uploads multiples', async () => {
|
|
115
|
+
const uploads = [];
|
|
116
|
+
const testData = {
|
|
117
|
+
originalName: 'test-multiple.pdf',
|
|
118
|
+
mimeType: 'application/pdf',
|
|
119
|
+
size: 1024,
|
|
120
|
+
tenantId: 'test-tenant',
|
|
121
|
+
entityName: 'test-entity',
|
|
122
|
+
entityId: 'test-id'
|
|
123
|
+
};
|
|
124
|
+
try {
|
|
125
|
+
// Créer plusieurs uploads simultanés
|
|
126
|
+
for (let i = 0; i < 3; i++) {
|
|
127
|
+
uploads.push(storageService.initUpload(`${testData.originalName}-${i}`, testData.mimeType, testData.size, testData.tenantId, testData.entityName, `${testData.entityId}-${i}`));
|
|
128
|
+
}
|
|
129
|
+
const results = await Promise.all(uploads);
|
|
130
|
+
expect(results).toHaveLength(3);
|
|
131
|
+
results.forEach((result, index) => {
|
|
132
|
+
expect(result.fileId).toBeDefined();
|
|
133
|
+
expect(result.presignedUrl).toBeDefined();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.log('Test de performance ignoré - credentials AWS non configurés');
|
|
138
|
+
}
|
|
139
|
+
}, 15000);
|
|
140
|
+
});
|
|
141
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@programisto/edrm-storage",
|
|
4
|
+
"version": "0.3.1",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"description": "an api for online storage with providers like S3",
|
|
9
|
+
"main": "app.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node ./dist/bin/www",
|
|
12
|
+
"dev": "tsc-watch --onSuccess \"node ./dist/bin/www\"",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"build": "tsc && npm run copy-files",
|
|
15
|
+
"copy-files": "copyfiles -u 1 'src/**/*.txt' dist",
|
|
16
|
+
"lint": "eslint \"**/*.{ts,tsx}\"",
|
|
17
|
+
"prepare": "husky install"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@programisto/endurance-core": "^1.1.6",
|
|
21
|
+
"aws-sdk": "^2.1692.0",
|
|
22
|
+
"debug": "^4.3.7",
|
|
23
|
+
"fs": "^0.0.1-security",
|
|
24
|
+
"http": "^0.0.1-security",
|
|
25
|
+
"jsonwebtoken": "^9.0.2",
|
|
26
|
+
"mongoose": "^8.8.3",
|
|
27
|
+
"multer": "^1.4.5-lts.2",
|
|
28
|
+
"multer-s3": "^3.0.1",
|
|
29
|
+
"mustache": "^4.2.0",
|
|
30
|
+
"nodemailer": "^6.10.1",
|
|
31
|
+
"openai": "^4.100.0",
|
|
32
|
+
"path": "^0.12.7",
|
|
33
|
+
"to-regex-range": "^5.0.1",
|
|
34
|
+
"tsc-watch": "^6.2.1",
|
|
35
|
+
"url": "^0.11.4",
|
|
36
|
+
"uuid": "^11.0.3"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
40
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
41
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
42
|
+
"@semantic-release/git": "^10.0.1",
|
|
43
|
+
"@semantic-release/github": "^11.0.3",
|
|
44
|
+
"@semantic-release/npm": "^12.0.1",
|
|
45
|
+
"@semantic-release/release-notes-generator": "^14.0.3",
|
|
46
|
+
"@types/jest": "^30.0.0",
|
|
47
|
+
"@types/node": "^22.16.5",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^8.26.0",
|
|
49
|
+
"@typescript-eslint/parser": "^8.26.0",
|
|
50
|
+
"commitlint": "^19.8.1",
|
|
51
|
+
"copyfiles": "^2.4.1",
|
|
52
|
+
"eslint": "^8.57.1",
|
|
53
|
+
"eslint-config-standard": "^17.1.0",
|
|
54
|
+
"eslint-plugin-import": "^2.31.0",
|
|
55
|
+
"eslint-plugin-n": "^16.6.2",
|
|
56
|
+
"eslint-plugin-promise": "^6.6.0",
|
|
57
|
+
"husky": "^9.1.7",
|
|
58
|
+
"jest": "^30.1.2",
|
|
59
|
+
"mocha": "^11.0.1",
|
|
60
|
+
"nodemon": "^3.1.4",
|
|
61
|
+
"semantic-release": "^24.2.5",
|
|
62
|
+
"supertest": "^3.0.0",
|
|
63
|
+
"ts-jest": "^29.4.1",
|
|
64
|
+
"ts-node": "^10.9.2",
|
|
65
|
+
"typescript": "^5.8.3"
|
|
66
|
+
},
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "git+https://github.com/programisto-labs/edrm-storage.git"
|
|
70
|
+
},
|
|
71
|
+
"author": "",
|
|
72
|
+
"license": "ISC",
|
|
73
|
+
"bugs": {
|
|
74
|
+
"url": "https://github.com/programisto-labs/edrm-storage/issues"
|
|
75
|
+
},
|
|
76
|
+
"homepage": "https://github.com/programisto-labs/edrm-storage#readme",
|
|
77
|
+
"files": [
|
|
78
|
+
"dist",
|
|
79
|
+
"README.md"
|
|
80
|
+
]
|
|
81
|
+
}
|