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