sumba 2.0.0 → 2.1.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/.github/FUNDING.yml +13 -0
- package/.github/workflows/repo-lockdown.yml +24 -0
- package/.jsdoc.conf.json +45 -0
- package/LICENSE +1 -1
- package/README.md +40 -7
- package/docs/Sumba.html +3 -0
- package/docs/data/search.json +1 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/global.html +3 -0
- package/docs/index.html +3 -0
- package/docs/index.js.html +538 -0
- package/docs/scripts/core.js +726 -0
- package/docs/scripts/core.min.js +23 -0
- package/docs/scripts/resize.js +90 -0
- package/docs/scripts/search.js +265 -0
- package/docs/scripts/search.min.js +6 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/scripts/third-party/hljs-original.js +5171 -0
- package/docs/scripts/third-party/hljs.js +1 -0
- package/docs/scripts/third-party/popper.js +5 -0
- package/docs/scripts/third-party/tippy.js +1 -0
- package/docs/scripts/third-party/tocbot.js +672 -0
- package/docs/scripts/third-party/tocbot.min.js +1 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/static/home.md +25 -0
- package/docs/static/logo-ecosystem.png +0 -0
- package/docs/static/logo.png +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/styles/clean-jsdoc-theme.min.css +1 -0
- package/extend/bajo/hook/{dobo.sumba-contact-form@after-record-create.js → dobo.sumba-contact-form@after-create-record.js} +3 -3
- package/extend/bajo/hook/{dobo.sumba-contact-form@before-record-create.js → dobo.sumba-contact-form@before-create-record.js} +3 -3
- package/extend/bajo/hook/{dobo.sumba-user@after-record-create.js → dobo.sumba-user@after-create-record.js} +3 -3
- package/extend/bajo/hook/dobo.sumba-user@after-record-validation.js +3 -3
- package/extend/bajo/hook/{dobo.sumba-user@after-record-update.js → dobo.sumba-user@after-update-record.js} +5 -5
- package/extend/bajo/hook/{dobo.sumba-user@before-record-create.js → dobo.sumba-user@before-create-record.js} +2 -2
- package/extend/bajo/hook/dobo.sumba-user@before-record-validation.js +3 -3
- package/extend/bajo/hook/{dobo.sumba-user@before-record-update.js → dobo.sumba-user@before-update-record.js} +2 -2
- package/extend/bajo/hook/dobo@before-count-record.js +8 -0
- package/extend/bajo/hook/{dobo@before-record-create.js → dobo@before-create-record.js} +6 -6
- package/extend/bajo/hook/dobo@before-find-one-record.js +8 -0
- package/extend/bajo/hook/{dobo@before-record-find.js → dobo@before-find-record.js} +10 -10
- package/extend/bajo/hook/dobo@before-get-record.js +23 -0
- package/extend/bajo/hook/dobo@before-remove-record.js +10 -0
- package/extend/bajo/hook/dobo@before-update-record.js +10 -0
- package/extend/bajo/hook/waibu-mpa.sumba@after-build-locals.js +0 -0
- package/extend/bajo/hook/waibu-mpa@pre-parsing.js +0 -0
- package/extend/bajo/hook/waibu-rest-api@pre-parsing.js +0 -0
- package/extend/bajo/hook/waibu-static@pre-parsing.js +0 -0
- package/extend/bajo/hook/waibu@after-app-boot.js +2 -2
- package/extend/bajo/hook/waibu@after-create-context.js +0 -0
- package/extend/bajo/hook/waibu@on-request.js +0 -0
- package/extend/bajo/intl/en-US.json +1 -0
- package/extend/bajo/intl/id.json +0 -0
- package/extend/bajoTemplate/layout/centered.html +0 -0
- package/extend/bajoTemplate/layout/default.html +0 -0
- package/extend/bajoTemplate/layout/error.html +0 -0
- package/extend/bajoTemplate/layout/info.html +0 -0
- package/extend/bajoTemplate/partial/403.html +0 -0
- package/extend/bajoTemplate/partial/_admin/reset-user-password.html +0 -0
- package/extend/bajoTemplate/partial/_mail/help-contact-form.html +0 -0
- package/extend/bajoTemplate/partial/_mail/help-contact-form.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/mystuff-change-password.html +0 -0
- package/extend/bajoTemplate/partial/_mail/mystuff-change-password.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/mystuff-reset-api-key.html +0 -0
- package/extend/bajoTemplate/partial/_mail/mystuff-reset-api-key.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-activation-success.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-activation-success.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-forgot-password-changed.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-forgot-password-changed.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-forgot-password-link.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-forgot-password-link.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-signup-success-active.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-signup-success-active.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-signup-success.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-signup-success.id.html +0 -0
- package/extend/bajoTemplate/partial/api-key-modal.html +0 -0
- package/extend/bajoTemplate/partial/app-launcher.html +0 -0
- package/extend/bajoTemplate/partial/help/contact-form/form.html +0 -0
- package/extend/bajoTemplate/partial/help/contact-form/success.html +0 -0
- package/extend/bajoTemplate/partial/help/trouble-tickets/add.html +0 -0
- package/extend/bajoTemplate/partial/help/trouble-tickets/details.html +0 -0
- package/extend/bajoTemplate/partial/help/trouble-tickets/list.html +0 -0
- package/extend/bajoTemplate/partial/layout/address.html +0 -0
- package/extend/bajoTemplate/partial/layout/breadcrumb.html +0 -0
- package/extend/bajoTemplate/partial/layout/footer.html +0 -0
- package/extend/bajoTemplate/partial/layout/more-info.html +0 -0
- package/extend/bajoTemplate/partial/layout/more-info.id.html +0 -0
- package/extend/bajoTemplate/partial/layout/navbar.html +0 -0
- package/extend/bajoTemplate/partial/layout/sidebar.html +0 -0
- package/extend/bajoTemplate/partial/layout/socmed.html +0 -0
- package/extend/bajoTemplate/partial/list-item/change-password.html +0 -0
- package/extend/bajoTemplate/partial/list-item/forgot-password.html +0 -0
- package/extend/bajoTemplate/partial/list-item/goto-home.html +0 -0
- package/extend/bajoTemplate/partial/list-item/member-links.html +0 -0
- package/extend/bajoTemplate/partial/list-item/oauth-signin.html +0 -0
- package/extend/bajoTemplate/partial/list-item/signin.html +0 -0
- package/extend/bajoTemplate/partial/list-item/signout.html +0 -0
- package/extend/bajoTemplate/partial/list-item/user-signup.html +0 -0
- package/extend/bajoTemplate/partial/list-item/your-profile.html +0 -0
- package/extend/bajoTemplate/partial/signin.html +0 -0
- package/extend/bajoTemplate/partial/signout.html +0 -0
- package/extend/bajoTemplate/partial/user/activation.html +0 -0
- package/extend/bajoTemplate/partial/user/forgot-password-nomail.id.md +0 -0
- package/extend/bajoTemplate/partial/user/forgot-password-nomail.md +0 -0
- package/extend/bajoTemplate/partial/user/forgot-password.html +0 -0
- package/extend/bajoTemplate/partial/user/fpl-invalid.html +0 -0
- package/extend/bajoTemplate/partial/user/fpl-invalid.id.md +0 -0
- package/extend/bajoTemplate/partial/user/fpl-invalid.md +0 -0
- package/extend/bajoTemplate/partial/user/fpl.html +0 -0
- package/extend/bajoTemplate/partial/user/signup/form.html +0 -0
- package/extend/bajoTemplate/partial/user/signup/success-mail.id.md +0 -0
- package/extend/bajoTemplate/partial/user/signup/success-mail.md +0 -0
- package/extend/bajoTemplate/partial/user/signup/success-nomail.id.md +0 -0
- package/extend/bajoTemplate/partial/user/signup/success-nomail.md +0 -0
- package/extend/bajoTemplate/partial/user/signup/success.html +0 -0
- package/extend/bajoTemplate/partial/your-stuff/change-password.html +0 -0
- package/extend/bajoTemplate/partial/your-stuff/profile/edit.html +0 -0
- package/extend/bajoTemplate/partial/your-stuff/profile/view.html +0 -0
- package/extend/bajoTemplate/partial/your-stuff/reset-api-key.html +0 -0
- package/extend/bajoTemplate/template/403.html +0 -0
- package/extend/bajoTemplate/template/_admin/reset-user-password.html +0 -0
- package/extend/bajoTemplate/template/_mail/help-contact-form.html +0 -0
- package/extend/bajoTemplate/template/_mail/mystuff-change-password.html +0 -0
- package/extend/bajoTemplate/template/_mail/mystuff-reset-api-key.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-activation-success.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-forgot-password-changed.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-forgot-password-link.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-signup-success-active.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-signup-success.html +0 -0
- package/extend/bajoTemplate/template/help/contact-form/form.html +0 -0
- package/extend/bajoTemplate/template/help/contact-form/success.html +0 -0
- package/extend/bajoTemplate/template/help/trouble-tickets/add.html +0 -0
- package/extend/bajoTemplate/template/help/trouble-tickets/details.html +0 -0
- package/extend/bajoTemplate/template/help/trouble-tickets/list.html +0 -0
- package/extend/bajoTemplate/template/info/about-us.md +0 -0
- package/extend/bajoTemplate/template/info/cookie-policy.md +0 -0
- package/extend/bajoTemplate/template/info/privacy.md +0 -0
- package/extend/bajoTemplate/template/info/terms-conditions.md +0 -0
- package/extend/bajoTemplate/template/signin.html +0 -0
- package/extend/bajoTemplate/template/signout.html +0 -0
- package/extend/bajoTemplate/template/user/activation.html +0 -0
- package/extend/bajoTemplate/template/user/forgot-password.html +0 -0
- package/extend/bajoTemplate/template/user/fpl-invalid.html +0 -0
- package/extend/bajoTemplate/template/user/fpl.html +0 -0
- package/extend/bajoTemplate/template/user/signup/form.html +0 -0
- package/extend/bajoTemplate/template/user/signup/success.html +0 -0
- package/extend/bajoTemplate/template/your-stuff/change-password.html +0 -0
- package/extend/bajoTemplate/template/your-stuff/profile/edit.html +0 -0
- package/extend/bajoTemplate/template/your-stuff/profile/view.html +0 -0
- package/extend/bajoTemplate/template/your-stuff/reset-api-key.html +0 -0
- package/extend/dobo/feature/address.js +1 -1
- package/extend/dobo/feature/category.js +0 -0
- package/extend/dobo/feature/country.js +1 -1
- package/extend/dobo/feature/email.js +0 -0
- package/extend/dobo/feature/lat-lng.js +3 -3
- package/extend/dobo/feature/lat.js +2 -2
- package/extend/dobo/feature/lng.js +2 -2
- package/extend/dobo/feature/person-in-charge.js +0 -0
- package/extend/dobo/feature/phone.js +0 -0
- package/extend/dobo/feature/site-id.js +3 -3
- package/extend/dobo/feature/slug.js +7 -8
- package/extend/dobo/feature/social.js +0 -0
- package/extend/dobo/feature/status.js +2 -2
- package/extend/dobo/feature/team-id.js +3 -3
- package/extend/dobo/feature/ts.js +0 -0
- package/extend/dobo/feature/url.js +6 -6
- package/extend/dobo/feature/user-id.js +5 -5
- package/extend/dobo/fixture/contact-form-cat.json +0 -0
- package/extend/dobo/fixture/site.json +0 -4
- package/extend/dobo/fixture/team-user.json +0 -0
- package/extend/dobo/fixture/team.json +2 -1
- package/extend/dobo/fixture/ticket-cat.json +0 -0
- package/extend/dobo/fixture/user.json +0 -0
- package/extend/dobo/model/contact-form-cat.json +3 -0
- package/extend/dobo/model/contact-form.json +16 -0
- package/extend/dobo/model/download.json +19 -0
- package/extend/dobo/model/site-setting.json +8 -0
- package/extend/dobo/{schema → model}/site.json +4 -8
- package/extend/dobo/{schema → model}/team-user.json +5 -10
- package/extend/dobo/model/team.json +15 -0
- package/extend/dobo/model/ticket-cat.json +3 -0
- package/extend/dobo/model/ticket-detail.json +7 -0
- package/extend/dobo/model/ticket.json +18 -0
- package/extend/dobo/{schema → model}/user.json +14 -11
- package/extend/masohiSocketIo/middleware/server/auth.js +1 -1
- package/extend/sumba/route/anonymous.json +0 -0
- package/extend/sumba/route/secure.json +0 -0
- package/extend/waibuBootstrap/theme/component/factory/nav-dropdown-user.js +5 -5
- package/extend/waibuDb/schema/contact-form-cat.json +0 -0
- package/extend/waibuDb/schema/contact-form.json +0 -0
- package/extend/waibuDb/schema/download.js +1 -1
- package/extend/waibuDb/schema/site.json +2 -2
- package/extend/waibuDb/schema/team-user.js +2 -2
- package/extend/waibuDb/schema/team.json +0 -0
- package/extend/waibuDb/schema/ticket-cat.json +0 -0
- package/extend/waibuDb/schema/user.json +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/contact-form/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/contact-form-cat/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/download/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/reset-user-password.js +5 -6
- package/extend/waibuMpa/extend/waibuAdmin/route/session/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/site.js +25 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/team/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/team-user/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/ticket/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/ticket-cat/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/user/@action.js +0 -0
- package/extend/waibuMpa/route/access-token.js +1 -2
- package/extend/waibuMpa/route/help/contact-form.js +5 -5
- package/extend/waibuMpa/route/help/trouble-tickets/add.js +4 -4
- package/extend/waibuMpa/route/help/trouble-tickets/details/@id.js +5 -5
- package/extend/waibuMpa/route/help/trouble-tickets/list.js +2 -2
- package/extend/waibuMpa/route/info/@item.js +0 -0
- package/extend/waibuMpa/route/signin.js +0 -0
- package/extend/waibuMpa/route/signout.js +1 -14
- package/extend/waibuMpa/route/user/activation.js +4 -6
- package/extend/waibuMpa/route/user/forgot-password/@fpl.js +9 -10
- package/extend/waibuMpa/route/user/forgot-password.js +5 -7
- package/extend/waibuMpa/route/user/signup.js +4 -4
- package/extend/waibuMpa/route/your-stuff/change-password.js +5 -6
- package/extend/waibuMpa/route/your-stuff/download/@action.js +0 -0
- package/extend/waibuMpa/route/your-stuff/download/get.js +0 -0
- package/extend/waibuMpa/route/your-stuff/profile/edit.js +5 -5
- package/extend/waibuMpa/route/your-stuff/profile.js +2 -2
- package/extend/waibuMpa/route/your-stuff/reset-api-key.js +8 -9
- package/extend/waibuRestApi/route/info/get.js +2 -2
- package/extend/waibuRestApi/route/manage/team/model-builder.json +0 -0
- package/extend/waibuRestApi/route/manage/user/model-builder.json +0 -0
- package/extend/waibuRestApi/route/user/access-token/@type/create.js +0 -0
- package/extend/waibuRestApi/route/user/api-key/get.js +1 -2
- package/extend/waibuRestApi/route/your-stuff/api-key/get.js +1 -2
- package/extend/waibuRestApi/route/your-stuff/api-key/update.js +5 -6
- package/extend/waibuRestApi/route/your-stuff/change-password/update.js +2 -3
- package/extend/waibuRestApi/route/your-stuff/profile/get.js +2 -2
- package/extend/waibuRestApi/route/your-stuff/profile/update.js +3 -3
- package/extend/waibuSocketIo/middleware/server/auth.js +2 -3
- package/extend/waibuStatic/asset/user-profile.png +0 -0
- package/index.js +78 -54
- package/lib/check-iconset.js +4 -6
- package/lib/check-team.js +1 -1
- package/lib/check-theme.js +4 -7
- package/lib/check-user-id.js +4 -3
- package/lib/collect-redirects.js +0 -0
- package/lib/collect-routes.js +4 -4
- package/lib/collect-team.js +3 -3
- package/lib/lat-lng-hook.js +2 -2
- package/lib/password-rule.js +0 -0
- package/lib/reset-token.js +1 -1
- package/lib/token-schema.js +0 -0
- package/logo.png +0 -0
- package/package.json +41 -34
- package/wiki/CHANGES.md +6 -0
- package/wiki/CONFIG.md +2 -0
- package/wiki/CONTRIBUTING.md +5 -0
- package/wiki/DEV-GUIDE.md +1 -0
- package/wiki/ECOSYSTEM.md +28 -0
- package/wiki/GETTING-STARTED.md +1 -0
- package/wiki/USER-GUIDE.md +1 -0
- package/extend/bajo/hook/dobo@before-record-count.js +0 -8
- package/extend/bajo/hook/dobo@before-record-find-one.js +0 -8
- package/extend/bajo/hook/dobo@before-record-get.js +0 -23
- package/extend/bajo/hook/dobo@before-record-remove.js +0 -10
- package/extend/bajo/hook/dobo@before-record-update.js +0 -10
- package/extend/dobo/schema/contact-form-cat.json +0 -3
- package/extend/dobo/schema/contact-form.json +0 -20
- package/extend/dobo/schema/download.json +0 -24
- package/extend/dobo/schema/site-setting.json +0 -8
- package/extend/dobo/schema/team.json +0 -19
- package/extend/dobo/schema/ticket-cat.json +0 -3
- package/extend/dobo/schema/ticket-detail.json +0 -7
- package/extend/dobo/schema/ticket.json +0 -17
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
<!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source: index.js</title><!--[if lt IE 9]>
|
|
2
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
3
|
+
<![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="light"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">Sumba API</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="Sumba.html">Sumba</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#factory">factory</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/sumba" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/sumba" target="">Github</a></div><div class="navbar-item"><a id="" href="https://sumba.bajo.app/" target="">Sumba</a></div><div class="navbar-item"><a id="" href="https://bajo.app/" target="">Bajo</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">index.js</h1></header><article><pre class="prettyprint source lang-js"><code>import path from 'path'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Plugin factory
|
|
7
|
+
*
|
|
8
|
+
* @param {string} pkgName - NPM package name
|
|
9
|
+
* @returns {class}
|
|
10
|
+
*/
|
|
11
|
+
async function factory (pkgName) {
|
|
12
|
+
const me = this
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sumba class
|
|
16
|
+
*
|
|
17
|
+
* @class
|
|
18
|
+
*/
|
|
19
|
+
class Sumba extends this.app.baseClass.Base {
|
|
20
|
+
static alias = 'sumba'
|
|
21
|
+
static dependencies = ['bajo-extra', 'bajo-common-db', 'bajo-config', 'bajo-markdown']
|
|
22
|
+
|
|
23
|
+
constructor () {
|
|
24
|
+
super(pkgName, me.app)
|
|
25
|
+
this.config = {
|
|
26
|
+
multiSite: false,
|
|
27
|
+
waibu: {
|
|
28
|
+
title: 'site',
|
|
29
|
+
prefix: 'site'
|
|
30
|
+
},
|
|
31
|
+
waibuMpa: {
|
|
32
|
+
home: 'sumba:/your-stuff/profile',
|
|
33
|
+
icon: 'globe',
|
|
34
|
+
redirect: {
|
|
35
|
+
'/': 'sumba:/your-stuff/profile',
|
|
36
|
+
'/your-stuff': 'sumba:/your-stuff/profile',
|
|
37
|
+
'/info': 'sumba:/info/about-us',
|
|
38
|
+
'/user': 'sumba:/your-stuff/profile',
|
|
39
|
+
'/db/export': 'sumba:/db/export/list',
|
|
40
|
+
'/help': 'sumba:/help/contact-form',
|
|
41
|
+
'/help/trouble-tickets': 'sumba:/help/trouble-tickets/list'
|
|
42
|
+
},
|
|
43
|
+
menuHandler: [{
|
|
44
|
+
title: 'account',
|
|
45
|
+
level: 9998,
|
|
46
|
+
children: [
|
|
47
|
+
// anonymous only
|
|
48
|
+
{ title: 'signin', href: 'sumba:/signin', visible: 'anon' },
|
|
49
|
+
{ title: 'forgotPassword', href: 'sumba:/user/forgot-password', visible: 'anon' },
|
|
50
|
+
{ title: 'newUserSignup', href: 'sumba:/user/signup', visible: 'anon' },
|
|
51
|
+
{ title: '-', visible: 'anon' },
|
|
52
|
+
{ title: 'activation', href: 'sumba:/user/activation', visible: 'anon' },
|
|
53
|
+
// authenticated only
|
|
54
|
+
{ title: 'yourProfile', href: 'sumba:/your-stuff/profile', visible: 'auth' },
|
|
55
|
+
{ title: 'changePassword', href: 'sumba:/your-stuff/change-password', visible: 'auth' },
|
|
56
|
+
{ title: 'downloadList', href: 'sumba:/your-stuff/download/list', visible: 'auth' },
|
|
57
|
+
{ title: '-', visible: 'auth' },
|
|
58
|
+
{ title: 'signout', href: 'sumba:/signout', visible: 'auth' }
|
|
59
|
+
]
|
|
60
|
+
}, {
|
|
61
|
+
title: 'help',
|
|
62
|
+
level: 9999,
|
|
63
|
+
children: [
|
|
64
|
+
{ title: 'contactForm', href: 'sumba:/help/contact-form' },
|
|
65
|
+
{ title: 'troubleTickets', href: 'sumba:/help/trouble-tickets', visible: 'auth' },
|
|
66
|
+
{ title: '-' },
|
|
67
|
+
{ title: 'cookiePolicy', href: 'sumba:/info/cookie-policy' },
|
|
68
|
+
{ title: 'privacy', href: 'sumba:/info/privacy' },
|
|
69
|
+
{ title: 'termsConditions', href: 'sumba:/info/terms-conditions' }
|
|
70
|
+
]
|
|
71
|
+
}]
|
|
72
|
+
},
|
|
73
|
+
waibuAdmin: {
|
|
74
|
+
menuHandler: 'sumba:adminMenu',
|
|
75
|
+
menuCollapsible: true,
|
|
76
|
+
modelDisabled: 'all'
|
|
77
|
+
},
|
|
78
|
+
auth: {
|
|
79
|
+
common: {
|
|
80
|
+
apiKey: {
|
|
81
|
+
type: 'Bearer',
|
|
82
|
+
qsKey: 'apiKey',
|
|
83
|
+
headerKey: 'X-Sumba-ApiKey'
|
|
84
|
+
},
|
|
85
|
+
basic: {
|
|
86
|
+
},
|
|
87
|
+
jwt: {
|
|
88
|
+
type: 'Bearer',
|
|
89
|
+
qsKey: 'token',
|
|
90
|
+
headerKey: 'X-Sumba-Token',
|
|
91
|
+
secret: '668de9cf57316c7dbf52f7ff7611c299',
|
|
92
|
+
expiresIn: 604800000
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
waibuRestApi: {
|
|
96
|
+
methods: ['basic', 'apiKey', 'jwt'],
|
|
97
|
+
silentOnError: false
|
|
98
|
+
},
|
|
99
|
+
waibuMpa: {
|
|
100
|
+
methods: ['session'],
|
|
101
|
+
silentOnError: false
|
|
102
|
+
},
|
|
103
|
+
waibuStatic: {
|
|
104
|
+
methods: ['basic', 'apiKey', 'jwt'],
|
|
105
|
+
basic: {
|
|
106
|
+
useUtf8: true,
|
|
107
|
+
realm: 'Protected Area',
|
|
108
|
+
warningMessage: 'Please authenticate yourself, thank you!'
|
|
109
|
+
},
|
|
110
|
+
silentOnError: false
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
redirect: {
|
|
114
|
+
signin: 'sumba:/signin',
|
|
115
|
+
afterSignin: '/',
|
|
116
|
+
signout: 'sumba:/signout',
|
|
117
|
+
afterSignout: '/'
|
|
118
|
+
},
|
|
119
|
+
siteSetting: {
|
|
120
|
+
forgotPasswordExpDur: '5m',
|
|
121
|
+
userPassword: {
|
|
122
|
+
minUppercase: 1,
|
|
123
|
+
minLowercase: 1,
|
|
124
|
+
minSpecialChar: 1,
|
|
125
|
+
minNumeric: 1,
|
|
126
|
+
noWhitespace: false,
|
|
127
|
+
latinOnlyChars: false
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.unsafeUserFields = ['password']
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
init = async () => {
|
|
135
|
+
const { getPluginDataDir } = this.app.bajo
|
|
136
|
+
this.downloadDir = `${getPluginDataDir(this.ns)}/download`
|
|
137
|
+
this.app.lib.fs.ensureDirSync(this.downloadDir)
|
|
138
|
+
for (const type of ['secure', 'anonymous', 'team']) {
|
|
139
|
+
this[`${type}Routes`] = this[`${type}Routes`] ?? []
|
|
140
|
+
this[`${type}NegRoutes`] = this[`${type}NegRoutes`] ?? []
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
_getSetting = async (type, source) => {
|
|
145
|
+
const { defaultsDeep } = this.app.lib.aneka
|
|
146
|
+
const { get } = this.app.lib._
|
|
147
|
+
|
|
148
|
+
const setting = defaultsDeep(get(this.config, `auth.${source}.${type}`, {}), get(this.config, `auth.common.${type}`, {}))
|
|
149
|
+
if (type === 'basic') setting.type = 'Basic'
|
|
150
|
+
return setting
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
_getToken = async (type, req, source) => {
|
|
154
|
+
const { isEmpty } = this.app.lib._
|
|
155
|
+
|
|
156
|
+
const setting = await this._getSetting(type, source)
|
|
157
|
+
let token = req.headers[setting.headerKey.toLowerCase()]
|
|
158
|
+
if (!['basic'].includes(type) && isEmpty(token)) token = req.query[setting.qsKey]
|
|
159
|
+
if (isEmpty(token)) {
|
|
160
|
+
const parts = (req.headers.authorization || '').split(' ')
|
|
161
|
+
if (parts[0] === setting.type) token = parts[1]
|
|
162
|
+
}
|
|
163
|
+
if (isEmpty(token)) return false
|
|
164
|
+
return token
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
adminMenu = async (locals, req) => {
|
|
168
|
+
if (!this.app.waibuAdmin) return
|
|
169
|
+
const { getPluginPrefix } = this.app.waibu
|
|
170
|
+
const prefix = getPluginPrefix(this.ns)
|
|
171
|
+
return [{
|
|
172
|
+
title: 'supportSystem',
|
|
173
|
+
children: [
|
|
174
|
+
{ title: 'contactForm', href: `waibuAdmin:/${prefix}/contact-form/list` },
|
|
175
|
+
{ title: 'contactFormCat', href: `waibuAdmin:/${prefix}/contact-form-cat/list` },
|
|
176
|
+
{ title: 'ticket', href: `waibuAdmin:/${prefix}/ticket/list` },
|
|
177
|
+
{ title: 'ticketCat', href: `waibuAdmin:/${prefix}/ticket-cat/list` }
|
|
178
|
+
]
|
|
179
|
+
}, {
|
|
180
|
+
title: 'management',
|
|
181
|
+
children: [
|
|
182
|
+
{ title: 'manageSite', href: `waibuAdmin:/${prefix}/site` },
|
|
183
|
+
{ title: 'manageUser', href: `waibuAdmin:/${prefix}/user/list` },
|
|
184
|
+
{ title: 'manageTeam', href: `waibuAdmin:/${prefix}/team/list` },
|
|
185
|
+
{ title: 'manageTeamUser', href: `waibuAdmin:/${prefix}/team-user/list` },
|
|
186
|
+
{ title: 'manageDownload', href: `waibuAdmin:/${prefix}/download/list` },
|
|
187
|
+
{ title: 'resetUserPassword', href: `waibuAdmin:/${prefix}/reset-user-password` }
|
|
188
|
+
]
|
|
189
|
+
}, {
|
|
190
|
+
title: 'misc',
|
|
191
|
+
children: [
|
|
192
|
+
{ title: 'userSession', href: `waibuAdmin:/${prefix}/session/list` }
|
|
193
|
+
]
|
|
194
|
+
}]
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
getUser = async (rec, safe = true) => {
|
|
198
|
+
const { omit, isPlainObject } = this.app.lib._
|
|
199
|
+
let user
|
|
200
|
+
if (isPlainObject(rec)) user = rec
|
|
201
|
+
else {
|
|
202
|
+
const mdl = this.app.dobo.getModel('SumbaUser')
|
|
203
|
+
user = await mdl.getRecord(rec, { noHook: true, throwNotFound: false })
|
|
204
|
+
}
|
|
205
|
+
if (!user) return null
|
|
206
|
+
return safe ? omit(user, this.unsafeUserFields) : user
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
mergeTeam = async (user, site) => {
|
|
210
|
+
if (!user) return
|
|
211
|
+
const { map, pick } = this.app.lib._
|
|
212
|
+
user.teams = []
|
|
213
|
+
const query = { userId: user.id, siteId: site.id }
|
|
214
|
+
let mdl = this.app.dobo.getModel('SumbaTeamUser')
|
|
215
|
+
const userTeam = await mdl.findAllRecord({ query })
|
|
216
|
+
if (userTeam.length === 0) return
|
|
217
|
+
delete query.userId
|
|
218
|
+
query.id = { $in: map(userTeam, 'id') }
|
|
219
|
+
query.status = 'ENABLED'
|
|
220
|
+
mdl = this.app.dobo.getModel('SumbaTeam')
|
|
221
|
+
const team = await mdl.findAllRecord({ query })
|
|
222
|
+
if (team.length > 0) user.teams.push(...map(team, t => pick(t, ['id', 'alias'])))
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
getUserFromUsernamePassword = async (username = '', password = '', req) => {
|
|
226
|
+
const { importPkg } = this.app.bajo
|
|
227
|
+
const model = this.app.dobo.getModel('SumbaUser')
|
|
228
|
+
await model.validate({ username, password }, null, { partial: true, ns: ['sumba', 'dobo'], fields: ['username', 'password'] })
|
|
229
|
+
const bcrypt = await importPkg('bajoExtra:bcrypt')
|
|
230
|
+
|
|
231
|
+
const query = { username, provider: 'local' }
|
|
232
|
+
const rows = await model.findRecord({ query }, { req, forceNoHidden: true, noHook: true })
|
|
233
|
+
if (rows.length === 0) throw this.error('validationError', { details: [{ field: 'username', error: 'Unknown username' }], statusCode: 401 })
|
|
234
|
+
const rec = rows[0]
|
|
235
|
+
if (rec.status !== 'ACTIVE') throw this.error('validationError', { details: ['User is inactive or temporarily disabled'], statusCode: 401 })
|
|
236
|
+
const verified = await bcrypt.compare(password, rec.password)
|
|
237
|
+
if (!verified) throw this.error('validationError', { details: [{ field: 'password', error: 'invalidPassword' }], statusCode: 401 })
|
|
238
|
+
return rec
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
createJwtFromUserRecord = async (rec) => {
|
|
242
|
+
const { importPkg } = this.app.bajo
|
|
243
|
+
const { dayjs } = this.app.lib
|
|
244
|
+
const { hash } = this.app.bajoExtra
|
|
245
|
+
const { get, pick } = this.app.lib._
|
|
246
|
+
|
|
247
|
+
const fastJwt = await importPkg('bajoExtra:fast-jwt')
|
|
248
|
+
const { createSigner } = fastJwt
|
|
249
|
+
|
|
250
|
+
const opts = pick(this.config.auth.common.jwt, ['expiresIn'])
|
|
251
|
+
opts.key = get(this.config, 'auth.common.jwt.secret')
|
|
252
|
+
const sign = createSigner(opts)
|
|
253
|
+
const apiKey = await hash(rec.password)
|
|
254
|
+
const payload = { uid: rec.id, apiKey }
|
|
255
|
+
const token = await sign(payload)
|
|
256
|
+
const expiresAt = dayjs().add(opts.expiresIn).toDate()
|
|
257
|
+
return { token, expiresAt }
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
verifySession = async (req, reply, source, payload) => {
|
|
261
|
+
const { getUser } = this
|
|
262
|
+
const { routePath } = this.app.waibu
|
|
263
|
+
|
|
264
|
+
if (!req.session) return false
|
|
265
|
+
if (req.session.userId) {
|
|
266
|
+
req.user = await getUser(req.session.userId)
|
|
267
|
+
return true
|
|
268
|
+
}
|
|
269
|
+
const redir = routePath(this.config.redirect.signin, req)
|
|
270
|
+
req.session.ref = req.url
|
|
271
|
+
throw this.error('_redirect', { redirect: redir })
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
verifyApiKey = async (req, reply, source, payload) => {
|
|
275
|
+
const { merge } = this.app.lib._
|
|
276
|
+
const { isMd5, hash } = this.app.bajoExtra
|
|
277
|
+
const { getUser } = this
|
|
278
|
+
|
|
279
|
+
let token = await this._getToken('apiKey', req, source)
|
|
280
|
+
if (!isMd5(token)) return false
|
|
281
|
+
token = await hash(token)
|
|
282
|
+
const query = { token }
|
|
283
|
+
const rows = await this.app.dobo.getModel('SumbaUser').findRecord({ query }, { req, noHook: true })
|
|
284
|
+
if (rows.length === 0) throw this.error('invalidKey', merge({ statusCode: 401 }, payload))
|
|
285
|
+
if (rows[0].status !== 'ACTIVE') throw this.error('userInactive', merge({ details: [{ field: 'status', error: 'inactive' }], statusCode: 401 }, payload))
|
|
286
|
+
req.user = await getUser(rows[0])
|
|
287
|
+
return true
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
verifyBasic = async (req, reply, source, payload) => {
|
|
291
|
+
const { getUserFromUsernamePassword } = this
|
|
292
|
+
const { getUser } = this
|
|
293
|
+
const { isEmpty, merge } = this.app.lib._
|
|
294
|
+
|
|
295
|
+
const setHeader = async (setting, reply) => {
|
|
296
|
+
const { isString } = this.app.lib._
|
|
297
|
+
|
|
298
|
+
let header = setting.type
|
|
299
|
+
const exts = []
|
|
300
|
+
if (isString(setting.realm)) exts.push(`realm="${setting.realm}"`)
|
|
301
|
+
if (setting.useUtf8) exts.push('charset="UTF-8"')
|
|
302
|
+
if (exts.length > 0) header += ` ${exts.join(', ')}`
|
|
303
|
+
reply.header('WWW-Authenticate', header)
|
|
304
|
+
reply.code(401)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const setting = await this._getSetting('basic', source)
|
|
308
|
+
let authInfo
|
|
309
|
+
const parts = (req.headers.authorization ?? '').split(' ')
|
|
310
|
+
if (parts[0] === setting.type) authInfo = parts[1]
|
|
311
|
+
if (isEmpty(authInfo)) {
|
|
312
|
+
if (setting.realm) {
|
|
313
|
+
await setHeader(setting, reply)
|
|
314
|
+
throw this.error(setting.warningMessage)
|
|
315
|
+
} else return false
|
|
316
|
+
}
|
|
317
|
+
const decoded = Buffer.from(authInfo, 'base64').toString()
|
|
318
|
+
const [username, password] = decoded.split(':')
|
|
319
|
+
try {
|
|
320
|
+
const user = await getUserFromUsernamePassword(username, password, req)
|
|
321
|
+
req.user = await getUser(user)
|
|
322
|
+
} catch (err) {
|
|
323
|
+
if (err.statusCode === 401 && setting.realm) {
|
|
324
|
+
await setHeader(setting, reply)
|
|
325
|
+
return err.message
|
|
326
|
+
}
|
|
327
|
+
throw merge(err, payload)
|
|
328
|
+
}
|
|
329
|
+
return true
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
verifyJwt = async (req, reply, source, payload) => {
|
|
333
|
+
const { importPkg } = this.app.bajo
|
|
334
|
+
const { getUser } = this
|
|
335
|
+
const { isEmpty, merge } = this.app.lib._
|
|
336
|
+
|
|
337
|
+
const fastJwt = await importPkg('bajoExtra:fast-jwt')
|
|
338
|
+
const { createVerifier } = fastJwt
|
|
339
|
+
const setting = await this._getSetting('jwt', source)
|
|
340
|
+
const token = await this._getToken('jwt', req, source)
|
|
341
|
+
if (isEmpty(token)) return false
|
|
342
|
+
const verifier = createVerifier({
|
|
343
|
+
key: setting.secret,
|
|
344
|
+
complete: true
|
|
345
|
+
})
|
|
346
|
+
const decoded = await verifier(token)
|
|
347
|
+
const id = decoded.payload.uid
|
|
348
|
+
try {
|
|
349
|
+
const rec = await this.app.dobo.getModel('SumbaUser').getRecord(id, { req, noHook: true })
|
|
350
|
+
if (!rec) throw this.error('invalidToken', { statusCode: 401 })
|
|
351
|
+
if (rec.status !== 'ACTIVE') throw this.error('userInactive', { details: [{ field: 'status', error: 'inactive' }], statusCode: 401 })
|
|
352
|
+
req.user = await getUser(rec)
|
|
353
|
+
} catch (err) {
|
|
354
|
+
merge(err, payload)
|
|
355
|
+
throw err
|
|
356
|
+
}
|
|
357
|
+
return true
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
checkPathsByTeam = ({ paths = [], method = 'GET', teams = [], guards = [] }) => {
|
|
361
|
+
const { includes } = this.app.lib.aneka
|
|
362
|
+
const { outmatch } = this.app.lib
|
|
363
|
+
|
|
364
|
+
for (const item of guards) {
|
|
365
|
+
const matchPath = outmatch(item.path)
|
|
366
|
+
for (const path of paths) {
|
|
367
|
+
if (matchPath(path)) {
|
|
368
|
+
const matchMethods = outmatch(item.methods, { separator: false })
|
|
369
|
+
if (matchMethods(method)) {
|
|
370
|
+
if (item.teams.length === 0) return item
|
|
371
|
+
if (includes(teams, item.teams)) return item
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
checkPathsByRoute = ({ paths = [], method = 'GET', guards = [] }) => {
|
|
379
|
+
const { outmatch } = this.app.lib
|
|
380
|
+
|
|
381
|
+
for (const item of guards) {
|
|
382
|
+
const matchPath = outmatch(item.path)
|
|
383
|
+
for (const path of paths) {
|
|
384
|
+
if (matchPath(path)) {
|
|
385
|
+
const matchMethods = outmatch(item.methods, { separator: false })
|
|
386
|
+
if (matchMethods(method)) return item
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
checkPathsByGuard = ({ guards, paths }) => {
|
|
393
|
+
const { outmatch } = this.app.lib
|
|
394
|
+
const matcher = outmatch(guards)
|
|
395
|
+
let guarded
|
|
396
|
+
for (const path of paths) {
|
|
397
|
+
if (!guarded) guarded = matcher(path)
|
|
398
|
+
}
|
|
399
|
+
return guarded
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
getSite = async (hostname, useId) => {
|
|
403
|
+
const { omit } = this.app.lib._
|
|
404
|
+
const omitted = ['status']
|
|
405
|
+
|
|
406
|
+
const mergeSetting = async (site) => {
|
|
407
|
+
const { defaultsDeep } = this.app.lib.aneka
|
|
408
|
+
const { parseObject } = this.app.lib
|
|
409
|
+
const { trim, get, filter } = this.app.lib._
|
|
410
|
+
const defSetting = {}
|
|
411
|
+
const nsSetting = {}
|
|
412
|
+
const names = this.app.getAllNs()
|
|
413
|
+
const query = {
|
|
414
|
+
ns: { $in: names },
|
|
415
|
+
siteId: site.id
|
|
416
|
+
}
|
|
417
|
+
const all = await this.app.dobo.getModel('SumbaSiteSetting').findRecord({ query, limit: -1 })
|
|
418
|
+
for (const ns of names) {
|
|
419
|
+
nsSetting[ns] = {}
|
|
420
|
+
defSetting[ns] = get(this, `app.${ns}.config.siteSetting`, {})
|
|
421
|
+
const items = filter(all, { ns })
|
|
422
|
+
for (const item of items) {
|
|
423
|
+
let value = trim([item.value] ?? '')
|
|
424
|
+
if (['[', '{'].includes(value[0])) value = JSON.parse(value)
|
|
425
|
+
else if (Number(value)) value = Number(value)
|
|
426
|
+
else if (['true', 'false'].includes(value)) value = value === 'true'
|
|
427
|
+
nsSetting[ns][item.key] = value
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
site.setting = parseObject(defaultsDeep({}, nsSetting, defSetting))
|
|
431
|
+
// additional fields
|
|
432
|
+
const country = await this.app.dobo.getModel('CdbCountry').getRecord(site.country, { noHook: true })
|
|
433
|
+
site.countryName = (country ?? {}).name ?? site.country
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
let site = {}
|
|
437
|
+
|
|
438
|
+
if (!this.config.multiSite) {
|
|
439
|
+
const resp = await this.app.dobo.getModel('SumbaSite').findRecord({ query: { alias: 'default' } }, { noHook: true })
|
|
440
|
+
site = omit(resp[0], omitted)
|
|
441
|
+
await mergeSetting(site)
|
|
442
|
+
return site
|
|
443
|
+
}
|
|
444
|
+
let query
|
|
445
|
+
if (useId) query = { id: hostname }
|
|
446
|
+
else {
|
|
447
|
+
query = {
|
|
448
|
+
$or: [
|
|
449
|
+
{ hostname },
|
|
450
|
+
{ alias: hostname }
|
|
451
|
+
]
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const filter = { query, limit: 1 }
|
|
455
|
+
const rows = await this.app.dobo.getModel('SumbaSite').findRecord(filter, { noHook: true })
|
|
456
|
+
if (rows.length === 0) throw this.error('unknownSite')
|
|
457
|
+
const row = omit(rows[0], omitted)
|
|
458
|
+
if (row.status !== 'ACTIVE') throw this.error('siteInactiveInfo')
|
|
459
|
+
site = row
|
|
460
|
+
await mergeSetting(site)
|
|
461
|
+
return site
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
signout = async ({ req, reply, reason }) => {
|
|
465
|
+
const { runHook } = this.app.bajo
|
|
466
|
+
const { getSessionId } = this.app.waibuMpa
|
|
467
|
+
const sid = await getSessionId(req.headers.cookie)
|
|
468
|
+
req.session.userId = null
|
|
469
|
+
await runHook(`${this.ns}:afterSignout`, sid, req)
|
|
470
|
+
const { query, params } = req
|
|
471
|
+
// const url = !isEmpty(referer) ? referer : this.config.redirect.home
|
|
472
|
+
const url = this.config.redirect.afterSignout
|
|
473
|
+
req.flash('notify', req.t(reason ?? 'signoutSuccessfully'))
|
|
474
|
+
return reply.redirectTo(url, { query, params })
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
signin = async ({ user, req, reply }) => {
|
|
478
|
+
const { getSessionId } = this.app.waibuMpa
|
|
479
|
+
const { runHook } = this.app.bajo
|
|
480
|
+
const { isEmpty, omit } = this.app.lib._
|
|
481
|
+
let { referer } = req.body || {}
|
|
482
|
+
if (req.session.ref) referer = req.session.ref
|
|
483
|
+
req.session.ref = null
|
|
484
|
+
const _user = omit(user, ['password', 'token'])
|
|
485
|
+
req.session.userId = _user.id
|
|
486
|
+
const sid = await getSessionId(req.headers.cookie)
|
|
487
|
+
await runHook(`${this.ns}:afterSignin`, _user, sid, req)
|
|
488
|
+
const { query, params } = req
|
|
489
|
+
const url = !isEmpty(referer) ? referer : this.config.redirect.afterSignin
|
|
490
|
+
req.flash('notify', req.t('signinSuccessfully'))
|
|
491
|
+
return reply.redirectTo(url, { query, params })
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
generatePassword = (req) => {
|
|
495
|
+
const { generateId } = this.app.lib.aneka
|
|
496
|
+
const cfg = req ? req.site.setting.sumba.userPassword : this.config.siteSetting.userPassword
|
|
497
|
+
let passwd = generateId()
|
|
498
|
+
if (cfg.minLowercase) passwd += generateId({ pattern: 'abcdefghijklmnopqrstuvwxyz', length: cfg.minLowercase })
|
|
499
|
+
if (cfg.minUppercase) passwd += generateId({ pattern: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', length: cfg.minUppercase })
|
|
500
|
+
if (cfg.minSpecialChar) passwd += generateId({ pattern: '!@#$%*', length: cfg.minSpecialChar })
|
|
501
|
+
if (cfg.minNumeric) passwd += generateId({ pattern: '0123456789', length: cfg.minNumeric })
|
|
502
|
+
return passwd
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
pushDownload = async ({ description, worker, data, source, req, file, type }) => {
|
|
506
|
+
const { getPlugin } = this.app.bajo
|
|
507
|
+
const { createRecord } = getPlugin('waibuDb')
|
|
508
|
+
const { push } = getPlugin('bajoQueue')
|
|
509
|
+
description = description ?? file
|
|
510
|
+
const jobQueue = {
|
|
511
|
+
worker,
|
|
512
|
+
source,
|
|
513
|
+
payload: {
|
|
514
|
+
type: 'object',
|
|
515
|
+
data
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (!type) type = path.extname(file)
|
|
519
|
+
if (type[0] === '.') type = type.slice(1)
|
|
520
|
+
const body = { file, description, jobQueue, type }
|
|
521
|
+
const rec = await createRecord({ model: 'SumbaDownload', body, req, options: { noFlash: true } })
|
|
522
|
+
jobQueue.payload.data.download = { id: rec.data.id, file }
|
|
523
|
+
await push(jobQueue)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
getApiKeyFromUserId = async id => {
|
|
527
|
+
const { hash } = this.app.bajoExtra
|
|
528
|
+
const options = { forceNoHidden: true, noHook: true, noCache: true, attachment: true, mimeType: true }
|
|
529
|
+
const resp = await this.app.dobo.getModel('SumbaUser').getRecord(id, options)
|
|
530
|
+
return await hash(resp.salt)
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return Sumba
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
export default factory
|
|
538
|
+
</code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">Sumba API</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/sumba" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/sumba" target="">Github</a></div><div class="navbar-item"><a id="" href="https://sumba.bajo.app/" target="">Sumba</a></div><div class="navbar-item"><a id="" href="https://bajo.app/" target="">Bajo</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="Sumba.html">Sumba</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#factory">factory</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>
|