@saasquatch/program-boilerplate 3.5.12-1 → 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.
@@ -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
@@ -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 graphQL query
60
- * @param num the conversion criteria set in a program
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 relavent information for the specified trigger type.
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 tranformed data that is relavent for the trigger type
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
@@ -120,8 +120,8 @@ function inferType(val) {
120
120
  exports.inferType = inferType;
121
121
  /**
122
122
  * Converts a number representation of a conversion operator set in program
123
- * rules to a string that can be user in a graphQL query
124
- * @param num the conversion criteria set in a program
123
+ * rules to a string that can be user in a GraphQL query
124
+ * @param {number} num conversion criteria set in a program
125
125
  * @return {string} the string representation of the conversion operator
126
126
  */
127
127
  function numToEquality(num) {
@@ -138,9 +138,9 @@ function numToEquality(num) {
138
138
  }
139
139
  exports.numToEquality = numToEquality;
140
140
  /**
141
- * Converts a trigger context into the relavent information for the specified trigger type.
141
+ * Converts a trigger context into the relevant information for the specified trigger type.
142
142
  * @param body the body of the trigger
143
- * @return object[] The tranformed data that is relavent for the trigger type
143
+ * @return object[] The transformed data that is relevant for the trigger type
144
144
  */
145
145
  function getTriggerSchema(body) {
146
146
  const activeTrigger = body.activeTrigger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saasquatch/program-boilerplate",
3
- "version": "3.5.12-1",
3
+ "version": "3.5.12-2",
4
4
  "description": "Boilerplate for writing programs",
5
5
  "main": "dist/index.js",
6
6
  "files": [