@nexusmutual/sdk 2.1.1 → 3.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 +123 -112
- package/dist/data/version.json +1 -1
- package/dist/index.d.mts +247 -227
- package/dist/index.d.ts +247 -227
- package/dist/index.js +260 -187
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +257 -187
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6507,6 +6507,38 @@ var require_bech32 = __commonJS({
|
|
|
6507
6507
|
// src/index.ts
|
|
6508
6508
|
import * as deployments from "@nexusmutual/deployments";
|
|
6509
6509
|
|
|
6510
|
+
// src/auth.ts
|
|
6511
|
+
var auth_exports = {};
|
|
6512
|
+
__export(auth_exports, {
|
|
6513
|
+
buildAuthTypedData: () => buildAuthTypedData,
|
|
6514
|
+
buildCoverMetadataAuthMessage: () => buildCoverMetadataAuthMessage
|
|
6515
|
+
});
|
|
6516
|
+
var SIGNING_DOMAIN = {
|
|
6517
|
+
name: "Nexus Mutual App",
|
|
6518
|
+
version: "1.0.0"
|
|
6519
|
+
};
|
|
6520
|
+
var SIGNING_TYPES = {
|
|
6521
|
+
Authentication: [
|
|
6522
|
+
{ name: "timestamp", type: "uint256" },
|
|
6523
|
+
{ name: "message", type: "string" }
|
|
6524
|
+
]
|
|
6525
|
+
};
|
|
6526
|
+
function buildAuthTypedData(message) {
|
|
6527
|
+
return {
|
|
6528
|
+
domain: SIGNING_DOMAIN,
|
|
6529
|
+
types: SIGNING_TYPES,
|
|
6530
|
+
primaryType: "Authentication",
|
|
6531
|
+
value: {
|
|
6532
|
+
timestamp: BigInt(Math.floor(Date.now() / 1e3)),
|
|
6533
|
+
message
|
|
6534
|
+
}
|
|
6535
|
+
};
|
|
6536
|
+
}
|
|
6537
|
+
var COVER_METADATA_AUTH_MESSAGE = "Nexus Mutual (app.nexusmutual.io) wants you to sign in to manage your proof of loss data";
|
|
6538
|
+
function buildCoverMetadataAuthMessage() {
|
|
6539
|
+
return buildAuthTypedData(COVER_METADATA_AUTH_MESSAGE);
|
|
6540
|
+
}
|
|
6541
|
+
|
|
6510
6542
|
// src/constants/index.ts
|
|
6511
6543
|
var constants_exports = {};
|
|
6512
6544
|
__export(constants_exports, {
|
|
@@ -7323,6 +7355,159 @@ var productCategoryMap = {
|
|
|
7323
7355
|
// Venus Flux
|
|
7324
7356
|
};
|
|
7325
7357
|
|
|
7358
|
+
// src/cover/index.ts
|
|
7359
|
+
var cover_exports = {};
|
|
7360
|
+
__export(cover_exports, {
|
|
7361
|
+
CoverData: () => CoverData
|
|
7362
|
+
});
|
|
7363
|
+
|
|
7364
|
+
// src/nexus-sdk-base.ts
|
|
7365
|
+
var ApiError = class extends Error {
|
|
7366
|
+
status;
|
|
7367
|
+
data;
|
|
7368
|
+
constructor(status, data, message) {
|
|
7369
|
+
super(message);
|
|
7370
|
+
this.name = "ApiError";
|
|
7371
|
+
this.status = status;
|
|
7372
|
+
this.data = data;
|
|
7373
|
+
}
|
|
7374
|
+
};
|
|
7375
|
+
var NexusSDKBase = class {
|
|
7376
|
+
apiUrl;
|
|
7377
|
+
/**
|
|
7378
|
+
* Create a new instance of NexusSDKBase
|
|
7379
|
+
* @param config SDK configuration
|
|
7380
|
+
*/
|
|
7381
|
+
constructor(config = {}) {
|
|
7382
|
+
this.apiUrl = config.apiUrl ?? "https://api.nexusmutual.io/v2";
|
|
7383
|
+
}
|
|
7384
|
+
/**
|
|
7385
|
+
* Sends an HTTP request to the specified endpoint
|
|
7386
|
+
* @param endpoint API endpoint to send the request to
|
|
7387
|
+
* @param options Request configuration
|
|
7388
|
+
* @returns Promise resolving to the response data
|
|
7389
|
+
*/
|
|
7390
|
+
async sendRequest(endpoint, options = {}) {
|
|
7391
|
+
const { method = "GET", headers, params, data } = options;
|
|
7392
|
+
const url = new URL(this.apiUrl + endpoint);
|
|
7393
|
+
if (params) {
|
|
7394
|
+
for (const [key2, value] of Object.entries(params)) {
|
|
7395
|
+
if (value != null) {
|
|
7396
|
+
url.searchParams.append(key2, String(value));
|
|
7397
|
+
}
|
|
7398
|
+
}
|
|
7399
|
+
}
|
|
7400
|
+
const init2 = { method };
|
|
7401
|
+
if (data !== void 0) {
|
|
7402
|
+
init2.body = JSON.stringify(data);
|
|
7403
|
+
init2.headers = { "Content-Type": "application/json", ...headers };
|
|
7404
|
+
} else if (headers) {
|
|
7405
|
+
init2.headers = headers;
|
|
7406
|
+
}
|
|
7407
|
+
let response;
|
|
7408
|
+
try {
|
|
7409
|
+
response = await fetch(url.toString(), init2);
|
|
7410
|
+
} catch (err) {
|
|
7411
|
+
throw new ApiError(0, void 0, err.message ?? "Network Error");
|
|
7412
|
+
}
|
|
7413
|
+
if (!response.ok) {
|
|
7414
|
+
const errorData = await this.parseResponseBody(response);
|
|
7415
|
+
const apiErrorMessage = errorData?.error || response.statusText || "Unknown error";
|
|
7416
|
+
const message = apiErrorMessage.includes("Not enough capacity") ? apiErrorMessage : `API request failed: ${response.status} ${apiErrorMessage}`;
|
|
7417
|
+
throw new ApiError(response.status, errorData, message);
|
|
7418
|
+
}
|
|
7419
|
+
return await this.parseResponseBody(response);
|
|
7420
|
+
}
|
|
7421
|
+
async parseResponseBody(response) {
|
|
7422
|
+
if (response.status === 204 || response.status === 205) {
|
|
7423
|
+
return void 0;
|
|
7424
|
+
}
|
|
7425
|
+
const text = await response.text();
|
|
7426
|
+
if (!text) {
|
|
7427
|
+
return void 0;
|
|
7428
|
+
}
|
|
7429
|
+
try {
|
|
7430
|
+
return JSON.parse(text);
|
|
7431
|
+
} catch {
|
|
7432
|
+
return text;
|
|
7433
|
+
}
|
|
7434
|
+
}
|
|
7435
|
+
};
|
|
7436
|
+
|
|
7437
|
+
// src/cover/Cover.ts
|
|
7438
|
+
var CoverData = class extends NexusSDKBase {
|
|
7439
|
+
constructor(config = {}) {
|
|
7440
|
+
super(config);
|
|
7441
|
+
}
|
|
7442
|
+
async getCover(coverId) {
|
|
7443
|
+
if (!coverId || coverId <= 0) {
|
|
7444
|
+
return { result: void 0, error: { message: "Invalid coverId: must be a positive number" } };
|
|
7445
|
+
}
|
|
7446
|
+
try {
|
|
7447
|
+
const response = await this.sendRequest(`/cover/${coverId}`);
|
|
7448
|
+
return { result: response, error: void 0 };
|
|
7449
|
+
} catch (error) {
|
|
7450
|
+
return { result: void 0, error: { message: error.message || "Failed to fetch cover" } };
|
|
7451
|
+
}
|
|
7452
|
+
}
|
|
7453
|
+
async viewCoverMetadata(params) {
|
|
7454
|
+
const { coverMetadataId, signature: signature2 } = params;
|
|
7455
|
+
if (!coverMetadataId || typeof coverMetadataId !== "string") {
|
|
7456
|
+
return { result: void 0, error: { message: "Invalid coverMetadataId: must be a non-empty string" } };
|
|
7457
|
+
}
|
|
7458
|
+
const options = { method: "GET" };
|
|
7459
|
+
if (signature2) {
|
|
7460
|
+
options.headers = this.buildAuthHeaders(signature2);
|
|
7461
|
+
}
|
|
7462
|
+
try {
|
|
7463
|
+
const response = await this.sendRequest(`/cover-metadata/${coverMetadataId}`, options);
|
|
7464
|
+
return { result: response, error: void 0 };
|
|
7465
|
+
} catch (error) {
|
|
7466
|
+
return { result: void 0, error: { message: error.message || "Failed to fetch cover metadata" } };
|
|
7467
|
+
}
|
|
7468
|
+
}
|
|
7469
|
+
async editCoverMetadata(params) {
|
|
7470
|
+
const { coverMetadataId, proofOfLoss, signature: signature2 } = params;
|
|
7471
|
+
if (!coverMetadataId || typeof coverMetadataId !== "string") {
|
|
7472
|
+
return { result: void 0, error: { message: "Invalid coverMetadataId: must be a non-empty string" } };
|
|
7473
|
+
}
|
|
7474
|
+
if (!proofOfLoss || proofOfLoss.length === 0) {
|
|
7475
|
+
return { result: void 0, error: { message: "At least one proof of loss entry is required" } };
|
|
7476
|
+
}
|
|
7477
|
+
if (!signature2?.signature || !signature2?.payload) {
|
|
7478
|
+
return { result: void 0, error: { message: "Signature is required to edit cover metadata" } };
|
|
7479
|
+
}
|
|
7480
|
+
const options = {
|
|
7481
|
+
method: "PUT",
|
|
7482
|
+
headers: this.buildAuthHeaders(signature2),
|
|
7483
|
+
data: { proofOfLoss }
|
|
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 update cover metadata" } };
|
|
7490
|
+
}
|
|
7491
|
+
}
|
|
7492
|
+
async createCoverMetadata(input) {
|
|
7493
|
+
const options = {
|
|
7494
|
+
method: "POST",
|
|
7495
|
+
data: input
|
|
7496
|
+
};
|
|
7497
|
+
const response = await this.sendRequest("/cover-metadata", options);
|
|
7498
|
+
return response.cid;
|
|
7499
|
+
}
|
|
7500
|
+
buildAuthHeaders(auth) {
|
|
7501
|
+
return {
|
|
7502
|
+
"x-auth-signature": auth.signature,
|
|
7503
|
+
"x-auth-payload": JSON.stringify(
|
|
7504
|
+
auth.payload,
|
|
7505
|
+
(_key, value) => typeof value === "bigint" ? String(value) : value
|
|
7506
|
+
)
|
|
7507
|
+
};
|
|
7508
|
+
}
|
|
7509
|
+
};
|
|
7510
|
+
|
|
7326
7511
|
// src/ipfs/index.ts
|
|
7327
7512
|
var ipfs_exports = {};
|
|
7328
7513
|
__export(ipfs_exports, {
|
|
@@ -23150,50 +23335,6 @@ import { z } from "zod";
|
|
|
23150
23335
|
var VERSION_1_0 = "1.0";
|
|
23151
23336
|
var VERSION_2_0 = "2.0";
|
|
23152
23337
|
var ethereumAddressRegex = /^0x[a-f0-9]{40}$/i;
|
|
23153
|
-
var coverValidatorsSchema = z.object({
|
|
23154
|
-
version: z.literal(VERSION_1_0),
|
|
23155
|
-
validators: z.array(z.string().regex(ethereumAddressRegex, "Invalid Ethereum address")).min(1, "At least one validator address is required")
|
|
23156
|
-
});
|
|
23157
|
-
var coverQuotaShareSchema = z.object({
|
|
23158
|
-
version: z.literal(VERSION_1_0),
|
|
23159
|
-
quotaShare: z.number().min(0).max(100)
|
|
23160
|
-
});
|
|
23161
|
-
var coverAumCoverAmountPercentageSchema = z.object({
|
|
23162
|
-
version: z.literal(VERSION_1_0),
|
|
23163
|
-
aumCoverAmountPercentage: z.number().min(0).max(100)
|
|
23164
|
-
});
|
|
23165
|
-
var coverWalletAddressSchema = z.object({
|
|
23166
|
-
version: z.literal(VERSION_1_0),
|
|
23167
|
-
walletAddress: z.string().regex(ethereumAddressRegex, "Invalid Ethereum address")
|
|
23168
|
-
});
|
|
23169
|
-
var coverWalletAddressesSchema = z.discriminatedUnion("version", [
|
|
23170
|
-
z.object({
|
|
23171
|
-
version: z.literal(VERSION_1_0),
|
|
23172
|
-
walletAddresses: z.string().refine((val) => {
|
|
23173
|
-
const addresses = val.split(",").map((addr) => addr.trim());
|
|
23174
|
-
return addresses.every((addr) => ethereumAddressRegex.test(addr));
|
|
23175
|
-
}, "Invalid Ethereum address(es)")
|
|
23176
|
-
}),
|
|
23177
|
-
z.object({
|
|
23178
|
-
version: z.literal(VERSION_2_0),
|
|
23179
|
-
walletAddresses: z.array(z.string().regex(ethereumAddressRegex, "Invalid Ethereum address")).min(1, "At least one wallet address is required")
|
|
23180
|
-
})
|
|
23181
|
-
]);
|
|
23182
|
-
var coverFreeTextSchema = z.object({
|
|
23183
|
-
version: z.literal(VERSION_1_0),
|
|
23184
|
-
freeText: z.string().min(1, "Free text cannot be empty")
|
|
23185
|
-
});
|
|
23186
|
-
var coverDesignatedWalletsSchema = z.object({
|
|
23187
|
-
version: z.literal(VERSION_1_0),
|
|
23188
|
-
wallets: z.array(
|
|
23189
|
-
z.object({
|
|
23190
|
-
wallet: z.string().regex(ethereumAddressRegex, "Invalid Ethereum address"),
|
|
23191
|
-
amount: z.string().regex(/^(?!,$)[\d,.]+$/, "Amount must be a valid number"),
|
|
23192
|
-
currency: z.string().min(1, "Currency cannot be empty")
|
|
23193
|
-
})
|
|
23194
|
-
).min(1, "At least one wallet object is required")
|
|
23195
|
-
});
|
|
23196
|
-
var defiPassContentSchema = z.union([coverWalletAddressSchema, coverDesignatedWalletsSchema]);
|
|
23197
23338
|
var stakingPoolDetailsSchema = z.object({
|
|
23198
23339
|
version: z.literal(VERSION_1_0),
|
|
23199
23340
|
poolName: z.string().min(1, "Pool name cannot be empty"),
|
|
@@ -23259,91 +23400,10 @@ var coverMetadataRefSchema = z.object({
|
|
|
23259
23400
|
});
|
|
23260
23401
|
|
|
23261
23402
|
// generated/version.json
|
|
23262
|
-
var version27 = "
|
|
23263
|
-
|
|
23264
|
-
// src/nexus-sdk-base.ts
|
|
23265
|
-
var ApiError = class extends Error {
|
|
23266
|
-
status;
|
|
23267
|
-
data;
|
|
23268
|
-
constructor(status, data, message) {
|
|
23269
|
-
super(message);
|
|
23270
|
-
this.name = "ApiError";
|
|
23271
|
-
this.status = status;
|
|
23272
|
-
this.data = data;
|
|
23273
|
-
}
|
|
23274
|
-
};
|
|
23275
|
-
var NexusSDKBase = class {
|
|
23276
|
-
apiUrl;
|
|
23277
|
-
/**
|
|
23278
|
-
* Create a new instance of NexusSDKBase
|
|
23279
|
-
* @param config SDK configuration
|
|
23280
|
-
*/
|
|
23281
|
-
constructor(config = {}) {
|
|
23282
|
-
this.apiUrl = config.apiUrl ?? "https://api.nexusmutual.io/v2";
|
|
23283
|
-
}
|
|
23284
|
-
/**
|
|
23285
|
-
* Sends an HTTP request to the specified endpoint
|
|
23286
|
-
* @param endpoint API endpoint to send the request to
|
|
23287
|
-
* @param options Request configuration
|
|
23288
|
-
* @returns Promise resolving to the response data
|
|
23289
|
-
*/
|
|
23290
|
-
async sendRequest(endpoint, options = {}) {
|
|
23291
|
-
const { method = "GET", headers, params, data } = options;
|
|
23292
|
-
const url = new URL(this.apiUrl + endpoint);
|
|
23293
|
-
if (params) {
|
|
23294
|
-
for (const [key2, value] of Object.entries(params)) {
|
|
23295
|
-
if (value != null) {
|
|
23296
|
-
url.searchParams.append(key2, String(value));
|
|
23297
|
-
}
|
|
23298
|
-
}
|
|
23299
|
-
}
|
|
23300
|
-
const init2 = { method };
|
|
23301
|
-
if (data !== void 0) {
|
|
23302
|
-
init2.body = JSON.stringify(data);
|
|
23303
|
-
init2.headers = { "Content-Type": "application/json", ...headers };
|
|
23304
|
-
} else if (headers) {
|
|
23305
|
-
init2.headers = headers;
|
|
23306
|
-
}
|
|
23307
|
-
let response;
|
|
23308
|
-
try {
|
|
23309
|
-
response = await fetch(url.toString(), init2);
|
|
23310
|
-
} catch (err) {
|
|
23311
|
-
throw new ApiError(0, void 0, err.message ?? "Network Error");
|
|
23312
|
-
}
|
|
23313
|
-
if (!response.ok) {
|
|
23314
|
-
const errorData = await this.parseResponseBody(response);
|
|
23315
|
-
const apiErrorMessage = errorData?.error || response.statusText || "Unknown error";
|
|
23316
|
-
const message = apiErrorMessage.includes("Not enough capacity") ? apiErrorMessage : `API request failed: ${response.status} ${apiErrorMessage}`;
|
|
23317
|
-
throw new ApiError(response.status, errorData, message);
|
|
23318
|
-
}
|
|
23319
|
-
return await this.parseResponseBody(response);
|
|
23320
|
-
}
|
|
23321
|
-
async parseResponseBody(response) {
|
|
23322
|
-
if (response.status === 204 || response.status === 205) {
|
|
23323
|
-
return void 0;
|
|
23324
|
-
}
|
|
23325
|
-
const text = await response.text();
|
|
23326
|
-
if (!text) {
|
|
23327
|
-
return void 0;
|
|
23328
|
-
}
|
|
23329
|
-
try {
|
|
23330
|
-
return JSON.parse(text);
|
|
23331
|
-
} catch {
|
|
23332
|
-
return text;
|
|
23333
|
-
}
|
|
23334
|
-
}
|
|
23335
|
-
};
|
|
23403
|
+
var version27 = "3.0.0";
|
|
23336
23404
|
|
|
23337
23405
|
// src/types/ipfs.ts
|
|
23338
23406
|
var ContentType = /* @__PURE__ */ ((ContentType2) => {
|
|
23339
|
-
ContentType2["coverValidators"] = "coverValidators";
|
|
23340
|
-
ContentType2["coverQuotaShare"] = "coverQuotaShare";
|
|
23341
|
-
ContentType2["coverAumCoverAmountPercentage"] = "coverAumCoverAmountPercentage";
|
|
23342
|
-
ContentType2["coverWalletAddress"] = "coverWalletAddress";
|
|
23343
|
-
ContentType2["coverWalletAddresses"] = "coverWalletAddresses";
|
|
23344
|
-
ContentType2["coverFreeText"] = "coverFreeText";
|
|
23345
|
-
ContentType2["coverDesignatedWallets"] = "coverDesignatedWallets";
|
|
23346
|
-
ContentType2["defiPassContent"] = "defiPassContent";
|
|
23347
23407
|
ContentType2["stakingPoolDetails"] = "stakingPoolDetails";
|
|
23348
23408
|
ContentType2["claimProof"] = "claimProof";
|
|
23349
23409
|
ContentType2["assessmentCriteriaAnswers"] = "assessmentCriteriaAnswers";
|
|
@@ -23409,22 +23469,6 @@ var Ipfs = class extends NexusSDKBase {
|
|
|
23409
23469
|
throw new Error("Content cannot be empty");
|
|
23410
23470
|
}
|
|
23411
23471
|
switch (type) {
|
|
23412
|
-
case "coverValidators" /* coverValidators */:
|
|
23413
|
-
return coverValidatorsSchema.parse(content);
|
|
23414
|
-
case "coverQuotaShare" /* coverQuotaShare */:
|
|
23415
|
-
return coverQuotaShareSchema.parse(content);
|
|
23416
|
-
case "coverAumCoverAmountPercentage" /* coverAumCoverAmountPercentage */:
|
|
23417
|
-
return coverAumCoverAmountPercentageSchema.parse(content);
|
|
23418
|
-
case "coverWalletAddress" /* coverWalletAddress */:
|
|
23419
|
-
return coverWalletAddressSchema.parse(content);
|
|
23420
|
-
case "coverWalletAddresses" /* coverWalletAddresses */:
|
|
23421
|
-
return coverWalletAddressesSchema.parse(content);
|
|
23422
|
-
case "coverFreeText" /* coverFreeText */:
|
|
23423
|
-
return coverFreeTextSchema.parse(content);
|
|
23424
|
-
case "coverDesignatedWallets" /* coverDesignatedWallets */:
|
|
23425
|
-
return coverDesignatedWalletsSchema.parse(content);
|
|
23426
|
-
case "defiPassContent" /* defiPassContent */:
|
|
23427
|
-
return defiPassContentSchema.parse(content);
|
|
23428
23472
|
case "stakingPoolDetails" /* stakingPoolDetails */:
|
|
23429
23473
|
return stakingPoolDetailsSchema.parse(content);
|
|
23430
23474
|
case "claimProof" /* claimProof */:
|
|
@@ -23488,10 +23532,11 @@ var ProductAPI = class extends NexusSDKBase {
|
|
|
23488
23532
|
/**
|
|
23489
23533
|
* Get product type details by ID
|
|
23490
23534
|
* @param productTypeId ID of the product type
|
|
23535
|
+
* @param params Optional attributes to include
|
|
23491
23536
|
* @returns Product type details
|
|
23492
23537
|
*/
|
|
23493
|
-
async getProductTypeById(productTypeId) {
|
|
23494
|
-
const productTypeEndpoint = `/product-types/${productTypeId}`;
|
|
23538
|
+
async getProductTypeById(productTypeId, params) {
|
|
23539
|
+
const productTypeEndpoint = `/product-types/${productTypeId}${params ? `?${new URLSearchParams({ withAttributes: params.join(",") }).toString()}` : ""}`;
|
|
23495
23540
|
return this.sendRequest(productTypeEndpoint);
|
|
23496
23541
|
}
|
|
23497
23542
|
/**
|
|
@@ -23507,8 +23552,8 @@ var ProductAPI = class extends NexusSDKBase {
|
|
|
23507
23552
|
* @param productId ID of the product
|
|
23508
23553
|
* @returns Product details
|
|
23509
23554
|
*/
|
|
23510
|
-
async getProductById(productId) {
|
|
23511
|
-
const productEndpoint = `/products/${productId}`;
|
|
23555
|
+
async getProductById(productId, params) {
|
|
23556
|
+
const productEndpoint = `/products/${productId}${params ? `?${new URLSearchParams({ withAttributes: params.join(",") }).toString()}` : ""}`;
|
|
23512
23557
|
return this.sendRequest(productEndpoint);
|
|
23513
23558
|
}
|
|
23514
23559
|
/**
|
|
@@ -23525,15 +23570,16 @@ var ProductAPI = class extends NexusSDKBase {
|
|
|
23525
23570
|
var Quote = class extends NexusSDKBase {
|
|
23526
23571
|
ipfs;
|
|
23527
23572
|
productAPI;
|
|
23573
|
+
coverData;
|
|
23528
23574
|
/**
|
|
23529
23575
|
* Create a new Quote instance
|
|
23530
23576
|
* @param config SDK configuration
|
|
23531
|
-
* @param ipfs IPFS instance for content upload and validation
|
|
23532
23577
|
*/
|
|
23533
|
-
constructor(config = {}
|
|
23578
|
+
constructor(config = {}) {
|
|
23534
23579
|
super(config);
|
|
23535
|
-
this.ipfs =
|
|
23580
|
+
this.ipfs = new Ipfs(config);
|
|
23536
23581
|
this.productAPI = new ProductAPI(config);
|
|
23582
|
+
this.coverData = new CoverData(config);
|
|
23537
23583
|
}
|
|
23538
23584
|
/**
|
|
23539
23585
|
* Get quote and buy cover inputs
|
|
@@ -23548,7 +23594,8 @@ var Quote = class extends NexusSDKBase {
|
|
|
23548
23594
|
coverAsset,
|
|
23549
23595
|
buyerAddress,
|
|
23550
23596
|
slippage = DEFAULT_SLIPPAGE / SLIPPAGE_DENOMINATOR,
|
|
23551
|
-
|
|
23597
|
+
ipfsCid,
|
|
23598
|
+
coverMetadata,
|
|
23552
23599
|
paymentAsset = coverAsset,
|
|
23553
23600
|
coverId = 0,
|
|
23554
23601
|
commissionRatio,
|
|
@@ -23592,26 +23639,10 @@ var Quote = class extends NexusSDKBase {
|
|
|
23592
23639
|
error: { message: "Invalid slippage: must be a number between 0 and 1" }
|
|
23593
23640
|
};
|
|
23594
23641
|
}
|
|
23595
|
-
|
|
23596
|
-
const isObject = typeof ipfsCidOrContent === "object" && ipfsCidOrContent !== null;
|
|
23597
|
-
if (!isString && !isObject) {
|
|
23598
|
-
return {
|
|
23599
|
-
result: void 0,
|
|
23600
|
-
error: { message: "Invalid ipfsCidOrContent: must be a string CID or content object" }
|
|
23601
|
-
};
|
|
23602
|
-
}
|
|
23603
|
-
if (isString && ipfsCidOrContent !== "") {
|
|
23604
|
-
const isValidCID = this.ipfs.validateIPFSCid(ipfsCidOrContent);
|
|
23605
|
-
if (!isValidCID) {
|
|
23606
|
-
return {
|
|
23607
|
-
result: void 0,
|
|
23608
|
-
error: { message: "Invalid ipfsCid: must be a valid IPFS CID" }
|
|
23609
|
-
};
|
|
23610
|
-
}
|
|
23611
|
-
}
|
|
23642
|
+
let product;
|
|
23612
23643
|
let productType;
|
|
23613
23644
|
try {
|
|
23614
|
-
|
|
23645
|
+
product = await this.productAPI.getProductById(productId);
|
|
23615
23646
|
const productTypeId = product?.productType;
|
|
23616
23647
|
if (productTypeId === void 0) {
|
|
23617
23648
|
return {
|
|
@@ -23619,7 +23650,7 @@ var Quote = class extends NexusSDKBase {
|
|
|
23619
23650
|
error: { message: `Invalid product` }
|
|
23620
23651
|
};
|
|
23621
23652
|
}
|
|
23622
|
-
productType = await this.productAPI.getProductTypeById(productTypeId);
|
|
23653
|
+
productType = await this.productAPI.getProductTypeById(productTypeId, ["buyCoverForm"]);
|
|
23623
23654
|
if (!productType) {
|
|
23624
23655
|
return {
|
|
23625
23656
|
result: void 0,
|
|
@@ -23632,27 +23663,59 @@ var Quote = class extends NexusSDKBase {
|
|
|
23632
23663
|
error: { message: error.message || "Failed to fetch product data" }
|
|
23633
23664
|
};
|
|
23634
23665
|
}
|
|
23635
|
-
|
|
23636
|
-
|
|
23637
|
-
|
|
23638
|
-
|
|
23639
|
-
|
|
23640
|
-
|
|
23641
|
-
|
|
23642
|
-
}
|
|
23643
|
-
}
|
|
23644
|
-
|
|
23645
|
-
|
|
23646
|
-
|
|
23647
|
-
|
|
23648
|
-
|
|
23649
|
-
|
|
23650
|
-
|
|
23666
|
+
let ipfsData = "";
|
|
23667
|
+
if (ipfsCid) {
|
|
23668
|
+
const isValidCID = this.ipfs.validateIPFSCid(ipfsCid);
|
|
23669
|
+
if (!isValidCID) {
|
|
23670
|
+
return {
|
|
23671
|
+
result: void 0,
|
|
23672
|
+
error: { message: "Invalid ipfsCid: must be a valid IPFS CID" }
|
|
23673
|
+
};
|
|
23674
|
+
}
|
|
23675
|
+
ipfsData = ipfsCid;
|
|
23676
|
+
} else {
|
|
23677
|
+
if (product.proofOfLossInputTypes?.length && (!coverMetadata?.proofOfLoss || coverMetadata.proofOfLoss.length === 0)) {
|
|
23678
|
+
return {
|
|
23679
|
+
result: void 0,
|
|
23680
|
+
error: {
|
|
23681
|
+
message: `Missing cover metadata. ${productType.name} requires proof of loss data.`
|
|
23682
|
+
}
|
|
23683
|
+
};
|
|
23684
|
+
}
|
|
23685
|
+
const contentType = productType.buyCoverForm;
|
|
23686
|
+
if (contentType === "withAUM" && !coverMetadata?.publicData?.aumCoverAmountPercentage) {
|
|
23651
23687
|
return {
|
|
23652
23688
|
result: void 0,
|
|
23653
|
-
error: { message:
|
|
23689
|
+
error: { message: "Missing AUM cover amount percentage data" }
|
|
23654
23690
|
};
|
|
23655
23691
|
}
|
|
23692
|
+
if (contentType === "withQuotaShare" && !coverMetadata?.publicData?.quotaShare) {
|
|
23693
|
+
return {
|
|
23694
|
+
result: void 0,
|
|
23695
|
+
error: { message: "Missing quota share data" }
|
|
23696
|
+
};
|
|
23697
|
+
}
|
|
23698
|
+
const requiredTypes = product.proofOfLossInputTypes;
|
|
23699
|
+
if (requiredTypes && requiredTypes.length > 0 && coverMetadata?.proofOfLoss) {
|
|
23700
|
+
const providedTypes = new Set(coverMetadata.proofOfLoss.map((e) => e.type));
|
|
23701
|
+
if (!requiredTypes.every((t) => providedTypes.has(t))) {
|
|
23702
|
+
return {
|
|
23703
|
+
result: void 0,
|
|
23704
|
+
error: { message: `Missing required proof of loss types. Required: ${requiredTypes.join(", ")}` }
|
|
23705
|
+
};
|
|
23706
|
+
}
|
|
23707
|
+
}
|
|
23708
|
+
const hasCoverMetadata = coverMetadata?.proofOfLoss?.length || coverMetadata?.publicData && Object.keys(coverMetadata.publicData).length > 0;
|
|
23709
|
+
if (hasCoverMetadata) {
|
|
23710
|
+
try {
|
|
23711
|
+
ipfsData = await this.coverData.createCoverMetadata(coverMetadata);
|
|
23712
|
+
} catch (error) {
|
|
23713
|
+
return {
|
|
23714
|
+
result: void 0,
|
|
23715
|
+
error: { message: error.message || "Failed to create cover metadata" }
|
|
23716
|
+
};
|
|
23717
|
+
}
|
|
23718
|
+
}
|
|
23656
23719
|
}
|
|
23657
23720
|
const slippageValue = slippage * SLIPPAGE_DENOMINATOR;
|
|
23658
23721
|
const quoteParams = {
|
|
@@ -23921,14 +23984,16 @@ var Swap = class {
|
|
|
23921
23984
|
|
|
23922
23985
|
// src/nexus-sdk.ts
|
|
23923
23986
|
var NexusSDK = class extends NexusSDKBase {
|
|
23987
|
+
cover;
|
|
23924
23988
|
quote;
|
|
23925
23989
|
swap;
|
|
23926
23990
|
ipfs;
|
|
23927
23991
|
constructor(config = {}) {
|
|
23928
23992
|
super(config);
|
|
23993
|
+
this.cover = new CoverData(config);
|
|
23929
23994
|
this.swap = new Swap();
|
|
23930
23995
|
this.ipfs = new Ipfs(config);
|
|
23931
|
-
this.quote = new Quote(config
|
|
23996
|
+
this.quote = new Quote(config);
|
|
23932
23997
|
}
|
|
23933
23998
|
};
|
|
23934
23999
|
|
|
@@ -23960,6 +24025,8 @@ var nexusSdk = {
|
|
|
23960
24025
|
...ipfs_exports,
|
|
23961
24026
|
...product_api_exports,
|
|
23962
24027
|
...constants_exports,
|
|
24028
|
+
...cover_exports,
|
|
24029
|
+
...auth_exports,
|
|
23963
24030
|
NexusSDK,
|
|
23964
24031
|
ApiError
|
|
23965
24032
|
};
|
|
@@ -23969,6 +24036,7 @@ export {
|
|
|
23969
24036
|
COMMISSION_DENOMINATOR,
|
|
23970
24037
|
ContentType,
|
|
23971
24038
|
CoverAsset,
|
|
24039
|
+
CoverData,
|
|
23972
24040
|
DEFAULT_SLIPPAGE,
|
|
23973
24041
|
Ipfs,
|
|
23974
24042
|
MAXIMUM_COVER_PERIOD,
|
|
@@ -23982,6 +24050,8 @@ export {
|
|
|
23982
24050
|
SLIPPAGE_DENOMINATOR,
|
|
23983
24051
|
Swap,
|
|
23984
24052
|
TARGET_PRICE_DENOMINATOR,
|
|
24053
|
+
buildAuthTypedData,
|
|
24054
|
+
buildCoverMetadataAuthMessage,
|
|
23985
24055
|
categoryLabelByEnum,
|
|
23986
24056
|
src_default as default,
|
|
23987
24057
|
productCategoryMap
|