inflow-export
Version:
Export my spendings as CSV across all Nigerian Bank accounts, using inflow.finance
36 lines • 1.74 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTransactionsInDateRange = void 0;
const axios_1 = __importDefault(require("axios"));
const INFLOW_API_ROOT_URL = "https://api.inflow.finance/v1";
const getTransactionsInDateRange = async (accessToken, options) => {
const root = (options === null || options === void 0 ? void 0 : options.inflowApiRootUrl) || INFLOW_API_ROOT_URL;
const query = new URLSearchParams({
...((options === null || options === void 0 ? void 0 : options.startDate)
? { after: new Date(options === null || options === void 0 ? void 0 : options.startDate).toISOString() }
: {}),
...((options === null || options === void 0 ? void 0 : options.endDate)
? { before: new Date(options === null || options === void 0 ? void 0 : options.endDate).toISOString() }
: {}),
}).toString();
function getTransactions(page = 1, transactions = []) {
return axios_1.default
.get(`${root}/finances/transactions?limit=15&page=${page}&${query}`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
})
.then((res) => res.data)
.then((data) => {
return data.transactions.length
? getTransactions(page + 1, transactions.concat(data.transactions))
: transactions.concat(data.transactions);
});
}
return getTransactions();
};
exports.getTransactionsInDateRange = getTransactionsInDateRange;
//# sourceMappingURL=get-transactions.js.map
;