@budibase/server 1.0.46-alpha.7 → 1.0.48
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/builder/assets/{index.dd9e386f.css → index.39e01193.css} +1 -1
- package/builder/assets/{index.af9e71d8.js → index.e083dcaf.js} +221 -223
- package/builder/assets/{vendor.3bd2f661.js → vendor.f9faf6ab.js} +12 -12
- package/builder/index.html +3 -3
- package/coverage/clover.xml +1637 -1793
- package/coverage/coverage-final.json +94 -98
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +126 -210
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
- 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/component.js.html +4 -4
- package/coverage/lcov-report/api/controllers/datasource.js.html +36 -72
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/{migrations/usageQuotas/syncRows.js.html → api/controllers/hosting.js.html} +44 -41
- package/coverage/lcov-report/api/controllers/index.html +42 -27
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.js.html +19 -19
- package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
- package/coverage/lcov-report/api/controllers/row/index.html +15 -15
- package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/row/internal.js.html +44 -44
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +8 -8
- package/coverage/lcov-report/api/controllers/row/utils.js.html +57 -39
- package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
- package/coverage/lcov-report/api/controllers/table/index.html +32 -32
- package/coverage/lcov-report/api/controllers/table/index.js.html +39 -57
- package/coverage/lcov-report/api/controllers/table/internal.js.html +34 -40
- package/coverage/lcov-report/api/controllers/table/utils.js.html +122 -83
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +20 -20
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
- package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +15 -15
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +10 -10
- 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/application.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/{migrations/usageQuotas/syncApps.js.html → api/routes/hosting.js.html} +27 -42
- package/coverage/lcov-report/api/routes/index.html +22 -7
- package/coverage/lcov-report/api/routes/index.js.html +10 -4
- 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/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/row.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/static.js.html +2 -17
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- 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/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +24 -24
- package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
- package/coverage/lcov-report/automations/bullboard.js.html +16 -16
- 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 +6 -6
- package/coverage/lcov-report/automations/steps/createRow.js.html +19 -13
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +20 -11
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
- package/coverage/lcov-report/automations/steps/index.html +13 -13
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +18 -18
- package/coverage/lcov-report/automations/utils.js.html +32 -32
- package/coverage/lcov-report/constants/index.html +11 -11
- package/coverage/lcov-report/constants/index.js.html +37 -40
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/client.js.html +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +18 -18
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +31 -31
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +15 -15
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +85 -85
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +5 -5
- package/coverage/lcov-report/events/utils.js.html +3 -3
- package/coverage/lcov-report/index.html +86 -116
- 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/authorized.js.html +11 -11
- package/coverage/lcov-report/middleware/builder.js.html +8 -8
- package/coverage/lcov-report/middleware/currentapp.js.html +29 -29
- package/coverage/lcov-report/middleware/index.html +20 -20
- package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +41 -275
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +15 -15
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +8 -23
- package/coverage/lcov-report/threads/utils.js.html +14 -14
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
- package/coverage/lcov-report/utilities/global.js.html +26 -26
- package/coverage/lcov-report/utilities/index.html +19 -19
- package/coverage/lcov-report/utilities/index.js.html +25 -25
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
- 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 +53 -53
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +10 -10
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +5 -5
- package/coverage/lcov-report/utilities/workerRequests.js.html +108 -39
- package/coverage/lcov.info +2332 -2599
- package/dist/api/controllers/application.js +20 -49
- package/dist/api/controllers/datasource.js +0 -11
- package/dist/api/controllers/hosting.js +30 -0
- package/dist/api/controllers/row/ExternalRequest.js +2 -1
- package/dist/api/controllers/row/utils.js +8 -6
- package/dist/api/controllers/static/index.js +10 -59
- package/dist/api/controllers/table/index.js +4 -10
- package/dist/api/controllers/table/internal.js +0 -2
- package/dist/api/controllers/table/utils.js +17 -11
- package/dist/api/routes/hosting.js +11 -0
- package/dist/api/routes/index.js +2 -0
- package/dist/api/routes/static.js +1 -2
- package/dist/automations/steps/createRow.js +4 -2
- package/dist/automations/steps/deleteRow.js +4 -1
- package/dist/constants/index.js +5 -8
- package/dist/definitions/datasource.js +0 -1
- package/dist/environment.js +0 -1
- package/dist/integrations/base/sql.js +6 -13
- package/dist/integrations/index.js +0 -3
- package/dist/integrations/utils.js +9 -56
- package/dist/middleware/usageQuota.js +13 -82
- package/dist/package.json +5 -8
- package/dist/tests/utilities/TestConfiguration.js +1 -3
- package/dist/threads/query.js +0 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/{usageQuota/index.js → usageQuota.js} +31 -44
- package/dist/utilities/workerRequests.js +20 -0
- package/nodemon.json +1 -1
- package/package.json +6 -9
- package/src/api/controllers/application.js +24 -52
- package/src/api/controllers/datasource.js +0 -12
- package/src/api/controllers/hosting.js +22 -0
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/utils.js +12 -6
- package/src/api/controllers/static/index.js +10 -63
- package/src/api/controllers/table/index.js +9 -15
- package/src/api/controllers/table/internal.js +0 -2
- package/src/api/controllers/table/utils.js +24 -11
- package/src/api/routes/hosting.js +13 -0
- package/src/api/routes/index.js +2 -0
- package/src/api/routes/static.js +0 -5
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/hosting.spec.js +36 -0
- package/src/automations/steps/createRow.js +4 -2
- package/src/automations/steps/deleteRow.js +4 -1
- package/src/constants/index.js +8 -9
- package/src/definitions/datasource.ts +0 -3
- package/src/environment.js +0 -1
- package/src/integrations/base/sql.ts +7 -14
- package/src/integrations/index.ts +0 -3
- package/src/integrations/tests/sql.spec.js +0 -16
- package/src/integrations/utils.ts +11 -70
- package/src/middleware/tests/usageQuota.spec.js +24 -18
- package/src/middleware/usageQuota.js +15 -93
- package/src/tests/utilities/TestConfiguration.js +1 -3
- package/src/threads/query.js +0 -5
- package/src/utilities/usageQuota.js +73 -0
- package/src/utilities/workerRequests.js +23 -0
- package/coverage/lcov-report/migrations/usageQuotas/index.html +0 -141
- package/coverage/lcov-report/migrations/usageQuotas/index.js.html +0 -152
- package/coverage/lcov-report/utilities/usageQuota/index.html +0 -141
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -356
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +0 -302
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +0 -134
- package/dist/integrations/googlesheets.js +0 -340
- package/dist/migrations/usageQuotas/index.js +0 -24
- package/dist/migrations/usageQuotas/syncApps.js +0 -26
- package/dist/migrations/usageQuotas/syncRows.js +0 -29
- package/dist/utilities/usageQuota/rows.js +0 -77
- package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
- package/src/api/routes/tests/static.spec.js +0 -98
- package/src/integrations/googlesheets.ts +0 -353
- package/src/migrations/tests/usageQuotas/index.spec.js +0 -27
- package/src/migrations/tests/usageQuotas/syncApps.spec.js +0 -37
- package/src/migrations/tests/usageQuotas/syncRows.spec.js +0 -43
- package/src/migrations/usageQuotas/index.js +0 -24
- package/src/migrations/usageQuotas/syncApps.js +0 -18
- package/src/migrations/usageQuotas/syncRows.js +0 -21
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
- package/src/utilities/usageQuota/index.js +0 -92
- package/src/utilities/usageQuota/rows.js +0 -74
- package/src/utilities/usageQuota/usageQuoteReset.js +0 -18
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const datasource_1 = require("../definitions/datasource");
|
|
13
|
-
const google_auth_library_1 = require("google-auth-library");
|
|
14
|
-
const utils_1 = require("./utils");
|
|
15
|
-
const constants_1 = require("../constants");
|
|
16
|
-
const google_spreadsheet_1 = require("google-spreadsheet");
|
|
17
|
-
var GoogleSheetsModule;
|
|
18
|
-
(function (GoogleSheetsModule) {
|
|
19
|
-
const { getGlobalDB } = require("@budibase/backend-core/tenancy");
|
|
20
|
-
const { getScopedConfig } = require("@budibase/backend-core/db");
|
|
21
|
-
const { Configs } = require("@budibase/backend-core/constants");
|
|
22
|
-
const SCHEMA = {
|
|
23
|
-
plus: true,
|
|
24
|
-
auth: {
|
|
25
|
-
type: "google",
|
|
26
|
-
},
|
|
27
|
-
relationships: false,
|
|
28
|
-
docs: "https://developers.google.com/sheets/api/quickstart/nodejs",
|
|
29
|
-
description: "Create and collaborate on online spreadsheets in real-time and from any device. ",
|
|
30
|
-
friendlyName: "Google Sheets",
|
|
31
|
-
datasource: {
|
|
32
|
-
spreadsheetId: {
|
|
33
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
34
|
-
required: true,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
query: {
|
|
38
|
-
create: {
|
|
39
|
-
type: datasource_1.QueryTypes.FIELDS,
|
|
40
|
-
fields: {
|
|
41
|
-
sheet: {
|
|
42
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
43
|
-
required: true,
|
|
44
|
-
},
|
|
45
|
-
row: {
|
|
46
|
-
type: datasource_1.QueryTypes.JSON,
|
|
47
|
-
required: true,
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
read: {
|
|
52
|
-
type: datasource_1.QueryTypes.FIELDS,
|
|
53
|
-
fields: {
|
|
54
|
-
sheet: {
|
|
55
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
56
|
-
required: true,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
update: {
|
|
61
|
-
type: datasource_1.QueryTypes.FIELDS,
|
|
62
|
-
fields: {
|
|
63
|
-
sheet: {
|
|
64
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
65
|
-
required: true,
|
|
66
|
-
},
|
|
67
|
-
rowIndex: {
|
|
68
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
69
|
-
required: true,
|
|
70
|
-
},
|
|
71
|
-
row: {
|
|
72
|
-
type: datasource_1.QueryTypes.JSON,
|
|
73
|
-
required: true,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
delete: {
|
|
78
|
-
type: datasource_1.QueryTypes.FIELDS,
|
|
79
|
-
fields: {
|
|
80
|
-
sheet: {
|
|
81
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
82
|
-
required: true,
|
|
83
|
-
},
|
|
84
|
-
rowIndex: {
|
|
85
|
-
type: datasource_1.DatasourceFieldTypes.NUMBER,
|
|
86
|
-
required: true,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
class GoogleSheetsIntegration {
|
|
93
|
-
constructor(config) {
|
|
94
|
-
this.tables = {};
|
|
95
|
-
this.schemaErrors = {};
|
|
96
|
-
this.config = config;
|
|
97
|
-
const spreadsheetId = this.cleanSpreadsheetUrl(this.config.spreadsheetId);
|
|
98
|
-
this.client = new google_spreadsheet_1.GoogleSpreadsheet(spreadsheetId);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Pull the spreadsheet ID out from a valid google sheets URL
|
|
102
|
-
* @param spreadsheetId - the URL or standard spreadsheetId of the google sheet
|
|
103
|
-
* @returns spreadsheet Id of the google sheet
|
|
104
|
-
*/
|
|
105
|
-
cleanSpreadsheetUrl(spreadsheetId) {
|
|
106
|
-
if (!spreadsheetId) {
|
|
107
|
-
throw new Error("You must set a spreadsheet ID in your configuration to fetch tables.");
|
|
108
|
-
}
|
|
109
|
-
const parts = spreadsheetId.split("/");
|
|
110
|
-
return parts.length > 5 ? parts[5] : spreadsheetId;
|
|
111
|
-
}
|
|
112
|
-
connect() {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
try {
|
|
115
|
-
// Initialise oAuth client
|
|
116
|
-
const db = getGlobalDB();
|
|
117
|
-
const googleConfig = yield getScopedConfig(db, {
|
|
118
|
-
type: Configs.GOOGLE,
|
|
119
|
-
});
|
|
120
|
-
const oauthClient = new google_auth_library_1.OAuth2Client({
|
|
121
|
-
clientId: googleConfig.clientID,
|
|
122
|
-
clientSecret: googleConfig.clientSecret,
|
|
123
|
-
});
|
|
124
|
-
oauthClient.credentials.access_token = this.config.auth.accessToken;
|
|
125
|
-
oauthClient.credentials.refresh_token = this.config.auth.refreshToken;
|
|
126
|
-
this.client.useOAuth2Client(oauthClient);
|
|
127
|
-
yield this.client.loadInfo();
|
|
128
|
-
}
|
|
129
|
-
catch (err) {
|
|
130
|
-
console.error("Error connecting to google sheets", err);
|
|
131
|
-
throw err;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
buildSchema(datasourceId) {
|
|
136
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
yield this.connect();
|
|
138
|
-
const sheets = yield this.client.sheetsByIndex;
|
|
139
|
-
const tables = {};
|
|
140
|
-
for (let sheet of sheets) {
|
|
141
|
-
// must fetch rows to determine schema
|
|
142
|
-
yield sheet.getRows();
|
|
143
|
-
// build schema
|
|
144
|
-
const schema = {};
|
|
145
|
-
// build schema from headers
|
|
146
|
-
for (let header of sheet.headerValues) {
|
|
147
|
-
schema[header] = {
|
|
148
|
-
name: header,
|
|
149
|
-
type: constants_1.FieldTypes.STRING,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
// create tables
|
|
153
|
-
tables[sheet.title] = {
|
|
154
|
-
_id: utils_1.buildExternalTableId(datasourceId, sheet.title),
|
|
155
|
-
name: sheet.title,
|
|
156
|
-
primary: ["rowNumber"],
|
|
157
|
-
schema,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
this.tables = tables;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
query(json) {
|
|
164
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
const sheet = json.endpoint.entityId;
|
|
166
|
-
const handlers = {
|
|
167
|
-
[constants_1.DataSourceOperation.CREATE]: () => this.create({ sheet, row: json.body }),
|
|
168
|
-
[constants_1.DataSourceOperation.READ]: () => this.read({ sheet }),
|
|
169
|
-
[constants_1.DataSourceOperation.UPDATE]: () => {
|
|
170
|
-
var _a, _b, _c;
|
|
171
|
-
return this.update({
|
|
172
|
-
// exclude the header row and zero index
|
|
173
|
-
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,
|
|
174
|
-
sheet,
|
|
175
|
-
row: json.body,
|
|
176
|
-
});
|
|
177
|
-
},
|
|
178
|
-
[constants_1.DataSourceOperation.DELETE]: () => {
|
|
179
|
-
var _a, _b, _c;
|
|
180
|
-
return this.delete({
|
|
181
|
-
// exclude the header row and zero index
|
|
182
|
-
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,
|
|
183
|
-
sheet,
|
|
184
|
-
});
|
|
185
|
-
},
|
|
186
|
-
[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); },
|
|
187
|
-
[constants_1.DataSourceOperation.UPDATE_TABLE]: () => this.updateTable(json.table),
|
|
188
|
-
[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); },
|
|
189
|
-
};
|
|
190
|
-
const internalQueryMethod = handlers[json.endpoint.operation];
|
|
191
|
-
return yield internalQueryMethod();
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
buildRowObject(headers, values, rowNumber) {
|
|
195
|
-
const rowObject = { rowNumber };
|
|
196
|
-
for (let i = 0; i < headers.length; i++) {
|
|
197
|
-
rowObject._id = rowNumber;
|
|
198
|
-
rowObject[headers[i]] = values[i];
|
|
199
|
-
}
|
|
200
|
-
return rowObject;
|
|
201
|
-
}
|
|
202
|
-
createTable(name) {
|
|
203
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
try {
|
|
205
|
-
yield this.connect();
|
|
206
|
-
const sheet = yield this.client.addSheet({ title: name });
|
|
207
|
-
return sheet;
|
|
208
|
-
}
|
|
209
|
-
catch (err) {
|
|
210
|
-
console.error("Error creating new table in google sheets", err);
|
|
211
|
-
throw err;
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
updateTable(table) {
|
|
216
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
try {
|
|
218
|
-
yield this.connect();
|
|
219
|
-
const sheet = yield this.client.sheetsByTitle[table.name];
|
|
220
|
-
yield sheet.loadHeaderRow();
|
|
221
|
-
if (table._rename) {
|
|
222
|
-
const headers = [];
|
|
223
|
-
for (let header of sheet.headerValues) {
|
|
224
|
-
if (header === table._rename.old) {
|
|
225
|
-
headers.push(table._rename.updated);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
headers.push(header);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
yield sheet.setHeaderRow(headers);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
let newField = Object.keys(table.schema).find(key => !sheet.headerValues.includes(key));
|
|
235
|
-
yield sheet.setHeaderRow([...sheet.headerValues, newField]);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
catch (err) {
|
|
239
|
-
console.error("Error updating table in google sheets", err);
|
|
240
|
-
throw err;
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
deleteTable(sheet) {
|
|
245
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
try {
|
|
247
|
-
yield this.connect();
|
|
248
|
-
const sheetToDelete = yield this.client.sheetsByTitle[sheet];
|
|
249
|
-
return yield sheetToDelete.delete();
|
|
250
|
-
}
|
|
251
|
-
catch (err) {
|
|
252
|
-
console.error("Error deleting table in google sheets", err);
|
|
253
|
-
throw err;
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
create(query) {
|
|
258
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
-
try {
|
|
260
|
-
yield this.connect();
|
|
261
|
-
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
262
|
-
const rowToInsert = typeof query.row === "string" ? JSON.parse(query.row) : query.row;
|
|
263
|
-
const row = yield sheet.addRow(rowToInsert);
|
|
264
|
-
return [
|
|
265
|
-
this.buildRowObject(sheet.headerValues, row._rawData, row._rowNumber),
|
|
266
|
-
];
|
|
267
|
-
}
|
|
268
|
-
catch (err) {
|
|
269
|
-
console.error("Error writing to google sheets", err);
|
|
270
|
-
throw err;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
read(query) {
|
|
275
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
-
try {
|
|
277
|
-
yield this.connect();
|
|
278
|
-
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
279
|
-
const rows = yield sheet.getRows();
|
|
280
|
-
const headerValues = sheet.headerValues;
|
|
281
|
-
const response = [];
|
|
282
|
-
for (let row of rows) {
|
|
283
|
-
response.push(this.buildRowObject(headerValues, row._rawData, row._rowNumber));
|
|
284
|
-
}
|
|
285
|
-
return response;
|
|
286
|
-
}
|
|
287
|
-
catch (err) {
|
|
288
|
-
console.error("Error reading from google sheets", err);
|
|
289
|
-
throw err;
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
update(query) {
|
|
294
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
-
try {
|
|
296
|
-
yield this.connect();
|
|
297
|
-
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
298
|
-
const rows = yield sheet.getRows();
|
|
299
|
-
const row = rows[query.rowIndex];
|
|
300
|
-
if (row) {
|
|
301
|
-
const updateValues = query.row;
|
|
302
|
-
for (let key in updateValues) {
|
|
303
|
-
row[key] = updateValues[key];
|
|
304
|
-
}
|
|
305
|
-
yield row.save();
|
|
306
|
-
return [
|
|
307
|
-
this.buildRowObject(sheet.headerValues, row._rawData, row._rowNumber),
|
|
308
|
-
];
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
throw new Error("Row does not exist.");
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
catch (err) {
|
|
315
|
-
console.error("Error reading from google sheets", err);
|
|
316
|
-
throw err;
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
delete(query) {
|
|
321
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
-
yield this.connect();
|
|
323
|
-
const sheet = yield this.client.sheetsByTitle[query.sheet];
|
|
324
|
-
const rows = yield sheet.getRows();
|
|
325
|
-
const row = rows[query.rowIndex];
|
|
326
|
-
if (row) {
|
|
327
|
-
yield row.delete();
|
|
328
|
-
return [{ deleted: query.rowIndex }];
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
throw new Error("Row does not exist.");
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
module.exports = {
|
|
337
|
-
schema: SCHEMA,
|
|
338
|
-
integration: GoogleSheetsIntegration,
|
|
339
|
-
};
|
|
340
|
-
})(GoogleSheetsModule || (GoogleSheetsModule = {}));
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
const { MIGRATIONS, MIGRATION_DBS, migrateIfRequired, } = require("@budibase/backend-core/migrations");
|
|
12
|
-
const { useQuotas } = require("../../utilities/usageQuota");
|
|
13
|
-
const syncApps = require("./syncApps");
|
|
14
|
-
const syncRows = require("./syncRows");
|
|
15
|
-
exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
if (!useQuotas()) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
// Jan 2022
|
|
20
|
-
yield migrateIfRequired(MIGRATION_DBS.GLOBAL_DB, MIGRATIONS.QUOTAS_1, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
yield syncApps.run();
|
|
22
|
-
yield syncRows.run();
|
|
23
|
-
}));
|
|
24
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy");
|
|
12
|
-
const { getAllApps } = require("@budibase/backend-core/db");
|
|
13
|
-
const CouchDB = require("../../db");
|
|
14
|
-
const { getUsageQuotaDoc } = require("../../utilities/usageQuota");
|
|
15
|
-
exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const db = getGlobalDB();
|
|
17
|
-
// get app count
|
|
18
|
-
const devApps = yield getAllApps(CouchDB, { dev: true });
|
|
19
|
-
const appCount = devApps ? devApps.length : 0;
|
|
20
|
-
// sync app count
|
|
21
|
-
const tenantId = getTenantId();
|
|
22
|
-
console.log(`[Tenant: ${tenantId}] Syncing app count: ${appCount}`);
|
|
23
|
-
const usageDoc = yield getUsageQuotaDoc(db);
|
|
24
|
-
usageDoc.usageQuota.apps = appCount;
|
|
25
|
-
yield db.put(usageDoc);
|
|
26
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy");
|
|
12
|
-
const { getAllApps } = require("@budibase/backend-core/db");
|
|
13
|
-
const CouchDB = require("../../db");
|
|
14
|
-
const { getUsageQuotaDoc } = require("../../utilities/usageQuota");
|
|
15
|
-
const { getUniqueRows } = require("../../utilities/usageQuota/rows");
|
|
16
|
-
exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const db = getGlobalDB();
|
|
18
|
-
// get all rows in all apps
|
|
19
|
-
const allApps = yield getAllApps(CouchDB, { all: true });
|
|
20
|
-
const appIds = allApps ? allApps.map(app => app.appId) : [];
|
|
21
|
-
const rows = yield getUniqueRows(appIds);
|
|
22
|
-
const rowCount = rows ? rows.length : 0;
|
|
23
|
-
// sync row count
|
|
24
|
-
const tenantId = getTenantId();
|
|
25
|
-
console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`);
|
|
26
|
-
const usageDoc = yield getUsageQuotaDoc(db);
|
|
27
|
-
usageDoc.usageQuota.rows = rowCount;
|
|
28
|
-
yield db.put(usageDoc);
|
|
29
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
const { getRowParams, USER_METDATA_PREFIX } = require("../../db/utils");
|
|
12
|
-
const CouchDB = require("../../db");
|
|
13
|
-
const { isDevAppID, getDevelopmentAppID } = require("@budibase/backend-core/db");
|
|
14
|
-
const ROW_EXCLUSIONS = [USER_METDATA_PREFIX];
|
|
15
|
-
const getAppPairs = appIds => {
|
|
16
|
-
// collect the app ids into dev / prod pairs
|
|
17
|
-
// keyed by the dev app id
|
|
18
|
-
const pairs = {};
|
|
19
|
-
for (let appId of appIds) {
|
|
20
|
-
const devId = getDevelopmentAppID(appId);
|
|
21
|
-
if (!pairs[devId]) {
|
|
22
|
-
pairs[devId] = {};
|
|
23
|
-
}
|
|
24
|
-
if (isDevAppID(appId)) {
|
|
25
|
-
pairs[devId].devId = appId;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
pairs[devId].prodId = appId;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return pairs;
|
|
32
|
-
};
|
|
33
|
-
const getAppRows = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
const appDb = new CouchDB(appId);
|
|
35
|
-
const response = yield appDb.allDocs(getRowParams(null, null, {
|
|
36
|
-
include_docs: false,
|
|
37
|
-
}));
|
|
38
|
-
return response.rows
|
|
39
|
-
.map(r => r.id)
|
|
40
|
-
.filter(id => {
|
|
41
|
-
for (let exclusion of ROW_EXCLUSIONS) {
|
|
42
|
-
if (id.startsWith(exclusion)) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
/**
|
|
50
|
-
* Return a set of all rows in the given app ids.
|
|
51
|
-
* The returned rows will be unique on a per dev/prod app basis.
|
|
52
|
-
* Rows duplicates may exist across apps due to data import so they are not filtered out.
|
|
53
|
-
*/
|
|
54
|
-
exports.getUniqueRows = (appIds) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
let uniqueRows = [];
|
|
56
|
-
const pairs = getAppPairs(appIds);
|
|
57
|
-
for (let pair of Object.values(pairs)) {
|
|
58
|
-
let appRows = [];
|
|
59
|
-
for (let appId of [pair.devId, pair.prodId]) {
|
|
60
|
-
if (!appId) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
appRows.push(yield getAppRows(appId));
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
console.error(e);
|
|
68
|
-
// don't error out if we can't count the app rows, just continue
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// ensure uniqueness on a per app pair basis
|
|
72
|
-
// this can't be done on all rows because app import results in
|
|
73
|
-
// duplicate row ids across apps
|
|
74
|
-
uniqueRows = uniqueRows.concat(...new Set(appRows));
|
|
75
|
-
}
|
|
76
|
-
return uniqueRows;
|
|
77
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// UNUSED CODE
|
|
3
|
-
// Preserved for future use
|
|
4
|
-
/* eslint-disable no-unused-vars */
|
|
5
|
-
function getNewQuotaReset() {
|
|
6
|
-
return Date.now() + 2592000000;
|
|
7
|
-
}
|
|
8
|
-
function resetQuotasIfRequired(quota) {
|
|
9
|
-
// Check if the quota needs reset
|
|
10
|
-
if (Date.now() >= quota.quotaReset) {
|
|
11
|
-
quota.quotaReset = getNewQuotaReset();
|
|
12
|
-
for (let prop of Object.keys(quota.usageQuota)) {
|
|
13
|
-
quota.usageQuota[prop] = 0;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
jest.mock("node-fetch")
|
|
2
|
-
jest.mock("aws-sdk", () => ({
|
|
3
|
-
config: {
|
|
4
|
-
update: jest.fn(),
|
|
5
|
-
},
|
|
6
|
-
DynamoDB: {
|
|
7
|
-
DocumentClient: jest.fn(),
|
|
8
|
-
},
|
|
9
|
-
S3: jest.fn(() => ({
|
|
10
|
-
getSignedUrl: jest.fn(() => {
|
|
11
|
-
return "my-url"
|
|
12
|
-
}),
|
|
13
|
-
})),
|
|
14
|
-
}))
|
|
15
|
-
|
|
16
|
-
const setup = require("./utilities")
|
|
17
|
-
|
|
18
|
-
describe("/attachments", () => {
|
|
19
|
-
let request = setup.getRequest()
|
|
20
|
-
let config = setup.getConfig()
|
|
21
|
-
let app
|
|
22
|
-
|
|
23
|
-
afterAll(setup.afterAll)
|
|
24
|
-
|
|
25
|
-
beforeEach(async () => {
|
|
26
|
-
app = await config.init()
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe("generateSignedUrls", () => {
|
|
30
|
-
let datasource
|
|
31
|
-
|
|
32
|
-
beforeEach(async () => {
|
|
33
|
-
datasource = await config.createDatasource({
|
|
34
|
-
datasource: {
|
|
35
|
-
type: "datasource",
|
|
36
|
-
name: "Test",
|
|
37
|
-
source: "S3",
|
|
38
|
-
config: {},
|
|
39
|
-
},
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it("should be able to generate a signed upload URL", async () => {
|
|
44
|
-
const bucket = "foo"
|
|
45
|
-
const key = "bar"
|
|
46
|
-
const res = await request
|
|
47
|
-
.post(`/api/attachments/${datasource._id}/url`)
|
|
48
|
-
.send({ bucket, key })
|
|
49
|
-
.set(config.defaultHeaders())
|
|
50
|
-
.expect("Content-Type", /json/)
|
|
51
|
-
.expect(200)
|
|
52
|
-
expect(res.body.signedUrl).toEqual("my-url")
|
|
53
|
-
expect(res.body.publicUrl).toEqual(
|
|
54
|
-
`https://${bucket}.s3.eu-west-1.amazonaws.com/${key}`
|
|
55
|
-
)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it("should handle an invalid datasource ID", async () => {
|
|
59
|
-
const res = await request
|
|
60
|
-
.post(`/api/attachments/foo/url`)
|
|
61
|
-
.send({
|
|
62
|
-
bucket: "foo",
|
|
63
|
-
key: "bar",
|
|
64
|
-
})
|
|
65
|
-
.set(config.defaultHeaders())
|
|
66
|
-
.expect("Content-Type", /json/)
|
|
67
|
-
.expect(400)
|
|
68
|
-
expect(res.body.message).toEqual(
|
|
69
|
-
"The specified datasource could not be found"
|
|
70
|
-
)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it("should require a bucket parameter", async () => {
|
|
74
|
-
const res = await request
|
|
75
|
-
.post(`/api/attachments/${datasource._id}/url`)
|
|
76
|
-
.send({
|
|
77
|
-
bucket: undefined,
|
|
78
|
-
key: "bar",
|
|
79
|
-
})
|
|
80
|
-
.set(config.defaultHeaders())
|
|
81
|
-
.expect("Content-Type", /json/)
|
|
82
|
-
.expect(400)
|
|
83
|
-
expect(res.body.message).toEqual("bucket and key values are required")
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it("should require a key parameter", async () => {
|
|
87
|
-
const res = await request
|
|
88
|
-
.post(`/api/attachments/${datasource._id}/url`)
|
|
89
|
-
.send({
|
|
90
|
-
bucket: "foo",
|
|
91
|
-
})
|
|
92
|
-
.set(config.defaultHeaders())
|
|
93
|
-
.expect("Content-Type", /json/)
|
|
94
|
-
.expect(400)
|
|
95
|
-
expect(res.body.message).toEqual("bucket and key values are required")
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
})
|