@casual-simulation/aux-common
Version:
Common library for AUX projects
106 lines • 3.14 kB
TypeScript
import { z } from 'zod';
export type RequestScope = 'auth' | 'player';
/**
* Defines an interface for a generic HTTP request.
*/
export interface GenericHttpRequest {
/**
* The path that the HTTP request is for.
* Does not include the query string parameters.
*/
path: string;
/**
* The query string parameters.
*/
query: GenericQueryStringParameters;
/**
* The path parameters.
* i.e. These are parameters that are calculated from the path of the
*/
pathParams: GenericPathParameters;
/**
* The method that the HTTP request uses.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
*/
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS';
/**
* The headers for the request.
*/
headers: GenericHttpHeaders;
/**
* The body of the HTTP request.
*/
body: string | null;
/**
* The IP address that the request is from.
* Null if the IP address is not available.
*/
ipAddress: string | null;
/**
* The scope that the request is for.
*/
scope?: RequestScope;
}
/**
* Defines an interface for a generic HTTP response.
*/
export interface GenericHttpResponse {
/**
* The status code for the response.
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
*
*/
statusCode: number;
/**
* The list of headers to include in the response.
*/
headers?: GenericHttpHeaders;
/**
* The body of the response.
*
* If given a string, then the body will be set to that string.
* If given an AsyncIterable, then each chunk will be written to the stream as a separate chunk.
*/
body?: string | null | AsyncIterable<string>;
}
export interface GenericHttpHeaders {
[key: string]: string;
}
export interface GenericQueryStringParameters {
[key: string]: string;
}
export interface GenericPathParameters {
[key: string]: string;
}
/**
* Defines an interface for a generic Websocket request.
*/
export interface GenericWebsocketRequest {
type: 'connect' | 'disconnect' | 'message';
/**
* The ID of the connection that the server has associated with this request.
*/
connectionId: string;
/**
* The body of the websocket request.
*/
body?: string | Uint8Array | null;
/**
* The IP address of the request.
*/
ipAddress: string;
/**
* The value of the HTTP Origin header when the connection was established.
*/
origin: string;
}
export declare const genericHttpRequestSchema: z.ZodObject<{
path: z.ZodString;
pathParams: z.ZodObject<{}, z.core.$catchall<z.ZodString>>;
method: z.ZodUnion<readonly [z.ZodLiteral<"GET">, z.ZodLiteral<"POST">, z.ZodLiteral<"PUT">, z.ZodLiteral<"DELETE">, z.ZodLiteral<"HEAD">, z.ZodLiteral<"OPTIONS">]>;
query: z.ZodObject<{}, z.core.$catchall<z.ZodString>>;
headers: z.ZodObject<{}, z.core.$catchall<z.ZodString>>;
body: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
}, z.core.$strip>;
//# sourceMappingURL=GenericHttpInterface.d.ts.map