Comparing version 4.11.2 to 5.0.0-r1
# WebDAV-Client changelog | ||
## v5.0.0-r1 | ||
_2022-11-30_ | ||
* **Major release** | ||
* [#326](https://github.com/perry-mitchell/webdav-client/issues/326) Build output is now ESM only (read [this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)) | ||
* [#269](https://github.com/perry-mitchell/webdav-client/issues/269) Axios replaced with Fetch | ||
* **Bugfix**: | ||
* [#204](https://github.com/perry-mitchell/webdav-client/issues/204) Missing engine restriction for Node | ||
* [#159](https://github.com/perry-mitchell/webdav-client/issues/159) Missing error status code | ||
Breaking changes: | ||
* Download progress no longer supported (`onDownloadProgress`): [see discussion](https://github.com/perry-mitchell/webdav-client/issues/319#issuecomment-1328323167) | ||
* Upload progress no longer supported (`onUploadProgress`): [see discussion](https://github.com/perry-mitchell/webdav-client/issues/319#issuecomment-1328323167) | ||
* Node request limitations removed: `maxBodyLength` and `maxContentLength` are no longer needed/supported | ||
## v4.11.2 | ||
@@ -4,0 +20,0 @@ _2022-11-19_ |
@@ -1,2 +0,2 @@ | ||
import { AuthHeader } from "../types"; | ||
import { AuthHeader } from "../types.js"; | ||
export declare function generateBasicAuthHeader(username: string, password: string): AuthHeader; |
@@ -1,9 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateBasicAuthHeader = void 0; | ||
var encode_1 = require("../tools/encode"); | ||
function generateBasicAuthHeader(username, password) { | ||
var encoded = (0, encode_1.toBase64)("".concat(username, ":").concat(password)); | ||
return "Basic ".concat(encoded); | ||
import { toBase64 } from "../tools/encode.js"; | ||
export function generateBasicAuthHeader(username, password) { | ||
const encoded = toBase64(`${username}:${password}`); | ||
return `Basic ${encoded}`; | ||
} | ||
exports.generateBasicAuthHeader = generateBasicAuthHeader; |
@@ -1,4 +0,4 @@ | ||
import { DigestContext, Response } from "../types"; | ||
import { DigestContext } from "../types.js"; | ||
export declare function createDigestContext(username: string, password: string): DigestContext; | ||
export declare function generateDigestAuthHeader(options: any, digest: DigestContext): string; | ||
export declare function parseDigestAuth(response: Response, _digest: DigestContext): boolean; |
@@ -1,32 +0,25 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseDigestAuth = exports.generateDigestAuthHeader = exports.createDigestContext = void 0; | ||
var md5_1 = __importDefault(require("md5")); | ||
var crypto_1 = require("../tools/crypto"); | ||
var NONCE_CHARS = "abcdef0123456789"; | ||
var NONCE_SIZE = 32; | ||
function createDigestContext(username, password) { | ||
return { username: username, password: password, nc: 0, algorithm: "md5", hasDigestAuth: false }; | ||
import md5 from "md5"; | ||
import { ha1Compute } from "../tools/crypto.js"; | ||
const NONCE_CHARS = "abcdef0123456789"; | ||
const NONCE_SIZE = 32; | ||
export function createDigestContext(username, password) { | ||
return { username, password, nc: 0, algorithm: "md5", hasDigestAuth: false }; | ||
} | ||
exports.createDigestContext = createDigestContext; | ||
function generateDigestAuthHeader(options, digest) { | ||
var url = options.url.replace("//", ""); | ||
var uri = url.indexOf("/") == -1 ? "/" : url.slice(url.indexOf("/")); | ||
var method = options.method ? options.method.toUpperCase() : "GET"; | ||
var qop = /(^|,)\s*auth\s*($|,)/.test(digest.qop) ? "auth" : false; | ||
var ncString = "00000000".concat(digest.nc).slice(-8); | ||
var ha1 = (0, crypto_1.ha1Compute)(digest.algorithm, digest.username, digest.realm, digest.password, digest.nonce, digest.cnonce); | ||
var ha2 = (0, md5_1.default)("".concat(method, ":").concat(uri)); | ||
var digestResponse = qop | ||
? (0, md5_1.default)("".concat(ha1, ":").concat(digest.nonce, ":").concat(ncString, ":").concat(digest.cnonce, ":").concat(qop, ":").concat(ha2)) | ||
: (0, md5_1.default)("".concat(ha1, ":").concat(digest.nonce, ":").concat(ha2)); | ||
var authValues = { | ||
export function generateDigestAuthHeader(options, digest) { | ||
const url = options.url.replace("//", ""); | ||
const uri = url.indexOf("/") == -1 ? "/" : url.slice(url.indexOf("/")); | ||
const method = options.method ? options.method.toUpperCase() : "GET"; | ||
const qop = /(^|,)\s*auth\s*($|,)/.test(digest.qop) ? "auth" : false; | ||
const ncString = `00000000${digest.nc}`.slice(-8); | ||
const ha1 = ha1Compute(digest.algorithm, digest.username, digest.realm, digest.password, digest.nonce, digest.cnonce); | ||
const ha2 = md5(`${method}:${uri}`); | ||
const digestResponse = qop | ||
? md5(`${ha1}:${digest.nonce}:${ncString}:${digest.cnonce}:${qop}:${ha2}`) | ||
: md5(`${ha1}:${digest.nonce}:${ha2}`); | ||
const authValues = { | ||
username: digest.username, | ||
realm: digest.realm, | ||
nonce: digest.nonce, | ||
uri: uri, | ||
qop: qop, | ||
uri, | ||
qop, | ||
response: digestResponse, | ||
@@ -38,31 +31,30 @@ nc: ncString, | ||
}; | ||
var authHeader = []; | ||
for (var k in authValues) { | ||
const authHeader = []; | ||
for (const k in authValues) { | ||
if (authValues[k]) { | ||
if (k === "qop" || k === "nc" || k === "algorithm") { | ||
authHeader.push("".concat(k, "=").concat(authValues[k])); | ||
authHeader.push(`${k}=${authValues[k]}`); | ||
} | ||
else { | ||
authHeader.push("".concat(k, "=\"").concat(authValues[k], "\"")); | ||
authHeader.push(`${k}="${authValues[k]}"`); | ||
} | ||
} | ||
} | ||
return "Digest ".concat(authHeader.join(", ")); | ||
return `Digest ${authHeader.join(", ")}`; | ||
} | ||
exports.generateDigestAuthHeader = generateDigestAuthHeader; | ||
function makeNonce() { | ||
var uid = ""; | ||
for (var i = 0; i < NONCE_SIZE; ++i) { | ||
uid = "".concat(uid).concat(NONCE_CHARS[Math.floor(Math.random() * NONCE_CHARS.length)]); | ||
let uid = ""; | ||
for (let i = 0; i < NONCE_SIZE; ++i) { | ||
uid = `${uid}${NONCE_CHARS[Math.floor(Math.random() * NONCE_CHARS.length)]}`; | ||
} | ||
return uid; | ||
} | ||
function parseDigestAuth(response, _digest) { | ||
var authHeader = response.headers["www-authenticate"] || ""; | ||
export function parseDigestAuth(response, _digest) { | ||
const authHeader = (response.headers && response.headers.get("www-authenticate")) || ""; | ||
if (authHeader.split(/\s/)[0].toLowerCase() !== "digest") { | ||
return false; | ||
} | ||
var re = /([a-z0-9_-]+)=(?:"([^"]+)"|([a-z0-9_-]+))/gi; | ||
const re = /([a-z0-9_-]+)=(?:"([^"]+)"|([a-z0-9_-]+))/gi; | ||
for (;;) { | ||
var match = re.exec(authHeader); | ||
const match = re.exec(authHeader); | ||
if (!match) { | ||
@@ -77,2 +69,1 @@ break; | ||
} | ||
exports.parseDigestAuth = parseDigestAuth; |
@@ -1,2 +0,2 @@ | ||
import { OAuthToken, WebDAVClientContext } from "../types"; | ||
import { OAuthToken, WebDAVClientContext } from "../types.js"; | ||
export declare function setupAuth(context: WebDAVClientContext, username: string, password: string, oauthToken: OAuthToken): void; |
@@ -1,31 +0,27 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setupAuth = void 0; | ||
var layerr_1 = require("layerr"); | ||
var digest_1 = require("./digest"); | ||
var basic_1 = require("./basic"); | ||
var oauth_1 = require("./oauth"); | ||
var types_1 = require("../types"); | ||
function setupAuth(context, username, password, oauthToken) { | ||
import { Layerr } from "layerr"; | ||
import { createDigestContext } from "./digest.js"; | ||
import { generateBasicAuthHeader } from "./basic.js"; | ||
import { generateTokenAuthHeader } from "./oauth.js"; | ||
import { AuthType, ErrorCode } from "../types.js"; | ||
export function setupAuth(context, username, password, oauthToken) { | ||
switch (context.authType) { | ||
case types_1.AuthType.Digest: | ||
context.digest = (0, digest_1.createDigestContext)(username, password); | ||
case AuthType.Digest: | ||
context.digest = createDigestContext(username, password); | ||
break; | ||
case types_1.AuthType.None: | ||
case AuthType.None: | ||
// Do nothing | ||
break; | ||
case types_1.AuthType.Password: | ||
context.headers.Authorization = (0, basic_1.generateBasicAuthHeader)(username, password); | ||
case AuthType.Password: | ||
context.headers.Authorization = generateBasicAuthHeader(username, password); | ||
break; | ||
case types_1.AuthType.Token: | ||
context.headers.Authorization = (0, oauth_1.generateTokenAuthHeader)(oauthToken); | ||
case AuthType.Token: | ||
context.headers.Authorization = generateTokenAuthHeader(oauthToken); | ||
break; | ||
default: | ||
throw new layerr_1.Layerr({ | ||
throw new Layerr({ | ||
info: { | ||
code: types_1.ErrorCode.InvalidAuthType | ||
code: ErrorCode.InvalidAuthType | ||
} | ||
}, "Invalid auth type: ".concat(context.authType)); | ||
}, `Invalid auth type: ${context.authType}`); | ||
} | ||
} | ||
exports.setupAuth = setupAuth; |
@@ -1,2 +0,2 @@ | ||
import { AuthHeader, OAuthToken } from "../types"; | ||
import { AuthHeader, OAuthToken } from "../types.js"; | ||
export declare function generateTokenAuthHeader(token: OAuthToken): AuthHeader; |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateTokenAuthHeader = void 0; | ||
function generateTokenAuthHeader(token) { | ||
return "".concat(token.token_type, " ").concat(token.access_token); | ||
export function generateTokenAuthHeader(token) { | ||
return `${token.token_type} ${token.access_token}`; | ||
} | ||
exports.generateTokenAuthHeader = generateTokenAuthHeader; |
@@ -1,11 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isArrayBuffer = void 0; | ||
var hasArrayBuffer = typeof ArrayBuffer === "function"; | ||
var objToString = Object.prototype.toString; | ||
const hasArrayBuffer = typeof ArrayBuffer === "function"; | ||
const { toString: objToString } = Object.prototype; | ||
// Taken from: https://github.com/fengyuanchen/is-array-buffer/blob/master/src/index.js | ||
function isArrayBuffer(value) { | ||
export function isArrayBuffer(value) { | ||
return (hasArrayBuffer && | ||
(value instanceof ArrayBuffer || objToString.call(value) === "[object ArrayBuffer]")); | ||
} | ||
exports.isArrayBuffer = isArrayBuffer; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isBuffer = void 0; | ||
function isBuffer(value) { | ||
export function isBuffer(value) { | ||
return (value != null && | ||
@@ -10,2 +7,1 @@ value.constructor != null && | ||
} | ||
exports.isBuffer = isBuffer; |
@@ -1,12 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPatcher = void 0; | ||
var hot_patcher_1 = require("hot-patcher"); | ||
var __patcher = null; | ||
function getPatcher() { | ||
import { HotPatcher } from "hot-patcher"; | ||
let __patcher = null; | ||
export function getPatcher() { | ||
if (!__patcher) { | ||
__patcher = new hot_patcher_1.HotPatcher(); | ||
__patcher = new HotPatcher(); | ||
} | ||
return __patcher; | ||
} | ||
exports.getPatcher = getPatcher; |
@@ -1,2 +0,2 @@ | ||
import { WebDAVClient, WebDAVClientOptions } from "./types"; | ||
import { WebDAVClient, WebDAVClientOptions } from "./types.js"; | ||
export declare function createClient(remoteURL: string, options?: WebDAVClientOptions): WebDAVClient; |
@@ -1,86 +0,61 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createClient = void 0; | ||
var url_1 = require("./tools/url"); | ||
var index_1 = require("./auth/index"); | ||
var copyFile_1 = require("./operations/copyFile"); | ||
var createDirectory_1 = require("./operations/createDirectory"); | ||
var createStream_1 = require("./operations/createStream"); | ||
var customRequest_1 = require("./operations/customRequest"); | ||
var deleteFile_1 = require("./operations/deleteFile"); | ||
var exists_1 = require("./operations/exists"); | ||
var directoryContents_1 = require("./operations/directoryContents"); | ||
var getFileContents_1 = require("./operations/getFileContents"); | ||
var lock_1 = require("./operations/lock"); | ||
var getQuota_1 = require("./operations/getQuota"); | ||
var stat_1 = require("./operations/stat"); | ||
var moveFile_1 = require("./operations/moveFile"); | ||
var putFileContents_1 = require("./operations/putFileContents"); | ||
var types_1 = require("./types"); | ||
var DEFAULT_CONTACT_HREF = "https://github.com/perry-mitchell/webdav-client/blob/master/LOCK_CONTACT.md"; | ||
function createClient(remoteURL, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = options.authType, authTypeRaw = _a === void 0 ? null : _a, _b = options.contactHref, contactHref = _b === void 0 ? DEFAULT_CONTACT_HREF : _b, _c = options.headers, headers = _c === void 0 ? {} : _c, httpAgent = options.httpAgent, httpsAgent = options.httpsAgent, maxBodyLength = options.maxBodyLength, maxContentLength = options.maxContentLength, password = options.password, token = options.token, username = options.username, withCredentials = options.withCredentials; | ||
var authType = authTypeRaw; | ||
import { extractURLPath } from "./tools/url.js"; | ||
import { setupAuth } from "./auth/index.js"; | ||
import { copyFile } from "./operations/copyFile.js"; | ||
import { createDirectory } from "./operations/createDirectory.js"; | ||
import { createReadStream, createWriteStream } from "./operations/createStream.js"; | ||
import { customRequest } from "./operations/customRequest.js"; | ||
import { deleteFile } from "./operations/deleteFile.js"; | ||
import { exists } from "./operations/exists.js"; | ||
import { getDirectoryContents } from "./operations/directoryContents.js"; | ||
import { getFileContents, getFileDownloadLink } from "./operations/getFileContents.js"; | ||
import { lock, unlock } from "./operations/lock.js"; | ||
import { getQuota } from "./operations/getQuota.js"; | ||
import { getStat } from "./operations/stat.js"; | ||
import { moveFile } from "./operations/moveFile.js"; | ||
import { getFileUploadLink, putFileContents } from "./operations/putFileContents.js"; | ||
import { AuthType } from "./types.js"; | ||
const DEFAULT_CONTACT_HREF = "https://github.com/perry-mitchell/webdav-client/blob/master/LOCK_CONTACT.md"; | ||
export function createClient(remoteURL, options = {}) { | ||
const { authType: authTypeRaw = null, contactHref = DEFAULT_CONTACT_HREF, headers = {}, httpAgent, httpsAgent, password, token, username, withCredentials } = options; | ||
let authType = authTypeRaw; | ||
if (!authType) { | ||
authType = username || password ? types_1.AuthType.Password : types_1.AuthType.None; | ||
authType = username || password ? AuthType.Password : AuthType.None; | ||
} | ||
var context = { | ||
authType: authType, | ||
contactHref: contactHref, | ||
const context = { | ||
authType, | ||
contactHref, | ||
headers: Object.assign({}, headers), | ||
httpAgent: httpAgent, | ||
httpsAgent: httpsAgent, | ||
maxBodyLength: maxBodyLength, | ||
maxContentLength: maxContentLength, | ||
remotePath: (0, url_1.extractURLPath)(remoteURL), | ||
remoteURL: remoteURL, | ||
password: password, | ||
token: token, | ||
username: username, | ||
withCredentials: withCredentials | ||
httpAgent, | ||
httpsAgent, | ||
remotePath: extractURLPath(remoteURL), | ||
remoteURL, | ||
password, | ||
token, | ||
username, | ||
withCredentials | ||
}; | ||
(0, index_1.setupAuth)(context, username, password, token); | ||
setupAuth(context, username, password, token); | ||
return { | ||
copyFile: function (filename, destination, options) { | ||
return (0, copyFile_1.copyFile)(context, filename, destination, options); | ||
}, | ||
createDirectory: function (path, options) { | ||
return (0, createDirectory_1.createDirectory)(context, path, options); | ||
}, | ||
createReadStream: function (filename, options) { | ||
return (0, createStream_1.createReadStream)(context, filename, options); | ||
}, | ||
createWriteStream: function (filename, options, callback) { return (0, createStream_1.createWriteStream)(context, filename, options, callback); }, | ||
customRequest: function (path, requestOptions) { | ||
return (0, customRequest_1.customRequest)(context, path, requestOptions); | ||
}, | ||
deleteFile: function (filename, options) { | ||
return (0, deleteFile_1.deleteFile)(context, filename, options); | ||
}, | ||
exists: function (path, options) { return (0, exists_1.exists)(context, path, options); }, | ||
getDirectoryContents: function (path, options) { | ||
return (0, directoryContents_1.getDirectoryContents)(context, path, options); | ||
}, | ||
getFileContents: function (filename, options) { | ||
return (0, getFileContents_1.getFileContents)(context, filename, options); | ||
}, | ||
getFileDownloadLink: function (filename) { return (0, getFileContents_1.getFileDownloadLink)(context, filename); }, | ||
getFileUploadLink: function (filename) { return (0, putFileContents_1.getFileUploadLink)(context, filename); }, | ||
getHeaders: function () { return Object.assign({}, context.headers); }, | ||
getQuota: function (options) { return (0, getQuota_1.getQuota)(context, options); }, | ||
lock: function (path, options) { return (0, lock_1.lock)(context, path, options); }, | ||
moveFile: function (filename, destinationFilename, options) { | ||
return (0, moveFile_1.moveFile)(context, filename, destinationFilename, options); | ||
}, | ||
putFileContents: function (filename, data, options) { return (0, putFileContents_1.putFileContents)(context, filename, data, options); }, | ||
setHeaders: function (headers) { | ||
copyFile: (filename, destination, options) => copyFile(context, filename, destination, options), | ||
createDirectory: (path, options) => createDirectory(context, path, options), | ||
createReadStream: (filename, options) => createReadStream(context, filename, options), | ||
createWriteStream: (filename, options, callback) => createWriteStream(context, filename, options, callback), | ||
customRequest: (path, requestOptions) => customRequest(context, path, requestOptions), | ||
deleteFile: (filename, options) => deleteFile(context, filename, options), | ||
exists: (path, options) => exists(context, path, options), | ||
getDirectoryContents: (path, options) => getDirectoryContents(context, path, options), | ||
getFileContents: (filename, options) => getFileContents(context, filename, options), | ||
getFileDownloadLink: (filename) => getFileDownloadLink(context, filename), | ||
getFileUploadLink: (filename) => getFileUploadLink(context, filename), | ||
getHeaders: () => Object.assign({}, context.headers), | ||
getQuota: (options) => getQuota(context, options), | ||
lock: (path, options) => lock(context, path, options), | ||
moveFile: (filename, destinationFilename, options) => moveFile(context, filename, destinationFilename, options), | ||
putFileContents: (filename, data, options) => putFileContents(context, filename, data, options), | ||
setHeaders: (headers) => { | ||
context.headers = Object.assign({}, headers); | ||
}, | ||
stat: function (path, options) { return (0, stat_1.getStat)(context, path, options); }, | ||
unlock: function (path, token, options) { | ||
return (0, lock_1.unlock)(context, path, token, options); | ||
} | ||
stat: (path, options) => getStat(context, path, options), | ||
unlock: (path, token, options) => unlock(context, path, token, options) | ||
}; | ||
} | ||
exports.createClient = createClient; |
@@ -1,4 +0,4 @@ | ||
export { createClient } from "./factory"; | ||
export { getPatcher } from "./compat/patcher"; | ||
export * from "./types"; | ||
export { parseStat, parseXML } from "./tools/dav"; | ||
export { createClient } from "./factory.js"; | ||
export { getPatcher } from "./compat/patcher.js"; | ||
export * from "./types.js"; | ||
export { parseStat, parseXML } from "./tools/dav.js"; |
@@ -1,25 +0,4 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseXML = exports.parseStat = exports.getPatcher = exports.createClient = void 0; | ||
var factory_1 = require("./factory"); | ||
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return factory_1.createClient; } }); | ||
var patcher_1 = require("./compat/patcher"); | ||
Object.defineProperty(exports, "getPatcher", { enumerable: true, get: function () { return patcher_1.getPatcher; } }); | ||
__exportStar(require("./types"), exports); | ||
var dav_1 = require("./tools/dav"); | ||
Object.defineProperty(exports, "parseStat", { enumerable: true, get: function () { return dav_1.parseStat; } }); | ||
Object.defineProperty(exports, "parseXML", { enumerable: true, get: function () { return dav_1.parseXML; } }); | ||
export { createClient } from "./factory.js"; | ||
export { getPatcher } from "./compat/patcher.js"; | ||
export * from "./types.js"; | ||
export { parseStat, parseXML } from "./tools/dav.js"; |
@@ -1,2 +0,2 @@ | ||
import { WebDAVClientContext, WebDAVMethodOptions } from "../types"; | ||
import { WebDAVClientContext, WebDAVMethodOptions } from "../types.js"; | ||
export declare function copyFile(context: WebDAVClientContext, filename: string, destination: string, options?: WebDAVMethodOptions): Promise<void>; |
@@ -1,67 +0,15 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.copyFile = void 0; | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
function copyFile(context, filename, destination, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestOptions, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filename)), | ||
method: "COPY", | ||
headers: { | ||
Destination: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(destination)) | ||
} | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath } from "../tools/path.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode } from "../response.js"; | ||
export async function copyFile(context, filename, destination, options = {}) { | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(filename)), | ||
method: "COPY", | ||
headers: { | ||
Destination: joinURL(context.remoteURL, encodePath(destination)) | ||
} | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
} | ||
exports.copyFile = copyFile; |
@@ -1,2 +0,2 @@ | ||
import { CreateDirectoryOptions, WebDAVClientContext } from "../types"; | ||
import { CreateDirectoryOptions, WebDAVClientContext } from "../types.js"; | ||
export declare function createDirectory(context: WebDAVClientContext, dirPath: string, options?: CreateDirectoryOptions): Promise<void>; |
@@ -1,79 +0,16 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createDirectory = void 0; | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
var stat_1 = require("./stat"); | ||
function createDirectory(context, dirPath, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestOptions, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (options.recursive === true) | ||
return [2 /*return*/, createDirectoryRecursively(context, dirPath, options)]; | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, ensureCollectionPath((0, path_1.encodePath)(dirPath))), | ||
method: "MKCOL" | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath, getAllDirectories, normalisePath } from "../tools/path.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode } from "../response.js"; | ||
import { getStat } from "./stat.js"; | ||
export async function createDirectory(context, dirPath, options = {}) { | ||
if (options.recursive === true) | ||
return createDirectoryRecursively(context, dirPath, options); | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, ensureCollectionPath(encodePath(dirPath))), | ||
method: "MKCOL" | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
} | ||
exports.createDirectory = createDirectory; | ||
/** | ||
@@ -92,57 +29,42 @@ * Ensure the path is a proper "collection" path by ensuring it has a trailing "/". | ||
} | ||
function createDirectoryRecursively(context, dirPath, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var paths, creating, _i, paths_1, testPath, testStat, err_1, error; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
paths = (0, path_1.getAllDirectories)((0, path_1.normalisePath)(dirPath)); | ||
paths.sort(function (a, b) { | ||
if (a.length > b.length) { | ||
return 1; | ||
} | ||
else if (b.length > a.length) { | ||
return -1; | ||
} | ||
return 0; | ||
}); | ||
creating = false; | ||
_i = 0, paths_1 = paths; | ||
_a.label = 1; | ||
case 1: | ||
if (!(_i < paths_1.length)) return [3 /*break*/, 10]; | ||
testPath = paths_1[_i]; | ||
if (!creating) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, createDirectory(context, testPath, __assign(__assign({}, options), { recursive: false }))]; | ||
case 2: | ||
_a.sent(); | ||
return [3 /*break*/, 9]; | ||
case 3: | ||
_a.trys.push([3, 5, , 9]); | ||
return [4 /*yield*/, (0, stat_1.getStat)(context, testPath)]; | ||
case 4: | ||
testStat = (_a.sent()); | ||
if (testStat.type !== "directory") { | ||
throw new Error("Path includes a file: ".concat(dirPath)); | ||
} | ||
return [3 /*break*/, 9]; | ||
case 5: | ||
err_1 = _a.sent(); | ||
error = err_1; | ||
if (!(error.status === 404)) return [3 /*break*/, 7]; | ||
creating = true; | ||
return [4 /*yield*/, createDirectory(context, testPath, __assign(__assign({}, options), { recursive: false }))]; | ||
case 6: | ||
_a.sent(); | ||
return [3 /*break*/, 8]; | ||
case 7: throw err_1; | ||
case 8: return [3 /*break*/, 9]; | ||
case 9: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 10: return [2 /*return*/]; | ||
async function createDirectoryRecursively(context, dirPath, options = {}) { | ||
const paths = getAllDirectories(normalisePath(dirPath)); | ||
paths.sort((a, b) => { | ||
if (a.length > b.length) { | ||
return 1; | ||
} | ||
else if (b.length > a.length) { | ||
return -1; | ||
} | ||
return 0; | ||
}); | ||
let creating = false; | ||
for (const testPath of paths) { | ||
if (creating) { | ||
await createDirectory(context, testPath, { | ||
...options, | ||
recursive: false | ||
}); | ||
continue; | ||
} | ||
try { | ||
const testStat = (await getStat(context, testPath)); | ||
if (testStat.type !== "directory") { | ||
throw new Error(`Path includes a file: ${dirPath}`); | ||
} | ||
}); | ||
}); | ||
} | ||
catch (err) { | ||
const error = err; | ||
if (error.status === 404) { | ||
creating = true; | ||
await createDirectory(context, testPath, { | ||
...options, | ||
recursive: false | ||
}); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
} | ||
} |
/// <reference types="node" /> | ||
import Stream from "stream"; | ||
import { CreateReadStreamOptions, CreateWriteStreamCallback, CreateWriteStreamOptions, WebDAVClientContext } from "../types"; | ||
import { CreateReadStreamOptions, CreateWriteStreamCallback, CreateWriteStreamOptions, WebDAVClientContext } from "../types.js"; | ||
export declare function createReadStream(context: WebDAVClientContext, filePath: string, options?: CreateReadStreamOptions): Stream.Readable; | ||
export declare function createWriteStream(context: WebDAVClientContext, filePath: string, options?: CreateWriteStreamOptions, callback?: CreateWriteStreamCallback): Stream.Writable; |
@@ -1,58 +0,15 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createWriteStream = exports.createReadStream = void 0; | ||
var stream_1 = __importDefault(require("stream")); | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
var NOOP = function () { }; | ||
function createReadStream(context, filePath, options) { | ||
if (options === void 0) { options = {}; } | ||
var PassThroughStream = stream_1.default.PassThrough; | ||
var outStream = new PassThroughStream(); | ||
import Stream from "stream"; | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath } from "../tools/path.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode } from "../response.js"; | ||
const NOOP = () => { }; | ||
export function createReadStream(context, filePath, options = {}) { | ||
const PassThroughStream = Stream.PassThrough; | ||
const outStream = new PassThroughStream(); | ||
getFileStream(context, filePath, options) | ||
.then(function (stream) { | ||
.then(stream => { | ||
stream.pipe(outStream); | ||
}) | ||
.catch(function (err) { | ||
.catch(err => { | ||
outStream.emit("error", err); | ||
@@ -62,28 +19,25 @@ }); | ||
} | ||
exports.createReadStream = createReadStream; | ||
function createWriteStream(context, filePath, options, callback) { | ||
if (options === void 0) { options = {}; } | ||
if (callback === void 0) { callback = NOOP; } | ||
var PassThroughStream = stream_1.default.PassThrough; | ||
var writeStream = new PassThroughStream(); | ||
var headers = {}; | ||
export function createWriteStream(context, filePath, options = {}, callback = NOOP) { | ||
const PassThroughStream = Stream.PassThrough; | ||
const writeStream = new PassThroughStream(); | ||
const headers = {}; | ||
if (options.overwrite === false) { | ||
headers["If-None-Match"] = "*"; | ||
} | ||
var requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filePath)), | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(filePath)), | ||
method: "PUT", | ||
headers: headers, | ||
headers, | ||
data: writeStream, | ||
maxRedirects: 0 | ||
}, context, options); | ||
(0, request_1.request)(requestOptions) | ||
.then(function (response) { return (0, response_1.handleResponseCode)(context, response); }) | ||
.then(function (response) { | ||
request(requestOptions) | ||
.then(response => handleResponseCode(context, response)) | ||
.then(response => { | ||
// Fire callback asynchronously to avoid errors | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
callback(response); | ||
}, 0); | ||
}) | ||
.catch(function (err) { | ||
.catch(err => { | ||
writeStream.emit("error", err); | ||
@@ -93,42 +47,30 @@ }); | ||
} | ||
exports.createWriteStream = createWriteStream; | ||
function getFileStream(context, filePath, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var headers, rangeHeader, requestOptions, response, responseError; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
headers = {}; | ||
if (typeof options.range === "object" && typeof options.range.start === "number") { | ||
rangeHeader = "bytes=".concat(options.range.start, "-"); | ||
if (typeof options.range.end === "number") { | ||
rangeHeader = "".concat(rangeHeader).concat(options.range.end); | ||
} | ||
headers.Range = rangeHeader; | ||
} | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filePath)), | ||
method: "GET", | ||
headers: headers, | ||
responseType: "stream" | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
if (headers.Range && response.status !== 206) { | ||
responseError = new Error("Invalid response code for partial request: ".concat(response.status)); | ||
responseError.status = response.status; | ||
throw responseError; | ||
} | ||
if (options.callback) { | ||
setTimeout(function () { | ||
options.callback(response); | ||
}, 0); | ||
} | ||
return [2 /*return*/, response.data]; | ||
} | ||
}); | ||
}); | ||
async function getFileStream(context, filePath, options = {}) { | ||
const headers = {}; | ||
if (typeof options.range === "object" && typeof options.range.start === "number") { | ||
let rangeHeader = `bytes=${options.range.start}-`; | ||
if (typeof options.range.end === "number") { | ||
rangeHeader = `${rangeHeader}${options.range.end}`; | ||
} | ||
headers.Range = rangeHeader; | ||
} | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(filePath)), | ||
method: "GET", | ||
headers | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
if (headers.Range && response.status !== 206) { | ||
const responseError = new Error(`Invalid response code for partial request: ${response.status}`); | ||
responseError.status = response.status; | ||
throw responseError; | ||
} | ||
if (options.callback) { | ||
setTimeout(() => { | ||
options.callback(response); | ||
}, 0); | ||
} | ||
// @ts-ignore | ||
return response.body; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { RequestOptionsCustom, Response, WebDAVClientContext } from "../types"; | ||
import { RequestOptionsCustom, WebDAVClientContext } from "../types.js"; | ||
export declare function customRequest(context: WebDAVClientContext, remotePath: string, requestOptions: RequestOptionsCustom): Promise<Response>; |
@@ -1,63 +0,13 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath } from "../tools/path.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode } from "../response.js"; | ||
export async function customRequest(context, remotePath, requestOptions) { | ||
if (!requestOptions.url) { | ||
requestOptions.url = joinURL(context.remoteURL, encodePath(remotePath)); | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.customRequest = void 0; | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
function customRequest(context, remotePath, requestOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var finalOptions, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!requestOptions.url) { | ||
requestOptions.url = (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(remotePath)); | ||
} | ||
finalOptions = (0, request_1.prepareRequestOptions)(requestOptions, context, {}); | ||
return [4 /*yield*/, (0, request_1.request)(finalOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
const finalOptions = prepareRequestOptions(requestOptions, context, {}); | ||
const response = await request(finalOptions); | ||
handleResponseCode(context, response); | ||
return response; | ||
} | ||
exports.customRequest = customRequest; |
@@ -1,2 +0,2 @@ | ||
import { WebDAVClientContext, WebDAVMethodOptions } from "../types"; | ||
import { WebDAVClientContext, WebDAVMethodOptions } from "../types.js"; | ||
export declare function deleteFile(context: WebDAVClientContext, filename: string, options?: WebDAVMethodOptions): Promise<void>; |
@@ -1,64 +0,12 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deleteFile = void 0; | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
function deleteFile(context, filename, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestOptions, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filename)), | ||
method: "DELETE" | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath } from "../tools/path.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode } from "../response.js"; | ||
export async function deleteFile(context, filename, options = {}) { | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(filename)), | ||
method: "DELETE" | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
} | ||
exports.deleteFile = deleteFile; |
@@ -1,2 +0,2 @@ | ||
import { FileStat, GetDirectoryContentsOptions, ResponseDataDetailed, WebDAVClientContext } from "../types"; | ||
import { FileStat, GetDirectoryContentsOptions, ResponseDataDetailed, WebDAVClientContext } from "../types.js"; | ||
export declare function getDirectoryContents(context: WebDAVClientContext, remotePath: string, options?: GetDirectoryContentsOptions): Promise<Array<FileStat> | ResponseDataDetailed<Array<FileStat>>>; |
@@ -1,106 +0,50 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
import pathPosix from "path-posix"; | ||
import { joinURL, normaliseHREF } from "../tools/url.js"; | ||
import { encodePath, normalisePath } from "../tools/path.js"; | ||
import { parseXML, prepareFileFromProps } from "../tools/dav.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode, processGlobFilter, processResponsePayload } from "../response.js"; | ||
export async function getDirectoryContents(context, remotePath, options = {}) { | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(remotePath), "/"), | ||
method: "PROPFIND", | ||
headers: { | ||
Accept: "text/plain,application/xml", | ||
Depth: options.deep ? "infinity" : "1" | ||
} | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
const responseData = await response.text(); | ||
if (!responseData) { | ||
throw new Error("Failed parsing directory contents: Empty response"); | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDirectoryContents = void 0; | ||
var path_posix_1 = __importDefault(require("path-posix")); | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var dav_1 = require("../tools/dav"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
function getDirectoryContents(context, remotePath, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestOptions, response, davResp, _remotePath, files; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(remotePath), "/"), | ||
method: "PROPFIND", | ||
headers: { | ||
Accept: "text/plain", | ||
Depth: options.deep ? "infinity" : "1" | ||
}, | ||
responseType: "text" | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [4 /*yield*/, (0, dav_1.parseXML)(response.data)]; | ||
case 2: | ||
davResp = _a.sent(); | ||
_remotePath = remotePath.startsWith("/") ? remotePath : "/" + remotePath; | ||
files = getDirectoryFiles(davResp, context.remotePath, _remotePath, options.details); | ||
if (options.glob) { | ||
files = (0, response_1.processGlobFilter)(files, options.glob); | ||
} | ||
return [2 /*return*/, (0, response_1.processResponsePayload)(response, files, options.details)]; | ||
} | ||
}); | ||
}); | ||
const davResp = await parseXML(responseData); | ||
const _remotePath = remotePath.startsWith("/") ? remotePath : "/" + remotePath; | ||
let files = getDirectoryFiles(davResp, context.remotePath, _remotePath, options.details); | ||
if (options.glob) { | ||
files = processGlobFilter(files, options.glob); | ||
} | ||
return processResponsePayload(response, files, options.details); | ||
} | ||
exports.getDirectoryContents = getDirectoryContents; | ||
function getDirectoryFiles(result, serverBasePath, requestPath, isDetailed) { | ||
if (isDetailed === void 0) { isDetailed = false; } | ||
var serverBase = path_posix_1.default.join(serverBasePath, "/"); | ||
function getDirectoryFiles(result, serverBasePath, requestPath, isDetailed = false) { | ||
const serverBase = pathPosix.join(serverBasePath, "/"); | ||
// Extract the response items (directory contents) | ||
var responseItems = result.multistatus.response; | ||
const { multistatus: { response: responseItems } } = result; | ||
return (responseItems | ||
// Map all items to a consistent output structure (results) | ||
.map(function (item) { | ||
.map(item => { | ||
// HREF is the file path (in full) | ||
var href = (0, url_1.normaliseHREF)(item.href); | ||
const href = normaliseHREF(item.href); | ||
// Each item should contain a stat object | ||
var props = item.propstat.prop; | ||
const { propstat: { prop: props } } = item; | ||
// Process the true full filename (minus the base server path) | ||
var filename = serverBase === "/" | ||
? decodeURIComponent((0, path_1.normalisePath)(href)) | ||
: decodeURIComponent((0, path_1.normalisePath)(path_posix_1.default.relative(serverBase, href))); | ||
return (0, dav_1.prepareFileFromProps)(props, filename, isDetailed); | ||
const filename = serverBase === "/" | ||
? decodeURIComponent(normalisePath(href)) | ||
: decodeURIComponent(normalisePath(pathPosix.relative(serverBase, href))); | ||
return prepareFileFromProps(props, filename, isDetailed); | ||
}) | ||
// Filter out the item pointing to the current directory (not needed) | ||
.filter(function (item) { | ||
return item.basename && | ||
(item.type === "file" || item.filename !== requestPath.replace(/\/$/, "")); | ||
})); | ||
.filter(item => item.basename && | ||
(item.type === "file" || item.filename !== requestPath.replace(/\/$/, "")))); | ||
} |
@@ -1,2 +0,2 @@ | ||
import { WebDAVClientContext, WebDAVMethodOptions } from "../types"; | ||
import { WebDAVClientContext, WebDAVMethodOptions } from "../types.js"; | ||
export declare function exists(context: WebDAVClientContext, remotePath: string, options?: WebDAVMethodOptions): Promise<boolean>; |
@@ -1,64 +0,13 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
import { getStat } from "./stat.js"; | ||
export async function exists(context, remotePath, options = {}) { | ||
try { | ||
await getStat(context, remotePath, options); | ||
return true; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.exists = void 0; | ||
var stat_1 = require("./stat"); | ||
function exists(context, remotePath, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, (0, stat_1.getStat)(context, remotePath, options)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, true]; | ||
case 2: | ||
err_1 = _a.sent(); | ||
if (err_1.status === 404) { | ||
return [2 /*return*/, false]; | ||
} | ||
throw err_1; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
catch (err) { | ||
if (err.status === 404) { | ||
return false; | ||
} | ||
throw err; | ||
} | ||
} | ||
exports.exists = exists; |
@@ -1,3 +0,3 @@ | ||
import { BufferLike, GetFileContentsOptions, ResponseDataDetailed, WebDAVClientContext } from "../types"; | ||
import { BufferLike, GetFileContentsOptions, ResponseDataDetailed, WebDAVClientContext } from "../types.js"; | ||
export declare function getFileContents(context: WebDAVClientContext, filePath: string, options?: GetFileContentsOptions): Promise<BufferLike | string | ResponseDataDetailed<BufferLike | string>>; | ||
export declare function getFileDownloadLink(context: WebDAVClientContext, filePath: string): string; |
@@ -1,133 +0,74 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
import { Layerr } from "layerr"; | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath } from "../tools/path.js"; | ||
import { fromBase64 } from "../tools/encode.js"; | ||
import { isWeb } from "../compat/env.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode, processResponsePayload } from "../response.js"; | ||
import { AuthType, ErrorCode } from "../types.js"; | ||
const TRANSFORM_RETAIN_FORMAT = (v) => v; | ||
export async function getFileContents(context, filePath, options = {}) { | ||
const { format = "binary" } = options; | ||
if (format !== "binary" && format !== "text") { | ||
throw new Layerr({ | ||
info: { | ||
code: ErrorCode.InvalidOutputFormat | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
}, `Invalid output format: ${format}`); | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFileDownloadLink = exports.getFileContents = void 0; | ||
var layerr_1 = require("layerr"); | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var encode_1 = require("../tools/encode"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
var types_1 = require("../types"); | ||
var TRANSFORM_RETAIN_FORMAT = function (v) { return v; }; | ||
function getFileContents(context, filePath, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, format; | ||
return __generator(this, function (_b) { | ||
_a = options.format, format = _a === void 0 ? "binary" : _a; | ||
if (format !== "binary" && format !== "text") { | ||
throw new layerr_1.Layerr({ | ||
info: { | ||
code: types_1.ErrorCode.InvalidOutputFormat | ||
} | ||
}, "Invalid output format: ".concat(format)); | ||
} | ||
return [2 /*return*/, format === "text" | ||
? getFileContentsString(context, filePath, options) | ||
: getFileContentsBuffer(context, filePath, options)]; | ||
}); | ||
}); | ||
return format === "text" | ||
? getFileContentsString(context, filePath, options) | ||
: getFileContentsBuffer(context, filePath, options); | ||
} | ||
exports.getFileContents = getFileContents; | ||
function getFileContentsBuffer(context, filePath, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestOptions, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filePath)), | ||
method: "GET", | ||
responseType: "arraybuffer" | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [2 /*return*/, (0, response_1.processResponsePayload)(response, response.data, options.details)]; | ||
} | ||
}); | ||
}); | ||
async function getFileContentsBuffer(context, filePath, options = {}) { | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(filePath)), | ||
method: "GET" | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
let body; | ||
if (isWeb()) { | ||
body = await response.arrayBuffer(); | ||
} | ||
else { | ||
body = Buffer.from(await response.arrayBuffer()); | ||
} | ||
return processResponsePayload(response, body, options.details); | ||
} | ||
function getFileContentsString(context, filePath, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestOptions, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filePath)), | ||
method: "GET", | ||
responseType: "text", | ||
transformResponse: [TRANSFORM_RETAIN_FORMAT] | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [2 /*return*/, (0, response_1.processResponsePayload)(response, response.data, options.details)]; | ||
} | ||
}); | ||
}); | ||
async function getFileContentsString(context, filePath, options = {}) { | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(filePath)), | ||
method: "GET", | ||
headers: { | ||
Accept: "text/plain" | ||
}, | ||
transformResponse: [TRANSFORM_RETAIN_FORMAT] | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
const body = await response.text(); | ||
return processResponsePayload(response, body, options.details); | ||
} | ||
function getFileDownloadLink(context, filePath) { | ||
var url = (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filePath)); | ||
var protocol = /^https:/i.test(url) ? "https" : "http"; | ||
export function getFileDownloadLink(context, filePath) { | ||
let url = joinURL(context.remoteURL, encodePath(filePath)); | ||
const protocol = /^https:/i.test(url) ? "https" : "http"; | ||
switch (context.authType) { | ||
case types_1.AuthType.None: | ||
case AuthType.None: | ||
// Do nothing | ||
break; | ||
case types_1.AuthType.Password: { | ||
var authPart = context.headers.Authorization.replace(/^Basic /i, "").trim(); | ||
var authContents = (0, encode_1.fromBase64)(authPart); | ||
url = url.replace(/^https?:\/\//, "".concat(protocol, "://").concat(authContents, "@")); | ||
case AuthType.Password: { | ||
const authPart = context.headers.Authorization.replace(/^Basic /i, "").trim(); | ||
const authContents = fromBase64(authPart); | ||
url = url.replace(/^https?:\/\//, `${protocol}://${authContents}@`); | ||
break; | ||
} | ||
default: | ||
throw new layerr_1.Layerr({ | ||
throw new Layerr({ | ||
info: { | ||
code: types_1.ErrorCode.LinkUnsupportedAuthType | ||
code: ErrorCode.LinkUnsupportedAuthType | ||
} | ||
}, "Unsupported auth type for file link: ".concat(context.authType)); | ||
}, `Unsupported auth type for file link: ${context.authType}`); | ||
} | ||
return url; | ||
} | ||
exports.getFileDownloadLink = getFileDownloadLink; |
@@ -1,2 +0,2 @@ | ||
import { DiskQuota, GetQuotaOptions, ResponseDataDetailed, WebDAVClientContext } from "../types"; | ||
import { DiskQuota, GetQuotaOptions, ResponseDataDetailed, WebDAVClientContext } from "../types.js"; | ||
export declare function getQuota(context: WebDAVClientContext, options?: GetQuotaOptions): Promise<DiskQuota | null | ResponseDataDetailed<DiskQuota | null>>; |
@@ -1,75 +0,22 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getQuota = void 0; | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
var dav_1 = require("../tools/dav"); | ||
var url_1 = require("../tools/url"); | ||
var quota_1 = require("../tools/quota"); | ||
function getQuota(context, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var path, requestOptions, response, result, quota; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
path = options.path || "/"; | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, path), | ||
method: "PROPFIND", | ||
headers: { | ||
Accept: "text/plain", | ||
Depth: "0" | ||
}, | ||
responseType: "text" | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [4 /*yield*/, (0, dav_1.parseXML)(response.data)]; | ||
case 2: | ||
result = _a.sent(); | ||
quota = (0, quota_1.parseQuota)(result); | ||
return [2 /*return*/, (0, response_1.processResponsePayload)(response, quota, options.details)]; | ||
} | ||
}); | ||
}); | ||
import { prepareRequestOptions, request } from "../request.js"; | ||
import { handleResponseCode, processResponsePayload } from "../response.js"; | ||
import { parseXML } from "../tools/dav.js"; | ||
import { joinURL } from "../tools/url.js"; | ||
import { parseQuota } from "../tools/quota.js"; | ||
export async function getQuota(context, options = {}) { | ||
const path = options.path || "/"; | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, path), | ||
method: "PROPFIND", | ||
headers: { | ||
Accept: "text/plain,application/xml", | ||
Depth: "0" | ||
} | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
const responseData = await response.text(); | ||
const result = await parseXML(responseData); | ||
const quota = parseQuota(result); | ||
return processResponsePayload(response, quota, options.details); | ||
} | ||
exports.getQuota = getQuota; |
@@ -1,3 +0,3 @@ | ||
import { LockOptions, LockResponse, WebDAVClientContext, WebDAVMethodOptions } from "../types"; | ||
import { LockOptions, LockResponse, WebDAVClientContext, WebDAVMethodOptions } from "../types.js"; | ||
export declare function lock(context: WebDAVClientContext, path: string, options?: LockOptions): Promise<LockResponse>; | ||
export declare function unlock(context: WebDAVClientContext, path: string, token: string, options?: WebDAVMethodOptions): Promise<void>; |
@@ -1,119 +0,52 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
import nestedProp from "nested-property"; | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath } from "../tools/path.js"; | ||
import { generateLockXML, parseGenericResponse } from "../tools/xml.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { createErrorFromResponse, handleResponseCode } from "../response.js"; | ||
const DEFAULT_TIMEOUT = "Infinite, Second-4100000000"; | ||
export async function lock(context, path, options = {}) { | ||
const { refreshToken, timeout = DEFAULT_TIMEOUT } = options; | ||
const headers = { | ||
Accept: "text/plain,application/xml", | ||
Timeout: timeout | ||
}; | ||
if (refreshToken) { | ||
headers.If = refreshToken; | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unlock = exports.lock = void 0; | ||
var nested_property_1 = __importDefault(require("nested-property")); | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var xml_1 = require("../tools/xml"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
var DEFAULT_TIMEOUT = "Infinite, Second-4100000000"; | ||
function lock(context, path, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var refreshToken, _a, timeout, headers, requestOptions, response, lockPayload, token, serverTimeout, err; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
refreshToken = options.refreshToken, _a = options.timeout, timeout = _a === void 0 ? DEFAULT_TIMEOUT : _a; | ||
headers = { | ||
Accept: "text/plain,application/xml", | ||
Timeout: timeout | ||
}; | ||
if (refreshToken) { | ||
headers.If = refreshToken; | ||
} | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(path)), | ||
method: "LOCK", | ||
headers: headers, | ||
data: (0, xml_1.generateLockXML)(context.contactHref), | ||
responseType: "text" | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _b.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
lockPayload = (0, xml_1.parseGenericResponse)(response.data); | ||
token = nested_property_1.default.get(lockPayload, "prop.lockdiscovery.activelock.locktoken.href"); | ||
serverTimeout = nested_property_1.default.get(lockPayload, "prop.lockdiscovery.activelock.timeout"); | ||
if (!token) { | ||
err = (0, response_1.createErrorFromResponse)(response, "No lock token received: "); | ||
throw err; | ||
} | ||
return [2 /*return*/, { | ||
token: token, | ||
serverTimeout: serverTimeout | ||
}]; | ||
} | ||
}); | ||
}); | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(path)), | ||
method: "LOCK", | ||
headers, | ||
data: generateLockXML(context.contactHref) | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
const responseData = await response.text(); | ||
const lockPayload = parseGenericResponse(responseData); | ||
const token = nestedProp.get(lockPayload, "prop.lockdiscovery.activelock.locktoken.href"); | ||
const serverTimeout = nestedProp.get(lockPayload, "prop.lockdiscovery.activelock.timeout"); | ||
if (!token) { | ||
const err = createErrorFromResponse(response, "No lock token received: "); | ||
throw err; | ||
} | ||
return { | ||
token, | ||
serverTimeout | ||
}; | ||
} | ||
exports.lock = lock; | ||
function unlock(context, path, token, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestOptions, response, err; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(path)), | ||
method: "UNLOCK", | ||
headers: { | ||
"Lock-Token": token | ||
} | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
if (response.status !== 204 && response.status !== 200) { | ||
err = (0, response_1.createErrorFromResponse)(response); | ||
throw err; | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
export async function unlock(context, path, token, options = {}) { | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(path)), | ||
method: "UNLOCK", | ||
headers: { | ||
"Lock-Token": token | ||
} | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
if (response.status !== 204 && response.status !== 200) { | ||
const err = createErrorFromResponse(response); | ||
throw err; | ||
} | ||
} | ||
exports.unlock = unlock; |
@@ -1,2 +0,2 @@ | ||
import { WebDAVClientContext, WebDAVMethodOptions } from "../types"; | ||
import { WebDAVClientContext, WebDAVMethodOptions } from "../types.js"; | ||
export declare function moveFile(context: WebDAVClientContext, filename: string, destination: string, options?: WebDAVMethodOptions): Promise<void>; |
@@ -1,67 +0,15 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.moveFile = void 0; | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
function moveFile(context, filename, destination, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestOptions, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filename)), | ||
method: "MOVE", | ||
headers: { | ||
Destination: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(destination)) | ||
} | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _a.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath } from "../tools/path.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode } from "../response.js"; | ||
export async function moveFile(context, filename, destination, options = {}) { | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(filename)), | ||
method: "MOVE", | ||
headers: { | ||
Destination: joinURL(context.remoteURL, encodePath(destination)) | ||
} | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
} | ||
exports.moveFile = moveFile; |
/// <reference types="node" /> | ||
import Stream from "stream"; | ||
import { BufferLike, PutFileContentsOptions, WebDAVClientContext } from "../types"; | ||
import { BufferLike, PutFileContentsOptions, WebDAVClientContext } from "../types.js"; | ||
export declare function putFileContents(context: WebDAVClientContext, filePath: string, data: string | BufferLike | Stream.Readable, options?: PutFileContentsOptions): Promise<boolean>; | ||
export declare function getFileUploadLink(context: WebDAVClientContext, filePath: string): string; |
@@ -1,130 +0,76 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
import { Layerr } from "layerr"; | ||
import Stream from "stream"; | ||
import { fromBase64 } from "../tools/encode.js"; | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath } from "../tools/path.js"; | ||
import { calculateDataLength } from "../tools/size.js"; | ||
import { isWeb } from "../compat/env.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode } from "../response.js"; | ||
import { AuthType, ErrorCode } from "../types.js"; | ||
export async function putFileContents(context, filePath, data, options = {}) { | ||
const { contentLength = true, overwrite = true } = options; | ||
const headers = { | ||
"Content-Type": "application/octet-stream" | ||
}; | ||
if (!isWeb() && | ||
typeof Stream !== "undefined" && | ||
typeof Stream?.Readable !== "undefined" && | ||
data instanceof Stream.Readable) { | ||
// Skip, no content-length | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFileUploadLink = exports.putFileContents = void 0; | ||
var layerr_1 = require("layerr"); | ||
var stream_1 = __importDefault(require("stream")); | ||
var encode_1 = require("../tools/encode"); | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
var size_1 = require("../tools/size"); | ||
var types_1 = require("../types"); | ||
function putFileContents(context, filePath, data, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, contentLength, _b, overwrite, headers, requestOptions, response, error; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = options.contentLength, contentLength = _a === void 0 ? true : _a, _b = options.overwrite, overwrite = _b === void 0 ? true : _b; | ||
headers = { | ||
"Content-Type": "application/octet-stream" | ||
}; | ||
if (typeof WEB === "undefined" && | ||
typeof stream_1.default !== "undefined" && | ||
typeof (stream_1.default === null || stream_1.default === void 0 ? void 0 : stream_1.default.Readable) !== "undefined" && | ||
data instanceof stream_1.default.Readable) { | ||
// Skip, no content-length | ||
} | ||
else if (contentLength === false) { | ||
// Skip, disabled | ||
} | ||
else if (typeof contentLength === "number") { | ||
headers["Content-Length"] = "".concat(contentLength); | ||
} | ||
else { | ||
headers["Content-Length"] = "".concat((0, size_1.calculateDataLength)(data)); | ||
} | ||
if (!overwrite) { | ||
headers["If-None-Match"] = "*"; | ||
} | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filePath)), | ||
method: "PUT", | ||
headers: headers, | ||
data: data | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _c.sent(); | ||
try { | ||
(0, response_1.handleResponseCode)(context, response); | ||
} | ||
catch (err) { | ||
error = err; | ||
if (error.status === 412 && !overwrite) { | ||
return [2 /*return*/, false]; | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
return [2 /*return*/, true]; | ||
} | ||
}); | ||
}); | ||
else if (contentLength === false) { | ||
// Skip, disabled | ||
} | ||
else if (typeof contentLength === "number") { | ||
headers["Content-Length"] = `${contentLength}`; | ||
} | ||
else { | ||
headers["Content-Length"] = `${calculateDataLength(data)}`; | ||
} | ||
if (!overwrite) { | ||
headers["If-None-Match"] = "*"; | ||
} | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(filePath)), | ||
method: "PUT", | ||
headers, | ||
data | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
try { | ||
handleResponseCode(context, response); | ||
} | ||
catch (err) { | ||
const error = err; | ||
if (error.status === 412 && !overwrite) { | ||
return false; | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
return true; | ||
} | ||
exports.putFileContents = putFileContents; | ||
function getFileUploadLink(context, filePath) { | ||
var url = "".concat((0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filePath)), "?Content-Type=application/octet-stream"); | ||
var protocol = /^https:/i.test(url) ? "https" : "http"; | ||
export function getFileUploadLink(context, filePath) { | ||
let url = `${joinURL(context.remoteURL, encodePath(filePath))}?Content-Type=application/octet-stream`; | ||
const protocol = /^https:/i.test(url) ? "https" : "http"; | ||
switch (context.authType) { | ||
case types_1.AuthType.None: | ||
case AuthType.None: | ||
// Do nothing | ||
break; | ||
case types_1.AuthType.Password: { | ||
var authPart = context.headers.Authorization.replace(/^Basic /i, "").trim(); | ||
var authContents = (0, encode_1.fromBase64)(authPart); | ||
url = url.replace(/^https?:\/\//, "".concat(protocol, "://").concat(authContents, "@")); | ||
case AuthType.Password: { | ||
const authPart = context.headers.Authorization.replace(/^Basic /i, "").trim(); | ||
const authContents = fromBase64(authPart); | ||
url = url.replace(/^https?:\/\//, `${protocol}://${authContents}@`); | ||
break; | ||
} | ||
default: | ||
throw new layerr_1.Layerr({ | ||
throw new Layerr({ | ||
info: { | ||
code: types_1.ErrorCode.LinkUnsupportedAuthType | ||
code: ErrorCode.LinkUnsupportedAuthType | ||
} | ||
}, "Unsupported auth type for file link: ".concat(context.authType)); | ||
}, `Unsupported auth type for file link: ${context.authType}`); | ||
} | ||
return url; | ||
} | ||
exports.getFileUploadLink = getFileUploadLink; |
@@ -1,2 +0,2 @@ | ||
import { FileStat, ResponseDataDetailed, StatOptions, WebDAVClientContext } from "../types"; | ||
import { FileStat, ResponseDataDetailed, StatOptions, WebDAVClientContext } from "../types.js"; | ||
export declare function getStat(context: WebDAVClientContext, filename: string, options?: StatOptions): Promise<FileStat | ResponseDataDetailed<FileStat>>; |
@@ -1,75 +0,22 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getStat = void 0; | ||
var dav_1 = require("../tools/dav"); | ||
var url_1 = require("../tools/url"); | ||
var path_1 = require("../tools/path"); | ||
var request_1 = require("../request"); | ||
var response_1 = require("../response"); | ||
function getStat(context, filename, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, isDetailed, requestOptions, response, result, stat; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_a = options.details, isDetailed = _a === void 0 ? false : _a; | ||
requestOptions = (0, request_1.prepareRequestOptions)({ | ||
url: (0, url_1.joinURL)(context.remoteURL, (0, path_1.encodePath)(filename)), | ||
method: "PROPFIND", | ||
headers: { | ||
Accept: "text/plain,application/xml", | ||
Depth: "0" | ||
}, | ||
responseType: "text" | ||
}, context, options); | ||
return [4 /*yield*/, (0, request_1.request)(requestOptions)]; | ||
case 1: | ||
response = _b.sent(); | ||
(0, response_1.handleResponseCode)(context, response); | ||
return [4 /*yield*/, (0, dav_1.parseXML)(response.data)]; | ||
case 2: | ||
result = _b.sent(); | ||
stat = (0, dav_1.parseStat)(result, filename, isDetailed); | ||
return [2 /*return*/, (0, response_1.processResponsePayload)(response, stat, isDetailed)]; | ||
} | ||
}); | ||
}); | ||
import { parseStat, parseXML } from "../tools/dav.js"; | ||
import { joinURL } from "../tools/url.js"; | ||
import { encodePath } from "../tools/path.js"; | ||
import { request, prepareRequestOptions } from "../request.js"; | ||
import { handleResponseCode, processResponsePayload } from "../response.js"; | ||
export async function getStat(context, filename, options = {}) { | ||
const { details: isDetailed = false } = options; | ||
const requestOptions = prepareRequestOptions({ | ||
url: joinURL(context.remoteURL, encodePath(filename)), | ||
method: "PROPFIND", | ||
headers: { | ||
Accept: "text/plain,application/xml", | ||
Depth: "0" | ||
} | ||
}, context, options); | ||
const response = await request(requestOptions); | ||
handleResponseCode(context, response); | ||
const responseData = await response.text(); | ||
const result = await parseXML(responseData); | ||
const stat = parseStat(result, filename, isDetailed); | ||
return processResponsePayload(response, stat, isDetailed); | ||
} | ||
exports.getStat = getStat; |
@@ -1,3 +0,3 @@ | ||
import { RequestOptionsCustom, RequestOptionsWithState, Response, WebDAVClientContext, WebDAVMethodOptions } from "./types"; | ||
import { RequestOptionsCustom, RequestOptionsWithState, WebDAVClientContext, WebDAVMethodOptions } from "./types.js"; | ||
export declare function prepareRequestOptions(requestOptions: RequestOptionsCustom | RequestOptionsWithState, context: WebDAVClientContext, userOptions: WebDAVMethodOptions): RequestOptionsWithState; | ||
export declare function request(requestOptions: RequestOptionsWithState): Promise<Response>; |
@@ -1,18 +0,52 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.request = exports.prepareRequestOptions = void 0; | ||
var axios_1 = __importDefault(require("axios")); | ||
var patcher_1 = require("./compat/patcher"); | ||
var digest_1 = require("./auth/digest"); | ||
var merge_1 = require("./tools/merge"); | ||
var headers_1 = require("./tools/headers"); | ||
import { Agent as HTTPAgent } from "http"; | ||
import { Agent as HTTPSAgent } from "https"; | ||
import fetch from "cross-fetch"; | ||
import { getPatcher } from "./compat/patcher.js"; | ||
import { isWeb } from "./compat/env.js"; | ||
import { generateDigestAuthHeader, parseDigestAuth } from "./auth/digest.js"; | ||
import { cloneShallow, merge } from "./tools/merge.js"; | ||
import { mergeHeaders } from "./tools/headers.js"; | ||
import { requestDataToFetchBody } from "./tools/body.js"; | ||
function _request(requestOptions) { | ||
return (0, patcher_1.getPatcher)().patchInline("request", function (options) { return (0, axios_1.default)(options); }, requestOptions); | ||
const patcher = getPatcher(); | ||
return patcher.patchInline("request", (options) => patcher.patchInline("fetch", fetch, options.url, getFetchOptions(options)), requestOptions); | ||
} | ||
function prepareRequestOptions(requestOptions, context, userOptions) { | ||
var finalOptions = (0, merge_1.cloneShallow)(requestOptions); | ||
finalOptions.headers = (0, headers_1.mergeHeaders)(context.headers, finalOptions.headers || {}, userOptions.headers || {}); | ||
function getFetchOptions(requestOptions) { | ||
let headers = {}; | ||
// Handle standard options | ||
const opts = { | ||
method: requestOptions.method | ||
}; | ||
if (requestOptions.headers) { | ||
headers = mergeHeaders(headers, requestOptions.headers); | ||
} | ||
if (typeof requestOptions.data !== "undefined") { | ||
const [body, newHeaders] = requestDataToFetchBody(requestOptions.data); | ||
opts.body = body; | ||
headers = mergeHeaders(headers, newHeaders); | ||
} | ||
if (requestOptions.signal) { | ||
opts.signal = requestOptions.signal; | ||
} | ||
if (requestOptions.withCredentials) { | ||
opts.credentials = "include"; | ||
} | ||
// Check for node-specific options | ||
if (!isWeb()) { | ||
if (requestOptions.httpAgent || requestOptions.httpsAgent) { | ||
opts.agent = (parsedURL) => { | ||
if (parsedURL.protocol === "http:") { | ||
return requestOptions.httpAgent || new HTTPAgent(); | ||
} | ||
return requestOptions.httpsAgent || new HTTPSAgent(); | ||
}; | ||
} | ||
} | ||
// Attach headers | ||
opts.headers = headers; | ||
return opts; | ||
} | ||
export function prepareRequestOptions(requestOptions, context, userOptions) { | ||
const finalOptions = cloneShallow(requestOptions); | ||
finalOptions.headers = mergeHeaders(context.headers, finalOptions.headers || {}, userOptions.headers || {}); | ||
if (typeof userOptions.data !== "undefined") { | ||
@@ -36,20 +70,5 @@ finalOptions.data = userOptions.data; | ||
} | ||
if (context.maxContentLength) { | ||
finalOptions.maxContentLength = context.maxContentLength; | ||
} | ||
if (context.maxBodyLength) { | ||
finalOptions.maxBodyLength = context.maxBodyLength; | ||
} | ||
if (userOptions.hasOwnProperty("onUploadProgress")) { | ||
finalOptions.onUploadProgress = userOptions["onUploadProgress"]; | ||
} | ||
if (userOptions.hasOwnProperty("onDownloadProgress")) { | ||
finalOptions.onDownloadProgress = userOptions["onDownloadProgress"]; | ||
} | ||
// Take full control of all response status codes | ||
finalOptions.validateStatus = function () { return true; }; | ||
return finalOptions; | ||
} | ||
exports.prepareRequestOptions = prepareRequestOptions; | ||
function request(requestOptions) { | ||
export async function request(requestOptions) { | ||
// Client not configured for digest authentication | ||
@@ -60,39 +79,36 @@ if (!requestOptions._digest) { | ||
// Remove client's digest authentication object from request options | ||
var _digest = requestOptions._digest; | ||
const _digest = requestOptions._digest; | ||
delete requestOptions._digest; | ||
// If client is already using digest authentication, include the digest authorization header | ||
if (_digest.hasDigestAuth) { | ||
requestOptions = (0, merge_1.merge)(requestOptions, { | ||
requestOptions = merge(requestOptions, { | ||
headers: { | ||
Authorization: (0, digest_1.generateDigestAuthHeader)(requestOptions, _digest) | ||
Authorization: generateDigestAuthHeader(requestOptions, _digest) | ||
} | ||
}); | ||
} | ||
// Perform the request and handle digest authentication | ||
return _request(requestOptions).then(function (response) { | ||
if (response.status == 401) { | ||
_digest.hasDigestAuth = (0, digest_1.parseDigestAuth)(response, _digest); | ||
if (_digest.hasDigestAuth) { | ||
requestOptions = (0, merge_1.merge)(requestOptions, { | ||
headers: { | ||
Authorization: (0, digest_1.generateDigestAuthHeader)(requestOptions, _digest) | ||
} | ||
}); | ||
return _request(requestOptions).then(function (response2) { | ||
if (response2.status == 401) { | ||
_digest.hasDigestAuth = false; | ||
} | ||
else { | ||
_digest.nc++; | ||
} | ||
return response2; | ||
}); | ||
// Perform digest request + check | ||
const response = await _request(requestOptions); | ||
if (response.status == 401) { | ||
_digest.hasDigestAuth = parseDigestAuth(response, _digest); | ||
if (_digest.hasDigestAuth) { | ||
requestOptions = merge(requestOptions, { | ||
headers: { | ||
Authorization: generateDigestAuthHeader(requestOptions, _digest) | ||
} | ||
}); | ||
const response2 = await _request(requestOptions); | ||
if (response2.status == 401) { | ||
_digest.hasDigestAuth = false; | ||
} | ||
else { | ||
_digest.nc++; | ||
} | ||
return response2; | ||
} | ||
else { | ||
_digest.nc++; | ||
} | ||
return response; | ||
}); | ||
} | ||
else { | ||
_digest.nc++; | ||
} | ||
return response; | ||
} | ||
exports.request = request; |
@@ -1,2 +0,2 @@ | ||
import { FileStat, Response, ResponseDataDetailed, WebDAVClientContext } from "./types"; | ||
import { FileStat, ResponseDataDetailed, WebDAVClientContext } from "./types.js"; | ||
export declare function createErrorFromResponse(response: Response, prefix?: string): Error; | ||
@@ -3,0 +3,0 @@ export declare function handleResponseCode(context: WebDAVClientContext, response: Response): Response; |
@@ -1,11 +0,5 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.processResponsePayload = exports.processGlobFilter = exports.handleResponseCode = exports.createErrorFromResponse = void 0; | ||
var minimatch_1 = __importDefault(require("minimatch")); | ||
function createErrorFromResponse(response, prefix) { | ||
if (prefix === void 0) { prefix = ""; } | ||
var err = new Error("".concat(prefix, "Invalid response: ").concat(response.status, " ").concat(response.statusText)); | ||
import minimatch from "minimatch"; | ||
import { convertResponseHeaders } from "./tools/headers.js"; | ||
export function createErrorFromResponse(response, prefix = "") { | ||
const err = new Error(`${prefix}Invalid response: ${response.status} ${response.statusText}`); | ||
err.status = response.status; | ||
@@ -15,9 +9,8 @@ err.response = response; | ||
} | ||
exports.createErrorFromResponse = createErrorFromResponse; | ||
function handleResponseCode(context, response) { | ||
var status = response.status; | ||
export function handleResponseCode(context, response) { | ||
const { status } = response; | ||
if (status === 401 && context.digest) | ||
return response; | ||
if (status >= 400) { | ||
var err = createErrorFromResponse(response); | ||
const err = createErrorFromResponse(response); | ||
throw err; | ||
@@ -27,13 +20,10 @@ } | ||
} | ||
exports.handleResponseCode = handleResponseCode; | ||
function processGlobFilter(files, glob) { | ||
return files.filter(function (file) { return (0, minimatch_1.default)(file.filename, glob, { matchBase: true }); }); | ||
export function processGlobFilter(files, glob) { | ||
return files.filter(file => minimatch(file.filename, glob, { matchBase: true })); | ||
} | ||
exports.processGlobFilter = processGlobFilter; | ||
function processResponsePayload(response, data, isDetailed) { | ||
if (isDetailed === void 0) { isDetailed = false; } | ||
export function processResponsePayload(response, data, isDetailed = false) { | ||
return isDetailed | ||
? { | ||
data: data, | ||
headers: response.headers || {}, | ||
data, | ||
headers: response.headers ? convertResponseHeaders(response.headers) : {}, | ||
status: response.status, | ||
@@ -44,2 +34,1 @@ statusText: response.statusText | ||
} | ||
exports.processResponsePayload = processResponsePayload; |
@@ -1,15 +0,8 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ha1Compute = void 0; | ||
var md5_1 = __importDefault(require("md5")); | ||
function ha1Compute(algorithm, user, realm, pass, nonce, cnonce) { | ||
var ha1 = (0, md5_1.default)("".concat(user, ":").concat(realm, ":").concat(pass)); | ||
import md5 from "md5"; | ||
export function ha1Compute(algorithm, user, realm, pass, nonce, cnonce) { | ||
const ha1 = md5(`${user}:${realm}:${pass}`); | ||
if (algorithm && algorithm.toLowerCase() === "md5-sess") { | ||
return (0, md5_1.default)("".concat(ha1, ":").concat(nonce, ":").concat(cnonce)); | ||
return md5(`${ha1}:${nonce}:${cnonce}`); | ||
} | ||
return ha1; | ||
} | ||
exports.ha1Compute = ha1Compute; |
@@ -1,2 +0,2 @@ | ||
import { DAVResult, DAVResultResponseProps, DiskQuotaAvailable, FileStat } from "../types"; | ||
import { DAVResult, DAVResultResponseProps, DiskQuotaAvailable, FileStat } from "../types.js"; | ||
export declare function parseXML(xml: string): Promise<DAVResult>; | ||
@@ -3,0 +3,0 @@ export declare function prepareFileFromProps(props: DAVResultResponseProps, rawFilename: string, isDetailed?: boolean): FileStat; |
@@ -1,12 +0,6 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.translateDiskSpace = exports.parseStat = exports.prepareFileFromProps = exports.parseXML = void 0; | ||
var path_posix_1 = __importDefault(require("path-posix")); | ||
var fast_xml_parser_1 = __importDefault(require("fast-xml-parser")); | ||
var nested_property_1 = __importDefault(require("nested-property")); | ||
var encode_1 = require("./encode"); | ||
var path_1 = require("./path"); | ||
import path from "path-posix"; | ||
import xmlParser from "fast-xml-parser"; | ||
import nestedProp from "nested-property"; | ||
import { decodeHTMLEntities } from "./encode.js"; | ||
import { normalisePath } from "./path.js"; | ||
var PropertyType; | ||
@@ -18,5 +12,4 @@ (function (PropertyType) { | ||
})(PropertyType || (PropertyType = {})); | ||
function getPropertyOfType(obj, prop, type) { | ||
if (type === void 0) { type = PropertyType.Original; } | ||
var val = nested_property_1.default.get(obj, prop); | ||
function getPropertyOfType(obj, prop, type = PropertyType.Original) { | ||
const val = nestedProp.get(obj, prop); | ||
if (type === "array" && Array.isArray(val) === false) { | ||
@@ -31,9 +24,9 @@ return [val]; | ||
function normaliseResponse(response) { | ||
var output = Object.assign({}, response); | ||
nested_property_1.default.set(output, "propstat", getPropertyOfType(output, "propstat", PropertyType.Object)); | ||
nested_property_1.default.set(output, "propstat.prop", getPropertyOfType(output, "propstat.prop", PropertyType.Object)); | ||
const output = Object.assign({}, response); | ||
nestedProp.set(output, "propstat", getPropertyOfType(output, "propstat", PropertyType.Object)); | ||
nestedProp.set(output, "propstat.prop", getPropertyOfType(output, "propstat.prop", PropertyType.Object)); | ||
return output; | ||
} | ||
function normaliseResult(result) { | ||
var multistatus = result.multistatus; | ||
const { multistatus } = result; | ||
if (multistatus === "") { | ||
@@ -49,12 +42,12 @@ return { | ||
} | ||
var output = { | ||
const output = { | ||
multistatus: Array.isArray(multistatus) ? multistatus[0] : multistatus | ||
}; | ||
nested_property_1.default.set(output, "multistatus.response", getPropertyOfType(output, "multistatus.response", PropertyType.Array)); | ||
nested_property_1.default.set(output, "multistatus.response", nested_property_1.default.get(output, "multistatus.response").map(function (response) { return normaliseResponse(response); })); | ||
nestedProp.set(output, "multistatus.response", getPropertyOfType(output, "multistatus.response", PropertyType.Array)); | ||
nestedProp.set(output, "multistatus.response", nestedProp.get(output, "multistatus.response").map(response => normaliseResponse(response))); | ||
return output; | ||
} | ||
function parseXML(xml) { | ||
return new Promise(function (resolve) { | ||
var result = fast_xml_parser_1.default.parse(xml, { | ||
export function parseXML(xml) { | ||
return new Promise(resolve => { | ||
const result = xmlParser.parse(xml, { | ||
arrayMode: false, | ||
@@ -70,8 +63,6 @@ ignoreNameSpace: true | ||
} | ||
exports.parseXML = parseXML; | ||
function prepareFileFromProps(props, rawFilename, isDetailed) { | ||
if (isDetailed === void 0) { isDetailed = false; } | ||
export function prepareFileFromProps(props, rawFilename, isDetailed = false) { | ||
// Last modified time, raw size, item type and mime | ||
var _a = props.getlastmodified, lastMod = _a === void 0 ? null : _a, _b = props.getcontentlength, rawSize = _b === void 0 ? "0" : _b, _c = props.resourcetype, resourceType = _c === void 0 ? null : _c, _d = props.getcontenttype, mimeType = _d === void 0 ? null : _d, _e = props.getetag, etag = _e === void 0 ? null : _e; | ||
var type = resourceType && | ||
const { getlastmodified: lastMod = null, getcontentlength: rawSize = "0", resourcetype: resourceType = null, getcontenttype: mimeType = null, getetag: etag = null } = props; | ||
const type = resourceType && | ||
typeof resourceType === "object" && | ||
@@ -81,9 +72,9 @@ typeof resourceType.collection !== "undefined" | ||
: "file"; | ||
var filename = (0, encode_1.decodeHTMLEntities)(rawFilename); | ||
var stat = { | ||
filename: filename, | ||
basename: path_posix_1.default.basename(filename), | ||
const filename = decodeHTMLEntities(rawFilename); | ||
const stat = { | ||
filename, | ||
basename: path.basename(filename), | ||
lastmod: lastMod, | ||
size: parseInt(rawSize, 10), | ||
type: type, | ||
type, | ||
etag: typeof etag === "string" ? etag.replace(/"/g, "") : null | ||
@@ -99,6 +90,4 @@ }; | ||
} | ||
exports.prepareFileFromProps = prepareFileFromProps; | ||
function parseStat(result, filename, isDetailed) { | ||
if (isDetailed === void 0) { isDetailed = false; } | ||
var responseItem = null; | ||
export function parseStat(result, filename, isDetailed = false) { | ||
let responseItem = null; | ||
try { | ||
@@ -113,16 +102,15 @@ responseItem = result.multistatus.response[0]; | ||
} | ||
var _a = responseItem.propstat, props = _a.prop, statusLine = _a.status; | ||
const { propstat: { prop: props, status: statusLine } } = responseItem; | ||
// As defined in https://tools.ietf.org/html/rfc2068#section-6.1 | ||
var _b = statusLine.split(" ", 3), _ = _b[0], statusCodeStr = _b[1], statusText = _b[2]; | ||
var statusCode = parseInt(statusCodeStr, 10); | ||
const [_, statusCodeStr, statusText] = statusLine.split(" ", 3); | ||
const statusCode = parseInt(statusCodeStr, 10); | ||
if (statusCode >= 400) { | ||
var err = new Error("Invalid response: ".concat(statusCode, " ").concat(statusText)); | ||
const err = new Error(`Invalid response: ${statusCode} ${statusText}`); | ||
err.status = statusCode; | ||
throw err; | ||
} | ||
var filePath = (0, path_1.normalisePath)(filename); | ||
const filePath = normalisePath(filename); | ||
return prepareFileFromProps(props, filePath, isDetailed); | ||
} | ||
exports.parseStat = parseStat; | ||
function translateDiskSpace(value) { | ||
export function translateDiskSpace(value) { | ||
switch (value.toString()) { | ||
@@ -140,2 +128,1 @@ case "-3": | ||
} | ||
exports.translateDiskSpace = translateDiskSpace; |
@@ -1,9 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toBase64 = exports.fromBase64 = exports.decodeHTMLEntities = void 0; | ||
var base_64_1 = require("base-64"); | ||
function decodeHTMLEntities(text) { | ||
if (typeof WEB === "undefined") { | ||
import base64 from "base-64"; | ||
import he from "he"; | ||
import { isWeb } from "../compat/env.js"; | ||
export function decodeHTMLEntities(text) { | ||
if (!isWeb()) { | ||
// Node | ||
var he = require("he"); | ||
return he.decode(text); | ||
@@ -13,3 +11,3 @@ } | ||
// Nasty browser way | ||
var txt = document.createElement("textarea"); | ||
const txt = document.createElement("textarea"); | ||
txt.innerHTML = text; | ||
@@ -19,10 +17,7 @@ return txt.value; | ||
} | ||
exports.decodeHTMLEntities = decodeHTMLEntities; | ||
function fromBase64(text) { | ||
return (0, base_64_1.decode)(text); | ||
export function fromBase64(text) { | ||
return base64.decode(text); | ||
} | ||
exports.fromBase64 = fromBase64; | ||
function toBase64(text) { | ||
return (0, base_64_1.encode)(text); | ||
export function toBase64(text) { | ||
return base64.encode(text); | ||
} | ||
exports.toBase64 = toBase64; |
@@ -1,2 +0,3 @@ | ||
import { Headers } from "../types"; | ||
export declare function mergeHeaders(...headerPayloads: Headers[]): Headers; | ||
import { Headers as HeadersSimple } from "../types.js"; | ||
export declare function convertResponseHeaders(headers: Headers): HeadersSimple; | ||
export declare function mergeHeaders(...headerPayloads: HeadersSimple[]): HeadersSimple; |
@@ -1,15 +0,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mergeHeaders = void 0; | ||
function mergeHeaders() { | ||
var headerPayloads = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
headerPayloads[_i] = arguments[_i]; | ||
export function convertResponseHeaders(headers) { | ||
const output = {}; | ||
for (const key of headers.keys()) { | ||
output[key] = headers.get(key); | ||
} | ||
return output; | ||
} | ||
export function mergeHeaders(...headerPayloads) { | ||
if (headerPayloads.length === 0) | ||
return {}; | ||
var headerKeys = {}; | ||
return headerPayloads.reduce(function (output, headers) { | ||
Object.keys(headers).forEach(function (header) { | ||
var lowerHeader = header.toLowerCase(); | ||
const headerKeys = {}; | ||
return headerPayloads.reduce((output, headers) => { | ||
Object.keys(headers).forEach(header => { | ||
const lowerHeader = header.toLowerCase(); | ||
if (headerKeys.hasOwnProperty(lowerHeader)) { | ||
@@ -26,2 +26,1 @@ output[headerKeys[lowerHeader]] = headers[header]; | ||
} | ||
exports.mergeHeaders = mergeHeaders; |
@@ -1,14 +0,2 @@ | ||
"use strict"; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.merge = exports.cloneShallow = void 0; | ||
function cloneShallow(obj) { | ||
export function cloneShallow(obj) { | ||
return isPlainObject(obj) | ||
@@ -18,3 +6,2 @@ ? Object.assign({}, obj) | ||
} | ||
exports.cloneShallow = cloneShallow; | ||
function isPlainObject(obj) { | ||
@@ -30,3 +17,3 @@ if (typeof obj !== "object" || | ||
} | ||
var proto = obj; | ||
let proto = obj; | ||
// Find the prototype | ||
@@ -38,10 +25,6 @@ while (Object.getPrototypeOf(proto) !== null) { | ||
} | ||
function merge() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var output = null, items = __spreadArray([], args, true); | ||
export function merge(...args) { | ||
let output = null, items = [...args]; | ||
while (items.length > 0) { | ||
var nextItem = items.shift(); | ||
const nextItem = items.shift(); | ||
if (!output) { | ||
@@ -56,6 +39,5 @@ output = cloneShallow(nextItem); | ||
} | ||
exports.merge = merge; | ||
function mergeObjects(obj1, obj2) { | ||
var output = cloneShallow(obj1); | ||
Object.keys(obj2).forEach(function (key) { | ||
const output = cloneShallow(obj1); | ||
Object.keys(obj2).forEach(key => { | ||
if (!output.hasOwnProperty(key)) { | ||
@@ -67,3 +49,4 @@ output[key] = obj2[key]; | ||
output[key] = Array.isArray(output[key]) | ||
? __spreadArray(__spreadArray([], output[key], true), obj2[key], true) : __spreadArray([], obj2[key], true); | ||
? [...output[key], ...obj2[key]] | ||
: [...obj2[key]]; | ||
} | ||
@@ -70,0 +53,0 @@ else if (typeof obj2[key] === "object" && !!obj2[key]) { |
@@ -1,3 +0,3 @@ | ||
export declare function encodePath(path: any): string; | ||
export declare function getAllDirectories(path: string): Array<string>; | ||
export declare function encodePath(filePath: string): string; | ||
export declare function getAllDirectories(directory: string): Array<string>; | ||
export declare function normalisePath(pathStr: string): string; |
@@ -1,27 +0,28 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.normalisePath = exports.getAllDirectories = exports.encodePath = void 0; | ||
var path_posix_1 = require("path-posix"); | ||
var SEP_PATH_POSIX = "__PATH_SEPARATOR_POSIX__"; | ||
var SEP_PATH_WINDOWS = "__PATH_SEPARATOR_WINDOWS__"; | ||
function encodePath(path) { | ||
var replaced = path.replace(/\//g, SEP_PATH_POSIX).replace(/\\\\/g, SEP_PATH_WINDOWS); | ||
var formatted = encodeURIComponent(replaced); | ||
return formatted.split(SEP_PATH_WINDOWS).join("\\\\").split(SEP_PATH_POSIX).join("/"); | ||
import { Layerr } from "layerr"; | ||
import path from "path-posix"; | ||
const SEP_PATH_POSIX = "__PATH_SEPARATOR_POSIX__"; | ||
const SEP_PATH_WINDOWS = "__PATH_SEPARATOR_WINDOWS__"; | ||
export function encodePath(filePath) { | ||
try { | ||
const replaced = filePath.replace(/\//g, SEP_PATH_POSIX).replace(/\\\\/g, SEP_PATH_WINDOWS); | ||
const formatted = encodeURIComponent(replaced); | ||
return formatted.split(SEP_PATH_WINDOWS).join("\\\\").split(SEP_PATH_POSIX).join("/"); | ||
} | ||
catch (err) { | ||
throw new Layerr(err, "Failed encoding path"); | ||
} | ||
} | ||
exports.encodePath = encodePath; | ||
function getAllDirectories(path) { | ||
if (!path || path === "/") | ||
export function getAllDirectories(directory) { | ||
if (!directory || directory === "/") | ||
return []; | ||
var currentPath = path; | ||
var output = []; | ||
let currentPath = directory; | ||
const output = []; | ||
do { | ||
output.push(currentPath); | ||
currentPath = (0, path_posix_1.dirname)(currentPath); | ||
currentPath = path.dirname(currentPath); | ||
} while (currentPath && currentPath !== "/"); | ||
return output; | ||
} | ||
exports.getAllDirectories = getAllDirectories; | ||
function normalisePath(pathStr) { | ||
var normalisedPath = pathStr; | ||
export function normalisePath(pathStr) { | ||
let normalisedPath = pathStr; | ||
if (normalisedPath[0] !== "/") { | ||
@@ -35,2 +36,1 @@ normalisedPath = "/" + normalisedPath; | ||
} | ||
exports.normalisePath = normalisePath; |
@@ -1,2 +0,2 @@ | ||
import { DAVResult, DiskQuota } from "../types"; | ||
import { DAVResult, DiskQuota } from "../types.js"; | ||
export declare function parseQuota(result: DAVResult): DiskQuota | null; |
@@ -1,13 +0,10 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseQuota = void 0; | ||
var dav_1 = require("./dav"); | ||
function parseQuota(result) { | ||
import { translateDiskSpace } from "./dav.js"; | ||
export function parseQuota(result) { | ||
try { | ||
var responseItem = result.multistatus.response[0]; | ||
var _a = responseItem.propstat.prop, quotaUsed = _a["quota-used-bytes"], quotaAvail = _a["quota-available-bytes"]; | ||
const [responseItem] = result.multistatus.response; | ||
const { propstat: { prop: { "quota-used-bytes": quotaUsed, "quota-available-bytes": quotaAvail } } } = responseItem; | ||
return typeof quotaUsed !== "undefined" && typeof quotaAvail !== "undefined" | ||
? { | ||
used: parseInt(quotaUsed, 10), | ||
available: (0, dav_1.translateDiskSpace)(quotaAvail) | ||
available: translateDiskSpace(quotaAvail) | ||
} | ||
@@ -21,2 +18,1 @@ : null; | ||
} | ||
exports.parseQuota = parseQuota; |
@@ -1,2 +0,2 @@ | ||
import { BufferLike } from "../types"; | ||
import { BufferLike } from "../types.js"; | ||
export declare function calculateDataLength(data: string | BufferLike): number; |
@@ -1,25 +0,21 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calculateDataLength = void 0; | ||
var layerr_1 = require("layerr"); | ||
var byte_length_1 = require("byte-length"); | ||
var arrayBuffer_1 = require("../compat/arrayBuffer"); | ||
var buffer_1 = require("../compat/buffer"); | ||
var types_1 = require("../types"); | ||
function calculateDataLength(data) { | ||
if ((0, arrayBuffer_1.isArrayBuffer)(data)) { | ||
import { Layerr } from "layerr"; | ||
import { byteLength } from "byte-length"; | ||
import { isArrayBuffer } from "../compat/arrayBuffer.js"; | ||
import { isBuffer } from "../compat/buffer.js"; | ||
import { ErrorCode } from "../types.js"; | ||
export function calculateDataLength(data) { | ||
if (isArrayBuffer(data)) { | ||
return data.byteLength; | ||
} | ||
else if ((0, buffer_1.isBuffer)(data)) { | ||
else if (isBuffer(data)) { | ||
return data.length; | ||
} | ||
else if (typeof data === "string") { | ||
return (0, byte_length_1.byteLength)(data); | ||
return byteLength(data); | ||
} | ||
throw new layerr_1.Layerr({ | ||
throw new Layerr({ | ||
info: { | ||
code: types_1.ErrorCode.DataTypeNoLength | ||
code: ErrorCode.DataTypeNoLength | ||
} | ||
}, "Cannot calculate data length: Invalid type"); | ||
} | ||
exports.calculateDataLength = calculateDataLength; |
@@ -1,25 +0,15 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.normaliseHREF = exports.joinURL = exports.extractURLPath = void 0; | ||
var url_parse_1 = __importDefault(require("url-parse")); | ||
var url_join_1 = __importDefault(require("url-join")); | ||
var path_1 = require("./path"); | ||
function extractURLPath(fullURL) { | ||
var url = new url_parse_1.default(fullURL); | ||
var urlPath = url.pathname; | ||
import URL from "url-parse"; | ||
import { Layerr } from "layerr"; | ||
import _joinURL from "url-join"; | ||
import { normalisePath } from "./path.js"; | ||
export function extractURLPath(fullURL) { | ||
const url = new URL(fullURL); | ||
let urlPath = url.pathname; | ||
if (urlPath.length <= 0) { | ||
urlPath = "/"; | ||
} | ||
return (0, path_1.normalisePath)(urlPath); | ||
return normalisePath(urlPath); | ||
} | ||
exports.extractURLPath = extractURLPath; | ||
function joinURL() { | ||
var parts = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
parts[_i] = arguments[_i]; | ||
} | ||
return (0, url_join_1.default)(parts.reduce(function (output, nextPart, partIndex) { | ||
export function joinURL(...parts) { | ||
return _joinURL(parts.reduce((output, nextPart, partIndex) => { | ||
if (partIndex === 0 || | ||
@@ -33,7 +23,10 @@ nextPart !== "/" || | ||
} | ||
exports.joinURL = joinURL; | ||
function normaliseHREF(href) { | ||
var normalisedHref = href.replace(/^https?:\/\/[^\/]+/, ""); | ||
return normalisedHref; | ||
export function normaliseHREF(href) { | ||
try { | ||
const normalisedHref = href.replace(/^https?:\/\/[^\/]+/, ""); | ||
return normalisedHref; | ||
} | ||
catch (err) { | ||
throw new Layerr(err, "Failed normalising HREF"); | ||
} | ||
} | ||
exports.normaliseHREF = normaliseHREF; |
@@ -1,40 +0,3 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseGenericResponse = exports.generateLockXML = void 0; | ||
var fast_xml_parser_1 = __importStar(require("fast-xml-parser")); | ||
function generateLockXML(ownerHREF) { | ||
import xmlParser, { j2xParser as XMLParser } from "fast-xml-parser"; | ||
export function generateLockXML(ownerHREF) { | ||
return getParser().parse(namespace({ | ||
@@ -55,5 +18,4 @@ lockinfo: { | ||
} | ||
exports.generateLockXML = generateLockXML; | ||
function getParser() { | ||
return new fast_xml_parser_1.j2xParser({ | ||
return new XMLParser({ | ||
attributeNamePrefix: "@_", | ||
@@ -66,4 +28,4 @@ format: true, | ||
function namespace(obj, ns) { | ||
var copy = __assign({}, obj); | ||
for (var key in copy) { | ||
const copy = { ...obj }; | ||
for (const key in copy) { | ||
if (!copy.hasOwnProperty(key)) { | ||
@@ -73,7 +35,7 @@ continue; | ||
if (copy[key] && typeof copy[key] === "object" && key.indexOf(":") === -1) { | ||
copy["".concat(ns, ":").concat(key)] = namespace(copy[key], ns); | ||
copy[`${ns}:${key}`] = namespace(copy[key], ns); | ||
delete copy[key]; | ||
} | ||
else if (/^@_/.test(key) === false) { | ||
copy["".concat(ns, ":").concat(key)] = copy[key]; | ||
copy[`${ns}:${key}`] = copy[key]; | ||
delete copy[key]; | ||
@@ -84,4 +46,4 @@ } | ||
} | ||
function parseGenericResponse(xml) { | ||
return fast_xml_parser_1.default.parse(xml, { | ||
export function parseGenericResponse(xml) { | ||
return xmlParser.parse(xml, { | ||
arrayMode: false, | ||
@@ -93,2 +55,1 @@ ignoreNameSpace: true, | ||
} | ||
exports.parseGenericResponse = parseGenericResponse; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import Stream from "stream"; | ||
export declare type AuthHeader = string; | ||
import Stream from "node:stream"; | ||
import { Response } from "cross-fetch"; | ||
export type { Response }; | ||
export type AuthHeader = string; | ||
export declare enum AuthType { | ||
@@ -11,3 +13,3 @@ Digest = "digest", | ||
} | ||
export declare type BufferLike = Buffer | ArrayBuffer; | ||
export type BufferLike = Buffer | ArrayBuffer; | ||
export interface CreateDirectoryOptions extends WebDAVMethodOptions { | ||
@@ -23,3 +25,3 @@ recursive?: boolean; | ||
} | ||
export declare type CreateWriteStreamCallback = (response: Response) => void; | ||
export type CreateWriteStreamCallback = (response: Response) => void; | ||
export interface CreateWriteStreamOptions extends WebDAVMethodOptions { | ||
@@ -74,3 +76,3 @@ overwrite?: boolean; | ||
} | ||
export declare type DiskQuotaAvailable = "unknown" | "unlimited" | number; | ||
export type DiskQuotaAvailable = "unknown" | "unlimited" | number; | ||
export declare enum ErrorCode { | ||
@@ -126,3 +128,3 @@ DataTypeNoLength = "data-type-no-length", | ||
} | ||
export declare type ProgressEventCallback = (e: ProgressEvent) => void; | ||
export type ProgressEventCallback = (e: ProgressEvent) => void; | ||
export interface PutFileContentsOptions extends WebDAVMethodOptions { | ||
@@ -133,5 +135,3 @@ contentLength?: boolean | number; | ||
} | ||
export declare type RequestDataPayload = string | Buffer | ArrayBuffer | { | ||
[key: string]: any; | ||
}; | ||
export type RequestDataPayload = string | Buffer | ArrayBuffer | Record<string, any>; | ||
interface RequestOptionsBase { | ||
@@ -142,4 +142,2 @@ data?: RequestDataPayload; | ||
httpsAgent?: any; | ||
maxBodyLength?: number; | ||
maxContentLength?: number; | ||
maxRedirects?: number; | ||
@@ -149,6 +147,4 @@ method: string; | ||
onUploadProgress?: ProgressEventCallback; | ||
responseType?: string; | ||
transformResponse?: Array<(value: any) => any>; | ||
url?: string; | ||
validateStatus?: (status: number) => boolean; | ||
withCredentials?: boolean; | ||
@@ -165,9 +161,3 @@ signal?: AbortSignal; | ||
} | ||
export interface Response { | ||
data: ResponseData; | ||
status: number; | ||
headers: Headers; | ||
statusText: string; | ||
} | ||
export declare type ResponseData = string | Buffer | ArrayBuffer | Object | Array<any>; | ||
export type ResponseData = string | Buffer | ArrayBuffer | Object | Array<any>; | ||
export interface ResponseDataDetailed<T> { | ||
@@ -185,4 +175,4 @@ data: T; | ||
} | ||
export declare type UploadProgress = ProgressEvent; | ||
export declare type UploadProgressCallback = ProgressEventCallback; | ||
export type UploadProgress = ProgressEvent; | ||
export type UploadProgressCallback = ProgressEventCallback; | ||
export interface WebDAVClient { | ||
@@ -216,4 +206,2 @@ copyFile: (filename: string, destination: string) => Promise<void>; | ||
httpsAgent?: any; | ||
maxBodyLength?: number; | ||
maxContentLength?: number; | ||
password?: string; | ||
@@ -248,2 +236,1 @@ remotePath: string; | ||
} | ||
export {}; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ErrorCode = exports.AuthType = void 0; | ||
var AuthType; | ||
export var AuthType; | ||
(function (AuthType) { | ||
@@ -10,4 +7,4 @@ AuthType["Digest"] = "digest"; | ||
AuthType["Token"] = "token"; | ||
})(AuthType = exports.AuthType || (exports.AuthType = {})); | ||
var ErrorCode; | ||
})(AuthType || (AuthType = {})); | ||
export var ErrorCode; | ||
(function (ErrorCode) { | ||
@@ -18,2 +15,2 @@ ErrorCode["DataTypeNoLength"] = "data-type-no-length"; | ||
ErrorCode["LinkUnsupportedAuthType"] = "link-unsupported-auth"; | ||
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {})); | ||
})(ErrorCode || (ErrorCode = {})); |
{ | ||
"name": "webdav", | ||
"version": "4.11.2", | ||
"version": "5.0.0-r1", | ||
"description": "WebDAV client for NodeJS", | ||
"main": "dist/node/index.js", | ||
"exports": { | ||
".": { | ||
"browser": "./dist/web/index.js", | ||
"default": "./dist/node/index.js" | ||
}, | ||
"./web": "./dist/web/index.js" | ||
}, | ||
"type": "module", | ||
"types": "./dist/node/index.d.ts", | ||
"scripts": { | ||
"build": "npm run clean && run-p build:node build:web", | ||
"build:node": "tsc", | ||
"build:web": "webpack --mode production --config webpack.config.js && tsc --emitDeclarationOnly --outDir dist/web/", | ||
"build:web": "webpack --mode production --config webpack.config.cjs", | ||
"clean": "rimraf dist web", | ||
"dev": "nodemon -e ts,js --exec 'npm run build' --ignore 'dist/' --ignore 'web/'", | ||
"format": "prettier --write '{source,test}/**/*.{js,ts}'", | ||
"prepare:publish:web": "cp -r ./dist/web ./web && mv ./web/webdav.js ./web/index.js", | ||
"prepublishOnly": "run-s build prepare:publish:web", | ||
"prepublishOnly": "npm run build", | ||
"test": "run-s test:node test:web test:format", | ||
"test:format": "prettier-check '{source,test}/**/*.{js,ts}'", | ||
"test:node": "npm run build:node && nyc mocha -r test/index.node.js \"test/node/**/*.spec.js\"", | ||
"test:node": "nyc mocha \"test/node/**/*.spec.ts\"", | ||
"test:node:watch": "nodemon --exec 'npm run test:node' --ignore 'dist/'", | ||
"test:web": "concurrently --success 'first' --kill-others 'npm run test:web:karma' 'npm run test:web:server'", | ||
"test:web:karma": "karma start test/karma.conf.js", | ||
"test:web:server": "node test/server.web.js" | ||
"test:web:karma": "karma start test/karma.conf.cjs", | ||
"test:web:server": "ts-node-esm ./test/server.web.ts" | ||
}, | ||
"types": "dist/node/index.d.ts", | ||
"files": [ | ||
"dist/", | ||
"web/", | ||
"test/server/", | ||
@@ -41,3 +46,3 @@ "*.md" | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14" | ||
}, | ||
@@ -61,8 +66,8 @@ "lint-staged": { | ||
"dependencies": { | ||
"axios": "^0.27.2", | ||
"base-64": "^1.0.0", | ||
"byte-length": "^1.0.2", | ||
"cross-fetch": "^3.1.5", | ||
"fast-xml-parser": "^3.19.0", | ||
"he": "^1.2.0", | ||
"hot-patcher": "^1.0.0", | ||
"hot-patcher": "^2.0.0", | ||
"layerr": "^0.1.2", | ||
@@ -80,3 +85,7 @@ "md5": "^2.3.0", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@types/node": "^18.7.8", | ||
"@types/chai": "^4.3.4", | ||
"@types/he": "^1.1.2", | ||
"@types/mocha": "^10.0.0", | ||
"@types/node": "^18.11.9", | ||
"@types/sinon": "^10.0.13", | ||
"@types/url-parse": "^1.4.8", | ||
@@ -86,4 +95,3 @@ "babel-loader": "^8.2.5", | ||
"buffer-equals": "^2.0.0", | ||
"chai": "^4.3.6", | ||
"chai-as-promised": "^7.1.1", | ||
"chai": "^4.3.7", | ||
"concurrently": "^7.3.0", | ||
@@ -104,4 +112,5 @@ "copy-dir": "^1.3.0", | ||
"mkdirp": "^1.0.4", | ||
"mocha": "^9.2.2", | ||
"mocha": "^10.1.0", | ||
"nock": "^13.2.9", | ||
"node-fetch": "^3.3.0", | ||
"nodemon": "^2.0.19", | ||
@@ -112,10 +121,13 @@ "npm-run-all": "^4.1.5", | ||
"prettier-check": "^2.0.0", | ||
"resolve-typescript-plugin": "^2.0.0", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^13.0.2", | ||
"typescript": "^4.7.4", | ||
"sinon": "^14.0.2", | ||
"speed-measure-webpack-plugin": "^1.5.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.3", | ||
"wait-on": "^6.0.1", | ||
"webdav-server": "^2.6.2", | ||
"webpack": "^5.74.0", | ||
"webpack-cli": "^4.10.0" | ||
"webpack": "^5.75.0", | ||
"webpack-cli": "^5.0.0" | ||
} | ||
} |
@@ -9,3 +9,3 @@  | ||
WebDAV is a well-known, stable and highly flexible protocol for interacting with remote filesystems via an API. Being that it is so widespread, many file hosting services such as **Box**, **Nextcloud**/**ownCloud** and **Yandex** use it as a fallback to their primary interfaces. | ||
WebDAV is a well-known, stable and highly flexible protocol for interacting with remote filesystems via an API. Being that it is so widespread, many file hosting services such as **Nextcloud**/**ownCloud**, **Box** and **Yandex** use it as a fallback to their primary interfaces. | ||
@@ -16,24 +16,53 @@ This library provides a **WebDAV client** interface that makes interacting with WebDAV enabled services easy. The API returns promises and resolve with the results. It parses and prepares directory-contents requests for easy consumption, as well as providing methods for fetching things like file stats and quotas. | ||
### Node support | ||
### Supported Versions / Environments | ||
This library is compatible with **NodeJS version 10** and above (For version 6/8 support, use versions in the range of `2.*`. For version 4 support, use versions in the range of `1.*`). Versions 2.x and 1.x are no longer supported, so use them at your own risk. Version 3.x is deprecated and may receive the odd bugfix. | ||
Version 5 is under active development. Version 4 is in support mode, and will receive security and stability related bugfixes. Earlier versions are deprecated and will not receive updates. | ||
### Browser support | ||
Version 5 upgrades the library to use ESM (ECMAScript Modules), and so your environment must fit one of the following formats to be able to use this library: | ||
This WebDAV client is supported in the browser is of version 3. The compilation settings specify a minimum supported browser version of Internet Explorer 11, however testing in this browser is not performed regularly. | ||
* NodeJS project with `"type": "module"` in `package.json` (ESM mode) | ||
* Web project bundled with a tool like Webpack that can handle ESM | ||
If you're not ready to upgrade, you may consider using version 4 of this library. | ||
#### Requests | ||
This library uses [`cross-fetch`](https://github.com/lquixada/cross-fetch) to make requests in a cross-platform manner. It uses the browser's native `fetch` if present, or a polyfill if not. In Node and other environments it uses [`node-fetch`](https://github.com/node-fetch/node-fetch). | ||
Versions before v5 used Axios for requests. | ||
#### Node support | ||
Support table: | ||
| Library Major Version | Node JS Range | | ||
|-----------------------|-------------------| | ||
| v5 | 14+ | | ||
| v4 | 10-18 | | ||
| v3 | 10-16 | | ||
| v2 | 6-14 | | ||
| v1 | 4-12 | | ||
#### Browser support | ||
Browser environments are supported from version 3 onwards of this library. | ||
As mentioned above, v5 introduced ESM and this may require additional configuration when bundling for the browser. | ||
_Although you may choose to transpile this library's default entry point (NodeJS) yourself, it is not advised - use the dedicated web version instead._ | ||
You can use the web version via a different entry point: | ||
In version 4 you had to use a different entry-point for the web version, and while this is still possible to use in version 5, you no longer need to: | ||
```typescript | ||
import { createClient } from "webdav/web"; | ||
``` | ||
The browser version uses a UMD-style module definition, meaning you can simply load the library within your browser using a `<script>` tag. When using this method the library is made available on the window object as such: `window.WebDAV`. For example: | ||
// or | ||
```javascript | ||
const client = window.WebDAV.createClient(/* ... */); | ||
import { createClient } from "webdav"; | ||
// will both work fine in supported bundlers | ||
``` | ||
Versions 3/4 supported a UMD-style module in the browser, but this is no longer supported in version 5. Version 5 provides only an ESM-enabled bundle that can be imported into other ESM-supporting projects. | ||
**NB:** Streams are not available within the browser, so `createReadStream` and `createWriteStream` are just stubbed. Calling them will throw an exception. | ||
@@ -148,11 +177,10 @@ | ||
| `authType` | `null` | The authentication type to use. If not provided, defaults to trying to detect based upon whether `username` and `password` were provided. | | ||
| `contactHref` | _[This URL](https://github.com/perry-mitchell/webdav-client/blob/master/LOCK_CONTACT.md)_ | Contact URL used for LOCKs. | | ||
| `headers` | `{}` | Additional headers provided to all requests. Headers provided here are overridden by method-specific headers, including `Authorization`. | | ||
| `httpAgent` | _None_ | HTTP agent instance. Available only in Node. See [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent). | | ||
| `httpsAgent` | _None_ | HTTPS agent instance. Available only in Node. See [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent). | | ||
| `maxBodyLength` | _None_ | Maximum body length allowed for sending, in bytes. | | ||
| `maxContentLength` | _None_ | Maximum content length allowed for receiving, in bytes. | | ||
| `password` | _None_ | Password for authentication. | | ||
| `token` | _None_ | Token object for authentication. | | ||
| `username` | _None_ | Username for authentication. | | ||
| `withCredentials` | _None_ | Credentials inclusion setting for Axios. | | ||
| `withCredentials` | _None_ | Credentials inclusion setting for the request, | | ||
@@ -383,4 +411,2 @@ ### Client methods | ||
Specify the `maxContentLength` option to alter the maximum number of bytes the client can receive in the request (**NodeJS only**). | ||
```typescript | ||
@@ -399,19 +425,2 @@ (filename: string, options?: GetFileContentsOptions) => Promise<BufferLike | string | ResponseDataDetailed<BufferLike | string>> | ||
##### Download progress | ||
You can calculate the progress of the download by using `onDownloadProgress`: | ||
```typescript | ||
import { ProgressEvent } from "webdav"; | ||
await client.getFileContents("/package.zip", { | ||
onDownloadProgress: (progressEvent: ProgressEvent) => { | ||
// { | ||
// total: 12345600, | ||
// loaded: 54023 | ||
// } | ||
} | ||
}); | ||
``` | ||
#### getFileDownloadLink | ||
@@ -528,15 +537,3 @@ | ||
Specify the `maxBodyLength` option to alter the maximum number of bytes the client can send in the request (**NodeJS only**). When using `{ overwrite: false }`, responses with status `412` are caught and no error is thrown. | ||
Handling Upload Progress (browsers only): | ||
*This uses the axios onUploadProgress callback which uses the native XMLHttpRequest [progress event](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestEventTarget/onprogress).* | ||
```typescript | ||
// Upload a file and log the progress to the console: | ||
await client.putFileContents("/my/file.jpg", imageFile, { onUploadProgress: progress => { | ||
console.log(`Uploaded ${progress.loaded} bytes of ${progress.total}`); | ||
} }); | ||
``` | ||
```typescript | ||
(filename: string, data: string | BufferLike | Stream.Readable, options?: PutFileContentsOptions) => Promise<boolean> | ||
@@ -672,2 +669,7 @@ ``` | ||
[Buttercup Password Manager](https://github.com/buttercup), [Nextcloud Server](https://github.com/nextcloud/server), [Nextcloud Photos](https://github.com/nextcloud/photos), [ownCloud SDK](https://github.com/owncloud/owncloud-sdk), [React OxIDE](https://github.com/bootrino/reactoxide), [BackItUp](https://github.com/simatec/ioBroker.backitup) | ||
* [Buttercup Password Manager](https://github.com/buttercup) | ||
* [Nextcloud Server](https://github.com/nextcloud/server) | ||
* [Nextcloud Photos](https://github.com/nextcloud/photos) | ||
* [ownCloud SDK](https://github.com/owncloud/owncloud-sdk) | ||
* [React OxIDE](https://github.com/bootrino/reactoxide) | ||
* [BackItUp](https://github.com/simatec/ioBroker.backitup) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
669
Yes
216550
46
84
1649
1
4
+ Addedcross-fetch@^3.1.5
+ Addedcross-fetch@3.2.0(transitive)
+ Addedhot-patcher@2.0.1(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removedaxios@^0.27.2
- Removedasynckit@0.4.0(transitive)
- Removedaxios@0.27.2(transitive)
- Removedcall-bind-apply-helpers@1.0.2(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedes-set-tostringtag@2.1.0(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedform-data@4.0.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.3.0(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhot-patcher@1.0.0(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
Updatedhot-patcher@^2.0.0