Some checks are pending
CI / Lint bridge (Biome) (push) Waiting to run
CI / Type-check bridge (push) Blocked by required conditions
CI / Tests unit bridge (push) Blocked by required conditions
CI / Tests integration bridge (push) Blocked by required conditions
CI / Security scan (push) Waiting to run
CI / Docker build + healthcheck (push) Blocked by required conditions
Pivot strategique : DocAdenice = produit Notion-like generique. Le bridge
est livre vide a un user qui cree ses tables Baserow comme il veut. Code
sans aucune ontologie metier.
Suppressions :
- 9 entites domain metier (Personne, Formation, Bloc, Module, Attribution,
Client, Projet, Tache, Intervention) + types.ts (Role, statuts)
- baserow-repo.ts (mega-fichier 554 LOC avec 9 repos heritant BaseRepo)
- 6 routes metier (personnes, formations, projets, modules, interventions,
attributions) + tests associes
- Lookup PersonneRepo.findByEmail dans middleware auth
- Mapping DEFAULT_ROLE_SCOPES dans middleware/scopes.ts
- Cascade rollup metier dans webhooks/baserow-handler.ts
Ajouts :
- Domain generique : Table, Row, Field, View + schemas zod refondus
- 4 repos generiques : tables / rows / fields / views
- Route unique routes/tables.ts avec 9 endpoints REST CRUD generiques
- Claim JWT acadenice_permissions[] lu directement dans le middleware auth
(alimente par RBAC dynamique cote DocAdenice en R2)
- examples/acadenice-formation-hub/ : README + seed-baserow.md schema
9 tables + example-roles.md (Formateur, Developpeur, Direction, Support,
Admin avec permissions generiques)
Refactors :
- BaserowClient etendu : listTables, getTable, listFields, listViews,
getGridViewRows
- middleware/auth.ts : extractPermissions(payload), AuthenticatedUser
remplace roles[] par permissions[]
- middleware/scopes.ts : computeOidcScopes(groups, permissions, map)
- webhooks/baserow-handler.ts : invalidation generique
bridge:tables:<tableId>:* sans cascade cross-table
- lib/cache.ts : invalidateEntity -> invalidateTable(redis, tableId, rowId?)
- container.ts : drop tableIds, RepoSet={tables, rows, fields, views}
- 501 NOT_IMPLEMENTED si DB token sur endpoints /tables qui exigent JWT
Tests : 250/250 verts (depuis 319). Coverage : domain 98.9%, adapters 89%,
auth 97.08%, rate-limit 100%, cache 100%, webhooks 100%.
Quality gates verts : typecheck, lint biome, vitest, coverage thresholds.
Refs: R1 dans le pivot strategique DocAdenice Notion-like generique.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
70 lines
2 KiB
TypeScript
70 lines
2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { BridgeError, errors } from '../../src/lib/errors.js';
|
|
|
|
describe('BridgeError', () => {
|
|
it('toJSON serialise code + message + details', () => {
|
|
const err = new BridgeError('VALIDATION_ERROR', 400, 'invalid', { field: 'x' });
|
|
expect(err.toJSON()).toEqual({
|
|
error: { code: 'VALIDATION_ERROR', message: 'invalid', details: { field: 'x' } },
|
|
});
|
|
});
|
|
|
|
it('toJSON sans details : pas de cle details', () => {
|
|
const err = new BridgeError('NOT_FOUND', 404, 'gone');
|
|
expect(err.toJSON()).toEqual({ error: { code: 'NOT_FOUND', message: 'gone' } });
|
|
});
|
|
|
|
it('preserve name = BridgeError', () => {
|
|
const err = new BridgeError('INTERNAL', 500, 'x');
|
|
expect(err.name).toBe('BridgeError');
|
|
});
|
|
});
|
|
|
|
describe('errors helpers', () => {
|
|
it('authRequired', () => {
|
|
const e = errors.authRequired();
|
|
expect(e.code).toBe('AUTH_REQUIRED');
|
|
expect(e.status).toBe(401);
|
|
});
|
|
|
|
it('authInvalid', () => {
|
|
expect(errors.authInvalid().status).toBe(401);
|
|
});
|
|
|
|
it('forbidden inclut le scope dans details', () => {
|
|
const e = errors.forbidden('admin:write');
|
|
expect(e.code).toBe('FORBIDDEN_SCOPE');
|
|
expect(e.status).toBe(403);
|
|
expect(e.details).toEqual({ scope: 'admin:write' });
|
|
});
|
|
|
|
it('notFound', () => {
|
|
const e = errors.notFound('Row', 99);
|
|
expect(e.status).toBe(404);
|
|
expect(e.details).toEqual({ entity: 'Row', id: 99 });
|
|
});
|
|
|
|
it('validation', () => {
|
|
const e = errors.validation([{ message: 'bad' }]);
|
|
expect(e.status).toBe(400);
|
|
expect(e.code).toBe('VALIDATION_ERROR');
|
|
});
|
|
|
|
it('rateLimited', () => {
|
|
const e = errors.rateLimited(60);
|
|
expect(e.status).toBe(429);
|
|
expect(e.details).toEqual({ retry_after: 60 });
|
|
});
|
|
|
|
it('baserowDown', () => {
|
|
expect(errors.baserowDown().status).toBe(502);
|
|
});
|
|
|
|
it('docmostDown', () => {
|
|
expect(errors.docmostDown().status).toBe(502);
|
|
});
|
|
|
|
it('internal', () => {
|
|
expect(errors.internal('boom').status).toBe(500);
|
|
});
|
|
});
|