@saasquatch/program-boilerplate 3.5.11 → 3.5.12-2
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 +3 -3
- package/dist/index.js +3 -1
- package/dist/utils.d.ts +11 -4
- package/dist/utils.js +46 -5
- package/package.json +2 -1
- package/CHANGELOG.md +0 -28
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";
|
|
@@ -8,9 +8,9 @@ import * as types from "./types";
|
|
|
8
8
|
import { Program, ProgramRequirement, RequirementValidationResult, ValidationProgramField, ProgramTriggerBody } from "./types/rpc";
|
|
9
9
|
import { timeboxExpression, safeJsonata } from "./jsonata";
|
|
10
10
|
import { ProgramType } from "./types/saasquatch";
|
|
11
|
-
import { inferType, getGoalAnalyticTimestamp, setRewardSchedule, numToEquality, getTriggerSchema } from "./utils";
|
|
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, 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.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");
|
|
@@ -25,6 +26,7 @@ Object.defineProperty(exports, "getGoalAnalyticTimestamp", { enumerable: true, g
|
|
|
25
26
|
Object.defineProperty(exports, "setRewardSchedule", { enumerable: true, get: function () { return utils_1.setRewardSchedule; } });
|
|
26
27
|
Object.defineProperty(exports, "numToEquality", { enumerable: true, get: function () { return utils_1.numToEquality; } });
|
|
27
28
|
Object.defineProperty(exports, "getTriggerSchema", { enumerable: true, get: function () { return utils_1.getTriggerSchema; } });
|
|
29
|
+
Object.defineProperty(exports, "getUserCustomFieldsFromJsonata", { enumerable: true, get: function () { return utils_1.getUserCustomFieldsFromJsonata; } });
|
|
28
30
|
/**
|
|
29
31
|
* Returns an express server that serves the provided handlers
|
|
30
32
|
* as a program
|
package/dist/utils.d.ts
CHANGED
|
@@ -56,14 +56,21 @@ 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
|
+
/**
|
|
71
|
+
* Parses JSONata expressions and finds user custom fields used in the expression(s)
|
|
72
|
+
*
|
|
73
|
+
* @param jsonataExpressions string | string[] input JSONata expression(s)
|
|
74
|
+
* @returns string[] a deduplicated list of user custom fields found in the input expression(s)
|
|
75
|
+
*/
|
|
76
|
+
export declare function getUserCustomFieldsFromJsonata(jsonataExpressions: string | string[]): string[];
|
package/dist/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTriggerSchema = exports.numToEquality = exports.inferType = exports.getGoalAnalyticTimestamp = exports.setRewardSchedule = void 0;
|
|
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_paths_extractor_1 = require("@saasquatch/jsonata-paths-extractor");
|
|
5
6
|
/**
|
|
6
7
|
* Append a reward schedule to the template and return the new template
|
|
7
8
|
*
|
|
@@ -119,8 +120,8 @@ function inferType(val) {
|
|
|
119
120
|
exports.inferType = inferType;
|
|
120
121
|
/**
|
|
121
122
|
* Converts a number representation of a conversion operator set in program
|
|
122
|
-
* rules to a string that can be user in a
|
|
123
|
-
* @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
|
|
124
125
|
* @return {string} the string representation of the conversion operator
|
|
125
126
|
*/
|
|
126
127
|
function numToEquality(num) {
|
|
@@ -137,9 +138,9 @@ function numToEquality(num) {
|
|
|
137
138
|
}
|
|
138
139
|
exports.numToEquality = numToEquality;
|
|
139
140
|
/**
|
|
140
|
-
* Converts a trigger context into the
|
|
141
|
+
* Converts a trigger context into the relevant information for the specified trigger type.
|
|
141
142
|
* @param body the body of the trigger
|
|
142
|
-
* @return object[] The
|
|
143
|
+
* @return object[] The transformed data that is relevant for the trigger type
|
|
143
144
|
*/
|
|
144
145
|
function getTriggerSchema(body) {
|
|
145
146
|
const activeTrigger = body.activeTrigger;
|
|
@@ -182,3 +183,43 @@ function getTriggerSchema(body) {
|
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
exports.getTriggerSchema = getTriggerSchema;
|
|
186
|
+
/**
|
|
187
|
+
* Parses JSONata expressions and finds user custom fields used in the expression(s)
|
|
188
|
+
*
|
|
189
|
+
* @param jsonataExpressions string | string[] input JSONata expression(s)
|
|
190
|
+
* @returns string[] a deduplicated list of user custom fields found in the input expression(s)
|
|
191
|
+
*/
|
|
192
|
+
function getUserCustomFieldsFromJsonata(jsonataExpressions) {
|
|
193
|
+
let userCustomFields = [];
|
|
194
|
+
if (typeof jsonataExpressions === "string") {
|
|
195
|
+
jsonataExpressions = [jsonataExpressions];
|
|
196
|
+
}
|
|
197
|
+
for (const expression of jsonataExpressions) {
|
|
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
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//dedup
|
|
223
|
+
return Array.from(new Set(userCustomFields));
|
|
224
|
+
}
|
|
225
|
+
exports.getUserCustomFieldsFromJsonata = getUserCustomFieldsFromJsonata;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saasquatch/program-boilerplate",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.12-2",
|
|
4
4
|
"description": "Boilerplate for writing programs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"typescript": "^3.9.9"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@saasquatch/jsonata-paths-extractor": "^1.0.0-0",
|
|
35
36
|
"bson-objectid": "^1.3.1",
|
|
36
37
|
"compression": "^1.7.4",
|
|
37
38
|
"express": "^4.17.1",
|
package/CHANGELOG.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
## [Unreleased]
|
|
9
|
-
|
|
10
|
-
## [3.5.11] - 2021-12-1
|
|
11
|
-
|
|
12
|
-
- Set default payload size limit to 1mb
|
|
13
|
-
- Added MAX_PAYLOAD_SIZE env var to allow easier configuration
|
|
14
|
-
- Fixes payload too large error that can occur during introspection
|
|
15
|
-
|
|
16
|
-
## [3.5.9] - 2021-10-20
|
|
17
|
-
|
|
18
|
-
### Added
|
|
19
|
-
|
|
20
|
-
- Added CHANGELOG.md
|
|
21
|
-
- Added referrer/referred emails to the email context query so they can be used in email templates
|
|
22
|
-
|
|
23
|
-
### Changed
|
|
24
|
-
|
|
25
|
-
### Removed
|
|
26
|
-
|
|
27
|
-
[unreleased]: https://github.com/saasquatch/program-tools/compare/%40saasquatch/program-boilerplate%403.5.9...HEAD
|
|
28
|
-
[3.5.9]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch/program-boilerplate%403.5.9
|