@nimee/inforu 1.0.17 → 1.0.18

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.
@@ -0,0 +1,232 @@
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.parseBookPurchaseEventType = exports.isBookPurchaseEvent = exports.BookPurchaseEventType = exports.parseEcommerceEventType = exports.isEcommerceEvent = exports.sendEcommerceOrder = exports.EcommerceEventType = 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
+ // Type for ecommerce events
20
+ var EcommerceEventType;
21
+ (function (EcommerceEventType) {
22
+ // Purchase events
23
+ EcommerceEventType["PURCHASED_PHYSICAL_BOOK"] = "PURCHASED_PHYSICAL_BOOK";
24
+ EcommerceEventType["PURCHASED_DIGITAL_BOOK"] = "PURCHASED_DIGITAL_BOOK";
25
+ EcommerceEventType["PURCHASED_VOD_PRODUCT"] = "PURCHASED_VOD_PRODUCT";
26
+ EcommerceEventType["PURCHASED_EVENT_TICKET"] = "PURCHASED_EVENT_TICKET";
27
+ // Abandoned cart events
28
+ EcommerceEventType["ABANDONED_CART_BOOK"] = "ABANDONED_CART_BOOK";
29
+ EcommerceEventType["ABANDONED_CART"] = "ABANDONED_CART";
30
+ })(EcommerceEventType || (exports.EcommerceEventType = EcommerceEventType = {}));
31
+ // Map internal event types to InfoRu API event names
32
+ const EVENT_TYPE_TO_API_EVENT = {
33
+ [EcommerceEventType.PURCHASED_PHYSICAL_BOOK]: "sales_order_place_after",
34
+ [EcommerceEventType.PURCHASED_DIGITAL_BOOK]: "sales_order_place_after",
35
+ [EcommerceEventType.PURCHASED_VOD_PRODUCT]: "sales_order_place_after",
36
+ [EcommerceEventType.PURCHASED_EVENT_TICKET]: "sales_order_place_after",
37
+ [EcommerceEventType.ABANDONED_CART_BOOK]: "cart_abandoned",
38
+ [EcommerceEventType.ABANDONED_CART]: "cart_abandoned",
39
+ };
40
+ /**
41
+ * Helper function to determine product type from event type
42
+ */
43
+ function getProductType(eventType) {
44
+ switch (eventType) {
45
+ case EcommerceEventType.PURCHASED_PHYSICAL_BOOK:
46
+ return "physical_book";
47
+ case EcommerceEventType.PURCHASED_DIGITAL_BOOK:
48
+ return "digital_book";
49
+ case EcommerceEventType.PURCHASED_VOD_PRODUCT:
50
+ return "vod";
51
+ case EcommerceEventType.PURCHASED_EVENT_TICKET:
52
+ return "event_ticket";
53
+ case EcommerceEventType.ABANDONED_CART_BOOK:
54
+ return "abandoned_book";
55
+ case EcommerceEventType.ABANDONED_CART:
56
+ return "abandoned_cart";
57
+ default:
58
+ return "product";
59
+ }
60
+ }
61
+ /**
62
+ * Transforms purchase data into ecommerce API format
63
+ */
64
+ function prepareEcommercePayload(eventType, data) {
65
+ const isAbandonedCart = eventType === EcommerceEventType.ABANDONED_CART_BOOK || eventType === EcommerceEventType.ABANDONED_CART;
66
+ // Map products to order items
67
+ const orderItems = data.products.map((product) => {
68
+ var _a, _b;
69
+ return ({
70
+ ProductCode: product.code || product.isbn || "",
71
+ ProductName: product.name,
72
+ ProductPrice: product.price,
73
+ ProductQty: product.quantity,
74
+ ProductDescription: product.description || null,
75
+ ProductLink: product.link,
76
+ ProductImage: product.image,
77
+ // Custom fields based on product type
78
+ Custom1: product.isbn || ((_a = product.eventDate) === null || _a === void 0 ? void 0 : _a.toString()) || product.vodDuration,
79
+ Custom2: product.author || product.eventLocation || ((_b = product.vodExpiry) === null || _b === void 0 ? void 0 : _b.toString()),
80
+ Custom3: product.publisher || product.seatNumber || product.vodStreamUrl,
81
+ Custom4: product.format || getProductType(eventType),
82
+ Custom5: eventType, // Add the original event type (e.g., PURCHASED_PHYSICAL_BOOK)
83
+ ProductAttributes: [
84
+ // Always include the event category
85
+ { label: "event_category", value: eventType },
86
+ ...(product.format ? [{ label: "format", value: product.format }] : []),
87
+ ...(product.author ? [{ label: "author", value: product.author }] : []),
88
+ ...(product.publisher ? [{ label: "publisher", value: product.publisher }] : []),
89
+ ...(product.eventDate ? [{ label: "event_date", value: product.eventDate.toString() }] : []),
90
+ ...(product.eventLocation ? [{ label: "location", value: product.eventLocation }] : []),
91
+ ...(product.seatNumber ? [{ label: "seat", value: product.seatNumber }] : []),
92
+ ...(product.downloadLink ? [{ label: "download_link", value: product.downloadLink }] : []),
93
+ ].filter(attr => attr.value) // Remove empty attributes
94
+ });
95
+ });
96
+ // Format order time
97
+ const orderTime = data.orderTime
98
+ ? (data.orderTime instanceof Date
99
+ ? data.orderTime.toISOString().replace('T', ' ').substring(0, 19)
100
+ : data.orderTime)
101
+ : new Date().toISOString().replace('T', ' ').substring(0, 19);
102
+ // Get the appropriate InfoRu API event name
103
+ const apiEventName = EVENT_TYPE_TO_API_EVENT[eventType];
104
+ // Determine group names based on event type
105
+ const groupNames = [];
106
+ switch (eventType) {
107
+ case EcommerceEventType.PURCHASED_PHYSICAL_BOOK:
108
+ groupNames.push("physical_book_buyers");
109
+ break;
110
+ case EcommerceEventType.PURCHASED_DIGITAL_BOOK:
111
+ groupNames.push("digital_book_buyers");
112
+ break;
113
+ case EcommerceEventType.PURCHASED_VOD_PRODUCT:
114
+ groupNames.push("vod_purchasers");
115
+ break;
116
+ case EcommerceEventType.PURCHASED_EVENT_TICKET:
117
+ groupNames.push("event_attendees");
118
+ break;
119
+ case EcommerceEventType.ABANDONED_CART_BOOK:
120
+ groupNames.push("abandoned_cart_books");
121
+ break;
122
+ case EcommerceEventType.ABANDONED_CART:
123
+ groupNames.push("abandoned_cart_general");
124
+ break;
125
+ }
126
+ // Determine if physical shipping is needed
127
+ const needsShipping = eventType === EcommerceEventType.PURCHASED_PHYSICAL_BOOK ||
128
+ eventType === EcommerceEventType.PURCHASED_EVENT_TICKET;
129
+ return {
130
+ Data: {
131
+ Event: apiEventName,
132
+ Category: eventType, // Add the original event type (e.g., PURCHASED_PHYSICAL_BOOK)
133
+ StoreName: data.storeName || "Nimi Store",
134
+ StoreBaseUrl: data.storeUrl || "https://www.nimi.co.il/",
135
+ LinkToCart: isAbandonedCart && data.cartUrl
136
+ ? data.cartUrl
137
+ : `${data.storeUrl || "https://www.nimi.co.il"}/checkout/cart/`,
138
+ IP: data.ip,
139
+ CustomerEmail: data.customerEmail,
140
+ CustomerFirstName: data.customerFirstName,
141
+ CustomerLastName: data.customerLastName,
142
+ ContactRefId: data.contactRefId || "",
143
+ SubscriberStatus: "Subscribed",
144
+ AddToGroupName: groupNames,
145
+ OrderNumber: data.orderNumber,
146
+ OrderAmount: String(data.orderAmount),
147
+ OrderStatus: isAbandonedCart ? "abandoned" : (data.orderStatus || "processing"),
148
+ BillingAddress: data.billingAddress,
149
+ ShippingAddress: needsShipping ? data.shippingAddress : undefined,
150
+ PaymentDescription: data.paymentMethod || "credit card",
151
+ ShippingDescription: needsShipping
152
+ ? (data.shippingMethod || "Standard shipping")
153
+ : "Digital delivery - Instant",
154
+ OrderTime: orderTime,
155
+ OrderItems: orderItems
156
+ }
157
+ };
158
+ }
159
+ /**
160
+ * Sends ecommerce order data to InfoRu API based on event type
161
+ */
162
+ function sendEcommerceOrder(params) {
163
+ var _a, _b, _c, _d;
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ try {
166
+ const { apiKey, eventType, data } = params;
167
+ if (!apiKey) {
168
+ throw new error_handler_1.CustomError("MISSING_API_KEY", 400, "API key is required");
169
+ }
170
+ if (!eventType || !Object.values(EcommerceEventType).includes(eventType)) {
171
+ throw new error_handler_1.CustomError("INVALID_EVENT_TYPE", 400, `Invalid event type. Must be one of: ${Object.values(EcommerceEventType).join(', ')}`);
172
+ }
173
+ if (!data || !data.customerEmail || !data.orderNumber) {
174
+ throw new error_handler_1.CustomError("MISSING_REQUIRED_DATA", 400, "Customer email and order number are required");
175
+ }
176
+ if (!data.products || data.products.length === 0) {
177
+ throw new error_handler_1.CustomError("NO_ORDER_ITEMS", 400, "Order must contain at least one product");
178
+ }
179
+ // Prepare the payload based on event type
180
+ const payload = prepareEcommercePayload(eventType, data);
181
+ // API endpoint for ecommerce
182
+ const apiUrl = "https://capi.inforu.co.il/api/v2/EcommerceApi";
183
+ // Send the request
184
+ const response = yield axios_1.default.post(apiUrl, payload, {
185
+ headers: {
186
+ "Authorization": apiKey,
187
+ "Content-Type": "application/json"
188
+ }
189
+ });
190
+ return {
191
+ success: true,
192
+ data: response.data,
193
+ orderNumber: data.orderNumber,
194
+ eventType
195
+ };
196
+ }
197
+ catch (error) {
198
+ logger_1.default.error("Failed to send ecommerce order", {
199
+ error: error instanceof Error ? error.message : error,
200
+ eventType: params.eventType,
201
+ orderNumber: (_a = params.data) === null || _a === void 0 ? void 0 : _a.orderNumber
202
+ });
203
+ if (axios_1.default.isAxiosError(error)) {
204
+ throw new error_handler_1.CustomError("ECOMMERCE_API_ERROR", ((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) || 500, `Failed to send ecommerce order: ${((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) || error.message}`);
205
+ }
206
+ throw new error_handler_1.CustomError("ECOMMERCE_ORDER_ERROR", 500, `Failed to process ecommerce order: ${error instanceof Error ? error.message : JSON.stringify(error)}`);
207
+ }
208
+ });
209
+ }
210
+ exports.sendEcommerceOrder = sendEcommerceOrder;
211
+ /**
212
+ * Helper function to determine if an event is an ecommerce event
213
+ */
214
+ function isEcommerceEvent(eventName) {
215
+ return Object.values(EcommerceEventType).includes(eventName);
216
+ }
217
+ exports.isEcommerceEvent = isEcommerceEvent;
218
+ /**
219
+ * Helper function to validate and parse ecommerce event type
220
+ */
221
+ function parseEcommerceEventType(eventName) {
222
+ if (Object.values(EcommerceEventType).includes(eventName)) {
223
+ return eventName;
224
+ }
225
+ return null;
226
+ }
227
+ exports.parseEcommerceEventType = parseEcommerceEventType;
228
+ // Backward compatibility aliases for book events
229
+ exports.BookPurchaseEventType = EcommerceEventType; // Type alias
230
+ exports.isBookPurchaseEvent = isEcommerceEvent;
231
+ exports.parseBookPurchaseEventType = parseEcommerceEventType;
232
+ //# sourceMappingURL=ecommerce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecommerce.js","sourceRoot":"","sources":["../src/ecommerce.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAAmD;AACnD,2DAAmC;AACnC,kDAA0B;AAoD1B,4BAA4B;AAC5B,IAAY,kBAUX;AAVD,WAAY,kBAAkB;IAC5B,kBAAkB;IAClB,yEAAmD,CAAA;IACnD,uEAAiD,CAAA;IACjD,qEAA+C,CAAA;IAC/C,uEAAiD,CAAA;IAEjD,wBAAwB;IACxB,iEAA2C,CAAA;IAC3C,uDAAiC,CAAA;AACnC,CAAC,EAVW,kBAAkB,kCAAlB,kBAAkB,QAU7B;AAED,qDAAqD;AACrD,MAAM,uBAAuB,GAAuC;IAClE,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,EAAE,yBAAyB;IACvE,CAAC,kBAAkB,CAAC,sBAAsB,CAAC,EAAE,yBAAyB;IACtE,CAAC,kBAAkB,CAAC,qBAAqB,CAAC,EAAE,yBAAyB;IACrE,CAAC,kBAAkB,CAAC,sBAAsB,CAAC,EAAE,yBAAyB;IACtE,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,gBAAgB;IAC1D,CAAC,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AAK,CAAC,OAAO,EAAE,CACpF,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,2BAAW,CACnB,uBAAuB,EACvB,GAAG,EACH,sCAAsC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CACvG,CAAC;QACJ,CAAC;;CACF;AAlED,gDAkEC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,SAAiB;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,SAA+B,CAAC,CAAC;AACrF,CAAC;AAFD,4CAEC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,SAAiB;IACvD,IAAI,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,SAA+B,CAAC,EAAE,CAAC;QAChF,OAAO,SAA+B,CAAC;IACzC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AALD,0DAKC;AAED,iDAAiD;AACpC,QAAA,qBAAqB,GAAG,kBAAkB,CAAC,CAAC,aAAa;AAEzD,QAAA,mBAAmB,GAAG,gBAAgB,CAAC;AACvC,QAAA,0BAA0B,GAAG,uBAAuB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export * from "./createGroup";
3
3
  export * from "./automations";
