@budibase/server 2.0.30-alpha.14 → 2.0.30-alpha.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 (228) hide show
  1. package/builder/assets/backups-default.8c011f1b.png +0 -0
  2. package/builder/assets/{index.099ad307.js → index.7ebb4fb6.js} +333 -329
  3. package/builder/assets/{index.acdbfe62.css → index.b15ffe95.css} +1 -1
  4. package/builder/index.html +2 -2
  5. package/coverage/clover.xml +254 -313
  6. package/coverage/coverage-final.json +15 -17
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/cloud.js.html +74 -62
  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 +17 -32
  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 +12 -9
  30. package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
  31. package/coverage/lcov-report/api/controllers/table/index.html +16 -16
  32. package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
  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 +3 -3
  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 +3 -3
  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/automation.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/index.html +5 -20
  52. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  66. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  69. package/coverage/lcov-report/automations/actions.js.html +1 -1
  70. package/coverage/lcov-report/automations/automationUtils.js.html +6 -6
  71. package/coverage/lcov-report/automations/bullboard.js.html +17 -92
  72. package/coverage/lcov-report/automations/index.html +18 -18
  73. package/coverage/lcov-report/automations/index.js.html +5 -5
  74. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  75. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  76. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  77. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  78. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/index.html +1 -1
  81. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  91. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  92. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  93. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  94. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggers.js.html +5 -5
  100. package/coverage/lcov-report/constants/index.html +5 -5
  101. package/coverage/lcov-report/constants/index.js.html +6 -18
  102. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  103. package/coverage/lcov-report/constants/screens.js.html +1 -1
  104. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  105. package/coverage/lcov-report/db/index.html +19 -19
  106. package/coverage/lcov-report/db/index.js.html +1 -1
  107. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  108. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  109. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  110. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  111. package/coverage/lcov-report/db/newid.js.html +2 -2
  112. package/coverage/lcov-report/db/utils.js.html +35 -308
  113. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  114. package/coverage/lcov-report/events/index.html +1 -1
  115. package/coverage/lcov-report/events/index.js.html +1 -1
  116. package/coverage/lcov-report/events/utils.js.html +1 -1
  117. package/coverage/lcov-report/index.html +62 -62
  118. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  119. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  120. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  121. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  122. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  123. package/coverage/lcov-report/middleware/index.html +1 -1
  124. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  125. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  126. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  127. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  128. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  129. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  130. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  131. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  132. package/coverage/lcov-report/utilities/global.js.html +1 -1
  133. package/coverage/lcov-report/utilities/index.html +1 -1
  134. package/coverage/lcov-report/utilities/index.js.html +1 -1
  135. package/coverage/lcov-report/utilities/plugins.js.html +1 -1
  136. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
  137. package/coverage/lcov-report/utilities/queue/index.html +21 -21
  138. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  139. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  140. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  141. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  142. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  143. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  144. package/coverage/lcov-report/utilities/security.js.html +2 -2
  145. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  146. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  147. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  148. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  149. package/coverage/lcov-report/utilities/users.js.html +1 -1
  150. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  151. package/coverage/lcov.info +451 -564
  152. package/dist/api/controllers/application.js +2 -5
  153. package/dist/api/controllers/backup.js +19 -13
  154. package/dist/api/controllers/cloud.js +38 -35
  155. package/dist/api/controllers/deploy/index.js +11 -2
  156. package/dist/api/controllers/static/index.js +2 -2
  157. package/dist/api/controllers/table/bulkFormula.js +4 -3
  158. package/dist/api/controllers/table/external.js +5 -4
  159. package/dist/api/controllers/table/index.js +4 -4
  160. package/dist/api/controllers/table/internal.js +2 -1
  161. package/dist/api/controllers/table/utils.js +4 -48
  162. package/dist/api/controllers/view/index.js +2 -2
  163. package/dist/api/routes/backup.js +34 -7
  164. package/dist/api/routes/index.js +9 -4
  165. package/dist/app.js +14 -0
  166. package/dist/automations/automationUtils.js +2 -2
  167. package/dist/automations/bullboard.js +5 -33
  168. package/dist/automations/index.js +4 -4
  169. package/dist/automations/triggers.js +4 -4
  170. package/dist/automations/utils.js +13 -9
  171. package/dist/constants/index.js +2 -5
  172. package/dist/db/utils.js +10 -75
  173. package/dist/migrations/functions/backfill/app/tables.js +5 -8
  174. package/dist/package.json +11 -11
  175. package/dist/sdk/app/backups/constants.js +5 -0
  176. package/dist/sdk/app/backups/exports.js +172 -0
  177. package/dist/sdk/app/backups/imports.js +162 -0
  178. package/dist/sdk/app/backups/index.js +29 -0
  179. package/dist/sdk/app/backups/statistics.js +73 -0
  180. package/dist/sdk/app/tables/index.js +61 -0
  181. package/dist/sdk/index.js +15 -0
  182. package/dist/tests/utilities/TestConfiguration.js +4 -2
  183. package/dist/threads/automation.js +12 -17
  184. package/dist/tsconfig.build.tsbuildinfo +1 -1
  185. package/dist/utilities/fileSystem/index.js +3 -95
  186. package/dist/utilities/fileSystem/utilities.js +2 -1
  187. package/package.json +12 -12
  188. package/src/api/controllers/application.ts +3 -10
  189. package/src/api/controllers/{backup.js → backup.ts} +7 -7
  190. package/src/api/controllers/cloud.js +44 -40
  191. package/src/api/controllers/deploy/index.ts +20 -7
  192. package/src/api/controllers/static/index.ts +2 -2
  193. package/src/api/controllers/table/bulkFormula.js +4 -3
  194. package/src/api/controllers/table/external.js +4 -4
  195. package/src/api/controllers/table/index.js +4 -4
  196. package/src/api/controllers/table/internal.ts +3 -7
  197. package/src/api/controllers/table/utils.ts +1 -52
  198. package/src/api/controllers/view/index.js +2 -2
  199. package/src/api/routes/backup.ts +10 -0
  200. package/src/api/routes/index.ts +11 -5
  201. package/src/api/routes/tests/backup.spec.js +1 -1
  202. package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
  203. package/src/app.ts +15 -0
  204. package/src/automations/automationUtils.js +2 -2
  205. package/src/automations/bullboard.js +8 -33
  206. package/src/automations/index.js +4 -4
  207. package/src/automations/triggers.js +4 -4
  208. package/src/automations/utils.ts +12 -8
  209. package/src/constants/index.js +2 -6
  210. package/src/db/utils.js +17 -108
  211. package/src/definitions/automations.ts +0 -12
  212. package/src/migrations/functions/backfill/app/tables.ts +6 -13
  213. package/src/sdk/app/backups/constants.ts +2 -0
  214. package/src/sdk/app/backups/exports.ts +171 -0
  215. package/src/sdk/app/backups/imports.ts +168 -0
  216. package/src/sdk/app/backups/index.ts +9 -0
  217. package/src/sdk/app/backups/statistics.ts +77 -0
  218. package/src/sdk/app/tables/index.ts +60 -0
  219. package/src/sdk/index.ts +13 -0
  220. package/src/tests/utilities/TestConfiguration.js +5 -2
  221. package/src/threads/automation.ts +20 -27
  222. package/src/utilities/fileSystem/index.js +2 -119
  223. package/src/utilities/fileSystem/utilities.js +2 -0
  224. package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
  225. package/coverage/lcov-report/api/routes/backup.js.html +0 -115
  226. package/dist/automations/listeners.js +0 -102
  227. package/src/api/routes/backup.js +0 -10
  228. package/src/automations/listeners.ts +0 -78
