Skip to content

Commit 2b8939d

Browse files
committed
refactor: Move HttpHandler types to same file
1 parent 626896f commit 2b8939d

18 files changed

Lines changed: 43 additions & 79 deletions

packages/uma/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ export * from './views/ScopeDescription';
5555
// HTTP
5656
export * from './util/http/identifier/BaseTargetExtractor';
5757
export * from './util/http/models/HttpHandler';
58-
export * from './util/http/models/HttpHandlerContext';
59-
export * from './util/http/models/HttpHandlerController';
60-
export * from './util/http/models/HttpHandlerRequest';
61-
export * from './util/http/models/HttpHandlerResponse';
6258
export * from './util/http/models/HttpHandlerRoute';
6359
export * from './util/http/server/ErrorHandler';
6460
export * from './util/http/server/NodeHttpRequestResponseHandler';

packages/uma/src/routes/Config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { ASYMMETRIC_CRYPTOGRAPHIC_ALGORITHM }
22
from '@solid/access-token-verifier/dist/constant/ASYMMETRIC_CRYPTOGRAPHIC_ALGORITHM';
33
import { getLoggerFor } from '@solid/community-server';
4-
import { HttpHandler } from '../util/http/models/HttpHandler';
5-
import { HttpHandlerContext } from '../util/http/models/HttpHandlerContext';
6-
import { HttpHandlerResponse } from '../util/http/models/HttpHandlerResponse';
4+
import { HttpHandler, HttpHandlerContext, HttpHandlerResponse } from '../util/http/models/HttpHandler';
75

