@ctx-core/jwt 10.0.51 → 10.1.2

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,24 @@
1
1
  # @ctx-core/jwt
2
2
 
3
+ ## 10.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - update dependencies
8
+
9
+ ## 10.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - fix: package.json: lib=>src
14
+
15
+ ## 10.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - JwtToken: + expires_in: number
20
+ - JwtToken: aliased by Token
21
+
3
22
  ## 10.0.51
4
23
 
5
24
  ### Patch Changes
Binary file
package/package.json CHANGED
@@ -1,53 +1,56 @@
1
1
  {
2
- "name": "@ctx-core/jwt",
3
- "version": "10.0.51",
4
- "description": "ctx-core jwt",
5
- "keywords": [
6
- "ctx-core",
7
- "jwt"
8
- ],
9
- "homepage": "https://github.com/ctx-core/jwt#readme",
10
- "bugs": {
11
- "url": "https://github.com/ctx-core/jwt/issues"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/ctx-core/jwt.git"
16
- },
17
- "license": "Apache-2.0",
18
- "author": "Brian Takita",
19
- "type": "module",
20
- "types": "./lib/index.d.ts",
21
- "exports": {
22
- ".": {
23
- "import": "./lib/index.js"
24
- },
25
- "./package.json": "./package.json"
26
- },
27
- "dependencies": {
28
- "@ctx-core/atob": "^10.0.47",
29
- "@ctx-core/error": "^11.3.1",
30
- "@ctx-core/function": "20.4.0",
31
- "@swc/cli": "^0.1.55",
32
- "@swc/core": "^1.2.136"
33
- },
34
- "devDependencies": {
35
- "rimraf": "^3.0.2",
36
- "typescript": "next"
37
- },
38
- "publishConfig": {
39
- "access": "public",
40
- "cache": "~/.npm"
41
- },
42
- "svelte": "./lib/index.js",
43
- "sideEffects": false,
44
- "scripts": {
45
- "build": "npm run compile",
46
- "clean": "rimraf lib && npm run clean:tsbuildinfo",
47
- "clean:tsbuildinfo": "rimraf tsconfig.tsbuildinfo && rimraf lib/**/*.d.ts",
48
- "compile": "npm run compile:source && npm run compile:declaration",
49
- "compile:source": "swc src --out-dir lib --copy-files --source-maps --config-file .swcrc",
50
- "compile:declaration": "npm run clean:tsbuildinfo && tsc --declaration --emitDeclarationOnly --declarationDir lib",
51
- "exec": "$@"
52
- }
53
- }
2
+ "name": "@ctx-core/jwt",
3
+ "version": "10.1.2",
4
+ "description": "ctx-core jwt",
5
+ "keywords": [
6
+ "ctx-core",
7
+ "jwt"
8
+ ],
9
+ "homepage": "https://github.com/ctx-core/jwt#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/ctx-core/jwt/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/ctx-core/jwt.git"
16
+ },
17
+ "license": "Apache-2.0",
18
+ "author": "Brian Takita",
19
+ "type": "module",
20
+ "types": "./src/index.d.ts",
21
+ "svelte": "./src/index.js",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./src/index.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "scripts": {
29
+ "build": ":",
30
+ "clean": ":",
31
+ "exec": "$@",
32
+ "prepublishOnly": "npm run clean && npm run build && npm run test",
33
+ "test": "pnpm test-unit && check-dts",
34
+ "test-unit": "tsm node_modules/uvu/bin.js . '\\.test\\.(ts|js)$'",
35
+ "test-unit-coverage": "c8 pnpm test-unit"
36
+ },
37
+ "dependencies": {
38
+ "@ctx-core/atob": "^10.0.49",
39
+ "@ctx-core/error": "^11.4.0",
40
+ "@ctx-core/function": "*",
41
+ "@swc/cli": "^0.1.55",
42
+ "@swc/core": "^1.2.147"
43
+ },
44
+ "devDependencies": {
45
+ "c8": "^7.11.0",
46
+ "check-dts": "^0.6.6",
47
+ "tsm": "^2.2.1",
48
+ "typescript": "next",
49
+ "uvu": "^0.5.3"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "cache": "~/.npm"
54
+ },
55
+ "sideEffects": false
56
+ }
@@ -0,0 +1,11 @@
1
+ import type { error_ctx_I } from '@ctx-core/error'
2
+ import type { nullish } from '@ctx-core/function'
3
+ export interface JwtToken {
4
+ access_token:string
5
+ token_type:string
6
+ id_token?:string
7
+ email?:string
8
+ error?:error_ctx_I|nullish
9
+ expires_in?:number
10
+ }
11
+ export type Token = JwtToken
@@ -0,0 +1,2 @@
1
+ export * from './jwt_error_ctx_I'
2
+ export * from './JwtToken'
@@ -0,0 +1,6 @@
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,7 +1,10 @@
1
- import type { nullish } from '@ctx-core/function'
2
- export function header_authorization_jwt_token_(authorization:string|nullish):string|undefined {
1
+ /**
2
+ * @param {string|nullish}authorization
3
+ * @return {string|null}
4
+ */
5
+ export function header_authorization_jwt_token_(authorization) {
3
6
  const authorization_a = authorization?.split(/^Bearer */)
4
- return authorization_a ? authorization_a[1] : undefined
7
+ return authorization_a ? authorization_a[1] : null
5
8
  }
6
9
  export {
7
10
  header_authorization_jwt_token_ as _header_authorization_jwt_token,
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './_types'
2
+ export * from './header_authorization_jwt_token_'
3
+ export * from './jwt_token_exp_'
4
+ export * from './validate_current_jwt'
@@ -1,5 +1,3 @@
1
1
  export * from './header_authorization_jwt_token_.js'
2
- export * from './jwt_error_ctx_I.js'
3
2
  export * from './jwt_token_exp_.js'
4
- export * from './JwtToken.js'
5
3
  export * from './validate_current_jwt.js'
@@ -0,0 +1,3 @@
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, }
@@ -0,0 +1,12 @@
1
+ import { atob_ } from '@ctx-core/atob'
2
+ /**
3
+ * @param {string|nullish}jwt_token
4
+ * @return {number|null}
5
+ */
6
+ export function jwt_token_exp_(jwt_token) {
7
+ const atob = atob_()
8
+ if (!jwt_token) return null
9
+ const jwt_data = JSON.parse(atob(jwt_token.split('.')[1]))
10
+ return jwt_data?.exp
11
+ }
12
+ export { jwt_token_exp_ as _jwt_token_exp, jwt_token_exp_ as _exp__jwt_token, }
@@ -0,0 +1,3 @@
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 +1,17 @@
1
1
  import { throw_bad_credentials } from '@ctx-core/error'
2
- import type { nullish } from '@ctx-core/function'
3
- import type { jwt_error_ctx_I } from './jwt_error_ctx_I.js'
4
2
  import { jwt_token_exp_ } from './jwt_token_exp_.js'
5
- export function validate_current_jwt(jwt_token:string|nullish):void {
3
+ /**
4
+ * @param {string|nullish}jwt_token
5
+ */
6
+ export function validate_current_jwt(jwt_token) {
6
7
  const jwt_token_exp = jwt_token_exp_(jwt_token)
8
+ if (jwt_token_exp === null) return
7
9
  const jwt_token_exp_millis = jwt_token_exp * 1000
8
10
  if (Date.now() > jwt_token_exp_millis) {
9
11
  throw_bad_credentials({
10
12
  jwt_token,
11
13
  error_message: 'Session Expired'
12
- } as jwt_error_ctx_I)
14
+ })
13
15
  }
14
16
  }
