@nimee/inforu 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/normalize.js +1 -1
- package/dist/sendEmail.d.ts +12 -0
- package/dist/sendEmail.js +82 -0
- package/dist/sendEmail.js.map +1 -0
- package/package.json +2 -3
- package/src/index.ts +1 -0
- package/src/normalize.ts +1 -1
- package/src/sendEmail.ts +76 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,4 +19,5 @@ __exportStar(require("./sendSMS"), exports);
|
|
|
19
19
|
__exportStar(require("./createGroup"), exports);
|
|
20
20
|
__exportStar(require("./automations"), exports);
|
|
21
21
|
__exportStar(require("./sendWA"), exports);
|
|
22
|
+
__exportStar(require("./sendEmail"), exports);
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2BAA2B;AAC3B,4CAA0B;AAC1B,gDAA8B;AAC9B,gDAA8B;AAC9B,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2BAA2B;AAC3B,4CAA0B;AAC1B,gDAA8B;AAC9B,gDAA8B;AAC9B,2CAAyB;AACzB,8CAA4B"}
|
package/dist/normalize.js
CHANGED
|
@@ -10,7 +10,7 @@ function normalizeBetweenEndUserToContacts(contacts, groupName) {
|
|
|
10
10
|
Email: contact.email,
|
|
11
11
|
PhoneNumber: contact.phone,
|
|
12
12
|
IsMember: contact.isMember,
|
|
13
|
-
|
|
13
|
+
ParticipationAtEventsCounter: contact.participationAtEventsCounter,
|
|
14
14
|
AddToGroupName: groupName,
|
|
15
15
|
ContactRefId: contact._id,
|
|
16
16
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IEndUserModel } from "@nimee/shared-types";
|
|
2
|
+
export declare function sendEmail(params: {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
campaignName: string;
|
|
5
|
+
fromAddress: string;
|
|
6
|
+
replyAddress: string;
|
|
7
|
+
fromName: string;
|
|
8
|
+
subject: string;
|
|
9
|
+
preHeader: string;
|
|
10
|
+
body: string;
|
|
11
|
+
contacts: IEndUserModel[];
|
|
12
|
+
}): Promise<any>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// var axios = require('axios');
|
|
3
|
+
// var data = '{\r\n "Data": {\r\n "CampaignName": "My First Email",\r\n "CampaignRefId": "213456789",\r\n "FromAddress": "ariel.l@inforu.co.il",\r\n "ReplyAddress": "ariel@abc.co.il",\r\n "FromName": "Abc Company",\r\n "Subject": "Summer Sale",\r\n "PreHeader": "AAAA DDDDD",\r\n "Body": "test...",\r\n "IncludeContacts": [\r\n {\r\n "Email": "ohad@inforu.co.il"\r\n }\r\n ]\r\n }\r\n}';
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.sendEmail = void 0;
|
|
18
|
+
// var config = {
|
|
19
|
+
// method: 'post',
|
|
20
|
+
// maxBodyLength: Infinity,
|
|
21
|
+
// url: 'https://capi.inforu.co.il/api/v2/Umail/Message/Send',
|
|
22
|
+
// headers: {
|
|
23
|
+
// 'Content-Type': 'application/json; charset=utf-8',
|
|
24
|
+
// 'Authorization': 'Your Base Credentials'
|
|
25
|
+
// },
|
|
26
|
+
// data : data
|
|
27
|
+
// };
|
|
28
|
+
// axios(config)
|
|
29
|
+
// .then(function (response) {
|
|
30
|
+
// console.log(JSON.stringify(response.data));
|
|
31
|
+
// })
|
|
32
|
+
// .catch(function (error) {
|
|
33
|
+
// console.log(error);
|
|
34
|
+
// });
|
|
35
|
+
const error_handler_1 = require("@nimee/error-handler");
|
|
36
|
+
const logger_1 = __importDefault(require("@nimee/logger"));
|
|
37
|
+
const axios_1 = __importDefault(require("axios"));
|
|
38
|
+
const normalize_1 = require("./normalize");
|
|
39
|
+
function sendEmail(params) {
|
|
40
|
+
var _a;
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
try {
|
|
43
|
+
const { apiKey, campaignName, fromAddress, replyAddress, fromName, subject, preHeader, body, contacts } = params;
|
|
44
|
+
if (!apiKey || !campaignName || !fromAddress || !replyAddress || !fromName || !subject || !body || !contacts) {
|
|
45
|
+
const contactsPayload = { endUsers: contacts };
|
|
46
|
+
const normalizeContact = (0, normalize_1.prepareContactsPayload)(contactsPayload);
|
|
47
|
+
const apiUrl = "https://capi.inforu.co.il/api/v2/Umail/Message/Send";
|
|
48
|
+
const data = {
|
|
49
|
+
Data: {
|
|
50
|
+
CampaignName: campaignName,
|
|
51
|
+
FromAddress: fromAddress,
|
|
52
|
+
ReplyAddress: replyAddress,
|
|
53
|
+
FromName: fromName,
|
|
54
|
+
Subject: subject,
|
|
55
|
+
PreHeader: preHeader,
|
|
56
|
+
Body: body,
|
|
57
|
+
IncludeContacts: normalizeContact,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
const response = yield axios_1.default.post(apiUrl, data, {
|
|
61
|
+
headers: {
|
|
62
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
63
|
+
Authorization: apiKey,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
return response.data;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const errorResponse = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
71
|
+
if (errorResponse) {
|
|
72
|
+
logger_1.default.error(JSON.stringify(errorResponse));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
logger_1.default.error(JSON.stringify(error));
|
|
76
|
+
}
|
|
77
|
+
throw new error_handler_1.CustomError("Failed to send email inforu", 450, error);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.sendEmail = sendEmail;
|
|
82
|
+
//# sourceMappingURL=sendEmail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendEmail.js","sourceRoot":"","sources":["../src/sendEmail.ts"],"names":[],"mappings":";AAAA,gCAAgC;AAChC,qfAAqf;;;;;;;;;;;;;;;AAErf,iBAAiB;AACjB,oBAAoB;AACpB,2BAA2B;AAC3B,gEAAgE;AAChE,eAAe;AACf,yDAAyD;AACzD,+CAA+C;AAC/C,OAAO;AACP,gBAAgB;AAChB,KAAK;AAEL,gBAAgB;AAChB,8BAA8B;AAC9B,gDAAgD;AAChD,KAAK;AACL,4BAA4B;AAC5B,wBAAwB;AACxB,MAAM;AACN,wDAAiE;AACjE,2DAAmC;AAEnC,kDAA0B;AAC1B,2CAAqD;AAErD,SAAsB,SAAS,CAAC,MAU/B;;;QACC,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,SA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,MAAM,IAAI,2BAAW,CAAC,6BAA6B,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC;;CACF;AAhDD,8BAgDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimee/inforu",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "inforu SDK for Node.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "dan goldberg",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
|
|
14
14
|
"incVersionAndPublish": "npm version patch && npm run publish-it && npm run i-all-workspaces",
|
|
15
15
|
"publish-it": "npm run build && npm publish --scope=nimee --access public",
|
|
16
|
-
"i-all-workspaces": "version=${npm_package_version} npm i @nimee/
|
|
16
|
+
"i-all-workspaces": "version=${npm_package_version} npm i @nimee/inforu@$version --workspace=@nimee/event --workspace=@nimee/user-event --workspace=@nimee/send-notification --workspace=@nimee/user --workspace=@nimee/payment --workspace=@nimee/analytics --workspace=@nimee/crm"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"types": "dist/index.d.ts",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@nimee/error-handler": "^0.0.9",
|
|
31
|
-
"@nimee/logger": "^1.0.27",
|
|
32
31
|
"axios": "1.2.1"
|
|
33
32
|
}
|
|
34
33
|
}
|
package/src/index.ts
CHANGED
package/src/normalize.ts
CHANGED
|
@@ -9,7 +9,7 @@ function normalizeBetweenEndUserToContacts(contacts: IEndUserModel[], groupName?
|
|
|
9
9
|
Email: contact.email,
|
|
10
10
|
PhoneNumber: contact.phone,
|
|
11
11
|
IsMember: (contact as any).isMember,
|
|
12
|
-
|
|
12
|
+
ParticipationAtEventsCounter: (contact as any).participationAtEventsCounter,
|
|
13
13
|
AddToGroupName: groupName,
|
|
14
14
|
ContactRefId: contact._id,
|
|
15
15
|
};
|
package/src/sendEmail.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// var axios = require('axios');
|
|
2
|
+
// var data = '{\r\n "Data": {\r\n "CampaignName": "My First Email",\r\n "CampaignRefId": "213456789",\r\n "FromAddress": "ariel.l@inforu.co.il",\r\n "ReplyAddress": "ariel@abc.co.il",\r\n "FromName": "Abc Company",\r\n "Subject": "Summer Sale",\r\n "PreHeader": "AAAA DDDDD",\r\n "Body": "test...",\r\n "IncludeContacts": [\r\n {\r\n "Email": "ohad@inforu.co.il"\r\n }\r\n ]\r\n }\r\n}';
|
|
3
|
+
|
|
4
|
+
// var config = {
|
|
5
|
+
// method: 'post',
|
|
6
|
+
// maxBodyLength: Infinity,
|
|
7
|
+
// url: 'https://capi.inforu.co.il/api/v2/Umail/Message/Send',
|
|
8
|
+
// headers: {
|
|
9
|
+
// 'Content-Type': 'application/json; charset=utf-8',
|
|
10
|
+
// 'Authorization': 'Your Base Credentials'
|
|
11
|
+
// },
|
|
12
|
+
// data : data
|
|
13
|
+
// };
|
|
14
|
+
|
|
15
|
+
// axios(config)
|
|
16
|
+
// .then(function (response) {
|
|
17
|
+
// console.log(JSON.stringify(response.data));
|
|
18
|
+
// })
|
|
19
|
+
// .catch(function (error) {
|
|
20
|
+
// console.log(error);
|
|
21
|
+
// });
|
|
22
|
+
import { CustomError, errorHandler } from "@nimee/error-handler";
|
|
23
|
+
import logger from "@nimee/logger";
|
|
24
|
+
import { IEndUserModel } from "@nimee/shared-types";
|
|
25
|
+
import axios from "axios";
|
|
26
|
+
import { prepareContactsPayload } from "./normalize";
|
|
27
|
+
|
|
28
|
+
export async function sendEmail(params: {
|
|
29
|
+
apiKey: string;
|
|
30
|
+
campaignName: string;
|
|
31
|
+
fromAddress: string;
|
|
32
|
+
replyAddress: string;
|
|
33
|
+
fromName: string;
|
|
34
|
+
subject: string;
|
|
35
|
+
preHeader: string;
|
|
36
|
+
body: string;
|
|
37
|
+
contacts: IEndUserModel[];
|
|
38
|
+
}) {
|
|
39
|
+
try {
|
|
40
|
+
const { apiKey, campaignName, fromAddress, replyAddress, fromName, subject, preHeader, body, contacts } = params;
|
|
41
|
+
if (!apiKey || !campaignName || !fromAddress || !replyAddress || !fromName || !subject || !body || !contacts) {
|
|
42
|
+
const contactsPayload = { endUsers: contacts };
|
|
43
|
+
const normalizeContact = prepareContactsPayload(contactsPayload);
|
|
44
|
+
const apiUrl = "https://capi.inforu.co.il/api/v2/Umail/Message/Send";
|
|
45
|
+
const data = {
|
|
46
|
+
Data: {
|
|
47
|
+
CampaignName: campaignName,
|
|
48
|
+
FromAddress: fromAddress,
|
|
49
|
+
ReplyAddress: replyAddress,
|
|
50
|
+
FromName: fromName,
|
|
51
|
+
Subject: subject,
|
|
52
|
+
PreHeader: preHeader,
|
|
53
|
+
Body: body,
|
|
54
|
+
IncludeContacts: normalizeContact,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const response = await axios.post(apiUrl, data, {
|
|
59
|
+
headers: {
|
|
60
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
61
|
+
Authorization: apiKey,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return response.data;
|
|
66
|
+
}
|
|
67
|
+
} catch (error: any) {
|
|
68
|
+
const errorResponse = error.response?.data;
|
|
69
|
+
if (errorResponse) {
|
|
70
|
+
logger.error(JSON.stringify(errorResponse));
|
|
71
|
+
} else {
|
|
72
|
+
logger.error(JSON.stringify(error));
|
|
73
|
+
}
|
|
74
|
+
throw new CustomError("Failed to send email inforu", 450, error);
|
|
75
|
+
}
|
|
76
|
+
}
|