@saasquatch/program-boilerplate 3.5.9 → 3.5.12-1
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/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +42 -1
- package/package.json +2 -2
- package/CHANGELOG.md +0 -22
package/dist/index.d.ts
CHANGED
|
@@ -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, 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,6 +1,6 @@
|
|
|
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.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; } });
|
|
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "getGoalAnalyticTimestamp", { enumerable: true, g
|
|
|
25
25
|
Object.defineProperty(exports, "setRewardSchedule", { enumerable: true, get: function () { return utils_1.setRewardSchedule; } });
|
|
26
26
|
Object.defineProperty(exports, "numToEquality", { enumerable: true, get: function () { return utils_1.numToEquality; } });
|
|
27
27
|
Object.defineProperty(exports, "getTriggerSchema", { enumerable: true, get: function () { return utils_1.getTriggerSchema; } });
|
|
28
|
+
Object.defineProperty(exports, "getUserCustomFieldsFromJsonata", { enumerable: true, get: function () { return utils_1.getUserCustomFieldsFromJsonata; } });
|
|
28
29
|
/**
|
|
29
30
|
* Returns an express server that serves the provided handlers
|
|
30
31
|
* as a program
|
|
@@ -34,10 +35,9 @@ Object.defineProperty(exports, "getTriggerSchema", { enumerable: true, get: func
|
|
|
34
35
|
* @return {Object} The express server
|
|
35
36
|
*/
|
|
36
37
|
function webtask(program = {}) {
|
|
37
|
-
const bodyParser = require("body-parser");
|
|
38
38
|
const compression = require("compression");
|
|
39
39
|
const app = express();
|
|
40
|
-
app.use(
|
|
40
|
+
app.use(express.json({ limit: process.env.MAX_PAYLOAD_SIZE || "1mb" }));
|
|
41
41
|
app.use(compression());
|
|
42
42
|
// Enforce HTTPS. The server does not redirect http -> https
|
|
43
43
|
// because OWASP advises not to
|
package/dist/utils.d.ts
CHANGED
|
@@ -67,3 +67,10 @@ export declare function numToEquality(num: number): string;
|
|
|
67
67
|
* @return object[] The tranformed data that is relavent 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
|
*
|
|
@@ -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-1",
|
|
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
|
-
"
|
|
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",
|
package/CHANGELOG.md
DELETED
|
@@ -1,22 +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.9] - 2021-10-20
|
|
11
|
-
|
|
12
|
-
### Added
|
|
13
|
-
|
|
14
|
-
- Added CHANGELOG.md
|
|
15
|
-
- Added referrer/referred emails to the email context query so they can be used in email templates
|
|
16
|
-
|
|
17
|
-
### Changed
|
|
18
|
-
|
|
19
|
-
### Removed
|
|
20
|
-
|
|
21
|
-
[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/%40saasquatch/program-boilerplate%403.5.9...HEAD
|
|
22
|
-
[3.5.9]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/%40saasquatch/program-boilerplate%403.5.9
|