@budibase/server 2.5.6-alpha.1 → 2.5.6-alpha.10

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 (121) hide show
  1. package/builder/assets/{index.1fe52b59.js → index.5c1a6913.js} +361 -361
  2. package/builder/assets/index.c0265b74.css +6 -0
  3. package/builder/index.html +2 -2
  4. package/dist/api/controllers/automation.js +13 -7
  5. package/dist/api/controllers/plugin/index.js +6 -37
  6. package/dist/api/controllers/table/utils.js +2 -1
  7. package/dist/api/controllers/user.js +1 -83
  8. package/dist/api/routes/user.js +0 -1
  9. package/dist/app.js +2 -2
  10. package/dist/automations/actions.js +32 -6
  11. package/dist/automations/index.js +3 -2
  12. package/dist/automations/steps/bash.js +6 -6
  13. package/dist/automations/steps/createRow.js +11 -11
  14. package/dist/automations/steps/delay.js +3 -3
  15. package/dist/automations/steps/deleteRow.js +8 -8
  16. package/dist/automations/steps/discord.js +8 -8
  17. package/dist/automations/steps/executeQuery.js +9 -9
  18. package/dist/automations/steps/executeScript.js +6 -6
  19. package/dist/automations/steps/filter.js +6 -6
  20. package/dist/automations/steps/integromat.js +10 -10
  21. package/dist/automations/steps/loop.js +9 -9
  22. package/dist/automations/steps/outgoingWebhook.js +10 -10
  23. package/dist/automations/steps/queryRows.js +14 -14
  24. package/dist/automations/steps/sendSmtpEmail.js +9 -9
  25. package/dist/automations/steps/serverLog.js +4 -4
  26. package/dist/automations/steps/slack.js +6 -6
  27. package/dist/automations/steps/updateRow.js +11 -11
  28. package/dist/automations/steps/zapier.js +9 -9
  29. package/dist/automations/triggerInfo/app.js +5 -5
  30. package/dist/automations/triggerInfo/cron.js +4 -4
  31. package/dist/automations/triggerInfo/rowDeleted.js +5 -5
  32. package/dist/automations/triggerInfo/rowSaved.js +7 -7
  33. package/dist/automations/triggerInfo/rowUpdated.js +7 -7
  34. package/dist/automations/triggerInfo/webhook.js +6 -6
  35. package/dist/events/docUpdates/index.js +17 -0
  36. package/dist/events/docUpdates/processors.js +18 -0
  37. package/dist/events/docUpdates/syncUsers.js +49 -0
  38. package/dist/events/index.js +3 -0
  39. package/dist/integrations/index.js +3 -3
  40. package/dist/package.json +9 -8
  41. package/dist/sdk/app/applications/sync.js +117 -23
  42. package/dist/sdk/index.js +2 -0
  43. package/dist/sdk/plugins/index.js +27 -0
  44. package/dist/sdk/plugins/plugins.js +53 -0
  45. package/dist/sdk/users/utils.js +21 -4
  46. package/dist/startup.js +2 -1
  47. package/dist/threads/automation.js +2 -2
  48. package/dist/tsconfig.build.tsbuildinfo +1 -1
  49. package/dist/utilities/fileSystem/plugin.js +33 -23
  50. package/dist/utilities/global.js +17 -12
  51. package/dist/watch.js +2 -2
  52. package/dist/websockets/client.js +14 -0
  53. package/dist/websockets/grid.js +60 -0
  54. package/dist/websockets/index.js +17 -0
  55. package/dist/websockets/websocket.js +78 -0
  56. package/jest.config.ts +3 -3
  57. package/nodemon.json +7 -3
  58. package/package.json +10 -9
  59. package/src/api/controllers/automation.ts +12 -6
  60. package/src/api/controllers/plugin/index.ts +8 -45
  61. package/src/api/controllers/row/internal.ts +9 -10
  62. package/src/api/controllers/row/utils.ts +2 -2
  63. package/src/api/controllers/table/utils.ts +2 -1
  64. package/src/api/controllers/user.ts +10 -96
  65. package/src/api/routes/tests/automation.spec.js +2 -2
  66. package/src/api/routes/tests/user.spec.js +0 -37
  67. package/src/api/routes/user.ts +0 -5
  68. package/src/app.ts +2 -2
  69. package/src/automations/actions.ts +56 -24
  70. package/src/automations/index.ts +1 -1
  71. package/src/automations/steps/bash.ts +10 -7
  72. package/src/automations/steps/createRow.ts +15 -12
  73. package/src/automations/steps/delay.ts +6 -4
  74. package/src/automations/steps/deleteRow.ts +12 -9
  75. package/src/automations/steps/discord.ts +10 -8
  76. package/src/automations/steps/executeQuery.ts +13 -10
  77. package/src/automations/steps/executeScript.ts +10 -7
  78. package/src/automations/steps/filter.ts +8 -6
  79. package/src/automations/steps/integromat.ts +12 -10
  80. package/src/automations/steps/loop.ts +16 -10
  81. package/src/automations/steps/outgoingWebhook.ts +14 -11
  82. package/src/automations/steps/queryRows.ts +18 -15
  83. package/src/automations/steps/sendSmtpEmail.ts +11 -9
  84. package/src/automations/steps/serverLog.ts +6 -4
  85. package/src/automations/steps/slack.ts +8 -6
  86. package/src/automations/steps/updateRow.ts +15 -12
  87. package/src/automations/steps/zapier.ts +11 -9
  88. package/src/automations/tests/utilities/index.ts +2 -2
  89. package/src/automations/triggerInfo/app.ts +8 -5
  90. package/src/automations/triggerInfo/cron.ts +7 -4
  91. package/src/automations/triggerInfo/rowDeleted.ts +8 -5
  92. package/src/automations/triggerInfo/rowSaved.ts +10 -7
  93. package/src/automations/triggerInfo/rowUpdated.ts +10 -7
  94. package/src/automations/triggerInfo/webhook.ts +9 -6
  95. package/src/events/docUpdates/index.ts +1 -0
  96. package/src/events/docUpdates/processors.ts +14 -0
  97. package/src/events/docUpdates/syncUsers.ts +35 -0
  98. package/src/events/index.ts +1 -0
  99. package/src/integrations/index.ts +3 -3
  100. package/src/sdk/app/applications/sync.ts +129 -22
  101. package/src/sdk/app/applications/tests/sync.spec.ts +137 -0
  102. package/src/sdk/index.ts +2 -0
  103. package/src/sdk/plugins/index.ts +5 -0
  104. package/src/sdk/plugins/plugins.ts +41 -0
  105. package/src/sdk/users/tests/utils.spec.ts +1 -32
  106. package/src/sdk/users/utils.ts +23 -5
  107. package/src/startup.ts +2 -1
  108. package/src/tests/utilities/TestConfiguration.ts +28 -0
  109. package/src/tests/utilities/structures.ts +25 -17
  110. package/src/threads/automation.ts +2 -2
  111. package/src/utilities/fileSystem/plugin.ts +13 -4
  112. package/src/utilities/global.ts +21 -16
  113. package/src/watch.ts +2 -2
  114. package/src/websockets/client.ts +11 -0
  115. package/src/websockets/grid.ts +55 -0
  116. package/src/websockets/index.ts +14 -0
  117. package/src/websockets/websocket.ts +83 -0
  118. package/tsconfig.json +1 -7
  119. package/builder/assets/index.841e62d8.css +0 -6
  120. package/dist/websocket.js +0 -22
  121. package/src/websocket.ts +0 -26
