UNPKG

22.3 kBMarkdownView Raw
1## Modules
2
3<dl>
4<dt><a href="#module_WebDAV">WebDAV</a></dt>
5<dd></dd>
6</dl>
7
8## Functions
9
10<dl>
11<dt><a href="#getPatcher">getPatcher()</a><code>HotPatcher</code></dt>
12<dd><p>Get the HotPatcher instance for patching internal methods</p>
13</dd>
14<dt><a href="#encodePath">encodePath(path)</a><code>String</code></dt>
15<dd><p>Encode a path for use with WebDAV servers</p>
16</dd>
17<dt><a href="#joinURL">joinURL(...parts)</a><code>String</code></dt>
18<dd><p>Join URL segments</p>
19</dd>
20<dt><a href="#prepareRequestOptions">prepareRequestOptions(requestOptions, methodOptions)</a></dt>
21<dd><p>Process request options before being passed to Axios</p>
22</dd>
23<dt><a href="#request">request(requestOptions)</a><code>Promise.&lt;Object&gt;</code></dt>
24<dd><p>Make a request
25This method can be patched by patching or plugging-in to the &quot;request&quot;
26item using <a href="https://github.com/perry-mitchell/hot-patcher">HotPatcher</a>.
27It uses <a href="https://github.com/axios/axios">Axios</a> by default.</p>
28</dd>
29</dl>
30
31## Typedefs
32
33<dl>
34<dt><a href="#ClientInterface">ClientInterface</a> : <code>Object</code></dt>
35<dd><p>Client adapter</p>
36</dd>
37<dt><a href="#PutOptions">PutOptions</a> : <code><a href="#UserOptions">UserOptions</a></code></dt>
38<dd><p>Options for creating a resource</p>
39</dd>
40<dt><a href="#OptionsWithFormat">OptionsWithFormat</a> : <code><a href="#UserOptions">UserOptions</a></code></dt>
41<dd><p>Options with headers and format</p>
42</dd>
43<dt><a href="#OptionsForAdvancedResponses">OptionsForAdvancedResponses</a> : <code><a href="#UserOptions">UserOptions</a></code></dt>
44<dd><p>Options for methods that resturn responses</p>
45</dd>
46<dt><a href="#GetDirectoryContentsOptions">GetDirectoryContentsOptions</a> : <code><a href="#OptionsForAdvancedResponses">OptionsForAdvancedResponses</a></code></dt>
47<dd></dd>
48<dt><a href="#AuthToken">AuthToken</a> : <code>Object</code></dt>
49<dd></dd>
50<dt><a href="#CreateClientOptions">CreateClientOptions</a> : <code>Object</code></dt>
51<dd></dd>
52<dt><a href="#Stat">Stat</a> : <code>Object</code></dt>
53<dd><p>A stat result</p>
54</dd>
55<dt><a href="#UserOptions">UserOptions</a> : <code>Object</code></dt>
56<dd></dd>
57<dt><a href="#RequestOptions">RequestOptions</a> : <code>Object</code></dt>
58<dd></dd>
59</dl>
60
61<a name="module_WebDAV"></a>
62
63## WebDAV
64
65* [WebDAV](#module_WebDAV)
66 * [.axios](#module_WebDAV.axios) : <code>function</code>
67 * [.createClient(remoteURL, [opts])](#module_WebDAV.createClient) ⇒ [<code>ClientInterface</code>](#ClientInterface)
68
69<a name="module_WebDAV.axios"></a>
70
71### WebDAV.axios : <code>function</code>
72Axios request library
73
74**Kind**: static property of [<code>WebDAV</code>](#module_WebDAV)
75<a name="module_WebDAV.createClient"></a>
76
77### WebDAV.createClient(remoteURL, [opts]) ⇒ [<code>ClientInterface</code>](#ClientInterface)
78Create a client adapter
79
80**Kind**: static method of [<code>WebDAV</code>](#module_WebDAV)
81**Returns**: [<code>ClientInterface</code>](#ClientInterface) - A new client interface instance
82
83| Param | Type | Description |
84| --- | --- | --- |
85| remoteURL | <code>String</code> | The remote address of the webdav server |
86| [opts] | [<code>CreateClientOptions</code>](#CreateClientOptions) | Client options |
87
88**Example**
89```js
90const createClient = require("webdav");
91 const client = createClient(url, { username, password });
92 client
93 .getDirectoryContents("/")
94 .then(contents => {
95 console.log(contents);
96 });
97```
98**Example**
99```js
100const createClient = require("webdav");
101 const client = createClient(url, {
102 token: { token_type: "Bearer", access_token: "tokenvalue" }
103 });
104 client
105 .getDirectoryContents("/")
106 .then(contents => {
107 console.log(contents);
108 });
109```
110<a name="getPatcher"></a>
111
112## getPatcher() ⇒ <code>HotPatcher</code>
113Get the HotPatcher instance for patching internal methods
114
115**Kind**: global function
116**Returns**: <code>HotPatcher</code> - The internal HotPatcher instance
117<a name="encodePath"></a>
118
119## encodePath(path) ⇒ <code>String</code>
120Encode a path for use with WebDAV servers
121
122**Kind**: global function
123**Returns**: <code>String</code> - The encoded path (separators protected)
124
125| Param | Type | Description |
126| --- | --- | --- |
127| path | <code>String</code> | The path to encode |
128
129<a name="joinURL"></a>
130
131## joinURL(...parts) ⇒ <code>String</code>
132Join URL segments
133
134**Kind**: global function
135**Returns**: <code>String</code> - A joined URL string
136
137| Param | Type | Description |
138| --- | --- | --- |
139| ...parts | <code>String</code> | URL segments to join |
140
141<a name="prepareRequestOptions"></a>
142
143## prepareRequestOptions(requestOptions, methodOptions)
144Process request options before being passed to Axios
145
146**Kind**: global function
147
148| Param | Type | Description |
149| --- | --- | --- |
150| requestOptions | [<code>RequestOptions</code>](#RequestOptions) | The request options object |
151| methodOptions | [<code>UserOptions</code>](#UserOptions) | Provided options (external) |
152
153<a name="request"></a>
154
155## request(requestOptions) ⇒ <code>Promise.&lt;Object&gt;</code>
156Make a request
157This method can be patched by patching or plugging-in to the "request"
158item using [HotPatcher](https://github.com/perry-mitchell/hot-patcher).
159It uses [Axios](https://github.com/axios/axios) by default.
160
161**Kind**: global function
162**Returns**: <code>Promise.&lt;Object&gt;</code> - A promise that resolves with a response object
163
164| Param | Type | Description |
165| --- | --- | --- |
166| requestOptions | [<code>RequestOptions</code>](#RequestOptions) | Options for the request |
167
168<a name="ClientInterface"></a>
169
170## ClientInterface : <code>Object</code>
171Client adapter
172
173**Kind**: global typedef
174
175* [ClientInterface](#ClientInterface) : <code>Object</code>
176 * [.copyFile(remotePath, targetRemotePath, [options])](#ClientInterface.copyFile) ⇒ <code>Promise</code>
177 * [.createDirectory(dirPath, [options])](#ClientInterface.createDirectory) ⇒ <code>Promise</code>
178 * [.createReadStream(remoteFilename, [options])](#ClientInterface.createReadStream) ⇒ <code>Readable</code>
179 * [.createWriteStream(remoteFilename, [options], [callback])](#ClientInterface.createWriteStream) ⇒ <code>Writeable</code>
180 * [.customRequest(remotePath, [requestOptions], [options])](#ClientInterface.customRequest) ⇒ <code>Promise.&lt;Any&gt;</code>
181 * [.deleteFile(remotePath, [options])](#ClientInterface.deleteFile) ⇒ <code>Promise</code>
182 * [.exists(remotePath, [options])](#ClientInterface.exists) ⇒ <code>Promise.&lt;Boolean&gt;</code>
183 * [.getDirectoryContents(remotePath, [options])](#ClientInterface.getDirectoryContents) ⇒ <code>Promise.&lt;Array.&lt;Stat&gt;&gt;</code>
184 * [.getFileContents(remoteFilename, [options])](#ClientInterface.getFileContents) ⇒ <code>Promise.&lt;(Buffer\|String)&gt;</code>
185 * [.getFileDownloadLink(remoteFilename, [options])](#ClientInterface.getFileDownloadLink) ⇒ <code>String</code>
186 * [.getFileUploadLink(remoteFilename, [options])](#ClientInterface.getFileUploadLink) ⇒ <code>String</code>
187 * [.getQuota([options])](#ClientInterface.getQuota) ⇒ <code>Promise.&lt;(null\|Object)&gt;</code>
188 * [.moveFile(remotePath, targetRemotePath, [options])](#ClientInterface.moveFile) ⇒ <code>Promise</code>
189 * [.putFileContents(remoteFilename, data, [options])](#ClientInterface.putFileContents) ⇒ <code>Promise</code>
190 * [.stat(remotePath, [options])](#ClientInterface.stat) ⇒ [<code>Promise.&lt;Stat&gt;</code>](#Stat)
191
192<a name="ClientInterface.copyFile"></a>
193
194### ClientInterface.copyFile(remotePath, targetRemotePath, [options]) ⇒ <code>Promise</code>
195Copy a remote item to another path
196
197**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
198**Returns**: <code>Promise</code> - A promise that resolves once the request has completed
199
200| Param | Type | Description |
201| --- | --- | --- |
202| remotePath | <code>String</code> | The remote item path |
203| targetRemotePath | <code>String</code> | The path file will be copied to |
204| [options] | [<code>UserOptions</code>](#UserOptions) | Options for the request |
205
206**Example**
207```js
208await client.copyFile("/photos/pic1.jpg", "/backup/pic1.jpg");
209```
210<a name="ClientInterface.createDirectory"></a>
211
212### ClientInterface.createDirectory(dirPath, [options]) ⇒ <code>Promise</code>
213Create a directory
214
215**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
216**Returns**: <code>Promise</code> - A promise that resolves when the remote path has been created
217
218| Param | Type | Description |
219| --- | --- | --- |
220| dirPath | <code>String</code> | The path to create |
221| [options] | [<code>UserOptions</code>](#UserOptions) | Options for the request |
222
223**Example**
224```js
225await client.createDirectory("/my/directory");
226```
227<a name="ClientInterface.createReadStream"></a>
228
229### ClientInterface.createReadStream(remoteFilename, [options]) ⇒ <code>Readable</code>
230Create a readable stream of a remote file
231
232**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
233**Returns**: <code>Readable</code> - A readable stream
234
235| Param | Type | Description |
236| --- | --- | --- |
237| remoteFilename | <code>String</code> | The file to stream |
238| [options] | [<code>UserOptions</code>](#UserOptions) | Options for the request |
239
240**Example**
241```js
242const remote = client.createReadStream("/data.zip");
243 remote.pipe(someWriteStream);
244```
245<a name="ClientInterface.createWriteStream"></a>
246
247### ClientInterface.createWriteStream(remoteFilename, [options], [callback]) ⇒ <code>Writeable</code>
248Create a writeable stream to a remote file
249
250**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
251**Returns**: <code>Writeable</code> - A writeable stream
252
253| Param | Type | Description |
254| --- | --- | --- |
255| remoteFilename | <code>String</code> | The file to write to |
256| [options] | [<code>PutOptions</code>](#PutOptions) | Options for the request |
257| [callback] | <code>function</code> | Optional callback to fire once the request has finished |
258
259**Example**
260```js
261const remote = client.createWriteStream("/data.zip");
262 fs.createReadStream("~/myData.zip").pipe(remote);
263```
264<a name="ClientInterface.customRequest"></a>
265
266### ClientInterface.customRequest(remotePath, [requestOptions], [options]) ⇒ <code>Promise.&lt;Any&gt;</code>
267Send a custom request
268
269**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
270**Returns**: <code>Promise.&lt;Any&gt;</code> - A promise that resolves with response of the request
271
272| Param | Type | Description |
273| --- | --- | --- |
274| remotePath | <code>String</code> | The remote path |
275| [requestOptions] | [<code>RequestOptions</code>](#RequestOptions) | the request options |
276| [options] | <code>Options</code> | Options for the request |
277
278**Example**
279```js
280const contents = await client.customRequest("/alrighty.jpg", {
281 method: "PROPFIND",
282 headers: {
283 Accept: "text/plain",
284 Depth: 0
285 },
286 responseType: "text"
287 });
288```
289<a name="ClientInterface.deleteFile"></a>
290
291### ClientInterface.deleteFile(remotePath, [options]) ⇒ <code>Promise</code>
292Delete a remote file
293
294**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
295**Returns**: <code>Promise</code> - A promise that resolves when the remote file as been deleted
296
297| Param | Type | Description |
298| --- | --- | --- |
299| remotePath | <code>String</code> | The remote path to delete |
300| [options] | [<code>UserOptions</code>](#UserOptions) | The options for the request |
301
302**Example**
303```js
304await client.deleteFile("/some/file.txt");
305```
306<a name="ClientInterface.exists"></a>
307
308### ClientInterface.exists(remotePath, [options]) ⇒ <code>Promise.&lt;Boolean&gt;</code>
309Check if a remote file or directory exists
310
311**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
312**Returns**: <code>Promise.&lt;Boolean&gt;</code> - A promise that resolves with true if the path exists
313 or false if it does not
314
315| Param | Type | Description |
316| --- | --- | --- |
317| remotePath | <code>String</code> | The remote path to check |
318| [options] | [<code>UserOptions</code>](#UserOptions) | The options for the request |
319
320**Example**
321```js
322if (await client.exists("/some-path/file.txt")) {
323 // Do something
324 }
325```
326<a name="ClientInterface.getDirectoryContents"></a>
327
328### ClientInterface.getDirectoryContents(remotePath, [options]) ⇒ <code>Promise.&lt;Array.&lt;Stat&gt;&gt;</code>
329Get the contents of a remote directory
330
331**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
332**Returns**: <code>Promise.&lt;Array.&lt;Stat&gt;&gt;</code> - A promise that resolves with an array of remote item stats
333
334| Param | Type | Description |
335| --- | --- | --- |
336| remotePath | <code>String</code> | The path to fetch the contents of |
337| [options] | [<code>GetDirectoryContentsOptions</code>](#GetDirectoryContentsOptions) | Options for the remote the request |
338
339**Example**
340```js
341const contents = await client.getDirectoryContents("/");
342```
343<a name="ClientInterface.getFileContents"></a>
344
345### ClientInterface.getFileContents(remoteFilename, [options]) ⇒ <code>Promise.&lt;(Buffer\|String)&gt;</code>
346Get the contents of a remote file
347
348**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
349**Returns**: <code>Promise.&lt;(Buffer\|String)&gt;</code> - A promise that resolves with the contents of the remote file
350
351| Param | Type | Description |
352| --- | --- | --- |
353| remoteFilename | <code>String</code> | The file to fetch |
354| [options] | [<code>OptionsWithFormat</code>](#OptionsWithFormat) | Options for the request |
355
356**Example**
357```js
358// Fetching data:
359 const buff = await client.getFileContents("/image.png");
360 // Fetching text:
361 const txt = await client.getFileContents("/list.txt", { format: "text" });
362```
363<a name="ClientInterface.getFileDownloadLink"></a>
364
365### ClientInterface.getFileDownloadLink(remoteFilename, [options]) ⇒ <code>String</code>
366Get the download link of a remote file
367Only supported for Basic authentication or unauthenticated connections.
368
369**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
370**Returns**: <code>String</code> - A download URL
371
372| Param | Type | Description |
373| --- | --- | --- |
374| remoteFilename | <code>String</code> | The file url to fetch |
375| [options] | [<code>UserOptions</code>](#UserOptions) | Options for the request |
376
377<a name="ClientInterface.getFileUploadLink"></a>
378
379### ClientInterface.getFileUploadLink(remoteFilename, [options]) ⇒ <code>String</code>
380Get a file upload link
381Only supported for Basic authentication or unauthenticated connections.
382
383**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
384**Returns**: <code>String</code> - A upload URL
385
386| Param | Type | Description |
387| --- | --- | --- |
388| remoteFilename | <code>String</code> | The path of the remote file location |
389| [options] | [<code>PutOptions</code>](#PutOptions) | The options for the request |
390
391<a name="ClientInterface.getQuota"></a>
392
393### ClientInterface.getQuota([options]) ⇒ <code>Promise.&lt;(null\|Object)&gt;</code>
394Get quota information
395
396**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
397**Returns**: <code>Promise.&lt;(null\|Object)&gt;</code> - Returns null if failed, or an object with `used` and `available`
398
399| Param | Type | Description |
400| --- | --- | --- |
401| [options] | [<code>OptionsForAdvancedResponses</code>](#OptionsForAdvancedResponses) | Options for the request |
402
403<a name="ClientInterface.moveFile"></a>
404
405### ClientInterface.moveFile(remotePath, targetRemotePath, [options]) ⇒ <code>Promise</code>
406Move a remote item to another path
407
408**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
409**Returns**: <code>Promise</code> - A promise that resolves once the request has completed
410
411| Param | Type | Description |
412| --- | --- | --- |
413| remotePath | <code>String</code> | The remote item path |
414| targetRemotePath | <code>String</code> | The new path after moving |
415| [options] | [<code>UserOptions</code>](#UserOptions) | Options for the request |
416
417**Example**
418```js
419await client.moveFile("/sub/file.dat", "/another/dir/file.dat");
420```
421<a name="ClientInterface.putFileContents"></a>
422
423### ClientInterface.putFileContents(remoteFilename, data, [options]) ⇒ <code>Promise</code>
424Write contents to a remote file path
425
426**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
427**Returns**: <code>Promise</code> - A promise that resolves once the contents have been written
428
429| Param | Type | Description |
430| --- | --- | --- |
431| remoteFilename | <code>String</code> | The path of the remote file |
432| data | <code>String</code> \| <code>Buffer</code> | The data to write |
433| [options] | [<code>PutOptions</code>](#PutOptions) | The options for the request |
434
435**Example**
436```js
437await client.putFileContents("/dir/image.png", myImageBuffer);
438 // Put contents without overwriting:
439 await client.putFileContents("/dir/image.png", myImageBuffer, { overwrite: false });
440```
441<a name="ClientInterface.stat"></a>
442
443### ClientInterface.stat(remotePath, [options]) ⇒ [<code>Promise.&lt;Stat&gt;</code>](#Stat)
444Stat a remote object
445
446**Kind**: static method of [<code>ClientInterface</code>](#ClientInterface)
447**Returns**: [<code>Promise.&lt;Stat&gt;</code>](#Stat) - A promise that resolves with the stat data
448
449| Param | Type | Description |
450| --- | --- | --- |
451| remotePath | <code>String</code> | The path of the item |
452| [options] | [<code>OptionsForAdvancedResponses</code>](#OptionsForAdvancedResponses) | Options for the request |
453
454<a name="PutOptions"></a>
455
456## PutOptions : [<code>UserOptions</code>](#UserOptions)
457Options for creating a resource
458
459**Kind**: global typedef
460**Properties**
461
462| Name | Type | Description |
463| --- | --- | --- |
464| [overwrite] | <code>Boolean</code> | Whether or not to overwrite existing files (default: true) |
465
466<a name="OptionsWithFormat"></a>
467
468## OptionsWithFormat : [<code>UserOptions</code>](#UserOptions)
469Options with headers and format
470
471**Kind**: global typedef
472**Properties**
473
474| Name | Type | Description |
475| --- | --- | --- |
476| format | <code>String</code> | The format to use (text/binary) |
477| [details] | <code>Boolean</code> | Provided detailed response information, such as response headers (defaults to false). Only available on requests that return result data. |
478
479<a name="OptionsForAdvancedResponses"></a>
480
481## OptionsForAdvancedResponses : [<code>UserOptions</code>](#UserOptions)
482Options for methods that resturn responses
483
484**Kind**: global typedef
485**Properties**
486
487| Name | Type | Description |
488| --- | --- | --- |
489| [details] | <code>Boolean</code> | Provided detailed response information, such as response headers (defaults to false). Only available on requests that return result data. |
490
491<a name="GetDirectoryContentsOptions"></a>
492
493## GetDirectoryContentsOptions : [<code>OptionsForAdvancedResponses</code>](#OptionsForAdvancedResponses)
494**Kind**: global typedef
495**Properties**
496
497| Name | Type | Description |
498| --- | --- | --- |
499| [deep] | <code>Boolean</code> | Return deep (infinite) items (default: false) |
500| [glob] | <code>String</code> | Glob pattern for matching certain files |
501
502<a name="AuthToken"></a>
503
504## AuthToken : <code>Object</code>
505**Kind**: global typedef
506**Properties**
507
508| Name | Type | Description |
509| --- | --- | --- |
510| token_type | <code>String</code> | The type of token (eg "Bearer") |
511| access_token | <code>String</code> | The token access code |
512
513<a name="CreateClientOptions"></a>
514
515## CreateClientOptions : <code>Object</code>
516**Kind**: global typedef
517**Properties**
518
519| Name | Type | Description |
520| --- | --- | --- |
521| [username] | <code>String</code> | The username for authentication |
522| [password] | <code>String</code> | The password for authentication |
523| [httpAgent] | <code>http.Agent</code> | Override the HTTP Agent instance for requests |
524| [httpsAgent] | <code>https.Agent</code> | Override the HTTPS Agent instance for requests |
525| [token] | [<code>AuthToken</code>](#AuthToken) | Optional OAuth token |
526
527<a name="Stat"></a>
528
529## Stat : <code>Object</code>
530A stat result
531
532**Kind**: global typedef
533**Properties**
534
535| Name | Type | Description |
536| --- | --- | --- |
537| filename | <code>String</code> | The full path and filename of the remote item |
538| basename | <code>String</code> | The base filename of the remote item, without the path |
539| lastmod | <code>String</code> \| <code>null</code> | The last modification date (eg. "Sun, 13 Mar 2016 04:23:32 GMT") |
540| size | <code>Number</code> | The size of the remote item |
541| type | <code>String</code> | The type of the item (file/directory) |
542| [mime] | <code>String</code> | The file mimetype (not present on directories) |
543| etag | <code>String</code> \| <code>null</code> | The ETag of the remote item (as supported by the server) |
544| [props] | <code>Object</code> | Additionally returned properties from the server, unprocessed, if `details: true` is specified in the options |
545
546<a name="UserOptions"></a>
547
548## UserOptions : <code>Object</code>
549**Kind**: global typedef
550**Properties**
551
552| Name | Type | Description |
553| --- | --- | --- |
554| [httpAgent] | <code>Object</code> | HTTP agent instance |
555| [httpsAgent] | <code>Object</code> | HTTPS agent instance |
556| [headers] | <code>Object</code> | Set additional request headers |
557| [withCredentials] | <code>Boolean</code> | Set whether or not credentials should |
558| data | <code>Object</code> \| <code>String</code> \| <code>\*</code> | Set additional body be included with the request. Defaults to value used by axios. |
559
560<a name="RequestOptions"></a>
561
562## RequestOptions : <code>Object</code>
563**Kind**: global typedef
564**Properties**
565
566| Name | Type | Description |
567| --- | --- | --- |
568| url | <code>String</code> | The URL to request |
569| method | <code>String</code> | The method to use (eg. "POST") |
570| [headers] | <code>Object</code> | Headers to set on the request |
571| [httpAgent] | <code>Object</code> | A HTTP agent instance |
572| [httpsAgent] | <code>Object</code> | A HTTPS agent interface |
573| data | <code>Object</code> \| <code>String</code> \| <code>\*</code> | Body data for the request |
574