@budibase/server 1.3.21 → 1.3.22-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/__mocks__/mongodb.ts +1 -1
- package/builder/assets/index.96c69636.js +1008 -0
- package/builder/assets/index.c167b5c3.css +6 -0
- package/builder/index.html +2 -4
- package/coverage/clover.xml +308 -338
- package/coverage/coverage-final.json +19 -21
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +41 -8
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +73 -34
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +27 -57
- package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +13 -13
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +2 -2
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +9 -9
- package/coverage/lcov-report/api/routes/utils/validators.js.html +75 -12
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +1 -1
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +14 -14
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +30 -18
- package/coverage/lcov-report/events/AutomationEmitter.js.html +3 -3
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +44 -44
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +12 -12
- package/coverage/lcov-report/middleware/currentapp.js.html +46 -40
- package/coverage/lcov-report/middleware/index.html +15 -15
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +16 -16
- package/coverage/lcov-report/utilities/index.html +15 -15
- package/coverage/lcov-report/utilities/index.js.html +24 -24
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +32 -8
- package/coverage/lcov.info +521 -558
- package/dist/api/controllers/application.js +5 -5
- package/dist/api/controllers/auth.js +9 -0
- package/dist/api/controllers/component.js +19 -6
- package/dist/api/controllers/datasource.js +21 -8
- package/dist/api/controllers/deploy/index.js +1 -8
- package/dist/api/controllers/integration.js +4 -4
- package/dist/{migrations/functions/usageQuotas/syncDevelopers.js → api/controllers/plugin/file.js} +13 -13
- package/dist/api/controllers/plugin/github.js +69 -0
- package/dist/api/controllers/plugin/index.js +144 -0
- package/dist/api/controllers/plugin/npm.js +58 -0
- package/dist/api/controllers/plugin/uploaders.js +11 -0
- package/dist/{migrations/functions/usageQuotas/syncPublishedApps.js → api/controllers/plugin/url.js} +13 -15
- package/dist/api/controllers/plugin/utils.js +26 -0
- package/dist/api/controllers/row/external.js +1 -1
- package/dist/api/controllers/screen.js +62 -14
- package/dist/api/controllers/static/index.js +1 -0
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +10 -0
- package/dist/api/controllers/static/templates/preview.hbs +5 -1
- package/dist/api/index.js +1 -1
- package/dist/api/routes/application.js +3 -2
- package/dist/api/routes/index.js +2 -0
- package/dist/{migrations/functions/publishedAppsQuota.js → api/routes/plugin.js} +13 -21
- package/dist/api/routes/public/rows.js +1 -82
- package/dist/api/routes/public/tables.js +1 -1
- package/dist/api/routes/table.js +1 -1
- package/dist/api/routes/utils/validators.js +20 -2
- package/dist/app.js +16 -1
- package/dist/db/utils.js +3 -0
- package/dist/environment.js +1 -0
- package/dist/integrations/airtable.js +126 -129
- package/dist/integrations/arangodb.js +86 -89
- package/dist/integrations/base/query.js +2 -2
- package/dist/integrations/base/sqlTable.js +3 -1
- package/dist/integrations/couchdb.js +80 -83
- package/dist/integrations/dynamodb.js +161 -164
- package/dist/integrations/elasticsearch.js +135 -138
- package/dist/integrations/firebase.js +154 -157
- package/dist/integrations/googlesheets.js +323 -327
- package/dist/integrations/index.js +99 -51
- package/dist/integrations/microsoftSqlServer.js +240 -243
- package/dist/integrations/mongodb.js +239 -242
- package/dist/integrations/mysql.js +215 -219
- package/dist/integrations/oracle.js +318 -322
- package/dist/integrations/postgres.js +262 -265
- package/dist/integrations/redis.js +134 -139
- package/dist/integrations/rest.js +289 -292
- package/dist/integrations/s3.js +61 -64
- package/dist/integrations/snowflake.js +83 -86
- package/dist/middleware/currentapp.js +2 -0
- package/dist/migrations/functions/backfill/global.js +0 -3
- package/dist/migrations/index.js +0 -10
- package/dist/package.json +9 -6
- package/dist/tests/utilities/TestConfiguration.js +1 -1
- package/dist/threads/query.js +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +105 -1
- package/dist/utilities/workerRequests.js +4 -0
- package/dist/watch.js +77 -0
- package/dist/websocket.js +22 -0
- package/package.json +10 -7
- package/scripts/dev/manage.js +4 -0
- package/scripts/localdomain.js +3 -1
- package/specs/openapi.json +115 -112
- package/specs/openapi.yaml +96 -94
- package/specs/resources/misc.js +116 -0
- package/specs/resources/query.js +1 -1
- package/src/api/controllers/application.ts +1 -2
- package/src/api/controllers/auth.js +11 -0
- package/src/api/controllers/component.ts +57 -0
- package/src/api/controllers/datasource.js +21 -8
- package/src/api/controllers/deploy/index.ts +1 -6
- package/src/api/controllers/integration.js +4 -4
- package/src/api/controllers/plugin/file.ts +15 -0
- package/src/api/controllers/plugin/github.ts +75 -0
- package/src/api/controllers/plugin/index.ts +134 -0
- package/src/api/controllers/plugin/npm.ts +56 -0
- package/src/api/controllers/plugin/uploaders.ts +4 -0
- package/src/api/controllers/plugin/url.ts +12 -0
- package/src/api/controllers/plugin/utils.ts +19 -0
- package/src/api/controllers/public/mapping/types.ts +8 -0
- package/src/api/controllers/row/external.js +1 -1
- package/src/api/controllers/screen.ts +122 -0
- package/src/api/controllers/static/index.ts +1 -1
- package/src/api/controllers/static/templates/BudibaseApp.svelte +10 -0
- package/src/api/controllers/static/templates/preview.hbs +5 -1
- package/src/api/index.js +1 -1
- package/src/api/routes/application.ts +13 -2
- package/src/api/routes/index.ts +2 -0
- package/src/api/routes/plugin.ts +14 -0
- package/src/api/routes/public/rows.ts +1 -82
- package/src/api/routes/public/tables.ts +1 -1
- package/src/api/routes/table.js +1 -1
- package/src/api/routes/tests/query.spec.js +8 -25
- package/src/api/routes/tests/user.spec.js +0 -2
- package/src/api/routes/utils/validators.js +26 -5
- package/src/app.ts +25 -2
- package/src/db/utils.js +4 -0
- package/src/definitions/openapi.ts +56 -55
- package/src/environment.js +1 -0
- package/src/integrations/airtable.ts +116 -118
- package/src/integrations/arangodb.ts +87 -89
- package/src/integrations/base/query.ts +2 -2
- package/src/integrations/base/sqlTable.ts +3 -1
- package/src/integrations/couchdb.ts +83 -89
- package/src/integrations/dynamodb.ts +173 -175
- package/src/integrations/elasticsearch.ts +120 -122
- package/src/integrations/firebase.ts +157 -159
- package/src/integrations/googlesheets.ts +328 -338
- package/src/integrations/index.ts +64 -21
- package/src/integrations/microsoftSqlServer.ts +249 -251
- package/src/integrations/mongodb.ts +261 -258
- package/src/integrations/mysql.ts +229 -234
- package/src/integrations/oracle.ts +373 -380
- package/src/integrations/postgres.ts +264 -268
- package/src/integrations/redis.ts +128 -132
- package/src/integrations/rest.ts +324 -329
- package/src/integrations/s3.ts +68 -71
- package/src/integrations/snowflake.ts +80 -82
- package/src/integrations/tests/{airtable.spec.js → airtable.spec.ts} +21 -18
- package/src/integrations/tests/{arangodb.spec.js → arangodb.spec.ts} +12 -9
- package/src/integrations/tests/{couchdb.spec.js → couchdb.spec.ts} +33 -27
- package/src/integrations/tests/{dynamodb.spec.js → dynamodb.spec.ts} +45 -41
- package/src/integrations/tests/{elasticsearch.spec.js → elasticsearch.spec.ts} +22 -21
- package/src/integrations/tests/{firebase.spec.js → firebase.spec.ts} +33 -28
- package/src/integrations/tests/{microsoftSqlServer.spec.js → microsoftSqlServer.spec.ts} +12 -11
- package/src/integrations/tests/{mongo.spec.js → mongo.spec.ts} +46 -35
- package/src/integrations/tests/{mysql.spec.js → mysql.spec.ts} +17 -15
- package/src/integrations/tests/{oracle.spec.js → oracle.spec.ts} +19 -17
- package/src/integrations/tests/{postgres.spec.js → postgres.spec.ts} +19 -17
- package/src/integrations/tests/{redis.spec.js → redis.spec.ts} +27 -18
- package/src/integrations/tests/{rest.spec.js → rest.spec.ts} +22 -14
- package/src/integrations/tests/{s3.spec.js → s3.spec.ts} +10 -8
- package/src/integrations/tests/{sql.spec.js → sql.spec.ts} +228 -177
- package/src/middleware/currentapp.js +2 -0
- package/src/migrations/functions/backfill/global.ts +0 -3
- package/src/migrations/index.ts +0 -16
- package/src/module.d.ts +2 -0
- package/src/tests/utilities/TestConfiguration.js +1 -1
- package/src/threads/query.ts +2 -2
- package/src/utilities/fileSystem/index.js +123 -0
- package/src/utilities/workerRequests.js +8 -0
- package/src/watch.ts +38 -0
- package/src/websocket.ts +26 -0
- package/builder/assets/index.8d12d461.css +0 -6
- package/builder/assets/index.d354271c.js +0 -879
- package/builder/assets/vendor.5e1fe644.css +0 -1
- package/builder/assets/vendor.67dbd8fa.js +0 -248
- package/coverage/lcov-report/api/controllers/component.js.html +0 -199
- package/coverage/lcov-report/api/controllers/screen.js.html +0 -259
- package/dist/migrations/functions/developerQuota.js +0 -49
- package/src/api/controllers/component.js +0 -38
- package/src/api/controllers/screen.js +0 -58
- package/src/migrations/functions/developerQuota.ts +0 -15
- package/src/migrations/functions/publishedAppsQuota.ts +0 -13
- package/src/migrations/functions/usageQuotas/syncDevelopers.ts +0 -19
- package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +0 -21
|
@@ -18,365 +18,361 @@ const utils_1 = require("./utils");
|
|
|
18
18
|
const constants_1 = require("../constants");
|
|
19
19
|
const google_spreadsheet_1 = require("google-spreadsheet");
|
|
20
20
|
const environment_1 = __importDefault(require("../environment"));
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy");
|
|
22
|
+
const { getScopedConfig } = require("@budibase/backend-core/db");
|
|
23
|
+
const { Configs } = require("@budibase/backend-core/constants");
|
|
24
|
+
const fetch = require("node-fetch");
|
|
25
|
+
const SCHEMA = {
|
|
26
|
+
plus: true,
|
|
27
|
+
auth: {
|
|
28
|
+
type: "google",
|
|
29
|
+
},
|
|
30
|
+
relationships: false,
|
|
31
|
+
docs: "https://developers.google.com/sheets/api/quickstart/nodejs",
|
|
32
|
+
description: "Create and collaborate on online spreadsheets in real-time and from any device. ",
|
|
33
|
+
friendlyName: "Google Sheets",
|
|
34
|
+
type: "Spreadsheet",
|
|
35
|
+
datasource: {
|
|
36
|
+
spreadsheetId: {
|
|
37
|
+
display: "Google Sheet URL",
|
|
38
|
+
type: types_1.DatasourceFieldType.STRING,
|
|
39
|
+
required: true,
|
|
31
40
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
},
|
|
42
|
+
query: {
|
|
43
|
+
create: {
|
|
44
|
+
type: types_1.QueryType.FIELDS,
|
|
45
|
+
fields: {
|
|
46
|
+
sheet: {
|
|
47
|
+
type: types_1.DatasourceFieldType.STRING,
|
|
48
|
+
required: true,
|
|
49
|
+
},
|
|
50
|
+
row: {
|
|
51
|
+
type: types_1.QueryType.JSON,
|
|
52
|
+
required: true,
|
|
53
|
+
},
|
|
42
54
|
},
|
|
43
55
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
required: true,
|
|
51
|
-
},
|
|
52
|
-
row: {
|
|
53
|
-
type: types_1.QueryType.JSON,
|
|
54
|
-
required: true,
|
|
55
|
-
},
|
|
56
|
+
read: {
|
|
57
|
+
type: types_1.QueryType.FIELDS,
|
|
58
|
+
fields: {
|
|
59
|
+
sheet: {
|
|
60
|
+
type: types_1.DatasourceFieldType.STRING,
|
|
61
|
+
required: true,
|
|
56
62
|
},
|
|
57
63
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
},
|
|
65
|
+
update: {
|
|
66
|
+
type: types_1.QueryType.FIELDS,
|
|
67
|
+
fields: {
|
|
68
|
+
sheet: {
|
|
69
|
+
type: types_1.DatasourceFieldType.STRING,
|
|
70
|
+
required: true,
|
|
65
71
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
rowIndex: {
|
|
75
|
-
type: types_1.DatasourceFieldType.STRING,
|
|
76
|
-
required: true,
|
|
77
|
-
},
|
|
78
|
-
row: {
|
|
79
|
-
type: types_1.QueryType.JSON,
|
|
80
|
-
required: true,
|
|
81
|
-
},
|
|
72
|
+
rowIndex: {
|
|
73
|
+
type: types_1.DatasourceFieldType.STRING,
|
|
74
|
+
required: true,
|
|
75
|
+
},
|
|
76
|
+
row: {
|
|
77
|
+
type: types_1.QueryType.JSON,
|
|
78
|
+
required: true,
|
|
82
79
|
},
|
|
83
80
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
81
|
+
},
|
|
82
|
+
delete: {
|
|
83
|
+
type: types_1.QueryType.FIELDS,
|
|
84
|
+
fields: {
|
|
85
|
+
sheet: {
|
|
86
|
+
type: types_1.DatasourceFieldType.STRING,
|
|
87
|
+
required: true,
|
|
88
|
+
},
|
|
89
|
+
rowIndex: {
|
|
90
|
+
type: types_1.DatasourceFieldType.NUMBER,
|
|
91
|
+
required: true,
|
|
95
92
|
},
|
|
96
93
|
},
|
|
97
94
|
},
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
class GoogleSheetsIntegration {
|
|
98
|
+
constructor(config) {
|
|
99
|
+
this.tables = {};
|
|
100
|
+
this.schemaErrors = {};
|
|
101
|
+
this.config = config;
|
|
102
|
+
const spreadsheetId = this.cleanSpreadsheetUrl(this.config.spreadsheetId);
|
|
103
|
+
this.client = new google_spreadsheet_1.GoogleSpreadsheet(spreadsheetId);
|
|
104
|
+
}
|
|
105
|
+
getBindingIdentifier() {
|
|
106
|
+
return "";
|
|
107
|
+
}
|
|
108
|
+
getStringConcat(parts) {
|
|
109
|
+
return "";
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Pull the spreadsheet ID out from a valid google sheets URL
|
|
113
|
+
* @param spreadsheetId - the URL or standard spreadsheetId of the google sheet
|
|
114
|
+
* @returns spreadsheet Id of the google sheet
|
|
115
|
+
*/
|
|
116
|
+
cleanSpreadsheetUrl(spreadsheetId) {
|
|
117
|
+
if (!spreadsheetId) {
|
|
118
|
+
throw new Error("You must set a spreadsheet ID in your configuration to fetch tables.");
|
|
112
119
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
const parts = spreadsheetId.split("/");
|
|
121
|
+
return parts.length > 5 ? parts[5] : spreadsheetId;
|
|
122
|
+
}
|
|
123
|
+
fetchAccessToken(payload) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const response = yield fetch("https://www.googleapis.com/oauth2/v4/token", {
|
|
126
|
+
method: "POST",
|
|
127
|
+
body: JSON.stringify(Object.assign(Object.assign({}, payload), { grant_type: "refresh_token" })),
|
|
128
|
+
headers: {
|
|
129
|
+
"Content-Type": "application/json",
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
const json = yield response.json();
|
|
133
|
+
if (response.status !== 200) {
|
|
134
|
+
throw new Error(`Error authenticating with google sheets. ${json.error_description}`);
|
|
121
135
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
},
|
|
136
|
+
return json;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
connect() {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
try {
|
|
142
|
+
// Initialise oAuth client
|
|
143
|
+
const db = getGlobalDB();
|
|
144
|
+
let googleConfig = yield getScopedConfig(db, {
|
|
145
|
+
type: Configs.GOOGLE,
|
|
133
146
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
connect() {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
try {
|
|
144
|
-
// Initialise oAuth client
|
|
145
|
-
const db = getGlobalDB();
|
|
146
|
-
let googleConfig = yield getScopedConfig(db, {
|
|
147
|
-
type: Configs.GOOGLE,
|
|
148
|
-
});
|
|
149
|
-
if (!googleConfig) {
|
|
150
|
-
googleConfig = {
|
|
151
|
-
clientID: environment_1.default.GOOGLE_CLIENT_ID,
|
|
152
|
-
clientSecret: environment_1.default.GOOGLE_CLIENT_SECRET,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
const oauthClient = new google_auth_library_1.OAuth2Client({
|
|
156
|
-
clientId: googleConfig.clientID,
|
|
157
|
-
clientSecret: googleConfig.clientSecret,
|
|
158
|
-
});
|
|
159
|
-
const tokenResponse = yield this.fetchAccessToken({
|
|
160
|
-
client_id: googleConfig.clientID,
|
|
161
|
-
client_secret: googleConfig.clientSecret,
|
|
162
|
-
refresh_token: this.config.auth.refreshToken,
|
|
163
|
-
});
|
|
164
|
-
oauthClient.setCredentials({
|
|
165
|
-
refresh_token: this.config.auth.refreshToken,
|
|
166
|
-
access_token: tokenResponse.access_token,
|
|
167
|
-
});
|
|
168
|
-
this.client.useOAuth2Client(oauthClient);
|
|
169
|
-
yield this.client.loadInfo();
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
console.error("Error connecting to google sheets", err);
|
|
173
|
-
throw err;
|
|
147
|
+
if (!googleConfig) {
|
|
148
|
+
googleConfig = {
|
|
149
|
+
clientID: environment_1.default.GOOGLE_CLIENT_ID,
|
|
150
|
+
clientSecret: environment_1.default.GOOGLE_CLIENT_SECRET,
|
|
151
|
+
};
|
|
174
152
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
yield this.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
153
|
+
const oauthClient = new google_auth_library_1.OAuth2Client({
|
|
154
|
+
clientId: googleConfig.clientID,
|
|
155
|
+
clientSecret: googleConfig.clientSecret,
|
|
156
|
+
});
|
|
157
|
+
const tokenResponse = yield this.fetchAccessToken({
|
|
158
|
+
client_id: googleConfig.clientID,
|
|
159
|
+
client_secret: googleConfig.clientSecret,
|
|
160
|
+
refresh_token: this.config.auth.refreshToken,
|
|
161
|
+
});
|
|
162
|
+
oauthClient.setCredentials({
|
|
163
|
+
refresh_token: this.config.auth.refreshToken,
|
|
164
|
+
access_token: tokenResponse.access_token,
|
|
165
|
+
});
|
|
166
|
+
this.client.useOAuth2Client(oauthClient);
|
|
167
|
+
yield this.client.loadInfo();
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
console.error("Error connecting to google sheets", err);
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
buildSchema(datasourceId) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
yield this.connect();
|
|
178
|
+
const sheets = yield this.client.sheetsByIndex;
|
|
179
|
+
const tables = {};
|
|
180
|
+
for (let sheet of sheets) {
|
|
181
|
+
// must fetch rows to determine schema
|
|
182
|
+
yield sheet.getRows();
|
|
183
|
+
// build schema
|
|
184
|
+
const schema = {};
|
|
185
|
+
// build schema from headers
|
|
186
|
+
for (let header of sheet.headerValues) {
|
|
187
|
+
schema[header] = {
|
|
188
|
+
name: header,
|
|
189
|
+
type: constants_1.FieldTypes.STRING,
|
|
200
190
|
};
|
|
201
191
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const handlers = {
|
|
209
|
-
[constants_1.DataSourceOperation.CREATE]: () => this.create({ sheet, row: json.body }),
|
|
210
|
-
[constants_1.DataSourceOperation.READ]: () => this.read({ sheet }),
|
|
211
|
-
[constants_1.DataSourceOperation.UPDATE]: () => {
|
|
212
|
-
var _a, _b, _c;
|
|
213
|
-
return this.update({
|
|
214
|
-
// exclude the header row and zero index
|
|
215
|
-
rowIndex: ((_c = (_b = (_a = json.extra) === null || _a === void 0 ? void 0 : _a.idFilter) === null || _b === void 0 ? void 0 : _b.equal) === null || _c === void 0 ? void 0 : _c.rowNumber) - 2,
|
|
216
|
-
sheet,
|
|
217
|
-
row: json.body,
|
|
218
|
-
});
|
|
219
|
-
},
|
|
220
|
-
[constants_1.DataSourceOperation.DELETE]: () => {
|
|
221
|
-
var _a, _b, _c;
|
|
222
|
-
return this.delete({
|
|
223
|
-
// exclude the header row and zero index
|
|
224
|
-
rowIndex: ((_c = (_b = (_a = json.extra) === null || _a === void 0 ? void 0 : _a.idFilter) === null || _b === void 0 ? void 0 : _b.equal) === null || _c === void 0 ? void 0 : _c.rowNumber) - 2,
|
|
225
|
-
sheet,
|
|
226
|
-
});
|
|
227
|
-
},
|
|
228
|
-
[constants_1.DataSourceOperation.CREATE_TABLE]: () => { var _a; return this.createTable((_a = json === null || json === void 0 ? void 0 : json.table) === null || _a === void 0 ? void 0 : _a.name); },
|
|
229
|
-
[constants_1.DataSourceOperation.UPDATE_TABLE]: () => this.updateTable(json.table),
|
|
230
|
-
[constants_1.DataSourceOperation.DELETE_TABLE]: () => { var _a; return this.deleteTable((_a = json === null || json === void 0 ? void 0 : json.table) === null || _a === void 0 ? void 0 : _a.name); },
|
|
192
|
+
// create tables
|
|
193
|
+
tables[sheet.title] = {
|
|
194
|
+
_id: (0, utils_1.buildExternalTableId)(datasourceId, sheet.title),
|
|
195
|
+
name: sheet.title,
|
|
196
|
+
primary: ["rowNumber"],
|
|
197
|
+
schema,
|
|
231
198
|
};
|
|
232
|
-
const internalQueryMethod = handlers[json.endpoint.operation];
|
|
233
|
-
return yield internalQueryMethod();
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
buildRowObject(headers, values, rowNumber) {
|
|
237
|
-
const rowObject = { rowNumber };
|
|
238
|
-
for (let i = 0; i < headers.length; i++) {
|
|
239
|
-
rowObject._id = rowNumber;
|
|
240
|
-
rowObject[headers[i]] = values[i];
|
|
241
199
|
}
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
200
|
+
this.tables = tables;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
query(json) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const sheet = json.endpoint.entityId;
|
|
206
|
+
const handlers = {
|
|
207
|
+
[constants_1.DataSourceOperation.CREATE]: () => this.create({ sheet, row: json.body }),
|
|
208
|
+
[constants_1.DataSourceOperation.READ]: () => this.read({ sheet }),
|
|
209
|
+
[constants_1.DataSourceOperation.UPDATE]: () => {
|
|
210
|
+
var _a, _b, _c;
|
|
211
|
+
return this.update({
|
|
212
|
+
// exclude the header row and zero index
|
|
213
|
+
rowIndex: ((_c = (_b = (_a = json.extra) === null || _a === void 0 ? void 0 : _a.idFilter) === null || _b === void 0 ? void 0 : _b.equal) === null || _c === void 0 ? void 0 : _c.rowNumber) - 2,
|
|
214
|
+
sheet,
|
|
215
|
+
row: json.body,
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
[constants_1.DataSourceOperation.DELETE]: () => {
|
|
219
|
+
var _a, _b, _c;
|
|
220
|
+
return this.delete({
|
|
221
|
+
// exclude the header row and zero index
|
|
222
|
+
rowIndex: ((_c = (_b = (_a = json.extra) === null || _a === void 0 ? void 0 : _a.idFilter) === null || _b === void 0 ? void 0 : _b.equal) === null || _c === void 0 ? void 0 : _c.rowNumber) - 2,
|
|
223
|
+
sheet,
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
[constants_1.DataSourceOperation.CREATE_TABLE]: () => { var _a; return this.createTable((_a = json === null || json === void 0 ? void 0 : json.table) === null || _a === void 0 ? void 0 : _a.name); },
|
|
227
|
+
[constants_1.DataSourceOperation.UPDATE_TABLE]: () => this.updateTable(json.table),
|
|
228
|
+
[constants_1.DataSourceOperation.DELETE_TABLE]: () => { var _a; return this.deleteTable((_a = json === null || json === void 0 ? void 0 : json.table) === null || _a === void 0 ? void 0 : _a.name); },
|
|
229
|
+
};
|
|
230
|
+
const internalQueryMethod = handlers[json.endpoint.operation];
|
|
231
|
+
return yield internalQueryMethod();
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
buildRowObject(headers, values, rowNumber) {
|
|
235
|
+
const rowObject = { rowNumber };
|
|
236
|
+
for (let i = 0; i < headers.length; i++) {
|
|
237
|
+
rowObject._id = rowNumber;
|
|
238
|
+
rowObject[headers[i]] = values[i];
|
|
256
239
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
240
|
+
return rowObject;
|
|
241
|
+
}
|
|
242
|
+
createTable(name) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
try {
|
|
245
|
+
yield this.connect();
|
|
246
|
+
return yield this.client.addSheet({ title: name });
|
|
247
|
+
}
|
|
248
|
+
catch (err) {
|
|
249
|
+
console.error("Error creating new table in google sheets", err);
|
|
250
|
+
throw err;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
updateTable(table) {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
try {
|
|
257
|
+
yield this.connect();
|
|
258
|
+
const sheet = yield this.client.sheetsByTitle[table.name];
|
|
259
|
+
yield sheet.loadHeaderRow();
|
|
260
|
+
if (table._rename) {
|
|
261
|
+
const headers = [];
|
|
262
|
+
for (let header of sheet.headerValues) {
|
|
263
|
+
if (header === table._rename.old) {
|
|
264
|
+
headers.push(table._rename.updated);
|
|
272
265
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
else {
|
|
276
|
-
let newField = Object.keys(table.schema).find(key => !sheet.headerValues.includes(key));
|
|
277
|
-
yield sheet.setHeaderRow([...sheet.headerValues, newField]);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
catch (err) {
|
|
281
|
-
console.error("Error updating table in google sheets", err);
|
|
282
|
-
throw err;
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
deleteTable(sheet) {
|
|
287
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
-
try {
|
|
289
|
-
yield this.connect();
|
|
290
|
-
const sheetToDelete = yield this.client.sheetsByTitle[sheet];
|
|
291
|
-
return yield sheetToDelete.delete();
|
|
292
|
-
}
|
|
293
|
-
catch (err) {
|
|
294
|
-
console.error("Error deleting table in google sheets", err);
|
|
295
|
-
throw err;
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
create(query) {
|
|
300
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
301
|
-
try {
|
|
302
|
-
yield this.connect();
|
|
303
|
-
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
304
|
-
const rowToInsert = typeof query.row === "string" ? JSON.parse(query.row) : query.row;
|
|
305
|
-
const row = yield sheet.addRow(rowToInsert);
|
|
306
|
-
return [
|
|
307
|
-
this.buildRowObject(sheet.headerValues, row._rawData, row._rowNumber),
|
|
308
|
-
];
|
|
309
|
-
}
|
|
310
|
-
catch (err) {
|
|
311
|
-
console.error("Error writing to google sheets", err);
|
|
312
|
-
throw err;
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
read(query) {
|
|
317
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
318
|
-
try {
|
|
319
|
-
yield this.connect();
|
|
320
|
-
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
321
|
-
const rows = yield sheet.getRows();
|
|
322
|
-
const headerValues = sheet.headerValues;
|
|
323
|
-
const response = [];
|
|
324
|
-
for (let row of rows) {
|
|
325
|
-
response.push(this.buildRowObject(headerValues, row._rawData, row._rowNumber));
|
|
326
|
-
}
|
|
327
|
-
return response;
|
|
328
|
-
}
|
|
329
|
-
catch (err) {
|
|
330
|
-
console.error("Error reading from google sheets", err);
|
|
331
|
-
throw err;
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
update(query) {
|
|
336
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
-
try {
|
|
338
|
-
yield this.connect();
|
|
339
|
-
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
340
|
-
const rows = yield sheet.getRows();
|
|
341
|
-
const row = rows[query.rowIndex];
|
|
342
|
-
if (row) {
|
|
343
|
-
const updateValues = typeof query.row === "string" ? JSON.parse(query.row) : query.row;
|
|
344
|
-
for (let key in updateValues) {
|
|
345
|
-
row[key] = updateValues[key];
|
|
266
|
+
else {
|
|
267
|
+
headers.push(header);
|
|
346
268
|
}
|
|
347
|
-
yield row.save();
|
|
348
|
-
return [
|
|
349
|
-
this.buildRowObject(sheet.headerValues, row._rawData, row._rowNumber),
|
|
350
|
-
];
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
throw new Error("Row does not exist.");
|
|
354
269
|
}
|
|
270
|
+
yield sheet.setHeaderRow(headers);
|
|
355
271
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
272
|
+
else {
|
|
273
|
+
let newField = Object.keys(table.schema).find(key => !sheet.headerValues.includes(key));
|
|
274
|
+
yield sheet.setHeaderRow([...sheet.headerValues, newField]);
|
|
359
275
|
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
console.error("Error updating table in google sheets", err);
|
|
279
|
+
throw err;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
deleteTable(sheet) {
|
|
284
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
+
try {
|
|
286
|
+
yield this.connect();
|
|
287
|
+
const sheetToDelete = yield this.client.sheetsByTitle[sheet];
|
|
288
|
+
return yield sheetToDelete.delete();
|
|
289
|
+
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
console.error("Error deleting table in google sheets", err);
|
|
292
|
+
throw err;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
create(query) {
|
|
297
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
+
try {
|
|
299
|
+
yield this.connect();
|
|
300
|
+
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
301
|
+
const rowToInsert = typeof query.row === "string" ? JSON.parse(query.row) : query.row;
|
|
302
|
+
const row = yield sheet.addRow(rowToInsert);
|
|
303
|
+
return [
|
|
304
|
+
this.buildRowObject(sheet.headerValues, row._rawData, row._rowNumber),
|
|
305
|
+
];
|
|
306
|
+
}
|
|
307
|
+
catch (err) {
|
|
308
|
+
console.error("Error writing to google sheets", err);
|
|
309
|
+
throw err;
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
read(query) {
|
|
314
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
315
|
+
try {
|
|
316
|
+
yield this.connect();
|
|
317
|
+
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
318
|
+
const rows = yield sheet.getRows();
|
|
319
|
+
const headerValues = sheet.headerValues;
|
|
320
|
+
const response = [];
|
|
321
|
+
for (let row of rows) {
|
|
322
|
+
response.push(this.buildRowObject(headerValues, row._rawData, row._rowNumber));
|
|
323
|
+
}
|
|
324
|
+
return response;
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
console.error("Error reading from google sheets", err);
|
|
328
|
+
throw err;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
update(query) {
|
|
333
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
try {
|
|
364
335
|
yield this.connect();
|
|
365
336
|
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
366
337
|
const rows = yield sheet.getRows();
|
|
367
338
|
const row = rows[query.rowIndex];
|
|
368
339
|
if (row) {
|
|
369
|
-
|
|
370
|
-
|
|
340
|
+
const updateValues = typeof query.row === "string" ? JSON.parse(query.row) : query.row;
|
|
341
|
+
for (let key in updateValues) {
|
|
342
|
+
row[key] = updateValues[key];
|
|
343
|
+
}
|
|
344
|
+
yield row.save();
|
|
345
|
+
return [
|
|
346
|
+
this.buildRowObject(sheet.headerValues, row._rawData, row._rowNumber),
|
|
347
|
+
];
|
|
371
348
|
}
|
|
372
349
|
else {
|
|
373
350
|
throw new Error("Row does not exist.");
|
|
374
351
|
}
|
|
375
|
-
}
|
|
376
|
-
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
console.error("Error reading from google sheets", err);
|
|
355
|
+
throw err;
|
|
356
|
+
}
|
|
357
|
+
});
|
|
377
358
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
359
|
+
delete(query) {
|
|
360
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
361
|
+
yield this.connect();
|
|
362
|
+
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
363
|
+
const rows = yield sheet.getRows();
|
|
364
|
+
const row = rows[query.rowIndex];
|
|
365
|
+
if (row) {
|
|
366
|
+
yield row.delete();
|
|
367
|
+
return [{ deleted: query.rowIndex }];
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
throw new Error("Row does not exist.");
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
exports.default = {
|
|
376
|
+
schema: SCHEMA,
|
|
377
|
+
integration: GoogleSheetsIntegration,
|
|
378
|
+
};
|