@budibase/server 2.4.44-alpha.2 → 2.4.44-alpha.21

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 (37) hide show
  1. package/builder/assets/index.6085409e.js +1776 -0
  2. package/builder/assets/{index.7f9a008b.css → index.841e62d8.css} +3 -3
  3. package/builder/index.html +2 -2
  4. package/dist/api/controllers/ops.js +40 -0
  5. package/dist/api/routes/index.js +2 -0
  6. package/dist/api/routes/ops.js +52 -0
  7. package/dist/app.js +2 -11
  8. package/dist/environment.js +0 -1
  9. package/dist/integrations/redis.js +7 -0
  10. package/dist/integrations/rest.js +4 -0
  11. package/dist/migrations/functions/usageQuotas/syncApps.js +1 -1
  12. package/dist/migrations/functions/usageQuotas/syncRows.js +1 -2
  13. package/dist/package.json +12 -12
  14. package/dist/startup.js +29 -27
  15. package/dist/tsconfig.build.tsbuildinfo +1 -1
  16. package/package.json +13 -13
  17. package/scripts/dev/manage.js +2 -0
  18. package/src/api/controllers/ops.ts +32 -0
  19. package/src/api/routes/index.ts +2 -0
  20. package/src/api/routes/ops.ts +30 -0
  21. package/src/api/routes/tests/automation.spec.js +5 -2
  22. package/src/api/routes/tests/user.spec.js +61 -13
  23. package/src/app.ts +2 -13
  24. package/src/environment.ts +0 -1
  25. package/src/integrations/redis.ts +8 -0
  26. package/src/integrations/rest.ts +3 -0
  27. package/src/migrations/functions/usageQuotas/syncApps.ts +1 -1
  28. package/src/migrations/functions/usageQuotas/syncRows.ts +2 -3
  29. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +2 -2
  30. package/src/startup.ts +34 -33
  31. package/src/tests/jestEnv.ts +0 -1
  32. package/src/tests/jestSetup.ts +0 -1
  33. package/builder/assets/index.8021c5c2.js +0 -1817
  34. package/dist/elasticApm.js +0 -14
  35. package/scripts/likeCypress.ts +0 -35
  36. package/src/elasticApm.ts +0 -10
  37. package/src/tests/logging.ts +0 -34
@@ -8,8 +8,8 @@
8
8
  <link rel="preconnect" href="https://fonts.gstatic.com" />
9
9
  <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap"
10
10
  rel="stylesheet" />
11
- <script type="module" crossorigin src="/builder/assets/index.8021c5c2.js"></script>
12
- <link rel="stylesheet" href="/builder/assets/index.7f9a008b.css">
11
+ <script type="module" crossorigin src="/builder/assets/index.6085409e.js"></script>
12
+ <link rel="stylesheet" href="/builder/assets/index.841e62d8.css">
13
13
  </head>
14
14
 
15
15
  <body id="app">
@@ -0,0 +1,40 @@
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.error = exports.alert = exports.log = void 0;
13
+ const backend_core_1 = require("@budibase/backend-core");
14
+ function log(ctx) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const body = ctx.request.body;
17
+ console.trace(body.message, body.data);
18
+ console.debug(body.message, body.data);
19
+ console.info(body.message, body.data);
20
+ console.warn(body.message, body.data);
21
+ console.error(body.message, body.data);
22
+ ctx.status = 204;
23
+ });
24
+ }
25
+ exports.log = log;
26
+ function alert(ctx) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const body = ctx.request.body;
29
+ backend_core_1.logging.logAlert(body.message, new Error(body.message));
30
+ ctx.status = 204;
31
+ });
32
+ }
33
+ exports.alert = alert;
34
+ function error(ctx) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const body = ctx.request.body;
37
+ throw new Error(body.message);
38
+ });
39
+ }
40
+ exports.error = error;
@@ -31,6 +31,7 @@ const dev_1 = __importDefault(require("./dev"));
31
31
  const cloud_1 = __importDefault(require("./cloud"));
32
32
  const migrations_1 = __importDefault(require("./migrations"));
33
33
  const plugin_1 = __importDefault(require("./plugin"));
34
+ const ops_1 = __importDefault(require("./ops"));
34
35
  const pro_1 = require("@budibase/pro");
35
36
  var static_1 = require("./static");
36
37
  Object.defineProperty(exports, "staticRoutes", { enumerable: true, get: function () { return __importDefault(static_1).default; } });
