authfort-client 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/CLAUDE.md ADDED
@@ -0,0 +1,45 @@
1
+ # AuthFort Client — AI Reference
2
+
3
+ ## Commands (User Runs These)
4
+
5
+ ```bash
6
+ # Install dependencies
7
+ npm install
8
+
9
+ # Build
10
+ npm run build
11
+
12
+ # Watch mode
13
+ npm run dev
14
+ ```
15
+
16
+ ## Structure
17
+
18
+ ```
19
+ client/
20
+ ├── package.json
21
+ ├── tsconfig.json
22
+ └── src/
23
+ ├── index.ts # Public API exports
24
+ ├── types.ts # TypeScript interfaces
25
+ ├── client.ts # createAuthClient factory
26
+ ├── token-manager.ts # Token lifecycle (refresh, dedup)
27
+ ├── react/index.ts # React hooks (useAuth)
28
+ ├── vue/index.ts # Vue composables
29
+ └── svelte/index.ts # Svelte stores
30
+ ```
31
+
32
+ ## Purpose
33
+
34
+ TypeScript SDK for frontend apps. Handles:
35
+ - Token storage and retrieval
36
+ - Proactive refresh (30s before expiry)
37
+ - Refresh promise deduplication (concurrent calls share one refresh)
38
+ - 401 retry (for immediate role invalidation)
39
+ - Auth state management (authenticated/unauthenticated/loading)
40
+
41
+ ## Constraints
42
+
43
+ - **No server-side code** — this is a client-side SDK
44
+ - **Framework-agnostic core** — React/Vue/Svelte are optional exports
45
+ - **Never store tokens insecurely** — httponly cookies for web, secure storage guidance for mobile
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "authfort-client",
3
+ "version": "0.0.1",
4
+ "description": "TypeScript client SDK for AuthFort authentication",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./react": {
14
+ "import": "./dist/react/index.js",
15
+ "types": "./dist/react/index.d.ts"
16
+ },
17
+ "./vue": {
18
+ "import": "./dist/vue/index.js",
19
+ "types": "./dist/vue/index.d.ts"
20
+ },
21
+ "./svelte": {
22
+ "import": "./dist/svelte/index.js",
23
+ "types": "./dist/svelte/index.d.ts"
24
+ }
25
+ },
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "dev": "tsc --watch"
29
+ },
30
+ "keywords": [],
31
+ "author": "",
32
+ "license": "ISC",
33
+ "devDependencies": {
34
+ "typescript": "^5.9.3"
35
+ }
36
+ }
package/src/client.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * AuthFort client factory — creates an auth client instance.
3
+ */
4
+
5
+ import type { AuthClientConfig, AuthClient } from './types';
6
+
7
+ export function createAuthClient(_config: AuthClientConfig): AuthClient {
8
+ // TODO: Implement in Phase 4
9
+ throw new Error('Not yet implemented');
10
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * AuthFort Client — TypeScript SDK for AuthFort authentication.
3
+ *
4
+ * Handles token lifecycle, proactive refresh, and authenticated requests.
5
+ */
6
+
7
+ export { createAuthClient } from './client';
8
+ export type { AuthClientConfig, AuthClient, AuthState, AuthUser } from './types';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * React hooks for AuthFort.
3
+ *
4
+ * Provides useAuth() and useSession() hooks.
5
+ */
@@ -0,0 +1,3 @@
1
+ /**
2
+ * Svelte stores for AuthFort.
3
+ */
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Token lifecycle manager.
3
+ *
4
+ * Handles:
5
+ * - Proactive refresh (before expiry)
6
+ * - Single refresh promise deduplication
7
+ * - Token storage
8
+ */
package/src/types.ts ADDED
@@ -0,0 +1,51 @@
1
+ /** Configuration for creating an AuthFort client. */
2
+ export interface AuthClientConfig {
3
+ /** Base URL of the auth server (e.g., "https://myapp.com/auth") */
4
+ baseUrl: string;
5
+
6
+ /** Token delivery mode */
7
+ tokenMode?: 'cookie' | 'bearer' | 'both';
8
+
9
+ /** Seconds before expiry to trigger proactive refresh (default: 30) */
10
+ refreshBuffer?: number;
11
+ }
12
+
13
+ /** Authentication state */
14
+ export type AuthState = 'authenticated' | 'unauthenticated' | 'loading';
15
+
16
+ /** Authenticated user data */
17
+ export interface AuthUser {
18
+ id: string;
19
+ email: string;
20
+ name?: string;
21
+ roles: string[];
22
+ emailVerified: boolean;
23
+ avatarUrl?: string;
24
+ }
25
+
26
+ /** Auth client interface */
27
+ export interface AuthClient {
28
+ /** Get a valid access token (refreshes if needed) */
29
+ getToken(): Promise<string>;
30
+
31
+ /** Make an authenticated fetch request (auto-attaches token, handles 401 retry) */
32
+ fetch(url: string, options?: RequestInit): Promise<Response>;
33
+
34
+ /** Get current user data */
35
+ getUser(): Promise<AuthUser>;
36
+
37
+ /** Sign up with email and password */
38
+ signUp(data: { email: string; password: string; name?: string }): Promise<AuthUser>;
39
+
40
+ /** Sign in with email and password */
41
+ signIn(data: { email: string; password: string }): Promise<AuthUser>;
42
+
43
+ /** Sign in with OAuth provider (redirects) */
44
+ signInWithProvider(provider: string): void;
45
+
46
+ /** Sign out */
47
+ signOut(): Promise<void>;
48
+
49
+ /** Subscribe to auth state changes */
50
+ onAuthStateChange(callback: (state: AuthState) => void): () => void;
51
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Vue composables for AuthFort.
3
+ *
4
+ * Provides useAuth() and useSession() composables.
5
+ */
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2020", "DOM"],
7
+ "outDir": "dist",
8
+ "rootDir": "src",
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "strict": true,
13
+ "esModuleInterop": true,
14
+ "skipLibCheck": true,
15
+ "forceConsistentCasingInFileNames": true,
16
+ "isolatedModules": true,
17
+ "jsx": "react-jsx"
18
+ },
19
+ "include": ["src"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }