4 Commits

Author SHA1 Message Date
41a0f1839f fix: safer (and correct) isUnauthorizedError 2023-04-02 23:32:28 +02:00
71e0d82655 fix: safer isUnauthorizedError type guard 2023-04-02 23:04:41 +02:00
03e8d51f9a fix: bump jsonwebtoken to v9.0.0
fixes #342

It introduces several security fixes to follow best practices.
2023-01-10 20:57:23 +01:00
bf234bd7b8 docs: client side usage, specify build in import 2022-09-09 12:10:12 +02:00
13 changed files with 4742 additions and 12652 deletions

View File

@ -10,10 +10,10 @@ jobs:
build:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v3.0.0'
- uses: 'actions/checkout@v3.5.0'
- name: 'Use Node.js'
uses: 'actions/setup-node@v3.1.0'
uses: 'actions/setup-node@v3.6.0'
with:
node-version: 'lts/*'
cache: 'npm'
@ -23,3 +23,5 @@ jobs:
- name: 'Build'
run: 'npm run build'
- run: 'npm run build:typescript'

View File

@ -10,10 +10,10 @@ jobs:
lint:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v3.0.0'
- uses: 'actions/checkout@v3.5.0'
- name: 'Use Node.js'
uses: 'actions/setup-node@v3.1.0'
uses: 'actions/setup-node@v3.6.0'
with:
node-version: 'lts/*'
cache: 'npm'
@ -24,5 +24,5 @@ jobs:
- run: 'npm run lint:commit -- --to "${{ github.sha }}"'
- run: 'npm run lint:editorconfig'
- run: 'npm run lint:markdown'
- run: 'npm run lint:typescript'
- run: 'npm run lint:eslint'
- run: 'npm run lint:prettier'

View File

@ -8,10 +8,10 @@ jobs:
release:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v3.0.0'
- uses: 'actions/checkout@v3.5.0'
- name: 'Use Node.js'
uses: 'actions/setup-node@v3.1.0'
uses: 'actions/setup-node@v3.6.0'
with:
node-version: 'lts/*'
cache: 'npm'
@ -22,6 +22,8 @@ jobs:
- name: 'Build Package'
run: 'npm run build'
- run: 'npm run build:typescript'
- name: 'Release'
run: 'npm run release'
env:

View File

@ -10,10 +10,10 @@ jobs:
test:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v3.0.0'
- uses: 'actions/checkout@v3.5.0'
- name: 'Use Node.js'
uses: 'actions/setup-node@v3.1.0'
uses: 'actions/setup-node@v3.6.0'
with:
node-version: 'lts/*'
cache: 'npm'

View File

@ -3,3 +3,4 @@
npm run lint:staged
npm run build
npm run build:typescript

View File

@ -1,10 +1,5 @@
{
"config": {
"default": true,
"MD013": false,
"MD033": false,
"MD041": false
},
"globs": ["**/*.{md,mdx}"],
"ignores": ["**/node_modules"]
"ignores": ["**/node_modules"],
"customRules": ["markdownlint-rule-relative-links"]
}

7
.markdownlint.json Normal file
View File

@ -0,0 +1,7 @@
{
"default": true,
"relative-links": true,
"extends": "markdownlint/style/prettier",
"MD033": false,
"MD041": false
}

View File

