@saasquatch/program-boilerplate 3.6.0-1 → 3.6.1-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.
@@ -2,9 +2,28 @@
2
2
  /**
3
3
  * @module conversion
4
4
  */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
14
+ }) : function(o, v) {
15
+ o["default"] = v;
16
+ });
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
23
+ };
5
24
  Object.defineProperty(exports, "__esModule", { value: true });
6
25
  exports.meetEventTriggerRules = exports.meetCustomFieldRules = exports.meetEdgeTriggerConditions = void 0;
7
- const assert = require("assert");
26
+ const assert = __importStar(require("assert"));
8
27
  const jsonata_1 = require("./jsonata");
9
28
  //functions
10
29
  /**
@@ -47,8 +66,8 @@ function meetEdgeTriggerConditions(fields, activeTrigger) {
47
66
  // not take more than a few milliseconds. if it takes longer than 500ms
48
67
  // something is definitely wrong with the query
49
68
  const jsonataTimeoutMs = 500;
50
- const { success: prevSuccess, result: previousValue } = jsonata_1.safeJsonata2(field.replace("user.", "previous."), activeTrigger, jsonataTimeoutMs);
51
- const { success: currentSuccess, result: currentValue } = jsonata_1.safeJsonata2(field, activeTrigger, jsonataTimeoutMs);
69
+ const { success: prevSuccess, result: previousValue } = jsonata_1.timeboxedJsonata(field.replace("user.", "previous."), activeTrigger, jsonataTimeoutMs);
70
+ const { success: currentSuccess, result: currentValue } = jsonata_1.timeboxedJsonata(field, activeTrigger, jsonataTimeoutMs);
52
71
  // one of the JSONata expressions failed to evaluate -- edge field is considered
53
72
  // "not passing"
54
73
  if (!prevSuccess || !currentSuccess) {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as express from "express";
1
+ import express from "express";
2
2
  import { meetCustomFieldRules, meetEventTriggerRules, meetEdgeTriggerConditions } from "./conversion";
3
3
  import { rewardEmailQuery } from "./queries";
4
4
  import Transaction from "./transaction";
@@ -6,11 +6,11 @@ import { triggerProgram } from "./trigger";
6
6
  import { getLogger, setLogLevel } from "./logger";
7
7
  import * as types from "./types";
8
8
  import { Program, ProgramRequirement, RequirementValidationResult, ValidationProgramField, ProgramTriggerBody } from "./types/rpc";
9
- import { timeboxExpression, safeJsonata } from "./jsonata";
9
+ import { timeboxExpression, timeboxedJsonata, 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, meetEdgeTriggerConditions, 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, timeboxedJsonata, 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,24 +1,47 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
2
24
  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.meetEdgeTriggerConditions = exports.meetCustomFieldRules = exports.meetEventTriggerRules = exports.Transaction = exports.types = void 0;
4
- const express = require("express");
25
+ exports.webtask = exports.setLogLevel = exports.getLogger = exports.safeJsonata = exports.timeboxedJsonata = 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;
26
+ const express_1 = __importDefault(require("express"));
5
27
  const conversion_1 = require("./conversion");
6
28
  Object.defineProperty(exports, "meetCustomFieldRules", { enumerable: true, get: function () { return conversion_1.meetCustomFieldRules; } });
7
29
  Object.defineProperty(exports, "meetEventTriggerRules", { enumerable: true, get: function () { return conversion_1.meetEventTriggerRules; } });
8
30
  Object.defineProperty(exports, "meetEdgeTriggerConditions", { enumerable: true, get: function () { return conversion_1.meetEdgeTriggerConditions; } });
9
31
  const queries_1 = require("./queries");
10
32
  Object.defineProperty(exports, "rewardEmailQuery", { enumerable: true, get: function () { return queries_1.rewardEmailQuery; } });
11
- const transaction_1 = require("./transaction");
33
+ const transaction_1 = __importDefault(require("./transaction"));
12
34
  exports.Transaction = transaction_1.default;
13
35
  const trigger_1 = require("./trigger");
14
36
  Object.defineProperty(exports, "triggerProgram", { enumerable: true, get: function () { return trigger_1.triggerProgram; } });
15
37
  const logger_1 = require("./logger");
16
38
  Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return logger_1.getLogger; } });
17
39
  Object.defineProperty(exports, "setLogLevel", { enumerable: true, get: function () { return logger_1.setLogLevel; } });
18
- const types = require("./types");
40
+ const types = __importStar(require("./types"));
19
41
  exports.types = types;
20
42
  const jsonata_1 = require("./jsonata");
21
43
  Object.defineProperty(exports, "timeboxExpression", { enumerable: true, get: function () { return jsonata_1.timeboxExpression; } });
44
+ Object.defineProperty(exports, "timeboxedJsonata", { enumerable: true, get: function () { return jsonata_1.timeboxedJsonata; } });
22
45
  Object.defineProperty(exports, "safeJsonata", { enumerable: true, get: function () { return jsonata_1.safeJsonata; } });
23
46
  const utils_1 = require("./utils");
24
47
  Object.defineProperty(exports, "inferType", { enumerable: true, get: function () { return utils_1.inferType; } });
@@ -37,8 +60,8 @@ Object.defineProperty(exports, "getUserCustomFieldsFromJsonata", { enumerable: t
37
60
  */
