@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jescon-technologies/react-native-ui-kit",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "A React Native module for Jescon Technologies that provides react-native-ui-kit",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,299 +1,267 @@
1
- import axios, { Method, AxiosResponse, AxiosError } from 'axios';
2
- import { isConnected, notifyMessage, ValueCheck } from '../CommonStyle/ComponentFunctions';
3
- import { Global } from '../../../../../src/Common/Global';
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
- // Type definitions
8
- export type HttpMethod = 'get' | 'post' | 'multiform';
7
+ // ---------------------------------------------------------------------------
8
+ // Types
9
+ // ---------------------------------------------------------------------------
9
10
 
10
- export interface NetworkResponse {
11
- data: any;
12
- httpstatus: number;
11
+ interface AlertData {
12
+ alertCaption: string;
13
+ alertMessage?: string;
14
+ alertContent?: string;
15
+ alertHttpstatus?: number;
13
16
  }
14
17
 
15
- export interface ErrorResponseData {
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
- export interface ErrorResponse {
24
+ interface ServiceResponse<T = unknown> {
27
25
  httpstatus: number;
28
- data: ErrorResponseData;
26
+ data: T | ErrorData;
29
27
  }
30
28
 
31
- // Type for electron API if available
32
- declare global {
33
- interface Window {
34
- electronAPI?: {
35
- networkCall: (method: string, url: string, params?: any) => Promise<NetworkResponse>;
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 NetworkServiceCallFunction = (
41
- method: HttpMethod | string,
41
+ type NetworkServiceMethod = 'get' | 'post' | 'multiform' | string;
42
+
43
+ export type NetworkServiceCallFn = <T = unknown>(
44
+ method: NetworkServiceMethod,
42
45
  url: string,
43
- params?: any,
46
+ params?: unknown,
44
47
  jwt?: string,
45
48
  timeout?: number
46
- ) => Promise<NetworkResponse | ErrorResponse>;
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
- const NetworkServiceCall: NetworkServiceCallFunction = (method, url, params, jwt, timeout) => {
49
- let jwtString = ValueCheck(Global.JWTToken) ? Global.JWTToken : jwt;
50
- let dataset: NetworkResponse | ErrorResponse = {};
74
+ // ---------------------------------------------------------------------------
75
+ // Service call
76
+ // ---------------------------------------------------------------------------
51
77
 
52
- if (method.toLowerCase() === 'get') {
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' as Method,
55
- url: 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(function (response: AxiosResponse): NetworkResponse | ErrorResponse {
63
- if (response.data.httpstatus === 200) {
64
- dataset = {
65
- data: response.data.data,
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
- .catch(function (error: AxiosError): ErrorResponse {
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: error.message,
95
- alertContent: error.message,
96
- alertHttpstatus: 404,
123
+ alertMessage: payload.message,
124
+ alertContent: payload.message,
125
+ alertHttpstatus: payload.httpstatus,
97
126
  },
98
127
  },
99
128
  };
100
- return dataset as ErrorResponse;
101
- });
129
+ })
130
+ .catch((error: Error) => makeErrorResponse(404, error.message)) as Promise<
131
+ ServiceResponse
132
+ >;
102
133
  }
103
- else if (method.toLowerCase() === 'post' && Platform.OS !== 'web') {
104
- return axios.post(url, params, {
105
- // headers: {
106
- // Authorization: `Bearer ${jwtString}`,
107
- // }
108
- })
109
- .then(function (response: AxiosResponse): NetworkResponse | ErrorResponse {
110
- if (response.data.httpstatus === 200) {
111
- dataset = {
112
- data: response.data.data,
113
- httpstatus: response.data.httpstatus,
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
- .catch(function (error: AxiosError): ErrorResponse {
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: error.message,
142
- alertContent: error.message,
143
- alertHttpstatus: 404,
153
+ alertMessage: payload.message,
154
+ alertContent: payload.message,
155
+ alertHttpstatus: payload.httpstatus,
144
156
  },
145
157
  },
146
158
  };
147
- return dataset as ErrorResponse;
148
- });
159
+ })
160
+ .catch((error: Error) => makeErrorResponse(404, error.message)) as Promise<
161
+ ServiceResponse
162
+ >;
149
163
  }
150
- else if (method.toLowerCase() === 'multiform' && Platform.OS !== 'web') {
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: 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(function (response: AxiosResponse): NetworkResponse | ErrorResponse {
179
+ .then((response) => {
163
180
  if (response.status === 200) {
164
- dataset = {
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
- .catch((error: AxiosError): ErrorResponse => {
187
- dataset = {
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: error.message,
195
- alertContent: error.message,
196
- alertHttpstatus: 404,
191
+ alertMessage: payload.message,
192
+ alertContent: payload.message,
193
+ alertHttpstatus: payload.httpstatus,
197
194
  },
198
195
  },
199
196
  };
200
- return dataset as ErrorResponse;
201
- });
197
+ })
198
+ .catch((error: Error) => makeErrorResponse(404, error.message)) as Promise<
199
+ ServiceResponse
200
+ >;
202
201
  }
203
- else if (method.toLowerCase() === 'post' && Platform.OS === 'web') {
204
- // Check if electronAPI is available
205
- if (typeof window !== 'undefined' && window.electronAPI) {
206
- return window.electronAPI.networkCall('post', url, params)
207
- .then(function (response: NetworkResponse): NetworkResponse | ErrorResponse {
208
- if (response.httpstatus === 200) {
209
- dataset = {
210
- data: response.data,
211
- httpstatus: response.httpstatus,
212
- };
213
- return dataset as NetworkResponse;
214
- } else {
215
- dataset = {
216
- httpstatus: response.httpstatus,
217
- data: {
218
- title: 'ERROR',
219
- subtitle: '',
220
- alertdata: {
221
- alertCaption: 'ERROR',
222
- alertMessage: (response as any).message || '',
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
- return dataset as ErrorResponse;
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
- .then(function (response: AxiosResponse): NetworkResponse | ErrorResponse {
253
- if (response.status === 200) {
254
- dataset = {
255
- data: response.data,
256
- httpstatus: response.status,
257
- };
258
- return dataset as NetworkResponse;
259
- } else {
260
- dataset = {
261
- httpstatus: response.status,
262
- data: {
263
- title: 'ERROR',
264
- subtitle: '',
265
- alertdata: {
266
- alertCaption: 'ERROR',
267
- alertMessage: response.data?.message || 'Request failed',
268
- alertContent: response.data?.message || 'Request failed',
269
- alertHttpstatus: response.status,
270
- },
271
- },
272
- };
273
- return dataset as ErrorResponse;
274
- }
275
- })
276
- .catch(function (error: AxiosError): ErrorResponse {
277
- dataset = {
278
- httpstatus: 404,
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
- return dataset as ErrorResponse;
291
- });
292
- }
254
+ },
255
+ };
256
+ })
257
+ .catch((error: Error) => makeErrorResponse(404, error.message)) as Promise<
258
+ ServiceResponse
259
+ >;
293
260
  }
294
261
 
295
- // Default return for unmatched conditions
296
- return Promise.reject(new Error('Invalid method or platform combination'));
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;