2.1.2 • Published 2 years ago

@workflowd1/workflow-sdk v2.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Workflow SDK for JavaScript

NPM version NPM downloads

Contents

How to install

The Workflow SDK is compatible with Node.js 14+, as is written in TypeScript. The way to install Workflow SDK for Node.js is to use npm package manager:

npm i @workflowd1/workflow-sdk

You can also use yarn, by simply type:

yarn add @workflowd1/workflow-sdk

Workflow

To use Workflow features, you should know some basic information, as which Tenant URL you are consuming. With that in mind, now you need to have some credentials to call the available operations, and the credential that is active will be the one related on logs.

Credentials

This class main responsibility is store one credential, that is basically one email, one password and the Tenant URL.

const { Credentials } = require('@workflows/workflow-sdk')

const userCredential = new Credentials({email: 'email@email.com', password: 'strongPassword', baseURL: 'tenant.url.com'})

You can also create multiple credentials only by instancing a new class

const { Credentials } = require('@workflows/workflow-sdk')

const userOneCredential = new Credentials({ email: 'email1@email.com', password: 'strongPassword', baseURL: 'tenant.url.com' })

const userTwoCredential = new Credentials({ email: 'email2@email.com', password: 'strongPassword', baseURL: 'tenant.url.com' })

It is important to know that the baseURL needs to be the one you are operating on. If you pass any other tenant URL, all the calls will be made on that, and it may cause you some problems.

Also credentials will be consumed by Workflow classes as an object and it has the following structure.

{
  'default': new Credentials({ email, password, baseURL }), // ('default' key is mandatory, and will applied if no other specified)
  'custom': new Credentials({ email, password, baseURL })
}

Credentials can also be instanced with Redis, it can be configured at the second parameter on constructor, it is basically connection options and a key that will store the authentication token, as the example bellow:

const userOneCredential = new Credentials(auth, { redis: { host: '', port: '', key: '' }})

Entities

All Workflow entities are available on the same class, as properties. This properties are references to classes that execute entity operations, as create or update. It is essential that Credentials are configured.

It should be instanced as below:

const { Workflow } = require('@workflows/workflow-sdk')

const workflowHandler = new Workflow({ default: defaultCredential, [key]: new Credential(auth) })

All the credentials that were passed on class constructor will be available as credential key on subsequent calls for any entity. The methods available are basically an easy axios call, all the parameters are described on API references.

The methods follow a pattern on parameters that is:

// Credential key is optional and references to Workflow constructor.
async function(data: RequestBody, credentialsKey?: string) {
  //If no credential key is provided, default key will be set.
  this.currentCredentials = this.credentialsObject[credentialKey]
}

Document

const newDocument = await workflowHandler.document.create(createParams: object)
const updatedDocument = await workflowHandler.document.update(updateParams: object)
const loadDocument = await workflowHandler.document.load(loadParams: object)
const loadDocument = await workflowHandler.document.loadById(idParam: object)

Attachment

const newAttachment = await workflowHandler.attachment.uploadFile(createParams: object)
const updatedAttachment = await workflowHandler.attachment.update(updateParams: object)
const newPendency = await workflowHandler.attachment.createPendency(loadParams: object)
const loadPendency = await workflowHandler.attachment.loadPendency(idParam: object)

Observation

  • create
const createParams = {
  document_id: number,
  message: string,
  observation_from: string,
  section: string,
  send_communication: boolean
}

const createObservation = await workflowHandler.observation.create(createParams)
  • delete
const deleteObservation = await workflowHandler.observation.delete({ id: idToDelete })

CertDox

You can you CertDox integration easily in your codes just instantiating it. Follow the example below:

const { Certdox } = require('@workflowd1/workflow-sdk')

const certdox = new Certdox('your_api_key_here')

Voucher

  • ask
const data = [
  {
    tipoCombo: "1",
    idDocumento: "10101010",
    nome: "Nome",
    cpfCnpj: "000.000.000-00",
    cidade: "São Paulo",
    uf: "SP",
    nomeMae: "Nome da Mãe",
    nomePai: "Nome do Pai",
    rg: "99999999",
    dataNascimento: "10-10-1900",
    informacoesAdicionais: "Informações adicionais"
  }
]

const res = await certdox.voucher.ask(data)

Register

  • ask
const data = {
  tipoCombo: "1",
  idDocumento: "10101010",
  cartorio: "Nome do Cartorio",
  cidade: "São Paulo",
  uf: "SP",
  numeroContrato: "123123123",
  partes: [
    {
      nome: "Nome da parte",
      cpf: "000.000.000-00",
      tipoDocumento: "RG"
    }
  ],
  documentos: [
    {
      tipoDocumento: "CPF",
      urlDocumento: "https://url-do-documento/documento.pdf"
    }
  ],
  informacoesAdicionais: "Informações adicionais"
}

const res = await certdox.register.ask(data)

Requirements

  • ask
const data = {
    idPedido: "10101010",
    idSmarkio: "20202020",
    textoSolucao: "Texto contendo teste"
}

const res = await certdox.requirements.ask(data)

Common

There is some classes that can be used by any other module or consumer. They are called 'Common'.

Redis

Redis class is based on Singleton, and should be used as one.

const redisInstance = Redis.getInstance(options, key);
2.1.2

2 years ago

2.0.3

2 years ago

2.1.1

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.11

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago