@budibase/server 2.6.24-alpha.2 → 2.6.26

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 cache3 = await getCache();
5398
+ const cache2 = await getCache();
5399
5399
  const key = doc._id;
5400
5400
  let cacheItem;
5401
5401
  if (key) {
5402
- cacheItem = await cache3.get(makeCacheKey(db2, key));
5402
+ cacheItem = await cache2.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 cache3.store(makeCacheKey(db2, output._id), cacheItem);
5440
+ await cache2.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 cache3 = await getCache();
5445
+ const cache2 = await getCache();
5446
5446
  const cacheKey = makeCacheKey(db2, id);
5447
- let cacheItem = await cache3.get(cacheKey);
5447
+ let cacheItem = await cache2.get(cacheKey);
5448
5448
  if (!cacheItem) {
5449
5449
  const doc = await db2.get(id);
5450
5450
  cacheItem = makeCacheItem(doc);
5451
- await cache3.store(cacheKey, cacheItem);
5451
+ await cache2.store(cacheKey, cacheItem);
5452
5452
  }
5453
5453
  return cacheItem.doc;
5454
5454
  }
5455
5455
  async function remove(db2, docOrId, rev) {
5456
- const cache3 = await getCache();
5456
+ const cache2 = 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 cache3.delete(makeCacheKey(db2, id));
5463
+ await cache2.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) {
10055
- ctx.throw(400, "appId query param not present.");
10054
+ if (!ctx.query.appId || !ctx.query.datasourceId) {
10055
+ ctx.throw(400, "appId and datasourceId query params 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,14 +10080,22 @@ 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
- const id = utils_exports2.newid();
10084
- await cache_exports.store(
10085
- `datasource:creation:${authStateCookie.appId}:google:${id}`,
10086
- {
10087
- tokens
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
+ }
10088
10091
  }
10089
- );
10090
- ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
10092
+ if (!datasource2.config) {
10093
+ datasource2.config = {};
10094
+ }
10095
+ datasource2.config.auth = { type: "google", ...tokens };
10096
+ await db2.put(datasource2);
10097
+ ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
10098
+ });
10091
10099
  }
10092
10100
  )(ctx, next);
10093
10101
  }
@@ -10097,9 +10105,9 @@ var init_google2 = __esm({
10097
10105
  init_google();
10098
10106
  init_constants2();
10099
10107
  init_utils5();
10108
+ init_db5();
10100
10109
  init_configs3();
10101
10110
  init_sso2();
10102
- init_src2();
10103
10111
  GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
10104
10112
  }
10105
10113
  });
@@ -24830,22 +24838,22 @@ function threadSetup() {
24830
24838
  init10();
24831
24839
  }
24832
24840
  async function checkCacheForDynamicVariable(queryId, variable) {
24833
- const cache3 = await getClient3();
24834
- return cache3.get(makeVariableKey(queryId, variable));
24841
+ const cache2 = await getClient3();
24842
+ return cache2.get(makeVariableKey(queryId, variable));
24835
24843
  }
24836
24844
  async function invalidateDynamicVariables(cachedVars) {
24837
- const cache3 = await getClient3();
24845
+ const cache2 = await getClient3();
24838
24846
  let promises = [];
24839
24847
  for (let variable of cachedVars) {
24840
24848
  promises.push(
24841
- cache3.delete(makeVariableKey(variable.queryId, variable.name))
24849
+ cache2.delete(makeVariableKey(variable.queryId, variable.name))
24842
24850
  );
24843
24851
  }
24844
24852
  await Promise.all(promises);
24845
24853
  }
24846
24854
  async function storeDynamicVariable(queryId, variable, value) {
24847
- const cache3 = await getClient3();
24848
- await cache3.store(
24855
+ const cache2 = await getClient3();
24856
+ await cache2.store(
24849
24857
  makeVariableKey(queryId, variable),
24850
24858
  value,
24851
24859
  VARIABLE_TTL_SECONDS
@@ -29021,20 +29029,9 @@ var init_rest = __esm({
29021
29029
  });
29022
29030
 
29023
29031
  // 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
- }
29034
29032
  var import_google_auth_library, import_google_spreadsheet, import_node_fetch10, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
29035
29033
  var init_googlesheets = __esm({
29036
29034
  "src/integrations/googlesheets.ts"() {
29037
- "use strict";
29038
29035
  init_src();
29039
29036
  import_google_auth_library = require("google-auth-library");
29040
29037
  init_utils19();
@@ -29069,7 +29066,7 @@ var init_googlesheets = __esm({
29069
29066
  },
29070
29067
  datasource: {
29071
29068
  spreadsheetId: {
29072
- display: "Spreadsheet URL",
29069
+ display: "Google Sheet URL",
29073
29070
  type: "string" /* STRING */,
29074
29071
  required: true
29075
29072
  }
@@ -29139,7 +29136,6 @@ var init_googlesheets = __esm({
29139
29136
  }
29140
29137
  async testConnection() {
29141
29138
  try {
29142
- await setupCreationAuth(this.config);
29143
29139
  await this.connect();
29144
29140
  return { connected: true };
29145
29141
  } catch (e) {
@@ -34787,9 +34783,6 @@ async function save13(ctx) {
34787
34783
  datasource2.entities = tables;
34788
34784
  setDefaultDisplayColumns(datasource2);
34789
34785
  }
34790
- if (preSaveAction[datasource2.source]) {
34791
- await preSaveAction[datasource2.source](datasource2);
34792
- }
34793
34786
  const dbResp = await db2.put(datasource2);
34794
34787
  await events_exports.datasource.created(datasource2);
34795
34788
  datasource2._rev = dbResp.rev;
@@ -34868,7 +34861,6 @@ async function query(ctx) {
34868
34861
  ctx.throw(400, err);
34869
34862
  }
34870
34863
  }
34871
- var preSaveAction;
34872
34864
  var init_datasource5 = __esm({
34873
34865
  "src/api/controllers/datasource.ts"() {
34874
34866
  init_utils9();
@@ -34878,15 +34870,8 @@ var init_datasource5 = __esm({
34878
34870
  init_utils24();
34879
34871
  init_utils18();
34880
34872
  init_src2();
34881
- init_src();
34882
34873
  init_sdk3();
34883
34874
  init_websockets();
34884
- init_googlesheets();
34885
- preSaveAction = {
34886
- ["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
34887
- await setupCreationAuth(datasource2.config);
34888
- }
34889
- };
34890
34875
  }
34891
34876
  });
34892
34877