paw-client

2.2.9 • Public • Published

paw-client 🔑

paw-client is a javascript client for Plugandwork api that comes with tools to build an app based on Plugandwork services.


  • Getting started
    • Minimal configuration for the client
  • Docs
    • create doc
    • upload a file in doc
    • read docs
    • update docs
    • delete docs
  • Spaces
  • Other tools
    • verify if a file is already uploaded

1 - Getting started

npm install --save paw-client

import PawClient from 'paw-client';
 
// create and configure a new client instance
const client = new PawClient(configuration);

Minimal configuration for the client

The Paw Client requires a minimal configuration. You need to provide the plugandwork server url to call and credentials to authorize all requests.
You can generate a new token in your plugandwork settings.

const client = new PawClient({
  host: 'https://host.plugandwork.fr',
  credentials: {
    token: '',
    uuid: ''
  }
});

2 - Docs

paw-client allows you to manage docs

import { Doc } from 'paw-client';
 
// create a new Doc instance
const doc = new Doc({
  title: 'Doc#1',
  tags: ['doing', 'work']
});

see Doc class

create doc

const _doc = new Doc(configuration);
const doc = await client.createDoc(doc);
console.log(doc.id); // will print the doc id provided by the api

You can also directly provide configuration to the createDoc method, a Doc instance will be returned

const doc = await client.createDoc(configuration);
console.log(doc instanceof Doc); // true

upload a file in doc

const file = fs.createReadStream(filePath);
const formData = new FormData();
formData.append('file', file, { filepath });
await client.uploadFile(formData, { docId: doc.id, headers: formData.getHeaders(), maxContentLength });

read docs

const docs = await client.getDocs({ title: 'test' });
console.log(docs.length); // will print how many docs with title 'test' did found by the api

You can get just one doc by adding limit: 1, exact: true to the query object.

update docs

const docs = await client.updateDocs(docs, { title: 'test', key: 'newValue' });

By default, client will replace doc values. You can add patch: true to the values object to update values instead of replace.

delete docs

const docs = await client.deleteDocs(docs);

3 - Spaces

Documentation to come

4 - Other tools

verify if a file is already uploaded

try {
  const md5 = 'myFileMd5';
  await client.validateMd5(md5);
} catch (e) {
  throw new Error('This file is already uploaded');
}

Readme

Keywords

none

Package Sidebar

Install

npm i paw-client

Weekly Downloads

0

Version

2.2.9

License

ISC

Unpacked Size

479 kB

Total Files

17

Last publish

Collaborators

  • pierrecabriere