@memberjunction/core-actions 2.47.0 → 2.49.0
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/custom/business-days-calculator.action.d.ts +65 -0
- package/dist/custom/business-days-calculator.action.d.ts.map +1 -0
- package/dist/custom/business-days-calculator.action.js +299 -0
- package/dist/custom/business-days-calculator.action.js.map +1 -0
- package/dist/custom/calculate-expression.action.d.ts +56 -0
- package/dist/custom/calculate-expression.action.d.ts.map +1 -0
- package/dist/custom/calculate-expression.action.js +226 -0
- package/dist/custom/calculate-expression.action.js.map +1 -0
- package/dist/custom/census-data-lookup.action.d.ts +54 -0
- package/dist/custom/census-data-lookup.action.d.ts.map +1 -0
- package/dist/custom/census-data-lookup.action.js +378 -0
- package/dist/custom/census-data-lookup.action.js.map +1 -0
- package/dist/custom/color-converter.action.d.ts +59 -0
- package/dist/custom/color-converter.action.d.ts.map +1 -0
- package/dist/custom/color-converter.action.js +295 -0
- package/dist/custom/color-converter.action.js.map +1 -0
- package/dist/custom/external-change-detection.action.js +1 -1
- package/dist/custom/external-change-detection.action.js.map +1 -1
- package/dist/custom/get-stock-price.action.d.ts +48 -0
- package/dist/custom/get-stock-price.action.d.ts.map +1 -0
- package/dist/custom/get-stock-price.action.js +153 -0
- package/dist/custom/get-stock-price.action.js.map +1 -0
- package/dist/custom/get-weather.action.d.ts +52 -0
- package/dist/custom/get-weather.action.d.ts.map +1 -0
- package/dist/custom/get-weather.action.js +172 -0
- package/dist/custom/get-weather.action.js.map +1 -0
- package/dist/custom/ip-geolocation.action.d.ts +43 -0
- package/dist/custom/ip-geolocation.action.d.ts.map +1 -0
- package/dist/custom/ip-geolocation.action.js +259 -0
- package/dist/custom/ip-geolocation.action.js.map +1 -0
- package/dist/custom/send-single-message.action.js +1 -1
- package/dist/custom/text-analyzer.action.d.ts +53 -0
- package/dist/custom/text-analyzer.action.d.ts.map +1 -0
- package/dist/custom/text-analyzer.action.js +218 -0
- package/dist/custom/text-analyzer.action.js.map +1 -0
- package/dist/custom/unit-converter.action.d.ts +63 -0
- package/dist/custom/unit-converter.action.d.ts.map +1 -0
- package/dist/custom/unit-converter.action.js +357 -0
- package/dist/custom/unit-converter.action.js.map +1 -0
- package/dist/custom/vectorize-entity.action.d.ts +45 -9
- package/dist/custom/vectorize-entity.action.d.ts.map +1 -1
- package/dist/custom/vectorize-entity.action.js +46 -10
- package/dist/custom/vectorize-entity.action.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ActionResultSimple, RunActionParams } from "@memberjunction/actions-base";
|
|
2
|
+
import { BaseAction } from "@memberjunction/actions";
|
|
3
|
+
/**
|
|
4
|
+
* Action that calculates business days between two dates, accounting for weekends
|
|
5
|
+
* and optionally holidays. Can also add/subtract business days from a date.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Calculate business days between dates
|
|
10
|
+
* await runAction({
|
|
11
|
+
* ActionName: 'Business Days Calculator',
|
|
12
|
+
* Params: [{
|
|
13
|
+
* Name: 'Operation',
|
|
14
|
+
* Value: 'DaysBetween'
|
|
15
|
+
* }, {
|
|
16
|
+
* Name: 'StartDate',
|
|
17
|
+
* Value: '2024-01-01'
|
|
18
|
+
* }, {
|
|
19
|
+
* Name: 'EndDate',
|
|
20
|
+
* Value: '2024-01-31'
|
|
21
|
+
* }]
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Add business days to a date
|
|
25
|
+
* await runAction({
|
|
26
|
+
* ActionName: 'Business Days Calculator',
|
|
27
|
+
* Params: [{
|
|
28
|
+
* Name: 'Operation',
|
|
29
|
+
* Value: 'AddDays'
|
|
30
|
+
* }, {
|
|
31
|
+
* Name: 'StartDate',
|
|
32
|
+
* Value: '2024-01-01'
|
|
33
|
+
* }, {
|
|
34
|
+
* Name: 'Days',
|
|
35
|
+
* Value: 10
|
|
36
|
+
* }]
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class BusinessDaysCalculatorAction extends BaseAction {
|
|
41
|
+
private defaultHolidays;
|
|
42
|
+
/**
|
|
43
|
+
* Executes the business days calculation
|
|
44
|
+
*
|
|
45
|
+
* @param params - The action parameters containing:
|
|
46
|
+
* - Operation: 'DaysBetween', 'AddDays', or 'SubtractDays'
|
|
47
|
+
* - StartDate: Starting date (YYYY-MM-DD format)
|
|
48
|
+
* - EndDate: Ending date (for DaysBetween operation)
|
|
49
|
+
* - Days: Number of business days to add/subtract
|
|
50
|
+
* - ExcludeHolidays: Boolean to exclude holidays (default: true)
|
|
51
|
+
* - Country: Country code for holiday calendar (default: 'US')
|
|
52
|
+
*
|
|
53
|
+
* @returns Business days calculation results
|
|
54
|
+
*/
|
|
55
|
+
protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
|
|
56
|
+
private calculateDaysBetween;
|
|
57
|
+
private addBusinessDays;
|
|
58
|
+
private isHoliday;
|
|
59
|
+
private formatDate;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Loader function to ensure the BusinessDaysCalculatorAction class is included in the bundle.
|
|
63
|
+
*/
|
|
64
|
+
export declare function LoadBusinessDaysCalculatorAction(): void;
|
|
65
|
+
//# sourceMappingURL=business-days-calculator.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business-days-calculator.action.d.ts","sourceRoot":"","sources":["../../src/custom/business-days-calculator.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAe,MAAM,8BAA8B,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBACa,4BAA6B,SAAQ,UAAU;IAExD,OAAO,CAAC,eAAe,CASrB;IAEF;;;;;;;;;;;;OAYG;cACa,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAwGvF,OAAO,CAAC,oBAAoB;IAkD5B,OAAO,CAAC,eAAe;IAqCvB,OAAO,CAAC,SAAS;IAyCjB,OAAO,CAAC,UAAU;CAGrB;AAED;;GAEG;AACH,wBAAgB,gCAAgC,SAE/C"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LoadBusinessDaysCalculatorAction = exports.BusinessDaysCalculatorAction = void 0;
|
|
10
|
+
const actions_1 = require("@memberjunction/actions");
|
|
11
|
+
const global_1 = require("@memberjunction/global");
|
|
12
|
+
/**
|
|
13
|
+
* Action that calculates business days between two dates, accounting for weekends
|
|
14
|
+
* and optionally holidays. Can also add/subtract business days from a date.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Calculate business days between dates
|
|
19
|
+
* await runAction({
|
|
20
|
+
* ActionName: 'Business Days Calculator',
|
|
21
|
+
* Params: [{
|
|
22
|
+
* Name: 'Operation',
|
|
23
|
+
* Value: 'DaysBetween'
|
|
24
|
+
* }, {
|
|
25
|
+
* Name: 'StartDate',
|
|
26
|
+
* Value: '2024-01-01'
|
|
27
|
+
* }, {
|
|
28
|
+
* Name: 'EndDate',
|
|
29
|
+
* Value: '2024-01-31'
|
|
30
|
+
* }]
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Add business days to a date
|
|
34
|
+
* await runAction({
|
|
35
|
+
* ActionName: 'Business Days Calculator',
|
|
36
|
+
* Params: [{
|
|
37
|
+
* Name: 'Operation',
|
|
38
|
+
* Value: 'AddDays'
|
|
39
|
+
* }, {
|
|
40
|
+
* Name: 'StartDate',
|
|
41
|
+
* Value: '2024-01-01'
|
|
42
|
+
* }, {
|
|
43
|
+
* Name: 'Days',
|
|
44
|
+
* Value: 10
|
|
45
|
+
* }]
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
let BusinessDaysCalculatorAction = class BusinessDaysCalculatorAction extends actions_1.BaseAction {
|
|
50
|
+
// US Federal holidays (fixed dates - actual dates may vary)
|
|
51
|
+
defaultHolidays = {
|
|
52
|
+
'US': [
|
|
53
|
+
'01-01', // New Year's Day
|
|
54
|
+
'07-04', // Independence Day
|
|
55
|
+
'12-25', // Christmas Day
|
|
56
|
+
'12-24', // Christmas Eve (many businesses closed)
|
|
57
|
+
'11-11', // Veterans Day
|
|
58
|
+
// Note: Some holidays like Memorial Day, Labor Day, Thanksgiving are calculated
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Executes the business days calculation
|
|
63
|
+
*
|
|
64
|
+
* @param params - The action parameters containing:
|
|
65
|
+
* - Operation: 'DaysBetween', 'AddDays', or 'SubtractDays'
|
|
66
|
+
* - StartDate: Starting date (YYYY-MM-DD format)
|
|
67
|
+
* - EndDate: Ending date (for DaysBetween operation)
|
|
68
|
+
* - Days: Number of business days to add/subtract
|
|
69
|
+
* - ExcludeHolidays: Boolean to exclude holidays (default: true)
|
|
70
|
+
* - Country: Country code for holiday calendar (default: 'US')
|
|
71
|
+
*
|
|
72
|
+
* @returns Business days calculation results
|
|
73
|
+
*/
|
|
74
|
+
async InternalRunAction(params) {
|
|
75
|
+
try {
|
|
76
|
+
const operationParam = params.Params.find(p => p.Name === 'Operation');
|
|
77
|
+
const startDateParam = params.Params.find(p => p.Name === 'StartDate');
|
|
78
|
+
const endDateParam = params.Params.find(p => p.Name === 'EndDate');
|
|
79
|
+
const daysParam = params.Params.find(p => p.Name === 'Days');
|
|
80
|
+
const excludeHolidaysParam = params.Params.find(p => p.Name === 'ExcludeHolidays');
|
|
81
|
+
const countryParam = params.Params.find(p => p.Name === 'Country');
|
|
82
|
+
if (!operationParam || !operationParam.Value) {
|
|
83
|
+
return {
|
|
84
|
+
Success: false,
|
|
85
|
+
Message: "Operation parameter is required (DaysBetween, AddDays, SubtractDays)",
|
|
86
|
+
ResultCode: "MISSING_PARAMETERS"
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (!startDateParam || !startDateParam.Value) {
|
|
90
|
+
return {
|
|
91
|
+
Success: false,
|
|
92
|
+
Message: "StartDate parameter is required",
|
|
93
|
+
ResultCode: "MISSING_PARAMETERS"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const operation = operationParam.Value;
|
|
97
|
+
const startDate = new Date(startDateParam.Value);
|
|
98
|
+
const excludeHolidays = excludeHolidaysParam?.Value !== false && excludeHolidaysParam?.Value !== 'false';
|
|
99
|
+
const country = countryParam?.Value || 'US';
|
|
100
|
+
if (isNaN(startDate.getTime())) {
|
|
101
|
+
return {
|
|
102
|
+
Success: false,
|
|
103
|
+
Message: "Invalid StartDate format. Use YYYY-MM-DD",
|
|
104
|
+
ResultCode: "INVALID_DATE"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
let result;
|
|
108
|
+
switch (operation) {
|
|
109
|
+
case 'DaysBetween':
|
|
110
|
+
if (!endDateParam || !endDateParam.Value) {
|
|
111
|
+
return {
|
|
112
|
+
Success: false,
|
|
113
|
+
Message: "EndDate parameter is required for DaysBetween operation",
|
|
114
|
+
ResultCode: "MISSING_PARAMETERS"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const endDate = new Date(endDateParam.Value);
|
|
118
|
+
if (isNaN(endDate.getTime())) {
|
|
119
|
+
return {
|
|
120
|
+
Success: false,
|
|
121
|
+
Message: "Invalid EndDate format. Use YYYY-MM-DD",
|
|
122
|
+
ResultCode: "INVALID_DATE"
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
result = this.calculateDaysBetween(startDate, endDate, excludeHolidays, country);
|
|
126
|
+
break;
|
|
127
|
+
case 'AddDays':
|
|
128
|
+
case 'SubtractDays':
|
|
129
|
+
if (!daysParam || daysParam.Value === undefined) {
|
|
130
|
+
return {
|
|
131
|
+
Success: false,
|
|
132
|
+
Message: "Days parameter is required for Add/Subtract operations",
|
|
133
|
+
ResultCode: "MISSING_PARAMETERS"
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const days = parseInt(daysParam.Value.toString());
|
|
137
|
+
if (isNaN(days)) {
|
|
138
|
+
return {
|
|
139
|
+
Success: false,
|
|
140
|
+
Message: "Days must be a valid number",
|
|
141
|
+
ResultCode: "INVALID_VALUE"
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const daysToAdd = operation === 'AddDays' ? days : -days;
|
|
145
|
+
result = this.addBusinessDays(startDate, daysToAdd, excludeHolidays, country);
|
|
146
|
+
break;
|
|
147
|
+
default:
|
|
148
|
+
return {
|
|
149
|
+
Success: false,
|
|
150
|
+
Message: "Invalid operation. Use: DaysBetween, AddDays, or SubtractDays",
|
|
151
|
+
ResultCode: "INVALID_OPERATION"
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
Success: true,
|
|
156
|
+
ResultCode: "SUCCESS",
|
|
157
|
+
Message: JSON.stringify(result, null, 2)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
return {
|
|
162
|
+
Success: false,
|
|
163
|
+
Message: `Failed to calculate business days: ${error instanceof Error ? error.message : String(error)}`,
|
|
164
|
+
ResultCode: "FAILED"
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
calculateDaysBetween(startDate, endDate, excludeHolidays, country) {
|
|
169
|
+
let start = new Date(startDate);
|
|
170
|
+
let end = new Date(endDate);
|
|
171
|
+
const isReverse = start > end;
|
|
172
|
+
if (isReverse) {
|
|
173
|
+
[start, end] = [end, start];
|
|
174
|
+
}
|
|
175
|
+
let businessDays = 0;
|
|
176
|
+
let totalDays = 0;
|
|
177
|
+
let weekends = 0;
|
|
178
|
+
let holidays = 0;
|
|
179
|
+
const holidayDates = [];
|
|
180
|
+
const current = new Date(start);
|
|
181
|
+
while (current <= end) {
|
|
182
|
+
totalDays++;
|
|
183
|
+
const dayOfWeek = current.getDay();
|
|
184
|
+
const isWeekend = dayOfWeek === 0 || dayOfWeek === 6;
|
|
185
|
+
const isHoliday = excludeHolidays && this.isHoliday(current, country);
|
|
186
|
+
if (isWeekend) {
|
|
187
|
+
weekends++;
|
|
188
|
+
}
|
|
189
|
+
else if (isHoliday) {
|
|
190
|
+
holidays++;
|
|
191
|
+
holidayDates.push(this.formatDate(current));
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
businessDays++;
|
|
195
|
+
}
|
|
196
|
+
current.setDate(current.getDate() + 1);
|
|
197
|
+
}
|
|
198
|
+
if (isReverse) {
|
|
199
|
+
businessDays = -businessDays;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
businessDays,
|
|
203
|
+
totalDays: totalDays - 1, // Exclusive of start date
|
|
204
|
+
weekends,
|
|
205
|
+
holidays,
|
|
206
|
+
holidayDates,
|
|
207
|
+
startDate: this.formatDate(startDate),
|
|
208
|
+
endDate: this.formatDate(endDate),
|
|
209
|
+
includesPartialDays: false
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
addBusinessDays(startDate, days, excludeHolidays, country) {
|
|
213
|
+
const result = new Date(startDate);
|
|
214
|
+
const direction = days >= 0 ? 1 : -1;
|
|
215
|
+
let remainingDays = Math.abs(days);
|
|
216
|
+
const skippedDates = [];
|
|
217
|
+
while (remainingDays > 0) {
|
|
218
|
+
result.setDate(result.getDate() + direction);
|
|
219
|
+
const dayOfWeek = result.getDay();
|
|
220
|
+
const isWeekend = dayOfWeek === 0 || dayOfWeek === 6;
|
|
221
|
+
const isHoliday = excludeHolidays && this.isHoliday(result, country);
|
|
222
|
+
if (isWeekend) {
|
|
223
|
+
skippedDates.push({
|
|
224
|
+
date: this.formatDate(result),
|
|
225
|
+
reason: dayOfWeek === 0 ? 'Sunday' : 'Saturday'
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else if (isHoliday) {
|
|
229
|
+
skippedDates.push({
|
|
230
|
+
date: this.formatDate(result),
|
|
231
|
+
reason: 'Holiday'
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
remainingDays--;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
startDate: this.formatDate(startDate),
|
|
240
|
+
businessDaysAdded: days,
|
|
241
|
+
resultDate: this.formatDate(result),
|
|
242
|
+
dayOfWeek: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][result.getDay()],
|
|
243
|
+
skippedDates: skippedDates.slice(-10), // Last 10 skipped dates
|
|
244
|
+
totalDaysElapsed: Math.abs(Math.ceil((result.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24)))
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
isHoliday(date, country) {
|
|
248
|
+
const monthDay = `${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
|
249
|
+
const year = date.getFullYear();
|
|
250
|
+
// Check fixed holidays
|
|
251
|
+
const holidays = this.defaultHolidays[country] || [];
|
|
252
|
+
if (holidays.includes(monthDay)) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
// Check calculated US holidays
|
|
256
|
+
if (country === 'US') {
|
|
257
|
+
// Memorial Day (last Monday in May)
|
|
258
|
+
if (date.getMonth() === 4 && date.getDay() === 1 && date.getDate() > 24) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
// Labor Day (first Monday in September)
|
|
262
|
+
if (date.getMonth() === 8 && date.getDay() === 1 && date.getDate() <= 7) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
// Thanksgiving (fourth Thursday in November)
|
|
266
|
+
if (date.getMonth() === 10 && date.getDay() === 4 && date.getDate() >= 22 && date.getDate() <= 28) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
// Black Friday (day after Thanksgiving)
|
|
270
|
+
if (date.getMonth() === 10 && date.getDay() === 5 && date.getDate() >= 23 && date.getDate() <= 29) {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
// Martin Luther King Jr. Day (third Monday in January)
|
|
274
|
+
if (date.getMonth() === 0 && date.getDay() === 1 && date.getDate() >= 15 && date.getDate() <= 21) {
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
// Presidents Day (third Monday in February)
|
|
278
|
+
if (date.getMonth() === 1 && date.getDay() === 1 && date.getDate() >= 15 && date.getDate() <= 21) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
formatDate(date) {
|
|
285
|
+
return date.toISOString().split('T')[0];
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
exports.BusinessDaysCalculatorAction = BusinessDaysCalculatorAction;
|
|
289
|
+
exports.BusinessDaysCalculatorAction = BusinessDaysCalculatorAction = __decorate([
|
|
290
|
+
(0, global_1.RegisterClass)(actions_1.BaseAction, "__BusinessDaysCalculator")
|
|
291
|
+
], BusinessDaysCalculatorAction);
|
|
292
|
+
/**
|
|
293
|
+
* Loader function to ensure the BusinessDaysCalculatorAction class is included in the bundle.
|
|
294
|
+
*/
|
|
295
|
+
function LoadBusinessDaysCalculatorAction() {
|
|
296
|
+
// this function is a stub that is used to force the bundler to include the above class in the final bundle and not tree shake them out
|
|
297
|
+
}
|
|
298
|
+
exports.LoadBusinessDaysCalculatorAction = LoadBusinessDaysCalculatorAction;
|
|
299
|
+
//# sourceMappingURL=business-days-calculator.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business-days-calculator.action.js","sourceRoot":"","sources":["../../src/custom/business-days-calculator.action.ts"],"names":[],"mappings":";;;;;;;;;AACA,qDAAqD;AACrD,mDAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEI,IAAM,4BAA4B,GAAlC,MAAM,4BAA6B,SAAQ,oBAAU;IACxD,4DAA4D;IACpD,eAAe,GAA6B;QAChD,IAAI,EAAE;YACF,OAAO,EAAE,iBAAiB;YAC1B,OAAO,EAAE,mBAAmB;YAC5B,OAAO,EAAE,gBAAgB;YACzB,OAAO,EAAE,yCAAyC;YAClD,OAAO,EAAE,eAAe;YACxB,gFAAgF;SACnF;KACJ,CAAC;IAEF;;;;;;;;;;;;OAYG;IACO,KAAK,CAAC,iBAAiB,CAAC,MAAuB;QACrD,IAAI,CAAC;YACD,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;YACvE,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;YACvE,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;YACnE,MAAM,SAAS,GAAG,MAAM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AC5C,uIAAuI;AAC3I,CAAC;AAFD,4EAEC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ActionResultSimple, RunActionParams } from "@memberjunction/actions-base";
|
|
2
|
+
import { BaseAction } from "@memberjunction/actions";
|
|
3
|
+
/**
|
|
4
|
+
* Action that evaluates mathematical expressions safely using JavaScript's built-in math functions.
|
|
5
|
+
* Supports basic arithmetic operations, parentheses, and common math functions.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Simple arithmetic
|
|
10
|
+
* await runAction({
|
|
11
|
+
* ActionName: 'Calculate Expression',
|
|
12
|
+
* Params: [{
|
|
13
|
+
* Name: 'Expression',
|
|
14
|
+
* Value: '(2 * 3) + 4 / 15'
|
|
15
|
+
* }]
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Using math functions
|
|
19
|
+
* await runAction({
|
|
20
|
+
* ActionName: 'Calculate Expression',
|
|
21
|
+
* Params: [{
|
|
22
|
+
* Name: 'Expression',
|
|
23
|
+
* Value: 'sqrt(16) + pow(2, 3) + sin(PI/2)'
|
|
24
|
+
* }]
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class CalculateExpressionAction extends BaseAction {
|
|
29
|
+
/**
|
|
30
|
+
* Executes the calculation for the provided mathematical expression
|
|
31
|
+
*
|
|
32
|
+
* @param params - The action parameters containing:
|
|
33
|
+
* - Expression: A mathematical expression to evaluate
|
|
34
|
+
*
|
|
35
|
+
* @returns A promise resolving to an ActionResultSimple with:
|
|
36
|
+
* - Success: true if calculation was successful
|
|
37
|
+
* - ResultCode: "SUCCESS", "INVALID_EXPRESSION", or "FAILED"
|
|
38
|
+
* - ResultData: Object containing the result and formatted expression
|
|
39
|
+
* - Message: Error message if failed
|
|
40
|
+
*/
|
|
41
|
+
protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the expression contains potentially dangerous code patterns
|
|
44
|
+
*/
|
|
45
|
+
private containsDangerousCode;
|
|
46
|
+
/**
|
|
47
|
+
* Formats a number for display, handling very large/small numbers appropriately
|
|
48
|
+
*/
|
|
49
|
+
private formatNumber;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Loader function to ensure the CalculateExpressionAction class is included in the bundle.
|
|
53
|
+
* This prevents tree-shaking from removing the class during the build process.
|
|
54
|
+
*/
|
|
55
|
+
export declare function LoadCalculateExpressionAction(): void;
|
|
56
|
+
//# sourceMappingURL=calculate-expression.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate-expression.action.d.ts","sourceRoot":"","sources":["../../src/custom/calculate-expression.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAe,MAAM,8BAA8B,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBACa,yBAA0B,SAAQ,UAAU;IACrD;;;;;;;;;;;OAWG;cACa,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAqHvF;;OAEG;IACH,OAAO,CAAC,qBAAqB;IA2C7B;;OAEG;IACH,OAAO,CAAC,YAAY;CAUvB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,SAE5C"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LoadCalculateExpressionAction = exports.CalculateExpressionAction = void 0;
|
|
10
|
+
const actions_1 = require("@memberjunction/actions");
|
|
11
|
+
const global_1 = require("@memberjunction/global");
|
|
12
|
+
/**
|
|
13
|
+
* Action that evaluates mathematical expressions safely using JavaScript's built-in math functions.
|
|
14
|
+
* Supports basic arithmetic operations, parentheses, and common math functions.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Simple arithmetic
|
|
19
|
+
* await runAction({
|
|
20
|
+
* ActionName: 'Calculate Expression',
|
|
21
|
+
* Params: [{
|
|
22
|
+
* Name: 'Expression',
|
|
23
|
+
* Value: '(2 * 3) + 4 / 15'
|
|
24
|
+
* }]
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Using math functions
|
|
28
|
+
* await runAction({
|
|
29
|
+
* ActionName: 'Calculate Expression',
|
|
30
|
+
* Params: [{
|
|
31
|
+
* Name: 'Expression',
|
|
32
|
+
* Value: 'sqrt(16) + pow(2, 3) + sin(PI/2)'
|
|
33
|
+
* }]
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
let CalculateExpressionAction = class CalculateExpressionAction extends actions_1.BaseAction {
|
|
38
|
+
/**
|
|
39
|
+
* Executes the calculation for the provided mathematical expression
|
|
40
|
+
*
|
|
41
|
+
* @param params - The action parameters containing:
|
|
42
|
+
* - Expression: A mathematical expression to evaluate
|
|
43
|
+
*
|
|
44
|
+
* @returns A promise resolving to an ActionResultSimple with:
|
|
45
|
+
* - Success: true if calculation was successful
|
|
46
|
+
* - ResultCode: "SUCCESS", "INVALID_EXPRESSION", or "FAILED"
|
|
47
|
+
* - ResultData: Object containing the result and formatted expression
|
|
48
|
+
* - Message: Error message if failed
|
|
49
|
+
*/
|
|
50
|
+
async InternalRunAction(params) {
|
|
51
|
+
try {
|
|
52
|
+
const expressionParam = params.Params.find(p => p.Name === 'Expression');
|
|
53
|
+
if (!expressionParam || !expressionParam.Value) {
|
|
54
|
+
return {
|
|
55
|
+
Success: false,
|
|
56
|
+
Message: "Expression parameter is required",
|
|
57
|
+
ResultCode: "MISSING_PARAMETERS"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const expression = expressionParam.Value.trim();
|
|
61
|
+
// Validate the expression doesn't contain dangerous code
|
|
62
|
+
if (this.containsDangerousCode(expression)) {
|
|
63
|
+
return {
|
|
64
|
+
Success: false,
|
|
65
|
+
Message: "Expression contains invalid or potentially dangerous code",
|
|
66
|
+
ResultCode: "INVALID_EXPRESSION"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Create a safe evaluation context with math functions
|
|
70
|
+
const mathContext = {
|
|
71
|
+
// Basic math functions
|
|
72
|
+
abs: Math.abs,
|
|
73
|
+
acos: Math.acos,
|
|
74
|
+
asin: Math.asin,
|
|
75
|
+
atan: Math.atan,
|
|
76
|
+
atan2: Math.atan2,
|
|
77
|
+
ceil: Math.ceil,
|
|
78
|
+
cos: Math.cos,
|
|
79
|
+
exp: Math.exp,
|
|
80
|
+
floor: Math.floor,
|
|
81
|
+
log: Math.log,
|
|
82
|
+
log10: Math.log10,
|
|
83
|
+
max: Math.max,
|
|
84
|
+
min: Math.min,
|
|
85
|
+
pow: Math.pow,
|
|
86
|
+
random: Math.random,
|
|
87
|
+
round: Math.round,
|
|
88
|
+
sin: Math.sin,
|
|
89
|
+
sqrt: Math.sqrt,
|
|
90
|
+
tan: Math.tan,
|
|
91
|
+
// Constants
|
|
92
|
+
E: Math.E,
|
|
93
|
+
PI: Math.PI,
|
|
94
|
+
// Additional useful functions
|
|
95
|
+
sign: Math.sign,
|
|
96
|
+
trunc: Math.trunc,
|
|
97
|
+
cbrt: Math.cbrt,
|
|
98
|
+
log2: Math.log2,
|
|
99
|
+
// Hyperbolic functions
|
|
100
|
+
sinh: Math.sinh,
|
|
101
|
+
cosh: Math.cosh,
|
|
102
|
+
tanh: Math.tanh
|
|
103
|
+
};
|
|
104
|
+
// Prepare the expression by replacing math function names
|
|
105
|
+
let safeExpression = expression;
|
|
106
|
+
// Replace common math notations
|
|
107
|
+
safeExpression = safeExpression.replace(/\^/g, '**'); // Replace ^ with ** for exponentiation
|
|
108
|
+
// Create the evaluation function
|
|
109
|
+
const evalFunction = new Function(...Object.keys(mathContext), `
|
|
110
|
+
"use strict";
|
|
111
|
+
try {
|
|
112
|
+
return (${safeExpression});
|
|
113
|
+
} catch (e) {
|
|
114
|
+
throw new Error('Invalid expression: ' + e.message);
|
|
115
|
+
}
|
|
116
|
+
`);
|
|
117
|
+
// Evaluate the expression
|
|
118
|
+
const result = evalFunction(...Object.values(mathContext));
|
|
119
|
+
// Check if result is a valid number
|
|
120
|
+
if (typeof result !== 'number' || isNaN(result)) {
|
|
121
|
+
return {
|
|
122
|
+
Success: false,
|
|
123
|
+
Message: "Expression did not evaluate to a valid number",
|
|
124
|
+
ResultCode: "INVALID_EXPRESSION"
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const resultData = {
|
|
128
|
+
expression: expression,
|
|
129
|
+
result: result,
|
|
130
|
+
formattedResult: this.formatNumber(result),
|
|
131
|
+
isInteger: Number.isInteger(result),
|
|
132
|
+
scientificNotation: result.toExponential(),
|
|
133
|
+
evaluatedAt: new Date().toISOString()
|
|
134
|
+
};
|
|
135
|
+
// Include both the simple message and the full result data
|
|
136
|
+
const message = {
|
|
137
|
+
summary: `${expression} = ${this.formatNumber(result)}`,
|
|
138
|
+
details: resultData
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
Success: true,
|
|
142
|
+
ResultCode: "SUCCESS",
|
|
143
|
+
Message: JSON.stringify(message, null, 2)
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
return {
|
|
148
|
+
Success: false,
|
|
149
|
+
Message: `Failed to calculate expression: ${error instanceof Error ? error.message : String(error)}`,
|
|
150
|
+
ResultCode: "INVALID_EXPRESSION"
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Checks if the expression contains potentially dangerous code patterns
|
|
156
|
+
*/
|
|
157
|
+
containsDangerousCode(expression) {
|
|
158
|
+
// List of dangerous patterns to block
|
|
159
|
+
const dangerousPatterns = [
|
|
160
|
+
/import\s/i,
|
|
161
|
+
/require\s*\(/i,
|
|
162
|
+
/eval\s*\(/i,
|
|
163
|
+
/function\s*\(/i,
|
|
164
|
+
/=>/,
|
|
165
|
+
/new\s+/i,
|
|
166
|
+
/\.\s*constructor/i,
|
|
167
|
+
/\[["'`].*["'`]\]/, // Array access with strings
|
|
168
|
+
/process\./i,
|
|
169
|
+
/global\./i,
|
|
170
|
+
/window\./i,
|
|
171
|
+
/document\./i,
|
|
172
|
+
/console\./i,
|
|
173
|
+
/alert\s*\(/i,
|
|
174
|
+
/prompt\s*\(/i,
|
|
175
|
+
/confirm\s*\(/i,
|
|
176
|
+
/while\s*\(/i,
|
|
177
|
+
/for\s*\(/i,
|
|
178
|
+
/do\s*{/i,
|
|
179
|
+
/if\s*\(/i,
|
|
180
|
+
/else/i,
|
|
181
|
+
/return/i,
|
|
182
|
+
/throw/i,
|
|
183
|
+
/try/i,
|
|
184
|
+
/catch/i,
|
|
185
|
+
/finally/i,
|
|
186
|
+
/await/i,
|
|
187
|
+
/async/i,
|
|
188
|
+
/class\s/i,
|
|
189
|
+
/extends/i,
|
|
190
|
+
/\${/, // Template literals
|
|
191
|
+
/`/, // Backticks
|
|
192
|
+
/;/, // Semicolons (prevent multiple statements)
|
|
193
|
+
/{/, // Curly braces (prevent code blocks)
|
|
194
|
+
/}/,
|
|
195
|
+
];
|
|
196
|
+
return dangerousPatterns.some(pattern => pattern.test(expression));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Formats a number for display, handling very large/small numbers appropriately
|
|
200
|
+
*/
|
|
201
|
+
formatNumber(num) {
|
|
202
|
+
if (Number.isInteger(num) && num >= -1e15 && num <= 1e15) {
|
|
203
|
+
return num.toString();
|
|
204
|
+
}
|
|
205
|
+
else if (Math.abs(num) < 1e-6 || Math.abs(num) > 1e15) {
|
|
206
|
+
return num.toExponential(6);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// Round to 10 decimal places and remove trailing zeros
|
|
210
|
+
return parseFloat(num.toFixed(10)).toString();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
exports.CalculateExpressionAction = CalculateExpressionAction;
|
|
215
|
+
exports.CalculateExpressionAction = CalculateExpressionAction = __decorate([
|
|
216
|
+
(0, global_1.RegisterClass)(actions_1.BaseAction, "__CalculateExpression")
|
|
217
|
+
], CalculateExpressionAction);
|
|
218
|
+
/**
|
|
219
|
+
* Loader function to ensure the CalculateExpressionAction class is included in the bundle.
|
|
220
|
+
* This prevents tree-shaking from removing the class during the build process.
|
|
221
|
+
*/
|
|
222
|
+
function LoadCalculateExpressionAction() {
|
|
223
|
+
// this function is a stub that is used to force the bundler to include the above class in the final bundle and not tree shake them out
|
|
224
|
+
}
|
|
225
|
+
exports.LoadCalculateExpressionAction = LoadCalculateExpressionAction;
|
|
226
|
+
//# sourceMappingURL=calculate-expression.action.js.map
|