cuenca-js ·
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();
await cuenca.client.configure({
apiKey: 'SOME_API_KEY',
apiSecret: 'SOME_API_SECRET',
loginToken: 'LOGIN_TOKEN',
phase: Phase.Api,
useJwt: true,
});
Client's configuration values
Configuration Name | Description | Default Value |
---|
apiKey | API Key credential | undefined |
apiSecret | Secret for the API Key | undefined |
phase | Used to change the environment for the client (production, stage or sandbox) | Phase.Sandbox |
loginToken | Login Token, sets X-Cuenca-LoginToken on each request | undefined |
useJwt | If true , it will create a JWT for authentification | false |
Login
After configuring the client, you should login to your user before performing requests on resources:
const login = await cuenca.userLogins.create('111111');
console.log(login);
Use Resources
Different actions may be performed on each resource depending on which of the following classes they implement:
Action Classes
Name | methods | Description |
---|
Retrievable | .retrieve(id) | Retrieves the resource's model given an ID |
Creatable | Implementation varies* | Creates the resource from a given data |
Updateable | Implementation varies* | Updates a resource given its ID and data |
Deactivable | Implementation 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
Name | Actions |
---|
accounts | Queryable , Retrievable |
apiKeys | Creatable , Deactivable , Queryable , Retrievable , Updateable |
arpc | Creatable |
accounts | Queryable , Retrievable |
balanceEntries | Queryable , Retrievable |
billPayments | Queryable , Retrievable |
cardActivations | Creatable |
cards | Creatable , Deactivable , Queryable , Retrievable , Updateable |
cardTransactions | Queryable , Retrievable |
cardValidations | Creatable |
commissions | Queryable , Retrievable |
deposits | Queryable , Retrievable |
loginTokens | Creatable |
savings | Creatable , Deactivable , Queryable , Retrievable , Updateable |
serviceProviders | Queryable , Retrievable |
statements | Downloadable , Queryable |
transfers | Creatable , Queryable , Retrievable |
userCredentials | Creatable , Updateable |
userLogins | Creatable , Deactivable |
walletTransactions | Creatable , Queryable , Retrievable |
whatsAppTransfers | Queryable , Retrievable |
Example:
import { AccountQuery } from '@cuenca-mx/cuenca-js/types';
let account;
account = await cuenca.accounts.first();
try {
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