@surf-ai/sdk 0.1.5-beta → 1.0.0-alpha.0
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/README.md +93 -159
- package/dist/chunk-4NA3GKVD.js +100 -0
- package/dist/{client-3YMIRPDV.js → client-Z45B2GYT.js} +1 -1
- package/dist/db/index.cjs +63 -37
- package/dist/db/index.d.cts +5 -2
- package/dist/db/index.d.ts +5 -2
- package/dist/db/index.js +63 -37
- package/dist/server/index.cjs +211 -190
- package/dist/server/index.d.cts +204 -16
- package/dist/server/index.d.ts +204 -16
- package/dist/server/index.js +131 -153
- package/package.json +6 -29
- package/dist/chunk-J4OMYO3F.js +0 -70
- package/dist/react/index.d.ts +0 -3450
- package/dist/react/index.js +0 -1092
- package/src/theme/index.css +0 -314
package/dist/db/index.js
CHANGED
|
@@ -1,25 +1,46 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
var
|
|
3
|
-
function
|
|
4
|
-
return
|
|
5
|
-
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
headers: { Authorization: `Bearer ${appToken}` }
|
|
17
|
-
};
|
|
1
|
+
// src/core/config.ts
|
|
2
|
+
var DEFAULT_API_BASE_URL = "https://api.ask.surf/gateway/v1";
|
|
3
|
+
function trimTrailingSlashes(value) {
|
|
4
|
+
return String(value || "").replace(/\/+$/, "");
|
|
5
|
+
}
|
|
6
|
+
function readSurfApiConfig() {
|
|
7
|
+
return {
|
|
8
|
+
baseUrl: trimTrailingSlashes(process.env.SURF_API_BASE_URL || DEFAULT_API_BASE_URL),
|
|
9
|
+
apiKey: process.env.SURF_API_KEY
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function requireSurfApiConfig() {
|
|
13
|
+
const config = readSurfApiConfig();
|
|
14
|
+
if (!config.apiKey) {
|
|
15
|
+
throw new Error("SURF_API_KEY is required");
|
|
18
16
|
}
|
|
19
|
-
return { baseUrl:
|
|
17
|
+
return { baseUrl: config.baseUrl, apiKey: config.apiKey };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/core/transport.ts
|
|
21
|
+
function sleep(ms) {
|
|
22
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
23
|
}
|
|
21
24
|
function normalizePath(path) {
|
|
22
|
-
return String(path || "").replace(/^\/+/, "")
|
|
25
|
+
return String(path || "").replace(/^\/+/, "");
|
|
26
|
+
}
|
|
27
|
+
function buildUrl(path, params) {
|
|
28
|
+
const { baseUrl } = requireSurfApiConfig();
|
|
29
|
+
const url = new URL(`${baseUrl}/${normalizePath(path)}`);
|
|
30
|
+
if (params) {
|
|
31
|
+
for (const [key, value] of Object.entries(params)) {
|
|
32
|
+
if (value != null) {
|
|
33
|
+
url.searchParams.set(key, String(value));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return url.toString();
|
|
38
|
+
}
|
|
39
|
+
function buildHeaders(extra) {
|
|
40
|
+
const { apiKey } = requireSurfApiConfig();
|
|
41
|
+
const headers = new Headers(extra);
|
|
42
|
+
headers.set("Authorization", `Bearer ${apiKey}`);
|
|
43
|
+
return headers;
|
|
23
44
|
}
|
|
24
45
|
async function fetchJson(url, init, retries = 1) {
|
|
25
46
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
@@ -29,39 +50,44 @@ async function fetchJson(url, init, retries = 1) {
|
|
|
29
50
|
throw new Error(`API error ${res.status}: ${text2.slice(0, 200)}`);
|
|
30
51
|
}
|
|
31
52
|
const text = await res.text();
|
|
32
|
-
if (text)
|
|
33
|
-
|
|
53
|
+
if (text) {
|
|
54
|
+
return JSON.parse(text);
|
|
55
|
+
}
|
|
56
|
+
if (attempt < retries) {
|
|
57
|
+
await sleep(1e3);
|
|
58
|
+
}
|
|
34
59
|
}
|
|
35
60
|
throw new Error(`Empty response from ${url}`);
|
|
36
61
|
}
|
|
37
|
-
async function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (params) {
|
|
41
|
-
for (const [k, v] of Object.entries(params)) {
|
|
42
|
-
if (v != null) cleaned[k] = String(v);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const qs = Object.keys(cleaned).length ? "?" + new URLSearchParams(cleaned).toString() : "";
|
|
46
|
-
return fetchJson(`${config.baseUrl}/${normalizePath(path)}${qs}`, {
|
|
47
|
-
headers: config.headers
|
|
62
|
+
async function getJson(path, params) {
|
|
63
|
+
return fetchJson(buildUrl(path, params), {
|
|
64
|
+
headers: buildHeaders()
|
|
48
65
|
});
|
|
49
66
|
}
|
|
50
|
-
async function
|
|
51
|
-
|
|
52
|
-
return fetchJson(`${config.baseUrl}/${normalizePath(path)}`, {
|
|
67
|
+
async function postJson(path, body) {
|
|
68
|
+
return fetchJson(buildUrl(path), {
|
|
53
69
|
method: "POST",
|
|
54
|
-
headers: {
|
|
70
|
+
headers: buildHeaders({
|
|
71
|
+
"Content-Type": "application/json"
|
|
72
|
+
}),
|
|
55
73
|
body: body ? JSON.stringify(body) : void 0
|
|
56
74
|
});
|
|
57
75
|
}
|
|
58
76
|
|
|
77
|
+
// src/data/client.ts
|
|
78
|
+
async function get(path, params) {
|
|
79
|
+
return getJson(path, params);
|
|
80
|
+
}
|
|
81
|
+
async function post(path, body) {
|
|
82
|
+
return postJson(path, body);
|
|
83
|
+
}
|
|
84
|
+
|
|
59
85
|
// src/db/index.ts
|
|
60
86
|
async function dbProvision() {
|
|
61
87
|
return post("db/provision");
|
|
62
88
|
}
|
|
63
89
|
async function dbQuery(sql, params, options) {
|
|
64
|
-
return post("db/query", { sql, params,
|
|
90
|
+
return post("db/query", { sql, params, arrayMode: options?.arrayMode ?? false });
|
|
65
91
|
}
|
|
66
92
|
async function dbTables() {
|
|
67
93
|
return get("db/tables");
|