@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.
@@ -8,7 +8,7 @@
8
8
  <link rel="preconnect" href="https://fonts.gstatic.com" />
9
9
  <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap"
10
10
  rel="stylesheet" />
11
- <script type="module" crossorigin src="/builder/assets/index.c0b0be95.js"></script>
11
+ <script type="module" crossorigin src="/builder/assets/index.edf18bd3.js"></script>
12
12
  <link rel="stylesheet" href="/builder/assets/index.b33e8ad5.css">
13
13
  </head>
14
14
 
@@ -5355,11 +5355,11 @@ function makeCacheItem(doc, lastWrite = null) {
5355
5355
  return { doc, lastWrite: lastWrite || Date.now() };
5356
5356
  }
5357
5357
  async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5358
- const cache2 = await getCache();
5358
+ const cache3 = await getCache();
5359
5359
  const key = doc._id;
5360
5360
  let cacheItem;
5361
5361
  if (key) {
5362
- cacheItem = await cache2.get(makeCacheKey(db2, key));
5362
+ cacheItem = await cache3.get(makeCacheKey(db2, key));
5363
5363
  }
5364
5364
  const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
5365
5365
  let output = doc;
@@ -5397,30 +5397,30 @@ async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5397
5397
  }
5398
5398
  cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
5399
5399
  if (output._id) {
5400
- await cache2.store(makeCacheKey(db2, output._id), cacheItem);
5400
+ await cache3.store(makeCacheKey(db2, output._id), cacheItem);
5401
5401
  }
5402
5402
  return { ok: true, id: output._id, rev: output._rev };
5403
5403
  }
5404
5404
  async function get2(db2, id) {
5405
- const cache2 = await getCache();
5405
+ const cache3 = await getCache();
5406
5406
  const cacheKey = makeCacheKey(db2, id);
5407
- let cacheItem = await cache2.get(cacheKey);
5407
+ let cacheItem = await cache3.get(cacheKey);
5408
5408
  if (!cacheItem) {
5409
5409
  const doc = await db2.get(id);
5410
5410
  cacheItem = makeCacheItem(doc);
5411
- await cache2.store(cacheKey, cacheItem);
5411
+ await cache3.store(cacheKey, cacheItem);
5412
5412
  }
5413
5413
  return cacheItem.doc;
5414
5414
  }
