@budibase/server 2.6.28-alpha.0 → 2.6.28

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 cache3 = await getCache();
5400
+ const cache2 = await getCache();
5401
5401
  const key = doc._id;
5402
5402
  let cacheItem;
5403
5403
  if (key) {
5404
- cacheItem = await cache3.get(makeCacheKey(db2, key));
5404
+ cacheItem = await cache2.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 cache3.store(makeCacheKey(db2, output._id), cacheItem);
5442
+ await cache2.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 cache3 = await getCache();
5447
+ const cache2 = await getCache();
5448
5448
  const cacheKey = makeCacheKey(db2, id);
5449
- let cacheItem = await cache3.get(cacheKey);
5449
+ let cacheItem = await cache2.get(cacheKey);
5450
5450
  if (!cacheItem) {
5451
5451
  const doc = await db2.get(id);
5452
5452
  cacheItem = makeCacheItem(doc);
5453
- await cache3.store(cacheKey, cacheItem);
5453
+ await cache2.store(cacheKey, cacheItem);
5454
5454
  }
5455
5455
  return cacheItem.doc;
5456
5456
  }
5457
5457
  async function remove(db2, docOrId, rev) {
5458
- const cache3 = await getCache();
5458
+ const cache2 = 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 cache3.delete(makeCacheKey(db2, id));
5465
+ await cache2.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) {
10064
- ctx.throw(400, "appId query param not present.");
10063
+ if (!ctx.query.appId || !ctx.query.datasourceId) {
10064
+ ctx.throw(400, "appId and datasourceId query params 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,14 +10089,22 @@ 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
- const id = utils_exports2.newid();
10093
- await cache_exports.store(
10094
- `datasource:creation:${authStateCookie.appId}:google:${id}`,
10095
- {
10096
- tokens
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
+ }
10097
10100
  }
10098
- );
10099
- ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
10101
+ if (!datasource2.config) {
10102
+ datasource2.config = {};
10103
+ }
10104
+ datasource2.config.auth = { type: "google", ...tokens };
10105
+ await db2.put(datasource2);
10106
+ ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
10107
+ });
10100
10108
  }
10101
10109
  )(ctx, next);
10102
10110
  }
@@ -10106,9 +10114,9 @@ var init_google2 = __esm({
10106
10114
  init_google();
10107
10115
  init_constants2();
10108
10116
  init_utils5();
10117
+ init_db5();
10109
10118
  init_configs3();
10110
10119
  init_sso2();
10111
- init_src2();
10112
10120
  GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
10113
10121
  }
10114
10122
  });
@@ -24839,22 +24847,22 @@ function threadSetup() {
24839
24847
  init10();
24840
24848
  }
24841
24849
  async function checkCacheForDynamicVariable(queryId, variable) {
24842
- const cache3 = await getClient3();
24843
- return cache3.get(makeVariableKey(queryId, variable));
24850
+ const cache2 = await getClient3();
24851
+ return cache2.get(makeVariableKey(queryId, variable));
24844
24852
  }
24845
24853
  async function invalidateDynamicVariables(cachedVars) {
24846
- const cache3 = await getClient3();
24854
+ const cache2 = await getClient3();
24847
24855
  let promises = [];
24848
24856
  for (let variable of cachedVars) {
24849
24857
  promises.push(
24850
- cache3.delete(makeVariableKey(variable.queryId, variable.name))
24858
+ cache2.delete(makeVariableKey(variable.queryId, variable.name))
24851
24859
  );
24852
24860
  }
24853
24861
  await Promise.all(promises);
24854
24862
  }
24855
24863
  async function storeDynamicVariable(queryId, variable, value) {
24856
- const cache3 = await getClient3();
24857
- await cache3.store(
24864
+ const cache2 = await getClient3();
24865
+ await cache2.store(
24858
24866
  makeVariableKey(queryId, variable),
24859
24867
  value,
24860
24868
  VARIABLE_TTL_SECONDS
@@ -29030,20 +29038,9 @@ var init_rest = __esm({
29030
29038
  });
29031
29039
 
29032
29040
  // 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
- }
29043
29041
  var import_google_auth_library, import_google_spreadsheet, import_node_fetch10, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
29044
29042
  var init_googlesheets = __esm({
29045
29043
  "src/integrations/googlesheets.ts"() {
29046
- "use strict";
29047
29044
  init_src();
29048
29045
  import_google_auth_library = require("google-auth-library");
29049
29046
  init_utils19();
@@ -29078,7 +29075,7 @@ var init_googlesheets = __esm({
29078
29075
  },
29079
29076
  datasource: {
29080
29077
  spreadsheetId: {
29081
- display: "Spreadsheet URL",
29078
+ display: "Google Sheet URL",
29082
29079
  type: "string" /* STRING */,
29083
29080
  required: true
29084
29081
  }
@@ -29148,7 +29145,6 @@ var init_googlesheets = __esm({
29148
29145
  }
29149
29146
  async testConnection() {
29150
29147
  try {
29151
- await setupCreationAuth(this.config);
29152
29148
  await this.connect();
29153
29149
  return { connected: true };
29154
29150
  } catch (e) {
@@ -34797,9 +34793,6 @@ async function save13(ctx) {
34797
34793
  datasource2.entities = tables;
34798
34794
  setDefaultDisplayColumns(datasource2);
34799
34795
  }
34800
- if (preSaveAction[datasource2.source]) {
34801
- await preSaveAction[datasource2.source](datasource2);
34802
- }
34803
34796
  const dbResp = await db2.put(datasource2);
34804
34797
  await events_exports.datasource.created(datasource2);
34805
34798
  datasource2._rev = dbResp.rev;
@@ -34878,7 +34871,6 @@ async function query(ctx) {
34878
34871
  ctx.throw(400, err);
34879
34872
  }
34880
34873
  }
34881
- var preSaveAction;
34882
34874
  var init_datasource5 = __esm({
34883
34875
  "src/api/controllers/datasource.ts"() {
34884
34876
  init_utils9();
@@ -34888,15 +34880,8 @@ var init_datasource5 = __esm({
34888
34880
  init_utils24();
34889
34881
  init_utils18();
34890
34882
  init_src2();
34891
- init_src();
34892
34883
  init_sdk3();
34893
34884
  init_websockets();
34894
- init_googlesheets();
34895
- preSaveAction = {
34896
- ["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
34897
- await setupCreationAuth(datasource2.config);
34898
- }
34899
- };
34900
34885
  }
34901
34886
  });
34902
34887