diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index 33915fb..014f9f4 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -3005,13 +3005,13 @@ declare namespace lib_plankton.http { * @author fenris */ enum enum_method { - get = "get", - post = "post", - patch = "patch", - put = "put", - delete = "delete", options = "options", - head = "head" + head = "head", + get = "get", + delete = "delete", + post = "post", + put = "put", + patch = "patch" } /** * @author fenris @@ -3305,16 +3305,28 @@ declare namespace lib_plankton.server { * @author fenris */ type type_subject = { + host: string; port: int; - handle: ((input: string, metadata?: type_metadata) => Promise); + threshold: (null | float); + handle: ((input: Buffer, metadata?: type_metadata) => Promise); serverobj: any; }; /** * @author fenris */ - function make(port: int, handle: ((input: string, metadata?: type_metadata) => Promise)): type_subject; + function make(handle: ((input: string, metadata?: type_metadata) => Promise), options?: { + host?: string; + port?: int; + threshold?: (null | float); + }): type_subject; /** * @author fenris + * @deprecated + */ + function make_old(port: int, handle: ((input: string, metadata?: type_metadata) => Promise)): type_subject; + /** + * @author fenris + * @see https://nodejs.org/api/net.html#serverlistenport-host-backlog-callback */ function start(subject: type_subject): Promise; /** @@ -3334,7 +3346,10 @@ declare namespace lib_plankton.server { /** * @author fenris */ - constructor(port: int, handle: ((input: string) => Promise)); + constructor(handle: ((input: Buffer, metadata?: type_metadata) => Promise), options?: { + host?: string; + port?: int; + }); /** * @author fenris */ diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 8dea427..16e2b3e 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -16,7 +16,7 @@ var __extends = (this && this.__extends) || (function () { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -36,7 +36,7 @@ along with »bacterio-plankton:base«. If not, see »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -69,7 +69,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -128,7 +128,7 @@ along with »bacterio-plankton:base«. If not, see »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -259,7 +259,7 @@ function instance_show(value) { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -370,7 +370,7 @@ export interface interface_writeable { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -410,6 +410,25 @@ var class_error = /** @class */ (function (_super) { }; return class_error; }(Error)); +/* +This file is part of »bacterio-plankton:base«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:base« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:base« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:base«. If not, see . + */ var lib_plankton; (function (lib_plankton) { var base; @@ -437,7 +456,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:pod«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:pod« is free software: you can redistribute it and/or modify @@ -541,7 +560,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:pod«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:pod« is free software: you can redistribute it and/or modify @@ -579,7 +598,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:call«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:call« is free software: you can redistribute it and/or modify @@ -741,7 +760,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:call«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:call« is free software: you can redistribute it and/or modify @@ -824,7 +843,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:call«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:call« is free software: you can redistribute it and/or modify @@ -991,7 +1010,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:call«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:call« is free software: you can redistribute it and/or modify @@ -1162,7 +1181,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:call«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:call« is free software: you can redistribute it and/or modify @@ -1253,7 +1272,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:call«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:call« is free software: you can redistribute it and/or modify @@ -1534,7 +1553,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:list«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:list« is free software: you can redistribute it and/or modify @@ -2020,7 +2039,7 @@ var lib_list; /* This file is part of »bacterio-plankton:file«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:file« is free software: you can redistribute it and/or modify @@ -2212,7 +2231,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { /* This file is part of »bacterio-plankton:email«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:email« is free software: you can redistribute it and/or modify @@ -2285,7 +2304,7 @@ var __extends = (this && this.__extends) || (function () { /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2340,7 +2359,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2424,7 +2443,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2457,7 +2476,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2512,7 +2531,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2594,7 +2613,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2646,7 +2665,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2713,7 +2732,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2764,7 +2783,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2837,7 +2856,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -2942,7 +2961,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -3101,7 +3120,7 @@ var make_eml_body = (function () { /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -3462,7 +3481,7 @@ var lib_string; /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -3726,7 +3745,7 @@ var printf = lib_plankton.string.printf; /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -3858,7 +3877,7 @@ var make_logger = (function () { /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -3996,7 +4015,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -4064,7 +4083,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -4140,7 +4159,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -4262,7 +4281,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -4422,7 +4441,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -4582,7 +4601,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -4756,7 +4775,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -4844,7 +4863,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -4987,7 +5006,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -5130,7 +5149,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:shape«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:shape« is free software: you can redistribute it and/or modify @@ -5316,7 +5335,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5335,7 +5354,7 @@ along with »bacterio-plankton:code«. If not, see »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5354,7 +5373,7 @@ along with »bacterio-plankton:code«. If not, see »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5393,7 +5412,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5447,7 +5466,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5490,7 +5509,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5545,7 +5564,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5595,7 +5614,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5647,7 +5666,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5707,7 +5726,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -5758,7 +5777,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:url«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:url« is free software: you can redistribute it and/or modify @@ -5777,7 +5796,7 @@ along with »bacterio-plankton:url«. If not, see /* This file is part of »bacterio-plankton:url«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:url« is free software: you can redistribute it and/or modify @@ -5903,7 +5922,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:url«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:url« is free software: you can redistribute it and/or modify @@ -5953,7 +5972,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:random«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:random« is free software: you can redistribute it and/or modify @@ -6641,7 +6660,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:sha256«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:sha256« is free software: you can redistribute it and/or modify @@ -6685,7 +6704,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge /* This file is part of »bacterio-plankton:database«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:database« is free software: you can redistribute it and/or modify @@ -6721,7 +6740,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:database«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:database« is free software: you can redistribute it and/or modify @@ -7042,7 +7061,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:database«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:database« is free software: you can redistribute it and/or modify @@ -7268,7 +7287,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:database«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:database« is free software: you can redistribute it and/or modify @@ -7308,7 +7327,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:database«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:database« is free software: you can redistribute it and/or modify @@ -7548,7 +7567,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:database«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:database« is free software: you can redistribute it and/or modify @@ -7588,7 +7607,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:database«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:database« is free software: you can redistribute it and/or modify @@ -7750,7 +7769,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:database«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:database« is free software: you can redistribute it and/or modify @@ -7826,7 +7845,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { /* This file is part of »bacterio-plankton:storage«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -7845,7 +7864,7 @@ along with »bacterio-plankton:storage«. If not, see »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -7864,7 +7883,7 @@ along with »bacterio-plankton:storage«. If not, see »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -7974,7 +7993,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:storage«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -8018,7 +8037,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:storage«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -8124,7 +8143,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:storage«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -8168,7 +8187,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:storage«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -8344,7 +8363,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:storage«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -8385,7 +8404,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:storage«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -8617,7 +8636,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:storage«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:storage« is free software: you can redistribute it and/or modify @@ -8697,7 +8716,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { /* This file is part of »bacterio-plankton:storage«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:session« is free software: you can redistribute it and/or modify @@ -8887,7 +8906,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:json«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:json« is free software: you can redistribute it and/or modify @@ -8926,7 +8945,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:json«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:json« is free software: you can redistribute it and/or modify @@ -8976,7 +8995,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:object«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:object« is free software: you can redistribute it and/or modify @@ -9345,7 +9364,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:markdown«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:markdown« is free software: you can redistribute it and/or modify @@ -9398,7 +9417,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:api«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:api« is free software: you can redistribute it and/or modify @@ -9436,7 +9455,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:api«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:api« is free software: you can redistribute it and/or modify @@ -9686,7 +9705,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:api«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:api« is free software: you can redistribute it and/or modify @@ -9754,7 +9773,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:http«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:http« is free software: you can redistribute it and/or modify @@ -9779,20 +9798,20 @@ var lib_plankton; */ let enum_method; (function (enum_method) { - enum_method["get"] = "get"; - enum_method["post"] = "post"; - enum_method["patch"] = "patch"; - enum_method["put"] = "put"; - enum_method["delete"] = "delete"; enum_method["options"] = "options"; enum_method["head"] = "head"; + enum_method["get"] = "get"; + enum_method["delete"] = "delete"; + enum_method["post"] = "post"; + enum_method["put"] = "put"; + enum_method["patch"] = "patch"; })(enum_method = http.enum_method || (http.enum_method = {})); })(http = lib_plankton.http || (lib_plankton.http = {})); })(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:http«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:http« is free software: you can redistribute it and/or modify @@ -9982,9 +10001,9 @@ var lib_plankton; headers[key.toLowerCase()] = value; } } - const body = ([http.enum_method.get, http.enum_method.head, http.enum_method.options, http.enum_method.delete].includes(method) - ? null - : Buffer["from"](lines.join(linebreak))); + const body = ([http.enum_method.post, http.enum_method.put, http.enum_method.patch].includes(method) + ? Buffer["from"](lines.join(linebreak)) + : null); const request = { // TODO "scheme": "http", @@ -10084,24 +10103,51 @@ var lib_plankton; } case "fetch": { function core(signal) { - return (fetch(target, { + return (fetch(target, Object.assign({ "method": ((method => { switch (method) { - case http.enum_method.get: return "GET"; - case http.enum_method.post: return "POST"; - case http.enum_method.patch: return "PATCH"; - case http.enum_method.put: return "PUT"; - case http.enum_method.delete: return "DELETE"; - case http.enum_method.options: return "OPTIONS"; case http.enum_method.head: return "HEAD"; + case http.enum_method.options: return "OPTIONS"; + case http.enum_method.get: return "GET"; + case http.enum_method.delete: return "DELETE"; + case http.enum_method.post: return "POST"; + case http.enum_method.put: return "PUT"; + case http.enum_method.patch: return "PATCH"; } })(request.method)), "headers": request.headers, - "redirect": (options.follow_redirects ? "follow" : "manual"), - "signal": (signal ?? undefined), - }) + /* + "redirect": ( + options.follow_redirects + ? + "follow" + : + "manual" + ), + */ + "signal": (signal + ?? + undefined), + // "keepalive": false, + }, ((((method => { + switch (method) { + case http.enum_method.head: return false; + case http.enum_method.options: return false; + case http.enum_method.get: return false; + case http.enum_method.delete: return false; + case http.enum_method.post: return true; + case http.enum_method.put: return true; + case http.enum_method.patch: return true; + } + })(request.method)) + && + (request.body !== null)) + ? { + "body": request.body.toString(), + } + : {}))) .catch((reason) => { - console.info(reason); + // console.info(reason); return Promise.reject(reason); }) .then((response_raw) => (response_raw.text() @@ -10147,7 +10193,9 @@ var lib_plankton; break; } case "http_module": { + // @ts-ignore const nm_http = require("http"); + // @ts-ignore const nm_https = require("https"); return (new Promise((resolve, reject) => { const req = ((request.scheme === "https") @@ -10193,7 +10241,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:http«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:http« is free software: you can redistribute it and/or modify @@ -10268,7 +10316,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:rest«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:rest« is free software: you can redistribute it and/or modify @@ -10287,7 +10335,7 @@ along with »bacterio-plankton:rest«. If not, see »bacterio-plankton:rest« is free software: you can redistribute it and/or modify @@ -10314,10 +10362,10 @@ var lib_plankton; case lib_plankton.http.enum_method.get: return "get"; case lib_plankton.http.enum_method.post: return "post"; case lib_plankton.http.enum_method.patch: return "patch"; - case lib_plankton.http.enum_method.head: return "put"; + case lib_plankton.http.enum_method.head: return "head"; case lib_plankton.http.enum_method.delete: return "delete"; case lib_plankton.http.enum_method.options: return "options"; - case lib_plankton.http.enum_method.put: return "head"; + case lib_plankton.http.enum_method.put: return "put"; default: throw (new Error("impossible")); } } @@ -11023,7 +11071,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:server«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:server« is free software: you can redistribute it and/or modify @@ -11046,9 +11094,16 @@ var lib_plankton; /** * @author fenris */ - function make(port, handle) { + function make(handle, options = {}) { + options = Object.assign({ + "host": "::", + "port": 9999, + "threshold": 0.25, + }, options); return { - "port": port, + "host": options.host, + "port": options.port, + "threshold": options.threshold, "handle": handle, "serverobj": undefined, }; @@ -11056,49 +11111,122 @@ var lib_plankton; server.make = make; /** * @author fenris + * @deprecated + */ + function make_old(port, handle) { + return make(handle, { + "host": "::", + "port": port, + "threshold": 0.25, + }); + } + server.make_old = make_old; + /** + * @author fenris + * @see https://nodejs.org/api/net.html#serverlistenport-host-backlog-callback */ function start(subject) { const net = require("net"); return (new Promise((resolve, reject) => { - subject.serverobj = net.createServer((socket) => { - lib_plankton.log.info("server_client connected", {}); - socket.on("readable", () => { - let chunk; - while (!((chunk = socket.read()) === null)) { - const input = chunk.toString(); - lib_plankton.log.debug("server_reading", { - "input": input, + // @ts-ignore + let input_chunks = []; + subject.serverobj = net.createServer({ + "allowHalfOpen": false, + }, (socket) => { + let timeout_handler = null; + let ended = false; + const process_input = function () { + // @ts-ignore + const input = Buffer.concat(input_chunks); + /* + const metadata : type_metadata = { + "ip_address": socket.remoteAddress, + }; + */ + lib_plankton.log.debug("server_process_input", { + "input": input, + }); + (subject.handle(input /*, metadata*/) + .then((output) => { + lib_plankton.log.debug("server_writing", { + "output": output, }); - const metadata = { - "ip_address": socket.remoteAddress, - }; - subject.handle(input, metadata) - .then((output) => { - lib_plankton.log.debug("server_writing", { - "output": output, - }); - socket.write(output); - socket.end(); - }) - .catch((error) => { - lib_plankton.log.warning("server_handle_failed", { - "error": error.toString(), - }); - // socket.write(""); - socket.end(); + socket.write(output); + socket.end(); + }) + .catch((error) => { + lib_plankton.log.warning("server_handle_failed", { + "error": error.toString(), }); + // socket.write(""); + socket.end(); + }) + .then(() => { + input_chunks = []; + })); + }; + const timeout_stop = function () { + if (timeout_handler === null) { + // do nothing } + else { + lib_plankton.log.debug("server_timeout_cancelling"); + clearTimeout(timeout_handler); + timeout_handler = null; + } + }; + const timeout_start = function () { + if (subject.threshold === null) { + process_input(); + } + else { + if (timeout_handler === null) { + timeout_handler = setTimeout(() => { + lib_plankton.log.debug("server_timeout_reached"); + timeout_handler = null; + process_input(); + }, (subject.threshold * 1000)); + } + else { + lib_plankton.log.warning("server_timeout_already_started"); + // do nothing + } + } + }; + lib_plankton.log.info("server_client connected", {}); + socket.on("data", (input_chunk_raw) => { + lib_plankton.log.debug("server_reading_chunk", { + "chunk_raw": input_chunk_raw, + }); + timeout_stop(); + const input_chunk = ((input_chunk_raw instanceof Buffer) + ? + input_chunk_raw + : + // @ts-ignore + Buffer.from(input_chunk_raw)); + input_chunks.push(input_chunk); + timeout_start(); }); socket.on("end", () => { - lib_plankton.log.info("server_client_disconnected", {}); + if (!ended) { + lib_plankton.log.info("server_client_disconnected", {}); + ended = true; + timeout_stop(); + } + else { + lib_plankton.log.info("server_socket_already_ended"); + // do nothing + } }); }); subject.serverobj.on("error", (error) => { // throw error; process.stderr.write("net_error: " + String(error) + "\n\n"); }); - subject.serverobj.listen(subject.port, () => { + subject.serverobj.listen(subject.port, subject.host, 511, () => { lib_plankton.log.info("server_listenting", { + "host": subject.host, "port": subject.port, }); resolve(undefined); @@ -11119,7 +11247,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:server«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:server« is free software: you can redistribute it and/or modify @@ -11146,8 +11274,15 @@ var lib_plankton; /** * @author fenris */ - constructor(port, handle) { - this.subject = server.make(port, handle); + constructor(handle, options = {}) { + options = Object.assign({ + "host": "::", + "port": 9999, + }, options); + this.subject = server.make(handle, { + "host": options.host, + "port": options.port, + }); } /** * @author fenris @@ -11169,7 +11304,7 @@ var lib_server = lib_plankton.server; /* This file is part of »bacterio-plankton:args«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:args« is free software: you can redistribute it and/or modify @@ -11228,7 +11363,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:args«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:args« is free software: you can redistribute it and/or modify @@ -11526,7 +11661,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:args«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:args« is free software: you can redistribute it and/or modify @@ -11949,7 +12084,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:translate«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:translate« is free software: you can redistribute it and/or modify @@ -12214,7 +12349,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:translate«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:translate« is free software: you can redistribute it and/or modify diff --git a/source/conf.ts b/source/conf.ts index cab001d..544580e 100644 --- a/source/conf.ts +++ b/source/conf.ts @@ -79,6 +79,7 @@ namespace _espe.conf } >; server : { + host : string; port : int; path_base : string; }; @@ -176,9 +177,36 @@ namespace _espe.conf email_address : (null | string); } >; - output : { - authelia : (null | string); - }; + outputs : Array< + { + kind : "authelia_file"; + data : { + path : string; + } + } + | + { + kind : "http"; + data : { + scheme : ("http" | "https"); + host : string; + path : string; + method : ("get" | "post" | "put" | "patch" | "delete" | "head" | "options"); + query : (null | string); + headers : Record; + }; + } + | + { + kind : "arc"; + data : { + http_scheme : ("http" | "https"); + http_host : string; + http_port : int; + hash_salt : string; + } + } + >; }; @@ -212,6 +240,7 @@ namespace _espe.conf ], "server": ( ((node_server) => ({ + "host": "::", "port": (node_server["port"] ?? 4916), "path_base": (node_server["path_base"] ?? ""), })) (conf_raw["server"] ?? {}) @@ -355,10 +384,20 @@ namespace _espe.conf })) (conf_raw["settings"] ?? {}) ), "admins": (conf_raw["admins"] ?? []), - "output": ( - ((node_session_output) => ({ - "authelia": (node_session_output["authelia"] ?? null), - })) (conf_raw["output"] ?? {}) + "outputs": ( + ((node_output) => ( + ("authelia" in node_output) + ? [ + { + "kind": "authelia_file", + "data": { + "path": node_output["authelia"], + } + } + ] + : [ + ] + )) (conf_raw["output"] ?? {}) ), }; break; @@ -397,6 +436,7 @@ namespace _espe.conf ), "server": ( ((node_server) => ({ + "host": "::", "port": (node_server["port"] ?? 4916), "path_base": (node_server["path_base"] ?? ""), })) (conf_raw["server"] ?? {}) @@ -540,10 +580,432 @@ namespace _espe.conf })) (conf_raw["settings"] ?? {}) ), "admins": (conf_raw["admins"] ?? []), - "output": ( - ((node_session_output) => ({ - "authelia": (node_session_output["authelia"] ?? null), - })) (conf_raw["output"] ?? {}) + "outputs": ( + ((node_output) => ( + ("authelia" in node_output) + ? [ + { + "kind": "authelia_file", + "data": { + "path": node_output["authelia"], + } + } + ] + : [ + ] + )) (conf_raw["output"] ?? {}) + ), + }; + break; + } + case 3: { + _data = { + "general": ( + ((node_general) => ({ + "language": (node_general["language"] ?? null), + "verification_secret": (node_general["verification_secret"] ?? null), + })) (conf_raw["general"] ?? {}) + ), + "log": ( + ((node_log) => node_log.map( + (node_log_entry : any) => ({ + "kind": node_log_entry["kind"], + "data": Object.assign( + { + "format": "human_readable", + "threshold": "notice", + }, + (node_log_entry["data"] ?? {}) + ) + }) + )) ( + conf_raw["log"] + ?? + [ + { + "kind": "console", + "data": { + } + }, + ] + ) + ), + "server": ( + ((node_server) => ({ + "host": "::", + "port": (node_server["port"] ?? 4916), + "path_base": (node_server["path_base"] ?? ""), + })) (conf_raw["server"] ?? {}) + ), + "database": ( + ((node_database) => { + const kind : string = (node_database["kind"] ?? "sqlite"); + const node_database_data_raw = (node_database["data"] ?? {}); + switch (kind) { + case "sqlite": { + return { + "kind": kind, + "data": { + "path": (node_database_data_raw["path"] ?? "data.sqlite"), + } + }; + break; + } + case "postgresql": { + return { + "kind": kind, + "data": node_database_data_raw, + }; + break; + } + default: { + throw (new Error("unhandled")); + break; + } + } + }) (conf_raw["database"] ?? {}) + ), + "email_sending": ( + ((node_email_sending) => { + const kind : string = (node_email_sending["kind"] ?? "console"); + const data_raw = (node_email_sending["data"] ?? {}); + switch (kind) { + case "regular": { + return { + "kind": kind, + "data": { + "smtp_credentials": (data_raw["smtp_credentials"] ?? null), + "sender": data_raw["sender"], + } + }; + break; + } + case "redirect": { + return { + "kind": kind, + "data": { + "smtp_credentials": (data_raw["smtp_credentials"] ?? null), + "sender": data_raw["sender"], + "target": data_raw["target"], + } + }; + break; + } + case "console": { + return { + "kind": kind, + "data": { + } + }; + break; + } + case "drop": { + return { + "kind": kind, + "data": { + } + }; + break; + } + default: { + throw (new Error("unhandled")); + break; + } + } + }) (conf_raw["email_sending"] ?? {}) + ), + "session_management": ( + ((node_session_management) => ({ + "in_memory": (node_session_management["in_memory"] ?? true), + "drop_all_at_start": (node_session_management["drop_all_at_start"] ?? true), + "lifetime": (node_session_management["lifetime"] ?? 900), + })) (conf_raw["session_management"] ?? {}) + ), + "settings": ( + ((node_settings) => ({ + "organisation": { + "name": ((node_settings["organisation"] ?? {})["name"] ?? "Example Orginsation"), // TODO: mandatory? + "domain": ((node_settings["organisation"] ?? {})["domain"] ?? "example.org"), // TODO: mandatory? + }, + "misc": ( + ((node_settings_misc) => ({ + "prefix_for_veiled_email_addresses": (node_settings_misc["prefix_for_veiled_email_addresses"] ?? "member-"), + "facultative_membership_number": (node_settings_misc["facultative_membership_number"] ?? false), + "auto_register": (node_settings_misc["auto_register"] ?? false), + })) (node_settings["misc"] ?? {}) + ), + "summon_email": ( + ((node_settings_summon_email) => ({ + "remark": (node_settings_summon_email["remark"] ?? null), + })) (node_settings["summon_email"] ?? {}) + ), + "password_policy": ( + ((node_settings_password_policy) => ({ + "minimum_length": ( + ("minimum_length" in node_settings_password_policy) + ? node_settings_password_policy["minimum_length"] + : 8 + ), + "maximum_length": ( + ("maximum_length" in node_settings_password_policy) + ? node_settings_password_policy["maximum_length"] + : 240 + ), + "must_contain_letter": (node_settings_password_policy["must_contain_letter"] ?? true), + "must_contain_number": (node_settings_password_policy["must_contain_number"] ?? true), + "must_contain_special_character": (node_settings_password_policy["must_contain_special_character"] ?? true), + })) (node_settings["password_policy"] ?? {}) + ), + "password_change": ( + ((node_settings_password_change) => ({ + "cooldown_time": (node_settings_password_change["cooldown_time"] ?? 86400), + })) (node_settings["password_change"] ?? {}) + ), + "name_index": ( + ((node_settings_password_policy) => ({ + "veil": (node_settings_password_policy["veil"] ?? true), + "salt": (node_settings_password_policy["salt"] ?? ""), + })) (node_settings["name_index"] ?? {}) + ), + "connections": ( + ((node_settings_connections) => ({ + "frontend_url_base": (node_settings_connections["frontend_url_base"] ?? null), + "login_url": (node_settings_connections["login_url"] ?? null), + })) (node_settings["connections"] ?? {}) + ), + })) (conf_raw["settings"] ?? {}) + ), + "admins": (conf_raw["admins"] ?? []), + "outputs": (conf_raw["outputs"] ?? []), + }; + break; + } + case 4: { + _data = { + "general": ( + ((node_general) => ({ + "language": (node_general["language"] ?? null), + "verification_secret": (node_general["verification_secret"] ?? null), + })) (conf_raw["general"] ?? {}) + ), + "log": ( + ((node_log) => node_log.map( + (node_log_entry : any) => ({ + "kind": node_log_entry["kind"], + "data": Object.assign( + { + "format": "human_readable", + "threshold": "notice", + }, + (node_log_entry["data"] ?? {}) + ) + }) + )) ( + conf_raw["log"] + ?? + [ + { + "kind": "console", + "data": { + } + }, + ] + ) + ), + "server": ( + ((node_server) => ({ + "host": (node_server["host"] ?? "::"), + "port": (node_server["port"] ?? 4916), + "path_base": (node_server["path_base"] ?? ""), + })) (conf_raw["server"] ?? {}) + ), + "database": ( + ((node_database) => { + const kind : string = (node_database["kind"] ?? "sqlite"); + const node_database_data_raw = (node_database["data"] ?? {}); + switch (kind) { + case "sqlite": { + return { + "kind": kind, + "data": { + "path": (node_database_data_raw["path"] ?? "data.sqlite"), + } + }; + break; + } + case "postgresql": { + return { + "kind": kind, + "data": node_database_data_raw, + }; + break; + } + default: { + throw (new Error("unhandled")); + break; + } + } + }) (conf_raw["database"] ?? {}) + ), + "email_sending": ( + ((node_email_sending) => { + const kind : string = (node_email_sending["kind"] ?? "console"); + const data_raw = (node_email_sending["data"] ?? {}); + switch (kind) { + case "regular": { + return { + "kind": kind, + "data": { + "smtp_credentials": (data_raw["smtp_credentials"] ?? null), + "sender": data_raw["sender"], + } + }; + break; + } + case "redirect": { + return { + "kind": kind, + "data": { + "smtp_credentials": (data_raw["smtp_credentials"] ?? null), + "sender": data_raw["sender"], + "target": data_raw["target"], + } + }; + break; + } + case "console": { + return { + "kind": kind, + "data": { + } + }; + break; + } + case "drop": { + return { + "kind": kind, + "data": { + } + }; + break; + } + default: { + throw (new Error("unhandled")); + break; + } + } + }) (conf_raw["email_sending"] ?? {}) + ), + "session_management": ( + ((node_session_management) => ({ + "in_memory": (node_session_management["in_memory"] ?? true), + "drop_all_at_start": (node_session_management["drop_all_at_start"] ?? true), + "lifetime": (node_session_management["lifetime"] ?? 900), + })) (conf_raw["session_management"] ?? {}) + ), + "settings": ( + ((node_settings) => ({ + "organisation": { + "name": ((node_settings["organisation"] ?? {})["name"] ?? "Example Orginsation"), // TODO: mandatory? + "domain": ((node_settings["organisation"] ?? {})["domain"] ?? "example.org"), // TODO: mandatory? + }, + "misc": ( + ((node_settings_misc) => ({ + "prefix_for_veiled_email_addresses": (node_settings_misc["prefix_for_veiled_email_addresses"] ?? "member-"), + "facultative_membership_number": (node_settings_misc["facultative_membership_number"] ?? false), + "auto_register": (node_settings_misc["auto_register"] ?? false), + })) (node_settings["misc"] ?? {}) + ), + "summon_email": ( + ((node_settings_summon_email) => ({ + "remark": (node_settings_summon_email["remark"] ?? null), + })) (node_settings["summon_email"] ?? {}) + ), + "password_policy": ( + ((node_settings_password_policy) => ({ + "minimum_length": ( + ("minimum_length" in node_settings_password_policy) + ? node_settings_password_policy["minimum_length"] + : 8 + ), + "maximum_length": ( + ("maximum_length" in node_settings_password_policy) + ? node_settings_password_policy["maximum_length"] + : 240 + ), + "must_contain_letter": (node_settings_password_policy["must_contain_letter"] ?? true), + "must_contain_number": (node_settings_password_policy["must_contain_number"] ?? true), + "must_contain_special_character": (node_settings_password_policy["must_contain_special_character"] ?? true), + })) (node_settings["password_policy"] ?? {}) + ), + "password_change": ( + ((node_settings_password_change) => ({ + "cooldown_time": (node_settings_password_change["cooldown_time"] ?? 86400), + })) (node_settings["password_change"] ?? {}) + ), + "name_index": ( + ((node_settings_password_policy) => ({ + "veil": (node_settings_password_policy["veil"] ?? true), + "salt": (node_settings_password_policy["salt"] ?? ""), + })) (node_settings["name_index"] ?? {}) + ), + "connections": ( + ((node_settings_connections) => ({ + "frontend_url_base": (node_settings_connections["frontend_url_base"] ?? null), + "login_url": (node_settings_connections["login_url"] ?? null), + })) (node_settings["connections"] ?? {}) + ), + })) (conf_raw["settings"] ?? {}) + ), + "admins": (conf_raw["admins"] ?? []), + "outputs": ( + ((node_outputs) => node_outputs.map( + (output_description : {kind : string; data : any;}) => { + const kind : string = output_description["kind"]; + const node_options_data_raw = (output_description["data"] ?? {}); + switch (kind) { + case "authelia_file": { + return { + "kind": kind, + "data": { + "path": (node_options_data_raw["path"] ?? "/var/authelia/users.yaml"), + } + }; + break; + } + case "http": { + return { + "kind": kind, + "data": { + "scheme": (node_options_data_raw["scheme"] ?? "http"), + "host": (node_options_data_raw["host"] ?? "localhost"), + "path": (node_options_data_raw["path"] ?? ""), + "method": (node_options_data_raw["method"] ?? "post"), + "query": (node_options_data_raw["query"] ?? null), + "headers": (node_options_data_raw["headers"] ?? {"Content-Type": "application/json"}), + }, + }; + break; + } + case "arc": { + return { + "kind": kind, + "data": { + "http_scheme": (node_options_data_raw["scheme"] ?? "http"), + "http_host": (node_options_data_raw["http_host"] ?? "localhost"), + "http_port": (node_options_data_raw["http_port"] ?? 7463), + "hash_salt": node_options_data_raw["hash_salt"], + } + }; + break; + } + default: { + throw (new Error("unhandled")); + break; + } + } + } + )) (conf_raw["outputs"] ?? []) ), }; break; diff --git a/source/main.ts b/source/main.ts index 51c2afe..9839147 100644 --- a/source/main.ts +++ b/source/main.ts @@ -309,6 +309,7 @@ async function main( } ); + // outputs _espe.service.member.listen_change( () => { lib_plankton.log.info( @@ -316,31 +317,62 @@ async function main( { } ); - } - ); - // outputs - { - if (_espe.conf.get().output.authelia === null) { - // do nothing - } - else { - _espe.service.member.listen_change( - async () => { - const authelia_export : string = await _espe.service.member.export_authelia_user_file(); - lib_plankton.file.write( - _espe.conf.get().output.authelia, - authelia_export + _espe.conf.get().outputs.forEach( + output_description => { + const procedure : (() => Promise) = ( + (() => { + switch (output_description.kind) { + default: { + lib_plankton.log.warning( + "output_kind_unhandled", + { + "description": output_description, + } + ); + return (() => Promise.resolve(undefined)); + break; + } + case "authelia_file": { + return (() => _espe.service.member.output_authelia_file(output_description.data)); + break; + } + case "http": { + return (() => _espe.service.member.output_http(output_description.data)); + break; + } + case "arc": { + return (() => _espe.service.member.output_arc(output_description.data)); + break; + } + } + }) () + ); + ( + procedure() + .then( + () => { + } + ) + .catch( + (error) => { + lib_plankton.log.warning( + "output_procedure_failed", + { + "error": String(error), + } + ); + } + ) ); } ); } - } + ); const rest_subject : lib_plankton.rest.type_rest = _espe.api.make(); const server : lib_plankton.server.type_subject = lib_plankton.server.make( - _espe.conf.get().server.port, async (input, metadata) => { - const http_request : lib_plankton.http.type_request = lib_plankton.http.decode_request(input); + const http_request : lib_plankton.http.type_request = lib_plankton.http.decode_request(input.toString()); const http_response : lib_plankton.http.type_response = await lib_plankton.rest.call( rest_subject, http_request, @@ -352,6 +384,12 @@ async function main( ); const output : string = lib_plankton.http.encode_response(http_response); return output; + }, + { + "host": _espe.conf.get().server.host, + "port": _espe.conf.get().server.port, + // DANGER! DANGER! + "threshold": 0.125, } ); diff --git a/source/services/member.ts b/source/services/member.ts index 15b5354..fb83b6d 100644 --- a/source/services/member.ts +++ b/source/services/member.ts @@ -253,7 +253,7 @@ namespace _espe.service.member /** * gibt die vollständigen Daten aller Mitglieder aus */ - async function dump( + export async function dump( ) : Promise< Array< { @@ -776,11 +776,11 @@ namespace _espe.service.member /** * @todo check validity (e.g. username characters) */ - export async function export_authelia_user_file( + export async function export_authelia_user_data( options : { custom_data ?: (null | Array<_espe.type.member_object>); } = {} - ) : Promise + ) : Promise { options = Object.assign( { @@ -789,8 +789,6 @@ namespace _espe.service.member options ); - const nm_yaml = require("yaml"); - type type_entry = { disabled : boolean; displayname : string; @@ -842,10 +840,163 @@ namespace _espe.service.member ), Object.fromEntries, (x : Record) => ({"users": x}), - (x : {users : Record}) => nm_yaml.stringify(x), ] ); } + + /** + */ + export async function export_authelia_user_file( + options : { + custom_data ?: (null | Array<_espe.type.member_object>); + } = {} + ) : Promise + { + options = Object.assign( + { + "custom_data": null, + }, + options + ); + + const nm_yaml = require("yaml"); + return nm_yaml.stringify(await export_authelia_user_data(options)); + } + + + /** + */ + export async function output_authelia_file( + output_parameters : { + path : string; + } + ) : Promise + { + await lib_plankton.file.write( + output_parameters.path, + await _espe.service.member.export_authelia_user_file() + ); + } + + + /** + */ + export async function output_http( + output_parameters : { + scheme : ("http" | "https"); + host : string; + path : string; + method : ("get" | "post" | "put" | "patch" | "delete" | "head" | "options"); + query : (null | string); + headers : Record; + } + ) : Promise + { + const http_request : lib_plankton.http.type_request = { + "scheme": output_parameters.scheme, + "host": output_parameters.host, + "path": output_parameters.path, + "version": "HTTP/1.1", + "method": ( + ( + { + "get": lib_plankton.http.enum_method.get, + "post": lib_plankton.http.enum_method.post, + "put": lib_plankton.http.enum_method.put, + "patch": lib_plankton.http.enum_method.patch, + "delete": lib_plankton.http.enum_method.delete, + "head": lib_plankton.http.enum_method.head, + "options": lib_plankton.http.enum_method.options, + }[output_parameters.method] + ) + ?? + lib_plankton.http.enum_method.post + ), + "query": output_parameters.query, + "headers": output_parameters.headers, + "body": lib_plankton.json.encode(await _espe.service.member.dump()), + }; + const http_response : lib_plankton.http.type_response = await lib_plankton.http.call( + http_request + ); + if (! ((http_response.status_code >= 200) && (http_response.status_code < 400))) { + lib_plankton.log.warning( + "output_http_failed", + { + "http_request": http_request, + "http_response_status_code": http_response.status_code, + } + ); + } + else { + // do nothing + } + } + + + /** + */ + export async function output_arc( + output_parameters : { + http_scheme : ("http" | "https"); + http_host : string; + http_port : int; + hash_salt : string; + } + ) : Promise + { + const timestamp : float = lib_plankton.base.get_current_timestamp(); + const auth : string = lib_plankton.sha256.get( + timestamp.toFixed(0) + + + output_parameters.hash_salt + ); + const http_request : lib_plankton.http.type_request = { + "scheme": output_parameters.http_scheme, + "host": lib_plankton.string.coin( + "{{host}}:{{port}}", + { + "host": output_parameters.http_host, + "port": output_parameters.http_port.toFixed(0), + } + ), + "path": "/users/set", + "version": "HTTP/1.1", + "method": lib_plankton.http.enum_method.put, + "query": lib_plankton.string.coin( + "?timestamp={{timestamp}}&auth={{auth}}", + { + "timestamp": timestamp.toFixed(0), + "auth": auth, + } + ), + "headers": { + "Content-Type": "application/json", + }, + // @ts-ignore + "body": Buffer.from( + lib_plankton.json.encode( + (await _espe.service.member.export_authelia_user_data()) + ), + "utf8" + ), + }; + const http_response : lib_plankton.http.type_response = await lib_plankton.http.call( + http_request + ); + if (http_response.status_code !== 200) { + lib_plankton.log.warning( + "output_arcback_failed", + { + "http_response_status_code": http_response.status_code, + } + ); + } + else { + // do nothing + } + } + }