@atproto/xrpc-server 0.8.0 → 0.9.1
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 +34 -0
- package/dist/auth.js +11 -11
- package/dist/auth.js.map +1 -1
- package/dist/errors.d.ts +67 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +202 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/rate-limiter.d.ts +69 -32
- package/dist/rate-limiter.d.ts.map +1 -1
- package/dist/rate-limiter.js +58 -41
- package/dist/rate-limiter.js.map +1 -1
- package/dist/server.d.ts +19 -14
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +151 -137
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +80 -178
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -226
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +9 -8
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +148 -108
- package/dist/util.js.map +1 -1
- package/package.json +4 -3
- package/src/auth.ts +1 -1
- package/src/errors.ts +293 -0
- package/src/index.ts +9 -3
- package/src/rate-limiter.ts +188 -96
- package/src/server.ts +198 -154
- package/src/types.ts +144 -439
- package/src/util.ts +176 -125
- package/tests/auth.test.ts +2 -2
- package/tests/bodies.test.ts +18 -27
- package/tests/errors.test.ts +1 -1
- package/tests/ipld.test.ts +15 -14
- package/tests/parameters.test.ts +4 -7
- package/tests/procedures.test.ts +22 -34
- package/tests/queries.test.ts +9 -12
- package/tests/rate-limiter.test.ts +7 -7
- package/tests/responses.test.ts +12 -15
- package/tsconfig.build.tsbuildinfo +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { IncomingMessage } from 'node:http';
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
|
-
import
|
|
3
|
+
import { NextFunction, Request, Response } from 'express';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { ErrorResult, XRPCError } from './errors';
|
|
6
|
+
import { CalcKeyFn, CalcPointsFn, RateLimiterI } from './rate-limiter';
|
|
7
|
+
export type Awaitable<T> = T | Promise<T>;
|
|
8
|
+
export type CatchallHandler = (req: Request, res: Response, next: NextFunction) => unknown;
|
|
7
9
|
export type Options = {
|
|
8
10
|
validateResponse?: boolean;
|
|
9
11
|
catchall?: CatchallHandler;
|
|
10
|
-
payload?:
|
|
11
|
-
jsonLimit?: number;
|
|
12
|
-
blobLimit?: number;
|
|
13
|
-
textLimit?: number;
|
|
14
|
-
};
|
|
12
|
+
payload?: RouteOptions;
|
|
15
13
|
rateLimits?: {
|
|
16
|
-
creator: RateLimiterCreator
|
|
17
|
-
global?: ServerRateLimitDescription[];
|
|
18
|
-
shared?: ServerRateLimitDescription[];
|
|
19
|
-
bypass?: (ctx:
|
|
14
|
+
creator: RateLimiterCreator<HandlerContext>;
|
|
15
|
+
global?: ServerRateLimitDescription<HandlerContext>[];
|
|
16
|
+
shared?: ServerRateLimitDescription<HandlerContext>[];
|
|
17
|
+
bypass?: (ctx: HandlerContext) => boolean;
|
|
20
18
|
};
|
|
21
19
|
/**
|
|
22
20
|
* By default, errors are converted to {@link XRPCError} using
|
|
@@ -30,44 +28,33 @@ export type Options = {
|
|
|
30
28
|
*/
|
|
31
29
|
errorParser?: (err: unknown) => XRPCError;
|
|
32
30
|
};
|
|
33
|
-
export type UndecodedParams =
|
|
31
|
+
export type UndecodedParams = Request['query'];
|
|
34
32
|
export type Primitive = string | number | boolean;
|
|
35
|
-
export type Params =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}, "strip", z.ZodTypeAny, {
|
|
40
|
-
encoding: string;
|
|
41
|
-
body?: any;
|
|
42
|
-
}, {
|
|
33
|
+
export type Params = {
|
|
34
|
+
[P in string]?: undefined | Primitive | Primitive[];
|
|
35
|
+
};
|
|
36
|
+
export type HandlerInput = {
|
|
43
37
|
encoding: string;
|
|
44
|
-
body
|
|
45
|
-
}
|
|
46
|
-
export type
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}, "strip", z.ZodTypeAny, {
|
|
51
|
-
credentials?: any;
|
|
52
|
-
artifacts?: any;
|
|
53
|
-
}, {
|
|
54
|
-
credentials?: any;
|
|
55
|
-
artifacts?: any;
|
|
56
|
-
}>;
|
|
57
|
-
export type HandlerAuth = z.infer<typeof handlerAuth>;
|
|
38
|
+
body: unknown;
|
|
39
|
+
};
|
|
40
|
+
export type AuthResult = {
|
|
41
|
+
credentials: unknown;
|
|
42
|
+
artifacts?: unknown;
|
|
43
|
+
};
|
|
58
44
|
export declare const headersSchema: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
45
|
+
export type Headers = z.infer<typeof headersSchema>;
|
|
59
46
|
export declare const handlerSuccess: z.ZodObject<{
|
|
60
47
|
encoding: z.ZodString;
|
|
61
48
|
body: z.ZodAny;
|
|
62
49
|
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
63
50
|
}, "strip", z.ZodTypeAny, {
|
|
64
51
|
encoding: string;
|
|
65
|
-
body?: any;
|
|
66
52
|
headers?: Record<string, string> | undefined;
|
|
53
|
+
body?: any;
|
|
67
54
|
}, {
|
|
68
55
|
encoding: string;
|
|
69
|
-
body?: any;
|
|
70
56
|
headers?: Record<string, string> | undefined;
|
|
57
|
+
body?: any;
|
|
71
58
|
}>;
|
|
72
59
|
export type HandlerSuccess = z.infer<typeof handlerSuccess>;
|
|
73
60
|
export declare const handlerPipeThroughBuffer: z.ZodObject<{
|
|
@@ -124,163 +111,78 @@ export declare const handlerPipeThrough: z.ZodUnion<[z.ZodObject<{
|
|
|
124
111
|
headers?: Record<string, string> | undefined;
|
|
125
112
|
}>]>;
|
|
126
113
|
export type HandlerPipeThrough = z.infer<typeof handlerPipeThrough>;
|
|
127
|
-
export
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}, {
|
|
136
|
-
status: number;
|
|
137
|
-
message?: string | undefined;
|
|
138
|
-
error?: string | undefined;
|
|
139
|
-
}>;
|
|
140
|
-
export type HandlerError = z.infer<typeof handlerError>;
|
|
141
|
-
export type HandlerOutput = HandlerSuccess | HandlerPipeThrough | HandlerError;
|
|
142
|
-
export type XRPCReqContext = {
|
|
143
|
-
auth: HandlerAuth | undefined;
|
|
144
|
-
params: Params;
|
|
145
|
-
input: HandlerInput | undefined;
|
|
146
|
-
req: express.Request;
|
|
147
|
-
res: express.Response;
|
|
148
|
-
resetRouteRateLimits: () => Promise<void>;
|
|
114
|
+
export type Auth = void | AuthResult;
|
|
115
|
+
export type Input = void | HandlerInput;
|
|
116
|
+
export type Output = void | HandlerSuccess | ErrorResult;
|
|
117
|
+
export type AuthVerifier<C, A extends AuthResult = AuthResult> = ((ctx: C) => Awaitable<A | ErrorResult>) | ((ctx: C) => Awaitable<A>);
|
|
118
|
+
export type MethodAuthContext<P extends Params = Params> = {
|
|
119
|
+
params: P;
|
|
120
|
+
req: Request;
|
|
121
|
+
res: Response;
|
|
149
122
|
};
|
|
150
|
-
export type
|
|
151
|
-
export type
|
|
152
|
-
auth:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
signal: AbortSignal;
|
|
156
|
-
}) => AsyncIterable<unknown>;
|
|
157
|
-
export type AuthOutput = HandlerAuth | HandlerError;
|
|
158
|
-
export interface AuthVerifierContext {
|
|
159
|
-
req: express.Request;
|
|
160
|
-
res: express.Response;
|
|
161
|
-
}
|
|
162
|
-
export type AuthVerifier = (ctx: AuthVerifierContext) => Promise<AuthOutput> | AuthOutput;
|
|
163
|
-
export interface StreamAuthVerifierContext {
|
|
164
|
-
req: IncomingMessage;
|
|
165
|
-
}
|
|
166
|
-
export type StreamAuthVerifier = (ctx: StreamAuthVerifierContext) => Promise<AuthOutput> | AuthOutput;
|
|
167
|
-
export type CalcKeyFn = (ctx: XRPCReqContext) => string | null;
|
|
168
|
-
export type CalcPointsFn = (ctx: XRPCReqContext) => number;
|
|
169
|
-
export interface RateLimiterI {
|
|
170
|
-
consume: RateLimiterConsume;
|
|
171
|
-
reset: RateLimiterReset;
|
|
172
|
-
}
|
|
173
|
-
export type RateLimiterConsumeOptions = {
|
|
174
|
-
calcKey?: CalcKeyFn;
|
|
175
|
-
calcPoints?: CalcPointsFn;
|
|
176
|
-
};
|
|
177
|
-
export type RateLimiterConsume = (ctx: XRPCReqContext, opts?: RateLimiterConsumeOptions) => Promise<RateLimiterStatus | RateLimitExceededError | null>;
|
|
178
|
-
export type RateLimiterResetOptions = {
|
|
179
|
-
calcKey?: CalcKeyFn;
|
|
123
|
+
export type MethodAuthVerifier<A extends AuthResult = AuthResult, P extends Params = Params> = AuthVerifier<MethodAuthContext<P>, A>;
|
|
124
|
+
export type HandlerContext<A extends Auth = Auth, P extends Params = Params, I extends Input = Input> = MethodAuthContext<P> & {
|
|
125
|
+
auth: A;
|
|
126
|
+
input: I;
|
|
127
|
+
resetRouteRateLimits: () => Promise<void>;
|
|
180
128
|
};
|
|
181
|
-
export type
|
|
182
|
-
export type RateLimiterCreator = (opts: {
|
|
129
|
+
export type MethodHandler<A extends Auth = Auth, P extends Params = Params, I extends Input = Input, O extends Output = Output> = (ctx: HandlerContext<A, P, I>) => Awaitable<O | HandlerPipeThrough>;
|
|
130
|
+
export type RateLimiterCreator<T extends HandlerContext = HandlerContext> = <C extends T = T>(opts: {
|
|
183
131
|
keyPrefix: string;
|
|
184
132
|
durationMs: number;
|
|
185
133
|
points: number;
|
|
186
|
-
calcKey
|
|
187
|
-
calcPoints
|
|
188
|
-
|
|
189
|
-
|
|
134
|
+
calcKey: CalcKeyFn<C>;
|
|
135
|
+
calcPoints: CalcPointsFn<C>;
|
|
136
|
+
failClosed?: boolean;
|
|
137
|
+
}) => RateLimiterI<C>;
|
|
138
|
+
export type ServerRateLimitDescription<C extends HandlerContext = HandlerContext> = {
|
|
190
139
|
name: string;
|
|
191
140
|
durationMs: number;
|
|
192
141
|
points: number;
|
|
193
|
-
calcKey?: CalcKeyFn
|
|
194
|
-
calcPoints?: CalcPointsFn
|
|
142
|
+
calcKey?: CalcKeyFn<C>;
|
|
143
|
+
calcPoints?: CalcPointsFn<C>;
|
|
144
|
+
failClosed?: boolean;
|
|
195
145
|
};
|
|
196
|
-
export type SharedRateLimitOpts = {
|
|
146
|
+
export type SharedRateLimitOpts<C extends HandlerContext = HandlerContext> = {
|
|
197
147
|
name: string;
|
|
198
|
-
calcKey?: CalcKeyFn
|
|
199
|
-
calcPoints?: CalcPointsFn
|
|
148
|
+
calcKey?: CalcKeyFn<C>;
|
|
149
|
+
calcPoints?: CalcPointsFn<C>;
|
|
200
150
|
};
|
|
201
|
-
export type RouteRateLimitOpts = {
|
|
151
|
+
export type RouteRateLimitOpts<C extends HandlerContext = HandlerContext> = {
|
|
202
152
|
durationMs: number;
|
|
203
153
|
points: number;
|
|
204
|
-
calcKey?: CalcKeyFn
|
|
205
|
-
calcPoints?: CalcPointsFn
|
|
154
|
+
calcKey?: CalcKeyFn<C>;
|
|
155
|
+
calcPoints?: CalcPointsFn<C>;
|
|
206
156
|
};
|
|
207
|
-
export type
|
|
208
|
-
export declare
|
|
209
|
-
export type
|
|
210
|
-
limit: number;
|
|
211
|
-
duration: number;
|
|
212
|
-
remainingPoints: number;
|
|
213
|
-
msBeforeNext: number;
|
|
214
|
-
consumedPoints: number;
|
|
215
|
-
isFirstInDuration: boolean;
|
|
216
|
-
};
|
|
217
|
-
export type RouteOpts = {
|
|
157
|
+
export type RateLimitOpts<C extends HandlerContext = HandlerContext> = SharedRateLimitOpts<C> | RouteRateLimitOpts<C>;
|
|
158
|
+
export declare function isSharedRateLimitOpts<C extends HandlerContext = HandlerContext>(opts: RateLimitOpts<C>): opts is SharedRateLimitOpts<C>;
|
|
159
|
+
export type RouteOptions = {
|
|
218
160
|
blobLimit?: number;
|
|
161
|
+
jsonLimit?: number;
|
|
162
|
+
textLimit?: number;
|
|
163
|
+
};
|
|
164
|
+
export type MethodConfig<A extends Auth = Auth, P extends Params = Params, I extends Input = Input, O extends Output = Output> = {
|
|
165
|
+
handler: MethodHandler<A, P, I, O>;
|
|
166
|
+
auth?: MethodAuthVerifier<Extract<A, AuthResult>, P>;
|
|
167
|
+
opts?: RouteOptions;
|
|
168
|
+
rateLimit?: RateLimitOpts<HandlerContext<A, P, I>> | RateLimitOpts<HandlerContext<A, P, I>>[];
|
|
219
169
|
};
|
|
220
|
-
export type
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
170
|
+
export type MethodConfigOrHandler<A extends Auth = Auth, P extends Params = Params, I extends Input = Input, O extends Output = Output> = MethodHandler<A, P, I, O> | MethodConfig<A, P, I, O>;
|
|
171
|
+
export type StreamAuthContext<P extends Params = Params> = {
|
|
172
|
+
params: P;
|
|
173
|
+
req: IncomingMessage;
|
|
174
|
+
};
|
|
175
|
+
export type StreamAuthVerifier<A extends AuthResult = AuthResult, P extends Params = Params> = AuthVerifier<StreamAuthContext<P>, A>;
|
|
176
|
+
export type StreamContext<A extends Auth = Auth, P extends Params = Params> = StreamAuthContext<P> & {
|
|
177
|
+
auth: A;
|
|
178
|
+
signal: AbortSignal;
|
|
225
179
|
};
|
|
226
|
-
export type
|
|
227
|
-
|
|
228
|
-
|
|
180
|
+
export type StreamHandler<A extends Auth = Auth, P extends Params = Params, O = unknown> = (ctx: StreamContext<A, P>) => AsyncIterable<O>;
|
|
181
|
+
export type StreamConfig<A extends Auth = Auth, P extends Params = Params, O = unknown> = {
|
|
182
|
+
auth?: StreamAuthVerifier<Extract<A, AuthResult>, P>;
|
|
183
|
+
handler: StreamHandler<A, P, O>;
|
|
229
184
|
};
|
|
230
|
-
export
|
|
231
|
-
export declare
|
|
232
|
-
|
|
233
|
-
errorMessage?: string | undefined;
|
|
234
|
-
customErrorName?: string | undefined;
|
|
235
|
-
constructor(type: ResponseType, errorMessage?: string | undefined, customErrorName?: string | undefined, options?: ErrorOptions);
|
|
236
|
-
get statusCode(): number;
|
|
237
|
-
get payload(): {
|
|
238
|
-
error: string | undefined;
|
|
239
|
-
message: string | undefined;
|
|
240
|
-
};
|
|
241
|
-
get typeName(): string | undefined;
|
|
242
|
-
get typeStr(): string | undefined;
|
|
243
|
-
static fromError(cause: unknown): XRPCError;
|
|
244
|
-
static fromHandlerError(err: HandlerError): XRPCError;
|
|
245
|
-
}
|
|
246
|
-
export declare function isHandlerError(v: unknown): v is HandlerError;
|
|
247
|
-
export declare function isHandlerPipeThroughBuffer(v: HandlerOutput): v is HandlerPipeThroughBuffer;
|
|
248
|
-
export declare function isHandlerPipeThroughStream(v: HandlerOutput): v is HandlerPipeThroughStream;
|
|
249
|
-
export declare class InvalidRequestError extends XRPCError {
|
|
250
|
-
constructor(errorMessage?: string, customErrorName?: string, options?: ErrorOptions);
|
|
251
|
-
[Symbol.hasInstance](instance: unknown): boolean;
|
|
252
|
-
}
|
|
253
|
-
export declare class AuthRequiredError extends XRPCError {
|
|
254
|
-
constructor(errorMessage?: string, customErrorName?: string, options?: ErrorOptions);
|
|
255
|
-
[Symbol.hasInstance](instance: unknown): boolean;
|
|
256
|
-
}
|
|
257
|
-
export declare class ForbiddenError extends XRPCError {
|
|
258
|
-
constructor(errorMessage?: string, customErrorName?: string, options?: ErrorOptions);
|
|
259
|
-
[Symbol.hasInstance](instance: unknown): boolean;
|
|
260
|
-
}
|
|
261
|
-
export declare class RateLimitExceededError extends XRPCError {
|
|
262
|
-
status: RateLimiterStatus;
|
|
263
|
-
constructor(status: RateLimiterStatus, errorMessage?: string, customErrorName?: string, options?: ErrorOptions);
|
|
264
|
-
[Symbol.hasInstance](instance: unknown): boolean;
|
|
265
|
-
}
|
|
266
|
-
export declare class InternalServerError extends XRPCError {
|
|
267
|
-
constructor(errorMessage?: string, customErrorName?: string, options?: ErrorOptions);
|
|
268
|
-
[Symbol.hasInstance](instance: unknown): boolean;
|
|
269
|
-
}
|
|
270
|
-
export declare class UpstreamFailureError extends XRPCError {
|
|
271
|
-
constructor(errorMessage?: string, customErrorName?: string, options?: ErrorOptions);
|
|
272
|
-
[Symbol.hasInstance](instance: unknown): boolean;
|
|
273
|
-
}
|
|
274
|
-
export declare class NotEnoughResourcesError extends XRPCError {
|
|
275
|
-
constructor(errorMessage?: string, customErrorName?: string, options?: ErrorOptions);
|
|
276
|
-
[Symbol.hasInstance](instance: unknown): boolean;
|
|
277
|
-
}
|
|
278
|
-
export declare class UpstreamTimeoutError extends XRPCError {
|
|
279
|
-
constructor(errorMessage?: string, customErrorName?: string, options?: ErrorOptions);
|
|
280
|
-
[Symbol.hasInstance](instance: unknown): boolean;
|
|
281
|
-
}
|
|
282
|
-
export declare class MethodNotImplementedError extends XRPCError {
|
|
283
|
-
constructor(errorMessage?: string, customErrorName?: string, options?: ErrorOptions);
|
|
284
|
-
[Symbol.hasInstance](instance: unknown): boolean;
|
|
285
|
-
}
|
|
185
|
+
export type StreamConfigOrHandler<A extends Auth = Auth, P extends Params = Params, O = unknown> = StreamHandler<A, P, O> | StreamConfig<A, P, O>;
|
|
186
|
+
export declare function isHandlerPipeThroughBuffer(output: Output): output is HandlerPipeThroughBuffer;
|
|
187
|
+
export declare function isHandlerPipeThroughStream(output: Output): output is HandlerPipeThroughStream;
|
|
286
188
|
//# sourceMappingURL=types.d.ts.map
|
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,OAAO,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings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AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,GACb,MAAM,IAAI,wBAAwB,CAGpC"}
|
package/dist/types.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.handlerPipeThrough = exports.handlerPipeThroughStream = exports.handlerPipeThroughBuffer = exports.handlerSuccess = exports.headersSchema = void 0;
|
|
4
|
+
exports.isSharedRateLimitOpts = isSharedRateLimitOpts;
|
|
5
5
|
exports.isHandlerPipeThroughBuffer = isHandlerPipeThroughBuffer;
|
|
6
6
|
exports.isHandlerPipeThroughStream = isHandlerPipeThroughStream;
|
|
7
7
|
const node_stream_1 = require("node:stream");
|
|
8
|
-
const http_errors_1 = require("http-errors");
|
|
9
8
|
const zod_1 = require("zod");
|
|
10
|
-
const xrpc_1 = require("@atproto/xrpc");
|
|
11
|
-
Object.defineProperty(exports, "ResponseType", { enumerable: true, get: function () { return xrpc_1.ResponseType; } });
|
|
12
|
-
exports.handlerInput = zod_1.z.object({
|
|
13
|
-
encoding: zod_1.z.string(),
|
|
14
|
-
body: zod_1.z.any(),
|
|
15
|
-
});
|
|
16
|
-
exports.handlerAuth = zod_1.z.object({
|
|
17
|
-
credentials: zod_1.z.any(),
|
|
18
|
-
artifacts: zod_1.z.any(),
|
|
19
|
-
});
|
|
20
9
|
exports.headersSchema = zod_1.z.record(zod_1.z.string());
|
|
21
10
|
exports.handlerSuccess = zod_1.z.object({
|
|
22
11
|
encoding: zod_1.z.string(),
|
|
@@ -37,221 +26,15 @@ exports.handlerPipeThrough = zod_1.z.union([
|
|
|
37
26
|
exports.handlerPipeThroughBuffer,
|
|
38
27
|
exports.handlerPipeThroughStream,
|
|
39
28
|
]);
|
|
40
|
-
|
|
41
|
-
status: zod_1.z.number(),
|
|
42
|
-
error: zod_1.z.string().optional(),
|
|
43
|
-
message: zod_1.z.string().optional(),
|
|
44
|
-
});
|
|
45
|
-
const isShared = (opts) => {
|
|
29
|
+
function isSharedRateLimitOpts(opts) {
|
|
46
30
|
return typeof opts['name'] === 'string';
|
|
47
|
-
};
|
|
48
|
-
exports.isShared = isShared;
|
|
49
|
-
/**
|
|
50
|
-
* Converts an upstream XRPC {@link ResponseType} into a downstream {@link ResponseType}.
|
|
51
|
-
*/
|
|
52
|
-
function mapFromClientError(error) {
|
|
53
|
-
switch (error.status) {
|
|
54
|
-
case xrpc_1.ResponseType.InvalidResponse:
|
|
55
|
-
// Upstream server returned an XRPC response that is not compatible with our internal lexicon definitions for that XRPC method.
|
|
56
|
-
// @NOTE This could be reflected as both a 500 ("we" are at fault) and 502 ("they" are at fault). Let's be gents about it.
|
|
57
|
-
return {
|
|
58
|
-
error: (0, xrpc_1.httpResponseCodeToName)(xrpc_1.ResponseType.InternalServerError),
|
|
59
|
-
message: (0, xrpc_1.httpResponseCodeToString)(xrpc_1.ResponseType.InternalServerError),
|
|
60
|
-
type: xrpc_1.ResponseType.InternalServerError,
|
|
61
|
-
};
|
|
62
|
-
case xrpc_1.ResponseType.Unknown:
|
|
63
|
-
// Typically a network error / unknown host
|
|
64
|
-
return {
|
|
65
|
-
error: (0, xrpc_1.httpResponseCodeToName)(xrpc_1.ResponseType.InternalServerError),
|
|
66
|
-
message: (0, xrpc_1.httpResponseCodeToString)(xrpc_1.ResponseType.InternalServerError),
|
|
67
|
-
type: xrpc_1.ResponseType.InternalServerError,
|
|
68
|
-
};
|
|
69
|
-
default:
|
|
70
|
-
return {
|
|
71
|
-
error: error.error,
|
|
72
|
-
message: error.message,
|
|
73
|
-
type: error.status,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
class XRPCError extends Error {
|
|
78
|
-
constructor(type, errorMessage, customErrorName, options) {
|
|
79
|
-
super(errorMessage, options);
|
|
80
|
-
Object.defineProperty(this, "type", {
|
|
81
|
-
enumerable: true,
|
|
82
|
-
configurable: true,
|
|
83
|
-
writable: true,
|
|
84
|
-
value: type
|
|
85
|
-
});
|
|
86
|
-
Object.defineProperty(this, "errorMessage", {
|
|
87
|
-
enumerable: true,
|
|
88
|
-
configurable: true,
|
|
89
|
-
writable: true,
|
|
90
|
-
value: errorMessage
|
|
91
|
-
});
|
|
92
|
-
Object.defineProperty(this, "customErrorName", {
|
|
93
|
-
enumerable: true,
|
|
94
|
-
configurable: true,
|
|
95
|
-
writable: true,
|
|
96
|
-
value: customErrorName
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
get statusCode() {
|
|
100
|
-
const { type } = this;
|
|
101
|
-
// Fool-proofing. `new XRPCError(123.5 as number, '')` does not generate a TypeScript error.
|
|
102
|
-
// Because of this, we can end-up with any numeric value instead of an actual `ResponseType`.
|
|
103
|
-
// For legacy reasons, the `type` argument is not checked in the constructor, so we check it here.
|
|
104
|
-
if (type < 400 || type >= 600 || !Number.isFinite(type)) {
|
|
105
|
-
return 500;
|
|
106
|
-
}
|
|
107
|
-
return type;
|
|
108
|
-
}
|
|
109
|
-
get payload() {
|
|
110
|
-
return {
|
|
111
|
-
error: this.customErrorName ?? this.typeName,
|
|
112
|
-
message: this.type === xrpc_1.ResponseType.InternalServerError
|
|
113
|
-
? this.typeStr // Do not respond with error details for 500s
|
|
114
|
-
: this.errorMessage || this.typeStr,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
get typeName() {
|
|
118
|
-
return xrpc_1.ResponseType[this.type];
|
|
119
|
-
}
|
|
120
|
-
get typeStr() {
|
|
121
|
-
return xrpc_1.ResponseTypeStrings[this.type];
|
|
122
|
-
}
|
|
123
|
-
static fromError(cause) {
|
|
124
|
-
if (cause instanceof XRPCError) {
|
|
125
|
-
return cause;
|
|
126
|
-
}
|
|
127
|
-
if (cause instanceof xrpc_1.XRPCError) {
|
|
128
|
-
const { error, message, type } = mapFromClientError(cause);
|
|
129
|
-
return new XRPCError(type, message, error, { cause });
|
|
130
|
-
}
|
|
131
|
-
if ((0, http_errors_1.isHttpError)(cause)) {
|
|
132
|
-
return new XRPCError(cause.status, cause.message, cause.name, { cause });
|
|
133
|
-
}
|
|
134
|
-
if (isHandlerError(cause)) {
|
|
135
|
-
return this.fromHandlerError(cause);
|
|
136
|
-
}
|
|
137
|
-
if (cause instanceof Error) {
|
|
138
|
-
return new InternalServerError(cause.message, undefined, { cause });
|
|
139
|
-
}
|
|
140
|
-
return new InternalServerError('Unexpected internal server error', undefined, { cause });
|
|
141
|
-
}
|
|
142
|
-
static fromHandlerError(err) {
|
|
143
|
-
return new XRPCError(err.status, err.message, err.error, { cause: err });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
exports.XRPCError = XRPCError;
|
|
147
|
-
function isHandlerError(v) {
|
|
148
|
-
return (!!v &&
|
|
149
|
-
typeof v === 'object' &&
|
|
150
|
-
typeof v['status'] === 'number' &&
|
|
151
|
-
(v['error'] === undefined || typeof v['error'] === 'string') &&
|
|
152
|
-
(v['message'] === undefined || typeof v['message'] === 'string'));
|
|
153
|
-
}
|
|
154
|
-
function isHandlerPipeThroughBuffer(v) {
|
|
155
|
-
// We only need to discriminate between possible HandlerOutput values
|
|
156
|
-
return v['buffer'] !== undefined;
|
|
157
|
-
}
|
|
158
|
-
function isHandlerPipeThroughStream(v) {
|
|
159
|
-
// We only need to discriminate between possible HandlerOutput values
|
|
160
|
-
return v['stream'] !== undefined;
|
|
161
|
-
}
|
|
162
|
-
class InvalidRequestError extends XRPCError {
|
|
163
|
-
constructor(errorMessage, customErrorName, options) {
|
|
164
|
-
super(xrpc_1.ResponseType.InvalidRequest, errorMessage, customErrorName, options);
|
|
165
|
-
}
|
|
166
|
-
[Symbol.hasInstance](instance) {
|
|
167
|
-
return (instance instanceof XRPCError &&
|
|
168
|
-
instance.type === xrpc_1.ResponseType.InvalidRequest);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
exports.InvalidRequestError = InvalidRequestError;
|
|
172
|
-
class AuthRequiredError extends XRPCError {
|
|
173
|
-
constructor(errorMessage, customErrorName, options) {
|
|
174
|
-
super(xrpc_1.ResponseType.AuthenticationRequired, errorMessage, customErrorName, options);
|
|
175
|
-
}
|
|
176
|
-
[Symbol.hasInstance](instance) {
|
|
177
|
-
return (instance instanceof XRPCError &&
|
|
178
|
-
instance.type === xrpc_1.ResponseType.AuthenticationRequired);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
exports.AuthRequiredError = AuthRequiredError;
|
|
182
|
-
class ForbiddenError extends XRPCError {
|
|
183
|
-
constructor(errorMessage, customErrorName, options) {
|
|
184
|
-
super(xrpc_1.ResponseType.Forbidden, errorMessage, customErrorName, options);
|
|
185
|
-
}
|
|
186
|
-
[Symbol.hasInstance](instance) {
|
|
187
|
-
return (instance instanceof XRPCError && instance.type === xrpc_1.ResponseType.Forbidden);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
exports.ForbiddenError = ForbiddenError;
|
|
191
|
-
class RateLimitExceededError extends XRPCError {
|
|
192
|
-
constructor(status, errorMessage, customErrorName, options) {
|
|
193
|
-
super(xrpc_1.ResponseType.RateLimitExceeded, errorMessage, customErrorName, options);
|
|
194
|
-
Object.defineProperty(this, "status", {
|
|
195
|
-
enumerable: true,
|
|
196
|
-
configurable: true,
|
|
197
|
-
writable: true,
|
|
198
|
-
value: status
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
[Symbol.hasInstance](instance) {
|
|
202
|
-
return (instance instanceof XRPCError &&
|
|
203
|
-
instance.type === xrpc_1.ResponseType.RateLimitExceeded);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
exports.RateLimitExceededError = RateLimitExceededError;
|
|
207
|
-
class InternalServerError extends XRPCError {
|
|
208
|
-
constructor(errorMessage, customErrorName, options) {
|
|
209
|
-
super(xrpc_1.ResponseType.InternalServerError, errorMessage, customErrorName, options);
|
|
210
|
-
}
|
|
211
|
-
[Symbol.hasInstance](instance) {
|
|
212
|
-
return (instance instanceof XRPCError &&
|
|
213
|
-
instance.type === xrpc_1.ResponseType.InternalServerError);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
exports.InternalServerError = InternalServerError;
|
|
217
|
-
class UpstreamFailureError extends XRPCError {
|
|
218
|
-
constructor(errorMessage, customErrorName, options) {
|
|
219
|
-
super(xrpc_1.ResponseType.UpstreamFailure, errorMessage, customErrorName, options);
|
|
220
|
-
}
|
|
221
|
-
[Symbol.hasInstance](instance) {
|
|
222
|
-
return (instance instanceof XRPCError &&
|
|
223
|
-
instance.type === xrpc_1.ResponseType.UpstreamFailure);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
exports.UpstreamFailureError = UpstreamFailureError;
|
|
227
|
-
class NotEnoughResourcesError extends XRPCError {
|
|
228
|
-
constructor(errorMessage, customErrorName, options) {
|
|
229
|
-
super(xrpc_1.ResponseType.NotEnoughResources, errorMessage, customErrorName, options);
|
|
230
|
-
}
|
|
231
|
-
[Symbol.hasInstance](instance) {
|
|
232
|
-
return (instance instanceof XRPCError &&
|
|
233
|
-
instance.type === xrpc_1.ResponseType.NotEnoughResources);
|
|
234
|
-
}
|
|
235
31
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
super(xrpc_1.ResponseType.UpstreamTimeout, errorMessage, customErrorName, options);
|
|
240
|
-
}
|
|
241
|
-
[Symbol.hasInstance](instance) {
|
|
242
|
-
return (instance instanceof XRPCError &&
|
|
243
|
-
instance.type === xrpc_1.ResponseType.UpstreamTimeout);
|
|
244
|
-
}
|
|
32
|
+
function isHandlerPipeThroughBuffer(output) {
|
|
33
|
+
// We only need to discriminate between possible Output values
|
|
34
|
+
return output != null && 'buffer' in output && output['buffer'] !== undefined;
|
|
245
35
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
super(xrpc_1.ResponseType.MethodNotImplemented, errorMessage, customErrorName, options);
|
|
250
|
-
}
|
|
251
|
-
[Symbol.hasInstance](instance) {
|
|
252
|
-
return (instance instanceof XRPCError &&
|
|
253
|
-
instance.type === xrpc_1.ResponseType.MethodNotImplemented);
|
|
254
|
-
}
|
|
36
|
+
function isHandlerPipeThroughStream(output) {
|
|
37
|
+
// We only need to discriminate between possible Output values
|
|
38
|
+
return output != null && 'stream' in output && output['stream'] !== undefined;
|
|
255
39
|
}
|
|
256
|
-
exports.MethodNotImplementedError = MethodNotImplementedError;
|
|
257
40
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAmKA,sDAIC;AAoED,gEAKC;AAED,gEAKC;AAtPD,6CAAsC;AAEtC,6BAAuB;AAkDV,QAAA,aAAa,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAA;AAIpC,QAAA,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;IACrC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,IAAI,EAAE,OAAC,CAAC,GAAG,EAAE;IACb,OAAO,EAAE,qBAAa,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAA;AAIW,QAAA,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,MAAM,EAAE,OAAC,CAAC,UAAU,CAAC,MAAM,CAAC;IAC5B,OAAO,EAAE,qBAAa,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAA;AAIW,QAAA,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,MAAM,EAAE,OAAC,CAAC,UAAU,CAAC,sBAAQ,CAAC;IAC9B,OAAO,EAAE,qBAAa,CAAC,QAAQ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