@synonymdev/blocktank-lsp-http-client
Advanced tools
Comparing version 0.6.0 to 0.7.0-rc.0
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -16,3 +25,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
class BlocktankClientError extends Error { | ||
data; | ||
constructor(message, data) { | ||
@@ -29,3 +37,2 @@ super(`${message} ${JSON.stringify(data)}`); | ||
class BlocktankClient { | ||
_baseUrl; | ||
constructor(_baseUrl = 'https://blocktank.synonym.to/api/v2') { | ||
@@ -44,9 +51,12 @@ this._baseUrl = _baseUrl; | ||
} | ||
async wrapErrorHandler(message, run) { | ||
try { | ||
return await run(); | ||
} | ||
catch (e) { | ||
throw new BlocktankClientError(message, e?.response?.data); | ||
} | ||
wrapErrorHandler(message, run) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield run(); | ||
} | ||
catch (e) { | ||
throw new BlocktankClientError(message, (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data); | ||
} | ||
}); | ||
} | ||
@@ -57,6 +67,8 @@ /** | ||
*/ | ||
async getInfo() { | ||
return await this.wrapErrorHandler('Failed to get info.', async () => { | ||
const response = await axios_1.default.get(this.baseUrl + '/info'); | ||
return response.data; | ||
getInfo() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.wrapErrorHandler('Failed to get info.', () => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield axios_1.default.get(this.baseUrl + '/info'); | ||
return response.data; | ||
})); | ||
}); | ||
@@ -71,13 +83,11 @@ } | ||
*/ | ||
async createOrder(lspBalanceSat, channelExpiryWeeks, options = {}) { | ||
const opts = Object.assign({}, exports.defaultCreateOrderOptions, options); | ||
opts.zeroConf = opts.turboChannel; | ||
delete opts.turboChannel; | ||
return await this.wrapErrorHandler(`Failed to create order.`, async () => { | ||
const response = await axios_1.default.post(this.baseUrl + '/channels', { | ||
...opts, | ||
lspBalanceSat: lspBalanceSat, | ||
channelExpiryWeeks: channelExpiryWeeks | ||
}); | ||
return response.data; | ||
createOrder(lspBalanceSat, channelExpiryWeeks, options = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const opts = Object.assign({}, exports.defaultCreateOrderOptions, options); | ||
opts.zeroConf = opts.turboChannel; | ||
delete opts.turboChannel; | ||
return yield this.wrapErrorHandler(`Failed to create order.`, () => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield axios_1.default.post(this.baseUrl + '/channels', Object.assign(Object.assign({}, opts), { lspBalanceSat: lspBalanceSat, channelExpiryWeeks: channelExpiryWeeks })); | ||
return response.data; | ||
})); | ||
}); | ||
@@ -90,6 +100,8 @@ } | ||
*/ | ||
async getOrder(orderId) { | ||
return await this.wrapErrorHandler(`Failed to fetch order ${orderId}.`, async () => { | ||
const response = await axios_1.default.get(this.baseUrl + '/channels/' + orderId); | ||
return response.data; | ||
getOrder(orderId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.wrapErrorHandler(`Failed to fetch order ${orderId}.`, () => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield axios_1.default.get(this.baseUrl + '/channels/' + orderId); | ||
return response.data; | ||
})); | ||
}); | ||
@@ -102,10 +114,12 @@ } | ||
*/ | ||
async getOrders(orderIds) { | ||
return await this.wrapErrorHandler(`Failed to fetch orders ${JSON.stringify(orderIds)}.`, async () => { | ||
const response = await axios_1.default.get(this.baseUrl + '/channels', { | ||
params: { | ||
ids: orderIds | ||
} | ||
}); | ||
return response.data; | ||
getOrders(orderIds) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.wrapErrorHandler(`Failed to fetch orders ${JSON.stringify(orderIds)}.`, () => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield axios_1.default.get(this.baseUrl + '/channels', { | ||
params: { | ||
ids: orderIds | ||
} | ||
}); | ||
return response.data; | ||
})); | ||
}); | ||
@@ -120,17 +134,21 @@ } | ||
*/ | ||
async openChannel(orderId, connectionStringOrPubkey, announceChannel) { | ||
return await this.wrapErrorHandler(`Failed to open the channel for order ${orderId}.`, async () => { | ||
const response = await axios_1.default.post(this.baseUrl + `/channels/${orderId}/open`, { | ||
connectionStringOrPubkey: connectionStringOrPubkey, | ||
announceChannel: announceChannel | ||
}); | ||
return response.data; | ||
openChannel(orderId, connectionStringOrPubkey, announceChannel) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.wrapErrorHandler(`Failed to open the channel for order ${orderId}.`, () => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield axios_1.default.post(this.baseUrl + `/channels/${orderId}/open`, { | ||
connectionStringOrPubkey: connectionStringOrPubkey, | ||
announceChannel: announceChannel | ||
}); | ||
return response.data; | ||
})); | ||
}); | ||
} | ||
async getMin0ConfTxFee(orderId) { | ||
const window = await this.wrapErrorHandler(`Failed to fetch order ${orderId}.`, async () => { | ||
const response = await axios_1.default.get(this.baseUrl + '/channels/' + orderId + '/min-0conf-tx-fee'); | ||
return response.data; | ||
getMin0ConfTxFee(orderId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const window = yield this.wrapErrorHandler(`Failed to fetch order ${orderId}.`, () => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield axios_1.default.get(this.baseUrl + '/channels/' + orderId + '/min-0conf-tx-fee'); | ||
return response.data; | ||
})); | ||
return window; | ||
}); | ||
return window; | ||
} | ||
@@ -147,13 +165,15 @@ /** | ||
*/ | ||
async createCJitEntry(channelSizeSat, invoiceSat, invoiceDescription, nodeId, channelExpiryWeeks, couponCode) { | ||
return await this.wrapErrorHandler(`Failed to create cjit entry.`, async () => { | ||
const response = await axios_1.default.post(this.baseUrl + '/cjit', { | ||
channelSizeSat, | ||
invoiceSat, | ||
invoiceDescription, | ||
channelExpiryWeeks, | ||
nodeId, | ||
couponCode | ||
}); | ||
return response.data; | ||
createCJitEntry(channelSizeSat, invoiceSat, invoiceDescription, nodeId, channelExpiryWeeks, couponCode) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.wrapErrorHandler(`Failed to create cjit entry.`, () => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield axios_1.default.post(this.baseUrl + '/cjit', { | ||
channelSizeSat, | ||
invoiceSat, | ||
invoiceDescription, | ||
channelExpiryWeeks, | ||
nodeId, | ||
couponCode | ||
}); | ||
return response.data; | ||
})); | ||
}); | ||
@@ -166,6 +186,8 @@ } | ||
*/ | ||
async getCJitEntry(entryId) { | ||
return await this.wrapErrorHandler(`Failed to fetch cjit entry ${entryId}.`, async () => { | ||
const response = await axios_1.default.get(this.baseUrl + '/cjit/' + entryId); | ||
return response.data; | ||
getCJitEntry(entryId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.wrapErrorHandler(`Failed to fetch cjit entry ${entryId}.`, () => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield axios_1.default.get(this.baseUrl + '/cjit/' + entryId); | ||
return response.data; | ||
})); | ||
}); | ||
@@ -172,0 +194,0 @@ } |
{ | ||
"name": "@synonymdev/blocktank-lsp-http-client", | ||
"version": "0.6.0", | ||
"version": "0.7.0-rc.0", | ||
"description": "Blocktank Http Api Client", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -7,5 +7,5 @@ { | ||
"module": "CommonJS", | ||
"target": "ES2022", | ||
"target": "ES6", | ||
"lib": [ | ||
"ES2022" | ||
"ES6" | ||
], | ||
@@ -12,0 +12,0 @@ "allowJs": true, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54270
1028