Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ in the plugin is too verbose #2

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineNuxtModule, addPlugin, addServerPlugin, createResolver } from '@nuxt/kit'
import { defineNuxtModule, addPlugin, addServerPlugin, createResolver, useRuntimeConfig } from '@nuxt/kit'
import { careReportConfig } from './runtime/care'

// Module options TypeScript interface definition
export interface ModuleOptions {
Expand All @@ -24,9 +25,13 @@ export default defineNuxtModule<ModuleOptions>({
defaults: {
apiDomain: 'https://fume.care',
},
setup(_options, _nuxt) {
setup(_options, nuxt) {
const resolver = createResolver(import.meta.url)

const config = useRuntimeConfig().public.care

nuxt.hook('modules:done', () => careReportConfig(config))

addPlugin(resolver.resolve('./runtime/plugin'))
addServerPlugin(resolver.resolve('./runtime/nitro'))
},
Expand Down
13 changes: 8 additions & 5 deletions src/runtime/care.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ const validApiKey = (config: Config): boolean => {
return /^[a-z0-9]{32}$/.test(config.apiKey)
}

export const careCheckConfig = (config: Config): boolean => {
export const careReportConfig = (config: Config) => {
if (!validApiKey(config)) {
log.info('[fume.care] Invalid or missing API key - reporting muted.')
log.info('[fume.care] No valid API Key discovered - reporting muted')
}
else {
log.success('[fume.care] Valid API key found - reporting errors.')
log.success('[fume.care] Valid API key found - reporting activated')
}
}

export const careCheckConfig = (config: Config): boolean => {
return validApiKey(config)
}

Expand Down Expand Up @@ -66,10 +69,10 @@ const sendError = async (hook: string, error: ErrorPayload, config: Config) => {
}),
})
const data = await response.json()
console.log('Error sent successfully:', data.meta)
log.success('[fume.care] Error sent successfully:', data.meta)
return data
}
catch (err) {
console.error('Failed to send error:', err)
log.error('[fume.care] Failed to send error:', err)
}
}
Loading