38
61
  function webtask(program = {}) {
39
62
  const compression = require("compression");
40
- const app = express();
41
- app.use(express.json({ limit: process.env.MAX_PAYLOAD_SIZE || "1mb" }));
63
+ const app = express_1.default();
64
+ app.use(express_1.default.json({ limit: process.env.MAX_PAYLOAD_SIZE || "1mb" }));
42
65
  app.use(compression());
43
66
  // Enforce HTTPS. The server does not redirect http -> https
44
67
  // because OWASP advises not to
package/dist/jsonata.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as jsonata from "jsonata";
1
+ import jsonata from "jsonata";
2
2
  /**
3
3
  * Protect the process/browser from a runnaway expression
4
4
  * i.e. Infinite loop (tail recursion), or excessive stack growth
@@ -8,8 +8,11 @@ import * as jsonata from "jsonata";
8
8
  * @param {Number} maxDepth - max stack depth
9
9
  */
10
10
  export declare function timeboxExpression(expr: jsonata.Expression, timeout?: number, maxDepth?: number): void;
11
+ /**
12
+ * @deprecated Use timeboxedJsonata instead
13
+ */
11
14
  export declare function safeJsonata(expression: string, inputData: any): any;
12
- export declare function safeJsonata2(expression: string, inputData: any, timeout?: number, maxDepth?: number): {
15
+ export declare function timeboxedJsonata(expression: string, inputData: any, timeout?: number, maxDepth?: number): {
13
16
  success: boolean;
14
17
  result: any;
15
18
  };
package/dist/jsonata.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safeJsonata2 = exports.safeJsonata = exports.timeboxExpression = void 0;
4
- const jsonata = require("jsonata");
6
+ exports.timeboxedJsonata = exports.safeJsonata = exports.timeboxExpression = void 0;
7
+ const jsonata_1 = __importDefault(require("jsonata"));
5
8
  const logger_1 = require("./logger");
6
9
  const TIMEOUT = 5000;
7
10
  const MAXDEPTH = 1000;
@@ -48,9 +51,12 @@ function timeboxExpression(expr, timeout, maxDepth) {
48
51
  });
49
52
  }
50
53
  exports.timeboxExpression = timeboxExpression;
54
+ /**
55
+ * @deprecated Use timeboxedJsonata instead
56
+ */
51
57
  function safeJsonata(expression, inputData) {
52
58
  try {
53
- const jsonataQuery = jsonata(expression);
59
+ const jsonataQuery = jsonata_1.default(expression);
54
60
  timeboxExpression(jsonataQuery);
55
61
  return jsonataQuery.evaluate(inputData);
56
62
  }
@@ -59,9 +65,9 @@ function safeJsonata(expression, inputData) {
59
65
  }
60
66
  }
61
67
  exports.safeJsonata = safeJsonata;
