@budibase/server 2.7.7-alpha.2 → 2.7.9

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
@@ -838,7 +838,6 @@ var init_automation2 = __esm({
838
838
  AutomationIOType2["NUMBER"] = "number";
839
839
  AutomationIOType2["ARRAY"] = "array";
840
840
  AutomationIOType2["JSON"] = "json";
841
- AutomationIOType2["DATE"] = "date";
842
841
  return AutomationIOType2;
843
842
  })(AutomationIOType || {});
844
843
  AutomationCustomIOType = /* @__PURE__ */ ((AutomationCustomIOType2) => {
@@ -11479,8 +11478,8 @@ async function preAuth(passport2, ctx, next) {
11479
11478
  callbackUrl,
11480
11479
  ssoSaveUserNoOp
11481
11480
  );
11482
- if (!ctx.query.appId) {
11483
- 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.");
11484
11483
  }
11485
11484
  return passport2.authenticate(strategy, {
11486
11485
  scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
@@ -11500,7 +11499,7 @@ async function postAuth(passport2, ctx, next) {
11500
11499
  clientSecret: config.clientSecret,
11501
11500
  callbackURL: callbackUrl
11502
11501
  },
11503
- (accessToken, refreshToken, _profile, done) => {
11502
+ (accessToken, refreshToken, profile, done) => {
11504
11503
  clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
11505
11504
  done(null, { accessToken, refreshToken });
11506
11505
  }
@@ -11508,14 +11507,22 @@ async function postAuth(passport2, ctx, next) {
11508
11507
  { successRedirect: "/", failureRedirect: "/error" },
11509
11508
  async (err, tokens) => {
11510
11509
  const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
11511
- const id = newid();
11512
- await store(
11513
- `datasource:creation:${authStateCookie.appId}:google:${id}`,
11514
- {
11515
- 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
+ }
11516
11518
  }
11517
- );
11518
- 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
+ });
11519
11526
  }
11520
11527
  )(ctx, next);
11521
11528
  }
@@ -17253,7 +17260,7 @@ var SCHEMA12 = {
17253
17260
  },
17254
17261
  datasource: {
17255
17262
  spreadsheetId: {
17256
- display: "Spreadsheet URL",
17263
+ display: "Google Sheet URL",
17257
17264
  type: "string" /* STRING */,
17258
17265
  required: true
17259
17266
  }
@@ -17323,7 +17330,6 @@ var GoogleSheetsIntegration = class {
17323
17330
  }
17324
17331
  async testConnection() {
17325
17332
  try {
17326
- await setupCreationAuth(this.config);
17327
17333
  await this.connect();
17328
17334
  return { connected: true };
17329
17335
  } catch (e) {
@@ -17685,16 +17691,6 @@ var GoogleSheetsIntegration = class {
17685
17691
  }
17686
17692
  }
17687
17693
  };
17688
- async function setupCreationAuth(datasouce) {
17689
- if (datasouce.continueSetupId) {
17690
- const appId = context_exports.getAppId();
17691
- const tokens = await cache_exports.get(
17692
- `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
17693
- );
17694
- datasouce.auth = tokens.tokens;
17695
- delete datasouce.continueSetupId;
17696
- }
17697
- }
17698
17694
  var googlesheets_default = {
17699
17695
  schema: SCHEMA12,
17700
17696
  integration: GoogleSheetsIntegration
@@ -23426,7 +23422,7 @@ function mergeConfigs(update7, old) {
23426
23422
  }
23427
23423
  if (hasAuthConfigs(update7)) {
23428
23424
  const configs = update7.config.authConfigs;
23429
- const oldConfigs = (_a = old.config) == null ? void 0 : _a.authConfigs;
23425
+ const oldConfigs = ((_a = old.config) == null ? void 0 : _a.authConfigs) || [];
23430
23426
  for (let config of configs) {
23431
23427
  if (config.type !== "basic" /* BASIC */) {
23432
23428
  continue;