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

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.
@@ -3,22 +3,45 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var axios = require('axios');
6
- var errors_index = require('./errors/index.js');
7
- var jwt_index = require('./jwt/index.js');
8
- var queries = require('./queries-b8f29837.js');
9
- var data = require('./data-c53f1052.js');
10
- var walletTransactionRequest = require('./walletTransactionRequest-b588cc52.js');
6
+ var Buffer = require('buffer');
7
+ var errors_index = require('./errors/index.cjs');
8
+ var jwt_index = require('./jwt/index.cjs');
9
+ var data = require('./data-efb53250.cjs');
10
+ var identities = require('./identities-93faf1ed.cjs');
11
+ var walletTransactionRequest = require('./walletTransactionRequest-31f14989.cjs');
11
12
 
12
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
 
14
15
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
16
+ var Buffer__default = /*#__PURE__*/_interopDefaultLegacy(Buffer);
17
+
18
+ /* global window */
19
+
20
+ const isBrowser =
21
+ typeof window !== 'undefined' && typeof window.document !== 'undefined';
22
+
23
+ const isNode =
24
+ typeof process !== 'undefined' &&
25
+ Object.prototype.toString.call(process) === '[object process]';
26
+
27
+ const runtimeEnv = { isBrowser, isNode };
28
+
29
+ const name="@cuenca-mx/cuenca-js";const version="0.0.2-dev.1";const description="Cuenca client for JS";const main="./build/index.cjs";const module$1="./build/index.mjs";const browser="./build/umd/cuenca.umd.js";const files=["build/**/*"];const exports$1={".":{"import":"./build/index.mjs",require:"./build/index.cjs"},"./errors":{"import":"./build/errors/index.mjs",require:"./build/errors/index.cjs"},"./jwt":{"import":"./build/jwt/index.mjs",require:"./build/jwt/index.cjs"},"./requests":{"import":"./build/requests/index.mjs",require:"./build/requests/index.cjs"},"./types":{"import":"./build/types/index.mjs",require:"./build/types/index.cjs"}};const packageManager="yarn@3.0.2";const type="module";const repository={type:"git",url:"https://github.com/cuenca-mx/cuenca-js.git",directory:"packages/cuenca-js"};const keywords=["cuenca"];const license="MIT";const bugs={url:"https://github.com/cuenca-mx/cuenca-js/issues"};const homepage="https://cuenca.com";const scripts={build:"rm -rf build/ && yarn rollup --config",test:"yarn node --experimental-vm-modules $(yarn bin jest)",publish:"yarn build && yarn npm publish"};const devDependencies={"@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.1",jest:"^27.4.5",rollup:"^2.61.1","rollup-plugin-terser":"^7.0.2"};const dependencies={axios:"^0.24.0",buffer:"^6.0.3","form-data":"^4.0.0"};var pkg = {name:name,version:version,description:description,main:main,module:module$1,browser:browser,files:files,exports:exports$1,packageManager:packageManager,type:type,repository:repository,keywords:keywords,license:license,bugs:bugs,homepage:homepage,scripts:scripts,devDependencies:devDependencies,dependencies:dependencies};
15
30
 
