screenreader-speech-capture 0.9.0-feat-bridge-focus-window.23 → 0.9.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 +8 -2
- package/dist/cli.mjs +89 -40
- package/dist/ui/adapter-node.js +1 -1
- package/dist/ui/client/ui/_app/version.json +1 -1
- package/dist/ui/client/ui/_app/version.json.br +0 -0
- package/dist/ui/client/ui/_app/version.json.gz +0 -0
- package/dist/ui/server/chunks/instance.js +3 -3
- package/dist/ui/server/chunks/internal.js +1 -1
- package/dist/ui/server/chunks/src.js +11 -2
- package/dist/ui/server/chunks/src.js.map +1 -1
- package/dist/ui/server/entries/hooks.server.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.server.js","names":["env"],"sources":["../../../../shared/src/api-version.ts","../../../.svelte-kit/generated/build/env/private/server.js","../../../src/lib/server/bridge-api.ts","../../../src/lib/server/bridge-from-env.ts","../../../src/lib/server/log.ts","../../../src/hooks.server.ts"],"sourcesContent":["/**\n * `<major>.<minor>` of the HTTP API. Minor versions only add things\n * (docs/usage/http-api.md#versioning).\n */\nexport const API_VERSION = '1.21';\n\n/** Path prefix of every API route. */\nexport const API_PREFIX = '/api/v1';\n","import { dynamic_private_env as env } from '../config.js';\n\nexport const SR_BRIDGE_API_URL = env.SR_BRIDGE_API_URL;\n","import { error } from '@sveltejs/kit';\nimport {\n AnyErrorBodySchema,\n API_PREFIX,\n CLIENT_HEADER,\n checkDto,\n ConfigOverridesSchema,\n ConfigSchema,\n SessionListSchema,\n SpeechEntrySchema,\n SpeechListSchema,\n StartSessionResponseSchema,\n StatusSchema,\n type ConfigDto,\n type ConfigOverridesDto,\n type ConfigPatchDto,\n type DtoOf,\n type DtoSchema,\n type SessionListDto,\n type SpeechEntryDto,\n type SpeechListDto,\n type StartSessionRequestDto,\n type StartSessionResponseDto,\n type StatusDto,\n} from '@screenreader-speech-capture/shared';\nimport type { SessionScope } from '#lib/core/sessions.js';\n\ntype Fetch = typeof fetch;\n\n/** The bridge's HTTP API as the BFF uses it: the only place the UI server talks to the bridge. */\nexport interface BridgeApi {\n status(): Promise<StatusDto>;\n sessions(): Promise<SessionListDto>;\n startSession(request: StartSessionRequestDto): Promise<StartSessionResponseDto>;\n /** Ends the current session; does nothing if none is current. */\n endSession(): Promise<void>;\n /** Deletes an ended session and its speech (the bridge refuses the current one). */\n deleteSession(id: number): Promise<void>;\n /** Clears the speech of the current session or of `none` (`session`: an id or `none`); it keeps running. */\n clearSpeech(session: SessionScope): Promise<void>;\n /** The configuration in use (`active`) or the one the next start will use (`saved`). */\n config(view: 'active' | 'saved'): Promise<ConfigDto>;\n /** The settings a flag or environment variable sets: the config file can't change them. */\n configOverrides(): Promise<ConfigOverridesDto>;\n /**\n * Saves a partial config for the next start and answers with the saved config. Rejects with the\n * bridge's status and message, plus `field` (`tcp.port`) when the bridge names one.\n */\n updateConfig(patch: ConfigPatchDto): Promise<ConfigDto>;\n /** Inserts a marker; the bridge files it under the current session (or outside any). */\n addMarker(label: string): Promise<SpeechEntryDto>;\n /** One page of a scope's entries with `seq > since`, oldest first (`session`: an id or `none`). */\n speech(session: SessionScope | null, since: number, limit: number): Promise<SpeechListDto>;\n /**\n * Opens the bridge's SSE stream (`session`: an id or `none`). The body is passed on as it is,\n * so `Last-Event-ID` replays and every event name reach the browser untouched.\n */\n openSpeechStream(\n session: SessionScope | null,\n lastEventId: string | null,\n signal: AbortSignal,\n ): Promise<Response>;\n}\n\n/** Named in the bridge's logs when this UI ends or replaces another client's session. */\nconst UI_CLIENT = 'web-ui';\n\n/**\n * `baseUrl` is the bridge's origin (no path). `fetchFn` is SvelteKit's `event.fetch` in\n * routes and a fake in tests.\n */\nexport function createBridgeApi(baseUrl: string, fetchFn: Fetch): BridgeApi {\n const root = baseUrl.replace(/\\/+$/, '') + API_PREFIX;\n // SvelteKit's `event.fetch` adds `Origin: <the UI's own origin>` to every call to another origin\n // (`pnpm dev:ui`: http://localhost:5173). The bridge refuses a POST from any origin but its own\n // (docs/usage/security.md#host-and-origin), so name the bridge itself: this is a server-side\n // call, not a page of another site.\n const origin = new URL(root).origin;\n\n async function call(\n method: 'GET' | 'POST' | 'PUT' | 'DELETE',\n path: string,\n body?: unknown,\n ): Promise<unknown> {\n let response: Response;\n try {\n response = await fetchFn(`${root}${path}`, {\n method,\n headers: {\n accept: 'application/json',\n origin,\n [CLIENT_HEADER]: UI_CLIENT,\n ...(body === undefined ? {} : { 'content-type': 'application/json' }),\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n } catch (cause) {\n error(502, `The bridge is not reachable: ${describe(cause)}`);\n }\n const answer: unknown = await response.json().catch(() => undefined);\n if (!response.ok) {\n const apiError = checkDto(AnyErrorBodySchema, answer);\n if (!apiError.ok) error(response.status, `The bridge answered ${response.status}`);\n const { message, details } = apiError.value.error;\n const field = details?.field;\n if (typeof field === 'string') error(response.status, { message, field });\n error(response.status, message);\n }\n return answer;\n }\n\n async function read<S extends DtoSchema>(\n method: 'GET' | 'POST' | 'PUT',\n path: string,\n schema: S,\n body?: unknown,\n ): Promise<DtoOf<S>> {\n const checked = checkDto(schema, await call(method, path, body));\n if (!checked.ok) {\n error(502, `Unexpected answer from the bridge at ${checked.field}: ${checked.message}`);\n }\n return checked.value;\n }\n\n return {\n status: () => read('GET', '/status', StatusSchema),\n sessions: () => read('GET', '/sessions', SessionListSchema),\n startSession: (request) => read('POST', '/sessions', StartSessionResponseSchema, request),\n endSession: async () => {\n await call('POST', '/sessions/end');\n },\n deleteSession: async (id) => {\n await call('DELETE', `/sessions?session=${id}`);\n },\n clearSpeech: async (session) => {\n await call('DELETE', `/speech?session=${session}`);\n },\n config: (view) => read('GET', `/config?view=${view}`, ConfigSchema),\n configOverrides: () => read('GET', '/config/overrides', ConfigOverridesSchema),\n updateConfig: (patch) => read('PUT', '/config', ConfigSchema, patch),\n addMarker: (label) => read('POST', '/markers', SpeechEntrySchema, { label }),\n speech: (session, since, limit) => {\n const query = new URLSearchParams({ since: String(since), limit: String(limit) });\n if (session !== null) query.set('session', String(session));\n return read('GET', `/speech?${query}`, SpeechListSchema);\n },\n openSpeechStream: async (session, lastEventId, signal) => {\n const query = session === null ? '' : `?session=${session}`;\n let response: Response;\n try {\n response = await fetchFn(`${root}/speech/stream${query}`, {\n headers: {\n accept: 'text/event-stream',\n origin,\n [CLIENT_HEADER]: UI_CLIENT,\n ...(lastEventId === null ? {} : { 'last-event-id': lastEventId }),\n },\n signal,\n });\n } catch (cause) {\n error(502, `The bridge is not reachable: ${describe(cause)}`);\n }\n if (!response.ok || response.body === null) {\n // Unread, the body would hold the bridge connection until it is garbage collected, and\n // `EventSource` retries every few seconds while the bridge refuses.\n await response.body?.cancel().catch(() => undefined);\n error(\n response.status === 200 ? 502 : response.status,\n 'The speech stream is not available',\n );\n }\n return response;\n },\n };\n}\n\nfunction describe(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n","import { SR_BRIDGE_API_URL } from '$app/env/private';\nimport { createBridgeApi, type BridgeApi } from './bridge-api.js';\n\n/** The bridge API of this deployment, at `SR_BRIDGE_API_URL` (`src/env.ts`). */\nexport function bridgeApiFromEnv(fetchFn: typeof fetch): BridgeApi {\n return createBridgeApi(SR_BRIDGE_API_URL, fetchFn);\n}\n","/** What the BFF logs through: the bridge's `Logger` port, as far as the UI uses it. */\nexport interface ServerLog {\n error(message: string): void;\n warn(message: string): void;\n}\n\n/**\n * Where the bridge puts its `[web-ui]` logger before it loads the UI (`UI_LOGGER_KEY` in\n * `packages/bridge/src/composition/ui.ts`; the bridge and the UI don't import each other).\n */\nconst BRIDGE_LOGGER_KEY = Symbol.for('screenreader-speech-capture.ui-logger');\n\nfunction isServerLog(value: unknown): value is ServerLog {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as ServerLog).error === 'function' &&\n typeof (value as ServerLog).warn === 'function'\n );\n}\n\n/** `pnpm dev:ui` has no bridge in its process: the Vite dev server's console stands in. */\nconst consoleLog: ServerLog = {\n error: (message) => console.error(`[web-ui] ${message}`),\n warn: (message) => console.warn(`[web-ui] ${message}`),\n};\n\n/**\n * The bridge log inside the bridge, the console otherwise. Read per call, so it doesn't matter\n * whether this module loads before or after the bridge sets it.\n */\nexport function serverLog(): ServerLog {\n const bridge = (globalThis as Record<symbol, unknown>)[BRIDGE_LOGGER_KEY];\n return isServerLog(bridge) ? bridge : consoleLog;\n}\n","import type { Handle, HandleServerError } from '@sveltejs/kit/hooks';\nimport { bridgeApiFromEnv } from '#lib/server/bridge-from-env.js';\nimport { serverLog } from '#lib/server/log.js';\n\n/**\n * Set by the bridge (`LOCAL_HEADER` in `packages/bridge/src/composition/ui.ts`) on a request that\n * comes from the bridge's own machine, and removed from every other one. The UI can't import it:\n * the bridge and the UI don't depend on each other.\n */\nconst LOCAL_HEADER = 'x-sr-bridge-local';\n\nexport const handle: Handle = ({ event, resolve }) => {\n event.locals.local = event.request.headers.get(LOCAL_HEADER) === '1';\n // Built once per request and with its `fetch`, so routes and loads share one way to the bridge.\n event.locals.bridge = bridgeApiFromEnv(event.fetch);\n return resolve(event);\n};\n\n/**\n * An unexpected error (`kind: 'unknown'`: not one thrown with `error()`, not SvelteKit's own such\n * as a 404) is one line in the bridge log; the browser keeps SvelteKit's generic answer. The line\n * names the path but never the query, which can hold speech text that must stay off the console\n * (docs/usage/operations.md#speech-text-stays-off-the-console).\n */\nexport const handleError: HandleServerError = ({ kind, error, event }) => {\n if (kind !== 'unknown') return;\n const reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n serverLog().error(`${event.request.method} ${event.url.pathname}: ${reason}`);\n};\n"],"mappings":";;;;;AAOA,IAAa,aAAa;;ACL1B,IAAa,oBAAoBA,oBAAI;;;AC+DrC,IAAM,YAAY;;;;;AAMlB,SAAgB,gBAAgB,SAAiB,SAA2B;CAC1E,MAAM,OAAO,QAAQ,QAAQ,QAAQ,EAAE,IAAI;CAK3C,MAAM,SAAS,IA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AO;AACnD;;;;;;ACIA,IAAM,oBAAoB,OAAO,IAAI,uCAAuC;AAE5E,SAAS,YAAY,OAAoC;CACvD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAoB,UAAU,cACtC,OAAQ,MAAoB,SAAS;AAEzC;;AAGA,IAAM,aAAwB;CAC5B,QAAQ,YAAY,QAAQ,MAAM,YAAY,SAAS;CACvD,OAAO,YAAY,QAAQ,KAAK,YAAY,SAAS;AACvD;;;;;AAMA,SAAgB,YAAuB;CACrC,MAAM,SAAU,WAAuC;CACvD,OAAO,YAAY,MAAM,IAAI,SAAS;AACxC;;;;;;;ACzBA,IAAM,eAAe;AAErB,IAAa,UAAkB,EAAE,OAAO,cAAc;CACpD,MAAM,OAAO,QAAQ,MAAM,QAAQ,QAAQ,IAAI,YAAY,MAAM;CAEjE,MAAM,OAAO,SAAS,iBAAiB,MAAM,KAAK;CAClD,OAAO,QAAQ,KAAK;AACtB;;;;;;;AAQA,IAAa,eAAkC,EAAE,MAAM,OAAO,YAAY;CACxE,IAAI,SAAS,WAAW;CACxB,MAAM,SAAS,iBAAiB,QAAQ,GAAG,MAAM,KAAK,IAAI,MAAM,YAAY,OAAO,KAAK;CACxF,UAAU,CAAC,CAAC,MAAM,GAAG,MAAM,QAAQ,OAAO,GAAG,MAAM,IAAI,SAAS,IAAI,QAAQ;AAC9E"}
|
|
1
|
+
{"version":3,"file":"hooks.server.js","names":["env"],"sources":["../../../../shared/src/api-version.ts","../../../.svelte-kit/generated/build/env/private/server.js","../../../src/lib/server/bridge-api.ts","../../../src/lib/server/bridge-from-env.ts","../../../src/lib/server/log.ts","../../../src/hooks.server.ts"],"sourcesContent":["/**\n * `<major>.<minor>` of the HTTP API. Minor versions only add things\n * (docs/usage/http-api.md#versioning).\n */\nexport const API_VERSION = '1.24';\n\n/** Path prefix of every API route. */\nexport const API_PREFIX = '/api/v1';\n\n/**\n * Response header with {@link API_VERSION} on every answer under {@link API_PREFIX} (since 1.22),\n * so a client checks the version on each answer instead of asking `GET /status` first.\n */\nexport const API_VERSION_HEADER = 'X-SR-Speech-Api-Version';\n","import { dynamic_private_env as env } from '../config.js';\n\nexport const SR_BRIDGE_API_URL = env.SR_BRIDGE_API_URL;\n","import { error } from '@sveltejs/kit';\nimport {\n AnyErrorBodySchema,\n API_PREFIX,\n CLIENT_HEADER,\n checkDto,\n ConfigOverridesSchema,\n ConfigSchema,\n SessionListSchema,\n SpeechEntrySchema,\n SpeechListSchema,\n StartSessionResponseSchema,\n StatusSchema,\n type ConfigDto,\n type ConfigOverridesDto,\n type ConfigPatchDto,\n type DtoOf,\n type DtoSchema,\n type SessionListDto,\n type SpeechEntryDto,\n type SpeechListDto,\n type StartSessionRequestDto,\n type StartSessionResponseDto,\n type StatusDto,\n} from '@screenreader-speech-capture/shared';\nimport type { SessionScope } from '#lib/core/sessions.js';\n\ntype Fetch = typeof fetch;\n\n/** The bridge's HTTP API as the BFF uses it: the only place the UI server talks to the bridge. */\nexport interface BridgeApi {\n status(): Promise<StatusDto>;\n sessions(): Promise<SessionListDto>;\n startSession(request: StartSessionRequestDto): Promise<StartSessionResponseDto>;\n /** Ends the current session; does nothing if none is current. */\n endSession(): Promise<void>;\n /** Deletes an ended session and its speech (the bridge refuses the current one). */\n deleteSession(id: number): Promise<void>;\n /** Clears the speech of the current session or of `none` (`session`: an id or `none`); it keeps running. */\n clearSpeech(session: SessionScope): Promise<void>;\n /** The configuration in use (`active`) or the one the next start will use (`saved`). */\n config(view: 'active' | 'saved'): Promise<ConfigDto>;\n /** The settings a flag or environment variable sets: the config file can't change them. */\n configOverrides(): Promise<ConfigOverridesDto>;\n /**\n * Saves a partial config for the next start and answers with the saved config. Rejects with the\n * bridge's status and message, plus `field` (`tcp.port`) when the bridge names one.\n */\n updateConfig(patch: ConfigPatchDto): Promise<ConfigDto>;\n /** Inserts a marker; the bridge files it under the current session (or outside any). */\n addMarker(label: string): Promise<SpeechEntryDto>;\n /** One page of a scope's entries with `seq > since`, oldest first (`session`: an id or `none`). */\n speech(session: SessionScope | null, since: number, limit: number): Promise<SpeechListDto>;\n /**\n * Opens the bridge's SSE stream (`session`: an id or `none`). The body is passed on as it is,\n * so `Last-Event-ID` replays and every event name reach the browser untouched.\n */\n openSpeechStream(\n session: SessionScope | null,\n lastEventId: string | null,\n signal: AbortSignal,\n ): Promise<Response>;\n}\n\n/** Named in the bridge's logs when this UI ends or replaces another client's session. */\nconst UI_CLIENT = 'web-ui';\n\n/**\n * `baseUrl` is the bridge's origin (no path). `fetchFn` is SvelteKit's `event.fetch` in\n * routes and a fake in tests.\n */\nexport function createBridgeApi(baseUrl: string, fetchFn: Fetch): BridgeApi {\n const root = baseUrl.replace(/\\/+$/, '') + API_PREFIX;\n // SvelteKit's `event.fetch` adds `Origin: <the UI's own origin>` to every call to another origin\n // (`pnpm dev:ui`: http://localhost:5173). The bridge refuses a POST from any origin but its own\n // (docs/usage/security.md#host-and-origin), so name the bridge itself: this is a server-side\n // call, not a page of another site.\n const origin = new URL(root).origin;\n\n async function call(\n method: 'GET' | 'POST' | 'PUT' | 'DELETE',\n path: string,\n body?: unknown,\n ): Promise<unknown> {\n let response: Response;\n try {\n response = await fetchFn(`${root}${path}`, {\n method,\n headers: {\n accept: 'application/json',\n origin,\n [CLIENT_HEADER]: UI_CLIENT,\n ...(body === undefined ? {} : { 'content-type': 'application/json' }),\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n } catch (cause) {\n error(502, `The bridge is not reachable: ${describe(cause)}`);\n }\n const answer: unknown = await response.json().catch(() => undefined);\n if (!response.ok) {\n const apiError = checkDto(AnyErrorBodySchema, answer);\n if (!apiError.ok) error(response.status, `The bridge answered ${response.status}`);\n const { message, details } = apiError.value.error;\n const field = details?.field;\n if (typeof field === 'string') error(response.status, { message, field });\n error(response.status, message);\n }\n return answer;\n }\n\n async function read<S extends DtoSchema>(\n method: 'GET' | 'POST' | 'PUT',\n path: string,\n schema: S,\n body?: unknown,\n ): Promise<DtoOf<S>> {\n const checked = checkDto(schema, await call(method, path, body));\n if (!checked.ok) {\n error(502, `Unexpected answer from the bridge at ${checked.field}: ${checked.message}`);\n }\n return checked.value;\n }\n\n return {\n status: () => read('GET', '/status', StatusSchema),\n sessions: () => read('GET', '/sessions', SessionListSchema),\n startSession: (request) => read('POST', '/sessions', StartSessionResponseSchema, request),\n endSession: async () => {\n await call('POST', '/sessions/end');\n },\n deleteSession: async (id) => {\n await call('DELETE', `/sessions?session=${id}`);\n },\n clearSpeech: async (session) => {\n await call('DELETE', `/speech?session=${session}`);\n },\n config: (view) => read('GET', `/config?view=${view}`, ConfigSchema),\n configOverrides: () => read('GET', '/config/overrides', ConfigOverridesSchema),\n updateConfig: (patch) => read('PUT', '/config', ConfigSchema, patch),\n addMarker: (label) => read('POST', '/markers', SpeechEntrySchema, { label }),\n speech: (session, since, limit) => {\n const query = new URLSearchParams({ since: String(since), limit: String(limit) });\n if (session !== null) query.set('session', String(session));\n return read('GET', `/speech?${query}`, SpeechListSchema);\n },\n openSpeechStream: async (session, lastEventId, signal) => {\n const query = session === null ? '' : `?session=${session}`;\n let response: Response;\n try {\n response = await fetchFn(`${root}/speech/stream${query}`, {\n headers: {\n accept: 'text/event-stream',\n origin,\n [CLIENT_HEADER]: UI_CLIENT,\n ...(lastEventId === null ? {} : { 'last-event-id': lastEventId }),\n },\n signal,\n });\n } catch (cause) {\n error(502, `The bridge is not reachable: ${describe(cause)}`);\n }\n if (!response.ok || response.body === null) {\n // Unread, the body would hold the bridge connection until it is garbage collected, and\n // `EventSource` retries every few seconds while the bridge refuses.\n await response.body?.cancel().catch(() => undefined);\n error(\n response.status === 200 ? 502 : response.status,\n 'The speech stream is not available',\n );\n }\n return response;\n },\n };\n}\n\nfunction describe(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n","import { SR_BRIDGE_API_URL } from '$app/env/private';\nimport { createBridgeApi, type BridgeApi } from './bridge-api.js';\n\n/** The bridge API of this deployment, at `SR_BRIDGE_API_URL` (`src/env.ts`). */\nexport function bridgeApiFromEnv(fetchFn: typeof fetch): BridgeApi {\n return createBridgeApi(SR_BRIDGE_API_URL, fetchFn);\n}\n","/** What the BFF logs through: the bridge's `Logger` port, as far as the UI uses it. */\nexport interface ServerLog {\n error(message: string): void;\n warn(message: string): void;\n}\n\n/**\n * Where the bridge puts its `[web-ui]` logger before it loads the UI (`UI_LOGGER_KEY` in\n * `packages/bridge/src/composition/ui.ts`; the bridge and the UI don't import each other).\n */\nconst BRIDGE_LOGGER_KEY = Symbol.for('screenreader-speech-capture.ui-logger');\n\nfunction isServerLog(value: unknown): value is ServerLog {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as ServerLog).error === 'function' &&\n typeof (value as ServerLog).warn === 'function'\n );\n}\n\n/** `pnpm dev:ui` has no bridge in its process: the Vite dev server's console stands in. */\nconst consoleLog: ServerLog = {\n error: (message) => console.error(`[web-ui] ${message}`),\n warn: (message) => console.warn(`[web-ui] ${message}`),\n};\n\n/**\n * The bridge log inside the bridge, the console otherwise. Read per call, so it doesn't matter\n * whether this module loads before or after the bridge sets it.\n */\nexport function serverLog(): ServerLog {\n const bridge = (globalThis as Record<symbol, unknown>)[BRIDGE_LOGGER_KEY];\n return isServerLog(bridge) ? bridge : consoleLog;\n}\n","import type { Handle, HandleServerError } from '@sveltejs/kit/hooks';\nimport { bridgeApiFromEnv } from '#lib/server/bridge-from-env.js';\nimport { serverLog } from '#lib/server/log.js';\n\n/**\n * Set by the bridge (`LOCAL_HEADER` in `packages/bridge/src/composition/ui.ts`) on a request that\n * comes from the bridge's own machine, and removed from every other one. The UI can't import it:\n * the bridge and the UI don't depend on each other.\n */\nconst LOCAL_HEADER = 'x-sr-bridge-local';\n\nexport const handle: Handle = ({ event, resolve }) => {\n event.locals.local = event.request.headers.get(LOCAL_HEADER) === '1';\n // Built once per request and with its `fetch`, so routes and loads share one way to the bridge.\n event.locals.bridge = bridgeApiFromEnv(event.fetch);\n return resolve(event);\n};\n\n/**\n * An unexpected error (`kind: 'unknown'`: not one thrown with `error()`, not SvelteKit's own such\n * as a 404) is one line in the bridge log; the browser keeps SvelteKit's generic answer. The line\n * names the path but never the query, which can hold speech text that must stay off the console\n * (docs/usage/operations.md#speech-text-stays-off-the-console).\n */\nexport const handleError: HandleServerError = ({ kind, error, event }) => {\n if (kind !== 'unknown') return;\n const reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n serverLog().error(`${event.request.method} ${event.url.pathname}: ${reason}`);\n};\n"],"mappings":";;;;;AAOA,IAAa,aAAa;;ACL1B,IAAa,oBAAoBA,oBAAI;;;AC+DrC,IAAM,YAAY;;;;;AAMlB,SAAgB,gBAAgB,SAAiB,SAA2B;CAC1E,MAAM,OAAO,QAAQ,QAAQ,QAAQ,EAAE,IAAI;CAK3C,MAAM,SAAS,IAAI,IAAI,IAAI,CAAC,CAAC;CAE7B,eAAe,KACb,QACA,MACA,MACkB;EAClB,IAAI;EACJ,IAAI;GACF,WAAW,MAAM,QAAQ,GAAG,OAAO,QAAQ;IACzC;IACA,SAAS;KACP,QAAQ;KACR;MACC,gBAAgB;KACjB,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,mBAAmB;IACrE;IACA,MAAM,SAAS,KAAA,IAAY,KAAA,IAAY,KAAK,UAAU,IAAI;GAC5D,CAAC;EACH,SAAS,OAAO;GACd,MAAM,KAAK,gCAAgC,SAAS,KAAK,GAAG;EAC9D;EACA,MAAM,SAAkB,MAAM,SAAS,KAAK,CAAC,CAAC,YAAY,KAAA,CAAS;EACnE,IAAI,CAAC,SAAS,IAAI;GAChB,MAAM,WAAW,SAAS,oBAAoB,MAAM;GACpD,IAAI,CAAC,SAAS,IAAI,MAAM,SAAS,QAAQ,uBAAuB,SAAS,QAAQ;GACjF,MAAM,EAAE,SAAS,YAAY,SAAS,MAAM;GAC5C,MAAM,QAAQ,SAAS;GACvB,IAAI,OAAO,UAAU,UAAU,MAAM,SAAS,QAAQ;IAAE;IAAS;GAAM,CAAC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,OAAO,KAAK;CACxF,UAAU,CAAC,CAAC,MAAM,GAAG,MAAM,QAAQ,OAAO,GAAG,MAAM,IAAI,SAAS,IAAI,QAAQ;AAC9E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screenreader-speech-capture",
|
|
3
|
-
"version": "0.9.0
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Capture what a screen reader says (JAWS / NVDA via a SAPI 5 socket voice) and expose it over HTTP for automated tests.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|