mailersend
Version:
Node.js helper module for MailerSend API
76 lines (75 loc) • 3.72 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecipientModule = void 0;
const request_service_1 = require("../../services/request.service");
const models_1 = require("../../models");
const MIN_LIMIT = 10;
const MAX_LIMIT = 100;
class RecipientModule extends request_service_1.RequestService {
constructor(apiKey, baseUrl) {
super(apiKey, baseUrl);
}
list(queryParams) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.get(`/recipients`, queryParams);
});
}
single(recipientId) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.get(`/recipients/${recipientId}`);
});
}
delete(recipientId) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.deleteReq(`/recipients/${recipientId}`);
});
}
blockList(queryParams_1) {
return __awaiter(this, arguments, void 0, function* (queryParams, type = models_1.BlockListType.BLOCK_LIST) {
if ((queryParams === null || queryParams === void 0 ? void 0 : queryParams.limit) !== undefined) {
if (queryParams.limit < MIN_LIMIT || queryParams.limit > MAX_LIMIT) {
throw new Error(`Limit must be between ${MIN_LIMIT} and ${MAX_LIMIT}.`);
}
}
return yield this.get(`/suppressions/${type}`, queryParams);
});
}
blockRecipients(blockRecipients_1) {
return __awaiter(this, arguments, void 0, function* (blockRecipients, type = models_1.BlockListType.BLOCK_LIST) {
var _a, _b;
if (type === models_1.BlockListType.BLOCK_LIST) {
const params = blockRecipients;
if (!((_a = params.recipients) === null || _a === void 0 ? void 0 : _a.length) && !((_b = params.patterns) === null || _b === void 0 ? void 0 : _b.length)) {
throw new Error('Either recipients or patterns must be provided.');
}
}
else {
const params = blockRecipients;
if (!params.recipients.length) {
throw new Error('Recipients must not be empty.');
}
}
return yield this.post(`/suppressions/${type}`, blockRecipients);
});
}
delBlockListRecipients(ids_1) {
return __awaiter(this, arguments, void 0, function* (ids, type = models_1.BlockListType.BLOCK_LIST, domainId) {
return yield this.deleteReq(`/suppressions/${type}`, Object.assign({ ids }, (domainId && { domain_id: domainId })));
});
}
delAllBlockListRecipients() {
return __awaiter(this, arguments, void 0, function* (type = models_1.BlockListType.BLOCK_LIST, domainId) {
return yield this.deleteReq(`/suppressions/${type}`, Object.assign({ all: true }, (domainId && { domain_id: domainId })));
});
}
}
exports.RecipientModule = RecipientModule;