@nimee/inforu 1.0.16 → 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.
- package/dist/automations.js +89 -1
- package/dist/automations.js.map +1 -1
- package/dist/ecommerce-example.d.ts +10 -0
- package/dist/ecommerce-example.js +246 -0
- package/dist/ecommerce-example.js.map +1 -0
- package/dist/ecommerce.d.ts +119 -0
- package/dist/ecommerce.js +232 -0
- package/dist/ecommerce.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/automations.ts +108 -1
- package/src/ecommerce-curl-examples.md +361 -0
- package/src/ecommerce.ts +346 -0
- package/src/index.ts +1 -0
package/dist/automations.js
CHANGED
|
@@ -17,14 +17,102 @@ const error_handler_1 = require("@nimee/error-handler");
|
|
|
17
17
|
const normalize_1 = require("./normalize");
|
|
18
18
|
const logger_1 = __importDefault(require("@nimee/logger"));
|
|
19
19
|
const axios_1 = __importDefault(require("axios"));
|
|
20
|
+
const ecommerce_1 = require("./ecommerce");
|
|
21
|
+
/**
|
|
22
|
+
* Normalizes CRM event data to InfoRu ecommerce format
|
|
23
|
+
* Handles the transformation from the internal data structure to InfoRu's expected format
|
|
24
|
+
*/
|
|
25
|
+
function normalizeEcommerceData(data, endUser) {
|
|
26
|
+
var _a, _b, _c, _d;
|
|
27
|
+
// The data structure from CRM service has endUser fields merged with the data object
|
|
28
|
+
// Extract customer info from data (which contains endUser fields + data fields)
|
|
29
|
+
const customerEmail = data.email || data.customerEmail || (endUser === null || endUser === void 0 ? void 0 : endUser.email) || "";
|
|
30
|
+
const customerFirstName = data.fname || data.customerFirstName || (endUser === null || endUser === void 0 ? void 0 : endUser.fname) || "";
|
|
31
|
+
const customerLastName = data.lname || data.customerLastName || (endUser === null || endUser === void 0 ? void 0 : endUser.lname) || "";
|
|
32
|
+
// Normalize order fields
|
|
33
|
+
const orderNumber = data.orderNumber || ((_a = data.Order_id) === null || _a === void 0 ? void 0 : _a.toString()) || ((_b = data.orderId) === null || _b === void 0 ? void 0 : _b.toString()) || "";
|
|
34
|
+
const orderAmount = data.orderAmount || data.Total || data.total || 0;
|
|
35
|
+
const orderStatus = data.orderStatus || data.Status || data.status || "processing";
|
|
36
|
+
const paymentMethod = data.paymentMethod || data.Payment_method || data.payment_method || "";
|
|
37
|
+
// Normalize products array
|
|
38
|
+
let products = [];
|
|
39
|
+
if (data.products && Array.isArray(data.products)) {
|
|
40
|
+
products = data.products;
|
|
41
|
+
}
|
|
42
|
+
else if (data.Products && Array.isArray(data.Products)) {
|
|
43
|
+
// Transform from internal format to InfoRu format
|
|
44
|
+
products = data.Products.map((product) => ({
|
|
45
|
+
code: product.code || product.Code || product.SKU || product.Name || "",
|
|
46
|
+
name: product.name || product.Name || "",
|
|
47
|
+
price: parseFloat(product.price || product.Price || "0"),
|
|
48
|
+
quantity: parseInt(product.quantity || product.Quantity || "1", 10),
|
|
49
|
+
description: product.description || product.Description || "",
|
|
50
|
+
link: product.link || product.Link || "",
|
|
51
|
+
image: product.image || product.Image || "",
|
|
52
|
+
isbn: product.isbn || product.ISBN || "",
|
|
53
|
+
author: product.author || product.Author || "",
|
|
54
|
+
publisher: product.publisher || product.Publisher || "",
|
|
55
|
+
format: product.format || product.Format || "physical",
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
customerEmail,
|
|
60
|
+
customerFirstName,
|
|
61
|
+
customerLastName,
|
|
62
|
+
orderNumber,
|
|
63
|
+
orderAmount,
|
|
64
|
+
orderStatus,
|
|
65
|
+
billingAddress: data.billingAddress || data.Billing_address || "",
|
|
66
|
+
shippingAddress: data.shippingAddress || data.Shipping_address || "",
|
|
67
|
+
paymentMethod,
|
|
68
|
+
shippingMethod: data.shippingMethod || data.Shipping_method || "",
|
|
69
|
+
orderTime: data.orderTime || data.Order_time || new Date().toISOString(),
|
|
70
|
+
products,
|
|
71
|
+
storeName: data.storeName || data.Store_name || "",
|
|
72
|
+
storeUrl: data.storeUrl || data.Store_url || "",
|
|
73
|
+
ip: data.ip || data.IP || "",
|
|
74
|
+
contactRefId: data.contactRefId || ((_c = data._id) === null || _c === void 0 ? void 0 : _c.toString()) || ((_d = endUser === null || endUser === void 0 ? void 0 : endUser._id) === null || _d === void 0 ? void 0 : _d.toString()) || "",
|
|
75
|
+
};
|
|
76
|
+
}
|
|
20
77
|
function triggerEventToStartAutomation(params) {
|
|
78
|
+
var _a;
|
|
21
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
80
|
try {
|
|
23
81
|
const { apiKey, eventName, data } = params;
|
|
24
82
|
if (!apiKey || !eventName || !data) {
|
|
25
83
|
throw new error_handler_1.CustomError("Missing_API_KEY_TRIGGER_EVENT", 400, "Missing API key or event name or data");
|
|
26
84
|
}
|
|
27
|
-
|
|
85
|
+
// Check if this is an ecommerce event (book purchases, VOD, tickets, abandoned carts)
|
|
86
|
+
if ((0, ecommerce_1.isEcommerceEvent)(eventName)) {
|
|
87
|
+
const ecommerceEventType = (0, ecommerce_1.parseEcommerceEventType)(eventName);
|
|
88
|
+
if (ecommerceEventType) {
|
|
89
|
+
// Handle ecommerce events differently
|
|
90
|
+
logger_1.default.info(`Processing ecommerce event: ${eventName}`);
|
|
91
|
+
// Normalize the data from CRM format to InfoRu format
|
|
92
|
+
const normalizedData = normalizeEcommerceData(data, data.endUser);
|
|
93
|
+
// Validate that normalized data has required fields
|
|
94
|
+
if (!normalizedData.customerEmail || !normalizedData.orderNumber || !normalizedData.products || normalizedData.products.length === 0) {
|
|
95
|
+
throw new error_handler_1.CustomError("INVALID_ECOMMERCE_DATA", 400, `Ecommerce data must include customerEmail, orderNumber, and products array. Received: ${JSON.stringify({
|
|
96
|
+
customerEmail: normalizedData.customerEmail,
|
|
97
|
+
orderNumber: normalizedData.orderNumber,
|
|
98
|
+
productsCount: (_a = normalizedData.products) === null || _a === void 0 ? void 0 : _a.length
|
|
99
|
+
})}`);
|
|
100
|
+
}
|
|
101
|
+
logger_1.default.debug(`Normalized ecommerce data for event ${eventName}`, {
|
|
102
|
+
orderNumber: normalizedData.orderNumber,
|
|
103
|
+
customerEmail: normalizedData.customerEmail,
|
|
104
|
+
productsCount: normalizedData.products.length
|
|
105
|
+
});
|
|
106
|
+
// Send to ecommerce API
|
|
107
|
+
return yield (0, ecommerce_1.sendEcommerceOrder)({
|
|
108
|
+
apiKey,
|
|
109
|
+
eventType: ecommerceEventType,
|
|
110
|
+
data: normalizedData
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Handle regular automation triggers
|
|
115
|
+
const normalizeContact = (0, normalize_1.prepareContactsPayload)({ endUser: data });
|
|
28
116
|
const json = {
|
|
29
117
|
Data: {
|
|
30
118
|
ApiEventName: eventName,
|
package/dist/automations.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automations.js","sourceRoot":"","sources":["../src/automations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAAiE;AACjE,2CAAqD;AACrD,2DAAmC;AACnC,kDAA0B;AAC1B,SAAsB,6BAA6B,CAAC,MAAwD
|
|
1
|
+
{"version":3,"file":"automations.js","sourceRoot":"","sources":["../src/automations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAAiE;AACjE,2CAAqD;AACrD,2DAAmC;AACnC,kDAA0B;AAC1B,2CAMqB;AAErB;;;GAGG;AACH,SAAS,sBAAsB,CAAC,IAAS,EAAE,OAAa;;IACtD,qFAAqF;IACrF,gFAAgF;IAChF,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,aAAa,KAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAA,IAAI,EAAE,CAAC;IAC/E,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,iBAAiB,KAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CA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AC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,2BAAW,CAAC,8BAA8B,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACpF,CAAC;;CACF;AAhED,sEAgEC;AACD,gBAAgB;AAChB,IAAI;AACJ,YAAY;AACZ,wBAAwB;AACxB,qBAAqB;AACrB,KAAK;AACL,YAAY;AACZ,sCAAsC;AACtC,iBAAiB;AACjB,wBAAwB;AACxB,sBAAsB;AACtB,kCAAkC;AAClC,8BAA8B;AAC9B,KAAK;AACL,IAAI;AACJ,qCAAqC;AACrC,KAAK;AACL,IAAI;AACJ,IAAI"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example usage of the InfoRu Ecommerce API integration
|
|
3
|
+
*
|
|
4
|
+
* This shows how to send different types of book purchase events
|
|
5
|
+
*/
|
|
6
|
+
declare function sendPhysicalBookPurchase(): Promise<void>;
|
|
7
|
+
declare function sendDigitalBookPurchase(): Promise<void>;
|
|
8
|
+
declare function sendMixedBookPurchase(): Promise<void>;
|
|
9
|
+
declare function sendRegularAutomationEvent(): Promise<void>;
|
|
10
|
+
export { sendPhysicalBookPurchase, sendDigitalBookPurchase, sendMixedBookPurchase, sendRegularAutomationEvent };
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example usage of the InfoRu Ecommerce API integration
|
|
4
|
+
*
|
|
5
|
+
* This shows how to send different types of book purchase events
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.sendRegularAutomationEvent = exports.sendMixedBookPurchase = exports.sendDigitalBookPurchase = exports.sendPhysicalBookPurchase = void 0;
|
|
18
|
+
const automations_1 = require("./automations");
|
|
19
|
+
const ecommerce_1 = require("./ecommerce");
|
|
20
|
+
// Example 1: Physical Book Purchase
|
|
21
|
+
function sendPhysicalBookPurchase() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const physicalBookData = {
|
|
24
|
+
customerEmail: "john.doe@example.com",
|
|
25
|
+
customerFirstName: "John",
|
|
26
|
+
customerLastName: "Doe",
|
|
27
|
+
orderNumber: "ORD-2024-001234",
|
|
28
|
+
orderAmount: 159.90,
|
|
29
|
+
orderStatus: "processing",
|
|
30
|
+
billingAddress: "123 Main Street, Tel Aviv, Israel",
|
|
31
|
+
shippingAddress: "123 Main Street, Tel Aviv, Israel",
|
|
32
|
+
paymentMethod: "credit card",
|
|
33
|
+
shippingMethod: "Standard shipping - 3-5 business days",
|
|
34
|
+
orderTime: new Date("2024-01-15T10:30:00"),
|
|
35
|
+
books: [
|
|
36
|
+
{
|
|
37
|
+
code: "ISBN-978-0-123456-78-9",
|
|
38
|
+
name: "Advanced TypeScript Programming",
|
|
39
|
+
price: 79.95,
|
|
40
|
+
quantity: 1,
|
|
41
|
+
description: "A comprehensive guide to TypeScript",
|
|
42
|
+
link: "https://bookstore.example.com/books/advanced-typescript",
|
|
43
|
+
image: "https://bookstore.example.com/images/advanced-typescript.jpg",
|
|
44
|
+
isbn: "978-0-123456-78-9",
|
|
45
|
+
author: "Jane Smith",
|
|
46
|
+
publisher: "Tech Publications",
|
|
47
|
+
format: "physical"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
code: "ISBN-978-0-987654-32-1",
|
|
51
|
+
name: "Node.js Best Practices",
|
|
52
|
+
price: 79.95,
|
|
53
|
+
quantity: 1,
|
|
54
|
+
description: "Production-ready Node.js patterns",
|
|
55
|
+
link: "https://bookstore.example.com/books/nodejs-best-practices",
|
|
56
|
+
image: "https://bookstore.example.com/images/nodejs-best-practices.jpg",
|
|
57
|
+
isbn: "978-0-987654-32-1",
|
|
58
|
+
author: "Michael Johnson",
|
|
59
|
+
publisher: "Dev Books Inc.",
|
|
60
|
+
format: "physical"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
storeName: "TechBooks Online",
|
|
64
|
+
storeUrl: "https://techbooks.example.com",
|
|
65
|
+
ip: "192.168.1.100",
|
|
66
|
+
contactRefId: "USR-456789"
|
|
67
|
+
};
|
|
68
|
+
try {
|
|
69
|
+
const result = yield (0, automations_1.triggerEventToStartAutomation)({
|
|
70
|
+
apiKey: "YOUR_API_KEY_HERE",
|
|
71
|
+
eventName: ecommerce_1.BookPurchaseEventType.PURCHASED_PHYSICAL_BOOK,
|
|
72
|
+
data: physicalBookData
|
|
73
|
+
});
|
|
74
|
+
console.log("Physical book purchase sent successfully:", result);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error("Failed to send physical book purchase:", error);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.sendPhysicalBookPurchase = sendPhysicalBookPurchase;
|
|
82
|
+
// Example 2: Digital Book Purchase
|
|
83
|
+
function sendDigitalBookPurchase() {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const digitalBookData = {
|
|
86
|
+
customerEmail: "jane.smith@example.com",
|
|
87
|
+
customerFirstName: "Jane",
|
|
88
|
+
customerLastName: "Smith",
|
|
89
|
+
orderNumber: "ORD-2024-001235",
|
|
90
|
+
orderAmount: 49.99,
|
|
91
|
+
orderStatus: "completed", // Digital orders are typically completed immediately
|
|
92
|
+
billingAddress: "456 Digital Avenue, Herzliya, Israel",
|
|
93
|
+
// No shipping address needed for digital books
|
|
94
|
+
paymentMethod: "PayPal",
|
|
95
|
+
shippingMethod: "Digital delivery - Instant",
|
|
96
|
+
orderTime: new Date(),
|
|
97
|
+
books: [
|
|
98
|
+
{
|
|
99
|
+
code: "EBOOK-001",
|
|
100
|
+
name: "Cloud Architecture Patterns (Digital Edition)",
|
|
101
|
+
price: 49.99,
|
|
102
|
+
quantity: 1,
|
|
103
|
+
description: "Digital book on cloud architecture patterns",
|
|
104
|
+
link: "https://bookstore.example.com/ebooks/cloud-architecture",
|
|
105
|
+
image: "https://bookstore.example.com/images/cloud-architecture-ebook.jpg",
|
|
106
|
+
isbn: "978-0-111111-11-1",
|
|
107
|
+
author: "Sarah Williams",
|
|
108
|
+
publisher: "Cloud Press Digital",
|
|
109
|
+
format: "digital",
|
|
110
|
+
downloadLink: "https://downloads.example.com/ebooks/cloud-architecture.pdf"
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
storeName: "Digital Library Store",
|
|
114
|
+
storeUrl: "https://digitalbooks.example.com",
|
|
115
|
+
ip: "10.0.0.50",
|
|
116
|
+
contactRefId: "USR-789012"
|
|
117
|
+
};
|
|
118
|
+
try {
|
|
119
|
+
const result = yield (0, automations_1.triggerEventToStartAutomation)({
|
|
120
|
+
apiKey: "YOUR_API_KEY_HERE",
|
|
121
|
+
eventName: ecommerce_1.BookPurchaseEventType.PURCHASED_DIGITAL_BOOK,
|
|
122
|
+
data: digitalBookData
|
|
123
|
+
});
|
|
124
|
+
console.log("Digital book purchase sent successfully:", result);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error("Failed to send digital book purchase:", error);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
exports.sendDigitalBookPurchase = sendDigitalBookPurchase;
|
|
132
|
+
// Example 3: Mixed Order (both physical and digital books)
|
|
133
|
+
function sendMixedBookPurchase() {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const mixedBookData = {
|
|
136
|
+
customerEmail: "book.lover@example.com",
|
|
137
|
+
customerFirstName: "Book",
|
|
138
|
+
customerLastName: "Lover",
|
|
139
|
+
orderNumber: "ORD-2024-001236",
|
|
140
|
+
orderAmount: 189.85,
|
|
141
|
+
orderStatus: "processing",
|
|
142
|
+
billingAddress: "789 Reading Lane, Ramat Gan, Israel",
|
|
143
|
+
shippingAddress: "789 Reading Lane, Ramat Gan, Israel", // For physical items
|
|
144
|
+
paymentMethod: "Visa Credit Card",
|
|
145
|
+
shippingMethod: "Express shipping - 1-2 business days",
|
|
146
|
+
orderTime: new Date("2024-01-16T14:30:00"),
|
|
147
|
+
books: [
|
|
148
|
+
{
|
|
149
|
+
code: "ISBN-978-0-222222-22-2",
|
|
150
|
+
name: "JavaScript: The Definitive Guide",
|
|
151
|
+
price: 89.95,
|
|
152
|
+
quantity: 1,
|
|
153
|
+
description: "The comprehensive guide to JavaScript",
|
|
154
|
+
link: "https://bookstore.example.com/books/js-definitive",
|
|
155
|
+
image: "https://bookstore.example.com/images/js-definitive.jpg",
|
|
156
|
+
isbn: "978-0-222222-22-2",
|
|
157
|
+
author: "David Flanagan",
|
|
158
|
+
publisher: "O'Reilly Media",
|
|
159
|
+
format: "physical"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
code: "EBOOK-002",
|
|
163
|
+
name: "React Hooks in Action (Digital)",
|
|
164
|
+
price: 39.95,
|
|
165
|
+
quantity: 1,
|
|
166
|
+
description: "Master React Hooks with practical examples",
|
|
167
|
+
link: "https://bookstore.example.com/ebooks/react-hooks",
|
|
168
|
+
image: "https://bookstore.example.com/images/react-hooks-ebook.jpg",
|
|
169
|
+
isbn: "978-0-333333-33-3",
|
|
170
|
+
author: "John Larsen",
|
|
171
|
+
publisher: "Manning Digital",
|
|
172
|
+
format: "digital",
|
|
173
|
+
downloadLink: "https://downloads.example.com/ebooks/react-hooks.epub"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
code: "ISBN-978-0-444444-44-4",
|
|
177
|
+
name: "Python for Data Science",
|
|
178
|
+
price: 59.95,
|
|
179
|
+
quantity: 1,
|
|
180
|
+
description: "Complete guide to Python for data science",
|
|
181
|
+
link: "https://bookstore.example.com/books/python-data-science",
|
|
182
|
+
image: "https://bookstore.example.com/images/python-data-science.jpg",
|
|
183
|
+
isbn: "978-0-444444-44-4",
|
|
184
|
+
author: "Jake VanderPlas",
|
|
185
|
+
publisher: "Data Science Press",
|
|
186
|
+
format: "physical"
|
|
187
|
+
}
|
|
188
|
+
],
|
|
189
|
+
storeName: "Complete Tech Bookstore",
|
|
190
|
+
storeUrl: "https://completetechbooks.example.com"
|
|
191
|
+
};
|
|
192
|
+
try {
|
|
193
|
+
// For mixed orders, you might want to send two separate events
|
|
194
|
+
// One for physical books
|
|
195
|
+
const physicalBooks = mixedBookData.books.filter(book => book.format === "physical");
|
|
196
|
+
if (physicalBooks.length > 0) {
|
|
197
|
+
yield (0, automations_1.triggerEventToStartAutomation)({
|
|
198
|
+
apiKey: "YOUR_API_KEY_HERE",
|
|
199
|
+
eventName: ecommerce_1.BookPurchaseEventType.PURCHASED_PHYSICAL_BOOK,
|
|
200
|
+
data: Object.assign(Object.assign({}, mixedBookData), { books: physicalBooks, orderAmount: physicalBooks.reduce((sum, book) => sum + (book.price * book.quantity), 0) })
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// One for digital books
|
|
204
|
+
const digitalBooks = mixedBookData.books.filter(book => book.format === "digital");
|
|
205
|
+
if (digitalBooks.length > 0) {
|
|
206
|
+
yield (0, automations_1.triggerEventToStartAutomation)({
|
|
207
|
+
apiKey: "YOUR_API_KEY_HERE",
|
|
208
|
+
eventName: ecommerce_1.BookPurchaseEventType.PURCHASED_DIGITAL_BOOK,
|
|
209
|
+
data: Object.assign(Object.assign({}, mixedBookData), { books: digitalBooks, orderAmount: digitalBooks.reduce((sum, book) => sum + (book.price * book.quantity), 0), shippingAddress: undefined, shippingMethod: "Digital delivery - Instant" })
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
console.log("Mixed book purchase sent successfully");
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
console.error("Failed to send mixed book purchase:", error);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
exports.sendMixedBookPurchase = sendMixedBookPurchase;
|
|
220
|
+
// Example 4: Regular automation event (non-ecommerce)
|
|
221
|
+
function sendRegularAutomationEvent() {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
// This will use the original automation trigger logic
|
|
224
|
+
const regularEventData = {
|
|
225
|
+
endUser: {
|
|
226
|
+
fname: "Test",
|
|
227
|
+
lname: "User",
|
|
228
|
+
email: "test@example.com",
|
|
229
|
+
phone: "0501234567"
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
try {
|
|
233
|
+
const result = yield (0, automations_1.triggerEventToStartAutomation)({
|
|
234
|
+
apiKey: "YOUR_API_KEY_HERE",
|
|
235
|
+
eventName: "UserRegistration", // Not a book purchase event
|
|
236
|
+
data: regularEventData
|
|
237
|
+
});
|
|
238
|
+
console.log("Regular automation event sent successfully:", result);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
console.error("Failed to send regular automation event:", error);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
exports.sendRegularAutomationEvent = sendRegularAutomationEvent;
|
|
246
|
+
//# sourceMappingURL=ecommerce-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecommerce-example.js","sourceRoot":"","sources":["../src/ecommerce-example.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;AAEH,+CAA8D;AAC9D,2CAAuE;AAEvE,oCAAoC;AACpC,SAAe,wBAAwB;;QACrC,MAAM,gBAAgB,G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@ -0,0 +1,119 @@
|
|
|
1
|
+
export interface IProductAttribute {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}
|
|
5
|
+
export interface IOrderItem {
|
|
6
|
+
ProductCode: string;
|
|
7
|
+
ProductName: string;
|
|
8
|
+
ProductPrice: number;
|
|
9
|
+
ProductQty: number;
|
|
10
|
+
ProductDescription?: string | null;
|
|
11
|
+
ProductLink?: string;
|
|
12
|
+
ProductImage?: string;
|
|
13
|
+
Custom1?: string;
|
|
14
|
+
Custom2?: string;
|
|
15
|
+
Custom3?: string;
|
|
16
|
+
Custom4?: string;
|
|
17
|
+
Custom5?: string;
|
|
18
|
+
ProductAttributes?: IProductAttribute[];
|
|
19
|
+
}
|
|
20
|
+
export interface IEcommerceOrderData {
|
|
21
|
+
Event: string;
|
|
22
|
+
Category?: string;
|
|
23
|
+
StoreName: string;
|
|
24
|
+
StoreBaseUrl: string;
|
|
25
|
+
LinkToCart?: string;
|
|
26
|
+
IP?: string;
|
|
27
|
+
CustomerEmail: string;
|
|
28
|
+
CustomerFirstName: string;
|
|
29
|
+
CustomerLastName: string;
|
|
30
|
+
ContactRefId?: string;
|
|
31
|
+
SubscriberStatus?: string;
|
|
32
|
+
AddToGroupName?: string[];
|
|
33
|
+
OrderNumber: string;
|
|
34
|
+
OrderAmount: string | number;
|
|
35
|
+
OrderStatus: string;
|
|
36
|
+
BillingAddress?: string;
|
|
37
|
+
ShippingAddress?: string;
|
|
38
|
+
PaymentDescription?: string;
|
|
39
|
+
ShippingDescription?: string;
|
|
40
|
+
OrderTime: string;
|
|
41
|
+
OrderItems: IOrderItem[];
|
|
42
|
+
}
|
|
43
|
+
export interface IEcommercePayload {
|
|
44
|
+
Data: IEcommerceOrderData;
|
|
45
|
+
}
|
|
46
|
+
export declare enum EcommerceEventType {
|
|
47
|
+
PURCHASED_PHYSICAL_BOOK = "PURCHASED_PHYSICAL_BOOK",
|
|
48
|
+
PURCHASED_DIGITAL_BOOK = "PURCHASED_DIGITAL_BOOK",
|
|
49
|
+
PURCHASED_VOD_PRODUCT = "PURCHASED_VOD_PRODUCT",
|
|
50
|
+
PURCHASED_EVENT_TICKET = "PURCHASED_EVENT_TICKET",
|
|
51
|
+
ABANDONED_CART_BOOK = "ABANDONED_CART_BOOK",
|
|
52
|
+
ABANDONED_CART = "ABANDONED_CART"
|
|
53
|
+
}
|
|
54
|
+
export interface IOrderProduct {
|
|
55
|
+
code: string;
|
|
56
|
+
name: string;
|
|
57
|
+
price: number;
|
|
58
|
+
quantity: number;
|
|
59
|
+
description?: string;
|
|
60
|
+
link?: string;
|
|
61
|
+
image?: string;
|
|
62
|
+
isbn?: string;
|
|
63
|
+
author?: string;
|
|
64
|
+
publisher?: string;
|
|
65
|
+
format?: string;
|
|
66
|
+
downloadLink?: string;
|
|
67
|
+
eventDate?: string | Date;
|
|
68
|
+
eventLocation?: string;
|
|
69
|
+
seatNumber?: string;
|
|
70
|
+
vodDuration?: string;
|
|
71
|
+
vodExpiry?: string | Date;
|
|
72
|
+
vodStreamUrl?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface IEcommercePurchaseData {
|
|
75
|
+
customerEmail: string;
|
|
76
|
+
customerFirstName: string;
|
|
77
|
+
customerLastName: string;
|
|
78
|
+
orderNumber: string;
|
|
79
|
+
orderAmount: number | string;
|
|
80
|
+
orderStatus?: string;
|
|
81
|
+
billingAddress?: string;
|
|
82
|
+
shippingAddress?: string;
|
|
83
|
+
paymentMethod?: string;
|
|
84
|
+
shippingMethod?: string;
|
|
85
|
+
orderTime?: string | Date;
|
|
86
|
+
products: IOrderProduct[];
|
|
87
|
+
storeName?: string;
|
|
88
|
+
storeUrl?: string;
|
|
89
|
+
ip?: string;
|
|
90
|
+
contactRefId?: string;
|
|
91
|
+
cartUrl?: string;
|
|
92
|
+
abandonedAt?: string | Date;
|
|
93
|
+
reminderCount?: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Sends ecommerce order data to InfoRu API based on event type
|
|
97
|
+
*/
|
|
98
|
+
export declare function sendEcommerceOrder(params: {
|
|
99
|
+
apiKey: string;
|
|
100
|
+
eventType: EcommerceEventType;
|
|
101
|
+
data: IEcommercePurchaseData;
|
|
102
|
+
}): Promise<{
|
|
103
|
+
success: boolean;
|
|
104
|
+
data: any;
|
|
105
|
+
orderNumber: string;
|
|
106
|
+
eventType: EcommerceEventType;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Helper function to determine if an event is an ecommerce event
|
|
110
|
+
*/
|
|
111
|
+
export declare function isEcommerceEvent(eventName: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Helper function to validate and parse ecommerce event type
|
|
114
|
+
*/
|
|
115
|
+
export declare function parseEcommerceEventType(eventName: string): EcommerceEventType | null;
|
|
116
|
+
export declare const BookPurchaseEventType: typeof EcommerceEventType;
|
|
117
|
+
export type IBookPurchaseData = IEcommercePurchaseData;
|
|
118
|
+
export declare const isBookPurchaseEvent: typeof isEcommerceEvent;
|
|
119
|
+
export declare const parseBookPurchaseEventType: typeof parseEcommerceEventType;
|