@atproto/xrpc-server 0.10.20 → 0.11.0-next.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/CHANGELOG.md +36 -0
- package/dist/auth.js +25 -65
- package/dist/auth.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +59 -85
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -28
- package/dist/index.js.map +1 -1
- package/dist/logger.js +4 -7
- package/dist/logger.js.map +1 -1
- package/dist/rate-limiter.d.ts +1 -1
- package/dist/rate-limiter.d.ts.map +1 -1
- package/dist/rate-limiter.js +27 -91
- package/dist/rate-limiter.js.map +1 -1
- package/dist/server.d.ts +4 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +94 -178
- package/dist/server.js.map +1 -1
- package/dist/stream/frames.d.ts +1 -1
- package/dist/stream/frames.d.ts.map +1 -1
- package/dist/stream/frames.js +20 -50
- package/dist/stream/frames.js.map +1 -1
- package/dist/stream/index.d.ts +5 -5
- package/dist/stream/index.d.ts.map +1 -1
- package/dist/stream/index.js +5 -21
- package/dist/stream/index.js.map +1 -1
- package/dist/stream/logger.js +3 -6
- package/dist/stream/logger.js.map +1 -1
- package/dist/stream/server.d.ts +3 -2
- package/dist/stream/server.d.ts.map +1 -1
- package/dist/stream/server.js +12 -22
- package/dist/stream/server.js.map +1 -1
- package/dist/stream/stream.d.ts +2 -2
- package/dist/stream/stream.d.ts.map +1 -1
- package/dist/stream/stream.js +12 -18
- package/dist/stream/stream.js.map +1 -1
- package/dist/stream/subscription.d.ts +1 -1
- package/dist/stream/subscription.d.ts.map +1 -1
- package/dist/stream/subscription.js +9 -18
- package/dist/stream/subscription.js.map +1 -1
- package/dist/stream/types.js +12 -15
- package/dist/stream/types.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +22 -29
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +2 -2
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +75 -116
- package/dist/util.js.map +1 -1
- package/{jest.config.js → jest.config.cjs} +8 -2
- package/package.json +28 -22
- package/src/auth.ts +1 -1
- package/src/errors.ts +4 -1
- package/src/index.ts +8 -8
- package/src/rate-limiter.ts +2 -2
- package/src/server.ts +11 -6
- package/src/stream/frames.ts +2 -2
- package/src/stream/index.ts +5 -5
- package/src/stream/server.ts +4 -3
- package/src/stream/stream.ts +1 -1
- package/src/stream/subscription.ts +2 -2
- package/src/types.ts +2 -2
- package/src/util.ts +6 -3
- package/tests/_util.ts +1 -1
- package/tests/auth.test.ts +6 -3
- package/tests/bodies.test.ts +4 -3
- package/tests/errors.test.ts +2 -2
- package/tests/frames.test.ts +1 -1
- package/tests/ipld.test.ts +2 -2
- package/tests/parameters.test.ts +2 -2
- package/tests/parsing.test.ts +1 -1
- package/tests/procedures.test.ts +2 -2
- package/tests/queries.test.ts +2 -2
- package/tests/rate-limiter.test.ts +3 -3
- package/tests/responses.test.ts +2 -2
- package/tests/stream.test.ts +1 -1
- package/tests/subscriptions.test.ts +11 -5
- package/tsconfig.build.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.tests.json +1 -1
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","source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AAG,MAAM,IAAI,cAAc,CAazE;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,GACb,MAAM,IAAI,wBAAwB,CAGpC;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,GACb,MAAM,IAAI,wBAAwB,CAGpC"}
|
package/dist/types.js
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const node_stream_1 = require("node:stream");
|
|
9
|
-
const lex_schema_1 = require("@atproto/lex-schema");
|
|
10
|
-
exports.headersSchema = lex_schema_1.l.dict(lex_schema_1.l.string(), lex_schema_1.l.string());
|
|
11
|
-
exports.handlerSuccess = lex_schema_1.l.object({
|
|
12
|
-
encoding: lex_schema_1.l.string(),
|
|
13
|
-
body: lex_schema_1.l.unknown(),
|
|
14
|
-
headers: lex_schema_1.l.optional(exports.headersSchema),
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { l } from '@atproto/lex-schema';
|
|
3
|
+
export const headersSchema = l.dict(l.string(), l.string());
|
|
4
|
+
export const handlerSuccess = l.object({
|
|
5
|
+
encoding: l.string(),
|
|
6
|
+
body: l.unknown(),
|
|
7
|
+
headers: l.optional(headersSchema),
|
|
15
8
|
});
|
|
16
|
-
|
|
17
|
-
encoding:
|
|
18
|
-
buffer:
|
|
19
|
-
headers:
|
|
9
|
+
export const handlerPipeThroughBuffer = l.object({
|
|
10
|
+
encoding: l.string(),
|
|
11
|
+
buffer: l.custom((v) => v instanceof Buffer, 'Expected a Buffer'),
|
|
12
|
+
headers: l.optional(headersSchema),
|
|
20
13
|
});
|
|
21
|
-
|
|
22
|
-
encoding:
|
|
23
|
-
stream:
|
|
24
|
-
headers:
|
|
14
|
+
export const handlerPipeThroughStream = l.object({
|
|
15
|
+
encoding: l.string(),
|
|
16
|
+
stream: l.custom((v) => v instanceof Readable, 'Expected a Readable stream'),
|
|
17
|
+
headers: l.optional(headersSchema),
|
|
25
18
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
export const handlerPipeThrough = l.union([
|
|
20
|
+
handlerPipeThroughBuffer,
|
|
21
|
+
handlerPipeThroughStream,
|
|
29
22
|
]);
|
|
30
|
-
function isSharedRateLimitOpts(opts) {
|
|
23
|
+
export function isSharedRateLimitOpts(opts) {
|
|
31
24
|
return typeof opts['name'] === 'string';
|
|
32
25
|
}
|
|
33
|
-
function isHandlerSuccess(output) {
|
|
26
|
+
export function isHandlerSuccess(output) {
|
|
34
27
|
// We only need to discriminate between possible Output values
|
|
35
28
|
return (output != null &&
|
|
36
29
|
'body' in output && // body is non optional (contrary to what type inference may suggest)
|
|
@@ -42,11 +35,11 @@ function isHandlerSuccess(output) {
|
|
|
42
35
|
output.status == null ||
|
|
43
36
|
Number(output.status) < 400));
|
|
44
37
|
}
|
|
45
|
-
function isHandlerPipeThroughBuffer(output) {
|
|
38
|
+
export function isHandlerPipeThroughBuffer(output) {
|
|
46
39
|
// We only need to discriminate between possible Output values
|
|
47
40
|
return output != null && 'buffer' in output && output['buffer'] !== undefined;
|
|
48
41
|
}
|
|
49
|
-
function isHandlerPipeThroughStream(output) {
|
|
42
|
+
export function isHandlerPipeThroughStream(output) {
|
|
50
43
|
// We only need to discriminate between possible Output values
|
|
51
44
|
return output != null && 'stream' in output && output['stream'] !== undefined;
|
|
52
45
|
}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAyKA,sDAIC;AAiID,4CAaC;AAED,gEAKC;AAED,gEAKC;AAxUD,6CAAsC;AAEtC,oDAAuC;AAkD1B,QAAA,aAAa,GAAG,cAAC,CAAC,IAAI,CAAC,cAAC,CAAC,MAAM,EAAE,EAAE,cAAC,CAAC,MAAM,EAAE,CAAC,CAAA;AAI9C,QAAA,cAA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AI,IAAI;YACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAC/B,CAAA;AACH,CAAC;AAED,SAAgB,0BAA0B,CACxC,MAAc;IAEd,8DAA8D;IAC9D,OAAO,MAAM,IAAI,IAAI,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAA;AAC/E,CAAC;AAED,SAAgB,0BAA0B,CACxC,MAAc;IAEd,8DAA8D;IAC9D,OAAO,MAAM,IAAI,IAAI,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAA;AAC/E,CAAC","sourcesContent":["import { IncomingMessage } from 'node:http'\nimport { Readable } from 'node:stream'\nimport { NextFunction, Request, Response } from 'express'\nimport { l } from '@atproto/lex-schema'\nimport { ErrorResult, XRPCError } from './errors'\nimport { CalcKeyFn, CalcPointsFn, RateLimiterI } from './rate-limiter'\n\nexport type Awaitable<T> = T | Promise<T>\n\nexport type CatchallHandler = (\n req: Request,\n res: Response,\n next: NextFunction,\n) => unknown\n\nexport type Options = {\n validateResponse?: boolean\n catchall?: CatchallHandler\n payload?: RouteOptions\n rateLimits?: {\n creator: RateLimiterCreator<HandlerContext>\n global?: ServerRateLimitDescription<HandlerContext>[]\n shared?: ServerRateLimitDescription<HandlerContext>[]\n bypass?: (ctx: HandlerContext) => boolean\n }\n /**\n * By default, errors are converted to {@link XRPCError} using\n * {@link XRPCError.fromError} before being rendered. If method handlers throw\n * error objects that are not properly rendered in the HTTP response, this\n * function can be used to properly convert them to {@link XRPCError}. The\n * provided function will typically fallback to the default error conversion\n * (`return XRPCError.fromError(err)`) if the error is not recognized.\n *\n * @note This function should not throw errors.\n */\n errorParser?: (err: unknown) => XRPCError\n}\n\nexport type UndecodedParams = Request['query']\n\nexport type Primitive = string | number | boolean\nexport type Params = { [P in string]?: undefined | Primitive | Primitive[] }\n\nexport type HandlerInput = {\n encoding: string\n body: unknown\n}\n\nexport type AuthResult = {\n credentials: unknown\n artifacts?: unknown\n}\n\nexport const headersSchema = l.dict(l.string(), l.string())\n\nexport type Headers = l.Infer<typeof headersSchema>\n\nexport const handlerSuccess = l.object({\n encoding: l.string(),\n body: l.unknown(),\n headers: l.optional(headersSchema),\n})\n\nexport type HandlerSuccess = l.Infer<typeof handlerSuccess>\n\nexport const handlerPipeThroughBuffer = l.object({\n encoding: l.string(),\n buffer: l.custom(\n (v): v is Buffer => v instanceof Buffer,\n 'Expected a Buffer',\n ),\n headers: l.optional(headersSchema),\n})\n\nexport type HandlerPipeThroughBuffer = l.Infer<typeof handlerPipeThroughBuffer>\n\nexport const handlerPipeThroughStream = l.object({\n encoding: l.string(),\n stream: l.custom(\n (v): v is Readable => v instanceof Readable,\n 'Expected a Readable stream',\n ),\n headers: l.optional(headersSchema),\n})\n\nexport type HandlerPipeThroughStream = l.Infer<typeof handlerPipeThroughStream>\n\nexport const handlerPipeThrough = l.union([\n handlerPipeThroughBuffer,\n handlerPipeThroughStream,\n])\n\nexport type HandlerPipeThrough = l.Infer<typeof handlerPipeThrough>\n\nexport type Auth = void | AuthResult\nexport type Input = void | HandlerInput\nexport type Output = void | HandlerSuccess | HandlerPipeThrough | ErrorResult\n\nexport type AuthVerifier<C, A extends AuthResult = AuthResult> =\n | ((ctx: C) => Awaitable<A | ErrorResult>)\n | ((ctx: C) => Awaitable<A>)\n\nexport type MethodAuthContext<P extends Params = Params> = {\n params: P\n req: Request\n res: Response\n}\n\nexport type MethodAuthVerifier<\n A extends AuthResult = AuthResult,\n P extends Params = Params,\n> = AuthVerifier<MethodAuthContext<P>, A>\n\nexport type HandlerContext<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n> = MethodAuthContext<P> & {\n auth: A\n input: I\n resetRouteRateLimits: () => Promise<void>\n}\n\nexport type MethodHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = (ctx: HandlerContext<A, P, I>) => Awaitable<O | HandlerPipeThrough>\n\nexport type RateLimiterCreator<T extends HandlerContext = HandlerContext> = <\n C extends T = T,\n>(opts: {\n keyPrefix: string\n durationMs: number\n points: number\n calcKey: CalcKeyFn<C>\n calcPoints: CalcPointsFn<C>\n failClosed?: boolean\n}) => RateLimiterI<C>\n\nexport type ServerRateLimitDescription<\n C extends HandlerContext = HandlerContext,\n> = {\n name: string\n durationMs: number\n points: number\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n failClosed?: boolean\n}\n\nexport type SharedRateLimitOpts<C extends HandlerContext = HandlerContext> = {\n name: string\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n}\n\nexport type RouteRateLimitOpts<C extends HandlerContext = HandlerContext> = {\n durationMs: number\n points: number\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n}\n\nexport type RateLimitOpts<C extends HandlerContext = HandlerContext> =\n | SharedRateLimitOpts<C>\n | RouteRateLimitOpts<C>\n\nexport function isSharedRateLimitOpts<\n C extends HandlerContext = HandlerContext,\n>(opts: RateLimitOpts<C>): opts is SharedRateLimitOpts<C> {\n return typeof opts['name'] === 'string'\n}\n\nexport type RouteOptions = {\n blobLimit?: number\n jsonLimit?: number\n textLimit?: number\n paramsParseLoose?: boolean\n}\n\nexport type MethodAuth<\n A extends Auth = Auth,\n P extends Params = Params,\n> = MethodAuthVerifier<Extract<A, AuthResult>, P>\n\nexport type MethodRateLimit<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n> =\n | RateLimitOpts<HandlerContext<A, P, I>>\n | RateLimitOpts<HandlerContext<A, P, I>>[]\n\nexport type MethodConfig<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = {\n handler: MethodHandler<A, P, I, O>\n auth?: MethodAuth<A, P>\n opts?: RouteOptions\n rateLimit?: MethodRateLimit<A, P, I>\n}\n\nexport type MethodConfigWithAuth<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = {\n handler: MethodHandler<A, P, I, O>\n auth: MethodAuth<A, P>\n opts?: RouteOptions\n rateLimit?: MethodRateLimit<A, P, I>\n}\n\nexport type MethodConfigOrHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = MethodHandler<A, P, I, O> | MethodConfig<A, P, I, O>\n\nexport type StreamAuthContext<P extends Params = Params> = {\n params: P\n req: IncomingMessage\n}\n\nexport type LexMethodParams<M extends l.Procedure | l.Query | l.Subscription> =\n l.InferMethodParams<M>\n\nexport type LexMethodInput<M extends l.Procedure | l.Query> =\n l.InferMethodInput<M, Readable>\n\nexport type LexMethodOutput<M extends l.Procedure | l.Query> =\n l.InferMethodOutput<M, Readable> extends undefined\n ? l.InferMethodOutput<M, Uint8Array | Readable> | void\n : l.InferMethodOutput<M, Uint8Array | Readable>\n\nexport type LexMethodMessage<M extends l.Subscription> = l.InferMethodMessage<M>\n\nexport type LexMethodHandler<\n M extends l.Procedure | l.Query,\n A extends Auth = Auth,\n> = MethodHandler<A, LexMethodParams<M>, LexMethodInput<M>, LexMethodOutput<M>>\n\nexport type LexMethodConfig<\n M extends l.Procedure | l.Query,\n A extends Auth = Auth,\n> = MethodConfig<A, LexMethodParams<M>, LexMethodInput<M>, LexMethodOutput<M>>\n\nexport type LexSubscriptionHandler<\n M extends l.Subscription,\n A extends Auth = Auth,\n> = StreamHandler<\n Extract<A, AuthResult>,\n LexMethodParams<M>,\n LexMethodMessage<M>\n>\n\nexport type LexSubscriptionConfig<\n M extends l.Subscription,\n A extends Auth = Auth,\n> = StreamConfig<A, LexMethodParams<M>, LexMethodMessage<M>>\n\nexport type StreamAuthVerifier<\n A extends AuthResult = AuthResult,\n P extends Params = Params,\n> = AuthVerifier<StreamAuthContext<P>, A>\n\nexport type StreamContext<\n A extends Auth = Auth,\n P extends Params = Params,\n> = StreamAuthContext<P> & {\n auth: A\n signal: AbortSignal\n}\n\nexport type StreamHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = (ctx: StreamContext<A, P>) => AsyncIterable<O>\n\nexport type StreamConfig<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = {\n auth?: StreamAuthVerifier<Extract<A, AuthResult>, P>\n handler: StreamHandler<A, P, O>\n}\n\nexport type StreamConfigOrHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = StreamHandler<A, P, O> | StreamConfig<A, P, O>\n\nexport function isHandlerSuccess(output: Output): output is HandlerSuccess {\n // We only need to discriminate between possible Output values\n return (\n output != null &&\n 'body' in output && // body is non optional (contrary to what type inference may suggest)\n 'encoding' in output &&\n // Allows using objects that extends HandlerSuccess with a \"status\" field as\n // output, as long as the status is < 400, in order to avoid being confused\n // with ErrorResult objects.\n (!('status' in output) ||\n output.status == null ||\n Number(output.status) < 400)\n )\n}\n\nexport function isHandlerPipeThroughBuffer(\n output: Output,\n): output is HandlerPipeThroughBuffer {\n // We only need to discriminate between possible Output values\n return output != null && 'buffer' in output && output['buffer'] !== undefined\n}\n\nexport function isHandlerPipeThroughStream(\n output: Output,\n): output is HandlerPipeThroughStream {\n // We only need to discriminate between possible Output values\n return output != null && 'stream' in output && output['stream'] !== undefined\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AAkDvC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;AAI3D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,IAAI,EAAE,C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AG,GAAG,CAAC,CAC/B,CAAA;AACH,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,MAAc;IAEd,8DAA8D;IAC9D,OAAO,MAAM,IAAI,IAAI,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAA;AAC/E,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,MAAc;IAEd,8DAA8D;IAC9D,OAAO,MAAM,IAAI,IAAI,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAA;AAC/E,CAAC","sourcesContent":["import { IncomingMessage } from 'node:http'\nimport { Readable } from 'node:stream'\nimport { NextFunction, Request, Response } from 'express'\nimport { l } from '@atproto/lex-schema'\nimport { ErrorResult, XRPCError } from './errors.js'\nimport { CalcKeyFn, CalcPointsFn, RateLimiterI } from './rate-limiter.js'\n\nexport type Awaitable<T> = T | Promise<T>\n\nexport type CatchallHandler = (\n req: Request,\n res: Response,\n next: NextFunction,\n) => unknown\n\nexport type Options = {\n validateResponse?: boolean\n catchall?: CatchallHandler\n payload?: RouteOptions\n rateLimits?: {\n creator: RateLimiterCreator<HandlerContext>\n global?: ServerRateLimitDescription<HandlerContext>[]\n shared?: ServerRateLimitDescription<HandlerContext>[]\n bypass?: (ctx: HandlerContext) => boolean\n }\n /**\n * By default, errors are converted to {@link XRPCError} using\n * {@link XRPCError.fromError} before being rendered. If method handlers throw\n * error objects that are not properly rendered in the HTTP response, this\n * function can be used to properly convert them to {@link XRPCError}. The\n * provided function will typically fallback to the default error conversion\n * (`return XRPCError.fromError(err)`) if the error is not recognized.\n *\n * @note This function should not throw errors.\n */\n errorParser?: (err: unknown) => XRPCError\n}\n\nexport type UndecodedParams = Request['query']\n\nexport type Primitive = string | number | boolean\nexport type Params = { [P in string]?: undefined | Primitive | Primitive[] }\n\nexport type HandlerInput = {\n encoding: string\n body: unknown\n}\n\nexport type AuthResult = {\n credentials: unknown\n artifacts?: unknown\n}\n\nexport const headersSchema = l.dict(l.string(), l.string())\n\nexport type Headers = l.Infer<typeof headersSchema>\n\nexport const handlerSuccess = l.object({\n encoding: l.string(),\n body: l.unknown(),\n headers: l.optional(headersSchema),\n})\n\nexport type HandlerSuccess = l.Infer<typeof handlerSuccess>\n\nexport const handlerPipeThroughBuffer = l.object({\n encoding: l.string(),\n buffer: l.custom(\n (v): v is Buffer => v instanceof Buffer,\n 'Expected a Buffer',\n ),\n headers: l.optional(headersSchema),\n})\n\nexport type HandlerPipeThroughBuffer = l.Infer<typeof handlerPipeThroughBuffer>\n\nexport const handlerPipeThroughStream = l.object({\n encoding: l.string(),\n stream: l.custom(\n (v): v is Readable => v instanceof Readable,\n 'Expected a Readable stream',\n ),\n headers: l.optional(headersSchema),\n})\n\nexport type HandlerPipeThroughStream = l.Infer<typeof handlerPipeThroughStream>\n\nexport const handlerPipeThrough = l.union([\n handlerPipeThroughBuffer,\n handlerPipeThroughStream,\n])\n\nexport type HandlerPipeThrough = l.Infer<typeof handlerPipeThrough>\n\nexport type Auth = void | AuthResult\nexport type Input = void | HandlerInput\nexport type Output = void | HandlerSuccess | HandlerPipeThrough | ErrorResult\n\nexport type AuthVerifier<C, A extends AuthResult = AuthResult> =\n | ((ctx: C) => Awaitable<A | ErrorResult>)\n | ((ctx: C) => Awaitable<A>)\n\nexport type MethodAuthContext<P extends Params = Params> = {\n params: P\n req: Request\n res: Response\n}\n\nexport type MethodAuthVerifier<\n A extends AuthResult = AuthResult,\n P extends Params = Params,\n> = AuthVerifier<MethodAuthContext<P>, A>\n\nexport type HandlerContext<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n> = MethodAuthContext<P> & {\n auth: A\n input: I\n resetRouteRateLimits: () => Promise<void>\n}\n\nexport type MethodHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = (ctx: HandlerContext<A, P, I>) => Awaitable<O | HandlerPipeThrough>\n\nexport type RateLimiterCreator<T extends HandlerContext = HandlerContext> = <\n C extends T = T,\n>(opts: {\n keyPrefix: string\n durationMs: number\n points: number\n calcKey: CalcKeyFn<C>\n calcPoints: CalcPointsFn<C>\n failClosed?: boolean\n}) => RateLimiterI<C>\n\nexport type ServerRateLimitDescription<\n C extends HandlerContext = HandlerContext,\n> = {\n name: string\n durationMs: number\n points: number\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n failClosed?: boolean\n}\n\nexport type SharedRateLimitOpts<C extends HandlerContext = HandlerContext> = {\n name: string\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n}\n\nexport type RouteRateLimitOpts<C extends HandlerContext = HandlerContext> = {\n durationMs: number\n points: number\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n}\n\nexport type RateLimitOpts<C extends HandlerContext = HandlerContext> =\n | SharedRateLimitOpts<C>\n | RouteRateLimitOpts<C>\n\nexport function isSharedRateLimitOpts<\n C extends HandlerContext = HandlerContext,\n>(opts: RateLimitOpts<C>): opts is SharedRateLimitOpts<C> {\n return typeof opts['name'] === 'string'\n}\n\nexport type RouteOptions = {\n blobLimit?: number\n jsonLimit?: number\n textLimit?: number\n paramsParseLoose?: boolean\n}\n\nexport type MethodAuth<\n A extends Auth = Auth,\n P extends Params = Params,\n> = MethodAuthVerifier<Extract<A, AuthResult>, P>\n\nexport type MethodRateLimit<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n> =\n | RateLimitOpts<HandlerContext<A, P, I>>\n | RateLimitOpts<HandlerContext<A, P, I>>[]\n\nexport type MethodConfig<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = {\n handler: MethodHandler<A, P, I, O>\n auth?: MethodAuth<A, P>\n opts?: RouteOptions\n rateLimit?: MethodRateLimit<A, P, I>\n}\n\nexport type MethodConfigWithAuth<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = {\n handler: MethodHandler<A, P, I, O>\n auth: MethodAuth<A, P>\n opts?: RouteOptions\n rateLimit?: MethodRateLimit<A, P, I>\n}\n\nexport type MethodConfigOrHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = MethodHandler<A, P, I, O> | MethodConfig<A, P, I, O>\n\nexport type StreamAuthContext<P extends Params = Params> = {\n params: P\n req: IncomingMessage\n}\n\nexport type LexMethodParams<M extends l.Procedure | l.Query | l.Subscription> =\n l.InferMethodParams<M>\n\nexport type LexMethodInput<M extends l.Procedure | l.Query> =\n l.InferMethodInput<M, Readable>\n\nexport type LexMethodOutput<M extends l.Procedure | l.Query> =\n l.InferMethodOutput<M, Readable> extends undefined\n ? l.InferMethodOutput<M, Uint8Array | Readable> | void\n : l.InferMethodOutput<M, Uint8Array | Readable>\n\nexport type LexMethodMessage<M extends l.Subscription> = l.InferMethodMessage<M>\n\nexport type LexMethodHandler<\n M extends l.Procedure | l.Query,\n A extends Auth = Auth,\n> = MethodHandler<A, LexMethodParams<M>, LexMethodInput<M>, LexMethodOutput<M>>\n\nexport type LexMethodConfig<\n M extends l.Procedure | l.Query,\n A extends Auth = Auth,\n> = MethodConfig<A, LexMethodParams<M>, LexMethodInput<M>, LexMethodOutput<M>>\n\nexport type LexSubscriptionHandler<\n M extends l.Subscription,\n A extends Auth = Auth,\n> = StreamHandler<\n Extract<A, AuthResult>,\n LexMethodParams<M>,\n LexMethodMessage<M>\n>\n\nexport type LexSubscriptionConfig<\n M extends l.Subscription,\n A extends Auth = Auth,\n> = StreamConfig<A, LexMethodParams<M>, LexMethodMessage<M>>\n\nexport type StreamAuthVerifier<\n A extends AuthResult = AuthResult,\n P extends Params = Params,\n> = AuthVerifier<StreamAuthContext<P>, A>\n\nexport type StreamContext<\n A extends Auth = Auth,\n P extends Params = Params,\n> = StreamAuthContext<P> & {\n auth: A\n signal: AbortSignal\n}\n\nexport type StreamHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = (ctx: StreamContext<A, P>) => AsyncIterable<O>\n\nexport type StreamConfig<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = {\n auth?: StreamAuthVerifier<Extract<A, AuthResult>, P>\n handler: StreamHandler<A, P, O>\n}\n\nexport type StreamConfigOrHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = StreamHandler<A, P, O> | StreamConfig<A, P, O>\n\nexport function isHandlerSuccess(output: Output): output is HandlerSuccess {\n // We only need to discriminate between possible Output values\n return (\n output != null &&\n 'body' in output && // body is non optional (contrary to what type inference may suggest)\n 'encoding' in output &&\n // Allows using objects that extends HandlerSuccess with a \"status\" field as\n // output, as long as the status is < 400, in order to avoid being confused\n // with ErrorResult objects.\n (!('status' in output) ||\n output.status == null ||\n Number(output.status) < 400)\n )\n}\n\nexport function isHandlerPipeThroughBuffer(\n output: Output,\n): output is HandlerPipeThroughBuffer {\n // We only need to discriminate between possible Output values\n return output != null && 'buffer' in output && output['buffer'] !== undefined\n}\n\nexport function isHandlerPipeThroughStream(\n output: Output,\n): output is HandlerPipeThroughStream {\n // We only need to discriminate between possible Output values\n return output != null && 'stream' in output && output['stream'] !== undefined\n}\n"]}
|
package/dist/util.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { IncomingMessage, OutgoingMessage } from 'node:http';
|
|
|
2
2
|
import { Request as ExpressRequest, Response as ExpressResponse } from 'express';
|
|
3
3
|
import { l } from '@atproto/lex-schema';
|
|
4
4
|
import { type LexXrpcProcedure, type LexXrpcQuery, type LexXrpcSubscription, Lexicons } from '@atproto/lexicon';
|
|
5
|
-
import { ErrorResult } from './errors';
|
|
6
|
-
import { Auth, Input, LexMethodInput, LexMethodOutput, LexMethodParams, Output, Params, RouteOptions, UndecodedParams } from './types';
|
|
5
|
+
import { ErrorResult } from './errors.js';
|
|
6
|
+
import { Auth, Input, LexMethodInput, LexMethodOutput, LexMethodParams, Output, Params, RouteOptions, UndecodedParams } from './types.js';
|
|
7
7
|
export type ParamsVerifierInternal<P extends Params = Params> = (req: IncomingMessage | ExpressRequest) => P;
|
|
8
8
|
export type AuthVerifierInternal<C, A extends Auth = Auth> = (ctx: C) => Promise<Exclude<A, ErrorResult>>;
|
|
9
9
|
export type InputVerifierInternal<I extends Input = Input> = (req: ExpressRequest, res: ExpressResponse) => Promise<I>;
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE5D,OAAO,EACL,OAAO,IAAI,cAAc,EACzB,QAAQ,IAAI,eAAe,EAG5B,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE5D,OAAO,EACL,OAAO,IAAI,cAAc,EACzB,QAAQ,IAAI,eAAe,EAG5B,MAAM,SAAS,CAAA;AAOhB,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,QAAQ,EAET,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EACL,WAAW,EAIZ,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,IAAI,EACJ,KAAK,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,MAAM,EACN,MAAM,EACN,YAAY,EACZ,eAAe,EAEhB,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,CAC9D,GAAG,EAAE,eAAe,GAAG,cAAc,KAClC,CAAC,CAAA;AAEN,MAAM,MAAM,oBAAoB,CAAC,CAAC,E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ACZ,WAAW,CAAC,EAAE,MAAM,YAAA;IAE7B,KAAK;IAIL,IAAI;CAKL;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,eAAO,MAAM,YAAY,GAAI,KAAK,cAAc,GAAG,eAAe,WACK,CAAA;AAEvE;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAI1C,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SA4DrD,CAAA"}
|
package/dist/util.js
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports.serverTimingHeader = serverTimingHeader;
|
|
18
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
19
|
-
const node_stream_1 = require("node:stream");
|
|
20
|
-
const express_1 = require("express");
|
|
21
|
-
const mime_types_1 = require("mime-types");
|
|
22
|
-
const common_1 = require("@atproto/common");
|
|
23
|
-
const lex_json_1 = require("@atproto/lex-json");
|
|
24
|
-
const lex_schema_1 = require("@atproto/lex-schema");
|
|
25
|
-
const lexicon_1 = require("@atproto/lexicon");
|
|
26
|
-
const xrpc_1 = require("@atproto/xrpc");
|
|
27
|
-
const errors_1 = require("./errors");
|
|
28
|
-
const types_1 = require("./types");
|
|
29
|
-
const asArray = (arr) => Array.isArray(arr) ? arr : [arr];
|
|
30
|
-
exports.asArray = asArray;
|
|
31
|
-
function setHeaders(res, headers) {
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { pipeline } from 'node:stream';
|
|
3
|
+
import { json, text, } from 'express';
|
|
4
|
+
// eslint-disable-next-line import/default, import/no-named-as-default-member
|
|
5
|
+
import mimeTypes from 'mime-types';
|
|
6
|
+
// eslint-disable-next-line import/no-named-as-default-member
|
|
7
|
+
const { contentType } = mimeTypes;
|
|
8
|
+
import { MaxSizeChecker, createDecoders } from '@atproto/common';
|
|
9
|
+
import { jsonToLex } from '@atproto/lex-json';
|
|
10
|
+
import { l } from '@atproto/lex-schema';
|
|
11
|
+
import { jsonToLex as jsonToLexWithBlobRef, } from '@atproto/lexicon';
|
|
12
|
+
import { ResponseType } from '@atproto/xrpc';
|
|
13
|
+
import { InternalServerError, InvalidRequestError, XRPCError, } from './errors.js';
|
|
14
|
+
import { handlerSuccess, } from './types.js';
|
|
15
|
+
export const asArray = (arr) => Array.isArray(arr) ? arr : [arr];
|
|
16
|
+
export function setHeaders(res, headers) {
|
|
32
17
|
if (headers) {
|
|
33
18
|
for (const [name, val] of Object.entries(headers)) {
|
|
34
19
|
if (val != null)
|
|
@@ -57,7 +42,7 @@ function decodeQueryParams(def, params) {
|
|
|
57
42
|
}
|
|
58
43
|
return decoded;
|
|
59
44
|
}
|
|
60
|
-
function decodeQueryParam(type, value) {
|
|
45
|
+
export function decodeQueryParam(type, value) {
|
|
61
46
|
if (!value) {
|
|
62
47
|
return undefined;
|
|
63
48
|
}
|
|
@@ -107,7 +92,7 @@ function getSearchParams(url, opts) {
|
|
|
107
92
|
}
|
|
108
93
|
return urlSearchParams;
|
|
109
94
|
}
|
|
110
|
-
function getQueryParams(req, opts) {
|
|
95
|
+
export function getQueryParams(req, opts) {
|
|
111
96
|
if ('query' in req)
|
|
112
97
|
return req.query;
|
|
113
98
|
const result = Object.create(null);
|
|
@@ -116,7 +101,7 @@ function getQueryParams(req, opts) {
|
|
|
116
101
|
return result;
|
|
117
102
|
if (searchParams.has('__proto__')) {
|
|
118
103
|
// Prevent prototype pollution
|
|
119
|
-
throw new
|
|
104
|
+
throw new InvalidRequestError(`Invalid query parameter: __proto__`, 'InvalidQueryParameter');
|
|
120
105
|
}
|
|
121
106
|
for (const key of searchParams.keys()) {
|
|
122
107
|
const values = searchParams.getAll(key);
|
|
@@ -124,7 +109,7 @@ function getQueryParams(req, opts) {
|
|
|
124
109
|
}
|
|
125
110
|
return result;
|
|
126
111
|
}
|
|
127
|
-
function createLexiconParamsVerifier(nsid, def, lexicons) {
|
|
112
|
+
export function createLexiconParamsVerifier(nsid, def, lexicons) {
|
|
128
113
|
return (req) => {
|
|
129
114
|
const queryParams = getQueryParams(req);
|
|
130
115
|
const params = decodeQueryParams(def, queryParams);
|
|
@@ -133,12 +118,12 @@ function createLexiconParamsVerifier(nsid, def, lexicons) {
|
|
|
133
118
|
}
|
|
134
119
|
catch (cause) {
|
|
135
120
|
// @NOTE WE historically did not check for specific error types here,
|
|
136
|
-
throw new
|
|
121
|
+
throw new InvalidRequestError(String(cause), undefined, { cause });
|
|
137
122
|
}
|
|
138
123
|
};
|
|
139
124
|
}
|
|
140
|
-
function createSchemaParamsVerifier(ns, options) {
|
|
141
|
-
const schema =
|
|
125
|
+
export function createSchemaParamsVerifier(ns, options) {
|
|
126
|
+
const schema = l.getMain(ns);
|
|
142
127
|
const queryOpts = { parseLoose: options?.paramsParseLoose };
|
|
143
128
|
return (req) => {
|
|
144
129
|
const urlSearchParams = getSearchParams(req.url, queryOpts) ?? new URLSearchParams();
|
|
@@ -147,22 +132,22 @@ function createSchemaParamsVerifier(ns, options) {
|
|
|
147
132
|
return params;
|
|
148
133
|
}
|
|
149
134
|
catch (cause) {
|
|
150
|
-
if (cause instanceof
|
|
135
|
+
if (cause instanceof l.LexValidationError) {
|
|
151
136
|
const message = `Invalid ${schema.nsid} params: ${cause.issues
|
|
152
137
|
.map((issue) => issue.message)
|
|
153
138
|
.join(', ')}`;
|
|
154
|
-
throw new
|
|
139
|
+
throw new InvalidRequestError(message, undefined, { cause });
|
|
155
140
|
}
|
|
156
141
|
throw cause;
|
|
157
142
|
}
|
|
158
143
|
};
|
|
159
144
|
}
|
|
160
|
-
function createLexiconInputVerifier(nsid, def, options, lexicons) {
|
|
145
|
+
export function createLexiconInputVerifier(nsid, def, options, lexicons) {
|
|
161
146
|
if (def.type === 'query' || !def.input) {
|
|
162
147
|
return async (req) => {
|
|
163
148
|
// @NOTE We allow (and ignore) "empty" bodies
|
|
164
149
|
if (getBodyPresence(req) === 'present') {
|
|
165
|
-
throw new
|
|
150
|
+
throw new InvalidRequestError(`A request body was provided when none was expected`);
|
|
166
151
|
}
|
|
167
152
|
return undefined;
|
|
168
153
|
};
|
|
@@ -177,22 +162,22 @@ function createLexiconInputVerifier(nsid, def, options, lexicons) {
|
|
|
177
162
|
const bodyParser = createBodyParser(input.encoding, options);
|
|
178
163
|
return async (req, res) => {
|
|
179
164
|
if (getBodyPresence(req) === 'missing') {
|
|
180
|
-
throw new
|
|
165
|
+
throw new InvalidRequestError(`A request body is expected but none was provided`);
|
|
181
166
|
}
|
|
182
167
|
const reqEncoding = parseReqEncoding(req);
|
|
183
168
|
if (checkEncoding && !checkEncoding(reqEncoding)) {
|
|
184
|
-
throw new
|
|
169
|
+
throw new InvalidRequestError(`Wrong request encoding (Content-Type): ${reqEncoding}`);
|
|
185
170
|
}
|
|
186
171
|
if (bodyParser) {
|
|
187
172
|
await bodyParser(req, res);
|
|
188
173
|
}
|
|
189
174
|
if (input.schema) {
|
|
190
175
|
try {
|
|
191
|
-
const lexBody = req.body ? (
|
|
176
|
+
const lexBody = req.body ? jsonToLexWithBlobRef(req.body) : req.body;
|
|
192
177
|
req.body = lexicons.assertValidXrpcInput(nsid, lexBody);
|
|
193
178
|
}
|
|
194
179
|
catch (cause) {
|
|
195
|
-
throw new
|
|
180
|
+
throw new InvalidRequestError(cause instanceof Error ? cause.message : String(cause), undefined, { cause });
|
|
196
181
|
}
|
|
197
182
|
}
|
|
198
183
|
// if middleware already got the body, we pass that along as input
|
|
@@ -201,8 +186,8 @@ function createLexiconInputVerifier(nsid, def, options, lexicons) {
|
|
|
201
186
|
return { encoding: reqEncoding, body };
|
|
202
187
|
};
|
|
203
188
|
}
|
|
204
|
-
function createSchemaInputVerifier(ns, options) {
|
|
205
|
-
const schema =
|
|
189
|
+
export function createSchemaInputVerifier(ns, options) {
|
|
190
|
+
const schema = l.getMain(ns);
|
|
206
191
|
const { blobLimit } = options;
|
|
207
192
|
const input = 'input' in schema ? schema.input : undefined;
|
|
208
193
|
if (!input?.encoding) {
|
|
@@ -210,7 +195,7 @@ function createSchemaInputVerifier(ns, options) {
|
|
|
210
195
|
return async (req) => {
|
|
211
196
|
if (getBodyPresence(req) === 'present') {
|
|
212
197
|
// @NOTE we *could* also discard the body here instead of throwing an error
|
|
213
|
-
throw new
|
|
198
|
+
throw new InvalidRequestError(`A request body was provided when none was expected`);
|
|
214
199
|
}
|
|
215
200
|
return undefined;
|
|
216
201
|
};
|
|
@@ -218,22 +203,22 @@ function createSchemaInputVerifier(ns, options) {
|
|
|
218
203
|
const bodyParser = createBodyParser(input.encoding, options);
|
|
219
204
|
return async (req, res) => {
|
|
220
205
|
if (getBodyPresence(req) === 'missing') {
|
|
221
|
-
throw new
|
|
206
|
+
throw new InvalidRequestError(`A request body is expected but none was provided`);
|
|
222
207
|
}
|
|
223
208
|
const reqEncoding = parseReqEncoding(req);
|
|
224
209
|
if (!input.matchesEncoding(reqEncoding)) {
|
|
225
|
-
throw new
|
|
210
|
+
throw new InvalidRequestError(`Wrong request encoding (Content-Type): ${reqEncoding}`);
|
|
226
211
|
}
|
|
227
212
|
if (bodyParser) {
|
|
228
213
|
await bodyParser(req, res);
|
|
229
214
|
}
|
|
230
215
|
if (input.schema) {
|
|
231
216
|
try {
|
|
232
|
-
const lexBody = req.body ?
|
|
217
|
+
const lexBody = req.body ? jsonToLex(req.body) : req.body;
|
|
233
218
|
req.body = input.schema.parse(lexBody);
|
|
234
219
|
}
|
|
235
220
|
catch (cause) {
|
|
236
|
-
throw new
|
|
221
|
+
throw new InvalidRequestError(cause instanceof Error ? cause.message : String(cause), undefined, { cause });
|
|
237
222
|
}
|
|
238
223
|
}
|
|
239
224
|
// if middleware already got the body, we pass that along as input
|
|
@@ -242,46 +227,46 @@ function createSchemaInputVerifier(ns, options) {
|
|
|
242
227
|
return { encoding: reqEncoding, body };
|
|
243
228
|
};
|
|
244
229
|
}
|
|
245
|
-
function createLexiconOutputVerifier(nsid, def, lexicons) {
|
|
230
|
+
export function createLexiconOutputVerifier(nsid, def, lexicons) {
|
|
246
231
|
const outputDef = def.output;
|
|
247
232
|
// Expects no output
|
|
248
233
|
if (!outputDef) {
|
|
249
234
|
return (handlerOutput) => {
|
|
250
235
|
if (handlerOutput !== undefined) {
|
|
251
|
-
throw new
|
|
236
|
+
throw new InternalServerError(`A response body was provided when none was expected`);
|
|
252
237
|
}
|
|
253
238
|
};
|
|
254
239
|
}
|
|
255
240
|
// An output is expected
|
|
256
241
|
return (handlerOutput) => {
|
|
257
242
|
if (handlerOutput === undefined) {
|
|
258
|
-
throw new
|
|
243
|
+
throw new InternalServerError(`A response body is expected but none was provided`);
|
|
259
244
|
}
|
|
260
245
|
if (!('encoding' in handlerOutput)) {
|
|
261
246
|
// Ensure handlerOutput is valid ErrorResult
|
|
262
247
|
if ('status' in handlerOutput && handlerOutput.status >= 400) {
|
|
263
248
|
return;
|
|
264
249
|
}
|
|
265
|
-
throw new
|
|
250
|
+
throw new InternalServerError(`Invalid handler output: missing encoding`);
|
|
266
251
|
}
|
|
267
252
|
if (!('body' in handlerOutput)) {
|
|
268
253
|
// Ensure handlerOutput is valid HandlerPipeThrough
|
|
269
254
|
if ('stream' in handlerOutput || 'buffer' in handlerOutput) {
|
|
270
255
|
return; // Validation is ignored for pipe-through outputs
|
|
271
256
|
}
|
|
272
|
-
throw new
|
|
257
|
+
throw new InternalServerError(`Invalid handler output: missing body`);
|
|
273
258
|
}
|
|
274
259
|
// Fool-proofing (should not be necessary due to type system)
|
|
275
|
-
const result =
|
|
260
|
+
const result = handlerSuccess.safeParse(handlerOutput);
|
|
276
261
|
if (!result.success) {
|
|
277
|
-
throw new
|
|
262
|
+
throw new InternalServerError(`Invalid handler output`, undefined, {
|
|
278
263
|
cause: result.reason,
|
|
279
264
|
});
|
|
280
265
|
}
|
|
281
266
|
// output mime
|
|
282
267
|
const { encoding } = handlerOutput;
|
|
283
268
|
if (!isValidEncoding(outputDef, encoding)) {
|
|
284
|
-
throw new
|
|
269
|
+
throw new InternalServerError(`Invalid response encoding: ${encoding}`);
|
|
285
270
|
}
|
|
286
271
|
// output schema
|
|
287
272
|
try {
|
|
@@ -296,41 +281,41 @@ function createLexiconOutputVerifier(nsid, def, lexicons) {
|
|
|
296
281
|
}
|
|
297
282
|
catch (cause) {
|
|
298
283
|
const message = cause instanceof Error ? cause.message : 'Output body validation failed';
|
|
299
|
-
throw new
|
|
284
|
+
throw new InternalServerError(message, undefined, { cause });
|
|
300
285
|
}
|
|
301
286
|
};
|
|
302
287
|
}
|
|
303
|
-
function createSchemaOutputVerifier(ns) {
|
|
304
|
-
const outputSchema =
|
|
288
|
+
export function createSchemaOutputVerifier(ns) {
|
|
289
|
+
const outputSchema = l.getMain(ns).output;
|
|
305
290
|
return (handlerOutput) => {
|
|
306
291
|
// @NOTE If the user of the lib wants to return an output that doesn't
|
|
307
292
|
// conform to the schema, they can use HandlerPipeThrough return types
|
|
308
293
|
if (!outputSchema.matchesEncoding(handlerOutput?.encoding)) {
|
|
309
|
-
throw new
|
|
294
|
+
throw new InternalServerError('Output encoding mismatch');
|
|
310
295
|
}
|
|
311
296
|
if (outputSchema.schema) {
|
|
312
297
|
const result = outputSchema.schema.safeValidate(handlerOutput?.body);
|
|
313
298
|
if (!result.success) {
|
|
314
|
-
throw new
|
|
299
|
+
throw new InternalServerError(result.reason.message, undefined, {
|
|
315
300
|
cause: result.reason,
|
|
316
301
|
});
|
|
317
302
|
}
|
|
318
303
|
}
|
|
319
304
|
else if (!outputSchema.encoding && handlerOutput?.body !== undefined) {
|
|
320
|
-
throw new
|
|
305
|
+
throw new InternalServerError('Output body not expected');
|
|
321
306
|
}
|
|
322
307
|
};
|
|
323
308
|
}
|
|
324
|
-
function parseReqEncoding(req) {
|
|
309
|
+
export function parseReqEncoding(req) {
|
|
325
310
|
const encoding = normalizeMime(req.headers['content-type']);
|
|
326
311
|
if (encoding)
|
|
327
312
|
return encoding;
|
|
328
|
-
throw new
|
|
313
|
+
throw new InvalidRequestError(`Request encoding (Content-Type) required but not provided`);
|
|
329
314
|
}
|
|
330
315
|
function normalizeMime(v) {
|
|
331
316
|
if (!v)
|
|
332
317
|
return null;
|
|
333
|
-
const fullType =
|
|
318
|
+
const fullType = contentType(v);
|
|
334
319
|
if (!fullType)
|
|
335
320
|
return null;
|
|
336
321
|
const shortType = fullType.split(';')[0];
|
|
@@ -382,17 +367,17 @@ function createBodyParser(inputEncoding, options) {
|
|
|
382
367
|
return;
|
|
383
368
|
}
|
|
384
369
|
const { jsonLimit, textLimit } = options;
|
|
385
|
-
const jsonParser =
|
|
386
|
-
const textParser =
|
|
370
|
+
const jsonParser = json({ limit: jsonLimit });
|
|
371
|
+
const textParser = text({ limit: textLimit });
|
|
387
372
|
// Transform json and text parser middlewares into a single function
|
|
388
373
|
return (req, res) => {
|
|
389
374
|
return new Promise((resolve, reject) => {
|
|
390
375
|
jsonParser(req, res, (err) => {
|
|
391
376
|
if (err)
|
|
392
|
-
return reject(
|
|
377
|
+
return reject(XRPCError.fromError(err));
|
|
393
378
|
textParser(req, res, (err) => {
|
|
394
379
|
if (err)
|
|
395
|
-
return reject(
|
|
380
|
+
return reject(XRPCError.fromError(err));
|
|
396
381
|
resolve();
|
|
397
382
|
});
|
|
398
383
|
});
|
|
@@ -406,29 +391,29 @@ function decodeBodyStream(req, maxSize) {
|
|
|
406
391
|
? parseInt(contentLength, 10)
|
|
407
392
|
: undefined;
|
|
408
393
|
if (Number.isNaN(contentLengthParsed)) {
|
|
409
|
-
throw new
|
|
394
|
+
throw new XRPCError(ResponseType.InvalidRequest, 'invalid content-length');
|
|
410
395
|
}
|
|
411
396
|
if (maxSize !== undefined &&
|
|
412
397
|
contentLengthParsed !== undefined &&
|
|
413
398
|
contentLengthParsed > maxSize) {
|
|
414
|
-
throw new
|
|
399
|
+
throw new XRPCError(ResponseType.PayloadTooLarge, 'request entity too large');
|
|
415
400
|
}
|
|
416
401
|
let transforms;
|
|
417
402
|
try {
|
|
418
|
-
transforms =
|
|
403
|
+
transforms = createDecoders(contentEncoding);
|
|
419
404
|
}
|
|
420
405
|
catch (cause) {
|
|
421
|
-
throw new
|
|
406
|
+
throw new XRPCError(ResponseType.UnsupportedMediaType, 'unsupported content-encoding', undefined, { cause });
|
|
422
407
|
}
|
|
423
408
|
if (maxSize !== undefined) {
|
|
424
|
-
const maxSizeChecker = new
|
|
409
|
+
const maxSizeChecker = new MaxSizeChecker(maxSize, () => new XRPCError(ResponseType.PayloadTooLarge, 'request entity too large'));
|
|
425
410
|
transforms.push(maxSizeChecker);
|
|
426
411
|
}
|
|
427
412
|
return transforms.length > 0
|
|
428
|
-
?
|
|
413
|
+
? pipeline([req, ...transforms], () => { })
|
|
429
414
|
: req;
|
|
430
415
|
}
|
|
431
|
-
function serverTimingHeader(timings) {
|
|
416
|
+
export function serverTimingHeader(timings) {
|
|
432
417
|
return timings
|
|
433
418
|
.map((timing) => {
|
|
434
419
|
let header = timing.name;
|
|
@@ -440,57 +425,32 @@ function serverTimingHeader(timings) {
|
|
|
440
425
|
})
|
|
441
426
|
.join(', ');
|
|
442
427
|
}
|
|
443
|
-
class ServerTimer {
|
|
428
|
+
export class ServerTimer {
|
|
444
429
|
constructor(name, description) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
configurable: true,
|
|
448
|
-
writable: true,
|
|
449
|
-
value: name
|
|
450
|
-
});
|
|
451
|
-
Object.defineProperty(this, "description", {
|
|
452
|
-
enumerable: true,
|
|
453
|
-
configurable: true,
|
|
454
|
-
writable: true,
|
|
455
|
-
value: description
|
|
456
|
-
});
|
|
457
|
-
Object.defineProperty(this, "duration", {
|
|
458
|
-
enumerable: true,
|
|
459
|
-
configurable: true,
|
|
460
|
-
writable: true,
|
|
461
|
-
value: void 0
|
|
462
|
-
});
|
|
463
|
-
Object.defineProperty(this, "startMs", {
|
|
464
|
-
enumerable: true,
|
|
465
|
-
configurable: true,
|
|
466
|
-
writable: true,
|
|
467
|
-
value: void 0
|
|
468
|
-
});
|
|
430
|
+
this.name = name;
|
|
431
|
+
this.description = description;
|
|
469
432
|
}
|
|
470
433
|
start() {
|
|
471
434
|
this.startMs = Date.now();
|
|
472
435
|
return this;
|
|
473
436
|
}
|
|
474
437
|
stop() {
|
|
475
|
-
(
|
|
438
|
+
assert(this.startMs, "timer hasn't been started");
|
|
476
439
|
this.duration = Date.now() - this.startMs;
|
|
477
440
|
return this;
|
|
478
441
|
}
|
|
479
442
|
}
|
|
480
|
-
|
|
481
|
-
const parseReqNsid = (req) => (0, exports.parseUrlNsid)('originalUrl' in req ? req.originalUrl : req.url || '/');
|
|
482
|
-
exports.parseReqNsid = parseReqNsid;
|
|
443
|
+
export const parseReqNsid = (req) => parseUrlNsid('originalUrl' in req ? req.originalUrl : req.url || '/');
|
|
483
444
|
/**
|
|
484
445
|
* Validates and extracts the nsid from an xrpc path
|
|
485
446
|
*/
|
|
486
|
-
const parseUrlNsid = (url) => {
|
|
487
|
-
const nsid =
|
|
447
|
+
export const parseUrlNsid = (url) => {
|
|
448
|
+
const nsid = extractUrlNsid(url);
|
|
488
449
|
if (nsid)
|
|
489
450
|
return nsid;
|
|
490
|
-
throw new
|
|
451
|
+
throw new InvalidRequestError('invalid xrpc path');
|
|
491
452
|
};
|
|
492
|
-
|
|
493
|
-
const extractUrlNsid = (url) => {
|
|
453
|
+
export const extractUrlNsid = (url) => {
|
|
494
454
|
// /!\ Hot path
|
|
495
455
|
if (
|
|
496
456
|
// Ordered by likelihood of failure
|
|
@@ -546,5 +506,4 @@ const extractUrlNsid = (url) => {
|
|
|
546
506
|
// @TODO check max length of nsid
|
|
547
507
|
return url.slice(startOfNsid, curr);
|
|
548
508
|
};
|
|
549
|
-
exports.extractUrlNsid = extractUrlNsid;
|
|
550
509
|
//# sourceMappingURL=util.js.map
|