@sfutureapps/db-sdk 0.3.8 → 0.3.10

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.d.mts CHANGED
@@ -30,6 +30,7 @@ declare class HttpClient {
30
30
  private baseUrl;
31
31
  private apiKey?;
32
32
  private accessToken?;
33
+ private fetcher;
33
34
  private extraHeaders;
34
35
  constructor(baseUrl: string, opts?: ClientOptions);
35
36
  post<T>(path: string, body: any): Promise<DbResponse<T>>;
package/dist/index.d.ts CHANGED
@@ -30,6 +30,7 @@ declare class HttpClient {
30
30
  private baseUrl;
31
31
  private apiKey?;
32
32
  private accessToken?;
33
+ private fetcher;
33
34
  private extraHeaders;
34
35
  constructor(baseUrl: string, opts?: ClientOptions);
35
36
  post<T>(path: string, body: any): Promise<DbResponse<T>>;
package/dist/index.js CHANGED
@@ -30,6 +30,15 @@ var HttpClient = class {
30
30
  this.baseUrl = baseUrl.replace(/\/+$/, "");
31
31
  this.apiKey = opts.apiKey;
32
32
  this.accessToken = opts.accessToken;
33
+ const g = globalThis;
34
+ const fetchImpl = opts.fetch ?? g.fetch ?? g.window?.fetch;
35
+ if (typeof fetchImpl !== "function") {
36
+ throw new Error(
37
+ "Fetch API is not available in this environment. Provide ClientOptions.fetch or a global fetch polyfill."
38
+ );
39
+ }
40
+ const thisArg = g.window && g.window.fetch === fetchImpl ? g.window : g;
41
+ this.fetcher = fetchImpl.bind(thisArg);
33
42
  this.extraHeaders = opts.headers ?? {};
34
43
  }
35
44
  async post(path, body) {
@@ -40,7 +49,7 @@ var HttpClient = class {
40
49
  if (this.apiKey) headers["x-api-key"] = this.apiKey;
41
50
  const token = this.accessToken?.();
42
51
  if (token) headers["Authorization"] = `Bearer ${token}`;
43
- const res = await fetch(`${this.baseUrl}${path}`, {
52
+ const res = await this.fetcher(`${this.baseUrl}${path}`, {
44
53
  method: "POST",
45
54
  headers,
46
55
  body: JSON.stringify(body)
package/dist/index.mjs CHANGED
@@ -4,6 +4,15 @@ var HttpClient = class {
4
4
  this.baseUrl = baseUrl.replace(/\/+$/, "");
5
5
  this.apiKey = opts.apiKey;
6
6
  this.accessToken = opts.accessToken;
7
+ const g = globalThis;
8
+ const fetchImpl = opts.fetch ?? g.fetch ?? g.window?.fetch;
9
+ if (typeof fetchImpl !== "function") {
10
+ throw new Error(
11
+ "Fetch API is not available in this environment. Provide ClientOptions.fetch or a global fetch polyfill."
12
+ );
13
+ }
14
+ const thisArg = g.window && g.window.fetch === fetchImpl ? g.window : g;
15
+ this.fetcher = fetchImpl.bind(thisArg);
7
16
  this.extraHeaders = opts.headers ?? {};
8
17
  }
9
18
  async post(path, body) {
@@ -14,7 +23,7 @@ var HttpClient = class {
14
23
  if (this.apiKey) headers["x-api-key"] = this.apiKey;
15
24
  const token = this.accessToken?.();
16
25
  if (token) headers["Authorization"] = `Bearer ${token}`;
17
- const res = await fetch(`${this.baseUrl}${path}`, {
26
+ const res = await this.fetcher(`${this.baseUrl}${path}`, {
18
27
  method: "POST",
19
28
  headers,
20
29
  body: JSON.stringify(body)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfutureapps/db-sdk",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "SfutureApps JS SDK for ThinkPHP DB Gateway (MySQL)",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",