@budibase/server 2.4.44-alpha.1 → 2.4.44-alpha.11

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.
@@ -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.76deb808.js"></script>
12
- <link rel="stylesheet" href="/builder/assets/index.7f9a008b.css">
11
+ <script type="module" crossorigin src="/builder/assets/index.6d4736dc.js"></script>
12
+ <link rel="stylesheet" href="/builder/assets/index.d013cac9.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,
@@ -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.0",
4
+ "version": "2.4.44-alpha.10",
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.0",
48
- "@budibase/client": "2.4.44-alpha.0",
49
- "@budibase/pro": "2.4.44-alpha.0",
50
- "@budibase/shared-core": "2.4.44-alpha.0",
51
- "@budibase/string-templates": "2.4.44-alpha.0",
52
- "@budibase/types": "2.4.44-alpha.0",
48
+ "@budibase/backend-core": "2.4.44-alpha.10",
49
+ "@budibase/client": "2.4.44-alpha.10",
50
+ "@budibase/pro": "2.4.44-alpha.10",
51
+ "@budibase/shared-core": "2.4.44-alpha.10",
52
+ "@budibase/string-templates": "2.4.44-alpha.10",
53
+ "@budibase/types": "2.4.44-alpha.10",
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",
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;
@@ -58,8 +58,8 @@ 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) {
60
60
  const binding = automationUtils.typecastForLooping(loopStep, input);
61
- if (!loopStep || !binding) {
62
- return 1;
61
+ if (!binding) {
62
+ return 0;
63
63
  }
64
64
  if (Array.isArray(binding)) {
65
65
  return binding.length;
@@ -67,7 +67,7 @@ function getLoopIterations(loopStep, input) {
67
67
  if (typeof binding === "string") {
68
68
  return automationUtils.stringSplit(binding).length;
69
69
  }
70
- return 1;
70
+ return 0;
71
71
  }
72
72
  /**
73
73
  * The automation orchestrator is a class responsible for executing automations.
@@ -372,6 +372,17 @@ class Orchestrator {
372
372
  }
373
373
  }
374
374
  }
375
+ if (loopStep && iterations === 0) {
376
+ loopStep = undefined;
377
+ this.executionOutput.steps.splice(loopStepNumber + 1, 0, {
378
+ id: step.id,
379
+ stepId: step.stepId,
380
+ outputs: { status: types_1.AutomationStatus.NO_ITERATIONS, success: true },
381
+ inputs: {},
382
+ });
383
+ this._context.steps.splice(loopStepNumber, 1);
384
+ iterations = 1;
385
+ }
375
386
  // Delete the step after the loop step as it's irrelevant, since information is included
376
387
  // in the loop step
377
388
  if (wasLoopStep && !loopStep) {