@blinkdotnew/sdk 0.2.1 → 0.3.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/README.md CHANGED
@@ -45,6 +45,13 @@ const { text } = await blink.ai.generateText({
45
45
  prompt: "Write a summary of the user's todos"
46
46
  })
47
47
 
48
+ // Data operations (extract text from documents)
49
+ const text = await blink.data.extractFromUrl("https://example.com/document.pdf")
50
+
51
+ // Website scraping and screenshots (crystal clear results!)
52
+ const { markdown, metadata, links } = await blink.data.scrape("https://competitor.com")
53
+ const screenshotUrl = await blink.data.screenshot("https://competitor.com")
54
+
48
55
  // Storage operations (instant - returns public URL directly)
49
56
  const { publicUrl } = await blink.storage.upload(
50
57
  file,
@@ -69,6 +76,7 @@ This SDK powers every Blink-generated app with:
69
76
  - **🔐 Authentication**: JWT-based auth with automatic token management
70
77
  - **🗄️ Database**: PostgREST-compatible CRUD operations with advanced filtering
71
78
  - **🤖 AI**: Text generation, object generation, image creation, speech synthesis, and transcription
79
+ - **📄 Data**: Extract text content from documents, spreadsheets, and more
72
80
  - **📁 Storage**: File upload, download, and management
73
81
  - **🌐 Universal**: Works on client-side and server-side
74
82
  - **📱 Framework Agnostic**: React, Vue, Svelte, vanilla JS, Node.js, Deno
@@ -241,6 +249,68 @@ await blink.ai.streamText(
241
249
  )
242
250
  ```
243
251
 
252
+ ### Data Operations
253
+
254
+ ```typescript
255
+ // Simple text extraction (default - returns single string)
256
+ const text = await blink.data.extractFromUrl('https://example.com/document.pdf');
257
+ console.log(typeof text); // 'string'
258
+
259
+ // Extract with chunking enabled
260
+ const chunks = await blink.data.extractFromUrl('https://example.com/document.pdf', {
261
+ chunking: true,
262
+ chunkSize: 2000
263
+ });
264
+ console.log(Array.isArray(chunks)); // true
265
+
266
+ // Extract from different file types
267
+ const csvText = await blink.data.extractFromUrl('https://example.com/data.csv');
268
+ const htmlText = await blink.data.extractFromUrl('https://example.com/page.html');
269
+ const jsonText = await blink.data.extractFromUrl('https://example.com/config.json');
270
+
271
+ // Extract from uploaded file blob (simple)
272
+ const fileInput = document.getElementById('fileInput') as HTMLInputElement;
273
+ const file = fileInput.files[0];
274
+ const extractedText = await blink.data.extractFromBlob(file);
275
+
276
+ // Extract from uploaded file blob (with chunking)
277
+ const chunks = await blink.data.extractFromBlob(file, {
278
+ chunking: true,
279
+ chunkSize: 3000
280
+ });
281
+
282
+ // Website scraping (NEW!) - Crystal clear destructuring
283
+ const { markdown, metadata, links, extract } = await blink.data.scrape('https://example.com');
284
+ console.log(markdown); // Clean markdown content
285
+ console.log(metadata.title); // Page title
286
+ console.log(links.length); // Number of links found
287
+
288
+ // Even cleaner - destructure only what you need
289
+ const { metadata, extract } = await blink.data.scrape('https://blog.example.com/article');
290
+ console.log(metadata.title); // Always available
291
+ console.log(extract.headings); // Always an array
292
+
293
+ // Website screenshots (NEW!)
294
+ const screenshotUrl = await blink.data.screenshot('https://example.com');
295
+ console.log(screenshotUrl); // Direct URL to screenshot image
296
+
297
+ // Full-page screenshot with custom dimensions
298
+ const fullPageUrl = await blink.data.screenshot('https://example.com', {
299
+ fullPage: true,
300
+ width: 1920,
301
+ height: 1080
302
+ });
303
+
304
+ // Error handling for data extraction
305
+ try {
306
+ const result = await blink.data.extractFromUrl('https://example.com/huge-file.pdf');
307
+ } catch (error) {
308
+ if (error instanceof BlinkDataError) {
309
+ console.error('Data processing error:', error.message);
310
+ }
311
+ }
312
+ ```
313
+
244
314
  ### Storage Operations
245
315
 
246
316
  ```typescript
@@ -263,7 +333,7 @@ await blink.storage.remove('file1.jpg', 'file2.jpg')
263
333
  ### Error Handling
264
334
 
265
335
  ```typescript
266
- import { BlinkAuthError, BlinkAIError, BlinkStorageError } from '@blinkdotnew/sdk'
336
+ import { BlinkAuthError, BlinkAIError, BlinkStorageError, BlinkDataError } from '@blinkdotnew/sdk'
267
337
 
268
338
  try {
269
339
  const user = await blink.auth.me()
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { BlinkClientConfig, BlinkUser, AuthState, HttpClient, TableOperations, CreateOptions, UpsertOptions, QueryOptions, ListResponse, UpdateOptions, FilterCondition, BlinkStorage, BlinkAI, StorageUploadOptions, StorageUploadResponse, TextGenerationRequest, TextGenerationResponse, ObjectGenerationRequest, ObjectGenerationResponse, ImageGenerationRequest, ImageGenerationResponse, SpeechGenerationRequest, SpeechGenerationResponse, TranscriptionRequest, TranscriptionResponse } from '@blink/core';
2
- export { AuthState, AuthTokens, BlinkAI, BlinkClientConfig, BlinkStorage, BlinkUser, CreateOptions, FileObject, FilterCondition, ImageGenerationRequest, ImageGenerationResponse, ListResponse, Message, ObjectGenerationRequest, ObjectGenerationResponse, QueryOptions, SpeechGenerationRequest, SpeechGenerationResponse, StorageUploadOptions, StorageUploadResponse, TableOperations, TextGenerationRequest, TextGenerationResponse, TokenUsage, TranscriptionRequest, TranscriptionResponse, UpdateOptions, UpsertOptions } from '@blink/core';
1
+ import { BlinkClientConfig, BlinkUser, AuthState, HttpClient, TableOperations, CreateOptions, UpsertOptions, QueryOptions, ListResponse, UpdateOptions, FilterCondition, ScrapeResult, BlinkStorage, BlinkAI, StorageUploadOptions, StorageUploadResponse, TextGenerationRequest, TextGenerationResponse, ObjectGenerationRequest, ObjectGenerationResponse, ImageGenerationRequest, ImageGenerationResponse, SpeechGenerationRequest, SpeechGenerationResponse, TranscriptionRequest, TranscriptionResponse } from '@blink/core';
2
+ export { AuthState, AuthTokens, BlinkAI, BlinkClientConfig, BlinkData, BlinkStorage, BlinkUser, CreateOptions, DataExtraction, FileObject, FilterCondition, ImageGenerationRequest, ImageGenerationResponse, ListResponse, Message, ObjectGenerationRequest, ObjectGenerationResponse, QueryOptions, SpeechGenerationRequest, SpeechGenerationResponse, StorageUploadOptions, StorageUploadResponse, TableOperations, TextGenerationRequest, TextGenerationResponse, TokenUsage, TranscriptionRequest, TranscriptionResponse, UpdateOptions, UpsertOptions } from '@blink/core';
3
3
 
4
4
  /**
5
5
  * Blink Auth Module - Client-side authentication management
@@ -196,6 +196,42 @@ declare class BlinkDatabase {
196
196
  }>;
197
197
  }
198
198
 
199
+ interface BlinkData {
200
+ extractFromUrl(url: string, options?: {
201
+ chunking?: boolean;
202
+ chunkSize?: number;
203
+ }): Promise<string | string[]>;
204
+ extractFromBlob(file: File, options?: {
205
+ chunking?: boolean;
206
+ chunkSize?: number;
207
+ }): Promise<string | string[]>;
208
+ scrape(url: string): Promise<ScrapeResult>;
209
+ screenshot(url: string, options?: {
210
+ fullPage?: boolean;
211
+ width?: number;
212
+ height?: number;
213
+ }): Promise<string>;
214
+ }
215
+ declare class BlinkDataImpl implements BlinkData {
216
+ private httpClient;
217
+ private projectId;
218
+ constructor(httpClient: HttpClient, projectId: string);
219
+ extractFromUrl(url: string, options?: {
220
+ chunking?: boolean;
221
+ chunkSize?: number;
222
+ }): Promise<string | string[]>;
223
+ extractFromBlob(file: File, options?: {
224
+ chunking?: boolean;
225
+ chunkSize?: number;
226
+ }): Promise<string | string[]>;
227
+ scrape(url: string): Promise<ScrapeResult>;
228
+ screenshot(url: string, options?: {
229
+ fullPage?: boolean;
230
+ width?: number;
231
+ height?: number;
232
+ }): Promise<string>;
233
+ }
234
+
199
235
  /**
200
236
  * Blink Client - Main SDK entry point
201
237
  * Factory function and client class for the Blink SDK
@@ -206,6 +242,7 @@ interface BlinkClient {
206
242
  db: BlinkDatabase;
207
243
  storage: BlinkStorage;
208
244
  ai: BlinkAI;
245
+ data: BlinkData;
209
246
  }
210
247
  /**
211
248
  * Create a new Blink client instance
@@ -596,4 +633,4 @@ declare class BlinkAIImpl implements BlinkAI {
596
633
  transcribeAudio(options: TranscriptionRequest): Promise<TranscriptionResponse>;
597
634
  }
598
635
 
599
- export { type AuthStateChangeCallback, BlinkAIImpl, type BlinkClient, BlinkDatabase, BlinkStorageImpl, BlinkTable, createClient };
636
+ export { type AuthStateChangeCallback, BlinkAIImpl, type BlinkClient, BlinkDataImpl, BlinkDatabase, BlinkStorageImpl, BlinkTable, createClient };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { BlinkClientConfig, BlinkUser, AuthState, HttpClient, TableOperations, CreateOptions, UpsertOptions, QueryOptions, ListResponse, UpdateOptions, FilterCondition, BlinkStorage, BlinkAI, StorageUploadOptions, StorageUploadResponse, TextGenerationRequest, TextGenerationResponse, ObjectGenerationRequest, ObjectGenerationResponse, ImageGenerationRequest, ImageGenerationResponse, SpeechGenerationRequest, SpeechGenerationResponse, TranscriptionRequest, TranscriptionResponse } from '@blink/core';
2
- export { AuthState, AuthTokens, BlinkAI, BlinkClientConfig, BlinkStorage, BlinkUser, CreateOptions, FileObject, FilterCondition, ImageGenerationRequest, ImageGenerationResponse, ListResponse, Message, ObjectGenerationRequest, ObjectGenerationResponse, QueryOptions, SpeechGenerationRequest, SpeechGenerationResponse, StorageUploadOptions, StorageUploadResponse, TableOperations, TextGenerationRequest, TextGenerationResponse, TokenUsage, TranscriptionRequest, TranscriptionResponse, UpdateOptions, UpsertOptions } from '@blink/core';
1
+ import { BlinkClientConfig, BlinkUser, AuthState, HttpClient, TableOperations, CreateOptions, UpsertOptions, QueryOptions, ListResponse, UpdateOptions, FilterCondition, ScrapeResult, BlinkStorage, BlinkAI, StorageUploadOptions, StorageUploadResponse, TextGenerationRequest, TextGenerationResponse, ObjectGenerationRequest, ObjectGenerationResponse, ImageGenerationRequest, ImageGenerationResponse, SpeechGenerationRequest, SpeechGenerationResponse, TranscriptionRequest, TranscriptionResponse } from '@blink/core';
2
+ export { AuthState, AuthTokens, BlinkAI, BlinkClientConfig, BlinkData, BlinkStorage, BlinkUser, CreateOptions, DataExtraction, FileObject, FilterCondition, ImageGenerationRequest, ImageGenerationResponse, ListResponse, Message, ObjectGenerationRequest, ObjectGenerationResponse, QueryOptions, SpeechGenerationRequest, SpeechGenerationResponse, StorageUploadOptions, StorageUploadResponse, TableOperations, TextGenerationRequest, TextGenerationResponse, TokenUsage, TranscriptionRequest, TranscriptionResponse, UpdateOptions, UpsertOptions } from '@blink/core';
3
3
 
4
4
  /**
5
5
  * Blink Auth Module - Client-side authentication management
@@ -196,6 +196,42 @@ declare class BlinkDatabase {
196
196
  }>;
197
197
  }
198
198
 
199
+ interface BlinkData {
200
+ extractFromUrl(url: string, options?: {
201
+ chunking?: boolean;
202
+ chunkSize?: number;
203
+ }): Promise<string | string[]>;
204
+ extractFromBlob(file: File, options?: {
205
+ chunking?: boolean;
206
+ chunkSize?: number;
207
+ }): Promise<string | string[]>;
208
+ scrape(url: string): Promise<ScrapeResult>;
209
+ screenshot(url: string, options?: {
210
+ fullPage?: boolean;
211
+ width?: number;
212
+ height?: number;
213
+ }): Promise<string>;
214
+ }
215
+ declare class BlinkDataImpl implements BlinkData {
216
+ private httpClient;
217
+ private projectId;
218
+ constructor(httpClient: HttpClient, projectId: string);
219
+ extractFromUrl(url: string, options?: {
220
+ chunking?: boolean;
221
+ chunkSize?: number;
222
+ }): Promise<string | string[]>;
223
+ extractFromBlob(file: File, options?: {
224
+ chunking?: boolean;
225
+ chunkSize?: number;
226
+ }): Promise<string | string[]>;
227
+ scrape(url: string): Promise<ScrapeResult>;
228
+ screenshot(url: string, options?: {
229
+ fullPage?: boolean;
230
+ width?: number;
231
+ height?: number;
232
+ }): Promise<string>;
233
+ }
234
+
199
235
  /**
200
236
  * Blink Client - Main SDK entry point
201
237
  * Factory function and client class for the Blink SDK
@@ -206,6 +242,7 @@ interface BlinkClient {
206
242
  db: BlinkDatabase;
207
243
  storage: BlinkStorage;
208
244
  ai: BlinkAI;
245
+ data: BlinkData;
209
246
  }
210
247
  /**
211
248
  * Create a new Blink client instance
@@ -596,4 +633,4 @@ declare class BlinkAIImpl implements BlinkAI {
596
633
  transcribeAudio(options: TranscriptionRequest): Promise<TranscriptionResponse>;
597
634
  }
598
635
 
599
- export { type AuthStateChangeCallback, BlinkAIImpl, type BlinkClient, BlinkDatabase, BlinkStorageImpl, BlinkTable, createClient };
636
+ export { type AuthStateChangeCallback, BlinkAIImpl, type BlinkClient, BlinkDataImpl, BlinkDatabase, BlinkStorageImpl, BlinkTable, createClient };
package/dist/index.js CHANGED
@@ -529,6 +529,41 @@ var HttpClient = class {
529
529
  signal
530
530
  });
531
531
  }
532
+ /**
533
+ * Data-specific requests
534
+ */
535
+ async dataExtractFromUrl(projectId, request) {
536
+ return this.request(`/api/data/${projectId}/extract-from-url`, {
537
+ method: "POST",
538
+ body: JSON.stringify(request)
539
+ });
540
+ }
541
+ async dataExtractFromBlob(projectId, file, chunking, chunkSize) {
542
+ const formData = new FormData();
543
+ formData.append("file", file);
544
+ if (chunking !== void 0) {
545
+ formData.append("chunking", String(chunking));
546
+ }
547
+ if (chunkSize !== void 0) {
548
+ formData.append("chunkSize", String(chunkSize));
549
+ }
550
+ return this.request(`/api/data/${projectId}/extract-from-blob`, {
551
+ method: "POST",
552
+ body: formData
553
+ });
554
+ }
555
+ async dataScrape(projectId, request) {
556
+ return this.request(`/api/data/${projectId}/scrape`, {
557
+ method: "POST",
558
+ body: JSON.stringify(request)
559
+ });
560
+ }
561
+ async dataScreenshot(projectId, request) {
562
+ return this.request(`/api/data/${projectId}/screenshot`, {
563
+ method: "POST",
564
+ body: JSON.stringify(request)
565
+ });
566
+ }
532
567
  /**
533
568
  * Private helper methods
534
569
  */
@@ -2279,12 +2314,71 @@ var BlinkAIImpl = class {
2279
2314
  }
2280
2315
  };
2281
2316
 
2317
+ // src/data.ts
2318
+ var BlinkDataImpl = class {
2319
+ constructor(httpClient, projectId) {
2320
+ this.httpClient = httpClient;
2321
+ this.projectId = projectId;
2322
+ }
2323
+ async extractFromUrl(url, options = {}) {
2324
+ const { chunking = false, chunkSize } = options;
2325
+ const request = { url, chunking, chunkSize };
2326
+ const response = await this.httpClient.dataExtractFromUrl(this.projectId, request);
2327
+ return chunking ? response.data.chunks : response.data.text;
2328
+ }
2329
+ async extractFromBlob(file, options = {}) {
2330
+ const { chunking = false, chunkSize } = options;
2331
+ const response = await this.httpClient.dataExtractFromBlob(this.projectId, file, chunking, chunkSize);
2332
+ return chunking ? response.data.chunks : response.data.text;
2333
+ }
2334
+ async scrape(url) {
2335
+ const request = {
2336
+ url,
2337
+ formats: ["markdown", "html", "links", "extract", "metadata"]
2338
+ };
2339
+ const response = await this.httpClient.dataScrape(this.projectId, request);
2340
+ const data = response.data;
2341
+ return {
2342
+ markdown: data.markdown || "",
2343
+ html: data.html || "",
2344
+ metadata: {
2345
+ title: data.metadata?.title || "",
2346
+ description: data.metadata?.description || "",
2347
+ url: data.metadata?.url || url,
2348
+ domain: data.metadata?.domain || new URL(url).hostname,
2349
+ favicon: data.metadata?.favicon,
2350
+ image: data.metadata?.image,
2351
+ author: data.metadata?.author,
2352
+ publishedTime: data.metadata?.publishedTime,
2353
+ modifiedTime: data.metadata?.modifiedTime,
2354
+ type: data.metadata?.type,
2355
+ siteName: data.metadata?.siteName,
2356
+ locale: data.metadata?.locale,
2357
+ keywords: data.metadata?.keywords || []
2358
+ },
2359
+ links: data.links || [],
2360
+ extract: {
2361
+ title: data.extract?.title || data.metadata?.title || "",
2362
+ description: data.extract?.description || data.metadata?.description || "",
2363
+ headings: data.extract?.headings || [],
2364
+ text: data.extract?.text || data.markdown || ""
2365
+ }
2366
+ };
2367
+ }
2368
+ async screenshot(url, options = {}) {
2369
+ const request = { url, ...options };
2370
+ const response = await this.httpClient.dataScreenshot(this.projectId, request);
2371
+ return response.data.url;
2372
+ }
2373
+ };
2374
+
2282
2375
  // src/client.ts
2283
2376
  var BlinkClientImpl = class {
2284
2377
  auth;
2285
2378
  db;
2286
2379
  storage;
2287
2380
  ai;
2381
+ data;
2288
2382
  httpClient;
2289
2383
  constructor(config) {
2290
2384
  this.auth = new BlinkAuth(config);
@@ -2296,6 +2390,7 @@ var BlinkClientImpl = class {
2296
2390
  this.db = new BlinkDatabase(this.httpClient);
2297
2391
  this.storage = new BlinkStorageImpl(this.httpClient);
2298
2392
  this.ai = new BlinkAIImpl(this.httpClient);
2393
+ this.data = new BlinkDataImpl(this.httpClient, config.projectId);
2299
2394
  }
2300
2395
  };
2301
2396
  function createClient(config) {
@@ -2310,6 +2405,7 @@ function createClient(config) {
2310
2405
  }
2311
2406
 
2312
2407
  exports.BlinkAIImpl = BlinkAIImpl;
2408
+ exports.BlinkDataImpl = BlinkDataImpl;
2313
2409
  exports.BlinkDatabase = BlinkDatabase;
2314
2410
  exports.BlinkStorageImpl = BlinkStorageImpl;
2315
2411
  exports.BlinkTable = BlinkTable;