@cuenca-mx/cuenca-js 0.0.1-dev.8 → 0.0.2-dev.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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var errors_index = require('./errors/index.js');
4
- var data = require('./data-c53f1052.js');
3
+ var errors_index = require('./errors/index.cjs');
4
+ var data = require('./data-efb53250.cjs');
5
5
 
6
6
  class BaseRequest {
7
7
  toObject() {
@@ -309,6 +309,109 @@ class CardValidationRequest extends BaseRequest {
309
309
  }
310
310
  }
311
311
 
312
+ //import { FormData } from 'form-data';
313
+ const FormData = require('form-data');
314
+ //import * as FormData from 'form-data';
315
+ //import { FormData } from 'form-data';
316
+
317
+ //import * as form from 'form-data';
318
+
319
+
320
+ class IdentitiesUploadRequest extends BaseRequest {
321
+ constructor({
322
+ address,
323
+ blacklistValidationStatus,
324
+ countryOfBirth,
325
+ createdAt,
326
+ curp,
327
+ dateOfBirth,
328
+ extension,
329
+ firstSurname,
330
+ gender,
331
+ govId,
332
+ id,
333
+ names,
334
+ nationality,
335
+ proofOfAddress,
336
+ proofOfLife,
337
+ rfc,
338
+ rfcDocument,
339
+ rfcFile,
340
+ secondSurname,
341
+ stateOfBirth,
342
+ status,
343
+ tosAgreement,
344
+ userId,
345
+ }) {
346
+ super();
347
+ this.address = address;
348
+ this.blacklistValidationStatus = blacklistValidationStatus;
349
+ this.countryOfBirth = countryOfBirth;
350
+ this.createdAt = createdAt;
351
+ this.curp = curp;
352
+ this.dateOfBirth = dateOfBirth;
353
+ this.extension = extension;
354
+ this.firstSurname = firstSurname;
355
+ this.gender = gender;
356
+ this.govId = govId;
357
+ this.id = id;
358
+ this.names = names;
359
+ this.nationality = nationality;
360
+ this.proofOfAddress = proofOfAddress;
361
+ this.proofOfLife = proofOfLife;
362
+ this.rfc = rfc;
363
+ this.rfcDocument = rfcDocument;
364
+ this.rfcFile = rfcFile;
365
+ this.secondSurname = secondSurname;
366
+ this.stateOfBirth = stateOfBirth;
367
+ this.status = status;
368
+ this.tosAgreement = tosAgreement;
369
+ this.userId = userId;
370
+ }
371
+
372
+ toObject() {
373
+ return {
374
+ address: this.address,
375
+ blacklist_validation_status: this.blacklistValidationStatus,
376
+ country_of_birth: this.countryOfBirth,
377
+ created_at: this.createdAt,
378
+ curp: this.curp,
379
+ date_of_birth: this.dateOfBirth,
380
+ extension: this.extension,
381
+ first_surname: this.first_surname,
382
+ gender: this.gender,
383
+ gov_id: this.govId,
384
+ id: this.id,
385
+ names: this.names,
386
+ nationality: this.nationality,
387
+ proof_of_address: this.proofOfAddress,
388
+ proof_of_life: this.proofOfLife,
389
+ rfc: this.rfc,
390
+ rfc_document: this.rfcDocument,
391
+ rfc_file: this.rfcFile,
392
+ second_surname: this.secondSurname,
393
+ state_of_birth: this.stateOfBirth,
394
+ status: this.status,
395
+ tos_agreement: this.tosAgreement,
396
+ user_id: this.userId,
397
+ };
398
+ }
399
+
400
+ toFormData() {
401
+ console.log('formmmmmmm ', FormData());
402
+
403
+ const formData = new FormData();
404
+ // formData.set('extension', this.extension);
405
+ // formData.set('user_id', this.userId);
406
+ // formData.set('rfc_file', this.rfcFile);
407
+ formData.append('extension', this.extension);
408
+ formData.append('user_id', this.userId);
409
+ formData.append('rfc_file', this.rfcFile);
410
+ console.log('FormDataaaaa :', formData);
411
+ return formData;
412
+ }
413
+ }
414
+
312
415
  class SavingRequest extends BaseRequest {
313
416
  constructor(category, goalAmount, goalDate, name) {
314
417
  super();
@@ -380,7 +483,7 @@ class UserCredentialRequest extends BaseRequest {
380
483
  }
381
484
 
382
485
  set pwd(value) {
383
- const validations = [!!value, value.length === 6, /^\d{6}$/.test(value)];
486
+ const validations = [!!value, value.length >= 6];
384
487
  if (validations.some((x) => !x)) {
385
488
  throw new errors_index.ValidationError('Invalid password');
386
489
  }
@@ -418,7 +521,7 @@ class UserCredentialUpdateRequest extends BaseRequest {
418
521
  this._password = value;
419
522
  return;
420
523
  }
421
- const validations = [value.length === 6, /^\d{6}$/.test(value)];
524
+ const validations = [value.length >= 6];
422
525
  if (validations.some((x) => !x)) {
423
526
  throw new errors_index.ValidationError('Invalid password');
424
527
  }
@@ -467,6 +570,166 @@ class UserLoginRequest extends BaseRequest {
467
570
  }
468
571
  }
469
572
 
573
+ class TosUpdateRequest extends BaseRequest {
574
+ constructor({ ip, location, type, version }) {
575
+ super();
576
+ this.ipAddress = ip;
577
+ this.location = location;
578
+ this.type = type;
579
+ this.version = version;
580
+ }
581
+
582
+ get ip() {
583
+ return this._ip;
584
+ }
585
+
586
+ set ipAddress(value) {
587
+ if (!value) throw new errors_index.ValidationError('missing ip address');
588
+ const ipBlocks = value.split('.');
589
+ const blocks = ipBlocks.every((block) => {
590
+ return block >= 0 && block <= 255;
591
+ });
592
+ if (blocks) {
593
+ this._ip = value;
594
+ } else {
595
+ throw new errors_index.ValidationError('Invalid ip address');
596
+ }
597
+ }
598
+
599
+ toObject() {
600
+ return {
601
+ ip: this.ip,
602
+ location: this.location,
603
+ type: this.type,
604
+ version: this.version,
605
+ };
606
+ }
607
+ }
608
+
609
+ class AddressUpdateRequest extends BaseRequest {
610
+ constructor({
611
+ city,
612
+ country,
613
+ extNumber,
614
+ intNumber,
615
+ postalCode,
616
+ state,
617
+ street,
618
+ } = {}) {
619
+ super();
620
+ this.city = city;
621
+ this.country = country;
622
+ this.extNumber = extNumber;
623
+ this.intNumber = intNumber;
624
+ this.postalCode = postalCode;
625
+ this.state = state;
626
+ this.street = street;
627
+ }
628
+
629
+ toObject() {
630
+ return {
631
+ city: this.city,
632
+ country: this.country,
633
+ ext_number: this.extNumber,
634
+ int_number: this.intNumber,
635
+ postal_code: this.postalCode,
636
+ state: this.state,
637
+ street: this.street,
638
+ };
639
+ }
640
+ }
641
+
642
+ class UserUpdateRequest extends BaseRequest {
643
+ constructor({ address, profession, termsOfService, verificationId }) {
644
+ super();
645
+ this.address = new AddressUpdateRequest(address);
646
+ this.profession = profession;
647
+ this.terms = termsOfService;
648
+ this.verificationId = verificationId;
649
+ }
650
+
651
+ get termsOfService() {
652
+ return this._termsOfService;
653
+ }
654
+
655
+ set terms(value) {
656
+ if (!value) return;
657
+ this._termsOfService = new TosUpdateRequest(value).toObject();
658
+ }
659
+
660
+ toObject() {
661
+ return {
662
+ address: this.address.toCleanObject(),
663
+ profession: this.profession,
664
+ terms_of_service: this.termsOfService,
665
+ verification_id: this.verificationId,
666
+ };
667
+ }
668
+ }
669
+
670
+ class VerificationRequest extends BaseRequest {
671
+ constructor({ platformId, recipient, type }) {
672
+ super();
673
+ this.platformId = platformId;
674
+ this.type = type;
675
+ this.recipients = recipient;
676
+ }
677
+
678
+ get recipient() {
679
+ return this._recipient;
680
+ }
681
+
682
+ set recipients(value) {
683
+ function validateEmail(email) {
684
+ return email.match(
685
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
686
+ );
687
+ }
688
+
689
+ function validatePhone(phone) {
690
+ return phone.match(/^\+?[0-9]{10,15}$/);
691
+ }
692
+
693
+ switch (data.enumValueFromString(data.VerificationType, this.type)) {
694
+ case data.VerificationType.Email:
695
+ if (validateEmail(value)) {
696
+ this._recipient = value;
697
+ } else {
698
+ throw new errors_index.ValidationError('Invalid email address');
699
+ }
700
+ break;
701
+ case data.VerificationType.Phone:
702
+ if (validatePhone(value)) {
703
+ this._recipient = value;
704
+ } else {
705
+ throw new errors_index.ValidationError('Invalid Phone Number');
706
+ }
707
+ break;
708
+ }
709
+ }
710
+
711
+ toObject() {
712
+ return {
713
+ platform_id: this.platformId,
714
+ recipient: this.recipient,
715
+ type: this.type,
716
+ };
717
+ }
718
+ }
719
+
720
+ class VerificationAttemptRequest extends BaseRequest {
721
+ constructor({ code }) {
722
+ super();
723
+ this.code = code;
724
+ }
725
+
726
+ toObject() {
727
+ return {
728
+ code: this.code,
729
+ };
730
+ }
731
+ }
732
+
470
733
  class WalletTransactionRequest extends BaseRequest {
471
734
  constructor(amount, transactionType, walletUri) {
472
735
  super();
@@ -490,9 +753,13 @@ exports.CardActivationRequest = CardActivationRequest;
490
753
  exports.CardRequest = CardRequest;
491
754
  exports.CardUpdateRequest = CardUpdateRequest;
492
755
  exports.CardValidationRequest = CardValidationRequest;
756
+ exports.IdentitiesUploadRequest = IdentitiesUploadRequest;
493
757
  exports.SavingRequest = SavingRequest;
494
758
  exports.TransferRequest = TransferRequest;
495
759
  exports.UserCredentialRequest = UserCredentialRequest;
496
760
  exports.UserCredentialUpdateRequest = UserCredentialUpdateRequest;
497
761
  exports.UserLoginRequest = UserLoginRequest;
762
+ exports.UserUpdateRequest = UserUpdateRequest;
763
+ exports.VerificationAttemptRequest = VerificationAttemptRequest;
764
+ exports.VerificationRequest = VerificationRequest;
498
765
  exports.WalletTransactionRequest = WalletTransactionRequest;
package/package.json CHANGED
@@ -1,34 +1,34 @@
1
1
  {
2
2
  "name": "@cuenca-mx/cuenca-js",
3
- "version": "0.0.1-dev.8",
3
+ "version": "0.0.2-dev.2",
4
4
  "description": "Cuenca client for JS",
5
- "main": "./build/index.js",
5
+ "main": "./build/index.cjs",
6
6
  "module": "./build/index.mjs",
7
7
  "browser": "./build/umd/cuenca.umd.js",
8
8
  "files": [
9
9
  "build/**/*"
10
10
  ],
11
11
  "exports": {
12
- ".": [
13
- "./build/index.mjs",
14
- "./build/index.js"
15
- ],
16
- "./errors": [
17
- "./build/errors/index.mjs",
18
- "./build/errors/index.js"
19
- ],
20
- "./jwt": [
21
- "./build/jwt/index.mjs",
22
- "./build/jwt/index.js"
23
- ],
24
- "./requests": [
25
- "./build/requests/index.mjs",
26
- "./build/requests/index.js"
27
- ],
28
- "./types": [
29
- "./build/types/index.mjs",
30
- "./build/types/index.js"
31
- ]
12
+ ".": {
13
+ "import": "./build/index.mjs",
14
+ "require": "./build/index.cjs"
15
+ },
16
+ "./errors": {
17
+ "import": "./build/errors/index.mjs",
18
+ "require": "./build/errors/index.cjs"
19
+ },
20
+ "./jwt": {
21
+ "import": "./build/jwt/index.mjs",
22
+ "require": "./build/jwt/index.cjs"
23
+ },
24
+ "./requests": {
25
+ "import": "./build/requests/index.mjs",
26
+ "require": "./build/requests/index.cjs"
27
+ },
28
+ "./types": {
29
+ "import": "./build/types/index.mjs",
30
+ "require": "./build/types/index.cjs"
31
+ }
32
32
  },
33
33
  "packageManager": "yarn@3.0.2",
34
34
  "type": "module",
@@ -51,13 +51,16 @@
51
51
  "publish": "yarn build && yarn npm publish"
52
52
  },
53
53
  "devDependencies": {
54
- "@rollup/plugin-commonjs": "^21.0.1",
54
+ "@rollup/plugin-json": "^4.1.0",
55
55
  "@rollup/plugin-node-resolve": "^13.1.1",
56
56
  "jest": "^27.4.5",
57
57
  "rollup": "^2.61.1",
58
58
  "rollup-plugin-terser": "^7.0.2"
59
59
  },
60
60
  "dependencies": {
61
- "axios": "^0.24.0"
61
+ "axios": "^0.24.0",
62
+ "buffer": "^6.0.3",
63
+ "form-data": "^4.0.0",
64
+ "formdata-node": "^4.3.2"
62
65
  }
63
66
  }
@@ -1,11 +0,0 @@
1
- const dateToUTC = (date) => {
2
- if (!date) return null;
3
- const dateObj = new Date(date);
4
- return new Date(dateObj.getTime());
5
- };
6
-
7
- const enumValueFromString = (enumValue, value) => {
8
- return Object.values(enumValue).find((enumV) => enumV.value === value);
9
- };
10
-
11
- export { dateToUTC as d, enumValueFromString as e };
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- const dateToUTC = (date) => {
4
- if (!date) return null;
5
- const dateObj = new Date(date);
6
- return new Date(dateObj.getTime());
7
- };
8
-
9
- const enumValueFromString = (enumValue, value) => {
10
- return Object.values(enumValue).find((enumV) => enumV.value === value);
11
- };
12
-
13
- exports.dateToUTC = dateToUTC;
14
- exports.enumValueFromString = enumValueFromString;