@humanonlyweb/create-nuxtflare 0.2.2 → 0.2.4
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,7 +6,7 @@ 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.
|
|
9
|
+
version: "0.2.4",
|
|
10
10
|
description: "Scaffold a Nuxt 5 + Cloudflare Workers + D1 + Effect v4 app with explicit auth, TOTP 2FA, and admin.",
|
|
11
11
|
keywords: [
|
|
12
12
|
"cloudflare",
|
|
@@ -6,7 +6,7 @@ import { fieldErrors, problemOf } from '~/utils/api-error'
|
|
|
6
6
|
const mapFields = fieldErrors()
|
|
7
7
|
type FormElementRef = Readonly<Ref<HTMLElement | null>>
|
|
8
8
|
|
|
9
|
-
export const useAccount =
|
|
9
|
+
export const useAccount = (
|
|
10
10
|
options: {
|
|
11
11
|
readonly profileFormRef?: FormElementRef
|
|
12
12
|
readonly passwordFormRef?: FormElementRef
|
|
@@ -14,16 +14,19 @@ export const useAccount = async (
|
|
|
14
14
|
readonly deleteFormRef?: FormElementRef
|
|
15
15
|
} = {},
|
|
16
16
|
) => {
|
|
17
|
-
const { data: me, refresh: refreshMe } = await useMe()
|
|
18
17
|
const features = useFeatures()
|
|
19
|
-
const { clear, fetch: refreshSession } = useUserSession()
|
|
18
|
+
const { clear, fetch: refreshSession, user: sessionUser } = useUserSession()
|
|
19
|
+
const meFetch = useMe()
|
|
20
|
+
const { data: me, refresh: refreshMe } = meFetch
|
|
20
21
|
|
|
21
22
|
const canUseVerifiedActions = computed(() => Boolean(me.value && (!features.emailVerificationRequired || me.value.emailStatus === 'verified')))
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
-
|
|
24
|
+
const initiallyVerified = Boolean(!features.emailVerificationRequired || sessionUser.value?.verified)
|
|
25
|
+
const sessionsFetch = useFetch('/api/account/sessions', {
|
|
26
|
+
immediate: initiallyVerified,
|
|
25
27
|
default: () => ({ sessions: [] }),
|
|
26
28
|
})
|
|
29
|
+
const { data: sessionList, refresh: refreshSessions } = sessionsFetch
|
|
27
30
|
|
|
28
31
|
const actionBusy = ref(false)
|
|
29
32
|
const notice = ref('')
|
|
@@ -63,6 +66,18 @@ export const useAccount = async (
|
|
|
63
66
|
onError: onFormError,
|
|
64
67
|
})
|
|
65
68
|
|
|
69
|
+
watch(
|
|
70
|
+
me,
|
|
71
|
+
(next) => {
|
|
72
|
+
if (next && !profile.isDirty.value) profile.setValues({ username: next.username })
|
|
73
|
+
},
|
|
74
|
+
{ immediate: true },
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
watch(canUseVerifiedActions, (verified) => {
|
|
78
|
+
if (verified) void refreshSessions()
|
|
79
|
+
})
|
|
80
|
+
|
|
66
81
|
const passwordForm = useForm({
|
|
67
82
|
schema: SetPasswordFormSchema,
|
|
68
83
|
initialValues: { currentPassword: '', newPassword: '', code: '' },
|
|
@@ -157,7 +172,10 @@ export const useAccount = async (
|
|
|
157
172
|
await refreshMe()
|
|
158
173
|
}, 'Pending email change cancelled.')
|
|
159
174
|
|
|
175
|
+
const ready = Promise.all([meFetch, sessionsFetch]).then(() => undefined)
|
|
176
|
+
|
|
160
177
|
return {
|
|
178
|
+
ready,
|
|
161
179
|
me,
|
|
162
180
|
features,
|
|
163
181
|
canUseVerifiedActions,
|
|
@@ -7,6 +7,7 @@ const emailFormRef = useTemplateRef<HTMLFormElement>('email-form')
|
|
|
7
7
|
const deleteFormRef = useTemplateRef<HTMLFormElement>('delete-form')
|
|
8
8
|
|
|
9
9
|
const {
|
|
10
|
+
ready,
|
|
10
11
|
me,
|
|
11
12
|
features,
|
|
12
13
|
canUseVerifiedActions,
|
|
@@ -23,12 +24,14 @@ const {
|
|
|
23
24
|
signOutEverywhere,
|
|
24
25
|
resendVerification,
|
|
25
26
|
cancelEmailChange,
|
|
26
|
-
} =
|
|
27
|
+
} = useAccount({ profileFormRef, passwordFormRef, emailFormRef, deleteFormRef })
|
|
27
28
|
|
|
28
29
|
const { form: profileValues, errors: profileErrors, processing: profileProcessing, submit: saveProfile } = profile
|
|
29
30
|
const { form: passwordValues, errors: passwordErrors, processing: passwordProcessing, submit: savePassword } = passwordForm
|
|
30
31
|
const { form: emailValues, errors: emailErrors, processing: emailProcessing, submit: requestEmailChange } = emailForm
|
|
31
32
|
const { form: deleteValues, errors: deleteErrors, processing: deleteProcessing, submit: deleteAccount } = deleteForm
|
|
33
|
+
|
|
34
|
+
await ready
|
|
32
35
|
</script>
|
|
33
36
|
|
|
34
37
|
<template>
|
|
@@ -14,7 +14,7 @@ import { join, resolve } from 'node:path'
|
|
|
14
14
|
import { migrations } from '../server/core/db/migrations'
|
|
15
15
|
|
|
16
16
|
const remote = process.argv.slice(2).includes('--remote')
|
|
17
|
-
const
|
|
17
|
+
const targetFlags = remote ? ['--remote', '--yes'] : ['--local']
|
|
18
18
|
|
|
19
19
|
const WranglerConfig = Schema.fromJsonString(
|
|
20
20
|
Schema.Struct({
|
|
@@ -36,14 +36,25 @@ const QueryOutput = Schema.fromJsonString(
|
|
|
36
36
|
),
|
|
37
37
|
)
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const extractJson = (raw: string): string => {
|
|
40
|
+
const start = raw.indexOf('[')
|
|
41
|
+
return start === -1 ? raw : raw.slice(start)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const runCommand = (sql: string, json = false): string => {
|
|
45
|
+
const args = ['wrangler', 'd1', 'execute', dbName, ...targetFlags, '--command', sql, ...(json ? ['--json'] : [])]
|
|
46
|
+
const result = spawnSync('bunx', args, { encoding: 'utf8', stdio: json ? ['inherit', 'pipe', 'inherit'] : 'inherit' })
|
|
47
|
+
if (result.status !== 0) process.exit(result.status ?? 1)
|
|
48
|
+
return result.stdout ?? ''
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const runSqlFile = (statements: ReadonlyArray<string>): void => {
|
|
40
52
|
const sqlFile = join(tmpdir(), `nuxtflare-migrate-${process.pid}-${Date.now()}.sql`)
|
|
41
53
|
writeFileSync(sqlFile, `${statements.join(';\n')};\n`, { encoding: 'utf8', mode: 0o600 })
|
|
42
54
|
try {
|
|
43
|
-
const args = ['wrangler', 'd1', 'execute', dbName,
|
|
44
|
-
const result = spawnSync('bunx', args, { encoding: 'utf8', stdio:
|
|
55
|
+
const args = ['wrangler', 'd1', 'execute', dbName, ...targetFlags, '--file', sqlFile]
|
|
56
|
+
const result = spawnSync('bunx', args, { encoding: 'utf8', stdio: 'inherit' })
|
|
45
57
|
if (result.status !== 0) process.exit(result.status ?? 1)
|
|
46
|
-
return result.stdout ?? ''
|
|
47
58
|
} finally {
|
|
48
59
|
rmSync(sqlFile, { force: true })
|
|
49
60
|
}
|
|
@@ -51,9 +62,9 @@ const runSqlFile = (statements: ReadonlyArray<string>, json = false): string =>
|
|
|
51
62
|
|
|
52
63
|
const quote = (text: string) => `'${text.replaceAll("'", "''")}'`
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
const appliedRaw =
|
|
56
|
-
const applied = new Set(Schema.decodeSync(QueryOutput)(appliedRaw).flatMap((batch) => (batch.results ?? []).map((row) => row.id)))
|
|
65
|
+
runCommand(`CREATE TABLE IF NOT EXISTS _migrations (id TEXT PRIMARY KEY, applied_at TEXT NOT NULL)`)
|
|
66
|
+
const appliedRaw = runCommand(`SELECT id FROM _migrations`, true)
|
|
67
|
+
const applied = new Set(Schema.decodeSync(QueryOutput)(extractJson(appliedRaw)).flatMap((batch) => (batch.results ?? []).map((row) => row.id)))
|
|
57
68
|
|
|
58
69
|
let count = 0
|
|
59
70
|
for (const migration of migrations) {
|
package/package.json
CHANGED