@nexusmutual/sdk 1.44.0 → 2.0.0-rc.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/dist/index.mjs CHANGED
@@ -23258,7 +23258,16 @@ var productAnnexSchema = z.object({
23258
23258
  var version27 = "1.44.0";
23259
23259
 
23260
23260
  // src/nexus-sdk-base.ts
23261
- import axios from "axios";
23261
+ var ApiError = class extends Error {
23262
+ status;
23263
+ data;
23264
+ constructor(status, data, message) {
23265
+ super(message);
23266
+ this.name = "ApiError";
23267
+ this.status = status;
23268
+ this.data = data;
23269
+ }
23270
+ };
23262
23271
  var NexusSDKBase = class {
23263
23272
  apiUrl;
23264
23273
  /**
@@ -23271,39 +23280,52 @@ var NexusSDKBase = class {
23271
23280
  /**
23272
23281
  * Sends an HTTP request to the specified endpoint
23273
23282
  * @param endpoint API endpoint to send the request to
23274
- * @param options Axios request configuration
23283
+ * @param options Request configuration
23275
23284
  * @returns Promise resolving to the response data
23276
23285
  */
23277
23286
  async sendRequest(endpoint, options = {}) {
23278
- const url = `${this.apiUrl}${endpoint}`;
23279
- const requestOptions = {};
23280
- if (options.headers) {
23281
- requestOptions.headers = options.headers;
23287
+ const { method = "GET", headers, params, data } = options;
23288
+ const url = new URL(this.apiUrl + endpoint);
23289
+ if (params) {
23290
+ for (const [key2, value] of Object.entries(params)) {
23291
+ if (value != null) {
23292
+ url.searchParams.append(key2, String(value));
23293
+ }
23294
+ }
23282
23295
  }
23283
- if (options.params) {
23284
- requestOptions.params = options.params;
23296
+ const init2 = { method };
23297
+ if (data !== void 0) {
23298
+ init2.body = JSON.stringify(data);
23299
+ init2.headers = { "Content-Type": "application/json", ...headers };
23300
+ } else if (headers) {
23301
+ init2.headers = headers;
23285
23302
  }
23303
+ let response;
23286
23304
  try {
23287
- let response;
23288
- if (!options.method || options.method.toUpperCase() === "GET") {
23289
- response = await axios.get(url, requestOptions);
23290
- } else if (options.method.toUpperCase() === "POST") {
23291
- response = await axios.post(url, options.data, requestOptions);
23292
- } else {
23293
- response = await axios.request({
23294
- url,
23295
- ...options
23296
- });
23297
- }
23298
- return response.data;
23299
- } catch (error) {
23300
- if (axios.isAxiosError(error) && error.response) {
23301
- const errorMessage = error.response.data.error || error.response.statusText;
23302
- if (!errorMessage.includes("Not enough capacity")) {
23303
- throw new Error(`API request failed: ${error.response.status} ${errorMessage}`);
23304
- }
23305
- }
23306
- throw error;
23305
+ response = await fetch(url.toString(), init2);
23306
+ } catch (err) {
23307
+ throw new ApiError(0, void 0, err.message ?? "Network Error");
23308
+ }
23309
+ if (!response.ok) {
23310
+ const errorData = await this.parseResponseBody(response);
23311
+ const apiErrorMessage = errorData?.error || response.statusText || "Unknown error";
23312
+ const message = apiErrorMessage.includes("Not enough capacity") ? apiErrorMessage : `API request failed: ${response.status} ${apiErrorMessage}`;
23313
+ throw new ApiError(response.status, errorData, message);
23314
+ }
23315
+ return await this.parseResponseBody(response);
23316
+ }
23317
+ async parseResponseBody(response) {
23318
+ if (response.status === 204 || response.status === 205) {
23319
+ return void 0;
23320
+ }
23321
+ const text = await response.text();
23322
+ if (!text) {
23323
+ return void 0;
23324
+ }
23325
+ try {
23326
+ return JSON.parse(text);
23327
+ } catch {
23328
+ return text;
23307
23329
  }
23308
23330
  }
23309
23331
  };
@@ -23725,22 +23747,22 @@ var Quote = class extends NexusSDKBase {
23725
23747
  * @returns Error response
23726
23748
  */
23727
23749
  async handleQuoteError(error, productId, coverPeriod, coverAsset) {
23728
- const axiosError = error;
23729
- if (axiosError.isAxiosError) {
23730
- if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
23750
+ if (error instanceof ApiError) {
23751
+ const apiErrorMessage = error.data?.error;
23752
+ if (apiErrorMessage?.includes("Not enough capacity")) {
23731
23753
  try {
23732
23754
  const maxCapacity = await this.getProductCapacity(productId, coverPeriod, coverAsset);
23733
23755
  return {
23734
23756
  result: void 0,
23735
23757
  error: {
23736
- message: axiosError.response?.data.error,
23758
+ message: apiErrorMessage,
23737
23759
  data: maxCapacity ? { maxCapacity } : void 0
23738
23760
  }
23739
23761
  };
23740
23762
  } catch (capacityError) {
23741
23763
  return {
23742
23764
  result: void 0,
23743
- error: { message: axiosError.response?.data.error || "Not enough capacity" }
23765
+ error: { message: apiErrorMessage || "Not enough capacity" }
23744
23766
  };
23745
23767
  }
23746
23768
  }
@@ -23931,10 +23953,12 @@ var nexusSdk = {
23931
23953
  ...ipfs_exports,
23932
23954
  ...product_api_exports,
23933
23955
  ...constants_exports,
23934
- NexusSDK
23956
+ NexusSDK,
23957
+ ApiError
23935
23958
  };
23936
23959
  var src_default = nexusSdk;
23937
23960
  export {
23961
+ ApiError,
23938
23962
  COMMISSION_DENOMINATOR,
23939
23963
  ContentType,
23940
23964
  CoverAsset,