shelflife-react-hooks 1.0.14 → 1.0.16
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 +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.esm.js +5 -5
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/context/ProductContext.tsx +2 -7
- package/src/context/StorageContext.tsx +3 -2
- package/src/context/api/productApi.ts +5 -4
- package/src/context/api/storageApi.ts +5 -4
- package/src/index.ts +1 -0
- package/src/type/PaginatedResponse.ts +9 -0
- package/src/type/models.ts +1 -0
- package/src/type/product.ts +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -26,6 +26,7 @@ type Product = {
|
|
|
26
26
|
id: number;
|
|
27
27
|
ownerId: number;
|
|
28
28
|
name: string;
|
|
29
|
+
description: string | null;
|
|
29
30
|
category: string;
|
|
30
31
|
expirationDaysDelta: number;
|
|
31
32
|
barcode: string | null;
|
|
@@ -125,8 +126,19 @@ type InviteMemberError = {
|
|
|
125
126
|
email?: string;
|
|
126
127
|
};
|
|
127
128
|
|
|
129
|
+
type PaginatedResponse<T> = {
|
|
130
|
+
data: T[];
|
|
131
|
+
currentPage: number;
|
|
132
|
+
totalPages: number;
|
|
133
|
+
totalItems: number;
|
|
134
|
+
pageSize: number;
|
|
135
|
+
hasNext: boolean;
|
|
136
|
+
hasPrevious: boolean;
|
|
137
|
+
};
|
|
138
|
+
|
|
128
139
|
type ProductCreateError = {
|
|
129
140
|
name?: string;
|
|
141
|
+
description?: string;
|
|
130
142
|
category?: string;
|
|
131
143
|
barcode?: string;
|
|
132
144
|
expirationDaysDelta?: number;
|
|
@@ -259,7 +271,7 @@ type ProductContextValue = {
|
|
|
259
271
|
isLoading: boolean;
|
|
260
272
|
isError: boolean;
|
|
261
273
|
error: Error | null;
|
|
262
|
-
fetchProducts: (search
|
|
274
|
+
fetchProducts: (search?: string, size?: number, page?: number) => Promise<PaginatedResponse<Product>>;
|
|
263
275
|
fetchProduct: (id: number) => Promise<Product | null>;
|
|
264
276
|
createProduct: (dto: CreateProductRequest) => Promise<Product>;
|
|
265
277
|
updateProduct: (id: number, dto: UpdateProductRequest) => Promise<Product>;
|
|
@@ -297,7 +309,7 @@ type StorageContextValue = {
|
|
|
297
309
|
isLoading: boolean;
|
|
298
310
|
isError: boolean;
|
|
299
311
|
error: Error | null;
|
|
300
|
-
fetchStorages: (search?: string, size?: number, page?: number) => Promise<Storage
|
|
312
|
+
fetchStorages: (search?: string, size?: number, page?: number) => Promise<PaginatedResponse<Storage>>;
|
|
301
313
|
fetchStorage: (id: number) => Promise<Storage | null>;
|
|
302
314
|
createStorage: (dto: CreateStorageRequest) => Promise<Storage>;
|
|
303
315
|
changeStorageName: (id: number, dto: ChangeStorageNameRequest) => Promise<Storage>;
|
|
@@ -400,4 +412,4 @@ type ToPurchaseProviderProps = {
|
|
|
400
412
|
declare const ToPurchaseProvider: ({ baseUrl, children }: ToPurchaseProviderProps) => react_jsx_runtime.JSX.Element;
|
|
401
413
|
declare const useToPurchase: () => ToPurchaseContextValue;
|
|
402
414
|
|
|
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 };
|
|
415
|
+
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 PaginatedResponse, 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
|
@@ -26,6 +26,7 @@ type Product = {
|
|
|
26
26
|
id: number;
|
|
27
27
|
ownerId: number;
|
|
28
28
|
name: string;
|
|
29
|
+
description: string | null;
|
|
29
30
|
category: string;
|
|
30
31
|
expirationDaysDelta: number;
|
|
31
32
|
barcode: string | null;
|
|
@@ -125,8 +126,19 @@ type InviteMemberError = {
|
|
|
125
126
|
email?: string;
|
|
126
127
|
};
|
|
127
128
|
|
|
129
|
+
type PaginatedResponse<T> = {
|
|
130
|
+
data: T[];
|
|
131
|
+
currentPage: number;
|
|
132
|
+
totalPages: number;
|
|
133
|
+
totalItems: number;
|
|
134
|
+
pageSize: number;
|
|
135
|
+
hasNext: boolean;
|
|
136
|
+
hasPrevious: boolean;
|
|
137
|
+
};
|
|
138
|
+
|
|
128
139
|
type ProductCreateError = {
|
|
129
140
|
name?: string;
|
|
141
|
+
description?: string;
|
|
130
142
|
category?: string;
|
|
131
143
|
barcode?: string;
|
|
132
144
|
expirationDaysDelta?: number;
|
|
@@ -259,7 +271,7 @@ type ProductContextValue = {
|
|
|
259
271
|
isLoading: boolean;
|
|
260
272
|
isError: boolean;
|
|
261
273
|
error: Error | null;
|
|
262
|
-
fetchProducts: (search
|
|
274
|
+
fetchProducts: (search?: string, size?: number, page?: number) => Promise<PaginatedResponse<Product>>;
|
|
263
275
|
fetchProduct: (id: number) => Promise<Product | null>;
|
|
264
276
|
createProduct: (dto: CreateProductRequest) => Promise<Product>;
|
|
265
277
|
updateProduct: (id: number, dto: UpdateProductRequest) => Promise<Product>;
|
|
@@ -297,7 +309,7 @@ type StorageContextValue = {
|
|
|
297
309
|
isLoading: boolean;
|
|
298
310
|
isError: boolean;
|
|
299
311
|
error: Error | null;
|
|
300
|
-
fetchStorages: (search?: string, size?: number, page?: number) => Promise<Storage
|
|
312
|
+
fetchStorages: (search?: string, size?: number, page?: number) => Promise<PaginatedResponse<Storage>>;
|
|
301
313
|
fetchStorage: (id: number) => Promise<Storage | null>;
|
|
302
314
|
createStorage: (dto: CreateStorageRequest) => Promise<Storage>;
|
|
303
315
|
changeStorageName: (id: number, dto: ChangeStorageNameRequest) => Promise<Storage>;
|
|
@@ -400,4 +412,4 @@ type ToPurchaseProviderProps = {
|
|
|
400
412
|
declare const ToPurchaseProvider: ({ baseUrl, children }: ToPurchaseProviderProps) => react_jsx_runtime.JSX.Element;
|
|
401
413
|
declare const useToPurchase: () => ToPurchaseContextValue;
|
|
402
414
|
|
|
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 };
|
|
415
|
+
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 PaginatedResponse, 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
|
@@ -481,10 +481,10 @@ var fetchProductsRequest = async (config, search, size, page) => runWithRequestS
|
|
|
481
481
|
}
|
|
482
482
|
const payload = await readJson(response);
|
|
483
483
|
if (payload) {
|
|
484
|
-
config.setProducts(payload);
|
|
484
|
+
config.setProducts(payload.data);
|
|
485
485
|
return payload;
|
|
486
486
|
}
|
|
487
|
-
return [];
|
|
487
|
+
return { data: [], currentPage: 0, hasNext: false, hasPrevious: false, pageSize: 0, totalItems: 0, totalPages: 0 };
|
|
488
488
|
});
|
|
489
489
|
var fetchProductRequest = async (config, id) => runWithRequestState(config, async () => {
|
|
490
490
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
@@ -865,10 +865,10 @@ var fetchStoragesRequest = async (config, search, size, page) => runWithRequestS
|
|
|
865
865
|
}
|
|
866
866
|
const payload = await readJson(response);
|
|
867
867
|
if (payload) {
|
|
868
|
-
config.setStorages(payload);
|
|
868
|
+
config.setStorages(payload.data);
|
|
869
869
|
return payload;
|
|
870
870
|
}
|
|
871
|
-
return [];
|
|
871
|
+
return { data: [], currentPage: 0, hasNext: false, hasPrevious: false, pageSize: 0, totalItems: 0, totalPages: 0 };
|
|
872
872
|
}
|
|
873
873
|
);
|
|
874
874
|
var fetchStorageRequest = async (config, id) => runWithRequestState(config, async () => {
|
|
@@ -971,7 +971,7 @@ var StorageProvider = ({ baseUrl, children }) => {
|
|
|
971
971
|
setIsError,
|
|
972
972
|
setError
|
|
973
973
|
}), [baseUrl, token]);
|
|
974
|
-
const fetchStorages = useCallback5((search = "", size = 0, page = 0) => fetchStoragesRequest(apiConfig, search,
|
|
974
|
+
const fetchStorages = useCallback5((search = "", size = 0, page = 0) => fetchStoragesRequest(apiConfig, search, size, page), [apiConfig]);
|
|
975
975
|
const fetchStorage = useCallback5((id) => fetchStorageRequest(apiConfig, id), [apiConfig]);
|
|
976
976
|
const createStorage = useCallback5(
|
|
977
977
|
(dto) => createStorageRequest(apiConfig, dto),
|