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.
package/dist/index.d.cts CHANGED
@@ -91,6 +91,7 @@ type LogoutErrorResponse = {
91
91
  type LogoutResponse = EmptyResponse | LogoutErrorResponse;
92
92
  type ChangePasswordErrorResponse = {
93
93
  oldPassword?: string;
94
+ newPassword?: string;
94
95
  newPasswordRepeat?: string;
95
96
  };
96
97
  type ChangePasswordResponse = EmptyResponse | ChangePasswordErrorResponse;
@@ -101,23 +102,20 @@ type TokenStorage = {
101
102
  removeItem: (key: string) => Promise<void> | void;
102
103
  };
103
104
 
104
- type ProductListResponse = Product[];
105
- type ProductResponse = Product | EmptyResponse;
106
- type ProductIconResponse = ImageResponse;
107
- type ProductUploadIconError = ErrorResponse | {
108
- pfp: string;
109
- };
110
- type ProductUploadIconResponse = EmptyResponse | ProductUploadIconError;
111
- type ProductCreateResponse = Product | FieldErrorMap | EmptyResponse;
112
- type ProductUpdateResponse = Product | FieldErrorMap | EmptyResponse;
113
- type ProductDeleteResponse = EmptyResponse;
105
+ type ProductCreateError = {
106
+ name?: string;
107
+ category?: string;
108
+ barcode?: string;
109
+ expirationDaysDelta?: number;
110
+ };
114
111
 
115
- type RunningLowSettingListResponse = RunningLowSetting[];
116
- type RunningLowSettingResponse = RunningLowSetting | EmptyResponse;
117
- type RunningLowCreateResponse = RunningLowSetting | FieldErrorMap | EmptyResponse;
118
- type RunningLowEditResponse = RunningLowSetting | FieldErrorMap | EmptyResponse;
119
- type RunningLowDeleteResponse = EmptyResponse;
120
- type RunningLowNotificationListResponse = RunningLowNotification[];
112
+ type CreateRunningLowSettingError = {
113
+ productId?: string;
114
+ runningLow?: string;
115
+ };
116
+ type EditRunningLowSettingError = {
117
+ runningLow?: string;
118
+ };
121
119
 
122
120
  type CreateProductRequest = {
123
121
  name: string;
@@ -160,33 +158,14 @@ type ChangeUserDataRequest = {
160
158
  isAdmin?: boolean;
161
159
  };
162
160
 
163
- type StorageListResponse = Storage[];
164
- type StorageResponse = Storage | EmptyResponse;
165
- type StorageCreateResponse = Storage | FieldErrorMap | EmptyResponse;
166
- type StorageChangeNameResponse = Storage | FieldErrorMap | EmptyResponse;
167
- type StorageDeleteResponse = EmptyResponse;
168
- type StorageItemListResponse = StorageItem[];
169
- type StorageItemResponse = StorageItem | EmptyResponse;
170
- type StorageItemAddResponse = StorageItem | FieldErrorMap | EmptyResponse;
171
- type StorageItemEditResponse = StorageItem | FieldErrorMap | EmptyResponse;
172
- type StorageItemDeleteResponse = EmptyResponse;
173
- type StorageExpiredItemsResponse = StorageItem[];
174
- type StorageAboutToExpireItemsResponse = StorageItem[];
175
- type StorageRunningLowResponse = RunningLowNotification[];
176
- type StorageMemberListResponse = StorageMember[];
177
- type StorageMemberResponse = StorageMember | EmptyResponse;
178
- type StorageMemberInviteResponse = StorageMember | FieldErrorMap | EmptyResponse;
179
- type StorageMemberDeleteResponse = EmptyResponse | FieldErrorMap;
180
- type InviteListResponse = StorageMember[];
181
- type InviteAcceptResponse = EmptyResponse;
182
- type InviteDeclineResponse = EmptyResponse;
161
+ type CreateStorageError = {
162
+ name?: string;
163
+ };
183
164
 
184
- type UserListResponse = User[];
185
- type UserResponse = User | EmptyResponse;
186
- type UserPfpResponse = ImageResponse;
187
- type UserUploadPfpResponse = EmptyResponse | FieldErrorMap | string;
188
- type UserDeleteResponse = EmptyResponse;
189
- type UserUpdateResponse = User | FieldErrorMap | EmptyResponse;
165
+ type UpdateUserError = {
166
+ username?: string;
167
+ email?: string;
168
+ };
190
169
 
191
170
  type AuthContextValue = {
192
171
  token: string | null;
@@ -354,4 +333,4 @@ type UserProviderProps = {
354
333
  declare const UserProvider: ({ baseUrl, children }: UserProviderProps) => react_jsx_runtime.JSX.Element;
355
334
  declare const useUsers: () => UserContextValue;
356
335
 
357
- export { type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateSettingRequest, type CreateStorageRequest, type EditItemRequest, type EditSettingRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteAcceptResponse, type InviteDeclineResponse, type InviteListResponse, type InviteMemberRequest, InviteProvider, type LoginErrorResponse, type LoginRequest, type LoginResponse, type LoginSuccessResponse, type LogoutErrorResponse, type LogoutResponse, type Product, type ProductCreateResponse, type ProductDeleteResponse, type ProductIconResponse, type ProductListResponse, ProductProvider, type ProductResponse, type ProductUpdateResponse, type ProductUploadIconError, type ProductUploadIconResponse, type RunningLowCreateResponse, type RunningLowDeleteResponse, type RunningLowEditResponse, type RunningLowNotification, type RunningLowNotificationListResponse, RunningLowProvider, type RunningLowSetting, type RunningLowSettingListResponse, type RunningLowSettingResponse, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageAboutToExpireItemsResponse, type StorageChangeNameResponse, type StorageCreateResponse, type StorageDeleteResponse, type StorageExpiredItemsResponse, type StorageItem, type StorageItemAddResponse, type StorageItemDeleteResponse, type StorageItemEditResponse, type StorageItemListResponse, StorageItemProvider, type StorageItemResponse, type StorageListResponse, type StorageMember, type StorageMemberDeleteResponse, type StorageMemberInviteResponse, type StorageMemberListResponse, StorageMemberProvider, type StorageMemberResponse, StorageProvider, type StorageResponse, type StorageRunningLowResponse, type TokenStorage, type UpdateProductRequest, type User, type UserDeleteResponse, type UserListResponse, type UserPfpResponse, UserProvider, type UserResponse, type UserUpdateResponse, type UserUploadPfpResponse, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useStorageItems, useStorageMembers, useStorages, useUsers };
336
+ export { type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateRunningLowSettingError, type CreateSettingRequest, type CreateStorageError, type CreateStorageRequest, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteMemberRequest, InviteProvider, type LoginErrorResponse, type LoginRequest, type LoginResponse, type LoginSuccessResponse, type LogoutErrorResponse, type LogoutResponse, type Product, type ProductCreateError, ProductProvider, type RunningLowNotification, RunningLowProvider, type RunningLowSetting, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useStorageItems, useStorageMembers, useStorages, useUsers };
package/dist/index.d.ts CHANGED
@@ -91,6 +91,7 @@ type LogoutErrorResponse = {
91
91
  type LogoutResponse = EmptyResponse | LogoutErrorResponse;
92
92
  type ChangePasswordErrorResponse = {
93
93
  oldPassword?: string;
94
+ newPassword?: string;
94
95
  newPasswordRepeat?: string;
95
96
  };
96
97
  type ChangePasswordResponse = EmptyResponse | ChangePasswordErrorResponse;
@@ -101,23 +102,20 @@ type TokenStorage = {
101
102
  removeItem: (key: string) => Promise<void> | void;
102
103
  };
103
104
 
104
- type ProductListResponse = Product[];
105
- type ProductResponse = Product | EmptyResponse;
106
- type ProductIconResponse = ImageResponse;
107
- type ProductUploadIconError = ErrorResponse | {
108
- pfp: string;
109
- };
110
- type ProductUploadIconResponse = EmptyResponse | ProductUploadIconError;
111
- type ProductCreateResponse = Product | FieldErrorMap | EmptyResponse;
112
- type ProductUpdateResponse = Product | FieldErrorMap | EmptyResponse;
113
- type ProductDeleteResponse = EmptyResponse;
105
+ type ProductCreateError = {
106
+ name?: string;
107
+ category?: string;
108
+ barcode?: string;
109
+ expirationDaysDelta?: number;
110
+ };
114
111
 
115
- type RunningLowSettingListResponse = RunningLowSetting[];
116
- type RunningLowSettingResponse = RunningLowSetting | EmptyResponse;
117
- type RunningLowCreateResponse = RunningLowSetting | FieldErrorMap | EmptyResponse;
118
- type RunningLowEditResponse = RunningLowSetting | FieldErrorMap | EmptyResponse;
119
- type RunningLowDeleteResponse = EmptyResponse;
120
- type RunningLowNotificationListResponse = RunningLowNotification[];
112
+ type CreateRunningLowSettingError = {
113
+ productId?: string;
114
+ runningLow?: string;
115
+ };
116
+ type EditRunningLowSettingError = {
117
+ runningLow?: string;
118
+ };
121
119
 
122
120
  type CreateProductRequest = {
123
121
  name: string;
@@ -160,33 +158,14 @@ type ChangeUserDataRequest = {
160
158
  isAdmin?: boolean;
161
159
  };
162
160
 
163
- type StorageListResponse = Storage[];
164
- type StorageResponse = Storage | EmptyResponse;
165
- type StorageCreateResponse = Storage | FieldErrorMap | EmptyResponse;
166
- type StorageChangeNameResponse = Storage | FieldErrorMap | EmptyResponse;
167
- type StorageDeleteResponse = EmptyResponse;
168
- type StorageItemListResponse = StorageItem[];
169
- type StorageItemResponse = StorageItem | EmptyResponse;
170
- type StorageItemAddResponse = StorageItem | FieldErrorMap | EmptyResponse;
171
- type StorageItemEditResponse = StorageItem | FieldErrorMap | EmptyResponse;
172
- type StorageItemDeleteResponse = EmptyResponse;
173
- type StorageExpiredItemsResponse = StorageItem[];
174
- type StorageAboutToExpireItemsResponse = StorageItem[];
175
- type StorageRunningLowResponse = RunningLowNotification[];
176
- type StorageMemberListResponse = StorageMember[];
177
- type StorageMemberResponse = StorageMember | EmptyResponse;
178
- type StorageMemberInviteResponse = StorageMember | FieldErrorMap | EmptyResponse;
179
- type StorageMemberDeleteResponse = EmptyResponse | FieldErrorMap;
180
- type InviteListResponse = StorageMember[];
181
- type InviteAcceptResponse = EmptyResponse;
182
- type InviteDeclineResponse = EmptyResponse;
161
+ type CreateStorageError = {
162
+ name?: string;
163
+ };
183
164
 
184
- type UserListResponse = User[];
185
- type UserResponse = User | EmptyResponse;
186
- type UserPfpResponse = ImageResponse;
187
- type UserUploadPfpResponse = EmptyResponse | FieldErrorMap | string;
188
- type UserDeleteResponse = EmptyResponse;
189
- type UserUpdateResponse = User | FieldErrorMap | EmptyResponse;
165
+ type UpdateUserError = {
166
+ username?: string;
167
+ email?: string;
168
+ };
190
169
 
191
170
  type AuthContextValue = {
192
171
  token: string | null;
@@ -354,4 +333,4 @@ type UserProviderProps = {
354
333
  declare const UserProvider: ({ baseUrl, children }: UserProviderProps) => react_jsx_runtime.JSX.Element;
355
334
  declare const useUsers: () => UserContextValue;
356
335
 
357
- export { type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateSettingRequest, type CreateStorageRequest, type EditItemRequest, type EditSettingRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteAcceptResponse, type InviteDeclineResponse, type InviteListResponse, type InviteMemberRequest, InviteProvider, type LoginErrorResponse, type LoginRequest, type LoginResponse, type LoginSuccessResponse, type LogoutErrorResponse, type LogoutResponse, type Product, type ProductCreateResponse, type ProductDeleteResponse, type ProductIconResponse, type ProductListResponse, ProductProvider, type ProductResponse, type ProductUpdateResponse, type ProductUploadIconError, type ProductUploadIconResponse, type RunningLowCreateResponse, type RunningLowDeleteResponse, type RunningLowEditResponse, type RunningLowNotification, type RunningLowNotificationListResponse, RunningLowProvider, type RunningLowSetting, type RunningLowSettingListResponse, type RunningLowSettingResponse, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageAboutToExpireItemsResponse, type StorageChangeNameResponse, type StorageCreateResponse, type StorageDeleteResponse, type StorageExpiredItemsResponse, type StorageItem, type StorageItemAddResponse, type StorageItemDeleteResponse, type StorageItemEditResponse, type StorageItemListResponse, StorageItemProvider, type StorageItemResponse, type StorageListResponse, type StorageMember, type StorageMemberDeleteResponse, type StorageMemberInviteResponse, type StorageMemberListResponse, StorageMemberProvider, type StorageMemberResponse, StorageProvider, type StorageResponse, type StorageRunningLowResponse, type TokenStorage, type UpdateProductRequest, type User, type UserDeleteResponse, type UserListResponse, type UserPfpResponse, UserProvider, type UserResponse, type UserUpdateResponse, type UserUploadPfpResponse, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useStorageItems, useStorageMembers, useStorages, useUsers };
336
+ export { type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateRunningLowSettingError, type CreateSettingRequest, type CreateStorageError, type CreateStorageRequest, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteMemberRequest, InviteProvider, type LoginErrorResponse, type LoginRequest, type LoginResponse, type LoginSuccessResponse, type LogoutErrorResponse, type LogoutResponse, type Product, type ProductCreateError, ProductProvider, type RunningLowNotification, RunningLowProvider, type RunningLowSetting, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useStorageItems, useStorageMembers, useStorages, useUsers };
package/dist/index.esm.js CHANGED
@@ -108,7 +108,7 @@ var changePasswordRequest = async (config, dto) => runWithRequestState(config, a
108
108
  });
109
109
  if (!response.ok) {
110
110
  const error = await readJson(response);
111
- if (error?.oldPassword || error?.newPasswordRepeat)
111
+ if (error?.oldPassword || error?.newPassword || error?.newPasswordRepeat)
112
112
  throw error;
113
113
  throw new Error("Change password failed");
114
114
  }
@@ -207,6 +207,9 @@ var updateUserRequest = async (config, id, dto) => runWithRequestState(config, a
207
207
  body: JSON.stringify(dto)
208
208
  });
209
209
  if (!response.ok) {
210
+ const update = await readJson(response);
211
+ if (update?.email || update?.username)
212
+ throw update;
210
213
  throw new Error("Failed to update user");
211
214
  }
212
215
  const payload = await readJson(response);
@@ -523,6 +526,9 @@ var createProductRequest = async (config, dto) => runWithRequestState(config, as
523
526
  body: JSON.stringify(dto)
524
527
  });
525
528
  if (!response.ok) {
529
+ const err = await readJson(response);
530
+ if (err?.name || err?.barcode || err?.category || err?.expirationDaysDelta)
531
+ throw err;
526
532
  throw new Error("Failed to create product");
527
533
  }
528
534
  const payload = await readJson(response);
@@ -544,6 +550,9 @@ var updateProductRequest = async (config, id, dto) => runWithRequestState(config
544
550
  body: JSON.stringify(dto)
545
551
  });
546
552
  if (!response.ok) {
553
+ const err = await readJson(response);
554
+ if (err?.name || err?.barcode || err?.category || err?.expirationDaysDelta)
555
+ throw err;
547
556
  throw new Error("Failed to update product");
548
557
  }
549
558
  const payload = await readJson(response);
@@ -716,6 +725,9 @@ var createSettingRequest = async (config, storageId, dto) => runWithRequestState
716
725
  }
717
726
  );
718
727
  if (!response.ok) {
728
+ const err = await readJson(response);
729
+ if (err?.productId || err?.runningLow)
730
+ throw err;
719
731
  throw new Error("Failed to create running low setting");
720
732
  }
721
733
  const payload = await readJson(response);
@@ -739,6 +751,9 @@ var editSettingRequest = async (config, storageId, id, dto) => runWithRequestSta
739
751
  }
740
752
  );
