@qwickapps/server 1.0.0 → 1.1.6
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/README.md +178 -79
- package/dist/core/control-panel.d.ts.map +1 -1
- package/dist/core/control-panel.js +37 -42
- package/dist/core/control-panel.js.map +1 -1
- package/dist/core/gateway.d.ts +32 -13
- package/dist/core/gateway.d.ts.map +1 -1
- package/dist/core/gateway.js +144 -81
- package/dist/core/gateway.js.map +1 -1
- package/dist/core/guards.d.ts +22 -0
- package/dist/core/guards.d.ts.map +1 -0
- package/dist/core/guards.js +167 -0
- package/dist/core/guards.js.map +1 -0
- package/dist/core/types.d.ts +104 -11
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins/frontend-app-plugin.d.ts +39 -0
- package/dist/plugins/frontend-app-plugin.d.ts.map +1 -0
- package/dist/plugins/frontend-app-plugin.js +176 -0
- package/dist/plugins/frontend-app-plugin.js.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/index.js.map +1 -1
- package/package.json +7 -2
- package/src/core/control-panel.ts +41 -50
- package/src/core/gateway.ts +186 -105
- package/src/core/guards.ts +190 -0
- package/src/core/types.ts +115 -9
- package/src/index.ts +18 -0
- package/src/plugins/frontend-app-plugin.ts +211 -0
- package/src/plugins/index.ts +3 -0
package/dist/core/gateway.js
CHANGED
|
@@ -17,56 +17,101 @@
|
|
|
17
17
|
import { createControlPanel } from './control-panel.js';
|
|
18
18
|
import { initializeLogging, getControlPanelLogger } from './logging.js';
|
|
19
19
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
20
|
-
import { randomBytes } from 'crypto';
|
|
21
20
|
import express from 'express';
|
|
22
21
|
import { existsSync } from 'fs';
|
|
23
22
|
import { resolve } from 'path';
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
26
|
-
* - Skips localhost requests
|
|
27
|
-
* - Skips API routes (/api/v1/*) - they have their own service auth
|
|
28
|
-
* - Skips health endpoints - these should be public
|
|
29
|
-
* - Requires valid credentials for non-localhost control panel access
|
|
24
|
+
* Generate landing page HTML for the frontend app
|
|
30
25
|
*/
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
26
|
+
function generateLandingPageHtml(config, controlPanelPath) {
|
|
27
|
+
if (!config)
|
|
28
|
+
return '';
|
|
29
|
+
const primaryColor = '#6366f1';
|
|
30
|
+
const links = config.links || [
|
|
31
|
+
{ label: 'Control Panel', url: controlPanelPath },
|
|
32
|
+
];
|
|
33
|
+
const linksHtml = links
|
|
34
|
+
.map((link) => `<a href="${link.url}" class="link">${link.label}</a>`)
|
|
35
|
+
.join('');
|
|
36
|
+
return `<!DOCTYPE html>
|
|
37
|
+
<html lang="en">
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="UTF-8">
|
|
40
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
41
|
+
<title>${config.title}</title>
|
|
42
|
+
<style>
|
|
43
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
44
|
+
body {
|
|
45
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
46
|
+
background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
|
|
47
|
+
color: #e2e8f0;
|
|
48
|
+
min-height: 100vh;
|
|
49
|
+
display: flex;
|
|
50
|
+
align-items: center;
|
|
51
|
+
justify-content: center;
|
|
52
|
+
}
|
|
53
|
+
.container {
|
|
54
|
+
text-align: center;
|
|
55
|
+
max-width: 600px;
|
|
56
|
+
padding: 2rem;
|
|
57
|
+
}
|
|
58
|
+
h1 {
|
|
59
|
+
font-size: 2.5rem;
|
|
60
|
+
color: ${primaryColor};
|
|
61
|
+
margin-bottom: 1rem;
|
|
62
|
+
}
|
|
63
|
+
p {
|
|
64
|
+
font-size: 1.125rem;
|
|
65
|
+
color: #94a3b8;
|
|
66
|
+
margin-bottom: 2rem;
|
|
67
|
+
line-height: 1.6;
|
|
68
|
+
}
|
|
69
|
+
.links {
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-wrap: wrap;
|
|
72
|
+
gap: 1rem;
|
|
73
|
+
justify-content: center;
|
|
74
|
+
}
|
|
75
|
+
.link {
|
|
76
|
+
display: inline-block;
|
|
77
|
+
padding: 0.875rem 2rem;
|
|
78
|
+
background: ${primaryColor};
|
|
79
|
+
color: white;
|
|
80
|
+
text-decoration: none;
|
|
81
|
+
border-radius: 0.5rem;
|
|
82
|
+
font-weight: 500;
|
|
83
|
+
transition: all 0.2s;
|
|
84
|
+
}
|
|
85
|
+
.link:hover {
|
|
86
|
+
transform: translateY(-2px);
|
|
87
|
+
box-shadow: 0 10px 20px rgba(0,0,0,0.3);
|
|
88
|
+
}
|
|
89
|
+
.footer {
|
|
90
|
+
position: fixed;
|
|
91
|
+
bottom: 1rem;
|
|
92
|
+
left: 0;
|
|
93
|
+
right: 0;
|
|
94
|
+
text-align: center;
|
|
95
|
+
color: #64748b;
|
|
96
|
+
font-size: 0.875rem;
|
|
97
|
+
}
|
|
98
|
+
.footer a {
|
|
99
|
+
color: ${primaryColor};
|
|
100
|
+
text-decoration: none;
|
|
101
|
+
}
|
|
102
|
+
</style>
|
|
103
|
+
</head>
|
|
104
|
+
<body>
|
|
105
|
+
<div class="container">
|
|
106
|
+
<h1>${config.heading || config.title}</h1>
|
|
107
|
+
${config.description ? `<p>${config.description}</p>` : ''}
|
|
108
|
+
${linksHtml ? `<div class="links">${linksHtml}</div>` : ''}
|
|
109
|
+
</div>
|
|
110
|
+
<div class="footer">
|
|
111
|
+
Powered by <a href="https://qwickapps.com" target="_blank">QwickApps</a>
|
|
112
|
+
</div>
|
|
113
|
+
</body>
|
|
114
|
+
</html>`;
|
|
70
115
|
}
|
|
71
116
|
/**
|
|
72
117
|
* Create a gateway that proxies to an internal service
|
|
@@ -110,12 +155,10 @@ export function createGateway(config, serviceFactory) {
|
|
|
110
155
|
const gatewayPort = config.gatewayPort || parseInt(process.env.GATEWAY_PORT || process.env.PORT || '3101', 10);
|
|
111
156
|
const servicePort = config.servicePort || parseInt(process.env.SERVICE_PORT || '3100', 10);
|
|
112
157
|
const nodeEnv = process.env.NODE_ENV || 'development';
|
|
113
|
-
//
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
const basicAuthPassword = providedPassword || (authMode === 'auto' ? randomBytes(16).toString('base64url') : '');
|
|
118
|
-
const isPasswordAutoGenerated = !providedPassword && authMode === 'auto';
|
|
158
|
+
// Control panel mount path (defaults to /cpanel)
|
|
159
|
+
const controlPanelPath = config.controlPanelPath || '/cpanel';
|
|
160
|
+
// Guard configuration for control panel
|
|
161
|
+
const guardConfig = config.controlPanelGuard;
|
|
119
162
|
// API paths to proxy
|
|
120
163
|
const proxyPaths = config.proxyPaths || ['/api/v1'];
|
|
121
164
|
let service = null;
|
|
@@ -129,17 +172,17 @@ export function createGateway(config, serviceFactory) {
|
|
|
129
172
|
cors: config.corsOrigins ? { origins: config.corsOrigins } : undefined,
|
|
130
173
|
// Skip body parsing for proxied paths
|
|
131
174
|
skipBodyParserPaths: [...proxyPaths, '/health'],
|
|
132
|
-
//
|
|
133
|
-
|
|
175
|
+
// Mount path for control panel
|
|
176
|
+
mountPath: controlPanelPath,
|
|
177
|
+
// Route guard
|
|
178
|
+
guard: guardConfig,
|
|
179
|
+
// Custom UI path
|
|
180
|
+
customUiPath: config.customUiPath,
|
|
134
181
|
links: config.links,
|
|
135
182
|
},
|
|
136
183
|
plugins: config.plugins || [],
|
|
137
184
|
logger,
|
|
138
185
|
});
|
|
139
|
-
// Add basic auth middleware if enabled
|
|
140
|
-
if (authMode === 'basic' || authMode === 'auto') {
|
|
141
|
-
controlPanel.app.use(createBasicAuthMiddleware(basicAuthUser, basicAuthPassword, proxyPaths));
|
|
142
|
-
}
|
|
143
186
|
// Setup proxy middleware for API paths
|
|
144
187
|
const setupProxyMiddleware = () => {
|
|
145
188
|
const target = `http://localhost:${servicePort}`;
|
|
@@ -185,17 +228,36 @@ export function createGateway(config, serviceFactory) {
|
|
|
185
228
|
};
|
|
186
229
|
controlPanel.app.use(createProxyMiddleware(healthProxyOptions));
|
|
187
230
|
};
|
|
188
|
-
//
|
|
189
|
-
const
|
|
190
|
-
if (config.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
res.
|
|
231
|
+
// Setup frontend app at root path
|
|
232
|
+
const setupFrontendApp = () => {
|
|
233
|
+
if (!config.frontendApp) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const { redirectUrl, staticPath, landingPage } = config.frontendApp;
|
|
237
|
+
// Priority 1: Redirect
|
|
238
|
+
if (redirectUrl) {
|
|
239
|
+
logger.info(`Frontend app: Redirecting / to ${redirectUrl}`);
|
|
240
|
+
controlPanel.app.get('/', (_req, res) => {
|
|
241
|
+
res.redirect(redirectUrl);
|
|
242
|
+
});
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
// Priority 2: Serve static files
|
|
246
|
+
if (staticPath && existsSync(staticPath)) {
|
|
247
|
+
logger.info(`Frontend app: Serving static files from ${staticPath}`);
|
|
248
|
+
controlPanel.app.use('/', express.static(staticPath));
|
|
249
|
+
// SPA fallback for root
|
|
250
|
+
controlPanel.app.get('/', (_req, res) => {
|
|
251
|
+
res.sendFile(resolve(staticPath, 'index.html'));
|
|
252
|
+
});
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
// Priority 3: Landing page
|
|
256
|
+
if (landingPage) {
|
|
257
|
+
logger.info(`Frontend app: Serving landing page`);
|
|
258
|
+
controlPanel.app.get('/', (_req, res) => {
|
|
259
|
+
const html = generateLandingPageHtml(landingPage, controlPanelPath);
|
|
260
|
+
res.type('html').send(html);
|
|
199
261
|
});
|
|
200
262
|
}
|
|
201
263
|
};
|
|
@@ -207,10 +269,12 @@ export function createGateway(config, serviceFactory) {
|
|
|
207
269
|
logger.info(`Internal service started on port ${servicePort}`);
|
|
208
270
|
// 2. Setup proxy middleware (after service is started)
|
|
209
271
|
setupProxyMiddleware();
|
|
210
|
-
// 3. Setup
|
|
211
|
-
|
|
272
|
+
// 3. Setup frontend app at root path
|
|
273
|
+
setupFrontendApp();
|
|
212
274
|
// 4. Start control panel gateway
|
|
213
275
|
await controlPanel.start();
|
|
276
|
+
// Calculate API base path
|
|
277
|
+
const apiBasePath = controlPanelPath === '/' ? '/api' : `${controlPanelPath}/api`;
|
|
214
278
|
// Log startup info
|
|
215
279
|
logger.info('');
|
|
216
280
|
logger.info('========================================');
|
|
@@ -220,26 +284,25 @@ export function createGateway(config, serviceFactory) {
|
|
|
220
284
|
logger.info(` Gateway Port: ${gatewayPort} (public)`);
|
|
221
285
|
logger.info(` Service Port: ${servicePort} (internal)`);
|
|
222
286
|
logger.info('');
|
|
223
|
-
if (
|
|
287
|
+
if (guardConfig && guardConfig.type === 'basic') {
|
|
224
288
|
logger.info(' Control Panel Auth: HTTP Basic Auth');
|
|
225
289
|
logger.info(' ----------------------------------------');
|
|
226
|
-
logger.info(` Username: ${
|
|
227
|
-
if (isPasswordAutoGenerated) {
|
|
228
|
-
logger.info(` Password: ${basicAuthPassword}`);
|
|
229
|
-
logger.info(' (auto-generated, set BASIC_AUTH_PASSWORD to use a fixed password)');
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
logger.info(' Password: ********** (from environment)');
|
|
233
|
-
}
|
|
290
|
+
logger.info(` Username: ${guardConfig.username}`);
|
|
234
291
|
logger.info(' ----------------------------------------');
|
|
235
292
|
}
|
|
293
|
+
else if (guardConfig && guardConfig.type !== 'none') {
|
|
294
|
+
logger.info(` Control Panel Auth: ${guardConfig.type}`);
|
|
295
|
+
}
|
|
236
296
|
else {
|
|
237
297
|
logger.info(' Control Panel Auth: None (not recommended)');
|
|
238
298
|
}
|
|
239
299
|
logger.info('');
|
|
240
300
|
logger.info(' Endpoints:');
|
|
241
|
-
|
|
242
|
-
|
|
301
|
+
if (config.frontendApp) {
|
|
302
|
+
logger.info(` GET / - Frontend App`);
|
|
303
|
+
}
|
|
304
|
+
logger.info(` GET ${controlPanelPath.padEnd(20)} - Control Panel UI`);
|
|
305
|
+
logger.info(` GET ${apiBasePath}/health - Gateway health`);
|
|
243
306
|
logger.info(` GET /health - Service health (proxied)`);
|
|
244
307
|
for (const apiPath of proxyPaths) {
|
|
245
308
|
logger.info(` * ${apiPath}/* - Service API (proxied)`);
|
package/dist/core/gateway.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/core/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAsB,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAgB,MAAM,uBAAuB,CAAC;AAC5E,OAAO,
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route Guards for @qwickapps/server
|
|
3
|
+
*
|
|
4
|
+
* Provides authentication middleware for protecting routes.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
7
|
+
*/
|
|
8
|
+
import type { Request, RequestHandler } from 'express';
|
|
9
|
+
import type { RouteGuardConfig } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create a route guard middleware from configuration
|
|
12
|
+
*/
|
|
13
|
+
export declare function createRouteGuard(config: RouteGuardConfig): RequestHandler;
|
|
14
|
+
/**
|
|
15
|
+
* Helper to check if a request is authenticated (for use in handlers)
|
|
16
|
+
*/
|
|
17
|
+
export declare function isAuthenticated(req: Request): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Get the authenticated user from the request
|
|
20
|
+
*/
|
|
21
|
+
export declare function getAuthenticatedUser(req: Request): any | null;
|
|
22
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/core/guards.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAA0B,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAazE;AAiID;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAUrD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,GAAG,IAAI,CAU7D"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route Guards for @qwickapps/server
|
|
3
|
+
*
|
|
4
|
+
* Provides authentication middleware for protecting routes.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Create a route guard middleware from configuration
|
|
10
|
+
*/
|
|
11
|
+
export function createRouteGuard(config) {
|
|
12
|
+
switch (config.type) {
|
|
13
|
+
case 'none':
|
|
14
|
+
return (_req, _res, next) => next();
|
|
15
|
+
case 'basic':
|
|
16
|
+
return createBasicAuthGuard(config);
|
|
17
|
+
case 'supabase':
|
|
18
|
+
return createSupabaseGuard(config);
|
|
19
|
+
case 'auth0':
|
|
20
|
+
return createAuth0Guard(config);
|
|
21
|
+
default:
|
|
22
|
+
throw new Error(`Unknown guard type: ${config.type}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create basic auth guard middleware
|
|
27
|
+
*/
|
|
28
|
+
function createBasicAuthGuard(config) {
|
|
29
|
+
const expectedAuth = `Basic ${Buffer.from(`${config.username}:${config.password}`).toString('base64')}`;
|
|
30
|
+
const realm = config.realm || 'Protected';
|
|
31
|
+
const excludePaths = config.excludePaths || [];
|
|
32
|
+
return (req, res, next) => {
|
|
33
|
+
// Check if path is excluded
|
|
34
|
+
if (excludePaths.some(path => req.path.startsWith(path))) {
|
|
35
|
+
return next();
|
|
36
|
+
}
|
|
37
|
+
const authHeader = req.headers.authorization;
|
|
38
|
+
if (authHeader === expectedAuth) {
|
|
39
|
+
return next();
|
|
40
|
+
}
|
|
41
|
+
res.setHeader('WWW-Authenticate', `Basic realm="${realm}"`);
|
|
42
|
+
res.status(401).json({
|
|
43
|
+
error: 'Unauthorized',
|
|
44
|
+
message: 'Authentication required.',
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create Supabase auth guard middleware
|
|
50
|
+
*
|
|
51
|
+
* Validates JWT tokens from Supabase Auth
|
|
52
|
+
*/
|
|
53
|
+
function createSupabaseGuard(config) {
|
|
54
|
+
const excludePaths = config.excludePaths || [];
|
|
55
|
+
return async (req, res, next) => {
|
|
56
|
+
// Check if path is excluded
|
|
57
|
+
if (excludePaths.some(path => req.path.startsWith(path))) {
|
|
58
|
+
return next();
|
|
59
|
+
}
|
|
60
|
+
const authHeader = req.headers.authorization;
|
|
61
|
+
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
62
|
+
return res.status(401).json({
|
|
63
|
+
error: 'Unauthorized',
|
|
64
|
+
message: 'Missing or invalid authorization header. Expected: Bearer <token>',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const token = authHeader.substring(7);
|
|
68
|
+
try {
|
|
69
|
+
// Validate the JWT with Supabase
|
|
70
|
+
const response = await fetch(`${config.supabaseUrl}/auth/v1/user`, {
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: `Bearer ${token}`,
|
|
73
|
+
apikey: config.supabaseAnonKey,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
return res.status(401).json({
|
|
78
|
+
error: 'Unauthorized',
|
|
79
|
+
message: 'Invalid or expired token.',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const user = await response.json();
|
|
83
|
+
req.user = user;
|
|
84
|
+
next();
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return res.status(401).json({
|
|
88
|
+
error: 'Unauthorized',
|
|
89
|
+
message: 'Failed to validate token.',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create Auth0 guard middleware
|
|
96
|
+
*
|
|
97
|
+
* Uses express-openid-connect for Auth0 authentication
|
|
98
|
+
*/
|
|
99
|
+
function createAuth0Guard(config) {
|
|
100
|
+
// Lazy-load express-openid-connect to avoid requiring it when not used
|
|
101
|
+
let authMiddleware = null;
|
|
102
|
+
return async (req, res, next) => {
|
|
103
|
+
// Lazy initialize the middleware
|
|
104
|
+
if (!authMiddleware) {
|
|
105
|
+
try {
|
|
106
|
+
const { auth } = await import('express-openid-connect');
|
|
107
|
+
authMiddleware = auth({
|
|
108
|
+
authRequired: true,
|
|
109
|
+
auth0Logout: true,
|
|
110
|
+
secret: config.secret,
|
|
111
|
+
baseURL: config.baseUrl,
|
|
112
|
+
clientID: config.clientId,
|
|
113
|
+
issuerBaseURL: `https://${config.domain}`,
|
|
114
|
+
clientSecret: config.clientSecret,
|
|
115
|
+
idpLogout: true,
|
|
116
|
+
routes: {
|
|
117
|
+
login: config.routes?.login || '/login',
|
|
118
|
+
logout: config.routes?.logout || '/logout',
|
|
119
|
+
callback: config.routes?.callback || '/callback',
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return res.status(500).json({
|
|
125
|
+
error: 'Configuration Error',
|
|
126
|
+
message: 'Auth0 is not properly configured. Install express-openid-connect package.',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Check if path is excluded
|
|
131
|
+
const excludePaths = config.excludePaths || [];
|
|
132
|
+
if (excludePaths.some(path => req.path.startsWith(path))) {
|
|
133
|
+
return next();
|
|
134
|
+
}
|
|
135
|
+
// Apply Auth0 middleware
|
|
136
|
+
authMiddleware(req, res, next);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Helper to check if a request is authenticated (for use in handlers)
|
|
141
|
+
*/
|
|
142
|
+
export function isAuthenticated(req) {
|
|
143
|
+
// Check for Auth0 session
|
|
144
|
+
if (req.oidc?.isAuthenticated?.()) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
// Check for Supabase user
|
|
148
|
+
if (req.user) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get the authenticated user from the request
|
|
155
|
+
*/
|
|
156
|
+
export function getAuthenticatedUser(req) {
|
|
157
|
+
// Check for Auth0 user
|
|
158
|
+
if (req.oidc?.user) {
|
|
159
|
+
return req.oidc.user;
|
|
160
|
+
}
|
|
161
|
+
// Check for Supabase user
|
|
162
|
+
if (req.user) {
|
|
163
|
+
return req.user;
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/core/guards.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAwB;IACvD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,MAAM;YACT,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;QACtC,KAAK,OAAO;YACV,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACtC,KAAK,UAAU;YACb,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACrC,KAAK,OAAO;YACV,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAClC;YACE,MAAM,IAAI,KAAK,CAAC,uBAAwB,MAAc,CAAC,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAC,MAA4B;IACxD,MAAM,YAAY,GAAG,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxG,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,WAAW,CAAC;IAC1C,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAE/C,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,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B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAY;IAC/C,uBAAuB;IACvB,IAAK,GAAW,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;QAC5B,OAAQ,GAAW,CAAC,IAAI,CAAC,IAAI,CAAC;IAChC,CAAC;IACD,0BAA0B;IAC1B,IAAK,GAAW,CAAC,IAAI,EAAE,CAAC;QACtB,OAAQ,GAAW,CAAC,IAAI,CAAC;IAC3B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -4,6 +4,100 @@
|
|
|
4
4
|
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
5
5
|
*/
|
|
6
6
|
import type { Application, RequestHandler, Router } from 'express';
|
|
7
|
+
/**
|
|
8
|
+
* Route guard types for protecting routes
|
|
9
|
+
*/
|
|
10
|
+
export type RouteGuardType = 'none' | 'basic' | 'supabase' | 'auth0';
|
|
11
|
+
/**
|
|
12
|
+
* Basic auth guard configuration
|
|
13
|
+
*/
|
|
14
|
+
export interface BasicAuthGuardConfig {
|
|
15
|
+
type: 'basic';
|
|
16
|
+
/** Username for basic auth */
|
|
17
|
+
username: string;
|
|
18
|
+
/** Password for basic auth */
|
|
19
|
+
password: string;
|
|
20
|
+
/** Realm name for the WWW-Authenticate header */
|
|
21
|
+
realm?: string;
|
|
22
|
+
/** Paths to exclude from authentication (e.g., ['/health']) */
|
|
23
|
+
excludePaths?: string[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Supabase auth guard configuration
|
|
27
|
+
*/
|
|
28
|
+
export interface SupabaseAuthGuardConfig {
|
|
29
|
+
type: 'supabase';
|
|
30
|
+
/** Supabase project URL */
|
|
31
|
+
supabaseUrl: string;
|
|
32
|
+
/** Supabase anon key */
|
|
33
|
+
supabaseAnonKey: string;
|
|
34
|
+
/** Paths to exclude from authentication */
|
|
35
|
+
excludePaths?: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Auth0 guard configuration
|
|
39
|
+
*/
|
|
40
|
+
export interface Auth0GuardConfig {
|
|
41
|
+
type: 'auth0';
|
|
42
|
+
/** Auth0 domain (e.g., 'myapp.auth0.com') */
|
|
43
|
+
domain: string;
|
|
44
|
+
/** Auth0 client ID */
|
|
45
|
+
clientId: string;
|
|
46
|
+
/** Auth0 client secret */
|
|
47
|
+
clientSecret: string;
|
|
48
|
+
/** Base URL of the application */
|
|
49
|
+
baseUrl: string;
|
|
50
|
+
/** Session secret for cookie encryption */
|
|
51
|
+
secret: string;
|
|
52
|
+
/** Auth routes configuration */
|
|
53
|
+
routes?: {
|
|
54
|
+
login?: string;
|
|
55
|
+
logout?: string;
|
|
56
|
+
callback?: string;
|
|
57
|
+
};
|
|
58
|
+
/** Paths to exclude from authentication */
|
|
59
|
+
excludePaths?: string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* No authentication guard
|
|
63
|
+
*/
|
|
64
|
+
export interface NoAuthGuardConfig {
|
|
65
|
+
type: 'none';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Union type for all guard configurations
|
|
69
|
+
*/
|
|
70
|
+
export type RouteGuardConfig = NoAuthGuardConfig | BasicAuthGuardConfig | SupabaseAuthGuardConfig | Auth0GuardConfig;
|
|
71
|
+
/**
|
|
72
|
+
* Mount path configuration for applications
|
|
73
|
+
*/
|
|
74
|
+
export interface MountConfig {
|
|
75
|
+
/** Path where this app is mounted (e.g., '/', '/cpanel', '/app') */
|
|
76
|
+
path: string;
|
|
77
|
+
/** Route guard configuration for this mount point */
|
|
78
|
+
guard?: RouteGuardConfig;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Frontend app configuration
|
|
82
|
+
*/
|
|
83
|
+
export interface FrontendAppConfig {
|
|
84
|
+
/** Mount configuration */
|
|
85
|
+
mount: MountConfig;
|
|
86
|
+
/** Redirect to another URL instead of serving content */
|
|
87
|
+
redirectUrl?: string;
|
|
88
|
+
/** Path to static files to serve */
|
|
89
|
+
staticPath?: string;
|
|
90
|
+
/** Landing page HTML (used if no staticPath or redirectUrl) */
|
|
91
|
+
landingPage?: {
|
|
92
|
+
title: string;
|
|
93
|
+
heading?: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
links?: Array<{
|
|
96
|
+
label: string;
|
|
97
|
+
url: string;
|
|
98
|
+
}>;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
7
101
|
/**
|
|
8
102
|
* Control Panel Configuration
|
|
9
103
|
*/
|
|
@@ -20,17 +114,16 @@ export interface ControlPanelConfig {
|
|
|
20
114
|
primaryColor?: string;
|
|
21
115
|
favicon?: string;
|
|
22
116
|
};
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
117
|
+
/**
|
|
118
|
+
* Mount path for the control panel.
|
|
119
|
+
* Defaults to '/cpanel'.
|
|
120
|
+
*/
|
|
121
|
+
mountPath?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Route guard for the control panel.
|
|
124
|
+
* Defaults to basic auth in production.
|
|
125
|
+
*/
|
|
126
|
+
guard?: RouteGuardConfig;
|
|
34
127
|
/** Optional: CORS configuration */
|
|
35
128
|
cors?: {
|
|
36
129
|
origins: string[];
|