@ng-vagabond-lab/ng-dsv 0.1.89 → 0.1.91
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/fesm2022/ng-vagabond-lab-ng-dsv-api.mjs +3 -46
- package/fesm2022/ng-vagabond-lab-ng-dsv-api.mjs.map +1 -1
- package/fesm2022/ng-vagabond-lab-ng-dsv-modules-auth.mjs +3 -8
- package/fesm2022/ng-vagabond-lab-ng-dsv-modules-auth.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ng-vagabond-lab-ng-dsv-api.d.ts +3 -10
- package/types/ng-vagabond-lab-ng-dsv-modules-auth.d.ts +0 -1
|
@@ -1,47 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { httpResource, HttpClient } from '@angular/common/http';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
|
-
import {
|
|
3
|
+
import { signal, Injectable, inject } from '@angular/core';
|
|
4
4
|
import { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';
|
|
5
|
-
import { catchError, throwError, switchMap } from 'rxjs';
|
|
6
5
|
import { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';
|
|
7
6
|
import { Store } from '@ng-vagabond-lab/ng-dsv/storage';
|
|
8
7
|
|
|
9
|
-
const authInterceptor = (req, next) => {
|
|
10
|
-
const httpClient = inject(HttpClient);
|
|
11
|
-
const apiService = inject(ApiService);
|
|
12
|
-
const toastService = inject(ToastService);
|
|
13
|
-
return next(getToken(req, apiService)).pipe(catchError((error) => {
|
|
14
|
-
if (error instanceof HttpErrorResponse &&
|
|
15
|
-
!req.url.includes('auth/') &&
|
|
16
|
-
req.url.includes(apiService.baseUrl) &&
|
|
17
|
-
error.status === 401) {
|
|
18
|
-
return handle401Error(httpClient, apiService, req, next);
|
|
19
|
-
}
|
|
20
|
-
console.error(error);
|
|
21
|
-
toastService.showToast({
|
|
22
|
-
type: 'error',
|
|
23
|
-
text: error.error.debugMessage ?? error.error.message ?? error.message,
|
|
24
|
-
});
|
|
25
|
-
return throwError(() => error);
|
|
26
|
-
}));
|
|
27
|
-
};
|
|
28
|
-
const getToken = (req, apiService) => {
|
|
29
|
-
const jwt = apiService.userToken();
|
|
30
|
-
if (!req.url.includes('/auth/') && req.url.includes(apiService.baseUrl) && jwt) {
|
|
31
|
-
const headers = req.headers.set('Authorization', `Bearer ${jwt}`);
|
|
32
|
-
return req.clone({
|
|
33
|
-
headers,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return req;
|
|
37
|
-
};
|
|
38
|
-
const handle401Error = (httpClient, apiService, request, next) => {
|
|
39
|
-
return httpClient.post(apiService.baseUrl + '/auth/refresh-token', {}, { withCredentials: true }).pipe(switchMap((response) => {
|
|
40
|
-
apiService.initUser(response);
|
|
41
|
-
return next(getToken(request, apiService));
|
|
42
|
-
}));
|
|
43
|
-
};
|
|
44
|
-
|
|
45
8
|
class ApiResourceService {
|
|
46
9
|
url = signal(undefined, ...(ngDevMode ? [{ debugName: "url" }] : /* istanbul ignore next */ []));
|
|
47
10
|
resource = httpResource(() => ({
|
|
@@ -77,17 +40,11 @@ class ApiService {
|
|
|
77
40
|
httpClient = inject(HttpClient);
|
|
78
41
|
toastService = inject(ToastService);
|
|
79
42
|
platformService = inject(PlatformService);
|
|
80
|
-
userConnected = signal(null, ...(ngDevMode ? [{ debugName: "userConnected" }] : /* istanbul ignore next */ []));
|
|
81
|
-
userToken = signal('', ...(ngDevMode ? [{ debugName: "userToken" }] : /* istanbul ignore next */ []));
|
|
82
43
|
load = signal(false, ...(ngDevMode ? [{ debugName: "load" }] : /* istanbul ignore next */ []));
|
|
83
44
|
baseUrl = '';
|
|
84
45
|
setBaseUrl(url) {
|
|
85
46
|
this.baseUrl = url;
|
|
86
47
|
}
|
|
87
|
-
initUser(user = null) {
|
|
88
|
-
this.userConnected.set(user);
|
|
89
|
-
this.userToken.set(user?.['jwt'] ?? '');
|
|
90
|
-
}
|
|
91
48
|
get(url, callback) {
|
|
92
49
|
this.doSubscribe(url, this.httpClient.get(this.baseUrl + url), callback);
|
|
93
50
|
}
|
|
@@ -211,5 +168,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
|
|
|
211
168
|
* Generated bundle index. Do not edit.
|
|
212
169
|
*/
|
|
213
170
|
|
|
214
|
-
export { ApiResourceService, ApiService, BaseSearchService
|
|
171
|
+
export { ApiResourceService, ApiService, BaseSearchService };
|
|
215
172
|
//# sourceMappingURL=ng-vagabond-lab-ng-dsv-api.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-vagabond-lab-ng-dsv-api.mjs","sources":["../../../projects/ng-dsv/api/interceptor/api.interceptor.ts","../../../projects/ng-dsv/api/service/api.resource.service.ts","../../../projects/ng-dsv/api/service/api.service.ts","../../../projects/ng-dsv/api/service/search/base.search.service.ts","../../../projects/ng-dsv/api/ng-vagabond-lab-ng-dsv-api.ts"],"sourcesContent":["import { HttpClient, HttpErrorResponse, HttpHandlerFn, HttpRequest } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';\nimport { catchError, switchMap, throwError } from 'rxjs';\nimport { ApiService } from '../public-api';\n\nexport const authInterceptor = (req: HttpRequest<unknown>, next: HttpHandlerFn) => {\n const httpClient = inject(HttpClient);\n const apiService = inject(ApiService);\n const toastService = inject(ToastService);\n\n return next(getToken(req, apiService)).pipe(\n catchError((error) => {\n if (\n error instanceof HttpErrorResponse &&\n !req.url.includes('auth/') &&\n req.url.includes(apiService.baseUrl) &&\n error.status === 401\n ) {\n return handle401Error(httpClient, apiService, req, next);\n }\n\n console.error(error);\n\n toastService.showToast({\n type: 'error',\n text: error.error.debugMessage ?? error.error.message ?? error.message,\n });\n\n return throwError(() => error);\n }),\n );\n};\n\nconst getToken = <T>(req: HttpRequest<T>, apiService: ApiService) => {\n const jwt = apiService.userToken();\n if (!req.url.includes('/auth/') && req.url.includes(apiService.baseUrl) && jwt) {\n const headers = req.headers.set('Authorization', `Bearer ${jwt}`);\n\n return req.clone({\n headers,\n });\n }\n return req;\n};\n\nconst handle401Error = <T>(\n httpClient: HttpClient,\n apiService: ApiService,\n request: HttpRequest<T>,\n next: HttpHandlerFn,\n) => {\n return httpClient.post(apiService.baseUrl + '/auth/refresh-token', {}, { withCredentials: true }).pipe(\n switchMap((response) => {\n apiService.initUser(response);\n\n return next(getToken(request, apiService));\n }),\n );\n};\n","import { httpResource } from '@angular/common/http';\nimport { Injectable, ResourceRef, signal } from '@angular/core';\nimport { OrderState } from '../public-api';\n\nexport interface ApiFindBy {\n endPoint?: string;\n fields?: string;\n values?: string;\n first?: number;\n max?: number;\n order?: OrderState;\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ApiResourceService<T> {\n url = signal<string | undefined>(undefined);\n\n resource: ResourceRef<T | undefined> = httpResource(() => ({\n url: `${this.url()}`,\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n },\n params: {},\n reportProgress: true,\n transferCache: true,\n keepalive: true,\n mode: 'same-origin',\n redirect: 'error',\n priority: 'high',\n cache: 'force-cache',\n credentials: 'include',\n referrer: 'no-referrer',\n integrity: 'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GhEXAMPLEKEY=',\n }));\n\n constructor() {}\n}\n","import { HttpClient } from '@angular/common/http';\nimport { inject, Injectable, signal } from '@angular/core';\nimport { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { Observable } from 'rxjs';\nimport { ApiDto, ID, JSONObject, OrderState } from '../dto/api.dto';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ApiService {\n readonly httpClient = inject(HttpClient);\n readonly toastService = inject(ToastService);\n readonly platformService = inject(PlatformService);\n\n userConnected = signal<JSONObject | null>(null);\n userToken = signal<string>('');\n\n load = signal<boolean>(false);\n baseUrl: string = '';\n\n setBaseUrl(url: string) {\n this.baseUrl = url;\n }\n\n initUser(user: JSONObject | null = null) {\n this.userConnected.set(user);\n this.userToken.set(user?.['jwt' as keyof JSONObject] ?? '');\n }\n\n get<T>(url: string, callback: (data: T) => void) {\n this.doSubscribe(url, this.httpClient.get<T>(this.baseUrl + url), callback);\n }\n\n post<T>(url: string, data: T, callback: (data: T) => void, withCredentials: boolean = false) {\n this.doSubscribe(\n url,\n this.httpClient.post<T>(this.baseUrl + url, data, { withCredentials }),\n callback,\n );\n }\n\n put<T>(url: string, data: T, callback: (data: T) => void) {\n this.doSubscribe(url, this.httpClient.put<T>(this.baseUrl + url, data), callback);\n }\n\n delete<T>(url: string, callback: (data: T) => void) {\n this.doSubscribe(url, this.httpClient.delete<T>(this.baseUrl + url), callback);\n }\n\n findById<T>(endPoint: string, id: ID, callback: (data: T) => void) {\n this.get<T>(endPoint + '/' + id, callback);\n }\n\n findBy<T>(\n endPoint: string,\n fields: string,\n values: string,\n first: number,\n max: number,\n order: OrderState,\n callback: (data: T) => void,\n ) {\n const orderType: string = order.orderAsc ? '' : 'Desc';\n const orderConst: string = order.order ? '>>' + order.order + orderType : '';\n const fieldsComplete = fields + orderConst;\n this.get<T>(\n endPoint +\n '?fields=' +\n encodeURI(fieldsComplete) +\n '&values=' +\n encodeURI(values) +\n '&first=' +\n first +\n '&max=' +\n max,\n (data: T) => {\n callback(data);\n },\n );\n }\n\n countBy(endPoint: string, fields: string, values: string, callback: (data: { count: number }) => void) {\n return this.get<{ count: number }>(\n endPoint + '?fields=' + encodeURI(fields) + '&values=' + values,\n (data: { count: number }) => {\n callback(data);\n },\n );\n }\n\n createOrUpdate<T extends ApiDto>(endPoint: string, data: T, callback: (data: T) => void) {\n if (data.id !== null && data.id !== undefined && data.id !== '' && Number(data.id) > 0) {\n this.put<T>('/' + endPoint + '/', data, (dateReturn: T) => {\n this.toastService.showToast({ text: 'UPDATE_OK', type: 'success' });\n callback(dateReturn);\n });\n } else {\n this.post<T>('/' + endPoint + '/', data, (dateReturn: T) => {\n this.toastService.showToast({ text: 'CREATION_OK', type: 'success' });\n callback(dateReturn);\n });\n }\n }\n\n doSubscribe<T>(url: string, observable: Observable<T>, callback: (data: T) => void) {\n this.load.set(true);\n observable.subscribe({\n next: (res) => {\n this.load.set(false);\n this.info(url, res as JSONObject);\n callback(res);\n },\n error: (error: JSONObject) => {\n this.load.set(false);\n this.error(url, error);\n },\n });\n }\n\n info(url: string, data: JSONObject) {\n if (this.platformService.isPlatformBrowser()) {\n console.log(url, data);\n }\n }\n\n error(url: string, error: JSONObject) {\n if (this.platformService.isPlatformBrowser()) {\n console.error(url, error);\n }\n }\n}\n","import { inject, Injectable, signal } from '@angular/core';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { Store } from '@ng-vagabond-lab/ng-dsv/storage';\nimport { PageableDto } from '../../public-api';\nimport { ApiService } from '../api.service';\n\n@Injectable({ providedIn: 'root' })\nexport abstract class BaseSearchService<T> {\n readonly apiService = inject(ApiService);\n readonly platformService = inject(PlatformService);\n\n datas = new Store<T>();\n\n page = signal<number>(1);\n isLoading = signal<boolean>(false);\n stopLoad = signal<boolean>(false);\n search = signal<string>('');\n\n doLoad(\n url: string,\n search: string = '',\n page: number = 1,\n nbPage: number = 20,\n field: string = 'content',\n ) {\n const params = '?page=' + page + '&nbPage=' + nbPage + '&query=' + search;\n\n this.search.set(search);\n if (page === 1) {\n this.stopLoad.set(false);\n }\n if (this.stopLoad()) {\n return;\n }\n this.isLoading.set(true);\n this.apiService.get<PageableDto<T>>(url + params, (data) => {\n this.page.set(page + nbPage);\n this.datas.updateForPage(page, data[field as keyof PageableDto<T>] as T[]);\n if ((data[field as keyof PageableDto<T>] as T[])?.length === 0) {\n this.stopLoad.set(true);\n }\n this.isLoading.set(false);\n });\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;MAMa,eAAe,GAAG,CAAC,GAAyB,EAAE,IAAmB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AK,IAAI,CAAC,KAA6B,CAAS,EAAE,MAAM,KAAK,CAAC,EAAE;AAC5D,gBAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;YAC3B;AACA,YAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;AAC7B,QAAA,CAAC,CAAC;IACN;uGApCkB,iBAAiB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAjB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,iBAAiB,cADb,MAAM,EAAA,CAAA;;2FACV,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBADtC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACNlC;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ng-vagabond-lab-ng-dsv-api.mjs","sources":["../../../projects/ng-dsv/api/service/api.resource.service.ts","../../../projects/ng-dsv/api/service/api.service.ts","../../../projects/ng-dsv/api/service/search/base.search.service.ts","../../../projects/ng-dsv/api/ng-vagabond-lab-ng-dsv-api.ts"],"sourcesContent":["import { httpResource } from '@angular/common/http';\nimport { Injectable, ResourceRef, signal } from '@angular/core';\nimport { OrderState } from '../public-api';\n\nexport interface ApiFindBy {\n endPoint?: string;\n fields?: string;\n values?: string;\n first?: number;\n max?: number;\n order?: OrderState;\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ApiResourceService<T> {\n url = signal<string | undefined>(undefined);\n\n resource: ResourceRef<T | undefined> = httpResource(() => ({\n url: `${this.url()}`,\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n },\n params: {},\n reportProgress: true,\n transferCache: true,\n keepalive: true,\n mode: 'same-origin',\n redirect: 'error',\n priority: 'high',\n cache: 'force-cache',\n credentials: 'include',\n referrer: 'no-referrer',\n integrity: 'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GhEXAMPLEKEY=',\n }));\n\n constructor() {}\n}\n","import { HttpClient } from '@angular/common/http';\nimport { inject, Injectable, signal } from '@angular/core';\nimport { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { Observable } from 'rxjs';\nimport { ApiDto, ID, JSONObject, OrderState } from '../dto/api.dto';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ApiService {\n readonly httpClient = inject(HttpClient);\n readonly toastService = inject(ToastService);\n readonly platformService = inject(PlatformService);\n\n load = signal<boolean>(false);\n baseUrl: string = '';\n\n setBaseUrl(url: string) {\n this.baseUrl = url;\n }\n\n get<T>(url: string, callback: (data: T) => void) {\n this.doSubscribe(url, this.httpClient.get<T>(this.baseUrl + url), callback);\n }\n\n post<T>(url: string, data: T, callback: (data: T) => void, withCredentials: boolean = false) {\n this.doSubscribe(\n url,\n this.httpClient.post<T>(this.baseUrl + url, data, { withCredentials }),\n callback,\n );\n }\n\n put<T>(url: string, data: T, callback: (data: T) => void) {\n this.doSubscribe(url, this.httpClient.put<T>(this.baseUrl + url, data), callback);\n }\n\n delete<T>(url: string, callback: (data: T) => void) {\n this.doSubscribe(url, this.httpClient.delete<T>(this.baseUrl + url), callback);\n }\n\n findById<T>(endPoint: string, id: ID, callback: (data: T) => void) {\n this.get<T>(endPoint + '/' + id, callback);\n }\n\n findBy<T>(\n endPoint: string,\n fields: string,\n values: string,\n first: number,\n max: number,\n order: OrderState,\n callback: (data: T) => void,\n ) {\n const orderType: string = order.orderAsc ? '' : 'Desc';\n const orderConst: string = order.order ? '>>' + order.order + orderType : '';\n const fieldsComplete = fields + orderConst;\n this.get<T>(\n endPoint +\n '?fields=' +\n encodeURI(fieldsComplete) +\n '&values=' +\n encodeURI(values) +\n '&first=' +\n first +\n '&max=' +\n max,\n (data: T) => {\n callback(data);\n },\n );\n }\n\n countBy(endPoint: string, fields: string, values: string, callback: (data: { count: number }) => void) {\n return this.get<{ count: number }>(\n endPoint + '?fields=' + encodeURI(fields) + '&values=' + values,\n (data: { count: number }) => {\n callback(data);\n },\n );\n }\n\n createOrUpdate<T extends ApiDto>(endPoint: string, data: T, callback: (data: T) => void) {\n if (data.id !== null && data.id !== undefined && data.id !== '' && Number(data.id) > 0) {\n this.put<T>('/' + endPoint + '/', data, (dateReturn: T) => {\n this.toastService.showToast({ text: 'UPDATE_OK', type: 'success' });\n callback(dateReturn);\n });\n } else {\n this.post<T>('/' + endPoint + '/', data, (dateReturn: T) => {\n this.toastService.showToast({ text: 'CREATION_OK', type: 'success' });\n callback(dateReturn);\n });\n }\n }\n\n doSubscribe<T>(url: string, observable: Observable<T>, callback: (data: T) => void) {\n this.load.set(true);\n observable.subscribe({\n next: (res) => {\n this.load.set(false);\n this.info(url, res as JSONObject);\n callback(res);\n },\n error: (error: JSONObject) => {\n this.load.set(false);\n this.error(url, error);\n },\n });\n }\n\n info(url: string, data: JSONObject) {\n if (this.platformService.isPlatformBrowser()) {\n console.log(url, data);\n }\n }\n\n error(url: string, error: JSONObject) {\n if (this.platformService.isPlatformBrowser()) {\n console.error(url, error);\n }\n }\n}\n","import { inject, Injectable, signal } from '@angular/core';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { Store } from '@ng-vagabond-lab/ng-dsv/storage';\nimport { PageableDto } from '../../public-api';\nimport { ApiService } from '../api.service';\n\n@Injectable({ providedIn: 'root' })\nexport abstract class BaseSearchService<T> {\n readonly apiService = inject(ApiService);\n readonly platformService = inject(PlatformService);\n\n datas = new Store<T>();\n\n page = signal<number>(1);\n isLoading = signal<boolean>(false);\n stopLoad = signal<boolean>(false);\n search = signal<string>('');\n\n doLoad(\n url: string,\n search: string = '',\n page: number = 1,\n nbPage: number = 20,\n field: string = 'content',\n ) {\n const params = '?page=' + page + '&nbPage=' + nbPage + '&query=' + search;\n\n this.search.set(search);\n if (page === 1) {\n this.stopLoad.set(false);\n }\n if (this.stopLoad()) {\n return;\n }\n this.isLoading.set(true);\n this.apiService.get<PageableDto<T>>(url + params, (data) => {\n this.page.set(page + nbPage);\n this.datas.updateForPage(page, data[field as keyof PageableDto<T>] as T[]);\n if ((data[field as keyof PageableDto<T>] as T[])?.length === 0) {\n this.stopLoad.set(true);\n }\n this.isLoading.set(false);\n });\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;MAgBa,kBAAkB,CAAA;AAC3B,IAAA,GAAG,GAAG,MAAM,CAAqB,SAAS,0EAAC;AAE3C,IAAA,QAAQ,GAA+B,YAAY,CAAC,OAAO;AACvD,QAAA,GAAG,EAAE,CAAA,EAAG,IAAI,CAAC,GAAG,EAAE,CAAA,CAAE;AACpB,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,OAAO,EAAE;AACL,YAAA,cAAc,EAAE,kBAAkB;AACrC,SAAA;AACD,QAAA,MAAM,EAAE,EAAE;AACV,QAAA,cAAc,EAAE,IAAI;AACpB,QAAA,aAAa,EAAE,IAAI;AACnB,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,IAAI,EAAE,aAAa;AACnB,QAAA,QAAQ,EAAE,OAAO;AACjB,QAAA,QAAQ,EAAE,MAAM;AAChB,QAAA,KAAK,EAAE,aAAa;AACpB,QAAA,WAAW,EAAE,SAAS;AACtB,QAAA,QAAQ,EAAE,aAAa;AACvB,QAAA,SAAS,EAAE,iDAAiD;AAC/D,KAAA,CAAC,+EAAC;AAEH,IAAA,WAAA,GAAA,EAAe;uGAtBN,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAlB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,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AA;kBADtC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACNlC;;AAEG;;;;"}
|
|
@@ -109,11 +109,6 @@ class AuthService {
|
|
|
109
109
|
apiService = inject(ApiService);
|
|
110
110
|
userConnected = signal(null, ...(ngDevMode ? [{ debugName: "userConnected" }] : /* istanbul ignore next */ []));
|
|
111
111
|
userToken = signal('', ...(ngDevMode ? [{ debugName: "userToken" }] : /* istanbul ignore next */ []));
|
|
112
|
-
constructor() {
|
|
113
|
-
effect(() => {
|
|
114
|
-
this.userConnected.set(this.apiService.userConnected());
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
112
|
initUser(user = null) {
|
|
118
113
|
this.userConnected.set(user);
|
|
119
114
|
this.userToken.set(user?.['jwt'] ?? '');
|
|
@@ -122,7 +117,7 @@ class AuthService {
|
|
|
122
117
|
this.apiService.post('auth/google-identity-connect', {
|
|
123
118
|
googleToken: credential,
|
|
124
119
|
}, (data) => {
|
|
125
|
-
this.
|
|
120
|
+
this.initUser(data);
|
|
126
121
|
this.apiService.toastService.showToast({
|
|
127
122
|
type: 'success',
|
|
128
123
|
text: 'Connexion réussie',
|
|
@@ -134,7 +129,7 @@ class AuthService {
|
|
|
134
129
|
}
|
|
135
130
|
logout() {
|
|
136
131
|
this.apiService.post('auth/logout', {}, () => {
|
|
137
|
-
this.
|
|
132
|
+
this.initUser();
|
|
138
133
|
this.apiService.toastService.showToast({
|
|
139
134
|
type: 'success',
|
|
140
135
|
text: 'Déconnexion réussie',
|
|
@@ -149,7 +144,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
|
|
|
149
144
|
args: [{
|
|
150
145
|
providedIn: 'root',
|
|
151
146
|
}]
|
|
152
|
-
}]
|
|
147
|
+
}] });
|
|
153
148
|
|
|
154
149
|
class AuthGoogleService {
|
|
155
150
|
authService = inject(AuthService);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-vagabond-lab-ng-dsv-modules-auth.mjs","sources":["../../../projects/ng-dsv/modules/auth/component/auth.component.ts","../../../projects/ng-dsv/modules/auth/component/auth.component.html","../../../projects/ng-dsv/modules/auth/guard/auth.guard.ts","../../../projects/ng-dsv/modules/auth/interceptor/auth.interceptor.ts","../../../projects/ng-dsv/modules/auth/service/auth.service.ts","../../../projects/ng-dsv/modules/auth/service/auth.google.service.ts","../../../projects/ng-dsv/modules/auth/utils/auth.utils.ts","../../../projects/ng-dsv/modules/auth/ng-vagabond-lab-ng-dsv-modules-auth.ts"],"sourcesContent":["import { CommonModule } from '@angular/common';\nimport { Component, effect, inject, output } from '@angular/core';\nimport { ID } from '@ng-vagabond-lab/ng-dsv/api';\nimport { ModalAlertComponent, ModalButtonComponent } from '@ng-vagabond-lab/ng-dsv/ds/modal';\nimport { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { AuthGoogleService, AuthService } from '../public-api';\n\n@Component({\n selector: 'dsv-auth',\n imports: [CommonModule, ModalButtonComponent, ModalAlertComponent],\n templateUrl: './auth.component.html',\n styleUrls: ['./auth.component.scss'],\n})\nexport class AuthComponent {\n readonly authService = inject(AuthService);\n readonly authGoogleService = inject(AuthGoogleService);\n readonly environmentService = inject(EnvironmentService);\n readonly platformService = inject(PlatformService);\n\n callbackInitMember = output<ID>();\n callbackLogout = output<void>();\n\n constructor() {\n effect(() => {\n if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {\n this.authGoogleService.initGoogleAuth();\n this.authService.refreshToken();\n }\n });\n effect(() => {\n if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {\n if (this.authService.userConnected() === null) {\n this.authGoogleService.loginWithGoogle();\n } else {\n this.callbackInitMember.emit(this.authService.userConnected()?.user?.id);\n }\n }\n });\n }\n\n logout() {\n this.authService.logout();\n this.callbackLogout.emit();\n }\n}\n","<div class=\"auth-button\">\n <button\n id=\"google-signin-button\"\n [class.hidden]=\"authService.userConnected() !== null\"\n ></button>\n</div>\n\n@if (authService.userConnected()) {\n <div class=\"profile\">\n <img\n [src]=\"authService.userConnected()?.user?.avatar\"\n alt=\"profile\"\n />\n <dsv-modal-button\n id=\"logout\"\n icon=\"ri-logout-box-line\"\n />\n </div>\n <dsv-modal-alert\n id=\"logout\"\n title=\"Déconnexion\"\n text=\"Voulez-vous vraiment vous déconnecter ?\"\n button=\"Oui\"\n buttonClose=\"Non\"\n (callback)=\"logout()\"\n ></dsv-modal-alert>\n}\n","import { inject } from '@angular/core';\nimport { ActivatedRouteSnapshot, CanActivateFn, Router } from '@angular/router';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { AuthService, hasRole } from '../public-api';\n\nexport const authGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => {\n const platformService = inject(PlatformService);\n\n if (!platformService.isPlatformBrowser()) {\n return true;\n }\n\n const authService = inject(AuthService);\n const router = inject(Router);\n\n const requiredRole = route.data['role'];\n\n if (!requiredRole) {\n console.warn('No role specified in route data.');\n return false;\n }\n\n const profiles = authService.userConnected()?.user?.profiles;\n if (hasRole(requiredRole, profiles)) {\n return true;\n }\n\n router.navigate(['/']);\n return false;\n};\n","import { HttpClient, HttpErrorResponse, HttpHandlerFn, HttpRequest } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';\nimport { catchError, switchMap, throwError } from 'rxjs';\nimport { AuthService } from '../public-api';\n\nexport const authInterceptor = (req: HttpRequest<unknown>, next: HttpHandlerFn) => {\n const httpClient = inject(HttpClient);\n const authService = inject(AuthService);\n const toastService = inject(ToastService);\n\n return next(getToken(req, authService)).pipe(\n catchError((error) => {\n if (\n error instanceof HttpErrorResponse &&\n !req.url.includes('auth/') &&\n req.url.includes(authService.apiService.baseUrl) &&\n error.status === 401\n ) {\n return handle401Error(httpClient, authService, req, next);\n }\n\n console.error(error);\n\n toastService.showToast({\n type: 'error',\n text: error.error.debugMessage ?? error.error.message ?? error.message,\n });\n\n return throwError(() => error);\n }),\n );\n};\n\nconst getToken = <T>(req: HttpRequest<T>, authService: AuthService) => {\n const jwt = authService.userToken();\n if (!req.url.includes('/auth/') && req.url.includes(authService.apiService.baseUrl) && jwt) {\n const headers = req.headers.set('Authorization', `Bearer ${jwt}`);\n\n return req.clone({\n headers,\n });\n }\n return req;\n};\n\nconst handle401Error = <T>(\n httpClient: HttpClient,\n authService: AuthService,\n request: HttpRequest<T>,\n next: HttpHandlerFn,\n) => {\n return httpClient\n .post(authService.apiService.baseUrl + '/auth/refresh-token', {}, { withCredentials: true })\n .pipe(\n switchMap((response) => {\n authService.initUser(response);\n return next(getToken(request, authService));\n }),\n );\n};\n","import { effect, inject, Injectable, signal } from '@angular/core';\nimport { ApiService, JSONObject } from '@ng-vagabond-lab/ng-dsv/api';\nimport { UserConnectedDto } from '../dto/user.dto';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthService {\n apiService = inject(ApiService);\n\n userConnected = signal<UserConnectedDto | null>(null);\n userToken = signal<string>('');\n\n constructor() {\n effect(() => {\n this.userConnected.set(this.apiService.userConnected() as UserConnectedDto);\n });\n }\n\n initUser(user: UserConnectedDto | null = null) {\n this.userConnected.set(user);\n this.userToken.set(user?.['jwt' as keyof JSONObject] ?? '');\n }\n\n googleLogin(credential: string) {\n this.apiService.post<UserConnectedDto>(\n 'auth/google-identity-connect',\n {\n googleToken: credential,\n },\n (data) => {\n this.apiService.initUser(data as JSONObject);\n this.apiService.toastService.showToast({\n type: 'success',\n text: 'Connexion réussie',\n });\n },\n true,\n );\n }\n\n refreshToken() {\n this.apiService.post<UserConnectedDto>('auth/refresh-token', {}, (data) => this.initUser(data), true);\n }\n\n logout() {\n this.apiService.post<UserConnectedDto>(\n 'auth/logout',\n {},\n () => {\n this.apiService.initUser();\n this.apiService.toastService.showToast({\n type: 'success',\n text: 'Déconnexion réussie',\n });\n },\n true,\n );\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';\nimport { AuthService } from './auth.service';\n\ndeclare const google: any;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthGoogleService {\n private readonly authService = inject(AuthService);\n private readonly environmentService = inject(EnvironmentService);\n\n initGoogleAuth(googleButtonid: string = 'google-signin-button') {\n google.accounts.id.initialize({\n client_id: this.environmentService.env()?.GOOGLE_CLIENT_ID,\n callback: this.handleCredentialResponse.bind(this),\n });\n google.accounts.id.renderButton(document.getElementById(googleButtonid)!, {\n theme: 'outline',\n size: 'medium',\n type: 'icon',\n });\n }\n\n handleCredentialResponse(response: { credential: string }) {\n this.authService.googleLogin(response.credential);\n }\n\n loginWithGoogle() {\n google.accounts.id.prompt();\n }\n}\n","import { ApiDto } from '@ng-vagabond-lab/ng-dsv/api';\n\nexport const hasRole = (roles: string, userRoles?: ApiDto[]) => {\n const roleSplit = roles.split(',');\n let find = false;\n roleSplit.forEach((role) => {\n if (\n userRoles?.find(\n (userRole) =>\n userRole['roles' as keyof ApiDto]?.toString().includes(role) ||\n userRole['name' as keyof ApiDto] === role,\n )\n ) {\n find = true;\n }\n });\n return find;\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;;MAca,aAAa,CAAA;AACb,IAAA,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACjC,IAAA,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAC7C,IAAA,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;AAC/C,IAAA,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;IAElD,kBAAkB,GAAG,MAAM,EAAM;IACjC,cAAc,GAAG,MAAM,EAAQ;AAE/B,IAAA,WAAA,GAAA;QACI,MAAM,CAAC,MAAK;AACR,YAAA,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,eAAe,CAAC,iBAAiB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,QAAQ,KACL,QAAQ,CAAC,OAAuB,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;AAC5D,YAAA,QAAQ,CAAC,MAAsB,CAAC,KAAK,IAAI,CAChD,EACH;YACE,IAAI,GAAG,IAAI;QACf;AACJ,IAAA,CAAC,CAAC;AACF,IAAA,OAAO,IAAI;AACf;;ACjBA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ng-vagabond-lab-ng-dsv-modules-auth.mjs","sources":["../../../projects/ng-dsv/modules/auth/component/auth.component.ts","../../../projects/ng-dsv/modules/auth/component/auth.component.html","../../../projects/ng-dsv/modules/auth/guard/auth.guard.ts","../../../projects/ng-dsv/modules/auth/interceptor/auth.interceptor.ts","../../../projects/ng-dsv/modules/auth/service/auth.service.ts","../../../projects/ng-dsv/modules/auth/service/auth.google.service.ts","../../../projects/ng-dsv/modules/auth/utils/auth.utils.ts","../../../projects/ng-dsv/modules/auth/ng-vagabond-lab-ng-dsv-modules-auth.ts"],"sourcesContent":["import { CommonModule } from '@angular/common';\nimport { Component, effect, inject, output } from '@angular/core';\nimport { ID } from '@ng-vagabond-lab/ng-dsv/api';\nimport { ModalAlertComponent, ModalButtonComponent } from '@ng-vagabond-lab/ng-dsv/ds/modal';\nimport { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { AuthGoogleService, AuthService } from '../public-api';\n\n@Component({\n selector: 'dsv-auth',\n imports: [CommonModule, ModalButtonComponent, ModalAlertComponent],\n templateUrl: './auth.component.html',\n styleUrls: ['./auth.component.scss'],\n})\nexport class AuthComponent {\n readonly authService = inject(AuthService);\n readonly authGoogleService = inject(AuthGoogleService);\n readonly environmentService = inject(EnvironmentService);\n readonly platformService = inject(PlatformService);\n\n callbackInitMember = output<ID>();\n callbackLogout = output<void>();\n\n constructor() {\n effect(() => {\n if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {\n this.authGoogleService.initGoogleAuth();\n this.authService.refreshToken();\n }\n });\n effect(() => {\n if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {\n if (this.authService.userConnected() === null) {\n this.authGoogleService.loginWithGoogle();\n } else {\n this.callbackInitMember.emit(this.authService.userConnected()?.user?.id);\n }\n }\n });\n }\n\n logout() {\n this.authService.logout();\n this.callbackLogout.emit();\n }\n}\n","<div class=\"auth-button\">\n <button\n id=\"google-signin-button\"\n [class.hidden]=\"authService.userConnected() !== null\"\n ></button>\n</div>\n\n@if (authService.userConnected()) {\n <div class=\"profile\">\n <img\n [src]=\"authService.userConnected()?.user?.avatar\"\n alt=\"profile\"\n />\n <dsv-modal-button\n id=\"logout\"\n icon=\"ri-logout-box-line\"\n />\n </div>\n <dsv-modal-alert\n id=\"logout\"\n title=\"Déconnexion\"\n text=\"Voulez-vous vraiment vous déconnecter ?\"\n button=\"Oui\"\n buttonClose=\"Non\"\n (callback)=\"logout()\"\n ></dsv-modal-alert>\n}\n","import { inject } from '@angular/core';\nimport { ActivatedRouteSnapshot, CanActivateFn, Router } from '@angular/router';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { AuthService, hasRole } from '../public-api';\n\nexport const authGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => {\n const platformService = inject(PlatformService);\n\n if (!platformService.isPlatformBrowser()) {\n return true;\n }\n\n const authService = inject(AuthService);\n const router = inject(Router);\n\n const requiredRole = route.data['role'];\n\n if (!requiredRole) {\n console.warn('No role specified in route data.');\n return false;\n }\n\n const profiles = authService.userConnected()?.user?.profiles;\n if (hasRole(requiredRole, profiles)) {\n return true;\n }\n\n router.navigate(['/']);\n return false;\n};\n","import { HttpClient, HttpErrorResponse, HttpHandlerFn, HttpRequest } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';\nimport { catchError, switchMap, throwError } from 'rxjs';\nimport { AuthService } from '../public-api';\n\nexport const authInterceptor = (req: HttpRequest<unknown>, next: HttpHandlerFn) => {\n const httpClient = inject(HttpClient);\n const authService = inject(AuthService);\n const toastService = inject(ToastService);\n\n return next(getToken(req, authService)).pipe(\n catchError((error) => {\n if (\n error instanceof HttpErrorResponse &&\n !req.url.includes('auth/') &&\n req.url.includes(authService.apiService.baseUrl) &&\n error.status === 401\n ) {\n return handle401Error(httpClient, authService, req, next);\n }\n\n console.error(error);\n\n toastService.showToast({\n type: 'error',\n text: error.error.debugMessage ?? error.error.message ?? error.message,\n });\n\n return throwError(() => error);\n }),\n );\n};\n\nconst getToken = <T>(req: HttpRequest<T>, authService: AuthService) => {\n const jwt = authService.userToken();\n if (!req.url.includes('/auth/') && req.url.includes(authService.apiService.baseUrl) && jwt) {\n const headers = req.headers.set('Authorization', `Bearer ${jwt}`);\n\n return req.clone({\n headers,\n });\n }\n return req;\n};\n\nconst handle401Error = <T>(\n httpClient: HttpClient,\n authService: AuthService,\n request: HttpRequest<T>,\n next: HttpHandlerFn,\n) => {\n return httpClient\n .post(authService.apiService.baseUrl + '/auth/refresh-token', {}, { withCredentials: true })\n .pipe(\n switchMap((response) => {\n authService.initUser(response);\n return next(getToken(request, authService));\n }),\n );\n};\n","import { inject, Injectable, signal } from '@angular/core';\nimport { ApiService, JSONObject } from '@ng-vagabond-lab/ng-dsv/api';\nimport { UserConnectedDto } from '../dto/user.dto';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthService {\n apiService = inject(ApiService);\n\n userConnected = signal<UserConnectedDto | null>(null);\n userToken = signal<string>('');\n\n initUser(user: UserConnectedDto | null = null) {\n this.userConnected.set(user);\n this.userToken.set(user?.['jwt' as keyof JSONObject] ?? '');\n }\n\n googleLogin(credential: string) {\n this.apiService.post<UserConnectedDto>(\n 'auth/google-identity-connect',\n {\n googleToken: credential,\n },\n (data) => {\n this.initUser(data);\n this.apiService.toastService.showToast({\n type: 'success',\n text: 'Connexion réussie',\n });\n },\n true,\n );\n }\n\n refreshToken() {\n this.apiService.post<UserConnectedDto>('auth/refresh-token', {}, (data) => this.initUser(data), true);\n }\n\n logout() {\n this.apiService.post<UserConnectedDto>(\n 'auth/logout',\n {},\n () => {\n this.initUser();\n this.apiService.toastService.showToast({\n type: 'success',\n text: 'Déconnexion réussie',\n });\n },\n true,\n );\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';\nimport { AuthService } from './auth.service';\n\ndeclare const google: any;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthGoogleService {\n private readonly authService = inject(AuthService);\n private readonly environmentService = inject(EnvironmentService);\n\n initGoogleAuth(googleButtonid: string = 'google-signin-button') {\n google.accounts.id.initialize({\n client_id: this.environmentService.env()?.GOOGLE_CLIENT_ID,\n callback: this.handleCredentialResponse.bind(this),\n });\n google.accounts.id.renderButton(document.getElementById(googleButtonid)!, {\n theme: 'outline',\n size: 'medium',\n type: 'icon',\n });\n }\n\n handleCredentialResponse(response: { credential: string }) {\n this.authService.googleLogin(response.credential);\n }\n\n loginWithGoogle() {\n google.accounts.id.prompt();\n }\n}\n","import { ApiDto } from '@ng-vagabond-lab/ng-dsv/api';\n\nexport const hasRole = (roles: string, userRoles?: ApiDto[]) => {\n const roleSplit = roles.split(',');\n let find = false;\n roleSplit.forEach((role) => {\n if (\n userRoles?.find(\n (userRole) =>\n userRole['roles' as keyof ApiDto]?.toString().includes(role) ||\n userRole['name' as keyof ApiDto] === role,\n )\n ) {\n find = true;\n }\n });\n return find;\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;;MAca,aAAa,CAAA;AACb,IAAA,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACjC,IAAA,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAC7C,IAAA,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;AAC/C,IAAA,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;I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C,QAAQ,KACL,QAAQ,CAAC,OAAuB,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;AAC5D,YAAA,QAAQ,CAAC,MAAsB,CAAC,KAAK,IAAI,CAChD,EACH;YACE,IAAI,GAAG,IAAI;QACf;AACJ,IAAA,CAAC,CAAC;AACF,IAAA,OAAO,IAAI;AACf;;ACjBA;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import * as rxjs from 'rxjs';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import * as _angular_common_http from '@angular/common/http';
|
|
4
|
-
import { HttpRequest, HttpHandlerFn, HttpClient } from '@angular/common/http';
|
|
5
1
|
import * as _angular_core from '@angular/core';
|
|
6
2
|
import { ResourceRef } from '@angular/core';
|
|
3
|
+
import { HttpClient } from '@angular/common/http';
|
|
7
4
|
import { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';
|
|
8
5
|
import { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
9
7
|
import { Store } from '@ng-vagabond-lab/ng-dsv/storage';
|
|
10
8
|
|
|
11
9
|
type ID = string | number | undefined | null;
|
|
@@ -68,8 +66,6 @@ interface PageableDto<T> {
|
|
|
68
66
|
empty?: boolean;
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
declare const authInterceptor: (req: HttpRequest<unknown>, next: HttpHandlerFn) => rxjs.Observable<_angular_common_http.HttpEvent<unknown>>;
|
|
72
|
-
|
|
73
69
|
interface ApiFindBy {
|
|
74
70
|
endPoint?: string;
|
|
75
71
|
fields?: string;
|
|
@@ -90,12 +86,9 @@ declare class ApiService {
|
|
|
90
86
|
readonly httpClient: HttpClient;
|
|
91
87
|
readonly toastService: ToastService;
|
|
92
88
|
readonly platformService: PlatformService;
|
|
93
|
-
userConnected: _angular_core.WritableSignal<JSONObject | null>;
|
|
94
|
-
userToken: _angular_core.WritableSignal<string>;
|
|
95
89
|
load: _angular_core.WritableSignal<boolean>;
|
|
96
90
|
baseUrl: string;
|
|
97
91
|
setBaseUrl(url: string): void;
|
|
98
|
-
initUser(user?: JSONObject | null): void;
|
|
99
92
|
get<T>(url: string, callback: (data: T) => void): void;
|
|
100
93
|
post<T>(url: string, data: T, callback: (data: T) => void, withCredentials?: boolean): void;
|
|
101
94
|
put<T>(url: string, data: T, callback: (data: T) => void): void;
|
|
@@ -126,5 +119,5 @@ declare abstract class BaseSearchService<T> {
|
|
|
126
119
|
static ɵprov: _angular_core.ɵɵInjectableDeclaration<BaseSearchService<any>>;
|
|
127
120
|
}
|
|
128
121
|
|
|
129
|
-
export { ApiResourceService, ApiService, BaseSearchService
|
|
122
|
+
export { ApiResourceService, ApiService, BaseSearchService };
|
|
130
123
|
export type { ApiDto, ApiFindBy, BaseUserConnectedDto, ID, JSON, JSONObject, JSONValue, OrderState, PageableDto, Primitif, Target };
|
|
@@ -57,7 +57,6 @@ declare class AuthService {
|
|
|
57
57
|
apiService: ApiService;
|
|
58
58
|
userConnected: i0.WritableSignal<UserConnectedDto | null>;
|
|
59
59
|
userToken: i0.WritableSignal<string>;
|
|
60
|
-
constructor();
|
|
61
60
|
initUser(user?: UserConnectedDto | null): void;
|
|
62
61
|
googleLogin(credential: string): void;
|
|
63
62
|
refreshToken(): void;
|