fix npm package

This commit is contained in:
yusing
2025-01-25 02:36:22 +08:00
parent 4c311fd78e
commit 9e181d25ce
39 changed files with 984 additions and 5 deletions

49
schemas/config/access_log.d.ts vendored Normal file
View File

@@ -0,0 +1,49 @@
import { CIDR, HTTPHeader, HTTPMethod, StatusCodeRange, URI } from "../types";
export declare const ACCESS_LOG_FORMATS: readonly ["combined", "common", "json"];
export type AccessLogFormat = (typeof ACCESS_LOG_FORMATS)[number];
export type AccessLogConfig = {
/**
* The size of the buffer.
*
* @minimum 0
* @default 65536
* @TJS-type integer
*/
buffer_size?: number;
/** The format of the access log.
*
* @default "combined"
*/
format?: AccessLogFormat;
path: URI;
filters?: AccessLogFilters;
fields?: AccessLogFields;
};
export type AccessLogFilter<T> = {
/** Whether the filter is negative.
*
* @default false
*/
negative?: boolean;
values: T[];
};
export type AccessLogFilters = {
status_code?: AccessLogFilter<StatusCodeRange>;
method?: AccessLogFilter<HTTPMethod>;
host?: AccessLogFilter<string>;
headers?: AccessLogFilter<HTTPHeader>;
cidr?: AccessLogFilter<CIDR>;
};
export declare const ACCESS_LOG_FIELD_MODES: readonly ["keep", "drop", "redact"];
export type AccessLogFieldMode = (typeof ACCESS_LOG_FIELD_MODES)[number];
export type AccessLogField = {
default?: AccessLogFieldMode;
config: {
[key: string]: AccessLogFieldMode;
};
};
export type AccessLogFields = {
header?: AccessLogField;
query?: AccessLogField;
cookie?: AccessLogField;
};

View File

@@ -0,0 +1,2 @@
export const ACCESS_LOG_FORMATS = ["combined", "common", "json"];
export const ACCESS_LOG_FIELD_MODES = ["keep", "drop", "redact"];

56
schemas/config/autocert.d.ts vendored Normal file
View File

@@ -0,0 +1,56 @@
import { DomainOrWildcards as DomainsOrWildcards, Email } from "../types";
export declare const AUTOCERT_PROVIDERS: readonly ["local", "cloudflare", "clouddns", "duckdns", "ovh"];
export type AutocertProvider = (typeof AUTOCERT_PROVIDERS)[number];
export type AutocertConfig = LocalOptions | CloudflareOptions | CloudDNSOptions | DuckDNSOptions | OVHOptionsWithAppKey | OVHOptionsWithOAuth2Config;
export interface AutocertConfigBase {
email: Email;
domains: DomainsOrWildcards;
cert_path?: string;
key_path?: string;
}
export interface LocalOptions extends AutocertConfigBase {
provider: "local";
}
export interface CloudflareOptions extends AutocertConfigBase {
provider: "cloudflare";
options: {
auth_token: string;
};
}
export interface CloudDNSOptions extends AutocertConfigBase {
provider: "clouddns";
options: {
client_id: string;
email: Email;
password: string;
};
}
export interface DuckDNSOptions extends AutocertConfigBase {
provider: "duckdns";
options: {
token: string;
};
}
export declare const OVH_ENDPOINTS: readonly ["ovh-eu", "ovh-ca", "ovh-us", "kimsufi-eu", "kimsufi-ca", "soyoustart-eu", "soyoustart-ca"];
export type OVHEndpoint = (typeof OVH_ENDPOINTS)[number];
export interface OVHOptionsWithAppKey extends AutocertConfigBase {
provider: "ovh";
options: {
application_secret: string;
consumer_key: string;
api_endpoint?: OVHEndpoint;
application_key: string;
};
}
export interface OVHOptionsWithOAuth2Config extends AutocertConfigBase {
provider: "ovh";
options: {
application_secret: string;
consumer_key: string;
api_endpoint?: OVHEndpoint;
oauth2_config: {
client_id: string;
client_secret: string;
};
};
}

View File

