@caseparts-org/casecore 0.0.2 → 0.0.3
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 +60 -69
- package/package.json +3 -2
package/README.md
CHANGED
@@ -1,69 +1,60 @@
|
|
1
|
-
# React
|
2
|
-
|
3
|
-
This
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
-
|
8
|
-
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
```
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
parserOptions: {
|
62
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
63
|
-
tsconfigRootDir: import.meta.dirname,
|
64
|
-
},
|
65
|
-
// other options...
|
66
|
-
},
|
67
|
-
},
|
68
|
-
])
|
69
|
-
```
|
1
|
+
# CaseCore React Component & Logic Library
|
2
|
+
|
3
|
+
This project is a reusable logic and component library for React and Next.js applications, designed to house all core business logic for our front-end apps, decoupled from any specific UI. While it currently focuses on authentication, claims, and session management, it is intended to grow into a central place for all shared business logic, utilities, and core functionality needed across our projects.
|
4
|
+
|
5
|
+
## Project Structure
|
6
|
+
|
7
|
+
- **/lib/**
|
8
|
+
- Contains all code intended for export as part of the library.
|
9
|
+
- Includes authentication context/provider, hooks, utility functions, and type definitions.
|
10
|
+
- The main entry point for consumers is `lib/index.ts`.
|
11
|
+
- **/src/App.tsx**
|
12
|
+
- Local demo/test app for development, not included in the library build.
|
13
|
+
- Useful for running and testing components locally with `npm run dev`.
|
14
|
+
- **/public/**
|
15
|
+
- Static assets for local development/demo.
|
16
|
+
- **/index.html**
|
17
|
+
- Entry point for local development with Vite.
|
18
|
+
|
19
|
+
## Key Features
|
20
|
+
|
21
|
+
- **Authentication Context (`AuthProvider`)**
|
22
|
+
- Provides authentication state, login/logout/impersonate methods, and claims to your app via React context.
|
23
|
+
- Handles JWT parsing, localStorage/sessionStorage, and API integration.
|
24
|
+
- **Claims & Session Utilities**
|
25
|
+
- `buildClaimsFromPayload`: Normalizes JWT payloads into a consistent claims object.
|
26
|
+
- `getSessionId`: Manages session IDs in sessionStorage.
|
27
|
+
- `useLocalStorage`: React hook for persistent state with automatic key prefixing.
|
28
|
+
- **TypeScript-first**
|
29
|
+
- All types and interfaces are defined in `lib/authentication/AuthTypes.ts` for strong typing and IDE support.
|
30
|
+
- **Testing**
|
31
|
+
- Tests are colocated with their modules (e.g., `AuthContext.test.tsx`).
|
32
|
+
- Mocks for fetch and JWT decoding are used to simulate authentication flows.
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
- **As a library:**
|
37
|
+
- Import from `lib/index.ts` in your consuming app:
|
38
|
+
```ts
|
39
|
+
import { AuthProvider, useAuthContext } from 'casecore/lib';
|
40
|
+
```
|
41
|
+
- **For local development:**
|
42
|
+
- Run `npm run dev` to start the Vite dev server and use the demo app in `src/App.tsx`.
|
43
|
+
- **To run tests locally:**
|
44
|
+
- Run `npm test` or `npx vitest run` to execute all tests.
|
45
|
+
- For watch mode (auto-re-run on file changes), use:
|
46
|
+
```sh
|
47
|
+
npx vitest
|
48
|
+
```
|
49
|
+
- Test files are colocated with their modules (e.g., `AuthContext.test.tsx`).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
- Add new core logic, hooks, or components to `/lib`.
|
54
|
+
- Add or update exports in `lib/index.ts`.
|
55
|
+
- Use `/src` and `/public` for local-only demo/testing code.
|
56
|
+
- Write and run tests for all exported logic.
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
MIT
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@caseparts-org/casecore",
|
3
3
|
"private": false,
|
4
|
-
"version": "0.0.
|
4
|
+
"version": "0.0.3",
|
5
5
|
"type": "module",
|
6
6
|
"main": "dist/index.js",
|
7
7
|
"types": "dist/index.d.ts",
|
@@ -29,7 +29,8 @@
|
|
29
29
|
"dependencies": {
|
30
30
|
"jwt-decode": "^4.0.0",
|
31
31
|
"react": "^18.0.0",
|
32
|
-
"react-dom": "^18.0.0"
|
32
|
+
"react-dom": "^18.0.0",
|
33
|
+
"uuid": "^11.1.0"
|
33
34
|
},
|
34
35
|
"devDependencies": {
|
35
36
|
"@eslint/js": "^9.29.0",
|