@budibase/server 2.7.20-alpha.0 → 2.7.20
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.6b48215f.js → index.1066b334.js} +371 -371
- package/builder/assets/{index.2e9069f3.css → index.d9b46807.css} +1 -1
- package/builder/index.html +2 -2
- package/dist/automation.js +179 -405
- package/dist/automation.js.map +3 -3
- package/dist/index.js +284 -517
- package/dist/index.js.map +3 -3
- package/dist/query.js +141 -301
- package/dist/query.js.map +3 -3
- package/package.json +11 -11
- package/src/api/controllers/application.ts +24 -21
- package/src/api/controllers/backup.ts +8 -22
- package/src/api/controllers/datasource.ts +24 -41
- 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 +2 -18
- package/src/automations/steps/sendSmtpEmail.ts +4 -55
- package/src/automations/tests/sendSmtpEmail.spec.js +71 -0
- package/src/events/docUpdates/syncUsers.ts +0 -4
- package/src/integrations/googlesheets.ts +18 -35
- package/src/integrations/mongodb.ts +2 -4
- package/src/integrations/postgres.ts +1 -2
- package/src/middleware/currentapp.ts +1 -1
- package/src/sdk/app/backups/exports.ts +5 -33
- package/src/sdk/app/backups/imports.ts +1 -21
- package/src/sdk/app/datasources/datasources.ts +0 -1
- package/src/utilities/workerRequests.ts +9 -20
- package/src/automations/tests/sendSmtpEmail.spec.ts +0 -74
package/dist/automation.js
CHANGED
|
@@ -946,7 +946,6 @@ var init_automation2 = __esm({
|
|
|
946
946
|
AutomationIOType2["NUMBER"] = "number";
|
|
947
947
|
AutomationIOType2["ARRAY"] = "array";
|
|
948
948
|
AutomationIOType2["JSON"] = "json";
|
|
949
|
-
AutomationIOType2["DATE"] = "date";
|
|
950
949
|
return AutomationIOType2;
|
|
951
950
|
})(AutomationIOType || {});
|
|
952
951
|
AutomationCustomIOType = /* @__PURE__ */ ((AutomationCustomIOType2) => {
|
|
@@ -5361,11 +5360,11 @@ function makeCacheItem(doc2, lastWrite = null) {
|
|
|
5361
5360
|
return { doc: doc2, lastWrite: lastWrite || Date.now() };
|
|
5362
5361
|
}
|
|
5363
5362
|
async function put(db2, doc2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
5364
|
-
const
|
|
5363
|
+
const cache2 = await getCache();
|
|
5365
5364
|
const key = doc2._id;
|
|
5366
5365
|
let cacheItem;
|
|
5367
5366
|
if (key) {
|
|
5368
|
-
cacheItem = await
|
|
5367
|
+
cacheItem = await cache2.get(makeCacheKey(db2, key));
|
|
5369
5368
|
}
|
|
5370
5369
|
const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
|
|
5371
5370
|
let output = doc2;
|
|
@@ -5403,30 +5402,30 @@ async function put(db2, doc2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
5403
5402
|
}
|
|
5404
5403
|
cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
|
|
5405
5404
|
if (output._id) {
|
|
5406
|
-
await
|
|
5405
|
+
await cache2.store(makeCacheKey(db2, output._id), cacheItem);
|
|
5407
5406
|
}
|
|
5408
5407
|
return { ok: true, id: output._id, rev: output._rev };
|
|
5409
5408
|
}
|
|
5410
5409
|
async function get2(db2, id) {
|
|
5411
|
-
const
|
|
5410
|
+
const cache2 = await getCache();
|
|
5412
5411
|
const cacheKey = makeCacheKey(db2, id);
|
|
5413
|
-
let cacheItem = await
|
|
5412
|
+
let cacheItem = await cache2.get(cacheKey);
|
|
5414
5413
|
if (!cacheItem) {
|
|
5415
5414
|
const doc2 = await db2.get(id);
|
|
5416
5415
|
cacheItem = makeCacheItem(doc2);
|
|
5417
|
-
await
|
|
5416
|
+
await cache2.store(cacheKey, cacheItem);
|
|
5418
5417
|
}
|
|
5419
5418
|
return cacheItem.doc;
|
|
5420
5419
|
}
|
|
5421
5420
|
async function remove(db2, docOrId, rev2) {
|
|
5422
|
-
const
|
|
5421
|
+
const cache2 = await getCache();
|
|
5423
5422
|
if (!docOrId) {
|
|
5424
5423
|
throw new Error("No ID/Rev provided.");
|
|
5425
5424
|
}
|
|
5426
5425
|
const id = typeof docOrId === "string" ? docOrId : docOrId._id;
|
|
5427
5426
|
rev2 = typeof docOrId === "string" ? rev2 : docOrId._rev;
|
|
5428
5427
|
try {
|
|
5429
|
-
await
|
|
5428
|
+
await cache2.delete(makeCacheKey(db2, id));
|
|
5430
5429
|
} finally {
|
|
5431
5430
|
await db2.remove(id, rev2);
|
|
5432
5431
|
}
|
|
@@ -9029,7 +9028,7 @@ function lowerBuiltinRoleID(roleId1, roleId2) {
|
|
|
9029
9028
|
}
|
|
9030
9029
|
return builtinRoleToNumber(roleId1) > builtinRoleToNumber(roleId2) ? roleId2 : roleId1;
|
|
9031
9030
|
}
|
|
9032
|
-
async function getRole(roleId
|
|
9031
|
+
async function getRole(roleId) {
|
|
9033
9032
|
if (!roleId) {
|
|
9034
9033
|
return void 0;
|
|
9035
9034
|
}
|
|
@@ -9045,9 +9044,6 @@ async function getRole(roleId, opts) {
|
|
|
9045
9044
|
role = Object.assign(role, dbRole);
|
|
9046
9045
|
role._id = getExternalRoleID(role._id);
|
|
9047
9046
|
} catch (err) {
|
|
9048
|
-
if (!isBuiltin(roleId) && (opts == null ? void 0 : opts.defaultPublic)) {
|
|
9049
|
-
return cloneDeep2(BUILTIN_ROLES.PUBLIC);
|
|
9050
|
-
}
|
|
9051
9047
|
if (Object.keys(role).length === 0) {
|
|
9052
9048
|
throw err;
|
|
9053
9049
|
}
|
|
@@ -9788,8 +9784,8 @@ async function preAuth(passport2, ctx, next) {
|
|
|
9788
9784
|
callbackUrl,
|
|
9789
9785
|
ssoSaveUserNoOp
|
|
9790
9786
|
);
|
|
9791
|
-
if (!ctx.query.appId) {
|
|
9792
|
-
ctx.throw(400, "appId query
|
|
9787
|
+
if (!ctx.query.appId || !ctx.query.datasourceId) {
|
|
9788
|
+
ctx.throw(400, "appId and datasourceId query params not present.");
|
|
9793
9789
|
}
|
|
9794
9790
|
return passport2.authenticate(strategy, {
|
|
9795
9791
|
scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
|
|
@@ -9809,7 +9805,7 @@ async function postAuth(passport2, ctx, next) {
|
|
|
9809
9805
|
clientSecret: config.clientSecret,
|
|
9810
9806
|
callbackURL: callbackUrl
|
|
9811
9807
|
},
|
|
9812
|
-
(accessToken, refreshToken,
|
|
9808
|
+
(accessToken, refreshToken, profile, done) => {
|
|
9813
9809
|
clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
|
|
9814
9810
|
done(null, { accessToken, refreshToken });
|
|
9815
9811
|
}
|
|
@@ -9817,14 +9813,22 @@ async function postAuth(passport2, ctx, next) {
|
|
|
9817
9813
|
{ successRedirect: "/", failureRedirect: "/error" },
|
|
9818
9814
|
async (err, tokens) => {
|
|
9819
9815
|
const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9816
|
+
await doWithDB(authStateCookie.appId, async (db2) => {
|
|
9817
|
+
let datasource2;
|
|
9818
|
+
try {
|
|
9819
|
+
datasource2 = await db2.get(authStateCookie.datasourceId);
|
|
9820
|
+
} catch (err2) {
|
|
9821
|
+
if (err2.status === 404) {
|
|
9822
|
+
ctx.redirect(baseUrl);
|
|
9823
|
+
}
|
|
9825
9824
|
}
|
|
9826
|
-
|
|
9827
|
-
|
|
9825
|
+
if (!datasource2.config) {
|
|
9826
|
+
datasource2.config = {};
|
|
9827
|
+
}
|
|
9828
|
+
datasource2.config.auth = { type: "google", ...tokens };
|
|
9829
|
+
await db2.put(datasource2);
|
|
9830
|
+
ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
|
|
9831
|
+
});
|
|
9828
9832
|
}
|
|
9829
9833
|
)(ctx, next);
|
|
9830
9834
|
}
|
|
@@ -9833,9 +9837,9 @@ var init_google2 = __esm({
|
|
|
9833
9837
|
"../backend-core/src/middleware/passport/datasource/google.ts"() {
|
|
9834
9838
|
init_google();
|
|
9835
9839
|
init_constants2();
|
|
9836
|
-
init_configs3();
|
|
9837
|
-
init_cache();
|
|
9838
9840
|
init_utils5();
|
|
9841
|
+
init_db5();
|
|
9842
|
+
init_configs3();
|
|
9839
9843
|
init_sso2();
|
|
9840
9844
|
GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
|
|
9841
9845
|
}
|
|
@@ -9885,9 +9889,7 @@ var encryption_exports = {};
|
|
|
9885
9889
|
__export(encryption_exports, {
|
|
9886
9890
|
SecretOption: () => SecretOption,
|
|
9887
9891
|
decrypt: () => decrypt,
|
|
9888
|
-
decryptFile: () => decryptFile,
|
|
9889
9892
|
encrypt: () => encrypt,
|
|
9890
|
-
encryptFile: () => encryptFile,
|
|
9891
9893
|
getSecret: () => getSecret
|
|
9892
9894
|
});
|
|
9893
9895
|
function getSecret(secretOption) {
|
|
@@ -9908,11 +9910,11 @@ function getSecret(secretOption) {
|
|
|
9908
9910
|
}
|
|
9909
9911
|
return secret;
|
|
9910
9912
|
}
|
|
9911
|
-
function stretchString(
|
|
9912
|
-
return import_crypto.default.pbkdf2Sync(
|
|
9913
|
+
function stretchString(string, salt) {
|
|
9914
|
+
return import_crypto.default.pbkdf2Sync(string, salt, ITERATIONS, STRETCH_LENGTH, "sha512");
|
|
9913
9915
|
}
|
|
9914
9916
|
function encrypt(input, secretOption = "api" /* API */) {
|
|
9915
|
-
const salt = import_crypto.default.randomBytes(
|
|
9917
|
+
const salt = import_crypto.default.randomBytes(RANDOM_BYTES);
|
|
9916
9918
|
const stretched = stretchString(getSecret(secretOption), salt);
|
|
9917
9919
|
const cipher = import_crypto.default.createCipheriv(ALGO, stretched, salt);
|
|
9918
9920
|
const base = cipher.update(input);
|
|
@@ -9929,101 +9931,16 @@ function decrypt(input, secretOption = "api" /* API */) {
|
|
|
9929
9931
|
const final = decipher.final();
|
|
9930
9932
|
return Buffer.concat([base, final]).toString();
|
|
9931
9933
|
}
|
|
9932
|
-
|
|
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;
|
|
9934
|
+
var import_crypto, ALGO, SEPARATOR3, ITERATIONS, RANDOM_BYTES, STRETCH_LENGTH, SecretOption;
|
|
10014
9935
|
var init_encryption = __esm({
|
|
10015
9936
|
"../backend-core/src/security/encryption.ts"() {
|
|
10016
9937
|
import_crypto = __toESM(require("crypto"));
|
|
10017
|
-
import_fs2 = __toESM(require("fs"));
|
|
10018
|
-
import_zlib = __toESM(require("zlib"));
|
|
10019
9938
|
init_environment3();
|
|
10020
|
-
import_path2 = require("path");
|
|
10021
9939
|
ALGO = "aes-256-ctr";
|
|
10022
9940
|
SEPARATOR3 = "-";
|
|
10023
9941
|
ITERATIONS = 1e4;
|
|
9942
|
+
RANDOM_BYTES = 16;
|
|
10024
9943
|
STRETCH_LENGTH = 32;
|
|
10025
|
-
SALT_LENGTH = 16;
|
|
10026
|
-
IV_LENGTH = 16;
|
|
10027
9944
|
SecretOption = /* @__PURE__ */ ((SecretOption2) => {
|
|
10028
9945
|
SecretOption2["API"] = "api";
|
|
10029
9946
|
SecretOption2["ENCRYPTION"] = "encryption";
|
|
@@ -10934,12 +10851,12 @@ var init_plugin4 = __esm({
|
|
|
10934
10851
|
function budibaseTempDir() {
|
|
10935
10852
|
return bbTmp;
|
|
10936
10853
|
}
|
|
10937
|
-
var
|
|
10854
|
+
var import_path2, import_os, import_fs2, ObjectStoreBuckets, bbTmp;
|
|
10938
10855
|
var init_utils8 = __esm({
|
|
10939
10856
|
"../backend-core/src/objectStore/utils.ts"() {
|
|
10940
|
-
|
|
10857
|
+
import_path2 = require("path");
|
|
10941
10858
|
import_os = require("os");
|
|
10942
|
-
|
|
10859
|
+
import_fs2 = __toESM(require("fs"));
|
|
10943
10860
|
init_environment3();
|
|
10944
10861
|
ObjectStoreBuckets = {
|
|
10945
10862
|
BACKUPS: environment_default2.BACKUPS_BUCKET_NAME,
|
|
@@ -10948,9 +10865,9 @@ var init_utils8 = __esm({
|
|
|
10948
10865
|
GLOBAL: environment_default2.GLOBAL_BUCKET_NAME,
|
|
10949
10866
|
PLUGINS: environment_default2.PLUGIN_BUCKET_NAME
|
|
10950
10867
|
};
|
|
10951
|
-
bbTmp = (0,
|
|
10952
|
-
if (!
|
|
10953
|
-
|
|
10868
|
+
bbTmp = (0, import_path2.join)((0, import_os.tmpdir)(), ".budibase");
|
|
10869
|
+
if (!import_fs2.default.existsSync(bbTmp)) {
|
|
10870
|
+
import_fs2.default.mkdirSync(bbTmp);
|
|
10954
10871
|
}
|
|
10955
10872
|
}
|
|
10956
10873
|
});
|
|
@@ -10962,17 +10879,17 @@ function sanitizeKey(input) {
|
|
|
10962
10879
|
function sanitizeBucket(input) {
|
|
10963
10880
|
return input.replace(new RegExp(APP_DEV_PREFIX, "g"), APP_PREFIX);
|
|
10964
10881
|
}
|
|
10965
|
-
var import_aws_sdk, import_stream, import_node_fetch6, import_tar_fs,
|
|
10882
|
+
var import_aws_sdk, import_stream, import_node_fetch6, import_tar_fs, import_zlib, import_util, import_path3, 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;
|
|
10966
10883
|
var init_objectStore = __esm({
|
|
10967
10884
|
"../backend-core/src/objectStore/objectStore.ts"() {
|
|
10968
10885
|
import_aws_sdk = __toESM(require("aws-sdk"));
|
|
10969
10886
|
import_stream = __toESM(require("stream"));
|
|
10970
10887
|
import_node_fetch6 = __toESM(require("node-fetch"));
|
|
10971
10888
|
import_tar_fs = __toESM(require("tar-fs"));
|
|
10972
|
-
|
|
10889
|
+
import_zlib = __toESM(require("zlib"));
|
|
10973
10890
|
import_util = require("util");
|
|
10974
|
-
|
|
10975
|
-
|
|
10891
|
+
import_path3 = require("path");
|
|
10892
|
+
import_fs3 = __toESM(require("fs"));
|
|
10976
10893
|
init_environment3();
|
|
10977
10894
|
init_utils8();
|
|
10978
10895
|
import_uuid3 = require("uuid");
|
|
@@ -11051,7 +10968,7 @@ var init_objectStore = __esm({
|
|
|
11051
10968
|
metadata: metadata2
|
|
11052
10969
|
}) => {
|
|
11053
10970
|
const extension = filename.split(".").pop();
|
|
11054
|
-
const fileBytes =
|
|
10971
|
+
const fileBytes = import_fs3.default.readFileSync(path2);
|
|
11055
10972
|
const objectStore = ObjectStore(bucketName);
|
|
11056
10973
|
await makeSureBucketExists(objectStore, bucketName);
|
|
11057
10974
|
let contentType = type;
|
|
@@ -11153,13 +11070,13 @@ var init_objectStore = __esm({
|
|
|
11153
11070
|
bucketName = sanitizeBucket(bucketName);
|
|
11154
11071
|
filepath = sanitizeKey(filepath);
|
|
11155
11072
|
const data2 = await retrieve(bucketName, filepath);
|
|
11156
|
-
const outputPath = (0,
|
|
11157
|
-
|
|
11073
|
+
const outputPath = (0, import_path3.join)(budibaseTempDir(), (0, import_uuid3.v4)());
|
|
11074
|
+
import_fs3.default.writeFileSync(outputPath, data2);
|
|
11158
11075
|
return outputPath;
|
|
11159
11076
|
};
|
|
11160
11077
|
retrieveDirectory = async (bucketName, path2) => {
|
|
11161
|
-
let writePath = (0,
|
|
11162
|
-
|
|
11078
|
+
let writePath = (0, import_path3.join)(budibaseTempDir(), (0, import_uuid3.v4)());
|
|
11079
|
+
import_fs3.default.mkdirSync(writePath);
|
|
11163
11080
|
const objects = await listAllObjects(bucketName, path2);
|
|
11164
11081
|
let fullObjects = await Promise.all(
|
|
11165
11082
|
objects.map((obj) => retrieve(bucketName, obj.Key))
|
|
@@ -11171,9 +11088,9 @@ var init_objectStore = __esm({
|
|
|
11171
11088
|
const possiblePath = filename.split("/");
|
|
11172
11089
|
if (possiblePath.length > 1) {
|
|
11173
11090
|
const dirs = possiblePath.slice(0, possiblePath.length - 1);
|
|
11174
|
-
|
|
11091
|
+
import_fs3.default.mkdirSync((0, import_path3.join)(writePath, ...dirs), { recursive: true });
|
|
11175
11092
|
}
|
|
11176
|
-
|
|
11093
|
+
import_fs3.default.writeFileSync((0, import_path3.join)(writePath, ...possiblePath), data2);
|
|
11177
11094
|
}
|
|
11178
11095
|
return writePath;
|
|
11179
11096
|
};
|
|
@@ -11227,14 +11144,14 @@ var init_objectStore = __esm({
|
|
|
11227
11144
|
uploadDirectory = async (bucketName, localPath, bucketPath2) => {
|
|
11228
11145
|
bucketName = sanitizeBucket(bucketName);
|
|
11229
11146
|
let uploads = [];
|
|
11230
|
-
const files2 =
|
|
11147
|
+
const files2 = import_fs3.default.readdirSync(localPath, { withFileTypes: true });
|
|
11231
11148
|
for (let file of files2) {
|
|
11232
|
-
const path2 = sanitizeKey((0,
|
|
11233
|
-
const local = (0,
|
|
11149
|
+
const path2 = sanitizeKey((0, import_path3.join)(bucketPath2, file.name));
|
|
11150
|
+
const local = (0, import_path3.join)(localPath, file.name);
|
|
11234
11151
|
if (file.isDirectory()) {
|
|
11235
11152
|
uploads.push(uploadDirectory(bucketName, local, path2));
|
|
11236
11153
|
} else {
|
|
11237
|
-
uploads.push(streamUpload(bucketName, path2,
|
|
11154
|
+
uploads.push(streamUpload(bucketName, path2, import_fs3.default.createReadStream(local)));
|
|
11238
11155
|
}
|
|
11239
11156
|
}
|
|
11240
11157
|
await Promise.all(uploads);
|
|
@@ -11246,7 +11163,7 @@ var init_objectStore = __esm({
|
|
|
11246
11163
|
if (!response2.ok) {
|
|
11247
11164
|
throw new Error(`unexpected response ${response2.statusText}`);
|
|
11248
11165
|
}
|
|
11249
|
-
await streamPipeline(response2.body,
|
|
11166
|
+
await streamPipeline(response2.body, import_zlib.default.createUnzip(), import_tar_fs.default.extract(path2));
|
|
11250
11167
|
};
|
|
11251
11168
|
downloadTarball = async (url, bucketName, path2) => {
|
|
11252
11169
|
bucketName = sanitizeBucket(bucketName);
|
|
@@ -11255,8 +11172,8 @@ var init_objectStore = __esm({
|
|
|
11255
11172
|
if (!response2.ok) {
|
|
11256
11173
|
throw new Error(`unexpected response ${response2.statusText}`);
|
|
11257
11174
|
}
|
|
11258
|
-
const tmpPath = (0,
|
|
11259
|
-
await streamPipeline(response2.body,
|
|
11175
|
+
const tmpPath = (0, import_path3.join)(budibaseTempDir(), path2);
|
|
11176
|
+
await streamPipeline(response2.body, import_zlib.default.createUnzip(), import_tar_fs.default.extract(tmpPath));
|
|
11260
11177
|
if (!environment_default2.isTest() && environment_default2.SELF_HOSTED) {
|
|
11261
11178
|
await uploadDirectory(bucketName, tmpPath, path2);
|
|
11262
11179
|
}
|
|
@@ -12709,21 +12626,21 @@ __export(version_exports, {
|
|
|
12709
12626
|
getLicenseVersion: () => getLicenseVersion,
|
|
12710
12627
|
getProVersion: () => getProVersion
|
|
12711
12628
|
});
|
|
12712
|
-
var
|
|
12629
|
+
var import_fs4, import_path4, getLicenseVersion, getProVersion;
|
|
12713
12630
|
var init_version2 = __esm({
|
|
12714
12631
|
"../pro/packages/pro/src/constants/version.ts"() {
|
|
12715
12632
|
init_src2();
|
|
12716
|
-
|
|
12717
|
-
|
|
12633
|
+
import_fs4 = __toESM(require("fs"));
|
|
12634
|
+
import_path4 = __toESM(require("path"));
|
|
12718
12635
|
getLicenseVersion = () => {
|
|
12719
12636
|
if (environment_default2.isDev()) {
|
|
12720
12637
|
const DEV_VER_FILENAME = "dev-version.txt";
|
|
12721
|
-
const verFile =
|
|
12722
|
-
if (
|
|
12723
|
-
return
|
|
12638
|
+
const verFile = import_path4.default.join(objectStore_exports2.budibaseTempDir(), DEV_VER_FILENAME);
|
|
12639
|
+
if (import_fs4.default.existsSync(verFile)) {
|
|
12640
|
+
return import_fs4.default.readFileSync(verFile, "utf8");
|
|
12724
12641
|
} else {
|
|
12725
12642
|
const devVer = utils_exports2.newid();
|
|
12726
|
-
|
|
12643
|
+
import_fs4.default.writeFileSync(verFile, devVer);
|
|
12727
12644
|
return devVer;
|
|
12728
12645
|
}
|
|
12729
12646
|
} else {
|
|
@@ -13169,31 +13086,31 @@ function getOfflineLicense() {
|
|
|
13169
13086
|
}
|
|
13170
13087
|
}
|
|
13171
13088
|
function getOfflineLicenseFromDisk() {
|
|
13172
|
-
if (
|
|
13173
|
-
const token =
|
|
13089
|
+
if (import_fs5.default.existsSync(LICENSE_FILE_PATH)) {
|
|
13090
|
+
const token = import_fs5.default.readFileSync(LICENSE_FILE_PATH, { encoding: "utf-8" });
|
|
13174
13091
|
return import_jsonwebtoken.default.verify(token, PUBLIC_KEY, { algorithms: ["RS256"] });
|
|
13175
13092
|
}
|
|
13176
13093
|
}
|
|
13177
13094
|
function writeOfflineLicenseToDisk(signedLicense) {
|
|
13178
|
-
|
|
13095
|
+
import_fs5.default.writeFileSync(LICENSE_FILE_PATH, signedLicense, { encoding: "utf-8" });
|
|
13179
13096
|
}
|
|
13180
13097
|
function deleteOfflineLicense() {
|
|
13181
|
-
|
|
13098
|
+
import_fs5.default.rmSync(LICENSE_FILE_PATH, { force: true });
|
|
13182
13099
|
}
|
|
13183
|
-
var
|
|
13100
|
+
var import_fs5, import_path5, import_os2, import_jsonwebtoken, SUB_DIRECTORY, DIRECTORY, OFFLINE_LICENSE_FILE, LICENSE_FILE_PATH, PUBLIC_KEY;
|
|
13184
13101
|
var init_offline = __esm({
|
|
13185
13102
|
"../pro/packages/pro/src/sdk/licensing/licenses/offline.ts"() {
|
|
13186
|
-
|
|
13187
|
-
|
|
13103
|
+
import_fs5 = __toESM(require("fs"));
|
|
13104
|
+
import_path5 = require("path");
|
|
13188
13105
|
import_os2 = require("os");
|
|
13189
13106
|
import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
13190
13107
|
init_src2();
|
|
13191
13108
|
SUB_DIRECTORY = environment_default2.isTest() ? ".budibase-test" : ".budibase";
|
|
13192
|
-
DIRECTORY = (0,
|
|
13109
|
+
DIRECTORY = (0, import_path5.join)((0, import_os2.tmpdir)(), SUB_DIRECTORY);
|
|
13193
13110
|
OFFLINE_LICENSE_FILE = "offline_license.txt";
|
|
13194
|
-
LICENSE_FILE_PATH = (0,
|
|
13195
|
-
if (!
|
|
13196
|
-
|
|
13111
|
+
LICENSE_FILE_PATH = (0, import_path5.join)(DIRECTORY, OFFLINE_LICENSE_FILE);
|
|
13112
|
+
if (!import_fs5.default.existsSync(DIRECTORY)) {
|
|
13113
|
+
import_fs5.default.mkdirSync(DIRECTORY);
|
|
13197
13114
|
}
|
|
13198
13115
|
PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvz3jePLCFBXZ19c8Dpkv\nXtSgOhKFOcvQdo/LV0KJRUzQWDPWuO4ILtBtnqhjtIzZH4CH0qCYBet5L6Qr4CM1\nl2HXiAD1Q2rlHNW9wDaYyKb1F5f+v4RyqCAyzlkwRdksmkLeECTboojNnmRCrE3C\n8suunQP5bEScqEY2kclqzSf8e6xqMzPUg3mL/pNa1iEv7TuLbU9nJfgR36l0WmZY\n94fWnSaT8OSXSqcxsaByf06gfS3HAoTJNc7eqz1Hf9fUORQGPUAnFK8cT3SfdA36\nd/o3ZWE1TTj1zYwlCLN5qRKr3hU8nC3xEYNEbkB9SfTRaOq9Q7P8WmfLkoCPm3pR\nmwIDAQAB\n-----END PUBLIC KEY-----\n";
|
|
13199
13116
|
}
|
|
@@ -14650,13 +14567,13 @@ var init_groups6 = __esm({
|
|
|
14650
14567
|
|
|
14651
14568
|
// ../pro/packages/pro/src/utilities/fileSystem.ts
|
|
14652
14569
|
function loadJSFile(directory2, name2) {
|
|
14653
|
-
return
|
|
14570
|
+
return import_fs6.default.readFileSync((0, import_path6.join)(directory2, name2), "utf8");
|
|
14654
14571
|
}
|
|
14655
|
-
var
|
|
14572
|
+
var import_fs6, import_path6;
|
|
14656
14573
|
var init_fileSystem = __esm({
|
|
14657
14574
|
"../pro/packages/pro/src/utilities/fileSystem.ts"() {
|
|
14658
|
-
|
|
14659
|
-
|
|
14575
|
+
import_fs6 = __toESM(require("fs"));
|
|
14576
|
+
import_path6 = require("path");
|
|
14660
14577
|
}
|
|
14661
14578
|
});
|
|
14662
14579
|
|
|
@@ -17623,8 +17540,8 @@ async function runBackup(trigger, tenantId, appId, opts) {
|
|
|
17623
17540
|
}
|
|
17624
17541
|
});
|
|
17625
17542
|
await updateMetadata2("complete" /* COMPLETE */, { filename, contents });
|
|
17626
|
-
if (
|
|
17627
|
-
|
|
17543
|
+
if (import_fs7.default.existsSync(tarPath)) {
|
|
17544
|
+
import_fs7.default.rmSync(tarPath);
|
|
17628
17545
|
}
|
|
17629
17546
|
} catch (err) {
|
|
17630
17547
|
logging_exports.logAlert("App backup error", err);
|
|
@@ -17682,14 +17599,14 @@ async function exportProcessor(job, opts) {
|
|
|
17682
17599
|
});
|
|
17683
17600
|
});
|
|
17684
17601
|
}
|
|
17685
|
-
var
|
|
17602
|
+
var import_fs7;
|
|
17686
17603
|
var init_processing = __esm({
|
|
17687
17604
|
"../pro/packages/pro/src/sdk/backups/processing.ts"() {
|
|
17688
17605
|
init_src2();
|
|
17689
17606
|
init_backup5();
|
|
17690
17607
|
init_src();
|
|
17691
17608
|
init_queue4();
|
|
17692
|
-
|
|
17609
|
+
import_fs7 = __toESM(require("fs"));
|
|
17693
17610
|
}
|
|
17694
17611
|
});
|
|
17695
17612
|
|
|
@@ -18330,15 +18247,15 @@ async function downloadBackup(ctx) {
|
|
|
18330
18247
|
const backupId = ctx.params.backupId;
|
|
18331
18248
|
const { metadata: metadata2, path: path2 } = await backups_default.downloadAppBackup(backupId);
|
|
18332
18249
|
ctx.attachment(`backup-${metadata2.timestamp}.tar.gz`);
|
|
18333
|
-
ctx.body =
|
|
18250
|
+
ctx.body = import_fs8.default.createReadStream(path2);
|
|
18334
18251
|
}
|
|
18335
|
-
var
|
|
18252
|
+
var import_fs8;
|
|
18336
18253
|
var init_backups3 = __esm({
|
|
18337
18254
|
"../pro/packages/pro/src/api/controllers/apps/backups.ts"() {
|
|
18338
18255
|
init_src();
|
|
18339
18256
|
init_sdk2();
|
|
18340
18257
|
init_src2();
|
|
18341
|
-
|
|
18258
|
+
import_fs8 = __toESM(require("fs"));
|
|
18342
18259
|
}
|
|
18343
18260
|
});
|
|
18344
18261
|
|
|
@@ -18974,39 +18891,11 @@ var init_filters = __esm({
|
|
|
18974
18891
|
// ../shared-core/src/utils.ts
|
|
18975
18892
|
var utils_exports5 = {};
|
|
18976
18893
|
__export(utils_exports5, {
|
|
18977
|
-
parallelForeach: () => parallelForeach,
|
|
18978
18894
|
unreachable: () => unreachable
|
|
18979
18895
|
});
|
|
18980
18896
|
function unreachable(value, message = `No such case in exhaustive switch: ${value}`) {
|
|
18981
18897
|
throw new Error(message);
|
|
18982
18898
|
}
|
|
18983
|
-
async function parallelForeach(items, task, maxConcurrency) {
|
|
18984
|
-
const promises = [];
|
|
18985
|
-
let index2 = 0;
|
|
18986
|
-
const processItem = async (item) => {
|
|
18987
|
-
try {
|
|
18988
|
-
await task(item);
|
|
18989
|
-
} finally {
|
|
18990
|
-
processNext();
|
|
18991
|
-
}
|
|
18992
|
-
};
|
|
18993
|
-
const processNext = () => {
|
|
18994
|
-
if (index2 >= items.length) {
|
|
18995
|
-
return;
|
|
18996
|
-
}
|
|
18997
|
-
const item = items[index2];
|
|
18998
|
-
index2++;
|
|
18999
|
-
const promise = processItem(item);
|
|
19000
|
-
promises.push(promise);
|
|
19001
|
-
if (promises.length >= maxConcurrency) {
|
|
19002
|
-
Promise.race(promises).then(processNext);
|
|
19003
|
-
} else {
|
|
19004
|
-
processNext();
|
|
19005
|
-
}
|
|
19006
|
-
};
|
|
19007
|
-
processNext();
|
|
19008
|
-
await Promise.all(promises);
|
|
19009
|
-
}
|
|
19010
18899
|
var init_utils12 = __esm({
|
|
19011
18900
|
"../shared-core/src/utils.ts"() {
|
|
19012
18901
|
}
|
|
@@ -19630,32 +19519,32 @@ var init_centralPath = __esm({
|
|
|
19630
19519
|
});
|
|
19631
19520
|
|
|
19632
19521
|
// src/utilities/fileSystem/filesystem.ts
|
|
19633
|
-
var
|
|
19522
|
+
var import_fs9, import_path7, import_tar, uuid2, TOP_LEVEL_PATH, apiFileReturn, streamFile, createTempFolder, extractTarball;
|
|
19634
19523
|
var init_filesystem = __esm({
|
|
19635
19524
|
"src/utilities/fileSystem/filesystem.ts"() {
|
|
19636
|
-
|
|
19525
|
+
import_fs9 = __toESM(require("fs"));
|
|
19637
19526
|
init_budibaseDir();
|
|
19638
|
-
|
|
19527
|
+
import_path7 = require("path");
|
|
19639
19528
|
init_environment();
|
|
19640
19529
|
import_tar = __toESM(require("tar"));
|
|
19641
19530
|
init_environment();
|
|
19642
19531
|
uuid2 = require("uuid/v4");
|
|
19643
|
-
TOP_LEVEL_PATH = environment_default.TOP_LEVEL_PATH || (0,
|
|
19532
|
+
TOP_LEVEL_PATH = environment_default.TOP_LEVEL_PATH || (0, import_path7.resolve)((0, import_path7.join)(__dirname, "..", "..", ".."));
|
|
19644
19533
|
apiFileReturn = (contents) => {
|
|
19645
|
-
const path2 = (0,
|
|
19646
|
-
|
|
19647
|
-
return
|
|
19534
|
+
const path2 = (0, import_path7.join)(budibaseTempDir2(), uuid2());
|
|
19535
|
+
import_fs9.default.writeFileSync(path2, contents);
|
|
19536
|
+
return import_fs9.default.createReadStream(path2);
|
|
19648
19537
|
};
|
|
19649
19538
|
streamFile = (path2) => {
|
|
19650
|
-
return
|
|
19539
|
+
return import_fs9.default.createReadStream(path2);
|
|
19651
19540
|
};
|
|
19652
19541
|
createTempFolder = (item) => {
|
|
19653
|
-
const path2 = (0,
|
|
19542
|
+
const path2 = (0, import_path7.join)(budibaseTempDir2(), item);
|
|
19654
19543
|
try {
|
|
19655
|
-
if (
|
|
19656
|
-
|
|
19544
|
+
if (import_fs9.default.existsSync(path2)) {
|
|
19545
|
+
import_fs9.default.rmSync(path2, { recursive: true, force: true });
|
|
19657
19546
|
}
|
|
19658
|
-
|
|
19547
|
+
import_fs9.default.mkdirSync(path2);
|
|
19659
19548
|
} catch (err) {
|
|
19660
19549
|
throw new Error(`Path cannot be created: ${err.message}`);
|
|
19661
19550
|
}
|
|
@@ -19682,17 +19571,17 @@ var init_clientLibrary = __esm({
|
|
|
19682
19571
|
});
|
|
19683
19572
|
|
|
19684
19573
|
// src/utilities/fileSystem/app.ts
|
|
19685
|
-
var
|
|
19574
|
+
var import_path8, NODE_MODULES_PATH;
|
|
19686
19575
|
var init_app7 = __esm({
|
|
19687
19576
|
"src/utilities/fileSystem/app.ts"() {
|
|
19688
19577
|
init_budibaseDir();
|
|
19689
|
-
|
|
19578
|
+
import_path8 = require("path");
|
|
19690
19579
|
init_constants6();
|
|
19691
19580
|
init_clientLibrary();
|
|
19692
19581
|
init_environment();
|
|
19693
19582
|
init_src2();
|
|
19694
19583
|
init_filesystem();
|
|
19695
|
-
NODE_MODULES_PATH = (0,
|
|
19584
|
+
NODE_MODULES_PATH = (0, import_path8.join)(TOP_LEVEL_PATH, "node_modules");
|
|
19696
19585
|
}
|
|
19697
19586
|
});
|
|
19698
19587
|
|
|
@@ -19700,19 +19589,19 @@ var init_app7 = __esm({
|
|
|
19700
19589
|
async function getPluginImpl(path2, plugin) {
|
|
19701
19590
|
var _a;
|
|
19702
19591
|
const hash3 = (_a = plugin.schema) == null ? void 0 : _a.hash;
|
|
19703
|
-
if (!
|
|
19704
|
-
|
|
19592
|
+
if (!import_fs10.default.existsSync(path2)) {
|
|
19593
|
+
import_fs10.default.mkdirSync(path2);
|
|
19705
19594
|
}
|
|
19706
|
-
const filename = (0,
|
|
19595
|
+
const filename = (0, import_path9.join)(path2, plugin.name);
|
|
19707
19596
|
const metadataName = `${filename}.bbmetadata`;
|
|
19708
|
-
if (
|
|
19709
|
-
const currentHash =
|
|
19597
|
+
if (import_fs10.default.existsSync(filename)) {
|
|
19598
|
+
const currentHash = import_fs10.default.readFileSync(metadataName, "utf8");
|
|
19710
19599
|
if (currentHash === hash3) {
|
|
19711
19600
|
return require(filename);
|
|
19712
19601
|
} else {
|
|
19713
19602
|
console.log(`Updating plugin: ${plugin.name}`);
|
|
19714
19603
|
delete require.cache[require.resolve(filename)];
|
|
19715
|
-
|
|
19604
|
+
import_fs10.default.unlinkSync(filename);
|
|
19716
19605
|
}
|
|
19717
19606
|
}
|
|
19718
19607
|
const pluginKey = objectStore_exports2.getPluginJSKey(plugin);
|
|
@@ -19720,24 +19609,24 @@ async function getPluginImpl(path2, plugin) {
|
|
|
19720
19609
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
19721
19610
|
pluginKey
|
|
19722
19611
|
);
|
|
19723
|
-
|
|
19724
|
-
|
|
19612
|
+
import_fs10.default.writeFileSync(filename, pluginJs);
|
|
19613
|
+
import_fs10.default.writeFileSync(metadataName, hash3);
|
|
19725
19614
|
return require(filename);
|
|
19726
19615
|
}
|
|
19727
|
-
var
|
|
19616
|
+
var import_fs10, import_path9, DATASOURCE_PATH, AUTOMATION_PATH, getPluginMetadata, getDatasourcePlugin, getAutomationPlugin;
|
|
19728
19617
|
var init_plugin5 = __esm({
|
|
19729
19618
|
"src/utilities/fileSystem/plugin.ts"() {
|
|
19730
19619
|
init_budibaseDir();
|
|
19731
|
-
|
|
19732
|
-
|
|
19620
|
+
import_fs10 = __toESM(require("fs"));
|
|
19621
|
+
import_path9 = require("path");
|
|
19733
19622
|
init_src2();
|
|
19734
|
-
DATASOURCE_PATH = (0,
|
|
19735
|
-
AUTOMATION_PATH = (0,
|
|
19623
|
+
DATASOURCE_PATH = (0, import_path9.join)(budibaseTempDir2(), "datasource");
|
|
19624
|
+
AUTOMATION_PATH = (0, import_path9.join)(budibaseTempDir2(), "automation");
|
|
19736
19625
|
getPluginMetadata = async (path2) => {
|
|
19737
19626
|
let metadata2 = {};
|
|
19738
19627
|
try {
|
|
19739
|
-
const pkg2 =
|
|
19740
|
-
const schema =
|
|
19628
|
+
const pkg2 = import_fs10.default.readFileSync((0, import_path9.join)(path2, "package.json"), "utf8");
|
|
19629
|
+
const schema = import_fs10.default.readFileSync((0, import_path9.join)(path2, "schema.json"), "utf8");
|
|
19741
19630
|
metadata2.schema = JSON.parse(schema);
|
|
19742
19631
|
metadata2.package = JSON.parse(pkg2);
|
|
19743
19632
|
if (!metadata2.package.name || !metadata2.package.version || !metadata2.package.description) {
|
|
@@ -19808,14 +19697,13 @@ __export(exports_exports, {
|
|
|
19808
19697
|
streamExportApp: () => streamExportApp
|
|
19809
19698
|
});
|
|
19810
19699
|
function tarFilesToTmp(tmpDir, files2) {
|
|
19811
|
-
const
|
|
19812
|
-
|
|
19813
|
-
import_tar2.default.create(
|
|
19700
|
+
const exportFile = (0, import_path10.join)(budibaseTempDir2(), `${uuid3()}.tar.gz`);
|
|
19701
|
+
tar3.create(
|
|
19814
19702
|
{
|
|
19815
19703
|
sync: true,
|
|
19816
19704
|
gzip: true,
|
|
19817
19705
|
file: exportFile,
|
|
19818
|
-
|
|
19706
|
+
recursive: true,
|
|
19819
19707
|
cwd: tmpDir
|
|
19820
19708
|
},
|
|
19821
19709
|
files2
|
|
@@ -19832,7 +19720,7 @@ async function exportDB(dbName, opts = {}) {
|
|
|
19832
19720
|
return db_exports.doWithDB(dbName, async (db2) => {
|
|
19833
19721
|
if (opts == null ? void 0 : opts.exportPath) {
|
|
19834
19722
|
const path2 = opts == null ? void 0 : opts.exportPath;
|
|
19835
|
-
const writeStream =
|
|
19723
|
+
const writeStream = import_fs11.default.createWriteStream(path2);
|
|
19836
19724
|
await db2.dump(writeStream, exportOpts);
|
|
19837
19725
|
return path2;
|
|
19838
19726
|
} else {
|
|
@@ -19865,9 +19753,9 @@ async function exportApp(appId, config) {
|
|
|
19865
19753
|
for (let path2 of STATIC_APP_FILES) {
|
|
19866
19754
|
const contents = await objectStore_exports2.retrieve(
|
|
19867
19755
|
ObjectStoreBuckets2.APPS,
|
|
19868
|
-
(0,
|
|
19756
|
+
(0, import_path10.join)(appPath, path2)
|
|
19869
19757
|
);
|
|
19870
|
-
|
|
19758
|
+
import_fs11.default.writeFileSync((0, import_path10.join)(tmpPath, path2), contents);
|
|
19871
19759
|
}
|
|
19872
19760
|
} else {
|
|
19873
19761
|
tmpPath = await objectStore_exports2.retrieveDirectory(
|
|
@@ -19876,52 +19764,37 @@ async function exportApp(appId, config) {
|
|
|
19876
19764
|
);
|
|
19877
19765
|
}
|
|
19878
19766
|
}
|
|
19879
|
-
const downloadedPath = (0,
|
|
19880
|
-
if (
|
|
19881
|
-
const allFiles =
|
|
19767
|
+
const downloadedPath = (0, import_path10.join)(tmpPath, appPath);
|
|
19768
|
+
if (import_fs11.default.existsSync(downloadedPath)) {
|
|
19769
|
+
const allFiles = import_fs11.default.readdirSync(downloadedPath);
|
|
19882
19770
|
for (let file of allFiles) {
|
|
19883
|
-
const path2 = (0,
|
|
19884
|
-
|
|
19771
|
+
const path2 = (0, import_path10.join)(downloadedPath, file);
|
|
19772
|
+
import_fs11.default.renameSync(path2, (0, import_path10.join)(downloadedPath, "..", file));
|
|
19885
19773
|
}
|
|
19886
|
-
|
|
19774
|
+
import_fs11.default.rmdirSync(downloadedPath);
|
|
19887
19775
|
}
|
|
19888
|
-
const dbPath = (0,
|
|
19776
|
+
const dbPath = (0, import_path10.join)(tmpPath, DB_EXPORT_FILE);
|
|
19889
19777
|
await exportDB(appId, {
|
|
19890
19778
|
filter: defineFilter(config == null ? void 0 : config.excludeRows, config == null ? void 0 : config.excludeLogs),
|
|
19891
19779
|
exportPath: dbPath
|
|
19892
19780
|
});
|
|
19893
|
-
if (config == null ? void 0 : config.encryptPassword) {
|
|
19894
|
-
for (let file of import_fs12.default.readdirSync(tmpPath)) {
|
|
19895
|
-
const path2 = (0, import_path11.join)(tmpPath, file);
|
|
19896
|
-
await encryption_exports.encryptFile(
|
|
19897
|
-
{ dir: tmpPath, filename: file },
|
|
19898
|
-
config.encryptPassword
|
|
19899
|
-
);
|
|
19900
|
-
import_fs12.default.rmSync(path2);
|
|
19901
|
-
}
|
|
19902
|
-
}
|
|
19903
19781
|
if (config == null ? void 0 : config.tar) {
|
|
19904
|
-
const tarPath = tarFilesToTmp(tmpPath,
|
|
19905
|
-
|
|
19782
|
+
const tarPath = tarFilesToTmp(tmpPath, import_fs11.default.readdirSync(tmpPath));
|
|
19783
|
+
import_fs11.default.rmSync(tmpPath, { recursive: true, force: true });
|
|
19906
19784
|
return tarPath;
|
|
19907
19785
|
} else {
|
|
19908
19786
|
return tmpPath;
|
|
19909
19787
|
}
|
|
19910
19788
|
}
|
|
19911
|
-
async function streamExportApp({
|
|
19912
|
-
appId,
|
|
19913
|
-
excludeRows,
|
|
19914
|
-
encryptPassword
|
|
19915
|
-
}) {
|
|
19789
|
+
async function streamExportApp(appId, excludeRows) {
|
|
19916
19790
|
const tmpPath = await exportApp(appId, {
|
|
19917
19791
|
excludeRows,
|
|
19918
19792
|
excludeLogs: true,
|
|
19919
|
-
tar: true
|
|
19920
|
-
encryptPassword
|
|
19793
|
+
tar: true
|
|
19921
19794
|
});
|
|
19922
19795
|
return streamFile(tmpPath);
|
|
19923
19796
|
}
|
|
19924
|
-
var
|
|
19797
|
+
var import_fs11, import_path10, uuid3, tar3, MemoryStream2;
|
|
19925
19798
|
var init_exports2 = __esm({
|
|
19926
19799
|
"src/sdk/app/backups/exports.ts"() {
|
|
19927
19800
|
init_src2();
|
|
@@ -19930,11 +19803,11 @@ var init_exports2 = __esm({
|
|
|
19930
19803
|
init_constants6();
|
|
19931
19804
|
init_utils13();
|
|
19932
19805
|
init_constants7();
|
|
19933
|
-
|
|
19934
|
-
|
|
19806
|
+
import_fs11 = __toESM(require("fs"));
|
|
19807
|
+
import_path10 = require("path");
|
|
19935
19808
|
init_environment();
|
|
19936
|
-
import_tar2 = __toESM(require("tar"));
|
|
19937
19809
|
uuid3 = require("uuid/v4");
|
|
19810
|
+
tar3 = require("tar");
|
|
19938
19811
|
MemoryStream2 = require("memorystream");
|
|
19939
19812
|
}
|
|
19940
19813
|
});
|
|
@@ -20011,16 +19884,16 @@ async function getTemplateStream(template) {
|
|
|
20011
19884
|
throw new Error("Cannot import a non-text based file.");
|
|
20012
19885
|
}
|
|
20013
19886
|
if (template.file) {
|
|
20014
|
-
return
|
|
19887
|
+
return import_fs12.default.createReadStream(template.file.path);
|
|
20015
19888
|
} else if (template.key) {
|
|
20016
19889
|
const [type, name2] = template.key.split("/");
|
|
20017
19890
|
const tmpPath = await downloadTemplate(type, name2);
|
|
20018
|
-
return
|
|
19891
|
+
return import_fs12.default.createReadStream((0, import_path11.join)(tmpPath, name2, "db", "dump.txt"));
|
|
20019
19892
|
}
|
|
20020
19893
|
}
|
|
20021
19894
|
function untarFile(file) {
|
|
20022
|
-
const tmpPath = (0,
|
|
20023
|
-
|
|
19895
|
+
const tmpPath = (0, import_path11.join)(budibaseTempDir2(), uuid4());
|
|
19896
|
+
import_fs12.default.mkdirSync(tmpPath);
|
|
20024
19897
|
tar4.extract({
|
|
20025
19898
|
sync: true,
|
|
20026
19899
|
cwd: tmpPath,
|
|
@@ -20028,49 +19901,31 @@ function untarFile(file) {
|
|
|
20028
19901
|
});
|
|
20029
19902
|
return tmpPath;
|
|
20030
19903
|
}
|
|
20031
|
-
async function decryptFiles(path2, password) {
|
|
20032
|
-
try {
|
|
20033
|
-
for (let file of import_fs13.default.readdirSync(path2)) {
|
|
20034
|
-
const inputPath = (0, import_path12.join)(path2, file);
|
|
20035
|
-
const outputPath = inputPath.replace(/\.enc$/, "");
|
|
20036
|
-
await encryption_exports.decryptFile(inputPath, outputPath, password);
|
|
20037
|
-
import_fs13.default.rmSync(inputPath);
|
|
20038
|
-
}
|
|
20039
|
-
} catch (err) {
|
|
20040
|
-
if (err.message === "incorrect header check") {
|
|
20041
|
-
throw new Error("File cannot be imported");
|
|
20042
|
-
}
|
|
20043
|
-
throw err;
|
|
20044
|
-
}
|
|
20045
|
-
}
|
|
20046
19904
|
function getGlobalDBFile(tmpPath) {
|
|
20047
|
-
return
|
|
19905
|
+
return import_fs12.default.readFileSync((0, import_path11.join)(tmpPath, GLOBAL_DB_EXPORT_FILE), "utf8");
|
|
20048
19906
|
}
|
|
20049
19907
|
function getListOfAppsInMulti(tmpPath) {
|
|
20050
|
-
return
|
|
19908
|
+
return import_fs12.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
|
|
20051
19909
|
}
|
|
20052
19910
|
async function importApp(appId, db2, template) {
|
|
20053
19911
|
var _a, _b;
|
|
20054
19912
|
let prodAppId = db_exports.getProdAppID(appId);
|
|
20055
19913
|
let dbStream;
|
|
20056
19914
|
const isTar = template.file && ((_b = (_a = template == null ? void 0 : template.file) == null ? void 0 : _a.type) == null ? void 0 : _b.endsWith("gzip"));
|
|
20057
|
-
const isDirectory = template.file &&
|
|
19915
|
+
const isDirectory = template.file && import_fs12.default.lstatSync(template.file.path).isDirectory();
|
|
20058
19916
|
if (template.file && (isTar || isDirectory)) {
|
|
20059
19917
|
const tmpPath = isTar ? untarFile(template.file) : template.file.path;
|
|
20060
|
-
|
|
20061
|
-
await decryptFiles(tmpPath, template.file.password);
|
|
20062
|
-
}
|
|
20063
|
-
const contents = import_fs13.default.readdirSync(tmpPath);
|
|
19918
|
+
const contents = import_fs12.default.readdirSync(tmpPath);
|
|
20064
19919
|
if (contents.length) {
|
|
20065
19920
|
let promises = [];
|
|
20066
19921
|
let excludedFiles = [GLOBAL_DB_EXPORT_FILE, DB_EXPORT_FILE];
|
|
20067
19922
|
for (let filename of contents) {
|
|
20068
|
-
const path2 = (0,
|
|
19923
|
+
const path2 = (0, import_path11.join)(tmpPath, filename);
|
|
20069
19924
|
if (excludedFiles.includes(filename)) {
|
|
20070
19925
|
continue;
|
|
20071
19926
|
}
|
|
20072
|
-
filename = (0,
|
|
20073
|
-
if (
|
|
19927
|
+
filename = (0, import_path11.join)(prodAppId, filename);
|
|
19928
|
+
if (import_fs12.default.lstatSync(path2).isDirectory()) {
|
|
20074
19929
|
promises.push(
|
|
20075
19930
|
objectStore_exports2.uploadDirectory(ObjectStoreBuckets2.APPS, path2, filename)
|
|
20076
19931
|
);
|
|
@@ -20086,7 +19941,7 @@ async function importApp(appId, db2, template) {
|
|
|
20086
19941
|
}
|
|
20087
19942
|
await Promise.all(promises);
|
|
20088
19943
|
}
|
|
20089
|
-
dbStream =
|
|
19944
|
+
dbStream = import_fs12.default.createReadStream((0, import_path11.join)(tmpPath, DB_EXPORT_FILE));
|
|
20090
19945
|
} else {
|
|
20091
19946
|
dbStream = await getTemplateStream(template);
|
|
20092
19947
|
}
|
|
@@ -20098,7 +19953,7 @@ async function importApp(appId, db2, template) {
|
|
|
20098
19953
|
await updateAutomations(prodAppId, db2);
|
|
20099
19954
|
return ok;
|
|
20100
19955
|
}
|
|
20101
|
-
var
|
|
19956
|
+
var import_path11, import_fs12, uuid4, tar4;
|
|
20102
19957
|
var init_imports = __esm({
|
|
20103
19958
|
"src/sdk/app/backups/imports.ts"() {
|
|
20104
19959
|
init_src2();
|
|
@@ -20107,8 +19962,8 @@ var init_imports = __esm({
|
|
|
20107
19962
|
init_constants7();
|
|
20108
19963
|
init_fileSystem2();
|
|
20109
19964
|
init_constants6();
|
|
20110
|
-
|
|
20111
|
-
|
|
19965
|
+
import_path11 = require("path");
|
|
19966
|
+
import_fs12 = __toESM(require("fs"));
|
|
20112
19967
|
init_sdk3();
|
|
20113
19968
|
init_src();
|
|
20114
19969
|
uuid4 = require("uuid/v4");
|
|
@@ -21415,8 +21270,7 @@ var init_postgres = __esm({
|
|
|
21415
21270
|
try {
|
|
21416
21271
|
await this.openConnection();
|
|
21417
21272
|
const columnsResponse = await this.client.query(this.COLUMNS_SQL);
|
|
21418
|
-
|
|
21419
|
-
return [...new Set(names)];
|
|
21273
|
+
return columnsResponse.rows.map((row) => row.table_name);
|
|
21420
21274
|
} finally {
|
|
21421
21275
|
await this.closeConnection();
|
|
21422
21276
|
}
|
|
@@ -22045,8 +21899,6 @@ var init_mongodb = __esm({
|
|
|
22045
21899
|
response2.connected = true;
|
|
22046
21900
|
} catch (e) {
|
|
22047
21901
|
response2.error = e.message;
|
|
22048
|
-
} finally {
|
|
22049
|
-
await this.client.close();
|
|
22050
21902
|
}
|
|
22051
21903
|
return response2;
|
|
22052
21904
|
}
|
|
@@ -23978,16 +23830,6 @@ var init_rest = __esm({
|
|
|
23978
23830
|
});
|
|
23979
23831
|
|
|
23980
23832
|
// src/integrations/googlesheets.ts
|
|
23981
|
-
async function setupCreationAuth(datasouce) {
|
|
23982
|
-
if (datasouce.continueSetupId) {
|
|
23983
|
-
const appId = context_exports.getAppId();
|
|
23984
|
-
const tokens = await cache_exports.get(
|
|
23985
|
-
`datasource:creation:${appId}:google:${datasouce.continueSetupId}`
|
|
23986
|
-
);
|
|
23987
|
-
datasouce.auth = tokens.tokens;
|
|
23988
|
-
delete datasouce.continueSetupId;
|
|
23989
|
-
}
|
|
23990
|
-
}
|
|
23991
23833
|
var import_google_auth_library, import_google_spreadsheet, import_node_fetch9, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
|
|
23992
23834
|
var init_googlesheets = __esm({
|
|
23993
23835
|
"src/integrations/googlesheets.ts"() {
|
|
@@ -24025,7 +23867,7 @@ var init_googlesheets = __esm({
|
|
|
24025
23867
|
},
|
|
24026
23868
|
datasource: {
|
|
24027
23869
|
spreadsheetId: {
|
|
24028
|
-
display: "
|
|
23870
|
+
display: "Google Sheet URL",
|
|
24029
23871
|
type: "string" /* STRING */,
|
|
24030
23872
|
required: true
|
|
24031
23873
|
}
|
|
@@ -24146,7 +23988,6 @@ var init_googlesheets = __esm({
|
|
|
24146
23988
|
async connect() {
|
|
24147
23989
|
var _a;
|
|
24148
23990
|
try {
|
|
24149
|
-
await setupCreationAuth(this.config);
|
|
24150
23991
|
let googleConfig = await configs_exports.getGoogleDatasourceConfig();
|
|
24151
23992
|
if (!googleConfig) {
|
|
24152
23993
|
throw new HTTPError("Google config not found", 400);
|
|
@@ -24197,22 +24038,21 @@ var init_googlesheets = __esm({
|
|
|
24197
24038
|
return table;
|
|
24198
24039
|
}
|
|
24199
24040
|
async buildSchema(datasourceId, entities) {
|
|
24041
|
+
if (!this.config.auth) {
|
|
24042
|
+
return;
|
|
24043
|
+
}
|
|
24200
24044
|
await this.connect();
|
|
24201
24045
|
const sheets = this.client.sheetsByIndex;
|
|
24202
24046
|
const tables = {};
|
|
24203
|
-
|
|
24204
|
-
|
|
24205
|
-
|
|
24206
|
-
|
|
24207
|
-
|
|
24208
|
-
|
|
24209
|
-
|
|
24210
|
-
|
|
24211
|
-
|
|
24212
|
-
);
|
|
24213
|
-
},
|
|
24214
|
-
10
|
|
24215
|
-
);
|
|
24047
|
+
for (let sheet of sheets) {
|
|
24048
|
+
await sheet.getRows();
|
|
24049
|
+
const id = buildExternalTableId(datasourceId, sheet.title);
|
|
24050
|
+
tables[sheet.title] = this.getTableSchema(
|
|
24051
|
+
sheet.title,
|
|
24052
|
+
sheet.headerValues,
|
|
24053
|
+
id
|
|
24054
|
+
);
|
|
24055
|
+
}
|
|
24216
24056
|
const final = finaliseExternalTables(tables, entities);
|
|
24217
24057
|
this.tables = final.tables;
|
|
24218
24058
|
this.schemaErrors = final.errors;
|
|
@@ -27068,22 +26908,22 @@ function threadSetup() {
|
|
|
27068
26908
|
init8();
|
|
27069
26909
|
}
|
|
27070
26910
|
async function checkCacheForDynamicVariable(queryId, variable) {
|
|
27071
|
-
const
|
|
27072
|
-
return
|
|
26911
|
+
const cache2 = await getClient2();
|
|
26912
|
+
return cache2.get(makeVariableKey(queryId, variable));
|
|
27073
26913
|
}
|
|
27074
26914
|
async function invalidateDynamicVariables(cachedVars) {
|
|
27075
|
-
const
|
|
26915
|
+
const cache2 = await getClient2();
|
|
27076
26916
|
let promises = [];
|
|
27077
26917
|
for (let variable of cachedVars) {
|
|
27078
26918
|
promises.push(
|
|
27079
|
-
|
|
26919
|
+
cache2.delete(makeVariableKey(variable.queryId, variable.name))
|
|
27080
26920
|
);
|
|
27081
26921
|
}
|
|
27082
26922
|
await Promise.all(promises);
|
|
27083
26923
|
}
|
|
27084
26924
|
async function storeDynamicVariable(queryId, variable, value) {
|
|
27085
|
-
const
|
|
27086
|
-
await
|
|
26925
|
+
const cache2 = await getClient2();
|
|
26926
|
+
await cache2.store(
|
|
27087
26927
|
makeVariableKey(queryId, variable),
|
|
27088
26928
|
value,
|
|
27089
26929
|
VARIABLE_TTL_SECONDS
|
|
@@ -27551,16 +27391,7 @@ async function checkResponse(response2, errorMsg, { ctx } = {}) {
|
|
|
27551
27391
|
}
|
|
27552
27392
|
return response2.json();
|
|
27553
27393
|
}
|
|
27554
|
-
async function sendSmtpEmail({
|
|
27555
|
-
to,
|
|
27556
|
-
from,
|
|
27557
|
-
subject,
|
|
27558
|
-
contents,
|
|
27559
|
-
cc,
|
|
27560
|
-
bcc,
|
|
27561
|
-
automation,
|
|
27562
|
-
invite
|
|
27563
|
-
}) {
|
|
27394
|
+
async function sendSmtpEmail(to, from, subject, contents, cc, bcc, automation) {
|
|
27564
27395
|
const response2 = await (0, import_node_fetch10.default)(
|
|
27565
27396
|
checkSlashesInUrl2(environment_default.WORKER_URL + `/api/global/email/send`),
|
|
27566
27397
|
request(void 0, {
|
|
@@ -27573,8 +27404,7 @@ async function sendSmtpEmail({
|
|
|
27573
27404
|
cc,
|
|
27574
27405
|
bcc,
|
|
27575
27406
|
purpose: "custom",
|
|
27576
|
-
automation
|
|
27577
|
-
invite
|
|
27407
|
+
automation
|
|
27578
27408
|
}
|
|
27579
27409
|
})
|
|
27580
27410
|
);
|
|
@@ -27622,35 +27452,6 @@ var definition7 = {
|
|
|
27622
27452
|
contents: {
|
|
27623
27453
|
type: "string" /* STRING */,
|
|
27624
27454
|
title: "HTML Contents"
|
|
27625
|
-
},
|
|
27626
|
-
addInvite: {
|
|
27627
|
-
type: "boolean" /* BOOLEAN */,
|
|
27628
|
-
title: "Add calendar invite"
|
|
27629
|
-
},
|
|
27630
|
-
startTime: {
|
|
27631
|
-
type: "date" /* DATE */,
|
|
27632
|
-
title: "Start Time",
|
|
27633
|
-
dependsOn: "addInvite"
|
|
27634
|
-
},
|
|
27635
|
-
endTime: {
|
|
27636
|
-
type: "date" /* DATE */,
|
|
27637
|
-
title: "End Time",
|
|
27638
|
-
dependsOn: "addInvite"
|
|
27639
|
-
},
|
|
27640
|
-
summary: {
|
|
27641
|
-
type: "string" /* STRING */,
|
|
27642
|
-
title: "Meeting Summary",
|
|
27643
|
-
dependsOn: "addInvite"
|
|
27644
|
-
},
|
|
27645
|
-
location: {
|
|
27646
|
-
type: "string" /* STRING */,
|
|
27647
|
-
title: "Location",
|
|
27648
|
-
dependsOn: "addInvite"
|
|
27649
|
-
},
|
|
27650
|
-
url: {
|
|
27651
|
-
type: "string" /* STRING */,
|
|
27652
|
-
title: "URL",
|
|
27653
|
-
dependsOn: "addInvite"
|
|
27654
27455
|
}
|
|
27655
27456
|
},
|
|
27656
27457
|
required: ["to", "from", "subject", "contents"]
|
|
@@ -27671,41 +27472,21 @@ var definition7 = {
|
|
|
27671
27472
|
}
|
|
27672
27473
|
};
|
|
27673
27474
|
async function run3({ inputs }) {
|
|
27674
|
-
let {
|
|
27675
|
-
to,
|
|
27676
|
-
from,
|
|
27677
|
-
subject,
|
|
27678
|
-
contents,
|
|
27679
|
-
cc,
|
|
27680
|
-
bcc,
|
|
27681
|
-
addInvite,
|
|
27682
|
-
startTime,
|
|
27683
|
-
endTime,
|
|
27684
|
-
summary,
|
|
27685
|
-
location,
|
|
27686
|
-
url
|
|
27687
|
-
} = inputs;
|
|
27475
|
+
let { to, from, subject, contents, cc, bcc } = inputs;
|
|
27688
27476
|
if (!contents) {
|
|
27689
27477
|
contents = "<h1>No content</h1>";
|
|
27690
27478
|
}
|
|
27691
27479
|
to = to || void 0;
|
|
27692
27480
|
try {
|
|
27693
|
-
let response2 = await sendSmtpEmail(
|
|
27481
|
+
let response2 = await sendSmtpEmail(
|
|
27694
27482
|
to,
|
|
27695
27483
|
from,
|
|
27696
27484
|
subject,
|
|
27697
27485
|
contents,
|
|
27698
27486
|
cc,
|
|
27699
27487
|
bcc,
|
|
27700
|
-
|
|
27701
|
-
|
|
27702
|
-
startTime,
|
|
27703
|
-
endTime,
|
|
27704
|
-
summary,
|
|
27705
|
-
location,
|
|
27706
|
-
url
|
|
27707
|
-
} : void 0
|
|
27708
|
-
});
|
|
27488
|
+
true
|
|
27489
|
+
);
|
|
27709
27490
|
return {
|
|
27710
27491
|
success: true,
|
|
27711
27492
|
response: response2
|
|
@@ -30929,15 +30710,8 @@ init_constants6();
|
|
|
30929
30710
|
init_integrations2();
|
|
30930
30711
|
init_utils20();
|
|
30931
30712
|
init_src2();
|
|
30932
|
-
init_src();
|
|
30933
30713
|
init_sdk3();
|
|
30934
30714
|
init_websockets();
|
|
30935
|
-
init_googlesheets();
|
|
30936
|
-
var preSaveAction = {
|
|
30937
|
-
["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
|
|
30938
|
-
await setupCreationAuth(datasource2.config);
|
|
30939
|
-
}
|
|
30940
|
-
};
|
|
30941
30715
|
|
|
30942
30716
|
// src/api/controllers/query/validation.ts
|
|
30943
30717
|
init_src2();
|