@cuenca-mx/cuenca-js 0.0.1-dev.3 → 0.0.1-dev.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -2
- package/build/base-80b9a673.cjs +28 -0
- package/build/base-c1f04b51.mjs +24 -0
- package/build/errors/{index.js → index.cjs} +0 -0
- package/build/{queries-f146b91b.js → identities-122c79fd.mjs} +49 -2
- package/build/{queries-b8f29837.js → identities-d9bd3846.cjs} +54 -4
- package/build/{index.js → index.cjs} +199 -117
- package/build/index.mjs +133 -17
- package/build/jwt/{index.js → index.cjs} +7 -2
- package/build/jwt/index.mjs +2 -1
- package/build/requests/{index.js → index.cjs} +5 -3
- package/build/requests/index.mjs +2 -2
- package/build/types/index.cjs +43 -0
- package/build/types/index.mjs +2 -2
- package/build/umd/cuenca.umd.js +1 -1
- package/build/{walletTransactionRequest-bbfb87bd.js → walletTransactionRequest-8b125547.mjs} +63 -16
- package/build/{walletTransactionRequest-b588cc52.js → walletTransactionRequest-bda66da3.cjs} +78 -29
- package/package.json +27 -4
- package/build/data-7d3d5fcc.js +0 -11
- package/build/data-c53f1052.js +0 -14
- package/build/types/index.js +0 -40
package/README.md
CHANGED
|
@@ -2,6 +2,161 @@
|
|
|
2
2
|
|
|
3
3
|
`cuenca-js` is a Javascript library client to use Cuenca's services.
|
|
4
4
|
|
|
5
|
-
## Installation
|
|
6
5
|
|
|
7
|
-
##
|
|
6
|
+
## 💻 Installation
|
|
7
|
+
|
|
8
|
+
Using `npm`:
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save @cuenca-mx/cuenca-js
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Using `yarn`:
|
|
14
|
+
```bash
|
|
15
|
+
yarn add @cuenca-mx/cuenca-js
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## 🚀 Getting Started
|
|
20
|
+
|
|
21
|
+
### Configure the client
|
|
22
|
+
|
|
23
|
+
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:
|
|
24
|
+
|
|
25
|
+
- Configuring the client on constructor
|
|
26
|
+
The credentials and environment can be set when instantiating the client:
|
|
27
|
+
```js
|
|
28
|
+
import { Cuenca } from '@cuenca-mx/cuenca-js';
|
|
29
|
+
import { Phase } from '@cuenca-mx/cuenca-js/types';
|
|
30
|
+
|
|
31
|
+
const cuenca = new Cuenca(
|
|
32
|
+
'SOME_API_KEY',
|
|
33
|
+
'SOME_API_SECRET',
|
|
34
|
+
Phase.Stage,
|
|
35
|
+
);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- Client's configuration
|
|
39
|
+
The configuration can be changed after creating it using the `configure` method:
|
|
40
|
+
```js
|
|
41
|
+
import { Cuenca } from '@cuenca-mx/cuenca-js';
|
|
42
|
+
import { Phase } from '@cuenca-mx/cuenca-js/types';
|
|
43
|
+
|
|
44
|
+
const cuenca = new Client();
|
|
45
|
+
// The method will require await if `useJwt` is setted to `true`
|
|
46
|
+
// because a request is made to Cuenca to create the JWT.
|
|
47
|
+
await cuenca.client.configure({
|
|
48
|
+
apiKey: 'SOME_API_KEY',
|
|
49
|
+
apiSecret: 'SOME_API_SECRET',
|
|
50
|
+
loginToken: 'LOGIN_TOKEN',
|
|
51
|
+
sessionId: 'SESSION_ID',
|
|
52
|
+
phase: Phase.Api, // Production environment
|
|
53
|
+
useJwt: true,
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Client's configuration values
|
|
58
|
+
|
|
59
|
+
| Configuration Name | Description | Default Value |
|
|
60
|
+
| :---------- | :------------------ | :------: |
|
|
61
|
+
| apiKey | API Key credential | `undefined` |
|
|
62
|
+
| apiSecret | Secret for the API Key | `undefined` |
|
|
63
|
+
| phase | Used to change the environment for the client (production, stage or sandbox) | `Phase.Sandbox` |
|
|
64
|
+
| loginToken | Login Token, sets `X-Cuenca-LoginToken` on each request | `undefined` |
|
|
65
|
+
| sessionId | Session Id, sets `X-Cuenca-SessionId` on each request | `undefined` |
|
|
66
|
+
| useJwt | If `true`, it will create a JWT for authentification | `false` |
|
|
67
|
+
|
|
68
|
+
### Login
|
|
69
|
+
|
|
70
|
+
After configuring the client, you should login to your user before performing requests on resources:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
const login = await cuenca.userLogins.create('111111'); // Use 6 digit password to login
|
|
74
|
+
console.log(login); // UserLogin model { id: string, lastLoginAt: Date, success: bool }
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Use Resources
|
|
78
|
+
|
|
79
|
+
Different actions may be performed on each resource depending on which of the following classes they implement:
|
|
80
|
+
|
|
81
|
+
#### Action Classes
|
|
82
|
+
| Name | methods | Description
|
|
83
|
+
| :--- | -----: | ---------: |
|
|
84
|
+
| `Retrievable` | `.retrieve(id)` | Retrieves the resource's model given an ID |
|
|
85
|
+
| `Creatable` | Implementation varies* | Creates the resource from a given data |
|
|
86
|
+
| `Updateable` | Implementation varies* | Updates a resource given its ID and data |
|
|
87
|
+
| `Deactivable` | Implementation varies* | Deactivates the resource given its ID |
|
|
88
|
+
| `Downloadable` | `.pdf()`, `.xml()` | Returns the byte string of a document given its ID |
|
|
89
|
+
| `Queryable` | `.one()`, `.first()`, `.count()`, `.all()` | Perform different types of queries on resources |
|
|
90
|
+
|
|
91
|
+
* *Some resources may have a different implementation of some actions, for more detail check the source code (better documentation is a WIP).
|
|
92
|
+
|
|
93
|
+
#### Resources
|
|
94
|
+
| Name | Actions |
|
|
95
|
+
| :---- | ---------: |
|
|
96
|
+
| accounts | `Queryable`, `Retrievable` |
|
|
97
|
+
| apiKeys | `Creatable`, `Deactivable`, `Queryable`, `Retrievable`, `Updateable` |
|
|
98
|
+
| arpc | `Creatable` |
|
|
99
|
+
| accounts | `Queryable`, `Retrievable` |
|
|
100
|
+
| balanceEntries | `Queryable`, `Retrievable` |
|
|
101
|
+
| billPayments | `Queryable`, `Retrievable` |
|
|
102
|
+
| cardActivations | `Creatable` |
|
|
103
|
+
| cards | `Creatable`, `Deactivable`, `Queryable`, `Retrievable`, `Updateable` |
|
|
104
|
+
| cardTransactions | `Queryable`, `Retrievable` |
|
|
105
|
+
| cardValidations | `Creatable` |
|
|
106
|
+
| commissions | `Queryable`, `Retrievable` |
|
|
107
|
+
| deposits | `Queryable`, `Retrievable` |
|
|
108
|
+
| loginTokens | `Creatable` |
|
|
109
|
+
| savings | `Creatable`, `Deactivable`, `Queryable`, `Retrievable`, `Updateable` |
|
|
110
|
+
| serviceProviders | `Queryable`, `Retrievable` |
|
|
111
|
+
| statements | `Downloadable`, `Queryable` |
|
|
112
|
+
| transfers | `Creatable`, `Queryable`, `Retrievable` |
|
|
113
|
+
| userCredentials | `Creatable`, `Updateable` |
|
|
114
|
+
| userLogins | `Creatable`, `Deactivable` |
|
|
115
|
+
| walletTransactions | `Creatable`, `Queryable`, `Retrievable` |
|
|
116
|
+
| whatsAppTransfers | `Queryable`, `Retrievable` |
|
|
117
|
+
|
|
118
|
+
### Example:
|
|
119
|
+
```js
|
|
120
|
+
import { AccountQuery } from '@cuenca-mx/cuenca-js/types';
|
|
121
|
+
|
|
122
|
+
let account;
|
|
123
|
+
account = await cuenca.accounts.first(); // Returns the first value found on the query
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
// Throws an error if no result was found or if more than one result were found.
|
|
127
|
+
account = await cuenca.accounts.one(
|
|
128
|
+
new AccountQuery({
|
|
129
|
+
accountNumber: 'SOME_ACCOUNT_NUMBER',
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.log(error);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## 💡 Contribute
|
|
138
|
+
|
|
139
|
+
### Found a bug?
|
|
140
|
+
|
|
141
|
+
Please submit an issue and how to replicate it.
|
|
142
|
+
|
|
143
|
+
### Want to contribute?
|
|
144
|
+
|
|
145
|
+
Fork the repo and send your PR so we can review it! Any and all help is welcomed, just keep in mind:
|
|
146
|
+
|
|
147
|
+
#### Testing
|
|
148
|
+
|
|
149
|
+
Be sure to keep coverage at least 99%
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
## Contact
|
|
153
|
+
|
|
154
|
+
dev@cuenca.com
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
Developed and maintained with 💙 by [Cuenca](https://github.com/cuenca-mx)
|
|
158
|
+
<p align="center">
|
|
159
|
+
<a href="https://cuenca.com/">
|
|
160
|
+
<img alt="Cuenca Logo" src="https://user-images.githubusercontent.com/23020655/150851002-0de97274-117b-4da4-93b7-e89d7c699793.svg" width="200" />
|
|
161
|
+
</a>
|
|
162
|
+
</p>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const dateToUTC = (date) => {
|
|
4
|
+
if (!date) return null;
|
|
5
|
+
const dateObj = new Date(date);
|
|
6
|
+
return new Date(dateObj.getTime());
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const enumValueFromString = (enumValue, value) =>
|
|
10
|
+
Object.values(enumValue).find((enumV) => enumV.value === value);
|
|
11
|
+
|
|
12
|
+
class BaseRequest {
|
|
13
|
+
toObject() {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
toCleanObject() {
|
|
18
|
+
const obj = this.toObject();
|
|
19
|
+
Object.keys(obj).forEach((k) => {
|
|
20
|
+
if (obj[k] == null) delete obj[k];
|
|
21
|
+
});
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.BaseRequest = BaseRequest;
|
|
27
|
+
exports.dateToUTC = dateToUTC;
|
|
28
|
+
exports.enumValueFromString = enumValueFromString;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const dateToUTC = (date) => {
|
|
2
|
+
if (!date) return null;
|
|
3
|
+
const dateObj = new Date(date);
|
|
4
|
+
return new Date(dateObj.getTime());
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const enumValueFromString = (enumValue, value) =>
|
|
8
|
+
Object.values(enumValue).find((enumV) => enumV.value === value);
|
|
9
|
+
|
|
10
|
+
class BaseRequest {
|
|
11
|
+
toObject() {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
toCleanObject() {
|
|
16
|
+
const obj = this.toObject();
|
|
17
|
+
Object.keys(obj).forEach((k) => {
|
|
18
|
+
if (obj[k] == null) delete obj[k];
|
|
19
|
+
});
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { BaseRequest as B, dateToUTC as d, enumValueFromString as e };
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValidationError } from './errors/index.mjs';
|
|
2
|
-
import { d as dateToUTC } from './
|
|
2
|
+
import { d as dateToUTC, B as BaseRequest } from './base-c1f04b51.mjs';
|
|
3
3
|
|
|
4
4
|
class CardErrorType {
|
|
5
5
|
static Blocked = new CardErrorType('blocked');
|
|
@@ -255,6 +255,20 @@ class TransferNetwork {
|
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
class UserStatus {
|
|
259
|
+
static Active = new UserStatus('active');
|
|
260
|
+
|
|
261
|
+
static Deactivated = new UserStatus('deactivated');
|
|
262
|
+
|
|
263
|
+
static fraud = new UserStatus('fraud');
|
|
264
|
+
|
|
265
|
+
static pld_blocked = new UserStatus('pld_blocked');
|
|
266
|
+
|
|
267
|
+
constructor(value) {
|
|
268
|
+
this.value = value;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
258
272
|
class WalletTransactionType {
|
|
259
273
|
static Deposit = new WalletTransactionType('deposit');
|
|
260
274
|
|
|
@@ -496,6 +510,23 @@ class WalletTransactionQuery extends QueryParams {
|
|
|
496
510
|
}
|
|
497
511
|
}
|
|
498
512
|
|
|
513
|
+
class UserQuery extends QueryParams {
|
|
514
|
+
constructor({ emailAddress, phoneNumber, status, ...args }) {
|
|
515
|
+
super(args);
|
|
516
|
+
this.emailAddress = emailAddress;
|
|
517
|
+
this.phoneNumber = phoneNumber;
|
|
518
|
+
this.status = status;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
toObject() {
|
|
522
|
+
return Object.assign(super.toObject(), {
|
|
523
|
+
email_address: this.emailAddress,
|
|
524
|
+
phone_number: this.phoneNumber,
|
|
525
|
+
status: this.status,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
499
530
|
class WalletQuery extends QueryParams {
|
|
500
531
|
constructor({ active, ...args }) {
|
|
501
532
|
super(args);
|
|
@@ -543,4 +574,20 @@ class StatementQuery extends QueryParams {
|
|
|
543
574
|
}
|
|
544
575
|
}
|
|
545
576
|
|
|
546
|
-
|
|
577
|
+
class TOSAgreements extends BaseRequest {
|
|
578
|
+
constructor({ ip, location, version }) {
|
|
579
|
+
super();
|
|
580
|
+
this.ip = ip;
|
|
581
|
+
this.location = location;
|
|
582
|
+
this.version = version;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
static fromObject = ({ ip, location, version }) =>
|
|
586
|
+
new TOSAgreements({
|
|
587
|
+
ip,
|
|
588
|
+
location,
|
|
589
|
+
version,
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
export { AccountQuery as A, BalanceEntryQuery as B, CardIssuer as C, DepositNetwork as D, EntryType as E, FileFormat as F, Phase as P, QueryParams as Q, SavingCategory as S, TransactionStatus as T, UserStatus as U, WalletTransactionType as W, CardStatus as a, CardType as b, CardFundingType as c, CardErrorType as d, CardTransactionType as e, CommissionType as f, ServiceProviderCategory as g, TransferNetwork as h, TOSAgreements as i, ApiKeyQuery as j, BillPaymentQuery as k, CardsQuery as l, CardTransactionQuery as m, DepositQuery as n, WalletQuery as o, StatementQuery as p, TransferQuery as q, UserQuery as r, WalletTransactionQuery as s, TrackDataMethod as t, PageSize as u };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var errors_index = require('./errors/index.
|
|
4
|
-
var
|
|
3
|
+
var errors_index = require('./errors/index.cjs');
|
|
4
|
+
var base = require('./base-80b9a673.cjs');
|
|
5
5
|
|
|
6
6
|
class CardErrorType {
|
|
7
7
|
static Blocked = new CardErrorType('blocked');
|
|
@@ -257,6 +257,20 @@ class TransferNetwork {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
class UserStatus {
|
|
261
|
+
static Active = new UserStatus('active');
|
|
262
|
+
|
|
263
|
+
static Deactivated = new UserStatus('deactivated');
|
|
264
|
+
|
|
265
|
+
static fraud = new UserStatus('fraud');
|
|
266
|
+
|
|
267
|
+
static pld_blocked = new UserStatus('pld_blocked');
|
|
268
|
+
|
|
269
|
+
constructor(value) {
|
|
270
|
+
this.value = value;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
260
274
|
class WalletTransactionType {
|
|
261
275
|
static Deposit = new WalletTransactionType('deposit');
|
|
262
276
|
|
|
@@ -498,6 +512,23 @@ class WalletTransactionQuery extends QueryParams {
|
|
|
498
512
|
}
|
|
499
513
|
}
|
|
500
514
|
|
|
515
|
+
class UserQuery extends QueryParams {
|
|
516
|
+
constructor({ emailAddress, phoneNumber, status, ...args }) {
|
|
517
|
+
super(args);
|
|
518
|
+
this.emailAddress = emailAddress;
|
|
519
|
+
this.phoneNumber = phoneNumber;
|
|
520
|
+
this.status = status;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
toObject() {
|
|
524
|
+
return Object.assign(super.toObject(), {
|
|
525
|
+
email_address: this.emailAddress,
|
|
526
|
+
phone_number: this.phoneNumber,
|
|
527
|
+
status: this.status,
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
501
532
|
class WalletQuery extends QueryParams {
|
|
502
533
|
constructor({ active, ...args }) {
|
|
503
534
|
super(args);
|
|
@@ -526,9 +557,9 @@ class StatementQuery extends QueryParams {
|
|
|
526
557
|
}
|
|
527
558
|
|
|
528
559
|
set d({ month, year }) {
|
|
529
|
-
const now =
|
|
560
|
+
const now = base.dateToUTC(Date.now());
|
|
530
561
|
now.setUTCDate(1);
|
|
531
|
-
const date =
|
|
562
|
+
const date = base.dateToUTC(`${year}-${month}-01`);
|
|
532
563
|
if (date.getTime() >= now.getTime()) {
|
|
533
564
|
throw new errors_index.ValidationError(
|
|
534
565
|
`${year}-${month} is not a valid year-month pair`,
|
|
@@ -545,6 +576,22 @@ class StatementQuery extends QueryParams {
|
|
|
545
576
|
}
|
|
546
577
|
}
|
|
547
578
|
|
|
579
|
+
class TOSAgreements extends base.BaseRequest {
|
|
580
|
+
constructor({ ip, location, version }) {
|
|
581
|
+
super();
|
|
582
|
+
this.ip = ip;
|
|
583
|
+
this.location = location;
|
|
584
|
+
this.version = version;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
static fromObject = ({ ip, location, version }) =>
|
|
588
|
+
new TOSAgreements({
|
|
589
|
+
ip,
|
|
590
|
+
location,
|
|
591
|
+
version,
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
|
|
548
595
|
exports.AccountQuery = AccountQuery;
|
|
549
596
|
exports.ApiKeyQuery = ApiKeyQuery;
|
|
550
597
|
exports.BalanceEntryQuery = BalanceEntryQuery;
|
|
@@ -568,10 +615,13 @@ exports.QueryParams = QueryParams;
|
|
|
568
615
|
exports.SavingCategory = SavingCategory;
|
|
569
616
|
exports.ServiceProviderCategory = ServiceProviderCategory;
|
|
570
617
|
exports.StatementQuery = StatementQuery;
|
|
618
|
+
exports.TOSAgreements = TOSAgreements;
|
|
571
619
|
exports.TrackDataMethod = TrackDataMethod;
|
|
572
620
|
exports.TransactionStatus = TransactionStatus;
|
|
573
621
|
exports.TransferNetwork = TransferNetwork;
|
|
574
622
|
exports.TransferQuery = TransferQuery;
|
|
623
|
+
exports.UserQuery = UserQuery;
|
|
624
|
+
exports.UserStatus = UserStatus;
|
|
575
625
|
exports.WalletQuery = WalletQuery;
|
|
576
626
|
exports.WalletTransactionQuery = WalletTransactionQuery;
|
|
577
627
|
exports.WalletTransactionType = WalletTransactionType;
|