@nimee/inforu 1.0.3 → 1.0.4

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.
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.triggerEventToStartAutomation = void 0;
16
16
  const error_handler_1 = require("@nimee/error-handler");
17
+ const normalize_1 = require("./normalize");
17
18
  const logger_1 = __importDefault(require("@nimee/logger"));
18
19
  const axios_1 = __importDefault(require("axios"));
19
20
  function triggerEventToStartAutomation(params) {
@@ -23,23 +24,24 @@ function triggerEventToStartAutomation(params) {
23
24
  if (!apiKey || !eventName || !data || !username) {
24
25
  throw new error_handler_1.CustomError("Missing_API_KEY_TRIGGER_EVENT", 400, "Missing API key or event name or data or username");
25
26
  }
27
+ const normalizeContact = (0, normalize_1.prepareContactsPayload)(data);
26
28
  const json = {
27
- User: {
28
- Username: username,
29
- Token: apiKey,
30
- },
31
29
  Data: {
32
30
  ApiEventName: eventName,
33
- Contacts: data,
31
+ Contacts: normalizeContact,
34
32
  },
35
33
  };
36
- const apiUrl = `https://capi.inforu.co.il/api/Automation/Trigger?json=${json}`;
37
- const response = yield axios_1.default.post(`${apiUrl}`);
38
- logger_1.default.debug("trigger sent successfully:", response.data);
34
+ const apiUrl = "https://capi.inforu.co.il/api/Automation/Trigger";
35
+ const response = yield axios_1.default.post(apiUrl, json, {
36
+ headers: {
37
+ Authorization: `${apiKey}`,
38
+ },
39
+ });
40
+ logger_1.default.debug(`trigger sent successfully: ${JSON.stringify(response.data)}`);
39
41
  return response.data;
40
42
  }
41
43
  catch (error) {
42
- throw new error_handler_1.CustomError("Failed to create group", 450, error);
44
+ throw new error_handler_1.CustomError("Failed to trigger automation", 450, error);
43
45
  }
44
46
  });
45
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"automations.js","sourceRoot":"","sources":["../src/automations.ts"],"names":[],"mappings":";;;;;;;;;;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,sCAAsC;AACtC,iBAAiB;AACjB,wBAAwB;AACxB,sBAAsB;AACtB,kCAAkC;AAClC,8BAA8B;AAC9B,KAAK;AACL,IAAI;AACJ,qCAAqC;AACrC,KAAK;AACL,IAAI;AACJ,IAAI"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from "./sendSMS";
2
2
  export * from "./createGroup";
3
+ export * from "./automations";
4
+ export * from "./sendWA";
package/dist/index.js CHANGED
@@ -17,4 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // export * from "./event";
18
18
  __exportStar(require("./sendSMS"), exports);
19
19
  __exportStar(require("./createGroup"), exports);
20
+ __exportStar(require("./automations"), exports);
21
+ __exportStar(require("./sendWA"), exports);
20
22
  //# 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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2BAA2B;AAC3B,4CAA0B;AAC1B,gDAA8B;AAC9B,gDAA8B;AAC9B,2CAAyB"}