62
- function safeJsonata2(expression, inputData, timeout, maxDepth) {
68
+ function timeboxedJsonata(expression, inputData, timeout, maxDepth) {
63
69
  try {
64
- const jsonataQuery = jsonata(expression);
70
+ const jsonataQuery = jsonata_1.default(expression);
65
71
  timeboxExpression(jsonataQuery, timeout, maxDepth);
66
72
  const result = jsonataQuery.evaluate(inputData);
67
73
  return { success: true, result };
@@ -73,4 +79,4 @@ function safeJsonata2(expression, inputData, timeout, maxDepth) {
73
79
  return { success: false, result: undefined };
74
80
  }
75
81
  }
76
- exports.safeJsonata2 = safeJsonata2;
82
+ exports.timeboxedJsonata = timeboxedJsonata;
package/dist/logger.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setLogLevel = exports.getLogger = void 0;
4
- const winston_1 = require("winston");
4
+ const logger_1 = require("@saasquatch/logger");
5
5
  // Lazily initialized logger instance
6
6
  let _logger;
7
7
  /**
@@ -16,13 +16,11 @@ function getLogger(logLevel) {
16
16
  if (_logger) {
17
17
  return _logger;
18
18
  }
19
- const logFormat = winston_1.format.printf(({ level, message }) => {
20
- return `[${level.toUpperCase()}] ${message}`;
21
- });
22
- _logger = winston_1.createLogger({
23
- level: logLevel,
24
- format: winston_1.format.combine(logFormat),
25
- transports: [new winston_1.transports.Console()],
19
+ if (!logger_1.LOG_LEVELS.includes(logLevel)) {
20
+ logLevel = "info";
21
+ }
22
+ _logger = logger_1.initializeLogger({
23
+ logLevel: logLevel,
26
24
  });
27
25
  return _logger;
28
26
  }
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  // @ts-check
4
7
  const queries_1 = require("./queries");
5
- const bson_objectid_1 = require("bson-objectid");
8
+ const bson_objectid_1 = __importDefault(require("bson-objectid"));
6
9
  class Transaction {
7
10
  /**
8
11
  * @classdesc A Transaction instance takes a context object from Express, generates mutations and analytics as the program requested.
package/dist/trigger.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.triggerProgram = void 0;
4
- const transaction_1 = require("./transaction");
7
+ const transaction_1 = __importDefault(require("./transaction"));
5
8
  /**
6
9
  * Triggers the program and returns the result (JSON + HTTP code)
7
10
  *
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.saasquatch = exports.rpc = void 0;
4
- const rpc = require("./rpc");
23
+ const rpc = __importStar(require("./rpc"));
5
24
  exports.rpc = rpc;
6
- const saasquatch = require("./saasquatch");
25
+ const saasquatch = __importStar(require("./saasquatch"));
7
26
  exports.saasquatch = saasquatch;
package/dist/utils.js CHANGED
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getUserCustomFieldsFromJsonata = exports.getTriggerSchema = exports.numToEquality = exports.inferType = exports.getGoalAnalyticTimestamp = exports.setRewardSchedule = void 0;
4
7
  const queries_1 = require("./queries");
5
- const jsonata_paths_extractor_1 = require("@saasquatch/jsonata-paths-extractor");
8
+ const jsonata_paths_extractor_1 = __importDefault(require("@saasquatch/jsonata-paths-extractor"));
6
9
  /**
7
10
  * Append a reward schedule to the template and return the new template
8
11
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saasquatch/program-boilerplate",
3
- "version": "3.6.0-1",
3
+ "version": "3.6.1-0",
4
4
  "description": "Boilerplate for writing programs",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -32,7 +32,8 @@
32
32
  "typescript": "^3.9.9"
33
33
  },
34
34
  "dependencies": {
35
- "@saasquatch/jsonata-paths-extractor": "^1.0.0-0",
35
+ "@saasquatch/jsonata-paths-extractor": "^1.0.1",
36
+ "@saasquatch/logger": "^1.0.0-1",
36
37
  "bson-objectid": "^1.3.1",
37
38
  "compression": "^1.7.4",
38
39
  "express": "^4.17.1",