npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mifiel/api-client

v0.2.3

Published

Mifiel API Client for NodeJS

Downloads

353

Readme

@mifiel/api-client

Library to wrap the most common methods of Mifiel API.

This library depends on @mifiel/api-client-auth to authenticate the Mifiel API calls.

Installation

npm install @mifiel/api-client-auth @mifiel/api-client --save
# or
yarn add @mifiel/api-client-auth @mifiel/api-client

Usage

// for ESM or TypeScript
import { Config } from '@mifiel/api-client-auth';
// for CJS
const { Config } = require('@mifiel/api-client-auth');

Config.setTokens({
  appId: '<APP_ID>',
  appSecret: '<APP_SECRET>',
  // [optional] - by default is production
  env: 'production' | 'sandbox' 
});

All methods return promises

Model Crud

We provide you a Model class to wrap API CRUD operations. You should create an instance sending the resource name.

import { Model } from '@mifiel/api-client';

const documentModel = new Model('documents');

// GET /documents
const documents = await documentModel.all();
// GET /documents/document-id
const doc = await documentModel.find('document-id');
// POST /documents
await documentModel.create({ ...docAttributes });
// DELETE /documents/document-id
await documentModel.delete('document-id');
// PATCH /documents/document-id
await documentModel.update('document-id', { ...docAttributes });

Document methods

import { Document } from '@mifiel/api-client';

The Document is an instance from a extended class of Model, so it inherits the CRUD operations (find, all, delete, create and update).

Document.getHash

Return the hex hash of a file.

import { Document } from '@mifiel/api-client';
import path from 'path';
import fs from 'fs';

const filepath = path.join(__dirname, 'my-file.pdf');
const fileBuffer = fs.readFileSync(filepath);

const hexHash = await Document.getHash(fileBuffer);

Document.getFile

Return the document related file.

import { Document } from '@mifiel/api-client';

// original file of document-id
const file = await Document.getFile({ documentId: 'document-id', type: 'file' });
// signed file (original file + signature page) of document-id
const fileSigned = await Document.getFile({ documentId: 'document-id', type: 'file_signed' });
// signed xml file
const fileSigned = await Document.getFile({ documentId: 'document-id', type: 'xml' });

Document.saveFile

Save Document related files.

import { Document } from '@mifiel/api-client';

await Document.saveFile({
  documentId: 'document-id',
  type: 'file' | 'file_signed' | 'xml',
  path: 'path/to/save/my-file.pdf'
});

Document.create

Use only original_hash if you don't want us to have the file. Either file or original_hash must be provided.

import { Document } from '@mifiel/api-client';
import path from 'path';
import fs from 'fs';

const filepath = path.join(__dirname, 'you-file.pdf');
const fileBuffer = fs.readFileSync(filepath);

// sending file to Mifiel server
const newDocumentWithFile = await Document.create({
  file: filepath,
  signatories: [{
    name: 'Signer 1',
    email: '[email protected]',
    tax_id: 'AAA010101AAA'
  }, {
    name: 'Signer 2',
    email: '[email protected]',
    tax_id: 'AAA010102AAA'
  }],
  // ...
});

// sending only the hash of file
const hexHash = await Document.getHash(fileBuffer);
const newDocumentOnlyHash = await Document.create({
  original_hash: hexHash,
  name: 'my-file.pdf',
  signatories: [
    //...
  ],
  // ...
});

Document.transfer

Use this method to transfer an endorsable document.

import { Document } from '@mifiel/api-client';

const doc = await Document.transfer({
  documentId: 'document-id-to-transfer',
  receiver: {
    email: '[email protected]',
    tax_id: 'ZAAE9306278TA',
  },
  signatories: [{
    name: 'Signer',
    email: '[email protected]',
    tax_id: 'AAA010102AAA',
    type: 'beneficiary',
  }]
})

Certifcate methods

import { Certificate } from '@mifiel/api-client';

The Certificate is an instance from a extended class of Model, so it inherits the CRUD operations (find, all, delete, create and update).

Certificate.create

import { Certificate } from '@mifiel/api-client';
import path from 'path';

const filepath = path.join(__dirname, 'you-cer.cer');

const newCertificate = await Certificate.create({ filepath });

User methods

import { User } from '@mifiel/api-client';

The User instance doesn't inherit from Model, so it doesn't have the CRUD operations.

User.me

Return the user data.

import { User } from '@mifiel/api-client';

const user = await User.me();

User.setupWidget

Every user (issuer or receiver) of an endorsable document must set up his account. During this setup process, we will use the user's FIEL/e.firma to derive a set of cryptocurrency addresses where the assets (the endorsable documents) will be stored.

Important: Save the widget_id in your database. If the user does not complete the setup, you should use the same widget_id when the user comes back to the setup flow.

import { User } from '@mifiel/api-client';

const user = await User.setupWidget({
  email: '[email protected]',
  tax_id: 'ZAAE9306278TA',
});

// save it in your database
user.widget_id

Template methods

import { Template } from '@mifiel/api-client';

The Template is an instance from a extended class of Model, so it inherits the CRUD operations (find, all, delete, create and update).

Templates are a tool that allows you to create templates that have a base format. You can define fields within the html so you can then create a custumized document.

Template.getFields

Get the fields of a specific template. Use it to know what to send to generate documents with this template.

import { Template } from '@mifiel/api-client';

const fields = await Template.getFields({ templateId: 'template-id' });

Template.getDocuments

Get all the active (non deleted) documents generated from a specific template.

import { Template } from '@mifiel/api-client';

const documents = await Template.getDocuments({ templateId: 'template-id' });

Template.generateDocument

Generate a document from a template.

import { Template } from '@mifiel/api-client';

const documents = await Template.generateDocument({
  templateId: 'template-id',
  document: {
    name: 'Mi Client Name',
    signatories: [{
      name: 'Signer 1',
      email: '[email protected]',
      tax_id: 'AAA010101AAA'
    }]
  }
});

Template.generateDocuments

The generation of documents runs in the background. We will respond with 200 (OK) and start generating the documents. When our servers finish, we will POST you to the provided callback_url with a list of the created documents.

import { Template } from '@mifiel/api-client';

const documents = await Template.generateDocuments({
  templateId: 'template-id',
  callback_url: 'https://www.my-site.com/webhook',
  documents: [{
    name: 'Mi Client Name',
    // ...
  }]
});

If you want to see more about the response attributes, please check out our library @mifiel/models