@sfutureapps/db-sdk 0.3.5 → 0.3.7

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,7 +30,6 @@ declare class HttpClient {
30
30
  private baseUrl;
31
31
  private apiKey?;
32
32
  private accessToken?;
33
- private fetcher;
34
33
  private extraHeaders;
35
34
  constructor(baseUrl: string, opts?: ClientOptions);
36
35
  post<T>(path: string, body: any): Promise<DbResponse<T>>;
package/dist/index.d.ts CHANGED
@@ -30,7 +30,6 @@ declare class HttpClient {
30
30
  private baseUrl;
31
31
  private apiKey?;
32
32
  private accessToken?;
33
- private fetcher;
34
33
  private extraHeaders;
35
34
  constructor(baseUrl: string, opts?: ClientOptions);
36
35
  post<T>(path: string, body: any): Promise<DbResponse<T>>;
package/dist/index.js CHANGED
@@ -30,7 +30,6 @@ var HttpClient = class {
30
30
  this.baseUrl = baseUrl.replace(/\/+$/, "");
31
31
  this.apiKey = opts.apiKey;
32
32
  this.accessToken = opts.accessToken;
33
- this.fetcher = opts.fetch ?? fetch;
34
33
  this.extraHeaders = opts.headers ?? {};
35
34
  }
36
35
  async post(path, body) {
@@ -41,14 +40,18 @@ var HttpClient = class {
41
40
  if (this.apiKey) headers["x-api-key"] = this.apiKey;
42
41
  const token = this.accessToken?.();
43
42
  if (token) headers["Authorization"] = `Bearer ${token}`;
44
- const res = await this.fetcher(`${this.baseUrl}${path}`, {
43
+ const url = `${this.baseUrl}${path}`;
44
+ const res = await window.fetch(url, {
45
45
  method: "POST",
46
46
  headers,
47
47
  body: JSON.stringify(body)
48
48
  });
49
49
  const text = await res.text();
50
50
  if (!res.ok) {
51
- return { data: null, error: { status: res.status, message: text || res.statusText } };
51
+ return {
52
+ data: null,
53
+ error: { status: res.status, message: text || res.statusText }
54
+ };
52
55
  }
53
56
  try {
54
57
  const json = JSON.parse(text || "{}");
@@ -59,7 +62,10 @@ var HttpClient = class {
59
62
  error: json.error ?? null
60
63
  };
61
64
  } catch {
62
- return { data: null, error: { status: res.status, message: "Invalid JSON response", details: text } };
65
+ return {
66
+ data: null,
67
+ error: { message: "Invalid JSON response", details: text }
68
+ };
63
69
  }
64
70
  }
65
71
  };
package/dist/index.mjs CHANGED
@@ -4,7 +4,6 @@ var HttpClient = class {
4
4
  this.baseUrl = baseUrl.replace(/\/+$/, "");
5
5
  this.apiKey = opts.apiKey;
6
6
  this.accessToken = opts.accessToken;
7
- this.fetcher = opts.fetch ?? fetch;
8
7
  this.extraHeaders = opts.headers ?? {};
9
8
  }
10
9
  async post(path, body) {
@@ -15,14 +14,18 @@ var HttpClient = class {
15
14
  if (this.apiKey) headers["x-api-key"] = this.apiKey;
16
15
  const token = this.accessToken?.();
17
16
  if (token) headers["Authorization"] = `Bearer ${token}`;
18
- const res = await this.fetcher(`${this.baseUrl}${path}`, {
17
+ const url = `${this.baseUrl}${path}`;
18
+ const res = await window.fetch(url, {
19
19
  method: "POST",
20
20
  headers,
21
21
  body: JSON.stringify(body)
22
22
  });
23
23
  const text = await res.text();
24
24
  if (!res.ok) {
25
- return { data: null, error: { status: res.status, message: text || res.statusText } };
25
+ return {
26
+ data: null,
27
+ error: { status: res.status, message: text || res.statusText }
28
+ };
26
29
  }
27
30
  try {
28
31
  const json = JSON.parse(text || "{}");
@@ -33,7 +36,10 @@ var HttpClient = class {
33
36
  error: json.error ?? null
34
37
  };
35
38
  } catch {
36
- return { data: null, error: { status: res.status, message: "Invalid JSON response", details: text } };
39
+ return {
40
+ data: null,
41
+ error: { message: "Invalid JSON response", details: text }
42
+ };
37
43
  }
38
44
  }
39
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfutureapps/db-sdk",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "SfutureApps JS SDK for ThinkPHP DB Gateway (MySQL)",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",