@blinkdotnew/sdk 0.17.2 → 0.17.4

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 CHANGED
@@ -176,8 +176,8 @@ blink.auth.setToken(jwtFromHeader)
176
176
 
177
177
  ```typescript
178
178
  // Login/logout
179
- blink.auth.login(nextUrl?)
180
- blink.auth.logout(redirectUrl?)
179
+ blink.auth.login(nextUrl?) // Redirect to auth page
180
+ blink.auth.logout(redirectUrl?) // Clear tokens and redirect
181
181
 
182
182
  // User management
183
183
  const user = await blink.auth.me()
@@ -197,6 +197,31 @@ const unsubscribe = blink.auth.onAuthStateChanged((state) => {
197
197
  })
198
198
  ```
199
199
 
200
+ #### Login Redirect Behavior
201
+
202
+ When `login()` is called, the SDK automatically determines where to redirect after authentication:
203
+
204
+ ```typescript
205
+ // Automatic redirect (uses current page URL)
206
+ blink.auth.login()
207
+ // → Redirects to: blink.new/auth?redirect_url=https://yourapp.com/current-page
208
+
209
+ // Custom redirect URL
210
+ blink.auth.login('https://yourapp.com/dashboard')
211
+ // → Redirects to: blink.new/auth?redirect_url=https://yourapp.com/dashboard
212
+
213
+ // Manual login button example
214
+ const handleLogin = () => {
215
+ // The SDK will automatically use the current page URL
216
+ blink.auth.login()
217
+
218
+ // Or specify a custom redirect
219
+ // blink.auth.login('https://yourapp.com/welcome')
220
+ }
221
+ ```
222
+
223
+ **✅ Fixed in v1.x**: The SDK now ensures redirect URLs are always absolute, preventing broken redirects when `window.location.href` returns relative paths.
224
+
200
225
  ### Database Operations
201
226
 
202
227
  **🎉 NEW: Automatic Case Conversion!**
@@ -279,13 +304,15 @@ const { text } = await blink.ai.generateText({
279
304
  })
280
305
 
281
306
  // Text generation with image content
307
+ // ⚠️ IMPORTANT: Images must be HTTPS URLs with file extensions (.jpg, .jpeg, .png, .gif, .webp)
308
+ // For file uploads, use blink.storage.upload() first to get public HTTPS URLs
282
309
  const { text } = await blink.ai.generateText({
283
310
  messages: [
284
311
  {
285
312
  role: "user",
286
313
  content: [
287
314
  { type: "text", text: "What do you see in this image?" },
288
- { type: "image", image: "https://example.com/photo.jpg" }
315
+ { type: "image", image: "https://storage.googleapis.com/.../.../photo.jpg" }
289
316
  ]
290
317
  }
291
318
  ]
@@ -298,8 +325,8 @@ const { text } = await blink.ai.generateText({
298
325
  role: "user",
299
326
  content: [
300
327
  { type: "text", text: "Compare these two images:" },
301
- { type: "image", image: "https://example.com/image1.jpg" },
302
- { type: "image", image: "https://example.com/image2.jpg" }
328
+ { type: "image", image: "https://storage.googleapis.com/.../.../image1.jpg" },
329
+ { type: "image", image: "https://cdn.example.com/image2.png" }
303
330
  ]
304
331
  }
305
332
  ]
@@ -1192,26 +1219,6 @@ try {
1192
1219
  console.error('Auth error:', error.message)
1193
1220
  }
1194
1221
  }
1195
-
1196
- // Image validation error handling
1197
- try {
1198
- const { text } = await blink.ai.generateText({
1199
- messages: [
1200
- {
1201
- role: "user",
1202
- content: [
1203
- { type: "text", text: "What's in this image?" },
1204
- { type: "image", image: "http://example.com/image.jpg" } // Invalid: not HTTPS
1205
- ]
1206
- }
1207
- ]
1208
- })
1209
- } catch (error) {
1210
- if (error instanceof BlinkAIError) {
1211
- console.error('AI validation error:', error.message)
1212
- // Example: "Message validation failed: Image URLs must use HTTPS protocol"
1213
- }
1214
- }
1215
1222
  ```
1216
1223
 
1217
1224
  ### Custom Configuration
package/dist/index.js CHANGED
@@ -992,7 +992,14 @@ var BlinkAuth = class {
992
992
  * Redirect to Blink auth page
993
993
  */
994
994
  login(nextUrl) {
995
- let redirectUrl = nextUrl || (typeof window !== "undefined" ? window.location.href : "");
995
+ let redirectUrl = nextUrl;
996
+ if (!redirectUrl && typeof window !== "undefined") {
997
+ if (window.location.href.startsWith("http")) {
998
+ redirectUrl = window.location.href;
999
+ } else {
1000
+ redirectUrl = `${window.location.protocol}//${window.location.host}${window.location.pathname}${window.location.search}${window.location.hash}`;
1001
+ }
1002
+ }
996
1003
  if (redirectUrl && typeof window !== "undefined") {
997
1004
  try {
998
1005
  const url = new URL(redirectUrl);
@@ -1004,7 +1011,7 @@ var BlinkAuth = class {
1004
1011
  }
1005
1012
  }
1006
1013
  const authUrl = new URL("/auth", this.authUrl);
1007
- authUrl.searchParams.set("redirect_url", redirectUrl);
1014
+ authUrl.searchParams.set("redirect_url", redirectUrl || "");
1008
1015
  if (this.config.projectId) {
1009
1016
  authUrl.searchParams.set("project_id", this.config.projectId);
1010
1017
  }
package/dist/index.mjs CHANGED
@@ -990,7 +990,14 @@ var BlinkAuth = class {
990
990
  * Redirect to Blink auth page
991
991
  */
992
992
  login(nextUrl) {
993
- let redirectUrl = nextUrl || (typeof window !== "undefined" ? window.location.href : "");
993
+ let redirectUrl = nextUrl;
994
+ if (!redirectUrl && typeof window !== "undefined") {
995
+ if (window.location.href.startsWith("http")) {
996
+ redirectUrl = window.location.href;
997
+ } else {
998
+ redirectUrl = `${window.location.protocol}//${window.location.host}${window.location.pathname}${window.location.search}${window.location.hash}`;
999
+ }
1000
+ }
994
1001
  if (redirectUrl && typeof window !== "undefined") {
995
1002
  try {
996
1003
  const url = new URL(redirectUrl);
@@ -1002,7 +1009,7 @@ var BlinkAuth = class {
1002
1009
  }
1003
1010
  }
1004
1011
  const authUrl = new URL("/auth", this.authUrl);
1005
- authUrl.searchParams.set("redirect_url", redirectUrl);
1012
+ authUrl.searchParams.set("redirect_url", redirectUrl || "");
1006
1013
  if (this.config.projectId) {
1007
1014
  authUrl.searchParams.set("project_id", this.config.projectId);
1008
1015
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/sdk",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "description": "Blink TypeScript SDK for client-side applications - Zero-boilerplate CRUD + auth + AI + analytics + notifications for modern SaaS/AI apps",
5
5
  "keywords": [
6
6
  "blink",