vasp-cli 0.3.0 → 0.4.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.
Files changed (26) hide show
  1. package/dist/vasp +25 -24
  2. package/package.json +1 -1
  3. package/starters/recipe.vasp +79 -0
  4. package/templates/shared/auth/client/Login.vue.hbs +1 -1
  5. package/templates/shared/auth/client/Register.vue.hbs +1 -1
  6. package/templates/shared/drizzle/drizzle.config.hbs +10 -0
  7. package/templates/shared/drizzle/schema.hbs +14 -3
  8. package/templates/shared/jobs/_job.hbs +12 -2
  9. package/templates/shared/package.json.hbs +4 -1
  10. package/templates/shared/server/index.hbs +8 -0
  11. package/templates/shared/server/middleware/csrf.hbs +34 -0
  12. package/templates/shared/server/middleware/rateLimit.hbs +44 -0
  13. package/templates/shared/server/routes/crud/_crud.hbs +47 -3
  14. package/templates/shared/server/routes/realtime/_channel.hbs +58 -10
  15. package/templates/ssr/js/plugins/vasp.client.js.hbs +11 -1
  16. package/templates/ssr/ts/plugins/vasp.client.ts.hbs +11 -1
  17. package/templates/templates/shared/.env.hbs +14 -0
  18. package/templates/templates/shared/README.md.hbs +53 -0
  19. package/templates/templates/shared/auth/server/index.hbs +3 -8
  20. package/templates/templates/shared/auth/server/plugin.hbs +9 -0
  21. package/templates/templates/shared/auth/server/providers/github.hbs +1 -1
  22. package/templates/templates/shared/auth/server/providers/google.hbs +1 -1
  23. package/templates/templates/shared/auth/server/providers/usernameAndPassword.hbs +3 -6
  24. package/templates/templates/shared/bunfig.toml.hbs +3 -0
  25. package/templates/templates/shared/package.json.hbs +4 -1
  26. package/templates/templates/shared/server/index.hbs +13 -0
@@ -2,17 +2,14 @@ import { Elysia, t } from 'elysia'
2
2
  import { db } from '../../db/client.{{ext}}'
3
3
  import { users } from '../../../drizzle/schema.{{ext}}'
4
4
  import { eq } from 'drizzle-orm'
5
- import { authPlugin } from '../index.{{ext}}'
5
+ import { authPlugin } from '../plugin.{{ext}}'
6
6
 
7
7
  async function hashPassword(password{{#if isTypeScript}}: string{{/if}}) {
8
- const encoder = new TextEncoder()
9
- const data = encoder.encode(password)
10
- const hash = await crypto.subtle.digest('SHA-256', data)
11
- return Buffer.from(hash).toString('hex')
8
+ return Bun.password.hash(password, 'argon2id')
12
9
  }
13
10
 
14
11
  async function verifyPassword(password{{#if isTypeScript}}: string{{/if}}, hash{{#if isTypeScript}}: string{{/if}}) {
15
- return (await hashPassword(password)) === hash
12
+ return Bun.password.verify(password, hash)
16
13
  }
17
14
 
18
15
  export const usernameAndPasswordRoutes = new Elysia()
@@ -1,2 +1,5 @@
1
1
  [install]
2
2
  exact = false
3
+
4
+ [resolve]
5
+ "@src" = "./src"
@@ -10,13 +10,16 @@
10
10
  "dev:client": "{{#if isSpa}}vite{{else}}nuxt dev{{/if}}",
11
11
  "db:generate": "bunx drizzle-kit generate",
12
12
  "db:migrate": "bunx drizzle-kit migrate",
13
+ "db:push": "bunx drizzle-kit push",
13
14
  "db:studio": "bunx drizzle-kit studio"
14
15
  },
15
16
  "dependencies": {
16
17
  "@vasp-framework/runtime": "^0.1.0",
17
18
  "elysia": "^1.1.0",
18
19
  "@elysiajs/cors": "^1.1.0",
19
- "@elysiajs/static": "^1.1.0",
20
+ "@elysiajs/static": "^1.1.0",{{#if auth}}
21
+ "@elysiajs/jwt": "^1.1.0",
22
+ "@elysiajs/cookie": "^0.8.0",{{/if}}
20
23
  "drizzle-orm": "^0.36.0",
21
24
  "postgres": "^3.4.0",
22
25
  "ofetch": "^1.3.4",
@@ -55,6 +55,19 @@ const app = new Elysia()
55
55
  {{#each jobs}}
56
56
  .use({{camelCase name}}ScheduleRoute)
57
57
  {{/each}}
58
+ .onError(({ code, error, set }) => {
59
+ if (code === 'NOT_FOUND') {
60
+ set.status = 404
61
+ return { error: 'Not found' }
62
+ }
63
+ if (code === 'VALIDATION') {
64
+ set.status = 400
65
+ return { error: 'Validation failed', details: error.message }
66
+ }
67
+ console.error('[server error]', error)
68
+ set.status = 500
69
+ return { error: 'Internal server error' }
70
+ })
58
71
  .listen(PORT)
59
72
 
60
73
  console.log(`🚀 Vasp backend running at http://localhost:${PORT}`)