notte-sdk 0.0.2 → 0.0.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/dist/index.mjs CHANGED
@@ -1259,6 +1259,15 @@ var scrapeWebpage = (options) => (options.client ?? client).post({
1259
1259
  ...options.headers
1260
1260
  }
1261
1261
  });
1262
+ var searchWeb = (options) => (options.client ?? client).post({
1263
+ security: [{ scheme: "bearer", type: "http" }],
1264
+ url: "/search",
1265
+ ...options,
1266
+ headers: {
1267
+ "Content-Type": "application/json",
1268
+ ...options.headers
1269
+ }
1270
+ });
1262
1271
  var scrapeFromHtml = (options) => (options.client ?? client).post({
1263
1272
  security: [{ scheme: "bearer", type: "http" }],
1264
1273
  url: "/scrape_from_html",
@@ -2482,7 +2491,7 @@ var NottePersona = class {
2482
2491
  };
2483
2492
 
2484
2493
  // src/version.ts
2485
- var SDK_VERSION = true ? "0.0.2" : "dev";
2494
+ var SDK_VERSION = true ? "0.0.4" : "dev";
2486
2495
 
2487
2496
  // src/functions.ts
2488
2497
  var NotteFunction = class {
@@ -2568,12 +2577,13 @@ var NotteClient = class {
2568
2577
  throw new Error("API key is required. Provide it via config.apiKey or set the NOTTE_API_KEY environment variable.");
2569
2578
  }
2570
2579
  this.config = {
2571
- baseUrl: config.baseUrl || "https://api.notte.cc",
2580
+ baseUrl: config.baseUrl || process.env.NOTTE_API_URL || "https://api.notte.cc",
2572
2581
  apiKey,
2573
2582
  ...config
2574
2583
  };
2575
2584
  client.setConfig({
2576
- baseUrl: this.config.baseUrl
2585
+ baseUrl: this.config.baseUrl,
2586
+ redirect: "manual"
2577
2587
  });
2578
2588
  client.interceptors.request.use((request) => {
2579
2589
  request.headers.set("Authorization", `Bearer ${this.config.apiKey}`);
@@ -2581,6 +2591,33 @@ var NotteClient = class {
2581
2591
  request.headers.set("x-notte-sdk-version", SDK_VERSION);
2582
2592
  return request;
2583
2593
  });
2594
+ client.interceptors.response.use(async (response, request, opts) => {
2595
+ if ((response.status === 307 || response.status === 308) && response.headers.get("location")) {
2596
+ const location = response.headers.get("location");
2597
+ const headers = new Headers(request.headers);
2598
+ if (new URL(location).origin !== new URL(request.url).origin) {
2599
+ headers.delete("Authorization");
2600
+ }
2601
+ const headerRecord = {};
2602
+ headers.forEach((v, k) => {
2603
+ headerRecord[k] = v;
2604
+ });
2605
+ const redirected = await fetch(location, {
2606
+ method: request.method,
2607
+ headers: headerRecord,
2608
+ body: opts.serializedBody ?? void 0
2609
+ });
2610
+ return redirected;
2611
+ }
2612
+ const ct = response.headers.get("content-type") ?? "";
2613
+ if (ct.split(";")[0]?.trim() === "text/plain") {
2614
+ const body = await response.arrayBuffer();
2615
+ const headers = new Headers(response.headers);
2616
+ headers.set("content-type", "application/json");
2617
+ return new Response(body, { status: response.status, statusText: response.statusText, headers });
2618
+ }
2619
+ return response;
2620
+ });
2584
2621
  }
2585
2622
  /**
2586
2623
  * Create a new session
@@ -2757,6 +2794,7 @@ export {
2757
2794
  profileList,
2758
2795
  scrapeFromHtml,
2759
2796
  scrapeWebpage,
2797
+ searchWeb,
2760
2798
  sessionCookiesGet,
2761
2799
  sessionCookiesSet,
2762
2800
  sessionDebugInfo,