@xh/hoist 64.0.0 → 64.0.3

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,9 +0,0 @@
1
- import { PlainObject } from '@xh/hoist/core';
2
- export declare class TokenInfo {
3
- readonly token: string;
4
- readonly decoded: PlainObject;
5
- readonly expiry: number;
6
- constructor(token: string);
7
- forLog(): PlainObject;
8
- expiresWithin(interval: number): boolean;
9
- }
@@ -1,42 +0,0 @@
1
- /*
2
- * This file belongs to Hoist, an application development toolkit
3
- * developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
4
- *
5
- * Copyright © 2024 Extremely Heavy Industries Inc.
6
- */
7
-
8
- import {PlainObject} from '@xh/hoist/core';
9
- import {olderThan, SECONDS} from '@xh/hoist/utils/datetime';
10
- import {jwtDecode} from 'jwt-decode';
11
- import {isUndefined} from 'lodash';
12
-
13
- export class TokenInfo {
14
- readonly token: string;
15
- readonly decoded: PlainObject;
16
- readonly expiry: number;
17
-
18
- constructor(token: string) {
19
- this.token = token;
20
- this.decoded = jwtDecode(token);
21
- this.expiry = this.decoded.exp * SECONDS;
22
- }
23
-
24
- forLog(): PlainObject {
25
- const ret: PlainObject = {
26
- ...this.decoded,
27
- exp: new Date(this.expiry)
28
- };
29
-
30
- ['iat', 'nbf'].forEach(k => {
31
- const val = this.decoded[k];
32
- if (isUndefined(val)) return;
33
- ret[k] = new Date(val * SECONDS);
34
- });
35
-
36
- return ret;
37
- }
38
-
39
- expiresWithin(interval: number): boolean {
40
- return olderThan(this.expiry, -interval);
41
- }
42
- }