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

fix(hapi): Widen type definitions #12710

Merged
merged 7 commits into from
Jul 1, 2024
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
4 changes: 2 additions & 2 deletions packages/node/src/integrations/tracing/hapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../../../debug-build';
import { generateInstrumentOnce } from '../../../otel/instrument';
import { ensureIsWrapped } from '../../../utils/ensureIsWrapped';
import type { RequestEvent, Server } from './types';
import type { Request, RequestEvent, Server } from './types';

const INTEGRATION_NAME = 'Hapi';

Expand Down Expand Up @@ -61,7 +61,7 @@ export const hapiErrorPlugin = {
register: async function (serverArg: Record<any, any>) {
const server = serverArg as unknown as Server;

server.events.on('request', (request, event) => {
server.events.on('request', (request: Request, event: RequestEvent) => {
if (getIsolationScope() !== getDefaultIsolationScope()) {
const route = request.route;
if (route && route.path) {
Expand Down
61 changes: 4 additions & 57 deletions packages/node/src/integrations/tracing/hapi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,38 +103,6 @@ export interface Listener {

export type Tags = { [tag: string]: boolean };

type Dependencies =
| string
| string[]
| {
[key: string]: string;
};

interface PluginNameVersion {
name: string;
version?: string | undefined;
}

interface PluginPackage {
pkg: any;
}

interface PluginBase<T> {
register: (server: Server, options: T) => void | Promise<void>;
multiple?: boolean | undefined;
dependencies?: Dependencies | undefined;
requirements?:
| {
node?: string | undefined;
hapi?: string | undefined;
}
| undefined;

once?: boolean | undefined;
}

type Plugin<T> = PluginBase<T> & (PluginNameVersion | PluginPackage);

interface UserCredentials {}

interface AppCredentials {}
Expand Down Expand Up @@ -205,7 +173,7 @@ interface RequestRoute {
};
}

interface Request extends Podium {
export interface Request extends Podium {
app: ApplicationState;
readonly auth: RequestAuth;
events: RequestEvents;
Expand All @@ -232,16 +200,6 @@ interface ResponseToolkit {
readonly continue: symbol;
}

interface ServerEventCriteria<T> {
name: T;
channels?: string | string[] | undefined;
clone?: boolean | undefined;
count?: number | undefined;
filter?: string | string[] | { tags: string | string[]; all?: boolean | undefined } | undefined;
spread?: boolean | undefined;
tags?: boolean | undefined;
}

export interface RequestEvent {
timestamp: string;
tags: string[];
Expand All @@ -250,26 +208,15 @@ export interface RequestEvent {
error: object;
}

type RequestEventHandler = (request: Request, event: RequestEvent, tags: { [key: string]: true }) => void;
interface ServerEvents {
on(criteria: 'request' | ServerEventCriteria<'request'>, listener: RequestEventHandler): void;
on(criteria: any, listener: any): void;
}

type RouteRequestExtType =
| 'onPreAuth'
| 'onCredentials'
| 'onPostAuth'
| 'onPreHandler'
| 'onPostHandler'
| 'onPreResponse';

type ServerRequestExtType = RouteRequestExtType | 'onRequest';

export type Server = Record<string, any> & {
events: ServerEvents;
ext(event: ServerRequestExtType, method: Lifecycle.Method, options?: Record<string, any>): void;
register: any;
ext(event: any, method: Lifecycle.Method, options?: Record<string, any>): void;
initialize(): Promise<void>;
register(plugins: Plugin<any> | Array<Plugin<any>>, options?: Record<string, any>): Promise<void>;
start(): Promise<void>;
};

Expand Down
Loading