@bts-soft/core 2.4.6 → 2.4.8

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
@@ -1,5 +1,10 @@
1
1
  # @bts-soft/core
2
2
 
3
+ ![NestJS](https://img.shields.io/badge/NestJS-%3E%3D11.0.0-E0234E?style=flat-square&logo=nestjs)
4
+ ![Node](https://img.shields.io/badge/Node-%3E%3D20.17.0-339933?style=flat-square&logo=node.js)
5
+ ![TypeScript](https://img.shields.io/badge/TypeScript-5.5-3178C6?style=flat-square&logo=typescript)
6
+ ![License](https://img.shields.io/badge/License-MIT-blue?style=flat-square)
7
+
3
8
  ## The Definitive Enterprise Meta-Framework for NestJS
4
9
 
5
10
  `@bts-soft/core` is not just a package; it is the architectural backbone of the BTS Soft enterprise ecosystem. It streamlines the development of high-performance, secure, and scalable NestJS applications by consolidating five specialized packages into a unified, high-level API.
@@ -8,6 +13,82 @@ This documentation serves as the comprehensive technical manual for the entire c
8
13
 
9
14
  ---
10
15
 
16
+ ## Table of Contents
17
+ - [Installation \& Quick Start](#installation--quick-start)
18
+ - [Core Vision \& Architecture](#core-vision--architecture)
19
+ - [Module Index](#module-index)
20
+ - [Deep Dive: @bts-soft/validation](#deep-dive-bts-softvalidation)
21
+ - [Deep Dive: @bts-soft/cache](#deep-dive-bts-softcache)
22
+ - [Deep Dive: @bts-soft/notifications](#deep-dive-bts-softnotifications)
23
+ - [Deep Dive: @bts-soft/upload](#deep-dive-bts-softupload)
24
+ - [Deep Dive: @bts-soft/common](#deep-dive-bts-softcommon)
25
+ - [Security Audit \& Hardening Guide](#security-audit--hardening-guide)
26
+ - [Deployment, CI/CD, and Operations](#deployment-cicd-and-operations)
27
+ - [The Giant Book of Usage Examples](#the-giant-book-of-usage-examples)
28
+ - [Frequently Asked Questions (FAQ)](#frequently-asked-questions-faq)
29
+ - [Exhaustive Redis API Guide](#exhaustive-redis-api-guide)
30
+
31
+ ---
32
+
33
+ ## Installation & Quick Start
34
+
35
+ ### 1. Install the Package
36
+
37
+ ```bash
38
+ npm install @bts-soft/core
39
+ ```
40
+
41
+ *Note: `@bts-soft/core` requires `Node.js >= 20.17.0` and has peer dependencies on `@nestjs/common` and `@nestjs/core` (v11+).*
42
+
43
+ ### 2. Basic Integration
44
+
45
+ Import the individual modules provided by `@bts-soft/core` into your `AppModule` or use them as needed:
46
+
47
+ ```typescript
48
+ import { Module } from '@nestjs/common';
49
+ import {
50
+ ConfigModule,
51
+ GraphqlModule,
52
+ ThrottlingModule
53
+ } from '@bts-soft/core';
54
+
55
+ @Module({
56
+ imports: [
57
+ ConfigModule,
58
+ ThrottlingModule,
59
+ GraphqlModule,
60
+ // Add other core modules like RedisModule, UploadModule, etc. as needed
61
+ ],
62
+ })
63
+ export class AppModule {}
64
+ ```
65
+
66
+ ### 3. Bootstrap Utilities
67
+
68
+ In your `main.ts`, utilize the core infrastructure to set up global interceptors and launch banners:
69
+
70
+ ```typescript
71
+ import { NestFactory } from '@nestjs/core';
72
+ import { AppModule } from './app.module';
73
+ import { setupInterceptors, displayAppBanner } from '@bts-soft/core';
74
+
75
+ async function bootstrap() {
76
+ const app = await NestFactory.create(AppModule);
77
+
78
+ // Apply standard BTS-Soft global interceptors (Serialization, SQLi Protection, Formatting)
79
+ setupInterceptors(app);
80
+
81
+ const port = process.env.PORT || 3000;
82
+ await app.listen(port);
83
+
84
+ // Display the professional terminal banner
85
+ displayAppBanner('My Service', port);
86
+ }
87
+ bootstrap();
88
+ ```
89
+
90
+ ---
91
+
11
92
  ## Core Vision & Architecture
12
93
 
13
94
  The primary objective of `@bts-soft/core` is to eliminate "infrastructure boilerplate." Instead of configuring Redis, Cloudinary, BullMQ, and Nodemailer repeatedly for every microservice, developers can import a single module that provides pre-validated, secure, and performant implementations of these essential services.
@@ -299,10 +380,10 @@ By calling `setupInterceptors(app)` in your `main.ts`, you enable a powerful sui
299
380
  Uses `class-transformer` to filter out sensitive fields (marked with `@Exclude()`) and include computed properties (marked with `@Expose()`).
300
381
 
301
382
  2. **`SqlInjectionInterceptor`**:
302
- A global scanner that intercepts all incoming request payloads (Body, Query, Params) and checks every string against the `SQL_INJECTION_REGEX`. If a violation is caught, it automatically throws a `400 Bad Request` before the controller logic is executed.
383
+ A global scanner that intercepts all incoming request payloads (Body, Query, Params) and checks every string against a predefined regex. If a violation is caught, it automatically throws a `400 Bad Request` before the controller logic is executed.
303
384
 
304
385
  3. **`GeneralResponseInterceptor`**:
305
- The most visible part of the common module. It ensures that every response, whether it's a single entity, a list, or an error, follows the exact same JSON structure.
386
+ Ensures that every REST response follows the exact same JSON structure. For GraphQL, it automatically skips formatting to preserve schema integrity while still allowing for global error handling.
306
387
 
307
388
  #### The Standard Response Envelope
308
389
  ```json
@@ -326,25 +407,37 @@ By calling `setupInterceptors(app)` in your `main.ts`, you enable a powerful sui
326
407
  ### Shared Base Classes
327
408
 
328
409
  #### 1. `BaseEntity` (The Persistence Foundation)
329
- All database entities in the system should extend `BaseEntity`.
410
+ All database entities in the system should extend a specialized base class.
330
411
 
331
- - **ULID Integration**: Instead of predictable numeric IDs, it uses **ULIDs** (Universally Unique Lexicographically Sortable Identifiers). These are 26-character strings that are both unique and sortable by creation time.
412
+ - **ULID Integration**: Instead of predictable numeric IDs, it uses ULIDs (Universally Unique Lexicographically Sortable Identifiers) which are both unique and sortable.
332
413
  - **Audit Trails**: Automatically generates `createdAt` and `updatedAt` timestamps.
333
- - **Lifecycle Hooks**: Includes pre-configured `AfterInsert`, `AfterUpdate`, and `BeforeRemove` logging to help with debugging database interactions in production.
414
+ - **Multi-ORM Support**: Includes dedicated bases for TypeORM, Sequelize, Mongoose, Prisma, and GraphQL.
334
415
 
335
416
  #### 2. `BaseResponse` (The API Contract)
336
- Used as a base class for DTOs and GraphQL Object Types to ensure consistency in manual response construction.
417
+ Used as a base class for DTOs and GraphQL Object Types to ensure consistency in response construction.
337
418
 
338
419
  ---
339
420
 
340
421
  ### Infrastructure Modules
341
422
 
342
- The common package also provides pre-configured NestJS modules:
423
+ The common package provides pre-configured NestJS modules:
343
424
 
344
425
  - **`ConfigModule`**: A wrapper around `@nestjs/config` with built-in validation.
345
- - **`ThrottlingModule`**: Pre-configured rate limiting to prevent Brute-Force and DDoS attacks.
426
+ - **`ThrottlingModule`**: Robust rate limiting that automatically handles both HTTP and GraphQL contexts.
346
427
  - **`TranslationModule`**: Integrated `nestjs-i18n` support for multi-language applications (Arabic/English).
347
- - **`GraphqlModule`**: The standard Apollo Server setup with custom error filters that bridge the gap between GraphQL and HTTP status codes.
428
+ - **`GraphqlModule`**: Standard Apollo Server setup with custom error filters and a context that includes both request and response objects.
429
+
430
+ ---
431
+
432
+ ### Production & CLI Utilities
433
+
434
+ The common package exposes tools to manage environment-specific behaviors:
435
+
436
+ - **`disableConsoleInProduction()`**: A safety utility to mute all `console` outputs when running in production.
437
+ - **`displayAppBanner(appName, port)`**: Displays a clean, professional banner in the terminal when the server starts.
438
+
439
+ ---
440
+
348
441
 
349
442
  ---
350
443
 
@@ -503,6 +596,12 @@ The Upload module provides:
503
596
  - Size caps to prevent Disk Exhaustion attacks.
504
597
  - Strategy-level validation to ensure the cloud provider is reputable and secure.
505
598
 
599
+ ### 5. Production Optimization & Information Leakage Prevention
600
+
601
+ To prevent sensitive data from leaking into server logs (such as tokens, passwords, or PII mistakenly logged during development), the `@bts-soft/core` meta-package **automatically disables all `console.*` methods** (e.g., `console.log`, `console.error`) the moment it is imported, provided that `process.env.NODE_ENV === "production"`.
602
+
603
+ If your production environment requires structured logging, you should use the NestJS `Logger` class or a dedicated logging transport instead of native `console` methods.
604
+
506
605
  ---
507
606
 
508
607
  ## Deployment, CI/CD, and Operations
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from '@bts-soft/notifications';
2
- export * from '@bts-soft/cache';
3
- export * from '@bts-soft/upload';
4
- export * from '@bts-soft/validation';
5
- export * from '@bts-soft/common';
1
+ export * from "@bts-soft/notifications";
2
+ export * from "@bts-soft/cache";
3
+ export * from "@bts-soft/upload";
4
+ export * from "@bts-soft/validation";
5
+ export * from "@bts-soft/common";
package/dist/index.js CHANGED
@@ -19,4 +19,12 @@ __exportStar(require("@bts-soft/cache"), exports);
19
19
  __exportStar(require("@bts-soft/upload"), exports);
20
20
  __exportStar(require("@bts-soft/validation"), exports);
21
21
  __exportStar(require("@bts-soft/common"), exports);
22
+ if (process.env.NODE_ENV === "production") {
23
+ const noop = () => { };
24
+ console.log = noop;
25
+ console.error = noop;
26
+ console.warn = noop;
27
+ console.info = noop;
28
+ console.debug = noop;
29
+ }
22
30
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,0DAAwC;AAGxC,kDAAgC;AAGhC,mDAAiC;AAGjC,uDAAqC;AAGrC,mDAAiC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,0DAAwC;AAGxC,kDAAgC;AAGhC,mDAAiC;AAGjC,uDAAqC;AAGrC,mDAAiC;AAEjC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;IAC1C,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IACnB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IACrB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;AACvB,CAAC"}