Compare commits

..

No commits in common. "master" and "v1.0.3" have entirely different histories.

27 changed files with 1944 additions and 10394 deletions

View File

@ -1,66 +0,0 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -1,124 +0,0 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

18
.gitignore vendored
View File

@ -1,19 +1,3 @@
.nogit/ node_modules/
# artifacts
coverage/ coverage/
public/ public/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
#------# custom

147
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,147 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
sast:
stage: security
image: docker:stable
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
--volume "$PWD:/code"
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
artifacts:
reports:
sast: gl-sast-report.json
tags:
- docker
- priv
# ====================
# test stage
# ====================
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

11
.vscode/launch.json vendored
View File

@ -1,11 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored
View File

@ -1,26 +0,0 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

33
README.md Normal file
View File

@ -0,0 +1,33 @@
# smartstatus
status information in TypeScript
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartstatus)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartstatus)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartstatus)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartstatus/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartstatus/badges/master/build.svg)](https://GitLab.com/pushrocks/smartstatus/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartstatus/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartstatus/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartstatus.svg)](https://www.npmjs.com/package/smartstatus)
[![Dependency Status](https://david-dm.org/pushrocks/smartstatus.svg)](https://david-dm.org/pushrocks/smartstatus)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartstatus/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartstatus/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartstatus/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartstatus)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -1,35 +0,0 @@
# Changelog
## 2024-12-25 - 1.1.1 - fix(smartstatus)
Remove all tslint:disable-next-line comments for max-classes-per-file rule
- Code cleanup by removing unnecessary tslint comments for disabling max-classes-per-file rule.
## 2024-12-25 - 1.1.0 - feat(ci)
Set up GitHub Actions workflows for CI/CD
- Replaced GitLab CI with GitHub Actions for both tag and non-tag pushes.
- Implemented npm audit for security checks on both production and development dependencies.
- Enabled npm test and build steps as part of the CI workflow.
## 2024-05-29 - 1.0.12 - Documentation & Configuration
Minor updates focusing on project configuration and descriptive metadata.
- Updated project description.
- Updated tsconfig multiple times for improved TypeScript configurations.
- Adjusted npmextra.json configuration for host consistency.
## 2021-08-19 to 2024-04-14 - 1.0.11 to 1.0.12 - Core Fixes & Maintenance
A range of updates focused on core functionality and essential maintenance fixes across versions.
- Multiple core updates distributed across versions 1.0.7 to 1.0.12.
## 2019-01-02 to 2021-08-19 - 1.0.5 to 1.0.10 - Core Updates
Core functionality was reviewed and updated multiple times to ensure stability and improved performance.
## 2017-04-06 to 2019-01-02 - 1.0.0 to 1.0.4 - Initial Development & Feature Implementations
The initial stages of development including major feature implementations across status codes and basic framework setup.
- Initial setup completed with basic framework and configuration.
- Implemented handling of 1xx to 5xx range of status codes.
- Added continuous integration and initial testing protocols.

33
docs/index.md Normal file
View File

@ -0,0 +1,33 @@
# smartstatus
status information in TypeScript
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartstatus)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartstatus)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartstatus)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartstatus/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartstatus/badges/master/build.svg)](https://GitLab.com/pushrocks/smartstatus/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartstatus/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartstatus/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartstatus.svg)](https://www.npmjs.com/package/smartstatus)
[![Dependency Status](https://david-dm.org/pushrocks/smartstatus.svg)](https://david-dm.org/pushrocks/smartstatus)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartstatus/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartstatus/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartstatus/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartstatus)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -1,37 +1,7 @@
{ {
"gitzone": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartstatus",
"shortDescription": "status information in TypeScript",
"npmPackagename": "@push.rocks/smartstatus",
"license": "MIT",
"description": "A TypeScript library for managing HTTP status codes, providing detailed classes for each status to enhance HTTP error and response handling.",
"keywords": [
"TypeScript",
"HTTP",
"status codes",
"error handling",
"client errors",
"server errors",
"response management",
"error management",
"API development",
"express.js",
"web applications",
"network services",
"custom status codes"
]
}
},
"npmci": { "npmci": {
"globalNpmTools": [], "globalNpmTools": [],
"npmRegistryUrl": "verdaccio.lossless.one", "npmRegistryUrl": "verdaccio.lossless.one",
"npmAccessLevel": "public" "npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
} }
} }

1591
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,61 +1,30 @@
{ {
"name": "@push.rocks/smartstatus", "name": "@pushrocks/smartstatus",
"version": "1.1.1", "version": "1.0.3",
"private": false, "private": false,
"description": "A TypeScript library for managing HTTP status codes, providing detailed classes for each status to enhance HTTP error and response handling.", "description": "status information in TypeScript",
"type": "module", "main": "dist/index.js",
"exports": { "typings": "dist/index.d.ts",
".": "./dist_ts/index.js"
},
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "tsbuild --web", "build": "tsbuild"
"buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://code.foss.global/push.rocks/smartstatus.git" "url": "git+ssh://git@gitlab.com/pkunz/smartstatus.git"
}, },
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://code.foss.global/push.rocks/smartstatus/issues" "url": "https://gitlab.com/pkunz/smartstatus/issues"
}, },
"homepage": "https://code.foss.global/push.rocks/smartstatus#readme", "homepage": "https://gitlab.com/pkunz/smartstatus#README",
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.4",
"@git.zone/tsrun": "^1.3.3", "@gitzone/tstest": "^1.0.18",
"@git.zone/tstest": "^1.0.54", "@pushrocks/tapbundle": "^3.0.7",
"@push.rocks/tapbundle": "^5.5.3" "tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0"
}, },
"browserslist": [ "dependencies": {}
"last 1 chrome versions"
],
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"keywords": [
"TypeScript",
"HTTP",
"status codes",
"error handling",
"client errors",
"server errors",
"response management",
"error management",
"API development",
"express.js",
"web applications",
"network services",
"custom status codes"
]
} }

