Skip to content

Commit b7abe5f

Browse files
committed
Vendor hapi / boom types.
1 parent 3c75db3 commit b7abe5f

File tree

4 files changed

+86
-305
lines changed

4 files changed

+86
-305
lines changed

packages/node/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
"https-proxy-agent": "^5.0.0"
3131
},
3232
"devDependencies": {
33-
"@hapi/hapi": "^21.3.2",
3433
"@types/cookie": "0.5.2",
3534
"@types/express": "^4.17.14",
36-
"@types/hapi": "^18.0.13",
3735
"@types/lru-cache": "^5.1.0",
3836
"@types/node": "~10.17.0",
3937
"express": "^4.17.1",

packages/node/src/integrations/hapi.ts renamed to packages/node/src/integrations/hapi/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { Boom } from '@hapi/boom';
2-
import type { RequestEvent, ResponseObject, Server } from '@hapi/hapi';
31
import { captureException, configureScope, continueTrace, getActiveTransaction, startTransaction } from '@sentry/core';
42
import type { Integration } from '@sentry/types';
53
import { addExceptionMechanism, dynamicSamplingContextToSentryBaggageHeader, fill } from '@sentry/utils';
64

5+
import type { Boom, RequestEvent, ResponseObject, Server } from './types';
6+
77
function isResponseObject(response: ResponseObject | Boom): response is ResponseObject {
88
return response && (response as ResponseObject).statusCode !== undefined;
99
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Vendored and simplified from @types/hapi__hapi and @types/boom
2+
export interface Boom<Data = unknown> extends Error {
3+
isBoom: boolean;
4+
isServer: boolean;
5+
message: string;
6+
reformat: () => string;
7+
isMissing?: boolean | undefined;
8+
data: Data;
9+
}
10+
11+
export interface RequestEvent {
12+
timestamp: string;
13+
tags: string[];
14+
channel: 'internal' | 'app' | 'error';
15+
data: object | string;
16+
error: object;
17+
}
18+
19+
export interface Server<A = ServerApplicationState> {
20+
app: A;
21+
events: ServerEvents;
22+
ext(event: ServerExtType, method: LifecycleMethod, options?: unknown | undefined): void;
23+
initialize(): Promise<void>;
24+
register<T, D>(plugins: Plugin<T>, options?: unknown | undefined): Promise<this & D>;
25+
start(): Promise<void>;
26+
}
27+
28+
export interface ResponseObject {
29+
statusCode: number;
30+
header: (key: string, value: string) => void;
31+
}
32+
33+
type RequestEventHandler = (request: Request, event: RequestEvent, tags: { [key: string]: true }) => void;
34+
type LifecycleMethod = (request: Request, h: ResponseToolkit, err?: Error | undefined) => unknown;
35+
type Plugin<T> = PluginBase<T> & (PluginNameVersion | PluginPackage);
36+
type ServerExtType =
37+
| 'onPreStart'
38+
| 'onPostStart'
39+
| 'onPreStop'
40+
| 'onPostStop'
41+
| 'onPreAuth'
42+
| 'onCredentials'
43+
| 'onPostAuth'
44+
| 'onPreHandler'
45+
| 'onPostHandler'
46+
| 'onPreResponse'
47+
| 'onPostResponse';
48+
49+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
50+
interface ServerApplicationState {}
51+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
52+
interface RequestEvents {}
53+
54+
interface ServerEvents {
55+
on(criteria: 'request', listener: RequestEventHandler): this;
56+
}
57+
58+
interface PluginBase<T> {
59+
register: (server: Server, options: T) => void | Promise<void>;
60+
}
61+
62+
interface PluginPackage {
63+
pkg: PluginNameVersion;
64+
}
65+
66+
interface ResponseToolkit {
67+
readonly continue: symbol;
68+
}
69+
70+
interface PluginNameVersion {
71+
name: string;
72+
version?: string | undefined;
73+
}
74+
75+
interface Request {
76+
events: RequestEvents;
77+
response: ResponseObject | Boom;
78+
headers: Record<string, string>;
79+
path: string;
80+
route: {
81+
path: string;
82+
};
83+
}

0 commit comments

Comments
 (0)