@cuenca-mx/cuenca-js 0.0.1-dev.3 → 0.0.1-dev.4
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/README.md +7 -0
- package/build/package.json +37 -0
- package/build/{queries-f146b91b.js → queries-395c7467.js} +1 -1
- package/build/{walletTransactionRequest-bbfb87bd.js → walletTransactionRequest-17132eb5.js} +1 -1
- package/package.json +11 -2
- package/build/errors/index.mjs +0 -64
- package/build/index.mjs +0 -1475
- package/build/jwt/index.mjs +0 -46
- package/build/requests/index.mjs +0 -3
- package/build/types/index.mjs +0 -3
package/build/jwt/index.mjs
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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 };
|
package/build/requests/index.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
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';
|
package/build/types/index.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
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';
|