@@ -0,0 +1,17 @@
1
+ import { IEndUserModel } from "@nimee/shared-types";
2
+ type ContactsPayload = {
3
+ endUsers: IEndUserModel[];
4
+ } | {
5
+ endUser: IEndUserModel;
6
+ };
7
+ export declare function prepareContactsPayload(data: ContactsPayload): IInforuContact[];
8
+ interface IInforuContact {
9
+ FirstName: string;
10
+ LastName: string;
11
+ Email: string;
12
+ PhoneNumber: string;
13
+ GenderId?: number;
14
+ BirthDate?: string;
15
+ MyCustomField?: string;
16
+ }
17
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareContactsPayload = void 0;
4
+ const error_handler_1 = require("@nimee/error-handler");
5
+ function normalizeBetweenEndUserToContacts(contacts) {
6
+ return contacts.map((contact) => {
7
+ return {
8
+ FirstName: contact.fname,
9
+ LastName: contact.lname,
10
+ Email: contact.email,
11
+ PhoneNumber: contact.phone,
12
+ IsMember: contact.isMember,
13
+ participationAtEventsCounter: contact.participationAtEventsCounter,
14
+ };
15
+ });
16
+ }
17
+ function prepareContactsPayload(data) {
18
+ if ("endUsers" in data && Array.isArray(data.endUsers) && data.endUsers.length) {
19
+ return normalizeBetweenEndUserToContacts(data.endUsers);
20
+ }
21
+ else if ("endUser" in data) {
22
+ return normalizeBetweenEndUserToContacts([data.endUser]);
23
+ }
24
+ throw new error_handler_1.CustomError("invalid_data_in_inforu_prepare_contacts", 400, `Invalid data ${JSON.stringify(data)}`);
25
+ }
26
+ exports.prepareContactsPayload = prepareContactsPayload;
27
+ //# sourceMappingURL=normalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":";;;AAAA,wDAAmD;AAGnD,SAAS,iCAAiC,CAAC,QAAyB;IAClE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,OAAO;YACL,SAAS,EAAE,OAAO,CAAC,KAAK;YACxB,QAAQ,EAAE,OAAO,CAAC,KAAK;YACvB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,WAAW,EAAE,OAAO,CAAC,KAAK;YAC1B,QAAQ,EAAG,OAAe,CAAC,QAAQ;YACnC,4BAA4B,EAAG,OAAe,CAAC,4BAA4B;SAC5E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAID,SAAgB,sBAAsB,CAAC,IAAqB;IAC1D,IAAI,UAAU,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC/E,OAAO,iCAAiC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC;SAAM,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QAC7B,OAAO,iCAAiC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,MAAM,IAAI,2BAAW,CAAC,yCAAyC,EAAE,GAAG,EAAE,gBAAgB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChH,CAAC;AAPD,wDAOC"}
@@ -0,0 +1,8 @@
1
+ export declare function sendWhatsApp(params: {
2
+ apiKey: string;
3
+ message: string;
4
+ phone: string;
5
+ messageMedia?: string;
6
+ customerMessageId?: string;
7
+ customerParameter?: string;
8
+ }): Promise<any>;
package/dist/sendWA.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.sendWhatsApp = void 0;
16
+ const error_handler_1 = require("@nimee/error-handler");
17
+ const logger_1 = __importDefault(require("@nimee/logger"));
18
+ const axios_1 = __importDefault(require("axios"));
19
+ function sendWhatsApp(params) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ try {
22
+ const { apiKey, message, phone, messageMedia, customerMessageId, customerParameter } = params;
23
+ if (!apiKey)
24
+ throw new error_handler_1.CustomError("Missing_API_KEY_SEND_WHATSAPP", 400, "Missing API key");
25
+ const apiUrl = "https://capi.inforu.co.il/api/v2/WhatsApp/SendWhatsAppChat";
26
+ const data = {
27
+ Data: {
28
+ Message: message,
29
+ Phone: phone,
30
+ MessageMedia: messageMedia,
31
+ Settings: {
32
+ CustomerMessageId: customerMessageId,
33
+ CustomerParameter: customerParameter,
34
+ },
35
+ },
36
+ };
37
+ const response = yield axios_1.default.post(apiUrl, data, {
38
+ headers: {
39
+ "Content-Type": "application/json",
40
+ Authorization: apiKey,
41
+ },
42
+ });
43
+ logger_1.default.debug("WhatsApp message sent successfully:", response.data);
44
+ return response.data;
45
+ }
46
+ catch (error) {
47
+ logger_1.default.error(JSON.stringify(error));
48
+ throw new error_handler_1.CustomError("Failed to send WhatsApp message", 450, error);
49
+ }
50
+ });
51
+ }
52
+ exports.sendWhatsApp = sendWhatsApp;
53
+ //# sourceMappingURL=sendWA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendWA.js","sourceRoot":"","sources":["../src/sendWA.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAAmD;AACnD,2DAAmC;AACnC,kDAA0B;AAE1B,SAAsB,YAAY,CAAC,MAOlC;;QACC,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;YAC9F,IAAI,CAAC,MAAM;gBAAE,MAAM,IAAI,2BAAW,CAAC,+BAA+B,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC;YAE5F,MAAM,MAAM,GAAG,4DAA4D,CAAC;YAC5E,MAAM,IAAI,GAAG;gBACX,IAAI,EAAE;oBACJ,OAAO,EAAE,OAAO;oBAChB,KAAK,EAAE,KAAK;oBACZ,YAAY,EAAE,YAAY;oBAC1B,QAAQ,EAAE;wBACR,iBAAiB,EAAE,iBAAiB;wBACpC,iBAAiB,EAAE,iBAAiB;qBACrC;iBACF;aACF,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE;gBAC9C,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,aAAa,EAAE,MAAM;iBACtB;aACF,CAAC,CAAC;YAEH,gBAAM,CAAC,KAAK,CAAC,qCAAqC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnE,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,gBAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YACpC,MAAM,IAAI,2BAAW,CAAC,iCAAiC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;CAAA;AAtCD,oCAsCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimee/inforu",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "inforu SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "author": "dan goldberg",
@@ -1,4 +1,5 @@
1
1
  import { CustomError, errorHandler } from "@nimee/error-handler";
2
+ import { prepareContactsPayload } from "./normalize";
2
3
  import logger from "@nimee/logger";
3
4
  import axios from "axios";
