nodecore-kit 0.2.0 → 0.3.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 ADDED
@@ -0,0 +1,138 @@
1
+ # nodeCore-kit
2
+
3
+ **A modular backend SDK for Node.js services.**
4
+
5
+ Provides infrastructure helpers, utilities, and microservice building blocks in a clean, scalable, and framework-agnostic way.
6
+
7
+ ---
8
+
9
+ ## 📦 Features
10
+
11
+ ### Infrastructure Helpers
12
+ - Redis wrapper
13
+ - SQS wrapper
14
+ - *(Future: Kafka, etc.)*
15
+
16
+ ### HTTP Utilities
17
+ - `getContent`, `postContent` — typed fetch wrappers
18
+ - Pagination helpers
19
+
20
+ ### Core Utilities
21
+ - `uuid` — binary/string conversion, generation, and validation
22
+ - JSON parse/stringify helpers
23
+ - `joiValidator` for request validation
24
+ - `sleep`, `formatDate`, and more
25
+
26
+ ### Security
27
+ - JWT encode/decode services
28
+
29
+ ### Logging
30
+ - Optional logger injection
31
+ - Compatible with `console` or structured loggers like Winston
32
+
33
+ ### Error Handling
34
+ - `ValidationError`
35
+ - `ServerError`
36
+ - `NotFoundError`
37
+
38
+ ---
39
+
40
+ ## ⚡ Installation
41
+
42
+ ```bash
43
+ npm install nodecore-kit
44
+ # or
45
+ yarn add nodecore-kit
46
+ ```
47
+
48
+ ---
49
+
50
+ ## 🔌 Usage Examples
51
+
52
+ ```ts
53
+ import {
54
+ uuid,
55
+ joiValidator,
56
+ paginate,
57
+ SQS,
58
+ SqsConfig,
59
+ WinstonLogger,
60
+ jwtService,
61
+ } from "nodecore-kit";
62
+ ```
63
+
64
+ ### UUID
65
+
66
+ ```ts
67
+ const id = uuid.get("v4");
68
+ ```
69
+
70
+ ### Joi Validator
71
+
72
+ ```ts
73
+ const schema = {
74
+ schema: { name: Joi.string().required() },
75
+ data: { name: "Alice" },
76
+ };
77
+
78
+ joiValidator(schema, false);
79
+ ```
80
+
81
+ ### Pagination
82
+
83
+ ```ts
84
+ const { pageCount, offset } = paginate(100, 2, 10);
85
+ ```
86
+
87
+ ### SQS Adapter
88
+
89
+ ```ts
90
+ const config: SqsConfig = {
91
+ region: "us-east-1",
92
+ accessKeyId: "your-key",
93
+ secretAccessKey: "your-secret",
94
+ };
95
+
96
+ // Optional custom logger
97
+ const logger = new WinstonLogger();
98
+
99
+ // Initialize adapter
100
+ const sqs = new SQS(config, logger);
101
+
102
+ // Enqueue a message
103
+ await sqs.enqueue({
104
+ queueUrl: "https://sqs.us-east-1.amazonaws.com/1234/my-queue",
105
+ message: { hello: "world" },
106
+ });
107
+ ```
108
+
109
+ ### JWT Service
110
+
111
+ ```ts
112
+ const token = await jwtService.encode({ data: { userId: 123 } }, "mySecret");
113
+ const decoded = await jwtService.decode(token, "mySecret");
114
+ ```
115
+
116
+ ---
117
+
118
+ ## 🏗️ Architecture Principles
119
+
120
+ | Layer | Description |
121
+ |---|---|
122
+ | **Core** | Pure utilities, errors, and types. Independent from adapters or transports. |
123
+ | **Adapters** | External services (SQS, Redis, DB). Depend only on core. |
124
+ | **Transport** | HTTP layers. May depend on core. |
125
+ | **Security** | JWT, hashing. Depends only on core. |
126
+ | **Logger** | Optional, adapter-friendly, injected as a dependency. |
127
+
128
+ > **No global environment reads inside adapters** — all configuration is passed via constructor.
129
+
130
+ ---
131
+
132
+ ## 🌱 Design Goals
133
+
134
+ - **Simplicity** — Easy to pick up and integrate into any project.
135
+ - **Modularity** — Pick and use only what you need.
136
+ - **Scalable** — Built for microservices and multi-service architectures.
137
+ - **Plug-n-Play** — Default logging works with `console`, but advanced logging can be injected.
138
+ - **Framework-Agnostic** — Works with Express, Fastify, NestJS, or bare Node.js.