@silexlabs/silex 3.0.1-alpha.0 → 3.0.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/.env.default +20 -0
- package/.silex.js +67 -8
- package/LICENSE +661 -203
- package/README.md +37 -35
- package/dist/client/client/api.d.ts +90 -0
- package/dist/client/client/assetUrl.d.ts +54 -0
- package/dist/client/client/config.d.ts +102 -0
- package/dist/client/client/events.d.ts +23 -0
- package/dist/client/client/expose.d.ts +8 -0
- package/dist/client/client/grapesjs/LoginDialog.d.ts +15 -0
- package/dist/client/client/grapesjs/PublicationManager.d.ts +73 -0
- package/dist/client/client/grapesjs/PublicationUi.d.ts +59 -0
- package/dist/client/client/grapesjs/blocks.d.ts +1 -0
- package/dist/client/client/grapesjs/breadcrumbs.d.ts +1 -0
- package/dist/client/client/grapesjs/css-props.d.ts +6 -0
- package/dist/client/client/grapesjs/footer.d.ts +2 -0
- package/dist/client/client/grapesjs/img.d.ts +6 -0
- package/dist/client/client/grapesjs/index.d.ts +9 -0
- package/dist/client/client/grapesjs/internal-links.d.ts +1 -0
- package/dist/client/client/grapesjs/keymaps.d.ts +123 -0
- package/dist/client/client/grapesjs/new-page-dialog.d.ts +2 -0
- package/dist/client/client/grapesjs/openImport.d.ts +9 -0
- package/dist/client/client/grapesjs/page-panel.d.ts +9 -0
- package/dist/client/client/grapesjs/project-bar.d.ts +21 -0
- package/dist/client/client/grapesjs/resize-panel.d.ts +1 -0
- package/dist/client/client/grapesjs/rich-text.d.ts +4 -0
- package/dist/client/client/grapesjs/semantic.d.ts +1 -0
- package/dist/client/client/grapesjs/settings-sections.d.ts +16 -0
- package/dist/client/client/grapesjs/settings.d.ts +4 -0
- package/dist/client/client/grapesjs/storage.d.ts +2 -0
- package/dist/client/client/grapesjs/symbolDialogs.d.ts +3 -0
- package/dist/client/client/grapesjs/view-buttons.d.ts +1 -0
- package/dist/client/client/index.d.ts +10 -0
- package/dist/client/client/publication-transformers.d.ts +42 -0
- package/dist/client/client/publish-custom-code-block.d.ts +4 -0
- package/dist/client/client/publish-fonts.d.ts +4 -0
- package/dist/client/client/utils.d.ts +22 -0
- package/dist/client/constants.d.ts +32 -0
- package/dist/client/css/admin.css +1114 -328
- package/dist/client/css/admin.css.map +1 -0
- package/dist/client/grapesjs-filter-styles/dist/index.d.ts +4 -0
- package/dist/client/grapesjs-fonts/dist/index.d.ts +4 -0
- package/dist/client/grapesjs-fonts/src/commands.d.ts +3 -0
- package/dist/client/grapesjs-fonts/src/fonts.d.ts +4 -0
- package/dist/client/grapesjs-storage-rate-limit/dist/index.d.ts +4 -0
- package/dist/client/grapesjs-ui-suggest-classes/dist/index.d.ts +4 -0
- package/dist/client/index.html +3 -2
- package/dist/client/js/main.js +356 -131
- package/dist/client/js/main.js.LICENSE.txt +15 -1
- package/dist/client/page.d.ts +2 -0
- package/dist/client/silex-lib/src/ts/client/api.d.ts +90 -0
- package/dist/client/silex-lib/src/ts/client/assetUrl.d.ts +54 -0
- package/dist/client/silex-lib/src/ts/client/config.d.ts +102 -0
- package/dist/client/silex-lib/src/ts/client/events.d.ts +23 -0
- package/dist/client/silex-lib/src/ts/client/expose.d.ts +8 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/LoginDialog.d.ts +15 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/PublicationManager.d.ts +73 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/PublicationUi.d.ts +59 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/blocks.d.ts +1 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/breadcrumbs.d.ts +1 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/css-props.d.ts +6 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/footer.d.ts +2 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/img.d.ts +6 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/index.d.ts +9 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/internal-links.d.ts +1 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/keymaps.d.ts +123 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/new-page-dialog.d.ts +2 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/openImport.d.ts +9 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/page-panel.d.ts +9 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/project-bar.d.ts +21 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/resize-panel.d.ts +1 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/rich-text.d.ts +4 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/semantic.d.ts +1 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/settings-sections.d.ts +16 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/settings.d.ts +4 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/storage.d.ts +2 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/symbolDialogs.d.ts +3 -0
- package/dist/client/silex-lib/src/ts/client/grapesjs/view-buttons.d.ts +1 -0
- package/dist/client/silex-lib/src/ts/client/index.d.ts +10 -0
- package/dist/client/silex-lib/src/ts/client/publication-transformers.d.ts +42 -0
- package/dist/client/silex-lib/src/ts/client/publish-custom-code-block.d.ts +4 -0
- package/dist/client/silex-lib/src/ts/client/publish-fonts.d.ts +4 -0
- package/dist/client/silex-lib/src/ts/client/utils.d.ts +22 -0
- package/dist/client/silex-lib/src/ts/constants.d.ts +32 -0
- package/dist/client/silex-lib/src/ts/page.d.ts +2 -0
- package/dist/client/silex-lib/src/ts/types.d.ts +339 -0
- package/dist/client/types.d.ts +339 -0
- package/dist/plugins/client/client/events.d.ts +23 -0
- package/dist/plugins/client/client/events.js +43 -0
- package/dist/plugins/client/client/events.js.map +1 -0
- package/dist/plugins/client/plugins/client/template.d.ts +2 -0
- package/dist/plugins/client/plugins/client/template.js +234 -0
- package/dist/plugins/client/plugins/client/template.js.map +1 -0
- package/dist/plugins/client/plugins/client/website-info.d.ts +1 -0
- package/dist/plugins/client/plugins/client/website-info.js +72 -0
- package/dist/plugins/client/plugins/client/website-info.js.map +1 -0
- package/dist/plugins/client/types.d.ts +339 -0
- package/dist/plugins/client/types.js +80 -0
- package/dist/plugins/client/types.js.map +1 -0
- package/dist/plugins/server/constants.d.ts +32 -0
- package/dist/plugins/server/constants.js +76 -0
- package/dist/plugins/server/constants.js.map +1 -0
- package/dist/plugins/server/plugins/server/Cache.d.ts +2 -0
- package/dist/plugins/server/plugins/server/Cache.js +36 -0
- package/dist/plugins/server/plugins/server/Cache.js.map +1 -0
- package/dist/plugins/server/plugins/server/DownloadConnector.d.ts +29 -0
- package/dist/plugins/server/plugins/server/DownloadConnector.js +127 -0
- package/dist/plugins/server/plugins/server/DownloadConnector.js.map +1 -0
- package/dist/plugins/server/plugins/server/FtpConnector.d.ts +86 -0
- package/dist/plugins/server/plugins/server/FtpConnector.js +536 -0
- package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.d.ts +135 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.js +649 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -0
- package/dist/plugins/server/plugins/server/GitlabHostingConnector.d.ts +16 -0
- package/dist/plugins/server/plugins/server/GitlabHostingConnector.js +209 -0
- package/dist/plugins/server/plugins/server/GitlabHostingConnector.js.map +1 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.d.ts +0 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.js +14 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.js.map +1 -0
- package/dist/plugins/server/plugins/server/SslPlugin.d.ts +1 -0
- package/dist/plugins/server/plugins/server/SslPlugin.js +86 -0
- package/dist/plugins/server/plugins/server/SslPlugin.js.map +1 -0
- package/dist/plugins/server/plugins/server/StaticPlugin.d.ts +8 -0
- package/dist/plugins/server/plugins/server/StaticPlugin.js +45 -0
- package/dist/plugins/server/plugins/server/StaticPlugin.js.map +1 -0
- package/dist/plugins/server/server/config.d.ts +59 -0
- package/dist/plugins/server/server/config.js +181 -0
- package/dist/plugins/server/server/config.js.map +1 -0
- package/dist/plugins/server/server/connectors/FsHosting.d.ts +14 -0
- package/dist/plugins/server/server/connectors/FsHosting.js +66 -0
- package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -0
- package/dist/plugins/server/server/connectors/FsStorage.d.ts +44 -0
- package/dist/plugins/server/server/connectors/FsStorage.js +261 -0
- package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -0
- package/dist/plugins/server/server/connectors/connectors.d.ts +86 -0
- package/dist/plugins/server/server/connectors/connectors.js +126 -0
- package/dist/plugins/server/server/connectors/connectors.js.map +1 -0
- package/dist/plugins/server/server/events.d.ts +26 -0
- package/dist/plugins/server/server/events.js +31 -0
- package/dist/plugins/server/server/events.js.map +1 -0
- package/dist/plugins/server/server/jobs.d.ts +12 -0
- package/dist/plugins/server/server/jobs.js +79 -0
- package/dist/plugins/server/server/jobs.js.map +1 -0
- package/dist/plugins/server/server/utils/validation.d.ts +7 -0
- package/dist/plugins/server/server/utils/validation.js +37 -0
- package/dist/plugins/server/server/utils/validation.js.map +1 -0
- package/dist/plugins/server/types.d.ts +339 -0
- package/dist/plugins/server/types.js +84 -0
- package/dist/plugins/server/types.js.map +1 -0
- package/dist/server/constants.js +55 -0
- package/dist/server/plugins/server/Cache.js +19 -0
- package/dist/server/server/api/api.js +20 -0
- package/dist/server/server/api/connectorApi.js +334 -0
- package/dist/server/server/api/publicationApi.js +106 -0
- package/dist/server/server/api/websiteApi.js +315 -0
- package/dist/server/server/cli.js +71 -0
- package/dist/server/server/config.js +120 -0
- package/dist/server/server/connectors/FsHosting.js +47 -0
- package/dist/server/server/connectors/FsStorage.js +228 -0
- package/dist/server/server/connectors/connectors.js +88 -0
- package/dist/server/server/events.js +14 -0
- package/dist/server/server/expose.js +27 -0
- package/dist/server/server/express.js +46 -0
- package/dist/server/server/index.js +92 -0
- package/dist/server/server/jobs.js +50 -0
- package/dist/server/server/utils/validation.js +14 -0
- package/dist/server/types.js +40 -0
- package/package.json +99 -49
- package/public/assets/download.png +0 -0
- package/public/assets/favicon.ico +0 -0
- package/public/assets/favicon.png +0 -0
- package/public/assets/ftp.png +0 -0
- package/public/assets/gitlab.png +0 -0
- package/public/assets/gitlab2.png +0 -0
- package/public/assets/laptop.png +0 -0
- package/public/assets/logo-silex-small.png +0 -0
- package/public/silex.js +22 -23
- package/src/css/_variables.scss +24 -20
- package/src/css/dialog.scss +35 -2
- package/src/css/fonts.scss +31 -0
- package/src/css/footer.scss +12 -0
- package/src/css/grapesjs-light.scss +180 -0
- package/src/css/grapesjs-plugins.scss +227 -0
- package/src/css/grapesjs.scss +159 -1
- package/src/css/index.scss +12 -1
- package/src/css/light.scss +7 -0
- package/src/css/loader.scss +2 -0
- package/src/css/project-bar.scss +32 -16
- package/src/css/silex.scss +79 -5
- package/src/css/website-info.scss +14 -0
- package/src/html/index.pug +3 -3
- package/src/html/templates/includes.pug +0 -1
- package/src/ts/client/api.ts +156 -0
- package/src/ts/client/assetUrl.test.ts +164 -0
- package/src/ts/client/assetUrl.ts +254 -0
- package/src/ts/client/config.ts +175 -13
- package/src/ts/client/events.ts +43 -0
- package/src/ts/client/expose.ts +27 -1
- package/src/ts/client/grapesjs/LoginDialog.ts +204 -0
- package/src/ts/client/grapesjs/PublicationManager.ts +433 -0
- package/src/ts/client/grapesjs/PublicationUi.ts +366 -0
- package/src/ts/client/grapesjs/blocks.ts +17 -0
- package/src/ts/client/grapesjs/breadcrumbs.ts +79 -0
- package/src/ts/client/grapesjs/css-props.ts +910 -0
- package/src/ts/client/grapesjs/eleventy.ts +30 -7
- package/src/ts/client/grapesjs/footer.ts +42 -0
- package/src/ts/client/grapesjs/img.ts +147 -0
- package/src/ts/client/grapesjs/index.ts +311 -122
- package/src/ts/client/grapesjs/internal-links.test.ts +19 -1
- package/src/ts/client/grapesjs/internal-links.ts +31 -7
- package/src/ts/client/grapesjs/keymaps.ts +207 -0
- package/src/ts/client/grapesjs/new-page-dialog.ts +19 -3
- package/src/ts/client/grapesjs/openImport.ts +22 -0
- package/src/ts/client/grapesjs/page-panel.ts +109 -7
- package/src/ts/client/grapesjs/project-bar.ts +133 -72
- package/src/ts/client/grapesjs/resize-panel.ts +20 -0
- package/src/ts/client/grapesjs/rich-text.ts +38 -13
- package/src/ts/client/grapesjs/semantic.ts +20 -3
- package/src/ts/client/grapesjs/settings-sections.ts +117 -0
- package/src/ts/client/grapesjs/settings.ts +191 -96
- package/src/ts/client/grapesjs/storage.ts +187 -0
- package/src/ts/client/grapesjs/symbolDialogs.ts +21 -5
- package/src/ts/client/grapesjs/view-buttons.ts +42 -0
- package/src/ts/client/index.ts +80 -21
- package/src/ts/client/publication-transformers.test.ts +207 -0
- package/src/ts/client/publication-transformers.ts +280 -0
- package/src/ts/client/publish-custom-code-block.ts +31 -0
- package/src/ts/client/publish-fonts.ts +36 -0
- package/src/ts/client/utils.ts +70 -1
- package/src/ts/constants.ts +78 -0
- package/src/ts/externs.ts +17 -0
- package/src/ts/page.ts +20 -3
- package/src/ts/plugins/client/template.ts +246 -0
- package/src/ts/plugins/client/website-info.ts +84 -0
- package/src/ts/plugins/server/Cache.ts +32 -0
- package/src/ts/plugins/server/DownloadConnector.ts +146 -0
- package/src/ts/plugins/server/FtpConnector.test.ts +82 -0
- package/src/ts/plugins/server/FtpConnector.ts +621 -0
- package/src/ts/plugins/server/GitlabConnector.ts +749 -0
- package/src/ts/plugins/server/GitlabHostingConnector.ts +215 -0
- package/src/ts/plugins/server/PublicationOptimizer.ts +14 -0
- package/src/ts/plugins/server/SslPlugin.ts +84 -0
- package/src/ts/plugins/server/StaticPlugin.ts +45 -0
- package/src/ts/server/api/api.ts +19 -0
- package/src/ts/server/api/connectorApi.ts +464 -0
- package/src/ts/server/api/publicationApi.ts +159 -0
- package/src/ts/server/api/websiteApi.ts +462 -0
- package/src/ts/server/cli.ts +48 -14
- package/src/ts/server/config.ts +158 -60
- package/src/ts/server/connectors/FsHosting.ts +66 -0
- package/src/ts/server/connectors/FsStorage.test.ts +51 -0
- package/src/ts/server/connectors/FsStorage.ts +290 -0
- package/src/ts/server/connectors/connectors.ts +203 -0
- package/src/ts/server/events.ts +37 -0
- package/src/ts/server/expose.ts +19 -0
- package/src/ts/server/express.ts +57 -5
- package/src/ts/server/index.ts +80 -19
- package/src/ts/server/jobs.test.ts +75 -0
- package/src/ts/server/jobs.ts +89 -0
- package/src/ts/server/utils/BackwardCompat.ts +546 -528
- package/src/ts/server/utils/validation.ts +34 -0
- package/src/ts/types.ts +295 -85
- package/.dockerignore +0 -5
- package/.editorconfig +0 -14
- package/.eslintrc.json +0 -43
- package/.github/FUNDING.yml +0 -13
- package/.github/workflows/docker-hub-publish.yml +0 -36
- package/.github/workflows/npm-publish.yml +0 -19
- package/.github/workflows/test.yml +0 -26
- package/.nvmrc +0 -1
- package/.silex/default/.silex.data.json +0 -1
- package/CODE_OF_CONDUCT.md +0 -128
- package/CONTRIBUTING.md +0 -131
- package/Dockerfile +0 -15
- package/directus.silex.js +0 -7
- package/dist/constants.js +0 -4
- package/dist/events.js +0 -5
- package/dist/page.js +0 -15
- package/dist/server/cli.js +0 -43
- package/dist/server/config.js +0 -70
- package/dist/server/express.js +0 -18
- package/dist/server/index.js +0 -58
- package/dist/types.js +0 -34
- package/jest.config.js +0 -10
- package/logos/logo_by_ceubri/silex-icon-2018@200px.png +0 -0
- package/logos/logo_by_ceubri/silex-icon-2018@4x.png +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018-white-transp.pdf +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018-white.jpg +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018-white.pdf +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018-white.png +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018-white@0.5x.png +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018-white@0.75x.png +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018-white@4x.jpg +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018-white@4x.png +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018.ai +5 -2521
- package/logos/logo_by_ceubri/silex-logo-2018.jpg +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018.pdf +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018.png +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018@0.5x.png +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018@0.75x.png +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018@4x.jpg +0 -0
- package/logos/logo_by_ceubri/silex-logo-2018@4x.png +0 -0
- package/logos/silexlabs.png +0 -0
- package/src/example-client-config.js +0 -47
- package/src/plugins/AuthPlugin.js +0 -21
- package/src/plugins/Cache.js +0 -11
- package/src/plugins/DefaultBackend.js +0 -149
- package/src/plugins/ExpressPlugin.js +0 -39
- package/src/plugins/HooksPlugin.js +0 -58
- package/src/plugins/PublishPlugin.js +0 -69
- package/src/plugins/SslPlugin.js +0 -66
- package/src/plugins/StaticPlugin.js +0 -48
- package/src/plugins/WebsitePlugin.js +0 -207
- package/src/ts/client/grapesjs/publish.ts +0 -386
- package/src/ts/client/grapesjs/template.ts +0 -166
- package/src/ts/events.ts +0 -2
- package/tsconfig-server-debug.json +0 -19
- package/tsconfig-server-release.json +0 -19
- package/tsconfig.jest.json +0 -9
- package/tsconfig.json +0 -26
- package/webpack.config.js +0 -28
- package/webpack.debug.config.js +0 -8
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
4
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
23
|
+
}
|
|
24
|
+
Object.defineProperty(o, k2, desc);
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
const constants_1 = require("../../constants");
|
|
46
|
+
const connectors_1 = require("../../server/connectors/connectors");
|
|
47
|
+
const types_1 = require("../../types");
|
|
48
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
49
|
+
const crypto_1 = __importStar(require("crypto"));
|
|
50
|
+
const path_1 = require("path");
|
|
51
|
+
const svg = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
52
|
+
<svg
|
|
53
|
+
xmlns:svg="http://www.w3.org/2000/svg"
|
|
54
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
55
|
+
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
|
56
|
+
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
|
57
|
+
width="1000"
|
|
58
|
+
height="963.197"
|
|
59
|
+
viewBox="0 0 1000 963.197"
|
|
60
|
+
version="1.1"
|
|
61
|
+
id="svg85">
|
|
62
|
+
<sodipodi:namedview
|
|
63
|
+
id="namedview87"
|
|
64
|
+
pagecolor="#ffffff"
|
|
65
|
+
bordercolor="#666666"
|
|
66
|
+
borderopacity="1.0"
|
|
67
|
+
inkscape:pageshadow="2"
|
|
68
|
+
inkscape:pageopacity="0.0"
|
|
69
|
+
inkscape:pagecheckerboard="0"
|
|
70
|
+
showgrid="false"
|
|
71
|
+
inkscape:zoom="1"
|
|
72
|
+
inkscape:cx="991.5"
|
|
73
|
+
inkscape:cy="964.5"
|
|
74
|
+
inkscape:window-width="1126"
|
|
75
|
+
inkscape:window-height="895"
|
|
76
|
+
inkscape:window-x="774"
|
|
77
|
+
inkscape:window-y="12"
|
|
78
|
+
inkscape:window-maximized="0"
|
|
79
|
+
inkscape:current-layer="svg85" />
|
|
80
|
+
<defs
|
|
81
|
+
id="defs74">
|
|
82
|
+
<style
|
|
83
|
+
id="style72">.cls-1{fill:#e24329;}.cls-2{fill:#fc6d26;}.cls-3{fill:#fca326;}</style>
|
|
84
|
+
</defs>
|
|
85
|
+
<g
|
|
86
|
+
id="LOGO"
|
|
87
|
+
transform="matrix(5.2068817,0,0,5.2068817,-489.30756,-507.76085)">
|
|
88
|
+
<path
|
|
89
|
+
class="cls-1"
|
|
90
|
+
d="m 282.83,170.73 -0.27,-0.69 -26.14,-68.22 a 6.81,6.81 0 0 0 -2.69,-3.24 7,7 0 0 0 -8,0.43 7,7 0 0 0 -2.32,3.52 l -17.65,54 h -71.47 l -17.65,-54 a 6.86,6.86 0 0 0 -2.32,-3.53 7,7 0 0 0 -8,-0.43 6.87,6.87 0 0 0 -2.69,3.24 L 97.44,170 l -0.26,0.69 a 48.54,48.54 0 0 0 16.1,56.1 l 0.09,0.07 0.24,0.17 39.82,29.82 19.7,14.91 12,9.06 a 8.07,8.07 0 0 0 9.76,0 l 12,-9.06 19.7,-14.91 40.06,-30 0.1,-0.08 a 48.56,48.56 0 0 0 16.08,-56.04 z"
|
|
91
|
+
id="path76" />
|
|
92
|
+
<path
|
|
93
|
+
class="cls-2"
|
|
94
|
+
d="m 282.83,170.73 -0.27,-0.69 a 88.3,88.3 0 0 0 -35.15,15.8 L 190,229.25 c 19.55,14.79 36.57,27.64 36.57,27.64 l 40.06,-30 0.1,-0.08 a 48.56,48.56 0 0 0 16.1,-56.08 z"
|
|
95
|
+
id="path78" />
|
|
96
|
+
<path
|
|
97
|
+
class="cls-3"
|
|
98
|
+
d="m 153.43,256.89 19.7,14.91 12,9.06 a 8.07,8.07 0 0 0 9.76,0 l 12,-9.06 19.7,-14.91 c 0,0 -17.04,-12.89 -36.59,-27.64 -19.55,14.75 -36.57,27.64 -36.57,27.64 z"
|
|
99
|
+
id="path80" />
|
|
100
|
+
<path
|
|
101
|
+
class="cls-2"
|
|
102
|
+
d="M 132.58,185.84 A 88.19,88.19 0 0 0 97.44,170 l -0.26,0.69 a 48.54,48.54 0 0 0 16.1,56.1 l 0.09,0.07 0.24,0.17 39.82,29.82 c 0,0 17,-12.85 36.57,-27.64 z"
|
|
103
|
+
id="path82" />
|
|
104
|
+
</g>
|
|
105
|
+
</svg>`;
|
|
106
|
+
const encodedSvg = encodeURIComponent(svg);
|
|
107
|
+
const ICON = '/assets/gitlab.png';
|
|
108
|
+
class GitlabConnector {
|
|
109
|
+
config;
|
|
110
|
+
connectorId = 'gitlab';
|
|
111
|
+
connectorType = types_1.ConnectorType.STORAGE;
|
|
112
|
+
displayName = 'GitLab';
|
|
113
|
+
icon = ICON;
|
|
114
|
+
disableLogout = false;
|
|
115
|
+
color = '#2B1B63';
|
|
116
|
+
background = 'rgba(252, 109, 38, 0.2)';
|
|
117
|
+
options;
|
|
118
|
+
constructor(config, opts) {
|
|
119
|
+
this.config = config;
|
|
120
|
+
this.options = {
|
|
121
|
+
branch: 'main',
|
|
122
|
+
assetsFolder: 'assets',
|
|
123
|
+
//metaRepo: 'silex-meta',
|
|
124
|
+
//metaRepoFile: 'websites.json',
|
|
125
|
+
repoPrefix: 'silex_',
|
|
126
|
+
scope: 'api', // 'api+read_api+read_user+read_repository+write_repository+email+sudo+profile+openid'
|
|
127
|
+
...opts,
|
|
128
|
+
};
|
|
129
|
+
if (!this.options.clientId)
|
|
130
|
+
throw new Error('Missing Gitlab client ID');
|
|
131
|
+
if (!this.options.clientSecret)
|
|
132
|
+
throw new Error('Missing Gitlab client secret');
|
|
133
|
+
if (!this.options.domain)
|
|
134
|
+
throw new Error('Missing Gitlab domain');
|
|
135
|
+
if (!this.options.timeOut)
|
|
136
|
+
this.options.timeOut = 15000; /* default value */
|
|
137
|
+
}
|
|
138
|
+
// **
|
|
139
|
+
// Convenience methods for the Gitlab API
|
|
140
|
+
getAssetPath(path) {
|
|
141
|
+
return encodeURIComponent((0, path_1.join)(this.options.assetsFolder, path));
|
|
142
|
+
}
|
|
143
|
+
isUsingOfficialInstance() {
|
|
144
|
+
const gitlabDomainRegexp = /(^|\b)(gitlab\.com)($|\b)/;
|
|
145
|
+
return gitlabDomainRegexp.test(this.options.domain);
|
|
146
|
+
}
|
|
147
|
+
async createFile(session, websiteId, path, content, isBase64 = false) {
|
|
148
|
+
// Remove leading slash
|
|
149
|
+
const safePath = path.replace(/^\//, '');
|
|
150
|
+
const encodePath = decodeURIComponent(path);
|
|
151
|
+
return this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${safePath}`, 'POST', {
|
|
152
|
+
id: websiteId,
|
|
153
|
+
branch: this.options.branch,
|
|
154
|
+
content,
|
|
155
|
+
commit_message: `Create file ${encodePath} from Silex`,
|
|
156
|
+
encoding: isBase64 ? 'base64' : undefined,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
async updateFile(session, websiteId, path, content, isBase64 = false) {
|
|
160
|
+
// Remove leading slash
|
|
161
|
+
const safePath = path.replace(/^\//, '');
|
|
162
|
+
const encodePath = decodeURIComponent(path);
|
|
163
|
+
return this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${safePath}`, 'PUT', {
|
|
164
|
+
id: websiteId,
|
|
165
|
+
branch: this.options.branch,
|
|
166
|
+
content: await (0, connectors_1.contentToString)(content),
|
|
167
|
+
commit_message: `Update website asset ${encodePath} from Silex`,
|
|
168
|
+
encoding: isBase64 ? 'base64' : undefined,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async readFile(session, websiteId, fileName) {
|
|
172
|
+
const safePath = fileName.replace(/^\//, '');
|
|
173
|
+
// Call the API
|
|
174
|
+
const url = `${this.options.domain}/api/v4/projects/${websiteId}/repository/files/${safePath}?ref=${this.options.branch}&access_token=${this.getSessionToken(session).token?.access_token}`;
|
|
175
|
+
const response = await (0, node_fetch_1.default)(url, {
|
|
176
|
+
method: 'GET',
|
|
177
|
+
headers: {
|
|
178
|
+
'Content-Type': 'application/json',
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
const json = await response.json();
|
|
182
|
+
if (!response.ok)
|
|
183
|
+
throw new types_1.ApiError(`Error reading file "${fileName}" from Gitlab: ${json?.message ?? json?.error ?? response.statusText}`, response.status);
|
|
184
|
+
// From base64 string to buffer
|
|
185
|
+
const buf = Buffer.from(json.content, 'base64');
|
|
186
|
+
// Return the image bytes
|
|
187
|
+
return buf;
|
|
188
|
+
}
|
|
189
|
+
/*
|
|
190
|
+
* Get the meta repo path for the current user
|
|
191
|
+
* The meta repo contains a JSON file which contains the list of websites
|
|
192
|
+
*/
|
|
193
|
+
//private getMetaRepoPath(session: GitlabSession): string {
|
|
194
|
+
// if(!this.getSessionToken(session).username) throw new ApiError('Missing Gitlab user ID. User not logged in?', 401)
|
|
195
|
+
// return encodeURIComponent(`${this.getSessionToken(session).username}/${this.options.metaRepo}`)
|
|
196
|
+
//}
|
|
197
|
+
///**
|
|
198
|
+
// * Initialize the storage with a meta repo
|
|
199
|
+
// */
|
|
200
|
+
//private async initStorage(session: GitlabSession): Promise<void> {
|
|
201
|
+
// // Create the meta repo
|
|
202
|
+
// try {
|
|
203
|
+
// const project = await this.callApi(session, 'api/v4/projects/', 'POST', {
|
|
204
|
+
// name: this.options.metaRepo,
|
|
205
|
+
// }) as any
|
|
206
|
+
// return this.createFile(session, this.getMetaRepoPath(session), this.options.metaRepoFile, JSON.stringify({
|
|
207
|
+
// websites: {}
|
|
208
|
+
// } as MetaRepoFileContent))
|
|
209
|
+
// } catch (e) {
|
|
210
|
+
// console.error('Could not init storage', e.statusCode, e.httpStatusCode, e)
|
|
211
|
+
// throw e
|
|
212
|
+
// }
|
|
213
|
+
//}
|
|
214
|
+
/**
|
|
215
|
+
* Call the Gitlab API with the user's token and handle errors
|
|
216
|
+
*/
|
|
217
|
+
async callApi(session, path, method = 'GET', body = null, params = {}) {
|
|
218
|
+
const token = this.getSessionToken(session).token;
|
|
219
|
+
const tokenParam = token ? `access_token=${token.access_token}&` : '';
|
|
220
|
+
const paramsStr = Object.entries(params).map(([k, v]) => `${k}=${encodeURIComponent(v.toString())}`).join('&');
|
|
221
|
+
const url = `${this.options.domain}/${path}?${tokenParam}${paramsStr}`;
|
|
222
|
+
const headers = {
|
|
223
|
+
'Content-Type': 'application/json',
|
|
224
|
+
};
|
|
225
|
+
if (method === 'GET' && body) {
|
|
226
|
+
console.error('Gitlab API error (4) - GET request with body', { url, method, body, params });
|
|
227
|
+
}
|
|
228
|
+
// With or without body
|
|
229
|
+
let response;
|
|
230
|
+
try {
|
|
231
|
+
response = await (0, node_fetch_1.default)(url, body && method !== 'GET' ? {
|
|
232
|
+
method,
|
|
233
|
+
headers,
|
|
234
|
+
body: body ? JSON.stringify(body) : undefined
|
|
235
|
+
} : {
|
|
236
|
+
method,
|
|
237
|
+
headers,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
console.error('Gitlab API error (0)', e);
|
|
242
|
+
throw new types_1.ApiError(`Gitlab API error (0): ${e.message} ${e.code} ${e.name} ${e.type}`, 500);
|
|
243
|
+
}
|
|
244
|
+
let json;
|
|
245
|
+
// Handle the case when the server returns a non-JSON response (e.g. 400 Bad Request)
|
|
246
|
+
const text = await response.text();
|
|
247
|
+
if (!response.ok) {
|
|
248
|
+
if (text.includes('A file with this name doesn\'t exist')) {
|
|
249
|
+
throw new types_1.ApiError('Gitlab API error (5): Not Found', 404);
|
|
250
|
+
}
|
|
251
|
+
else if (response.status === 401 && this.getSessionToken(session).token?.refresh_token) {
|
|
252
|
+
// Refresh the token
|
|
253
|
+
const token = this.getSessionToken(session).token;
|
|
254
|
+
const body = {
|
|
255
|
+
grant_type: 'refresh_token',
|
|
256
|
+
refresh_token: token?.refresh_token,
|
|
257
|
+
client_id: this.options.clientId,
|
|
258
|
+
client_secret: this.options.clientSecret,
|
|
259
|
+
};
|
|
260
|
+
const response = await (0, node_fetch_1.default)(this.options.domain + '/oauth/token', {
|
|
261
|
+
method: 'POST',
|
|
262
|
+
headers: {
|
|
263
|
+
'Content-Type': 'application/json',
|
|
264
|
+
},
|
|
265
|
+
body: JSON.stringify(body)
|
|
266
|
+
});
|
|
267
|
+
const refreshJson = await response.json();
|
|
268
|
+
if (response.ok) {
|
|
269
|
+
this.setSessionToken(session, {
|
|
270
|
+
token: {
|
|
271
|
+
...token,
|
|
272
|
+
...refreshJson,
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
return await this.callApi(session, path, method, body, params);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
const message = typeof refreshJson?.message === 'object' ? Object.entries(refreshJson.message).map(entry => entry.join(' ')).join(' ') : refreshJson?.message ?? refreshJson?.error ?? response.statusText;
|
|
279
|
+
console.error('Gitlab API error (2) - could not refresh token', response.status, response.statusText, { message }, 'refresh_token:', token?.refresh_token);
|
|
280
|
+
// Workaround for when the token is invalid
|
|
281
|
+
// It happens often which is not normal (refresh token should last 6 months)
|
|
282
|
+
this.logout(session);
|
|
283
|
+
// Notify the user
|
|
284
|
+
throw new types_1.ApiError(`Gitlab API error (2): ${message}`, response.status);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
const message = typeof json?.message === 'object' ? Object.entries(json.message).map(entry => entry.join(' ')).join(' ') : json?.message ?? json?.error ?? response.statusText;
|
|
289
|
+
console.error('Gitlab API error (1)', response.status, response.statusText, { url, method, body, params, text, message });
|
|
290
|
+
throw new types_1.ApiError(`Gitlab API error (1): ${message}`, response.status);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
json = JSON.parse(text);
|
|
295
|
+
}
|
|
296
|
+
catch (e) {
|
|
297
|
+
if (!response.ok) {
|
|
298
|
+
// A real error
|
|
299
|
+
throw e;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
// Useless error linked to the fact that the response is not JSON
|
|
303
|
+
console.error('Gitlab API error (3) - could not parse response', response.status, response.statusText, { url, method, body, params, text });
|
|
304
|
+
return text;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return json;
|
|
308
|
+
}
|
|
309
|
+
generateCodeVerifier() {
|
|
310
|
+
return crypto_1.default.randomBytes(64).toString('base64')
|
|
311
|
+
.replace(/\+/g, '-')
|
|
312
|
+
.replace(/\//g, '_')
|
|
313
|
+
.replace(/=/g, '')
|
|
314
|
+
.substr(0, 128);
|
|
315
|
+
}
|
|
316
|
+
async generateCodeChallenge(verifier) {
|
|
317
|
+
const hashed = (0, crypto_1.createHash)('sha256').update(verifier).digest();
|
|
318
|
+
let base64Url = hashed.toString('base64');
|
|
319
|
+
// Replace '+' with '-', '/' with '_', and remove '='
|
|
320
|
+
base64Url = base64Url.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
321
|
+
return base64Url;
|
|
322
|
+
}
|
|
323
|
+
getRedirect() {
|
|
324
|
+
const params = `connectorId=${this.connectorId}&type=${this.connectorType}`;
|
|
325
|
+
return `${this.config.url}${constants_1.API_PATH}${constants_1.API_CONNECTOR_PATH}${constants_1.API_CONNECTOR_LOGIN_CALLBACK}?${params}`;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get the OAuth URL to redirect the user to
|
|
329
|
+
* The URL should look like
|
|
330
|
+
* https://gitlab.example.com/oauth/authorize?client_id=APP_ID&redirect_uri=REDIRECT_URI&response_type=code&state=STATE&scope=REQUESTED_SCOPES&code_challenge=CODE_CHALLENGE&code_challenge_method=S256
|
|
331
|
+
* OAuth2 Step #1 from https://docs.gitlab.com/ee/api/oauth2.html#authorization-code-with-proof-key-for-code-exchange-pkce
|
|
332
|
+
*/
|
|
333
|
+
async getOAuthUrl(session) {
|
|
334
|
+
const redirect_uri = encodeURIComponent(this.getRedirect());
|
|
335
|
+
const state = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
336
|
+
const codeVerifier = this.generateCodeVerifier();
|
|
337
|
+
// Create the code challenge
|
|
338
|
+
const codeChallenge = await this.generateCodeChallenge(codeVerifier);
|
|
339
|
+
// Store the code verifier and code challenge in the session
|
|
340
|
+
this.setSessionToken(session, {
|
|
341
|
+
...this.getSessionToken(session),
|
|
342
|
+
state,
|
|
343
|
+
codeVerifier,
|
|
344
|
+
codeChallenge,
|
|
345
|
+
});
|
|
346
|
+
return `${this.options.domain}/oauth/authorize?client_id=${this.options.clientId}&redirect_uri=${redirect_uri}&response_type=code&state=${this.getSessionToken(session).state}&scope=${this.options.scope}&code_challenge=${codeChallenge}&code_challenge_method=S256`;
|
|
347
|
+
}
|
|
348
|
+
getSessionToken(session) {
|
|
349
|
+
return (session ?? {})[this.connectorId] ?? {};
|
|
350
|
+
}
|
|
351
|
+
setSessionToken(session, token) {
|
|
352
|
+
session[this.connectorId] = token;
|
|
353
|
+
}
|
|
354
|
+
resetSessionToken(session) {
|
|
355
|
+
delete session[this.connectorId];
|
|
356
|
+
}
|
|
357
|
+
getOptions(formData) {
|
|
358
|
+
return {}; // FIXME: store branch
|
|
359
|
+
}
|
|
360
|
+
async getLoginForm(session, redirectTo) {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
async getSettingsForm(session, redirectTo) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
async isLoggedIn(session) {
|
|
367
|
+
return !!this.getSessionToken(session).token;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Get the token from return code
|
|
371
|
+
* Set the token in the session
|
|
372
|
+
* OAuth2 Step #2 from https://docs.gitlab.com/ee/api/oauth2.html#authorization-code-with-proof-key-for-code-exchange-pkce
|
|
373
|
+
*/
|
|
374
|
+
async setToken(session, loginResult) {
|
|
375
|
+
const sessionToken = this.getSessionToken(session);
|
|
376
|
+
if (!loginResult.state || loginResult.state !== sessionToken?.state) {
|
|
377
|
+
this.logout(session);
|
|
378
|
+
throw new types_1.ApiError('Invalid state', 401);
|
|
379
|
+
}
|
|
380
|
+
if (!sessionToken?.codeVerifier) {
|
|
381
|
+
this.logout(session);
|
|
382
|
+
throw new types_1.ApiError('Missing code verifier', 401);
|
|
383
|
+
}
|
|
384
|
+
if (!sessionToken?.codeChallenge) {
|
|
385
|
+
this.logout(session);
|
|
386
|
+
throw new types_1.ApiError('Missing code challenge', 401);
|
|
387
|
+
}
|
|
388
|
+
const response = await (0, node_fetch_1.default)(this.options.domain + '/oauth/token', {
|
|
389
|
+
method: 'POST',
|
|
390
|
+
headers: {
|
|
391
|
+
'Content-Type': 'application/json',
|
|
392
|
+
},
|
|
393
|
+
body: JSON.stringify({
|
|
394
|
+
client_id: this.options.clientId,
|
|
395
|
+
client_secret: this.options.clientSecret,
|
|
396
|
+
code: loginResult.code,
|
|
397
|
+
grant_type: 'authorization_code',
|
|
398
|
+
redirect_uri: this.getRedirect(),
|
|
399
|
+
code_verifier: sessionToken.codeVerifier,
|
|
400
|
+
}),
|
|
401
|
+
});
|
|
402
|
+
const token = await response.json();
|
|
403
|
+
// Store the token in the session
|
|
404
|
+
this.setSessionToken(session, {
|
|
405
|
+
token,
|
|
406
|
+
...this.getSessionToken(session),
|
|
407
|
+
});
|
|
408
|
+
// We need to get the user ID for listWebsites
|
|
409
|
+
const user = await this.callApi(session, 'api/v4/user');
|
|
410
|
+
// Store the user details in the session
|
|
411
|
+
this.setSessionToken(session, {
|
|
412
|
+
...this.getSessionToken(session),
|
|
413
|
+
userId: user.id,
|
|
414
|
+
username: user.username,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
async logout(session) {
|
|
418
|
+
this.resetSessionToken(session);
|
|
419
|
+
}
|
|
420
|
+
async getUser(session) {
|
|
421
|
+
const user = await this.callApi(session, 'api/v4/user');
|
|
422
|
+
return {
|
|
423
|
+
name: user.name,
|
|
424
|
+
email: user.email,
|
|
425
|
+
picture: user.avatar_url,
|
|
426
|
+
storage: await (0, connectors_1.toConnectorData)(session, this),
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
async listWebsites(session) {
|
|
430
|
+
//try {
|
|
431
|
+
// const result = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
432
|
+
// ref: this.options.branch,
|
|
433
|
+
// })
|
|
434
|
+
// const { content } = result
|
|
435
|
+
// const contentDecoded = Buffer.from(content, 'base64').toString('utf8')
|
|
436
|
+
// const websites = (JSON.parse(contentDecoded) as MetaRepoFileContent).websites
|
|
437
|
+
// return Object.entries(websites).map(([websiteId, {meta, createdAt, updatedAt}]) => ({
|
|
438
|
+
// websiteId,
|
|
439
|
+
// createdAt: new Date(createdAt),
|
|
440
|
+
// updatedAt: new Date(updatedAt),
|
|
441
|
+
// ...meta,
|
|
442
|
+
// }))
|
|
443
|
+
//} catch (e) {
|
|
444
|
+
// console.error('Could not list websites', e.statusCode, e.httpStatusCode, e.code)
|
|
445
|
+
// if (e.statusCode === 404 || e.httpStatusCode === 404) {
|
|
446
|
+
// await this.initStorage(session)
|
|
447
|
+
// return []
|
|
448
|
+
// } else {
|
|
449
|
+
// throw e
|
|
450
|
+
// }
|
|
451
|
+
//}
|
|
452
|
+
const userId = this.getSessionToken(session).userId;
|
|
453
|
+
if (!userId) {
|
|
454
|
+
this.logout(session);
|
|
455
|
+
throw new types_1.ApiError('Missing Gitlab user ID. User not logged in?', 401);
|
|
456
|
+
}
|
|
457
|
+
const projects = await this.callApi(session, `api/v4/users/${userId}/projects`);
|
|
458
|
+
return projects
|
|
459
|
+
.filter(p => p.name.startsWith(this.options.repoPrefix))
|
|
460
|
+
.map(p => ({
|
|
461
|
+
websiteId: p.id,
|
|
462
|
+
name: p.name.replace(this.options.repoPrefix, ''),
|
|
463
|
+
createdAt: p.created_at,
|
|
464
|
+
updatedAt: p.last_activity_at,
|
|
465
|
+
connectorUserSettings: {},
|
|
466
|
+
}));
|
|
467
|
+
}
|
|
468
|
+
async readWebsite(session, websiteId) {
|
|
469
|
+
const result = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${constants_1.WEBSITE_DATA_FILE}`, 'GET', null, {
|
|
470
|
+
ref: this.options.branch,
|
|
471
|
+
});
|
|
472
|
+
const { content } = result;
|
|
473
|
+
const contentDecoded = Buffer.from(content, 'base64').toString('utf8');
|
|
474
|
+
const websiteData = JSON.parse(contentDecoded);
|
|
475
|
+
return websiteData;
|
|
476
|
+
}
|
|
477
|
+
async createWebsite(session, websiteMeta) {
|
|
478
|
+
const project = await this.callApi(session, 'api/v4/projects/', 'POST', {
|
|
479
|
+
name: this.options.repoPrefix + websiteMeta.name,
|
|
480
|
+
});
|
|
481
|
+
await this.createFile(session, project.id, constants_1.WEBSITE_DATA_FILE, JSON.stringify({}));
|
|
482
|
+
//await this.createFile(session, project.id, WEBSITE_META_DATA_FILE, JSON.stringify(websiteMeta))
|
|
483
|
+
//await this.updateWebsite(session, project.id, {} as WebsiteData)
|
|
484
|
+
//await this.setWebsiteMeta(session, project.id, websiteMeta)
|
|
485
|
+
return project.id;
|
|
486
|
+
}
|
|
487
|
+
async updateWebsite(session, websiteId, websiteData) {
|
|
488
|
+
const project = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${constants_1.WEBSITE_DATA_FILE}`, 'PUT', {
|
|
489
|
+
branch: this.options.branch,
|
|
490
|
+
commit_message: 'Update website data from Silex',
|
|
491
|
+
content: JSON.stringify(websiteData),
|
|
492
|
+
id: websiteId,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
async deleteWebsite(session, websiteId) {
|
|
496
|
+
// Delete repo
|
|
497
|
+
await this.callApi(session, `api/v4/projects/${websiteId}`, 'DELETE');
|
|
498
|
+
//// Load the meta repo data
|
|
499
|
+
//const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
500
|
+
// ref: this.options.branch,
|
|
501
|
+
//})
|
|
502
|
+
//const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
|
|
503
|
+
//const data = metaRepo.websites[websiteId]
|
|
504
|
+
//if(!data) throw new ApiError(`Website ${websiteId} not found`, 404)
|
|
505
|
+
//// Update or create the website meta data
|
|
506
|
+
//delete metaRepo.websites[websiteId]
|
|
507
|
+
//// Save the meta repo data
|
|
508
|
+
//const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
|
|
509
|
+
// branch: this.options.branch,
|
|
510
|
+
// commit_message: `Delete meta data of ${data.meta.name} (${websiteId}) from Silex`,
|
|
511
|
+
// content: JSON.stringify(metaRepo),
|
|
512
|
+
// file_path: this.options.metaRepoFile,
|
|
513
|
+
//})
|
|
514
|
+
}
|
|
515
|
+
async duplicateWebsite(session, websiteId) {
|
|
516
|
+
// Get the repo meta data
|
|
517
|
+
const meta = await this.getWebsiteMeta(session, websiteId);
|
|
518
|
+
// List all the repository files
|
|
519
|
+
const blobs = await this.callApi(session, `api/v4/projects/${websiteId}/repository/tree`, 'GET', null, {
|
|
520
|
+
recursive: true,
|
|
521
|
+
});
|
|
522
|
+
const files = blobs
|
|
523
|
+
.filter(item => item.type === 'blob')
|
|
524
|
+
.map(item => item.path);
|
|
525
|
+
// Create a new repo
|
|
526
|
+
const newId = await this.createWebsite(session, {
|
|
527
|
+
...meta,
|
|
528
|
+
name: meta.name + ' Copy ' + new Date().toISOString().replace(/T.*/, '') + ' ' + Math.random().toString(36).substring(2, 4),
|
|
529
|
+
});
|
|
530
|
+
// Upload all files
|
|
531
|
+
for (const file of files) {
|
|
532
|
+
const path = encodeURIComponent(file);
|
|
533
|
+
const content = await this.readFile(session, websiteId, path);
|
|
534
|
+
// From buffer to string
|
|
535
|
+
const contentStr = content.toString('base64');
|
|
536
|
+
switch (file) {
|
|
537
|
+
case constants_1.WEBSITE_DATA_FILE:
|
|
538
|
+
await this.updateFile(session, newId, path, contentStr, true);
|
|
539
|
+
break;
|
|
540
|
+
default:
|
|
541
|
+
await this.createFile(session, newId, path, contentStr, true);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
async getWebsiteMeta(session, websiteId) {
|
|
546
|
+
//const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
547
|
+
// ref: this.options.branch,
|
|
548
|
+
//})
|
|
549
|
+
//const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
|
|
550
|
+
//if(!metaRepo.websites[websiteId]) throw new ApiError(`Website ${websiteId} not found`, 404)
|
|
551
|
+
//return {
|
|
552
|
+
// websiteId,
|
|
553
|
+
// createdAt: new Date(metaRepo.websites[websiteId].createdAt),
|
|
554
|
+
// updatedAt: new Date(metaRepo.websites[websiteId].updatedAt),
|
|
555
|
+
// ...metaRepo.websites[websiteId].meta,
|
|
556
|
+
//}
|
|
557
|
+
// const response = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`, 'GET', null, {
|
|
558
|
+
// ref: this.options.branch,
|
|
559
|
+
// }) as any
|
|
560
|
+
// Base64 to string to JSON
|
|
561
|
+
// const contentDecoded = Buffer.from(response.content, 'base64').toString('utf8')
|
|
562
|
+
// const websiteMeta = JSON.parse(contentDecoded) as WebsiteMetaFileContent
|
|
563
|
+
const project = await this.callApi(session, `api/v4/projects/${websiteId}`);
|
|
564
|
+
return {
|
|
565
|
+
websiteId,
|
|
566
|
+
name: project.name.replace(this.options.repoPrefix, ''),
|
|
567
|
+
imageUrl: project.avatar_url,
|
|
568
|
+
createdAt: project.created_at,
|
|
569
|
+
updatedAt: project.last_activity_at,
|
|
570
|
+
connectorUserSettings: {},
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
async setWebsiteMeta(session, websiteId, websiteMeta) {
|
|
574
|
+
//// Load the meta repo data
|
|
575
|
+
//const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
576
|
+
// ref: this.options.branch,
|
|
577
|
+
//})
|
|
578
|
+
//const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
|
|
579
|
+
//// Update or create the website meta data
|
|
580
|
+
//metaRepo.websites[websiteId] = {
|
|
581
|
+
// updatedAt: new Date().toISOString(),
|
|
582
|
+
// createdAt: metaRepo.websites[websiteId]?.createdAt ?? new Date().toISOString(),
|
|
583
|
+
// meta: websiteMeta,
|
|
584
|
+
//}
|
|
585
|
+
//// Save the meta repo data
|
|
586
|
+
//const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
|
|
587
|
+
// branch: this.options.branch,
|
|
588
|
+
// commit_message: `Update website meta data of ${websiteMeta.name} (${websiteId}) from Silex`,
|
|
589
|
+
// content: JSON.stringify(metaRepo),
|
|
590
|
+
// file_path: this.options.metaRepoFile,
|
|
591
|
+
//})
|
|
592
|
+
// Rename the repo if needed
|
|
593
|
+
const oldMeta = await this.getWebsiteMeta(session, websiteId);
|
|
594
|
+
if (websiteMeta.name !== oldMeta.name) {
|
|
595
|
+
await this.callApi(session, `api/v4/projects/${websiteId}`, 'PUT', {
|
|
596
|
+
name: this.options.repoPrefix + websiteMeta.name,
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
//// Update the metadata file
|
|
600
|
+
//await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`, 'PUT', {
|
|
601
|
+
// branch: this.options.branch,
|
|
602
|
+
// commit_message: 'Update website meta data from Silex',
|
|
603
|
+
// content: JSON.stringify(websiteMeta),
|
|
604
|
+
// file_path: WEBSITE_META_DATA_FILE,
|
|
605
|
+
// id: websiteId,
|
|
606
|
+
//})
|
|
607
|
+
}
|
|
608
|
+
async writeAssets(session, websiteId, files, status) {
|
|
609
|
+
status && await status({ message: 'in progress...', status: types_1.JobStatus.IN_PROGRESS });
|
|
610
|
+
// For each file
|
|
611
|
+
for (const file of files) {
|
|
612
|
+
// Convert to base64
|
|
613
|
+
const content = (await (0, connectors_1.contentToBuffer)(file.content)).toString('base64');
|
|
614
|
+
const path = this.getAssetPath(file.path);
|
|
615
|
+
try {
|
|
616
|
+
await this.updateFile(session, websiteId, path, content, true);
|
|
617
|
+
}
|
|
618
|
+
catch (e) {
|
|
619
|
+
// If the file does not exist, create it
|
|
620
|
+
if (e.statusCode === 404 || e.httpStatusCode === 404 || e.message.endsWith('A file with this name doesn\'t exist')) {
|
|
621
|
+
await this.createFile(session, websiteId, path, content, true);
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
status && await status({ message: 'Error', status: types_1.JobStatus.ERROR });
|
|
625
|
+
throw e;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
status && await status({ message: 'Successfull', status: types_1.JobStatus.SUCCESS });
|
|
630
|
+
}
|
|
631
|
+
async readAsset(session, websiteId, fileName) {
|
|
632
|
+
// Remove leading slash
|
|
633
|
+
const finalPath = this.getAssetPath(fileName);
|
|
634
|
+
return this.readFile(session, websiteId, finalPath);
|
|
635
|
+
}
|
|
636
|
+
async deleteAssets(session, websiteId, fileNames) {
|
|
637
|
+
return this.callApi(session, `api/v4/projects/${websiteId}/repository/commits`, 'POST', {
|
|
638
|
+
id: websiteId,
|
|
639
|
+
branch: this.options.branch,
|
|
640
|
+
commit_message: `Delete assets from Silex: ${fileNames.join(', ')}`,
|
|
641
|
+
actions: fileNames.map(f => ({
|
|
642
|
+
action: 'delete',
|
|
643
|
+
file_path: this.getAssetPath(f),
|
|
644
|
+
})),
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
exports.default = GitlabConnector;
|
|
649
|
+
//# sourceMappingURL=GitlabConnector.js.map
|