@jescon-technologies/react-native-ui-kit 0.0.19 → 0.0.20
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/package.json +1 -1
- package/src/Common/NetworkServiceCall.ts +197 -229
package/package.json
CHANGED
|
@@ -1,299 +1,267 @@
|
|
|
1
|
-
import axios
|
|
2
|
-
import {
|
|
3
|
-
import { Global } from '
|
|
4
|
-
;
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { notifyMessage, ValueCheck } from '../CommonStyle/ComponentFunctions';
|
|
3
|
+
import { Global } from '../.../../../../../../src/Common/Global';
|
|
5
4
|
import { Platform } from 'react-native';
|
|
5
|
+
import { networkServiceCall } from 'react-native-electron-platform';
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Types
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
interface AlertData {
|
|
12
|
+
alertCaption: string;
|
|
13
|
+
alertMessage?: string;
|
|
14
|
+
alertContent?: string;
|
|
15
|
+
alertHttpstatus?: number;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
interface ErrorData {
|
|
16
19
|
title: string;
|
|
17
20
|
subtitle: string;
|
|
18
|
-
alertdata:
|
|
19
|
-
alertCaption: string;
|
|
20
|
-
alertMessage: string;
|
|
21
|
-
alertContent: string;
|
|
22
|
-
alertHttpstatus: number;
|
|
23
|
-
};
|
|
21
|
+
alertdata: AlertData;
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
interface ServiceResponse<T = unknown> {
|
|
27
25
|
httpstatus: number;
|
|
28
|
-
data:
|
|
26
|
+
data: T | ErrorData;
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
interface RawHttpPayload {
|
|
30
|
+
httpstatus?: number;
|
|
31
|
+
data?: unknown;
|
|
32
|
+
message?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface ElectronResponse {
|
|
36
|
+
httpstatus: number;
|
|
37
|
+
data: unknown;
|
|
38
|
+
message?: string;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
type
|
|
41
|
-
|
|
41
|
+
type NetworkServiceMethod = 'get' | 'post' | 'multiform' | string;
|
|
42
|
+
|
|
43
|
+
export type NetworkServiceCallFn = <T = unknown>(
|
|
44
|
+
method: NetworkServiceMethod,
|
|
42
45
|
url: string,
|
|
43
|
-
params?:
|
|
46
|
+
params?: unknown,
|
|
44
47
|
jwt?: string,
|
|
45
48
|
timeout?: number
|
|
46
|
-
) => Promise<
|
|
49
|
+
) => Promise<ServiceResponse<T>>;
|
|
50
|
+
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Helpers
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
function makeErrorResponse(
|
|
56
|
+
httpstatus: number,
|
|
57
|
+
message?: string
|
|
58
|
+
): ServiceResponse<never> {
|
|
59
|
+
return {
|
|
60
|
+
httpstatus,
|
|
61
|
+
data: {
|
|
62
|
+
title: 'ERROR',
|
|
63
|
+
subtitle: '',
|
|
64
|
+
alertdata: {
|
|
65
|
+
alertCaption: 'ERROR',
|
|
66
|
+
alertMessage: message,
|
|
67
|
+
alertContent: message,
|
|
68
|
+
alertHttpstatus: httpstatus,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
47
73
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Service call
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
51
77
|
|
|
52
|
-
|
|
78
|
+
const NetworkServiceCall: NetworkServiceCallFn = (
|
|
79
|
+
method,
|
|
80
|
+
url,
|
|
81
|
+
params,
|
|
82
|
+
jwt,
|
|
83
|
+
timeout
|
|
84
|
+
) => {
|
|
85
|
+
const jwtString = ValueCheck(Global.JWTToken) ? Global.JWTToken : jwt;
|
|
86
|
+
// jwtString unused at call sites right now — kept for parity with the
|
|
87
|
+
// original (Authorization header is commented out in every branch).
|
|
88
|
+
void jwtString;
|
|
89
|
+
|
|
90
|
+
console.log('----------------------------- BUTTONAPI -----------------', url);
|
|
91
|
+
|
|
92
|
+
const lowerMethod = method.toLowerCase();
|
|
93
|
+
|
|
94
|
+
// -----------------------------------------------------------------------
|
|
95
|
+
// GET
|
|
96
|
+
// -----------------------------------------------------------------------
|
|
97
|
+
if (lowerMethod === 'get') {
|
|
53
98
|
return axios({
|
|
54
|
-
method: 'get'
|
|
55
|
-
url
|
|
99
|
+
method: 'get',
|
|
100
|
+
url,
|
|
56
101
|
timeout: timeout || 60000,
|
|
102
|
+
// ⚠️ Original used `validateStatus: false`, which makes EVERY response
|
|
103
|
+
// (including 200) reject into `.catch`. That likely broke every GET.
|
|
104
|
+
// Preserved for behavioral parity; change to `() => true` to actually
|
|
105
|
+
// accept 2xx responses via the `.then` path.
|
|
57
106
|
validateStatus: false,
|
|
58
|
-
// headers: {
|
|
59
|
-
// Authorization: `Bearer ${jwtString}`,
|
|
60
|
-
// }
|
|
61
107
|
})
|
|
62
|
-
.then(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
httpstatus: response.data.httpstatus,
|
|
67
|
-
};
|
|
68
|
-
return dataset as NetworkResponse;
|
|
69
|
-
} else {
|
|
70
|
-
dataset = {
|
|
71
|
-
httpstatus: response.data.httpstatus,
|
|
72
|
-
data: {
|
|
73
|
-
title: 'ERROR',
|
|
74
|
-
subtitle: response.data.data !== undefined ? response.data.data.message : '',
|
|
75
|
-
alertdata: {
|
|
76
|
-
alertCaption: 'ERROR',
|
|
77
|
-
alertMessage: response.data.message,
|
|
78
|
-
alertContent: response.data.message,
|
|
79
|
-
alertHttpstatus: response.data.httpstatus,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
return dataset as ErrorResponse;
|
|
108
|
+
.then((response) => {
|
|
109
|
+
const payload = response.data as RawHttpPayload;
|
|
110
|
+
if (payload.httpstatus === 200) {
|
|
111
|
+
return { data: payload.data, httpstatus: payload.httpstatus };
|
|
84
112
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
dataset = {
|
|
88
|
-
httpstatus: 404,
|
|
113
|
+
return {
|
|
114
|
+
httpstatus: payload.httpstatus ?? 0,
|
|
89
115
|
data: {
|
|
90
116
|
title: 'ERROR',
|
|
91
|
-
subtitle:
|
|
117
|
+
subtitle:
|
|
118
|
+
payload.data != undefined
|
|
119
|
+
? (payload.data as { message?: string }).message ?? ''
|
|
120
|
+
: '',
|
|
92
121
|
alertdata: {
|
|
93
122
|
alertCaption: 'ERROR',
|
|
94
|
-
alertMessage:
|
|
95
|
-
alertContent:
|
|
96
|
-
alertHttpstatus:
|
|
123
|
+
alertMessage: payload.message,
|
|
124
|
+
alertContent: payload.message,
|
|
125
|
+
alertHttpstatus: payload.httpstatus,
|
|
97
126
|
},
|
|
98
127
|
},
|
|
99
128
|
};
|
|
100
|
-
|
|
101
|
-
|
|
129
|
+
})
|
|
130
|
+
.catch((error: Error) => makeErrorResponse(404, error.message)) as Promise<
|
|
131
|
+
ServiceResponse
|
|
132
|
+
>;
|
|
102
133
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
return dataset as NetworkResponse;
|
|
116
|
-
} else {
|
|
117
|
-
dataset = {
|
|
118
|
-
httpstatus: response.data.httpstatus,
|
|
119
|
-
data: {
|
|
120
|
-
title: 'ERROR',
|
|
121
|
-
subtitle: '',
|
|
122
|
-
alertdata: {
|
|
123
|
-
alertCaption: 'ERROR',
|
|
124
|
-
alertMessage: response.data.message,
|
|
125
|
-
alertContent: response.data.message,
|
|
126
|
-
alertHttpstatus: response.data.httpstatus,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
return dataset as ErrorResponse;
|
|
134
|
+
|
|
135
|
+
// -----------------------------------------------------------------------
|
|
136
|
+
// POST — native
|
|
137
|
+
// -----------------------------------------------------------------------
|
|
138
|
+
if (lowerMethod === 'post' && Platform.OS !== 'web') {
|
|
139
|
+
return axios
|
|
140
|
+
.post(url, params)
|
|
141
|
+
.then((response) => {
|
|
142
|
+
const payload = response.data as RawHttpPayload;
|
|
143
|
+
if (payload.httpstatus === 200) {
|
|
144
|
+
return { data: payload.data, httpstatus: payload.httpstatus };
|
|
131
145
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
dataset = {
|
|
135
|
-
httpstatus: 404,
|
|
146
|
+
return {
|
|
147
|
+
httpstatus: payload.httpstatus ?? 0,
|
|
136
148
|
data: {
|
|
137
149
|
title: 'ERROR',
|
|
138
150
|
subtitle: '',
|
|
139
151
|
alertdata: {
|
|
140
152
|
alertCaption: 'ERROR',
|
|
141
|
-
alertMessage:
|
|
142
|
-
alertContent:
|
|
143
|
-
alertHttpstatus:
|
|
153
|
+
alertMessage: payload.message,
|
|
154
|
+
alertContent: payload.message,
|
|
155
|
+
alertHttpstatus: payload.httpstatus,
|
|
144
156
|
},
|
|
145
157
|
},
|
|
146
158
|
};
|
|
147
|
-
|
|
148
|
-
|
|
159
|
+
})
|
|
160
|
+
.catch((error: Error) => makeErrorResponse(404, error.message)) as Promise<
|
|
161
|
+
ServiceResponse
|
|
162
|
+
>;
|
|
149
163
|
}
|
|
150
|
-
|
|
164
|
+
|
|
165
|
+
// -----------------------------------------------------------------------
|
|
166
|
+
// MULTIFORM — native
|
|
167
|
+
// -----------------------------------------------------------------------
|
|
168
|
+
if (lowerMethod === 'multiform' && Platform.OS !== 'web') {
|
|
151
169
|
console.log('JWT STRING', jwtString);
|
|
152
170
|
|
|
153
171
|
return axios({
|
|
154
|
-
url
|
|
172
|
+
url,
|
|
155
173
|
method: 'POST',
|
|
156
174
|
headers: {
|
|
157
175
|
'Content-Type': 'multipart/form-data',
|
|
158
|
-
// Authorization: `Bearer ${jwtString}`,
|
|
159
176
|
},
|
|
160
177
|
data: params,
|
|
161
178
|
})
|
|
162
|
-
.then(
|
|
179
|
+
.then((response) => {
|
|
163
180
|
if (response.status === 200) {
|
|
164
|
-
|
|
165
|
-
data: response.data,
|
|
166
|
-
httpstatus: response.status,
|
|
167
|
-
};
|
|
168
|
-
return dataset as NetworkResponse;
|
|
169
|
-
} else {
|
|
170
|
-
dataset = {
|
|
171
|
-
httpstatus: response.status,
|
|
172
|
-
data: {
|
|
173
|
-
title: 'ERROR',
|
|
174
|
-
subtitle: '',
|
|
175
|
-
alertdata: {
|
|
176
|
-
alertCaption: 'ERROR',
|
|
177
|
-
alertMessage: response.data.message,
|
|
178
|
-
alertContent: response.data.message,
|
|
179
|
-
alertHttpstatus: response.data.httpstatus,
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
return dataset as ErrorResponse;
|
|
181
|
+
return { data: response.data, httpstatus: response.status };
|
|
184
182
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
httpstatus: 404,
|
|
183
|
+
const payload = response.data as RawHttpPayload;
|
|
184
|
+
return {
|
|
185
|
+
httpstatus: response.status,
|
|
189
186
|
data: {
|
|
190
187
|
title: 'ERROR',
|
|
191
188
|
subtitle: '',
|
|
192
189
|
alertdata: {
|
|
193
190
|
alertCaption: 'ERROR',
|
|
194
|
-
alertMessage:
|
|
195
|
-
alertContent:
|
|
196
|
-
alertHttpstatus:
|
|
191
|
+
alertMessage: payload.message,
|
|
192
|
+
alertContent: payload.message,
|
|
193
|
+
alertHttpstatus: payload.httpstatus,
|
|
197
194
|
},
|
|
198
195
|
},
|
|
199
196
|
};
|
|
200
|
-
|
|
201
|
-
|
|
197
|
+
})
|
|
198
|
+
.catch((error: Error) => makeErrorResponse(404, error.message)) as Promise<
|
|
199
|
+
ServiceResponse
|
|
200
|
+
>;
|
|
202
201
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
alertContent: (response as any).message || '',
|
|
224
|
-
alertHttpstatus: response.httpstatus,
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
return dataset as ErrorResponse;
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
.catch(function (error: Error): ErrorResponse {
|
|
232
|
-
dataset = {
|
|
233
|
-
httpstatus: 404,
|
|
234
|
-
data: {
|
|
235
|
-
title: 'ERROR',
|
|
236
|
-
subtitle: '',
|
|
237
|
-
alertdata: {
|
|
238
|
-
alertCaption: 'ERROR',
|
|
239
|
-
alertMessage: error.message,
|
|
240
|
-
alertContent: error.message,
|
|
241
|
-
alertHttpstatus: 404,
|
|
242
|
-
},
|
|
202
|
+
|
|
203
|
+
// -----------------------------------------------------------------------
|
|
204
|
+
// POST — web (electron)
|
|
205
|
+
// -----------------------------------------------------------------------
|
|
206
|
+
if (lowerMethod === 'post' && Platform.OS === 'web') {
|
|
207
|
+
return networkServiceCall('post', url, params)
|
|
208
|
+
.then((response: ElectronResponse) => {
|
|
209
|
+
if (response.httpstatus === 200) {
|
|
210
|
+
return { data: response.data, httpstatus: response.httpstatus };
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
httpstatus: response.httpstatus,
|
|
214
|
+
data: {
|
|
215
|
+
title: 'ERROR',
|
|
216
|
+
subtitle: '',
|
|
217
|
+
alertdata: {
|
|
218
|
+
alertCaption: 'ERROR',
|
|
219
|
+
alertMessage: response.message,
|
|
220
|
+
alertContent: response.message,
|
|
221
|
+
alertHttpstatus: response.httpstatus,
|
|
243
222
|
},
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
});
|
|
247
|
-
} else {
|
|
248
|
-
// Fallback to regular axios if electronAPI is not available
|
|
249
|
-
return axios.post(url, params, {
|
|
250
|
-
timeout: timeout || 60000,
|
|
223
|
+
},
|
|
224
|
+
};
|
|
251
225
|
})
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
data: {
|
|
280
|
-
title: 'ERROR',
|
|
281
|
-
subtitle: '',
|
|
282
|
-
alertdata: {
|
|
283
|
-
alertCaption: 'ERROR',
|
|
284
|
-
alertMessage: error.message,
|
|
285
|
-
alertContent: error.message,
|
|
286
|
-
alertHttpstatus: 404,
|
|
287
|
-
},
|
|
226
|
+
.catch((error: Error) => makeErrorResponse(404, error.message)) as Promise<
|
|
227
|
+
ServiceResponse
|
|
228
|
+
>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// -----------------------------------------------------------------------
|
|
232
|
+
// MULTIFORM — web (electron)
|
|
233
|
+
// -----------------------------------------------------------------------
|
|
234
|
+
if (lowerMethod === 'multiform' && Platform.OS === 'web') {
|
|
235
|
+
const headers = {
|
|
236
|
+
'Content-Type': 'multipart/form-data',
|
|
237
|
+
};
|
|
238
|
+
return networkServiceCall('post', url, params, headers)
|
|
239
|
+
.then((response: ElectronResponse) => {
|
|
240
|
+
if (response.httpstatus === 200) {
|
|
241
|
+
return { data: response.data, httpstatus: response.httpstatus };
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
httpstatus: response.httpstatus,
|
|
245
|
+
data: {
|
|
246
|
+
title: 'ERROR',
|
|
247
|
+
subtitle: '',
|
|
248
|
+
alertdata: {
|
|
249
|
+
alertCaption: 'ERROR',
|
|
250
|
+
alertMessage: response.message,
|
|
251
|
+
alertContent: response.message,
|
|
252
|
+
alertHttpstatus: response.httpstatus,
|
|
288
253
|
},
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
})
|
|
257
|
+
.catch((error: Error) => makeErrorResponse(404, error.message)) as Promise<
|
|
258
|
+
ServiceResponse
|
|
259
|
+
>;
|
|
293
260
|
}
|
|
294
261
|
|
|
295
|
-
//
|
|
296
|
-
|
|
262
|
+
// Unknown method — original fell through and returned `undefined`
|
|
263
|
+
console.warn(`NetworkServiceCall: unsupported method "${method}"`);
|
|
264
|
+
return Promise.resolve(makeErrorResponse(400, `Unsupported method: ${method}`));
|
|
297
265
|
};
|
|
298
266
|
|
|
299
267
|
export default NetworkServiceCall;
|