@budibase/server 2.6.27 → 2.6.28-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5397,11 +5397,11 @@ function makeCacheItem(doc, lastWrite = null) {
5397
5397
  return { doc, lastWrite: lastWrite || Date.now() };
5398
5398
  }
5399
5399
  async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5400
- const cache2 = await getCache();
5400
+ const cache3 = await getCache();
5401
5401
  const key = doc._id;
5402
5402
  let cacheItem;
5403
5403
  if (key) {
5404
- cacheItem = await cache2.get(makeCacheKey(db2, key));
5404
+ cacheItem = await cache3.get(makeCacheKey(db2, key));
5405
5405
  }
5406
5406
  const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
5407
5407
  let output = doc;
@@ -5439,30 +5439,30 @@ async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5439
5439
  }
5440
5440
  cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
5441
5441
  if (output._id) {
5442
- await cache2.store(makeCacheKey(db2, output._id), cacheItem);
5442
+ await cache3.store(makeCacheKey(db2, output._id), cacheItem);
5443
5443
  }
5444
5444
  return { ok: true, id: output._id, rev: output._rev };
5445
5445
  }
5446
5446
  async function get2(db2, id) {
5447
- const cache2 = await getCache();
5447
+ const cache3 = await getCache();
5448
5448
  const cacheKey = makeCacheKey(db2, id);
5449
- let cacheItem = await cache2.get(cacheKey);
5449
+ let cacheItem = await cache3.get(cacheKey);
5450
5450
  if (!cacheItem) {
5451
5451
  const doc = await db2.get(id);
5452
5452
  cacheItem = makeCacheItem(doc);
5453
- await cache2.store(cacheKey, cacheItem);
5453
+ await cache3.store(cacheKey, cacheItem);
5454
5454
  }
5455
5455
  return cacheItem.doc;
5456
5456
  }
