@qyh213/easyauth-client 1.0.0-beta.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,300 @@
1
+ /**
2
+ * Easy Auth Client - Type Definitions
3
+ */
4
+ interface EasyAuthConfig {
5
+ /** Base URL of the Easy Auth service */
6
+ baseUrl: string;
7
+ /** API Key for admin operations (keep secret!) */
8
+ apiKey?: string;
9
+ /** Default token expiration in hours */
10
+ defaultTokenExpiry?: number;
11
+ }
12
+ interface LoginCredentials {
13
+ email: string;
14
+ password: string;
15
+ /** Token expiration in hours (overrides default) */
16
+ expiresInHours?: number;
17
+ /** Scopes to request for the token */
18
+ scopes?: string[];
19
+ }
20
+ interface AuthToken {
21
+ accessToken: string;
22
+ tokenType: "Bearer";
23
+ expiresIn: number;
24
+ expiresAt: string;
25
+ userId: string;
26
+ email: string;
27
+ scopes?: string[];
28
+ }
29
+ interface ValidationResult {
30
+ valid: boolean;
31
+ type?: "token" | "api_key";
32
+ serviceId?: string;
33
+ scope?: "admin" | "service" | "user";
34
+ scopes?: string[];
35
+ userId?: string;
36
+ email?: string;
37
+ keyId?: string;
38
+ error?: string;
39
+ }
40
+ interface IntrospectRequest {
41
+ serviceId: string;
42
+ /** Either token or apiKey must be provided */
43
+ token?: string;
44
+ apiKey?: string;
45
+ /** Required scopes to check */
46
+ requiredScopes?: string[];
47
+ }
48
+ interface IntrospectResponse {
49
+ valid: boolean;
50
+ type?: "bearer" | "api_key";
51
+ userId?: string;
52
+ email?: string;
53
+ scopes?: string[];
54
+ keyId?: string;
55
+ error?: string;
56
+ required?: string[];
57
+ provided?: string[];
58
+ }
59
+ interface User {
60
+ userId: string;
61
+ email: string;
62
+ createdAt: string;
63
+ }
64
+ interface CreateUserRequest {
65
+ email: string;
66
+ password: string;
67
+ userId?: string;
68
+ scopes?: string[];
69
+ }
70
+ interface UserListResponse {
71
+ users: User[];
72
+ }
73
+ interface ApiKey {
74
+ keyId: string;
75
+ name: string;
76
+ scope: string;
77
+ scopes: Scope[];
78
+ keyType: string;
79
+ tpsLimit: number;
80
+ revoked: boolean;
81
+ createdAt: string;
82
+ }
83
+ interface CreateApiKeyRequest {
84
+ name: string;
85
+ scope?: string;
86
+ /** Custom granular scopes */
87
+ scopes?: string[];
88
+ keyType?: string;
89
+ tpsLimit?: number;
90
+ }
91
+ interface CreateApiKeyResponse {
92
+ keyId: string;
93
+ apiKey: string;
94
+ name: string;
95
+ scope: string;
96
+ scopes: string[];
97
+ }
98
+ interface Scope {
99
+ scopeId: string;
100
+ name: string;
101
+ key: string;
102
+ description?: string;
103
+ createdAt: string;
104
+ }
105
+ interface CreateScopeRequest {
106
+ name: string;
107
+ key: string;
108
+ description?: string;
109
+ }
110
+ interface Service {
111
+ serviceId: string;
112
+ serviceName: string;
113
+ ownerEmail: string;
114
+ createdAt: string;
115
+ userCount: number;
116
+ apiKeyCount: number;
117
+ webhookCount: number;
118
+ }
119
+ interface OnboardRequest {
120
+ serviceName: string;
121
+ ownerEmail: string;
122
+ }
123
+ interface OnboardResponse {
124
+ serviceId: string;
125
+ serviceName: string;
126
+ ownerEmail: string;
127
+ adminKeyId: string;
128
+ serviceAdminApiKey: string;
129
+ createdAt: string;
130
+ }
131
+ interface Webhook {
132
+ webhookId: string;
133
+ url: string;
134
+ events: string[];
135
+ active: boolean;
136
+ createdAt: string;
137
+ }
138
+ interface RegisterWebhookRequest {
139
+ url: string;
140
+ events: string[];
141
+ secret?: string;
142
+ }
143
+ declare class EasyAuthError extends Error {
144
+ code: string;
145
+ statusCode?: number | undefined;
146
+ constructor(message: string, code: string, statusCode?: number | undefined);
147
+ }
148
+ declare class ScopeError extends EasyAuthError {
149
+ requiredScopes: string[];
150
+ providedScopes: string[];
151
+ constructor(message: string, requiredScopes: string[], providedScopes: string[]);
152
+ }
153
+ interface TokenStorage {
154
+ getToken(): string | null;
155
+ setToken(token: string): void;
156
+ removeToken(): void;
157
+ }
158
+ declare class LocalStorageTokenStorage implements TokenStorage {
159
+ private static readonly KEY;
160
+ getToken(): string | null;
161
+ setToken(token: string): void;
162
+ removeToken(): void;
163
+ }
164
+ declare class MemoryTokenStorage implements TokenStorage {
165
+ private token;
166
+ getToken(): string | null;
167
+ setToken(token: string): void;
168
+ removeToken(): void;
169
+ }
170
+
171
+ /**
172
+ * Easy Auth Client - Core Client Implementation
173
+ */
174
+
175
+ declare class EasyAuthClient {
176
+ private config;
177
+ private tokenStorage;
178
+ constructor(config: EasyAuthConfig, tokenStorage?: TokenStorage);
179
+ private request;
180
+ /**
181
+ * Update the client's service configuration
182
+ */
183
+ configure(config: Partial<EasyAuthConfig>): void;
184
+ /**
185
+ * Get current configuration (without sensitive data)
186
+ */
187
+ getConfig(): Omit<EasyAuthConfig, "apiKey">;
188
+ /**
189
+ * Get the stored access token
190
+ */
191
+ getAccessToken(): string | null;
192
+ /**
193
+ * Store an access token
194
+ */
195
+ setAccessToken(token: string): void;
196
+ /**
197
+ * Remove the stored access token (logout)
198
+ */
199
+ clearAccessToken(): void;
200
+ /**
201
+ * Check if user is logged in
202
+ */
203
+ isLoggedIn(): boolean;
204
+ /**
205
+ * Introspect a token or API key and validate required scopes
206
+ */
207
+ introspect(request: IntrospectRequest): Promise<IntrospectResponse>;
208
+ /**
209
+ * Validate the current token with optional scope checking
210
+ */
211
+ validateWithScopes(requiredScopes?: string[]): Promise<ValidationResult>;
212
+ /**
213
+ * Check if the current user has all the required scopes
214
+ * Throws ScopeError if scopes are insufficient
215
+ */
216
+ requireScopes(...requiredScopes: string[]): Promise<ValidationResult>;
217
+ /**
218
+ * Execute a function only if the user has the required scopes
219
+ */
220
+ withScope<T>(scopes: string[], fn: () => Promise<T>): Promise<T>;
221
+ /**
222
+ * Login a user and store the access token
223
+ */
224
+ login(credentials: LoginCredentials): Promise<AuthToken>;
225
+ /**
226
+ * Logout the current user
227
+ */
228
+ logout(): Promise<void>;
229
+ /**
230
+ * Validate the current token or an API key
231
+ * @deprecated Use validateWithScopes instead
232
+ */
233
+ validate(_credential?: string): Promise<ValidationResult>;
234
+ /**
235
+ * Refresh the current token
236
+ */
237
+ refreshToken(): Promise<AuthToken>;
238
+ /**
239
+ * Create a new user (requires admin API key)
240
+ */
241
+ createUser(request: CreateUserRequest): Promise<User>;
242
+ /**
243
+ * List all users for the service
244
+ */
245
+ listUsers(): Promise<User[]>;
246
+ /**
247
+ * Delete a user
248
+ */
249
+ deleteUser(userId: string): Promise<void>;
250
+ /**
251
+ * Update user password
252
+ */
253
+ updatePassword(userId: string, oldPassword: string, newPassword: string): Promise<void>;
254
+ /**
255
+ * List custom scopes for the service
256
+ */
257
+ listScopes(): Promise<Scope[]>;
258
+ /**
259
+ * Create a custom scope
260
+ */
261
+ createScope(request: CreateScopeRequest): Promise<Scope>;
262
+ /**
263
+ * Delete a custom scope
264
+ */
265
+ deleteScope(scopeId: string): Promise<void>;
266
+ /**
267
+ * List all API keys for the service
268
+ */
269
+ listApiKeys(): Promise<ApiKey[]>;
270
+ /**
271
+ * Create a new API key with optional custom scopes
272
+ */
273
+ createApiKey(request: CreateApiKeyRequest): Promise<CreateApiKeyResponse>;
274
+ /**
275
+ * Revoke an API key
276
+ */
277
+ revokeApiKey(keyId: string): Promise<void>;
278
+ /**
279
+ * Onboard a new service (requires master admin key)
280
+ */
281
+ onboardService(request: OnboardRequest, masterAdminKey: string): Promise<OnboardResponse>;
282
+ /**
283
+ * Delete a service (requires master admin key)
284
+ */
285
+ deleteService(serviceId: string, masterAdminKey: string): Promise<void>;
286
+ /**
287
+ * List webhooks
288
+ */
289
+ listWebhooks(): Promise<Webhook[]>;
290
+ /**
291
+ * Register a webhook
292
+ */
293
+ registerWebhook(request: RegisterWebhookRequest): Promise<Webhook>;
294
+ /**
295
+ * Delete a webhook
296
+ */
297
+ deleteWebhook(webhookId: string): Promise<void>;
298
+ }
299
+
300
+ export { type ApiKey as A, type CreateApiKeyRequest as C, EasyAuthClient as E, type IntrospectRequest as I, LocalStorageTokenStorage as L, MemoryTokenStorage as M, type OnboardRequest as O, type RegisterWebhookRequest as R, type Scope as S, type TokenStorage as T, type User as U, type ValidationResult as V, type Webhook as W, type AuthToken as a, type CreateApiKeyResponse as b, type CreateScopeRequest as c, type CreateUserRequest as d, type EasyAuthConfig as e, EasyAuthError as f, type IntrospectResponse as g, type LoginCredentials as h, type OnboardResponse as i, ScopeError as j, type Service as k, type UserListResponse as l };
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Easy Auth Client - Type Definitions
3
+ */
4
+ interface EasyAuthConfig {
5
+ /** Base URL of the Easy Auth service */
6
+ baseUrl: string;
7
+ /** API Key for admin operations (keep secret!) */
8
+ apiKey?: string;
9
+ /** Default token expiration in hours */
10
+ defaultTokenExpiry?: number;
11
+ }
12
+ interface LoginCredentials {
13
+ email: string;
14
+ password: string;
15
+ /** Token expiration in hours (overrides default) */
16
+ expiresInHours?: number;
17
+ /** Scopes to request for the token */
18
+ scopes?: string[];
19
+ }
20
+ interface AuthToken {
21
+ accessToken: string;
22
+ tokenType: "Bearer";
23
+ expiresIn: number;
24
+ expiresAt: string;
25
+ userId: string;
26
+ email: string;
27
+ scopes?: string[];
28
+ }
29
+ interface ValidationResult {
30
+ valid: boolean;
31
+ type?: "token" | "api_key";
32
+ serviceId?: string;
33
+ scope?: "admin" | "service" | "user";
34
+ scopes?: string[];
35
+ userId?: string;
36
+ email?: string;
37
+ keyId?: string;
38
+ error?: string;
39
+ }
40
+ interface IntrospectRequest {
41
+ serviceId: string;
42
+ /** Either token or apiKey must be provided */
43
+ token?: string;
44
+ apiKey?: string;
45
+ /** Required scopes to check */
46
+ requiredScopes?: string[];
47
+ }
48
+ interface IntrospectResponse {
49
+ valid: boolean;
50
+ type?: "bearer" | "api_key";
51
+ userId?: string;
52
+ email?: string;
53
+ scopes?: string[];
54
+ keyId?: string;
55
+ error?: string;
56
+ required?: string[];
57
+ provided?: string[];
58
+ }
59
+ interface User {
60
+ userId: string;
61
+ email: string;
62
+ createdAt: string;
63
+ }
64
+ interface CreateUserRequest {
65
+ email: string;
66
+ password: string;
67
+ userId?: string;
68
+ scopes?: string[];
69
+ }
70
+ interface UserListResponse {
71
+ users: User[];
72
+ }
73
+ interface ApiKey {
74
+ keyId: string;
75
+ name: string;
76
+ scope: string;
77
+ scopes: Scope[];
78
+ keyType: string;
79
+ tpsLimit: number;
80
+ revoked: boolean;
81
+ createdAt: string;
82
+ }
83
+ interface CreateApiKeyRequest {
84
+ name: string;
85
+ scope?: string;
86
+ /** Custom granular scopes */
87
+ scopes?: string[];
88
+ keyType?: string;
89
+ tpsLimit?: number;
90
+ }
91
+ interface CreateApiKeyResponse {
92
+ keyId: string;
93
+ apiKey: string;
94
+ name: string;
95
+ scope: string;
96
+ scopes: string[];
97
+ }
98
+ interface Scope {
99
+ scopeId: string;
100
+ name: string;
101
+ key: string;
102
+ description?: string;
103
+ createdAt: string;
104
+ }
105
+ interface CreateScopeRequest {
106
+ name: string;
107
+ key: string;
108
+ description?: string;
109
+ }
110
+ interface Service {
111
+ serviceId: string;
112
+ serviceName: string;
113
+ ownerEmail: string;
114
+ createdAt: string;
115
+ userCount: number;
116
+ apiKeyCount: number;
117
+ webhookCount: number;
118
+ }
119
+ interface OnboardRequest {
120
+ serviceName: string;
121
+ ownerEmail: string;
122
+ }
123
+ interface OnboardResponse {
124
+ serviceId: string;
125
+ serviceName: string;
126
+ ownerEmail: string;
127
+ adminKeyId: string;
128
+ serviceAdminApiKey: string;
129
+ createdAt: string;
130
+ }
131
+ interface Webhook {
132
+ webhookId: string;
133
+ url: string;
134
+ events: string[];
135
+ active: boolean;
136
+ createdAt: string;
137
+ }
138
+ interface RegisterWebhookRequest {
139
+ url: string;
140
+ events: string[];
141
+ secret?: string;
142
+ }
143
+ declare class EasyAuthError extends Error {
144
+ code: string;
145
+ statusCode?: number | undefined;
146
+ constructor(message: string, code: string, statusCode?: number | undefined);
147
+ }
148
+ declare class ScopeError extends EasyAuthError {
149
+ requiredScopes: string[];
150
+ providedScopes: string[];
151
+ constructor(message: string, requiredScopes: string[], providedScopes: string[]);
152
+ }
153
+ interface TokenStorage {
154
+ getToken(): string | null;
155
+ setToken(token: string): void;
156
+ removeToken(): void;
157
+ }
158
+ declare class LocalStorageTokenStorage implements TokenStorage {
159
+ private static readonly KEY;
160
+ getToken(): string | null;
161
+ setToken(token: string): void;
162
+ removeToken(): void;
163
+ }
164
+ declare class MemoryTokenStorage implements TokenStorage {
165
+ private token;
166
+ getToken(): string | null;
167
+ setToken(token: string): void;
168
+ removeToken(): void;
169
+ }
170
+
171
+ /**
172
+ * Easy Auth Client - Core Client Implementation
173
+ */
174
+
175
+ declare class EasyAuthClient {
176
+ private config;
177
+ private tokenStorage;
178
+ constructor(config: EasyAuthConfig, tokenStorage?: TokenStorage);
179
+ private request;
180
+ /**
181
+ * Update the client's service configuration
182
+ */
183
+ configure(config: Partial<EasyAuthConfig>): void;
184
+ /**
185
+ * Get current configuration (without sensitive data)
186
+ */
187
+ getConfig(): Omit<EasyAuthConfig, "apiKey">;
188
+ /**
189
+ * Get the stored access token
190
+ */
191
+ getAccessToken(): string | null;
192
+ /**
193
+ * Store an access token
194
+ */
195
+ setAccessToken(token: string): void;
196
+ /**
197
+ * Remove the stored access token (logout)
198
+ */
199
+ clearAccessToken(): void;
200
+ /**
201
+ * Check if user is logged in
202
+ */
203
+ isLoggedIn(): boolean;
204
+ /**
205
+ * Introspect a token or API key and validate required scopes
206
+ */
207
+ introspect(request: IntrospectRequest): Promise<IntrospectResponse>;
208
+ /**
209
+ * Validate the current token with optional scope checking
210
+ */
211
+ validateWithScopes(requiredScopes?: string[]): Promise<ValidationResult>;
212
+ /**
213
+ * Check if the current user has all the required scopes
214
+ * Throws ScopeError if scopes are insufficient
215
+ */
216
+ requireScopes(...requiredScopes: string[]): Promise<ValidationResult>;
217
+ /**
218
+ * Execute a function only if the user has the required scopes
219
+ */
220
+ withScope<T>(scopes: string[], fn: () => Promise<T>): Promise<T>;
221
+ /**
222
+ * Login a user and store the access token
223
+ */
224
+ login(credentials: LoginCredentials): Promise<AuthToken>;
225
+ /**
226
+ * Logout the current user
227
+ */
228
+ logout(): Promise<void>;
229
+ /**
230
+ * Validate the current token or an API key
231
+ * @deprecated Use validateWithScopes instead
232
+ */
233
+ validate(_credential?: string): Promise<ValidationResult>;
234
+ /**
235
+ * Refresh the current token
236
+ */
237
+ refreshToken(): Promise<AuthToken>;
238
+ /**
239
+ * Create a new user (requires admin API key)
240
+ */
241
+ createUser(request: CreateUserRequest): Promise<User>;
242
+ /**
243
+ * List all users for the service
244
+ */
245
+ listUsers(): Promise<User[]>;
246
+ /**
247
+ * Delete a user
248
+ */
249
+ deleteUser(userId: string): Promise<void>;
250
+ /**
251
+ * Update user password
252
+ */
253
+ updatePassword(userId: string, oldPassword: string, newPassword: string): Promise<void>;
254
+ /**
255
+ * List custom scopes for the service
256
+ */
257
+ listScopes(): Promise<Scope[]>;
258
+ /**
259
+ * Create a custom scope
260
+ */
261
+ createScope(request: CreateScopeRequest): Promise<Scope>;
262
+ /**
263
+ * Delete a custom scope
264
+ */
265
+ deleteScope(scopeId: string): Promise<void>;
266
+ /**
267
+ * List all API keys for the service
268
+ */
269
+ listApiKeys(): Promise<ApiKey[]>;
270
+ /**
271
+ * Create a new API key with optional custom scopes
272
+ */
273
+ createApiKey(request: CreateApiKeyRequest): Promise<CreateApiKeyResponse>;
274
+ /**
275
+ * Revoke an API key
276
+ */
277
+ revokeApiKey(keyId: string): Promise<void>;
278
+ /**
279
+ * Onboard a new service (requires master admin key)
280
+ */
281
+ onboardService(request: OnboardRequest, masterAdminKey: string): Promise<OnboardResponse>;
282
+ /**
283
+ * Delete a service (requires master admin key)
284
+ */
285
+ deleteService(serviceId: string, masterAdminKey: string): Promise<void>;
286
+ /**
287
+ * List webhooks
288
+ */
289
+ listWebhooks(): Promise<Webhook[]>;
290
+ /**
291
+ * Register a webhook
292
+ */
293
+ registerWebhook(request: RegisterWebhookRequest): Promise<Webhook>;
294
+ /**
295
+ * Delete a webhook
296
+ */
297
+ deleteWebhook(webhookId: string): Promise<void>;
298
+ }
299
+
300
+ export { type ApiKey as A, type CreateApiKeyRequest as C, EasyAuthClient as E, type IntrospectRequest as I, LocalStorageTokenStorage as L, MemoryTokenStorage as M, type OnboardRequest as O, type RegisterWebhookRequest as R, type Scope as S, type TokenStorage as T, type User as U, type ValidationResult as V, type Webhook as W, type AuthToken as a, type CreateApiKeyResponse as b, type CreateScopeRequest as c, type CreateUserRequest as d, type EasyAuthConfig as e, EasyAuthError as f, type IntrospectResponse as g, type LoginCredentials as h, type OnboardResponse as i, ScopeError as j, type Service as k, type UserListResponse as l };
@@ -0,0 +1,31 @@
1
+ export { A as ApiKey, a as AuthToken, C as CreateApiKeyRequest, b as CreateApiKeyResponse, c as CreateScopeRequest, d as CreateUserRequest, E as EasyAuthClient, e as EasyAuthConfig, f as EasyAuthError, I as IntrospectRequest, g as IntrospectResponse, L as LocalStorageTokenStorage, h as LoginCredentials, M as MemoryTokenStorage, O as OnboardRequest, i as OnboardResponse, R as RegisterWebhookRequest, S as Scope, j as ScopeError, k as Service, T as TokenStorage, U as User, l as UserListResponse, V as ValidationResult, W as Webhook } from './client-RPDHpVsj.mjs';
2
+
3
+ /**
4
+ * Easy Auth Client
5
+ *
6
+ * Official client library for Easy Auth - Multi-tenant authentication-as-a-service
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { EasyAuthClient } from "@easyauth/client";
11
+ *
12
+ * const client = new EasyAuthClient({
13
+ * baseUrl: "https://auth.yourapp.com",
14
+ * serviceId: "svc-xxx",
15
+ * apiKey: "ak-xxx",
16
+ * });
17
+ *
18
+ * // Login
19
+ * const token = await client.login({
20
+ * email: "user@example.com",
21
+ * password: "password123",
22
+ * });
23
+ *
24
+ * // Validate token
25
+ * const isValid = await client.validate();
26
+ * ```
27
+ */
28
+
29
+ declare const VERSION = "1.0.0";
30
+
31
+ export { VERSION };
@@ -0,0 +1,31 @@
1
+ export { A as ApiKey, a as AuthToken, C as CreateApiKeyRequest, b as CreateApiKeyResponse, c as CreateScopeRequest, d as CreateUserRequest, E as EasyAuthClient, e as EasyAuthConfig, f as EasyAuthError, I as IntrospectRequest, g as IntrospectResponse, L as LocalStorageTokenStorage, h as LoginCredentials, M as MemoryTokenStorage, O as OnboardRequest, i as OnboardResponse, R as RegisterWebhookRequest, S as Scope, j as ScopeError, k as Service, T as TokenStorage, U as User, l as UserListResponse, V as ValidationResult, W as Webhook } from './client-RPDHpVsj.js';
2
+
3
+ /**
4
+ * Easy Auth Client
5
+ *
6
+ * Official client library for Easy Auth - Multi-tenant authentication-as-a-service
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { EasyAuthClient } from "@easyauth/client";
11
+ *
12
+ * const client = new EasyAuthClient({
13
+ * baseUrl: "https://auth.yourapp.com",
14
+ * serviceId: "svc-xxx",
15
+ * apiKey: "ak-xxx",
16
+ * });
17
+ *
18
+ * // Login
19
+ * const token = await client.login({
20
+ * email: "user@example.com",
21
+ * password: "password123",
22
+ * });
23
+ *
24
+ * // Validate token
25
+ * const isValid = await client.validate();
26
+ * ```
27
+ */
28
+
29
+ declare const VERSION = "1.0.0";
30
+
31
+ export { VERSION };