@experteam-mx/ngx-services 0.1.1 → 15.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.
- package/esm2020/lib/apis/api-companies.service.mjs +255 -0
- package/esm2020/lib/apis/api-security.service.mjs +53 -53
- package/esm2020/lib/apis/models/api-catalog.interfaces.mjs +2 -0
- package/esm2020/lib/apis/models/api-companies.interfaces.mjs +2 -0
- package/esm2020/lib/apis/models/api-companies.types.mjs +2 -0
- package/esm2020/lib/apis/models/api-security.interfaces.mjs +2 -0
- package/esm2020/lib/apis/models/api-security.types.mjs +2 -0
- package/esm2020/lib/apis/models/api.models.mjs +2 -0
- package/esm2020/lib/helpers/http.mjs +27 -6
- package/esm2020/lib/interceptors/api-token.interceptor.mjs +10 -6
- package/esm2020/lib/interceptors/http-caching.interceptor.mjs +38 -0
- package/esm2020/lib/ngx-services.models.mjs +1 -1
- package/esm2020/public-api.mjs +10 -3
- package/fesm2015/experteam-mx-ngx-services.mjs +445 -129
- package/fesm2015/experteam-mx-ngx-services.mjs.map +1 -1
- package/fesm2020/experteam-mx-ngx-services.mjs +438 -129
- package/fesm2020/experteam-mx-ngx-services.mjs.map +1 -1
- package/lib/apis/api-companies.service.d.ts +163 -0
- package/lib/apis/api-security.service.d.ts +37 -37
- package/lib/apis/models/api-catalog.interfaces.d.ts +71 -0
- package/lib/apis/models/api-companies.interfaces.d.ts +380 -0
- package/lib/apis/models/api-companies.types.d.ts +75 -0
- package/lib/apis/{api-security.models.d.ts → models/api-security.interfaces.d.ts} +3 -38
- package/lib/apis/models/api-security.types.d.ts +30 -0
- package/lib/apis/{api.models.d.ts → models/api.models.d.ts} +3 -11
- package/lib/helpers/http.d.ts +11 -4
- package/lib/interceptors/api-token.interceptor.d.ts +3 -1
- package/lib/interceptors/http-caching.interceptor.d.ts +12 -0
- package/lib/ngx-services.models.d.ts +2 -0
- package/package.json +3 -2
- package/public-api.d.ts +8 -2
- package/esm2020/experteam-ngx-services.mjs +0 -5
- package/esm2020/lib/apis/api-catalog.models.mjs +0 -2
- package/esm2020/lib/apis/api-security.models.mjs +0 -2
- package/esm2020/lib/apis/api.models.mjs +0 -2
- package/fesm2015/experteam-ngx-services.mjs +0 -283
- package/fesm2015/experteam-ngx-services.mjs.map +0 -1
- package/fesm2020/experteam-ngx-services.mjs +0 -280
- package/fesm2020/experteam-ngx-services.mjs.map +0 -1
- package/lib/apis/api-catalog.models.d.ts +0 -5
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { NgModule, Injectable, Inject } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/common/http';
|
|
4
|
-
import { HttpClientModule, HttpHeaders } from '@angular/common/http';
|
|
5
|
-
import { map, tap } from 'rxjs';
|
|
6
|
-
import * as
|
|
4
|
+
import { HttpClientModule, HttpParams, HttpHeaders, HttpResponse } from '@angular/common/http';
|
|
5
|
+
import { map, mergeMap, forkJoin, tap, of } from 'rxjs';
|
|
6
|
+
import * as i1$1 from 'ngx-cookie-service';
|
|
7
|
+
import { tap as tap$1 } from 'rxjs/operators';
|
|
7
8
|
|
|
8
9
|
class NgxServicesModule {
|
|
9
10
|
/**
|
|
@@ -39,62 +40,378 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
39
40
|
}]
|
|
40
41
|
}] });
|
|
41
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Convert an object of key-value pairs into a URL query string.
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} params - The key-value pairs to converted into a query string.
|
|
47
|
+
*
|
|
48
|
+
* @return {string} - The generated query string.
|
|
49
|
+
*/
|
|
50
|
+
const queryString = (params) => {
|
|
51
|
+
let queryElements = [];
|
|
52
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
53
|
+
if (Array.isArray(value)) {
|
|
54
|
+
const arrayQuery = value
|
|
55
|
+
.map((item) => `${encodeURIComponent(key)}=${encodeURIComponent(item)}`)
|
|
56
|
+
.join('&');
|
|
57
|
+
queryElements.push(arrayQuery);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const encodedQuery = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
61
|
+
queryElements.push(encodedQuery);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const queryString = queryElements.join('&');
|
|
65
|
+
return queryString.length ? `?${queryString}` : '';
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Creates an instance of HttpParams using the provided params object.
|
|
69
|
+
*
|
|
70
|
+
* @param {Object} params - The object containing the params to the HttpParams constructor.
|
|
71
|
+
*
|
|
72
|
+
* @returns {HttpParams} - An instance of HttpParams created from the params object.
|
|
73
|
+
*/
|
|
74
|
+
const httpParams = (params) => new HttpParams({
|
|
75
|
+
fromObject: params
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Returns the headers for generating PDF files.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} format - The format of the headers, 'object' or 'http_header'.
|
|
81
|
+
*
|
|
82
|
+
* @returns {HttpHeaders | { [header: string]: string | string[] }} - The headers for generating PDF files.
|
|
83
|
+
*/
|
|
84
|
+
const pdfHeaders = (format = 'object') => {
|
|
85
|
+
const headers = {
|
|
86
|
+
'Accept': 'application/pdf'
|
|
87
|
+
};
|
|
88
|
+
return format === 'object'
|
|
89
|
+
? headers
|
|
90
|
+
: new HttpHeaders(headers);
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Returns the headers for generating XML files.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} format - The format of the headers, 'object' or 'http_header'.
|
|
96
|
+
*
|
|
97
|
+
* @returns {HttpHeaders | { [header: string]: string | string[] }} - The headers for generating XML files.
|
|
98
|
+
*/
|
|
99
|
+
const xmlHeaders = (format = 'object') => {
|
|
100
|
+
const headers = {
|
|
101
|
+
'Accept': 'application/xml',
|
|
102
|
+
};
|
|
103
|
+
return format === 'object'
|
|
104
|
+
? headers
|
|
105
|
+
: new HttpHeaders(headers);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
class ApiCompaniesService {
|
|
109
|
+
constructor(environments, http) {
|
|
110
|
+
this.environments = environments;
|
|
111
|
+
this.http = http;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves the URL for the companies API from the environment configurations.
|
|
115
|
+
*
|
|
116
|
+
* @return {string} The URL of the companies API.
|
|
117
|
+
*/
|
|
118
|
+
get url() {
|
|
119
|
+
return this.environments.apiCompaniesUrl;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Fetches the installations based on the provided query parameters.
|
|
123
|
+
*
|
|
124
|
+
* @param {QueryParams} params - The parameters used to filter the installations query.
|
|
125
|
+
* @return {Observable<InstallationsData>} An observable that emits the installations data.
|
|
126
|
+
*/
|
|
127
|
+
getInstallations(params) {
|
|
128
|
+
return this.http.get(`${this.url}/installations`, {
|
|
129
|
+
params: httpParams(params),
|
|
130
|
+
}).pipe(map(({ data }) => data));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves the installation details based on the given installation ID.
|
|
134
|
+
*
|
|
135
|
+
* @param {number} id - The unique identifier of the installation to retrieve.
|
|
136
|
+
* @returns {Observable<InstallationData>} An observable of the installation details.
|
|
137
|
+
*/
|
|
138
|
+
getInstallation(id) {
|
|
139
|
+
return this.http.get(`${this.url}/installations/${id}`)
|
|
140
|
+
.pipe(map(({ data }) => data));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves a list of locations based on the provided query parameters.
|
|
144
|
+
*
|
|
145
|
+
* @param {QueryParams} params - The parameters to use for querying locations.
|
|
146
|
+
* @return {Observable<LocationsData>} An observable that emits the locations data.
|
|
147
|
+
*/
|
|
148
|
+
getLocations(params) {
|
|
149
|
+
return this.http.get(`${this.url}/locations`, {
|
|
150
|
+
params: httpParams(params),
|
|
151
|
+
}).pipe(map(({ data }) => data));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Fetches the location details for a given location ID.
|
|
155
|
+
*
|
|
156
|
+
* @param {number} id - The unique identifier of the location.
|
|
157
|
+
* @return {Observable<LocationData>} An Observable containing the location details.
|
|
158
|
+
*/
|
|
159
|
+
getLocation(id) {
|
|
160
|
+
return this.http.get(`${this.url}/locations/${id}`)
|
|
161
|
+
.pipe(map(({ data }) => data));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Retrieves a list of active supply entities.
|
|
165
|
+
*
|
|
166
|
+
* @param {QueryParams} params - The query parameters to filter supply entities.
|
|
167
|
+
* @return {Observable<SupplyEntitiesData>} Observable emitting supply entities data.
|
|
168
|
+
*/
|
|
169
|
+
getSupplyEntitiesActive(params) {
|
|
170
|
+
return this.http.get(`${this.url}/supply-entities/actives`, {
|
|
171
|
+
params: httpParams(params),
|
|
172
|
+
}).pipe(map(({ data }) => data));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Fetches a list of employees based on the specified query parameters.
|
|
176
|
+
*
|
|
177
|
+
* @param {QueryParams} params - The parameters to filter and sort the employees.
|
|
178
|
+
* @return {Observable<EmployeesData>} An observable that emits the list of employees.
|
|
179
|
+
*/
|
|
180
|
+
getEmployees(params) {
|
|
181
|
+
return this.http.get(`${this.url}/employees`, {
|
|
182
|
+
params: httpParams(params),
|
|
183
|
+
}).pipe(map(({ data }) => data));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Fetches an employee's details based on the provided employee ID.
|
|
187
|
+
*
|
|
188
|
+
* @param {number} id - The unique identifier of the employee.
|
|
189
|
+
* @return {Observable<EmployeeData>} An observable that emits the employee's details.
|
|
190
|
+
*/
|
|
191
|
+
getEmployee(id) {
|
|
192
|
+
return this.http.get(`${this.url}/employees/${id}`)
|
|
193
|
+
.pipe(map(({ data }) => data));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Retrieves the list of employees for a specified location based on provided query parameters.
|
|
197
|
+
*
|
|
198
|
+
* @param {QueryParams} params - The query parameters used to filter and retrieve the location employees.
|
|
199
|
+
* @returns {Observable<LocationEmployeesData>} An observable that emits the list of employees for the specified location.
|
|
200
|
+
*/
|
|
201
|
+
getLocationEmployees(params) {
|
|
202
|
+
return this.http.get(`${this.url}/location-employees`, {
|
|
203
|
+
params: httpParams(params),
|
|
204
|
+
}).pipe(map(({ data }) => data));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Retrieves a list of countries where the company operates.
|
|
208
|
+
*
|
|
209
|
+
* @param {QueryParams} params - The query parameters for the API request.
|
|
210
|
+
* @return {Observable<CompanyCountriesData>} An observable containing the list of company countries.
|
|
211
|
+
*/
|
|
212
|
+
getCompanyCountries(params) {
|
|
213
|
+
return this.http.get(`${this.url}/company-countries`, {
|
|
214
|
+
params: httpParams(params),
|
|
215
|
+
}).pipe(map(({ data }) => data));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Retrieves the country information for a specified company by its ID.
|
|
219
|
+
*
|
|
220
|
+
* @param {number} id - The unique identifier of the company.
|
|
221
|
+
* @return {Observable<CompanyCountryData>} An observable containing the country information of the company.
|
|
222
|
+
*/
|
|
223
|
+
getCompanyCountry(id) {
|
|
224
|
+
return this.http.get(`${this.url}/company-countries/${id}`)
|
|
225
|
+
.pipe(map(({ data }) => data));
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Fetches the reference currencies for a given country.
|
|
229
|
+
*
|
|
230
|
+
* @param {QueryParams} params - The query parameters to include in the request.
|
|
231
|
+
* @return {Observable<CountryReferenceCurrenciesData>} The observable containing the country reference currencies data.
|
|
232
|
+
*/
|
|
233
|
+
getCountryReferenceCurrencies(params) {
|
|
234
|
+
return this.http.get(`${this.url}/country-reference-currencies`, { params }).pipe(map(({ data }) => data));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Retrieves a list of currencies for different countries along with their current exchange rates.
|
|
238
|
+
*
|
|
239
|
+
* @param {QueryParams} params - The query parameters used to fetch the country reference currencies.
|
|
240
|
+
* @return {Observable<CountryCurrencyRate[]>} An observable that emits an array of country currency rates.
|
|
241
|
+
*/
|
|
242
|
+
getCountryCurrenciesWithRate(params) {
|
|
243
|
+
return this.getCountryReferenceCurrencies(params)
|
|
244
|
+
.pipe(mergeMap((currenciesData) => {
|
|
245
|
+
const $observables = currenciesData.country_reference_currencies
|
|
246
|
+
.map((country_reference_currency) => this.getCurrentExchanges({
|
|
247
|
+
currency_id: country_reference_currency.currency.id,
|
|
248
|
+
}).pipe(map((exchangesData) => ({
|
|
249
|
+
...country_reference_currency,
|
|
250
|
+
rate: exchangesData.exchanges[0]?.value ?? 1.00,
|
|
251
|
+
}))));
|
|
252
|
+
return forkJoin($observables);
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Retrieves the current exchanges based on the given query parameters.
|
|
257
|
+
*
|
|
258
|
+
* @param {QueryParams} params - The query parameters to filter the exchanges.
|
|
259
|
+
*
|
|
260
|
+
* @returns {Observable<ExchangesData>} - An observable that emits the API response data containing the current exchanges.
|
|
261
|
+
*/
|
|
262
|
+
getCurrentExchanges(params) {
|
|
263
|
+
return this.http.get(`${this.url}/exchanges/current`, {
|
|
264
|
+
params: httpParams(params),
|
|
265
|
+
}).pipe(map(({ data }) => data));
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Fetches the country-specific tax information for a company.
|
|
269
|
+
*
|
|
270
|
+
* @param {QueryParams} params - The parameters used to filter and query the taxes.
|
|
271
|
+
* @return {Observable<CompanyCountryTaxesData>} An observable that emits the tax information.
|
|
272
|
+
*/
|
|
273
|
+
getCompanyCountryTaxes(params) {
|
|
274
|
+
return this.http.get(`${this.url}/company-country-taxes`, {
|
|
275
|
+
params: httpParams(params),
|
|
276
|
+
}).pipe(map(({ data }) => data));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Retrieves the list of active account entities based on the provided query parameters.
|
|
280
|
+
*
|
|
281
|
+
* @param {QueryParams} params - The parameters to filter and query active account entities.
|
|
282
|
+
* @return {Observable<AccountEntitiesData>} An observable that emits the list of active account entities.
|
|
283
|
+
*/
|
|
284
|
+
getActiveAccountEntities(params) {
|
|
285
|
+
return this.http.get(`${this.url}/account-entities/actives`, {
|
|
286
|
+
params: httpParams(params),
|
|
287
|
+
}).pipe(map(({ data }) => data));
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Retrieves the parameter values based on the provided parameter names.
|
|
291
|
+
*
|
|
292
|
+
* @param {Object} params - An object containing the required parameters.
|
|
293
|
+
* @param {string[]} params.paramNames - An array of parameter names for which the values need to be fetched.
|
|
294
|
+
* @return {Observable<ParametersData>} An observable that emits the fetched parameter values.
|
|
295
|
+
*/
|
|
296
|
+
getParameters({ paramNames, }) {
|
|
297
|
+
const parameters = paramNames.map((p) => ({ name: p }));
|
|
298
|
+
return this.http.post(`${this.url}/parameters-values`, {
|
|
299
|
+
parameters
|
|
300
|
+
}).pipe(map(({ data }) => data));
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Retrieves the value of a specified parameter.
|
|
304
|
+
*
|
|
305
|
+
* @param {Object} input - The input object containing the parameter details.
|
|
306
|
+
* @param {string} input.paramName - The name of the parameter whose value is to be retrieved.
|
|
307
|
+
* @return {Observable<ParameterValueData>} An observable emitting the value of the specified parameter.
|
|
308
|
+
*/
|
|
309
|
+
getParameterValue({ paramName, }) {
|
|
310
|
+
return this.http.get(`${this.url}/parameters-values/${paramName}`)
|
|
311
|
+
.pipe(map(({ data }) => data));
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Retrieves a list of country references based on the given query parameters.
|
|
315
|
+
*
|
|
316
|
+
* @param {QueryParams} params - The query parameters for retrieving country references.
|
|
317
|
+
* @return {Observable<CountryReferencesData>} An observable containing the country reference data.
|
|
318
|
+
*/
|
|
319
|
+
getCountryReferences(params) {
|
|
320
|
+
return this.http.get(`${this.url}/country-references`, {
|
|
321
|
+
params: httpParams(params),
|
|
322
|
+
}).pipe(map(({ data }) => data));
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Fetches the country reference data for a given country ID.
|
|
326
|
+
*
|
|
327
|
+
* @param {number} id - The unique identifier of the country for which the reference data is to be retrieved.
|
|
328
|
+
* @return {Observable<CountryReferenceData>} An observable containing the country reference data.
|
|
329
|
+
*/
|
|
330
|
+
getCountryReference(id) {
|
|
331
|
+
return this.http.get(`${this.url}/country-references/${id}`)
|
|
332
|
+
.pipe(map(({ data }) => data));
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Fetches the list of workflows based on the provided query parameters.
|
|
336
|
+
*
|
|
337
|
+
* @param {QueryParams} params - The query parameters used to filter workflows.
|
|
338
|
+
* @return {Observable<WorkflowsData>} An observable containing the workflow data.
|
|
339
|
+
*/
|
|
340
|
+
getWorkflows(params) {
|
|
341
|
+
return this.http.get(`${this.url}/workflows`, {
|
|
342
|
+
params: httpParams(params),
|
|
343
|
+
}).pipe(map(({ data }) => data));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
ApiCompaniesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiCompaniesService, deps: [{ token: 'env' }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
347
|
+
ApiCompaniesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiCompaniesService, providedIn: 'root' });
|
|
348
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiCompaniesService, decorators: [{
|
|
349
|
+
type: Injectable,
|
|
350
|
+
args: [{
|
|
351
|
+
providedIn: 'root'
|
|
352
|
+
}]
|
|
353
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
354
|
+
type: Inject,
|
|
355
|
+
args: ['env']
|
|
356
|
+
}] }, { type: i1.HttpClient }]; } });
|
|
357
|
+
|
|
42
358
|
class ApiSecurityService {
|
|
43
|
-
constructor(environments,
|
|
359
|
+
constructor(environments, cookie, http) {
|
|
44
360
|
this.environments = environments;
|
|
45
|
-
this.httpClient = httpClient;
|
|
46
361
|
this.cookie = cookie;
|
|
362
|
+
this.http = http;
|
|
47
363
|
}
|
|
48
364
|
/**
|
|
49
|
-
* Retrieves the API security URL.
|
|
365
|
+
* Retrieves the API security URL from the environments configuration.
|
|
50
366
|
*
|
|
51
|
-
* @
|
|
367
|
+
* @return {string} The API security URL.
|
|
52
368
|
*/
|
|
53
369
|
get url() {
|
|
54
370
|
return this.environments.apiSecurityUrl;
|
|
55
371
|
}
|
|
56
372
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @param {object} loginParams - The login parameters.
|
|
60
|
-
* @param {string} loginParams.username - The username of the user.
|
|
61
|
-
* @param {string} loginParams.password - The password of the user.
|
|
62
|
-
* @param {string} loginParams.role - The role of the user.
|
|
373
|
+
* Authenticates a user with the provided credentials and role.
|
|
63
374
|
*
|
|
64
|
-
* @
|
|
375
|
+
* @param {Object} param0 - The login input object.
|
|
376
|
+
* @param {string} param0.username - The username of the user.
|
|
377
|
+
* @param {string} param0.password - The password of the user.
|
|
378
|
+
* @param {string} param0.role - The role of the user.
|
|
379
|
+
* @return {Observable<LoginOut>} An observable emitting the login output object.
|
|
65
380
|
*/
|
|
66
381
|
login({ username, password, role, }) {
|
|
67
|
-
return this.
|
|
382
|
+
return this.http.post(`${this.url}/auth/login`, {
|
|
68
383
|
system_name: 'CRA',
|
|
69
384
|
username,
|
|
70
385
|
password,
|
|
71
386
|
role,
|
|
72
|
-
}).pipe(map(({ data }) => data), tap(({ access_token }) => this.cookie.set(
|
|
387
|
+
}).pipe(map(({ data }) => data), tap(({ access_token }) => this.cookie.set(this.environments.tokenName, access_token, { path: '/' })));
|
|
73
388
|
}
|
|
74
389
|
/**
|
|
75
|
-
* Logs out the user
|
|
390
|
+
* Logs out the current user by making a POST request to the logout endpoint.
|
|
76
391
|
*
|
|
77
|
-
*
|
|
392
|
+
* This method deletes all cookies after a successful logout.
|
|
393
|
+
*
|
|
394
|
+
* @return {Observable<{}>} An observable that emits the server's response to the logout request.
|
|
78
395
|
*/
|
|
79
396
|
logout() {
|
|
80
|
-
return this.
|
|
397
|
+
return this.http.post(`${this.url}/auth/logout`, null)
|
|
81
398
|
.pipe(map(({ data }) => data), tap(() => this.cookie.deleteAll('/')));
|
|
82
399
|
}
|
|
83
400
|
/**
|
|
84
|
-
* Creates a session
|
|
401
|
+
* Creates a new session for a specified model.
|
|
85
402
|
*
|
|
86
|
-
* @param {
|
|
87
|
-
* @param {string}
|
|
88
|
-
* @param {string}
|
|
89
|
-
* @param {string}
|
|
403
|
+
* @param {Object} params - The parameters for creating the session.
|
|
404
|
+
* @param {string} params.modelType - The type of the model.
|
|
405
|
+
* @param {string} params.modelId - The ID of the model.
|
|
406
|
+
* @param {string} [params.token] - Optional authorization token.
|
|
90
407
|
*
|
|
91
|
-
* @return {Observable<CreateSessionOut>}
|
|
408
|
+
* @return {Observable<CreateSessionOut>} An observable containing the created session details.
|
|
92
409
|
*/
|
|
93
410
|
createSession({ modelType, modelId, token, }) {
|
|
94
411
|
let headers = new HttpHeaders({});
|
|
95
412
|
if (token)
|
|
96
413
|
headers = headers.set('Authorization', `Bearer ${token}`);
|
|
97
|
-
return this.
|
|
414
|
+
return this.http.post(`${this.url}/sessions`, {
|
|
98
415
|
model_type: modelType,
|
|
99
416
|
model_id: modelId,
|
|
100
417
|
}, {
|
|
@@ -102,54 +419,53 @@ class ApiSecurityService {
|
|
|
102
419
|
}).pipe(map(({ data }) => data));
|
|
103
420
|
}
|
|
104
421
|
/**
|
|
105
|
-
*
|
|
422
|
+
* Fetches the authenticated user's information.
|
|
423
|
+
* Sends a GET request to the endpoint '/auth/me' to retrieve information
|
|
424
|
+
* about the currently authenticated user.
|
|
106
425
|
*
|
|
107
|
-
* @
|
|
426
|
+
* @return {Observable<MeOut>} An observable that emits the authenticated user's data.
|
|
108
427
|
*/
|
|
109
428
|
me() {
|
|
110
|
-
return this.
|
|
429
|
+
return this.http.get(`${this.url}/auth/me`)
|
|
111
430
|
.pipe(map(({ data }) => data));
|
|
112
431
|
}
|
|
113
432
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* @param {GetUserIn} user - The user object containing the user ID.
|
|
433
|
+
* Fetches the authenticated user's details from the server.
|
|
117
434
|
*
|
|
118
|
-
* @
|
|
435
|
+
* @param token The JWT token used for authorization.
|
|
436
|
+
* @return An Observable that emits the user's details encapsulated in a MeOut object.
|
|
119
437
|
*/
|
|
120
|
-
|
|
121
|
-
return this.
|
|
122
|
-
.pipe(map(({ data }) => data));
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Get user information
|
|
126
|
-
*
|
|
127
|
-
* @param {string} token - The user's authentication token
|
|
128
|
-
*
|
|
129
|
-
* @return {Observable<MeOut>} - An observable that emits the user's information
|
|
130
|
-
*/
|
|
131
|
-
userInfo({ token }) {
|
|
132
|
-
return this.httpClient.get(`${this.url}/auth/me`, {
|
|
438
|
+
otherMe(token) {
|
|
439
|
+
return this.http.get(`${this.url}/auth/me`, {
|
|
133
440
|
headers: {
|
|
134
441
|
Authorization: `Bearer ${token}`
|
|
135
442
|
}
|
|
136
443
|
}).pipe(map(({ data }) => data));
|
|
137
444
|
}
|
|
138
445
|
/**
|
|
139
|
-
*
|
|
446
|
+
* Fetches a user by their unique ID.
|
|
140
447
|
*
|
|
141
|
-
* @param {
|
|
142
|
-
* @
|
|
448
|
+
* @param {number} id - The unique identifier of the user to be fetched.
|
|
449
|
+
* @return {Observable<GetUserOut>} An observable containing the user information.
|
|
450
|
+
*/
|
|
451
|
+
user(id) {
|
|
452
|
+
return this.http.get(`${this.url}/users/${id}`)
|
|
453
|
+
.pipe(map(({ data }) => data));
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Changes the language for the authenticated user.
|
|
143
457
|
*
|
|
144
|
-
* @
|
|
458
|
+
* @param {Object} params - The input parameters for changing the language.
|
|
459
|
+
* @param {string} params.languageId - The ID of the new language to be set.
|
|
460
|
+
* @return {Observable<ApiSuccess<MeOut>>} An observable that emits the result of the language change request.
|
|
145
461
|
*/
|
|
146
462
|
changeLanguage({ languageId }) {
|
|
147
|
-
return this.
|
|
463
|
+
return this.http.put(`${this.url}/auth/me`, {
|
|
148
464
|
language_id: languageId
|
|
149
465
|
}).pipe(map(({ data }) => data));
|
|
150
466
|
}
|
|
151
467
|
}
|
|
152
|
-
ApiSecurityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiSecurityService, deps: [{ token: 'env' }, { token: i1.
|
|
468
|
+
ApiSecurityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiSecurityService, deps: [{ token: 'env' }, { token: i1$1.CookieService }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
153
469
|
ApiSecurityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiSecurityService, providedIn: 'root' });
|
|
154
470
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiSecurityService, decorators: [{
|
|
155
471
|
type: Injectable,
|
|
@@ -159,39 +475,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
159
475
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
160
476
|
type: Inject,
|
|
161
477
|
args: ['env']
|
|
162
|
-
}] }, { type: i1.
|
|
163
|
-
|
|
164
|
-
class ApiTokenInterceptor {
|
|
165
|
-
constructor(cookie) {
|
|
166
|
-
this.cookie = cookie;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Intercepts the HTTP request and adds the Authorization header.
|
|
170
|
-
*
|
|
171
|
-
* @param {HttpRequest<unknown>} request - The HTTP request to intercept.
|
|
172
|
-
* @param {HttpHandler} next - The next HTTP handler in the chain.
|
|
173
|
-
*
|
|
174
|
-
* @returns {Observable<HttpEvent<unknown>>} - An observable containing the HTTP event.
|
|
175
|
-
*/
|
|
176
|
-
intercept(request, next) {
|
|
177
|
-
if (request.headers.has('Authorization'))
|
|
178
|
-
return next.handle(request);
|
|
179
|
-
const token = this.cookie.get('tokenCRA');
|
|
180
|
-
if (!token)
|
|
181
|
-
return next.handle(request);
|
|
182
|
-
request = request.clone({
|
|
183
|
-
setHeaders: {
|
|
184
|
-
Authorization: `Bearer ${token}`
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
return next.handle(request);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
ApiTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor, deps: [{ token: i2.CookieService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
191
|
-
ApiTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor });
|
|
192
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor, decorators: [{
|
|
193
|
-
type: Injectable
|
|
194
|
-
}], ctorParameters: function () { return [{ type: i2.CookieService }]; } });
|
|
478
|
+
}] }, { type: i1$1.CookieService }, { type: i1.HttpClient }]; } });
|
|
195
479
|
|
|
196
480
|
class ApiHeadersInterceptor {
|
|
197
481
|
/**
|
|
@@ -224,49 +508,74 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
224
508
|
type: Injectable
|
|
225
509
|
}] });
|
|
226
510
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
511
|
+
class ApiTokenInterceptor {
|
|
512
|
+
constructor(environments, cookie) {
|
|
513
|
+
this.environments = environments;
|
|
514
|
+
this.cookie = cookie;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Intercepts the HTTP request and adds the Authorization header.
|
|
518
|
+
*
|
|
519
|
+
* @param {HttpRequest<unknown>} request - The HTTP request to intercept.
|
|
520
|
+
* @param {HttpHandler} next - The next HTTP handler in the chain.
|
|
521
|
+
*
|
|
522
|
+
* @returns {Observable<HttpEvent<unknown>>} - An observable containing the HTTP event.
|
|
523
|
+
*/
|
|
524
|
+
intercept(request, next) {
|
|
525
|
+
if (request.headers.has('Authorization'))
|
|
526
|
+
return next.handle(request);
|
|
527
|
+
const token = this.cookie.get(this.environments.tokenName);
|
|
528
|
+
if (!token)
|
|
529
|
+
return next.handle(request);
|
|
530
|
+
request = request.clone({
|
|
531
|
+
setHeaders: {
|
|
532
|
+
Authorization: `Bearer ${token}`
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
return next.handle(request);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
ApiTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor, deps: [{ token: 'env' }, { token: i1$1.CookieService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
539
|
+
ApiTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor });
|
|
540
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor, decorators: [{
|
|
541
|
+
type: Injectable
|
|
542
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
543
|
+
type: Inject,
|
|
544
|
+
args: ['env']
|
|
545
|
+
}] }, { type: i1$1.CookieService }]; } });
|
|
546
|
+
|
|
547
|
+
const DEFAULT_TTL = 10000; // ttl in ms
|
|
548
|
+
class HttpCachingInterceptor {
|
|
549
|
+
constructor(envs) {
|
|
550
|
+
this.envs = envs;
|
|
551
|
+
this.cache = new Map();
|
|
552
|
+
}
|
|
553
|
+
intercept(req, next) {
|
|
554
|
+
if (req.method !== 'GET')
|
|
555
|
+
return next.handle(req);
|
|
556
|
+
const cached = this.cache.get(req.urlWithParams);
|
|
557
|
+
if (cached) {
|
|
558
|
+
const isExpired = Date.now() > cached.ttl;
|
|
559
|
+
if (!isExpired)
|
|
560
|
+
return of(cached.res);
|
|
561
|
+
this.cache.delete(req.urlWithParams); // If expired, remove the entry from cache
|
|
562
|
+
}
|
|
563
|
+
return next.handle(req).pipe(tap$1((res) => {
|
|
564
|
+
if (!(res instanceof HttpResponse))
|
|
565
|
+
return;
|
|
566
|
+
const ttl = Date.now() + (this.envs.cacheTtl ?? DEFAULT_TTL);
|
|
567
|
+
this.cache.set(req.urlWithParams, { res, ttl });
|
|
568
|
+
}));
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
HttpCachingInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor, deps: [{ token: 'env' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
572
|
+
HttpCachingInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor });
|
|
573
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor, decorators: [{
|
|
574
|
+
type: Injectable
|
|
575
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
576
|
+
type: Inject,
|
|
577
|
+
args: ['env']
|
|
578
|
+
}] }]; } });
|
|
270
579
|
|
|
271
580
|
/*
|
|
272
581
|
* Public API Surface of ngx-services
|
|
@@ -276,5 +585,5 @@ const xmlHeaders = (format = 'object') => {
|
|
|
276
585
|
* Generated bundle index. Do not edit.
|
|
277
586
|
*/
|
|
278
587
|
|
|
279
|
-
export { ApiHeadersInterceptor, ApiSecurityService, ApiTokenInterceptor, NgxServicesModule, pdfHeaders, queryString, xmlHeaders };
|
|
588
|
+
export { ApiCompaniesService, ApiHeadersInterceptor, ApiSecurityService, ApiTokenInterceptor, HttpCachingInterceptor, NgxServicesModule, httpParams, pdfHeaders, queryString, xmlHeaders };
|
|
280
589
|
//# sourceMappingURL=experteam-mx-ngx-services.mjs.map
|