@budibase/string-templates 2.19.0 → 2.19.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.
@@ -1,2 +1,3 @@
1
1
  export function setJSRunner(runner: any): any;
2
+ export function setOnErrorLog(delegate: any): any;
2
3
  export function processJS(handlebars: any, context: any): string;
package/dist/index.d.mts CHANGED
@@ -17,6 +17,7 @@ export const disableEscaping: (string: any) => any;
17
17
  export const findHBSBlocks: (string: string) => string[];
18
18
  export const convertToJS: (hbs: any) => string;
19
19
  export const setJSRunner: (runner: any) => any;
20
+ export const setOnErrorLog: (delegate: any) => any;
20
21
  export const FIND_ANY_HBS_REGEX: RegExp;
21
22
  export const helpersToRemoveForJs: string[];
22
23
  export * from "./errors.js";
package/dist/index.d.ts CHANGED
@@ -15,4 +15,4 @@ export function doesContainString(template: string, string: string): boolean;
15
15
  export function convertToJS(hbs: any): string;
16
16
  import { FIND_ANY_HBS_REGEX } from "./utilities";
17
17
  import { helpersToRemoveForJs } from "./helpers/list";
18
- export { setJSRunner, FIND_ANY_HBS_REGEX, JsErrorTimeout, helpersToRemoveForJs };
18
+ export { setJSRunner, setOnErrorLog, FIND_ANY_HBS_REGEX, JsErrorTimeout, helpersToRemoveForJs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/string-templates",
3
- "version": "2.19.0",
3
+ "version": "2.19.2",
4
4
  "description": "Handlebars wrapper for Budibase templating.",
5
5
  "main": "src/index.js",
6
6
  "module": "dist/bundle.mjs",
@@ -46,5 +46,5 @@
46
46
  "rollup-plugin-terser": "^7.0.2",
47
47
  "typescript": "5.2.2"
48
48
  },
49
- "gitHead": "aa0c674b6129fc1aba5a5646d257097f7cfe1edc"
49
+ "gitHead": "e0cacd8993732dc9d156a92b0e6df026e76999e1"
50
50
  }
@@ -8,6 +8,9 @@ const { getJsHelperList } = require("./list")
8
8
  let runJS
9
9
  module.exports.setJSRunner = runner => (runJS = runner)
10
10
 
11
+ let onErrorLog
12
+ module.exports.setOnErrorLog = delegate => (onErrorLog = delegate)
13
+
11
14
  // Helper utility to strip square brackets from a value
12
15
  const removeSquareBrackets = value => {
13
16
  if (!value || typeof value !== "string") {
@@ -56,6 +59,8 @@ module.exports.processJS = (handlebars, context) => {
56
59
  const res = { data: runJS(js, sandboxContext) }
57
60
  return `{{${LITERAL_MARKER} js_result-${JSON.stringify(res)}}}`
58
61
  } catch (error) {
62
+ onErrorLog && onErrorLog(error)
63
+
59
64
  if (error.code === "ERR_SCRIPT_EXECUTION_TIMEOUT") {
60
65
  return "Timed out while executing JS"
61
66
  }
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ const vm = require("vm")
1
2
  const handlebars = require("handlebars")
2
3
  const { registerAll, registerMinimum } = require("./helpers/index")
3
4
  const processors = require("./processors")
@@ -365,6 +366,7 @@ module.exports.doesContainString = (template, string) => {
365
366
  }
366
367
 
367
368
  module.exports.setJSRunner = javascript.setJSRunner
369
+ module.exports.setOnErrorLog = javascript.setOnErrorLog
368
370
 
369
371
  module.exports.convertToJS = hbs => {
370
372
  const blocks = exports.findHBSBlocks(hbs)
@@ -401,3 +403,19 @@ const errors = require("./errors")
401
403
  module.exports.JsErrorTimeout = errors.JsErrorTimeout
402
404
 
403
405
  module.exports.helpersToRemoveForJs = helpersToRemoveForJs
406
+
407
+ if (process && !process.env.NO_JS) {
408
+ /**
409
+ * Use polyfilled vm to run JS scripts in a browser Env
410
+ */
411
+ javascript.setJSRunner((js, context) => {
412
+ context = {
413
+ ...context,
414
+ alert: undefined,
415
+ setInterval: undefined,
416
+ setTimeout: undefined,
417
+ }
418
+ vm.createContext(context)
419
+ return vm.runInNewContext(js, context, { timeout: 1000 })
420
+ })
421
+ }
package/src/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import vm from "vm"
2
1
  import templates from "./index.js"
3
2
 
4
3
  /**
@@ -20,23 +19,8 @@ export const disableEscaping = templates.disableEscaping
20
19
  export const findHBSBlocks = templates.findHBSBlocks
21
20
  export const convertToJS = templates.convertToJS
22
21
  export const setJSRunner = templates.setJSRunner
22
+ export const setOnErrorLog = templates.setOnErrorLog
23
23
  export const FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX
24
24
  export const helpersToRemoveForJs = templates.helpersToRemoveForJs
25
25
 
26
- if (process && !process.env.NO_JS) {
27
- /**
28
- * Use polyfilled vm to run JS scripts in a browser Env
29
- */
30
- setJSRunner((js, context) => {
31
- context = {
32
- ...context,
33
- alert: undefined,
34
- setInterval: undefined,
35
- setTimeout: undefined,
36
- }
37
- vm.createContext(context)
38
- return vm.runInNewContext(js, context, { timeout: 1000 })
39
- })
40
- }
41
-
42
26
  export * from "./errors.js"