4
4
  export * from "./sendWA";
5
5
  export * from "./sendEmail";
6
+ export * from "./ecommerce";
package/dist/index.js CHANGED
@@ -20,4 +20,5 @@ __exportStar(require("./createGroup"), exports);
20
20
  __exportStar(require("./automations"), exports);
21
21
  __exportStar(require("./sendWA"), exports);
22
22
  __exportStar(require("./sendEmail"), exports);
23
+ __exportStar(require("./ecommerce"), exports);
23
24
  //# 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;AACzB,8CAA4B"}
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;AAC5B,8CAA4B"}
package/dist/normalize.js CHANGED
@@ -4,7 +4,7 @@ exports.prepareContactsPayload = void 0;
4
4
  const error_handler_1 = require("@nimee/error-handler");
5
5
  function normalizeBetweenEndUserToContacts(contacts, groupName) {
6
6
  return contacts.map((contact) => {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27;
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
8
8
  return {
9
9
  FirstName: contact.fname,
10
10
  LastName: contact.lname,
@@ -14,11 +14,11 @@ function normalizeBetweenEndUserToContacts(contacts, groupName) {
14
14
  ParticipationAtEventsCounter: contact.participationAtEventsCounter,
15
15
  AddToGroupName: groupName,
16
16
  ContactRefId: contact._id,
17
- OrderId: contact.Order_id,
17
+ Order_id: contact.Order_id,
18
18
  Status: contact.Status,
19
19
  Total: contact.Total,
20
20
  Currency: contact.Currency,
21
- PaymentMethod: contact.Payment_method,
21
+ Payment_method: contact.Payment_method,
22
22
  Product1Name: (_b = (_a = contact.Products) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.Name,
23
23
  Product1Price: (_d = (_c = contact.Products) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.Price,
24
24
  Product1Quantity: (_f = (_e = contact.Products) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.Quantity,
@@ -39,28 +39,6 @@ function normalizeBetweenEndUserToContacts(contacts, groupName) {
39
39
  UpdatedAt: contact.updatedAt,
40
40
  GettingKnowRadical: contact.GettingKnowRadical,
41
41
  ActionName: contact.actionName,
42
- EventName: contact.eventName,
43
- EventStartDate: contact.eventStartDate,
44
- EventStartHour: contact.eventStartHour,
45
- Ticket1Name: (_1 = (_0 = contact.tickets) === null || _0 === void 0 ? void 0 : _0[0]) === null || _1 === void 0 ? void 0 : _1.ticketName,
46
- Ticket1Quantity: (_3 = (_2 = contact.tickets) === null || _2 === void 0 ? void 0 : _2[0]) === null || _3 === void 0 ? void 0 : _3.quantity,
47
- Ticket2Name: (_5 = (_4 = contact.tickets) === null || _4 === void 0 ? void 0 : _4[1]) === null || _5 === void 0 ? void 0 : _5.ticketName,
48
- Ticket2Quantity: (_7 = (_6 = contact.tickets) === null || _6 === void 0 ? void 0 : _6[1]) === null || _7 === void 0 ? void 0 : _7.quantity,
49
- Ticket3Name: (_9 = (_8 = contact.tickets) === null || _8 === void 0 ? void 0 : _8[2]) === null || _9 === void 0 ? void 0 : _9.ticketName,
50
- Ticket3Quantity: (_11 = (_10 = contact.tickets) === null || _10 === void 0 ? void 0 : _10[2]) === null || _11 === void 0 ? void 0 : _11.quantity,
51
- Ticket4Name: (_13 = (_12 = contact.tickets) === null || _12 === void 0 ? void 0 : _12[3]) === null || _13 === void 0 ? void 0 : _13.ticketName,
52
- Ticket4Quantity: (_15 = (_14 = contact.tickets) === null || _14 === void 0 ? void 0 : _14[3]) === null || _15 === void 0 ? void 0 : _15.quantity,
53
- Ticket5Name: (_17 = (_16 = contact.tickets) === null || _16 === void 0 ? void 0 : _16[4]) === null || _17 === void 0 ? void 0 : _17.ticketName,
54
- Ticket5Quantity: (_19 = (_18 = contact.tickets) === null || _18 === void 0 ? void 0 : _18[4]) === null || _19 === void 0 ? void 0 : _19.quantity,
55
- Ticket6Name: (_21 = (_20 = contact.tickets) === null || _20 === void 0 ? void 0 : _20[5]) === null || _21 === void 0 ? void 0 : _21.ticketName,
56
- Ticket6Quantity: (_23 = (_22 = contact.tickets) === null || _22 === void 0 ? void 0 : _22[5]) === null || _23 === void 0 ? void 0 : _23.quantity,
57
- Ticket7Name: (_25 = (_24 = contact.tickets) === null || _24 === void 0 ? void 0 : _24[6]) === null || _25 === void 0 ? void 0 : _25.ticketName,
58
- Ticket7Quantity: (_27 = (_26 = contact.tickets) === null || _26 === void 0 ? void 0 : _26[6]) === null || _27 === void 0 ? void 0 : _27.quantity,
59
- SubscriptionName: contact.subscriptionName,
60
- SubscriptionPrice: contact.subscriptionPrice,
61
- OrderNumber: contact.orderNumber,
62
- TicketsAmount: contact.ticketsAmount,
63
- TicketsLink: contact.ticketsLink,
64
42
  };
65
43
  });
66
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":";;;AAAA,wDAAmD;AAGnD,SAAS,iCAAiC,CAAC,QAAyB,EAAE,SAAkB;IACtF,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;YAC3E,cAAc,EAAE,SAAS;YACzB,YAAY,EAAG,OAAe,CAAC,GAAG;YAClC,OAAO,EAAG,OAAe,CAAC,QAAQ;YAClC,MAAM,EAAG,OAAe,CAAC,MAAM;YAC/B,KAAK,EAAG,OAAe,CAAC,KAAK;YAC7B,QAAQ,EAAG,OAAe,CAAC,QAAQ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0CAAG,CAAC,CAAC,0CAAE,QAAQ;YAC1D,aAAa,EAAE,MAAA,MAAC,OAAe,CAAC,QAAQ,0CAAG,CAAC,CAAC,0CAAE,KAAK;YACpD,OAAO,EAAG,OAAe,CAAC,OAAO;YACjC,OAAO,EAAG,OAAe,CAAC,OAAO;YACjC,OAAO,EAAG,OAAe,CAAC,OAAO;YACjC,YAAY,EAAG,OAAe,CAAC,YAAY;YAC3C,SAAS,EAAG,OAAe,CAAC,SAAS;YACrC,SAAS,EAAG,OAAe,CAAC,SAAS;YACrC,kBAAkB,EAAG,OAAe,CAAC,kBAAkB;YACvD,UAAU,EAAG,OAAe,CAAC,UAAU;SACxC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAID,SAAgB,sBAAsB,CAAC,IAAqB,EAAE,SAAkB;IAC9E,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,EAAE,SAAS,CAAC,CAAC;IACrE,CAAC;SAAM,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QAC7B,OAAO,iCAAiC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,IAAI,2BAAW,CAAC,yCAAyC,EAAE,GAAG,EAAE,gBAAgB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChH,CAAC;AAPD,wDAOC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimee/inforu",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "inforu SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "author": "dan goldberg",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "types": "dist/index.d.ts",
29
29
  "dependencies": {
30
- "@nimee/error-handler": "^0.0.12",
30
+ "@nimee/error-handler": "0.0.14",
31
31
  "@nimee/logger": "^1.0.27",
32
32
  "axios": "1.2.1"
33
33
  }
@@ -2,13 +2,120 @@ import { CustomError, errorHandler } from "@nimee/error-handler";
2
2
  import { prepareContactsPayload } from "./normalize";
3
3
  import logger from "@nimee/logger";
4
4
  import axios from "axios";
5
+ import {
6
+ sendEcommerceOrder,
7
+ isEcommerceEvent,
8
+ parseEcommerceEventType,
9
+ IEcommercePurchaseData,
10
+ IOrderProduct
11
+ } from "./ecommerce";
12
+
13
+ /**
14
+ * Normalizes CRM event data to InfoRu ecommerce format
15
+ * Handles the transformation from the internal data structure to InfoRu's expected format
16
+ */
17
+ function normalizeEcommerceData(data: any, endUser?: any): IEcommercePurchaseData {
18
+ // The data structure from CRM service has endUser fields merged with the data object
19
+ // Extract customer info from data (which contains endUser fields + data fields)
20
+ const customerEmail = data.email || data.customerEmail || endUser?.email || "";
21
+ const customerFirstName = data.fname || data.customerFirstName || endUser?.fname || "";
22
+ const customerLastName = data.lname || data.customerLastName || endUser?.lname || "";
23
+
24
+ // Normalize order fields
25
+ const orderNumber = data.orderNumber || data.Order_id?.toString() || data.orderId?.toString() || "";
26
+ const orderAmount = data.orderAmount || data.Total || data.total || 0;
27
+ const orderStatus = data.orderStatus || data.Status || data.status || "processing";
28
+ const paymentMethod = data.paymentMethod || data.Payment_method || data.payment_method || "";
29
+
30
+ // Normalize products array
31
+ let products: IOrderProduct[] = [];
32
+
33
+ if (data.products && Array.isArray(data.products)) {
34
+ products = data.products;
35
+ } else if (data.Products && Array.isArray(data.Products)) {
36
+ // Transform from internal format to InfoRu format
37
+ products = data.Products.map((product: any) => ({
38
+ code: product.code || product.Code || product.SKU || product.Name || "",
39
+ name: product.name || product.Name || "",
40
+ price: parseFloat(product.price || product.Price || "0"),
41
+ quantity: parseInt(product.quantity || product.Quantity || "1", 10),
42
+ description: product.description || product.Description || "",
43
+ link: product.link || product.Link || "",
44
+ image: product.image || product.Image || "",
45
+ isbn: product.isbn || product.ISBN || "",
46
+ author: product.author || product.Author || "",
47
+ publisher: product.publisher || product.Publisher || "",
48
+ format: product.format || product.Format || "physical",
49
+ }));
50
+ }
51
+
52
+ return {
53
+ customerEmail,
54
+ customerFirstName,
55
+ customerLastName,
56
+ orderNumber,
57
+ orderAmount,
58
+ orderStatus,
59
+ billingAddress: data.billingAddress || data.Billing_address || "",
60
+ shippingAddress: data.shippingAddress || data.Shipping_address || "",
61
+ paymentMethod,
62
+ shippingMethod: data.shippingMethod || data.Shipping_method || "",
63
+ orderTime: data.orderTime || data.Order_time || new Date().toISOString(),
64
+ products,
65
+ storeName: data.storeName || data.Store_name || "",
66
+ storeUrl: data.storeUrl || data.Store_url || "",
67
+ ip: data.ip || data.IP || "",
68
+ contactRefId: data.contactRefId || data._id?.toString() || endUser?._id?.toString() || "",
69
+ };
70
+ }
71
+
5
72
  export async function triggerEventToStartAutomation(params: { apiKey: string; eventName: string; data: any }) {
6
73
  try {
7
74
  const { apiKey, eventName, data } = params;
8
75
  if (!apiKey || !eventName || !data) {
9
76
  throw new CustomError("Missing_API_KEY_TRIGGER_EVENT", 400, "Missing API key or event name or data");
10
77
  }
11
- const normalizeContact = prepareContactsPayload(data);
78
+
79
+ // Check if this is an ecommerce event (book purchases, VOD, tickets, abandoned carts)
80
+ if (isEcommerceEvent(eventName)) {
81
+ const ecommerceEventType = parseEcommerceEventType(eventName);
82
+ if (ecommerceEventType) {
83
+ // Handle ecommerce events differently
84
+ logger.info(`Processing ecommerce event: ${eventName}`);
85
+
86
+ // Normalize the data from CRM format to InfoRu format
87
+ const normalizedData = normalizeEcommerceData(data, data.endUser);
88
+
89
+ // Validate that normalized data has required fields
90
+ if (!normalizedData.customerEmail || !normalizedData.orderNumber || !normalizedData.products || normalizedData.products.length === 0) {
91
+ throw new CustomError(
92
+ "INVALID_ECOMMERCE_DATA",
93
+ 400,
94
+ `Ecommerce data must include customerEmail, orderNumber, and products array. Received: ${JSON.stringify({
95
+ customerEmail: normalizedData.customerEmail,
96
+ orderNumber: normalizedData.orderNumber,
97
+ productsCount: normalizedData.products?.length
98
+ })}`
99
+ );
100
+ }
101
+
102
+ logger.debug(`Normalized ecommerce data for event ${eventName}`, {
103
+ orderNumber: normalizedData.orderNumber,
104
+ customerEmail: normalizedData.customerEmail,
105
+ productsCount: normalizedData.products.length
106
+ });
107
+
108
+ // Send to ecommerce API
109
+ return await sendEcommerceOrder({
110
+ apiKey,
111
+ eventType: ecommerceEventType,
112
+ data: normalizedData
113
+ });
114
+ }
115
+ }
116
+
117
+ // Handle regular automation triggers
118
+ const normalizeContact = prepareContactsPayload({ endUser: data });
12
119
  const json = {
13
120
  Data: {
14
121
  ApiEventName: eventName,