nexusdocs-client

0.3.4 • Public • Published

nexusdocs-client

Client-SDK for nexusdocs-server

NexusDocs Documentation

Use

npm install nexusdocs-client

Modules

nexusdocs-client

Classes

Client

Class presenting NexusDocs client instance

Namespace

Class presenting NexusDocs namespace instance

nexusdocs-client

module.exports(options) ⇒ Client

Create a NexusDocs client instance

Kind: Exported function
See: new Client()

Param Type Description
options ServerOptions Server options, see ServerOptions

Example
Create a client

const createClient = require('nexusdocs-client');

// Object style server options:
const client = createClient({
  hostname: '192.168.1.6',
  port: 4001,
  apiKey: 'MY_API_KEY',
  apiSecret: 'MY_API_SECRET',
});

// URL style server options:
const client = createClient('http://MY_API_KEY:MY_API_SECRET@192.168.1.6:4001/api');

Client

Class presenting NexusDocs client instance

Kind: global class

new Client(options)

Creates an instance of NDS Client.

Param Type Description
options ServerOptions | string Server options, see ServerOptions

Example
You can pass a URL sting instead of a config object:

http://<clientKey>:<clientSecret>@<hostname>:<port><endPoint>

client.getNamespace(name, [options]) ⇒ Namespace

Get namespace instance

Kind: instance method of Client
Returns: Namespace - Namespace instance

Param Type Description
name string The name
[options] object Additional options

Client~ServerOptions : object

Server options

Kind: inner typedef of Client
Properties

Name Type Default Description
clientKey string NDS API key
clientSecret string NDS API secret
[hostname] string "127.0.0.1" hostname
[secure] boolean false Whether to use HTTPS
[port] number 4000 Server Port
[endPoint] string "/api" API endpoint
[defaultUrlExpires] number Default expires seconds
[defaultRequestExpires] number Default expires seconds

Namespace

Class presenting NexusDocs namespace instance

Kind: global class

new Namespace(client, name, options)

Namespace Class constructor

Param Type Description
client Client NDS Client instance
name string The name of namespace
options object

Example
Create a namespace instance

const namespace = client.getNamespace('a.name.space');

namespace.getUploadUrl([options]) ⇒ string

Get URL for upload

Kind: instance method of Namespace
Returns: string - URL for upload

Param Type Description
[options] RequestOptions Additional options, see RequestOptions
[options.resumable] boolean If upload with resumbable.js
[options.expires] date Timestamp the Request will available before

namespace.getDownloadUrl(fileId, [options]) ⇒ string

Get file URL for view or download

Kind: instance method of Namespace
Returns: string - file URL

Param Type Description
fileId FileId File identifier, see FileId
[options] DownloadOptions Additional options, see DownloadOptions

namespace.getConvertedUrl(fileId, converting, [options]) ⇒ string

Get the converted file URL for view or download

Kind: instance method of Namespace
Returns: string - The converted file URL

Param Type Description
fileId FileId File identifier, see FileId
converting ConvertingOptions Converting options, see ConvertingOptions
[options] DownloadOptions Additional options, see DownloadOptions

namespace.upload(Buffer|ReadableStream, [options]) ⇒ Promise

Upload file from Buffer, ReadableStream

Kind: instance method of Namespace
Fulfil: object File info when uploading is finished
Reject: any Request error

Param Type Description
Buffer ReadableStream data
[options] UploadOptions Additional options, see UploadOptions

namespace.openUploadStream([options]) ⇒ WritableStream

Get upload stream

Kind: instance method of Namespace
Returns: WritableStream - Writable stream for upload

Param Type Description
[options] UploadOptions Additional options, see UploadOptions
[options.stream] ReadableStream Provide readable stream directly

namespace.uploadFromLocal(filePath, options) ⇒ Promise

Upload a file from local file-system

Kind: instance method of Namespace
Fulfil: FileInfo File info when uploading is finished
Reject: any Request error

Param Type Description
filePath string The path of file will be uploaded
options UploadOptions Upload options

namespace.openDownloadStream(fileId, [options]) ⇒ ReadableStream

Get a readable stream for download

Kind: instance method of Namespace
Returns: ReadableStream - - the readable stream

Param Type Description
fileId FileId The file needed to download later, see FileId
[options] RequestOptions Additional options, see RequestOptions

namespace.downloadToLocal(fileId, filePath, [options]) ⇒ Promise

Download a file to local file-system

Kind: instance method of Namespace
Fulfil: any Download finished

