@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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -1
- package/dist/index.mjs +10 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
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
|
|
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
|
|
26
|
+
const res = await this.fetcher(`${this.baseUrl}${path}`, {
|
|
18
27
|
method: "POST",
|
|
19
28
|
headers,
|
|
20
29
|
body: JSON.stringify(body)
|