@silexlabs/silex 3.0.0-alpha.39 → 3.0.0-alpha.41
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/.silex.js +38 -8
- package/dist/client/client/config.d.ts +11 -41
- package/dist/client/client/grapesjs/LoginDialog.d.ts +13 -0
- package/dist/client/client/grapesjs/PublicationManager.d.ts +69 -0
- package/dist/client/client/grapesjs/PublicationUi.d.ts +58 -0
- package/dist/client/client/grapesjs/index.d.ts +18 -44
- package/dist/client/client/grapesjs/storage.d.ts +1 -0
- package/dist/client/client/services.d.ts +35 -0
- package/dist/client/constants.d.ts +17 -0
- package/dist/client/css/admin.css +86 -3
- package/dist/client/js/main.js +201 -90
- package/dist/client/js/main.js.LICENSE.txt +6 -0
- package/dist/client/types.d.ts +200 -29
- package/dist/constants.d.ts +21 -0
- package/dist/constants.js +38 -1
- package/dist/constants.js.map +1 -0
- package/dist/events.d.ts +2 -0
- package/dist/events.js +17 -0
- package/dist/events.js.map +1 -0
- package/dist/plugins/AuthPlugin.d.ts +1 -0
- package/dist/plugins/AuthPlugin.js +38 -0
- package/dist/plugins/AuthPlugin.js.map +1 -0
- package/dist/plugins/Cache.d.ts +2 -0
- package/dist/plugins/Cache.js +32 -0
- package/dist/plugins/Cache.js.map +1 -0
- package/dist/plugins/FtpBackend.d.ts +92 -0
- package/dist/plugins/FtpBackend.js +604 -0
- package/dist/plugins/FtpBackend.js.map +1 -0
- package/dist/plugins/HooksPlugin.d.ts +7 -0
- package/dist/plugins/HooksPlugin.js +76 -0
- package/dist/plugins/HooksPlugin.js.map +1 -0
- package/dist/plugins/PublicationPlugin.d.ts +17 -0
- package/dist/plugins/PublicationPlugin.js +170 -0
- package/dist/plugins/PublicationPlugin.js.map +1 -0
- package/dist/plugins/SslPlugin.d.ts +1 -0
- package/dist/plugins/SslPlugin.js +86 -0
- package/dist/plugins/SslPlugin.js.map +1 -0
- package/dist/plugins/StaticPlugin.d.ts +1 -0
- package/dist/plugins/StaticPlugin.js +66 -0
- package/dist/plugins/StaticPlugin.js.map +1 -0
- package/dist/plugins/WebsitePlugin.d.ts +14 -0
- package/dist/plugins/WebsitePlugin.js +302 -0
- package/dist/plugins/WebsitePlugin.js.map +1 -0
- package/dist/server/backends/FsBackend.d.ts +42 -0
- package/dist/server/backends/FsBackend.js +269 -0
- package/dist/server/backends/FsBackend.js.map +1 -0
- package/dist/server/backends/index.d.ts +95 -0
- package/dist/server/backends/index.js +255 -0
- package/dist/server/backends/index.js.map +1 -0
- package/dist/server/cli.js +0 -1
- package/dist/server/config.d.ts +58 -0
- package/dist/server/config.js +128 -24
- package/dist/server/config.js.map +1 -0
- package/dist/server/express.js +31 -3
- package/dist/server/index.js +9 -20
- package/dist/server/jobs.d.ts +6 -0
- package/dist/server/jobs.js +75 -0
- package/dist/server/jobs.js.map +1 -0
- package/dist/server/utils/validation.d.ts +7 -0
- package/dist/server/utils/validation.js +37 -0
- package/dist/server/utils/validation.js.map +1 -0
- package/dist/types.d.ts +270 -0
- package/dist/types.js +35 -28
- package/dist/types.js.map +1 -0
- package/package.json +19 -8
- package/public/silex.js +17 -0
- package/src/css/dialog.scss +9 -2
- package/src/css/grapesjs.scss +79 -0
- package/src/css/project-bar.scss +2 -2
- package/src/example-client-config.js +17 -0
- package/src/html/templates/includes.pug +0 -1
- package/src/ts/client/config.ts +7 -6
- package/src/ts/client/grapesjs/LoginDialog.ts +190 -0
- package/src/ts/client/grapesjs/PublicationManager.ts +333 -0
- package/src/ts/client/grapesjs/PublicationUi.ts +320 -0
- package/src/ts/client/grapesjs/index.ts +88 -85
- package/src/ts/client/grapesjs/storage.ts +110 -0
- package/src/ts/client/index.ts +5 -7
- package/src/ts/client/services.ts +129 -0
- package/src/ts/constants.ts +21 -0
- package/src/ts/plugins/AuthPlugin.ts +38 -0
- package/src/ts/plugins/Cache.ts +28 -0
- package/src/ts/plugins/FtpBackend.ts +689 -0
- package/src/ts/plugins/HooksPlugin.ts +79 -0
- package/src/ts/plugins/PublicationPlugin.ts +170 -0
- package/src/{plugins/SslPlugin.js → ts/plugins/SslPlugin.ts} +24 -6
- package/src/ts/plugins/StaticPlugin.ts +68 -0
- package/src/ts/plugins/WebsitePlugin.ts +318 -0
- package/src/ts/server/backends/FsBackend.ts +266 -0
- package/src/ts/server/backends/index.ts +309 -0
- package/src/ts/server/cli.ts +0 -2
- package/src/ts/server/config.ts +103 -33
- package/src/ts/server/express.ts +37 -3
- package/src/ts/server/index.ts +24 -14
- package/src/ts/server/jobs.test.ts +74 -0
- package/src/ts/server/jobs.ts +77 -0
- package/src/ts/server/utils/validation.ts +33 -0
- package/src/ts/types.ts +167 -59
- package/dist/client/client/grapesjs/publish.d.ts +0 -18
- package/dist/page.js +0 -15
- 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/StaticPlugin.js +0 -48
- package/src/plugins/WebsitePlugin.js +0 -207
- package/src/ts/client/grapesjs/publish.ts +0 -403
- /package/.silex/default/{.silex.data.json → website.json} +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Application } from 'express';
|
|
4
|
+
import { Readable } from 'stream';
|
|
5
|
+
import { ServerConfig } from '../config';
|
|
6
|
+
import { JobStatus, JobData, BackendData, BackendId, WebsiteId, BackendType, BackendUser, WebsiteMeta, FileMeta } from '../../types';
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview define types for Silex backends
|
|
9
|
+
* Bakends can provide storage for website data and assets, and/or hosting to publish the website online
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Files are stored in backend as a File object
|
|
13
|
+
* @see types/ClientSideFile
|
|
14
|
+
*/
|
|
15
|
+
export interface File {
|
|
16
|
+
path: string;
|
|
17
|
+
content: Buffer | string | Readable;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Callback to update the publication status
|
|
21
|
+
*/
|
|
22
|
+
export type StatusCallback = ({ message, status }: {
|
|
23
|
+
message: string;
|
|
24
|
+
status: JobStatus;
|
|
25
|
+
}) => Promise<void>;
|
|
26
|
+
export type BackendSession = any;
|
|
27
|
+
/**
|
|
28
|
+
* Backends are the base interface for Storage and Hosting providers
|
|
29
|
+
*/
|
|
30
|
+
export interface Backend<Session extends BackendSession = BackendSession> {
|
|
31
|
+
id: BackendId;
|
|
32
|
+
displayName: string;
|
|
33
|
+
icon: string;
|
|
34
|
+
disableLogout?: boolean;
|
|
35
|
+
type: BackendType;
|
|
36
|
+
getAdminUrl(session: Session, id: WebsiteId): Promise<string | null>;
|
|
37
|
+
getAuthorizeURL(session: Session): Promise<string | null>;
|
|
38
|
+
isLoggedIn(session: Session): Promise<boolean>;
|
|
39
|
+
logout(session: Session): Promise<void>;
|
|
40
|
+
getUserData(session: Session): Promise<BackendUser>;
|
|
41
|
+
init(session: Session, id: WebsiteId): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Storage are used to store the website data and assets
|
|
45
|
+
* And possibly rename files and directories, and get the URL of a file
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
export interface StorageProvider<Session = BackendSession> extends Backend<Session> {
|
|
49
|
+
listWebsites(session: Session): Promise<WebsiteMeta[]>;
|
|
50
|
+
readFile(session: Session, id: WebsiteId, path: string): Promise<File>;
|
|
51
|
+
writeFiles(session: Session, id: WebsiteId, files: File[], status?: StatusCallback): Promise<string[]>;
|
|
52
|
+
deleteFiles(session: Session, id: WebsiteId, paths: string[]): Promise<void>;
|
|
53
|
+
listDir(session: Session, id: WebsiteId, path: string): Promise<FileMeta[]>;
|
|
54
|
+
createDir(session: Session, id: WebsiteId, path: string): Promise<void>;
|
|
55
|
+
deleteDir(session: Session, id: WebsiteId, path: string): Promise<void>;
|
|
56
|
+
getSiteMeta(session: Session, id: WebsiteId): Promise<WebsiteMeta>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Hosting providers are used to publish the website
|
|
60
|
+
*/
|
|
61
|
+
export interface HostingProvider<Session = BackendSession> extends Backend<Session> {
|
|
62
|
+
publish(session: Session, id: WebsiteId, backendData: BackendData, files: File[]): Promise<JobData>;
|
|
63
|
+
getWebsiteUrl(session: Session, id: WebsiteId): Promise<string>;
|
|
64
|
+
}
|
|
65
|
+
export declare function toBackendEnum(type: string): BackendType;
|
|
66
|
+
/**
|
|
67
|
+
* Get a backend by id or by type
|
|
68
|
+
*/
|
|
69
|
+
export declare function getBackend<T extends Backend>(config: ServerConfig, session: any, type: BackendType, backendId?: BackendId): Promise<T | undefined>;
|
|
70
|
+
/**
|
|
71
|
+
* Convert a backend to a BackendData object to be sent to the frontend
|
|
72
|
+
*/
|
|
73
|
+
export declare function toBackendData(session: any, backend: Backend): Promise<BackendData>;
|
|
74
|
+
/**
|
|
75
|
+
* Add routes to the express app
|
|
76
|
+
*/
|
|
77
|
+
export declare function addRoutes(config: ServerConfig, app: Application): void;
|
|
78
|
+
/**
|
|
79
|
+
* Express route to check if the user is logged in
|
|
80
|
+
* Returns user data and backend data
|
|
81
|
+
*/
|
|
82
|
+
export declare function routeLoginStatus(req: any, res: any): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Express route to list the backends
|
|
85
|
+
*/
|
|
86
|
+
export declare function routeListBackends(req: any, res: any): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Express route to serve as redirect after a successful login
|
|
89
|
+
* The returned HTML will postMessage data and close the popup window
|
|
90
|
+
*/
|
|
91
|
+
export declare function routeLoginSuccess(req: any, res: any): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Express route to logout from a backend
|
|
94
|
+
*/
|
|
95
|
+
export declare function routeLogout(req: any, res: any): Promise<void>;
|
|
@@ -0,0 +1,255 @@
|
|
|
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.routeLogout = exports.routeLoginSuccess = exports.routeListBackends = exports.routeLoginStatus = exports.addRoutes = exports.toBackendData = exports.getBackend = exports.toBackendEnum = void 0;
|
|
20
|
+
const express_1 = require("express");
|
|
21
|
+
const types_1 = require("../../types");
|
|
22
|
+
const constants_1 = require("../../constants");
|
|
23
|
+
const validation_1 = require("../utils/validation");
|
|
24
|
+
function toBackendEnum(type) {
|
|
25
|
+
return types_1.BackendType[type.toUpperCase()];
|
|
26
|
+
}
|
|
27
|
+
exports.toBackendEnum = toBackendEnum;
|
|
28
|
+
/**
|
|
29
|
+
* Get a backend by id or by type
|
|
30
|
+
*/
|
|
31
|
+
async function getBackend(config, session, type, backendId) {
|
|
32
|
+
const backends = config.getBackends(type);
|
|
33
|
+
// Find the backend by id
|
|
34
|
+
if (backendId)
|
|
35
|
+
return backends.find(s => s.id === backendId && s.type === type);
|
|
36
|
+
// Find the first logged in backend
|
|
37
|
+
for (const backend of backends) {
|
|
38
|
+
if (await backend.isLoggedIn(session)) {
|
|
39
|
+
return backend;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Defaults to the first backend
|
|
43
|
+
return backends[0];
|
|
44
|
+
}
|
|
45
|
+
exports.getBackend = getBackend;
|
|
46
|
+
/**
|
|
47
|
+
* Convert a backend to a BackendData object to be sent to the frontend
|
|
48
|
+
*/
|
|
49
|
+
async function toBackendData(session, backend) {
|
|
50
|
+
return {
|
|
51
|
+
backendId: backend.id,
|
|
52
|
+
type: backend.type,
|
|
53
|
+
displayName: backend.displayName,
|
|
54
|
+
icon: backend.icon,
|
|
55
|
+
disableLogout: !!backend.disableLogout,
|
|
56
|
+
isLoggedIn: await backend.isLoggedIn(session),
|
|
57
|
+
authUrl: await backend.getAuthorizeURL(session),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.toBackendData = toBackendData;
|
|
61
|
+
/**
|
|
62
|
+
* Add routes to the express app
|
|
63
|
+
*/
|
|
64
|
+
function addRoutes(config, app) {
|
|
65
|
+
// Create the router
|
|
66
|
+
const router = (0, express_1.Router)();
|
|
67
|
+
app.use(router);
|
|
68
|
+
// Backend routes
|
|
69
|
+
router.get(`/${constants_1.API_BACKEND_LOGIN_STATUS}`, routeLoginStatus);
|
|
70
|
+
router.get(`/${constants_1.API_BACKEND_LIST}`, routeListBackends);
|
|
71
|
+
router.post(`/${constants_1.API_BACKEND_LOGOUT}`, routeLogout);
|
|
72
|
+
router.get(`/${constants_1.API_BACKEND_LOGIN_CALLBACK}`, routeLoginSuccess);
|
|
73
|
+
}
|
|
74
|
+
exports.addRoutes = addRoutes;
|
|
75
|
+
/**
|
|
76
|
+
* Express route to check if the user is logged in
|
|
77
|
+
* Returns user data and backend data
|
|
78
|
+
*/
|
|
79
|
+
async function routeLoginStatus(req, res) {
|
|
80
|
+
try {
|
|
81
|
+
const config = (0, validation_1.requiredParam)(req.app.get('config'), 'Config object on express js APP');
|
|
82
|
+
const query = (0, validation_1.requiredParam)(req.query, 'Query object');
|
|
83
|
+
const session = (0, validation_1.requiredParam)(req['session'], 'Session object');
|
|
84
|
+
const websiteId = query.id;
|
|
85
|
+
const backendId = query.backendId;
|
|
86
|
+
const type = query.type;
|
|
87
|
+
const backend = await getBackend(config, session, type, backendId);
|
|
88
|
+
if (!backend) {
|
|
89
|
+
res
|
|
90
|
+
.status(500)
|
|
91
|
+
.json({
|
|
92
|
+
error: true,
|
|
93
|
+
message: 'No backend found',
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!await backend.isLoggedIn(session)) {
|
|
98
|
+
res
|
|
99
|
+
.status(401)
|
|
100
|
+
.json({
|
|
101
|
+
error: true,
|
|
102
|
+
message: 'Not logged in',
|
|
103
|
+
});
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const backendData = await toBackendData(session, backend);
|
|
107
|
+
const user = await backend.getUserData(session);
|
|
108
|
+
const websiteMeta = websiteId && backend.type === types_1.BackendType.STORAGE && await backend.getSiteMeta(session, websiteId);
|
|
109
|
+
res.json({
|
|
110
|
+
backend: backendData,
|
|
111
|
+
user,
|
|
112
|
+
websiteMeta,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error('Error in the login status request', error);
|
|
117
|
+
res.status(error?.code ?? 500).json({
|
|
118
|
+
error: true,
|
|
119
|
+
message: error.message,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.routeLoginStatus = routeLoginStatus;
|
|
124
|
+
/**
|
|
125
|
+
* Express route to list the backends
|
|
126
|
+
*/
|
|
127
|
+
async function routeListBackends(req, res) {
|
|
128
|
+
try {
|
|
129
|
+
const config = (0, validation_1.requiredParam)(req.app.get('config'), 'Config object on express js APP');
|
|
130
|
+
const query = req.query;
|
|
131
|
+
const type = toBackendEnum((0, validation_1.requiredParam)(query.type, 'Backend type'));
|
|
132
|
+
const backends = config.getBackends(type);
|
|
133
|
+
try {
|
|
134
|
+
const list = await Promise.all(backends.map(async (backend) => toBackendData(req['session'], backend)));
|
|
135
|
+
res.json(list);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.error('Error while listing backends', error);
|
|
139
|
+
res.status(error?.code ?? 500).json({
|
|
140
|
+
error: true,
|
|
141
|
+
message: 'Error while listing backends: ' + error.message,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error('Error in the list backends request', error);
|
|
147
|
+
res.status(error?.code ?? 400).json({
|
|
148
|
+
error: true,
|
|
149
|
+
message: 'Error in the list backends request: ' + error.message,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.routeListBackends = routeListBackends;
|
|
154
|
+
/**
|
|
155
|
+
* Utility function to send an HTML page to the browser
|
|
156
|
+
* This page will send a postMessage to the parent window and close itself
|
|
157
|
+
*/
|
|
158
|
+
function sendHtml(res, message, backendId, error, defaultErrorCode) {
|
|
159
|
+
error && console.error('Error while logging in', error);
|
|
160
|
+
// Data for postMessage
|
|
161
|
+
const data = {
|
|
162
|
+
type: 'login',
|
|
163
|
+
error: error ? true : false,
|
|
164
|
+
message,
|
|
165
|
+
backendId,
|
|
166
|
+
};
|
|
167
|
+
// HTTP status code
|
|
168
|
+
const status = error ? error['code'] ?? defaultErrorCode ?? 500 : 200;
|
|
169
|
+
// Send the HTML
|
|
170
|
+
res
|
|
171
|
+
.status(status)
|
|
172
|
+
.send(`
|
|
173
|
+
<html>
|
|
174
|
+
<head>
|
|
175
|
+
<script>
|
|
176
|
+
window.opener.postMessage(${JSON.stringify(data)}, '*')
|
|
177
|
+
window.close()
|
|
178
|
+
</script>
|
|
179
|
+
</head>
|
|
180
|
+
<body>
|
|
181
|
+
<p>${message}</p>
|
|
182
|
+
<p>Close this window</p>
|
|
183
|
+
</body>
|
|
184
|
+
</html>
|
|
185
|
+
`);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Express route to serve as redirect after a successful login
|
|
189
|
+
* The returned HTML will postMessage data and close the popup window
|
|
190
|
+
*/
|
|
191
|
+
async function routeLoginSuccess(req, res) {
|
|
192
|
+
try {
|
|
193
|
+
const query = req.query;
|
|
194
|
+
if (query.error)
|
|
195
|
+
throw new Error(query.error);
|
|
196
|
+
const backendId = (0, validation_1.requiredParam)(query.backendId, 'Backend id');
|
|
197
|
+
const config = (0, validation_1.requiredParam)(req.app.get('config'), 'Config object on express js APP');
|
|
198
|
+
const type = toBackendEnum((0, validation_1.requiredParam)(query.type, 'Backend type'));
|
|
199
|
+
const backend = await getBackend(config, req['session'], type, backendId);
|
|
200
|
+
if (!backend)
|
|
201
|
+
throw new Error('Backend not found ' + backendId);
|
|
202
|
+
try {
|
|
203
|
+
sendHtml(res, 'Logged in', backendId);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
sendHtml(res, 'Error while logging in', undefined, error, 500);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
sendHtml(res, 'Error in the request ' + error.message, undefined, error, 400);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.routeLoginSuccess = routeLoginSuccess;
|
|
214
|
+
/**
|
|
215
|
+
* Express route to logout from a backend
|
|
216
|
+
*/
|
|
217
|
+
async function routeLogout(req, res) {
|
|
218
|
+
try {
|
|
219
|
+
const query = req.query;
|
|
220
|
+
// Get the backend
|
|
221
|
+
const backendId = (0, validation_1.requiredParam)(query.backendId, 'Backend id');
|
|
222
|
+
const config = (0, validation_1.requiredParam)(req.app.get('config'), 'Config object on express js APP');
|
|
223
|
+
const type = toBackendEnum((0, validation_1.requiredParam)(query.type, 'Backend type'));
|
|
224
|
+
const backend = await getBackend(config, req['session'], type, backendId);
|
|
225
|
+
if (!backend)
|
|
226
|
+
throw new Error(`Backend not found ${backendId} ${type}`);
|
|
227
|
+
try {
|
|
228
|
+
// Logout
|
|
229
|
+
await backend.logout(req['session']);
|
|
230
|
+
// Return success
|
|
231
|
+
res.json({
|
|
232
|
+
error: false,
|
|
233
|
+
message: 'OK',
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
console.error('Error while logging out', error);
|
|
238
|
+
res.status(error?.code ?? 500).json({
|
|
239
|
+
error: true,
|
|
240
|
+
message: 'Error while logging out: ' + error.message,
|
|
241
|
+
});
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
console.error('Error in the logout request', error);
|
|
247
|
+
res.status(error?.code ?? 400).json({
|
|
248
|
+
error: true,
|
|
249
|
+
message: 'Error in the logout request: ' + error.message,
|
|
250
|
+
});
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.routeLogout = routeLogout;
|
|
255
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ts/server/backends/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,qCAAuD;AAGvD,uCAAsW;AACtW,+CAA4H;AAC5H,oDAAmD;AAiEnD,SAAgB,aAAa,CAAC,IAAY;IACxC,OAAO,mBAAW,CAAC,IAAI,CAAC,WAAW,EAA8B,CAAC,CAAA;AACpE,CAAC;AAFD,sCAEC;AAED;;GAEG;AACI,KAAK,UAAU,UAAU,CAAoB,MAAoB,EAAE,OAAY,EAAE,IAAiB,EAAE,SAAqB;IAC9H,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAI,IAAI,CAAC,CAAA;IAC5C,yBAAyB;IACzB,IAAI,SAAS;QAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;IAC/E,mCAAmC;IACnC,KAAK,MAA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,IAAI,GAAG,aAAa,CAAC,IAAA,0BAAa,EAAC,KAAK,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAA;QACrE,MAAM,OAAO,GAAG,MAAM,UAAU,CAAU,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;QAClF,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,SAAS,IAAI,IAAI,EAAE,CAAC,CAAA;QACvE,IAAI;YACF,SAAS;YACT,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAA;YACpC,iBAAiB;YACjB,GAAG,CAAC,IAAI,CAAC;gBACP,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,IAAI;aACM,CAAC,CAAA;SACvB;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAA;YAC/C,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;gBAClC,KAAK,EAAE,IAAI;gBACX,OAAO,EAAE,2BAA2B,GAAG,KAAK,CAAC,OAAO;aACjC,CAAC,CAAA;YACtB,OAAM;SACP;KACF;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAA;QACnD,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;YAClC,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,+BAA+B,GAAG,KAAK,CAAC,OAAO;SACrC,CAAC,CAAA;QACtB,OAAM;KACP;AACH,CAAC;AAjCD,kCAiCC"}
|
package/dist/server/cli.js
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This is where the default config is defined. Also use this object as an event emitter to listen to Silex events
|
|
3
|
+
* The values can be overriden with env vars or before passing the config to Silex
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @class default config for Silex server
|
|
7
|
+
*/
|
|
8
|
+
import { Config } from '@silexlabs/silex-plugins';
|
|
9
|
+
import { Application } from 'express';
|
|
10
|
+
import { HostingProvider, StorageProvider } from './backends';
|
|
11
|
+
import { Backend } from './backends';
|
|
12
|
+
import { BackendType } from '../types';
|
|
13
|
+
/**
|
|
14
|
+
* Config types definitions
|
|
15
|
+
*/
|
|
16
|
+
export declare class ServerConfig extends Config {
|
|
17
|
+
url: string;
|
|
18
|
+
debug: boolean;
|
|
19
|
+
port: string;
|
|
20
|
+
apiPath: string;
|
|
21
|
+
expressOptions: {
|
|
22
|
+
jsonLimit: string;
|
|
23
|
+
textLimit: string;
|
|
24
|
+
sessionName: string;
|
|
25
|
+
sessionSecret: string;
|
|
26
|
+
cors: string;
|
|
27
|
+
};
|
|
28
|
+
constructor(url: string, debug: boolean, port: string, apiPath: string);
|
|
29
|
+
getBackends<T extends Backend>(type?: BackendType | string | null): T[];
|
|
30
|
+
private storageProviders;
|
|
31
|
+
addStorageProvider(storage: StorageProvider | StorageProvider[]): void;
|
|
32
|
+
setStorageProviders(storageProviders: StorageProvider[]): void;
|
|
33
|
+
getStorageProviders(): StorageProvider[];
|
|
34
|
+
private hostingProviders;
|
|
35
|
+
addHostingProvider(hosting: HostingProvider | HostingProvider[]): void;
|
|
36
|
+
setHostingProviders(hostings: HostingProvider[]): void;
|
|
37
|
+
getHostingProviders(): HostingProvider[];
|
|
38
|
+
/**
|
|
39
|
+
* Add routes to serve the client config file
|
|
40
|
+
*/
|
|
41
|
+
addRoutes(app: Application): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Load config files
|
|
44
|
+
* This is the main config file and the user config file
|
|
45
|
+
*/
|
|
46
|
+
loadConfigFiles(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export declare function createConfig(): ServerConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Load user config file
|
|
51
|
+
* This is the config file passed as env var CONFIG
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadUserConfig(config: ServerConfig): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Load .silex.js in the root folder
|
|
56
|
+
* This is the main config file
|
|
57
|
+
*/
|
|
58
|
+
export declare function loadSilexConfig(config: ServerConfig): Promise<void>;
|
package/dist/server/config.js
CHANGED
|
@@ -1,17 +1,51 @@
|
|
|
1
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
|
+
*/
|
|
2
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ServerConfig = void 0;
|
|
19
|
+
exports.loadSilexConfig = exports.loadUserConfig = exports.createConfig = exports.ServerConfig = void 0;
|
|
20
|
+
/**
|
|
21
|
+
* @fileoverview This is where the default config is defined. Also use this object as an event emitter to listen to Silex events
|
|
22
|
+
* The values can be overriden with env vars or before passing the config to Silex
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* @class default config for Silex server
|
|
26
|
+
*/
|
|
4
27
|
const silex_plugins_1 = require("@silexlabs/silex-plugins");
|
|
5
28
|
const path_1 = require("path");
|
|
6
29
|
const constants_1 = require("../constants");
|
|
7
|
-
const express_1 = require("express");
|
|
8
30
|
const promises_1 = require("fs/promises");
|
|
9
|
-
const
|
|
31
|
+
const backends_1 = require("./backends");
|
|
32
|
+
const FsBackend_1 = require("./backends/FsBackend");
|
|
33
|
+
const types_1 = require("../types");
|
|
34
|
+
/**
|
|
35
|
+
* Config types definitions
|
|
36
|
+
*/
|
|
10
37
|
class ServerConfig extends silex_plugins_1.Config {
|
|
11
38
|
url;
|
|
12
39
|
debug;
|
|
13
40
|
port;
|
|
14
41
|
apiPath;
|
|
42
|
+
expressOptions = {
|
|
43
|
+
jsonLimit: process.env.SILEX_EXPRESS_JSON_LIMIT || '1mb',
|
|
44
|
+
textLimit: process.env.SILEX_EXPRESS_TEXT_LIMIT || '10mb',
|
|
45
|
+
sessionName: process.env.SILEX_SESSION_NAME || 'silex-session',
|
|
46
|
+
sessionSecret: process.env.SILEX_SESSION_SECRET || 'replace this session secret in env vars',
|
|
47
|
+
cors: process.env.SILEX_CORS_URL,
|
|
48
|
+
};
|
|
15
49
|
constructor(url, debug, port, apiPath) {
|
|
16
50
|
super();
|
|
17
51
|
this.url = url;
|
|
@@ -19,42 +53,112 @@ class ServerConfig extends silex_plugins_1.Config {
|
|
|
19
53
|
this.port = port;
|
|
20
54
|
this.apiPath = apiPath;
|
|
21
55
|
}
|
|
56
|
+
// All backends or just the storage or hosting providers
|
|
57
|
+
getBackends(type = null) {
|
|
58
|
+
// All backends including storage and hosting providers
|
|
59
|
+
if (!type) {
|
|
60
|
+
// Concat storage and hosting providers
|
|
61
|
+
const allBackends = this.getStorageProviders().concat(this.getHostingProviders());
|
|
62
|
+
// Remove duplicates (if a backend is both a storage and a hosting provider)
|
|
63
|
+
return Array.from(new Set(allBackends));
|
|
64
|
+
}
|
|
65
|
+
// Convert to enum in case it is a string
|
|
66
|
+
const backendType = (0, backends_1.toBackendEnum)(type.toString());
|
|
67
|
+
// Only one type of backend
|
|
68
|
+
switch (backendType) {
|
|
69
|
+
case types_1.BackendType.HOSTING: return this.getHostingProviders();
|
|
70
|
+
case types_1.BackendType.STORAGE: return this.getStorageProviders();
|
|
71
|
+
default: throw new Error(`Unknown backend type ${type}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Storage providers to store the website data and assets
|
|
75
|
+
storageProviders = [new FsBackend_1.FsBackend(null, { type: types_1.BackendType.STORAGE })];
|
|
76
|
+
addStorageProvider(storage) {
|
|
77
|
+
this.setStorageProviders(this.storageProviders.concat(storage));
|
|
78
|
+
}
|
|
79
|
+
setStorageProviders(storageProviders) {
|
|
80
|
+
this.storageProviders = storageProviders;
|
|
81
|
+
}
|
|
82
|
+
getStorageProviders() {
|
|
83
|
+
return this.storageProviders;
|
|
84
|
+
}
|
|
85
|
+
// Hosting providers to publish the website online
|
|
86
|
+
hostingProviders = [new FsBackend_1.FsBackend(null, { type: types_1.BackendType.HOSTING })];
|
|
87
|
+
addHostingProvider(hosting) {
|
|
88
|
+
this.setHostingProviders(this.hostingProviders.concat(hosting));
|
|
89
|
+
}
|
|
90
|
+
setHostingProviders(hostings) {
|
|
91
|
+
this.hostingProviders = hostings;
|
|
92
|
+
}
|
|
93
|
+
getHostingProviders() { return this.hostingProviders; }
|
|
94
|
+
/**
|
|
95
|
+
* Add routes to serve the client config file
|
|
96
|
+
*/
|
|
97
|
+
async addRoutes(app) {
|
|
98
|
+
const path = process.env.SILEX_CLIENT_CONFIG;
|
|
99
|
+
if (path) {
|
|
100
|
+
console.log(`> Serving client side config ${path} at ${constants_1.CLIENT_CONFIG_FILE_NAME}`);
|
|
101
|
+
// Load the client config file
|
|
102
|
+
let clientConfig = (await (0, promises_1.readFile)(path)).toString();
|
|
103
|
+
// Serve the config file
|
|
104
|
+
app.get(`/${constants_1.CLIENT_CONFIG_FILE_NAME}`, async (req, res) => {
|
|
105
|
+
// Reload each time in debug mode
|
|
106
|
+
if (this.debug) {
|
|
107
|
+
console.log('[Debug mode] Reloading config file', path);
|
|
108
|
+
clientConfig = (await (0, promises_1.readFile)(path)).toString();
|
|
109
|
+
}
|
|
110
|
+
// Send the config file
|
|
111
|
+
res.json(clientConfig);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Load config files
|
|
117
|
+
* This is the main config file and the user config file
|
|
118
|
+
*/
|
|
119
|
+
async loadConfigFiles() {
|
|
120
|
+
// Load the user config file
|
|
121
|
+
await loadUserConfig(this);
|
|
122
|
+
// Load the main config file
|
|
123
|
+
await loadSilexConfig(this);
|
|
124
|
+
}
|
|
22
125
|
}
|
|
23
126
|
exports.ServerConfig = ServerConfig;
|
|
24
|
-
async function
|
|
25
|
-
|
|
127
|
+
// Get config async function
|
|
128
|
+
function createConfig() {
|
|
129
|
+
const port = process.env.PORT || '6805'; // 6805 is the date of sexual revolution started in paris france 8-)
|
|
26
130
|
const debug = process.env.SILEX_DEBUG === 'true';
|
|
27
|
-
const clientConfigPath = process.env.SILEX_CLIENT_CONFIG;
|
|
28
131
|
const url = process.env.SERVER_URL || `http://localhost:${port}`;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (config.debug) {
|
|
38
|
-
console.log('[Debug mode] Reloading config file', clientConfigPath);
|
|
39
|
-
clientConfig = (await (0, promises_1.readFile)(clientConfigPath)).toString();
|
|
40
|
-
}
|
|
41
|
-
req.header('Content-Type', 'application/javascript').send(clientConfig);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
132
|
+
return new ServerConfig(url, debug, port, '/api');
|
|
133
|
+
}
|
|
134
|
+
exports.createConfig = createConfig;
|
|
135
|
+
/**
|
|
136
|
+
* Load user config file
|
|
137
|
+
* This is the config file passed as env var CONFIG
|
|
138
|
+
*/
|
|
139
|
+
async function loadUserConfig(config) {
|
|
45
140
|
if (process.env.CONFIG) {
|
|
46
141
|
const userConfigPath = process.env.CONFIG;
|
|
47
142
|
console.log('> Loading user config', userConfigPath);
|
|
48
143
|
try {
|
|
144
|
+
// Initiate the process with the config file which is just another plugin
|
|
49
145
|
await config.addPlugin(userConfigPath, {});
|
|
50
146
|
}
|
|
51
147
|
catch (e) {
|
|
52
148
|
throw new Error(`User config file ${userConfigPath} error: ${e.message}`);
|
|
53
149
|
}
|
|
54
150
|
}
|
|
151
|
+
}
|
|
152
|
+
exports.loadUserConfig = loadUserConfig;
|
|
153
|
+
/**
|
|
154
|
+
* Load .silex.js in the root folder
|
|
155
|
+
* This is the main config file
|
|
156
|
+
*/
|
|
157
|
+
async function loadSilexConfig(config) {
|
|
55
158
|
const configFilePath = (0, path_1.resolve)(__dirname, '../../.silex.js');
|
|
56
159
|
console.log('> Loading config', configFilePath);
|
|
57
160
|
try {
|
|
161
|
+
// Initiate the process with the config file which is just another plugin
|
|
58
162
|
await config.addPlugin(configFilePath, {});
|
|
59
163
|
}
|
|
60
164
|
catch (e) {
|
|
@@ -65,6 +169,6 @@ async function default_1() {
|
|
|
65
169
|
throw new Error(`Error in config file ${configFilePath}: ${e.message}`);
|
|
66
170
|
}
|
|
67
171
|
}
|
|
68
|
-
return config;
|
|
69
172
|
}
|
|
70
|
-
exports.
|
|
173
|
+
exports.loadSilexConfig = loadSilexConfig;
|
|
174
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/ts/server/config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH;;;GAGG;AAEH;;GAEG;AAEH,4DAAyD;AACzD,+BAA8B;AAC9B,4CAAsD;AAEtD,0CAAsC;AACtC,yCAA4E;AAC5E,oDAAgD;AAEhD,oCAAsC;AAEtC;;GAEG;AACH,MAAa,YAAa,SAAQ,sBAAM;IAS7B;IACA;IACA;IACA;IAXF,cAAc,GAAG;QACtB,SAAS,EAAE,OAAO,CAAC,GAA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