@ctx-core/jwt 10.1.54 → 10.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @ctx-core/jwt
2
2
 
3
+ ## 10.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - extract _.js & _.d.ts into directories
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - Updated dependencies
13
+ - @ctx-core/error@11.6.0
14
+
15
+ ## 10.1.55
16
+
17
+ ### Patch Changes
18
+
19
+ - @ctx-core/atob: ^10.0.91 -> ^10.0.92
20
+
3
21
  ## 10.1.54
4
22
 
5
23
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctx-core/jwt",
3
- "version": "10.1.54",
3
+ "version": "10.2.0",
4
4
  "description": "ctx-core jwt",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -24,8 +24,8 @@
24
24
  "./package.json": "./package.json"
25
25
  },
26
26
  "dependencies": {
27
- "@ctx-core/atob": "^10.0.91",
28
- "@ctx-core/error": "^11.5.18",
27
+ "@ctx-core/atob": "^10.0.92",
28
+ "@ctx-core/error": "^11.6.0",
29
29
  "@ctx-core/function": "^21.6.1",
30
30
  "@swc/cli": "^0.1.61",
31
31
  "@swc/core": "^1.3.32"
@@ -1,11 +1,11 @@
1
- import type { error_ctx_I } from '@ctx-core/error'
1
+ import type { error_o_T } from '@ctx-core/error'
2
2
  import { type nullish } from '@ctx-core/function'
3
3
  export interface JwtToken {
4
4
  access_token:string
5
5
  token_type:string
6
6
  id_token?:string
7
7
  email?:string
8
- error?:error_ctx_I|nullish
8
+ error?:error_o_T|nullish
9
9
  expires_in?:number
10
10
  }
11
11
  export type Token = JwtToken
@@ -1,4 +1,4 @@
1
- import type { error_ctx_I } from '@ctx-core/error'
2
- export interface jwt_error_ctx_I extends error_ctx_I {
1
+ import type { error_o_T } from '@ctx-core/error'
2
+ export interface jwt_error_ctx_I extends error_o_T {
3
3
  jwt_token:string
4
4
  }
@@ -0,0 +1,6 @@
1
+ export declare function authorization__header__jwt_token_(authorization:string):string
2
+ export {
3
+ authorization__header__jwt_token_ as header_authorization_jwt_token_,
4
+ authorization__header__jwt_token_ as _header_authorization_jwt_token,
5
+ authorization__header__jwt_token_ as _jwt_token__authorization__header,
6
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @param {string}authorization
3
+ * @return {string}
4
+ */
5
+ export function authorization__header__jwt_token_(authorization) {
6
+ const authorization_a = authorization?.split(/^Bearer */)
7
+ return authorization_a ? authorization_a[1] : null
8
+ }
9
+ export {
10
+ authorization__header__jwt_token_ as header_authorization_jwt_token_,
11
+ authorization__header__jwt_token_ as _header_authorization_jwt_token,
12
+ authorization__header__jwt_token_ as _jwt_token__authorization__header,
13
+ }
package/src/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './_types'
2
- export * from './header_authorization_jwt_token_'
2
+ export * from './authorization__header__jwt_token_'
3
3
  export * from './jwt_token_exp_'
4
- export * from './validate_current_jwt'
4
+ export * from './jwt__expiration__validate'
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './header_authorization_jwt_token_.js'
2
- export * from './jwt_token_exp_.js'
3
- export * from './validate_current_jwt.js'
1
+ export * from './authorization__header__jwt_token_/index.js'
2
+ export * from './jwt_token_exp_/index.js'
3
+ export * from './jwt__expiration__validate/index.js'
@@ -0,0 +1,5 @@
1
+ export declare function jwt__expiration__validate(jwt_token:string):void
2
+ export {
3
+ jwt__expiration__validate as validate_current_jwt,
4
+ jwt__expiration__validate as validate__current__jwt,
5
+ }
@@ -0,0 +1,20 @@
1
+ import { bad_credentials__throw } from '@ctx-core/error'
2
+ import { jwt_token_exp_ } from '../jwt_token_exp_/index.js'
3
+ /**
4
+ * @param {string}jwt_token
5
+ */
6
+ export function jwt__expiration__validate(jwt_token) {
7
+ const jwt_token_exp = jwt_token_exp_(jwt_token)
8
+ if (jwt_token_exp === null) return
9
+ const jwt_token_exp_millis = jwt_token_exp * 1000
10
+ if (Date.now() > jwt_token_exp_millis) {
11
+ bad_credentials__throw({
12
+ jwt_token,
13
+ error_message: 'Session Expired'
14
+ })
15
+ }
16
+ }
17
+ export {
18
+ jwt__expiration__validate as validate_current_jwt,
19
+ jwt__expiration__validate as validate__current__jwt,
20
+ }
@@ -0,0 +1,2 @@
1
+ export declare function jwt_token_exp_(jwt_token:string):number|null
2
+ export { jwt_token_exp_ as _jwt_token_exp, jwt_token_exp_ as _exp__jwt_token, }
@@ -1,6 +1,6 @@
1
1
  import { atob_ } from '@ctx-core/atob'
2
2
  /**
3
- * @param {string|nullish}jwt_token
3
+ * @param {string}jwt_token
4
4
  * @return {number|null}
5
5
  */
6
6
  export function jwt_token_exp_(jwt_token) {
@@ -11,4 +11,7 @@ export function jwt_token_exp_(jwt_token) {
11
11
  const jwt_data = JSON.parse(atob(atob_jwt_data))
12
12
  return jwt_data?.exp
13
13
  }
14
- export { jwt_token_exp_ as _jwt_token_exp, jwt_token_exp_ as _exp__jwt_token, }
14
+ export {
15
+ jwt_token_exp_ as _jwt_token_exp,
16
+ jwt_token_exp_ as _exp__jwt_token,
17
+ }
@@ -1,6 +0,0 @@
1
- import { type nullish } from '@ctx-core/function'
2
- export declare function header_authorization_jwt_token_(authorization:string|nullish):string|null
3
- export {
4
- header_authorization_jwt_token_ as _header_authorization_jwt_token,
5
- header_authorization_jwt_token_ as _jwt_token__authorization__header,
6
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * @param {string|nullish}authorization
3
- * @return {string|null}
4
- */
5
- export function header_authorization_jwt_token_(authorization) {
6
- const authorization_a = authorization?.split(/^Bearer */)
7
- return authorization_a ? authorization_a[1] : null
8
- }
9
- export {
10
- header_authorization_jwt_token_ as _header_authorization_jwt_token,
11
- header_authorization_jwt_token_ as _jwt_token__authorization__header,
12
- }
@@ -1,3 +0,0 @@
1
- import { type nullish } from '@ctx-core/function'
2
- export declare function jwt_token_exp_(jwt_token:string|nullish):number|null
3
- export { jwt_token_exp_ as _jwt_token_exp, jwt_token_exp_ as _exp__jwt_token, }
@@ -1,3 +0,0 @@
1
- import { type nullish } from '@ctx-core/function'
2
- export declare function validate_current_jwt(jwt_token:string|nullish):void
3
- export { validate_current_jwt as validate__current__jwt }
@@ -1,17 +0,0 @@
1
- import { throw_bad_credentials } from '@ctx-core/error'
2
- import { jwt_token_exp_ } from './jwt_token_exp_.js'
3
- /**
4
- * @param {string|nullish}jwt_token
5
- */
6
- export function validate_current_jwt(jwt_token) {
7
- const jwt_token_exp = jwt_token_exp_(jwt_token)
8
- if (jwt_token_exp === null) return
9
- const jwt_token_exp_millis = jwt_token_exp * 1000
10
- if (Date.now() > jwt_token_exp_millis) {
11
- throw_bad_credentials({
12
- jwt_token,
13
- error_message: 'Session Expired'
14
- })
15
- }
16
- }
17
- export { validate_current_jwt as validate__current__jwt }