@budibase/server 2.7.5-alpha.0 → 2.7.6

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
@@ -11478,8 +11478,8 @@ async function preAuth(passport2, ctx, next) {
11478
11478
  callbackUrl,
11479
11479
  ssoSaveUserNoOp
11480
11480
  );
11481
- if (!ctx.query.appId) {
11482
- ctx.throw(400, "appId query param not present.");
11481
+ if (!ctx.query.appId || !ctx.query.datasourceId) {
11482
+ ctx.throw(400, "appId and datasourceId query params not present.");
11483
11483
  }
11484
11484
  return passport2.authenticate(strategy, {
11485
11485
  scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
@@ -11499,7 +11499,7 @@ async function postAuth(passport2, ctx, next) {
11499
11499
  clientSecret: config.clientSecret,
11500
11500
  callbackURL: callbackUrl
11501
11501
  },
11502
- (accessToken, refreshToken, _profile, done) => {
11502
+ (accessToken, refreshToken, profile, done) => {
11503
11503
  clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
11504
11504
  done(null, { accessToken, refreshToken });
11505
11505
  }
@@ -11507,14 +11507,22 @@ async function postAuth(passport2, ctx, next) {
11507
11507
  { successRedirect: "/", failureRedirect: "/error" },
11508
11508
  async (err, tokens) => {
11509
11509
  const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
11510
- const id = utils_exports2.newid();
11511
- await cache_exports.store(
11512
- `datasource:creation:${authStateCookie.appId}:google:${id}`,
11513
- {
11514
- tokens
11510
+ await doWithDB(authStateCookie.appId, async (db) => {
11511
+ let datasource2;
11512
+ try {
11513
+ datasource2 = await db.get(authStateCookie.datasourceId);
11514
+ } catch (err2) {
11515
+ if (err2.status === 404) {
11516
+ ctx.redirect(baseUrl);
11517
+ }
11515
11518
  }
11516
- );
11517
- ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
11519
+ if (!datasource2.config) {
11520
+ datasource2.config = {};
11521
+ }
11522
+ datasource2.config.auth = { type: "google", ...tokens };
11523
+ await db.put(datasource2);
11524
+ ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
11525
+ });
11518
11526
  }
11519
11527
  )(ctx, next);
11520
11528
  }
@@ -17252,7 +17260,7 @@ var SCHEMA12 = {
17252
17260
  },
17253
17261
  datasource: {
17254
17262
  spreadsheetId: {
17255
- display: "Spreadsheet URL",
17263
+ display: "Google Sheet URL",
17256
17264
  type: "string" /* STRING */,
17257
17265
  required: true
17258
17266
  }
@@ -17322,7 +17330,6 @@ var GoogleSheetsIntegration = class {
17322
17330
  }
17323
17331
  async testConnection() {
17324
17332
  try {
17325
- await setupCreationAuth(this.config);
17326
17333
  await this.connect();
17327
17334
  return { connected: true };
17328
17335
  } catch (e) {
@@ -17684,16 +17691,6 @@ var GoogleSheetsIntegration = class {
17684
17691
  }
17685
17692
  }
17686
17693
  };
17687
- async function setupCreationAuth(datasouce) {
17688
- if (datasouce.continueSetupId) {
17689
- const appId = context_exports.getAppId();
17690
- const tokens = await cache_exports.get(
17691
- `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
17692
- );
17693
- datasouce.auth = tokens.tokens;
17694
- delete datasouce.continueSetupId;
17695
- }
17696
- }
17697
17694
  var googlesheets_default = {
17698
17695
  schema: SCHEMA12,
17699
17696
  integration: GoogleSheetsIntegration