@budibase/server 2.7.6 → 2.7.7-alpha.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.7.6",
4
+ "version": "2.7.7-alpha.1",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -46,12 +46,12 @@
46
46
  "license": "GPL-3.0",
47
47
  "dependencies": {
48
48
  "@apidevtools/swagger-parser": "10.0.3",
49
- "@budibase/backend-core": "2.7.6",
50
- "@budibase/client": "2.7.6",
51
- "@budibase/pro": "2.7.6",
52
- "@budibase/shared-core": "2.7.6",
53
- "@budibase/string-templates": "2.7.6",
54
- "@budibase/types": "2.7.6",
49
+ "@budibase/backend-core": "2.7.7-alpha.1",
50
+ "@budibase/client": "2.7.7-alpha.1",
51
+ "@budibase/pro": "2.7.7-alpha.1",
52
+ "@budibase/shared-core": "2.7.7-alpha.1",
53
+ "@budibase/string-templates": "2.7.7-alpha.1",
54
+ "@budibase/types": "2.7.7-alpha.1",
55
55
  "@bull-board/api": "3.7.0",
56
56
  "@bull-board/koa": "3.9.4",
57
57
  "@elastic/elasticsearch": "7.10.0",
@@ -195,5 +195,5 @@
195
195
  }
196
196
  }
197
197
  },
198
- "gitHead": "f35112cc9cd7ee93c9dcb43bc68ea6e86ac786a9"
198
+ "gitHead": "b73360642ae0e50fa114678d88a102f060f9b07b"
199
199
  }
@@ -11,7 +11,7 @@ import { BuildSchemaErrors, InvalidColumns } from "../../constants"
11
11
  import { getIntegration } from "../../integrations"
12
12
  import { getDatasourceAndQuery } from "./row/utils"
13
13
  import { invalidateDynamicVariables } from "../../threads/utils"