86
// eslint-disable no-unused-vars
97
export enum ResponseType {

packages/uma/src/routes/Default.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {HttpHandler} from '../util/http/models/HttpHandler';
2-
import {HttpHandlerContext} from '../util/http/models/HttpHandlerContext';
3-
import {HttpHandlerResponse} from '../util/http/models/HttpHandlerResponse';
1+
import { HttpHandler, HttpHandlerContext, HttpHandlerResponse } from '../util/http/models/HttpHandler';
42

53
/**
64
* Default route handler

packages/uma/src/routes/Introspection.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { HttpHandlerContext } from '../util/http/models/HttpHandlerContext';
2-
import { HttpHandler } from '../util/http/models/HttpHandler';
3-
import { HttpHandlerResponse } from '../util/http/models/HttpHandlerResponse';
1+
2+
import { HttpHandler, HttpHandlerContext, HttpHandlerResponse } from '../util/http/models/HttpHandler';
43
import { AccessToken } from '../tokens/AccessToken';
54
import { JwtTokenFactory } from '../tokens/JwtTokenFactory';
65
import { SerializedToken } from '../tokens/TokenFactory';

packages/uma/src/routes/Jwks.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { HttpHandler } from '../util/http/models/HttpHandler';
2-
import { HttpHandlerContext } from '../util/http/models/HttpHandlerContext';
3-
import { HttpHandlerResponse } from '../util/http/models/HttpHandlerResponse';
1+
import { HttpHandler, HttpHandlerContext, HttpHandlerResponse } from '../util/http/models/HttpHandler';
42
import { getLoggerFor, JwkGenerator } from '@solid/community-server';
53

64
/**

packages/uma/src/routes/ResourceRegistration.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import {
88
UnsupportedMediaTypeHttpError
99
} from '@solid/community-server';
1010
import { randomUUID } from 'node:crypto';
11-
import {HttpHandler} from '../util/http/models/HttpHandler';
12-
import {HttpHandlerContext} from '../util/http/models/HttpHandlerContext';
13-
import {HttpHandlerResponse} from '../util/http/models/HttpHandlerResponse';
14-
import { HttpHandlerRequest } from '../util/http/models/HttpHandlerRequest';
11+
import {
12+
HttpHandler,
13+
HttpHandlerContext,
14+
HttpHandlerRequest,
15+
HttpHandlerResponse
16+
} from '../util/http/models/HttpHandler';
1517
import { ResourceDescription } from '../views/ResourceDescription';
1618
import { reType } from '../util/ReType';
1719
import { extractRequestSigner, verifyRequest } from '../util/HttpMessageSignatures';

packages/uma/src/routes/Ticket.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import {
55
UnsupportedMediaTypeHttpError
66
} from '@solid/community-server';
77
import { randomUUID } from 'node:crypto';
8-
import { HttpHandler } from '../util/http/models/HttpHandler';
9-
import { HttpHandlerContext } from '../util/http/models/HttpHandlerContext';
10-
import { HttpHandlerResponse } from '../util/http/models/HttpHandlerResponse';
8+
import { HttpHandler, HttpHandlerContext, HttpHandlerResponse } from '../util/http/models/HttpHandler';
119
import { array, reType } from '../util/ReType';
1210
import { Permission } from '../views/Permission';
1311
import { Ticket } from '../ticketing/Ticket';

packages/uma/src/routes/Token.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {
44
getLoggerFor,
55
UnsupportedMediaTypeHttpError
66
} from '@solid/community-server';
7-
import { HttpHandler } from '../util/http/models/HttpHandler';
8-
import { HttpHandlerContext } from '../util/http/models/HttpHandlerContext';
9-
import { HttpHandlerResponse } from '../util/http/models/HttpHandlerResponse';
7+
import { HttpHandler, HttpHandlerContext, HttpHandlerResponse } from '../util/http/models/HttpHandler';
108
import { Negotiator } from '../dialog/Negotiator';
119
import { DialogInput } from '../dialog/Input';
1210
import { reType } from '../util/ReType';

packages/uma/src/util/HttpMessageSignatures.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { UnauthorizedHttpError, type AlgJwk, BadRequestHttpError, InternalServer
22
import { httpbis, type SigningKey, type Request as SignRequest } from 'http-message-signatures';
33
import { verifyMessage } from 'http-message-signatures/lib/httpbis';
44
import { type SignatureParameters, type VerifierFinder, type VerifyingKey } from 'http-message-signatures/lib/types';
5-
import type { HttpHandlerRequest } from './http/models/HttpHandlerRequest';
5+
import { HttpHandlerRequest } from './http/models/HttpHandler';
66
import buildGetJwks from 'get-jwks';
77
import crypto from 'node:crypto';
88

99
const authParserMod = import('@httpland/authorization-parser');
1010

1111
export async function signRequest(
12-
url: string,
13-
request: RequestInit & Omit<SignRequest, 'url'>,
12+
url: string,
13+
request: RequestInit & Omit<SignRequest, 'url'>,
1414
jwk: AlgJwk
1515
): Promise<RequestInit & SignRequest> {
1616
const key: SigningKey = {
@@ -52,10 +52,10 @@ export async function verifyRequest(
5252
signer?: string,
5353
): Promise<boolean> {
5454
signer = signer ?? await extractRequestSigner(request);
55-
55+
5656
if (signer.startsWith('"')) signer = signer.slice(1);
5757
if (signer.endsWith('"')) signer = signer.slice(0,-1);
58-
58+
5959
const jwks = buildGetJwks();
6060

6161
const keyLookup: VerifierFinder = async (params: SignatureParameters) => {
@@ -67,7 +67,7 @@ export async function verifyRequest(
6767
alg: alg ?? '',
6868
kid: keyid ?? '',
6969
})
70-
70+
7171
if (!alg) throw new BadRequestHttpError('Invalid HTTP message Signature parameters.');
7272
// if (alg === 'EdDSA') throw new InternalServerError('EdDSA signing is not supported');
7373
// if (alg === 'ES256K') throw new InternalServerError('ES256K signing is not supported');
@@ -83,7 +83,7 @@ export async function verifyRequest(
8383
} catch (err) { console.log(err); return null }
8484
},
8585
};
86-
86+
8787
return verifier;
8888

8989
} catch (err) {
@@ -111,4 +111,3 @@ const algMap: Record<string, AlgParams> = {
111111
'RS384': { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-384' },
112112
'RS512': { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-512' },
113113
}
114-
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
import { AsyncHandler } from '@solid/community-server';
2-
import { HttpHandlerResponse } from './HttpHandlerResponse';
3-
import { HttpHandlerContext } from './HttpHandlerContext';
2+
import { OutgoingHttpHeaders } from 'http';
3+
4+
export interface HttpHandlerContext {
5+
request: HttpHandlerRequest;
6+
}
7+
8+
export interface HttpHandlerRequest<B = unknown> {
9+
url: URL;
10+
method: string;
11+
parameters?: { [key: string]: string };
12+
headers: { [key: string]: string };
13+
body?: B;
14+
}
15+
16+
export interface HttpHandlerResponse<B = unknown> {
17+
body?: B;
18+
headers?: OutgoingHttpHeaders;
19+
status: number;
20+
}
421

5-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
622
export abstract class HttpHandler<C extends HttpHandlerContext = HttpHandlerContext>
723
extends AsyncHandler<C, HttpHandlerResponse> { }

0 commit comments

Comments
 (0)