@computec/uibase 1.0.2

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.
Files changed (86) hide show
  1. package/dist/communication/HttpClient.d.ts +248 -0
  2. package/dist/communication/HttpClient.d.ts.map +1 -0
  3. package/dist/communication/HttpClient.js +355 -0
  4. package/dist/communication/HttpClientCacheOptions.d.ts +9 -0
  5. package/dist/communication/HttpClientCacheOptions.d.ts.map +1 -0
  6. package/dist/communication/HttpClientCacheOptions.js +25 -0
  7. package/dist/communication/IBaseHttpClientOptions.d.ts +17 -0
  8. package/dist/communication/IBaseHttpClientOptions.d.ts.map +1 -0
  9. package/dist/communication/IBaseHttpClientOptions.js +2 -0
  10. package/dist/helpers/ErrorHelper.d.ts +15 -0
  11. package/dist/helpers/ErrorHelper.d.ts.map +1 -0
  12. package/dist/helpers/ErrorHelper.js +37 -0
  13. package/dist/helpers/HttpClientHelper.d.ts +42 -0
  14. package/dist/helpers/HttpClientHelper.d.ts.map +1 -0
  15. package/dist/helpers/HttpClientHelper.js +175 -0
  16. package/dist/index.d.ts +23 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +50 -0
  19. package/dist/models/AppEngineException.d.ts +11 -0
  20. package/dist/models/AppEngineException.d.ts.map +1 -0
  21. package/dist/models/AppEngineException.js +21 -0
  22. package/dist/models/BaseBusinessObject.d.ts +158 -0
  23. package/dist/models/BaseBusinessObject.d.ts.map +1 -0
  24. package/dist/models/BaseBusinessObject.js +187 -0
  25. package/dist/models/LocalStorage.d.ts +9 -0
  26. package/dist/models/LocalStorage.d.ts.map +1 -0
  27. package/dist/models/LocalStorage.js +54 -0
  28. package/dist/models/Session.d.ts +18 -0
  29. package/dist/models/Session.d.ts.map +1 -0
  30. package/dist/models/Session.js +5 -0
  31. package/dist/models/enums/HeadersContentTypeEnum.d.ts +8 -0
  32. package/dist/models/enums/HeadersContentTypeEnum.d.ts.map +1 -0
  33. package/dist/models/enums/HeadersContentTypeEnum.js +10 -0
  34. package/dist/models/enums/StorageTypeEnum.d.ts +5 -0
  35. package/dist/models/enums/StorageTypeEnum.d.ts.map +1 -0
  36. package/dist/models/enums/StorageTypeEnum.js +8 -0
  37. package/dist/models/interfaces/IAppEngineException.d.ts +7 -0
  38. package/dist/models/interfaces/IAppEngineException.d.ts.map +1 -0
  39. package/dist/models/interfaces/IAppEngineException.js +2 -0
  40. package/dist-ui5/resources/computec/appengine/uibase/.library +15 -0
  41. package/dist-ui5/resources/computec/appengine/uibase/communication/HttpClient-dbg.js +485 -0
  42. package/dist-ui5/resources/computec/appengine/uibase/communication/HttpClient.js +2 -0
  43. package/dist-ui5/resources/computec/appengine/uibase/communication/HttpClient.js.map +1 -0
  44. package/dist-ui5/resources/computec/appengine/uibase/communication/HttpClientCacheOptions-dbg.js +41 -0
  45. package/dist-ui5/resources/computec/appengine/uibase/communication/HttpClientCacheOptions.js +2 -0
  46. package/dist-ui5/resources/computec/appengine/uibase/communication/HttpClientCacheOptions.js.map +1 -0
  47. package/dist-ui5/resources/computec/appengine/uibase/communication/IBaseHttpClientOptions-dbg.js +1 -0
  48. package/dist-ui5/resources/computec/appengine/uibase/communication/IBaseHttpClientOptions.js +2 -0
  49. package/dist-ui5/resources/computec/appengine/uibase/communication/IBaseHttpClientOptions.js.map +1 -0
  50. package/dist-ui5/resources/computec/appengine/uibase/helpers/ErrorHelper-dbg.js +57 -0
  51. package/dist-ui5/resources/computec/appengine/uibase/helpers/ErrorHelper.js +2 -0
  52. package/dist-ui5/resources/computec/appengine/uibase/helpers/ErrorHelper.js.map +1 -0
  53. package/dist-ui5/resources/computec/appengine/uibase/helpers/HttpClientHelper-dbg.js +310 -0
  54. package/dist-ui5/resources/computec/appengine/uibase/helpers/HttpClientHelper.js +2 -0
  55. package/dist-ui5/resources/computec/appengine/uibase/helpers/HttpClientHelper.js.map +1 -0
  56. package/dist-ui5/resources/computec/appengine/uibase/index-dbg.js +43 -0
  57. package/dist-ui5/resources/computec/appengine/uibase/index.js +2 -0
  58. package/dist-ui5/resources/computec/appengine/uibase/index.js.map +1 -0
  59. package/dist-ui5/resources/computec/appengine/uibase/library-dbg.js +27 -0
  60. package/dist-ui5/resources/computec/appengine/uibase/library-preload.js +47 -0
  61. package/dist-ui5/resources/computec/appengine/uibase/library-preload.js.map +1 -0
  62. package/dist-ui5/resources/computec/appengine/uibase/library.js +2 -0
  63. package/dist-ui5/resources/computec/appengine/uibase/library.js.map +1 -0
  64. package/dist-ui5/resources/computec/appengine/uibase/manifest.json +35 -0
  65. package/dist-ui5/resources/computec/appengine/uibase/models/AppEngineException-dbg.js +37 -0
  66. package/dist-ui5/resources/computec/appengine/uibase/models/AppEngineException.js +2 -0
  67. package/dist-ui5/resources/computec/appengine/uibase/models/AppEngineException.js.map +1 -0
  68. package/dist-ui5/resources/computec/appengine/uibase/models/BaseBusinessObject-dbg.js +231 -0
  69. package/dist-ui5/resources/computec/appengine/uibase/models/BaseBusinessObject.js +2 -0
  70. package/dist-ui5/resources/computec/appengine/uibase/models/BaseBusinessObject.js.map +1 -0
  71. package/dist-ui5/resources/computec/appengine/uibase/models/LocalStorage-dbg.js +75 -0
  72. package/dist-ui5/resources/computec/appengine/uibase/models/LocalStorage.js +2 -0
  73. package/dist-ui5/resources/computec/appengine/uibase/models/LocalStorage.js.map +1 -0
  74. package/dist-ui5/resources/computec/appengine/uibase/models/Session-dbg.js +15 -0
  75. package/dist-ui5/resources/computec/appengine/uibase/models/Session.js +2 -0
  76. package/dist-ui5/resources/computec/appengine/uibase/models/Session.js.map +1 -0
  77. package/dist-ui5/resources/computec/appengine/uibase/models/enums/HeadersContentTypeEnum-dbg.js +14 -0
  78. package/dist-ui5/resources/computec/appengine/uibase/models/enums/HeadersContentTypeEnum.js +2 -0
  79. package/dist-ui5/resources/computec/appengine/uibase/models/enums/HeadersContentTypeEnum.js.map +1 -0
  80. package/dist-ui5/resources/computec/appengine/uibase/models/enums/StorageTypeEnum-dbg.js +16 -0
  81. package/dist-ui5/resources/computec/appengine/uibase/models/enums/StorageTypeEnum.js +2 -0
  82. package/dist-ui5/resources/computec/appengine/uibase/models/enums/StorageTypeEnum.js.map +1 -0
  83. package/dist-ui5/resources/computec/appengine/uibase/models/interfaces/IAppEngineException-dbg.js +7 -0
  84. package/dist-ui5/resources/computec/appengine/uibase/models/interfaces/IAppEngineException.js +2 -0
  85. package/dist-ui5/resources/computec/appengine/uibase/models/interfaces/IAppEngineException.js.map +1 -0
  86. package/package.json +92 -0
