@albi_scando/as-backbone-lib 1.0.4 → 1.1.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"albi_scando-as-backbone-lib.mjs","sources":["../../../projects/as-backbone-lib/src/lib/constants/application.constant.ts","../../../projects/as-backbone-lib/src/albi_scando-as-backbone-lib.ts"],"sourcesContent":["/**\n * The name of the application.\n */\nexport const APPLICATION_NAME = 'as-backbone-lib';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;AAEG;AACI,MAAM,gBAAgB,GAAG;;ACHhC;;AAEG;;;;"}
1
+ {"version":3,"file":"albi_scando-as-backbone-lib.mjs","sources":["../../../projects/as-backbone-lib/src/lib/modules/http/services/http/http.service.ts","../../../projects/as-backbone-lib/src/lib/modules/http/interceptors/authorization/authorization.interceptor.ts","../../../projects/as-backbone-lib/src/lib/modules/http/interceptors/log-request/log-request.interceptor.ts","../../../projects/as-backbone-lib/src/lib/modules/http/interceptors/request-timestamp/request-timestamp.interceptor.ts","../../../projects/as-backbone-lib/src/lib/modules/http/interceptors/unauthorized/unauthorized.interceptor.ts","../../../projects/as-backbone-lib/src/lib/modules/language/services/translations/translations.service.ts","../../../projects/as-backbone-lib/src/lib/modules/language/pipes/translate/translate.pipe.ts","../../../projects/as-backbone-lib/src/lib/modules/language/constants/constants.ts","../../../projects/as-backbone-lib/src/lib/modules/language/services/language/language.service.ts","../../../projects/as-backbone-lib/src/lib/modules/user/constants/user-levels.constant.ts","../../../projects/as-backbone-lib/src/lib/modules/user/constants/default.ts","../../../projects/as-backbone-lib/src/lib/modules/user/services/user/user.service.ts","../../../projects/as-backbone-lib/src/albi_scando-as-backbone-lib.ts"],"sourcesContent":["import type { HttpHeaders } from '@albi_scando/as-const-http-lib';\nimport { HttpClient } from '@angular/common/http';\nimport { Injectable, inject } from '@angular/core';\nimport type { Observable } from 'rxjs';\n\nimport type { IHttpService } from './http.service.interface';\nimport type { Delete } from '../../interfaces/delete';\nimport type { Get } from '../../interfaces/get';\nimport type { Patch } from '../../interfaces/patch';\nimport type { Post } from '../../interfaces/post';\nimport type { Put } from '../../interfaces/put';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class HttpService implements IHttpService {\n\n /**\n * {@link HttpClient}\n */\n private httpClient: HttpClient = inject(HttpClient);\n\n /**\n * {@link IHttpService.expiredPasswordFn}\n */\n public expiredPasswordFn = (): void => undefined;\n\n /**\n * {@link IHttpService.unauthorizedFn}\n */\n public unauthorizedFn = (): void => undefined;\n\n /**\n * Perform http delete request\n *\n * @param {Delete} httpRequest http request\n * @returns {Observable<unknown>} response observable\n */\n public delete(httpRequest: Delete): Observable<unknown> {\n const options: { headers: Partial<Record<HttpHeaders, string>> } = this.typeSafeHeaderOptions(httpRequest.headerParams);\n\n return this.httpClient.delete(httpRequest.url, options);\n }\n\n /**\n * Perform http get request\n *\n * @param {Get} httpRequest http request\n * @returns {Observable<unknown>} response observable\n */\n public get(httpRequest: Get): Observable<unknown> {\n httpRequest.url = this._setQueryParams(httpRequest.queryParams, httpRequest.url);\n\n const options: { headers: Partial<Record<HttpHeaders, string>> } = this.typeSafeHeaderOptions(httpRequest.headerParams);\n\n return this.httpClient.get(httpRequest.url, options);\n }\n\n /**\n * Perform http patch request\n *\n * @param {Patch} httpRequest http request\n * @returns {Observable<unknown>} response observable\n */\n public patch(httpRequest: Patch): Observable<unknown> {\n const options: { headers: Partial<Record<HttpHeaders, string>> } = this.typeSafeHeaderOptions(httpRequest.headerParams);\n\n return this.httpClient.patch(httpRequest.url, httpRequest.body, options);\n }\n\n /**\n * Perform http post request\n *\n * @param {Post} httpRequest http request\n * @returns {Observable<unknown>} response observable\n */\n public post(httpRequest: Post): Observable<unknown> {\n const options: { headers: Partial<Record<HttpHeaders, string>> } = this.typeSafeHeaderOptions(httpRequest.headerParams);\n\n return this.httpClient.post(httpRequest.url, httpRequest.body, options);\n }\n\n /**\n * Perform http put request\n *\n * @param {Put} httpRequest http request\n * @returns {Observable<unknown>} response observable\n */\n public put(httpRequest: Put): Observable<unknown> {\n const options: { headers: Partial<Record<HttpHeaders, string>> } = this.typeSafeHeaderOptions(httpRequest.headerParams);\n\n return this.httpClient.put(httpRequest.url, httpRequest.body, options);\n }\n\n /**\n * Set url query parameters\n *\n * @param {Map<string, string>} queryParams query parameters key-value pairs\n * @param {string} url original httpRequest url\n * @returns {string} new url with aquery parameters\n */\n private _setQueryParams(queryParams = new Map<string, string>(), url: string): string {\n if (queryParams.size === 0) {\n return url;\n }\n\n url += `?${Array.from(queryParams.entries()).map(([key, value]) => `${key}=${value}`).join('&')}`;\n return url;\n }\n\n /**\n * Type safe header options for HttpClient methods\n * @param httpRequestHeaders header parameters key-value pairs\n * @returns header options for HttpClient methods\n */\n private typeSafeHeaderOptions(\n httpRequestHeaders: Map<HttpHeaders, string | boolean> | undefined\n ): {\n headers: Partial<Record<HttpHeaders, string>>;\n } {\n return { headers: Object.fromEntries(this._setHeaderParams(httpRequestHeaders)) };\n }\n \n /**\n * Set http request header parameters\n *\n * @param {Map<HttpHeaders, string | boolean>} headerParams header parameters key-value pairs\n * @returns {Map<HttpHeaders, string>} header parameters key-value pairs. All values must be strings.\n */\n private _setHeaderParams(headerParams: Map<HttpHeaders, string | boolean> | undefined): Map<HttpHeaders, string> {\n if (headerParams === undefined || headerParams.size === 0) {\n return new Map();\n }\n\n const headerParameters: Map<HttpHeaders, string> = new Map<HttpHeaders, string>();\n Array.from(headerParams.entries()).forEach(([key, value]: [key: HttpHeaders, value: string | boolean]) => {\n headerParameters.set(key, `${value}`);\n });\n\n return headerParameters;\n }\n}\n","import { HTTP_HEADERS } from '@albi_scando/as-const-http-lib';\nimport type {\n HttpEvent,\n HttpHandlerFn,\n HttpInterceptorFn,\n HttpRequest,\n} from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { UserService } from '@user/services/user/user.service';\nimport type { Observable } from 'rxjs';\n\n/**\n * This interceptor is responsible for adding Authorization header parameter to every outgoing HttpRequest\n *\n * @param {HttpRequest<unknown>} httpRequest @see {@link HttpRequest}\n * @param {HttpHandlerFn} next @see {@link HttpHandlerFn}\n * @returns {Observable<HttpEvent<unknown>>} @see {@link Observable<HttpEvent>}\n */\nexport const authorizationInterceptor: HttpInterceptorFn = (\n httpRequest: HttpRequest<unknown>,\n next: HttpHandlerFn\n): Observable<HttpEvent<unknown>> => {\n /**\n * {@link UserService}\n */\n const userService: UserService = inject(UserService);\n const token: string | undefined = userService.token();\n\n if (token === undefined) {\n return next(httpRequest);\n }\n\n const clonedRequest: HttpRequest<unknown> = httpRequest.clone({\n headers: httpRequest.headers.set(\n HTTP_HEADERS.AUTHORIZATION,\n token\n ),\n });\n return next(clonedRequest);\n};\n","import { LoggerService } from '@albi_scando/as-log-lib';\nimport type {\n HttpEvent,\n HttpHandlerFn,\n HttpInterceptorFn,\n HttpRequest,\n} from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport type { Observable} from 'rxjs';\nimport { tap } from 'rxjs';\n\n/**\n * This interceptor logs every outgoing HttpRequest.\n * It fulfills the same task as the developer tools Network inspector.\n *\n * @param {HttpRequest<unknown>} httpRequest @see {@link HttpRequest}\n * @param {HttpHandlerFn} next @see {@link HttpHandlerFn}\n * @returns {Observable<HttpEvent<unknown>>} @see {@link Observable<HttpEvent>}\n */\nexport const logRequestInterceptor: HttpInterceptorFn = (\n httpRequest: HttpRequest<unknown>,\n next: HttpHandlerFn\n): Observable<HttpEvent<unknown>> => {\n /**\n * {@link LoggerService}\n */\n const loggerService: LoggerService = inject(LoggerService);\n\n return next(httpRequest).pipe(\n tap(() => {\n loggerService.debug(\n `${logRequestInterceptor.name}: - ${httpRequest.url} http request`,\n httpRequest\n );\n })\n );\n};\n","import { LoggerService } from '@albi_scando/as-log-lib';\nimport type {\n HttpEvent,\n HttpHandlerFn,\n HttpInterceptorFn,\n HttpRequest,\n} from '@angular/common/http';\nimport { HttpEventType } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport type { Observable } from 'rxjs';\nimport { tap } from 'rxjs';\n\n/**\n * This interceptor logs the time interval (in milliseconds) between the request submission and the incoming response.\n * It fulfills the same task as 'Waterfall' graph in the developer tools Network inspector.\n *\n * @param {HttpRequest<unknown>} httpRequest @see {@link HttpRequest}\n * @param {HttpHandlerFn} next @see {@link HttpHandlerFn}\n * @returns {Observable<HttpEvent<unknown>>} @see {@link Observable<HttpEvent>}\n */\nexport const requestTimestampInterceptor: HttpInterceptorFn = (\n httpRequest: HttpRequest<unknown>,\n next: HttpHandlerFn\n): Observable<HttpEvent<unknown>> => {\n /**\n * {@link LoggerService}\n */\n const loggerService: LoggerService = inject(LoggerService);\n\n const startTime: number = Date.now();\n const formatLog = (message: string, isError = false): void => {\n const diff: number = Date.now() - startTime;\n const logMessage = `${requestTimestampInterceptor.name}: - ${httpRequest.url} ${message} in ${diff} ms`;\n if (isError) {\n loggerService.error(logMessage);\n } else {\n loggerService.debug(logMessage);\n }\n };\n\n return next(httpRequest).pipe(\n tap({\n next: (event) => {\n if (event.type === HttpEventType.Response) {\n formatLog('succeeded');\n }\n },\n error: () => {\n formatLog('failed', true);\n },\n })\n );\n};\n","import { HTTP_RESPONSE_STATUS_CODES } from '@albi_scando/as-const-http-lib';\nimport type {\n HttpRequest,\n HttpErrorResponse,\n HttpHandlerFn,\n HttpInterceptorFn,\n HttpEvent,\n} from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport type { Observable } from 'rxjs';\nimport { catchError, of, throwError } from 'rxjs';\n\n// Services\nimport { HttpService } from '../../services/http/http.service';\n\nconst EXPIRED_PASSWORD_MESSAGE = 'Expired password';\n\n/**\n * Http request interceptor to handle 401 unauthorized responses.\n * 401 error is special, because it needs more than just a feedback.\n * In most situations, it could be provoked by an expired token that requires a redirect to a 'Login' page.\n * When validating credentials, it could be provoked by an expired password that requires a redirect to 'Change password' page.\n *\n * @param {HttpRequest<unknown>} httpRequest @see {@link HttpRequest}\n * @param {HttpHandlerFn} next @see {@link HttpHandlerFn}\n * @returns {Observable<HttpEvent<unknown>>} @see {@link : Observable<HttpEvent>}\n */\nexport const unauthorizedInterceptor: HttpInterceptorFn = (\n httpRequest: HttpRequest<unknown>,\n next: HttpHandlerFn\n): Observable<HttpEvent<unknown>> => {\n const httpService: HttpService = inject(HttpService);\n\n return next(httpRequest).pipe(\n catchError((httpResponse: HttpErrorResponse) => {\n if (httpResponse.status !== HTTP_RESPONSE_STATUS_CODES.UNAUTHORIZED) {\n return throwError(() => httpResponse);\n }\n\n const errorMessage: string | undefined = httpResponse.error?.ErrMsg;\n if (errorMessage === EXPIRED_PASSWORD_MESSAGE) {\n httpService.expiredPasswordFn();\n } else {\n httpService.unauthorizedFn();\n }\n\n return of();\n })\n );\n};\n","\nimport { LOCALE_ISO_CODES, type Locales } from '@albi_scando/as-const-languages-lib';\nimport { TRANSLATION_DELIBERATELY_UNSET } from '@albi_scando/as-const-lib/dist/types/constants/constants';\nimport { LoggerService } from '@albi_scando/as-log-lib';\nimport type { Signal, WritableSignal } from '@angular/core';\nimport { Injectable, computed, inject, signal } from '@angular/core';\nimport type { Get } from '@http/interfaces/get';\nimport { HttpService } from '@http/services/http/http.service';\nimport type { Observable } from 'rxjs';\nimport { defaultIfEmpty, forkJoin, map } from 'rxjs';\n\n// Interfaces\nimport type { Translations } from '../../interfaces/translations.interface';\n\n/**\n * A service that manages translations based on the current language.\n *\n * The `TranslationsService` handles fetching, storing, and updating translations\n * for different languages. It interacts with various translation sources and\n * provides methods to retrieve translations based on a given key.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class TranslationsService {\n /**\n * List of translations sources (apis/files)\n */\n private _sources = new Set<string>();\n\n /**\n * Current translations dictionary, mapping translation keys to their values.\n */\n public translations: WritableSignal<Map<string, string>> = signal(new Map());\n\n /**\n * Derived signal that indicates whether translations are currently loaded.\n * Returns true if the translations map contains any entries.\n */\n public hasTranslations: Signal<boolean> = computed(\n () => this.translations().size > 0\n );\n\n /**\n * Derived signal for the count of currently loaded translations.\n * Useful for debugging or monitoring translation load status.\n */\n public translationsCount: Signal<number> = computed(\n () => this.translations().size\n );\n\n /**\n * {@link HttpService}\n */\n private readonly httpService = inject(HttpService);\n\n /**\n * {@link LoggerService}\n */\n private readonly loggerService = inject(LoggerService);\n\n /**\n * Adds new translation sources and optionally updates translations for a given language code.\n *\n * If no language code is provided, the translations will not be updated immediately.\n * The translations will be updated as soon as the current language is set.\n *\n * @param {Set<TranslationsSource>} sources New sources to add.\n * @param {Locales} [language=stringEmpty] Optional language code to trigger translations update.\n * @returns {Observable<void>} An observable that completes when the translations are updated.\n */\n public addTranslationsSources$(\n sources: Set<string>,\n language: Locales\n ): Observable<void> {\n this._sources = new Set([...this._sources, ...sources]);\n this.loggerService.debug(`Translations sources added`, this._sources);\n\n return this.updateTranslations$(language, sources);\n }\n\n /**\n * Updates translations based on the provided language code and sources.\n *\n * @param {Locales} language The language code to use for updating translations.\n * @param {Set<TranslationsSource>} [sources=this._sources] Optional set of sources to update.\n * @returns {Observable<void>} An observable that completes when the translations are updated.\n */\n public updateTranslations$(\n language: Locales,\n sources: Set<string> = this._sources\n ): Observable<void> {\n const observables: Set<Observable<Map<string, string>>> =\n this._getUpdateTranslationsObservables(language, sources);\n\n return forkJoin(Array.from(observables)).pipe(\n defaultIfEmpty([]),\n map((responses) => {\n this.translations.update(() =>\n this._mergeMaps(this.translations(), ...responses)\n );\n this.loggerService.info(\n `${this.constructor.name} - Setup - Translations set`,\n this.translations()\n );\n })\n );\n }\n\n /**\n * {@link ITranslationsService.translate}\n */\n public translate(key: string): string {\n const keyExists: boolean = this.translations().has(key);\n if (!keyExists) {\n this.loggerService.warn(\n `${this.constructor.name} - '${key}' translation key does not exist.`\n );\n return key;\n }\n\n const value: string = this.translations().get(key) as string;\n if (value === '' || value == null) {\n this.loggerService.warn(\n `${this.constructor.name} - '${key}' translation value is missing.`\n );\n return key;\n }\n\n if (value === TRANSLATION_DELIBERATELY_UNSET) {\n return key;\n }\n\n return value.replace('\\\\n', '\\n');\n }\n\n /**\n * Merge all translations update observables into a single set object\n * @param {Locales} language required language\n * @param {string} sources source object\n * @returns {Set<Observable<Map<string, string>>>} a set of translations\n * @private\n */\n private _getUpdateTranslationsObservables(\n language: Locales,\n sources: Set<string>\n ): Set<Observable<Map<string, string>>> {\n const observables = new Set<Observable<Map<string, string>>>();\n\n sources.forEach((source) => {\n const observable: Observable<Map<string, string>> =\n this._fetchTranslations$(language, source);\n observables.add(observable);\n });\n\n return observables;\n }\n\n /**\n * Fetch translations process, from JSON file path or API url\n * @param {Locales} language required language\n * @param {string} source source object\n * @returns {Observable<Map<string, string>>} a map with all required translations\n * @private\n */\n private _fetchTranslations$(\n language: Locales,\n source: string\n ): Observable<Map<string, string>> {\n const request: Get = {\n key: `translations:${language}:${source}`,\n url: `${source}`,\n };\n\n const observable: Observable<Map<string, string>> = this.httpService\n .get(request)\n .pipe(\n map((response) =>\n this._filterTranslations(\n language,\n response as Record<string, Translations>\n )\n )\n );\n\n return observable;\n }\n\n /**\n * API fetched translations are already filtered correctly by current language.\n * JSON are not. Treat them equally and filter out unneeded translations.\n *\n * @example\n * Generic JSON response is of type\n * {\n * key1: {\n * fr: 'frenchTranslatedValue',\n * en: 'englishTranslatedValue',\n * it: 'italianTranslatedValue'\n * ...\n * },\n * key2: {\n * fr: 'frenchTranslatedValue',\n * en: 'englishTranslatedValue',\n * it: 'italianTranslatedValue'\n * ...\n * },\n * ...\n * }\n *\n * If language is 'en', then original response will be filtered as follow\n *\n * {\n * key1: 'englishTranslatedValue',\n * key2: 'englishTranslatedValue',\n * ...\n * }\n *\n * @param {Locales} language filter translations upon this language code\n * @param {any} response fetched translations\n * @returns {Translations} this source filtered translations\n * @private\n */\n private _filterTranslations(\n language: Locales,\n response: Record<string, Translations>\n ): Map<string, string> {\n const isoCode = LOCALE_ISO_CODES[language];\n \n const translations = new Map<string, string>(\n Object.entries(\n Object.entries(response)\n .map(([key, value]: [string, Record<string, string>]) => {\n const val = value[isoCode];\n return { [key]: val };\n })\n .reduce((acc, translation) => Object.assign(acc, translation), {})\n )\n );\n return translations;\n }\n\n /**\n * Merge multiple map objects into single map\n * @param {Map<K, V>[]} maps maps to merge\n * @returns {Map<K, V>} merged maps\n * @private\n */\n private _mergeMaps<K, V>(...maps: Map<K, V>[]): Map<K, V> {\n const mergedMap = new Map<K, V>();\n\n maps.forEach((map) => {\n map.forEach((value, key) => {\n mergedMap.set(key, value);\n });\n });\n\n return mergedMap;\n }\n}\n","import type { PipeTransform } from '@angular/core';\nimport { Pipe, inject } from '@angular/core';\n\n// Services\nimport { TranslationsService } from '../../services/translations/translations.service';\n\n/**\n * Pipe that transforms a key into a translated string based on the provided language.\n * It allows to avoid calling function {@link TranslationsService.translate} in template\n * (highly inefficient for function being triggered on every changeDetection), exploiting\n * signal powerness.\n */\n@Pipe({\n name: 'translate',\n standalone: true,\n})\nexport class TranslatePipe implements PipeTransform {\n /**\n * @type {TranslationsService}\n */\n private readonly translationsService = inject(TranslationsService);\n\n /**\n * Transforms the given key into the corresponding translation.\n *\n * @param {string} key The key for the translation.\n * @returns {string} The translated string.\n */\n public transform(key: string): string {\n return this.translationsService.translate(key);\n }\n}\n","import type { Locales } from '@albi_scando/as-const-languages-lib';\nimport { LOCALES } from '@albi_scando/as-const-languages-lib';\n\n/**\n * Default language\n */\nexport const DEFAULT_LANGUAGE: Locales =\n LOCALES.ENGLISH_UNITED_KINGDOM;\n","\nimport type { Locales } from '@albi_scando/as-const-languages-lib';\nimport { LoggerService } from '@albi_scando/as-log-lib';\nimport type { Signal, WritableSignal } from '@angular/core';\nimport { Injectable, computed, inject, signal } from '@angular/core';\nimport { UserService } from '@user/services/user/user.service';\nimport type { Observable } from 'rxjs';\nimport { defer, EMPTY, of, switchMap, take, tap } from 'rxjs';\n\n// assets\nimport defaultConfigJSON from '../../assets/jsons/default.json';\n// constants\nimport { DEFAULT_LANGUAGE } from '../../constants/constants';\n// interfaces\nimport type { ILanguageLibSetup } from '../../interfaces/setup.interface';\n// services\nimport { TranslationsService } from '../translations/translations.service';\n\n/**\n * A service that manages different languages operations.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class LanguageService {\n /**\n * Boolean value triggered when there is an ongoing language change process\n */\n public isLoadingLanguage: WritableSignal<boolean> = signal(false);\n\n /**\n * Allowed locales\n */\n public allowedLocales = new Set<Locales>();\n\n /**\n * Derived signal for the current language/locale from the user service.\n * Updates automatically when user's locale changes.\n */\n public currentLanguage: Signal<Locales | undefined> = computed(\n () => this.userService.locale()\n );\n\n /**\n * {@link LoggerService}\n */\n private readonly loggerService = inject(LoggerService);\n\n /**\n * {@link TranslationsService}\n */\n private readonly translationsService = inject(TranslationsService);\n\n /**\n * {@link UserService}\n */\n private readonly userService = inject(UserService);\n\n /**\n * Constructor\n * @constructor\n * @ignore\n */\n constructor() {\n const config = defaultConfigJSON as Record<string, unknown>;\n\n const setup: ILanguageLibSetup = {\n locales: new Set<Locales>(config['locales'] as Locales[]),\n currentLocale: config['currentLocale'] as Locales,\n };\n this.setup$(setup).pipe(take(1)).subscribe();\n }\n\n /**\n * {@link ILanguageService.setup$}\n */\n public setup$(setup: Partial<ILanguageLibSetup>): Observable<void> {\n return defer(() => {\n if (setup.locales !== null && setup.locales !== undefined) {this.setAllowedLanguages(setup.locales);}\n return setup.currentLocale !== null && setup.currentLocale !== undefined\n ? this.setLanguage$(setup.currentLocale)\n : this.setLanguage$();\n });\n }\n\n /**\n * {@link ILanguageService.setAllowedLanguages}\n */\n public setAllowedLanguages(locales: Set<Locales>): void {\n this.allowedLocales = locales;\n }\n\n /**\n * {@link ILanguageService.setLanguage$}\n */\n public setLanguage$(\n locale: Locales | undefined = undefined\n ): Observable<void> {\n if (locale !== null && locale !== undefined && this._isLanguageAllowed(locale) === false) {\n this.loggerService.warn(\n `'${locale}' is not among valid locales. Going for auto locale.`\n );\n locale = undefined;\n }\n\n if (locale === null || locale === undefined) {\n locale = this._pickAutoLanguage();\n this.loggerService.warn(`Auto locale set. Picked '${locale}'.`);\n }\n\n if (this._isLanguageAlreadySet(locale)) {\n this.loggerService.warn(`'${locale}' locale is already set.`);\n return EMPTY;\n }\n\n const resolvedLocale: Locales = locale;\n\n return of(() => { this._toggleIsLoadingLanguage(true); }).pipe(\n tap(() => { this._updateUserLanguage(resolvedLocale); }),\n switchMap(() => this._updateTranslations$()),\n tap(() => { this._toggleIsLoadingLanguage(false); })\n );\n }\n\n /**\n * Update user locale and sync\n * @param {Locales} locale locale to set\n * @returns {void}\n * @private\n */\n private _updateUserLanguage(locale: Locales): void {\n this.userService.setLocale(locale);\n }\n\n /**\n * Update app translations according to current user locale\n * @returns {Observable<void>}\n * @private\n */\n private _updateTranslations$(): Observable<void> {\n const locale = this.userService.locale();\n if (locale === null || locale === undefined) {\n this.loggerService.error(\n `User locale is not set. Cannot update translations.`\n );\n return EMPTY;\n }\n return this.translationsService.updateTranslations$(\n locale\n );\n }\n\n /**\n * Check if locale is already set\n * @param {Locales} locale locale to set\n * @returns {boolean} true if provided locale is already set\n * @private\n */\n private _isLanguageAlreadySet(locale: Locales): boolean {\n return locale === this.userService.locale();\n }\n\n /**\n * Check if locale is among allowed ones\n * @param {Locales} locale locale to set\n * @returns {boolean} true if provided locale is among allowed ones\n * @private\n */\n private _isLanguageAllowed(locale: Locales): boolean {\n return this.allowedLocales.has(locale);\n }\n\n /**\n * Pick a valid locale automatically.\n * Try to get it from:\n * 1. user locale\n * 2. navigator locale\n * 3. default locale (en)\n * 4. first allowed locale\n * @returns {Locales} allowed locale according to rules above.\n * @private\n */\n private _pickAutoLanguage(): Locales {\n let language: Locales | undefined = this.userService.locale();\n if (language === null || language === undefined || !this._isLanguageAllowed(language)) {\n language = this._getNavigatorLanguage();\n if (!this._isLanguageAllowed(language)) {\n language = DEFAULT_LANGUAGE;\n if (!this._isLanguageAllowed(language)) {\n language = [...this.allowedLocales][0];\n }\n }\n }\n\n return language;\n }\n\n /**\n * Get navigator language\n * @returns {Locales} navigator language 'it'/'fr'\n * @private\n */\n private _getNavigatorLanguage(): Locales {\n const navigatorLocale: string = this._getNavigatorLocale();\n\n return (navigatorLocale.includes('-')\n ? navigatorLocale.split('-')[0]\n : navigatorLocale) as unknown as Locales;\n }\n\n /**\n * Get navigator locale\n * @returns {string} navigator locale 'it-IT'/'fr-FR'\n * @private\n */\n private _getNavigatorLocale(): string {\n return window.navigator.language;\n }\n\n /**\n * Toggle isLoadingNewLanguage property\n * @param {boolean | null} value value to set\n * @returns {void}\n * @private\n */\n private _toggleIsLoadingLanguage(value: boolean | null): void {\n value = value ?? !this.isLoadingLanguage();\n this.isLoadingLanguage.set(value);\n }\n}\n","/**\n * User levels constants.\n */\nexport const USER_LEVELS = {\n GUEST: 'guest',\n}\n","export const DEFAULT_USERNAME = 'guest';\nexport const DEFAULT_LEVEL = 'guest';\n","import type { Locales } from '@albi_scando/as-const-languages-lib';\nimport { STRING_EMPTY } from '@albi_scando/as-const-lib';\nimport type { Signal, WritableSignal } from '@angular/core';\nimport { Injectable, computed, signal } from '@angular/core';\nimport type { Observable } from 'rxjs';\nimport { of, take } from 'rxjs';\n\n// Assets\nimport type { IUserService } from './user.service.interface';\nimport defaultConfigJSON from '../../assets/jsons/default.json';\n// Constants\nimport { DEFAULT_LEVEL, DEFAULT_USERNAME } from '../../constants/default';\n// Interfaces\nimport type { IUserLibSetup } from '../../interfaces/setup.interface';\n\n\n@Injectable({\n providedIn: 'root',\n})\nexport class UserService implements IUserService {\n /**\n * {@link IUserService.username}\n */\n public username: WritableSignal<string | undefined> = signal(undefined);\n\n /**\n * {@link IUserService.token}\n */\n public token: WritableSignal<string | undefined> = signal(undefined);\n\n /**\n * @see IUserService.locale\n */\n public locale: WritableSignal<Locales | undefined> = signal(undefined);\n\n /**\n * Derived signal that indicates whether the user is logged in.\n * Returns true if both username and token are set and not empty.\n */\n public isLoggedIn: Signal<boolean> = computed(() => {\n const username = this.username();\n const token = this.token();\n return (\n username !== null &&\n username !== undefined &&\n username !== STRING_EMPTY &&\n token !== null &&\n token !== undefined &&\n token !== STRING_EMPTY\n );\n });\n\n /**\n * Constructor\n * @constructor\n * @ignore\n */\n constructor() {\n this.initialize();\n }\n\n /**\n * @see IUserService.setup$\n */\n public setup$(setup: IUserLibSetup): Observable<void> {\n this.reset();\n\n this.setUsername(setup.username);\n\n return of(undefined);\n }\n\n /**\n * @see IUserService.reset\n */\n public reset(): void {\n this.initialize();\n }\n\n /**\n * @see IUserService.setUsername\n */\n public setUsername(username: string): void {\n this.username.set(username);\n }\n\n /**\n * @see IUserService.setLocale\n */\n public setLocale(locale: Locales): void {\n this.locale.set(locale);\n }\n\n /**\n * Initialization method\n * \n * @returns {void}\n */\n private initialize(): void {\n const config = defaultConfigJSON as {\n language?: {\n username?: string;\n updateAPI?: string;\n };\n };\n\n const setup: IUserLibSetup = {\n username: config.language?.username ?? DEFAULT_USERNAME,\n level: DEFAULT_LEVEL as IUserLibSetup['level'],\n api: {\n patchUserDataAPIUrl: config.language?.updateAPI ?? STRING_EMPTY,\n },\n };\n\n this.setup$(setup).pipe(take(1)).subscribe();\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["UserService","HttpService","defaultConfigJSON"],"mappings":";;;;;;;;;;;;MAea,WAAW,CAAA;AAEtB;;AAEG;AACK,IAAA,UAAU,GAAe,MAAM,CAAC,UAAU,CAAC;AAEnD;;AAEG;AACI,IAAA,iBAAiB,GAAG,MAAY,SAAS;AAEhD;;AAEG;AACI,IAAA,cAAc,GAAG,MAAY,SAAS;AAE7C;;;;;AAKG;AACI,IAAA,MAAM,CAAC,WAAmB,EAAA;QAC/B,MAAM,OAAO,GAAsD,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,YAAY,CAAC;AAEvH,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC;IACzD;AAEA;;;;;AAKG;AACI,IAAA,GAAG,CAAC,WAAgB,EAAA;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QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,IAAI,gBAAgB;AACvD,YAAA,KAAK,EAAE,aAAuC;AAC9C,YAAA,GAAG,EAAE;AACH,gBAAA,mBAAmB,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,IAAI,YAAY;AAChE,aAAA;SACF;AAED,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE;IAC9C;uGAhGW,WAAW,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAX,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAW,cAFV,MAAM,EAAA,CAAA;;2FAEP,WAAW,EAAA,UAAA,EAAA,CAAA;kBAHvB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;AClBD;;AAEG;;;;"}
@@ -1,6 +1,542 @@
1
+ import { Observable } from 'rxjs';
2
+ import { HttpHeaders } from '@albi_scando/as-const-http-lib/dist/types/types/http-headers.type';
3
+ import * as i0 from '@angular/core';
4
+ import { PipeTransform, WritableSignal, Signal } from '@angular/core';
5
+ import { HttpInterceptorFn } from '@angular/common/http';
6
+ import { Locales } from '@albi_scando/as-const-languages-lib';
7
+
8
+ /**
9
+ *
10
+ */
11
+ interface IHttpService {
12
+ /**
13
+ * Expired password handler function.
14
+ * Used inside {@link UnauthorizedInterceptor}
15
+ */
16
+ expiredPasswordFn: () => void;
17
+ /**
18
+ * Unauthorized token handler function.
19
+ * Used inside {@link UnauthorizedInterceptor}
20
+ */
21
+ unauthorizedFn: () => void;
22
+ }
23
+
24
+ interface Api {
25
+ key: string;
26
+ url: string;
27
+ headerParams?: Map<HttpHeaders, string | boolean>;
28
+ }
29
+
30
+ interface Delete extends Api {
31
+ }
32
+
33
+ interface Get extends Api {
34
+ queryParams?: Map<string, string>;
35
+ }
36
+
37
+ interface Patch extends Api {
38
+ body: unknown;
39
+ }
40
+
41
+ interface Post extends Api {
42
+ body: unknown;
43
+ }
44
+
45
+ interface Put extends Api {
46
+ body: unknown;
47
+ }
48
+
49
+ declare class HttpService implements IHttpService {
50
+ /**
51
+ * {@link HttpClient}
52
+ */
53
+ private httpClient;
54
+ /**
55
+ * {@link IHttpService.expiredPasswordFn}
56
+ */
57
+ expiredPasswordFn: () => void;
58
+ /**
59
+ * {@link IHttpService.unauthorizedFn}
60
+ */
61
+ unauthorizedFn: () => void;
62
+ /**
63
+ * Perform http delete request
64
+ *
65
+ * @param {Delete} httpRequest http request
66
+ * @returns {Observable<unknown>} response observable
67
+ */
68
+ delete(httpRequest: Delete): Observable<unknown>;
69
+ /**
70
+ * Perform http get request
71
+ *
72
+ * @param {Get} httpRequest http request
73
+ * @returns {Observable<unknown>} response observable
74
+ */
75
+ get(httpRequest: Get): Observable<unknown>;
76
+ /**
77
+ * Perform http patch request
78
+ *
79
+ * @param {Patch} httpRequest http request
80
+ * @returns {Observable<unknown>} response observable
81
+ */
82
+ patch(httpRequest: Patch): Observable<unknown>;
83
+ /**
84
+ * Perform http post request
85
+ *
86
+ * @param {Post} httpRequest http request
87
+ * @returns {Observable<unknown>} response observable
88
+ */
89
+ post(httpRequest: Post): Observable<unknown>;
90
+ /**
91
+ * Perform http put request
92
+ *
93
+ * @param {Put} httpRequest http request
94
+ * @returns {Observable<unknown>} response observable
95
+ */
96
+ put(httpRequest: Put): Observable<unknown>;
97
+ /**
98
+ * Set url query parameters
99
+ *
100
+ * @param {Map<string, string>} queryParams query parameters key-value pairs
101
+ * @param {string} url original httpRequest url
102
+ * @returns {string} new url with aquery parameters
103
+ */
104
+ private _setQueryParams;
105
+ /**
106
+ * Type safe header options for HttpClient methods
107
+ * @param httpRequestHeaders header parameters key-value pairs
108
+ * @returns header options for HttpClient methods
109
+ */
110
+ private typeSafeHeaderOptions;
111
+ /**
112
+ * Set http request header parameters
113
+ *
114
+ * @param {Map<HttpHeaders, string | boolean>} headerParams header parameters key-value pairs
115
+ * @returns {Map<HttpHeaders, string>} header parameters key-value pairs. All values must be strings.
116
+ */
117
+ private _setHeaderParams;
118
+ static ɵfac: i0.ɵɵFactoryDeclaration<HttpService, never>;
119
+ static ɵprov: i0.ɵɵInjectableDeclaration<HttpService>;
120
+ }
121
+
122
+ /**
123
+ * This interceptor is responsible for adding Authorization header parameter to every outgoing HttpRequest
124
+ *
125
+ * @param {HttpRequest<unknown>} httpRequest @see {@link HttpRequest}
126
+ * @param {HttpHandlerFn} next @see {@link HttpHandlerFn}
127
+ * @returns {Observable<HttpEvent<unknown>>} @see {@link Observable<HttpEvent>}
128
+ */
129
+ declare const authorizationInterceptor: HttpInterceptorFn;
130
+
131
+ /**
132
+ * This interceptor logs every outgoing HttpRequest.
133
+ * It fulfills the same task as the developer tools Network inspector.
134
+ *
135
+ * @param {HttpRequest<unknown>} httpRequest @see {@link HttpRequest}
136
+ * @param {HttpHandlerFn} next @see {@link HttpHandlerFn}
137
+ * @returns {Observable<HttpEvent<unknown>>} @see {@link Observable<HttpEvent>}
138
+ */
139
+ declare const logRequestInterceptor: HttpInterceptorFn;
140
+
141
+ /**
142
+ * This interceptor logs the time interval (in milliseconds) between the request submission and the incoming response.
143
+ * It fulfills the same task as 'Waterfall' graph in the developer tools Network inspector.
144
+ *
145
+ * @param {HttpRequest<unknown>} httpRequest @see {@link HttpRequest}
146
+ * @param {HttpHandlerFn} next @see {@link HttpHandlerFn}
147
+ * @returns {Observable<HttpEvent<unknown>>} @see {@link Observable<HttpEvent>}
148
+ */
149
+ declare const requestTimestampInterceptor: HttpInterceptorFn;
150
+
151
+ /**
152
+ * Http request interceptor to handle 401 unauthorized responses.
153
+ * 401 error is special, because it needs more than just a feedback.
154
+ * In most situations, it could be provoked by an expired token that requires a redirect to a 'Login' page.
155
+ * When validating credentials, it could be provoked by an expired password that requires a redirect to 'Change password' page.
156
+ *
157
+ * @param {HttpRequest<unknown>} httpRequest @see {@link HttpRequest}
158
+ * @param {HttpHandlerFn} next @see {@link HttpHandlerFn}
159
+ * @returns {Observable<HttpEvent<unknown>>} @see {@link : Observable<HttpEvent>}
160
+ */
161
+ declare const unauthorizedInterceptor: HttpInterceptorFn;
162
+
163
+ /**
164
+ * Pipe that transforms a key into a translated string based on the provided language.
165
+ * It allows to avoid calling function {@link TranslationsService.translate} in template
166
+ * (highly inefficient for function being triggered on every changeDetection), exploiting
167
+ * signal powerness.
168
+ */
169
+ declare class TranslatePipe implements PipeTransform {
170
+ /**
171
+ * @type {TranslationsService}
172
+ */
173
+ private readonly translationsService;
174
+ /**
175
+ * Transforms the given key into the corresponding translation.
176
+ *
177
+ * @param {string} key The key for the translation.
178
+ * @returns {string} The translated string.
179
+ */
180
+ transform(key: string): string;
181
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslatePipe, never>;
182
+ static ɵpipe: i0.ɵɵPipeDeclaration<TranslatePipe, "translate", true>;
183
+ }
184
+
185
+ /**
186
+ * Configuration interface
187
+ */
188
+ interface ILanguageLibSetup {
189
+ locales?: Set<Locales>;
190
+ currentLocale?: Locales;
191
+ }
192
+
193
+ /**
194
+ * A service that manages different languages operations.
195
+ */
196
+ declare class LanguageService {
197
+ /**
198
+ * Boolean value triggered when there is an ongoing language change process
199
+ */
200
+ isLoadingLanguage: WritableSignal<boolean>;
201
+ /**
202
+ * Allowed locales
203
+ */
204
+ allowedLocales: Set<Locales>;
205
+ /**
206
+ * Derived signal for the current language/locale from the user service.
207
+ * Updates automatically when user's locale changes.
208
+ */
209
+ currentLanguage: Signal<Locales | undefined>;
210
+ /**
211
+ * {@link LoggerService}
212
+ */
213
+ private readonly loggerService;
214
+ /**
215
+ * {@link TranslationsService}
216
+ */
217
+ private readonly translationsService;
218
+ /**
219
+ * {@link UserService}
220
+ */
221
+ private readonly userService;
222
+ /**
223
+ * Constructor
224
+ * @constructor
225
+ * @ignore
226
+ */
227
+ constructor();
228
+ /**
229
+ * {@link ILanguageService.setup$}
230
+ */
231
+ setup$(setup: Partial<ILanguageLibSetup>): Observable<void>;
232
+ /**
233
+ * {@link ILanguageService.setAllowedLanguages}
234
+ */
235
+ setAllowedLanguages(locales: Set<Locales>): void;
236
+ /**
237
+ * {@link ILanguageService.setLanguage$}
238
+ */
239
+ setLanguage$(locale?: Locales | undefined): Observable<void>;
240
+ /**
241
+ * Update user locale and sync
242
+ * @param {Locales} locale locale to set
243
+ * @returns {void}
244
+ * @private
245
+ */
246
+ private _updateUserLanguage;
247
+ /**
248
+ * Update app translations according to current user locale
249
+ * @returns {Observable<void>}
250
+ * @private
251
+ */
252
+ private _updateTranslations$;
253
+ /**
254
+ * Check if locale is already set
255
+ * @param {Locales} locale locale to set
256
+ * @returns {boolean} true if provided locale is already set
257
+ * @private
258
+ */
259
+ private _isLanguageAlreadySet;
260
+ /**
261
+ * Check if locale is among allowed ones
262
+ * @param {Locales} locale locale to set
263
+ * @returns {boolean} true if provided locale is among allowed ones
264
+ * @private
265
+ */
266
+ private _isLanguageAllowed;
267
+ /**
268
+ * Pick a valid locale automatically.
269
+ * Try to get it from:
270
+ * 1. user locale
271
+ * 2. navigator locale
272
+ * 3. default locale (en)
273
+ * 4. first allowed locale
274
+ * @returns {Locales} allowed locale according to rules above.
275
+ * @private
276
+ */
277
+ private _pickAutoLanguage;
278
+ /**
279
+ * Get navigator language
280
+ * @returns {Locales} navigator language 'it'/'fr'
281
+ * @private
282
+ */
283
+ private _getNavigatorLanguage;
284
+ /**
285
+ * Get navigator locale
286
+ * @returns {string} navigator locale 'it-IT'/'fr-FR'
287
+ * @private
288
+ */
289
+ private _getNavigatorLocale;
290
+ /**
291
+ * Toggle isLoadingNewLanguage property
292
+ * @param {boolean | null} value value to set
293
+ * @returns {void}
294
+ * @private
295
+ */
296
+ private _toggleIsLoadingLanguage;
297
+ static ɵfac: i0.ɵɵFactoryDeclaration<LanguageService, never>;
298
+ static ɵprov: i0.ɵɵInjectableDeclaration<LanguageService>;
299
+ }
300
+
301
+ /**
302
+ * A service that manages translations based on the current language.
303
+ *
304
+ * The `TranslationsService` handles fetching, storing, and updating translations
305
+ * for different languages. It interacts with various translation sources and
306
+ * provides methods to retrieve translations based on a given key.
307
+ */
308
+ declare class TranslationsService {
309
+ /**
310
+ * List of translations sources (apis/files)
311
+ */
312
+ private _sources;
313
+ /**
314
+ * Current translations dictionary, mapping translation keys to their values.
315
+ */
316
+ translations: WritableSignal<Map<string, string>>;
317
+ /**
318
+ * Derived signal that indicates whether translations are currently loaded.
319
+ * Returns true if the translations map contains any entries.
320
+ */
321
+ hasTranslations: Signal<boolean>;
322
+ /**
323
+ * Derived signal for the count of currently loaded translations.
324
+ * Useful for debugging or monitoring translation load status.
325
+ */
326
+ translationsCount: Signal<number>;
327
+ /**
328
+ * {@link HttpService}
329
+ */
330
+ private readonly httpService;
331
+ /**
332
+ * {@link LoggerService}
333
+ */
334
+ private readonly loggerService;
335
+ /**
336
+ * Adds new translation sources and optionally updates translations for a given language code.
337
+ *
338
+ * If no language code is provided, the translations will not be updated immediately.
339
+ * The translations will be updated as soon as the current language is set.
340
+ *
341
+ * @param {Set<TranslationsSource>} sources New sources to add.
342
+ * @param {Locales} [language=stringEmpty] Optional language code to trigger translations update.
343
+ * @returns {Observable<void>} An observable that completes when the translations are updated.
344
+ */
345
+ addTranslationsSources$(sources: Set<string>, language: Locales): Observable<void>;
346
+ /**
347
+ * Updates translations based on the provided language code and sources.
348
+ *
349
+ * @param {Locales} language The language code to use for updating translations.
350
+ * @param {Set<TranslationsSource>} [sources=this._sources] Optional set of sources to update.
351
+ * @returns {Observable<void>} An observable that completes when the translations are updated.
352
+ */
353
+ updateTranslations$(language: Locales, sources?: Set<string>): Observable<void>;
354
+ /**
355
+ * {@link ITranslationsService.translate}
356
+ */
357
+ translate(key: string): string;
358
+ /**
359
+ * Merge all translations update observables into a single set object
360
+ * @param {Locales} language required language
361
+ * @param {string} sources source object
362
+ * @returns {Set<Observable<Map<string, string>>>} a set of translations
363
+ * @private
364
+ */
365
+ private _getUpdateTranslationsObservables;
366
+ /**
367
+ * Fetch translations process, from JSON file path or API url
368
+ * @param {Locales} language required language
369
+ * @param {string} source source object
370
+ * @returns {Observable<Map<string, string>>} a map with all required translations
371
+ * @private
372
+ */
373
+ private _fetchTranslations$;
374
+ /**
375
+ * API fetched translations are already filtered correctly by current language.
376
+ * JSON are not. Treat them equally and filter out unneeded translations.
377
+ *
378
+ * @example
379
+ * Generic JSON response is of type
380
+ * {
381
+ * key1: {
382
+ * fr: 'frenchTranslatedValue',
383
+ * en: 'englishTranslatedValue',
384
+ * it: 'italianTranslatedValue'
385
+ * ...
386
+ * },
387
+ * key2: {
388
+ * fr: 'frenchTranslatedValue',
389
+ * en: 'englishTranslatedValue',
390
+ * it: 'italianTranslatedValue'
391
+ * ...
392
+ * },
393
+ * ...
394
+ * }
395
+ *
396
+ * If language is 'en', then original response will be filtered as follow
397
+ *
398
+ * {
399
+ * key1: 'englishTranslatedValue',
400
+ * key2: 'englishTranslatedValue',
401
+ * ...
402
+ * }
403
+ *
404
+ * @param {Locales} language filter translations upon this language code
405
+ * @param {any} response fetched translations
406
+ * @returns {Translations} this source filtered translations
407
+ * @private
408
+ */
409
+ private _filterTranslations;
410
+ /**
411
+ * Merge multiple map objects into single map
412
+ * @param {Map<K, V>[]} maps maps to merge
413
+ * @returns {Map<K, V>} merged maps
414
+ * @private
415
+ */
416
+ private _mergeMaps;
417
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslationsService, never>;
418
+ static ɵprov: i0.ɵɵInjectableDeclaration<TranslationsService>;
419
+ }
420
+
421
+ /**
422
+ * User levels constants.
423
+ */
424
+ declare const USER_LEVELS: {
425
+ GUEST: string;
426
+ };
427
+
1
428
  /**
2
- * The name of the application.
429
+ * Union type of all values in the {@link USER_LEVELS} constant.
3
430
  */
4
- declare const APPLICATION_NAME = "as-backbone-lib";
431
+ type UserLevels = (typeof USER_LEVELS)[keyof typeof USER_LEVELS];
432
+
433
+ /**
434
+ * Configuration interface
435
+ */
436
+ interface IUserLibSetup {
437
+ username: string;
438
+ level: UserLevels;
439
+ api?: API;
440
+ }
441
+ interface API {
442
+ patchUserDataAPIUrl: string;
443
+ }
444
+
445
+ interface IUserService {
446
+ /**
447
+ * Username signal
448
+ */
449
+ username: WritableSignal<string | undefined>;
450
+ /**
451
+ * Token signal
452
+ */
453
+ token: WritableSignal<string | undefined>;
454
+ /**
455
+ * Locale signal
456
+ */
457
+ locale: WritableSignal<string | undefined>;
458
+ /**
459
+ * Setup method
460
+ *
461
+ * @param setup Setup object
462
+ * @return Observable that completes when setup is done
463
+ */
464
+ setup$(setup: IUserLibSetup): Observable<void>;
465
+ /**
466
+ * Reset method
467
+ *
468
+ * @returns {void}
469
+ */
470
+ reset(): void;
471
+ /**
472
+ * Set username method
473
+ * @param username Username to set
474
+ * @return {void}
475
+ */
476
+ setUsername(username: string): void;
477
+ /**
478
+ * Set user language method
479
+ * @param locale Locale to set
480
+ * @return {void}
481
+ */
482
+ setLocale(locale: Locales): void;
483
+ }
484
+
485
+ declare class UserService implements IUserService {
486
+ /**
487
+ * {@link IUserService.username}
488
+ */
489
+ username: WritableSignal<string | undefined>;
490
+ /**
491
+ * {@link IUserService.token}
492
+ */
493
+ token: WritableSignal<string | undefined>;
494
+ /**
495
+ * @see IUserService.locale
496
+ */
497
+ locale: WritableSignal<Locales | undefined>;
498
+ /**
499
+ * Derived signal that indicates whether the user is logged in.
500
+ * Returns true if both username and token are set and not empty.
501
+ */
502
+ isLoggedIn: Signal<boolean>;
503
+ /**
504
+ * Constructor
505
+ * @constructor
506
+ * @ignore
507
+ */
508
+ constructor();
509
+ /**
510
+ * @see IUserService.setup$
511
+ */
512
+ setup$(setup: IUserLibSetup): Observable<void>;
513
+ /**
514
+ * @see IUserService.reset
515
+ */
516
+ reset(): void;
517
+ /**
518
+ * @see IUserService.setUsername
519
+ */
520
+ setUsername(username: string): void;
521
+ /**
522
+ * @see IUserService.setLocale
523
+ */
524
+ setLocale(locale: Locales): void;
525
+ /**
526
+ * Initialization method
527
+ *
528
+ * @returns {void}
529
+ */
530
+ private initialize;
531
+ static ɵfac: i0.ɵɵFactoryDeclaration<UserService, never>;
532
+ static ɵprov: i0.ɵɵInjectableDeclaration<UserService>;
533
+ }
534
+
535
+ interface User {
536
+ username: string;
537
+ token: string;
538
+ locale: Locales;
539
+ }
5
540
 
6
- export { APPLICATION_NAME };
541
+ export { HttpService, LanguageService, TranslatePipe, TranslationsService, USER_LEVELS, UserService, authorizationInterceptor, logRequestInterceptor, requestTimestampInterceptor, unauthorizedInterceptor };
542
+ export type { Delete, Get, ILanguageLibSetup, IUserLibSetup, Patch, Post, Put, User, UserLevels };