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 tracer from "dd-trace"
import fs from "fs" import fs from "fs"
import url from "url" import url from "url"
import crypto from "crypto"
export function init() { export function init() {
const helpersSource = fs.readFileSync( const helpersSource = fs.readFileSync(
@ -45,7 +46,25 @@ export function init() {
const helpersModule = jsIsolate.compileModuleSync( const helpersModule = jsIsolate.compileModuleSync(
`${injectedRequire};${helpersSource}` `${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 => { helpersModule.instantiateSync(jsContext, specifier => {
if (specifier === "crypto") {
return cryptoModule
}
throw new Error(`No imports allowed. Required: ${specifier}`) throw new Error(`No imports allowed. Required: ${specifier}`)
}) })

View File

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