@budibase/server 1.3.21-alpha.0 → 1.3.21-alpha.2

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 (169) hide show
  1. package/builder/assets/{index.75653b72.js → index.da0d40d9.js} +1 -1
  2. package/builder/index.html +1 -1
  3. package/coverage/clover.xml +92 -183
  4. package/coverage/coverage-final.json +1 -3
  5. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  6. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  7. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/index.html +9 -39
  13. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  19. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  41. package/coverage/lcov-report/api/index.html +1 -1
  42. package/coverage/lcov-report/api/index.js.html +1 -1
  43. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  44. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  45. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/index.html +1 -1
  54. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  68. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  71. package/coverage/lcov-report/automations/actions.js.html +1 -1
  72. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  73. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  74. package/coverage/lcov-report/automations/index.html +1 -1
  75. package/coverage/lcov-report/automations/index.js.html +1 -1
  76. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  77. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  78. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/index.html +1 -1
  83. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  93. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  94. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  102. package/coverage/lcov-report/constants/index.html +1 -1
  103. package/coverage/lcov-report/constants/index.js.html +1 -1
  104. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  105. package/coverage/lcov-report/constants/screens.js.html +1 -1
  106. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  107. package/coverage/lcov-report/db/index.html +18 -18
  108. package/coverage/lcov-report/db/index.js.html +1 -1
  109. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  110. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  111. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  112. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  113. package/coverage/lcov-report/db/newid.js.html +1 -1
  114. package/coverage/lcov-report/db/utils.js.html +13 -37
  115. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  116. package/coverage/lcov-report/events/index.html +1 -1
  117. package/coverage/lcov-report/events/index.js.html +1 -1
  118. package/coverage/lcov-report/events/utils.js.html +1 -1
  119. package/coverage/lcov-report/index.html +27 -27
  120. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  121. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  122. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  123. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  124. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  125. package/coverage/lcov-report/middleware/index.html +1 -1
  126. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  127. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  128. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  129. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  130. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  131. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  132. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  133. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  134. package/coverage/lcov-report/utilities/global.js.html +1 -1
  135. package/coverage/lcov-report/utilities/index.html +1 -1
  136. package/coverage/lcov-report/utilities/index.js.html +1 -1
  137. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  138. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  139. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  140. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  141. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  142. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  143. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  144. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  145. package/coverage/lcov-report/utilities/security.js.html +1 -1
  146. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  147. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  148. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  149. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  150. package/coverage/lcov-report/utilities/users.js.html +1 -1
  151. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  152. package/coverage/lcov.info +169 -332
  153. package/dist/api/controllers/component.js +12 -12
  154. package/dist/api/controllers/plugin/index.js +15 -71
  155. package/dist/api/controllers/screen.js +21 -23
  156. package/dist/db/utils.js +1 -7
  157. package/dist/package.json +6 -6
  158. package/dist/tsconfig.build.tsbuildinfo +1 -1
  159. package/dist/utilities/fileSystem/index.js +0 -6
  160. package/dist/watch.js +1 -1
  161. package/package.json +7 -7
  162. package/src/api/controllers/{component.js → component.ts} +13 -13
  163. package/src/api/controllers/plugin/index.ts +16 -97
  164. package/src/api/controllers/{screen.js → screen.ts} +26 -27
  165. package/src/db/utils.js +0 -8
  166. package/src/utilities/fileSystem/index.js +0 -7
  167. package/src/watch.ts +2 -2
  168. package/coverage/lcov-report/api/controllers/component.js.html +0 -256
  169. package/coverage/lcov-report/api/controllers/screen.js.html +0 -454