9627
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@

220
readme.md
View File

@ -1,220 +0,0 @@
# @push.rocks/smartstatus
A TypeScript library for managing HTTP status information, with detailed status classes.
## Install
To install `@push.rocks/smartstatus`, use npm (or yarn, or pnpm) by running the following command in your terminal:
```sh
npm install @push.rocks/smartstatus --save
```
Ensure you have TypeScript and a package to work with TypeScript in your project. If not, you might want to install TypeScript and ts-node (for development purposes) to your project:
```sh
npm install typescript ts-node --save-dev
```
## Usage
The `@push.rocks/smartstatus` library provides a structured and comprehensive way to handle HTTP status codes in TypeScript, enhancing your ability to manage HTTP responses effectively. Below, we outline an extensive set of scenarios demonstrating how you can leverage this module's capabilities to streamline and enrich your response handling from server-side applications to API endpoints.
### Getting Started
To start using `@push.rocks/smartstatus`, ensure you import the module into your TypeScript files. Here's a basic import statement you can use:
```typescript
import * as smartstatus from '@push.rocks/smartstatus';
```
For more specific imports, such as obtaining particular HTTP status code classes, you may use:
```typescript
import { HttpStatus, Status404, Status200 } from '@push.rocks/smartstatus';
```
### Retrieving a Specific Status
The library allows you to retrieve any HTTP status code with its corresponding information quickly. You can do this by using either a class representation for known statuses or using a method that fetches the status by its status code string.
#### Example: Fetching 404 Not Found Status
Let's say you wish to work with the HTTP 404 "Not Found" status. You can retrieve its details as follows:
```typescript
import { HttpStatus } from '@push.rocks/smartstatus';
const notFoundStatus = HttpStatus.getHttpStatusByString('404');
console.log(notFoundStatus.code); // 404
console.log(notFoundStatus.text); // Not Found
console.log(notFoundStatus.description); // The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.
```
The `getHttpStatusByString` function dynamically returns an instance of the respective status class with fields like HTTP code, textual representation, and an insightful description of the status.
### Handling Errors Using HTTP Statuses
One of the most valuable features of `@push.rocks/smartstatus` is enriching error handling protocols in web applications or APIs. Let's illustrate how smartstatus can be used with an Express.js framework to enhance HTTP response management, specifically handling different HTTP error statuses.
#### Example: Implementing with Express.js
Imagine you are developing a web service, and a specific operation fails due to an authorization issue. Here's how you might use smartstatus to handle this error gracefully:
```typescript
import express from 'express';
import { HttpStatus } from '@push.rocks/smartstatus';
const app = express();
app.get('/secure/data', (req, res) => {
// Simulating an authorization failure condition
const userIsAuthorized = false;
if (!userIsAuthorized) {
const unauthorizedStatus = HttpStatus.getHttpStatusByString('401');
res.status(unauthorizedStatus.code).json({
error: unauthorizedStatus.text,
message: unauthorizedStatus.description,
});
} else {
res.status(200).send('Secure Data');
}
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
```
In this express app endpoint, if the user is not authorized to access the resource, it responds with a 401 Unauthorized status. This status code is enriched with a detailed message derived from smartstatus, providing a helpful explanation to API consumers.
### Extending with Custom Statuses
While `@push.rocks/smartstatus` covers standard HTTP statuses, the library also allows you to define and manage custom status codes tailored to specific application needs. This is particularly useful for internal APIs requiring bespoke statuses.
#### Example: Creating a Custom HTTP Status
Let's say you want to create a unique status for indicating a special condition encountered by your application, such as a "Processing Error" that is represented by code 499. Define a custom status class as follows:
```typescript
import { HttpStatus } from '@push.rocks/smartstatus';
class Status499 extends HttpStatus {
constructor() {
super({
code: 499,
text: 'Processing Error',
description:
'The server encountered a processing error which prevented it from completing the request.',
});
}
}
// Register the custom status for use
HttpStatus.addStatus('499', Status499);
// Usage of the custom status
const processingErrorStatus = HttpStatus.getHttpStatusByString('499');
console.log(`${processingErrorStatus.code} ${processingErrorStatus.text}`); // 499 Processing Error
```
This custom status can then be used in the same way as predefined statuses in the library, allowing you to handle unique responses efficiently.
### Comprehensive Examples Across HTTP Status Ranges
The `smartstatus` library classifies statuses across different ranges (1xx, 2xx, 3xx, 4xx, and 5xx). Here, we will demonstrate how to handle each of these categories to provide robustness in response management.
#### Informational Responses (1xx)
Status codes in the 1xx range inform the client about the progress of the request. These are mostly used in scenarios involving continuation or switching protocols.
```typescript
import { Status100 } from '@push.rocks/smartstatus';
// Handling 100 Continue status
const continueStatus = new Status100();
console.log(continueStatus.code, continueStatus.text, continueStatus.description);
```
#### Successful Responses (2xx)
The 2xx successes indicate that the client's request was received, understood, and accepted. Utilizing these codes effectively can aid in confirming successful API operations.
```typescript
import { Status200, Status201 } from '@push.rocks/smartstatus';
// 200 OK status for successfully processed requests
const okStatus = new Status200();
console.log(okStatus.code, okStatus.text, okStatus.description);
// 201 Created status for resource creation
const createdStatus = new Status201();
console.log(createdStatus.code, createdStatus.text, createdStatus.description);
```
#### Redirection Messages (3xx)
Statuses in the 3xx range indicate redirection, offering guidance on how the client can access different resources or follow up with another request.
```typescript
import { Status301, Status302 } from '@push.rocks/smartstatus';
// Permanent and Temporary redirects
const movedPermanentlyStatus = new Status301();
console.log(movedPermanentlyStatus.text); // Moved Permanently
const foundStatus = new Status302();
console.log(foundStatus.text); // Found
```
#### Client Error Responses (4xx)
This class of status codes is intended to inform the client that the error seems to have been caused by the client, such as a malformed request.
```typescript
import { Status400, Status404 } from '@push.rocks/smartstatus';
// Using 400 Bad Request for malformed requests
const badRequestStatus = new Status400();
console.log(badRequestStatus.description);
// Handling 404 Not Found for missing resources
const notFoundStatus = new Status404();
console.log(notFoundStatus.description);
```
#### Server Error Responses (5xx)
5xx indicates server-side errors, signaling the server is aware it encountered an error or is otherwise incapable of performing the request.
```typescript
import { Status500, Status503 } from '@push.rocks/smartstatus';
// Internal server error handling
const internalServerErrorStatus = new Status500();
console.log(internalServerErrorStatus.text);
// Service unavailable handling with a 503 response
const serviceUnavailableStatus = new Status503();
console.log(serviceUnavailableStatus.description);
```
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -1,10 +1,13 @@
import { expect, tap } from '@push.rocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as smartstatus from '../ts/index.js'; import * as smartstatus from '../ts/index';
tap.test('should get a status by codeString', async () => { tap.test('should create valid status classes', async () => {
const status = smartstatus.HttpStatus.getHttpStatusByString('404'); const myStatus301 = new smartstatus.status301();
console.log(status); console.log(myStatus301.code);
console.log(myStatus301.text);
console.log(myStatus301.description);
return expect(myStatus301).to.be.instanceOf(smartstatus.HttpStatus);
}); });
tap.start(); tap.start();

