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 +45 -0
- package/package.json +36 -0
- package/src/client.ts +10 -0
- package/src/index.ts +8 -0
- package/src/react/index.ts +5 -0
- package/src/svelte/index.ts +3 -0
- package/src/token-manager.ts +8 -0
- package/src/types.ts +51 -0
- package/src/vue/index.ts +5 -0
- package/tsconfig.json +21 -0
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';
|
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
|
+
}
|
package/src/vue/index.ts
ADDED
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
|
+
}
|