@@ -14,8 +14,8 @@ exports.definition = {
14
14
  inputs: {
15
15
  properties: {
16
16
  tableId: {
17
- type: "string",
18
- customType: "table",
17
+ type: types_1.AutomationIOType.STRING,
18
+ customType: types_1.AutomationCustomIOType.TABLE,
19
19
  title: "Table",
20
20
  },
21
21
  },
@@ -24,21 +24,21 @@ exports.definition = {
24
24
  outputs: {
25
25
  properties: {
26
26
  row: {
27
- type: "object",
28
- customType: "row",
27
+ type: types_1.AutomationIOType.OBJECT,
28
+ customType: types_1.AutomationCustomIOType.ROW,
29
29
  description: "The new row that was created",
30
30
  },
31
31
  id: {
32
- type: "string",
32
+ type: types_1.AutomationIOType.STRING,
33
33
  description: "Row ID - can be used for updating",
34
34
  },
35
35
  revision: {
36
- type: "string",
36
+ type: types_1.AutomationIOType.STRING,
37
37
  description: "Revision of row",
38
38
  },
39
39
  },
40
40
  required: ["row", "id"],
41
41
  },
42
42
  },
43
- type: "TRIGGER",
43
+ type: types_1.AutomationStepType.TRIGGER,
44
44
  };
@@ -14,8 +14,8 @@ exports.definition = {
14
14
  inputs: {
15
15
  properties: {
16
16
  tableId: {
17
- type: "string",
18
- customType: "table",
17
+ type: types_1.AutomationIOType.STRING,
18
+ customType: types_1.AutomationCustomIOType.TABLE,
19
19
  title: "Table",
20
20
  },
21
21
  },
@@ -24,21 +24,21 @@ exports.definition = {
24
24
  outputs: {
25
25
  properties: {
26
26
  row: {
27
- type: "object",
28
- customType: "row",
27
+ type: types_1.AutomationIOType.OBJECT,
28
+ customType: types_1.AutomationCustomIOType.ROW,
29
29
  description: "The row that was updated",
30
30
  },
31
31
  id: {
32
- type: "string",
32
+ type: types_1.AutomationIOType.STRING,
33
33
  description: "Row ID - can be used for updating",
34
34
  },
35
35
  revision: {
36
- type: "string",
36
+ type: types_1.AutomationIOType.STRING,
37
37
  description: "Revision of row",
38
38
  },
39
39
  },
40
40
  required: ["row", "id"],
41
41
  },
42
42
  },
43
- type: "TRIGGER",
43
+ type: types_1.AutomationStepType.TRIGGER,
44
44
  };
@@ -14,13 +14,13 @@ exports.definition = {
14
14
  inputs: {
15
15
  properties: {
16
16
  schemaUrl: {
17
- type: "string",
18
- customType: "webhookUrl",
17
+ type: types_1.AutomationIOType.STRING,
18
+ customType: types_1.AutomationCustomIOType.WEBHOOK_URL,
19
19
  title: "Schema URL",
20
20
  },
21
21
  triggerUrl: {
22
- type: "string",
23
- customType: "webhookUrl",
22
+ type: types_1.AutomationIOType.STRING,
23
+ customType: types_1.AutomationCustomIOType.WEBHOOK_URL,
24
24
  title: "Trigger URL",
25
25
  },
26
26
  },
@@ -29,12 +29,12 @@ exports.definition = {
29
29
  outputs: {
30
30
  properties: {
31
31
  body: {
32
- type: "object",
32
+ type: types_1.AutomationIOType.OBJECT,
33
33
  description: "Body of the request which hit the webhook",
34
34
  },
35
35
  },
36
36
  required: ["body"],
37
37
  },
38
38
  },
39
- type: "TRIGGER",
39
+ type: types_1.AutomationStepType.TRIGGER,
40
40
  };
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./processors"), exports);
@@ -0,0 +1,18 @@
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
+ exports.init = void 0;
7
+ const syncUsers_1 = __importDefault(require("./syncUsers"));
8
+ const backend_core_1 = require("@budibase/backend-core");
9
+ let started = false;
10
+ function init(updateCb) {
11
+ if (started) {
12
+ return;
13
+ }
14
+ const processors = [(0, syncUsers_1.default)(updateCb)];
15
+ backend_core_1.docUpdates.init(processors);
16
+ started = true;
17
+ }
18
+ exports.init = init;
@@ -0,0 +1,49 @@
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 backend_core_1 = require("@budibase/backend-core");
13
+ const pro_1 = require("@budibase/pro");
14
+ const types_1 = require("@budibase/types");
15
+ const sync_1 = require("../../sdk/app/applications/sync");
16
+ function process(updateCb) {
17
+ const processor = (update) => __awaiter(this, void 0, void 0, function* () {
18
+ var _a;
19
+ try {
20
+ const docId = update.id;
21
+ const isGroup = docId.startsWith(backend_core_1.constants.DocumentType.GROUP);
22
+ let userIds;
23
+ if (isGroup) {
24
+ const group = yield pro_1.sdk.groups.get(docId);
25
+ userIds = ((_a = group.users) === null || _a === void 0 ? void 0 : _a.map(user => user._id)) || [];
26
+ }
27
+ else {
28
+ userIds = [docId];
29
+ }
30
+ if (userIds.length > 0) {
31
+ yield (0, sync_1.syncUsersToAllApps)(userIds);
32
+ }
33
+ if (updateCb) {
34
+ updateCb(docId);
35
+ }
36
+ }
37
+ catch (err) {
38
+ // if something not found - no changes to perform
39
+ if ((err === null || err === void 0 ? void 0 : err.status) === 404) {
40
+ return;
41
+ }
42
+ else {
43
+ backend_core_1.logging.logAlert("Failed to perform user/group app sync", err);
44
+ }
45
+ }
46
+ });
47
+ return { events: types_1.UserGroupSyncEvents, processor };
48
+ }
49
+ exports.default = process;
@@ -3,6 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.init = void 0;
6
7
  const BudibaseEmitter_1 = __importDefault(require("./BudibaseEmitter"));
7
8
  const emitter = new BudibaseEmitter_1.default();
9
+ var docUpdates_1 = require("./docUpdates");
10
+ Object.defineProperty(exports, "init", { enumerable: true, get: function () { return docUpdates_1.init; } });
8
11
  exports.default = emitter;
@@ -29,11 +29,11 @@ const firebase_1 = __importDefault(require("./firebase"));
29
29
  const redis_1 = __importDefault(require("./redis"));
30
30
  const snowflake_1 = __importDefault(require("./snowflake"));
31
31
  const oracle_1 = __importDefault(require("./oracle"));
32
- const plugin_1 = require("../api/controllers/plugin");
33
32
  const types_1 = require("@budibase/types");
34
33
  const fileSystem_1 = require("../utilities/fileSystem");
35
34
  const environment_1 = __importDefault(require("../environment"));
36
35
  const lodash_1 = require("lodash");
36
+ const sdk_1 = __importDefault(require("../sdk"));
37
37
  const DEFINITIONS = {
38
38
  [types_1.SourceName.POSTGRES]: postgres_1.default.schema,
39
39
  [types_1.SourceName.DYNAMODB]: dynamodb_1.default.schema,
@@ -91,7 +91,7 @@ function getDefinitions() {
91
91
  return __awaiter(this, void 0, void 0, function* () {
92
92
  const pluginSchemas = {};
93
93
  if (environment_1.default.SELF_HOSTED) {
94
- const plugins = yield (0, plugin_1.getPlugins)(types_1.PluginType.DATASOURCE);
94
+ const plugins = yield sdk_1.default.plugins.fetch(types_1.PluginType.DATASOURCE);
95
95
  // extract the actual schema from each custom
96
96
  for (let plugin of plugins) {
97
97
  const sourceId = plugin.name;
@@ -111,7 +111,7 @@ function getIntegration(integration) {
111
111
  return INTEGRATIONS[integration];
112
112
  }
113
113
  if (environment_1.default.SELF_HOSTED) {
114
- const plugins = yield (0, plugin_1.getPlugins)(types_1.PluginType.DATASOURCE);
114
+ const plugins = yield sdk_1.default.plugins.fetch(types_1.PluginType.DATASOURCE);
115
115
  for (let plugin of plugins) {
116
116
  if (plugin.name === integration) {
117
117
  // need to use commonJS require due to its dynamic runtime nature
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.5.6-alpha.0",
4
+ "version": "2.5.6-alpha.6",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -45,12 +45,12 @@
45
45
  "license": "GPL-3.0",
46
46
  "dependencies": {
47
47
  "@apidevtools/swagger-parser": "10.0.3",
48
- "@budibase/backend-core": "2.5.5-alpha.4",
49
- "@budibase/client": "2.5.5-alpha.4",
50
- "@budibase/pro": "2.5.5-alpha.4",
51
- "@budibase/shared-core": "2.5.5-alpha.4",
52
- "@budibase/string-templates": "2.5.5-alpha.4",
53
- "@budibase/types": "2.5.5-alpha.4",
48
+ "@budibase/backend-core": "2.5.6-alpha.6",
49
+ "@budibase/client": "2.5.6-alpha.6",
50
+ "@budibase/pro": "2.5.6-alpha.6",
51
+ "@budibase/shared-core": "2.5.6-alpha.6",
52
+ "@budibase/string-templates": "2.5.6-alpha.6",
53
+ "@budibase/types": "2.5.6-alpha.6",
54
54
  "@bull-board/api": "3.7.0",
55
55
  "@bull-board/koa": "3.9.4",
56
56
  "@elastic/elasticsearch": "7.10.0",
@@ -65,6 +65,7 @@
65
65
  "bull": "4.10.1",
66
66
  "chmodr": "1.2.0",
67
67
  "chokidar": "3.5.3",
68
+ "cookies": "0.8.0",
68
69
  "csvtojson": "2.0.10",
69
70
  "curlconverter": "3.21.0",
70
71
  "dd-trace": "3.13.2",
@@ -108,7 +109,7 @@
108
109
  "redis": "4",
109
110
  "server-destroy": "1.0.1",
110
111
  "snowflake-promise": "^4.5.0",
111
- "socket.io": "^4.5.1",
112
+ "socket.io": "4.6.1",
112
113
  "svelte": "3.49.0",
113
114
  "swagger-parser": "10.0.3",
114
115
  "tar": "6.1.11",
@@ -12,10 +12,108 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.syncApp = void 0;
15
+ exports.syncApp = exports.syncUsersToAllApps = void 0;
16
16
  const environment_1 = __importDefault(require("../../../environment"));
17
17
  const backend_core_1 = require("@budibase/backend-core");
18
+ const pro_1 = require("@budibase/pro");
18
19
  const __1 = __importDefault(require("../../"));
20
+ const global_1 = require("../../../utilities/global");
21
+ const utils_1 = require("../../../db/utils");
22
+ function syncUsersToApp(appId, users, groups) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ if (!(yield backend_core_1.db.dbExists(appId))) {
25
+ return;
26
+ }
27
+ yield backend_core_1.context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
28
+ const db = backend_core_1.context.getAppDB();
29
+ for (let user of users) {
30
+ let ctxUser = user;
31
+ let deletedUser = false;
32
+ const metadataId = (0, utils_1.generateUserMetadataID)(user._id);
33
+ if (user.deleted) {
34
+ deletedUser = true;
35
+ }
36
+ // make sure role is correct
37
+ if (!deletedUser) {
38
+ ctxUser = yield (0, global_1.processUser)(ctxUser, { appId, groups });
39
+ }
40
+ let roleId = ctxUser.roleId;
41
+ if (roleId === backend_core_1.roles.BUILTIN_ROLE_IDS.PUBLIC) {
42
+ roleId = undefined;
43
+ }
44
+ let metadata;
45
+ try {
46
+ metadata = yield db.get(metadataId);
47
+ }
48
+ catch (err) {
49
+ if (err.status !== 404) {
50
+ throw err;
51
+ }
52
+ // no metadata and user is to be deleted, can skip
53
+ // no role - user isn't in app anyway
54
+ if (!roleId) {
55
+ continue;
56
+ }
57
+ else if (!deletedUser) {
58
+ // doesn't exist yet, creating it
59
+ metadata = {
60
+ tableId: utils_1.InternalTables.USER_METADATA,
61
+ };
62
+ }
63
+ }
64
+ // the user doesn't exist, or doesn't have a role anymore
65
+ // get rid of their metadata
66
+ if (deletedUser || !roleId) {
67
+ yield db.remove(metadata);
68
+ continue;
69
+ }
70
+ // assign the roleId for the metadata doc
71
+ if (roleId) {
72
+ metadata.roleId = roleId;
73
+ }
74
+ let combined = __1.default.users.combineMetadataAndUser(ctxUser, metadata);
75
+ // if no combined returned, there are no updates to make
76
+ if (combined) {
77
+ yield db.put(combined);
78
+ }
79
+ }
80
+ }));
81
+ });
82
+ }
83
+ function syncUsersToAllApps(userIds) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ // list of users, if one has been deleted it will be undefined in array
86
+ const users = (yield (0, global_1.getGlobalUsers)(userIds, {
87
+ noProcessing: true,
88
+ }));
89
+ const groups = yield pro_1.sdk.groups.fetch();
90
+ const finalUsers = [];
91
+ for (let userId of userIds) {
92
+ const user = users.find(user => user._id === userId);
93
+ if (!user) {
94
+ finalUsers.push({ _id: userId, deleted: true });
95
+ }
96
+ else {
97
+ finalUsers.push(user);
98
+ }
99
+ }
100
+ const devAppIds = yield backend_core_1.db.getDevAppIDs();
101
+ let promises = [];
102
+ for (let devAppId of devAppIds) {
103
+ const prodAppId = backend_core_1.db.getProdAppID(devAppId);
104
+ for (let appId of [prodAppId, devAppId]) {
105
+ promises.push(syncUsersToApp(appId, finalUsers, groups));
106
+ }
107
+ }
108
+ const resp = yield Promise.allSettled(promises);
109
+ const failed = resp.filter(promise => promise.status === "rejected");
110
+ if (failed.length > 0) {
111
+ const reasons = failed.map(fail => fail.reason);
112
+ backend_core_1.logging.logAlert("Failed to sync users to apps", reasons);
113
+ }
114
+ });
115
+ }
116
+ exports.syncUsersToAllApps = syncUsersToAllApps;
19
117
  function syncApp(appId, opts) {
20
118
  return __awaiter(this, void 0, void 0, function* () {
21
119
  if (environment_1.default.DISABLE_AUTO_PROD_APP_SYNC) {
@@ -31,31 +129,27 @@ function syncApp(appId, opts) {
31
129
  // specific case, want to make sure setup is skipped
32
130
  const prodDb = backend_core_1.context.getProdAppDB({ skip_setup: true });
33
131
  const exists = yield prodDb.exists();
34
- if (!exists) {
35
- // the database doesn't exist. Don't replicate
36
- return {
37
- message: "App sync not required, app not deployed.",
38
- };
39
- }
40
- const replication = new backend_core_1.db.Replication({
41
- source: prodAppId,
42
- target: appId,
43
- });
44
132
  let error;
45
- try {
46
- const replOpts = replication.appReplicateOpts();
47
- if (opts === null || opts === void 0 ? void 0 : opts.automationOnly) {
48
- replOpts.filter = (doc) => doc._id.startsWith(backend_core_1.db.DocumentType.AUTOMATION);
133
+ if (exists) {
134
+ const replication = new backend_core_1.db.Replication({
135
+ source: prodAppId,
136
+ target: appId,
137
+ });
138
+ try {
139
+ const replOpts = replication.appReplicateOpts();
140
+ if (opts === null || opts === void 0 ? void 0 : opts.automationOnly) {
141
+ replOpts.filter = (doc) => doc._id.startsWith(backend_core_1.db.DocumentType.AUTOMATION);
142
+ }
143
+ yield replication.replicate(replOpts);
144
+ }
145
+ catch (err) {
146
+ error = err;
147
+ }
148
+ finally {
149
+ yield replication.close();
49
150
  }
50
- yield replication.replicate(replOpts);
51
- }
52
- catch (err) {
53
- error = err;
54
- }
55
- finally {
56
- yield replication.close();
57
151
  }
58
- // sync the users
152
+ // sync the users - kept for safe keeping
59
153
  yield __1.default.users.syncGlobalUsers();
60
154
  if (error) {
61
155
  throw error;
package/dist/sdk/index.js CHANGED
@@ -11,6 +11,7 @@ const datasources_1 = __importDefault(require("./app/datasources"));
11
11
  const queries_1 = __importDefault(require("./app/queries"));
12
12
  const rows_1 = __importDefault(require("./app/rows"));
13
13
  const users_1 = __importDefault(require("./users"));
14
+ const plugins_1 = __importDefault(require("./plugins"));
14
15
  const sdk = {
15
16
  backups: backups_1.default,
16
17
  tables: tables_1.default,
@@ -20,6 +21,7 @@ const sdk = {
20
21
  users: users_1.default,
21
22
  datasources: datasources_1.default,
22
23
  queries: queries_1.default,
24
+ plugins: plugins_1.default,
23
25
  };
24
26
  // default export for TS
25
27
  exports.default = sdk;
@@ -0,0 +1,27 @@
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 plugins = __importStar(require("./plugins"));
27
+ exports.default = Object.assign({}, plugins);
@@ -0,0 +1,53 @@
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.processUploaded = exports.fetch = void 0;
16
+ const types_1 = require("@budibase/types");
17
+ const backend_core_1 = require("@budibase/backend-core");
18
+ const file_1 = require("../../api/controllers/plugin/file");
19
+ const environment_1 = __importDefault(require("../../environment"));
20
+ const websockets_1 = require("../../websockets");
21
+ const pro_1 = require("@budibase/pro");
22
+ function fetch(type) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const db = backend_core_1.tenancy.getGlobalDB();
25
+ const response = yield db.allDocs(backend_core_1.db.getPluginParams(null, {
26
+ include_docs: true,
27
+ }));
28
+ let plugins = response.rows.map((row) => row.doc);
29
+ plugins = backend_core_1.objectStore.enrichPluginURLs(plugins);
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.fetch = fetch;
39
+ function processUploaded(plugin, source) {
40
+ var _a;
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const { metadata, directory } = yield (0, file_1.fileUpload)(plugin);
43
+ backend_core_1.plugins.validate(metadata === null || metadata === void 0 ? void 0 : metadata.schema);
44
+ // Only allow components in cloud
45
+ if (!environment_1.default.SELF_HOSTED && ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.schema) === null || _a === void 0 ? void 0 : _a.type) !== types_1.PluginType.COMPONENT) {
46
+ throw new Error("Only component plugins are supported outside of self-host");
47
+ }
48
+ const doc = yield pro_1.sdk.plugins.storePlugin(metadata, directory, source);
49
+ websockets_1.clientAppSocket.emit("plugin-update", { name: doc.name, hash: doc.hash });
50
+ return doc;
51
+ });
52
+ }
53
+ exports.processUploaded = processUploaded;
@@ -34,6 +34,10 @@ function combineMetadataAndUser(user, metadata) {
34
34
  if (found) {
35
35
  newDoc._rev = found._rev;
36
36
  }
37
+ // clear fields that shouldn't be in metadata
38
+ delete newDoc.password;
39
+ delete newDoc.forceResetPassword;
40
+ delete newDoc.roles;
37
41
  if (found == null || !(0, lodash_1.isEqual)(newDoc, found)) {
38
42
  return Object.assign(Object.assign({}, found), newDoc);
39
43
  }
@@ -53,10 +57,9 @@ function syncGlobalUsers() {
53
57
  return __awaiter(this, void 0, void 0, function* () {
54
58
  // sync user metadata
55
59
  const db = backend_core_1.context.getAppDB();
56
- const [users, metadata] = yield Promise.all([
57
- (0, global_1.getGlobalUsers)(),
58
- rawUserMetadata(),
59
- ]);
60
+ const resp = yield Promise.all([(0, global_1.getGlobalUsers)(), rawUserMetadata()]);
61
+ const users = resp[0];
62
+ const metadata = resp[1];
60
63
  const toWrite = [];
61
64
  for (let user of users) {
62
65
  const combined = combineMetadataAndUser(user, metadata);
@@ -64,6 +67,20 @@ function syncGlobalUsers() {
64
67
  toWrite.push(combined);
65
68
  }
66
69
  }
70
+ let foundEmails = [];
71
+ for (let data of metadata) {
72
+ if (!data._id) {
73
+ continue;
74
+ }
75
+ const alreadyExisting = data.email && foundEmails.indexOf(data.email) !== -1;
76
+ const globalId = (0, utils_1.getGlobalIDFromUserMetadataID)(data._id);
77
+ if (!users.find(user => user._id === globalId) || alreadyExisting) {
78
+ toWrite.push(Object.assign(Object.assign({}, data), { _deleted: true }));
79
+ }
80
+ if (data.email) {
81
+ foundEmails.push(data.email);
82
+ }
83
+ }
67
84
  yield db.bulkDocs(toWrite);
68
85
  });
69
86
  }
package/dist/startup.js CHANGED
@@ -44,7 +44,7 @@ const fs_1 = __importDefault(require("fs"));
44
44
  const watch_1 = require("./watch");
45
45
  const automations = __importStar(require("./automations"));
46
46
  const fileSystem = __importStar(require("./utilities/fileSystem"));
47
- const events_1 = __importDefault(require("./events"));
47
+ const events_1 = __importStar(require("./events"));
48
48
  const migrations = __importStar(require("./migrations"));
49
49
  const bullboard = __importStar(require("./automations/bullboard"));
50
50
  const pro = __importStar(require("@budibase/pro"));
@@ -96,6 +96,7 @@ function startup(app, server) {
96
96
  events_1.default.emitPort(environment_1.default.PORT);
97
97
  fileSystem.init();
98
98
  yield redis.init();
99
+ (0, events_1.init)();
99
100
  // run migrations on startup if not done via http
100
101
  // not recommended in a clustered environment
101
102
  if (!environment_1.default.HTTP_MIGRATIONS && !environment_1.default.isTest()) {
@@ -52,8 +52,8 @@ const string_templates_1 = require("@budibase/string-templates");
52
52
  const fp_1 = require("lodash/fp");
53
53
  const sdkUtils = __importStar(require("../sdk/utils"));
54
54
  const environment_1 = __importDefault(require("../environment"));
55
- const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId;
56
- const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId;
55
+ const FILTER_STEP_ID = actions.BUILTIN_ACTION_DEFINITIONS.FILTER.stepId;
56
+ const LOOP_STEP_ID = actions.BUILTIN_ACTION_DEFINITIONS.LOOP.stepId;
57
57
  const CRON_STEP_ID = triggerInfo_1.definitions.CRON.stepId;
58
58
  const STOPPED_STATUS = { success: true, status: types_1.AutomationStatus.STOPPED };
59
59
  function getLoopIterations(loopStep, input) {