@saasquatch/program-boilerplate 3.5.11 → 3.5.12-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/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
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,9 @@
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 = require("jsonata");
6
+ const jsonata_paths_extractor_1 = require("@saasquatch/jsonata-paths-extractor");
5
7
  /**
6
8
  * Append a reward schedule to the template and return the new template
7
9
  *
@@ -182,3 +184,47 @@ function getTriggerSchema(body) {
182
184
  }
183
185
  }
184
186
  exports.getTriggerSchema = getTriggerSchema;
187
+ /**
188
+ * Parses JSONata expressions and finds user custom fields used in the expression(s)
189
+ *
190
+ * @param jsonataExpressions string | string[] input JSONata expression(s)
191
+ * @returns string[] a deduplicated list of user custom fields found in the input expression(s)
192
+ */
193
+ function getUserCustomFieldsFromJsonata(jsonataExpressions) {
194
+ let userCustomFields = [];
195
+ const getJsonataASTSafe = (expression) => {
196
+ try {
197
+ return jsonata(expression).ast();
198
+ }
199
+ catch (e) { }
200
+ };
201
+ if (typeof jsonataExpressions === "string") {
202
+ jsonataExpressions = [jsonataExpressions];
203
+ }
204
+ for (const expression of jsonataExpressions) {
205
+ const ast = getJsonataASTSafe(expression);
206
+ if (!ast)
207
+ continue;
208
+ const allPaths = jsonata_paths_extractor_1.default(ast);
209
+ for (const path of allPaths) {
210
+ if (path.startsWith("/user/customFields/")) {
211
+ const key = path.split("/")[3];
212
+ if (key)
213
+ userCustomFields.push(key);
214
+ }
215
+ if (path.startsWith("/user/referredByReferral/referrerUser/customFields/")) {
216
+ const key = path.split("/")[5];
217
+ if (key)
218
+ userCustomFields.push(key);
219
+ }
220
+ if (path.startsWith("/referral/referrerUser/customFields/")) {
221
+ const key = path.split("/")[4];
222
+ if (key)
223
+ userCustomFields.push(key);
224
+ }
225
+ }
226
+ }
227
+ //dedup
228
+ return Array.from(new Set(userCustomFields));
229
+ }
230
+ exports.getUserCustomFieldsFromJsonata = getUserCustomFieldsFromJsonata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saasquatch/program-boilerplate",
3
- "version": "3.5.11",
3
+ "version": "3.5.12-0",
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": "^0.1.0-1",
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