Initial commit

This commit is contained in:
AI
2026-05-03 07:26:12 +00:00
commit 776d374b59
57 changed files with 15968 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import { createExampleApi } from '~~/api/wrappers/example'
import type { ApiClients } from '~/types/api'
export default defineNuxtPlugin(() => {
const runtimeConfig = useRuntimeConfig()
const api: ApiClients = {
example: createExampleApi({
baseURL: runtimeConfig.public.apiBaseUrl,
timeoutMs: runtimeConfig.public.apiTimeoutMs
})
}
return {
provide: {
api
}
}
})
+123
View File
@@ -0,0 +1,123 @@
import { computed, ref, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useAuthStore, type AuthUser } from '~/stores/auth'
import type { AuthClient, AuthMode } from '~/types/auth'
function normalizeAuthMode(value: string | undefined): AuthMode {
if (value === 'mock' || value === 'userinfo') {
return value
}
return 'disabled'
}
function createMockUser(): AuthUser {
return {
id: 'mock-user',
email: 'mock@example.com',
firstName: 'Mock',
lastName: 'User',
roles: ['USER']
}
}
function canUseWindow() {
return typeof window !== 'undefined'
}
export default defineNuxtPlugin(() => {
const runtimeConfig = useRuntimeConfig()
const authStore = useAuthStore()
const { isAuthenticated, isInitialized, user } = storeToRefs(authStore)
const mode = normalizeAuthMode(runtimeConfig.public.authMode)
const ready = ref(false)
const initialize = async () => {
if (ready.value) {
return
}
if (mode === 'disabled') {
authStore.initialize(null)
ready.value = true
return
}
if (mode === 'mock') {
authStore.initialize(createMockUser())
ready.value = true
return
}
try {
const authUser = await $fetch<AuthUser | null>(runtimeConfig.public.authUserinfoUrl, {
credentials: 'include'
})
authStore.initialize(authUser)
} catch {
authStore.initialize(null)
}
ready.value = true
}
watch(
isInitialized,
(value) => {
if (value) {
ready.value = true
}
},
{ immediate: true }
)
const login = () => {
if (mode === 'disabled') {
return
}
if (mode === 'mock') {
authStore.setUser(createMockUser())
return
}
if (canUseWindow()) {
window.location.href = runtimeConfig.public.authLoginUrl
}
}
const logout = () => {
authStore.clearSession()
if (mode === 'disabled') {
return
}
if (mode === 'mock') {
return
}
if (canUseWindow()) {
window.location.href = runtimeConfig.public.authLogoutUrl
}
}
const auth: AuthClient = {
mode,
isEnabled: mode !== 'disabled',
isReady: ready,
isAuthenticated: computed(() => isAuthenticated.value),
user,
ensureInitialized: initialize,
login,
logout
}
return {
provide: {
auth
}
}
})
+28
View File
@@ -0,0 +1,28 @@
import type { LoggerApi, LoggerPayload, LogLevel } from '~/composables/useLogger'
function write(level: LogLevel, message: string, payload?: LoggerPayload) {
const timestamp = new Date().toISOString()
const prefix = `[template:${level}] ${timestamp} ${message}`
if (payload) {
console[level](prefix, payload)
return
}
console[level](prefix)
}
export default defineNuxtPlugin(() => {
const logger: LoggerApi = {
debug: (message, payload) => write('debug', message, payload),
info: (message, payload) => write('info', message, payload),
warn: (message, payload) => write('warn', message, payload),
error: (message, payload) => write('error', message, payload)
}
return {
provide: {
logger
}
}
})