@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/builder/assets/{index.d9b46807.css → index.2e9069f3.css} +1 -1
- package/builder/assets/{index.717d69a6.js → index.55a50076.js} +351 -351
- package/builder/index.html +2 -2
- package/dist/automation.js +405 -179
- package/dist/automation.js.map +3 -3
- package/dist/index.js +516 -282
- package/dist/index.js.map +3 -3
- package/dist/query.js +301 -141
- package/dist/query.js.map +3 -3
- package/package.json +11 -11
- package/src/api/controllers/backup.ts +22 -8
- package/src/api/controllers/datasource.ts +41 -24
- package/src/api/controllers/role.ts +5 -5
- package/src/api/controllers/routing.ts +3 -3
- package/src/api/routes/backup.ts +1 -1
- package/src/api/routes/tests/backup.spec.ts +18 -2
- package/src/automations/steps/sendSmtpEmail.ts +55 -4
- package/src/automations/tests/sendSmtpEmail.spec.ts +74 -0
- package/src/events/docUpdates/syncUsers.ts +4 -0
- package/src/integrations/googlesheets.ts +35 -18
- package/src/integrations/mongodb.ts +4 -2
- package/src/integrations/postgres.ts +2 -1
- package/src/middleware/currentapp.ts +1 -1
- package/src/sdk/app/backups/exports.ts +33 -5
- package/src/sdk/app/backups/imports.ts +21 -1
- package/src/sdk/app/datasources/datasources.ts +1 -0
- package/src/utilities/workerRequests.ts +20 -9
- package/src/automations/tests/sendSmtpEmail.spec.js +0 -71
package/dist/automation.js
CHANGED
|
@@ -946,6 +946,7 @@ var init_automation2 = __esm({
|
|
|
946
946
|
AutomationIOType2["NUMBER"] = "number";
|
|
947
947
|
AutomationIOType2["ARRAY"] = "array";
|
|
948
948
|
AutomationIOType2["JSON"] = "json";
|
|
949
|
+
AutomationIOType2["DATE"] = "date";
|
|
949
950
|
return AutomationIOType2;
|
|
950
951
|
})(AutomationIOType || {});
|
|
951
952
|
AutomationCustomIOType = /* @__PURE__ */ ((AutomationCustomIOType2) => {
|
|
@@ -5360,11 +5361,11 @@ function makeCacheItem(doc, lastWrite = null) {
|
|
|
5360
5361
|
return { doc, lastWrite: lastWrite || Date.now() };
|
|
5361
5362
|
}
|
|
5362
5363
|
async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
5363
|
-
const
|
|
5364
|
+
const cache3 = await getCache();
|
|
5364
5365
|
const key = doc._id;
|
|
5365
5366
|
let cacheItem;
|
|
5366
5367
|
if (key) {
|
|
5367
|
-
cacheItem = await
|
|
5368
|
+
cacheItem = await cache3.get(makeCacheKey(db2, key));
|
|
5368
5369
|
}
|
|
5369
5370
|
const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
|
|
5370
5371
|
let output = doc;
|
|
@@ -5402,30 +5403,30 @@ async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
5402
5403
|
}
|
|
5403
5404
|
cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
|
|
5404
5405
|
if (output._id) {
|
|
5405
|
-
await
|
|
5406
|
+
await cache3.store(makeCacheKey(db2, output._id), cacheItem);
|
|
5406
5407
|
}
|
|
5407
5408
|
return { ok: true, id: output._id, rev: output._rev };
|
|
5408
5409
|
}
|
|
5409
5410
|
async function get2(db2, id) {
|
|
5410
|
-
const
|
|
5411
|
+
const cache3 = await getCache();
|
|
5411
5412
|
const cacheKey = makeCacheKey(db2, id);
|
|
5412
|
-
let cacheItem = await
|
|
5413
|
+
let cacheItem = await cache3.get(cacheKey);
|
|
5413
5414
|
if (!cacheItem) {
|
|
5414
5415
|
const doc = await db2.get(id);
|
|
5415
5416
|
cacheItem = makeCacheItem(doc);
|
|
5416
|
-
await
|
|
5417
|
+
await cache3.store(cacheKey, cacheItem);
|
|
5417
5418
|
}
|
|
5418
5419
|
return cacheItem.doc;
|
|
5419
5420
|
}
|
|
5420
5421
|
async function remove(db2, docOrId, rev) {
|
|
5421
|
-
const
|
|
5422
|
+
const cache3 = await getCache();
|
|
5422
5423
|
if (!docOrId) {
|
|
5423
5424
|
throw new Error("No ID/Rev provided.");
|
|
5424
5425
|
}
|
|
5425
5426
|
const id = typeof docOrId === "string" ? docOrId : docOrId._id;
|
|
5426
5427
|
rev = typeof docOrId === "string" ? rev : docOrId._rev;
|
|
5427
5428
|
try {
|
|
5428
|
-
await
|
|
5429
|
+
await cache3.delete(makeCacheKey(db2, id));
|
|
5429
5430
|
} finally {
|
|
5430
5431
|
await db2.remove(id, rev);
|
|
5431
5432
|
}
|
|
@@ -9028,7 +9029,7 @@ function lowerBuiltinRoleID(roleId1, roleId2) {
|
|
|
9028
9029
|
}
|
|
9029
9030
|
return builtinRoleToNumber(roleId1) > builtinRoleToNumber(roleId2) ? roleId2 : roleId1;
|
|
9030
9031
|
}
|
|
9031
|
-
async function getRole(roleId) {
|
|
9032
|
+
async function getRole(roleId, opts) {
|
|
9032
9033
|
if (!roleId) {
|
|
9033
9034
|
return void 0;
|
|
9034
9035
|
}
|
|
@@ -9044,6 +9045,9 @@ async function getRole(roleId) {
|
|
|
9044
9045
|
role = Object.assign(role, dbRole);
|
|
9045
9046
|
role._id = getExternalRoleID(role._id);
|
|
9046
9047
|
} catch (err) {
|
|
9048
|
+
if (!isBuiltin(roleId) && (opts == null ? void 0 : opts.defaultPublic)) {
|
|
9049
|
+
return cloneDeep2(BUILTIN_ROLES.PUBLIC);
|
|
9050
|
+
}
|
|
9047
9051
|
if (Object.keys(role).length === 0) {
|
|
9048
9052
|
throw err;
|
|
9049
9053
|
}
|
|
@@ -9784,8 +9788,8 @@ async function preAuth(passport2, ctx, next) {
|
|
|
9784
9788
|
callbackUrl,
|
|
9785
9789
|
ssoSaveUserNoOp
|
|
9786
9790
|
);
|
|
9787
|
-
if (!ctx.query.appId
|
|
9788
|
-
ctx.throw(400, "appId
|
|
9791
|
+
if (!ctx.query.appId) {
|
|
9792
|
+
ctx.throw(400, "appId query param not present.");
|
|
9789
9793
|
}
|
|
9790
9794
|
return passport2.authenticate(strategy, {
|
|
9791
9795
|
scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
|
|
@@ -9805,7 +9809,7 @@ async function postAuth(passport2, ctx, next) {
|
|
|
9805
9809
|
clientSecret: config.clientSecret,
|
|
9806
9810
|
callbackURL: callbackUrl
|
|
9807
9811
|
},
|
|
9808
|
-
(accessToken, refreshToken,
|
|
9812
|
+
(accessToken, refreshToken, _profile, done) => {
|
|
9809
9813
|
clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
|
|
9810
9814
|
done(null, { accessToken, refreshToken });
|
|
9811
9815
|
}
|
|
@@ -9813,22 +9817,14 @@ async function postAuth(passport2, ctx, next) {
|
|
|
9813
9817
|
{ successRedirect: "/", failureRedirect: "/error" },
|
|
9814
9818
|
async (err, tokens) => {
|
|
9815
9819
|
const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
if (err2.status === 404) {
|
|
9822
|
-
ctx.redirect(baseUrl);
|
|
9823
|
-
}
|
|
9824
|
-
}
|
|
9825
|
-
if (!datasource2.config) {
|
|
9826
|
-
datasource2.config = {};
|
|
9820
|
+
const id = newid();
|
|
9821
|
+
await store(
|
|
9822
|
+
`datasource:creation:${authStateCookie.appId}:google:${id}`,
|
|
9823
|
+
{
|
|
9824
|
+
tokens
|
|
9827
9825
|
}
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
|
|
9831
|
-
});
|
|
9826
|
+
);
|
|
9827
|
+
ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
|
|
9832
9828
|
}
|
|
9833
9829
|
)(ctx, next);
|
|
9834
9830
|
}
|
|
@@ -9837,9 +9833,9 @@ var init_google2 = __esm({
|
|
|
9837
9833
|
"../backend-core/src/middleware/passport/datasource/google.ts"() {
|
|
9838
9834
|
init_google();
|
|
9839
9835
|
init_constants2();
|
|
9840
|
-
init_utils5();
|
|
9841
|
-
init_db5();
|
|
9842
9836
|
init_configs3();
|
|
9837
|
+
init_cache();
|
|
9838
|
+
init_utils5();
|
|
9843
9839
|
init_sso2();
|
|
9844
9840
|
GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
|
|
9845
9841
|
}
|
|
@@ -9889,7 +9885,9 @@ var encryption_exports = {};
|
|
|
9889
9885
|
__export(encryption_exports, {
|
|
9890
9886
|
SecretOption: () => SecretOption,
|
|
9891
9887
|
decrypt: () => decrypt,
|
|
9888
|
+
decryptFile: () => decryptFile,
|
|
9892
9889
|
encrypt: () => encrypt,
|
|
9890
|
+
encryptFile: () => encryptFile,
|
|
9893
9891
|
getSecret: () => getSecret
|
|
9894
9892
|
});
|
|
9895
9893
|
function getSecret(secretOption) {
|
|
@@ -9910,11 +9908,11 @@ function getSecret(secretOption) {
|
|
|
9910
9908
|
}
|
|
9911
9909
|
return secret;
|
|
9912
9910
|
}
|
|
9913
|
-
function stretchString(
|
|
9914
|
-
return import_crypto.default.pbkdf2Sync(
|
|
9911
|
+
function stretchString(secret, salt) {
|
|
9912
|
+
return import_crypto.default.pbkdf2Sync(secret, salt, ITERATIONS, STRETCH_LENGTH, "sha512");
|
|
9915
9913
|
}
|
|
9916
9914
|
function encrypt(input, secretOption = "api" /* API */) {
|
|
9917
|
-
const salt = import_crypto.default.randomBytes(
|
|
9915
|
+
const salt = import_crypto.default.randomBytes(SALT_LENGTH);
|
|
9918
9916
|
const stretched = stretchString(getSecret(secretOption), salt);
|
|
9919
9917
|
const cipher = import_crypto.default.createCipheriv(ALGO, stretched, salt);
|
|
9920
9918
|
const base = cipher.update(input);
|
|
@@ -9931,16 +9929,101 @@ function decrypt(input, secretOption = "api" /* API */) {
|
|
|
9931
9929
|
const final = decipher.final();
|
|
9932
9930
|
return Buffer.concat([base, final]).toString();
|
|
9933
9931
|
}
|
|
9934
|
-
|
|
9932
|
+
async function encryptFile({ dir, filename }, secret) {
|
|
9933
|
+
const outputFileName = `${filename}.enc`;
|
|
9934
|
+
const filePath = (0, import_path2.join)(dir, filename);
|
|
9935
|
+
const inputFile = import_fs2.default.createReadStream(filePath);
|
|
9936
|
+
const outputFile = import_fs2.default.createWriteStream((0, import_path2.join)(dir, outputFileName));
|
|
9937
|
+
const salt = import_crypto.default.randomBytes(SALT_LENGTH);
|
|
9938
|
+
const iv = import_crypto.default.randomBytes(IV_LENGTH);
|
|
9939
|
+
const stretched = stretchString(secret, salt);
|
|
9940
|
+
const cipher = import_crypto.default.createCipheriv(ALGO, stretched, iv);
|
|
9941
|
+
outputFile.write(salt);
|
|
9942
|
+
outputFile.write(iv);
|
|
9943
|
+
inputFile.pipe(import_zlib.default.createGzip()).pipe(cipher).pipe(outputFile);
|
|
9944
|
+
return new Promise((r) => {
|
|
9945
|
+
outputFile.on("finish", () => {
|
|
9946
|
+
r({
|
|
9947
|
+
filename: outputFileName,
|
|
9948
|
+
dir
|
|
9949
|
+
});
|
|
9950
|
+
});
|
|
9951
|
+
});
|
|
9952
|
+
}
|
|
9953
|
+
async function getSaltAndIV(path2) {
|
|
9954
|
+
const fileStream = import_fs2.default.createReadStream(path2);
|
|
9955
|
+
const salt = await readBytes(fileStream, SALT_LENGTH);
|
|
9956
|
+
const iv = await readBytes(fileStream, IV_LENGTH);
|
|
9957
|
+
fileStream.close();
|
|
9958
|
+
return { salt, iv };
|
|
9959
|
+
}
|
|
9960
|
+
async function decryptFile(inputPath, outputPath, secret) {
|
|
9961
|
+
const { salt, iv } = await getSaltAndIV(inputPath);
|
|
9962
|
+
const inputFile = import_fs2.default.createReadStream(inputPath, {
|
|
9963
|
+
start: SALT_LENGTH + IV_LENGTH
|
|
9964
|
+
});
|
|
9965
|
+
const outputFile = import_fs2.default.createWriteStream(outputPath);
|
|
9966
|
+
const stretched = stretchString(secret, salt);
|
|
9967
|
+
const decipher = import_crypto.default.createDecipheriv(ALGO, stretched, iv);
|
|
9968
|
+
const unzip = import_zlib.default.createGunzip();
|
|
9969
|
+
inputFile.pipe(decipher).pipe(unzip).pipe(outputFile);
|
|
9970
|
+
return new Promise((res, rej) => {
|
|
9971
|
+
outputFile.on("finish", () => {
|
|
9972
|
+
outputFile.close();
|
|
9973
|
+
res();
|
|
9974
|
+
});
|
|
9975
|
+
inputFile.on("error", (e) => {
|
|
9976
|
+
outputFile.close();
|
|
9977
|
+
rej(e);
|
|
9978
|
+
});
|
|
9979
|
+
decipher.on("error", (e) => {
|
|
9980
|
+
outputFile.close();
|
|
9981
|
+
rej(e);
|
|
9982
|
+
});
|
|
9983
|
+
unzip.on("error", (e) => {
|
|
9984
|
+
outputFile.close();
|
|
9985
|
+
rej(e);
|
|
9986
|
+
});
|
|
9987
|
+
outputFile.on("error", (e) => {
|
|
9988
|
+
outputFile.close();
|
|
9989
|
+
rej(e);
|
|
9990
|
+
});
|
|
9991
|
+
});
|
|
9992
|
+
}
|
|
9993
|
+
function readBytes(stream3, length) {
|
|
9994
|
+
return new Promise((resolve3, reject) => {
|
|
9995
|
+
let bytesRead = 0;
|
|
9996
|
+
const data2 = [];
|
|
9997
|
+
stream3.on("readable", () => {
|
|
9998
|
+
let chunk;
|
|
9999
|
+
while ((chunk = stream3.read(length - bytesRead)) !== null) {
|
|
10000
|
+
data2.push(chunk);
|
|
10001
|
+
bytesRead += chunk.length;
|
|
10002
|
+
}
|
|
10003
|
+
resolve3(Buffer.concat(data2));
|
|
10004
|
+
});
|
|
10005
|
+
stream3.on("end", () => {
|
|
10006
|
+
reject(new Error("Insufficient data in the stream."));
|
|
10007
|
+
});
|
|
10008
|
+
stream3.on("error", (error) => {
|
|
10009
|
+
reject(error);
|
|
10010
|
+
});
|
|
10011
|
+
});
|
|
10012
|
+
}
|
|
10013
|
+
var import_crypto, import_fs2, import_zlib, import_path2, ALGO, SEPARATOR3, ITERATIONS, STRETCH_LENGTH, SALT_LENGTH, IV_LENGTH, SecretOption;
|
|
9935
10014
|
var init_encryption = __esm({
|
|
9936
10015
|
"../backend-core/src/security/encryption.ts"() {
|
|
9937
10016
|
import_crypto = __toESM(require("crypto"));
|
|
10017
|
+
import_fs2 = __toESM(require("fs"));
|
|
10018
|
+
import_zlib = __toESM(require("zlib"));
|
|
9938
10019
|
init_environment3();
|
|
10020
|
+
import_path2 = require("path");
|
|
9939
10021
|
ALGO = "aes-256-ctr";
|
|
9940
10022
|
SEPARATOR3 = "-";
|
|
9941
10023
|
ITERATIONS = 1e4;
|
|
9942
|
-
RANDOM_BYTES = 16;
|
|
9943
10024
|
STRETCH_LENGTH = 32;
|
|
10025
|
+
SALT_LENGTH = 16;
|
|
10026
|
+
IV_LENGTH = 16;
|
|
9944
10027
|
SecretOption = /* @__PURE__ */ ((SecretOption2) => {
|
|
9945
10028
|
SecretOption2["API"] = "api";
|
|
9946
10029
|
SecretOption2["ENCRYPTION"] = "encryption";
|
|
@@ -10851,12 +10934,12 @@ var init_plugin4 = __esm({
|
|
|
10851
10934
|
function budibaseTempDir() {
|
|
10852
10935
|
return bbTmp;
|
|
10853
10936
|
}
|
|
10854
|
-
var
|
|
10937
|
+
var import_path3, import_os, import_fs3, ObjectStoreBuckets, bbTmp;
|
|
10855
10938
|
var init_utils8 = __esm({
|
|
10856
10939
|
"../backend-core/src/objectStore/utils.ts"() {
|
|
10857
|
-
|
|
10940
|
+
import_path3 = require("path");
|
|
10858
10941
|
import_os = require("os");
|
|
10859
|
-
|
|
10942
|
+
import_fs3 = __toESM(require("fs"));
|
|
10860
10943
|
init_environment3();
|
|
10861
10944
|
ObjectStoreBuckets = {
|
|
10862
10945
|
BACKUPS: environment_default2.BACKUPS_BUCKET_NAME,
|
|
@@ -10865,9 +10948,9 @@ var init_utils8 = __esm({
|
|
|
10865
10948
|
GLOBAL: environment_default2.GLOBAL_BUCKET_NAME,
|
|
10866
10949
|
PLUGINS: environment_default2.PLUGIN_BUCKET_NAME
|
|
10867
10950
|
};
|
|
10868
|
-
bbTmp = (0,
|
|
10869
|
-
if (!
|
|
10870
|
-
|
|
10951
|
+
bbTmp = (0, import_path3.join)((0, import_os.tmpdir)(), ".budibase");
|
|
10952
|
+
if (!import_fs3.default.existsSync(bbTmp)) {
|
|
10953
|
+
import_fs3.default.mkdirSync(bbTmp);
|
|
10871
10954
|
}
|
|
10872
10955
|
}
|
|
10873
10956
|
});
|
|
@@ -10879,17 +10962,17 @@ function sanitizeKey(input) {
|
|
|
10879
10962
|
function sanitizeBucket(input) {
|
|
10880
10963
|
return input.replace(new RegExp(APP_DEV_PREFIX, "g"), APP_PREFIX);
|
|
10881
10964
|
}
|
|
10882
|
-
var import_aws_sdk, import_stream, import_node_fetch6, import_tar_fs,
|
|
10965
|
+
var import_aws_sdk, import_stream, import_node_fetch6, import_tar_fs, import_zlib2, import_util, import_path4, 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;
|
|
10883
10966
|
var init_objectStore = __esm({
|
|
10884
10967
|
"../backend-core/src/objectStore/objectStore.ts"() {
|
|
10885
10968
|
import_aws_sdk = __toESM(require("aws-sdk"));
|
|
10886
10969
|
import_stream = __toESM(require("stream"));
|
|
10887
10970
|
import_node_fetch6 = __toESM(require("node-fetch"));
|
|
10888
10971
|
import_tar_fs = __toESM(require("tar-fs"));
|
|
10889
|
-
|
|
10972
|
+
import_zlib2 = __toESM(require("zlib"));
|
|
10890
10973
|
import_util = require("util");
|
|
10891
|
-
|
|
10892
|
-
|
|
10974
|
+
import_path4 = require("path");
|
|
10975
|
+
import_fs4 = __toESM(require("fs"));
|
|
10893
10976
|
init_environment3();
|
|
10894
10977
|
init_utils8();
|
|
10895
10978
|
import_uuid3 = require("uuid");
|
|
@@ -10968,7 +11051,7 @@ var init_objectStore = __esm({
|
|
|
10968
11051
|
metadata
|
|
10969
11052
|
}) => {
|
|
10970
11053
|
const extension = filename.split(".").pop();
|
|
10971
|
-
const fileBytes =
|
|
11054
|
+
const fileBytes = import_fs4.default.readFileSync(path2);
|
|
10972
11055
|
const objectStore = ObjectStore(bucketName);
|
|
10973
11056
|
await makeSureBucketExists(objectStore, bucketName);
|
|
10974
11057
|
let contentType = type;
|
|
@@ -11070,13 +11153,13 @@ var init_objectStore = __esm({
|
|
|
11070
11153
|
bucketName = sanitizeBucket(bucketName);
|
|
11071
11154
|
filepath = sanitizeKey(filepath);
|
|
11072
11155
|
const data2 = await retrieve(bucketName, filepath);
|
|
11073
|
-
const outputPath = (0,
|
|
11074
|
-
|
|
11156
|
+
const outputPath = (0, import_path4.join)(budibaseTempDir(), (0, import_uuid3.v4)());
|
|
11157
|
+
import_fs4.default.writeFileSync(outputPath, data2);
|
|
11075
11158
|
return outputPath;
|
|
11076
11159
|
};
|
|
11077
11160
|
retrieveDirectory = async (bucketName, path2) => {
|
|
11078
|
-
let writePath = (0,
|
|
11079
|
-
|
|
11161
|
+
let writePath = (0, import_path4.join)(budibaseTempDir(), (0, import_uuid3.v4)());
|
|
11162
|
+
import_fs4.default.mkdirSync(writePath);
|
|
11080
11163
|
const objects = await listAllObjects(bucketName, path2);
|
|
11081
11164
|
let fullObjects = await Promise.all(
|
|
11082
11165
|
objects.map((obj) => retrieve(bucketName, obj.Key))
|
|
@@ -11088,9 +11171,9 @@ var init_objectStore = __esm({
|
|
|
11088
11171
|
const possiblePath = filename.split("/");
|
|
11089
11172
|
if (possiblePath.length > 1) {
|
|
11090
11173
|
const dirs = possiblePath.slice(0, possiblePath.length - 1);
|
|
11091
|
-
|
|
11174
|
+
import_fs4.default.mkdirSync((0, import_path4.join)(writePath, ...dirs), { recursive: true });
|
|
11092
11175
|
}
|
|
11093
|
-
|
|
11176
|
+
import_fs4.default.writeFileSync((0, import_path4.join)(writePath, ...possiblePath), data2);
|
|
11094
11177
|
}
|
|
11095
11178
|
return writePath;
|
|
11096
11179
|
};
|
|
@@ -11144,14 +11227,14 @@ var init_objectStore = __esm({
|
|
|
11144
11227
|
uploadDirectory = async (bucketName, localPath, bucketPath) => {
|
|
11145
11228
|
bucketName = sanitizeBucket(bucketName);
|
|
11146
11229
|
let uploads = [];
|
|
11147
|
-
const files =
|
|
11230
|
+
const files = import_fs4.default.readdirSync(localPath, { withFileTypes: true });
|
|
11148
11231
|
for (let file of files) {
|
|
11149
|
-
const path2 = sanitizeKey((0,
|
|
11150
|
-
const local = (0,
|
|
11232
|
+
const path2 = sanitizeKey((0, import_path4.join)(bucketPath, file.name));
|
|
11233
|
+
const local = (0, import_path4.join)(localPath, file.name);
|
|
11151
11234
|
if (file.isDirectory()) {
|
|
11152
11235
|
uploads.push(uploadDirectory(bucketName, local, path2));
|
|
11153
11236
|
} else {
|
|
11154
|
-
uploads.push(streamUpload(bucketName, path2,
|
|
11237
|
+
uploads.push(streamUpload(bucketName, path2, import_fs4.default.createReadStream(local)));
|
|
11155
11238
|
}
|
|
11156
11239
|
}
|
|
11157
11240
|
await Promise.all(uploads);
|
|
@@ -11163,7 +11246,7 @@ var init_objectStore = __esm({
|
|
|
11163
11246
|
if (!response2.ok) {
|
|
11164
11247
|
throw new Error(`unexpected response ${response2.statusText}`);
|
|
11165
11248
|
}
|
|
11166
|
-
await streamPipeline(response2.body,
|
|
11249
|
+
await streamPipeline(response2.body, import_zlib2.default.createUnzip(), import_tar_fs.default.extract(path2));
|
|
11167
11250
|
};
|
|
11168
11251
|
downloadTarball = async (url, bucketName, path2) => {
|
|
11169
11252
|
bucketName = sanitizeBucket(bucketName);
|
|
@@ -11172,8 +11255,8 @@ var init_objectStore = __esm({
|
|
|
11172
11255
|
if (!response2.ok) {
|
|
11173
11256
|
throw new Error(`unexpected response ${response2.statusText}`);
|
|
11174
11257
|
}
|
|
11175
|
-
const tmpPath = (0,
|
|
11176
|
-
await streamPipeline(response2.body,
|
|
11258
|
+
const tmpPath = (0, import_path4.join)(budibaseTempDir(), path2);
|
|
11259
|
+
await streamPipeline(response2.body, import_zlib2.default.createUnzip(), import_tar_fs.default.extract(tmpPath));
|
|
11177
11260
|
if (!environment_default2.isTest() && environment_default2.SELF_HOSTED) {
|
|
11178
11261
|
await uploadDirectory(bucketName, tmpPath, path2);
|
|
11179
11262
|
}
|
|
@@ -12626,21 +12709,21 @@ __export(version_exports, {
|
|
|
12626
12709
|
getLicenseVersion: () => getLicenseVersion,
|
|
12627
12710
|
getProVersion: () => getProVersion
|
|
12628
12711
|
});
|
|
12629
|
-
var
|
|
12712
|
+
var import_fs5, import_path5, getLicenseVersion, getProVersion;
|
|
12630
12713
|
var init_version2 = __esm({
|
|
12631
12714
|
"../pro/packages/pro/src/constants/version.ts"() {
|
|
12632
12715
|
init_src2();
|
|
12633
|
-
|
|
12634
|
-
|
|
12716
|
+
import_fs5 = __toESM(require("fs"));
|
|
12717
|
+
import_path5 = __toESM(require("path"));
|
|
12635
12718
|
getLicenseVersion = () => {
|
|
12636
12719
|
if (environment_default2.isDev()) {
|
|
12637
12720
|
const DEV_VER_FILENAME = "dev-version.txt";
|
|
12638
|
-
const verFile =
|
|
12639
|
-
if (
|
|
12640
|
-
return
|
|
12721
|
+
const verFile = import_path5.default.join(objectStore_exports2.budibaseTempDir(), DEV_VER_FILENAME);
|
|
12722
|
+
if (import_fs5.default.existsSync(verFile)) {
|
|
12723
|
+
return import_fs5.default.readFileSync(verFile, "utf8");
|
|
12641
12724
|
} else {
|
|
12642
12725
|
const devVer = utils_exports2.newid();
|
|
12643
|
-
|
|
12726
|
+
import_fs5.default.writeFileSync(verFile, devVer);
|
|
12644
12727
|
return devVer;
|
|
12645
12728
|
}
|
|
12646
12729
|
} else {
|
|
@@ -13086,31 +13169,31 @@ function getOfflineLicense() {
|
|
|
13086
13169
|
}
|
|
13087
13170
|
}
|
|
13088
13171
|
function getOfflineLicenseFromDisk() {
|
|
13089
|
-
if (
|
|
13090
|
-
const token =
|
|
13172
|
+
if (import_fs6.default.existsSync(LICENSE_FILE_PATH)) {
|
|
13173
|
+
const token = import_fs6.default.readFileSync(LICENSE_FILE_PATH, { encoding: "utf-8" });
|
|
13091
13174
|
return import_jsonwebtoken.default.verify(token, PUBLIC_KEY, { algorithms: ["RS256"] });
|
|
13092
13175
|
}
|
|
13093
13176
|
}
|
|
13094
13177
|
function writeOfflineLicenseToDisk(signedLicense) {
|
|
13095
|
-
|
|
13178
|
+
import_fs6.default.writeFileSync(LICENSE_FILE_PATH, signedLicense, { encoding: "utf-8" });
|
|
13096
13179
|
}
|
|
13097
13180
|
function deleteOfflineLicense() {
|
|
13098
|
-
|
|
13181
|
+
import_fs6.default.rmSync(LICENSE_FILE_PATH, { force: true });
|
|
13099
13182
|
}
|
|
13100
|
-
var
|
|
13183
|
+
var import_fs6, import_path6, import_os2, import_jsonwebtoken, SUB_DIRECTORY, DIRECTORY, OFFLINE_LICENSE_FILE, LICENSE_FILE_PATH, PUBLIC_KEY;
|
|
13101
13184
|
var init_offline = __esm({
|
|
13102
13185
|
"../pro/packages/pro/src/sdk/licensing/licenses/offline.ts"() {
|
|
13103
|
-
|
|
13104
|
-
|
|
13186
|
+
import_fs6 = __toESM(require("fs"));
|
|
13187
|
+
import_path6 = require("path");
|
|
13105
13188
|
import_os2 = require("os");
|
|
13106
13189
|
import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
13107
13190
|
init_src2();
|
|
13108
13191
|
SUB_DIRECTORY = environment_default2.isTest() ? ".budibase-test" : ".budibase";
|
|
13109
|
-
DIRECTORY = (0,
|
|
13192
|
+
DIRECTORY = (0, import_path6.join)((0, import_os2.tmpdir)(), SUB_DIRECTORY);
|
|
13110
13193
|
OFFLINE_LICENSE_FILE = "offline_license.txt";
|
|
13111
|
-
LICENSE_FILE_PATH = (0,
|
|
13112
|
-
if (!
|
|
13113
|
-
|
|
13194
|
+
LICENSE_FILE_PATH = (0, import_path6.join)(DIRECTORY, OFFLINE_LICENSE_FILE);
|
|
13195
|
+
if (!import_fs6.default.existsSync(DIRECTORY)) {
|
|
13196
|
+
import_fs6.default.mkdirSync(DIRECTORY);
|
|
13114
13197
|
}
|
|
13115
13198
|
PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvz3jePLCFBXZ19c8Dpkv\nXtSgOhKFOcvQdo/LV0KJRUzQWDPWuO4ILtBtnqhjtIzZH4CH0qCYBet5L6Qr4CM1\nl2HXiAD1Q2rlHNW9wDaYyKb1F5f+v4RyqCAyzlkwRdksmkLeECTboojNnmRCrE3C\n8suunQP5bEScqEY2kclqzSf8e6xqMzPUg3mL/pNa1iEv7TuLbU9nJfgR36l0WmZY\n94fWnSaT8OSXSqcxsaByf06gfS3HAoTJNc7eqz1Hf9fUORQGPUAnFK8cT3SfdA36\nd/o3ZWE1TTj1zYwlCLN5qRKr3hU8nC3xEYNEbkB9SfTRaOq9Q7P8WmfLkoCPm3pR\nmwIDAQAB\n-----END PUBLIC KEY-----\n";
|
|
13116
13199
|
}
|
|
@@ -14567,13 +14650,13 @@ var init_groups6 = __esm({
|
|
|
14567
14650
|
|
|
14568
14651
|
// ../pro/packages/pro/src/utilities/fileSystem.ts
|
|
14569
14652
|
function loadJSFile(directory, name) {
|
|
14570
|
-
return
|
|
14653
|
+
return import_fs7.default.readFileSync((0, import_path7.join)(directory, name), "utf8");
|
|
14571
14654
|
}
|
|
14572
|
-
var
|
|
14655
|
+
var import_fs7, import_path7;
|
|
14573
14656
|
var init_fileSystem = __esm({
|
|
14574
14657
|
"../pro/packages/pro/src/utilities/fileSystem.ts"() {
|
|
14575
|
-
|
|
14576
|
-
|
|
14658
|
+
import_fs7 = __toESM(require("fs"));
|
|
14659
|
+
import_path7 = require("path");
|
|
14577
14660
|
}
|
|
14578
14661
|
});
|
|
14579
14662
|
|
|
@@ -17541,8 +17624,8 @@ async function runBackup(trigger, tenantId, appId, opts) {
|
|
|
17541
17624
|
}
|
|
17542
17625
|
});
|
|
17543
17626
|
await updateMetadata2("complete" /* COMPLETE */, { filename, contents });
|
|
17544
|
-
if (
|
|
17545
|
-
|
|
17627
|
+
if (import_fs8.default.existsSync(tarPath)) {
|
|
17628
|
+
import_fs8.default.rmSync(tarPath);
|
|
17546
17629
|
}
|
|
17547
17630
|
} catch (err) {
|
|
17548
17631
|
logging_exports.logAlert("App backup error", err);
|
|
@@ -17600,14 +17683,14 @@ async function exportProcessor(job, opts) {
|
|
|
17600
17683
|
});
|
|
17601
17684
|
});
|
|
17602
17685
|
}
|
|
17603
|
-
var
|
|
17686
|
+
var import_fs8;
|
|
17604
17687
|
var init_processing = __esm({
|
|
17605
17688
|
"../pro/packages/pro/src/sdk/backups/processing.ts"() {
|
|
17606
17689
|
init_src2();
|
|
17607
17690
|
init_backup5();
|
|
17608
17691
|
init_src();
|
|
17609
17692
|
init_queue4();
|
|
17610
|
-
|
|
17693
|
+
import_fs8 = __toESM(require("fs"));
|
|
17611
17694
|
}
|
|
17612
17695
|
});
|
|
17613
17696
|
|
|
@@ -18248,15 +18331,15 @@ async function downloadBackup(ctx) {
|
|
|
18248
18331
|
const backupId = ctx.params.backupId;
|
|
18249
18332
|
const { metadata, path: path2 } = await backups_default.downloadAppBackup(backupId);
|
|
18250
18333
|
ctx.attachment(`backup-${metadata.timestamp}.tar.gz`);
|
|
18251
|
-
ctx.body =
|
|
18334
|
+
ctx.body = import_fs9.default.createReadStream(path2);
|
|
18252
18335
|
}
|
|
18253
|
-
var
|
|
18336
|
+
var import_fs9;
|
|
18254
18337
|
var init_backups3 = __esm({
|
|
18255
18338
|
"../pro/packages/pro/src/api/controllers/apps/backups.ts"() {
|
|
18256
18339
|
init_src();
|
|
18257
18340
|
init_sdk2();
|
|
18258
18341
|
init_src2();
|
|
18259
|
-
|
|
18342
|
+
import_fs9 = __toESM(require("fs"));
|
|
18260
18343
|
}
|
|
18261
18344
|
});
|
|
18262
18345
|
|
|
@@ -18892,11 +18975,39 @@ var init_filters = __esm({
|
|
|
18892
18975
|
// ../shared-core/src/utils.ts
|
|
18893
18976
|
var utils_exports5 = {};
|
|
18894
18977
|
__export(utils_exports5, {
|
|
18978
|
+
parallelForeach: () => parallelForeach,
|
|
18895
18979
|
unreachable: () => unreachable
|
|
18896
18980
|
});
|
|
18897
18981
|
function unreachable(value, message = `No such case in exhaustive switch: ${value}`) {
|
|
18898
18982
|
throw new Error(message);
|
|
18899
18983
|
}
|
|
18984
|
+
async function parallelForeach(items, task, maxConcurrency) {
|
|
18985
|
+
const promises = [];
|
|
18986
|
+
let index2 = 0;
|
|
18987
|
+
const processItem = async (item) => {
|
|
18988
|
+
try {
|
|
18989
|
+
await task(item);
|
|
18990
|
+
} finally {
|
|
18991
|
+
processNext();
|
|
18992
|
+
}
|
|
18993
|
+
};
|
|
18994
|
+
const processNext = () => {
|
|
18995
|
+
if (index2 >= items.length) {
|
|
18996
|
+
return;
|
|
18997
|
+
}
|
|
18998
|
+
const item = items[index2];
|
|
18999
|
+
index2++;
|
|
19000
|
+
const promise = processItem(item);
|
|
19001
|
+
promises.push(promise);
|
|
19002
|
+
if (promises.length >= maxConcurrency) {
|
|
19003
|
+
Promise.race(promises).then(processNext);
|
|
19004
|
+
} else {
|
|
19005
|
+
processNext();
|
|
19006
|
+
}
|
|
19007
|
+
};
|
|
19008
|
+
processNext();
|
|
19009
|
+
await Promise.all(promises);
|
|
19010
|
+
}
|
|
18900
19011
|
var init_utils12 = __esm({
|
|
18901
19012
|
"../shared-core/src/utils.ts"() {
|
|
18902
19013
|
}
|
|
@@ -19520,32 +19631,32 @@ var init_centralPath = __esm({
|
|
|
19520
19631
|
});
|
|
19521
19632
|
|
|
19522
19633
|
// src/utilities/fileSystem/filesystem.ts
|
|
19523
|
-
var
|
|
19634
|
+
var import_fs10, import_path8, import_tar, uuid2, TOP_LEVEL_PATH, apiFileReturn, streamFile, createTempFolder, extractTarball;
|
|
19524
19635
|
var init_filesystem = __esm({
|
|
19525
19636
|
"src/utilities/fileSystem/filesystem.ts"() {
|
|
19526
|
-
|
|
19637
|
+
import_fs10 = __toESM(require("fs"));
|
|
19527
19638
|
init_budibaseDir();
|
|
19528
|
-
|
|
19639
|
+
import_path8 = require("path");
|
|
19529
19640
|
init_environment();
|
|
19530
19641
|
import_tar = __toESM(require("tar"));
|
|
19531
19642
|
init_environment();
|
|
19532
19643
|
uuid2 = require("uuid/v4");
|
|
19533
|
-
TOP_LEVEL_PATH = environment_default.TOP_LEVEL_PATH || (0,
|
|
19644
|
+
TOP_LEVEL_PATH = environment_default.TOP_LEVEL_PATH || (0, import_path8.resolve)((0, import_path8.join)(__dirname, "..", "..", ".."));
|
|
19534
19645
|
apiFileReturn = (contents) => {
|
|
19535
|
-
const path2 = (0,
|
|
19536
|
-
|
|
19537
|
-
return
|
|
19646
|
+
const path2 = (0, import_path8.join)(budibaseTempDir2(), uuid2());
|
|
19647
|
+
import_fs10.default.writeFileSync(path2, contents);
|
|
19648
|
+
return import_fs10.default.createReadStream(path2);
|
|
19538
19649
|
};
|
|
19539
19650
|
streamFile = (path2) => {
|
|
19540
|
-
return
|
|
19651
|
+
return import_fs10.default.createReadStream(path2);
|
|
19541
19652
|
};
|
|
19542
19653
|
createTempFolder = (item) => {
|
|
19543
|
-
const path2 = (0,
|
|
19654
|
+
const path2 = (0, import_path8.join)(budibaseTempDir2(), item);
|
|
19544
19655
|
try {
|
|
19545
|
-
if (
|
|
19546
|
-
|
|
19656
|
+
if (import_fs10.default.existsSync(path2)) {
|
|
19657
|
+
import_fs10.default.rmSync(path2, { recursive: true, force: true });
|
|
19547
19658
|
}
|
|
19548
|
-
|
|
19659
|
+
import_fs10.default.mkdirSync(path2);
|
|
19549
19660
|
} catch (err) {
|
|
19550
19661
|
throw new Error(`Path cannot be created: ${err.message}`);
|
|
19551
19662
|
}
|
|
@@ -19572,17 +19683,17 @@ var init_clientLibrary = __esm({
|
|
|
19572
19683
|
});
|
|
19573
19684
|
|
|
19574
19685
|
// src/utilities/fileSystem/app.ts
|
|
19575
|
-
var
|
|
19686
|
+
var import_path9, NODE_MODULES_PATH;
|
|
19576
19687
|
var init_app7 = __esm({
|
|
19577
19688
|
"src/utilities/fileSystem/app.ts"() {
|
|
19578
19689
|
init_budibaseDir();
|
|
19579
|
-
|
|
19690
|
+
import_path9 = require("path");
|
|
19580
19691
|
init_constants6();
|
|
19581
19692
|
init_clientLibrary();
|
|
19582
19693
|
init_environment();
|
|
19583
19694
|
init_src2();
|
|
19584
19695
|
init_filesystem();
|
|
19585
|
-
NODE_MODULES_PATH = (0,
|
|
19696
|
+
NODE_MODULES_PATH = (0, import_path9.join)(TOP_LEVEL_PATH, "node_modules");
|
|
19586
19697
|
}
|
|
19587
19698
|
});
|
|
19588
19699
|
|
|
@@ -19590,19 +19701,19 @@ var init_app7 = __esm({
|
|
|
19590
19701
|
async function getPluginImpl(path2, plugin) {
|
|
19591
19702
|
var _a;
|
|
19592
19703
|
const hash2 = (_a = plugin.schema) == null ? void 0 : _a.hash;
|
|
19593
|
-
if (!
|
|
19594
|
-
|
|
19704
|
+
if (!import_fs11.default.existsSync(path2)) {
|
|
19705
|
+
import_fs11.default.mkdirSync(path2);
|
|
19595
19706
|
}
|
|
19596
|
-
const filename = (0,
|
|
19707
|
+
const filename = (0, import_path10.join)(path2, plugin.name);
|
|
19597
19708
|
const metadataName = `${filename}.bbmetadata`;
|
|
19598
|
-
if (
|
|
19599
|
-
const currentHash =
|
|
19709
|
+
if (import_fs11.default.existsSync(filename)) {
|
|
19710
|
+
const currentHash = import_fs11.default.readFileSync(metadataName, "utf8");
|
|
19600
19711
|
if (currentHash === hash2) {
|
|
19601
19712
|
return require(filename);
|
|
19602
19713
|
} else {
|
|
19603
19714
|
console.log(`Updating plugin: ${plugin.name}`);
|
|
19604
19715
|
delete require.cache[require.resolve(filename)];
|
|
19605
|
-
|
|
19716
|
+
import_fs11.default.unlinkSync(filename);
|
|
19606
19717
|
}
|
|
19607
19718
|
}
|
|
19608
19719
|
const pluginKey = objectStore_exports2.getPluginJSKey(plugin);
|
|
@@ -19610,24 +19721,24 @@ async function getPluginImpl(path2, plugin) {
|
|
|
19610
19721
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
19611
19722
|
pluginKey
|
|
19612
19723
|
);
|
|
19613
|
-
|
|
19614
|
-
|
|
19724
|
+
import_fs11.default.writeFileSync(filename, pluginJs);
|
|
19725
|
+
import_fs11.default.writeFileSync(metadataName, hash2);
|
|
19615
19726
|
return require(filename);
|
|
19616
19727
|
}
|
|
19617
|
-
var
|
|
19728
|
+
var import_fs11, import_path10, DATASOURCE_PATH, AUTOMATION_PATH, getPluginMetadata, getDatasourcePlugin, getAutomationPlugin;
|
|
19618
19729
|
var init_plugin5 = __esm({
|
|
19619
19730
|
"src/utilities/fileSystem/plugin.ts"() {
|
|
19620
19731
|
init_budibaseDir();
|
|
19621
|
-
|
|
19622
|
-
|
|
19732
|
+
import_fs11 = __toESM(require("fs"));
|
|
19733
|
+
import_path10 = require("path");
|
|
19623
19734
|
init_src2();
|
|
19624
|
-
DATASOURCE_PATH = (0,
|
|
19625
|
-
AUTOMATION_PATH = (0,
|
|
19735
|
+
DATASOURCE_PATH = (0, import_path10.join)(budibaseTempDir2(), "datasource");
|
|
19736
|
+
AUTOMATION_PATH = (0, import_path10.join)(budibaseTempDir2(), "automation");
|
|
19626
19737
|
getPluginMetadata = async (path2) => {
|
|
19627
19738
|
let metadata = {};
|
|
19628
19739
|
try {
|
|
19629
|
-
const pkg2 =
|
|
19630
|
-
const schema =
|
|
19740
|
+
const pkg2 = import_fs11.default.readFileSync((0, import_path10.join)(path2, "package.json"), "utf8");
|
|
19741
|
+
const schema = import_fs11.default.readFileSync((0, import_path10.join)(path2, "schema.json"), "utf8");
|
|
19631
19742
|
metadata.schema = JSON.parse(schema);
|
|
19632
19743
|
metadata.package = JSON.parse(pkg2);
|
|
19633
19744
|
if (!metadata.package.name || !metadata.package.version || !metadata.package.description) {
|
|
@@ -19698,13 +19809,14 @@ __export(exports_exports, {
|
|
|
19698
19809
|
streamExportApp: () => streamExportApp
|
|
19699
19810
|
});
|
|
19700
19811
|
function tarFilesToTmp(tmpDir, files) {
|
|
19701
|
-
const
|
|
19702
|
-
|
|
19812
|
+
const fileName = `${uuid3()}.tar.gz`;
|
|
19813
|
+
const exportFile = (0, import_path11.join)(budibaseTempDir2(), fileName);
|
|
19814
|
+
import_tar2.default.create(
|
|
19703
19815
|
{
|
|
19704
19816
|
sync: true,
|
|
19705
19817
|
gzip: true,
|
|
19706
19818
|
file: exportFile,
|
|
19707
|
-
|
|
19819
|
+
noDirRecurse: false,
|
|
19708
19820
|
cwd: tmpDir
|
|
19709
19821
|
},
|
|
19710
19822
|
files
|
|
@@ -19721,7 +19833,7 @@ async function exportDB(dbName, opts = {}) {
|
|
|
19721
19833
|
return db_exports.doWithDB(dbName, async (db2) => {
|
|
19722
19834
|
if (opts == null ? void 0 : opts.exportPath) {
|
|
19723
19835
|
const path2 = opts == null ? void 0 : opts.exportPath;
|
|
19724
|
-
const writeStream =
|
|
19836
|
+
const writeStream = import_fs12.default.createWriteStream(path2);
|
|
19725
19837
|
await db2.dump(writeStream, exportOpts);
|
|
19726
19838
|
return path2;
|
|
19727
19839
|
} else {
|
|
@@ -19754,9 +19866,9 @@ async function exportApp(appId, config) {
|
|
|
19754
19866
|
for (let path2 of STATIC_APP_FILES) {
|
|
19755
19867
|
const contents = await objectStore_exports2.retrieve(
|
|
19756
19868
|
ObjectStoreBuckets2.APPS,
|
|
19757
|
-
(0,
|
|
19869
|
+
(0, import_path11.join)(appPath, path2)
|
|
19758
19870
|
);
|
|
19759
|
-
|
|
19871
|
+
import_fs12.default.writeFileSync((0, import_path11.join)(tmpPath, path2), contents);
|
|
19760
19872
|
}
|
|
19761
19873
|
} else {
|
|
19762
19874
|
tmpPath = await objectStore_exports2.retrieveDirectory(
|
|
@@ -19765,37 +19877,52 @@ async function exportApp(appId, config) {
|
|
|
19765
19877
|
);
|
|
19766
19878
|
}
|
|
19767
19879
|
}
|
|
19768
|
-
const downloadedPath = (0,
|
|
19769
|
-
if (
|
|
19770
|
-
const allFiles =
|
|
19880
|
+
const downloadedPath = (0, import_path11.join)(tmpPath, appPath);
|
|
19881
|
+
if (import_fs12.default.existsSync(downloadedPath)) {
|
|
19882
|
+
const allFiles = import_fs12.default.readdirSync(downloadedPath);
|
|
19771
19883
|
for (let file of allFiles) {
|
|
19772
|
-
const path2 = (0,
|
|
19773
|
-
|
|
19884
|
+
const path2 = (0, import_path11.join)(downloadedPath, file);
|
|
19885
|
+
import_fs12.default.renameSync(path2, (0, import_path11.join)(downloadedPath, "..", file));
|
|
19774
19886
|
}
|
|
19775
|
-
|
|
19887
|
+
import_fs12.default.rmdirSync(downloadedPath);
|
|
19776
19888
|
}
|
|
19777
|
-
const dbPath = (0,
|
|
19889
|
+
const dbPath = (0, import_path11.join)(tmpPath, DB_EXPORT_FILE);
|
|
19778
19890
|
await exportDB(appId, {
|
|
19779
19891
|
filter: defineFilter(config == null ? void 0 : config.excludeRows, config == null ? void 0 : config.excludeLogs),
|
|
19780
19892
|
exportPath: dbPath
|
|
19781
19893
|
});
|
|
19894
|
+
if (config == null ? void 0 : config.encryptPassword) {
|
|
19895
|
+
for (let file of import_fs12.default.readdirSync(tmpPath)) {
|
|
19896
|
+
const path2 = (0, import_path11.join)(tmpPath, file);
|
|
19897
|
+
await encryption_exports.encryptFile(
|
|
19898
|
+
{ dir: tmpPath, filename: file },
|
|
19899
|
+
config.encryptPassword
|
|
19900
|
+
);
|
|
19901
|
+
import_fs12.default.rmSync(path2);
|
|
19902
|
+
}
|
|
19903
|
+
}
|
|
19782
19904
|
if (config == null ? void 0 : config.tar) {
|
|
19783
|
-
const tarPath = tarFilesToTmp(tmpPath,
|
|
19784
|
-
|
|
19905
|
+
const tarPath = tarFilesToTmp(tmpPath, import_fs12.default.readdirSync(tmpPath));
|
|
19906
|
+
import_fs12.default.rmSync(tmpPath, { recursive: true, force: true });
|
|
19785
19907
|
return tarPath;
|
|
19786
19908
|
} else {
|
|
19787
19909
|
return tmpPath;
|
|
19788
19910
|
}
|
|
19789
19911
|
}
|
|
19790
|
-
async function streamExportApp(
|
|
19912
|
+
async function streamExportApp({
|
|
19913
|
+
appId,
|
|
19914
|
+
excludeRows,
|
|
19915
|
+
encryptPassword
|
|
19916
|
+
}) {
|
|
19791
19917
|
const tmpPath = await exportApp(appId, {
|
|
19792
19918
|
excludeRows,
|
|
19793
19919
|
excludeLogs: true,
|
|
19794
|
-
tar: true
|
|
19920
|
+
tar: true,
|
|
19921
|
+
encryptPassword
|
|
19795
19922
|
});
|
|
19796
19923
|
return streamFile(tmpPath);
|
|
19797
19924
|
}
|
|
19798
|
-
var
|
|
19925
|
+
var import_fs12, import_path11, import_tar2, uuid3, MemoryStream2;
|
|
19799
19926
|
var init_exports2 = __esm({
|
|
19800
19927
|
"src/sdk/app/backups/exports.ts"() {
|
|
19801
19928
|
init_src2();
|
|
@@ -19804,11 +19931,11 @@ var init_exports2 = __esm({
|
|
|
19804
19931
|
init_constants6();
|
|
19805
19932
|
init_utils13();
|
|
19806
19933
|
init_constants7();
|
|
19807
|
-
|
|
19808
|
-
|
|
19934
|
+
import_fs12 = __toESM(require("fs"));
|
|
19935
|
+
import_path11 = require("path");
|
|
19809
19936
|
init_environment();
|
|
19937
|
+
import_tar2 = __toESM(require("tar"));
|
|
19810
19938
|
uuid3 = require("uuid/v4");
|
|
19811
|
-
tar3 = require("tar");
|
|
19812
19939
|
MemoryStream2 = require("memorystream");
|
|
19813
19940
|
}
|
|
19814
19941
|
});
|
|
@@ -19885,16 +20012,16 @@ async function getTemplateStream(template) {
|
|
|
19885
20012
|
throw new Error("Cannot import a non-text based file.");
|
|
19886
20013
|
}
|
|
19887
20014
|
if (template.file) {
|
|
19888
|
-
return
|
|
20015
|
+
return import_fs13.default.createReadStream(template.file.path);
|
|
19889
20016
|
} else if (template.key) {
|
|
19890
20017
|
const [type, name] = template.key.split("/");
|
|
19891
20018
|
const tmpPath = await downloadTemplate(type, name);
|
|
19892
|
-
return
|
|
20019
|
+
return import_fs13.default.createReadStream((0, import_path12.join)(tmpPath, name, "db", "dump.txt"));
|
|
19893
20020
|
}
|
|
19894
20021
|
}
|
|
19895
20022
|
function untarFile(file) {
|
|
19896
|
-
const tmpPath = (0,
|
|
19897
|
-
|
|
20023
|
+
const tmpPath = (0, import_path12.join)(budibaseTempDir2(), uuid4());
|
|
20024
|
+
import_fs13.default.mkdirSync(tmpPath);
|
|
19898
20025
|
tar4.extract({
|
|
19899
20026
|
sync: true,
|
|
19900
20027
|
cwd: tmpPath,
|
|
@@ -19902,31 +20029,49 @@ function untarFile(file) {
|
|
|
19902
20029
|
});
|
|
19903
20030
|
return tmpPath;
|
|
19904
20031
|
}
|
|
20032
|
+
async function decryptFiles(path2, password) {
|
|
20033
|
+
try {
|
|
20034
|
+
for (let file of import_fs13.default.readdirSync(path2)) {
|
|
20035
|
+
const inputPath = (0, import_path12.join)(path2, file);
|
|
20036
|
+
const outputPath = inputPath.replace(/\.enc$/, "");
|
|
20037
|
+
await encryption_exports.decryptFile(inputPath, outputPath, password);
|
|
20038
|
+
import_fs13.default.rmSync(inputPath);
|
|
20039
|
+
}
|
|
20040
|
+
} catch (err) {
|
|
20041
|
+
if (err.message === "incorrect header check") {
|
|
20042
|
+
throw new Error("File cannot be imported");
|
|
20043
|
+
}
|
|
20044
|
+
throw err;
|
|
20045
|
+
}
|
|
20046
|
+
}
|
|
19905
20047
|
function getGlobalDBFile(tmpPath) {
|
|
19906
|
-
return
|
|
20048
|
+
return import_fs13.default.readFileSync((0, import_path12.join)(tmpPath, GLOBAL_DB_EXPORT_FILE), "utf8");
|
|
19907
20049
|
}
|
|
19908
20050
|
function getListOfAppsInMulti(tmpPath) {
|
|
19909
|
-
return
|
|
20051
|
+
return import_fs13.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
|
|
19910
20052
|
}
|
|
19911
20053
|
async function importApp(appId, db2, template) {
|
|
19912
20054
|
var _a, _b;
|
|
19913
20055
|
let prodAppId = db_exports.getProdAppID(appId);
|
|
19914
20056
|
let dbStream;
|
|
19915
20057
|
const isTar = template.file && ((_b = (_a = template == null ? void 0 : template.file) == null ? void 0 : _a.type) == null ? void 0 : _b.endsWith("gzip"));
|
|
19916
|
-
const isDirectory = template.file &&
|
|
20058
|
+
const isDirectory = template.file && import_fs13.default.lstatSync(template.file.path).isDirectory();
|
|
19917
20059
|
if (template.file && (isTar || isDirectory)) {
|
|
19918
20060
|
const tmpPath = isTar ? untarFile(template.file) : template.file.path;
|
|
19919
|
-
|
|
20061
|
+
if (isTar && template.file.password) {
|
|
20062
|
+
await decryptFiles(tmpPath, template.file.password);
|
|
20063
|
+
}
|
|
20064
|
+
const contents = import_fs13.default.readdirSync(tmpPath);
|
|
19920
20065
|
if (contents.length) {
|
|
19921
20066
|
let promises = [];
|
|
19922
20067
|
let excludedFiles = [GLOBAL_DB_EXPORT_FILE, DB_EXPORT_FILE];
|
|
19923
20068
|
for (let filename of contents) {
|
|
19924
|
-
const path2 = (0,
|
|
20069
|
+
const path2 = (0, import_path12.join)(tmpPath, filename);
|
|
19925
20070
|
if (excludedFiles.includes(filename)) {
|
|
19926
20071
|
continue;
|
|
19927
20072
|
}
|
|
19928
|
-
filename = (0,
|
|
19929
|
-
if (
|
|
20073
|
+
filename = (0, import_path12.join)(prodAppId, filename);
|
|
20074
|
+
if (import_fs13.default.lstatSync(path2).isDirectory()) {
|
|
19930
20075
|
promises.push(
|
|
19931
20076
|
objectStore_exports2.uploadDirectory(ObjectStoreBuckets2.APPS, path2, filename)
|
|
19932
20077
|
);
|
|
@@ -19942,7 +20087,7 @@ async function importApp(appId, db2, template) {
|
|
|
19942
20087
|
}
|
|
19943
20088
|
await Promise.all(promises);
|
|
19944
20089
|
}
|
|
19945
|
-
dbStream =
|
|
20090
|
+
dbStream = import_fs13.default.createReadStream((0, import_path12.join)(tmpPath, DB_EXPORT_FILE));
|
|
19946
20091
|
} else {
|
|
19947
20092
|
dbStream = await getTemplateStream(template);
|
|
19948
20093
|
}
|
|
@@ -19954,7 +20099,7 @@ async function importApp(appId, db2, template) {
|
|
|
19954
20099
|
await updateAutomations(prodAppId, db2);
|
|
19955
20100
|
return ok;
|
|
19956
20101
|
}
|
|
19957
|
-
var
|
|
20102
|
+
var import_path12, import_fs13, uuid4, tar4;
|
|
19958
20103
|
var init_imports = __esm({
|
|
19959
20104
|
"src/sdk/app/backups/imports.ts"() {
|
|
19960
20105
|
init_src2();
|
|
@@ -19963,8 +20108,8 @@ var init_imports = __esm({
|
|
|
19963
20108
|
init_constants7();
|
|
19964
20109
|
init_fileSystem2();
|
|
19965
20110
|
init_constants6();
|
|
19966
|
-
|
|
19967
|
-
|
|
20111
|
+
import_path12 = require("path");
|
|
20112
|
+
import_fs13 = __toESM(require("fs"));
|
|
19968
20113
|
init_sdk3();
|
|
19969
20114
|
init_src();
|
|
19970
20115
|
uuid4 = require("uuid/v4");
|
|
@@ -21259,7 +21404,8 @@ var init_postgres = __esm({
|
|
|
21259
21404
|
try {
|
|
21260
21405
|
await this.openConnection();
|
|
21261
21406
|
const columnsResponse = await this.client.query(this.COLUMNS_SQL);
|
|
21262
|
-
|
|
21407
|
+
const names = columnsResponse.rows.map((row) => row.table_name);
|
|
21408
|
+
return [...new Set(names)];
|
|
21263
21409
|
} finally {
|
|
21264
21410
|
await this.closeConnection();
|
|
21265
21411
|
}
|
|
@@ -21888,6 +22034,8 @@ var init_mongodb = __esm({
|
|
|
21888
22034
|
response2.connected = true;
|
|
21889
22035
|
} catch (e) {
|
|
21890
22036
|
response2.error = e.message;
|
|
22037
|
+
} finally {
|
|
22038
|
+
await this.client.close();
|
|
21891
22039
|
}
|
|
21892
22040
|
return response2;
|
|
21893
22041
|
}
|
|
@@ -23814,6 +23962,16 @@ var init_rest = __esm({
|
|
|
23814
23962
|
});
|
|
23815
23963
|
|
|
23816
23964
|
// src/integrations/googlesheets.ts
|
|
23965
|
+
async function setupCreationAuth(datasouce) {
|
|
23966
|
+
if (datasouce.continueSetupId) {
|
|
23967
|
+
const appId = context_exports.getAppId();
|
|
23968
|
+
const tokens = await cache_exports.get(
|
|
23969
|
+
`datasource:creation:${appId}:google:${datasouce.continueSetupId}`
|
|
23970
|
+
);
|
|
23971
|
+
datasouce.auth = tokens.tokens;
|
|
23972
|
+
delete datasouce.continueSetupId;
|
|
23973
|
+
}
|
|
23974
|
+
}
|
|
23817
23975
|
var import_google_auth_library, import_google_spreadsheet, import_node_fetch9, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
|
|
23818
23976
|
var init_googlesheets = __esm({
|
|
23819
23977
|
"src/integrations/googlesheets.ts"() {
|
|
@@ -23851,7 +24009,7 @@ var init_googlesheets = __esm({
|
|
|
23851
24009
|
},
|
|
23852
24010
|
datasource: {
|
|
23853
24011
|
spreadsheetId: {
|
|
23854
|
-
display: "
|
|
24012
|
+
display: "Spreadsheet URL",
|
|
23855
24013
|
type: "string" /* STRING */,
|
|
23856
24014
|
required: true
|
|
23857
24015
|
}
|
|
@@ -23972,6 +24130,7 @@ var init_googlesheets = __esm({
|
|
|
23972
24130
|
async connect() {
|
|
23973
24131
|
var _a;
|
|
23974
24132
|
try {
|
|
24133
|
+
await setupCreationAuth(this.config);
|
|
23975
24134
|
let googleConfig = await configs_exports.getGoogleDatasourceConfig();
|
|
23976
24135
|
if (!googleConfig) {
|
|
23977
24136
|
throw new HTTPError("Google config not found", 400);
|
|
@@ -24022,21 +24181,22 @@ var init_googlesheets = __esm({
|
|
|
24022
24181
|
return table;
|
|
24023
24182
|
}
|
|
24024
24183
|
async buildSchema(datasourceId, entities) {
|
|
24025
|
-
if (!this.config.auth) {
|
|
24026
|
-
return;
|
|
24027
|
-
}
|
|
24028
24184
|
await this.connect();
|
|
24029
24185
|
const sheets = this.client.sheetsByIndex;
|
|
24030
24186
|
const tables = {};
|
|
24031
|
-
|
|
24032
|
-
|
|
24033
|
-
|
|
24034
|
-
|
|
24035
|
-
sheet.title
|
|
24036
|
-
sheet.
|
|
24037
|
-
|
|
24038
|
-
|
|
24039
|
-
|
|
24187
|
+
await utils_exports5.parallelForeach(
|
|
24188
|
+
sheets,
|
|
24189
|
+
async (sheet) => {
|
|
24190
|
+
await sheet.getRows({ limit: 0, offset: 0 });
|
|
24191
|
+
const id = buildExternalTableId(datasourceId, sheet.title);
|
|
24192
|
+
tables[sheet.title] = this.getTableSchema(
|
|
24193
|
+
sheet.title,
|
|
24194
|
+
sheet.headerValues,
|
|
24195
|
+
id
|
|
24196
|
+
);
|
|
24197
|
+
},
|
|
24198
|
+
10
|
|
24199
|
+
);
|
|
24040
24200
|
const final = finaliseExternalTables(tables, entities);
|
|
24041
24201
|
this.tables = final.tables;
|
|
24042
24202
|
this.schemaErrors = final.errors;
|
|
@@ -26892,22 +27052,22 @@ function threadSetup() {
|
|
|
26892
27052
|
init8();
|
|
26893
27053
|
}
|
|
26894
27054
|
async function checkCacheForDynamicVariable(queryId, variable) {
|
|
26895
|
-
const
|
|
26896
|
-
return
|
|
27055
|
+
const cache3 = await getClient2();
|
|
27056
|
+
return cache3.get(makeVariableKey(queryId, variable));
|
|
26897
27057
|
}
|
|
26898
27058
|
async function invalidateDynamicVariables(cachedVars) {
|
|
26899
|
-
const
|
|
27059
|
+
const cache3 = await getClient2();
|
|
26900
27060
|
let promises = [];
|
|
26901
27061
|
for (let variable of cachedVars) {
|
|
26902
27062
|
promises.push(
|
|
26903
|
-
|
|
27063
|
+
cache3.delete(makeVariableKey(variable.queryId, variable.name))
|
|
26904
27064
|
);
|
|
26905
27065
|
}
|
|
26906
27066
|
await Promise.all(promises);
|
|
26907
27067
|
}
|
|
26908
27068
|
async function storeDynamicVariable(queryId, variable, value) {
|
|
26909
|
-
const
|
|
26910
|
-
await
|
|
27069
|
+
const cache3 = await getClient2();
|
|
27070
|
+
await cache3.store(
|
|
26911
27071
|
makeVariableKey(queryId, variable),
|
|
26912
27072
|
value,
|
|
26913
27073
|
VARIABLE_TTL_SECONDS
|
|
@@ -27375,7 +27535,16 @@ async function checkResponse(response2, errorMsg, { ctx } = {}) {
|
|
|
27375
27535
|
}
|
|
27376
27536
|
return response2.json();
|
|
27377
27537
|
}
|
|
27378
|
-
async function sendSmtpEmail(
|
|
27538
|
+
async function sendSmtpEmail({
|
|
27539
|
+
to,
|
|
27540
|
+
from,
|
|
27541
|
+
subject,
|
|
27542
|
+
contents,
|
|
27543
|
+
cc,
|
|
27544
|
+
bcc,
|
|
27545
|
+
automation,
|
|
27546
|
+
invite
|
|
27547
|
+
}) {
|
|
27379
27548
|
const response2 = await (0, import_node_fetch10.default)(
|
|
27380
27549
|
checkSlashesInUrl2(environment_default.WORKER_URL + `/api/global/email/send`),
|
|
27381
27550
|
request(void 0, {
|
|
@@ -27388,7 +27557,8 @@ async function sendSmtpEmail(to, from, subject, contents, cc, bcc, automation) {
|
|
|
27388
27557
|
cc,
|
|
27389
27558
|
bcc,
|
|
27390
27559
|
purpose: "custom",
|
|
27391
|
-
automation
|
|
27560
|
+
automation,
|
|
27561
|
+
invite
|
|
27392
27562
|
}
|
|
27393
27563
|
})
|
|
27394
27564
|
);
|
|
@@ -27436,6 +27606,35 @@ var definition7 = {
|
|
|
27436
27606
|
contents: {
|
|
27437
27607
|
type: "string" /* STRING */,
|
|
27438
27608
|
title: "HTML Contents"
|
|
27609
|
+
},
|
|
27610
|
+
addInvite: {
|
|
27611
|
+
type: "boolean" /* BOOLEAN */,
|
|
27612
|
+
title: "Add calendar invite"
|
|
27613
|
+
},
|
|
27614
|
+
startTime: {
|
|
27615
|
+
type: "date" /* DATE */,
|
|
27616
|
+
title: "Start Time",
|
|
27617
|
+
dependsOn: "addInvite"
|
|
27618
|
+
},
|
|
27619
|
+
endTime: {
|
|
27620
|
+
type: "date" /* DATE */,
|
|
27621
|
+
title: "End Time",
|
|
27622
|
+
dependsOn: "addInvite"
|
|
27623
|
+
},
|
|
27624
|
+
summary: {
|
|
27625
|
+
type: "string" /* STRING */,
|
|
27626
|
+
title: "Meeting Summary",
|
|
27627
|
+
dependsOn: "addInvite"
|
|
27628
|
+
},
|
|
27629
|
+
location: {
|
|
27630
|
+
type: "string" /* STRING */,
|
|
27631
|
+
title: "Location",
|
|
27632
|
+
dependsOn: "addInvite"
|
|
27633
|
+
},
|
|
27634
|
+
url: {
|
|
27635
|
+
type: "string" /* STRING */,
|
|
27636
|
+
title: "URL",
|
|
27637
|
+
dependsOn: "addInvite"
|
|
27439
27638
|
}
|
|
27440
27639
|
},
|
|
27441
27640
|
required: ["to", "from", "subject", "contents"]
|
|
@@ -27456,21 +27655,41 @@ var definition7 = {
|
|
|
27456
27655
|
}
|
|
27457
27656
|
};
|
|
27458
27657
|
async function run3({ inputs }) {
|
|
27459
|
-
let {
|
|
27658
|
+
let {
|
|
27659
|
+
to,
|
|
27660
|
+
from,
|
|
27661
|
+
subject,
|
|
27662
|
+
contents,
|
|
27663
|
+
cc,
|
|
27664
|
+
bcc,
|
|
27665
|
+
addInvite,
|
|
27666
|
+
startTime,
|
|
27667
|
+
endTime,
|
|
27668
|
+
summary,
|
|
27669
|
+
location,
|
|
27670
|
+
url
|
|
27671
|
+
} = inputs;
|
|
27460
27672
|
if (!contents) {
|
|
27461
27673
|
contents = "<h1>No content</h1>";
|
|
27462
27674
|
}
|
|
27463
27675
|
to = to || void 0;
|
|
27464
27676
|
try {
|
|
27465
|
-
let response2 = await sendSmtpEmail(
|
|
27677
|
+
let response2 = await sendSmtpEmail({
|
|
27466
27678
|
to,
|
|
27467
27679
|
from,
|
|
27468
27680
|
subject,
|
|
27469
27681
|
contents,
|
|
27470
27682
|
cc,
|
|
27471
27683
|
bcc,
|
|
27472
|
-
true
|
|
27473
|
-
|
|
27684
|
+
automation: true,
|
|
27685
|
+
invite: addInvite ? {
|
|
27686
|
+
startTime,
|
|
27687
|
+
endTime,
|
|
27688
|
+
summary,
|
|
27689
|
+
location,
|
|
27690
|
+
url
|
|
27691
|
+
} : void 0
|
|
27692
|
+
});
|
|
27474
27693
|
return {
|
|
27475
27694
|
success: true,
|
|
27476
27695
|
response: response2
|
|
@@ -30691,8 +30910,15 @@ init_constants6();
|
|
|
30691
30910
|
init_integrations2();
|
|
30692
30911
|
init_utils20();
|
|
30693
30912
|
init_src2();
|
|
30913
|
+
init_src();
|
|
30694
30914
|
init_sdk3();
|
|
30695
30915
|
init_websockets();
|
|
30916
|
+
init_googlesheets();
|
|
30917
|
+
var preSaveAction = {
|
|
30918
|
+
["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
|
|
30919
|
+
await setupCreationAuth(datasource2.config);
|
|
30920
|
+
}
|
|
30921
|
+
};
|
|
30696
30922
|
|
|
30697
30923
|
// src/api/controllers/query/validation.ts
|
|
30698
30924
|
init_src2();
|