@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/README.md +4 -0
- package/dist/index.d.mts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +59 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -6
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
|
-
|
|
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
|
|
23283
|
+
* @param options Request configuration
|
|
23275
23284
|
* @returns Promise resolving to the response data
|
|
23276
23285
|
*/
|
|
23277
23286
|
async sendRequest(endpoint, options = {}) {
|
|
23278
|
-
const
|
|
23279
|
-
const
|
|
23280
|
-
if (
|
|
23281
|
-
|
|
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
|
-
|
|
23284
|
-
|
|
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
|
-
|
|
23288
|
-
|
|
23289
|
-
|
|
23290
|
-
|
|
23291
|
-
|
|
23292
|
-
|
|
23293
|
-
|
|
23294
|
-
|
|
23295
|
-
|
|
23296
|
-
|
|
23297
|
-
|
|
23298
|
-
|
|
23299
|
-
|
|
23300
|
-
|
|
23301
|
-
|
|
23302
|
-
|
|
23303
|
-
|
|
23304
|
-
|
|
23305
|
-
|
|
23306
|
-
|
|
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
|
-
|
|
23729
|
-
|
|
23730
|
-
if (
|
|
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:
|
|
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:
|
|
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,
|