@budibase/server 1.3.15-alpha.0 → 1.3.16

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 (252) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/builder/assets/index.43e7aaa8.js +876 -0
  3. package/builder/assets/{index.f5c54dd2.css → index.a70e216a.css} +2 -2
  4. package/builder/assets/vendor.5e1fe644.css +1 -0
  5. package/builder/assets/vendor.67dbd8fa.js +248 -0
  6. package/builder/index.html +4 -2
  7. package/coverage/clover.xml +254 -296
  8. package/coverage/coverage-final.json +17 -17
  9. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +13 -82
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +20 -20
  16. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +30 -30
  18. package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
  19. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/screen.js.html +12 -204
  34. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  47. package/coverage/lcov-report/api/index.html +1 -1
  48. package/coverage/lcov-report/api/index.js.html +12 -12
  49. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/index.html +1 -1
  60. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  74. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  77. package/coverage/lcov-report/automations/actions.js.html +1 -1
  78. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  79. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  80. package/coverage/lcov-report/automations/index.html +1 -1
  81. package/coverage/lcov-report/automations/index.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/index.html +1 -1
  89. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  108. package/coverage/lcov-report/constants/index.html +1 -1
  109. package/coverage/lcov-report/constants/index.js.html +1 -1
  110. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  111. package/coverage/lcov-report/constants/screens.js.html +1 -1
  112. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  113. package/coverage/lcov-report/db/index.html +18 -18
  114. package/coverage/lcov-report/db/index.js.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  116. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  117. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  118. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  119. package/coverage/lcov-report/db/newid.js.html +2 -2
  120. package/coverage/lcov-report/db/utils.js.html +20 -56
  121. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  122. package/coverage/lcov-report/events/index.html +1 -1
  123. package/coverage/lcov-report/events/index.js.html +1 -1
  124. package/coverage/lcov-report/events/utils.js.html +1 -1
  125. package/coverage/lcov-report/index.html +28 -28
  126. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  127. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  128. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  129. package/coverage/lcov-report/middleware/builder.js.html +12 -12
  130. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  131. package/coverage/lcov-report/middleware/index.html +1 -1
  132. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  133. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  134. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  135. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  136. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  137. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  138. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  139. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  140. package/coverage/lcov-report/utilities/global.js.html +16 -16
  141. package/coverage/lcov-report/utilities/index.html +1 -1
  142. package/coverage/lcov-report/utilities/index.js.html +24 -24
  143. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  144. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  145. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  146. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  147. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  148. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  149. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  150. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  151. package/coverage/lcov-report/utilities/security.js.html +2 -2
  152. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  153. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  154. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  155. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  156. package/coverage/lcov-report/utilities/users.js.html +1 -1
  157. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  158. package/coverage/lcov.info +445 -533
  159. package/dist/api/controllers/application.js +4 -5
  160. package/dist/api/controllers/component.js +1 -18
  161. package/dist/api/controllers/datasource.js +4 -4
  162. package/dist/api/controllers/integration.js +4 -4
  163. package/dist/api/controllers/row/ExternalRequest.js +3 -1
  164. package/dist/api/controllers/screen.js +2 -51
  165. package/dist/api/controllers/static/index.js +0 -1
  166. package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -10
  167. package/dist/api/controllers/static/templates/preview.hbs +1 -3
  168. package/dist/api/routes/index.js +0 -2
  169. package/dist/app.js +0 -9
  170. package/dist/db/utils.js +1 -10
  171. package/dist/environment.js +2 -3
  172. package/dist/integrations/airtable.js +129 -126
  173. package/dist/integrations/arangodb.js +89 -86
  174. package/dist/integrations/base/query.js +2 -2
  175. package/dist/integrations/couchdb.js +83 -80
  176. package/dist/integrations/dynamodb.js +164 -161
  177. package/dist/integrations/elasticsearch.js +138 -135
  178. package/dist/integrations/firebase.js +157 -154
  179. package/dist/integrations/googlesheets.js +327 -323
  180. package/dist/integrations/index.js +51 -93
  181. package/dist/integrations/microsoftSqlServer.js +243 -240
  182. package/dist/integrations/mongodb.js +242 -239
  183. package/dist/integrations/mysql.js +219 -215
  184. package/dist/integrations/oracle.js +322 -318
  185. package/dist/integrations/postgres.js +265 -262
  186. package/dist/integrations/redis.js +139 -134
  187. package/dist/integrations/rest.js +292 -289
  188. package/dist/integrations/s3.js +64 -61
  189. package/dist/integrations/snowflake.js +86 -83
  190. package/dist/package.json +6 -8
  191. package/dist/threads/query.js +2 -2
  192. package/dist/tsconfig.build.tsbuildinfo +1 -1
  193. package/dist/utilities/fileSystem/index.js +10 -66
  194. package/package.json +7 -9
  195. package/scripts/dev/manage.js +0 -1
  196. package/src/api/controllers/application.ts +1 -1
  197. package/src/api/controllers/component.js +2 -25
  198. package/src/api/controllers/datasource.js +4 -4
  199. package/src/api/controllers/integration.js +4 -4
  200. package/src/api/controllers/row/ExternalRequest.ts +4 -1
  201. package/src/api/controllers/screen.js +1 -65
  202. package/src/api/controllers/static/index.ts +0 -1
  203. package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -10
  204. package/src/api/controllers/static/templates/preview.hbs +1 -3
  205. package/src/api/routes/index.ts +0 -2
  206. package/src/api/routes/tests/query.spec.js +25 -8
  207. package/src/app.ts +0 -12
  208. package/src/db/utils.js +0 -12
  209. package/src/environment.js +2 -3
  210. package/src/integrations/airtable.ts +118 -116
  211. package/src/integrations/arangodb.ts +89 -87
  212. package/src/integrations/base/query.ts +2 -2
  213. package/src/integrations/couchdb.ts +89 -83
  214. package/src/integrations/dynamodb.ts +175 -173
  215. package/src/integrations/elasticsearch.ts +122 -120
  216. package/src/integrations/firebase.ts +159 -157
  217. package/src/integrations/googlesheets.ts +338 -328
  218. package/src/integrations/index.ts +21 -59
  219. package/src/integrations/microsoftSqlServer.ts +251 -249
  220. package/src/integrations/mongodb.ts +258 -261
  221. package/src/integrations/mysql.ts +234 -229
  222. package/src/integrations/oracle.ts +380 -373
  223. package/src/integrations/postgres.ts +268 -264
  224. package/src/integrations/redis.ts +132 -128
  225. package/src/integrations/rest.ts +329 -324
  226. package/src/integrations/s3.ts +71 -68
  227. package/src/integrations/snowflake.ts +82 -80
  228. package/src/integrations/tests/{airtable.spec.ts → airtable.spec.js} +18 -21
  229. package/src/integrations/tests/{arangodb.spec.ts → arangodb.spec.js} +9 -12
  230. package/src/integrations/tests/{couchdb.spec.ts → couchdb.spec.js} +27 -33
  231. package/src/integrations/tests/{dynamodb.spec.ts → dynamodb.spec.js} +41 -45
  232. package/src/integrations/tests/{elasticsearch.spec.ts → elasticsearch.spec.js} +21 -22
  233. package/src/integrations/tests/{firebase.spec.ts → firebase.spec.js} +28 -33
  234. package/src/integrations/tests/{microsoftSqlServer.spec.ts → microsoftSqlServer.spec.js} +11 -12
  235. package/src/integrations/tests/{mongo.spec.ts → mongo.spec.js} +35 -46
  236. package/src/integrations/tests/{mysql.spec.ts → mysql.spec.js} +15 -17
  237. package/src/integrations/tests/{oracle.spec.ts → oracle.spec.js} +17 -19
  238. package/src/integrations/tests/{postgres.spec.ts → postgres.spec.js} +17 -19
  239. package/src/integrations/tests/{redis.spec.ts → redis.spec.js} +18 -27
  240. package/src/integrations/tests/{rest.spec.ts → rest.spec.js} +14 -22
  241. package/src/integrations/tests/{s3.spec.ts → s3.spec.js} +8 -10
  242. package/src/integrations/tests/{sql.spec.ts → sql.spec.js} +177 -228
  243. package/src/module.d.ts +0 -1
  244. package/src/threads/query.ts +2 -2
  245. package/src/utilities/fileSystem/index.js +9 -70
  246. package/builder/assets/index.b266d29f.js +0 -995
  247. package/dist/api/controllers/plugin.js +0 -119
  248. package/dist/api/routes/plugin.js +0 -38
  249. package/dist/watch.js +0 -77
  250. package/src/api/controllers/plugin.ts +0 -110
  251. package/src/api/routes/plugin.ts +0 -13
  252. package/src/watch.ts +0 -38
