waibu 2.7.0 → 2.8.0
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/extend/bajo/intl/en-US.json +3 -1
- package/extend/bajo/intl/id.json +3 -1
- package/index.js +0 -31
- package/lib/handle-error.js +5 -1
- package/lib/handle-not-found.js +12 -4
- package/lib/template/404.html +9 -0
- package/lib/template/500.html +9 -0
- package/package.json +1 -1
- package/wiki/CHANGES.md +12 -0
- package/extend/bajoTemplate/layout/email.html +0 -17
- package/extend/bajoTemplate/layout/email.id.html +0 -18
|
@@ -15,5 +15,7 @@
|
|
|
15
15
|
"middlewareDisabled%s": "Middleware '%s' is disabled",
|
|
16
16
|
"httpResp%s%s%s%s%s": "%s %s%s with a %s-status took %sms",
|
|
17
17
|
"httpReq%s%s%s%s": "%s %s%s from IP %s",
|
|
18
|
-
"httpReqExt%s": ", content length: %s"
|
|
18
|
+
"httpReqExt%s": ", content length: %s",
|
|
19
|
+
"internalServerError": "Internal Server Error",
|
|
20
|
+
"pageNotFound": "Page Not Found"
|
|
19
21
|
}
|
package/extend/bajo/intl/id.json
CHANGED
|
@@ -15,5 +15,7 @@
|
|
|
15
15
|
"middlewareDisabled%s": "Middleware '%s' dimatikan",
|
|
16
16
|
"httpResp%s%s%s%s%s": "%s %s:%s dengan status %s selama %sms",
|
|
17
17
|
"httpReq%s%s%s%s": "%s %s:%s dari IP %s",
|
|
18
|
-
"httpReqExt%s": ", panjang konten: %s"
|
|
18
|
+
"httpReqExt%s": ", panjang konten: %s",
|
|
19
|
+
"internalServerError": "Kesalahan Internal Server",
|
|
20
|
+
"pageNotFound": "Halaman Tidak Ditemukan"
|
|
19
21
|
}
|
package/index.js
CHANGED
|
@@ -12,7 +12,6 @@ import handleFavicon from './lib/handle-favicon.js'
|
|
|
12
12
|
import handleError from './lib/handle-error.js'
|
|
13
13
|
import handleNotFound from './lib/handle-not-found.js'
|
|
14
14
|
import handleHome from './lib/handle-home.js'
|
|
15
|
-
import buildLocals from './lib/build-locals.js'
|
|
16
15
|
import queryString from 'query-string'
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -502,36 +501,6 @@ async function factory (pkgName) {
|
|
|
502
501
|
return url
|
|
503
502
|
}
|
|
504
503
|
|
|
505
|
-
/**
|
|
506
|
-
* Method to send mail through Masohi Messaging System. It is a thin wrapper
|
|
507
|
-
* for {@link https://github.com/ardhi/masohi-mail|masohi-mail} send method.
|
|
508
|
-
*
|
|
509
|
-
* If masohi is not loaded, nothing is delivered.
|
|
510
|
-
*
|
|
511
|
-
* @method
|
|
512
|
-
* @async
|
|
513
|
-
* @param {(string|Array)} tpl - Mail's template to use. If a string is given, the same template will be used for html & plaintext versions. Otherwise, the first template will be used for html mail, and the second one is for it's plaintext version
|
|
514
|
-
* @param {Object} [params={}] - {@link https://github.com/ardhi/masohi-mail|masohi-mail}'s params object.
|
|
515
|
-
* @returns
|
|
516
|
-
*/
|
|
517
|
-
sendMail = async (tpl, { to, cc, bcc, from, subject, data = {}, conn, source, options = {} }) => {
|
|
518
|
-
conn = conn ?? 'masohiMail:default'
|
|
519
|
-
if (!this.app.masohi || !this.app.masohiMail) return
|
|
520
|
-
const { get, isString } = this.app.lib._
|
|
521
|
-
const { generateId } = this.app.lib.aneka
|
|
522
|
-
const { render } = this.app.bajoTemplate
|
|
523
|
-
if (isString(tpl)) tpl = [tpl]
|
|
524
|
-
const locals = await buildLocals.call(this, { tpl, params: data, opts: options })
|
|
525
|
-
const opts = {
|
|
526
|
-
lang: get(options, 'req.lang'),
|
|
527
|
-
groupId: get(options, 'req.id', generateId())
|
|
528
|
-
}
|
|
529
|
-
const message = await render(tpl[0], locals, opts)
|
|
530
|
-
if (tpl[1]) opts.messageText = await render(tpl[1], locals, opts)
|
|
531
|
-
const payload = { type: 'object', data: { to, cc, bcc, from, subject, message, options: opts } }
|
|
532
|
-
await this.app.masohi.send({ payload, source: source ?? this.ns, conn }) // mail sent through worker
|
|
533
|
-
}
|
|
534
|
-
|
|
535
504
|
/**
|
|
536
505
|
* Recursively unescape block of texts
|
|
537
506
|
*
|
package/lib/handle-error.js
CHANGED
|
@@ -5,7 +5,11 @@ async function error (err, req, reply) {
|
|
|
5
5
|
this.log.error(err)
|
|
6
6
|
const resp = await interceptor.call(this, 'errorHandler', err, req, reply)
|
|
7
7
|
if (resp) return resp
|
|
8
|
-
|
|
8
|
+
const payload = {
|
|
9
|
+
text: this.app.log.getErrorMessage(err),
|
|
10
|
+
title: req.t('internalServerError')
|
|
11
|
+
}
|
|
12
|
+
return writeHtml.call(this, req, reply, `${this.ns}:/lib/template/500.html`, payload)
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
async function handleError () {
|
package/lib/handle-not-found.js
CHANGED
|
@@ -5,7 +5,7 @@ export function writeHtml (req, reply, tpl, payload) {
|
|
|
5
5
|
reply.header('Content-Type', 'text/html')
|
|
6
6
|
reply.header('Content-Language', req.lang)
|
|
7
7
|
const file = getPluginFile(tpl)
|
|
8
|
-
const content = fs.readFileSync(file)
|
|
8
|
+
const content = fs.readFileSync(file, 'utf8')
|
|
9
9
|
const compiled = template(content)
|
|
10
10
|
return compiled(payload)
|
|
11
11
|
}
|
|
@@ -14,9 +14,14 @@ export async function interceptor (name, err, req, reply) {
|
|
|
14
14
|
const { get, trim } = this.app.lib._
|
|
15
15
|
let webApp = get(req, 'routeOptions.config.webApp')
|
|
16
16
|
if (!webApp) {
|
|
17
|
-
const
|
|
17
|
+
const url = req.url ?? req.raw.url
|
|
18
|
+
const [prefix] = trim(url, '/').split('/')
|
|
18
19
|
webApp = this.getPluginByPrefix(prefix, true)
|
|
19
20
|
}
|
|
21
|
+
if (!webApp) {
|
|
22
|
+
const wa = this.webApps.find(item => item.prefix === '')
|
|
23
|
+
if (wa) webApp = wa.ns
|
|
24
|
+
}
|
|
20
25
|
if (webApp) {
|
|
21
26
|
const plugin = this.app[webApp]
|
|
22
27
|
const handler = get(plugin, `webAppFactory.${name}`)
|
|
@@ -59,8 +64,11 @@ export async function notFound (err, req, reply) {
|
|
|
59
64
|
reply.code(404)
|
|
60
65
|
const resp = await interceptor.call(this, 'notFoundHandler', err, req, reply)
|
|
61
66
|
if (resp) return resp
|
|
62
|
-
const
|
|
63
|
-
|
|
67
|
+
const payload = {
|
|
68
|
+
text: req.t('notFound%s%s', req.t('route'), req.url),
|
|
69
|
+
title: req.t('pageNotFound')
|
|
70
|
+
}
|
|
71
|
+
return writeHtml.call(this, req, reply, `${this.ns}:/lib/template/404.html`, payload)
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
async function handleNotFound () {
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-03-02
|
|
4
|
+
|
|
5
|
+
- [2.8.0] Remove ```sendMail()``` as from now on it will be using sumba's ```sendMail()```
|
|
6
|
+
- [2.8.0] Remove mail templates
|
|
7
|
+
|
|
8
|
+
## 2026-02-21
|
|
9
|
+
|
|
10
|
+
- [2.7.1] Bug fix on ```errorHandler```
|
|
11
|
+
- [2.7.1] Bug fix on ```notFoundHandler```
|
|
12
|
+
- [2.7.1] Add fallback template for both handlers above
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## 2026-02-20
|
|
4
16
|
|
|
5
17
|
- [2.7.0] Add ```req.te()``` decorator
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<head lang="<%= _meta.lang %>">
|
|
3
|
-
<meta charset="UTF-8">
|
|
4
|
-
<title><%= page.fullTitle %></title>
|
|
5
|
-
<style type="text/css">
|
|
6
|
-
</style>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<% if (arguments[0].firstName && arguments[0].lastName) { %>
|
|
10
|
-
<p>Dear <%= firstName %> <%= lastName %>,</p>
|
|
11
|
-
<% } %>
|
|
12
|
-
<!-- body -->
|
|
13
|
-
<p>Sincerely,</p>
|
|
14
|
-
|
|
15
|
-
<p><%= _meta.site.title %></p>
|
|
16
|
-
</body>
|
|
17
|
-
</html>
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="<%= _meta.lang %>">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<title><%= page.fullTitle %></title>
|
|
6
|
-
<style type="text/css">
|
|
7
|
-
</style>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<% if (arguments[0].firstName && arguments[0].lastName) { %>
|
|
11
|
-
<p>Yth <%= firstName %> <%= lastName %>,</p>
|
|
12
|
-
<% } %>
|
|
13
|
-
<!-- body -->
|
|
14
|
-
<p>Hormat kami,</p>
|
|
15
|
-
|
|
16
|
-
<p><%= _meta.site.title %></p>
|
|
17
|
-
</body>
|
|
18
|
-
</html>
|