diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index d0ac2a8..a8acc5e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -8,13 +8,13 @@ assignees: '' **Describe the bug** -A clear and concise description of what the bug is, the package version you are using. +A clear and concise description of what the bug is, the `http-status` package version you are using. **To Reproduce** -Please provide us with a unit test, an example code or even pseudo-code. It could be written in JavaScript or CoffeeScript, but not in TypeScript unless the bug is related to TypeScript. +Please provide us with a unit test, an example code or even pseudo-code. It is written in JavaScript, but not in TypeScript unless the bug is related to TypeScript. -What's important is to **limit the data** to the minimum as well as to **strip down the number of options** to the relevant ones with an impact. Do not reference an external file. +What's important is to provide a **minimal code**, only focussing on the problem. Do not reference an external file. **Additional context** diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 3ba13e0..0babb42 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1 +1,5 @@ blank_issues_enabled: false +# contact_links: +# - name: documentation +# url: https://domain.com/ +# about: Check out the documentation for answers to common questions. diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 46f4966..7fa5a33 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,6 +1,3 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - name: Publish on: push: @@ -10,27 +7,30 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [16.x, 18.x] + node-version: [16.x, 18.x, 20.x] steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - run: yarn --frozen-lockfile - - run: yarn run test + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: yarn --frozen-lockfile + - run: yarn run test publish: needs: [test] + if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - uses: actions/setup-node@v2 - with: - node-version: '16.x' - registry-url: 'https://registry.npmjs.org' - - run: npm install - - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org' + - run: npm install + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d36503f..12a2572 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,23 +1,33 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - name: Test on: push: - branches: [ master ] pull_request: - branches: [ master ] jobs: + is_release: + runs-on: ubuntu-latest + outputs: + type: ${{ steps.get_type.outputs.type }} + continue-on-error: true + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - id: get_type + run: echo $( git tag --points-at HEAD | grep -q -e '^v' && echo 'type=::release::' || echo "type=::norelease::" ) >> "$GITHUB_OUTPUT" test: + needs: [is_release] + if: ${{ needs.is_release.outputs.type == '::norelease::' }} runs-on: ubuntu-latest strategy: matrix: - node-version: [16.x, 18.x] + node-version: [16.x, 18.x, 20.x] steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - run: yarn --frozen-lockfile - - run: yarn run test + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: yarn --frozen-lockfile + - run: yarn run test diff --git a/CHANGELOG.md b/CHANGELOG.md index b7b6814..db7e8b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [1.7.4](https://github.com/adaltas/node-http-status/compare/v1.7.3...v1.7.4) (2024-02-23) + + +### Bug Fixes + +* **types:** improve TypeScript strict typing for numeric keys in HttpStatus ([#49](https://github.com/adaltas/node-http-status/issues/49)) ([4945afd](https://github.com/adaltas/node-http-status/commit/4945afdc1f8aaba59fbc95983e7a2934238dab24)), closes [#48](https://github.com/adaltas/node-http-status/issues/48) + +### [1.7.3](https://github.com/adaltas/node-http-status/compare/v1.7.2...v1.7.3) (2023-10-17) + +### [1.7.2](https://github.com/adaltas/node-http-status/compare/v1.7.1...v1.7.2) (2023-10-17) + +### [1.7.1](https://github.com/adaltas/node-http-status/compare/v1.7.0...v1.7.1) (2023-10-17) + ## [1.7.0](https://github.com/adaltas/node-http-status/compare/v1.6.2...v1.7.0) (2023-09-04) diff --git a/README.md b/README.md index f7295c8..c110020 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Build Status](https://secure.travis-ci.org/adaltas/node-http-status.png)](http://travis-ci.org/adaltas/node-http-status) -# HTTP Status codes for Node +# HTTP Status codes for Node.js Utility to interact with HTTP status codes. @@ -8,7 +8,7 @@ Utility to interact with HTTP status codes. Once you require this module, you may call it with either an HTTP code or a message name. With an HTTP code, you will get the message name while with a message name you will get an HTTP code. -### HTTP Status Codes +### HTTP Status codes HTTP code names, messages, and classes are respectively accessible with the property `{code}_NAME`, `{code}_MESSAGE` and `{code}_CLASS`. This includes all statuses in the [IANA HTTP Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml), with the only addition being `418 I'm a teapot`. @@ -27,7 +27,7 @@ Available categories are:
Cloudflare's reverse proxy service expands the 5xx error class to signal issues with the origin server.
-### HTTP Status Code Classes +### HTTP Status code classes In addition to HTTP status codes, this module also contains status code classes under the `classes` property. Similar to HTTP codes, you can access class names and messages with the property `{class}_NAME` and `{class}_MESSAGE` @@ -90,7 +90,7 @@ extra. For additional information, please refer to [original code](./src/index.litcoffee). -### Example Usage +### Example usage ```javascript const status = require('http-status'); @@ -145,7 +145,7 @@ switch (status[`${responseCode}_CLASS`]) { } ``` -### Example Using `extra` Property +### Example using the `extra` property ```javascript // Accessing property from the NGINX category @@ -157,7 +157,7 @@ console.info(status.IM_A_TEAPOT); console.info(status.NO_RESPONSE) ``` -### Express Example +### Example integrating Express ```javascript const express = require('express'), @@ -194,13 +194,7 @@ This package is developed by [Adaltas](https://www.adaltas.com). To automatically generate a new version: ``` -rm package-lock.json yarn run release -git push --follow-tags origin master ``` Package publication is handled by the CI/CD with GitHub action. - -Note: -- On release, both the publish and test workflows run in parallel. Not very happy about it but I haven't found a better way. -- `yarn` does not call the "postrelease" script and `npm` fails if the `package-lock.json` file is present and git ignored. diff --git a/lib/index.d.ts b/lib/index.d.ts index aa81727..18f458c 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -4,15 +4,6 @@ declare const httpStatus: httpStatus.HttpStatus; declare namespace httpStatus { interface HttpStatus { - readonly [key: number]: string | undefined; - - readonly [key: string]: - | string - | number - | HttpStatusClasses - | HttpStatusExtra - | undefined; - readonly 100: string; readonly '100_NAME': string; readonly '100_MESSAGE': string; @@ -395,8 +386,6 @@ declare namespace httpStatus { } interface HttpStatusClasses { - readonly [key: string]: string | number; - readonly '1xx': string; readonly '1xx_NAME': string; readonly '1xx_MESSAGE': string; @@ -424,8 +413,6 @@ declare namespace httpStatus { } interface HttpStatusUnofficial { - readonly [key: string]: string | number; - readonly 103: string; readonly '103_NAME': string; readonly '103_MESSAGE': string; @@ -476,8 +463,6 @@ declare namespace httpStatus { } interface HttpStatusIis { - readonly [key: string]: string | number; - readonly 440: string; readonly '440_NAME': string; readonly '440_MESSAGE': string; @@ -498,8 +483,6 @@ declare namespace httpStatus { } interface HttpStatusNginx { - readonly [key: string]: string | number; - readonly 444: string; readonly '444_NAME': string; readonly '444_MESSAGE': string; diff --git a/lib/index.js b/lib/index.js index 9d132ce..31f515b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -338,7 +338,7 @@ module.exports = { '425_NAME': 'TOO_EARLY', '425_MESSAGE': 'The server is unwilling to risk processing a request that might be replayed.', '425_CLASS': classes.CLIENT_ERROR, - FAILED_DEPENDENCY: 425, + TOO_EARLY: 425, // 426 - The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field. 426: 'Upgrade Required', '426_NAME': 'UPGRADE_REQUIRED', diff --git a/package.json b/package.json index 46e2483..6cbe2f8 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,15 @@ { "name": "http-status", - "version": "1.7.0", + "version": "1.7.4", "description": "Interact with HTTP status code", "homepage": "https://github.com/adaltas/node-http-status", "author": "David Worms (https://www.adaltas.com)", "keywords": [ "http", - "express", - "connect" + "connect", + "frontend", + "status", + "express" ], "license": "BSD-3-Clause", "repository": { @@ -77,11 +79,12 @@ "build": "coffee -b -o lib src && cp src/index.d.ts lib", "prepare": "husky install", "pretest": "npm run build", + "prerelease": "npm run build && git update-index --refresh && git diff-index --quiet HEAD --", "release": "standard-version", - "postrelease": "git push --follow-tags origin master", "release:minor": "standard-version --release-as minor", "release:patch": "standard-version --release-as patch", "release:major": "standard-version --release-as major", + "postrelease": "git push --follow-tags origin master", "test": "mocha \"test/**/*.{coffee,ts}\"" } } diff --git a/src/index.d.ts b/src/index.d.ts index aa81727..18f458c 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -4,15 +4,6 @@ declare const httpStatus: httpStatus.HttpStatus; declare namespace httpStatus { interface HttpStatus { - readonly [key: number]: string | undefined; - - readonly [key: string]: - | string - | number - | HttpStatusClasses - | HttpStatusExtra - | undefined; - readonly 100: string; readonly '100_NAME': string; readonly '100_MESSAGE': string; @@ -395,8 +386,6 @@ declare namespace httpStatus { } interface HttpStatusClasses { - readonly [key: string]: string | number; - readonly '1xx': string; readonly '1xx_NAME': string; readonly '1xx_MESSAGE': string; @@ -424,8 +413,6 @@ declare namespace httpStatus { } interface HttpStatusUnofficial { - readonly [key: string]: string | number; - readonly 103: string; readonly '103_NAME': string; readonly '103_MESSAGE': string; @@ -476,8 +463,6 @@ declare namespace httpStatus { } interface HttpStatusIis { - readonly [key: string]: string | number; - readonly 440: string; readonly '440_NAME': string; readonly '440_MESSAGE': string; @@ -498,8 +483,6 @@ declare namespace httpStatus { } interface HttpStatusNginx { - readonly [key: string]: string | number; - readonly 444: string; readonly '444_NAME': string; readonly '444_MESSAGE': string; diff --git a/src/index.litcoffee b/src/index.litcoffee index 9e7ac24..07a67ac 100644 --- a/src/index.litcoffee +++ b/src/index.litcoffee @@ -440,7 +440,7 @@ Indicates that the client seems to have erred. '425_NAME': 'TOO_EARLY' '425_MESSAGE': 'The server is unwilling to risk processing a request that might be replayed.' '425_CLASS': classes.CLIENT_ERROR - FAILED_DEPENDENCY: 425 + TOO_EARLY: 425 426 - The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field. diff --git a/test/types.ts b/test/types.ts index 7ea4694..b376fc0 100644 --- a/test/types.ts +++ b/test/types.ts @@ -29,12 +29,12 @@ describe('Types', () => { it('undefined status codes', () => { const undefinedStatusCode = 777 - const code: string = typeof status[undefinedStatusCode] + const code: string = typeof (status as any)[undefinedStatusCode] code.should.eql('undefined') }) it('sub level properties', () => { - const number: number = status.extra.nginx.NO_RESPONSE + const number: 444 = status.extra.nginx.NO_RESPONSE const code: string = status.extra.nginx[number] as string code.should.eql('No Response') const name: string = status.extra.nginx[`${number}_NAME`] as string