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

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.
@@ -0,0 +1,46 @@
1
+ import { MalformedJwtToken } from '../errors/index.mjs';
2
+
3
+ class Jwt {
4
+ constructor(expiresAt, token) {
5
+ this.expiresAt = expiresAt;
6
+ this.token = token;
7
+ }
8
+
9
+ get isExpired() {
10
+ const today = new Date();
11
+ return (this.expiresAt.valueOf() - today.valueOf()) / 60000 <= 5;
12
+ }
13
+
14
+ static getExpirationDate = (token) => {
15
+ let payload;
16
+ try {
17
+ const [, payloadEncoded] = token.split('.');
18
+ payload = JSON.parse(
19
+ Buffer.from(`${payloadEncoded}==`, 'base64').toString(),
20
+ );
21
+ } catch (error) {
22
+ throw new MalformedJwtToken();
23
+ }
24
+
25
+ const { exp } = payload;
26
+ return new Date(new Date(exp * 1000).toUTCString());
27
+ };
28
+
29
+ static create = async (client) => {
30
+ const currentClient = client;
31
+ currentClient.jwtToken = null;
32
+ // Intercepts requests and removes the header if it includes it
33
+ const tokenInterceptor =
34
+ currentClient.deleteRequestHeader('X-Cuenca-Token');
35
+
36
+ const { token } = await client.post('token', {});
37
+
38
+ // Remove the interceptor to avoid removing the header on all requests
39
+ tokenInterceptor.eject();
40
+
41
+ const expiresAt = Jwt.getExpirationDate(token);
42
+ return new Jwt(expiresAt, token);
43
+ };
44
+ }
45
+
46
+ export { Jwt };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuenca-mx/cuenca-js",
3
- "version": "0.0.1-dev.4",
3
+ "version": "0.0.1-dev.5",
4
4
  "description": "Cuenca client for JS",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -10,10 +10,10 @@
10
10
  ],
11
11
  "exports": {
12
12
  ".": "./build/index.mjs",
13
- "./errors/": "./build/errors/",
14
- "./jwt/": "./build/jwt/",
15
- "./requests/": "./build/requests/",
16
- "./types/": "./build/types/"
13
+ "./errors/": "./build/errors/index.mjs",
14
+ "./jwt/": "./build/jwt/index.mjs",
15
+ "./requests/": "./build/requests/index.mjs",
16
+ "./types/": "./build/types/index.mjs"
17
17
  },
18
18
  "packageManager": "yarn@3.0.2",
19
19
  "type": "module",
@@ -1,4 +1,4 @@
1
- import { ValidationError } from './errors/index.js';
1
+ import { ValidationError } from './errors/index.mjs';
2
2
  import { d as dateToUTC } from './data-7d3d5fcc.js';
3
3
 
4
4
  class CardErrorType {
@@ -0,0 +1,3 @@
1
+ export { A as ApiKeyUpdateRequest, a as ArpcRequest, C as CardActivationRequest, b as CardRequest, c as CardUpdateRequest, d as CardValidationRequest, S as SavingRequest, T as TransferRequest, U as UserCredentialRequest, e as UserCredentialUpdateRequest, f as UserLoginRequest, W as WalletTransactionRequest } from '../walletTransactionRequest-bbfb87bd.js';
2
+ import '../errors/index.mjs';
3
+ import '../data-7d3d5fcc.js';
@@ -0,0 +1,3 @@
1
+ export { A as AccountQuery, i as ApiKeyQuery, B as BalanceEntryQuery, j as BillPaymentQuery, d as CardErrorType, c as CardFundingType, C as CardIssuer, a as CardStatus, l as CardTransactionQuery, e as CardTransactionType, b as CardType, k as CardsQuery, f as CommissionType, D as DepositNetwork, m as DepositQuery, E as EntryType, F as FileFormat, s as PageSize, P as Phase, Q as QueryParams, S as SavingCategory, g as ServiceProviderCategory, o as StatementQuery, r as TrackDataMethod, T as TransactionStatus, h as TransferNetwork, p as TransferQuery, n as WalletQuery, q as WalletTransactionQuery, W as WalletTransactionType } from '../queries-f146b91b.js';
2
+ import '../errors/index.mjs';
3
+ import '../data-7d3d5fcc.js';
@@ -1,4 +1,4 @@
1
- import { ValidationError } from './errors/index.js';
1
+ import { ValidationError } from './errors/index.mjs';
2
2
  import { d as dateToUTC } from './data-7d3d5fcc.js';
3
3
 
4
4
  class BaseRequest {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuenca-mx/cuenca-js",
3
- "version": "0.0.1-dev.4",
3
+ "version": "0.0.1-dev.5",
4
4
  "description": "Cuenca client for JS",
5
5
  "main": "./build/index.js",
6
6
  "module": "./build/index.mjs",
@@ -10,10 +10,10 @@
10
10
  ],
11
11
  "exports": {
12
12
  ".": "./build/index.mjs",
13
- "./errors/": "./build/errors/",
14
- "./jwt/": "./build/jwt/",
15
- "./requests/": "./build/requests/",
16
- "./types/": "./build/types/"
13
+ "./errors/": "./build/errors/index.mjs",
14
+ "./jwt/": "./build/jwt/index.mjs",
15
+ "./requests/": "./build/requests/index.mjs",
16
+ "./types/": "./build/types/index.mjs"
17
17
  },
18
18
  "packageManager": "yarn@3.0.2",
19
19
  "type": "module",