Skip to content

Commit 7ae3fd1

Browse files
intel352Copilot
andauthored
docs: add README and CI/CD workflows (#5)
* docs: add comprehensive README.md Closes #1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: add CI and publish GitHub Actions workflows Closes #2 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ffb8688 commit 7ae3fd1

3 files changed

Lines changed: 288 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
- uses: actions/setup-node@v4
1616
with:
17-
node-version: '20'
17+
node-version: '22'
1818
cache: 'npm'
1919

2020
- run: npm ci

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
- uses: actions/setup-node@v4
1818
with:
19-
node-version: '20'
19+
node-version: '22'
2020
registry-url: 'https://npm.pkg.github.com'
2121
scope: '@gocodealone'
2222

README.md

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
# @gocodealone/workflow-ui
2+
3+
A shared React component library providing UI utilities for workflow orchestration applications. Built with React 19, TypeScript, and Zustand.
4+
5+
## Features
6+
7+
- 🎨 **Theme System** — Catppuccin Mocha color palette with pre-styled components
8+
- 🔐 **Authentication** — Configurable Zustand auth store with LoginPage component
9+
- 🌐 **API Client** — Shared fetch wrapper with auth token injection
10+
- 📡 **SSE Support** — Server-Sent Events connection utility
11+
-**TypeScript** — Full type safety with TypeScript 5.9
12+
- 📦 **Tree-shakeable** — Modular exports for optimal bundle size
13+
14+
## Installation
15+
16+
This package is published to GitHub Packages. Configure npm to use GitHub Packages for the `@gocodealone` scope:
17+
18+
```bash
19+
# Add to your .npmrc
20+
@gocodealone:registry=https://npm.pkg.github.com
21+
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN
22+
```
23+
24+
Then install:
25+
26+
```bash
27+
npm install @gocodealone/workflow-ui
28+
```
29+
30+
## Quick Start
31+
32+
### Theme
33+
34+
Use the Catppuccin Mocha color palette and pre-styled base components:
35+
36+
```tsx
37+
import { colors, statusColors, baseStyles } from '@gocodealone/workflow-ui/theme';
38+
39+
function App() {
40+
return (
41+
<div style={baseStyles.container}>
42+
<div style={baseStyles.card}>
43+
<h1 style={{ color: colors.blue }}>Hello World</h1>
44+
<button style={baseStyles.button.primary}>
45+
Click Me
46+
</button>
47+
</div>
48+
</div>
49+
);
50+
}
51+
```
52+
53+
### API Client
54+
55+
Configure once at app startup, then use the typed HTTP methods:
56+
57+
```tsx
58+
import { configureApi, apiGet, apiPost } from '@gocodealone/workflow-ui/api';
59+
60+
// Configure at app root
61+
configureApi({
62+
baseUrl: '/api/v1',
63+
onResponseError: (status) => {
64+
if (status === 401) {
65+
// Handle unauthorized
66+
}
67+
},
68+
});
69+
70+
// Use anywhere
71+
const data = await apiGet<User[]>('/users');
72+
await apiPost('/users', { name: 'Alice' });
73+
```
74+
75+
### Authentication
76+
77+
Create an auth store and use the LoginPage component:
78+
79+
```tsx
80+
import { createAuthStore, LoginPage } from '@gocodealone/workflow-ui/auth';
81+
82+
// Create store (once at module scope)
83+
export const useAuthStore = createAuthStore({
84+
loginPath: '/auth/login',
85+
mePath: '/auth/me',
86+
});
87+
88+
// Use in your app
89+
function App() {
90+
const { isAuthenticated, login, error } = useAuthStore();
91+
92+
if (!isAuthenticated) {
93+
return (
94+
<LoginPage
95+
title="My App"
96+
subtitle="Sign in to continue"
97+
onLogin={login}
98+
error={error}
99+
/>
100+
);
101+
}
102+
103+
return <div>Authenticated!</div>;
104+
}
105+
```
106+
107+
### Server-Sent Events
108+
109+
Connect to SSE endpoints with automatic auth token handling:
110+
111+
```tsx
112+
import { connectSSE } from '@gocodealone/workflow-ui/sse';
113+
import { useEffect } from 'react';
114+
115+
function EventListener() {
116+
useEffect(() => {
117+
const es = connectSSE({
118+
url: '/events',
119+
onEvent: (event) => {
120+
console.log('Received:', event.type, event.data);
121+
},
122+
onError: (err) => console.error('SSE error:', err),
123+
});
124+
125+
return () => es.close();
126+
}, []);
127+
128+
return <div>Listening for events...</div>;
129+
}
130+
```
131+
132+
## API Reference
133+
134+
### `/theme`
135+
136+
#### `colors`
137+
Catppuccin Mocha color palette with semantic naming:
138+
- Base colors: `base`, `mantle`, `crust`, `surface0-2`, `overlay0-2`
139+
- Text colors: `text`, `subtext0-1`
140+
- Accent colors: `blue`, `green`, `yellow`, `red`, `mauve`, `pink`, etc.
141+
142+
#### `statusColors`
143+
Status-to-color mappings for common states:
144+
```typescript
145+
statusColors.active // green
146+
statusColors.error // red
147+
statusColors.pending // yellow
148+
```
149+
150+
#### `baseStyles`
151+
Pre-styled component objects:
152+
- `baseStyles.container` — Full-height page container
153+
- `baseStyles.card` — Card with border and padding
154+
- `baseStyles.input` — Text input
155+
- `baseStyles.button.primary` — Primary action button
156+
- `baseStyles.button.secondary` — Secondary button
157+
- `baseStyles.button.danger` — Destructive action button
158+
- `baseStyles.table`, `baseStyles.th`, `baseStyles.td` — Table styles
159+
160+
### `/api`
161+
162+
#### `configureApi(config: ApiClientConfig)`
163+
Configure the API client. Call once at app startup.
164+
165+
**Config options:**
166+
- `baseUrl?: string` — Base URL prefix (default: `/api`)
167+
- `getToken?: () => string | null` — Token retrieval function
168+
- `onResponseError?: (status: number, body: string) => void` — Error handler
169+
170+
#### HTTP Methods
171+
All methods return typed promises and inject auth tokens automatically:
172+
- `apiGet<T>(path: string): Promise<T>`
173+
- `apiPost<T>(path: string, body?: unknown): Promise<T>`
174+
- `apiPut<T>(path: string, body?: unknown): Promise<T>`
175+
- `apiPatch<T>(path: string, body: unknown): Promise<T>`
176+
- `apiDelete<T>(path: string): Promise<T>`
177+
178+
### `/auth`
179+
180+
#### `createAuthStore(config?: AuthStoreConfig)`
181+
Factory function to create a Zustand auth store.
182+
183+
**Config options:**
184+
- `loginPath?: string` — Login endpoint (default: `/auth/login`)
185+
- `mePath?: string` — User profile endpoint (default: `/auth/me`)
186+
- `tokenKey?: string` — localStorage key (default: `auth_token`)
187+
- `parseLoginResponse?: (data: unknown) => { token: string; user?: BaseUser }`
188+
- `buildLoginBody?: (username: string, password: string) => unknown`
189+
- `onLogout?: (token: string | null) => void`
190+
191+
**Store interface:**
192+
```typescript
193+
interface BaseAuthState {
194+
token: string | null;
195+
user: BaseUser | null;
196+
isAuthenticated: boolean;
197+
isLoading: boolean;
198+
error: string | null;
199+
login: (username: string, password: string) => Promise<void>;
200+
logout: () => void;
201+
loadUser: () => Promise<void>;
202+
clearError: () => void;
203+
}
204+
```
205+
206+
#### `LoginPage` Component
207+
Pre-styled login form using theme system.
208+
209+
**Props:**
210+
```typescript
211+
interface LoginPageProps {
212+
title: string;
213+
subtitle?: string;
214+
usernameLabel?: string;
215+
usernameType?: string;
216+
usernamePlaceholder?: string;
217+
onLogin: (username: string, password: string) => Promise<void>;
218+
error?: string | null;
219+
style?: CSSProperties;
220+
}
221+
```
222+
223+
### `/sse`
224+
225+
#### `connectSSE(config: SSEConfig): EventSource`
226+
Connect to a Server-Sent Events endpoint. Returns the EventSource instance.
227+
228+
**Config:**
229+
```typescript
230+
interface SSEConfig {
231+
url?: string; // Default: '/events'
232+
withAuth?: boolean; // Default: true
233+
tokenKey?: string; // Default: 'auth_token'
234+
onEvent: (event: { type: string; data: unknown }) => void;
235+
onError?: (event: Event) => void;
236+
}
237+
```
238+
239+
## Development
240+
241+
### Setup
242+
243+
```bash
244+
npm install
245+
```
246+
247+
### Build
248+
249+
```bash
250+
npm run build
251+
```
252+
253+
Output: `dist/` with ESM, CJS, and type definitions.
254+
255+
### Test
256+
257+
```bash
258+
npm test # Run once
259+
npm run test:watch # Watch mode
260+
```
261+
262+
### Lint
263+
264+
```bash
265+
npm run lint
266+
```
267+
268+
### Local Development
269+
270+
Link locally for testing in other projects:
271+
272+
```bash
273+
npm link
274+
cd ../your-project
275+
npm link @gocodealone/workflow-ui
276+
```
277+
278+
## Peer Dependencies
279+
280+
- `react`: ^18.0.0 || ^19.0.0
281+
- `react-dom`: ^18.0.0 || ^19.0.0
282+
- `zustand`: ^4.0.0 || ^5.0.0
283+
284+
## License
285+
286+
MIT © GoCodeAlone

0 commit comments

Comments
 (0)