4
5
  export async function triggerEventToStartAutomation(params: { apiKey: string; username: string; eventName: string; data: any }) {
@@ -7,22 +8,23 @@ export async function triggerEventToStartAutomation(params: { apiKey: string; us
7
8
  if (!apiKey || !eventName || !data || !username) {
8
9
  throw new CustomError("Missing_API_KEY_TRIGGER_EVENT", 400, "Missing API key or event name or data or username");
9
10
  }
11
+ const normalizeContact = prepareContactsPayload(data);
10
12
  const json = {
11
- User: {
12
- Username: username,
13
- Token: apiKey,
14
- },
15
13
  Data: {
16
14
  ApiEventName: eventName,
17
- Contacts: data,
15
+ Contacts: normalizeContact,
18
16
  },
19
17
  };
20
- const apiUrl = `https://capi.inforu.co.il/api/Automation/Trigger?json=${json}`;
21
- const response = await axios.post(`${apiUrl}`);
22
- logger.debug("trigger sent successfully:", response.data);
18
+ const apiUrl = "https://capi.inforu.co.il/api/Automation/Trigger";
19
+ const response = await axios.post(apiUrl, json, {
20
+ headers: {
21
+ Authorization: `${apiKey}`,
22
+ },
23
+ });
24
+ logger.debug(`trigger sent successfully: ${JSON.stringify(response.data)}`);
23
25
  return response.data;
24
26
  } catch (error) {
25
- throw new CustomError("Failed to create group", 450, error);
27
+ throw new CustomError("Failed to trigger automation", 450, error);
26
28
  }
27
29
  }
28
30
  // json example:
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  // export * from "./event";
2
2
  export * from "./sendSMS";
3
3
  export * from "./createGroup";
4
+ export * from "./automations";
5
+ export * from "./sendWA";
@@ -0,0 +1,36 @@
1
+ import { CustomError } from "@nimee/error-handler";
2
+ import { IEndUserModel } from "@nimee/shared-types";
3
+
4
+ function normalizeBetweenEndUserToContacts(contacts: IEndUserModel[]): IInforuContact[] {
5
+ return contacts.map((contact) => {
6
+ return {
7
+ FirstName: contact.fname,
8
+ LastName: contact.lname,
9
+ Email: contact.email,
10
+ PhoneNumber: contact.phone,
11
+ IsMember: (contact as any).isMember,
12
+ participationAtEventsCounter: (contact as any).participationAtEventsCounter,
13
+ };
14
+ });
15
+ }
16
+
17
+ type ContactsPayload = { endUsers: IEndUserModel[] } | { endUser: IEndUserModel };
18
+
19
+ export function prepareContactsPayload(data: ContactsPayload): IInforuContact[] {
20
+ if ("endUsers" in data && Array.isArray(data.endUsers) && data.endUsers.length) {
21
+ return normalizeBetweenEndUserToContacts(data.endUsers);
22
+ } else if ("endUser" in data) {
23
+ return normalizeBetweenEndUserToContacts([data.endUser]);
24
+ }
25
+ throw new CustomError("invalid_data_in_inforu_prepare_contacts", 400, `Invalid data ${JSON.stringify(data)}`);
26
+ }
27
+
28
+ interface IInforuContact {
29
+ FirstName: string;
30
+ LastName: string;
31
+ Email: string;
32
+ PhoneNumber: string;
33
+ GenderId?: number;
34
+ BirthDate?: string;
35
+ MyCustomField?: string;
36
+ }
package/src/sendWA.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { CustomError } from "@nimee/error-handler";
2
+ import logger from "@nimee/logger";
3
+ import axios from "axios";
4
+
5
+ export async function sendWhatsApp(params: {
6
+ apiKey: string;
7
+ message: string;
8
+ phone: string;
9
+ messageMedia?: string;
10
+ customerMessageId?: string;
11
+ customerParameter?: string;
12
+ }) {
13
+ try {
14
+ const { apiKey, message, phone, messageMedia, customerMessageId, customerParameter } = params;
15
+ if (!apiKey) throw new CustomError("Missing_API_KEY_SEND_WHATSAPP", 400, "Missing API key");
16
+
17
+ const apiUrl = "https://capi.inforu.co.il/api/v2/WhatsApp/SendWhatsAppChat";
18
+ const data = {
19
+ Data: {
20
+ Message: message,
21
+ Phone: phone,
22
+ MessageMedia: messageMedia,
23
+ Settings: {
24
+ CustomerMessageId: customerMessageId,
25
+ CustomerParameter: customerParameter,
26
+ },
27
+ },
28
+ };
29
+
30
+ const response = await axios.post(apiUrl, data, {
31
+ headers: {
32
+ "Content-Type": "application/json",
33
+ Authorization: apiKey,
34
+ },
35
+ });
36
+
37
+ logger.debug("WhatsApp message sent successfully:", response.data);
38
+ return response.data;
39
+ } catch (error) {
40
+ logger.error(JSON.stringify(error));
41
+ throw new CustomError("Failed to send WhatsApp message", 450, error);
42
+ }
43
+ }