16
31
  class Client {
17
- constructor({ apiKey, apiSecret, phase = queries.Phase.Sandbox } = {}) {
32
+ constructor({
33
+ apiKey,
34
+ apiSecret,
35
+ language = 'en',
36
+ phase = data.Phase.Sandbox,
37
+ } = {}) {
18
38
  this.phase = phase;
19
39
  this.basicAuth = { apiKey, apiSecret };
20
40
  this.jwtToken = null;
21
- this._session = axios__default["default"].create();
41
+ this._session = axios__default["default"].create({
42
+ headers: { 'Accept-Language': language },
43
+ timeout: 45000,
44
+ });
22
45
  }
23
46
 
24
47
  get session() {
@@ -32,8 +55,9 @@ class Client {
32
55
  get authHeader() {
33
56
  const { apiKey, apiSecret } = this.basicAuth;
34
57
  if (!apiKey || !apiSecret) return '';
35
- return `Basic ${Buffer.from(
36
- Buffer.from(`${apiKey}:${apiSecret}`).toString('utf-8'),
58
+ return `Basic ${Buffer__default["default"].Buffer.from(
59
+ `${apiKey}:${apiSecret}`,
60
+ 'utf-8',
37
61
  ).toString('base64')}`;
38
62
  }
39
63
 
@@ -79,7 +103,14 @@ class Client {
79
103
  };
80
104
  }
81
105
 
82
- async configure({ apiKey, apiSecret, loginToken, phase, useJwt = false }) {
106
+ async configure({
107
+ apiKey,
108
+ apiSecret,
109
+ loginToken,
110
+ phase,
111
+ sessionId,
112
+ useJwt = false,
113
+ }) {
83
114
  this.basicAuth = {
84
115
  apiKey: apiKey || this.basicAuth.apiKey,
85
116
  apiSecret: apiSecret || this.basicAuth.apiSecret,
@@ -92,14 +123,18 @@ class Client {
92
123
  if (loginToken) {
93
124
  this.addHeadersToRequest({ 'X-Cuenca-LoginToken': loginToken });
94
125
  }
126
+
127
+ if (sessionId) {
128
+ this.addHeadersToRequest({ 'X-Cuenca-SessionId': sessionId });
129
+ }
95
130
  }
96
131
 
97
132
  async get({ endpoint, format, params }) {
98
133
  return this.request({ endpoint, format, params });
99
134
  }
100
135
 
101
- async post({ endpoint, data }) {
102
- return this.request({ method: 'POST', endpoint, data });
136
+ async post({ endpoint, data, multipart }) {
137
+ return this.request({ method: 'POST', endpoint, data, multipart });
103
138
  }
104
139
 
105
140
  async patch({ endpoint, data }) {
@@ -112,17 +147,35 @@ class Client {
112
147
 
113
148
  async request({
114
149
  endpoint,
115
- data = null,
116
- format = queries.FileFormat.Json,
150
+ data: data$1 = null,
151
+ format = data.FileFormat.Json,
117
152
  method = 'GET',
153
+ multipart = false,
118
154
  params = null,
119
155
  }) {
120
- const headers = {
121
- Authorization: this.authHeader,
122
- 'X-User-Agent': `cuenca-js/0.0.1`, // TODO: Change for client version
123
- 'Content-Type': 'application/json',
124
- Accept: `application/${format.value}`,
125
- };
156
+ console.log('multipart :', multipart);
157
+ console.log('endPoint', endpoint);
158
+ let headers;
159
+ if (multipart) {
160
+ headers = data$1.getHeaders();
161
+ } else {
162
+ headers = {
163
+ 'Content-Type': 'application/json',
164
+ Accept: `application/${format.value}`,
165
+ };
166
+ }
167
+
168
+ if (this.authHeader) {
169
+ headers.Authorization = this.authHeader;
170
+ }
171
+
172
+ if (runtimeEnv.isNode) {
173
+ headers['User-Agent'] = `cuenca-js/${pkg.version}`;
174
+ } else if (runtimeEnv.isBrowser) {
175
+ // Cannot set User-Agent header on browsers
176
+ // https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
177
+ headers['X-User-Agent'] = `cuenca-js/${pkg.version}`;
178
+ }
126
179
 
127
180
  if (this.jwtToken) {
128
181
  if (this.jwtToken.isExpired) {
@@ -130,10 +183,11 @@ class Client {
130
183
  }
131
184
  headers['X-Cuenca-Token'] = this.jwtToken.token;
132
185
  }
133
-
186
+ console.log('headers :', headers);
134
187
  const headersInterceptor = this.addHeadersToRequest(headers);
188
+ console.log('headersInterceptor :', headersInterceptor);
135
189
 
136
- const modifiedData = data;
190
+ const modifiedData = data$1;
137
191
  if (modifiedData) {
138
192
  Object.keys(modifiedData).forEach((k) => {
139
193
  if (modifiedData[k] instanceof Date) {
@@ -142,6 +196,8 @@ class Client {
142
196
  });
143
197
  }
144
198
 
199
+ console.log('modifiedData :', modifiedData);
200
+
145
201
  const configInterceptor = this.addConfigToRequest({
146
202
  method,
147
203
  params,
@@ -255,7 +311,7 @@ class BalanceEntry {
255
311
  this.amount = amount;
256
312
  this.createdAt = data.dateToUTC(createdAt);
257
313
  this.descriptor = descriptor;
258
- this.entryType = data.enumValueFromString(queries.EntryType, entryType);
314
+ this.entryType = data.enumValueFromString(data.EntryType, entryType);
259
315
  this.fundingInstrumentUri = fundingInstrumentUri;
260
316
  this.id = id;
261
317
  this.name = name;
@@ -282,7 +338,7 @@ class Transaction {
282
338
  this.amount = amount;
283
339
  this.createdAt = data.dateToUTC(createdAt);
284
340
  this.descriptor = descriptor;
285
- this.status = data.enumValueFromString(queries.TransactionStatus, status);
341
+ this.status = data.enumValueFromString(data.TransactionStatus, status);
286
342
  this.userId = userId;
287
343
  }
288
344
  }
@@ -298,7 +354,13 @@ class BillPayment extends Transaction {
298
354
  status,
299
355
  userId,
300
356
  }) {
301
- super({ amount, createdAt, descriptor, status, userId });
357
+ super({
358
+ amount,
359
+ createdAt,
360
+ descriptor,
361
+ status,
362
+ userId,
363
+ });
302
364
  this.accountNumber = accountNumber;
303
365
  this.id = id;
304
366
  this.providerUri = providerUri;
@@ -337,13 +399,13 @@ class Card {
337
399
  this.cvv2 = cvv2;
338
400
  this.expMonth = expMonth;
339
401
  this.expYear = expYear;
340
- this.fundingType = data.enumValueFromString(queries.CardFundingType, fundingType);
402
+ this.fundingType = data.enumValueFromString(data.CardFundingType, fundingType);
341
403
  this.id = id;
342
- this.issuer = data.enumValueFromString(queries.CardIssuer, issuer);
404
+ this.issuer = data.enumValueFromString(data.CardIssuer, issuer);
343
405
  this.number = number;
344
406
  this.pin = pin;
345
- this.status = data.enumValueFromString(queries.CardStatus, status);
346
- this.type = data.enumValueFromString(queries.CardType, type);
407
+ this.status = data.enumValueFromString(data.CardStatus, status);
408
+ this.type = data.enumValueFromString(data.CardType, type);
347
409
  this.updatedAt = data.dateToUTC(updatedAt);
348
410
  this.userId = userId;
349
411
  }
@@ -412,15 +474,21 @@ class CardTransaction extends Transaction {
412
474
  type,
413
475
  userId,
414
476
  }) {
415
- super({ amount, createdAt, descriptor, status, userId });
416
- this.cardErrorType = data.enumValueFromString(queries.CardErrorType, cardErrorType);
477
+ super({
478
+ amount,
479
+ createdAt,
480
+ descriptor,
481
+ status,
482
+ userId,
483
+ });
484
+ this.cardErrorType = data.enumValueFromString(data.CardErrorType, cardErrorType);
417
485
  this.cardLastFour = cardLastFour;
418
- this.cardType = data.enumValueFromString(queries.CardType, cardType);
486
+ this.cardType = data.enumValueFromString(data.CardType, cardType);
419
487
  this.cardUri = cardUri;
420
488
  this.metadata = metadata;
421
489
  this.network = network;
422
490
  this.relatedCardTransactionsUris = relatedCardTransactionsUris;
423
- this.type = data.enumValueFromString(queries.CardTransactionType, type);
491
+ this.type = data.enumValueFromString(data.CardTransactionType, type);
424
492
  }
425
493
 
426
494
  static fromObject = ({
@@ -464,8 +532,8 @@ class CardValidation {
464
532
  isValidPinBlock,
465
533
  userId,
466
534
  }) {
467
- this.cardStatus = data.enumValueFromString(queries.CardStatus, cardStatus);
468
- this.cardType = data.enumValueFromString(queries.CardType, cardType);
535
+ this.cardStatus = data.enumValueFromString(data.CardStatus, cardStatus);
536
+ this.cardType = data.enumValueFromString(data.CardType, cardType);
469
537
  this.cardUri = cardUri;
470
538
  this.createdAt = data.dateToUTC(createdAt);
471
539
  this.isExpired = isExpired;
@@ -495,7 +563,7 @@ class CardValidation {
495
563
  });
496
564
 
497
565
  get isActive() {
498
- return this.cardStatus === queries.CardStatus.Active;
566
+ return this.cardStatus === data.CardStatus.Active;
499
567
  }
500
568
  }
501
569
 
@@ -509,9 +577,15 @@ class Commission extends Transaction {
509
577
  type,
510
578
  userId,
511
579
  }) {
512
- super({ amount, createdAt, descriptor, status, userId });
580
+ super({
581
+ amount,
582
+ createdAt,
583
+ descriptor,
584
+ status,
585
+ userId,
586
+ });
513
587
  this.relatedTransactionUri = relatedTransactionUri;
514
- this.type = data.enumValueFromString(queries.CommissionType, type);
588
+ this.type = data.enumValueFromString(data.CommissionType, type);
515
589
  }
516
590
 
517
591
  static fromObject = ({ amount, descriptor, status, type, ...obj }) =>
@@ -538,9 +612,15 @@ class Deposit extends Transaction {
538
612
  trackingKey,
539
613
  userId,
540
614
  }) {
541
- super({ amount, createdAt, descriptor, status, userId });
615
+ super({
616
+ amount,
617
+ createdAt,
618
+ descriptor,
619
+ status,
620
+ userId,
621
+ });
542
622
  this.id = id;
543
- this.network = data.enumValueFromString(queries.DepositNetwork, network);
623
+ this.network = data.enumValueFromString(data.DepositNetwork, network);
544
624
  this.sourceUri = sourceUri;
545
625
  this.trackingKey = trackingKey;
546
626
  }
@@ -559,6 +639,96 @@ class Deposit extends Transaction {
559
639
  });
560
640
  }
561
641
 
642
+ class Identities {
643
+ constructor({
644
+ address,
645
+ blacklistValidationStatus,
646
+ countryOfBirth,
647
+ createdAt,
648
+ curp,
649
+ dateOfBirth,
650
+ extension,
651
+ firstSurname,
652
+ gender,
653
+ govId,
654
+ id,
655
+ names,
656
+ nationality,
657
+ proofOfAddress,
658
+ proofOfLife,
659
+ rfc,
660
+ rfcDocument,
661
+ rfcFile,
662
+ secondSurname,
663
+ stateOfBirth,
664
+ status,
665
+ tosAgreement,
666
+ userId,
667
+ }) {
668
+ this.address = address;
669
+ this.blacklistValidationStatus = blacklistValidationStatus;
670
+ this.countryOfBirth = countryOfBirth;
671
+ this.createdAt = createdAt;
672
+ this.curp = curp;
673
+ this.dateOfBirth = dateOfBirth;
674
+ this.extension = extension;
675
+ this.firstSurname = firstSurname;
676
+ this.gender = gender;
677
+ this.govId = govId;
678
+ this.id = id;
679
+ this.names = names;
680
+ this.nationality = nationality;
681
+ this.proofOfAddress = proofOfAddress;
682
+ this.proofOfLife = proofOfLife;
683
+ this.rfc = rfc;
684
+ this.rfcDocument = rfcDocument;
685
+ this.rfcFile = rfcFile;
686
+ this.secondSurname = secondSurname;
687
+ this.stateOfBirth = stateOfBirth;
688
+ this.status = status;
689
+ this.tosAgreement = tosAgreement;
690
+ this.userId = userId;
691
+ }
692
+
693
+ static fromObject = ({
694
+ address,
695
+ curp,
696
+ extension,
697
+ gender,
698
+ id,
699
+ names,
700
+ nationality,
701
+ rfc,
702
+ status,
703
+ ...obj
704
+ }) =>
705
+ new Identities({
706
+ address,
707
+ curp,
708
+ extension,
709
+ gender,
710
+ id,
711
+ names,
712
+ nationality,
713
+ rfc,
714
+ status,
715
+ blacklistValidationStatus: obj.blacklist_validation_status,
716
+ countryOfBirth: obj.country_of_birth,
717
+ createdAt: obj.created_at,
718
+ dateOfBirth: obj.date_of_birth,
719
+ firstSurname: obj.first_surname,
720
+ govId: obj.gov_id,
721
+ proofOfAddress: obj.proof_of_address,
722
+ proofOfLife: obj.proof_of_life,
723
+ rfcDocument: obj.rfc_document,
724
+ rfcFile: obj.rfc_file,
725
+ secondSurname: obj.second_surname,
726
+ stateOfBirth: obj.state_of_birth,
727
+ tosAgreement: obj.tos_agreement,
728
+ userId: obj.user_id,
729
+ });
730
+ }
731
+
562
732
  class LoginToken {
563
733
  constructor({ id }) {
564
734
  this.id = id;
@@ -591,8 +761,15 @@ class Saving extends Wallet {
591
761
  userId,
592
762
  updatedAt,
593
763
  }) {
594
- super({ balance, createdAt, deactivatedAt, id, userId, updatedAt });
595
- this.category = data.enumValueFromString(queries.SavingCategory, category);
764
+ super({
765
+ balance,
766
+ createdAt,
767
+ deactivatedAt,
768
+ id,
769
+ userId,
770
+ updatedAt,
771
+ });
772
+ this.category = data.enumValueFromString(data.SavingCategory, category);
596
773
  this.goalAmount = goalAmount;
597
774
  this.goalDate = data.dateToUTC(goalDate);
598
775
  this.name = name;
@@ -616,7 +793,7 @@ class Saving extends Wallet {
616
793
  const categoriesFromString = (categoriesList) => {
617
794
  if (categoriesList == null) return [];
618
795
  return categoriesList.map((category) =>
619
- data.enumValueFromString(queries.ServiceProviderCategory, category),
796
+ data.enumValueFromString(data.ServiceProviderCategory, category),
620
797
  );
621
798
  };
622
799
 
@@ -670,12 +847,18 @@ class Transfer extends Transaction {
670
847
  updatedAt,
671
848
  userId,
672
849
  }) {
673
- super({ amount, createdAt, descriptor, status, userId });
850
+ super({
851
+ amount,
852
+ createdAt,
853
+ descriptor,
854
+ status,
855
+ userId,
856
+ });
674
857
  this.accountNumber = accountNumber;
675
858
  this.destinationUri = destinationUri;
676
859
  this.id = id;
677
860
  this.idempotencyKey = idempotencyKey;
678
- this.network = data.enumValueFromString(queries.TransferNetwork, network);
861
+ this.network = data.enumValueFromString(data.TransferNetwork, network);
679
862
  this.recipientName = recipientName;
680
863
  this.trackingKey = trackingKey;
681
864
  this.updatedAt = data.dateToUTC(updatedAt);
@@ -699,6 +882,82 @@ class Transfer extends Transaction {
699
882
  });
700
883
  }
701
884
 
885
+ class User {
886
+ constructor({
887
+ emailAddress,
888
+ govtId,
889
+ identityUri,
890
+ level,
891
+ phoneNumber,
892
+ proofOfAddress,
893
+ proofOfLife,
894
+ status,
895
+ termsOfService,
896
+ verificationId,
897
+ }) {
898
+ this.emailAddress = emailAddress;
899
+ this.govstIds = govtId;
900
+ this.identityUri = identityUri;
901
+ this.level = level;
902
+ this.phoneNumber = phoneNumber;
903
+ this.addressProofs = proofOfAddress;
904
+ this.lifeProofs = proofOfLife;
905
+ this.status = data.enumValueFromString(data.UserStatus, status);
906
+ this.terms = termsOfService;
907
+ this.verificationId = verificationId;
908
+ }
909
+
910
+ get proofOfAddress() {
911
+ return this._proofOfAddress;
912
+ }
913
+
914
+ set addressProofs(value) {
915
+ if (!value) return;
916
+ this._proofOfAddress = identities.KYCFile.fromObject(value);
917
+ }
918
+
919
+ get proofOfLife() {
920
+ return this._proofOfLife;
921
+ }
922
+
923
+ set lifeProofs(value) {
924
+ if (!value) return;
925
+ this._proofOfLife = identities.KYCFile.fromObject(value);
926
+ }
927
+
928
+ get govtId() {
929
+ return this._govtId;
930
+ }
931
+
932
+ set govstIds(value) {
933
+ if (!value) return;
934
+ this._govtId = identities.KYCFile.fromObject(value);
935
+ }
936
+
937
+ get termsOfService() {
938
+ return this._termsOfService;
939
+ }
940
+
941
+ set terms(value) {
942
+ if (!value) return;
943
+ this._termsOfService = identities.TOSAgreements.fromObject(value);
944
+ }
945
+
946
+ static fromObject = ({ level, status, ...obj }) =>
947
+ new User({
948
+ level,
949
+ status,
950
+ govtId: obj.govt_id,
951
+ identityUri: obj.identity_uri,
952
+ emailAddress: obj.email_address,
953
+ phoneNumber: obj.phone_number,
954
+ proofOfAddress: obj.proof_of_address,
955
+ proofOfLife: obj.proof_of_life,
956
+ termsOfService: obj.terms_of_service,
957
+ verificationId: obj.verification_id,
958
+ });
959
+ }
960
+
702
961
  class UserCredential {
703
962
  constructor({ createdAt, id, isActive, updatedAt }) {
704
963
  this.createdAt = data.dateToUTC(createdAt);
@@ -731,6 +990,27 @@ class UserLogin {
731
990
  });
732
991
  }
733
992
 
993
+ class Verification {
994
+ constructor({ createdAt, id, platformId, recipient, type, updatedAt }) {
995
+ this.createdAt = data.dateToUTC(createdAt);
996
+ this.id = id;
997
+ this.platformId = platformId;
998
+ this.recipient = recipient;
999
+ this.type = data.enumValueFromString(data.VerificationType, type);
1000
+ this.updatedAt = data.dateToUTC(updatedAt);
1001
+ }
1002
+
1003
+ static fromObject = ({ id, recipient, type, ...obj }) =>
1004
+ new Verification({
1005
+ id,
1006
+ recipient,
1007
+ type,
1008
+ createdAt: obj.created_at,
1009
+ platformId: obj.platform_id,
1010
+ updatedAt: obj.updated_at,
1011
+ });
1012
+ }
1013
+
734
1014
  class WalletTransaction extends Transaction {
735
1015
  constructor({
736
1016
  amount,
@@ -742,10 +1022,16 @@ class WalletTransaction extends Transaction {
742
1022
  userId,
743
1023
  walletUri,
744
1024
  }) {
745
- super({ amount, createdAt, descriptor, status, userId });
1025
+ super({
1026
+ amount,
1027
+ createdAt,
1028
+ descriptor,
1029
+ status,
1030
+ userId,
1031
+ });
746
1032
  this.id = id;
747
1033
  this.transactionType = data.enumValueFromString(
748
- queries.WalletTransactionType,
1034
+ data.WalletTransactionType,
749
1035
  transactionType,
750
1036
  );
751
1037
  this.walletUri = walletUri;
@@ -781,12 +1067,18 @@ class WhatsAppTransfer extends Transaction {
781
1067
  updatedAt,
782
1068
  userId,
783
1069
  }) {
784
- super({ amount, createdAt, descriptor, status, userId });
1070
+ super({
1071
+ amount,
1072
+ createdAt,
1073
+ descriptor,
1074
+ status,
1075
+ userId,
1076
+ });
785
1077
  this.claimUrl = claimUrl;
786
1078
  this.destinationUri = destinationUri;
787
1079
  this.id = id;
788
1080
  this.expiresAt = data.dateToUTC(expiresAt);
789
- this.network = data.enumValueFromString(queries.TransferNetwork, network);
1081
+ this.network = data.enumValueFromString(data.TransferNetwork, network);
790
1082
  this.phoneNumber = phoneNumber;
791
1083
  this.recipientName = recipientName;
792
1084
  this.trackingKey = trackingKey;
@@ -837,13 +1129,16 @@ const getModelFromPath = (path, obj) => {
837
1129
  card_validations: () => CardValidation.fromObject(obj),
838
1130
  commissions: () => Commission.fromObject(obj),
839
1131
  deposits: () => Deposit.fromObject(obj),
1132
+ identities: () => Identities.fromObject(obj),
840
1133
  login_tokens: () => LoginToken.fromObject(obj),
841
1134
  savings: () => Saving.fromObject(obj),
842
1135
  service_providers: () => ServiceProvider.fromObject(obj),
843
1136
  statements: () => Statement.fromObject(obj),
844
1137
  transfers: () => Transfer.fromObject(obj),
1138
+ users: () => User.fromObject(obj),
845
1139
  user_credentials: () => UserCredential.fromObject(obj),
846
1140
  user_logins: () => UserLogin.fromObject(obj),
1141
+ verifications: () => Verification.fromObject(obj),
847
1142
  wallet_transactions: () => WalletTransaction.fromObject(obj),
848
1143
  whatsapp_transfers: () => WhatsAppTransfer.fromObject(obj),
849
1144
  };
@@ -900,6 +1195,19 @@ const Updateable = (SuperClass) =>
900
1195
  }
901
1196
  };
902
1197
 
1198
+ const Uploadable = (SuperClass) =>
1199
+ class Uploadable extends SuperClass {
1200
+ async _upload(id, data) {
1201
+ const response = await this.client.post({
1202
+ endpoint: `/${this.path}`,
1203
+ data,
1204
+ multipart: true,
1205
+ });
1206
+ const model = getModelFromPath(this.path, response);
1207
+ return model;
1208
+ }
1209
+ };
1210
+
903
1211
  const Deactivable = (SuperClass) =>
904
1212
  class Deactivable extends SuperClass {
905
1213
  async _deactivate(id, data) {
@@ -981,7 +1289,7 @@ const Queryable = (SuperClass) =>
981
1289
 
982
1290
  class AccountResource extends mix(Resource).with(Queryable, Retrievable) {
983
1291
  constructor(client) {
984
- super('accounts', queries.AccountQuery, client);
1292
+ super('accounts', identities.AccountQuery, client);
985
1293
  }
986
1294
  }
987
1295
 
@@ -993,7 +1301,7 @@ class ApiKeyResource extends mix(Resource).with(
993
1301
  Updateable,
994
1302
  ) {
995
1303
  constructor(client) {
996
- super('api_keys', queries.ApiKeyQuery, client);
1304
+ super('api_keys', identities.ApiKeyQuery, client);
997
1305
  }
998
1306
 
999
1307
  async create() {
@@ -1047,7 +1355,7 @@ class ArpcResource extends mix(Resource).with(Creatable) {
1047
1355
 
1048
1356
  class BalanceEntryResource extends mix(Resource).with(Queryable, Retrievable) {
1049
1357
  constructor(client) {
1050
- super('balance_entries', queries.BalanceEntryQuery, client);
1358
+ super('balance_entries', identities.BalanceEntryQuery, client);
1051
1359
  }
1052
1360
 
1053
1361
  async relatedTransaction(relatedTransactionUri) {
@@ -1073,7 +1381,7 @@ class BalanceEntryResource extends mix(Resource).with(Queryable, Retrievable) {
1073
1381
 
1074
1382
  class BillPaymentResource extends mix(Resource).with(Queryable, Retrievable) {
1075
1383
  constructor(client) {
1076
- super('bill_payments', queries.BillPaymentQuery, client);
1384
+ super('bill_payments', identities.BillPaymentQuery, client);
1077
1385
  }
1078
1386
 
1079
1387
  async serviceProvider(providerUri) {
@@ -1111,7 +1419,7 @@ class CardResource extends mix(Resource).with(
1111
1419
  Updateable,
1112
1420
  ) {
1113
1421
  constructor(client) {
1114
- super('cards', queries.CardsQuery, client);
1422
+ super('cards', identities.CardsQuery, client);
1115
1423
  }
1116
1424
 
1117
1425
  async create(userId, issuer, fundingType) {
@@ -1137,7 +1445,7 @@ class CardTransactionResource extends mix(Resource).with(
1137
1445
  Retrievable,
1138
1446
  ) {
1139
1447
  constructor(client) {
1140
- super('card_transactions', queries.CardTransactionQuery, client);
1448
+ super('card_transactions', identities.CardTransactionQuery, client);
1141
1449
  }
1142
1450
 
1143
1451
  async relatedCard(relatedCardUri) {
@@ -1189,7 +1497,7 @@ class CardValidationResource extends mix(Resource).with(Creatable) {
1189
1497
 
1190
1498
  class CommissionResource extends mix(Resource).with(Queryable, Retrievable) {
1191
1499
  constructor(client) {
1192
- super('commissions', queries.QueryParams, client);
1500
+ super('commissions', identities.QueryParams, client);
1193
1501
  }
1194
1502
 
1195
1503
  async relatedTransaction(relatedTransactionUri) {
@@ -1203,7 +1511,7 @@ class CommissionResource extends mix(Resource).with(Queryable, Retrievable) {
1203
1511
 
1204
1512
  class DepositResource extends mix(Resource).with(Queryable, Retrievable) {
1205
1513
  constructor(client) {
1206
- super('deposits', queries.DepositQuery, client);
1514
+ super('deposits', identities.DepositQuery, client);
1207
1515
  }
1208
1516
 
1209
1517
  async source(sourceUri) {
@@ -1212,6 +1520,19 @@ class DepositResource extends mix(Resource).with(Queryable, Retrievable) {
1212
1520
  }
1213
1521
  }
1214
1522
 
1523
+ class IdentitiesResource extends mix(Resource).with(Uploadable) {
1524
+ constructor(client) {
1525
+ super('identities', Object, client);
1526
+ }
1527
+
1528
+ async upload({ extension, id, rfcFile, userId = 'me' }) {
1529
+ const request = new walletTransactionRequest.IdentitiesUploadRequest({ extension, rfcFile, userId });
1530
+ const identities = await this._upload(id, request.toFormData());
1531
+ // const identities = await this._update(identityId, request.toObject());
1532
+ return identities;
1533
+ }
1534
+ }
1535
+
1215
1536
  class LoginTokenResource extends mix(Resource).with(Creatable) {
1216
1537
  constructor(client) {
1217
1538
  super('login_tokens', Object, client);
@@ -1231,7 +1552,7 @@ class SavingResource extends mix(Resource).with(
1231
1552
  Updateable,
1232
1553
  ) {
1233
1554
  constructor(client) {
1234
- super('savings', queries.WalletQuery, client);
1555
+ super('savings', identities.WalletQuery, client);
1235
1556
  }
1236
1557
 
1237
1558
  async create(category, goalAmount, goalDate, name) {
@@ -1257,22 +1578,22 @@ class ServiceProviderResource extends mix(Resource).with(
1257
1578
  Retrievable,
1258
1579
  ) {
1259
1580
  constructor(client) {
1260
- super('service_providers', queries.QueryParams, client);
1581
+ super('service_providers', identities.QueryParams, client);
1261
1582
  }
1262
1583
  }
1263
1584
 
1264
1585
  class StatementResource extends mix(Resource).with(Downlodable, Queryable) {
1265
1586
  constructor(client) {
1266
- super('statements', queries.StatementQuery, client);
1587
+ super('statements', identities.StatementQuery, client);
1267
1588
  }
1268
1589
 
1269
1590
  async pdf(id) {
1270
- const byteString = await this._download(id, queries.FileFormat.Pdf);
1591
+ const byteString = await this._download(id, data.FileFormat.Pdf);
1271
1592
  return byteString;
1272
1593
  }
1273
1594
 
1274
1595
  async xml(id) {
1275
- const byteString = await this._download(id, queries.FileFormat.Xml);
1596
+ const byteString = await this._download(id, data.FileFormat.Xml);
1276
1597
  return byteString;
1277
1598
  }
1278
1599
  }
@@ -1283,7 +1604,7 @@ class TransferResource extends mix(Resource).with(
1283
1604
  Retrievable,
1284
1605
  ) {
1285
1606
  constructor(client) {
1286
- super('transfers', queries.TransferQuery, client);
1607
+ super('transfers', identities.TransferQuery, client);
1287
1608
  }
1288
1609
 
1289
1610
  async destination(destinationUri) {
@@ -1403,13 +1724,47 @@ class UserLoginResource extends mix(Resource).with(Creatable, Deactivable) {
1403
1724
  }
1404
1725
  }
1405
1726
 
1727
+ class UserResourse extends mix(Resource).with(
1728
+ Queryable,
1729
+ Updateable,
1730
+ Retrievable,
1731
+ ) {
1732
+ constructor(client) {
1733
+ super('users', identities.UserQuery, client);
1734
+ }
1735
+
1736
+ async update({ userId = 'me', ...req }) {
1737
+ const request = new walletTransactionRequest.UserUpdateRequest(req);
1738
+ const user = await this._update(userId, request.toCleanObject());
1739
+ return user;
1740
+ }
1741
+ }
1742
+
1743
+ class VerificationResourse extends mix(Resource).with(Creatable, Updateable) {
1744
+ constructor(client) {
1745
+ super('verifications', Object, client);
1746
+ }
1747
+
1748
+ async create({ platformId, recipient, type }) {
1749
+ const request = new walletTransactionRequest.VerificationRequest({ platformId, recipient, type });
1750
+ const verification = await this._create(request.toObject());
1751
+ return verification;
1752
+ }
1753
+
1754
+ async update({ code, id }) {
1755
+ const request = new walletTransactionRequest.VerificationAttemptRequest({ code });
1756
+ const verification = await this._update(id, request.toObject());
1757
+ return verification;
1758
+ }
1759
+ }
1760
+
1406
1761
  class WalletTransactionsResource extends mix(Resource).with(
1407
1762
  Creatable,
1408
1763
  Queryable,
1409
1764
  Retrievable,
1410
1765
  ) {
1411
1766
  constructor(client) {
1412
- super('wallet_transactions', queries.WalletTransactionQuery, client);
1767
+ super('wallet_transactions', identities.WalletTransactionQuery, client);
1413
1768
  }
1414
1769
 
1415
1770
  async create(amount, transactionType, walletUri) {
@@ -1436,7 +1791,7 @@ class WhatsAppTransferResource extends mix(Resource).with(
1436
1791
  Retrievable,
1437
1792
  ) {
1438
1793
  constructor(client) {
1439
- super('whatsapp_transfers', queries.QueryParams, client);
1794
+ super('whatsapp_transfers', identities.QueryParams, client);
1440
1795
  }
1441
1796
 
1442
1797
  async accountDestination(destinationUri) {
@@ -1449,8 +1804,13 @@ class WhatsAppTransferResource extends mix(Resource).with(
1449
1804
  }
1450
1805
 
1451
1806
  class Cuenca {
1452
- constructor(apiKey, apiSecret, phase = queries.Phase.Sandbox) {
1453
- this.client = new Client({ apiKey, apiSecret, phase });
1807
+ constructor({
1808
+ apiKey,
1809
+ apiSecret,
1810
+ language = 'en',
1811
+ phase = data.Phase.Sandbox,
1812
+ } = {}) {
1813
+ this.client = new Client({ apiKey, apiSecret, language, phase });
1454
1814
  this.withClient(this.client);
1455
1815
  }
1456
1816
 
@@ -1465,6 +1825,7 @@ class Cuenca {
1465
1825
  this.cardValidations = new CardValidationResource(client);
1466
1826
  this.commissions = new CommissionResource(client);
1467
1827
  this.deposits = new DepositResource(client);
1828
+ this.identities = new IdentitiesResource(client);
1468
1829
  this.loginTokens = new LoginTokenResource(client);
1469
1830
  this.savings = new SavingResource(client);
1470
1831
  this.serviceProviders = new ServiceProviderResource(client);
@@ -1472,47 +1833,11 @@ class Cuenca {
1472
1833
  this.transfers = new TransferResource(client);
1473
1834
  this.userCredentials = new UserCredentialResource(client);
1474
1835
  this.userLogins = new UserLoginResource(client);
1836
+ this.users = new UserResourse(client);
1837
+ this.verifications = new VerificationResourse(client);
1475
1838
  this.walletTransactions = new WalletTransactionsResource(client);
1476
1839
  this.whatsAppTransfers = new WhatsAppTransferResource(client);
1477
1840
  }
1478
1841
  }
1479
1842
 
1480
- exports.CuencaException = errors_index.CuencaException;
1481
- exports.CuencaResponseException = errors_index.CuencaResponseException;
1482
- exports.InvalidPassword = errors_index.InvalidPassword;
1483
- exports.MalformedJwtToken = errors_index.MalformedJwtToken;
1484
- exports.MultipleResultsFound = errors_index.MultipleResultsFound;
1485
- exports.NoResultFound = errors_index.NoResultFound;
1486
- exports.ValidationError = errors_index.ValidationError;
1487
- exports.Jwt = jwt_index.Jwt;
1488
- exports.AccountQuery = queries.AccountQuery;
1489
- exports.ApiKeyQuery = queries.ApiKeyQuery;
1490
- exports.BalanceEntryQuery = queries.BalanceEntryQuery;
1491
- exports.BillPaymentQuery = queries.BillPaymentQuery;
1492
- exports.CardErrorType = queries.CardErrorType;
1493
- exports.CardFundingType = queries.CardFundingType;
1494
- exports.CardIssuer = queries.CardIssuer;
1495
- exports.CardStatus = queries.CardStatus;
1496
- exports.CardTransactionQuery = queries.CardTransactionQuery;
1497
- exports.CardTransactionType = queries.CardTransactionType;
1498
- exports.CardType = queries.CardType;
1499
- exports.CardsQuery = queries.CardsQuery;
1500
- exports.CommissionType = queries.CommissionType;
1501
- exports.DepositNetwork = queries.DepositNetwork;
1502
- exports.DepositQuery = queries.DepositQuery;
1503
- exports.EntryType = queries.EntryType;
1504
- exports.FileFormat = queries.FileFormat;
1505
- exports.PageSize = queries.PageSize;
1506
- exports.Phase = queries.Phase;
1507
- exports.QueryParams = queries.QueryParams;
1508
- exports.SavingCategory = queries.SavingCategory;
1509
- exports.ServiceProviderCategory = queries.ServiceProviderCategory;
1510
- exports.StatementQuery = queries.StatementQuery;
1511
- exports.TrackDataMethod = queries.TrackDataMethod;
1512
- exports.TransactionStatus = queries.TransactionStatus;
1513
- exports.TransferNetwork = queries.TransferNetwork;
1514
- exports.TransferQuery = queries.TransferQuery;
1515
- exports.WalletQuery = queries.WalletQuery;
1516
- exports.WalletTransactionQuery = queries.WalletTransactionQuery;
1517
- exports.WalletTransactionType = queries.WalletTransactionType;
1518
1843
  exports.Cuenca = Cuenca;