@@ -100,12 +100,6 @@ exports.getTemplateStream = (template) => __awaiter(void 0, void 0, void 0, func
100
100
  exports.loadHandlebarsFile = path => {
101
101
  return fs.readFileSync(path, "utf8");
102
102
  };
103
- /**
104
- * Same as above just with a different name.
105
- */
106
- exports.loadJSFile = (directory, name) => {
107
- return fs.readFileSync(join(directory, name), "utf8");
108
- };
109
103
  /**
110
104
  * When return a file from the API need to write the file to the system temporarily so we
111
105
  * can create a read stream to send.
package/dist/watch.js CHANGED
@@ -65,7 +65,7 @@ function watch() {
65
65
  const split = path.split("/");
66
66
  const name = split[split.length - 1];
67
67
  console.log("Importing plugin:", path);
68
- yield (0, plugin_1.processPlugin)({ name, path });
68
+ yield (0, plugin_1.processUploadedPlugin)({ name, path });
69
69
  }
70
70
  catch (err) {
71
71
  const message = (err === null || err === void 0 ? void 0 : err.message) ? err === null || err === void 0 ? void 0 : err.message : err;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.3.21-alpha.0",
4
+ "version": "1.3.21-alpha.2",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -77,11 +77,11 @@
77
77
  "license": "GPL-3.0",
78
78
  "dependencies": {
79
79
  "@apidevtools/swagger-parser": "10.0.3",
80
- "@budibase/backend-core": "1.3.21-alpha.0",
81
- "@budibase/client": "1.3.21-alpha.0",
82
- "@budibase/pro": "1.3.20",
83
- "@budibase/string-templates": "1.3.21-alpha.0",
84
- "@budibase/types": "1.3.21-alpha.0",
80
+ "@budibase/backend-core": "1.3.21-alpha.2",
81
+ "@budibase/client": "1.3.21-alpha.2",
82
+ "@budibase/pro": "1.3.21-alpha.1",
83
+ "@budibase/string-templates": "1.3.21-alpha.2",
84
+ "@budibase/types": "1.3.21-alpha.2",
85
85
  "@bull-board/api": "3.7.0",
86
86
  "@bull-board/koa": "3.9.4",
87
87
  "@elastic/elasticsearch": "7.10.0",
@@ -199,5 +199,5 @@
199
199
  "optionalDependencies": {
200
200
  "oracledb": "5.3.0"
201
201
  },
202
- "gitHead": "95d427cdf7f197a1da5cb8029d3906e46b96f100"
202
+ "gitHead": "361cc7577c50217c516da563f1fb726b65acf639"
203
203
  }
@@ -1,15 +1,15 @@
1
- const { DocumentType, getPluginParams } = require("../../db/utils")
2
- const { getComponentLibraryManifest } = require("../../utilities/fileSystem")
3
- const { getAppDB } = require("@budibase/backend-core/context")
4
- const { getGlobalDB } = require("@budibase/backend-core/tenancy")
1
+ import { DocumentType } from "../../db/utils"
2
+ import { Plugin } from "@budibase/types"
3
+ import { db as dbCore, context, tenancy } from "@budibase/backend-core"
4
+ import { getComponentLibraryManifest } from "../../utilities/fileSystem"
5
5
 
6
- exports.fetchAppComponentDefinitions = async function (ctx) {
6
+ exports.fetchAppComponentDefinitions = async function (ctx: any) {
7
7
  try {
8
- const db = getAppDB()
8
+ const db = context.getAppDB()
9
9
  const app = await db.get(DocumentType.APP_METADATA)
10
10
 
11
11
  let componentManifests = await Promise.all(
12
- app.componentLibraries.map(async library => {
12
+ app.componentLibraries.map(async (library: any) => {
13
13
  let manifest = await getComponentLibraryManifest(library)
14
14
  return {
15
15
  manifest,
@@ -17,7 +17,7 @@ exports.fetchAppComponentDefinitions = async function (ctx) {
17
17
  }
18
18
  })
19
19
  )
20
- const definitions = {}
20
+ const definitions: { [key: string]: any } = {}
21
21
  for (let { manifest, library } of componentManifests) {
22
22
  for (let key of Object.keys(manifest)) {
23
23
  if (key === "features") {
@@ -33,16 +33,16 @@ exports.fetchAppComponentDefinitions = async function (ctx) {
33
33
  }
34
34
 
35
35
  // Add custom components
36
- const globalDB = getGlobalDB()
36
+ const globalDB = tenancy.getGlobalDB()
37
37
  const response = await globalDB.allDocs(
38
- getPluginParams(null, {
38
+ dbCore.getPluginParams(null, {
39
39
  include_docs: true,
40
40
  })
41
41
  )
42
42
  response.rows
43
- .map(row => row.doc)
44
- .filter(plugin => plugin.schema.type === "component")
45
- .forEach(plugin => {
43
+ .map((row: any) => row.doc)
44
+ .filter((plugin: Plugin) => plugin.schema.type === "component")
45
+ .forEach((plugin: Plugin) => {
46
46
  const fullComponentName = `plugin/${plugin.name}`
47
47
  definitions[fullComponentName] = {
48
48
  component: fullComponentName,
@@ -1,22 +1,16 @@
1
- import { ObjectStoreBuckets } from "../../../constants"
2
- import { loadJSFile } from "../../../utilities/fileSystem"
3
1
  import { npmUpload, urlUpload, githubUpload, fileUpload } from "./uploaders"
4
2
  import { getGlobalDB } from "@budibase/backend-core/tenancy"
5
3
  import { validate } from "@budibase/backend-core/plugins"
6
- import { generatePluginID, getPluginParams } from "../../../db/utils"
7
- import {
8
- uploadDirectory,
9
- deleteFolder,
10
- } from "@budibase/backend-core/objectStore"
11
- import { PluginType, FileType, PluginSource, Plugin } from "@budibase/types"
4
+ import { PluginType, FileType, PluginSource } from "@budibase/types"
12
5
  import env from "../../../environment"
13
6
  import { ClientAppSocket } from "../../../websocket"
14
- import { events } from "@budibase/backend-core"
7
+ import { db as dbCore } from "@budibase/backend-core"
8
+ import { plugins } from "@budibase/pro"
15
9
 
16
10
  export async function getPlugins(type?: PluginType) {
17
11
  const db = getGlobalDB()
18
12
  const response = await db.allDocs(
19
- getPluginParams(null, {
13
+ dbCore.getPluginParams(null, {
20
14
  include_docs: true,
21
15
  })
22
16
  )
@@ -37,7 +31,7 @@ export async function upload(ctx: any) {
37
31
  let docs = []
38
32
  // can do single or multiple plugins
39
33
  for (let plugin of plugins) {
40
- const doc = await processPlugin(plugin, PluginSource.FILE)
34
+ const doc = await processUploadedPlugin(plugin, PluginSource.FILE)
41
35
  docs.push(doc)
42
36
  }
43
37
  ctx.body = {
@@ -91,18 +85,19 @@ export async function create(ctx: any) {
91
85
  )
92
86
  }
93
87
 
94
- const doc = await storePlugin(metadata, directory, source)
88
+ const doc = await plugins.storePlugin(metadata, directory, source)
95
89
 
90
+ ClientAppSocket.emit("plugins-update", { name, hash: doc.hash })
96
91
  ctx.body = {
97
92
  message: "Plugin uploaded successfully",
98
93
  plugins: [doc],
99
94
  }
95
+ ctx.body = { plugin: doc }
100
96
  } catch (err: any) {
101
97
  const errMsg = err?.message ? err?.message : err
102
98
 
103
99
  ctx.throw(400, `Failed to import plugin: ${errMsg}`)
104
100
  }
105
- ctx.status = 200
106
101
  }
107
102
 
108
103
  export async function fetch(ctx: any) {
@@ -110,99 +105,21 @@ export async function fetch(ctx: any) {
110
105
  }
111
106
 
112
107
  export async function destroy(ctx: any) {
113
- const db = getGlobalDB()
114
108
  const { pluginId } = ctx.params
115
109
 
116
110
  try {
117
- const plugin: Plugin = await db.get(pluginId)
118
- const bucketPath = `${plugin.name}/`
119
- await deleteFolder(ObjectStoreBuckets.PLUGINS, bucketPath)
111
+ await plugins.deletePlugin(pluginId)
120
112
 
121
- await db.remove(pluginId, plugin._rev)
122
- await events.plugin.deleted(plugin)
113
+ ctx.body = { message: `Plugin ${ctx.params.pluginId} deleted.` }
123
114
  } catch (err: any) {
124
- const errMsg = err?.message ? err?.message : err
125
-
126
- ctx.throw(400, `Failed to delete plugin: ${errMsg}`)
115
+ ctx.throw(400, err.message)
127
116
  }
128
-
129
- ctx.message = `Plugin ${ctx.params.pluginId} deleted.`
130
- ctx.status = 200
131
117
  }
132
118
 
133
- export async function storePlugin(
134
- metadata: any,
135
- directory: any,
119
+ export async function processUploadedPlugin(
120
+ plugin: FileType,
136
121
  source?: PluginSource
137
122
  ) {
138
- const db = getGlobalDB()
139
- const version = metadata.package.version,
140
- name = metadata.package.name,
141
- description = metadata.package.description,
142
- hash = metadata.schema.hash
143
-
144
- // first open the tarball into tmp directory
145
- const bucketPath = `${name}/`
146
- const files = await uploadDirectory(
147
- ObjectStoreBuckets.PLUGINS,
148
- directory,
149
- bucketPath
150
- )
151
- const jsFile = files.find((file: any) => file.name.endsWith(".js"))
152
- if (!jsFile) {
153
- throw new Error(`Plugin missing .js file.`)
154
- }
155
- // validate the JS for a datasource
156
- if (metadata.schema.type === PluginType.DATASOURCE) {
157
- const js = loadJSFile(directory, jsFile.name)
158
- // TODO: this isn't safe - but we need full node environment
159
- // in future we should do this in a thread for safety
160
- try {
161
- eval(js)
162
- } catch (err: any) {
163
- const message = err?.message ? err.message : JSON.stringify(err)
164
- throw new Error(`JS invalid: ${message}`)
165
- }
166
- }
167
- const jsFileName = jsFile.name
168
- const pluginId = generatePluginID(name)
169
-
170
- // overwrite existing docs entirely if they exist
171
- let rev
172
- try {
173
- const existing = await db.get(pluginId)
174
- rev = existing._rev
175
- } catch (err) {
176
- rev = undefined
177
- }
178
- let doc: Plugin = {
179
- _id: pluginId,
180
- _rev: rev,
181
- ...metadata,
182
- name,
183
- version,
184
- hash,
185
- description,
186
- jsUrl: `${bucketPath}${jsFileName}`,
187
- }
188
-
189
- if (source) {
190
- doc = {
191
- ...doc,
192
- source,
193
- }
194
- }
195
-
196
- const response = await db.put(doc)
197
- await events.plugin.imported(doc)
198
- ClientAppSocket.emit("plugin-update", { name, hash })
199
- return {
200
- ...doc,
201
- _rev: response.rev,
202
- }
203
- }
204
-
205
- export async function processPlugin(plugin: FileType, source?: PluginSource) {
206
123
  const { metadata, directory } = await fileUpload(plugin)
207
124
  validate(metadata?.schema)
208
125
 
@@ -211,5 +128,7 @@ export async function processPlugin(plugin: FileType, source?: PluginSource) {
211
128
  throw new Error("Only component plugins are supported outside of self-host")
212
129
  }
213
130
 
214
- return await storePlugin(metadata, directory, source)
131
+ const doc = await plugins.storePlugin(metadata, directory, source)
132
+ ClientAppSocket.emit("plugins-update", { name, hash: doc.hash })
133
+ return doc
215
134
  }
@@ -1,17 +1,16 @@
1
- const {
2
- getScreenParams,
3
- generateScreenID,
4
- getPluginParams,
5
- DocumentType,
6
- } = require("../../db/utils")
7
- const { AccessController } = require("@budibase/backend-core/roles")
8
- const { getAppDB } = require("@budibase/backend-core/context")
9
- const { events } = require("@budibase/backend-core")
10
- const { getGlobalDB } = require("@budibase/backend-core/tenancy")
11
- const { updateAppPackage } = require("./application")
1
+ import { getScreenParams, generateScreenID, DocumentType } from "../../db/utils"
2
+ import {
3
+ events,
4
+ context,
5
+ tenancy,
6
+ db as dbCore,
7
+ roles,
8
+ } from "@budibase/backend-core"
9
+ import { updateAppPackage } from "./application"
10
+ import { Plugin, ScreenProps } from "@budibase/types"
12
11
 
13
- exports.fetch = async ctx => {
14
- const db = getAppDB()
12
+ exports.fetch = async (ctx: any) => {
13
+ const db = context.getAppDB()
15
14
 
16
15
  const screens = (
17
16
  await db.allDocs(
@@ -19,16 +18,16 @@ exports.fetch = async ctx => {
19
18
  include_docs: true,
20
19
  })
21
20
  )
22
- ).rows.map(element => element.doc)
21
+ ).rows.map((el: any) => el.doc)
23
22
 
24
- ctx.body = await new AccessController().checkScreensAccess(
23
+ ctx.body = await new roles.AccessController().checkScreensAccess(
25
24
  screens,
26
25
  ctx.user.role._id
27
26
  )
28
27
  }
29
28
 
30
- exports.save = async ctx => {
31
- const db = getAppDB()
29
+ exports.save = async (ctx: any) => {
30
+ const db = context.getAppDB()
32
31
  let screen = ctx.request.body
33
32
 
34
33
  let eventFn
@@ -40,19 +39,19 @@ exports.save = async ctx => {
40
39
  const response = await db.put(screen)
41
40
 
42
41
  // Find any custom components being used
43
- let pluginNames = []
42
+ let pluginNames: string[] = []
44
43
  let pluginAdded = false
45
44
  findPlugins(screen.props, pluginNames)
46
45
  if (pluginNames.length) {
47
- const globalDB = getGlobalDB()
46
+ const globalDB = tenancy.getGlobalDB()
48
47
  const pluginsResponse = await globalDB.allDocs(
49
- getPluginParams(null, {
48
+ dbCore.getPluginParams(null, {
50
49
  include_docs: true,
51
50
  })
52
51
  )
53
52
  const requiredPlugins = pluginsResponse.rows
54
- .map(row => row.doc)
55
- .filter(plugin => {
53
+ .map((row: any) => row.doc)
54
+ .filter((plugin: Plugin) => {
56
55
  return (
57
56
  plugin.schema.type === "component" &&
58
57
  pluginNames.includes(`plugin/${plugin.name}`)
@@ -63,8 +62,8 @@ exports.save = async ctx => {
63
62
  const application = await db.get(DocumentType.APP_METADATA)
64
63
  let usedPlugins = application.usedPlugins || []
65
64
 
66
- requiredPlugins.forEach(plugin => {
67
- if (!usedPlugins.find(x => x._id === plugin._id)) {
65
+ requiredPlugins.forEach((plugin: Plugin) => {
66
+ if (!usedPlugins.find((x: Plugin) => x._id === plugin._id)) {
68
67
  pluginAdded = true
69
68
  usedPlugins.push({
70
69
  _id: plugin._id,
@@ -93,8 +92,8 @@ exports.save = async ctx => {
93
92
  }
94
93
  }
95
94
 
96
- exports.destroy = async ctx => {
97
- const db = getAppDB()
95
+ exports.destroy = async (ctx: any) => {
96
+ const db = context.getAppDB()
98
97
  const id = ctx.params.screenId
99
98
  const screen = await db.get(id)
100
99
 
@@ -107,7 +106,7 @@ exports.destroy = async ctx => {
107
106
  ctx.status = 200
108
107
  }
109
108
 
110
- const findPlugins = (component, foundPlugins) => {
109
+ const findPlugins = (component: ScreenProps, foundPlugins: string[]) => {
111
110
  if (!component) {
112
111
  return
113
112
  }
package/src/db/utils.js CHANGED
@@ -42,7 +42,6 @@ const DocumentType = {
42
42
  MEM_VIEW: "view",
43
43
  USER_FLAG: "flag",
44
44
  AUTOMATION_METADATA: "meta_au",
45
- PLUGIN: "plg",
46
45
  }
47
46
 
48
47
  const InternalTables = {
@@ -384,10 +383,3 @@ exports.getMultiIDParams = ids => {
384
383
  include_docs: true,
385
384
  }
386
385
  }
387
-
388
- /**
389
- * Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
390
- */
391
- exports.getPluginParams = (pluginId = null, otherProps = {}) => {
392
- return getDocParams(DocumentType.PLUGIN, pluginId, otherProps)
393
- }
@@ -112,13 +112,6 @@ exports.loadHandlebarsFile = path => {
112
112
  return fs.readFileSync(path, "utf8")
113
113
  }
114
114
 
115
- /**
116
- * Same as above just with a different name.
117
- */
118
- exports.loadJSFile = (directory, name) => {
119
- return fs.readFileSync(join(directory, name), "utf8")
120
- }
121
-
122
115
  /**
123
116
  * When return a file from the API need to write the file to the system temporarily so we
124
117
  * can create a read stream to send.
package/src/watch.ts CHANGED
@@ -4,7 +4,7 @@ import chokidar from "chokidar"
4
4
  import fs from "fs"
5
5
  import { tenancy } from "@budibase/backend-core"
6
6
  import { DEFAULT_TENANT_ID } from "@budibase/backend-core/constants"
7
- import { processPlugin } from "./api/controllers/plugin"
7
+ import { processUploadedPlugin } from "./api/controllers/plugin"
8
8
 
9
9
  export function watch() {
10
10
  const watchPath = path.join(env.PLUGINS_DIR, "./**/*.tar.gz")
@@ -28,7 +28,7 @@ export function watch() {
28
28
  const split = path.split("/")
29
29
  const name = split[split.length - 1]
30
30
  console.log("Importing plugin:", path)
31
- await processPlugin({ name, path })
31
+ await processUploadedPlugin({ name, path })
32
32
  } catch (err: any) {
33
33
  const message = err?.message ? err?.message : err
34
34
  console.error("Failed to import plugin:", message)