@budibase/server 2.7.1-alpha.1 → 2.7.3

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,8 +8,8 @@
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.933787a7.js"></script>
12
- <link rel="stylesheet" href="/builder/assets/index.b33e8ad5.css">
11
+ <script type="module" crossorigin src="/builder/assets/index.4ca5529d.js"></script>
12
+ <link rel="stylesheet" href="/builder/assets/index.a86e2071.css">
13
13
  </head>
14
14
 
15
15
  <body id="app">
@@ -5357,11 +5357,11 @@ function makeCacheItem(doc, lastWrite = null) {
5357
5357
  return { doc, lastWrite: lastWrite || Date.now() };
5358
5358
  }
5359
5359
  async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5360
- const cache3 = await getCache();
5360
+ const cache2 = await getCache();
5361
5361
  const key = doc._id;
5362
5362
  let cacheItem;
5363
5363
  if (key) {
5364
- cacheItem = await cache3.get(makeCacheKey(db2, key));
5364
+ cacheItem = await cache2.get(makeCacheKey(db2, key));
5365
5365
  }
5366
5366
  const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
5367
5367
  let output = doc;
@@ -5399,30 +5399,30 @@ async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5399
5399
  }
5400
5400
  cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
5401
5401
  if (output._id) {
5402
- await cache3.store(makeCacheKey(db2, output._id), cacheItem);
5402
+ await cache2.store(makeCacheKey(db2, output._id), cacheItem);
5403
5403
  }
5404
5404
  return { ok: true, id: output._id, rev: output._rev };
5405
5405
  }
5406
5406
  async function get2(db2, id) {
5407
- const cache3 = await getCache();
5407
+ const cache2 = await getCache();
5408
5408
  const cacheKey = makeCacheKey(db2, id);
5409
- let cacheItem = await cache3.get(cacheKey);
5409
+ let cacheItem = await cache2.get(cacheKey);
5410
5410
  if (!cacheItem) {
5411
5411
  const doc = await db2.get(id);
5412
5412
  cacheItem = makeCacheItem(doc);
5413
- await cache3.store(cacheKey, cacheItem);
5413
+ await cache2.store(cacheKey, cacheItem);
5414
5414
  }
5415
5415
  return cacheItem.doc;
5416
5416
  }