@@ -0,0 +1,248 @@
1
+ import { IBasicHttpRequest, IGetHttpClientOptions, IBaseHttpClientOptions } from "./IBaseHttpClientOptions";
2
+ /**
3
+ * @class
4
+ * @description This class is used to make requests to the server. It is a wrapper for the jQuery.ajax method.
5
+ * @method request - This method is used to make a other requests to the server. Remember, that you should use the other methods of this class instead of this method. This is the 2nd version of the request method. The first version is in the {@link Http}.
6
+ * @method get - This method is used to make a GET request to the server.
7
+ * @method getCache - This method is used to make a GET request to the server.
8
+ * @method post - This method is used to make a POST request to the server.
9
+ * @method postJSON - This method is used to make a POST request to the server with a JSON body.
10
+ * @method postFile - This method is used to make a POST request to the server with a file.
11
+ * @method put - This method is used to make a PUT request to the server.
12
+ * @method putJSON - This method is used to make a PUT request to the server with a JSON body.
13
+ * @method patch - This method is used to make a PATCH request to the server.
14
+ * @method patchJSON - This method is used to make a PATCH request to the server with a JSON body.
15
+ * @method remove - This method is used to make a DELETE request to the server.
16
+ *
17
+ * @example
18
+ *
19
+ * import HttpClient from 'computec/appengine/uicore/communication/HttpClient';
20
+ *
21
+ * const getProduct = async () => {
22
+ * const data = await HttpClient.get({
23
+ * url: "odata/odata.svc/Products",
24
+ * useCache: true
25
+ * });
26
+ *
27
+ * return data;
28
+ * }u
29
+ *
30
+ * const createProduct = () => {
31
+ * return HttpClient.postJSON({
32
+ * url: "odata/odata.svc/Products",
33
+ * data: {
34
+ * Name: "Test"
35
+ * }
36
+ * });
37
+ * }
38
+ */
39
+ export default class HttpClient {
40
+ /**
41
+ * @memberof computec.appengine.uicore.communication.HttpClient
42
+ * @static
43
+ * @public
44
+ * @description This method is used to clear the cache from service worker.
45
+ * @example
46
+ * import HttpClient from 'computec/appengine/uicore/communication/HttpClient';
47
+ *
48
+ * HttpClient.clearCache();
49
+ */
50
+ static clearCache(): void;
51
+ /**
52
+ * @obsolete Use cacheControl with refresh option instead
53
+ * @memberof computec.appengine.uicore.communication.HttpClient
54
+ * @static
55
+ * @public
56
+ * @description This method is used to remove a specific url from the cache.
57
+ * @param {string} url - The url to remove from the cache.
58
+ * @example
59
+ * import HttpClient from 'computec/appengine/uicore/communication/HttpClient';
60
+ *
61
+ * HttpClient.removeCache("odata/odata.svc/Products");
62
+ */
63
+ static removeCache(url: string): void;
64
+ /**
65
+ * @memberof computec.appengine.uicore.communication.HttpClient
66
+ * @static
67
+ * @public
68
+ * @async
69
+ * @description This method is used to make a other requests to the server. Remember, that you should use the other methods of this class instead of this method.
70
+ * @param {IBasicHttpRequest} options - The options for the request.
71
+ * @param {boolean} failHandling - If true, the request will be handled as a failure.
72
+ * @param {boolean} handleBusy - If true, the request will be handled as a busy request.
73
+ * @param {MBusyIndicator} busyIndicator - The busy indicator to show.
74
+ * @returns {Promise<T>} - The response of the request.
75
+ * @example
76
+ * import HttpClient from 'computec/appengine/uicore/communication/HttpClient';
77
+ *
78
+ * const getProduct = async () => {
79
+ * const data = await HttpClient.request({
80
+ * url: "odata/odata.svc/Products",
81
+ * method: "GET",
82
+ * headers: {
83
+ * "Content-Type": "application/json"
84
+ * Accepted: "application/json"
85
+ * },
86
+ * busyIndicator: this.getView().byId("busyIndicator")
87
+ * });
88
+ *
89
+ * return data;
90
+ * }
91
+ *
92
+ * void getProduct();
93
+ */
94
+ static request<T>(options?: IBasicHttpRequest): Promise<T>;
95
+ /**
96
+ *
97
+ * @description get request. You can set options to the request. You can also choose if you want to use local cache. If data is already in cache, it will be returned from cache. Otherwise it will be requested from server and cached. Remember to use "useCache" when you know, that data is not changable.
98
+ * @see {@link IGetHttpClientOptions}
99
+ * @param url url
100
+ * @param options options
101
+ * @param options.headers by default Content-Type: "application/json", Accepted: "json"
102
+ * @param options.useCache This is a boolean value. If true, the data will be cached. If data is already in cache, it will be returned from cache. Otherwise it will be requested from server and cached. Remember to use "useCache" when you know, that data is not changable.
103
+ * @returns {T}
104
+ * @memberof HttpClient
105
+ * @static
106
+ * @example
107
+ * import HttpClient from "computec/appengine/uicore/model/Http";
108
+ *
109
+ * console.log("get account from server, without cache");
110
+ * const getAccounts = async () => {
111
+ * const account = await Http.get<IAccount>(`/api/Account/${id}`);
112
+ * return account;
113
+ * }
114
+ *
115
+ * @example
116
+ * import HttpClient from "computec/appengine/uicore/model/Http";
117
+ *
118
+ * console.log("get account from cache");
119
+ * const getAccounts = async () => {
120
+ * const account = await Http.get<IAccount>(`/api/Account/${id}`, {useCache: true});
121
+ * return account;
122
+ * }
123
+ *
124
+ */
125
+ static get<T>(url: string, options?: IGetHttpClientOptions): Promise<T>;
126
+ /**
127
+ *
128
+ * @description get request with cache as true. You can set options to the request. If data is already in cache, it will be returned from cache. Otherwise it will be requested from server and cached. Remember to use "useCache" when you know, that data is not changable.
129
+ * @see {@link IGetHttpClientOptions}
130
+ * @param url url
131
+ * @param options options
132
+ * @param options.headers by default Content-Type: "application/json", Accepted: "json"
133
+ * @returns {T}
134
+ * @memberof HttpClient
135
+ * @static
136
+ *
137
+ * @example
138
+ * import HttpClient from "computec/appengine/uicore/model/Http";
139
+ *
140
+ * console.log("get account from cache");
141
+ * const getAccounts = async () => {
142
+ * const account = await Http.getCache<IAccount>(`/api/Account/${id}`, {useCache: true});
143
+ * return account;
144
+ * }
145
+ *
146
+ */
147
+ static getCache<T>(url: string, options?: IGetHttpClientOptions): Promise<T>;
148
+ /**
149
+ * @description post request. You can set options to the request. {@link IBaseHttpClientOptions}
150
+ * @param data data
151
+ * @param url url
152
+ * @param options options
153
+ * @param options.headers by default {Content-Type: "application/json", Accepted: "json"}
154
+ * @returns {T} value. It depends from server response
155
+ *
156
+ * @example
157
+ * import HttpClient from "computec/appengine/uicore/model/Http";
158
+ *
159
+ * console.log("post account to server");
160
+ * const postAccount = async () => {
161
+ * const dataInJSON = JSON.stringify({name: "test"});
162
+ * const account = await Http.post<IAccount>(`/api/Account`, dataInJSON);
163
+ * return account;
164
+ * }
165
+ */
166
+ static post<T>(data: string, url: string, options?: IBaseHttpClientOptions): Promise<T>;
167
+ /**
168
+ * @description post request with JSON data. You can set options to the request. {@link IBaseHttpClientOptions}
169
+ * @param data data
170
+ * @param url url
171
+ * @param options options
172
+ * @returns {T} value. It depends from server response
173
+ *
174
+ * @example
175
+ * import HttpClient from "computec/appengine/uicore/model/Http";
176
+ *
177
+ * console.log("post account to server");
178
+ * const postAccount = async () => {
179
+ * const account = await Http.postJSON<IAccount>(`/api/Account`, {name: "test"});
180
+ * return account;
181
+ * }
182
+ *
183
+ */
184
+ static postJSON<T>(data: object, url: string, options?: IBaseHttpClientOptions): Promise<T>;
185
+ /**
186
+ * @description post request with File as data. You can set options to the request. {@link IBaseHttpClientOptions}
187
+ * @param data - file that will be send to server
188
+ * @param url url
189
+ * @param options options
190
+ * @param options.headers by default {Content-Type: "application/json", Accepted: "json"}
191
+ * @returns {T} value. It depends from server response
192
+ *
193
+ * @example
194
+ * import HttpClient from "computec/appengine/uicore/model/Http";
195
+ *
196
+ * console.log("send attachment to server");
197
+ * const setAttachment = async (file: File) => {
198
+ * const isPicture = file.type.includes("image").toString();
199
+ * const data = await HttpClient.postFile<IAttachment[]>(file, `api/Attachments/SetAttachment/${isPicture}/true`);
200
+ * return data[0];
201
+ * }
202
+ *
203
+ */
204
+ static postFile<T>(data: File, url: string, options?: IBaseHttpClientOptions): Promise<T>;
205
+ /**
206
+ * @description put request. You can set options to the request. {@link IBaseHttpClientOptions}
207
+ * @param data data
208
+ * @param url url
209
+ * @param options options
210
+ * @param options.headers by default {Content-Type: "application/json", Accepted: "json"}
211
+ * @returns {T} value. It depends from server response
212
+ */
213
+ static put<T>(data: string, url: string, options?: IBaseHttpClientOptions): Promise<T>;
214
+ /**
215
+ * @description put request with JSON data. You can set options to the request. {@link IBaseHttpClientOptions}
216
+ * @param data data
217
+ * @param url url
218
+ * @param options options
219
+ * @returns {T} value. It depends from server response
220
+ */
221
+ static putJSON<T>(data: object, url: string, options?: IBaseHttpClientOptions): Promise<T>;
222
+ /**
223
+ * @description patch request. You can set options to the request. {@link IBaseHttpClientOptions}
224
+ * @param data data
225
+ * @param url url
226
+ * @param options options
227
+ * @param options.headers by default {Content-Type: "application/json", Accepted: "json"}
228
+ * @returns {T} value. It depends from server response
229
+ */
230
+ static patch<T>(data: string, url: string, options?: IBaseHttpClientOptions): Promise<T>;
231
+ /**
232
+ * @description patch request with JSON data. You can set options to the request. {@link IBaseHttpClientOptions}
233
+ * @param data data
234
+ * @param url url
235
+ * @param options options
236
+ * @returns {T} value. It depends from server response
237
+ */
238
+ static patchJSON<T>(data: object, url: string, options?: IBaseHttpClientOptions): Promise<T>;
239
+ /**
240
+ * @description delete request. You can set options to the request. {@link IBaseHttpClientOptions}
241
+ * @param url url
242
+ * @param contentType by default "application/json"
243
+ * @returns {T} value. It depends from server response
244
+ */
245
+ static remove<T>(url: string, options?: IBaseHttpClientOptions): Promise<T>;
246
+ private static _appendToHeaders;
247
+ }
248
+ //# sourceMappingURL=HttpClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/communication/HttpClient.ts"],"names":[],"mappings":"AAMA,OAAO,EACN,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAE9B;;;;;;;;;OASG;WACW,UAAU;IAUxB;;;;;;;;;;;OAWG;WACW,WAAW,CAAC,GAAG,EAAE,MAAM;IAIrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;WACiB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAE,iBAAsB;IAmC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;WACW,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;IAWrE;;;;;;;;;;;;;;;;;;;;OAoBG;WACW,QAAQ,CAAC,CAAC,EACvB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,qBAER;IAKF;;;;;;;;;;;;;;;;;OAiBG;WACW,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IASrF;;;;;;;;;;;;;;;;OAgBG;WACW,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IASzF;;;;;;;;;;;;;;;;;;OAkBG;WACW,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IAcvF;;;;;;;OAOG;WACW,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IASpF;;;;;;OAMG;WACW,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IASxF;;;;;;;OAOG;WACW,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IAStF;;;;;;OAMG;WACW,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IAS1F;;;;;OAKG;WACW,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IAYzE,OAAO,CAAC,MAAM,CAAC,gBAAgB;CAW/B"}
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const LocalStorage_1 = __importDefault(require("../models/LocalStorage"));
16
+ const ErrorHelper_1 = __importDefault(require("../helpers/ErrorHelper"));
17
+ const HeadersContentTypeEnum_1 = __importDefault(require("../models/enums/HeadersContentTypeEnum"));
18
+ const HttpClientHelper_1 = __importDefault(require("../helpers/HttpClientHelper"));
19
+ const HttpClientCacheOptions_1 = __importDefault(require("./HttpClientCacheOptions"));
20
+ /**
21
+ * @class
22
+ * @description This class is used to make requests to the server. It is a wrapper for the jQuery.ajax method.
23
+ * @method request - This method is used to make a other requests to the server. Remember, that you should use the other methods of this class instead of this method. This is the 2nd version of the request method. The first version is in the {@link Http}.
24
+ * @method get - This method is used to make a GET request to the server.
25
+ * @method getCache - This method is used to make a GET request to the server.
26
+ * @method post - This method is used to make a POST request to the server.
27
+ * @method postJSON - This method is used to make a POST request to the server with a JSON body.
28
+ * @method postFile - This method is used to make a POST request to the server with a file.
29
+ * @method put - This method is used to make a PUT request to the server.
30
+ * @method putJSON - This method is used to make a PUT request to the server with a JSON body.
31
+ * @method patch - This method is used to make a PATCH request to the server.
32
+ * @method patchJSON - This method is used to make a PATCH request to the server with a JSON body.
33
+ * @method remove - This method is used to make a DELETE request to the server.
34
+ *
35
+ * @example
36
+ *
37
+ * import HttpClient from 'computec/appengine/uicore/communication/HttpClient';
38
+ *
39
+ * const getProduct = async () => {
40
+ * const data = await HttpClient.get({
41
+ * url: "odata/odata.svc/Products",
42
+ * useCache: true
43
+ * });
44
+ *
45
+ * return data;
46
+ * }u
47
+ *
48
+ * const createProduct = () => {
49
+ * return HttpClient.postJSON({
50
+ * url: "odata/odata.svc/Products",
51
+ * data: {
52
+ * Name: "Test"
53
+ * }
54
+ * });
55
+ * }
56
+ */
57
+ class HttpClient {
58
+ //#region cache methods
59
+ /**
60
+ * @memberof computec.appengine.uicore.communication.HttpClient
61
+ * @static
62
+ * @public
63
+ * @description This method is used to clear the cache from service worker.
64
+ * @example
65
+ * import HttpClient from 'computec/appengine/uicore/communication/HttpClient';
66
+ *
67
+ * HttpClient.clearCache();
68
+ */
69
+ static clearCache() {
70
+ if (navigator.serviceWorker.controller) {
71
+ navigator.serviceWorker.controller.postMessage({
72
+ type: "CT_AppEngine_pwa",
73
+ });
74
+ }
75
+ else {
76
+ console.warn("No active service worker found.");
77
+ }
78
+ }
79
+ /**
80
+ * @obsolete Use cacheControl with refresh option instead
81
+ * @memberof computec.appengine.uicore.communication.HttpClient
82
+ * @static
83
+ * @public
84
+ * @description This method is used to remove a specific url from the cache.
85
+ * @param {string} url - The url to remove from the cache.
86
+ * @example
87
+ * import HttpClient from 'computec/appengine/uicore/communication/HttpClient';
88
+ *
89
+ * HttpClient.removeCache("odata/odata.svc/Products");
90
+ */
91
+ static removeCache(url) {
92
+ this.clearCache();
93
+ }
94
+ //#endregion
95
+ /**
96
+ * @memberof computec.appengine.uicore.communication.HttpClient
97
+ * @static
98
+ * @public
99
+ * @async
100
+ * @description This method is used to make a other requests to the server. Remember, that you should use the other methods of this class instead of this method.
101
+ * @param {IBasicHttpRequest} options - The options for the request.
102
+ * @param {boolean} failHandling - If true, the request will be handled as a failure.
103
+ * @param {boolean} handleBusy - If true, the request will be handled as a busy request.
104
+ * @param {MBusyIndicator} busyIndicator - The busy indicator to show.
105
+ * @returns {Promise<T>} - The response of the request.
106
+ * @example
107
+ * import HttpClient from 'computec/appengine/uicore/communication/HttpClient';
108
+ *
109
+ * const getProduct = async () => {
110
+ * const data = await HttpClient.request({
111
+ * url: "odata/odata.svc/Products",
112
+ * method: "GET",
113
+ * headers: {
114
+ * "Content-Type": "application/json"
115
+ * Accepted: "application/json"
116
+ * },
117
+ * busyIndicator: this.getView().byId("busyIndicator")
118
+ * });
119
+ *
120
+ * return data;
121
+ * }
122
+ *
123
+ * void getProduct();
124
+ */
125
+ static request() {
126
+ return __awaiter(this, arguments, void 0, function* (options = {}) {
127
+ var _a, _b, _c;
128
+ const companyId = (_a = LocalStorage_1.default.get("CTS_Session")) === null || _a === void 0 ? void 0 : _a.CompanyId;
129
+ const restOptions = Object.assign({ headers: new Headers({
130
+ "Content-Type": "application/json",
131
+ Accepted: "application/json",
132
+ }) }, options);
133
+ if (companyId) {
134
+ this._appendToHeaders(restOptions.headers, "x-b1-companyid", companyId);
135
+ }
136
+ const cacheOptions = (_b = options.cacheOptions) === null || _b === void 0 ? void 0 : _b.getCacheControlHeader();
137
+ const useCtCache = (_c = options.cacheOptions) === null || _c === void 0 ? void 0 : _c.getComputecCustomCacheControlHeader();
138
+ if (cacheOptions) {
139
+ this._appendToHeaders(restOptions.headers, "cache-control", cacheOptions);
140
+ }
141
+ if (useCtCache) {
142
+ this._appendToHeaders(restOptions.headers, useCtCache[0], useCtCache[1]);
143
+ }
144
+ const url = HttpClientHelper_1.default.getFullUrl(restOptions.url);
145
+ try {
146
+ const response = yield fetch(url, restOptions);
147
+ yield HttpClientHelper_1.default.validateResponse(response, restOptions);
148
+ return HttpClientHelper_1.default.fetchData(response);
149
+ }
150
+ catch (e) {
151
+ const error = ErrorHelper_1.default.getError(e);
152
+ throw error;
153
+ }
154
+ });
155
+ }
156
+ /**
157
+ *
158
+ * @description get request. You can set options to the request. You can also choose if you want to use local cache. If data is already in cache, it will be returned from cache. Otherwise it will be requested from server and cached. Remember to use "useCache" when you know, that data is not changable.
159
+ * @see {@link IGetHttpClientOptions}
160
+ * @param url url
161
+ * @param options options
162
+ * @param options.headers by default Content-Type: "application/json", Accepted: "json"
163
+ * @param options.useCache This is a boolean value. If true, the data will be cached. If data is already in cache, it will be returned from cache. Otherwise it will be requested from server and cached. Remember to use "useCache" when you know, that data is not changable.
164
+ * @returns {T}
165
+ * @memberof HttpClient
166
+ * @static
167
+ * @example
168
+ * import HttpClient from "computec/appengine/uicore/model/Http";
169
+ *
170
+ * console.log("get account from server, without cache");
171
+ * const getAccounts = async () => {
172
+ * const account = await Http.get<IAccount>(`/api/Account/${id}`);
173
+ * return account;
174
+ * }
175
+ *
176
+ * @example
177
+ * import HttpClient from "computec/appengine/uicore/model/Http";
178
+ *
179
+ * console.log("get account from cache");
180
+ * const getAccounts = async () => {
181
+ * const account = await Http.get<IAccount>(`/api/Account/${id}`, {useCache: true});
182
+ * return account;
183
+ * }
184
+ *
185
+ */
186
+ static get(url, options = {}) {
187
+ const restOptions = Object.assign(Object.assign({}, options), { method: "GET", url: url });
188
+ if (options.useCache)
189
+ restOptions.cacheOptions = new HttpClientCacheOptions_1.default(true);
190
+ return this.request(restOptions);
191
+ }
192
+ /**
193
+ *
194
+ * @description get request with cache as true. You can set options to the request. If data is already in cache, it will be returned from cache. Otherwise it will be requested from server and cached. Remember to use "useCache" when you know, that data is not changable.
195
+ * @see {@link IGetHttpClientOptions}
196
+ * @param url url
197
+ * @param options options
198
+ * @param options.headers by default Content-Type: "application/json", Accepted: "json"
199
+ * @returns {T}
200
+ * @memberof HttpClient
201
+ * @static
202
+ *
203
+ * @example
204
+ * import HttpClient from "computec/appengine/uicore/model/Http";
205
+ *
206
+ * console.log("get account from cache");
207
+ * const getAccounts = async () => {
208
+ * const account = await Http.getCache<IAccount>(`/api/Account/${id}`, {useCache: true});
209
+ * return account;
210
+ * }
211
+ *
212
+ */
213
+ static getCache(url, options = {
214
+ cacheOptions: new HttpClientCacheOptions_1.default(true),
215
+ }) {
216
+ return this.get(url, options);
217
+ }
218
+ /**
219
+ * @description post request. You can set options to the request. {@link IBaseHttpClientOptions}
220
+ * @param data data
221
+ * @param url url
222
+ * @param options options
223
+ * @param options.headers by default {Content-Type: "application/json", Accepted: "json"}
224
+ * @returns {T} value. It depends from server response
225
+ *
226
+ * @example
227
+ * import HttpClient from "computec/appengine/uicore/model/Http";
228
+ *
229
+ * console.log("post account to server");
230
+ * const postAccount = async () => {
231
+ * const dataInJSON = JSON.stringify({name: "test"});
232
+ * const account = await Http.post<IAccount>(`/api/Account`, dataInJSON);
233
+ * return account;
234
+ * }
235
+ */
236
+ static post(data, url, options = {}) {
237
+ return this.request(Object.assign(Object.assign({}, options), { method: "POST", url: url, body: data }));
238
+ }
239
+ /**
240
+ * @description post request with JSON data. You can set options to the request. {@link IBaseHttpClientOptions}
241
+ * @param data data
242
+ * @param url url
243
+ * @param options options
244
+ * @returns {T} value. It depends from server response
245
+ *
246
+ * @example
247
+ * import HttpClient from "computec/appengine/uicore/model/Http";
248
+ *
249
+ * console.log("post account to server");
250
+ * const postAccount = async () => {
251
+ * const account = await Http.postJSON<IAccount>(`/api/Account`, {name: "test"});
252
+ * return account;
253
+ * }
254
+ *
255
+ */
256
+ static postJSON(data, url, options = {}) {
257
+ return this.post(JSON.stringify(data), url, Object.assign({ headers: {
258
+ "Content-Type": "application/json",
259
+ } }, options));
260
+ }
261
+ /**
262
+ * @description post request with File as data. You can set options to the request. {@link IBaseHttpClientOptions}
263
+ * @param data - file that will be send to server
264
+ * @param url url
265
+ * @param options options
266
+ * @param options.headers by default {Content-Type: "application/json", Accepted: "json"}
267
+ * @returns {T} value. It depends from server response
268
+ *
269
+ * @example
270
+ * import HttpClient from "computec/appengine/uicore/model/Http";
271
+ *
272
+ * console.log("send attachment to server");
273
+ * const setAttachment = async (file: File) => {
274
+ * const isPicture = file.type.includes("image").toString();
275
+ * const data = await HttpClient.postFile<IAttachment[]>(file, `api/Attachments/SetAttachment/${isPicture}/true`);
276
+ * return data[0];
277
+ * }
278
+ *
279
+ */
280
+ static postFile(data, url, options = {}) {
281
+ const formData = new FormData();
282
+ formData.append("file", data);
283
+ return this.request(Object.assign(Object.assign({ headers: {} }, options), { method: "POST", url: url, body: formData, cache: "no-cache" }));
284
+ }
285
+ /**
286
+ * @description put request. You can set options to the request. {@link IBaseHttpClientOptions}
287
+ * @param data data
288
+ * @param url url
289
+ * @param options options
290
+ * @param options.headers by default {Content-Type: "application/json", Accepted: "json"}
291
+ * @returns {T} value. It depends from server response
292
+ */
293
+ static put(data, url, options = {}) {
294
+ return this.request(Object.assign(Object.assign({}, options), { method: "PUT", url: url, body: data }));
295
+ }
296
+ /**
297
+ * @description put request with JSON data. You can set options to the request. {@link IBaseHttpClientOptions}
298
+ * @param data data
299
+ * @param url url
300
+ * @param options options
301
+ * @returns {T} value. It depends from server response
302
+ */
303
+ static putJSON(data, url, options = {}) {
304
+ return this.put(JSON.stringify(data), url, Object.assign({ headers: {
305
+ "Content-Type": "application/json",
306
+ } }, options));
307
+ }
308
+ /**
309
+ * @description patch request. You can set options to the request. {@link IBaseHttpClientOptions}
310
+ * @param data data
311
+ * @param url url
312
+ * @param options options
313
+ * @param options.headers by default {Content-Type: "application/json", Accepted: "json"}
314
+ * @returns {T} value. It depends from server response
315
+ */
316
+ static patch(data, url, options = {}) {
317
+ return this.request(Object.assign(Object.assign({}, options), { method: "PATCH", url: url, body: data }));
318
+ }
319
+ /**
320
+ * @description patch request with JSON data. You can set options to the request. {@link IBaseHttpClientOptions}
321
+ * @param data data
322
+ * @param url url
323
+ * @param options options
324
+ * @returns {T} value. It depends from server response
325
+ */
326
+ static patchJSON(data, url, options = {}) {
327
+ return this.patch(JSON.stringify(data), url, Object.assign({ headers: {
328
+ "Content-Type": "application/json",
329
+ } }, options));
330
+ }
331
+ /**
332
+ * @description delete request. You can set options to the request. {@link IBaseHttpClientOptions}
333
+ * @param url url
334
+ * @param contentType by default "application/json"
335
+ * @returns {T} value. It depends from server response
336
+ */
337
+ static remove(url, options = {}) {
338
+ return this.request(Object.assign(Object.assign({ headers: {
339
+ Accepted: `${HeadersContentTypeEnum_1.default.Null},${HeadersContentTypeEnum_1.default.Text}`,
340
+ } }, options), { method: "DELETE", url: url, cache: "no-cache" }));
341
+ }
342
+ //#region private methods
343
+ static _appendToHeaders(headers, key, value) {
344
+ if (headers instanceof Headers) {
345
+ if (!headers.has(key))
346
+ headers.append(key, value);
347
+ }
348
+ if (HttpClientHelper_1.default.isHeadersArrayType(headers)) {
349
+ if (!headers.find(([k]) => k === key))
350
+ headers.push([key, value]);
351
+ }
352
+ return (headers[key] = value);
353
+ }
354
+ }
355
+ exports.default = HttpClient;
@@ -0,0 +1,9 @@
1
+ export default class HttpClientCacheOptions {
2
+ useCache: boolean;
3
+ refresh: boolean;
4
+ maxAge?: number;
5
+ constructor(cache?: boolean, refresh?: boolean, maxAge?: number);
6
+ getCacheControlHeader(): string;
7
+ getComputecCustomCacheControlHeader(): [string, string];
8
+ }
9
+ //# sourceMappingURL=HttpClientCacheOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpClientCacheOptions.d.ts","sourceRoot":"","sources":["../../src/communication/HttpClientCacheOptions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,sBAAsB;IAC1C,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;gBACJ,KAAK,GAAE,OAAe,EAAE,OAAO,GAAE,OAAe,EAAE,MAAM,CAAC,EAAE,MAAM;IAM7E,qBAAqB;IASrB,mCAAmC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;CAIvD"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class HttpClientCacheOptions {
4
+ constructor(cache = false, refresh = false, maxAge) {
5
+ this.useCache = cache;
6
+ this.refresh = refresh;
7
+ this.maxAge = maxAge;
8
+ }
9
+ getCacheControlHeader() {
10
+ if (!this.useCache)
11
+ return "no-store";
12
+ if (this.refresh)
13
+ return "no-cache";
14
+ if (this.maxAge) {
15
+ return `max-age=${this.maxAge}`;
16
+ }
17
+ return null;
18
+ }
19
+ getComputecCustomCacheControlHeader() {
20
+ if (this.useCache)
21
+ return ["use-ct-cache", "true"];
22
+ return null;
23
+ }
24
+ }
25
+ exports.default = HttpClientCacheOptions;
@@ -0,0 +1,17 @@
1
+ import HttpClientCacheOptions from "./HttpClientCacheOptions";
2
+ export interface IBaseHttpClientOptions {
3
+ headers?: HeadersInit;
4
+ cacheOptions?: HttpClientCacheOptions;
5
+ }
6
+ export interface IGetHttpClientOptions extends IBaseHttpClientOptions {
7
+ useCache?: boolean;
8
+ }
9
+ export interface ICustomViewHttpClientOptions extends IGetHttpClientOptions {
10
+ parameters?: string;
11
+ viewParameters?: string;
12
+ options?: string;
13
+ }
14
+ export interface IBasicHttpRequest extends RequestInit, IBaseHttpClientOptions {
15
+ url?: string;
16
+ }
17
+ //# sourceMappingURL=IBaseHttpClientOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IBaseHttpClientOptions.d.ts","sourceRoot":"","sources":["../../src/communication/IBaseHttpClientOptions.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,MAAM,0BAA0B,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IACtC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,YAAY,CAAC,EAAE,sBAAsB,CAAC;CACtC;AAED,MAAM,WAAW,qBAAsB,SAAQ,sBAAsB;IAEpE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,4BAA6B,SAAQ,qBAAqB;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAkB,SAAQ,WAAW,EAAE,sBAAsB;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;CACb"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });