@von-development-studio/angular-rest-service 1.0.5 → 1.0.6
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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +1 -1
- package/bundles/von-development-studio-angular-rest-service.umd.js +50 -562
- package/bundles/von-development-studio-angular-rest-service.umd.js.map +1 -1
- package/bundles/von-development-studio-angular-rest-service.umd.min.js +1 -15
- package/bundles/von-development-studio-angular-rest-service.umd.min.js.map +1 -1
- package/esm2015/lib/model/von-error-response.model.js +2 -17
- package/esm2015/lib/model/von-error-rest-interceptor.model.js +2 -15
- package/esm2015/lib/model/von-http-options.model.js +2 -23
- package/esm2015/lib/model/von-page-response.model.js +2 -26
- package/esm2015/lib/von-rest-interceptor.service.js +7 -67
- package/esm2015/lib/von-rest.service.js +37 -211
- package/esm2015/public-api.js +7 -11
- package/esm2015/von-development-studio-angular-rest-service.js +2 -6
- package/fesm2015/von-development-studio-angular-rest-service.js +43 -341
- package/fesm2015/von-development-studio-angular-rest-service.js.map +1 -1
- package/lib/von-rest.service.d.ts +3 -3
- package/package.json +3 -5
- package/esm5/lib/model/von-error-response.model.js +0 -17
- package/esm5/lib/model/von-error-rest-interceptor.model.js +0 -15
- package/esm5/lib/model/von-http-options.model.js +0 -23
- package/esm5/lib/model/von-page-response.model.js +0 -26
- package/esm5/lib/von-rest-interceptor.service.js +0 -126
- package/esm5/lib/von-rest.service.js +0 -272
- package/esm5/public-api.js +0 -11
- package/esm5/von-development-studio-angular-rest-service.js +0 -9
- package/fesm5/von-development-studio-angular-rest-service.js +0 -459
- package/fesm5/von-development-studio-angular-rest-service.js.map +0 -1
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
import { HttpResponse, HttpHeaders } from '@angular/common/http';
|
|
2
|
-
import { throwError } from 'rxjs';
|
|
3
|
-
import { map, catchError, take, share } from 'rxjs/operators';
|
|
4
|
-
import { __assign } from 'tslib';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @fileoverview added by tsickle
|
|
8
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* @record
|
|
12
|
-
*/
|
|
13
|
-
function VonErrorResponseModel() { }
|
|
14
|
-
if (false) {
|
|
15
|
-
/** @type {?|undefined} */
|
|
16
|
-
VonErrorResponseModel.prototype.code;
|
|
17
|
-
/** @type {?|undefined} */
|
|
18
|
-
VonErrorResponseModel.prototype.message;
|
|
19
|
-
/** @type {?|undefined} */
|
|
20
|
-
VonErrorResponseModel.prototype.payload;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @fileoverview added by tsickle
|
|
25
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* @record
|
|
29
|
-
*/
|
|
30
|
-
function VonErrorRestInterceptorModel() { }
|
|
31
|
-
if (false) {
|
|
32
|
-
/** @type {?} */
|
|
33
|
-
VonErrorRestInterceptorModel.prototype.status;
|
|
34
|
-
/** @type {?} */
|
|
35
|
-
VonErrorRestInterceptorModel.prototype.message;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @fileoverview added by tsickle
|
|
40
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
41
|
-
*/
|
|
42
|
-
/**
|
|
43
|
-
* @record
|
|
44
|
-
* @template T
|
|
45
|
-
*/
|
|
46
|
-
function VonPageResponseModel() { }
|
|
47
|
-
if (false) {
|
|
48
|
-
/** @type {?} */
|
|
49
|
-
VonPageResponseModel.prototype.content;
|
|
50
|
-
/** @type {?} */
|
|
51
|
-
VonPageResponseModel.prototype.last;
|
|
52
|
-
/** @type {?} */
|
|
53
|
-
VonPageResponseModel.prototype.totalPages;
|
|
54
|
-
/** @type {?} */
|
|
55
|
-
VonPageResponseModel.prototype.totalElements;
|
|
56
|
-
/** @type {?} */
|
|
57
|
-
VonPageResponseModel.prototype.size;
|
|
58
|
-
/** @type {?} */
|
|
59
|
-
VonPageResponseModel.prototype.numberOfElements;
|
|
60
|
-
/** @type {?} */
|
|
61
|
-
VonPageResponseModel.prototype.number;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @fileoverview added by tsickle
|
|
66
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
67
|
-
*/
|
|
68
|
-
/**
|
|
69
|
-
* @abstract
|
|
70
|
-
*/
|
|
71
|
-
var /**
|
|
72
|
-
* @abstract
|
|
73
|
-
*/
|
|
74
|
-
VonRestInterceptorService = /** @class */ (function () {
|
|
75
|
-
function VonRestInterceptorService(router) {
|
|
76
|
-
this.router = router;
|
|
77
|
-
this.consoleDebug = false;
|
|
78
|
-
this.errorResponseUnknown = 'Unknown Error';
|
|
79
|
-
this.errorResponseForbidden = 'Forbidden Error';
|
|
80
|
-
this.urlWhoAmI = 'api/who-am-i';
|
|
81
|
-
this.postHttpRequest = (/**
|
|
82
|
-
* @return {?}
|
|
83
|
-
*/
|
|
84
|
-
function () {
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* @param {?} request
|
|
89
|
-
* @param {?} next
|
|
90
|
-
* @return {?}
|
|
91
|
-
*/
|
|
92
|
-
VonRestInterceptorService.prototype.intercept = /**
|
|
93
|
-
* @param {?} request
|
|
94
|
-
* @param {?} next
|
|
95
|
-
* @return {?}
|
|
96
|
-
*/
|
|
97
|
-
function (request, next) {
|
|
98
|
-
var _this = this;
|
|
99
|
-
return next.handle(request).pipe(map((/**
|
|
100
|
-
* @param {?} event
|
|
101
|
-
* @return {?}
|
|
102
|
-
*/
|
|
103
|
-
function (event) {
|
|
104
|
-
if (event instanceof HttpResponse) {
|
|
105
|
-
if (event.status === 200 || event.status === 204) {
|
|
106
|
-
_this.postHttpRequest();
|
|
107
|
-
return event;
|
|
108
|
-
}
|
|
109
|
-
if (event.status !== 200) {
|
|
110
|
-
/** @type {?} */
|
|
111
|
-
var error = {
|
|
112
|
-
status: event.status,
|
|
113
|
-
message: event.statusText
|
|
114
|
-
};
|
|
115
|
-
if (_this.consoleDebug) {
|
|
116
|
-
console.error('[ErrorWS]: ', error);
|
|
117
|
-
}
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
_this.postHttpRequest();
|
|
122
|
-
return event;
|
|
123
|
-
})), catchError((/**
|
|
124
|
-
* @param {?} errorResponse
|
|
125
|
-
* @return {?}
|
|
126
|
-
*/
|
|
127
|
-
function (errorResponse) {
|
|
128
|
-
if (_this.consoleDebug) {
|
|
129
|
-
console.error('[Fatal]: ', errorResponse);
|
|
130
|
-
}
|
|
131
|
-
/** @type {?} */
|
|
132
|
-
var error = {
|
|
133
|
-
status: errorResponse.status,
|
|
134
|
-
message: ''
|
|
135
|
-
};
|
|
136
|
-
if (errorResponse.status === 0) {
|
|
137
|
-
error.message = _this.errorResponseUnknown;
|
|
138
|
-
}
|
|
139
|
-
if (errorResponse.status === 401) {
|
|
140
|
-
error.message = errorResponse.error ? errorResponse.error : _this.errorResponseForbidden;
|
|
141
|
-
}
|
|
142
|
-
if (errorResponse.status === 403 || (errorResponse.url && errorResponse.url.indexOf(_this.urlWhoAmI) > -1)) {
|
|
143
|
-
_this.router.navigate(['403']);
|
|
144
|
-
}
|
|
145
|
-
return throwError(error);
|
|
146
|
-
})));
|
|
147
|
-
};
|
|
148
|
-
return VonRestInterceptorService;
|
|
149
|
-
}());
|
|
150
|
-
if (false) {
|
|
151
|
-
/**
|
|
152
|
-
* @type {?}
|
|
153
|
-
* @protected
|
|
154
|
-
*/
|
|
155
|
-
VonRestInterceptorService.prototype.consoleDebug;
|
|
156
|
-
/**
|
|
157
|
-
* @type {?}
|
|
158
|
-
* @protected
|
|
159
|
-
*/
|
|
160
|
-
VonRestInterceptorService.prototype.errorResponseUnknown;
|
|
161
|
-
/**
|
|
162
|
-
* @type {?}
|
|
163
|
-
* @protected
|
|
164
|
-
*/
|
|
165
|
-
VonRestInterceptorService.prototype.errorResponseForbidden;
|
|
166
|
-
/**
|
|
167
|
-
* @type {?}
|
|
168
|
-
* @protected
|
|
169
|
-
*/
|
|
170
|
-
VonRestInterceptorService.prototype.urlWhoAmI;
|
|
171
|
-
/**
|
|
172
|
-
* @type {?}
|
|
173
|
-
* @protected
|
|
174
|
-
*/
|
|
175
|
-
VonRestInterceptorService.prototype.postHttpRequest;
|
|
176
|
-
/**
|
|
177
|
-
* @type {?}
|
|
178
|
-
* @protected
|
|
179
|
-
*/
|
|
180
|
-
VonRestInterceptorService.prototype.router;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* @fileoverview added by tsickle
|
|
185
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
186
|
-
*/
|
|
187
|
-
/**
|
|
188
|
-
* @abstract
|
|
189
|
-
*/
|
|
190
|
-
var /**
|
|
191
|
-
* @abstract
|
|
192
|
-
*/
|
|
193
|
-
VonRestService = /** @class */ (function () {
|
|
194
|
-
function VonRestService(http, sanitizer) {
|
|
195
|
-
var _this = this;
|
|
196
|
-
this.http = http;
|
|
197
|
-
this.sanitizer = sanitizer;
|
|
198
|
-
this.setHeaders = (/**
|
|
199
|
-
* @param {?=} contentType
|
|
200
|
-
* @param {?=} accept
|
|
201
|
-
* @return {?}
|
|
202
|
-
*/
|
|
203
|
-
function (contentType, accept) {
|
|
204
|
-
if (contentType === void 0) { contentType = 'application/json'; }
|
|
205
|
-
if (accept === void 0) { accept = 'application/json'; }
|
|
206
|
-
return new HttpHeaders({
|
|
207
|
-
'Content-Type': contentType,
|
|
208
|
-
Accept: accept
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
this.setOptions = (/**
|
|
212
|
-
* @param {?=} params
|
|
213
|
-
* @return {?}
|
|
214
|
-
*/
|
|
215
|
-
function (params) {
|
|
216
|
-
return {
|
|
217
|
-
headers: _this.setHeaders(),
|
|
218
|
-
params: params,
|
|
219
|
-
withCredentials: true
|
|
220
|
-
};
|
|
221
|
-
});
|
|
222
|
-
this.setUrlParams = (/**
|
|
223
|
-
* @param {?} url
|
|
224
|
-
* @param {?=} params
|
|
225
|
-
* @return {?}
|
|
226
|
-
*/
|
|
227
|
-
function (url, params) {
|
|
228
|
-
if (params != null) {
|
|
229
|
-
for (var p in params) {
|
|
230
|
-
if (p != null) {
|
|
231
|
-
url = url.replace("{" + p + "}", params[p]);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return url;
|
|
236
|
-
});
|
|
237
|
-
this.authenticate = (/**
|
|
238
|
-
* @param {?} url
|
|
239
|
-
* @param {?} username
|
|
240
|
-
* @param {?} password
|
|
241
|
-
* @return {?}
|
|
242
|
-
*/
|
|
243
|
-
function (url, username, password) {
|
|
244
|
-
/** @type {?} */
|
|
245
|
-
var authorization = btoa(username + ":" + password);
|
|
246
|
-
/** @type {?} */
|
|
247
|
-
var headers = new HttpHeaders({
|
|
248
|
-
authorization: "Basic " + authorization,
|
|
249
|
-
});
|
|
250
|
-
return _this.http.get(url, {
|
|
251
|
-
headers: headers,
|
|
252
|
-
withCredentials: true
|
|
253
|
-
}).pipe(take(1), share());
|
|
254
|
-
});
|
|
255
|
-
this.logout = (/**
|
|
256
|
-
* @param {?} url
|
|
257
|
-
* @return {?}
|
|
258
|
-
*/
|
|
259
|
-
function (url) {
|
|
260
|
-
return _this.http.delete(url, _this.setOptions()).pipe(take(1), share());
|
|
261
|
-
});
|
|
262
|
-
this.get = (/**
|
|
263
|
-
* @template T
|
|
264
|
-
* @param {?} url
|
|
265
|
-
* @param {?=} urlParams
|
|
266
|
-
* @param {?=} queryParams
|
|
267
|
-
* @return {?}
|
|
268
|
-
*/
|
|
269
|
-
function (url, urlParams, queryParams) {
|
|
270
|
-
url = _this.setUrlParams(url, urlParams);
|
|
271
|
-
return _this.http.get(url, _this.setOptions(queryParams));
|
|
272
|
-
});
|
|
273
|
-
this.delete = (/**
|
|
274
|
-
* @template T
|
|
275
|
-
* @param {?} url
|
|
276
|
-
* @param {?=} urlParams
|
|
277
|
-
* @param {?=} queryParams
|
|
278
|
-
* @return {?}
|
|
279
|
-
*/
|
|
280
|
-
function (url, urlParams, queryParams) {
|
|
281
|
-
url = _this.setUrlParams(url, urlParams);
|
|
282
|
-
return _this.http.delete(url, _this.setOptions(queryParams));
|
|
283
|
-
});
|
|
284
|
-
this.post = (/**
|
|
285
|
-
* @template T
|
|
286
|
-
* @param {?} url
|
|
287
|
-
* @param {?} body
|
|
288
|
-
* @param {?=} urlParams
|
|
289
|
-
* @param {?=} queryParams
|
|
290
|
-
* @return {?}
|
|
291
|
-
*/
|
|
292
|
-
function (url, body, urlParams, queryParams) {
|
|
293
|
-
url = _this.setUrlParams(url, urlParams);
|
|
294
|
-
return _this.http.post(url, body, _this.setOptions(queryParams));
|
|
295
|
-
});
|
|
296
|
-
this.put = (/**
|
|
297
|
-
* @template T
|
|
298
|
-
* @param {?} url
|
|
299
|
-
* @param {?} body
|
|
300
|
-
* @param {?=} urlParams
|
|
301
|
-
* @param {?=} queryParams
|
|
302
|
-
* @return {?}
|
|
303
|
-
*/
|
|
304
|
-
function (url, body, urlParams, queryParams) {
|
|
305
|
-
url = _this.setUrlParams(url, urlParams);
|
|
306
|
-
return _this.http.put(url, body, _this.setOptions(queryParams));
|
|
307
|
-
});
|
|
308
|
-
this.patch = (/**
|
|
309
|
-
* @template T
|
|
310
|
-
* @param {?} url
|
|
311
|
-
* @param {?} body
|
|
312
|
-
* @param {?=} urlParams
|
|
313
|
-
* @param {?=} queryParams
|
|
314
|
-
* @return {?}
|
|
315
|
-
*/
|
|
316
|
-
function (url, body, urlParams, queryParams) {
|
|
317
|
-
url = _this.setUrlParams(url, urlParams);
|
|
318
|
-
return _this.http.patch(url, body, _this.setOptions(queryParams));
|
|
319
|
-
});
|
|
320
|
-
this.setFileOptions = (/**
|
|
321
|
-
* @param {?} contentType
|
|
322
|
-
* @param {?=} queryParams
|
|
323
|
-
* @return {?}
|
|
324
|
-
*/
|
|
325
|
-
function (contentType, queryParams) {
|
|
326
|
-
return __assign(__assign({}, _this.setOptions(queryParams)), { headers: _this.setHeaders(contentType), responseType: (/** @type {?} */ ('blob')) });
|
|
327
|
-
});
|
|
328
|
-
this.getFile = (/**
|
|
329
|
-
* @param {?} contentType
|
|
330
|
-
* @param {?} url
|
|
331
|
-
* @param {?=} urlParams
|
|
332
|
-
* @param {?=} queryParams
|
|
333
|
-
* @return {?}
|
|
334
|
-
*/
|
|
335
|
-
function (contentType, url, urlParams, queryParams) {
|
|
336
|
-
url = _this.setUrlParams(url, urlParams);
|
|
337
|
-
return _this.http.get(url, _this.setFileOptions(contentType, queryParams)).pipe(map((/**
|
|
338
|
-
* @param {?} res
|
|
339
|
-
* @return {?}
|
|
340
|
-
*/
|
|
341
|
-
function (res) {
|
|
342
|
-
/** @type {?} */
|
|
343
|
-
var fileBlob = new Blob([res], { type: contentType });
|
|
344
|
-
/** @type {?} */
|
|
345
|
-
var objUrl = URL.createObjectURL(fileBlob);
|
|
346
|
-
/** @type {?} */
|
|
347
|
-
var sanitized = _this.sanitizer.bypassSecurityTrustResourceUrl(objUrl);
|
|
348
|
-
return sanitized;
|
|
349
|
-
})));
|
|
350
|
-
});
|
|
351
|
-
this.postFile = (/**
|
|
352
|
-
* @template T
|
|
353
|
-
* @param {?} contentType
|
|
354
|
-
* @param {?} url
|
|
355
|
-
* @param {?} body
|
|
356
|
-
* @param {?=} urlParams
|
|
357
|
-
* @param {?=} queryParams
|
|
358
|
-
* @return {?}
|
|
359
|
-
*/
|
|
360
|
-
function (contentType, url, body, urlParams, queryParams) {
|
|
361
|
-
url = _this.setUrlParams(url, urlParams);
|
|
362
|
-
return _this.http.post(url, body, _this.setFileOptions(contentType, queryParams));
|
|
363
|
-
});
|
|
364
|
-
this.putFile = (/**
|
|
365
|
-
* @template T
|
|
366
|
-
* @param {?} contentType
|
|
367
|
-
* @param {?} url
|
|
368
|
-
* @param {?} body
|
|
369
|
-
* @param {?=} urlParams
|
|
370
|
-
* @param {?=} queryParams
|
|
371
|
-
* @return {?}
|
|
372
|
-
*/
|
|
373
|
-
function (contentType, url, body, urlParams, queryParams) {
|
|
374
|
-
url = _this.setUrlParams(url, urlParams);
|
|
375
|
-
return _this.http.put(url, body, _this.setFileOptions(contentType, queryParams));
|
|
376
|
-
});
|
|
377
|
-
this.patchFile = (/**
|
|
378
|
-
* @template T
|
|
379
|
-
* @param {?} contentType
|
|
380
|
-
* @param {?} url
|
|
381
|
-
* @param {?} body
|
|
382
|
-
* @param {?=} urlParams
|
|
383
|
-
* @param {?=} queryParams
|
|
384
|
-
* @return {?}
|
|
385
|
-
*/
|
|
386
|
-
function (contentType, url, body, urlParams, queryParams) {
|
|
387
|
-
url = _this.setUrlParams(url, urlParams);
|
|
388
|
-
return _this.http.patch(url, body, _this.setFileOptions(contentType, queryParams));
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
return VonRestService;
|
|
392
|
-
}());
|
|
393
|
-
if (false) {
|
|
394
|
-
/**
|
|
395
|
-
* @type {?}
|
|
396
|
-
* @private
|
|
397
|
-
*/
|
|
398
|
-
VonRestService.prototype.setHeaders;
|
|
399
|
-
/**
|
|
400
|
-
* @type {?}
|
|
401
|
-
* @private
|
|
402
|
-
*/
|
|
403
|
-
VonRestService.prototype.setOptions;
|
|
404
|
-
/**
|
|
405
|
-
* @type {?}
|
|
406
|
-
* @private
|
|
407
|
-
*/
|
|
408
|
-
VonRestService.prototype.setUrlParams;
|
|
409
|
-
/** @type {?} */
|
|
410
|
-
VonRestService.prototype.authenticate;
|
|
411
|
-
/** @type {?} */
|
|
412
|
-
VonRestService.prototype.logout;
|
|
413
|
-
/** @type {?} */
|
|
414
|
-
VonRestService.prototype.get;
|
|
415
|
-
/** @type {?} */
|
|
416
|
-
VonRestService.prototype.delete;
|
|
417
|
-
/** @type {?} */
|
|
418
|
-
VonRestService.prototype.post;
|
|
419
|
-
/** @type {?} */
|
|
420
|
-
VonRestService.prototype.put;
|
|
421
|
-
/** @type {?} */
|
|
422
|
-
VonRestService.prototype.patch;
|
|
423
|
-
/**
|
|
424
|
-
* @type {?}
|
|
425
|
-
* @private
|
|
426
|
-
*/
|
|
427
|
-
VonRestService.prototype.setFileOptions;
|
|
428
|
-
/** @type {?} */
|
|
429
|
-
VonRestService.prototype.getFile;
|
|
430
|
-
/** @type {?} */
|
|
431
|
-
VonRestService.prototype.postFile;
|
|
432
|
-
/** @type {?} */
|
|
433
|
-
VonRestService.prototype.putFile;
|
|
434
|
-
/** @type {?} */
|
|
435
|
-
VonRestService.prototype.patchFile;
|
|
436
|
-
/**
|
|
437
|
-
* @type {?}
|
|
438
|
-
* @protected
|
|
439
|
-
*/
|
|
440
|
-
VonRestService.prototype.http;
|
|
441
|
-
/**
|
|
442
|
-
* @type {?}
|
|
443
|
-
* @protected
|
|
444
|
-
*/
|
|
445
|
-
VonRestService.prototype.sanitizer;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* @fileoverview added by tsickle
|
|
450
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
451
|
-
*/
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* @fileoverview added by tsickle
|
|
455
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
456
|
-
*/
|
|
457
|
-
|
|
458
|
-
export { VonRestInterceptorService, VonRestService };
|
|
459
|
-
//# sourceMappingURL=von-development-studio-angular-rest-service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"von-development-studio-angular-rest-service.js","sources":["ng://@von-development-studio/angular-rest-service/lib/model/von-error-response.model.ts","ng://@von-development-studio/angular-rest-service/lib/model/von-error-rest-interceptor.model.ts","ng://@von-development-studio/angular-rest-service/lib/model/von-page-response.model.ts","ng://@von-development-studio/angular-rest-service/lib/von-rest-interceptor.service.ts","ng://@von-development-studio/angular-rest-service/lib/von-rest.service.ts"],"sourcesContent":["export interface VonErrorResponseModel {\n code?: string | null;\n message?: string | null;\n payload?: any | null;\n}\n","export interface VonErrorRestInterceptorModel {\n status: number;\n message: string;\n}\n","export interface VonPageResponseModel<T> {\n content: T[];\n last: boolean;\n totalPages: number;\n totalElements: number;\n size: number;\n numberOfElements: number;\n number: number;\n}\n","import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';\nimport { Router } from '@angular/router';\nimport { Observable, throwError } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\nimport { VonErrorRestInterceptorModel } from './model/von-error-rest-interceptor.model';\n\nexport abstract class VonRestInterceptorService implements HttpInterceptor {\n\n protected consoleDebug = false;\n protected errorResponseUnknown = 'Unknown Error';\n protected errorResponseForbidden = 'Forbidden Error';\n protected urlWhoAmI = 'api/who-am-i';\n\n constructor(\n protected router: Router\n ) { }\n\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n return next.handle(request).pipe(\n\n map((event: HttpEvent<any>) => {\n if (event instanceof HttpResponse) {\n if (event.status === 200 || event.status === 204) {\n this.postHttpRequest();\n return event;\n }\n if (event.status !== 200) {\n const error: VonErrorRestInterceptorModel = {\n status: event.status,\n message: event.statusText\n };\n if (this.consoleDebug) {\n console.error('[ErrorWS]: ', error);\n }\n throw error;\n }\n }\n this.postHttpRequest();\n return event;\n }),\n\n catchError((errorResponse: HttpErrorResponse) => {\n if (this.consoleDebug) {\n console.error('[Fatal]: ', errorResponse);\n }\n const error: VonErrorRestInterceptorModel = {\n status: errorResponse.status,\n message: ''\n };\n if (errorResponse.status === 0) {\n error.message = this.errorResponseUnknown;\n }\n if (errorResponse.status === 401) {\n error.message = errorResponse.error ? errorResponse.error : this.errorResponseForbidden;\n }\n if (errorResponse.status === 403 || (errorResponse.url && errorResponse.url.indexOf(this.urlWhoAmI) > -1)) {\n this.router.navigate(['403']);\n }\n return throwError(error);\n })\n );\n }\n\n protected postHttpRequest = () => {\n }\n\n}","import { HttpClient, HttpHeaders } from '@angular/common/http';\nimport { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';\nimport { Observable } from 'rxjs';\nimport { map, share, take } from 'rxjs/operators';\nimport { VonHttpOptionsModel } from './model/von-http-options.model';\n\nexport abstract class VonRestService {\n\n constructor(\n protected http: HttpClient,\n protected sanitizer: DomSanitizer\n ) { }\n\n private setHeaders = (\n contentType: string = 'application/json',\n accept: string = 'application/json'\n ): HttpHeaders => {\n return new HttpHeaders({\n 'Content-Type': contentType,\n Accept: accept\n });\n }\n\n private setOptions = (params?: { [key: string]: any }): VonHttpOptionsModel => {\n return {\n headers: this.setHeaders(),\n params,\n withCredentials: true\n };\n }\n\n private setUrlParams = (url: string, params?: { [key: string]: any }) => {\n if (params != null) {\n for (const p in params) {\n if (p != null) {\n url = url.replace(`{${p}}`, params[p]);\n }\n }\n }\n return url;\n }\n\n authenticate = (url: string, username: string, password: string): Observable<any> => {\n const authorization = btoa(`${username}:${password}`);\n const headers = new HttpHeaders({\n authorization: `Basic ${authorization}`,\n });\n return this.http.get(url, {\n headers,\n withCredentials: true\n }).pipe(\n take(1),\n share()\n );\n }\n\n logout = (url: string): Observable<any> => {\n return this.http.delete<string>(url, this.setOptions()).pipe(\n take(1),\n share()\n );\n }\n\n get = <T = any>(url: string, urlParams?: any, queryParams?: any): Observable<T> => {\n url = this.setUrlParams(url, urlParams);\n return this.http.get<T>(url, this.setOptions(queryParams));\n }\n\n delete = <T = any>(url: string, urlParams?: any, queryParams?: any): Observable<T> => {\n url = this.setUrlParams(url, urlParams);\n return this.http.delete<T>(url, this.setOptions(queryParams));\n }\n\n post = <T = any>(url: string, body: any, urlParams?: any, queryParams?: any): Observable<T> => {\n url = this.setUrlParams(url, urlParams);\n return this.http.post<T>(url, body, this.setOptions(queryParams));\n }\n\n put = <T = any>(url: string, body: any, urlParams?: any, queryParams?: any): Observable<T> => {\n url = this.setUrlParams(url, urlParams);\n return this.http.put<T>(url, body, this.setOptions(queryParams));\n }\n\n patch = <T = any>(url: string, body: any, urlParams?: any, queryParams?: any): Observable<T> => {\n url = this.setUrlParams(url, urlParams);\n return this.http.patch<T>(url, body, this.setOptions(queryParams));\n }\n\n private setFileOptions = (contentType: string, queryParams?: { [key: string]: any }): VonHttpOptionsModel => {\n return {\n ...this.setOptions(queryParams),\n headers: this.setHeaders(contentType),\n responseType: 'blob' as 'json'\n };\n }\n\n getFile = (contentType: string, url: string, urlParams?: any, queryParams?: any): Observable<SafeResourceUrl> => {\n url = this.setUrlParams(url, urlParams);\n return this.http.get(url, this.setFileOptions(contentType, queryParams)).pipe(\n map((res: any) => {\n const fileBlob = new Blob([res], { type: contentType });\n const objUrl = URL.createObjectURL(fileBlob);\n const sanitized = this.sanitizer.bypassSecurityTrustResourceUrl(objUrl);\n return sanitized;\n })\n );\n }\n\n postFile = <T = any>(contentType: string, url: string, body: any, urlParams?: any, queryParams?: any): Observable<any> => {\n url = this.setUrlParams(url, urlParams);\n return this.http.post<T>(url, body, this.setFileOptions(contentType, queryParams));\n }\n\n putFile = <T = any>(contentType: string, url: string, body: any, urlParams?: any, queryParams?: any): Observable<any> => {\n url = this.setUrlParams(url, urlParams);\n return this.http.put<T>(url, body, this.setFileOptions(contentType, queryParams));\n }\n\n patchFile = <T = any>(contentType: string, url: string, body: any, urlParams?: any, queryParams?: any): Observable<any> => {\n url = this.setUrlParams(url, urlParams);\n return this.http.patch<T>(url, body, this.setFileOptions(contentType, queryParams));\n }\n\n}"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAIC;;;IAHC,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