1 | import * as i0 from '@angular/core';
|
2 | import { NgModule, Injectable } from '@angular/core';
|
3 | import * as i1 from '@angular/common/http';
|
4 | import { HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http';
|
5 | import { Observable, of, BehaviorSubject, throwError } from 'rxjs';
|
6 | import { catchError, switchMap, filter, take, map } from 'rxjs/operators';
|
7 |
|
8 | class AbpModule {
|
9 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
10 | static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.1", ngImport: i0, type: AbpModule });
|
11 | static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpModule });
|
12 | }
|
13 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpModule, decorators: [{
|
14 | type: NgModule,
|
15 | args: [{
|
16 | declarations: [],
|
17 | imports: [],
|
18 | exports: []
|
19 | }]
|
20 | }] });
|
21 |
|
22 |
|
23 |
|
24 | class TokenService {
|
25 | getToken() {
|
26 | return abp.auth.getToken();
|
27 | }
|
28 | getTokenCookieName() {
|
29 | return abp.auth.tokenCookieName;
|
30 | }
|
31 | clearToken() {
|
32 | abp.auth.clearToken();
|
33 | }
|
34 | setToken(authToken, expireDate) {
|
35 | abp.auth.setToken(authToken, expireDate);
|
36 | }
|
37 |
|
38 | getRefreshToken() {
|
39 | return abp.auth.getRefreshToken();
|
40 | }
|
41 | getRefreshTokenCookieName() {
|
42 | return abp.auth.refreshTokenCookieName;
|
43 | }
|
44 | clearRefreshToken() {
|
45 | abp.auth.clearRefreshToken();
|
46 | }
|
47 | setRefreshToken(refreshToken, expireDate) {
|
48 | abp.auth.setRefreshToken(refreshToken, expireDate);
|
49 | }
|
50 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: TokenService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
51 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: TokenService, providedIn: 'root' });
|
52 | }
|
53 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: TokenService, decorators: [{
|
54 | type: Injectable,
|
55 | args: [{
|
56 | providedIn: 'root'
|
57 | }]
|
58 | }] });
|
59 |
|
60 |
|
61 |
|
62 | class PermissionCheckerService {
|
63 | isGranted(permissionName) {
|
64 | return abp.auth.isGranted(permissionName);
|
65 | }
|
66 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: PermissionCheckerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
67 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: PermissionCheckerService, providedIn: 'root' });
|
68 | }
|
69 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: PermissionCheckerService, decorators: [{
|
70 | type: Injectable,
|
71 | args: [{
|
72 | providedIn: 'root'
|
73 | }]
|
74 | }] });
|
75 |
|
76 |
|
77 |
|
78 | class FeatureCheckerService {
|
79 | get(featureName) {
|
80 | return abp.features.get(featureName);
|
81 | }
|
82 | getValue(featureName) {
|
83 | return abp.features.getValue(featureName);
|
84 | }
|
85 | isEnabled(featureName) {
|
86 | return abp.features.isEnabled(featureName);
|
87 | }
|
88 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: FeatureCheckerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
89 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: FeatureCheckerService, providedIn: 'root' });
|
90 | }
|
91 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: FeatureCheckerService, decorators: [{
|
92 | type: Injectable,
|
93 | args: [{
|
94 | providedIn: 'root'
|
95 | }]
|
96 | }] });
|
97 |
|
98 |
|
99 |
|
100 | class LocalizationService {
|
101 | get languages() {
|
102 | return abp.localization.languages;
|
103 | }
|
104 | get currentLanguage() {
|
105 | return abp.localization.currentLanguage;
|
106 | }
|
107 | localize(key, sourceName) {
|
108 | return abp.localization.localize(key, sourceName);
|
109 | }
|
110 | getSource(sourceName) {
|
111 | return abp.localization.getSource(sourceName);
|
112 | }
|
113 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: LocalizationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
114 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: LocalizationService, providedIn: 'root' });
|
115 | }
|
116 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: LocalizationService, decorators: [{
|
117 | type: Injectable,
|
118 | args: [{
|
119 | providedIn: 'root'
|
120 | }]
|
121 | }] });
|
122 |
|
123 |
|
124 |
|
125 | class LogService {
|
126 | debug(logObject) {
|
127 | abp.log.debug(logObject);
|
128 | }
|
129 | info(logObject) {
|
130 | abp.log.info(logObject);
|
131 | }
|
132 | warn(logObject) {
|
133 | abp.log.warn(logObject);
|
134 | }
|
135 | error(logObject) {
|
136 | abp.log.error(logObject);
|
137 | }
|
138 | fatal(logObject) {
|
139 | abp.log.fatal(logObject);
|
140 | }
|
141 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: LogService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
142 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: LogService, providedIn: 'root' });
|
143 | }
|
144 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: LogService, decorators: [{
|
145 | type: Injectable,
|
146 | args: [{
|
147 | providedIn: 'root'
|
148 | }]
|
149 | }] });
|
150 |
|
151 |
|
152 |
|
153 | class MessageService {
|
154 | info(message, title, options) {
|
155 | return abp.message.info(message, title, options);
|
156 | }
|
157 | success(message, title, options) {
|
158 | return abp.message.success(message, title, options);
|
159 | }
|
160 | warn(message, title, options) {
|
161 | return abp.message.warn(message, title, options);
|
162 | }
|
163 | error(message, title, options) {
|
164 | return abp.message.error(message, title, options);
|
165 | }
|
166 | confirm(message, title, callback, options) {
|
167 | return abp.message.confirm(message, title, callback, options);
|
168 | }
|
169 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MessageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
170 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MessageService, providedIn: 'root' });
|
171 | }
|
172 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MessageService, decorators: [{
|
173 | type: Injectable,
|
174 | args: [{
|
175 | providedIn: 'root'
|
176 | }]
|
177 | }] });
|
178 |
|
179 |
|
180 |
|
181 | class AbpMultiTenancyService {
|
182 | get isEnabled() {
|
183 | return abp.multiTenancy.isEnabled;
|
184 | }
|
185 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpMultiTenancyService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
186 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpMultiTenancyService, providedIn: 'root' });
|
187 | }
|
188 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpMultiTenancyService, decorators: [{
|
189 | type: Injectable,
|
190 | args: [{
|
191 | providedIn: 'root'
|
192 | }]
|
193 | }] });
|
194 |
|
195 |
|
196 |
|
197 | class NotifyService {
|
198 | info(message, title, options) {
|
199 | abp.notify.info(message, title, options);
|
200 | }
|
201 | success(message, title, options) {
|
202 | abp.notify.success(message, title, options);
|
203 | }
|
204 | warn(message, title, options) {
|
205 | abp.notify.warn(message, title, options);
|
206 | }
|
207 | error(message, title, options) {
|
208 | abp.notify.error(message, title, options);
|
209 | }
|
210 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: NotifyService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
211 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: NotifyService, providedIn: 'root' });
|
212 | }
|
213 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: NotifyService, decorators: [{
|
214 | type: Injectable,
|
215 | args: [{
|
216 | providedIn: 'root'
|
217 | }]
|
218 | }] });
|
219 |
|
220 |
|
221 |
|
222 | class AbpSessionService {
|
223 | get userId() {
|
224 | return abp.session.userId;
|
225 | }
|
226 | get tenantId() {
|
227 | return abp.session.tenantId;
|
228 | }
|
229 | get impersonatorUserId() {
|
230 | return abp.session.impersonatorUserId;
|
231 | }
|
232 | get impersonatorTenantId() {
|
233 | return abp.session.impersonatorTenantId;
|
234 | }
|
235 | get multiTenancySide() {
|
236 | return abp.session.multiTenancySide;
|
237 | }
|
238 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpSessionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
239 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpSessionService, providedIn: 'root' });
|
240 | }
|
241 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpSessionService, decorators: [{
|
242 | type: Injectable,
|
243 | args: [{
|
244 | providedIn: 'root'
|
245 | }]
|
246 | }] });
|
247 |
|
248 |
|
249 |
|
250 | class SettingService {
|
251 | get(name) {
|
252 | return abp.setting.get(name);
|
253 | }
|
254 | getBoolean(name) {
|
255 | return abp.setting.getBoolean(name);
|
256 | }
|
257 | getInt(name) {
|
258 | return abp.setting.getInt(name);
|
259 | }
|
260 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: SettingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
261 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: SettingService, providedIn: 'root' });
|
262 | }
|
263 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: SettingService, decorators: [{
|
264 | type: Injectable,
|
265 | args: [{
|
266 | providedIn: 'root'
|
267 | }]
|
268 | }] });
|
269 |
|
270 |
|
271 |
|
272 | class UtilsService {
|
273 | getCookieValue(key) {
|
274 | return abp.utils.getCookieValue(key);
|
275 | }
|
276 | setCookieValue(key, value, expireDate, path, domain, attributes) {
|
277 | abp.utils.setCookieValue(key, value, expireDate, path, domain, attributes);
|
278 | }
|
279 | deleteCookie(key, path) {
|
280 | abp.utils.deleteCookie(key, path);
|
281 | }
|
282 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: UtilsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
283 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: UtilsService, providedIn: 'root' });
|
284 | }
|
285 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: UtilsService, decorators: [{
|
286 | type: Injectable,
|
287 | args: [{
|
288 | providedIn: 'root'
|
289 | }]
|
290 | }] });
|
291 |
|
292 |
|
293 |
|
294 | class AbpUserConfigurationService {
|
295 | _http;
|
296 | constructor(_http) {
|
297 | this._http = _http;
|
298 | }
|
299 | initialize() {
|
300 | this._http.get('/AbpUserConfiguration/GetAll')
|
301 | .subscribe(result => {
|
302 | jQuery.extend(true, abp, JSON.parse(JSON.stringify(result)));
|
303 | });
|
304 | }
|
305 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpUserConfigurationService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
306 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpUserConfigurationService, providedIn: 'root' });
|
307 | }
|
308 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpUserConfigurationService, decorators: [{
|
309 | type: Injectable,
|
310 | args: [{
|
311 | providedIn: 'root'
|
312 | }]
|
313 | }], ctorParameters: function () { return [{ type: i1.HttpClient }]; } });
|
314 |
|
315 | class RefreshTokenService {
|
316 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: RefreshTokenService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
317 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: RefreshTokenService });
|
318 | }
|
319 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: RefreshTokenService, decorators: [{
|
320 | type: Injectable
|
321 | }] });
|
322 |
|
323 | class AbpHttpConfigurationService {
|
324 | _messageService;
|
325 | _logService;
|
326 | constructor(_messageService, _logService) {
|
327 | this._messageService = _messageService;
|
328 | this._logService = _logService;
|
329 | }
|
330 | defaultError = {
|
331 | message: 'An error has occurred!',
|
332 | details: 'Error details were not sent by server.'
|
333 | };
|
334 | defaultError401 = {
|
335 | message: 'You are not authenticated!',
|
336 | details: 'You should be authenticated (sign in) in order to perform this operation.'
|
337 | };
|
338 | defaultError403 = {
|
339 | message: 'You are not authorized!',
|
340 | details: 'You are not allowed to perform this operation.'
|
341 | };
|
342 | defaultError404 = {
|
343 | message: 'Resource not found!',
|
344 | details: 'The resource requested could not be found on the server.'
|
345 | };
|
346 | logError(error) {
|
347 | this._logService.error(error);
|
348 | }
|
349 | showError(error) {
|
350 | if (error.details) {
|
351 | return this._messageService.error(error.details, error.message || this.defaultError.message);
|
352 | }
|
353 | else {
|
354 | return this._messageService.error(error.message || this.defaultError.message);
|
355 | }
|
356 | }
|
357 | handleTargetUrl(targetUrl) {
|
358 | if (!targetUrl) {
|
359 | location.href = '/';
|
360 | }
|
361 | else {
|
362 | location.href = targetUrl;
|
363 | }
|
364 | }
|
365 | handleUnAuthorizedRequest(messagePromise, targetUrl) {
|
366 | const self = this;
|
367 | if (messagePromise) {
|
368 | messagePromise.done(() => {
|
369 | this.handleTargetUrl(targetUrl || '/');
|
370 | });
|
371 | }
|
372 | else {
|
373 | self.handleTargetUrl(targetUrl || '/');
|
374 | }
|
375 | }
|
376 | handleNonAbpErrorResponse(response) {
|
377 | const self = this;
|
378 | switch (response.status) {
|
379 | case 401:
|
380 | self.handleUnAuthorizedRequest(self.showError(self.defaultError401), '/');
|
381 | break;
|
382 | case 403:
|
383 | self.showError(self.defaultError403);
|
384 | break;
|
385 | case 404:
|
386 | self.showError(self.defaultError404);
|
387 | break;
|
388 | default:
|
389 | self.showError(self.defaultError);
|
390 | break;
|
391 | }
|
392 | }
|
393 | handleAbpResponse(response, ajaxResponse) {
|
394 | var newResponse;
|
395 | if (ajaxResponse.success) {
|
396 | newResponse = response.clone({
|
397 | body: ajaxResponse.result
|
398 | });
|
399 | if (ajaxResponse.targetUrl) {
|
400 | this.handleTargetUrl(ajaxResponse.targetUrl);
|
401 | ;
|
402 | }
|
403 | }
|
404 | else {
|
405 | newResponse = response.clone({
|
406 | body: ajaxResponse.result
|
407 | });
|
408 | if (!ajaxResponse.error) {
|
409 | ajaxResponse.error = this.defaultError;
|
410 | }
|
411 | this.logError(ajaxResponse.error);
|
412 | this.showError(ajaxResponse.error);
|
413 | if (response.status === 401) {
|
414 | this.handleUnAuthorizedRequest(null, ajaxResponse.targetUrl);
|
415 | }
|
416 | }
|
417 | return newResponse;
|
418 | }
|
419 | getAbpAjaxResponseOrNull(response) {
|
420 | if (!response || !response.headers) {
|
421 | return null;
|
422 | }
|
423 | var contentType = response.headers.get('Content-Type');
|
424 | if (!contentType) {
|
425 | this._logService.warn('Content-Type is not sent!');
|
426 | return null;
|
427 | }
|
428 | if (contentType.indexOf("application/json") < 0) {
|
429 | this._logService.warn('Content-Type is not application/json: ' + contentType);
|
430 | return null;
|
431 | }
|
432 | var responseObj = JSON.parse(JSON.stringify(response.body));
|
433 | if (!responseObj.__abp) {
|
434 | return null;
|
435 | }
|
436 | return responseObj;
|
437 | }
|
438 | handleResponse(response) {
|
439 | var ajaxResponse = this.getAbpAjaxResponseOrNull(response);
|
440 | if (ajaxResponse == null) {
|
441 | return response;
|
442 | }
|
443 | return this.handleAbpResponse(response, ajaxResponse);
|
444 | }
|
445 | blobToText(blob) {
|
446 | return new Observable((observer) => {
|
447 | if (!blob) {
|
448 | observer.next("");
|
449 | observer.complete();
|
450 | }
|
451 | else {
|
452 | let reader = new FileReader();
|
453 | reader.onload = function () {
|
454 | observer.next(this.result);
|
455 | observer.complete();
|
456 | };
|
457 | reader.readAsText(blob);
|
458 | }
|
459 | });
|
460 | }
|
461 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpHttpConfigurationService, deps: [{ token: MessageService }, { token: LogService }], target: i0.ɵɵFactoryTarget.Injectable });
|
462 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpHttpConfigurationService, providedIn: 'root' });
|
463 | }
|
464 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpHttpConfigurationService, decorators: [{
|
465 | type: Injectable,
|
466 | args: [{
|
467 | providedIn: 'root'
|
468 | }]
|
469 | }], ctorParameters: function () { return [{ type: MessageService }, { type: LogService }]; } });
|
470 |
|
471 | class AbpHttpInterceptor {
|
472 | _injector;
|
473 | configuration;
|
474 | _tokenService = new TokenService();
|
475 | _utilsService = new UtilsService();
|
476 | _logService = new LogService();
|
477 | constructor(configuration, _injector) {
|
478 | this._injector = _injector;
|
479 | this.configuration = configuration;
|
480 | }
|
481 | intercept(request, next) {
|
482 | var modifiedRequest = this.normalizeRequestHeaders(request);
|
483 | return next.handle(modifiedRequest)
|
484 | .pipe(catchError(error => {
|
485 | if (error instanceof HttpErrorResponse && error.status === 401) {
|
486 | return this.tryAuthWithRefreshToken(request, next, error);
|
487 | }
|
488 | else {
|
489 | return this.handleErrorResponse(error);
|
490 | }
|
491 | }), switchMap((event) => {
|
492 | return this.handleSuccessResponse(event);
|
493 | }));
|
494 | }
|
495 | tryGetRefreshTokenService() {
|
496 | var _refreshTokenService = this._injector.get(RefreshTokenService, null);
|
497 | if (_refreshTokenService) {
|
498 | return _refreshTokenService.tryAuthWithRefreshToken();
|
499 | }
|
500 | return of(false);
|
501 | }
|
502 | isRefreshing = false;
|
503 | refreshTokenSubject = new BehaviorSubject(null);
|
504 | tryAuthWithRefreshToken(request, next, error) {
|
505 | if (!this.isRefreshing) {
|
506 | this.isRefreshing = true;
|
507 | this.refreshTokenSubject.next(null);
|
508 | return this.tryGetRefreshTokenService().pipe(switchMap((authResult) => {
|
509 | this.isRefreshing = false;
|
510 | if (authResult) {
|
511 | this.refreshTokenSubject.next(authResult);
|
512 | let modifiedRequest = this.normalizeRequestHeaders(request);
|
513 | return next.handle(modifiedRequest);
|
514 | }
|
515 | else {
|
516 | return this.handleErrorResponse(error);
|
517 | }
|
518 | }));
|
519 | }
|
520 | else {
|
521 | return this.refreshTokenSubject.pipe(filter(authResult => authResult != null), take(1), switchMap(authResult => {
|
522 | let modifiedRequest = this.normalizeRequestHeaders(request);
|
523 | return next.handle(modifiedRequest);
|
524 | }));
|
525 | }
|
526 | }
|
527 | normalizeRequestHeaders(request) {
|
528 | var modifiedHeaders = new HttpHeaders();
|
529 | modifiedHeaders = request.headers.set("Pragma", "no-cache")
|
530 | .set("Cache-Control", "no-cache")
|
531 | .set("Expires", "Sat, 01 Jan 2000 00:00:00 GMT");
|
532 | modifiedHeaders = this.addXRequestedWithHeader(modifiedHeaders);
|
533 | modifiedHeaders = this.addAuthorizationHeaders(modifiedHeaders);
|
534 | modifiedHeaders = this.addAspNetCoreCultureHeader(modifiedHeaders);
|
535 | modifiedHeaders = this.addAcceptLanguageHeader(modifiedHeaders);
|
536 | modifiedHeaders = this.addTenantIdHeader(modifiedHeaders);
|
537 | return request.clone({
|
538 | headers: modifiedHeaders
|
539 | });
|
540 | }
|
541 | addXRequestedWithHeader(headers) {
|
542 | if (headers) {
|
543 | headers = headers.set('X-Requested-With', 'XMLHttpRequest');
|
544 | }
|
545 | return headers;
|
546 | }
|
547 | addAspNetCoreCultureHeader(headers) {
|
548 | let cookieLangValue = this._utilsService.getCookieValue("Abp.Localization.CultureName");
|
549 | if (cookieLangValue && headers && !headers.has('.AspNetCore.Culture')) {
|
550 | headers = headers.set('.AspNetCore.Culture', cookieLangValue);
|
551 | }
|
552 | return headers;
|
553 | }
|
554 | addAcceptLanguageHeader(headers) {
|
555 | let cookieLangValue = this._utilsService.getCookieValue("Abp.Localization.CultureName");
|
556 | if (cookieLangValue && headers && !headers.has('Accept-Language')) {
|
557 | headers = headers.set('Accept-Language', cookieLangValue);
|
558 | }
|
559 | return headers;
|
560 | }
|
561 | addTenantIdHeader(headers) {
|
562 | let cookieTenantIdValue = this._utilsService.getCookieValue(abp.multiTenancy.tenantIdCookieName);
|
563 | if (cookieTenantIdValue && headers && !headers.has(abp.multiTenancy.tenantIdCookieName)) {
|
564 | headers = headers.set(abp.multiTenancy.tenantIdCookieName, cookieTenantIdValue);
|
565 | }
|
566 | return headers;
|
567 | }
|
568 | addAuthorizationHeaders(headers) {
|
569 | let authorizationHeaders = headers ? headers.getAll('Authorization') : null;
|
570 | if (!authorizationHeaders) {
|
571 | authorizationHeaders = [];
|
572 | }
|
573 | if (!this.itemExists(authorizationHeaders, (item) => item.indexOf('Bearer ') == 0)) {
|
574 | let token = this._tokenService.getToken();
|
575 | if (headers && token) {
|
576 | headers = headers.set('Authorization', 'Bearer ' + token);
|
577 | }
|
578 | }
|
579 | return headers;
|
580 | }
|
581 | handleSuccessResponse(event) {
|
582 | var self = this;
|
583 | if (event instanceof HttpResponse) {
|
584 | if (event.body instanceof Blob && event.body.type && event.body.type.indexOf("application/json") >= 0) {
|
585 | return self.configuration.blobToText(event.body).pipe(map(json => {
|
586 | const responseBody = json == "null" ? {} : JSON.parse(json);
|
587 | var modifiedResponse = self.configuration.handleResponse(event.clone({
|
588 | body: responseBody
|
589 | }));
|
590 | return modifiedResponse.clone({
|
591 | body: new Blob([JSON.stringify(modifiedResponse.body)], { type: 'application/json' })
|
592 | });
|
593 | }));
|
594 | }
|
595 | }
|
596 | return of(event);
|
597 | }
|
598 | handleErrorResponse(error) {
|
599 | if (!(error.error instanceof Blob)) {
|
600 | return throwError(error);
|
601 | }
|
602 | return this.configuration.blobToText(error.error).pipe(switchMap((json) => {
|
603 | const errorBody = (json == "" || json == "null") ? {} : JSON.parse(json);
|
604 | const errorResponse = new HttpResponse({
|
605 | headers: error.headers,
|
606 | status: error.status,
|
607 | body: errorBody
|
608 | });
|
609 | var ajaxResponse = this.configuration.getAbpAjaxResponseOrNull(errorResponse);
|
610 | if (ajaxResponse != null) {
|
611 | this.configuration.handleAbpResponse(errorResponse, ajaxResponse);
|
612 | }
|
613 | else {
|
614 | this.configuration.handleNonAbpErrorResponse(errorResponse);
|
615 | }
|
616 | return throwError(error);
|
617 | }));
|
618 | }
|
619 | itemExists(items, predicate) {
|
620 | for (let i = 0; i < items.length; i++) {
|
621 | if (predicate(items[i])) {
|
622 | return true;
|
623 | }
|
624 | }
|
625 | return false;
|
626 | }
|
627 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpHttpInterceptor, deps: [{ token: AbpHttpConfigurationService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
628 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpHttpInterceptor });
|
629 | }
|
630 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: AbpHttpInterceptor, decorators: [{
|
631 | type: Injectable
|
632 | }], ctorParameters: function () { return [{ type: AbpHttpConfigurationService }, { type: i0.Injector }]; } });
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 | export { AbpHttpConfigurationService, AbpHttpInterceptor, AbpModule, AbpMultiTenancyService, AbpSessionService, AbpUserConfigurationService, FeatureCheckerService, LocalizationService, LogService, MessageService, NotifyService, PermissionCheckerService, RefreshTokenService, SettingService, TokenService, UtilsService };
|
643 |
|