@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,270 @@
|
|
|
1
|
+
import { watch } from 'vue'
|
|
2
|
+
import { useRoute, useRuntimeConfig } from 'nuxt/app'
|
|
3
|
+
import { useFirebaseAuth } from 'vuefire'
|
|
4
|
+
import type {
|
|
5
|
+
DebugErrorEntry,
|
|
6
|
+
DebugFirestoreEntry,
|
|
7
|
+
DebugHttpEntry,
|
|
8
|
+
DebugLogEntry,
|
|
9
|
+
DebugNavEntry,
|
|
10
|
+
} from '../stores/debug'
|
|
11
|
+
import { useBakusokuDebugStore } from '../stores/debug'
|
|
12
|
+
import { useBakusokuAuthStore } from '../stores/auth'
|
|
13
|
+
import { useBakusokuDateTimeStore } from '../stores/datetime'
|
|
14
|
+
|
|
15
|
+
export interface BakusokuDebugSnapshot {
|
|
16
|
+
now: string
|
|
17
|
+
nowOverridden: boolean
|
|
18
|
+
nodeEnv: string
|
|
19
|
+
appEnv: string
|
|
20
|
+
firebaseProjectId: string
|
|
21
|
+
firebaseAuthDomain: string
|
|
22
|
+
emulators: string
|
|
23
|
+
publicConfig: { key: string; value: string }[]
|
|
24
|
+
auth: {
|
|
25
|
+
isAuthenticated: boolean
|
|
26
|
+
uid: string
|
|
27
|
+
email: string
|
|
28
|
+
role: string
|
|
29
|
+
}
|
|
30
|
+
token: {
|
|
31
|
+
expiry: string
|
|
32
|
+
provider: string
|
|
33
|
+
}
|
|
34
|
+
route: {
|
|
35
|
+
fullPath: string
|
|
36
|
+
name: string | null
|
|
37
|
+
}
|
|
38
|
+
http: DebugHttpEntry[]
|
|
39
|
+
nav: DebugNavEntry[]
|
|
40
|
+
firestore: DebugFirestoreEntry[]
|
|
41
|
+
errors: DebugErrorEntry[]
|
|
42
|
+
logs: DebugLogEntry[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface BakusokuDebugBridge {
|
|
46
|
+
getSnapshot: () => BakusokuDebugSnapshot
|
|
47
|
+
subscribe: (listener: () => void) => () => void
|
|
48
|
+
clearAllLogs: () => void
|
|
49
|
+
clearHttp: () => void
|
|
50
|
+
clearNav: () => void
|
|
51
|
+
clearFirestore: () => void
|
|
52
|
+
clearErrors: () => void
|
|
53
|
+
clearLogs: () => void
|
|
54
|
+
setOffsetHours: (hours: number) => void
|
|
55
|
+
setOffsetDays: (days: number) => void
|
|
56
|
+
shiftNow: (ms: number) => void
|
|
57
|
+
setNow: (iso: string) => void
|
|
58
|
+
resetNow: () => void
|
|
59
|
+
refreshToken: () => Promise<void>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** デバッグ情報をフレーム間で扱えるプレーンなデータに変換する。 */
|
|
63
|
+
function toPlain<T>(value: T): T {
|
|
64
|
+
return JSON.parse(JSON.stringify(value)) as T
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 設定値をデバッグ画面の表示用に整形する。 */
|
|
68
|
+
function formatConfigValue(value: unknown): string {
|
|
69
|
+
if (value == null || typeof value !== 'object') {
|
|
70
|
+
return String(value)
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return JSON.stringify(value)
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return '[object]'
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 操作中アプリのデバッグ状態を DevTools iframe から読むための橋。
|
|
82
|
+
* ストアはホスト側の Pinia に残し、スナップショットだけを渡す。
|
|
83
|
+
*/
|
|
84
|
+
export function createBakusokuDebugBridge(): BakusokuDebugBridge {
|
|
85
|
+
const route = useRoute()
|
|
86
|
+
const runtimeConfig = useRuntimeConfig()
|
|
87
|
+
const debugStore = useBakusokuDebugStore()
|
|
88
|
+
const authStore = useBakusokuAuthStore()
|
|
89
|
+
const dateTimeStore = useBakusokuDateTimeStore()
|
|
90
|
+
const firebaseAuth = import.meta.client ? useFirebaseAuth() : null
|
|
91
|
+
|
|
92
|
+
const listeners = new Set<() => void>()
|
|
93
|
+
let tokenExpiry = '-'
|
|
94
|
+
let tokenProvider = ''
|
|
95
|
+
|
|
96
|
+
const publicVuefire = (runtimeConfig.public.vuefire ?? {}) as {
|
|
97
|
+
config?: Record<string, string>
|
|
98
|
+
emulators?: Record<string, { host?: string; port?: number }>
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** デバッグ情報の更新を購読者に通知する。 */
|
|
102
|
+
function notify(): void {
|
|
103
|
+
for (const listener of [...listeners]) {
|
|
104
|
+
try {
|
|
105
|
+
listener()
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
listeners.delete(listener)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** ログ、認証状態、設定などの現在のデバッグ情報をまとめる。 */
|
|
114
|
+
function getSnapshot(): BakusokuDebugSnapshot {
|
|
115
|
+
const emulators = publicVuefire.emulators
|
|
116
|
+
const emulatorText = emulators && Object.keys(emulators).length
|
|
117
|
+
? Object.entries(emulators)
|
|
118
|
+
.map(([name, value]) => `${name}=${value?.host}:${value?.port}`)
|
|
119
|
+
.join(', ')
|
|
120
|
+
: 'なし'
|
|
121
|
+
|
|
122
|
+
const pub = runtimeConfig.public as Record<string, unknown>
|
|
123
|
+
const publicConfig = Object.keys(pub)
|
|
124
|
+
.sort()
|
|
125
|
+
.map(key => ({ key, value: formatConfigValue(pub[key]) }))
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
now: dateTimeStore.effectiveNow.toISOString(),
|
|
129
|
+
nowOverridden: dateTimeStore.nowOverride != null,
|
|
130
|
+
nodeEnv: process.env.NODE_ENV || '',
|
|
131
|
+
appEnv: String(runtimeConfig.public.appEnv ?? ''),
|
|
132
|
+
firebaseProjectId: publicVuefire.config?.projectId ?? '',
|
|
133
|
+
firebaseAuthDomain: publicVuefire.config?.authDomain ?? '',
|
|
134
|
+
emulators: emulatorText,
|
|
135
|
+
publicConfig,
|
|
136
|
+
auth: {
|
|
137
|
+
isAuthenticated: authStore.isAuthenticated,
|
|
138
|
+
uid: authStore.user?.uid ?? '',
|
|
139
|
+
email: authStore.user?.email ?? '',
|
|
140
|
+
role: authStore.user?.role ?? '',
|
|
141
|
+
},
|
|
142
|
+
token: {
|
|
143
|
+
expiry: tokenExpiry,
|
|
144
|
+
provider: tokenProvider,
|
|
145
|
+
},
|
|
146
|
+
route: {
|
|
147
|
+
fullPath: route.fullPath,
|
|
148
|
+
name: route.name != null ? String(route.name) : null,
|
|
149
|
+
},
|
|
150
|
+
http: toPlain(debugStore.httpEntries),
|
|
151
|
+
nav: toPlain(debugStore.navEntries),
|
|
152
|
+
firestore: toPlain(debugStore.firestoreEntries),
|
|
153
|
+
errors: toPlain(debugStore.errorEntries),
|
|
154
|
+
logs: toPlain(debugStore.logEntries),
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
watch(
|
|
159
|
+
() => [
|
|
160
|
+
debugStore.httpEntries[0]?.id,
|
|
161
|
+
debugStore.httpEntries.length,
|
|
162
|
+
debugStore.navEntries[0]?.id,
|
|
163
|
+
debugStore.navEntries.length,
|
|
164
|
+
debugStore.firestoreEntries[0]?.id,
|
|
165
|
+
debugStore.firestoreEntries.length,
|
|
166
|
+
debugStore.errorEntries[0]?.id,
|
|
167
|
+
debugStore.errorEntries.length,
|
|
168
|
+
debugStore.logEntries[0]?.id,
|
|
169
|
+
debugStore.logEntries.length,
|
|
170
|
+
authStore.user?.uid ?? '',
|
|
171
|
+
route.fullPath,
|
|
172
|
+
dateTimeStore.nowOverride?.toISOString() ?? '',
|
|
173
|
+
],
|
|
174
|
+
() => notify(),
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
/** 現在のデバッグ時刻を複製してから変更し、ストアに設定する。 */
|
|
178
|
+
function shiftNow(update: (date: Date) => void): void {
|
|
179
|
+
const next = new Date(dateTimeStore.effectiveNow)
|
|
180
|
+
update(next)
|
|
181
|
+
debugStore.setNowOverride(next)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
getSnapshot,
|
|
186
|
+
/** デバッグ情報の変更通知を購読し、購読を解除する関数を返す。 */
|
|
187
|
+
subscribe(listener) {
|
|
188
|
+
listeners.add(listener)
|
|
189
|
+
return () => listeners.delete(listener)
|
|
190
|
+
},
|
|
191
|
+
/** すべてのデバッグ履歴を消去する。 */
|
|
192
|
+
clearAllLogs() {
|
|
193
|
+
debugStore.clearAllLogs()
|
|
194
|
+
},
|
|
195
|
+
/** HTTP 通信のデバッグ履歴を消去する。 */
|
|
196
|
+
clearHttp() {
|
|
197
|
+
debugStore.clearHttp()
|
|
198
|
+
},
|
|
199
|
+
/** ページ遷移のデバッグ履歴を消去する。 */
|
|
200
|
+
clearNav() {
|
|
201
|
+
debugStore.clearNav()
|
|
202
|
+
},
|
|
203
|
+
/** Firestore 操作のデバッグ履歴を消去する。 */
|
|
204
|
+
clearFirestore() {
|
|
205
|
+
debugStore.clearFirestore()
|
|
206
|
+
},
|
|
207
|
+
/** エラー履歴を消去し、購読者に通知する。 */
|
|
208
|
+
clearErrors() {
|
|
209
|
+
debugStore.clearErrors()
|
|
210
|
+
notify()
|
|
211
|
+
},
|
|
212
|
+
/** ロガーの出力履歴を消去し、購読者に通知する。 */
|
|
213
|
+
clearLogs() {
|
|
214
|
+
debugStore.clearLogs()
|
|
215
|
+
notify()
|
|
216
|
+
},
|
|
217
|
+
/** 現在のデバッグ時刻を指定された時間数だけずらす。 */
|
|
218
|
+
setOffsetHours(hours) {
|
|
219
|
+
shiftNow(date => date.setHours(date.getHours() + hours))
|
|
220
|
+
},
|
|
221
|
+
/** 現在のデバッグ日付を指定された日数だけずらす。 */
|
|
222
|
+
setOffsetDays(days) {
|
|
223
|
+
shiftNow(date => date.setDate(date.getDate() + days))
|
|
224
|
+
},
|
|
225
|
+
/** 現在のデバッグ時刻を指定されたミリ秒だけずらす。 */
|
|
226
|
+
shiftNow(ms) {
|
|
227
|
+
const next = new Date(dateTimeStore.effectiveNow.getTime() + ms)
|
|
228
|
+
debugStore.setNowOverride(next)
|
|
229
|
+
},
|
|
230
|
+
/** 有効な日時文字列をデバッグ時刻として設定する。 */
|
|
231
|
+
setNow(iso) {
|
|
232
|
+
const next = new Date(iso)
|
|
233
|
+
if (Number.isNaN(next.getTime())) {
|
|
234
|
+
return
|
|
235
|
+
}
|
|
236
|
+
debugStore.setNowOverride(next)
|
|
237
|
+
},
|
|
238
|
+
/** デバッグ時刻の上書きを解除する。 */
|
|
239
|
+
resetNow() {
|
|
240
|
+
debugStore.clearOverride()
|
|
241
|
+
},
|
|
242
|
+
/** ブラウザーの認証トークンの有効期限と認証プロバイダーを取得する。 */
|
|
243
|
+
async refreshToken() {
|
|
244
|
+
if (!import.meta.client) {
|
|
245
|
+
tokenExpiry = 'client のみ'
|
|
246
|
+
tokenProvider = ''
|
|
247
|
+
notify()
|
|
248
|
+
return
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
const current = firebaseAuth?.currentUser
|
|
253
|
+
if (!current) {
|
|
254
|
+
tokenExpiry = '未ログイン'
|
|
255
|
+
tokenProvider = ''
|
|
256
|
+
notify()
|
|
257
|
+
return
|
|
258
|
+
}
|
|
259
|
+
const result = await current.getIdTokenResult()
|
|
260
|
+
tokenExpiry = new Date(result.expirationTime).toLocaleString('ja-JP')
|
|
261
|
+
tokenProvider = result.signInProvider ?? ''
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
tokenExpiry = error instanceof Error ? error.message : '取得失敗'
|
|
265
|
+
tokenProvider = ''
|
|
266
|
+
}
|
|
267
|
+
notify()
|
|
268
|
+
},
|
|
269
|
+
}
|
|
270
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isBakusokuDebugEnabled } from './is-debug-enabled'
|
|
2
|
+
import { useBakusokuDebugStore } from '../stores/debug'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Firestore 操作をデバッグストアへ記録しつつ実行する(開発時のみ)。
|
|
6
|
+
*/
|
|
7
|
+
export async function withFirestoreDebug<T>(
|
|
8
|
+
operation: string,
|
|
9
|
+
path: string,
|
|
10
|
+
fn: () => Promise<T>,
|
|
11
|
+
detailFromResult?: (result: T) => string | undefined,
|
|
12
|
+
): Promise<T> {
|
|
13
|
+
if (!isBakusokuDebugEnabled()) {
|
|
14
|
+
return fn()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const debugStore = useBakusokuDebugStore()
|
|
18
|
+
const started = Date.now()
|
|
19
|
+
try {
|
|
20
|
+
const result = await fn()
|
|
21
|
+
debugStore.recordFirestore({
|
|
22
|
+
operation,
|
|
23
|
+
path,
|
|
24
|
+
durationMs: Date.now() - started,
|
|
25
|
+
detail: detailFromResult?.(result),
|
|
26
|
+
})
|
|
27
|
+
return result
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
debugStore.recordFirestore({
|
|
31
|
+
operation,
|
|
32
|
+
path,
|
|
33
|
+
durationMs: Date.now() - started,
|
|
34
|
+
error: error instanceof Error ? error.message : String(error),
|
|
35
|
+
})
|
|
36
|
+
throw error
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** 日時を画面表示用の文字列に変換する。 */
|
|
2
|
+
export function formatDebugTime(iso: string): string {
|
|
3
|
+
try {
|
|
4
|
+
return new Date(iso).toLocaleTimeString('ja-JP')
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return iso
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** デバッグ値を画面で読める文字列に変換する。 */
|
|
12
|
+
export function stringifyDebugValue(value: unknown): string {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(value, null, 2)
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return String(value)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { onMounted, onUnmounted, watch } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** 自動更新を続ける必要がある実行状態か判定する。 */
|
|
4
|
+
export function isExecutionActive(status?: string) {
|
|
5
|
+
return status === 'pending' || status === 'accepted' || status === 'running' || status === 'retrying'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** 表示中のページで進行中の実行を定期取得し、手動更新と競合する古い結果を破棄する。 */
|
|
9
|
+
export function useExecutionRefresh(
|
|
10
|
+
enabled: boolean,
|
|
11
|
+
hasActiveExecutions: () => boolean,
|
|
12
|
+
read: (background: boolean, isCurrent: () => boolean) => Promise<void>,
|
|
13
|
+
) {
|
|
14
|
+
let mounted = false
|
|
15
|
+
let inFlight = false
|
|
16
|
+
let requestId = 0
|
|
17
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
18
|
+
|
|
19
|
+
/** 予約済みの更新を取り消し、必要なら次回の読み取りを予約する。 */
|
|
20
|
+
function schedule() {
|
|
21
|
+
clearTimeout(timer)
|
|
22
|
+
if (mounted && !inFlight && !document.hidden && hasActiveExecutions()) {
|
|
23
|
+
timer = setTimeout(() => void reload(true), 3000)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 最新のリクエストだけが表示を更新できるようにする。 */
|
|
28
|
+
async function reload(background = false) {
|
|
29
|
+
if (!mounted || (background && (inFlight || document.hidden))) return
|
|
30
|
+
const id = ++requestId
|
|
31
|
+
const isCurrent = () => mounted && id === requestId
|
|
32
|
+
inFlight = true
|
|
33
|
+
schedule()
|
|
34
|
+
try {
|
|
35
|
+
await read(background, isCurrent)
|
|
36
|
+
} finally {
|
|
37
|
+
if (isCurrent()) {
|
|
38
|
+
inFlight = false
|
|
39
|
+
schedule()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** タブに戻ったら、次の更新時刻を待たずに最新の状態を取得する。 */
|
|
45
|
+
function onVisibilityChange() {
|
|
46
|
+
if (document.hidden) schedule()
|
|
47
|
+
else void reload(true)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (enabled) {
|
|
51
|
+
watch(hasActiveExecutions, schedule)
|
|
52
|
+
onMounted(() => {
|
|
53
|
+
mounted = true
|
|
54
|
+
document.addEventListener('visibilitychange', onVisibilityChange)
|
|
55
|
+
void reload()
|
|
56
|
+
})
|
|
57
|
+
onUnmounted(() => {
|
|
58
|
+
mounted = false
|
|
59
|
+
clearTimeout(timer)
|
|
60
|
+
document.removeEventListener('visibilitychange', onVisibilityChange)
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Vue のクリックイベントを自動更新フラグとして受け取らない。
|
|
65
|
+
return () => reload()
|
|
66
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import type { Auth } from 'firebase/auth'
|
|
2
|
+
import type { FirebaseApp } from 'firebase/app'
|
|
3
|
+
import { getCookie } from 'h3'
|
|
4
|
+
import {
|
|
5
|
+
DECODED_ID_TOKEN_SYMBOL,
|
|
6
|
+
UserSymbol,
|
|
7
|
+
} from 'nuxt-vuefire/runtime/constants.js'
|
|
8
|
+
import { useNuxtApp, useRuntimeConfig, useRequestEvent } from 'nuxt/app'
|
|
9
|
+
|
|
10
|
+
export type VuefireStepStatus = 'ok' | 'skip' | 'fail' | 'unknown'
|
|
11
|
+
|
|
12
|
+
export interface VuefirePipelineStep {
|
|
13
|
+
id: string
|
|
14
|
+
plugin: string
|
|
15
|
+
status: VuefireStepStatus
|
|
16
|
+
detail: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface VuefirePipelineSnapshot {
|
|
20
|
+
side: 'server' | 'client'
|
|
21
|
+
steps: VuefirePipelineStep[]
|
|
22
|
+
summary: {
|
|
23
|
+
ok: number
|
|
24
|
+
fail: number
|
|
25
|
+
skip: number
|
|
26
|
+
unknown: number
|
|
27
|
+
}
|
|
28
|
+
raw: Record<string, unknown>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* nuxt-vuefire のプラグイン連鎖がどこまで進んだかを検査する(デバッグ用)
|
|
33
|
+
*
|
|
34
|
+
* SSR 想定の実行順(概略):
|
|
35
|
+
* 1. admin/plugin.server
|
|
36
|
+
* 2. auth/plugin-user-token.server(__session → decodedToken)
|
|
37
|
+
* 3. app/plugin.server($firebaseApp)
|
|
38
|
+
* 4. auth/plugin.server($firebaseAuth)
|
|
39
|
+
* 5. emulators/*.plugin
|
|
40
|
+
* 6. auth/plugin-authenticate-user.server(customToken / vuefireUser)
|
|
41
|
+
*/
|
|
42
|
+
export function inspectNuxtVuefirePipeline(): VuefirePipelineSnapshot {
|
|
43
|
+
const side = import.meta.server ? 'server' : 'client'
|
|
44
|
+
const nuxtApp = useNuxtApp()
|
|
45
|
+
const runtimeConfig = useRuntimeConfig()
|
|
46
|
+
const publicVuefire = (runtimeConfig.public.vuefire ?? {}) as {
|
|
47
|
+
config?: Record<string, string>
|
|
48
|
+
emulators?: Record<string, { host?: string; port?: number }>
|
|
49
|
+
auth?: { enabled?: boolean; sessionCookie?: boolean | object }
|
|
50
|
+
}
|
|
51
|
+
const privateVuefire = (runtimeConfig.vuefire ?? {}) as {
|
|
52
|
+
admin?: unknown
|
|
53
|
+
auth?: { enabled?: boolean; sessionCookie?: boolean | object }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const firebaseAdminApp = nuxtApp.$firebaseAdminApp as FirebaseApp | undefined
|
|
57
|
+
const firebaseApp = nuxtApp.$firebaseApp as FirebaseApp | undefined
|
|
58
|
+
const firebaseAuth = nuxtApp.$firebaseAuth as Auth | undefined
|
|
59
|
+
|
|
60
|
+
const decodedToken = (nuxtApp as unknown as Record<PropertyKey, unknown>)[
|
|
61
|
+
DECODED_ID_TOKEN_SYMBOL
|
|
62
|
+
] as { uid?: string; email?: string } | null | undefined
|
|
63
|
+
|
|
64
|
+
const userFromSymbol = (nuxtApp as unknown as Record<PropertyKey, unknown>)[UserSymbol] as
|
|
65
|
+
| { uid?: string }
|
|
66
|
+
| null
|
|
67
|
+
| undefined
|
|
68
|
+
|
|
69
|
+
const payloadUser = (nuxtApp.payload?.vuefireUser as { uid?: string } | null | undefined) ?? null
|
|
70
|
+
|
|
71
|
+
let sessionCookiePresent: boolean | null = null
|
|
72
|
+
if (import.meta.server) {
|
|
73
|
+
try {
|
|
74
|
+
const event = useRequestEvent()
|
|
75
|
+
sessionCookiePresent = event ? Boolean(getCookie(event, '__session')) : null
|
|
76
|
+
} catch {
|
|
77
|
+
sessionCookiePresent = null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const authEnabled =
|
|
82
|
+
publicVuefire.auth?.enabled ?? privateVuefire.auth?.enabled ?? true
|
|
83
|
+
const sessionCookieEnabled = Boolean(
|
|
84
|
+
publicVuefire.auth?.sessionCookie ?? privateVuefire.auth?.sessionCookie,
|
|
85
|
+
)
|
|
86
|
+
const emulators = publicVuefire.emulators ?? null
|
|
87
|
+
const config = publicVuefire.config ?? null
|
|
88
|
+
|
|
89
|
+
const steps: VuefirePipelineStep[] = []
|
|
90
|
+
|
|
91
|
+
// 0. module config
|
|
92
|
+
steps.push({
|
|
93
|
+
id: 'module-config',
|
|
94
|
+
plugin: 'nuxt-vuefire (module options → runtimeConfig)',
|
|
95
|
+
status: config?.projectId ? 'ok' : 'fail',
|
|
96
|
+
detail: config
|
|
97
|
+
? `projectId=${config.projectId}, authDomain=${config.authDomain ?? '?'}`
|
|
98
|
+
: 'public.vuefire.config が無い',
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
steps.push({
|
|
102
|
+
id: 'auth-enabled',
|
|
103
|
+
plugin: 'vuefire.auth.enabled',
|
|
104
|
+
status: authEnabled ? 'ok' : 'skip',
|
|
105
|
+
detail: `enabled=${authEnabled}`,
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
steps.push({
|
|
109
|
+
id: 'session-cookie-option',
|
|
110
|
+
plugin: 'vuefire.auth.sessionCookie',
|
|
111
|
+
status: sessionCookieEnabled ? 'ok' : 'skip',
|
|
112
|
+
detail: `sessionCookie=${sessionCookieEnabled}`,
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// 1. admin
|
|
116
|
+
steps.push({
|
|
117
|
+
id: 'admin-app',
|
|
118
|
+
plugin: 'admin/plugin.server → $firebaseAdminApp',
|
|
119
|
+
status: import.meta.server
|
|
120
|
+
? firebaseAdminApp
|
|
121
|
+
? 'ok'
|
|
122
|
+
: 'fail'
|
|
123
|
+
: 'skip',
|
|
124
|
+
detail: import.meta.server
|
|
125
|
+
? firebaseAdminApp
|
|
126
|
+
? `name=${(firebaseAdminApp as { name?: string }).name ?? 'admin'}`
|
|
127
|
+
: 'Admin App 未提供(GOOGLE_APPLICATION_CREDENTIALS / emulators 要確認)'
|
|
128
|
+
: 'client では対象外',
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
// 2. user-token (session decode)
|
|
132
|
+
steps.push({
|
|
133
|
+
id: 'session-cookie-present',
|
|
134
|
+
plugin: 'Cookie __session',
|
|
135
|
+
status: import.meta.server
|
|
136
|
+
? sessionCookiePresent
|
|
137
|
+
? 'ok'
|
|
138
|
+
: 'skip'
|
|
139
|
+
: 'unknown',
|
|
140
|
+
detail: import.meta.server
|
|
141
|
+
? sessionCookiePresent
|
|
142
|
+
? '__session Cookie あり'
|
|
143
|
+
: '__session Cookie なし(未ログイン or mint 前)'
|
|
144
|
+
: 'SSR でのみ判定',
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
steps.push({
|
|
148
|
+
id: 'decoded-id-token',
|
|
149
|
+
plugin: 'auth/plugin-user-token.server → DECODED_ID_TOKEN',
|
|
150
|
+
status: import.meta.server
|
|
151
|
+
? !sessionCookieEnabled
|
|
152
|
+
? 'skip'
|
|
153
|
+
: decodedToken?.uid
|
|
154
|
+
? 'ok'
|
|
155
|
+
: sessionCookiePresent
|
|
156
|
+
? 'fail'
|
|
157
|
+
: 'skip'
|
|
158
|
+
: 'skip',
|
|
159
|
+
detail: import.meta.server
|
|
160
|
+
? decodedToken?.uid
|
|
161
|
+
? `uid=${decodedToken.uid}, email=${decodedToken.email ?? '?'}`
|
|
162
|
+
: sessionCookiePresent
|
|
163
|
+
? 'Cookie はあるが decode 失敗(SA / revoke 要確認)'
|
|
164
|
+
: 'decode 対象なし'
|
|
165
|
+
: 'client では対象外',
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
// 3. app
|
|
169
|
+
steps.push({
|
|
170
|
+
id: 'firebase-app',
|
|
171
|
+
plugin: 'app/plugin.server|client → $firebaseApp',
|
|
172
|
+
status: firebaseApp ? 'ok' : 'fail',
|
|
173
|
+
detail: firebaseApp
|
|
174
|
+
? `name=${firebaseApp.name}, projectId=${firebaseApp.options.projectId ?? '?'}`
|
|
175
|
+
: '$firebaseApp 未提供',
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
// 4. auth
|
|
179
|
+
steps.push({
|
|
180
|
+
id: 'firebase-auth',
|
|
181
|
+
plugin: 'auth/plugin.server|client → $firebaseAuth',
|
|
182
|
+
status: !authEnabled ? 'skip' : firebaseAuth ? 'ok' : 'fail',
|
|
183
|
+
detail: firebaseAuth
|
|
184
|
+
? `appName=${firebaseAuth.app.name}, currentUser=${firebaseAuth.currentUser?.uid ?? 'null'}`
|
|
185
|
+
: authEnabled
|
|
186
|
+
? '$firebaseAuth 未提供'
|
|
187
|
+
: 'auth disabled',
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
// 5. emulators
|
|
191
|
+
const emulatorNames = emulators ? Object.keys(emulators) : []
|
|
192
|
+
steps.push({
|
|
193
|
+
id: 'emulators-config',
|
|
194
|
+
plugin: 'emulators/*.plugin(runtimeConfig.public.vuefire.emulators)',
|
|
195
|
+
status: emulatorNames.length > 0 ? 'ok' : 'skip',
|
|
196
|
+
detail:
|
|
197
|
+
emulatorNames.length > 0
|
|
198
|
+
? emulatorNames
|
|
199
|
+
.map(name => {
|
|
200
|
+
const e = emulators![name]
|
|
201
|
+
return `${name}=${e?.host}:${e?.port}`
|
|
202
|
+
})
|
|
203
|
+
.join(', ')
|
|
204
|
+
: 'emulators 未検出(起動時に hub :4400 が生きていないと無効)',
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
steps.push({
|
|
208
|
+
id: 'emulator-env',
|
|
209
|
+
plugin: 'process.env FIREBASE_*_EMULATOR_HOST',
|
|
210
|
+
status: import.meta.server
|
|
211
|
+
? process.env.FIREBASE_AUTH_EMULATOR_HOST || process.env.FIRESTORE_EMULATOR_HOST
|
|
212
|
+
? 'ok'
|
|
213
|
+
: emulatorNames.length > 0
|
|
214
|
+
? 'fail'
|
|
215
|
+
: 'skip'
|
|
216
|
+
: 'unknown',
|
|
217
|
+
detail: import.meta.server
|
|
218
|
+
? [
|
|
219
|
+
`AUTH=${process.env.FIREBASE_AUTH_EMULATOR_HOST ?? '-'}`,
|
|
220
|
+
`FIRESTORE=${process.env.FIRESTORE_EMULATOR_HOST ?? '-'}`,
|
|
221
|
+
`STORAGE=${process.env.FIREBASE_STORAGE_EMULATOR_HOST ?? '-'}`,
|
|
222
|
+
].join(', ')
|
|
223
|
+
: 'SSR でのみ判定',
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
// 6. authenticate-user
|
|
227
|
+
steps.push({
|
|
228
|
+
id: 'authenticate-user',
|
|
229
|
+
plugin: 'auth/plugin-authenticate-user.server → vuefireUser / customToken',
|
|
230
|
+
status: import.meta.server
|
|
231
|
+
? !authEnabled
|
|
232
|
+
? 'skip'
|
|
233
|
+
: payloadUser?.uid || firebaseAuth?.currentUser?.uid
|
|
234
|
+
? 'ok'
|
|
235
|
+
: decodedToken?.uid
|
|
236
|
+
? 'fail'
|
|
237
|
+
: 'skip'
|
|
238
|
+
: 'skip',
|
|
239
|
+
detail: import.meta.server
|
|
240
|
+
? [
|
|
241
|
+
`payload.vuefireUser=${payloadUser?.uid ?? 'null'}`,
|
|
242
|
+
`UserSymbol=${userFromSymbol?.uid ?? 'null'}`,
|
|
243
|
+
`auth.currentUser=${firebaseAuth?.currentUser?.uid ?? 'null'}`,
|
|
244
|
+
].join(', ')
|
|
245
|
+
: 'client では対象外(client は auth plugin + mint-cookie)',
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
// client-only hints
|
|
249
|
+
steps.push({
|
|
250
|
+
id: 'mint-cookie-client',
|
|
251
|
+
plugin: 'auth/plugin-mint-cookie.client',
|
|
252
|
+
status: import.meta.client
|
|
253
|
+
? sessionCookieEnabled
|
|
254
|
+
? 'unknown'
|
|
255
|
+
: 'skip'
|
|
256
|
+
: 'skip',
|
|
257
|
+
detail: import.meta.client
|
|
258
|
+
? sessionCookieEnabled
|
|
259
|
+
? 'クライアントで onIdTokenChanged → POST /api/__session(実行有無はネットワークで確認)'
|
|
260
|
+
: 'sessionCookie 無効のためスキップ'
|
|
261
|
+
: 'SSR では未実行',
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
const summary = {
|
|
265
|
+
ok: steps.filter(s => s.status === 'ok').length,
|
|
266
|
+
fail: steps.filter(s => s.status === 'fail').length,
|
|
267
|
+
skip: steps.filter(s => s.status === 'skip').length,
|
|
268
|
+
unknown: steps.filter(s => s.status === 'unknown').length,
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
side,
|
|
273
|
+
steps,
|
|
274
|
+
summary,
|
|
275
|
+
raw: {
|
|
276
|
+
authEnabled,
|
|
277
|
+
sessionCookieEnabled,
|
|
278
|
+
sessionCookiePresent,
|
|
279
|
+
decodedUid: decodedToken?.uid ?? null,
|
|
280
|
+
payloadVuefireUser: payloadUser,
|
|
281
|
+
userSymbolUid: userFromSymbol?.uid ?? null,
|
|
282
|
+
firebaseAppName: firebaseApp?.name ?? null,
|
|
283
|
+
authCurrentUserUid: firebaseAuth?.currentUser?.uid ?? null,
|
|
284
|
+
emulators,
|
|
285
|
+
configProjectId: config?.projectId ?? null,
|
|
286
|
+
},
|
|
287
|
+
}
|
|
288
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useRuntimeConfig } from 'nuxt/app'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* デバッグ UI / 記録が有効かどうか。
|
|
5
|
+
* 開発ビルドかつ `runtimeConfig.public.enableDebug !== false` のときのみ true。
|
|
6
|
+
*/
|
|
7
|
+
export function isBakusokuDebugEnabled(
|
|
8
|
+
config?: { public?: { enableDebug?: boolean } },
|
|
9
|
+
): boolean {
|
|
10
|
+
const enableDebug
|
|
11
|
+
= config?.public?.enableDebug ?? useRuntimeConfig().public.enableDebug
|
|
12
|
+
return import.meta.dev && enableDebug !== false
|
|
13
|
+
}
|