@budibase/server 2.6.24-alpha.1 → 2.6.24-alpha.2

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
@@ -5395,11 +5395,11 @@ function makeCacheItem(doc, lastWrite = null) {
5395
5395
  return { doc, lastWrite: lastWrite || Date.now() };
5396
5396
  }
5397
5397
  async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5398
- const cache2 = await getCache();
5398
+ const cache3 = await getCache();
5399
5399
  const key = doc._id;
5400
5400
  let cacheItem;
5401
5401
  if (key) {
5402
- cacheItem = await cache2.get(makeCacheKey(db2, key));
5402
+ cacheItem = await cache3.get(makeCacheKey(db2, key));
5403
5403
  }
5404
5404
  const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
5405
5405
  let output = doc;
@@ -5437,30 +5437,30 @@ async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5437
5437
  }
5438
5438
  cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
5439
5439
  if (output._id) {
5440
- await cache2.store(makeCacheKey(db2, output._id), cacheItem);
5440
+ await cache3.store(makeCacheKey(db2, output._id), cacheItem);
5441
5441
  }
5442
5442
  return { ok: true, id: output._id, rev: output._rev };
5443
5443
  }
5444
5444
  async function get2(db2, id) {
5445
- const cache2 = await getCache();
5445
+ const cache3 = await getCache();
5446
5446
  const cacheKey = makeCacheKey(db2, id);
5447
- let cacheItem = await cache2.get(cacheKey);
5447
+ let cacheItem = await cache3.get(cacheKey);
5448
5448
  if (!cacheItem) {
5449
5449
  const doc = await db2.get(id);
5450
5450
  cacheItem = makeCacheItem(doc);
5451
- await cache2.store(cacheKey, cacheItem);
5451
+ await cache3.store(cacheKey, cacheItem);
5452
5452
  }
5453
5453
  return cacheItem.doc;
5454
5454
  }
