UNPKG

ithit.webdav.server

Version:

With IT Hit WebDAV Server Engine for Node.js you can create your own WebDAV server, add WebDAV support to your existing Node.js project or DAV-enable your CMS/DMS/CRM.

176 lines (175 loc) 8.71 kB
/** * @copyright Copyright (c) 2017 IT Hit. All rights reserved. */ import { DavContextBase } from "./DavContextBase"; import { IMethodHandler } from "./Extensibility/IMethodHandler"; import { IOptionsHandler } from "./Extensibility/IOptionsHandler"; import { IPropertyHandler } from "./Extensibility/IPropertyHandler"; import { IReportHandler } from "./Extensibility/IReportHandler"; import { IHierarchyItem } from "./IHierarchyItem"; import { ILogger } from "./ILogger"; import { PropertyName } from "./PropertyName"; /** * The DavEngine class provides the core implementation for WebDAV engine. * @remarks * Engine parses XML send by WebDAV client, processes requests making calls to your implementations of * WebDAV interfaces ({@link IHierarchyItem} , {@link IFolder}, {@link IFile} and other) * and finally generates XML response. * * In each HTTP request you will create separate instance of your class derived * from {@link DavContextBase} class and pass it to the {@link DavEngine.run} method. Via the context, engine * receives all necessary information about hosting environment. * * You must set {@link license} property before you can use the engine. * * All updates invoked within one request execution shall be inside one transactions. * Transaction can be committed or rollbacked in {@link DavContextBase.beforeResponse} method, which * is called right before starting sending response to client. * After this method is called, no methods of interfaces which update state will be called. However methods * which read state can be called. * @threadsafety Method {@link DavEngine.run} is threadsafe. All other members are not threadsafe. * You can create a single instance of DavEngine, initialize it onces and use to serve all requests * from different threads. */ export declare class DavEngine { private methodHandlers; propertyHandlers: IPropertyHandler[]; private reportHandlers; /** * Gets or sets the license text. * @value License string. */ license: string; /** * Enables or disables CORS. * @remarks If this property is set to * CORS will be enabled for in all domains. In this case, * if the Origin request header is available the Engine will extract the value of the Origin header and * set the Access-Control-Allow-Origin header to the value of the Origin header. * If Origin header is not available the Access-Control-Allow-Origin header will be set to '*'. * * To enable CORS for a specific domain set this property to the name of the of the domain. * To disable CORS set this property to null or empty string. * * If CORS is enabled Access-Control headers are included in all responses. * @value Domain for which CORS is enabled. Null or empty string if CORS is disabled. Default is * - CORS is enabled for all domains. */ corsAllowedFor: string; /** * @hidden * Determines if placing file under version control is automatic. * @value Boolean value indicating if items must be put under version control before content or properties * update. Default is true. * @remarks Determines whether items will be placed under version control automatically * or explicit request from client shall be made to put an item under version control. * * If this property is true the IVersionableItem.putUnderVersionControl will be called * after item is created and prior item content or properties update. */ autoPutUnderVersionControl: boolean; /** * Gets or sets the HTTP character set of the output stream. Default is UTF-8. * @value A Encoding object that contains information about the character set of the response. * Default is UTF-8. */ contentEncoding: string; /** * Specifies whether engine shall use full or relative urls. Default is true. * @remarks By default full urls are used. */ useFullUris: boolean; /** * @hidden * ILogger instance which engine will use for logging. * @remarks By default this is {@link DefaultLoggerImpl}. */ logger: ILogger; /** * Specifies whether XML written to the output will be formatted. Default is false. */ outputXmlFormatting: boolean; /** * @hidden */ allowOffice12Versioning: boolean; /** * @param item Item that implement {@link IHierarchyItem}. */ static DisposeSafe(item: IHierarchyItem): void; /** * Initializes a new instance of the DavEngine class. */ constructor(); getMethodsThatApplyTo(item: IHierarchyItem): string[]; getOptionsForItem(item: IHierarchyItem): string[]; /** * Registers custom method handler. * @param method HTTP verb. * @param handler Custom handled implementing {@link IMethodHandler} interface. * @returns Original handler if any. * @remarks Using this method you can register custom method handler to be called by the engine. * If the handler for the specified method was already defined it is returned from this method. */ registerMethodHandler(method: string, handler: IMethodHandler): IMethodHandler; /** * Registers custom property handler. * @param propName Property name. * @param handler Custom handled implementing {@link IPropertyHandler} interface. * @returns Original handler if any. * @remarks Property handler allows formatting of property values to XML and reading property values from XML. * Using this method you can register custom property handler to be called by the engine. * If the handler for the specified property was already defined it is returned from this method. * The original handler can be saved and called later from your custom handler. */ registerPropertyHandler(propName: string, handler: IPropertyHandler): IPropertyHandler; /** * Registers custom options handler. * @param name Token that will be added to 'DAV' header for OPTIONS response. * @param handler Custom handled implementing {@link IOptionsHandler} interface. * @returns Original handler if any. * @remarks Using this method you can register custom options handler to be called by the engine. * If the handler for the specified token was already defined it is returned from this method. * The original handler can be saved and called later from your custom handler. */ registerOptionsHandler(name: string, handler: IOptionsHandler): IOptionsHandler; /** * Registers custom report handler. * @param name Report element name. * @param namespace Report namespace. * @param handler Custom handled implementing {@link IReportHandler} interface. * @returns Original handler if any. * @remarks Using this method you can register custom report handler to be called by the engine. * If the handler for the specified token was already defined it is returned from this method. * The original handler can be saved and called later from your custom handler. */ registerReportHandler(name: string, namespace: string, handler: IReportHandler): IReportHandler; /** * Processes WebDAV request and generates WebDAV response. * @param context Instance of your context class derived from {@link DavContextBase} class. * @remarks * You must call {@link run} method in each request to your WebDAV server passing your context class derived from {@link DavContextBase} * as input parameter. */ run(context: DavContextBase): Promise<void>; getAllProp(): PropertyName[]; getPropertiesForItem(item: IHierarchyItem): PropertyName[]; getReportHandler(name: string, namespace: string): IReportHandler | null; private checkLicense; private isResponseBodyAllowed; private addCrossDomainHeaders; private initPropertyHandlers; private initMethodHandlers; private initReportHandlers; /** * Sets 301 Moved Permanently in case of requests to '/.well-known/caldav' * or '/.well-known/carddav' url. * @remarks * Gives a chance for the user to return hierarchy item that coresponds to * well-known requests to CalDAV and CardDAV servers. * @returns Boolean value indicating if this is a well known request. * * http://www.iana.org/assignments/well-known-uris/well-known-uris.xhtml * http://tools.ietf.org/html/rfc5785 * http://tools.ietf.org/html/rfc6764 */ private processWellKnownRequest; }