@budibase/backend-core 3.2.35 → 3.2.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -17698,7 +17698,7 @@ var environment = {
17698
17698
  MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
17699
17699
  MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
17700
17700
  AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN,
17701
- AWS_REGION: process.env.AWS_REGION || "eu-west-1",
17701
+ AWS_REGION: process.env.AWS_REGION,
17702
17702
  MINIO_URL: process.env.MINIO_URL,
17703
17703
  MINIO_ENABLED: process.env.MINIO_ENABLED || 1,
17704
17704
  INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
@@ -18619,9 +18619,7 @@ __export(objectStore_exports2, {
18619
18619
  });
18620
18620
 
18621
18621
  // src/objectStore/objectStore.ts
18622
- var import_client_s3 = require("@aws-sdk/client-s3");
18623
- var import_lib_storage = require("@aws-sdk/lib-storage");
18624
- var import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
18622
+ var import_aws_sdk = __toESM(require("aws-sdk"));
18625
18623
  var import_stream2 = __toESM(require("stream"));
18626
18624
  var import_node_fetch2 = __toESM(require("node-fetch"));
18627
18625
  var import_tar_fs = __toESM(require("tar-fs"));
@@ -18740,42 +18738,42 @@ function sanitizeKey(input) {
18740
18738
  function sanitizeBucket(input) {
18741
18739
  return input.replace(new RegExp(APP_DEV_PREFIX2, "g"), APP_PREFIX2);
18742
18740
  }
18743
- function ObjectStore(opts = { presigning: false }) {
18741
+ function ObjectStore(bucket, opts = { presigning: false }) {
18744
18742
  const config = {
18745
- forcePathStyle: true,
18746
- credentials: {
18747
- accessKeyId: environment_default.MINIO_ACCESS_KEY,
18748
- secretAccessKey: environment_default.MINIO_SECRET_KEY
18749
- },
18743
+ s3ForcePathStyle: true,
18744
+ signatureVersion: "v4",
18745
+ apiVersion: "2006-03-01",
18746
+ accessKeyId: environment_default.MINIO_ACCESS_KEY,
18747
+ secretAccessKey: environment_default.MINIO_SECRET_KEY,
18750
18748
  region: environment_default.AWS_REGION
18751
18749
  };
18752
- if (!environment_default.MINIO_ENABLED && environment_default.AWS_SESSION_TOKEN) {
18753
- config.credentials = {
18754
- accessKeyId: environment_default.MINIO_ACCESS_KEY,
18755
- secretAccessKey: environment_default.MINIO_SECRET_KEY,
18756
- sessionToken: environment_default.AWS_SESSION_TOKEN
18750
+ if (bucket) {
18751
+ config.params = {
18752
+ Bucket: sanitizeBucket(bucket)
18757
18753
  };
18758
18754
  }
18755
+ if (!environment_default.MINIO_ENABLED && environment_default.AWS_SESSION_TOKEN) {
18756
+ config.sessionToken = environment_default.AWS_SESSION_TOKEN;
18757
+ }
18759
18758
  if (environment_default.MINIO_URL) {
18760
18759
  if (opts.presigning && environment_default.MINIO_ENABLED) {
18761
- config.endpoint = "http://minio-service";
18760
+ config.endpoint = "minio-service";
18762
18761
  } else {
18763
18762
  config.endpoint = environment_default.MINIO_URL;
18764
18763
  }
18765
18764
  }
18766
- return new import_client_s3.S3(config);
18765
+ return new import_aws_sdk.default.S3(config);
18767
18766
  }
18768
18767
  async function createBucketIfNotExists(client, bucketName) {
18769
18768
  bucketName = sanitizeBucket(bucketName);
18770
18769
  try {
18771
18770
  await client.headBucket({
18772
18771
  Bucket: bucketName
18773
- });
18772
+ }).promise();
18774
18773
  return { created: false, exists: true };
18775
18774
  } catch (err) {
18776
- const statusCode = err.statusCode || err.$response?.statusCode;
18777
18775
  const promises = STATE.bucketCreationPromises;
18778
- const doesntExist = statusCode === 404, noAccess = statusCode === 403;
18776
+ const doesntExist = err.statusCode === 404, noAccess = err.statusCode === 403;
18779
18777
  if (promises[bucketName]) {
18780
18778
  await promises[bucketName];
18781
18779
  return { created: false, exists: true };
@@ -18783,7 +18781,7 @@ async function createBucketIfNotExists(client, bucketName) {
18783
18781
  if (doesntExist) {
18784
18782
  promises[bucketName] = client.createBucket({
18785
18783
  Bucket: bucketName
18786
- });
18784
+ }).promise();
18787
18785
  await promises[bucketName];
18788
18786
  delete promises[bucketName];
18789
18787
  return { created: true, exists: false };
@@ -18806,20 +18804,21 @@ async function upload({
18806
18804
  }) {
18807
18805
  const extension = filename.split(".").pop();
18808
18806
  const fileBytes = path3 ? (await import_promises.default.open(path3)).createReadStream() : body2;
18809
- const objectStore = ObjectStore();
18807
+ const objectStore = ObjectStore(bucketName);
18810
18808
  const bucketCreated = await createBucketIfNotExists(objectStore, bucketName);
18811
18809
  if (ttl && bucketCreated.created) {
18812
18810
  let ttlConfig = bucketTTLConfig(bucketName, ttl);
18813
- await objectStore.putBucketLifecycleConfiguration(ttlConfig);
18811
+ await objectStore.putBucketLifecycleConfiguration(ttlConfig).promise();
18814
18812
  }
18815
18813
  let contentType = type;
18816
- const finalContentType = contentType ? contentType : extension ? CONTENT_TYPE_MAP[extension.toLowerCase()] : CONTENT_TYPE_MAP.txt;
18814
+ if (!contentType) {
18815
+ contentType = extension ? CONTENT_TYPE_MAP[extension.toLowerCase()] : CONTENT_TYPE_MAP.txt;
18816
+ }
18817
18817
  const config = {
18818
18818
  // windows file paths need to be converted to forward slashes for s3
18819
- Bucket: sanitizeBucket(bucketName),
18820
18819
  Key: sanitizeKey(filename),
18821
18820
  Body: fileBytes,
18822
- ContentType: finalContentType
18821
+ ContentType: contentType
18823
18822
  };
18824
18823
  if (metadata && typeof metadata === "object") {
18825
18824
  for (let key of Object.keys(metadata)) {
@@ -18829,11 +18828,7 @@ async function upload({
18829
18828
  }
18830
18829
  config.Metadata = metadata;
18831
18830
  }
18832
- const upload2 = new import_lib_storage.Upload({
18833
- client: objectStore,
18834
- params: config
18835
- });
18836
- return upload2.done();
18831
+ return objectStore.upload(config).promise();
18837
18832
  }
18838
18833
  async function streamUpload({
18839
18834
  bucket: bucketName,
@@ -18847,11 +18842,11 @@ async function streamUpload({
18847
18842
  throw new Error("Stream to upload is invalid/undefined");
18848
18843
  }
18849
18844
  const extension = filename.split(".").pop();
18850
- const objectStore = ObjectStore();
18845
+ const objectStore = ObjectStore(bucketName);
18851
18846
  const bucketCreated = await createBucketIfNotExists(objectStore, bucketName);
18852
18847
  if (ttl && bucketCreated.created) {
18853
18848
  let ttlConfig = bucketTTLConfig(bucketName, ttl);
18854
- await objectStore.putBucketLifecycleConfiguration(ttlConfig);
18849
+ await objectStore.putBucketLifecycleConfiguration(ttlConfig).promise();
18855
18850
  }
18856
18851
  if (filename?.endsWith(".js")) {
18857
18852
  extra = {
@@ -18876,45 +18871,37 @@ async function streamUpload({
18876
18871
  ContentType: contentType,
18877
18872
  ...extra
18878
18873
  };
18879
- const upload2 = new import_lib_storage.Upload({
18880
- client: objectStore,
18881
- params: params2
18882
- });
18883
- const details = await upload2.done();
18874
+ const details = await objectStore.upload(params2).promise();
18884
18875
  const headDetails = await objectStore.headObject({
18885
18876
  Bucket: bucket,
18886
18877
  Key: objKey
18887
- });
18878
+ }).promise();
18888
18879
  return {
18889
18880
  ...details,
18890
18881
  ContentLength: headDetails.ContentLength
18891
18882
  };
18892
18883
  }
18893
18884
  async function retrieve(bucketName, filepath) {
18894
- const objectStore = ObjectStore();
18885
+ const objectStore = ObjectStore(bucketName);
18895
18886
  const params2 = {
18896
18887
  Bucket: sanitizeBucket(bucketName),
18897
18888
  Key: sanitizeKey(filepath)
18898
18889
  };
18899
- const response = await objectStore.getObject(params2);
18900
- if (!response.Body) {
18901
- throw new Error("Unable to retrieve object");
18902
- }
18903
- const nodeResponse = response.Body;
18890
+ const response = await objectStore.getObject(params2).promise();
18904
18891
  if (STRING_CONTENT_TYPES.includes(response.ContentType)) {
18905
- return nodeResponse.toString();
18892
+ return response.Body.toString("utf8");
18906
18893
  } else {
18907
- return nodeResponse;
18894
+ return response.Body;
18908
18895
  }
18909
18896
  }
18910
18897
  async function listAllObjects(bucketName, path3) {
18911
- const objectStore = ObjectStore();
18898
+ const objectStore = ObjectStore(bucketName);
18912
18899
  const list = (params2 = {}) => {
18913
18900
  return objectStore.listObjectsV2({
18914
18901
  ...params2,
18915
18902
  Bucket: sanitizeBucket(bucketName),
18916
18903
  Prefix: sanitizeKey(path3)
18917
- });
18904
+ }).promise();
18918
18905
  };
18919
18906
  let isTruncated = false, token, objects = [];
18920
18907
  do {
@@ -18931,15 +18918,14 @@ async function listAllObjects(bucketName, path3) {
18931
18918
  } while (isTruncated && token);
18932
18919
  return objects;
18933
18920
  }
18934
- async function getPresignedUrl(bucketName, key, durationSeconds = 3600) {
18935
- const objectStore = ObjectStore({ presigning: true });
18921
+ function getPresignedUrl(bucketName, key, durationSeconds = 3600) {
18922
+ const objectStore = ObjectStore(bucketName, { presigning: true });
18936
18923
  const params2 = {
18937
18924
  Bucket: sanitizeBucket(bucketName),
18938
- Key: sanitizeKey(key)
18925
+ Key: sanitizeKey(key),
18926
+ Expires: durationSeconds
18939
18927
  };
18940
- const url = await (0, import_s3_request_presigner.getSignedUrl)(objectStore, new import_client_s3.GetObjectCommand(params2), {
18941
- expiresIn: durationSeconds
18942
- });
18928
+ const url = objectStore.getSignedUrl("getObject", params2);
18943
18929
  if (!environment_default.MINIO_ENABLED) {
18944
18930
  return url;
18945
18931
  } else {
@@ -18954,11 +18940,7 @@ async function retrieveToTmp(bucketName, filepath) {
18954
18940
  filepath = sanitizeKey(filepath);
18955
18941
  const data = await retrieve(bucketName, filepath);
18956
18942
  const outputPath = (0, import_path2.join)(budibaseTempDir(), (0, import_uuid2.v4)());
18957
- if (data instanceof import_stream2.default.Readable) {
18958
- data.pipe(import_fs3.default.createWriteStream(outputPath));
18959
- } else {
18960
- import_fs3.default.writeFileSync(outputPath, data);
18961
- }
18943
+ import_fs3.default.writeFileSync(outputPath, data);
18962
18944
  return outputPath;
18963
18945
  }
18964
18946
  async function retrieveDirectory(bucketName, path3) {
@@ -18995,16 +18977,16 @@ async function retrieveDirectory(bucketName, path3) {
18995
18977
  return writePath;
18996
18978
  }
18997
18979
  async function deleteFile(bucketName, filepath) {
18998
- const objectStore = ObjectStore();
18980
+ const objectStore = ObjectStore(bucketName);
18999
18981
  await createBucketIfNotExists(objectStore, bucketName);
19000
18982
  const params2 = {
19001
18983
  Bucket: bucketName,
19002
18984
  Key: sanitizeKey(filepath)
19003
18985
  };
19004
- return objectStore.deleteObject(params2);
18986
+ return objectStore.deleteObject(params2).promise();
19005
18987
  }
19006
18988
  async function deleteFiles(bucketName, filepaths) {
19007
- const objectStore = ObjectStore();
18989
+ const objectStore = ObjectStore(bucketName);
19008
18990
  await createBucketIfNotExists(objectStore, bucketName);
19009
18991
  const params2 = {
19010
18992
  Bucket: bucketName,
@@ -19012,17 +18994,17 @@ async function deleteFiles(bucketName, filepaths) {
19012
18994
  Objects: filepaths.map((path3) => ({ Key: sanitizeKey(path3) }))
19013
18995
  }
19014
18996
  };
19015
- return objectStore.deleteObjects(params2);
18997
+ return objectStore.deleteObjects(params2).promise();
19016
18998
  }
19017
18999
  async function deleteFolder(bucketName, folder) {
19018
19000
  bucketName = sanitizeBucket(bucketName);
19019
19001
  folder = sanitizeKey(folder);
19020
- const client = ObjectStore();
19002
+ const client = ObjectStore(bucketName);
19021
19003
  const listParams = {
19022
19004
  Bucket: bucketName,
19023
19005
  Prefix: folder
19024
19006
  };
19025
- const existingObjectsResponse = await client.listObjects(listParams);
19007
+ const existingObjectsResponse = await client.listObjects(listParams).promise();
19026
19008
  if (existingObjectsResponse.Contents?.length === 0) {
19027
19009
  return;
19028
19010
  }
@@ -19035,7 +19017,7 @@ async function deleteFolder(bucketName, folder) {
19035
19017
  existingObjectsResponse.Contents?.forEach((content) => {
19036
19018
  deleteParams.Delete.Objects.push({ Key: content.Key });
19037
19019
  });
19038
- const deleteResponse = await client.deleteObjects(deleteParams);
19020
+ const deleteResponse = await client.deleteObjects(deleteParams).promise();
19039
19021
  if (deleteResponse.Deleted?.length === 1e3) {
19040
19022
  return deleteFolder(bucketName, folder);
19041
19023
  }
@@ -19087,27 +19069,23 @@ async function downloadTarball(url, bucketName, path3) {
19087
19069
  async function getReadStream(bucketName, path3) {
19088
19070
  bucketName = sanitizeBucket(bucketName);
19089
19071
  path3 = sanitizeKey(path3);
19090
- const client = ObjectStore();
19072
+ const client = ObjectStore(bucketName);
19091
19073
  const params2 = {
19092
19074
  Bucket: bucketName,
19093
19075
  Key: path3
19094
19076
  };
19095
- const response = await client.getObject(params2);
19096
- if (!response.Body || !(response.Body instanceof import_stream2.default.Readable)) {
19097
- throw new Error("Unable to retrieve stream - invalid response");
19098
- }
19099
- return response.Body;
19077
+ return client.getObject(params2).createReadStream();
19100
19078
  }
19101
19079
  async function getObjectMetadata(bucket, path3) {
19102
19080
  bucket = sanitizeBucket(bucket);
19103
19081
  path3 = sanitizeKey(path3);
19104
- const client = ObjectStore();
19082
+ const client = ObjectStore(bucket);
19105
19083
  const params2 = {
19106
19084
  Bucket: bucket,
19107
19085
  Key: path3
19108
19086
  };
19109
19087
  try {
19110
- return await client.headObject(params2);
19088
+ return await client.headObject(params2).promise();
19111
19089
  } catch (err) {
19112
19090
  throw new Error("Unable to retrieve metadata from object");
19113
19091
  }
@@ -19165,7 +19143,7 @@ var import_querystring = __toESM(require("querystring"));
19165
19143
  function clientLibraryPath(appId) {
19166
19144
  return `${sanitizeKey(appId)}/budibase-client.js`;
19167
19145
  }
19168
- async function clientLibraryCDNUrl(appId, version) {
19146
+ function clientLibraryCDNUrl(appId, version) {
19169
19147
  let file = clientLibraryPath(appId);
19170
19148
  if (environment_default.CLOUDFRONT_CDN) {
19171
19149
  if (version) {
@@ -19173,7 +19151,7 @@ async function clientLibraryCDNUrl(appId, version) {
19173
19151
  }
19174
19152
  return getUrl(file);
19175
19153
  } else {
19176
- return await getPresignedUrl(environment_default.APPS_BUCKET_NAME, file);
19154
+ return getPresignedUrl(environment_default.APPS_BUCKET_NAME, file);
19177
19155
  }
19178
19156
  }
19179
19157
  function clientLibraryUrl(appId, version) {
@@ -19191,16 +19169,16 @@ function clientLibraryUrl(appId, version) {
19191
19169
  }
19192
19170
  return `/api/assets/client?${import_querystring.default.encode(qsParams)}`;
19193
19171
  }
19194
- async function getAppFileUrl(s3Key) {
19172
+ function getAppFileUrl(s3Key) {
19195
19173
  if (environment_default.CLOUDFRONT_CDN) {
19196
19174
  return getPresignedUrl2(s3Key);
19197
19175
  } else {
19198
- return await getPresignedUrl(environment_default.APPS_BUCKET_NAME, s3Key);
19176
+ return getPresignedUrl(environment_default.APPS_BUCKET_NAME, s3Key);
19199
19177
  }
19200
19178
  }
19201
19179
 
19202
19180
  // src/objectStore/buckets/global.ts
19203
- var getGlobalFileUrl = async (type, name, etag) => {
19181
+ var getGlobalFileUrl = (type, name, etag) => {
19204
19182
  let file = getGlobalFileS3Key(type, name);
19205
19183
  if (environment_default.CLOUDFRONT_CDN) {
19206
19184
  if (etag) {
@@ -19208,7 +19186,7 @@ var getGlobalFileUrl = async (type, name, etag) => {
19208
19186
  }
19209
19187
  return getPresignedUrl2(file);
19210
19188
  } else {
19211
- return await getPresignedUrl(environment_default.GLOBAL_BUCKET_NAME, file);
19189
+ return getPresignedUrl(environment_default.GLOBAL_BUCKET_NAME, file);
19212
19190
  }
19213
19191
  };
19214
19192
  var getGlobalFileS3Key = (type, name) => {
@@ -19221,34 +19199,32 @@ var getGlobalFileS3Key = (type, name) => {
19221
19199
  };
19222
19200
 
19223
19201
  // src/objectStore/buckets/plugins.ts
19224
- async function enrichPluginURLs(plugins) {
19202
+ function enrichPluginURLs(plugins) {
19225
19203
  if (!plugins || !plugins.length) {
19226
19204
  return [];
19227
19205
  }
19228
- return await Promise.all(
19229
- plugins.map(async (plugin) => {
19230
- const jsUrl = await getPluginJSUrl(plugin);
19231
- const iconUrl = await getPluginIconUrl(plugin);
19232
- return { ...plugin, jsUrl, iconUrl };
19233
- })
19234
- );
19206
+ return plugins.map((plugin) => {
19207
+ const jsUrl = getPluginJSUrl(plugin);
19208
+ const iconUrl = getPluginIconUrl(plugin);
19209
+ return { ...plugin, jsUrl, iconUrl };
19210
+ });
19235
19211
  }
19236
- async function getPluginJSUrl(plugin) {
19212
+ function getPluginJSUrl(plugin) {
19237
19213
  const s3Key = getPluginJSKey(plugin);
19238
19214
  return getPluginUrl(s3Key);
19239
19215
  }
19240
- async function getPluginIconUrl(plugin) {
19216
+ function getPluginIconUrl(plugin) {
19241
19217
  const s3Key = getPluginIconKey(plugin);
19242
19218
  if (!s3Key) {
19243
19219
  return;
19244
19220
  }
19245
19221
  return getPluginUrl(s3Key);
19246
19222
  }
19247
- async function getPluginUrl(s3Key) {
19223
+ function getPluginUrl(s3Key) {
19248
19224
  if (environment_default.CLOUDFRONT_CDN) {
19249
19225
  return getPresignedUrl2(s3Key);
19250
19226
  } else {
19251
- return await getPresignedUrl(environment_default.PLUGIN_BUCKET_NAME, s3Key);
19227
+ return getPresignedUrl(environment_default.PLUGIN_BUCKET_NAME, s3Key);
19252
19228
  }
19253
19229
  }
19254
19230
  function getPluginJSKey(plugin) {