@budibase/server 1.3.15-alpha.0 → 1.3.15-alpha.3
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/builder/assets/{index.b266d29f.js → index.e1d89439.js} +288 -288
- package/builder/assets/{index.f5c54dd2.css → index.ecdac070.css} +2 -2
- package/builder/index.html +2 -2
- package/coverage/clover.xml +21 -21
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +1 -1
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/screen.js.html +5 -2
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +1 -1
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +1 -1
- package/coverage/lcov-report/db/utils.js.html +1 -1
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +1 -1
- package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +1 -1
- package/coverage/lcov-report/utilities/index.html +1 -1
- package/coverage/lcov-report/utilities/index.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +34 -34
- package/dist/api/controllers/plugin/file.js +24 -0
- package/dist/api/controllers/plugin/github.js +69 -0
- package/dist/api/controllers/{plugin.js → plugin/index.js} +87 -14
- package/dist/api/controllers/plugin/npm.js +58 -0
- package/dist/api/controllers/plugin/uploaders.js +11 -0
- package/dist/api/controllers/plugin/url.js +24 -0
- package/dist/api/controllers/plugin/utils.js +26 -0
- package/dist/api/controllers/screen.js +1 -0
- package/dist/api/controllers/static/templates/preview.hbs +3 -1
- package/dist/api/routes/plugin.js +1 -0
- package/dist/app.js +2 -0
- package/dist/integrations/base/sqlTable.js +3 -1
- package/dist/package.json +7 -6
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +56 -12
- package/dist/websocket.js +22 -0
- package/package.json +8 -7
- package/src/api/controllers/plugin/file.ts +15 -0
- package/src/api/controllers/plugin/github.ts +75 -0
- package/src/api/controllers/plugin/index.ts +206 -0
- package/src/api/controllers/plugin/npm.ts +56 -0
- package/src/api/controllers/plugin/uploaders.ts +4 -0
- package/src/api/controllers/plugin/url.ts +12 -0
- package/src/api/controllers/plugin/utils.ts +19 -0
- package/src/api/controllers/screen.js +1 -0
- package/src/api/controllers/static/templates/preview.hbs +3 -1
- package/src/api/routes/plugin.ts +1 -0
- package/src/app.ts +2 -0
- package/src/integrations/base/sqlTable.ts +3 -1
- package/src/module.d.ts +1 -0
- package/src/utilities/fileSystem/index.js +72 -12
- package/src/websocket.ts +26 -0
- package/src/api/controllers/plugin.ts +0 -110
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
streamUpload,
|
|
16
16
|
deleteFolder,
|
|
17
17
|
downloadTarball,
|
|
18
|
+
downloadTarballDirect,
|
|
18
19
|
deleteFiles,
|
|
19
20
|
} = require("./utilities")
|
|
20
21
|
const { updateClientLibrary } = require("./clientLibrary")
|
|
@@ -338,31 +339,57 @@ exports.cleanup = appIds => {
|
|
|
338
339
|
}
|
|
339
340
|
}
|
|
340
341
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
fs.
|
|
342
|
+
const createTempFolder = item => {
|
|
343
|
+
const path = join(budibaseTempDir(), item)
|
|
344
|
+
try {
|
|
345
|
+
// remove old tmp directories automatically - don't combine
|
|
346
|
+
if (fs.existsSync(path)) {
|
|
347
|
+
fs.rmSync(path, { recursive: true, force: true })
|
|
348
|
+
}
|
|
349
|
+
fs.mkdirSync(path)
|
|
350
|
+
} catch (err) {
|
|
351
|
+
throw new Error(`Path cannot be created: ${err.message}`)
|
|
349
352
|
}
|
|
350
|
-
|
|
353
|
+
|
|
354
|
+
return path
|
|
355
|
+
}
|
|
356
|
+
exports.createTempFolder = createTempFolder
|
|
357
|
+
|
|
358
|
+
const extractTarball = async (fromFilePath, toPath) => {
|
|
351
359
|
await tar.extract({
|
|
352
|
-
file:
|
|
353
|
-
C:
|
|
360
|
+
file: fromFilePath,
|
|
361
|
+
C: toPath,
|
|
354
362
|
})
|
|
363
|
+
}
|
|
364
|
+
exports.extractTarball = extractTarball
|
|
365
|
+
|
|
366
|
+
const getPluginMetadata = async path => {
|
|
355
367
|
let metadata = {}
|
|
356
368
|
try {
|
|
357
369
|
const pkg = fs.readFileSync(join(path, "package.json"), "utf8")
|
|
358
370
|
const schema = fs.readFileSync(join(path, "schema.json"), "utf8")
|
|
371
|
+
|
|
359
372
|
metadata.schema = JSON.parse(schema)
|
|
360
373
|
metadata.package = JSON.parse(pkg)
|
|
374
|
+
|
|
375
|
+
if (
|
|
376
|
+
!metadata.package.name ||
|
|
377
|
+
!metadata.package.version ||
|
|
378
|
+
!metadata.package.description
|
|
379
|
+
) {
|
|
380
|
+
throw new Error(
|
|
381
|
+
"package.json is missing one of 'name', 'version' or 'description'."
|
|
382
|
+
)
|
|
383
|
+
}
|
|
361
384
|
} catch (err) {
|
|
362
|
-
throw new Error(
|
|
385
|
+
throw new Error(
|
|
386
|
+
`Unable to process schema.json/package.json in plugin. ${err.message}`
|
|
387
|
+
)
|
|
363
388
|
}
|
|
389
|
+
|
|
364
390
|
return { metadata, directory: path }
|
|
365
391
|
}
|
|
392
|
+
exports.getPluginMetadata = getPluginMetadata
|
|
366
393
|
|
|
367
394
|
exports.getDatasourcePlugin = async (name, url, hash) => {
|
|
368
395
|
if (!fs.existsSync(DATASOURCE_PATH)) {
|
|
@@ -396,6 +423,38 @@ exports.getDatasourcePlugin = async (name, url, hash) => {
|
|
|
396
423
|
}
|
|
397
424
|
}
|
|
398
425
|
|
|
426
|
+
/**
|
|
427
|
+
* Find for a file recursively from start path applying filter, return first match
|
|
428
|
+
*/
|
|
429
|
+
exports.findFileRec = (startPath, filter) => {
|
|
430
|
+
if (!fs.existsSync(startPath)) {
|
|
431
|
+
return
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const files = fs.readdirSync(startPath)
|
|
435
|
+
for (let i = 0, len = files.length; i < len; i++) {
|
|
436
|
+
const filename = join(startPath, files[i])
|
|
437
|
+
const stat = fs.lstatSync(filename)
|
|
438
|
+
|
|
439
|
+
if (stat.isDirectory()) {
|
|
440
|
+
return exports.findFileRec(filename, filter)
|
|
441
|
+
} else if (filename.endsWith(filter)) {
|
|
442
|
+
return filename
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Remove a folder which is not empty from the file system
|
|
449
|
+
*/
|
|
450
|
+
exports.deleteFolderFileSystem = path => {
|
|
451
|
+
if (!fs.existsSync(path)) {
|
|
452
|
+
return
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
fs.rmSync(path, { recursive: true, force: true })
|
|
456
|
+
}
|
|
457
|
+
|
|
399
458
|
/**
|
|
400
459
|
* Full function definition for below can be found in the utilities.
|
|
401
460
|
*/
|
|
@@ -403,5 +462,6 @@ exports.upload = upload
|
|
|
403
462
|
exports.retrieve = retrieve
|
|
404
463
|
exports.retrieveToTmp = retrieveToTmp
|
|
405
464
|
exports.deleteFiles = deleteFiles
|
|
465
|
+
exports.downloadTarballDirect = downloadTarballDirect
|
|
406
466
|
exports.TOP_LEVEL_PATH = TOP_LEVEL_PATH
|
|
407
467
|
exports.NODE_MODULES_PATH = NODE_MODULES_PATH
|
package/src/websocket.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Server } from "socket.io"
|
|
2
|
+
import http from "http"
|
|
3
|
+
|
|
4
|
+
class Websocket {
|
|
5
|
+
socketServer: Server
|
|
6
|
+
|
|
7
|
+
constructor(server: http.Server, path: string) {
|
|
8
|
+
this.socketServer = new Server(server, {
|
|
9
|
+
path,
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Emit an event to all sockets
|
|
14
|
+
emit(event: string, payload: any) {
|
|
15
|
+
this.socketServer.sockets.emit(event, payload)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Likely to be more socket instances in future
|
|
20
|
+
let ClientAppSocket: Websocket
|
|
21
|
+
|
|
22
|
+
export const initialise = (server: http.Server) => {
|
|
23
|
+
ClientAppSocket = new Websocket(server, "/socket/client")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { ClientAppSocket }
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { ObjectStoreBuckets } from "../../constants"
|
|
2
|
-
import { extractPluginTarball, loadJSFile } from "../../utilities/fileSystem"
|
|
3
|
-
import { getGlobalDB } from "@budibase/backend-core/tenancy"
|
|
4
|
-
import { generatePluginID, getPluginParams } from "../../db/utils"
|
|
5
|
-
import { uploadDirectory } from "@budibase/backend-core/objectStore"
|
|
6
|
-
import { PluginType, FileType } from "@budibase/types"
|
|
7
|
-
import env from "../../environment"
|
|
8
|
-
|
|
9
|
-
export async function getPlugins(type?: PluginType) {
|
|
10
|
-
const db = getGlobalDB()
|
|
11
|
-
const response = await db.allDocs(
|
|
12
|
-
getPluginParams(null, {
|
|
13
|
-
include_docs: true,
|
|
14
|
-
})
|
|
15
|
-
)
|
|
16
|
-
const plugins = response.rows.map((row: any) => row.doc)
|
|
17
|
-
if (type) {
|
|
18
|
-
return plugins.filter((plugin: any) => plugin.schema?.type === type)
|
|
19
|
-
} else {
|
|
20
|
-
return plugins
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function upload(ctx: any) {
|
|
25
|
-
const plugins: FileType[] =
|
|
26
|
-
ctx.request.files.file.length > 1
|
|
27
|
-
? Array.from(ctx.request.files.file)
|
|
28
|
-
: [ctx.request.files.file]
|
|
29
|
-
try {
|
|
30
|
-
let docs = []
|
|
31
|
-
// can do single or multiple plugins
|
|
32
|
-
for (let plugin of plugins) {
|
|
33
|
-
const doc = await processPlugin(plugin)
|
|
34
|
-
docs.push(doc)
|
|
35
|
-
}
|
|
36
|
-
ctx.body = {
|
|
37
|
-
message: "Plugin(s) uploaded successfully",
|
|
38
|
-
plugins: docs,
|
|
39
|
-
}
|
|
40
|
-
} catch (err: any) {
|
|
41
|
-
const errMsg = err?.message ? err?.message : err
|
|
42
|
-
ctx.throw(400, `Failed to import plugin: ${errMsg}`)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function fetch(ctx: any) {
|
|
47
|
-
ctx.body = await getPlugins()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function destroy(ctx: any) {}
|
|
51
|
-
|
|
52
|
-
export async function processPlugin(plugin: FileType) {
|
|
53
|
-
if (!env.SELF_HOSTED) {
|
|
54
|
-
throw new Error("Plugins not supported outside of self-host.")
|
|
55
|
-
}
|
|
56
|
-
const db = getGlobalDB()
|
|
57
|
-
const { metadata, directory } = await extractPluginTarball(plugin)
|
|
58
|
-
const version = metadata.package.version,
|
|
59
|
-
name = metadata.package.name,
|
|
60
|
-
description = metadata.package.description
|
|
61
|
-
|
|
62
|
-
// first open the tarball into tmp directory
|
|
63
|
-
const bucketPath = `${name}/`
|
|
64
|
-
const files = await uploadDirectory(
|
|
65
|
-
ObjectStoreBuckets.PLUGINS,
|
|
66
|
-
directory,
|
|
67
|
-
bucketPath
|
|
68
|
-
)
|
|
69
|
-
const jsFile = files.find((file: any) => file.name.endsWith(".js"))
|
|
70
|
-
if (!jsFile) {
|
|
71
|
-
throw new Error(`Plugin missing .js file.`)
|
|
72
|
-
}
|
|
73
|
-
// validate the JS for a datasource
|
|
74
|
-
if (metadata.schema.type === PluginType.DATASOURCE) {
|
|
75
|
-
const js = loadJSFile(directory, jsFile.name)
|
|
76
|
-
// TODO: this isn't safe - but we need full node environment
|
|
77
|
-
// in future we should do this in a thread for safety
|
|
78
|
-
try {
|
|
79
|
-
eval(js)
|
|
80
|
-
} catch (err: any) {
|
|
81
|
-
const message = err?.message ? err.message : JSON.stringify(err)
|
|
82
|
-
throw new Error(`JS invalid: ${message}`)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const jsFileName = jsFile.name
|
|
86
|
-
const pluginId = generatePluginID(name)
|
|
87
|
-
|
|
88
|
-
// overwrite existing docs entirely if they exist
|
|
89
|
-
let rev
|
|
90
|
-
try {
|
|
91
|
-
const existing = await db.get(pluginId)
|
|
92
|
-
rev = existing._rev
|
|
93
|
-
} catch (err) {
|
|
94
|
-
rev = undefined
|
|
95
|
-
}
|
|
96
|
-
const doc = {
|
|
97
|
-
_id: pluginId,
|
|
98
|
-
_rev: rev,
|
|
99
|
-
...metadata,
|
|
100
|
-
name,
|
|
101
|
-
version,
|
|
102
|
-
description,
|
|
103
|
-
jsUrl: `${bucketPath}${jsFileName}`,
|
|
104
|
-
}
|
|
105
|
-
const response = await db.put(doc)
|
|
106
|
-
return {
|
|
107
|
-
...doc,
|
|
108
|
-
_rev: response.rev,
|
|
109
|
-
}
|
|
110
|
-
}
|