Param Type Description
fileId FileId The file id, see FileId
filePath string The path of file will be saved
[options] RequestOptions Additional options, see RequestOptions

namespace.getFileInfo(fileId) ⇒ Promise

Get file information

Kind: instance method of Namespace
Fulfil: FileInfo file information

Param Type
fileId FileId

namespace.delete(fileId) ⇒ Promise

Delete a file on the server

Kind: instance method of Namespace
Fulfil: object When deletion is finished
Reject: any When a error occur

Param Type Description
fileId FileId The file to be deleted, see FileId

namespace.truncate() ⇒ Promise

Delete all files in this namespace

Kind: instance method of Namespace

namespace.createArchive(files) ⇒ Promise

Create an archive

Kind: instance method of Namespace

Param Type Description
files Array.<FileId> file id array

namespace.getArchiveUrl(files, options)

Archive files then return download URL

Kind: instance method of Namespace

Param Type Description
files Array.<FileId> file id array, see FileId
options RequestOptions RequestOptions, see RequestOptions

Namespace~RequestOptions : object

Request options for request, some properties are added for additional use, see specified method

Kind: inner typedef of Namespace
Properties

Name Type Description
method string HTTP method of the request
url string Path of the request, or full url
[body] string Entire body for PATCH, PUT, POST or DELETE, json must be true and only plain object is allowed
[json] boolean Set to true when providing body
[expires] number | date Expires time in second, timestamp or Date object, the request will be invalid after this timestamp
[signature] object Additional signature data besides method, url, expires

Namespace~UploadOptions : object

Upload request options

Kind: inner typedef of Namespace
Extends: RequestOptions
Properties

Name Type Description
[fileId] FileId Specify fileId, see FileId
[filename] string Provide filename
[md5] string MD5 hash of the file if available
[contentType] string Provide content-type for download
[knownLength] number Provide stream total length if available

Namespace~DownloadOptions : object

Download options

Kind: inner typedef of Namespace
Extends: RequestOptions
Properties

Name Type Default Description
[origin] boolean false Download from the origin provider
[download] boolean false Download with the original filename
[filename] string Download with new filename, this will set contentType & contentDisposition
[response] object Overwrite response header
[response.contentType] string Overwrite Content-Type
[response.contentDisposition] string Overwrite Content-Disposition

Namespace~FileId : string

File identifier

Kind: inner typedef of Namespace
Example

Example file id: `e5ac71cf-a0f0-46b5-9070-268ae97bb769`

Namespace~ImageInfo : object

Image file info

Kind: inner typedef of Namespace
Properties

Name Type Description
width number Image width
height number Image height
type number Image type, e.g. jpeg, png, gif
thumbnailUrl string Image thumbnail data-url

Namespace~ZipFileEntry : object

Zip file entry

Kind: inner typedef of Namespace
Properties

Name Type Description
path string Relative path to zip archive
size number Stored size
lastModified date Last modified date

Namespace~ZipInfo : object

Zip file info

Kind: inner typedef of Namespace
Properties

Name Type Description
entries Array.<ZipFileEntry> files

Namespace~FileInfo : object

File information

Kind: inner typedef of Namespace
Properties

Name Type Description
namespace string Namespace file is stored in
md5 string MD5 hash string
contentType string File content type
size number File total length
metadata object Additional information
[metadata.image] ImageInfo Metadata for image files
[metadata.zip] ZipInfo Zip file entries

Namespace~ConvertingOptions : object

File converting options

Kind: inner typedef of Namespace
Properties

Name Type Description
format string The output format, documents: pdf, image: gif, jpeg, png, webp, tiff
[resize] string For image, resize the image <width>x<height>{%}{@}{!}{<}{>} please check GraphicsMagick. notice: only {!}{>}{^} are available when the server is using ImageSharpConverter
[rotate] string | number For image, rotate the image by angle {auto}{90}{180}{270}, if auto is set, the angle will be detected by gravity from EXIF
[quality] number Forimage, set the output image quality 0 - 100, available for format jpeg, tiff, webp

Example
Get a thumbnail of size 32px

{
  format: 'jpeg',
  resize: '32x32',
  rotate: 'auto'
}

Example
Get a pdf version of a document

{
  format: 'pdf',
}

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i nexusdocs-client

Weekly Downloads

2

Version

0.3.4

License

MIT

Unpacked Size

135 kB

Total Files

32

Last publish

Collaborators

  • alphakevin