@saasquatch/program-boilerplate 3.5.12-0 → 3.6.0-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/conversion.d.ts +10 -0
- package/dist/conversion.js +36 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.js +25 -30
- package/package.json +2 -2
package/dist/conversion.d.ts
CHANGED
|
@@ -38,6 +38,16 @@ declare type UserQueryResult = {
|
|
|
38
38
|
* The value of a rule
|
|
39
39
|
*/
|
|
40
40
|
declare type RuleValue = string | boolean | number;
|
|
41
|
+
/**
|
|
42
|
+
* Checks whether any of the edge trigger conditions are met given
|
|
43
|
+
* a list of fields to check and the current context.
|
|
44
|
+
*
|
|
45
|
+
* @param {string[] | undefined} fields The list of edge trigger fields
|
|
46
|
+
* @param {any} activeTrigger The current program `activeTrigger`
|
|
47
|
+
*
|
|
48
|
+
* @return {boolean} Whether any of the edge fields have changed
|
|
49
|
+
*/
|
|
50
|
+
export declare function meetEdgeTriggerConditions(fields: string[] | undefined, activeTrigger: any): boolean;
|
|
41
51
|
/**
|
|
42
52
|
* @deprecated No longer in use, use JSONata expression and evaluation instead
|
|
43
53
|
* Checks if the customFields of the user meet every rule that defines customFields-based conversion
|
package/dist/conversion.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* @module conversion
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.meetEventTriggerRules = exports.meetCustomFieldRules = void 0;
|
|
6
|
+
exports.meetEventTriggerRules = exports.meetCustomFieldRules = exports.meetEdgeTriggerConditions = void 0;
|
|
7
|
+
const assert = require("assert");
|
|
8
|
+
const jsonata = require("jsonata");
|
|
7
9
|
//functions
|
|
8
10
|
/**
|
|
9
11
|
* Turns a string scalar into a Number, Boolean or String
|
|
@@ -23,6 +25,39 @@ function parseValue(value) {
|
|
|
23
25
|
}
|
|
24
26
|
return value;
|
|
25
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether any of the edge trigger conditions are met given
|
|
30
|
+
* a list of fields to check and the current context.
|
|
31
|
+
*
|
|
32
|
+
* @param {string[] | undefined} fields The list of edge trigger fields
|
|
33
|
+
* @param {any} activeTrigger The current program `activeTrigger`
|
|
34
|
+
*
|
|
35
|
+
* @return {boolean} Whether any of the edge fields have changed
|
|
36
|
+
*/
|
|
37
|
+
function meetEdgeTriggerConditions(fields, activeTrigger) {
|
|
38
|
+
if (fields === undefined || fields.length === 0) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
for (const field of fields) {
|
|
42
|
+
if (!field.startsWith("user.")) {
|
|
43
|
+
// TODO: what to do here? this is probably some kind of error case
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const previousValue = jsonata(field.replace("user.", "previous.")).evaluate(activeTrigger);
|
|
47
|
+
const currentValue = jsonata(field).evaluate(activeTrigger);
|
|
48
|
+
try {
|
|
49
|
+
assert.deepStrictEqual(currentValue, previousValue);
|
|
50
|
+
// assertion passed -- field did not change
|
|
51
|
+
// continue on to other fields and see if any changed
|
|
52
|
+
}
|
|
53
|
+
catch (_e) {
|
|
54
|
+
// assertion failed -- field must have changed
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
exports.meetEdgeTriggerConditions = meetEdgeTriggerConditions;
|
|
26
61
|
/**
|
|
27
62
|
* Checks if the customFields of a user meet a certain customField-based conversion rule.
|
|
28
63
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as express from "express";
|
|
2
|
-
import { meetCustomFieldRules, meetEventTriggerRules } from "./conversion";
|
|
2
|
+
import { meetCustomFieldRules, meetEventTriggerRules, meetEdgeTriggerConditions } from "./conversion";
|
|
3
3
|
import { rewardEmailQuery } from "./queries";
|
|
4
4
|
import Transaction from "./transaction";
|
|
5
5
|
import { triggerProgram } from "./trigger";
|
|
@@ -10,7 +10,7 @@ import { timeboxExpression, safeJsonata } from "./jsonata";
|
|
|
10
10
|
import { ProgramType } from "./types/saasquatch";
|
|
11
11
|
import { inferType, getGoalAnalyticTimestamp, setRewardSchedule, numToEquality, getTriggerSchema, getUserCustomFieldsFromJsonata } from "./utils";
|
|
12
12
|
export { types };
|
|
13
|
-
export { Transaction, ProgramTriggerBody, Program, ProgramType, RequirementValidationResult, ProgramRequirement, ValidationProgramField, meetEventTriggerRules, meetCustomFieldRules, rewardEmailQuery, setRewardSchedule, getGoalAnalyticTimestamp, triggerProgram, inferType, numToEquality, getTriggerSchema, getUserCustomFieldsFromJsonata, timeboxExpression, safeJsonata, getLogger, setLogLevel, };
|
|
13
|
+
export { Transaction, ProgramTriggerBody, Program, ProgramType, RequirementValidationResult, ProgramRequirement, ValidationProgramField, meetEventTriggerRules, meetCustomFieldRules, meetEdgeTriggerConditions, rewardEmailQuery, setRewardSchedule, getGoalAnalyticTimestamp, triggerProgram, inferType, numToEquality, getTriggerSchema, getUserCustomFieldsFromJsonata, timeboxExpression, safeJsonata, getLogger, setLogLevel, };
|
|
14
14
|
/**
|
|
15
15
|
* Returns an express server that serves the provided handlers
|
|
16
16
|
* as a program
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.webtask = exports.setLogLevel = exports.getLogger = exports.safeJsonata = exports.timeboxExpression = exports.getUserCustomFieldsFromJsonata = exports.getTriggerSchema = exports.numToEquality = exports.inferType = exports.triggerProgram = exports.getGoalAnalyticTimestamp = exports.setRewardSchedule = exports.rewardEmailQuery = exports.meetCustomFieldRules = exports.meetEventTriggerRules = exports.Transaction = exports.types = void 0;
|
|
3
|
+
exports.webtask = exports.setLogLevel = exports.getLogger = exports.safeJsonata = exports.timeboxExpression = 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;
|
|
4
4
|
const express = require("express");
|
|
5
5
|
const conversion_1 = require("./conversion");
|
|
6
6
|
Object.defineProperty(exports, "meetCustomFieldRules", { enumerable: true, get: function () { return conversion_1.meetCustomFieldRules; } });
|
|
7
7
|
Object.defineProperty(exports, "meetEventTriggerRules", { enumerable: true, get: function () { return conversion_1.meetEventTriggerRules; } });
|
|
8
|
+
Object.defineProperty(exports, "meetEdgeTriggerConditions", { enumerable: true, get: function () { return conversion_1.meetEdgeTriggerConditions; } });
|
|
8
9
|
const queries_1 = require("./queries");
|
|
9
10
|
Object.defineProperty(exports, "rewardEmailQuery", { enumerable: true, get: function () { return queries_1.rewardEmailQuery; } });
|
|
10
11
|
const transaction_1 = require("./transaction");
|
package/dist/utils.d.ts
CHANGED
|
@@ -56,15 +56,15 @@ export declare function getGoalAnalyticTimestamp(trigger: any): number;
|
|
|
56
56
|
export declare function inferType(val: string): any;
|
|
57
57
|
/**
|
|
58
58
|
* Converts a number representation of a conversion operator set in program
|
|
59
|
-
* rules to a string that can be user in a
|
|
60
|
-
* @param num
|
|
59
|
+
* rules to a string that can be user in a GraphQL query
|
|
60
|
+
* @param {number} num conversion criteria set in a program
|
|
61
61
|
* @return {string} the string representation of the conversion operator
|
|
62
62
|
*/
|
|
63
63
|
export declare function numToEquality(num: number): string;
|
|
64
64
|
/**
|
|
65
|
-
* Converts a trigger context into the
|
|
65
|
+
* Converts a trigger context into the relevant information for the specified trigger type.
|
|
66
66
|
* @param body the body of the trigger
|
|
67
|
-
* @return object[] The
|
|
67
|
+
* @return object[] The transformed data that is relevant for the trigger type
|
|
68
68
|
*/
|
|
69
69
|
export declare function getTriggerSchema(body: ProgramTriggerBody): object[];
|
|
70
70
|
/**
|
package/dist/utils.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getUserCustomFieldsFromJsonata = exports.getTriggerSchema = exports.numToEquality = exports.inferType = exports.getGoalAnalyticTimestamp = exports.setRewardSchedule = void 0;
|
|
4
4
|
const queries_1 = require("./queries");
|
|
5
|
-
const jsonata = require("jsonata");
|
|
6
5
|
const jsonata_paths_extractor_1 = require("@saasquatch/jsonata-paths-extractor");
|
|
7
6
|
/**
|
|
8
7
|
* Append a reward schedule to the template and return the new template
|
|
@@ -121,8 +120,8 @@ function inferType(val) {
|
|
|
121
120
|
exports.inferType = inferType;
|
|
122
121
|
/**
|
|
123
122
|
* Converts a number representation of a conversion operator set in program
|
|
124
|
-
* rules to a string that can be user in a
|
|
125
|
-
* @param num
|
|
123
|
+
* rules to a string that can be user in a GraphQL query
|
|
124
|
+
* @param {number} num conversion criteria set in a program
|
|
126
125
|
* @return {string} the string representation of the conversion operator
|
|
127
126
|
*/
|
|
128
127
|
function numToEquality(num) {
|
|
@@ -139,9 +138,9 @@ function numToEquality(num) {
|
|
|
139
138
|
}
|
|
140
139
|
exports.numToEquality = numToEquality;
|
|
141
140
|
/**
|
|
142
|
-
* Converts a trigger context into the
|
|
141
|
+
* Converts a trigger context into the relevant information for the specified trigger type.
|
|
143
142
|
* @param body the body of the trigger
|
|
144
|
-
* @return object[] The
|
|
143
|
+
* @return object[] The transformed data that is relevant for the trigger type
|
|
145
144
|
*/
|
|
146
145
|
function getTriggerSchema(body) {
|
|
147
146
|
const activeTrigger = body.activeTrigger;
|
|
@@ -192,37 +191,33 @@ exports.getTriggerSchema = getTriggerSchema;
|
|
|
192
191
|
*/
|
|
193
192
|
function getUserCustomFieldsFromJsonata(jsonataExpressions) {
|
|
194
193
|
let userCustomFields = [];
|
|
195
|
-
const getJsonataASTSafe = (expression) => {
|
|
196
|
-
try {
|
|
197
|
-
return jsonata(expression).ast();
|
|
198
|
-
}
|
|
199
|
-
catch (e) { }
|
|
200
|
-
};
|
|
201
194
|
if (typeof jsonataExpressions === "string") {
|
|
202
195
|
jsonataExpressions = [jsonataExpressions];
|
|
203
196
|
}
|
|
204
197
|
for (const expression of jsonataExpressions) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
userCustomFields.push(key);
|
|
198
|
+
try {
|
|
199
|
+
const allPaths = jsonata_paths_extractor_1.default(expression);
|
|
200
|
+
for (const path of allPaths) {
|
|
201
|
+
if (path.startsWith("/user/customFields/")) {
|
|
202
|
+
const key = path.split("/")[3];
|
|
203
|
+
if (key)
|
|
204
|
+
userCustomFields.push(key);
|
|
205
|
+
}
|
|
206
|
+
if (path.startsWith("/user/referredByReferral/referrerUser/customFields/")) {
|
|
207
|
+
const key = path.split("/")[5];
|
|
208
|
+
if (key)
|
|
209
|
+
userCustomFields.push(key);
|
|
210
|
+
}
|
|
211
|
+
if (path.startsWith("/referral/referrerUser/customFields/")) {
|
|
212
|
+
const key = path.split("/")[4];
|
|
213
|
+
if (key)
|
|
214
|
+
userCustomFields.push(key);
|
|
215
|
+
}
|
|
224
216
|
}
|
|
225
217
|
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
226
221
|
}
|
|
227
222
|
//dedup
|
|
228
223
|
return Array.from(new Set(userCustomFields));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saasquatch/program-boilerplate",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0-0",
|
|
4
4
|
"description": "Boilerplate for writing programs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"typescript": "^3.9.9"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@saasquatch/jsonata-paths-extractor": "^
|
|
35
|
+
"@saasquatch/jsonata-paths-extractor": "^1.0.0-0",
|
|
36
36
|
"bson-objectid": "^1.3.1",
|
|
37
37
|
"compression": "^1.7.4",
|
|
38
38
|
"express": "^4.17.1",
|