@@ -67,6 +68,7 @@ exports.mainRoutes = [
67
68
  row_1.default,
68
69
  migrations_1.default,
69
70
  plugin_1.default,
71
+ ops_1.default,
70
72
  scheduleRoutes,
71
73
  environmentVariableRoutes,
72
74
  // these need to be handled last as they still use /api/:tableId
@@ -0,0 +1,52 @@
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
+ exports.errorValidator = exports.logsValidator = void 0;
30
+ const router_1 = __importDefault(require("@koa/router"));
31
+ const controller = __importStar(require("../controllers/ops"));
32
+ const backend_core_1 = require("@budibase/backend-core");
33
+ const joi_1 = __importDefault(require("joi"));
34
+ function logsValidator() {
35
+ return backend_core_1.middleware.joiValidator.body(joi_1.default.object({
36
+ message: joi_1.default.string().required(),
37
+ data: joi_1.default.object(),
38
+ }));
39
+ }
40
+ exports.logsValidator = logsValidator;
41
+ function errorValidator() {
42
+ return backend_core_1.middleware.joiValidator.body(joi_1.default.object({
43
+ message: joi_1.default.string().required(),
44
+ }));
45
+ }
46
+ exports.errorValidator = errorValidator;
47
+ const router = new router_1.default();
48
+ router
49
+ .post("/api/ops/log", logsValidator(), controller.log)
50
+ .post("/api/ops/error", errorValidator(), controller.error)
51
+ .post("/api/ops/alert", errorValidator(), controller.alert);
52
+ exports.default = router;
package/dist/app.js CHANGED
@@ -38,18 +38,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  if (process.env.DD_APM_ENABLED) {
39
39
  require("./ddApm");
40
40
  }
41
- if (process.env.ELASTIC_APM_ENABLED) {
42
- require("./elasticApm");
43
- }
44
41
  // need to load environment first
45
42
  const environment_1 = __importDefault(require("./environment"));
46
- // enable APM if configured
47
- if (process.env.ELASTIC_APM_ENABLED) {
48
- const apm = require("elastic-apm-node").start({
49
- serviceName: process.env.SERVICE,
50
- environment: process.env.BUDIBASE_ENVIRONMENT,
51
- });
52
- }
53
43
  const db = __importStar(require("./db"));
54
44
  db.init();
55
45
  const koa_1 = __importDefault(require("koa"));
@@ -80,7 +70,8 @@ app.use((0, koa_body_1.default)({
80
70
  enableTypes: ["json", "form", "text"],
81
71
  parsedMethods: ["POST", "PUT", "PATCH", "DELETE"],
82
72
  }));
83
- app.use(backend_core_1.middleware.logging);
73
+ app.use(backend_core_1.middleware.correlation);
74
+ app.use(backend_core_1.middleware.pino);
84
75
  app.use(userAgent);
85
76
  if (environment_1.default.isProd()) {
86
77
  environment_1.default._set("NODE_ENV", "production");
@@ -54,7 +54,6 @@ const environment = {
54
54
  // minor
55
55
  SALT_ROUNDS: process.env.SALT_ROUNDS,
56
56
  LOGGER: process.env.LOGGER,
57
- LOG_LEVEL: process.env.LOG_LEVEL,
58
57
  ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
59
58
  AUTOMATION_MAX_ITERATIONS: parseIntSafe(process.env.AUTOMATION_MAX_ITERATIONS) || 200,
60
59
  SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
@@ -38,6 +38,12 @@ const SCHEMA = {
38
38
  type: "password",
39
39
  required: false,
40
40
  },
41
+ db: {
42
+ type: "number",
43
+ required: false,
44
+ display: "DB",
45
+ default: 0,
46
+ },
41
47
  },
42
48
  query: {
43
49
  create: {
@@ -90,6 +96,7 @@ class RedisIntegration {
90
96
  port: this.config.port,
91
97
  username: this.config.username,
92
98
  password: this.config.password,
99
+ db: this.config.db,
93
100
  });
94
101
  }
95
102
  disconnect() {
@@ -166,6 +166,10 @@ class RestIntegration {
166
166
  }
167
167
  raw = rawXml;
168
168
  }
169
+ else if (contentType.includes("application/pdf")) {
170
+ data = yield response.arrayBuffer(); // Save PDF as ArrayBuffer
171
+ raw = Buffer.from(data);
172
+ }
169
173
  else {
170
174
  data = yield response.text();
171
175
  raw = data;
@@ -19,7 +19,7 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
19
19
  const appCount = devApps ? devApps.length : 0;
20
20
  // sync app count
21
21
  const tenantId = backend_core_1.tenancy.getTenantId();
22
- console.log(`[Tenant: ${tenantId}] Syncing app count: ${appCount}`);
22
+ console.log(`Syncing app count: ${appCount}`);
23
23
  yield pro_1.quotas.setUsage(appCount, types_1.StaticQuotaName.APPS, types_1.QuotaUsageType.STATIC);
24
24
  });
25
25
  exports.run = run;
@@ -27,8 +27,7 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
27
27
  rowCount += rows.length;
28
28
  });
