@cuenca-mx/cuenca-js 0.0.1-dev.2 → 0.0.1-dev.22

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 CHANGED
@@ -2,6 +2,159 @@
2
2
 
3
3
  `cuenca-js` is a Javascript library client to use Cuenca's services.
4
4
 
5
- ## Installation
6
5
 
7
- ## Documentation
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
+ phase: Phase.Api, // Production environment
52
+ useJwt: true,
53
+ });
54
+ ```
55
+
56
+ #### Client's configuration values
57
+
58
+ | Configuration Name | Description | Default Value |
59
+ | :---------- | :------------------ | :------: |
60
+ | apiKey | API Key credential | `undefined` |
61
+ | apiSecret | Secret for the API Key | `undefined` |
62
+ | phase | Used to change the environment for the client (production, stage or sandbox) | `Phase.Sandbox` |
63
+ | loginToken | Login Token, sets `X-Cuenca-LoginToken` on each request | `undefined` |
64
+ | useJwt | If `true`, it will create a JWT for authentification | `false` |
65
+
66
+ ### Login
67
+
68
+ After configuring the client, you should login to your user before performing requests on resources:
69
+
70
+ ```js
71
+ const login = await cuenca.userLogins.create('111111'); // Use 6 digit password to login
72
+ console.log(login); // UserLogin model { id: string, lastLoginAt: Date, success: bool }
73
+ ```
74
+
75
+ ### Use Resources
76
+
77
+ Different actions may be performed on each resource depending on which of the following classes they implement:
78
+
79
+ #### Action Classes
80
+ | Name | methods | Description
81
+ | :--- | -----: | ---------: |
82
+ | `Retrievable` | `.retrieve(id)` | Retrieves the resource's model given an ID |
83
+ | `Creatable` | Implementation varies* | Creates the resource from a given data |
84
+ | `Updateable` | Implementation varies* | Updates a resource given its ID and data |
85
+ | `Deactivable` | Implementation varies* | Deactivates the resource given its ID |
86
+ | `Downloadable` | `.pdf()`, `.xml()` | Returns the byte string of a document given its ID |
87
+ | `Queryable` | `.one()`, `.first()`, `.count()`, `.all()` | Perform different types of queries on resources |
88
+
89
+ * *Some resources may have a different implementation of some actions, for more detail check the source code (better documentation is a WIP).
90
+
91
+ #### Resources
92
+ | Name | Actions |
93
+ | :---- | ---------: |
94
+ | accounts | `Queryable`, `Retrievable` |
95
+ | apiKeys | `Creatable`, `Deactivable`, `Queryable`, `Retrievable`, `Updateable` |
96
+ | arpc | `Creatable` |
97
+ | accounts | `Queryable`, `Retrievable` |
98
+ | balanceEntries | `Queryable`, `Retrievable` |
99
+ | billPayments | `Queryable`, `Retrievable` |
100
+ | cardActivations | `Creatable` |
101
+ | cards | `Creatable`, `Deactivable`, `Queryable`, `Retrievable`, `Updateable` |
102
+ | cardTransactions | `Queryable`, `Retrievable` |
103
+ | cardValidations | `Creatable` |
104
+ | commissions | `Queryable`, `Retrievable` |
105
+ | deposits | `Queryable`, `Retrievable` |
106
+ | loginTokens | `Creatable` |
107
+ | savings | `Creatable`, `Deactivable`, `Queryable`, `Retrievable`, `Updateable` |
108
+ | serviceProviders | `Queryable`, `Retrievable` |
109
+ | statements | `Downloadable`, `Queryable` |
110
+ | transfers | `Creatable`, `Queryable`, `Retrievable` |
111
+ | userCredentials | `Creatable`, `Updateable` |
112
+ | userLogins | `Creatable`, `Deactivable` |
113
+ | walletTransactions | `Creatable`, `Queryable`, `Retrievable` |
114
+ | whatsAppTransfers | `Queryable`, `Retrievable` |
115
+
116
+ ### Example:
117
+ ```js
118
+ import { AccountQuery } from '@cuenca-mx/cuenca-js/types';
119
+
120
+ let account;
121
+ account = await cuenca.accounts.first(); // Returns the first value found on the query
122
+
123
+ try {
124
+ // Throws an error if no result was found or if more than one result were found.
125
+ account = await cuenca.accounts.one(
126
+ new AccountQuery({
127
+ accountNumber: 'SOME_ACCOUNT_NUMBER',
128
+ }),
129
+ );
130
+ } catch (error) {
131
+ console.log(error);
132
+ }
133
+ ```
134
+
135
+ ## 💡 Contribute
136
+
137
+ ### Found a bug?
138
+
139
+ Please submit an issue and how to replicate it.
140
+
141
+ ### Want to contribute?
142
+
143
+ Fork the repo and send your PR so we can review it! Any and all help is welcomed, just keep in mind:
144
+
145
+ #### Testing
146
+
147
+ Be sure to keep coverage at least 99%
148
+
149
+
150
+ ## Contact
151
+
152
+ dev@cuenca.com
153
+
154
+ ---
155
+ Developed and maintained with 💙 by [Cuenca](https://github.com/cuenca-mx)
156
+ <p align="center">
157
+ <a href="https://cuenca.com/">
158
+ <img alt="Cuenca Logo" src="https://user-images.githubusercontent.com/23020655/150851002-0de97274-117b-4da4-93b7-e89d7c699793.svg" width="200" />
159
+ </a>
160
+ </p>
File without changes
File without changes
@@ -0,0 +1,289 @@
1
+ class CardErrorType {
2
+ static Blocked = new CardErrorType('blocked');
3
+
4
+ static Comunication = new CardErrorType('comunication');
5
+
6
+ static ContactlesAmountLimit = new CardErrorType('contactles_amount_limit');
7
+
8
+ static FraudDetection = new CardErrorType('fraud_detection');
9
+
10
+ static FraudDetectionUncertain = new CardErrorType(
11
+ 'fraud_detection_uncertain',
12
+ );
13
+
14
+ static InsufficientFounds = new CardErrorType('insufficient_founds');
15
+
16
+ static InvalidPin = new CardErrorType('invalid_pin');
17
+
18
+ static Notification = new CardErrorType('notification');
19
+
20
+ static NotificationDeactivatedCard = new CardErrorType(
21
+ 'notification_deactivated_card',
22
+ );
23
+
24
+ constructor(value) {
25
+ this.value = value;
26
+ }
27
+ }
28
+
29
+ class CardFundingType {
30
+ static Credit = new CardFundingType('credit');
31
+
32
+ static Debit = new CardFundingType('debit');
33
+
34
+ constructor(value) {
35
+ this.value = value;
36
+ }
37
+ }
38
+
39
+ class CardIssuer {
40
+ static Accendo = new CardIssuer('accendo');
41
+
42
+ static Cuenca = new CardIssuer('cuenca');
43
+
44
+ constructor(value) {
45
+ this.value = value;
46
+ }
47
+ }
48
+
49
+ class CardStatus {
50
+ static Active = new CardStatus('active');
51
+
52
+ static Blocked = new CardStatus('blocked');
53
+
54
+ static Created = new CardStatus('created');
55
+
56
+ static Deactivated = new CardStatus('deactivated');
57
+
58
+ static Printing = new CardStatus('printing');
59
+
60
+ constructor(value) {
61
+ this.value = value;
62
+ }
63
+ }
64
+
65
+ class CardTransactionType {
66
+ static Auth = new CardTransactionType('auth');
67
+
68
+ static Capture = new CardTransactionType('capture');
69
+
70
+ static Chargeback = new CardTransactionType('chargeback');
71
+
72
+ static Expiration = new CardTransactionType('expiration');
73
+
74
+ static Refund = new CardTransactionType('refund');
75
+
76
+ static Void = new CardTransactionType('void');
77
+
78
+ constructor(value) {
79
+ this.value = value;
80
+ }
81
+ }
82
+
83
+ class CardType {
84
+ static Physical = new CardType('physical');
85
+
86
+ static Virtual = new CardType('virtual');
87
+
88
+ constructor(value) {
89
+ this.value = value;
90
+ }
91
+ }
92
+
93
+ class CommissionType {
94
+ static CardRequest = new CommissionType('card_request');
95
+
96
+ static CashDeposit = new CommissionType('cash_deposit');
97
+
98
+ static OutgoingSpei = new CommissionType('outgoing_spei');
99
+
100
+ constructor(value) {
101
+ this.value = value;
102
+ }
103
+ }
104
+
105
+ class DepositNetwork {
106
+ static Cash = new DepositNetwork('cash');
107
+
108
+ static Internal = new DepositNetwork('internal');
109
+
110
+ static Spei = new DepositNetwork('spei');
111
+
112
+ constructor(value) {
113
+ this.value = value;
114
+ }
115
+ }
116
+
117
+ class EntryType {
118
+ static Credit = new EntryType('credit');
119
+
120
+ static Debit = new EntryType('debit');
121
+
122
+ constructor(value) {
123
+ this.value = value;
124
+ }
125
+ }
126
+
127
+ class FileFormat {
128
+ static Pdf = new FileFormat('pdf');
129
+
130
+ static Xml = new FileFormat('xml');
131
+
132
+ static Json = new FileFormat('json');
133
+
134
+ constructor(value) {
135
+ this.value = value;
136
+ }
137
+ }
138
+
139
+ class Phase {
140
+ static Sandbox = new Phase('sandbox');
141
+
142
+ static Stage = new Phase('stage');
143
+
144
+ static Api = new Phase('api');
145
+
146
+ constructor(value) {
147
+ this.value = value;
148
+ }
149
+ }
150
+
151
+ class ServiceProviderCategory {
152
+ static Cable = new ServiceProviderCategory('cable');
153
+
154
+ static CreditCard = new ServiceProviderCategory('credit_card');
155
+
156
+ static Electricity = new ServiceProviderCategory('electricity');
157
+
158
+ static Gas = new ServiceProviderCategory('gas');
159
+
160
+ static Internet = new ServiceProviderCategory('internet');
161
+
162
+ static LandlineTelephone = new ServiceProviderCategory('landline_telephone');
163
+
164
+ static MobileTelephonePostpaid = new ServiceProviderCategory(
165
+ 'mobile_telephone_postpaid',
166
+ );
167
+
168
+ static MobileTelephonePrepaid = new ServiceProviderCategory(
169
+ 'mobile_telephone_prepaid',
170
+ );
171
+
172
+ static SateliteTelevision = new ServiceProviderCategory(
173
+ 'satelite_television',
174
+ );
175
+
176
+ static Water = new ServiceProviderCategory('water');
177
+
178
+ constructor(value) {
179
+ this.value = value;
180
+ }
181
+ }
182
+
183
+ class SavingCategory {
184
+ static General = new SavingCategory('general');
185
+
186
+ static Home = new SavingCategory('home');
187
+
188
+ static Vehicle = new SavingCategory('vehicle');
189
+
190
+ static Travel = new SavingCategory('travel');
191
+
192
+ static Clothing = new SavingCategory('clothing');
193
+
194
+ static Other = new SavingCategory('other');
195
+
196
+ static Medical = new SavingCategory('medical');
197
+
198
+ static Accident = new SavingCategory('accident');
199
+
200
+ static Education = new SavingCategory('education');
201
+
202
+ constructor(value) {
203
+ this.value = value;
204
+ }
205
+ }
206
+
207
+ class TrackDataMethod {
208
+ static NotSet = new TrackDataMethod('not_set');
209
+
210
+ static Terminal = new TrackDataMethod('terminal');
211
+
212
+ static Manual = new TrackDataMethod('manual');
213
+
214
+ static Unknown = new TrackDataMethod('unknown');
215
+
216
+ static Contactless = new TrackDataMethod('contactless');
217
+
218
+ static FallBack = new TrackDataMethod('fall_back');
219
+
220
+ static MagneticStripe = new TrackDataMethod('magnetic_stripe');
221
+
222
+ static RecurringCharge = new TrackDataMethod('recurring_charge');
223
+
224
+ constructor(value) {
225
+ this.value = value;
226
+ }
227
+ }
228
+
229
+ class TransactionStatus {
230
+ static Created = new TransactionStatus('created');
231
+
232
+ static Failed = new TransactionStatus('failed');
233
+
234
+ static InReview = new TransactionStatus('in_review');
235
+
236
+ static Submitted = new TransactionStatus('submitted');
237
+
238
+ static Succeeded = new TransactionStatus('succeeded');
239
+
240
+ constructor(value) {
241
+ this.value = value;
242
+ }
243
+ }
244
+
245
+ class TransferNetwork {
246
+ static Internal = new TransferNetwork('internal');
247
+
248
+ static Spei = new TransferNetwork('spei');
249
+
250
+ constructor(value) {
251
+ this.value = value;
252
+ }
253
+ }
254
+
255
+ class WalletTransactionType {
256
+ static Deposit = new WalletTransactionType('deposit');
257
+
258
+ static Withdrawal = new WalletTransactionType('withdrawal');
259
+
260
+ constructor(value) {
261
+ this.value = value;
262
+ }
263
+ }
264
+
265
+ const dateToUTC = (date) => {
266
+ if (!date) return null;
267
+ const dateObj = new Date(date);
268
+ return new Date(dateObj.getTime());
269
+ };
270
+
271
+ const enumValueFromString = (enumValue, value) =>
272
+ Object.values(enumValue).find((enumV) => enumV.value === value);
273
+
274
+ class TOSAgreements {
275
+ constructor({ ip, location, version }) {
276
+ this.ip = ip;
277
+ this.location = location;
278
+ this.version = version;
279
+ }
280
+
281
+ static fromObject = ({ ip, location, version }) =>
282
+ new TOSAgreements({
283
+ ip,
284
+ location,
285
+ version,
286
+ });
287
+ }
288
+
289
+ export { CardIssuer as C, DepositNetwork as D, EntryType as E, FileFormat as F, Phase as P, SavingCategory as S, TransactionStatus as T, WalletTransactionType as W, CardStatus as a, CardType as b, CardFundingType as c, dateToUTC as d, enumValueFromString as e, CardErrorType as f, CardTransactionType as g, CommissionType as h, ServiceProviderCategory as i, TransferNetwork as j, TOSAgreements as k, TrackDataMethod as l };