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.mjs CHANGED
@@ -2482,7 +2482,7 @@ var NottePersona = class {
2482
2482
  };
2483
2483
 
2484
2484
  // src/version.ts
2485
- var SDK_VERSION = true ? "0.0.2" : "dev";
2485
+ var SDK_VERSION = true ? "0.0.3" : "dev";
2486
2486
 
2487
2487
  // src/functions.ts
2488
2488
  var NotteFunction = class {
@@ -2568,12 +2568,13 @@ var NotteClient = class {
2568
2568
  throw new Error("API key is required. Provide it via config.apiKey or set the NOTTE_API_KEY environment variable.");
2569
2569
  }
2570
2570
  this.config = {
2571
- baseUrl: config.baseUrl || "https://api.notte.cc",
2571
+ baseUrl: config.baseUrl || process.env.NOTTE_API_URL || "https://api.notte.cc",
2572
2572
  apiKey,
2573
2573
  ...config
2574
2574
  };
2575
2575
  client.setConfig({
2576
- baseUrl: this.config.baseUrl
2576
+ baseUrl: this.config.baseUrl,
2577
+ redirect: "manual"
2577
2578
  });
2578
2579
  client.interceptors.request.use((request) => {
2579
2580
  request.headers.set("Authorization", `Bearer ${this.config.apiKey}`);
@@ -2581,6 +2582,33 @@ var NotteClient = class {
2581
2582
  request.headers.set("x-notte-sdk-version", SDK_VERSION);
2582
2583
  return request;
2583
2584
  });
2585
+ client.interceptors.response.use(async (response, request, opts) => {
2586
+ if ((response.status === 307 || response.status === 308) && response.headers.get("location")) {
2587
+ const location = response.headers.get("location");
2588
+ const headers = new Headers(request.headers);
2589
+ if (new URL(location).origin !== new URL(request.url).origin) {
2590
+ headers.delete("Authorization");
2591
+ }
2592
+ const headerRecord = {};
2593
+ headers.forEach((v, k) => {
2594
+ headerRecord[k] = v;
2595
+ });
2596
+ const redirected = await fetch(location, {
2597
+ method: request.method,
2598
+ headers: headerRecord,
2599
+ body: opts.serializedBody ?? void 0
2600
+ });
2601
+ return redirected;
2602
+ }
2603
+ const ct = response.headers.get("content-type") ?? "";
2604
+ if (ct.split(";")[0]?.trim() === "text/plain") {
2605
+ const body = await response.arrayBuffer();
2606
+ const headers = new Headers(response.headers);
2607
+ headers.set("content-type", "application/json");
2608
+ return new Response(body, { status: response.status, statusText: response.statusText, headers });
2609
+ }
2610
+ return response;
2611
+ });
2584
2612
  }
2585
2613
  /**
2586
2614
  * Create a new session