741
753
  if (!response.ok) {
754
+ const err = await readJson(response);
755
+ if (err?.runningLow)
756
+ throw err;
742
757
  throw new Error("Failed to edit running low setting");
743
758
  }
744
759
  const payload = await readJson(response);
@@ -893,6 +908,9 @@ var createStorageRequest = async (config, dto) => runWithRequestState(config, as
893
908
  body: JSON.stringify(dto)
894
909
  });
895
910
  if (!response.ok) {
911
+ const payload2 = await readJson(response);
912
+ if (payload2?.name)
913
+ throw payload2;
896
914
  throw new Error("Failed to create storage");
897
915
  }
898
916
  const payload = await readJson(response);
@@ -914,6 +932,9 @@ var changeStorageNameRequest = async (config, id, dto) => runWithRequestState(co
914
932
  body: JSON.stringify(dto)
915
933
  });
916
934
  if (!response.ok) {
935
+ const payload2 = await readJson(response);
936
+ if (payload2?.name)
937
+ throw payload2;
917
938
  throw new Error("Failed to update storage");
918
939
  }
919
940
  const payload = await readJson(response);
@@ -1045,6 +1066,9 @@ var addItemRequest = async (config, storageId, dto) => runWithRequestState(confi
1045
1066
  body: JSON.stringify(dto)
1046
1067
  });
1047
1068
  if (!response.ok) {
1069
+ const err = await readJson(response);
1070
+ if (err?.productId || err?.expiresAt)
1071
+ throw err;
1048
1072
  throw new Error("Failed to add storage item");
1049
1073
  }
1050
1074
  const payload = await readJson(response);
@@ -1065,6 +1089,9 @@ var editItemRequest = async (config, storageId, itemId, dto) => runWithRequestSt
1065
1089
  body: JSON.stringify(dto)
1066
1090
  });
1067
1091
  if (!response.ok) {
1092
+ const err = await readJson(response);
1093
+ if (err?.expiresAt)
1094
+ throw err;
1068
1095
  throw new Error("Failed to edit storage item");
1069
1096
  }
1070
1097
  const payload = await readJson(response);
@@ -1256,6 +1283,9 @@ var inviteMemberRequest = async (config, storageId, dto) => runWithRequestState(
1256
1283
  body: JSON.stringify(dto)
1257
1284
  });
1258
1285
  if (!response.ok) {
1286
+ const err = await readJson(response);
1287
+ if (err?.email)
1288
+ throw err;
1259
1289
  throw new Error("Failed to invite member");
1260
1290
  }
1261
1291
  const payload = await readJson(response);