@nexusmutual/sdk 2.1.1 → 3.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 +123 -112
- package/dist/index.d.mts +247 -227
- package/dist/index.d.ts +247 -227
- package/dist/index.js +259 -186
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +256 -186
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6507,6 +6507,7 @@ __export(src_exports, {
|
|
|
6507
6507
|
COMMISSION_DENOMINATOR: () => COMMISSION_DENOMINATOR,
|
|
6508
6508
|
ContentType: () => ContentType,
|
|
6509
6509
|
CoverAsset: () => CoverAsset,
|
|
6510
|
+
CoverData: () => CoverData,
|
|
6510
6511
|
DEFAULT_SLIPPAGE: () => DEFAULT_SLIPPAGE,
|
|
6511
6512
|
Ipfs: () => Ipfs,
|
|
6512
6513
|
MAXIMUM_COVER_PERIOD: () => MAXIMUM_COVER_PERIOD,
|
|
@@ -6520,6 +6521,8 @@ __export(src_exports, {
|
|
|
6520
6521
|
SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
|
|
6521
6522
|
Swap: () => Swap,
|
|
6522
6523
|
TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR,
|
|
6524
|
+
buildAuthTypedData: () => buildAuthTypedData,
|
|
6525
|
+
buildCoverMetadataAuthMessage: () => buildCoverMetadataAuthMessage,
|
|
6523
6526
|
categoryLabelByEnum: () => categoryLabelByEnum,
|
|
6524
6527
|
default: () => src_default,
|
|
6525
6528
|
productCategoryMap: () => productCategoryMap
|
|
@@ -6527,6 +6530,38 @@ __export(src_exports, {
|
|
|
6527
6530
|
module.exports = __toCommonJS(src_exports);
|
|
6528
6531
|
var deployments = __toESM(require("@nexusmutual/deployments"));
|
|
6529
6532
|
|
|
6533
|
+
// src/auth.ts
|
|
6534
|
+
var auth_exports = {};
|
|
6535
|
+
__export(auth_exports, {
|
|
6536
|
+
buildAuthTypedData: () => buildAuthTypedData,
|
|
6537
|
+
buildCoverMetadataAuthMessage: () => buildCoverMetadataAuthMessage
|
|
6538
|
+
});
|
|
6539
|
+
var SIGNING_DOMAIN = {
|
|
6540
|
+
name: "Nexus Mutual App",
|
|
6541
|
+
version: "1.0.0"
|
|
6542
|
+
};
|
|
6543
|
+
var SIGNING_TYPES = {
|
|
6544
|
+
Authentication: [
|
|
6545
|
+
{ name: "timestamp", type: "uint256" },
|
|
6546
|
+
{ name: "message", type: "string" }
|
|
6547
|
+
]
|
|
6548
|
+
};
|
|
6549
|
+
function buildAuthTypedData(message) {
|
|
6550
|
+
return {
|
|
6551
|
+
domain: SIGNING_DOMAIN,
|
|
6552
|
+
types: SIGNING_TYPES,
|
|
6553
|
+
primaryType: "Authentication",
|
|
6554
|
+
value: {
|
|
6555
|
+
timestamp: BigInt(Math.floor(Date.now() / 1e3)),
|
|
6556
|
+
message
|
|
6557
|
+
}
|
|
6558
|
+
};
|
|
6559
|
+
}
|
|
6560
|
+
var COVER_METADATA_AUTH_MESSAGE = "Nexus Mutual (app.nexusmutual.io) wants you to sign in to manage your proof of loss data";
|
|
6561
|
+
function buildCoverMetadataAuthMessage() {
|
|
6562
|
+
return buildAuthTypedData(COVER_METADATA_AUTH_MESSAGE);
|
|
6563
|
+
}
|
|
6564
|
+
|
|
6530
6565
|
// src/constants/index.ts
|
|
6531
6566
|
var constants_exports = {};
|
|
6532
6567
|
__export(constants_exports, {
|
|
@@ -7343,6 +7378,159 @@ var productCategoryMap = {
|
|
|
7343
7378
|
// Venus Flux
|
|
7344
7379
|
};
|
|
7345
7380
|
|
|
7381
|
+
// src/cover/index.ts
|
|
7382
|
+
var cover_exports = {};
|
|
7383
|
+
__export(cover_exports, {
|
|
7384
|
+
CoverData: () => CoverData
|
|
7385
|
+
});
|
|
7386
|
+
|
|
7387
|
+
// src/nexus-sdk-base.ts
|
|
7388
|
+
var ApiError = class extends Error {
|
|
7389
|
+
status;
|
|
7390
|
+
data;
|
|
7391
|
+
constructor(status, data, message) {
|
|
7392
|
+
super(message);
|
|
7393
|
+
this.name = "ApiError";
|
|
7394
|
+
this.status = status;
|
|
7395
|
+
this.data = data;
|
|
7396
|
+
}
|
|
7397
|
+
};
|
|
7398
|
+
var NexusSDKBase = class {
|
|
7399
|
+
apiUrl;
|
|
7400
|
+
/**
|
|
7401
|
+
* Create a new instance of NexusSDKBase
|
|
7402
|
+
* @param config SDK configuration
|
|
7403
|
+
*/
|
|
7404
|
+
constructor(config = {}) {
|
|
7405
|
+
this.apiUrl = config.apiUrl ?? "https://api.nexusmutual.io/v2";
|
|
7406
|
+
}
|
|
7407
|
+
/**
|
|
7408
|
+
* Sends an HTTP request to the specified endpoint
|
|
7409
|
+
* @param endpoint API endpoint to send the request to
|
|
7410
|
+
* @param options Request configuration
|
|
7411
|
+
* @returns Promise resolving to the response data
|
|
7412
|
+
*/
|
|
7413
|
+
async sendRequest(endpoint, options = {}) {
|
|
7414
|
+
const { method = "GET", headers, params, data } = options;
|
|
7415
|
+
const url = new URL(this.apiUrl + endpoint);
|
|
7416
|
+
if (params) {
|
|
7417
|
+
for (const [key2, value] of Object.entries(params)) {
|
|
7418
|
+
if (value != null) {
|
|
7419
|
+
url.searchParams.append(key2, String(value));
|
|
7420
|
+
}
|
|
7421
|
+
}
|
|
7422
|
+
}
|
|
7423
|
+
const init2 = { method };
|
|
7424
|
+
if (data !== void 0) {
|
|
7425
|
+
init2.body = JSON.stringify(data);
|
|
7426
|
+
init2.headers = { "Content-Type": "application/json", ...headers };
|
|
7427
|
+
} else if (headers) {
|
|
7428
|
+
init2.headers = headers;
|
|
7429
|
+
}
|
|
7430
|
+
let response;
|
|
7431
|
+
try {
|
|
7432
|
+
response = await fetch(url.toString(), init2);
|
|
7433
|
+
} catch (err) {
|
|
7434
|
+
throw new ApiError(0, void 0, err.message ?? "Network Error");
|
|
7435
|
+
}
|
|
7436
|
+
if (!response.ok) {
|
|
7437
|
+
const errorData = await this.parseResponseBody(response);
|
|
7438
|
+
const apiErrorMessage = errorData?.error || response.statusText || "Unknown error";
|
|
7439
|
+
const message = apiErrorMessage.includes("Not enough capacity") ? apiErrorMessage : `API request failed: ${response.status} ${apiErrorMessage}`;
|
|
7440
|
+
throw new ApiError(response.status, errorData, message);
|
|
7441
|
+
}
|
|
7442
|
+
return await this.parseResponseBody(response);
|
|
7443
|
+
}
|
|
7444
|
+
async parseResponseBody(response) {
|
|
7445
|
+
if (response.status === 204 || response.status === 205) {
|
|
7446
|
+
return void 0;
|
|
7447
|
+
}
|
|
7448
|
+
const text = await response.text();
|
|
7449
|
+
if (!text) {
|
|
7450
|
+
return void 0;
|
|
7451
|
+
}
|
|
7452
|
+
try {
|
|
7453
|
+
return JSON.parse(text);
|
|
7454
|
+
} catch {
|
|
7455
|
+
return text;
|
|
7456
|
+
}
|
|
7457
|
+
}
|
|
7458
|
+
};
|
|
7459
|
+
|
|
7460
|
+
// src/cover/Cover.ts
|
|
7461
|
+
var CoverData = class extends NexusSDKBase {
|
|
7462
|
+
constructor(config = {}) {
|
|
7463
|
+
super(config);
|
|
7464
|
+
}
|
|
7465
|
+
async getCover(coverId) {
|
|
7466
|
+
if (!coverId || coverId <= 0) {
|
|
7467
|
+
return { result: void 0, error: { message: "Invalid coverId: must be a positive number" } };
|
|
7468
|
+
}
|
|
7469
|
+
try {
|
|
7470
|
+
const response = await this.sendRequest(`/cover/${coverId}`);
|
|
7471
|
+
return { result: response, error: void 0 };
|
|
7472
|
+
} catch (error) {
|
|
7473
|
+
return { result: void 0, error: { message: error.message || "Failed to fetch cover" } };
|
|
7474
|
+
}
|
|
7475
|
+
}
|
|
7476
|
+
async viewCoverMetadata(params) {
|
|
7477
|
+
const { coverMetadataId, signature: signature2 } = params;
|
|
7478
|
+
if (!coverMetadataId || typeof coverMetadataId !== "string") {
|
|
7479
|
+
return { result: void 0, error: { message: "Invalid coverMetadataId: must be a non-empty string" } };
|
|
7480
|
+
}
|
|
7481
|
+
const options = { method: "GET" };
|
|
7482
|
+
if (signature2) {
|
|
7483
|
+
options.headers = this.buildAuthHeaders(signature2);
|
|
7484
|
+
}
|
|
7485
|
+
try {
|
|
7486
|
+
const response = await this.sendRequest(`/cover-metadata/${coverMetadataId}`, options);
|
|
7487
|
+
return { result: response, error: void 0 };
|
|
7488
|
+
} catch (error) {
|
|
7489
|
+
return { result: void 0, error: { message: error.message || "Failed to fetch cover metadata" } };
|
|
7490
|
+
}
|
|
7491
|
+
}
|
|
7492
|
+
async editCoverMetadata(params) {
|
|
7493
|
+
const { coverMetadataId, proofOfLoss, signature: signature2 } = params;
|
|
7494
|
+
if (!coverMetadataId || typeof coverMetadataId !== "string") {
|
|
7495
|
+
return { result: void 0, error: { message: "Invalid coverMetadataId: must be a non-empty string" } };
|
|
7496
|
+
}
|
|
7497
|
+
if (!proofOfLoss || proofOfLoss.length === 0) {
|
|
7498
|
+
return { result: void 0, error: { message: "At least one proof of loss entry is required" } };
|
|
7499
|
+
}
|
|
7500
|
+
if (!signature2?.signature || !signature2?.payload) {
|
|
7501
|
+
return { result: void 0, error: { message: "Signature is required to edit cover metadata" } };
|
|
7502
|
+
}
|
|
7503
|
+
const options = {
|
|
7504
|
+
method: "PUT",
|
|
7505
|
+
headers: this.buildAuthHeaders(signature2),
|
|
7506
|
+
data: { proofOfLoss }
|
|
7507
|
+
};
|
|
7508
|
+
try {
|
|
7509
|
+
const response = await this.sendRequest(`/cover-metadata/${coverMetadataId}`, options);
|
|
7510
|
+
return { result: response, error: void 0 };
|
|
7511
|
+
} catch (error) {
|
|
7512
|
+
return { result: void 0, error: { message: error.message || "Failed to update cover metadata" } };
|
|
7513
|
+
}
|
|
7514
|
+
}
|
|
7515
|
+
async createCoverMetadata(input) {
|
|
7516
|
+
const options = {
|
|
7517
|
+
method: "POST",
|
|
7518
|
+
data: input
|
|
7519
|
+
};
|
|
7520
|
+
const response = await this.sendRequest("/cover-metadata", options);
|
|
7521
|
+
return response.cid;
|
|
7522
|
+
}
|
|
7523
|
+
buildAuthHeaders(auth) {
|
|
7524
|
+
return {
|
|
7525
|
+
"x-auth-signature": auth.signature,
|
|
7526
|
+
"x-auth-payload": JSON.stringify(
|
|
7527
|
+
auth.payload,
|
|
7528
|
+
(_key, value) => typeof value === "bigint" ? String(value) : value
|
|
7529
|
+
)
|
|
7530
|
+
};
|
|
7531
|
+
}
|
|
7532
|
+
};
|
|
7533
|
+
|
|
7346
7534
|
// src/ipfs/index.ts
|
|
7347
7535
|
var ipfs_exports = {};
|
|
7348
7536
|
__export(ipfs_exports, {
|
|
@@ -23170,50 +23358,6 @@ var import_zod = require("zod");
|
|
|
23170
23358
|
var VERSION_1_0 = "1.0";
|
|
23171
23359
|
var VERSION_2_0 = "2.0";
|
|
23172
23360
|
var ethereumAddressRegex = /^0x[a-f0-9]{40}$/i;
|
|
23173
|
-
var coverValidatorsSchema = import_zod.z.object({
|
|
23174
|
-
version: import_zod.z.literal(VERSION_1_0),
|
|
23175
|
-
validators: import_zod.z.array(import_zod.z.string().regex(ethereumAddressRegex, "Invalid Ethereum address")).min(1, "At least one validator address is required")
|
|
23176
|
-
});
|
|
23177
|
-
var coverQuotaShareSchema = import_zod.z.object({
|
|
23178
|
-
version: import_zod.z.literal(VERSION_1_0),
|
|
23179
|
-
quotaShare: import_zod.z.number().min(0).max(100)
|
|
23180
|
-
});
|
|
23181
|
-
var coverAumCoverAmountPercentageSchema = import_zod.z.object({
|
|
23182
|
-
version: import_zod.z.literal(VERSION_1_0),
|
|
23183
|
-
aumCoverAmountPercentage: import_zod.z.number().min(0).max(100)
|
|
23184
|
-
});
|
|
23185
|
-
var coverWalletAddressSchema = import_zod.z.object({
|
|
23186
|
-
version: import_zod.z.literal(VERSION_1_0),
|
|
23187
|
-
walletAddress: import_zod.z.string().regex(ethereumAddressRegex, "Invalid Ethereum address")
|
|
23188
|
-
});
|
|
23189
|
-
var coverWalletAddressesSchema = import_zod.z.discriminatedUnion("version", [
|
|
23190
|
-
import_zod.z.object({
|
|
23191
|
-
version: import_zod.z.literal(VERSION_1_0),
|
|
23192
|
-
walletAddresses: import_zod.z.string().refine((val) => {
|
|
23193
|
-
const addresses = val.split(",").map((addr) => addr.trim());
|
|
23194
|
-
return addresses.every((addr) => ethereumAddressRegex.test(addr));
|
|
23195
|
-
}, "Invalid Ethereum address(es)")
|
|
23196
|
-
}),
|
|
23197
|
-
import_zod.z.object({
|
|
23198
|
-
version: import_zod.z.literal(VERSION_2_0),
|
|
23199
|
-
walletAddresses: import_zod.z.array(import_zod.z.string().regex(ethereumAddressRegex, "Invalid Ethereum address")).min(1, "At least one wallet address is required")
|
|
23200
|
-
})
|
|
23201
|
-
]);
|
|
23202
|
-
var coverFreeTextSchema = import_zod.z.object({
|
|
23203
|
-
version: import_zod.z.literal(VERSION_1_0),
|
|
23204
|
-
freeText: import_zod.z.string().min(1, "Free text cannot be empty")
|
|
23205
|
-
});
|
|
23206
|
-
var coverDesignatedWalletsSchema = import_zod.z.object({
|
|
23207
|
-
version: import_zod.z.literal(VERSION_1_0),
|
|
23208
|
-
wallets: import_zod.z.array(
|
|
23209
|
-
import_zod.z.object({
|
|
23210
|
-
wallet: import_zod.z.string().regex(ethereumAddressRegex, "Invalid Ethereum address"),
|
|
23211
|
-
amount: import_zod.z.string().regex(/^(?!,$)[\d,.]+$/, "Amount must be a valid number"),
|
|
23212
|
-
currency: import_zod.z.string().min(1, "Currency cannot be empty")
|
|
23213
|
-
})
|
|
23214
|
-
).min(1, "At least one wallet object is required")
|
|
23215
|
-
});
|
|
23216
|
-
var defiPassContentSchema = import_zod.z.union([coverWalletAddressSchema, coverDesignatedWalletsSchema]);
|
|
23217
23361
|
var stakingPoolDetailsSchema = import_zod.z.object({
|
|
23218
23362
|
version: import_zod.z.literal(VERSION_1_0),
|
|
23219
23363
|
poolName: import_zod.z.string().min(1, "Pool name cannot be empty"),
|
|
@@ -23281,89 +23425,8 @@ var coverMetadataRefSchema = import_zod.z.object({
|
|
|
23281
23425
|
// generated/version.json
|
|
23282
23426
|
var version27 = "2.1.1";
|
|
23283
23427
|
|
|
23284
|
-
// src/nexus-sdk-base.ts
|
|
23285
|
-
var ApiError = class extends Error {
|
|
23286
|
-
status;
|
|
23287
|
-
data;
|
|
23288
|
-
constructor(status, data, message) {
|
|
23289
|
-
super(message);
|
|
23290
|
-
this.name = "ApiError";
|
|
23291
|
-
this.status = status;
|
|
23292
|
-
this.data = data;
|
|
23293
|
-
}
|
|
23294
|
-
};
|
|
23295
|
-
var NexusSDKBase = class {
|
|
23296
|
-
apiUrl;
|
|
23297
|
-
/**
|
|
23298
|
-
* Create a new instance of NexusSDKBase
|
|
23299
|
-
* @param config SDK configuration
|
|
23300
|
-
*/
|
|
23301
|
-
constructor(config = {}) {
|
|
23302
|
-
this.apiUrl = config.apiUrl ?? "https://api.nexusmutual.io/v2";
|
|
23303
|
-
}
|
|
23304
|
-
/**
|
|
23305
|
-
* Sends an HTTP request to the specified endpoint
|
|
23306
|
-
* @param endpoint API endpoint to send the request to
|
|
23307
|
-
* @param options Request configuration
|
|
23308
|
-
* @returns Promise resolving to the response data
|
|
23309
|
-
*/
|
|
23310
|
-
async sendRequest(endpoint, options = {}) {
|
|
23311
|
-
const { method = "GET", headers, params, data } = options;
|
|
23312
|
-
const url = new URL(this.apiUrl + endpoint);
|
|
23313
|
-
if (params) {
|
|
23314
|
-
for (const [key2, value] of Object.entries(params)) {
|
|
23315
|
-
if (value != null) {
|
|
23316
|
-
url.searchParams.append(key2, String(value));
|
|
23317
|
-
}
|
|
23318
|
-
}
|
|
23319
|
-
}
|
|
23320
|
-
const init2 = { method };
|
|
23321
|
-
if (data !== void 0) {
|
|
23322
|
-
init2.body = JSON.stringify(data);
|
|
23323
|
-
init2.headers = { "Content-Type": "application/json", ...headers };
|
|
23324
|
-
} else if (headers) {
|
|
23325
|
-
init2.headers = headers;
|
|
23326
|
-
}
|
|
23327
|
-
let response;
|
|
23328
|
-
try {
|
|
23329
|
-
response = await fetch(url.toString(), init2);
|
|
23330
|
-
} catch (err) {
|
|
23331
|
-
throw new ApiError(0, void 0, err.message ?? "Network Error");
|
|
23332
|
-
}
|
|
23333
|
-
if (!response.ok) {
|
|
23334
|
-
const errorData = await this.parseResponseBody(response);
|
|
23335
|
-
const apiErrorMessage = errorData?.error || response.statusText || "Unknown error";
|
|
23336
|
-
const message = apiErrorMessage.includes("Not enough capacity") ? apiErrorMessage : `API request failed: ${response.status} ${apiErrorMessage}`;
|
|
23337
|
-
throw new ApiError(response.status, errorData, message);
|
|
23338
|
-
}
|
|
23339
|
-
return await this.parseResponseBody(response);
|
|
23340
|
-
}
|
|
23341
|
-
async parseResponseBody(response) {
|
|
23342
|
-
if (response.status === 204 || response.status === 205) {
|
|
23343
|
-
return void 0;
|
|
23344
|
-
}
|
|
23345
|
-
const text = await response.text();
|
|
23346
|
-
if (!text) {
|
|
23347
|
-
return void 0;
|
|
23348
|
-
}
|
|
23349
|
-
try {
|
|
23350
|
-
return JSON.parse(text);
|
|
23351
|
-
} catch {
|
|
23352
|
-
return text;
|
|
23353
|
-
}
|
|
23354
|
-
}
|
|
23355
|
-
};
|
|
23356
|
-
|
|
23357
23428
|
// src/types/ipfs.ts
|
|
23358
23429
|
var ContentType = /* @__PURE__ */ ((ContentType2) => {
|
|
23359
|
-
ContentType2["coverValidators"] = "coverValidators";
|
|
23360
|
-
ContentType2["coverQuotaShare"] = "coverQuotaShare";
|
|
23361
|
-
ContentType2["coverAumCoverAmountPercentage"] = "coverAumCoverAmountPercentage";
|
|
23362
|
-
ContentType2["coverWalletAddress"] = "coverWalletAddress";
|
|
23363
|
-
ContentType2["coverWalletAddresses"] = "coverWalletAddresses";
|
|
23364
|
-
ContentType2["coverFreeText"] = "coverFreeText";
|
|
23365
|
-
ContentType2["coverDesignatedWallets"] = "coverDesignatedWallets";
|
|
23366
|
-
ContentType2["defiPassContent"] = "defiPassContent";
|
|
23367
23430
|
ContentType2["stakingPoolDetails"] = "stakingPoolDetails";
|
|
23368
23431
|
ContentType2["claimProof"] = "claimProof";
|
|
23369
23432
|
ContentType2["assessmentCriteriaAnswers"] = "assessmentCriteriaAnswers";
|
|
@@ -23429,22 +23492,6 @@ var Ipfs = class extends NexusSDKBase {
|
|
|
23429
23492
|
throw new Error("Content cannot be empty");
|
|
23430
23493
|
}
|
|
23431
23494
|
switch (type) {
|
|
23432
|
-
case "coverValidators" /* coverValidators */:
|
|
23433
|
-
return coverValidatorsSchema.parse(content);
|
|
23434
|
-
case "coverQuotaShare" /* coverQuotaShare */:
|
|
23435
|
-
return coverQuotaShareSchema.parse(content);
|
|
23436
|
-
case "coverAumCoverAmountPercentage" /* coverAumCoverAmountPercentage */:
|
|
23437
|
-
return coverAumCoverAmountPercentageSchema.parse(content);
|
|
23438
|
-
case "coverWalletAddress" /* coverWalletAddress */:
|
|
23439
|
-
return coverWalletAddressSchema.parse(content);
|
|
23440
|
-
case "coverWalletAddresses" /* coverWalletAddresses */:
|
|
23441
|
-
return coverWalletAddressesSchema.parse(content);
|
|
23442
|
-
case "coverFreeText" /* coverFreeText */:
|
|
23443
|
-
return coverFreeTextSchema.parse(content);
|
|
23444
|
-
case "coverDesignatedWallets" /* coverDesignatedWallets */:
|
|
23445
|
-
return coverDesignatedWalletsSchema.parse(content);
|
|
23446
|
-
case "defiPassContent" /* defiPassContent */:
|
|
23447
|
-
return defiPassContentSchema.parse(content);
|
|
23448
23495
|
case "stakingPoolDetails" /* stakingPoolDetails */:
|
|
23449
23496
|
return stakingPoolDetailsSchema.parse(content);
|
|
23450
23497
|
case "claimProof" /* claimProof */:
|
|
@@ -23508,10 +23555,11 @@ var ProductAPI = class extends NexusSDKBase {
|
|
|
23508
23555
|
/**
|
|
23509
23556
|
* Get product type details by ID
|
|
23510
23557
|
* @param productTypeId ID of the product type
|
|
23558
|
+
* @param params Optional attributes to include
|
|
23511
23559
|
* @returns Product type details
|
|
23512
23560
|
*/
|
|
23513
|
-
async getProductTypeById(productTypeId) {
|
|
23514
|
-
const productTypeEndpoint = `/product-types/${productTypeId}`;
|
|
23561
|
+
async getProductTypeById(productTypeId, params) {
|
|
23562
|
+
const productTypeEndpoint = `/product-types/${productTypeId}${params ? `?${new URLSearchParams({ withAttributes: params.join(",") }).toString()}` : ""}`;
|
|
23515
23563
|
return this.sendRequest(productTypeEndpoint);
|
|
23516
23564
|
}
|
|
23517
23565
|
/**
|
|
@@ -23527,8 +23575,8 @@ var ProductAPI = class extends NexusSDKBase {
|
|
|
23527
23575
|
* @param productId ID of the product
|
|
23528
23576
|
* @returns Product details
|
|
23529
23577
|
*/
|
|
23530
|
-
async getProductById(productId) {
|
|
23531
|
-
const productEndpoint = `/products/${productId}`;
|
|
23578
|
+
async getProductById(productId, params) {
|
|
23579
|
+
const productEndpoint = `/products/${productId}${params ? `?${new URLSearchParams({ withAttributes: params.join(",") }).toString()}` : ""}`;
|
|
23532
23580
|
return this.sendRequest(productEndpoint);
|
|
23533
23581
|
}
|
|
23534
23582
|
/**
|
|
@@ -23545,15 +23593,16 @@ var ProductAPI = class extends NexusSDKBase {
|
|
|
23545
23593
|
var Quote = class extends NexusSDKBase {
|
|
23546
23594
|
ipfs;
|
|
23547
23595
|
productAPI;
|
|
23596
|
+
coverData;
|
|
23548
23597
|
/**
|
|
23549
23598
|
* Create a new Quote instance
|
|
23550
23599
|
* @param config SDK configuration
|
|
23551
|
-
* @param ipfs IPFS instance for content upload and validation
|
|
23552
23600
|
*/
|
|
23553
|
-
constructor(config = {}
|
|
23601
|
+
constructor(config = {}) {
|
|
23554
23602
|
super(config);
|
|
23555
|
-
this.ipfs =
|
|
23603
|
+
this.ipfs = new Ipfs(config);
|
|
23556
23604
|
this.productAPI = new ProductAPI(config);
|
|
23605
|
+
this.coverData = new CoverData(config);
|
|
23557
23606
|
}
|
|
23558
23607
|
/**
|
|
23559
23608
|
* Get quote and buy cover inputs
|
|
@@ -23568,7 +23617,8 @@ var Quote = class extends NexusSDKBase {
|
|
|
23568
23617
|
coverAsset,
|
|
23569
23618
|
buyerAddress,
|
|
23570
23619
|
slippage = DEFAULT_SLIPPAGE / SLIPPAGE_DENOMINATOR,
|
|
23571
|
-
|
|
23620
|
+
ipfsCid,
|
|
23621
|
+
coverMetadata,
|
|
23572
23622
|
paymentAsset = coverAsset,
|
|
23573
23623
|
coverId = 0,
|
|
23574
23624
|
commissionRatio,
|
|
@@ -23612,26 +23662,10 @@ var Quote = class extends NexusSDKBase {
|
|
|
23612
23662
|
error: { message: "Invalid slippage: must be a number between 0 and 1" }
|
|
23613
23663
|
};
|
|
23614
23664
|
}
|
|
23615
|
-
|
|
23616
|
-
const isObject = typeof ipfsCidOrContent === "object" && ipfsCidOrContent !== null;
|
|
23617
|
-
if (!isString && !isObject) {
|
|
23618
|
-
return {
|
|
23619
|
-
result: void 0,
|
|
23620
|
-
error: { message: "Invalid ipfsCidOrContent: must be a string CID or content object" }
|
|
23621
|
-
};
|
|
23622
|
-
}
|
|
23623
|
-
if (isString && ipfsCidOrContent !== "") {
|
|
23624
|
-
const isValidCID = this.ipfs.validateIPFSCid(ipfsCidOrContent);
|
|
23625
|
-
if (!isValidCID) {
|
|
23626
|
-
return {
|
|
23627
|
-
result: void 0,
|
|
23628
|
-
error: { message: "Invalid ipfsCid: must be a valid IPFS CID" }
|
|
23629
|
-
};
|
|
23630
|
-
}
|
|
23631
|
-
}
|
|
23665
|
+
let product;
|
|
23632
23666
|
let productType;
|
|
23633
23667
|
try {
|
|
23634
|
-
|
|
23668
|
+
product = await this.productAPI.getProductById(productId);
|
|
23635
23669
|
const productTypeId = product?.productType;
|
|
23636
23670
|
if (productTypeId === void 0) {
|
|
23637
23671
|
return {
|
|
@@ -23639,7 +23673,7 @@ var Quote = class extends NexusSDKBase {
|
|
|
23639
23673
|
error: { message: `Invalid product` }
|
|
23640
23674
|
};
|
|
23641
23675
|
}
|
|
23642
|
-
productType = await this.productAPI.getProductTypeById(productTypeId);
|
|
23676
|
+
productType = await this.productAPI.getProductTypeById(productTypeId, ["buyCoverForm"]);
|
|
23643
23677
|
if (!productType) {
|
|
23644
23678
|
return {
|
|
23645
23679
|
result: void 0,
|
|
@@ -23652,27 +23686,59 @@ var Quote = class extends NexusSDKBase {
|
|
|
23652
23686
|
error: { message: error.message || "Failed to fetch product data" }
|
|
23653
23687
|
};
|
|
23654
23688
|
}
|
|
23655
|
-
|
|
23656
|
-
|
|
23657
|
-
|
|
23658
|
-
|
|
23659
|
-
|
|
23660
|
-
|
|
23661
|
-
|
|
23662
|
-
}
|
|
23663
|
-
}
|
|
23664
|
-
|
|
23665
|
-
|
|
23666
|
-
|
|
23667
|
-
|
|
23668
|
-
|
|
23669
|
-
|
|
23670
|
-
|
|
23689
|
+
let ipfsData = "";
|
|
23690
|
+
if (ipfsCid) {
|
|
23691
|
+
const isValidCID = this.ipfs.validateIPFSCid(ipfsCid);
|
|
23692
|
+
if (!isValidCID) {
|
|
23693
|
+
return {
|
|
23694
|
+
result: void 0,
|
|
23695
|
+
error: { message: "Invalid ipfsCid: must be a valid IPFS CID" }
|
|
23696
|
+
};
|
|
23697
|
+
}
|
|
23698
|
+
ipfsData = ipfsCid;
|
|
23699
|
+
} else {
|
|
23700
|
+
if (product.proofOfLossInputTypes?.length && (!coverMetadata?.proofOfLoss || coverMetadata.proofOfLoss.length === 0)) {
|
|
23701
|
+
return {
|
|
23702
|
+
result: void 0,
|
|
23703
|
+
error: {
|
|
23704
|
+
message: `Missing cover metadata. ${productType.name} requires proof of loss data.`
|
|
23705
|
+
}
|
|
23706
|
+
};
|
|
23707
|
+
}
|
|
23708
|
+
const contentType = productType.buyCoverForm;
|
|
23709
|
+
if (contentType === "withAUM" && !coverMetadata?.publicData?.aumCoverAmountPercentage) {
|
|
23671
23710
|
return {
|
|
23672
23711
|
result: void 0,
|
|
23673
|
-
error: { message:
|
|
23712
|
+
error: { message: "Missing AUM cover amount percentage data" }
|
|
23674
23713
|
};
|
|
23675
23714
|
}
|
|
23715
|
+
if (contentType === "withQuotaShare" && !coverMetadata?.publicData?.quotaShare) {
|
|
23716
|
+
return {
|
|
23717
|
+
result: void 0,
|
|
23718
|
+
error: { message: "Missing quota share data" }
|
|
23719
|
+
};
|
|
23720
|
+
}
|
|
23721
|
+
const requiredTypes = product.proofOfLossInputTypes;
|
|
23722
|
+
if (requiredTypes && requiredTypes.length > 0 && coverMetadata?.proofOfLoss) {
|
|
23723
|
+
const providedTypes = new Set(coverMetadata.proofOfLoss.map((e) => e.type));
|
|
23724
|
+
if (!requiredTypes.every((t) => providedTypes.has(t))) {
|
|
23725
|
+
return {
|
|
23726
|
+
result: void 0,
|
|
23727
|
+
error: { message: `Missing required proof of loss types. Required: ${requiredTypes.join(", ")}` }
|
|
23728
|
+
};
|
|
23729
|
+
}
|
|
23730
|
+
}
|
|
23731
|
+
const hasCoverMetadata = coverMetadata?.proofOfLoss?.length || coverMetadata?.publicData && Object.keys(coverMetadata.publicData).length > 0;
|
|
23732
|
+
if (hasCoverMetadata) {
|
|
23733
|
+
try {
|
|
23734
|
+
ipfsData = await this.coverData.createCoverMetadata(coverMetadata);
|
|
23735
|
+
} catch (error) {
|
|
23736
|
+
return {
|
|
23737
|
+
result: void 0,
|
|
23738
|
+
error: { message: error.message || "Failed to create cover metadata" }
|
|
23739
|
+
};
|
|
23740
|
+
}
|
|
23741
|
+
}
|
|
23676
23742
|
}
|
|
23677
23743
|
const slippageValue = slippage * SLIPPAGE_DENOMINATOR;
|
|
23678
23744
|
const quoteParams = {
|
|
@@ -23941,14 +24007,16 @@ var Swap = class {
|
|
|
23941
24007
|
|
|
23942
24008
|
// src/nexus-sdk.ts
|
|
23943
24009
|
var NexusSDK = class extends NexusSDKBase {
|
|
24010
|
+
cover;
|
|
23944
24011
|
quote;
|
|
23945
24012
|
swap;
|
|
23946
24013
|
ipfs;
|
|
23947
24014
|
constructor(config = {}) {
|
|
23948
24015
|
super(config);
|
|
24016
|
+
this.cover = new CoverData(config);
|
|
23949
24017
|
this.swap = new Swap();
|
|
23950
24018
|
this.ipfs = new Ipfs(config);
|
|
23951
|
-
this.quote = new Quote(config
|
|
24019
|
+
this.quote = new Quote(config);
|
|
23952
24020
|
}
|
|
23953
24021
|
};
|
|
23954
24022
|
|
|
@@ -23980,6 +24048,8 @@ var nexusSdk = {
|
|
|
23980
24048
|
...ipfs_exports,
|
|
23981
24049
|
...product_api_exports,
|
|
23982
24050
|
...constants_exports,
|
|
24051
|
+
...cover_exports,
|
|
24052
|
+
...auth_exports,
|
|
23983
24053
|
NexusSDK,
|
|
23984
24054
|
ApiError
|
|
23985
24055
|
};
|
|
@@ -23990,6 +24060,7 @@ var src_default = nexusSdk;
|
|
|
23990
24060
|
COMMISSION_DENOMINATOR,
|
|
23991
24061
|
ContentType,
|
|
23992
24062
|
CoverAsset,
|
|
24063
|
+
CoverData,
|
|
23993
24064
|
DEFAULT_SLIPPAGE,
|
|
23994
24065
|
Ipfs,
|
|
23995
24066
|
MAXIMUM_COVER_PERIOD,
|
|
@@ -24003,6 +24074,8 @@ var src_default = nexusSdk;
|
|
|
24003
24074
|
SLIPPAGE_DENOMINATOR,
|
|
24004
24075
|
Swap,
|
|
24005
24076
|
TARGET_PRICE_DENOMINATOR,
|
|
24077
|
+
buildAuthTypedData,
|
|
24078
|
+
buildCoverMetadataAuthMessage,
|
|
24006
24079
|
categoryLabelByEnum,
|
|
24007
24080
|
productCategoryMap,
|
|
24008
24081
|
...require("@nexusmutual/deployments")
|