@humanonlyweb/create-nuxtflare 0.2.1 → 0.2.2

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/dist/cli.js CHANGED
@@ -6,30 +6,26 @@ import { basename as basename2, resolve as resolve2 } from "node:path";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@humanonlyweb/create-nuxtflare",
9
- version: "0.2.1",
9
+ version: "0.2.2",
10
10
  description: "Scaffold a Nuxt 5 + Cloudflare Workers + D1 + Effect v4 app with explicit auth, TOTP 2FA, and admin.",
11
- license: "MIT",
12
- repository: {
13
- type: "git",
14
- url: "git+https://github.com/humanonlyweb/nuxtflare.git"
15
- },
16
- homepage: "https://github.com/humanonlyweb/nuxtflare#readme",
17
- bugs: {
18
- url: "https://github.com/humanonlyweb/nuxtflare/issues"
19
- },
20
11
  keywords: [
21
- "nuxt",
22
- "nuxt5",
23
12
  "cloudflare",
24
13
  "cloudflare-workers",
14
+ "create",
25
15
  "d1",
26
16
  "effect",
27
- "starter",
28
- "create"
17
+ "nuxt",
18
+ "nuxt5",
19
+ "starter"
29
20
  ],
30
- type: "module",
31
- publishConfig: {
32
- access: "public"
21
+ homepage: "https://github.com/humanonlyweb/nuxtflare#readme",
22
+ bugs: {
23
+ url: "https://github.com/humanonlyweb/nuxtflare/issues"
24
+ },
25
+ license: "MIT",
26
+ repository: {
27
+ type: "git",
28
+ url: "git+https://github.com/humanonlyweb/nuxtflare.git"
33
29
  },
34
30
  bin: {
35
31
  "create-nuxtflare": "./dist/cli.js",
@@ -38,6 +34,10 @@ var package_default = {
38
34
  files: [
39
35
  "dist"
40
36
  ],
37
+ type: "module",
38
+ publishConfig: {
39
+ access: "public"
40
+ },
41
41
  scripts: {
42
42
  build: "bun scripts/build.ts",
43
43
  test: "bun test src/scaffold.test.ts",
@@ -38,6 +38,7 @@ Never rely on callers "remembering" a rule, ordering assumption, or hidden conve
38
38
 
39
39
  - **Comments**: No useless or restating comments — only add a comment when it explains a non-obvious reason, constraint, or trade-off that genuinely improves understanding.
40
40
  - **Vue components**: Component filenames use `kebab-case` (e.g. `app/components/qr-code.vue`, `app/components/totp-setup.vue`).
41
+ - **UI library**: For `@humanonlyweb/ui`, read `node_modules/@humanonlyweb/ui/dist/docs/README.md` before using a component. It indexes a page per component: props, events, slots, and styling hooks.
41
42
  - **Typed errors only**: Services fail with tagged errors from `shared/domain/errors.ts` or `server/utils/errors.ts`. Unexpected defects become a bare 500.
42
43
  - **D1 safety**: Bound parameters are capped at 100 per statement — use `chunked` for variable-length `IN (...)` lists. Pure `SELECT` queries retry transient D1 resets; writes never retry automatically.
43
44
  - **Secrets**: Come from Nuxt runtime config (`NUXT_*`), wrapped in `Redacted` inside `AppConfig`. Never read secrets off Cloudflare `env`.
@@ -0,0 +1,178 @@
1
+ import type { Ref } from 'vue'
2
+
3
+ import { ChangeEmailFormSchema, DeleteAccountFormSchema, ProfileFormSchema, SetPasswordFormSchema } from '#shared/utils/schema-validation'
4
+ import { fieldErrors, problemOf } from '~/utils/api-error'
5
+
6
+ const mapFields = fieldErrors()
7
+ type FormElementRef = Readonly<Ref<HTMLElement | null>>
8
+
9
+ export const useAccount = async (
10
+ options: {
11
+ readonly profileFormRef?: FormElementRef
12
+ readonly passwordFormRef?: FormElementRef
13
+ readonly emailFormRef?: FormElementRef
14
+ readonly deleteFormRef?: FormElementRef
15
+ } = {},
16
+ ) => {
17
+ const { data: me, refresh: refreshMe } = await useMe()
18
+ const features = useFeatures()
19
+ const { clear, fetch: refreshSession } = useUserSession()
20
+
21
+ const canUseVerifiedActions = computed(() => Boolean(me.value && (!features.emailVerificationRequired || me.value.emailStatus === 'verified')))
22
+
23
+ const { data: sessionList, refresh: refreshSessions } = await useFetch('/api/account/sessions', {
24
+ immediate: canUseVerifiedActions.value,
25
+ default: () => ({ sessions: [] }),
26
+ })
27
+
28
+ const actionBusy = ref(false)
29
+ const notice = ref('')
30
+ const errorMessage = ref('')
31
+
32
+ const onFormError = (error: unknown) => {
33
+ if (!mapFields(error)) errorMessage.value = problemOf(error).message
34
+ }
35
+
36
+ const runAction = async (work: () => Promise<void>, successMessage?: string) => {
37
+ errorMessage.value = ''
38
+ notice.value = ''
39
+ actionBusy.value = true
40
+ try {
41
+ await work()
42
+ if (successMessage) notice.value = successMessage
43
+ } catch (error) {
44
+ errorMessage.value = problemOf(error).message
45
+ } finally {
46
+ actionBusy.value = false
47
+ }
48
+ }
49
+
50
+ const profile = useForm({
51
+ schema: ProfileFormSchema,
52
+ initialValues: { username: me.value?.username ?? '' },
53
+ formRef: options.profileFormRef,
54
+ mapError: mapFields,
55
+ onSubmit: async (values) => {
56
+ errorMessage.value = ''
57
+ notice.value = ''
58
+ const updated = await $fetch('/api/account', { method: 'PATCH', body: values })
59
+ profile.setValues({ username: updated.username })
60
+ await Promise.all([refreshMe(), refreshSession()])
61
+ notice.value = 'Username updated.'
62
+ },
63
+ onError: onFormError,
64
+ })
65
+
66
+ const passwordForm = useForm({
67
+ schema: SetPasswordFormSchema,
68
+ initialValues: { currentPassword: '', newPassword: '', code: '' },
69
+ formRef: options.passwordFormRef,
70
+ mapError: mapFields,
71
+ onSubmit: async (values) => {
72
+ errorMessage.value = ''
73
+ notice.value = ''
74
+ const hadPassword = Boolean(me.value?.hasPassword)
75
+ await $fetch('/api/account/password', {
76
+ method: 'POST',
77
+ body: {
78
+ ...(hadPassword && values.currentPassword ? { currentPassword: values.currentPassword } : {}),
79
+ newPassword: values.newPassword,
80
+ ...(values.code ? { code: values.code } : {}),
81
+ },
82
+ })
83
+ passwordForm.reset()
84
+ await Promise.all([refreshMe(), refreshSessions()])
85
+ notice.value = hadPassword ? 'Password updated and other sessions signed out.' : 'Password set.'
86
+ },
87
+ onError: onFormError,
88
+ })
89
+
90
+ const emailForm = useForm({
91
+ schema: ChangeEmailFormSchema,
92
+ initialValues: { email: '', password: '', code: '' },
93
+ formRef: options.emailFormRef,
94
+ mapError: mapFields,
95
+ onSubmit: async (values) => {
96
+ errorMessage.value = ''
97
+ notice.value = ''
98
+ await $fetch('/api/account/email', {
99
+ method: 'POST',
100
+ body: {
101
+ email: values.email,
102
+ password: values.password,
103
+ ...(values.code ? { code: values.code } : {}),
104
+ },
105
+ })
106
+ emailForm.reset()
107
+ await refreshMe()
108
+ notice.value = 'Check your new email address for a confirmation link.'
109
+ },
110
+ onError: onFormError,
111
+ })
112
+
113
+ const deleteForm = useForm({
114
+ schema: DeleteAccountFormSchema,
115
+ initialValues: { confirm: '', password: '', code: '' },
116
+ formRef: options.deleteFormRef,
117
+ mapError: mapFields,
118
+ onSubmit: async (values) => {
119
+ errorMessage.value = ''
120
+ notice.value = ''
121
+ await $fetch('/api/account', {
122
+ method: 'DELETE',
123
+ body: {
124
+ confirm: values.confirm,
125
+ ...(values.password ? { password: values.password } : {}),
126
+ ...(values.code ? { code: values.code } : {}),
127
+ },
128
+ })
129
+ await clear()
130
+ await navigateTo('/login')
131
+ },
132
+ onError: onFormError,
133
+ })
134
+
135
+ const signOut = () =>
136
+ runAction(async () => {
137
+ await $fetch('/api/auth/logout', { method: 'POST' })
138
+ await clear()
139
+ await navigateTo('/login')
140
+ })
141
+
142
+ const signOutEverywhere = () =>
143
+ runAction(async () => {
144
+ await $fetch('/api/auth/logout-everywhere', { method: 'POST' })
145
+ await clear()
146
+ await navigateTo('/login')
147
+ })
148
+
149
+ const resendVerification = () =>
150
+ runAction(async () => {
151
+ await $fetch('/api/auth/verify/send', { method: 'POST' })
152
+ }, 'Verification email sent.')
153
+
154
+ const cancelEmailChange = () =>
155
+ runAction(async () => {
156
+ await $fetch('/api/account/email', { method: 'DELETE' })
157
+ await refreshMe()
158
+ }, 'Pending email change cancelled.')
159
+
160
+ return {
161
+ me,
162
+ features,
163
+ canUseVerifiedActions,
164
+ sessionList,
165
+ profile,
166
+ passwordForm,
167
+ emailForm,
168
+ deleteForm,
169
+ actionBusy,
170
+ notice,
171
+ errorMessage,
172
+ refreshSessions,
173
+ signOut,
174
+ signOutEverywhere,
175
+ resendVerification,
176
+ cancelEmailChange,
177
+ }
178
+ }
@@ -0,0 +1,27 @@
1
+ import type { Ref } from 'vue'
2
+
3
+ import { AdminLoginFormSchema } from '#shared/utils/schema-validation'
4
+ import { fieldErrors, problemOf } from '~/utils/api-error'
5
+
6
+ const mapFields = fieldErrors()
7
+
8
+ export const useAdminLogin = (options: { readonly formRef?: Readonly<Ref<HTMLElement | null>> } = {}) => {
9
+ const errorMessage = ref('')
10
+
11
+ const formState = useForm({
12
+ schema: AdminLoginFormSchema,
13
+ initialValues: { email: '', password: '' },
14
+ formRef: options.formRef,
15
+ mapError: mapFields,
16
+ onSubmit: async (values) => {
17
+ errorMessage.value = ''
18
+ await $fetch('/api/admin/session', { method: 'POST', body: values })
19
+ await navigateTo('/admin')
20
+ },
21
+ onError: (error) => {
22
+ if (!mapFields(error)) errorMessage.value = problemOf(error).message
23
+ },
24
+ })
25
+
26
+ return { ...formState, errorMessage }
27
+ }