@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.
Files changed (188) hide show
  1. package/builder/assets/{index.b266d29f.js → index.e1d89439.js} +288 -288
  2. package/builder/assets/{index.f5c54dd2.css → index.ecdac070.css} +2 -2
  3. package/builder/index.html +2 -2
  4. package/coverage/clover.xml +21 -21
  5. package/coverage/coverage-final.json +1 -1
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  7. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/index.html +1 -1
  15. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/screen.js.html +5 -2
  31. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  44. package/coverage/lcov-report/api/index.html +1 -1
  45. package/coverage/lcov-report/api/index.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/index.html +1 -1
  57. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  71. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  74. package/coverage/lcov-report/automations/actions.js.html +1 -1
  75. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  76. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  77. package/coverage/lcov-report/automations/index.html +1 -1
  78. package/coverage/lcov-report/automations/index.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/index.html +1 -1
  86. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  105. package/coverage/lcov-report/constants/index.html +1 -1
  106. package/coverage/lcov-report/constants/index.js.html +1 -1
  107. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  108. package/coverage/lcov-report/constants/screens.js.html +1 -1
  109. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  110. package/coverage/lcov-report/db/index.html +1 -1
  111. package/coverage/lcov-report/db/index.js.html +1 -1
  112. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  113. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  116. package/coverage/lcov-report/db/newid.js.html +1 -1
  117. package/coverage/lcov-report/db/utils.js.html +1 -1
  118. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  119. package/coverage/lcov-report/events/index.html +1 -1
  120. package/coverage/lcov-report/events/index.js.html +1 -1
  121. package/coverage/lcov-report/events/utils.js.html +1 -1
  122. package/coverage/lcov-report/index.html +1 -1
  123. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  124. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  125. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  126. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  127. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  128. package/coverage/lcov-report/middleware/index.html +1 -1
  129. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  130. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  131. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  132. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  133. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  134. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  135. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  136. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  137. package/coverage/lcov-report/utilities/global.js.html +1 -1
  138. package/coverage/lcov-report/utilities/index.html +1 -1
  139. package/coverage/lcov-report/utilities/index.js.html +1 -1
  140. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  141. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  142. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  143. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  144. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  145. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  146. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  147. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  148. package/coverage/lcov-report/utilities/security.js.html +1 -1
  149. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  150. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  151. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  152. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  153. package/coverage/lcov-report/utilities/users.js.html +1 -1
  154. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  155. package/coverage/lcov.info +34 -34
  156. package/dist/api/controllers/plugin/file.js +24 -0
  157. package/dist/api/controllers/plugin/github.js +69 -0
  158. package/dist/api/controllers/{plugin.js → plugin/index.js} +87 -14
  159. package/dist/api/controllers/plugin/npm.js +58 -0
  160. package/dist/api/controllers/plugin/uploaders.js +11 -0
  161. package/dist/api/controllers/plugin/url.js +24 -0
  162. package/dist/api/controllers/plugin/utils.js +26 -0
  163. package/dist/api/controllers/screen.js +1 -0
  164. package/dist/api/controllers/static/templates/preview.hbs +3 -1
  165. package/dist/api/routes/plugin.js +1 -0
  166. package/dist/app.js +2 -0
  167. package/dist/integrations/base/sqlTable.js +3 -1
  168. package/dist/package.json +7 -6
  169. package/dist/tsconfig.build.tsbuildinfo +1 -1
  170. package/dist/utilities/fileSystem/index.js +56 -12
  171. package/dist/websocket.js +22 -0
  172. package/package.json +8 -7
  173. package/src/api/controllers/plugin/file.ts +15 -0
  174. package/src/api/controllers/plugin/github.ts +75 -0
  175. package/src/api/controllers/plugin/index.ts +206 -0
  176. package/src/api/controllers/plugin/npm.ts +56 -0
  177. package/src/api/controllers/plugin/uploaders.ts +4 -0
  178. package/src/api/controllers/plugin/url.ts +12 -0
  179. package/src/api/controllers/plugin/utils.ts +19 -0
  180. package/src/api/controllers/screen.js +1 -0
  181. package/src/api/controllers/static/templates/preview.hbs +3 -1
  182. package/src/api/routes/plugin.ts +1 -0
  183. package/src/app.ts +2 -0
  184. package/src/integrations/base/sqlTable.ts +3 -1
  185. package/src/module.d.ts +1 -0
  186. package/src/utilities/fileSystem/index.js +72 -12
  187. package/src/websocket.ts +26 -0
  188. 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
- exports.extractPluginTarball = async file => {
342
- if (!file.name.endsWith(".tar.gz")) {
343
- throw new Error("Plugin must be compressed into a gzipped tarball.")
344
- }
345
- const path = join(budibaseTempDir(), file.name.split(".tar.gz")[0])
346
- // remove old tmp directories automatically - don't combine
347
- if (fs.existsSync(path)) {
348
- fs.rmSync(path, { recursive: true, force: true })
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
- fs.mkdirSync(path)
353
+
354
+ return path
355
+ }
356
+ exports.createTempFolder = createTempFolder
357
+
358
+ const extractTarball = async (fromFilePath, toPath) => {
351
359
  await tar.extract({
352
- file: file.path,
353
- C: path,
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("Unable to process schema.json/package.json in plugin.")
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
@@ -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
- }