@ikoabo/notifications
Advanced tools
Comparing version 1.1.0 to 1.1.1
# CHANGELOG | ||
## [1.1.1] - 2021-06-25 | ||
- Fix include of core package | ||
## [1.1.0] - 2021-06-25 | ||
@@ -4,0 +7,0 @@ - Update errors definition |
declare class Mails { | ||
private static _instance; | ||
private _notificationsService; | ||
private _service; | ||
private _token; | ||
private constructor(); | ||
static get shared(): Mails; | ||
setup(notificationsService: string, token: string): void; | ||
send(project: string, mail: string, subject: string, lang?: string, to?: string | string[], cc?: string | string[], bcc?: string | string[], data?: any): Promise<void>; | ||
setup(service: string, token: string): void; | ||
send(project: string, subject: string, body?: string, template?: string, data?: any, to?: string | string[], cc?: string | string[], bcc?: string | string[]): Promise<void>; | ||
} | ||
export declare const MailCtrl: Mails; | ||
export {}; |
@@ -10,2 +10,3 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
const core_2 = require("@ikoabo/core"); | ||
class Mails { | ||
@@ -20,26 +21,44 @@ constructor() { | ||
} | ||
setup(notificationsService, token) { | ||
this._notificationsService = notificationsService; | ||
setup(service, token) { | ||
this._service = service; | ||
this._token = token; | ||
} | ||
send(project, mail, subject, lang, to, cc, bcc, data) { | ||
send(project, subject, body, template, data, to, cc, bcc) { | ||
return new Promise((resolve, reject) => { | ||
if (!this._notificationsService || this._notificationsService.length <= 0) { | ||
reject({ | ||
boError: errors_enum_1.NOTIFICATION_ERRORS.INVALID_MAIL_SERVER, | ||
if (!this._service || this._service.length <= 0) { | ||
return reject({ | ||
boError: errors_enum_1.ERRORS.INVALID_MAIL_SERVER, | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_ACCEPTABLE | ||
}); | ||
return; | ||
} | ||
axios_1.default | ||
.post(`${this._notificationsService}/v1/mails/send`, { | ||
if ((!to || (Array.isArray(to) && to.length === 0)) && | ||
(!cc || (Array.isArray(cc) && cc.length === 0)) && | ||
(!bcc || (Array.isArray(bcc) && bcc.length === 0))) { | ||
return reject({ | ||
boError: errors_enum_1.ERRORS.INVALID_MAIL_DATA, | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_ACCEPTABLE | ||
}); | ||
} | ||
const bodyObj = { | ||
project: project, | ||
mail: mail, | ||
subject: subject, | ||
lang: lang, | ||
data: data, | ||
to: to, | ||
cc: cc, | ||
bcc: bcc, | ||
data: data | ||
}, { | ||
bcc: bcc | ||
}; | ||
if (body) { | ||
bodyObj["body"] = body; | ||
} | ||
else if (template) { | ||
bodyObj["template"] = template; | ||
} | ||
else { | ||
return reject({ | ||
boError: errors_enum_1.ERRORS.INVALID_MAIL_DATA, | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_NOT_ACCEPTABLE | ||
}); | ||
} | ||
axios_1.default | ||
.post(`${this._service}/v1/mail/send`, bodyObj, { | ||
headers: { | ||
@@ -56,3 +75,3 @@ Authorization: `Bearer ${this._token}` | ||
reject({ | ||
boError: errors_enum_1.NOTIFICATION_ERRORS.UNKNOWN_NOTIFICATIONS_SERVER_ERROR, | ||
boError: errors_enum_1.ERRORS.UNKNOWN_NOTIFICATIONS_SERVER_ERROR, | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_FORBIDDEN | ||
@@ -67,3 +86,6 @@ }); | ||
boStatus: err.response.status, | ||
boError: core_1.Objects.get(err, "response.data.error", null), | ||
boError: { | ||
value: core_1.Objects.get(err, "response.data.error", core_2.SERVER_ERRORS.UNKNOWN_ERROR.value), | ||
str: core_1.Objects.get(err, "response.data.description", core_2.SERVER_ERRORS.UNKNOWN_ERROR.str), | ||
}, | ||
boData: core_1.Objects.get(err, "response.data.data", null) | ||
@@ -73,3 +95,3 @@ }); | ||
reject({ | ||
boError: errors_enum_1.NOTIFICATION_ERRORS.UNKNOWN_NOTIFICATIONS_SERVER_ERROR, | ||
boError: errors_enum_1.ERRORS.UNKNOWN_NOTIFICATIONS_SERVER_ERROR, | ||
boStatus: core_1.HTTP_STATUS.HTTP_4XX_FORBIDDEN | ||
@@ -76,0 +98,0 @@ }); |
export { MailCtrl } from "./controllers/mails.controller"; | ||
export { NOTIFICATION_ERRORS } from "./models/errors.enum"; | ||
export { ERRORS } from "./models/errors.enum"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NOTIFICATION_ERRORS = exports.MailCtrl = void 0; | ||
exports.ERRORS = exports.MailCtrl = void 0; | ||
var mails_controller_1 = require("./controllers/mails.controller"); | ||
Object.defineProperty(exports, "MailCtrl", { enumerable: true, get: function () { return mails_controller_1.MailCtrl; } }); | ||
var errors_enum_1 = require("./models/errors.enum"); | ||
Object.defineProperty(exports, "NOTIFICATION_ERRORS", { enumerable: true, get: function () { return errors_enum_1.NOTIFICATION_ERRORS; } }); | ||
Object.defineProperty(exports, "ERRORS", { enumerable: true, get: function () { return errors_enum_1.ERRORS; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,50 @@ | ||
export declare enum NOTIFICATION_ERRORS { | ||
UNKNOWN_NOTIFICATIONS_SERVER_ERROR = 1500, | ||
INVALID_MAIL_TEMPLATE = 1501, | ||
INVALID_MAIL_SETTINGS = 1502, | ||
INVALID_MAIL_SERVER = 1503, | ||
INVALID_PUSH_NOTIFICATION = 1525, | ||
INVALID_TELEGRAM_SETTINGS = 1550, | ||
INVALID_TELEGRAM_AUTHENTICATION = 1551 | ||
} | ||
export declare const ERRORS: { | ||
UNKNOWN_NOTIFICATIONS_SERVER_ERROR: { | ||
value: number; | ||
str: string; | ||
}; | ||
NOT_AUTHORIZED: { | ||
value: number; | ||
str: string; | ||
}; | ||
INVALID_MAIL_TEMPLATE: { | ||
value: number; | ||
str: string; | ||
}; | ||
INVALID_MAIL_SETTINGS: { | ||
value: number; | ||
str: string; | ||
}; | ||
INVALID_MAIL_SERVER: { | ||
value: number; | ||
str: string; | ||
}; | ||
INVALID_MAIL_DATA: { | ||
value: number; | ||
str: string; | ||
}; | ||
MAIL_SERVER_ERROR: { | ||
value: number; | ||
str: string; | ||
}; | ||
INVALID_PUSH_NOTIFICATION: { | ||
value: number; | ||
str: string; | ||
}; | ||
INVALID_PUSH_SETTINGS: { | ||
value: number; | ||
str: string; | ||
}; | ||
PUSH_NOTIFICATION_ERROR: { | ||
value: number; | ||
str: string; | ||
}; | ||
INVALID_TELEGRAM_SETTINGS: { | ||
value: number; | ||
str: string; | ||
}; | ||
INVALID_TELEGRAM_AUTHENTICATION: { | ||
value: number; | ||
str: string; | ||
}; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NOTIFICATION_ERRORS = void 0; | ||
var NOTIFICATION_ERRORS; | ||
(function (NOTIFICATION_ERRORS) { | ||
NOTIFICATION_ERRORS[NOTIFICATION_ERRORS["UNKNOWN_NOTIFICATIONS_SERVER_ERROR"] = 1500] = "UNKNOWN_NOTIFICATIONS_SERVER_ERROR"; | ||
NOTIFICATION_ERRORS[NOTIFICATION_ERRORS["INVALID_MAIL_TEMPLATE"] = 1501] = "INVALID_MAIL_TEMPLATE"; | ||
NOTIFICATION_ERRORS[NOTIFICATION_ERRORS["INVALID_MAIL_SETTINGS"] = 1502] = "INVALID_MAIL_SETTINGS"; | ||
NOTIFICATION_ERRORS[NOTIFICATION_ERRORS["INVALID_MAIL_SERVER"] = 1503] = "INVALID_MAIL_SERVER"; | ||
NOTIFICATION_ERRORS[NOTIFICATION_ERRORS["INVALID_PUSH_NOTIFICATION"] = 1525] = "INVALID_PUSH_NOTIFICATION"; | ||
NOTIFICATION_ERRORS[NOTIFICATION_ERRORS["INVALID_TELEGRAM_SETTINGS"] = 1550] = "INVALID_TELEGRAM_SETTINGS"; | ||
NOTIFICATION_ERRORS[NOTIFICATION_ERRORS["INVALID_TELEGRAM_AUTHENTICATION"] = 1551] = "INVALID_TELEGRAM_AUTHENTICATION"; | ||
})(NOTIFICATION_ERRORS = exports.NOTIFICATION_ERRORS || (exports.NOTIFICATION_ERRORS = {})); | ||
exports.ERRORS = void 0; | ||
exports.ERRORS = { | ||
UNKNOWN_NOTIFICATIONS_SERVER_ERROR: { | ||
value: 1500, | ||
str: "unknown-notifications-server-error" | ||
}, | ||
NOT_AUTHORIZED: { | ||
value: 1501, | ||
str: "not-authorized" | ||
}, | ||
INVALID_MAIL_TEMPLATE: { | ||
value: 1520, | ||
str: "invalid-mail-template" | ||
}, | ||
INVALID_MAIL_SETTINGS: { | ||
value: 1521, | ||
str: "invalid-mail-settings" | ||
}, | ||
INVALID_MAIL_SERVER: { | ||
value: 1522, | ||
str: "invalid-mail-server" | ||
}, | ||
INVALID_MAIL_DATA: { | ||
value: 1523, | ||
str: "invalid-mail-data" | ||
}, | ||
MAIL_SERVER_ERROR: { | ||
value: 1524, | ||
str: "mail-server-error" | ||
}, | ||
INVALID_PUSH_NOTIFICATION: { | ||
value: 1540, | ||
str: "invalid-push-notification" | ||
}, | ||
INVALID_PUSH_SETTINGS: { | ||
value: 1541, | ||
str: "invalid-push-settings" | ||
}, | ||
PUSH_NOTIFICATION_ERROR: { | ||
value: 1542, | ||
str: "push-notification-error" | ||
}, | ||
INVALID_TELEGRAM_SETTINGS: { | ||
value: 1560, | ||
str: "invalid-telegram-settings" | ||
}, | ||
INVALID_TELEGRAM_AUTHENTICATION: { | ||
value: 1561, | ||
str: "invalid-telegram-authentication" | ||
} | ||
}; | ||
//# sourceMappingURL=errors.enum.js.map |
{ | ||
"name": "@ikoabo/notifications", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "IKOA Business Opportunity Notifications API", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
29671
497
0