@budibase/server 1.0.46-alpha.4 → 1.0.46-alpha.8
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.c21ee1fb.js → index.51efc215.js} +243 -243
- package/builder/assets/{index.243ca52c.css → index.dd9e386f.css} +1 -1
- package/builder/assets/{vendor.10e2ad1b.js → vendor.3bd2f661.js} +1 -1
- package/builder/index.html +3 -3
- package/coverage/clover.xml +1794 -1793
- package/coverage/coverage-final.json +136 -138
- package/coverage/lcov-report/api/controllers/analytics.js.html +6 -6
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/application.js.html +209 -125
- package/coverage/lcov-report/api/controllers/auth.js.html +23 -11
- package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
- package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
- package/coverage/lcov-report/api/controllers/cloud.js.html +12 -12
- package/coverage/lcov-report/api/controllers/component.js.html +5 -5
- package/coverage/lcov-report/api/controllers/datasource.js.html +58 -22
- package/coverage/lcov-report/api/controllers/dev.js.html +19 -19
- package/coverage/lcov-report/api/controllers/index.html +38 -53
- package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
- package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
- package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
- package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.js.html +61 -28
- package/coverage/lcov-report/api/controllers/query/validation.js.html +9 -9
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
- package/coverage/lcov-report/api/controllers/row/index.html +5 -5
- package/coverage/lcov-report/api/controllers/row/index.js.html +13 -13
- package/coverage/lcov-report/api/controllers/row/internal.js.html +26 -26
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +8 -8
- package/coverage/lcov-report/api/controllers/row/utils.js.html +17 -26
- 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 +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +14 -14
- package/coverage/lcov-report/api/controllers/table/internal.js.html +10 -10
- package/coverage/lcov-report/api/controllers/table/utils.js.html +26 -26
- package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
- package/coverage/lcov-report/api/controllers/user.js.html +30 -24
- 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 +26 -26
- package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/application.js.html +9 -9
- package/coverage/lcov-report/api/routes/auth.js.html +6 -6
- package/coverage/lcov-report/api/routes/automation.js.html +14 -14
- package/coverage/lcov-report/api/routes/backup.js.html +8 -8
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +13 -13
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +13 -13
- package/coverage/lcov-report/api/routes/index.html +7 -22
- package/coverage/lcov-report/api/routes/index.js.html +31 -37
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
- package/coverage/lcov-report/api/routes/permission.js.html +12 -12
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +12 -12
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/row.js.html +10 -10
- package/coverage/lcov-report/api/routes/screen.js.html +11 -11
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +13 -13
- package/coverage/lcov-report/api/routes/table.js.html +12 -12
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +8 -8
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/api/routes/webhook.js.html +11 -11
- 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 +7 -7
- package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
- package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
- 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 +1 -1
- 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 +5 -5
- package/coverage/lcov-report/constants/index.js.html +36 -24
- 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 +1 -1
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +7 -7
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +18 -18
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +13 -13
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +73 -73
- 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 +6 -6
- package/coverage/lcov-report/events/utils.js.html +3 -3
- package/coverage/lcov-report/index.html +62 -62
- 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 +5 -5
- package/coverage/lcov-report/middleware/authorized.js.html +171 -69
- package/coverage/lcov-report/middleware/builder.js.html +16 -16
- package/coverage/lcov-report/middleware/currentapp.js.html +46 -73
- package/coverage/lcov-report/middleware/index.html +24 -24
- package/coverage/lcov-report/middleware/joi-validator.js.html +6 -6
- package/coverage/lcov-report/middleware/resourceId.js.html +22 -22
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +17 -17
- package/coverage/lcov-report/middleware/utils.js.html +4 -4
- package/coverage/lcov-report/migrations/usageQuotas/index.html +1 -1
- package/coverage/lcov-report/migrations/usageQuotas/index.js.html +6 -6
- package/coverage/lcov-report/migrations/usageQuotas/syncApps.js.html +6 -6
- package/coverage/lcov-report/migrations/usageQuotas/syncRows.js.html +7 -7
- 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 +23 -8
- 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 +9 -9
- 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 +6 -6
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +17 -17
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
- 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/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +8 -8
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +8 -8
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +5 -5
- package/coverage/lcov-report/utilities/workerRequests.js.html +39 -108
- package/coverage/lcov.info +2292 -2272
- package/dist/api/controllers/application.js +49 -20
- package/dist/api/controllers/auth.js +4 -0
- package/dist/api/controllers/datasource.js +11 -0
- package/dist/api/controllers/query/index.js +11 -3
- package/dist/api/controllers/row/utils.js +1 -2
- package/dist/api/controllers/static/index.js +9 -10
- package/dist/api/controllers/user.js +2 -0
- package/dist/api/routes/index.js +0 -2
- package/dist/constants/index.js +3 -0
- package/dist/definitions/datasource.js +1 -0
- package/dist/integrations/googlesheets.js +340 -0
- package/dist/integrations/index.js +3 -0
- package/dist/integrations/utils.js +6 -3
- package/dist/middleware/authorized.js +55 -30
- package/dist/middleware/currentapp.js +0 -9
- package/dist/package.json +8 -5
- package/dist/tests/utilities/TestConfiguration.js +10 -6
- package/dist/threads/query.js +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/workerRequests.js +0 -20
- package/nodemon.json +1 -1
- package/package.json +9 -6
- package/src/api/controllers/application.js +52 -24
- package/src/api/controllers/auth.js +4 -0
- package/src/api/controllers/datasource.js +12 -0
- package/src/api/controllers/query/index.js +14 -3
- package/src/api/controllers/row/utils.js +1 -4
- package/src/api/controllers/static/index.js +13 -10
- package/src/api/controllers/user.js +2 -0
- package/src/api/routes/index.js +0 -2
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/auth.spec.js +1 -2
- package/src/constants/index.js +4 -0
- package/src/definitions/datasource.ts +3 -0
- package/src/integrations/googlesheets.ts +353 -0
- package/src/integrations/index.ts +3 -0
- package/src/integrations/utils.ts +18 -5
- package/src/middleware/authorized.js +64 -30
- package/src/middleware/currentapp.js +0 -9
- package/src/middleware/tests/authorized.spec.js +6 -4
- package/src/migrations/tests/usageQuotas/syncRows.spec.js +1 -1
- package/src/tests/utilities/TestConfiguration.js +10 -6
- package/src/threads/query.js +5 -0
- package/src/utilities/workerRequests.js +0 -23
- package/coverage/lcov-report/api/controllers/hosting.js.html +0 -146
- package/coverage/lcov-report/api/routes/hosting.js.html +0 -119
- package/dist/api/controllers/hosting.js +0 -30
- package/dist/api/routes/hosting.js +0 -11
- package/src/api/controllers/hosting.js +0 -22
- package/src/api/routes/hosting.js +0 -13
- package/src/api/routes/tests/hosting.spec.js +0 -36
|
@@ -20,7 +20,7 @@ const { cloneDeep } = require("lodash/fp");
|
|
|
20
20
|
const { processObject } = require("@budibase/string-templates");
|
|
21
21
|
const { getAllApps, isDevAppID, getDeployedAppID, Replication, } = require("@budibase/backend-core/db");
|
|
22
22
|
const { USERS_TABLE_SCHEMA } = require("../../constants");
|
|
23
|
-
const {
|
|
23
|
+
const { removeAppFromUserRoles } = require("../../utilities/workerRequests");
|
|
24
24
|
const { clientLibraryPath, stringToReadStream } = require("../../utilities");
|
|
25
25
|
const { getAllLocks } = require("../../utilities/redis");
|
|
26
26
|
const { updateClientLibrary, backupClientLibrary, revertClientLibrary, } = require("../../utilities/fileSystem/clientLibrary");
|
|
@@ -49,31 +49,44 @@ function getUserRoleId(ctx) {
|
|
|
49
49
|
? BUILTIN_ROLE_IDS.PUBLIC
|
|
50
50
|
: ctx.user.role._id;
|
|
51
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function getAppUrl(ctx) {
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
// construct the url
|
|
54
55
|
let url;
|
|
55
56
|
if (ctx.request.body.url) {
|
|
57
|
+
// if the url is provided, use that
|
|
56
58
|
url = encodeURI(ctx.request.body.url);
|
|
57
59
|
}
|
|
58
60
|
else if (ctx.request.body.name) {
|
|
61
|
+
// otherwise use the name
|
|
59
62
|
url = encodeURI(`${ctx.request.body.name}`);
|
|
60
63
|
}
|
|
61
64
|
if (url) {
|
|
62
65
|
url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase();
|
|
63
66
|
}
|
|
64
|
-
if (!env.SELF_HOSTED) {
|
|
65
|
-
return url;
|
|
66
|
-
}
|
|
67
|
-
const deployedApps = yield getDeployedApps();
|
|
68
|
-
if (url &&
|
|
69
|
-
deployedApps[url] != null &&
|
|
70
|
-
ctx.params != null &&
|
|
71
|
-
deployedApps[url].appId !== ctx.params.appId) {
|
|
72
|
-
ctx.throw(400, "App name/URL is already in use.");
|
|
73
|
-
}
|
|
74
67
|
return url;
|
|
75
68
|
});
|
|
76
69
|
}
|
|
70
|
+
const checkAppUrl = (ctx, apps, url, currentAppId) => {
|
|
71
|
+
if (currentAppId) {
|
|
72
|
+
apps = apps.filter(app => app.appId !== currentAppId);
|
|
73
|
+
}
|
|
74
|
+
if (apps.some(app => app.url === url)) {
|
|
75
|
+
ctx.throw(400, "App URL is already in use.");
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const checkAppName = (ctx, apps, name, currentAppId) => {
|
|
79
|
+
// TODO: Replace with Joi
|
|
80
|
+
if (!name) {
|
|
81
|
+
ctx.throw(400, "Name is required");
|
|
82
|
+
}
|
|
83
|
+
if (currentAppId) {
|
|
84
|
+
apps = apps.filter(app => app.appId !== currentAppId);
|
|
85
|
+
}
|
|
86
|
+
if (apps.some(app => app.name === name)) {
|
|
87
|
+
ctx.throw(400, "App name is already in use.");
|
|
88
|
+
}
|
|
89
|
+
};
|
|
77
90
|
function createInstance(template) {
|
|
78
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
92
|
const tenantId = isMultiTenant() ? getTenantId() : null;
|
|
@@ -167,6 +180,11 @@ exports.fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
167
180
|
};
|
|
168
181
|
});
|
|
169
182
|
exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
|
+
const apps = yield getAllApps(CouchDB, { dev: true });
|
|
184
|
+
const name = ctx.request.body.name;
|
|
185
|
+
checkAppName(ctx, apps, name);
|
|
186
|
+
const url = yield getAppUrl(ctx);
|
|
187
|
+
checkAppUrl(ctx, apps, url);
|
|
170
188
|
const { useTemplate, templateKey, templateString } = ctx.request.body;
|
|
171
189
|
const instanceConfig = {
|
|
172
190
|
useTemplate,
|
|
@@ -178,7 +196,6 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
178
196
|
}
|
|
179
197
|
const instance = yield createInstance(instanceConfig);
|
|
180
198
|
const appId = instance._id;
|
|
181
|
-
const url = yield getAppUrlIfNotInUse(ctx);
|
|
182
199
|
const db = new CouchDB(appId);
|
|
183
200
|
let _rev;
|
|
184
201
|
try {
|
|
@@ -196,7 +213,7 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
196
213
|
type: "app",
|
|
197
214
|
version: packageJson.version,
|
|
198
215
|
componentLibraries: ["@budibase/standard-components"],
|
|
199
|
-
name:
|
|
216
|
+
name: name,
|
|
200
217
|
url: url,
|
|
201
218
|
template: ctx.request.body.template,
|
|
202
219
|
instance: instance,
|
|
@@ -219,8 +236,21 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
219
236
|
ctx.status = 200;
|
|
220
237
|
ctx.body = newApplication;
|
|
221
238
|
});
|
|
239
|
+
// This endpoint currently operates as a PATCH rather than a PUT
|
|
240
|
+
// Thus name and url fields are handled only if present
|
|
222
241
|
exports.update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
|
-
const
|
|
242
|
+
const apps = yield getAllApps(CouchDB, { dev: true });
|
|
243
|
+
// validation
|
|
244
|
+
const name = ctx.request.body.name;
|
|
245
|
+
if (name) {
|
|
246
|
+
checkAppName(ctx, apps, name, ctx.params.appId);
|
|
247
|
+
}
|
|
248
|
+
const url = yield getAppUrl(ctx);
|
|
249
|
+
if (url) {
|
|
250
|
+
checkAppUrl(ctx, apps, url, ctx.params.appId);
|
|
251
|
+
ctx.request.body.url = url;
|
|
252
|
+
}
|
|
253
|
+
const data = yield updateAppPackage(ctx.request.body, ctx.params.appId);
|
|
224
254
|
ctx.status = 200;
|
|
225
255
|
ctx.body = data;
|
|
226
256
|
});
|
|
@@ -239,7 +269,7 @@ exports.updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
239
269
|
version: packageJson.version,
|
|
240
270
|
revertableVersion: currentVersion,
|
|
241
271
|
};
|
|
242
|
-
const data = yield updateAppPackage(
|
|
272
|
+
const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
|
|
243
273
|
ctx.status = 200;
|
|
244
274
|
ctx.body = data;
|
|
245
275
|
});
|
|
@@ -259,7 +289,7 @@ exports.revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
259
289
|
version: application.revertableVersion,
|
|
260
290
|
revertableVersion: null,
|
|
261
291
|
};
|
|
262
|
-
const data = yield updateAppPackage(
|
|
292
|
+
const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
|
|
263
293
|
ctx.status = 200;
|
|
264
294
|
ctx.body = data;
|
|
265
295
|
});
|
|
@@ -326,11 +356,10 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
326
356
|
};
|
|
327
357
|
}
|
|
328
358
|
});
|
|
329
|
-
const updateAppPackage = (
|
|
330
|
-
const url = yield getAppUrlIfNotInUse(ctx);
|
|
359
|
+
const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
331
360
|
const db = new CouchDB(appId);
|
|
332
361
|
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
333
|
-
const newAppPackage = Object.assign(Object.assign(
|
|
362
|
+
const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
|
|
334
363
|
if (appPackage._rev !== application._rev) {
|
|
335
364
|
newAppPackage._rev = application._rev;
|
|
336
365
|
}
|
|
@@ -24,6 +24,8 @@ exports.fetchSelf = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
24
24
|
const user = yield getFullUser(ctx, userId);
|
|
25
25
|
// this shouldn't be returned by the app self
|
|
26
26
|
delete user.roles;
|
|
27
|
+
// forward the csrf token from the session
|
|
28
|
+
user.csrfToken = ctx.user.csrfToken;
|
|
27
29
|
if (appId) {
|
|
28
30
|
const db = new CouchDB(appId);
|
|
29
31
|
// remove the full roles structure
|
|
@@ -31,6 +33,8 @@ exports.fetchSelf = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
31
33
|
try {
|
|
32
34
|
const userTable = yield db.get(InternalTables.USER_METADATA);
|
|
33
35
|
const metadata = yield db.get(userId);
|
|
36
|
+
// make sure there is never a stale csrf token
|
|
37
|
+
delete metadata.csrfToken;
|
|
34
38
|
// specifically needs to make sure is enriched
|
|
35
39
|
ctx.body = yield outputProcessing(ctx, userTable, Object.assign(Object.assign({}, user), metadata));
|
|
36
40
|
}
|
|
@@ -28,6 +28,12 @@ exports.fetch = function (ctx) {
|
|
|
28
28
|
const datasources = (yield database.allDocs(getDatasourceParams(null, {
|
|
29
29
|
include_docs: true,
|
|
30
30
|
}))).rows.map(row => row.doc);
|
|
31
|
+
for (let datasource of datasources) {
|
|
32
|
+
if (datasource.config && datasource.config.auth) {
|
|
33
|
+
// strip secrets from response so they don't show in the network request
|
|
34
|
+
delete datasource.config.auth;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
31
37
|
ctx.body = [bbInternalDb, ...datasources];
|
|
32
38
|
});
|
|
33
39
|
};
|
|
@@ -78,8 +84,13 @@ exports.update = function (ctx) {
|
|
|
78
84
|
const db = new CouchDB(ctx.appId);
|
|
79
85
|
const datasourceId = ctx.params.datasourceId;
|
|
80
86
|
let datasource = yield db.get(datasourceId);
|
|
87
|
+
const auth = datasource.config.auth;
|
|
81
88
|
yield invalidateVariables(datasource, ctx.request.body);
|
|
82
89
|
datasource = Object.assign(Object.assign({}, datasource), ctx.request.body);
|
|
90
|
+
if (auth && !ctx.request.body.auth) {
|
|
91
|
+
// don't strip auth config from DB
|
|
92
|
+
datasource.config.auth = auth;
|
|
93
|
+
}
|
|
83
94
|
const response = yield db.put(datasource);
|
|
84
95
|
datasource._rev = response.rev;
|
|
85
96
|
// Drain connection pools when configuration is changed
|
|
@@ -130,6 +130,15 @@ function execute(ctx, opts = { rowsOnly: false }) {
|
|
|
130
130
|
const db = new CouchDB(ctx.appId);
|
|
131
131
|
const query = yield db.get(ctx.params.queryId);
|
|
132
132
|
const datasource = yield db.get(query.datasourceId);
|
|
133
|
+
const enrichedParameters = ctx.request.body.parameters || {};
|
|
134
|
+
// make sure parameters are fully enriched with defaults
|
|
135
|
+
if (query && query.parameters) {
|
|
136
|
+
for (let parameter of query.parameters) {
|
|
137
|
+
if (!enrichedParameters[parameter.name]) {
|
|
138
|
+
enrichedParameters[parameter.name] = parameter.default;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
133
142
|
// call the relevant CRUD method on the integration class
|
|
134
143
|
try {
|
|
135
144
|
const { rows, pagination, extra } = yield Runner.run({
|
|
@@ -138,7 +147,7 @@ function execute(ctx, opts = { rowsOnly: false }) {
|
|
|
138
147
|
queryVerb: query.queryVerb,
|
|
139
148
|
fields: query.fields,
|
|
140
149
|
pagination: ctx.request.body.pagination,
|
|
141
|
-
parameters:
|
|
150
|
+
parameters: enrichedParameters,
|
|
142
151
|
transformer: query.transformer,
|
|
143
152
|
queryId: ctx.params.queryId,
|
|
144
153
|
});
|
|
@@ -170,8 +179,7 @@ const removeDynamicVariables = (db, queryId) => __awaiter(void 0, void 0, void 0
|
|
|
170
179
|
const dynamicVariables = datasource.config.dynamicVariables;
|
|
171
180
|
if (dynamicVariables) {
|
|
172
181
|
// delete dynamic variables from the datasource
|
|
173
|
-
|
|
174
|
-
datasource.config.dynamicVariables = newVariables;
|
|
182
|
+
datasource.config.dynamicVariables = dynamicVariables.filter(dv => dv.queryId !== queryId);
|
|
175
183
|
yield db.put(datasource);
|
|
176
184
|
// invalidate the deleted variables
|
|
177
185
|
const variablesToDelete = dynamicVariables.filter(dv => dv.queryId === queryId);
|
|
@@ -59,8 +59,7 @@ exports.validate = ({ appId, tableId, row, table }) => __awaiter(void 0, void 0,
|
|
|
59
59
|
const constraints = cloneDeep(table.schema[fieldName].constraints);
|
|
60
60
|
const type = table.schema[fieldName].type;
|
|
61
61
|
// special case for options, need to always allow unselected (null)
|
|
62
|
-
if (
|
|
63
|
-
constraints.inclusion) {
|
|
62
|
+
if (type === FieldTypes.OPTIONS && constraints.inclusion) {
|
|
64
63
|
constraints.inclusion.push(null);
|
|
65
64
|
}
|
|
66
65
|
let res;
|
|
@@ -14,7 +14,7 @@ const { resolve, join } = require("../../../utilities/centralPath");
|
|
|
14
14
|
const uuid = require("uuid");
|
|
15
15
|
const { ObjectStoreBuckets } = require("../../../constants");
|
|
16
16
|
const { processString } = require("@budibase/string-templates");
|
|
17
|
-
const {
|
|
17
|
+
const { getAllApps } = require("@budibase/backend-core/db");
|
|
18
18
|
const CouchDB = require("../../../db");
|
|
19
19
|
const { loadHandlebarsFile, NODE_MODULES_PATH, TOP_LEVEL_PATH, } = require("../../../utilities/fileSystem");
|
|
20
20
|
const env = require("../../../environment");
|
|
@@ -43,13 +43,15 @@ function prepareUpload({ s3Key, bucket, metadata, file }) {
|
|
|
43
43
|
};
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function getAppIdFromUrl(ctx) {
|
|
47
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
// the "appId" component of the URL
|
|
48
|
+
// the "appId" component of the URL can be the id or the custom url
|
|
49
49
|
let possibleAppUrl = `/${encodeURI(ctx.params.appId).toLowerCase()}`;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
// search prod apps for a url that matches, exclude dev where id is always used
|
|
51
|
+
const apps = yield getAllApps(CouchDB, { dev: false });
|
|
52
|
+
const app = apps.filter(a => a.url && a.url.toLowerCase() === possibleAppUrl)[0];
|
|
53
|
+
if (app && app.appId) {
|
|
54
|
+
return app.appId;
|
|
53
55
|
}
|
|
54
56
|
else {
|
|
55
57
|
return ctx.params.appId;
|
|
@@ -82,10 +84,7 @@ exports.uploadFile = function (ctx) {
|
|
|
82
84
|
};
|
|
83
85
|
exports.serveApp = function (ctx) {
|
|
84
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
let appId = ctx
|
|
86
|
-
if (env.SELF_HOSTED) {
|
|
87
|
-
appId = yield checkForSelfHostedURL(ctx);
|
|
88
|
-
}
|
|
87
|
+
let appId = yield getAppIdFromUrl(ctx);
|
|
89
88
|
const App = require("./templates/BudibaseApp.svelte").default;
|
|
90
89
|
const db = new CouchDB(appId, { skip_setup: true });
|
|
91
90
|
const appInfo = yield db.get(DocumentTypes.APP_METADATA);
|
|
@@ -155,6 +155,8 @@ exports.updateSelfMetadata = function (ctx) {
|
|
|
155
155
|
ctx.request.body._id = ctx.user._id;
|
|
156
156
|
// make sure no stale rev
|
|
157
157
|
delete ctx.request.body._rev;
|
|
158
|
+
// make sure no csrf token
|
|
159
|
+
delete ctx.request.body.csrfToken;
|
|
158
160
|
yield exports.updateMetadata(ctx);
|
|
159
161
|
});
|
|
160
162
|
};
|
package/dist/api/routes/index.js
CHANGED
|
@@ -21,7 +21,6 @@ const integrationRoutes = require("./integration");
|
|
|
21
21
|
const permissionRoutes = require("./permission");
|
|
22
22
|
const datasourceRoutes = require("./datasource");
|
|
23
23
|
const queryRoutes = require("./query");
|
|
24
|
-
const hostingRoutes = require("./hosting");
|
|
25
24
|
const backupRoutes = require("./backup");
|
|
26
25
|
const metadataRoutes = require("./metadata");
|
|
27
26
|
const devRoutes = require("./dev");
|
|
@@ -46,7 +45,6 @@ exports.mainRoutes = [
|
|
|
46
45
|
permissionRoutes,
|
|
47
46
|
datasourceRoutes,
|
|
48
47
|
queryRoutes,
|
|
49
|
-
hostingRoutes,
|
|
50
48
|
backupRoutes,
|
|
51
49
|
metadataRoutes,
|
|
52
50
|
devRoutes,
|
package/dist/constants/index.js
CHANGED
|
@@ -49,6 +49,7 @@ var SourceNames;
|
|
|
49
49
|
SourceNames["ARANGODB"] = "ARANGODB";
|
|
50
50
|
SourceNames["REST"] = "REST";
|
|
51
51
|
SourceNames["ORACLE"] = "ORACLE";
|
|
52
|
+
SourceNames["GOOGLE_SHEETS"] = "GOOGLE_SHEETS";
|
|
52
53
|
})(SourceNames = exports.SourceNames || (exports.SourceNames = {}));
|
|
53
54
|
var IncludeRelationships;
|
|
54
55
|
(function (IncludeRelationships) {
|
|
@@ -0,0 +1,340 @@
|
|
|
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 = {}));
|