@marceloclp/monzojs
Version:
Unofficial wrapper for the Monzo API written in TypeScript.
45 lines (44 loc) • 1.69 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.deregisterAttachment = exports.registerAttachment = exports.uploadAttachment = void 0;
const create_request_1 = __importDefault(require("../utils/create-request"));
/**
* The first step when uploading an attachment is to obtain a temporary URL to
* which the file can be uploaded.
*
* @see https://docs.monzo.com/#upload-attachment
*/
const uploadAttachment = async (accessToken, { fileName, fileType, contentLength }) => (0, create_request_1.default)(accessToken)
.withFormData({
file_name: fileName,
file_type: fileType,
content_length: contentLength,
})
.post(`attachment/upload`);
exports.uploadAttachment = uploadAttachment;
/**
* Register an existing attachment against a transaction.
*
* @see https://docs.monzo.com/#register-attachment
*/
const registerAttachment = async (accessToken, { externalId, fileUrl, fileType }) => (0, create_request_1.default)(accessToken)
.withFormData({
external_id: externalId,
file_url: fileUrl,
file_type: fileType,
})
.post(`attachment/register`)
.then(({ attachment }) => attachment);
exports.registerAttachment = registerAttachment;
/**
* Remove an attachment by id.
*
* @see https://docs.monzo.com/#deregister-attachment
*/
const deregisterAttachment = async (accessToken, { attachmentId }) => (0, create_request_1.default)(accessToken)
.withFormData({ id: attachmentId })
.post(`attachment/deregister`);
exports.deregisterAttachment = deregisterAttachment;