@cuenca-mx/cuenca-js 0.0.5-dev.8 → 0.0.5-dev.9

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/build/index.cjs CHANGED
@@ -6,9 +6,10 @@ var axios = require('axios');
6
6
  var Buffer = require('buffer');
7
7
  var errors_index = require('./errors/index.cjs');
8
8
  var jwt_index = require('./jwt/index.cjs');
9
- var data = require('./data-f85a5287.cjs');
10
- var identities = require('./identities-ab85ec0b.cjs');
11
- var walletTransactionRequest = require('./walletTransactionRequest-8a816a1f.cjs');
9
+ var data = require('./data-d25afb50.cjs');
10
+ var identities = require('./identities-b472f1c7.cjs');
11
+ var walletTransactionRequest = require('./walletTransactionRequest-b7d18604.cjs');
12
+ require('module');
12
13
 
13
14
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
15
 
@@ -26,7 +27,7 @@ const isNode =
26
27
 
27
28
  const runtimeEnv = { isBrowser, isNode };
28
29
 
29
- const name="@cuenca-mx/cuenca-js";const version="0.0.5-dev.8";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"};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};
30
+ const name="@cuenca-mx/cuenca-js";const version="0.0.5-dev.9";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};
30
31
 
31
32
  class Client {
32
33
  constructor({
@@ -133,8 +134,8 @@ class Client {
133
134
  return this.request({ endpoint, format, params });
134
135
  }
135
136
 
136
- async post({ endpoint, data }) {
137
- return this.request({ method: 'POST', endpoint, data });
137
+ async post({ endpoint, data, multipart }) {
138
+ return this.request({ method: 'POST', endpoint, data, multipart });
138
139
  }
139
140
 
140
141
  async patch({ endpoint, data }) {
@@ -150,12 +151,18 @@ class Client {
150
151
  data: data$1 = null,
151
152
  format = data.FileFormat.Json,
152
153
  method = 'GET',
154
+ multipart = false,
153
155
  params = null,
154
156
  }) {
155
- const headers = {
156
- 'Content-Type': 'application/json',
157
- Accept: `application/${format.value}`,
158
- };
157
+ let headers;
158
+ if (multipart) {
159
+ headers = data$1.getHeaders();
160
+ } else {
161
+ headers = {
162
+ 'Content-Type': 'application/json',
163
+ Accept: `application/${format.value}`,
164
+ };
165
+ }
159
166
 
160
167
  if (this.authHeader) {
161
168
  headers.Authorization = this.authHeader;
@@ -175,11 +182,10 @@ class Client {
175
182
  }
176
183
  headers['X-Cuenca-Token'] = this.jwtToken.token;
177
184
  }
178
-
179
185
  const headersInterceptor = this.addHeadersToRequest(headers);
180
186
 
181
187
  const modifiedData = data$1;
182
- if (modifiedData) {
188
+ if (modifiedData && !multipart) {
183
189
  Object.keys(modifiedData).forEach((k) => {
184
190
  if (modifiedData[k] instanceof Date) {
185
191
  modifiedData[k] = modifiedData[k].toISOString();
@@ -368,64 +374,6 @@ class BillPayment extends Transaction {
368
374
  });
369
375
  }
370
376
 
371
- class BridgeAccount {
372
- constructor({
373
- id,
374
- names,
375
- firstSurname,
376
- secondSurname,
377
- dateOfBirth,
378
- countryOfBirth,
379
- rfc,
380
- curp,
381
- userId,
382
- gender,
383
- phoneNumber,
384
- emailAddress,
385
- govtId,
386
- proofOfAddress,
387
- proofOfLife,
388
- status,
389
- }) {
390
- this.id = id;
391
- this.emailAddress = emailAddress;
392
- this.govtId = govtId;
393
- this.names = names;
394
- this.firstSurname = firstSurname;
395
- this.secondSurname = secondSurname;
396
- this.dateOfBirth = dateOfBirth;
397
- this.countryOfBirth = countryOfBirth;
398
- this.rfc = rfc;
399
- this.curp = curp;
400
- this.userId = userId;
401
- this.gender = gender;
402
- this.phoneNumber = phoneNumber;
403
- this.addressProofs = proofOfAddress;
404
- this.lifeProofs = proofOfLife;
405
- this.status = data.enumValueFromString(data.BridgeAccountStatus, status);
406
- }
407
-
408
- static fromObject = ({ status, ...obj }) =>
409
- new BridgeAccount({
410
- id: obj.id,
411
- names: obj.names,
412
- firstSurname: obj.first_surname,
413
- secondSurname: obj.second_surname,
414
- dateOfBirth: obj.date_of_birth,
415
- countryOfBirth: obj.country_of_birth,
416
- rfc: obj.rfc,
417
- curp: obj.curp,
418
- userId: obj.user_id,
419
- gender: obj.gender,
420
- govtId: obj.govt_id,
421
- emailAddress: obj.email_address,
422
- phoneNumber: obj.phone_number,
423
- proofOfAddress: obj.proof_of_address,
424
- proofOfLife: obj.proof_of_life,
425
- status,
426
- });
427
- }
428
-
429
377
  class Card {
430
378
  constructor({
431
379
  createdAt,
@@ -686,6 +634,35 @@ class Deposit extends Transaction {
686
634
  });
687
635
  }
688
636
 
637
+ class File {
638
+ constructor({ extension, type, url, userId }) {
639
+ this.extension = extension;
640
+ this.type = data.enumValueFromString(data.KYCFileType, type);
641
+ this.url = url;
642
+ this.userId = userId;
643
+ }
644
+
645
+ static fromObject = ({ extension, type, url, ...obj }) =>
646
+ new File({ extension, type, url, userId: obj.user_id });
647
+ }
648
+
649
+ class KYCValidations {
650
+ constructor({ platformId, attemps, verificationId, filesUri }) {
651
+ this.attemps = attemps;
652
+ this.filesUri = filesUri;
653
+ this.platformId = platformId;
654
+ this.verificationId = verificationId;
655
+ }
656
+
657
+ static fromObject = ({ attemps, ...obj }) =>
658
+ new KYCValidations({
659
+ attemps,
660
+ filesUri: obj.files_uri,
661
+ platformId: obj.platform_id,
662
+ verificationId: obj.verification_id,
663
+ });
664
+ }
665
+
689
666
  class LoginToken {
690
667
  constructor({ id }) {
691
668
  this.id = id;
@@ -841,29 +818,73 @@ class Transfer extends Transaction {
841
818
 
842
819
  class User {
843
820
  constructor({
821
+ address,
822
+ blacklistValidationStatus,
823
+ clabe,
824
+ countryOfBirth,
825
+ createdAt,
826
+ curp,
827
+ dateOfBirth,
844
828
  emailAddress,
829
+ firstSurname,
830
+ gender,
845
831
  govtId,
832
+ id,
846
833
  level,
834
+ names,
835
+ nationality,
847
836
  phoneNumber,
848
837
  proofOfAddress,
849
838
  proofOfLife,
850
839
  requiredLevel,
840
+ rfc,
841
+ secondSurname,
842
+ stateOfBirth,
851
843
  status,
852
844
  termsOfService,
845
+ updatedAt,
853
846
  verificationId,
854
847
  }) {
848
+ this.add = address;
849
+ this.blacklistValidationStatus = data.enumValueFromString(
850
+ data.VerificationStatus,
851
+ blacklistValidationStatus,
852
+ );
853
+ this.clabe = clabe;
854
+ this.countryOfBirth = countryOfBirth;
855
+ this.createdAt = data.dateToUTC(createdAt);
856
+ this.curp = curp;
857
+ this.dateOfBirth = dateOfBirth;
855
858
  this.emailAddress = emailAddress;
859
+ this.firstSurname = firstSurname;
860
+ this.gender = gender;
856
861
  this.govstIds = govtId;
862
+ this.id = id;
857
863
  this.level = level;
864
+ this.names = names;
865
+ this.nationality = nationality;
858
866
  this.phoneNumber = phoneNumber;
859
867
  this.addressProofs = proofOfAddress;
860
868
  this.lifeProofs = proofOfLife;
861
869
  this.requiredLevel = requiredLevel;
870
+ this.rfc = rfc;
871
+ this.secondSurname = secondSurname;
872
+ this.stateOfBirth = stateOfBirth;
862
873
  this.status = data.enumValueFromString(data.UserStatus, status);
863
874
  this.terms = termsOfService;
875
+ this.updatedAt = data.dateToUTC(updatedAt);
864
876
  this.verificationId = verificationId;
865
877
  }
866
878
 
879
+ get address() {
880
+ return this._address;
881
+ }
882
+
883
+ set add(value) {
884
+ if (!value) return;
885
+ this._address = identities.Address.fromObject(value);
886
+ }
887
+
867
888
  get proofOfAddress() {
868
889
  return this._proofOfAddress;
869
890
  }
@@ -900,17 +921,45 @@ class User {
900
921
  this._termsOfService = identities.TOSAgreements.fromObject(value);
901
922
  }
902
923
 
903
- static fromObject = ({ level, status, ...obj }) =>
924
+ static fromObject = ({
925
+ address,
926
+ clabe,
927
+ curp,
928
+ gender,
929
+ id,
930
+ level,
931
+ names,
932
+ nationality,
933
+ rfc,
934
+ status,
935
+ ...obj
936
+ }) =>
904
937
  new User({
938
+ address,
939
+ clabe,
940
+ curp,
941
+ gender,
942
+ id,
905
943
  level,
944
+ names,
945
+ nationality,
946
+ rfc,
906
947
  status,
907
- govtId: obj.govt_id,
948
+ blacklistValidationStatus: obj.blacklist_validation_status,
949
+ countryOfBirth: obj.country_of_birth,
950
+ createdAt: obj.created_at,
951
+ dateOfBirth: obj.date_of_birth,
908
952
  emailAddress: obj.email_address,
953
+ firstSurname: obj.first_surname,
954
+ govtId: obj.govt_id,
909
955
  phoneNumber: obj.phone_number,
910
956
  proofOfAddress: obj.proof_of_address,
911
957
  proofOfLife: obj.proof_of_life,
912
958
  requiredLevel: obj.required_level,
959
+ secondSurname: obj.second_surname,
960
+ stateOfBirth: obj.state_of_birth,
913
961
  termsOfService: obj.terms_of_service,
962
+ updatedAt: obj.updated_at,
914
963
  verificationId: obj.verification_id,
915
964
  });
916
965
  }
@@ -1080,13 +1129,14 @@ const getModelFromPath = (path, obj) => {
1080
1129
  arpc: () => Arpc.fromObject(obj),
1081
1130
  balance_entries: () => BalanceEntry.fromObject(obj),
1082
1131
  bill_payments: () => BillPayment.fromObject(obj),
1083
- 'bridge/accounts': () => BridgeAccount.fromObject(obj),
1084
1132
  cards: () => Card.fromObject(obj),
1085
1133
  card_activations: () => CardActivation.fromObject(obj),
1086
1134
  card_transactions: () => CardTransaction.fromObject(obj),
1087
1135
  card_validations: () => CardValidation.fromObject(obj),
1088
1136
  commissions: () => Commission.fromObject(obj),
1089
1137
  deposits: () => Deposit.fromObject(obj),
1138
+ files: () => File.fromObject(obj),
1139
+ kyc_validations: () => KYCValidations.fromObject(obj),
1090
1140
  login_tokens: () => LoginToken.fromObject(obj),
1091
1141
  savings: () => Saving.fromObject(obj),
1092
1142
  service_providers: () => ServiceProvider.fromObject(obj),
@@ -1152,6 +1202,19 @@ const Updateable = (SuperClass) =>
1152
1202
  }
1153
1203
  };
1154
1204
 
1205
+ const Uploadable = (SuperClass) =>
1206
+ class Uploadable extends SuperClass {
1207
+ async _upload(data) {
1208
+ const response = await this.client.post({
1209
+ endpoint: `/${this.path}`,
1210
+ data,
1211
+ multipart: true,
1212
+ });
1213
+ const model = getModelFromPath(this.path, response);
1214
+ return model;
1215
+ }
1216
+ };
1217
+
1155
1218
  const Deactivable = (SuperClass) =>
1156
1219
  class Deactivable extends SuperClass {
1157
1220
  async _deactivate(id, data) {
@@ -1167,10 +1230,14 @@ const Deactivable = (SuperClass) =>
1167
1230
  const Downlodable = (SuperClass) =>
1168
1231
  class Downlodable extends SuperClass {
1169
1232
  async _download(id, format) {
1233
+ const interceptor = this.client.addConfigToRequest({
1234
+ responseType: 'stream',
1235
+ });
1170
1236
  const byteString = await this.client.get({
1171
1237
  endpoint: `/${this.path}/${id}`,
1172
1238
  format,
1173
1239
  });
1240
+ interceptor.eject();
1174
1241
  return byteString;
1175
1242
  }
1176
1243
  };
@@ -1337,12 +1404,6 @@ class BillPaymentResource extends mix(Resource).with(Queryable, Retrievable) {
1337
1404
  }
1338
1405
  }
1339
1406
 
1340
- class BridegAccountResource extends mix(Resource).with(Queryable, Retrievable) {
1341
- constructor(client) {
1342
- super('bridge/accounts', identities.BridgeAccountQuery, client);
1343
- }
1344
- }
1345
-
1346
1407
  class CardActivationResource extends mix(Resource).with(Creatable) {
1347
1408
  constructor(client) {
1348
1409
  super('card_activations', Object, client);
@@ -1470,6 +1531,39 @@ class DepositResource extends mix(Resource).with(Queryable, Retrievable) {
1470
1531
  }
1471
1532
  }
1472
1533
 
1534
+ class FileResource extends mix(Resource).with(Downlodable, Uploadable) {
1535
+ constructor(client) {
1536
+ super('files', Object, client);
1537
+ }
1538
+
1539
+ async download(id) {
1540
+ const byteString = await this._download(id, data.FileFormat.Any);
1541
+ return byteString;
1542
+ }
1543
+
1544
+ async upload({ ...req }) {
1545
+ const request = new walletTransactionRequest.UploadRequest(req);
1546
+ const fileUpload = await this._upload(request.toFormData());
1547
+ return fileUpload;
1548
+ }
1549
+ }
1550
+
1551
+ class KYCValidationsResource extends mix(Resource).with(
1552
+ Creatable,
1553
+ Retrievable,
1554
+ Queryable,
1555
+ ) {
1556
+ constructor(client) {
1557
+ super('kyc_validations', Object, client);
1558
+ }
1559
+
1560
+ async create(userId = 'me') {
1561
+ const request = new walletTransactionRequest.KYCValidationsRequest(userId);
1562
+ const kycValidation = await this._create(request.toObject());
1563
+ return kycValidation;
1564
+ }
1565
+ }
1566
+
1473
1567
  class LoginTokenResource extends mix(Resource).with(Creatable) {
1474
1568
  constructor(client) {
1475
1569
  super('login_tokens', Object, client);
@@ -1762,6 +1856,8 @@ class Cuenca {
1762
1856
  this.cardValidations = new CardValidationResource(client);
1763
1857
  this.commissions = new CommissionResource(client);
1764
1858
  this.deposits = new DepositResource(client);
1859
+ this.files = new FileResource(client);
1860
+ this.kycValidations = new KYCValidationsResource(client);
1765
1861
  this.loginTokens = new LoginTokenResource(client);
1766
1862
  this.savings = new SavingResource(client);
1767
1863
  this.serviceProviders = new ServiceProviderResource(client);