@cuenca-mx/cuenca-js 0.0.1-dev.4 → 0.0.1-dev.42

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() {
@@ -380,7 +380,7 @@ class UserCredentialRequest extends BaseRequest {
380
380
  }
381
381
 
382
382
  set pwd(value) {
383
- const validations = [!!value, value.length === 6, /^\d{6}$/.test(value)];
383
+ const validations = [!!value, value.length >= 6];
384
384
  if (validations.some((x) => !x)) {
385
385
  throw new errors_index.ValidationError('Invalid password');
386
386
  }
@@ -418,7 +418,7 @@ class UserCredentialUpdateRequest extends BaseRequest {
418
418
  this._password = value;
419
419
  return;
420
420
  }
421
- const validations = [value.length === 6, /^\d{6}$/.test(value)];
421
+ const validations = [value.length >= 6];
422
422
  if (validations.some((x) => !x)) {
423
423
  throw new errors_index.ValidationError('Invalid password');
424
424
  }
@@ -467,6 +467,129 @@ class UserLoginRequest extends BaseRequest {
467
467
  }
468
468
  }
469
469
 
470
+ class TosUpdateRequest extends BaseRequest {
471
+ constructor({ ip, location, type, version }) {
472
+ super();
473
+ this.ipAddress = ip;
474
+ this.location = location;
475
+ this.type = type;
476
+ this.version = version;
477
+ }
478
+
479
+ get ip() {
480
+ return this._ip;
481
+ }
482
+
483
+ set ipAddress(value) {
484
+ if (!value) throw new errors_index.ValidationError('missing ip address');
485
+ const ipBlocks = value.split('.');
486
+ const blocks = ipBlocks.every((block) => {
487
+ return block >= 0 && block <= 255;
488
+ });
489
+ if (blocks) {
490
+ this._ip = value;
491
+ } else {
492
+ throw new errors_index.ValidationError('Invalid ip address');
493
+ }
494
+ }
495
+
496
+ toObject() {
497
+ return {
498
+ ip: this.ip,
499
+ location: this.location,
500
+ type: this.type,
501
+ version: this.version,
502
+ };
503
+ }
504
+ }
505
+
506
+ class UserUpdateRequest extends BaseRequest {
507
+ constructor({ termsOfService, verificationId }) {
508
+ super();
509
+ this.terms = termsOfService;
510
+ this.verificationId = verificationId;
511
+ }
512
+
513
+ get termsOfService() {
514
+ return this._termsOfService;
515
+ }
516
+
517
+ set terms(value) {
518
+ if (!value) return;
519
+ this._termsOfService = new TosUpdateRequest(value).toObject();
520
+ }
521
+
522
+ toObject() {
523
+ return {
524
+ terms_of_service: this.termsOfService,
525
+ verification_id: this.verificationId,
526
+ };
527
+ }
528
+ }
529
+
530
+ class VerificationRequest extends BaseRequest {
531
+ constructor({ platformId, recipient, type }) {
532
+ super();
533
+ this.platformId = platformId;
534
+ this.type = type;
535
+ this.recipients = recipient;
536
+ }
537
+
538
+ get recipient() {
539
+ return this._recipient;
540
+ }
541
+
542
+ set recipients(value) {
543
+ function validateEmail(email) {
544
+ return email.match(
545
+ /^(([^<>()[\]\\.,;:\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,}))$/,
546
+ );
547
+ }
548
+
549
+ function validatePhone(phone) {
550
+ return phone.match(/^\+?[0-9]{10,15}$/);
551
+ }
552
+
553
+ switch (data.enumValueFromString(data.VerificationType, this.type)) {
554
+ case data.VerificationType.Email:
555
+ if (validateEmail(value)) {
556
+ this._recipient = value;
557
+ } else {
558
+ throw new errors_index.ValidationError('Invalid email address');
559
+ }
560
+ break;
561
+ case data.VerificationType.Phone:
562
+ if (validatePhone(value)) {
563
+ this._recipient = value;
564
+ } else {
565
+ throw new errors_index.ValidationError('Invalid Phone Number');
566
+ }
567
+ break;
568
+ }
569
+ }
570
+
571
+ toObject() {
572
+ return {
573
+ platform_id: this.platformId,
574
+ recipient: this.recipient,
575
+ type: this.type,
576
+ };
577
+ }
578
+ }
579
+
580
+ class VerificationAttemptRequest extends BaseRequest {
581
+ constructor({ code }) {
582
+ super();
583
+ this.code = code;
584
+ }
585
+
586
+ toObject() {
587
+ return {
588
+ code: this.code,
589
+ };
590
+ }
591
+ }
592
+
470
593
  class WalletTransactionRequest extends BaseRequest {
471
594
  constructor(amount, transactionType, walletUri) {
472
595
  super();
@@ -495,4 +618,7 @@ exports.TransferRequest = TransferRequest;
495
618
  exports.UserCredentialRequest = UserCredentialRequest;
496
619
  exports.UserCredentialUpdateRequest = UserCredentialUpdateRequest;
497
620
  exports.UserLoginRequest = UserLoginRequest;
621
+ exports.UserUpdateRequest = UserUpdateRequest;
622
+ exports.VerificationAttemptRequest = VerificationAttemptRequest;
623
+ exports.VerificationRequest = VerificationRequest;
498
624
  exports.WalletTransactionRequest = WalletTransactionRequest;
package/package.json CHANGED
@@ -1,19 +1,34 @@
1
1
  {
2
2
  "name": "@cuenca-mx/cuenca-js",
3
- "version": "0.0.1-dev.4",
3
+ "version": "0.0.1-dev.42",
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
- ".": "./build/index.mjs",
13
- "./errors/": "./build/errors/",
14
- "./jwt/": "./build/jwt/",
15
- "./requests/": "./build/requests/",
16
- "./types/": "./build/types/"
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
+ }
17
32
  },
18
33
  "packageManager": "yarn@3.0.2",
19
34
  "type": "module",
@@ -31,20 +46,19 @@
31
46
  },
32
47
  "homepage": "https://cuenca.com",
33
48
  "scripts": {
34
- "build": "rm -rf build/ && yarn node ./scripts/rollup/rollup.cjs",
49
+ "build": "rm -rf build/ && yarn rollup --config",
35
50
  "test": "yarn node --experimental-vm-modules $(yarn bin jest)",
36
51
  "publish": "yarn build && yarn npm publish"
37
52
  },
38
53
  "devDependencies": {
39
- "@rollup/plugin-commonjs": "^21.0.1",
54
+ "@rollup/plugin-json": "^4.1.0",
40
55
  "@rollup/plugin-node-resolve": "^13.1.1",
41
- "chalk": "^4.1.2",
42
- "fs-extra": "^10.0.0",
43
56
  "jest": "^27.4.5",
44
57
  "rollup": "^2.61.1",
45
58
  "rollup-plugin-terser": "^7.0.2"
46
59
  },
47
60
  "dependencies": {
48
- "axios": "^0.24.0"
61
+ "axios": "^0.24.0",
62
+ "buffer": "^6.0.3"
49
63
  }
50
64
  }
