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CACX,GACJ,EAEJ,QAAQ,QAAU,SAClB,QAAQ,SAAW,SACnB,SAAS,cAAgB","file":"/npm/efici-nextcloud@0.3.2/dist/ncClient.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/efici-nextcloud@0.3.2/dist/ncClient.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n    return new (P || (P = Promise))(function (resolve, reject) {\n        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n        function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n        step((generator = generator.apply(thisArg, _arguments || [])).next());\n    });\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nvar __importStar = (this && this.__importStar) || function (mod) {\n    if (mod && mod.__esModule) return mod;\n    var result = {};\n    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\n    result[\"default\"] = mod;\n    return result;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n// tslint:disable-next-line:no-var-requires\nrequire(\"dotenv\").config();\nconst debug_1 = __importDefault(require(\"debug\"));\nconst fast_xml_parser_1 = __importDefault(require(\"fast-xml-parser\"));\nconst node_fetch_1 = require(\"node-fetch\");\nconst path_1 = __importStar(require(\"path\"));\nconst ncError_1 = __importDefault(require(\"./ncError\"));\nexports.NCError = ncError_1.default;\nconst ncFile_1 = __importDefault(require(\"./ncFile\"));\nexports.NCFile = ncFile_1.default;\nconst ncFolder_1 = __importDefault(require(\"./ncFolder\"));\nexports.NCFolder = ncFolder_1.default;\nconst ncHttpClient_1 = require(\"./ncHttpClient\");\nconst ncTag_1 = __importDefault(require(\"./ncTag\"));\nexports.NCTag = ncTag_1.default;\nconst debug = debug_1.default(\"NCClient\");\nclass FakeServer {\n    constructor(fakeResponses) {\n        this.fakeResponses = [];\n        this.fakeResponses = fakeResponses;\n    }\n    getFakeHttpResponse(url, requestInit, expectedHttpStatusCode, context) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getFakeHttpResponse\");\n            if (!requestInit.method) {\n                requestInit.method = \"UNDEFINED\";\n            }\n            const rrEntry = this.fakeResponses.shift();\n            if (!rrEntry) {\n                throw new Error(`error providing fake http response. No fake response available`);\n            }\n            const responseInit = {\n                status: rrEntry.response.status,\n            };\n            const response = new node_fetch_1.Response(rrEntry.response.body, responseInit);\n            if (rrEntry.response.contentType) {\n                response.headers.append(\"Content-Type\", rrEntry.response.contentType);\n            }\n            if (rrEntry.response.contentLocation) {\n                response.headers.append(\"Content-Location\", rrEntry.response.contentLocation);\n            }\n            if (expectedHttpStatusCode.indexOf(response.status) === -1) {\n                debug(\"getHttpResponse unexpected status response %s\", response.status + \" \" + response.statusText);\n                debug(\"getHttpResponse description %s\", context.description);\n                debug(\"getHttpResponse expected %s\", expectedHttpStatusCode.join(\",\"));\n                debug(\"getHttpResponse headers %s\", JSON.stringify(response.headers, null, 4));\n                debug(\"getHttpResponse request body %s\", requestInit.body);\n                debug(\"getHttpResponse text %s\", yield response.text());\n                throw new Error(`HTTP response status ${response.status} not expected. Expected status: ${expectedHttpStatusCode.join(\",\")} - status text: ${response.statusText}`);\n            }\n            return response;\n        });\n    }\n}\nexports.FakeServer = FakeServer;\n// tslint:disable-next-line: max-classes-per-file\nclass NextcloudServer {\n    constructor(url, basicAuth, proxy, logRequestResponse = false) {\n        this.url = url;\n        this.basicAuth = basicAuth;\n        this.proxy = proxy;\n        this.logRequestResponse = logRequestResponse;\n    }\n}\nexports.NextcloudServer = NextcloudServer;\n// tslint:disable-next-line: max-classes-per-file\nclass NCClient {\n    constructor(server) {\n        this.logRequestResponse = false;\n        debug(\"constructor\");\n        this.nextcloudOrigin = \"\";\n        this.nextcloudAuthHeader = \"\";\n        this.nextcloudRequestToken = \"\";\n        this.webDAVUrl = \"\";\n        if (server instanceof NextcloudServer) {\n            this.proxy = server.proxy;\n            debug(\"constructor: webdav url %s\", server.url);\n            if (server.url.indexOf(NCClient.webDavUrlPath) === -1) {\n                // not a valid nextcloud url\n                throw new ncError_1.default(`The provided nextcloud url \"${server.url}\" does not comply to the nextcloud url standard, \"${NCClient.webDavUrlPath}\" is missing`, \"ERR_INVALID_NEXTCLOUD_WEBDAV_URL\");\n            }\n            this.nextcloudOrigin = server.url.substr(0, server.url.indexOf(NCClient.webDavUrlPath));\n            debug(\"constructor: nextcloud url %s\", this.nextcloudOrigin);\n            this.nextcloudAuthHeader = \"Basic \" + Buffer.from(server.basicAuth.username + \":\" + server.basicAuth.password).toString(\"base64\");\n            this.nextcloudRequestToken = \"\";\n            if (server.url.slice(-1) === \"/\") {\n                this.webDAVUrl = server.url.slice(0, -1);\n            }\n            else {\n                this.webDAVUrl = server.url;\n            }\n            this.logRequestResponse = server.logRequestResponse;\n            const options = {\n                authorizationHeader: this.nextcloudAuthHeader,\n                logRequestResponse: this.logRequestResponse,\n                origin: this.nextcloudOrigin,\n                proxy: this.proxy,\n            };\n            this.httpClient = new ncHttpClient_1.NCHttpClient(options);\n        }\n        if (server instanceof FakeServer) {\n            this.fakeServer = server;\n            this.webDAVUrl = \"https://fake.server\" + NCClient.webDavUrlPath;\n        }\n    }\n    /**\n     * returns the nextcloud credentials that is defined in the\n     * \"user-provided\" service section of the VCAP_SERVICES environment\n     * @param instanceName the name of the nextcloud user provided service instance\n     * @returns credentials from the VCAP_SERVICES environment (user provided service)\n     */\n    static getCredentialsFromEnv() {\n        if (!process.env.NEXTCLOUD_URL) {\n            throw new ncError_1.default(\"NCClient getCredentialsFromEnv: NEXTCLOUD_URL not defined in environment\", \"ERR_NEXTCLOUD_URL_NOT_DEFINED\");\n        }\n        if (!process.env.NEXTCLOUD_USERNAME) {\n            throw new ncError_1.default(\"NCClient getCredentialsFromEnv: NEXTCLOUD_USERNAME not defined in environment\", \"ERR_NEXTCLOUD_USERNAME_NOT_DEFINED\");\n        }\n        if (!process.env.NEXTCLOUD_PASSWORD) {\n            throw new ncError_1.default(\"NCClient getCredentialsFromEnv: NEXTCLOUD_PASSWORD not defined in environment\", \"ERR_NEXTCLOUD_PASSWORD_NOT_DEFINED\");\n        }\n        let logRequestResponse;\n        if ((process.env.TEST_RECORDING_ACTIVE &&\n            (process.env.TEST_RECORDING_ACTIVE === \"0\" || process.env.TEST_RECORDING_ACTIVE === \"false\" || process.env.TEST_RECORDING_ACTIVE === \"inactive\")) ||\n            !process.env.TEST_RECORDING_ACTIVE) {\n            logRequestResponse = false;\n        }\n        else {\n            logRequestResponse = true;\n        }\n        return new NextcloudServer(process.env.NEXTCLOUD_URL, {\n            password: process.env.NEXTCLOUD_PASSWORD,\n            username: process.env.NEXTCLOUD_USERNAME,\n        }, undefined, logRequestResponse);\n    }\n    /**\n     * returns the nextcloud credentials that is defined in the\n     * \"user-provided\" service section of the VCAP_SERVICES environment\n     * @param instanceName the name of the nextcloud user provided service instance\n     * @returns credentials from the VCAP_SERVICES environment (user provided service)\n     */\n    static getCredentialsFromVcapServicesEnv(instanceName) {\n        if (!process.env.VCAP_SERVICES) {\n            throw new ncError_1.default(\"NCClient getCredentials: environment VCAP_SERVICES not found\", \"ERR_VCAP_SERVICES_NOT_FOUND\");\n        }\n        const vcapServices = require(\"vcap_services\");\n        const cred = vcapServices.getCredentials(\"user-provided\", null, instanceName);\n        if (!cred || cred === undefined || (!cred.url && !cred.username && !cred.password)) {\n            debug(\"NCClient: error credentials not found or not fully specified %O\", cred);\n            throw new ncError_1.default(`NCClient getCredentials: nextcloud credentials not found in environment VCAP_SERVICES. Service section: \"user-provided\", service instance name: \"${instanceName}\" `, \"ERR_VCAP_SERVICES_NOT_FOUND\");\n        }\n        if (!cred.url) {\n            throw new ncError_1.default(\"NCClient getCredentials: VCAP_SERVICES url not defined in user provided services for nextcloud\", \"ERR_VCAP_SERVICES_URL_NOT_DEFINED\", { credentials: cred });\n        }\n        if (!cred.password) {\n            throw new ncError_1.default(\"NCClient getCredentials VCAP_SERVICES password not defined in user provided services for nextcloud\", \"ERR_VCAP_SERVICES_PASSWORD_NOT_DEFINED\", { credentials: cred });\n        }\n        if (!cred.username) {\n            throw new ncError_1.default(\"NCClient getCredentials VCAP_SERVICES username not defined in user provided services for nextcloud\", \"ERR_VCAP_SERVICES_USERNAME_NOT_DEFINED\", { credentials: cred });\n        }\n        return new NextcloudServer(cred.url, { username: cred.username, password: cred.password });\n    }\n    /**\n     * returns the used and free quota of the nextcloud account\n     */\n    getQuota() {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getQuota\");\n            const requestInit = {\n                method: \"PROPFIND\",\n            };\n            const response = yield this.getHttpResponse(this.webDAVUrl + \"/\", requestInit, [207], { description: \"Client get quota\" });\n            const properties = yield this.getPropertiesFromWebDAVMultistatusResponse(response, NCClient.webDavUrlPath + \"/\");\n            let quota = null;\n            for (const prop of properties) {\n                if (prop[\"quota-available-bytes\"]) {\n                    quota = {\n                        available: \"unlimited\",\n                        used: prop[\"quota-used-bytes\"],\n                    };\n                    if (prop[\"quota-available-bytes\"] > 0) {\n                        quota.available = prop[\"quota-available-bytes\"];\n                    }\n                }\n            }\n            if (!quota) {\n                debug(\"Error, quota not available: %s \", JSON.stringify(properties, null, 4));\n                throw new ncError_1.default(`Error, quota not available`, \"ERR_QUOTA_NOT_AVAILABLE\");\n            }\n            debug(\"getQuota = %O\", quota);\n            return quota;\n        });\n    }\n    // ***************************************************************************************\n    // tags\n    // ***************************************************************************************\n    /**\n     * creates a new tag, if not already existing\n     * this function will fail with http 403 if the user does not have admin privileges\n     * @param tagName the name of the tag\n     * @returns tagId\n     */\n    createTag(tagName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"createTag\");\n            let tag;\n            // is the tag already existing?\n            tag = yield this.getTagByName(tagName);\n            if (tag) {\n                return tag;\n            }\n            // tag does not exist, create tag\n            const requestInit = {\n                body: `{ \"name\": \"${tagName}\", \"userVisible\": true, \"userAssignable\": true, \"canAssign\": true }`,\n                headers: new node_fetch_1.Headers({ \"Content-Type\": \"application/json\" }),\n                method: \"POST\",\n            };\n            const response = yield this.getHttpResponse(this.nextcloudOrigin + \"/remote.php/dav/systemtags/\", requestInit, [201], { description: \"Tag create\" });\n            const tagString = response.headers.get(\"Content-Location\");\n            debug(\"createTag new tagId %s, tagName %s\", tagString, tagName);\n            if (tagString === \"\" || tagString === null) {\n                throw new ncError_1.default(`Error, tag with name '${tagName}' could not be created`, \"ERR_TAG_CREATE_FAILED\");\n            }\n            // the number id of the tag is the last element in the id (path)\n            const tagId = this.getTagIdFromHref(tagString);\n            tag = new ncTag_1.default(this, tagId, tagName, true, true, true);\n            return tag;\n        });\n    }\n    /**\n     * returns a tag identified by the name or null if not found\n     * @param tagName the name of the tag\n     * @returns tag or null\n     */\n    getTagByName(tagName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getTag\");\n            const tags = yield this.getTags();\n            for (const tag of tags) {\n                if (tag.name === tagName) {\n                    return tag;\n                }\n            }\n            return null;\n        });\n    }\n    /**\n     * returns a tag identified by the id or null if not found\n     * @param tagId the id of the tag\n     * @returns tag or null\n     */\n    getTagById(tagId) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getTagById\");\n            const tags = yield this.getTags();\n            for (const tag of tags) {\n                if (tag.id === tagId) {\n                    return tag;\n                }\n            }\n            return null;\n        });\n    }\n    /**\n     * deletes the tag by id\n     * this function will fail with http 403 if the user does not have admin privileges\n     * @param tagId the id of the tag like \"/remote.php/dav/systemtags/234\"\n     */\n    deleteTag(tagId) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"deleteTag tagId: $s\", tagId);\n            const requestInit = {\n                method: \"DELETE\",\n            };\n            const response = yield this.getHttpResponse(`${this.nextcloudOrigin}/remote.php/dav/systemtags/${tagId}`, requestInit, [204, 404], { description: \"Tag delete\" });\n        });\n    }\n    /**\n     * deletes all visible assignable tags\n     * @throws Error\n     */\n    deleteAllTags() {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"deleteAllTags\");\n            const tags = yield this.getTags();\n            for (const tag of tags) {\n                // debug(\"deleteAllTags tag: %O\", tag);\n                yield tag.delete();\n            }\n        });\n    }\n    /**\n     * returns a list of tags\n     * @returns array of tags\n     */\n    getTags() {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getTags PROPFIND %s\", this.nextcloudOrigin + \"/remote.php/dav/systemtags/\");\n            const requestInit = {\n                body: `<?xml version=\"1.0\"?>\n            <d:propfind  xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\">\n              <d:prop>\n                <oc:id />\n                <oc:display-name />\n                <oc:user-visible />\n                <oc:user-assignable />\n                <oc:can-assign />\n              </d:prop>\n            </d:propfind>`,\n                method: \"PROPFIND\",\n            };\n            const relUrl = `/remote.php/dav/systemtags/`;\n            const response = yield this.getHttpResponse(this.nextcloudOrigin + relUrl, requestInit, [207], { description: \"Tags get\" });\n            const properties = yield this.getPropertiesFromWebDAVMultistatusResponse(response, relUrl + \"/*\");\n            const tags = [];\n            for (const prop of properties) {\n                tags.push(new ncTag_1.default(this, this.getTagIdFromHref(prop._href), prop[\"display-name\"], prop[\"user-visible\"], prop[\"user-assignable\"], prop[\"can-assign\"]));\n            }\n            return tags;\n        });\n    }\n    /**\n     * returns the list of tag names and the tag ids\n     * @param fileId the id of the file\n     */\n    getTagsOfFile(fileId) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getTagsOfFile\");\n            const requestInit = {\n                body: `<?xml version=\"1.0\"?>\n            <d:propfind  xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\">\n              <d:prop>\n                <oc:id />\n                <oc:display-name />\n                <oc:user-visible />\n                <oc:user-assignable />\n                <oc:can-assign />\n              </d:prop>\n            </d:propfind>`,\n                method: \"PROPFIND\",\n            };\n            const relUrl = `/remote.php/dav/systemtags-relations/files/${fileId}`;\n            const response = yield this.getHttpResponse(`${this.nextcloudOrigin}${relUrl}`, requestInit, [207], { description: \"File get tags\" });\n            const properties = yield this.getPropertiesFromWebDAVMultistatusResponse(response, relUrl + \"/*\");\n            const tagMap = new Map();\n            for (const prop of properties) {\n                tagMap.set(prop[\"display-name\"], prop.id);\n            }\n            debug(\"tags of file %O\", tagMap);\n            return tagMap;\n        });\n    }\n    /**\n     * removes the tag from the file\n     * @param fileId the file id\n     * @param tagId the tag id\n     */\n    removeTagOfFile(fileId, tagId) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"removeTagOfFile tagId: $s fileId:\", tagId, fileId);\n            const requestInit = {\n                method: \"DELETE\",\n            };\n            const response = yield this.getHttpResponse(`${this.nextcloudOrigin}/remote.php/dav/systemtags-relations/files/${fileId}/${tagId}`, requestInit, [204, 404], { description: \"File remove tag\" });\n            return;\n        });\n    }\n    /**\n     * returns the id of the file or -1 of not found\n     * @returns id of the file or -1 if not found\n     */\n    getFileId(fileUrl) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getFileId\");\n            const requestInit = {\n                body: `\n            <d:propfind  xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">\n              <d:prop>\n                  <oc:fileid />\n              </d:prop>\n            </d:propfind>`,\n                method: \"PROPFIND\",\n            };\n            const response = yield this.getHttpResponse(fileUrl, requestInit, [207], { description: \"File get id\" });\n            const properties = yield this.getPropertiesFromWebDAVMultistatusResponse(response, \"\");\n            for (const prop of properties) {\n                if (prop.fileid) {\n                    return prop.fileid;\n                }\n            }\n            debug(\"getFileId no file id found for %s\", fileUrl);\n            return -1;\n        });\n    }\n    getFolderContents(folderName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getFolderContents\");\n            const requestInit = {\n                body: `<?xml version=\"1.0\"?>\n            <d:propfind  xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\" xmlns:ocs=\"http://open-collaboration-services.org/ns\">\n              <d:prop>\n                <d:getlastmodified />\n                <d:getetag />\n                <d:getcontenttype />\n                <d:resourcetype />\n                <oc:fileid />\n                <oc:permissions />\n                <oc:size />\n                <d:getcontentlength />\n                <nc:has-preview />\n                <nc:mount-type />\n                <nc:is-encrypted />\n                <ocs:share-permissions />\n                <oc:tags />\n                <oc:favorite />\n                <oc:comments-unread />\n                <oc:owner-id />\n                <oc:owner-display-name />\n                <oc:share-types />\n              </d:prop>\n            </d:propfind>`,\n                method: \"PROPFIND\",\n            };\n            const url = `${this.webDAVUrl}${folderName}`;\n            const response = yield this.getHttpResponse(url, requestInit, [207], { description: \"Folder get contents\" });\n            const properties = yield this.getPropertiesFromWebDAVMultistatusResponse(response, \"\");\n            const folderContents = [];\n            // tslint:disable-next-line:no-empty\n            for (const prop of properties) {\n                let fileName = decodeURI(prop._href.substr(prop._href.indexOf(NCClient.webDavUrlPath) + 18));\n                if (fileName.endsWith(\"/\")) {\n                    fileName = fileName.slice(0, -1);\n                }\n                if ((url + \"/\").endsWith(prop._href)) {\n                    continue;\n                }\n                const folderContentsEntry = {};\n                folderContentsEntry.lastmod = prop.getlastmodified;\n                folderContentsEntry.fileid = prop.fileid;\n                folderContentsEntry.basename = fileName.split(\"/\").reverse()[0];\n                folderContentsEntry.filename = fileName;\n                if (prop.getcontenttype) {\n                    folderContentsEntry.mime = prop.getcontenttype;\n                    folderContentsEntry.size = prop.getcontentlength;\n                    folderContentsEntry.type = \"file\";\n                }\n                else {\n                    folderContentsEntry.type = \"directory\";\n                }\n                folderContents.push(folderContentsEntry);\n            }\n            // debug(\"folderContentsEntry $s\", JSON.stringify(folderContents, null, 4));\n            return folderContents;\n        });\n    }\n    /**\n     * creates a folder and all parent folders in the path if they do not exist\n     * @param folderName name of the folder /folder/subfolder/subfolder\n     * @returns a folder object\n     */\n    createFolder(folderName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            folderName = this.sanitizeFolderName(folderName);\n            debug(\"createFolder: folderName=%s\", folderName);\n            const parts1 = folderName.split(\"/\");\n            for (const p of parts1) {\n                if ((p) === \".\" || p === \"..\") {\n                    throw new ncError_1.default(`Error creating folder, folder name \"${folderName}\" invalid`, \"ERR_CREATE_FOLDER_INVALID_FOLDER_NAME\");\n                }\n            }\n            let folder;\n            folder = yield this.getFolder(folderName);\n            if (folder) {\n                debug(\"createFolder: folder already available %O\", folder.name);\n                return folder;\n            }\n            else {\n                // try to do a simple create with the complete path\n                try {\n                    debug(\"createFolder: folder = %s\", folderName);\n                    yield this.createFolderInternal(folderName);\n                }\n                catch (e) {\n                    // create all folders in the path\n                    const parts = folderName.split(\"/\");\n                    parts.shift();\n                    let folderPath = \"\";\n                    debug(\"createFolder: parts = %O\", parts);\n                    for (const part of parts) {\n                        debug(\"createFolder: part = %O\", part);\n                        folderPath += \"/\" + part;\n                        folder = yield this.getFolder(folderPath);\n                        if (folder === null) {\n                            debug(\"createFolder: folder not available\");\n                            // folder not  available\n                            debug(\"createFolder: folder = %s\", folderPath);\n                            yield this.createFolderInternal(folderPath);\n                        }\n                        else {\n                            debug(\"createFolder: folder already available %s\", folderPath);\n                        }\n                    }\n                }\n            }\n            folder = yield this.getFolder(folderName);\n            if (folder) {\n                debug(\"createFolder: new folder %O\", folder.name);\n                return folder;\n            }\n            else {\n                throw new Error(\"createFolder: Error creating folder \" + folderName);\n            }\n        });\n    }\n    /**\n     * deletes a file\n     * @param fileName name of folder \"/f1/f2/f3/x.txt\"\n     */\n    deleteFile(fileName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const url = this.webDAVUrl + fileName;\n            debug(\"deleteFile %s\", url);\n            const requestInit = {\n                method: \"DELETE\",\n            };\n            try {\n                yield this.getHttpResponse(url, requestInit, [204], { description: \"File delete\" });\n            }\n            catch (err) {\n                debug(\"Error in deleteFile %s %s %s\", err.message, requestInit.method, url);\n                throw err;\n            }\n        });\n    }\n    /**\n     * deletes a folder\n     * @param folderName name of folder \"/f1/f2/f3\"\n     */\n    deleteFolder(folderName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            folderName = this.sanitizeFolderName(folderName);\n            debug(\"deleteFolder:\");\n            const folder = yield this.getFolder(folderName);\n            if (folder) {\n                yield this.deleteFile(folderName);\n            }\n        });\n    }\n    /**\n     * get a folder object from a path string\n     * @param folderName Name of the folder like \"/company/branches/germany\"\n     * @returns null if the folder does not exist or an folder object\n     */\n    getFolder(folderName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            folderName = this.sanitizeFolderName(folderName);\n            debug(\"getFolder %s\", folderName);\n            // return root folder\n            if (folderName === \"/\" || folderName === \"\") {\n                return new ncFolder_1.default(this, \"/\", \"\", \"\");\n            }\n            try {\n                const stat = yield this.stat(folderName);\n                debug(\": SUCCESS!!\");\n                if (stat.type !== \"file\") {\n                    return new ncFolder_1.default(this, stat.filename.replace(/\\\\/g, \"/\"), stat.basename, stat.lastmod, stat.fileid);\n                }\n                else {\n                    debug(\"getFolder: found object is file not a folder\");\n                    return null;\n                }\n            }\n            catch (e) {\n                debug(\"getFolder: exception occurred calling stat %O\", e.message);\n                return null;\n            }\n        });\n    }\n    /**\n     * get a array of folders from a folder path string\n     * @param folderName Name of the folder like \"/company/branches/germany\"\n     * @returns array of folder objects\n     */\n    getSubFolders(folderName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getSubFolders: folder %s\", folderName);\n            const folders = [];\n            folderName = this.sanitizeFolderName(folderName);\n            const folderElements = yield this.Contents(folderName, true);\n            for (const folderElement of folderElements) {\n                debug(\"getSubFolders: adding subfolders %s\", folderElement.filename);\n                folders.push(new ncFolder_1.default(this, folderElement.filename.replace(/\\\\/g, \"/\"), folderElement.basename, folderElement.lastmod, folderElement.fileid));\n            }\n            return folders;\n        });\n    }\n    /**\n     * get files of a folder\n     * @param folderName Name of the folder like \"/company/branches/germany\"\n     * @returns array of file objects\n     */\n    getFiles(folderName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getFiles: folder %s\", folderName);\n            const files = [];\n            folderName = this.sanitizeFolderName(folderName);\n            const fileElements = yield this.Contents(folderName, false);\n            for (const folderElement of fileElements) {\n                debug(\"getFiles: adding file %s\", folderElement.filename);\n                // debug(\"getFiles: adding file %O\", folderElement);\n                files.push(new ncFile_1.default(this, folderElement.filename.replace(/\\\\/g, \"/\"), folderElement.basename, folderElement.lastmod, folderElement.size, folderElement.mime, folderElement.fileid));\n            }\n            return files;\n        });\n    }\n    /**\n     * create a new file of overwrites an existing file\n     * @param fileName the file name /folder1/folder2/filename.txt\n     * @param data the buffer object\n     */\n    createFile(fileName, data) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const baseName = path_1.default.basename(fileName);\n            let folderName = path_1.default.dirname(fileName);\n            if (folderName === \".\") {\n                folderName = \"\";\n            }\n            debug(\"createFile folder name %s base name %s\", folderName, baseName);\n            // ensure that we have the folder\n            let folder;\n            try {\n                folder = yield this.createFolder(folderName);\n            }\n            catch (e) {\n                e.message = \"Error creating file: \" + e.message;\n                throw e;\n            }\n            if (folder === null) {\n                throw new ncError_1.default(\"File could not be created: Folder '\" + folderName + \"' could not be created\", \"ERR_FOLDER_NOT_FOUND\", { folderName, baseName });\n            }\n            // fileName = \"/d1/d2/file.txt\"\n            const res = yield this.putFileContents(fileName, data);\n            // debug(\"%O\", Object.keys(res));\n            debug(\"createFile Status %s\", res.status);\n            if (!(res.status === 204 || res.status === 201)) {\n                throw new ncError_1.default(\"File could not be created: '\" + fileName + \"', response status \" + res.status + \" \" + res.statusText, \"ERR_FILE_CREATE_FAILED\", { folderName, baseName });\n            }\n            debug(\"createFile file successfully created\");\n            let file;\n            file = yield this.getFile(fileName);\n            return file;\n        });\n    }\n    /**\n     * returns a nextcloud file object\n     * @param fileName the full file name /folder1/folder2/file.pdf\n     */\n    getFile(fileName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getFile fileName = %s\", fileName);\n            try {\n                const stat = yield this.stat(fileName);\n                debug(\": SUCCESS!!\");\n                if (stat.type === \"file\") {\n                    return new ncFile_1.default(this, stat.filename.replace(/\\\\/g, \"/\"), stat.basename, stat.lastmod, stat.size, stat.mime || \"\", stat.fileid || -1);\n                }\n                else {\n                    debug(\"getFile: found object is a folder not a file\");\n                    return null;\n                }\n            }\n            catch (e) {\n                debug(\"getFile: exception occurred calling stat %O\", e.message);\n                return null;\n            }\n        });\n    }\n    /**\n     * renames the file or moves it to an other location\n     * @param sourceFileName source file name\n     * @param targetFileName target file name\n     */\n    moveFile(sourceFileName, targetFileName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const url = this.webDAVUrl + sourceFileName;\n            const destinationUrl = this.webDAVUrl + targetFileName;\n            debug(\"moveFile from '%s' to '%s'\", url, destinationUrl);\n            const requestInit = {\n                headers: new node_fetch_1.Headers({ Destination: destinationUrl }),\n                method: \"MOVE\",\n            };\n            try {\n                yield this.getHttpResponse(url, requestInit, [201], { description: \"File move\" });\n            }\n            catch (err) {\n                debug(\"Error in move file %s %s source: %s destination: %s\", err.message, requestInit.method, url, destinationUrl);\n                throw new ncError_1.default(\"Error: moving file failed: source=\" + sourceFileName + \" target=\" + targetFileName + \" - \" + err.message, \"ERR_FILE_MOVE_FAILED\");\n            }\n            const targetFile = yield this.getFile(targetFileName);\n            if (!targetFile) {\n                throw new ncError_1.default(\"Error: moving file failed: source=\" + sourceFileName + \" target=\" + targetFileName, \"ERR_FILE_MOVE_FAILED\");\n            }\n            return targetFile;\n        });\n    }\n    /**\n     * renames the folder or moves it to an other location\n     * @param sourceFolderName source folder name\n     * @param tarName target folder name\n     */\n    moveFolder(sourceFolderName, tarName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const url = this.webDAVUrl + sourceFolderName;\n            const destinationUrl = this.webDAVUrl + tarName;\n            debug(\"moveFolder from '%s' to '%s'\", url, destinationUrl);\n            const requestInit = {\n                headers: new node_fetch_1.Headers({ Destination: destinationUrl }),\n                method: \"MOVE\",\n            };\n            try {\n                yield this.getHttpResponse(url, requestInit, [201], { description: \"Folder move\" });\n            }\n            catch (err) {\n                debug(\"Error in move folder %s %s source: %s destination: %s\", err.message, requestInit.method, url, destinationUrl);\n                throw new ncError_1.default(\"Error: moving folder failed: source=\" + sourceFolderName + \" target=\" + tarName + \" - \" + err.message, \"ERR_FOLDER_MOVE_FAILED\");\n            }\n            const tar = yield this.getFolder(tarName);\n            if (!tar) {\n                throw new ncError_1.default(\"Error: moving folder failed: source=\" + sourceFolderName + \" target=\" + tarName, \"ERR_FOLDER_MOVE_FAILED\");\n            }\n            return tar;\n        });\n    }\n    /**\n     * returns the content of a file\n     * @param fileName name of the file /d1/file1.txt\n     * @returns Buffer with file content\n     */\n    getContent(fileName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const url = this.webDAVUrl + fileName;\n            debug(\"getContent GET %s\", url);\n            const requestInit = {\n                method: \"GET\",\n            };\n            let response;\n            try {\n                response = yield this.getHttpResponse(url, requestInit, [200], { description: \"File get content\" });\n            }\n            catch (err) {\n                debug(\"Error getContent %s - error %s\", url, err.message);\n                throw err;\n            }\n            return Buffer.from(yield response.buffer());\n        });\n    }\n    /**\n     * returns the link to a file for downloading\n     * @param fileName name of the file /folder1/folder1.txt\n     * @returns url\n     */\n    getLink(fileName) {\n        debug(\"getLink of %s\", fileName);\n        return this.webDAVUrl + fileName;\n    }\n    getUILink(fileId) {\n        debug(\"getUILink of %s\", fileId);\n        return `${this.nextcloudOrigin}/apps/files/?fileid=${fileId}`;\n    }\n    /**\n     * adds a tag to a file or folder\n     * if the tag does not exist, it is automatically created\n     * if the tag is created, the user must have damin privileges\n     * @param fileId the id of the file\n     * @param tagName the name of the tag\n     * @returns nothing\n     * @throws Error\n     */\n    addTagToFile(fileId, tagName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"addTagToFile file:%s tag:%s\", fileId, tagName);\n            const tag = yield this.createTag(tagName);\n            if (!tag) {\n                return;\n            }\n            if (!tag.canAssign) {\n                throw new ncError_1.default(`Error: No permission to assign tag \"${tagName}\" to file. Tag is not assignable`, \"ERR_TAG_NOT_ASSIGNABLE\");\n            }\n            const addTagBody = {\n                canAssign: tag.canAssign,\n                id: tag.id,\n                name: tag.name,\n                userAssignable: tag.assignable,\n                userVisible: tag.visible,\n            };\n            const requestInit = {\n                body: JSON.stringify(addTagBody, null, 4),\n                headers: new node_fetch_1.Headers({ \"Content-Type\": \"application/json\" }),\n                method: \"PUT\",\n            };\n            yield this.getHttpResponse(`${this.nextcloudOrigin}/remote.php/dav/systemtags-relations/files/${fileId}/${tag.id}`, requestInit, [201, 409], { description: \"File add tag\" }); // created or conflict\n        });\n    }\n    // ***************************************************************************************\n    // activity\n    // ***************************************************************************************\n    getActivities() {\n        return __awaiter(this, void 0, void 0, function* () {\n            const result = [];\n            const requestInit = {\n                headers: new node_fetch_1.Headers({ \"ocs-apirequest\": \"true\" }),\n                method: \"GET\",\n            };\n            const response = yield this.getHttpResponse(this.nextcloudOrigin + \"/ocs/v2.php/apps/activity/api/v2/activity/files?format=json&previews=false&since=97533\", requestInit, [200], { description: \"Activities get\" });\n            const responseObject = yield response.json();\n            // @todo\n            for (const res of responseObject.ocs.data) {\n                debug(JSON.stringify({\n                    acivityId: res.activity_id,\n                    objects: res.objects,\n                    type: res.type,\n                }, null, 4));\n            }\n            // debug(\"getActivities: responseObject %s\", JSON.stringify(responseObject, null, 4));\n            return result;\n        });\n    }\n    // ***************************************************************************************\n    // comments\n    // ***************************************************************************************\n    addCommentToFile(fileId, comment) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"addCommentToFile file:%s comment:%s\", fileId, comment);\n            const addCommentBody = {\n                actorType: \"users\",\n                message: comment,\n                objectType: \"files\",\n                verb: \"comment\",\n            };\n            const requestInit = {\n                body: JSON.stringify(addCommentBody, null, 4),\n                headers: new node_fetch_1.Headers({ \"Content-Type\": \"application/json\" }),\n                method: \"POST\",\n            };\n            yield this.getHttpResponse(`${this.nextcloudOrigin}/remote.php/dav/comments/files/${fileId}`, requestInit, [201], { description: \"File add comment\" }); // created\n        });\n    }\n    /**\n     * returns comments of a file / folder\n     * @param fileId the id of the file / folder\n     * @param top number of comments to return\n     * @param skip the offset\n     * @returns array of comment strings\n     * @throws Exception\n     */\n    getFileComments(fileId, top, skip) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"getFileComments fileId:%s\", fileId);\n            if (!top) {\n                top = 30;\n            }\n            if (!skip) {\n                skip = 0;\n            }\n            const requestInit = {\n                body: `<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n                    <oc:filter-comments xmlns:D=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\">\n                        <oc:limit>${top}</oc:limit>\n                        <oc:offset>${skip}</oc:offset>\n                    </oc:filter-comments>`,\n                method: \"REPORT\",\n            };\n            const response = yield this.getHttpResponse(`${this.nextcloudOrigin}/remote.php/dav/comments/files/${fileId}`, requestInit, [207], { description: \"File get comments\" });\n            const properties = yield this.getPropertiesFromWebDAVMultistatusResponse(response, \"\");\n            const comments = [];\n            for (const prop of properties) {\n                comments.push(prop.message);\n            }\n            return comments;\n        });\n    }\n    // ***************************************************************************************\n    // private methods\n    // ***************************************************************************************\n    /**\n     * asserts valid xml\n     * asserts multistatus response\n     * asserts that a href is available in the multistatus response\n     * asserts propstats and prop\n     * @param response the http response\n     * @param href get only properties that match the href\n     * @returns array of properties\n     * @throws NCError\n     */\n    getPropertiesFromWebDAVMultistatusResponse(response, href) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const responseContentType = response.headers.get(\"content-type\");\n            if (!responseContentType) {\n                throw new ncError_1.default(\"Response content type expected\", \"ERR_RESPONSE_WITHOUT_CONTENT_TYPE_HEADER\");\n            }\n            if (responseContentType.indexOf(\"application/xml\") === -1) {\n                throw new ncError_1.default(\"XML response content type expected\", \"ERR_XML_RESPONSE_CONTENT_TYPE_EXPECTED\");\n            }\n            const xmlBody = yield response.text();\n            if (fast_xml_parser_1.default.validate(xmlBody) !== true) {\n                throw new ncError_1.default(`The response is not valid XML: ${xmlBody}`, \"ERR_RESPONSE_NOT_INVALID_XML\");\n            }\n            const options = {\n                ignoreNameSpace: true,\n            };\n            const body = fast_xml_parser_1.default.parse(xmlBody, options);\n            // ensure that we have a multistatus response\n            if (!body.multistatus || !body.multistatus.response) {\n                throw new ncError_1.default(`The response is is not a WebDAV multistatus response`, \"ERR_RESPONSE_NO_MULTISTATUS_XML\");\n            }\n            // ensure that response is always an array\n            if (body.multistatus.response.href) {\n                body.multistatus.response = new Array(body.multistatus.response);\n            }\n            const responseProperties = [];\n            for (const res of body.multistatus.response) {\n                if (!res.href) {\n                    throw new ncError_1.default(`The mulitstatus response must have a href`, \"ERR_RESPONSE_MISSING_HREF_MULTISTATUS\");\n                }\n                //            if (res.href === href) {\n                if (!res.propstat) {\n                    throw new ncError_1.default(`The mulitstatus response must have a \"propstat\" container`, \"ERR_RESPONSE_MISSING_PROPSTAT\");\n                }\n                let propStats = res.propstat;\n                // ensure an array\n                if (res.propstat.prop) {\n                    propStats = [res.propstat];\n                }\n                for (const propStat of propStats) {\n                    if (!propStat.status) {\n                        throw new ncError_1.default(`The propstat must have a \"status\"`, \"ERR_RESPONSE_MISSING_PROPSTAT_STATUS\");\n                    }\n                    if (propStat.status === \"HTTP/1.1 200 OK\") {\n                        if (!propStat.prop) {\n                            throw new ncError_1.default(`The propstat must have a \"prop\"`, \"ERR_RESPONSE_MISSING_PROPSTAT_PROP\");\n                        }\n                        const property = propStat.prop;\n                        property._href = res.href;\n                        responseProperties.push(property);\n                    }\n                }\n                //            }\n            }\n            return responseProperties;\n        });\n    }\n    /**\n     * nextcloud creates a csrf token and stores it in the html header attribute\n     * data-requesttoken\n     * this function is currently not used\n     * @returns the csrf token / requesttoken\n     */\n    getCSRFToken() {\n        return __awaiter(this, void 0, void 0, function* () {\n            const requestInit = {\n                method: \"GET\",\n            };\n            const response = yield this.getHttpResponse(this.nextcloudOrigin, requestInit, [200], { description: \"CSER token get\" });\n            const html = yield response.text();\n            const requestToken = html.substr(html.indexOf(\"data-requesttoken=\") + 19, 89);\n            debug(\"getCSRFToken  %s\", requestToken);\n            return requestToken;\n        });\n    }\n    getHttpResponse(url, requestInit, expectedHttpStatusCode, context) {\n        return __awaiter(this, void 0, void 0, function* () {\n            if (!requestInit.headers) {\n                requestInit.headers = new node_fetch_1.Headers();\n            }\n            if (this.fakeServer) {\n                return yield this.fakeServer.getFakeHttpResponse(url, requestInit, expectedHttpStatusCode, context);\n            }\n            return yield this.httpClient.getHttpResponse(url, requestInit, expectedHttpStatusCode, context);\n        });\n    }\n    /**\n     * get contents array of a folder\n     * @param folderName Name of the folder like \"/company/branches/germany\"\n     * @param folderIndicator true if folders are requested otherwise files\n     * @returns array of folder contents meta data\n     */\n    Contents(folderName, folderIndicator) {\n        return __awaiter(this, void 0, void 0, function* () {\n            debug(\"Contents: folder %s\", folderName);\n            const folders = [];\n            folderName = this.sanitizeFolderName(folderName);\n            const resultArray = [];\n            if (folderIndicator === true) {\n                debug(\"Contents: get folders\");\n            }\n            else {\n                debug(\"Contents: get files\");\n            }\n            try {\n                const folderContentsArray = yield this.getFolderContents(folderName);\n                // debug(\"###########################\");\n                // debug(\"$s\", JSON.stringify(folderContentsArray, null, 4));\n                // debug(\"###########################\");\n                yield this.getFolderContents(folderName);\n                for (const folderElement of folderContentsArray) {\n                    if (folderElement.type === \"directory\") {\n                        if (folderIndicator === true) {\n                            resultArray.push(folderElement);\n                        }\n                    }\n                    else {\n                        if (folderIndicator === false) {\n                            debug(\"Contents folder element file %O \", folderElement);\n                            resultArray.push(folderElement);\n                        }\n                    }\n                }\n            }\n            catch (e) {\n                debug(\"Contents: exception occurred %s\", e.message);\n            }\n            return resultArray;\n        });\n    }\n    sanitizeFolderName(folderName) {\n        if (folderName[0] !== \"/\") {\n            folderName = \"/\" + folderName;\n        }\n        // remove trailing \"/\" es\n        folderName = folderName.replace(/\\/+$/, \"\");\n        if (folderName === \"\") {\n            folderName = \"/\";\n        }\n        return folderName;\n    }\n    getTagIdFromHref(href) {\n        return parseInt(href.split(\"/\")[href.split(\"/\").length - 1], 10);\n    }\n    createFolderInternal(folderName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const url = this.webDAVUrl + folderName;\n            debug(\"createFolderInternal %s\", url);\n            const requestInit = {\n                method: \"MKCOL\",\n            };\n            try {\n                yield this.getHttpResponse(url, requestInit, [201], { description: \"Folder create\" });\n            }\n            catch (err) {\n                debug(\"Error in createFolderInternal %s %s %s %s\", err.message, requestInit.method, url);\n                throw err;\n            }\n        });\n    }\n    stat(fileName) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const url = this.webDAVUrl + fileName;\n            debug(\"stat %s\", url);\n            const requestInit = {\n                body: `<?xml version=\"1.0\"?>\n            <d:propfind  xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">\n            <d:prop>\n                  <d:getlastmodified />\n                  <d:getetag />\n                  <d:getcontenttype />\n                  <d:resourcetype />\n                  <oc:fileid />\n                  <oc:permissions />\n                  <oc:size />\n                  <d:getcontentlength />\n                  <nc:has-preview />\n                  <oc:favorite />\n                  <oc:comments-unread />\n                  <oc:owner-display-name />\n                  <oc:share-types />\n            </d:prop>\n          </d:propfind>`,\n                headers: new node_fetch_1.Headers({ Depth: \"0\" }),\n                method: \"PROPFIND\",\n            };\n            let response;\n            try {\n                response = yield this.getHttpResponse(url, requestInit, [207], { description: \"File/Folder get details\" });\n            }\n            catch (err) {\n                debug(\"Error in stat %s %s %s %s\", err.message, requestInit.method, url);\n                throw err;\n            }\n            const properties = yield this.getPropertiesFromWebDAVMultistatusResponse(response, \"\");\n            let resultStat = null;\n            for (const prop of properties) {\n                resultStat = {\n                    basename: path_1.basename(fileName),\n                    fileid: prop.fileid,\n                    filename: fileName,\n                    lastmod: prop.getlastmodified,\n                    type: \"file\",\n                };\n                if (prop.getcontentlength) {\n                    resultStat.size = prop.getcontentlength;\n                }\n                else {\n                    resultStat.type = \"directory\";\n                }\n                if (prop.getcontenttype) {\n                    resultStat.mime = prop.getcontenttype;\n                }\n            }\n            if (!resultStat) {\n                debug(\"Error: response %s\", JSON.stringify(properties, null, 4));\n                throw new ncError_1.default(\"Error getting status information from : \" + url, \"ERR_STAT\");\n            }\n            return resultStat;\n        });\n    }\n    putFileContents(fileName, data) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const url = this.webDAVUrl + fileName;\n            debug(\"putFileContents %s\", url);\n            const requestInit = {\n                body: data,\n                method: \"PUT\",\n            };\n            let response;\n            try {\n                response = yield this.getHttpResponse(url, requestInit, [201, 204], { description: \"File save content\" });\n            }\n            catch (err) {\n                debug(\"Error in stat %s %s %s %s\", err.message, requestInit.method, url);\n                throw err;\n            }\n            return response;\n        });\n    }\n}\nexports.default = NCClient;\nexports.NCClient = NCClient;\nNCClient.webDavUrlPath = \"/remote.php/webdav\";\n"]}