@cuenca-mx/cuenca-js 0.0.1-dev.20 → 0.0.1-dev.23

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
@@ -61,7 +61,6 @@ To start using the library, the client must be configured with your credentials.
61
61
  | apiSecret | Secret for the API Key | `undefined` |
62
62
  | phase | Used to change the environment for the client (production, stage or sandbox) | `Phase.Sandbox` |
63
63
  | loginToken | Login Token, sets `X-Cuenca-LoginToken` on each request | `undefined` |
64
- | sessionId | Session Id, sets `X-Cuenca-SessionId` on each request | `undefined` |
65
64
  | useJwt | If `true`, it will create a JWT for authentification | `false` |
66
65
 
67
66
  ### Login
@@ -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 };
@@ -1,8 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var errors_index = require('./errors/index.cjs');
4
- var data = require('./data-9edbb2a0.cjs');
5
-
6
3
  class CardErrorType {
7
4
  static Blocked = new CardErrorType('blocked');
8
5
 
@@ -267,311 +264,47 @@ class WalletTransactionType {
267
264
  }
268
265
  }
269
266
 
270
- class PageSize {
271
- constructor(size) {
272
- this.maxSize = 100;
273
- this._ps = size;
274
- }
275
-
276
- get size() {
277
- return this._pageSize;
278
- }
279
-
280
- set _ps(value) {
281
- let validatedPageSize = this.maxSize;
282
- if (value && value > 0 && value <= this.maxSize) {
283
- validatedPageSize = value;
284
- }
285
- this._pageSize = validatedPageSize;
286
- }
287
- }
288
-
289
- class QueryParams {
290
- constructor({
291
- createdAfter,
292
- createdBefore,
293
- limit,
294
- pageSize,
295
- relatedTransaction,
296
- userId,
297
- count = false,
298
- }) {
299
- this.createdAfter = createdAfter;
300
- this.createdBefore = createdBefore;
301
- this._lmt = limit;
302
- this.relatedTransaction = relatedTransaction;
303
- this.userId = userId;
304
- this.count = count;
305
- this.pageSize = pageSize;
306
- }
307
-
308
- get limit() {
309
- return this._limit;
310
- }
311
-
312
- // Validator for limit
313
- set _lmt(value) {
314
- let validatedValue = null;
315
- if (value && value >= 0) {
316
- validatedValue = value;
317
- }
318
- this._limit = validatedValue;
319
- }
320
-
321
- toObject() {
322
- return {
323
- created_after: this.createdAfter,
324
- created_before: this.createdBefore,
325
- limit: this.limit,
326
- related_transaction: this.relatedTransaction,
327
- user_id: this.userId,
328
- page_size: this.pageSize && this.pageSize.size,
329
- };
330
- }
331
-
332
- toParams() {
333
- const helper = { ...this.toObject() };
334
- if (this.count) helper.count = 1;
335
- Object.keys(helper).forEach((k) => {
336
- if (helper[k] == null) delete helper[k];
337
- });
338
- return helper;
339
- }
267
+ const dateToUTC = (date) => {
268
+ if (!date) return null;
269
+ const dateObj = new Date(date);
270
+ return new Date(dateObj.getTime());
271
+ };
340
272
 
341
- toQueryString() {
342
- return new URLSearchParams(this.toParams()).toString();
343
- }
344
- }
273
+ const enumValueFromString = (enumValue, value) =>
274
+ Object.values(enumValue).find((enumV) => enumV.value === value);
345
275
 
