@budibase/server 2.6.19-alpha.40 → 2.6.19-alpha.42

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.
package/dist/index.js CHANGED
@@ -1710,7 +1710,6 @@ var init_environment2 = __esm({
1710
1710
  REDIS_URL: process.env.REDIS_URL || "localhost:6379",
1711
1711
  REDIS_PASSWORD: process.env.REDIS_PASSWORD,
1712
1712
  REDIS_CLUSTERED: process.env.REDIS_CLUSTERED,
1713
- MOCK_REDIS: process.env.MOCK_REDIS,
1714
1713
  MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
1715
1714
  MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
1716
1715
  AWS_REGION: process.env.AWS_REGION,
@@ -1737,6 +1736,7 @@ var init_environment2 = __esm({
1737
1736
  GLOBAL_BUCKET_NAME: process.env.GLOBAL_BUCKET_NAME || DefaultBucketName.GLOBAL,
1738
1737
  PLUGIN_BUCKET_NAME: process.env.PLUGIN_BUCKET_NAME || DefaultBucketName.PLUGINS,
1739
1738
  USE_COUCH: process.env.USE_COUCH || true,
1739
+ MOCK_REDIS: process.env.MOCK_REDIS,
1740
1740
  DEFAULT_LICENSE: process.env.DEFAULT_LICENSE,
1741
1741
  SERVICE: process.env.SERVICE || "budibase",
1742
1742
  LOG_LEVEL: process.env.LOG_LEVEL || "info",
@@ -2612,7 +2612,7 @@ function getRedisOptions() {
2612
2612
  opts.port = port;
2613
2613
  opts.password = password;
2614
2614
  }
2615
- return { opts, host, port, redisProtocolUrl };
2615
+ return { opts, host, port: parseInt(port), redisProtocolUrl };
2616
2616
  }
2617
2617
  function addDbPrefix(db2, key) {
2618
2618
  if (key.includes(db2)) {
@@ -2733,6 +2733,7 @@ function connectionError(selectDb, timeout2, err) {
2733
2733
  }, RETRY_PERIOD_MS);
2734
2734
  }
2735
2735
  function init2(selectDb = DEFAULT_SELECT_DB) {
2736
+ const RedisCore = environment_default.MOCK_REDIS ? MockRedis : import_ioredis.default;
2736
2737
  let timeout2;
2737
2738
  CLOSED = false;
2738
2739
  let client3 = pickClient(selectDb);
@@ -2740,7 +2741,7 @@ function init2(selectDb = DEFAULT_SELECT_DB) {
2740
2741
  return;
2741
2742
  }
2742
2743
  if (environment_default.MOCK_REDIS) {
2743
- CLIENTS[selectDb] = new Redis(getRedisOptions());
2744
+ CLIENTS[selectDb] = new RedisCore(getRedisOptions());
2744
2745
  }
2745
2746
  timeout2 = setTimeout(() => {
2746
2747
  if (!CONNECTED) {
@@ -2756,11 +2757,11 @@ function init2(selectDb = DEFAULT_SELECT_DB) {
2756
2757
  }
2757
2758
  const { redisProtocolUrl, opts, host, port } = getRedisOptions();
2758
2759
  if (CLUSTERED) {
2759
- client3 = new Redis.Cluster([{ host, port }], opts);
2760
+ client3 = new RedisCore.Cluster([{ host, port }], opts);
2760
2761
  } else if (redisProtocolUrl) {
2761
- client3 = new Redis(redisProtocolUrl);
2762
+ client3 = new RedisCore(redisProtocolUrl);
2762
2763
  } else {
2763
- client3 = new Redis(opts);
2764
+ client3 = new RedisCore(opts);
2764
2765
  }
2765
2766
  client3.on("end", (err) => {
2766
2767
  if (environment_default.isTest()) {
@@ -2824,13 +2825,14 @@ function promisifyStream(stream3, client3) {
2824
2825
  });
2825
2826
  });
2826
2827
  }
2827
- var Redis, RETRY_PERIOD_MS, STARTUP_TIMEOUT_MS, CLUSTERED, DEFAULT_SELECT_DB, CLOSED, CLIENTS, CONNECTED, RedisWrapper, redis_default;
2828
+ var import_ioredis, MockRedis, RETRY_PERIOD_MS, STARTUP_TIMEOUT_MS, CLUSTERED, DEFAULT_SELECT_DB, CLOSED, CLIENTS, CONNECTED, RedisWrapper, redis_default;
2828
2829
  var init_redis = __esm({
2829
2830
  "../backend-core/src/redis/redis.ts"() {
2830
2831
  init_environment2();
2832
+ import_ioredis = __toESM(require("ioredis"));
2831
2833
  init_utils2();
2832
2834
  init_timers2();
2833
- Redis = environment_default.MOCK_REDIS ? require("ioredis-mock") : require("ioredis");
2835
+ MockRedis = require("ioredis-mock");
2834
2836
  RETRY_PERIOD_MS = 2e3;
2835
2837
  STARTUP_TIMEOUT_MS = 5e3;
2836
2838
  CLUSTERED = environment_default.REDIS_CLUSTERED;
@@ -11861,6 +11863,7 @@ var init_src2 = __esm({
11861
11863
  init_cache();
11862
11864
  init_objectStore2();
11863
11865
  init_redis2();
11866
+ init_redis2();
11864
11867
  init_redlockImpl();
11865
11868
  init_utils5();
11866
11869
  init_errors3();
@@ -15060,6 +15063,7 @@ var init_users7 = __esm({
15060
15063
 
15061
15064
  // ../pro/packages/pro/src/utilities/delay.ts
15062
15065
  async function backOff(fn2, errMsg) {
15066
+ let error2;
15063
15067
  let attempts = 5, success = false, response2, first = true;
15064
15068
  for (; attempts > 0; attempts--) {
15065
15069
  try {
@@ -15071,10 +15075,11 @@ async function backOff(fn2, errMsg) {
15071
15075
  success = true;
15072
15076
  break;
15073
15077
  } catch (err) {
15078
+ error2 = err;
15074
15079
  }
15075
15080
  }
15076
15081
  if (!success) {
15077
- logging_exports.logAlert(`Failed to backoff`, errMsg);
15082
+ logging_exports.logAlert(`Failed to backoff: ${errMsg}`, error2);
15078
15083
  }
15079
15084
  return response2;
15080
15085
  }
@@ -21812,7 +21817,9 @@ async function init17() {
21812
21817
  await debounceClient.init();
21813
21818
  await flagClient.init();
21814
21819
  socketClient2 = await redis_exports.clients.getSocketClient();
21815
- socketSubClient = socketClient2.getClient().duplicate();
21820
+ if (!environment_default2.isTest()) {
21821
+ socketSubClient = socketClient2.getClient().duplicate();
21822
+ }
21816
21823
  }
21817
21824
  async function shutdown6() {
21818
21825
  console.log("REDIS SHUTDOWN");
@@ -21887,6 +21894,7 @@ var init_redis4 = __esm({
21887
21894
  "src/utilities/redis.ts"() {
21888
21895
  init_src2();
21889
21896
  init_utils9();
21897
+ init_environment3();
21890
21898
  APP_DEV_LOCK_SECONDS = 600;
21891
21899
  AUTOMATION_TEST_FLAG_SECONDS = 60;
21892
21900
  }
@@ -29610,11 +29618,11 @@ var init_firebase = __esm({
29610
29618
  });
29611
29619
 
29612
29620
  // src/integrations/redis.ts
29613
- var import_ioredis, SCHEMA14, RedisIntegration, redis_default2;
29621
+ var import_ioredis2, SCHEMA14, RedisIntegration, redis_default2;
29614
29622
  var init_redis5 = __esm({
29615
29623
  "src/integrations/redis.ts"() {
29616
29624
  init_src();
29617
- import_ioredis = __toESM(require("ioredis"));
29625
+ import_ioredis2 = __toESM(require("ioredis"));
29618
29626
  SCHEMA14 = {
29619
29627
  docs: "https://redis.io/docs/",
29620
29628
  description: "Redis is a caching tool, providing powerful key-value store capabilities.",
@@ -29695,7 +29703,7 @@ var init_redis5 = __esm({
29695
29703
  RedisIntegration = class {
29696
29704
  constructor(config) {
29697
29705
  this.config = config;
29698
- this.client = new import_ioredis.default({
29706
+ this.client = new import_ioredis2.default({
29699
29707
  host: this.config.host,
29700
29708
  port: this.config.port,
29701
29709
  username: this.config.username,
@@ -29759,7 +29767,13 @@ var init_redis5 = __esm({
29759
29767
  }
29760
29768
  const pipeline = this.client.pipeline(pipelineCommands);
29761
29769
  const result = await pipeline.exec();
29762
- return result.map((output) => output[1]);
29770
+ return result == null ? void 0 : result.map((output) => {
29771
+ if (typeof output === "string") {
29772
+ return output;
29773
+ } else if (Array.isArray(output)) {
29774
+ return output[1];
29775
+ }
29776
+ });
29763
29777
  });
29764
29778
  }
29765
29779
  };
@@ -31653,7 +31667,7 @@ var init_builder2 = __esm({
31653
31667
  super(app2, server2, "/socket/builder", [authorized_default(permissions_exports.BUILDER)]);
31654
31668
  }
31655
31669
  async onConnect(socket) {
31656
- socket.on("SelectApp" /* SelectApp */, async (appId, callback) => {
31670
+ socket == null ? void 0 : socket.on("SelectApp" /* SelectApp */, async (appId, callback) => {
31657
31671
  await this.joinRoom(socket, appId);
31658
31672
  const sessions = await this.getRoomSessions(appId);
31659
31673
  callback({ users: sessions });
@@ -31675,12 +31689,14 @@ var init_builder2 = __esm({
31675
31689
  }
31676
31690
  }
31677
31691
  emitTableUpdate(ctx, table2) {
31692
+ var _a2;
31678
31693
  this.io.in(ctx.appId).emit("TableChange" /* TableChange */, { id: table2._id, table: table2 });
31679
- gridSocket.emitTableUpdate(table2);
31694
+ (_a2 = gridSocket) == null ? void 0 : _a2.emitTableUpdate(table2);
31680
31695
  }
31681
31696
  emitTableDeletion(ctx, id) {
31697
+ var _a2;
31682
31698
  this.io.in(ctx.appId).emit("TableChange" /* TableChange */, { id, table: null });
31683
- gridSocket.emitTableDeletion(id);
31699
+ (_a2 = gridSocket) == null ? void 0 : _a2.emitTableDeletion(id);
31684
31700
  }
31685
31701
  emitDatasourceUpdate(ctx, datasource2) {
31686
31702
  this.io.in(ctx.appId).emit("DatasourceChange" /* DatasourceChange */, {
@@ -31702,10 +31718,13 @@ var init_websockets = __esm({
31702
31718
  init_client2();
31703
31719
  init_grid();
31704
31720
  init_builder2();
31721
+ init_environment3();
31705
31722
  initialise = (app2, server2) => {
31706
- clientAppSocket = new ClientAppWebsocket(app2, server2);
31707
- gridSocket = new GridSocket(app2, server2);
31708
- builderSocket = new BuilderSocket(app2, server2);
31723
+ if (!environment_default2.isTest()) {
31724
+ clientAppSocket = new ClientAppWebsocket(app2, server2);
31725
+ gridSocket = new GridSocket(app2, server2);
31726
+ builderSocket = new BuilderSocket(app2, server2);
31727
+ }
31709
31728
  };
31710
31729
  }
31711
31730
  });
@@ -31735,14 +31754,14 @@ async function fetch17(type) {
31735
31754
  }
31736
31755
  }
31737
31756
  async function processUploaded(plugin, source) {
31738
- var _a2;
31757
+ var _a2, _b2;
31739
31758
  const { metadata, directory } = await fileUpload(plugin);
31740
31759
  plugin_exports.validate(metadata == null ? void 0 : metadata.schema);
31741
31760
  if (!environment_default2.SELF_HOSTED && ((_a2 = metadata == null ? void 0 : metadata.schema) == null ? void 0 : _a2.type) !== "component" /* COMPONENT */) {
31742
31761
  throw new Error("Only component plugins are supported outside of self-host");
31743
31762
  }
31744
31763
  const doc = await sdk_exports.plugins.storePlugin(metadata, directory, source);
31745
- clientAppSocket.emit("plugin-update", { name: doc.name, hash: doc.hash });
31764
+ (_b2 = clientAppSocket) == null ? void 0 : _b2.emit("plugin-update", { name: doc.name, hash: doc.hash });
31746
31765
  return doc;
31747
31766
  }
31748
31767
  var init_plugins4 = __esm({
@@ -34434,6 +34453,20 @@ async function getConnector(datasource2) {
34434
34453
  }
34435
34454
  return new Connector(datasource2.config);
34436
34455
  }
34456
+ async function getAndMergeDatasource(datasource2) {
34457
+ let existingDatasource;
34458
+ if (datasource2._id) {
34459
+ existingDatasource = await sdk_default.datasources.get(datasource2._id);
34460
+ }
34461
+ let enrichedDatasource = datasource2;
34462
+ if (existingDatasource) {
34463
+ enrichedDatasource = sdk_default.datasources.mergeConfigs(
34464
+ datasource2,
34465
+ existingDatasource
34466
+ );
34467
+ }
34468
+ return await sdk_default.datasources.enrich(enrichedDatasource);
34469
+ }
34437
34470
  async function buildSchemaHelper(datasource2) {
34438
34471
  const connector = await getConnector(datasource2);
34439
34472
  await connector.buildSchema(datasource2._id, datasource2.entities);
@@ -34494,17 +34527,7 @@ async function fetch22(ctx) {
34494
34527
  }
34495
34528
  async function verify(ctx) {
34496
34529
  const { datasource: datasource2 } = ctx.request.body;
34497
- let existingDatasource;
34498
- if (datasource2._id) {
34499
- existingDatasource = await sdk_default.datasources.get(datasource2._id);
34500
- }
34501
- let enrichedDatasource = datasource2;
34502
- if (existingDatasource) {
34503
- enrichedDatasource = sdk_default.datasources.mergeConfigs(
34504
- datasource2,
34505
- existingDatasource
34506
- );
34507
- }
34530
+ const enrichedDatasource = await getAndMergeDatasource(datasource2);
34508
34531
  const connector = await getConnector(enrichedDatasource);
34509
34532
  if (!connector.testConnection) {
34510
34533
  ctx.throw(400, "Connection information verification not supported");
@@ -34516,9 +34539,9 @@ async function verify(ctx) {
34516
34539
  };
34517
34540
  }
34518
34541
  async function information(ctx) {
34519
- const datasourceId = ctx.params.datasourceId;
34520
- const datasource2 = await sdk_default.datasources.get(datasourceId, { enriched: true });
34521
- const connector = await getConnector(datasource2);
34542
+ const { datasource: datasource2 } = ctx.request.body;
34543
+ const enrichedDatasource = await getAndMergeDatasource(datasource2);
34544
+ const connector = await getConnector(enrichedDatasource);
34522
34545
  if (!connector.getTableNames) {
34523
34546
  ctx.throw(400, "Table name fetching not supported by datasource");
34524
34547
  }
@@ -34592,7 +34615,7 @@ async function invalidateVariables(existingDatasource, updatedDatasource) {
34592
34615
  await invalidateDynamicVariables(toInvalidate);
34593
34616
  }
34594
34617
  async function update7(ctx) {
34595
- var _a2, _b2;
34618
+ var _a2, _b2, _c;
34596
34619
  const db2 = context_exports.getAppDB();
34597
34620
  const datasourceId = ctx.params.datasourceId;
34598
34621
  let datasource2 = await sdk_default.datasources.get(datasourceId);
@@ -34621,9 +34644,10 @@ async function update7(ctx) {
34621
34644
  ctx.body = {
34622
34645
  datasource: await sdk_default.datasources.removeSecretSingle(datasource2)
34623
34646
  };
34624
- builderSocket.emitDatasourceUpdate(ctx, datasource2);
34647
+ (_c = builderSocket) == null ? void 0 : _c.emitDatasourceUpdate(ctx, datasource2);
34625
34648
  }
34626
34649
  async function save13(ctx) {
34650
+ var _a2;
34627
34651
  const db2 = context_exports.getAppDB();
34628
34652
  const plus = ctx.request.body.datasource.plus;
34629
34653
  const fetchSchema = ctx.request.body.fetchSchema;
@@ -34655,7 +34679,7 @@ async function save13(ctx) {
34655
34679
  response2.error = schemaError;
34656
34680
  }
34657
34681
  ctx.body = response2;
34658
- builderSocket.emitDatasourceUpdate(ctx, datasource2);
34682
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitDatasourceUpdate(ctx, datasource2);
34659
34683
  }
34660
34684
  async function destroyInternalTablesBySourceId(datasourceId) {
34661
34685
  const db2 = context_exports.getAppDB();
@@ -34682,6 +34706,7 @@ async function destroyInternalTablesBySourceId(datasourceId) {
34682
34706
  }
34683
34707
  }
34684
34708
  async function destroy12(ctx) {
34709
+ var _a2;
34685
34710
  const db2 = context_exports.getAppDB();
34686
34711
  const datasourceId = ctx.params.datasourceId;
34687
34712
  const datasource2 = await sdk_default.datasources.get(datasourceId);
@@ -34701,7 +34726,7 @@ async function destroy12(ctx) {
34701
34726
  await events_exports.datasource.deleted(datasource2);
34702
34727
  ctx.message = `Datasource deleted.`;
34703
34728
  ctx.status = 200;
34704
- builderSocket.emitDatasourceDeletion(ctx, datasourceId);
34729
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitDatasourceDeletion(ctx, datasourceId);
34705
34730
  }
34706
34731
  async function find8(ctx) {
34707
34732
  const database = context_exports.getAppDB();
@@ -36803,6 +36828,7 @@ async function find10(ctx) {
36803
36828
  ctx.body = await sdk_default.tables.getTable(tableId);
36804
36829
  }
36805
36830
  async function save16(ctx) {
36831
+ var _a2;
36806
36832
  const appId = ctx.appId;
36807
36833
  const table2 = ctx.request.body;
36808
36834
  const isImport = table2.rows;
@@ -36819,9 +36845,10 @@ async function save16(ctx) {
36819
36845
  ctx.message = `Table ${table2.name} saved successfully.`;
36820
36846
  ctx.eventEmitter && ctx.eventEmitter.emitTable(`table:save`, appId, savedTable);
36821
36847
  ctx.body = savedTable;
36822
- builderSocket.emitTableUpdate(ctx, savedTable);
36848
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitTableUpdate(ctx, savedTable);
36823
36849
  }
36824
36850
  async function destroy15(ctx) {
36851
+ var _a2;
36825
36852
  const appId = ctx.appId;
36826
36853
  const tableId = ctx.params.tableId;
36827
36854
  const deletedTable = await pickApi2({ tableId }).destroy(ctx);
@@ -36830,7 +36857,7 @@ async function destroy15(ctx) {
36830
36857
  ctx.status = 200;
36831
36858
  ctx.table = deletedTable;
36832
36859
  ctx.body = { message: `Table ${tableId} deleted.` };
36833
- builderSocket.emitTableDeletion(ctx, tableId);
36860
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitTableDeletion(ctx, tableId);
36834
36861
  }
36835
36862
  async function bulkImport3(ctx) {
36836
36863
  const tableId = ctx.params.tableId;
@@ -37725,10 +37752,17 @@ function getLoopIterations(loopStep) {
37725
37752
  if (!binding) {
37726
37753
  return 0;
37727
37754
  }
37755
+ const isString = typeof binding === "string";
37756
+ try {
37757
+ if (isString) {
37758
+ binding = JSON.parse(binding);
37759
+ }
37760
+ } catch (err) {
37761
+ }
37728
37762
  if (Array.isArray(binding)) {
37729
37763
  return binding.length;
37730
37764
  }
37731
- if (typeof binding === "string") {
37765
+ if (isString) {
37732
37766
  return stringSplit(binding).length;
37733
37767
  }
37734
37768
  return 0;
@@ -39771,6 +39805,7 @@ async function fetch32(ctx) {
39771
39805
  ctx.body = await getViews();
39772
39806
  }
39773
39807
  async function save18(ctx) {
39808
+ var _a2;
39774
39809
  const db2 = context_exports.getAppDB();
39775
39810
  const { originalName, ...viewToSave } = ctx.request.body;
39776
39811
  const existingTable = await db2.get(ctx.request.body.tableId);
@@ -39797,7 +39832,7 @@ async function save18(ctx) {
39797
39832
  await db2.put(table2);
39798
39833
  await handleViewEvents(existingTable.views[viewName], table2.views[viewName]);
39799
39834
  ctx.body = table2.views[viewName];
39800
- builderSocket.emitTableUpdate(ctx, table2);
39835
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitTableUpdate(ctx, table2);
39801
39836
  }
39802
39837
  async function calculationEvents(existingView, newView) {
39803
39838
  const existingCalculation = existingView && existingView.calculation;
@@ -39835,6 +39870,7 @@ async function handleViewEvents(existingView, newView) {
39835
39870
  await filterEvents(existingView, newView);
39836
39871
  }
39837
39872
  async function destroy18(ctx) {
39873
+ var _a2;
39838
39874
  const db2 = context_exports.getAppDB();
39839
39875
  const viewName = decodeURIComponent(ctx.params.viewName);
39840
39876
  const view2 = await deleteView(viewName);
@@ -39843,7 +39879,7 @@ async function destroy18(ctx) {
39843
39879
  await db2.put(table2);
39844
39880
  await events_exports.view.deleted(view2);
39845
39881
  ctx.body = view2;
39846
- builderSocket.emitTableUpdate(ctx, table2);
39882
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitTableUpdate(ctx, table2);
39847
39883
  }
39848
39884
  async function exportView(ctx) {
39849
39885
  const viewName = decodeURIComponent(ctx.query.view);
@@ -41342,8 +41378,8 @@ var init_datasource6 = __esm({
41342
41378
  "/api/datasources/verify",
41343
41379
  authorized_default(permissions_exports.BUILDER),
41344
41380
  verify
41345
- ).get(
41346
- "/api/datasources/:datasourceId/info",
41381
+ ).post(
41382
+ "/api/datasources/info",
41347
41383
  authorized_default(permissions_exports.BUILDER),
41348
41384
  information
41349
41385
  ).get(
@@ -42960,7 +42996,7 @@ async function upload2(ctx) {
42960
42996
  }
42961
42997
  }
42962
42998
  async function create8(ctx) {
42963
- var _a2;
42999
+ var _a2, _b2;
42964
43000
  const { source, url, headers, githubToken } = ctx.request.body;
42965
43001
  try {
42966
43002
  let metadata;
@@ -42991,7 +43027,7 @@ async function create8(ctx) {
42991
43027
  );
42992
43028
  }
42993
43029
  const doc = await sdk_exports.plugins.storePlugin(metadata, directory, source);
42994
- clientAppSocket.emit("plugins-update", { name, hash: doc.hash });
43030
+ (_b2 = clientAppSocket) == null ? void 0 : _b2.emit("plugins-update", { name, hash: doc.hash });
42995
43031
  ctx.body = {
42996
43032
  message: "Plugin uploaded successfully",
42997
43033
  plugins: [doc]