package/build/README.md DELETED
@@ -1,7 +0,0 @@
1
- # cuenca-js &middot; [![codecov](https://codecov.io/gh/cuenca-mx/cuenca-js/branch/main/graph/badge.svg?token=SRY49Q0VrM)](https://codecov.io/gh/cuenca-mx/cuenca-js)
2
-
3
- `cuenca-js` is a Javascript library client to use Cuenca's services.
4
-
5
- ## Installation
6
-
7
- ## Documentation
@@ -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;
@@ -1,37 +0,0 @@
1
- {
2
- "name": "@cuenca-mx/cuenca-js",
3
- "version": "0.0.1-dev.4",
4
- "description": "Cuenca client for JS",
5
- "main": "./index.js",
6
- "module": "./index.mjs",
7
- "browser": "./umd/cuenca.umd.js",
8
- "files": [
9
- "build/**/*"
10
- ],
11
- "exports": {
12
- ".": "./build/index.mjs",
13
- "./errors/": "./build/errors/",
14
- "./jwt/": "./build/jwt/",
15
- "./requests/": "./build/requests/",
16
- "./types/": "./build/types/"
17
- },
18
- "packageManager": "yarn@3.0.2",
19
- "type": "module",
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/cuenca-mx/cuenca-js.git",
23
- "directory": "packages/cuenca-js"
24
- },
25
- "keywords": [
26
- "cuenca"
27
- ],
28
- "license": "MIT",
29
- "bugs": {
30
- "url": "https://github.com/cuenca-mx/cuenca-js/issues"
31
- },
32
- "homepage": "https://cuenca.com",
33
- "dependencies": {
34
- "axios": "^0.24.0"
35
- },
36
- "private": false
37
- }