¡Esta es una revisión vieja del documento!
Esta librería funciona como un repositorio centralizado de componentes, permitiendo compartir y reutilizar elementos visuales de manera consistente en todas las aplicaciones. Al mantener un sistema de diseño unificado, garantiza la coherencia visual y mejora la eficiencia del desarrollo, reduciendo la duplicación de código y simplificando el mantenimiento de la interfaz de usuario.
Para comenzar, sigue estos pasos:
npm i crypto-js
"crypto-util-library": "http://10.1.40.130:8081/repository/npm-hosted/crypto-util-library/-/crypto-util-library-1.0.0.tgz"
import { CryptoUtil } from 'crypto-util-library';
decryptResponse(data: any) { return this.cryptoUtil.decryptObject(data); }
encryptData(data: any) { return this.cryptoUtil.encryptObject(data); }
import { CryptoConfig } from './crypto.config'; import { CryptoUtilLibraryService } from '../services/crypto-util-library.service';
export const cryptoInterceptorInterceptor = (config: CryptoConfig): HttpInterceptorFn => (request, next) => { const cryptoService = inject(CryptoUtilLibraryService); const shouldSkip = config.excludedUrls.some(url => request.url.includes(url) ); if (shouldSkip) { return next(request); } if (request.body) { return from(cryptoService.encryptData(request.body)).pipe( switchMap(encryptedBody => { const clonedRequest = request.clone({ body: encryptedBody }); return next(clonedRequest).pipe( switchMap(event => { if (event instanceof HttpResponse && event.body) { const decryptedBodyPromise = cryptoService.decryptResponse(event.body); return from(decryptedBodyPromise).pipe( map(decryptedBody => event.clone({ body: decryptedBody })) ); } return [event]; }), catchError(error => { if (error instanceof HttpErrorResponse && error.error) { const decryptedErrorPromise = cryptoService.decryptResponse(error.error); return from(decryptedErrorPromise).pipe( switchMap(decryptedError => { const clonedError = new HttpErrorResponse({ ...error, error: decryptedError, url: error.url ?? undefined }); return throwError(() => clonedError); }) ); } return throwError(() => error); })
); }) ); } return next(request).pipe( switchMap(event => { if (event instanceof HttpResponse && event.body) { const decryptedBodyPromise = cryptoService.decryptResponse(event.body); return from(decryptedBodyPromise).pipe( map(decryptedBody => event.clone({ body: decryptedBody })) ); } return [event]; }), catchError(error => { if (error instanceof HttpErrorResponse && error.error) { const decryptedErrorPromise = cryptoService.decryptResponse(error.error); return from(decryptedErrorPromise).pipe( switchMap(decryptedError => { const clonedError = new HttpErrorResponse({ ...error, error: decryptedError, url: error.url ?? undefined }); return throwError(() => clonedError); }) ); } return throwError(() => error); }) ); };