notte-sdk 0.0.2 → 0.0.3

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.js CHANGED
@@ -2587,7 +2587,7 @@ var NottePersona = class {
2587
2587
  };
2588
2588
 
2589
2589
  // src/version.ts
2590
- var SDK_VERSION = true ? "0.0.2" : "dev";
2590
+ var SDK_VERSION = true ? "0.0.3" : "dev";
2591
2591
 
2592
2592
  // src/functions.ts
2593
2593
  var NotteFunction = class {
@@ -2673,12 +2673,13 @@ var NotteClient = class {
2673
2673
  throw new Error("API key is required. Provide it via config.apiKey or set the NOTTE_API_KEY environment variable.");
2674
2674
  }
2675
2675
  this.config = {
2676
- baseUrl: config.baseUrl || "https://api.notte.cc",
2676
+ baseUrl: config.baseUrl || process.env.NOTTE_API_URL || "https://api.notte.cc",
2677
2677
  apiKey,
2678
2678
  ...config
2679
2679
  };
2680
2680
  client.setConfig({
2681
- baseUrl: this.config.baseUrl
2681
+ baseUrl: this.config.baseUrl,
2682
+ redirect: "manual"
2682
2683
  });
2683
2684
  client.interceptors.request.use((request) => {
2684
2685
  request.headers.set("Authorization", `Bearer ${this.config.apiKey}`);
@@ -2686,6 +2687,33 @@ var NotteClient = class {
2686
2687
  request.headers.set("x-notte-sdk-version", SDK_VERSION);
2687
2688
  return request;
2688
2689
  });
2690
+ client.interceptors.response.use(async (response, request, opts) => {
2691
+ if ((response.status === 307 || response.status === 308) && response.headers.get("location")) {
2692
+ const location = response.headers.get("location");
2693
+ const headers = new Headers(request.headers);
2694
+ if (new URL(location).origin !== new URL(request.url).origin) {
2695
+ headers.delete("Authorization");
2696
+ }
2697
+ const headerRecord = {};
2698
+ headers.forEach((v, k) => {
2699
+ headerRecord[k] = v;
2700
+ });
2701
+ const redirected = await fetch(location, {
2702
+ method: request.method,
2703
+ headers: headerRecord,
2704
+ body: opts.serializedBody ?? void 0
2705
+ });
2706
+ return redirected;
2707
+ }
2708
+ const ct = response.headers.get("content-type") ?? "";
2709
+ if (ct.split(";")[0]?.trim() === "text/plain") {
2710
+ const body = await response.arrayBuffer();
2711
+ const headers = new Headers(response.headers);
2712
+ headers.set("content-type", "application/json");
2713
+ return new Response(body, { status: response.status, statusText: response.statusText, headers });
2714
+ }
2715
+ return response;
2716
+ });
2689
2717
  }
2690
2718
  /**
2691
2719
  * Create a new session