View File

@ -1,8 +0,0 @@
/**
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartstatus',
version: '1.1.1',
description: 'A TypeScript library for managing HTTP status codes, providing detailed classes for each status to enhance HTTP error and response handling.'
}

View File

View File

@ -1,7 +1 @@
export * from './smartstatus.classes.http.1xx.js'; export * from './smartstatus.classes.http';
export * from './smartstatus.classes.http.2xx.js';
export * from './smartstatus.classes.http.3xx.js';
export * from './smartstatus.classes.http.4xx.js';
export * from './smartstatus.classes.http.5xx.js';
export * from './smartstatus.classes.http.js';

View File

@ -1,6 +1,6 @@
import { HttpStatus, type TStatusGroup } from './smartstatus.classes.http.js'; import { HttpStatus, TStatusGroup } from './smartstatus.classes.http';
export class Status100 extends HttpStatus { export class status100 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 100, code: 100,
@ -13,24 +13,22 @@ export class Status100 extends HttpStatus {
To have a server check the request's headers, To have a server check the request's headers,
a client must send Expect: 100-continue as a header in its initial request and receive a client must send Expect: 100-continue as a header in its initial request and receive
a 100 Continue status code in response before sending the body. a 100 Continue status code in response before sending the body.
The response 417 Expectation Failed indicates the request should not be continued.`, The response 417 Expectation Failed indicates the request should not be continued.`
}); });
} }
} }
HttpStatus.addStatus('100', Status100);
export class Status101 extends HttpStatus { export class status101 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 101, code: 101,
text: 'Switching Protocols', text: 'Switching Protocols',
description: `The requester has asked the server to switch protocols and the server has agreed to do so.`, description: `The requester has asked the server to switch protocols and the server has agreed to do so.`
}); });
} }
} }
HttpStatus.addStatus('101', Status101);
export class Status102 extends HttpStatus { export class status102 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 102, code: 102,
@ -39,8 +37,7 @@ export class Status102 extends HttpStatus {
requiring a long time to complete the request. requiring a long time to complete the request.
This code indicates that the server has received and is processing the request, This code indicates that the server has received and is processing the request,
but no response is available yet.[6] but no response is available yet.[6]
This prevents the client from timing out and assuming the request was lost.`, This prevents the client from timing out and assuming the request was lost.`
}); });
} }
} }
HttpStatus.addStatus('102', Status102);

View File

@ -1,6 +1,6 @@
import { HttpStatus, type TStatusGroup } from './smartstatus.classes.http.js'; import { HttpStatus, TStatusGroup } from './smartstatus.classes.http';
export class Status200 extends HttpStatus { export class status200 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 200, code: 200,
@ -8,71 +8,65 @@ export class Status200 extends HttpStatus {
description: `Standard response for successful HTTP requests. description: `Standard response for successful HTTP requests.
The actual response will depend on the request method used. The actual response will depend on the request method used.
In a GET request, the response will contain an entity corresponding to the requested resource. In a GET request, the response will contain an entity corresponding to the requested resource.
In a POST request, the response will contain an entity describing or containing the result of the action.`, In a POST request, the response will contain an entity describing or containing the result of the action.`
}); });
} }
} }
HttpStatus.addStatus('200', Status200);
export class Status201 extends HttpStatus { export class status201 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 201, code: 201,
text: 'Created', text: 'Created',
description: `The request has been fulfilled, resulting in the creation of a new resource.`, description: `The request has been fulfilled, resulting in the creation of a new resource.`
}); });
} }
} }
HttpStatus.addStatus('201', Status201);
export class Status202 extends HttpStatus { export class status202 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 202, code: 202,
text: 'Accepted', text: 'Accepted',
description: `The request has been accepted for processing, but the processing has not been completed. description: `The request has been accepted for processing, but the processing has not been completed.
The request might or might not be eventually acted upon, and may be disallowed when processing occurs.`, The request might or might not be eventually acted upon, and may be disallowed when processing occurs.`
}); });
} }
} }
HttpStatus.addStatus('202', Status202);
export class Status203 extends HttpStatus { export class status203 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 203, code: 203,
text: 'Non-Authoritative Information', text: 'Non-Authoritative Information',
description: `The server is a transforming proxy (e.g. a Web accelerator) description: `The server is a transforming proxy (e.g. a Web accelerator)
that received a 200 OK from its origin, but is returning a modified version of the origin's response.`, that received a 200 OK from its origin, but is returning a modified version of the origin's response.`
}); });
} }
} }
HttpStatus.addStatus('203', Status203);
export class Status204 extends HttpStatus { export class status204 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 204, code: 204,
text: 'Non-Authoritative Information', text: 'Non-Authoritative Information',
description: `The server successfully processed the request and is not returning any content.`, description: `The server successfully processed the request and is not returning any content.`
}); });
} }
} }
HttpStatus.addStatus('204', Status204);
export class Status205 extends HttpStatus { export class status205 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 205, code: 205,
text: 'Reset Content', text: 'Reset Content',
description: `The server successfully processed the request, but is not returning any content. description: `The server successfully processed the request, but is not returning any content.
Unlike a 204 response, this response requires that the requester reset the document view.`, Unlike a 204 response, this response requires that the requester reset the document view.`
}); });
} }
} }
HttpStatus.addStatus('205', Status205);
export class Status206 extends HttpStatus { export class status206 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 206, code: 206,
@ -80,47 +74,43 @@ export class Status206 extends HttpStatus {
description: `The server is delivering only part of the resource (byte serving) description: `The server is delivering only part of the resource (byte serving)
due to a range header sent by the client. due to a range header sent by the client.
The range header is used by HTTP clients to enable resuming of interrupted downloads, The range header is used by HTTP clients to enable resuming of interrupted downloads,
or split a download into multiple simultaneous streams.`, or split a download into multiple simultaneous streams.`
}); });
} }
} }
HttpStatus.addStatus('206', Status206);
export class Status207 extends HttpStatus { export class status207 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 207, code: 207,
text: 'Multi-Status', text: 'Multi-Status',
description: `The message body that follows is an XML message description: `The message body that follows is an XML message
and can contain a number of separate response codes, and can contain a number of separate response codes,
depending on how many sub-requests were made.`, depending on how many sub-requests were made.`
}); });
} }
} }
HttpStatus.addStatus('207', Status207);
export class Status208 extends HttpStatus { export class status208 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 208, code: 208,
text: 'Already Reported', text: 'Already Reported',
description: `The members of a DAV binding have already been enumerated description: `The members of a DAV binding have already been enumerated
in a preceding part of the (multistatus) response, in a preceding part of the (multistatus) response,
and are not being included again.`, and are not being included again.`
}); });
} }
} }
HttpStatus.addStatus('208', Status208);
export class Status226 extends HttpStatus { export class status226 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 226, code: 226,
text: 'IM Used', text: 'IM Used',
description: `The server has fulfilled a request for the resource, description: `The server has fulfilled a request for the resource,
and the response is a representation of the result of one or more instance-manipulations and the response is a representation of the result of one or more instance-manipulations
applied to the current instance.`, applied to the current instance.`
}); });
} }
} }
HttpStatus.addStatus('226', Status226);

View File

@ -1,6 +1,6 @@
import { HttpStatus, type TStatusGroup } from './smartstatus.classes.http.js'; import { HttpStatus, TStatusGroup } from './smartstatus.classes.http';
export class Status300 extends HttpStatus { export class status300 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 300, code: 300,
@ -8,24 +8,22 @@ export class Status300 extends HttpStatus {
description: `Indicates multiple options for the resource from which the client may choose description: `Indicates multiple options for the resource from which the client may choose
(via agent-driven content negotiation). (via agent-driven content negotiation).
For example, this code could be used to present multiple video format options, For example, this code could be used to present multiple video format options,
to list files with different filename extensions, or to suggest word-sense disambiguation.`, to list files with different filename extensions, or to suggest word-sense disambiguation.`
}); });
} }
} }
HttpStatus.addStatus('300', Status300);
export class Status301 extends HttpStatus { export class status301 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 301, code: 301,
text: 'Moved Permanently', text: 'Moved Permanently',
description: `This and all future requests should be directed to the given URI.`, description: `This and all future requests should be directed to the given URI.`
}); });
} }
} }
HttpStatus.addStatus('301', Status301);
export class Status302 extends HttpStatus { export class status302 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 302, code: 302,
@ -35,13 +33,12 @@ export class Status302 extends HttpStatus {
(the original describing phrase was "Moved Temporarily"), (the original describing phrase was "Moved Temporarily"),
[20] but popular browsers implemented 302 with the functionality of a 303 See Other. [20] but popular browsers implemented 302 with the functionality of a 303 See Other.
Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours.[21] Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours.[21]
However, some Web applications and frameworks use the 302 status code as if it were the 303.`, However, some Web applications and frameworks use the 302 status code as if it were the 303.`
}); });
} }
} }
HttpStatus.addStatus('302', Status302);
export class Status303 extends HttpStatus { export class status303 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 303, code: 303,
@ -49,13 +46,12 @@ export class Status303 extends HttpStatus {
description: `The response to the request can be found under another URI using a GET method. description: `The response to the request can be found under another URI using a GET method.
When received in response to a POST (or PUT/DELETE), When received in response to a POST (or PUT/DELETE),
the client should presume that the server has received the data and should issue a redirect the client should presume that the server has received the data and should issue a redirect
with a separate GET message.`, with a separate GET message.`
}); });
} }
} }
HttpStatus.addStatus('303', Status303);
export class Status304 extends HttpStatus { export class status304 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 304, code: 304,
@ -63,13 +59,12 @@ export class Status304 extends HttpStatus {
description: `Indicates that the resource has not been modified description: `Indicates that the resource has not been modified
since the version specified by the request headers If-Modified-Since or If-None-Match. since the version specified by the request headers If-Modified-Since or If-None-Match.
In such case, there is no need to retransmit the resource since the client In such case, there is no need to retransmit the resource since the client
still has a previously-downloaded copy.`, still has a previously-downloaded copy.`
}); });
} }
} }
HttpStatus.addStatus('304', Status304);
export class Status305 extends HttpStatus { export class status305 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 305, code: 305,
@ -77,24 +72,22 @@ export class Status305 extends HttpStatus {
description: `The requested resource is available only through a proxy, description: `The requested resource is available only through a proxy,
the address for which is provided in the response. Many HTTP clients (such as Mozilla[25] the address for which is provided in the response. Many HTTP clients (such as Mozilla[25]
and Internet Explorer) do not correctly handle responses with this status code, and Internet Explorer) do not correctly handle responses with this status code,
primarily for security reasons.`, primarily for security reasons.`
}); });
} }
} }
HttpStatus.addStatus('305', Status305);
export class Status306 extends HttpStatus { export class status306 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 306, code: 306,
text: 'Switch Proxy', text: 'Switch Proxy',
description: `No longer used. Originally meant "Subsequent requests should use the specified proxy."`, description: `No longer used. Originally meant "Subsequent requests should use the specified proxy."`
}); });
} }
} }
HttpStatus.addStatus('306', Status306);
export class Status307 extends HttpStatus { export class status307 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 307, code: 307,
@ -103,21 +96,19 @@ export class Status307 extends HttpStatus {
however, future requests should still use the original URI. however, future requests should still use the original URI.
In contrast to how 302 was historically implemented, In contrast to how 302 was historically implemented,
the request method is not allowed to be changed when reissuing the original request. the request method is not allowed to be changed when reissuing the original request.
For example, a POST request should be repeated using another POST request.`, For example, a POST request should be repeated using another POST request.`
}); });
} }
} }
HttpStatus.addStatus('307', Status307);
export class Status308 extends HttpStatus { export class status308 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 308, code: 308,
text: 'Permanent Redirect', text: 'Permanent Redirect',
description: `The request and all future requests should be repeated using another URI. description: `The request and all future requests should be repeated using another URI.
307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change. 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change.
So, for example, submitting a form to a permanently redirected resource may continue smoothly.`, So, for example, submitting a form to a permanently redirected resource may continue smoothly.`
}); });
} }
} }
HttpStatus.addStatus('308', Status308);

View File

@ -1,68 +1,52 @@
import { HttpStatus, type TStatusGroup } from './smartstatus.classes.http.js'; import { HttpStatus, TStatusGroup } from './smartstatus.classes.http';
export class Status400 extends HttpStatus { export class status400 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 400, code: 400,
text: 'Bad Request', text: 'Bad Request',
description: `The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).`, description: `The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).`
}); });
} }
} }
HttpStatus.addStatus('400', Status400);
export class Status401 extends HttpStatus { export class status401 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 401, code: 401,
text: 'Unauthorized', text: 'Unauthorized',
description: `Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication.[32] 401 semantically means "unauthenticated",[33] i.e. the user does not have the necessary credentials. description: `Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication.[32] 401 semantically means "unauthenticated",[33] i.e. the user does not have the necessary credentials.
Note: Some sites issue HTTP 401 when an IP address is banned from the website (usually the website domain) and that specific address is refused permission to access a website.`, Note: Some sites issue HTTP 401 when an IP address is banned from the website (usually the website domain) and that specific address is refused permission to access a website.`
}); });
} }
} }
HttpStatus.addStatus('401', Status401);
export class Status402 extends HttpStatus { export class status402 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 402, code: 402,
text: 'Payment Required', text: 'Payment Required',
description: `The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource.`, description: `The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource.`
}); });
} }
} }
HttpStatus.addStatus('402', Status402);
export class Status403 extends HttpStatus { export class status403 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 403, code: 403,
text: 'Forbidden', text: 'Forbidden',
description: `The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource.`, description: `The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource.`
}); });
} }
} }
HttpStatus.addStatus('403', Status403);
export class Status404 extends HttpStatus { export class status404 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 404, code: 404,
text: 'Not Found', text: 'Not Found',
description: `The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.`, description: `The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.`
}); });
} }
} }
HttpStatus.addStatus('404', Status404);
export class Status429 extends HttpStatus {
constructor() {
super({
code: 429,
text: 'Too Many Requests',
description: `The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.`,
});
}
}
HttpStatus.addStatus('429', Status429);

View File

@ -1,127 +1,115 @@
import { HttpStatus, type TStatusGroup } from './smartstatus.classes.http.js'; import { HttpStatus, TStatusGroup } from './smartstatus.classes.http';
export class Status500 extends HttpStatus { export class status500 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 500, code: 500,
text: 'Internal Server Error', text: 'Internal Server Error',
description: description:
'A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.', 'A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.'
}); });
} }
} }
HttpStatus.addStatus('500', Status500);
export class Status501 extends HttpStatus { export class status501 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 501, code: 501,
text: 'Bad Request', text: 'Bad Request',
description: `The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).`, description: `The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).`
}); });
} }
} }
HttpStatus.addStatus('501', Status501);
export class Status502 extends HttpStatus { export class status502 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 502, code: 502,
text: 'Payment Required', text: 'Payment Required',
description: `The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource.`, description: `The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource.`
}); });
} }
} }
HttpStatus.addStatus('502', Status502);
export class Status503 extends HttpStatus { export class status503 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 503, code: 503,
text: 'Forbidden', text: 'Forbidden',
description: `The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource.`, description: `The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource.`
}); });
} }
} }
HttpStatus.addStatus('503', Status503);
export class Status504 extends HttpStatus { export class status504 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 504, code: 504,
text: 'Gateway Time-out', text: 'Gateway Time-out',
description: `The server was acting as a gateway or proxy description: `The server was acting as a gateway or proxy
and did not receive a timely response from the upstream server.`, and did not receive a timely response from the upstream server.`
}); });
} }
} }
HttpStatus.addStatus('504', Status504);
export class Status505 extends HttpStatus { export class status505 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 505, code: 505,
text: 'HTTP Version Not Supported', text: 'HTTP Version Not Supported',
description: `The server does not support the HTTP protocol version used in the request.`, description: `The server does not support the HTTP protocol version used in the request.`
}); });
} }
} }
HttpStatus.addStatus('505', Status505);
export class Status506 extends HttpStatus { export class status506 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 506, code: 506,
text: 'Variant Also Negotiates', text: 'Variant Also Negotiates',
description: `Transparent content negotiation for the request results in a circular reference.`, description: `Transparent content negotiation for the request results in a circular reference.`
}); });
} }
} }
HttpStatus.addStatus('506', Status506); export class status507 extends HttpStatus {
export class Status507 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 507, code: 507,
text: 'Insufficient Storage', text: 'Insufficient Storage',
description: `The server is unable to store the representation needed to complete the request.`, description: `The server is unable to store the representation needed to complete the request.`
}); });
} }
} }
HttpStatus.addStatus('507', Status507); export class status508 extends HttpStatus {
export class Status508 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 508, code: 508,
text: 'Loop Detected', text: 'Loop Detected',
description: `The server detected an infinite loop while processing the request`, description: `The server detected an infinite loop while processing the request`
}); });
} }
} }
HttpStatus.addStatus('508', Status508);
export class Status510 extends HttpStatus { export class status510 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 510, code: 510,
text: 'Loop Detected', text: 'Loop Detected',
description: `The server detected an infinite loop while processing the request`, description: `The server detected an infinite loop while processing the request`
}); });
} }
} }
export class Status511 extends HttpStatus { export class status511 extends HttpStatus {
constructor() { constructor() {
super({ super({
code: 511, code: 511,
text: 'Network Authentication Required', text: 'Network Authentication Required',
description: `The client needs to authenticate to gain network access. description: `The client needs to authenticate to gain network access.
Intended for use by intercepting proxies used to control access to the network Intended for use by intercepting proxies used to control access to the network
(e.g., "captive portals" used to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot)`, (e.g., "captive portals" used to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot)`
}); });
} }
} }
HttpStatus.addStatus('511', Status511);

View File

@ -1,30 +1,23 @@
export type TStatusGroup = 'clientError' | 'serverError'; export type TStatusGroup = 'clientError' | 'serverError';
export class HttpStatus { export class HttpStatus {
public static statusMap: { [key: string]: any } = {}; protected static statusMap: {[key:string]: HttpStatus} = {};
public static addStatus(statusStringArg: string, statusArg: any) { public static getHttpStatusByString (codeArg: number) {
HttpStatus.statusMap[statusStringArg] = statusArg; return HttpStatus.statusMap[codeArg.toString()];
} }
public static getHttpStatusByString(codeStringArg: string): HttpStatus { code: number;
let statusInstance: HttpStatus; text: string;
try { description: string;
statusInstance = new HttpStatus.statusMap[codeStringArg]();
} catch {
console.log('unknown status');
return new HttpStatus({
code: 0,
text: 'unknown status',
description: `The status ${codeStringArg} is not known.`,
});
}
return statusInstance;
}
public code: number;
public text: string;
public description: string;
constructor(optionsArg: { code: number; text: string; description: string }) { constructor(optionsArg: { code: number; text: string; description: string }) {
this.code = optionsArg.code; this.code = optionsArg.code;
this.text = optionsArg.text; this.text = optionsArg.text;
this.description = optionsArg.description; this.description = optionsArg.description;
HttpStatus.statusMap[this.code.toString()] = this;
} }
} }
export * from './smartstatus.classes.http.1xx';
export * from './smartstatus.classes.http.2xx';
export * from './smartstatus.classes.http.3xx';
export * from './smartstatus.classes.http.4xx';
export * from './smartstatus.classes.http.5xx';

View File

@ -1,16 +0,0 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
"baseUrl": ".",
"paths": {}
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

17
tslint.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}