@@ -0,0 +1,16 @@
export const AUTOCERT_PROVIDERS = [
"local",
"cloudflare",
"clouddns",
"duckdns",
"ovh",
];
export const OVH_ENDPOINTS = [
"ovh-eu",
"ovh-ca",
"ovh-us",
"kimsufi-eu",
"kimsufi-ca",
"soyoustart-eu",
"soyoustart-ca",
];

54
schemas/config/config.d.ts vendored Normal file
View File

@@ -0,0 +1,54 @@
import { DomainNames } from "../types";
import { AutocertConfig } from "./autocert";
import { EntrypointConfig } from "./entrypoint";
import { HomepageConfig } from "./homepage";
import { Providers } from "./providers";
export type Config = {
/** Optional autocert configuration
*
* @examples require(".").autocertExamples
*/
autocert?: AutocertConfig;
entrypoint?: EntrypointConfig;
providers: Providers;
/** Optional list of domains to match
*
* @minItems 1
* @examples require(".").matchDomainsExamples
*/
match_domains?: DomainNames;
homepage?: HomepageConfig;
/**
* Optional timeout before shutdown
* @default 3
* @minimum 1
*/
timeout_shutdown?: number;
};
export declare const autocertExamples: ({
provider: string;
email?: undefined;
domains?: undefined;
options?: undefined;
} | {
provider: string;
email: string;
domains: string[];
options: {
auth_token: string;
client_id?: undefined;
email?: undefined;
password?: undefined;
};
} | {
provider: string;
email: string;
domains: string[];
options: {
client_id: string;
email: string;
password: string;
auth_token?: undefined;
};
})[];
export declare const matchDomainsExamples: readonly ["example.com", "*.example.com"];

20
schemas/config/config.js Normal file
View File

@@ -0,0 +1,20 @@
export const autocertExamples = [
{ provider: "local" },
{
provider: "cloudflare",
email: "abc@gmail",
domains: ["example.com"],
options: { auth_token: "c1234565789-abcdefghijklmnopqrst" },
},
{
provider: "clouddns",
email: "abc@gmail",
domains: ["example.com"],
options: {
client_id: "c1234565789",
email: "abc@gmail",
password: "password",
},
},
];
export const matchDomainsExamples = ["example.com", "*.example.com"];

39
schemas/config/entrypoint.d.ts vendored Normal file
View File

