Skip to content

Commit 1cf4da5

Browse files
author
Sergey Khomushin
committed
build version 3.2.0
1 parent cd5905f commit 1cf4da5

File tree

12 files changed

+165
-8
lines changed

12 files changed

+165
-8
lines changed

cjs/api/sendPost.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.sendPost = void 0;
4+
const EmailJSResponseStatus_1 = require("../models/EmailJSResponseStatus");
5+
const store_1 = require("../store/store");
6+
const sendPost = (url, data, headers = {}) => {
7+
return new Promise((resolve, reject) => {
8+
const xhr = new XMLHttpRequest();
9+
xhr.addEventListener('load', ({ target }) => {
10+
const responseStatus = new EmailJSResponseStatus_1.EmailJSResponseStatus(target);
11+
if (responseStatus.status === 200 || responseStatus.text === 'OK') {
12+
resolve(responseStatus);
13+
}
14+
else {
15+
reject(responseStatus);
16+
}
17+
});
18+
xhr.addEventListener('error', ({ target }) => {
19+
reject(new EmailJSResponseStatus_1.EmailJSResponseStatus(target));
20+
});
21+
xhr.open('POST', store_1.store._origin + url, true);
22+
Object.keys(headers).forEach((key) => {
23+
xhr.setRequestHeader(key, headers[key]);
24+
});
25+
xhr.send(data);
26+
});
27+
};
28+
exports.sendPost = sendPost;

cjs/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.sendForm = exports.send = exports.init = void 0;
4+
const init_1 = require("./methods/init/init");
5+
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_1.init; } });
6+
const send_1 = require("./methods/send/send");
7+
Object.defineProperty(exports, "send", { enumerable: true, get: function () { return send_1.send; } });
8+
const sendForm_1 = require("./methods/sendForm/sendForm");
9+
Object.defineProperty(exports, "sendForm", { enumerable: true, get: function () { return sendForm_1.sendForm; } });
10+
exports.default = {
11+
init: init_1.init,
12+
send: send_1.send,
13+
sendForm: sendForm_1.sendForm,
14+
};

cjs/methods/init/init.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.init = void 0;
4+
const store_1 = require("../../store/store");
5+
/**
6+
* Initiation
7+
* @param {string} userID - set the EmailJS user ID
8+
* @param {string} origin - set the EmailJS origin
9+
*/
10+
const init = (userID, origin = 'https://api.emailjs.com') => {
11+
store_1.store._userID = userID;
12+
store_1.store._origin = origin;
13+
};
14+
exports.init = init;

cjs/methods/send/send.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.send = void 0;
4+
const store_1 = require("../../store/store");
5+
const validateParams_1 = require("../../utils/validateParams");
6+
const sendPost_1 = require("../../api/sendPost");
7+
/**
8+
* Send a template to the specific EmailJS service
9+
* @param {string} serviceID - the EmailJS service ID
10+
* @param {string} templateID - the EmailJS template ID
11+
* @param {object} templatePrams - the template params, what will be set to the EmailJS template
12+
* @param {string} userID - the EmailJS user ID
13+
* @returns {Promise<EmailJSResponseStatus>}
14+
*/
15+
const send = (serviceID, templateID, templatePrams, userID) => {
16+
const uID = userID || store_1.store._userID;
17+
validateParams_1.validateParams(uID, serviceID, templateID);
18+
const params = {
19+
lib_version: '3.2.0',
20+
user_id: uID,
21+
service_id: serviceID,
22+
template_id: templateID,
23+
template_params: templatePrams,
24+
};
25+
return sendPost_1.sendPost('/api/v1.0/email/send', JSON.stringify(params), {
26+
'Content-type': 'application/json',
27+
});
28+
};
29+
exports.send = send;