5417
5417
  async function remove(db2, docOrId, rev) {
5418
- const cache3 = await getCache();
5418
+ const cache2 = await getCache();
5419
5419
  if (!docOrId) {
5420
5420
  throw new Error("No ID/Rev provided.");
5421
5421
  }
5422
5422
  const id = typeof docOrId === "string" ? docOrId : docOrId._id;
5423
5423
  rev = typeof docOrId === "string" ? rev : docOrId._rev;
5424
5424
  try {
5425
- await cache3.delete(makeCacheKey(db2, id));
5425
+ await cache2.delete(makeCacheKey(db2, id));
5426
5426
  } finally {
5427
5427
  await db2.remove(id, rev);
5428
5428
  }
@@ -9781,8 +9781,8 @@ async function preAuth(passport2, ctx, next) {
9781
9781
  callbackUrl,
9782
9782
  ssoSaveUserNoOp
9783
9783
  );
9784
- if (!ctx.query.appId) {
9785
- ctx.throw(400, "appId query param not present.");
9784
+ if (!ctx.query.appId || !ctx.query.datasourceId) {
9785
+ ctx.throw(400, "appId and datasourceId query params not present.");
9786
9786
  }
9787
9787
  return passport2.authenticate(strategy, {
9788
9788
  scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
@@ -9802,7 +9802,7 @@ async function postAuth(passport2, ctx, next) {
9802
9802
  clientSecret: config.clientSecret,
9803
9803
  callbackURL: callbackUrl
9804
9804
  },
9805
- (accessToken, refreshToken, _profile, done) => {
9805
+ (accessToken, refreshToken, profile, done) => {
9806
9806
  clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
9807
9807
  done(null, { accessToken, refreshToken });
9808
9808
  }
@@ -9810,14 +9810,22 @@ async function postAuth(passport2, ctx, next) {
9810
9810
  { successRedirect: "/", failureRedirect: "/error" },
9811
9811
  async (err, tokens) => {
9812
9812
  const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
9813
- const id = utils_exports2.newid();
9814
- await cache_exports.store(
9815
- `datasource:creation:${authStateCookie.appId}:google:${id}`,
9816
- {
9817
- tokens
9813
+ await doWithDB(authStateCookie.appId, async (db2) => {
9814
+ let datasource2;
9815
+ try {
9816
+ datasource2 = await db2.get(authStateCookie.datasourceId);
9817
+ } catch (err2) {
9818
+ if (err2.status === 404) {
9819
+ ctx.redirect(baseUrl);
9820
+ }
9818
9821
  }
9819
- );
9820
- ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
9822
+ if (!datasource2.config) {
9823
+ datasource2.config = {};
9824
+ }
9825
+ datasource2.config.auth = { type: "google", ...tokens };
9826
+ await db2.put(datasource2);
9827
+ ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
9828
+ });
9821
9829
  }
9822
9830
  )(ctx, next);
9823
9831
  }
@@ -9827,9 +9835,9 @@ var init_google2 = __esm({
9827
9835
  init_google();
9828
9836
  init_constants2();
9829
9837
  init_utils5();
9838
+ init_db5();
9830
9839
  init_configs3();
9831
9840
  init_sso2();
9832
- init_src2();
9833
9841
  GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
9834
9842
  }
9835
9843
  });
@@ -23803,16 +23811,6 @@ var init_rest = __esm({
23803
23811
  });
23804
23812
 
23805
23813
  // src/integrations/googlesheets.ts
23806
- async function setupCreationAuth(datasouce) {
23807
- if (datasouce.continueSetupId) {
23808
- const appId = context_exports.getAppId();
23809
- const tokens = await cache_exports.get(
23810
- `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
23811
- );
23812
- datasouce.auth = tokens.tokens;
23813
- delete datasouce.continueSetupId;
23814
- }
23815
- }
23816
23814
  var import_google_auth_library, import_google_spreadsheet, import_node_fetch9, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
23817
23815
  var init_googlesheets = __esm({
23818
23816
  "src/integrations/googlesheets.ts"() {
@@ -23850,7 +23848,7 @@ var init_googlesheets = __esm({
23850
23848
  },
23851
23849
  datasource: {
23852
23850
  spreadsheetId: {
23853
- display: "Spreadsheet URL",
23851
+ display: "Google Sheet URL",
23854
23852
  type: "string" /* STRING */,
23855
23853
  required: true
23856
23854
  }
@@ -23920,7 +23918,6 @@ var init_googlesheets = __esm({
23920
23918
  }
23921
23919
  async testConnection() {
23922
23920
  try {
23923
- await setupCreationAuth(this.config);
23924
23921
  await this.connect();
23925
23922
  return { connected: true };
23926
23923
  } catch (e) {
@@ -26892,22 +26889,22 @@ function threadSetup() {
26892
26889
  init8();
26893
26890
  }
26894
26891
  async function checkCacheForDynamicVariable(queryId, variable) {
26895
- const cache3 = await getClient2();
26896
- return cache3.get(makeVariableKey(queryId, variable));
26892
+ const cache2 = await getClient2();
26893
+ return cache2.get(makeVariableKey(queryId, variable));
26897
26894
  }
26898
26895
  async function invalidateDynamicVariables(cachedVars) {
26899
- const cache3 = await getClient2();
26896
+ const cache2 = await getClient2();
26900
26897
  let promises = [];
26901
26898
  for (let variable of cachedVars) {
26902
26899
  promises.push(
26903
- cache3.delete(makeVariableKey(variable.queryId, variable.name))
26900
+ cache2.delete(makeVariableKey(variable.queryId, variable.name))
26904
26901
  );
26905
26902
  }
26906
26903
  await Promise.all(promises);
26907
26904
  }
26908
26905
  async function storeDynamicVariable(queryId, variable, value) {
26909
- const cache3 = await getClient2();
26910
- await cache3.store(
26906
+ const cache2 = await getClient2();
26907
+ await cache2.store(
26911
26908
  makeVariableKey(queryId, variable),
26912
26909
  value,
26913
26910
  VARIABLE_TTL_SECONDS
@@ -30685,15 +30682,8 @@ init_constants6();
30685
30682
  init_integrations2();
30686
30683
  init_utils20();
30687
30684
  init_src2();
30688
- init_src();
30689
30685
  init_sdk3();
30690
30686
  init_websockets();
30691
- init_googlesheets();
30692
- var preSaveAction = {
30693
- ["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
30694
- await setupCreationAuth(datasource2.config);
30695
- }
30696
- };
30697
30687
 
30698
30688
  // src/api/controllers/query/validation.ts
30699
30689
  init_src2();