@edge-zuq/core 1.2.7 → 1.3.4
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 +2 -2
- package/lib/module/data/use-cases/remote-get-comment-list.js.map +1 -1
- package/lib/module/data/use-cases/remote-get-image-list.js.map +1 -1
- package/lib/module/infra/axios-http-client-adapter.js +45 -72
- package/lib/module/infra/axios-http-client-adapter.js.map +1 -1
- package/lib/module/infra/offline-mutation-queue.js.map +1 -1
- package/lib/module/infra/rnp-permission-manager-adapter.js.map +1 -1
- package/lib/module/presentation/components/atoms/UIIcon.js +40 -40
- package/lib/module/presentation/components/atoms/UIIcon.js.map +1 -1
- package/lib/module/presentation/components/atoms/UIProgress.js.map +1 -1
- package/lib/module/presentation/components/molecules/UIActionSheet.js.map +1 -1
- package/lib/module/presentation/components/molecules/UIButton.js +5 -5
- package/lib/module/presentation/components/molecules/UIButton.js.map +1 -1
- package/lib/module/presentation/components/molecules/UICurrencyInput.js.map +1 -1
- package/lib/module/presentation/components/molecules/UIDatetimeInput.js +1 -0
- package/lib/module/presentation/components/molecules/UIDatetimeInput.js.map +1 -1
- package/lib/module/presentation/components/molecules/UIImage.js.map +1 -1
- package/lib/module/presentation/components/molecules/UISkeleton.js +41 -9
- package/lib/module/presentation/components/molecules/UISkeleton.js.map +1 -1
- package/lib/module/presentation/components/molecules/UITextInput.js +6 -2
- package/lib/module/presentation/components/molecules/UITextInput.js.map +1 -1
- package/lib/module/presentation/components/molecules/UITextInputMask.js +6 -2
- package/lib/module/presentation/components/molecules/UITextInputMask.js.map +1 -1
- package/lib/module/presentation/components/organisms/UIFormButton.js.map +1 -1
- package/lib/module/presentation/components/organisms/UIFormCheckboxInput.js.map +1 -1
- package/lib/module/presentation/components/organisms/UIFormCurrencyInput.js.map +1 -1
- package/lib/module/presentation/components/organisms/UIFormDatetimeInput.js.map +1 -1
- package/lib/module/presentation/components/organisms/UIFormMultiselectInput.js.map +1 -1
- package/lib/module/presentation/components/organisms/UIFormSelectInput.js +8 -2
- package/lib/module/presentation/components/organisms/UIFormSelectInput.js.map +1 -1
- package/lib/module/presentation/components/organisms/UIFormTextInput.js.map +1 -1
- package/lib/module/presentation/components/organisms/UIMultipleSelectChip.js +129 -0
- package/lib/module/presentation/components/organisms/UIMultipleSelectChip.js.map +1 -0
- package/lib/module/presentation/components/organisms/UISelectChip.js +33 -2
- package/lib/module/presentation/components/organisms/UISelectChip.js.map +1 -1
- package/lib/module/presentation/components/organisms/UISignature.js +3 -2
- package/lib/module/presentation/components/organisms/UISignature.js.map +1 -1
- package/lib/module/presentation/components/organisms/UISlideButton.js.map +1 -1
- package/lib/module/presentation/components/organisms/index.js +1 -0
- package/lib/module/presentation/components/organisms/index.js.map +1 -1
- package/lib/module/presentation/components/permissions/request-permissions.js.map +1 -1
- package/lib/module/presentation/domain/offline/use-offline-mutation.js +1 -1
- package/lib/module/presentation/domain/offline/use-offline-mutation.js.map +1 -1
- package/lib/module/presentation/domain/offline/use-offline-query.js.map +1 -1
- package/lib/module/theme.js +22 -22
- package/lib/module/theme.js.map +1 -1
- package/lib/typescript/src/infra/axios-http-client-adapter.d.ts +1 -1
- package/lib/typescript/src/infra/axios-http-client-adapter.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/atoms/UIIcon.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/atoms/UIProgress.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/molecules/UIActionSheet.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/molecules/UIButton.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/molecules/UIDatetimeInput.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/molecules/UIImage.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/molecules/UISkeleton.d.ts +3 -1
- package/lib/typescript/src/presentation/components/molecules/UISkeleton.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/molecules/UITextInput.d.ts +1 -0
- package/lib/typescript/src/presentation/components/molecules/UITextInput.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/molecules/UITextInputMask.d.ts +1 -0
- package/lib/typescript/src/presentation/components/molecules/UITextInputMask.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/organisms/UIFormMultiselectInput.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/organisms/UIFormSelectInput.d.ts +4 -1
- package/lib/typescript/src/presentation/components/organisms/UIFormSelectInput.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/organisms/UIMultipleSelectChip.d.ts +17 -0
- package/lib/typescript/src/presentation/components/organisms/UIMultipleSelectChip.d.ts.map +1 -0
- package/lib/typescript/src/presentation/components/organisms/UISelectChip.d.ts +6 -2
- package/lib/typescript/src/presentation/components/organisms/UISelectChip.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/organisms/UISignature.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/organisms/UISlideButton.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/organisms/index.d.ts +1 -0
- package/lib/typescript/src/presentation/components/organisms/index.d.ts.map +1 -1
- package/lib/typescript/src/presentation/components/permissions/request-permissions.d.ts.map +1 -1
- package/package.json +71 -75
- package/src/data/use-cases/remote-get-comment-list.ts +1 -1
- package/src/data/use-cases/remote-get-image-list.ts +2 -2
- package/src/infra/axios-http-client-adapter.ts +46 -70
- package/src/infra/offline-mutation-queue.ts +4 -4
- package/src/infra/rnp-permission-manager-adapter.ts +4 -4
- package/src/presentation/components/atoms/UIIcon.tsx +75 -110
- package/src/presentation/components/atoms/UIProgress.tsx +2 -3
- package/src/presentation/components/molecules/UIActionSheet.tsx +9 -13
- package/src/presentation/components/molecules/UIButton.tsx +6 -7
- package/src/presentation/components/molecules/UICurrencyInput.tsx +2 -2
- package/src/presentation/components/molecules/UIDatetimeInput.tsx +1 -0
- package/src/presentation/components/molecules/UIImage.tsx +3 -5
- package/src/presentation/components/molecules/UISkeleton.tsx +19 -7
- package/src/presentation/components/molecules/UITextInput.tsx +8 -7
- package/src/presentation/components/molecules/UITextInputMask.tsx +8 -7
- package/src/presentation/components/organisms/UIFormButton.tsx +1 -1
- package/src/presentation/components/organisms/UIFormCheckboxInput.tsx +1 -1
- package/src/presentation/components/organisms/UIFormCurrencyInput.tsx +1 -1
- package/src/presentation/components/organisms/UIFormDatetimeInput.tsx +1 -1
- package/src/presentation/components/organisms/UIFormMultiselectInput.tsx +7 -9
- package/src/presentation/components/organisms/UIFormSelectInput.tsx +13 -6
- package/src/presentation/components/organisms/UIFormTextInput.tsx +1 -1
- package/src/presentation/components/organisms/UIMultipleSelectChip.tsx +139 -0
- package/src/presentation/components/organisms/UISelectChip.tsx +26 -3
- package/src/presentation/components/organisms/UISignature.tsx +10 -8
- package/src/presentation/components/organisms/UISlideButton.tsx +5 -7
- package/src/presentation/components/organisms/index.ts +1 -0
- package/src/presentation/components/permissions/request-permissions.tsx +5 -7
- package/src/presentation/domain/offline/use-offline-mutation.ts +2 -2
- package/src/presentation/domain/offline/use-offline-query.ts +1 -1
- package/src/theme.ts +22 -22
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
2
|
|
|
3
|
-
import axios, { AxiosError } from 'axios';
|
|
3
|
+
import axios, { AxiosError, isAxiosError } from 'axios';
|
|
4
4
|
import type { AxiosResponse } from 'axios';
|
|
5
5
|
|
|
6
6
|
import { HttpClient, type Storage } from '../data/protocols';
|
|
@@ -17,7 +17,6 @@ export class AxiosHttpClientAdapter implements HttpClient {
|
|
|
17
17
|
private readonly storage: Storage;
|
|
18
18
|
private readonly recorder: RecordRequest;
|
|
19
19
|
public readonly login?: UserAuthentication;
|
|
20
|
-
private isConnected: boolean | null = null;
|
|
21
20
|
public readonly logout?: UserLogout;
|
|
22
21
|
private hasConnection: boolean | null = null;
|
|
23
22
|
private isRefreshingAuth: Promise<any> | null = null;
|
|
@@ -31,16 +30,46 @@ export class AxiosHttpClientAdapter implements HttpClient {
|
|
|
31
30
|
this.client = axios.create({
|
|
32
31
|
baseURL: url,
|
|
33
32
|
headers: {
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
platform: Platform.OS,
|
|
34
|
+
accept: 'application/json',
|
|
36
35
|
'Content-Type': 'application/json',
|
|
37
36
|
},
|
|
38
37
|
});
|
|
39
|
-
addEventListener(
|
|
38
|
+
addEventListener(state => {
|
|
40
39
|
this.hasConnection = Boolean(
|
|
41
40
|
state.isConnected && state.isInternetReachable
|
|
42
41
|
);
|
|
43
42
|
});
|
|
43
|
+
this.client.interceptors.response.use(
|
|
44
|
+
async response => {
|
|
45
|
+
const { needsLogin, succeded } =
|
|
46
|
+
await this.refreshAuthIfNeeded(response);
|
|
47
|
+
if (!needsLogin) {
|
|
48
|
+
this.recorder.record({
|
|
49
|
+
url: response.config.url ?? 'NO_URL',
|
|
50
|
+
data: response.data ?? 'NO_DATA',
|
|
51
|
+
body: response.config?.data ?? 'NO_BODY',
|
|
52
|
+
headers: response.config?.headers,
|
|
53
|
+
query: response.config?.params,
|
|
54
|
+
});
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
if (succeded) return await this.client(response.config);
|
|
58
|
+
return response;
|
|
59
|
+
},
|
|
60
|
+
async error => {
|
|
61
|
+
if (!isAxiosError(error)) throw error;
|
|
62
|
+
if (!this.hasConnection || error.response?.status) throw error;
|
|
63
|
+
if (!error.config) throw error;
|
|
64
|
+
if (error.response) {
|
|
65
|
+
const { succeded } = await this.refreshAuthIfNeeded(error.response);
|
|
66
|
+
if (succeded) {
|
|
67
|
+
return await this.client(error.config);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
);
|
|
44
73
|
}
|
|
45
74
|
|
|
46
75
|
private throwIfNotConnectedOrExecuted(
|
|
@@ -93,14 +122,16 @@ export class AxiosHttpClientAdapter implements HttpClient {
|
|
|
93
122
|
|
|
94
123
|
private async refreshAuthIfNeeded(response: AxiosResponse<any>) {
|
|
95
124
|
const needsLogin = this.needsLogin(response);
|
|
125
|
+
let succeded = false;
|
|
96
126
|
if (needsLogin && this.login && this.logout) {
|
|
97
|
-
|
|
127
|
+
succeded = await this.refreshAuth();
|
|
98
128
|
if (!succeded) {
|
|
99
129
|
const [username] = this.storage.getItem<string[]>('__auth') ?? [];
|
|
100
130
|
if (username) await this.logout.logout({ username });
|
|
101
131
|
}
|
|
102
132
|
}
|
|
103
133
|
return {
|
|
134
|
+
succeded,
|
|
104
135
|
needsLogin,
|
|
105
136
|
};
|
|
106
137
|
}
|
|
@@ -128,69 +159,31 @@ export class AxiosHttpClientAdapter implements HttpClient {
|
|
|
128
159
|
private async execute<T>(
|
|
129
160
|
handler: () => Promise<AxiosResponse<T>>
|
|
130
161
|
): Promise<HttpClient.Response<T>> {
|
|
131
|
-
let response: AxiosResponse<T> | undefined;
|
|
132
|
-
let isRetry = false;
|
|
133
162
|
try {
|
|
134
|
-
response = await handler();
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
headers: response.headers,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
isRetry = true;
|
|
144
|
-
response = await handler();
|
|
163
|
+
const response = await handler();
|
|
164
|
+
return {
|
|
165
|
+
statusCode: response.status,
|
|
166
|
+
data: response.data,
|
|
167
|
+
headers: response.headers,
|
|
168
|
+
};
|
|
145
169
|
} catch (e) {
|
|
146
170
|
if (!(e instanceof AxiosError)) throw e;
|
|
147
171
|
if (!e.response?.status) throw e;
|
|
148
|
-
|
|
149
|
-
if (isRetry) throw error;
|
|
150
|
-
try {
|
|
151
|
-
if (response) await this.refreshAuthIfNeeded(response);
|
|
152
|
-
else if (e.response) await this.refreshAuthIfNeeded(e.response);
|
|
153
|
-
response = await handler();
|
|
154
|
-
} catch (e) {
|
|
155
|
-
if (!(e instanceof AxiosError)) throw e;
|
|
156
|
-
throw this.fromAxiosError<T>(e);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (this.isConnected && this.needsLogin(response)) {
|
|
160
|
-
const [username] = this.storage.getItem<string[]>('__auth') ?? [];
|
|
161
|
-
if (username) await this.logout?.logout({ username });
|
|
162
|
-
throw new Error('Needs login');
|
|
172
|
+
throw this.fromAxiosError<T>(e);
|
|
163
173
|
}
|
|
164
|
-
return {
|
|
165
|
-
statusCode: response.status,
|
|
166
|
-
data: response.data,
|
|
167
|
-
headers: response.headers,
|
|
168
|
-
};
|
|
169
174
|
}
|
|
170
175
|
|
|
171
176
|
async get<T = any>(
|
|
172
177
|
url: string,
|
|
173
178
|
config?: HttpClient.Config
|
|
174
179
|
): Promise<HttpClient.Response<T>> {
|
|
175
|
-
|
|
176
|
-
this.recorder.record({
|
|
177
|
-
url,
|
|
178
|
-
data: response.data,
|
|
179
|
-
headers: config?.headers,
|
|
180
|
-
query: config?.params,
|
|
181
|
-
});
|
|
182
|
-
return response;
|
|
180
|
+
return await this.execute<T>(() => this.client.get(url, config));
|
|
183
181
|
}
|
|
184
182
|
|
|
185
183
|
async delete(
|
|
186
184
|
url: string,
|
|
187
185
|
config?: HttpClient.Config
|
|
188
186
|
): Promise<HttpClient.Response<undefined>> {
|
|
189
|
-
this.recorder.record({
|
|
190
|
-
url,
|
|
191
|
-
headers: config?.headers,
|
|
192
|
-
query: config?.params,
|
|
193
|
-
});
|
|
194
187
|
this.throwIfNotConnectedOrExecuted(
|
|
195
188
|
HttpClient.Method.delete,
|
|
196
189
|
url,
|
|
@@ -205,12 +198,6 @@ export class AxiosHttpClientAdapter implements HttpClient {
|
|
|
205
198
|
body: any,
|
|
206
199
|
config?: HttpClient.Config
|
|
207
200
|
): Promise<HttpClient.Response<T>> {
|
|
208
|
-
this.recorder.record({
|
|
209
|
-
url,
|
|
210
|
-
body,
|
|
211
|
-
headers: config?.headers,
|
|
212
|
-
query: config?.params,
|
|
213
|
-
});
|
|
214
201
|
this.throwIfNotConnectedOrExecuted(
|
|
215
202
|
HttpClient.Method.post,
|
|
216
203
|
url,
|
|
@@ -225,12 +212,6 @@ export class AxiosHttpClientAdapter implements HttpClient {
|
|
|
225
212
|
body: any,
|
|
226
213
|
config?: HttpClient.Config
|
|
227
214
|
): Promise<HttpClient.Response<T>> {
|
|
228
|
-
this.recorder.record({
|
|
229
|
-
url,
|
|
230
|
-
body,
|
|
231
|
-
headers: config?.headers,
|
|
232
|
-
query: config?.params,
|
|
233
|
-
});
|
|
234
215
|
this.throwIfNotConnectedOrExecuted(
|
|
235
216
|
HttpClient.Method.patch,
|
|
236
217
|
url,
|
|
@@ -245,12 +226,6 @@ export class AxiosHttpClientAdapter implements HttpClient {
|
|
|
245
226
|
body: any,
|
|
246
227
|
config?: HttpClient.Config
|
|
247
228
|
): Promise<HttpClient.Response<T>> {
|
|
248
|
-
this.recorder.record({
|
|
249
|
-
url,
|
|
250
|
-
body,
|
|
251
|
-
headers: config?.headers,
|
|
252
|
-
query: config?.params,
|
|
253
|
-
});
|
|
254
229
|
this.throwIfNotConnectedOrExecuted(
|
|
255
230
|
HttpClient.Method.put,
|
|
256
231
|
url,
|
|
@@ -267,5 +242,6 @@ export namespace AxiosHttpClientAdapter {
|
|
|
267
242
|
recorder: RecordRequest;
|
|
268
243
|
login?: UserAuthentication;
|
|
269
244
|
logout?: UserLogout;
|
|
245
|
+
fallbackUrl?: string;
|
|
270
246
|
};
|
|
271
247
|
}
|
|
@@ -65,7 +65,7 @@ export class OfflineMutationQueue {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
private areDependenciesExecuted(offlineMutation: OfflineMutation) {
|
|
68
|
-
return offlineMutation.dependencies.every(
|
|
68
|
+
return offlineMutation.dependencies.every(key => {
|
|
69
69
|
let currentKey;
|
|
70
70
|
if (key instanceof IsomorphicIdManager.IsomorphicId) {
|
|
71
71
|
const isomorphicId = this.isomorphicIdManager?.get(key.getOfflineId());
|
|
@@ -139,7 +139,7 @@ export class OfflineMutationQueue {
|
|
|
139
139
|
|
|
140
140
|
private async executeRequest(key: string, offlineMutation: OfflineMutation) {
|
|
141
141
|
this.updateStatus(key, OfflineMutationStatus.EXECUTING);
|
|
142
|
-
const dependencies = offlineMutation.dependencies.map(
|
|
142
|
+
const dependencies = offlineMutation.dependencies.map(dependency =>
|
|
143
143
|
dependency instanceof IsomorphicIdManager.IsomorphicId
|
|
144
144
|
? this.queue.get(String(dependency.getOfflineId()))
|
|
145
145
|
: this.queue.get(dependency)
|
|
@@ -184,7 +184,7 @@ export class OfflineMutationQueue {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
private assertOfflineMutation(key: string, offlineMutation: OfflineMutation) {
|
|
187
|
-
const isValid = offlineMutation.dependencies.every(
|
|
187
|
+
const isValid = offlineMutation.dependencies.every(dependencyKey => {
|
|
188
188
|
let dependency: OfflineMutation | undefined;
|
|
189
189
|
if (dependencyKey instanceof IsomorphicIdManager.IsomorphicId) {
|
|
190
190
|
const isomorphicId = this.isomorphicIdManager?.get(
|
|
@@ -201,7 +201,7 @@ export class OfflineMutationQueue {
|
|
|
201
201
|
}
|
|
202
202
|
if (dependency) {
|
|
203
203
|
const existsDependencyLoop = dependency.dependencies.some(
|
|
204
|
-
|
|
204
|
+
innerKey => innerKey === key
|
|
205
205
|
);
|
|
206
206
|
return !existsDependencyLoop;
|
|
207
207
|
} else {
|
|
@@ -58,7 +58,7 @@ export class RNPPermissionManagerAdapter implements PermissionManager {
|
|
|
58
58
|
permissions: PermissionManager.Permission[]
|
|
59
59
|
): Promise<PermissionManager.Result[]> {
|
|
60
60
|
return await Promise.all(
|
|
61
|
-
permissions.map(
|
|
61
|
+
permissions.map(permission => this.get(permission))
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -99,7 +99,7 @@ export class RNPPermissionManagerAdapter implements PermissionManager {
|
|
|
99
99
|
}>
|
|
100
100
|
): Promise<PermissionManager.Result[]> {
|
|
101
101
|
return await Promise.all(
|
|
102
|
-
data.map(
|
|
102
|
+
data.map(item => this.request(item.permission, item.options))
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -140,8 +140,8 @@ export class RNPPermissionManagerAdapter implements PermissionManager {
|
|
|
140
140
|
permissions: PermissionManager.Permission[]
|
|
141
141
|
): Promise<boolean> {
|
|
142
142
|
const result = await Promise.all(
|
|
143
|
-
permissions.map(async
|
|
143
|
+
permissions.map(async permission => this.has(permission))
|
|
144
144
|
);
|
|
145
|
-
return result.every(
|
|
145
|
+
return result.every(item => Boolean(item));
|
|
146
146
|
}
|
|
147
147
|
}
|