5455
5455
  async function remove(db2, docOrId, rev) {
5456
- const cache2 = await getCache();
5456
+ const cache3 = await getCache();
5457
5457
  if (!docOrId) {
5458
5458
  throw new Error("No ID/Rev provided.");
5459
5459
  }
5460
5460
  const id = typeof docOrId === "string" ? docOrId : docOrId._id;
5461
5461
  rev = typeof docOrId === "string" ? rev : docOrId._rev;
5462
5462
  try {
5463
- await cache2.delete(makeCacheKey(db2, id));
5463
+ await cache3.delete(makeCacheKey(db2, id));
5464
5464
  } finally {
5465
5465
  await db2.remove(id, rev);
5466
5466
  }
@@ -10051,8 +10051,8 @@ async function preAuth(passport2, ctx, next) {
10051
10051
  callbackUrl,
10052
10052
  ssoSaveUserNoOp
10053
10053
  );
10054
- if (!ctx.query.appId || !ctx.query.datasourceId) {
10055
- ctx.throw(400, "appId and datasourceId query params not present.");
10054
+ if (!ctx.query.appId) {
10055
+ ctx.throw(400, "appId query param not present.");
10056
10056
  }
10057
10057
  return passport2.authenticate(strategy, {
10058
10058
  scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
@@ -10072,7 +10072,7 @@ async function postAuth(passport2, ctx, next) {
10072
10072
  clientSecret: config.clientSecret,
10073
10073
  callbackURL: callbackUrl
10074
10074
  },
10075
- (accessToken, refreshToken, profile, done) => {
10075
+ (accessToken, refreshToken, _profile, done) => {
10076
10076
  clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
10077
10077
  done(null, { accessToken, refreshToken });
10078
10078
  }
@@ -10080,22 +10080,14 @@ async function postAuth(passport2, ctx, next) {
10080
10080
  { successRedirect: "/", failureRedirect: "/error" },
10081
10081
  async (err, tokens) => {
10082
10082
  const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
10083
- await doWithDB(authStateCookie.appId, async (db2) => {
10084
- let datasource2;
10085
- try {
10086
- datasource2 = await db2.get(authStateCookie.datasourceId);
10087
- } catch (err2) {
10088
- if (err2.status === 404) {
10089
- ctx.redirect(baseUrl);
10090
- }
10091
- }
10092
- if (!datasource2.config) {
10093
- datasource2.config = {};
10083
+ const id = utils_exports2.newid();
10084
+ await cache_exports.store(
10085
+ `datasource:creation:${authStateCookie.appId}:google:${id}`,
10086
+ {
10087
+ tokens
10094
10088
  }
10095
- datasource2.config.auth = { type: "google", ...tokens };
10096
- await db2.put(datasource2);
10097
- ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
10098
- });
10089
+ );
10090
+ ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
10099
10091
  }
10100
10092
  )(ctx, next);
10101
10093
  }
@@ -10105,9 +10097,9 @@ var init_google2 = __esm({
10105
10097
  init_google();
10106
10098
  init_constants2();
10107
10099
  init_utils5();
10108
- init_db5();
10109
10100
  init_configs3();
10110
10101
  init_sso2();
10102
+ init_src2();
10111
10103
  GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
10112
10104
  }
10113
10105
  });
@@ -24838,22 +24830,22 @@ function threadSetup() {
24838
24830
  init10();
24839
24831
  }
24840
24832
  async function checkCacheForDynamicVariable(queryId, variable) {
24841
- const cache2 = await getClient3();
24842
- return cache2.get(makeVariableKey(queryId, variable));
24833
+ const cache3 = await getClient3();
24834
+ return cache3.get(makeVariableKey(queryId, variable));
24843
24835
  }
24844
24836
  async function invalidateDynamicVariables(cachedVars) {
24845
- const cache2 = await getClient3();
24837
+ const cache3 = await getClient3();
24846
24838
  let promises = [];
24847
24839
  for (let variable of cachedVars) {
24848
24840
  promises.push(
24849
- cache2.delete(makeVariableKey(variable.queryId, variable.name))
24841
+ cache3.delete(makeVariableKey(variable.queryId, variable.name))
24850
24842
  );
24851
24843
  }
24852
24844
  await Promise.all(promises);
24853
24845
  }
24854
24846
  async function storeDynamicVariable(queryId, variable, value) {
24855
- const cache2 = await getClient3();
24856
- await cache2.store(
24847
+ const cache3 = await getClient3();
24848
+ await cache3.store(
24857
24849
  makeVariableKey(queryId, variable),
24858
24850
  value,
24859
24851
  VARIABLE_TTL_SECONDS
@@ -29029,9 +29021,20 @@ var init_rest = __esm({
29029
29021
  });
29030
29022
 
29031
29023
  // src/integrations/googlesheets.ts
29024
+ async function setupCreationAuth(datasouce) {
29025
+ if (datasouce.continueSetupId) {
29026
+ const appId = context_exports.getAppId();
29027
+ const tokens = await cache_exports.get(
29028
+ `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
29029
+ );
29030
+ datasouce.auth = tokens.tokens;
29031
+ delete datasouce.continueSetupId;
29032
+ }
29033
+ }
29032
29034
  var import_google_auth_library, import_google_spreadsheet, import_node_fetch10, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
29033
29035
  var init_googlesheets = __esm({
29034
29036
  "src/integrations/googlesheets.ts"() {
29037
+ "use strict";
29035
29038
  init_src();
29036
29039
  import_google_auth_library = require("google-auth-library");
29037
29040
  init_utils19();
@@ -29066,7 +29069,7 @@ var init_googlesheets = __esm({
29066
29069
  },
29067
29070
  datasource: {
29068
29071
  spreadsheetId: {
29069
- display: "Google Sheet URL",
29072
+ display: "Spreadsheet URL",
29070
29073
  type: "string" /* STRING */,
29071
29074
  required: true
29072
29075
  }
@@ -29136,6 +29139,7 @@ var init_googlesheets = __esm({
29136
29139
  }
29137
29140
  async testConnection() {
29138
29141
  try {
29142
+ await setupCreationAuth(this.config);
29139
29143
  await this.connect();
29140
29144
  return { connected: true };
29141
29145
  } catch (e) {
@@ -34783,6 +34787,9 @@ async function save13(ctx) {
34783
34787
  datasource2.entities = tables;
34784
34788
  setDefaultDisplayColumns(datasource2);
34785
34789
  }
34790
+ if (preSaveAction[datasource2.source]) {
34791
+ await preSaveAction[datasource2.source](datasource2);
34792
+ }
34786
34793
  const dbResp = await db2.put(datasource2);
34787
34794
  await events_exports.datasource.created(datasource2);
34788
34795
  datasource2._rev = dbResp.rev;
@@ -34861,6 +34868,7 @@ async function query(ctx) {
34861
34868
  ctx.throw(400, err);
34862
34869
  }
34863
34870
  }
34871
+ var preSaveAction;
34864
34872
  var init_datasource5 = __esm({
34865
34873
  "src/api/controllers/datasource.ts"() {
34866
34874
  init_utils9();
@@ -34870,8 +34878,15 @@ var init_datasource5 = __esm({
34870
34878
  init_utils24();
34871
34879
  init_utils18();
34872
34880
  init_src2();
34881
+ init_src();
34873
34882
  init_sdk3();
34874
34883
  init_websockets();
34884
+ init_googlesheets();
34885
+ preSaveAction = {
34886
+ ["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
34887
+ await setupCreationAuth(datasource2.config);
34888
+ }
34889
+ };
34875
34890
  }
34876
34891
  });
34877
34892