15
- export {
16
- validate_current_jwt as validate__current__jwt
17
- }
17
+ export { validate_current_jwt as validate__current__jwt }
package/.swcrc DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "jsc": {
3
- "target": "es2020",
4
- "parser": {
5
- "syntax": "typescript",
6
- "tsx": true,
7
- "dynamicImport": true
8
- }
9
- }
10
- }
package/lib/JwtToken.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { error_ctx_I } from '@ctx-core/error';
2
- import type { maybe, nullish } from '@ctx-core/function';
3
- export interface Token {
4
- access_token: string;
5
- token_type: string;
6
- id_token?: string;
7
- email?: string;
8
- error?: maybe<error_ctx_I, nullish>;
9
- }
package/lib/JwtToken.js DELETED
@@ -1,3 +0,0 @@
1
- export { };
2
-
3
- //# sourceMappingURL=JwtToken.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/JwtToken.ts"],"sourcesContent":["import type { error_ctx_I } from '@ctx-core/error'\nimport type { maybe, nullish } from '@ctx-core/function'\nexport interface Token {\n\taccess_token: string\n\ttoken_type: string\n\tid_token?:string\n\temail?:string\n\terror?:maybe<error_ctx_I, nullish>\n}\n"],"names":[],"mappings":"AAAA,MAAM"}
@@ -1,3 +0,0 @@
1
- import type { nullish } from '@ctx-core/function';
2
- export declare function header_authorization_jwt_token_(authorization: string | nullish): string | undefined;
3
- export { header_authorization_jwt_token_ as _header_authorization_jwt_token, header_authorization_jwt_token_ as _jwt_token__authorization__header, };
@@ -1,7 +0,0 @@
1
- export function header_authorization_jwt_token_(authorization) {
2
- const authorization_a = authorization?.split(/^Bearer */);
3
- return authorization_a ? authorization_a[1] : undefined;
4
- }
5
- export { header_authorization_jwt_token_ as _header_authorization_jwt_token, header_authorization_jwt_token_ as _jwt_token__authorization__header, };
6
-
7
- //# sourceMappingURL=header_authorization_jwt_token_.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/header_authorization_jwt_token_.ts"],"sourcesContent":["import type { nullish } from '@ctx-core/function'\nexport function header_authorization_jwt_token_(authorization:string|nullish):string|undefined {\n\tconst authorization_a = authorization?.split(/^Bearer */)\n\treturn authorization_a ? authorization_a[1] : undefined\n}\nexport {\n\theader_authorization_jwt_token_ as _header_authorization_jwt_token,\n\theader_authorization_jwt_token_ as _jwt_token__authorization__header,\n}\n"],"names":["header_authorization_jwt_token_","authorization","authorization_a","split","undefined","_header_authorization_jwt_token","_jwt_token__authorization__header"],"mappings":"AACA,MAAM,UAAUA,+BAA+B,CAACC,aAA4B,EAAmB,CAAC;IAC/F,KAAK,CAACC,eAAe,GAAGD,aAAa,EAAEE,KAAK;IAC5C,MAAM,CAACD,eAAe,GAAGA,eAAe,CAAC,CAAC,IAAIE,SAAS;AACxD,CAAC;AACD,MAAM,GACLJ,+BAA+B,IAAIK,+BAA+B,EAClEL,+BAA+B,IAAIM,iCAAiC"}
package/lib/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './header_authorization_jwt_token_.js';
2
- export * from './jwt_error_ctx_I.js';
3
- export * from './jwt_token_exp_.js';
4
- export * from './JwtToken.js';
5
- export * from './validate_current_jwt.js';
package/lib/index.js DELETED
@@ -1,7 +0,0 @@
1
- export * from './header_authorization_jwt_token_.js';
2
- export * from './jwt_error_ctx_I.js';
3
- export * from './jwt_token_exp_.js';
4
- export * from './JwtToken.js';
5
- export * from './validate_current_jwt.js';
6
-
7
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './header_authorization_jwt_token_.js'\nexport * from './jwt_error_ctx_I.js'\nexport * from './jwt_token_exp_.js'\nexport * from './JwtToken.js'\nexport * from './validate_current_jwt.js'\n"],"names":[],"mappings":"cAAc,CAAsC;cACtC,CAAsB;cACtB,CAAqB;cACrB,CAAe;cACf,CAA2B"}
@@ -1,4 +0,0 @@
1
- import type { error_ctx_I } from '@ctx-core/error';
2
- export interface jwt_error_ctx_I extends error_ctx_I {
3
- jwt_token: string;
4
- }
@@ -1,3 +0,0 @@
1
- export { };
2
-
3
- //# sourceMappingURL=jwt_error_ctx_I.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/jwt_error_ctx_I.ts"],"sourcesContent":["import type { error_ctx_I } from '@ctx-core/error'\nexport interface jwt_error_ctx_I extends error_ctx_I {\n\tjwt_token:string\n}\n"],"names":[],"mappings":"AAAA,MAAM"}
@@ -1,3 +0,0 @@
1
- import type { nullish } from '@ctx-core/function';
2
- export declare function jwt_token_exp_(jwt_token: string | nullish): number;
3
- export { jwt_token_exp_ as _jwt_token_exp, jwt_token_exp_ as _exp__jwt_token, };
@@ -1,9 +0,0 @@
1
- import { atob_ } from '@ctx-core/atob';
2
- export function jwt_token_exp_(jwt_token) {
3
- const atob = atob_();
4
- const jwt_data = jwt_token && JSON.parse(atob(jwt_token.split('.')[1]));
5
- return jwt_data?.exp;
6
- }
7
- export { jwt_token_exp_ as _jwt_token_exp, jwt_token_exp_ as _exp__jwt_token, };
8
-
9
- //# sourceMappingURL=jwt_token_exp_.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/jwt_token_exp_.ts"],"sourcesContent":["import { atob_ } from '@ctx-core/atob'\nimport type { nullish } from '@ctx-core/function'\nexport function jwt_token_exp_(jwt_token:string|nullish):number {\n\tconst atob = atob_()\n\tconst jwt_data = jwt_token && JSON.parse(atob(jwt_token.split('.')[1]))\n\treturn jwt_data?.exp\n}\nexport {\n\tjwt_token_exp_ as _jwt_token_exp,\n\tjwt_token_exp_ as _exp__jwt_token,\n}\n"],"names":["atob_","jwt_token_exp_","jwt_token","atob","jwt_data","JSON","parse","split","exp","_jwt_token_exp","_exp__jwt_token"],"mappings":"AAAA,MAAM,GAAGA,KAAK,QAAQ,CAAgB;AAEtC,MAAM,UAAUC,cAAc,CAACC,SAAwB,EAAS,CAAC;IAChE,KAAK,CAACC,IAAI,GAAGH,KAAK;IAClB,KAAK,CAACI,QAAQ,GAAGF,SAAS,IAAIG,IAAI,CAACC,KAAK,CAACH,IAAI,CAACD,SAAS,CAACK,KAAK,CAAC,CAAG,IAAE,CAAC;IACpE,MAAM,CAACH,QAAQ,EAAEI,GAAG;AACrB,CAAC;AACD,MAAM,GACLP,cAAc,IAAIQ,cAAc,EAChCR,cAAc,IAAIS,eAAe"}
@@ -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,15 +0,0 @@
1
- import { throw_bad_credentials } from '@ctx-core/error';
2
- import { jwt_token_exp_ } from './jwt_token_exp_.js';
3
- export function validate_current_jwt(jwt_token) {
4
- const jwt_token_exp = jwt_token_exp_(jwt_token);
5
- const jwt_token_exp_millis = jwt_token_exp * 1000;
6
- if (Date.now() > jwt_token_exp_millis) {
7
- throw_bad_credentials({
8
- jwt_token,
9
- error_message: 'Session Expired'
10
- });
11
- }
12
- }
13
- export { validate_current_jwt as validate__current__jwt };
14
-
15
- //# sourceMappingURL=validate_current_jwt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/validate_current_jwt.ts"],"sourcesContent":["import { throw_bad_credentials } from '@ctx-core/error'\nimport type { nullish } from '@ctx-core/function'\nimport type { jwt_error_ctx_I } from './jwt_error_ctx_I.js'\nimport { jwt_token_exp_ } from './jwt_token_exp_.js'\nexport function validate_current_jwt(jwt_token:string|nullish):void {\n\tconst jwt_token_exp = jwt_token_exp_(jwt_token)\n\tconst jwt_token_exp_millis = jwt_token_exp * 1000\n\tif (Date.now() > jwt_token_exp_millis) {\n\t\tthrow_bad_credentials({\n\t\t\tjwt_token,\n\t\t\terror_message: 'Session Expired'\n\t\t} as jwt_error_ctx_I)\n\t}\n}\nexport {\n\tvalidate_current_jwt as validate__current__jwt\n}\n"],"names":["throw_bad_credentials","jwt_token_exp_","validate_current_jwt","jwt_token","jwt_token_exp","jwt_token_exp_millis","Date","now","error_message","validate__current__jwt"],"mappings":"AAAA,MAAM,GAAGA,qBAAqB,QAAQ,CAAiB;AAGvD,MAAM,GAAGC,cAAc,QAAQ,CAAqB;AACpD,MAAM,UAAUC,oBAAoB,CAACC,SAAwB,EAAO,CAAC;IACpE,KAAK,CAACC,aAAa,GAAGH,cAAc,CAACE,SAAS;IAC9C,KAAK,CAACE,oBAAoB,GAAGD,aAAa,GAAG,IAAI;IACjD,EAAE,EAAEE,IAAI,CAACC,GAAG,KAAKF,oBAAoB,EAAE,CAAC;QACvCL,qBAAqB,CAAC,CAAC;YACtBG,SAAS;YACTK,aAAa,EAAE,CAAiB;QACjC,CAAC;IACF,CAAC;AACF,CAAC;AACD,MAAM,GACLN,oBAAoB,IAAIO,sBAAsB"}
package/src/JwtToken.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { error_ctx_I } from '@ctx-core/error'
2
- import type { maybe, nullish } from '@ctx-core/function'
3
- export interface Token {
4
- access_token: string
5
- token_type: string
6
- id_token?:string
7
- email?:string
8
- error?:maybe<error_ctx_I, nullish>
9
- }
@@ -1,11 +0,0 @@
1
- import { atob_ } from '@ctx-core/atob'
2
- import type { nullish } from '@ctx-core/function'
3
- export function jwt_token_exp_(jwt_token:string|nullish):number {
4
- const atob = atob_()
5
- const jwt_data = jwt_token && JSON.parse(atob(jwt_token.split('.')[1]))
6
- return jwt_data?.exp
7
- }
8
- export {
9
- jwt_token_exp_ as _jwt_token_exp,
10
- jwt_token_exp_ as _exp__jwt_token,
11
- }