@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/query.js CHANGED
@@ -11469,8 +11469,8 @@ async function preAuth(passport2, ctx, next) {
11469
11469
  callbackUrl,
11470
11470
  ssoSaveUserNoOp
11471
11471
  );
11472
- if (!ctx.query.appId) {
11473
- ctx.throw(400, "appId query param not present.");
11472
+ if (!ctx.query.appId || !ctx.query.datasourceId) {
11473
+ ctx.throw(400, "appId and datasourceId query params not present.");
11474
11474
  }
11475
11475
  return passport2.authenticate(strategy, {
11476
11476
  scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
@@ -11490,7 +11490,7 @@ async function postAuth(passport2, ctx, next) {
11490
11490
  clientSecret: config.clientSecret,
11491
11491
  callbackURL: callbackUrl
11492
11492
  },
11493
- (accessToken, refreshToken, _profile, done) => {
11493
+ (accessToken, refreshToken, profile, done) => {
11494
11494
  clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
11495
11495
  done(null, { accessToken, refreshToken });
11496
11496
  }
@@ -11498,14 +11498,22 @@ async function postAuth(passport2, ctx, next) {
11498
11498
  { successRedirect: "/", failureRedirect: "/error" },
11499
11499
  async (err, tokens) => {
11500
11500
  const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
11501
- const id = utils_exports2.newid();
11502
- await cache_exports.store(
11503
- `datasource:creation:${authStateCookie.appId}:google:${id}`,
11504
- {
11505
- tokens
11501
+ await doWithDB(authStateCookie.appId, async (db) => {
11502
+ let datasource2;
11503
+ try {
11504
+ datasource2 = await db.get(authStateCookie.datasourceId);
11505
+ } catch (err2) {
11506
+ if (err2.status === 404) {
11507
+ ctx.redirect(baseUrl);
11508
+ }
11506
11509
  }
11507
- );
11508
- ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
11510
+ if (!datasource2.config) {
11511
+ datasource2.config = {};
11512
+ }
11513
+ datasource2.config.auth = { type: "google", ...tokens };
11514
+ await db.put(datasource2);
11515
+ ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
11516
+ });
11509
11517
  }
11510
11518
  )(ctx, next);
11511
11519
  }
@@ -17243,7 +17251,7 @@ var SCHEMA12 = {
17243
17251
  },
17244
17252
  datasource: {
17245
17253
  spreadsheetId: {
17246
- display: "Spreadsheet URL",
17254
+ display: "Google Sheet URL",
17247
17255
  type: "string" /* STRING */,
17248
17256
  required: true
17249
17257
  }
@@ -17313,7 +17321,6 @@ var GoogleSheetsIntegration = class {
17313
17321
  }
17314
17322
  async testConnection() {
17315
17323
  try {
17316
- await setupCreationAuth(this.config);
17317
17324
  await this.connect();
17318
17325
  return { connected: true };
17319
17326
  } catch (e) {
@@ -17675,16 +17682,6 @@ var GoogleSheetsIntegration = class {
17675
17682
  }
17676
17683
  }
17677
17684
  };
17678
- async function setupCreationAuth(datasouce) {
17679
- if (datasouce.continueSetupId) {
17680
- const appId = context_exports.getAppId();
17681
- const tokens = await cache_exports.get(
17682
- `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
17683
- );
17684
- datasouce.auth = tokens.tokens;
17685
- delete datasouce.continueSetupId;
17686
- }
17687
- }
17688
17685
  var googlesheets_default = {
17689
17686
  schema: SCHEMA12,
17690
17687
  integration: GoogleSheetsIntegration