@saasquatch/program-boilerplate 3.10.1-5 → 3.10.1-6
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/conversion.d.ts +5 -5
- package/dist/conversion.js +14 -27
- package/dist/index.js +16 -30
- package/dist/jsonata.js +8 -7
- package/dist/logger.js +4 -3
- package/dist/queries.d.ts +2 -2
- package/dist/queries.js +3 -24
- package/dist/transaction.d.ts +5 -7
- package/dist/transaction.js +3 -11
- package/dist/trigger.d.ts +1 -1
- package/dist/trigger.js +41 -25
- package/dist/types/index.js +8 -22
- package/dist/types/rpc.d.ts +24 -48
- package/dist/types/saasquatch.d.ts +9 -66
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +16 -12
- package/package.json +11 -11
package/dist/conversion.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* A custom field based conversion rule
|
|
6
6
|
*/
|
|
7
|
-
type CustomFieldConversionRule = {
|
|
7
|
+
declare type CustomFieldConversionRule = {
|
|
8
8
|
operator: number | string;
|
|
9
9
|
fieldName: string;
|
|
10
10
|
value: RuleValue;
|
|
@@ -12,7 +12,7 @@ type CustomFieldConversionRule = {
|
|
|
12
12
|
/**
|
|
13
13
|
* An event-based conversion rule
|
|
14
14
|
*/
|
|
15
|
-
type EventTriggerRule = {
|
|
15
|
+
declare type EventTriggerRule = {
|
|
16
16
|
operator: string;
|
|
17
17
|
eventKey: string;
|
|
18
18
|
value: string;
|
|
@@ -20,7 +20,7 @@ type EventTriggerRule = {
|
|
|
20
20
|
/**
|
|
21
21
|
* A key-value pair
|
|
22
22
|
*/
|
|
23
|
-
type Event = {
|
|
23
|
+
declare type Event = {
|
|
24
24
|
key: string;
|
|
25
25
|
fields: {
|
|
26
26
|
[key: string]: any;
|
|
@@ -29,7 +29,7 @@ type Event = {
|
|
|
29
29
|
/**
|
|
30
30
|
* A user object returned from a GraphQL query
|
|
31
31
|
*/
|
|
32
|
-
type UserQueryResult = {
|
|
32
|
+
declare type UserQueryResult = {
|
|
33
33
|
customFields: {
|
|
34
34
|
[key: string]: any;
|
|
35
35
|
};
|
|
@@ -37,7 +37,7 @@ type UserQueryResult = {
|
|
|
37
37
|
/**
|
|
38
38
|
* The value of a rule
|
|
39
39
|
*/
|
|
40
|
-
type RuleValue = string | boolean | number;
|
|
40
|
+
declare type RuleValue = string | boolean | number;
|
|
41
41
|
/**
|
|
42
42
|
* Checks whether any of the edge trigger conditions are met given
|
|
43
43
|
* a list of fields to check and the current context.
|
package/dist/conversion.js
CHANGED
|
@@ -4,11 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
7
|
-
|
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(o, k2, desc);
|
|
7
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
8
|
}) : (function(o, m, k, k2) {
|
|
13
9
|
if (k2 === undefined) k2 = k;
|
|
14
10
|
o[k2] = m[k];
|
|
@@ -18,27 +14,15 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
18
14
|
}) : function(o, v) {
|
|
19
15
|
o["default"] = v;
|
|
20
16
|
});
|
|
21
|
-
var __importStar = (this && this.__importStar) ||
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return ownKeys(o);
|
|
29
|
-
};
|
|
30
|
-
return function (mod) {
|
|
31
|
-
if (mod && mod.__esModule) return mod;
|
|
32
|
-
var result = {};
|
|
33
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
-
__setModuleDefault(result, mod);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
})();
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
38
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.meetEdgeTriggerConditions =
|
|
40
|
-
exports.meetCustomFieldRules = meetCustomFieldRules;
|
|
41
|
-
exports.meetEventTriggerRules = meetEventTriggerRules;
|
|
25
|
+
exports.meetEventTriggerRules = exports.meetCustomFieldRules = exports.meetEdgeTriggerConditions = void 0;
|
|
42
26
|
const assert = __importStar(require("assert"));
|
|
43
27
|
const jsonata_1 = require("./jsonata");
|
|
44
28
|
//functions
|
|
@@ -82,8 +66,8 @@ function meetEdgeTriggerConditions(fields, activeTrigger) {
|
|
|
82
66
|
// not take more than a few milliseconds. if it takes longer than 500ms
|
|
83
67
|
// something is definitely wrong with the query
|
|
84
68
|
const jsonataTimeoutMs = 500;
|
|
85
|
-
const { success: prevSuccess, result: previousValue } =
|
|
86
|
-
const { success: currentSuccess, result: currentValue } =
|
|
69
|
+
const { success: prevSuccess, result: previousValue } = jsonata_1.timeboxedJsonata(field.replace("user.", "previous."), activeTrigger, jsonataTimeoutMs);
|
|
70
|
+
const { success: currentSuccess, result: currentValue } = jsonata_1.timeboxedJsonata(field, activeTrigger, jsonataTimeoutMs);
|
|
87
71
|
// one of the JSONata expressions failed to evaluate -- edge field is considered
|
|
88
72
|
// "not passing"
|
|
89
73
|
if (!prevSuccess || !currentSuccess) {
|
|
@@ -101,6 +85,7 @@ function meetEdgeTriggerConditions(fields, activeTrigger) {
|
|
|
101
85
|
}
|
|
102
86
|
return false;
|
|
103
87
|
}
|
|
88
|
+
exports.meetEdgeTriggerConditions = meetEdgeTriggerConditions;
|
|
104
89
|
/**
|
|
105
90
|
* Checks if the customFields of a user meet a certain customField-based conversion rule.
|
|
106
91
|
*
|
|
@@ -166,6 +151,7 @@ function meetCustomFieldRules(user, customConversionRules) {
|
|
|
166
151
|
}
|
|
167
152
|
return customConversionRules.every((rule) => meetCustomFieldCondition(user, rule));
|
|
168
153
|
}
|
|
154
|
+
exports.meetCustomFieldRules = meetCustomFieldRules;
|
|
169
155
|
/**
|
|
170
156
|
* @deprecated No longer in use, use JSONata expression and evaluation instead
|
|
171
157
|
* Checks if the events triggering the program meet every rule that defines event-based conversion
|
|
@@ -183,3 +169,4 @@ function meetEventTriggerRules(events, eventTriggerRules) {
|
|
|
183
169
|
}
|
|
184
170
|
return eventTriggerRules.every((rule) => meetEventCondition(events, rule));
|
|
185
171
|
}
|
|
172
|
+
exports.meetEventTriggerRules = meetEventTriggerRules;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -15,30 +11,18 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
11
|
}) : function(o, v) {
|
|
16
12
|
o["default"] = v;
|
|
17
13
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
35
21
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
23
|
};
|
|
38
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.loadStandardWebtaskConfig = exports.setLogLevel = exports.getLogger = exports.safeJsonata = exports.timeboxedJsonata = exports.timeboxExpression = exports.getRewardUnitsFromJsonata = exports.getUserCustomFieldsFromJsonata = exports.getTriggerSchema = exports.numToEquality = exports.inferType = exports.triggerProgram = exports.getGoalAnalyticTimestamp = exports.setRewardSchedule = exports.rewardEmailQuery = exports.meetEdgeTriggerConditions = exports.meetCustomFieldRules = exports.meetEventTriggerRules = exports.Transaction = exports.types = void 0;
|
|
40
|
-
exports.webtask = webtask;
|
|
41
|
-
exports.runWebtask = runWebtask;
|
|
25
|
+
exports.runWebtask = exports.webtask = exports.loadStandardWebtaskConfig = exports.setLogLevel = exports.getLogger = exports.safeJsonata = exports.timeboxedJsonata = exports.timeboxExpression = exports.getRewardUnitsFromJsonata = exports.getUserCustomFieldsFromJsonata = exports.getTriggerSchema = exports.numToEquality = exports.inferType = exports.triggerProgram = exports.getGoalAnalyticTimestamp = exports.setRewardSchedule = exports.rewardEmailQuery = exports.meetEdgeTriggerConditions = exports.meetCustomFieldRules = exports.meetEventTriggerRules = exports.Transaction = exports.types = void 0;
|
|
42
26
|
const express_1 = __importDefault(require("express"));
|
|
43
27
|
const conversion_1 = require("./conversion");
|
|
44
28
|
Object.defineProperty(exports, "meetCustomFieldRules", { enumerable: true, get: function () { return conversion_1.meetCustomFieldRules; } });
|
|
@@ -80,11 +64,11 @@ const logger_3 = require("@saasquatch/logger");
|
|
|
80
64
|
*/
|
|
81
65
|
function webtask(program = {}) {
|
|
82
66
|
const compression = require("compression");
|
|
83
|
-
const app =
|
|
84
|
-
const logger =
|
|
67
|
+
const app = express_1.default();
|
|
68
|
+
const logger = logger_2.getLogger("program-boilerplate");
|
|
85
69
|
app.use(express_1.default.json({ limit: process.env.MAX_PAYLOAD_SIZE || "1mb" }));
|
|
86
70
|
app.use(compression());
|
|
87
|
-
app.use(
|
|
71
|
+
app.use(logger_3.httpLogMiddleware(logger, { logNonErrorResponses: false }));
|
|
88
72
|
// Enforce HTTPS. The server does not redirect http -> https
|
|
89
73
|
// because OWASP advises not to
|
|
90
74
|
app.use((req, res, next) => {
|
|
@@ -108,13 +92,14 @@ function webtask(program = {}) {
|
|
|
108
92
|
app.get("/livez", healthCheck);
|
|
109
93
|
app.get("/readyz", healthCheck);
|
|
110
94
|
app.post("/*", (req, res) => {
|
|
111
|
-
const { json, code } =
|
|
95
|
+
const { json, code } = trigger_1.triggerProgram(req.body, program);
|
|
112
96
|
return res.status(code).json(json);
|
|
113
97
|
});
|
|
114
98
|
return app;
|
|
115
99
|
}
|
|
100
|
+
exports.webtask = webtask;
|
|
116
101
|
function runWebtask(webtask, config) {
|
|
117
|
-
const logger =
|
|
102
|
+
const logger = logger_2.getLogger("program-boilerplate");
|
|
118
103
|
const server = webtask.listen(config.port, () => logger.notice(`${config.webtaskName} running on port ${config.port}`));
|
|
119
104
|
if (config.keepAliveTimeoutSeconds !== undefined) {
|
|
120
105
|
// https://cloud.google.com/load-balancing/docs/https/https-logging-monitoring#failure-messages
|
|
@@ -138,3 +123,4 @@ function runWebtask(webtask, config) {
|
|
|
138
123
|
process.on("SIGTERM", gracefulShutdown("SIGTERM"));
|
|
139
124
|
process.on("SIGINT", gracefulShutdown("SIGINT"));
|
|
140
125
|
}
|
|
126
|
+
exports.runWebtask = runWebtask;
|
package/dist/jsonata.js
CHANGED
|
@@ -3,9 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.timeboxExpression =
|
|
7
|
-
exports.safeJsonata = safeJsonata;
|
|
8
|
-
exports.timeboxedJsonata = timeboxedJsonata;
|
|
6
|
+
exports.timeboxedJsonata = exports.safeJsonata = exports.timeboxExpression = void 0;
|
|
9
7
|
const jsonata_1 = __importDefault(require("jsonata"));
|
|
10
8
|
const logger_1 = require("@saasquatch/logger");
|
|
11
9
|
const TIMEOUT = 5000;
|
|
@@ -51,30 +49,33 @@ function timeboxExpression(expr, timeout, maxDepth) {
|
|
|
51
49
|
checkRunnaway();
|
|
52
50
|
});
|
|
53
51
|
}
|
|
52
|
+
exports.timeboxExpression = timeboxExpression;
|
|
54
53
|
/**
|
|
55
54
|
* @deprecated Use timeboxedJsonata instead
|
|
56
55
|
*/
|
|
57
56
|
function safeJsonata(expression, inputData) {
|
|
58
57
|
try {
|
|
59
|
-
const jsonataQuery =
|
|
58
|
+
const jsonataQuery = jsonata_1.default(expression);
|
|
60
59
|
timeboxExpression(jsonataQuery);
|
|
61
60
|
return jsonataQuery.evaluate(inputData);
|
|
62
61
|
}
|
|
63
62
|
catch (e) {
|
|
64
|
-
|
|
63
|
+
logger_1.getLogger("program-boilerplate").warn(`Failed to evaluate JSONata expression: ${e.message}`);
|
|
65
64
|
}
|
|
66
65
|
}
|
|
66
|
+
exports.safeJsonata = safeJsonata;
|
|
67
67
|
function timeboxedJsonata(expression, inputData, timeout, maxDepth) {
|
|
68
68
|
try {
|
|
69
|
-
const jsonataQuery =
|
|
69
|
+
const jsonataQuery = jsonata_1.default(expression);
|
|
70
70
|
timeboxExpression(jsonataQuery, timeout, maxDepth);
|
|
71
71
|
const result = jsonataQuery.evaluate(inputData);
|
|
72
72
|
return { success: true, result };
|
|
73
73
|
}
|
|
74
74
|
catch (e) {
|
|
75
75
|
if (e instanceof Error) {
|
|
76
|
-
|
|
76
|
+
logger_1.getLogger("program-boilerplate").warn(`Failed to evaluate JSONata expression: ${e.message}`);
|
|
77
77
|
}
|
|
78
78
|
return { success: false, result: undefined };
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
+
exports.timeboxedJsonata = timeboxedJsonata;
|
package/dist/logger.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLogger =
|
|
4
|
-
exports.setLogLevel = setLogLevel;
|
|
3
|
+
exports.setLogLevel = exports.getLogger = void 0;
|
|
5
4
|
const logger_1 = require("@saasquatch/logger");
|
|
6
5
|
// Lazily initialized logger instance
|
|
7
6
|
let _logger;
|
|
@@ -20,11 +19,12 @@ function getLogger(logLevel) {
|
|
|
20
19
|
if (!logger_1.LOG_LEVELS.includes(logLevel)) {
|
|
21
20
|
logLevel = "info";
|
|
22
21
|
}
|
|
23
|
-
_logger =
|
|
22
|
+
_logger = logger_1.initializeLogger({
|
|
24
23
|
logLevel: logLevel,
|
|
25
24
|
});
|
|
26
25
|
return _logger;
|
|
27
26
|
}
|
|
27
|
+
exports.getLogger = getLogger;
|
|
28
28
|
/**
|
|
29
29
|
* Set the log level of the singleton logger.
|
|
30
30
|
*
|
|
@@ -35,3 +35,4 @@ function setLogLevel(logLevel) {
|
|
|
35
35
|
return;
|
|
36
36
|
_logger.level = logLevel;
|
|
37
37
|
}
|
|
38
|
+
exports.setLogLevel = setLogLevel;
|
package/dist/queries.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const rewardEmailQuery = "\n query ($userId:String!, $accountId:String!, $rewardId:ID!, $programId:ID!, $referralId: ID
|
|
2
|
-
export declare const nonRewardEmailQueryForReferralPrograms = "query ($userId:String!, $accountId:String!,$programId:ID!, $referralId: ID
|
|
1
|
+
export declare const rewardEmailQuery = "\n query ($userId:String!, $accountId:String!, $rewardId:ID!, $programId:ID!, $referralId: ID!) {\n reward(id:$rewardId) {\n ...AllFlatRewardFields\n }\n user(id:$userId, accountId:$accountId) {\n firstName\n lastName\n customFields\n referralCode(programId:$programId)\n shareLink(programId:$programId,useCleanLink:true)\n facebook: messageLink(programId:$programId,shareMedium:FACEBOOK,engagementMedium:EMAIL)\n twitter: messageLink(programId:$programId,shareMedium:TWITTER,engagementMedium:EMAIL)\n email:messageLink(programId:$programId,shareMedium:EMAIL,engagementMedium:EMAIL)\n sms:messageLink(programId:$programId,shareMedium:SMS,engagementMedium:EMAIL)\n linkedin: messageLink(programId:$programId,shareMedium:LINKEDIN,engagementMedium:EMAIL)\n fbmessenger: messageLink(programId:$programId,shareMedium:FBMESSENGER,engagementMedium:EMAIL)\n }\n\n program(id: $programId) {\n sharing {\n redirectUrl {\n url\n }\n }\n }\n\n referral(id:$referralId) {\n referrerUser{\n firstName\n lastName\n email\n customFields\n }\n referredUser{\n firstName\n lastName\n email\n customFields\n }\n }\n\n tenant {\n emailAddress\n settings {\n companyName\n }\n }\n }\n\n fragment AllFlatRewardFields on FlatReward {\n type\n prettyValue\n value\n unit\n name\n dateGiven\n dateExpires\n dateCancelled\n rewardSource\n fuelTankCode\n fuelTankType\n currency\n programId\n programRewardKey\n }\n";
|
|
2
|
+
export declare const nonRewardEmailQueryForReferralPrograms = "query ($userId:String!, $accountId:String!,$programId:ID!, $referralId: ID!) {\n user(id:$userId, accountId:$accountId) {\n firstName\n lastName\n customFields\n referralCode(programId:$programId)\n shareLink(programId:$programId,useCleanLink:true)\n facebook: messageLink(programId:$programId,shareMedium:FACEBOOK)\n twitter: messageLink(programId:$programId,shareMedium:TWITTER)\n email:messageLink(programId:$programId,shareMedium:EMAIL)\n sms:messageLink(programId:$programId,shareMedium:SMS)\n linkedin: messageLink(programId:$programId,shareMedium:LINKEDIN)\n fbmessenger: messageLink(programId:$programId,shareMedium:FBMESSENGER)\n }\n\n referral(id:$referralId) {\n referrerUser{\n firstName\n lastName\n email\n customFields\n }\n referredUser{\n firstName\n lastName\n email\n customFields\n }\n }\n\n program(id: $programId) {\n sharing {\n redirectUrl {\n url\n }\n }\n }\n\n tenant {\n emailAddress\n settings {\n companyName\n }\n }\n}\n";
|
|
3
3
|
export declare const rewardEmailQueryForNonReferralPrograms = "\n query ($userId:String!, $accountId:String!, $rewardId:ID!, $programId:ID!) {\n reward(id:$rewardId) {\n ...AllFlatRewardFields\n }\n user(id:$userId, accountId:$accountId) {\n firstName\n lastName\n customFields\n email:messageLink(programId:$programId,shareMedium:EMAIL)\n }\n\n program(id: $programId) {\n sharing {\n redirectUrl {\n url\n }\n }\n }\n\n tenant {\n emailAddress\n settings {\n companyName\n }\n }\n }\n\n fragment AllFlatRewardFields on FlatReward {\n type\n prettyValue\n value\n unit\n name\n dateGiven\n dateExpires\n dateCancelled\n rewardSource\n fuelTankCode\n fuelTankType\n currency\n programId\n programRewardKey\n }\n";
|
|
4
4
|
export declare const nonRewardEmailQueryForNonReferralPrograms = "\n query ($userId:String!, $accountId:String!, $programId:ID!) {\n user(id:$userId, accountId:$accountId) {\n firstName\n lastName\n customFields\n email:messageLink(programId:$programId,shareMedium:EMAIL)\n }\n\n program(id: $programId) {\n sharing {\n redirectUrl {\n url\n }\n }\n }\n\n tenant {\n emailAddress\n settings {\n companyName\n }\n }\n }\n";
|
|
5
5
|
export declare const rewardScheduleQuery: (emailKey: string) => string;
|
package/dist/queries.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rewardScheduleQuery = exports.nonRewardEmailQueryForNonReferralPrograms = exports.rewardEmailQueryForNonReferralPrograms = exports.nonRewardEmailQueryForReferralPrograms = exports.rewardEmailQuery = void 0;
|
|
4
4
|
exports.rewardEmailQuery = `
|
|
5
|
-
query ($userId:String!, $accountId:String!, $rewardId:ID!, $programId:ID!, $referralId: ID
|
|
5
|
+
query ($userId:String!, $accountId:String!, $rewardId:ID!, $programId:ID!, $referralId: ID!) {
|
|
6
6
|
reward(id:$rewardId) {
|
|
7
7
|
...AllFlatRewardFields
|
|
8
8
|
}
|
|
@@ -28,16 +28,6 @@ exports.rewardEmailQuery = `
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
userEvents(filter: {id_eq: $eventId}) @include(if: $fetchEvent) {
|
|
32
|
-
data {
|
|
33
|
-
id
|
|
34
|
-
dateReceived
|
|
35
|
-
dateTriggered
|
|
36
|
-
dateProcessed
|
|
37
|
-
fields
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
31
|
referral(id:$referralId) {
|
|
42
32
|
referrerUser{
|
|
43
33
|
firstName
|
|
@@ -78,7 +68,7 @@ exports.rewardEmailQuery = `
|
|
|
78
68
|
programRewardKey
|
|
79
69
|
}
|
|
80
70
|
`;
|
|
81
|
-
exports.nonRewardEmailQueryForReferralPrograms = `query ($userId:String!, $accountId:String!,$programId:ID!, $referralId: ID
|
|
71
|
+
exports.nonRewardEmailQueryForReferralPrograms = `query ($userId:String!, $accountId:String!,$programId:ID!, $referralId: ID!) {
|
|
82
72
|
user(id:$userId, accountId:$accountId) {
|
|
83
73
|
firstName
|
|
84
74
|
lastName
|
|
@@ -93,16 +83,6 @@ exports.nonRewardEmailQueryForReferralPrograms = `query ($userId:String!, $accou
|
|
|
93
83
|
fbmessenger: messageLink(programId:$programId,shareMedium:FBMESSENGER)
|
|
94
84
|
}
|
|
95
85
|
|
|
96
|
-
userEvents(filter: {id_eq: $eventId}) @include(if: $fetchEvent) {
|
|
97
|
-
data {
|
|
98
|
-
id
|
|
99
|
-
dateReceived
|
|
100
|
-
dateTriggered
|
|
101
|
-
dateProcessed
|
|
102
|
-
fields
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
86
|
referral(id:$referralId) {
|
|
107
87
|
referrerUser{
|
|
108
88
|
firstName
|
|
@@ -205,7 +185,7 @@ exports.nonRewardEmailQueryForNonReferralPrograms = `
|
|
|
205
185
|
}
|
|
206
186
|
`;
|
|
207
187
|
//context for reward schedule trigger
|
|
208
|
-
|
|
188
|
+
exports.rewardScheduleQuery = (emailKey) => {
|
|
209
189
|
const query = `query ProgramTrigger($programId: ID!) {
|
|
210
190
|
activeTrigger: activeProgramTrigger {
|
|
211
191
|
type
|
|
@@ -370,4 +350,3 @@ const rewardScheduleQuery = (emailKey) => {
|
|
|
370
350
|
}`;
|
|
371
351
|
return query;
|
|
372
352
|
};
|
|
373
|
-
exports.rewardScheduleQuery = rewardScheduleQuery;
|
package/dist/transaction.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ProgramTriggerBody } from "./types/rpc";
|
|
2
2
|
import { ProgramType, User } from "./types/saasquatch";
|
|
3
|
-
type TransactionContext = {
|
|
3
|
+
declare type TransactionContext = {
|
|
4
4
|
body: ProgramTriggerBody;
|
|
5
5
|
};
|
|
6
|
-
type ReferralRewardInput = {
|
|
6
|
+
declare type ReferralRewardInput = {
|
|
7
7
|
rewardKey: string;
|
|
8
8
|
user: User;
|
|
9
9
|
referralId: string;
|
|
@@ -87,12 +87,11 @@ export default class Transaction {
|
|
|
87
87
|
user: User;
|
|
88
88
|
rewardId?: string;
|
|
89
89
|
}): void;
|
|
90
|
-
generateReferralEmail({ emailKey, user, referralId, rewardId,
|
|
90
|
+
generateReferralEmail({ emailKey, user, referralId, rewardId, }: {
|
|
91
91
|
emailKey: string;
|
|
92
92
|
user: User;
|
|
93
93
|
referralId: string;
|
|
94
94
|
rewardId?: string;
|
|
95
|
-
eventId?: string;
|
|
96
95
|
}): void;
|
|
97
96
|
/**
|
|
98
97
|
* Generates both reward and email.
|
|
@@ -105,7 +104,7 @@ export default class Transaction {
|
|
|
105
104
|
/**
|
|
106
105
|
* Generates both reward and email for a referral.
|
|
107
106
|
*/
|
|
108
|
-
generateReferralRewardAndEmail({ emailKey, rewardKey, referralId, user, status, overrideProperties, dynamicProperties,
|
|
107
|
+
generateReferralRewardAndEmail({ emailKey, rewardKey, referralId, user, status, overrideProperties, dynamicProperties, }: {
|
|
109
108
|
emailKey: string;
|
|
110
109
|
rewardKey: string;
|
|
111
110
|
referralId: string;
|
|
@@ -113,7 +112,6 @@ export default class Transaction {
|
|
|
113
112
|
status?: string;
|
|
114
113
|
overrideProperties?: any;
|
|
115
114
|
dynamicProperties?: any;
|
|
116
|
-
eventId?: string;
|
|
117
115
|
}): void;
|
|
118
116
|
generateRefunds(): void;
|
|
119
117
|
/**
|
|
@@ -121,7 +119,7 @@ export default class Transaction {
|
|
|
121
119
|
*/
|
|
122
120
|
toJson(): {
|
|
123
121
|
mutations: any[];
|
|
124
|
-
programId:
|
|
122
|
+
programId: any;
|
|
125
123
|
analytics: any[];
|
|
126
124
|
};
|
|
127
125
|
}
|
package/dist/transaction.js
CHANGED
|
@@ -160,14 +160,12 @@ class Transaction {
|
|
|
160
160
|
};
|
|
161
161
|
this.mutations = [...this.mutations, newMutation];
|
|
162
162
|
}
|
|
163
|
-
generateReferralEmail({ emailKey, user, referralId, rewardId,
|
|
163
|
+
generateReferralEmail({ emailKey, user, referralId, rewardId, }) {
|
|
164
164
|
const variables = {
|
|
165
165
|
userId: user.id,
|
|
166
166
|
accountId: user.accountId,
|
|
167
167
|
programId: this.context.body.program.id,
|
|
168
168
|
referralId: referralId,
|
|
169
|
-
eventId: eventId,
|
|
170
|
-
fetchEvent: !!eventId,
|
|
171
169
|
};
|
|
172
170
|
const queryVariables = rewardId ? Object.assign(Object.assign({}, variables), { rewardId }) : variables;
|
|
173
171
|
const newMutation = {
|
|
@@ -200,7 +198,7 @@ class Transaction {
|
|
|
200
198
|
/**
|
|
201
199
|
* Generates both reward and email for a referral.
|
|
202
200
|
*/
|
|
203
|
-
generateReferralRewardAndEmail({ emailKey, rewardKey, referralId, user, status, overrideProperties, dynamicProperties,
|
|
201
|
+
generateReferralRewardAndEmail({ emailKey, rewardKey, referralId, user, status, overrideProperties, dynamicProperties, }) {
|
|
204
202
|
const { rewardId } = this.generateReferralReward({
|
|
205
203
|
rewardKey,
|
|
206
204
|
referralId,
|
|
@@ -211,13 +209,7 @@ class Transaction {
|
|
|
211
209
|
overrideProperties,
|
|
212
210
|
dynamicProperties,
|
|
213
211
|
});
|
|
214
|
-
this.generateReferralEmail({
|
|
215
|
-
emailKey,
|
|
216
|
-
user,
|
|
217
|
-
referralId,
|
|
218
|
-
rewardId,
|
|
219
|
-
eventId,
|
|
220
|
-
});
|
|
212
|
+
this.generateReferralEmail({ emailKey, user, referralId, rewardId });
|
|
221
213
|
}
|
|
222
214
|
generateRefunds() {
|
|
223
215
|
const refundEvents = (this.events || []).filter((e) => e.key === "refund" &&
|
package/dist/trigger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProgramTriggerResult, ProgramTriggerBody, ProgramIntrospectionBody, ProgramValidationBody, ProgramVariableSchemaRequestBody, Program } from "./types/rpc";
|
|
2
2
|
/**
|
|
3
3
|
* Triggers the program and returns the result (JSON + HTTP code)
|
|
4
4
|
*
|
package/dist/trigger.js
CHANGED
|
@@ -3,26 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.triggerProgram =
|
|
7
|
-
const logger_1 = require("@saasquatch/logger");
|
|
6
|
+
exports.triggerProgram = void 0;
|
|
8
7
|
const transaction_1 = __importDefault(require("./transaction"));
|
|
9
|
-
|
|
10
|
-
const stack = typeof e === "object" && e !== null && "stack" in e ? e.stack : undefined;
|
|
11
|
-
const message = typeof e === "object" && e !== null && "message" in e
|
|
12
|
-
? e.message
|
|
13
|
-
: undefined;
|
|
14
|
-
const errorMes = {
|
|
15
|
-
error: `An error occurred in a webtask (${triggerType})`,
|
|
16
|
-
// consider not returning stack trace for security reasons
|
|
17
|
-
message: typeof e === "object" && e !== null && "stack" in e ? e.stack : undefined,
|
|
18
|
-
};
|
|
19
|
-
(0, logger_1.getLogger)("program-boilerplate").error({
|
|
20
|
-
message: errorMes.error,
|
|
21
|
-
["error.message"]: message,
|
|
22
|
-
["error.stack"]: stack,
|
|
23
|
-
});
|
|
24
|
-
return errorMes;
|
|
25
|
-
}
|
|
8
|
+
const logger_1 = require("@saasquatch/logger");
|
|
26
9
|
/**
|
|
27
10
|
* Triggers the program and returns the result (JSON + HTTP code)
|
|
28
11
|
*
|
|
@@ -57,13 +40,14 @@ function triggerProgram(body, program = {}) {
|
|
|
57
40
|
return handleProgramVariableSchemaRequest(body, program);
|
|
58
41
|
default:
|
|
59
42
|
const message = `Unrecognized messageType ${body.messageType}`;
|
|
60
|
-
|
|
43
|
+
logger_1.getLogger("program-boilerplate").warn(message);
|
|
61
44
|
return {
|
|
62
45
|
json: { message },
|
|
63
46
|
code: 501,
|
|
64
47
|
};
|
|
65
48
|
}
|
|
66
49
|
}
|
|
50
|
+
exports.triggerProgram = triggerProgram;
|
|
67
51
|
/**
|
|
68
52
|
* Trigger the program for the default cases
|
|
69
53
|
*
|
|
@@ -86,8 +70,20 @@ function handleProgramTrigger(body, program) {
|
|
|
86
70
|
};
|
|
87
71
|
}
|
|
88
72
|
catch (e) {
|
|
89
|
-
const errorMes =
|
|
90
|
-
|
|
73
|
+
const errorMes = {
|
|
74
|
+
error: "An error occurred in a webtask",
|
|
75
|
+
// consider not returning stack trace for security reasons
|
|
76
|
+
message: e.stack,
|
|
77
|
+
};
|
|
78
|
+
logger_1.getLogger("program-boilerplate").error({
|
|
79
|
+
message: errorMes.error,
|
|
80
|
+
["error.message"]: e.message,
|
|
81
|
+
["error.stack"]: e.stack,
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
json: errorMes,
|
|
85
|
+
code: 500,
|
|
86
|
+
};
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
/**
|
|
@@ -115,8 +111,20 @@ function handleProgramIntrospection(body, program) {
|
|
|
115
111
|
};
|
|
116
112
|
}
|
|
117
113
|
catch (e) {
|
|
118
|
-
const errorMes =
|
|
119
|
-
|
|
114
|
+
const errorMes = {
|
|
115
|
+
error: "An error occurred in a webtask",
|
|
116
|
+
// consider not returning stack trace for security reasons
|
|
117
|
+
message: e.stack,
|
|
118
|
+
};
|
|
119
|
+
logger_1.getLogger("program-boilerplate").error({
|
|
120
|
+
message: "Error ocurred in a webtask",
|
|
121
|
+
["error.message"]: e.message,
|
|
122
|
+
["error.stack"]: e.stack,
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
json: errorMes,
|
|
126
|
+
code: 500,
|
|
127
|
+
};
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
130
|
/**
|
|
@@ -173,7 +181,15 @@ function handleProgramVariableSchemaRequest(body, program) {
|
|
|
173
181
|
newSchema = handleSchemaRequest(schema, triggerType, scheduleKey);
|
|
174
182
|
}
|
|
175
183
|
catch (e) {
|
|
176
|
-
|
|
184
|
+
const errorMes = {
|
|
185
|
+
error: "An error occurred in a webtask (PROGRAM_TRIGGER_VARIABLES_SCHEMA_REQUEST)",
|
|
186
|
+
message: e.stack,
|
|
187
|
+
};
|
|
188
|
+
logger_1.getLogger("program-boilerplate").error({
|
|
189
|
+
message: errorMes.error,
|
|
190
|
+
["error.message"]: e.message,
|
|
191
|
+
["error.stack"]: e.stack,
|
|
192
|
+
});
|
|
177
193
|
}
|
|
178
194
|
if (!newSchema) {
|
|
179
195
|
return {
|
package/dist/types/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -15,23 +11,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
11
|
}) : function(o, v) {
|
|
16
12
|
o["default"] = v;
|
|
17
13
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
35
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
22
|
exports.saasquatch = exports.rpc = void 0;
|
|
37
23
|
const rpc = __importStar(require("./rpc"));
|
package/dist/types/rpc.d.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import { ProgramTemplateBuilder } from "@saasquatch/schema/types/ProgramTemplate";
|
|
2
2
|
import Transaction from "../transaction";
|
|
3
|
-
import { Referral, RSJsonNode, User, UserEvent } from "./saasquatch";
|
|
4
3
|
/********************************************************/
|
|
5
4
|
/********************************************************/
|
|
6
5
|
/**
|
|
7
6
|
* The different trigger handlers the programs can export
|
|
8
7
|
*/
|
|
9
|
-
export type
|
|
10
|
-
/**
|
|
11
|
-
* The different trigger handlers the programs can export
|
|
12
|
-
*/
|
|
13
|
-
export type TriggerType = ActiveTriggerType | ("PROGRAM_INTROSPECTION" | "PROGRAM_VALIDATION" | "PROGRAM_TRIGGER_VARIABLES_SCHEMA_REQUEST");
|
|
8
|
+
export declare type TriggerType = "AFTER_USER_CREATED_OR_UPDATED" | "AFTER_USER_EVENT_PROCESSED" | "REFERRAL" | "PROGRAM_INTROSPECTION" | "SCHEDULED" | "REWARD_SCHEDULED" | "PROGRAM_VALIDATION" | "PROGRAM_TRIGGER_VARIABLES_SCHEMA_REQUEST";
|
|
14
9
|
/**
|
|
15
10
|
* The Program type
|
|
16
11
|
*/
|
|
17
|
-
export type Program = {
|
|
12
|
+
export declare type Program = {
|
|
18
13
|
AFTER_USER_CREATED_OR_UPDATED?: ProgramTriggerHandler;
|
|
19
14
|
AFTER_USER_EVENT_PROCESSED?: ProgramTriggerHandler;
|
|
20
15
|
REFERRAL?: ProgramTriggerHandler;
|
|
@@ -27,24 +22,13 @@ export type Program = {
|
|
|
27
22
|
/********************************************************/
|
|
28
23
|
/********************************************************/
|
|
29
24
|
/**
|
|
30
|
-
* A JSON request body for the PROGRAM_TRIGGER case.
|
|
25
|
+
* A JSON request body for the PROGRAM_TRIGGER case. This type
|
|
26
|
+
* may not be complete.
|
|
31
27
|
*/
|
|
32
|
-
export type ProgramTriggerBody = {
|
|
28
|
+
export declare type ProgramTriggerBody = {
|
|
33
29
|
messageType: "PROGRAM_TRIGGER";
|
|
34
|
-
activeTrigger:
|
|
35
|
-
|
|
36
|
-
time: number;
|
|
37
|
-
user: User;
|
|
38
|
-
previous?: User;
|
|
39
|
-
events?: UserEvent[];
|
|
40
|
-
referral?: Referral;
|
|
41
|
-
[key: string]: any;
|
|
42
|
-
};
|
|
43
|
-
program: {
|
|
44
|
-
id: string;
|
|
45
|
-
rules: RSJsonNode;
|
|
46
|
-
templateId: string;
|
|
47
|
-
};
|
|
30
|
+
activeTrigger: any;
|
|
31
|
+
program: any;
|
|
48
32
|
tenant: {
|
|
49
33
|
impactBrandId: string | undefined | null;
|
|
50
34
|
settings: {
|
|
@@ -53,7 +37,7 @@ export type ProgramTriggerBody = {
|
|
|
53
37
|
};
|
|
54
38
|
ids: string[];
|
|
55
39
|
};
|
|
56
|
-
type TenantInfo = {
|
|
40
|
+
declare type TenantInfo = {
|
|
57
41
|
tenantAlias: string;
|
|
58
42
|
featureFlags?: string[] | null;
|
|
59
43
|
isLiveMode: boolean;
|
|
@@ -61,7 +45,7 @@ type TenantInfo = {
|
|
|
61
45
|
/**
|
|
62
46
|
* A JSON request body for the PROGRAM_INTROSPECTION case
|
|
63
47
|
*/
|
|
64
|
-
export type ProgramIntrospectionBody = {
|
|
48
|
+
export declare type ProgramIntrospectionBody = {
|
|
65
49
|
messageType: "PROGRAM_INTROSPECTION";
|
|
66
50
|
template: any;
|
|
67
51
|
rules: any;
|
|
@@ -73,7 +57,7 @@ export type ProgramIntrospectionBody = {
|
|
|
73
57
|
* to be validated along with the result of the graphql query
|
|
74
58
|
* associated with the requirement
|
|
75
59
|
*/
|
|
76
|
-
export type ValidationRequest = {
|
|
60
|
+
export declare type ValidationRequest = {
|
|
77
61
|
key: string;
|
|
78
62
|
queryResult: any;
|
|
79
63
|
};
|
|
@@ -81,14 +65,14 @@ export type ValidationRequest = {
|
|
|
81
65
|
* The program information included by the backend for validation
|
|
82
66
|
* requests
|
|
83
67
|
*/
|
|
84
|
-
export type ValidationProgramField = {
|
|
68
|
+
export declare type ValidationProgramField = {
|
|
85
69
|
id: string;
|
|
86
70
|
rules: any;
|
|
87
71
|
};
|
|
88
72
|
/**
|
|
89
73
|
* A JSON request body for the PROGRAM_VALIDATION case
|
|
90
74
|
*/
|
|
91
|
-
export type ProgramValidationBody = {
|
|
75
|
+
export declare type ProgramValidationBody = {
|
|
92
76
|
messageType: "PROGRAM_VALIDATION";
|
|
93
77
|
validationRequests: ValidationRequest[];
|
|
94
78
|
program: ValidationProgramField;
|
|
@@ -98,7 +82,7 @@ export type ProgramValidationBody = {
|
|
|
98
82
|
* The program information provided by the backend for
|
|
99
83
|
* requesting custom schema
|
|
100
84
|
*/
|
|
101
|
-
export type ProgramVariableSchemaRequestBody = {
|
|
85
|
+
export declare type ProgramVariableSchemaRequestBody = {
|
|
102
86
|
messageType: "PROGRAM_TRIGGER_VARIABLES_SCHEMA_REQUEST";
|
|
103
87
|
schema: any;
|
|
104
88
|
triggerType: TriggerType;
|
|
@@ -109,11 +93,11 @@ export type ProgramVariableSchemaRequestBody = {
|
|
|
109
93
|
/**
|
|
110
94
|
* Handler for the default program trigger cases
|
|
111
95
|
*/
|
|
112
|
-
export type ProgramTriggerHandler = (transaction: Transaction) => void;
|
|
96
|
+
export declare type ProgramTriggerHandler = (transaction: Transaction) => void;
|
|
113
97
|
/**
|
|
114
98
|
* Output of program introspection
|
|
115
99
|
*/
|
|
116
|
-
export type ProgramIntrospectionResponse = ProgramTemplateBuilder | {
|
|
100
|
+
export declare type ProgramIntrospectionResponse = ProgramTemplateBuilder | {
|
|
117
101
|
template: ProgramTemplateBuilder;
|
|
118
102
|
errors?: {
|
|
119
103
|
key: string;
|
|
@@ -124,7 +108,7 @@ export type ProgramIntrospectionResponse = ProgramTemplateBuilder | {
|
|
|
124
108
|
/**
|
|
125
109
|
* Introspection handler
|
|
126
110
|
*/
|
|
127
|
-
export type ProgramIntrospectionHandler = (template: ProgramTemplateBuilder, rules: any, program: any, tenant: TenantInfo) => ProgramIntrospectionResponse;
|
|
111
|
+
export declare type ProgramIntrospectionHandler = (template: ProgramTemplateBuilder, rules: any, program: any, tenant: TenantInfo) => ProgramIntrospectionResponse;
|
|
128
112
|
/**
|
|
129
113
|
* Handler for an individual program requirement validation.
|
|
130
114
|
* Handlers will be exported as key-value pairs in the
|
|
@@ -133,13 +117,13 @@ export type ProgramIntrospectionHandler = (template: ProgramTemplateBuilder, rul
|
|
|
133
117
|
* that will be used to compute the `queryResult` parameter for this
|
|
134
118
|
* function.
|
|
135
119
|
*/
|
|
136
|
-
export type RequirementValidationHandler = (queryResult: any, program: ValidationProgramField, time: number) => RequirementValidationResult[];
|
|
137
|
-
export type ProgramVariableSchemaHandler = (schema: any, triggerType: TriggerType, scheduleKey?: string) => ProgramVariableSchemaResult;
|
|
120
|
+
export declare type RequirementValidationHandler = (queryResult: any, program: ValidationProgramField, time: number) => RequirementValidationResult[];
|
|
121
|
+
export declare type ProgramVariableSchemaHandler = (schema: any, triggerType: TriggerType, scheduleKey?: string) => ProgramVariableSchemaResult;
|
|
138
122
|
/**
|
|
139
123
|
* Key-value list of validation functions to be exported by
|
|
140
124
|
* the program
|
|
141
125
|
*/
|
|
142
|
-
type ProgramValidationFunctions = {
|
|
126
|
+
declare type ProgramValidationFunctions = {
|
|
143
127
|
[key: string]: RequirementValidationHandler;
|
|
144
128
|
};
|
|
145
129
|
/********************************************************/
|
|
@@ -150,14 +134,14 @@ type ProgramValidationFunctions = {
|
|
|
150
134
|
* calculated by the boilerplate depending on the result
|
|
151
135
|
* of the trigger.
|
|
152
136
|
*/
|
|
153
|
-
export type ProgramTriggerResult = {
|
|
137
|
+
export declare type ProgramTriggerResult = {
|
|
154
138
|
json: any;
|
|
155
139
|
code: number;
|
|
156
140
|
};
|
|
157
141
|
/**
|
|
158
142
|
* A result for an individual program requirement check
|
|
159
143
|
*/
|
|
160
|
-
export type RequirementValidationResult = {
|
|
144
|
+
export declare type RequirementValidationResult = {
|
|
161
145
|
message: string;
|
|
162
146
|
longDescription: string;
|
|
163
147
|
status: "ERROR" | "WARN" | "SUCCESS";
|
|
@@ -167,11 +151,11 @@ export type RequirementValidationResult = {
|
|
|
167
151
|
* The key provided here corresponds to a key from the
|
|
168
152
|
* `ProgramRequirement` type from below.
|
|
169
153
|
*/
|
|
170
|
-
export type ValidationResult = {
|
|
154
|
+
export declare type ValidationResult = {
|
|
171
155
|
key: string;
|
|
172
156
|
results: RequirementValidationResult[];
|
|
173
157
|
};
|
|
174
|
-
export type ProgramVariableSchemaResult = {
|
|
158
|
+
export declare type ProgramVariableSchemaResult = {
|
|
175
159
|
schema: any;
|
|
176
160
|
};
|
|
177
161
|
/********************************************************/
|
|
@@ -179,7 +163,7 @@ export type ProgramVariableSchemaResult = {
|
|
|
179
163
|
/**
|
|
180
164
|
* A program requirement
|
|
181
165
|
*/
|
|
182
|
-
export type ProgramRequirement = {
|
|
166
|
+
export declare type ProgramRequirement = {
|
|
183
167
|
key: string;
|
|
184
168
|
name: string;
|
|
185
169
|
description: string;
|
|
@@ -189,12 +173,4 @@ export type ProgramRequirement = {
|
|
|
189
173
|
[key: string]: any;
|
|
190
174
|
};
|
|
191
175
|
};
|
|
192
|
-
export type TriggerSchemaObject = {
|
|
193
|
-
type: ProgramTriggerBody["activeTrigger"]["type"];
|
|
194
|
-
time: ProgramTriggerBody["activeTrigger"]["time"];
|
|
195
|
-
user: ProgramTriggerBody["activeTrigger"]["user"];
|
|
196
|
-
previous?: User;
|
|
197
|
-
event?: UserEvent;
|
|
198
|
-
referral?: Referral;
|
|
199
|
-
};
|
|
200
176
|
export {};
|
|
@@ -1,77 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A program type
|
|
3
3
|
*/
|
|
4
|
-
export type ProgramType = "ACQUISITION" | "LOYALTY" | "RETENTION";
|
|
5
|
-
export type RSJsonNode = any;
|
|
6
|
-
export type ProgramGoal = {
|
|
7
|
-
goalId: string;
|
|
8
|
-
programId?: string;
|
|
9
|
-
count: number;
|
|
10
|
-
firstDate: number;
|
|
11
|
-
lastDate: number;
|
|
12
|
-
};
|
|
4
|
+
export declare type ProgramType = "ACQUISITION" | "LOYALTY" | "RETENTION";
|
|
13
5
|
/**
|
|
14
|
-
*
|
|
6
|
+
* A referral. This type is not complete and is only
|
|
7
|
+
* used internally by the programs.
|
|
15
8
|
*/
|
|
16
|
-
export type
|
|
9
|
+
export declare type Referral = {
|
|
17
10
|
id: string;
|
|
18
|
-
accountId: string;
|
|
19
|
-
firstName?: string;
|
|
20
|
-
lastName?: string;
|
|
21
|
-
referredByReferral?: Referral;
|
|
22
|
-
programGoals: ProgramGoal[];
|
|
23
|
-
[key: string]: any;
|
|
24
11
|
};
|
|
25
12
|
/**
|
|
26
|
-
*
|
|
13
|
+
* A user. This type is not complete and is only
|
|
14
|
+
* used internally by the programs.
|
|
27
15
|
*/
|
|
28
|
-
export type
|
|
29
|
-
key: string;
|
|
16
|
+
export declare type User = {
|
|
30
17
|
id: string;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
dateTriggered?: number;
|
|
34
|
-
dateReceived?: number;
|
|
35
|
-
dateProcessed?: number;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Defined in core under ProgramTriggerQuery.graphql
|
|
39
|
-
*/
|
|
40
|
-
export type UserReward = {
|
|
41
|
-
id: string;
|
|
42
|
-
dateGiven?: number;
|
|
43
|
-
dateExpires?: number;
|
|
44
|
-
dateCancelled?: number;
|
|
45
|
-
programId?: string;
|
|
46
|
-
programRewardKey?: string;
|
|
47
|
-
referralId?: string;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Defined in core under ProgramTriggerQuery.graphql
|
|
51
|
-
*/
|
|
52
|
-
export type FraudFlag = "IP" | "EMAIL" | "NAME" | "RATE" | "DAILY_REFERRAL_REWARD_LIMIT" | "TEMP_EMAIL" | "BLOCKED_USER" | "BLOCKED_IP";
|
|
53
|
-
/**
|
|
54
|
-
* Defined in core under ProgramTriggerQuery.graphql
|
|
55
|
-
*/
|
|
56
|
-
export type Referral = {
|
|
57
|
-
id: string;
|
|
58
|
-
moderationStatus?: "PENDING" | "ACTIONED";
|
|
59
|
-
referrerModerationStatus?: "PENDING" | "APPROVED" | "DENIED";
|
|
60
|
-
referredModerationStatus?: "PENDING" | "APPROVED" | "DENIED";
|
|
61
|
-
dateReferralStarted?: number;
|
|
62
|
-
dateFraudChecksCompleted?: number;
|
|
63
|
-
dateConverted?: number;
|
|
64
|
-
fraudSignals?: any;
|
|
65
|
-
fraudFlags: {
|
|
66
|
-
type: FraudFlag;
|
|
67
|
-
message: string;
|
|
68
|
-
}[];
|
|
69
|
-
isFraudExempt: boolean;
|
|
70
|
-
referrerUser: User & {
|
|
71
|
-
rewards: {
|
|
72
|
-
totalCount: number;
|
|
73
|
-
data: UserReward[];
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
rewards: UserReward[];
|
|
18
|
+
accountId: string;
|
|
19
|
+
referredByReferral: Referral;
|
|
77
20
|
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ProgramTriggerBody
|
|
1
|
+
import { ProgramTriggerBody } from "./types/rpc";
|
|
2
2
|
import jsonata from "jsonata";
|
|
3
|
-
export type WebtaskConfig = {
|
|
3
|
+
export declare type WebtaskConfig = {
|
|
4
4
|
port: number;
|
|
5
5
|
webtaskName: string;
|
|
6
6
|
keepAliveTimeoutSeconds: number;
|
|
@@ -74,7 +74,7 @@ export declare function numToEquality(num: number): string;
|
|
|
74
74
|
* @param body the body of the trigger
|
|
75
75
|
* @return object[] The transformed data that is relevant for the trigger type
|
|
76
76
|
*/
|
|
77
|
-
export declare function getTriggerSchema(body: ProgramTriggerBody):
|
|
77
|
+
export declare function getTriggerSchema(body: ProgramTriggerBody): object[];
|
|
78
78
|
/**
|
|
79
79
|
* Parses JSONata expressions and finds user custom fields used in the expression(s)
|
|
80
80
|
*
|
package/dist/utils.js
CHANGED
|
@@ -3,14 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadStandardWebtaskConfig =
|
|
7
|
-
exports.setRewardSchedule = setRewardSchedule;
|
|
8
|
-
exports.getGoalAnalyticTimestamp = getGoalAnalyticTimestamp;
|
|
9
|
-
exports.inferType = inferType;
|
|
10
|
-
exports.numToEquality = numToEquality;
|
|
11
|
-
exports.getTriggerSchema = getTriggerSchema;
|
|
12
|
-
exports.getUserCustomFieldsFromJsonata = getUserCustomFieldsFromJsonata;
|
|
13
|
-
exports.getRewardUnitsFromJsonata = getRewardUnitsFromJsonata;
|
|
6
|
+
exports.getRewardUnitsFromJsonata = exports.getUserCustomFieldsFromJsonata = exports.getTriggerSchema = exports.numToEquality = exports.inferType = exports.getGoalAnalyticTimestamp = exports.setRewardSchedule = exports.loadStandardWebtaskConfig = void 0;
|
|
14
7
|
const queries_1 = require("./queries");
|
|
15
8
|
const jsonata_paths_extractor_1 = __importDefault(require("@saasquatch/jsonata-paths-extractor"));
|
|
16
9
|
function loadStandardWebtaskConfig() {
|
|
@@ -36,6 +29,7 @@ function loadStandardWebtaskConfig() {
|
|
|
36
29
|
terminationDelaySeconds,
|
|
37
30
|
};
|
|
38
31
|
}
|
|
32
|
+
exports.loadStandardWebtaskConfig = loadStandardWebtaskConfig;
|
|
39
33
|
/**
|
|
40
34
|
* Append a reward schedule to the template and return the new template
|
|
41
35
|
*
|
|
@@ -54,7 +48,7 @@ function setRewardSchedule({ template, expiryWarningDays, key, emailKey, periodI
|
|
|
54
48
|
filter: {
|
|
55
49
|
dateExpires_timeframe,
|
|
56
50
|
},
|
|
57
|
-
query:
|
|
51
|
+
query: queries_1.rewardScheduleQuery(emailKey),
|
|
58
52
|
periodInHours,
|
|
59
53
|
};
|
|
60
54
|
const currentSchedules = template.schedules;
|
|
@@ -68,6 +62,7 @@ function setRewardSchedule({ template, expiryWarningDays, key, emailKey, periodI
|
|
|
68
62
|
return template;
|
|
69
63
|
}
|
|
70
64
|
}
|
|
65
|
+
exports.setRewardSchedule = setRewardSchedule;
|
|
71
66
|
/**
|
|
72
67
|
* Returns the appropriate timestamp based on the trigger.
|
|
73
68
|
* If the trigger includes a purchase event, the timestamp
|
|
@@ -84,6 +79,7 @@ function getGoalAnalyticTimestamp(trigger) {
|
|
|
84
79
|
: undefined;
|
|
85
80
|
return purchaseEvent ? purchaseEvent.dateTriggered - 1 : trigger.time;
|
|
86
81
|
}
|
|
82
|
+
exports.getGoalAnalyticTimestamp = getGoalAnalyticTimestamp;
|
|
87
83
|
/**
|
|
88
84
|
* Translates a string type into its proper JavaScript type.
|
|
89
85
|
* Supports conversion to number, boolean, null and undefined values.
|
|
@@ -148,6 +144,7 @@ function inferType(val) {
|
|
|
148
144
|
return val;
|
|
149
145
|
}
|
|
150
146
|
}
|
|
147
|
+
exports.inferType = inferType;
|
|
151
148
|
/**
|
|
152
149
|
* Converts a number representation of a conversion operator set in program
|
|
153
150
|
* rules to a string that can be user in a GraphQL query
|
|
@@ -166,13 +163,13 @@ function numToEquality(num) {
|
|
|
166
163
|
return "eq";
|
|
167
164
|
}
|
|
168
165
|
}
|
|
166
|
+
exports.numToEquality = numToEquality;
|
|
169
167
|
/**
|
|
170
168
|
* Converts a trigger context into the relevant information for the specified trigger type.
|
|
171
169
|
* @param body the body of the trigger
|
|
172
170
|
* @return object[] The transformed data that is relevant for the trigger type
|
|
173
171
|
*/
|
|
174
172
|
function getTriggerSchema(body) {
|
|
175
|
-
var _a;
|
|
176
173
|
const activeTrigger = body.activeTrigger;
|
|
177
174
|
const triggerType = activeTrigger.type;
|
|
178
175
|
const standardData = {
|
|
@@ -190,7 +187,11 @@ function getTriggerSchema(body) {
|
|
|
190
187
|
Object.assign(Object.assign({}, standardData), { referral: activeTrigger.referral }),
|
|
191
188
|
];
|
|
192
189
|
case "AFTER_USER_EVENT_PROCESSED":
|
|
193
|
-
|
|
190
|
+
let contexts = [];
|
|
191
|
+
activeTrigger.events.forEach((event) => {
|
|
192
|
+
contexts.push(Object.assign(Object.assign({}, standardData), { event }));
|
|
193
|
+
});
|
|
194
|
+
return contexts;
|
|
194
195
|
case "SCHEDULED":
|
|
195
196
|
return [
|
|
196
197
|
Object.assign({}, standardData),
|
|
@@ -203,6 +204,7 @@ function getTriggerSchema(body) {
|
|
|
203
204
|
throw new Error("Trigger type did not match expected options");
|
|
204
205
|
}
|
|
205
206
|
}
|
|
207
|
+
exports.getTriggerSchema = getTriggerSchema;
|
|
206
208
|
/**
|
|
207
209
|
* Parses JSONata expressions and finds user custom fields used in the expression(s)
|
|
208
210
|
*
|
|
@@ -216,7 +218,7 @@ function getUserCustomFieldsFromJsonata(jsonataExpressions) {
|
|
|
216
218
|
}
|
|
217
219
|
for (const expression of jsonataExpressions) {
|
|
218
220
|
try {
|
|
219
|
-
const allPaths =
|
|
221
|
+
const allPaths = jsonata_paths_extractor_1.default(expression);
|
|
220
222
|
for (const path of allPaths) {
|
|
221
223
|
if (path.startsWith("/user/customFields/")) {
|
|
222
224
|
const key = path.split("/")[3];
|
|
@@ -242,6 +244,7 @@ function getUserCustomFieldsFromJsonata(jsonataExpressions) {
|
|
|
242
244
|
//dedup
|
|
243
245
|
return Array.from(new Set(userCustomFields));
|
|
244
246
|
}
|
|
247
|
+
exports.getUserCustomFieldsFromJsonata = getUserCustomFieldsFromJsonata;
|
|
245
248
|
function getRewardUnitsFromJsonata(expr) {
|
|
246
249
|
if (expr === undefined) {
|
|
247
250
|
return undefined;
|
|
@@ -261,3 +264,4 @@ function getRewardUnitsFromJsonata(expr) {
|
|
|
261
264
|
}
|
|
262
265
|
}
|
|
263
266
|
}
|
|
267
|
+
exports.getRewardUnitsFromJsonata = getRewardUnitsFromJsonata;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saasquatch/program-boilerplate",
|
|
3
|
-
"version": "3.10.1-
|
|
3
|
+
"version": "3.10.1-6",
|
|
4
4
|
"description": "Boilerplate for writing programs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist/"
|
|
8
8
|
],
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": "^
|
|
10
|
+
"node": "^18 || ^20 || ^22"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "tsc --declaration",
|
|
@@ -28,27 +28,27 @@
|
|
|
28
28
|
"source-map": "^0.7.4"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/express": "^4.17.
|
|
32
|
-
"@types/node": "^
|
|
31
|
+
"@types/express": "^4.17.11",
|
|
32
|
+
"@types/node": "^13.13.50",
|
|
33
33
|
"@types/supertest": "^2.0.11",
|
|
34
|
-
"jest": "^
|
|
35
|
-
"jest-cucumber": "^
|
|
34
|
+
"jest": "^26.6.3",
|
|
35
|
+
"jest-cucumber": "^3.0.1",
|
|
36
36
|
"prettier": "^2.2.1",
|
|
37
37
|
"source-map": "^0.7.4",
|
|
38
38
|
"supertest": "^6.1.3",
|
|
39
|
-
"ts-jest": "^
|
|
40
|
-
"ts-node": "^
|
|
39
|
+
"ts-jest": "^26.5.5",
|
|
40
|
+
"ts-node": "^9.1.1",
|
|
41
41
|
"typedoc": "^0.17.8",
|
|
42
|
-
"typescript": "^
|
|
42
|
+
"typescript": "^3.9.9"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@saasquatch/jsonata-paths-extractor": "^1.0.1",
|
|
46
|
-
"@saasquatch/logger": "^
|
|
46
|
+
"@saasquatch/logger": "^1.5.1",
|
|
47
47
|
"@saasquatch/schema": "^2.0.0",
|
|
48
48
|
"bson-objectid": "^1.3.1",
|
|
49
49
|
"compression": "^1.7.4",
|
|
50
50
|
"express": "^4.17.1",
|
|
51
51
|
"jsonata": "^1.8.4",
|
|
52
|
-
"winston": "^3.
|
|
52
|
+
"winston": "^3.3.3"
|
|
53
53
|
}
|
|
54
54
|
}
|