monzolib
Version:
Fully Featured JS/Node Monzo Library
113 lines (112 loc) • 2.52 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const date_fns_1 = require("date-fns");
class Account {
constructor(acc) {
this.acc = acc;
}
get created() {
return date_fns_1.parseISO(this.acc.created);
}
get description() {
return this.acc.description;
}
get id() {
return this.acc.id;
}
get name() {
return this.owners[0].preferred_name;
}
get owners() {
return this.acc.owners;
}
get userId() {
return this.owners[0].user_id;
}
get ownerNames() {
return this.owners.map((x) => x.preferred_name);
}
balanceRequest() {
return {
path: '/balance',
qs: {
account_id: this.id,
},
};
}
transactionRequest(txId) {
return {
path: `/transactions/${txId}`,
qs: {
'expand[]': 'merchant',
},
};
}
transactionsRequest(options = {}) {
const opts = {
account_id: this.id,
'expand[]': 'merchant',
};
if (options.since) {
if (options.since instanceof Date) {
opts.since = options.since.toISOString();
}
else {
opts.since = options.since;
}
}
if (options.before) {
opts.before = options.before.toISOString();
}
if (options.limit) {
opts.limit = options.limit;
}
return {
path: '/transactions',
qs: opts,
};
}
targetsRequest() {
const opts = {
account_id: this.id,
};
return {
path: '/targets',
qs: opts,
};
}
limitsRequest() {
const opts = {
account_id: this.id,
};
return {
path: '/balance/limits',
qs: opts,
};
}
overdraftStatusRequest() {
const opts = {
account_id: this.id,
};
return {
path: '/overdraft/status',
qs: opts,
};
}
get json() {
return this.acc;
}
get stringify() {
return JSON.stringify(this.json);
}
}
exports.Account = Account;
function accountsRequest() {
return {
path: '/accounts',
qs: {
account_type: 'uk_retail',
},
};
}
exports.accountsRequest = accountsRequest;