@nimbleflux/fluxbase-sdk 2026.3.7-rc.8 → 2026.5.1
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.cjs +22 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -14
- package/dist/index.d.ts +19 -14
- package/dist/index.js +22 -77
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -71,9 +71,10 @@ var FluxbaseFetch = class {
|
|
|
71
71
|
return this.requestInternal(path, options, false);
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* Full request implementation returning response with headers, status, and data.
|
|
75
|
+
* Used by both requestInternal and requestWithHeadersInternal.
|
|
75
76
|
*/
|
|
76
|
-
async
|
|
77
|
+
async requestFull(path, options, isRetry) {
|
|
77
78
|
const url = `${this.baseUrl}${path}`;
|
|
78
79
|
const headers = { ...this.defaultHeaders, ...options.headers };
|
|
79
80
|
if (this.beforeRequestCallback) {
|
|
@@ -114,7 +115,7 @@ var FluxbaseFetch = class {
|
|
|
114
115
|
if (response.status === 401 && !isRetry && !options.skipAutoRefresh && this.refreshTokenCallback) {
|
|
115
116
|
const refreshSuccess = await this.handleTokenRefresh();
|
|
116
117
|
if (refreshSuccess) {
|
|
117
|
-
return this.
|
|
118
|
+
return this.requestFull(path, options, true);
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
if (!response.ok) {
|
|
@@ -125,7 +126,11 @@ var FluxbaseFetch = class {
|
|
|
125
126
|
error.details = data;
|
|
126
127
|
throw error;
|
|
127
128
|
}
|
|
128
|
-
return
|
|
129
|
+
return {
|
|
130
|
+
data,
|
|
131
|
+
headers: response.headers,
|
|
132
|
+
status: response.status
|
|
133
|
+
};
|
|
129
134
|
} catch (err) {
|
|
130
135
|
clearTimeout(timeoutId);
|
|
131
136
|
if (err instanceof Error) {
|
|
@@ -172,6 +177,19 @@ var FluxbaseFetch = class {
|
|
|
172
177
|
return false;
|
|
173
178
|
}
|
|
174
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Internal request implementation with retry capability
|
|
182
|
+
*/
|
|
183
|
+
async requestInternal(path, options, isRetry) {
|
|
184
|
+
const { data } = await this.requestFull(path, options, isRetry);
|
|
185
|
+
return data;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Internal request implementation that returns response with headers
|
|
189
|
+
*/
|
|
190
|
+
async requestWithHeadersInternal(path, options, isRetry) {
|
|
191
|
+
return this.requestFull(path, options, isRetry);
|
|
192
|
+
}
|
|
175
193
|
/**
|
|
176
194
|
* GET request
|
|
177
195
|
*/
|
|
@@ -200,79 +218,6 @@ var FluxbaseFetch = class {
|
|
|
200
218
|
async requestWithHeaders(path, options) {
|
|
201
219
|
return this.requestWithHeadersInternal(path, options, false);
|
|
202
220
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Internal request implementation that returns response with headers
|
|
205
|
-
*/
|
|
206
|
-
async requestWithHeadersInternal(path, options, isRetry) {
|
|
207
|
-
const url = `${this.baseUrl}${path}`;
|
|
208
|
-
const headers = { ...this.defaultHeaders, ...options.headers };
|
|
209
|
-
if (this.beforeRequestCallback) {
|
|
210
|
-
this.beforeRequestCallback(headers);
|
|
211
|
-
}
|
|
212
|
-
const controller = new AbortController();
|
|
213
|
-
const timeoutId = setTimeout(
|
|
214
|
-
() => controller.abort(),
|
|
215
|
-
options.timeout ?? this.timeout
|
|
216
|
-
);
|
|
217
|
-
if (this.debug) {
|
|
218
|
-
console.log(`[Fluxbase SDK] ${options.method} ${url}`, options.body);
|
|
219
|
-
}
|
|
220
|
-
try {
|
|
221
|
-
const isFormData = options.body && (options.body.constructor?.name === "FormData" || options.body instanceof FormData);
|
|
222
|
-
const requestHeaders = isFormData ? Object.fromEntries(
|
|
223
|
-
Object.entries(headers).filter(
|
|
224
|
-
([key]) => key.toLowerCase() !== "content-type"
|
|
225
|
-
)
|
|
226
|
-
) : headers;
|
|
227
|
-
const response = await fetch(url, {
|
|
228
|
-
method: options.method,
|
|
229
|
-
headers: requestHeaders,
|
|
230
|
-
body: isFormData ? options.body : options.body ? JSON.stringify(options.body) : void 0,
|
|
231
|
-
signal: controller.signal
|
|
232
|
-
});
|
|
233
|
-
clearTimeout(timeoutId);
|
|
234
|
-
const contentType = response.headers.get("content-type");
|
|
235
|
-
let data;
|
|
236
|
-
if (contentType?.includes("application/json")) {
|
|
237
|
-
data = await response.json();
|
|
238
|
-
} else {
|
|
239
|
-
data = await response.text();
|
|
240
|
-
}
|
|
241
|
-
if (this.debug) {
|
|
242
|
-
console.log(`[Fluxbase SDK] Response:`, response.status, data);
|
|
243
|
-
}
|
|
244
|
-
if (response.status === 401 && !isRetry && !options.skipAutoRefresh && this.refreshTokenCallback) {
|
|
245
|
-
const refreshSuccess = await this.handleTokenRefresh();
|
|
246
|
-
if (refreshSuccess) {
|
|
247
|
-
return this.requestWithHeadersInternal(path, options, true);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (!response.ok) {
|
|
251
|
-
const error = new Error(
|
|
252
|
-
typeof data === "object" && data && "error" in data ? String(data.error) : response.statusText
|
|
253
|
-
);
|
|
254
|
-
error.status = response.status;
|
|
255
|
-
error.details = data;
|
|
256
|
-
throw error;
|
|
257
|
-
}
|
|
258
|
-
return {
|
|
259
|
-
data,
|
|
260
|
-
headers: response.headers,
|
|
261
|
-
status: response.status
|
|
262
|
-
};
|
|
263
|
-
} catch (err) {
|
|
264
|
-
clearTimeout(timeoutId);
|
|
265
|
-
if (err instanceof Error) {
|
|
266
|
-
if (err.name === "AbortError") {
|
|
267
|
-
const timeoutError = new Error("Request timeout");
|
|
268
|
-
timeoutError.status = 408;
|
|
269
|
-
throw timeoutError;
|
|
270
|
-
}
|
|
271
|
-
throw err;
|
|
272
|
-
}
|
|
273
|
-
throw new Error("Unknown error occurred");
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
221
|
/**
|
|
277
222
|
* POST request
|
|
278
223
|
*/
|