@@ -0,0 +1,39 @@
import { MiddlewareCompose } from "../middlewares/middleware_compose";
import { AccessLogConfig } from "./access_log";
export type EntrypointConfig = {
/** Entrypoint middleware configuration
*
* @examples require(".").middlewaresExamples
*/
middlewares: MiddlewareCompose;
/** Entrypoint access log configuration
*
* @examples require(".").accessLogExamples
*/
access_log?: AccessLogConfig;
};
export declare const accessLogExamples: readonly [{
readonly path: "/var/log/access.log";
readonly format: "combined";
readonly filters: {
readonly status_codes: {
readonly values: readonly ["200-299"];
};
};
readonly fields: {
readonly headers: {
readonly default: "keep";
readonly config: {
readonly foo: "redact";
};
};
};
}];
export declare const middlewaresExamples: readonly [{
readonly use: "RedirectHTTP";
}, {
readonly use: "CIDRWhitelist";
readonly allow: readonly ["127.0.0.1", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"];
readonly status: 403;
readonly message: "Forbidden";
}];

View File

@@ -0,0 +1,30 @@
export const accessLogExamples = [
{
path: "/var/log/access.log",
format: "combined",
filters: {
status_codes: {
values: ["200-299"],
},
},
fields: {
headers: {
default: "keep",
config: {
foo: "redact",
},
},
},
},
];
export const middlewaresExamples = [
{
use: "RedirectHTTP",
},
{
use: "CIDRWhitelist",
allow: ["127.0.0.1", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
status: 403,
message: "Forbidden",
},
];

7
schemas/config/homepage.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
export type HomepageConfig = {
/**
* Use default app categories (uses docker image name)
* @default true
*/
use_default_categories: boolean;
};

View File

@@ -0,0 +1 @@
export {};

52
schemas/config/notification.d.ts vendored Normal file
View File

@@ -0,0 +1,52 @@
import { URL } from "../types";
export declare const NOTIFICATION_PROVIDERS: readonly ["webhook", "gotify"];
export type NotificationProvider = (typeof NOTIFICATION_PROVIDERS)[number];
export type NotificationConfig = {
name: string;
url: URL;
};
export interface GotifyConfig extends NotificationConfig {
provider: "gotify";
token: string;
}
export declare const WEBHOOK_TEMPLATES: readonly ["discord"];
export declare const WEBHOOK_METHODS: readonly ["POST", "GET", "PUT"];
export declare const WEBHOOK_MIME_TYPES: readonly ["application/json", "application/x-www-form-urlencoded", "text/plain"];
export declare const WEBHOOK_COLOR_MODES: readonly ["hex", "dec"];
export type WebhookTemplate = (typeof WEBHOOK_TEMPLATES)[number];
export type WebhookMethod = (typeof WEBHOOK_METHODS)[number];
export type WebhookMimeType = (typeof WEBHOOK_MIME_TYPES)[number];
export type WebhookColorMode = (typeof WEBHOOK_COLOR_MODES)[number];
export interface WebhookConfig extends NotificationConfig {
provider: "webhook";
/**
* Webhook template
*
* @default "discord"
*/
template?: WebhookTemplate;
token?: string;
/**
* Webhook message (usally JSON),
* required when template is not defined
*/
payload?: string;
/**
* Webhook method
*
* @default "POST"
*/
method?: WebhookMethod;
/**
* Webhook mime type
*
* @default "application/json"
*/
mime_type?: WebhookMimeType;
/**
* Webhook color mode
*
* @default "hex"
*/
color_mode?: WebhookColorMode;
}

View File

@@ -0,0 +1,9 @@
export const NOTIFICATION_PROVIDERS = ["webhook", "gotify"];
export const WEBHOOK_TEMPLATES = ["discord"];
export const WEBHOOK_METHODS = ["POST", "GET", "PUT"];
export const WEBHOOK_MIME_TYPES = [
"application/json",
"application/x-www-form-urlencoded",
"text/plain",
];
export const WEBHOOK_COLOR_MODES = ["hex", "dec"];

44
schemas/config/providers.d.ts vendored Normal file
View File

@@ -0,0 +1,44 @@
import { URI, URL } from "../types";
import { GotifyConfig, WebhookConfig } from "./notification";
export type Providers = {
/** List of route definition files to include
*
* @minItems 1
* @examples require(".").includeExamples
* @items.pattern ^[\w\d\-_]+\.(yaml|yml)$
*/
include?: URI[];
/** Name-value mapping of docker hosts to retrieve routes from
*
* @minProperties 1
* @examples require(".").dockerExamples
*/
docker?: {
[name: string]: URL | "$DOCKER_HOST";
};
/** List of notification providers
*
* @minItems 1
* @examples require(".").notificationExamples
*/
notification?: (WebhookConfig | GotifyConfig)[];
};
export declare const includeExamples: readonly ["file1.yml", "file2.yml"];
export declare const dockerExamples: readonly [{
readonly local: "$DOCKER_HOST";
}, {
readonly remote: "tcp://10.0.2.1:2375";
}, {
readonly remote2: "ssh://root:1234@10.0.2.2";
}];
export declare const notificationExamples: readonly [{
readonly name: "gotify";
readonly provider: "gotify";
readonly url: "https://gotify.domain.tld";
readonly token: "abcd";
}, {
readonly name: "discord";
readonly provider: "webhook";
readonly template: "discord";
readonly url: "https://discord.com/api/webhooks/1234/abcd";
}];

View File

@@ -0,0 +1,20 @@
export const includeExamples = ["file1.yml", "file2.yml"];
export const dockerExamples = [
{ local: "$DOCKER_HOST" },
{ remote: "tcp://10.0.2.1:2375" },
{ remote2: "ssh://root:1234@10.0.2.2" },
];
export const notificationExamples = [
{
name: "gotify",
provider: "gotify",
url: "https://gotify.domain.tld",
token: "abcd",
},
{
name: "discord",
provider: "webhook",
template: "discord",
url: "https://discord.com/api/webhooks/1234/abcd",
},
];