@@ -0,0 +1,162 @@
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.importApp = exports.getListOfAppsInMulti = exports.getGlobalDBFile = exports.untarFile = void 0;
16
+ const backend_core_1 = require("@budibase/backend-core");
17
+ const utils_1 = require("../../../db/utils");
18
+ const budibaseDir_1 = require("../../../utilities/budibaseDir");
19
+ const constants_1 = require("./constants");
20
+ const utilities_1 = require("../../../utilities/fileSystem/utilities");
21
+ const fileSystem_1 = require("../../../utilities/fileSystem");
22
+ const constants_2 = require("../../../constants");
23
+ const path_1 = require("path");
24
+ const fs_1 = __importDefault(require("fs"));
25
+ const __1 = __importDefault(require("../../"));
26
+ const uuid = require("uuid/v4");
27
+ const tar = require("tar");
28
+ function updateAttachmentColumns(prodAppId, db) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ // iterate through attachment documents and update them
31
+ const tables = yield __1.default.tables.getAllInternalTables(db);
32
+ for (let table of tables) {
33
+ const attachmentCols = [];
34
+ for (let [key, column] of Object.entries(table.schema)) {
35
+ if (column.type === constants_2.FieldTypes.ATTACHMENT) {
36
+ attachmentCols.push(key);
37
+ }
38
+ }
39
+ // no attachment columns, nothing to do
40
+ if (attachmentCols.length === 0) {
41
+ continue;
42
+ }
43
+ // use the CouchDB Mango query API to lookup rows that have attachments
44
+ const params = {
45
+ selector: {
46
+ _id: {
47
+ $regex: `^${utils_1.TABLE_ROW_PREFIX}`,
48
+ },
49
+ },
50
+ };
51
+ attachmentCols.forEach(col => (params.selector[col] = { $exists: true }));
52
+ const { rows } = yield backend_core_1.db.directCouchFind(db.name, params);
53
+ for (let row of rows) {
54
+ for (let column of attachmentCols) {
55
+ if (!Array.isArray(row[column])) {
56
+ continue;
57
+ }
58
+ row[column] = row[column].map((attachment) => {
59
+ // URL looks like: /prod-budi-app-assets/appId/attachments/file.csv
60
+ const urlParts = attachment.url.split("/");
61
+ // drop the first empty element
62
+ urlParts.shift();
63
+ // get the prefix
64
+ const prefix = urlParts.shift();
65
+ // remove the app ID
66
+ urlParts.shift();
67
+ // add new app ID
68
+ urlParts.unshift(prodAppId);
69
+ const key = urlParts.join("/");
70
+ return Object.assign(Object.assign({}, attachment), { key, url: `/${prefix}/${key}` });
71
+ });
72
+ }
73
+ }
74
+ // write back the updated attachments
75
+ yield db.bulkDocs(rows);
76
+ }
77
+ });
78
+ }
79
+ /**
80
+ * This function manages temporary template files which are stored by Koa.
81
+ * @param {Object} template The template object retrieved from the Koa context object.
82
+ * @returns {Object} Returns a fs read stream which can be loaded into the database.
83
+ */
84
+ function getTemplateStream(template) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ if (template.file) {
87
+ return fs_1.default.createReadStream(template.file.path);
88
+ }
89
+ else if (template.key) {
90
+ const [type, name] = template.key.split("/");
91
+ const tmpPath = yield (0, fileSystem_1.downloadTemplate)(type, name);
92
+ return fs_1.default.createReadStream((0, path_1.join)(tmpPath, name, "db", "dump.txt"));
93
+ }
94
+ });
95
+ }
96
+ function untarFile(file) {
97
+ const tmpPath = (0, path_1.join)((0, budibaseDir_1.budibaseTempDir)(), uuid());
98
+ fs_1.default.mkdirSync(tmpPath);
99
+ // extract the tarball
100
+ tar.extract({
101
+ sync: true,
102
+ cwd: tmpPath,
103
+ file: file.path,
104
+ });
105
+ return tmpPath;
106
+ }
107
+ exports.untarFile = untarFile;
108
+ function getGlobalDBFile(tmpPath) {
109
+ return fs_1.default.readFileSync((0, path_1.join)(tmpPath, constants_1.GLOBAL_DB_EXPORT_FILE), "utf8");
110
+ }
111
+ exports.getGlobalDBFile = getGlobalDBFile;
112
+ function getListOfAppsInMulti(tmpPath) {
113
+ return fs_1.default.readdirSync(tmpPath).filter(dir => dir !== constants_1.GLOBAL_DB_EXPORT_FILE);
114
+ }
115
+ exports.getListOfAppsInMulti = getListOfAppsInMulti;
116
+ function importApp(appId, db, template) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ let prodAppId = backend_core_1.db.getProdAppID(appId);
119
+ let dbStream;
120
+ const isTar = template.file && template.file.type === "application/gzip";
121
+ const isDirectory = template.file && fs_1.default.lstatSync(template.file.path).isDirectory();
122
+ if (template.file && (isTar || isDirectory)) {
123
+ const tmpPath = isTar ? untarFile(template.file) : template.file.path;
124
+ const contents = fs_1.default.readdirSync(tmpPath);
125
+ // have to handle object import
126
+ if (contents.length) {
127
+ let promises = [];
128
+ let excludedFiles = [constants_1.GLOBAL_DB_EXPORT_FILE, constants_1.DB_EXPORT_FILE];
129
+ for (let filename of contents) {
130
+ const path = (0, path_1.join)(tmpPath, filename);
131
+ if (excludedFiles.includes(filename)) {
132
+ continue;
133
+ }
134
+ filename = (0, path_1.join)(prodAppId, filename);
135
+ if (fs_1.default.lstatSync(path).isDirectory()) {
136
+ promises.push((0, utilities_1.uploadDirectory)(constants_2.ObjectStoreBuckets.APPS, path, filename));
137
+ }
138
+ else {
139
+ promises.push((0, utilities_1.upload)({
140
+ bucket: constants_2.ObjectStoreBuckets.APPS,
141
+ path,
142
+ filename,
143
+ }));
144
+ }
145
+ }
146
+ yield Promise.all(promises);
147
+ }
148
+ dbStream = fs_1.default.createReadStream((0, path_1.join)(tmpPath, constants_1.DB_EXPORT_FILE));
149
+ }
150
+ else {
151
+ dbStream = yield getTemplateStream(template);
152
+ }
153
+ // @ts-ignore
154
+ const { ok } = yield db.load(dbStream);
155
+ if (!ok) {
156
+ throw "Error loading database dump from template.";
157
+ }
158
+ yield updateAttachmentColumns(prodAppId, db);
159
+ return ok;
160
+ });
161
+ }
162
+ exports.importApp = importApp;
@@ -0,0 +1,29 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const exportApps = __importStar(require("./exports"));
27
+ const importApps = __importStar(require("./imports"));
28
+ const statistics = __importStar(require("./statistics"));
29
+ exports.default = Object.assign(Object.assign(Object.assign({}, exportApps), importApps), statistics);
@@ -0,0 +1,73 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.calculateBackupStats = exports.calculateScreenCount = exports.calculateAutomationCount = exports.calculateDatasourceCount = void 0;
13
+ const backend_core_1 = require("@budibase/backend-core");
14
+ const utils_1 = require("../../../db/utils");
15
+ function runInContext(appId, cb, db) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ if (db) {
18
+ return cb(db);
19
+ }
20
+ else {
21
+ const devAppId = backend_core_1.db.getDevAppID(appId);
22
+ return backend_core_1.context.doInAppContext(devAppId, () => {
23
+ const db = backend_core_1.context.getAppDB();
24
+ return cb(db);
25
+ });
26
+ }
27
+ });
28
+ }
29
+ function calculateDatasourceCount(appId, db) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return runInContext(appId, (db) => __awaiter(this, void 0, void 0, function* () {
32
+ const datasourceList = yield db.allDocs((0, utils_1.getDatasourceParams)());
33
+ const tableList = yield db.allDocs((0, utils_1.getTableParams)());
34
+ return datasourceList.rows.length + tableList.rows.length;
35
+ }), db);
36
+ });
37
+ }
38
+ exports.calculateDatasourceCount = calculateDatasourceCount;
39
+ function calculateAutomationCount(appId, db) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return runInContext(appId, (db) => __awaiter(this, void 0, void 0, function* () {
42
+ const automationList = yield db.allDocs((0, utils_1.getAutomationParams)());
43
+ return automationList.rows.length;
44
+ }), db);
45
+ });
46
+ }
47
+ exports.calculateAutomationCount = calculateAutomationCount;
48
+ function calculateScreenCount(appId, db) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ return runInContext(appId, (db) => __awaiter(this, void 0, void 0, function* () {
51
+ const screenList = yield db.allDocs((0, utils_1.getScreenParams)());
52
+ return screenList.rows.length;
53
+ }), db);
54
+ });
55
+ }
56
+ exports.calculateScreenCount = calculateScreenCount;
57
+ function calculateBackupStats(appId) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ return runInContext(appId, (db) => __awaiter(this, void 0, void 0, function* () {
60
+ const promises = [];
61
+ promises.push(calculateDatasourceCount(appId, db));
62
+ promises.push(calculateAutomationCount(appId, db));
63
+ promises.push(calculateScreenCount(appId, db));
64
+ const responses = yield Promise.all(promises);
65
+ return {
66
+ datasources: responses[0],
67
+ automations: responses[1],
68
+ screens: responses[2],
69
+ };
70
+ }));
71
+ });
72
+ }
73
+ exports.calculateBackupStats = calculateBackupStats;
@@ -0,0 +1,61 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const context_1 = require("@budibase/backend-core/context");
13
+ const utils_1 = require("../../../db/utils");
14
+ const utils_2 = require("../../../integrations/utils");
15
+ function getAllInternalTables(db) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ if (!db) {
18
+ db = (0, context_1.getAppDB)();
19
+ }
20
+ const internalTables = yield db.allDocs((0, utils_1.getTableParams)(null, {
21
+ include_docs: true,
22
+ }));
23
+ return internalTables.rows.map((tableDoc) => (Object.assign(Object.assign({}, tableDoc.doc), { type: "internal", sourceId: utils_1.BudibaseInternalDB._id })));
24
+ });
25
+ }
26
+ function getAllExternalTables(datasourceId) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const db = (0, context_1.getAppDB)();
29
+ const datasource = yield db.get(datasourceId);
30
+ if (!datasource || !datasource.entities) {
31
+ throw "Datasource is not configured fully.";
32
+ }
33
+ return datasource.entities;
34
+ });
35
+ }
36
+ function getExternalTable(datasourceId, tableName) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const entities = yield getAllExternalTables(datasourceId);
39
+ return entities[tableName];
40
+ });
41
+ }
42
+ function getTable(tableId) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const db = (0, context_1.getAppDB)();
45
+ if ((0, utils_2.isExternalTable)(tableId)) {
46
+ let { datasourceId, tableName } = (0, utils_2.breakExternalTableId)(tableId);
47
+ const datasource = yield db.get(datasourceId);
48
+ const table = yield getExternalTable(datasourceId, tableName);
49
+ return Object.assign(Object.assign({}, table), { sql: (0, utils_2.isSQL)(datasource) });
50
+ }
51
+ else {
52
+ return db.get(tableId);
53
+ }
54
+ });
55
+ }
56
+ exports.default = {
57
+ getAllInternalTables,
58
+ getAllExternalTables,
59
+ getExternalTable,
60
+ getTable,
61
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const backups_1 = __importDefault(require("./app/backups"));
7
+ const tables_1 = __importDefault(require("./app/tables"));
8
+ const sdk = {
9
+ backups: backups_1.default,
10
+ tables: tables_1.default,
11
+ };
12
+ // default export for TS
13
+ exports.default = sdk;
14
+ // default export for JS
15
+ module.exports = sdk;
@@ -24,7 +24,7 @@ const newid = require("../../db/newid");
24
24
  const context = require("@budibase/backend-core/context");
25
25
  const { generateDevInfoID, SEPARATOR } = require("@budibase/backend-core/db");
26
26
  const { encrypt } = require("@budibase/backend-core/encryption");
27
- const { DocumentType } = require("../../db/utils");
27
+ const { DocumentType, generateUserMetadataID } = require("../../db/utils");
28
28
  const GLOBAL_USER_ID = "us_uuid1";
29
29
  const EMAIL = "babs@babs.com";
30
30
  const FIRSTNAME = "Barbara";
@@ -87,7 +87,9 @@ class TestConfiguration {
87
87
  // use a new id as the name to avoid name collisions
88
88
  init(appName = newid()) {
89
89
  return __awaiter(this, void 0, void 0, function* () {
90
- yield this.globalUser();
90
+ this.user = yield this.globalUser();
91
+ this.globalUserId = this.user._id;
92
+ this.userMetadataId = generateUserMetadataID(this.globalUserId);
91
93
  return this.createApp(appName);
92
94
  });
93
95
  }
@@ -72,16 +72,12 @@ function getLoopIterations(loopStep, input) {
72
72
  * inputs and handles any outputs.
73
73
  */
74
74
  class Orchestrator {
75
- constructor(automation, triggerOutput, opts) {
75
+ constructor(job) {
76
+ let automation = job.data.automation, triggerOutput = job.data.event;
76
77
  const metadata = triggerOutput.metadata;
77
78
  this._chainCount = metadata ? metadata.automationChainCount : 0;
78
79
  this._appId = triggerOutput.appId;
79
- if (opts === null || opts === void 0 ? void 0 : opts.repeat) {
80
- this._repeat = {
81
- jobId: opts.repeat.jobId,
82
- jobKey: opts.repeat.key,
83
- };
84
- }
80
+ this._job = job;
85
81
  const triggerStepId = automation.definition.trigger.stepId;
86
82
  triggerOutput = this.cleanupTriggerOutputs(triggerStepId, triggerOutput);
87
83
  // remove from context
@@ -131,15 +127,14 @@ class Orchestrator {
131
127
  });
132
128
  }
133
129
  stopCron(reason) {
134
- var _a, _b;
135
130
  return __awaiter(this, void 0, void 0, function* () {
136
- if (!this._repeat) {
131
+ if (!this._job.opts.repeat) {
137
132
  return;
138
133
  }
139
134
  logWarn(`CRON disabled reason=${reason} - ${this._appId}/${this._automation._id}`);
140
135
  const automation = this._automation;
141
136
  const trigger = automation.definition.trigger;
142
- yield (0, utils_2.disableCron)((_a = this._repeat) === null || _a === void 0 ? void 0 : _a.jobId, (_b = this._repeat) === null || _b === void 0 ? void 0 : _b.jobKey);
137
+ yield (0, utils_2.disableCronById)(this._job.id);
143
138
  this.updateExecutionOutput(trigger.id, trigger.stepId, {}, {
144
139
  status: types_1.AutomationStatus.STOPPED_ERROR,
145
140
  success: false,
@@ -149,7 +144,7 @@ class Orchestrator {
149
144
  }
150
145
  checkIfShouldStop(metadata) {
151
146
  return __awaiter(this, void 0, void 0, function* () {
152
- if (!metadata.errorCount || !this._repeat) {
147
+ if (!metadata.errorCount || !this._job.opts.repeat) {
153
148
  return false;
154
149
  }
155
150
  if (metadata.errorCount >= constants_1.MAX_AUTOMATION_RECURRING_ERRORS) {
@@ -404,13 +399,13 @@ class Orchestrator {
404
399
  });
405
400
  }
406
401
  }
407
- function execute(input, callback) {
408
- const appId = input.data.event.appId;
402
+ function execute(job, callback) {
403
+ const appId = job.data.event.appId;
409
404
  if (!appId) {
410
405
  throw new Error("Unable to execute, event doesn't contain app ID.");
411
406
  }
412
407
  doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
413
- const automationOrchestrator = new Orchestrator(input.data.automation, input.data.event, input.opts);
408
+ const automationOrchestrator = new Orchestrator(job);
414
409
  try {
415
410
  const response = yield automationOrchestrator.execute();
416
411
  callback(null, response);
@@ -421,13 +416,13 @@ function execute(input, callback) {
421
416
  }));
422
417
  }
423
418
  exports.execute = execute;
424
- const removeStalled = (input) => __awaiter(void 0, void 0, void 0, function* () {
425
- const appId = input.data.event.appId;
419
+ const removeStalled = (job) => __awaiter(void 0, void 0, void 0, function* () {
420
+ const appId = job.data.event.appId;
426
421
  if (!appId) {
427
422
  throw new Error("Unable to execute, event doesn't contain app ID.");
428
423
  }
429
424
  yield doInAppContext(appId, () => __awaiter(void 0, void 0, void 0, function* () {
430
- const automationOrchestrator = new Orchestrator(input.data.automation, input.data.event, input.opts);
425
+ const automationOrchestrator = new Orchestrator(job);
431
426
  yield automationOrchestrator.stopCron("stalled");
432
427
  }));
433
428
  });