14
- import { db as dbCore, context, events } from "@budibase/backend-core"
14
+ import { db as dbCore, context, events, cache } from "@budibase/backend-core"
15
15
  import {
16
16
  UserCtx,
17
17
  Datasource,
@@ -25,9 +25,11 @@ import {
25
25
  FetchDatasourceInfoResponse,
26
26
  IntegrationBase,
27
27
  DatasourcePlus,
28
+ SourceName,
28
29
  } from "@budibase/types"
29
30
  import sdk from "../../sdk"
30
31
  import { builderSocket } from "../../websockets"
32
+ import { setupCreationAuth as googleSetupCreationAuth } from "../../integrations/googlesheets"
31
33
 
32
34
  function getErrorTables(errors: any, errorType: string) {
33
35
  return Object.entries(errors)
@@ -306,6 +308,12 @@ export async function update(ctx: UserCtx<any, UpdateDatasourceResponse>) {
306
308
  builderSocket?.emitDatasourceUpdate(ctx, datasource)
307
309
  }
308
310
 
311
+ const preSaveAction: Partial<Record<SourceName, any>> = {
312
+ [SourceName.GOOGLE_SHEETS]: async (datasource: Datasource) => {
313
+ await googleSetupCreationAuth(datasource.config as any)
314
+ },
315
+ }
316
+
309
317
  export async function save(
310
318
  ctx: UserCtx<CreateDatasourceRequest, CreateDatasourceResponse>
311
319
  ) {
@@ -327,6 +335,10 @@ export async function save(
327
335
  setDefaultDisplayColumns(datasource)
328
336
  }
329
337
 
338
+ if (preSaveAction[datasource.source]) {
339
+ await preSaveAction[datasource.source](datasource)
340
+ }
341
+
330
342
  const dbResp = await db.put(datasource)
331
343
  await events.datasource.created(datasource)
332
344
  datasource._rev = dbResp.rev
@@ -1,6 +1,6 @@
1
1
  require("svelte/register")
2
2
 
3
- import { resolve, join } from "../../../utilities/centralPath"
3
+ import { join } from "../../../utilities/centralPath"
4
4
  const uuid = require("uuid")
5
5
  import { ObjectStoreBuckets } from "../../../constants"
6
6
  import { processString } from "@budibase/string-templates"
@@ -49,7 +49,7 @@ export const toggleBetaUiFeature = async function (ctx: any) {
49
49
  return
50
50
  }
51
51
 
52
- let builderPath = resolve(TOP_LEVEL_PATH, "new_design_ui")
52
+ let builderPath = join(TOP_LEVEL_PATH, "new_design_ui")
53
53
 
54
54
  // // download it from S3
55
55
  if (!fs.existsSync(builderPath)) {
@@ -67,7 +67,7 @@ export const toggleBetaUiFeature = async function (ctx: any) {
67
67
  }
68
68
 
69
69
  export const serveBuilder = async function (ctx: any) {
70
- const builderPath = resolve(TOP_LEVEL_PATH, "builder")
70
+ const builderPath = join(TOP_LEVEL_PATH, "builder")
71
71
  await send(ctx, ctx.file, { root: builderPath })
72
72
  }
73
73
 
@@ -98,7 +98,8 @@ const environment = {
98
98
  isInThread: () => {
99
99
  return process.env.FORKED_PROCESS
100
100
  },
101
- TOP_LEVEL_PATH: process.env.TOP_LEVEL_PATH,
101
+ TOP_LEVEL_PATH:
102
+ process.env.TOP_LEVEL_PATH || process.env.SERVER_TOP_LEVEL_PATH,
102
103
  }
103
104
 
104
105
  // threading can cause memory issues with node-ts in development
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ConnectionInfo,
3
+ Datasource,
3
4
  DatasourceFeature,
4
5
  DatasourceFieldType,
5
6
  DatasourcePlus,
@@ -19,13 +20,15 @@ import { OAuth2Client } from "google-auth-library"
19
20
  import { buildExternalTableId, finaliseExternalTables } from "./utils"
20
21
  import { GoogleSpreadsheet, GoogleSpreadsheetRow } from "google-spreadsheet"
21
22
  import fetch from "node-fetch"
22
- import { configs, HTTPError } from "@budibase/backend-core"
23
+ import { cache, configs, context, HTTPError } from "@budibase/backend-core"
23
24
  import { dataFilters } from "@budibase/shared-core"
24
25
  import { GOOGLE_SHEETS_PRIMARY_KEY } from "../constants"
26
+ import sdk from "../sdk"
25
27
 
26
28
  interface GoogleSheetsConfig {
27
29
  spreadsheetId: string
28
30
  auth: OAuthClientConfig
31
+ continueSetupId?: string
29
32
  }
30
33
 
31
34
  interface OAuthClientConfig {
@@ -72,7 +75,7 @@ const SCHEMA: Integration = {
72
75
  },
73
76
  datasource: {
74
77
  spreadsheetId: {
75
- display: "Google Sheet URL",
78
+ display: "Spreadsheet URL",
76
79
  type: DatasourceFieldType.STRING,
77
80
  required: true,
78
81
  },
@@ -147,6 +150,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
147
150
 
148
151
  async testConnection(): Promise<ConnectionInfo> {
149
152
  try {
153
+ await setupCreationAuth(this.config)
150
154
  await this.connect()
151
155
  return { connected: true }
152
156
  } catch (e: any) {
@@ -566,6 +570,18 @@ class GoogleSheetsIntegration implements DatasourcePlus {
566
570
  }
567
571
  }
568
572
 
573
+ export async function setupCreationAuth(datasouce: GoogleSheetsConfig) {
574
+ if (datasouce.continueSetupId) {
575
+ const appId = context.getAppId()
576
+ const tokens = await cache.get(
577
+ `datasource:creation:${appId}:google:${datasouce.continueSetupId}`
578
+ )
579
+
580
+ datasouce.auth = tokens.tokens
581
+ delete datasouce.continueSetupId
582
+ }
583
+ }
584
+
569
585
  export default {
570
586
  schema: SCHEMA,
571
587
  integration: GoogleSheetsIntegration,
@@ -1,14 +1,14 @@
1
1
  import { PathLike } from "fs"
2
2
  import fs from "fs"
3
3
  import { budibaseTempDir } from "../budibaseDir"
4
- import { join } from "path"
4
+ import { resolve, join } from "path"
5
5
  import env from "../../environment"
6
6
  import tar from "tar"
7
7
  import environment from "../../environment"
8
8
  const uuid = require("uuid/v4")
9
9
 
10
10
  export const TOP_LEVEL_PATH =
11
- environment.TOP_LEVEL_PATH || join(__dirname, "..", "..", "..")
11
+ environment.TOP_LEVEL_PATH || resolve(join(__dirname, "..", "..", ".."))
12
12
 
13
13
  /**
14
14
  * Upon first startup of instance there may not be everything we need in tmp directory, set it up.