@budibase/string-templates 2.20.3 → 2.20.4
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/bundle.mjs +1 -1
- package/dist/helpers/javascript.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/utilities.d.ts +2 -0
- package/package.json +2 -2
- package/src/helpers/javascript.js +5 -2
- package/src/index.js +22 -15
- package/src/utilities.js +8 -0
package/dist/index.d.ts
CHANGED
@@ -15,4 +15,5 @@ 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 function defaultJSSetup(): void;
|
18
19
|
export { setJSRunner, setOnErrorLog, FIND_ANY_HBS_REGEX, JsErrorTimeout, helpersToRemoveForJs };
|
package/dist/utilities.d.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
export const FIND_HBS_REGEX: RegExp;
|
2
2
|
export const FIND_ANY_HBS_REGEX: RegExp;
|
3
3
|
export const FIND_TRIPLE_HBS_REGEX: RegExp;
|
4
|
+
export function isBackendService(): boolean;
|
5
|
+
export function isJSAllowed(): boolean;
|
4
6
|
export function findDoubleHbsInstances(string: any): any;
|
5
7
|
export function isAlphaNumeric(char: any): any;
|
6
8
|
export function swapStrings(string: any, start: any, length: any, swap: any): any;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@budibase/string-templates",
|
3
|
-
"version": "2.20.
|
3
|
+
"version": "2.20.4",
|
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": "
|
49
|
+
"gitHead": "1791e493ef1b7bad157eddb723f67437802658e6"
|
50
50
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
const { atob } = require("../utilities")
|
1
|
+
const { atob, isBackendService, isJSAllowed } = require("../utilities")
|
2
2
|
const cloneDeep = require("lodash.clonedeep")
|
3
3
|
const { LITERAL_MARKER } = require("../helpers/constants")
|
4
4
|
const { getJsHelperList } = require("./list")
|
@@ -7,6 +7,9 @@ const { getJsHelperList } = require("./list")
|
|
7
7
|
// This setter is used in the entrypoint (either index.js or index.mjs).
|
8
8
|
let runJS
|
9
9
|
module.exports.setJSRunner = runner => (runJS = runner)
|
10
|
+
module.exports.removeJSRunner = () => {
|
11
|
+
runJS = undefined
|
12
|
+
}
|
10
13
|
|
11
14
|
let onErrorLog
|
12
15
|
module.exports.setOnErrorLog = delegate => (onErrorLog = delegate)
|
@@ -39,7 +42,7 @@ const getContextValue = (path, context) => {
|
|
39
42
|
|
40
43
|
// Evaluates JS code against a certain context
|
41
44
|
module.exports.processJS = (handlebars, context) => {
|
42
|
-
if (
|
45
|
+
if (!isJSAllowed() || (isBackendService() && !runJS)) {
|
43
46
|
throw new Error("JS disabled in environment.")
|
44
47
|
}
|
45
48
|
try {
|
package/src/index.js
CHANGED
@@ -2,7 +2,7 @@ const vm = require("vm")
|
|
2
2
|
const handlebars = require("handlebars")
|
3
3
|
const { registerAll, registerMinimum } = require("./helpers/index")
|
4
4
|
const processors = require("./processors")
|
5
|
-
const { atob, btoa } = require("./utilities")
|
5
|
+
const { atob, btoa, isBackendService } = require("./utilities")
|
6
6
|
const manifest = require("../manifest.json")
|
7
7
|
const {
|
8
8
|
FIND_HBS_REGEX,
|
@@ -404,18 +404,25 @@ module.exports.JsErrorTimeout = errors.JsErrorTimeout
|
|
404
404
|
|
405
405
|
module.exports.helpersToRemoveForJs = helpersToRemoveForJs
|
406
406
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
context
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
407
|
+
function defaultJSSetup() {
|
408
|
+
if (!isBackendService()) {
|
409
|
+
/**
|
410
|
+
* Use polyfilled vm to run JS scripts in a browser Env
|
411
|
+
*/
|
412
|
+
javascript.setJSRunner((js, context) => {
|
413
|
+
context = {
|
414
|
+
...context,
|
415
|
+
alert: undefined,
|
416
|
+
setInterval: undefined,
|
417
|
+
setTimeout: undefined,
|
418
|
+
}
|
419
|
+
vm.createContext(context)
|
420
|
+
return vm.runInNewContext(js, context, { timeout: 1000 })
|
421
|
+
})
|
422
|
+
} else {
|
423
|
+
javascript.removeJSRunner()
|
424
|
+
}
|
421
425
|
}
|
426
|
+
defaultJSSetup()
|
427
|
+
|
428
|
+
module.exports.defaultJSSetup = defaultJSSetup
|
package/src/utilities.js
CHANGED
@@ -4,6 +4,14 @@ module.exports.FIND_HBS_REGEX = /{{([^{].*?)}}/g
|
|
4
4
|
module.exports.FIND_ANY_HBS_REGEX = /{?{{([^{].*?)}}}?/g
|
5
5
|
module.exports.FIND_TRIPLE_HBS_REGEX = /{{{([^{].*?)}}}/g
|
6
6
|
|
7
|
+
module.exports.isBackendService = () => {
|
8
|
+
return typeof window === "undefined"
|
9
|
+
}
|
10
|
+
|
11
|
+
module.exports.isJSAllowed = () => {
|
12
|
+
return process && !process.env.NO_JS
|
13
|
+
}
|
14
|
+
|
7
15
|
// originally this could be done with a single regex using look behinds
|
8
16
|
// but safari does not support this feature
|
9
17
|
// original regex: /(?<!{){{[^{}]+}}(?!})/g
|