29
29
  // sync row count
30
- const tenantId = backend_core_1.tenancy.getTenantId();
31
- console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`);
30
+ console.log(`Syncing row count: ${rowCount}`);
32
31
  yield pro_1.quotas.setUsagePerApp(counts, types_1.StaticQuotaName.ROWS, types_1.QuotaUsageType.STATIC);
33
32
  });
34
33
  exports.run = run;
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.4.44-alpha.1",
4
+ "version": "2.4.44-alpha.20",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -26,6 +26,7 @@
26
26
  "dev:stack:down": "node scripts/dev/manage.js down",
27
27
  "dev:stack:nuke": "node scripts/dev/manage.js nuke",
28
28
  "dev:builder": "yarn run dev:stack:up && nodemon",
29
+ "dev:built": "yarn run dev:stack:up && yarn run run:docker",
29
30
  "specs": "ts-node specs/generate.ts && openapi-typescript specs/openapi.yaml --output src/definitions/openapi.ts",
30
31
  "initialise": "node scripts/initialise.js",
31
32
  "env:multi:enable": "node scripts/multiTenancy.js enable",
@@ -44,12 +45,12 @@
44
45
  "license": "GPL-3.0",
45
46
  "dependencies": {
46
47
  "@apidevtools/swagger-parser": "10.0.3",
47
- "@budibase/backend-core": "2.4.44-alpha.1",
48
- "@budibase/client": "2.4.44-alpha.1",
49
- "@budibase/pro": "2.4.44-alpha.1",
50
- "@budibase/shared-core": "2.4.44-alpha.1",
51
- "@budibase/string-templates": "2.4.44-alpha.1",
52
- "@budibase/types": "2.4.44-alpha.1",
48
+ "@budibase/backend-core": "2.4.44-alpha.20",
49
+ "@budibase/client": "2.4.44-alpha.20",
50
+ "@budibase/pro": "2.4.44-alpha.20",
51
+ "@budibase/shared-core": "2.4.44-alpha.20",
52
+ "@budibase/string-templates": "2.4.44-alpha.20",
53
+ "@budibase/types": "2.4.44-alpha.20",
53
54
  "@bull-board/api": "3.7.0",
54
55
  "@bull-board/koa": "3.9.4",
55
56
  "@elastic/elasticsearch": "7.10.0",
@@ -85,7 +86,6 @@
85
86
  "koa-body": "4.2.0",
86
87
  "koa-compress": "4.0.1",
87
88
  "koa-connect": "2.1.0",
88
- "koa-pino-logger": "3.0.0",
89
89
  "koa-send": "5.0.0",
90
90
  "koa-session": "5.12.0",
91
91
  "koa-static": "5.0.0",
@@ -99,7 +99,6 @@
99
99
  "node-fetch": "2.6.7",
100
100
  "open": "8.4.0",
101
101
  "pg": "8.5.1",
102
- "pino-pretty": "4.0.0",
103
102
  "posthog-node": "1.3.0",
104
103
  "pouchdb": "7.3.0",
105
104
  "pouchdb-adapter-memory": "7.2.2",
@@ -116,9 +115,9 @@
116
115
  "to-json-schema": "0.2.5",
117
116
  "uuid": "3.3.2",
118
117
  "validate.js": "0.13.1",
119
- "vm2": "3.9.11",
118
+ "vm2": "3.9.16",
120
119
  "worker-farm": "1.7.0",
121
- "xml2js": "0.4.23",
120
+ "xml2js": "0.5.0",
122
121
  "yargs": "13.2.4",
123
122
  "zlib": "1.0.5"
124
123
  },
@@ -149,7 +148,7 @@
149
148
  "@types/tar": "6.1.3",
150
149
  "@typescript-eslint/parser": "5.45.0",
151
150
  "apidoc": "0.50.4",
152
- "babel-jest": "27.5.1",
151
+ "babel-jest": "29.5.0",
153
152
  "copyfiles": "2.4.1",
154
153
  "docker-compose": "0.23.17",
155
154
  "eslint": "6.8.0",
@@ -157,6 +156,7 @@
157
156
  "is-wsl": "2.2.0",
158
157
  "jest": "29.5.0",
159
158
  "jest-openapi": "0.14.2",
159
+ "jest-runner": "29.5.0",
160
160
  "jest-serial-runner": "^1.2.1",
161
161
  "nodemon": "2.0.15",
162
162
  "openapi-types": "9.3.1",
package/dist/startup.js CHANGED
@@ -50,11 +50,9 @@ const bullboard = __importStar(require("./automations/bullboard"));
50
50
  const pro = __importStar(require("@budibase/pro"));
51
51
  const api = __importStar(require("./api"));
52
52
  const sdk_1 = __importDefault(require("./sdk"));
53
- const pino = require("koa-pino-logger");
54
53
  let STARTUP_RAN = false;
55
54
  function initRoutes(app) {
56
55
  return __awaiter(this, void 0, void 0, function* () {
57
- app.use(pino(backend_core_1.logging.pinoSettings()));
58
56
  if (!environment_1.default.isTest()) {
59
57
  const plugin = yield bullboard.init();
60
58
  app.use(plugin);
@@ -79,8 +77,10 @@ function initPro() {
79
77
  });
80
78
  }
81
79
  function shutdown(server) {
82
- server.close();
83
- server.destroy();
80
+ if (server) {
81
+ server.close();
82
+ server.destroy();
83
+ }
84
84
  }
85
85
  function startup(app, server) {
86
86
  var _a;
@@ -104,29 +104,7 @@ function startup(app, server) {
104
104
  }
105
105
  catch (e) {
106
106
  backend_core_1.logging.logAlert("Error performing migrations. Exiting.", e);
107
- shutdown();
108
- }
109
- }
110
- // check and create admin user if required
111
- if (environment_1.default.SELF_HOSTED &&
112
- !environment_1.default.MULTI_TENANCY &&
113
- environment_1.default.BB_ADMIN_USER_EMAIL &&
114
- environment_1.default.BB_ADMIN_USER_PASSWORD) {
115
- const checklist = yield (0, workerRequests_1.getChecklist)();
116
- if (!((_a = checklist === null || checklist === void 0 ? void 0 : checklist.adminUser) === null || _a === void 0 ? void 0 : _a.checked)) {
117
- try {
118
- const tenantId = backend_core_1.tenancy.getTenantId();
119
- const user = yield (0, workerRequests_1.createAdminUser)(environment_1.default.BB_ADMIN_USER_EMAIL, environment_1.default.BB_ADMIN_USER_PASSWORD, tenantId);
120
- // Need to set up an API key for automated integration tests
121
- if (environment_1.default.isTest()) {
122
- yield (0, workerRequests_1.generateApiKey)(user._id);
123
- }
124
- console.log("Admin account automatically created for", environment_1.default.BB_ADMIN_USER_EMAIL);
125
- }
126
- catch (e) {
127
- backend_core_1.logging.logAlert("Error creating initial admin user. Exiting.", e);
128
- shutdown();
129
- }
107
+ shutdown(server);
130
108
  }
131
109
  }
132
110
  // monitor plugin directory if required
@@ -150,6 +128,30 @@ function startup(app, server) {
150
128
  // bring routes online as final step once everything ready
151
129
  yield initRoutes(app);
152
130
  }
131
+ // check and create admin user if required
132
+ // this must be run after the api has been initialised due to
133
+ // the app user sync
134
+ if (environment_1.default.SELF_HOSTED &&
135
+ !environment_1.default.MULTI_TENANCY &&
136
+ environment_1.default.BB_ADMIN_USER_EMAIL &&
137
+ environment_1.default.BB_ADMIN_USER_PASSWORD) {
138
+ const checklist = yield (0, workerRequests_1.getChecklist)();
139
+ if (!((_a = checklist === null || checklist === void 0 ? void 0 : checklist.adminUser) === null || _a === void 0 ? void 0 : _a.checked)) {
140
+ try {
141
+ const tenantId = backend_core_1.tenancy.getTenantId();
142
+ const user = yield (0, workerRequests_1.createAdminUser)(environment_1.default.BB_ADMIN_USER_EMAIL, environment_1.default.BB_ADMIN_USER_PASSWORD, tenantId);
143
+ // Need to set up an API key for automated integration tests
144
+ if (environment_1.default.isTest()) {
145
+ yield (0, workerRequests_1.generateApiKey)(user._id);
146
+ }
147
+ console.log("Admin account automatically created for", environment_1.default.BB_ADMIN_USER_EMAIL);
148
+ }
149
+ catch (e) {
150
+ backend_core_1.logging.logAlert("Error creating initial admin user. Exiting.", e);
151
+ shutdown(server);
152
+ }
153
+ }
154
+ }
153
155
  });
154
156
  }
155
157
  exports.startup = startup;