@genation/sdk 0.1.0

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,823 @@
1
+ /**
2
+ * Authentication-related errors
3
+ */
4
+ export declare class AuthError extends GenationError {
5
+ constructor(message: string, code: string, cause?: unknown);
6
+ static invalidGrant(message?: string): AuthError;
7
+ static accessDenied(message?: string): AuthError;
8
+ static expiredToken(message?: string): AuthError;
9
+ static invalidState(message?: string): AuthError;
10
+ static pkceVerificationFailed(message?: string): AuthError;
11
+ }
12
+
13
+ /**
14
+ * Authentication state change event types
15
+ *
16
+ * Events are fired in the following scenarios:
17
+ * - `INITIAL_SESSION`: Fired once when `onAuthStateChange` is first called.
18
+ * Session may or may not exist depending on previous auth state.
19
+ * - `SIGNED_IN`: Fired when user successfully completes OAuth flow via `handleCallback()`.
20
+ * - `SIGNED_OUT`: Fired when user signs out via `signOut()` or session expires.
21
+ * - `TOKEN_REFRESHED`: Fired when access token is automatically refreshed.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * client.onAuthStateChange((event, session) => {
26
+ * switch (event) {
27
+ * case 'INITIAL_SESSION':
28
+ * // Check if user was previously logged in
29
+ * break;
30
+ * case 'SIGNED_IN':
31
+ * // Redirect to dashboard
32
+ * break;
33
+ * case 'SIGNED_OUT':
34
+ * // Clear app state, redirect to home
35
+ * break;
36
+ * case 'TOKEN_REFRESHED':
37
+ * // Update cached token if needed
38
+ * break;
39
+ * }
40
+ * });
41
+ * ```
42
+ */
43
+ export declare type AuthEvent = "INITIAL_SESSION" | "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED";
44
+
45
+ /**
46
+ * Callback function signature for auth state change events
47
+ *
48
+ * @param event - Type of auth event that occurred
49
+ * @param session - Current session if authenticated, null otherwise
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const callback: AuthStateChangeCallback = (event, session) => {
54
+ * console.log(`Auth event: ${event}`, session?.user?.email);
55
+ * };
56
+ * ```
57
+ */
58
+ export declare type AuthStateChangeCallback = (event: AuthEvent, session: Session | null) => void;
59
+
60
+ /**
61
+ * Configuration-related errors
62
+ */
63
+ export declare class ConfigError extends GenationError {
64
+ constructor(message: string);
65
+ static missingField(field: string): ConfigError;
66
+ }
67
+
68
+ /**
69
+ * Create a new Genation client instance
70
+ *
71
+ * Factory function for creating SDK client with configuration.
72
+ *
73
+ * @param config - Client configuration options
74
+ * @returns Configured GenationClient instance
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * import { createClient } from 'genation';
79
+ *
80
+ * const client = createClient({
81
+ * clientId: 'your-client-id',
82
+ * clientSecret: 'your-client-secret',
83
+ * redirectUri: 'http://localhost:3000/callback',
84
+ * // Optional
85
+ * scopes: ['openid', 'profile', 'email'],
86
+ * storage: 'localStorage',
87
+ * });
88
+ * ```
89
+ */
90
+ export declare function createClient(config: GenationConfig): GenationClient;
91
+
92
+ /**
93
+ * Create a storage instance based on type
94
+ *
95
+ * @param type - Storage type to create
96
+ * @returns Storage implementation
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const storage = createStorage('localStorage');
101
+ * await storage.set('key', 'value');
102
+ * ```
103
+ */
104
+ export declare function createStorage(type?: StorageType): TokenStorage;
105
+
106
+ /**
107
+ * Main Genation SDK client
108
+ *
109
+ * OAuth 2.1 authentication client for Genation platform.
110
+ * Supports PKCE flow and automatic token refresh.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * import { createClient } from 'genation';
115
+ *
116
+ * const client = createClient({
117
+ * clientId: 'your-client-id',
118
+ * clientSecret: 'your-client-secret',
119
+ * redirectUri: 'http://localhost:3000/callback'
120
+ * });
121
+ *
122
+ * // Listen to auth state changes
123
+ * const { subscription } = client.onAuthStateChange((event, session) => {
124
+ * if (event === 'SIGNED_IN') {
125
+ * console.log('User signed in:', session?.user);
126
+ * }
127
+ * });
128
+ *
129
+ * // Start login flow
130
+ * window.location.href = await client.signIn();
131
+ * ```
132
+ */
133
+ export declare class GenationClient {
134
+ private oauth;
135
+ private tokenManager;
136
+ private http;
137
+ private httpServer;
138
+ private listeners;
139
+ private initialized;
140
+ constructor(config: GenationConfig);
141
+ private validateConfig;
142
+ /**
143
+ * Emit auth state change event to all listeners
144
+ */
145
+ private emitAuthStateChange;
146
+ /**
147
+ * Listen to authentication state changes
148
+ *
149
+ * Register a callback that fires when:
150
+ * - `INITIAL_SESSION`: On first subscription, with current session state
151
+ * - `SIGNED_IN`: User successfully authenticated
152
+ * - `SIGNED_OUT`: User logged out or session expired
153
+ * - `TOKEN_REFRESHED`: Access token was automatically refreshed
154
+ *
155
+ * @param callback - Function called on each auth state change
156
+ * @returns Object containing subscription with `unsubscribe()` method
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const { subscription } = client.onAuthStateChange((event, session) => {
161
+ * console.log('Auth event:', event);
162
+ *
163
+ * if (event === 'INITIAL_SESSION') {
164
+ * // Check if user was previously logged in
165
+ * if (session) {
166
+ * console.log('Welcome back!', session.user);
167
+ * }
168
+ * } else if (event === 'SIGNED_IN') {
169
+ * // User just signed in
170
+ * console.log('Signed in:', session?.user);
171
+ * } else if (event === 'SIGNED_OUT') {
172
+ * // Clear app state, redirect to login
173
+ * console.log('Signed out');
174
+ * }
175
+ * });
176
+ *
177
+ * // Cleanup when component unmounts
178
+ * subscription.unsubscribe();
179
+ * ```
180
+ */
181
+ onAuthStateChange(callback: AuthStateChangeCallback): {
182
+ subscription: Subscription;
183
+ };
184
+ /**
185
+ * Start OAuth sign-in flow
186
+ *
187
+ * Generates authorization URL with PKCE challenge.
188
+ * Redirect user to this URL to start authentication.
189
+ *
190
+ * @returns Authorization URL to redirect user to
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * async function handleLogin() {
195
+ * const url = await client.signIn();
196
+ * window.location.href = url;
197
+ * }
198
+ * ```
199
+ */
200
+ signIn(): Promise<string>;
201
+ /**
202
+ * Handle OAuth callback after user authentication
203
+ *
204
+ * Call this on your redirect URI page to exchange
205
+ * the authorization code for access tokens.
206
+ * Triggers `SIGNED_IN` event on success.
207
+ *
208
+ * @param code - Authorization code from URL query params
209
+ * @param state - State parameter for CSRF validation
210
+ * @returns Token set with access and refresh tokens
211
+ * @throws {AuthError} If state mismatch or code exchange fails
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * // On your /callback page
216
+ * async function handleCallback() {
217
+ * const params = new URLSearchParams(window.location.search);
218
+ * const code = params.get('code');
219
+ * const state = params.get('state');
220
+ *
221
+ * if (code && state) {
222
+ * await client.handleCallback(code, state);
223
+ * // onAuthStateChange will fire with SIGNED_IN event
224
+ * }
225
+ * }
226
+ * ```
227
+ */
228
+ handleCallback(code: string, state: string): Promise<TokenSet>;
229
+ /**
230
+ * Sign out and revoke tokens
231
+ *
232
+ * Clears local session and revokes tokens on server.
233
+ * Triggers `SIGNED_OUT` event for all listeners.
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * async function handleLogout() {
238
+ * await client.signOut();
239
+ * // onAuthStateChange will fire with SIGNED_OUT event
240
+ * }
241
+ * ```
242
+ */
243
+ signOut(): Promise<void>;
244
+ /**
245
+ * Get current session
246
+ *
247
+ * Returns session with access token and user info.
248
+ * Automatically refreshes token if expired.
249
+ *
250
+ * @returns Current session or null if not authenticated
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * const session = await client.getSession();
255
+ * if (session) {
256
+ * console.log('Logged in as:', session.user?.email);
257
+ *
258
+ * // Use access token for API calls
259
+ * fetch('/api/data', {
260
+ * headers: { Authorization: `Bearer ${session.accessToken}` }
261
+ * });
262
+ * }
263
+ * ```
264
+ */
265
+ getSession(): Promise<Session | null>;
266
+ /**
267
+ * Get licenses
268
+ * @param accessToken - The access token to use for the request
269
+ * @param options - The options for the request
270
+ * @param options.expiresAfter - Query licenses that are expired after the given date, default set to today to get all valid licenses (unexpired licenses)
271
+ * @returns The licenses
272
+ */
273
+ getLicenses(options?: {
274
+ expiresAfter?: Date;
275
+ }): Promise<License[] | null>;
276
+ /**
277
+ * Fetch user info from auth server
278
+ */
279
+ private fetchUser;
280
+ }
281
+
282
+ /**
283
+ * @fileoverview SDK configuration types for Genation SDK
284
+ * @module types/config
285
+ */
286
+ /**
287
+ * Genation SDK configuration options
288
+ *
289
+ * Required configuration for initializing the SDK client.
290
+ * Obtain `clientId` and `clientSecret` from the Genation developer portal.
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * import { createClient, GenationConfig } from 'genation';
295
+ *
296
+ * const config: GenationConfig = {
297
+ * clientId: 'your-client-id',
298
+ * clientSecret: 'your-client-secret',
299
+ * redirectUri: 'http://localhost:3000/callback',
300
+ * scopes: ['openid', 'profile', 'email'],
301
+ * storage: 'localStorage',
302
+ * };
303
+ *
304
+ * const client = createClient(config);
305
+ * ```
306
+ */
307
+ export declare interface GenationConfig {
308
+ /**
309
+ * OAuth client ID from Genation developer portal
310
+ * Unique identifier for your application
311
+ * @required
312
+ */
313
+ clientId: string;
314
+ /**
315
+ * OAuth client secret from Genation developer portal
316
+ *
317
+ * **Security note:**
318
+ * - Frontend apps: PKCE provides protection, secret exposure is acceptable
319
+ * - Backend apps: Keep secret secure on server-side only
320
+ *
321
+ * @required
322
+ */
323
+ clientSecret: string;
324
+ /**
325
+ * Registered redirect URI for OAuth callback
326
+ *
327
+ * Must exactly match a URI registered in developer portal.
328
+ * User will be redirected here after authentication.
329
+ *
330
+ * @required
331
+ * @example "http://localhost:3000/callback"
332
+ * @example "https://myapp.com/auth/callback"
333
+ */
334
+ redirectUri: string;
335
+ /**
336
+ * OAuth scopes to request during authorization
337
+ *
338
+ * Controls what user data your app can access.
339
+ *
340
+ * @default undefined (Server handles defaults)
341
+ * @example ['openid', 'profile', 'email']
342
+ */
343
+ scopes?: string[];
344
+ /**
345
+ * Custom auth server URL
346
+ *
347
+ * Override if using a custom Genation deployment.
348
+ *
349
+ * @default "https://mnnoheowoowbtpuoguul.supabase.co/auth/v1"
350
+ */
351
+ authUrl?: string;
352
+ /**
353
+ * Token storage strategy
354
+ *
355
+ * - `'localStorage'`: Persist across browser sessions (default)
356
+ * - `'sessionStorage'`: Clear when tab closes
357
+ * - `'memory'`: Clear on page refresh (most secure, least convenient)
358
+ *
359
+ * @default 'localStorage'
360
+ */
361
+ storage?: StorageType;
362
+ }
363
+
364
+ /**
365
+ * Base error class for Genation SDK
366
+ */
367
+ export declare class GenationError extends Error {
368
+ code: string;
369
+ cause?: unknown;
370
+ constructor(message: string, code: string, cause?: unknown);
371
+ }
372
+
373
+ /**
374
+ * Represents an individual license issued for a user or entity.
375
+ * A license grants access to an application under specific terms, durations, and plans.
376
+ */
377
+ declare interface License {
378
+ /**
379
+ * Unique identifier for the license.
380
+ * Typically a UUID string.
381
+ * Example: 'b23f680b-968d-4db3-a1ef-1870eaa8b17e'
382
+ */
383
+ id: string;
384
+ /**
385
+ * Alphanumeric code or token that represents the ownership or grant of this license.
386
+ * May be used for redeeming, activating, or looking up the license.
387
+ * Example: 'ACME-56T9-PX24-2024'
388
+ */
389
+ code: string;
390
+ /**
391
+ * The foreign key referencing the license plan this license was issued under.
392
+ * This ties the license to a specific set of plan attributes/entitlements.
393
+ * Example: '15f24aa1-83e2-4f6c-af22-b2e159d56f98'
394
+ */
395
+ app_plan_id: string;
396
+ /**
397
+ * The total duration (in calendar days) for which the license is valid after being redeemed or activated.
398
+ * Example: 30 (for a one-month license), 365 (for annual licenses)
399
+ */
400
+ duration_days: number;
401
+ /**
402
+ * Optionally, the UUID of a plan term or subscription cycle associated with the license, if applicable.
403
+ * Can be null if the license does not have distinct terms.
404
+ * Example: 'random<uuid>', or null for perpetual/server-issued licenses.
405
+ */
406
+ plan_term_id: string | null;
407
+ /**
408
+ * The user UUID (or organization ID) of the purchaser who paid for or obtained the license.
409
+ * This identifies the buying entity. May be a UUID string.
410
+ * Example: 'uuid'
411
+ */
412
+ purchaser_id: string;
413
+ /**
414
+ * The user UUID of the account that redeemed or is assigned this license.
415
+ * For team or transferred licenses, this may differ from purchaser_id.
416
+ * Example: 'uuid'
417
+ */
418
+ redeemed_by: string;
419
+ /**
420
+ * The ISO 8601 timestamp when the license was purchased, invoiced, or issued (by admin/tool).
421
+ * Format: 'YYYY-MM-DDTHH:mm:ss.sssZ'
422
+ * Example: '2024-06-05T14:00:13.001Z'
423
+ */
424
+ purchased_at: string;
425
+ /**
426
+ * The ISO 8601 timestamp when the license was redeemed or activated by a user for use.
427
+ * May be equal to purchased_at for immediate use, or later if redeemed by a team member.
428
+ * Format: 'YYYY-MM-DDTHH:mm:ss.sssZ'
429
+ * Example: '2024-06-05T16:20:27.330Z'
430
+ */
431
+ redeemed_at: string;
432
+ /**
433
+ * Optional note from the purchaser (attached to the license at order time).
434
+ * Could contain recipient info, business notes, or a purpose for purchase.
435
+ * Example: 'For Emily - Happy birthday!', 'Procured by IT Services, invoice #2024-1091'
436
+ */
437
+ purchaser_note: string;
438
+ /**
439
+ * The ISO 8601 timestamp for license expiration or end of entitlement.
440
+ * After this date, the license is considered expired and may not grant access.
441
+ * Format: 'YYYY-MM-DDTHH:mm:ss.sssZ'
442
+ * Example: '2025-06-05T16:20:27.000Z'
443
+ */
444
+ expires_at: string;
445
+ /**
446
+ * String representing the license status in the system.
447
+ * Common examples: 'available', 'active', 'expired'
448
+ * Used to control access and display state in user/admin portals.
449
+ */
450
+ status: LicenseStatus;
451
+ /**
452
+ * The license plan details that define the attributes/entitlements for this license.
453
+ * Fully inlines the associated LicensePlan object.
454
+ */
455
+ plan: LicensePlan;
456
+ }
457
+
458
+ /**
459
+ * Represents a license plan, which defines the properties of a license tier or offering for an application.
460
+ */
461
+ declare interface LicensePlan {
462
+ /**
463
+ * Unique identifier for the license plan.
464
+ * Typically a UUID string assigned by the backend.
465
+ * Example: 'f265b8c0-0ef1-4cc0-b37b-92dded82d49a'
466
+ */
467
+ id: string;
468
+ /**
469
+ * The unique ID of the application this plan belongs to.
470
+ * Maps to the application entity in the system.
471
+ * Example: 'app_003cd5870d'
472
+ */
473
+ app_id: string;
474
+ /**
475
+ * The public (human-readable or machine-friendly) code for the plan.
476
+ * Used for referencing the plan in APIs, admin panels, or order forms.
477
+ * Example: 'PRO', 'TEAM_2023', 'ENTERPRISE'
478
+ */
479
+ code: string;
480
+ /**
481
+ * The display name of the license plan.
482
+ * Used for showing to end users in UIs.
483
+ * Example: 'Pro Plan', 'Enterprise Annual Subscription'
484
+ */
485
+ name: string;
486
+ /**
487
+ * The ISO 8601 timestamp when this plan was created in the system.
488
+ * Format: 'YYYY-MM-DDTHH:mm:ss.sssZ'
489
+ * Example: '2024-06-05T12:34:56.789Z'
490
+ */
491
+ created_at: string;
492
+ }
493
+
494
+ /**
495
+ * The status of a license.
496
+ * Example: 'available', 'active', 'expired'
497
+ * available: the license is available to be redeemed
498
+ * active: the license is redeemed and can know as valid license
499
+ * expired: the license has expired and can no longer be used
500
+ */
501
+ declare type LicenseStatus = "available" | "active" | "expired";
502
+
503
+ /**
504
+ * Browser localStorage implementation
505
+ * Tokens persist across browser sessions
506
+ */
507
+ export declare class LocalStorage implements TokenStorage {
508
+ private prefix;
509
+ constructor(prefix?: string);
510
+ private getKey;
511
+ get(key: string): Promise<string | null>;
512
+ set(key: string, value: string): Promise<void>;
513
+ remove(key: string): Promise<void>;
514
+ clear(): Promise<void>;
515
+ }
516
+
517
+ /**
518
+ * In-memory storage implementation
519
+ * Tokens are lost when page refreshes
520
+ */
521
+ export declare class MemoryStorage implements TokenStorage {
522
+ private store;
523
+ get(key: string): Promise<string | null>;
524
+ set(key: string, value: string): Promise<void>;
525
+ remove(key: string): Promise<void>;
526
+ clear(): Promise<void>;
527
+ }
528
+
529
+ /**
530
+ * Network-related errors
531
+ */
532
+ export declare class NetworkError extends GenationError {
533
+ status?: number;
534
+ constructor(message: string, status?: number, cause?: unknown);
535
+ static fromResponse(response: Response): NetworkError;
536
+ }
537
+
538
+ /**
539
+ * PKCE (Proof Key for Code Exchange) challenge pair
540
+ *
541
+ * Generated internally by SDK for OAuth 2.1 authorization code flow.
542
+ * The verifier is stored and used during token exchange, while the
543
+ * challenge is sent with the authorization request.
544
+ *
545
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7636 | RFC 7636 - PKCE}
546
+ */
547
+ export declare interface PKCEChallenge {
548
+ /**
549
+ * High-entropy cryptographic random string (43-128 chars)
550
+ * Stored locally and sent during token exchange
551
+ */
552
+ codeVerifier: string;
553
+ /**
554
+ * Base64URL-encoded SHA-256 hash of the code verifier
555
+ * Sent with authorization request
556
+ */
557
+ codeChallenge: string;
558
+ /**
559
+ * Challenge derivation method, always 'S256' for OAuth 2.1
560
+ * Plain method is deprecated and not supported
561
+ */
562
+ codeChallengeMethod: "S256";
563
+ }
564
+
565
+ /**
566
+ * Active user session containing tokens and user information
567
+ *
568
+ * Returned by `getSession()` and passed to `onAuthStateChange` callback.
569
+ * Contains everything needed to make authenticated API requests.
570
+ *
571
+ * @example
572
+ * ```typescript
573
+ * const session = await client.getSession();
574
+ * if (session) {
575
+ * // Use access token for API calls
576
+ * fetch('/api/data', {
577
+ * headers: { Authorization: `Bearer ${session.accessToken}` }
578
+ * });
579
+ *
580
+ * // Check token expiration
581
+ * if (Date.now() > session.expiresAt) {
582
+ * console.log('Token expired');
583
+ * }
584
+ * }
585
+ * ```
586
+ */
587
+ export declare interface Session {
588
+ /**
589
+ * JWT access token for authenticating API requests
590
+ * Include in Authorization header: `Bearer ${accessToken}`
591
+ */
592
+ accessToken: string;
593
+ /**
594
+ * Refresh token for obtaining new access tokens
595
+ * Managed internally by SDK, typically not needed directly
596
+ */
597
+ refreshToken?: string;
598
+ /**
599
+ * Access token lifetime in seconds from issue time
600
+ * @example 3600 // 1 hour
601
+ */
602
+ expiresIn: number;
603
+ /**
604
+ * Unix timestamp (ms) when the access token expires
605
+ * Use to check if token needs refresh: `Date.now() > session.expiresAt`
606
+ */
607
+ expiresAt: number;
608
+ /**
609
+ * Authenticated user information
610
+ * May be null if user info fetch failed
611
+ */
612
+ user: User | null;
613
+ }
614
+
615
+ /**
616
+ * Browser sessionStorage implementation
617
+ * Tokens persist until browser tab is closed
618
+ */
619
+ export declare class SessionStorage implements TokenStorage {
620
+ private prefix;
621
+ constructor(prefix?: string);
622
+ private getKey;
623
+ get(key: string): Promise<string | null>;
624
+ set(key: string, value: string): Promise<void>;
625
+ remove(key: string): Promise<void>;
626
+ clear(): Promise<void>;
627
+ }
628
+
629
+ /**
630
+ * Available storage backends for token persistence
631
+ *
632
+ * Choose based on security vs convenience tradeoffs:
633
+ *
634
+ * | Type | Persistence | Security | Use Case |
635
+ * |------|-------------|----------|----------|
636
+ * | `memory` | Page only | Highest | Sensitive apps |
637
+ * | `sessionStorage` | Tab lifetime | Medium | Standard apps |
638
+ * | `localStorage` | Permanent | Lower | Convenience priority |
639
+ */
640
+ export declare type StorageType = "memory" | "localStorage" | "sessionStorage";
641
+
642
+ /**
643
+ * Subscription handle for auth state change listener
644
+ *
645
+ * Returned by `onAuthStateChange()`. Call `unsubscribe()` to stop
646
+ * receiving auth state change events (e.g., on component unmount).
647
+ *
648
+ * @example
649
+ * ```typescript
650
+ * // React useEffect pattern
651
+ * useEffect(() => {
652
+ * const { subscription } = client.onAuthStateChange((event, session) => {
653
+ * setSession(session);
654
+ * });
655
+ *
656
+ * return () => {
657
+ * subscription.unsubscribe();
658
+ * };
659
+ * }, []);
660
+ * ```
661
+ */
662
+ export declare interface Subscription {
663
+ /**
664
+ * Stop listening to auth state changes
665
+ * Call this on cleanup to prevent memory leaks
666
+ */
667
+ unsubscribe: () => void;
668
+ }
669
+
670
+ /**
671
+ * OAuth token set returned from token exchange
672
+ *
673
+ * Internal type used by SDK. For external use, prefer `Session` type.
674
+ */
675
+ export declare interface TokenSet {
676
+ /**
677
+ * JWT access token for API authentication
678
+ */
679
+ accessToken: string;
680
+ /**
681
+ * Refresh token for obtaining new access tokens
682
+ * Used internally for automatic token refresh
683
+ */
684
+ refreshToken?: string;
685
+ /**
686
+ * Token type, typically 'Bearer'
687
+ */
688
+ tokenType: string;
689
+ /**
690
+ * Access token expiration time in seconds
691
+ */
692
+ expiresIn: number;
693
+ /**
694
+ * Unix timestamp (ms) when tokens were issued
695
+ * Used to calculate expiration: `issuedAt + expiresIn * 1000`
696
+ */
697
+ issuedAt: number;
698
+ /**
699
+ * Space-separated list of granted OAuth scopes
700
+ * @example "openid profile email"
701
+ */
702
+ scope?: string;
703
+ }
704
+
705
+ /**
706
+ * Custom token storage interface
707
+ *
708
+ * Implement this interface to provide custom storage backend
709
+ * (e.g., encrypted storage, IndexedDB, React Native AsyncStorage).
710
+ *
711
+ * All methods are async to support various storage backends.
712
+ *
713
+ * @example
714
+ * ```typescript
715
+ * import { TokenStorage } from 'genation';
716
+ *
717
+ * class EncryptedStorage implements TokenStorage {
718
+ * async get(key: string) {
719
+ * const encrypted = localStorage.getItem(key);
720
+ * return encrypted ? decrypt(encrypted) : null;
721
+ * }
722
+ *
723
+ * async set(key: string, value: string) {
724
+ * localStorage.setItem(key, encrypt(value));
725
+ * }
726
+ *
727
+ * async remove(key: string) {
728
+ * localStorage.removeItem(key);
729
+ * }
730
+ *
731
+ * async clear() {
732
+ * // Clear all SDK-related keys
733
+ * }
734
+ * }
735
+ * ```
736
+ */
737
+ export declare interface TokenStorage {
738
+ /**
739
+ * Retrieve a value by key
740
+ * @param key - Storage key
741
+ * @returns Stored value or null if not found
742
+ */
743
+ get(key: string): Promise<string | null>;
744
+ /**
745
+ * Store a value with the given key
746
+ * @param key - Storage key
747
+ * @param value - Value to store
748
+ */
749
+ set(key: string, value: string): Promise<void>;
750
+ /**
751
+ * Remove a value by key
752
+ * @param key - Storage key to remove
753
+ */
754
+ remove(key: string): Promise<void>;
755
+ /**
756
+ * Clear all stored values
757
+ * Called on sign out to clean up all SDK data
758
+ */
759
+ clear(): Promise<void>;
760
+ }
761
+
762
+ /**
763
+ * @fileoverview User information types for Genation SDK
764
+ * @module types/user
765
+ */
766
+ /**
767
+ * OIDC Standard Claims User Profile
768
+ * https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
769
+ */
770
+ export declare interface User {
771
+ /**
772
+ * Subject - Identifier for the End-User at the Issuer.
773
+ * Guaranteed to be unique and stable.
774
+ */
775
+ sub: string;
776
+ /**
777
+ * End-User's full name in displayable form including all name parts
778
+ */
779
+ name?: string;
780
+ /**
781
+ * Given name(s) or first name(s) of the End-User
782
+ */
783
+ given_name?: string;
784
+ /**
785
+ * Surname(s) or last name(s) of the End-User
786
+ */
787
+ family_name?: string;
788
+ /**
789
+ * Shorthand name by which the End-User wishes to be referred to
790
+ */
791
+ preferred_username?: string;
792
+ /**
793
+ * URL of the End-User's profile picture
794
+ */
795
+ picture?: string;
796
+ /**
797
+ * End-User's preferred e-mail address
798
+ */
799
+ email?: string;
800
+ /**
801
+ * True if the End-User's e-mail address has been verified
802
+ */
803
+ email_verified?: boolean;
804
+ /**
805
+ * End-User's preferred telephone number
806
+ */
807
+ phone_number?: string;
808
+ /**
809
+ * True if the End-User's phone number has been verified
810
+ */
811
+ phone_number_verified?: boolean;
812
+ /**
813
+ * Time the End-User's information was last updated
814
+ * ISO 8601 string or number
815
+ */
816
+ updated_at?: string;
817
+ /**
818
+ * Additional claims from the provider
819
+ */
820
+ [key: string]: unknown;
821
+ }
822
+
823
+ export { }