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
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { ServerResponse } from 'http';
|
|
2
|
+
import { CryptoUtils, getSessionExpireDays, isHttpsRequest, isSessionExpired, Logger, ServerRequest } from 'lupine.api';
|
|
3
|
+
import { body, fail, ok } from './answer';
|
|
4
|
+
import { db, insertedId, now } from './db';
|
|
5
|
+
|
|
6
|
+
// Accounts and sessions.
|
|
7
|
+
//
|
|
8
|
+
// The password is kept as a salted scrypt hash (CryptoUtils.hashPassword: "scrypt$<salt>$<hash>") and compared in
|
|
9
|
+
// constant time (CryptoUtils.verifyPassword). A sign-in answers the same for an unknown user name and a wrong password,
|
|
10
|
+
// and takes as long (an unknown name is checked against a hash of nothing).
|
|
11
|
+
//
|
|
12
|
+
// The session is a token encrypted with CRYPTO_KEY of .env (AES-256 and an HMAC: it can't be read or changed without
|
|
13
|
+
// the key). It holds the id and the name of the user, the time of the sign-in, and a hash of the stored password hash,
|
|
14
|
+
// so a new password ends every session of before. A browser gets it as the httpOnly cookie _token; an app (iOS, Android,
|
|
15
|
+
// macOS, Windows: no cookie store) in the answer, and sends it back as the cookie itself. Browsers send Origin with
|
|
16
|
+
// every POST and the apps don't, so the token is in the answer only without Origin: a script in a page never sees it.
|
|
17
|
+
|
|
18
|
+
const logger = new Logger('user-api');
|
|
19
|
+
|
|
20
|
+
export const COOKIE = '_token';
|
|
21
|
+
const NAME_RE = /^[a-z0-9_.@-]{3,50}$/;
|
|
22
|
+
const PASSWORD_MIN = 6;
|
|
23
|
+
const PASSWORD_MAX = 256;
|
|
24
|
+
// failed sign-ins of a user name: after MAX_FAILURES in a row, none for LOCK_MINUTES after the last one. Kept in the
|
|
25
|
+
// database, so every worker process and a restart know them; for every name, known or not, so the brake doesn't tell
|
|
26
|
+
// which names have an account. Limit the requests in front of the server, too (nginx: limit_req).
|
|
27
|
+
const MAX_FAILURES = 5;
|
|
28
|
+
const LOCK_MINUTES = 15;
|
|
29
|
+
const LOCK_MS = LOCK_MINUTES * 60 * 1000;
|
|
30
|
+
// SESSION_EXPIRE_DAYS of .env, 90 days by default
|
|
31
|
+
const expireDays = () => getSessionExpireDays('SESSION_EXPIRE_DAYS', 90);
|
|
32
|
+
|
|
33
|
+
/** a user name as it is kept: without spaces around it, in lower case ("Ada" and "ada" are one account) */
|
|
34
|
+
const normalName = (value: unknown) => (typeof value === 'string' ? value.trim().toLowerCase() : '');
|
|
35
|
+
const validPassword = (value: unknown): value is string => typeof value === 'string' && value.length >= PASSWORD_MIN && value.length <= PASSWORD_MAX;
|
|
36
|
+
|
|
37
|
+
// an unknown name is checked against this, so that it takes as long as a wrong password
|
|
38
|
+
const NOBODY = CryptoUtils.hashPassword(CryptoUtils.randomString(16));
|
|
39
|
+
|
|
40
|
+
export type SessionUser = { id: number; username: string };
|
|
41
|
+
type Account = { id: number; username: string; password: string };
|
|
42
|
+
type Token = { i: number; u: string; t: number; h: string };
|
|
43
|
+
|
|
44
|
+
const cryptoKey = () => process.env['CRYPTO_KEY'] || '';
|
|
45
|
+
|
|
46
|
+
/** No CRYPTO_KEY in .env: sessions can't be made or read. Answers that and returns true. */
|
|
47
|
+
export const noCryptoKey = (req: ServerRequest, res: ServerResponse) => {
|
|
48
|
+
if (cryptoKey()) return false;
|
|
49
|
+
logger.error('CRYPTO_KEY is not set in .env: no sign-in is possible');
|
|
50
|
+
return fail(req, res, 500, 'no_crypto_key', 'The server has no CRYPTO_KEY in its .env.');
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** a hash of the stored password hash: a new password changes it */
|
|
54
|
+
const passwordStamp = (a: Account) => CryptoUtils.sha256(`${a.id}:${a.username}:${a.password}`);
|
|
55
|
+
|
|
56
|
+
const startSession = (req: ServerRequest, res: ServerResponse, a: Account, code: string, message: string) => {
|
|
57
|
+
const token: Token = { i: a.id, u: a.username, t: Date.now(), h: passwordStamp(a) };
|
|
58
|
+
const encrypted = CryptoUtils.encrypt(JSON.stringify(token), cryptoKey());
|
|
59
|
+
req.locals.setCookie(COOKIE, encrypted, { expireDays: expireDays(), path: '/', httpOnly: true, secure: isHttpsRequest(req), sameSite: 'lax' });
|
|
60
|
+
return ok(req, res, code, message, { user: { id: a.id, username: a.username }, token: req.headers.origin ? undefined : encrypted });
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** The user of the session (the cookie _token), or null: none, not ours, too old, an account that is gone, a new password. */
|
|
64
|
+
export const sessionUser = async (req: ServerRequest): Promise<SessionUser | null> => {
|
|
65
|
+
const encrypted = req.locals.cookies().get(COOKIE, '');
|
|
66
|
+
if (!encrypted || !cryptoKey()) return null;
|
|
67
|
+
let token: Token;
|
|
68
|
+
try {
|
|
69
|
+
token = JSON.parse(CryptoUtils.decrypt(encrypted, cryptoKey()));
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
if (!token || !Number.isInteger(token.i) || typeof token.u !== 'string' || typeof token.h !== 'string' || isSessionExpired(token.t, expireDays())) return null;
|
|
74
|
+
const [a] = await (await db()).select<Account>('SELECT id, username, password FROM $__account WHERE id = ?', [token.i]);
|
|
75
|
+
if (!a || a.username !== token.u || !CryptoUtils.timingSafeEqual(passwordStamp(a), token.h)) return null;
|
|
76
|
+
return { id: Number(a.id), username: a.username };
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** The user of the session, or answers not_signed_in (or no_crypto_key) and returns null. */
|
|
80
|
+
export const needSession = async (req: ServerRequest, res: ServerResponse): Promise<SessionUser | null> => {
|
|
81
|
+
if (noCryptoKey(req, res)) return null;
|
|
82
|
+
const user = await sessionUser(req);
|
|
83
|
+
if (!user) fail(req, res, 401, 'not_signed_in', 'Not signed in.');
|
|
84
|
+
return user;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// ---- the brake on failed sign-ins
|
|
88
|
+
|
|
89
|
+
let cleaned = 0;
|
|
90
|
+
/** minutes until the name may try again, or 0 */
|
|
91
|
+
const lockedMinutes = async (username: string) => {
|
|
92
|
+
const [row] = await (await db()).select('SELECT failures, last_at FROM $__login_failure WHERE username = ?', [username]);
|
|
93
|
+
const left = row && Number(row.failures) >= MAX_FAILURES ? Number(row.last_at) + LOCK_MS - Date.now() : 0;
|
|
94
|
+
return left > 0 ? Math.ceil(left / 60000) : 0;
|
|
95
|
+
};
|
|
96
|
+
const recordFailure = async (username: string) => {
|
|
97
|
+
const d = await db();
|
|
98
|
+
const at = Date.now();
|
|
99
|
+
const [row] = await d.select('SELECT failures, last_at FROM $__login_failure WHERE username = ?', [username]);
|
|
100
|
+
if (row) {
|
|
101
|
+
// a failure long after the last one starts counting again
|
|
102
|
+
const failures = at - Number(row.last_at) > LOCK_MS ? 1 : Number(row.failures) + 1;
|
|
103
|
+
await d.execute('UPDATE $__login_failure SET failures = ?, last_at = ? WHERE username = ?', [failures, at, username]);
|
|
104
|
+
} else {
|
|
105
|
+
try {
|
|
106
|
+
await d.execute('INSERT INTO $__login_failure (username, failures, last_at) VALUES (?, ?, ?)', [username, 1, at]);
|
|
107
|
+
} catch {
|
|
108
|
+
// another request inserted it just now
|
|
109
|
+
await d.execute('UPDATE $__login_failure SET failures = failures + 1, last_at = ? WHERE username = ?', [at, username]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// the names nobody tried for a while (now and then)
|
|
113
|
+
if (at - cleaned > LOCK_MS) {
|
|
114
|
+
cleaned = at;
|
|
115
|
+
await d.execute('DELETE FROM $__login_failure WHERE last_at < ?', [at - LOCK_MS]);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// ---- the routes
|
|
120
|
+
|
|
121
|
+
/** POST /api/register { username, password }: a new account, signed in at once */
|
|
122
|
+
export const register = async (req: ServerRequest, res: ServerResponse) => {
|
|
123
|
+
if (noCryptoKey(req, res)) return true;
|
|
124
|
+
const data = body(req);
|
|
125
|
+
if (!data) return fail(req, res, 400, 'bad_request', 'Wrong data.');
|
|
126
|
+
const username = normalName(data.username);
|
|
127
|
+
if (!NAME_RE.test(username)) return fail(req, res, 400, 'bad_username', 'User name: 3 to 50 characters (letters, digits, _ . @ -).');
|
|
128
|
+
if (!validPassword(data.password)) return fail(req, res, 400, 'bad_password', `Password: ${PASSWORD_MIN} to ${PASSWORD_MAX} characters.`);
|
|
129
|
+
const d = await db();
|
|
130
|
+
const taken = () => fail(req, res, 409, 'username_taken', 'This user name is taken.');
|
|
131
|
+
if ((await d.select('SELECT id FROM $__account WHERE username = ?', [username])).length) return taken();
|
|
132
|
+
const password = CryptoUtils.hashPassword(data.password);
|
|
133
|
+
let id: number;
|
|
134
|
+
try {
|
|
135
|
+
id = insertedId(await d.execute('INSERT INTO $__account (username, password, created_at) VALUES (?, ?, ?)', [username, password, now()]));
|
|
136
|
+
} catch (e) {
|
|
137
|
+
// UNIQUE: registered by another request at the same moment
|
|
138
|
+
if ((await d.select('SELECT id FROM $__account WHERE username = ?', [username])).length) return taken();
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
141
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
142
|
+
const [row] = await d.select('SELECT id FROM $__account WHERE username = ?', [username]);
|
|
143
|
+
id = Number(row.id);
|
|
144
|
+
}
|
|
145
|
+
logger.info(`new account ${id}`);
|
|
146
|
+
return startSession(req, res, { id, username, password }, 'registered', 'Account created.');
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/** POST /api/login { username, password } */
|
|
150
|
+
export const login = async (req: ServerRequest, res: ServerResponse) => {
|
|
151
|
+
if (noCryptoKey(req, res)) return true;
|
|
152
|
+
const data = body(req);
|
|
153
|
+
if (!data) return fail(req, res, 400, 'bad_request', 'Wrong data.');
|
|
154
|
+
const username = normalName(data.username);
|
|
155
|
+
const password = data.password;
|
|
156
|
+
const failed = () => fail(req, res, 401, 'login_failed', 'Wrong user name or password.');
|
|
157
|
+
// such a name has no account, and a password that long is never checked (scrypt of megabytes)
|
|
158
|
+
if (!NAME_RE.test(username) || typeof password !== 'string' || !password || password.length > PASSWORD_MAX) return failed();
|
|
159
|
+
const minutes = await lockedMinutes(username);
|
|
160
|
+
if (minutes) return fail(req, res, 429, 'too_many_attempts', `Too many failed sign-ins. Try again in ${minutes} minutes.`, { minutes });
|
|
161
|
+
const d = await db();
|
|
162
|
+
const [a] = await d.select<Account>('SELECT id, username, password FROM $__account WHERE username = ?', [username]);
|
|
163
|
+
const valid = CryptoUtils.verifyPassword(password, a ? String(a.password) : NOBODY);
|
|
164
|
+
if (!a || !valid) {
|
|
165
|
+
await recordFailure(username);
|
|
166
|
+
return failed();
|
|
167
|
+
}
|
|
168
|
+
await d.execute('DELETE FROM $__login_failure WHERE username = ?', [username]);
|
|
169
|
+
return startSession(req, res, { id: Number(a.id), username: a.username, password: String(a.password) }, 'signed_in', 'Signed in.');
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/** POST /api/logout: the browser forgets the cookie; an app forgets its token itself */
|
|
173
|
+
export const logout = async (req: ServerRequest, res: ServerResponse) => {
|
|
174
|
+
req.locals.setCookie(COOKIE, '', { expireDays: -1, path: '/', httpOnly: true, secure: isHttpsRequest(req), sameSite: 'lax' });
|
|
175
|
+
return ok(req, res, 'signed_out', 'Signed out.');
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/** GET /api/me: who is signed in */
|
|
179
|
+
export const me = async (req: ServerRequest, res: ServerResponse) => {
|
|
180
|
+
const user = await needSession(req, res);
|
|
181
|
+
return user ? ok(req, res, 'ok', 'Signed in.', { user }) : true;
|
|
182
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lupine-template-fullstack-note-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Notes kept on the server, with accounts: a lupine.native app (tabs, pages, themes, languages, sign-in) for iOS, Android, macOS, Windows and the web.",
|
|
6
|
+
"lupineNative": {
|
|
7
|
+
"name": "LupineNotes",
|
|
8
|
+
"id": "com.uuware.lupine.notes",
|
|
9
|
+
"entry": {
|
|
10
|
+
"native": "src/index.native.tsx",
|
|
11
|
+
"test": "src/index.test.tsx",
|
|
12
|
+
"web": "src/index.web.tsx"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"lupine.native.components": "^1.1.0",
|
|
17
|
+
"lupine.native.core": "^1.1.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import './shell/texts';
|
|
2
|
+
import { createEffect, onBack, onMount, Text, untrack, View } from 'lupine.native.core';
|
|
3
|
+
import { col, Icon, NavBar, NavItem, OverlayHost, Pages, router, syncAppearance, t, Toast, tr, val } from 'lupine.native.components';
|
|
4
|
+
import { Components } from './pages/components';
|
|
5
|
+
import { About, Item, NotFound } from './pages/details';
|
|
6
|
+
import { Discover } from './pages/discover';
|
|
7
|
+
import { Home } from './pages/home';
|
|
8
|
+
import { Inbox, unread } from './pages/inbox';
|
|
9
|
+
import { Login } from './pages/login';
|
|
10
|
+
import { Me } from './pages/me';
|
|
11
|
+
import { Notes } from './pages/notes';
|
|
12
|
+
import { Settings } from './pages/settings';
|
|
13
|
+
import * as icons from 'lupine.core/icons';
|
|
14
|
+
import { api } from './shell/api';
|
|
15
|
+
|
|
16
|
+
const items: NavItem[] = [
|
|
17
|
+
{ key: '/', label: tr('nav.home', 'Home'), icon: icons.home, testID: 'tab-home' },
|
|
18
|
+
{ key: '/components', label: tr('nav.components', 'Components'), icon: icons.grid, testID: 'tab-components' },
|
|
19
|
+
{ key: '/discover', label: tr('nav.discover', 'Create'), icon: icons.plus, raised: true, testID: 'tab-discover' },
|
|
20
|
+
{ key: '/inbox', label: tr('nav.inbox', 'Inbox'), icon: icons.bell, badge: unread, testID: 'tab-inbox' },
|
|
21
|
+
{ key: '/me', label: tr('nav.me', 'Me'), icon: icons.user, testID: 'tab-me' },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
// the title of the browser's tab (the window on desktops) while a tab is shown; pages over the tabs: the name of the app
|
|
25
|
+
const appName = () => t('app.name', 'Lupine Notes');
|
|
26
|
+
const tabTitle = (key: string) => () => (key === '/' ? appName() : `${val(items.find((i) => i.key === key)?.label ?? '')} | ${appName()}`);
|
|
27
|
+
|
|
28
|
+
/** Wide windows: the menu stays on the left. Phones: a tab bar at the bottom, pushed pages cover it. */
|
|
29
|
+
export const App = () => {
|
|
30
|
+
untrack(syncAppearance); // before the first control is created
|
|
31
|
+
createEffect(syncAppearance);
|
|
32
|
+
// who is signed in; not while a server renders the page
|
|
33
|
+
onMount(() => void api.refresh());
|
|
34
|
+
let last = 0;
|
|
35
|
+
onBack(() => {
|
|
36
|
+
if (Date.now() - last < 2000) return false;
|
|
37
|
+
last = Date.now();
|
|
38
|
+
Toast.info(t('ln.pressAgainToExit', 'Press back again to exit'));
|
|
39
|
+
});
|
|
40
|
+
return (
|
|
41
|
+
<View style={{ flex: 1, backgroundColor: col('bg') }}>
|
|
42
|
+
<Pages
|
|
43
|
+
side={240}
|
|
44
|
+
title={appName}
|
|
45
|
+
tabs={[
|
|
46
|
+
{ path: '/', page: Home, title: tabTitle('/') },
|
|
47
|
+
{ path: '/components', page: Components, title: tabTitle('/components') },
|
|
48
|
+
{ path: '/discover', page: Discover, title: tabTitle('/discover') },
|
|
49
|
+
{ path: '/inbox', page: Inbox, title: tabTitle('/inbox') },
|
|
50
|
+
{ path: '/me', page: Me, title: tabTitle('/me') },
|
|
51
|
+
]}
|
|
52
|
+
routes={[
|
|
53
|
+
{ path: '/item/:id', page: ({ id }) => <Item id={id} /> },
|
|
54
|
+
{ path: '/about', page: () => <About /> },
|
|
55
|
+
{ path: '/settings', page: () => <Settings /> },
|
|
56
|
+
{ path: '/notes', page: () => <Notes /> },
|
|
57
|
+
{ path: '/login', page: () => <Login /> },
|
|
58
|
+
]}
|
|
59
|
+
notFound={() => <NotFound />}
|
|
60
|
+
>
|
|
61
|
+
{/* one menu: a tab bar at the bottom on phones, a column on the left on wide windows (css, also on the server) */}
|
|
62
|
+
<NavBar
|
|
63
|
+
items={items} active={router.tab} onPress={router.navigate} width={240}
|
|
64
|
+
header={
|
|
65
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 10, padding: 18 }}>
|
|
66
|
+
<Icon name={icons.logo} size={26} color={col('primary')} />
|
|
67
|
+
<Text style={{ fontSize: 17, fontWeight: '700', color: col('text') }}>{tr('app.name', 'Lupine Notes')}</Text>
|
|
68
|
+
</View>
|
|
69
|
+
}
|
|
70
|
+
/>
|
|
71
|
+
</Pages>
|
|
72
|
+
<OverlayHost />
|
|
73
|
+
</View>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/// <reference path="../../../../node_modules/lupine.native.core/src/native-globals.d.ts" />
|
|
2
|
+
// Walks through the app inside a native shell built with --test: presses the real views, types into the real fields.
|
|
3
|
+
// There is no server: first the API is an address where nobody answers (the app shows that, it doesn't break), then
|
|
4
|
+
// fetch is a small fake of the API (api/src/service): accounts, the session, notes, errors of the server.
|
|
5
|
+
import { Platform, storage, windowInfo } from 'lupine.native.core';
|
|
6
|
+
import { isWide, setLang, setThemePref } from 'lupine.native.components';
|
|
7
|
+
import { runApp } from 'lupine.native.core/native';
|
|
8
|
+
import { App } from './app';
|
|
9
|
+
import { api, setServerAddress } from './shell/api';
|
|
10
|
+
|
|
11
|
+
const native = globalThis.__lupine;
|
|
12
|
+
const act = (id: string, action: string, arg?: unknown) => native.test!(id, action, arg);
|
|
13
|
+
const text = (id: string) => act(id, 'text');
|
|
14
|
+
const sleep = (ms: number) => new Promise<void>((done) => setTimeout(done, ms));
|
|
15
|
+
const exists = (id: string) => act(id, 'x') !== '<missing>';
|
|
16
|
+
|
|
17
|
+
let passed = 0;
|
|
18
|
+
let failed = 0;
|
|
19
|
+
const check = (name: string, actual: unknown, expected: unknown) => {
|
|
20
|
+
const ok = actual === expected;
|
|
21
|
+
if (ok) passed++;
|
|
22
|
+
else failed++;
|
|
23
|
+
console.log(`TEST ${ok ? 'ok ' : 'FAIL'} ${name}${ok ? '' : ` -> ${JSON.stringify(actual)}, expected ${JSON.stringify(expected)}`}`);
|
|
24
|
+
};
|
|
25
|
+
/** The script that runs the test takes a picture; desktops do it themselves. */
|
|
26
|
+
const shot = async (name: string) => {
|
|
27
|
+
await sleep(250);
|
|
28
|
+
if (Platform.OS === 'macos' || Platform.OS === 'windows') act('', 'screenshot', `shot-${name}.png`);
|
|
29
|
+
console.log(`SHOT ${name}`);
|
|
30
|
+
await sleep(Platform.OS === 'macos' || Platform.OS === 'windows' ? 50 : 2500);
|
|
31
|
+
};
|
|
32
|
+
const press = async (id: string, wait = 600) => {
|
|
33
|
+
check(`press ${id}`, exists(id) && act(id, 'click'), true);
|
|
34
|
+
await sleep(wait);
|
|
35
|
+
};
|
|
36
|
+
const type = async (id: string, value: string) => {
|
|
37
|
+
act(id, 'focus');
|
|
38
|
+
await sleep(200);
|
|
39
|
+
act(id, 'type', value);
|
|
40
|
+
await sleep(200);
|
|
41
|
+
};
|
|
42
|
+
const toast = () => (exists('toast-text') ? text('toast-text') : '');
|
|
43
|
+
/** the toast, when it comes (on Windows an address where nobody answers takes about 2 s to fail) */
|
|
44
|
+
const toastSoon = async (ms = 6000) => {
|
|
45
|
+
for (let t = 0; t < ms && !toast(); t += 100) await sleep(100);
|
|
46
|
+
return toast();
|
|
47
|
+
};
|
|
48
|
+
const at = (id: string) => Math.round(act(id, 'screenX'));
|
|
49
|
+
|
|
50
|
+
// ---- the fake API: what the app sends, and the answers of api/src/service (user-api.ts, notes-api.ts)
|
|
51
|
+
const realFetch = globalThis.fetch;
|
|
52
|
+
type Sent = { method: string; path: string; query: string; cookie: string; type: string; body: any };
|
|
53
|
+
const sent: Sent[] = [];
|
|
54
|
+
const last = () => sent[sent.length - 1] || ({} as Sent);
|
|
55
|
+
/** ok; 500: a page of an error instead of JSON; offline: nobody answers; expired: the session is over; nokey: no CRYPTO_KEY */
|
|
56
|
+
let mode: 'ok' | '500' | 'offline' | 'expired' | 'nokey' = 'ok';
|
|
57
|
+
const accounts = new Map<string, { id: number; password: string }>();
|
|
58
|
+
const notes: { id: number; owner: string; text: string; created_at: string; updated_at: string }[] = [];
|
|
59
|
+
const PAGE = 3; // the API: 100
|
|
60
|
+
let ids = 0;
|
|
61
|
+
const fakeFetch = async (url: string, init: { method?: string; headers?: { [name: string]: string }; body?: string } = {}) => {
|
|
62
|
+
const [path, query = ''] = url.replace(/^\w+:\/\/[^/]+/, '').split('?');
|
|
63
|
+
const cookie = init.headers?.Cookie || '';
|
|
64
|
+
const body = init.body ? JSON.parse(init.body) : undefined;
|
|
65
|
+
sent.push({ method: init.method || 'GET', path, query, cookie, type: init.headers?.['Content-Type'] || '', body });
|
|
66
|
+
if (mode === 'offline') throw new TypeError('Network request failed');
|
|
67
|
+
const reply = (status: number, value: object | string) => {
|
|
68
|
+
const t = typeof value === 'string' ? value : JSON.stringify(value);
|
|
69
|
+
return { ok: status < 300, status, statusText: '', url, headers: new Headers(), text: async () => t, json: async () => JSON.parse(t), arrayBuffer: async () => new ArrayBuffer(0) };
|
|
70
|
+
};
|
|
71
|
+
if (mode === '500') return reply(500, '<html><body>Internal Server Error</body></html>');
|
|
72
|
+
if (mode === 'nokey') return reply(500, { status: 'error', code: 'no_crypto_key', message: 'server: no_crypto_key' });
|
|
73
|
+
const answer = (code: string, data: object = {}) => reply(200, { status: 'ok', code, message: `server: ${code}`, ...data });
|
|
74
|
+
const error = (status: number, code: string, data: object = {}) => reply(status, { status: 'error', code, message: `server: ${code}`, ...data });
|
|
75
|
+
const token = decodeURIComponent((/(?:^|; )_token=([^;]*)/.exec(cookie) || [])[1] || '');
|
|
76
|
+
const owner = mode === 'expired' ? '' : (/^tok\+(\w+)\/=$/.exec(token) || [])[1] || '';
|
|
77
|
+
const session = (name: string) => ({ user: { id: accounts.get(name)!.id, username: name }, token: `tok+${name}/=` }); // base64, as CryptoUtils.encrypt
|
|
78
|
+
const name = String(body?.username || '').trim().toLowerCase();
|
|
79
|
+
if (path === '/api/register') {
|
|
80
|
+
if (!/^[a-z0-9_.@-]{3,50}$/.test(name)) return error(400, 'bad_username');
|
|
81
|
+
if (accounts.has(name)) return error(409, 'username_taken');
|
|
82
|
+
accounts.set(name, { id: ++ids, password: body.password });
|
|
83
|
+
return answer('registered', session(name));
|
|
84
|
+
}
|
|
85
|
+
if (path === '/api/login') return accounts.get(name)?.password === body.password ? answer('signed_in', session(name)) : error(401, 'login_failed');
|
|
86
|
+
if (path === '/api/logout') return answer('signed_out');
|
|
87
|
+
if (!owner) return error(401, 'not_signed_in');
|
|
88
|
+
if (path === '/api/me') return answer('ok', { user: session(owner).user });
|
|
89
|
+
const mine = notes.filter((n) => n.owner === owner).sort((a, b) => b.id - a.id);
|
|
90
|
+
const plain = ({ owner: _, ...n }: (typeof notes)[0]) => n;
|
|
91
|
+
if (path === '/api/notes') {
|
|
92
|
+
const before = Number(new URLSearchParams(query).get('before') || 0);
|
|
93
|
+
const list = mine.filter((n) => !before || n.id < before);
|
|
94
|
+
return answer('ok', { notes: list.slice(0, PAGE).map(plain), more: list.length > PAGE });
|
|
95
|
+
}
|
|
96
|
+
if (path === '/api/notes/add') {
|
|
97
|
+
const value = String(body.text || '').trim();
|
|
98
|
+
if (!value) return error(400, 'bad_note');
|
|
99
|
+
const n = { id: ++ids, owner, text: value, created_at: '2026-12-04T09:30:00.000Z', updated_at: '2026-12-04T09:30:00.000Z' };
|
|
100
|
+
notes.push(n);
|
|
101
|
+
return answer('note_added', { note: plain(n) });
|
|
102
|
+
}
|
|
103
|
+
const i = notes.findIndex((n) => n.id === body.id && n.owner === owner);
|
|
104
|
+
if (path === '/api/notes/update') return i < 0 ? error(404, 'note_not_found') : ((notes[i].text = body.text), answer('note_updated', { note: plain(notes[i]) }));
|
|
105
|
+
if (path === '/api/notes/delete') return i < 0 ? error(404, 'note_not_found') : (notes.splice(i, 1), answer('note_deleted', { id: body.id }));
|
|
106
|
+
return error(404, 'not_found');
|
|
107
|
+
};
|
|
108
|
+
const useFake = (on: boolean) => ((globalThis as any).fetch = on ? fakeFetch : realFetch);
|
|
109
|
+
|
|
110
|
+
// a known start: signed out, and nobody answers at port 9
|
|
111
|
+
setThemePref('light');
|
|
112
|
+
setLang('en');
|
|
113
|
+
api.forget();
|
|
114
|
+
setServerAddress('http://127.0.0.1:9');
|
|
115
|
+
|
|
116
|
+
const started = Date.now();
|
|
117
|
+
runApp(App);
|
|
118
|
+
console.log(`TEST mounted in ${Date.now() - started} ms, window ${JSON.stringify(windowInfo())}`);
|
|
119
|
+
|
|
120
|
+
const main = async () => {
|
|
121
|
+
for (let i = 0; i < 100 && !(act('page-home', 'width') > 0); i++) await sleep(100);
|
|
122
|
+
await sleep(500);
|
|
123
|
+
const left = isWide() ? 240 : 0;
|
|
124
|
+
check('home', text('app-name'), 'Lupine Notes');
|
|
125
|
+
check('home fills the window', Math.round(act('page-home', 'width')), Math.round(windowInfo().width - left));
|
|
126
|
+
await shot('1-home');
|
|
127
|
+
|
|
128
|
+
// settings: push, sheet, theme, language, slider, switch, the server
|
|
129
|
+
await press('shortcut-settings', 800);
|
|
130
|
+
check('the page slid in', at('page-settings'), left);
|
|
131
|
+
check('theme row', text('settings-theme-value'), 'Light');
|
|
132
|
+
check('the server of the app', text('settings-server-value'), 'http://127.0.0.1:9');
|
|
133
|
+
await press('settings-theme');
|
|
134
|
+
await shot('2-sheet');
|
|
135
|
+
await press('option-dark');
|
|
136
|
+
check('sheet closed', exists('sheet'), false);
|
|
137
|
+
check('theme changed', text('settings-theme-value'), 'Dark');
|
|
138
|
+
await shot('3-dark');
|
|
139
|
+
check('switch', act('settings-push', 'value'), true);
|
|
140
|
+
act('settings-push', 'toggle');
|
|
141
|
+
await sleep(100);
|
|
142
|
+
check('switch toggled', act('settings-push', 'value'), false);
|
|
143
|
+
check('slider', Math.abs(act('size-slider', 'value') - 1) < 0.05, true);
|
|
144
|
+
await press('settings-language');
|
|
145
|
+
await press('option-zh-CN');
|
|
146
|
+
check('language', text('settings-language-value'), '简体中文');
|
|
147
|
+
check('Chinese: the server row', text('settings-server-value'), 'http://127.0.0.1:9');
|
|
148
|
+
await shot('4-chinese');
|
|
149
|
+
await press('settings-language');
|
|
150
|
+
await press('option-en');
|
|
151
|
+
await press('settings-theme');
|
|
152
|
+
await press('option-light');
|
|
153
|
+
await press('settings-clear');
|
|
154
|
+
await shot('5-dialog');
|
|
155
|
+
await press('dialog-ok');
|
|
156
|
+
check('toast', toast(), 'Cache cleared');
|
|
157
|
+
await press('header-back', 800);
|
|
158
|
+
check('page removed', exists('page-settings'), false);
|
|
159
|
+
|
|
160
|
+
// slide panel, pager
|
|
161
|
+
await press('shortcut-layers');
|
|
162
|
+
await shot('6-panel');
|
|
163
|
+
await press('panel-close');
|
|
164
|
+
check('panel removed', exists('home-panel'), false);
|
|
165
|
+
await press('pager-dot-1');
|
|
166
|
+
await shot('7-pager');
|
|
167
|
+
|
|
168
|
+
// tabs
|
|
169
|
+
const tab = (name: string) => press(`tab-${name}`);
|
|
170
|
+
await tab('components');
|
|
171
|
+
await press('native-button', 100);
|
|
172
|
+
check('native button', text('native-taps'), '1 taps');
|
|
173
|
+
await shot('8-components');
|
|
174
|
+
await tab('inbox');
|
|
175
|
+
check('unread', text('unread'), '3 unread');
|
|
176
|
+
await shot('9-inbox');
|
|
177
|
+
await press('mark-read');
|
|
178
|
+
check('all read', exists('unread'), false);
|
|
179
|
+
await tab('discover');
|
|
180
|
+
await press('create-button');
|
|
181
|
+
await press('option-task');
|
|
182
|
+
check('created', toast(), 'Created: New task');
|
|
183
|
+
|
|
184
|
+
// signed out: the notes invite to sign in
|
|
185
|
+
await tab('me');
|
|
186
|
+
check('guest', text('me-name'), 'Guest');
|
|
187
|
+
await shot('10-me');
|
|
188
|
+
await press('me-notes', 800);
|
|
189
|
+
check('notes: sign in first', exists('notes-signed-out') && exists('notes-signin'), true);
|
|
190
|
+
check('notes: no field', exists('note-input'), false);
|
|
191
|
+
await shot('11-notes-signed-out');
|
|
192
|
+
await press('notes-signin', 800);
|
|
193
|
+
check('notes: to the sign-in', exists('page-login'), true);
|
|
194
|
+
await press('header-back', 800);
|
|
195
|
+
await press('header-back', 800);
|
|
196
|
+
|
|
197
|
+
// the sign-in page: the checks of the form (a new page for each round: each field is typed into once)
|
|
198
|
+
await press('me-signin', 800);
|
|
199
|
+
check('the server on the page', text('login-server'), 'Server: http://127.0.0.1:9');
|
|
200
|
+
await press('login-submit', 300);
|
|
201
|
+
check('user name required', text('login-username-error'), 'Required');
|
|
202
|
+
check('password required', text('login-password-error'), 'Required');
|
|
203
|
+
await press('login-switch', 300);
|
|
204
|
+
check('register: a second password', exists('login-password2'), true);
|
|
205
|
+
await type('login-username', 'ab');
|
|
206
|
+
check('register: the rule of user names', text('login-username-error'), '3 to 50 characters: letters, digits, _ . @ -');
|
|
207
|
+
await type('login-password', '12345');
|
|
208
|
+
check('register: password length', text('login-password-error'), 'At least 6 characters');
|
|
209
|
+
await type('login-password2', '1');
|
|
210
|
+
check('register: passwords differ', text('login-password2-error'), 'The two passwords differ');
|
|
211
|
+
await shot('12-register-checks');
|
|
212
|
+
await press('login-switch', 300);
|
|
213
|
+
check('sign in again: no second password', exists('login-password2'), false);
|
|
214
|
+
check('sign in: no rule for the name', exists('login-username-error'), false);
|
|
215
|
+
await press('header-back', 800);
|
|
216
|
+
|
|
217
|
+
// no server: a message, nothing breaks
|
|
218
|
+
await press('me-signin', 800);
|
|
219
|
+
await type('login-username', 'ada');
|
|
220
|
+
await type('login-password', 'secret1');
|
|
221
|
+
await press('login-submit', 300);
|
|
222
|
+
check('no server: a message', await toastSoon(), 'The server cannot be reached');
|
|
223
|
+
check('still on the page', exists('page-login'), true);
|
|
224
|
+
check('not signed in', api.user(), null);
|
|
225
|
+
await shot('13-login-offline');
|
|
226
|
+
await press('header-back', 800);
|
|
227
|
+
|
|
228
|
+
// a server (the fake)
|
|
229
|
+
useFake(true);
|
|
230
|
+
await press('me-signin', 800);
|
|
231
|
+
await type('login-username', 'Ada');
|
|
232
|
+
await type('login-password', 'wrong!!');
|
|
233
|
+
await press('login-submit', 800);
|
|
234
|
+
check('the text of the app for the code', toast(), 'Wrong user name or password');
|
|
235
|
+
check('a POST with JSON', `${last().method} ${last().path} ${last().type}`, 'POST /api/login application/json');
|
|
236
|
+
check('the user name and the password', JSON.stringify(last().body), JSON.stringify({ username: 'Ada', password: 'wrong!!' }));
|
|
237
|
+
check('the language goes along, no token yet', last().cookie, 'lang=en');
|
|
238
|
+
setLang('zh-CN');
|
|
239
|
+
await sleep(300);
|
|
240
|
+
await press('login-submit', 800);
|
|
241
|
+
check('the text of the code in Chinese', toast(), '用户名或密码错误');
|
|
242
|
+
check('the language of the request', last().cookie, 'lang=zh-CN');
|
|
243
|
+
await shot('14-login-chinese');
|
|
244
|
+
setLang('en');
|
|
245
|
+
await sleep(300);
|
|
246
|
+
mode = 'nokey';
|
|
247
|
+
await press('login-submit', 800);
|
|
248
|
+
check('no CRYPTO_KEY on the server: said so', toast(), 'The server has no CRYPTO_KEY in its .env');
|
|
249
|
+
mode = 'ok';
|
|
250
|
+
await press('header-back', 800);
|
|
251
|
+
|
|
252
|
+
// a new account: signed in at once
|
|
253
|
+
await press('me-signin', 800);
|
|
254
|
+
await press('login-switch', 300);
|
|
255
|
+
await type('login-username', 'Ada');
|
|
256
|
+
await type('login-password', 'secret1');
|
|
257
|
+
await type('login-password2', 'secret1');
|
|
258
|
+
await shot('15-register');
|
|
259
|
+
await press('login-submit', 1200);
|
|
260
|
+
check('registered', last().path, '/api/register');
|
|
261
|
+
check('welcome', toast(), 'Welcome, ada: your account is ready');
|
|
262
|
+
check('signed in', text('me-name'), 'ada');
|
|
263
|
+
check('the token is kept', storage.get('session'), 'tok+ada/=');
|
|
264
|
+
await shot('16-signed-in');
|
|
265
|
+
|
|
266
|
+
// the notes on the server
|
|
267
|
+
await press('me-notes', 800);
|
|
268
|
+
check('notes: loaded with the token', `${last().method} ${last().path} ${last().cookie}`, `GET /api/notes lang=en; _token=${encodeURIComponent('tok+ada/=')}`);
|
|
269
|
+
check('notes: none yet, no error', exists('notes-error') || exists('notes-more'), false);
|
|
270
|
+
await type('note-input', 'first note 你好 😀');
|
|
271
|
+
await press('note-add', 500);
|
|
272
|
+
check('add: sent', JSON.stringify(last().body), JSON.stringify({ text: 'first note 你好 😀' }));
|
|
273
|
+
check('add: shown', text('note-2'), 'first note 你好 😀');
|
|
274
|
+
check('add: the field is cleared', text('note-input'), '');
|
|
275
|
+
for (const value of ['second', 'third', 'fourth']) {
|
|
276
|
+
await type('note-input', value);
|
|
277
|
+
await press('note-add', 400);
|
|
278
|
+
}
|
|
279
|
+
check('four notes', ['note-2', 'note-3', 'note-4', 'note-5'].every(exists), true);
|
|
280
|
+
await shot('17-notes');
|
|
281
|
+
await press('notes-refresh', 800);
|
|
282
|
+
check('refresh: a page of three', exists('note-5') && exists('note-3') && !exists('note-2'), true);
|
|
283
|
+
check('refresh: older ones', exists('notes-more'), true);
|
|
284
|
+
await press('notes-more', 800);
|
|
285
|
+
check('older notes: before the last one', `${last().path}?${last().query}`, '/api/notes?before=3');
|
|
286
|
+
check('older notes: all four', exists('note-2') && !exists('notes-more'), true);
|
|
287
|
+
check('update (the client)', (await api.updateNote(3, 'second, changed')).code, 'note_updated');
|
|
288
|
+
|
|
289
|
+
// the server answers with an error page, then not at all: the notes stay, a message and a button
|
|
290
|
+
mode = '500';
|
|
291
|
+
await press('notes-refresh', 800);
|
|
292
|
+
check('server error: a message', text('notes-error'), 'Unexpected answer of the server (500)');
|
|
293
|
+
check('server error: the notes stay', exists('note-5'), true);
|
|
294
|
+
await shot('18-server-error');
|
|
295
|
+
mode = 'offline';
|
|
296
|
+
await press('notes-retry', 800);
|
|
297
|
+
check('offline: a message', text('notes-error'), 'The server cannot be reached');
|
|
298
|
+
await type('note-input', 'written offline');
|
|
299
|
+
await press('note-add', 800);
|
|
300
|
+
check('offline: add fails with a message', toast(), 'The server cannot be reached');
|
|
301
|
+
check('offline: the text stays', text('note-input'), 'written offline');
|
|
302
|
+
check('offline: still signed in', api.user()?.username, 'ada');
|
|
303
|
+
await shot('19-offline');
|
|
304
|
+
mode = 'ok';
|
|
305
|
+
await press('notes-retry', 800);
|
|
306
|
+
check('online again: no message', exists('notes-error'), false);
|
|
307
|
+
check('online again: the change of the update', text('note-3'), 'second, changed');
|
|
308
|
+
await press('note-add', 600);
|
|
309
|
+
check('online again: added', text('note-6'), 'written offline');
|
|
310
|
+
await press('note-delete-4', 600);
|
|
311
|
+
check('delete: sent', `${last().path} ${JSON.stringify(last().body)}`, '/api/notes/delete {"id":4}');
|
|
312
|
+
check('delete: a message', toast(), 'Note deleted');
|
|
313
|
+
check('delete: gone', exists('note-4'), false);
|
|
314
|
+
|
|
315
|
+
// the session is over (a new password ...): signed out, and asked to sign in again
|
|
316
|
+
mode = 'expired';
|
|
317
|
+
await press('notes-refresh', 800);
|
|
318
|
+
check('session over: signed out', api.user(), null);
|
|
319
|
+
check('session over: a message', toast(), 'Please sign in again');
|
|
320
|
+
check('session over: the token is gone', storage.get('session'), null);
|
|
321
|
+
check('session over: sign in again', exists('notes-signed-out'), true);
|
|
322
|
+
check('session over: no notes of before', exists('note-5'), false);
|
|
323
|
+
await shot('20-session-over');
|
|
324
|
+
mode = 'ok';
|
|
325
|
+
await press('notes-signin', 800);
|
|
326
|
+
await type('login-username', 'ada');
|
|
327
|
+
await type('login-password', 'secret1');
|
|
328
|
+
await press('login-submit', 1200);
|
|
329
|
+
check('signed in again: back on the notes', exists('page-notes') && !exists('page-login'), true);
|
|
330
|
+
check('signed in again: the notes', exists('note-6') && exists('note-5') && !exists('note-4'), true);
|
|
331
|
+
await press('header-back', 800);
|
|
332
|
+
|
|
333
|
+
// sign out
|
|
334
|
+
check('me', text('me-name'), 'ada');
|
|
335
|
+
await press('me-signout', 800);
|
|
336
|
+
check('signed out', text('me-name'), 'Guest');
|
|
337
|
+
check('told the API', last().path, '/api/logout');
|
|
338
|
+
check('the token is gone', storage.get('session'), null);
|
|
339
|
+
// the name is taken
|
|
340
|
+
await press('me-signin', 800);
|
|
341
|
+
await press('login-switch', 300);
|
|
342
|
+
await type('login-username', 'ADA');
|
|
343
|
+
await type('login-password', 'another1');
|
|
344
|
+
await type('login-password2', 'another1');
|
|
345
|
+
await press('login-submit', 800);
|
|
346
|
+
check('register: the name is taken', toast(), 'This user name is taken');
|
|
347
|
+
check('register: not signed in', api.user(), null);
|
|
348
|
+
await press('header-back', 800);
|
|
349
|
+
useFake(false);
|
|
350
|
+
|
|
351
|
+
// a note from the Create tab: the page of the notes
|
|
352
|
+
await tab('discover');
|
|
353
|
+
await press('create-button');
|
|
354
|
+
await press('option-note', 800);
|
|
355
|
+
check('create a note: the notes', exists('page-notes'), true);
|
|
356
|
+
await press('header-back', 800);
|
|
357
|
+
await tab('home');
|
|
358
|
+
await press('recent-12', 800);
|
|
359
|
+
check('route parameter', text('item-title'), 'Team photos');
|
|
360
|
+
await press('header-back', 800);
|
|
361
|
+
if (!isWide()) {
|
|
362
|
+
await press('menu-button');
|
|
363
|
+
await shot('21-menu');
|
|
364
|
+
await press('menu-theme');
|
|
365
|
+
await press('side-menu-mask');
|
|
366
|
+
check('menu closed', exists('side-menu'), false);
|
|
367
|
+
check('the pager is where it was', act('pager-page-1', 'screenX') < 60, true);
|
|
368
|
+
await shot('22-home-dark');
|
|
369
|
+
}
|
|
370
|
+
console.log(`TEST RESULT ${failed ? 'FAILED' : 'PASSED'} ${passed} ok, ${failed} failed`);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
main().catch((e) => console.log(`TEST RESULT FAILED ${e && e.stack}`));
|