@@ -1,119 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.processPlugin = exports.destroy = exports.fetch = exports.upload = exports.getPlugins = void 0;
16
- const constants_1 = require("../../constants");
17
- const fileSystem_1 = require("../../utilities/fileSystem");
18
- const tenancy_1 = require("@budibase/backend-core/tenancy");
19
- const utils_1 = require("../../db/utils");
20
- const objectStore_1 = require("@budibase/backend-core/objectStore");
21
- const types_1 = require("@budibase/types");
22
- const environment_1 = __importDefault(require("../../environment"));
23
- function getPlugins(type) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const db = (0, tenancy_1.getGlobalDB)();
26
- const response = yield db.allDocs((0, utils_1.getPluginParams)(null, {
27
- include_docs: true,
28
- }));
29
- const plugins = response.rows.map((row) => row.doc);
30
- if (type) {
31
- return plugins.filter((plugin) => { var _a; return ((_a = plugin.schema) === null || _a === void 0 ? void 0 : _a.type) === type; });
32
- }
33
- else {
34
- return plugins;
35
- }
36
- });
37
- }
38
- exports.getPlugins = getPlugins;
39
- function upload(ctx) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const plugins = ctx.request.files.file.length > 1
42
- ? Array.from(ctx.request.files.file)
43
- : [ctx.request.files.file];
44
- try {
45
- let docs = [];
46
- // can do single or multiple plugins
47
- for (let plugin of plugins) {
48
- const doc = yield processPlugin(plugin);
49
- docs.push(doc);
50
- }
51
- ctx.body = {
52
- message: "Plugin(s) uploaded successfully",
53
- plugins: docs,
54
- };
55
- }
56
- catch (err) {
57
- const errMsg = (err === null || err === void 0 ? void 0 : err.message) ? err === null || err === void 0 ? void 0 : err.message : err;
58
- ctx.throw(400, `Failed to import plugin: ${errMsg}`);
59
- }
60
- });
61
- }
62
- exports.upload = upload;
63
- function fetch(ctx) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- ctx.body = yield getPlugins();
66
- });
67
- }
68
- exports.fetch = fetch;
69
- function destroy(ctx) {
70
- return __awaiter(this, void 0, void 0, function* () { });
71
- }
72
- exports.destroy = destroy;
73
- function processPlugin(plugin) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- if (!environment_1.default.SELF_HOSTED) {
76
- throw new Error("Plugins not supported outside of self-host.");
77
- }
78
- const db = (0, tenancy_1.getGlobalDB)();
79
- const { metadata, directory } = yield (0, fileSystem_1.extractPluginTarball)(plugin);
80
- const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description;
81
- // first open the tarball into tmp directory
82
- const bucketPath = `${name}/`;
83
- const files = yield (0, objectStore_1.uploadDirectory)(constants_1.ObjectStoreBuckets.PLUGINS, directory, bucketPath);
84
- const jsFile = files.find((file) => file.name.endsWith(".js"));
85
- if (!jsFile) {
86
- throw new Error(`Plugin missing .js file.`);
87
- }
88
- // validate the JS for a datasource
89
- if (metadata.schema.type === types_1.PluginType.DATASOURCE) {
90
- const js = (0, fileSystem_1.loadJSFile)(directory, jsFile.name);
91
- // TODO: this isn't safe - but we need full node environment
92
- // in future we should do this in a thread for safety
93
- try {
94
- eval(js);
95
- }
96
- catch (err) {
97
- const message = (err === null || err === void 0 ? void 0 : err.message) ? err.message : JSON.stringify(err);
98
- throw new Error(`JS invalid: ${message}`);
99
- }
100
- }
101
- const jsFileName = jsFile.name;
102
- const pluginId = (0, utils_1.generatePluginID)(name);
103
- // overwrite existing docs entirely if they exist
104
- let rev;
105
- try {
106
- const existing = yield db.get(pluginId);
107
- rev = existing._rev;
108
- }
109
- catch (err) {
110
- rev = undefined;
111
- }
112
- const doc = Object.assign(Object.assign({ _id: pluginId, _rev: rev }, metadata), { name,
113
- version,
114
- description, jsUrl: `${bucketPath}${jsFileName}` });
115
- const response = yield db.put(doc);
116
- return Object.assign(Object.assign({}, doc), { _rev: response.rev });
117
- });
118
- }
119
- exports.processPlugin = processPlugin;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const router_1 = __importDefault(require("@koa/router"));
30
- const controller = __importStar(require("../controllers/plugin"));
31
- const authorized_1 = __importDefault(require("../../middleware/authorized"));
32
- const permissions_1 = require("@budibase/backend-core/permissions");
33
- const router = new router_1.default();
34
- router
35
- .post("/api/plugin/upload", (0, authorized_1.default)(permissions_1.BUILDER), controller.upload)
36
- .get("/api/plugin", (0, authorized_1.default)(permissions_1.BUILDER), controller.fetch)
37
- .delete("/api/plugin/:pluginId", (0, authorized_1.default)(permissions_1.BUILDER), controller.destroy);
38
- exports.default = router;
package/dist/watch.js DELETED
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.watch = void 0;
39
- const path_1 = __importDefault(require("path"));
40
- const env = __importStar(require("./environment"));
41
- const chokidar_1 = __importDefault(require("chokidar"));
42
- const fs_1 = __importDefault(require("fs"));
43
- const backend_core_1 = require("@budibase/backend-core");
44
- const constants_1 = require("@budibase/backend-core/constants");
45
- const plugin_1 = require("./api/controllers/plugin");
46
- function watch() {
47
- const watchPath = path_1.default.join(env.PLUGINS_DIR, "./**/*.tar.gz");
48
- chokidar_1.default
49
- .watch(watchPath, {
50
- ignored: "**/node_modules",
51
- awaitWriteFinish: {
52
- pollInterval: 100,
53
- stabilityThreshold: 250,
54
- },
55
- usePolling: true,
56
- interval: 250,
57
- })
58
- .on("all", (event, path) => __awaiter(this, void 0, void 0, function* () {
59
- // Sanity checks
60
- if (!(path === null || path === void 0 ? void 0 : path.endsWith(".tar.gz")) || !fs_1.default.existsSync(path)) {
61
- return;
62
- }
63
- yield backend_core_1.tenancy.doInTenant(constants_1.DEFAULT_TENANT_ID, () => __awaiter(this, void 0, void 0, function* () {
64
- try {
65
- const split = path.split("/");
66
- const name = split[split.length - 1];
67
- console.log("Importing plugin:", path);
68
- yield (0, plugin_1.processPlugin)({ name, path });
69
- }
70
- catch (err) {
71
- const message = (err === null || err === void 0 ? void 0 : err.message) ? err === null || err === void 0 ? void 0 : err.message : err;
72
- console.error("Failed to import plugin:", message);
73
- }
74
- }));
75
- }));
76
- }
77
- exports.watch = watch;
@@ -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
- }
@@ -1,13 +0,0 @@
1
- import Router from "@koa/router"
2
- import * as controller from "../controllers/plugin"
3
- import authorized from "../../middleware/authorized"
4
- import { BUILDER } from "@budibase/backend-core/permissions"
5
-
6
- const router = new Router()
7
-
8
- router
9
- .post("/api/plugin/upload", authorized(BUILDER), controller.upload)
10
- .get("/api/plugin", authorized(BUILDER), controller.fetch)
11
- .delete("/api/plugin/:pluginId", authorized(BUILDER), controller.destroy)
12
-
13
- export default router
package/src/watch.ts DELETED
@@ -1,38 +0,0 @@
1
- import path from "path"
2
- import * as env from "./environment"
3
- import chokidar from "chokidar"
4
- import fs from "fs"
5
- import { tenancy } from "@budibase/backend-core"
6
- import { DEFAULT_TENANT_ID } from "@budibase/backend-core/constants"
7
- import { processPlugin } from "./api/controllers/plugin"
8
-
9
- export function watch() {
10
- const watchPath = path.join(env.PLUGINS_DIR, "./**/*.tar.gz")
11
- chokidar
12
- .watch(watchPath, {
13
- ignored: "**/node_modules",
14
- awaitWriteFinish: {
15
- pollInterval: 100,
16
- stabilityThreshold: 250,
17
- },
18
- usePolling: true,
19
- interval: 250,
20
- })
21
- .on("all", async (event: string, path: string) => {
22
- // Sanity checks
23
- if (!path?.endsWith(".tar.gz") || !fs.existsSync(path)) {
24
- return
25
- }
26
- await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => {
27
- try {
28
- const split = path.split("/")
29
- const name = split[split.length - 1]
30
- console.log("Importing plugin:", path)
31
- await processPlugin({ name, path })
32
- } catch (err: any) {
33
- const message = err?.message ? err?.message : err
34
- console.error("Failed to import plugin:", message)
35
- }
36
- })
37
- })
38
- }