@budibase/server 1.3.14 → 1.3.15-alpha.2
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.2884f3c4.js +995 -0
- package/builder/assets/{index.a70e216a.css → index.ecdac070.css} +2 -2
- package/builder/index.html +2 -4
- package/coverage/clover.xml +296 -254
- package/coverage/coverage-final.json +17 -17
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- 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/component.js.html +82 -13
- package/coverage/lcov-report/api/controllers/datasource.js.html +20 -20
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +30 -30
- 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 +1 -1
- 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/screen.js.html +207 -12
- 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 +12 -12
- 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 +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/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.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 +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 +18 -18
- 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 +56 -20
- 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 +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +28 -28
- 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 +33 -33
- package/coverage/lcov-report/middleware/index.html +1 -1
- 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 +1 -1
- 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 +1 -1
- package/coverage/lcov.info +533 -445
- package/dist/api/controllers/application.js +5 -4
- package/dist/api/controllers/component.js +18 -1
- package/dist/api/controllers/datasource.js +4 -4
- package/dist/api/controllers/integration.js +4 -4
- package/dist/api/controllers/plugin/file.js +24 -0
- package/dist/api/controllers/plugin/github.js +69 -0
- package/dist/api/controllers/plugin/index.js +192 -0
- package/dist/api/controllers/plugin/npm.js +58 -0
- package/dist/api/controllers/plugin/uploaders.js +11 -0
- package/dist/api/controllers/plugin/url.js +24 -0
- package/dist/api/controllers/plugin/utils.js +26 -0
- package/dist/api/controllers/screen.js +52 -2
- 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/routes/index.js +2 -0
- package/dist/api/routes/plugin.js +39 -0
- package/dist/app.js +11 -0
- package/dist/db/utils.js +10 -1
- 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/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 +93 -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/package.json +9 -6
- package/dist/threads/query.js +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +110 -1
- package/dist/watch.js +77 -0
- package/dist/websocket.js +22 -0
- package/package.json +10 -7
- package/scripts/dev/manage.js +1 -0
- package/src/api/controllers/application.ts +1 -1
- package/src/api/controllers/component.js +25 -2
- package/src/api/controllers/datasource.js +4 -4
- 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 +206 -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/screen.js +66 -1
- package/src/api/controllers/static/index.ts +1 -0
- package/src/api/controllers/static/templates/BudibaseApp.svelte +10 -0
- package/src/api/controllers/static/templates/preview.hbs +5 -1
- package/src/api/routes/index.ts +2 -0
- package/src/api/routes/plugin.ts +14 -0
- package/src/api/routes/tests/query.spec.js +8 -25
- package/src/app.ts +14 -0
- package/src/db/utils.js +12 -0
- 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/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 +59 -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/module.d.ts +2 -0
- package/src/threads/query.ts +2 -2
- package/src/utilities/fileSystem/index.js +129 -0
- package/src/watch.ts +38 -0
- package/src/websocket.ts +26 -0
- package/builder/assets/index.d8428ac8.js +0 -876
- package/builder/assets/vendor.5e1fe644.css +0 -1
- package/builder/assets/vendor.67dbd8fa.js +0 -248
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.sync = exports.destroy = exports.revertClient = exports.updateClient = exports.update = exports.create = exports.fetchAppPackage = exports.fetchAppDefinition = exports.fetch = exports.getAppUrl = void 0;
|
|
15
|
+
exports.updateAppPackage = exports.sync = exports.destroy = exports.revertClient = exports.updateClient = exports.update = exports.create = exports.fetchAppPackage = exports.fetchAppDefinition = exports.fetch = exports.getAppUrl = void 0;
|
|
16
16
|
const environment_1 = __importDefault(require("../../environment"));
|
|
17
17
|
const package_json_1 = __importDefault(require("../../../package.json"));
|
|
18
18
|
const staticViews_1 = require("../../db/views/staticViews");
|
|
@@ -353,7 +353,7 @@ const update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
353
353
|
checkAppUrl(ctx, apps, url, ctx.params.appId);
|
|
354
354
|
ctx.request.body.url = url;
|
|
355
355
|
}
|
|
356
|
-
const app = yield updateAppPackage(ctx.request.body, ctx.params.appId);
|
|
356
|
+
const app = yield (0, exports.updateAppPackage)(ctx.request.body, ctx.params.appId);
|
|
357
357
|
yield backend_core_2.events.app.updated(app);
|
|
358
358
|
ctx.status = 200;
|
|
359
359
|
ctx.body = app;
|
|
@@ -375,7 +375,7 @@ const updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
375
375
|
version: updatedToVersion,
|
|
376
376
|
revertableVersion: currentVersion,
|
|
377
377
|
};
|
|
378
|
-
const app = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
|
|
378
|
+
const app = yield (0, exports.updateAppPackage)(appPackageUpdates, ctx.params.appId);
|
|
379
379
|
yield backend_core_2.events.app.versionUpdated(app, currentVersion, updatedToVersion);
|
|
380
380
|
ctx.status = 200;
|
|
381
381
|
ctx.body = app;
|
|
@@ -399,7 +399,7 @@ const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
399
399
|
version: revertedToVersion,
|
|
400
400
|
revertableVersion: null,
|
|
401
401
|
};
|
|
402
|
-
const app = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
|
|
402
|
+
const app = yield (0, exports.updateAppPackage)(appPackageUpdates, ctx.params.appId);
|
|
403
403
|
yield backend_core_2.events.app.versionReverted(app, currentVersion, revertedToVersion);
|
|
404
404
|
ctx.status = 200;
|
|
405
405
|
ctx.body = app;
|
|
@@ -527,6 +527,7 @@ const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0
|
|
|
527
527
|
return newAppPackage;
|
|
528
528
|
}));
|
|
529
529
|
});
|
|
530
|
+
exports.updateAppPackage = updateAppPackage;
|
|
530
531
|
const migrateAppNavigation = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
531
532
|
const db = backend_core_1.context.getAppDB();
|
|
532
533
|
const existing = yield db.get(utils_1.DocumentType.APP_METADATA);
|
|
@@ -8,9 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const { DocumentType } = require("../../db/utils");
|
|
11
|
+
const { DocumentType, getPluginParams } = require("../../db/utils");
|
|
12
12
|
const { getComponentLibraryManifest } = require("../../utilities/fileSystem");
|
|
13
13
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
14
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy");
|
|
15
|
+
const env = require("../../environment");
|
|
14
16
|
exports.fetchAppComponentDefinitions = function (ctx) {
|
|
15
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
18
|
try {
|
|
@@ -35,6 +37,21 @@ exports.fetchAppComponentDefinitions = function (ctx) {
|
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
}
|
|
40
|
+
// for now custom components only supported in self-host
|
|
41
|
+
if (env.SELF_HOSTED) {
|
|
42
|
+
// Add custom components
|
|
43
|
+
const globalDB = getGlobalDB();
|
|
44
|
+
const response = yield globalDB.allDocs(getPluginParams(null, {
|
|
45
|
+
include_docs: true,
|
|
46
|
+
}));
|
|
47
|
+
response.rows
|
|
48
|
+
.map(row => row.doc)
|
|
49
|
+
.filter(plugin => plugin.schema.type === "component")
|
|
50
|
+
.forEach(plugin => {
|
|
51
|
+
const fullComponentName = `plugin/${plugin.name}`;
|
|
52
|
+
definitions[fullComponentName] = Object.assign({ component: fullComponentName }, plugin.schema.schema);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
38
55
|
ctx.body = definitions;
|
|
39
56
|
}
|
|
40
57
|
catch (err) {
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const { generateDatasourceID, getDatasourceParams, getQueryParams, DocumentType, BudibaseInternalDB, getTableParams, } = require("../../db/utils");
|
|
12
12
|
const { BuildSchemaErrors, InvalidColumns } = require("../../constants");
|
|
13
|
-
const {
|
|
13
|
+
const { getIntegration } = require("../../integrations");
|
|
14
14
|
const { getDatasourceAndQuery } = require("./row/utils");
|
|
15
15
|
const { invalidateDynamicVariables } = require("../../threads/utils");
|
|
16
16
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
@@ -96,7 +96,7 @@ exports.update = function (ctx) {
|
|
|
96
96
|
datasource._rev = response.rev;
|
|
97
97
|
// Drain connection pools when configuration is changed
|
|
98
98
|
if (datasource.source) {
|
|
99
|
-
const source =
|
|
99
|
+
const source = yield getIntegration(datasource.source);
|
|
100
100
|
if (source && source.pool) {
|
|
101
101
|
yield source.pool.end();
|
|
102
102
|
}
|
|
@@ -123,7 +123,7 @@ exports.save = function (ctx) {
|
|
|
123
123
|
datasource._rev = dbResp.rev;
|
|
124
124
|
// Drain connection pools when configuration is changed
|
|
125
125
|
if (datasource.source) {
|
|
126
|
-
const source =
|
|
126
|
+
const source = yield getIntegration(datasource.source);
|
|
127
127
|
if (source && source.pool) {
|
|
128
128
|
yield source.pool.end();
|
|
129
129
|
}
|
|
@@ -188,7 +188,7 @@ function updateError(error, newError, tables) {
|
|
|
188
188
|
return error;
|
|
189
189
|
}
|
|
190
190
|
const buildSchemaHelper = (datasource) => __awaiter(void 0, void 0, void 0, function* () {
|
|
191
|
-
const Connector =
|
|
191
|
+
const Connector = yield getIntegration(datasource.source);
|
|
192
192
|
// Connect to the DB and build the schema
|
|
193
193
|
const connector = new Connector(datasource.config);
|
|
194
194
|
yield connector.buildSchema(datasource._id, datasource.entities);
|
|
@@ -8,15 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const {
|
|
12
|
-
const { definitions } = require("../../integrations");
|
|
11
|
+
const { getDefinitions } = require("../../integrations");
|
|
13
12
|
const { SourceName } = require("@budibase/types");
|
|
14
13
|
const googlesheets = require("../../integrations/googlesheets");
|
|
15
14
|
const { featureFlags } = require("@budibase/backend-core");
|
|
16
15
|
exports.fetch = function (ctx) {
|
|
17
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
17
|
ctx.status = 200;
|
|
19
|
-
const defs =
|
|
18
|
+
const defs = yield getDefinitions();
|
|
20
19
|
// for google sheets integration google verification
|
|
21
20
|
if (featureFlags.isEnabled(featureFlags.FeatureFlag.GOOGLE_SHEETS)) {
|
|
22
21
|
defs[SourceName.GOOGLE_SHEETS] = googlesheets.schema;
|
|
@@ -26,7 +25,8 @@ exports.fetch = function (ctx) {
|
|
|
26
25
|
};
|
|
27
26
|
exports.find = function (ctx) {
|
|
28
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const defs = yield getDefinitions();
|
|
29
29
|
ctx.status = 200;
|
|
30
|
-
ctx.body =
|
|
30
|
+
ctx.body = defs[ctx.params.type];
|
|
31
31
|
});
|
|
32
32
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
exports.fileUpload = void 0;
|
|
13
|
+
const fileSystem_1 = require("../../../utilities/fileSystem");
|
|
14
|
+
function fileUpload(file) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
if (!file.name.endsWith(".tar.gz")) {
|
|
17
|
+
throw new Error("Plugin must be compressed into a gzipped tarball.");
|
|
18
|
+
}
|
|
19
|
+
const path = (0, fileSystem_1.createTempFolder)(file.name.split(".tar.gz")[0]);
|
|
20
|
+
yield (0, fileSystem_1.extractTarball)(file.path, path);
|
|
21
|
+
return yield (0, fileSystem_1.getPluginMetadata)(path);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.fileUpload = fileUpload;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.githubUpload = exports.request = void 0;
|
|
16
|
+
const fileSystem_1 = require("../../../utilities/fileSystem");
|
|
17
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
18
|
+
const utils_1 = require("./utils");
|
|
19
|
+
function request(url, headers, err) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const response = yield (0, node_fetch_1.default)(url, { headers });
|
|
22
|
+
if (response.status >= 300) {
|
|
23
|
+
const respErr = yield response.text();
|
|
24
|
+
throw new Error(`Error: ${err} - ${respErr}`);
|
|
25
|
+
}
|
|
26
|
+
return response.json();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.request = request;
|
|
30
|
+
function githubUpload(url, name = "", token = "") {
|
|
31
|
+
var _a;
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
let githubUrl = url;
|
|
34
|
+
if (!githubUrl.includes("https://github.com/")) {
|
|
35
|
+
throw new Error("The plugin origin must be from Github");
|
|
36
|
+
}
|
|
37
|
+
if (url.includes(".git")) {
|
|
38
|
+
githubUrl = url.replace(".git", "");
|
|
39
|
+
}
|
|
40
|
+
const githubApiUrl = githubUrl.replace("https://github.com/", "https://api.github.com/repos/");
|
|
41
|
+
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
|
42
|
+
const pluginDetails = yield request(githubApiUrl, headers, "Repository not found");
|
|
43
|
+
const pluginName = pluginDetails.name || name;
|
|
44
|
+
const pluginLatestReleaseUrl = (pluginDetails === null || pluginDetails === void 0 ? void 0 : pluginDetails["releases_url"])
|
|
45
|
+
? pluginDetails === null || pluginDetails === void 0 ? void 0 : pluginDetails["releases_url"].replace("{/id}", "/latest")
|
|
46
|
+
: undefined;
|
|
47
|
+
if (!pluginLatestReleaseUrl) {
|
|
48
|
+
throw new Error("Github release not found");
|
|
49
|
+
}
|
|
50
|
+
const pluginReleaseDetails = yield request(pluginLatestReleaseUrl, headers, "Github latest release not found");
|
|
51
|
+
const pluginReleaseTarballAsset = (_a = pluginReleaseDetails === null || pluginReleaseDetails === void 0 ? void 0 : pluginReleaseDetails.assets) === null || _a === void 0 ? void 0 : _a.find((x) => (x === null || x === void 0 ? void 0 : x["content_type"]) === "application/gzip");
|
|
52
|
+
const pluginLastReleaseTarballUrl = pluginReleaseTarballAsset === null || pluginReleaseTarballAsset === void 0 ? void 0 : pluginReleaseTarballAsset["browser_download_url"];
|
|
53
|
+
if (!pluginLastReleaseTarballUrl) {
|
|
54
|
+
throw new Error("Github latest release url not found");
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const path = yield (0, utils_1.downloadUnzipTarball)(pluginLastReleaseTarballUrl, pluginName, headers);
|
|
58
|
+
return yield (0, fileSystem_1.getPluginMetadata)(path);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
let errMsg = (err === null || err === void 0 ? void 0 : err.message) || err;
|
|
62
|
+
if (errMsg === "unexpected response Not Found") {
|
|
63
|
+
errMsg = "Github release tarball not found";
|
|
64
|
+
}
|
|
65
|
+
throw new Error(errMsg);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
exports.githubUpload = githubUpload;
|
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.processPlugin = exports.storePlugin = exports.destroy = exports.fetch = exports.create = exports.upload = exports.getPlugins = void 0;
|
|
16
|
+
const constants_1 = require("../../../constants");
|
|
17
|
+
const fileSystem_1 = require("../../../utilities/fileSystem");
|
|
18
|
+
const uploaders_1 = require("./uploaders");
|
|
19
|
+
const tenancy_1 = require("@budibase/backend-core/tenancy");
|
|
20
|
+
const plugins_1 = require("@budibase/backend-core/plugins");
|
|
21
|
+
const utils_1 = require("../../../db/utils");
|
|
22
|
+
const objectStore_1 = require("@budibase/backend-core/objectStore");
|
|
23
|
+
const types_1 = require("@budibase/types");
|
|
24
|
+
const environment_1 = __importDefault(require("../../../environment"));
|
|
25
|
+
const websocket_1 = require("../../../websocket");
|
|
26
|
+
function getPlugins(type) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const db = (0, tenancy_1.getGlobalDB)();
|
|
29
|
+
const response = yield db.allDocs((0, utils_1.getPluginParams)(null, {
|
|
30
|
+
include_docs: true,
|
|
31
|
+
}));
|
|
32
|
+
const plugins = response.rows.map((row) => row.doc);
|
|
33
|
+
if (type) {
|
|
34
|
+
return plugins.filter((plugin) => { var _a; return ((_a = plugin.schema) === null || _a === void 0 ? void 0 : _a.type) === type; });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return plugins;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.getPlugins = getPlugins;
|
|
42
|
+
function upload(ctx) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const plugins = ctx.request.files.file.length > 1
|
|
45
|
+
? Array.from(ctx.request.files.file)
|
|
46
|
+
: [ctx.request.files.file];
|
|
47
|
+
try {
|
|
48
|
+
let docs = [];
|
|
49
|
+
// can do single or multiple plugins
|
|
50
|
+
for (let plugin of plugins) {
|
|
51
|
+
const doc = yield processPlugin(plugin, types_1.PluginSource.FILE);
|
|
52
|
+
docs.push(doc);
|
|
53
|
+
}
|
|
54
|
+
ctx.body = {
|
|
55
|
+
message: "Plugin(s) uploaded successfully",
|
|
56
|
+
plugins: docs,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
const errMsg = (err === null || err === void 0 ? void 0 : err.message) ? err === null || err === void 0 ? void 0 : err.message : err;
|
|
61
|
+
ctx.throw(400, `Failed to import plugin: ${errMsg}`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.upload = upload;
|
|
66
|
+
function create(ctx) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const { source, url, headers, githubToken } = ctx.request.body;
|
|
69
|
+
if (!environment_1.default.SELF_HOSTED) {
|
|
70
|
+
ctx.throw(400, "Plugins not supported outside of self-host.");
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
let metadata;
|
|
74
|
+
let directory;
|
|
75
|
+
// Generating random name as a backup and needed for url
|
|
76
|
+
let name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000);
|
|
77
|
+
switch (source) {
|
|
78
|
+
case types_1.PluginSource.NPM:
|
|
79
|
+
const { metadata: metadataNpm, directory: directoryNpm } = yield (0, uploaders_1.npmUpload)(url, name);
|
|
80
|
+
metadata = metadataNpm;
|
|
81
|
+
directory = directoryNpm;
|
|
82
|
+
break;
|
|
83
|
+
case types_1.PluginSource.GITHUB:
|
|
84
|
+
const { metadata: metadataGithub, directory: directoryGithub } = yield (0, uploaders_1.githubUpload)(url, name, githubToken);
|
|
85
|
+
metadata = metadataGithub;
|
|
86
|
+
directory = directoryGithub;
|
|
87
|
+
break;
|
|
88
|
+
case types_1.PluginSource.URL:
|
|
89
|
+
const headersObj = headers || {};
|
|
90
|
+
const { metadata: metadataUrl, directory: directoryUrl } = yield (0, uploaders_1.urlUpload)(url, name, headersObj);
|
|
91
|
+
metadata = metadataUrl;
|
|
92
|
+
directory = directoryUrl;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
(0, plugins_1.validate)(metadata === null || metadata === void 0 ? void 0 : metadata.schema);
|
|
96
|
+
const doc = yield storePlugin(metadata, directory, source);
|
|
97
|
+
ctx.body = {
|
|
98
|
+
message: "Plugin uploaded successfully",
|
|
99
|
+
plugins: [doc],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
const errMsg = (err === null || err === void 0 ? void 0 : err.message) ? err === null || err === void 0 ? void 0 : err.message : err;
|
|
104
|
+
ctx.throw(400, `Failed to import plugin: ${errMsg}`);
|
|
105
|
+
}
|
|
106
|
+
ctx.status = 200;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
exports.create = create;
|
|
110
|
+
function fetch(ctx) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
ctx.body = yield getPlugins();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
exports.fetch = fetch;
|
|
116
|
+
function destroy(ctx) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const db = (0, tenancy_1.getGlobalDB)();
|
|
119
|
+
const { pluginId } = ctx.params;
|
|
120
|
+
try {
|
|
121
|
+
const plugin = yield db.get(pluginId);
|
|
122
|
+
const bucketPath = `${plugin.name}/`;
|
|
123
|
+
yield (0, objectStore_1.deleteFolder)(constants_1.ObjectStoreBuckets.PLUGINS, bucketPath);
|
|
124
|
+
yield db.remove(pluginId, plugin._rev);
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
const errMsg = (err === null || err === void 0 ? void 0 : err.message) ? err === null || err === void 0 ? void 0 : err.message : err;
|
|
128
|
+
ctx.throw(400, `Failed to delete plugin: ${errMsg}`);
|
|
129
|
+
}
|
|
130
|
+
ctx.message = `Plugin ${ctx.params.pluginId} deleted.`;
|
|
131
|
+
ctx.status = 200;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
exports.destroy = destroy;
|
|
135
|
+
function storePlugin(metadata, directory, source) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const db = (0, tenancy_1.getGlobalDB)();
|
|
138
|
+
const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description, hash = metadata.schema.hash;
|
|
139
|
+
// first open the tarball into tmp directory
|
|
140
|
+
const bucketPath = `${name}/`;
|
|
141
|
+
const files = yield (0, objectStore_1.uploadDirectory)(constants_1.ObjectStoreBuckets.PLUGINS, directory, bucketPath);
|
|
142
|
+
const jsFile = files.find((file) => file.name.endsWith(".js"));
|
|
143
|
+
if (!jsFile) {
|
|
144
|
+
throw new Error(`Plugin missing .js file.`);
|
|
145
|
+
}
|
|
146
|
+
// validate the JS for a datasource
|
|
147
|
+
if (metadata.schema.type === types_1.PluginType.DATASOURCE) {
|
|
148
|
+
const js = (0, fileSystem_1.loadJSFile)(directory, jsFile.name);
|
|
149
|
+
// TODO: this isn't safe - but we need full node environment
|
|
150
|
+
// in future we should do this in a thread for safety
|
|
151
|
+
try {
|
|
152
|
+
eval(js);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
const message = (err === null || err === void 0 ? void 0 : err.message) ? err.message : JSON.stringify(err);
|
|
156
|
+
throw new Error(`JS invalid: ${message}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const jsFileName = jsFile.name;
|
|
160
|
+
const pluginId = (0, utils_1.generatePluginID)(name);
|
|
161
|
+
// overwrite existing docs entirely if they exist
|
|
162
|
+
let rev;
|
|
163
|
+
try {
|
|
164
|
+
const existing = yield db.get(pluginId);
|
|
165
|
+
rev = existing._rev;
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
rev = undefined;
|
|
169
|
+
}
|
|
170
|
+
let doc = Object.assign(Object.assign({ _id: pluginId, _rev: rev }, metadata), { name,
|
|
171
|
+
version,
|
|
172
|
+
hash,
|
|
173
|
+
description, jsUrl: `${bucketPath}${jsFileName}` });
|
|
174
|
+
if (source) {
|
|
175
|
+
doc = Object.assign(Object.assign({}, doc), { source });
|
|
176
|
+
}
|
|
177
|
+
const response = yield db.put(doc);
|
|
178
|
+
websocket_1.ClientAppSocket.emit("plugin-update", { name, hash });
|
|
179
|
+
return Object.assign(Object.assign({}, doc), { _rev: response.rev });
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
exports.storePlugin = storePlugin;
|
|
183
|
+
function processPlugin(plugin, source) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
if (!environment_1.default.SELF_HOSTED) {
|
|
186
|
+
throw new Error("Plugins not supported outside of self-host.");
|
|
187
|
+
}
|
|
188
|
+
const { metadata, directory } = yield (0, uploaders_1.fileUpload)(plugin);
|
|
189
|
+
return yield storePlugin(metadata, directory, source);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
exports.processPlugin = processPlugin;
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.npmUpload = void 0;
|
|
16
|
+
const fileSystem_1 = require("../../../utilities/fileSystem");
|
|
17
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
18
|
+
const path_1 = require("path");
|
|
19
|
+
const utils_1 = require("./utils");
|
|
20
|
+
function npmUpload(url, name, headers = {}) {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
let npmTarballUrl = url;
|
|
24
|
+
let pluginName = name;
|
|
25
|
+
if (!npmTarballUrl.includes("https://www.npmjs.com") &&
|
|
26
|
+
!npmTarballUrl.includes("https://registry.npmjs.org")) {
|
|
27
|
+
throw new Error("The plugin origin must be from NPM");
|
|
28
|
+
}
|
|
29
|
+
if (!npmTarballUrl.includes(".tgz")) {
|
|
30
|
+
const npmPackageURl = url.replace("https://www.npmjs.com/package/", "https://registry.npmjs.org/");
|
|
31
|
+
const response = yield (0, node_fetch_1.default)(npmPackageURl);
|
|
32
|
+
if (response.status !== 200) {
|
|
33
|
+
throw new Error("NPM Package not found");
|
|
34
|
+
}
|
|
35
|
+
let npmDetails = yield response.json();
|
|
36
|
+
pluginName = npmDetails.name;
|
|
37
|
+
const npmVersion = npmDetails["dist-tags"].latest;
|
|
38
|
+
npmTarballUrl = (_c = (_b = (_a = npmDetails === null || npmDetails === void 0 ? void 0 : npmDetails.versions) === null || _a === void 0 ? void 0 : _a[npmVersion]) === null || _b === void 0 ? void 0 : _b.dist) === null || _c === void 0 ? void 0 : _c.tarball;
|
|
39
|
+
if (!npmTarballUrl) {
|
|
40
|
+
throw new Error("NPM tarball url not found");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const path = yield (0, utils_1.downloadUnzipTarball)(npmTarballUrl, pluginName, headers);
|
|
44
|
+
const tarballPluginFile = (0, fileSystem_1.findFileRec)(path, ".tar.gz");
|
|
45
|
+
if (!tarballPluginFile) {
|
|
46
|
+
throw new Error("Tarball plugin file not found");
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
yield (0, fileSystem_1.extractTarball)(tarballPluginFile, path);
|
|
50
|
+
(0, fileSystem_1.deleteFolderFileSystem)((0, path_1.join)(path, "package"));
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
throw new Error(err);
|
|
54
|
+
}
|
|
55
|
+
return yield (0, fileSystem_1.getPluginMetadata)(path);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.npmUpload = npmUpload;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.urlUpload = exports.npmUpload = exports.githubUpload = exports.fileUpload = void 0;
|
|
4
|
+
var file_1 = require("./file");
|
|
5
|
+
Object.defineProperty(exports, "fileUpload", { enumerable: true, get: function () { return file_1.fileUpload; } });
|
|
6
|
+
var github_1 = require("./github");
|
|
7
|
+
Object.defineProperty(exports, "githubUpload", { enumerable: true, get: function () { return github_1.githubUpload; } });
|
|
8
|
+
var npm_1 = require("./npm");
|
|
9
|
+
Object.defineProperty(exports, "npmUpload", { enumerable: true, get: function () { return npm_1.npmUpload; } });
|
|
10
|
+
var url_1 = require("./url");
|
|
11
|
+
Object.defineProperty(exports, "urlUpload", { enumerable: true, get: function () { return url_1.urlUpload; } });
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
exports.urlUpload = void 0;
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
const fileSystem_1 = require("../../../utilities/fileSystem");
|
|
15
|
+
function urlUpload(url, name = "", headers = {}) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
if (!url.includes(".tar.gz")) {
|
|
18
|
+
throw new Error("Plugin must be compressed into a gzipped tarball.");
|
|
19
|
+
}
|
|
20
|
+
const path = yield (0, utils_1.downloadUnzipTarball)(url, name, headers);
|
|
21
|
+
return yield (0, fileSystem_1.getPluginMetadata)(path);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.urlUpload = urlUpload;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
exports.downloadUnzipTarball = void 0;
|
|
13
|
+
const fileSystem_1 = require("../../../utilities/fileSystem");
|
|
14
|
+
function downloadUnzipTarball(url, name, headers = {}) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const path = (0, fileSystem_1.createTempFolder)(name);
|
|
18
|
+
yield (0, fileSystem_1.downloadTarballDirect)(url, path, headers);
|
|
19
|
+
return path;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
throw new Error(e.message);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.downloadUnzipTarball = downloadUnzipTarball;
|
|
@@ -8,10 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const { getScreenParams, generateScreenID } = require("../../db/utils");
|
|
11
|
+
const { getScreenParams, generateScreenID, getPluginParams, DocumentType, } = require("../../db/utils");
|
|
12
12
|
const { AccessController } = require("@budibase/backend-core/roles");
|
|
13
13
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
14
14
|
const { events } = require("@budibase/backend-core");
|
|
15
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy");
|
|
16
|
+
const { updateAppPackage } = require("./application");
|
|
15
17
|
exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
18
|
const db = getAppDB();
|
|
17
19
|
const screens = (yield db.allDocs(getScreenParams(null, {
|
|
@@ -28,11 +30,45 @@ exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
28
30
|
eventFn = events.screen.created;
|
|
29
31
|
}
|
|
30
32
|
const response = yield db.put(screen);
|
|
33
|
+
// Find any custom components being used
|
|
34
|
+
let pluginNames = [];
|
|
35
|
+
let pluginAdded = false;
|
|
36
|
+
findPlugins(screen.props, pluginNames);
|
|
37
|
+
if (pluginNames.length) {
|
|
38
|
+
const globalDB = getGlobalDB();
|
|
39
|
+
const pluginsResponse = yield globalDB.allDocs(getPluginParams(null, {
|
|
40
|
+
include_docs: true,
|
|
41
|
+
}));
|
|
42
|
+
const requiredPlugins = pluginsResponse.rows
|
|
43
|
+
.map(row => row.doc)
|
|
44
|
+
.filter(plugin => {
|
|
45
|
+
return (plugin.schema.type === "component" &&
|
|
46
|
+
pluginNames.includes(`plugin/${plugin.name}`));
|
|
47
|
+
});
|
|
48
|
+
// Update the app metadata
|
|
49
|
+
const application = yield db.get(DocumentType.APP_METADATA);
|
|
50
|
+
let usedPlugins = application.usedPlugins || [];
|
|
51
|
+
requiredPlugins.forEach(plugin => {
|
|
52
|
+
if (!usedPlugins.find(x => x._id === plugin._id)) {
|
|
53
|
+
pluginAdded = true;
|
|
54
|
+
usedPlugins.push({
|
|
55
|
+
_id: plugin._id,
|
|
56
|
+
name: plugin.name,
|
|
57
|
+
version: plugin.version,
|
|
58
|
+
jsUrl: plugin.jsUrl,
|
|
59
|
+
hash: plugin.hash,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (pluginAdded) {
|
|
64
|
+
yield updateAppPackage({ usedPlugins }, ctx.appId);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
31
67
|
if (eventFn) {
|
|
32
68
|
yield eventFn(screen);
|
|
33
69
|
}
|
|
34
70
|
ctx.message = `Screen ${screen.name} saved.`;
|
|
35
|
-
ctx.body = Object.assign(Object.assign({}, screen), { _id: response.id, _rev: response.rev });
|
|
71
|
+
ctx.body = Object.assign(Object.assign({}, screen), { _id: response.id, _rev: response.rev, pluginAdded });
|
|
36
72
|
});
|
|
37
73
|
exports.destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
74
|
const db = getAppDB();
|
|
@@ -45,3 +81,17 @@ exports.destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
45
81
|
};
|
|
46
82
|
ctx.status = 200;
|
|
47
83
|
});
|
|
84
|
+
const findPlugins = (component, foundPlugins) => {
|
|
85
|
+
if (!component) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (component._component.startsWith("plugin")) {
|
|
89
|
+
if (!foundPlugins.includes(component._component)) {
|
|
90
|
+
foundPlugins.push(component._component);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!component._children || !component._children.length) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
component._children.forEach(child => findPlugins(child, foundPlugins));
|
|
97
|
+
};
|
|
@@ -113,6 +113,7 @@ const serveApp = function (ctx) {
|
|
|
113
113
|
production: env.isProd(),
|
|
114
114
|
appId,
|
|
115
115
|
clientLibPath: clientLibraryPath(appId, appInfo.version, ctx),
|
|
116
|
+
usedPlugins: appInfo.usedPlugins,
|
|
116
117
|
});
|
|
117
118
|
const appHbs = loadHandlebarsFile(`${__dirname}/templates/app.hbs`);
|
|
118
119
|
ctx.body = yield processString(appHbs, {
|