@cuenca-mx/cuenca-js 0.0.1-dev.7 → 0.0.2

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,161 @@
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
+ 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,330 @@
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 KYCFileType {
140
+ static Ine = new KYCFileType('ine');
141
+
142
+ static Passport = new KYCFileType('passport');
143
+
144
+ static Residency = new KYCFileType('residency');
145
+
146
+ static MatriculaConsular = new KYCFileType('matricula_consular');
147
+
148
+ static ProofOfLiveness = new KYCFileType('proof_of_liveness');
149
+
150
+ static ProofOfAddress = new KYCFileType('proof_of_address');
151
+
152
+ constructor(value) {
153
+ this.value = value;
154
+ }
155
+ }
156
+
157
+ class KYCStatus {
158
+ static UploadAgain = new KYCStatus('upload_again');
159
+
160
+ static ReviewNeeded = new KYCStatus('review_needed');
161
+
162
+ static Submitted = new KYCStatus('submitted');
163
+
164
+ static Succeeded = new KYCStatus('succeeded');
165
+
166
+ constructor(value) {
167
+ this.value = value;
168
+ }
169
+ }
170
+
171
+ class Phase {
172
+ static Sandbox = new Phase('sandbox');
173
+
174
+ static Stage = new Phase('stage');
175
+
176
+ static Api = new Phase('api');
177
+
178
+ constructor(value) {
179
+ this.value = value;
180
+ }
181
+ }
182
+
183
+ class ServiceProviderCategory {
184
+ static Cable = new ServiceProviderCategory('cable');
185
+
186
+ static CreditCard = new ServiceProviderCategory('credit_card');
187
+
188
+ static Electricity = new ServiceProviderCategory('electricity');
189
+
190
+ static Gas = new ServiceProviderCategory('gas');
191
+
192
+ static Internet = new ServiceProviderCategory('internet');
193
+
194
+ static LandlineTelephone = new ServiceProviderCategory('landline_telephone');
195
+
196
+ static MobileTelephonePostpaid = new ServiceProviderCategory(
197
+ 'mobile_telephone_postpaid',
198
+ );
199
+
200
+ static MobileTelephonePrepaid = new ServiceProviderCategory(
201
+ 'mobile_telephone_prepaid',
202
+ );
203
+
204
+ static SateliteTelevision = new ServiceProviderCategory(
205
+ 'satelite_television',
206
+ );
207
+
208
+ static Water = new ServiceProviderCategory('water');
209
+
210
+ constructor(value) {
211
+ this.value = value;
212
+ }
213
+ }
214
+
215
+ class SavingCategory {
216
+ static General = new SavingCategory('general');
217
+
218
+ static Home = new SavingCategory('home');
219
+
220
+ static Vehicle = new SavingCategory('vehicle');
221
+
222
+ static Travel = new SavingCategory('travel');
223
+
224
+ static Clothing = new SavingCategory('clothing');
225
+
226
+ static Other = new SavingCategory('other');
227
+
228
+ static Medical = new SavingCategory('medical');
229
+
230
+ static Accident = new SavingCategory('accident');
231
+
232
+ static Education = new SavingCategory('education');
233
+
234
+ constructor(value) {
235
+ this.value = value;
236
+ }
237
+ }
238
+
239
+ class TrackDataMethod {
240
+ static NotSet = new TrackDataMethod('not_set');
241
+
242
+ static Terminal = new TrackDataMethod('terminal');
243
+
244
+ static Manual = new TrackDataMethod('manual');
245
+
246
+ static Unknown = new TrackDataMethod('unknown');
247
+
248
+ static Contactless = new TrackDataMethod('contactless');
249
+
250
+ static FallBack = new TrackDataMethod('fall_back');
251
+
252
+ static MagneticStripe = new TrackDataMethod('magnetic_stripe');
253
+
254
+ static RecurringCharge = new TrackDataMethod('recurring_charge');
255
+
256
+ constructor(value) {
257
+ this.value = value;
258
+ }
259
+ }
260
+
261
+ class TransactionStatus {
262
+ static Created = new TransactionStatus('created');
263
+
264
+ static Failed = new TransactionStatus('failed');
265
+
266
+ static InReview = new TransactionStatus('in_review');
267
+
268
+ static Submitted = new TransactionStatus('submitted');
269
+
270
+ static Succeeded = new TransactionStatus('succeeded');
271
+
272
+ constructor(value) {
273
+ this.value = value;
274
+ }
275
+ }
276
+
277
+ class TransferNetwork {
278
+ static Internal = new TransferNetwork('internal');
279
+
280
+ static Spei = new TransferNetwork('spei');
281
+
282
+ constructor(value) {
283
+ this.value = value;
284
+ }
285
+ }
286
+
287
+ class UserStatus {
288
+ static Active = new UserStatus('active');
289
+
290
+ static Deactivated = new UserStatus('deactivated');
291
+
292
+ static Fraud = new UserStatus('fraud');
293
+
294
+ static PldBlocked = new UserStatus('pld_blocked');
295
+
296
+ constructor(value) {
297
+ this.value = value;
298
+ }
299
+ }
300
+
301
+ class VerificationType {
302
+ static Phone = new VerificationType('phone');
303
+
304
+ static Email = new VerificationType('email');
305
+
306
+ constructor(value) {
307
+ this.value = value;
308
+ }
309
+ }
310
+
311
+ class WalletTransactionType {
312
+ static Deposit = new WalletTransactionType('deposit');
313
+
314
+ static Withdrawal = new WalletTransactionType('withdrawal');
315
+
316
+ constructor(value) {
317
+ this.value = value;
318
+ }
319
+ }
320
+
321
+ const dateToUTC = (date) => {
322
+ if (!date) return null;
323
+ const dateObj = new Date(date);
324
+ return new Date(dateObj.getTime());
325
+ };
326
+
327
+ const enumValueFromString = (enumValue, value) =>
328
+ Object.values(enumValue).find((enumV) => enumV.value === value);
329
+
330
+ export { CardFundingType as C, DepositNetwork as D, EntryType as E, FileFormat as F, KYCFileType as K, Phase as P, SavingCategory as S, TransactionStatus as T, UserStatus as U, VerificationType as V, WalletTransactionType as W, CardIssuer as a, CardStatus as b, CardType as c, dateToUTC as d, enumValueFromString as e, CardErrorType as f, CardTransactionType as g, CommissionType as h, ServiceProviderCategory as i, TransferNetwork as j, KYCStatus as k, TrackDataMethod as l };