84 Commits

Author SHA1 Message Date
9eedd5afbd chore: add semantic-release
close #153
2021-07-23 23:15:52 +02:00
dff86f7bda build(deps): bump jest from 26.6.3 to 27.0.6
close #128
2021-07-23 23:00:25 +02:00
a41881744a fix(types): onAuthorization can return a string 2021-07-23 22:54:07 +02:00
15f5c60b27 build(deps-dev): bump @types/node to 16.4.1 (#171) 2021-07-23 08:49:11 +02:00
56fb31edf6 build(deps-dev): bump markdownlint-cli from 0.27.1 to 0.28.1 (#172) 2021-07-23 08:34:29 +02:00
c08c431e6a build(deps): bump wagoid/commitlint-github-action to 4.1.1 (#167) 2021-07-22 08:07:00 +02:00
4ae9f519c5 build(deps): bump codecov/codecov-action from 1.5.2 to 2.0.1 (#168) 2021-07-22 08:06:17 +02:00
e4dcdf9928 build(deps): bump actions/setup-node from 2.2.0 to 2.3.0 (#169) 2021-07-22 08:05:56 +02:00
f08a6e4f62 build(deps-dev): bump socket.io-client from 4.1.2 to 4.1.3 (#161) 2021-07-18 00:33:11 +02:00
18df1dd19f build(deps-dev): bump socket.io from 4.1.2 to 4.1.3 (#162) 2021-07-16 23:25:29 +02:00
86cac11108 build(deps): bump wagoid/commitlint-github-action to 4.0.2 (#165) 2021-07-16 23:25:14 +02:00
170ad34da3 build(deps-dev): bump @types/jsonwebtoken from 8.5.3 to 8.5.4 (#155) 2021-07-07 21:40:27 +02:00
b5460b95ee build(deps-dev): bump @types/express from 4.17.12 to 4.17.13 (#156) 2021-07-07 21:40:16 +02:00
b1ab84e610 build(deps-dev): bump husky from 7.0.0 to 7.0.1 (#157) 2021-07-07 21:40:03 +02:00
b56248919e build(deps-dev): bump @types/jsonwebtoken to 8.5.3 (#152) 2021-07-02 10:19:49 +02:00
464381813f build(deps-dev): bump husky from 6.0.0 to 7.0.0 (#149) 2021-07-01 09:33:45 +02:00
6dc3696910 build(deps): bump actions/setup-node from 2.1.5 to 2.2.0 (#148) 2021-07-01 09:27:46 +02:00
e500fd3862 build(deps-dev): bump typescript to 4.3.5 (#150) 2021-07-01 09:03:53 +02:00
30aea8120a build(deps-dev): bump @types/jsonwebtoken to 8.5.2 (#142) 2021-06-23 13:30:42 +02:00
87d3af481e build(deps-dev): bump release-it to 14.10.0 (#144) 2021-06-23 13:30:25 +02:00
8867b9914e build(deps-dev): bump @release-it/conventional-changelog to 3.0.1 (#137) 2021-06-18 18:35:18 +02:00
8ae78c6732 build(deps-dev): bump typescript to 4.3.4 (#140) 2021-06-18 18:34:30 +02:00
def5b56184 build(deps-dev): bump release-it from 14.8.0 to 14.9.0 (#138)
Bumps [release-it](https://github.com/release-it/release-it) from 14.8.0 to 14.9.0.
- [Release notes](https://github.com/release-it/release-it/releases)
- [Changelog](https://github.com/release-it/release-it/blob/master/CHANGELOG.md)
- [Commits](https://github.com/release-it/release-it/compare/14.8.0...14.9.0)

---
updated-dependencies:
- dependency-name: release-it
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-15 23:34:11 +02:00
983d18ee09 build(deps): bump codecov/codecov-action from 1.5.0 to 1.5.2 (#136) 2021-06-12 22:03:42 +02:00
16f632d1b4 build(deps-dev): bump release-it from 14.7.0 to 14.8.0 (#134) 2021-06-12 22:03:31 +02:00
65bc3314cc chore: ci pass again (update jest later) 2021-05-28 10:13:00 +02:00
d6bd5e5cd7 build(deps-dev): bump typescript from 4.2.4 to 4.3.2 (#126) 2021-05-28 09:18:22 +02:00
96a41659bd build(deps): bump actions/cache from 2.1.5 to 2.1.6 (#127) 2021-05-28 09:18:03 +02:00
e5fca7e5ee build(deps-dev): bump jest from 26.6.3 to 27.0.1 (#123) 2021-05-26 18:45:48 +02:00
da40d6b1fd build(deps-dev): bump @types/express from 4.17.11 to 4.17.12 (#124) 2021-05-26 18:45:33 +02:00
219094da40 build(deps-dev): bump release-it from 14.6.2 to 14.7.0 (#122) 2021-05-25 18:07:56 +02:00
6361bd8782 build(deps-dev): bump @types/node from 15.6.0 to 15.6.1 (#121) 2021-05-25 18:07:33 +02:00
59efee7c37 build(deps-dev): bump @types/node from 15.3.1 to 15.6.0 (#120) 2021-05-24 11:29:11 +02:00
07c96e876b build(deps-dev): bump @types/node to 15.3.1 (#119) 2021-05-20 15:02:21 +02:00
ae08cc6e65 build(deps-dev): bump socket.io from 4.1.1 to 4.1.2 (#117) 2021-05-20 15:02:03 +02:00
3bae2e2bbf build(deps): bump wagoid/commitlint-github-action to 3.1.4 (#118) 2021-05-20 15:01:46 +02:00
47e69050e5 build(deps-dev): bump socket.io-client from 4.1.1 to 4.1.2 (#116) 2021-05-19 19:58:38 +02:00
9851fb319d build(deps-dev): bump @types/node from 15.0.3 to 15.3.0 (#115) 2021-05-17 16:29:51 +02:00
73fc64b9e5 build(deps-dev): bump @commitlint/cli from 12.1.1 to 12.1.4 (#112) 2021-05-15 15:59:19 +02:00
e300799e99 build(deps-dev): bump @commitlint/config-conventional (#114) 2021-05-13 13:37:14 +02:00
f6755c7d12 build(deps-dev): bump @types/node from 15.0.2 to 15.0.3 (#113) 2021-05-13 13:37:01 +02:00
5e16b06575 build(deps-dev): bump socket.io from 4.1.0 to 4.1.1 (#111) 2021-05-13 13:36:49 +02:00
a5468fdfae build(deps-dev): bump socket.io-client from 4.1.0 to 4.1.1 (#110) 2021-05-12 16:41:27 +02:00
4b86c778bf build(deps): bump codecov/codecov-action from 1 to 1.5.0 (#108) 2021-05-12 16:41:17 +02:00
a14e6e5ab1 build(deps): bump actions/checkout from 2 to 2.3.4 (#109) 2021-05-12 16:41:03 +02:00
927f021941 build(deps-dev): bump socket.io from 4.0.1 to 4.1.0 (#107) 2021-05-11 21:18:26 +02:00
344f71ced1 build(deps-dev): bump socket.io-client from 4.0.1 to 4.1.0 (#106) 2021-05-11 21:02:35 +02:00
3ce4b14d03 build(deps-dev): bump release-it from 14.6.1 to 14.6.2 (#103) 2021-05-11 18:29:05 +02:00
d11cbc3ffb build(deps): bump wagoid/commitlint-github-action from v3.1.0 to v3.1.3 (#105) 2021-05-11 18:28:53 +02:00
31ba9b48b5 build(deps-dev): bump ts-jest from 26.5.5 to 26.5.6 (#100) 2021-05-11 18:28:37 +02:00
88eba43f83 build(deps-dev): bump @types/node from 15.0.1 to 15.0.2 (#99) 2021-05-11 18:28:27 +02:00
9330edd3bc build(deps-dev): bump @types/node from 15.0.0 to 15.0.1 (#97) 2021-05-03 19:25:44 +02:00
2412e2e5fc build(deps-dev): bump @types/jest from 26.0.22 to 26.0.23 (#95) 2021-04-27 09:32:05 +02:00
7cfab50330 build(deps-dev): bump @types/node from 14.14.41 to 15.0.0 (#96) 2021-04-27 09:31:54 +02:00
644e3a52b7 build(deps-dev): bump ts-jest from 26.5.4 to 26.5.5 (#91) 2021-04-18 22:03:14 +02:00
1f912feda1 build(deps-dev): bump @types/node from 14.14.39 to 14.14.41 (#92) 2021-04-18 22:02:59 +02:00
6dcb8cbd49 build(deps-dev): bump @types/node from 14.14.37 to 14.14.39 (#90) 2021-04-15 18:17:33 +02:00
a93271bcec build(deps-dev): bump release-it from 14.5.1 to 14.6.1 (#88) 2021-04-14 14:10:38 +02:00
68e02a6ad5 build(deps): bump actions/cache from v2.1.4 to v2.1.5 (#89) 2021-04-14 14:10:26 +02:00
efb2b72572 build(deps-dev): bump typescript from 4.2.3 to 4.2.4 (#87) 2021-04-08 10:04:03 +02:00
4c869ba0ea build(deps): bump wagoid/commitlint-github-action from v3.0.8 to v3.1.0 (#86) 2021-04-07 19:36:16 +02:00
79c88b928b build(deps): bump wagoid/commitlint-github-action from v3.0.7 to v3.0.8 (#85) 2021-04-05 10:18:27 +02:00
f0f58630d9 build(deps-dev): bump @commitlint/config-conventional (#81) 2021-04-03 09:55:26 +02:00
cf81ca58fc build(deps-dev): bump @commitlint/cli from 12.0.1 to 12.1.1 (#82) 2021-04-03 09:53:19 +02:00
1255f7545e build(deps-dev): bump release-it from 14.5.0 to 14.5.1 (#83) 2021-04-03 09:53:08 +02:00
8570861d16 build(deps-dev): bump socket.io-client from 4.0.0 to 4.0.1 (#79) 2021-04-03 09:52:57 +02:00
f90cddc4a4 build(deps): bump wagoid/commitlint-github-action from v3.0.6 to v3.0.7 (#84) 2021-04-03 09:52:41 +02:00
f260bc793b build(deps-dev): bump socket.io from 4.0.0 to 4.0.1 (#78) 2021-04-01 13:24:20 +02:00
089ca1b67e build(deps-dev): bump editorconfig-checker from 4.0.1 to 4.0.2 (#80) 2021-04-01 13:24:04 +02:00
6696d1fa0a build(deps-dev): bump husky from 5.2.0 to 6.0.0 (#76) 2021-03-29 18:58:23 +02:00
d4d4adac31 build(deps-dev): bump @types/node from 14.14.36 to 14.14.37 (#77) 2021-03-29 18:58:10 +02:00
c8723a736e build(deps-dev): bump @types/node from 14.14.35 to 14.14.36 (#75) 2021-03-27 15:04:27 +01:00
38a5036623 build(deps-dev): bump @types/jest from 26.0.21 to 26.0.22 (#74) 2021-03-27 15:04:13 +01:00
f1866e290d build(deps-dev): bump release-it from 14.4.1 to 14.5.0 (#72) 2021-03-23 10:39:21 +01:00
47d74534ea build(deps-dev): bump husky from 5.1.3 to 5.2.0 (#73) 2021-03-23 10:39:04 +01:00
0d0109be52 chore: add editorconfig-checker 2021-03-19 14:07:21 +01:00
85953cdcce build(deps-dev): bump ts-jest from 26.5.3 to 26.5.4 (#70) 2021-03-18 16:31:12 +01:00
da2be10ed4 build(deps-dev): bump @types/jest from 26.0.20 to 26.0.21 (#71) 2021-03-18 16:30:58 +01:00
1bb3e0174f build(deps-dev): bump @types/jsonwebtoken from 8.5.0 to 8.5.1 (#69) 2021-03-17 18:26:01 +01:00
a20ead358c build(deps-dev): bump @types/node from 14.14.34 to 14.14.35 (#68) 2021-03-17 18:25:06 +01:00
215593c6d6 build(deps-dev): bump @types/node from 14.14.33 to 14.14.34 (#67) 2021-03-15 19:09:26 +01:00
7380635760 build(deps-dev): bump socket.io-client from 3.1.2 to 4.0.0 (#66) 2021-03-11 16:09:32 +01:00
7f7dda651b build(deps-dev): bump socket.io from 3.1.2 to 4.0.0 (#65) 2021-03-11 16:05:38 +01:00
2512c046d2 build(deps-dev): bump @types/node from 14.14.32 to 14.14.33 (#64) 2021-03-10 14:24:11 +01:00
24 changed files with 11779 additions and 11510 deletions

View File

@ -1,11 +1,4 @@
<!-- <!-- Please first discuss the change you wish to make via issue before making a change. It might avoid a waste of your time. -->
Please first discuss the change you wish to make via issue before making a change. It might avoid a waste of your time.
Before submitting your contribution, please take a moment to review this document:
https://github.com/Thream/socketio-jwt/blob/master/CONTRIBUTING.md
-->
## What changes this PR introduce? ## What changes this PR introduce?

View File

@ -1,5 +1,3 @@
# For more information see: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2 version: 2
updates: updates:
- package-ecosystem: 'github-actions' - package-ecosystem: 'github-actions'

25
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: 'Build'
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
jobs:
build:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v2'
- name: 'Use Node.js'
uses: 'actions/setup-node@v2.3.0'
with:
node-version: '16.x'
cache: 'npm'
- name: 'Install'
run: 'npm install'
- name: 'Build Package'
run: 'npm run build'

View File

@ -1,22 +0,0 @@
# For more information see: https://github.com/marketplace/actions/commit-linter
name: 'Lint Commit Messages'
on:
push:
branches: [master, develop]
pull_request_review:
branches: [master, develop]
types: [submitted]
jobs:
commitlint:
if: ${{ (github.event_name == 'push') || (github.event_name == 'pull_request_review' && github.event.review.state == 'approved' && (github.event.review.author_association == 'COLLABORATOR' || github.event.review.author_association == 'MEMBER' || github.event.review.author_association == 'OWNER') && !github.event.pull_request.draft && github.event.pull_request.state == 'open') }}
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v2'
with:
fetch-depth: 0
- uses: 'wagoid/commitlint-github-action@v3.0.6'
with:
configFile: '.commitlintrc.json'

27
.github/workflows/lint.yml vendored Normal file
View File

@ -0,0 +1,27 @@
name: 'Lint'
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
jobs:
lint:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v2'
- name: 'Use Node.js'
uses: 'actions/setup-node@v2.3.0'
with:
node-version: '16.x'
cache: 'npm'
- name: 'Install'
run: 'npm install'
- run: 'npm run lint:commit -- --to "${{ github.sha }}"'
- run: 'npm run lint:editorconfig'
- run: 'npm run lint:markdown'
- run: 'npm run lint:typescript'

View File

@ -1,49 +0,0 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: 'Node.js CI'
on:
push:
branches: [master, develop]
pull_request_review:
branches: [master, develop]
types: [submitted]
jobs:
ci_app:
if: ${{ (github.event_name == 'push') || (github.event_name == 'pull_request_review' && github.event.review.state == 'approved' && (github.event.review.author_association == 'COLLABORATOR' || github.event.review.author_association == 'MEMBER' || github.event.review.author_association == 'OWNER') && !github.event.pull_request.draft && github.event.pull_request.state == 'open') }}
runs-on: 'ubuntu-latest'
strategy:
matrix:
node-version: [14.x]
steps:
- uses: 'actions/checkout@v2'
- name: Use Node.js ${{ matrix.node-version }}
uses: 'actions/setup-node@v2.1.5'
with:
node-version: ${{ matrix.node-version }}
- name: 'Cache dependencies'
uses: 'actions/cache@v2.1.4'
with:
path: '.npm'
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: 'Install dependencies'
run: 'npm ci --cache .npm --prefer-offline'
- name: 'Lint'
run: 'npm run lint'
- name: 'MarkdownLint'
run: 'npm run markdownlint'
- name: 'Build'
run: 'npm run build'
- name: 'Run the tests and generate coverage report'
run: 'npm test'
- name: 'Upload coverage to Codecov'
uses: 'codecov/codecov-action@v1'

View File

@ -1,36 +0,0 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
name: 'Node.js Package'
on:
release:
types: [created]
jobs:
publish-npm:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v2'
- name: Use Node.js ${{ matrix.node-version }}
uses: 'actions/setup-node@v2.1.5'
with:
node-version: 14
registry-url: 'https://registry.npmjs.org/'
- name: 'Cache dependencies'
uses: 'actions/cache@v2.1.4'
with:
path: '.npm'
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: 'Install dependencies'
run: 'npm ci --cache .npm --prefer-offline'
- name: 'Build'
run: 'npm run build'
- name: 'Publish package on npm'
run: 'npm publish --access public'
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

29
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: 'Release'
on:
push:
branches: [master]
jobs:
release:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v2'
- name: 'Use Node.js'
uses: 'actions/setup-node@v2.3.0'
with:
node-version: '16.x'
cache: 'npm'
- name: 'Install'
run: 'npm install'
- name: 'Build Package'
run: 'npm run build'
- name: 'Release'
run: 'npm run release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

28
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,28 @@
name: 'Test'
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
jobs:
test:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v2'
- name: 'Use Node.js'
uses: 'actions/setup-node@v2.3.0'
with:
node-version: '16.x'
cache: 'npm'
- name: 'Install'
run: 'npm install'
- name: 'Test'
run: 'npm run test'
- name: 'Upload Coverage'
uses: 'codecov/codecov-action@v2.0.1'

1
.husky/.gitignore vendored
View File

@ -1 +0,0 @@
_

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh
. "$(dirname "$0")/_/husky.sh" . "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit npm run lint:commit -- --edit

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
. "$(dirname "$0")/_/husky.sh" . "$(dirname "$0")/_/husky.sh"
npm run lint npm run lint:editorconfig
npm run markdownlint npm run lint:markdown
npm run lint:typescript
npm run build

19
.releaserc.json Normal file
View File

@ -0,0 +1,19 @@
{
"branches": ["master"],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits"
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits"
}
],
"@semantic-release/npm",
"@semantic-release/github"
]
}

132
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,132 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
- Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
contact@divlo.fr.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][mozilla coc].
For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][faq]. Translations are available
at [https://www.contributor-covenant.org/translations][translations].
[homepage]: https://www.contributor-covenant.org
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
[mozilla coc]: https://github.com/mozilla/diversity
[faq]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations

View File

@ -4,7 +4,7 @@ Thanks a lot for your interest in contributing to **Thream/socketio-jwt**! 🎉
## Code of Conduct ## Code of Conduct
**Thream** has adopted the [Contributor Covenant](https://www.contributor-covenant.org/) as its Code of Conduct, and we expect project participants to adhere to it. Please read [the full text](https://github.com/Thream/Thream/blob/master/.github/CODE_OF_CONDUCT.md) so that you can understand what actions will and will not be tolerated. **Thream** has adopted the [Contributor Covenant](https://www.contributor-covenant.org/) as its Code of Conduct, and we expect project participants to adhere to it. Please read [the full text](./CODE_OF_CONDUCT.md) so that you can understand what actions will and will not be tolerated.
## Open Development ## Open Development

View File

@ -5,14 +5,19 @@
</p> </p>
<p align="center"> <p align="center">
<a href="https://github.com/Thream/socketio-jwt/actions?query=workflow%3A%22Node.js+CI%22"><img src="https://github.com/Thream/socketio-jwt/workflows/Node.js%20CI/badge.svg" alt="Node.js CI" /></a> <a href="./CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" /></a>
<a href="https://codecov.io/gh/Thream/socketio-jwt"><img src="https://codecov.io/gh/Thream/socketio-jwt/branch/develop/graph/badge.svg" alt="codecov" /></a>
<a href="https://dependabot.com/"><img src="https://badgen.net/github/dependabot/Thream/socketio-jwt?icon=dependabot" alt="Dependabot badge" /></a>
<a href="https://www.npmjs.com/package/@thream/socketio-jwt"><img src="https://img.shields.io/npm/v/@thream/socketio-jwt.svg" alt="npm version"></a>
<a href="https://www.npmjs.com/package/ts-standard"><img alt="TypeScript Standard Style" src="https://camo.githubusercontent.com/f87caadb70f384c0361ec72ccf07714ef69a5c0a/68747470733a2f2f62616467656e2e6e65742f62616467652f636f64652532307374796c652f74732d7374616e646172642f626c75653f69636f6e3d74797065736372697074"/></a>
<a href="./LICENSE"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="Licence MIT"/></a> <a href="./LICENSE"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="Licence MIT"/></a>
<a href="./CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Contributor Covenant" /></a>
<a href="https://dependabot.com/"><img src="https://badgen.net/github/dependabot/Thream/socketio-jwt?icon=dependabot" alt="Dependabot badge" /></a>
<br/>
<a href="https://github.com/Thream/socketio-jwt/actions/workflows/build.yml"><img src="https://github.com/Thream/socketio-jwt/actions/workflows/build.yml/badge.svg?branch=develop" /></a>
<a href="https://github.com/Thream/socketio-jwt/actions/workflows/lint.yml"><img src="https://github.com/Thream/socketio-jwt/actions/workflows/lint.yml/badge.svg?branch=develop" /></a>
<a href="https://github.com/Thream/socketio-jwt/actions/workflows/test.yml"><img src="https://github.com/Thream/socketio-jwt/actions/workflows/test.yml/badge.svg?branch=develop" /></a>
<a href="https://codecov.io/gh/Thream/socketio-jwt"><img src="https://codecov.io/gh/Thream/socketio-jwt/branch/develop/graph/badge.svg" alt="codecov" /></a>
<br />
<a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt="Conventional Commits" /></a> <a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt="Conventional Commits" /></a>
<a href="https://github.com/Thream/Thream/blob/master/.github/CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Contributor Covenant" /></a> <a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release" /></a>
<a href="https://www.npmjs.com/package/@thream/socketio-jwt"><img src="https://img.shields.io/npm/v/@thream/socketio-jwt.svg" alt="npm version"></a>
</p> </p>
## 📜 About ## 📜 About

8
jest.config.js Normal file
View File

@ -0,0 +1,8 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: './src',
setupFilesAfterEnv: ['<rootDir>/__test__/setup.ts'],
collectCoverage: true,
coverageDirectory: '../coverage/'
}

22522
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@thream/socketio-jwt", "name": "@thream/socketio-jwt",
"version": "2.1.0", "version": "0.0.0-development",
"description": "Authenticate socket.io incoming connections with JWTs.", "description": "Authenticate socket.io incoming connections with JWTs.",
"license": "MIT", "license": "MIT",
"main": "build/index.js", "main": "build/index.js",
@ -9,7 +9,7 @@
"build" "build"
], ],
"engines": { "engines": {
"node": ">=12" "node": ">=12.0.0"
}, },
"keywords": [ "keywords": [
"socket", "socket",
@ -25,40 +25,6 @@
"url": "https://github.com/Thream/socketio-jwt/issues" "url": "https://github.com/Thream/socketio-jwt/issues"
}, },
"homepage": "https://github.com/Thream/socketio-jwt#readme", "homepage": "https://github.com/Thream/socketio-jwt#readme",
"release-it": {
"git": {
"commit": false,
"push": false,
"tag": false
},
"github": {
"release": false
},
"npm": {
"publish": false
},
"hooks": {
"before:init": [
"npm run lint",
"npm run markdownlint",
"npm run build",
"npm run test"
]
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": "angular",
"infile": "CHANGELOG.md"
}
}
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"rootDir": "./src",
"collectCoverage": true,
"coverageDirectory": "../coverage/"
},
"ts-standard": { "ts-standard": {
"ignore": [ "ignore": [
"build", "build",
@ -73,9 +39,11 @@
}, },
"scripts": { "scripts": {
"build": "rimraf ./build && tsc", "build": "rimraf ./build && tsc",
"markdownlint": "markdownlint '**/*.md' --dot --ignore node_modules", "lint:commit": "commitlint",
"lint": "ts-standard", "lint:editorconfig": "editorconfig-checker",
"release": "release-it", "lint:markdown": "markdownlint '**/*.md' --dot --ignore node_modules",
"lint:typescript": "ts-standard",
"release": "semantic-release",
"test": "jest", "test": "jest",
"postinstall": "husky install", "postinstall": "husky install",
"prepublishOnly": "pinst --disable", "prepublishOnly": "pinst --disable",
@ -88,27 +56,27 @@
"jsonwebtoken": "8.5.1" "jsonwebtoken": "8.5.1"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "12.0.1", "@commitlint/cli": "12.1.4",
"@commitlint/config-conventional": "12.0.1", "@commitlint/config-conventional": "12.1.4",
"@release-it/conventional-changelog": "2.0.1", "@types/express": "4.17.13",
"@types/express": "4.17.11", "@types/jest": "26.0.24",
"@types/jest": "26.0.20", "@types/jsonwebtoken": "8.5.4",
"@types/jsonwebtoken": "8.5.0", "@types/node": "16.4.1",
"@types/node": "14.14.32",
"@types/server-destroy": "1.0.1", "@types/server-destroy": "1.0.1",
"axios": "0.21.1", "axios": "0.21.1",
"editorconfig-checker": "4.0.2",
"express": "4.17.1", "express": "4.17.1",
"husky": "5.1.3", "husky": "7.0.1",
"jest": "26.6.3", "jest": "27.0.6",
"markdownlint-cli": "0.27.1", "markdownlint-cli": "0.28.1",
"pinst": "2.1.6", "pinst": "2.1.6",
"release-it": "14.4.1",
"rimraf": "3.0.2", "rimraf": "3.0.2",
"semantic-release": "17.4.4",
"server-destroy": "1.0.1", "server-destroy": "1.0.1",
"socket.io": "3.1.2", "socket.io": "4.1.3",
"socket.io-client": "3.1.2", "socket.io-client": "4.1.3",
"ts-jest": "26.5.3", "ts-jest": "27.0.4",
"ts-standard": "10.0.0", "ts-standard": "10.0.0",
"typescript": "4.2.3" "typescript": "4.3.5"
} }
} }

View File

@ -6,15 +6,182 @@ import { fixtureStart, fixtureStop, getSocket, Profile } from './fixture'
describe('authorize - with secret as string in options', () => { describe('authorize - with secret as string in options', () => {
let token: string = '' let token: string = ''
beforeEach(async (done) => { beforeEach((done) => {
jest.setTimeout(15_000) fixtureStart(async () => {
await fixtureStart(async () => {
const response = await axios.post('http://localhost:9000/login') const response = await axios.post('http://localhost:9000/login')
token = response.data.token token = response.data.token
})
.then(done)
.catch((error) => {
done(error)
})
})
afterEach((done) => {
fixtureStop(done)
})
it('should emit error with no token provided', (done) => {
const socket = io('http://localhost:9000')
socket.on('connect_error', (err: any) => {
expect(err.data.message).toEqual('no token provided')
expect(err.data.code).toEqual('credentials_required')
socket.close()
done() done()
}) })
}) })
it('should emit error with bad token format', (done) => {
const socket = io('http://localhost:9000', {
auth: { token: 'testing' }
})
socket.on('connect_error', (err: any) => {
expect(err.data.message).toEqual(
'Format is Authorization: Bearer [token]'
)
expect(err.data.code).toEqual('credentials_bad_format')
socket.close()
done()
})
})
it('should emit error with unauthorized handshake', (done) => {
const socket = io('http://localhost:9000', {
auth: { token: 'Bearer testing' }
})
socket.on('connect_error', (err: any) => {
expect(err.data.message).toEqual(
'Unauthorized: Token is missing or invalid Bearer'
)
expect(err.data.code).toEqual('invalid_token')
socket.close()
done()
})
})
it('should connect the user', (done) => {
const socket = io('http://localhost:9000', {
auth: { token: `Bearer ${token}` }
})
socket.on('connect', () => {
socket.close()
done()
})
socket.on('connect_error', (err: any) => {
done(err)
})
})
})
const secretCallback = async (): Promise<string> => {
return 'somesecret'
}
describe('authorize - with secret as callback in options', () => {
let token: string = ''
beforeEach((done) => {
fixtureStart(
async () => {
const response = await axios.post('http://localhost:9000/login')
token = response.data.token
},
{ secret: secretCallback }
)
.then(done)
.catch((error) => {
done(error)
})
})
afterEach((done) => {
fixtureStop(done)
})
it('should emit error with no token provided', (done) => {
const socket = io('http://localhost:9000')
socket.on('connect_error', (err: any) => {
expect(err.data.message).toEqual('no token provided')
expect(err.data.code).toEqual('credentials_required')
socket.close()
done()
})
})
it('should emit error with bad token format', (done) => {
const socket = io('http://localhost:9000', {
auth: { token: 'testing' }
})
socket.on('connect_error', (err: any) => {
expect(err.data.message).toEqual(
'Format is Authorization: Bearer [token]'
)
expect(err.data.code).toEqual('credentials_bad_format')
socket.close()
done()
})
})
it('should emit error with unauthorized handshake', (done) => {
const socket = io('http://localhost:9000', {
auth: { token: 'Bearer testing' }
})
socket.on('connect_error', (err: any) => {
expect(err.data.message).toEqual(
'Unauthorized: Token is missing or invalid Bearer'
)
expect(err.data.code).toEqual('invalid_token')
socket.close()
done()
})
})
it('should connect the user', (done) => {
const socket = io('http://localhost:9000', {
auth: { token: `Bearer ${token}` }
})
socket.on('connect', () => {
socket.close()
done()
})
socket.on('connect_error', (err: any) => {
done(err)
})
})
})
describe('authorize - with onAuthentication callback in options', () => {
let token: string = ''
let wrongToken: string = ''
beforeEach((done) => {
fixtureStart(
async () => {
const response = await axios.post('http://localhost:9000/login')
token = response.data.token
const responseWrong = await axios.post(
'http://localhost:9000/login-wrong'
)
wrongToken = responseWrong.data.token
},
{
secret: secretCallback,
onAuthentication: (decodedToken: Profile) => {
if (!decodedToken.checkField) {
throw new Error('Check Field validation failed')
}
return {
email: decodedToken.email
}
}
}
)
.then(done)
.catch((error) => {
done(error)
})
})
afterEach((done) => { afterEach((done) => {
fixtureStop(done) fixtureStop(done)
}) })
@ -66,83 +233,6 @@ describe('authorize - with secret as string in options', () => {
done() done()
}) })
}) })
})
const secretCallback = async (): Promise<string> => {
return 'somesecret'
}
describe('authorize - with secret as callback in options', () => {
let token: string = ''
beforeEach(async (done) => {
jest.setTimeout(15_000)
await fixtureStart(
async () => {
const response = await axios.post('http://localhost:9000/login')
token = response.data.token
done()
},
{ secret: secretCallback }
)
})
afterEach((done) => {
fixtureStop(done)
})
it('should connect the user', (done) => {
const socket = io('http://localhost:9000', {
auth: { token: `Bearer ${token}` }
})
socket.on('connect', () => {
socket.close()
done()
})
})
})
describe('authorize - with onAuthentication callback in options', () => {
let token: string = ''
let wrongToken: string = ''
beforeEach(async (done) => {
jest.setTimeout(15_000)
await fixtureStart(
async () => {
const response = await axios.post('http://localhost:9000/login')
token = response.data.token
const responseWrong = await axios.post('http://localhost:9000/login-wrong')
wrongToken = responseWrong.data.token
done()
},
{
secret: secretCallback,
onAuthentication: (decodedToken: Profile) => {
if (!decodedToken.checkField) {
throw new Error('Check Field validation failed')
}
return {
email: decodedToken.email
}
}
}
)
})
afterEach((done) => {
fixtureStop(done)
})
it('should connect the user', (done) => {
const socket = io('http://localhost:9000', {
auth: { token: `Bearer ${token}` }
})
socket.on('connect', () => {
socket.close()
done()
})
})
it('should contain user property', (done) => { it('should contain user property', (done) => {
const socketServer = getSocket() const socketServer = getSocket()

View File

@ -29,33 +29,29 @@ let server: HttpServer | null = null
export const fixtureStart = async ( export const fixtureStart = async (
done: any, done: any,
options: AuthorizeOptions = { secret: 'aaafoo super sercret' } options: AuthorizeOptions = { secret: 'super secret' }
): Promise<void> => { ): Promise<void> => {
const app = express()
app.use(express.json())
let keySecret = 'secret'
if (typeof options.secret === 'string') {
keySecret = options.secret
} else {
keySecret = await options.secret({ header: { alg: 'RS256' }, payload: '' })
}
app.post('/login', (_req, res) => {
const profile: Profile = { const profile: Profile = {
email: 'john@doe.com', email: 'john@doe.com',
id: 123, id: 123,
checkField: true checkField: true
} }
let keySecret = ''
if (typeof options.secret === 'string') {
keySecret = options.secret
} else {
keySecret = await options.secret({ header: { alg: 'HS256' }, payload: profile })
}
const app = express()
app.use(express.json())
app.post('/login', (_req, res) => {
const token = jwt.sign(profile, keySecret, { const token = jwt.sign(profile, keySecret, {
expiresIn: 60 * 60 * 5 expiresIn: 60 * 60 * 5
}) })
return res.json({ token }) return res.json({ token })
}) })
app.post('/login-wrong', (_req, res) => { app.post('/login-wrong', (_req, res) => {
const profile: Profile = { profile.checkField = false
email: 'john@doe.com',
id: 123,
checkField: false
}
const token = jwt.sign(profile, keySecret, { const token = jwt.sign(profile, keySecret, {
expiresIn: 60 * 60 * 5 expiresIn: 60 * 60 * 5
}) })
@ -71,7 +67,7 @@ export const fixtureStop = (callback: Function): void => {
socket.io?.close() socket.io?.close()
try { try {
server?.destroy() server?.destroy()
} catch (err) {} } catch {}
callback() callback()
} }

1
src/__test__/setup.ts Normal file
View File

@ -0,0 +1 @@
jest.setTimeout(15_000)

View File

@ -30,7 +30,7 @@ interface CompleteDecodedToken {
payload: any payload: any
} }
type SecretCallback = (decodedToken: CompleteDecodedToken) => Promise<string> type SecretCallback = (decodedToken: CompleteDecodedToken) => Promise<string> | string
export interface AuthorizeOptions { export interface AuthorizeOptions {
secret: string | SecretCallback secret: string | SecretCallback

View File

@ -1,23 +1,13 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2019", "target": "ESNext",
"module": "commonjs", "module": "commonjs",
"lib": ["ES2019"], "lib": ["ESNext"],
"moduleResolution": "node", "moduleResolution": "node",
"allowJs": false,
"checkJs": false,
"declaration": true,
"sourceMap": false,
"outDir": "./build", "outDir": "./build",
"rootDir": "./src", "rootDir": "./src",
"removeComments": false,
"noEmitOnError": true,
"importHelpers": false,
"strict": true, "strict": true,
"esModuleInterop": true, "esModuleInterop": true,
"experimentalDecorators": true, "declaration": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true,
"incremental": false
} }
} }