Configure cypto

This commit is contained in:
Adria Navarro 2024-01-19 10:59:48 +01:00
parent 09d8951fc3
commit 915482a915
2 changed files with 20 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import { context } from "@budibase/backend-core"
import tracer from "dd-trace"
import fs from "fs"
import url from "url"
import crypto from "crypto"
export function init() {
const helpersSource = fs.readFileSync(
@ -45,7 +46,25 @@ export function init() {
const helpersModule = jsIsolate.compileModuleSync(
`${injectedRequire};${helpersSource}`
)
const cryptoModule = jsIsolate.compileModuleSync(`export default {
randomUUID: cryptoRandomUUIDCb,
}`)
cryptoModule.instantiateSync(jsContext, specifier => {
throw new Error(`No imports allowed. Required: ${specifier}`)
})
global.setSync(
"cryptoRandomUUIDCb",
new ivm.Callback((...params: Parameters<typeof crypto.randomUUID>) => {
return crypto.randomUUID(...params)
})
)
helpersModule.instantiateSync(jsContext, specifier => {
if (specifier === "crypto") {
return cryptoModule
}
throw new Error(`No imports allowed. Required: ${specifier}`)
})

View File

@ -10,7 +10,7 @@ const externalCollections = {
comparison: require("@budibase/handlebars-helpers/lib/comparison"),
object: require("@budibase/handlebars-helpers/lib/object"),
regex: require("@budibase/handlebars-helpers/lib/regex"),
// uuid: require("@budibase/handlebars-helpers/lib/uuid"),
uuid: require("@budibase/handlebars-helpers/lib/uuid"),
}
const addedHelpers = {