shelflife-react-hooks 1.0.13 → 1.0.14
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.cjs.js +11 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.cts +34 -16
- package/dist/index.d.ts +34 -16
- package/dist/index.esm.js +11 -16
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -113,6 +113,18 @@ type TokenStorage = {
|
|
|
113
113
|
removeItem: (key: string) => Promise<void> | void;
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
+
type AddItemError = {
|
|
117
|
+
productId?: string;
|
|
118
|
+
expiresAt?: string;
|
|
119
|
+
};
|
|
120
|
+
type EditItemError = {
|
|
121
|
+
expiresAt?: string;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
type InviteMemberError = {
|
|
125
|
+
email?: string;
|
|
126
|
+
};
|
|
127
|
+
|
|
116
128
|
type ProductCreateError = {
|
|
117
129
|
name?: string;
|
|
118
130
|
category?: string;
|
|
@@ -120,23 +132,17 @@ type ProductCreateError = {
|
|
|
120
132
|
expirationDaysDelta?: number;
|
|
121
133
|
};
|
|
122
134
|
|
|
123
|
-
type CreateRunningLowSettingError = {
|
|
124
|
-
productId?: string;
|
|
125
|
-
runningLow?: string;
|
|
126
|
-
};
|
|
127
|
-
type EditRunningLowSettingError = {
|
|
128
|
-
runningLow?: string;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
135
|
type CreateProductRequest = {
|
|
132
136
|
name: string;
|
|
133
137
|
category: string;
|
|
138
|
+
description?: string;
|
|
134
139
|
barcode?: string;
|
|
135
140
|
expirationDaysDelta: number;
|
|
136
141
|
};
|
|
137
142
|
type UpdateProductRequest = {
|
|
138
143
|
name?: string;
|
|
139
144
|
category?: string;
|
|
145
|
+
description?: string;
|
|
140
146
|
barcode?: string;
|
|
141
147
|
expirationDaysDelta?: number;
|
|
142
148
|
};
|
|
@@ -176,6 +182,23 @@ type ChangeUserDataRequest = {
|
|
|
176
182
|
isAdmin?: boolean;
|
|
177
183
|
};
|
|
178
184
|
|
|
185
|
+
type CreateRunningLowSettingError = {
|
|
186
|
+
productId?: string;
|
|
187
|
+
runningLow?: string;
|
|
188
|
+
};
|
|
189
|
+
type EditRunningLowSettingError = {
|
|
190
|
+
runningLow?: string;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
type CreateShoppingItemError = {
|
|
194
|
+
productId?: string;
|
|
195
|
+
amountToBuy?: string;
|
|
196
|
+
};
|
|
197
|
+
type EditShoppingItemError = {
|
|
198
|
+
productId?: string;
|
|
199
|
+
amountToBuy?: string;
|
|
200
|
+
};
|
|
201
|
+
|
|
179
202
|
type CreateStorageError = {
|
|
180
203
|
name?: string;
|
|
181
204
|
};
|
|
@@ -230,18 +253,13 @@ type InviteProviderProps = {
|
|
|
230
253
|
declare const InviteProvider: ({ baseUrl, children }: InviteProviderProps) => react_jsx_runtime.JSX.Element;
|
|
231
254
|
declare const useInvites: () => InviteContextValue;
|
|
232
255
|
|
|
233
|
-
type ProductQuery = {
|
|
234
|
-
barcode?: string;
|
|
235
|
-
name?: string;
|
|
236
|
-
category?: string;
|
|
237
|
-
};
|
|
238
256
|
type ProductContextValue = {
|
|
239
257
|
products: Product[];
|
|
240
258
|
product: Product | null;
|
|
241
259
|
isLoading: boolean;
|
|
242
260
|
isError: boolean;
|
|
243
261
|
error: Error | null;
|
|
244
|
-
fetchProducts: (
|
|
262
|
+
fetchProducts: (search: string, size: number, page: number) => Promise<Product[]>;
|
|
245
263
|
fetchProduct: (id: number) => Promise<Product | null>;
|
|
246
264
|
createProduct: (dto: CreateProductRequest) => Promise<Product>;
|
|
247
265
|
updateProduct: (id: number, dto: UpdateProductRequest) => Promise<Product>;
|
|
@@ -279,7 +297,7 @@ type StorageContextValue = {
|
|
|
279
297
|
isLoading: boolean;
|
|
280
298
|
isError: boolean;
|
|
281
299
|
error: Error | null;
|
|
282
|
-
fetchStorages: () => Promise<Storage[]>;
|
|
300
|
+
fetchStorages: (search?: string, size?: number, page?: number) => Promise<Storage[]>;
|
|
283
301
|
fetchStorage: (id: number) => Promise<Storage | null>;
|
|
284
302
|
createStorage: (dto: CreateStorageRequest) => Promise<Storage>;
|
|
285
303
|
changeStorageName: (id: number, dto: ChangeStorageNameRequest) => Promise<Storage>;
|
|
@@ -382,4 +400,4 @@ type ToPurchaseProviderProps = {
|
|
|
382
400
|
declare const ToPurchaseProvider: ({ baseUrl, children }: ToPurchaseProviderProps) => react_jsx_runtime.JSX.Element;
|
|
383
401
|
declare const useToPurchase: () => ToPurchaseContextValue;
|
|
384
402
|
|
|
385
|
-
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 CreateShoppingItemRequest, type CreateStorageError, type CreateStorageRequest, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EditShoppingItemRequest, 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 ShoppingListItem, ShoppingListProvider, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type ToPurchaseItem, ToPurchaseProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useShoppingList, useStorageItems, useStorageMembers, useStorages, useToPurchase, useUsers };
|
|
403
|
+
export { type AddItemError, type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateRunningLowSettingError, type CreateSettingRequest, type CreateShoppingItemError, type CreateShoppingItemRequest, type CreateStorageError, type CreateStorageRequest, type EditItemError, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EditShoppingItemError, type EditShoppingItemRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteMemberError, 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 ShoppingListItem, ShoppingListProvider, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type ToPurchaseItem, ToPurchaseProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useShoppingList, useStorageItems, useStorageMembers, useStorages, useToPurchase, useUsers };
|
package/dist/index.d.ts
CHANGED
|
@@ -113,6 +113,18 @@ type TokenStorage = {
|
|
|
113
113
|
removeItem: (key: string) => Promise<void> | void;
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
+
type AddItemError = {
|
|
117
|
+
productId?: string;
|
|
118
|
+
expiresAt?: string;
|
|
119
|
+
};
|
|
120
|
+
type EditItemError = {
|
|
121
|
+
expiresAt?: string;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
type InviteMemberError = {
|
|
125
|
+
email?: string;
|
|
126
|
+
};
|
|
127
|
+
|
|
116
128
|
type ProductCreateError = {
|
|
117
129
|
name?: string;
|
|
118
130
|
category?: string;
|
|
@@ -120,23 +132,17 @@ type ProductCreateError = {
|
|
|
120
132
|
expirationDaysDelta?: number;
|
|
121
133
|
};
|
|
122
134
|
|
|
123
|
-
type CreateRunningLowSettingError = {
|
|
124
|
-
productId?: string;
|
|
125
|
-
runningLow?: string;
|
|
126
|
-
};
|
|
127
|
-
type EditRunningLowSettingError = {
|
|
128
|
-
runningLow?: string;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
135
|
type CreateProductRequest = {
|
|
132
136
|
name: string;
|
|
133
137
|
category: string;
|
|
138
|
+
description?: string;
|
|
134
139
|
barcode?: string;
|
|
135
140
|
expirationDaysDelta: number;
|
|
136
141
|
};
|
|
137
142
|
type UpdateProductRequest = {
|
|
138
143
|
name?: string;
|
|
139
144
|
category?: string;
|
|
145
|
+
description?: string;
|
|
140
146
|
barcode?: string;
|
|
141
147
|
expirationDaysDelta?: number;
|
|
142
148
|
};
|
|
@@ -176,6 +182,23 @@ type ChangeUserDataRequest = {
|
|
|
176
182
|
isAdmin?: boolean;
|
|
177
183
|
};
|
|
178
184
|
|
|
185
|
+
type CreateRunningLowSettingError = {
|
|
186
|
+
productId?: string;
|
|
187
|
+
runningLow?: string;
|
|
188
|
+
};
|
|
189
|
+
type EditRunningLowSettingError = {
|
|
190
|
+
runningLow?: string;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
type CreateShoppingItemError = {
|
|
194
|
+
productId?: string;
|
|
195
|
+
amountToBuy?: string;
|
|
196
|
+
};
|
|
197
|
+
type EditShoppingItemError = {
|
|
198
|
+
productId?: string;
|
|
199
|
+
amountToBuy?: string;
|
|
200
|
+
};
|
|
201
|
+
|
|
179
202
|
type CreateStorageError = {
|
|
180
203
|
name?: string;
|
|
181
204
|
};
|
|
@@ -230,18 +253,13 @@ type InviteProviderProps = {
|
|
|
230
253
|
declare const InviteProvider: ({ baseUrl, children }: InviteProviderProps) => react_jsx_runtime.JSX.Element;
|
|
231
254
|
declare const useInvites: () => InviteContextValue;
|
|
232
255
|
|
|
233
|
-
type ProductQuery = {
|
|
234
|
-
barcode?: string;
|
|
235
|
-
name?: string;
|
|
236
|
-
category?: string;
|
|
237
|
-
};
|
|
238
256
|
type ProductContextValue = {
|
|
239
257
|
products: Product[];
|
|
240
258
|
product: Product | null;
|
|
241
259
|
isLoading: boolean;
|
|
242
260
|
isError: boolean;
|
|
243
261
|
error: Error | null;
|
|
244
|
-
fetchProducts: (
|
|
262
|
+
fetchProducts: (search: string, size: number, page: number) => Promise<Product[]>;
|
|
245
263
|
fetchProduct: (id: number) => Promise<Product | null>;
|
|
246
264
|
createProduct: (dto: CreateProductRequest) => Promise<Product>;
|
|
247
265
|
updateProduct: (id: number, dto: UpdateProductRequest) => Promise<Product>;
|
|
@@ -279,7 +297,7 @@ type StorageContextValue = {
|
|
|
279
297
|
isLoading: boolean;
|
|
280
298
|
isError: boolean;
|
|
281
299
|
error: Error | null;
|
|
282
|
-
fetchStorages: () => Promise<Storage[]>;
|
|
300
|
+
fetchStorages: (search?: string, size?: number, page?: number) => Promise<Storage[]>;
|
|
283
301
|
fetchStorage: (id: number) => Promise<Storage | null>;
|
|
284
302
|
createStorage: (dto: CreateStorageRequest) => Promise<Storage>;
|
|
285
303
|
changeStorageName: (id: number, dto: ChangeStorageNameRequest) => Promise<Storage>;
|
|
@@ -382,4 +400,4 @@ type ToPurchaseProviderProps = {
|
|
|
382
400
|
declare const ToPurchaseProvider: ({ baseUrl, children }: ToPurchaseProviderProps) => react_jsx_runtime.JSX.Element;
|
|
383
401
|
declare const useToPurchase: () => ToPurchaseContextValue;
|
|
384
402
|
|
|
385
|
-
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 CreateShoppingItemRequest, type CreateStorageError, type CreateStorageRequest, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EditShoppingItemRequest, 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 ShoppingListItem, ShoppingListProvider, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type ToPurchaseItem, ToPurchaseProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useShoppingList, useStorageItems, useStorageMembers, useStorages, useToPurchase, useUsers };
|
|
403
|
+
export { type AddItemError, type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateRunningLowSettingError, type CreateSettingRequest, type CreateShoppingItemError, type CreateShoppingItemRequest, type CreateStorageError, type CreateStorageRequest, type EditItemError, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EditShoppingItemError, type EditShoppingItemRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteMemberError, 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 ShoppingListItem, ShoppingListProvider, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type ToPurchaseItem, ToPurchaseProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useShoppingList, useStorageItems, useStorageMembers, useStorages, useToPurchase, useUsers };
|
package/dist/index.esm.js
CHANGED
|
@@ -468,19 +468,11 @@ var updateById2 = (items, updated) => {
|
|
|
468
468
|
next[index] = updated;
|
|
469
469
|
return next;
|
|
470
470
|
};
|
|
471
|
-
var fetchProductsRequest = async (config,
|
|
471
|
+
var fetchProductsRequest = async (config, search, size, page) => runWithRequestState(config, async () => {
|
|
472
472
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
473
|
-
|
|
474
|
-
if (
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
if (query?.name) {
|
|
478
|
-
params.set("name", query.name);
|
|
479
|
-
}
|
|
480
|
-
if (query?.category) {
|
|
481
|
-
params.set("category", query.category);
|
|
482
|
-
}
|
|
483
|
-
const url = params.toString() ? `${normalizedBaseUrl}/api/products?${params.toString()}` : `${normalizedBaseUrl}/api/products`;
|
|
473
|
+
let url = `${normalizedBaseUrl}/api/products?search=${search}`;
|
|
474
|
+
if (size > 0)
|
|
475
|
+
url += `&page=${page}&size=${size}`;
|
|
484
476
|
const response = await fetch(url, {
|
|
485
477
|
headers: buildAuthHeaders(config.token)
|
|
486
478
|
});
|
|
@@ -618,7 +610,7 @@ var ProductProvider = ({ baseUrl, children }) => {
|
|
|
618
610
|
setError
|
|
619
611
|
}), [baseUrl, token]);
|
|
620
612
|
const fetchProducts = useCallback3(
|
|
621
|
-
(
|
|
613
|
+
(search = "", size = 0, page = 0) => fetchProductsRequest(apiConfig, search, size, page),
|
|
622
614
|
[apiConfig]
|
|
623
615
|
);
|
|
624
616
|
const fetchProduct = useCallback3((id) => fetchProductRequest(apiConfig, id), [apiConfig]);
|
|
@@ -858,11 +850,14 @@ var updateById4 = (items, updated) => {
|
|
|
858
850
|
next[index] = updated;
|
|
859
851
|
return next;
|
|
860
852
|
};
|
|
861
|
-
var fetchStoragesRequest = async (config) => runWithRequestState(
|
|
853
|
+
var fetchStoragesRequest = async (config, search, size, page) => runWithRequestState(
|
|
862
854
|
config,
|
|
863
855
|
async () => {
|
|
864
856
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
865
|
-
|
|
857
|
+
let url = `${normalizedBaseUrl}/api/storages?search=${search}`;
|
|
858
|
+
if (size > 0)
|
|
859
|
+
url += `&page=${page}&size=${size}`;
|
|
860
|
+
const response = await fetch(url, {
|
|
866
861
|
headers: buildAuthHeaders(config.token)
|
|
867
862
|
});
|
|
868
863
|
if (!response.ok) {
|
|
@@ -976,7 +971,7 @@ var StorageProvider = ({ baseUrl, children }) => {
|
|
|
976
971
|
setIsError,
|
|
977
972
|
setError
|
|
978
973
|
}), [baseUrl, token]);
|
|
979
|
-
const fetchStorages = useCallback5(() => fetchStoragesRequest(apiConfig), [apiConfig]);
|
|
974
|
+
const fetchStorages = useCallback5((search = "", size = 0, page = 0) => fetchStoragesRequest(apiConfig, search, page, size), [apiConfig]);
|
|
980
975
|
const fetchStorage = useCallback5((id) => fetchStorageRequest(apiConfig, id), [apiConfig]);
|
|
981
976
|
const createStorage = useCallback5(
|
|
982
977
|
(dto) => createStorageRequest(apiConfig, dto),
|