keypointjs 1.0.0 → 1.1.0

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/README.md CHANGED
@@ -6,8 +6,6 @@
6
6
 
7
7
  </div>
8
8
 
9
- Based on your complete codebase, here is the comprehensive documentation:
10
-
11
9
  <div align="center">
12
10
  <p align="center">
13
11
  <img alt="GitHub" src="https://img.shields.io/github/license/anasbex-dev/keypointjs?color=blue">
@@ -23,7 +21,6 @@ Based on your complete codebase, here is the comprehensive documentation:
23
21
  </div>
24
22
 
25
23
 
26
-
27
24
  # Project Overview
28
25
 
29
26
  KeypointJS is a sophisticated, layered authentication and authorization framework for Node.js with built-in security features, plugin architecture, and real-time capabilities.
@@ -51,7 +48,6 @@ Layered Middleware System
51
48
  │ Layer 7: Response Processing │
52
49
  └─────────────────────────────────┘
53
50
  ```
54
-
55
51
  # File Structure & Responsibilities
56
52
 
57
53
  ## Core Components (core/)
@@ -192,6 +188,16 @@ responses
192
188
 
193
189
  Installation & Setup
194
190
 
191
+ ``` bash
192
+
193
+ npm install keypointjs
194
+ # or
195
+ yarn add keypointjs
196
+ # or
197
+ pnpm add keypointjs
198
+
199
+ ```
200
+
195
201
  ```javascript
196
202
  import { KeypointJS } from './src/keypointJS.js';
197
203
 
@@ -800,7 +806,10 @@ Apache-2.0 license - see the LICENSE file for details.
800
806
  - Contributions: PRs welcome for bug fixes and features
801
807
  - Questions: Open a discussion for usage questions
802
808
 
803
- ---
809
+ ## KeypointJS is Independent
810
+
811
+ KeypointJS does not depend on Express, Fastify, or any third-party HTTP framework.
812
+ It ships with its own HTTP server, routing system, middleware pipeline, and security layer.
804
813
 
805
814
  ## Created Base ♥️ KeypointJS
806
815
  ### AnasBex - (⁠づ⁠ ̄⁠ ⁠³⁠ ̄⁠)⁠づ
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keypointjs",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "KeypointJS Identity-First API Framework with Mandatory Authentication",
5
5
  "main": "src/keypointJS.js",
6
6
  "type": "module",
@@ -12,6 +12,7 @@
12
12
  "./keypoint/validator": "./src/keypoint/KeypointValidator.js",
13
13
  "./keypoint/scopes": "./src/keypoint/ScopeManager.js",
14
14
  "./plugins": "./src/plugins/PluginManager.js",
15
+ "./plugins/transformer": "./src/plugins/transformer/TransformerPlugin.js",
15
16
  "./plugins/audit": "./src/plugins/AuditLogger.js",
16
17
  "./plugins/ratelimit": "./src/plugins/RateLimiter.js",
17
18
  "./plugins/websocket": "./src/plugins/WebSocketGuard.js",
@@ -0,0 +1,82 @@
1
+ // Copyright AnasBex - 2026 TransformersPlugin.js
2
+ /*
3
+
4
+ API response standardization
5
+
6
+ Inject metadata (requestId, timestamp, duration)
7
+
8
+ Optional envelope (success, data, error)
9
+
10
+ */
11
+
12
+ export class TransformerPlugin {
13
+ constructor(options = {}) {
14
+ this.options = {
15
+ envelope: true,
16
+ addRequestId: true,
17
+ addTimestamp: true,
18
+ addDuration: true,
19
+ ...options
20
+ };
21
+ }
22
+
23
+ async process(ctx, next) {
24
+ const start = Date.now();
25
+
26
+ const response = await next(ctx);
27
+
28
+ // Jika handler return null / undefined
29
+ if (!response) return response;
30
+
31
+ // Jika response bukan object API KeypointJS
32
+ if (typeof response !== 'object' || !response.body) {
33
+ return response;
34
+ }
35
+
36
+ const duration = Date.now() - start;
37
+
38
+ // Error response
39
+ if (response.status >= 400) {
40
+ return {
41
+ ...response,
42
+ body: this.options.envelope
43
+ ? {
44
+ success: false,
45
+ error: response.body,
46
+ meta: this._meta(ctx, duration)
47
+ }
48
+ : response.body
49
+ };
50
+ }
51
+
52
+ // Success response
53
+ return {
54
+ ...response,
55
+ body: this.options.envelope
56
+ ? {
57
+ success: true,
58
+ data: response.body,
59
+ meta: this._meta(ctx, duration)
60
+ }
61
+ : response.body
62
+ };
63
+ }
64
+
65
+ _meta(ctx, duration) {
66
+ const meta = {};
67
+
68
+ if (this.options.addRequestId) {
69
+ meta.requestId = ctx.id;
70
+ }
71
+
72
+ if (this.options.addTimestamp) {
73
+ meta.timestamp = new Date().toISOString();
74
+ }
75
+
76
+ if (this.options.addDuration) {
77
+ meta.durationMs = duration;
78
+ }
79
+
80
+ return meta;
81
+ }
82
+ }