@boltic/sdk 0.0.5 → 0.0.6
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/sdk.js +80 -6
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.mjs +80 -6
- package/dist/sdk.mjs.map +1 -1
- package/package.json +1 -1
package/dist/sdk.js
CHANGED
|
@@ -259,6 +259,39 @@ class AxiosAdapter {
|
|
|
259
259
|
// Don't throw on non-2xx status codes
|
|
260
260
|
};
|
|
261
261
|
const response = await this.axios(axiosConfig);
|
|
262
|
+
if (response.status < 200 || response.status >= 300) {
|
|
263
|
+
const isHtmlError = typeof response.data === "string" && response.data.trim().startsWith("<!DOCTYPE") || typeof response.data === "string" && response.data.includes("<html");
|
|
264
|
+
if (isHtmlError) {
|
|
265
|
+
const htmlContent = response.data;
|
|
266
|
+
const preMatch = htmlContent.match(/<pre>(.*?)<\/pre>/s);
|
|
267
|
+
const errorMessage = preMatch ? preMatch[1].trim() : `HTTP ${response.status}: ${response.statusText}`;
|
|
268
|
+
throw createErrorWithContext(errorMessage, {
|
|
269
|
+
url: config.url,
|
|
270
|
+
method: config.method,
|
|
271
|
+
status: response.status,
|
|
272
|
+
statusText: response.statusText,
|
|
273
|
+
isHtmlError: true
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
if (response.data && typeof response.data === "object" && "error" in response.data) {
|
|
277
|
+
return {
|
|
278
|
+
data: response.data,
|
|
279
|
+
status: response.status,
|
|
280
|
+
statusText: response.statusText,
|
|
281
|
+
headers: response.headers || {}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
throw createErrorWithContext(
|
|
285
|
+
`HTTP ${response.status}: ${response.statusText}`,
|
|
286
|
+
{
|
|
287
|
+
url: config.url,
|
|
288
|
+
method: config.method,
|
|
289
|
+
status: response.status,
|
|
290
|
+
statusText: response.statusText,
|
|
291
|
+
responseData: response.data
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
}
|
|
262
295
|
return {
|
|
263
296
|
data: response.data,
|
|
264
297
|
status: response.status,
|
|
@@ -357,6 +390,39 @@ class FetchAdapter {
|
|
|
357
390
|
response.headers.forEach((value, key) => {
|
|
358
391
|
headers[key] = value;
|
|
359
392
|
});
|
|
393
|
+
if (response.status < 200 || response.status >= 300) {
|
|
394
|
+
const isHtmlError = typeof data === "string" && (data.trim().startsWith("<!DOCTYPE") || data.includes("<html"));
|
|
395
|
+
if (isHtmlError) {
|
|
396
|
+
const htmlContent = data;
|
|
397
|
+
const preMatch = htmlContent.match(/<pre>(.*?)<\/pre>/s);
|
|
398
|
+
const errorMessage = preMatch ? preMatch[1].trim() : `HTTP ${response.status}: ${response.statusText}`;
|
|
399
|
+
throw createErrorWithContext(errorMessage, {
|
|
400
|
+
url: config.url,
|
|
401
|
+
method: config.method,
|
|
402
|
+
status: response.status,
|
|
403
|
+
statusText: response.statusText,
|
|
404
|
+
isHtmlError: true
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
if (data && typeof data === "object" && "error" in data) {
|
|
408
|
+
return {
|
|
409
|
+
data,
|
|
410
|
+
status: response.status,
|
|
411
|
+
statusText: response.statusText,
|
|
412
|
+
headers
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
throw createErrorWithContext(
|
|
416
|
+
`HTTP ${response.status}: ${response.statusText}`,
|
|
417
|
+
{
|
|
418
|
+
url: config.url,
|
|
419
|
+
method: config.method,
|
|
420
|
+
status: response.status,
|
|
421
|
+
statusText: response.statusText,
|
|
422
|
+
responseData: data
|
|
423
|
+
}
|
|
424
|
+
);
|
|
425
|
+
}
|
|
360
426
|
const httpResponse = {
|
|
361
427
|
data,
|
|
362
428
|
status: response.status,
|
|
@@ -2525,8 +2591,8 @@ const RECORD_ENDPOINTS = {
|
|
|
2525
2591
|
rateLimit: { requests: 200, window: 6e4 }
|
|
2526
2592
|
},
|
|
2527
2593
|
update: {
|
|
2528
|
-
path: "/tables/{table_id}/records",
|
|
2529
|
-
method: "
|
|
2594
|
+
path: "/tables/{table_id}/records/bulk-update",
|
|
2595
|
+
method: "PUT",
|
|
2530
2596
|
authenticated: true
|
|
2531
2597
|
},
|
|
2532
2598
|
updateById: {
|
|
@@ -2731,26 +2797,34 @@ class RecordsApiClient {
|
|
|
2731
2797
|
*/
|
|
2732
2798
|
async updateRecords(request) {
|
|
2733
2799
|
try {
|
|
2734
|
-
const { table_id, ...
|
|
2800
|
+
const { table_id, set, filters, fields, ...rest } = request;
|
|
2735
2801
|
if (!table_id) {
|
|
2736
2802
|
return this.formatErrorResponse(
|
|
2737
2803
|
new Error("table_id is required for update operation")
|
|
2738
2804
|
);
|
|
2739
2805
|
}
|
|
2806
|
+
const apiPayload = {
|
|
2807
|
+
updates: set,
|
|
2808
|
+
filters,
|
|
2809
|
+
...rest
|
|
2810
|
+
};
|
|
2811
|
+
if (fields) {
|
|
2812
|
+
apiPayload.fields = fields;
|
|
2813
|
+
}
|
|
2740
2814
|
const endpoint = RECORD_ENDPOINTS.update;
|
|
2741
2815
|
const url = `${this.baseURL}${buildRecordEndpointPath(endpoint, { table_id })}`;
|
|
2742
2816
|
const response = await this.httpAdapter.request({
|
|
2743
2817
|
url,
|
|
2744
2818
|
method: endpoint.method,
|
|
2745
2819
|
headers: this.buildHeaders(),
|
|
2746
|
-
data:
|
|
2820
|
+
data: apiPayload,
|
|
2747
2821
|
timeout: this.config.timeout
|
|
2748
2822
|
});
|
|
2749
2823
|
const responseData = response.data;
|
|
2750
|
-
if (
|
|
2824
|
+
if (fields && responseData.data) {
|
|
2751
2825
|
responseData.data = filterArrayFields(
|
|
2752
2826
|
responseData.data,
|
|
2753
|
-
|
|
2827
|
+
fields
|
|
2754
2828
|
);
|
|
2755
2829
|
}
|
|
2756
2830
|
return responseData;
|