@winible/winible-typed 2.66.1 → 2.66.3
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/utils/campaignUtils.js +1 -10
- package/dist/utils/campaignUtils.js.map +1 -1
- package/package.json +2 -1
- package/utils/campaignUtils.ts +131 -0
- package/utils/index.ts +1 -0
@@ -1,6 +1,5 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.buildEmailQueueInput = exports.buildSmsQueueInput = void 0;
|
4
3
|
const CLIENT_URL = process.env.CLIENT_URL;
|
5
4
|
const VARIABLE_MAP = {
|
6
5
|
FIRST_NAME: "{FIRST_NAME}",
|
@@ -36,9 +35,6 @@ const buildReplacements = (contact, campaignMessage) => {
|
|
36
35
|
}
|
37
36
|
return replacements;
|
38
37
|
};
|
39
|
-
/**
|
40
|
-
* Builds a single SMS queue input object.
|
41
|
-
*/
|
42
38
|
const buildSmsQueueInput = (senderId, contact, campaignMessage, scheduleSendTime // Optional: Used for absolute/relative timing
|
43
39
|
) => {
|
44
40
|
const replacements = buildReplacements(contact, campaignMessage);
|
@@ -57,10 +53,6 @@ const buildSmsQueueInput = (senderId, contact, campaignMessage, scheduleSendTime
|
|
57
53
|
configuration: configuration,
|
58
54
|
};
|
59
55
|
};
|
60
|
-
exports.buildSmsQueueInput = buildSmsQueueInput;
|
61
|
-
/**
|
62
|
-
* Builds a single Email queue input object.
|
63
|
-
*/
|
64
56
|
const buildEmailQueueInput = (senderId, contact, campaignMessage, scheduleSendTime // Optional: Used for absolute/relative timing
|
65
57
|
) => {
|
66
58
|
const replacements = buildReplacements(contact, campaignMessage);
|
@@ -79,6 +71,5 @@ const buildEmailQueueInput = (senderId, contact, campaignMessage, scheduleSendTi
|
|
79
71
|
configuration: configuration,
|
80
72
|
};
|
81
73
|
};
|
82
|
-
exports.
|
83
|
-
exports.default = { buildReplacements };
|
74
|
+
exports.default = { buildReplacements, buildEmailQueueInput, buildSmsQueueInput };
|
84
75
|
//# sourceMappingURL=campaignUtils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"campaignUtils.js","sourceRoot":"","sources":["../../utils/campaignUtils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"campaignUtils.js","sourceRoot":"","sources":["../../utils/campaignUtils.ts"],"names":[],"mappings":";;AAyBA,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;AAE1C,MAAM,YAAY,GAAG;IACnB,UAAU,EAAE,cAAc;IAC1B,YAAY,EAAE,gBAAgB;IAC9B,SAAS,EAAE,aAAa;IACxB,aAAa,EAAE,iBAAiB;IAChC,gBAAgB,EAAE,oBAAoB;CACvC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,OAAa,EAAE,eAAgC,EAAE,EAAE;IAC5E,IAAI,YAAY,GAA2B,EAAE,CAAC;IAE9C,MAAM,OAAO,GAAG,CAAC,eAAe,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACxE,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,IAAI,EAAE,CAAC;IAC9C,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,IAAI,EAAE,CAAC;IAChD,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,IAAI,EAAE,CAAC;IAEnD,IACE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC;QACzC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC,EACzC;QACA,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;KACjE;IAED,IACE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC;QAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,EAC3C;QACA,MAAM,WAAW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C3B,QAAgB,EAChB,OAAa,EACb,eAAgC,EAChC,gBAA8B,CAAC,8CAA8C;EACxD,EAAE;IACvB,MAAM,YAAY,GAAG,iBAAiB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IACjE,MAAM,aAAa,GAAkD;QACnE,YAAY;KACb,CAAC;IAEF,IAAI,gBAAgB,EAAE;QACpB,aAAa,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;KACnD;IAED,OAAO;QACL,UAAU,EAAE,eAAe,CAAC,UAAU;QACtC,iBAAiB,EAAE,eAAe,CAAC,EAAE;QACrC,QAAQ;QACR,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,YAAY,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;QACjC,aAAa,EAAE,aAAqD;KACrE,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@winible/winible-typed",
|
3
|
-
"version": "2.66.
|
3
|
+
"version": "2.66.3",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "./dist/index.d.ts",
|
@@ -78,6 +78,7 @@
|
|
78
78
|
"files": [
|
79
79
|
"typed-model/**/*",
|
80
80
|
"event-collector-models/**/*",
|
81
|
+
"utils/**/*",
|
81
82
|
"support/**/*",
|
82
83
|
"src/**/*",
|
83
84
|
"index.ts",
|
@@ -0,0 +1,131 @@
|
|
1
|
+
import { CampaignMessage, User } from "../typed-model";
|
2
|
+
|
3
|
+
type CampaignMessageConfiguration = {
|
4
|
+
scheduleSendTime?: Date | null;
|
5
|
+
replacements?: Record<string, string>;
|
6
|
+
};
|
7
|
+
|
8
|
+
type EmailSendQueueInput = {
|
9
|
+
campaignId: number;
|
10
|
+
campaignMessageId: number;
|
11
|
+
senderId: string;
|
12
|
+
contactId: string;
|
13
|
+
contactEmail: string;
|
14
|
+
configuration: CampaignMessageConfiguration;
|
15
|
+
};
|
16
|
+
|
17
|
+
type SmsSendQueueInput = {
|
18
|
+
campaignId: number;
|
19
|
+
campaignMessageId: number;
|
20
|
+
senderId: string;
|
21
|
+
contactId: string;
|
22
|
+
contactPhoneNumber: string;
|
23
|
+
configuration: CampaignMessageConfiguration;
|
24
|
+
};
|
25
|
+
|
26
|
+
const CLIENT_URL = process.env.CLIENT_URL;
|
27
|
+
|
28
|
+
const VARIABLE_MAP = {
|
29
|
+
FIRST_NAME: "{FIRST_NAME}",
|
30
|
+
CHECKOUT_URL: "{CHECKOUT_URL}",
|
31
|
+
PLAN_NAME: "{PLAN_NAME}",
|
32
|
+
FOR_PROMOTION: "{FOR_PROMOTION}",
|
33
|
+
JOINED_PLAN_NAME: "{JOINED_PLAN_NAME}",
|
34
|
+
};
|
35
|
+
|
36
|
+
const buildReplacements = (contact: User, campaignMessage: CampaignMessage) => {
|
37
|
+
let replacements: Record<string, string> = {};
|
38
|
+
|
39
|
+
const subject = (campaignMessage.subject || "").replace(/<[^>]*>/g, "");
|
40
|
+
const content = campaignMessage.content || "";
|
41
|
+
const metadata = campaignMessage.metadata || {};
|
42
|
+
const dynamicFields = metadata.dynamicFields || {};
|
43
|
+
|
44
|
+
if (
|
45
|
+
subject.includes(VARIABLE_MAP.FIRST_NAME) ||
|
46
|
+
content.includes(VARIABLE_MAP.FIRST_NAME)
|
47
|
+
) {
|
48
|
+
replacements[VARIABLE_MAP.FIRST_NAME] = contact.firstName || "";
|
49
|
+
}
|
50
|
+
|
51
|
+
if (
|
52
|
+
subject.includes(VARIABLE_MAP.CHECKOUT_URL) ||
|
53
|
+
content.includes(VARIABLE_MAP.CHECKOUT_URL)
|
54
|
+
) {
|
55
|
+
const checkoutUrl = dynamicFields.checkoutUrl || `${CLIENT_URL}/404`;
|
56
|
+
|
57
|
+
replacements[VARIABLE_MAP.CHECKOUT_URL] = checkoutUrl;
|
58
|
+
}
|
59
|
+
|
60
|
+
if (
|
61
|
+
subject.includes(VARIABLE_MAP.PLAN_NAME) ||
|
62
|
+
content.includes(VARIABLE_MAP.PLAN_NAME)
|
63
|
+
) {
|
64
|
+
const planName = dynamicFields.planName || "";
|
65
|
+
|
66
|
+
replacements[VARIABLE_MAP.PLAN_NAME] = planName;
|
67
|
+
}
|
68
|
+
|
69
|
+
if (
|
70
|
+
subject.includes(VARIABLE_MAP.FOR_PROMOTION) ||
|
71
|
+
content.includes(VARIABLE_MAP.FOR_PROMOTION)
|
72
|
+
) {
|
73
|
+
const promotion = dynamicFields.promotion || "";
|
74
|
+
|
75
|
+
replacements[VARIABLE_MAP.FOR_PROMOTION] = promotion;
|
76
|
+
}
|
77
|
+
|
78
|
+
return replacements;
|
79
|
+
};
|
80
|
+
|
81
|
+
const buildSmsQueueInput = (
|
82
|
+
senderId: string,
|
83
|
+
contact: User,
|
84
|
+
campaignMessage: CampaignMessage,
|
85
|
+
scheduleSendTime?: Date | null // Optional: Used for absolute/relative timing
|
86
|
+
): SmsSendQueueInput => {
|
87
|
+
const replacements = buildReplacements(contact, campaignMessage);
|
88
|
+
const configuration: Partial<SmsSendQueueInput["configuration"]> = {
|
89
|
+
replacements,
|
90
|
+
};
|
91
|
+
|
92
|
+
if (scheduleSendTime) {
|
93
|
+
configuration.scheduleSendTime = scheduleSendTime;
|
94
|
+
}
|
95
|
+
|
96
|
+
return {
|
97
|
+
campaignId: campaignMessage.campaignId,
|
98
|
+
campaignMessageId: campaignMessage.id,
|
99
|
+
senderId,
|
100
|
+
contactId: contact.id,
|
101
|
+
contactPhoneNumber: contact.phoneNumber || "",
|
102
|
+
configuration: configuration as SmsSendQueueInput["configuration"],
|
103
|
+
};
|
104
|
+
};
|
105
|
+
|
106
|
+
const buildEmailQueueInput = (
|
107
|
+
senderId: string,
|
108
|
+
contact: User,
|
109
|
+
campaignMessage: CampaignMessage,
|
110
|
+
scheduleSendTime?: Date | null // Optional: Used for absolute/relative timing
|
111
|
+
): EmailSendQueueInput => {
|
112
|
+
const replacements = buildReplacements(contact, campaignMessage);
|
113
|
+
const configuration: Partial<EmailSendQueueInput["configuration"]> = {
|
114
|
+
replacements,
|
115
|
+
};
|
116
|
+
|
117
|
+
if (scheduleSendTime) {
|
118
|
+
configuration.scheduleSendTime = scheduleSendTime;
|
119
|
+
}
|
120
|
+
|
121
|
+
return {
|
122
|
+
campaignId: campaignMessage.campaignId,
|
123
|
+
campaignMessageId: campaignMessage.id,
|
124
|
+
senderId,
|
125
|
+
contactId: contact.id,
|
126
|
+
contactEmail: contact.email || "",
|
127
|
+
configuration: configuration as EmailSendQueueInput["configuration"],
|
128
|
+
};
|
129
|
+
};
|
130
|
+
|
131
|
+
export default { buildReplacements, buildEmailQueueInput, buildSmsQueueInput };
|
package/utils/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { default as campaignUtils } from "./campaignUtils";
|