@blinkdotnew/sdk 0.4.2 β 0.5.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 +114 -2
- package/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +15 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,10 @@ const text = await blink.data.extractFromUrl("https://example.com/document.pdf")
|
|
|
52
52
|
const { markdown, metadata, links } = await blink.data.scrape("https://competitor.com")
|
|
53
53
|
const screenshotUrl = await blink.data.screenshot("https://competitor.com")
|
|
54
54
|
|
|
55
|
+
// Web search (get real-time information)
|
|
56
|
+
const searchResults = await blink.data.search("chatgpt latest news", { type: 'news' })
|
|
57
|
+
const localResults = await blink.data.search("best restaurants", { location: "San Francisco,CA,United States" })
|
|
58
|
+
|
|
55
59
|
// Secure API proxy (call external APIs with secret substitution)
|
|
56
60
|
const response = await blink.data.fetch({
|
|
57
61
|
url: "https://api.sendgrid.com/v3/mail/send",
|
|
@@ -84,7 +88,7 @@ This SDK powers every Blink-generated app with:
|
|
|
84
88
|
- **π Authentication**: JWT-based auth with automatic token management
|
|
85
89
|
- **ποΈ Database**: PostgREST-compatible CRUD operations with advanced filtering
|
|
86
90
|
- **π€ AI**: Text generation with web search, object generation, image creation, speech synthesis, and transcription
|
|
87
|
-
- **π Data**: Extract text content from documents, secure API proxy with secret substitution, web scraping, and
|
|
91
|
+
- **π Data**: Extract text content from documents, secure API proxy with secret substitution, web scraping, screenshots, and web search
|
|
88
92
|
- **π Storage**: File upload, download, and management
|
|
89
93
|
- **π Universal**: Works on client-side and server-side
|
|
90
94
|
- **π± Framework Agnostic**: React, Vue, Svelte, vanilla JS, Node.js, Deno
|
|
@@ -329,8 +333,58 @@ const fullPageUrl = await blink.data.screenshot('https://example.com', {
|
|
|
329
333
|
height: 1080
|
|
330
334
|
});
|
|
331
335
|
|
|
336
|
+
// π₯ Web Search (NEW!) - Google search results with clean structure
|
|
337
|
+
// Perfect for getting real-time information and current data
|
|
338
|
+
|
|
339
|
+
// Basic web search - just provide a query
|
|
340
|
+
const searchResults = await blink.data.search('chatgpt');
|
|
341
|
+
console.log(searchResults.organic_results); // Main search results
|
|
342
|
+
console.log(searchResults.related_searches); // Related search suggestions
|
|
343
|
+
console.log(searchResults.people_also_ask); // People also ask questions
|
|
344
|
+
|
|
345
|
+
// Search with location for local results
|
|
346
|
+
const localResults = await blink.data.search('best restaurants', {
|
|
347
|
+
location: 'San Francisco,CA,United States'
|
|
348
|
+
});
|
|
349
|
+
console.log(localResults.local_results); // Local business results
|
|
350
|
+
console.log(localResults.organic_results); // Regular web results
|
|
351
|
+
|
|
352
|
+
// News search - get latest news articles
|
|
353
|
+
const newsResults = await blink.data.search('artificial intelligence', {
|
|
354
|
+
type: 'news'
|
|
355
|
+
});
|
|
356
|
+
console.log(newsResults.news_results); // News articles with dates and sources
|
|
357
|
+
|
|
358
|
+
// Image search - find images
|
|
359
|
+
const imageResults = await blink.data.search('elon musk', {
|
|
360
|
+
type: 'images',
|
|
361
|
+
limit: 20
|
|
362
|
+
});
|
|
363
|
+
console.log(imageResults.image_results); // Image results with thumbnails
|
|
364
|
+
|
|
365
|
+
// Search in different languages
|
|
366
|
+
const spanishResults = await blink.data.search('noticias tecnologΓa', {
|
|
367
|
+
language: 'es',
|
|
368
|
+
type: 'news'
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// Shopping search - find products
|
|
372
|
+
const shoppingResults = await blink.data.search('macbook pro', {
|
|
373
|
+
type: 'shopping'
|
|
374
|
+
});
|
|
375
|
+
console.log(shoppingResults.shopping_results); // Product results with prices
|
|
376
|
+
|
|
377
|
+
// All search types return consistent, structured data:
|
|
378
|
+
// - organic_results: Main search results (always included)
|
|
379
|
+
// - related_searches: Related search suggestions
|
|
380
|
+
// - people_also_ask: FAQ-style questions and answers
|
|
381
|
+
// - local_results: Local businesses (when location provided)
|
|
382
|
+
// - news_results: News articles (when type='news')
|
|
383
|
+
// - image_results: Images (when type='images')
|
|
384
|
+
// - shopping_results: Products (when type='shopping')
|
|
385
|
+
// - ads: Sponsored results (when present)
|
|
386
|
+
|
|
332
387
|
// π₯ Secure API Proxy (NEW!) - Make API calls with secret substitution
|
|
333
|
-
// Perfect for calling external APIs from frontend while keeping API keys safe
|
|
334
388
|
|
|
335
389
|
// Basic API call with secret substitution
|
|
336
390
|
const response = await blink.data.fetch({
|
|
@@ -563,6 +617,64 @@ function App() {
|
|
|
563
617
|
return <div>Welcome, {user.email}!</div>
|
|
564
618
|
}
|
|
565
619
|
|
|
620
|
+
// React example with search functionality
|
|
621
|
+
function SearchResults() {
|
|
622
|
+
const [query, setQuery] = useState('')
|
|
623
|
+
const [results, setResults] = useState(null)
|
|
624
|
+
const [loading, setLoading] = useState(false)
|
|
625
|
+
|
|
626
|
+
const handleSearch = async () => {
|
|
627
|
+
if (!query.trim()) return
|
|
628
|
+
|
|
629
|
+
setLoading(true)
|
|
630
|
+
try {
|
|
631
|
+
const searchResults = await blink.data.search(query, {
|
|
632
|
+
type: 'news', // Get latest news
|
|
633
|
+
limit: 10
|
|
634
|
+
})
|
|
635
|
+
setResults(searchResults)
|
|
636
|
+
} catch (error) {
|
|
637
|
+
console.error('Search failed:', error)
|
|
638
|
+
} finally {
|
|
639
|
+
setLoading(false)
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
return (
|
|
644
|
+
<div>
|
|
645
|
+
<input
|
|
646
|
+
value={query}
|
|
647
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
648
|
+
placeholder="Search for news..."
|
|
649
|
+
onKeyPress={(e) => e.key === 'Enter' && handleSearch()}
|
|
650
|
+
/>
|
|
651
|
+
<button onClick={handleSearch} disabled={loading}>
|
|
652
|
+
{loading ? 'Searching...' : 'Search'}
|
|
653
|
+
</button>
|
|
654
|
+
|
|
655
|
+
{results && (
|
|
656
|
+
<div>
|
|
657
|
+
<h3>News Results:</h3>
|
|
658
|
+
{results.news_results?.map((article, i) => (
|
|
659
|
+
<div key={i}>
|
|
660
|
+
<h4><a href={article.link}>{article.title}</a></h4>
|
|
661
|
+
<p>{article.snippet}</p>
|
|
662
|
+
<small>{article.source} - {article.date}</small>
|
|
663
|
+
</div>
|
|
664
|
+
))}
|
|
665
|
+
|
|
666
|
+
<h3>Related Searches:</h3>
|
|
667
|
+
{results.related_searches?.map((suggestion, i) => (
|
|
668
|
+
<button key={i} onClick={() => setQuery(suggestion)}>
|
|
669
|
+
{suggestion}
|
|
670
|
+
</button>
|
|
671
|
+
))}
|
|
672
|
+
</div>
|
|
673
|
+
)}
|
|
674
|
+
</div>
|
|
675
|
+
)
|
|
676
|
+
}
|
|
677
|
+
|
|
566
678
|
// React example with secure API calls
|
|
567
679
|
function EmailSender() {
|
|
568
680
|
const [status, setStatus] = useState('')
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlinkClientConfig, BlinkUser, AuthState, HttpClient, TableOperations, CreateOptions, UpsertOptions, QueryOptions, ListResponse, UpdateOptions, FilterCondition, ScrapeResult, FetchRequest, FetchResponse, AsyncFetchResponse, BlinkStorage, BlinkAI, StorageUploadOptions, StorageUploadResponse, TextGenerationRequest, TextGenerationResponse, ObjectGenerationRequest, ObjectGenerationResponse, ImageGenerationRequest, ImageGenerationResponse, SpeechGenerationRequest, SpeechGenerationResponse, TranscriptionRequest, TranscriptionResponse } from '@blink/core';
|
|
1
|
+
import { BlinkClientConfig, BlinkUser, AuthState, HttpClient, TableOperations, CreateOptions, UpsertOptions, QueryOptions, ListResponse, UpdateOptions, FilterCondition, ScrapeResult, FetchRequest, FetchResponse, AsyncFetchResponse, SearchResponse, BlinkStorage, BlinkAI, StorageUploadOptions, StorageUploadResponse, TextGenerationRequest, TextGenerationResponse, ObjectGenerationRequest, ObjectGenerationResponse, ImageGenerationRequest, ImageGenerationResponse, SpeechGenerationRequest, SpeechGenerationResponse, TranscriptionRequest, TranscriptionResponse } from '@blink/core';
|
|
2
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
|
/**
|
|
@@ -213,6 +213,12 @@ interface BlinkData {
|
|
|
213
213
|
}): Promise<string>;
|
|
214
214
|
fetch(request: FetchRequest): Promise<FetchResponse>;
|
|
215
215
|
fetchAsync(request: Omit<FetchRequest, 'async'>): Promise<AsyncFetchResponse>;
|
|
216
|
+
search(query: string, options?: {
|
|
217
|
+
location?: string;
|
|
218
|
+
type?: 'news' | 'images' | 'videos' | 'shopping';
|
|
219
|
+
language?: string;
|
|
220
|
+
limit?: number;
|
|
221
|
+
}): Promise<SearchResponse>;
|
|
216
222
|
}
|
|
217
223
|
declare class BlinkDataImpl implements BlinkData {
|
|
218
224
|
private httpClient;
|
|
@@ -234,6 +240,12 @@ declare class BlinkDataImpl implements BlinkData {
|
|
|
234
240
|
}): Promise<string>;
|
|
235
241
|
fetch(request: FetchRequest): Promise<FetchResponse>;
|
|
236
242
|
fetchAsync(request: Omit<FetchRequest, 'async'>): Promise<AsyncFetchResponse>;
|
|
243
|
+
search(query: string, options?: {
|
|
244
|
+
location?: string;
|
|
245
|
+
type?: 'news' | 'images' | 'videos' | 'shopping';
|
|
246
|
+
language?: string;
|
|
247
|
+
limit?: number;
|
|
248
|
+
}): Promise<SearchResponse>;
|
|
237
249
|
}
|
|
238
250
|
|
|
239
251
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlinkClientConfig, BlinkUser, AuthState, HttpClient, TableOperations, CreateOptions, UpsertOptions, QueryOptions, ListResponse, UpdateOptions, FilterCondition, ScrapeResult, FetchRequest, FetchResponse, AsyncFetchResponse, BlinkStorage, BlinkAI, StorageUploadOptions, StorageUploadResponse, TextGenerationRequest, TextGenerationResponse, ObjectGenerationRequest, ObjectGenerationResponse, ImageGenerationRequest, ImageGenerationResponse, SpeechGenerationRequest, SpeechGenerationResponse, TranscriptionRequest, TranscriptionResponse } from '@blink/core';
|
|
1
|
+
import { BlinkClientConfig, BlinkUser, AuthState, HttpClient, TableOperations, CreateOptions, UpsertOptions, QueryOptions, ListResponse, UpdateOptions, FilterCondition, ScrapeResult, FetchRequest, FetchResponse, AsyncFetchResponse, SearchResponse, BlinkStorage, BlinkAI, StorageUploadOptions, StorageUploadResponse, TextGenerationRequest, TextGenerationResponse, ObjectGenerationRequest, ObjectGenerationResponse, ImageGenerationRequest, ImageGenerationResponse, SpeechGenerationRequest, SpeechGenerationResponse, TranscriptionRequest, TranscriptionResponse } from '@blink/core';
|
|
2
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
|
/**
|
|
@@ -213,6 +213,12 @@ interface BlinkData {
|
|
|
213
213
|
}): Promise<string>;
|
|
214
214
|
fetch(request: FetchRequest): Promise<FetchResponse>;
|
|
215
215
|
fetchAsync(request: Omit<FetchRequest, 'async'>): Promise<AsyncFetchResponse>;
|
|
216
|
+
search(query: string, options?: {
|
|
217
|
+
location?: string;
|
|
218
|
+
type?: 'news' | 'images' | 'videos' | 'shopping';
|
|
219
|
+
language?: string;
|
|
220
|
+
limit?: number;
|
|
221
|
+
}): Promise<SearchResponse>;
|
|
216
222
|
}
|
|
217
223
|
declare class BlinkDataImpl implements BlinkData {
|
|
218
224
|
private httpClient;
|
|
@@ -234,6 +240,12 @@ declare class BlinkDataImpl implements BlinkData {
|
|
|
234
240
|
}): Promise<string>;
|
|
235
241
|
fetch(request: FetchRequest): Promise<FetchResponse>;
|
|
236
242
|
fetchAsync(request: Omit<FetchRequest, 'async'>): Promise<AsyncFetchResponse>;
|
|
243
|
+
search(query: string, options?: {
|
|
244
|
+
location?: string;
|
|
245
|
+
type?: 'news' | 'images' | 'videos' | 'shopping';
|
|
246
|
+
language?: string;
|
|
247
|
+
limit?: number;
|
|
248
|
+
}): Promise<SearchResponse>;
|
|
237
249
|
}
|
|
238
250
|
|
|
239
251
|
/**
|
package/dist/index.js
CHANGED
|
@@ -571,10 +571,10 @@ var HttpClient = class {
|
|
|
571
571
|
});
|
|
572
572
|
}
|
|
573
573
|
async dataFetch(projectId, request) {
|
|
574
|
-
return this.
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
});
|
|
574
|
+
return this.post(`/api/data/${projectId}/fetch`, request);
|
|
575
|
+
}
|
|
576
|
+
async dataSearch(projectId, request) {
|
|
577
|
+
return this.post(`/api/data/${projectId}/search`, request);
|
|
578
578
|
}
|
|
579
579
|
/**
|
|
580
580
|
* Private helper methods
|
|
@@ -2419,6 +2419,17 @@ var BlinkDataImpl = class {
|
|
|
2419
2419
|
}
|
|
2420
2420
|
throw new BlinkDataError("Unexpected response format from async fetch endpoint");
|
|
2421
2421
|
}
|
|
2422
|
+
async search(query, options) {
|
|
2423
|
+
const request = {
|
|
2424
|
+
q: query,
|
|
2425
|
+
location: options?.location,
|
|
2426
|
+
hl: options?.language || "en",
|
|
2427
|
+
tbm: options?.type === "news" ? "nws" : options?.type === "images" ? "isch" : options?.type === "videos" ? "vid" : options?.type === "shopping" ? "shop" : void 0,
|
|
2428
|
+
num: options?.limit
|
|
2429
|
+
};
|
|
2430
|
+
const response = await this.httpClient.dataSearch(this.projectId, request);
|
|
2431
|
+
return response.data;
|
|
2432
|
+
}
|
|
2422
2433
|
};
|
|
2423
2434
|
|
|
2424
2435
|
// src/client.ts
|