@cuenca-mx/cuenca-js 0.0.1-dev.9 → 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.
@@ -1,5 +1,5 @@
1
1
  import { ValidationError } from './errors/index.mjs';
2
- import { d as dateToUTC } from './data-7d3d5fcc.js';
2
+ import { d as dateToUTC, e as enumValueFromString, V as VerificationType } from './data-69952249.mjs';
3
3
 
4
4
  class BaseRequest {
5
5
  toObject() {
@@ -307,6 +307,99 @@ class CardValidationRequest extends BaseRequest {
307
307
  }
308
308
  }
309
309
 
310
+ //import FormData from 'form-data';
311
+ const FormData = require('form-data');
312
+
313
+ class IdentitiesUploadRequest extends BaseRequest {
314
+ constructor({
315
+ address,
316
+ blacklistValidationStatus,
317
+ countryOfBirth,
318
+ createdAt,
319
+ curp,
320
+ dateOfBirth,
321
+ extension,
322
+ firstSurname,
323
+ gender,
324
+ govId,
325
+ id,
326
+ names,
327
+ nationality,
328
+ proofOfAddress,
329
+ proofOfLife,
330
+ rfc,
331
+ rfcDocument,
332
+ rfcFile,
333
+ secondSurname,
334
+ stateOfBirth,
335
+ status,
336
+ tosAgreement,
337
+ userId,
338
+ }) {
339
+ super();
340
+ this.address = address;
341
+ this.blacklistValidationStatus = blacklistValidationStatus;
342
+ this.countryOfBirth = countryOfBirth;
343
+ this.createdAt = createdAt;
344
+ this.curp = curp;
345
+ this.dateOfBirth = dateOfBirth;
346
+ this.extension = extension;
347
+ this.firstSurname = firstSurname;
348
+ this.gender = gender;
349
+ this.govId = govId;
350
+ this.id = id;
351
+ this.names = names;
352
+ this.nationality = nationality;
353
+ this.proofOfAddress = proofOfAddress;
354
+ this.proofOfLife = proofOfLife;
355
+ this.rfc = rfc;
356
+ this.rfcDocument = rfcDocument;
357
+ this.rfcFile = rfcFile;
358
+ this.secondSurname = secondSurname;
359
+ this.stateOfBirth = stateOfBirth;
360
+ this.status = status;
361
+ this.tosAgreement = tosAgreement;
362
+ this.userId = userId;
363
+ }
364
+
365
+ toObject() {
366
+ return {
367
+ address: this.address,
368
+ blacklist_validation_status: this.blacklistValidationStatus,
369
+ country_of_birth: this.countryOfBirth,
370
+ created_at: this.createdAt,
371
+ curp: this.curp,
372
+ date_of_birth: this.dateOfBirth,
373
+ extension: this.extension,
374
+ first_surname: this.first_surname,
375
+ gender: this.gender,
376
+ gov_id: this.govId,
377
+ id: this.id,
378
+ names: this.names,
379
+ nationality: this.nationality,
380
+ proof_of_address: this.proofOfAddress,
381
+ proof_of_life: this.proofOfLife,
382
+ rfc: this.rfc,
383
+ rfc_document: this.rfcDocument,
384
+ rfc_file: this.rfcFile,
385
+ second_surname: this.secondSurname,
386
+ state_of_birth: this.stateOfBirth,
387
+ status: this.status,
388
+ tos_agreement: this.tosAgreement,
389
+ user_id: this.userId,
390
+ };
391
+ }
392
+
393
+ toFormData() {
394
+ const formData = new FormData();
395
+ formData.append('extension', this.extension);
396
+ formData.append('user_id', this.userId);
397
+ formData.append('rfc_file', this.rfcFile);
398
+ console.log('Headers fromData :', formData.getHeaders());
399
+ return formData;
400
+ }
401
+ }
402
+
310
403
  class SavingRequest extends BaseRequest {
311
404
  constructor(category, goalAmount, goalDate, name) {
312
405
  super();
@@ -378,7 +471,7 @@ class UserCredentialRequest extends BaseRequest {
378
471
  }
379
472
 
380
473
  set pwd(value) {
381
- const validations = [!!value, value.length === 6, /^\d{6}$/.test(value)];
474
+ const validations = [!!value, value.length >= 6];
382
475
  if (validations.some((x) => !x)) {
383
476
  throw new ValidationError('Invalid password');
384
477
  }
@@ -416,7 +509,7 @@ class UserCredentialUpdateRequest extends BaseRequest {
416
509
  this._password = value;
417
510
  return;
418
511
  }
419
- const validations = [value.length === 6, /^\d{6}$/.test(value)];
512
+ const validations = [value.length >= 6];
420
513
  if (validations.some((x) => !x)) {
421
514
  throw new ValidationError('Invalid password');
422
515
  }
@@ -465,6 +558,166 @@ class UserLoginRequest extends BaseRequest {
465
558
  }
466
559
  }
467
560
 
561
+ class TosUpdateRequest extends BaseRequest {
562
+ constructor({ ip, location, type, version }) {
563
+ super();
564
+ this.ipAddress = ip;
565
+ this.location = location;
566
+ this.type = type;
567
+ this.version = version;
568
+ }
569
+
570
+ get ip() {
571
+ return this._ip;
572
+ }
573
+
574
+ set ipAddress(value) {
575
+ if (!value) throw new ValidationError('missing ip address');
576
+ const ipBlocks = value.split('.');
577
+ const blocks = ipBlocks.every((block) => {
578
+ return block >= 0 && block <= 255;
579
+ });
580
+ if (blocks) {
581
+ this._ip = value;
582
+ } else {
583
+ throw new ValidationError('Invalid ip address');
584
+ }
585
+ }
586
+
587
+ toObject() {
588
+ return {
589
+ ip: this.ip,
590
+ location: this.location,
591
+ type: this.type,
592
+ version: this.version,
593
+ };
594
+ }
595
+ }
596
+
597
+ class AddressUpdateRequest extends BaseRequest {
598
+ constructor({
599
+ city,
600
+ country,
601
+ extNumber,
602
+ intNumber,
603
+ postalCode,
604
+ state,
605
+ street,
606
+ } = {}) {
607
+ super();
608
+ this.city = city;
609
+ this.country = country;
610
+ this.extNumber = extNumber;
611
+ this.intNumber = intNumber;
612
+ this.postalCode = postalCode;
613
+ this.state = state;
614
+ this.street = street;
615
+ }
616
+
617
+ toObject() {
618
+ return {
619
+ city: this.city,
620
+ country: this.country,
621
+ ext_number: this.extNumber,
622
+ int_number: this.intNumber,
623
+ postal_code: this.postalCode,
624
+ state: this.state,
625
+ street: this.street,
626
+ };
627
+ }
628
+ }
629
+
630
+ class UserUpdateRequest extends BaseRequest {
631
+ constructor({ address, profession, termsOfService, verificationId }) {
632
+ super();
633
+ this.address = new AddressUpdateRequest(address);
634
+ this.profession = profession;
635
+ this.terms = termsOfService;
636
+ this.verificationId = verificationId;
637
+ }
638
+
639
+ get termsOfService() {
640
+ return this._termsOfService;
641
+ }
642
+
643
+ set terms(value) {
644
+ if (!value) return;
645
+ this._termsOfService = new TosUpdateRequest(value).toObject();
646
+ }
647
+
648
+ toObject() {
649
+ return {
650
+ address: this.address.toCleanObject(),
651
+ profession: this.profession,
652
+ terms_of_service: this.termsOfService,
653
+ verification_id: this.verificationId,
654
+ };
655
+ }
656
+ }
657
+
658
+ class VerificationRequest extends BaseRequest {
659
+ constructor({ platformId, recipient, type }) {
660
+ super();
661
+ this.platformId = platformId;
662
+ this.type = type;
663
+ this.recipients = recipient;
664
+ }
665
+
666
+ get recipient() {
667
+ return this._recipient;
668
+ }
669
+
670
+ set recipients(value) {
671
+ function validateEmail(email) {
672
+ return email.match(
673
+ /^(([^<>()[\]\\.,;:\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,}))$/,
674
+ );
675
+ }
676
+
677
+ function validatePhone(phone) {
678
+ return phone.match(/^\+?[0-9]{10,15}$/);
679
+ }
680
+
681
+ switch (enumValueFromString(VerificationType, this.type)) {
682
+ case VerificationType.Email:
683
+ if (validateEmail(value)) {
684
+ this._recipient = value;
685
+ } else {
686
+ throw new ValidationError('Invalid email address');
687
+ }
688
+ break;
689
+ case VerificationType.Phone:
690
+ if (validatePhone(value)) {
691
+ this._recipient = value;
692
+ } else {
693
+ throw new ValidationError('Invalid Phone Number');
694
+ }
695
+ break;
696
+ }
697
+ }
698
+
699
+ toObject() {
700
+ return {
701
+ platform_id: this.platformId,
702
+ recipient: this.recipient,
703
+ type: this.type,
704
+ };
705
+ }
706
+ }
707
+
708
+ class VerificationAttemptRequest extends BaseRequest {
709
+ constructor({ code }) {
710
+ super();
711
+ this.code = code;
712
+ }
713
+
714
+ toObject() {
715
+ return {
716
+ code: this.code,
717
+ };
718
+ }
719
+ }
720
+
468
721
  class WalletTransactionRequest extends BaseRequest {
469
722
  constructor(amount, transactionType, walletUri) {
470
723
  super();
@@ -482,4 +735,4 @@ class WalletTransactionRequest extends BaseRequest {
482
735
  }
483
736
  }
484
737
 
485
- export { ApiKeyUpdateRequest as A, CardActivationRequest as C, SavingRequest as S, TransferRequest as T, UserCredentialRequest as U, WalletTransactionRequest as W, ArpcRequest as a, CardRequest as b, CardUpdateRequest as c, CardValidationRequest as d, UserCredentialUpdateRequest as e, UserLoginRequest as f };
738
+ export { ApiKeyUpdateRequest as A, CardActivationRequest as C, IdentitiesUploadRequest as I, SavingRequest as S, TransferRequest as T, UserCredentialRequest as U, VerificationRequest as V, WalletTransactionRequest as W, ArpcRequest as a, CardRequest as b, CardUpdateRequest as c, CardValidationRequest as d, UserCredentialUpdateRequest as e, UserLoginRequest as f, UserUpdateRequest as g, VerificationAttemptRequest as h };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@cuenca-mx/cuenca-js",
3
- "version": "0.0.1-dev.9",
3
+ "version": "0.0.2-dev.1",
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": [
@@ -11,23 +11,23 @@
11
11
  "exports": {
12
12
  ".": {
13
13
  "import": "./build/index.mjs",
14
- "require": "./build/index.js"
14
+ "require": "./build/index.cjs"
15
15
  },
16
16
  "./errors": {
17
17
  "import": "./build/errors/index.mjs",
18
- "require": "./build/errors/index.js"
18
+ "require": "./build/errors/index.cjs"
19
19
  },
20
20
  "./jwt": {
21
21
  "import": "./build/jwt/index.mjs",
22
- "require": "./build/jwt/index.js"
22
+ "require": "./build/jwt/index.cjs"
23
23
  },
24
24
  "./requests": {
25
25
  "import": "./build/requests/index.mjs",
26
- "require": "./build/requests/index.js"
26
+ "require": "./build/requests/index.cjs"
27
27
  },
28
28
  "./types": {
29
29
  "import": "./build/types/index.mjs",
30
- "require": "./build/types/index.js"
30
+ "require": "./build/types/index.cjs"
31
31
  }
32
32
  },
33
33
  "packageManager": "yarn@3.0.2",
@@ -51,13 +51,15 @@
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"
62
64
  }
63
65
  }
@@ -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;