From 440b7978b5f3ab52fc34bd13108387609737902f Mon Sep 17 00:00:00 2001 From: kevin olson Date: Tue, 21 Jan 2025 01:32:45 -0600 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20in=20the=20plugin=20is=20t?= =?UTF-8?q?oo=20verbose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module.ts | 9 +++++++-- src/runtime/care.ts | 13 ++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/module.ts b/src/module.ts index 328453a..5d90aeb 100644 --- a/src/module.ts +++ b/src/module.ts @@ -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 { @@ -24,9 +25,13 @@ export default defineNuxtModule({ 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')) }, diff --git a/src/runtime/care.ts b/src/runtime/care.ts index f9cf767..a7f2105 100644 --- a/src/runtime/care.ts +++ b/src/runtime/care.ts @@ -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) } @@ -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) } }