@jsarc/cp-request 0.0.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/README.md +726 -0
- package/index.ts +1064 -0
- package/js/index.js +665 -0
- package/package.json +22 -0
- package/tsconfig.json +27 -0
- package/web/cp-request.js +6716 -0
- package/web/cp-request.min.js +1 -0
package/index.ts
ADDED
|
@@ -0,0 +1,1064 @@
|
|
|
1
|
+
import JON from '@jsarc/jon';
|
|
2
|
+
import { Pajo } from '@jsarc/pajo';
|
|
3
|
+
import { qust, Qust } from '@jsarc/qust';
|
|
4
|
+
|
|
5
|
+
// @ts-nocheck
|
|
6
|
+
|
|
7
|
+
interface Window {
|
|
8
|
+
default: typeof defaultElementGF;
|
|
9
|
+
HttpRequest: any;
|
|
10
|
+
WsRequest: any;
|
|
11
|
+
__bundledModules: any;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface HTTPRequestParams {
|
|
15
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
16
|
+
path: string;
|
|
17
|
+
headers?: any;
|
|
18
|
+
params?: any;
|
|
19
|
+
body?: any;
|
|
20
|
+
responseType?: "json" | "arraybuffer" | "blob" | "text";
|
|
21
|
+
auth?: {
|
|
22
|
+
username: string;
|
|
23
|
+
password: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface HTTPRequestResponse {
|
|
28
|
+
response: {
|
|
29
|
+
code: number;
|
|
30
|
+
type: string;
|
|
31
|
+
message: any;
|
|
32
|
+
};
|
|
33
|
+
data: any;
|
|
34
|
+
error?: any;
|
|
35
|
+
errors?: any[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
type HttpRequestMapAction = (code: number, type: string, message: string, data: any, cleanedData?: any, error?: any, errors?: any[]) => HTTPRequestResponse;
|
|
40
|
+
|
|
41
|
+
type HttpRequestReponseAction = (response: HTTPRequestResponse) => Promise<void> | void;
|
|
42
|
+
|
|
43
|
+
interface WSRequestParams {
|
|
44
|
+
path: string;
|
|
45
|
+
headers?: Record<string, string>;
|
|
46
|
+
params?: any;
|
|
47
|
+
auth?: {
|
|
48
|
+
username: string;
|
|
49
|
+
password: string;
|
|
50
|
+
};
|
|
51
|
+
autoReconnect?: boolean;
|
|
52
|
+
reconnectDelay?: number;
|
|
53
|
+
maxReconnectAttempts?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
interface WSMessageResponse {
|
|
58
|
+
response: {
|
|
59
|
+
code: number;
|
|
60
|
+
type: string;
|
|
61
|
+
message: any;
|
|
62
|
+
};
|
|
63
|
+
data: any;
|
|
64
|
+
error?: any;
|
|
65
|
+
errors?: any[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
type WsRequestMapAction = (
|
|
70
|
+
code: number,
|
|
71
|
+
type: string,
|
|
72
|
+
message: string,
|
|
73
|
+
data: any,
|
|
74
|
+
cleanedData?: any,
|
|
75
|
+
error?: any,
|
|
76
|
+
errors?: any[],
|
|
77
|
+
) => WSMessageResponse;
|
|
78
|
+
|
|
79
|
+
type WsRequestReponseAction = (response: WSMessageResponse) => Promise<void> | void;
|
|
80
|
+
|
|
81
|
+
const globalFunct = (function(global: any) {
|
|
82
|
+
'use strict';
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const NODEENV: 'development' | 'production' | 'debug' = 'development'; // development | debug | production
|
|
86
|
+
|
|
87
|
+
const langs = ['en', 'fr'];
|
|
88
|
+
const langCodes = {
|
|
89
|
+
'fr': 'fr_FR',
|
|
90
|
+
'en': 'en_US',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const dateTimeFormatInitial = '%Y-%m-%dT%H:%M:%S.%fZ';
|
|
94
|
+
const dateFormatInitial = '%Y-%m-%d';
|
|
95
|
+
const timeFormatInitial = '%H:%M:%S.%fZ';
|
|
96
|
+
|
|
97
|
+
const dateFormatForFile = '%Y%m%d%H%M%S';
|
|
98
|
+
const dateFormat1 = '%Y/%m/%d %H:%M:%S.%fZ';
|
|
99
|
+
const dateFormat2 = '%Y/%m/%d %H:%M:%S';
|
|
100
|
+
const dateFormat3 = '%Y/%m/%d %H:%M';
|
|
101
|
+
const dateFormat4 = '%d/%m/%Y %H:%M:%S GMT%z';
|
|
102
|
+
const dateFormat5 = '%Y/%m/%d';
|
|
103
|
+
const timeFormat1 = '%H:%M:%S.%fZ';
|
|
104
|
+
const timeFormat2 = '%H:%M:%S';
|
|
105
|
+
const timeFormat3 = '%H:%M:%S.%f';
|
|
106
|
+
const pagesPossibles = [5, 10, 15, 25, 50, 100, -1];
|
|
107
|
+
|
|
108
|
+
const regExpForAlphanumeric = /^[\w\s]{1,}/;
|
|
109
|
+
|
|
110
|
+
const tabNumerique = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
111
|
+
const tabAlphabetique = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
|
|
112
|
+
const tabAlphabetiqueInsensitive = [...tabAlphabetique, ...tabAlphabetique.map(x => x.toUpperCase())];
|
|
113
|
+
const tabAlphanumerique = [...tabNumerique, ...tabAlphabetique];
|
|
114
|
+
const tabAlphanumeriqueInsensitive = [...tabNumerique, ...tabAlphabetiqueInsensitive];
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
function defaultMapAction(
|
|
124
|
+
code: number,
|
|
125
|
+
type: string,
|
|
126
|
+
message: string,
|
|
127
|
+
data: any,
|
|
128
|
+
cleanedData: any,
|
|
129
|
+
error?: any,
|
|
130
|
+
errors?: any[],
|
|
131
|
+
) {
|
|
132
|
+
return ({
|
|
133
|
+
response: {
|
|
134
|
+
code,
|
|
135
|
+
type,
|
|
136
|
+
message,
|
|
137
|
+
},
|
|
138
|
+
data: cleanedData,
|
|
139
|
+
error,
|
|
140
|
+
errors,
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
function defaultErrMapAction(
|
|
144
|
+
code: number,
|
|
145
|
+
type: string,
|
|
146
|
+
message: string,
|
|
147
|
+
data: any,
|
|
148
|
+
cleanedData: any,
|
|
149
|
+
error?: any,
|
|
150
|
+
errors?: any[],
|
|
151
|
+
) {
|
|
152
|
+
return ({
|
|
153
|
+
response: {
|
|
154
|
+
code,
|
|
155
|
+
type,
|
|
156
|
+
message,
|
|
157
|
+
},
|
|
158
|
+
data: cleanedData,
|
|
159
|
+
error,
|
|
160
|
+
errors,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function defaultSuccessAction(response: HTTPRequestResponse) {
|
|
164
|
+
if (NODEENV === 'development') {
|
|
165
|
+
console.log('HttpRequest - actionRequest | successActionF - response:: ', response);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function defaultErrorAction(response: HTTPRequestResponse) {
|
|
169
|
+
if (NODEENV === 'development') {
|
|
170
|
+
console.log('HttpRequest - actionRequest | errorActionF - response:: ', response, ' && (typeof response):: ', (typeof response));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function getNotifRequestType(status: number | undefined = undefined) {
|
|
175
|
+
let type = "success";
|
|
176
|
+
if ([200].includes(status as any) || !status) {
|
|
177
|
+
status = 200;
|
|
178
|
+
type = "success";
|
|
179
|
+
} else if ([422].includes(status as any)) {
|
|
180
|
+
type = "warning";
|
|
181
|
+
} else if ([403, 409].includes(status as any)) {
|
|
182
|
+
type = "error_auth";
|
|
183
|
+
} else if ([419, 401].includes(status as any)) {
|
|
184
|
+
type = "error_auth_required";
|
|
185
|
+
} else if ([404, 405, 500, 400].includes(status as any)) {
|
|
186
|
+
type = "error";
|
|
187
|
+
} else if ([501].includes(status as any)) {
|
|
188
|
+
type = "info";
|
|
189
|
+
} else {
|
|
190
|
+
type = "error";
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return type;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
class HttpRequest {
|
|
197
|
+
protected host: string | undefined;
|
|
198
|
+
protected lang: 'fr' | 'en' = 'fr';
|
|
199
|
+
|
|
200
|
+
constructor() {
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
public initConfig(host: string, lang: 'fr' | 'en'): this {
|
|
204
|
+
if (typeof host === 'string' && host.length > 0) {
|
|
205
|
+
this.host = host;
|
|
206
|
+
}
|
|
207
|
+
if(['fr', 'en'].includes(lang)) {
|
|
208
|
+
this.lang = lang;
|
|
209
|
+
}
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private getDefaultError(): HTTPRequestResponse {
|
|
214
|
+
const message = {
|
|
215
|
+
fr: 'Error lors de la recuperation de la reponse',
|
|
216
|
+
en: 'Error lors de la recuperation de la reponse',
|
|
217
|
+
}[this.lang];
|
|
218
|
+
return {
|
|
219
|
+
response: {
|
|
220
|
+
code: 404,
|
|
221
|
+
type: 'error',
|
|
222
|
+
message: message
|
|
223
|
+
},
|
|
224
|
+
data: undefined,
|
|
225
|
+
error: new Error(message),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
protected async actionRequest<T = any>(
|
|
230
|
+
urlParams: HTTPRequestParams = {
|
|
231
|
+
path: "",
|
|
232
|
+
method: "GET",
|
|
233
|
+
},
|
|
234
|
+
otherParams: any = {},
|
|
235
|
+
schema: any = undefined,
|
|
236
|
+
mapAction: HttpRequestMapAction,
|
|
237
|
+
errMapAction?: HttpRequestMapAction,
|
|
238
|
+
successAction?: HttpRequestReponseAction,
|
|
239
|
+
errorAction?: HttpRequestReponseAction,
|
|
240
|
+
) {
|
|
241
|
+
if (NODEENV === 'development') {
|
|
242
|
+
console.log('HttpRequest - actionRequest | urlParams:: ', urlParams);
|
|
243
|
+
console.log('HttpRequest - actionRequest | otherParams:: ', otherParams);
|
|
244
|
+
console.log('HttpRequest - actionRequest | schema:: ', schema);
|
|
245
|
+
}
|
|
246
|
+
const FetchClass = this.getFetchClass();
|
|
247
|
+
urlParams = (
|
|
248
|
+
typeof urlParams === "object" &&
|
|
249
|
+
Array.isArray(urlParams) === false
|
|
250
|
+
) ? urlParams : {
|
|
251
|
+
path: "",
|
|
252
|
+
method: "GET",
|
|
253
|
+
};
|
|
254
|
+
const responseType: "json" | "arraybuffer" | "blob" | "text" = (
|
|
255
|
+
!!urlParams?.responseType &&
|
|
256
|
+
["json", "arraybuffer", "blob", "text"].includes(urlParams?.responseType)
|
|
257
|
+
) ? urlParams?.responseType : 'json';
|
|
258
|
+
const method: "GET" | "POST" | "PUT" | "DELETE" = [
|
|
259
|
+
"GET",
|
|
260
|
+
"POST",
|
|
261
|
+
"PUT",
|
|
262
|
+
"DELETE",
|
|
263
|
+
].includes(urlParams?.method) ? urlParams?.method : "GET";
|
|
264
|
+
let path: string = (typeof urlParams?.path === "string") ? urlParams?.path : "";
|
|
265
|
+
let headers = (
|
|
266
|
+
typeof urlParams?.headers === "object" &&
|
|
267
|
+
Array.isArray(urlParams?.headers) === false &&
|
|
268
|
+
Object.keys(urlParams?.headers).length > 0
|
|
269
|
+
) ? urlParams?.headers : undefined;
|
|
270
|
+
let params = (
|
|
271
|
+
typeof urlParams?.params === "object" &&
|
|
272
|
+
Array.isArray(urlParams?.params) === false &&
|
|
273
|
+
Object.keys(urlParams?.params).length > 0
|
|
274
|
+
) ? urlParams?.params : undefined;
|
|
275
|
+
let body: any = (
|
|
276
|
+
(
|
|
277
|
+
typeof urlParams?.body === "object" &&
|
|
278
|
+
Array.isArray(urlParams?.body) === false
|
|
279
|
+
) || urlParams?.body instanceof FormData
|
|
280
|
+
) ? urlParams?.body : undefined;
|
|
281
|
+
if (
|
|
282
|
+
typeof body === "object" &&
|
|
283
|
+
Array.isArray(body) === false
|
|
284
|
+
) {
|
|
285
|
+
body = JSON.stringify(urlParams?.body);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
otherParams = (
|
|
289
|
+
typeof otherParams === "object" &&
|
|
290
|
+
Array.isArray(otherParams) == false
|
|
291
|
+
) ? otherParams : {};
|
|
292
|
+
|
|
293
|
+
if (!!urlParams?.auth) {
|
|
294
|
+
headers = {
|
|
295
|
+
...headers,
|
|
296
|
+
Authorization: `Basic ${btoa(`${urlParams?.auth?.username}:${urlParams?.auth?.password}`)}`,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const mapActionF = (!!mapAction) ? mapAction : defaultMapAction;
|
|
301
|
+
const errMapActionF = (!!errMapAction) ? errMapAction : defaultErrMapAction;
|
|
302
|
+
const successActionF = !!successAction ? successAction : defaultSuccessAction;
|
|
303
|
+
const errorActionF = (!!errorAction) ? errorAction : defaultErrorAction;
|
|
304
|
+
if(!(schema instanceof JON.Object)) {
|
|
305
|
+
schema = new JON.Object(this.lang);
|
|
306
|
+
}
|
|
307
|
+
schema = schema.required();
|
|
308
|
+
|
|
309
|
+
try {
|
|
310
|
+
const newPath = (
|
|
311
|
+
typeof this.host === 'string' &&
|
|
312
|
+
this.host.length > 0
|
|
313
|
+
) ? Pajo.joinWithHost(this.host, path) : Pajo.join(path);
|
|
314
|
+
if (!!newPath) {
|
|
315
|
+
path = newPath;
|
|
316
|
+
}
|
|
317
|
+
if (!!params) {
|
|
318
|
+
path = `${path}${qust.stringify(params)}`;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
let resConfig: RequestInit = {
|
|
322
|
+
method,
|
|
323
|
+
headers,
|
|
324
|
+
...otherParams,
|
|
325
|
+
};
|
|
326
|
+
if (!!body) {
|
|
327
|
+
resConfig.body = body;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (NODEENV === 'development') {
|
|
331
|
+
console.log('HttpRequest - actionRequest | path (final):: ', path);
|
|
332
|
+
console.log('HttpRequest - actionRequest | resConfig:: ', resConfig);
|
|
333
|
+
}
|
|
334
|
+
const res = await FetchClass(path, {
|
|
335
|
+
...resConfig,
|
|
336
|
+
});
|
|
337
|
+
const hasContentType = !!res.headers.get("content-type");
|
|
338
|
+
const isJson = res.headers.get("content-type")?.includes("application/json");
|
|
339
|
+
if (NODEENV === 'development') {
|
|
340
|
+
console.log('HttpRequest - actionRequest | res:: ', res);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const statusResponse = res.status;
|
|
344
|
+
const typeResponse = getNotifRequestType(statusResponse);
|
|
345
|
+
let httpRes: any = undefined;
|
|
346
|
+
if (responseType === 'text' && hasContentType) {
|
|
347
|
+
httpRes = await res.text();
|
|
348
|
+
} else if (responseType === 'json' && !!isJson) {
|
|
349
|
+
httpRes = await res.json();
|
|
350
|
+
} else if (responseType === 'arraybuffer' && hasContentType) {
|
|
351
|
+
httpRes = await res.arrayBuffer();
|
|
352
|
+
}
|
|
353
|
+
let errors: any = undefined;
|
|
354
|
+
if (
|
|
355
|
+
typeof httpRes === 'object' &&
|
|
356
|
+
!Array.isArray(httpRes)
|
|
357
|
+
) {
|
|
358
|
+
errors = httpRes?.errors;
|
|
359
|
+
} else if (
|
|
360
|
+
typeof httpRes === 'string' &&
|
|
361
|
+
!(['info', 'success'].includes(typeResponse))
|
|
362
|
+
) {
|
|
363
|
+
errors = httpRes;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (NODEENV === 'development') {
|
|
367
|
+
console.log('HttpRequest - actionRequest | httpRes:: ', httpRes);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
let messageNotif: any = undefined;
|
|
371
|
+
if (!res.ok) {
|
|
372
|
+
if (
|
|
373
|
+
typeof errors === 'object' &&
|
|
374
|
+
!Array.isArray(errors) &&
|
|
375
|
+
Object.keys(errors).length > 0
|
|
376
|
+
) {
|
|
377
|
+
messageNotif = errors[
|
|
378
|
+
Object.keys(errors)[
|
|
379
|
+
Object.keys(errors).length - 1
|
|
380
|
+
]
|
|
381
|
+
];
|
|
382
|
+
} else if (
|
|
383
|
+
!!httpRes?.message
|
|
384
|
+
) {
|
|
385
|
+
messageNotif = httpRes?.message;
|
|
386
|
+
} else {
|
|
387
|
+
messageNotif = {
|
|
388
|
+
en: "unknown error",
|
|
389
|
+
fr: "erreur inconnue",
|
|
390
|
+
}[this.lang];
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (NODEENV === 'development') {
|
|
394
|
+
console.log("HttpRequest - actionRequest | messageNotif:: ", messageNotif);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
let codeF = statusResponse || (!!res.ok ? 200 : 404);
|
|
398
|
+
let typeF = (!!statusResponse ? typeResponse : (!!res.ok ? "success" : "error"));
|
|
399
|
+
let messageF = messageNotif;
|
|
400
|
+
let correctDataF = schema.isValid(httpRes);
|
|
401
|
+
let dataF = ((!!res.ok) ? httpRes : undefined);
|
|
402
|
+
let cleanedDataF = !!correctDataF ? dataF : this.getDefaultError();
|
|
403
|
+
let errorsF: any | undefined = undefined;
|
|
404
|
+
if(typeof errors === 'object' && !Array.isArray(errors)) {
|
|
405
|
+
errorsF = Object.values(errors);
|
|
406
|
+
} else if(typeof errors === 'object' && !!Array.isArray(errors)) {
|
|
407
|
+
errorsF = errorsF;
|
|
408
|
+
} else if(typeof errors === 'string' && errors.length > 0) {
|
|
409
|
+
errorsF = [errorsF]
|
|
410
|
+
}
|
|
411
|
+
let errorF = errorsF?.[0];
|
|
412
|
+
errorF = (!(errorF instanceof Error || typeof errorF === 'undefined' || errorF === null)) ? new Error(`${errorF}`) : errorF;
|
|
413
|
+
if(!errorF && !!messageNotif) {
|
|
414
|
+
errorF = new Error(`${messageNotif}`);
|
|
415
|
+
errorsF = [messageNotif];
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const cleanedData = (['success', 'info'].includes(typeF)) ? mapActionF(
|
|
419
|
+
codeF,
|
|
420
|
+
typeF,
|
|
421
|
+
messageF,
|
|
422
|
+
dataF,
|
|
423
|
+
cleanedDataF,
|
|
424
|
+
errorF,
|
|
425
|
+
errorsF,
|
|
426
|
+
) : errMapActionF(
|
|
427
|
+
codeF,
|
|
428
|
+
typeF,
|
|
429
|
+
messageF,
|
|
430
|
+
dataF,
|
|
431
|
+
cleanedDataF,
|
|
432
|
+
errorF,
|
|
433
|
+
errorsF,
|
|
434
|
+
);
|
|
435
|
+
if (NODEENV === 'development') {
|
|
436
|
+
console.log("HttpRequest - actionRequest | cleanedData (OLD):: ", cleanedData);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (cleanedData.response.type === "success") {
|
|
440
|
+
await successActionF(cleanedData);
|
|
441
|
+
} else {
|
|
442
|
+
await errorActionF(cleanedData);
|
|
443
|
+
}
|
|
444
|
+
} catch (error: any) {
|
|
445
|
+
let message = 'erreur inconnue';
|
|
446
|
+
if(typeof error?.message === 'string') {
|
|
447
|
+
message = error?.message;
|
|
448
|
+
} else if(typeof error === 'string') {
|
|
449
|
+
message = error;
|
|
450
|
+
}
|
|
451
|
+
if (message.toLowerCase() === 'failed to fetch') {
|
|
452
|
+
message = {
|
|
453
|
+
en: "Service unavailable. Please try again later.",
|
|
454
|
+
fr: "Service indisponible. Veuillez réessayer plus tard.",
|
|
455
|
+
}[this.lang];
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (NODEENV === 'development') {
|
|
459
|
+
console.log("[ERROR] HttpRequest - actionRequest | error:: ", error);
|
|
460
|
+
console.log("[ERROR] HttpRequest - actionRequest | message:: ", message);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
let codeF: number = error?.status || 404;
|
|
464
|
+
let typeF: string = !!error?.status ? getNotifRequestType(error?.status) : "error";
|
|
465
|
+
let messageF: string = message;
|
|
466
|
+
let dataF: any = error;
|
|
467
|
+
let correctDataF = schema.isValid(dataF);
|
|
468
|
+
let cleanedDataF = !!correctDataF ? dataF : this.getDefaultError();
|
|
469
|
+
let errorsF: any | undefined = [message];
|
|
470
|
+
if(typeof errorsF === 'object' && !Array.isArray(errorsF)) {
|
|
471
|
+
errorsF = Object.values(errorsF);
|
|
472
|
+
} else if(typeof errorsF === 'object' && !!Array.isArray(errorsF)) {
|
|
473
|
+
errorsF = errorsF;
|
|
474
|
+
} else if(typeof errorsF === 'string' && errorsF.length > 0) {
|
|
475
|
+
errorsF = [errorsF]
|
|
476
|
+
}
|
|
477
|
+
let errorF = errorsF?.[0];
|
|
478
|
+
errorF = (!(errorF instanceof Error || typeof errorF === 'undefined' || errorF === null)) ? new Error(`${errorF}`) : errorF;
|
|
479
|
+
if(!errorF && !!message) {
|
|
480
|
+
errorF = new Error(`${message}`);
|
|
481
|
+
errorsF = [message];
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (NODEENV === 'development') {
|
|
485
|
+
console.log("[ERROR] HttpRequest - actionRequest | codeF:: ", codeF);
|
|
486
|
+
console.log("[ERROR] HttpRequest - actionRequest | typeF:: ", typeF);
|
|
487
|
+
console.log("[ERROR] HttpRequest - actionRequest | dataF:: ", dataF);
|
|
488
|
+
console.log("[ERROR] HttpRequest - actionRequest | correctDataF:: ", correctDataF);
|
|
489
|
+
console.log("[ERROR] HttpRequest - actionRequest | cleanedDataF:: ", cleanedDataF);
|
|
490
|
+
console.log("[ERROR] HttpRequest - actionRequest | errorsF:: ", errorsF);
|
|
491
|
+
console.log("[ERROR] HttpRequest - actionRequest | errorsF:: ", errorsF);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const errorDatas = errMapActionF(
|
|
495
|
+
codeF,
|
|
496
|
+
typeF,
|
|
497
|
+
messageF,
|
|
498
|
+
dataF,
|
|
499
|
+
cleanedDataF,
|
|
500
|
+
errorF,
|
|
501
|
+
errorsF,
|
|
502
|
+
);
|
|
503
|
+
if (NODEENV === 'development') {
|
|
504
|
+
console.log("[ERROR] HttpRequest - actionRequest | errorDatas:: ", errorDatas);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
await errorActionF(errorDatas);
|
|
508
|
+
|
|
509
|
+
return errorDatas as T;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
public async findAllRequests<T = any>(
|
|
514
|
+
urlParams: HTTPRequestParams = {
|
|
515
|
+
path: "",
|
|
516
|
+
method: "GET",
|
|
517
|
+
},
|
|
518
|
+
otherParams: any = {},
|
|
519
|
+
successAction: HttpRequestReponseAction = defaultSuccessAction,
|
|
520
|
+
errorAction: HttpRequestReponseAction = defaultErrorAction,
|
|
521
|
+
) {
|
|
522
|
+
const schema = new JON.Object(this.lang).struct({
|
|
523
|
+
response: new JON.Object(this.lang).struct({
|
|
524
|
+
type: new JON.Enum(this.lang).choices('warning', 'success', 'danger', 'info').required(),
|
|
525
|
+
code: new JON.Number(this.lang).required(),
|
|
526
|
+
message: new JON.String(this.lang),
|
|
527
|
+
}),
|
|
528
|
+
datas: new JON.Array(this.lang).types(
|
|
529
|
+
new JON.Object(this.lang).min(1).required(),
|
|
530
|
+
).required().default([]),
|
|
531
|
+
});
|
|
532
|
+
const mapAction: HttpRequestMapAction = (
|
|
533
|
+
code,
|
|
534
|
+
type,
|
|
535
|
+
message,
|
|
536
|
+
data,
|
|
537
|
+
cleanedData,
|
|
538
|
+
error,
|
|
539
|
+
errors
|
|
540
|
+
) => {
|
|
541
|
+
return ({
|
|
542
|
+
response: {
|
|
543
|
+
code,
|
|
544
|
+
type,
|
|
545
|
+
message,
|
|
546
|
+
},
|
|
547
|
+
data: cleanedData?.datas,
|
|
548
|
+
error,
|
|
549
|
+
errors,
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
const errMapAction: HttpRequestMapAction = (
|
|
553
|
+
code,
|
|
554
|
+
type,
|
|
555
|
+
message,
|
|
556
|
+
data,
|
|
557
|
+
cleanedData,
|
|
558
|
+
error,
|
|
559
|
+
errors
|
|
560
|
+
) => {
|
|
561
|
+
return ({
|
|
562
|
+
response: {
|
|
563
|
+
code,
|
|
564
|
+
type,
|
|
565
|
+
message,
|
|
566
|
+
},
|
|
567
|
+
data: cleanedData?.datas,
|
|
568
|
+
error,
|
|
569
|
+
errors,
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
await this.actionRequest<T>(
|
|
573
|
+
urlParams,
|
|
574
|
+
otherParams,
|
|
575
|
+
schema,
|
|
576
|
+
mapAction,
|
|
577
|
+
errMapAction,
|
|
578
|
+
successAction,
|
|
579
|
+
errorAction,
|
|
580
|
+
)
|
|
581
|
+
}
|
|
582
|
+
public async findOneRequest<T = any>(
|
|
583
|
+
urlParams: HTTPRequestParams = {
|
|
584
|
+
path: "",
|
|
585
|
+
method: "GET",
|
|
586
|
+
},
|
|
587
|
+
otherParams: any = {},
|
|
588
|
+
successAction: HttpRequestReponseAction = defaultSuccessAction,
|
|
589
|
+
errorAction: HttpRequestReponseAction = defaultErrorAction,
|
|
590
|
+
) {
|
|
591
|
+
const schema = new JON.Object(this.lang).struct({
|
|
592
|
+
response: new JON.Object(this.lang).struct({
|
|
593
|
+
type: new JON.Enum(this.lang).choices('warning', 'success', 'danger', 'info').required(),
|
|
594
|
+
code: new JON.Number(this.lang).required(),
|
|
595
|
+
message: new JON.String(this.lang),
|
|
596
|
+
}),
|
|
597
|
+
data: new JON.Object(this.lang).min(1),
|
|
598
|
+
});
|
|
599
|
+
const mapAction: HttpRequestMapAction = (
|
|
600
|
+
code,
|
|
601
|
+
type,
|
|
602
|
+
message,
|
|
603
|
+
data,
|
|
604
|
+
cleanedData,
|
|
605
|
+
error,
|
|
606
|
+
errors
|
|
607
|
+
) => {
|
|
608
|
+
return ({
|
|
609
|
+
response: {
|
|
610
|
+
code,
|
|
611
|
+
type,
|
|
612
|
+
message,
|
|
613
|
+
},
|
|
614
|
+
data: cleanedData?.data,
|
|
615
|
+
error,
|
|
616
|
+
errors,
|
|
617
|
+
});
|
|
618
|
+
};
|
|
619
|
+
const errMapAction: HttpRequestMapAction = (
|
|
620
|
+
code,
|
|
621
|
+
type,
|
|
622
|
+
message,
|
|
623
|
+
data,
|
|
624
|
+
cleanedData,
|
|
625
|
+
error,
|
|
626
|
+
errors
|
|
627
|
+
) => {
|
|
628
|
+
return ({
|
|
629
|
+
response: {
|
|
630
|
+
code,
|
|
631
|
+
type,
|
|
632
|
+
message,
|
|
633
|
+
},
|
|
634
|
+
data: cleanedData?.data,
|
|
635
|
+
error,
|
|
636
|
+
errors,
|
|
637
|
+
});
|
|
638
|
+
};
|
|
639
|
+
await this.actionRequest<T>(
|
|
640
|
+
urlParams,
|
|
641
|
+
otherParams,
|
|
642
|
+
schema,
|
|
643
|
+
mapAction,
|
|
644
|
+
errMapAction,
|
|
645
|
+
successAction,
|
|
646
|
+
errorAction,
|
|
647
|
+
)
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
protected getFetchClass() {
|
|
651
|
+
return (typeof window !== "undefined") ? (window as any).fetch : fetch;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
static exposeToGlobal(): void {
|
|
655
|
+
if (typeof window !== "undefined") {
|
|
656
|
+
(window as any).HttpRequest = HttpRequest;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
if (typeof window !== "undefined") {
|
|
662
|
+
(window as any).HttpRequest = HttpRequest;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
function defaultMapActionWS(
|
|
678
|
+
code: number,
|
|
679
|
+
type: string,
|
|
680
|
+
message: string,
|
|
681
|
+
data: any,
|
|
682
|
+
cleanedData: any,
|
|
683
|
+
error?: any,
|
|
684
|
+
errors?: any[],
|
|
685
|
+
) {
|
|
686
|
+
return {
|
|
687
|
+
response: { code, type, message },
|
|
688
|
+
data: cleanedData,
|
|
689
|
+
error,
|
|
690
|
+
errors,
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function defaultErrMapActionWS(
|
|
695
|
+
code: number,
|
|
696
|
+
type: string,
|
|
697
|
+
message: string,
|
|
698
|
+
data: any,
|
|
699
|
+
cleanedData: any,
|
|
700
|
+
error?: any,
|
|
701
|
+
errors?: any[],
|
|
702
|
+
) {
|
|
703
|
+
return {
|
|
704
|
+
response: { code, type, message },
|
|
705
|
+
data: cleanedData,
|
|
706
|
+
error,
|
|
707
|
+
errors,
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
function defaultSuccessActionWS(res: WSMessageResponse) {
|
|
712
|
+
if (NODEENV === "development") {
|
|
713
|
+
console.log("WsRequest | success :: ", res);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function defaultErrorActionWS(res: WSMessageResponse) {
|
|
718
|
+
if (NODEENV === "development") {
|
|
719
|
+
console.log("WsRequest | error :: ", res);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
class WsRequest {
|
|
724
|
+
protected host: string | undefined;
|
|
725
|
+
protected lang: "fr" | "en" = "fr";
|
|
726
|
+
|
|
727
|
+
private socket: WebSocket | null = null;
|
|
728
|
+
private connected = false;
|
|
729
|
+
|
|
730
|
+
private autoReconnect = true;
|
|
731
|
+
private reconnectDelay = 2000;
|
|
732
|
+
private maxReconnectAttempts = 10;
|
|
733
|
+
private reconnectAttempts = 0;
|
|
734
|
+
|
|
735
|
+
private messageQueue: any[] = [];
|
|
736
|
+
|
|
737
|
+
constructor() {}
|
|
738
|
+
|
|
739
|
+
public initConfig(host: string, lang: "fr" | "en"): this {
|
|
740
|
+
if (host && typeof host === "string") {
|
|
741
|
+
this.host = host;
|
|
742
|
+
}
|
|
743
|
+
if (["fr", "en"].includes(lang)) {
|
|
744
|
+
this.lang = lang;
|
|
745
|
+
}
|
|
746
|
+
return this;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
public connect(params: WSRequestParams): void {
|
|
750
|
+
const {
|
|
751
|
+
path,
|
|
752
|
+
auth,
|
|
753
|
+
headers = {},
|
|
754
|
+
autoReconnect = true,
|
|
755
|
+
reconnectDelay = 2000,
|
|
756
|
+
maxReconnectAttempts = 10,
|
|
757
|
+
} = params;
|
|
758
|
+
let urlParams = (
|
|
759
|
+
typeof params?.params === "object" &&
|
|
760
|
+
!Array.isArray(params?.params) &&
|
|
761
|
+
Object.keys(params?.params).length > 0
|
|
762
|
+
) ? params?.params : undefined;
|
|
763
|
+
|
|
764
|
+
this.autoReconnect = autoReconnect;
|
|
765
|
+
this.reconnectDelay = reconnectDelay;
|
|
766
|
+
this.maxReconnectAttempts = maxReconnectAttempts;
|
|
767
|
+
|
|
768
|
+
let url = (
|
|
769
|
+
typeof this.host === 'string' &&
|
|
770
|
+
this.host.length > 0
|
|
771
|
+
) ? Pajo.joinWithHost(this.host, path) : Pajo.join(path);
|
|
772
|
+
if (!!urlParams) {
|
|
773
|
+
url = `${url}${qust.stringify(urlParams)}`;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
if (auth) {
|
|
777
|
+
headers["Authorization"] =
|
|
778
|
+
"Basic " + btoa(`${auth.username}:${auth.password}`);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
if (NODEENV === "development") {
|
|
782
|
+
console.log("WsRequest | connecting to:", url);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
this.socket = new (this.getWsClass())(url || '');
|
|
786
|
+
|
|
787
|
+
if(!!this.socket) {
|
|
788
|
+
this.socket.onopen = () => {
|
|
789
|
+
this.connected = true;
|
|
790
|
+
this.reconnectAttempts = 0;
|
|
791
|
+
|
|
792
|
+
if (NODEENV === "development") {
|
|
793
|
+
console.log("WsRequest | WebSocket connected");
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
while (this.messageQueue.length > 0) {
|
|
797
|
+
this.socket?.send(this.messageQueue.shift());
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
this.socket.onerror = (err) => {
|
|
802
|
+
if (NODEENV === "development") {
|
|
803
|
+
console.log("WsRequest | error:", err);
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
this.socket.onclose = () => {
|
|
808
|
+
this.connected = false;
|
|
809
|
+
if (NODEENV === "development") {
|
|
810
|
+
console.log("WsRequest | closed");
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if (this.autoReconnect && this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
814
|
+
setTimeout(() => {
|
|
815
|
+
this.reconnectAttempts++;
|
|
816
|
+
if (NODEENV === "development") {
|
|
817
|
+
console.log("WsRequest | reconnect attempt:", this.reconnectAttempts);
|
|
818
|
+
}
|
|
819
|
+
this.connect(params);
|
|
820
|
+
}, this.reconnectDelay);
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
public async actionMessage<T = any>(
|
|
827
|
+
message: any,
|
|
828
|
+
schema: any = undefined,
|
|
829
|
+
mapAction: WsRequestMapAction = defaultMapActionWS,
|
|
830
|
+
errMapAction: WsRequestMapAction = defaultErrMapActionWS,
|
|
831
|
+
successAction: WsRequestReponseAction = defaultSuccessActionWS,
|
|
832
|
+
errorAction: WsRequestReponseAction = defaultErrorActionWS,
|
|
833
|
+
) {
|
|
834
|
+
if (!this.connected || !this.socket) {
|
|
835
|
+
this.messageQueue.push(JSON.stringify(message));
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
if(!(schema instanceof JON.Object)) {
|
|
840
|
+
schema = new JON.Object(this.lang);
|
|
841
|
+
}
|
|
842
|
+
schema = schema.required();
|
|
843
|
+
|
|
844
|
+
const payload = JSON.stringify(message);
|
|
845
|
+
|
|
846
|
+
return new Promise<T>((resolve) => {
|
|
847
|
+
this.socket!.onmessage = async (e) => {
|
|
848
|
+
let resJson: any = undefined;
|
|
849
|
+
try {
|
|
850
|
+
resJson = JSON.parse(e.data);
|
|
851
|
+
} catch (err) {
|
|
852
|
+
resJson = e.data;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
let isValid = schema.isValid(resJson);
|
|
856
|
+
let cleaned = isValid ? resJson : undefined;
|
|
857
|
+
|
|
858
|
+
let codeF = resJson?.response?.code ?? 200;
|
|
859
|
+
let typeF = resJson?.response?.type ?? "success";
|
|
860
|
+
let messageF = resJson?.response?.message ?? undefined;
|
|
861
|
+
|
|
862
|
+
let errorsF: any[] | undefined = [];
|
|
863
|
+
if (resJson?.errors) {
|
|
864
|
+
errorsF = Array.isArray(resJson.errors)
|
|
865
|
+
? resJson.errors
|
|
866
|
+
: Object.values(resJson.errors);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
let errorF = errorsF?.[0];
|
|
870
|
+
|
|
871
|
+
if (!(errorF instanceof Error)) {
|
|
872
|
+
if (typeof errorF !== "undefined") errorF = new Error(`${errorF}`);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
const responseCleaned =
|
|
876
|
+
typeF === "success" || typeF === "info"
|
|
877
|
+
? mapAction(
|
|
878
|
+
codeF,
|
|
879
|
+
typeF,
|
|
880
|
+
messageF,
|
|
881
|
+
resJson,
|
|
882
|
+
cleaned,
|
|
883
|
+
errorF,
|
|
884
|
+
errorsF,
|
|
885
|
+
)
|
|
886
|
+
: errMapAction(
|
|
887
|
+
codeF,
|
|
888
|
+
typeF,
|
|
889
|
+
messageF,
|
|
890
|
+
resJson,
|
|
891
|
+
cleaned,
|
|
892
|
+
errorF,
|
|
893
|
+
errorsF,
|
|
894
|
+
);
|
|
895
|
+
|
|
896
|
+
if (responseCleaned.response.type === "success") {
|
|
897
|
+
await successAction(responseCleaned);
|
|
898
|
+
} else {
|
|
899
|
+
await errorAction(responseCleaned);
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
resolve(responseCleaned as T);
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
this.socket!.send(payload);
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
public async findAllMessages<T = any>(
|
|
910
|
+
message: any,
|
|
911
|
+
successAction: WsRequestReponseAction = defaultSuccessActionWS,
|
|
912
|
+
errorAction: WsRequestReponseAction = defaultErrorActionWS,
|
|
913
|
+
) {
|
|
914
|
+
const schema = new JON.Object(this.lang).struct({
|
|
915
|
+
response: new JON.Object(this.lang).struct({
|
|
916
|
+
type: new JON.Enum(this.lang)
|
|
917
|
+
.choices("warning", "success", "danger", "info")
|
|
918
|
+
.required(),
|
|
919
|
+
code: new JON.Number(this.lang).required(),
|
|
920
|
+
message: new JON.String(this.lang),
|
|
921
|
+
}),
|
|
922
|
+
datas: new JON.Array(this.lang)
|
|
923
|
+
.types(new JON.Object(this.lang).min(1).required())
|
|
924
|
+
.default([]),
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
const mapAction: WsRequestMapAction = (code, type, message, data, cleaned, error, errors) => {
|
|
928
|
+
return {
|
|
929
|
+
response: { code, type, message },
|
|
930
|
+
data: cleaned?.datas || [],
|
|
931
|
+
error,
|
|
932
|
+
errors,
|
|
933
|
+
};
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
return await this.actionMessage<T>(
|
|
937
|
+
message,
|
|
938
|
+
schema,
|
|
939
|
+
mapAction,
|
|
940
|
+
mapAction,
|
|
941
|
+
successAction,
|
|
942
|
+
errorAction,
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
public async findOneMessage<T = any>(
|
|
947
|
+
message: any,
|
|
948
|
+
successAction: WsRequestReponseAction = defaultSuccessActionWS,
|
|
949
|
+
errorAction: WsRequestReponseAction = defaultErrorActionWS,
|
|
950
|
+
) {
|
|
951
|
+
const schema = new JON.Object(this.lang).struct({
|
|
952
|
+
response: new JON.Object(this.lang).struct({
|
|
953
|
+
type: new JON.Enum(this.lang)
|
|
954
|
+
.choices("warning", "success", "danger", "info")
|
|
955
|
+
.required(),
|
|
956
|
+
code: new JON.Number(this.lang).required(),
|
|
957
|
+
message: new JON.String(this.lang),
|
|
958
|
+
}),
|
|
959
|
+
data: new JON.Object(this.lang).min(1),
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
const mapAction: WsRequestMapAction = (code, type, message, data, cleaned, error, errors) => {
|
|
963
|
+
return {
|
|
964
|
+
response: { code, type, message },
|
|
965
|
+
data: cleaned?.data || null,
|
|
966
|
+
error,
|
|
967
|
+
errors,
|
|
968
|
+
};
|
|
969
|
+
};
|
|
970
|
+
|
|
971
|
+
return await this.actionMessage<T>(
|
|
972
|
+
message,
|
|
973
|
+
schema,
|
|
974
|
+
mapAction,
|
|
975
|
+
mapAction,
|
|
976
|
+
successAction,
|
|
977
|
+
errorAction,
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
protected getWsClass() {
|
|
982
|
+
return (typeof window !== "undefined") ? (window as any).WebSocket : WebSocket;
|
|
983
|
+
}
|
|
984
|
+
static exposeToGlobal(): void {
|
|
985
|
+
if (typeof window !== "undefined") {
|
|
986
|
+
(window as any).WsRequest = WsRequest;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
if (typeof window !== "undefined") {
|
|
992
|
+
(window as any).WsRequest = WsRequest;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
const defaultExport = {
|
|
1001
|
+
HttpRequest,
|
|
1002
|
+
WsRequest,
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
const globalFunctModule = {
|
|
1009
|
+
default: defaultExport,
|
|
1010
|
+
HttpRequest: HttpRequest,
|
|
1011
|
+
WsRequest: WsRequest,
|
|
1012
|
+
};
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
const __bundledModules = globalFunctModule;
|
|
1016
|
+
|
|
1017
|
+
if (typeof global !== 'undefined') {
|
|
1018
|
+
(global as any).default = defaultExport;
|
|
1019
|
+
(global as any).HttpRequest = HttpRequest;
|
|
1020
|
+
(global as any).WsRequest = WsRequest;
|
|
1021
|
+
(global as any).__bundledModules = __bundledModules;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
if (typeof window !== "undefined") {
|
|
1025
|
+
(window as any).default = defaultExport;
|
|
1026
|
+
(window as any).HttpRequest = HttpRequest;
|
|
1027
|
+
(window as any).WsRequest = WsRequest;
|
|
1028
|
+
(window as any).__bundledModules = __bundledModules;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
if (typeof exports !== 'undefined') {
|
|
1032
|
+
exports.default = defaultExport;
|
|
1033
|
+
exports.HttpRequest = HttpRequest;
|
|
1034
|
+
exports.WsRequest = WsRequest;
|
|
1035
|
+
}
|
|
1036
|
+
return globalFunctModule;
|
|
1037
|
+
|
|
1038
|
+
})(typeof global !== 'undefined' ? global :
|
|
1039
|
+
typeof window !== 'undefined' ? window :
|
|
1040
|
+
typeof self !== 'undefined' ? self :
|
|
1041
|
+
typeof globalThis !== 'undefined' ? globalThis :
|
|
1042
|
+
{});
|
|
1043
|
+
|
|
1044
|
+
type HttpRequestElementTypeGF = typeof globalFunct.HttpRequest;
|
|
1045
|
+
|
|
1046
|
+
type WsRequestElementTypeGF = typeof globalFunct.WsRequest;
|
|
1047
|
+
|
|
1048
|
+
type DefaultElementTypeGF = typeof globalFunct.default;
|
|
1049
|
+
|
|
1050
|
+
const HttpRequestElementGF: HttpRequestElementTypeGF = globalFunct.HttpRequest;
|
|
1051
|
+
|
|
1052
|
+
const WsRequestElementGF: WsRequestElementTypeGF = globalFunct.WsRequest;
|
|
1053
|
+
|
|
1054
|
+
const defaultElementGF: DefaultElementTypeGF = globalFunct.default;
|
|
1055
|
+
|
|
1056
|
+
export {
|
|
1057
|
+
defaultElementGF as default,
|
|
1058
|
+
HttpRequestElementGF as HttpRequest,
|
|
1059
|
+
WsRequestElementGF as WsRequest,
|
|
1060
|
+
};
|
|
1061
|
+
export type {
|
|
1062
|
+
DefaultElementTypeGF,
|
|
1063
|
+
HttpRequestElementTypeGF,WsRequestElementTypeGF,
|
|
1064
|
+
};
|