@silexlabs/silex 3.0.1-alpha.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.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 +94 -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 +79 -16
- 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,86 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { ServerConfig } from '../config';
|
|
3
|
+
import { JobStatus, JobData, ConnectorData, ConnectorId, WebsiteId, ConnectorType, ConnectorUser, WebsiteMeta, WebsiteMetaFileContent, WebsiteData, ConnectorOptions } from '../../types';
|
|
4
|
+
import { JobManager } from '../jobs';
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview define types for Silex connectors
|
|
7
|
+
* Bakends can provide storage for website data and assets, and/or hosting to publish the website online
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Connector data stored in the website meta file
|
|
11
|
+
*/
|
|
12
|
+
export type ConnectorFileContent = string | Buffer | Readable;
|
|
13
|
+
/**
|
|
14
|
+
* Files are stored in connector as a File object
|
|
15
|
+
* @see types/ClientSideFile
|
|
16
|
+
* @see contentToString()
|
|
17
|
+
*/
|
|
18
|
+
export interface ConnectorFile {
|
|
19
|
+
path: string;
|
|
20
|
+
content: ConnectorFileContent;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Callback to update the publication status
|
|
24
|
+
*/
|
|
25
|
+
export type StatusCallback = ({ message, status }: {
|
|
26
|
+
message: string;
|
|
27
|
+
status: JobStatus;
|
|
28
|
+
}) => Promise<void>;
|
|
29
|
+
export type ConnectorSession = object;
|
|
30
|
+
/**
|
|
31
|
+
* Connectors are the base interface for Storage and Hosting connectors
|
|
32
|
+
*/
|
|
33
|
+
export interface Connector<Session extends ConnectorSession = ConnectorSession> {
|
|
34
|
+
connectorId: ConnectorId;
|
|
35
|
+
connectorType: ConnectorType;
|
|
36
|
+
displayName: string;
|
|
37
|
+
icon: string;
|
|
38
|
+
disableLogout?: boolean;
|
|
39
|
+
color: string;
|
|
40
|
+
background: string;
|
|
41
|
+
getOAuthUrl(session: Session): Promise<string | null>;
|
|
42
|
+
getLoginForm(session: Session, redirectTo: string): Promise<string | null>;
|
|
43
|
+
getSettingsForm(session: Session, redirectTo: string): Promise<string | null>;
|
|
44
|
+
isLoggedIn(session: Session): Promise<boolean>;
|
|
45
|
+
setToken(session: Session, token: object): Promise<void>;
|
|
46
|
+
logout(session: Session): Promise<void>;
|
|
47
|
+
getUser(session: Session): Promise<ConnectorUser | null>;
|
|
48
|
+
getOptions(formData: object): ConnectorOptions;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Storage are used to store the website data and assets
|
|
52
|
+
* And possibly rename files and directories, and get the URL of a file
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
export interface StorageConnector<Session extends ConnectorSession = ConnectorSession> extends Connector<Session> {
|
|
56
|
+
listWebsites(session: Session): Promise<WebsiteMeta[]>;
|
|
57
|
+
readWebsite(session: Session, websiteId: WebsiteId): Promise<WebsiteData | Readable>;
|
|
58
|
+
createWebsite(session: Session, data: WebsiteMetaFileContent): Promise<WebsiteId>;
|
|
59
|
+
updateWebsite(session: Session, websiteId: WebsiteId, data: WebsiteData): Promise<void>;
|
|
60
|
+
deleteWebsite(session: Session, websiteId: WebsiteId): Promise<void>;
|
|
61
|
+
duplicateWebsite(session: Session, websiteId: WebsiteId): Promise<void>;
|
|
62
|
+
writeAssets(session: Session, websiteId: WebsiteId, files: ConnectorFile[], status?: StatusCallback): Promise<string[] | void>;
|
|
63
|
+
readAsset(session: Session, websiteId: WebsiteId, fileName: string): Promise<ConnectorFileContent>;
|
|
64
|
+
deleteAssets(session: Session, websiteId: WebsiteId, fileNames: string[]): Promise<void>;
|
|
65
|
+
getWebsiteMeta(session: Session, websiteId: WebsiteId): Promise<WebsiteMeta>;
|
|
66
|
+
setWebsiteMeta(session: Session, websiteId: WebsiteId, data: WebsiteMetaFileContent): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Hosting connectors are used to publish the website
|
|
70
|
+
*/
|
|
71
|
+
export interface HostingConnector<Session extends ConnectorSession = ConnectorSession> extends Connector<Session> {
|
|
72
|
+
publish(session: Session, websiteId: WebsiteId, files: ConnectorFile[], jobManager: JobManager): Promise<JobData>;
|
|
73
|
+
getUrl(session: Session, websiteId: WebsiteId): Promise<string>;
|
|
74
|
+
}
|
|
75
|
+
export declare function toConnectorEnum(type: string | ConnectorType): ConnectorType;
|
|
76
|
+
/**
|
|
77
|
+
* Get a connector by id or by type
|
|
78
|
+
*/
|
|
79
|
+
export declare function getConnector<T extends Connector>(config: ServerConfig, session: any, type: ConnectorType, connectorId?: ConnectorId): Promise<T | undefined>;
|
|
80
|
+
/**
|
|
81
|
+
* Convert a connector to a ConnectorData object to be sent to the frontend
|
|
82
|
+
*/
|
|
83
|
+
export declare function toConnectorData(session: any, connector: Connector): Promise<ConnectorData>;
|
|
84
|
+
export declare function contentToString(content: ConnectorFileContent): Promise<string>;
|
|
85
|
+
export declare function contentToBuffer(content: ConnectorFileContent): Promise<Buffer>;
|
|
86
|
+
export declare function contentToReadable(content: ConnectorFileContent): Readable;
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.toConnectorEnum = toConnectorEnum;
|
|
20
|
+
exports.getConnector = getConnector;
|
|
21
|
+
exports.toConnectorData = toConnectorData;
|
|
22
|
+
exports.contentToString = contentToString;
|
|
23
|
+
exports.contentToBuffer = contentToBuffer;
|
|
24
|
+
exports.contentToReadable = contentToReadable;
|
|
25
|
+
const stream_1 = require("stream");
|
|
26
|
+
const types_1 = require("../../types");
|
|
27
|
+
function toConnectorEnum(type) {
|
|
28
|
+
const result = types_1.ConnectorType[type.toString().toUpperCase()];
|
|
29
|
+
if (!result)
|
|
30
|
+
throw new Error(`Unknown connector type ${type}. It should be one of ${Object.keys(types_1.ConnectorType).join(', ')}`);
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get a connector by id or by type
|
|
35
|
+
*/
|
|
36
|
+
async function getConnector(config, session, type, connectorId) {
|
|
37
|
+
// Get the connectors for this type
|
|
38
|
+
const connectors = config.getConnectors(type);
|
|
39
|
+
// Find the connector by id
|
|
40
|
+
if (connectorId)
|
|
41
|
+
return connectors.find(s => s.connectorId === connectorId && s.connectorType === type);
|
|
42
|
+
// Find the first logged in connector
|
|
43
|
+
for (const connector of connectors) {
|
|
44
|
+
if (await connector.isLoggedIn(session)) {
|
|
45
|
+
return connector;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Defaults to the first connector
|
|
49
|
+
return connectors[0];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Convert a connector to a ConnectorData object to be sent to the frontend
|
|
53
|
+
*/
|
|
54
|
+
async function toConnectorData(session, connector) {
|
|
55
|
+
return {
|
|
56
|
+
connectorId: connector.connectorId,
|
|
57
|
+
type: connector.connectorType,
|
|
58
|
+
displayName: connector.displayName,
|
|
59
|
+
icon: connector.icon,
|
|
60
|
+
disableLogout: !!connector.disableLogout,
|
|
61
|
+
isLoggedIn: await connector.isLoggedIn(session),
|
|
62
|
+
oauthUrl: await connector.getOAuthUrl(session),
|
|
63
|
+
color: connector.color,
|
|
64
|
+
background: connector.background,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function contentToString(content) {
|
|
68
|
+
// String
|
|
69
|
+
if (typeof content === 'string')
|
|
70
|
+
return content;
|
|
71
|
+
// Buffer
|
|
72
|
+
if (Buffer.isBuffer(content))
|
|
73
|
+
return content.toString('utf8');
|
|
74
|
+
// Stream
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
let result = '';
|
|
77
|
+
content.on('data', (chunk) => {
|
|
78
|
+
result += chunk.toString('utf8');
|
|
79
|
+
});
|
|
80
|
+
content.on('error', (err) => {
|
|
81
|
+
reject(err);
|
|
82
|
+
});
|
|
83
|
+
content.on('end', () => {
|
|
84
|
+
resolve(result);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function contentToBuffer(content) {
|
|
89
|
+
// String
|
|
90
|
+
if (typeof content === 'string')
|
|
91
|
+
return Buffer.from(content, 'utf8');
|
|
92
|
+
// Buffer
|
|
93
|
+
if (Buffer.isBuffer(content))
|
|
94
|
+
return content;
|
|
95
|
+
// Stream
|
|
96
|
+
if (content instanceof stream_1.Readable) {
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
const chunks = [];
|
|
99
|
+
content.on('data', (chunk) => {
|
|
100
|
+
chunks.push(chunk);
|
|
101
|
+
});
|
|
102
|
+
content.on('error', (err) => {
|
|
103
|
+
reject(err);
|
|
104
|
+
});
|
|
105
|
+
content.on('end', () => {
|
|
106
|
+
resolve(Buffer.concat(chunks));
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// Unknown
|
|
111
|
+
throw new Error('Unknown content type');
|
|
112
|
+
}
|
|
113
|
+
function contentToReadable(content) {
|
|
114
|
+
// String
|
|
115
|
+
if (typeof content === 'string')
|
|
116
|
+
return stream_1.Readable.from([content]);
|
|
117
|
+
// Buffer
|
|
118
|
+
if (Buffer.isBuffer(content))
|
|
119
|
+
return stream_1.Readable.from([content]);
|
|
120
|
+
// Stream
|
|
121
|
+
if (content instanceof stream_1.Readable)
|
|
122
|
+
return content;
|
|
123
|
+
// Unknown
|
|
124
|
+
throw new Error('Unknown content type');
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=connectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectors.js","sourceRoot":"","sources":["../../../../../src/ts/server/connectors/connectors.ts"],"names":[],"mappings":";AAAA;;;;;;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ebsiteId } from '../types';
|
|
2
|
+
import { ConnectorFile } from './connectors/connectors';
|
|
3
|
+
export declare enum ServerEvent {
|
|
4
|
+
STARTUP_START = "startup-start",
|
|
5
|
+
STARTUP_END = "startup-end",
|
|
6
|
+
PUBLISH_START = "publish-start",
|
|
7
|
+
PUBLISH_END = "publish-end",
|
|
8
|
+
WEBSITE_STORE_START = "store-start",
|
|
9
|
+
WEBSITE_STORE_END = "store-end",
|
|
10
|
+
WEBSITE_ASSET_STORE_START = "asset-store-start",
|
|
11
|
+
WEBSITE_ASSET_STORE_END = "asset-store-end"
|
|
12
|
+
}
|
|
13
|
+
export type PublishStartEventType = PublicationData;
|
|
14
|
+
export type PublishEndEventType = Error | null;
|
|
15
|
+
export type WebsiteStoreStartEventType = {
|
|
16
|
+
websiteId: WebsiteId;
|
|
17
|
+
websiteData: WebsiteData;
|
|
18
|
+
connectorId: ConnectorId;
|
|
19
|
+
};
|
|
20
|
+
export type WebsiteStoreEndEventType = Error | null;
|
|
21
|
+
export type WebsiteAssetStoreStartEventType = {
|
|
22
|
+
files: ConnectorFile[];
|
|
23
|
+
websiteId: WebsiteId;
|
|
24
|
+
connectorId: ConnectorId;
|
|
25
|
+
};
|
|
26
|
+
export type WebsiteAssetStoreEndEventType = Error | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.ServerEvent = void 0;
|
|
20
|
+
var ServerEvent;
|
|
21
|
+
(function (ServerEvent) {
|
|
22
|
+
ServerEvent["STARTUP_START"] = "startup-start";
|
|
23
|
+
ServerEvent["STARTUP_END"] = "startup-end";
|
|
24
|
+
ServerEvent["PUBLISH_START"] = "publish-start";
|
|
25
|
+
ServerEvent["PUBLISH_END"] = "publish-end";
|
|
26
|
+
ServerEvent["WEBSITE_STORE_START"] = "store-start";
|
|
27
|
+
ServerEvent["WEBSITE_STORE_END"] = "store-end";
|
|
28
|
+
ServerEvent["WEBSITE_ASSET_STORE_START"] = "asset-store-start";
|
|
29
|
+
ServerEvent["WEBSITE_ASSET_STORE_END"] = "asset-store-end";
|
|
30
|
+
})(ServerEvent || (exports.ServerEvent = ServerEvent = {}));
|
|
31
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/ts/server/events.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAKH,IAAY,WASX;AATD,WAAY,WAAW;IACrB,8CAA+B,CAAA;IAC/B,0CAA2B,CAAA;IAC3B,8CAA+B,CAAA;IAC/B,0CAA2B,CAAA;IAC3B,kDAAmC,CAAA;IACnC,8CAA+B,CAAA;IAC/B,8DAA+C,CAAA;IAC/C,0DAA2C,CAAA;AAC7C,CAAC,EATW,WAAW,2BAAX,WAAW,QAStB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JobData, JobId } from '../types';
|
|
2
|
+
export declare function startJob(message?: string): JobData;
|
|
3
|
+
export declare function getJob(id: JobId): JobData | undefined;
|
|
4
|
+
export declare function jobSuccess(id: JobId, message?: string): boolean;
|
|
5
|
+
export declare function jobError(id: JobId, message?: string): boolean;
|
|
6
|
+
export declare function killJob(job: JobData): void;
|
|
7
|
+
export interface JobManager {
|
|
8
|
+
startJob: typeof startJob;
|
|
9
|
+
jobSuccess: typeof jobSuccess;
|
|
10
|
+
jobError: typeof jobError;
|
|
11
|
+
}
|
|
12
|
+
export declare const jobManager: JobManager;
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.jobManager = void 0;
|
|
20
|
+
exports.startJob = startJob;
|
|
21
|
+
exports.getJob = getJob;
|
|
22
|
+
exports.jobSuccess = jobSuccess;
|
|
23
|
+
exports.jobError = jobError;
|
|
24
|
+
exports.killJob = killJob;
|
|
25
|
+
const types_1 = require("../types");
|
|
26
|
+
// Delay after which the job is deleted from memory
|
|
27
|
+
const TIME_TO_KEEP_AFTER_STOP = 60 * 10 * 1000; // 10 min
|
|
28
|
+
// Store the jobs in memory
|
|
29
|
+
const jobs = new Array();
|
|
30
|
+
const timers = new WeakMap();
|
|
31
|
+
// Key which will change on server restart
|
|
32
|
+
const processKey = Math.ceil(Math.random() * 1000000);
|
|
33
|
+
// Next id for the next job
|
|
34
|
+
let nextJobId = 0;
|
|
35
|
+
// Create a new job
|
|
36
|
+
function startJob(message = '') {
|
|
37
|
+
const jobId = `${processKey}_${++nextJobId}`;
|
|
38
|
+
const job = {
|
|
39
|
+
jobId,
|
|
40
|
+
status: types_1.JobStatus.IN_PROGRESS,
|
|
41
|
+
message: message
|
|
42
|
+
};
|
|
43
|
+
jobs.push(job);
|
|
44
|
+
return job;
|
|
45
|
+
}
|
|
46
|
+
// Retriev a job if it exists
|
|
47
|
+
function getJob(id) {
|
|
48
|
+
return jobs.find(job => job.jobId === id);
|
|
49
|
+
}
|
|
50
|
+
// End the job with success
|
|
51
|
+
function jobSuccess(id, message = '') {
|
|
52
|
+
return end(id, types_1.JobStatus.SUCCESS, message);
|
|
53
|
+
}
|
|
54
|
+
// End the job with error
|
|
55
|
+
function jobError(id, message = '') {
|
|
56
|
+
return end(id, types_1.JobStatus.ERROR, message);
|
|
57
|
+
}
|
|
58
|
+
// Remove a job from memory
|
|
59
|
+
// This is also used in unit tests to avoid memory lea
|
|
60
|
+
function killJob(job) {
|
|
61
|
+
clearTimeout(timers.get(job));
|
|
62
|
+
timers.delete(job);
|
|
63
|
+
jobs.splice(jobs.findIndex(j => job.jobId === j.jobId), 1);
|
|
64
|
+
}
|
|
65
|
+
// End the job
|
|
66
|
+
function end(id, status, message = '') {
|
|
67
|
+
const job = getJob(id);
|
|
68
|
+
if (job) {
|
|
69
|
+
job.status = status;
|
|
70
|
+
if (message)
|
|
71
|
+
job.message = message;
|
|
72
|
+
timers.set(job, setTimeout(() => killJob(job), TIME_TO_KEEP_AFTER_STOP));
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
// Export the job manager
|
|
78
|
+
exports.jobManager = { startJob, jobSuccess, jobError };
|
|
79
|
+
//# sourceMappingUR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C5C,CAAC;AAED,yBAAyB;AACzB,SAAgB,QAAQ,CAAC,EAAS,EAAE,OAAO,GAAG,EAAE;IAC9C,OAAO,GAAG,CAAC,EAAE,EAAE,iBAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AAC1C,CAAC;AAED,2BAA2B;AAC3B,sDAAsD;AACtD,SAAgB,OAAO,CAAC,GAAY;IAClC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7B,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED,cAAc;AACd,SAAS,GAAG,CAAC,EAAS,EAAE,MAAiB,EAAE,OAAO,GAAG,EAAE;IACrD,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAA;IACtB,IAAG,GAAG,EAAE,CAAC;QACP,GAAG,CAAC,MAAM,GAAG,MAAM,CAAA;QACnB,IAAG,OAAO;YAAE,GAAG,CAAC,OAAO,GAAG,OAAO,CAAA;QACjC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAA;QACxE,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AASD,yBAAyB;AACZ,QAAA,UAAU,GAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throw an error if a parameter is missing
|
|
3
|
+
* @param value the value to check
|
|
4
|
+
* @param name the name of the parameter
|
|
5
|
+
* @throws Error if the parameter is missing
|
|
6
|
+
*/
|
|
7
|
+
export declare function requiredParam<T>(value: T | undefined, name: string, defaultValue?: T): NonNullable<T>;
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.requiredParam = requiredParam;
|
|
20
|
+
/**
|
|
21
|
+
* Throw an error if a parameter is missing
|
|
22
|
+
* @param value the value to check
|
|
23
|
+
* @param name the name of the parameter
|
|
24
|
+
* @throws Error if the parameter is missing
|
|
25
|
+
*/
|
|
26
|
+
function requiredParam(value, name, defaultValue) {
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
if (defaultValue !== undefined) {
|
|
29
|
+
return defaultValue;
|
|
30
|
+
}
|
|
31
|
+
const error = new Error(`Missing required parameter ${name}`);
|
|
32
|
+
console.error(`Missing required parameter ${name}`, error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../../../src/ts/server/utils/validation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAQH,sCAUC;AAhBD;;;;;GAKG;AACH,SAAgB,aAAa,CAAI,KAAoB,EAAE,IAAY,EAAE,YAAgB;IACnF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,YAA8B,CAAA;QACvC,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,8BAA8B,IAAI,EAAE,CAAC,CAAA;QAC7D,OAAO,CAAC,KAAK,CAAC,8BAA8B,IAAI,EAAE,EAAE,KAAK,CAAC,CAAA;QAC1D,MAAM,KAAK,CAAA;IACb,CAAC;IACD,OAAO,KAAuB,CAAA;AAChC,CAAC"}
|