@sudobility/cravings_lib 0.0.10 → 0.0.11
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/README.md +70 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @sudobility/cravings_lib
|
|
2
|
+
|
|
3
|
+
Business logic library with Zustand stores for the Cravings application.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @sudobility/cravings_lib
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `react` (>=18), `@tanstack/react-query` (>=5), `zustand` (>=5), `@sudobility/types`.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { useHistoriesManager } from "@sudobility/cravings_lib";
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
histories,
|
|
20
|
+
total,
|
|
21
|
+
percentage,
|
|
22
|
+
isCached,
|
|
23
|
+
createHistory,
|
|
24
|
+
updateHistory,
|
|
25
|
+
deleteHistory,
|
|
26
|
+
} = useHistoriesManager({
|
|
27
|
+
baseUrl: "http://localhost:8022",
|
|
28
|
+
networkClient,
|
|
29
|
+
userId,
|
|
30
|
+
token,
|
|
31
|
+
autoFetch: true,
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
### useHistoriesManager
|
|
38
|
+
|
|
39
|
+
Unified hook combining cravings_client hooks + Zustand store + business logic:
|
|
40
|
+
|
|
41
|
+
- Percentage calculation: `(userSum / globalTotal) * 100`
|
|
42
|
+
- Cache fallback when server hasn't responded yet
|
|
43
|
+
- Auto-fetch on mount (configurable)
|
|
44
|
+
- Token reactivity: resets state on token change
|
|
45
|
+
|
|
46
|
+
### useHistoriesStore
|
|
47
|
+
|
|
48
|
+
Zustand store providing per-user client-side cache with `set`, `get`, `add`, `update`, `remove` operations.
|
|
49
|
+
|
|
50
|
+
## Development
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
bun run build # Build ESM
|
|
54
|
+
bun test # Run Vitest tests
|
|
55
|
+
bun run typecheck # TypeScript check
|
|
56
|
+
bun run lint # ESLint
|
|
57
|
+
bun run verify # All checks + build (use before commit)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Related Packages
|
|
61
|
+
|
|
62
|
+
- **cravings_types** -- Shared type definitions
|
|
63
|
+
- **cravings_client** -- API client SDK (wrapped by this library)
|
|
64
|
+
- **cravings_api** -- Backend server
|
|
65
|
+
- **cravings_app** -- Web frontend (consumes useHistoriesManager)
|
|
66
|
+
- **cravings_app_rn** -- React Native app (consumes useHistoriesManager)
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
BUSL-1.1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/cravings_lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Business logic library for Starter with Zustand stores",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
"author": "Sudobility",
|
|
36
36
|
"license": "BUSL-1.1",
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@sudobility/types": "^1.9.
|
|
38
|
+
"@sudobility/types": "^1.9.57",
|
|
39
39
|
"@tanstack/react-query": ">=5.0.0",
|
|
40
40
|
"react": ">=18.0.0",
|
|
41
41
|
"zustand": ">=5.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@eslint/js": "^9.38.0",
|
|
45
|
-
"@sudobility/cravings_client": "^0.0.
|
|
46
|
-
"@sudobility/cravings_types": "^0.0.
|
|
47
|
-
"@sudobility/types": "^1.9.
|
|
45
|
+
"@sudobility/cravings_client": "^0.0.13",
|
|
46
|
+
"@sudobility/cravings_types": "^0.0.7",
|
|
47
|
+
"@sudobility/types": "^1.9.57",
|
|
48
48
|
"@tanstack/react-query": "^5.90.5",
|
|
49
49
|
"@testing-library/react": "^16.3.2",
|
|
50
50
|
"@testing-library/react-hooks": "^8.0.1",
|