@domu-ai/kiban-sdk 1.72.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 +35 -0
- package/dashboard/client.d.ts +799 -0
- package/dashboard/client.js +195 -0
- package/dashboard/index.d.ts +3 -0
- package/dashboard/index.js +42 -0
- package/dashboard/schemas.d.ts +1002 -0
- package/dashboard/schemas.js +258 -0
- package/fetcher.d.ts +2 -0
- package/fetcher.js +23 -0
- package/index.d.ts +11 -0
- package/index.js +55 -0
- package/internal/client.d.ts +3055 -0
- package/internal/client.js +495 -0
- package/internal/index.d.ts +3 -0
- package/internal/index.js +42 -0
- package/internal/schemas.d.ts +12845 -0
- package/internal/schemas.js +1870 -0
- package/package.json +43 -0
- package/public/client.d.ts +871 -0
- package/public/client.js +251 -0
- package/public/index.d.ts +3 -0
- package/public/index.js +42 -0
- package/public/schemas.d.ts +1487 -0
- package/public/schemas.js +455 -0
- package/shared/fetcher.d.ts +94 -0
- package/shared/fetcher.js +189 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom HTTP fetcher for the Kiban API client.
|
|
4
|
+
*
|
|
5
|
+
* Supports Orval's mutator signature (`customFetcher(url, options)`) while
|
|
6
|
+
* preserving auth-token injection and robust JSON/non-JSON response parsing.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.setAuthToken = setAuthToken;
|
|
10
|
+
exports.clearAuthToken = clearAuthToken;
|
|
11
|
+
exports.setApiBaseUrl = setApiBaseUrl;
|
|
12
|
+
exports.clearApiBaseUrl = clearApiBaseUrl;
|
|
13
|
+
exports.getApiBaseUrl = getApiBaseUrl;
|
|
14
|
+
exports.isSuccessResponse = isSuccessResponse;
|
|
15
|
+
exports.ensureSuccess = ensureSuccess;
|
|
16
|
+
exports.getSuccessData = getSuccessData;
|
|
17
|
+
exports.customFetcher = customFetcher;
|
|
18
|
+
const DEFAULT_BASE_URL = "http://localhost:3000";
|
|
19
|
+
const ENV_BASE_URL = typeof process !== "undefined"
|
|
20
|
+
? process.env?.SDK_BASE_URL ?? process.env?.API_BASE_URL
|
|
21
|
+
: undefined;
|
|
22
|
+
let baseUrlOverride = null;
|
|
23
|
+
// Auth token getter - configured via setAuthToken()
|
|
24
|
+
let authTokenGetter = null;
|
|
25
|
+
/**
|
|
26
|
+
* Set the authentication token getter
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // After user login:
|
|
30
|
+
* setAuthToken(() => localStorage.getItem('authToken'));
|
|
31
|
+
*
|
|
32
|
+
* // With Clerk:
|
|
33
|
+
* setAuthToken(() => clerk.session?.getToken() ?? null);
|
|
34
|
+
*/
|
|
35
|
+
function setAuthToken(getter) {
|
|
36
|
+
authTokenGetter = getter;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Clear the authentication token (call on logout)
|
|
40
|
+
*/
|
|
41
|
+
function clearAuthToken() {
|
|
42
|
+
authTokenGetter = null;
|
|
43
|
+
}
|
|
44
|
+
function normalizeBaseUrl(url) {
|
|
45
|
+
return url.trim().replace(/\/+$/, "");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set API base URL at runtime.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* setApiBaseUrl("https://api.example.com");
|
|
52
|
+
*/
|
|
53
|
+
function setApiBaseUrl(url) {
|
|
54
|
+
if (!url || !url.trim()) {
|
|
55
|
+
throw new Error("API base URL cannot be empty");
|
|
56
|
+
}
|
|
57
|
+
baseUrlOverride = normalizeBaseUrl(url);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Clear runtime API base URL override and fall back to env/default.
|
|
61
|
+
*/
|
|
62
|
+
function clearApiBaseUrl() {
|
|
63
|
+
baseUrlOverride = null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the effective API base URL used by the fetcher.
|
|
67
|
+
*/
|
|
68
|
+
function getApiBaseUrl() {
|
|
69
|
+
return baseUrlOverride ?? ENV_BASE_URL ?? DEFAULT_BASE_URL;
|
|
70
|
+
}
|
|
71
|
+
function isAbsoluteUrl(url) {
|
|
72
|
+
try {
|
|
73
|
+
const parsed = new URL(url);
|
|
74
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function resolveUrl(url, params) {
|
|
81
|
+
const effectiveBaseUrl = getApiBaseUrl();
|
|
82
|
+
const absolute = isAbsoluteUrl(url);
|
|
83
|
+
const baseForRelative = effectiveBaseUrl.endsWith("/")
|
|
84
|
+
? effectiveBaseUrl
|
|
85
|
+
: `${effectiveBaseUrl}/`;
|
|
86
|
+
const normalizedRelativeUrl = url.startsWith("/") ? url.slice(1) : url;
|
|
87
|
+
const urlObj = absolute
|
|
88
|
+
? new URL(url)
|
|
89
|
+
: new URL(normalizedRelativeUrl, baseForRelative);
|
|
90
|
+
// If the generated client still emits localhost absolute URLs, remap origin.
|
|
91
|
+
if (absolute && urlObj.origin === DEFAULT_BASE_URL) {
|
|
92
|
+
const baseUrlObj = new URL(effectiveBaseUrl);
|
|
93
|
+
urlObj.protocol = baseUrlObj.protocol;
|
|
94
|
+
urlObj.host = baseUrlObj.host;
|
|
95
|
+
}
|
|
96
|
+
if (params) {
|
|
97
|
+
for (const [key, value] of Object.entries(params)) {
|
|
98
|
+
if (value !== undefined && value !== null) {
|
|
99
|
+
urlObj.searchParams.set(key, String(value));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return urlObj.toString();
|
|
104
|
+
}
|
|
105
|
+
function withAuthHeader(headers) {
|
|
106
|
+
const requestHeaders = new Headers(headers);
|
|
107
|
+
const token = authTokenGetter?.();
|
|
108
|
+
if (token) {
|
|
109
|
+
requestHeaders.set("Authorization", `Bearer ${token}`);
|
|
110
|
+
}
|
|
111
|
+
return requestHeaders;
|
|
112
|
+
}
|
|
113
|
+
function serializeErrorPayload(data) {
|
|
114
|
+
try {
|
|
115
|
+
return JSON.stringify(data);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return "[unserializable]";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Type guard for SDK response unions that discriminates 2xx responses.
|
|
123
|
+
*/
|
|
124
|
+
function isSuccessResponse(response) {
|
|
125
|
+
return response.status >= 200 && response.status < 300;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Assert an SDK response is successful (2xx), otherwise throw with payload context.
|
|
129
|
+
*/
|
|
130
|
+
function ensureSuccess(response, operationName = "request") {
|
|
131
|
+
if (isSuccessResponse(response)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
throw new Error(`[${operationName}] failed with status=${response.status} payload=${serializeErrorPayload(response.data)}`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Return the success payload from an SDK response or throw for non-2xx responses.
|
|
138
|
+
*/
|
|
139
|
+
function getSuccessData(response, operationName = "request") {
|
|
140
|
+
ensureSuccess(response, operationName);
|
|
141
|
+
return response.data;
|
|
142
|
+
}
|
|
143
|
+
async function parseResponseBody(response) {
|
|
144
|
+
const text = await response.text();
|
|
145
|
+
const contentType = response.headers.get("content-type");
|
|
146
|
+
if (contentType?.includes("application/json")) {
|
|
147
|
+
return text ? JSON.parse(text) : {};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
message: text || `HTTP ${response.status}`,
|
|
151
|
+
code: "NON_JSON_RESPONSE",
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Custom fetcher used by all generated API functions.
|
|
156
|
+
*/
|
|
157
|
+
async function customFetcher(urlOrOptions, maybeOptions) {
|
|
158
|
+
if (typeof urlOrOptions === "string") {
|
|
159
|
+
const requestHeaders = withAuthHeader(maybeOptions?.headers);
|
|
160
|
+
const response = await fetch(resolveUrl(urlOrOptions), {
|
|
161
|
+
...maybeOptions,
|
|
162
|
+
headers: requestHeaders,
|
|
163
|
+
});
|
|
164
|
+
const responseData = await parseResponseBody(response);
|
|
165
|
+
const envelope = {
|
|
166
|
+
data: responseData,
|
|
167
|
+
status: response.status,
|
|
168
|
+
headers: response.headers,
|
|
169
|
+
};
|
|
170
|
+
return envelope;
|
|
171
|
+
}
|
|
172
|
+
const { url, method, headers, params, data, signal } = urlOrOptions;
|
|
173
|
+
const requestHeaders = withAuthHeader(headers);
|
|
174
|
+
if (data !== undefined && !requestHeaders.has("Content-Type")) {
|
|
175
|
+
requestHeaders.set("Content-Type", "application/json");
|
|
176
|
+
}
|
|
177
|
+
const response = await fetch(resolveUrl(url, params), {
|
|
178
|
+
method,
|
|
179
|
+
headers: requestHeaders,
|
|
180
|
+
body: data !== undefined ? JSON.stringify(data) : undefined,
|
|
181
|
+
signal,
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
data: await parseResponseBody(response),
|
|
185
|
+
status: response.status,
|
|
186
|
+
headers: response.headers,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
exports.default = customFetcher;
|