@lanonasis/oauth-client 1.2.7 → 2.0.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.
package/dist/index.d.cts CHANGED
@@ -13,6 +13,165 @@ declare class TerminalOAuthFlow extends BaseOAuthFlow {
13
13
  private checkDeviceCode;
14
14
  }
15
15
 
16
+ /**
17
+ * Magic Link / OTP Flow
18
+ *
19
+ * Passwordless authentication supporting two modes:
20
+ * 1. OTP Code (type: 'email') - User receives 6-digit code to enter manually (CLI, mobile)
21
+ * 2. Magic Link (type: 'magiclink') - User clicks link in email (web, desktop)
22
+ *
23
+ * Usage:
24
+ * ```typescript
25
+ * // OTP Code Flow (CLI)
26
+ * const flow = new MagicLinkFlow({ clientId: 'my-app' });
27
+ * await flow.requestOTP('user@example.com');
28
+ * const tokens = await flow.verifyOTP('user@example.com', '123456');
29
+ *
30
+ * // Magic Link Flow (Web)
31
+ * const flow = new MagicLinkFlow({ clientId: 'my-app' });
32
+ * await flow.requestMagicLink('user@example.com', 'https://myapp.com/auth/callback');
33
+ * // User clicks link in email, then:
34
+ * const tokens = await flow.exchangeMagicLinkToken(supabaseAccessToken, state);
35
+ * ```
36
+ */
37
+
38
+ type OTPType = 'email' | 'magiclink';
39
+ type Platform = 'cli' | 'web' | 'mcp' | 'api';
40
+ interface MagicLinkConfig extends OAuthConfig {
41
+ projectScope?: string;
42
+ platform?: Platform;
43
+ }
44
+ interface OTPSendResponse {
45
+ success: boolean;
46
+ message: string;
47
+ type: OTPType;
48
+ expires_in: number;
49
+ }
50
+ interface OTPVerifyResponse extends TokenResponse {
51
+ auth_method: 'otp' | 'magic_link';
52
+ user?: {
53
+ id: string;
54
+ email: string;
55
+ role: string;
56
+ };
57
+ }
58
+ interface MagicLinkExchangeResponse extends TokenResponse {
59
+ redirect_to?: string;
60
+ user?: {
61
+ id: string;
62
+ email?: string;
63
+ role?: string;
64
+ project_scope?: string;
65
+ };
66
+ }
67
+ declare class MagicLinkFlow extends BaseOAuthFlow {
68
+ private readonly projectScope;
69
+ private readonly platform;
70
+ constructor(config: MagicLinkConfig);
71
+ /**
72
+ * Main authenticate method - uses OTP code flow by default
73
+ * For interactive CLI usage, prefer using requestOTP() and verifyOTP() separately
74
+ */
75
+ authenticate(): Promise<TokenResponse>;
76
+ /**
77
+ * Request a 6-digit OTP code to be sent via email
78
+ * User will enter this code manually in the CLI
79
+ *
80
+ * @param email - User's email address
81
+ * @returns Response with success status and expiration time
82
+ */
83
+ requestOTP(email: string): Promise<OTPSendResponse>;
84
+ /**
85
+ * Verify the OTP code entered by the user and get tokens
86
+ *
87
+ * @param email - User's email address (must match the one used in requestOTP)
88
+ * @param code - 6-digit OTP code from email
89
+ * @returns Token response with access_token, refresh_token, etc.
90
+ */
91
+ verifyOTP(email: string, code: string): Promise<OTPVerifyResponse>;
92
+ /**
93
+ * Resend OTP code (rate limited)
94
+ *
95
+ * @param email - User's email address
96
+ * @returns Response with success status
97
+ */
98
+ resendOTP(email: string): Promise<OTPSendResponse>;
99
+ /**
100
+ * Request a magic link to be sent via email
101
+ * User will click the link which redirects to your callback URL
102
+ *
103
+ * @param email - User's email address
104
+ * @param redirectUri - URL to redirect to after clicking the magic link
105
+ * @returns Response with success status
106
+ */
107
+ requestMagicLink(email: string, redirectUri: string): Promise<OTPSendResponse>;
108
+ /**
109
+ * Alternative: Use the /v1/auth/magic-link endpoint (web-optimized)
110
+ * This endpoint provides better redirect handling for web apps
111
+ *
112
+ * @param email - User's email address
113
+ * @param redirectUri - URL to redirect to after authentication
114
+ * @param createUser - Whether to create a new user if email doesn't exist
115
+ */
116
+ requestMagicLinkWeb(email: string, redirectUri: string, createUser?: boolean): Promise<{
117
+ success: boolean;
118
+ message: string;
119
+ }>;
120
+ /**
121
+ * Exchange magic link token for auth-gateway tokens
122
+ * Called after user clicks the magic link and is redirected to your callback
123
+ *
124
+ * @param supabaseAccessToken - Access token from Supabase (from URL hash/query)
125
+ * @param state - State parameter from the callback URL
126
+ * @returns Token response with redirect URL
127
+ */
128
+ exchangeMagicLinkToken(supabaseAccessToken: string, state: string): Promise<MagicLinkExchangeResponse>;
129
+ /**
130
+ * Check if an email is valid format
131
+ */
132
+ static isValidEmail(email: string): boolean;
133
+ /**
134
+ * Check if an OTP code is valid format (6 digits).
135
+ *
136
+ * This method:
137
+ * - Trims leading and trailing whitespace from the input before validating.
138
+ * - Requires exactly 6 numeric digits (0–9); any non-numeric characters or
139
+ * incorrect length will cause it to return `false`.
140
+ *
141
+ * Note: This method expects a string value. Passing `null`, `undefined`, or
142
+ * other non-string values will result in a runtime error when `.trim()` is
143
+ * called, rather than returning `false`.
144
+ *
145
+ * @param code - The OTP code to validate.
146
+ * @returns `true` if the trimmed code consists of exactly 6 digits, otherwise `false`.
147
+ */
148
+ static isValidOTPCode(code: string): boolean;
149
+ }
150
+
151
+ /**
152
+ * API Key Authentication Flow
153
+ *
154
+ * This flow uses a direct API key for authentication instead of OAuth.
155
+ * The API key is sent via x-api-key header to the backend.
156
+ */
157
+ declare class APIKeyFlow extends BaseOAuthFlow {
158
+ private apiKey;
159
+ constructor(apiKey: string, authBaseUrl?: string);
160
+ /**
161
+ * "Authenticate" by returning the API key as a virtual token
162
+ * The API key will be used directly in request headers
163
+ */
164
+ authenticate(): Promise<TokenResponse>;
165
+ /**
166
+ * API keys don't need refresh
167
+ */
168
+ refreshToken(refreshToken: string): Promise<TokenResponse>;
169
+ /**
170
+ * Optional: Validate API key by making a test request
171
+ */
172
+ validateAPIKey(): Promise<boolean>;
173
+ }
174
+
16
175
  interface MCPClientConfig extends Partial<OAuthConfig> {
17
176
  mcpEndpoint?: string;
18
177
  autoRefresh?: boolean;
@@ -51,4 +210,4 @@ declare class MCPClient {
51
210
  deleteMemory(id: string): Promise<void>;
52
211
  }
53
212
 
54
- export { BaseOAuthFlow, MCPClient, type MCPClientConfig, OAuthConfig, TerminalOAuthFlow, TokenResponse, TokenStorageAdapter };
213
+ export { APIKeyFlow, BaseOAuthFlow, MCPClient, type MCPClientConfig, type MagicLinkConfig, type MagicLinkExchangeResponse, MagicLinkFlow, OAuthConfig, type OTPSendResponse, type OTPType, type OTPVerifyResponse, type Platform, TerminalOAuthFlow, TokenResponse, TokenStorageAdapter };
package/dist/index.d.ts CHANGED
@@ -13,6 +13,165 @@ declare class TerminalOAuthFlow extends BaseOAuthFlow {
13
13
  private checkDeviceCode;
14
14
  }
15
15
 
16
+ /**
17
+ * Magic Link / OTP Flow
18
+ *
19
+ * Passwordless authentication supporting two modes:
20
+ * 1. OTP Code (type: 'email') - User receives 6-digit code to enter manually (CLI, mobile)
21
+ * 2. Magic Link (type: 'magiclink') - User clicks link in email (web, desktop)
22
+ *
23
+ * Usage:
24
+ * ```typescript
25
+ * // OTP Code Flow (CLI)
26
+ * const flow = new MagicLinkFlow({ clientId: 'my-app' });
27
+ * await flow.requestOTP('user@example.com');
28
+ * const tokens = await flow.verifyOTP('user@example.com', '123456');
29
+ *
30
+ * // Magic Link Flow (Web)
31
+ * const flow = new MagicLinkFlow({ clientId: 'my-app' });
32
+ * await flow.requestMagicLink('user@example.com', 'https://myapp.com/auth/callback');
33
+ * // User clicks link in email, then:
34
+ * const tokens = await flow.exchangeMagicLinkToken(supabaseAccessToken, state);
35
+ * ```
36
+ */
37
+
38
+ type OTPType = 'email' | 'magiclink';
39
+ type Platform = 'cli' | 'web' | 'mcp' | 'api';
40
+ interface MagicLinkConfig extends OAuthConfig {
41
+ projectScope?: string;
42
+ platform?: Platform;
43
+ }
44
+ interface OTPSendResponse {
45
+ success: boolean;
46
+ message: string;
47
+ type: OTPType;
48
+ expires_in: number;
49
+ }
50
+ interface OTPVerifyResponse extends TokenResponse {
51
+ auth_method: 'otp' | 'magic_link';
52
+ user?: {
53
+ id: string;
54
+ email: string;
55
+ role: string;
56
+ };
57
+ }
58
+ interface MagicLinkExchangeResponse extends TokenResponse {
59
+ redirect_to?: string;
60
+ user?: {
61
+ id: string;
62
+ email?: string;
63
+ role?: string;
64
+ project_scope?: string;
65
+ };
66
+ }
67
+ declare class MagicLinkFlow extends BaseOAuthFlow {
68
+ private readonly projectScope;
69
+ private readonly platform;
70
+ constructor(config: MagicLinkConfig);
71
+ /**
72
+ * Main authenticate method - uses OTP code flow by default
73
+ * For interactive CLI usage, prefer using requestOTP() and verifyOTP() separately
74
+ */
75
+ authenticate(): Promise<TokenResponse>;
76
+ /**
77
+ * Request a 6-digit OTP code to be sent via email
78
+ * User will enter this code manually in the CLI
79
+ *
80
+ * @param email - User's email address
81
+ * @returns Response with success status and expiration time
82
+ */
83
+ requestOTP(email: string): Promise<OTPSendResponse>;
84
+ /**
85
+ * Verify the OTP code entered by the user and get tokens
86
+ *
87
+ * @param email - User's email address (must match the one used in requestOTP)
88
+ * @param code - 6-digit OTP code from email
89
+ * @returns Token response with access_token, refresh_token, etc.
90
+ */
91
+ verifyOTP(email: string, code: string): Promise<OTPVerifyResponse>;
92
+ /**
93
+ * Resend OTP code (rate limited)
94
+ *
95
+ * @param email - User's email address
96
+ * @returns Response with success status
97
+ */
98
+ resendOTP(email: string): Promise<OTPSendResponse>;
99
+ /**
100
+ * Request a magic link to be sent via email
101
+ * User will click the link which redirects to your callback URL
102
+ *
103
+ * @param email - User's email address
104
+ * @param redirectUri - URL to redirect to after clicking the magic link
105
+ * @returns Response with success status
106
+ */
107
+ requestMagicLink(email: string, redirectUri: string): Promise<OTPSendResponse>;
108
+ /**
109
+ * Alternative: Use the /v1/auth/magic-link endpoint (web-optimized)
110
+ * This endpoint provides better redirect handling for web apps
111
+ *
112
+ * @param email - User's email address
113
+ * @param redirectUri - URL to redirect to after authentication
114
+ * @param createUser - Whether to create a new user if email doesn't exist
115
+ */
116
+ requestMagicLinkWeb(email: string, redirectUri: string, createUser?: boolean): Promise<{
117
+ success: boolean;
118
+ message: string;
119
+ }>;
120
+ /**
121
+ * Exchange magic link token for auth-gateway tokens
122
+ * Called after user clicks the magic link and is redirected to your callback
123
+ *
124
+ * @param supabaseAccessToken - Access token from Supabase (from URL hash/query)
125
+ * @param state - State parameter from the callback URL
126
+ * @returns Token response with redirect URL
127
+ */
128
+ exchangeMagicLinkToken(supabaseAccessToken: string, state: string): Promise<MagicLinkExchangeResponse>;
129
+ /**
130
+ * Check if an email is valid format
131
+ */
132
+ static isValidEmail(email: string): boolean;
133
+ /**
134
+ * Check if an OTP code is valid format (6 digits).
135
+ *
136
+ * This method:
137
+ * - Trims leading and trailing whitespace from the input before validating.
138
+ * - Requires exactly 6 numeric digits (0–9); any non-numeric characters or
139
+ * incorrect length will cause it to return `false`.
140
+ *
141
+ * Note: This method expects a string value. Passing `null`, `undefined`, or
142
+ * other non-string values will result in a runtime error when `.trim()` is
143
+ * called, rather than returning `false`.
144
+ *
145
+ * @param code - The OTP code to validate.
146
+ * @returns `true` if the trimmed code consists of exactly 6 digits, otherwise `false`.
147
+ */
148
+ static isValidOTPCode(code: string): boolean;
149
+ }
150
+
151
+ /**
152
+ * API Key Authentication Flow
153
+ *
154
+ * This flow uses a direct API key for authentication instead of OAuth.
155
+ * The API key is sent via x-api-key header to the backend.
156
+ */
157
+ declare class APIKeyFlow extends BaseOAuthFlow {
158
+ private apiKey;
159
+ constructor(apiKey: string, authBaseUrl?: string);
160
+ /**
161
+ * "Authenticate" by returning the API key as a virtual token
162
+ * The API key will be used directly in request headers
163
+ */
164
+ authenticate(): Promise<TokenResponse>;
165
+ /**
166
+ * API keys don't need refresh
167
+ */
168
+ refreshToken(refreshToken: string): Promise<TokenResponse>;
169
+ /**
170
+ * Optional: Validate API key by making a test request
171
+ */
172
+ validateAPIKey(): Promise<boolean>;
173
+ }
174
+
16
175
  interface MCPClientConfig extends Partial<OAuthConfig> {
17
176
  mcpEndpoint?: string;
18
177
  autoRefresh?: boolean;
@@ -51,4 +210,4 @@ declare class MCPClient {
51
210
  deleteMemory(id: string): Promise<void>;
52
211
  }
53
212
 
54
- export { BaseOAuthFlow, MCPClient, type MCPClientConfig, OAuthConfig, TerminalOAuthFlow, TokenResponse, TokenStorageAdapter };
213
+ export { APIKeyFlow, BaseOAuthFlow, MCPClient, type MCPClientConfig, type MagicLinkConfig, type MagicLinkExchangeResponse, MagicLinkFlow, OAuthConfig, type OTPSendResponse, type OTPType, type OTPVerifyResponse, type Platform, TerminalOAuthFlow, TokenResponse, TokenStorageAdapter };