5415
5415
  async function remove(db2, docOrId, rev) {
5416
- const cache2 = await getCache();
5416
+ const cache3 = await getCache();
5417
5417
  if (!docOrId) {
5418
5418
  throw new Error("No ID/Rev provided.");
5419
5419
  }
5420
5420
  const id = typeof docOrId === "string" ? docOrId : docOrId._id;
5421
5421
  rev = typeof docOrId === "string" ? rev : docOrId._rev;
5422
5422
  try {
5423
- await cache2.delete(makeCacheKey(db2, id));
5423
+ await cache3.delete(makeCacheKey(db2, id));
5424
5424
  } finally {
5425
5425
  await db2.remove(id, rev);
5426
5426
  }
@@ -9772,8 +9772,8 @@ async function preAuth(passport2, ctx, next) {
9772
9772
  callbackUrl,
9773
9773
  ssoSaveUserNoOp
9774
9774
  );
9775
- if (!ctx.query.appId || !ctx.query.datasourceId) {
9776
- ctx.throw(400, "appId and datasourceId query params not present.");
9775
+ if (!ctx.query.appId) {
9776
+ ctx.throw(400, "appId query param not present.");
9777
9777
  }
9778
9778
  return passport2.authenticate(strategy, {
9779
9779
  scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
@@ -9793,7 +9793,7 @@ async function postAuth(passport2, ctx, next) {
9793
9793
  clientSecret: config.clientSecret,
9794
9794
  callbackURL: callbackUrl
9795
9795
  },
9796
- (accessToken, refreshToken, profile, done) => {
9796
+ (accessToken, refreshToken, _profile, done) => {
9797
9797
  clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
9798
9798
  done(null, { accessToken, refreshToken });
9799
9799
  }
@@ -9801,22 +9801,14 @@ async function postAuth(passport2, ctx, next) {
9801
9801
  { successRedirect: "/", failureRedirect: "/error" },
9802
9802
  async (err, tokens) => {
9803
9803
  const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
9804
- await doWithDB(authStateCookie.appId, async (db2) => {
9805
- let datasource2;
9806
- try {
9807
- datasource2 = await db2.get(authStateCookie.datasourceId);
9808
- } catch (err2) {
9809
- if (err2.status === 404) {
9810
- ctx.redirect(baseUrl);
9811
- }
9812
- }
9813
- if (!datasource2.config) {
9814
- datasource2.config = {};
9804
+ const id = utils_exports2.newid();
9805
+ await cache_exports.store(
9806
+ `datasource:creation:${authStateCookie.appId}:google:${id}`,
9807
+ {
9808
+ tokens
9815
9809
  }
9816
- datasource2.config.auth = { type: "google", ...tokens };
9817
- await db2.put(datasource2);
9818
- ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
9819
- });
9810
+ );
9811
+ ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
9820
9812
  }
9821
9813
  )(ctx, next);
9822
9814
  }
@@ -9826,9 +9818,9 @@ var init_google2 = __esm({
9826
9818
  init_google();
9827
9819
  init_constants2();
9828
9820
  init_utils5();
9829
- init_db5();
9830
9821
  init_configs3();
9831
9822
  init_sso2();
9823
+ init_src2();
9832
9824
  GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
9833
9825
  }
9834
9826
  });
@@ -23802,9 +23794,20 @@ var init_rest = __esm({
23802
23794
  });
23803
23795
 
23804
23796
  // src/integrations/googlesheets.ts
23797
+ async function setupCreationAuth(datasouce) {
23798
+ if (datasouce.continueSetupId) {
23799
+ const appId = context_exports.getAppId();
23800
+ const tokens = await cache_exports.get(
23801
+ `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
23802
+ );
23803
+ datasouce.auth = tokens.tokens;
23804
+ delete datasouce.continueSetupId;
23805
+ }
23806
+ }
23805
23807
  var import_google_auth_library, import_google_spreadsheet, import_node_fetch9, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
23806
23808
  var init_googlesheets = __esm({
23807
23809
  "src/integrations/googlesheets.ts"() {
23810
+ "use strict";
23808
23811
  init_src();
23809
23812
  import_google_auth_library = require("google-auth-library");
23810
23813
  init_utils14();
@@ -23839,7 +23842,7 @@ var init_googlesheets = __esm({
23839
23842
  },
23840
23843
  datasource: {
23841
23844
  spreadsheetId: {
23842
- display: "Google Sheet URL",
23845
+ display: "Spreadsheet URL",
23843
23846
  type: "string" /* STRING */,
23844
23847
  required: true
23845
23848
  }
@@ -23909,6 +23912,7 @@ var init_googlesheets = __esm({
23909
23912
  }
23910
23913
  async testConnection() {
23911
23914
  try {
23915
+ await setupCreationAuth(this.config);
23912
23916
  await this.connect();
23913
23917
  return { connected: true };
23914
23918
  } catch (e) {
@@ -26880,22 +26884,22 @@ function threadSetup() {
26880
26884
  init8();
26881
26885
  }
26882
26886
  async function checkCacheForDynamicVariable(queryId, variable) {
26883
- const cache2 = await getClient2();
26884
- return cache2.get(makeVariableKey(queryId, variable));
26887
+ const cache3 = await getClient2();
26888
+ return cache3.get(makeVariableKey(queryId, variable));
26885
26889
  }
26886
26890
  async function invalidateDynamicVariables(cachedVars) {
26887
- const cache2 = await getClient2();
26891
+ const cache3 = await getClient2();
26888
26892
  let promises = [];
26889
26893
  for (let variable of cachedVars) {
26890
26894
  promises.push(
26891
- cache2.delete(makeVariableKey(variable.queryId, variable.name))
26895
+ cache3.delete(makeVariableKey(variable.queryId, variable.name))
26892
26896
  );
26893
26897
  }
26894
26898
  await Promise.all(promises);
26895
26899
  }
26896
26900
  async function storeDynamicVariable(queryId, variable, value) {
26897
- const cache2 = await getClient2();
26898
- await cache2.store(
26901
+ const cache3 = await getClient2();
26902
+ await cache3.store(
26899
26903
  makeVariableKey(queryId, variable),
26900
26904
  value,
26901
26905
  VARIABLE_TTL_SECONDS
@@ -30673,8 +30677,15 @@ init_constants6();
30673
30677
  init_integrations2();
30674
30678
  init_utils20();
30675
30679
  init_src2();
30680
+ init_src();
30676
30681
  init_sdk3();
30677
30682
  init_websockets();
30683
+ init_googlesheets();
30684
+ var preSaveAction = {
30685
+ ["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
30686
+ await setupCreationAuth(datasource2.config);
30687
+ }
30688
+ };
30678
30689
 
30679
30690
  // src/api/controllers/query/validation.ts
30680
30691
  init_src2();