@nexusmutual/sdk 1.44.0 → 2.0.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 CHANGED
@@ -6,6 +6,10 @@
6
6
  npm install @nexusmutual/sdk
7
7
  ```
8
8
 
9
+ ## Requirements
10
+
11
+ - Node.js 18 or newer
12
+
9
13
  ## Usage
10
14
 
11
15
  This package only exports CommonJS modules. You can import it like this:
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "1.44.0"
2
+ "version": "2.0.0"
3
3
  }
package/dist/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- import { AxiosRequestConfig } from 'axios';
2
1
  import { z } from 'zod';
3
2
  export * from '@nexusmutual/deployments';
4
3
 
@@ -526,6 +525,17 @@ interface GetQuoteAndBuyCoverInputsParams {
526
525
  paymentAsset?: number;
527
526
  }
528
527
 
528
+ interface RequestConfig {
529
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
530
+ headers?: Record<string, string>;
531
+ params?: Record<string, unknown>;
532
+ data?: unknown;
533
+ }
534
+ declare class ApiError extends Error {
535
+ readonly status: number;
536
+ readonly data: unknown;
537
+ constructor(status: number, data: unknown, message: string);
538
+ }
529
539
  /**
530
540
  * Base class for the Nexus SDK.
531
541
  * Handles configuration and provides common functionality for all SDK components.
@@ -540,10 +550,11 @@ declare class NexusSDKBase {
540
550
  /**
541
551
  * Sends an HTTP request to the specified endpoint
542
552
  * @param endpoint API endpoint to send the request to
543
- * @param options Axios request configuration
553
+ * @param options Request configuration
544
554
  * @returns Promise resolving to the response data
545
555
  */
546
- protected sendRequest<T>(endpoint: string, options?: AxiosRequestConfig): Promise<T>;
556
+ protected sendRequest<T>(endpoint: string, options?: RequestConfig): Promise<T>;
557
+ private parseResponseBody;
547
558
  }
548
559
 
549
560
  /**
@@ -851,6 +862,7 @@ declare class ProductAPI extends NexusSDKBase {
851
862
 
852
863
  declare const nexusSdk: {
853
864
  NexusSDK: typeof NexusSDK;
865
+ ApiError: typeof ApiError;
854
866
  CoverAsset: typeof CoverAsset;
855
867
  PaymentAsset: typeof PaymentAsset;
856
868
  COMMISSION_DENOMINATOR: 10000;
@@ -36680,4 +36692,4 @@ declare const nexusSdk: {
36680
36692
  }];
36681
36693
  };
36682
36694
 
36683
- export { Address, ApiResponse, AssessmentCriteriaAnswers, AssessmentReason, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, ClaimProof, ContentType, CoverAsset, CoverAumCoverAmountPercentage, CoverDesignatedWallets, CoverFreeText, CoverQuotaShare, CoverRouterProductCapacityResponse, CoverRouterQuoteResponse, CoverValidators, CoverWalletAddress, CoverWalletAddresses, DEFAULT_SLIPPAGE, DefiPassContent, ErrorApiResponse, ErrorResponse, File, FloatString, GetQuoteAndBuyCoverInputsParams, GetQuoteApiResponse, GetQuoteResponse, GovernanceCategory, GovernanceProposal, IPFSContentTypes, IPFSTypeContentTuple, IPFSUploadServiceResponse, IntString, Integer, Ipfs, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, NexusSDK, NexusSDKConfig, PaymentAsset, PoolAllocationRequest, PoolCapacity, ProductAPI, ProductAnnex, ProductCategoryEnum, Quote, QuoteDisplayInfo, QuoteParams, Reserves, SLIPPAGE_DENOMINATOR, StakingPoolDetails, Swap, TARGET_PRICE_DENOMINATOR, categoryLabelByEnum, nexusSdk as default, productCategoryMap };
36695
+ export { Address, ApiError, ApiResponse, AssessmentCriteriaAnswers, AssessmentReason, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, ClaimProof, ContentType, CoverAsset, CoverAumCoverAmountPercentage, CoverDesignatedWallets, CoverFreeText, CoverQuotaShare, CoverRouterProductCapacityResponse, CoverRouterQuoteResponse, CoverValidators, CoverWalletAddress, CoverWalletAddresses, DEFAULT_SLIPPAGE, DefiPassContent, ErrorApiResponse, ErrorResponse, File, FloatString, GetQuoteAndBuyCoverInputsParams, GetQuoteApiResponse, GetQuoteResponse, GovernanceCategory, GovernanceProposal, IPFSContentTypes, IPFSTypeContentTuple, IPFSUploadServiceResponse, IntString, Integer, Ipfs, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, NexusSDK, NexusSDKConfig, PaymentAsset, PoolAllocationRequest, PoolCapacity, ProductAPI, ProductAnnex, ProductCategoryEnum, Quote, QuoteDisplayInfo, QuoteParams, RequestConfig, Reserves, SLIPPAGE_DENOMINATOR, StakingPoolDetails, Swap, TARGET_PRICE_DENOMINATOR, categoryLabelByEnum, nexusSdk as default, productCategoryMap };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { AxiosRequestConfig } from 'axios';
2
1
  import { z } from 'zod';
3
2
  export * from '@nexusmutual/deployments';
4
3
 
@@ -526,6 +525,17 @@ interface GetQuoteAndBuyCoverInputsParams {
526
525
  paymentAsset?: number;
527
526
  }
528
527
 
528
+ interface RequestConfig {
529
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
530
+ headers?: Record<string, string>;
531
+ params?: Record<string, unknown>;
532
+ data?: unknown;
533
+ }
534
+ declare class ApiError extends Error {
535
+ readonly status: number;
536
+ readonly data: unknown;
537
+ constructor(status: number, data: unknown, message: string);
538
+ }
529
539
  /**
530
540
  * Base class for the Nexus SDK.
531
541
  * Handles configuration and provides common functionality for all SDK components.
@@ -540,10 +550,11 @@ declare class NexusSDKBase {
540
550
  /**
541
551
  * Sends an HTTP request to the specified endpoint
542
552
  * @param endpoint API endpoint to send the request to
543
- * @param options Axios request configuration
553
+ * @param options Request configuration
544
554
  * @returns Promise resolving to the response data
545
555
  */
546
- protected sendRequest<T>(endpoint: string, options?: AxiosRequestConfig): Promise<T>;
556
+ protected sendRequest<T>(endpoint: string, options?: RequestConfig): Promise<T>;
557
+ private parseResponseBody;
547
558
  }
548
559
 
549
560
  /**
@@ -851,6 +862,7 @@ declare class ProductAPI extends NexusSDKBase {
851
862
 
852
863
  declare const nexusSdk: {
853
864
  NexusSDK: typeof NexusSDK;
865
+ ApiError: typeof ApiError;
854
866
  CoverAsset: typeof CoverAsset;
855
867
  PaymentAsset: typeof PaymentAsset;
856
868
  COMMISSION_DENOMINATOR: 10000;
@@ -36680,4 +36692,4 @@ declare const nexusSdk: {
36680
36692
  }];
36681
36693
  };
36682
36694
 
36683
- export { Address, ApiResponse, AssessmentCriteriaAnswers, AssessmentReason, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, ClaimProof, ContentType, CoverAsset, CoverAumCoverAmountPercentage, CoverDesignatedWallets, CoverFreeText, CoverQuotaShare, CoverRouterProductCapacityResponse, CoverRouterQuoteResponse, CoverValidators, CoverWalletAddress, CoverWalletAddresses, DEFAULT_SLIPPAGE, DefiPassContent, ErrorApiResponse, ErrorResponse, File, FloatString, GetQuoteAndBuyCoverInputsParams, GetQuoteApiResponse, GetQuoteResponse, GovernanceCategory, GovernanceProposal, IPFSContentTypes, IPFSTypeContentTuple, IPFSUploadServiceResponse, IntString, Integer, Ipfs, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, NexusSDK, NexusSDKConfig, PaymentAsset, PoolAllocationRequest, PoolCapacity, ProductAPI, ProductAnnex, ProductCategoryEnum, Quote, QuoteDisplayInfo, QuoteParams, Reserves, SLIPPAGE_DENOMINATOR, StakingPoolDetails, Swap, TARGET_PRICE_DENOMINATOR, categoryLabelByEnum, nexusSdk as default, productCategoryMap };
36695
+ export { Address, ApiError, ApiResponse, AssessmentCriteriaAnswers, AssessmentReason, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, ClaimProof, ContentType, CoverAsset, CoverAumCoverAmountPercentage, CoverDesignatedWallets, CoverFreeText, CoverQuotaShare, CoverRouterProductCapacityResponse, CoverRouterQuoteResponse, CoverValidators, CoverWalletAddress, CoverWalletAddresses, DEFAULT_SLIPPAGE, DefiPassContent, ErrorApiResponse, ErrorResponse, File, FloatString, GetQuoteAndBuyCoverInputsParams, GetQuoteApiResponse, GetQuoteResponse, GovernanceCategory, GovernanceProposal, IPFSContentTypes, IPFSTypeContentTuple, IPFSUploadServiceResponse, IntString, Integer, Ipfs, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, NexusSDK, NexusSDKConfig, PaymentAsset, PoolAllocationRequest, PoolCapacity, ProductAPI, ProductAnnex, ProductCategoryEnum, Quote, QuoteDisplayInfo, QuoteParams, RequestConfig, Reserves, SLIPPAGE_DENOMINATOR, StakingPoolDetails, Swap, TARGET_PRICE_DENOMINATOR, categoryLabelByEnum, nexusSdk as default, productCategoryMap };
package/dist/index.js CHANGED
@@ -6503,6 +6503,7 @@ var require_bech32 = __commonJS({
6503
6503
  // src/index.ts
6504
6504
  var src_exports = {};
6505
6505
  __export(src_exports, {
6506
+ ApiError: () => ApiError,
6506
6507
  COMMISSION_DENOMINATOR: () => COMMISSION_DENOMINATOR,
6507
6508
  ContentType: () => ContentType,
6508
6509
  CoverAsset: () => CoverAsset,
@@ -23274,10 +23275,19 @@ var productAnnexSchema = import_zod.z.object({
23274
23275
  });
23275
23276
 
23276
23277
  // generated/version.json
23277
- var version27 = "1.44.0";
23278
+ var version27 = "2.0.0";
23278
23279
 
23279
23280
  // src/nexus-sdk-base.ts
23280
- var import_axios = __toESM(require("axios"));
23281
+ var ApiError = class extends Error {
23282
+ status;
23283
+ data;
23284
+ constructor(status, data, message) {
23285
+ super(message);
23286
+ this.name = "ApiError";
23287
+ this.status = status;
23288
+ this.data = data;
23289
+ }
23290
+ };
23281
23291
  var NexusSDKBase = class {
23282
23292
  apiUrl;
23283
23293
  /**
@@ -23290,39 +23300,52 @@ var NexusSDKBase = class {
23290
23300
  /**
23291
23301
  * Sends an HTTP request to the specified endpoint
23292
23302
  * @param endpoint API endpoint to send the request to
23293
- * @param options Axios request configuration
23303
+ * @param options Request configuration
23294
23304
  * @returns Promise resolving to the response data
23295
23305
  */
23296
23306
  async sendRequest(endpoint, options = {}) {
23297
- const url = `${this.apiUrl}${endpoint}`;
23298
- const requestOptions = {};
23299
- if (options.headers) {
23300
- requestOptions.headers = options.headers;
23307
+ const { method = "GET", headers, params, data } = options;
23308
+ const url = new URL(this.apiUrl + endpoint);
23309
+ if (params) {
23310
+ for (const [key2, value] of Object.entries(params)) {
23311
+ if (value != null) {
23312
+ url.searchParams.append(key2, String(value));
23313
+ }
23314
+ }
23301
23315
  }
23302
- if (options.params) {
23303
- requestOptions.params = options.params;
23316
+ const init2 = { method };
23317
+ if (data !== void 0) {
23318
+ init2.body = JSON.stringify(data);
23319
+ init2.headers = { "Content-Type": "application/json", ...headers };
23320
+ } else if (headers) {
23321
+ init2.headers = headers;
23304
23322
  }
23323
+ let response;
23305
23324
  try {
23306
- let response;
23307
- if (!options.method || options.method.toUpperCase() === "GET") {
23308
- response = await import_axios.default.get(url, requestOptions);
23309
- } else if (options.method.toUpperCase() === "POST") {
23310
- response = await import_axios.default.post(url, options.data, requestOptions);
23311
- } else {
23312
- response = await import_axios.default.request({
23313
- url,
23314
- ...options
23315
- });
23316
- }
23317
- return response.data;
23318
- } catch (error) {
23319
- if (import_axios.default.isAxiosError(error) && error.response) {
23320
- const errorMessage = error.response.data.error || error.response.statusText;
23321
- if (!errorMessage.includes("Not enough capacity")) {
23322
- throw new Error(`API request failed: ${error.response.status} ${errorMessage}`);
23323
- }
23324
- }
23325
- throw error;
23325
+ response = await fetch(url.toString(), init2);
23326
+ } catch (err) {
23327
+ throw new ApiError(0, void 0, err.message ?? "Network Error");
23328
+ }
23329
+ if (!response.ok) {
23330
+ const errorData = await this.parseResponseBody(response);
23331
+ const apiErrorMessage = errorData?.error || response.statusText || "Unknown error";
23332
+ const message = apiErrorMessage.includes("Not enough capacity") ? apiErrorMessage : `API request failed: ${response.status} ${apiErrorMessage}`;
23333
+ throw new ApiError(response.status, errorData, message);
23334
+ }
23335
+ return await this.parseResponseBody(response);
23336
+ }
23337
+ async parseResponseBody(response) {
23338
+ if (response.status === 204 || response.status === 205) {
23339
+ return void 0;
23340
+ }
23341
+ const text = await response.text();
23342
+ if (!text) {
23343
+ return void 0;
23344
+ }
23345
+ try {
23346
+ return JSON.parse(text);
23347
+ } catch {
23348
+ return text;
23326
23349
  }
23327
23350
  }
23328
23351
  };
@@ -23744,22 +23767,22 @@ var Quote = class extends NexusSDKBase {
23744
23767
  * @returns Error response
23745
23768
  */
23746
23769
  async handleQuoteError(error, productId, coverPeriod, coverAsset) {
23747
- const axiosError = error;
23748
- if (axiosError.isAxiosError) {
23749
- if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
23770
+ if (error instanceof ApiError) {
23771
+ const apiErrorMessage = error.data?.error;
23772
+ if (apiErrorMessage?.includes("Not enough capacity")) {
23750
23773
  try {
23751
23774
  const maxCapacity = await this.getProductCapacity(productId, coverPeriod, coverAsset);
23752
23775
  return {
23753
23776
  result: void 0,
23754
23777
  error: {
23755
- message: axiosError.response?.data.error,
23778
+ message: apiErrorMessage,
23756
23779
  data: maxCapacity ? { maxCapacity } : void 0
23757
23780
  }
23758
23781
  };
23759
23782
  } catch (capacityError) {
23760
23783
  return {
23761
23784
  result: void 0,
23762
- error: { message: axiosError.response?.data.error || "Not enough capacity" }
23785
+ error: { message: apiErrorMessage || "Not enough capacity" }
23763
23786
  };
23764
23787
  }
23765
23788
  }
@@ -23950,11 +23973,13 @@ var nexusSdk = {
23950
23973
  ...ipfs_exports,
23951
23974
  ...product_api_exports,
23952
23975
  ...constants_exports,
23953
- NexusSDK
23976
+ NexusSDK,
23977
+ ApiError
23954
23978
  };
23955
23979
  var src_default = nexusSdk;
23956
23980
  // Annotate the CommonJS export names for ESM import in node:
23957
23981
  0 && (module.exports = {
23982
+ ApiError,
23958
23983
  COMMISSION_DENOMINATOR,
23959
23984
  ContentType,
23960
23985
  CoverAsset,