@budibase/server 2.7.21-alpha.2 → 2.7.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.
package/dist/index.js CHANGED
@@ -838,7 +838,6 @@ var init_automation2 = __esm({
838
838
  AutomationIOType2["NUMBER"] = "number";
839
839
  AutomationIOType2["ARRAY"] = "array";
840
840
  AutomationIOType2["JSON"] = "json";
841
- AutomationIOType2["DATE"] = "date";
842
841
  return AutomationIOType2;
843
842
  })(AutomationIOType || {});
844
843
  AutomationCustomIOType = /* @__PURE__ */ ((AutomationCustomIOType2) => {
@@ -5401,11 +5400,11 @@ function makeCacheItem(doc2, lastWrite = null) {
5401
5400
  return { doc: doc2, lastWrite: lastWrite || Date.now() };
5402
5401
  }
5403
5402
  async function put(db2, doc2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5404
- const cache3 = await getCache();
5403
+ const cache2 = await getCache();
5405
5404
  const key = doc2._id;
5406
5405
  let cacheItem;
5407
5406
  if (key) {
5408
- cacheItem = await cache3.get(makeCacheKey(db2, key));
5407
+ cacheItem = await cache2.get(makeCacheKey(db2, key));
5409
5408
  }
5410
5409
  const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
5411
5410
  let output = doc2;
@@ -5443,30 +5442,30 @@ async function put(db2, doc2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5443
5442
  }
5444
5443
  cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
5445
5444
  if (output._id) {
5446
- await cache3.store(makeCacheKey(db2, output._id), cacheItem);
5445
+ await cache2.store(makeCacheKey(db2, output._id), cacheItem);
5447
5446
  }
5448
5447
  return { ok: true, id: output._id, rev: output._rev };
5449
5448
  }
5450
5449
  async function get2(db2, id) {
5451
- const cache3 = await getCache();
5450
+ const cache2 = await getCache();
5452
5451
  const cacheKey = makeCacheKey(db2, id);
5453
- let cacheItem = await cache3.get(cacheKey);
5452
+ let cacheItem = await cache2.get(cacheKey);
5454
5453
  if (!cacheItem) {
5455
5454
  const doc2 = await db2.get(id);
5456
5455
  cacheItem = makeCacheItem(doc2);
5457
- await cache3.store(cacheKey, cacheItem);
5456
+ await cache2.store(cacheKey, cacheItem);
5458
5457
  }
5459
5458
  return cacheItem.doc;
5460
5459
  }
5461
5460
  async function remove(db2, docOrId, rev2) {
5462
- const cache3 = await getCache();
5461
+ const cache2 = await getCache();
5463
5462
  if (!docOrId) {
5464
5463
  throw new Error("No ID/Rev provided.");
5465
5464
  }
5466
5465
  const id = typeof docOrId === "string" ? docOrId : docOrId._id;
5467
5466
  rev2 = typeof docOrId === "string" ? rev2 : docOrId._rev;
5468
5467
  try {
5469
- await cache3.delete(makeCacheKey(db2, id));
5468
+ await cache2.delete(makeCacheKey(db2, id));
5470
5469
  } finally {
5471
5470
  await db2.remove(id, rev2);
5472
5471
  }
@@ -9308,7 +9307,7 @@ function lowerBuiltinRoleID(roleId1, roleId2) {
9308
9307
  }
9309
9308
  return builtinRoleToNumber(roleId1) > builtinRoleToNumber(roleId2) ? roleId2 : roleId1;
9310
9309
  }
9311
- async function getRole(roleId, opts) {
9310
+ async function getRole(roleId) {
9312
9311
  if (!roleId) {
9313
9312
  return void 0;
9314
9313
  }
@@ -9324,9 +9323,6 @@ async function getRole(roleId, opts) {
9324
9323
  role = Object.assign(role, dbRole);
9325
9324
  role._id = getExternalRoleID(role._id);
9326
9325
  } catch (err) {
9327
- if (!isBuiltin(roleId) && (opts == null ? void 0 : opts.defaultPublic)) {
9328
- return cloneDeep2(BUILTIN_ROLES.PUBLIC);
9329
- }
9330
9326
  if (Object.keys(role).length === 0) {
9331
9327
  throw err;
9332
9328
  }
@@ -10067,8 +10063,8 @@ async function preAuth(passport2, ctx, next) {
10067
10063
  callbackUrl,
10068
10064
  ssoSaveUserNoOp
10069
10065
  );
10070
- if (!ctx.query.appId) {
10071
- ctx.throw(400, "appId query param not present.");
10066
+ if (!ctx.query.appId || !ctx.query.datasourceId) {
10067
+ ctx.throw(400, "appId and datasourceId query params not present.");
10072
10068
  }
10073
10069
  return passport2.authenticate(strategy, {
10074
10070
  scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
@@ -10088,7 +10084,7 @@ async function postAuth(passport2, ctx, next) {
10088
10084
  clientSecret: config.clientSecret,
10089
10085
  callbackURL: callbackUrl
10090
10086
  },
10091
- (accessToken, refreshToken, _profile, done) => {
10087
+ (accessToken, refreshToken, profile, done) => {
10092
10088
  clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
10093
10089
  done(null, { accessToken, refreshToken });
10094
10090
  }
@@ -10096,14 +10092,22 @@ async function postAuth(passport2, ctx, next) {
10096
10092
  { successRedirect: "/", failureRedirect: "/error" },
10097
10093
  async (err, tokens) => {
10098
10094
  const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
10099
- const id = newid();
10100
- await store(
10101
- `datasource:creation:${authStateCookie.appId}:google:${id}`,
10102
- {
10103
- tokens
10095
+ await doWithDB(authStateCookie.appId, async (db2) => {
10096
+ let datasource2;
10097
+ try {
10098
+ datasource2 = await db2.get(authStateCookie.datasourceId);
10099
+ } catch (err2) {
10100
+ if (err2.status === 404) {
10101
+ ctx.redirect(baseUrl);
10102
+ }
10104
10103
  }
10105
- );
10106
- ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
10104
+ if (!datasource2.config) {
10105
+ datasource2.config = {};
10106
+ }
10107
+ datasource2.config.auth = { type: "google", ...tokens };
10108
+ await db2.put(datasource2);
10109
+ ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
10110
+ });
10107
10111
  }
10108
10112
  )(ctx, next);
10109
10113
  }
@@ -10112,9 +10116,9 @@ var init_google2 = __esm({
10112
10116
  "../backend-core/src/middleware/passport/datasource/google.ts"() {
10113
10117
  init_google();
10114
10118
  init_constants2();
10115
- init_configs3();
10116
- init_cache();
10117
10119
  init_utils5();
10120
+ init_db5();
10121
+ init_configs3();
10118
10122
  init_sso2();
10119
10123
  GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
10120
10124
  }
@@ -10164,9 +10168,7 @@ var encryption_exports = {};
10164
10168
  __export(encryption_exports, {
10165
10169
  SecretOption: () => SecretOption,
10166
10170
  decrypt: () => decrypt,
10167
- decryptFile: () => decryptFile,
10168
10171
  encrypt: () => encrypt,
10169
- encryptFile: () => encryptFile,
10170
10172
  getSecret: () => getSecret
10171
10173
  });
10172
10174
  function getSecret(secretOption) {
@@ -10187,11 +10189,11 @@ function getSecret(secretOption) {
10187
10189
  }
10188
10190
  return secret;
10189
10191
  }
10190
- function stretchString(secret, salt) {
10191
- return import_crypto.default.pbkdf2Sync(secret, salt, ITERATIONS, STRETCH_LENGTH, "sha512");
10192
+ function stretchString(string, salt) {
10193
+ return import_crypto.default.pbkdf2Sync(string, salt, ITERATIONS, STRETCH_LENGTH, "sha512");
10192
10194
  }
10193
10195
  function encrypt(input, secretOption = "api" /* API */) {
10194
- const salt = import_crypto.default.randomBytes(SALT_LENGTH);
10196
+ const salt = import_crypto.default.randomBytes(RANDOM_BYTES);
10195
10197
  const stretched = stretchString(getSecret(secretOption), salt);
10196
10198
  const cipher = import_crypto.default.createCipheriv(ALGO, stretched, salt);
10197
10199
  const base = cipher.update(input);
@@ -10208,101 +10210,16 @@ function decrypt(input, secretOption = "api" /* API */) {
10208
10210
  const final = decipher.final();
10209
10211
  return Buffer.concat([base, final]).toString();
10210
10212
  }
10211
- async function encryptFile({ dir, filename }, secret) {
10212
- const outputFileName = `${filename}.enc`;
10213
- const filePath = (0, import_path.join)(dir, filename);
10214
- const inputFile = import_fs2.default.createReadStream(filePath);
10215
- const outputFile = import_fs2.default.createWriteStream((0, import_path.join)(dir, outputFileName));
10216
- const salt = import_crypto.default.randomBytes(SALT_LENGTH);
10217
- const iv = import_crypto.default.randomBytes(IV_LENGTH);
10218
- const stretched = stretchString(secret, salt);
10219
- const cipher = import_crypto.default.createCipheriv(ALGO, stretched, iv);
10220
- outputFile.write(salt);
10221
- outputFile.write(iv);
10222
- inputFile.pipe(import_zlib.default.createGzip()).pipe(cipher).pipe(outputFile);
10223
- return new Promise((r) => {
10224
- outputFile.on("finish", () => {
10225
- r({
10226
- filename: outputFileName,
10227
- dir
10228
- });
10229
- });
10230
- });
10231
- }
10232
- async function getSaltAndIV(path5) {
10233
- const fileStream = import_fs2.default.createReadStream(path5);
10234
- const salt = await readBytes(fileStream, SALT_LENGTH);
10235
- const iv = await readBytes(fileStream, IV_LENGTH);
10236
- fileStream.close();
10237
- return { salt, iv };
10238
- }
10239
- async function decryptFile(inputPath, outputPath, secret) {
10240
- const { salt, iv } = await getSaltAndIV(inputPath);
10241
- const inputFile = import_fs2.default.createReadStream(inputPath, {
10242
- start: SALT_LENGTH + IV_LENGTH
10243
- });
10244
- const outputFile = import_fs2.default.createWriteStream(outputPath);
10245
- const stretched = stretchString(secret, salt);
10246
- const decipher = import_crypto.default.createDecipheriv(ALGO, stretched, iv);
10247
- const unzip = import_zlib.default.createGunzip();
10248
- inputFile.pipe(decipher).pipe(unzip).pipe(outputFile);
10249
- return new Promise((res, rej) => {
10250
- outputFile.on("finish", () => {
10251
- outputFile.close();
10252
- res();
10253
- });
10254
- inputFile.on("error", (e) => {
10255
- outputFile.close();
10256
- rej(e);
10257
- });
10258
- decipher.on("error", (e) => {
10259
- outputFile.close();
10260
- rej(e);
10261
- });
10262
- unzip.on("error", (e) => {
10263
- outputFile.close();
10264
- rej(e);
10265
- });
10266
- outputFile.on("error", (e) => {
10267
- outputFile.close();
10268
- rej(e);
10269
- });
10270
- });
10271
- }
10272
- function readBytes(stream3, length) {
10273
- return new Promise((resolve3, reject) => {
10274
- let bytesRead = 0;
10275
- const data2 = [];
10276
- stream3.on("readable", () => {
10277
- let chunk;
10278
- while ((chunk = stream3.read(length - bytesRead)) !== null) {
10279
- data2.push(chunk);
10280
- bytesRead += chunk.length;
10281
- }
10282
- resolve3(Buffer.concat(data2));
10283
- });
10284
- stream3.on("end", () => {
10285
- reject(new Error("Insufficient data in the stream."));
10286
- });
10287
- stream3.on("error", (error2) => {
10288
- reject(error2);
10289
- });
10290
- });
10291
- }
10292
- var import_crypto, import_fs2, import_zlib, import_path, ALGO, SEPARATOR3, ITERATIONS, STRETCH_LENGTH, SALT_LENGTH, IV_LENGTH, SecretOption;
10213
+ var import_crypto, ALGO, SEPARATOR3, ITERATIONS, RANDOM_BYTES, STRETCH_LENGTH, SecretOption;
10293
10214
  var init_encryption = __esm({
10294
10215
  "../backend-core/src/security/encryption.ts"() {
10295
10216
  import_crypto = __toESM(require("crypto"));
10296
- import_fs2 = __toESM(require("fs"));
10297
- import_zlib = __toESM(require("zlib"));
10298
10217
  init_environment2();
10299
- import_path = require("path");
10300
10218
  ALGO = "aes-256-ctr";
10301
10219
  SEPARATOR3 = "-";
10302
10220
  ITERATIONS = 1e4;
10221
+ RANDOM_BYTES = 16;
10303
10222
  STRETCH_LENGTH = 32;
10304
- SALT_LENGTH = 16;
10305
- IV_LENGTH = 16;
10306
10223
  SecretOption = /* @__PURE__ */ ((SecretOption2) => {
10307
10224
  SecretOption2["API"] = "api";
10308
10225
  SecretOption2["ENCRYPTION"] = "encryption";
@@ -11213,12 +11130,12 @@ var init_plugin4 = __esm({
11213
11130
  function budibaseTempDir() {
11214
11131
  return bbTmp;
11215
11132
  }
11216
- var import_path2, import_os, import_fs3, ObjectStoreBuckets, bbTmp;
11133
+ var import_path, import_os, import_fs2, ObjectStoreBuckets, bbTmp;
11217
11134
  var init_utils8 = __esm({
11218
11135
  "../backend-core/src/objectStore/utils.ts"() {
11219
- import_path2 = require("path");
11136
+ import_path = require("path");
11220
11137
  import_os = require("os");
11221
- import_fs3 = __toESM(require("fs"));
11138
+ import_fs2 = __toESM(require("fs"));
11222
11139
  init_environment2();
11223
11140
  ObjectStoreBuckets = {
11224
11141
  BACKUPS: environment_default.BACKUPS_BUCKET_NAME,
@@ -11227,9 +11144,9 @@ var init_utils8 = __esm({
11227
11144
  GLOBAL: environment_default.GLOBAL_BUCKET_NAME,
11228
11145
  PLUGINS: environment_default.PLUGIN_BUCKET_NAME
11229
11146
  };
11230
- bbTmp = (0, import_path2.join)((0, import_os.tmpdir)(), ".budibase");
11231
- if (!import_fs3.default.existsSync(bbTmp)) {
11232
- import_fs3.default.mkdirSync(bbTmp);
11147
+ bbTmp = (0, import_path.join)((0, import_os.tmpdir)(), ".budibase");
11148
+ if (!import_fs2.default.existsSync(bbTmp)) {
11149
+ import_fs2.default.mkdirSync(bbTmp);
11233
11150
  }
11234
11151
  }
11235
11152
  });
@@ -11241,17 +11158,17 @@ function sanitizeKey(input) {
11241
11158
  function sanitizeBucket(input) {
11242
11159
  return input.replace(new RegExp(APP_DEV_PREFIX, "g"), APP_PREFIX);
11243
11160
  }
11244
- var import_aws_sdk, import_stream, import_node_fetch6, import_tar_fs, import_zlib2, import_util, import_path3, import_fs4, import_uuid3, sanitize, streamPipeline, STATE, CONTENT_TYPE_MAP, STRING_CONTENT_TYPES, ObjectStore, makeSureBucketExists, upload, streamUpload, retrieve, listAllObjects, getPresignedUrl, retrieveToTmp, retrieveDirectory, deleteFile, deleteFiles, deleteFolder, uploadDirectory, downloadTarballDirect, downloadTarball;
11161
+ var import_aws_sdk, import_stream, import_node_fetch6, import_tar_fs, import_zlib, import_util, import_path2, import_fs3, import_uuid3, sanitize, streamPipeline, STATE, CONTENT_TYPE_MAP, STRING_CONTENT_TYPES, ObjectStore, makeSureBucketExists, upload, streamUpload, retrieve, listAllObjects, getPresignedUrl, retrieveToTmp, retrieveDirectory, deleteFile, deleteFiles, deleteFolder, uploadDirectory, downloadTarballDirect, downloadTarball;
11245
11162
  var init_objectStore = __esm({
11246
11163
  "../backend-core/src/objectStore/objectStore.ts"() {
11247
11164
  import_aws_sdk = __toESM(require("aws-sdk"));
11248
11165
  import_stream = __toESM(require("stream"));
11249
11166
  import_node_fetch6 = __toESM(require("node-fetch"));
11250
11167
  import_tar_fs = __toESM(require("tar-fs"));
11251
- import_zlib2 = __toESM(require("zlib"));
11168
+ import_zlib = __toESM(require("zlib"));
11252
11169
  import_util = require("util");
11253
- import_path3 = require("path");
11254
- import_fs4 = __toESM(require("fs"));
11170
+ import_path2 = require("path");
11171
+ import_fs3 = __toESM(require("fs"));
11255
11172
  init_environment2();
11256
11173
  init_utils8();
11257
11174
  import_uuid3 = require("uuid");
@@ -11330,7 +11247,7 @@ var init_objectStore = __esm({
11330
11247
  metadata: metadata2
11331
11248
  }) => {
11332
11249
  const extension = filename.split(".").pop();
11333
- const fileBytes = import_fs4.default.readFileSync(path5);
11250
+ const fileBytes = import_fs3.default.readFileSync(path5);
11334
11251
  const objectStore = ObjectStore(bucketName);
11335
11252
  await makeSureBucketExists(objectStore, bucketName);
11336
11253
  let contentType = type;
@@ -11432,13 +11349,13 @@ var init_objectStore = __esm({
11432
11349
  bucketName = sanitizeBucket(bucketName);
11433
11350
  filepath = sanitizeKey(filepath);
11434
11351
  const data2 = await retrieve(bucketName, filepath);
11435
- const outputPath = (0, import_path3.join)(budibaseTempDir(), (0, import_uuid3.v4)());
11436
- import_fs4.default.writeFileSync(outputPath, data2);
11352
+ const outputPath = (0, import_path2.join)(budibaseTempDir(), (0, import_uuid3.v4)());
11353
+ import_fs3.default.writeFileSync(outputPath, data2);
11437
11354
  return outputPath;
11438
11355
  };
11439
11356
  retrieveDirectory = async (bucketName, path5) => {
11440
- let writePath = (0, import_path3.join)(budibaseTempDir(), (0, import_uuid3.v4)());
11441
- import_fs4.default.mkdirSync(writePath);
11357
+ let writePath = (0, import_path2.join)(budibaseTempDir(), (0, import_uuid3.v4)());
11358
+ import_fs3.default.mkdirSync(writePath);
11442
11359
  const objects = await listAllObjects(bucketName, path5);
11443
11360
  let fullObjects = await Promise.all(
11444
11361
  objects.map((obj) => retrieve(bucketName, obj.Key))
@@ -11450,9 +11367,9 @@ var init_objectStore = __esm({
11450
11367
  const possiblePath = filename.split("/");
11451
11368
  if (possiblePath.length > 1) {
11452
11369
  const dirs = possiblePath.slice(0, possiblePath.length - 1);
11453
- import_fs4.default.mkdirSync((0, import_path3.join)(writePath, ...dirs), { recursive: true });
11370
+ import_fs3.default.mkdirSync((0, import_path2.join)(writePath, ...dirs), { recursive: true });
11454
11371
  }
11455
- import_fs4.default.writeFileSync((0, import_path3.join)(writePath, ...possiblePath), data2);
11372
+ import_fs3.default.writeFileSync((0, import_path2.join)(writePath, ...possiblePath), data2);
11456
11373
  }
11457
11374
  return writePath;
11458
11375
  };
@@ -11506,14 +11423,14 @@ var init_objectStore = __esm({
11506
11423
  uploadDirectory = async (bucketName, localPath, bucketPath2) => {
11507
11424
  bucketName = sanitizeBucket(bucketName);
11508
11425
  let uploads = [];
11509
- const files2 = import_fs4.default.readdirSync(localPath, { withFileTypes: true });
11426
+ const files2 = import_fs3.default.readdirSync(localPath, { withFileTypes: true });
11510
11427
  for (let file of files2) {
11511
- const path5 = sanitizeKey((0, import_path3.join)(bucketPath2, file.name));
11512
- const local = (0, import_path3.join)(localPath, file.name);
11428
+ const path5 = sanitizeKey((0, import_path2.join)(bucketPath2, file.name));
11429
+ const local = (0, import_path2.join)(localPath, file.name);
11513
11430
  if (file.isDirectory()) {
11514
11431
  uploads.push(uploadDirectory(bucketName, local, path5));
11515
11432
  } else {
11516
- uploads.push(streamUpload(bucketName, path5, import_fs4.default.createReadStream(local)));
11433
+ uploads.push(streamUpload(bucketName, path5, import_fs3.default.createReadStream(local)));
11517
11434
  }
11518
11435
  }
11519
11436
  await Promise.all(uploads);
@@ -11525,7 +11442,7 @@ var init_objectStore = __esm({
11525
11442
  if (!response2.ok) {
11526
11443
  throw new Error(`unexpected response ${response2.statusText}`);
11527
11444
  }
11528
- await streamPipeline(response2.body, import_zlib2.default.createUnzip(), import_tar_fs.default.extract(path5));
11445
+ await streamPipeline(response2.body, import_zlib.default.createUnzip(), import_tar_fs.default.extract(path5));
11529
11446
  };
11530
11447
  downloadTarball = async (url, bucketName, path5) => {
11531
11448
  bucketName = sanitizeBucket(bucketName);
@@ -11534,8 +11451,8 @@ var init_objectStore = __esm({
11534
11451
  if (!response2.ok) {
11535
11452
  throw new Error(`unexpected response ${response2.statusText}`);
11536
11453
  }
11537
- const tmpPath = (0, import_path3.join)(budibaseTempDir(), path5);
11538
- await streamPipeline(response2.body, import_zlib2.default.createUnzip(), import_tar_fs.default.extract(tmpPath));
11454
+ const tmpPath = (0, import_path2.join)(budibaseTempDir(), path5);
11455
+ await streamPipeline(response2.body, import_zlib.default.createUnzip(), import_tar_fs.default.extract(tmpPath));
11539
11456
  if (!environment_default.isTest() && environment_default.SELF_HOSTED) {
11540
11457
  await uploadDirectory(bucketName, tmpPath, path5);
11541
11458
  }
@@ -12117,16 +12034,16 @@ var init_constants4 = __esm({
12117
12034
  });
12118
12035
 
12119
12036
  // src/utilities/centralPath.ts
12120
- function join4(...args) {
12121
- return import_path4.default.join(...args);
12037
+ function join3(...args) {
12038
+ return import_path3.default.join(...args);
12122
12039
  }
12123
12040
  function resolve(...args) {
12124
- return import_path4.default.resolve(...args);
12041
+ return import_path3.default.resolve(...args);
12125
12042
  }
12126
- var import_path4;
12043
+ var import_path3;
12127
12044
  var init_centralPath = __esm({
12128
12045
  "src/utilities/centralPath.ts"() {
12129
- import_path4 = __toESM(require("path"));
12046
+ import_path3 = __toESM(require("path"));
12130
12047
  }
12131
12048
  });
12132
12049
 
@@ -12148,14 +12065,14 @@ function parseIntSafe(number) {
12148
12065
  return parseInt(number);
12149
12066
  }
12150
12067
  }
12151
- var import_path5, LOADED2, environment2, environment_default2;
12068
+ var import_path4, LOADED2, environment2, environment_default2;
12152
12069
  var init_environment3 = __esm({
12153
12070
  "src/environment.ts"() {
12154
- import_path5 = require("path");
12071
+ import_path4 = require("path");
12155
12072
  LOADED2 = false;
12156
12073
  if (!LOADED2 && isDev2() && !isTest2()) {
12157
12074
  require("dotenv").config({
12158
- path: (0, import_path5.join)(__dirname, "..", ".env")
12075
+ path: (0, import_path4.join)(__dirname, "..", ".env")
12159
12076
  });
12160
12077
  LOADED2 = true;
12161
12078
  }
@@ -12239,22 +12156,22 @@ var init_environment3 = __esm({
12239
12156
  });
12240
12157
 
12241
12158
  // src/utilities/fileSystem/filesystem.ts
12242
- var import_fs5, import_path6, import_tar, uuid2, TOP_LEVEL_PATH, init9, checkDevelopmentEnvironment, loadHandlebarsFile, apiFileReturn, streamFile, createTempFolder, extractTarball, findFileRec, deleteFolderFileSystem;
12159
+ var import_fs4, import_path5, import_tar, uuid2, TOP_LEVEL_PATH, init9, checkDevelopmentEnvironment, loadHandlebarsFile, apiFileReturn, streamFile, createTempFolder, extractTarball, findFileRec, deleteFolderFileSystem;
12243
12160
  var init_filesystem = __esm({
12244
12161
  "src/utilities/fileSystem/filesystem.ts"() {
12245
- import_fs5 = __toESM(require("fs"));
12162
+ import_fs4 = __toESM(require("fs"));
12246
12163
  init_budibaseDir();
12247
- import_path6 = require("path");
12164
+ import_path5 = require("path");
12248
12165
  init_environment3();
12249
12166
  import_tar = __toESM(require("tar"));
12250
12167
  init_environment3();
12251
12168
  uuid2 = require("uuid/v4");
12252
- TOP_LEVEL_PATH = environment_default2.TOP_LEVEL_PATH || (0, import_path6.resolve)((0, import_path6.join)(__dirname, "..", "..", ".."));
12169
+ TOP_LEVEL_PATH = environment_default2.TOP_LEVEL_PATH || (0, import_path5.resolve)((0, import_path5.join)(__dirname, "..", "..", ".."));
12253
12170
  init9 = () => {
12254
12171
  const tempDir = budibaseTempDir2();
12255
- if (!import_fs5.default.existsSync(tempDir)) {
12172
+ if (!import_fs4.default.existsSync(tempDir)) {
12256
12173
  try {
12257
- import_fs5.default.mkdirSync(tempDir);
12174
+ import_fs4.default.mkdirSync(tempDir);
12258
12175
  } catch (err) {
12259
12176
  if (!err || err.code !== "EEXIST") {
12260
12177
  throw err;
@@ -12266,11 +12183,11 @@ var init_filesystem = __esm({
12266
12183
  if (!environment_default2.isDev() || environment_default2.isTest()) {
12267
12184
  return;
12268
12185
  }
12269
- if (!import_fs5.default.existsSync(budibaseTempDir2())) {
12270
- import_fs5.default.mkdirSync(budibaseTempDir2());
12186
+ if (!import_fs4.default.existsSync(budibaseTempDir2())) {
12187
+ import_fs4.default.mkdirSync(budibaseTempDir2());
12271
12188
  }
12272
12189
  let error2;
12273
- if (!import_fs5.default.existsSync((0, import_path6.join)(process.cwd(), ".env"))) {
12190
+ if (!import_fs4.default.existsSync((0, import_path5.join)(process.cwd(), ".env"))) {
12274
12191
  error2 = "Must run via yarn once to generate environment.";
12275
12192
  }
12276
12193
  if (error2) {
@@ -12279,23 +12196,23 @@ var init_filesystem = __esm({
12279
12196
  }
12280
12197
  };
12281
12198
  loadHandlebarsFile = (path5) => {
12282
- return import_fs5.default.readFileSync(path5, "utf8");
12199
+ return import_fs4.default.readFileSync(path5, "utf8");
12283
12200
  };
12284
12201
  apiFileReturn = (contents) => {
12285
- const path5 = (0, import_path6.join)(budibaseTempDir2(), uuid2());
12286
- import_fs5.default.writeFileSync(path5, contents);
12287
- return import_fs5.default.createReadStream(path5);
12202
+ const path5 = (0, import_path5.join)(budibaseTempDir2(), uuid2());
12203
+ import_fs4.default.writeFileSync(path5, contents);
12204
+ return import_fs4.default.createReadStream(path5);
12288
12205
  };
12289
12206
  streamFile = (path5) => {
12290
- return import_fs5.default.createReadStream(path5);
12207
+ return import_fs4.default.createReadStream(path5);
12291
12208
  };
12292
12209
  createTempFolder = (item) => {
12293
- const path5 = (0, import_path6.join)(budibaseTempDir2(), item);
12210
+ const path5 = (0, import_path5.join)(budibaseTempDir2(), item);
12294
12211
  try {
12295
- if (import_fs5.default.existsSync(path5)) {
12296
- import_fs5.default.rmSync(path5, { recursive: true, force: true });
12212
+ if (import_fs4.default.existsSync(path5)) {
12213
+ import_fs4.default.rmSync(path5, { recursive: true, force: true });
12297
12214
  }
12298
- import_fs5.default.mkdirSync(path5);
12215
+ import_fs4.default.mkdirSync(path5);
12299
12216
  } catch (err) {
12300
12217
  throw new Error(`Path cannot be created: ${err.message}`);
12301
12218
  }
@@ -12308,13 +12225,13 @@ var init_filesystem = __esm({
12308
12225
  });
12309
12226
  };
12310
12227
  findFileRec = (startPath, filter2) => {
12311
- if (!import_fs5.default.existsSync(startPath)) {
12228
+ if (!import_fs4.default.existsSync(startPath)) {
12312
12229
  return;
12313
12230
  }
12314
- const files2 = import_fs5.default.readdirSync(startPath);
12231
+ const files2 = import_fs4.default.readdirSync(startPath);
12315
12232
  for (let i = 0, len = files2.length; i < len; i++) {
12316
- const filename = (0, import_path6.join)(startPath, files2[i]);
12317
- const stat = import_fs5.default.lstatSync(filename);
12233
+ const filename = (0, import_path5.join)(startPath, files2[i]);
12234
+ const stat = import_fs4.default.lstatSync(filename);
12318
12235
  if (stat.isDirectory()) {
12319
12236
  return findFileRec(filename, filter2);
12320
12237
  } else if (filename.endsWith(filter2)) {
@@ -12323,10 +12240,10 @@ var init_filesystem = __esm({
12323
12240
  }
12324
12241
  };
12325
12242
  deleteFolderFileSystem = (path5) => {
12326
- if (!import_fs5.default.existsSync(path5)) {
12243
+ if (!import_fs4.default.existsSync(path5)) {
12327
12244
  return;
12328
12245
  }
12329
- import_fs5.default.rmSync(path5, { recursive: true, force: true });
12246
+ import_fs4.default.rmSync(path5, { recursive: true, force: true });
12330
12247
  };
12331
12248
  }
12332
12249
  });
@@ -12340,12 +12257,12 @@ async function backupClientLibrary(appId) {
12340
12257
  try {
12341
12258
  tmpManifestPath = await objectStore_exports2.retrieveToTmp(
12342
12259
  ObjectStoreBuckets2.APPS,
12343
- (0, import_path7.join)(appId, "manifest.json")
12260
+ (0, import_path6.join)(appId, "manifest.json")
12344
12261
  );
12345
12262
  } catch (error2) {
12346
12263
  tmpManifestPath = await objectStore_exports2.retrieveToTmp(
12347
12264
  ObjectStoreBuckets2.APPS,
12348
- (0, import_path7.join)(
12265
+ (0, import_path6.join)(
12349
12266
  appId,
12350
12267
  "node_modules",
12351
12268
  "budibase",
@@ -12357,17 +12274,17 @@ async function backupClientLibrary(appId) {
12357
12274
  }
12358
12275
  const tmpClientPath = await objectStore_exports2.retrieveToTmp(
12359
12276
  ObjectStoreBuckets2.APPS,
12360
- (0, import_path7.join)(appId, "budibase-client.js")
12277
+ (0, import_path6.join)(appId, "budibase-client.js")
12361
12278
  );
12362
12279
  const manifestUpload = objectStore_exports2.upload({
12363
12280
  bucket: ObjectStoreBuckets2.APPS,
12364
- filename: (0, import_path7.join)(appId, "manifest.json.bak"),
12281
+ filename: (0, import_path6.join)(appId, "manifest.json.bak"),
12365
12282
  path: tmpManifestPath,
12366
12283
  type: "application/json"
12367
12284
  });
12368
12285
  const clientUpload = objectStore_exports2.upload({
12369
12286
  bucket: ObjectStoreBuckets2.APPS,
12370
- filename: (0, import_path7.join)(appId, "budibase-client.js.bak"),
12287
+ filename: (0, import_path6.join)(appId, "budibase-client.js.bak"),
12371
12288
  path: tmpClientPath,
12372
12289
  type: "application/javascript"
12373
12290
  });
@@ -12377,7 +12294,7 @@ async function updateClientLibrary(appId) {
12377
12294
  let manifest, client3;
12378
12295
  if (environment_default2.isDev()) {
12379
12296
  const clientPath = devClientLibPath();
12380
- manifest = (0, import_path7.join)(import_path7.default.dirname(import_path7.default.dirname(clientPath)), "manifest.json");
12297
+ manifest = (0, import_path6.join)(import_path6.default.dirname(import_path6.default.dirname(clientPath)), "manifest.json");
12381
12298
  client3 = clientPath;
12382
12299
  } else {
12383
12300
  manifest = resolve(TOP_LEVEL_PATH, "client", "manifest.json");
@@ -12385,16 +12302,16 @@ async function updateClientLibrary(appId) {
12385
12302
  }
12386
12303
  const manifestUpload = objectStore_exports2.streamUpload(
12387
12304
  ObjectStoreBuckets2.APPS,
12388
- (0, import_path7.join)(appId, "manifest.json"),
12389
- import_fs6.default.createReadStream(manifest),
12305
+ (0, import_path6.join)(appId, "manifest.json"),
12306
+ import_fs5.default.createReadStream(manifest),
12390
12307
  {
12391
12308
  ContentType: "application/json"
12392
12309
  }
12393
12310
  );
12394
12311
  const clientUpload = objectStore_exports2.streamUpload(
12395
12312
  ObjectStoreBuckets2.APPS,
12396
- (0, import_path7.join)(appId, "budibase-client.js"),
12397
- import_fs6.default.createReadStream(client3),
12313
+ (0, import_path6.join)(appId, "budibase-client.js"),
12314
+ import_fs5.default.createReadStream(client3),
12398
12315
  {
12399
12316
  ContentType: "application/javascript"
12400
12317
  }
@@ -12404,32 +12321,32 @@ async function updateClientLibrary(appId) {
12404
12321
  async function revertClientLibrary(appId) {
12405
12322
  const tmpManifestPath = await objectStore_exports2.retrieveToTmp(
12406
12323
  ObjectStoreBuckets2.APPS,
12407
- (0, import_path7.join)(appId, "manifest.json.bak")
12324
+ (0, import_path6.join)(appId, "manifest.json.bak")
12408
12325
  );
12409
12326
  const tmpClientPath = await objectStore_exports2.retrieveToTmp(
12410
12327
  ObjectStoreBuckets2.APPS,
12411
- (0, import_path7.join)(appId, "budibase-client.js.bak")
12328
+ (0, import_path6.join)(appId, "budibase-client.js.bak")
12412
12329
  );
12413
12330
  const manifestUpload = objectStore_exports2.upload({
12414
12331
  bucket: ObjectStoreBuckets2.APPS,
12415
- filename: (0, import_path7.join)(appId, "manifest.json"),
12332
+ filename: (0, import_path6.join)(appId, "manifest.json"),
12416
12333
  path: tmpManifestPath,
12417
12334
  type: "application/json"
12418
12335
  });
12419
12336
  const clientUpload = objectStore_exports2.upload({
12420
12337
  bucket: ObjectStoreBuckets2.APPS,
12421
- filename: (0, import_path7.join)(appId, "budibase-client.js"),
12338
+ filename: (0, import_path6.join)(appId, "budibase-client.js"),
12422
12339
  path: tmpClientPath,
12423
12340
  type: "application/javascript"
12424
12341
  });
12425
12342
  await Promise.all([manifestUpload, clientUpload]);
12426
12343
  }
12427
- var import_path7, import_fs6;
12344
+ var import_path6, import_fs5;
12428
12345
  var init_clientLibrary = __esm({
12429
12346
  "src/utilities/fileSystem/clientLibrary.ts"() {
12430
- import_path7 = __toESM(require("path"));
12347
+ import_path6 = __toESM(require("path"));
12431
12348
  init_constants4();
12432
- import_fs6 = __toESM(require("fs"));
12349
+ import_fs5 = __toESM(require("fs"));
12433
12350
  init_src2();
12434
12351
  init_centralPath();
12435
12352
  init_environment3();
@@ -12438,18 +12355,18 @@ var init_clientLibrary = __esm({
12438
12355
  });
12439
12356
 
12440
12357
  // src/utilities/fileSystem/app.ts
12441
- var import_fs7, import_path8, NODE_MODULES_PATH, createApp, deleteApp, getComponentLibraryManifest;
12358
+ var import_fs6, import_path7, NODE_MODULES_PATH, createApp, deleteApp, getComponentLibraryManifest;
12442
12359
  var init_app7 = __esm({
12443
12360
  "src/utilities/fileSystem/app.ts"() {
12444
12361
  init_budibaseDir();
12445
- import_fs7 = __toESM(require("fs"));
12446
- import_path8 = require("path");
12362
+ import_fs6 = __toESM(require("fs"));
12363
+ import_path7 = require("path");
12447
12364
  init_constants4();
12448
12365
  init_clientLibrary();
12449
12366
  init_environment3();
12450
12367
  init_src2();
12451
12368
  init_filesystem();
12452
- NODE_MODULES_PATH = (0, import_path8.join)(TOP_LEVEL_PATH, "node_modules");
12369
+ NODE_MODULES_PATH = (0, import_path7.join)(TOP_LEVEL_PATH, "node_modules");
12453
12370
  createApp = async (appId) => {
12454
12371
  await updateClientLibrary(appId);
12455
12372
  };
@@ -12461,11 +12378,11 @@ var init_app7 = __esm({
12461
12378
  const filename = "manifest.json";
12462
12379
  if (environment_default2.isDev() || environment_default2.isTest()) {
12463
12380
  const paths = [
12464
- (0, import_path8.join)(TOP_LEVEL_PATH, "packages/client", filename),
12465
- (0, import_path8.join)(process.cwd(), "client", filename)
12381
+ (0, import_path7.join)(TOP_LEVEL_PATH, "packages/client", filename),
12382
+ (0, import_path7.join)(process.cwd(), "client", filename)
12466
12383
  ];
12467
12384
  for (let path6 of paths) {
12468
- if (import_fs7.default.existsSync(path6)) {
12385
+ if (import_fs6.default.existsSync(path6)) {
12469
12386
  delete require.cache[require.resolve(path6)];
12470
12387
  return require(path6);
12471
12388
  }
@@ -12480,14 +12397,14 @@ var init_app7 = __esm({
12480
12397
  let resp;
12481
12398
  let path5;
12482
12399
  try {
12483
- path5 = (0, import_path8.join)(appId, filename);
12400
+ path5 = (0, import_path7.join)(appId, filename);
12484
12401
  resp = await objectStore_exports2.retrieve(ObjectStoreBuckets2.APPS, path5);
12485
12402
  } catch (error2) {
12486
12403
  console.error(
12487
12404
  `component-manifest-objectstore=failed appId=${appId} path=${path5}`,
12488
12405
  error2
12489
12406
  );
12490
- path5 = (0, import_path8.join)(appId, "node_modules", library, "package", filename);
12407
+ path5 = (0, import_path7.join)(appId, "node_modules", library, "package", filename);
12491
12408
  resp = await objectStore_exports2.retrieve(ObjectStoreBuckets2.APPS, path5);
12492
12409
  }
12493
12410
  if (typeof resp !== "string") {
@@ -12502,19 +12419,19 @@ var init_app7 = __esm({
12502
12419
  async function getPluginImpl(path5, plugin) {
12503
12420
  var _a2;
12504
12421
  const hash3 = (_a2 = plugin.schema) == null ? void 0 : _a2.hash;
12505
- if (!import_fs8.default.existsSync(path5)) {
12506
- import_fs8.default.mkdirSync(path5);
12422
+ if (!import_fs7.default.existsSync(path5)) {
12423
+ import_fs7.default.mkdirSync(path5);
12507
12424
  }
12508
- const filename = (0, import_path9.join)(path5, plugin.name);
12425
+ const filename = (0, import_path8.join)(path5, plugin.name);
12509
12426
  const metadataName = `${filename}.bbmetadata`;
12510
- if (import_fs8.default.existsSync(filename)) {
12511
- const currentHash = import_fs8.default.readFileSync(metadataName, "utf8");
12427
+ if (import_fs7.default.existsSync(filename)) {
12428
+ const currentHash = import_fs7.default.readFileSync(metadataName, "utf8");
12512
12429
  if (currentHash === hash3) {
12513
12430
  return require(filename);
12514
12431
  } else {
12515
12432
  console.log(`Updating plugin: ${plugin.name}`);
12516
12433
  delete require.cache[require.resolve(filename)];
12517
- import_fs8.default.unlinkSync(filename);
12434
+ import_fs7.default.unlinkSync(filename);
12518
12435
  }
12519
12436
  }
12520
12437
  const pluginKey = objectStore_exports2.getPluginJSKey(plugin);
@@ -12522,24 +12439,24 @@ async function getPluginImpl(path5, plugin) {
12522
12439
  objectStore_exports2.ObjectStoreBuckets.PLUGINS,
12523
12440
  pluginKey
12524
12441
  );
12525
- import_fs8.default.writeFileSync(filename, pluginJs);
12526
- import_fs8.default.writeFileSync(metadataName, hash3);
12442
+ import_fs7.default.writeFileSync(filename, pluginJs);
12443
+ import_fs7.default.writeFileSync(metadataName, hash3);
12527
12444
  return require(filename);
12528
12445
  }
12529
- var import_fs8, import_path9, DATASOURCE_PATH, AUTOMATION_PATH, getPluginMetadata, getDatasourcePlugin, getAutomationPlugin;
12446
+ var import_fs7, import_path8, DATASOURCE_PATH, AUTOMATION_PATH, getPluginMetadata, getDatasourcePlugin, getAutomationPlugin;
12530
12447
  var init_plugin5 = __esm({
12531
12448
  "src/utilities/fileSystem/plugin.ts"() {
12532
12449
  init_budibaseDir();
12533
- import_fs8 = __toESM(require("fs"));
12534
- import_path9 = require("path");
12450
+ import_fs7 = __toESM(require("fs"));
12451
+ import_path8 = require("path");
12535
12452
  init_src2();
12536
- DATASOURCE_PATH = (0, import_path9.join)(budibaseTempDir2(), "datasource");
12537
- AUTOMATION_PATH = (0, import_path9.join)(budibaseTempDir2(), "automation");
12453
+ DATASOURCE_PATH = (0, import_path8.join)(budibaseTempDir2(), "datasource");
12454
+ AUTOMATION_PATH = (0, import_path8.join)(budibaseTempDir2(), "automation");
12538
12455
  getPluginMetadata = async (path5) => {
12539
12456
  let metadata2 = {};
12540
12457
  try {
12541
- const pkg2 = import_fs8.default.readFileSync((0, import_path9.join)(path5, "package.json"), "utf8");
12542
- const schema = import_fs8.default.readFileSync((0, import_path9.join)(path5, "schema.json"), "utf8");
12458
+ const pkg2 = import_fs7.default.readFileSync((0, import_path8.join)(path5, "package.json"), "utf8");
12459
+ const schema = import_fs7.default.readFileSync((0, import_path8.join)(path5, "schema.json"), "utf8");
12543
12460
  metadata2.schema = JSON.parse(schema);
12544
12461
  metadata2.package = JSON.parse(pkg2);
12545
12462
  if (!metadata2.package.name || !metadata2.package.version || !metadata2.package.description) {
@@ -13807,21 +13724,21 @@ __export(version_exports, {
13807
13724
  getLicenseVersion: () => getLicenseVersion,
13808
13725
  getProVersion: () => getProVersion
13809
13726
  });
13810
- var import_fs9, import_path10, getLicenseVersion, getProVersion;
13727
+ var import_fs8, import_path9, getLicenseVersion, getProVersion;
13811
13728
  var init_version2 = __esm({
13812
13729
  "../pro/packages/pro/src/constants/version.ts"() {
13813
13730
  init_src2();
13814
- import_fs9 = __toESM(require("fs"));
13815
- import_path10 = __toESM(require("path"));
13731
+ import_fs8 = __toESM(require("fs"));
13732
+ import_path9 = __toESM(require("path"));
13816
13733
  getLicenseVersion = () => {
13817
13734
  if (environment_default.isDev()) {
13818
13735
  const DEV_VER_FILENAME = "dev-version.txt";
13819
- const verFile = import_path10.default.join(objectStore_exports2.budibaseTempDir(), DEV_VER_FILENAME);
13820
- if (import_fs9.default.existsSync(verFile)) {
13821
- return import_fs9.default.readFileSync(verFile, "utf8");
13736
+ const verFile = import_path9.default.join(objectStore_exports2.budibaseTempDir(), DEV_VER_FILENAME);
13737
+ if (import_fs8.default.existsSync(verFile)) {
13738
+ return import_fs8.default.readFileSync(verFile, "utf8");
13822
13739
  } else {
13823
13740
  const devVer = utils_exports2.newid();
13824
- import_fs9.default.writeFileSync(verFile, devVer);
13741
+ import_fs8.default.writeFileSync(verFile, devVer);
13825
13742
  return devVer;
13826
13743
  }
13827
13744
  } else {
@@ -14267,31 +14184,31 @@ function getOfflineLicense() {
14267
14184
  }
14268
14185
  }
14269
14186
  function getOfflineLicenseFromDisk() {
14270
- if (import_fs10.default.existsSync(LICENSE_FILE_PATH)) {
14271
- const token = import_fs10.default.readFileSync(LICENSE_FILE_PATH, { encoding: "utf-8" });
14187
+ if (import_fs9.default.existsSync(LICENSE_FILE_PATH)) {
14188
+ const token = import_fs9.default.readFileSync(LICENSE_FILE_PATH, { encoding: "utf-8" });
14272
14189
  return import_jsonwebtoken.default.verify(token, PUBLIC_KEY, { algorithms: ["RS256"] });
14273
14190
  }
14274
14191
  }
14275
14192
  function writeOfflineLicenseToDisk(signedLicense) {
14276
- import_fs10.default.writeFileSync(LICENSE_FILE_PATH, signedLicense, { encoding: "utf-8" });
14193
+ import_fs9.default.writeFileSync(LICENSE_FILE_PATH, signedLicense, { encoding: "utf-8" });
14277
14194
  }
14278
14195
  function deleteOfflineLicense() {
14279
- import_fs10.default.rmSync(LICENSE_FILE_PATH, { force: true });
14196
+ import_fs9.default.rmSync(LICENSE_FILE_PATH, { force: true });
14280
14197
  }
14281
- var import_fs10, import_path11, import_os2, import_jsonwebtoken, SUB_DIRECTORY, DIRECTORY, OFFLINE_LICENSE_FILE, LICENSE_FILE_PATH, PUBLIC_KEY;
14198
+ var import_fs9, import_path10, import_os2, import_jsonwebtoken, SUB_DIRECTORY, DIRECTORY, OFFLINE_LICENSE_FILE, LICENSE_FILE_PATH, PUBLIC_KEY;
14282
14199
  var init_offline = __esm({
14283
14200
  "../pro/packages/pro/src/sdk/licensing/licenses/offline.ts"() {
14284
- import_fs10 = __toESM(require("fs"));
14285
- import_path11 = require("path");
14201
+ import_fs9 = __toESM(require("fs"));
14202
+ import_path10 = require("path");
14286
14203
  import_os2 = require("os");
14287
14204
  import_jsonwebtoken = __toESM(require("jsonwebtoken"));
14288
14205
  init_src2();
14289
14206
  SUB_DIRECTORY = environment_default.isTest() ? ".budibase-test" : ".budibase";
14290
- DIRECTORY = (0, import_path11.join)((0, import_os2.tmpdir)(), SUB_DIRECTORY);
14207
+ DIRECTORY = (0, import_path10.join)((0, import_os2.tmpdir)(), SUB_DIRECTORY);
14291
14208
  OFFLINE_LICENSE_FILE = "offline_license.txt";
14292
- LICENSE_FILE_PATH = (0, import_path11.join)(DIRECTORY, OFFLINE_LICENSE_FILE);
14293
- if (!import_fs10.default.existsSync(DIRECTORY)) {
14294
- import_fs10.default.mkdirSync(DIRECTORY);
14209
+ LICENSE_FILE_PATH = (0, import_path10.join)(DIRECTORY, OFFLINE_LICENSE_FILE);
14210
+ if (!import_fs9.default.existsSync(DIRECTORY)) {
14211
+ import_fs9.default.mkdirSync(DIRECTORY);
14295
14212
  }
14296
14213
  PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvz3jePLCFBXZ19c8Dpkv\nXtSgOhKFOcvQdo/LV0KJRUzQWDPWuO4ILtBtnqhjtIzZH4CH0qCYBet5L6Qr4CM1\nl2HXiAD1Q2rlHNW9wDaYyKb1F5f+v4RyqCAyzlkwRdksmkLeECTboojNnmRCrE3C\n8suunQP5bEScqEY2kclqzSf8e6xqMzPUg3mL/pNa1iEv7TuLbU9nJfgR36l0WmZY\n94fWnSaT8OSXSqcxsaByf06gfS3HAoTJNc7eqz1Hf9fUORQGPUAnFK8cT3SfdA36\nd/o3ZWE1TTj1zYwlCLN5qRKr3hU8nC3xEYNEbkB9SfTRaOq9Q7P8WmfLkoCPm3pR\nmwIDAQAB\n-----END PUBLIC KEY-----\n";
14297
14214
  }
@@ -15748,13 +15665,13 @@ var init_groups6 = __esm({
15748
15665
 
15749
15666
  // ../pro/packages/pro/src/utilities/fileSystem.ts
15750
15667
  function loadJSFile(directory2, name2) {
15751
- return import_fs11.default.readFileSync((0, import_path12.join)(directory2, name2), "utf8");
15668
+ return import_fs10.default.readFileSync((0, import_path11.join)(directory2, name2), "utf8");
15752
15669
  }
15753
- var import_fs11, import_path12;
15670
+ var import_fs10, import_path11;
15754
15671
  var init_fileSystem2 = __esm({
15755
15672
  "../pro/packages/pro/src/utilities/fileSystem.ts"() {
15756
- import_fs11 = __toESM(require("fs"));
15757
- import_path12 = require("path");
15673
+ import_fs10 = __toESM(require("fs"));
15674
+ import_path11 = require("path");
15758
15675
  }
15759
15676
  });
15760
15677
 
@@ -18721,8 +18638,8 @@ async function runBackup(trigger3, tenantId, appId, opts) {
18721
18638
  }
18722
18639
  });
18723
18640
  await updateMetadata2("complete" /* COMPLETE */, { filename, contents });
18724
- if (import_fs12.default.existsSync(tarPath)) {
18725
- import_fs12.default.rmSync(tarPath);
18641
+ if (import_fs11.default.existsSync(tarPath)) {
18642
+ import_fs11.default.rmSync(tarPath);
18726
18643
  }
18727
18644
  } catch (err) {
18728
18645
  logging_exports.logAlert("App backup error", err);
@@ -18780,14 +18697,14 @@ async function exportProcessor(job, opts) {
18780
18697
  });
18781
18698
  });
18782
18699
  }
18783
- var import_fs12;
18700
+ var import_fs11;
18784
18701
  var init_processing = __esm({
18785
18702
  "../pro/packages/pro/src/sdk/backups/processing.ts"() {
18786
18703
  init_src2();
18787
18704
  init_backup5();
18788
18705
  init_src();
18789
18706
  init_queue4();
18790
- import_fs12 = __toESM(require("fs"));
18707
+ import_fs11 = __toESM(require("fs"));
18791
18708
  }
18792
18709
  });
18793
18710
 
@@ -19470,15 +19387,15 @@ async function downloadBackup(ctx) {
19470
19387
  const backupId = ctx.params.backupId;
19471
19388
  const { metadata: metadata2, path: path5 } = await backups_default.downloadAppBackup(backupId);
19472
19389
  ctx.attachment(`backup-${metadata2.timestamp}.tar.gz`);
19473
- ctx.body = import_fs13.default.createReadStream(path5);
19390
+ ctx.body = import_fs12.default.createReadStream(path5);
19474
19391
  }
19475
- var import_fs13;
19392
+ var import_fs12;
19476
19393
  var init_backups3 = __esm({
19477
19394
  "../pro/packages/pro/src/api/controllers/apps/backups.ts"() {
19478
19395
  init_src();
19479
19396
  init_sdk2();
19480
19397
  init_src2();
19481
- import_fs13 = __toESM(require("fs"));
19398
+ import_fs12 = __toESM(require("fs"));
19482
19399
  }
19483
19400
  });
19484
19401
 
@@ -20117,39 +20034,11 @@ var init_filters = __esm({
20117
20034
  // ../shared-core/src/utils.ts
20118
20035
  var utils_exports5 = {};
20119
20036
  __export(utils_exports5, {
20120
- parallelForeach: () => parallelForeach,
20121
20037
  unreachable: () => unreachable
20122
20038
  });
20123
20039
  function unreachable(value, message = `No such case in exhaustive switch: ${value}`) {
20124
20040
  throw new Error(message);
20125
20041
  }
20126
- async function parallelForeach(items, task, maxConcurrency) {
20127
- const promises = [];
20128
- let index2 = 0;
20129
- const processItem = async (item) => {
20130
- try {
20131
- await task(item);
20132
- } finally {
20133
- processNext();
20134
- }
20135
- };
20136
- const processNext = () => {
20137
- if (index2 >= items.length) {
20138
- return;
20139
- }
20140
- const item = items[index2];
20141
- index2++;
20142
- const promise = processItem(item);
20143
- promises.push(promise);
20144
- if (promises.length >= maxConcurrency) {
20145
- Promise.race(promises).then(processNext);
20146
- } else {
20147
- processNext();
20148
- }
20149
- };
20150
- processNext();
20151
- await Promise.all(promises);
20152
- }
20153
20042
  var init_utils13 = __esm({
20154
20043
  "../shared-core/src/utils.ts"() {
20155
20044
  }
@@ -20743,7 +20632,7 @@ var init_currentapp = __esm({
20743
20632
  userId,
20744
20633
  globalId,
20745
20634
  roleId,
20746
- role: await roles_exports.getRole(roleId, { defaultPublic: true })
20635
+ role: await roles_exports.getRole(roleId)
20747
20636
  };
20748
20637
  }
20749
20638
  return next();
@@ -24394,6 +24283,13 @@ function convertBookmark(bookmark) {
24394
24283
  }
24395
24284
  return bookmark;
24396
24285
  }
24286
+ function isQsTrue(param) {
24287
+ if (typeof param === "string") {
24288
+ return param.toLowerCase() === "true";
24289
+ } else {
24290
+ return param === true;
24291
+ }
24292
+ }
24397
24293
  var import_stream2, Readable, isDev3, NUMBER_REGEX;
24398
24294
  var init_utilities2 = __esm({
24399
24295
  "src/utilities/index.ts"() {
@@ -24447,16 +24343,7 @@ async function checkResponse(response2, errorMsg, { ctx } = {}) {
24447
24343
  }
24448
24344
  return response2.json();
24449
24345
  }
24450
- async function sendSmtpEmail({
24451
- to,
24452
- from,
24453
- subject,
24454
- contents,
24455
- cc,
24456
- bcc,
24457
- automation,
24458
- invite
24459
- }) {
24346
+ async function sendSmtpEmail(to, from, subject, contents, cc, bcc, automation) {
24460
24347
  const response2 = await (0, import_node_fetch8.default)(
24461
24348
  checkSlashesInUrl2(environment_default2.WORKER_URL + `/api/global/email/send`),
24462
24349
  request(void 0, {
@@ -24469,8 +24356,7 @@ async function sendSmtpEmail({
24469
24356
  cc,
24470
24357
  bcc,
24471
24358
  purpose: "custom",
24472
- automation,
24473
- invite
24359
+ automation
24474
24360
  }
24475
24361
  })
24476
24362
  );
@@ -24963,22 +24849,22 @@ function threadSetup() {
24963
24849
  init10();
24964
24850
  }
24965
24851
  async function checkCacheForDynamicVariable(queryId, variable) {
24966
- const cache3 = await getClient3();
24967
- return cache3.get(makeVariableKey(queryId, variable));
24852
+ const cache2 = await getClient3();
24853
+ return cache2.get(makeVariableKey(queryId, variable));
24968
24854
  }
24969
24855
  async function invalidateDynamicVariables(cachedVars) {
24970
- const cache3 = await getClient3();
24856
+ const cache2 = await getClient3();
24971
24857
  let promises = [];
24972
24858
  for (let variable of cachedVars) {
24973
24859
  promises.push(
24974
- cache3.delete(makeVariableKey(variable.queryId, variable.name))
24860
+ cache2.delete(makeVariableKey(variable.queryId, variable.name))
24975
24861
  );
24976
24862
  }
24977
24863
  await Promise.all(promises);
24978
24864
  }
24979
24865
  async function storeDynamicVariable(queryId, variable, value) {
24980
- const cache3 = await getClient3();
24981
- await cache3.store(
24866
+ const cache2 = await getClient3();
24867
+ await cache2.store(
24982
24868
  makeVariableKey(queryId, variable),
24983
24869
  value,
24984
24870
  VARIABLE_TTL_SECONDS
@@ -25038,14 +24924,13 @@ __export(exports_exports, {
25038
24924
  streamExportApp: () => streamExportApp
25039
24925
  });
25040
24926
  function tarFilesToTmp(tmpDir, files2) {
25041
- const fileName = `${uuid3()}.tar.gz`;
25042
- const exportFile = (0, import_path13.join)(budibaseTempDir2(), fileName);
25043
- import_tar2.default.create(
24927
+ const exportFile = (0, import_path12.join)(budibaseTempDir2(), `${uuid3()}.tar.gz`);
24928
+ tar3.create(
25044
24929
  {
25045
24930
  sync: true,
25046
24931
  gzip: true,
25047
24932
  file: exportFile,
25048
- noDirRecurse: false,
24933
+ recursive: true,
25049
24934
  cwd: tmpDir
25050
24935
  },
25051
24936
  files2
@@ -25062,7 +24947,7 @@ async function exportDB(dbName, opts = {}) {
25062
24947
  return db_exports.doWithDB(dbName, async (db2) => {
25063
24948
  if (opts == null ? void 0 : opts.exportPath) {
25064
24949
  const path5 = opts == null ? void 0 : opts.exportPath;
25065
- const writeStream = import_fs14.default.createWriteStream(path5);
24950
+ const writeStream = import_fs13.default.createWriteStream(path5);
25066
24951
  await db2.dump(writeStream, exportOpts);
25067
24952
  return path5;
25068
24953
  } else {
@@ -25095,9 +24980,9 @@ async function exportApp(appId, config) {
25095
24980
  for (let path5 of STATIC_APP_FILES) {
25096
24981
  const contents = await objectStore_exports2.retrieve(
25097
24982
  ObjectStoreBuckets2.APPS,
25098
- (0, import_path13.join)(appPath, path5)
24983
+ (0, import_path12.join)(appPath, path5)
25099
24984
  );
25100
- import_fs14.default.writeFileSync((0, import_path13.join)(tmpPath, path5), contents);
24985
+ import_fs13.default.writeFileSync((0, import_path12.join)(tmpPath, path5), contents);
25101
24986
  }
25102
24987
  } else {
25103
24988
  tmpPath = await objectStore_exports2.retrieveDirectory(
@@ -25106,52 +24991,37 @@ async function exportApp(appId, config) {
25106
24991
  );
25107
24992
  }
25108
24993
  }
25109
- const downloadedPath = (0, import_path13.join)(tmpPath, appPath);
25110
- if (import_fs14.default.existsSync(downloadedPath)) {
25111
- const allFiles = import_fs14.default.readdirSync(downloadedPath);
24994
+ const downloadedPath = (0, import_path12.join)(tmpPath, appPath);
24995
+ if (import_fs13.default.existsSync(downloadedPath)) {
24996
+ const allFiles = import_fs13.default.readdirSync(downloadedPath);
25112
24997
  for (let file of allFiles) {
25113
- const path5 = (0, import_path13.join)(downloadedPath, file);
25114
- import_fs14.default.renameSync(path5, (0, import_path13.join)(downloadedPath, "..", file));
24998
+ const path5 = (0, import_path12.join)(downloadedPath, file);
24999
+ import_fs13.default.renameSync(path5, (0, import_path12.join)(downloadedPath, "..", file));
25115
25000
  }
25116
- import_fs14.default.rmdirSync(downloadedPath);
25001
+ import_fs13.default.rmdirSync(downloadedPath);
25117
25002
  }
25118
- const dbPath = (0, import_path13.join)(tmpPath, DB_EXPORT_FILE);
25003
+ const dbPath = (0, import_path12.join)(tmpPath, DB_EXPORT_FILE);
25119
25004
  await exportDB(appId, {
25120
25005
  filter: defineFilter(config == null ? void 0 : config.excludeRows, config == null ? void 0 : config.excludeLogs),
25121
25006
  exportPath: dbPath
25122
25007
  });
25123
- if (config == null ? void 0 : config.encryptPassword) {
25124
- for (let file of import_fs14.default.readdirSync(tmpPath)) {
25125
- const path5 = (0, import_path13.join)(tmpPath, file);
25126
- await encryption_exports.encryptFile(
25127
- { dir: tmpPath, filename: file },
25128
- config.encryptPassword
25129
- );
25130
- import_fs14.default.rmSync(path5);
25131
- }
25132
- }
25133
25008
  if (config == null ? void 0 : config.tar) {
25134
- const tarPath = tarFilesToTmp(tmpPath, import_fs14.default.readdirSync(tmpPath));
25135
- import_fs14.default.rmSync(tmpPath, { recursive: true, force: true });
25009
+ const tarPath = tarFilesToTmp(tmpPath, import_fs13.default.readdirSync(tmpPath));
25010
+ import_fs13.default.rmSync(tmpPath, { recursive: true, force: true });
25136
25011
  return tarPath;
25137
25012
  } else {
25138
25013
  return tmpPath;
25139
25014
  }
25140
25015
  }
25141
- async function streamExportApp({
25142
- appId,
25143
- excludeRows,
25144
- encryptPassword
25145
- }) {
25016
+ async function streamExportApp(appId, excludeRows) {
25146
25017
  const tmpPath = await exportApp(appId, {
25147
25018
  excludeRows,
25148
25019
  excludeLogs: true,
25149
- tar: true,
25150
- encryptPassword
25020
+ tar: true
25151
25021
  });
25152
25022
  return streamFile(tmpPath);
25153
25023
  }
25154
- var import_fs14, import_path13, import_tar2, uuid3, MemoryStream2;
25024
+ var import_fs13, import_path12, uuid3, tar3, MemoryStream2;
25155
25025
  var init_exports2 = __esm({
25156
25026
  "src/sdk/app/backups/exports.ts"() {
25157
25027
  init_src2();
@@ -25160,11 +25030,11 @@ var init_exports2 = __esm({
25160
25030
  init_constants4();
25161
25031
  init_utils9();
25162
25032
  init_constants7();
25163
- import_fs14 = __toESM(require("fs"));
25164
- import_path13 = require("path");
25033
+ import_fs13 = __toESM(require("fs"));
25034
+ import_path12 = require("path");
25165
25035
  init_environment3();
25166
- import_tar2 = __toESM(require("tar"));
25167
25036
  uuid3 = require("uuid/v4");
25037
+ tar3 = require("tar");
25168
25038
  MemoryStream2 = require("memorystream");
25169
25039
  }
25170
25040
  });
@@ -25241,16 +25111,16 @@ async function getTemplateStream(template) {
25241
25111
  throw new Error("Cannot import a non-text based file.");
25242
25112
  }
25243
25113
  if (template.file) {
25244
- return import_fs15.default.createReadStream(template.file.path);
25114
+ return import_fs14.default.createReadStream(template.file.path);
25245
25115
  } else if (template.key) {
25246
25116
  const [type, name2] = template.key.split("/");
25247
25117
  const tmpPath = await downloadTemplate(type, name2);
25248
- return import_fs15.default.createReadStream((0, import_path14.join)(tmpPath, name2, "db", "dump.txt"));
25118
+ return import_fs14.default.createReadStream((0, import_path13.join)(tmpPath, name2, "db", "dump.txt"));
25249
25119
  }
25250
25120
  }
25251
25121
  function untarFile(file) {
25252
- const tmpPath = (0, import_path14.join)(budibaseTempDir2(), uuid4());
25253
- import_fs15.default.mkdirSync(tmpPath);
25122
+ const tmpPath = (0, import_path13.join)(budibaseTempDir2(), uuid4());
25123
+ import_fs14.default.mkdirSync(tmpPath);
25254
25124
  tar4.extract({
25255
25125
  sync: true,
25256
25126
  cwd: tmpPath,
@@ -25258,49 +25128,31 @@ function untarFile(file) {
25258
25128
  });
25259
25129
  return tmpPath;
25260
25130
  }
25261
- async function decryptFiles(path5, password) {
25262
- try {
25263
- for (let file of import_fs15.default.readdirSync(path5)) {
25264
- const inputPath = (0, import_path14.join)(path5, file);
25265
- const outputPath = inputPath.replace(/\.enc$/, "");
25266
- await encryption_exports.decryptFile(inputPath, outputPath, password);
25267
- import_fs15.default.rmSync(inputPath);
25268
- }
25269
- } catch (err) {
25270
- if (err.message === "incorrect header check") {
25271
- throw new Error("File cannot be imported");
25272
- }
25273
- throw err;
25274
- }
25275
- }
25276
25131
  function getGlobalDBFile(tmpPath) {
25277
- return import_fs15.default.readFileSync((0, import_path14.join)(tmpPath, GLOBAL_DB_EXPORT_FILE), "utf8");
25132
+ return import_fs14.default.readFileSync((0, import_path13.join)(tmpPath, GLOBAL_DB_EXPORT_FILE), "utf8");
25278
25133
  }
25279
25134
  function getListOfAppsInMulti(tmpPath) {
25280
- return import_fs15.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
25135
+ return import_fs14.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
25281
25136
  }
25282
25137
  async function importApp(appId, db2, template) {
25283
25138
  var _a2, _b2;
25284
25139
  let prodAppId = db_exports.getProdAppID(appId);
25285
25140
  let dbStream;
25286
25141
  const isTar = template.file && ((_b2 = (_a2 = template == null ? void 0 : template.file) == null ? void 0 : _a2.type) == null ? void 0 : _b2.endsWith("gzip"));
25287
- const isDirectory = template.file && import_fs15.default.lstatSync(template.file.path).isDirectory();
25142
+ const isDirectory = template.file && import_fs14.default.lstatSync(template.file.path).isDirectory();
25288
25143
  if (template.file && (isTar || isDirectory)) {
25289
25144
  const tmpPath = isTar ? untarFile(template.file) : template.file.path;
25290
- if (isTar && template.file.password) {
25291
- await decryptFiles(tmpPath, template.file.password);
25292
- }
25293
- const contents = import_fs15.default.readdirSync(tmpPath);
25145
+ const contents = import_fs14.default.readdirSync(tmpPath);
25294
25146
  if (contents.length) {
25295
25147
  let promises = [];
25296
25148
  let excludedFiles = [GLOBAL_DB_EXPORT_FILE, DB_EXPORT_FILE];
25297
25149
  for (let filename of contents) {
25298
- const path5 = (0, import_path14.join)(tmpPath, filename);
25150
+ const path5 = (0, import_path13.join)(tmpPath, filename);
25299
25151
  if (excludedFiles.includes(filename)) {
25300
25152
  continue;
25301
25153
  }
25302
- filename = (0, import_path14.join)(prodAppId, filename);
25303
- if (import_fs15.default.lstatSync(path5).isDirectory()) {
25154
+ filename = (0, import_path13.join)(prodAppId, filename);
25155
+ if (import_fs14.default.lstatSync(path5).isDirectory()) {
25304
25156
  promises.push(
25305
25157
  objectStore_exports2.uploadDirectory(ObjectStoreBuckets2.APPS, path5, filename)
25306
25158
  );
@@ -25316,7 +25168,7 @@ async function importApp(appId, db2, template) {
25316
25168
  }
25317
25169
  await Promise.all(promises);
25318
25170
  }
25319
- dbStream = import_fs15.default.createReadStream((0, import_path14.join)(tmpPath, DB_EXPORT_FILE));
25171
+ dbStream = import_fs14.default.createReadStream((0, import_path13.join)(tmpPath, DB_EXPORT_FILE));
25320
25172
  } else {
25321
25173
  dbStream = await getTemplateStream(template);
25322
25174
  }
@@ -25328,7 +25180,7 @@ async function importApp(appId, db2, template) {
25328
25180
  await updateAutomations(prodAppId, db2);
25329
25181
  return ok;
25330
25182
  }
25331
- var import_path14, import_fs15, uuid4, tar4;
25183
+ var import_path13, import_fs14, uuid4, tar4;
25332
25184
  var init_imports = __esm({
25333
25185
  "src/sdk/app/backups/imports.ts"() {
25334
25186
  init_src2();
@@ -25337,8 +25189,8 @@ var init_imports = __esm({
25337
25189
  init_constants7();
25338
25190
  init_fileSystem();
25339
25191
  init_constants4();
25340
- import_path14 = require("path");
25341
- import_fs15 = __toESM(require("fs"));
25192
+ import_path13 = require("path");
25193
+ import_fs14 = __toESM(require("fs"));
25342
25194
  init_sdk3();
25343
25195
  init_src();
25344
25196
  uuid4 = require("uuid/v4");
@@ -26461,19 +26313,6 @@ var init_postgres = __esm({
26461
26313
  required: false
26462
26314
  },
26463
26315
  ca: {
26464
- display: "Server CA",
26465
- type: "longForm" /* LONGFORM */,
26466
- default: false,
26467
- required: false
26468
- },
26469
- clientKey: {
26470
- display: "Client key",
26471
- type: "longForm" /* LONGFORM */,
26472
- default: false,
26473
- required: false
26474
- },
26475
- clientCert: {
26476
- display: "Client cert",
26477
26316
  type: "longForm" /* LONGFORM */,
26478
26317
  default: false,
26479
26318
  required: false
@@ -26515,9 +26354,7 @@ var init_postgres = __esm({
26515
26354
  ...this.config,
26516
26355
  ssl: this.config.ssl ? {
26517
26356
  rejectUnauthorized: this.config.rejectUnauthorized,
26518
- ca: this.config.ca,
26519
- key: this.config.clientKey,
26520
- cert: this.config.clientCert
26357
+ ca: this.config.ca
26521
26358
  } : void 0
26522
26359
  };
26523
26360
  this.client = new import_pg.Client(newConfig);
@@ -26660,8 +26497,7 @@ var init_postgres = __esm({
26660
26497
  try {
26661
26498
  await this.openConnection();
26662
26499
  const columnsResponse = await this.client.query(this.COLUMNS_SQL);
26663
- const names = columnsResponse.rows.map((row2) => row2.table_name);
26664
- return [...new Set(names)];
26500
+ return columnsResponse.rows.map((row2) => row2.table_name);
26665
26501
  } finally {
26666
26502
  await this.closeConnection();
26667
26503
  }
@@ -27290,8 +27126,6 @@ var init_mongodb = __esm({
27290
27126
  response2.connected = true;
27291
27127
  } catch (e) {
27292
27128
  response2.error = e.message;
27293
- } finally {
27294
- await this.client.close();
27295
27129
  }
27296
27130
  return response2;
27297
27131
  }
@@ -29223,16 +29057,6 @@ var init_rest = __esm({
29223
29057
  });
29224
29058
 
29225
29059
  // src/integrations/googlesheets.ts
29226
- async function setupCreationAuth(datasouce) {
29227
- if (datasouce.continueSetupId) {
29228
- const appId = context_exports.getAppId();
29229
- const tokens = await cache_exports.get(
29230
- `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
29231
- );
29232
- datasouce.auth = tokens.tokens;
29233
- delete datasouce.continueSetupId;
29234
- }
29235
- }
29236
29060
  var import_google_auth_library, import_google_spreadsheet, import_node_fetch10, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
29237
29061
  var init_googlesheets = __esm({
29238
29062
  "src/integrations/googlesheets.ts"() {
@@ -29270,7 +29094,7 @@ var init_googlesheets = __esm({
29270
29094
  },
29271
29095
  datasource: {
29272
29096
  spreadsheetId: {
29273
- display: "Spreadsheet URL",
29097
+ display: "Google Sheet URL",
29274
29098
  type: "string" /* STRING */,
29275
29099
  required: true
29276
29100
  }
@@ -29391,7 +29215,6 @@ var init_googlesheets = __esm({
29391
29215
  async connect() {
29392
29216
  var _a2;
29393
29217
  try {
29394
- await setupCreationAuth(this.config);
29395
29218
  let googleConfig = await configs_exports.getGoogleDatasourceConfig();
29396
29219
  if (!googleConfig) {
29397
29220
  throw new HTTPError("Google config not found", 400);
@@ -29442,22 +29265,21 @@ var init_googlesheets = __esm({
29442
29265
  return table2;
29443
29266
  }
29444
29267
  async buildSchema(datasourceId, entities) {
29268
+ if (!this.config.auth) {
29269
+ return;
29270
+ }
29445
29271
  await this.connect();
29446
29272
  const sheets = this.client.sheetsByIndex;
29447
29273
  const tables = {};
29448
- await utils_exports5.parallelForeach(
29449
- sheets,
29450
- async (sheet) => {
29451
- await sheet.getRows({ limit: 0, offset: 0 });
29452
- const id = buildExternalTableId(datasourceId, sheet.title);
29453
- tables[sheet.title] = this.getTableSchema(
29454
- sheet.title,
29455
- sheet.headerValues,
29456
- id
29457
- );
29458
- },
29459
- 10
29460
- );
29274
+ for (let sheet of sheets) {
29275
+ await sheet.getRows();
29276
+ const id = buildExternalTableId(datasourceId, sheet.title);
29277
+ tables[sheet.title] = this.getTableSchema(
29278
+ sheet.title,
29279
+ sheet.headerValues,
29280
+ id
29281
+ );
29282
+ }
29461
29283
  const final = finaliseExternalTables(tables, entities);
29462
29284
  this.tables = final.tables;
29463
29285
  this.schemaErrors = final.errors;
@@ -32249,41 +32071,21 @@ var init_automationUtils = __esm({
32249
32071
 
32250
32072
  // src/automations/steps/sendSmtpEmail.ts
32251
32073
  async function run3({ inputs }) {
32252
- let {
32253
- to,
32254
- from,
32255
- subject,
32256
- contents,
32257
- cc,
32258
- bcc,
32259
- addInvite,
32260
- startTime,
32261
- endTime,
32262
- summary,
32263
- location,
32264
- url
32265
- } = inputs;
32074
+ let { to, from, subject, contents, cc, bcc } = inputs;
32266
32075
  if (!contents) {
32267
32076
  contents = "<h1>No content</h1>";
32268
32077
  }
32269
32078
  to = to || void 0;
32270
32079
  try {
32271
- let response2 = await sendSmtpEmail({
32080
+ let response2 = await sendSmtpEmail(
32272
32081
  to,
32273
32082
  from,
32274
32083
  subject,
32275
32084
  contents,
32276
32085
  cc,
32277
32086
  bcc,
32278
- automation: true,
32279
- invite: addInvite ? {
32280
- startTime,
32281
- endTime,
32282
- summary,
32283
- location,
32284
- url
32285
- } : void 0
32286
- });
32087
+ true
32088
+ );
32287
32089
  return {
32288
32090
  success: true,
32289
32091
  response: response2
@@ -32339,35 +32141,6 @@ var init_sendSmtpEmail = __esm({
32339
32141
  contents: {
32340
32142
  type: "string" /* STRING */,
32341
32143
  title: "HTML Contents"
32342
- },
32343
- addInvite: {
32344
- type: "boolean" /* BOOLEAN */,
32345
- title: "Add calendar invite"
32346
- },
32347
- startTime: {
32348
- type: "date" /* DATE */,
32349
- title: "Start Time",
32350
- dependsOn: "addInvite"
32351
- },
32352
- endTime: {
32353
- type: "date" /* DATE */,
32354
- title: "End Time",
32355
- dependsOn: "addInvite"
32356
- },
32357
- summary: {
32358
- type: "string" /* STRING */,
32359
- title: "Meeting Summary",
32360
- dependsOn: "addInvite"
32361
- },
32362
- location: {
32363
- type: "string" /* STRING */,
32364
- title: "Location",
32365
- dependsOn: "addInvite"
32366
- },
32367
- url: {
32368
- type: "string" /* STRING */,
32369
- title: "URL",
32370
- dependsOn: "addInvite"
32371
32144
  }
32372
32145
  },
32373
32146
  required: ["to", "from", "subject", "contents"]
@@ -34878,19 +34651,6 @@ async function buildSchemaHelper(datasource2) {
34878
34651
  }
34879
34652
  return { tables: connector.tables, error: error2 };
34880
34653
  }
34881
- async function buildFilteredSchema(datasource2, filter2) {
34882
- let { tables, error: error2 } = await buildSchemaHelper(datasource2);
34883
- let finalTables = tables;
34884
- if (filter2) {
34885
- finalTables = {};
34886
- for (let key in tables) {
34887
- if (filter2.some((filter3) => filter3.toLowerCase() === key.toLowerCase())) {
34888
- finalTables[key] = tables[key];
34889
- }
34890
- }
34891
- }
34892
- return { tables: finalTables, error: error2 };
34893
- }
34894
34654
  async function fetch22(ctx) {
34895
34655
  const db2 = context_exports.getAppDB();
34896
34656
  const internalTables = await db2.allDocs(
@@ -34945,24 +34705,37 @@ async function information(ctx) {
34945
34705
  }
34946
34706
  const tableNames = await connector.getTableNames();
34947
34707
  ctx.body = {
34948
- tableNames: tableNames.sort()
34708
+ tableNames
34949
34709
  };
34950
34710
  }
34951
34711
  async function buildSchemaFromDb(ctx) {
34952
34712
  const db2 = context_exports.getAppDB();
34953
- const tablesFilter = ctx.request.body.tablesFilter;
34954
34713
  const datasource2 = await sdk_default.datasources.get(ctx.params.datasourceId);
34955
- const { tables, error: error2 } = await buildFilteredSchema(datasource2, tablesFilter);
34956
- datasource2.entities = tables;
34714
+ const tablesFilter = ctx.request.body.tablesFilter;
34715
+ let { tables, error: error2 } = await buildSchemaHelper(datasource2);
34716
+ if (tablesFilter) {
34717
+ if (!datasource2.entities) {
34718
+ datasource2.entities = {};
34719
+ }
34720
+ for (let key in tables) {
34721
+ if (tablesFilter.some(
34722
+ (filter2) => filter2.toLowerCase() === key.toLowerCase()
34723
+ )) {
34724
+ datasource2.entities[key] = tables[key];
34725
+ }
34726
+ }
34727
+ } else {
34728
+ datasource2.entities = tables;
34729
+ }
34957
34730
  setDefaultDisplayColumns(datasource2);
34958
34731
  const dbResp = await db2.put(datasource2);
34959
34732
  datasource2._rev = dbResp.rev;
34960
34733
  const cleanedDatasource = await sdk_default.datasources.removeSecretSingle(datasource2);
34961
- const res = { datasource: cleanedDatasource };
34734
+ const response2 = { datasource: cleanedDatasource };
34962
34735
  if (error2) {
34963
- res.error = error2;
34736
+ response2.error = error2;
34964
34737
  }
34965
- ctx.body = res;
34738
+ ctx.body = response2;
34966
34739
  }
34967
34740
  function setDefaultDisplayColumns(datasource2) {
34968
34741
  for (let entity of Object.values(datasource2.entities || {})) {
@@ -35036,7 +34809,6 @@ async function save13(ctx) {
35036
34809
  const db2 = context_exports.getAppDB();
35037
34810
  const plus = ctx.request.body.datasource.plus;
35038
34811
  const fetchSchema = ctx.request.body.fetchSchema;
35039
- const tablesFilter = ctx.request.body.tablesFilter;
35040
34812
  const datasource2 = {
35041
34813
  _id: generateDatasourceID({ plus }),
35042
34814
  ...ctx.request.body.datasource,
@@ -35044,17 +34816,11 @@ async function save13(ctx) {
35044
34816
  };
35045
34817
  let schemaError = null;
35046
34818
  if (fetchSchema) {
35047
- const { tables, error: error2 } = await buildFilteredSchema(
35048
- datasource2,
35049
- tablesFilter
35050
- );
34819
+ const { tables, error: error2 } = await buildSchemaHelper(datasource2);
35051
34820
  schemaError = error2;
35052
34821
  datasource2.entities = tables;
35053
34822
  setDefaultDisplayColumns(datasource2);
35054
34823
  }
35055
- if (preSaveAction[datasource2.source]) {
35056
- await preSaveAction[datasource2.source](datasource2);
35057
- }
35058
34824
  const dbResp = await db2.put(datasource2);
35059
34825
  await events_exports.datasource.created(datasource2);
35060
34826
  datasource2._rev = dbResp.rev;
@@ -35133,7 +34899,6 @@ async function query(ctx) {
35133
34899
  ctx.throw(400, err);
35134
34900
  }
35135
34901
  }
35136
- var preSaveAction;
35137
34902
  var init_datasource5 = __esm({
35138
34903
  "src/api/controllers/datasource.ts"() {
35139
34904
  init_utils9();
@@ -35143,15 +34908,8 @@ var init_datasource5 = __esm({
35143
34908
  init_utils24();
35144
34909
  init_utils18();
35145
34910
  init_src2();
35146
- init_src();
35147
34911
  init_sdk3();
35148
34912
  init_websockets();
35149
- init_googlesheets();
35150
- preSaveAction = {
35151
- ["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
35152
- await setupCreationAuth(datasource2.config);
35153
- }
35154
- };
35155
34913
  }
35156
34914
  });
35157
34915
 
@@ -37995,8 +37753,6 @@ function process2(updateCb) {
37995
37753
  } catch (err) {
37996
37754
  if ((err == null ? void 0 : err.status) === 404) {
37997
37755
  return;
37998
- } else if ((err == null ? void 0 : err.status) === 409) {
37999
- return;
38000
37756
  } else {
38001
37757
  logging_exports.logAlert("Failed to perform user/group app sync", err);
38002
37758
  }
@@ -41879,23 +41635,17 @@ var init_query6 = __esm({
41879
41635
 
41880
41636
  // src/api/controllers/backup.ts
41881
41637
  async function exportAppDump(ctx) {
41882
- const { appId } = ctx.query;
41883
- const { excludeRows, encryptPassword } = ctx.request.body;
41884
- const [app2] = await db_exports.getAppsByIDs([appId]);
41885
- const appName = app2.name;
41638
+ let { appId, excludeRows } = ctx.query;
41886
41639
  ctx.req.setTimeout(0);
41887
- const extension = encryptPassword ? "enc.tar.gz" : "tar.gz";
41888
- const backupIdentifier = `${appName}-export-${(/* @__PURE__ */ new Date()).getTime()}.${extension}`;
41640
+ const appName = decodeURI(ctx.query.appname);
41641
+ excludeRows = isQsTrue(excludeRows);
41642
+ const backupIdentifier = `${appName}-export-${(/* @__PURE__ */ new Date()).getTime()}.tar.gz`;
41889
41643
  ctx.attachment(backupIdentifier);
41890
- ctx.body = await sdk_default.backups.streamExportApp({
41891
- appId,
41892
- excludeRows,
41893
- encryptPassword
41894
- });
41644
+ ctx.body = await sdk_default.backups.streamExportApp(appId, excludeRows);
41895
41645
  await context_exports.doInAppContext(appId, async () => {
41896
41646
  const appDb = context_exports.getAppDB();
41897
- const app3 = await appDb.get(DocumentType2.APP_METADATA);
41898
- await events_exports.app.exported(app3);
41647
+ const app2 = await appDb.get(DocumentType2.APP_METADATA);
41648
+ await events_exports.app.exported(app2);
41899
41649
  });
41900
41650
  }
41901
41651
  var init_backup6 = __esm({
@@ -41903,6 +41653,7 @@ var init_backup6 = __esm({
41903
41653
  init_sdk3();
41904
41654
  init_src2();
41905
41655
  init_utils9();
41656
+ init_utilities2();
41906
41657
  }
41907
41658
  });
41908
41659
 
@@ -41915,7 +41666,7 @@ var init_backup7 = __esm({
41915
41666
  init_authorized();
41916
41667
  init_src2();
41917
41668
  router28 = new import_router28.default();
41918
- router28.post(
41669
+ router28.get(
41919
41670
  "/api/backups/export",
41920
41671
  authorized_default(permissions_exports.BUILDER),
41921
41672
  exportAppDump
@@ -43347,18 +43098,18 @@ async function npmUpload(url, name2, headers = {}) {
43347
43098
  }
43348
43099
  try {
43349
43100
  await extractTarball(tarballPluginFile, path5);
43350
- deleteFolderFileSystem((0, import_path15.join)(path5, "package"));
43101
+ deleteFolderFileSystem((0, import_path14.join)(path5, "package"));
43351
43102
  } catch (err) {
43352
43103
  throw new Error(err);
43353
43104
  }
43354
43105
  return await getPluginMetadata(path5);
43355
43106
  }
43356
- var import_node_fetch20, import_path15;
43107
+ var import_node_fetch20, import_path14;
43357
43108
  var init_npm = __esm({
43358
43109
  "src/api/controllers/plugin/npm.ts"() {
43359
43110
  init_fileSystem();
43360
43111
  import_node_fetch20 = __toESM(require("node-fetch"));
43361
- import_path15 = require("path");
43112
+ import_path14 = require("path");
43362
43113
  init_utils28();
43363
43114
  }
43364
43115
  });
@@ -43566,7 +43317,7 @@ async function prepareUpload({ s3Key, bucket, metadata: metadata2, file }) {
43566
43317
  key: response2.Key
43567
43318
  };
43568
43319
  }
43569
- var import_string_templates10, import_aws_sdk4, import_fs16, uuid5, send2, toggleBetaUiFeature, serveBuilder, uploadFile, deleteObjects, serveApp, serveBuilderPreview, serveClientLibrary, getSignedUploadURL;
43320
+ var import_string_templates10, import_aws_sdk4, import_fs15, uuid5, send2, toggleBetaUiFeature, serveBuilder, uploadFile, deleteObjects, serveApp, serveBuilderPreview, serveClientLibrary, getSignedUploadURL;
43570
43321
  var init_static = __esm({
43571
43322
  "src/api/controllers/static/index.ts"() {
43572
43323
  init_centralPath();
@@ -43577,7 +43328,7 @@ var init_static = __esm({
43577
43328
  init_utils9();
43578
43329
  init_src2();
43579
43330
  import_aws_sdk4 = __toESM(require("aws-sdk"));
43580
- import_fs16 = __toESM(require("fs"));
43331
+ import_fs15 = __toESM(require("fs"));
43581
43332
  init_sdk3();
43582
43333
  init_src4();
43583
43334
  require("svelte/register");
@@ -43592,9 +43343,9 @@ var init_static = __esm({
43592
43343
  };
43593
43344
  return;
43594
43345
  }
43595
- let builderPath = join4(TOP_LEVEL_PATH, "new_design_ui");
43596
- if (!import_fs16.default.existsSync(builderPath)) {
43597
- import_fs16.default.mkdirSync(builderPath);
43346
+ let builderPath = join3(TOP_LEVEL_PATH, "new_design_ui");
43347
+ if (!import_fs15.default.existsSync(builderPath)) {
43348
+ import_fs15.default.mkdirSync(builderPath);
43598
43349
  }
43599
43350
  await objectStore_exports2.downloadTarballDirect(
43600
43351
  "https://cdn.budi.live/beta:design_ui/new_ui.tar.gz",
@@ -43606,7 +43357,7 @@ var init_static = __esm({
43606
43357
  };
43607
43358
  };
43608
43359
  serveBuilder = async function(ctx) {
43609
- const builderPath = join4(TOP_LEVEL_PATH, "builder");
43360
+ const builderPath = join3(TOP_LEVEL_PATH, "builder");
43610
43361
  await send2(ctx, ctx.file, { root: builderPath });
43611
43362
  };
43612
43363
  uploadFile = async function(ctx) {
@@ -43695,7 +43446,7 @@ var init_static = __esm({
43695
43446
  };
43696
43447
  serveClientLibrary = async function(ctx) {
43697
43448
  return send2(ctx, "budibase-client.js", {
43698
- root: join4(NODE_MODULES_PATH, "@budibase", "client", "dist")
43449
+ root: join3(NODE_MODULES_PATH, "@budibase", "client", "dist")
43699
43450
  });
43700
43451
  };
43701
43452
  getSignedUploadURL = async function(ctx) {
@@ -45015,13 +44766,13 @@ var init_routes = __esm({
45015
44766
  });
45016
44767
 
45017
44768
  // src/api/index.ts
45018
- var import_router35, import_zlib3, compress, router35;
44769
+ var import_router35, import_zlib2, compress, router35;
45019
44770
  var init_api8 = __esm({
45020
44771
  "src/api/index.ts"() {
45021
44772
  import_router35 = __toESM(require("@koa/router"));
45022
44773
  init_src2();
45023
44774
  init_currentapp();
45024
- import_zlib3 = __toESM(require("zlib"));
44775
+ import_zlib2 = __toESM(require("zlib"));
45025
44776
  init_routes();
45026
44777
  init_src4();
45027
44778
  init_public();
@@ -45034,10 +44785,10 @@ var init_api8 = __esm({
45034
44785
  compress({
45035
44786
  threshold: 2048,
45036
44787
  gzip: {
45037
- flush: import_zlib3.default.constants.Z_SYNC_FLUSH
44788
+ flush: import_zlib2.default.constants.Z_SYNC_FLUSH
45038
44789
  },
45039
44790
  deflate: {
45040
- flush: import_zlib3.default.constants.Z_SYNC_FLUSH
44791
+ flush: import_zlib2.default.constants.Z_SYNC_FLUSH
45041
44792
  },
45042
44793
  br: false
45043
44794
  })
@@ -45083,7 +44834,7 @@ var init_automations8 = __esm({
45083
44834
 
45084
44835
  // src/watch.ts
45085
44836
  function watch() {
45086
- const watchPath = import_path16.default.join(environment_default2.PLUGINS_DIR, "./**/*.tar.gz");
44837
+ const watchPath = import_path15.default.join(environment_default2.PLUGINS_DIR, "./**/*.tar.gz");
45087
44838
  import_chokidar.default.watch(watchPath, {
45088
44839
  ignored: "**/node_modules",
45089
44840
  awaitWriteFinish: {
@@ -45093,7 +44844,7 @@ function watch() {
45093
44844
  usePolling: true,
45094
44845
  interval: 250
45095
44846
  }).on("all", async (event, path5) => {
45096
- if (!(path5 == null ? void 0 : path5.endsWith(".tar.gz")) || !import_fs17.default.existsSync(path5)) {
44847
+ if (!(path5 == null ? void 0 : path5.endsWith(".tar.gz")) || !import_fs16.default.existsSync(path5)) {
45097
44848
  return;
45098
44849
  }
45099
44850
  await tenancy.doInTenant(constants_exports.DEFAULT_TENANT_ID, async () => {
@@ -45109,13 +44860,13 @@ function watch() {
45109
44860
  });
45110
44861
  });
45111
44862
  }
45112
- var import_path16, import_chokidar, import_fs17;
44863
+ var import_path15, import_chokidar, import_fs16;
45113
44864
  var init_watch = __esm({
45114
44865
  "src/watch.ts"() {
45115
- import_path16 = __toESM(require("path"));
44866
+ import_path15 = __toESM(require("path"));
45116
44867
  init_environment3();
45117
44868
  import_chokidar = __toESM(require("chokidar"));
45118
- import_fs17 = __toESM(require("fs"));
44869
+ import_fs16 = __toESM(require("fs"));
45119
44870
  init_src2();
45120
44871
  init_plugins5();
45121
44872
  }
@@ -45171,7 +44922,7 @@ async function startup(app2, server2) {
45171
44922
  shutdown9(server2);
45172
44923
  }
45173
44924
  }
45174
- if (environment_default2.SELF_HOSTED && !environment_default2.MULTI_TENANCY && environment_default2.PLUGINS_DIR && import_fs18.default.existsSync(environment_default2.PLUGINS_DIR)) {
44925
+ if (environment_default2.SELF_HOSTED && !environment_default2.MULTI_TENANCY && environment_default2.PLUGINS_DIR && import_fs17.default.existsSync(environment_default2.PLUGINS_DIR)) {
45175
44926
  watch();
45176
44927
  }
45177
44928
  await installation_exports.checkInstallVersion();
@@ -45206,14 +44957,14 @@ async function startup(app2, server2) {
45206
44957
  }
45207
44958
  }
45208
44959
  }
45209
- var import_fs18, STARTUP_RAN;
44960
+ var import_fs17, STARTUP_RAN;
45210
44961
  var init_startup = __esm({
45211
44962
  "src/startup.ts"() {
45212
44963
  init_environment3();
45213
44964
  init_redis4();
45214
44965
  init_workerRequests();
45215
44966
  init_src2();
45216
- import_fs18 = __toESM(require("fs"));
44967
+ import_fs17 = __toESM(require("fs"));
45217
44968
  init_watch();
45218
44969
  init_automations8();
45219
44970
  init_fileSystem();