@budibase/server 2.7.23 → 2.7.25-alpha.0

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