Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cuenca-mx/cuenca-js

Package Overview
Dependencies
Maintainers
2
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cuenca-mx/cuenca-js

Cuenca client for JS

  • 0.0.1-dev.39
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
Maintainers
2
Weekly downloads
 
Created
Source

cuenca-js · codecov

cuenca-js is a Javascript library client to use Cuenca's services.

💻 Installation

Using npm:

npm install --save @cuenca-mx/cuenca-js

Using yarn:

yarn add @cuenca-mx/cuenca-js

🚀 Getting Started

Configure the client

To start using the library, the client must be configured with your credentials. Some configurations can be changed to further improve the use of the library:

  • Configuring the client on constructor The credentials and environment can be set when instantiating the client:

    import { Cuenca } from '@cuenca-mx/cuenca-js';
    import { Phase } from '@cuenca-mx/cuenca-js/types';
    
    const cuenca = new Cuenca(
        'SOME_API_KEY',
        'SOME_API_SECRET',
        Phase.Stage,
    );
    
  • Client's configuration The configuration can be changed after creating it using the configure method:

    import { Cuenca } from '@cuenca-mx/cuenca-js';
    import { Phase } from '@cuenca-mx/cuenca-js/types';
    
    const cuenca = new Client();
    // The method will require await if `useJwt` is setted to `true`
    // because a request is made to Cuenca to create the JWT.
    await cuenca.client.configure({
        apiKey: 'SOME_API_KEY',
        apiSecret: 'SOME_API_SECRET',
        loginToken: 'LOGIN_TOKEN',
        sessionId: 'SESSION_ID',
        phase: Phase.Api, // Production environment
        useJwt: true,
    });
    
Client's configuration values
Configuration NameDescriptionDefault Value
apiKeyAPI Key credentialundefined
apiSecretSecret for the API Keyundefined
phaseUsed to change the environment for the client (production, stage or sandbox)Phase.Sandbox
loginTokenLogin Token, sets X-Cuenca-LoginToken on each requestundefined
sessionIdSession Id, sets X-Cuenca-SessionId on each requestundefined
useJwtIf true, it will create a JWT for authentificationfalse

Login

After configuring the client, you should login to your user before performing requests on resources:

const login = await cuenca.userLogins.create('111111'); // Use 6 digit password to login
console.log(login); // UserLogin model { id: string, lastLoginAt: Date, success: bool }

Use Resources

Different actions may be performed on each resource depending on which of the following classes they implement:

Action Classes
NamemethodsDescription
Retrievable.retrieve(id)Retrieves the resource's model given an ID
CreatableImplementation varies*Creates the resource from a given data
UpdateableImplementation varies*Updates a resource given its ID and data
DeactivableImplementation varies*Deactivates the resource given its ID
Downloadable.pdf(), .xml()Returns the byte string of a document given its ID
Queryable.one(), .first(), .count(), .all()Perform different types of queries on resources
  • *Some resources may have a different implementation of some actions, for more detail check the source code (better documentation is a WIP).
Resources
NameActions
accountsQueryable, Retrievable
apiKeysCreatable, Deactivable, Queryable, Retrievable, Updateable
arpcCreatable
accountsQueryable, Retrievable
balanceEntriesQueryable, Retrievable
billPaymentsQueryable, Retrievable
cardActivationsCreatable
cardsCreatable, Deactivable, Queryable, Retrievable, Updateable
cardTransactionsQueryable, Retrievable
cardValidationsCreatable
commissionsQueryable, Retrievable
depositsQueryable, Retrievable
loginTokensCreatable
savingsCreatable, Deactivable, Queryable, Retrievable, Updateable
serviceProvidersQueryable, Retrievable
statementsDownloadable, Queryable
transfersCreatable, Queryable, Retrievable
userCredentialsCreatable, Updateable
userLoginsCreatable, Deactivable
walletTransactionsCreatable, Queryable, Retrievable
whatsAppTransfersQueryable, Retrievable

Example:

import { AccountQuery } from '@cuenca-mx/cuenca-js/types';

let account;
account = await cuenca.accounts.first(); // Returns the first value found on the query

try {
    // Throws an error if no result was found or if more than one result were found.
    account = await cuenca.accounts.one(
        new AccountQuery({
            accountNumber: 'SOME_ACCOUNT_NUMBER',
        }),
    );
} catch (error) {
    console.log(error);
}

💡 Contribute

Found a bug?

Please submit an issue and how to replicate it.

Want to contribute?

Fork the repo and send your PR so we can review it! Any and all help is welcomed, just keep in mind:

Testing

Be sure to keep coverage at least 99%

Contact

dev@cuenca.com


Developed and maintained with 💙 by Cuenca

Cuenca Logo

Keywords

FAQs

Package last updated on 18 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc