transit-kit 0.7.0 → 0.7.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/dist/generator/generateOpenApi.d.ts +4 -4
- package/dist/generator/generateOpenApi.js +2 -2
- package/dist/generator/generateOpenApi.spec.js +2 -2
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/index.js +1 -1
- package/dist/server/handlers/api/ApiEndpoint.d.ts +4 -4
- package/dist/server/handlers/api/EndpointDefinition.d.ts +3 -3
- package/dist/server/handlers/api/EndpointHandler.d.ts +2 -2
- package/dist/server/handlers/api/HandlerFromDefinition.d.ts +6 -6
- package/dist/server/handlers/api/createApiHandler.d.ts +9 -9
- package/dist/server/handlers/api/createApiHandler.spec.js +3 -3
- package/dist/server/handlers/api/responses/index.d.ts +2 -2
- package/dist/server/handlers/api/responses/jsonResponse.d.ts +1 -1
- package/dist/server/index.d.ts +4 -4
- package/dist/server/index.js +4 -4
- package/dist/server/middleware/auth.d.ts +1 -1
- package/dist/server/middleware/auth.js +2 -2
- package/dist/server/middleware/logging.d.ts +1 -1
- package/dist/server/middleware/logging.js +1 -1
- package/dist/server/middleware/validation.js +1 -1
- package/dist/server/security/SecuritySchema.d.ts +2 -2
- package/dist/server/security/SecuritySchema.js +2 -2
- package/dist/server/security/basicAuth.js +1 -1
- package/dist/server/security/basicAuth.spec.js +5 -5
- package/dist/server/server.d.ts +3 -3
- package/dist/server/server.js +7 -7
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { HttpMethod } from "../server/constants/HttpMethods";
|
|
2
|
-
import { ApiEndpointDefinition } from "../server/handlers/api/EndpointDefinition";
|
|
3
|
-
import { GenericResponseSchemaMap } from "../server/handlers/api/responses";
|
|
1
|
+
import { HttpMethod } from "../server/constants/HttpMethods.js";
|
|
2
|
+
import { ApiEndpointDefinition } from "../server/handlers/api/EndpointDefinition.js";
|
|
3
|
+
import { GenericResponseSchemaMap } from "../server/handlers/api/responses/index.js";
|
|
4
4
|
import { ZodType } from "zod";
|
|
5
5
|
import { OpenAPIV3 } from "openapi-types";
|
|
6
|
-
import { Server } from "../server";
|
|
6
|
+
import { Server } from "../server/server.js";
|
|
7
7
|
declare function translateToOpenAPIPathItem(definition: ApiEndpointDefinition<string, HttpMethod, ZodType | undefined, ZodType | undefined, GenericResponseSchemaMap>): [string, OpenAPIV3.PathItemObject];
|
|
8
8
|
interface GeneratorOptions {
|
|
9
9
|
title: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { hasValue } from "../server/utils/typeGuards";
|
|
3
|
-
import { isJsonResponseSchema } from "../server/handlers/api/responses/jsonResponse";
|
|
2
|
+
import { hasValue } from "../server/utils/typeGuards.js";
|
|
3
|
+
import { isJsonResponseSchema } from "../server/handlers/api/responses/jsonResponse.js";
|
|
4
4
|
function extractPathAndParameters(path) {
|
|
5
5
|
const parameters = path.match(/:([a-zA-Z0-9_]+)/g)?.map((param) => {
|
|
6
6
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import z from "zod";
|
|
3
|
-
import { createApiEndpointHandler } from "../server";
|
|
4
|
-
import { __TEST_EXPORTS } from "./generateOpenApi";
|
|
3
|
+
import { createApiEndpointHandler } from "../server/handlers/api/createApiHandler.js";
|
|
4
|
+
import { __TEST_EXPORTS } from "./generateOpenApi.js";
|
|
5
5
|
const { translateToOpenAPIPathItem } = __TEST_EXPORTS;
|
|
6
6
|
describe("translateToOpenAPIPathItem", () => {
|
|
7
7
|
it("should translate endpoint definitions to OpenAPI path items", () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { generateOpenApiDoc } from "./generateOpenApi";
|
|
1
|
+
export { generateOpenApiDoc } from "./generateOpenApi.js";
|
package/dist/generator/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { generateOpenApiDoc } from "./generateOpenApi";
|
|
1
|
+
export { generateOpenApiDoc } from "./generateOpenApi.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { HttpMethod } from "../../constants/HttpMethods";
|
|
3
|
-
import { ApiEndpointDefinition } from "./EndpointDefinition";
|
|
4
|
-
import { HandlerForDefinition } from "./HandlerFromDefinition";
|
|
5
|
-
import { GenericResponseSchemaMap } from "./responses";
|
|
2
|
+
import { HttpMethod } from "../../constants/HttpMethods.js";
|
|
3
|
+
import { ApiEndpointDefinition } from "./EndpointDefinition.js";
|
|
4
|
+
import { HandlerForDefinition } from "./HandlerFromDefinition.js";
|
|
5
|
+
import { GenericResponseSchemaMap } from "./responses/index.js";
|
|
6
6
|
export interface ApiEndpoint<Path extends string = string, Method extends HttpMethod = HttpMethod, RequestBody extends z.ZodType | undefined = undefined | z.ZodType, Query extends z.ZodType | undefined = undefined | z.ZodType, ResponseMap extends GenericResponseSchemaMap = GenericResponseSchemaMap, Handler extends HandlerForDefinition<Path, RequestBody, Query, ResponseMap> = HandlerForDefinition<Path, RequestBody, Query, ResponseMap>> {
|
|
7
7
|
definition: ApiEndpointDefinition<Path, Method, RequestBody, Query, ResponseMap>;
|
|
8
8
|
handler: Handler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { HttpMethod } from "../../constants/HttpMethods";
|
|
3
|
-
import { SecurityScheme } from "../../security/SecuritySchema";
|
|
4
|
-
import { GenericResponseSchemaMap } from "./responses/index";
|
|
2
|
+
import { HttpMethod } from "../../constants/HttpMethods.js";
|
|
3
|
+
import { SecurityScheme } from "../../security/SecuritySchema.js";
|
|
4
|
+
import { GenericResponseSchemaMap } from "./responses/index.js";
|
|
5
5
|
export interface ApiEndpointMeta {
|
|
6
6
|
name: string;
|
|
7
7
|
group: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Request, Response } from "express";
|
|
2
|
-
import { HttpStatusCode } from "../../constants/HttpStatusCodes";
|
|
3
|
-
import { HandlerResponse } from "./responses";
|
|
2
|
+
import { HttpStatusCode } from "../../constants/HttpStatusCodes.js";
|
|
3
|
+
import { HandlerResponse } from "./responses/index.js";
|
|
4
4
|
export type ApiEndpointHandler<Responses extends HandlerResponse<HttpStatusCode, unknown>, PathParams extends Record<string, string> = {}, RequestBody = unknown, Query = unknown, Caller = unknown> = (typedRequestData: {
|
|
5
5
|
request: Request<PathParams, unknown, RequestBody, Query, Record<string, unknown>>;
|
|
6
6
|
response: Response<unknown>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { HttpStatusCode } from "../../constants/HttpStatusCodes";
|
|
3
|
-
import { SecurityScheme } from "../../security/SecuritySchema";
|
|
4
|
-
import { Prettify } from "../../utils/types";
|
|
5
|
-
import { ApiEndpointHandler } from "./EndpointHandler";
|
|
6
|
-
import { ExtractPathParams } from "./PathParameters";
|
|
7
|
-
import { GenericResponseSchema, GenericResponseSchemaMap, InferResponseFromSchema } from "./responses/index";
|
|
2
|
+
import { HttpStatusCode } from "../../constants/HttpStatusCodes.js";
|
|
3
|
+
import { SecurityScheme } from "../../security/SecuritySchema.js";
|
|
4
|
+
import { Prettify } from "../../utils/types.js";
|
|
5
|
+
import { ApiEndpointHandler } from "./EndpointHandler.js";
|
|
6
|
+
import { ExtractPathParams } from "./PathParameters.js";
|
|
7
|
+
import { GenericResponseSchema, GenericResponseSchemaMap, InferResponseFromSchema } from "./responses/index.js";
|
|
8
8
|
export type HandlerForDefinition<Path extends string, RequestBody extends z.ZodType | undefined, Query extends z.ZodType | undefined, ResponsesMap extends GenericResponseSchemaMap, SecuritySchemas extends SecurityScheme<unknown>[] = []> = ApiEndpointHandler<Exclude<Prettify<{
|
|
9
9
|
[K in keyof ResponsesMap]: K extends HttpStatusCode ? InferResponseFromSchema<K, ResponsesMap[K] extends GenericResponseSchema ? ResponsesMap[K] : never> : never;
|
|
10
10
|
}[keyof ResponsesMap]>, undefined>, ExtractPathParams<Path>, RequestBody extends undefined ? undefined : z.infer<RequestBody>, Query extends undefined ? undefined : z.infer<Query>, SecuritySchemas extends SecurityScheme<infer Caller>[] ? Caller : unknown>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { HttpMethod } from "../../constants/HttpMethods";
|
|
3
|
-
import { HttpStatusCode } from "../../constants/HttpStatusCodes";
|
|
4
|
-
import { SecurityScheme } from "../../security/SecuritySchema";
|
|
5
|
-
import { Prettify } from "../../utils/types";
|
|
6
|
-
import { ApiEndpointDefinition } from "./EndpointDefinition";
|
|
7
|
-
import { ApiEndpointHandler } from "./EndpointHandler";
|
|
8
|
-
import { HandlerForDefinition } from "./HandlerFromDefinition";
|
|
9
|
-
import { GenericResponseSchemaMap, HandlerResponse } from "./responses";
|
|
2
|
+
import { HttpMethod } from "../../constants/HttpMethods.js";
|
|
3
|
+
import { HttpStatusCode } from "../../constants/HttpStatusCodes.js";
|
|
4
|
+
import { SecurityScheme } from "../../security/SecuritySchema.js";
|
|
5
|
+
import { Prettify } from "../../utils/types.js";
|
|
6
|
+
import { ApiEndpointDefinition } from "./EndpointDefinition.js";
|
|
7
|
+
import { ApiEndpointHandler } from "./EndpointHandler.js";
|
|
8
|
+
import { HandlerForDefinition } from "./HandlerFromDefinition.js";
|
|
9
|
+
import { GenericResponseSchemaMap, HandlerResponse } from "./responses/index.js";
|
|
10
10
|
export declare function createApiEndpointHandler<const ResponsesMap extends GenericResponseSchemaMap, const Path extends string, const Method extends HttpMethod, const RequestBody extends z.ZodType | undefined = undefined, const Query extends z.ZodType | undefined = undefined, const SecuritySchemas extends SecurityScheme<unknown>[] = []>(definition: Prettify<ApiEndpointDefinition<Path, Method, RequestBody, Query, ResponsesMap, SecuritySchemas>>, handler: HandlerForDefinition<Path, RequestBody, Query, ResponsesMap, SecuritySchemas>): {
|
|
11
11
|
definition: {
|
|
12
|
-
meta: import("./EndpointDefinition").ApiEndpointMeta;
|
|
12
|
+
meta: import("./EndpointDefinition.js").ApiEndpointMeta;
|
|
13
13
|
path: Path;
|
|
14
14
|
method: Method;
|
|
15
15
|
requestBodySchema?: RequestBody | undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { createServer } from "../../server";
|
|
3
|
-
import { createApiEndpointHandler } from "./createApiHandler";
|
|
2
|
+
import { createServer } from "../../server.js";
|
|
3
|
+
import { createApiEndpointHandler } from "./createApiHandler.js";
|
|
4
4
|
import testRequest from "supertest";
|
|
5
5
|
import z from "zod";
|
|
6
|
-
import { HttpMethods } from "../../constants/HttpMethods";
|
|
6
|
+
import { HttpMethods } from "../../constants/HttpMethods.js";
|
|
7
7
|
export const testEndpointBase = {
|
|
8
8
|
meta: {
|
|
9
9
|
name: "getTest",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { HttpStatusCode } from "../../../constants/HttpStatusCodes";
|
|
3
|
-
import { JsonResponseSchema } from "./jsonResponse";
|
|
2
|
+
import { HttpStatusCode } from "../../../constants/HttpStatusCodes.js";
|
|
3
|
+
import { JsonResponseSchema } from "./jsonResponse.js";
|
|
4
4
|
export type AbstractResponseSchema<Headers extends string[] | undefined = string[] | undefined> = {
|
|
5
5
|
type: string;
|
|
6
6
|
headers?: Headers;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { AbstractResponseSchema } from ".";
|
|
2
|
+
import { AbstractResponseSchema } from "./index.js";
|
|
3
3
|
export interface JsonResponseSchema<DataSchema extends z.ZodType = z.ZodType, Headers extends string[] | undefined = string[] | undefined> extends AbstractResponseSchema<Headers> {
|
|
4
4
|
type: "json";
|
|
5
5
|
schema: DataSchema;
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { createApiEndpointHandler } from "./handlers/api/createApiHandler";
|
|
2
|
-
export { createBasicAuthSchema } from "./security/basicAuth";
|
|
3
|
-
export { createBearerAuthSchema } from "./security/bearerAuth";
|
|
4
|
-
export { createServer, type Server, type ServerConfig } from "./server";
|
|
1
|
+
export { createApiEndpointHandler } from "./handlers/api/createApiHandler.js";
|
|
2
|
+
export { createBasicAuthSchema } from "./security/basicAuth.js";
|
|
3
|
+
export { createBearerAuthSchema } from "./security/bearerAuth.js";
|
|
4
|
+
export { createServer, type Server, type ServerConfig } from "./server.js";
|
|
5
5
|
declare const _default: {};
|
|
6
6
|
export default _default;
|
package/dist/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { createApiEndpointHandler } from "./handlers/api/createApiHandler";
|
|
2
|
-
export { createBasicAuthSchema } from "./security/basicAuth";
|
|
3
|
-
export { createBearerAuthSchema } from "./security/bearerAuth";
|
|
4
|
-
export { createServer } from "./server";
|
|
1
|
+
export { createApiEndpointHandler } from "./handlers/api/createApiHandler.js";
|
|
2
|
+
export { createBasicAuthSchema } from "./security/basicAuth.js";
|
|
3
|
+
export { createBearerAuthSchema } from "./security/bearerAuth.js";
|
|
4
|
+
export { createServer } from "./server.js";
|
|
5
5
|
export default {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SecurityScheme } from "../security/SecuritySchema";
|
|
1
|
+
import { SecurityScheme } from "../security/SecuritySchema.js";
|
|
2
2
|
export declare function buildAuthenticationMiddleware<Caller>(schemes: SecurityScheme<Caller>[]): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import expressAsyncHandler from "express-async-handler";
|
|
2
|
-
import { HttpStatusCodes } from "../constants/HttpStatusCodes";
|
|
3
|
-
import { authenticate } from "../security/SecuritySchema";
|
|
2
|
+
import { HttpStatusCodes } from "../constants/HttpStatusCodes.js";
|
|
3
|
+
import { authenticate } from "../security/SecuritySchema.js";
|
|
4
4
|
export function buildAuthenticationMiddleware(schemes) {
|
|
5
5
|
return expressAsyncHandler(async (request, response, next) => {
|
|
6
6
|
const caller = await authenticate(schemes, request);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
|
-
import { Logger } from "../utils/logging";
|
|
2
|
+
import { Logger } from "../utils/logging.js";
|
|
3
3
|
export declare function buildRequestLogger(logger: Logger, isInDevMode: boolean): (req: Request, res: Response, next: NextFunction) => void;
|
|
4
4
|
export declare function buildResponseLogger(logger: Logger, isInDevMode: boolean): (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpStatusCodes } from "../constants/HttpStatusCodes";
|
|
1
|
+
import { HttpStatusCodes } from "../constants/HttpStatusCodes.js";
|
|
2
2
|
export function buildBodyValidatorMiddleware(schema) {
|
|
3
3
|
return (request, response, next) => {
|
|
4
4
|
const validationResult = schema.safeParse(request.body);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request } from "express";
|
|
2
|
-
import { BasicAuthScheme } from "./basicAuth";
|
|
3
|
-
import { BearerAuthScheme } from "./bearerAuth";
|
|
2
|
+
import { BasicAuthScheme } from "./basicAuth.js";
|
|
3
|
+
import { BearerAuthScheme } from "./bearerAuth.js";
|
|
4
4
|
export type SecurityScheme<Caller> = BasicAuthScheme<Caller> | BearerAuthScheme<Caller>;
|
|
5
5
|
export declare function authenticate<Caller>(schemes: SecurityScheme<Caller>[], request: Request): Promise<Caller | null>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { buildBasicAuthenticator } from "./basicAuth";
|
|
2
|
-
import { buildBearerAuthenticator } from "./bearerAuth";
|
|
1
|
+
import { buildBasicAuthenticator } from "./basicAuth.js";
|
|
2
|
+
import { buildBearerAuthenticator } from "./bearerAuth.js";
|
|
3
3
|
export async function authenticate(schemes, request) {
|
|
4
4
|
const authenticationResults = await Promise.all(schemes.map((scheme) => {
|
|
5
5
|
switch (scheme.scheme) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import testRequest from "supertest";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { HttpStatusCodes } from "../constants/HttpStatusCodes";
|
|
4
|
-
import { createApiEndpointHandler } from "../handlers/api/createApiHandler";
|
|
5
|
-
import { testEndpointBase } from "../handlers/api/createApiHandler.spec";
|
|
6
|
-
import { createServer } from "../server";
|
|
7
|
-
import { createBasicAuthSchema } from "./basicAuth";
|
|
3
|
+
import { HttpStatusCodes } from "../constants/HttpStatusCodes.js";
|
|
4
|
+
import { createApiEndpointHandler } from "../handlers/api/createApiHandler.js";
|
|
5
|
+
import { testEndpointBase } from "../handlers/api/createApiHandler.spec.js";
|
|
6
|
+
import { createServer } from "../server.js";
|
|
7
|
+
import { createBasicAuthSchema } from "./basicAuth.js";
|
|
8
8
|
describe("basic auth schema", () => {
|
|
9
9
|
const testUsername = "Test";
|
|
10
10
|
const testPassword = "TestPW";
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Application } from "express";
|
|
2
|
-
import { ApiEndpointDefinition } from "./handlers/api/EndpointDefinition";
|
|
3
|
-
import { HandlerForDefinition } from "./handlers/api/HandlerFromDefinition";
|
|
4
|
-
import { Logger } from "./utils/logging";
|
|
2
|
+
import { ApiEndpointDefinition } from "./handlers/api/EndpointDefinition.js";
|
|
3
|
+
import { HandlerForDefinition } from "./handlers/api/HandlerFromDefinition.js";
|
|
4
|
+
import { Logger } from "./utils/logging.js";
|
|
5
5
|
export interface ServerConfig {
|
|
6
6
|
inDevMode: boolean;
|
|
7
7
|
port: number;
|
package/dist/server/server.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import cookieParser from "cookie-parser";
|
|
2
2
|
import express from "express";
|
|
3
|
-
import { buildApiEndpointHandler } from "./handlers/api/createApiHandler";
|
|
4
|
-
import { buildAuthenticationMiddleware } from "./middleware/auth";
|
|
5
|
-
import { buildRequestLogger, buildResponseLogger } from "./middleware/logging";
|
|
6
|
-
import { buildBodyValidatorMiddleware, buildQueryValidatorMiddleware, } from "./middleware/validation";
|
|
7
|
-
import { isEmpty } from "./utils/funcs";
|
|
8
|
-
import { NoOpLogger } from "./utils/logging";
|
|
9
|
-
import { hasNoValue, hasValue } from "./utils/typeGuards";
|
|
3
|
+
import { buildApiEndpointHandler } from "./handlers/api/createApiHandler.js";
|
|
4
|
+
import { buildAuthenticationMiddleware } from "./middleware/auth.js";
|
|
5
|
+
import { buildRequestLogger, buildResponseLogger, } from "./middleware/logging.js";
|
|
6
|
+
import { buildBodyValidatorMiddleware, buildQueryValidatorMiddleware, } from "./middleware/validation.js";
|
|
7
|
+
import { isEmpty } from "./utils/funcs.js";
|
|
8
|
+
import { NoOpLogger } from "./utils/logging.js";
|
|
9
|
+
import { hasNoValue, hasValue } from "./utils/typeGuards.js";
|
|
10
10
|
function registerApiEndpoint(expressApp, endpoint) {
|
|
11
11
|
const { definition, handler } = endpoint;
|
|
12
12
|
const handlerStack = [
|