cjs/methods/sendForm/sendForm.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.sendForm = void 0;
4+
const store_1 = require("../../store/store");
5+
const validateParams_1 = require("../../utils/validateParams");
6+
const sendPost_1 = require("../../api/sendPost");
7+
const findHTMLForm = (form) => {
8+
let currentForm;
9+
if (typeof form === 'string') {
10+
currentForm = document.querySelector(form);
11+
}
12+
else {
13+
currentForm = form;
14+
}
15+
if (!currentForm || currentForm.nodeName !== 'FORM') {
16+
throw 'The 3rd parameter is expected to be the HTML form element or the style selector of form';
17+
}
18+
return currentForm;
19+
};
20+
/**
21+
* Send a form the specific EmailJS service
22+
* @param {string} serviceID - the EmailJS service ID
23+
* @param {string} templateID - the EmailJS template ID
24+
* @param {string | HTMLFormElement} form - the form element or selector
25+
* @param {string} userID - the EmailJS user ID
26+
* @returns {Promise<EmailJSResponseStatus>}
27+
*/
28+
const sendForm = (serviceID, templateID, form, userID) => {
29+
const uID = userID || store_1.store._userID;
30+
const currentForm = findHTMLForm(form);
31+
validateParams_1.validateParams(uID, serviceID, templateID);
32+
const formData = new FormData(currentForm);
33+
formData.append('lib_version', '3.2.0');
34+
formData.append('service_id', serviceID);
35+
formData.append('template_id', templateID);
36+
formData.append('user_id', uID);
37+
return sendPost_1.sendPost('/api/v1.0/email/send-form', formData);
38+
};
39+
exports.sendForm = sendForm;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.EmailJSResponseStatus = void 0;
4+
class EmailJSResponseStatus {
5+
constructor(httpResponse) {
6+
this.status = httpResponse.status;
7+
this.text = httpResponse.responseText;
8+
}
9+
}
10+
exports.EmailJSResponseStatus = EmailJSResponseStatus;

cjs/store/store.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.store = void 0;
4+
exports.store = {
5+
_origin: 'https://api.emailjs.com',
6+
};

cjs/utils/validateParams.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.validateParams = void 0;
4+
const validateParams = (userID, serviceID, templateID) => {
5+
if (!userID) {
6+
throw 'The user ID is required. Visit https://dashboard.emailjs.com/admin/integration';
7+
}
8+
if (!serviceID) {
9+
throw 'The service ID is required. Visit https://dashboard.emailjs.com/admin';
10+
}
11+
if (!templateID) {
12+
throw 'The template ID is required. Visit https://dashboard.emailjs.com/admin/templates';
13+
}
14+
return true;
15+
};
16+
exports.validateParams = validateParams;

dist/email.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ var store = __webpack_require__(5465);
16401640
(module.exports = function (key, value) {
16411641
return store[key] || (store[key] = value !== undefined ? value : {});
16421642
})('versions', []).push({
1643-
version: '3.14.0',
1643+
version: '3.15.2',
16441644
mode: IS_PURE ? 'pure' : 'global',
16451645
copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
16461646
});
@@ -2047,7 +2047,8 @@ var SUBCLASSING = false;
20472047
var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen;
20482048

20492049
var FORCED = isForced(PROMISE, function () {
2050-
var GLOBAL_CORE_JS_PROMISE = inspectSource(PromiseConstructor) !== String(PromiseConstructor);
2050+
var PROMISE_CONSTRUCTOR_SOURCE = inspectSource(PromiseConstructor);
2051+
var GLOBAL_CORE_JS_PROMISE = PROMISE_CONSTRUCTOR_SOURCE !== String(PromiseConstructor);
20512052
// V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables
20522053
// https://bugs.chromium.org/p/chromium/issues/detail?id=830565
20532054
// We can't detect it synchronously, so just check versions
@@ -2057,7 +2058,7 @@ var FORCED = isForced(PROMISE, function () {
20572058
// We can't use @@species feature detection in V8 since it causes
20582059
// deoptimization and performance degradation
20592060
// https://github.com/zloirock/core-js/issues/679
2060-
if (V8_VERSION >= 51 && /native code/.test(PromiseConstructor)) return false;
2061+
if (V8_VERSION >= 51 && /native code/.test(PROMISE_CONSTRUCTOR_SOURCE)) return false;
20612062
// Detect correctness of subclassing with @@species support
20622063
var promise = new PromiseConstructor(function (resolve) { resolve(1); });
20632064
var FakePromise = function (exec) {
@@ -2590,7 +2591,7 @@ var send = function send(serviceID, templateID, templatePrams, userID) {
25902591
var uID = userID || store._userID;
25912592
validateParams(uID, serviceID, templateID);
25922593
var params = {
2593-
lib_version: '3.1.0',
2594+
lib_version: '3.2.0',
25942595
user_id: uID,
25952596
service_id: serviceID,
25962597
template_id: templateID,
@@ -2635,7 +2636,7 @@ var sendForm = function sendForm(serviceID, templateID, form, userID) {
26352636
var currentForm = findHTMLForm(form);
26362637
validateParams(uID, serviceID, templateID);
26372638
var formData = new FormData(currentForm);
2638-
formData.append('lib_version', '3.1.0');
2639+
formData.append('lib_version', '3.2.0');
26392640
formData.append('service_id', serviceID);
26402641
formData.append('template_id', templateID);
26412642
formData.append('user_id', uID);

dist/email.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)