@caseparts-org/casecore 0.0.1

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 ADDED
@@ -0,0 +1,69 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## Expanding the ESLint configuration
11
+
12
+ If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
13
+
14
+ ```js
15
+ export default tseslint.config([
16
+ globalIgnores(['dist']),
17
+ {
18
+ files: ['**/*.{ts,tsx}'],
19
+ extends: [
20
+ // Other configs...
21
+
22
+ // Remove tseslint.configs.recommended and replace with this
23
+ ...tseslint.configs.recommendedTypeChecked,
24
+ // Alternatively, use this for stricter rules
25
+ ...tseslint.configs.strictTypeChecked,
26
+ // Optionally, add this for stylistic rules
27
+ ...tseslint.configs.stylisticTypeChecked,
28
+
29
+ // Other configs...
30
+ ],
31
+ languageOptions: {
32
+ parserOptions: {
33
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
34
+ tsconfigRootDir: import.meta.dirname,
35
+ },
36
+ // other options...
37
+ },
38
+ },
39
+ ])
40
+ ```
41
+
42
+ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
43
+
44
+ ```js
45
+ // eslint.config.js
46
+ import reactX from 'eslint-plugin-react-x'
47
+ import reactDom from 'eslint-plugin-react-dom'
48
+
49
+ export default tseslint.config([
50
+ globalIgnores(['dist']),
51
+ {
52
+ files: ['**/*.{ts,tsx}'],
53
+ extends: [
54
+ // Other configs...
55
+ // Enable lint rules for React
56
+ reactX.configs['recommended-typescript'],
57
+ // Enable lint rules for React DOM
58
+ reactDom.configs.recommended,
59
+ ],
60
+ languageOptions: {
61
+ parserOptions: {
62
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
63
+ tsconfigRootDir: import.meta.dirname,
64
+ },
65
+ // other options...
66
+ },
67
+ },
68
+ ])
69
+ ```
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ export interface AuthContextValue {
3
+ initialized: string;
4
+ login: (email: string, password: string) => void;
5
+ }
6
+ export declare const useAuthContext: () => AuthContextValue;
7
+ export interface AuthProviderProps {
8
+ children: React.ReactNode;
9
+ apiKey: string;
10
+ loginUrl: string;
11
+ }
12
+ export declare const AuthProvider: React.FC<AuthProviderProps>;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useState } from "react";
3
+ const AuthContext = createContext(undefined);
4
+ export const useAuthContext = () => {
5
+ const ctx = useContext(AuthContext);
6
+ if (!ctx)
7
+ throw new Error("Must be inside AuthProvider");
8
+ return ctx;
9
+ };
10
+ export const AuthProvider = ({ children, apiKey, loginUrl, }) => {
11
+ const [initialized, setInitialized] = useState("OK");
12
+ const login = (email, password) => {
13
+ console.log({ email, password });
14
+ };
15
+ console.log(apiKey);
16
+ console.log(loginUrl);
17
+ return (_jsx(AuthContext.Provider, { value: { initialized, login }, children: children }));
18
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { describe, it, expect } from 'vitest';
3
+ import { render, screen } from '@testing-library/react';
4
+ import { AuthProvider, useAuthContext } from './AuthContext';
5
+ /**
6
+ * Dummy component to consume the AuthContext
7
+ */
8
+ function ShowAuthState() {
9
+ const { initialized } = useAuthContext();
10
+ return _jsx("span", { "data-testid": "auth-state", children: initialized });
11
+ }
12
+ describe('AuthContext', () => {
13
+ it('provides initialized state to children', () => {
14
+ render(_jsx(AuthProvider, { loginUrl: '/login', apiKey: '123', children: _jsx(ShowAuthState, {}) }));
15
+ // The initial state should be "OK"
16
+ expect(screen.getByTestId('auth-state')).toHaveTextContent('OK');
17
+ });
18
+ it('throws error if used outside AuthProvider', () => {
19
+ // Expect the hook to throw if used outside the provider
20
+ // (React Testing Library can't render hooks directly; need to use a component)
21
+ // We'll use a function to capture the error:
22
+ function CallWithoutProvider() {
23
+ useAuthContext();
24
+ return null;
25
+ }
26
+ // Wrap in a function to capture the thrown error
27
+ expect(() => render(_jsx(CallWithoutProvider, {}))).toThrow(/Must be inside AuthProvider/);
28
+ });
29
+ });
@@ -0,0 +1,2 @@
1
+ export type { AuthContextValue, AuthProviderProps } from './authentication/AuthContext';
2
+ export { useAuthContext, AuthProvider } from './authentication/AuthContext';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { useAuthContext, AuthProvider } from './authentication/AuthContext';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@caseparts-org/casecore",
3
+ "private": false,
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "peerDependencies": {
19
+ "react": "^18.0.0"
20
+ },
21
+ "scripts": {
22
+ "dev": "vite",
23
+ "build": "tsc -p tsconfig.json",
24
+ "lint": "eslint .",
25
+ "preview": "vite preview",
26
+ "test": "vitest",
27
+ "test:ci": "vitest run"
28
+ },
29
+ "dependencies": {
30
+ "jwt-decode": "^4.0.0",
31
+ "react": "^18.0.0",
32
+ "react-dom": "^18.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@eslint/js": "^9.29.0",
36
+ "@testing-library/jest-dom": "^6.6.3",
37
+ "@testing-library/react": "^16.3.0",
38
+ "@types/node": "^24.0.4",
39
+ "@types/react": "^19.1.8",
40
+ "@types/react-dom": "^19.1.6",
41
+ "@vitejs/plugin-react": "^4.5.2",
42
+ "eslint": "^9.29.0",
43
+ "eslint-plugin-react-hooks": "^5.2.0",
44
+ "eslint-plugin-react-refresh": "^0.4.20",
45
+ "globals": "^16.2.0",
46
+ "jsdom": "^26.1.0",
47
+ "typescript": "~5.8.3",
48
+ "typescript-eslint": "^8.34.1",
49
+ "vite": "^7.0.0",
50
+ "vitest": "^3.2.4"
51
+ }
52
+ }