shelflife-react-hooks 1.0.19 → 1.0.20

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.
Files changed (44) hide show
  1. package/dist/index.cjs.js +22 -0
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.cts +2 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.esm.js +22 -0
  6. package/dist/index.esm.js.map +1 -1
  7. package/package.json +36 -36
  8. package/src/context/AuthContext.tsx +161 -161
  9. package/src/context/InviteContext.tsx +74 -74
  10. package/src/context/ProductContext.tsx +131 -121
  11. package/src/context/RunningLowContext.tsx +100 -100
  12. package/src/context/ShoppingListContext.tsx +76 -76
  13. package/src/context/StorageContext.tsx +105 -105
  14. package/src/context/StorageItemContext.tsx +157 -157
  15. package/src/context/StorageMemberContext.tsx +84 -84
  16. package/src/context/UserContext.tsx +109 -109
  17. package/src/context/__tests__/contexts.test.tsx +370 -370
  18. package/src/context/api/authApi.ts +155 -155
  19. package/src/context/api/inviteApi.ts +65 -65
  20. package/src/context/api/productApi.ts +223 -201
  21. package/src/context/api/requestState.ts +24 -24
  22. package/src/context/api/runningLowApi.ts +141 -141
  23. package/src/context/api/shoppingListApi.ts +161 -161
  24. package/src/context/api/storageApi.ts +166 -166
  25. package/src/context/api/storageItemApi.ts +260 -260
  26. package/src/context/api/storageMemberApi.ts +84 -84
  27. package/src/context/api/userApi.ts +161 -161
  28. package/src/context/http.ts +22 -22
  29. package/src/index.ts +21 -21
  30. package/src/type/PaginatedResponse.ts +8 -8
  31. package/src/type/auth.ts +79 -79
  32. package/src/type/base.ts +21 -21
  33. package/src/type/item.ts +12 -12
  34. package/src/type/member.ts +6 -6
  35. package/src/type/models.ts +56 -56
  36. package/src/type/product.ts +11 -11
  37. package/src/type/requests.ts +60 -60
  38. package/src/type/runninglow.ts +13 -13
  39. package/src/type/shoppingList.ts +13 -13
  40. package/src/type/storage.ts +7 -7
  41. package/src/type/user.ts +11 -11
  42. package/tsconfig.json +46 -46
  43. package/tsup.config.ts +10 -10
  44. package/vitest.config.ts +8 -8
package/dist/index.cjs.js CHANGED
@@ -534,6 +534,21 @@ var fetchProductRequest = async (config, id) => runWithRequestState(config, asyn
534
534
  config.setProducts((previous) => updateById2(previous, payload));
535
535
  return payload;
536
536
  });
537
+ var fetchCategoriesRequest = async (config) => runWithRequestState(config, async () => {
538
+ const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
539
+ const response = await fetch(`${normalizedBaseUrl}/api/products/categories`, {
540
+ headers: buildAuthHeaders(config.token)
541
+ });
542
+ if (!response.ok) {
543
+ throw new Error("Failed to fetch categories");
544
+ }
545
+ const payload = await readJson(response);
546
+ if (!payload) {
547
+ throw new Error("Category response missing data");
548
+ }
549
+ config.setCategories(payload);
550
+ return payload;
551
+ });
537
552
  var createProductRequest = async (config, dto) => runWithRequestState(config, async () => {
538
553
  const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
539
554
  const response = await fetch(`${normalizedBaseUrl}/api/products`, {
@@ -623,6 +638,7 @@ var import_jsx_runtime3 = require("react/jsx-runtime");
623
638
  var ProductContext = (0, import_react3.createContext)(void 0);
624
639
  var ProductProvider = ({ baseUrl, children }) => {
625
640
  const { token } = useAuth();
641
+ const [categories, setCategories] = (0, import_react3.useState)([]);
626
642
  const [products, setProducts] = (0, import_react3.useState)([]);
627
643
  const [product, setProduct] = (0, import_react3.useState)(null);
628
644
  const [isLoading, setIsLoading] = (0, import_react3.useState)(false);
@@ -631,6 +647,7 @@ var ProductProvider = ({ baseUrl, children }) => {
631
647
  const apiConfig = (0, import_react3.useMemo)(() => ({
632
648
  baseUrl,
633
649
  token,
650
+ setCategories,
634
651
  setProducts,
635
652
  setProduct,
636
653
  setIsLoading,
@@ -641,6 +658,7 @@ var ProductProvider = ({ baseUrl, children }) => {
641
658
  (search = "", size = 0, page = 0) => fetchProductsRequest(apiConfig, search, size, page),
642
659
  [apiConfig]
643
660
  );
661
+ const fetchCategories = (0, import_react3.useCallback)(() => fetchCategoriesRequest(apiConfig), [apiConfig]);
644
662
  const fetchProduct = (0, import_react3.useCallback)((id) => fetchProductRequest(apiConfig, id), [apiConfig]);
645
663
  const createProduct = (0, import_react3.useCallback)(
646
664
  (dto) => createProductRequest(apiConfig, dto),
@@ -662,6 +680,8 @@ var ProductProvider = ({ baseUrl, children }) => {
662
680
  isLoading,
663
681
  isError,
664
682
  error,
683
+ categories,
684
+ fetchCategories,
665
685
  fetchProducts,
666
686
  fetchProduct,
667
687
  createProduct,
@@ -675,11 +695,13 @@ var ProductProvider = ({ baseUrl, children }) => {
675
695
  error,
676
696
  fetchProduct,
677
697
  fetchProducts,
698
+ fetchCategories,
678
699
  getProductIcon,
679
700
  isError,
680
701
  isLoading,
681
702
  product,
682
703
  products,
704
+ categories,
683
705
  updateProduct,
684
706
  uploadProductIcon
685
707
  ]);