update tsconfig

This commit is contained in:
Philipp Kunz 2024-04-14 18:40:21 +02:00
parent 04d6240ffb
commit 1d3786f2ce
4 changed files with 124 additions and 30 deletions

View File

@ -5,17 +5,27 @@
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "webjwt",
"description": "a package to handle jwt in the web",
"description": "A package for handling JWTs in web environments.",
"npmPackagename": "@push.rocks/webjwt",
"license": "MIT",
"projectDomain": "push.rocks"
"projectDomain": "push.rocks",
"keywords": [
"jwt",
"web",
"authentication",
"security",
"token parsing",
"JSON Web Tokens",
"smartstring",
"typescript"
]
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdocs": {
"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"
}
}

View File

@ -2,7 +2,7 @@
"name": "@push.rocks/webjwt",
"version": "1.0.9",
"private": false,
"description": "a package to handle jwt in the web",
"description": "A package for handling JWTs in web environments.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
@ -39,5 +39,15 @@
"cli.js",
"npmextra.json",
"readme.md"
],
"keywords": [
"jwt",
"web",
"authentication",
"security",
"token parsing",
"JSON Web Tokens",
"smartstring",
"typescript"
]
}

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

123
readme.md
View File

@ -1,37 +1,110 @@
# @push.rocks/webjwt
a package to handle jwt in the web
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/webjwt)
* [gitlab.com (source)](https://gitlab.com/push.rocks/webjwt)
* [github.com (source mirror)](https://github.com/push.rocks/webjwt)
* [docs (typedoc)](https://push.rocks.gitlab.io/webjwt/)
## Install
## Status for master
To install `@push.rocks/webjwt`, ensure you have Node.js and npm installed. Then run the following command in your terminal:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/webjwt/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/webjwt/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/webjwt)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/webjwt)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/webjwt)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/webjwt)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/webjwt)](https://lossless.cloud)
```bash
npm install @push.rocks/webjwt --save
```
This command installs `@push.rocks/webjwt` and adds it to your project's `package.json` dependencies.
## Usage
Use TypeScript for best in class intellisense
This module provides a streamlined way to handle JSON Web Tokens (JWT) within web contexts, leveraging TypeScript for type safety and developer ergonomics. Let's dive into how you can utilize `@push.rocks/webjwt` in your project.
## Contribution
### Importing the Module
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
First, import the necessary functions from the module in your TypeScript file:
For further information read the linked docs at the top of this readme.
```typescript
import { getDataFromJwtString } from '@push.rocks/webjwt';
```
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
### Decoding JWT
`@push.rocks/webjwt` simplifies the process of decoding JWTs to extract data payloads without dealing with the intricacies of token verification or parsing manually. Here's a basic example of decoding a JWT string to extract its payload:
```typescript
// Example JWT string (Note: This is just an example and not a valid token)
const jwtString: string = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvZSBEb2UiLCJpYXQiOjE1MTYyMzkwMjJ9.abcd1234';
// Decode the JWT and extract the data payload
const decodedData = getDataFromJwtString<{ sub: string; name: string; iat: number }>(jwtString);
// Log the decoded data
console.log(decodedData);
// Output would be an object containing the sub, name, and iat fields from the JWT payload
```
### Handling Custom JWT Payloads
`@push.rocks/webjwt` is designed to be flexible, allowing you to define the structure of your JWT payload as needed. The generic `<T>` in the `getDataFromJwtString` function enables you to specify the expected shape of your payload, ensuring type safety:
```typescript
// Define a custom payload structure
interface MyCustomPayload {
userId: string;
permissions: string[];
issuedAt: number;
}
// Example JWT string with a custom payload
const customJwtString: string = 'your.jwt.string.here';
// Decode the JWT with a custom payload
const customDecodedData = getDataFromJwtString<MyCustomPayload>(customJwtString);
// Accessing the custom payload data with full TypeScript support
console.log(`User ID: ${customDecodedData.userId}`);
console.log(`Permissions: ${customDecodedData.permissions.join(', ')}`);
```
### Real-World Scenario: User Authentication
In a web application, you might want to use JWTs for user authentication. After the user logs in, you receive a JWT from your authentication server. You can then decode this token on the client side to obtain user-specific information without making additional requests to the server:
```typescript
// This example assumes you have a function to get the auth token, e.g., from local storage or a cookie
const authToken: string = getAuthTokenFromStorage();
// Define the expected structure of your authentication payload
interface AuthPayload {
userId: string;
userName: string;
roles: string[];
}
// Decode the authentication token
const authInfo = getDataFromJwtString<AuthPayload>(authToken);
// Use the decoded information, for example, to customize the UI
console.log(`Welcome, ${authInfo.userName}!`);
// Potentially, check for roles to display certain UI elements
if (authInfo.roles.includes('admin')) {
console.log('Displaying admin panel...');
}
```
`@push.rocks/webjwt` enables efficient, type-safe handling of JWTs in your TypeScript web projects, simplifying the process of decoding and utilizing token payloads according to your application's requirements.
## 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.