@ -132,7 +132,7 @@ io.on('connection', async (socket) => {
```ts
import { io } from 'socket.io-client'
import { isUnauthorizedError } from '@thream/socketio-jwt/UnauthorizedError.js'
import { isUnauthorizedError } from '@thream/socketio-jwt/build/UnauthorizedError.js'
// Require Bearer Token
const socket = io('http://localhost:9000', {

17264
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -31,12 +31,13 @@
},
"homepage": "https://github.com/Thream/socketio-jwt#readme",
"scripts": {
"build": "rimraf ./build && swc ./src --out-dir ./build && tsc",
"build": "rimraf ./build && swc ./src --out-dir ./build",
"build:dev": "swc ./src --out-dir ./build --watch",
"build:typescript": "tsc",
"lint:commit": "commitlint",
"lint:editorconfig": "editorconfig-checker",
"lint:markdown": "markdownlint-cli2",
"lint:typescript": "eslint \"**/*.{js,jsx,ts,tsx}\" --ignore-path \".gitignore\"",
"lint:eslint": "eslint \"**/*.{js,jsx,ts,tsx}\" --ignore-path \".gitignore\"",
"lint:prettier": "prettier \".\" --check --ignore-path \".gitignore\"",
"lint:staged": "lint-staged",
"test": "c8 tap",
@ -49,39 +50,41 @@
"socket.io": ">=3.0.0"
},
"dependencies": {
"jsonwebtoken": "8.5.1"
"jsonwebtoken": "9.0.0"
},
"devDependencies": {
"@commitlint/cli": "17.1.2",
"@commitlint/config-conventional": "17.1.0",
"@swc/cli": "0.1.57",
"@swc/core": "1.2.249",
"@types/jsonwebtoken": "8.5.9",
"@types/node": "18.7.16",
"@types/tap": "15.0.7",
"@typescript-eslint/eslint-plugin": "5.36.2",
"@typescript-eslint/parser": "5.36.2",
"axios": "0.27.2",
"c8": "7.12.0",
"editorconfig-checker": "4.0.2",
"eslint": "8.23.0",
"eslint-config-conventions": "4.0.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0",
"@commitlint/cli": "17.5.1",
"@commitlint/config-conventional": "17.4.4",
"@swc/cli": "0.1.62",
"@swc/core": "1.3.44",
"@tsconfig/strictest": "2.0.0",
"@types/jsonwebtoken": "9.0.1",
"@types/node": "18.15.11",
"@types/tap": "15.0.8",
"@typescript-eslint/eslint-plugin": "5.57.0",
"@typescript-eslint/parser": "5.57.0",
"axios": "1.3.4",
"c8": "7.13.0",
"editorconfig-checker": "5.0.1",
"eslint": "8.37.0",
"eslint-config-conventions": "8.0.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-promise": "6.0.1",
"eslint-plugin-unicorn": "43.0.2",
"fastify": "4.5.3",
"husky": "8.0.1",
"lint-staged": "13.0.3",
"markdownlint-cli2": "0.5.1",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-unicorn": "46.0.0",
"fastify": "4.15.0",
"husky": "8.0.3",
"lint-staged": "13.2.0",
"markdownlint-cli2": "0.6.0",
"markdownlint-rule-relative-links": "1.1.2",
"pinst": "3.0.0",
"prettier": "2.7.1",
"rimraf": "3.0.2",
"semantic-release": "19.0.5",
"socket.io": "4.5.2",
"socket.io-client": "4.5.2",
"tap": "16.3.0",
"typescript": "4.8.3"
"prettier": "2.8.7",
"rimraf": "4.4.1",
"semantic-release": "21.0.1",
"socket.io": "4.6.1",
"socket.io-client": "4.6.1",
"tap": "16.3.4",
"typescript": "5.0.3"
}
}

View File

@ -15,6 +15,16 @@ export class UnauthorizedError extends Error {
}
}
export const isUnauthorizedError = (error: any): error is UnauthorizedError => {
return error.data.type === 'UnauthorizedError'
export const isUnauthorizedError = (
error: unknown
): error is UnauthorizedError => {
return (
typeof error === 'object' &&
error != null &&
'data' in error &&
typeof error.data === 'object' &&
error.data != null &&
'type' in error.data &&
error.data.type === 'UnauthorizedError'
)
}

View File

@ -62,7 +62,7 @@ export const authorize = (options: AuthorizeOptions): SocketIOMiddleware => {
}
socket.encodedToken = encodedToken
let keySecret: string | null = null
let decodedToken: any
let decodedToken: any = null
if (typeof secret === 'string') {
keySecret = secret
} else {

View File

@ -1,4 +1,5 @@
{
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
@ -7,9 +8,6 @@
"outDir": "./build",
"rootDir": "./src",
"emitDeclarationOnly": true,
"declaration": true,
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true
"declaration": true
}
}