@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,235 @@
|
|
|
1
|
+
import { useRuntimeConfig } from 'nuxt/app'
|
|
2
|
+
import { isBakusokuDebugEnabled } from './is-debug-enabled'
|
|
3
|
+
import { maskSecrets } from './mask-secrets'
|
|
4
|
+
import { useBakusokuDebugStore, type DebugLogLevel } from '../stores/debug'
|
|
5
|
+
|
|
6
|
+
export type BakusokuLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
7
|
+
|
|
8
|
+
const LEVEL_WEIGHTS: Record<BakusokuLogLevel, number> = {
|
|
9
|
+
debug: 10,
|
|
10
|
+
info: 20,
|
|
11
|
+
warn: 30,
|
|
12
|
+
error: 40,
|
|
13
|
+
silent: 50,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const CLOUD_LOGGING_SEVERITY: Record<DebugLogLevel, string> = {
|
|
17
|
+
debug: 'DEBUG',
|
|
18
|
+
info: 'INFO',
|
|
19
|
+
warn: 'WARNING',
|
|
20
|
+
error: 'ERROR',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface BakusokuLoggerOptions {
|
|
24
|
+
tag?: string
|
|
25
|
+
level?: BakusokuLogLevel
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface BakusokuLogger {
|
|
29
|
+
debug(message: string, data?: unknown): void
|
|
30
|
+
info(message: string, data?: unknown): void
|
|
31
|
+
warn(message: string, data?: unknown): void
|
|
32
|
+
error(message: string, errorOrData?: unknown, data?: unknown): void
|
|
33
|
+
withTag(tag: string): BakusokuLogger
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 設定を参照して出力対象となる最低ログレベルを決める。 */
|
|
37
|
+
function resolveThresholdLevel(): BakusokuLogLevel {
|
|
38
|
+
try {
|
|
39
|
+
const config = typeof useRuntimeConfig === 'function' ? useRuntimeConfig() : undefined
|
|
40
|
+
if (import.meta.client) {
|
|
41
|
+
if (config?.public?.logLevel) {
|
|
42
|
+
return config.public.logLevel as BakusokuLogLevel
|
|
43
|
+
}
|
|
44
|
+
return isBakusokuDebugEnabled(config) ? 'debug' : 'warn'
|
|
45
|
+
}
|
|
46
|
+
if (config?.logLevel) {
|
|
47
|
+
return config.logLevel as BakusokuLogLevel
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
// Nuxt context 外(ユニットテスト等)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
54
|
+
if (process.env.LOG_LEVEL) {
|
|
55
|
+
return process.env.LOG_LEVEL as BakusokuLogLevel
|
|
56
|
+
}
|
|
57
|
+
if (process.env.NODE_ENV === 'production') {
|
|
58
|
+
return import.meta.client ? 'warn' : 'info'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return 'debug'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** ログの引数から例外情報と付加データを取り出す。 */
|
|
66
|
+
function extractErrorAndData(
|
|
67
|
+
errorOrData?: unknown,
|
|
68
|
+
data?: unknown,
|
|
69
|
+
): { errorObj?: Error | Record<string, unknown>; metaData?: unknown } {
|
|
70
|
+
if (errorOrData === undefined) {
|
|
71
|
+
return { errorObj: undefined, metaData: data }
|
|
72
|
+
}
|
|
73
|
+
if (errorOrData instanceof Error) {
|
|
74
|
+
return { errorObj: errorOrData, metaData: data }
|
|
75
|
+
}
|
|
76
|
+
if (
|
|
77
|
+
errorOrData
|
|
78
|
+
&& typeof errorOrData === 'object'
|
|
79
|
+
&& ('message' in errorOrData || 'stack' in errorOrData || 'code' in errorOrData)
|
|
80
|
+
) {
|
|
81
|
+
return { errorObj: errorOrData as Record<string, unknown>, metaData: data }
|
|
82
|
+
}
|
|
83
|
+
return { errorObj: undefined, metaData: errorOrData }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** レベル判定と実行環境ごとの出力処理を備えたロガーを作る。 */
|
|
87
|
+
export function createBakusokuLogger(options: BakusokuLoggerOptions = {}): BakusokuLogger {
|
|
88
|
+
const tag = options.tag
|
|
89
|
+
|
|
90
|
+
/** 指定レベルのログが現在の出力条件を満たすか判定する。 */
|
|
91
|
+
function shouldLog(level: BakusokuLogLevel): boolean {
|
|
92
|
+
const threshold = options.level ?? resolveThresholdLevel()
|
|
93
|
+
return LEVEL_WEIGHTS[level] >= LEVEL_WEIGHTS[threshold]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** ログをサーバー側の出力形式に整えて記録する。 */
|
|
97
|
+
function emitServer(
|
|
98
|
+
level: DebugLogLevel,
|
|
99
|
+
message: string,
|
|
100
|
+
maskedData?: unknown,
|
|
101
|
+
errorObj?: Error | Record<string, unknown>,
|
|
102
|
+
) {
|
|
103
|
+
const isProd = typeof process !== 'undefined' && process.env?.NODE_ENV === 'production'
|
|
104
|
+
|
|
105
|
+
if (isProd) {
|
|
106
|
+
// Cloud Logging 構造化 JSON
|
|
107
|
+
const entry: Record<string, unknown> = {
|
|
108
|
+
severity: CLOUD_LOGGING_SEVERITY[level],
|
|
109
|
+
message: tag ? `[${tag}] ${message}` : message,
|
|
110
|
+
timestamp: new Date().toISOString(),
|
|
111
|
+
}
|
|
112
|
+
if (tag) entry.tag = tag
|
|
113
|
+
if (maskedData !== undefined) entry.data = maskedData
|
|
114
|
+
if (errorObj) {
|
|
115
|
+
entry.error = {
|
|
116
|
+
name: (errorObj as Error).name || 'Error',
|
|
117
|
+
message: (errorObj as Error).message || String(errorObj),
|
|
118
|
+
stack: (errorObj as Error).stack,
|
|
119
|
+
code: (errorObj as { code?: string }).code,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const line = JSON.stringify(entry)
|
|
123
|
+
if (level === 'error') {
|
|
124
|
+
console.error(line)
|
|
125
|
+
} else if (level === 'warn') {
|
|
126
|
+
console.warn(line)
|
|
127
|
+
} else {
|
|
128
|
+
console.log(line)
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
// 開発環境: 読みやすいコンソール出力
|
|
132
|
+
const time = new Date().toISOString().split('T')[1]?.slice(0, 8) || ''
|
|
133
|
+
const prefix = `[${time}] [${level.toUpperCase()}]${tag ? ` [${tag}]` : ''} ${message}`
|
|
134
|
+
const args: unknown[] = [prefix]
|
|
135
|
+
if (maskedData !== undefined) args.push(maskedData)
|
|
136
|
+
if (errorObj) args.push(errorObj)
|
|
137
|
+
|
|
138
|
+
if (level === 'error') {
|
|
139
|
+
console.error(...args)
|
|
140
|
+
} else if (level === 'warn') {
|
|
141
|
+
console.warn(...args)
|
|
142
|
+
} else if (level === 'info') {
|
|
143
|
+
console.info(...args)
|
|
144
|
+
} else {
|
|
145
|
+
console.debug(...args)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** ログをブラウザーに出力し、デバッグ表示に必要な情報も記録する。 */
|
|
151
|
+
function emitClient(
|
|
152
|
+
level: DebugLogLevel,
|
|
153
|
+
message: string,
|
|
154
|
+
maskedData?: unknown,
|
|
155
|
+
errorObj?: Error | Record<string, unknown>,
|
|
156
|
+
) {
|
|
157
|
+
const prefix = tag ? `[${tag}] ${message}` : message
|
|
158
|
+
const args: unknown[] = [prefix]
|
|
159
|
+
if (maskedData !== undefined) args.push(maskedData)
|
|
160
|
+
if (errorObj) args.push(errorObj)
|
|
161
|
+
|
|
162
|
+
if (level === 'error') {
|
|
163
|
+
console.error(...args)
|
|
164
|
+
} else if (level === 'warn') {
|
|
165
|
+
console.warn(...args)
|
|
166
|
+
} else if (level === 'info') {
|
|
167
|
+
console.info(...args)
|
|
168
|
+
} else {
|
|
169
|
+
console.debug(...args)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// デバッグ画面・DevTools 連携
|
|
173
|
+
try {
|
|
174
|
+
if (isBakusokuDebugEnabled()) {
|
|
175
|
+
const debugStore = useBakusokuDebugStore()
|
|
176
|
+
debugStore.recordLog({
|
|
177
|
+
level,
|
|
178
|
+
tag,
|
|
179
|
+
message,
|
|
180
|
+
data: maskedData,
|
|
181
|
+
error: errorObj ? (errorObj as Error).message || String(errorObj) : undefined,
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
} catch {
|
|
185
|
+
// Pinia / Nuxt 初期化前など
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** ログレベルを確認し、メッセージと付加情報を出力する。 */
|
|
190
|
+
function log(
|
|
191
|
+
level: DebugLogLevel,
|
|
192
|
+
message: string,
|
|
193
|
+
errorOrData?: unknown,
|
|
194
|
+
data?: unknown,
|
|
195
|
+
) {
|
|
196
|
+
if (!shouldLog(level)) return
|
|
197
|
+
|
|
198
|
+
const { errorObj, metaData } = extractErrorAndData(errorOrData, data)
|
|
199
|
+
const maskedData = metaData !== undefined ? maskSecrets(metaData) : undefined
|
|
200
|
+
|
|
201
|
+
if (import.meta.server || (typeof window === 'undefined' && typeof process !== 'undefined')) {
|
|
202
|
+
emitServer(level, message, maskedData, errorObj)
|
|
203
|
+
} else {
|
|
204
|
+
emitClient(level, message, maskedData, errorObj)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
/** デバッグ情報を記録する。 */
|
|
210
|
+
debug(message: string, data?: unknown) {
|
|
211
|
+
log('debug', message, undefined, data)
|
|
212
|
+
},
|
|
213
|
+
/** 通常の実行情報を記録する。 */
|
|
214
|
+
info(message: string, data?: unknown) {
|
|
215
|
+
log('info', message, undefined, data)
|
|
216
|
+
},
|
|
217
|
+
/** 注意が必要な状態を記録する。 */
|
|
218
|
+
warn(message: string, data?: unknown) {
|
|
219
|
+
log('warn', message, undefined, data)
|
|
220
|
+
},
|
|
221
|
+
/** エラーメッセージと、指定された例外や関連情報を記録する。 */
|
|
222
|
+
error(message: string, errorOrData?: unknown, data?: unknown) {
|
|
223
|
+
log('error', message, errorOrData, data)
|
|
224
|
+
},
|
|
225
|
+
/** 指定したタグで出力するロガーを作る。 */
|
|
226
|
+
withTag(newTag: string) {
|
|
227
|
+
return createBakusokuLogger({ ...options, tag: newTag })
|
|
228
|
+
},
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** 指定したタグを使うアプリ共通のロガーを取得する。 */
|
|
233
|
+
export function useBakusokuLogger(tag?: string): BakusokuLogger {
|
|
234
|
+
return createBakusokuLogger({ tag })
|
|
235
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Auth エラーコードをユーザー向けメッセージに変換
|
|
3
|
+
*/
|
|
4
|
+
export function mapAuthError(
|
|
5
|
+
err: { code?: string; message?: string },
|
|
6
|
+
defaultMessage: string,
|
|
7
|
+
map: Record<string, string>
|
|
8
|
+
): string {
|
|
9
|
+
const code = err?.code
|
|
10
|
+
return (code && map[code]) || err?.message || defaultMessage
|
|
11
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* デバッグ表示用に機密っぽいキーの値をマスクする。
|
|
3
|
+
* Authorization / password / token などを対象にする。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const SENSITIVE_KEY_PATTERN =
|
|
7
|
+
/password|passwd|secret|token|authorization|api[_-]?key|credential|private[_-]?key|cookie|session|refresh/i
|
|
8
|
+
|
|
9
|
+
const MAX_DEPTH = 8
|
|
10
|
+
const MAX_STRING_LENGTH = 4000
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* キー名が機密情報を示すかどうか
|
|
14
|
+
*/
|
|
15
|
+
export function isSensitiveKey(key: string): boolean {
|
|
16
|
+
return SENSITIVE_KEY_PATTERN.test(key)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* オブジェクト / 配列内の機密値を `***` に置換する。
|
|
21
|
+
* 文字列はそのまま(長さ上限あり)。パース可能な JSON 文字列はオブジェクトとして扱う。
|
|
22
|
+
*/
|
|
23
|
+
export function maskSecrets(value: unknown, depth = 0): unknown {
|
|
24
|
+
if (depth > MAX_DEPTH) {
|
|
25
|
+
return '[MaxDepth]'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (value == null) {
|
|
29
|
+
return value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof value === 'string') {
|
|
33
|
+
if (value.length > MAX_STRING_LENGTH) {
|
|
34
|
+
return `${value.slice(0, MAX_STRING_LENGTH)}…`
|
|
35
|
+
}
|
|
36
|
+
const trimmed = value.trim()
|
|
37
|
+
if (
|
|
38
|
+
(trimmed.startsWith('{') && trimmed.endsWith('}'))
|
|
39
|
+
|| (trimmed.startsWith('[') && trimmed.endsWith(']'))
|
|
40
|
+
) {
|
|
41
|
+
try {
|
|
42
|
+
return maskSecrets(JSON.parse(trimmed), depth + 1)
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return value
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return value
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof value !== 'object') {
|
|
52
|
+
return value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
return value.map(item => maskSecrets(item, depth + 1))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const out: Record<string, unknown> = {}
|
|
60
|
+
for (const [key, child] of Object.entries(value as Record<string, unknown>)) {
|
|
61
|
+
if (isSensitiveKey(key)) {
|
|
62
|
+
out[key] = child == null || child === '' ? child : '***'
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
out[key] = maskSecrets(child, depth + 1)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* ofetch / $fetch の body をデバッグ表示用に正規化してマスクする。
|
|
73
|
+
*/
|
|
74
|
+
export function serializeDebugBody(body: unknown): unknown {
|
|
75
|
+
if (body == null || body === false) {
|
|
76
|
+
return undefined
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (typeof FormData !== 'undefined' && body instanceof FormData) {
|
|
80
|
+
const obj: Record<string, unknown> = {}
|
|
81
|
+
body.forEach((entry, key) => {
|
|
82
|
+
obj[key] = typeof entry === 'string' ? entry : `[Blob:${entry.name || 'file'}]`
|
|
83
|
+
})
|
|
84
|
+
return maskSecrets(obj)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams) {
|
|
88
|
+
const obj: Record<string, unknown> = {}
|
|
89
|
+
body.forEach((entry, key) => {
|
|
90
|
+
obj[key] = entry
|
|
91
|
+
})
|
|
92
|
+
return maskSecrets(obj)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (typeof Blob !== 'undefined' && body instanceof Blob) {
|
|
96
|
+
return `[Blob:${body.type || 'unknown'};${body.size}b]`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return maskSecrets(body)
|
|
100
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Auth } from 'firebase/auth'
|
|
2
|
+
import type { FirebaseApp } from 'firebase/app'
|
|
3
|
+
import { getCurrentUser } from 'vuefire'
|
|
4
|
+
import { useNuxtApp } from 'nuxt/app'
|
|
5
|
+
|
|
6
|
+
export type ResolvedAuthUser = { uid: string }
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Firebase Auth の現在ユーザー uid を解決する。
|
|
10
|
+
*
|
|
11
|
+
* 優先順:
|
|
12
|
+
* 1. SSR: `payload.vuefireUser`(sessionCookie → authenticate-user 済み)
|
|
13
|
+
* 2. `$firebaseAuth.authStateReady()` 後の `currentUser`
|
|
14
|
+
* 3. `getCurrentUser(appName)`(`$firebaseApp.name`)
|
|
15
|
+
*/
|
|
16
|
+
export async function resolveAuthUser(
|
|
17
|
+
nuxtApp: ReturnType<typeof useNuxtApp> = useNuxtApp(),
|
|
18
|
+
firebaseAuth: Auth | undefined = nuxtApp.$firebaseAuth as Auth | undefined,
|
|
19
|
+
): Promise<ResolvedAuthUser | null> {
|
|
20
|
+
const side = import.meta.server ? 'server' : 'client'
|
|
21
|
+
|
|
22
|
+
// 1) SSR: cookie → signIn 済みのペイロード
|
|
23
|
+
if (import.meta.server) {
|
|
24
|
+
const fromPayload = nuxtApp.payload?.vuefireUser as { uid?: string } | null | undefined
|
|
25
|
+
if (fromPayload?.uid) {
|
|
26
|
+
return { uid: fromPayload.uid }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 2) Auth SDK の currentUser
|
|
31
|
+
if (firebaseAuth) {
|
|
32
|
+
await firebaseAuth.authStateReady()
|
|
33
|
+
if (firebaseAuth.currentUser?.uid) {
|
|
34
|
+
return { uid: firebaseAuth.currentUser.uid }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 3) VueFire getCurrentUser(アプリ名は $firebaseApp)
|
|
39
|
+
// payload にユーザーがあるときだけ呼ぶ(不要な待ち・ハングを避ける)
|
|
40
|
+
try {
|
|
41
|
+
const app = nuxtApp.$firebaseApp as FirebaseApp | undefined
|
|
42
|
+
const appName = app?.name
|
|
43
|
+
const payloadUser = nuxtApp.payload?.vuefireUser as { uid?: string } | null | undefined
|
|
44
|
+
if (appName && payloadUser) {
|
|
45
|
+
const fromVueFire = await getCurrentUser(appName)
|
|
46
|
+
if (fromVueFire?.uid) return { uid: fromVueFire.uid }
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
useBakusokuLogger('auth').warn(`getCurrentUser failed (${side})`, error)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FirebaseApp } from 'firebase/app'
|
|
2
|
+
import { getFirestore } from 'firebase/firestore'
|
|
3
|
+
import type { Firestore } from 'firebase/firestore'
|
|
4
|
+
import { useNuxtApp } from 'nuxt/app'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* nuxt-vuefire の `$firebaseApp` から Firestore を取得する。
|
|
8
|
+
*
|
|
9
|
+
* Pinia / middleware では `getCurrentInstance()` が無いことがあり、
|
|
10
|
+
* `useFirebaseApp()` → `getApp()` が `[DEFAULT]` を探して `app/no-app` になる。
|
|
11
|
+
* sessionCookie 成功時の SSR App 名は `auth:{uid}:...` のため `$firebaseApp` を使う。
|
|
12
|
+
*/
|
|
13
|
+
export function resolveFirestore(): Firestore | null {
|
|
14
|
+
const app = useNuxtApp().$firebaseApp as FirebaseApp | undefined
|
|
15
|
+
if (!app) {
|
|
16
|
+
useBakusokuLogger('firestore').warn('$firebaseApp missing')
|
|
17
|
+
return null
|
|
18
|
+
}
|
|
19
|
+
return getFirestore(app)
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type TaskRunField = {
|
|
2
|
+
key: string
|
|
3
|
+
label: string
|
|
4
|
+
type: 'text' | 'select' | 'user'
|
|
5
|
+
required: boolean
|
|
6
|
+
placeholder: string
|
|
7
|
+
options: { value: string, label: string }[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type TaskRunTarget = {
|
|
11
|
+
id: string
|
|
12
|
+
name: string
|
|
13
|
+
description: string
|
|
14
|
+
fields: TaskRunField[]
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs'
|
|
2
|
+
import { useNuxt } from '@nuxt/kit'
|
|
3
|
+
|
|
4
|
+
/** Include VueFire's Admin plugins in SSR builds; runtime uses Cloud Run ADC. */
|
|
5
|
+
// `modules:before` is invoked with no arguments. Take the instance from context.
|
|
6
|
+
export function prepareBuildCredentials(nuxt = useNuxt()) {
|
|
7
|
+
if (nuxt.options.dev || !nuxt.options.ssr || nuxt.options._generate
|
|
8
|
+
|| process.env.GOOGLE_APPLICATION_CREDENTIALS !== undefined) {
|
|
9
|
+
return
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const credentials = '/tmp/dummy.json'
|
|
13
|
+
try {
|
|
14
|
+
writeFileSync(credentials, '{}\n', { flag: 'wx' })
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error.code !== 'EEXIST') throw error
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
process.env.GOOGLE_APPLICATION_CREDENTIALS = credentials
|
|
21
|
+
console.info('[@enlt-bakusoku/nuxt4] GOOGLE_APPLICATION_CREDENTIALS が未設定のため、ビルドに /tmp/dummy.json を使用します。')
|
|
22
|
+
|
|
23
|
+
/** ビルド用の仮の認証情報を指している環境変数を解除する。 */
|
|
24
|
+
const restore = () => {
|
|
25
|
+
if (process.env.GOOGLE_APPLICATION_CREDENTIALS === credentials) {
|
|
26
|
+
delete process.env.GOOGLE_APPLICATION_CREDENTIALS
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// VueFire only needs the variable while registering its plugins. Clear it
|
|
30
|
+
// before Nitro builds/prerenders, and also when Nuxt closes after an error.
|
|
31
|
+
nuxt.hook('modules:done', restore)
|
|
32
|
+
nuxt.hook('close', restore)
|
|
33
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bakusoku UI Layer
|
|
3
|
+
*
|
|
4
|
+
* app/(components / layouts / stores / plugins / middleware)と
|
|
5
|
+
* server/、VueFire(+ Pinia / Nuxt UI)のデフォルト設定を提供する。
|
|
6
|
+
* #bakusoku/user-schemas は Module 側。
|
|
7
|
+
*
|
|
8
|
+
* 消費側:
|
|
9
|
+
* ```ts
|
|
10
|
+
* export default defineNuxtConfig({
|
|
11
|
+
* extends: ['@enlt-bakusoku/nuxt4/layer'],
|
|
12
|
+
* modules: ['@enlt-bakusoku/nuxt4'],
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
// @ts-nocheck
|
|
17
|
+
import { existsSync } from 'node:fs'
|
|
18
|
+
import { fileURLToPath } from 'node:url'
|
|
19
|
+
import { dirname, join } from 'node:path'
|
|
20
|
+
import { prepareBuildCredentials } from './build-credentials.mjs'
|
|
21
|
+
|
|
22
|
+
const root = dirname(fileURLToPath(import.meta.url))
|
|
23
|
+
|
|
24
|
+
/** 環境変数からタスク機能を有効にするか判定する。 */
|
|
25
|
+
function resolveTasksEnabled() {
|
|
26
|
+
const flag = process.env.NUXT_PUBLIC_TASKS_ENABLED ?? process.env.NUXT_PUBLIC_FUNCTIONS_ENABLED
|
|
27
|
+
if (flag === 'false') return false
|
|
28
|
+
if (flag === 'true') return true
|
|
29
|
+
return existsSync(join(process.cwd(), 'functions', 'package.json'))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default defineNuxtConfig({
|
|
33
|
+
compatibilityDate: '2025-07-15',
|
|
34
|
+
|
|
35
|
+
hooks: {
|
|
36
|
+
'modules:before': prepareBuildCredentials,
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
modules: [
|
|
40
|
+
'@nuxt/ui',
|
|
41
|
+
'nuxt-vuefire',
|
|
42
|
+
'@pinia/nuxt',
|
|
43
|
+
],
|
|
44
|
+
|
|
45
|
+
// Layer の app/stores を各 layer.app 基準でスキャンする。
|
|
46
|
+
// 未指定時は消費側 srcDir の絶対パスになり、Layer 側 stores が拾われない。
|
|
47
|
+
pinia: {
|
|
48
|
+
storesDirs: ['stores'],
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
components: [
|
|
52
|
+
{
|
|
53
|
+
path: join(root, 'app/components'),
|
|
54
|
+
prefix: 'Bksk',
|
|
55
|
+
pathPrefix: false,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
|
|
59
|
+
vuefire: {
|
|
60
|
+
auth: {
|
|
61
|
+
enabled: true,
|
|
62
|
+
sessionCookie: true,
|
|
63
|
+
},
|
|
64
|
+
config: {
|
|
65
|
+
apiKey: process.env.NUXT_PUBLIC_FIREBASE_API_KEY || 'demo-api-key',
|
|
66
|
+
authDomain: process.env.NUXT_PUBLIC_FIREBASE_AUTH_DOMAIN || 'demo-no-project.firebaseapp.com',
|
|
67
|
+
projectId: process.env.NUXT_PUBLIC_FIREBASE_PROJECT_ID || 'demo-no-project',
|
|
68
|
+
storageBucket: process.env.NUXT_PUBLIC_FIREBASE_STORAGE_BUCKET || 'demo-no-project.firebasestorage.app',
|
|
69
|
+
appId: process.env.NUXT_PUBLIC_FIREBASE_APP_ID || 'demo-app-id',
|
|
70
|
+
measurementId: process.env.NUXT_PUBLIC_FIREBASE_MEASUREMENT_ID || 'demo-measurement-id',
|
|
71
|
+
},
|
|
72
|
+
emulators: {
|
|
73
|
+
enabled: process.env.NODE_ENV === 'development',
|
|
74
|
+
host: 'localhost',
|
|
75
|
+
auth: { options: { disableWarnings: true } },
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
runtimeConfig: {
|
|
80
|
+
logLevel: process.env.LOG_LEVEL || (process.env.NODE_ENV === 'production' ? 'info' : 'debug'),
|
|
81
|
+
public: {
|
|
82
|
+
logLevel: process.env.NUXT_PUBLIC_LOG_LEVEL || (process.env.NODE_ENV === 'production' ? 'warn' : 'debug'),
|
|
83
|
+
tasksEnabled: resolveTasksEnabled(),
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getApps, initializeApp } from 'firebase-admin/app'
|
|
2
|
+
import { getAuth } from 'firebase-admin/auth'
|
|
3
|
+
import { getFirestore } from 'firebase-admin/firestore'
|
|
4
|
+
import { createError, defineEventHandler, getHeader, readBody, setResponseHeader } from 'h3'
|
|
5
|
+
import { setDebugUserRole } from '../../utils/debug-test-admin'
|
|
6
|
+
|
|
7
|
+
/** 開発時の Firebase エミュレーターで、認証した本人のロールを変更する。 */
|
|
8
|
+
export default defineEventHandler(async (event) => {
|
|
9
|
+
const config = useRuntimeConfig(event)
|
|
10
|
+
const projectId = config.public.vuefire?.config?.projectId
|
|
11
|
+
if (!import.meta.dev || config.public.enableDebug === false || !projectId
|
|
12
|
+
|| !process.env.FIREBASE_AUTH_EMULATOR_HOST || !process.env.FIRESTORE_EMULATOR_HOST) {
|
|
13
|
+
throw createError({ statusCode: 404, statusMessage: 'Not Found' })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const name = `bakusoku-debug-${projectId}`
|
|
17
|
+
const app = getApps().find(app => app.name === name) ?? initializeApp({ projectId }, name)
|
|
18
|
+
const auth = getAuth(app)
|
|
19
|
+
const token = getHeader(event, 'authorization')?.match(/^Bearer (\S+)$/i)?.[1]
|
|
20
|
+
if (!token) throw createError({ statusCode: 401, message: 'ログインしてください。' })
|
|
21
|
+
|
|
22
|
+
let user
|
|
23
|
+
try {
|
|
24
|
+
user = await auth.verifyIdToken(token, true)
|
|
25
|
+
} catch {
|
|
26
|
+
throw createError({ statusCode: 401, message: 'ログイン状態を確認できませんでした。' })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const role = (await readBody<{ role?: unknown }>(event))?.role
|
|
30
|
+
if (role !== 'admin' && role !== 'user') {
|
|
31
|
+
throw createError({ statusCode: 400, message: 'ロールには admin または user を指定してください。' })
|
|
32
|
+
}
|
|
33
|
+
setResponseHeader(event, 'Cache-Control', 'no-store')
|
|
34
|
+
if (!await setDebugUserRole(getFirestore(app), user.uid, role)) {
|
|
35
|
+
throw createError({ statusCode: 404, message: 'ログイン中のユーザープロフィールが見つかりません。' })
|
|
36
|
+
}
|
|
37
|
+
return { role }
|
|
38
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { cancelExecution } from '@enlt-bakusoku/functions/enqueue-task'
|
|
2
|
+
import { assertTasksAdmin, rethrowExecutionError } from '../../../utils/tasks-gateway'
|
|
3
|
+
|
|
4
|
+
/** 管理者からの実行の取り消し要求を処理する。 */
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
await assertTasksAdmin(event)
|
|
7
|
+
const body = await readBody(event)
|
|
8
|
+
const executionId = typeof body?.executionId === 'string' ? body.executionId.trim() : ''
|
|
9
|
+
if (!executionId) {
|
|
10
|
+
throw createError({ statusCode: 400, message: '実行IDが必要です。' })
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const cancelled = await cancelExecution(executionId)
|
|
14
|
+
if (!cancelled) {
|
|
15
|
+
throw createError({ statusCode: 404, message: '実行が見つかりません。' })
|
|
16
|
+
}
|
|
17
|
+
return { success: true }
|
|
18
|
+
} catch (error) {
|
|
19
|
+
rethrowExecutionError(error)
|
|
20
|
+
}
|
|
21
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { tasksCatalog } from '#bakusoku/tasks-catalog'
|
|
2
|
+
import { listExecutions, subjectName } from '@enlt-bakusoku/functions/enqueue-task'
|
|
3
|
+
import { assertTasksAdmin } from '../../../utils/tasks-gateway'
|
|
4
|
+
|
|
5
|
+
/** 管理者向けにタスクやマイグレーションの実行履歴を返す。 */
|
|
6
|
+
export default defineEventHandler(async (event) => {
|
|
7
|
+
await assertTasksAdmin(event)
|
|
8
|
+
const query = getQuery(event)
|
|
9
|
+
const kind = query.kind === 'task' || query.kind === 'migration' ? query.kind : undefined
|
|
10
|
+
const subjectId = typeof query.subjectId === 'string' && query.subjectId.trim() !== ''
|
|
11
|
+
? query.subjectId
|
|
12
|
+
: undefined
|
|
13
|
+
const catalog = tasksCatalog()
|
|
14
|
+
const rows = await listExecutions(50, kind, subjectId)
|
|
15
|
+
return {
|
|
16
|
+
success: true,
|
|
17
|
+
data: rows.map(row => ({
|
|
18
|
+
...row,
|
|
19
|
+
name: subjectName(row, catalog.tasks ?? [], catalog.migrations ?? []),
|
|
20
|
+
})),
|
|
21
|
+
}
|
|
22
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { tasksCatalog } from '#bakusoku/tasks-catalog'
|
|
2
|
+
import { enqueueTask, prepareTaskRun } from '@enlt-bakusoku/functions/enqueue-task'
|
|
3
|
+
import { assertTasksAdmin, rethrowExecutionError } from '../../../utils/tasks-gateway'
|
|
4
|
+
|
|
5
|
+
/** 管理者からのタスク実行依頼を検証し、キューに登録する。 */
|
|
6
|
+
export default defineEventHandler(async (event) => {
|
|
7
|
+
const admin = await assertTasksAdmin(event)
|
|
8
|
+
const body = await readBody(event)
|
|
9
|
+
try {
|
|
10
|
+
const catalog = tasksCatalog().tasks ?? []
|
|
11
|
+
const prepared = prepareTaskRun(catalog, body)
|
|
12
|
+
const result = await enqueueTask({
|
|
13
|
+
catalog,
|
|
14
|
+
executionId: prepared.executionId,
|
|
15
|
+
taskType: prepared.taskType,
|
|
16
|
+
data: prepared.data,
|
|
17
|
+
source: 'manual',
|
|
18
|
+
actorUid: admin.uid,
|
|
19
|
+
...(prepared.scheduleTime ? { scheduleTime: prepared.scheduleTime } : {}),
|
|
20
|
+
})
|
|
21
|
+
return { success: true, data: result }
|
|
22
|
+
} catch (error) {
|
|
23
|
+
rethrowExecutionError(error)
|
|
24
|
+
}
|
|
25
|
+
})
|