nhb-toolbox 4.28.0 → 4.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ All notable changes to the package will be documented here.
6
6
 
7
7
  ---
8
8
 
9
+ ## [4.28.1] - 2025-12-02
10
+
11
+ - **Updated** *type* names `TokenHeader` to `SignetHeader` and `TokenPayload` to `SignetPayload` and both are available to import.
12
+
9
13
  ## [4.28.0] - 2025-12-01
10
14
 
11
15
  - **Added** *new* class `Cipher` to *encrypt/decrypt* string with *secret key*.
@@ -1,5 +1,5 @@
1
1
  import type { GenericObject } from '../object/types';
2
- import type { DecodedToken, SignOptions, TokenPayload, TokenString, VerifiedToken, VerifyOptions } from './types';
2
+ import type { DecodedToken, SignetPayload, SignOptions, TokenString, VerifiedToken, VerifyOptions } from './types';
3
3
  /**
4
4
  * * A lightweight, secure implementation of JWT-like tokens using `HMAC-SHA256` signatures.
5
5
  * - This class provides methods to create, verify, and decode tokens with a simple API similar to JSON Web Tokens (`JWT`) but with a smaller footprint and zero dependencies.
@@ -166,7 +166,7 @@ export declare class Signet {
166
166
  *
167
167
  * @remarks
168
168
  * - Tokens without `exp` claim are considered non-expiring (returns `false`)
169
- * - Uses current system time for comparison
169
+ * - Uses current system time for comparison ({@link Date.now()})
170
170
  * - Does not verify the signature (use only with trusted tokens or after verification)
171
171
  *
172
172
  * @example
@@ -192,7 +192,10 @@ export declare class Signet {
192
192
  *
193
193
  * @throws If the token is malformed or cannot be decoded.
194
194
  *
195
- * @remarks Useful for implementing time-based access control, like activation links that shouldn't be used until a certain time.
195
+ * @remarks
196
+ * - Useful for implementing time-based access control, like activation links that shouldn't be used until a certain time.
197
+ * - Uses current system time for comparison ({@link Date.now()})
198
+ * - Does not verify the signature (use only with trusted tokens or after verification)
196
199
  *
197
200
  * @example
198
201
  * ```typescript
@@ -310,7 +313,7 @@ export declare class Signet {
310
313
  * @param options - Optional validation criteria for token claims.
311
314
  *
312
315
  * @returns A {@link VerifiedToken} object indicating success or failure.
313
- * - If valid: `{ isValid: true, payload: TokenPayload<T> }`
316
+ * - If valid: `{ isValid: true, payload: SignetPayload<T> }`
314
317
  * - If invalid: `{ isValid: false, error: string }`
315
318
  *
316
319
  * @remarks
@@ -440,5 +443,5 @@ export declare class Signet {
440
443
  * const canDelete = payload.permissions.includes('delete');
441
444
  * ```
442
445
  */
443
- decodePayload<T extends GenericObject = GenericObject>(token: string): TokenPayload<T>;
446
+ decodePayload<T extends GenericObject = GenericObject>(token: string): SignetPayload<T>;
444
447
  }
@@ -45,7 +45,7 @@ export interface DecodedUUID {
45
45
  node?: string;
46
46
  }
47
47
  /** Header for `Signet` */
48
- export type TokenHeader = {
48
+ export type SignetHeader = {
49
49
  /** Algorithm used. Currently supports `'HS256'` only */
50
50
  alg: 'HS256';
51
51
  /** Type of token. Fixed `'SIGNET+JWT'` */
@@ -79,14 +79,14 @@ export interface SignOptions extends VerifyOptions {
79
79
  */
80
80
  notBefore?: TimeWithUnit | Numeric;
81
81
  }
82
- /** Pattern of a valid 3-parts token */
82
+ /** 3-parts dot separated token string */
83
83
  export type TokenString = `${string}.${string}.${string}`;
84
84
  /** Interface of token verification result if token is valid */
85
85
  export type $ValidToken<T extends GenericObject = GenericObject> = {
86
86
  /** Whether the token is valid */
87
87
  isValid: true;
88
- /** Decoded payload after successful verification with common {@link TokenPayload} properties */
89
- payload: TokenPayload<T>;
88
+ /** Decoded payload after successful verification with common {@link SignetPayload} properties */
89
+ payload: SignetPayload<T>;
90
90
  };
91
91
  /** Interface of token verification result if token is invalid */
92
92
  export type $InvalidToken = {
@@ -97,7 +97,7 @@ export type $InvalidToken = {
97
97
  };
98
98
  /** Result of token verification */
99
99
  export type VerifiedToken<T extends GenericObject = GenericObject> = $ValidToken<T> | $InvalidToken;
100
- export type TokenPayload<T extends GenericObject = GenericObject> = {
100
+ export type SignetPayload<T extends GenericObject = GenericObject> = {
101
101
  /** When the token was created (unix timestamp in seconds) */
102
102
  iat: number;
103
103
  /** When the token was created (as JavaScript {@link Date}) */
@@ -120,9 +120,9 @@ export type TokenPayload<T extends GenericObject = GenericObject> = {
120
120
  /** Interface of a decoded token */
121
121
  export type DecodedToken<T extends GenericObject = GenericObject> = {
122
122
  /** Token header info, algorithm, type etc. */
123
- header: TokenHeader;
124
- /** Decoded payload after with common {@link TokenPayload} properties */
125
- payload: TokenPayload<T>;
123
+ header: SignetHeader;
124
+ /** Decoded payload after with common {@link SignetPayload} properties */
125
+ payload: SignetPayload<T>;
126
126
  /**
127
127
  * The `Base64`-encoded signature from the token.
128
128
  * This is the third part of the token string.
@@ -131,3 +131,4 @@ export type DecodedToken<T extends GenericObject = GenericObject> = {
131
131
  /** The header and payload in encrypted `Base64` format.*/
132
132
  signingInput: `${string}.${string}`;
133
133
  };
134
+ export type { SignetPayload as TokenPayload, SignetHeader as TokenHeader };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.28.0",
3
+ "version": "4.28.1",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -42,8 +42,8 @@
42
42
  "@eslint/js": "^9.39.1",
43
43
  "@types/jest": "^30.0.0",
44
44
  "@types/node": "^24.10.1",
45
- "@typescript-eslint/eslint-plugin": "^8.47.0",
46
- "@typescript-eslint/parser": "^8.47.0",
45
+ "@typescript-eslint/eslint-plugin": "^8.48.0",
46
+ "@typescript-eslint/parser": "^8.48.0",
47
47
  "eslint": "^9.39.1",
48
48
  "eslint-config-prettier": "^10.1.8",
49
49
  "eslint-plugin-prettier": "^5.5.4",
@@ -52,10 +52,10 @@
52
52
  "jest": "^30.2.0",
53
53
  "lint-staged": "^16.2.7",
54
54
  "nhb-scripts": "^1.8.88",
55
- "prettier": "^3.6.2",
56
- "ts-jest": "^29.4.5",
55
+ "prettier": "^3.7.3",
56
+ "ts-jest": "^29.4.6",
57
57
  "typescript": "^5.9.3",
58
- "typescript-eslint": "^8.47.0"
58
+ "typescript-eslint": "^8.48.0"
59
59
  },
60
60
  "keywords": [
61
61
  "toolbox",