shelflife-react-hooks 1.0.18 → 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 +23 -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 +23 -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 -159
  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/src/type/auth.ts CHANGED
@@ -1,80 +1,80 @@
1
- import type { EmptyResponse, ErrorResponse, FieldErrorMap } from './base.js';
2
- import type { User } from './models.js';
3
-
4
- type LoginRequest = {
5
- email: string;
6
- password: string;
7
- }
8
-
9
- type LoginSuccessResponse = {
10
- token: string;
11
- }
12
-
13
- type LoginErrorResponse = {
14
- error: string;
15
- };
16
-
17
- type LoginResponse = LoginSuccessResponse | LoginErrorResponse;
18
-
19
- type SignupRequest = {
20
- email: string;
21
- username: string;
22
- password: string;
23
- passwordRepeat: string;
24
- }
25
-
26
- type ChangePasswordRequest = {
27
- oldPassword: string;
28
- newPassword: string;
29
- newPasswordRepeat: string;
30
- }
31
-
32
- type SignupError = {
33
- username?: string;
34
- email?: string;
35
- password?: string;
36
- passwordRepeat?: string;
37
- error?: string;
38
- };
39
-
40
- type SignupResponse = User | SignupError | EmptyResponse;
41
-
42
- type LogoutErrorResponse = {
43
- error: string;
44
- };
45
-
46
- type LogoutResponse = EmptyResponse | LogoutErrorResponse;
47
-
48
- type ChangePasswordErrorResponse = {
49
- oldPassword?: string;
50
- newPassword?: string;
51
- newPasswordRepeat?: string;
52
- };
53
-
54
- type ChangePasswordResponse = EmptyResponse | ChangePasswordErrorResponse;
55
-
56
- type GetMeResponse = User;
57
-
58
- type TokenStorage = {
59
- getItem: (key: string) => Promise<string | null> | string | null;
60
- setItem: (key: string, value: string) => Promise<void> | void;
61
- removeItem: (key: string) => Promise<void> | void;
62
- };
63
-
64
- export type {
65
- LoginRequest,
66
- LoginSuccessResponse,
67
- LoginErrorResponse,
68
- LoginResponse,
69
- User,
70
- SignupRequest,
71
- SignupError,
72
- SignupResponse,
73
- ChangePasswordRequest,
74
- LogoutErrorResponse,
75
- LogoutResponse,
76
- ChangePasswordErrorResponse,
77
- ChangePasswordResponse,
78
- GetMeResponse,
79
- TokenStorage
1
+ import type { EmptyResponse, ErrorResponse, FieldErrorMap } from './base.js';
2
+ import type { User } from './models.js';
3
+
4
+ type LoginRequest = {
5
+ email: string;
6
+ password: string;
7
+ }
8
+
9
+ type LoginSuccessResponse = {
10
+ token: string;
11
+ }
12
+
13
+ type LoginErrorResponse = {
14
+ error: string;
15
+ };
16
+
17
+ type LoginResponse = LoginSuccessResponse | LoginErrorResponse;
18
+
19
+ type SignupRequest = {
20
+ email: string;
21
+ username: string;
22
+ password: string;
23
+ passwordRepeat: string;
24
+ }
25
+
26
+ type ChangePasswordRequest = {
27
+ oldPassword: string;
28
+ newPassword: string;
29
+ newPasswordRepeat: string;
30
+ }
31
+
32
+ type SignupError = {
33
+ username?: string;
34
+ email?: string;
35
+ password?: string;
36
+ passwordRepeat?: string;
37
+ error?: string;
38
+ };
39
+
40
+ type SignupResponse = User | SignupError | EmptyResponse;
41
+
42
+ type LogoutErrorResponse = {
43
+ error: string;
44
+ };
45
+
46
+ type LogoutResponse = EmptyResponse | LogoutErrorResponse;
47
+
48
+ type ChangePasswordErrorResponse = {
49
+ oldPassword?: string;
50
+ newPassword?: string;
51
+ newPasswordRepeat?: string;
52
+ };
53
+
54
+ type ChangePasswordResponse = EmptyResponse | ChangePasswordErrorResponse;
55
+
56
+ type GetMeResponse = User;
57
+
58
+ type TokenStorage = {
59
+ getItem: (key: string) => Promise<string | null> | string | null;
60
+ setItem: (key: string, value: string) => Promise<void> | void;
61
+ removeItem: (key: string) => Promise<void> | void;
62
+ };
63
+
64
+ export type {
65
+ LoginRequest,
66
+ LoginSuccessResponse,
67
+ LoginErrorResponse,
68
+ LoginResponse,
69
+ User,
70
+ SignupRequest,
71
+ SignupError,
72
+ SignupResponse,
73
+ ChangePasswordRequest,
74
+ LogoutErrorResponse,
75
+ LogoutResponse,
76
+ ChangePasswordErrorResponse,
77
+ ChangePasswordResponse,
78
+ GetMeResponse,
79
+ TokenStorage
80
80
  }
package/src/type/base.ts CHANGED
@@ -1,22 +1,22 @@
1
- type BaseErrorResponse = {
2
- success: false;
3
- message: string;
4
- }
5
-
6
- type EmptyResponse = Record<string, never>;
7
-
8
- type ErrorResponse = {
9
- error: string;
10
- };
11
-
12
- type FieldErrorMap = Record<string, string>;
13
-
14
- type ImageResponse = ArrayBuffer;
15
-
16
- export type {
17
- BaseErrorResponse,
18
- EmptyResponse,
19
- ErrorResponse,
20
- FieldErrorMap,
21
- ImageResponse
1
+ type BaseErrorResponse = {
2
+ success: false;
3
+ message: string;
4
+ }
5
+
6
+ type EmptyResponse = Record<string, never>;
7
+
8
+ type ErrorResponse = {
9
+ error: string;
10
+ };
11
+
12
+ type FieldErrorMap = Record<string, string>;
13
+
14
+ type ImageResponse = ArrayBuffer;
15
+
16
+ export type {
17
+ BaseErrorResponse,
18
+ EmptyResponse,
19
+ ErrorResponse,
20
+ FieldErrorMap,
21
+ ImageResponse
22
22
  }
package/src/type/item.ts CHANGED
@@ -1,13 +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
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
13
  }
@@ -1,7 +1,7 @@
1
- type InviteMemberError = {
2
- email?: string;
3
- }
4
-
5
- export type {
6
- InviteMemberError
1
+ type InviteMemberError = {
2
+ email?: string;
3
+ }
4
+
5
+ export type {
6
+ InviteMemberError
7
7
  }
@@ -1,57 +1,57 @@
1
- export type User = {
2
- id: number;
3
- username: string;
4
- admin: boolean;
5
- };
6
-
7
- export type Storage = {
8
- id: number;
9
- name: string;
10
- owner: User;
11
- };
12
-
13
- export type Product = {
14
- id: number;
15
- ownerId: number;
16
- name: string;
17
- description: string | null;
18
- category: string;
19
- expirationDaysDelta: number;
20
- barcode: string | null;
21
- };
22
-
23
- export type StorageItem = {
24
- id: number;
25
- storage: Storage;
26
- product: Product;
27
- expiresAt: string;
28
- createdAt: string;
29
- };
30
-
31
- export type StorageMember = {
32
- id: number;
33
- storage: Storage;
34
- user: User;
35
- accepted: boolean;
36
- };
37
-
38
- export type RunningLowSetting = {
39
- id: number;
40
- storage: Storage;
41
- product: Product;
42
- runningLow: number;
43
- };
44
-
45
- export type RunningLowNotification = {
46
- storage: Storage;
47
- product: Product;
48
- runningLowAt: number;
49
- amount: number;
50
- };
51
-
52
- export type ShoppingListItem = {
53
- id: number;
54
- storage: Storage;
55
- product: Product;
56
- amountToBuy: number;
1
+ export type User = {
2
+ id: number;
3
+ username: string;
4
+ admin: boolean;
5
+ };
6
+
7
+ export type Storage = {
8
+ id: number;
9
+ name: string;
10
+ owner: User;
11
+ };
12
+
13
+ export type Product = {
14
+ id: number;
15
+ ownerId: number;
16
+ name: string;
17
+ description: string | null;
18
+ category: string;
19
+ expirationDaysDelta: number;
20
+ barcode: string | null;
21
+ };
22
+
23
+ export type StorageItem = {
24
+ id: number;
25
+ storage: Storage;
26
+ product: Product;
27
+ expiresAt: string;
28
+ createdAt: string;
29
+ };
30
+
31
+ export type StorageMember = {
32
+ id: number;
33
+ storage: Storage;
34
+ user: User;
35
+ accepted: boolean;
36
+ };
37
+
38
+ export type RunningLowSetting = {
39
+ id: number;
40
+ storage: Storage;
41
+ product: Product;
42
+ runningLow: number;
43
+ };
44
+
45
+ export type RunningLowNotification = {
46
+ storage: Storage;
47
+ product: Product;
48
+ runningLowAt: number;
49
+ amount: number;
50
+ };
51
+
52
+ export type ShoppingListItem = {
53
+ id: number;
54
+ storage: Storage;
55
+ product: Product;
56
+ amountToBuy: number;
57
57
  };
@@ -1,11 +1,11 @@
1
- type ProductCreateError = {
2
- name?: string;
3
- description?: string;
4
- category?: string;
5
- barcode?: string;
6
- expirationDaysDelta?: number;
7
- }
8
-
9
- export type {
10
- ProductCreateError
11
- };
1
+ type ProductCreateError = {
2
+ name?: string;
3
+ description?: string;
4
+ category?: string;
5
+ barcode?: string;
6
+ expirationDaysDelta?: number;
7
+ }
8
+
9
+ export type {
10
+ ProductCreateError
11
+ };
@@ -1,60 +1,60 @@
1
- export type CreateProductRequest = {
2
- name: string;
3
- category: string;
4
- description?: string;
5
- barcode?: string;
6
- expirationDaysDelta: number;
7
- };
8
-
9
- export type UpdateProductRequest = {
10
- name?: string;
11
- category?: string;
12
- description?: string;
13
- barcode?: string;
14
- expirationDaysDelta?: number;
15
- };
16
-
17
- export type CreateSettingRequest = {
18
- productId: number;
19
- runningLow: number;
20
- };
21
-
22
- export type EditSettingRequest = {
23
- runningLow: number;
24
- };
25
-
26
- export type AddItemRequest = {
27
- productId: number;
28
- expiresAt: string;
29
- };
30
-
31
- export type EditItemRequest = {
32
- expiresAt?: string;
33
- };
34
-
35
- export type CreateShoppingItemRequest = {
36
- productId: number;
37
- amountToBuy: number;
38
- };
39
-
40
- export type EditShoppingItemRequest = {
41
- amountToBuy: number;
42
- };
43
-
44
- export type CreateStorageRequest = {
45
- name: string;
46
- };
47
-
48
- export type ChangeStorageNameRequest = {
49
- name: string;
50
- };
51
-
52
- export type InviteMemberRequest = {
53
- email: string;
54
- };
55
-
56
- export type ChangeUserDataRequest = {
57
- email?: string;
58
- username?: string;
59
- isAdmin?: boolean;
60
- };
1
+ export type CreateProductRequest = {
2
+ name: string;
3
+ category: string;
4
+ description?: string;
5
+ barcode?: string;
6
+ expirationDaysDelta: number;
7
+ };
8
+
9
+ export type UpdateProductRequest = {
10
+ name?: string;
11
+ category?: string;
12
+ description?: string;
13
+ barcode?: string;
14
+ expirationDaysDelta?: number;
15
+ };
16
+
17
+ export type CreateSettingRequest = {
18
+ productId: number;
19
+ runningLow: number;
20
+ };
21
+
22
+ export type EditSettingRequest = {
23
+ runningLow: number;
24
+ };
25
+
26
+ export type AddItemRequest = {
27
+ productId: number;
28
+ expiresAt: string;
29
+ };
30
+
31
+ export type EditItemRequest = {
32
+ expiresAt?: string;
33
+ };
34
+
35
+ export type CreateShoppingItemRequest = {
36
+ productId: number;
37
+ amountToBuy: number;
38
+ };
39
+
40
+ export type EditShoppingItemRequest = {
41
+ amountToBuy: number;
42
+ };
43
+
44
+ export type CreateStorageRequest = {
45
+ name: string;
46
+ };
47
+
48
+ export type ChangeStorageNameRequest = {
49
+ name: string;
50
+ };
51
+
52
+ export type InviteMemberRequest = {
53
+ email: string;
54
+ };
55
+
56
+ export type ChangeUserDataRequest = {
57
+ email?: string;
58
+ username?: string;
59
+ isAdmin?: boolean;
60
+ };
@@ -1,13 +1,13 @@
1
- type CreateRunningLowSettingError = {
2
- productId?: string;
3
- runningLow?: string;
4
- }
5
-
6
- type EditRunningLowSettingError = {
7
- runningLow?: string;
8
- }
9
-
10
- export type {
11
- CreateRunningLowSettingError,
12
- EditRunningLowSettingError
13
- };
1
+ type CreateRunningLowSettingError = {
2
+ productId?: string;
3
+ runningLow?: string;
4
+ }
5
+
6
+ type EditRunningLowSettingError = {
7
+ runningLow?: string;
8
+ }
9
+
10
+ export type {
11
+ CreateRunningLowSettingError,
12
+ EditRunningLowSettingError
13
+ };
@@ -1,14 +1,14 @@
1
- type CreateShoppingItemError = {
2
- productId?: string;
3
- amountToBuy?: string;
4
- }
5
-
6
- type EditShoppingItemError = {
7
- productId?: string;
8
- amountToBuy?: string;
9
- }
10
-
11
- export type {
12
- CreateShoppingItemError,
13
- EditShoppingItemError
1
+ type CreateShoppingItemError = {
2
+ productId?: string;
3
+ amountToBuy?: string;
4
+ }
5
+
6
+ type EditShoppingItemError = {
7
+ productId?: string;
8
+ amountToBuy?: string;
9
+ }
10
+
11
+ export type {
12
+ CreateShoppingItemError,
13
+ EditShoppingItemError
14
14
  }
@@ -1,7 +1,7 @@
1
- type CreateStorageError = {
2
- name?: string;
3
- }
4
-
5
- export type {
6
- CreateStorageError
7
- };
1
+ type CreateStorageError = {
2
+ name?: string;
3
+ }
4
+
5
+ export type {
6
+ CreateStorageError
7
+ };
package/src/type/user.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { EmptyResponse, FieldErrorMap, ImageResponse } from './base.js';
2
- import type { User } from './models.js';
3
-
4
- type UpdateUserError = {
5
- username?: string;
6
- email?: string;
7
- }
8
-
9
- export type {
10
- UpdateUserError
11
- };
1
+ import type { EmptyResponse, FieldErrorMap, ImageResponse } from './base.js';
2
+ import type { User } from './models.js';
3
+
4
+ type UpdateUserError = {
5
+ username?: string;
6
+ email?: string;
7
+ }
8
+
9
+ export type {
10
+ UpdateUserError
11
+ };