webspresso 0.0.80 → 0.0.81
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 +91 -0
- package/bin/commands/doctor.js +83 -0
- package/bin/commands/favicon-generate.js +3 -1
- package/core/auth/hash.js +1 -1
- package/core/auth/index.js +30 -0
- package/core/auth/manager.js +190 -0
- package/core/auth/tokens.js +135 -0
- package/core/kernel/app.js +7 -1
- package/index.d.ts +32 -0
- package/index.js +2 -0
- package/package.json +5 -2
- package/plugins/admin-panel/field-renderers/file-upload.js +48 -2
- package/plugins/csrf/index.js +222 -0
- package/plugins/email/admin-component.js +226 -0
- package/plugins/email/api-handlers.js +139 -0
- package/plugins/email/auth-bridge.js +209 -0
- package/plugins/email/bundled-templates.js +68 -0
- package/plugins/email/fs-env.js +101 -0
- package/plugins/email/index.js +186 -0
- package/plugins/email/manifest.js +25 -0
- package/plugins/email/migration-template.js +40 -0
- package/plugins/email/purge.js +28 -0
- package/plugins/email/render.js +154 -0
- package/plugins/email/service.js +244 -0
- package/plugins/email/template-registry.js +134 -0
- package/plugins/email/templates/auth-email-verify.mjml +13 -0
- package/plugins/email/templates/auth-password-reset.mjml +13 -0
- package/plugins/email/templates/auth-welcome.mjml +11 -0
- package/plugins/email/transport.js +71 -0
- package/plugins/index.js +4 -0
- package/src/file-router.js +75 -0
- package/templates/skills/webspresso-usage/REFERENCE-framework.md +1 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nodemailer transport resolution
|
|
3
|
+
* @module plugins/email/transport
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
let nodemailer;
|
|
7
|
+
try {
|
|
8
|
+
nodemailer = require('nodemailer');
|
|
9
|
+
} catch {
|
|
10
|
+
nodemailer = null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Build SMTP config from env vars
|
|
15
|
+
* @returns {Object|null}
|
|
16
|
+
*/
|
|
17
|
+
function smtpFromEnv() {
|
|
18
|
+
const host = process.env.SMTP_HOST;
|
|
19
|
+
if (!host) return null;
|
|
20
|
+
|
|
21
|
+
const port = parseInt(process.env.SMTP_PORT || '587', 10);
|
|
22
|
+
const secure = process.env.SMTP_SECURE === 'true' || port === 465;
|
|
23
|
+
const user = process.env.SMTP_USER;
|
|
24
|
+
const pass = process.env.SMTP_PASS;
|
|
25
|
+
|
|
26
|
+
const config = { host, port, secure };
|
|
27
|
+
if (user && pass) {
|
|
28
|
+
config.auth = { user, pass };
|
|
29
|
+
}
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {Object} options
|
|
35
|
+
* @param {Object} [options.transport] - Pre-built nodemailer transport
|
|
36
|
+
* @param {Object} [options.smtp] - SMTP options
|
|
37
|
+
* @returns {Object} nodemailer transport
|
|
38
|
+
*/
|
|
39
|
+
function createTransport(options = {}) {
|
|
40
|
+
if (!nodemailer) {
|
|
41
|
+
throw new Error('nodemailer is required. Install it with: npm install nodemailer');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (options.transport) {
|
|
45
|
+
return options.transport;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const smtp = options.smtp || smtpFromEnv();
|
|
49
|
+
if (!smtp) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
'Email transport not configured. Pass transport/smtp options or set SMTP_HOST env variable.'
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return nodemailer.createTransport(smtp);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Default from address
|
|
60
|
+
* @param {Object} [defaults={}]
|
|
61
|
+
* @returns {string|undefined}
|
|
62
|
+
*/
|
|
63
|
+
function resolveDefaultFrom(defaults = {}) {
|
|
64
|
+
return defaults.from || process.env.MAIL_FROM || undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
createTransport,
|
|
69
|
+
smtpFromEnv,
|
|
70
|
+
resolveDefaultFrom,
|
|
71
|
+
};
|
package/plugins/index.js
CHANGED
|
@@ -21,7 +21,9 @@ const { uploadPlugin, createLocalFileProvider } = require('./upload');
|
|
|
21
21
|
const { dataExchangePlugin } = require('./data-exchange');
|
|
22
22
|
const { redirectPlugin } = require('./redirect');
|
|
23
23
|
const { rateLimitPlugin } = require('./rate-limit');
|
|
24
|
+
const emailPlugin = require('./email');
|
|
24
25
|
const contentPlugin = require('./content');
|
|
26
|
+
const csrfPlugin = require('./csrf');
|
|
25
27
|
|
|
26
28
|
module.exports = {
|
|
27
29
|
sitemapPlugin,
|
|
@@ -42,6 +44,8 @@ module.exports = {
|
|
|
42
44
|
dataExchangePlugin,
|
|
43
45
|
redirectPlugin,
|
|
44
46
|
rateLimitPlugin,
|
|
47
|
+
emailPlugin,
|
|
45
48
|
contentPlugin,
|
|
49
|
+
csrfPlugin,
|
|
46
50
|
};
|
|
47
51
|
|
package/src/file-router.js
CHANGED
|
@@ -644,6 +644,81 @@ function mountPages(app, options) {
|
|
|
644
644
|
|
|
645
645
|
// Get absolute path to pages directory
|
|
646
646
|
const absolutePagesDir = path.resolve(pagesDir);
|
|
647
|
+
|
|
648
|
+
// Routing and file-system checks at startup
|
|
649
|
+
function checkRoutesAtStartup() {
|
|
650
|
+
function getGenericSegment(name) {
|
|
651
|
+
if (name.startsWith('[') && name.endsWith(']')) {
|
|
652
|
+
const inner = name.slice(1, -1);
|
|
653
|
+
if (inner.startsWith('...')) return '*';
|
|
654
|
+
return ':param';
|
|
655
|
+
}
|
|
656
|
+
return name;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function checkDir(dirPath, relativeDir = '', isApi = false) {
|
|
660
|
+
if (!fs.existsSync(dirPath)) return;
|
|
661
|
+
const children = fs.readdirSync(dirPath);
|
|
662
|
+
const kept = [];
|
|
663
|
+
|
|
664
|
+
for (const child of children) {
|
|
665
|
+
if (child.startsWith('_') || child === 'locales') continue;
|
|
666
|
+
const fullPath = path.join(dirPath, child);
|
|
667
|
+
const relPath = relativeDir ? path.join(relativeDir, child) : child;
|
|
668
|
+
const stats = fs.statSync(fullPath);
|
|
669
|
+
|
|
670
|
+
// 1. Check case-sensitivity issues
|
|
671
|
+
if (child !== child.toLowerCase()) {
|
|
672
|
+
console.warn(`[webspresso] WARNING: Path "pages/${relPath.split(path.sep).join('/')}" contains uppercase letters. Use lowercase to avoid routing issues on case-sensitive filesystems.`);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
if (stats.isDirectory()) {
|
|
676
|
+
if (child === 'api' && relativeDir === '') {
|
|
677
|
+
checkDir(fullPath, relPath, true);
|
|
678
|
+
} else {
|
|
679
|
+
checkDir(fullPath, relPath, isApi);
|
|
680
|
+
if (!isApi) {
|
|
681
|
+
kept.push({ name: child, isDir: true, original: child });
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
} else {
|
|
685
|
+
const ext = path.extname(child);
|
|
686
|
+
if (isApi) {
|
|
687
|
+
if (ext === '.js') {
|
|
688
|
+
const base = path.basename(child, ext);
|
|
689
|
+
kept.push({ name: base, isDir: false, original: child });
|
|
690
|
+
}
|
|
691
|
+
} else {
|
|
692
|
+
if (ext === '.njk') {
|
|
693
|
+
const base = path.basename(child, ext);
|
|
694
|
+
kept.push({ name: base, isDir: false, original: child });
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// 2. Check dynamic route collisions
|
|
701
|
+
const groups = new Map();
|
|
702
|
+
for (const item of kept) {
|
|
703
|
+
const normalized = getGenericSegment(item.name);
|
|
704
|
+
if (!groups.has(normalized)) {
|
|
705
|
+
groups.set(normalized, []);
|
|
706
|
+
}
|
|
707
|
+
groups.get(normalized).push(item);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
for (const [norm, items] of groups.entries()) {
|
|
711
|
+
if (items.length > 1) {
|
|
712
|
+
const namesList = items.map(item => `"${item.original}"`).join(' and ');
|
|
713
|
+
console.warn(`[webspresso] WARNING: Dynamic route collision in "pages/${relativeDir.split(path.sep).join('/')}": ${namesList} resolve to the same segment "${norm}" and will conflict at runtime.`);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
checkDir(absolutePagesDir, '');
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
checkRoutesAtStartup();
|
|
647
722
|
|
|
648
723
|
// Load global hooks
|
|
649
724
|
const globalHooks = loadGlobalHooks(absolutePagesDir, isDev);
|
|
@@ -202,6 +202,7 @@ Pass **`db`** into **`createApp({ db })`** so **`ctx.db`** works in pages and pl
|
|
|
202
202
|
| `siteAnalyticsPlugin` | Self-hosted page views + admin charts |
|
|
203
203
|
| `auditLogPlugin` | Admin mutation audit trail |
|
|
204
204
|
| `recaptchaPlugin` | v2/v3 + middleware |
|
|
205
|
+
| `emailPlugin` | MJML + Nodemailer sending with optional admin UI and auth bridge |
|
|
205
206
|
| `seoCheckerPlugin` | Dev SEO panel |
|
|
206
207
|
| `restResourcePlugin` | Opt-in REST CRUD from models; `?include=` uses ORM eager load (single-level relations only) |
|
|
207
208
|
| `ormCacheAdminPlugin` | Admin page for ORM cache metrics / purge / invalidate (`db.cache` required) |
|