diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index ade56fc..3b69962 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -3348,18 +3348,22 @@ declare namespace lib_plankton.http { patch = "patch" } /** - * @author fenris + * @author roydfalk */ - type type_request = { + type type_request_generic = { scheme: ("http" | "https"); host: (null | string); path: string; version: string; - method: enum_method; + method: type_method; query: (null | string); headers: Record; body: (null | Buffer); }; + /** + * @author fenris + */ + type type_request = type_request_generic; /** * @author fenris */ @@ -3375,10 +3379,22 @@ declare namespace lib_plankton.http { * @author fenris */ function encode_method(method: enum_method): string; + /** + * @author fenris + */ + function decode_method(method_raw: string): enum_method; /** * @author fenris */ function encode_request(request: type_request): string; + /** + * @author fenris + */ + function has_body(method: enum_method): boolean; + /** + * @author fenris + */ + function decode_request_generic(decode_method_: ((method_raw: string) => type_method), has_body: ((method: type_method) => boolean), request_raw: string): type_request_generic; /** * @author fenris */ @@ -3442,6 +3458,260 @@ declare namespace lib_plankton.http { decode(x: string): type_response; } } +/** + * @author fenris + */ +declare namespace lib_plankton.xml { + /** + * @author fenris + */ + abstract class class_node { + /** + * @author fenris + */ + abstract compile(depth?: int): string; + } + /** + * @author fenris + */ + class class_node_text extends class_node { + /** + * @author fenris + */ + protected content: string; + /** + * @author fenris + */ + constructor(content: string); + /** + * @author fenris + */ + compile(depth?: int): string; + } + /** + * @author fenris + */ + class class_node_comment extends class_node { + /** + * @author fenris + */ + protected content: string; + /** + * @author fenris + */ + constructor(content: string); + /** + * @author fenris + */ + compile(depth?: int): string; + } + /** + * @author fenris + */ + class class_node_complex extends class_node { + /** + * @author fenris + */ + protected name: string; + /** + * @author fenris + */ + protected attributes: { + [key: string]: string; + }; + /** + * @author fenris + */ + protected children: Array; + /** + * @author fenris + */ + constructor(name: string, attributes?: { + [key: string]: string; + }, children?: any[]); + /** + * @author fenris + */ + compile(depth?: int): string; + } +} +declare namespace lib_plankton.webdav { + /** + * @author roydfalk + */ + enum enum_method { + options = "options", + head = "head", + get = "get", + delete = "delete", + post = "post", + put = "put", + patch = "patch", + propfind = "propfind", + proppatch = "proppatch", + mkcol = "mkcol", + copy = "copy", + move = "move", + lock = "lock", + unlock = "unlock" + } + /** + * @author roydfalk + * @see http://www.webdav.org/specs/rfc2518.html#ELEMENT_href + */ + type type_data_href = string; + /** + * @author roydfalk + * @see http://www.webdav.org/specs/rfc2518.html#ELEMENT_status + */ + type type_data_status = string; + /** + * @author roydfalk + * @see http://www.webdav.org/specs/rfc2518.html#ELEMENT_prop + */ + type type_data_prop = { + name: string; + value: (null | string); + }; + /** + * @author roydfalk + * @see http://www.webdav.org/specs/rfc2518.html#ELEMENT_propstat + */ + type type_data_propstat = { + prop: Array; + status: string; + description: (null | string); + }; + /** + * @author roydfalk + * @see http://www.webdav.org/specs/rfc2518.html#ELEMENT_response + */ + type type_data_response = { + href: type_data_href; + body: ({ + hrefs: Array; + status: string; + } | { + propstats: Array; + }); + description: (null | string); + }; + /** + * @author roydfalk + * @see http://www.webdav.org/specs/rfc2518.html#ELEMENT_multistatus + */ + type type_data_multistatus = { + responses: Array; + description: (null | string); + }; + /** + * @author roydfalk + */ + type type_request = lib_plankton.http.type_request_generic; + /** + * @author roydfalk + */ + type type_response = { + version: (null | string); + status_code: int; + headers: Record; + body: Buffer; + }; +} +declare namespace lib_plankton.webdav { + /** + * @author roydfalk + */ + function is_special_method(method: enum_method): boolean; + /** + * @author roydfalk + */ + function encode_method(method: enum_method): string; + /** + * @author roydfalk + */ + function decode_method(method_raw: string): enum_method; + /** + */ + function data_multistatus_encode(data_multistatus: type_data_multistatus): string; + /** + * @author roydfalk + */ + function has_body(method: enum_method): boolean; + /** + * @author fenris + */ + function decode_request(request_raw: string): type_request; + /** + * @author fenris + * @todo try to base on lib_plankton.http.encode_response + */ + function encode_response(response: type_response): string; +} +declare namespace lib_plankton.caldav { + /** + * @author roydfalk + */ + enum enum_method { + options = "options", + head = "head", + get = "get", + delete = "delete", + post = "post", + put = "put", + patch = "patch", + propfind = "propfind", + proppatch = "proppatch", + mkcol = "mkcol", + copy = "copy", + move = "move", + lock = "lock", + unlock = "unlock", + report = "report", + mkcalendar = "mkcalendar", + acl = "acl" + } + /** + * @author roydfalk + */ + type type_request = lib_plankton.http.type_request_generic; + /** + * @author roydfalk + */ + type type_response = { + version: (null | string); + status_code: int; + headers: Record; + body: Buffer; + }; +} +declare namespace lib_plankton.caldav { + /** + * @author roydfalk + */ + function is_special_method(method: enum_method): boolean; + /** + * @author roydfalk + */ + function encode_method(method: enum_method): string; + /** + * @author roydfalk + */ + function decode_method(method_raw: string): enum_method; + /** + * @author roydfalk + */ + function has_body(method: enum_method): boolean; + /** + * @author fenris + */ + function decode_request(request_raw: string): type_request; + /** + * @author fenris + * @todo try to base on lib_plankton.http.encode_response + */ + function encode_response(response: type_response): string; +} declare namespace lib_plankton.markdown { /** * @author fenris @@ -3586,7 +3856,7 @@ declare namespace lib_plankton.api { generate_documentation(): string; } } -declare namespace lib_plankton.rest { +declare namespace lib_plankton.rest_base { /** */ type type_oas_schema = ({} | { @@ -3689,7 +3959,110 @@ declare namespace lib_plankton.rest { }); }; } -declare namespace lib_plankton.rest { +declare namespace lib_plankton.rest_base { + /** + */ + function make(encode_http_method: ((http_method: type_http_method) => string), options?: { + title?: (null | string); + versioning_method?: ("none" | "path" | "header" | "query"); + versioning_header_name?: (null | string); + versioning_query_key?: (null | string); + header_parameters?: Array<{ + name: string; + description: (null | string); + required: boolean; + }>; + set_access_control_headers?: boolean; + authentication?: ({ + kind: "none"; + parameters: {}; + } | { + kind: "key_header"; + parameters: { + name: string; + }; + }); + actions?: Array<{ + http_method: type_http_method; + path: string; + options: { + active?: ((version: string) => boolean); + restriction?: (null | type_restriction); + execution?: type_execution; + title?: (null | string); + description?: (null | string); + query_parameters?: ((version: string) => Array<{ + name: string; + description: (null | string); + required: boolean; + }>); + input_schema?: ((version: string) => type_oas_schema); + output_schema?: ((version: string) => type_oas_schema); + request_body_mimetype?: string; + request_body_decode?: ((http_request_body: Buffer, http_request_header_content_type: (null | string)) => any); + response_body_mimetype?: string; + response_body_encode?: ((output: any) => Buffer); + }; + }>; + }): type_rest; + /** + */ + function register(encode_http_method: ((http_method: type_http_method) => string), rest: type_rest, http_method: type_http_method, path: string, options: { + active?: ((version: string) => boolean); + restriction?: (null | type_restriction); + execution?: type_execution; + title?: (null | string); + description?: (null | string); + query_parameters?: ((version: string) => Array<{ + name: string; + description: (null | string); + required: boolean; + }>); + input_schema?: ((version: (null | string)) => type_oas_schema); + output_schema?: ((version: (null | string)) => type_oas_schema); + request_body_mimetype?: string; + request_body_decode?: ((http_request_body: Buffer, http_request_header_content_type: (null | string)) => any); + response_body_mimetype?: string; + response_body_encode?: ((output: any) => Buffer); + }): void; + /** + * @todo check request body mimetype? + * @todo check query paramater validity + */ + function call>(encode_http_method: ((http_method: type_http_method) => string), rest: type_rest, http_request: type_http_request, options?: { + checklevel_restriction?: lib_plankton.api.enum_checklevel; + checklevel_input?: lib_plankton.api.enum_checklevel; + checklevel_output?: lib_plankton.api.enum_checklevel; + }): Promise; + /** + * @see https://swagger.io/specification/#openrest-object + */ + function to_oas(http_request_method_to_oas: ((http_request_method: type_method) => string), rest: type_rest, options?: { + version?: (null | string); + servers?: Array; + }): any; +} +declare namespace lib_plankton.rest_http { + /** + */ + type type_oas_schema = lib_plankton.rest_base.type_oas_schema; + /** + */ + type type_execution = lib_plankton.rest_base.type_execution; + /** + */ + type type_restriction = lib_plankton.rest_base.type_restriction; + /** + */ + type type_operation = lib_plankton.rest_base.type_operation; + /** + */ + type type_routenode = lib_plankton.rest_base.type_routenode; + /** + */ + type type_rest = lib_plankton.rest_base.type_rest; +} +declare namespace lib_plankton.rest_http { /** */ function make(options?: { @@ -3772,6 +4145,212 @@ declare namespace lib_plankton.rest { servers?: Array; }): any; } +declare namespace lib_plankton.rest_webdav { + /** + */ + type type_oas_schema = lib_plankton.rest_base.type_oas_schema; + /** + */ + type type_execution = lib_plankton.rest_base.type_execution; + /** + */ + type type_restriction = lib_plankton.rest_base.type_restriction; + /** + */ + type type_operation = lib_plankton.rest_base.type_operation; + /** + */ + type type_routenode = lib_plankton.rest_base.type_routenode; + /** + */ + type type_rest = lib_plankton.rest_base.type_rest; +} +declare namespace lib_plankton.rest_webdav { + /** + */ + function make(options?: { + title?: (null | string); + versioning_method?: ("none" | "path" | "header" | "query"); + versioning_header_name?: (null | string); + versioning_query_key?: (null | string); + header_parameters?: Array<{ + name: string; + description: (null | string); + required: boolean; + }>; + set_access_control_headers?: boolean; + authentication?: ({ + kind: "none"; + parameters: {}; + } | { + kind: "key_header"; + parameters: { + name: string; + }; + }); + actions?: Array<{ + http_method: lib_plankton.webdav.enum_method; + path: string; + options: { + active?: ((version: string) => boolean); + restriction?: (null | type_restriction); + execution?: type_execution; + title?: (null | string); + description?: (null | string); + query_parameters?: ((version: string) => Array<{ + name: string; + description: (null | string); + required: boolean; + }>); + input_schema?: ((version: string) => type_oas_schema); + output_schema?: ((version: string) => type_oas_schema); + request_body_mimetype?: string; + request_body_decode?: ((http_request_body: Buffer, http_request_header_content_type: (null | string)) => any); + response_body_mimetype?: string; + response_body_encode?: ((output: any) => Buffer); + }; + }>; + }): type_rest; + /** + */ + function register(rest: type_rest, http_method: lib_plankton.webdav.enum_method, path: string, options: { + active?: ((version: string) => boolean); + restriction?: (null | type_restriction); + execution?: type_execution; + title?: (null | string); + description?: (null | string); + query_parameters?: ((version: string) => Array<{ + name: string; + description: (null | string); + required: boolean; + }>); + input_schema?: ((version: (null | string)) => type_oas_schema); + output_schema?: ((version: (null | string)) => type_oas_schema); + request_body_mimetype?: string; + request_body_decode?: ((http_request_body: Buffer, http_request_header_content_type: (null | string)) => any); + response_body_mimetype?: string; + response_body_encode?: ((output: any) => Buffer); + }): void; + /** + * @todo check request body mimetype? + * @todo check query paramater validity + */ + function call(rest: type_rest, http_request: lib_plankton.webdav.type_request, options?: { + checklevel_restriction?: lib_plankton.api.enum_checklevel; + checklevel_input?: lib_plankton.api.enum_checklevel; + checklevel_output?: lib_plankton.api.enum_checklevel; + }): Promise; + /** + * @see https://swagger.io/specification/#openrest-object + */ + function to_oas(rest: type_rest, options?: { + version?: (null | string); + servers?: Array; + }): any; +} +declare namespace lib_plankton.rest_caldav { + /** + */ + type type_oas_schema = lib_plankton.rest_base.type_oas_schema; + /** + */ + type type_execution = lib_plankton.rest_base.type_execution; + /** + */ + type type_restriction = lib_plankton.rest_base.type_restriction; + /** + */ + type type_operation = lib_plankton.rest_base.type_operation; + /** + */ + type type_routenode = lib_plankton.rest_base.type_routenode; + /** + */ + type type_rest = lib_plankton.rest_base.type_rest; +} +declare namespace lib_plankton.rest_caldav { + /** + */ + function make(options?: { + title?: (null | string); + versioning_method?: ("none" | "path" | "header" | "query"); + versioning_header_name?: (null | string); + versioning_query_key?: (null | string); + header_parameters?: Array<{ + name: string; + description: (null | string); + required: boolean; + }>; + set_access_control_headers?: boolean; + authentication?: ({ + kind: "none"; + parameters: {}; + } | { + kind: "key_header"; + parameters: { + name: string; + }; + }); + actions?: Array<{ + http_method: lib_plankton.caldav.enum_method; + path: string; + options: { + active?: ((version: string) => boolean); + restriction?: (null | type_restriction); + execution?: type_execution; + title?: (null | string); + description?: (null | string); + query_parameters?: ((version: string) => Array<{ + name: string; + description: (null | string); + required: boolean; + }>); + input_schema?: ((version: string) => type_oas_schema); + output_schema?: ((version: string) => type_oas_schema); + request_body_mimetype?: string; + request_body_decode?: ((http_request_body: Buffer, http_request_header_content_type: (null | string)) => any); + response_body_mimetype?: string; + response_body_encode?: ((output: any) => Buffer); + }; + }>; + }): type_rest; + /** + */ + function register(rest: type_rest, http_method: lib_plankton.caldav.enum_method, path: string, options: { + active?: ((version: string) => boolean); + restriction?: (null | type_restriction); + execution?: type_execution; + title?: (null | string); + description?: (null | string); + query_parameters?: ((version: string) => Array<{ + name: string; + description: (null | string); + required: boolean; + }>); + input_schema?: ((version: (null | string)) => type_oas_schema); + output_schema?: ((version: (null | string)) => type_oas_schema); + request_body_mimetype?: string; + request_body_decode?: ((http_request_body: Buffer, http_request_header_content_type: (null | string)) => any); + response_body_mimetype?: string; + response_body_encode?: ((output: any) => Buffer); + }): void; + /** + * @todo check request body mimetype? + * @todo check query paramater validity + */ + function call(rest: type_rest, http_request: lib_plankton.caldav.type_request, options?: { + checklevel_restriction?: lib_plankton.api.enum_checklevel; + checklevel_input?: lib_plankton.api.enum_checklevel; + checklevel_output?: lib_plankton.api.enum_checklevel; + }): Promise; + /** + * @see https://swagger.io/specification/#openrest-object + */ + function to_oas(rest: type_rest, options?: { + version?: (null | string); + servers?: Array; + }): any; +} declare namespace lib_plankton.server { /** * @author fenris @@ -4359,3 +4938,9 @@ declare namespace lib_plankton.auth.oidc { }>; export {}; } +declare namespace lib_plankton.sha256 { + /** + * @author fenris + */ + function get(value: string, secret?: string): string; +} diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 3ccab96..cf79164 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -11855,6 +11855,7 @@ var lib_plankton; default: throw (new Error("unhandled method: " + method_raw)); } } + http.decode_method = decode_method; /** * @author fenris */ @@ -11957,11 +11958,22 @@ var lib_plankton; /** * @author fenris */ - function decode_request(request_raw) { + function has_body(method) { + return [ + http.enum_method.post, + http.enum_method.put, + http.enum_method.patch + ].includes(method); + } + http.has_body = has_body; + /** + * @author fenris + */ + function decode_request_generic(decode_method_, has_body, request_raw) { const lines = request_raw.split(linebreak); const first = lines.shift(); const parts = first.split(" "); - const method = decode_method(parts[0]); + const method = decode_method_(parts[0]); const path_and_query = parts[1]; const parts_ = path_and_query.split("?"); const path = parts_[0]; @@ -11978,11 +11990,11 @@ var lib_plankton; headers[key.toLowerCase()] = value; } } - const body = ([http.enum_method.post, http.enum_method.put, http.enum_method.patch].includes(method) + const body = (has_body(method) // @ts-ignore ? Buffer.from(lines.join(linebreak)) : null); - const request = { + const request_generic = { // TODO "scheme": "http", "host": (headers["host"] ?? null), @@ -11993,7 +12005,14 @@ var lib_plankton; "headers": headers, "body": body, }; - return request; + return request_generic; + } + http.decode_request_generic = decode_request_generic; + /** + * @author fenris + */ + function decode_request(request_raw) { + return decode_request_generic(decode_method, has_body, request_raw); } http.decode_request = decode_request; /** @@ -12292,6 +12311,740 @@ var lib_plankton; http.class_http_response = class_http_response; })(http = lib_plankton.http || (lib_plankton.http = {})); })(lib_plankton || (lib_plankton = {})); +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +/* +This file is part of »bacterio-plankton:xml«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:xml« 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:xml« 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:xml«. If not, see . + */ +/** + * @author fenris + */ +var lib_plankton; +(function (lib_plankton) { + var xml; + (function (xml) { + /** + * @author fenris + */ + function string_repeat(symbol, count) { + return ((count <= 0) ? "" : (string_repeat(symbol, count - 1) + symbol)); + } + /** + * @author fenris + */ + var class_node = /** @class */ (function () { + function class_node() { + } + return class_node; + }()); + xml.class_node = class_node; + /** + * @author fenris + */ + var class_node_text = /** @class */ (function (_super) { + __extends(class_node_text, _super); + /** + * @author fenris + */ + function class_node_text(content) { + var _this = _super.call(this) || this; + _this.content = content; + return _this; + } + /** + * @author fenris + */ + class_node_text.prototype.compile = function (depth) { + if (depth === void 0) { depth = 0; } + return (string_repeat("\t", depth) + this.content + "\n"); + }; + return class_node_text; + }(class_node)); + xml.class_node_text = class_node_text; + /** + * @author fenris + */ + var class_node_comment = /** @class */ (function (_super) { + __extends(class_node_comment, _super); + /** + * @author fenris + */ + function class_node_comment(content) { + var _this = _super.call(this) || this; + _this.content = content; + return _this; + } + /** + * @author fenris + */ + class_node_comment.prototype.compile = function (depth) { + if (depth === void 0) { depth = 0; } + return (string_repeat("\t", depth) + "" + "\n"); + }; + return class_node_comment; + }(class_node)); + xml.class_node_comment = class_node_comment; + /** + * @author fenris + */ + var class_node_complex = /** @class */ (function (_super) { + __extends(class_node_complex, _super); + /** + * @author fenris + */ + function class_node_complex(name, attributes, children) { + if (attributes === void 0) { attributes = {}; } + if (children === void 0) { children = []; } + var _this = _super.call(this) || this; + _this.name = name; + _this.attributes = attributes; + _this.children = children; + return _this; + } + /** + * @author fenris + */ + class_node_complex.prototype.compile = function (depth) { + var _this = this; + if (depth === void 0) { depth = 0; } + var output = ""; + var attributes = (Object.keys(this.attributes) + .filter(function (key) { return (_this.attributes[key] !== null); }) + .map(function (key) { return (" " + key + "=" + ("\"" + _this.attributes[key] + "\"")); }) + .join("")); + output += (string_repeat("\t", depth) + "<" + this.name + attributes + ">" + "\n"); + this.children.forEach(function (child) { return (output += child.compile(depth + 1)); }); + output += (string_repeat("\t", depth) + "" + "\n"); + return output; + }; + return class_node_complex; + }(class_node)); + xml.class_node_complex = class_node_complex; + })(xml = lib_plankton.xml || (lib_plankton.xml = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:webdav«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:webdav« 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:webdav« 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:webdav«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var webdav; + (function (webdav) { + /** + * @author roydfalk + */ + let enum_method; + (function (enum_method) { + 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["propfind"] = "propfind"; + enum_method["proppatch"] = "proppatch"; + enum_method["mkcol"] = "mkcol"; + enum_method["copy"] = "copy"; + enum_method["move"] = "move"; + enum_method["lock"] = "lock"; + enum_method["unlock"] = "unlock"; + })(enum_method = webdav.enum_method || (webdav.enum_method = {})); + ; + })(webdav = lib_plankton.webdav || (lib_plankton.webdav = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:webdav«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:webdav« 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:webdav« 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:webdav«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var webdav; + (function (webdav) { + /** + * @author fenris + */ + const linebreak = "\r\n"; + /** + * @todo outsource to string module + */ + function capitalize(str) { + return (str[0].toUpperCase() + str.slice(1)); + } + /** + * @todo outsource to string module + */ + function capitalize_all(str) { + return str.split("-").map(x => capitalize(x)).join("-"); + } + /** + * @author roydfalk + */ + function is_special_method(method) { + return ((method === webdav.enum_method.propfind) + || + (method === webdav.enum_method.proppatch) + || + (method === webdav.enum_method.mkcol) + || + (method === webdav.enum_method.copy) + || + (method === webdav.enum_method.move) + || + (method === webdav.enum_method.lock) + || + (method === webdav.enum_method.unlock)); + } + webdav.is_special_method = is_special_method; + /** + * @author roydfalk + */ + function encode_method(method) { + switch (method) { + case webdav.enum_method.get: return "GET"; + case webdav.enum_method.post: return "POST"; + case webdav.enum_method.patch: return "PATCH"; + case webdav.enum_method.put: return "PUT"; + case webdav.enum_method.delete: return "DELETE"; + case webdav.enum_method.options: return "OPTIONS"; + case webdav.enum_method.head: return "HEAD"; + case webdav.enum_method.propfind: return "PROPFIND"; + case webdav.enum_method.proppatch: return "PROPPATCH"; + case webdav.enum_method.mkcol: return "MKCOL"; + case webdav.enum_method.copy: return "COPY"; + case webdav.enum_method.move: return "MOVE"; + case webdav.enum_method.lock: return "LOCK"; + case webdav.enum_method.unlock: return "UNLOCK"; + default: throw (new Error("impossible")); + } + } + webdav.encode_method = encode_method; + /** + * @author roydfalk + */ + function decode_method(method_raw) { + switch (method_raw) { + case "GET": return webdav.enum_method.get; + case "POST": return webdav.enum_method.post; + case "PATCH": return webdav.enum_method.patch; + case "PUT": return webdav.enum_method.put; + case "DELETE": return webdav.enum_method.delete; + case "OPTIONS": return webdav.enum_method.options; + case "HEAD": return webdav.enum_method.head; + case "PROPFIND": return webdav.enum_method.propfind; + case "PROPPATCH": return webdav.enum_method.proppatch; + case "MKCOL": return webdav.enum_method.mkcol; + case "COPY": return webdav.enum_method.copy; + case "MOVE": return webdav.enum_method.move; + case "LOCK": return webdav.enum_method.lock; + case "UNLOCK": return webdav.enum_method.unlock; + default: throw (new Error("unhandled method: " + method_raw)); + } + } + webdav.decode_method = decode_method; + /** + * @author fenris + */ + function get_statustext(statuscode) { + switch (statuscode) { + case 100: return "Continue"; + case 101: return "Switching Protocols"; + case 103: return "Early Hints"; + case 200: return "OK"; + case 201: return "Created"; + case 202: return "Accepted"; + case 203: return "Non-Authoritative Information"; + case 204: return "No Content"; + case 205: return "Reset Content"; + case 206: return "Partial Content"; + case 207: return "Multistatus"; + case 300: return "Multiple Choices"; + case 301: return "Moved Permanently"; + case 302: return "Found"; + case 303: return "See Other"; + case 304: return "Not Modified"; + case 307: return "Temporary Redirect"; + case 308: return "Permanent Redirect"; + case 400: return "Bad Request"; + case 401: return "Unauthorized"; + case 402: return "Payment Required"; + case 403: return "Forbidden"; + case 404: return "Not Found"; + case 405: return "Method Not Allowed"; + case 406: return "Not Acceptable"; + case 407: return "Proxy Authentication Required"; + case 408: return "Request Timeout"; + case 409: return "Conflict"; + case 410: return "Gone"; + case 411: return "Length Required"; + case 412: return "Precondition Failed"; + case 413: return "Payload Too Large"; + case 414: return "URI Too Long"; + case 415: return "Unsupported Media Type"; + case 416: return "Range Not Satisfiable"; + case 417: return "Expectation Failed"; + case 418: return "I'm a teapot"; + case 422: return "Unprocessable Entity"; + case 425: return "Too Early"; + case 426: return "Upgrade Required"; + case 428: return "Precondition Required"; + case 429: return "Too Many Requests"; + case 431: return "Request Header Fields Too Large"; + case 451: return "Unavailable For Legal Reasons"; + case 500: return "Internal Server Error"; + case 501: return "Not Implemented"; + case 502: return "Bad Gateway"; + case 503: return "Service Unavailable"; + case 504: return "Gateway Timeout"; + case 505: return "HTTP Version Not Supported"; + case 506: return "Variant Also Negotiates"; + case 507: return "Insufficient Storage"; + case 508: return "Loop Detected"; + case 510: return "Not Extended"; + case 511: return "Network Authentication"; + default: throw (new Error("unhandled statuscode: " + statuscode.toFixed(0))); + } + } + /** + */ + function data_href_encode_xml(data_href) { + return (new lib_plankton.xml.class_node_complex("d:href", {}, [ + new lib_plankton.xml.class_node_text(data_href), + ])); + } + /** + */ + function data_status_encode_xml(data_status) { + return (new lib_plankton.xml.class_node_complex("d:status", {}, [ + new lib_plankton.xml.class_node_text(data_status), + ])); + } + /** + */ + function data_prop_encode_xml(data_prop) { + return (new lib_plankton.xml.class_node_complex(data_prop.name, {}, [ + new lib_plankton.xml.class_node_text(data_prop.value ?? ""), + ])); + } + /** + */ + function data_propstat_encode_xml(data_propstat) { + return (new lib_plankton.xml.class_node_complex("d:propstat", { + // todo xmlns:R + }, [ + new lib_plankton.xml.class_node_complex("d:prop", { + // todo xmlns:R + }, data_propstat.prop.map(data_prop_encode_xml)), + data_status_encode_xml(data_propstat.status), + ])); + } + /** + */ + function data_response_encode_xml(data_response) { + return (new lib_plankton.xml.class_node_complex("d:response", {}, ([ + data_href_encode_xml(data_response.href), + ] + .concat(("hrefs" in data_response.body) + ? + (data_response.body.hrefs.map(data_href_encode_xml) + .concat([ + data_status_encode_xml(data_response.body.status), + ])) + : + data_response.body.propstats.map(data_propstat_encode_xml))))); + } + /** + */ + function data_multistatus_encode_xml(data_multistatus) { + return (new lib_plankton.xml.class_node_complex("d:multistatus", { + "xmlns:d": "DAV:", + }, (data_multistatus.responses.map(data_response_encode_xml) + .concat()))); + } + /** + */ + function data_multistatus_encode(data_multistatus) { + return data_multistatus_encode_xml(data_multistatus).compile(); + } + webdav.data_multistatus_encode = data_multistatus_encode; + /** + * @author roydfalk + */ + function has_body(method) { + return [ + webdav.enum_method.post, + webdav.enum_method.put, + webdav.enum_method.patch, + webdav.enum_method.propfind, + webdav.enum_method.proppatch, + webdav.enum_method.mkcol, + webdav.enum_method.copy, + webdav.enum_method.move, + webdav.enum_method.lock, + webdav.enum_method.unlock, // TODO verify + ].includes(method); + } + webdav.has_body = has_body; + /** + * @author fenris + */ + function decode_request(request_raw) { + return lib_plankton.http.decode_request_generic(decode_method, has_body, request_raw); + } + webdav.decode_request = decode_request; + /** + * @author fenris + * @todo try to base on lib_plankton.http.encode_response + */ + function encode_response(response) { + let response_raw = ""; + response_raw += (response.version + + + " " + + + response.status_code.toFixed(0) + + + " " + + + get_statustext(response.status_code) + + + linebreak); + for (const [key, value] of Object.entries(response.headers)) { + response_raw += (capitalize_all(key) + ": " + value + linebreak); + } + response_raw += linebreak; + response_raw += response.body; + return response_raw; + } + webdav.encode_response = encode_response; + })(webdav = lib_plankton.webdav || (lib_plankton.webdav = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:caldav«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:caldav« 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:caldav« 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:caldav«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var caldav; + (function (caldav) { + /** + * @author roydfalk + */ + let enum_method; + (function (enum_method) { + 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["propfind"] = "propfind"; + enum_method["proppatch"] = "proppatch"; + enum_method["mkcol"] = "mkcol"; + enum_method["copy"] = "copy"; + enum_method["move"] = "move"; + enum_method["lock"] = "lock"; + enum_method["unlock"] = "unlock"; + enum_method["report"] = "report"; + enum_method["mkcalendar"] = "mkcalendar"; + enum_method["acl"] = "acl"; + })(enum_method = caldav.enum_method || (caldav.enum_method = {})); + ; + })(caldav = lib_plankton.caldav || (lib_plankton.caldav = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:caldav«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:caldav« 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:caldav« 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:caldav«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var caldav; + (function (caldav) { + /** + * @author fenris + */ + const linebreak = "\r\n"; + /** + * @todo outsource to string module + */ + function capitalize(str) { + return (str[0].toUpperCase() + str.slice(1)); + } + /** + * @todo outsource to string module + */ + function capitalize_all(str) { + return str.split("-").map(x => capitalize(x)).join("-"); + } + /** + * @author roydfalk + */ + function is_special_method(method) { + return ((method === caldav.enum_method.report) + || + (method === caldav.enum_method.mkcalendar) + || + (method === caldav.enum_method.acl)); + } + caldav.is_special_method = is_special_method; + /** + * @author roydfalk + */ + function encode_method(method) { + switch (method) { + case caldav.enum_method.get: return "GET"; + case caldav.enum_method.post: return "POST"; + case caldav.enum_method.patch: return "PATCH"; + case caldav.enum_method.put: return "PUT"; + case caldav.enum_method.delete: return "DELETE"; + case caldav.enum_method.options: return "OPTIONS"; + case caldav.enum_method.head: return "HEAD"; + case caldav.enum_method.propfind: return "PROPFIND"; + case caldav.enum_method.proppatch: return "PROPPATCH"; + case caldav.enum_method.mkcol: return "MKCOL"; + case caldav.enum_method.copy: return "COPY"; + case caldav.enum_method.move: return "MOVE"; + case caldav.enum_method.lock: return "LOCK"; + case caldav.enum_method.unlock: return "UNLOCK"; + case caldav.enum_method.report: return "REPORT"; + case caldav.enum_method.mkcalendar: return "MKCALENDAR"; + case caldav.enum_method.acl: return "ACL"; + default: throw (new Error("impossible")); + } + } + caldav.encode_method = encode_method; + /** + * @author roydfalk + */ + function decode_method(method_raw) { + switch (method_raw) { + case "GET": return caldav.enum_method.get; + case "POST": return caldav.enum_method.post; + case "PATCH": return caldav.enum_method.patch; + case "PUT": return caldav.enum_method.put; + case "DELETE": return caldav.enum_method.delete; + case "OPTIONS": return caldav.enum_method.options; + case "HEAD": return caldav.enum_method.head; + case "PROPFIND": return caldav.enum_method.propfind; + case "PROPPATCH": return caldav.enum_method.proppatch; + case "MKCOL": return caldav.enum_method.mkcol; + case "COPY": return caldav.enum_method.copy; + case "MOVE": return caldav.enum_method.move; + case "LOCK": return caldav.enum_method.lock; + case "UNLOCK": return caldav.enum_method.unlock; + case "REPORT": return caldav.enum_method.report; + case "MKCALENDAR": return caldav.enum_method.mkcalendar; + case "ACL": return caldav.enum_method.acl; + default: throw (new Error("unhandled method: " + method_raw)); + } + } + caldav.decode_method = decode_method; + /** + * @author fenris + */ + function get_statustext(statuscode) { + switch (statuscode) { + case 100: return "Continue"; + case 101: return "Switching Protocols"; + case 103: return "Early Hints"; + case 200: return "OK"; + case 201: return "Created"; + case 202: return "Accepted"; + case 203: return "Non-Authoritative Information"; + case 204: return "No Content"; + case 205: return "Reset Content"; + case 206: return "Partial Content"; + case 207: return "Multistatus"; + case 300: return "Multiple Choices"; + case 301: return "Moved Permanently"; + case 302: return "Found"; + case 303: return "See Other"; + case 304: return "Not Modified"; + case 307: return "Temporary Redirect"; + case 308: return "Permanent Redirect"; + case 400: return "Bad Request"; + case 401: return "Unauthorized"; + case 402: return "Payment Required"; + case 403: return "Forbidden"; + case 404: return "Not Found"; + case 405: return "Method Not Allowed"; + case 406: return "Not Acceptable"; + case 407: return "Proxy Authentication Required"; + case 408: return "Request Timeout"; + case 409: return "Conflict"; + case 410: return "Gone"; + case 411: return "Length Required"; + case 412: return "Precondition Failed"; + case 413: return "Payload Too Large"; + case 414: return "URI Too Long"; + case 415: return "Unsupported Media Type"; + case 416: return "Range Not Satisfiable"; + case 417: return "Expectation Failed"; + case 418: return "I'm a teapot"; + case 422: return "Unprocessable Entity"; + case 425: return "Too Early"; + case 426: return "Upgrade Required"; + case 428: return "Precondition Required"; + case 429: return "Too Many Requests"; + case 431: return "Request Header Fields Too Large"; + case 451: return "Unavailable For Legal Reasons"; + case 500: return "Internal Server Error"; + case 501: return "Not Implemented"; + case 502: return "Bad Gateway"; + case 503: return "Service Unavailable"; + case 504: return "Gateway Timeout"; + case 505: return "HTTP Version Not Supported"; + case 506: return "Variant Also Negotiates"; + case 507: return "Insufficient Storage"; + case 508: return "Loop Detected"; + case 510: return "Not Extended"; + case 511: return "Network Authentication"; + default: throw (new Error("unhandled statuscode: " + statuscode.toFixed(0))); + } + } + /** + * @author roydfalk + */ + function has_body(method) { + return [ + caldav.enum_method.post, + caldav.enum_method.put, + caldav.enum_method.patch, + caldav.enum_method.propfind, + caldav.enum_method.proppatch, + caldav.enum_method.mkcol, + caldav.enum_method.copy, + caldav.enum_method.move, + caldav.enum_method.lock, + caldav.enum_method.unlock, + caldav.enum_method.mkcalendar, // TODO verify + ].includes(method); + } + caldav.has_body = has_body; + /** + * @author fenris + */ + function decode_request(request_raw) { + return lib_plankton.http.decode_request_generic(decode_method, has_body, request_raw); + } + caldav.decode_request = decode_request; + /** + * @author fenris + * @todo try to base on lib_plankton.http.encode_response + */ + function encode_response(response) { + let response_raw = ""; + response_raw += (response.version + + + " " + + + response.status_code.toFixed(0) + + + " " + + + get_statustext(response.status_code) + + + linebreak); + for (const [key, value] of Object.entries(response.headers)) { + response_raw += (capitalize_all(key) + ": " + value + linebreak); + } + response_raw += linebreak; + response_raw += response.body; + return response_raw; + } + caldav.encode_response = encode_response; + })(caldav = lib_plankton.caldav || (lib_plankton.caldav = {})); +})(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:markdown«. @@ -12702,61 +13455,47 @@ var lib_plankton; })(api = lib_plankton.api || (lib_plankton.api = {})); })(lib_plankton || (lib_plankton = {})); /* -This file is part of »bacterio-plankton:rest«. +This file is part of »bacterio-plankton:rest_base«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:rest« is free software: you can redistribute it and/or modify +»bacterio-plankton:rest_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:rest« is distributed in the hope that it will be useful, +»bacterio-plankton:rest_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:rest«. If not, see . +along with »bacterio-plankton:rest_base«. If not, see . */ /* -This file is part of »bacterio-plankton:rest«. +This file is part of »bacterio-plankton:rest_base«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:rest« is free software: you can redistribute it and/or modify +»bacterio-plankton:rest_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:rest« is distributed in the hope that it will be useful, +»bacterio-plankton:rest_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:rest«. If not, see . +along with »bacterio-plankton:rest_base«. If not, see . */ var lib_plankton; (function (lib_plankton) { - var rest; - (function (rest_1) { - /** - */ - function http_request_method_to_oas(http_request_method) { - switch (http_request_method) { - 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 "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 "put"; - default: throw (new Error("impossible")); - } - } + var rest_base; + (function (rest_base) { /** */ function wildcard_step_decode(step) { @@ -12795,11 +13534,11 @@ var lib_plankton; } /** */ - function routenode_spawn(steps, http_method, operation) { + function routenode_spawn(encode_http_method, steps, http_method, operation) { let routenode; if (steps.length <= 0) { routenode = { - "operations": Object.fromEntries([[http_method, operation]]), + "operations": Object.fromEntries([[encode_http_method(http_method).toLowerCase(), operation]]), "sub_branch": {}, "sub_wildcard": null, }; @@ -12807,7 +13546,7 @@ var lib_plankton; else { const steps_head = steps[0]; const steps_tail = steps.slice(1); - const sub = routenode_spawn(steps_tail, http_method, operation); + const sub = routenode_spawn(encode_http_method, steps_tail, http_method, operation); const wildcard_name = wildcard_step_decode(steps_head); if (wildcard_name === null) { // branch @@ -12884,12 +13623,13 @@ var lib_plankton; } /** */ - function routenode_path_write(routenode, steps, http_method, operation, options = {}) { + function routenode_path_write(encode_http_method, routenode, steps, http_method, operation, options = {}) { options = lib_plankton.object.patched({ "create": false, }, options); + const http_method_encoded = encode_http_method(http_method).toLowerCase(); if (steps.length <= 0) { - if (!(http_method in routenode.operations)) { + if (!(http_method_encoded in routenode.operations)) { // do nothing } else { @@ -12898,7 +13638,7 @@ var lib_plankton; "steps": steps, }); } - routenode.operations[http_method] = operation; + routenode.operations[http_method_encoded] = operation; } else { const steps_head = steps[0]; @@ -12913,7 +13653,7 @@ var lib_plankton; else { routenode.sub_wildcard = { "name": wildcard_name, - "node": routenode_spawn(steps_tail, http_method, operation), + "node": routenode_spawn(encode_http_method, steps_tail, http_method, operation), }; } } @@ -12931,14 +13671,14 @@ var lib_plankton; } else { // walk - routenode_path_write(routenode.sub_wildcard.node, steps_tail, http_method, operation, options); + routenode_path_write(encode_http_method, routenode.sub_wildcard.node, steps_tail, http_method, operation, options); } } } else { if (steps_head in routenode.sub_branch) { // walk branch - routenode_path_write(routenode.sub_branch[steps_head], steps_tail, http_method, operation, options); + routenode_path_write(encode_http_method, routenode.sub_branch[steps_head], steps_tail, http_method, operation, options); } else { // add branch @@ -12946,7 +13686,7 @@ var lib_plankton; throw (new Error("may not create missing route")); } else { - routenode.sub_branch[steps_head] = routenode_spawn(steps_tail, http_method, operation); + routenode.sub_branch[steps_head] = routenode_spawn(encode_http_method, steps_tail, http_method, operation); } } } @@ -12954,7 +13694,7 @@ var lib_plankton; } /** */ - function make(options = {}) { + function make(encode_http_method, options = {}) { options = lib_plankton.object.patched({ "title": "REST-API", "versioning_method": "none", @@ -12982,15 +13722,15 @@ var lib_plankton; "set_access_control_headers": options.set_access_control_headers, "authentication": options.authentication, }; - options.actions.forEach(action_definition => { - rest.register(subject, action_definition.http_method, action_definition.path, action_definition.options); + options.actions.forEach((action_definition) => { + register(encode_http_method, subject, action_definition.http_method, action_definition.path, action_definition.options); }); return subject; } - rest_1.make = make; + rest_base.make = make; /** */ - function register(rest, http_method, path, options) { + function register(encode_http_method, rest, http_method, path, options) { options = lib_plankton.object.patched({ "active": ((version) => true), "execution": ((stuff) => Promise.resolve({ "status_code": 501, "data": null })), @@ -13020,7 +13760,8 @@ var lib_plankton; const steps_enriched = ((rest.versioning_method === "path") ? ["{version}"].concat(steps) : steps); - const action_name = (steps.concat([lib_plankton.http.encode_method(http_method).toLowerCase()]) + const http_method_encoded = encode_http_method(http_method).toLowerCase(); + const action_name = (steps.concat([http_method_encoded]) .join("_")); const operation = { "action_name": action_name, @@ -13032,7 +13773,7 @@ var lib_plankton; "input_schema": options.input_schema, "output_schema": options.output_schema, }; - routenode_path_write(rest.routetree, steps_enriched, http_method, operation, { + routenode_path_write(encode_http_method, rest.routetree, steps_enriched, http_method, operation, { "create": true, }); lib_plankton.api.register(rest.api, action_name, { @@ -13062,12 +13803,12 @@ var lib_plankton; // "routetree": rest.routetree, }); } - rest_1.register = register; + rest_base.register = register; /** * @todo check request body mimetype? * @todo check query paramater validity */ - async function call(rest, http_request, options = {}) { + async function call(encode_http_method, rest, http_request, options = {}) { options = /*lib_plankton.object.patched*/ Object.assign({ "checklevel_restriction": lib_plankton.api.enum_checklevel.hard, "checklevel_input": lib_plankton.api.enum_checklevel.soft, @@ -13101,7 +13842,6 @@ var lib_plankton; // resolve const stuff = routenode_path_read(rest.routetree, steps); const allowed_methods = (Object.keys(stuff.routenode.operations) - .map(x => lib_plankton.http.encode_method(x)) .join(", ")); // get version let version; @@ -13165,7 +13905,8 @@ var lib_plankton; }; } else { - if (!(http_request.method in stuff.routenode.operations)) { + const http_method_encoded = encode_http_method(http_request.method).toLowerCase(); + if (!(http_method_encoded in stuff.routenode.operations)) { if (Object.keys(stuff.routenode.operations).length <= 0) { return { "version": "HTTP/1.1", @@ -13189,7 +13930,7 @@ var lib_plankton; // call let result; let error; - const operation = stuff.routenode.operations[http_request.method]; + const operation = stuff.routenode.operations[http_method_encoded]; const stuff_ = { "version": version, "headers": http_request.headers, @@ -13314,11 +14055,11 @@ var lib_plankton; } } } - rest_1.call = call; + rest_base.call = call; /** * @see https://swagger.io/specification/#openrest-object */ - function to_oas(rest, options = {}) { + function to_oas(http_request_method_to_oas, rest, options = {}) { options = lib_plankton.object.patched({ "version": null, "servers": [], @@ -13453,8 +14194,280 @@ var lib_plankton; ]) }; } - rest_1.to_oas = to_oas; - })(rest = lib_plankton.rest || (lib_plankton.rest = {})); + rest_base.to_oas = to_oas; + })(rest_base = lib_plankton.rest_base || (lib_plankton.rest_base = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:rest_http«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:rest_http« 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:rest_http« 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:rest_http«. If not, see . + */ +/* +This file is part of »bacterio-plankton:rest_http«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:rest_http« 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:rest_http« 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:rest_http«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var rest_http; + (function (rest_http) { + /** + */ + function http_request_method_to_oas(http_request_method) { + switch (http_request_method) { + 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 "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 "put"; + default: throw (new Error("impossible")); + } + } + /** + */ + function make(options = {}) { + return lib_plankton.rest_base.make(lib_plankton.http.encode_method, options); + } + rest_http.make = make; + /** + */ + function register(rest, http_method, path, options) { + lib_plankton.rest_base.register(lib_plankton.http.encode_method, rest, http_method, path, options); + } + rest_http.register = register; + /** + * @todo check request body mimetype? + * @todo check query paramater validity + */ + async function call(rest, http_request, options = {}) { + return lib_plankton.rest_base.call(lib_plankton.http.encode_method, rest, http_request, options); + } + rest_http.call = call; + /** + * @see https://swagger.io/specification/#openrest-object + */ + function to_oas(rest, options = {}) { + return lib_plankton.rest_base.to_oas(http_request_method_to_oas, rest, options); + } + rest_http.to_oas = to_oas; + })(rest_http = lib_plankton.rest_http || (lib_plankton.rest_http = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:rest_webdav«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:rest_webdav« 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:rest_webdav« 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:rest_webdav«. If not, see . + */ +/* +This file is part of »bacterio-plankton:rest_webdav«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:rest_webdav« 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:rest_webdav« 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:rest_webdav«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var rest_webdav; + (function (rest_webdav) { + /** + */ + function http_request_method_to_oas(http_request_method) { + switch (http_request_method) { + case lib_plankton.webdav.enum_method.get: return "get"; + case lib_plankton.webdav.enum_method.post: return "post"; + case lib_plankton.webdav.enum_method.patch: return "patch"; + case lib_plankton.webdav.enum_method.head: return "head"; + case lib_plankton.webdav.enum_method.delete: return "delete"; + case lib_plankton.webdav.enum_method.options: return "options"; + case lib_plankton.webdav.enum_method.put: return "put"; + case lib_plankton.webdav.enum_method.propfind: return "PROPFIND"; + case lib_plankton.webdav.enum_method.proppatch: return "PROPPATCH"; + case lib_plankton.webdav.enum_method.mkcol: return "MKCOL"; + case lib_plankton.webdav.enum_method.copy: return "COPY"; + case lib_plankton.webdav.enum_method.move: return "MOVE"; + case lib_plankton.webdav.enum_method.lock: return "LOCK"; + case lib_plankton.webdav.enum_method.unlock: return "UNLOCK"; + default: throw (new Error("impossible")); + } + } + /** + */ + function make(options = {}) { + return lib_plankton.rest_base.make(lib_plankton.webdav.encode_method, options); + } + rest_webdav.make = make; + /** + */ + function register(rest, http_method, path, options) { + lib_plankton.rest_base.register(lib_plankton.webdav.encode_method, rest, http_method, path, options); + } + rest_webdav.register = register; + /** + * @todo check request body mimetype? + * @todo check query paramater validity + */ + async function call(rest, http_request, options = {}) { + return lib_plankton.rest_base.call(lib_plankton.webdav.encode_method, rest, http_request, options); + } + rest_webdav.call = call; + /** + * @see https://swagger.io/specification/#openrest-object + */ + function to_oas(rest, options = {}) { + return lib_plankton.rest_base.to_oas(http_request_method_to_oas, rest, options); + } + rest_webdav.to_oas = to_oas; + })(rest_webdav = lib_plankton.rest_webdav || (lib_plankton.rest_webdav = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:rest_caldav«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:rest_caldav« 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:rest_caldav« 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:rest_caldav«. If not, see . + */ +/* +This file is part of »bacterio-plankton:rest_caldav«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:rest_caldav« 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:rest_caldav« 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:rest_caldav«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var rest_caldav; + (function (rest_caldav) { + /** + */ + function http_request_method_to_oas(http_request_method) { + switch (http_request_method) { + case lib_plankton.caldav.enum_method.get: return "get"; + case lib_plankton.caldav.enum_method.post: return "post"; + case lib_plankton.caldav.enum_method.patch: return "patch"; + case lib_plankton.caldav.enum_method.head: return "head"; + case lib_plankton.caldav.enum_method.delete: return "delete"; + case lib_plankton.caldav.enum_method.options: return "options"; + case lib_plankton.caldav.enum_method.put: return "put"; + case lib_plankton.caldav.enum_method.propfind: return "PROPFIND"; + case lib_plankton.caldav.enum_method.proppatch: return "PROPPATCH"; + case lib_plankton.caldav.enum_method.mkcol: return "MKCOL"; + case lib_plankton.caldav.enum_method.copy: return "COPY"; + case lib_plankton.caldav.enum_method.move: return "MOVE"; + case lib_plankton.caldav.enum_method.lock: return "LOCK"; + case lib_plankton.caldav.enum_method.unlock: return "UNLOCK"; + case lib_plankton.caldav.enum_method.report: return "REPORT"; + case lib_plankton.caldav.enum_method.mkcalendar: return "MKCALENDAR"; + case lib_plankton.caldav.enum_method.acl: return "ACL"; + default: throw (new Error("impossible")); + } + } + /** + */ + function make(options = {}) { + return lib_plankton.rest_base.make(lib_plankton.caldav.encode_method, options); + } + rest_caldav.make = make; + /** + */ + function register(rest, http_method, path, options) { + lib_plankton.rest_base.register(lib_plankton.caldav.encode_method, rest, http_method, path, options); + } + rest_caldav.register = register; + /** + * @todo check request body mimetype? + * @todo check query paramater validity + */ + async function call(rest, http_request, options = {}) { + return lib_plankton.rest_base.call(lib_plankton.caldav.encode_method, rest, http_request, options); + } + rest_caldav.call = call; + /** + * @see https://swagger.io/specification/#openrest-object + */ + function to_oas(rest, options = {}) { + return lib_plankton.rest_base.to_oas(http_request_method_to_oas, rest, options); + } + rest_caldav.to_oas = to_oas; + })(rest_caldav = lib_plankton.rest_caldav || (lib_plankton.rest_caldav = {})); })(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:server«. @@ -15472,3 +16485,38 @@ var lib_plankton; })(oidc = auth.oidc || (auth.oidc = {})); })(auth = lib_plankton.auth || (lib_plankton.auth = {})); })(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:sha256«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:sha256« 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:sha256« 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:sha256«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var sha256; + (function (sha256) { + /** + * @author fenris + */ + function get(value, secret = "") { + const nm_crypto = require("crypto"); + const sha256Hasher = nm_crypto.createHmac("sha256", secret); + const hash = sha256Hasher.update(value).digest("hex"); + return hash; + } + sha256.get = get; + })(sha256 = lib_plankton.sha256 || (lib_plankton.sha256 = {})); +})(lib_plankton || (lib_plankton = {})); diff --git a/source/api/actions/caldav_get.ts b/source/api/actions/caldav_get.ts new file mode 100644 index 0000000..8812e8a --- /dev/null +++ b/source/api/actions/caldav_get.ts @@ -0,0 +1,166 @@ + +namespace _zeitbild.api +{ + + /** + */ + export function register_caldav_get( + rest_subject : lib_plankton.rest_caldav.type_rest + ) : void + { + register< + null, + ( + lib_plankton.ical.type_vcalendar + | + string + ) + >( + rest_subject, + lib_plankton.caldav.enum_method.report, + "/caldav", + { + "description": "trägt Veranstaltungen aus verschiedenen Kalendern zusammen im ical-Format", + "query_parameters": () => ([ + { + "name": "from", + "required": false, + "description": "UNIX timestamp", + }, + { + "name": "to", + "required": false, + "description": "UNIX timestamp", + }, + { + "name": "calendar_ids", + "required": false, + "description": "comma separated", + }, + { + "name": "auth", + "required": true, + "description": "", + }, + ]), + "output_schema": () => ({ + "nullable": false, + "type": "string", + }), + "response_body_mimetype": "text/calendar", + "response_body_encode": (output) => Buffer.from( + (typeof(output) === "string") + ? + output + : + lib_plankton.ical.ics_encode(output) + ), + "restriction": restriction_none, + "execution": async (stuff) => { + const user_id : (null | _zeitbild.type_user_id) = await ( + session_from_stuff(stuff) + .then( + (session : {key : string; value : lib_plankton.session.type_session;}) => ( + _zeitbild.service.user.identify(session.value.name) + .catch(x => Promise.resolve(null)) + ) + ) + .catch(x => Promise.resolve(null)) + ); + + const from : lib_plankton.pit.type_pit = ( + ("from" in stuff.query_parameters) + ? + parseInt(stuff.query_parameters["from"]) + : + lib_plankton.pit.shift_week( + lib_plankton.pit.now(), + -2 + ) + ); + const to : lib_plankton.pit.type_pit = ( + ("to" in stuff.query_parameters) + ? + parseInt(stuff.query_parameters["to"]) + : + lib_plankton.pit.shift_week( + lib_plankton.pit.now(), + +6 + ) + ); + const calendar_ids_wanted : (null | Array<_zeitbild.type_calendar_id>) = ( + ( + ("calendar_ids" in stuff.query_parameters) + && + (stuff.query_parameters["calendar_ids"] !== null) + ) + ? + lib_plankton.call.convey( + stuff.query_parameters["calendar_ids"], + [ + (x : string) => x.split(","), + (x : Array) => x.map(parseInt), + (x : Array) => x.filter(y => (! isNaN(y))) + ] + ) + : + null + ); + + const auth_hash_shall : string = lib_plankton.sha256.get( + (stuff.query_parameters["calendar_ids"] ?? ""), + _zeitbild.conf.get()["misc"]["auth_salt"] + ); + const auth_hash_is : string = stuff.query_parameters["auth"]; + /** + * @todo remove + */ + lib_plankton.log.info( + "auth_hashes", + { + "shall": auth_hash_shall, + "is": auth_hash_is, + } + ); + if (! (auth_hash_is === auth_hash_shall)) { + return Promise.resolve( + { + "status_code": 403, + "data": "not authorized", + } + ); + } + else { + return ( + _zeitbild.service.calendar.gather_events( + calendar_ids_wanted, + from, + to, + user_id + ) + .then( + (data) => Promise.resolve( + { + "status_code": 200, + "data": _zeitbild.helpers.ical_vcalendar_from_own_event_list( + data.map(entry => entry.event_object) + ) + } + ) + ) + .catch( + (reason) => Promise.resolve( + { + "status_code": 403, + "data": String(reason), + } + ) + ) + ); + } + } + } + ); + } + +} diff --git a/source/api/actions/caldav_probe.ts b/source/api/actions/caldav_probe.ts new file mode 100644 index 0000000..58b80e2 --- /dev/null +++ b/source/api/actions/caldav_probe.ts @@ -0,0 +1,100 @@ + +namespace _zeitbild.api +{ + + /** + */ + export function register_caldav_probe( + rest_subject : lib_plankton.rest_caldav.type_rest + ) : void + { + register< + any, + any + >( + rest_subject, + lib_plankton.caldav.enum_method.propfind, + "/caldav", + { + "query_parameters": () => ([ + { + "name": "from", + "required": false, + "description": "UNIX timestamp", + }, + { + "name": "to", + "required": false, + "description": "UNIX timestamp", + }, + { + "name": "calendar_ids", + "required": false, + "description": "comma separated", + }, + { + "name": "auth", + "required": true, + "description": "", + }, + ]), + "output_schema": () => ({ + "nullable": false, + "type": "string", + }), + "response_body_mimetype": "application/xml", + "response_body_encode": output => Buffer.from(output), + "restriction": restriction_none, + /** + * @todo examine body + */ + "execution": async (stuff) => { + return Promise.resolve( + { + "status_code": 207, + "data": ( + /*"\n" + +*/ + lib_plankton.webdav.data_multistatus_encode( + { + "responses": [ + { + "href": "/caldav/events", + "body": { + "propstats": [ + { + "prop": [ + {"name": "d:displayname", "value": "default"}, + // {"name": "cs:getctag", "value": "47"}, // TODO correct value + // {"name": "current-user-privilege-set", "value": ""}, + /* + "uid", + "dtstamp", + "dtstart", + "dtend", + "summary", + "description", + "url", + "location", + */ + ], + "status": "HTTP/2.0 200 OK", + "description": null, + }, + ] + }, + "description": null, + } + ], + "description": null, + } + ) + ), + } + ); + } + } + ); + } + +} diff --git a/source/api/actions/calendar_add.ts b/source/api/actions/calendar_add.ts index 949cbdc..b2b87d2 100644 --- a/source/api/actions/calendar_add.ts +++ b/source/api/actions/calendar_add.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_add( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/calendar_change.ts b/source/api/actions/calendar_change.ts index 07a32d8..6ce095e 100644 --- a/source/api/actions/calendar_change.ts +++ b/source/api/actions/calendar_change.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_change( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/calendar_event_add.ts b/source/api/actions/calendar_event_add.ts index df4c00e..b7a4b47 100644 --- a/source/api/actions/calendar_event_add.ts +++ b/source/api/actions/calendar_event_add.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_event_add( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/calendar_event_change.ts b/source/api/actions/calendar_event_change.ts index 42ec2d3..9fe6963 100644 --- a/source/api/actions/calendar_event_change.ts +++ b/source/api/actions/calendar_event_change.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_event_change( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/calendar_event_get.ts b/source/api/actions/calendar_event_get.ts index 34427a7..8fb59c2 100644 --- a/source/api/actions/calendar_event_get.ts +++ b/source/api/actions/calendar_event_get.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_event_get( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/calendar_event_remove.ts b/source/api/actions/calendar_event_remove.ts index cd83b3a..7df847a 100644 --- a/source/api/actions/calendar_event_remove.ts +++ b/source/api/actions/calendar_event_remove.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_event_remove( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/calendar_get.ts b/source/api/actions/calendar_get.ts index cdb4b0d..a042ab7 100644 --- a/source/api/actions/calendar_get.ts +++ b/source/api/actions/calendar_get.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_get( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/calendar_list.ts b/source/api/actions/calendar_list.ts index 5c345dd..6770c75 100644 --- a/source/api/actions/calendar_list.ts +++ b/source/api/actions/calendar_list.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_list( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/calendar_remove.ts b/source/api/actions/calendar_remove.ts index 693afc4..f430477 100644 --- a/source/api/actions/calendar_remove.ts +++ b/source/api/actions/calendar_remove.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_remove( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/events.ts b/source/api/actions/events.ts index 5feecb1..8be3f78 100644 --- a/source/api/actions/events.ts +++ b/source/api/actions/events.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_events( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/export_caldav.ts b/source/api/actions/export_ical.ts similarity index 96% rename from source/api/actions/export_caldav.ts rename to source/api/actions/export_ical.ts index d970b6e..b8f68d4 100644 --- a/source/api/actions/export_caldav.ts +++ b/source/api/actions/export_ical.ts @@ -4,8 +4,8 @@ namespace _zeitbild.api /** */ - export function register_export_caldav( - rest_subject : lib_plankton.rest.type_rest + export function register_export_ical( + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< @@ -18,9 +18,9 @@ namespace _zeitbild.api >( rest_subject, lib_plankton.http.enum_method.get, - "/export/caldav", + "/export/ical", { - "description": "trägt Veranstaltungen aus verschiedenen Kalendern zusammen im CalDAV-Format", + "description": "trägt Veranstaltungen aus verschiedenen Kalendern zusammen im ical-Format", "query_parameters": () => ([ { "name": "from", diff --git a/source/api/actions/meta_ping.ts b/source/api/actions/meta_ping.ts index bfe01f1..77f8258 100644 --- a/source/api/actions/meta_ping.ts +++ b/source/api/actions/meta_ping.ts @@ -5,10 +5,10 @@ namespace _zeitbild.api /** */ export function register_meta_ping( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { - lib_plankton.rest.register< + lib_plankton.rest_caldav.register< null, string > diff --git a/source/api/actions/meta_spec.ts b/source/api/actions/meta_spec.ts index cecb3ad..5dca37d 100644 --- a/source/api/actions/meta_spec.ts +++ b/source/api/actions/meta_spec.ts @@ -5,10 +5,10 @@ namespace _zeitbild.api /** */ export function register_meta_spec( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { - lib_plankton.rest.register< + lib_plankton.rest_caldav.register< null, any > @@ -27,7 +27,7 @@ namespace _zeitbild.api "execution": () => { return Promise.resolve({ "status_code": 200, - "data": lib_plankton.rest.to_oas(rest_subject), + "data": lib_plankton.rest_caldav.to_oas(rest_subject), }); }, } diff --git a/source/api/actions/session_begin.ts b/source/api/actions/session_begin.ts index 8125575..62ab793 100644 --- a/source/api/actions/session_begin.ts +++ b/source/api/actions/session_begin.ts @@ -5,10 +5,10 @@ namespace _zeitbild.api /** */ export function register_session_begin( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { - lib_plankton.rest.register< + lib_plankton.rest_caldav.register< { name : string; password : string; diff --git a/source/api/actions/session_end.ts b/source/api/actions/session_end.ts index 124bb5e..3ecbba7 100644 --- a/source/api/actions/session_end.ts +++ b/source/api/actions/session_end.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_session_end( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register( diff --git a/source/api/actions/session_oidc.ts b/source/api/actions/session_oidc.ts index d609537..9ace510 100644 --- a/source/api/actions/session_oidc.ts +++ b/source/api/actions/session_oidc.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_session_oidc( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/actions/session_prepare.ts b/source/api/actions/session_prepare.ts index e76e225..8753106 100644 --- a/source/api/actions/session_prepare.ts +++ b/source/api/actions/session_prepare.ts @@ -5,10 +5,10 @@ namespace _zeitbild.api /** */ export function register_session_prepare( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { - lib_plankton.rest.register< + lib_plankton.rest_caldav.register< any, { kind : string; diff --git a/source/api/actions/users.ts b/source/api/actions/users.ts index fc4010b..3f667bc 100644 --- a/source/api/actions/users.ts +++ b/source/api/actions/users.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_users( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_caldav.type_rest ) : void { register< diff --git a/source/api/base.ts b/source/api/base.ts index 56f7a07..4f85f52 100644 --- a/source/api/base.ts +++ b/source/api/base.ts @@ -27,7 +27,7 @@ namespace _zeitbild.api /** */ - export const restriction_logged_in : lib_plankton.rest.type_restriction = ( + export const restriction_logged_in : lib_plankton.rest_caldav.type_restriction = ( (stuff) => ( session_from_stuff(stuff) .then(() => Promise.resolve(true)) @@ -38,7 +38,7 @@ namespace _zeitbild.api /** */ - export const restriction_none : lib_plankton.rest.type_restriction = ( + export const restriction_none : lib_plankton.rest_caldav.type_restriction = ( (stuff) => Promise.resolve(true) ); @@ -46,13 +46,13 @@ namespace _zeitbild.api /** */ export function register( - rest_subject : lib_plankton.rest.type_rest, - http_method : lib_plankton.http.enum_method, + rest_subject : lib_plankton.rest_caldav.type_rest, + http_method : lib_plankton.caldav.enum_method, path : string, options : { active ?: ((version : string) => boolean); - restriction ?: (null | lib_plankton.rest.type_restriction); - execution ?: lib_plankton.rest.type_execution; + restriction ?: (null | lib_plankton.rest_caldav.type_restriction); + execution ?: lib_plankton.rest_caldav.type_execution; title ?: (null | string); description ?: (null | string); query_parameters ?: ((version : (null | string)) => Array< @@ -62,8 +62,8 @@ namespace _zeitbild.api required : boolean; } >); - input_schema ?: ((version: (null | string)) => lib_plankton.rest.type_oas_schema); - output_schema ?: ((version: (null | string)) => lib_plankton.rest.type_oas_schema); + input_schema ?: ((version: (null | string)) => lib_plankton.rest_caldav.type_oas_schema); + output_schema ?: ((version: (null | string)) => lib_plankton.rest_caldav.type_oas_schema); request_body_mimetype ?: string; request_body_decode ?: ((http_request_body : Buffer, http_request_header_content_type : (null | string)) => any); response_body_mimetype ?: string; @@ -76,7 +76,7 @@ namespace _zeitbild.api }, options ); - lib_plankton.rest.register( + lib_plankton.rest_caldav.register( rest_subject, http_method, (_zeitbild.conf.get().server.path_base + path), diff --git a/source/api/functions.ts b/source/api/functions.ts index 1d24611..8344792 100644 --- a/source/api/functions.ts +++ b/source/api/functions.ts @@ -5,9 +5,9 @@ namespace _zeitbild.api /** */ export function make( - ) : lib_plankton.rest.type_rest + ) : lib_plankton.rest_caldav.type_rest { - const rest_subject : lib_plankton.rest.type_rest = lib_plankton.rest.make( + const rest_subject : lib_plankton.rest_caldav.type_rest = lib_plankton.rest_caldav.make( { "title": "zeitbild", "versioning_method": "header", @@ -48,7 +48,12 @@ namespace _zeitbild.api } // export { - _zeitbild.api.register_export_caldav(rest_subject); + _zeitbild.api.register_export_ical(rest_subject); + } + // caldav + { + _zeitbild.api.register_caldav_probe(rest_subject); + _zeitbild.api.register_caldav_get(rest_subject); } // misc { diff --git a/source/api/transformations/datetime.ts b/source/api/transformations/datetime.ts index bb2a51d..72f515e 100644 --- a/source/api/transformations/datetime.ts +++ b/source/api/transformations/datetime.ts @@ -8,7 +8,7 @@ namespace _zeitbild.api options : { nullable ?: boolean; } = {} - ) : lib_plankton.rest.type_oas_schema + ) : lib_plankton.rest_caldav.type_oas_schema { options = Object.assign( { @@ -49,7 +49,7 @@ namespace _zeitbild.api options : { nullable ?: boolean; } = {} - ) : lib_plankton.rest.type_oas_schema + ) : lib_plankton.rest_caldav.type_oas_schema { options = Object.assign( { @@ -90,7 +90,7 @@ namespace _zeitbild.api options : { nullable ?: boolean; } = {} - ) : lib_plankton.rest.type_oas_schema + ) : lib_plankton.rest_caldav.type_oas_schema { options = Object.assign( { diff --git a/source/main.ts b/source/main.ts index 326b563..858131c 100644 --- a/source/main.ts +++ b/source/main.ts @@ -320,11 +320,11 @@ async function main( } case "api-doc": { lib_plankton.log.conf_push([]); - const rest_subject : lib_plankton.rest.type_rest = _zeitbild.api.make(); + const rest_subject : lib_plankton.rest_caldav.type_rest = _zeitbild.api.make(); lib_plankton.log.conf_pop(); process.stdout.write( JSON.stringify( - lib_plankton.rest.to_oas(rest_subject), + lib_plankton.rest_caldav.to_oas(rest_subject), undefined, "\t" ) @@ -376,11 +376,11 @@ async function main( await _zeitbild.auth.init(); - const rest_subject : lib_plankton.rest.type_rest = _zeitbild.api.make(); + const rest_subject : lib_plankton.rest_caldav.type_rest = _zeitbild.api.make(); const server : lib_plankton.server.type_subject = lib_plankton.server.make( async (input, metadata) => { - 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( + const http_request : lib_plankton.caldav.type_request = lib_plankton.caldav.decode_request(input.toString()); + const http_response : lib_plankton.caldav.type_response = await lib_plankton.rest_caldav.call( rest_subject, http_request, { @@ -389,7 +389,7 @@ async function main( // "checklevel_output": lib_plankton.api.enum_checklevel.soft, } ); - const output : string = lib_plankton.http.encode_response(http_response); + const output : string = lib_plankton.caldav.encode_response(http_response); return output; }, { diff --git a/tools/makefile b/tools/makefile index b5ea7a9..ebedf93 100644 --- a/tools/makefile +++ b/tools/makefile @@ -75,7 +75,9 @@ ${dir_temp}/zeitbild-unlinked.js: \ ${dir_source}/api/actions/calendar_event_change.ts \ ${dir_source}/api/actions/calendar_event_remove.ts \ ${dir_source}/api/actions/events.ts \ - ${dir_source}/api/actions/export_caldav.ts \ + ${dir_source}/api/actions/export_ical.ts \ + ${dir_source}/api/actions/caldav_probe.ts \ + ${dir_source}/api/actions/caldav_get.ts \ ${dir_source}/api/functions.ts \ ${dir_source}/main.ts @ ${cmd_log} "compile …" diff --git a/tools/update-plankton b/tools/update-plankton index beecb08..b62b0e6 100755 --- a/tools/update-plankton +++ b/tools/update-plankton @@ -21,15 +21,20 @@ modules="${modules} order" modules="${modules} ical" modules="${modules} url" modules="${modules} http" +modules="${modules} webdav" +modules="${modules} caldav" modules="${modules} api" modules="${modules} rest" -modules="${modules} rest" +modules="${modules} rest_http" +modules="${modules} rest_webdav" +modules="${modules} rest_caldav" modules="${modules} server" modules="${modules} args" modules="${modules} bcrypt" modules="${modules} map" modules="${modules} pit" modules="${modules} auth" +modules="${modules} sha256" ## exec