0.3.4 • Published 4 years ago

nexusdocs-client v0.3.4

Weekly downloads
119
License
MIT
Repository
github
Last release
4 years ago

nexusdocs-client

Client-SDK for nexusdocs-server

NexusDocs Documentation

Use

npm install nexusdocs-client

Modules

Classes

nexusdocs-client

module.exports(options) ⇒ Client

Create a NexusDocs client instance

Kind: Exported function
See: new Client()

ParamTypeDescription
optionsServerOptionsServer 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.

ParamTypeDescription
optionsServerOptions | stringServer 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

ParamTypeDescription
namestringThe name
optionsobjectAdditional options

Client~ServerOptions : object

Server options

Kind: inner typedef of Client
Properties

NameTypeDefaultDescription
clientKeystringNDS API key
clientSecretstringNDS API secret
hostnamestring"127.0.0.1"hostname
securebooleanfalseWhether to use HTTPS
portnumber4000Server Port
endPointstring"/api"API endpoint
defaultUrlExpiresnumberDefault expires seconds
defaultRequestExpiresnumberDefault expires seconds

Namespace

Class presenting NexusDocs namespace instance

Kind: global class

new Namespace(client, name, options)

Namespace Class constructor

ParamTypeDescription
clientClientNDS Client instance
namestringThe name of namespace
optionsobject

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

ParamTypeDescription
optionsRequestOptionsAdditional options, see RequestOptions
options.resumablebooleanIf upload with resumbable.js
options.expiresdateTimestamp 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

ParamTypeDescription
fileIdFileIdFile identifier, see FileId
optionsDownloadOptionsAdditional 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

ParamTypeDescription
fileIdFileIdFile identifier, see FileId
convertingConvertingOptionsConverting options, see ConvertingOptions
optionsDownloadOptionsAdditional 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

ParamTypeDescription
BufferReadableStreamdataFile data
optionsUploadOptionsAdditional options, see UploadOptions

namespace.openUploadStream(options) ⇒ WritableStream

Get upload stream

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

ParamTypeDescription
optionsUploadOptionsAdditional options, see UploadOptions
options.streamReadableStreamProvide 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

ParamTypeDescription
filePathstringThe path of file will be uploaded
optionsUploadOptionsUpload options

namespace.openDownloadStream(fileId, options) ⇒ ReadableStream

Get a readable stream for download

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

ParamTypeDescription
fileIdFileIdThe file needed to download later, see FileId
optionsRequestOptionsAdditional 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

ParamTypeDescription
fileIdFileIdThe file id, see FileId
filePathstringThe path of file will be saved
optionsRequestOptionsAdditional options, see RequestOptions

namespace.getFileInfo(fileId) ⇒ Promise

Get file information

Kind: instance method of Namespace
Fulfil: FileInfo file information

ParamType
fileIdFileId

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

ParamTypeDescription
fileIdFileIdThe 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

ParamTypeDescription
filesArray.<FileId>file id array

namespace.getArchiveUrl(files, options)

Archive files then return download URL

Kind: instance method of Namespace

ParamTypeDescription
filesArray.<FileId>file id array, see FileId
optionsRequestOptionsRequestOptions, 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

NameTypeDescription
methodstringHTTP method of the request
urlstringPath of the request, or full url
bodystringEntire body for PATCH, PUT, POST or DELETE, json must be true and only plain object is allowed
jsonbooleanSet to true when providing body
expiresnumber | dateExpires time in second, timestamp or Date object, the request will be invalid after this timestamp
signatureobjectAdditional signature data besides method, url, expires

Namespace~UploadOptions : object

Upload request options

Kind: inner typedef of Namespace
Extends: RequestOptions
Properties

NameTypeDescription
fileIdFileIdSpecify fileId, see FileId
filenamestringProvide filename
md5stringMD5 hash of the file if available
contentTypestringProvide content-type for download
knownLengthnumberProvide stream total length if available

Namespace~DownloadOptions : object

Download options

Kind: inner typedef of Namespace
Extends: RequestOptions
Properties

NameTypeDefaultDescription
originbooleanfalseDownload from the origin provider
downloadbooleanfalseDownload with the original filename
filenamestringDownload with new filename, this will set contentType & contentDisposition
responseobjectOverwrite response header
response.contentTypestringOverwrite Content-Type
response.contentDispositionstringOverwrite 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

NameTypeDescription
widthnumberImage width
heightnumberImage height
typenumberImage type, e.g. jpeg, png, gif
thumbnailUrlstringImage thumbnail data-url

Namespace~ZipFileEntry : object

Zip file entry

Kind: inner typedef of Namespace
Properties

NameTypeDescription
pathstringRelative path to zip archive
sizenumberStored size
lastModifieddateLast modified date

Namespace~ZipInfo : object

Zip file info

Kind: inner typedef of Namespace
Properties

NameTypeDescription
entriesArray.<ZipFileEntry>files

Namespace~FileInfo : object

File information

Kind: inner typedef of Namespace
Properties

NameTypeDescription
namespacestringNamespace file is stored in
md5stringMD5 hash string
contentTypestringFile content type
sizenumberFile total length
metadataobjectAdditional information
metadata.imageImageInfoMetadata for image files
metadata.zipZipInfoZip file entries

Namespace~ConvertingOptions : object

File converting options

Kind: inner typedef of Namespace
Properties

NameTypeDescription
formatstringThe output format, documents: pdf, image: gif, jpeg, png, webp, tiff
resizestringFor image, resize the image <width>x<height>{%}{@}{!}{<}{>} please check GraphicsMagick. notice: only {!}{>}{^} are available when the server is using ImageSharpConverter
rotatestring | numberFor image, rotate the image by angle {auto}{90}{180}{270}, if auto is set, the angle will be detected by gravity from EXIF
qualitynumberForimage, 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

0.3.4

4 years ago

0.3.3

4 years ago

0.5.0-alpha.3

5 years ago

0.5.0-alpha.1

5 years ago

0.5.0-alpha.0

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago