@budibase/server 2.7.15 → 2.7.16-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(doc, lastWrite = null) {
5400
5401
  return { doc, lastWrite: lastWrite || Date.now() };
5401
5402
  }
5402
5403
  async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5403
- const cache2 = await getCache();
5404
+ const cache3 = await getCache();
5404
5405
  const key = doc._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 = doc;
@@ -5442,30 +5443,30 @@ async function put(db2, doc, 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 doc = await db2.get(id);
5455
5456
  cacheItem = makeCacheItem(doc);
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, rev) {
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
  rev = typeof docOrId === "string" ? rev : 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, rev);
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
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, bucketPath) => {
11424
11507
  bucketName = sanitizeBucket(bucketName);
11425
11508
  let uploads = [];
11426
- const files = import_fs3.default.readdirSync(localPath, { withFileTypes: true });
11509
+ const files = import_fs4.default.readdirSync(localPath, { withFileTypes: true });
11427
11510
  for (let file of files) {
11428
- const path5 = sanitizeKey((0, import_path2.join)(bucketPath, file.name));
11429
- const local = (0, import_path2.join)(localPath, file.name);
11511
+ const path5 = sanitizeKey((0, import_path3.join)(bucketPath, 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 files = import_fs4.default.readdirSync(startPath);
12314
+ const files = import_fs5.default.readdirSync(startPath);
12232
12315
  for (let i = 0, len = files.length; i < len; i++) {
12233
- const filename = (0, import_path5.join)(startPath, files[i]);
12234
- const stat = import_fs4.default.lstatSync(filename);
12316
+ const filename = (0, import_path6.join)(startPath, files[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 hash2 = (_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 === hash2) {
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, hash2);
12525
+ import_fs8.default.writeFileSync(filename, pluginJs);
12526
+ import_fs8.default.writeFileSync(metadataName, hash2);
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 metadata = {};
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
  metadata.schema = JSON.parse(schema);
12461
12544
  metadata.package = JSON.parse(pkg2);
12462
12545
  if (!metadata.package.name || !metadata.package.version || !metadata.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(directory, name) {
15668
- return import_fs10.default.readFileSync((0, import_path11.join)(directory, name), "utf8");
15751
+ return import_fs11.default.readFileSync((0, import_path12.join)(directory, name), "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
 
@@ -18639,8 +18722,8 @@ async function runBackup(trigger3, tenantId, appId, opts) {
18639
18722
  }
18640
18723
  });
18641
18724
  await updateMetadata2("complete" /* COMPLETE */, { filename, contents });
18642
- if (import_fs11.default.existsSync(tarPath)) {
18643
- import_fs11.default.rmSync(tarPath);
18725
+ if (import_fs12.default.existsSync(tarPath)) {
18726
+ import_fs12.default.rmSync(tarPath);
18644
18727
  }
18645
18728
  } catch (err) {
18646
18729
  logging_exports.logAlert("App backup error", err);
@@ -18698,14 +18781,14 @@ async function exportProcessor(job, opts) {
18698
18781
  });
18699
18782
  });
18700
18783
  }
18701
- var import_fs11;
18784
+ var import_fs12;
18702
18785
  var init_processing = __esm({
18703
18786
  "../pro/packages/pro/src/sdk/backups/processing.ts"() {
18704
18787
  init_src2();
18705
18788
  init_backup5();
18706
18789
  init_src();
18707
18790
  init_queue4();
18708
- import_fs11 = __toESM(require("fs"));
18791
+ import_fs12 = __toESM(require("fs"));
18709
18792
  }
18710
18793
  });
18711
18794
 
@@ -19388,15 +19471,15 @@ async function downloadBackup(ctx) {
19388
19471
  const backupId = ctx.params.backupId;
19389
19472
  const { metadata, path: path5 } = await backups_default.downloadAppBackup(backupId);
19390
19473
  ctx.attachment(`backup-${metadata.timestamp}.tar.gz`);
19391
- ctx.body = import_fs12.default.createReadStream(path5);
19474
+ ctx.body = import_fs13.default.createReadStream(path5);
19392
19475
  }
19393
- var import_fs12;
19476
+ var import_fs13;
19394
19477
  var init_backups3 = __esm({
19395
19478
  "../pro/packages/pro/src/api/controllers/apps/backups.ts"() {
19396
19479
  init_src();
19397
19480
  init_sdk2();
19398
19481
  init_src2();
19399
- import_fs12 = __toESM(require("fs"));
19482
+ import_fs13 = __toESM(require("fs"));
19400
19483
  }
19401
19484
  });
19402
19485
 
@@ -20035,11 +20118,39 @@ var init_filters = __esm({
20035
20118
  // ../shared-core/src/utils.ts
20036
20119
  var utils_exports5 = {};
20037
20120
  __export(utils_exports5, {
20121
+ parallelForeach: () => parallelForeach,
20038
20122
  unreachable: () => unreachable
20039
20123
  });
20040
20124
  function unreachable(value, message = `No such case in exhaustive switch: ${value}`) {
20041
20125
  throw new Error(message);
20042
20126
  }
20127
+ async function parallelForeach(items, task, maxConcurrency) {
20128
+ const promises = [];
20129
+ let index2 = 0;
20130
+ const processItem = async (item) => {
20131
+ try {
20132
+ await task(item);
20133
+ } finally {
20134
+ processNext();
20135
+ }
20136
+ };
20137
+ const processNext = () => {
20138
+ if (index2 >= items.length) {
20139
+ return;
20140
+ }
20141
+ const item = items[index2];
20142
+ index2++;
20143
+ const promise = processItem(item);
20144
+ promises.push(promise);
20145
+ if (promises.length >= maxConcurrency) {
20146
+ Promise.race(promises).then(processNext);
20147
+ } else {
20148
+ processNext();
20149
+ }
20150
+ };
20151
+ processNext();
20152
+ await Promise.all(promises);
20153
+ }
20043
20154
  var init_utils13 = __esm({
20044
20155
  "../shared-core/src/utils.ts"() {
20045
20156
  }
@@ -20633,7 +20744,7 @@ var init_currentapp = __esm({
20633
20744
  userId,
20634
20745
  globalId,
20635
20746
  roleId,
20636
- role: await roles_exports.getRole(roleId)
20747
+ role: await roles_exports.getRole(roleId, { defaultPublic: true })
20637
20748
  };
20638
20749
  }
20639
20750
  return next();
@@ -24284,13 +24395,6 @@ function convertBookmark(bookmark) {
24284
24395
  }
24285
24396
  return bookmark;
24286
24397
  }
24287
- function isQsTrue(param) {
24288
- if (typeof param === "string") {
24289
- return param.toLowerCase() === "true";
24290
- } else {
24291
- return param === true;
24292
- }
24293
- }
24294
24398
  var import_stream2, Readable, isDev3, NUMBER_REGEX;
24295
24399
  var init_utilities2 = __esm({
24296
24400
  "src/utilities/index.ts"() {
@@ -24344,7 +24448,16 @@ async function checkResponse(response2, errorMsg, { ctx } = {}) {
24344
24448
  }
24345
24449
  return response2.json();
24346
24450
  }
24347
- async function sendSmtpEmail(to, from, subject, contents, cc, bcc, automation) {
24451
+ async function sendSmtpEmail({
24452
+ to,
24453
+ from,
24454
+ subject,
24455
+ contents,
24456
+ cc,
24457
+ bcc,
24458
+ automation,
24459
+ invite
24460
+ }) {
24348
24461
  const response2 = await (0, import_node_fetch8.default)(
24349
24462
  checkSlashesInUrl2(environment_default2.WORKER_URL + `/api/global/email/send`),
24350
24463
  request(void 0, {
@@ -24357,7 +24470,8 @@ async function sendSmtpEmail(to, from, subject, contents, cc, bcc, automation) {
24357
24470
  cc,
24358
24471
  bcc,
24359
24472
  purpose: "custom",
24360
- automation
24473
+ automation,
24474
+ invite
24361
24475
  }
24362
24476
  })
24363
24477
  );
@@ -24850,22 +24964,22 @@ function threadSetup() {
24850
24964
  init10();
24851
24965
  }
24852
24966
  async function checkCacheForDynamicVariable(queryId, variable) {
24853
- const cache2 = await getClient3();
24854
- return cache2.get(makeVariableKey(queryId, variable));
24967
+ const cache3 = await getClient3();
24968
+ return cache3.get(makeVariableKey(queryId, variable));
24855
24969
  }
24856
24970
  async function invalidateDynamicVariables(cachedVars) {
24857
- const cache2 = await getClient3();
24971
+ const cache3 = await getClient3();
24858
24972
  let promises = [];
24859
24973
  for (let variable of cachedVars) {
24860
24974
  promises.push(
24861
- cache2.delete(makeVariableKey(variable.queryId, variable.name))
24975
+ cache3.delete(makeVariableKey(variable.queryId, variable.name))
24862
24976
  );
24863
24977
  }
24864
24978
  await Promise.all(promises);
24865
24979
  }
24866
24980
  async function storeDynamicVariable(queryId, variable, value) {
24867
- const cache2 = await getClient3();
24868
- await cache2.store(
24981
+ const cache3 = await getClient3();
24982
+ await cache3.store(
24869
24983
  makeVariableKey(queryId, variable),
24870
24984
  value,
24871
24985
  VARIABLE_TTL_SECONDS
@@ -24925,13 +25039,14 @@ __export(exports_exports, {
24925
25039
  streamExportApp: () => streamExportApp
24926
25040
  });
24927
25041
  function tarFilesToTmp(tmpDir, files) {
24928
- const exportFile = (0, import_path12.join)(budibaseTempDir2(), `${uuid3()}.tar.gz`);
24929
- tar3.create(
25042
+ const fileName = `${uuid3()}.tar.gz`;
25043
+ const exportFile = (0, import_path13.join)(budibaseTempDir2(), fileName);
25044
+ import_tar2.default.create(
24930
25045
  {
24931
25046
  sync: true,
24932
25047
  gzip: true,
24933
25048
  file: exportFile,
24934
- recursive: true,
25049
+ noDirRecurse: false,
24935
25050
  cwd: tmpDir
24936
25051
  },
24937
25052
  files
@@ -24948,7 +25063,7 @@ async function exportDB(dbName, opts = {}) {
24948
25063
  return db_exports.doWithDB(dbName, async (db2) => {
24949
25064
  if (opts == null ? void 0 : opts.exportPath) {
24950
25065
  const path5 = opts == null ? void 0 : opts.exportPath;
24951
- const writeStream = import_fs13.default.createWriteStream(path5);
25066
+ const writeStream = import_fs14.default.createWriteStream(path5);
24952
25067
  await db2.dump(writeStream, exportOpts);
24953
25068
  return path5;
24954
25069
  } else {
@@ -24981,9 +25096,9 @@ async function exportApp(appId, config) {
24981
25096
  for (let path5 of STATIC_APP_FILES) {
24982
25097
  const contents = await objectStore_exports2.retrieve(
24983
25098
  ObjectStoreBuckets2.APPS,
24984
- (0, import_path12.join)(appPath, path5)
25099
+ (0, import_path13.join)(appPath, path5)
24985
25100
  );
24986
- import_fs13.default.writeFileSync((0, import_path12.join)(tmpPath, path5), contents);
25101
+ import_fs14.default.writeFileSync((0, import_path13.join)(tmpPath, path5), contents);
24987
25102
  }
24988
25103
  } else {
24989
25104
  tmpPath = await objectStore_exports2.retrieveDirectory(
@@ -24992,37 +25107,52 @@ async function exportApp(appId, config) {
24992
25107
  );
24993
25108
  }
24994
25109
  }
24995
- const downloadedPath = (0, import_path12.join)(tmpPath, appPath);
24996
- if (import_fs13.default.existsSync(downloadedPath)) {
24997
- const allFiles = import_fs13.default.readdirSync(downloadedPath);
25110
+ const downloadedPath = (0, import_path13.join)(tmpPath, appPath);
25111
+ if (import_fs14.default.existsSync(downloadedPath)) {
25112
+ const allFiles = import_fs14.default.readdirSync(downloadedPath);
24998
25113
  for (let file of allFiles) {
24999
- const path5 = (0, import_path12.join)(downloadedPath, file);
25000
- import_fs13.default.renameSync(path5, (0, import_path12.join)(downloadedPath, "..", file));
25114
+ const path5 = (0, import_path13.join)(downloadedPath, file);
25115
+ import_fs14.default.renameSync(path5, (0, import_path13.join)(downloadedPath, "..", file));
25001
25116
  }
25002
- import_fs13.default.rmdirSync(downloadedPath);
25117
+ import_fs14.default.rmdirSync(downloadedPath);
25003
25118
  }
25004
- const dbPath = (0, import_path12.join)(tmpPath, DB_EXPORT_FILE);
25119
+ const dbPath = (0, import_path13.join)(tmpPath, DB_EXPORT_FILE);
25005
25120
  await exportDB(appId, {
25006
25121
  filter: defineFilter(config == null ? void 0 : config.excludeRows, config == null ? void 0 : config.excludeLogs),
25007
25122
  exportPath: dbPath
25008
25123
  });
25124
+ if (config == null ? void 0 : config.encryptPassword) {
25125
+ for (let file of import_fs14.default.readdirSync(tmpPath)) {
25126
+ const path5 = (0, import_path13.join)(tmpPath, file);
25127
+ await encryption_exports.encryptFile(
25128
+ { dir: tmpPath, filename: file },
25129
+ config.encryptPassword
25130
+ );
25131
+ import_fs14.default.rmSync(path5);
25132
+ }
25133
+ }
25009
25134
  if (config == null ? void 0 : config.tar) {
25010
- const tarPath = tarFilesToTmp(tmpPath, import_fs13.default.readdirSync(tmpPath));
25011
- import_fs13.default.rmSync(tmpPath, { recursive: true, force: true });
25135
+ const tarPath = tarFilesToTmp(tmpPath, import_fs14.default.readdirSync(tmpPath));
25136
+ import_fs14.default.rmSync(tmpPath, { recursive: true, force: true });
25012
25137
  return tarPath;
25013
25138
  } else {
25014
25139
  return tmpPath;
25015
25140
  }
25016
25141
  }
25017
- async function streamExportApp(appId, excludeRows) {
25142
+ async function streamExportApp({
25143
+ appId,
25144
+ excludeRows,
25145
+ encryptPassword
25146
+ }) {
25018
25147
  const tmpPath = await exportApp(appId, {
25019
25148
  excludeRows,
25020
25149
  excludeLogs: true,
25021
- tar: true
25150
+ tar: true,
25151
+ encryptPassword
25022
25152
  });
25023
25153
  return streamFile(tmpPath);
25024
25154
  }
25025
- var import_fs13, import_path12, uuid3, tar3, MemoryStream2;
25155
+ var import_fs14, import_path13, import_tar2, uuid3, MemoryStream2;
25026
25156
  var init_exports2 = __esm({
25027
25157
  "src/sdk/app/backups/exports.ts"() {
25028
25158
  init_src2();
@@ -25031,11 +25161,11 @@ var init_exports2 = __esm({
25031
25161
  init_constants4();
25032
25162
  init_utils9();
25033
25163
  init_constants7();
25034
- import_fs13 = __toESM(require("fs"));
25035
- import_path12 = require("path");
25164
+ import_fs14 = __toESM(require("fs"));
25165
+ import_path13 = require("path");
25036
25166
  init_environment3();
25167
+ import_tar2 = __toESM(require("tar"));
25037
25168
  uuid3 = require("uuid/v4");
25038
- tar3 = require("tar");
25039
25169
  MemoryStream2 = require("memorystream");
25040
25170
  }
25041
25171
  });
@@ -25112,16 +25242,16 @@ async function getTemplateStream(template) {
25112
25242
  throw new Error("Cannot import a non-text based file.");
25113
25243
  }
25114
25244
  if (template.file) {
25115
- return import_fs14.default.createReadStream(template.file.path);
25245
+ return import_fs15.default.createReadStream(template.file.path);
25116
25246
  } else if (template.key) {
25117
25247
  const [type, name] = template.key.split("/");
25118
25248
  const tmpPath = await downloadTemplate(type, name);
25119
- return import_fs14.default.createReadStream((0, import_path13.join)(tmpPath, name, "db", "dump.txt"));
25249
+ return import_fs15.default.createReadStream((0, import_path14.join)(tmpPath, name, "db", "dump.txt"));
25120
25250
  }
25121
25251
  }
25122
25252
  function untarFile(file) {
25123
- const tmpPath = (0, import_path13.join)(budibaseTempDir2(), uuid4());
25124
- import_fs14.default.mkdirSync(tmpPath);
25253
+ const tmpPath = (0, import_path14.join)(budibaseTempDir2(), uuid4());
25254
+ import_fs15.default.mkdirSync(tmpPath);
25125
25255
  tar4.extract({
25126
25256
  sync: true,
25127
25257
  cwd: tmpPath,
@@ -25129,31 +25259,49 @@ function untarFile(file) {
25129
25259
  });
25130
25260
  return tmpPath;
25131
25261
  }
25262
+ async function decryptFiles(path5, password) {
25263
+ try {
25264
+ for (let file of import_fs15.default.readdirSync(path5)) {
25265
+ const inputPath = (0, import_path14.join)(path5, file);
25266
+ const outputPath = inputPath.replace(/\.enc$/, "");
25267
+ await encryption_exports.decryptFile(inputPath, outputPath, password);
25268
+ import_fs15.default.rmSync(inputPath);
25269
+ }
25270
+ } catch (err) {
25271
+ if (err.message === "incorrect header check") {
25272
+ throw new Error("File cannot be imported");
25273
+ }
25274
+ throw err;
25275
+ }
25276
+ }
25132
25277
  function getGlobalDBFile(tmpPath) {
25133
- return import_fs14.default.readFileSync((0, import_path13.join)(tmpPath, GLOBAL_DB_EXPORT_FILE), "utf8");
25278
+ return import_fs15.default.readFileSync((0, import_path14.join)(tmpPath, GLOBAL_DB_EXPORT_FILE), "utf8");
25134
25279
  }
25135
25280
  function getListOfAppsInMulti(tmpPath) {
25136
- return import_fs14.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
25281
+ return import_fs15.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
25137
25282
  }
25138
25283
  async function importApp(appId, db2, template) {
25139
25284
  var _a2, _b2;
25140
25285
  let prodAppId = db_exports.getProdAppID(appId);
25141
25286
  let dbStream;
25142
25287
  const isTar = template.file && ((_b2 = (_a2 = template == null ? void 0 : template.file) == null ? void 0 : _a2.type) == null ? void 0 : _b2.endsWith("gzip"));
25143
- const isDirectory = template.file && import_fs14.default.lstatSync(template.file.path).isDirectory();
25288
+ const isDirectory = template.file && import_fs15.default.lstatSync(template.file.path).isDirectory();
25144
25289
  if (template.file && (isTar || isDirectory)) {
25145
25290
  const tmpPath = isTar ? untarFile(template.file) : template.file.path;
25146
- const contents = import_fs14.default.readdirSync(tmpPath);
25291
+ if (isTar && template.file.password) {
25292
+ await decryptFiles(tmpPath, template.file.password);
25293
+ }
25294
+ const contents = import_fs15.default.readdirSync(tmpPath);
25147
25295
  if (contents.length) {
25148
25296
  let promises = [];
25149
25297
  let excludedFiles = [GLOBAL_DB_EXPORT_FILE, DB_EXPORT_FILE];
25150
25298
  for (let filename of contents) {
25151
- const path5 = (0, import_path13.join)(tmpPath, filename);
25299
+ const path5 = (0, import_path14.join)(tmpPath, filename);
25152
25300
  if (excludedFiles.includes(filename)) {
25153
25301
  continue;
25154
25302
  }
25155
- filename = (0, import_path13.join)(prodAppId, filename);
25156
- if (import_fs14.default.lstatSync(path5).isDirectory()) {
25303
+ filename = (0, import_path14.join)(prodAppId, filename);
25304
+ if (import_fs15.default.lstatSync(path5).isDirectory()) {
25157
25305
  promises.push(
25158
25306
  objectStore_exports2.uploadDirectory(ObjectStoreBuckets2.APPS, path5, filename)
25159
25307
  );
@@ -25169,7 +25317,7 @@ async function importApp(appId, db2, template) {
25169
25317
  }
25170
25318
  await Promise.all(promises);
25171
25319
  }
25172
- dbStream = import_fs14.default.createReadStream((0, import_path13.join)(tmpPath, DB_EXPORT_FILE));
25320
+ dbStream = import_fs15.default.createReadStream((0, import_path14.join)(tmpPath, DB_EXPORT_FILE));
25173
25321
  } else {
25174
25322
  dbStream = await getTemplateStream(template);
25175
25323
  }
@@ -25181,7 +25329,7 @@ async function importApp(appId, db2, template) {
25181
25329
  await updateAutomations(prodAppId, db2);
25182
25330
  return ok;
25183
25331
  }
25184
- var import_path13, import_fs14, uuid4, tar4;
25332
+ var import_path14, import_fs15, uuid4, tar4;
25185
25333
  var init_imports = __esm({
25186
25334
  "src/sdk/app/backups/imports.ts"() {
25187
25335
  init_src2();
@@ -25190,8 +25338,8 @@ var init_imports = __esm({
25190
25338
  init_constants7();
25191
25339
  init_fileSystem();
25192
25340
  init_constants4();
25193
- import_path13 = require("path");
25194
- import_fs14 = __toESM(require("fs"));
25341
+ import_path14 = require("path");
25342
+ import_fs15 = __toESM(require("fs"));
25195
25343
  init_sdk3();
25196
25344
  init_src();
25197
25345
  uuid4 = require("uuid/v4");
@@ -26486,7 +26634,8 @@ var init_postgres = __esm({
26486
26634
  try {
26487
26635
  await this.openConnection();
26488
26636
  const columnsResponse = await this.client.query(this.COLUMNS_SQL);
26489
- return columnsResponse.rows.map((row2) => row2.table_name);
26637
+ const names = columnsResponse.rows.map((row2) => row2.table_name);
26638
+ return [...new Set(names)];
26490
26639
  } finally {
26491
26640
  await this.closeConnection();
26492
26641
  }
@@ -27115,6 +27264,8 @@ var init_mongodb = __esm({
27115
27264
  response2.connected = true;
27116
27265
  } catch (e) {
27117
27266
  response2.error = e.message;
27267
+ } finally {
27268
+ await this.client.close();
27118
27269
  }
27119
27270
  return response2;
27120
27271
  }
@@ -29041,6 +29192,16 @@ var init_rest = __esm({
29041
29192
  });
29042
29193
 
29043
29194
  // src/integrations/googlesheets.ts
29195
+ async function setupCreationAuth(datasouce) {
29196
+ if (datasouce.continueSetupId) {
29197
+ const appId = context_exports.getAppId();
29198
+ const tokens = await cache_exports.get(
29199
+ `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
29200
+ );
29201
+ datasouce.auth = tokens.tokens;
29202
+ delete datasouce.continueSetupId;
29203
+ }
29204
+ }
29044
29205
  var import_google_auth_library, import_google_spreadsheet, import_node_fetch10, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
29045
29206
  var init_googlesheets = __esm({
29046
29207
  "src/integrations/googlesheets.ts"() {
@@ -29078,7 +29239,7 @@ var init_googlesheets = __esm({
29078
29239
  },
29079
29240
  datasource: {
29080
29241
  spreadsheetId: {
29081
- display: "Google Sheet URL",
29242
+ display: "Spreadsheet URL",
29082
29243
  type: "string" /* STRING */,
29083
29244
  required: true
29084
29245
  }
@@ -29199,6 +29360,7 @@ var init_googlesheets = __esm({
29199
29360
  async connect() {
29200
29361
  var _a2;
29201
29362
  try {
29363
+ await setupCreationAuth(this.config);
29202
29364
  let googleConfig = await configs_exports.getGoogleDatasourceConfig();
29203
29365
  if (!googleConfig) {
29204
29366
  throw new HTTPError("Google config not found", 400);
@@ -29249,21 +29411,22 @@ var init_googlesheets = __esm({
29249
29411
  return table2;
29250
29412
  }
29251
29413
  async buildSchema(datasourceId, entities) {
29252
- if (!this.config.auth) {
29253
- return;
29254
- }
29255
29414
  await this.connect();
29256
29415
  const sheets = this.client.sheetsByIndex;
29257
29416
  const tables = {};
29258
- for (let sheet of sheets) {
29259
- await sheet.getRows();
29260
- const id = buildExternalTableId(datasourceId, sheet.title);
29261
- tables[sheet.title] = this.getTableSchema(
29262
- sheet.title,
29263
- sheet.headerValues,
29264
- id
29265
- );
29266
- }
29417
+ await utils_exports5.parallelForeach(
29418
+ sheets,
29419
+ async (sheet) => {
29420
+ await sheet.getRows({ limit: 0, offset: 0 });
29421
+ const id = buildExternalTableId(datasourceId, sheet.title);
29422
+ tables[sheet.title] = this.getTableSchema(
29423
+ sheet.title,
29424
+ sheet.headerValues,
29425
+ id
29426
+ );
29427
+ },
29428
+ 10
29429
+ );
29267
29430
  const final = finaliseExternalTables(tables, entities);
29268
29431
  this.tables = final.tables;
29269
29432
  this.schemaErrors = final.errors;
@@ -32055,21 +32218,41 @@ var init_automationUtils = __esm({
32055
32218
 
32056
32219
  // src/automations/steps/sendSmtpEmail.ts
32057
32220
  async function run3({ inputs }) {
32058
- let { to, from, subject, contents, cc, bcc } = inputs;
32221
+ let {
32222
+ to,
32223
+ from,
32224
+ subject,
32225
+ contents,
32226
+ cc,
32227
+ bcc,
32228
+ addInvite,
32229
+ startTime,
32230
+ endTime,
32231
+ summary,
32232
+ location,
32233
+ url
32234
+ } = inputs;
32059
32235
  if (!contents) {
32060
32236
  contents = "<h1>No content</h1>";
32061
32237
  }
32062
32238
  to = to || void 0;
32063
32239
  try {
32064
- let response2 = await sendSmtpEmail(
32240
+ let response2 = await sendSmtpEmail({
32065
32241
  to,
32066
32242
  from,
32067
32243
  subject,
32068
32244
  contents,
32069
32245
  cc,
32070
32246
  bcc,
32071
- true
32072
- );
32247
+ automation: true,
32248
+ invite: addInvite ? {
32249
+ startTime,
32250
+ endTime,
32251
+ summary,
32252
+ location,
32253
+ url
32254
+ } : void 0
32255
+ });
32073
32256
  return {
32074
32257
  success: true,
32075
32258
  response: response2
@@ -32125,6 +32308,35 @@ var init_sendSmtpEmail = __esm({
32125
32308
  contents: {
32126
32309
  type: "string" /* STRING */,
32127
32310
  title: "HTML Contents"
32311
+ },
32312
+ addInvite: {
32313
+ type: "boolean" /* BOOLEAN */,
32314
+ title: "Add calendar invite"
32315
+ },
32316
+ startTime: {
32317
+ type: "date" /* DATE */,
32318
+ title: "Start Time",
32319
+ dependsOn: "addInvite"
32320
+ },
32321
+ endTime: {
32322
+ type: "date" /* DATE */,
32323
+ title: "End Time",
32324
+ dependsOn: "addInvite"
32325
+ },
32326
+ summary: {
32327
+ type: "string" /* STRING */,
32328
+ title: "Meeting Summary",
32329
+ dependsOn: "addInvite"
32330
+ },
32331
+ location: {
32332
+ type: "string" /* STRING */,
32333
+ title: "Location",
32334
+ dependsOn: "addInvite"
32335
+ },
32336
+ url: {
32337
+ type: "string" /* STRING */,
32338
+ title: "URL",
32339
+ dependsOn: "addInvite"
32128
32340
  }
32129
32341
  },
32130
32342
  required: ["to", "from", "subject", "contents"]
@@ -34632,6 +34844,19 @@ async function buildSchemaHelper(datasource2) {
34632
34844
  }
34633
34845
  return { tables: connector.tables, error: error2 };
34634
34846
  }
34847
+ async function buildFilteredSchema(datasource2, filter2) {
34848
+ let { tables, error: error2 } = await buildSchemaHelper(datasource2);
34849
+ let finalTables = tables;
34850
+ if (filter2) {
34851
+ finalTables = {};
34852
+ for (let key in tables) {
34853
+ if (filter2.some((filter3) => filter3.toLowerCase() === key.toLowerCase())) {
34854
+ finalTables[key] = tables[key];
34855
+ }
34856
+ }
34857
+ }
34858
+ return { tables: finalTables, error: error2 };
34859
+ }
34635
34860
  async function fetch22(ctx) {
34636
34861
  const db2 = context_exports.getAppDB();
34637
34862
  const internalTables = await db2.allDocs(
@@ -34686,37 +34911,24 @@ async function information(ctx) {
34686
34911
  }
34687
34912
  const tableNames = await connector.getTableNames();
34688
34913
  ctx.body = {
34689
- tableNames
34914
+ tableNames: tableNames.sort()
34690
34915
  };
34691
34916
  }
34692
34917
  async function buildSchemaFromDb(ctx) {
34693
34918
  const db2 = context_exports.getAppDB();
34694
- const datasource2 = await sdk_default.datasources.get(ctx.params.datasourceId);
34695
34919
  const tablesFilter = ctx.request.body.tablesFilter;
34696
- let { tables, error: error2 } = await buildSchemaHelper(datasource2);
34697
- if (tablesFilter) {
34698
- if (!datasource2.entities) {
34699
- datasource2.entities = {};
34700
- }
34701
- for (let key in tables) {
34702
- if (tablesFilter.some(
34703
- (filter2) => filter2.toLowerCase() === key.toLowerCase()
34704
- )) {
34705
- datasource2.entities[key] = tables[key];
34706
- }
34707
- }
34708
- } else {
34709
- datasource2.entities = tables;
34710
- }
34920
+ const datasource2 = await sdk_default.datasources.get(ctx.params.datasourceId);
34921
+ const { tables, error: error2 } = await buildFilteredSchema(datasource2, tablesFilter);
34922
+ datasource2.entities = tables;
34711
34923
  setDefaultDisplayColumns(datasource2);
34712
34924
  const dbResp = await db2.put(datasource2);
34713
34925
  datasource2._rev = dbResp.rev;
34714
34926
  const cleanedDatasource = await sdk_default.datasources.removeSecretSingle(datasource2);
34715
- const response2 = { datasource: cleanedDatasource };
34927
+ const res = { datasource: cleanedDatasource };
34716
34928
  if (error2) {
34717
- response2.error = error2;
34929
+ res.error = error2;
34718
34930
  }
34719
- ctx.body = response2;
34931
+ ctx.body = res;
34720
34932
  }
34721
34933
  function setDefaultDisplayColumns(datasource2) {
34722
34934
  for (let entity of Object.values(datasource2.entities || {})) {
@@ -34790,6 +35002,7 @@ async function save13(ctx) {
34790
35002
  const db2 = context_exports.getAppDB();
34791
35003
  const plus = ctx.request.body.datasource.plus;
34792
35004
  const fetchSchema = ctx.request.body.fetchSchema;
35005
+ const tablesFilter = ctx.request.body.tablesFilter;
34793
35006
  const datasource2 = {
34794
35007
  _id: generateDatasourceID({ plus }),
34795
35008
  ...ctx.request.body.datasource,
@@ -34797,11 +35010,17 @@ async function save13(ctx) {
34797
35010
  };
34798
35011
  let schemaError = null;
34799
35012
  if (fetchSchema) {
34800
- const { tables, error: error2 } = await buildSchemaHelper(datasource2);
35013
+ const { tables, error: error2 } = await buildFilteredSchema(
35014
+ datasource2,
35015
+ tablesFilter
35016
+ );
34801
35017
  schemaError = error2;
34802
35018
  datasource2.entities = tables;
34803
35019
  setDefaultDisplayColumns(datasource2);
34804
35020
  }
35021
+ if (preSaveAction[datasource2.source]) {
35022
+ await preSaveAction[datasource2.source](datasource2);
35023
+ }
34805
35024
  const dbResp = await db2.put(datasource2);
34806
35025
  await events_exports.datasource.created(datasource2);
34807
35026
  datasource2._rev = dbResp.rev;
@@ -34880,6 +35099,7 @@ async function query(ctx) {
34880
35099
  ctx.throw(400, err);
34881
35100
  }
34882
35101
  }
35102
+ var preSaveAction;
34883
35103
  var init_datasource5 = __esm({
34884
35104
  "src/api/controllers/datasource.ts"() {
34885
35105
  init_utils9();
@@ -34889,8 +35109,15 @@ var init_datasource5 = __esm({
34889
35109
  init_utils24();
34890
35110
  init_utils18();
34891
35111
  init_src2();
35112
+ init_src();
34892
35113
  init_sdk3();
34893
35114
  init_websockets();
35115
+ init_googlesheets();
35116
+ preSaveAction = {
35117
+ ["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
35118
+ await setupCreationAuth(datasource2.config);
35119
+ }
35120
+ };
34894
35121
  }
34895
35122
  });
34896
35123
 
@@ -37734,6 +37961,8 @@ function process2(updateCb) {
37734
37961
  } catch (err) {
37735
37962
  if ((err == null ? void 0 : err.status) === 404) {
37736
37963
  return;
37964
+ } else if ((err == null ? void 0 : err.status) === 409) {
37965
+ return;
37737
37966
  } else {
37738
37967
  logging_exports.logAlert("Failed to perform user/group app sync", err);
37739
37968
  }
@@ -41615,17 +41844,23 @@ var init_query6 = __esm({
41615
41844
 
41616
41845
  // src/api/controllers/backup.ts
41617
41846
  async function exportAppDump(ctx) {
41618
- let { appId, excludeRows } = ctx.query;
41847
+ const { appId } = ctx.query;
41848
+ const { excludeRows, encryptPassword } = ctx.request.body;
41849
+ const [app2] = await db_exports.getAppsByIDs([appId]);
41850
+ const appName = app2.name;
41619
41851
  ctx.req.setTimeout(0);
41620
- const appName = decodeURI(ctx.query.appname);
41621
- excludeRows = isQsTrue(excludeRows);
41622
- const backupIdentifier = `${appName}-export-${(/* @__PURE__ */ new Date()).getTime()}.tar.gz`;
41852
+ const extension = encryptPassword ? "enc.tar.gz" : "tar.gz";
41853
+ const backupIdentifier = `${appName}-export-${(/* @__PURE__ */ new Date()).getTime()}.${extension}`;
41623
41854
  ctx.attachment(backupIdentifier);
41624
- ctx.body = await sdk_default.backups.streamExportApp(appId, excludeRows);
41855
+ ctx.body = await sdk_default.backups.streamExportApp({
41856
+ appId,
41857
+ excludeRows,
41858
+ encryptPassword
41859
+ });
41625
41860
  await context_exports.doInAppContext(appId, async () => {
41626
41861
  const appDb = context_exports.getAppDB();
41627
- const app2 = await appDb.get(DocumentType2.APP_METADATA);
41628
- await events_exports.app.exported(app2);
41862
+ const app3 = await appDb.get(DocumentType2.APP_METADATA);
41863
+ await events_exports.app.exported(app3);
41629
41864
  });
41630
41865
  }
41631
41866
  var init_backup6 = __esm({
@@ -41633,7 +41868,6 @@ var init_backup6 = __esm({
41633
41868
  init_sdk3();
41634
41869
  init_src2();
41635
41870
  init_utils9();
41636
- init_utilities2();
41637
41871
  }
41638
41872
  });
41639
41873
 
@@ -41646,7 +41880,7 @@ var init_backup7 = __esm({
41646
41880
  init_authorized();
41647
41881
  init_src2();
41648
41882
  router28 = new import_router28.default();
41649
- router28.get(
41883
+ router28.post(
41650
41884
  "/api/backups/export",
41651
41885
  authorized_default(permissions_exports.BUILDER),
41652
41886
  exportAppDump
@@ -43078,18 +43312,18 @@ async function npmUpload(url, name, headers = {}) {
43078
43312
  }
43079
43313
  try {
43080
43314
  await extractTarball(tarballPluginFile, path5);
43081
- deleteFolderFileSystem((0, import_path14.join)(path5, "package"));
43315
+ deleteFolderFileSystem((0, import_path15.join)(path5, "package"));
43082
43316
  } catch (err) {
43083
43317
  throw new Error(err);
43084
43318
  }
43085
43319
  return await getPluginMetadata(path5);
43086
43320
  }
43087
- var import_node_fetch20, import_path14;
43321
+ var import_node_fetch20, import_path15;
43088
43322
  var init_npm = __esm({
43089
43323
  "src/api/controllers/plugin/npm.ts"() {
43090
43324
  init_fileSystem();
43091
43325
  import_node_fetch20 = __toESM(require("node-fetch"));
43092
- import_path14 = require("path");
43326
+ import_path15 = require("path");
43093
43327
  init_utils28();
43094
43328
  }
43095
43329
  });
@@ -43297,7 +43531,7 @@ async function prepareUpload({ s3Key, bucket, metadata, file }) {
43297
43531
  key: response2.Key
43298
43532
  };
43299
43533
  }
43300
- var import_string_templates10, import_aws_sdk4, import_fs15, uuid5, send2, toggleBetaUiFeature, serveBuilder, uploadFile, deleteObjects, serveApp, serveBuilderPreview, serveClientLibrary, getSignedUploadURL;
43534
+ var import_string_templates10, import_aws_sdk4, import_fs16, uuid5, send2, toggleBetaUiFeature, serveBuilder, uploadFile, deleteObjects, serveApp, serveBuilderPreview, serveClientLibrary, getSignedUploadURL;
43301
43535
  var init_static = __esm({
43302
43536
  "src/api/controllers/static/index.ts"() {
43303
43537
  init_centralPath();
@@ -43308,7 +43542,7 @@ var init_static = __esm({
43308
43542
  init_utils9();
43309
43543
  init_src2();
43310
43544
  import_aws_sdk4 = __toESM(require("aws-sdk"));
43311
- import_fs15 = __toESM(require("fs"));
43545
+ import_fs16 = __toESM(require("fs"));
43312
43546
  init_sdk3();
43313
43547
  init_src4();
43314
43548
  require("svelte/register");
@@ -43323,9 +43557,9 @@ var init_static = __esm({
43323
43557
  };
43324
43558
  return;
43325
43559
  }
43326
- let builderPath = join3(TOP_LEVEL_PATH, "new_design_ui");
43327
- if (!import_fs15.default.existsSync(builderPath)) {
43328
- import_fs15.default.mkdirSync(builderPath);
43560
+ let builderPath = join4(TOP_LEVEL_PATH, "new_design_ui");
43561
+ if (!import_fs16.default.existsSync(builderPath)) {
43562
+ import_fs16.default.mkdirSync(builderPath);
43329
43563
  }
43330
43564
  await objectStore_exports2.downloadTarballDirect(
43331
43565
  "https://cdn.budi.live/beta:design_ui/new_ui.tar.gz",
@@ -43337,7 +43571,7 @@ var init_static = __esm({
43337
43571
  };
43338
43572
  };
43339
43573
  serveBuilder = async function(ctx) {
43340
- const builderPath = join3(TOP_LEVEL_PATH, "builder");
43574
+ const builderPath = join4(TOP_LEVEL_PATH, "builder");
43341
43575
  await send2(ctx, ctx.file, { root: builderPath });
43342
43576
  };
43343
43577
  uploadFile = async function(ctx) {
@@ -43426,7 +43660,7 @@ var init_static = __esm({
43426
43660
  };
43427
43661
  serveClientLibrary = async function(ctx) {
43428
43662
  return send2(ctx, "budibase-client.js", {
43429
- root: join3(NODE_MODULES_PATH, "@budibase", "client", "dist")
43663
+ root: join4(NODE_MODULES_PATH, "@budibase", "client", "dist")
43430
43664
  });
43431
43665
  };
43432
43666
  getSignedUploadURL = async function(ctx) {
@@ -44746,13 +44980,13 @@ var init_routes = __esm({
44746
44980
  });
44747
44981
 
44748
44982
  // src/api/index.ts
44749
- var import_router35, import_zlib2, compress, router35;
44983
+ var import_router35, import_zlib3, compress, router35;
44750
44984
  var init_api8 = __esm({
44751
44985
  "src/api/index.ts"() {
44752
44986
  import_router35 = __toESM(require("@koa/router"));
44753
44987
  init_src2();
44754
44988
  init_currentapp();
44755
- import_zlib2 = __toESM(require("zlib"));
44989
+ import_zlib3 = __toESM(require("zlib"));
44756
44990
  init_routes();
44757
44991
  init_src4();
44758
44992
  init_public();
@@ -44765,10 +44999,10 @@ var init_api8 = __esm({
44765
44999
  compress({
44766
45000
  threshold: 2048,
44767
45001
  gzip: {
44768
- flush: import_zlib2.default.constants.Z_SYNC_FLUSH
45002
+ flush: import_zlib3.default.constants.Z_SYNC_FLUSH
44769
45003
  },
44770
45004
  deflate: {
44771
- flush: import_zlib2.default.constants.Z_SYNC_FLUSH
45005
+ flush: import_zlib3.default.constants.Z_SYNC_FLUSH
44772
45006
  },
44773
45007
  br: false
44774
45008
  })
@@ -44814,7 +45048,7 @@ var init_automations8 = __esm({
44814
45048
 
44815
45049
  // src/watch.ts
44816
45050
  function watch() {
44817
- const watchPath = import_path15.default.join(environment_default2.PLUGINS_DIR, "./**/*.tar.gz");
45051
+ const watchPath = import_path16.default.join(environment_default2.PLUGINS_DIR, "./**/*.tar.gz");
44818
45052
  import_chokidar.default.watch(watchPath, {
44819
45053
  ignored: "**/node_modules",
44820
45054
  awaitWriteFinish: {
@@ -44824,7 +45058,7 @@ function watch() {
44824
45058
  usePolling: true,
44825
45059
  interval: 250
44826
45060
  }).on("all", async (event, path5) => {
44827
- if (!(path5 == null ? void 0 : path5.endsWith(".tar.gz")) || !import_fs16.default.existsSync(path5)) {
45061
+ if (!(path5 == null ? void 0 : path5.endsWith(".tar.gz")) || !import_fs17.default.existsSync(path5)) {
44828
45062
  return;
44829
45063
  }
44830
45064
  await tenancy.doInTenant(constants_exports.DEFAULT_TENANT_ID, async () => {
@@ -44840,13 +45074,13 @@ function watch() {
44840
45074
  });
44841
45075
  });
44842
45076
  }
44843
- var import_path15, import_chokidar, import_fs16;
45077
+ var import_path16, import_chokidar, import_fs17;
44844
45078
  var init_watch = __esm({
44845
45079
  "src/watch.ts"() {
44846
- import_path15 = __toESM(require("path"));
45080
+ import_path16 = __toESM(require("path"));
44847
45081
  init_environment3();
44848
45082
  import_chokidar = __toESM(require("chokidar"));
44849
- import_fs16 = __toESM(require("fs"));
45083
+ import_fs17 = __toESM(require("fs"));
44850
45084
  init_src2();
44851
45085
  init_plugins5();
44852
45086
  }
@@ -44902,7 +45136,7 @@ async function startup(app2, server2) {
44902
45136
  shutdown9(server2);
44903
45137
  }
44904
45138
  }
44905
- if (environment_default2.SELF_HOSTED && !environment_default2.MULTI_TENANCY && environment_default2.PLUGINS_DIR && import_fs17.default.existsSync(environment_default2.PLUGINS_DIR)) {
45139
+ if (environment_default2.SELF_HOSTED && !environment_default2.MULTI_TENANCY && environment_default2.PLUGINS_DIR && import_fs18.default.existsSync(environment_default2.PLUGINS_DIR)) {
44906
45140
  watch();
44907
45141
  }
44908
45142
  await installation_exports.checkInstallVersion();
@@ -44937,14 +45171,14 @@ async function startup(app2, server2) {
44937
45171
  }
44938
45172
  }
44939
45173
  }
44940
- var import_fs17, STARTUP_RAN;
45174
+ var import_fs18, STARTUP_RAN;
44941
45175
  var init_startup = __esm({
44942
45176
  "src/startup.ts"() {
44943
45177
  init_environment3();
44944
45178
  init_redis4();
44945
45179
  init_workerRequests();
44946
45180
  init_src2();
44947
- import_fs17 = __toESM(require("fs"));
45181
+ import_fs18 = __toESM(require("fs"));
44948
45182
  init_watch();
44949
45183
  init_automations8();
44950
45184
  init_fileSystem();