feat: expose ws globally for console debugging

This commit is contained in:
Fabian @ Blax Software 2026-04-16 08:48:19 +02:00
parent 448b1770fc
commit 34f9d8fd81
2 changed files with 13 additions and 2 deletions

View File

@ -5,8 +5,8 @@ Plug-and-play API + WebSocket client for Vue/Nuxt apps. Framework-agnostic core
## Build
- `pnpm build` — builds via tsup to `dist/`
- `dist/` is committed to the repo (required for GitHub-based `pnpm` installs)
- Always rebuild before committing changes: `pnpm build && git add dist/`
- `dist/` is gitignored — never commit build artifacts
- `prepare` script runs `tsup` automatically on `git+https://` installs
- Exports: `.` (core), `./vue`, `./nuxt`, `./axios`
## WebSocket

View File

@ -122,6 +122,11 @@ export function createFromNuxtConfig(options: NuxtNetworkingOptions = {}): {
vueRef,
)
// Expose ws globally for console debugging: `await ws.send('auth.user')`
if (!isServer && typeof globalThis !== 'undefined') {
;(globalThis as any).ws = ws
}
return { api, ws }
}
@ -130,3 +135,9 @@ export { createApiClient } from './api'
export { createWsClient } from './ws'
export type { ApiClient } from './api'
export type { WsClient, WsChannel } from './ws'
// Global type declaration — makes `ws` available in browser console and TypeScript
declare global {
// eslint-disable-next-line no-var
var ws: WsClient | undefined
}