@enlt-bakusoku/nuxt4 0.0.0-stage → 2.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 +38 -2
- package/dist/module.d.mts +25 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +208 -0
- package/dist/runtime/shared/schemas/user.d.ts +40 -0
- package/dist/runtime/shared/schemas/user.js +21 -0
- package/dist/runtime/tasks-catalog.d.ts +6 -0
- package/dist/runtime/tasks-catalog.js +7 -0
- package/dist/types.d.mts +9 -0
- package/package.json +120 -3
- package/scripts/bakusoku-dev.mjs +387 -0
- package/scripts/dev-log-relay.mjs +96 -0
- package/scripts/predeploy.mjs +24 -0
- package/scripts/prepare-firebase-artifact.mjs +43 -0
- package/scripts/setup-worktree.sh +59 -0
- package/scripts/verify-firebase-artifacts.mjs +70 -0
- package/src/layer/app/components/admin/AdminExecutionHistory.vue +137 -0
- package/src/layer/app/components/admin/TaskRunDialog.vue +162 -0
- package/src/layer/app/components/admin/UserManagementPage.vue +342 -0
- package/src/layer/app/components/debug/DebugApplicationLogs.vue +87 -0
- package/src/layer/app/components/debug/DebugErrorLogs.vue +47 -0
- package/src/layer/app/components/debug/DebugFirestoreOperations.vue +48 -0
- package/src/layer/app/components/debug/DebugHttpRequests.vue +86 -0
- package/src/layer/app/components/debug/DebugNavigation.vue +60 -0
- package/src/layer/app/components/debug/DebugNowControl.vue +243 -0
- package/src/layer/app/components/debug/DebugPublicConfig.vue +24 -0
- package/src/layer/app/components/debug/DebugTestAdmin.vue +67 -0
- package/src/layer/app/components/demo/DemoDebug.vue +266 -0
- package/src/layer/app/components/demo/DemoHome.vue +347 -0
- package/src/layer/app/components/demo/DemoLogin.vue +391 -0
- package/src/layer/app/components/demo/DemoPassword.vue +224 -0
- package/src/layer/app/components/demo/DemoRegister.vue +148 -0
- package/src/layer/app/components/home/HomePage.vue +77 -0
- package/src/layer/app/layouts/dashboard.vue +126 -0
- package/src/layer/app/layouts/default.vue +3 -0
- package/src/layer/app/middleware/admin.ts +15 -0
- package/src/layer/app/middleware/authenticated.ts +19 -0
- package/src/layer/app/pages/admin/migrations.vue +463 -0
- package/src/layer/app/pages/admin/tasks/[id].vue +276 -0
- package/src/layer/app/pages/admin/tasks/index.vue +220 -0
- package/src/layer/app/pages/admin/users.vue +17 -0
- package/src/layer/app/pages/bakusoku-devtools.vue +294 -0
- package/src/layer/app/plugins/auth-init.ts +36 -0
- package/src/layer/app/plugins/debug-devtools.client.ts +20 -0
- package/src/layer/app/plugins/debug-errors.client.ts +78 -0
- package/src/layer/app/plugins/debug-http.client.ts +154 -0
- package/src/layer/app/plugins/debug-nav.client.ts +28 -0
- package/src/layer/app/plugins/vuefire-inspect.ts +18 -0
- package/src/layer/app/stores/auth.ts +462 -0
- package/src/layer/app/stores/datetime.ts +41 -0
- package/src/layer/app/stores/debug.ts +235 -0
- package/src/layer/app/stores/user.ts +170 -0
- package/src/layer/app/utils/admin-execution.ts +48 -0
- package/src/layer/app/utils/dashboard-heading.ts +36 -0
- package/src/layer/app/utils/debug-bridge.ts +270 -0
- package/src/layer/app/utils/debug-firestore.ts +38 -0
- package/src/layer/app/utils/debug-format.ts +19 -0
- package/src/layer/app/utils/execution-refresh.ts +66 -0
- package/src/layer/app/utils/framework-version.ts +4 -0
- package/src/layer/app/utils/inspect-nuxt-vuefire.ts +288 -0
- package/src/layer/app/utils/is-debug-enabled.ts +13 -0
- package/src/layer/app/utils/logger.ts +235 -0
- package/src/layer/app/utils/map-auth-error.ts +11 -0
- package/src/layer/app/utils/mask-secrets.ts +100 -0
- package/src/layer/app/utils/resolve-auth-user.ts +53 -0
- package/src/layer/app/utils/resolve-firestore.ts +20 -0
- package/src/layer/app/utils/task-run.ts +15 -0
- package/src/layer/build-credentials.mjs +33 -0
- package/src/layer/nuxt.config.ts +86 -0
- package/src/layer/package.json +5 -0
- package/src/layer/server/api/debug/test-admin.post.ts +38 -0
- package/src/layer/server/api/tasks/executions/cancel.post.ts +21 -0
- package/src/layer/server/api/tasks/executions/index.get.ts +22 -0
- package/src/layer/server/api/tasks/executions/index.post.ts +25 -0
- package/src/layer/server/api/tasks/index.get.ts +70 -0
- package/src/layer/server/api/tasks/migrations/index.post.ts +27 -0
- package/src/layer/server/api/tasks/migrations/recovery.post.ts +20 -0
- package/src/layer/server/api/users/[id].delete.ts +57 -0
- package/src/layer/server/api/users/[id].put.ts +110 -0
- package/src/layer/server/api/users/index.post.ts +232 -0
- package/src/layer/server/utils/admin-access.ts +32 -0
- package/src/layer/server/utils/debug-test-admin.ts +17 -0
- package/src/layer/server/utils/firebase-admin.ts +22 -0
- package/src/layer/server/utils/logger.ts +172 -0
- package/src/layer/server/utils/tasks-gateway.ts +57 -0
- package/src/layer/server/utils/user-mutations.ts +103 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="min-h-screen bg-default p-3 text-xs text-default">
|
|
3
|
+
<div class="mb-3 flex items-center justify-between gap-3">
|
|
4
|
+
<div class="min-w-0">
|
|
5
|
+
<div class="flex items-center gap-2">
|
|
6
|
+
<UIcon name="i-lucide-bug" class="size-4 text-error" />
|
|
7
|
+
<h1 class="text-sm font-semibold">Bakusoku</h1>
|
|
8
|
+
<UBadge
|
|
9
|
+
:color="bridge ? 'success' : 'neutral'"
|
|
10
|
+
variant="subtle"
|
|
11
|
+
size="sm"
|
|
12
|
+
>
|
|
13
|
+
{{ bridge ? '接続中' : '未接続' }}
|
|
14
|
+
</UBadge>
|
|
15
|
+
</div>
|
|
16
|
+
<p class="mt-1 truncate text-[11px] text-muted">{{ status }}</p>
|
|
17
|
+
</div>
|
|
18
|
+
<UButton
|
|
19
|
+
size="xs"
|
|
20
|
+
variant="outline"
|
|
21
|
+
color="neutral"
|
|
22
|
+
icon="i-lucide-trash-2"
|
|
23
|
+
:disabled="!bridge"
|
|
24
|
+
@click="bridge?.clearAllLogs()"
|
|
25
|
+
>
|
|
26
|
+
クリア
|
|
27
|
+
</UButton>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<p v-if="!snapshot" class="text-muted">
|
|
31
|
+
操作中のアプリに接続しています。
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
<div v-else class="flex flex-col gap-3">
|
|
35
|
+
<UTabs v-model="tab" :items="tabs" :content="false" size="xs" variant="link" />
|
|
36
|
+
|
|
37
|
+
<div v-if="tab === 'overview'" class="grid grid-cols-1 gap-3 xl:grid-cols-2">
|
|
38
|
+
<UCard>
|
|
39
|
+
<template #header>
|
|
40
|
+
<div class="flex items-center gap-2 text-sm font-semibold">
|
|
41
|
+
<UIcon name="i-lucide-monitor-smartphone" />
|
|
42
|
+
環境
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
45
|
+
<dl class="space-y-2">
|
|
46
|
+
<div v-for="row in envRows" :key="row.label" class="flex items-start justify-between gap-3">
|
|
47
|
+
<dt class="shrink-0 text-muted">{{ row.label }}</dt>
|
|
48
|
+
<dd class="min-w-0 break-all text-right font-mono">{{ row.value }}</dd>
|
|
49
|
+
</div>
|
|
50
|
+
</dl>
|
|
51
|
+
</UCard>
|
|
52
|
+
|
|
53
|
+
<UCard>
|
|
54
|
+
<template #header>
|
|
55
|
+
<div class="flex items-center justify-between gap-2">
|
|
56
|
+
<div class="flex items-center gap-2 text-sm font-semibold">
|
|
57
|
+
<UIcon name="i-lucide-user" />
|
|
58
|
+
認証
|
|
59
|
+
</div>
|
|
60
|
+
<UBadge
|
|
61
|
+
:color="snapshot.auth.isAuthenticated ? 'success' : 'neutral'"
|
|
62
|
+
variant="subtle"
|
|
63
|
+
size="sm"
|
|
64
|
+
>
|
|
65
|
+
{{ snapshot.auth.isAuthenticated ? 'ログイン中' : '未ログイン' }}
|
|
66
|
+
</UBadge>
|
|
67
|
+
</div>
|
|
68
|
+
</template>
|
|
69
|
+
<dl class="space-y-2">
|
|
70
|
+
<div v-for="row in authRows" :key="row.label" class="flex items-start justify-between gap-3">
|
|
71
|
+
<dt class="shrink-0 text-muted">{{ row.label }}</dt>
|
|
72
|
+
<dd class="min-w-0 break-all text-right font-mono">{{ row.value }}</dd>
|
|
73
|
+
</div>
|
|
74
|
+
</dl>
|
|
75
|
+
<UButton
|
|
76
|
+
class="mt-3"
|
|
77
|
+
size="xs"
|
|
78
|
+
variant="soft"
|
|
79
|
+
color="neutral"
|
|
80
|
+
icon="i-lucide-refresh-cw"
|
|
81
|
+
@click="bridge?.refreshToken()"
|
|
82
|
+
>
|
|
83
|
+
トークン再取得
|
|
84
|
+
</UButton>
|
|
85
|
+
</UCard>
|
|
86
|
+
|
|
87
|
+
<DebugNowControl
|
|
88
|
+
class="xl:col-span-2"
|
|
89
|
+
:now="snapshot.now"
|
|
90
|
+
:overridden="snapshot.nowOverridden"
|
|
91
|
+
@shift="ms => bridge?.shiftNow(ms)"
|
|
92
|
+
@set="iso => bridge?.setNow(iso)"
|
|
93
|
+
@reset="bridge?.resetNow()"
|
|
94
|
+
/>
|
|
95
|
+
<p class="break-all text-muted xl:col-span-2">
|
|
96
|
+
{{ snapshot.route.name || 'route' }}
|
|
97
|
+
<span class="font-mono text-default">{{ snapshot.route.fullPath }}</span>
|
|
98
|
+
</p>
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
<DebugHttpRequests
|
|
102
|
+
v-else-if="tab === 'http'"
|
|
103
|
+
:entries="snapshot.http"
|
|
104
|
+
@clear="bridge?.clearHttp()"
|
|
105
|
+
/>
|
|
106
|
+
|
|
107
|
+
<div v-else-if="tab === 'logs'" class="flex flex-col gap-3">
|
|
108
|
+
<DebugApplicationLogs :entries="snapshot.logs ?? []" @clear="bridge?.clearLogs()" />
|
|
109
|
+
<DebugNavigation :entries="snapshot.nav" @clear="bridge?.clearNav()" />
|
|
110
|
+
<DebugFirestoreOperations :entries="snapshot.firestore" @clear="bridge?.clearFirestore()" />
|
|
111
|
+
<DebugErrorLogs :entries="snapshot.errors" @clear="bridge?.clearErrors()" />
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<DebugPublicConfig v-else :entries="snapshot.publicConfig" />
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
</template>
|
|
118
|
+
|
|
119
|
+
<script setup lang="ts">
|
|
120
|
+
import { computed, createError, onMounted, onUnmounted, ref } from '#imports'
|
|
121
|
+
import type { BakusokuDebugBridge, BakusokuDebugSnapshot } from '../utils/debug-bridge'
|
|
122
|
+
import DebugApplicationLogs from '../components/debug/DebugApplicationLogs.vue'
|
|
123
|
+
import DebugErrorLogs from '../components/debug/DebugErrorLogs.vue'
|
|
124
|
+
import DebugFirestoreOperations from '../components/debug/DebugFirestoreOperations.vue'
|
|
125
|
+
import DebugHttpRequests from '../components/debug/DebugHttpRequests.vue'
|
|
126
|
+
import DebugNavigation from '../components/debug/DebugNavigation.vue'
|
|
127
|
+
import DebugNowControl from '../components/debug/DebugNowControl.vue'
|
|
128
|
+
import DebugPublicConfig from '../components/debug/DebugPublicConfig.vue'
|
|
129
|
+
|
|
130
|
+
definePageMeta({
|
|
131
|
+
layout: false,
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
if (!import.meta.dev) {
|
|
135
|
+
throw createError({ statusCode: 404, statusMessage: 'Not Found' })
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface HostNuxt {
|
|
139
|
+
$bakusokuDebug?: BakusokuDebugBridge
|
|
140
|
+
vueApp?: {
|
|
141
|
+
config?: {
|
|
142
|
+
globalProperties?: {
|
|
143
|
+
$bakusokuDebug?: BakusokuDebugBridge
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface DevtoolsClient {
|
|
150
|
+
host?: {
|
|
151
|
+
nuxt?: HostNuxt
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface DevtoolsHostClient {
|
|
156
|
+
nuxt?: HostNuxt
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const snapshot = ref<BakusokuDebugSnapshot | null>(null)
|
|
160
|
+
const bridge = ref<BakusokuDebugBridge | null>(null)
|
|
161
|
+
const status = ref('操作中のアプリへ接続しています…')
|
|
162
|
+
const tab = ref('overview')
|
|
163
|
+
|
|
164
|
+
const tabs = computed(() => [
|
|
165
|
+
{ label: '概要', value: 'overview' },
|
|
166
|
+
{ label: `HTTP ${snapshot.value?.http.length ?? 0}`, value: 'http' },
|
|
167
|
+
{ label: `ログ ${logCount.value}`, value: 'logs' },
|
|
168
|
+
{ label: '設定', value: 'config' },
|
|
169
|
+
])
|
|
170
|
+
|
|
171
|
+
const logCount = computed(() => {
|
|
172
|
+
const current = snapshot.value
|
|
173
|
+
if (!current) {
|
|
174
|
+
return 0
|
|
175
|
+
}
|
|
176
|
+
return (current.logs?.length ?? 0) + current.nav.length + current.firestore.length + current.errors.length
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
const envRows = computed(() => {
|
|
180
|
+
const current = snapshot.value
|
|
181
|
+
if (!current) {
|
|
182
|
+
return []
|
|
183
|
+
}
|
|
184
|
+
return [
|
|
185
|
+
{ label: 'NODE_ENV', value: current.nodeEnv || '-' },
|
|
186
|
+
{ label: 'APP_ENV', value: current.appEnv || '-' },
|
|
187
|
+
{ label: 'projectId', value: current.firebaseProjectId || '-' },
|
|
188
|
+
{ label: 'authDomain', value: current.firebaseAuthDomain || '-' },
|
|
189
|
+
{ label: 'emulators', value: current.emulators || '-' },
|
|
190
|
+
]
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
const authRows = computed(() => {
|
|
194
|
+
const current = snapshot.value
|
|
195
|
+
if (!current) {
|
|
196
|
+
return []
|
|
197
|
+
}
|
|
198
|
+
return [
|
|
199
|
+
{ label: 'UID', value: current.auth.uid || '-' },
|
|
200
|
+
{ label: 'メール', value: current.auth.email || '-' },
|
|
201
|
+
{ label: 'ロール', value: current.auth.role || '-' },
|
|
202
|
+
{ label: 'トークン期限', value: current.token.expiry || '-' },
|
|
203
|
+
{ label: 'provider', value: current.token.provider || '-' },
|
|
204
|
+
]
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
let unsubscribe: (() => void) | null = null
|
|
208
|
+
let timer: ReturnType<typeof setInterval> | null = null
|
|
209
|
+
|
|
210
|
+
/** Nuxt アプリからデバッグブリッジを取得する。 */
|
|
211
|
+
function bridgeFromNuxt(nuxt: HostNuxt | null | undefined): BakusokuDebugBridge | null {
|
|
212
|
+
if (!nuxt) {
|
|
213
|
+
return null
|
|
214
|
+
}
|
|
215
|
+
return nuxt.$bakusokuDebug
|
|
216
|
+
?? nuxt.vueApp?.config?.globalProperties?.$bakusokuDebug
|
|
217
|
+
?? null
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** DevTools を開いた側の Nuxt アプリを取得する。 */
|
|
221
|
+
function readHostNuxt(): HostNuxt | null {
|
|
222
|
+
const legacy = (window as Window & { __NUXT_DEVTOOLS__?: DevtoolsClient }).__NUXT_DEVTOOLS__
|
|
223
|
+
if (legacy?.host?.nuxt) {
|
|
224
|
+
return legacy.host.nuxt
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const hostWindow = window.parent === window ? window : window.parent
|
|
228
|
+
try {
|
|
229
|
+
return (hostWindow as Window & { __NUXT_DEVTOOLS_HOST__?: DevtoolsHostClient }).__NUXT_DEVTOOLS_HOST__?.nuxt ?? null
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return null
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** 接続可能な Nuxt アプリからデバッグブリッジを取得する。 */
|
|
237
|
+
function readBridge(): BakusokuDebugBridge | null {
|
|
238
|
+
return bridgeFromNuxt(readHostNuxt())
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** デバッグブリッジを接続し、状態の更新を購読する。 */
|
|
242
|
+
function attach(next: BakusokuDebugBridge): void {
|
|
243
|
+
unsubscribe?.()
|
|
244
|
+
bridge.value = next
|
|
245
|
+
/** デバッグブリッジの最新情報を画面の状態に反映する。 */
|
|
246
|
+
const pull = () => {
|
|
247
|
+
snapshot.value = next.getSnapshot()
|
|
248
|
+
}
|
|
249
|
+
pull()
|
|
250
|
+
unsubscribe = next.subscribe(pull)
|
|
251
|
+
status.value = '操作中のアプリに接続しました'
|
|
252
|
+
if (timer) {
|
|
253
|
+
clearInterval(timer)
|
|
254
|
+
timer = null
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** デバッグブリッジを探して画面と接続する。 */
|
|
259
|
+
function tryConnect(): boolean {
|
|
260
|
+
const next = readBridge()
|
|
261
|
+
if (!next || next === bridge.value) {
|
|
262
|
+
return Boolean(next)
|
|
263
|
+
}
|
|
264
|
+
attach(next)
|
|
265
|
+
return true
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
onMounted(() => {
|
|
269
|
+
if (tryConnect()) {
|
|
270
|
+
return
|
|
271
|
+
}
|
|
272
|
+
let attempts = 0
|
|
273
|
+
timer = setInterval(() => {
|
|
274
|
+
attempts += 1
|
|
275
|
+
if (tryConnect()) {
|
|
276
|
+
return
|
|
277
|
+
}
|
|
278
|
+
if (attempts > 40) {
|
|
279
|
+
status.value = '接続できません。開発サーバーで DevTools を開いているか確認してください。'
|
|
280
|
+
if (timer) {
|
|
281
|
+
clearInterval(timer)
|
|
282
|
+
timer = null
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}, 250)
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
onUnmounted(() => {
|
|
289
|
+
unsubscribe?.()
|
|
290
|
+
if (timer) {
|
|
291
|
+
clearInterval(timer)
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
</script>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { watch } from 'vue'
|
|
2
|
+
import { useCurrentUser } from 'vuefire'
|
|
3
|
+
import type { Auth } from 'firebase/auth'
|
|
4
|
+
import type { Pinia } from 'pinia'
|
|
5
|
+
import { defineNuxtPlugin, useNuxtApp } from 'nuxt/app'
|
|
6
|
+
import { resolveAuthUser } from '../utils/resolve-auth-user'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Firebase Auth と useBakusokuAuthStore プロフィールの同期。
|
|
10
|
+
*
|
|
11
|
+
* - 初回(SSR / Client): resolveAuthUser → setupAuthentication
|
|
12
|
+
* - Client: useCurrentUser の変化を watch して追従
|
|
13
|
+
*
|
|
14
|
+
* middleware はストアを読むだけ(書き込みはここに集約)。
|
|
15
|
+
*/
|
|
16
|
+
export default defineNuxtPlugin({
|
|
17
|
+
name: 'bakusoku-auth-init',
|
|
18
|
+
dependsOn: ['pinia'],
|
|
19
|
+
enforce: 'post',
|
|
20
|
+
/** 初回の認証状態をストアに反映し、ブラウザーではその後の変更も同期する。 */
|
|
21
|
+
async setup() {
|
|
22
|
+
const nuxtApp = useNuxtApp()
|
|
23
|
+
const auth = useBakusokuAuthStore(nuxtApp.$pinia as Pinia)
|
|
24
|
+
const firebaseAuth = nuxtApp.$firebaseAuth as Auth | undefined
|
|
25
|
+
|
|
26
|
+
const firebaseUser = await resolveAuthUser(nuxtApp, firebaseAuth)
|
|
27
|
+
await auth.setupAuthentication(firebaseUser)
|
|
28
|
+
|
|
29
|
+
if (!import.meta.client) return
|
|
30
|
+
|
|
31
|
+
const currentUser = useCurrentUser()
|
|
32
|
+
watch(currentUser, async nextUser => {
|
|
33
|
+
await auth.setupAuthentication(nextUser ? { uid: nextUser.uid } : null)
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
|
|
2
|
+
import { createBakusokuDebugBridge } from '../utils/debug-bridge'
|
|
3
|
+
import { isBakusokuDebugEnabled } from '../utils/is-debug-enabled'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 開発時のみ、操作中アプリのデバッグ状態を DevTools タブへ渡す。
|
|
7
|
+
*/
|
|
8
|
+
export default defineNuxtPlugin({
|
|
9
|
+
name: 'bakusoku-debug-devtools',
|
|
10
|
+
/** DevTools が参照するデバッグブリッジを Nuxt に登録する。 */
|
|
11
|
+
setup(nuxtApp) {
|
|
12
|
+
if (!isBakusokuDebugEnabled(useRuntimeConfig())) {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const bridge = createBakusokuDebugBridge()
|
|
17
|
+
nuxtApp.provide('bakusokuDebug', bridge)
|
|
18
|
+
void bridge.refreshToken()
|
|
19
|
+
},
|
|
20
|
+
})
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
|
|
2
|
+
import { isBakusokuDebugEnabled } from '../utils/is-debug-enabled'
|
|
3
|
+
import { useBakusokuDebugStore } from '../stores/debug'
|
|
4
|
+
|
|
5
|
+
/** 捕捉した例外から表示可能なメッセージを取り出す。 */
|
|
6
|
+
function toErrorMessage(error: unknown): string {
|
|
7
|
+
if (error instanceof Error) {
|
|
8
|
+
return error.message
|
|
9
|
+
}
|
|
10
|
+
if (typeof error === 'string') {
|
|
11
|
+
return error
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(error)
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return String(error)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 捕捉した例外にスタックトレースがあれば取り出す。 */
|
|
22
|
+
function toErrorStack(error: unknown): string | undefined {
|
|
23
|
+
if (error instanceof Error && error.stack) {
|
|
24
|
+
return error.stack
|
|
25
|
+
}
|
|
26
|
+
if (error && typeof error === 'object' && 'stack' in error) {
|
|
27
|
+
const stack = (error as { stack?: unknown }).stack
|
|
28
|
+
return typeof stack === 'string' ? stack : undefined
|
|
29
|
+
}
|
|
30
|
+
return undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 開発時のみ Vue / グローバルエラーをデバッグストアへ記録する。
|
|
35
|
+
*/
|
|
36
|
+
export default defineNuxtPlugin({
|
|
37
|
+
name: 'bakusoku-debug-errors',
|
|
38
|
+
/** ブラウザーと Nuxt で発生した未処理のエラーを収集する。 */
|
|
39
|
+
setup(nuxtApp) {
|
|
40
|
+
if (!isBakusokuDebugEnabled(useRuntimeConfig())) {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const previousErrorHandler = nuxtApp.vueApp.config.errorHandler
|
|
45
|
+
nuxtApp.vueApp.config.errorHandler = (error, instance, info) => {
|
|
46
|
+
const debugStore = useBakusokuDebugStore()
|
|
47
|
+
debugStore.recordError({
|
|
48
|
+
message: toErrorMessage(error),
|
|
49
|
+
stack: toErrorStack(error),
|
|
50
|
+
source: info ? `vue:${info}` : 'vue',
|
|
51
|
+
})
|
|
52
|
+
console.error('[bakusoku-debug]', error)
|
|
53
|
+
if (typeof previousErrorHandler === 'function') {
|
|
54
|
+
previousErrorHandler(error, instance, info)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
nuxtApp.hook('app:error', (error) => {
|
|
59
|
+
const debugStore = useBakusokuDebugStore()
|
|
60
|
+
debugStore.recordError({
|
|
61
|
+
message: toErrorMessage(error),
|
|
62
|
+
stack: toErrorStack(error),
|
|
63
|
+
source: 'nuxt:app:error',
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
if (import.meta.client) {
|
|
68
|
+
window.addEventListener('unhandledrejection', (event) => {
|
|
69
|
+
const debugStore = useBakusokuDebugStore()
|
|
70
|
+
debugStore.recordError({
|
|
71
|
+
message: toErrorMessage(event.reason),
|
|
72
|
+
stack: toErrorStack(event.reason),
|
|
73
|
+
source: 'unhandledrejection',
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
})
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
|
|
2
|
+
import { isBakusokuDebugEnabled } from '../utils/is-debug-enabled'
|
|
3
|
+
import { maskSecrets, serializeDebugBody } from '../utils/mask-secrets'
|
|
4
|
+
import { useBakusokuDebugStore } from '../stores/debug'
|
|
5
|
+
|
|
6
|
+
type DebugFetchOptions = {
|
|
7
|
+
method?: string
|
|
8
|
+
body?: unknown
|
|
9
|
+
headers?: HeadersInit
|
|
10
|
+
_bakusokuDebugStart?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** リクエスト入力からログ用の URL を取得する。 */
|
|
14
|
+
function resolveUrl(request: RequestInfo | URL | string): string {
|
|
15
|
+
if (typeof request === 'string') {
|
|
16
|
+
return request
|
|
17
|
+
}
|
|
18
|
+
if (request instanceof URL) {
|
|
19
|
+
return request.toString()
|
|
20
|
+
}
|
|
21
|
+
if (typeof Request !== 'undefined' && request instanceof Request) {
|
|
22
|
+
return request.url
|
|
23
|
+
}
|
|
24
|
+
return String(request)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** リクエスト入力とオプションから HTTP メソッドを取得する。 */
|
|
28
|
+
function resolveMethod(
|
|
29
|
+
request: RequestInfo | URL | string,
|
|
30
|
+
options: DebugFetchOptions,
|
|
31
|
+
): string {
|
|
32
|
+
if (options.method) {
|
|
33
|
+
return String(options.method).toUpperCase()
|
|
34
|
+
}
|
|
35
|
+
if (typeof Request !== 'undefined' && request instanceof Request) {
|
|
36
|
+
return request.method.toUpperCase()
|
|
37
|
+
}
|
|
38
|
+
return 'GET'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** ヘッダーをログに記録できるオブジェクト形式に整える。 */
|
|
42
|
+
function normalizeHeaders(
|
|
43
|
+
headers: HeadersInit | undefined,
|
|
44
|
+
): Record<string, string> | undefined {
|
|
45
|
+
if (!headers) {
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const raw: Record<string, string> = {}
|
|
50
|
+
if (headers instanceof Headers) {
|
|
51
|
+
headers.forEach((value, key) => {
|
|
52
|
+
raw[key] = value
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
else if (Array.isArray(headers)) {
|
|
56
|
+
for (const [key, value] of headers) {
|
|
57
|
+
raw[key] = value
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
Object.assign(raw, headers)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return maskSecrets(raw) as Record<string, string>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** HTTP エラーからレスポンス本文を取り出す。 */
|
|
68
|
+
function extractErrorPayload(error: unknown): unknown {
|
|
69
|
+
if (!error || typeof error !== 'object') {
|
|
70
|
+
return undefined
|
|
71
|
+
}
|
|
72
|
+
const data = (error as { data?: unknown }).data
|
|
73
|
+
return data !== undefined ? serializeDebugBody(data) : undefined
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 開発時のみ $fetch をラップし、API リクエストをデバッグストアへ記録する。
|
|
78
|
+
*/
|
|
79
|
+
export default defineNuxtPlugin({
|
|
80
|
+
name: 'bakusoku-debug-http',
|
|
81
|
+
enforce: 'pre',
|
|
82
|
+
/** HTTP リクエストの結果を記録するためのフックを登録する。 */
|
|
83
|
+
setup() {
|
|
84
|
+
if (!isBakusokuDebugEnabled(useRuntimeConfig())) {
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const originalFetch = globalThis.$fetch
|
|
89
|
+
if (!originalFetch || typeof originalFetch.create !== 'function') {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
globalThis.$fetch = originalFetch.create({
|
|
94
|
+
/** 経過時間を計測するためにリクエスト開始時刻を記録する。 */
|
|
95
|
+
onRequest({ options }) {
|
|
96
|
+
const opts = options as DebugFetchOptions
|
|
97
|
+
opts._bakusokuDebugStart = Date.now()
|
|
98
|
+
},
|
|
99
|
+
/** 正常な応答の内容と所要時間をデバッグ履歴に記録する。 */
|
|
100
|
+
onResponse({ request, response, options }) {
|
|
101
|
+
const debugStore = useBakusokuDebugStore()
|
|
102
|
+
const opts = options as DebugFetchOptions
|
|
103
|
+
const started = opts._bakusokuDebugStart
|
|
104
|
+
const durationMs = started != null ? Date.now() - started : 0
|
|
105
|
+
|
|
106
|
+
debugStore.recordHttp({
|
|
107
|
+
method: resolveMethod(request, opts),
|
|
108
|
+
url: resolveUrl(request),
|
|
109
|
+
status: response.status,
|
|
110
|
+
durationMs,
|
|
111
|
+
requestBody: serializeDebugBody(opts.body),
|
|
112
|
+
responseBody: serializeDebugBody(response._data),
|
|
113
|
+
requestHeaders: normalizeHeaders(opts.headers),
|
|
114
|
+
})
|
|
115
|
+
},
|
|
116
|
+
/** HTTP エラー応答のステータスと内容を記録する。 */
|
|
117
|
+
onResponseError({ request, response, options, error }) {
|
|
118
|
+
const debugStore = useBakusokuDebugStore()
|
|
119
|
+
const opts = options as DebugFetchOptions
|
|
120
|
+
const started = opts._bakusokuDebugStart
|
|
121
|
+
const durationMs = started != null ? Date.now() - started : 0
|
|
122
|
+
|
|
123
|
+
debugStore.recordHttp({
|
|
124
|
+
method: resolveMethod(request, opts),
|
|
125
|
+
url: resolveUrl(request),
|
|
126
|
+
status: response?.status ?? null,
|
|
127
|
+
durationMs,
|
|
128
|
+
requestBody: serializeDebugBody(opts.body),
|
|
129
|
+
responseBody:
|
|
130
|
+
serializeDebugBody(response?._data) ?? extractErrorPayload(error),
|
|
131
|
+
requestHeaders: normalizeHeaders(opts.headers),
|
|
132
|
+
error: error instanceof Error ? error.message : String(error ?? 'request failed'),
|
|
133
|
+
})
|
|
134
|
+
},
|
|
135
|
+
/** レスポンス受信前の通信エラーをデバッグ履歴に記録する。 */
|
|
136
|
+
onRequestError({ request, options, error }) {
|
|
137
|
+
const debugStore = useBakusokuDebugStore()
|
|
138
|
+
const opts = options as DebugFetchOptions
|
|
139
|
+
const started = opts._bakusokuDebugStart
|
|
140
|
+
const durationMs = started != null ? Date.now() - started : 0
|
|
141
|
+
|
|
142
|
+
debugStore.recordHttp({
|
|
143
|
+
method: resolveMethod(request, opts),
|
|
144
|
+
url: resolveUrl(request),
|
|
145
|
+
status: null,
|
|
146
|
+
durationMs,
|
|
147
|
+
requestBody: serializeDebugBody(opts.body),
|
|
148
|
+
requestHeaders: normalizeHeaders(opts.headers),
|
|
149
|
+
error: error instanceof Error ? error.message : String(error ?? 'request error'),
|
|
150
|
+
})
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
},
|
|
154
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig, useRouter } from 'nuxt/app'
|
|
2
|
+
import { isBakusokuDebugEnabled } from '../utils/is-debug-enabled'
|
|
3
|
+
import { useBakusokuDebugStore } from '../stores/debug'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 開発時のみページ遷移をデバッグストアへ記録する。
|
|
7
|
+
*/
|
|
8
|
+
export default defineNuxtPlugin({
|
|
9
|
+
name: 'bakusoku-debug-nav',
|
|
10
|
+
/** ルート遷移後に遷移先を記録するフックを登録する。 */
|
|
11
|
+
setup() {
|
|
12
|
+
if (!isBakusokuDebugEnabled(useRuntimeConfig())) {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const router = useRouter()
|
|
17
|
+
const debugStore = useBakusokuDebugStore()
|
|
18
|
+
|
|
19
|
+
router.afterEach((to) => {
|
|
20
|
+
debugStore.recordNav({
|
|
21
|
+
fullPath: to.fullPath,
|
|
22
|
+
name: to.name != null ? String(to.name) : null,
|
|
23
|
+
params: { ...to.params },
|
|
24
|
+
query: { ...to.query },
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
|
|
2
|
+
import { isBakusokuDebugEnabled } from '../utils/is-debug-enabled'
|
|
3
|
+
import { inspectNuxtVuefirePipeline } from '../utils/inspect-nuxt-vuefire'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* nuxt-vuefire の到達状況をコンソールに出す(開発時のみ・画面表示なし)
|
|
7
|
+
*/
|
|
8
|
+
export default defineNuxtPlugin({
|
|
9
|
+
name: 'bakusoku-vuefire-inspect',
|
|
10
|
+
enforce: 'post',
|
|
11
|
+
/** VueFire の初期化状態をデバッグログに出力する。 */
|
|
12
|
+
setup() {
|
|
13
|
+
if (!isBakusokuDebugEnabled(useRuntimeConfig())) return
|
|
14
|
+
|
|
15
|
+
const snapshot = inspectNuxtVuefirePipeline()
|
|
16
|
+
useBakusokuLogger('vuefire').debug('pipeline', snapshot)
|
|
17
|
+
},
|
|
18
|
+
})
|