5457
5457
  async function remove(db2, docOrId, rev) {
5458
- const cache2 = await getCache();
5458
+ const cache3 = await getCache();
5459
5459
  if (!docOrId) {
5460
5460
  throw new Error("No ID/Rev provided.");
5461
5461
  }
5462
5462
  const id = typeof docOrId === "string" ? docOrId : docOrId._id;
5463
5463
  rev = typeof docOrId === "string" ? rev : docOrId._rev;
5464
5464
  try {
5465
- await cache2.delete(makeCacheKey(db2, id));
5465
+ await cache3.delete(makeCacheKey(db2, id));
5466
5466
  } finally {
5467
5467
  await db2.remove(id, rev);
5468
5468
  }
@@ -10060,8 +10060,8 @@ async function preAuth(passport2, ctx, next) {
10060
10060
  callbackUrl,
10061
10061
  ssoSaveUserNoOp
10062
10062
  );
10063
- if (!ctx.query.appId || !ctx.query.datasourceId) {
10064
- ctx.throw(400, "appId and datasourceId query params not present.");
10063
+ if (!ctx.query.appId) {
10064
+ ctx.throw(400, "appId query param not present.");
10065
10065
  }
10066
10066
  return passport2.authenticate(strategy, {
10067
10067
  scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
@@ -10081,7 +10081,7 @@ async function postAuth(passport2, ctx, next) {
10081
10081
  clientSecret: config.clientSecret,
10082
10082
  callbackURL: callbackUrl
10083
10083
  },
10084
- (accessToken, refreshToken, profile, done) => {
10084
+ (accessToken, refreshToken, _profile, done) => {
10085
10085
  clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
10086
10086
  done(null, { accessToken, refreshToken });
10087
10087
  }
@@ -10089,22 +10089,14 @@ async function postAuth(passport2, ctx, next) {
10089
10089
  { successRedirect: "/", failureRedirect: "/error" },
10090
10090
  async (err, tokens) => {
10091
10091
  const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
10092
- await doWithDB(authStateCookie.appId, async (db2) => {
10093
- let datasource2;
10094
- try {
10095
- datasource2 = await db2.get(authStateCookie.datasourceId);
10096
- } catch (err2) {
10097
- if (err2.status === 404) {
10098
- ctx.redirect(baseUrl);
10099
- }
10100
- }
10101
- if (!datasource2.config) {
10102
- datasource2.config = {};
10092
+ const id = utils_exports2.newid();
10093
+ await cache_exports.store(
10094
+ `datasource:creation:${authStateCookie.appId}:google:${id}`,
10095
+ {
10096
+ tokens
10103
10097
  }
10104
- datasource2.config.auth = { type: "google", ...tokens };
10105
- await db2.put(datasource2);
10106
- ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
10107
- });
10098
+ );
10099
+ ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
10108
10100
  }
10109
10101
  )(ctx, next);
10110
10102
  }
@@ -10114,9 +10106,9 @@ var init_google2 = __esm({
10114
10106
  init_google();
10115
10107
  init_constants2();
10116
10108
  init_utils5();
10117
- init_db5();
10118
10109
  init_configs3();
10119
10110
  init_sso2();
10111
+ init_src2();
10120
10112
  GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
10121
10113
  }
10122
10114
  });
@@ -24847,22 +24839,22 @@ function threadSetup() {
24847
24839
  init10();
24848
24840
  }
24849
24841
  async function checkCacheForDynamicVariable(queryId, variable) {
24850
- const cache2 = await getClient3();
24851
- return cache2.get(makeVariableKey(queryId, variable));
24842
+ const cache3 = await getClient3();
24843
+ return cache3.get(makeVariableKey(queryId, variable));
24852
24844
  }
24853
24845
  async function invalidateDynamicVariables(cachedVars) {
24854
- const cache2 = await getClient3();
24846
+ const cache3 = await getClient3();
24855
24847
  let promises = [];
24856
24848
  for (let variable of cachedVars) {
24857
24849
  promises.push(
24858
- cache2.delete(makeVariableKey(variable.queryId, variable.name))
24850
+ cache3.delete(makeVariableKey(variable.queryId, variable.name))
24859
24851
  );
24860
24852
  }
24861
24853
  await Promise.all(promises);
24862
24854
  }
24863
24855
  async function storeDynamicVariable(queryId, variable, value) {
24864
- const cache2 = await getClient3();
24865
- await cache2.store(
24856
+ const cache3 = await getClient3();
24857
+ await cache3.store(
24866
24858
  makeVariableKey(queryId, variable),
24867
24859
  value,
24868
24860
  VARIABLE_TTL_SECONDS
@@ -29038,9 +29030,20 @@ var init_rest = __esm({
29038
29030
  });
29039
29031
 
29040
29032
  // src/integrations/googlesheets.ts
29033
+ async function setupCreationAuth(datasouce) {
29034
+ if (datasouce.continueSetupId) {
29035
+ const appId = context_exports.getAppId();
29036
+ const tokens = await cache_exports.get(
29037
+ `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
29038
+ );
29039
+ datasouce.auth = tokens.tokens;
29040
+ delete datasouce.continueSetupId;
29041
+ }
29042
+ }
29041
29043
  var import_google_auth_library, import_google_spreadsheet, import_node_fetch10, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
29042
29044
  var init_googlesheets = __esm({
29043
29045
  "src/integrations/googlesheets.ts"() {
29046
+ "use strict";
29044
29047
  init_src();
29045
29048
  import_google_auth_library = require("google-auth-library");
29046
29049
  init_utils19();
@@ -29075,7 +29078,7 @@ var init_googlesheets = __esm({
29075
29078
  },
29076
29079
  datasource: {
29077
29080
  spreadsheetId: {
29078
- display: "Google Sheet URL",
29081
+ display: "Spreadsheet URL",
29079
29082
  type: "string" /* STRING */,
29080
29083
  required: true
29081
29084
  }
@@ -29145,6 +29148,7 @@ var init_googlesheets = __esm({
29145
29148
  }
29146
29149
  async testConnection() {
29147
29150
  try {
29151
+ await setupCreationAuth(this.config);
29148
29152
  await this.connect();
29149
29153
  return { connected: true };
29150
29154
  } catch (e) {
@@ -34793,6 +34797,9 @@ async function save13(ctx) {
34793
34797
  datasource2.entities = tables;
34794
34798
  setDefaultDisplayColumns(datasource2);
34795
34799
  }
34800
+ if (preSaveAction[datasource2.source]) {
34801
+ await preSaveAction[datasource2.source](datasource2);
34802
+ }
34796
34803
  const dbResp = await db2.put(datasource2);
34797
34804
  await events_exports.datasource.created(datasource2);
34798
34805
  datasource2._rev = dbResp.rev;
@@ -34871,6 +34878,7 @@ async function query(ctx) {
34871
34878
  ctx.throw(400, err);
34872
34879
  }
34873
34880
  }
34881
+ var preSaveAction;
34874
34882
  var init_datasource5 = __esm({
34875
34883
  "src/api/controllers/datasource.ts"() {
34876
34884
  init_utils9();
@@ -34880,8 +34888,15 @@ var init_datasource5 = __esm({
34880
34888
  init_utils24();
34881
34889
  init_utils18();
34882
34890
  init_src2();
34891
+ init_src();
34883
34892
  init_sdk3();
34884
34893
  init_websockets();
34894
+ init_googlesheets();
34895
+ preSaveAction = {
34896
+ ["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
34897
+ await setupCreationAuth(datasource2.config);
34898
+ }
34899
+ };
34885
34900
  }
34886
34901
  });
34887
34902