@blinkdotnew/sdk 2.0.0 → 2.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/README.md +179 -23
- package/dist/index.d.mts +238 -6
- package/dist/index.d.ts +238 -6
- package/dist/index.js +632 -174
- package/dist/index.mjs +632 -174
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -146,7 +146,7 @@ This SDK powers every Blink-generated app with:
|
|
|
146
146
|
|
|
147
147
|
- **🔐 Authentication**: Flexible auth system with managed (redirect) and headless (custom UI) modes, email/password, social providers (Google, GitHub, Apple, Microsoft), magic links, RBAC, and custom email branding
|
|
148
148
|
- **🗄️ Database**: PostgREST-compatible CRUD operations with advanced filtering
|
|
149
|
-
- **🤖 AI**:
|
|
149
|
+
- **🤖 AI**: Multi-model image generation & editing (10 models), text generation with web search, object generation, speech synthesis, and transcription
|
|
150
150
|
- **📄 Data**: Extract text content from documents, secure API proxy with secret substitution, web scraping, screenshots, and web search
|
|
151
151
|
- **📁 Storage**: File upload, download, and management
|
|
152
152
|
- **📧 Notifications**: Email sending with attachments, custom branding, and delivery tracking
|
|
@@ -195,48 +195,167 @@ const blink = createClient({
|
|
|
195
195
|
|
|
196
196
|
The SDK has **first-class React Native support** with platform-aware features that automatically adapt to mobile environments.
|
|
197
197
|
|
|
198
|
+
#### Step 1: Install Dependencies
|
|
199
|
+
|
|
198
200
|
```bash
|
|
199
|
-
npm install @blinkdotnew/sdk @react-native-async-storage/async-storage
|
|
201
|
+
npm install @blinkdotnew/sdk @react-native-async-storage/async-storage expo-web-browser
|
|
200
202
|
```
|
|
201
203
|
|
|
204
|
+
**Required packages:**
|
|
205
|
+
- `@blinkdotnew/sdk` - The Blink SDK
|
|
206
|
+
- `@react-native-async-storage/async-storage` - For token persistence
|
|
207
|
+
- `expo-web-browser` - For OAuth authentication (Google, GitHub, Apple, etc.)
|
|
208
|
+
|
|
209
|
+
#### Step 2: Create Client (`lib/blink.ts`)
|
|
210
|
+
|
|
211
|
+
**⚠️ IMPORTANT: You MUST pass `webBrowser: WebBrowser` to enable OAuth on mobile!**
|
|
212
|
+
|
|
202
213
|
```typescript
|
|
214
|
+
// lib/blink.ts
|
|
203
215
|
import { createClient, AsyncStorageAdapter } from '@blinkdotnew/sdk'
|
|
204
216
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
217
|
+
import * as WebBrowser from 'expo-web-browser' // ← Import this
|
|
205
218
|
|
|
206
|
-
const blink = createClient({
|
|
219
|
+
export const blink = createClient({
|
|
207
220
|
projectId: 'your-project-id',
|
|
208
221
|
authRequired: false,
|
|
209
|
-
|
|
222
|
+
auth: {
|
|
223
|
+
mode: 'headless',
|
|
224
|
+
webBrowser: WebBrowser // ← Pass it here! Required for OAuth
|
|
225
|
+
},
|
|
210
226
|
storage: new AsyncStorageAdapter(AsyncStorage)
|
|
211
227
|
})
|
|
228
|
+
```
|
|
212
229
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
230
|
+
#### Step 3: Use Authentication
|
|
231
|
+
|
|
232
|
+
**Email/Password (works immediately):**
|
|
233
|
+
```typescript
|
|
234
|
+
// Sign up
|
|
235
|
+
const user = await blink.auth.signUp({
|
|
236
|
+
email: 'user@example.com',
|
|
237
|
+
password: 'SecurePass123'
|
|
217
238
|
})
|
|
239
|
+
|
|
240
|
+
// Sign in
|
|
241
|
+
const user = await blink.auth.signInWithEmail('user@example.com', 'SecurePass123')
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**OAuth (Google, GitHub, Apple, Microsoft):**
|
|
245
|
+
```typescript
|
|
246
|
+
// ✅ Same code works on web, iOS, AND Android!
|
|
247
|
+
const user = await blink.auth.signInWithGoogle()
|
|
248
|
+
const user = await blink.auth.signInWithGitHub()
|
|
249
|
+
const user = await blink.auth.signInWithApple()
|
|
250
|
+
const user = await blink.auth.signInWithMicrosoft()
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
#### Step 4: Create Auth Hook (`hooks/useAuth.ts`)
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
// hooks/useAuth.ts
|
|
257
|
+
import { useEffect, useState } from 'react'
|
|
258
|
+
import { blink } from '@/lib/blink'
|
|
259
|
+
import type { BlinkUser } from '@blinkdotnew/sdk'
|
|
260
|
+
|
|
261
|
+
export function useAuth() {
|
|
262
|
+
const [user, setUser] = useState<BlinkUser | null>(null)
|
|
263
|
+
const [isLoading, setIsLoading] = useState(true)
|
|
264
|
+
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
const unsubscribe = blink.auth.onAuthStateChanged((state) => {
|
|
267
|
+
setUser(state.user)
|
|
268
|
+
setIsLoading(state.isLoading)
|
|
269
|
+
})
|
|
270
|
+
return unsubscribe
|
|
271
|
+
}, [])
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
user,
|
|
275
|
+
isLoading,
|
|
276
|
+
isAuthenticated: !!user,
|
|
277
|
+
signInWithGoogle: () => blink.auth.signInWithGoogle(),
|
|
278
|
+
signInWithGitHub: () => blink.auth.signInWithGitHub(),
|
|
279
|
+
signInWithApple: () => blink.auth.signInWithApple(),
|
|
280
|
+
signOut: () => blink.auth.signOut(),
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
#### Step 5: Use in Components
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import { useAuth } from '@/hooks/useAuth'
|
|
289
|
+
import { View, Text, Button } from 'react-native'
|
|
290
|
+
|
|
291
|
+
function App() {
|
|
292
|
+
const { user, isLoading, signInWithGoogle, signOut } = useAuth()
|
|
293
|
+
|
|
294
|
+
if (isLoading) return <Text>Loading...</Text>
|
|
295
|
+
|
|
296
|
+
if (!user) {
|
|
297
|
+
return <Button onPress={signInWithGoogle} title="Sign in with Google" />
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<View>
|
|
302
|
+
<Text>Welcome, {user.email}!</Text>
|
|
303
|
+
<Button onPress={signOut} title="Sign Out" />
|
|
304
|
+
</View>
|
|
305
|
+
)
|
|
306
|
+
}
|
|
218
307
|
```
|
|
219
308
|
|
|
220
|
-
|
|
221
|
-
- ✅ **AsyncStorage integration** for secure token persistence
|
|
222
|
-
- ✅ **Automatic platform detection** - skips browser-only features (analytics tracking, cross-tab sync)
|
|
223
|
-
- ✅ **No polyfills needed** - works out of the box
|
|
224
|
-
- ✅ **Optimized for mobile** - reduced memory footprint
|
|
309
|
+
#### Common Mistakes
|
|
225
310
|
|
|
226
|
-
**Configuration Options:**
|
|
227
311
|
```typescript
|
|
228
|
-
//
|
|
312
|
+
// ❌ WRONG: Missing webBrowser - OAuth won't work on mobile!
|
|
229
313
|
const blink = createClient({
|
|
230
314
|
projectId: 'your-project-id',
|
|
315
|
+
auth: { mode: 'headless' }, // Missing webBrowser!
|
|
231
316
|
storage: new AsyncStorageAdapter(AsyncStorage)
|
|
232
317
|
})
|
|
233
318
|
|
|
234
|
-
//
|
|
319
|
+
// ✅ CORRECT: Include webBrowser for OAuth support
|
|
320
|
+
import * as WebBrowser from 'expo-web-browser'
|
|
321
|
+
|
|
235
322
|
const blink = createClient({
|
|
236
|
-
projectId: 'your-project-id'
|
|
323
|
+
projectId: 'your-project-id',
|
|
324
|
+
auth: {
|
|
325
|
+
mode: 'headless',
|
|
326
|
+
webBrowser: WebBrowser // ← Required for OAuth!
|
|
327
|
+
},
|
|
328
|
+
storage: new AsyncStorageAdapter(AsyncStorage)
|
|
237
329
|
})
|
|
238
330
|
```
|
|
239
331
|
|
|
332
|
+
#### Low-Level OAuth (For Custom Control)
|
|
333
|
+
|
|
334
|
+
If you need custom polling timeouts or manual browser handling:
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
// Get auth URL and authenticate function separately
|
|
338
|
+
const { authUrl, authenticate } = await blink.auth.signInWithProviderMobile('google')
|
|
339
|
+
|
|
340
|
+
// Open browser manually
|
|
341
|
+
await WebBrowser.openAuthSessionAsync(authUrl)
|
|
342
|
+
|
|
343
|
+
// Poll with custom options
|
|
344
|
+
const user = await authenticate({
|
|
345
|
+
maxAttempts: 120, // 60 seconds (default: 60 = 30 seconds)
|
|
346
|
+
intervalMs: 500 // Check every 500ms
|
|
347
|
+
})
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
#### Platform Features
|
|
351
|
+
|
|
352
|
+
- ✅ **AsyncStorage** - Secure token persistence
|
|
353
|
+
- ✅ **Universal OAuth** - Same code works on web + mobile
|
|
354
|
+
- ✅ **expo-web-browser** - Native browser UI
|
|
355
|
+
- ✅ **No deep linking** - Session-based polling
|
|
356
|
+
- ✅ **Works in Expo Go** - No custom dev client needed
|
|
357
|
+
- ✅ **Auto token refresh** - Seamless sessions
|
|
358
|
+
|
|
240
359
|
## 📖 API Reference
|
|
241
360
|
|
|
242
361
|
### Authentication
|
|
@@ -708,29 +827,56 @@ const { object: todoList } = await blink.ai.generateObject({
|
|
|
708
827
|
// })
|
|
709
828
|
// Error: "schema must be a JSON Schema of 'type: \"object\"', got 'type: \"array\"'"
|
|
710
829
|
|
|
711
|
-
// Generate and modify images with AI
|
|
712
|
-
// 🔥
|
|
830
|
+
// Generate and modify images with AI - Multi-Model Support (10 models available)
|
|
831
|
+
// 🔥 Choose between fast generation or high-quality results
|
|
713
832
|
// 🎨 For style transfer: provide ALL images in the images array, don't reference URLs in prompts
|
|
714
833
|
|
|
715
|
-
// Basic image generation
|
|
834
|
+
// Basic image generation (uses default fast model: fal-ai/nano-banana)
|
|
716
835
|
const { data } = await blink.ai.generateImage({
|
|
717
836
|
prompt: 'A serene landscape with mountains and a lake at sunset'
|
|
718
837
|
})
|
|
719
838
|
console.log('Image URL:', data[0].url)
|
|
720
839
|
|
|
721
|
-
//
|
|
840
|
+
// High-quality generation with Pro model
|
|
841
|
+
const { data: proImage } = await blink.ai.generateImage({
|
|
842
|
+
prompt: 'A detailed infographic about AI with charts and diagrams',
|
|
843
|
+
model: 'fal-ai/nano-banana-pro', // High quality model
|
|
844
|
+
n: 1,
|
|
845
|
+
size: '1792x1024' // Custom size
|
|
846
|
+
})
|
|
847
|
+
|
|
848
|
+
// Generate multiple variations
|
|
722
849
|
const { data } = await blink.ai.generateImage({
|
|
723
850
|
prompt: 'A futuristic robot in different poses',
|
|
851
|
+
model: 'fal-ai/nano-banana', // Fast model
|
|
724
852
|
n: 3
|
|
725
853
|
})
|
|
726
854
|
data.forEach((img, i) => console.log(`Image ${i+1}:`, img.url))
|
|
727
855
|
|
|
728
|
-
|
|
856
|
+
**Available Models for Text-to-Image:**
|
|
857
|
+
|
|
858
|
+
| Model | Speed | Quality | Best For |
|
|
859
|
+
|-------|-------|---------|----------|
|
|
860
|
+
| `fal-ai/nano-banana` (default) | ⚡ Fast | Good | Prototypes, high-volume generation |
|
|
861
|
+
| `fal-ai/nano-banana-pro` | Standard | ⭐ Excellent | Marketing materials, high-fidelity visuals |
|
|
862
|
+
| `fal-ai/gemini-25-flash-image` | ⚡ Fast | Good | Alias for `nano-banana` |
|
|
863
|
+
| `fal-ai/gemini-3-pro-image-preview` | Standard | ⭐ Excellent | Alias for `nano-banana-pro` |
|
|
864
|
+
| `gemini-2.5-flash-image-preview` | ⚡ Fast | Good | Legacy - Direct Gemini API |
|
|
865
|
+
| `gemini-3-pro-image-preview` | Standard | ⭐ Excellent | Legacy - Direct Gemini API |
|
|
866
|
+
|
|
867
|
+
// Image editing - transform existing images with prompts (uses default fast model)
|
|
729
868
|
const { data: headshots } = await blink.ai.modifyImage({
|
|
730
|
-
images: ['https://storage.example.com/user-photo.jpg'], // Up to
|
|
869
|
+
images: ['https://storage.example.com/user-photo.jpg'], // Up to 16 images supported!
|
|
731
870
|
prompt: 'Transform into professional business headshot with studio lighting'
|
|
732
871
|
})
|
|
733
872
|
|
|
873
|
+
// High-quality editing with Pro model
|
|
874
|
+
const { data: proEdited } = await blink.ai.modifyImage({
|
|
875
|
+
images: ['https://storage.example.com/portrait.jpg'],
|
|
876
|
+
prompt: 'Add a majestic ancient tree in the background with glowing leaves',
|
|
877
|
+
model: 'fal-ai/nano-banana-pro/edit' // High quality editing
|
|
878
|
+
})
|
|
879
|
+
|
|
734
880
|
// Advanced image editing with multiple input images
|
|
735
881
|
const { data } = await blink.ai.modifyImage({
|
|
736
882
|
images: [
|
|
@@ -739,9 +885,19 @@ const { data } = await blink.ai.modifyImage({
|
|
|
739
885
|
'https://storage.example.com/photo3.jpg'
|
|
740
886
|
],
|
|
741
887
|
prompt: 'Combine these architectural styles into a futuristic building design',
|
|
888
|
+
model: 'fal-ai/nano-banana/edit', // Fast editing
|
|
742
889
|
n: 2
|
|
743
890
|
})
|
|
744
891
|
|
|
892
|
+
**Available Models for Image Editing:**
|
|
893
|
+
|
|
894
|
+
| Model | Speed | Quality | Best For |
|
|
895
|
+
|-------|-------|---------|----------|
|
|
896
|
+
| `fal-ai/nano-banana/edit` (default) | ⚡ Fast | Good | Quick adjustments, style transfers |
|
|
897
|
+
| `fal-ai/nano-banana-pro/edit` | Standard | ⭐ Excellent | Detailed retouching, complex edits |
|
|
898
|
+
| `fal-ai/gemini-25-flash-image/edit` | ⚡ Fast | Good | Alias for `nano-banana/edit` |
|
|
899
|
+
| `fal-ai/gemini-3-pro-image-preview/edit` | Standard | ⭐ Excellent | Alias for `nano-banana-pro/edit` |
|
|
900
|
+
|
|
745
901
|
// 🎨 Style Transfer & Feature Application
|
|
746
902
|
// ⚠️ IMPORTANT: When applying styles/features from one image to another,
|
|
747
903
|
// provide ALL images in the array - don't reference images in the prompt text
|
package/dist/index.d.mts
CHANGED
|
@@ -82,6 +82,49 @@ interface BlinkClientConfig {
|
|
|
82
82
|
}
|
|
83
83
|
interface BlinkAuthConfig {
|
|
84
84
|
mode?: 'managed' | 'headless';
|
|
85
|
+
/**
|
|
86
|
+
* Automatically detect and extract auth tokens from URL parameters
|
|
87
|
+
*
|
|
88
|
+
* - Web: Set to `true` (default) to handle OAuth redirects
|
|
89
|
+
* - React Native: Set to `false` to use deep links instead
|
|
90
|
+
*
|
|
91
|
+
* @default true
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* // React Native - disable URL detection, use deep links
|
|
95
|
+
* {
|
|
96
|
+
* auth: {
|
|
97
|
+
* detectSessionInUrl: false,
|
|
98
|
+
* storage: AsyncStorageAdapter(AsyncStorage)
|
|
99
|
+
* }
|
|
100
|
+
* }
|
|
101
|
+
*/
|
|
102
|
+
detectSessionInUrl?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* WebBrowser module for React Native OAuth (expo-web-browser)
|
|
105
|
+
*
|
|
106
|
+
* When provided, `signInWithGoogle()` and other OAuth methods will
|
|
107
|
+
* automatically use the mobile session-based flow on React Native,
|
|
108
|
+
* so you don't need platform-specific code.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // React Native setup (configure once)
|
|
112
|
+
* import * as WebBrowser from 'expo-web-browser'
|
|
113
|
+
* import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
114
|
+
*
|
|
115
|
+
* const blink = createClient({
|
|
116
|
+
* projectId: 'your-project',
|
|
117
|
+
* auth: {
|
|
118
|
+
* mode: 'headless',
|
|
119
|
+
* webBrowser: WebBrowser // Pass the module here
|
|
120
|
+
* },
|
|
121
|
+
* storage: new AsyncStorageAdapter(AsyncStorage)
|
|
122
|
+
* })
|
|
123
|
+
*
|
|
124
|
+
* // Now this works on both web and mobile!
|
|
125
|
+
* const user = await blink.auth.signInWithGoogle()
|
|
126
|
+
*/
|
|
127
|
+
webBrowser?: WebBrowserModule;
|
|
85
128
|
email?: {
|
|
86
129
|
requireVerification?: boolean;
|
|
87
130
|
allowSignUp?: boolean;
|
|
@@ -118,6 +161,7 @@ type AuthProvider = 'email' | 'google' | 'github' | 'apple' | 'microsoft' | 'twi
|
|
|
118
161
|
interface AuthOptions {
|
|
119
162
|
redirectUrl?: string;
|
|
120
163
|
metadata?: Record<string, any>;
|
|
164
|
+
useMobileSession?: boolean;
|
|
121
165
|
}
|
|
122
166
|
interface SignUpData {
|
|
123
167
|
email: string;
|
|
@@ -131,6 +175,22 @@ interface SignUpData {
|
|
|
131
175
|
interface MagicLinkOptions {
|
|
132
176
|
redirectUrl?: string;
|
|
133
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* WebBrowser interface for React Native OAuth
|
|
180
|
+
* Compatible with expo-web-browser module
|
|
181
|
+
*
|
|
182
|
+
* Simply pass the expo-web-browser module directly:
|
|
183
|
+
* ```typescript
|
|
184
|
+
* import * as WebBrowser from 'expo-web-browser'
|
|
185
|
+
* const blink = createClient({ auth: { webBrowser: WebBrowser } })
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
interface WebBrowserModule {
|
|
189
|
+
openAuthSessionAsync(url: string, redirectUrl?: string, options?: unknown): Promise<{
|
|
190
|
+
type: string;
|
|
191
|
+
url?: string;
|
|
192
|
+
}>;
|
|
193
|
+
}
|
|
134
194
|
interface BlinkUser {
|
|
135
195
|
id: string;
|
|
136
196
|
email: string;
|
|
@@ -776,7 +836,7 @@ declare class HttpClient {
|
|
|
776
836
|
signal?: AbortSignal;
|
|
777
837
|
}): Promise<BlinkResponse<any>>;
|
|
778
838
|
/**
|
|
779
|
-
* Stream AI text generation
|
|
839
|
+
* Stream AI text generation with Vercel AI SDK data stream format
|
|
780
840
|
*/
|
|
781
841
|
streamAiText(prompt: string, options: {
|
|
782
842
|
model?: string | undefined;
|
|
@@ -800,7 +860,7 @@ declare class HttpClient {
|
|
|
800
860
|
signal?: AbortSignal;
|
|
801
861
|
}): Promise<BlinkResponse<any>>;
|
|
802
862
|
/**
|
|
803
|
-
* Stream AI object generation
|
|
863
|
+
* Stream AI object generation with Vercel AI SDK data stream format
|
|
804
864
|
*/
|
|
805
865
|
streamAiObject(prompt: string, options: {
|
|
806
866
|
model?: string | undefined;
|
|
@@ -881,10 +941,10 @@ declare class HttpClient {
|
|
|
881
941
|
private parseResponse;
|
|
882
942
|
private handleErrorResponse;
|
|
883
943
|
/**
|
|
884
|
-
* Parse Vercel AI SDK
|
|
885
|
-
*
|
|
944
|
+
* Parse Vercel AI SDK data stream format
|
|
945
|
+
* Handles text chunks (0:"text"), partial objects (2:[...]), and metadata (d:, e:)
|
|
886
946
|
*/
|
|
887
|
-
private
|
|
947
|
+
private parseDataStream;
|
|
888
948
|
}
|
|
889
949
|
|
|
890
950
|
/**
|
|
@@ -994,22 +1054,156 @@ declare class BlinkAuth {
|
|
|
994
1054
|
signInWithEmail(email: string, password: string): Promise<BlinkUser>;
|
|
995
1055
|
/**
|
|
996
1056
|
* Sign in with Google (headless mode)
|
|
1057
|
+
*
|
|
1058
|
+
* **Universal OAuth** - Works on both Web and React Native!
|
|
1059
|
+
*
|
|
1060
|
+
* On React Native, requires `webBrowser` to be configured in client:
|
|
1061
|
+
* ```typescript
|
|
1062
|
+
* const blink = createClient({
|
|
1063
|
+
* auth: { mode: 'headless', webBrowser: WebBrowser }
|
|
1064
|
+
* })
|
|
1065
|
+
* await blink.auth.signInWithGoogle() // Works on both platforms!
|
|
1066
|
+
* ```
|
|
997
1067
|
*/
|
|
998
1068
|
signInWithGoogle(options?: AuthOptions): Promise<BlinkUser>;
|
|
999
1069
|
/**
|
|
1000
1070
|
* Sign in with GitHub (headless mode)
|
|
1071
|
+
*
|
|
1072
|
+
* **Universal OAuth** - Works on both Web and React Native!
|
|
1073
|
+
* See signInWithGoogle() for setup instructions.
|
|
1001
1074
|
*/
|
|
1002
1075
|
signInWithGitHub(options?: AuthOptions): Promise<BlinkUser>;
|
|
1003
1076
|
/**
|
|
1004
1077
|
* Sign in with Apple (headless mode)
|
|
1078
|
+
*
|
|
1079
|
+
* **Universal OAuth** - Works on both Web and React Native!
|
|
1080
|
+
* See signInWithGoogle() for setup instructions.
|
|
1005
1081
|
*/
|
|
1006
1082
|
signInWithApple(options?: AuthOptions): Promise<BlinkUser>;
|
|
1007
1083
|
/**
|
|
1008
1084
|
* Sign in with Microsoft (headless mode)
|
|
1085
|
+
*
|
|
1086
|
+
* **Universal OAuth** - Works on both Web and React Native!
|
|
1087
|
+
* See signInWithGoogle() for setup instructions.
|
|
1009
1088
|
*/
|
|
1010
1089
|
signInWithMicrosoft(options?: AuthOptions): Promise<BlinkUser>;
|
|
1090
|
+
/**
|
|
1091
|
+
* Initiate OAuth for mobile without deep linking (expo-web-browser pattern)
|
|
1092
|
+
*
|
|
1093
|
+
* This method:
|
|
1094
|
+
* 1. Generates a unique session ID
|
|
1095
|
+
* 2. Returns OAuth URL with session parameter
|
|
1096
|
+
* 3. App opens URL in expo-web-browser
|
|
1097
|
+
* 4. App polls checkMobileOAuthSession() until complete
|
|
1098
|
+
*
|
|
1099
|
+
* @param provider - OAuth provider (google, github, apple, etc.)
|
|
1100
|
+
* @param options - Optional metadata
|
|
1101
|
+
* @returns Session ID and OAuth URL
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* // React Native with expo-web-browser
|
|
1105
|
+
* import * as WebBrowser from 'expo-web-browser';
|
|
1106
|
+
*
|
|
1107
|
+
* const { sessionId, authUrl } = await blink.auth.initiateMobileOAuth('google');
|
|
1108
|
+
*
|
|
1109
|
+
* // Open browser
|
|
1110
|
+
* await WebBrowser.openAuthSessionAsync(authUrl);
|
|
1111
|
+
*
|
|
1112
|
+
* // Poll for completion
|
|
1113
|
+
* const user = await blink.auth.pollMobileOAuthSession(sessionId);
|
|
1114
|
+
* console.log('Authenticated:', user.email);
|
|
1115
|
+
*/
|
|
1116
|
+
initiateMobileOAuth(provider: AuthProvider, options?: Omit<AuthOptions, 'redirectUrl'>): Promise<{
|
|
1117
|
+
sessionId: string;
|
|
1118
|
+
authUrl: string;
|
|
1119
|
+
}>;
|
|
1120
|
+
/**
|
|
1121
|
+
* Check mobile OAuth session status (single check)
|
|
1122
|
+
*
|
|
1123
|
+
* @param sessionId - Session ID from initiateMobileOAuth
|
|
1124
|
+
* @returns Tokens if session is complete, null if still pending
|
|
1125
|
+
*/
|
|
1126
|
+
checkMobileOAuthSession(sessionId: string): Promise<AuthTokens | null>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Poll mobile OAuth session until complete (convenience method)
|
|
1129
|
+
*
|
|
1130
|
+
* @param sessionId - Session ID from initiateMobileOAuth
|
|
1131
|
+
* @param options - Polling options
|
|
1132
|
+
* @returns Authenticated user
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* const { sessionId, authUrl } = await blink.auth.initiateMobileOAuth('google');
|
|
1136
|
+
* await WebBrowser.openAuthSessionAsync(authUrl);
|
|
1137
|
+
* const user = await blink.auth.pollMobileOAuthSession(sessionId, {
|
|
1138
|
+
* maxAttempts: 60,
|
|
1139
|
+
* intervalMs: 1000
|
|
1140
|
+
* });
|
|
1141
|
+
*/
|
|
1142
|
+
pollMobileOAuthSession(sessionId: string, options?: {
|
|
1143
|
+
maxAttempts?: number;
|
|
1144
|
+
intervalMs?: number;
|
|
1145
|
+
}): Promise<BlinkUser>;
|
|
1146
|
+
/**
|
|
1147
|
+
* Sign in with OAuth provider using expo-web-browser (React Native)
|
|
1148
|
+
*
|
|
1149
|
+
* This is a convenience method that handles the entire flow:
|
|
1150
|
+
* 1. Initiates mobile OAuth session
|
|
1151
|
+
* 2. Returns auth URL to open in WebBrowser
|
|
1152
|
+
* 3. Provides polling function to call after browser opens
|
|
1153
|
+
*
|
|
1154
|
+
* @param provider - OAuth provider
|
|
1155
|
+
* @returns Object with authUrl and authenticate function
|
|
1156
|
+
*
|
|
1157
|
+
* @example
|
|
1158
|
+
* import * as WebBrowser from 'expo-web-browser';
|
|
1159
|
+
*
|
|
1160
|
+
* const { authUrl, authenticate } = await blink.auth.signInWithProviderMobile('google');
|
|
1161
|
+
*
|
|
1162
|
+
* // Open browser
|
|
1163
|
+
* await WebBrowser.openAuthSessionAsync(authUrl);
|
|
1164
|
+
*
|
|
1165
|
+
* // Wait for authentication
|
|
1166
|
+
* const user = await authenticate();
|
|
1167
|
+
*/
|
|
1168
|
+
signInWithProviderMobile(provider: AuthProvider, options?: Omit<AuthOptions, 'redirectUrl'>): Promise<{
|
|
1169
|
+
authUrl: string;
|
|
1170
|
+
authenticate: () => Promise<BlinkUser>;
|
|
1171
|
+
}>;
|
|
1172
|
+
/**
|
|
1173
|
+
* Universal OAuth flow using session-based authentication (internal)
|
|
1174
|
+
* Works on ALL platforms: Web, iOS, Android
|
|
1175
|
+
* Uses expo-web-browser to open auth URL and polls for completion
|
|
1176
|
+
*/
|
|
1177
|
+
private signInWithProviderUniversal;
|
|
1011
1178
|
/**
|
|
1012
1179
|
* Generic provider sign-in method (headless mode)
|
|
1180
|
+
*
|
|
1181
|
+
* **Universal OAuth** - Works seamlessly on both Web and React Native!
|
|
1182
|
+
*
|
|
1183
|
+
* When `webBrowser` is configured in the client, this method automatically
|
|
1184
|
+
* uses the session-based OAuth flow that works on ALL platforms.
|
|
1185
|
+
*
|
|
1186
|
+
* **Universal Setup (configure once, works everywhere):**
|
|
1187
|
+
* ```typescript
|
|
1188
|
+
* import * as WebBrowser from 'expo-web-browser'
|
|
1189
|
+
* import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
1190
|
+
*
|
|
1191
|
+
* const blink = createClient({
|
|
1192
|
+
* projectId: 'your-project',
|
|
1193
|
+
* auth: {
|
|
1194
|
+
* mode: 'headless',
|
|
1195
|
+
* webBrowser: WebBrowser // Pass the module here
|
|
1196
|
+
* },
|
|
1197
|
+
* storage: new AsyncStorageAdapter(AsyncStorage)
|
|
1198
|
+
* })
|
|
1199
|
+
*
|
|
1200
|
+
* // Now this works on ALL platforms - no platform checks needed!
|
|
1201
|
+
* const user = await blink.auth.signInWithGoogle()
|
|
1202
|
+
* ```
|
|
1203
|
+
*
|
|
1204
|
+
* @param provider - OAuth provider (google, github, apple, etc.)
|
|
1205
|
+
* @param options - Optional redirect URL and metadata
|
|
1206
|
+
* @returns Promise that resolves with authenticated user
|
|
1013
1207
|
*/
|
|
1014
1208
|
signInWithProvider(provider: AuthProvider, options?: AuthOptions): Promise<BlinkUser>;
|
|
1015
1209
|
/**
|
|
@@ -1099,6 +1293,40 @@ declare class BlinkAuth {
|
|
|
1099
1293
|
* Manually set tokens (for server-side usage)
|
|
1100
1294
|
*/
|
|
1101
1295
|
setToken(jwt: string, persist?: boolean): Promise<void>;
|
|
1296
|
+
/**
|
|
1297
|
+
* Manually set auth session from tokens (React Native deep link OAuth)
|
|
1298
|
+
*
|
|
1299
|
+
* Use this method to set the user session after receiving tokens from a deep link callback.
|
|
1300
|
+
* This is the React Native equivalent of automatic URL token detection on web.
|
|
1301
|
+
*
|
|
1302
|
+
* @param tokens - Auth tokens received from deep link or OAuth callback
|
|
1303
|
+
* @param persist - Whether to persist tokens to storage (default: true)
|
|
1304
|
+
*
|
|
1305
|
+
* @example
|
|
1306
|
+
* // React Native: Handle deep link OAuth callback
|
|
1307
|
+
* import * as Linking from 'expo-linking'
|
|
1308
|
+
*
|
|
1309
|
+
* Linking.addEventListener('url', async ({ url }) => {
|
|
1310
|
+
* const { queryParams } = Linking.parse(url)
|
|
1311
|
+
*
|
|
1312
|
+
* if (queryParams.access_token) {
|
|
1313
|
+
* await blink.auth.setSession({
|
|
1314
|
+
* access_token: queryParams.access_token,
|
|
1315
|
+
* refresh_token: queryParams.refresh_token,
|
|
1316
|
+
* expires_in: parseInt(queryParams.expires_in) || 3600,
|
|
1317
|
+
* refresh_expires_in: parseInt(queryParams.refresh_expires_in)
|
|
1318
|
+
* })
|
|
1319
|
+
*
|
|
1320
|
+
* console.log('User authenticated:', blink.auth.currentUser())
|
|
1321
|
+
* }
|
|
1322
|
+
* })
|
|
1323
|
+
*/
|
|
1324
|
+
setSession(tokens: {
|
|
1325
|
+
access_token: string;
|
|
1326
|
+
refresh_token?: string;
|
|
1327
|
+
expires_in?: number;
|
|
1328
|
+
refresh_expires_in?: number;
|
|
1329
|
+
}, persist?: boolean): Promise<BlinkUser>;
|
|
1102
1330
|
/**
|
|
1103
1331
|
* Refresh access token using refresh token
|
|
1104
1332
|
*/
|
|
@@ -1123,6 +1351,10 @@ declare class BlinkAuth {
|
|
|
1123
1351
|
* Generate secure random state for OAuth flows
|
|
1124
1352
|
*/
|
|
1125
1353
|
private generateState;
|
|
1354
|
+
/**
|
|
1355
|
+
* Generate unique session ID for mobile OAuth
|
|
1356
|
+
*/
|
|
1357
|
+
private generateSessionId;
|
|
1126
1358
|
/**
|
|
1127
1359
|
* Extract magic link token from URL
|
|
1128
1360
|
*/
|
|
@@ -2064,4 +2296,4 @@ declare class BlinkRealtimeImpl implements BlinkRealtime {
|
|
|
2064
2296
|
onPresence(channelName: string, callback: (users: PresenceUser[]) => void): () => void;
|
|
2065
2297
|
}
|
|
2066
2298
|
|
|
2067
|
-
export { type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkUser, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type ImageGenerationRequest, type ImageGenerationResponse, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenUsage, type TranscriptionRequest, type TranscriptionResponse, type UpdateOptions, type UpsertOptions, WebStorageAdapter, createClient, getDefaultStorageAdapter, isBrowser, isNode, isReactNative, isWeb, platform };
|
|
2299
|
+
export { type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkUser, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type ImageGenerationRequest, type ImageGenerationResponse, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenUsage, type TranscriptionRequest, type TranscriptionResponse, type UpdateOptions, type UpsertOptions, type WebBrowserModule, WebStorageAdapter, createClient, getDefaultStorageAdapter, isBrowser, isNode, isReactNative, isWeb, platform };
|