
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@tc-libs/angular
Advanced tools
Libreria Angular condivisa per autenticazione, servizi HTTP base, storage, utilita e piccoli componenti standalone.
Libreria Angular condivisa per autenticazione, servizi HTTP base, storage, utilita e piccoli componenti standalone.
La libreria e pensata per Angular 21 e per applicazioni standalone. Tutte le API pubbliche sono esportate da @tc-libs/angular.
AuthService, guard, direttive e interceptorServiceBase, ServiceAdminBase e ServicePublicBaseIDatabaseMongoEntity, IAppResponse, II18n, ISEO, ecc.)PaginationService, SeoService, I18nService, DeviceService, ErrorService, ValidationService, ImageService)StorageService, StorageAdminService, IStorageImage, ACL)LongdashComponent^21.1.0provideHttpClient(...)@angular/router, @angular/platform-browserDeviceService: @angular/cdkAuthService: jwt-decodeNel progetto host installa la libreria e le dipendenze runtime usate dalle API pubbliche:
npm install @tc-libs/angular jwt-decode @angular/cdk
In una normale applicazione Angular, @angular/common, @angular/core, @angular/forms, @angular/router e @angular/platform-browser sono gia presenti.
Configura i token e, se vuoi usare gli interceptor DI-based, registra anche withInterceptorsFromDi():
import { ApplicationConfig } from '@angular/core';
import {
HTTP_INTERCEPTORS,
provideHttpClient,
withFetch,
withInterceptorsFromDi,
} from '@angular/common/http';
import { provideRouter } from '@angular/router';
import {
AUTH_CONFIGURATION_TOKEN,
CONFIGURATION_TOKEN,
CredentialsInterceptor,
TokenInterceptor,
TRANSLATION_CONFIGURATION_TOKEN,
} from '@tc-libs/angular';
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideHttpClient(withFetch(), withInterceptorsFromDi()),
{
provide: CONFIGURATION_TOKEN,
useValue: {
server: {
basePath: 'http://localhost:7002',
apiBase: 'http://localhost:7002/api',
},
seo: {
append: ' | Demo',
title: 'Demo',
description: 'Descrizione SEO di default',
},
},
},
{
provide: AUTH_CONFIGURATION_TOKEN,
useValue: {
disabled: false,
},
},
{
provide: TRANSLATION_CONFIGURATION_TOKEN,
useValue: {},
},
{
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptor,
multi: true,
},
{
provide: HTTP_INTERCEPTORS,
useClass: CredentialsInterceptor,
multi: true,
},
],
};
CONFIGURATION_TOKEN: configurazione server e default SEOAUTH_CONFIGURATION_TOKEN: flag disabled per bypassare i controlli di autorizzazioneTRANSLATION_CONFIGURATION_TOKEN: dizionario traduzioni usato da I18nServiceCONFIGURATION_TOKEN{
server: {
basePath: string;
apiBase: string;
};
seo: {
append: string;
title: string;
description: string;
};
}
apiBase e il campo usato dai servizi HTTP base e da AuthService.
import {
ACL,
AuthService,
CONFIGURATION_TOKEN,
CountRequest,
DeviceService,
ErrorService,
GetAllRequest,
I18n,
I18nService,
IDatabaseMongoEntity,
ISEO,
IStorageImage,
LongdashComponent,
PaginationService,
ROLE_ACCESS_FOR,
SEO,
SeoService,
ServiceAdminBase,
ServiceBase,
ServicePublicBase,
StorageAdminService,
fileExtensionValidator,
fileSizeValidator,
isGranted,
} from '@tc-libs/angular';
AuthService espone i metodi principali:
login(credentials)register(credentials)onboarding(data)resetPassword(credentials)logout()refreshToken()getProfile()isGranted(roles)isLoggedIn()Gli access token e refresh token vengono salvati in localStorage.
Esempio di routing:
import {
ROLE_ACCESS_FOR,
alreadyAuthGuard,
authGuard,
isGranted,
} from '@tc-libs/angular';
export const routes = [
{
path: 'login',
canActivate: [alreadyAuthGuard],
loadComponent: () => import('./login.component').then((m) => m.LoginComponent),
},
{
path: 'admin',
canActivate: [authGuard, isGranted([ROLE_ACCESS_FOR.ADMIN])],
loadComponent: () => import('./admin.component').then((m) => m.AdminComponent),
},
];
Esempio in template:
<button *isGranted="[ROLE_ACCESS_FOR.ADMIN]">Solo admin</button>
authGuardL'implementazione corrente di authGuard richiama redirectToSafeUrl() quando non trova un token, ma restituisce comunque true. In pratica:
Se nel tuo progetto vuoi bloccare davvero la route, crea una guard custom che usi AuthService.isLoggedIn() e ritorni false o una UrlTree.
Se stai costruendo una demo, uno styleguide o un backoffice senza login attivo, puoi disabilitare i controlli ruolo impostando:
{
provide: AUTH_CONFIGURATION_TOKEN,
useValue: { disabled: true },
}
Questo bypassa la direttiva *isGranted.
La libreria fornisce tre classi astratte:
ServiceBase<T>: endpoint standardServiceAdminBase<T>: aggiunge il prefisso admin/ServicePublicBase<T>: aggiunge il prefisso public/Per usarle basta estenderle e definire basePath ed entity.
import { Injectable } from '@angular/core';
import { ServiceAdminBase, IDatabaseMongoEntity } from '@tc-libs/angular';
export interface IProduct extends IDatabaseMongoEntity {
title: { it: string };
}
@Injectable({ providedIn: 'root' })
export class ProductAdminService extends ServiceAdminBase<IProduct> {
override basePath = 'product';
override entity = 'ProductEntity';
}
getById(id, options?)getBySlug(slug)getByCode(code)getAll(options?)count(options?)create(model, options?)updateById(id, model)patchById(id, model)deleteById(id, model?)movePos(event, elements) per entita ordinabiliOgni servizio espone anche messageBus$, utile per reagire agli eventi CRUD (onCreate, onUpdate, onDelete, onSuccess).
Per costruire richieste paginabili o filtrabili puoi usare:
GetAllRequestGetByIdRequestFilterRequestCountRequestEsempio:
const options = new GetAllRequest({
pagination: { page: 1, perPage: 20 },
order: {
orderBy: 'createdAt',
orderDirection: 'desc',
availableOrderBy: ['createdAt', 'title.it'],
},
enums: {
active: true,
},
});
this.productService.getAll(options).subscribe((response) => {
console.log(response.data);
});
API disponibili:
StorageServiceStorageAdminServiceIStorageIStorageImageStorageImageACLIMAGE_FILE_EXTENSIONSUpload admin:
this.storageAdminService
.uploadImage('ProductEntity', ACL.public_read, file)
.subscribe();
StorageAdminService.signUrl(url) permette anche di firmare un URL lato backend.
Gestisce cambio pagina e ordinamento per componenti tabellari:
this.paginationService.onPageChange(this.reload, options, event);
this.paginationService.onSortChange(this.reload, options, defaultOrder, event);
Legge le traduzioni dal token TRANSLATION_CONFIGURATION_TOKEN.
Formato atteso:
{
common: {
default: {
button: {
save: {
it: 'Salva',
},
},
},
},
}
Uso:
this.i18nService.translate('common.button.save');
La translate() attuale restituisce il valore italiano (it), quindi il dizionario va popolato almeno per quella lingua.
Aggiorna titolo e meta description a partire da un oggetto ISEO:
this.seoService.updateSeo(entity.seo);
this.seoService.noindex();
this.seoService.index();
myControl.addValidators([
fileSizeValidator(5),
fileExtensionValidator(['jpg', 'png', 'webp']),
]);
ValidationService aiuta a costruire classi CSS per stati invalidi di FormControl e FormGroup.
isMobile()isMobile$onMobile()copyFormatted(text)Utility per formattare errori backend, in particolare risposte 422.
Genera uno srcset a partire dalle resize image/thumb e image/hd.
Componente minimale esportato come LongdashComponent e usabile con:
<tc-longdash></tc-longdash>
Comandi utili dentro questo workspace:
ng build shared
ng test shared
Il progetto di esempio che usa la libreria si trova in projects/demo-bo.
FAQs
Libreria Angular condivisa per autenticazione, servizi HTTP base, storage, utilita e piccoli componenti standalone.
We found that @tc-libs/angular demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.