shelflife-react-hooks 1.0.6 → 1.0.8

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.
@@ -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 { buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson } from '../http.js';
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
@@ -47,6 +47,7 @@ type LogoutResponse = EmptyResponse | LogoutErrorResponse;
47
47
 
48
48
  type ChangePasswordErrorResponse = {
49
49
  oldPassword?: string;
50
+ newPassword?: string;
50
51
  newPasswordRepeat?: string;
51
52
  };
52
53
 
@@ -0,0 +1,13 @@
1
+ type AddItemError = {
2
+ productId?: string;
3
+ expiresAt?: string;
4
+ }
5
+
6
+ type EditItemError = {
7
+ expiresAt?: string;
8
+ }
9
+
10
+ export type {
11
+ AddItemError,
12
+ EditItemError
13
+ }
@@ -0,0 +1,7 @@
1
+ type InviteMemberError = {
2
+ email?: string;
3
+ }
4
+
5
+ export type {
6
+ InviteMemberError
7
+ }
@@ -1,29 +1,10 @@
1
- import type { EmptyResponse, ErrorResponse, FieldErrorMap, ImageResponse } from './base.js';
2
- import type { Product } from './models.js';
3
-
4
- type ProductListResponse = Product[];
5
-
6
- type ProductResponse = Product | EmptyResponse;
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
- ProductListResponse,
22
- ProductResponse,
23
- ProductIconResponse,
24
- ProductUploadIconError,
25
- ProductUploadIconResponse,
26
- ProductCreateResponse,
27
- ProductUpdateResponse,
28
- ProductDeleteResponse
9
+ ProductCreateError
29
10
  };
@@ -1,23 +1,13 @@
1
- import type { EmptyResponse, FieldErrorMap } from './base.js';
2
- import type { RunningLowNotification, RunningLowSetting } from './models.js';
1
+ type CreateRunningLowSettingError = {
2
+ productId?: string;
3
+ runningLow?: string;
4
+ }
3
5
 
4
- type RunningLowSettingListResponse = RunningLowSetting[];
5
-
6
- type RunningLowSettingResponse = RunningLowSetting | EmptyResponse;
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
- RunningLowSettingListResponse,
18
- RunningLowSettingResponse,
19
- RunningLowCreateResponse,
20
- RunningLowEditResponse,
21
- RunningLowDeleteResponse,
22
- RunningLowNotificationListResponse
11
+ CreateRunningLowSettingError,
12
+ EditRunningLowSettingError
23
13
  };
@@ -1,70 +1,7 @@
1
- import type { EmptyResponse, FieldErrorMap } from './base.js';
2
- import type {
3
- RunningLowNotification,
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
- StorageListResponse,
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 UserListResponse = User[];
5
-
6
- type UserResponse = User | EmptyResponse;
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
- UserListResponse,
18
- UserResponse,
19
- UserPfpResponse,
20
- UserUploadPfpResponse,
21
- UserDeleteResponse,
22
- UserUpdateResponse
10
+ UpdateUserError
23
11
  };