346
- class AccountQuery extends QueryParams {
347
- constructor({ accountNumber, ...args }) {
348
- super(args);
349
- this.accountNumber = accountNumber;
276
+ class TOSAgreements {
277
+ constructor({ ip, location, version }) {
278
+ this.ip = ip;
279
+ this.location = location;
280
+ this.version = version;
350
281
  }
351
282
 
352
- toObject() {
353
- return Object.assign(super.toObject(), {
354
- account_number: this.accountNumber,
283
+ static fromObject = ({ ip, location, version }) =>
284
+ new TOSAgreements({
285
+ ip,
286
+ location,
287
+ version,
355
288
  });
356
- }
357
- }
358
-
359
- class ApiKeyQuery extends QueryParams {
360
- constructor({ active, ...args }) {
361
- super(args);
362
- this.active = active;
363
- }
364
-
365
- toObject() {
366
- return Object.assign(super.toObject(), {
367
- active: this.active,
368
- });
369
- }
370
- }
371
-
372
- class TransactionQuery extends QueryParams {
373
- constructor({ status, ...args }) {
374
- super(args);
375
- this.status = status;
376
- }
377
-
378
- toObject() {
379
- return Object.assign(super.toObject(), {
380
- status: this.status,
381
- });
382
- }
383
- }
384
-
385
- class DepositQuery extends TransactionQuery {
386
- constructor({ trackingKey, network, ...args }) {
387
- super(args);
388
- this.trackingKey = trackingKey;
389
- this.network = network;
390
- }
391
-
392
- toObject() {
393
- return Object.assign(super.toObject(), {
394
- tracking_key: this.trackingKey,
395
- network: this.network,
396
- });
397
- }
398
- }
399
-
400
- class TransferQuery extends TransactionQuery {
401
- constructor({
402
- accountNumber,
403
- idempotencyKey,
404
- trackingKey,
405
- network,
406
- ...args
407
- }) {
408
- super(args);
409
- this.accountNumber = accountNumber;
410
- this.idempotencyKey = idempotencyKey;
411
- this.trackingKey = trackingKey;
412
- this.network = network;
413
- }
414
-
415
- toObject() {
416
- return Object.assign(super.toObject(), {
417
- account_number: this.accountNumber,
418
- idempotency_key: this.idempotencyKey,
419
- tracking_key: this.trackingKey,
420
- network: this.network,
421
- });
422
- }
423
- }
424
-
425
- class BalanceEntryQuery extends QueryParams {
426
- constructor({
427
- fundingInstrumentUri,
428
- count = false,
429
- walletId = 'default',
430
- ...args
431
- }) {
432
- super(args);
433
- this.fundingInstrumentUri = fundingInstrumentUri;
434
- this.count = count;
435
- this.walletId = walletId;
436
- }
437
-
438
- toObject() {
439
- return Object.assign(super.toObject(), {
440
- wallet_id: this.walletId,
441
- funding_instrument_uri: this.fundingInstrumentUri,
442
- count: this.count,
443
- });
444
- }
445
- }
446
-
447
- class BillPaymentQuery extends QueryParams {
448
- constructor({ accountNumber, ...args }) {
449
- super(args);
450
- this.accountNumber = accountNumber;
451
- }
452
-
453
- toObject() {
454
- return Object.assign(super.toObject(), {
455
- account_number: this.accountNumber,
456
- });
457
- }
458
- }
459
-
460
- class CardTransactionQuery extends QueryParams {
461
- constructor({ cardUri, ...args }) {
462
- super(args);
463
- this.cardUri = cardUri;
464
- }
465
-
466
- toObject() {
467
- return Object.assign(super.toObject(), {
468
- card_uri: this.cardUri,
469
- });
470
- }
471
- }
472
-
473
- class CardsQuery extends QueryParams {
474
- constructor({ cardUri, count = false, ...args }) {
475
- super(args);
476
- this.cardUri = cardUri;
477
- this.count = count;
478
- }
479
-
480
- toObject() {
481
- return Object.assign(super.toObject(), {
482
- card_uri: this.cardUri,
483
- count: this.count,
484
- });
485
- }
486
- }
487
-
488
- class WalletTransactionQuery extends QueryParams {
489
- constructor({ walletUri, ...args }) {
490
- super(args);
491
- this.walletUri = walletUri;
492
- }
493
-
494
- toObject() {
495
- return Object.assign(super.toObject(), {
496
- wallet_uri: this.walletUri,
497
- });
498
- }
499
- }
500
-
501
- class WalletQuery extends QueryParams {
502
- constructor({ active, ...args }) {
503
- super(args);
504
- this.active = active;
505
- }
506
-
507
- toObject() {
508
- return Object.assign(super.toObject(), {
509
- active: this.active,
510
- });
511
- }
512
- }
513
-
514
- class StatementQuery extends QueryParams {
515
- constructor({ month, year, ...args }) {
516
- super(args);
517
- this.d = { month, year };
518
- }
519
-
520
- get month() {
521
- return this._date.month;
522
- }
523
-
524
- get year() {
525
- return this._date.year;
526
- }
527
-
528
- set d({ month, year }) {
529
- const now = data.dateToUTC(Date.now());
530
- now.setUTCDate(1);
531
- const date = data.dateToUTC(`${year}-${month}-01`);
532
- if (date.getTime() >= now.getTime()) {
533
- throw new errors_index.ValidationError(
534
- `${year}-${month} is not a valid year-month pair`,
535
- );
536
- }
537
- this._date = { month, year };
538
- }
539
-
540
- toObject() {
541
- return Object.assign(super.toObject(), {
542
- month: this.month,
543
- year: this.year,
544
- });
545
- }
546
289
  }
547
290
 
548
- exports.AccountQuery = AccountQuery;
549
- exports.ApiKeyQuery = ApiKeyQuery;
550
- exports.BalanceEntryQuery = BalanceEntryQuery;
551
- exports.BillPaymentQuery = BillPaymentQuery;
552
291
  exports.CardErrorType = CardErrorType;
553
292
  exports.CardFundingType = CardFundingType;
554
293
  exports.CardIssuer = CardIssuer;
555
294
  exports.CardStatus = CardStatus;
556
- exports.CardTransactionQuery = CardTransactionQuery;
557
295
  exports.CardTransactionType = CardTransactionType;
558
296
  exports.CardType = CardType;
559
- exports.CardsQuery = CardsQuery;
560
297
  exports.CommissionType = CommissionType;
561
298
  exports.DepositNetwork = DepositNetwork;
562
- exports.DepositQuery = DepositQuery;
563
299
  exports.EntryType = EntryType;
564
300
  exports.FileFormat = FileFormat;
565
- exports.PageSize = PageSize;
566
301
  exports.Phase = Phase;
567
- exports.QueryParams = QueryParams;
568
302
  exports.SavingCategory = SavingCategory;
569
303
  exports.ServiceProviderCategory = ServiceProviderCategory;
570
- exports.StatementQuery = StatementQuery;
304
+ exports.TOSAgreements = TOSAgreements;
571
305
  exports.TrackDataMethod = TrackDataMethod;
572
306
  exports.TransactionStatus = TransactionStatus;
573
307
  exports.TransferNetwork = TransferNetwork;
574
- exports.TransferQuery = TransferQuery;
575
- exports.WalletQuery = WalletQuery;
576
- exports.WalletTransactionQuery = WalletTransactionQuery;
577
308
  exports.WalletTransactionType = WalletTransactionType;
309
+ exports.dateToUTC = dateToUTC;
310
+ exports.enumValueFromString = enumValueFromString;