@humanonlyweb/create-nuxtflare 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -2
- package/dist/cli.js +322 -0
- package/dist/template/.env.example +22 -0
- package/dist/template/.github/workflows/ci.yml +96 -0
- package/dist/template/.oxfmtrc.json +18 -0
- package/dist/template/.oxlintrc.json +69 -0
- package/dist/template/CLAUDE.md +42 -0
- package/dist/template/_gitignore +14 -0
- package/dist/template/app/app.vue +3 -0
- package/dist/template/app/components/qr-code.vue +36 -0
- package/dist/template/app/components/totp-setup.vue +151 -0
- package/dist/template/app/composables/use-features.ts +1 -0
- package/dist/template/app/composables/use-me.ts +10 -0
- package/dist/template/app/middleware/admin.global.ts +12 -0
- package/dist/template/app/middleware/auth.ts +6 -0
- package/dist/template/app/middleware/guest.ts +4 -0
- package/dist/template/app/pages/account.vue +22 -0
- package/dist/template/app/pages/admin/index.vue +16 -0
- package/dist/template/app/pages/admin/login.vue +39 -0
- package/dist/template/app/pages/index.vue +18 -0
- package/dist/template/app/pages/login.vue +110 -0
- package/dist/template/app/pages/register.vue +51 -0
- package/dist/template/app/utils/api-error.ts +50 -0
- package/dist/template/nuxt.config.ts +115 -0
- package/dist/template/package.json +59 -0
- package/dist/template/scripts/admin-password.ts +123 -0
- package/dist/template/server/api/account/email/index.delete.ts +5 -0
- package/dist/template/server/api/account/email/index.post.ts +8 -0
- package/dist/template/server/api/account/index.delete.ts +18 -0
- package/dist/template/server/api/account/index.patch.ts +16 -0
- package/dist/template/server/api/account/sessions.get.ts +11 -0
- package/dist/template/server/api/account/totp/cancel.post.ts +5 -0
- package/dist/template/server/api/account/totp/confirm.post.ts +10 -0
- package/dist/template/server/api/account/totp/disable.post.ts +8 -0
- package/dist/template/server/api/account/totp/index.get.ts +6 -0
- package/dist/template/server/api/account/totp/start.post.ts +8 -0
- package/dist/template/server/api/admin/me.get.ts +7 -0
- package/dist/template/server/api/admin/session/index.delete.ts +12 -0
- package/dist/template/server/api/admin/session/index.post.ts +18 -0
- package/dist/template/server/api/auth/email/index.post.ts +13 -0
- package/dist/template/server/api/auth/login/totp.post.ts +15 -0
- package/dist/template/server/api/auth/login.post.ts +17 -0
- package/dist/template/server/api/auth/logout-everywhere.post.ts +17 -0
- package/dist/template/server/api/auth/logout.post.ts +14 -0
- package/dist/template/server/api/auth/register.post.ts +18 -0
- package/dist/template/server/api/auth/reset/check.post.ts +5 -0
- package/dist/template/server/api/auth/reset/index.post.ts +5 -0
- package/dist/template/server/api/auth/reset/request.post.ts +5 -0
- package/dist/template/server/api/auth/verify/index.post.ts +17 -0
- package/dist/template/server/api/auth/verify/send.post.ts +7 -0
- package/dist/template/server/api/me.get.ts +8 -0
- package/dist/template/server/app/admin/auth.test.ts +41 -0
- package/dist/template/server/app/admin/auth.ts +133 -0
- package/dist/template/server/app/features.ts +18 -0
- package/dist/template/server/app/identity/email-change.ts +147 -0
- package/dist/template/server/app/identity/identity.test.ts +119 -0
- package/dist/template/server/app/identity/lockout.ts +93 -0
- package/dist/template/server/app/identity/password-reset.ts +119 -0
- package/dist/template/server/app/identity/service.ts +379 -0
- package/dist/template/server/app/identity/sessions.ts +141 -0
- package/dist/template/server/app/identity/state.ts +41 -0
- package/dist/template/server/app/identity/totp-crypto.ts +89 -0
- package/dist/template/server/app/identity/totp.test.ts +103 -0
- package/dist/template/server/app/identity/totp.ts +361 -0
- package/dist/template/server/app/identity/verification.ts +120 -0
- package/dist/template/server/app/notifications/email.ts +12 -0
- package/dist/template/server/app/notifications/render.test.ts +26 -0
- package/dist/template/server/app/notifications/render.ts +82 -0
- package/dist/template/server/app/notifications/samples.ts +11 -0
- package/dist/template/server/app/notifications/templates.ts +37 -0
- package/dist/template/server/assets/email/blocks/button.html +1 -0
- package/dist/template/server/assets/email/blocks/lead.html +1 -0
- package/dist/template/server/assets/email/blocks/note.html +1 -0
- package/dist/template/server/assets/email/blocks/text.html +1 -0
- package/dist/template/server/assets/email/layout.html +22 -0
- package/dist/template/server/cloudflare/exports/rate-limit.do.ts +38 -0
- package/dist/template/server/core/app-layer.ts +33 -0
- package/dist/template/server/core/db/atomic-d1.ts +21 -0
- package/dist/template/server/core/db/atomic.ts +86 -0
- package/dist/template/server/core/db/chunked.ts +13 -0
- package/dist/template/server/core/db/migrations.ts +149 -0
- package/dist/template/server/core/db/migrator.ts +39 -0
- package/dist/template/server/core/http/body-limit.ts +35 -0
- package/dist/template/server/core/http/csrf.ts +16 -0
- package/dist/template/server/core/http/device-label.ts +27 -0
- package/dist/template/server/core/http/handle.ts +271 -0
- package/dist/template/server/core/http/limit-key.ts +17 -0
- package/dist/template/server/core/http/page-csp.ts +16 -0
- package/dist/template/server/core/http/public-failure.ts +9 -0
- package/dist/template/server/core/http/request-user.ts +13 -0
- package/dist/template/server/core/http/runtime.ts +30 -0
- package/dist/template/server/core/http/session-cookie.ts +29 -0
- package/dist/template/server/core/platform/app-config.ts +55 -0
- package/dist/template/server/core/platform/clock.ts +4 -0
- package/dist/template/server/core/platform/database.ts +78 -0
- package/dist/template/server/core/platform/email-assets.ts +32 -0
- package/dist/template/server/core/platform/id-generator.ts +29 -0
- package/dist/template/server/core/platform/kv.ts +54 -0
- package/dist/template/server/core/platform/mailer-cloudflare.ts +51 -0
- package/dist/template/server/core/platform/mailer.ts +21 -0
- package/dist/template/server/core/platform/password-hasher.ts +27 -0
- package/dist/template/server/core/platform/pii.ts +80 -0
- package/dist/template/server/core/platform/provider-http.ts +21 -0
- package/dist/template/server/core/platform/rate-limiter-strict.ts +42 -0
- package/dist/template/server/core/platform/rate-limiter.ts +35 -0
- package/dist/template/server/core/platform/runtime-config-schema.ts +15 -0
- package/dist/template/server/core/platform/seal.ts +68 -0
- package/dist/template/server/core/platform/sliding-window.ts +39 -0
- package/dist/template/server/core/platform/tokens.ts +36 -0
- package/dist/template/server/core/platform/turnstile.ts +61 -0
- package/dist/template/server/middleware/00-body-limit.ts +10 -0
- package/dist/template/server/middleware/00-security-headers.ts +19 -0
- package/dist/template/server/middleware/01-user-session.ts +25 -0
- package/dist/template/server/plugins/page-csp.ts +15 -0
- package/dist/template/server/plugins/sessions.ts +21 -0
- package/dist/template/server/routes/(dev)/emails.get.dev.ts +37 -0
- package/dist/template/server/routes/auth/github.get.ts +96 -0
- package/dist/template/server/routes/auth/google.get.ts +61 -0
- package/dist/template/server/test/email-assets.ts +8 -0
- package/dist/template/server/test/invariants.test.ts +83 -0
- package/dist/template/server/test/kit.ts +83 -0
- package/dist/template/server/utils/define-validated-handler.ts +78 -0
- package/dist/template/server/utils/errors.ts +16 -0
- package/dist/template/server/utils/read-body.ts +34 -0
- package/dist/template/server/utils/user-actor.ts +10 -0
- package/dist/template/server.ts +5 -0
- package/dist/template/shared/domain/errors.ts +33 -0
- package/dist/template/shared/types/auth.d.ts +13 -0
- package/dist/template/shared/utils/admin.ts +13 -0
- package/dist/template/shared/utils/auth.ts +132 -0
- package/dist/template/shared/utils/ids.ts +21 -0
- package/dist/template/shared/utils/local-path.ts +2 -0
- package/dist/template/shared/utils/schema-validation.ts +59 -0
- package/dist/template/shared/utils/unknown.ts +9 -0
- package/dist/template/tsconfig.json +17 -0
- package/dist/template/vitest.config.ts +10 -0
- package/dist/template/wrangler.json +46 -0
- package/package.json +28 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Schema } from 'effect'
|
|
2
|
+
|
|
3
|
+
const uuidV7 = Schema.String.check(Schema.isUUID(7), Schema.isLowercased())
|
|
4
|
+
|
|
5
|
+
const idPattern = (prefix: string) => {
|
|
6
|
+
const isShaped = Schema.is(Schema.TemplateLiteral([`${prefix}_`, uuidV7]))
|
|
7
|
+
return Schema.String.check(Schema.makeFilter(isShaped, { message: `Expected a valid ${prefix}_ ID` }))
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const kinds = {
|
|
11
|
+
user: { prefix: 'usr', schema: idPattern('usr').pipe(Schema.brand('UserId')) },
|
|
12
|
+
session: { prefix: 'ses', schema: idPattern('ses').pipe(Schema.brand('SessionId')) },
|
|
13
|
+
} as const
|
|
14
|
+
|
|
15
|
+
export type IdKind = keyof typeof kinds
|
|
16
|
+
export type Id<K extends IdKind> = (typeof kinds)[K]['schema']['Type']
|
|
17
|
+
|
|
18
|
+
export const idSchema = <K extends IdKind>(kind: K): (typeof kinds)[K]['schema'] => kinds[kind].schema
|
|
19
|
+
|
|
20
|
+
export const UserId = idSchema('user')
|
|
21
|
+
export const SessionId = idSchema('session')
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Schema, Struct } from 'effect'
|
|
2
|
+
|
|
3
|
+
const formStruct = <F extends Schema.Struct.Fields>(fields: F) => Schema.Struct(fields).mapFields(Struct.map(Schema.mutableKey))
|
|
4
|
+
|
|
5
|
+
const required = (max: number, message: string) =>
|
|
6
|
+
Schema.Trim.check(Schema.isNonEmpty({ message }), Schema.isMaxLength(max, { message: `Use ${max} characters or fewer.` }))
|
|
7
|
+
|
|
8
|
+
export const EmailField = Schema.Trim.check(
|
|
9
|
+
Schema.isNonEmpty({ message: 'Enter your email.' }),
|
|
10
|
+
Schema.isPattern(/^[^\s@]+@[^\s@]+\.[^\s@]+$/, { message: 'Enter a valid email.' }),
|
|
11
|
+
Schema.isMaxLength(254, { message: 'That email is too long.' }),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
export const UsernameField = Schema.Trim.check(Schema.isPattern(/^[a-z0-9-]{3,24}$/i, { message: 'Use 3–24 letters, numbers or dashes.' }))
|
|
15
|
+
|
|
16
|
+
export const MIN_PASSWORD = 8
|
|
17
|
+
|
|
18
|
+
export const PasswordField = Schema.String.check(
|
|
19
|
+
Schema.isMinLength(MIN_PASSWORD, { message: `Use at least ${MIN_PASSWORD} characters.` }),
|
|
20
|
+
Schema.isMaxLength(200, { message: 'Use 200 characters or fewer.' }),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
export const NonEmptyPasswordField = Schema.String.check(
|
|
24
|
+
Schema.isNonEmpty({ message: 'Enter your password.' }),
|
|
25
|
+
Schema.isMaxLength(200, { message: 'Use 200 characters or fewer.' }),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
export const TokenField = Schema.Trim.check(Schema.isPattern(/^[0-9a-f]{64}$/, { message: 'Invalid token.' }))
|
|
29
|
+
|
|
30
|
+
/** A 6-digit authenticator code or a 10-hex recovery code (with optional dash/spaces). */
|
|
31
|
+
export const SecondFactorCodeField = Schema.Trim.check(
|
|
32
|
+
Schema.isNonEmpty({ message: 'Enter a verification code.' }),
|
|
33
|
+
Schema.isMaxLength(32, { message: 'That code is too long.' }),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
export const TotpSixDigitField = Schema.Trim.check(Schema.isPattern(/^\d{6}$/, { message: 'Enter the 6-digit code from your authenticator app.' }))
|
|
37
|
+
|
|
38
|
+
export const LoginFormSchema = Schema.toStandardSchemaV1(
|
|
39
|
+
formStruct({
|
|
40
|
+
identity: required(254, 'Enter your email or username.'),
|
|
41
|
+
password: NonEmptyPasswordField,
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
export const RegisterFormSchema = Schema.toStandardSchemaV1(
|
|
46
|
+
formStruct({
|
|
47
|
+
username: UsernameField,
|
|
48
|
+
email: EmailField,
|
|
49
|
+
password: PasswordField,
|
|
50
|
+
confirm: Schema.String,
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
export const ForgotPasswordFormSchema = Schema.toStandardSchemaV1(formStruct({ email: EmailField }))
|
|
55
|
+
export const ResetPasswordFormSchema = Schema.toStandardSchemaV1(formStruct({ password: PasswordField, confirm: Schema.String }))
|
|
56
|
+
export const ChangeEmailFormSchema = Schema.toStandardSchemaV1(formStruct({ email: EmailField, password: NonEmptyPasswordField }))
|
|
57
|
+
export const ProfileFormSchema = Schema.toStandardSchemaV1(formStruct({ username: UsernameField }))
|
|
58
|
+
|
|
59
|
+
export const matchesConfirm = (typed: string, expected: string) => typed.trim().toLowerCase() === expected.toLowerCase()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Reads one key off a value whose shape isn't known (a parsed message, an error's body): undefined when it isn't an object. */
|
|
2
|
+
export const readKey = (value: unknown, key: PropertyKey): unknown => (typeof value === 'object' && value !== null ? Reflect.get(value, key) : undefined)
|
|
3
|
+
|
|
4
|
+
export const asString = (value: unknown) => (typeof value === 'string' ? value : undefined)
|
|
5
|
+
|
|
6
|
+
export const asFinite = (value: unknown) => (typeof value === 'number' && Number.isFinite(value) ? value : undefined)
|
|
7
|
+
|
|
8
|
+
export const isOneOf = <T extends string>(choices: ReadonlyArray<T>, value: unknown): value is T =>
|
|
9
|
+
typeof value === 'string' && (choices as ReadonlyArray<string>).includes(value)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
import { defineConfig } from 'vitest/config'
|
|
3
|
+
|
|
4
|
+
const alias = { '#shared': resolve(import.meta.dirname, 'shared'), '#server': resolve(import.meta.dirname, 'server') }
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
resolve: { alias },
|
|
8
|
+
// Every test builds its own in-memory SQLite + Effect layer and leaves no module mocks behind, so workers can be reused across files.
|
|
9
|
+
test: { name: 'node', include: ['server/**/*.test.ts', 'shared/**/*.test.ts', 'app/**/*.test.ts'], environment: 'node', isolate: false },
|
|
10
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/wrangler/config-schema.json",
|
|
3
|
+
"name": "nuxtflare-app",
|
|
4
|
+
"main": "./server.ts",
|
|
5
|
+
"compatibility_date": "2026-11-11",
|
|
6
|
+
"compatibility_flags": ["nodejs_compat", "temporal", "global_fetch_strictly_public"],
|
|
7
|
+
"observability": {
|
|
8
|
+
"enabled": true,
|
|
9
|
+
"logs": {
|
|
10
|
+
"enabled": true,
|
|
11
|
+
"invocation_logs": false
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"d1_databases": [
|
|
15
|
+
{
|
|
16
|
+
"binding": "DB",
|
|
17
|
+
"database_name": "nuxtflare-app",
|
|
18
|
+
"database_id": "00000000-0000-0000-0000-000000000000"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"kv_namespaces": [
|
|
22
|
+
{
|
|
23
|
+
"binding": "KV"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"send_email": [
|
|
27
|
+
{
|
|
28
|
+
"name": "EMAIL",
|
|
29
|
+
"allowed_sender_addresses": ["no-reply@example.com"]
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"durable_objects": {
|
|
33
|
+
"bindings": [
|
|
34
|
+
{
|
|
35
|
+
"name": "RATE_LIMITER",
|
|
36
|
+
"class_name": "RateLimitCounter"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"exports": {
|
|
41
|
+
"RateLimitCounter": {
|
|
42
|
+
"type": "durable-object",
|
|
43
|
+
"storage": "sqlite"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humanonlyweb/create-nuxtflare",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffold a Nuxt 5 + Cloudflare Workers + D1 + Effect v4 app with explicit auth, TOTP 2FA, and admin.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"create-nuxtflare": "./dist/cli.js",
|
|
12
|
+
"nuxtflare": "./dist/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "bun scripts/build.ts",
|
|
19
|
+
"test": "bun test src/scaffold.test.ts",
|
|
20
|
+
"test:template": "bun run --cwd template check",
|
|
21
|
+
"build:template": "bun run --cwd template build",
|
|
22
|
+
"check": "bun run build && bun run test && bun run test:template && bun run build:template",
|
|
23
|
+
"prepublishOnly": "bun run check"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"bun": ">=1.4.0",
|
|
27
|
+
"node": ">=22.0.0"
|
|
28
|
+
},
|
|
29
|
+
"packageManager": "bun@1.4.5"
|
|
30
|
+
}
|