netreq-auth 0.1.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.
@@ -0,0 +1,193 @@
1
+ /**
2
+ * @fileoverview Storage adapter implementations for @netreq/auth.
3
+ * Provides both in-memory and web storage (localStorage/sessionStorage) adapters.
4
+ */
5
+ /**
6
+ * In-memory storage adapter.
7
+ * Stores tokens in JavaScript memory. Data is lost on page refresh.
8
+ *
9
+ * Use this for:
10
+ * - Server-side rendering (SSR)
11
+ * - Testing environments
12
+ * - When you don't need persistence across page reloads
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { MemoryStorage } from '@netreq/auth';
17
+ *
18
+ * const auth = new AuthPlugin({
19
+ * storage: new MemoryStorage(),
20
+ * refreshEndpoint: '/auth/refresh'
21
+ * });
22
+ * ```
23
+ */
24
+ export class MemoryStorage {
25
+ tokens = null;
26
+ /**
27
+ * Retrieves tokens from memory.
28
+ * @returns Promise resolving to stored tokens or null
29
+ */
30
+ async getTokens() {
31
+ return this.tokens;
32
+ }
33
+ /**
34
+ * Stores tokens in memory.
35
+ * @param tokens - Token pair to store
36
+ */
37
+ async setTokens(tokens) {
38
+ this.tokens = tokens;
39
+ }
40
+ /**
41
+ * Clears tokens from memory.
42
+ */
43
+ async clearTokens() {
44
+ this.tokens = null;
45
+ }
46
+ }
47
+ /**
48
+ * Web Storage adapter for browsers.
49
+ * Uses localStorage or sessionStorage to persist tokens.
50
+ *
51
+ * Use this for:
52
+ * - Browser applications requiring token persistence
53
+ * - Remember me functionality (localStorage)
54
+ * - Session-only persistence (sessionStorage)
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * import { WebStorage } from '@netreq/auth';
59
+ *
60
+ * // Use localStorage (persists across browser sessions)
61
+ * const auth = new AuthPlugin({
62
+ * storage: new WebStorage('localStorage', 'myapp_tokens'),
63
+ * refreshEndpoint: '/auth/refresh'
64
+ * });
65
+ *
66
+ * // Use sessionStorage (cleared when tab closes)
67
+ * const authSession = new AuthPlugin({
68
+ * storage: new WebStorage('sessionStorage', 'myapp_tokens'),
69
+ * refreshEndpoint: '/auth/refresh'
70
+ * });
71
+ * ```
72
+ */
73
+ export class WebStorage {
74
+ storage;
75
+ key;
76
+ /**
77
+ * Creates a new WebStorage instance.
78
+ *
79
+ * @param storageType - Type of web storage ('localStorage' or 'sessionStorage')
80
+ * @param key - Storage key name (default: 'netreq_auth_tokens')
81
+ * @throws Error if storage type is invalid or not available (SSR)
82
+ */
83
+ constructor(storageType = 'localStorage', key = 'netreq_auth_tokens') {
84
+ this.key = key;
85
+ if (typeof window === 'undefined') {
86
+ throw new Error('WebStorage is not available in server-side environment. ' +
87
+ 'Use MemoryStorage for SSR or check typeof window before creating WebStorage.');
88
+ }
89
+ const storage = window[storageType];
90
+ if (!storage) {
91
+ throw new Error(`Storage type "${storageType}" is not available in this browser`);
92
+ }
93
+ this.storage = storage;
94
+ }
95
+ /**
96
+ * Retrieves tokens from web storage.
97
+ * @returns Promise resolving to stored tokens or null
98
+ */
99
+ async getTokens() {
100
+ try {
101
+ const data = this.storage.getItem(this.key);
102
+ if (!data)
103
+ return null;
104
+ const parsed = JSON.parse(data);
105
+ return parsed;
106
+ }
107
+ catch {
108
+ // If parsing fails, clear corrupted data
109
+ this.storage.removeItem(this.key);
110
+ return null;
111
+ }
112
+ }
113
+ /**
114
+ * Stores tokens in web storage.
115
+ * @param tokens - Token pair to store
116
+ */
117
+ async setTokens(tokens) {
118
+ this.storage.setItem(this.key, JSON.stringify(tokens));
119
+ }
120
+ /**
121
+ * Clears tokens from web storage.
122
+ */
123
+ async clearTokens() {
124
+ this.storage.removeItem(this.key);
125
+ }
126
+ }
127
+ export class CookieStorage {
128
+ options;
129
+ constructor(options) {
130
+ if (typeof document === 'undefined') {
131
+ throw new Error('CookieStorage is not available in server-side environment. ' +
132
+ 'Use MemoryStorage for SSR.');
133
+ }
134
+ this.options = {
135
+ name: options.name,
136
+ path: options.path ?? '/',
137
+ expires: options.expires,
138
+ domain: options.domain,
139
+ secure: options.secure,
140
+ sameSite: options.sameSite,
141
+ };
142
+ }
143
+ /**
144
+ * Retrieves tokens from cookies.
145
+ */
146
+ async getTokens() {
147
+ const cookies = document.cookie.split(';');
148
+ const targetCookie = cookies.find(c => c.trim().startsWith(`${this.options.name}=`));
149
+ if (!targetCookie)
150
+ return null;
151
+ try {
152
+ const value = targetCookie.split('=')[1];
153
+ const decoded = decodeURIComponent(value);
154
+ return JSON.parse(decoded);
155
+ }
156
+ catch {
157
+ return null;
158
+ }
159
+ }
160
+ /**
161
+ * Stores tokens in cookies.
162
+ */
163
+ async setTokens(tokens) {
164
+ const value = encodeURIComponent(JSON.stringify(tokens));
165
+ let cookieString = `${this.options.name}=${value}; path=${this.options.path}`;
166
+ if (this.options.expires) {
167
+ const date = new Date();
168
+ date.setDate(date.getDate() + this.options.expires);
169
+ cookieString += `; expires=${date.toUTCString()}`;
170
+ }
171
+ if (this.options.domain) {
172
+ cookieString += `; domain=${this.options.domain}`;
173
+ }
174
+ if (this.options.secure) {
175
+ cookieString += '; secure';
176
+ }
177
+ if (this.options.sameSite) {
178
+ cookieString += `; samesite=${this.options.sameSite}`;
179
+ }
180
+ document.cookie = cookieString;
181
+ }
182
+ /**
183
+ * Clears tokens from cookies.
184
+ */
185
+ async clearTokens() {
186
+ let cookieString = `${this.options.name}=; path=${this.options.path}; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
187
+ if (this.options.domain) {
188
+ cookieString += `; domain=${this.options.domain}`;
189
+ }
190
+ document.cookie = cookieString;
191
+ }
192
+ }
193
+ //# sourceMappingURL=Storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Storage.js","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,aAAa;IAChB,MAAM,GAAqB,IAAI,CAAC;IAExC;;;OAGG;IACH,KAAK,CAAC,SAAS;QACb,OA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AC,OAAO,CAAC,IAAI,yCAAyC,CAAC;QAE7G,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACxB,YAAY,IAAI,YAAY,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpD,CAAC;QAED,QAAQ,CAAC,MAAM,GAAG,YAAY,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @fileoverview Main entry point for @netreq/auth.
3
+ * Authentication plugin for netreq HTTP client with JWT support,
4
+ * automatic token refresh, and flexible storage adapters.
5
+ */
6
+ export { Auth, } from './Auth.js';
7
+ export { MemoryStorage, WebStorage, CookieStorage, } from './Storage.js';
8
+ export type { TokenPair, TokenStorage, SessionEvent, SessionEventListener, AuthPluginOptions, QueuedRequest, AuthState, LoginCredentials, LoginResult, CookieOptions, } from './types.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,IAAI,GACL,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,aAAa,EACb,UAAU,EACV,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @fileoverview Main entry point for @netreq/auth.
3
+ * Authentication plugin for netreq HTTP client with JWT support,
4
+ * automatic token refresh, and flexible storage adapters.
5
+ */
6
+ export { Auth, } from './Auth.js';
7
+ export { MemoryStorage, WebStorage, CookieStorage, } from './Storage.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,IAAI,GACL,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,aAAa,EACb,UAAU,EACV,aAAa,GACd,MAAM,cAAc,CAAC"}
@@ -0,0 +1,218 @@
1
+ /**
2
+ * @fileoverview Core type definitions for @netreq/auth.
3
+ * Defines interfaces for storage adapters, token management, and plugin configuration.
4
+ */
5
+ /**
6
+ * Token pair structure containing both access and refresh tokens.
7
+ * Access token is used for API authentication.
8
+ * Refresh token is used to obtain a new access token when it expires.
9
+ */
10
+ export interface TokenPair {
11
+ /** JWT access token for API authentication */
12
+ accessToken: string;
13
+ /** Refresh token to obtain new access token */
14
+ refreshToken: string;
15
+ /** Token expiration timestamp (Unix timestamp in milliseconds) */
16
+ expiresAt?: number;
17
+ }
18
+ /**
19
+ * Storage adapter interface for token persistence.
20
+ * Implement this interface to create custom storage solutions
21
+ * (e.g., encrypted storage, cookie-based storage).
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * class SecureStorage implements TokenStorage {
26
+ * async getTokens(): Promise<TokenPair | null> {
27
+ * const encrypted = await decryptFromStorage();
28
+ * return encrypted;
29
+ * }
30
+ * // ... implement other methods
31
+ * }
32
+ * ```
33
+ */
34
+ export interface TokenStorage {
35
+ /**
36
+ * Retrieves stored tokens from storage.
37
+ * @returns Promise resolving to token pair or null if not found
38
+ */
39
+ getTokens(): Promise<TokenPair | null>;
40
+ /**
41
+ * Stores tokens in storage.
42
+ * @param tokens - Token pair to store
43
+ * @returns Promise that resolves when storage is complete
44
+ */
45
+ setTokens(tokens: TokenPair): Promise<void>;
46
+ /**
47
+ * Removes all tokens from storage (logout).
48
+ * @returns Promise that resolves when removal is complete
49
+ */
50
+ clearTokens(): Promise<void>;
51
+ }
52
+ /**
53
+ * Session state change event types.
54
+ */
55
+ export type SessionEvent = 'login' | 'logout' | 'refresh' | 'expired';
56
+ /**
57
+ * Session state event listener callback type.
58
+ */
59
+ export type SessionEventListener = (event: SessionEvent, tokens?: TokenPair) => void;
60
+ /**
61
+ * Authentication plugin configuration options.
62
+ */
63
+ export interface AuthPluginOptions {
64
+ /**
65
+ * Storage adapter for token persistence.
66
+ * Defaults to MemoryStorage for Node.js/SSR, LocalStorage for browsers.
67
+ */
68
+ storage?: TokenStorage;
69
+ /**
70
+ * URL endpoint for token refresh.
71
+ * This endpoint should accept refresh token and return new token pair.
72
+ * @example '/auth/refresh' or 'https://api.example.com/auth/refresh'
73
+ */
74
+ refreshEndpoint: string;
75
+ /**
76
+ * HTTP method for refresh request.
77
+ * @default 'POST'
78
+ */
79
+ refreshMethod?: 'POST' | 'GET' | 'PUT';
80
+ /**
81
+ * Function to extract token pair from refresh response.
82
+ * Use this if your API returns tokens in a non-standard format.
83
+ *
84
+ * @default (response) => response (assumes response is TokenPair)
85
+ * @example
86
+ * ```typescript
87
+ * extractTokenPair: (response) => ({
88
+ * accessToken: response.data.access_token,
89
+ * refreshToken: response.data.refresh_token,
90
+ * expiresAt: Date.now() + response.data.expires_in * 1000
91
+ * })
92
+ * ```
93
+ */
94
+ extractTokenPair?: (response: unknown) => TokenPair;
95
+ /**
96
+ * Function to build refresh request body.
97
+ * Use this if your API expects refresh token in a specific format.
98
+ *
99
+ * @default (refreshToken) => ({ refreshToken })
100
+ */
101
+ buildRefreshBody?: (refreshToken: string) => unknown;
102
+ /**
103
+ * Request headers to include with refresh requests.
104
+ * Useful for adding content-type or custom headers.
105
+ *
106
+ * @default { 'Content-Type': 'application/json' }
107
+ */
108
+ refreshHeaders?: Record<string, string>;
109
+ /**
110
+ * Header name for authorization token.
111
+ * @default 'Authorization'
112
+ */
113
+ authHeaderName?: string;
114
+ /**
115
+ * Token prefix for authorization header.
116
+ * @default 'Bearer '
117
+ */
118
+ tokenPrefix?: string;
119
+ /**
120
+ * Called when user successfully logs in.
121
+ */
122
+ onLogin?: SessionEventListener;
123
+ /**
124
+ * Called when user logs out.
125
+ */
126
+ onLogout?: SessionEventListener;
127
+ /**
128
+ * Called when session expires and refresh fails.
129
+ * Use this to redirect to login page.
130
+ */
131
+ onSessionExpired?: SessionEventListener;
132
+ /**
133
+ * Called when tokens are successfully refreshed.
134
+ */
135
+ onTokenRefreshed?: SessionEventListener;
136
+ /**
137
+ * Maximum number of refresh retry attempts.
138
+ * @default 3
139
+ */
140
+ maxRefreshRetries?: number;
141
+ /**
142
+ * Timeout for refresh requests in milliseconds.
143
+ * @default 10000
144
+ */
145
+ refreshTimeout?: number;
146
+ /**
147
+ * Custom fetch implementation for refresh requests.
148
+ * Useful for testing or custom fetch wrappers.
149
+ */
150
+ fetch?: typeof fetch;
151
+ }
152
+ /**
153
+ * Internal queue item for pending requests during token refresh.
154
+ * @internal
155
+ */
156
+ export interface QueuedRequest {
157
+ /** Unique request identifier */
158
+ id: string;
159
+ /** Request configuration */
160
+ config: {
161
+ path: string;
162
+ method?: string;
163
+ headers?: Record<string, string>;
164
+ body?: unknown;
165
+ };
166
+ /** Resolve function for the request promise */
167
+ resolve: (value: unknown) => void;
168
+ /** Reject function for the request promise */
169
+ reject: (reason?: Error) => void;
170
+ }
171
+ /**
172
+ * Authentication state managed by the plugin.
173
+ * @internal
174
+ */
175
+ export interface AuthState {
176
+ /** Currently active access token */
177
+ accessToken: string | null;
178
+ /** Currently active refresh token */
179
+ refreshToken: string | null;
180
+ /** Whether a token refresh is currently in progress */
181
+ isRefreshing: boolean;
182
+ /** Queue of requests waiting for token refresh */
183
+ refreshQueue: QueuedRequest[];
184
+ /** Number of consecutive refresh failures */
185
+ refreshRetryCount: number;
186
+ }
187
+ /**
188
+ * Login credentials structure.
189
+ */
190
+ export interface LoginCredentials {
191
+ [key: string]: string | number | boolean | undefined;
192
+ }
193
+ /**
194
+ * Login function response.
195
+ */
196
+ export interface LoginResult {
197
+ success: boolean;
198
+ error?: string;
199
+ tokens?: TokenPair;
200
+ }
201
+ /**
202
+ * Cookie storage configuration options.
203
+ */
204
+ export interface CookieOptions {
205
+ /** Cookie name */
206
+ name: string;
207
+ /** Cookie expiration in days */
208
+ expires?: number;
209
+ /** Cookie path */
210
+ path?: string;
211
+ /** Cookie domain */
212
+ domain?: string;
213
+ /** Whether cookie requires HTTPS */
214
+ secure?: boolean;
215
+ /** SameSite attribute */
216
+ sameSite?: 'strict' | 'lax' | 'none';
217
+ }
218
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,SAAS,IAAI,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAEvC;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5C;;;OAGG;IACH,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,QAAQ,GACR,SAAS,GACT,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;AAErF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IAEvB;;;;OAIG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;IAEvC;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CA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AI,CAAC;IAC3B,qCAAqC;IACrC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,uDAAuD;IACvD,YAAY,EAAE,OAAO,CAAC;IACtB,kDAAkD;IAClD,YAAY,EAAE,aAAa,EAAE,CAAC;IAC9B,6CAA6C;IAC7C,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oBAAoB;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CACtC"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @fileoverview Core type definitions for @netreq/auth.
3
+ * Defines interfaces for storage adapters, token management, and plugin configuration.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "netreq-auth",
3
+ "version": "0.1.1",
4
+ "description": "Authentication plugin for netreq. JWT token management with automatic refresh and storage adapters.",
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
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "typecheck": "tsc --noEmit",
21
+ "lint": "tsc --noEmit"
22
+ },
23
+ "keywords": [
24
+ "netreq",
25
+ "auth",
26
+ "jwt",
27
+ "authentication",
28
+ "http",
29
+ "client",
30
+ "token",
31
+ "refresh",
32
+ "interceptor",
33
+ "typescript",
34
+ "zero-dependency"
35
+ ],
36
+ "author": "",
37
+ "license": "MIT",
38
+ "engines": {
39
+ "node": ">=18.0.0"
40
+ },
41
+ "peerDependencies": {
42
+ "netreq": ">=0.1.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^20.0.0",
46
+ "typescript": "^5.0.0",
47
+ "netreq": "file:../.."
48
+ }
49
+ }