strike-axios
Version:
147 lines (146 loc) • 6.05 kB
JavaScript
"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) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StrikeAxios = void 0;
const axios_1 = __importDefault(require("axios"));
class StrikeAxios {
constructor(strikeApiKey) {
this.axiosInstance = axios_1.default.create({
baseURL: "https://api.strike.me/v1/",
timeout: 10000,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${strikeApiKey}`,
},
});
}
issueInvoice(request) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.axiosInstance.post("invoices", request)).data;
});
}
findInvoiceById(invoiceId) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`invoices/${invoiceId}`, {
// If the status is 404, don't throw an error. We'll return undefined instead.
validateStatus: (status) => {
return (status >= 200 && status < 300) || status === 404;
},
});
if (response.status === 404) {
return undefined;
}
else {
return response.data;
}
});
}
cancelUnpaidInvoice(invoiceId) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.axiosInstance.patch(`invoices/${invoiceId}/cancel`)).data;
});
}
getBankPaymentMethodById(bankPaymentMethodId) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`payment-methods/bank/${bankPaymentMethodId}`, {
// If the status is 404, don't throw an error. We'll return undefined instead.
validateStatus: (status) => {
return (status >= 200 && status < 300) || status === 404;
},
});
if (response.status === 404) {
return undefined;
}
else {
return response.data;
}
});
}
deleteBankPaymentMethod(bankPaymentMethodId) {
return __awaiter(this, void 0, void 0, function* () {
yield this.axiosInstance.delete(`payment-methods/bank/${bankPaymentMethodId}`);
});
}
createBankPaymentMethod(request) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.axiosInstance.post("payment-methods/bank", request)).data;
});
}
createPayout(request) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.axiosInstance.post("payouts", request)).data;
});
}
findPayoutById(payoutId) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`payouts/${payoutId}`, {
// If the status is 404, don't throw an error. We'll return undefined instead.
validateStatus: (status) => {
return (status >= 200 && status < 300) || status === 404;
},
});
if (response.status === 404) {
return undefined;
}
else {
return response.data;
}
});
}
initiatePayout(payoutId) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.axiosInstance.patch(`payouts/${payoutId}/initiate`)).data;
});
}
findReceiveRequestById(receiveRequestId) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`receive-requests/${receiveRequestId}`, {
// If the status is 404, don't throw an error. We'll return undefined instead.
validateStatus: (status) => {
return (status >= 200 && status < 300) || status === 404;
},
});
if (response.status === 404) {
return undefined;
}
else {
return response.data;
}
});
}
createReceiveRequest(request) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.axiosInstance.post("receive-requests", request)).data;
});
}
// TODO: Add support for query parameters.
getReceivesForReceiveRequest(receiveRequestId) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`receive-requests/${receiveRequestId}/receives`, {
// If the status is 404, don't throw an error. We'll return undefined instead.
validateStatus: (status) => {
return (status >= 200 && status < 300) || status === 404;
},
});
if (response.status === 404) {
return undefined;
}
else {
return response.data;
}
});
}
}
exports.StrikeAxios = StrikeAxios;