@blinkdotnew/sdk 0.2.2 → 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/dist/index.mjs CHANGED
@@ -38,12 +38,6 @@ var BlinkAIError = class extends BlinkError {
38
38
  this.name = "BlinkAIError";
39
39
  }
40
40
  };
41
- var BlinkDataError = class extends BlinkError {
42
- constructor(message, status, details) {
43
- super(message, "DATA_ERROR", status, details);
44
- this.name = "BlinkDataError";
45
- }
46
- };
47
41
 
48
42
  // ../core/src/query-builder.ts
49
43
  function buildFilterQuery(condition) {
@@ -536,10 +530,36 @@ var HttpClient = class {
536
530
  /**
537
531
  * Data-specific requests
538
532
  */
539
- async dataExtractFromUrl(url, filename) {
540
- return this.request(`/api/data/${this.projectId}/extract-from-url`, {
533
+ async dataExtractFromUrl(projectId, request) {
534
+ return this.request(`/api/data/${projectId}/extract-from-url`, {
535
+ method: "POST",
536
+ body: JSON.stringify(request)
537
+ });
538
+ }
539
+ async dataExtractFromBlob(projectId, file, chunking, chunkSize) {
540
+ const formData = new FormData();
541
+ formData.append("file", file);
542
+ if (chunking !== void 0) {
543
+ formData.append("chunking", String(chunking));
544
+ }
545
+ if (chunkSize !== void 0) {
546
+ formData.append("chunkSize", String(chunkSize));
547
+ }
548
+ return this.request(`/api/data/${projectId}/extract-from-blob`, {
541
549
  method: "POST",
542
- body: { url, filename }
550
+ body: formData
551
+ });
552
+ }
553
+ async dataScrape(projectId, request) {
554
+ return this.request(`/api/data/${projectId}/scrape`, {
555
+ method: "POST",
556
+ body: JSON.stringify(request)
557
+ });
558
+ }
559
+ async dataScreenshot(projectId, request) {
560
+ return this.request(`/api/data/${projectId}/screenshot`, {
561
+ method: "POST",
562
+ body: JSON.stringify(request)
543
563
  });
544
564
  }
545
565
  /**
@@ -2294,29 +2314,59 @@ var BlinkAIImpl = class {
2294
2314
 
2295
2315
  // src/data.ts
2296
2316
  var BlinkDataImpl = class {
2297
- constructor(httpClient) {
2317
+ constructor(httpClient, projectId) {
2298
2318
  this.httpClient = httpClient;
2299
- }
2300
- async extractFromUrl(url, filename) {
2301
- try {
2302
- const response = await this.httpClient.dataExtractFromUrl(url, filename);
2303
- if (response.data?.chunks) {
2304
- return {
2305
- chunks: response.data.chunks
2306
- };
2307
- } else {
2308
- throw new BlinkDataError("Invalid response format: missing chunks");
2309
- }
2310
- } catch (error) {
2311
- if (error instanceof BlinkDataError) {
2312
- throw error;
2319
+ this.projectId = projectId;
2320
+ }
2321
+ async extractFromUrl(url, options = {}) {
2322
+ const { chunking = false, chunkSize } = options;
2323
+ const request = { url, chunking, chunkSize };
2324
+ const response = await this.httpClient.dataExtractFromUrl(this.projectId, request);
2325
+ return chunking ? response.data.chunks : response.data.text;
2326
+ }
2327
+ async extractFromBlob(file, options = {}) {
2328
+ const { chunking = false, chunkSize } = options;
2329
+ const response = await this.httpClient.dataExtractFromBlob(this.projectId, file, chunking, chunkSize);
2330
+ return chunking ? response.data.chunks : response.data.text;
2331
+ }
2332
+ async scrape(url) {
2333
+ const request = {
2334
+ url,
2335
+ formats: ["markdown", "html", "links", "extract", "metadata"]
2336
+ };
2337
+ const response = await this.httpClient.dataScrape(this.projectId, request);
2338
+ const data = response.data;
2339
+ return {
2340
+ markdown: data.markdown || "",
2341
+ html: data.html || "",
2342
+ metadata: {
2343
+ title: data.metadata?.title || "",
2344
+ description: data.metadata?.description || "",
2345
+ url: data.metadata?.url || url,
2346
+ domain: data.metadata?.domain || new URL(url).hostname,
2347
+ favicon: data.metadata?.favicon,
2348
+ image: data.metadata?.image,
2349
+ author: data.metadata?.author,
2350
+ publishedTime: data.metadata?.publishedTime,
2351
+ modifiedTime: data.metadata?.modifiedTime,
2352
+ type: data.metadata?.type,
2353
+ siteName: data.metadata?.siteName,
2354
+ locale: data.metadata?.locale,
2355
+ keywords: data.metadata?.keywords || []
2356
+ },
2357
+ links: data.links || [],
2358
+ extract: {
2359
+ title: data.extract?.title || data.metadata?.title || "",
2360
+ description: data.extract?.description || data.metadata?.description || "",
2361
+ headings: data.extract?.headings || [],
2362
+ text: data.extract?.text || data.markdown || ""
2313
2363
  }
2314
- throw new BlinkDataError(
2315
- `Data extraction failed: ${error instanceof Error ? error.message : "Unknown error"}`,
2316
- void 0,
2317
- { originalError: error }
2318
- );
2319
- }
2364
+ };
2365
+ }
2366
+ async screenshot(url, options = {}) {
2367
+ const request = { url, ...options };
2368
+ const response = await this.httpClient.dataScreenshot(this.projectId, request);
2369
+ return response.data.url;
2320
2370
  }
2321
2371
  };
2322
2372
 
@@ -2338,7 +2388,7 @@ var BlinkClientImpl = class {
2338
2388
  this.db = new BlinkDatabase(this.httpClient);
2339
2389
  this.storage = new BlinkStorageImpl(this.httpClient);
2340
2390
  this.ai = new BlinkAIImpl(this.httpClient);
2341
- this.data = new BlinkDataImpl(this.httpClient);
2391
+ this.data = new BlinkDataImpl(this.httpClient, config.projectId);
2342
2392
  }
2343
2393
  };
2344
2394
  function createClient(config) {