@esfaenza/httpservice 12.2.22 → 13.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/esfaenza-httpservice.d.ts +1 -1
- package/esm2020/esfaenza-httpservice.mjs +5 -0
- package/{esm2015/lib/config/HttpServiceExtensions.js → esm2020/lib/config/HttpServiceExtensions.mjs} +0 -0
- package/{esm2015/lib/config/HttpServiceModuleConfig.js → esm2020/lib/config/HttpServiceModuleConfig.mjs} +0 -0
- package/{esm2015/lib/config/IHttpServiceExtensions.js → esm2020/lib/config/IHttpServiceExtensions.mjs} +0 -0
- package/esm2020/lib/httpservice.module.mjs +30 -0
- package/{esm2015/lib/httpservice.service.loc.js → esm2020/lib/httpservice.service.loc.mjs} +0 -0
- package/esm2020/lib/httpservice.service.mjs +716 -0
- package/{esm2015/lib/models/Download.js → esm2020/lib/models/Download.mjs} +0 -0
- package/{esm2015/lib/tokens.js → esm2020/lib/tokens.mjs} +0 -0
- package/{esm2015/public-api.js → esm2020/public-api.mjs} +0 -0
- package/fesm2015/{esfaenza-httpservice.js → esfaenza-httpservice.mjs} +51 -20
- package/fesm2015/esfaenza-httpservice.mjs.map +1 -0
- package/fesm2020/esfaenza-httpservice.mjs +885 -0
- package/fesm2020/esfaenza-httpservice.mjs.map +1 -0
- package/lib/httpservice.module.d.ts +4 -0
- package/lib/httpservice.service.d.ts +3 -0
- package/package.json +21 -9
- package/bundles/esfaenza-httpservice.umd.js +0 -1253
- package/bundles/esfaenza-httpservice.umd.js.map +0 -1
- package/esfaenza-httpservice.metadata.json +0 -1
- package/esm2015/esfaenza-httpservice.js +0 -6
- package/esm2015/lib/httpservice.module.js +0 -26
- package/esm2015/lib/httpservice.service.js +0 -698
- package/fesm2015/esfaenza-httpservice.js.map +0 -1
|
@@ -1,1253 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common/http'), require('@angular/core'), require('rxjs/operators'), require('rxjs')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@esfaenza/httpservice', ['exports', '@angular/common/http', '@angular/core', 'rxjs/operators', 'rxjs'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.esfaenza = global.esfaenza || {}, global.esfaenza.httpservice = {}), global.ng.common.http, global.ng.core, global.rxjs.operators, global.rxjs));
|
|
5
|
-
}(this, (function (exports, http, core, operators, rxjs) { 'use strict';
|
|
6
|
-
|
|
7
|
-
/*! *****************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise */
|
|
22
|
-
var extendStatics = function (d, b) {
|
|
23
|
-
extendStatics = Object.setPrototypeOf ||
|
|
24
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
-
function (d, b) { for (var p in b)
|
|
26
|
-
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
27
|
-
d[p] = b[p]; };
|
|
28
|
-
return extendStatics(d, b);
|
|
29
|
-
};
|
|
30
|
-
function __extends(d, b) {
|
|
31
|
-
if (typeof b !== "function" && b !== null)
|
|
32
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
33
|
-
extendStatics(d, b);
|
|
34
|
-
function __() { this.constructor = d; }
|
|
35
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
36
|
-
}
|
|
37
|
-
var __assign = function () {
|
|
38
|
-
__assign = Object.assign || function __assign(t) {
|
|
39
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
-
s = arguments[i];
|
|
41
|
-
for (var p in s)
|
|
42
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
43
|
-
t[p] = s[p];
|
|
44
|
-
}
|
|
45
|
-
return t;
|
|
46
|
-
};
|
|
47
|
-
return __assign.apply(this, arguments);
|
|
48
|
-
};
|
|
49
|
-
function __rest(s, e) {
|
|
50
|
-
var t = {};
|
|
51
|
-
for (var p in s)
|
|
52
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
53
|
-
t[p] = s[p];
|
|
54
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
55
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
56
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
57
|
-
t[p[i]] = s[p[i]];
|
|
58
|
-
}
|
|
59
|
-
return t;
|
|
60
|
-
}
|
|
61
|
-
function __decorate(decorators, target, key, desc) {
|
|
62
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
63
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
64
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
65
|
-
else
|
|
66
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
67
|
-
if (d = decorators[i])
|
|
68
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
69
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
70
|
-
}
|
|
71
|
-
function __param(paramIndex, decorator) {
|
|
72
|
-
return function (target, key) { decorator(target, key, paramIndex); };
|
|
73
|
-
}
|
|
74
|
-
function __metadata(metadataKey, metadataValue) {
|
|
75
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
76
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
|
77
|
-
}
|
|
78
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
79
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
80
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
81
|
-
function fulfilled(value) { try {
|
|
82
|
-
step(generator.next(value));
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
reject(e);
|
|
86
|
-
} }
|
|
87
|
-
function rejected(value) { try {
|
|
88
|
-
step(generator["throw"](value));
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
reject(e);
|
|
92
|
-
} }
|
|
93
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
94
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function __generator(thisArg, body) {
|
|
98
|
-
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
|
99
|
-
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
100
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
101
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
102
|
-
function step(op) {
|
|
103
|
-
if (f)
|
|
104
|
-
throw new TypeError("Generator is already executing.");
|
|
105
|
-
while (_)
|
|
106
|
-
try {
|
|
107
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
108
|
-
return t;
|
|
109
|
-
if (y = 0, t)
|
|
110
|
-
op = [op[0] & 2, t.value];
|
|
111
|
-
switch (op[0]) {
|
|
112
|
-
case 0:
|
|
113
|
-
case 1:
|
|
114
|
-
t = op;
|
|
115
|
-
break;
|
|
116
|
-
case 4:
|
|
117
|
-
_.label++;
|
|
118
|
-
return { value: op[1], done: false };
|
|
119
|
-
case 5:
|
|
120
|
-
_.label++;
|
|
121
|
-
y = op[1];
|
|
122
|
-
op = [0];
|
|
123
|
-
continue;
|
|
124
|
-
case 7:
|
|
125
|
-
op = _.ops.pop();
|
|
126
|
-
_.trys.pop();
|
|
127
|
-
continue;
|
|
128
|
-
default:
|
|
129
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
130
|
-
_ = 0;
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
134
|
-
_.label = op[1];
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
138
|
-
_.label = t[1];
|
|
139
|
-
t = op;
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
if (t && _.label < t[2]) {
|
|
143
|
-
_.label = t[2];
|
|
144
|
-
_.ops.push(op);
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
if (t[2])
|
|
148
|
-
_.ops.pop();
|
|
149
|
-
_.trys.pop();
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
op = body.call(thisArg, _);
|
|
153
|
-
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
op = [6, e];
|
|
156
|
-
y = 0;
|
|
157
|
-
}
|
|
158
|
-
finally {
|
|
159
|
-
f = t = 0;
|
|
160
|
-
}
|
|
161
|
-
if (op[0] & 5)
|
|
162
|
-
throw op[1];
|
|
163
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
167
|
-
if (k2 === undefined)
|
|
168
|
-
k2 = k;
|
|
169
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
|
170
|
-
}) : (function (o, m, k, k2) {
|
|
171
|
-
if (k2 === undefined)
|
|
172
|
-
k2 = k;
|
|
173
|
-
o[k2] = m[k];
|
|
174
|
-
});
|
|
175
|
-
function __exportStar(m, o) {
|
|
176
|
-
for (var p in m)
|
|
177
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
|
178
|
-
__createBinding(o, m, p);
|
|
179
|
-
}
|
|
180
|
-
function __values(o) {
|
|
181
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
182
|
-
if (m)
|
|
183
|
-
return m.call(o);
|
|
184
|
-
if (o && typeof o.length === "number")
|
|
185
|
-
return {
|
|
186
|
-
next: function () {
|
|
187
|
-
if (o && i >= o.length)
|
|
188
|
-
o = void 0;
|
|
189
|
-
return { value: o && o[i++], done: !o };
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
193
|
-
}
|
|
194
|
-
function __read(o, n) {
|
|
195
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
196
|
-
if (!m)
|
|
197
|
-
return o;
|
|
198
|
-
var i = m.call(o), r, ar = [], e;
|
|
199
|
-
try {
|
|
200
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
201
|
-
ar.push(r.value);
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
e = { error: error };
|
|
205
|
-
}
|
|
206
|
-
finally {
|
|
207
|
-
try {
|
|
208
|
-
if (r && !r.done && (m = i["return"]))
|
|
209
|
-
m.call(i);
|
|
210
|
-
}
|
|
211
|
-
finally {
|
|
212
|
-
if (e)
|
|
213
|
-
throw e.error;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return ar;
|
|
217
|
-
}
|
|
218
|
-
/** @deprecated */
|
|
219
|
-
function __spread() {
|
|
220
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
221
|
-
ar = ar.concat(__read(arguments[i]));
|
|
222
|
-
return ar;
|
|
223
|
-
}
|
|
224
|
-
/** @deprecated */
|
|
225
|
-
function __spreadArrays() {
|
|
226
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
227
|
-
s += arguments[i].length;
|
|
228
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
229
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
230
|
-
r[k] = a[j];
|
|
231
|
-
return r;
|
|
232
|
-
}
|
|
233
|
-
function __spreadArray(to, from) {
|
|
234
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
235
|
-
to[j] = from[i];
|
|
236
|
-
return to;
|
|
237
|
-
}
|
|
238
|
-
function __await(v) {
|
|
239
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
240
|
-
}
|
|
241
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
242
|
-
if (!Symbol.asyncIterator)
|
|
243
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
244
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
245
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
246
|
-
function verb(n) { if (g[n])
|
|
247
|
-
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
248
|
-
function resume(n, v) { try {
|
|
249
|
-
step(g[n](v));
|
|
250
|
-
}
|
|
251
|
-
catch (e) {
|
|
252
|
-
settle(q[0][3], e);
|
|
253
|
-
} }
|
|
254
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
255
|
-
function fulfill(value) { resume("next", value); }
|
|
256
|
-
function reject(value) { resume("throw", value); }
|
|
257
|
-
function settle(f, v) { if (f(v), q.shift(), q.length)
|
|
258
|
-
resume(q[0][0], q[0][1]); }
|
|
259
|
-
}
|
|
260
|
-
function __asyncDelegator(o) {
|
|
261
|
-
var i, p;
|
|
262
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
263
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
264
|
-
}
|
|
265
|
-
function __asyncValues(o) {
|
|
266
|
-
if (!Symbol.asyncIterator)
|
|
267
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
268
|
-
var m = o[Symbol.asyncIterator], i;
|
|
269
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
270
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
271
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
|
272
|
-
}
|
|
273
|
-
function __makeTemplateObject(cooked, raw) {
|
|
274
|
-
if (Object.defineProperty) {
|
|
275
|
-
Object.defineProperty(cooked, "raw", { value: raw });
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
cooked.raw = raw;
|
|
279
|
-
}
|
|
280
|
-
return cooked;
|
|
281
|
-
}
|
|
282
|
-
;
|
|
283
|
-
var __setModuleDefault = Object.create ? (function (o, v) {
|
|
284
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
285
|
-
}) : function (o, v) {
|
|
286
|
-
o["default"] = v;
|
|
287
|
-
};
|
|
288
|
-
function __importStar(mod) {
|
|
289
|
-
if (mod && mod.__esModule)
|
|
290
|
-
return mod;
|
|
291
|
-
var result = {};
|
|
292
|
-
if (mod != null)
|
|
293
|
-
for (var k in mod)
|
|
294
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
295
|
-
__createBinding(result, mod, k);
|
|
296
|
-
__setModuleDefault(result, mod);
|
|
297
|
-
return result;
|
|
298
|
-
}
|
|
299
|
-
function __importDefault(mod) {
|
|
300
|
-
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
301
|
-
}
|
|
302
|
-
function __classPrivateFieldGet(receiver, privateMap) {
|
|
303
|
-
if (!privateMap.has(receiver)) {
|
|
304
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
305
|
-
}
|
|
306
|
-
return privateMap.get(receiver);
|
|
307
|
-
}
|
|
308
|
-
function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
309
|
-
if (!privateMap.has(receiver)) {
|
|
310
|
-
throw new TypeError("attempted to set private field on non-instance");
|
|
311
|
-
}
|
|
312
|
-
privateMap.set(receiver, value);
|
|
313
|
-
return value;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Dizionario di invalidazioni delle chiamate HTTP
|
|
318
|
-
*/
|
|
319
|
-
var HTTP_INVALIDATION = new core.InjectionToken('HTTP_INVALIDATION');
|
|
320
|
-
/**
|
|
321
|
-
* Durata della cache lato libreria dopo il quale la cache verrà ripulita
|
|
322
|
-
*/
|
|
323
|
-
var CLIENT_CACHE_DURATION_S = new core.InjectionToken('CLIENT_CACHE_DURATION_S');
|
|
324
|
-
/**
|
|
325
|
-
* URL del Backend a cui inviare le chiamate
|
|
326
|
-
*/
|
|
327
|
-
var BACKEND_URL = new core.InjectionToken('BACKEND_URL');
|
|
328
|
-
/**
|
|
329
|
-
* Locale della libreria per messaggi d'errore ed Header di default "Accept-Language". Sono supportati "it-IT" ed "en-US"
|
|
330
|
-
*/
|
|
331
|
-
var HTTP_LOCALE = new core.InjectionToken('HTTP_LOCALE');
|
|
332
|
-
/**
|
|
333
|
-
* Nome dell'APP utilizzato per creare le chiavi delle cache specifiche per l'applicazione corrente
|
|
334
|
-
*/
|
|
335
|
-
var APP_NAME = new core.InjectionToken('APP_NAME');
|
|
336
|
-
/**
|
|
337
|
-
* Indica se utilizzare l'identificativo utente nella cache
|
|
338
|
-
*/
|
|
339
|
-
var CACHE_BY_USER = new core.InjectionToken('CACHE_BY_USER');
|
|
340
|
-
/**
|
|
341
|
-
* Indica se fare log nella console ad ogni azione significativa
|
|
342
|
-
*/
|
|
343
|
-
var DEBUG_MODE = new core.InjectionToken('DEBUG_MODE');
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Classe d'estensione che permette di modificare il comportamento della libreria negli hook definiti da interfaccia, in modo da poterla adattare
|
|
347
|
-
* con un certo grado di customizzazione a qualsiasi struttura di frontend
|
|
348
|
-
*/
|
|
349
|
-
var HttpServiceExtensions = /** @class */ (function () {
|
|
350
|
-
function HttpServiceExtensions() {
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Hook per recuperare l'access token con cui effettuare le chiamate HTTP
|
|
354
|
-
*/
|
|
355
|
-
HttpServiceExtensions.prototype.retrieveAccessToken = function () {
|
|
356
|
-
return "";
|
|
357
|
-
};
|
|
358
|
-
/**
|
|
359
|
-
* Hook per recuperare l'Identity corrente in un oggetto generico con le informazioni di User e Tenant
|
|
360
|
-
*/
|
|
361
|
-
HttpServiceExtensions.prototype.retrieveIdentity = function () {
|
|
362
|
-
return null;
|
|
363
|
-
};
|
|
364
|
-
/**
|
|
365
|
-
* Hook per leggere dallo stato dell'applicazione se stiamo già venendo ridirezionati al login, in modo da non tentare di effettuare
|
|
366
|
-
* N redirect contemporaneamente qualora molte API fallissero allo stesso tempo nell'autenticazione
|
|
367
|
-
*/
|
|
368
|
-
HttpServiceExtensions.prototype.readRedirectingToLogin = function () {
|
|
369
|
-
return false;
|
|
370
|
-
};
|
|
371
|
-
/**
|
|
372
|
-
* Hook per scrivere nello stato dell'applicazione se stiamo effettuando un redirect al login o meno
|
|
373
|
-
*/
|
|
374
|
-
HttpServiceExtensions.prototype.writeRedirectingToLogin = function (status) {
|
|
375
|
-
};
|
|
376
|
-
/**
|
|
377
|
-
* Hook per effettuare il redirect al login
|
|
378
|
-
*/
|
|
379
|
-
HttpServiceExtensions.prototype.redirectToLogin = function () {
|
|
380
|
-
};
|
|
381
|
-
/**
|
|
382
|
-
* Hook per leggere dallo stato dell'applicazione se stiamo già gestendo un errore, in modo da non tentare di gestire
|
|
383
|
-
* N errori contemporaneamente qualora molte API fallissero allo stesso tempo
|
|
384
|
-
*/
|
|
385
|
-
HttpServiceExtensions.prototype.readHandlingErrorStatus = function () {
|
|
386
|
-
return false;
|
|
387
|
-
};
|
|
388
|
-
/**
|
|
389
|
-
* Hook per scrivere nello stato dell'applicazione se stiamo gestendo un errore o meno
|
|
390
|
-
*/
|
|
391
|
-
HttpServiceExtensions.prototype.writeHandlingErrorStatus = function (status) {
|
|
392
|
-
};
|
|
393
|
-
/**
|
|
394
|
-
* Hook per leggere dallo stato dell'applicazione se stiamo già gestendo un redirect, in modo da non tentare di gestire
|
|
395
|
-
* N redirect contemporaneamente qualora molte API lo richiedessero allo stesso tempo
|
|
396
|
-
*/
|
|
397
|
-
HttpServiceExtensions.prototype.readRedirectionStatus = function () {
|
|
398
|
-
return false;
|
|
399
|
-
};
|
|
400
|
-
/**
|
|
401
|
-
* Hook per scrivere nello stato dell'applicazione se stiamo gestendo un redirect o meno
|
|
402
|
-
*/
|
|
403
|
-
HttpServiceExtensions.prototype.writeRedirectionStatus = function (status) {
|
|
404
|
-
};
|
|
405
|
-
/**
|
|
406
|
-
* Hook per indicare se l'applicazione può gestire eccezioni del tipo "NotConfigured" (444). Qualora l'applicazione che lo implementa dichiari di gestirle verrà chiamata
|
|
407
|
-
* la funzione **handleBlockingException** per ognuno di questi errori
|
|
408
|
-
*/
|
|
409
|
-
HttpServiceExtensions.prototype.handleNotConfiguredException = function () {
|
|
410
|
-
return false;
|
|
411
|
-
};
|
|
412
|
-
/**
|
|
413
|
-
* Hook per la gestione di un qualsiasi errore bloccante per l'operazione attuale, ma non fatale (Generalmente gestibile da dialog di avviso)
|
|
414
|
-
*/
|
|
415
|
-
HttpServiceExtensions.prototype.handleBlockingException = function (status, text) {
|
|
416
|
-
console.error("ESHttpError Blocking Exception " + status + " " + text);
|
|
417
|
-
};
|
|
418
|
-
/**
|
|
419
|
-
* Hook per la gestione di un qualsiasi errore fatale (Generalmente gestibile tramite navigazione a una pagina di errore custom per l'applicativo)
|
|
420
|
-
*/
|
|
421
|
-
HttpServiceExtensions.prototype.handleException = function (status, text) {
|
|
422
|
-
console.error("ESHttpError " + status + " " + text);
|
|
423
|
-
};
|
|
424
|
-
return HttpServiceExtensions;
|
|
425
|
-
}());
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Oggetto statico di localizzazione per i messaggi
|
|
429
|
-
*/
|
|
430
|
-
var Loc = {
|
|
431
|
-
"Result for": { "en-US": "Result for", "it-IT": "Risultato per", },
|
|
432
|
-
"retrieved from cache": { "en-US": "retrieved from cache", "it-IT": "recuperato dalla cache", },
|
|
433
|
-
"Cached result for": { "en-US": "Cached result for", "it-IT": "Messo in cache risultato per", },
|
|
434
|
-
"Starting call": { "en-US": "Starting call", "it-IT": "Inizio la chiamata", },
|
|
435
|
-
"at URL": { "en-US": "at URL", "it-IT": "all'URL", },
|
|
436
|
-
"Invlalidating cache element": { "en-US": "Invlalidating cache element", "it-IT": "Invalido elemento della cache", },
|
|
437
|
-
"Finalizing call": { "en-US": "Finalizing call", "it-IT": "Finalizzo chiamata", },
|
|
438
|
-
"with status": { "en-US": "with status", "it-IT": "con stato", },
|
|
439
|
-
"Success": { "en-US": "Success", "it-IT": "Successso", },
|
|
440
|
-
"Failure": { "en-US": "Failure", "it-IT": "Fallimento", },
|
|
441
|
-
"Error 401 on call": { "en-US": "Error 401 on call", "it-IT": "Errore 401 su chiamata", },
|
|
442
|
-
"with redirect already in progress. Ignoring this event": { "en-US": "with redirect already in progress. Ignoring this event", "it-IT": "con redirezione già in corso. Ignoro l'evento", },
|
|
443
|
-
"redirecting to login": { "en-US": "redirecting to login", "it-IT": "redireziono al login", },
|
|
444
|
-
"Redirecting to Login, ignoring HTTP error on call": { "en-US": "Redirecting to Login, ignoring HTTP error on call", "it-IT": "Redireziono al login ignorando errori sulla chiamata", },
|
|
445
|
-
"Already Handling an error, ignoring HTTP error on call": { "en-US": "Already Handling an error, ignoring HTTP error on call", "it-IT": "sto già gestendo un errore, ignoro quello corrente per la chiamata HTTP", },
|
|
446
|
-
"Error 444 on call": { "en-US": "Error 444 on call", "it-IT": "Errore 444 su chiamata" },
|
|
447
|
-
"Resource not found": { "en-US": "Resource not found", "it-IT": "Risorsa non trovata" }
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Servizio utilizzato per effettuare qualsiasi tipo di chiamata HTTP dall'applicazione, gestisce errori e cache delle risposte nativamente e ne può essere
|
|
452
|
-
* esteso/modificato il comportamento implementando la classe di "hook" **IHttpServiceExtensions** e registrandola nel provider della classe **HttpServiceExtensions**
|
|
453
|
-
*/
|
|
454
|
-
var HTTPService = /** @class */ (function () {
|
|
455
|
-
/**
|
|
456
|
-
* @ignore
|
|
457
|
-
*/
|
|
458
|
-
function HTTPService(BACKEND_URL, EXTENSION_CLASS, HTTP_INVALIDATION, LOCALE, APP_NAME, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, DEBUG_MODE, http) {
|
|
459
|
-
var _a, _b;
|
|
460
|
-
this.BACKEND_URL = BACKEND_URL;
|
|
461
|
-
this.EXTENSION_CLASS = EXTENSION_CLASS;
|
|
462
|
-
this.HTTP_INVALIDATION = HTTP_INVALIDATION;
|
|
463
|
-
this.LOCALE = LOCALE;
|
|
464
|
-
this.APP_NAME = APP_NAME;
|
|
465
|
-
this.CLIENT_CACHE_DURATION_S = CLIENT_CACHE_DURATION_S;
|
|
466
|
-
this.CACHE_BY_USER = CACHE_BY_USER;
|
|
467
|
-
this.DEBUG_MODE = DEBUG_MODE;
|
|
468
|
-
this.http = http;
|
|
469
|
-
/**
|
|
470
|
-
* Cache dello stato delle chiamate HTTP attualmente effettuate. Ogni chiamata è rappresentata da un GUID e lo status assume valore **false** solo sugli errori
|
|
471
|
-
*/
|
|
472
|
-
this.callStatus = {};
|
|
473
|
-
/**
|
|
474
|
-
* Nome della cache in cui vengono storicizzate le informazioni sulle risposte delle chiamate sotto forma di dictionary
|
|
475
|
-
*/
|
|
476
|
-
this.localStorageHttpCacheKey = null;
|
|
477
|
-
/**
|
|
478
|
-
* Nome della cache in cui vengono storicizzate le informazioni sulle risposte delle chiamate sotto forma di dictionary, solo per le chiamate con un tempo definito di caching
|
|
479
|
-
*/
|
|
480
|
-
this.localStorageHttpTimedCacheKey = null;
|
|
481
|
-
/**
|
|
482
|
-
* Nome della cache in cui vengono storicizzate le informazioni sullo scadere della cache stessa
|
|
483
|
-
*/
|
|
484
|
-
this.localStorageHttpCacheExpireKey = null;
|
|
485
|
-
/**
|
|
486
|
-
* Identità collegata al token di autenticazione da usare, richiesta al programma che utilizza la libreria attraverso l'hook **retrieveIdentity** della **HttpServiceExtensions**
|
|
487
|
-
*/
|
|
488
|
-
this.me = null;
|
|
489
|
-
this.ExtensionsImpl = this.EXTENSION_CLASS || new HttpServiceExtensions();
|
|
490
|
-
this.me = this.ExtensionsImpl.retrieveIdentity();
|
|
491
|
-
this.localStorageHttpCacheKey = ((_a = this.APP_NAME) !== null && _a !== void 0 ? _a : "APP").replace(/\s/g, '_') + "_HttpCache";
|
|
492
|
-
this.localStorageHttpTimedCacheKey = ((_b = this.APP_NAME) !== null && _b !== void 0 ? _b : "APP").replace(/\s/g, '_') + "_HttpTimedCache";
|
|
493
|
-
this.localStorageHttpCacheExpireKey = this.localStorageHttpCacheKey + "_Expire";
|
|
494
|
-
if (this.untimedCacheExpired())
|
|
495
|
-
this.resetHttpUntimedCacheStorage();
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Esecuzione di una GET HTTP con eventualmente la gestione della cache qualora la chiamata termini con la convenzione "#cache"
|
|
499
|
-
*
|
|
500
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
501
|
-
* @param {HttpParams} params Parametri della chiamata
|
|
502
|
-
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
503
|
-
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
504
|
-
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
505
|
-
* @param {Function} errorCallback Callback chiamato in caso di errore
|
|
506
|
-
*
|
|
507
|
-
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
508
|
-
*/
|
|
509
|
-
HTTPService.prototype.get = function (url, params, transaction, succesfulResultMandatory, errorCallback) {
|
|
510
|
-
var _this = this;
|
|
511
|
-
if (params === void 0) { params = null; }
|
|
512
|
-
if (transaction === void 0) { transaction = ""; }
|
|
513
|
-
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
514
|
-
if (errorCallback === void 0) { errorCallback = null; }
|
|
515
|
-
var myGuid = this.defaultStartCall(url);
|
|
516
|
-
var cachedInfos = this.tryGetCacheInformations(url, params);
|
|
517
|
-
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
518
|
-
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
519
|
-
return rxjs.of(cachedInfos.cacheItem).pipe(operators.delay(0), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
520
|
-
}
|
|
521
|
-
var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(transaction), params: params });
|
|
522
|
-
return httpCall.pipe(operators.map(function (res) {
|
|
523
|
-
var responseItem = res;
|
|
524
|
-
if (cachedInfos.cache) {
|
|
525
|
-
_this.cacheResponse(responseItem, cachedInfos);
|
|
526
|
-
_this.log(_this.loc("Cached result for") + " " + url);
|
|
527
|
-
}
|
|
528
|
-
return responseItem;
|
|
529
|
-
}), operators.catchError(function (err, caught) {
|
|
530
|
-
if (errorCallback)
|
|
531
|
-
errorCallback();
|
|
532
|
-
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
533
|
-
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
534
|
-
};
|
|
535
|
-
/**
|
|
536
|
-
* Esecuzione di una GET HTTP con eventualmente la gestione della cache qualora la chiamata termini con la convenzione "#cache"
|
|
537
|
-
*
|
|
538
|
-
* Caso specifico di chiamata che deve restituire un Blob o un ArrayBuffer nativo da elaborare
|
|
539
|
-
*
|
|
540
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
541
|
-
* @param {HttpParams} params Parametri della chiamata
|
|
542
|
-
* @param {"arraybuffer"| "blob"} type Tipo di ritorno richiesto
|
|
543
|
-
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
544
|
-
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
545
|
-
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
546
|
-
* @param {Function} errorCallback Callback chiamato in caso di errore
|
|
547
|
-
*
|
|
548
|
-
* @returns {Observable<Blob | ArrayBuffer>} Observable che contiene il risultato della chiamata
|
|
549
|
-
*/
|
|
550
|
-
HTTPService.prototype.getRaw = function (url, params, type, transaction, succesfulResultMandatory, errorCallback) {
|
|
551
|
-
var _this = this;
|
|
552
|
-
if (params === void 0) { params = null; }
|
|
553
|
-
if (type === void 0) { type = "arraybuffer"; }
|
|
554
|
-
if (transaction === void 0) { transaction = ""; }
|
|
555
|
-
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
556
|
-
if (errorCallback === void 0) { errorCallback = null; }
|
|
557
|
-
var myGuid = this.defaultStartCall(url);
|
|
558
|
-
var cachedInfos = this.tryGetCacheInformations(url, params);
|
|
559
|
-
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
560
|
-
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
561
|
-
return rxjs.of(cachedInfos.cacheItem).pipe(operators.delay(0), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
562
|
-
}
|
|
563
|
-
var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(transaction), params: params });
|
|
564
|
-
return httpCall.pipe(operators.map(function (blob) {
|
|
565
|
-
if (cachedInfos.cache) {
|
|
566
|
-
_this.cacheResponse(blob, cachedInfos);
|
|
567
|
-
_this.log(_this.loc("Cached result for") + " " + url);
|
|
568
|
-
}
|
|
569
|
-
return blob;
|
|
570
|
-
}), operators.catchError(function (err, caught) {
|
|
571
|
-
if (errorCallback)
|
|
572
|
-
errorCallback();
|
|
573
|
-
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
574
|
-
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
575
|
-
};
|
|
576
|
-
/**
|
|
577
|
-
* Esecuzione di una POST HTTP
|
|
578
|
-
*
|
|
579
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
580
|
-
* @param {any} bodyData DTO per la chiamata
|
|
581
|
-
* @param {HttpParams} params Parametri della chiamata
|
|
582
|
-
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
583
|
-
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
584
|
-
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
585
|
-
*
|
|
586
|
-
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
587
|
-
*/
|
|
588
|
-
HTTPService.prototype.post = function (url, bodyData, params, transaction, succesfulResultMandatory) {
|
|
589
|
-
var _this = this;
|
|
590
|
-
if (params === void 0) { params = null; }
|
|
591
|
-
if (transaction === void 0) { transaction = ""; }
|
|
592
|
-
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
593
|
-
var myGuid = this.defaultStartCall(url);
|
|
594
|
-
var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
595
|
-
return httpCall.pipe(operators.map(function (res) {
|
|
596
|
-
var responseItem = res;
|
|
597
|
-
return responseItem;
|
|
598
|
-
}), operators.catchError(function (err, caught) {
|
|
599
|
-
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
600
|
-
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
601
|
-
};
|
|
602
|
-
/**
|
|
603
|
-
* Esecuzione di una DELETE HTTP
|
|
604
|
-
*
|
|
605
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
606
|
-
* @param {HttpParams} params Parametri della chiamata
|
|
607
|
-
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
608
|
-
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
609
|
-
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
610
|
-
*
|
|
611
|
-
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
612
|
-
*/
|
|
613
|
-
HTTPService.prototype.delete = function (url, params, transaction, succesfulResultMandatory) {
|
|
614
|
-
var _this = this;
|
|
615
|
-
if (params === void 0) { params = null; }
|
|
616
|
-
if (transaction === void 0) { transaction = ""; }
|
|
617
|
-
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
618
|
-
var myGuid = this.defaultStartCall(url);
|
|
619
|
-
var httpCall = this.http.delete(url, { headers: this.getHeaders(transaction), params: params });
|
|
620
|
-
return httpCall.pipe(operators.map(function (res) {
|
|
621
|
-
var responseItem = res;
|
|
622
|
-
return responseItem;
|
|
623
|
-
}), operators.catchError(function (err, caught) {
|
|
624
|
-
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
625
|
-
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
626
|
-
};
|
|
627
|
-
/**
|
|
628
|
-
* Esecuzione di una PUT HTTP
|
|
629
|
-
*
|
|
630
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
631
|
-
* @param {any} bodyData DTO per la chiamata
|
|
632
|
-
* @param {HttpParams} params Parametri della chiamata
|
|
633
|
-
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
634
|
-
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
635
|
-
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
636
|
-
*
|
|
637
|
-
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
638
|
-
*/
|
|
639
|
-
HTTPService.prototype.put = function (url, bodyData, params, transaction, succesfulResultMandatory) {
|
|
640
|
-
var _this = this;
|
|
641
|
-
if (params === void 0) { params = null; }
|
|
642
|
-
if (transaction === void 0) { transaction = ""; }
|
|
643
|
-
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
644
|
-
var myGuid = this.defaultStartCall(url);
|
|
645
|
-
var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
646
|
-
return httpCall.pipe(operators.map(function (res) {
|
|
647
|
-
var responseItem = res;
|
|
648
|
-
return responseItem;
|
|
649
|
-
}), operators.catchError(function (err, caught) {
|
|
650
|
-
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
651
|
-
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
652
|
-
};
|
|
653
|
-
/**
|
|
654
|
-
* Esecuzione di una POST HTTP
|
|
655
|
-
*
|
|
656
|
-
* Casistica particolare in cui bisogna anche inviare dei File
|
|
657
|
-
*
|
|
658
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
659
|
-
* @param {any} bodyData DTO per la chiamata
|
|
660
|
-
* @param {File[] | File} fileArrayOrFile Singolo file o lista di file da inviare. Il tipo **File** è quello nativo del Javascript
|
|
661
|
-
*
|
|
662
|
-
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
663
|
-
*/
|
|
664
|
-
HTTPService.prototype.postwithFiles = function (url, bodyData, fileArrayOrFile) {
|
|
665
|
-
var _this = this;
|
|
666
|
-
var myGuid = this.defaultStartCall(url);
|
|
667
|
-
var formData = this.getFilesFormData(fileArrayOrFile);
|
|
668
|
-
formData.append("body", JSON.stringify(bodyData));
|
|
669
|
-
var httpCall = this.http.post(url, formData, { headers: this.getHeaders(null, true, null, null) });
|
|
670
|
-
return httpCall.pipe(operators.catchError(function (err, caught) { return _this.registerErrorAndReturnEmptyObservable(err, myGuid); }), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
671
|
-
};
|
|
672
|
-
/**
|
|
673
|
-
* Esecuzione di una POST HTTP
|
|
674
|
-
*
|
|
675
|
-
* Casistica particolare in cui viene restituito un file gestito come ObjectURL il cui URL si può gestire dal parametro di callback **getFileCallback**.
|
|
676
|
-
* La chiamata non ha un tipo restituito in quanto il risultato dev'essere gestito attraverso la callback **getFileCallback**
|
|
677
|
-
*
|
|
678
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
679
|
-
* @param {K} bodyData DTO per la chiamata
|
|
680
|
-
* @param {string} filename Nome del file che si sta richiedendo, rimane lato Frontend e serve per assegnare arbitrariamente un nome al file restituito, se vuoto viene utilizzata la Content-Disposition della risposta
|
|
681
|
-
* @param {Function} getFileCallback Callback a due parametri (url: string, filename: string) per gestire il risultato del file richiesto. **Utilizzare UtilityService.fileDownload** di @esfaenza/extensions
|
|
682
|
-
* @param {Function} afterGetFile Callback da chiamare dopo aver gestito la risposta del **getFileCallback**, in caso **handleError** fosse **false** verrà richiamato anche in caso di errore
|
|
683
|
-
* @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
|
|
684
|
-
*/
|
|
685
|
-
HTTPService.prototype.postGetFile = function (url, bodyData, filename, getFileCallback, afterGetFile, handleError) {
|
|
686
|
-
var _this = this;
|
|
687
|
-
if (afterGetFile === void 0) { afterGetFile = null; }
|
|
688
|
-
if (handleError === void 0) { handleError = true; }
|
|
689
|
-
var myGuid = this.defaultStartCall(url);
|
|
690
|
-
this.http.post(url, bodyData, { headers: this.getHeaders(), observe: 'response', responseType: "blob" }).pipe(operators.catchError(function (err, caught) {
|
|
691
|
-
if (afterGetFile && !handleError)
|
|
692
|
-
afterGetFile();
|
|
693
|
-
return _this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
694
|
-
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); })).subscribe(function (response) {
|
|
695
|
-
var _a, _b, _c, _d;
|
|
696
|
-
var retUrl = window.URL.createObjectURL(response.body);
|
|
697
|
-
var fn = (_d = (_c = (_b = (_a = response.headers.get('content-disposition')) === null || _a === void 0 ? void 0 : _a.split(';')[1]) === null || _b === void 0 ? void 0 : _b.split('filename')[1]) === null || _c === void 0 ? void 0 : _c.split('=')[1]) === null || _d === void 0 ? void 0 : _d.trim().replace(/\"/g, '');
|
|
698
|
-
getFileCallback(retUrl, filename || fn);
|
|
699
|
-
if (afterGetFile)
|
|
700
|
-
afterGetFile();
|
|
701
|
-
});
|
|
702
|
-
};
|
|
703
|
-
/**
|
|
704
|
-
* Esecuzione di una GET HTTP
|
|
705
|
-
*
|
|
706
|
-
* Casistica particolare in cui viene restituito un file gestito come ObjectURL il cui URL si può gestire dal parametro di callback **getFileCallback**.
|
|
707
|
-
* La chiamata non ha un tipo restituito in quanto il risultato dev'essere gestito attraverso la callback **getFileCallback**
|
|
708
|
-
*
|
|
709
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
710
|
-
* @param {HttpParams} params Parametri della chiamata
|
|
711
|
-
* @param {string} filename Nome del file che si sta richiedendo, rimane lato Frontend e serve per assegnare arbitrariamente un nome al file restituito, se vuoto viene utilizzata la Content-Disposition della risposta
|
|
712
|
-
* @param {Function} getFileCallback Callback a due parametri (url: string, filename: string) per gestire il risultato del file richiesto. **Utilizzare UtilityService.fileDownload** di @esfaenza/extensions
|
|
713
|
-
* @param {Function} afterGetFile Callback da chiamare dopo aver gestito la risposta del **getFileCallback**, in caso **handleError** fosse **false** verrà richiamato anche in caso di errore
|
|
714
|
-
* @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
|
|
715
|
-
*/
|
|
716
|
-
HTTPService.prototype.getFile = function (url, params, filename, getFileCallback, afterGetFile, handleError) {
|
|
717
|
-
var _this = this;
|
|
718
|
-
if (params === void 0) { params = null; }
|
|
719
|
-
if (afterGetFile === void 0) { afterGetFile = null; }
|
|
720
|
-
if (handleError === void 0) { handleError = true; }
|
|
721
|
-
var myGuid = this.defaultStartCall(url);
|
|
722
|
-
this.http.get(url, { params: params, headers: this.getHeaders(), observe: 'response', responseType: "blob" }).pipe(operators.catchError(function (err, caught) {
|
|
723
|
-
if (afterGetFile && !handleError)
|
|
724
|
-
afterGetFile();
|
|
725
|
-
return _this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
726
|
-
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); })).subscribe(function (response) {
|
|
727
|
-
var _a, _b, _c, _d;
|
|
728
|
-
var retUrl = window.URL.createObjectURL(response.body);
|
|
729
|
-
var fn = (_d = (_c = (_b = (_a = response.headers.get('content-disposition')) === null || _a === void 0 ? void 0 : _a.split(';')[1]) === null || _b === void 0 ? void 0 : _b.split('filename')[1]) === null || _c === void 0 ? void 0 : _c.split('=')[1]) === null || _d === void 0 ? void 0 : _d.trim().replace(/\"/g, '');
|
|
730
|
-
getFileCallback(retUrl, filename || fn);
|
|
731
|
-
if (afterGetFile)
|
|
732
|
-
afterGetFile();
|
|
733
|
-
});
|
|
734
|
-
};
|
|
735
|
-
/**
|
|
736
|
-
* Download nativo di un file. Internamente utilizza il pattern **window.location.href = "..."**
|
|
737
|
-
*
|
|
738
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
739
|
-
* @param {HttpParams} params Parametri della chiamata
|
|
740
|
-
*/
|
|
741
|
-
HTTPService.prototype.getFileNative = function (url, params) {
|
|
742
|
-
if (params === void 0) { params = null; }
|
|
743
|
-
var finalUrl = url + (params ? "?" + params.toString() : "");
|
|
744
|
-
window.location.href = finalUrl;
|
|
745
|
-
};
|
|
746
|
-
/**
|
|
747
|
-
* Esecuzione di una GET di un file che emette i vari eventi di progresso di download.
|
|
748
|
-
* Utilizzarla per overridare la dialog nativa di progress del browser e sostituirla con qualcosa tipo quello che fa MEGA.
|
|
749
|
-
*
|
|
750
|
-
* In caso si voglia ottenere il risultato nativo del browser del download utilizzare **getFileNative(url, pars)**
|
|
751
|
-
*
|
|
752
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
753
|
-
* @param {HttpParams} params Parametri della chiamata
|
|
754
|
-
* @param {Function} getFileCallback Callback a due parametri (url: string, filename: string) per gestire il risultato del file richiesto. **Utilizzare UtilityService.fileDownload** di @esfaenza/extensions
|
|
755
|
-
*
|
|
756
|
-
* @returns {Observable<Download>} Observable dei vari step di progresso del download
|
|
757
|
-
*/
|
|
758
|
-
HTTPService.prototype.getFileWithProgress = function (url, params, getFileCallback) {
|
|
759
|
-
var _this = this;
|
|
760
|
-
if (params === void 0) { params = null; }
|
|
761
|
-
var myGuid = this.defaultStartCall(url);
|
|
762
|
-
return this.http.get(url, { responseType: 'blob', headers: this.getHeaders(), params: params, observe: 'events', reportProgress: true })
|
|
763
|
-
.pipe(operators.scan(function (previous, event) {
|
|
764
|
-
if (_this.isHttpProgressEvent(event)) {
|
|
765
|
-
var progress = event.total ? (event.loaded > event.total ? 100 : Math.round((100 * event.loaded) / event.total)) : previous.progress;
|
|
766
|
-
return { progress: progress, state: 'IN_PROGRESS', content: null };
|
|
767
|
-
}
|
|
768
|
-
if (_this.isHttpResponse(event)) {
|
|
769
|
-
if (event.body) {
|
|
770
|
-
var cdisp = event.headers.get('content-disposition');
|
|
771
|
-
var cdispFilename = cdisp.split(';')[1].split('filename')[1].split('=')[1].trim().replace(/\"/g, '');
|
|
772
|
-
var retUrl = window.URL.createObjectURL(event.body);
|
|
773
|
-
getFileCallback(retUrl, cdispFilename);
|
|
774
|
-
}
|
|
775
|
-
return { progress: 100, state: 'DONE', content: event.body };
|
|
776
|
-
}
|
|
777
|
-
return previous;
|
|
778
|
-
}, { state: 'PENDING', progress: 0, content: null }), operators.catchError(function (err, _) { return _this.registerErrorAndReturnEmptyObservable(err, myGuid); }), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
779
|
-
};
|
|
780
|
-
/**
|
|
781
|
-
* Riconosce se l'evento HTTP è di tipo **HttpResponse** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
782
|
-
*/
|
|
783
|
-
HTTPService.prototype.isHttpResponse = function (event) {
|
|
784
|
-
return event.type === http.HttpEventType.Response;
|
|
785
|
-
};
|
|
786
|
-
/**
|
|
787
|
-
* Riconosce se l'evento HTTP è di tipo **HttpProgressEvent** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
788
|
-
*/
|
|
789
|
-
HTTPService.prototype.isHttpProgressEvent = function (event) {
|
|
790
|
-
return event.type === http.HttpEventType.DownloadProgress || event.type === http.HttpEventType.UploadProgress;
|
|
791
|
-
};
|
|
792
|
-
/**
|
|
793
|
-
* Gestione dell'inizio di una chiamata ad un certo URL, viene generato un GUID da assegnarci, controllata la scadenza della cache,
|
|
794
|
-
* e eventualmente loggato il fatto che sta per essere effettuata una chiamata HTTP
|
|
795
|
-
*
|
|
796
|
-
* @param {string} url Url a cui effettuare la chiamata
|
|
797
|
-
* @returns {string} GUID assegnato alla chiamata
|
|
798
|
-
*/
|
|
799
|
-
HTTPService.prototype.defaultStartCall = function (url) {
|
|
800
|
-
var myGuid = this.getGUID();
|
|
801
|
-
this.checkCacheInvalidation(url);
|
|
802
|
-
this.callStatus[myGuid] = true;
|
|
803
|
-
this.log(this.loc("Starting call") + " " + myGuid + " " + this.loc("at URL") + ": " + url);
|
|
804
|
-
return myGuid;
|
|
805
|
-
};
|
|
806
|
-
/**
|
|
807
|
-
* Dato un url vengono controllate le informazioni su tutti gli url da invalidare collegati all'url chiamato e, se presenti in cache, invalidati
|
|
808
|
-
*
|
|
809
|
-
* @param {string} url URL per cui controllare se ci sono chiamate in cache da invalidare
|
|
810
|
-
*/
|
|
811
|
-
HTTPService.prototype.checkCacheInvalidation = function (url) {
|
|
812
|
-
var _this = this;
|
|
813
|
-
var cache = JSON.parse(localStorage.getItem(this.localStorageHttpCacheKey));
|
|
814
|
-
var tmp = /#cache(:?-(\d+))/gi.exec(url);
|
|
815
|
-
var cacheTime = tmp ? tmp[2] : null;
|
|
816
|
-
var normalizedUrl = url.replace("#cache" + (cacheTime ? "-" + cacheTime : ""), "").replace(this.BACKEND_URL, "");
|
|
817
|
-
if (!cache || !this.HTTP_INVALIDATION || !this.HTTP_INVALIDATION[normalizedUrl])
|
|
818
|
-
return;
|
|
819
|
-
var apisToInvalidate = this.HTTP_INVALIDATION[normalizedUrl];
|
|
820
|
-
if (!apisToInvalidate || apisToInvalidate.length == 0)
|
|
821
|
-
return;
|
|
822
|
-
var keysToRemove = [];
|
|
823
|
-
apisToInvalidate.forEach(function (api) {
|
|
824
|
-
var cacheKey = _this.makeCacheKey(api, null);
|
|
825
|
-
for (var item in cache)
|
|
826
|
-
if (item.indexOf(cacheKey) != -1)
|
|
827
|
-
keysToRemove.push(item);
|
|
828
|
-
});
|
|
829
|
-
for (var i = 0; i < keysToRemove.length; i++) {
|
|
830
|
-
var k = keysToRemove[i];
|
|
831
|
-
this.log(this.loc("Invlalidating cache element") + " " + k);
|
|
832
|
-
delete cache[k];
|
|
833
|
-
}
|
|
834
|
-
localStorage.setItem(this.localStorageHttpCacheKey, JSON.stringify(cache));
|
|
835
|
-
};
|
|
836
|
-
/**
|
|
837
|
-
* Finalizzazione di una chiamata
|
|
838
|
-
*
|
|
839
|
-
* @param {string} guid GUID collegato alla chiamata appena terminata
|
|
840
|
-
*/
|
|
841
|
-
HTTPService.prototype.tryFinalizeByGuid = function (guid) {
|
|
842
|
-
this.log(this.loc("Finalizing call") + " " + guid + " " + this.loc("with status") + ": " + (this.callStatus[guid] ? this.loc('Success') : this.loc('Failure')));
|
|
843
|
-
//Alla prima chiamata buona, significa che almeno il login ce l'ho. Posso mettermi in modalità redirectInProgress false
|
|
844
|
-
//e riiniziare a valutare errori di javashit
|
|
845
|
-
if (this.callStatus[guid] && this.ExtensionsImpl.readRedirectionStatus())
|
|
846
|
-
this.ExtensionsImpl.writeRedirectionStatus(false);
|
|
847
|
-
//In ogni caso questa posso rimuoverla
|
|
848
|
-
delete this.callStatus[guid];
|
|
849
|
-
};
|
|
850
|
-
/**
|
|
851
|
-
* Helper che dato un unico File o una lista di File crea un oggetto FormData che può essere inviato comodamente
|
|
852
|
-
* ad un backend ASP.NET da cui si potrà accedere a Request.Form.Files
|
|
853
|
-
*
|
|
854
|
-
* @param {File | File[]} fileArrayOrFile Singolo File o lista di File. N.B: nella firma della funzione viene considerato **any** per fare test sulle proprietà
|
|
855
|
-
* invece che fare test con l'**istanceof**
|
|
856
|
-
*
|
|
857
|
-
* @returns {FormData} FormData contenente tutti i file passati
|
|
858
|
-
*/
|
|
859
|
-
HTTPService.prototype.getFilesFormData = function (fileArrayOrFile) {
|
|
860
|
-
var formData = new FormData();
|
|
861
|
-
if (fileArrayOrFile) {
|
|
862
|
-
if (fileArrayOrFile.length)
|
|
863
|
-
fileArrayOrFile.forEach(function (t) { formData.append("file", t, t.name); });
|
|
864
|
-
else if (fileArrayOrFile.name)
|
|
865
|
-
formData.append("files", fileArrayOrFile, fileArrayOrFile.name);
|
|
866
|
-
}
|
|
867
|
-
return formData;
|
|
868
|
-
};
|
|
869
|
-
/**
|
|
870
|
-
* Helper che in base ai parametri disponibili genera gli Header HTTP per la chiamata da effettuare
|
|
871
|
-
*
|
|
872
|
-
* @param {string} contentType Indica se aggiungere agli header "Content-Type", valorizzato al valore del parametro
|
|
873
|
-
* @param {string} accept Indica se aggiungere agli header "Accept", valorizzato al valore del parametro
|
|
874
|
-
* @param {boolean} includeAuth Indica se aggiungere agli header "Authorization", valorizzato col token recuperato dall'hook **retrieveAccessToken** della classe di estensione
|
|
875
|
-
* @param {string} transactionId Indica se aggiungere agli header "X-TX-ID", valorizzato al valore del parametro
|
|
876
|
-
*
|
|
877
|
-
* @returns {HttpHeaders} Header generati in base ai parametri
|
|
878
|
-
*/
|
|
879
|
-
HTTPService.prototype.getHeaders = function (transactionId, includeAuth, contentType, accept) {
|
|
880
|
-
if (transactionId === void 0) { transactionId = ""; }
|
|
881
|
-
if (includeAuth === void 0) { includeAuth = true; }
|
|
882
|
-
if (contentType === void 0) { contentType = "application/json"; }
|
|
883
|
-
if (accept === void 0) { accept = "application/json"; }
|
|
884
|
-
var _a;
|
|
885
|
-
var headers = new http.HttpHeaders();
|
|
886
|
-
var authtoken = this.ExtensionsImpl.retrieveAccessToken();
|
|
887
|
-
if (contentType)
|
|
888
|
-
headers = headers.append("Content-Type", contentType);
|
|
889
|
-
if (transactionId)
|
|
890
|
-
headers = headers.append("X-TX-ID", transactionId);
|
|
891
|
-
if (authtoken && includeAuth)
|
|
892
|
-
headers = headers.append("Authorization", "Bearer " + authtoken);
|
|
893
|
-
if (accept)
|
|
894
|
-
headers = headers.append("Accept", "application/json");
|
|
895
|
-
headers = headers.append("Accept-Language", (_a = this.LOCALE) !== null && _a !== void 0 ? _a : 'it-IT');
|
|
896
|
-
return headers;
|
|
897
|
-
};
|
|
898
|
-
/**
|
|
899
|
-
* Gestione di default degli errori
|
|
900
|
-
*
|
|
901
|
-
* @param {any} res Risultato della chiamata effettuata
|
|
902
|
-
* @param {string} guid Identificativo GUID della chiamata effettuata
|
|
903
|
-
*/
|
|
904
|
-
HTTPService.prototype.onError = function (res, guid) {
|
|
905
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
906
|
-
var finalError, finalStatus;
|
|
907
|
-
return __generator(this, function (_e) {
|
|
908
|
-
switch (_e.label) {
|
|
909
|
-
case 0:
|
|
910
|
-
this.callStatus[guid] = false;
|
|
911
|
-
//Mi assicuro che tutti gli errori durante il redirect al login vengano ignorati
|
|
912
|
-
if (this.ExtensionsImpl.readRedirectingToLogin()) {
|
|
913
|
-
this.log(this.loc("Redirecting to Login, ignoring HTTP error on call") + " " + guid);
|
|
914
|
-
return [2 /*return*/];
|
|
915
|
-
}
|
|
916
|
-
//Mi assicuro che venga gestito un solo errore per volta
|
|
917
|
-
if (this.ExtensionsImpl.readHandlingErrorStatus()) {
|
|
918
|
-
this.log(this.loc("Already Handling an error, ignoring HTTP error on call") + " " + guid);
|
|
919
|
-
return [2 /*return*/];
|
|
920
|
-
}
|
|
921
|
-
else
|
|
922
|
-
this.ExtensionsImpl.writeHandlingErrorStatus(true);
|
|
923
|
-
finalError = "";
|
|
924
|
-
finalStatus = "";
|
|
925
|
-
if (!this.isTypeError(res)) return [3 /*break*/, 1];
|
|
926
|
-
finalError = res.message;
|
|
927
|
-
finalStatus = "HTTP Service Internal Error";
|
|
928
|
-
return [3 /*break*/, 3];
|
|
929
|
-
case 1:
|
|
930
|
-
if (!this.isHttpErrorResponse(res)) return [3 /*break*/, 3];
|
|
931
|
-
return [4 /*yield*/, this.getHttpErrorText(res.error)];
|
|
932
|
-
case 2:
|
|
933
|
-
finalError = _e.sent();
|
|
934
|
-
finalStatus = res.status.toString();
|
|
935
|
-
switch (res.status) {
|
|
936
|
-
// Unauthorized
|
|
937
|
-
case 401:
|
|
938
|
-
if (this.ExtensionsImpl.readRedirectionStatus()) {
|
|
939
|
-
this.log(this.loc("Error 401 on call") + " " + guid + " " + this.loc("with redirect already in progress. Ignoring this event"));
|
|
940
|
-
return [2 /*return*/];
|
|
941
|
-
}
|
|
942
|
-
this.log(this.loc("Error 401 on call") + " " + guid + " " + this.loc("redirecting to login."));
|
|
943
|
-
this.ExtensionsImpl.writeRedirectionStatus(true);
|
|
944
|
-
this.ExtensionsImpl.writeRedirectingToLogin(true);
|
|
945
|
-
this.ExtensionsImpl.redirectToLogin();
|
|
946
|
-
return [2 /*return*/];
|
|
947
|
-
// Handled exception
|
|
948
|
-
case 400:
|
|
949
|
-
// No Permissions
|
|
950
|
-
case 403:
|
|
951
|
-
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
952
|
-
return [2 /*return*/];
|
|
953
|
-
// Not found
|
|
954
|
-
case 404:
|
|
955
|
-
this.ExtensionsImpl.handleBlockingException(res.status, this.loc("Resource not found"));
|
|
956
|
-
return [2 /*return*/];
|
|
957
|
-
// NotConfiguredException
|
|
958
|
-
case 444:
|
|
959
|
-
if (this.ExtensionsImpl.readRedirectionStatus())
|
|
960
|
-
this.log(this.loc("Error 444 on call") + " " + guid + " " + this.loc("with redirect already in progress. Ignoring this event"));
|
|
961
|
-
else if (!this.ExtensionsImpl.handleNotConfiguredException())
|
|
962
|
-
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
963
|
-
return [2 /*return*/];
|
|
964
|
-
case 0:
|
|
965
|
-
finalError = "Server might be offline" + (res.statusText ? " (" + res.statusText + ") " : "");
|
|
966
|
-
}
|
|
967
|
-
_e.label = 3;
|
|
968
|
-
case 3:
|
|
969
|
-
this.ExtensionsImpl.handleException(finalStatus, finalError);
|
|
970
|
-
return [2 /*return*/];
|
|
971
|
-
}
|
|
972
|
-
});
|
|
973
|
-
});
|
|
974
|
-
};
|
|
975
|
-
/**
|
|
976
|
-
* Dato un errore restituisce una promise con la stringa finale dell'errore in modo da poter fare un await
|
|
977
|
-
*
|
|
978
|
-
* @param {any} err Errore da controllare
|
|
979
|
-
*
|
|
980
|
-
* @returns {Promise<string>} Promise che risolve con la stringa finale dell'errore
|
|
981
|
-
*/
|
|
982
|
-
HTTPService.prototype.getHttpErrorText = function (err) {
|
|
983
|
-
var _this = this;
|
|
984
|
-
// Se ho un Blob può essere o un CallResult o suppongo una semplice stringa,
|
|
985
|
-
// altrimenti potrebbe essere direttamente un CallResult, oppure una semplice stringa
|
|
986
|
-
return new Promise(function (resolve) {
|
|
987
|
-
if (err instanceof Blob) {
|
|
988
|
-
var reader = new FileReader();
|
|
989
|
-
reader.onload = function (e) {
|
|
990
|
-
var errMsg = e.target.result;
|
|
991
|
-
var jsonerrMsg;
|
|
992
|
-
try {
|
|
993
|
-
jsonerrMsg = JSON.parse(errMsg);
|
|
994
|
-
}
|
|
995
|
-
catch (e) { }
|
|
996
|
-
return resolve(jsonerrMsg && _this.isCallResult(jsonerrMsg) ? jsonerrMsg.error.message : errMsg);
|
|
997
|
-
};
|
|
998
|
-
reader.readAsText(err);
|
|
999
|
-
}
|
|
1000
|
-
else if (_this.isCallResult(err))
|
|
1001
|
-
return resolve(err.error.message);
|
|
1002
|
-
else
|
|
1003
|
-
return resolve(err === null || err === void 0 ? void 0 : err.toString());
|
|
1004
|
-
});
|
|
1005
|
-
};
|
|
1006
|
-
/**
|
|
1007
|
-
* Riconosce se l'oggetto è di tipo **CallResult** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
1008
|
-
*
|
|
1009
|
-
* @param {any} err Errore da controllare
|
|
1010
|
-
*/
|
|
1011
|
-
HTTPService.prototype.isCallResult = function (err) {
|
|
1012
|
-
var _a;
|
|
1013
|
-
return !!((_a = err === null || err === void 0 ? void 0 : err.error) === null || _a === void 0 ? void 0 : _a.message);
|
|
1014
|
-
};
|
|
1015
|
-
/**
|
|
1016
|
-
* Riconosce se l'errore è di tipo **HttpErrorResponse** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
1017
|
-
*
|
|
1018
|
-
* @param {any} err Errore da controllare
|
|
1019
|
-
*/
|
|
1020
|
-
HTTPService.prototype.isHttpErrorResponse = function (err) {
|
|
1021
|
-
return err instanceof http.HttpErrorResponse;
|
|
1022
|
-
};
|
|
1023
|
-
/**
|
|
1024
|
-
* Riconosce se l'errore è di tipo **TypeError** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
1025
|
-
*
|
|
1026
|
-
* @param {any} err Errore da controllare
|
|
1027
|
-
*/
|
|
1028
|
-
HTTPService.prototype.isTypeError = function (err) {
|
|
1029
|
-
return err.name == "TypeError";
|
|
1030
|
-
};
|
|
1031
|
-
/**
|
|
1032
|
-
* Come dice il nome, registra un errore e restituisce un Observable vuoto come risultato della chiamata
|
|
1033
|
-
*
|
|
1034
|
-
* @param {any} res Risultato della chiamata effettuata
|
|
1035
|
-
* @param {string} guid Identificativo GUID della chiamata effettuata
|
|
1036
|
-
* @param {boolean} handleError Indica se gestire l'errore via libreria o se limitarsi a restituire l'Observable vuoto
|
|
1037
|
-
*
|
|
1038
|
-
* @returns {Observable<any>} Observable vuoto
|
|
1039
|
-
*/
|
|
1040
|
-
HTTPService.prototype.registerErrorAndReturnEmptyObservable = function (res, guid, handleError) {
|
|
1041
|
-
if (handleError === void 0) { handleError = true; }
|
|
1042
|
-
if (handleError)
|
|
1043
|
-
this.onError(res, guid);
|
|
1044
|
-
return new rxjs.Observable(function () { });
|
|
1045
|
-
};
|
|
1046
|
-
/**
|
|
1047
|
-
* Dato un Url e dei parametri cerca di recuperare l'eventuale oggetto già salvato in cache con le informazioni base della cache stessa
|
|
1048
|
-
*
|
|
1049
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
1050
|
-
* @param {HttpParams} params Parametri della chiamata (nulli in caso di POST)
|
|
1051
|
-
*
|
|
1052
|
-
* @returns {{ finalUrl: string, cache: boolean, cacheKey: string, cacheTime: string, cacheItem: any }} Oggetto contenente le informazioni sulla cache per l'oggetto specificato
|
|
1053
|
-
*/
|
|
1054
|
-
HTTPService.prototype.tryGetCacheInformations = function (url, params) {
|
|
1055
|
-
var cachingKey = null, cacheTime = null, cache = null, item = null;
|
|
1056
|
-
var useCaching = !!(/#cache/gi.exec(url));
|
|
1057
|
-
if (useCaching) {
|
|
1058
|
-
var tmp = /#cache(:?-(\d+))/gi.exec(url);
|
|
1059
|
-
cacheTime = tmp ? tmp[2] : null;
|
|
1060
|
-
url = url.replace("#cache" + (cacheTime ? "-" + cacheTime : ""), "");
|
|
1061
|
-
if (this.untimedCacheExpired() && !cacheTime)
|
|
1062
|
-
this.resetHttpUntimedCacheStorage();
|
|
1063
|
-
cachingKey = this.makeCacheKey(url, params);
|
|
1064
|
-
var cacheKey = cacheTime ? this.localStorageHttpTimedCacheKey : this.localStorageHttpCacheKey;
|
|
1065
|
-
var cacheLs = localStorage.getItem(cacheKey);
|
|
1066
|
-
var cache_1 = cacheLs ? JSON.parse(cacheLs) : {};
|
|
1067
|
-
if (cache_1 && cache_1[cachingKey] && !this.timedCacheItemExpired(cache_1[cachingKey])) {
|
|
1068
|
-
// Se gestisco il tempo esatto della cache prima di restituire l'oggetto cachato lo ripulisco
|
|
1069
|
-
// dalle proprietà interne che gli ho aggiunto per controllarne la scadenza
|
|
1070
|
-
if (cacheTime)
|
|
1071
|
-
delete cache_1[cachingKey].__expire;
|
|
1072
|
-
item = cache_1[cachingKey];
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
return { finalUrl: url, cache: useCaching, cacheKey: cachingKey, cacheTime: cacheTime, cacheItem: item };
|
|
1076
|
-
};
|
|
1077
|
-
/**
|
|
1078
|
-
* Inserisce un oggetto nella cache appropriata in base alle informazioni contenute nel parametro **cacheInfos**
|
|
1079
|
-
*
|
|
1080
|
-
* @param {T} item Oggetto da inserire nella cache
|
|
1081
|
-
* @param {{ finalUrl: string, cache: boolean, cacheKey: string, cacheTime: string, cacheItem: any }} cacheInfos Informazioni sulla cache recuperate da una chiamata precedente a **tryGetCacheInformations**
|
|
1082
|
-
*/
|
|
1083
|
-
HTTPService.prototype.cacheResponse = function (item, cacheInfos) {
|
|
1084
|
-
var cacheKey = cacheInfos.cacheTime ? this.localStorageHttpTimedCacheKey : this.localStorageHttpCacheKey;
|
|
1085
|
-
var cacheLs = localStorage.getItem(cacheKey);
|
|
1086
|
-
var cache = cacheLs ? JSON.parse(cacheLs) : {};
|
|
1087
|
-
cache[cacheInfos.cacheKey] = item;
|
|
1088
|
-
if (cacheInfos.cacheTime)
|
|
1089
|
-
cache[cacheInfos.cacheKey].__expire = dayjs().add(cacheInfos.cacheTime, "seconds");
|
|
1090
|
-
localStorage.setItem(cacheKey, JSON.stringify(cache));
|
|
1091
|
-
};
|
|
1092
|
-
/**
|
|
1093
|
-
* Controlla se la cache per le chiamate senza expire time è scaduta
|
|
1094
|
-
*
|
|
1095
|
-
* @returns {boolean} **true** se la cache è scaduta e dev'essere ripulita, **false** altrimenti
|
|
1096
|
-
*/
|
|
1097
|
-
HTTPService.prototype.untimedCacheExpired = function () {
|
|
1098
|
-
var expire = JSON.parse(localStorage.getItem(this.localStorageHttpCacheExpireKey));
|
|
1099
|
-
return !expire || expire && dayjs(expire) < dayjs();
|
|
1100
|
-
};
|
|
1101
|
-
/**
|
|
1102
|
-
* Controlla se la cache per una chiamata che ha un tempo di vita ben definito è scaduta o meno
|
|
1103
|
-
*
|
|
1104
|
-
* @param {any} item Oggetto recuperato dalla cache a cui ho aggiunto la chiave interna __expire
|
|
1105
|
-
*
|
|
1106
|
-
* @returns {boolean} **true** se la cache è scaduta e dev'essere ripulita, **false** altrimenti
|
|
1107
|
-
*/
|
|
1108
|
-
HTTPService.prototype.timedCacheItemExpired = function (item) {
|
|
1109
|
-
return dayjs(item.__expire) < dayjs();
|
|
1110
|
-
};
|
|
1111
|
-
/**
|
|
1112
|
-
* Ripulisce la cache e imposta la prossima scadenza ad adesso + **CLIENT_CACHE_DURATION_S** (token valorizzato in fase di configurazione dalla proprietà **clientCacheDurationS** della classe **HttpServiceModuleConfig**)
|
|
1113
|
-
*/
|
|
1114
|
-
HTTPService.prototype.resetHttpUntimedCacheStorage = function () {
|
|
1115
|
-
var _a;
|
|
1116
|
-
localStorage.setItem(this.localStorageHttpCacheKey, JSON.stringify({}));
|
|
1117
|
-
localStorage.setItem(this.localStorageHttpCacheExpireKey, JSON.stringify(dayjs().add((_a = this.CLIENT_CACHE_DURATION_S) !== null && _a !== void 0 ? _a : 3600, "second")));
|
|
1118
|
-
};
|
|
1119
|
-
/**
|
|
1120
|
-
* Ripulisce la cache delle chiamate con un tempo di expire definito
|
|
1121
|
-
*/
|
|
1122
|
-
HTTPService.prototype.resetHttpTimedCacheStorage = function () {
|
|
1123
|
-
localStorage.setItem(this.localStorageHttpTimedCacheKey, JSON.stringify({}));
|
|
1124
|
-
};
|
|
1125
|
-
/**
|
|
1126
|
-
* Genera una chiave per la cache delle chiamate in base ad URL e Parametri HTTP
|
|
1127
|
-
*
|
|
1128
|
-
* @param {string} url URL su cui effettuare la chiamata
|
|
1129
|
-
* @param {HttpParams} params Parametri della chiamata
|
|
1130
|
-
*
|
|
1131
|
-
* @returns {string} Chiave che rappresenta in maniera univoca la chiamata
|
|
1132
|
-
*/
|
|
1133
|
-
HTTPService.prototype.makeCacheKey = function (url, params) {
|
|
1134
|
-
var authKeyPart = (this.me ? this.me.Idtenant : "") + (this.me && this.CACHE_BY_USER ? this.me.IdUser : "");
|
|
1135
|
-
var paramsKeyPart = params && params.keys().length > 0 ? params.keys().reduce(function (prev, next) { return prev + next + '=' + params.get(next); }, "") : "";
|
|
1136
|
-
return authKeyPart + url + paramsKeyPart;
|
|
1137
|
-
};
|
|
1138
|
-
/**
|
|
1139
|
-
* Generazione GUID
|
|
1140
|
-
*
|
|
1141
|
-
* @returns {string} Nuovo GUID generato in maniera casuale
|
|
1142
|
-
*/
|
|
1143
|
-
HTTPService.prototype.getGUID = function () {
|
|
1144
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
1145
|
-
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
1146
|
-
return v.toString(16);
|
|
1147
|
-
});
|
|
1148
|
-
};
|
|
1149
|
-
/**
|
|
1150
|
-
* Metodo per scrivere log a console qualora **DEBUG_MODE** risultasse **true**
|
|
1151
|
-
*
|
|
1152
|
-
* @param {string} message Messaggio di log
|
|
1153
|
-
*/
|
|
1154
|
-
HTTPService.prototype.log = function (message) {
|
|
1155
|
-
if (this.DEBUG_MODE)
|
|
1156
|
-
console.log("@httpservice: " + message);
|
|
1157
|
-
};
|
|
1158
|
-
/**
|
|
1159
|
-
* Helper per la localizzazione dei messaggi
|
|
1160
|
-
*
|
|
1161
|
-
* @param {string} message Messaggio da localizzare
|
|
1162
|
-
*
|
|
1163
|
-
* @returns {string} Messaggio localizzato
|
|
1164
|
-
*/
|
|
1165
|
-
HTTPService.prototype.loc = function (message) {
|
|
1166
|
-
if (!Loc[message]) {
|
|
1167
|
-
console.warn("Untranslated message: " + message);
|
|
1168
|
-
return "";
|
|
1169
|
-
}
|
|
1170
|
-
return Loc[message][this.LOCALE];
|
|
1171
|
-
};
|
|
1172
|
-
return HTTPService;
|
|
1173
|
-
}());
|
|
1174
|
-
HTTPService.decorators = [
|
|
1175
|
-
{ type: core.Injectable }
|
|
1176
|
-
];
|
|
1177
|
-
HTTPService.ctorParameters = function () { return [
|
|
1178
|
-
{ type: undefined, decorators: [{ type: core.Inject, args: [BACKEND_URL,] }] },
|
|
1179
|
-
{ type: HttpServiceExtensions },
|
|
1180
|
-
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [HTTP_INVALIDATION,] }] },
|
|
1181
|
-
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [HTTP_LOCALE,] }] },
|
|
1182
|
-
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [APP_NAME,] }] },
|
|
1183
|
-
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [CLIENT_CACHE_DURATION_S,] }] },
|
|
1184
|
-
{ type: Boolean, decorators: [{ type: core.Optional }, { type: core.Inject, args: [CACHE_BY_USER,] }] },
|
|
1185
|
-
{ type: Boolean, decorators: [{ type: core.Optional }, { type: core.Inject, args: [DEBUG_MODE,] }] },
|
|
1186
|
-
{ type: http.HttpClient }
|
|
1187
|
-
]; };
|
|
1188
|
-
|
|
1189
|
-
var HttpserviceModule = /** @class */ (function () {
|
|
1190
|
-
function HttpserviceModule() {
|
|
1191
|
-
}
|
|
1192
|
-
HttpserviceModule.forRoot = function (config) {
|
|
1193
|
-
return {
|
|
1194
|
-
ngModule: HttpserviceModule,
|
|
1195
|
-
providers: [
|
|
1196
|
-
HTTPService,
|
|
1197
|
-
HttpServiceExtensions,
|
|
1198
|
-
{ provide: HTTP_INVALIDATION, useValue: config === null || config === void 0 ? void 0 : config.httpInvalidation },
|
|
1199
|
-
{ provide: CLIENT_CACHE_DURATION_S, useValue: config === null || config === void 0 ? void 0 : config.clientCacheDurationS },
|
|
1200
|
-
{ provide: BACKEND_URL, useValue: config === null || config === void 0 ? void 0 : config.backendUrl },
|
|
1201
|
-
{ provide: HTTP_LOCALE, useValue: (config === null || config === void 0 ? void 0 : config.httpLocale) || 'it-IT' },
|
|
1202
|
-
{ provide: APP_NAME, useValue: config === null || config === void 0 ? void 0 : config.appName },
|
|
1203
|
-
{ provide: CACHE_BY_USER, useValue: config === null || config === void 0 ? void 0 : config.cacheByUser },
|
|
1204
|
-
{ provide: DEBUG_MODE, useValue: config === null || config === void 0 ? void 0 : config.debugMode }
|
|
1205
|
-
]
|
|
1206
|
-
};
|
|
1207
|
-
};
|
|
1208
|
-
return HttpserviceModule;
|
|
1209
|
-
}());
|
|
1210
|
-
HttpserviceModule.decorators = [
|
|
1211
|
-
{ type: core.NgModule }
|
|
1212
|
-
];
|
|
1213
|
-
|
|
1214
|
-
/**
|
|
1215
|
-
* Classe di configurazione per il Modulo della libreria
|
|
1216
|
-
*/
|
|
1217
|
-
var HttpServiceModuleConfig = /** @class */ (function () {
|
|
1218
|
-
function HttpServiceModuleConfig() {
|
|
1219
|
-
}
|
|
1220
|
-
return HttpServiceModuleConfig;
|
|
1221
|
-
}());
|
|
1222
|
-
|
|
1223
|
-
var Download = /** @class */ (function () {
|
|
1224
|
-
function Download() {
|
|
1225
|
-
}
|
|
1226
|
-
return Download;
|
|
1227
|
-
}());
|
|
1228
|
-
|
|
1229
|
-
/*
|
|
1230
|
-
* Public API Surface of httpservice
|
|
1231
|
-
*/
|
|
1232
|
-
|
|
1233
|
-
/**
|
|
1234
|
-
* Generated bundle index. Do not edit.
|
|
1235
|
-
*/
|
|
1236
|
-
|
|
1237
|
-
exports.Download = Download;
|
|
1238
|
-
exports.HTTPService = HTTPService;
|
|
1239
|
-
exports.HttpServiceExtensions = HttpServiceExtensions;
|
|
1240
|
-
exports.HttpServiceModuleConfig = HttpServiceModuleConfig;
|
|
1241
|
-
exports.HttpserviceModule = HttpserviceModule;
|
|
1242
|
-
exports.ɵa = HTTP_INVALIDATION;
|
|
1243
|
-
exports.ɵb = CLIENT_CACHE_DURATION_S;
|
|
1244
|
-
exports.ɵc = BACKEND_URL;
|
|
1245
|
-
exports.ɵd = HTTP_LOCALE;
|
|
1246
|
-
exports.ɵe = APP_NAME;
|
|
1247
|
-
exports.ɵf = CACHE_BY_USER;
|
|
1248
|
-
exports.ɵg = DEBUG_MODE;
|
|
1249
|
-
|
|
1250
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1251
|
-
|
|
1252
|
-
})));
|
|
1253
|
-
//# sourceMappingURL=esfaenza-httpservice.umd.js.map
|