fixed some schemas, packed it as a npm package

This commit is contained in:
yusing
2025-01-24 10:42:50 +08:00
parent 9936b3af5b
commit 4c311fd78e
17 changed files with 634 additions and 3955 deletions

File diff suppressed because one or more lines are too long

View File

@@ -47,7 +47,6 @@ export interface CloudDNSOptions extends AutocertConfigBase {
};
}
export interface DuckDNSOptions extends AutocertConfigBase {
provider: "duckdns";
options: {

View File

@@ -13,9 +13,8 @@ export type Providers = {
*
* @minProperties 1
* @examples require(".").dockerExamples
* @items.pattern ^((\w+://)[^\s]+)|\$DOCKER_HOST$
*/
docker?: { [name: string]: URL };
docker?: { [name: string]: URL | "$DOCKER_HOST" };
/** List of notification providers
*
* @minItems 1

File diff suppressed because one or more lines are too long

View File

@@ -1,364 +1 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"CIDR": {
"anyOf": [
{
"pattern": "^[0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*$",
"type": "string"
},
{
"pattern": "^.*:.*:.*:.*:.*:.*:.*:.*$",
"type": "string"
},
{
"pattern": "^[0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*/[0-9]*$",
"type": "string"
},
{
"pattern": "^::[0-9]*$",
"type": "string"
},
{
"pattern": "^.*::/[0-9]*$",
"type": "string"
},
{
"pattern": "^.*:.*::/[0-9]*$",
"type": "string"
}
]
},
"MiddlewareComposeMap": {
"anyOf": [
{
"additionalProperties": false,
"properties": {
"use": {
"enum": [
"CustomErrorPage",
"ErrorPage",
"customErrorPage",
"custom_error_page",
"errorPage",
"error_page"
],
"type": "string"
}
},
"required": [
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"use": {
"enum": [
"RedirectHTTP",
"redirectHTTP",
"redirect_http"
],
"type": "string"
}
},
"required": [
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"use": {
"enum": [
"SetXForwarded",
"setXForwarded",
"set_x_forwarded"
],
"type": "string"
}
},
"required": [
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"use": {
"enum": [
"HideXForwarded",
"hideXForwarded",
"hide_x_forwarded"
],
"type": "string"
}
},
"required": [
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"allow": {
"items": {
"$ref": "#/definitions/CIDR"
},
"type": "array"
},
"message": {
"default": "IP not allowed",
"description": "Error message when blocked",
"type": "string"
},
"status": {
"$ref": "#/definitions/StatusCode",
"default": 403,
"description": "HTTP status code when blocked (alias of status_code)"
},
"status_code": {
"$ref": "#/definitions/StatusCode",
"default": 403,
"description": "HTTP status code when blocked"
},
"use": {
"enum": [
"CIDRWhitelist",
"cidrWhitelist",
"cidr_whitelist"
],
"type": "string"
}
},
"required": [
"allow",
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"recursive": {
"default": false,
"description": "Recursively resolve the IP",
"type": "boolean"
},
"use": {
"enum": [
"cloudflareRealIp",
"cloudflare_real_ip"
],
"type": "string"
}
},
"required": [
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"add_headers": {
"additionalProperties": {
"type": "string"
},
"description": "Add HTTP headers",
"type": "object"
},
"hide_headers": {
"description": "Hide HTTP headers",
"items": {
"type": "string"
},
"type": "array"
},
"set_headers": {
"additionalProperties": {
"type": "string"
},
"description": "Set HTTP headers",
"type": "object"
},
"use": {
"enum": [
"ModifyRequest",
"Request",
"modifyRequest",
"modify_request",
"request"
],
"type": "string"
}
},
"required": [
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"add_headers": {
"additionalProperties": {
"type": "string"
},
"description": "Add HTTP headers",
"type": "object"
},
"hide_headers": {
"description": "Hide HTTP headers",
"items": {
"type": "string"
},
"type": "array"
},
"set_headers": {
"additionalProperties": {
"type": "string"
},
"description": "Set HTTP headers",
"type": "object"
},
"use": {
"enum": [
"ModifyResponse",
"Response",
"modifyResponse",
"modify_response",
"response"
],
"type": "string"
}
},
"required": [
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"allowed_groups": {
"description": "Allowed groups",
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"allowed_users": {
"description": "Allowed users",
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"use": {
"enum": [
"OIDC",
"oidc"
],
"type": "string"
}
},
"required": [
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"average": {
"description": "Average number of requests allowed in a period",
"type": "number"
},
"burst": {
"description": "Maximum number of requests allowed in a period",
"type": "number"
},
"period": {
"default": "1s",
"description": "Duration of the rate limit",
"pattern": "^([0-9]+(ms|s|m|h))+$",
"type": "string"
},
"use": {
"enum": [
"RateLimit",
"rateLimit",
"rate_limit"
],
"type": "string"
}
},
"required": [
"average",
"burst",
"use"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"from": {
"items": {
"$ref": "#/definitions/CIDR"
},
"type": "array"
},
"header": {
"default": "X-Real-IP",
"description": "Header to get the client IP from",
"pattern": "^[a-zA-Z0-9\\-]+$",
"type": "string"
},
"recursive": {
"default": false,
"description": "Recursive resolve the IP",
"type": "boolean"
},
"use": {
"enum": [
"RealIP",
"realIP",
"real_ip"
],
"type": "string"
}
},
"required": [
"from",
"use"
],
"type": "object"
}
]
},
"StatusCode": {
"anyOf": [
{
"pattern": "^[0-9]*$",
"type": "string"
},
{
"type": "number"
}
]
}
},
"items": {
"$ref": "#/definitions/MiddlewareComposeMap"
},
"type": "array"
}
{"$schema":"http://json-schema.org/draft-07/schema#","definitions":{"CIDR":{"anyOf":[{"pattern":"^[0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*$","type":"string"},{"pattern":"^.*:.*:.*:.*:.*:.*:.*:.*$","type":"string"},{"pattern":"^[0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*/[0-9]*$","type":"string"},{"pattern":"^::[0-9]*$","type":"string"},{"pattern":"^.*::/[0-9]*$","type":"string"},{"pattern":"^.*:.*::/[0-9]*$","type":"string"}]},"Duration":{"pattern":"^([0-9]+(ms|s|m|h))+$","type":"string"},"HTTPHeader":{"description":"HTTP Header","pattern":"^[a-zA-Z0-9\\-]+$","type":"string"},"MiddlewareComposeMap":{"anyOf":[{"additionalProperties":false,"properties":{"use":{"enum":["CustomErrorPage","ErrorPage","customErrorPage","custom_error_page","errorPage","error_page"],"type":"string"}},"required":["use"],"type":"object"},{"additionalProperties":false,"properties":{"use":{"enum":["RedirectHTTP","redirectHTTP","redirect_http"],"type":"string"}},"required":["use"],"type":"object"},{"additionalProperties":false,"properties":{"use":{"enum":["SetXForwarded","setXForwarded","set_x_forwarded"],"type":"string"}},"required":["use"],"type":"object"},{"additionalProperties":false,"properties":{"use":{"enum":["HideXForwarded","hideXForwarded","hide_x_forwarded"],"type":"string"}},"required":["use"],"type":"object"},{"additionalProperties":false,"properties":{"allow":{"items":{"$ref":"#/definitions/CIDR"},"type":"array"},"message":{"default":"IP not allowed","description":"Error message when blocked","type":"string"},"status":{"$ref":"#/definitions/StatusCode","default":403,"description":"HTTP status code when blocked (alias of status_code)"},"status_code":{"$ref":"#/definitions/StatusCode","default":403,"description":"HTTP status code when blocked"},"use":{"enum":["CIDRWhitelist","cidrWhitelist","cidr_whitelist"],"type":"string"}},"required":["allow","use"],"type":"object"},{"additionalProperties":false,"properties":{"recursive":{"default":false,"description":"Recursively resolve the IP","type":"boolean"},"use":{"enum":["cloudflareRealIp","cloudflare_real_ip"],"type":"string"}},"required":["use"],"type":"object"},{"additionalProperties":false,"properties":{"add_headers":{"additionalProperties":false,"description":"Add HTTP headers","items":{"type":"string"},"type":"array"},"hide_headers":{"description":"Hide HTTP headers","items":{"$ref":"#/definitions/HTTPHeader"},"type":"array"},"set_headers":{"additionalProperties":false,"description":"Set HTTP headers","items":{"type":"string"},"type":"array"},"use":{"enum":["ModifyRequest","Request","modifyRequest","modify_request","request"],"type":"string"}},"required":["use"],"type":"object"},{"additionalProperties":false,"properties":{"add_headers":{"additionalProperties":false,"description":"Add HTTP headers","items":{"type":"string"},"type":"array"},"hide_headers":{"description":"Hide HTTP headers","items":{"$ref":"#/definitions/HTTPHeader"},"type":"array"},"set_headers":{"additionalProperties":false,"description":"Set HTTP headers","items":{"type":"string"},"type":"array"},"use":{"enum":["ModifyResponse","Response","modifyResponse","modify_response","response"],"type":"string"}},"required":["use"],"type":"object"},{"additionalProperties":false,"properties":{"allowed_groups":{"description":"Allowed groups","items":{"type":"string"},"minItems":1,"type":"array"},"allowed_users":{"description":"Allowed users","items":{"type":"string"},"minItems":1,"type":"array"},"use":{"enum":["OIDC","oidc"],"type":"string"}},"required":["use"],"type":"object"},{"additionalProperties":false,"properties":{"average":{"description":"Average number of requests allowed in a period","type":"number"},"burst":{"description":"Maximum number of requests allowed in a period","type":"number"},"period":{"$ref":"#/definitions/Duration","default":"1s","description":"Duration of the rate limit"},"use":{"enum":["RateLimit","rateLimit","rate_limit"],"type":"string"}},"required":["average","burst","use"],"type":"object"},{"additionalProperties":false,"properties":{"from":{"items":{"$ref":"#/definitions/CIDR"},"type":"array"},"header":{"$ref":"#/definitions/HTTPHeader","default":"X-Real-IP","description":"Header to get the client IP from"},"recursive":{"default":false,"description":"Recursive resolve the IP","type":"boolean"},"use":{"enum":["RealIP","realIP","real_ip"],"type":"string"}},"required":["from","use"],"type":"object"}]},"StatusCode":{"anyOf":[{"pattern":"^[0-9]*$","type":"string"},{"type":"number"}]}},"items":{"$ref":"#/definitions/MiddlewareComposeMap"},"type":"array"}

View File

@@ -1,3 +1,3 @@
import { MiddlewareComposeMap } from "./middlewares";
export type MiddlewareCompose = MiddlewareComposeMap[];
export type MiddlewareCompose = MiddlewareComposeMap[];

View File

@@ -2,11 +2,13 @@ import * as types from "../types";
export type MiddlewareComposeObjectRef = `${string}@file`;
export type KeyOptMapping<T extends { use: string }> = {
[key in T["use"]]: Omit<T, "use">;
} | { use: MiddlewareComposeObjectRef };
export type KeyOptMapping<T extends { use: string }> =
| {
[key in T["use"]]: Omit<T, "use">;
}
| { use: MiddlewareComposeObjectRef };
export type MiddlewaresMap = (
export type MiddlewaresMap =
| KeyOptMapping<CustomErrorPage>
| KeyOptMapping<RedirectHTTP>
| KeyOptMapping<SetXForwarded>
@@ -18,10 +20,9 @@ export type MiddlewaresMap = (
| KeyOptMapping<OIDC>
| KeyOptMapping<RateLimit>
| KeyOptMapping<RealIP>
| { [key in MiddlewareComposeObjectRef]: types.NullOrEmptyMap }
);
| { [key in MiddlewareComposeObjectRef]: types.NullOrEmptyMap };
export type MiddlewareComposeMap = (
export type MiddlewareComposeMap =
| CustomErrorPage
| RedirectHTTP
| SetXForwarded
@@ -32,11 +33,16 @@ export type MiddlewareComposeMap = (
| ModifyResponse
| OIDC
| RateLimit
| RealIP
);
| RealIP;
export type CustomErrorPage = {
use: "error_page" | "errorPage" | "ErrorPage" | "custom_error_page" | "customErrorPage" | "CustomErrorPage";
use:
| "error_page"
| "errorPage"
| "ErrorPage"
| "custom_error_page"
| "customErrorPage"
| "CustomErrorPage";
};
export type RedirectHTTP = {
@@ -81,7 +87,12 @@ export type CloudflareRealIP = {
};
export type ModifyRequest = {
use: "request" | "Request" | "modify_request" | "modifyRequest" | "ModifyRequest";
use:
| "request"
| "Request"
| "modify_request"
| "modifyRequest"
| "ModifyRequest";
/** Set HTTP headers */
set_headers?: { [key: types.HTTPHeader]: string };
/** Add HTTP headers */
@@ -91,7 +102,12 @@ export type ModifyRequest = {
};
export type ModifyResponse = {
use: "response" | "Response" | "modify_response" | "modifyResponse" | "ModifyResponse";
use:
| "response"
| "Response"
| "modify_response"
| "modifyResponse"
| "ModifyResponse";
/** Set HTTP headers */
set_headers?: { [key: types.HTTPHeader]: string };
/** Add HTTP headers */

View File

@@ -12,7 +12,7 @@ export type HomepageConfig = {
/* Display name on dashboard */
name?: string;
/* Display icon on dashboard */
icon?: URL | WalkxcodeIcon | TargetRelativeIconPath;
icon?: URL | WalkxcodeIcon | ExternalIcon | TargetRelativeIconPath;
/* App description */
description?: string;
/* Override url */
@@ -25,12 +25,14 @@ export type HomepageConfig = {
};
};
/**
* @pattern ^(png|svg|webp)\\/[\\w\\d\\-_]+\\.\\1$
*/
export type WalkxcodeIcon = string;
/* Walkxcode icon */
export type WalkxcodeIcon = `${
| "png"
| "svg"
| "webp"}/${string}/${string}.${string}`;
/**
* @pattern ^@target/.+$
*/
export type TargetRelativeIconPath = string;
/* Walkxcode / selfh.st icon */
export type ExternalIcon = `@${"selfhst" | "walkxcode"}/${string}.${string}`;
/* Relative path to proxy target */
export type TargetRelativeIconPath = `@target/${string}` | `/${string}`;

View File

@@ -26,7 +26,7 @@ export type IdleWatcherConfig = {
wake_timeout?: Duration;
/** Stop timeout
*
* @default 10s
* @default 30s
*/
stop_timeout?: Duration;
/** Stop method

File diff suppressed because one or more lines are too long

View File

@@ -18,22 +18,28 @@ export const HTTP_METHODS = [
] as const;
export type HTTPMethod = (typeof HTTP_METHODS)[number];
// "string & {}" Prevents skipping schema generation
/**
* HTTP Header
* @pattern ^[a-zA-Z0-9\-]+$
* @type string
*/
export type HTTPHeader = string;
export type HTTPHeader = string & {};
/**
* HTTP Query
* @pattern ^[a-zA-Z0-9\-_]+$
* @type string
*/
export type HTTPQuery = string;
export type HTTPQuery = string & {};
/**
* HTTP Cookie
* @pattern ^[a-zA-Z0-9\-_]+$
* @type string
*/
export type HTTPCookie = string;
export type HTTPCookie = string & {};
export type StatusCode = number | `${number}`;
export type StatusCodeRange = number | `${number}` | `${number}-${number}`;
@@ -48,16 +54,19 @@ export type DomainNames = string[];
export type DomainOrWildcards = string[];
/**
* @format hostname
* @type string
*/
export type Hostname = string;
export type Hostname = string & {};
/**
* @format ipv4
* @type string
*/
export type IPv4 = string;
export type IPv4 = string & {};
/**
* @format ipv6
* @type string
*/
export type IPv6 = string;
export type IPv6 = string & {};
/* CIDR / IPv4 / IPv6 */
export type CIDR =
@@ -73,39 +82,46 @@ export type CIDR =
* @minimum 0
* @maximum 65535
*/
export type Port = number;
export type Port = number | `${number}`;
/**
* @pattern ^\d+:\d+$
* @type string
*/
export type StreamPort = string;
export type StreamPort = string & {};
/**
* @format email
* @type string
*/
export type Email = string;
export type Email = string & {};
/**
* @format uri
* @type string
*/
export type URL = string;
export type URL = string & {};
/**
* @format uri-reference
* @type string
*/
export type URI = string;
export type URI = string & {};
/**
* @pattern ^(?:([A-Z]+) )?(?:([a-zA-Z0-9.-]+)\\/)?(\\/[^\\s]*)$
* @type string
*/
export type PathPattern = string;
export type PathPattern = string & {};
/**
* @pattern ^([0-9]+(ms|s|m|h))+$
* @type string
*/
export type Duration = string;
export type Duration = string & {};
/**
* @format date-time
* @type string
*/
export type DateTime = string;
export type DateTime = string & {};