create-lupine 1.0.31 → 1.3.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/README.md +31 -0
- package/index.js +238 -112
- package/package.json +1 -1
- package/templates/common/.agents/skills/lupine-framework/SKILL.md +63 -0
- package/templates/common/.agents/skills/lupine-framework/references/backend-api.md +113 -0
- package/templates/common/.agents/skills/lupine-framework/references/icon-handling.md +71 -0
- package/templates/common/.agents/skills/lupine-framework/references/mobile-interactions.md +29 -0
- package/templates/common/.agents/skills/lupine-framework/references/native-apps.md +190 -0
- package/templates/common/.agents/skills/lupine-framework/references/navigation-and-routing.md +55 -0
- package/templates/common/.agents/skills/lupine-framework/references/reactivity-and-state.md +108 -0
- package/templates/common/.agents/skills/lupine-framework/references/styling-and-themes.md +121 -0
- package/templates/common/.env.mobile +4 -3
- package/templates/common/_env +10 -4
- package/templates/common/apps/server/README.md +10 -0
- package/templates/common/dev/cp-folder.js +9 -4
- package/templates/lupine-template-cv-starter/README.md +37 -0
- package/templates/lupine-template-cv-starter/app/package.json +20 -0
- package/templates/lupine-template-cv-starter/app/src/app.tsx +6 -0
- package/templates/lupine-template-cv-starter/app/src/index.native.tsx +4 -0
- package/templates/lupine-template-cv-starter/app/src/index.test.tsx +71 -0
- package/templates/lupine-template-cv-starter/app/src/index.web.tsx +28 -0
- package/templates/lupine-template-cv-starter/app/tsconfig.json +17 -0
- package/templates/lupine-template-cv-starter/lupine.json +8 -7
- package/templates/lupine-template-cv-starter/web/src/index.html +9 -2
- package/templates/lupine-template-cv-starter/web/src/index.tsx +9 -23
- package/templates/lupine-template-cv-starter/web/src/lupine-template-cv-starter/index.html +9 -2
- package/templates/lupine-template-cv-starter/web/src/lupine-template-cv-starter/index.tsx +4 -29
- package/templates/lupine-template-doc-starter/README.md +37 -0
- package/templates/lupine-template-doc-starter/app/package.json +20 -0
- package/templates/lupine-template-doc-starter/app/src/app.tsx +6 -0
- package/templates/lupine-template-doc-starter/app/src/index.native.tsx +4 -0
- package/templates/lupine-template-doc-starter/app/src/index.test.tsx +78 -0
- package/templates/lupine-template-doc-starter/app/src/index.web.tsx +28 -0
- package/templates/lupine-template-doc-starter/app/tsconfig.json +17 -0
- package/templates/lupine-template-doc-starter/lupine.json +8 -7
- package/templates/lupine-template-doc-starter/web/src/index.html +9 -2
- package/templates/lupine-template-doc-starter/web/src/index.tsx +9 -23
- package/templates/lupine-template-doc-starter/web/src/lupine-template-doc-starter/index.html +9 -2
- package/templates/lupine-template-doc-starter/web/src/lupine-template-doc-starter/index.tsx +4 -29
- package/templates/lupine-template-fullstack-note/README.md +83 -0
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-note}/api/package.json +1 -1
- package/templates/lupine-template-fullstack-note/api/resources/install.mysql.sql +32 -0
- package/templates/lupine-template-fullstack-note/api/resources/install.sqlite.sql +27 -0
- package/templates/lupine-template-fullstack-note/api/src/service/answer.ts +39 -0
- package/templates/lupine-template-fullstack-note/api/src/service/api.ts +52 -0
- package/templates/lupine-template-fullstack-note/api/src/service/db.ts +78 -0
- package/templates/lupine-template-fullstack-note/api/src/service/notes-api.ts +86 -0
- package/templates/lupine-template-fullstack-note/api/src/service/root-api.ts +19 -0
- package/templates/lupine-template-fullstack-note/api/src/service/user-api.ts +182 -0
- package/templates/lupine-template-fullstack-note/app/package.json +19 -0
- package/templates/lupine-template-fullstack-note/app/src/app.tsx +75 -0
- package/templates/lupine-template-fullstack-note/app/src/index.native.tsx +4 -0
- package/templates/lupine-template-fullstack-note/app/src/index.test.tsx +373 -0
- package/templates/lupine-template-fullstack-note/app/src/index.web.tsx +20 -0
- package/templates/lupine-template-fullstack-note/app/src/pages/components.tsx +65 -0
- package/templates/lupine-template-fullstack-note/app/src/pages/details.tsx +38 -0
- package/templates/lupine-template-fullstack-note/app/src/pages/discover.tsx +25 -0
- package/templates/lupine-template-fullstack-note/app/src/pages/home.tsx +76 -0
- package/templates/lupine-template-fullstack-note/app/src/pages/inbox.tsx +49 -0
- package/templates/lupine-template-fullstack-note/app/src/pages/login.tsx +54 -0
- package/templates/lupine-template-fullstack-note/app/src/pages/me.tsx +32 -0
- package/templates/lupine-template-fullstack-note/app/src/pages/notes.tsx +128 -0
- package/templates/lupine-template-fullstack-note/app/src/pages/settings.tsx +45 -0
- package/templates/lupine-template-fullstack-note/app/src/shell/AppMenu.tsx +44 -0
- package/templates/lupine-template-fullstack-note/app/src/shell/api.ts +159 -0
- package/templates/lupine-template-fullstack-note/app/src/shell/data.ts +20 -0
- package/templates/lupine-template-fullstack-note/app/src/shell/locales/ja.ts +80 -0
- package/templates/lupine-template-fullstack-note/app/src/shell/locales/zh-CN.ts +80 -0
- package/templates/lupine-template-fullstack-note/app/src/shell/texts.ts +14 -0
- package/templates/lupine-template-fullstack-note/app/tsconfig.json +17 -0
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-note}/lupine.json +4 -2
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-note}/web/package.json +1 -1
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-note}/web/src/index.html +10 -3
- package/templates/lupine-template-fullstack-note/web/src/index.tsx +15 -0
- package/templates/lupine-template-fullstack-starter/README.md +70 -0
- package/templates/lupine-template-fullstack-starter/api/package.json +10 -0
- package/templates/lupine-template-fullstack-starter/api/resources/install.mysql.sql +107 -0
- package/templates/lupine-template-fullstack-starter/api/resources/install.sqlite.sql +75 -0
- package/templates/lupine-template-fullstack-starter/api/src/lang/api-lang-en.ts +39 -0
- package/templates/lupine-template-fullstack-starter/api/src/lang/api-lang-zh-cn.ts +37 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/admin-api.ts +139 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/api.ts +111 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/contact-api.ts +50 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/file-api-base.ts +30 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/root-api.ts +28 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/send-email.ts +47 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/setting-api.ts +60 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/user-api.ts +1046 -0
- package/templates/lupine-template-fullstack-starter/app/assets/sample.png +0 -0
- package/templates/lupine-template-fullstack-starter/app/package.json +20 -0
- package/templates/lupine-template-fullstack-starter/app/src/app.tsx +76 -0
- package/templates/lupine-template-fullstack-starter/app/src/index.native.tsx +4 -0
- package/templates/lupine-template-fullstack-starter/app/src/index.test.tsx +276 -0
- package/templates/lupine-template-fullstack-starter/app/src/index.web.tsx +28 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/about.tsx +27 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/contact.tsx +41 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/favorite.tsx +27 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/home.tsx +63 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/login.tsx +63 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/mine.tsx +44 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/profile.tsx +58 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/register.tsx +48 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/reset-password.tsx +41 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/settings.tsx +33 -0
- package/templates/lupine-template-fullstack-starter/app/src/pages/story.tsx +46 -0
- package/templates/lupine-template-fullstack-starter/app/src/shell/api.ts +127 -0
- package/templates/lupine-template-fullstack-starter/app/src/shell/parts.tsx +100 -0
- package/templates/lupine-template-fullstack-starter/app/src/shell/stories.ts +65 -0
- package/templates/lupine-template-fullstack-starter/app/src/shell/texts.ts +79 -0
- package/templates/lupine-template-fullstack-starter/app/tsconfig.json +17 -0
- package/templates/lupine-template-fullstack-starter/lupine.json +31 -0
- package/templates/lupine-template-fullstack-starter/web/assets/android-chrome-192x192.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/apple-touch-icon.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/favicon-16x16.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/favicon-32x32.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/favicon.ico +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/License-carbon-icons.txt +71 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/License-material-design.txt +20 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/i-font.woff2 +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/sample.html +124 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/style.css +103 -0
- package/templates/lupine-template-fullstack-starter/web/assets/lupine-flower.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/lupine.svg +71 -0
- package/templates/lupine-template-fullstack-starter/web/assets/site.webmanifest +14 -0
- package/templates/lupine-template-fullstack-starter/web/icons-font.config.js +129 -0
- package/templates/{lupine-template-responsive-starter/api → lupine-template-fullstack-starter/web}/package.json +1 -1
- package/templates/lupine-template-fullstack-starter/web/src/admin/admin-patch.tsx +34 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/components/home-search-component.tsx +125 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/components/story-card.tsx +105 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/components/story-list.tsx +105 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/components/story-props.ts +34 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/index.html +23 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/index.tsx +49 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/pages/admin-cfg.tsx +144 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/pages/admin-item-edit.tsx +20 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/pages/admin-item-list.tsx +23 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin/pages/admin-user.tsx +145 -0
- package/templates/lupine-template-fullstack-starter/web/src/index.html +28 -0
- package/templates/lupine-template-fullstack-starter/web/src/index.tsx +16 -0
- package/templates/lupine-template-fullstack-starter/web/src/services/fetch-data.ts +37 -0
- package/templates/lupine-template-fullstack-starter/web/src/styles/base-css.ts +14 -0
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/web/src/styles/global.css +10 -57
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/web/src/styles/theme.ts +2 -1
- package/templates/lupine-template-responsive-starter/README.md +51 -0
- package/templates/lupine-template-responsive-starter/app/package.json +19 -0
- package/templates/lupine-template-responsive-starter/app/src/app.tsx +80 -0
- package/templates/lupine-template-responsive-starter/app/src/index.native.tsx +4 -0
- package/templates/lupine-template-responsive-starter/app/src/index.test.tsx +283 -0
- package/templates/lupine-template-responsive-starter/app/src/index.web.tsx +31 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/about.tsx +23 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/finance.tsx +48 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/mine.tsx +60 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/not-found.tsx +9 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/note-detail.tsx +43 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/note-edit.tsx +45 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/note-search.tsx +62 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/notes.tsx +71 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/settings.tsx +55 -0
- package/templates/lupine-template-responsive-starter/app/src/pages/tools.tsx +112 -0
- package/templates/lupine-template-responsive-starter/app/src/shell/icons.ts +7 -0
- package/templates/lupine-template-responsive-starter/app/src/shell/layout.ts +18 -0
- package/templates/lupine-template-responsive-starter/app/src/shell/locales/zh-CN.ts +89 -0
- package/templates/lupine-template-responsive-starter/app/src/shell/menu.tsx +81 -0
- package/templates/lupine-template-responsive-starter/app/src/shell/nav.ts +12 -0
- package/templates/lupine-template-responsive-starter/app/src/shell/store.ts +72 -0
- package/templates/lupine-template-responsive-starter/app/src/shell/texts.ts +11 -0
- package/templates/lupine-template-responsive-starter/app/tsconfig.json +17 -0
- package/templates/lupine-template-responsive-starter/lupine.json +7 -6
- package/templates/lupine-template-responsive-starter/web/src/index.html +9 -2
- package/templates/lupine-template-responsive-starter/web/src/index.tsx +9 -34
- package/templates/lupine-template-responsive-starter/web/src/lupine-template-responsive-starter/index.html +12 -6
- package/templates/lupine-template-responsive-starter/web/src/lupine-template-responsive-starter/index.tsx +12 -31
- package/templates/common/AI_CONTEXT.md +0 -1002
- package/templates/common/apps/server/src/app-loader.ts +0 -4
- package/templates/lupine-template-cv-starter/api/package.json +0 -6
- package/templates/lupine-template-cv-starter/api/resources/install.sqlite.sql +0 -4
- package/templates/lupine-template-cv-starter/api/src/index.ts +0 -15
- package/templates/lupine-template-cv-starter/web/src/styles/base-css.ts +0 -15
- package/templates/lupine-template-doc-starter/api/package.json +0 -6
- package/templates/lupine-template-doc-starter/api/resources/config_default.json +0 -6
- package/templates/lupine-template-doc-starter/api/resources/install.sqlite.sql +0 -4
- package/templates/lupine-template-doc-starter/api/src/index.ts +0 -15
- package/templates/lupine-template-doc-starter/api/src/resources/config_default.json +0 -6
- package/templates/lupine-template-doc-starter/api/src/resources/install.sqlite.sql +0 -4
- package/templates/lupine-template-doc-starter/web/src/client-env-keys.ts +0 -5
- package/templates/lupine-template-doc-starter/web/src/styles/base-css.ts +0 -15
- package/templates/lupine-template-hello-world/api/resources/config_default.json +0 -6
- package/templates/lupine-template-hello-world/api/resources/install.sqlite.sql +0 -4
- package/templates/lupine-template-hello-world/api/src/service/root-api.ts +0 -18
- package/templates/lupine-template-hello-world/web/src/index.tsx +0 -73
- package/templates/lupine-template-hello-world/web/src/styles/app.css +0 -0
- package/templates/lupine-template-hello-world/web/src/styles/base-css.ts +0 -1
- package/templates/lupine-template-responsive-starter/api/resources/config_default.json +0 -6
- package/templates/lupine-template-responsive-starter/api/resources/install.sqlite.sql +0 -4
- package/templates/lupine-template-responsive-starter/api/src/service/root-api.ts +0 -18
- package/templates/lupine-template-responsive-starter/web/src/app-icons.ts +0 -76
- package/templates/lupine-template-responsive-starter/web/src/components/input-history-component.tsx +0 -93
- package/templates/lupine-template-responsive-starter/web/src/components/mine-about-page.tsx +0 -86
- package/templates/lupine-template-responsive-starter/web/src/components/mine-premium-page.tsx +0 -80
- package/templates/lupine-template-responsive-starter/web/src/components/mine-settings-page.tsx +0 -220
- package/templates/lupine-template-responsive-starter/web/src/components/mobile-top-search-menu.tsx +0 -119
- package/templates/lupine-template-responsive-starter/web/src/components/note-detail.tsx +0 -116
- package/templates/lupine-template-responsive-starter/web/src/components/note-edit.tsx +0 -154
- package/templates/lupine-template-responsive-starter/web/src/components/note-search-page.tsx +0 -193
- package/templates/lupine-template-responsive-starter/web/src/components/search-input.tsx +0 -95
- package/templates/lupine-template-responsive-starter/web/src/components/side-menu-content.tsx +0 -182
- package/templates/lupine-template-responsive-starter/web/src/frames/app-responsive-frame.tsx +0 -52
- package/templates/lupine-template-responsive-starter/web/src/pages/about-page.tsx +0 -43
- package/templates/lupine-template-responsive-starter/web/src/pages/finance-page.tsx +0 -46
- package/templates/lupine-template-responsive-starter/web/src/pages/home-page.tsx +0 -452
- package/templates/lupine-template-responsive-starter/web/src/pages/mine-page.tsx +0 -325
- package/templates/lupine-template-responsive-starter/web/src/pages/tools-page.tsx +0 -46
- package/templates/lupine-template-responsive-starter/web/src/services/local-notes-service.ts +0 -87
- package/templates/lupine-template-responsive-starter/web/src/services/mine-service.ts +0 -45
- package/templates/lupine-template-responsive-starter/web/src/styles/app.css +0 -0
- package/templates/lupine-template-responsive-starter/web/src/styles/base-css.ts +0 -65
- package/templates/lupine-template-responsive-starter/web/src/styles/global.css +0 -2130
- package/templates/lupine-template-responsive-starter/web/src/styles/theme.ts +0 -16
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/en/01-experience/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/en/02-projects/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/en/03-skills/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/en/04-education/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/en/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/zh/01-experience/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/zh/02-projects/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/zh/03-skills/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/zh/04-education/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/markdown/zh/index.md +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/en/01-experience/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/en/02-projects/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/en/03-skills/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/en/04-education/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/en/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/markdown-config.ts +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/zh/01-experience/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/zh/02-projects/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/zh/03-skills/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/zh/04-education/index.html +0 -0
- /package/templates/lupine-template-cv-starter/{web → app}/src/markdown-built/zh/index.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/en/essentials/index.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/en/essentials/list.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/en/guide/install.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/en/guide/started.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/en/index.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/index.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/zh/essentials/index.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/zh/essentials/list.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/zh/guide/install.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/zh/guide/started.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/markdown/zh/index.md +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/en/essentials/index.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/en/essentials/list.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/en/guide/install.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/en/guide/started.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/en/index.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/index.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/markdown-config.ts +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/zh/essentials/index.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/zh/essentials/list.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/zh/guide/install.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/zh/guide/started.html +0 -0
- /package/templates/lupine-template-doc-starter/{web → app}/src/markdown-built/zh/index.html +0 -0
- /package/templates/{lupine-template-hello-world → lupine-template-fullstack-note}/api/src/index.ts +0 -0
- /package/templates/{lupine-template-hello-world → lupine-template-fullstack-note}/web/assets/favicon.ico +0 -0
- /package/templates/{lupine-template-cv-starter → lupine-template-fullstack-starter}/api/resources/config_default.json +0 -0
- /package/templates/{lupine-template-responsive-starter → lupine-template-fullstack-starter}/api/src/index.ts +0 -0
- /package/templates/{lupine-template-cv-starter/web/src → lupine-template-fullstack-starter/web/src/models}/client-env-keys.ts +0 -0
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<title><!--META-TITLE--></title>
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
|
7
7
|
<!--META-ENV-START-->
|
|
8
8
|
<!--META-ENV-END-->
|
|
9
9
|
<link rel="shortcut icon" href="{SUBDIR}/assets/favicon.ico?t={hash}" type="image/x-icon" />
|
|
10
|
-
<
|
|
10
|
+
<style>
|
|
11
|
+
html,
|
|
12
|
+
body,
|
|
13
|
+
.lupine-root {
|
|
14
|
+
height: 100%;
|
|
15
|
+
margin: 0;
|
|
16
|
+
}
|
|
17
|
+
</style>
|
|
11
18
|
<script defer src="{SUBDIR}/index.js?t={hash}"></script>
|
|
12
19
|
</head>
|
|
13
20
|
<body>
|
|
@@ -1,28 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
setDefaultPageTitle,
|
|
6
|
-
isFrontEnd,
|
|
7
|
-
debugWatch,
|
|
8
|
-
webEnv,
|
|
9
|
-
bindAppGlobalStyle,
|
|
10
|
-
} from 'lupine.components';
|
|
11
|
-
import { bindPressData, PressPage, pressThemes } from 'lupine.press';
|
|
12
|
-
import { markdownConfig } from './markdown-built/markdown-config';
|
|
13
|
-
import { ClientEnvKeys } from './client-env-keys';
|
|
14
|
-
import { baseCss } from './styles/base-css';
|
|
1
|
+
import { bindRouter, PageRouter, setDefaultPageTitle } from 'lupine.web';
|
|
2
|
+
import { AppPage } from '../../app/src/index.web';
|
|
3
|
+
// the primitives of the app in the page that the server renders
|
|
4
|
+
import 'lupine.native.core/web/server';
|
|
15
5
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
bindTheme('light', pressThemes);
|
|
20
|
-
bindAppGlobalStyle('comm-css', baseCss, false, true);
|
|
21
|
-
setDefaultPageTitle('Lupine.js Doc');
|
|
6
|
+
// The page of the site is the app (app/), in the same bundle: the server renders the page of the address (search
|
|
7
|
+
// engines see the text). keep: the app is made once and stays; when the address changes (its own pages, the back
|
|
8
|
+
// button) it follows the address itself. Pages of the site itself go into pageRouter before it.
|
|
22
9
|
|
|
23
|
-
|
|
10
|
+
setDefaultPageTitle('Doc Starter');
|
|
24
11
|
|
|
25
12
|
const pageRouter = new PageRouter();
|
|
26
|
-
pageRouter.use('*',
|
|
27
|
-
|
|
13
|
+
pageRouter.use('*', AppPage, { keep: true });
|
|
28
14
|
bindRouter(pageRouter);
|
package/templates/lupine-template-doc-starter/web/src/lupine-template-doc-starter/index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<title><!--META-TITLE--></title>
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
|
7
7
|
<!--META-ENV-START-->
|
|
8
8
|
<!--META-ENV-END-->
|
|
9
9
|
<link
|
|
@@ -11,7 +11,14 @@
|
|
|
11
11
|
href="{SUBDIR}/assets/favicon.ico?t={hash}"
|
|
12
12
|
type="image/x-icon"
|
|
13
13
|
/>
|
|
14
|
-
<
|
|
14
|
+
<style>
|
|
15
|
+
html,
|
|
16
|
+
body,
|
|
17
|
+
.lupine-root {
|
|
18
|
+
height: 100%;
|
|
19
|
+
margin: 0;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
15
22
|
<script defer src="{SUBDIR}/index.js?t={hash}"></script>
|
|
16
23
|
<!-- Cloudflare Web Analytics -->
|
|
17
24
|
<script
|
|
@@ -1,30 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
bindRouter,
|
|
3
|
-
PageRouter,
|
|
4
|
-
bindTheme,
|
|
5
|
-
setDefaultPageTitle,
|
|
6
|
-
isFrontEnd,
|
|
7
|
-
debugWatch,
|
|
8
|
-
webEnv,
|
|
9
|
-
bindAppGlobalStyle,
|
|
10
|
-
} from 'lupine.components';
|
|
11
|
-
import { bindPressData, PressPage, pressThemes, setPressSubDir } from 'lupine.press';
|
|
12
|
-
import { ClientEnvKeys } from '../client-env-keys';
|
|
13
|
-
import { baseCss } from '../styles/base-css';
|
|
14
|
-
import { markdownConfig } from '../markdown-built/markdown-config';
|
|
1
|
+
import { start } from '../../../app/src/index.web';
|
|
15
2
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
bindTheme('light', pressThemes);
|
|
20
|
-
bindAppGlobalStyle('comm-css', baseCss, false, true);
|
|
21
|
-
setDefaultPageTitle('Doc Starter');
|
|
22
|
-
|
|
23
|
-
bindPressData(markdownConfig);
|
|
24
|
-
setPressSubDir('/lupine-template-doc-starter');
|
|
25
|
-
|
|
26
|
-
const pageRouter = new PageRouter();
|
|
27
|
-
pageRouter.setSubDir('/lupine-template-doc-starter');
|
|
28
|
-
pageRouter.use('*', PressPage);
|
|
29
|
-
|
|
30
|
-
bindRouter(pageRouter);
|
|
3
|
+
// The page for GitHub Pages (https://<user>.github.io/lupine-template-doc-starter/): the app without the server, in the
|
|
4
|
+
// folder of the project. Its 404.html sends other addresses of the folder to this page. npm run build, then npm run cp-docs.
|
|
5
|
+
start(document.querySelector<HTMLElement>('.lupine-root') || document.body, '/lupine-template-doc-starter');
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Full-stack Notes
|
|
2
|
+
|
|
3
|
+
An app for iOS, Android, macOS, Windows and the web (lupine.native) with accounts and notes kept in the database of its server: the web site that serves the web version of the app (lupine.web), and the API (lupine.api).
|
|
4
|
+
|
|
5
|
+
<!-- screenshots macos=1 windows=17 web=/ ios=1,22 android=4,8 -->
|
|
6
|
+
<table>
|
|
7
|
+
<tr><th>macOS</th><th>Windows</th><th>Web</th></tr>
|
|
8
|
+
<tr><td><a href="docs/macos-1-home.png"><img src="docs/macos-1-home.png" width="253" alt="macOS"></a></td><td><a href="docs/windows-17-notes.png"><img src="docs/windows-17-notes.png" width="253" alt="Windows"></a></td><td><a href="docs/web-1.png"><img src="docs/web-1.png" width="253" alt="Web"></a></td></tr>
|
|
9
|
+
</table>
|
|
10
|
+
<table>
|
|
11
|
+
<tr><th colspan="2">iOS</th><th colspan="2">Android</th></tr>
|
|
12
|
+
<tr><td><a href="docs/ios-1-home.png"><img src="docs/ios-1-home.png" width="183" alt="iOS"></a></td><td><a href="docs/ios-22-home-dark.png"><img src="docs/ios-22-home-dark.png" width="183" alt="iOS"></a></td><td><a href="docs/android-4-chinese.png"><img src="docs/android-4-chinese.png" width="183" alt="Android"></a></td><td><a href="docs/android-8-components.png"><img src="docs/android-8-components.png" width="183" alt="Android"></a></td></tr>
|
|
13
|
+
</table>
|
|
14
|
+
<!-- /screenshots -->
|
|
15
|
+
|
|
16
|
+
| Part | |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `app/` | the app: tabs, a side menu, a list, the notes of the user (`/notes`), sign-in and new accounts (`/login`), settings (theme, language, the server), components, inbox, details. Its settings: `lupineNative` in `app/package.json`; the client of the API: `app/src/shell/api.ts`; the Chinese and Japanese texts: `app/src/shell/locales` |
|
|
19
|
+
| `web/` | the site: `web/src/index.tsx` imports the web version of the app (one bundle) and keeps it in the frame of its router; the server renders the page of the address (with the theme and the language of the cookies); pages of the site itself go into that router |
|
|
20
|
+
| `api/` | the API: routes in `api/src/service/api.ts`; accounts and sessions in `user-api.ts`, notes in `notes-api.ts`, the tables in `db.ts` |
|
|
21
|
+
| `api/resources/` | the tables as SQL (`install.sqlite.sql`, `install.mysql.sql`), for a database made by hand; copied to `data/resources` of the build |
|
|
22
|
+
| `lupine.json` | what `npm run dev` builds; `"nativeApp": "app"` and `"nativeOut": "dist/native"` for `lupine-native` |
|
|
23
|
+
|
|
24
|
+
## First start
|
|
25
|
+
|
|
26
|
+
1. In `.env`: `CRYPTO_KEY`, the key of the sessions (create-lupine fills in a random one; to make one: `node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"`). Without it the API answers every sign-in with the code `no_crypto_key`, and the app says so. A new key signs everybody out.
|
|
27
|
+
2. `npm run dev` with `lupine-template-fullstack-note` in `APPS` and a `DOMAINS:lupine-template-fullstack-note=...` line (empty in a new project: the app gets every host), then open the site (`http://lupine-template-fullstack-note.app.localhost:<HTTP_PORT>/`), Me → Sign in → Create a new account.
|
|
28
|
+
3. Nothing to install: the API creates its tables when they are first needed, in the database of the app (`DB_TYPE` of `.env`; sqlite by default: `sqlite3.db` in `dist/server_root/lupine-template-fullstack-note_data`). For MySQL / MariaDB too; another database: create them from `api/resources/install.*.sql`.
|
|
29
|
+
|
|
30
|
+
Optional in `.env`: `SESSION_EXPIRE_DAYS` (90 by default).
|
|
31
|
+
|
|
32
|
+
## The apps
|
|
33
|
+
|
|
34
|
+
In a project of create-lupine (and in the repository of this template) the same is in the scripts: `npm run run-mac`, `run-ios`, `run-android`, `run-exe`; `build-android` (the apk for the store), `bump` (the next version), `icons` (the icons of the site from the icon of the app), `release` (a folder for the server).
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm run native -- macos --app=lupine-template-fullstack-note --run
|
|
38
|
+
npm run native -- ios --app=lupine-template-fullstack-note --run
|
|
39
|
+
npm run native -- android --app=lupine-template-fullstack-note --run
|
|
40
|
+
npm run native -- windows --app=lupine-template-fullstack-note --run
|
|
41
|
+
npm run native -- web --app=lupine-template-fullstack-note --watch # the app alone, as a static page
|
|
42
|
+
npm run native -- test macos --app=lupine-template-fullstack-note # app/src/index.test.tsx
|
|
43
|
+
# the apps for the stores, which call your server (WEB.API_BASE_URL of .env.mobile)
|
|
44
|
+
npm run native -- android --app=lupine-template-fullstack-note --release --env=.env.mobile
|
|
45
|
+
npm run native -- ios --app=lupine-template-fullstack-note --release --env=.env.mobile
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The builds are in `dist/native/lupine-template-fullstack-note-app/<platform>`. The test needs no server: it calls an address where nobody answers, then a fake of the API.
|
|
49
|
+
|
|
50
|
+
## The address of the API
|
|
51
|
+
|
|
52
|
+
The native apps call `WEB.API_BASE_URL` of the env file they are built with (`--env=`; `.env.development` by default, `.env.production` with `--release`), or `lupine-template-fullstack-note.WEB.API_BASE_URL` for this app alone. Put the address of your server (`https://example.com/`) into `.env.mobile` and build the apps for the stores with `--release --env=.env.mobile`: it imports `.env`, and the site, built with `.env.production`, doesn't use it. The key goes into the bundle, so it is public.
|
|
53
|
+
|
|
54
|
+
Without it the app calls `http://lupine-template-fullstack-note.app.localhost:<WEB.API_PORT>`: the server of `npm run dev` on the same computer. The Android emulator uses `http://10.0.2.2:<WEB.API_PORT>` instead. The server finds the app by the host name, so add `lupine-template-fullstack-note.app.localhost` and `10.0.2.2` to its `DOMAINS:` line, unless that line is empty or `*`. A phone needs an address of the computer in the network. Settings shows the address the app uses. Release builds for Android refuse plain `http://`.
|
|
55
|
+
|
|
56
|
+
In the browser the app always calls the site it comes from, and `WEB.API_BASE_URL` is not used.
|
|
57
|
+
|
|
58
|
+
| Route | |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `POST /api/register` | `{ username, password }`: a new account, signed in at once |
|
|
61
|
+
| `POST /api/login` | `{ username, password }` |
|
|
62
|
+
| `POST /api/logout` | the browser forgets the cookie |
|
|
63
|
+
| `GET /api/me` | who is signed in |
|
|
64
|
+
| `GET /api/notes?before=<id>` | the notes of the user, newest first, 100 at a time (`more`: there are older ones; `before`: the id of the last one shown) |
|
|
65
|
+
| `POST /api/notes/add` | `{ text }` |
|
|
66
|
+
| `POST /api/notes/update` | `{ id, text }` (in `api.updateNote` of the app; the page has no editing) |
|
|
67
|
+
| `POST /api/notes/delete` | `{ id }` |
|
|
68
|
+
|
|
69
|
+
Every answer is `{ status: 'ok' | 'error', code, message }`, with an HTTP status that fits (400, 401, 404, 409, 429, 500). The message is English, for logs and curl; the app shows its own text for each code (`messageOf` in `app/src/shell/api.ts`, in the languages of `app/src/shell/locales`), and `offline` when the server isn't reached.
|
|
70
|
+
|
|
71
|
+
## Sessions and security
|
|
72
|
+
|
|
73
|
+
- User names: 3 to 50 characters (letters, digits, `_ . @ -`), kept in lower case. Passwords: 6 to 256 characters, kept as a salted scrypt hash (`CryptoUtils.hashPassword` of lupine.api) and compared in constant time.
|
|
74
|
+
- A sign-in answers the same for an unknown name and a wrong password (`login_failed`), and takes as long. A new account has to tell that a name is taken.
|
|
75
|
+
- After five failed sign-ins in a row a name can't sign in for 15 minutes (`too_many_attempts`). The failures are kept in the database (`$__login_failure`), for every name tried, so the brake works across worker processes and restarts and doesn't tell which names have an account. Someone could keep an account locked this way, and nothing limits new accounts: limit the requests to `/api/login` and `/api/register` in front of the server too (nginx: `limit_req`).
|
|
76
|
+
- The session is a token encrypted with `CRYPTO_KEY` (AES-256 and an HMAC): the id and the name of the user, the time of the sign-in, and a hash of the stored password hash, so a new password ends every session of before. It expires after `SESSION_EXPIRE_DAYS`.
|
|
77
|
+
- In the browser the API sets the httpOnly cookie `_token` (SameSite=lax; Secure on https, also behind a proxy that sends `X-Forwarded-Proto`), so the scripts of the page never hold the token.
|
|
78
|
+
- A native app has no cookie store. It keeps the token from the sign-in answer in `storage` and sends it as `Cookie: lang=...; _token=...`. The API puts the token in the answer only for requests without `Origin`, which browsers always send with a POST, so a script in a page can't get it from there either. Signing out removes it from the device and calls `/api/logout`; the token itself is valid until it expires or the password changes.
|
|
79
|
+
- What writes is a POST. A POST with the `Origin` of another site is refused (`forbidden_origin`); the apps send no `Origin`, so they pass, and browsers are still checked. The notes need a session.
|
|
80
|
+
- Every query of the notes has the id of the user in its `WHERE`, so nobody reaches the notes of another user, not even with their ids. A note has 1 to 2000 characters, a user at most 500 notes.
|
|
81
|
+
- An error of the server (the database ...) is logged and answered with `server_error`, without its details.
|
|
82
|
+
|
|
83
|
+
See [Getting started](https://uuware.github.io/lupine.js/en/native/started).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#-- The tables of the app for MySQL / MariaDB. api/src/service/db.ts makes them itself when they are first needed, so
|
|
2
|
+
#-- this file is only for a database made by hand. $__ is the prefix of the tables (DB_TABLE_PREFIX of .env, tbl_ by
|
|
3
|
+
#-- default). utf8mb4: notes may have emoji.
|
|
4
|
+
|
|
5
|
+
#-- the accounts: password is a salted scrypt hash (scrypt$<salt>$<hash>), username is in lower case
|
|
6
|
+
CREATE TABLE IF NOT EXISTS $__account (
|
|
7
|
+
id INTEGER NOT NULL AUTO_INCREMENT,
|
|
8
|
+
username VARCHAR(50) NOT NULL,
|
|
9
|
+
password VARCHAR(255) NOT NULL,
|
|
10
|
+
created_at VARCHAR(30) NOT NULL,
|
|
11
|
+
PRIMARY KEY (id),
|
|
12
|
+
UNIQUE KEY $__account_username (username)
|
|
13
|
+
) DEFAULT CHARSET=utf8mb4;
|
|
14
|
+
|
|
15
|
+
#-- the notes: account_id is the id of $__account; the times are ISO (UTC)
|
|
16
|
+
CREATE TABLE IF NOT EXISTS $__user_note (
|
|
17
|
+
id INTEGER NOT NULL AUTO_INCREMENT,
|
|
18
|
+
account_id INTEGER NOT NULL,
|
|
19
|
+
text TEXT NOT NULL,
|
|
20
|
+
created_at VARCHAR(30) NOT NULL,
|
|
21
|
+
updated_at VARCHAR(30) NOT NULL,
|
|
22
|
+
PRIMARY KEY (id),
|
|
23
|
+
KEY $__user_note_account (account_id, id)
|
|
24
|
+
) DEFAULT CHARSET=utf8mb4;
|
|
25
|
+
|
|
26
|
+
#-- failed sign-ins of a user name (the brake), for any name: last_at is in milliseconds
|
|
27
|
+
CREATE TABLE IF NOT EXISTS $__login_failure (
|
|
28
|
+
username VARCHAR(50) NOT NULL,
|
|
29
|
+
failures INTEGER NOT NULL DEFAULT 0,
|
|
30
|
+
last_at BIGINT NOT NULL DEFAULT 0,
|
|
31
|
+
PRIMARY KEY (username)
|
|
32
|
+
) DEFAULT CHARSET=utf8mb4;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#-- The tables of the app. api/src/service/db.ts makes them itself when they are first needed, so this file is only
|
|
2
|
+
#-- for a database made by hand. $__ is the prefix of the tables (DB_TABLE_PREFIX of .env, tbl_ by default).
|
|
3
|
+
|
|
4
|
+
#-- the accounts: password is a salted scrypt hash (scrypt$<salt>$<hash>), username is in lower case
|
|
5
|
+
CREATE TABLE IF NOT EXISTS $__account (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
username VARCHAR(50) NOT NULL UNIQUE,
|
|
8
|
+
password VARCHAR(255) NOT NULL,
|
|
9
|
+
created_at VARCHAR(30) NOT NULL
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
#-- the notes: account_id is the id of $__account; the times are ISO (UTC)
|
|
13
|
+
CREATE TABLE IF NOT EXISTS $__user_note (
|
|
14
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15
|
+
account_id INTEGER NOT NULL,
|
|
16
|
+
text TEXT NOT NULL,
|
|
17
|
+
created_at VARCHAR(30) NOT NULL,
|
|
18
|
+
updated_at VARCHAR(30) NOT NULL
|
|
19
|
+
);
|
|
20
|
+
CREATE INDEX IF NOT EXISTS $__user_note_account ON $__user_note (account_id, id);
|
|
21
|
+
|
|
22
|
+
#-- failed sign-ins of a user name (the brake), for any name: last_at is in milliseconds
|
|
23
|
+
CREATE TABLE IF NOT EXISTS $__login_failure (
|
|
24
|
+
username VARCHAR(50) NOT NULL PRIMARY KEY,
|
|
25
|
+
failures INTEGER NOT NULL DEFAULT 0,
|
|
26
|
+
last_at BIGINT NOT NULL DEFAULT 0
|
|
27
|
+
);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ServerResponse } from 'http';
|
|
2
|
+
import { ApiHelper, Logger, ServerRequest } from 'lupine.api';
|
|
3
|
+
|
|
4
|
+
// Every answer of the API: { status: 'ok' | 'error', code, message, ...data }. The message is English, for logs and
|
|
5
|
+
// curl; the app shows its own text for each code (app/src/shell/api.ts), in the language of the user.
|
|
6
|
+
const logger = new Logger('note-api');
|
|
7
|
+
|
|
8
|
+
export type Answer = { status: 'ok' | 'error'; code: string; message: string; [key: string]: unknown };
|
|
9
|
+
|
|
10
|
+
/** answers of one user are never cached */
|
|
11
|
+
export const send = (req: ServerRequest, res: ServerResponse, answer: Answer, httpStatus = 200) => {
|
|
12
|
+
ApiHelper.sendJson(req, res, answer as any, httpStatus, { 'Cache-Control': 'no-store' });
|
|
13
|
+
return true;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const ok = (req: ServerRequest, res: ServerResponse, code: string, message: string, data: { [key: string]: unknown } = {}) =>
|
|
17
|
+
send(req, res, { status: 'ok', code, message, ...data });
|
|
18
|
+
|
|
19
|
+
export const fail = (req: ServerRequest, res: ServerResponse, httpStatus: number, code: string, message: string, data: { [key: string]: unknown } = {}) =>
|
|
20
|
+
send(req, res, { status: 'error', code, message, ...data }, httpStatus);
|
|
21
|
+
|
|
22
|
+
/** the JSON object of a POST, or undefined (no body, not JSON, an array) */
|
|
23
|
+
export const body = (req: ServerRequest): { [key: string]: unknown } | undefined => {
|
|
24
|
+
const data = req.locals.json();
|
|
25
|
+
return data && typeof data === 'object' && !Array.isArray(data) ? (data as { [key: string]: unknown }) : undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** A route: an error (the database, a bug) is logged and answered with code server_error, without its details. */
|
|
29
|
+
export const route =
|
|
30
|
+
(handler: (req: ServerRequest, res: ServerResponse) => Promise<boolean>) =>
|
|
31
|
+
async (req: ServerRequest, res: ServerResponse): Promise<boolean> => {
|
|
32
|
+
try {
|
|
33
|
+
return await handler(req, res);
|
|
34
|
+
} catch (e: any) {
|
|
35
|
+
logger.error(`${req.method} ${req.locals.urlWithoutQuery}: ${e && e.message}`);
|
|
36
|
+
if (!res.headersSent) fail(req, res, 500, 'server_error', 'Internal server error.');
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ServerResponse } from 'http';
|
|
2
|
+
import { ApiRouter, IApiBase, ServerRequest } from 'lupine.api';
|
|
3
|
+
import { fail, ok, route } from './answer';
|
|
4
|
+
import { addNote, deleteNote, listNotes, updateNote } from './notes-api';
|
|
5
|
+
import { login, logout, me, register } from './user-api';
|
|
6
|
+
|
|
7
|
+
// The routes under /api. What writes is a POST, and the notes need a session.
|
|
8
|
+
export class Api implements IApiBase {
|
|
9
|
+
protected router = new ApiRouter();
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
// CSRF: a POST from a page of another site is refused. Browsers send Origin with every POST; the apps (iOS, Android,
|
|
13
|
+
// macOS, Windows) send none, and they pass. The session cookie is SameSite=lax as well.
|
|
14
|
+
this.router.setFilter(async (req: ServerRequest, res: ServerResponse) => {
|
|
15
|
+
const method = (req.method || 'GET').toUpperCase();
|
|
16
|
+
const origin = req.headers.origin;
|
|
17
|
+
if (method === 'GET' || method === 'HEAD' || method === 'OPTIONS' || !origin) return false;
|
|
18
|
+
try {
|
|
19
|
+
const originHost = new URL(origin).host.toLowerCase();
|
|
20
|
+
const originHostname = originHost.split(':')[0];
|
|
21
|
+
const requestHost = (req.headers.host || '').toLowerCase();
|
|
22
|
+
// the host names of the app (DOMAINS:<app>= of .env)
|
|
23
|
+
const trustedHosts: string[] = (req.locals?.hostPath?.hosts || []).map((h: string) => h.toLowerCase());
|
|
24
|
+
if (originHost === requestHost || trustedHosts.some((h) => originHostname === h || originHost === h || originHostname.endsWith('.' + h))) return false;
|
|
25
|
+
} catch {
|
|
26
|
+
// not a URL (Origin: null)
|
|
27
|
+
}
|
|
28
|
+
return fail(req, res, 403, 'forbidden_origin', 'Forbidden: invalid request origin.');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
this.router.get('/health', route(async (req, res) => ok(req, res, 'ok', 'OK.')));
|
|
32
|
+
|
|
33
|
+
// accounts
|
|
34
|
+
this.router.post('/register', route(register));
|
|
35
|
+
this.router.post('/login', route(login));
|
|
36
|
+
this.router.post('/logout', route(logout));
|
|
37
|
+
this.router.get('/me', route(me));
|
|
38
|
+
|
|
39
|
+
// the notes of the signed-in user
|
|
40
|
+
this.router.get('/notes', route(listNotes));
|
|
41
|
+
this.router.post('/notes/add', route(addNote));
|
|
42
|
+
this.router.post('/notes/update', route(updateNote));
|
|
43
|
+
this.router.post('/notes/delete', route(deleteNote));
|
|
44
|
+
|
|
45
|
+
// anything else under /api
|
|
46
|
+
this.router.use('*', route(async (req, res) => fail(req, res, 404, 'not_found', 'No such route.')));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public getRouter(): ApiRouter {
|
|
50
|
+
return this.router;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { apiCache, Db } from 'lupine.api';
|
|
2
|
+
|
|
3
|
+
// The tables of the app, made when they are first needed: in the database of the app (sqlite by default:
|
|
4
|
+
// <app>_data/sqlite3.db; DB_TYPE of .env). The same tables, for a database made by hand: api/resources/install.*.sql.
|
|
5
|
+
// $__ is the prefix of the tables (DB_TABLE_PREFIX, tbl_ by default).
|
|
6
|
+
|
|
7
|
+
const SQLITE = [
|
|
8
|
+
`CREATE TABLE IF NOT EXISTS $__account (
|
|
9
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
10
|
+
username VARCHAR(50) NOT NULL UNIQUE,
|
|
11
|
+
password VARCHAR(255) NOT NULL,
|
|
12
|
+
created_at VARCHAR(30) NOT NULL
|
|
13
|
+
)`,
|
|
14
|
+
`CREATE TABLE IF NOT EXISTS $__user_note (
|
|
15
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
16
|
+
account_id INTEGER NOT NULL,
|
|
17
|
+
text TEXT NOT NULL,
|
|
18
|
+
created_at VARCHAR(30) NOT NULL,
|
|
19
|
+
updated_at VARCHAR(30) NOT NULL
|
|
20
|
+
)`,
|
|
21
|
+
'CREATE INDEX IF NOT EXISTS $__user_note_account ON $__user_note (account_id, id)',
|
|
22
|
+
`CREATE TABLE IF NOT EXISTS $__login_failure (
|
|
23
|
+
username VARCHAR(50) NOT NULL PRIMARY KEY,
|
|
24
|
+
failures INTEGER NOT NULL DEFAULT 0,
|
|
25
|
+
last_at BIGINT NOT NULL DEFAULT 0
|
|
26
|
+
)`,
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const MYSQL = [
|
|
30
|
+
`CREATE TABLE IF NOT EXISTS $__account (
|
|
31
|
+
id INTEGER NOT NULL AUTO_INCREMENT,
|
|
32
|
+
username VARCHAR(50) NOT NULL,
|
|
33
|
+
password VARCHAR(255) NOT NULL,
|
|
34
|
+
created_at VARCHAR(30) NOT NULL,
|
|
35
|
+
PRIMARY KEY (id),
|
|
36
|
+
UNIQUE KEY $__account_username (username)
|
|
37
|
+
) DEFAULT CHARSET=utf8mb4`,
|
|
38
|
+
`CREATE TABLE IF NOT EXISTS $__user_note (
|
|
39
|
+
id INTEGER NOT NULL AUTO_INCREMENT,
|
|
40
|
+
account_id INTEGER NOT NULL,
|
|
41
|
+
text TEXT NOT NULL,
|
|
42
|
+
created_at VARCHAR(30) NOT NULL,
|
|
43
|
+
updated_at VARCHAR(30) NOT NULL,
|
|
44
|
+
PRIMARY KEY (id),
|
|
45
|
+
KEY $__user_note_account (account_id, id)
|
|
46
|
+
) DEFAULT CHARSET=utf8mb4`,
|
|
47
|
+
`CREATE TABLE IF NOT EXISTS $__login_failure (
|
|
48
|
+
username VARCHAR(50) NOT NULL,
|
|
49
|
+
failures INTEGER NOT NULL DEFAULT 0,
|
|
50
|
+
last_at BIGINT NOT NULL DEFAULT 0,
|
|
51
|
+
PRIMARY KEY (username)
|
|
52
|
+
) DEFAULT CHARSET=utf8mb4`,
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
let ready: Promise<void> | undefined;
|
|
56
|
+
|
|
57
|
+
/** The database, with the tables. Other databases (sqlserver, oracle): make the tables yourself. */
|
|
58
|
+
export const db = async (): Promise<Db> => {
|
|
59
|
+
const d = apiCache.getDb();
|
|
60
|
+
if (!ready) {
|
|
61
|
+
const list = d.type === 'sqlite' ? SQLITE : d.type === 'mysql' || d.type === 'mariadb' ? MYSQL : [];
|
|
62
|
+
ready = (async () => {
|
|
63
|
+
for (const sql of list) await d.execute(sql);
|
|
64
|
+
})();
|
|
65
|
+
// try again with the next request (the database wasn't there yet ...)
|
|
66
|
+
ready.catch(() => (ready = undefined));
|
|
67
|
+
}
|
|
68
|
+
await ready;
|
|
69
|
+
return d;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** the id of a new row: insertId of sqlite and mysql */
|
|
73
|
+
export const insertedId = (result: any): number => Number((Array.isArray(result) ? result[0] : result)?.insertId);
|
|
74
|
+
/** how many rows an UPDATE or DELETE changed */
|
|
75
|
+
export const changedRows = (result: any): number => Number((Array.isArray(result) ? result[0] : result)?.affectedRows) || 0;
|
|
76
|
+
|
|
77
|
+
/** what is kept as the time: ISO, UTC (the app shows it in its own time zone) */
|
|
78
|
+
export const now = () => new Date().toISOString();
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ServerResponse } from 'http';
|
|
2
|
+
import { ServerRequest } from 'lupine.api';
|
|
3
|
+
import { body, fail, ok } from './answer';
|
|
4
|
+
import { changedRows, db, insertedId, now } from './db';
|
|
5
|
+
import { needSession } from './user-api';
|
|
6
|
+
|
|
7
|
+
// The notes of the signed-in user: every query has the user's id in its WHERE, so nobody reaches the notes of another
|
|
8
|
+
// user, not even with the id of one.
|
|
9
|
+
const MAX_TEXT = 2000; // characters (an emoji is one)
|
|
10
|
+
const MAX_NOTES = 500; // of a user
|
|
11
|
+
const PAGE = 100; // notes of one answer, newest first
|
|
12
|
+
|
|
13
|
+
type Note = { id: number; text: string; created_at: string; updated_at: string };
|
|
14
|
+
const FIELDS = 'id, text, created_at, updated_at';
|
|
15
|
+
const plain = (n: any): Note => ({ id: Number(n.id), text: String(n.text), created_at: String(n.created_at), updated_at: String(n.updated_at) });
|
|
16
|
+
|
|
17
|
+
/** the text of a note: 1 to MAX_TEXT characters, or null */
|
|
18
|
+
const noteText = (value: unknown) => {
|
|
19
|
+
const text = typeof value === 'string' ? value.trim() : '';
|
|
20
|
+
const length = Array.from(text).length;
|
|
21
|
+
return length >= 1 && length <= MAX_TEXT ? text : null;
|
|
22
|
+
};
|
|
23
|
+
const noteId = (value: unknown) => (typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : null);
|
|
24
|
+
const badText = (req: ServerRequest, res: ServerResponse) => fail(req, res, 400, 'bad_note', `A note has 1 to ${MAX_TEXT} characters.`);
|
|
25
|
+
const notFound = (req: ServerRequest, res: ServerResponse) => fail(req, res, 404, 'note_not_found', 'No such note.');
|
|
26
|
+
|
|
27
|
+
/** GET /api/notes?before=<id>: the newest notes (before that id: the next page); more: there are older ones */
|
|
28
|
+
export const listNotes = async (req: ServerRequest, res: ServerResponse) => {
|
|
29
|
+
const user = await needSession(req, res);
|
|
30
|
+
if (!user) return true;
|
|
31
|
+
const before = Number(req.locals.query.get('before') || 0);
|
|
32
|
+
const params: number[] = [user.id];
|
|
33
|
+
let sql = `SELECT ${FIELDS} FROM $__user_note WHERE account_id = ?`;
|
|
34
|
+
if (Number.isInteger(before) && before > 0) {
|
|
35
|
+
sql += ' AND id < ?';
|
|
36
|
+
params.push(before);
|
|
37
|
+
}
|
|
38
|
+
// one more than a page: are there more?
|
|
39
|
+
const rows = await (await db()).select(`${sql} ORDER BY id DESC LIMIT ${PAGE + 1}`, params);
|
|
40
|
+
return ok(req, res, 'ok', 'Notes.', { notes: rows.slice(0, PAGE).map(plain), more: rows.length > PAGE });
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** POST /api/notes/add { text } */
|
|
44
|
+
export const addNote = async (req: ServerRequest, res: ServerResponse) => {
|
|
45
|
+
const user = await needSession(req, res);
|
|
46
|
+
if (!user) return true;
|
|
47
|
+
const data = body(req);
|
|
48
|
+
if (!data) return fail(req, res, 400, 'bad_request', 'Wrong data.');
|
|
49
|
+
const text = noteText(data.text);
|
|
50
|
+
if (text === null) return badText(req, res);
|
|
51
|
+
const d = await db();
|
|
52
|
+
const [{ count }] = await d.select('SELECT COUNT(*) AS count FROM $__user_note WHERE account_id = ?', [user.id]);
|
|
53
|
+
if (Number(count) >= MAX_NOTES) return fail(req, res, 400, 'too_many_notes', `At most ${MAX_NOTES} notes: delete some first.`, { max: MAX_NOTES });
|
|
54
|
+
const at = now();
|
|
55
|
+
const id = insertedId(await d.execute('INSERT INTO $__user_note (account_id, text, created_at, updated_at) VALUES (?, ?, ?, ?)', [user.id, text, at, at]));
|
|
56
|
+
return ok(req, res, 'note_added', 'Note added.', { note: { id, text, created_at: at, updated_at: at } });
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** POST /api/notes/update { id, text } */
|
|
60
|
+
export const updateNote = async (req: ServerRequest, res: ServerResponse) => {
|
|
61
|
+
const user = await needSession(req, res);
|
|
62
|
+
if (!user) return true;
|
|
63
|
+
const data = body(req);
|
|
64
|
+
if (!data) return fail(req, res, 400, 'bad_request', 'Wrong data.');
|
|
65
|
+
const id = noteId(data.id);
|
|
66
|
+
if (id === null) return fail(req, res, 400, 'bad_request', 'Wrong id.');
|
|
67
|
+
const text = noteText(data.text);
|
|
68
|
+
if (text === null) return badText(req, res);
|
|
69
|
+
const d = await db();
|
|
70
|
+
const result = await d.execute('UPDATE $__user_note SET text = ?, updated_at = ? WHERE id = ? AND account_id = ?', [text, now(), id, user.id]);
|
|
71
|
+
if (!changedRows(result)) return notFound(req, res);
|
|
72
|
+
const [note] = await d.select(`SELECT ${FIELDS} FROM $__user_note WHERE id = ? AND account_id = ?`, [id, user.id]);
|
|
73
|
+
return note ? ok(req, res, 'note_updated', 'Note updated.', { note: plain(note) }) : notFound(req, res);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** POST /api/notes/delete { id } */
|
|
77
|
+
export const deleteNote = async (req: ServerRequest, res: ServerResponse) => {
|
|
78
|
+
const user = await needSession(req, res);
|
|
79
|
+
if (!user) return true;
|
|
80
|
+
const data = body(req);
|
|
81
|
+
if (!data) return fail(req, res, 400, 'bad_request', 'Wrong data.');
|
|
82
|
+
const id = noteId(data.id);
|
|
83
|
+
if (id === null) return fail(req, res, 400, 'bad_request', 'Wrong id.');
|
|
84
|
+
const result = await (await db()).execute('DELETE FROM $__user_note WHERE id = ? AND account_id = ?', [id, user.id]);
|
|
85
|
+
return changedRows(result) ? ok(req, res, 'note_deleted', 'Note deleted.', { id }) : notFound(req, res);
|
|
86
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ApiRouter, IApiBase, StaticServer } from 'lupine.api';
|
|
2
|
+
import { Api } from './api';
|
|
3
|
+
|
|
4
|
+
// /api: the API of the app (api.ts: accounts, sessions, notes); everything else is the web files (the page, the app)
|
|
5
|
+
// and the pages rendered on the server.
|
|
6
|
+
export class RootApi implements IApiBase {
|
|
7
|
+
protected router = new ApiRouter();
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
this.router.use('/api', new Api().getRouter());
|
|
11
|
+
|
|
12
|
+
const staticServer = new StaticServer();
|
|
13
|
+
this.router.use('*', staticServer.processRequest.bind(staticServer));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public getRouter(): ApiRouter {
|
|
17
|
+
return this.router;
|
|
18
|
+
}
|
|
19
|
+
}
|