shelflife-react-hooks 1.0.6 → 1.0.7
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/context/api/authApi.ts +1 -1
- package/src/context/api/productApi.ts +11 -0
- package/src/context/api/runningLowApi.ts +11 -0
- package/src/context/api/storageApi.ts +9 -0
- package/src/context/api/storageItemApi.ts +11 -0
- package/src/context/api/storageMemberApi.ts +6 -0
- package/src/context/api/userApi.ts +7 -1
- package/src/type/auth.ts +1 -0
- package/src/type/item.ts +13 -0
- package/src/type/member.ts +7 -0
- package/src/type/product.ts +7 -26
- package/src/type/runninglow.ts +9 -19
- package/src/type/storage.ts +4 -67
- package/src/type/user.ts +5 -17
package/package.json
CHANGED
|
@@ -108,7 +108,7 @@ export const changePasswordRequest = async (
|
|
|
108
108
|
if (!response.ok) {
|
|
109
109
|
const error = await readJson<ChangePasswordErrorResponse>(response);
|
|
110
110
|
|
|
111
|
-
if (error?.oldPassword || error?.newPasswordRepeat)
|
|
111
|
+
if (error?.oldPassword || error?.newPassword || error?.newPasswordRepeat)
|
|
112
112
|
throw error;
|
|
113
113
|
|
|
114
114
|
throw new Error('Change password failed');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Product } from '../../type/models.js';
|
|
2
|
+
import type { ProductCreateError } from '../../type/product.js';
|
|
2
3
|
import type { CreateProductRequest, UpdateProductRequest } from '../../type/requests.js';
|
|
3
4
|
import { buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson } from '../http.js';
|
|
4
5
|
import { runWithRequestState, type RequestStateHandlers } from './requestState.js';
|
|
@@ -107,6 +108,11 @@ export const createProductRequest = async (
|
|
|
107
108
|
});
|
|
108
109
|
|
|
109
110
|
if (!response.ok) {
|
|
111
|
+
const err = await readJson<ProductCreateError>(response);
|
|
112
|
+
|
|
113
|
+
if (err?.name || err?.barcode || err?.category || err?.expirationDaysDelta)
|
|
114
|
+
throw err;
|
|
115
|
+
|
|
110
116
|
throw new Error('Failed to create product');
|
|
111
117
|
}
|
|
112
118
|
|
|
@@ -136,6 +142,11 @@ export const updateProductRequest = async (
|
|
|
136
142
|
});
|
|
137
143
|
|
|
138
144
|
if (!response.ok) {
|
|
145
|
+
const err = await readJson<ProductCreateError>(response);
|
|
146
|
+
|
|
147
|
+
if (err?.name || err?.barcode || err?.category || err?.expirationDaysDelta)
|
|
148
|
+
throw err;
|
|
149
|
+
|
|
139
150
|
throw new Error('Failed to update product');
|
|
140
151
|
}
|
|
141
152
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RunningLowSetting } from '../../type/models.js';
|
|
2
2
|
import type { CreateSettingRequest, EditSettingRequest } from '../../type/requests.js';
|
|
3
|
+
import type { CreateRunningLowSettingError, EditRunningLowSettingError } from '../../type/runninglow.js';
|
|
3
4
|
import { buildAuthHeaders, normalizeBaseUrl, readJson } from '../http.js';
|
|
4
5
|
import { runWithRequestState, type RequestStateHandlers } from './requestState.js';
|
|
5
6
|
|
|
@@ -64,6 +65,11 @@ export const createSettingRequest = async (
|
|
|
64
65
|
);
|
|
65
66
|
|
|
66
67
|
if (!response.ok) {
|
|
68
|
+
const err = await readJson<CreateRunningLowSettingError>(response);
|
|
69
|
+
|
|
70
|
+
if (err?.productId || err?.runningLow)
|
|
71
|
+
throw err;
|
|
72
|
+
|
|
67
73
|
throw new Error('Failed to create running low setting');
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -96,6 +102,11 @@ export const editSettingRequest = async (
|
|
|
96
102
|
);
|
|
97
103
|
|
|
98
104
|
if (!response.ok) {
|
|
105
|
+
const err = await readJson<EditRunningLowSettingError>(response);
|
|
106
|
+
|
|
107
|
+
if (err?.runningLow)
|
|
108
|
+
throw err;
|
|
109
|
+
|
|
99
110
|
throw new Error('Failed to edit running low setting');
|
|
100
111
|
}
|
|
101
112
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Storage } from '../../type/models.js';
|
|
2
2
|
import type { ChangeStorageNameRequest, CreateStorageRequest } from '../../type/requests.js';
|
|
3
|
+
import type { CreateStorageError } from '../../type/storage.js';
|
|
3
4
|
import { buildAuthHeaders, normalizeBaseUrl, readJson } from '../http.js';
|
|
4
5
|
import { runWithRequestState, type RequestStateHandlers } from './requestState.js';
|
|
5
6
|
|
|
@@ -86,6 +87,10 @@ export const createStorageRequest = async (
|
|
|
86
87
|
});
|
|
87
88
|
|
|
88
89
|
if (!response.ok) {
|
|
90
|
+
const payload = await readJson<CreateStorageError>(response);
|
|
91
|
+
if (payload?.name)
|
|
92
|
+
throw payload;
|
|
93
|
+
|
|
89
94
|
throw new Error('Failed to create storage');
|
|
90
95
|
}
|
|
91
96
|
|
|
@@ -115,6 +120,10 @@ export const changeStorageNameRequest = async (
|
|
|
115
120
|
});
|
|
116
121
|
|
|
117
122
|
if (!response.ok) {
|
|
123
|
+
const payload = await readJson<CreateStorageError>(response);
|
|
124
|
+
if (payload?.name)
|
|
125
|
+
throw payload;
|
|
126
|
+
|
|
118
127
|
throw new Error('Failed to update storage');
|
|
119
128
|
}
|
|
120
129
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AddItemError, EditItemError } from '../../type/item.js';
|
|
1
2
|
import type { RunningLowNotification, StorageItem } from '../../type/models.js';
|
|
2
3
|
import type { AddItemRequest, EditItemRequest } from '../../type/requests.js';
|
|
3
4
|
import { buildAuthHeaders, normalizeBaseUrl, readJson } from '../http.js';
|
|
@@ -61,6 +62,11 @@ export const addItemRequest = async (
|
|
|
61
62
|
});
|
|
62
63
|
|
|
63
64
|
if (!response.ok) {
|
|
65
|
+
const err = await readJson<AddItemError>(response);
|
|
66
|
+
|
|
67
|
+
if (err?.productId || err?.expiresAt)
|
|
68
|
+
throw err;
|
|
69
|
+
|
|
64
70
|
throw new Error('Failed to add storage item');
|
|
65
71
|
}
|
|
66
72
|
|
|
@@ -90,6 +96,11 @@ export const editItemRequest = async (
|
|
|
90
96
|
});
|
|
91
97
|
|
|
92
98
|
if (!response.ok) {
|
|
99
|
+
const err = await readJson<EditItemError>(response);
|
|
100
|
+
|
|
101
|
+
if (err?.expiresAt)
|
|
102
|
+
throw err;
|
|
103
|
+
|
|
93
104
|
throw new Error('Failed to edit storage item');
|
|
94
105
|
}
|
|
95
106
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InviteMemberError } from '../../type/member.js';
|
|
1
2
|
import type { StorageMember } from '../../type/models.js';
|
|
2
3
|
import type { InviteMemberRequest } from '../../type/requests.js';
|
|
3
4
|
import { buildAuthHeaders, normalizeBaseUrl, readJson } from '../http.js';
|
|
@@ -47,6 +48,11 @@ export const inviteMemberRequest = async (
|
|
|
47
48
|
});
|
|
48
49
|
|
|
49
50
|
if (!response.ok) {
|
|
51
|
+
const err = await readJson<InviteMemberError>(response);
|
|
52
|
+
|
|
53
|
+
if(err?.email)
|
|
54
|
+
throw err;
|
|
55
|
+
|
|
50
56
|
throw new Error('Failed to invite member');
|
|
51
57
|
}
|
|
52
58
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { User } from '../../type/models.js';
|
|
2
2
|
import type { ChangeUserDataRequest } from '../../type/requests.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { UpdateUserError } from '../../type/user.js';
|
|
4
|
+
import { buildAuthHeaders, normalizeBaseUrl, readJson } from '../http.js';
|
|
4
5
|
import { runWithRequestState, type RequestStateHandlers } from './requestState.js';
|
|
5
6
|
|
|
6
7
|
type UserApiConfig = RequestStateHandlers & {
|
|
@@ -87,6 +88,11 @@ export const updateUserRequest = async (
|
|
|
87
88
|
});
|
|
88
89
|
|
|
89
90
|
if (!response.ok) {
|
|
91
|
+
const update = await readJson<UpdateUserError>(response);
|
|
92
|
+
|
|
93
|
+
if (update?.email || update?.username)
|
|
94
|
+
throw update;
|
|
95
|
+
|
|
90
96
|
throw new Error('Failed to update user');
|
|
91
97
|
}
|
|
92
98
|
|
package/src/type/auth.ts
CHANGED
package/src/type/item.ts
ADDED
package/src/type/product.ts
CHANGED
|
@@ -1,29 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type ProductIconResponse = ImageResponse;
|
|
9
|
-
|
|
10
|
-
type ProductUploadIconError = ErrorResponse | { pfp: string };
|
|
11
|
-
|
|
12
|
-
type ProductUploadIconResponse = EmptyResponse | ProductUploadIconError;
|
|
13
|
-
|
|
14
|
-
type ProductCreateResponse = Product | FieldErrorMap | EmptyResponse;
|
|
15
|
-
|
|
16
|
-
type ProductUpdateResponse = Product | FieldErrorMap | EmptyResponse;
|
|
17
|
-
|
|
18
|
-
type ProductDeleteResponse = EmptyResponse;
|
|
1
|
+
type ProductCreateError = {
|
|
2
|
+
name?: string;
|
|
3
|
+
category?: string;
|
|
4
|
+
barcode?: string;
|
|
5
|
+
expirationDaysDelta?: number;
|
|
6
|
+
}
|
|
19
7
|
|
|
20
8
|
export type {
|
|
21
|
-
|
|
22
|
-
ProductResponse,
|
|
23
|
-
ProductIconResponse,
|
|
24
|
-
ProductUploadIconError,
|
|
25
|
-
ProductUploadIconResponse,
|
|
26
|
-
ProductCreateResponse,
|
|
27
|
-
ProductUpdateResponse,
|
|
28
|
-
ProductDeleteResponse
|
|
9
|
+
ProductCreateError
|
|
29
10
|
};
|
package/src/type/runninglow.ts
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type CreateRunningLowSettingError = {
|
|
2
|
+
productId?: string;
|
|
3
|
+
runningLow?: string;
|
|
4
|
+
}
|
|
3
5
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type RunningLowCreateResponse = RunningLowSetting | FieldErrorMap | EmptyResponse;
|
|
9
|
-
|
|
10
|
-
type RunningLowEditResponse = RunningLowSetting | FieldErrorMap | EmptyResponse;
|
|
11
|
-
|
|
12
|
-
type RunningLowDeleteResponse = EmptyResponse;
|
|
13
|
-
|
|
14
|
-
type RunningLowNotificationListResponse = RunningLowNotification[];
|
|
6
|
+
type EditRunningLowSettingError = {
|
|
7
|
+
runningLow?: string;
|
|
8
|
+
}
|
|
15
9
|
|
|
16
10
|
export type {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
RunningLowCreateResponse,
|
|
20
|
-
RunningLowEditResponse,
|
|
21
|
-
RunningLowDeleteResponse,
|
|
22
|
-
RunningLowNotificationListResponse
|
|
11
|
+
CreateRunningLowSettingError,
|
|
12
|
+
EditRunningLowSettingError
|
|
23
13
|
};
|
package/src/type/storage.ts
CHANGED
|
@@ -1,70 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Storage,
|
|
5
|
-
StorageItem,
|
|
6
|
-
StorageMember
|
|
7
|
-
} from './models.js';
|
|
8
|
-
|
|
9
|
-
type StorageListResponse = Storage[];
|
|
10
|
-
|
|
11
|
-
type StorageResponse = Storage | EmptyResponse;
|
|
12
|
-
|
|
13
|
-
type StorageCreateResponse = Storage | FieldErrorMap | EmptyResponse;
|
|
14
|
-
|
|
15
|
-
type StorageChangeNameResponse = Storage | FieldErrorMap | EmptyResponse;
|
|
16
|
-
|
|
17
|
-
type StorageDeleteResponse = EmptyResponse;
|
|
18
|
-
|
|
19
|
-
type StorageItemListResponse = StorageItem[];
|
|
20
|
-
|
|
21
|
-
type StorageItemResponse = StorageItem | EmptyResponse;
|
|
22
|
-
|
|
23
|
-
type StorageItemAddResponse = StorageItem | FieldErrorMap | EmptyResponse;
|
|
24
|
-
|
|
25
|
-
type StorageItemEditResponse = StorageItem | FieldErrorMap | EmptyResponse;
|
|
26
|
-
|
|
27
|
-
type StorageItemDeleteResponse = EmptyResponse;
|
|
28
|
-
|
|
29
|
-
type StorageExpiredItemsResponse = StorageItem[];
|
|
30
|
-
|
|
31
|
-
type StorageAboutToExpireItemsResponse = StorageItem[];
|
|
32
|
-
|
|
33
|
-
type StorageRunningLowResponse = RunningLowNotification[];
|
|
34
|
-
|
|
35
|
-
type StorageMemberListResponse = StorageMember[];
|
|
36
|
-
|
|
37
|
-
type StorageMemberResponse = StorageMember | EmptyResponse;
|
|
38
|
-
|
|
39
|
-
type StorageMemberInviteResponse = StorageMember | FieldErrorMap | EmptyResponse;
|
|
40
|
-
|
|
41
|
-
type StorageMemberDeleteResponse = EmptyResponse | FieldErrorMap;
|
|
42
|
-
|
|
43
|
-
type InviteListResponse = StorageMember[];
|
|
44
|
-
|
|
45
|
-
type InviteAcceptResponse = EmptyResponse;
|
|
46
|
-
|
|
47
|
-
type InviteDeclineResponse = EmptyResponse;
|
|
1
|
+
type CreateStorageError = {
|
|
2
|
+
name?: string;
|
|
3
|
+
}
|
|
48
4
|
|
|
49
5
|
export type {
|
|
50
|
-
|
|
51
|
-
StorageResponse,
|
|
52
|
-
StorageCreateResponse,
|
|
53
|
-
StorageChangeNameResponse,
|
|
54
|
-
StorageDeleteResponse,
|
|
55
|
-
StorageItemListResponse,
|
|
56
|
-
StorageItemResponse,
|
|
57
|
-
StorageItemAddResponse,
|
|
58
|
-
StorageItemEditResponse,
|
|
59
|
-
StorageItemDeleteResponse,
|
|
60
|
-
StorageExpiredItemsResponse,
|
|
61
|
-
StorageAboutToExpireItemsResponse,
|
|
62
|
-
StorageRunningLowResponse,
|
|
63
|
-
StorageMemberListResponse,
|
|
64
|
-
StorageMemberResponse,
|
|
65
|
-
StorageMemberInviteResponse,
|
|
66
|
-
StorageMemberDeleteResponse,
|
|
67
|
-
InviteListResponse,
|
|
68
|
-
InviteAcceptResponse,
|
|
69
|
-
InviteDeclineResponse
|
|
6
|
+
CreateStorageError
|
|
70
7
|
};
|
package/src/type/user.ts
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
import type { EmptyResponse, FieldErrorMap, ImageResponse } from './base.js';
|
|
2
2
|
import type { User } from './models.js';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type UserPfpResponse = ImageResponse;
|
|
9
|
-
|
|
10
|
-
type UserUploadPfpResponse = EmptyResponse | FieldErrorMap | string;
|
|
11
|
-
|
|
12
|
-
type UserDeleteResponse = EmptyResponse;
|
|
13
|
-
|
|
14
|
-
type UserUpdateResponse = User | FieldErrorMap | EmptyResponse;
|
|
4
|
+
type UpdateUserError = {
|
|
5
|
+
username?: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
}
|
|
15
8
|
|
|
16
9
|
export type {
|
|
17
|
-
|
|
18
|
-
UserResponse,
|
|
19
|
-
UserPfpResponse,
|
|
20
|
-
UserUploadPfpResponse,
|
|
21
|
-
UserDeleteResponse,
|
|
22
|
-
UserUpdateResponse
|
|
10
|
+
UpdateUserError
|
|
23
11
|
};
|