@futdevpro/nts-dynamo 1.15.170 → 1.15.174
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/LICENSE +21 -21
- package/README.md +809 -799
- package/build/_modules/pagination/_models/keyset-cursor.interface.d.ts +16 -0
- package/build/_modules/pagination/_models/keyset-cursor.interface.d.ts.map +1 -0
- package/build/_modules/pagination/_models/keyset-cursor.interface.js +3 -0
- package/build/_modules/pagination/_models/keyset-cursor.interface.js.map +1 -0
- package/build/_modules/pagination/index.d.ts +3 -0
- package/build/_modules/pagination/index.d.ts.map +1 -0
- package/build/_modules/pagination/index.js +6 -0
- package/build/_modules/pagination/index.js.map +1 -0
- package/build/_modules/pagination/keyset-cursor.control-service.d.ts +21 -0
- package/build/_modules/pagination/keyset-cursor.control-service.d.ts.map +1 -0
- package/build/_modules/pagination/keyset-cursor.control-service.js +116 -0
- package/build/_modules/pagination/keyset-cursor.control-service.js.map +1 -0
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -1,799 +1,809 @@
|
|
|
1
|
-
# Dynamo-NTS
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-
**Dynamo-NTS** (NodeTS) is a comprehensive backend framework for building robust, secure, and scalable Node.js applications with TypeScript. Built on top of [Dynamo FSM](https://www.npmjs.com/package/@futdevpro/fsm-dynamo) (`@futdevpro/fsm-dynamo`), it provides a structured approach to server-side development with clear separation of concerns, extensive configuration options, and production-ready implementations for common backend tasks.
|
|
6
|
-
|
|
7
|
-
Dynamo-NTS uses **[Dynamo FSM](https://www.npmjs.com/package/@futdevpro/fsm-dynamo)** as its foundational layer, implementing the server-side components of the FSM architecture. All core interfaces, types, and utilities are provided by FSM, ensuring consistency and type safety across the entire Dynamo ecosystem.
|
|
8
|
-
|
|
9
|
-
Dynamo-NTS is part of the unified **Dynamo ecosystem**, a full-stack development framework designed to accelerate the development of scalable web applications. The ecosystem consists of interconnected packages that work together seamlessly, with Dynamo-NTS serving as the backend implementation layer. The frontend counterpart is **[Dynamo NGX](https://www.npmjs.com/package/@futdevpro/ngx-dynamo)**, which uses **[Dynamo NGX Models](https://www.npmjs.com/package/@futdevpro/ngx-dynamo-models)** for type-safe model definitions.
|
|
10
|
-
|
|
11
|
-
### Design Philosophy
|
|
12
|
-
|
|
13
|
-
Dynamo-NTS is built with two key principles:
|
|
14
|
-
|
|
15
|
-
- **Full Override Capability**: Every component, service, and class can be overridden or extended. The framework provides a solid foundation with sensible defaults, but you have complete control to customize or replace any part to fit your specific needs. This makes Dynamo-NTS highly customizable and adaptable to any project requirements.
|
|
16
|
-
|
|
17
|
-
- **Complete Type Information**: All types, interfaces, and definitions are included in the compiled output. This ensures excellent readability and maintainability—everything you need is available at compile time through TypeScript's type system, providing full IntelliSense support and eliminating the need to reference external documentation during development.
|
|
18
|
-
|
|
19
|
-
### Simplified System Definitions
|
|
20
|
-
|
|
21
|
-
Dynamo-NTS simplifies complex system definitions by abstracting common backend infrastructure into simple parameterization. Instead of manually configuring various libraries and services, you define your application through straightforward parameter objects:
|
|
22
|
-
|
|
23
|
-
- **Express Usage**: HTTP/HTTPS server setup, routing, middleware, and error handling are configured through `DyNTS_App_Params`, `DyNTS_Http_Settings`, and `DyNTS_RoutingModule` parameters (simplifies Express server initialization and route management)
|
|
24
|
-
- **MongoDB/Mongoose Usage**: Database connections, models, schemas, and operations are managed through `DyNTS_DBService` and `DyNTS_DataService` with simple data model parameter definitions (simplifies Mongoose schema creation and model management)
|
|
25
|
-
- **Socket.io Usage**: Real-time communication setup, event handling, and presence tracking are configured through `DyNTS_SocketServerService` parameters and the `DyNTS_AppExtended` class (simplifies Socket.io server initialization and event management)
|
|
26
|
-
- **Nodemailer Usage**: Email sending with templating, attachments, and async delivery is handled through `DyNTS_EmailService` with template component definitions (simplifies Nodemailer transporter setup and email template management)
|
|
27
|
-
- **OAuth2 Implementation**: Complete OAuth2.0 protocol flows including authorization codes, token exchange, and refresh tokens are managed through `DyNTS_OAuth2_Controller` and `DyNTS_OAuth2_AuthService` (simplifies complex OAuth2 flow implementation)
|
|
28
|
-
- **Axios Usage**: HTTP client requests to external APIs are standardized through `DyNTS_ApiService` with `DyNTS_ApiCall_Params` configuration (simplifies Axios request setup, error handling, and response management)
|
|
29
|
-
- **Discord.js / Slack / Teams Bot Development**: Platform-agnostic bot framework through `DyNTS_Bot_MessagingProvider_ServiceBase` and bot modules (simplifies Discord.js, Slack, and Teams bot development with unified interfaces)
|
|
30
|
-
- **OpenAI / AI Provider Integration**: AI/LLM operations including chat, embeddings, and vector search are abstracted through `DyNTS_AI_Provider_ServiceBase` and provider implementations (simplifies OpenAI SDK usage and enables multi-provider architecture)
|
|
31
|
-
- **Location Tracking**: Optional, local-only IP geolocation through `geoip-lite`; addresses are not sent to an external service or written to logs by Dynamo-NTS
|
|
32
|
-
|
|
33
|
-
This parameterization approach eliminates boilerplate code and provides a consistent, type-safe interface for all backend operations. Instead of learning multiple library APIs and their configuration patterns, developers work with unified Dynamo-NTS parameter objects that handle the underlying complexity.
|
|
34
|
-
|
|
35
|
-
### Content-free process diagnostics
|
|
36
|
-
|
|
37
|
-
`DyNTS_App` projects bootstrap failures, unhandled promise rejections, database connection/runtime failures,
|
|
38
|
-
HTTP/HTTPS server errors, routing failures and Express fallbacks through the versioned
|
|
39
|
-
`dynts-safe-diagnostic/1` contract before framework-owned logging or error forwarding. The public allowlist is
|
|
40
|
-
limited to `contractVersion`, `code`, `stage`, `causeType`, `fingerprint` and `status`. Raw error messages,
|
|
41
|
-
stacks, rejected promises, requests and database URIs are excluded. The fingerprint is derived only from the
|
|
42
|
-
allowlisted classification, never from raw failure content.
|
|
43
|
-
|
|
44
|
-
Consumers can use `DyNTS_SafeDiagnostic_ControlService.project()` when they need the same deterministic
|
|
45
|
-
projection without logging, `report()` for safe framework logging, and `toError()` when a content-free
|
|
46
|
-
`DyFM_Error` must cross an existing error-handler boundary. See
|
|
47
|
-
[`__documentations/2026-08-22-content-free-process-error-boundary.md`](./__documentations/2026-08-22-content-free-process-error-boundary.md)
|
|
48
|
-
for the normative boundary and verification matrix.
|
|
49
|
-
|
|
50
|
-
## Table of Contents
|
|
51
|
-
|
|
52
|
-
- [Installation](#installation)
|
|
53
|
-
- [Quick Start](#quick-start)
|
|
54
|
-
- [Core Concepts](#core-concepts)
|
|
55
|
-
- [Modules Overview](#modules-overview)
|
|
56
|
-
- [Usage Examples](#usage-examples)
|
|
57
|
-
- [Ecosystem Integration](#ecosystem-integration)
|
|
58
|
-
- [API Reference](#api-reference)
|
|
59
|
-
|
|
60
|
-
## Installation
|
|
61
|
-
|
|
62
|
-
Install Dynamo-NTS using pnpm (recommended) or npm:
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
pnpm add @futdevpro/dynamo-nts
|
|
66
|
-
# or
|
|
67
|
-
npm install @futdevpro/dynamo-nts
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Peer Dependencies
|
|
71
|
-
|
|
72
|
-
Dynamo-NTS requires peer dependencies that are divided into two categories: core dependencies (required for the main module) and module-specific dependencies (required only when using specific modules).
|
|
73
|
-
|
|
74
|
-
#### Core Dependencies (Required)
|
|
75
|
-
|
|
76
|
-
These dependencies are required for the main Dynamo-NTS functionality:
|
|
77
|
-
|
|
78
|
-
- [`@futdevpro/fsm-dynamo`](https://www.npmjs.com/package/@futdevpro/fsm-dynamo) - The foundational package providing core interfaces and utilities (always required)
|
|
79
|
-
- `express` - Web framework for Node.js (simplified through Dynamo-NTS parameterization)
|
|
80
|
-
- `mongoose` - MongoDB object modeling (simplified through Dynamo-NTS data services)
|
|
81
|
-
- `axios` - HTTP client (simplified through Dynamo-NTS API service)
|
|
82
|
-
- `body-parser` - Request body parsing middleware
|
|
83
|
-
- `dotenv` - Environment variable management
|
|
84
|
-
- `rxjs` - Reactive programming library
|
|
85
|
-
- `@types/express` - TypeScript types for Express
|
|
86
|
-
- `@types/node` - TypeScript types for Node.js
|
|
87
|
-
- `ts-node` - TypeScript execution environment
|
|
88
|
-
|
|
89
|
-
Install core dependencies:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
pnpm add @futdevpro/fsm-dynamo express mongoose axios body-parser dotenv rxjs @types/express @types/node ts-node
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
#### Module-Specific Dependencies (Optional)
|
|
96
|
-
|
|
97
|
-
These dependencies are only required when using specific modules:
|
|
98
|
-
|
|
99
|
-
- **Socket Module**: `socket.io` - Real-time communication (simplified through Dynamo-NTS socket services)
|
|
100
|
-
- **Email Service**: `nodemailer` - Email sending (simplified through Dynamo-NTS email services)
|
|
101
|
-
- **Usage Module**: `geoip-lite` and `@types/geoip-lite` - optional, local-only IP geolocation. The provider is loaded only when a lookup is requested. Without it, lookup methods return `null` and the rest of Dynamo-NTS remains usable. The supported secure `geoip-lite` line requires Node.js 24 or newer.
|
|
102
|
-
- **Bot Module (Discord)**: `discord.js` - Discord bot development (simplified through Dynamo-NTS bot module)
|
|
103
|
-
- **AI Module (OpenAI)**: `openai` - OpenAI API integration (simplified through Dynamo-NTS AI module)
|
|
104
|
-
|
|
105
|
-
The GeoIP lookup itself does not transmit or log an address. Calling the Usage module can persist the
|
|
106
|
-
request address and derived location in the consumer's own data store. Consumers enabling that capability
|
|
107
|
-
must define the applicable lawful basis, user-facing transparency, access controls, retention and deletion.
|
|
108
|
-
|
|
109
|
-
Install module-specific dependencies as needed:
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
# For Socket module
|
|
113
|
-
pnpm add socket.io
|
|
114
|
-
|
|
115
|
-
# For Email service
|
|
116
|
-
pnpm add nodemailer
|
|
117
|
-
|
|
118
|
-
# For Usage module
|
|
119
|
-
pnpm add geoip-lite@^2.0.3 @types/geoip-lite@^1.4.4
|
|
120
|
-
|
|
121
|
-
# For Bot module (Discord)
|
|
122
|
-
pnpm add discord.js
|
|
123
|
-
|
|
124
|
-
# For AI module (OpenAI)
|
|
125
|
-
pnpm add openai
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
## Quick Start
|
|
129
|
-
|
|
130
|
-
The following example demonstrates how to set up a basic Dynamo-NTS application with routing and socket support:
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
import {
|
|
134
|
-
DyNTS_AppExtended,
|
|
135
|
-
DyNTS_App_Params,
|
|
136
|
-
DyNTS_GlobalService_Settings,
|
|
137
|
-
DyNTS_Http_Settings,
|
|
138
|
-
DyNTS_RoutingModule
|
|
139
|
-
} from '@futdevpro/nts-dynamo';
|
|
140
|
-
import {
|
|
141
|
-
DyNTS_SocketServerService
|
|
142
|
-
} from '@futdevpro/nts-dynamo/socket';
|
|
143
|
-
import { DyFM_usageSession_dataParams } from '@futdevpro/fsm-dynamo/usage';
|
|
144
|
-
import { DyFM_customData_dataParams } from '@futdevpro/fsm-dynamo/custom-data';
|
|
145
|
-
import { DyNTS_getUsageRoutingModule } from '@futdevpro/nts-dynamo/usage';
|
|
146
|
-
import { DyNTS_getTestRoutingModule } from '@futdevpro/nts-dynamo/test';
|
|
147
|
-
|
|
148
|
-
import { AuthService } from './core-services/auth.service';
|
|
149
|
-
import { Email_ServiceCollection } from './core-services/email.service-collection';
|
|
150
|
-
import { User_Controller } from './routes/user/user.controller';
|
|
151
|
-
import { Chat_SocketServerService } from './socket-services/chat.socket-server-service';
|
|
152
|
-
|
|
153
|
-
export class App extends DyNTS_AppExtended {
|
|
154
|
-
|
|
155
|
-
getAppParams(): DyNTS_App_Params {
|
|
156
|
-
return new DyNTS_App_Params({
|
|
157
|
-
name: 'My Application',
|
|
158
|
-
version: '1.0.0',
|
|
159
|
-
dbName: 'myapp',
|
|
160
|
-
dbUri: process.env.MONGO_URL || 'mongodb://localhost:27017/myapp',
|
|
161
|
-
systemShortCodeName: 'MYAPP',
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
getGlobalServiceCollection(): DyNTS_GlobalService_Settings {
|
|
166
|
-
return {
|
|
167
|
-
authService: AuthService.getInstance(),
|
|
168
|
-
emailServiceCollection: Email_ServiceCollection.getInstance(),
|
|
169
|
-
dbModels: [
|
|
170
|
-
// Your data model parameters here
|
|
171
|
-
DyFM_usageSession_dataParams,
|
|
172
|
-
DyFM_customData_dataParams,
|
|
173
|
-
],
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
getPortSettings(): DyNTS_Http_Settings {
|
|
178
|
-
return new DyNTS_Http_Settings({
|
|
179
|
-
httpPort: 3000,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
getRoutingModules(): DyNTS_RoutingModule[] {
|
|
184
|
-
return [
|
|
185
|
-
new DyNTS_RoutingModule({
|
|
186
|
-
route: '/user',
|
|
187
|
-
controllers: [
|
|
188
|
-
User_Controller.getInstance(),
|
|
189
|
-
],
|
|
190
|
-
}),
|
|
191
|
-
DyNTS_getTestRoutingModule(),
|
|
192
|
-
DyNTS_getUsageRoutingModule(),
|
|
193
|
-
];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
getSocketServices(): DyNTS_SocketServerService<any>[] {
|
|
197
|
-
return [
|
|
198
|
-
Chat_SocketServerService.getInstance(),
|
|
199
|
-
];
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Start the application
|
|
204
|
-
const app = new App();
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
## Core Concepts
|
|
208
|
-
|
|
209
|
-
Dynamo-NTS uses [Dynamo FSM](https://www.npmjs.com/package/@futdevpro/fsm-dynamo) as its foundation, implementing all server-side components defined in the FSM architecture. All types, interfaces, and base models are provided by FSM, ensuring full type safety and consistency.
|
|
210
|
-
|
|
211
|
-
### Extensibility and Customization
|
|
212
|
-
|
|
213
|
-
Dynamo-NTS is designed with extensibility in mind. Every component, service, and class can be overridden or extended to meet your specific requirements:
|
|
214
|
-
|
|
215
|
-
- **Service Override**: All services (authentication, email, data services, etc.) can be extended or completely replaced with custom implementations
|
|
216
|
-
- **Method Override**: Abstract methods in base classes allow you to customize behavior while maintaining the framework structure
|
|
217
|
-
- **Configuration Override**: Global settings, route security, and application parameters can be overridden at any level
|
|
218
|
-
- **Type Safety**: All overrides maintain full TypeScript type safety, with all types and interfaces available at compile time
|
|
219
|
-
|
|
220
|
-
This design philosophy ensures that Dynamo-NTS provides a solid foundation while remaining fully customizable for your specific use cases.
|
|
221
|
-
|
|
222
|
-
### Complete Type Information
|
|
223
|
-
|
|
224
|
-
All types, interfaces, and definitions are included in the compiled output, ensuring excellent readability and maintainability. When you compile your project, you have access to:
|
|
225
|
-
|
|
226
|
-
- Complete type definitions for all services, models, and interfaces
|
|
227
|
-
- Full IntelliSense support in your IDE
|
|
228
|
-
- Compile-time type checking for all framework components
|
|
229
|
-
- Self-documenting code through TypeScript's type system
|
|
230
|
-
|
|
231
|
-
This approach eliminates the need to reference external documentation during development—everything you need is available in your IDE's autocomplete and type hints.
|
|
232
|
-
|
|
233
|
-
### Application Classes
|
|
234
|
-
|
|
235
|
-
Dynamo-NTS provides two main application base classes that simplify Express server setup:
|
|
236
|
-
|
|
237
|
-
- **`DyNTS_App`**: Basic application class for standard HTTP server applications without real-time socket support
|
|
238
|
-
- **`DyNTS_AppExtended`**: Extended application class that includes built-in socket server capabilities for real-time communication (simplifies Socket.io setup)
|
|
239
|
-
|
|
240
|
-
Both classes abstract away Express server configuration, requiring you to implement several abstract methods with simple parameter objects:
|
|
241
|
-
|
|
242
|
-
- `getAppParams()`: Define application parameters (name, version, database name, etc.) - replaces Express app initialization
|
|
243
|
-
- `getGlobalServiceCollection()`: Configure global services (authentication, email, database models) - replaces manual service registration
|
|
244
|
-
- `getPortSettings()`: Configure HTTP/HTTPS ports - replaces Express server.listen() configuration
|
|
245
|
-
- `getRoutingModules()`: Define API routes and controllers - replaces Express router setup
|
|
246
|
-
|
|
247
|
-
### Data Services
|
|
248
|
-
|
|
249
|
-
Data services provide a structured way to interact with MongoDB, simplifying Mongoose model and schema definitions:
|
|
250
|
-
|
|
251
|
-
- **`DyNTS_DBService<T>`**: Low-level MongoDB service for direct database operations (simplifies Mongoose model creation)
|
|
252
|
-
- **`DyNTS_DataService<T>`**: High-level data service with business logic, validation, and dependency management (simplifies MongoDB CRUD operations)
|
|
253
|
-
- **`DyNTS_ArchiveDataService<T>`**: Service for managing archived data in separate collections
|
|
254
|
-
|
|
255
|
-
Instead of manually creating Mongoose schemas and models, you define data models through `DyFM_DataModel_Params` (from FSM), and Dynamo-NTS handles schema generation, model creation, and connection management automatically. Data services handle CRUD operations, data validation, dependency tracking, and provide methods for searching, filtering, and managing data relationships.
|
|
256
|
-
|
|
257
|
-
### Atomic MongoDB transactions
|
|
258
|
-
|
|
259
|
-
`DyNTS_MongoTransaction_ControlService` is the shared Bedrock entry point for business operations that must
|
|
260
|
-
commit several MongoDB writes as one unit. The callback receives the same Mongoose `ClientSession` that must
|
|
261
|
-
be attached to every participating query or write:
|
|
262
|
-
|
|
263
|
-
```typescript
|
|
264
|
-
import { ClientSession } from 'mongoose';
|
|
265
|
-
|
|
266
|
-
import { DyNTS_MongoTransaction_ControlService } from '@futdevpro/nts-dynamo';
|
|
267
|
-
|
|
268
|
-
const transactionService: DyNTS_MongoTransaction_ControlService =
|
|
269
|
-
DyNTS_MongoTransaction_ControlService.getInstance();
|
|
270
|
-
|
|
271
|
-
const pipelineId: string = await transactionService.execute<string>({
|
|
272
|
-
transactionName: 'publish-pipeline-version',
|
|
273
|
-
issuer: 'pipeline-persistence-service',
|
|
274
|
-
maxCommitTimeMs: 3_000,
|
|
275
|
-
task: async (session: ClientSession): Promise<string> => {
|
|
276
|
-
// Every MongoDB operation in this callback must use `session`.
|
|
277
|
-
// Example: await model.updateOne(filter, update, { session: session });
|
|
278
|
-
// Example: await auditModel.create([ event ], { session: session });
|
|
279
|
-
return 'pipeline-id';
|
|
280
|
-
},
|
|
281
|
-
});
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
The service uses snapshot reads, majority writes and primary routing, always closes the session, and emits
|
|
285
|
-
stable content-free error codes. MongoDB transactions require a replica set or sharded deployment; a standalone
|
|
286
|
-
MongoDB instance is intentionally not treated as transaction-capable. Mongoose may retry the callback after a
|
|
287
|
-
transient transaction error, so the callback must not perform non-transactional side effects such as sending
|
|
288
|
-
messages or mutating external systems.
|
|
289
|
-
|
|
290
|
-
### Routing System
|
|
291
|
-
|
|
292
|
-
The routing system provides a structured approach to defining RESTful API endpoints, simplifying Express router configuration:
|
|
293
|
-
|
|
294
|
-
- **`DyNTS_RoutingModule`**: Groups related controllers under a common route path (replaces Express Router setup)
|
|
295
|
-
- **`DyNTS_Controller`**: Abstract base class for defining HTTP endpoints (simplifies Express route handlers)
|
|
296
|
-
- **`DyNTS_Endpoint_Params`**: Configuration for individual API endpoints (replaces Express route definitions)
|
|
297
|
-
|
|
298
|
-
Instead of manually setting up Express routers and route handlers, you define endpoints through parameter objects. Controllers define endpoints with support for:
|
|
299
|
-
- Multiple HTTP methods (GET, POST, PUT, PATCH, DELETE)
|
|
300
|
-
- Pre-processing middleware (authentication, validation)
|
|
301
|
-
- Task functions for handling requests
|
|
302
|
-
- Route security levels (open, secure, both)
|
|
303
|
-
|
|
304
|
-
### Global Services
|
|
305
|
-
|
|
306
|
-
The `DyNTS_GlobalService` provides centralized access to:
|
|
307
|
-
|
|
308
|
-
- Authentication service
|
|
309
|
-
- Email service collection
|
|
310
|
-
- Database models registry
|
|
311
|
-
- Error handlers
|
|
312
|
-
- Socket server instances
|
|
313
|
-
|
|
314
|
-
### Authentication
|
|
315
|
-
|
|
316
|
-
Dynamo-NTS provides an abstract `DyNTS_AuthService` class that you can extend to implement your authentication logic. The framework supports:
|
|
317
|
-
|
|
318
|
-
- Token-based authentication
|
|
319
|
-
- OAuth2 flows (via the OAuth2 module)
|
|
320
|
-
- Session management
|
|
321
|
-
- Route-level security configuration
|
|
322
|
-
|
|
323
|
-
For product-local accounts, the optional `@futdevpro/nts-dynamo/account-security` entry point adds production
|
|
324
|
-
security primitives without coupling a product to a shared account provider:
|
|
325
|
-
|
|
326
|
-
- versioned adaptive password hashing and rehash detection;
|
|
327
|
-
- hash-only email-verification and password-reset challenges with atomic one-time consumption;
|
|
328
|
-
- opaque, hash-only access credentials backed by revocable server-side sessions;
|
|
329
|
-
- one-time refresh rotation, replay detection, session listing and subject-wide revocation.
|
|
330
|
-
|
|
331
|
-
Persistence remains application-owned through explicit atomic adapters. Transports must never put the raw
|
|
332
|
-
credentials in URLs, logs, analytics or durable client storage. A consuming application must also apply its
|
|
333
|
-
rate-limit, authorization, cookie/storage and audit-redaction policy at the API boundary.
|
|
334
|
-
|
|
335
|
-
### Distributed rate limiting
|
|
336
|
-
|
|
337
|
-
The `@futdevpro/nts-dynamo/rate-limit` entry point provides an atomic rate-limit boundary for HTTP services:
|
|
338
|
-
|
|
339
|
-
- an exact sliding-window in-memory store for deterministic tests and explicitly single-instance development;
|
|
340
|
-
- an application-owned shared-store contract for production deployments;
|
|
341
|
-
- a production configuration gate that requires both shared persistence and explicit opaque subject/endpoint
|
|
342
|
-
extractors;
|
|
343
|
-
- validated positive limits, windows and weighted request costs with stable, content-free failures;
|
|
344
|
-
- trusted `req.ip` as the safe local default instead of reading caller-controlled forwarding headers directly;
|
|
345
|
-
- explicit opportunistic local cleanup with no timer, polling loop or hidden background task.
|
|
346
|
-
|
|
347
|
-
Production consumers must implement the shared store with one atomic permit decision across every application
|
|
348
|
-
instance. They must derive non-sensitive, purpose-scoped bucket identifiers and must not persist or log raw IP
|
|
349
|
-
addresses, credentials, email addresses or other request content as rate-limit keys.
|
|
350
|
-
|
|
351
|
-
###
|
|
352
|
-
|
|
353
|
-
The optional `@futdevpro/nts-dynamo/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
The
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
- **
|
|
385
|
-
- **
|
|
386
|
-
- **
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
-
|
|
397
|
-
|
|
398
|
-
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
-
|
|
407
|
-
-
|
|
408
|
-
-
|
|
409
|
-
-
|
|
410
|
-
|
|
411
|
-
###
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
-
|
|
416
|
-
-
|
|
417
|
-
-
|
|
418
|
-
-
|
|
419
|
-
-
|
|
420
|
-
|
|
421
|
-
###
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
-
|
|
426
|
-
-
|
|
427
|
-
-
|
|
428
|
-
-
|
|
429
|
-
-
|
|
430
|
-
|
|
431
|
-
###
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
-
|
|
436
|
-
-
|
|
437
|
-
-
|
|
438
|
-
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
-
|
|
446
|
-
-
|
|
447
|
-
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
-
|
|
490
|
-
-
|
|
491
|
-
-
|
|
492
|
-
-
|
|
493
|
-
|
|
494
|
-
###
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
-
|
|
499
|
-
-
|
|
500
|
-
-
|
|
501
|
-
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
-
|
|
509
|
-
-
|
|
510
|
-
-
|
|
511
|
-
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
-
|
|
754
|
-
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
-
|
|
765
|
-
-
|
|
766
|
-
-
|
|
767
|
-
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
-
|
|
775
|
-
-
|
|
776
|
-
-
|
|
777
|
-
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
-
|
|
791
|
-
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
1
|
+
# Dynamo-NTS
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
**Dynamo-NTS** (NodeTS) is a comprehensive backend framework for building robust, secure, and scalable Node.js applications with TypeScript. Built on top of [Dynamo FSM](https://www.npmjs.com/package/@futdevpro/fsm-dynamo) (`@futdevpro/fsm-dynamo`), it provides a structured approach to server-side development with clear separation of concerns, extensive configuration options, and production-ready implementations for common backend tasks.
|
|
6
|
+
|
|
7
|
+
Dynamo-NTS uses **[Dynamo FSM](https://www.npmjs.com/package/@futdevpro/fsm-dynamo)** as its foundational layer, implementing the server-side components of the FSM architecture. All core interfaces, types, and utilities are provided by FSM, ensuring consistency and type safety across the entire Dynamo ecosystem.
|
|
8
|
+
|
|
9
|
+
Dynamo-NTS is part of the unified **Dynamo ecosystem**, a full-stack development framework designed to accelerate the development of scalable web applications. The ecosystem consists of interconnected packages that work together seamlessly, with Dynamo-NTS serving as the backend implementation layer. The frontend counterpart is **[Dynamo NGX](https://www.npmjs.com/package/@futdevpro/ngx-dynamo)**, which uses **[Dynamo NGX Models](https://www.npmjs.com/package/@futdevpro/ngx-dynamo-models)** for type-safe model definitions.
|
|
10
|
+
|
|
11
|
+
### Design Philosophy
|
|
12
|
+
|
|
13
|
+
Dynamo-NTS is built with two key principles:
|
|
14
|
+
|
|
15
|
+
- **Full Override Capability**: Every component, service, and class can be overridden or extended. The framework provides a solid foundation with sensible defaults, but you have complete control to customize or replace any part to fit your specific needs. This makes Dynamo-NTS highly customizable and adaptable to any project requirements.
|
|
16
|
+
|
|
17
|
+
- **Complete Type Information**: All types, interfaces, and definitions are included in the compiled output. This ensures excellent readability and maintainability—everything you need is available at compile time through TypeScript's type system, providing full IntelliSense support and eliminating the need to reference external documentation during development.
|
|
18
|
+
|
|
19
|
+
### Simplified System Definitions
|
|
20
|
+
|
|
21
|
+
Dynamo-NTS simplifies complex system definitions by abstracting common backend infrastructure into simple parameterization. Instead of manually configuring various libraries and services, you define your application through straightforward parameter objects:
|
|
22
|
+
|
|
23
|
+
- **Express Usage**: HTTP/HTTPS server setup, routing, middleware, and error handling are configured through `DyNTS_App_Params`, `DyNTS_Http_Settings`, and `DyNTS_RoutingModule` parameters (simplifies Express server initialization and route management)
|
|
24
|
+
- **MongoDB/Mongoose Usage**: Database connections, models, schemas, and operations are managed through `DyNTS_DBService` and `DyNTS_DataService` with simple data model parameter definitions (simplifies Mongoose schema creation and model management)
|
|
25
|
+
- **Socket.io Usage**: Real-time communication setup, event handling, and presence tracking are configured through `DyNTS_SocketServerService` parameters and the `DyNTS_AppExtended` class (simplifies Socket.io server initialization and event management)
|
|
26
|
+
- **Nodemailer Usage**: Email sending with templating, attachments, and async delivery is handled through `DyNTS_EmailService` with template component definitions (simplifies Nodemailer transporter setup and email template management)
|
|
27
|
+
- **OAuth2 Implementation**: Complete OAuth2.0 protocol flows including authorization codes, token exchange, and refresh tokens are managed through `DyNTS_OAuth2_Controller` and `DyNTS_OAuth2_AuthService` (simplifies complex OAuth2 flow implementation)
|
|
28
|
+
- **Axios Usage**: HTTP client requests to external APIs are standardized through `DyNTS_ApiService` with `DyNTS_ApiCall_Params` configuration (simplifies Axios request setup, error handling, and response management)
|
|
29
|
+
- **Discord.js / Slack / Teams Bot Development**: Platform-agnostic bot framework through `DyNTS_Bot_MessagingProvider_ServiceBase` and bot modules (simplifies Discord.js, Slack, and Teams bot development with unified interfaces)
|
|
30
|
+
- **OpenAI / AI Provider Integration**: AI/LLM operations including chat, embeddings, and vector search are abstracted through `DyNTS_AI_Provider_ServiceBase` and provider implementations (simplifies OpenAI SDK usage and enables multi-provider architecture)
|
|
31
|
+
- **Location Tracking**: Optional, local-only IP geolocation through `geoip-lite`; addresses are not sent to an external service or written to logs by Dynamo-NTS
|
|
32
|
+
|
|
33
|
+
This parameterization approach eliminates boilerplate code and provides a consistent, type-safe interface for all backend operations. Instead of learning multiple library APIs and their configuration patterns, developers work with unified Dynamo-NTS parameter objects that handle the underlying complexity.
|
|
34
|
+
|
|
35
|
+
### Content-free process diagnostics
|
|
36
|
+
|
|
37
|
+
`DyNTS_App` projects bootstrap failures, unhandled promise rejections, database connection/runtime failures,
|
|
38
|
+
HTTP/HTTPS server errors, routing failures and Express fallbacks through the versioned
|
|
39
|
+
`dynts-safe-diagnostic/1` contract before framework-owned logging or error forwarding. The public allowlist is
|
|
40
|
+
limited to `contractVersion`, `code`, `stage`, `causeType`, `fingerprint` and `status`. Raw error messages,
|
|
41
|
+
stacks, rejected promises, requests and database URIs are excluded. The fingerprint is derived only from the
|
|
42
|
+
allowlisted classification, never from raw failure content.
|
|
43
|
+
|
|
44
|
+
Consumers can use `DyNTS_SafeDiagnostic_ControlService.project()` when they need the same deterministic
|
|
45
|
+
projection without logging, `report()` for safe framework logging, and `toError()` when a content-free
|
|
46
|
+
`DyFM_Error` must cross an existing error-handler boundary. See
|
|
47
|
+
[`__documentations/2026-08-22-content-free-process-error-boundary.md`](./__documentations/2026-08-22-content-free-process-error-boundary.md)
|
|
48
|
+
for the normative boundary and verification matrix.
|
|
49
|
+
|
|
50
|
+
## Table of Contents
|
|
51
|
+
|
|
52
|
+
- [Installation](#installation)
|
|
53
|
+
- [Quick Start](#quick-start)
|
|
54
|
+
- [Core Concepts](#core-concepts)
|
|
55
|
+
- [Modules Overview](#modules-overview)
|
|
56
|
+
- [Usage Examples](#usage-examples)
|
|
57
|
+
- [Ecosystem Integration](#ecosystem-integration)
|
|
58
|
+
- [API Reference](#api-reference)
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
Install Dynamo-NTS using pnpm (recommended) or npm:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm add @futdevpro/dynamo-nts
|
|
66
|
+
# or
|
|
67
|
+
npm install @futdevpro/dynamo-nts
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Peer Dependencies
|
|
71
|
+
|
|
72
|
+
Dynamo-NTS requires peer dependencies that are divided into two categories: core dependencies (required for the main module) and module-specific dependencies (required only when using specific modules).
|
|
73
|
+
|
|
74
|
+
#### Core Dependencies (Required)
|
|
75
|
+
|
|
76
|
+
These dependencies are required for the main Dynamo-NTS functionality:
|
|
77
|
+
|
|
78
|
+
- [`@futdevpro/fsm-dynamo`](https://www.npmjs.com/package/@futdevpro/fsm-dynamo) - The foundational package providing core interfaces and utilities (always required)
|
|
79
|
+
- `express` - Web framework for Node.js (simplified through Dynamo-NTS parameterization)
|
|
80
|
+
- `mongoose` - MongoDB object modeling (simplified through Dynamo-NTS data services)
|
|
81
|
+
- `axios` - HTTP client (simplified through Dynamo-NTS API service)
|
|
82
|
+
- `body-parser` - Request body parsing middleware
|
|
83
|
+
- `dotenv` - Environment variable management
|
|
84
|
+
- `rxjs` - Reactive programming library
|
|
85
|
+
- `@types/express` - TypeScript types for Express
|
|
86
|
+
- `@types/node` - TypeScript types for Node.js
|
|
87
|
+
- `ts-node` - TypeScript execution environment
|
|
88
|
+
|
|
89
|
+
Install core dependencies:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pnpm add @futdevpro/fsm-dynamo express mongoose axios body-parser dotenv rxjs @types/express @types/node ts-node
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Module-Specific Dependencies (Optional)
|
|
96
|
+
|
|
97
|
+
These dependencies are only required when using specific modules:
|
|
98
|
+
|
|
99
|
+
- **Socket Module**: `socket.io` - Real-time communication (simplified through Dynamo-NTS socket services)
|
|
100
|
+
- **Email Service**: `nodemailer` - Email sending (simplified through Dynamo-NTS email services)
|
|
101
|
+
- **Usage Module**: `geoip-lite` and `@types/geoip-lite` - optional, local-only IP geolocation. The provider is loaded only when a lookup is requested. Without it, lookup methods return `null` and the rest of Dynamo-NTS remains usable. The supported secure `geoip-lite` line requires Node.js 24 or newer.
|
|
102
|
+
- **Bot Module (Discord)**: `discord.js` - Discord bot development (simplified through Dynamo-NTS bot module)
|
|
103
|
+
- **AI Module (OpenAI)**: `openai` - OpenAI API integration (simplified through Dynamo-NTS AI module)
|
|
104
|
+
|
|
105
|
+
The GeoIP lookup itself does not transmit or log an address. Calling the Usage module can persist the
|
|
106
|
+
request address and derived location in the consumer's own data store. Consumers enabling that capability
|
|
107
|
+
must define the applicable lawful basis, user-facing transparency, access controls, retention and deletion.
|
|
108
|
+
|
|
109
|
+
Install module-specific dependencies as needed:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# For Socket module
|
|
113
|
+
pnpm add socket.io
|
|
114
|
+
|
|
115
|
+
# For Email service
|
|
116
|
+
pnpm add nodemailer
|
|
117
|
+
|
|
118
|
+
# For Usage module
|
|
119
|
+
pnpm add geoip-lite@^2.0.3 @types/geoip-lite@^1.4.4
|
|
120
|
+
|
|
121
|
+
# For Bot module (Discord)
|
|
122
|
+
pnpm add discord.js
|
|
123
|
+
|
|
124
|
+
# For AI module (OpenAI)
|
|
125
|
+
pnpm add openai
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Quick Start
|
|
129
|
+
|
|
130
|
+
The following example demonstrates how to set up a basic Dynamo-NTS application with routing and socket support:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import {
|
|
134
|
+
DyNTS_AppExtended,
|
|
135
|
+
DyNTS_App_Params,
|
|
136
|
+
DyNTS_GlobalService_Settings,
|
|
137
|
+
DyNTS_Http_Settings,
|
|
138
|
+
DyNTS_RoutingModule
|
|
139
|
+
} from '@futdevpro/nts-dynamo';
|
|
140
|
+
import {
|
|
141
|
+
DyNTS_SocketServerService
|
|
142
|
+
} from '@futdevpro/nts-dynamo/socket';
|
|
143
|
+
import { DyFM_usageSession_dataParams } from '@futdevpro/fsm-dynamo/usage';
|
|
144
|
+
import { DyFM_customData_dataParams } from '@futdevpro/fsm-dynamo/custom-data';
|
|
145
|
+
import { DyNTS_getUsageRoutingModule } from '@futdevpro/nts-dynamo/usage';
|
|
146
|
+
import { DyNTS_getTestRoutingModule } from '@futdevpro/nts-dynamo/test';
|
|
147
|
+
|
|
148
|
+
import { AuthService } from './core-services/auth.service';
|
|
149
|
+
import { Email_ServiceCollection } from './core-services/email.service-collection';
|
|
150
|
+
import { User_Controller } from './routes/user/user.controller';
|
|
151
|
+
import { Chat_SocketServerService } from './socket-services/chat.socket-server-service';
|
|
152
|
+
|
|
153
|
+
export class App extends DyNTS_AppExtended {
|
|
154
|
+
|
|
155
|
+
getAppParams(): DyNTS_App_Params {
|
|
156
|
+
return new DyNTS_App_Params({
|
|
157
|
+
name: 'My Application',
|
|
158
|
+
version: '1.0.0',
|
|
159
|
+
dbName: 'myapp',
|
|
160
|
+
dbUri: process.env.MONGO_URL || 'mongodb://localhost:27017/myapp',
|
|
161
|
+
systemShortCodeName: 'MYAPP',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
getGlobalServiceCollection(): DyNTS_GlobalService_Settings {
|
|
166
|
+
return {
|
|
167
|
+
authService: AuthService.getInstance(),
|
|
168
|
+
emailServiceCollection: Email_ServiceCollection.getInstance(),
|
|
169
|
+
dbModels: [
|
|
170
|
+
// Your data model parameters here
|
|
171
|
+
DyFM_usageSession_dataParams,
|
|
172
|
+
DyFM_customData_dataParams,
|
|
173
|
+
],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
getPortSettings(): DyNTS_Http_Settings {
|
|
178
|
+
return new DyNTS_Http_Settings({
|
|
179
|
+
httpPort: 3000,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
getRoutingModules(): DyNTS_RoutingModule[] {
|
|
184
|
+
return [
|
|
185
|
+
new DyNTS_RoutingModule({
|
|
186
|
+
route: '/user',
|
|
187
|
+
controllers: [
|
|
188
|
+
User_Controller.getInstance(),
|
|
189
|
+
],
|
|
190
|
+
}),
|
|
191
|
+
DyNTS_getTestRoutingModule(),
|
|
192
|
+
DyNTS_getUsageRoutingModule(),
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
getSocketServices(): DyNTS_SocketServerService<any>[] {
|
|
197
|
+
return [
|
|
198
|
+
Chat_SocketServerService.getInstance(),
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Start the application
|
|
204
|
+
const app = new App();
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Core Concepts
|
|
208
|
+
|
|
209
|
+
Dynamo-NTS uses [Dynamo FSM](https://www.npmjs.com/package/@futdevpro/fsm-dynamo) as its foundation, implementing all server-side components defined in the FSM architecture. All types, interfaces, and base models are provided by FSM, ensuring full type safety and consistency.
|
|
210
|
+
|
|
211
|
+
### Extensibility and Customization
|
|
212
|
+
|
|
213
|
+
Dynamo-NTS is designed with extensibility in mind. Every component, service, and class can be overridden or extended to meet your specific requirements:
|
|
214
|
+
|
|
215
|
+
- **Service Override**: All services (authentication, email, data services, etc.) can be extended or completely replaced with custom implementations
|
|
216
|
+
- **Method Override**: Abstract methods in base classes allow you to customize behavior while maintaining the framework structure
|
|
217
|
+
- **Configuration Override**: Global settings, route security, and application parameters can be overridden at any level
|
|
218
|
+
- **Type Safety**: All overrides maintain full TypeScript type safety, with all types and interfaces available at compile time
|
|
219
|
+
|
|
220
|
+
This design philosophy ensures that Dynamo-NTS provides a solid foundation while remaining fully customizable for your specific use cases.
|
|
221
|
+
|
|
222
|
+
### Complete Type Information
|
|
223
|
+
|
|
224
|
+
All types, interfaces, and definitions are included in the compiled output, ensuring excellent readability and maintainability. When you compile your project, you have access to:
|
|
225
|
+
|
|
226
|
+
- Complete type definitions for all services, models, and interfaces
|
|
227
|
+
- Full IntelliSense support in your IDE
|
|
228
|
+
- Compile-time type checking for all framework components
|
|
229
|
+
- Self-documenting code through TypeScript's type system
|
|
230
|
+
|
|
231
|
+
This approach eliminates the need to reference external documentation during development—everything you need is available in your IDE's autocomplete and type hints.
|
|
232
|
+
|
|
233
|
+
### Application Classes
|
|
234
|
+
|
|
235
|
+
Dynamo-NTS provides two main application base classes that simplify Express server setup:
|
|
236
|
+
|
|
237
|
+
- **`DyNTS_App`**: Basic application class for standard HTTP server applications without real-time socket support
|
|
238
|
+
- **`DyNTS_AppExtended`**: Extended application class that includes built-in socket server capabilities for real-time communication (simplifies Socket.io setup)
|
|
239
|
+
|
|
240
|
+
Both classes abstract away Express server configuration, requiring you to implement several abstract methods with simple parameter objects:
|
|
241
|
+
|
|
242
|
+
- `getAppParams()`: Define application parameters (name, version, database name, etc.) - replaces Express app initialization
|
|
243
|
+
- `getGlobalServiceCollection()`: Configure global services (authentication, email, database models) - replaces manual service registration
|
|
244
|
+
- `getPortSettings()`: Configure HTTP/HTTPS ports - replaces Express server.listen() configuration
|
|
245
|
+
- `getRoutingModules()`: Define API routes and controllers - replaces Express router setup
|
|
246
|
+
|
|
247
|
+
### Data Services
|
|
248
|
+
|
|
249
|
+
Data services provide a structured way to interact with MongoDB, simplifying Mongoose model and schema definitions:
|
|
250
|
+
|
|
251
|
+
- **`DyNTS_DBService<T>`**: Low-level MongoDB service for direct database operations (simplifies Mongoose model creation)
|
|
252
|
+
- **`DyNTS_DataService<T>`**: High-level data service with business logic, validation, and dependency management (simplifies MongoDB CRUD operations)
|
|
253
|
+
- **`DyNTS_ArchiveDataService<T>`**: Service for managing archived data in separate collections
|
|
254
|
+
|
|
255
|
+
Instead of manually creating Mongoose schemas and models, you define data models through `DyFM_DataModel_Params` (from FSM), and Dynamo-NTS handles schema generation, model creation, and connection management automatically. Data services handle CRUD operations, data validation, dependency tracking, and provide methods for searching, filtering, and managing data relationships.
|
|
256
|
+
|
|
257
|
+
### Atomic MongoDB transactions
|
|
258
|
+
|
|
259
|
+
`DyNTS_MongoTransaction_ControlService` is the shared Bedrock entry point for business operations that must
|
|
260
|
+
commit several MongoDB writes as one unit. The callback receives the same Mongoose `ClientSession` that must
|
|
261
|
+
be attached to every participating query or write:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { ClientSession } from 'mongoose';
|
|
265
|
+
|
|
266
|
+
import { DyNTS_MongoTransaction_ControlService } from '@futdevpro/nts-dynamo';
|
|
267
|
+
|
|
268
|
+
const transactionService: DyNTS_MongoTransaction_ControlService =
|
|
269
|
+
DyNTS_MongoTransaction_ControlService.getInstance();
|
|
270
|
+
|
|
271
|
+
const pipelineId: string = await transactionService.execute<string>({
|
|
272
|
+
transactionName: 'publish-pipeline-version',
|
|
273
|
+
issuer: 'pipeline-persistence-service',
|
|
274
|
+
maxCommitTimeMs: 3_000,
|
|
275
|
+
task: async (session: ClientSession): Promise<string> => {
|
|
276
|
+
// Every MongoDB operation in this callback must use `session`.
|
|
277
|
+
// Example: await model.updateOne(filter, update, { session: session });
|
|
278
|
+
// Example: await auditModel.create([ event ], { session: session });
|
|
279
|
+
return 'pipeline-id';
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
The service uses snapshot reads, majority writes and primary routing, always closes the session, and emits
|
|
285
|
+
stable content-free error codes. MongoDB transactions require a replica set or sharded deployment; a standalone
|
|
286
|
+
MongoDB instance is intentionally not treated as transaction-capable. Mongoose may retry the callback after a
|
|
287
|
+
transient transaction error, so the callback must not perform non-transactional side effects such as sending
|
|
288
|
+
messages or mutating external systems.
|
|
289
|
+
|
|
290
|
+
### Routing System
|
|
291
|
+
|
|
292
|
+
The routing system provides a structured approach to defining RESTful API endpoints, simplifying Express router configuration:
|
|
293
|
+
|
|
294
|
+
- **`DyNTS_RoutingModule`**: Groups related controllers under a common route path (replaces Express Router setup)
|
|
295
|
+
- **`DyNTS_Controller`**: Abstract base class for defining HTTP endpoints (simplifies Express route handlers)
|
|
296
|
+
- **`DyNTS_Endpoint_Params`**: Configuration for individual API endpoints (replaces Express route definitions)
|
|
297
|
+
|
|
298
|
+
Instead of manually setting up Express routers and route handlers, you define endpoints through parameter objects. Controllers define endpoints with support for:
|
|
299
|
+
- Multiple HTTP methods (GET, POST, PUT, PATCH, DELETE)
|
|
300
|
+
- Pre-processing middleware (authentication, validation)
|
|
301
|
+
- Task functions for handling requests
|
|
302
|
+
- Route security levels (open, secure, both)
|
|
303
|
+
|
|
304
|
+
### Global Services
|
|
305
|
+
|
|
306
|
+
The `DyNTS_GlobalService` provides centralized access to:
|
|
307
|
+
|
|
308
|
+
- Authentication service
|
|
309
|
+
- Email service collection
|
|
310
|
+
- Database models registry
|
|
311
|
+
- Error handlers
|
|
312
|
+
- Socket server instances
|
|
313
|
+
|
|
314
|
+
### Authentication
|
|
315
|
+
|
|
316
|
+
Dynamo-NTS provides an abstract `DyNTS_AuthService` class that you can extend to implement your authentication logic. The framework supports:
|
|
317
|
+
|
|
318
|
+
- Token-based authentication
|
|
319
|
+
- OAuth2 flows (via the OAuth2 module)
|
|
320
|
+
- Session management
|
|
321
|
+
- Route-level security configuration
|
|
322
|
+
|
|
323
|
+
For product-local accounts, the optional `@futdevpro/nts-dynamo/account-security` entry point adds production
|
|
324
|
+
security primitives without coupling a product to a shared account provider:
|
|
325
|
+
|
|
326
|
+
- versioned adaptive password hashing and rehash detection;
|
|
327
|
+
- hash-only email-verification and password-reset challenges with atomic one-time consumption;
|
|
328
|
+
- opaque, hash-only access credentials backed by revocable server-side sessions;
|
|
329
|
+
- one-time refresh rotation, replay detection, session listing and subject-wide revocation.
|
|
330
|
+
|
|
331
|
+
Persistence remains application-owned through explicit atomic adapters. Transports must never put the raw
|
|
332
|
+
credentials in URLs, logs, analytics or durable client storage. A consuming application must also apply its
|
|
333
|
+
rate-limit, authorization, cookie/storage and audit-redaction policy at the API boundary.
|
|
334
|
+
|
|
335
|
+
### Distributed rate limiting
|
|
336
|
+
|
|
337
|
+
The `@futdevpro/nts-dynamo/rate-limit` entry point provides an atomic rate-limit boundary for HTTP services:
|
|
338
|
+
|
|
339
|
+
- an exact sliding-window in-memory store for deterministic tests and explicitly single-instance development;
|
|
340
|
+
- an application-owned shared-store contract for production deployments;
|
|
341
|
+
- a production configuration gate that requires both shared persistence and explicit opaque subject/endpoint
|
|
342
|
+
extractors;
|
|
343
|
+
- validated positive limits, windows and weighted request costs with stable, content-free failures;
|
|
344
|
+
- trusted `req.ip` as the safe local default instead of reading caller-controlled forwarding headers directly;
|
|
345
|
+
- explicit opportunistic local cleanup with no timer, polling loop or hidden background task.
|
|
346
|
+
|
|
347
|
+
Production consumers must implement the shared store with one atomic permit decision across every application
|
|
348
|
+
instance. They must derive non-sensitive, purpose-scoped bucket identifiers and must not persist or log raw IP
|
|
349
|
+
addresses, credentials, email addresses or other request content as rate-limit keys.
|
|
350
|
+
|
|
351
|
+
### Namespace-bound keyset pagination
|
|
352
|
+
|
|
353
|
+
The optional `@futdevpro/nts-dynamo/pagination` entry point provides a strict keyset cursor codec for bounded
|
|
354
|
+
API listings. A codec instance binds every cursor to one declared namespace and an exact tuple dimension count,
|
|
355
|
+
uses canonical unpadded base64url, rejects expanded or reordered payloads, and returns defensive tuple copies.
|
|
356
|
+
|
|
357
|
+
The cursor is an integrity and routing boundary, not encryption. Consumers must put only non-sensitive ordering
|
|
358
|
+
values such as canonical timestamps and opaque resource identifiers into the tuple. Tenant, account, email,
|
|
359
|
+
authorization or business-content fields must remain server-derived and outside the cursor payload.
|
|
360
|
+
|
|
361
|
+
### Privacy lifecycle
|
|
362
|
+
|
|
363
|
+
The optional `@futdevpro/nts-dynamo/privacy-lifecycle` entry point provides the shared machinery for standalone
|
|
364
|
+
GDPR-capable products:
|
|
365
|
+
|
|
366
|
+
- identity-gated, deadline-bearing data-subject requests;
|
|
367
|
+
- explicit `received → identity-verified → scoped → planned → executing → verifying` processing;
|
|
368
|
+
- deterministic product-domain contributors with resumable partial outcomes and documented retention bases;
|
|
369
|
+
- append-only, checksummed legal acceptances;
|
|
370
|
+
- versioned, purpose-specific consent grants and withdrawals.
|
|
371
|
+
|
|
372
|
+
The Bedrock module coordinates state and evidence only. Each consuming product must register every data domain,
|
|
373
|
+
implement hard-delete/anonymization/export behavior, and provide transaction-safe persistence. A request is
|
|
374
|
+
never reported complete while a registered contributor has a failed outcome.
|
|
375
|
+
|
|
376
|
+
## Modules Overview
|
|
377
|
+
|
|
378
|
+
Dynamo-NTS is organized into focused modules, each providing specific functionality:
|
|
379
|
+
|
|
380
|
+
### Main Module
|
|
381
|
+
|
|
382
|
+
The core foundation providing essential components:
|
|
383
|
+
|
|
384
|
+
- **Collections**: Archive utilities, global settings, environment configuration
|
|
385
|
+
- **Enums**: Data model types, service functions, route security levels
|
|
386
|
+
- **Models**: Application configuration interfaces, control models, database types
|
|
387
|
+
- **Services**: Core services for API communication, authentication, data management, routing
|
|
388
|
+
|
|
389
|
+
### AI Module
|
|
390
|
+
|
|
391
|
+
Provides abstractions and implementations for AI operations:
|
|
392
|
+
|
|
393
|
+
- **Abstract Service Bases**: Base classes for AI providers, LLM services, LLM chat services, and embedding services
|
|
394
|
+
- **OpenAI Implementation**: Complete OpenAI integration with LLM, chat, and embedding support
|
|
395
|
+
- **Document AI**: Document chunking and preprocessing for AI models
|
|
396
|
+
- **Vector Search**: MongoDB Atlas vector database operations with automatic data vectorization
|
|
397
|
+
|
|
398
|
+
#### OpenAI-Compatible Providers
|
|
399
|
+
|
|
400
|
+
The OAI service-ek (`DyNTS_OAI_LLM_ServiceBase`, `DyNTS_OAI_LLMChat_ServiceBase`, `DyNTS_OAI_Embedding_ControlService`) bármely OpenAI-API-kompatibilis endpoint-tal működnek — lokál LLM (LM Studio, Ollama), self-hosted (vLLM, LocalAI) is — a `DyFM_OAI_ClientOptions.baseURL` mező segítségével. Részletek + provider-konfig sample-ök: [`__documentations/2026-05-17-oai-compatible-providers.md`](__documentations/2026-05-17-oai-compatible-providers.md).
|
|
401
|
+
|
|
402
|
+
### Assistant Module
|
|
403
|
+
|
|
404
|
+
Platform and AI provider agnostic solutions for creating intelligent assistants:
|
|
405
|
+
|
|
406
|
+
- Integrates communication providers (bot) with AI providers (LLM Chat)
|
|
407
|
+
- Message conversion utilities
|
|
408
|
+
- Conversation management
|
|
409
|
+
- Configurable settings for system prompts and message filtering
|
|
410
|
+
|
|
411
|
+
### Bot Module
|
|
412
|
+
|
|
413
|
+
Platform-agnostic bot functionality:
|
|
414
|
+
|
|
415
|
+
- Message, channel, and user wrappers for any messaging platform
|
|
416
|
+
- Command system for bot commands
|
|
417
|
+
- Routine system for scheduled and event-driven tasks
|
|
418
|
+
- IO management for bot interactions
|
|
419
|
+
- Provider support for Discord, Slack, and Teams
|
|
420
|
+
|
|
421
|
+
### Socket Module
|
|
422
|
+
|
|
423
|
+
Real-time communication capabilities that simplify Socket.io setup:
|
|
424
|
+
|
|
425
|
+
- Socket client and server implementations with secure and open connection options (simplifies Socket.io server initialization)
|
|
426
|
+
- Event handling system for managing real-time communications (replaces manual Socket.io event handler setup)
|
|
427
|
+
- Presence tracking for monitoring connected clients
|
|
428
|
+
- Error handling and logging for reliable operation
|
|
429
|
+
- Extended application class with built-in socket server capabilities (automatically configures Socket.io with Express server)
|
|
430
|
+
|
|
431
|
+
### Messaging Module
|
|
432
|
+
|
|
433
|
+
Backend implementation for unified messaging system:
|
|
434
|
+
|
|
435
|
+
- Data services for messages and conversations
|
|
436
|
+
- Control services for business logic orchestration
|
|
437
|
+
- Real-time socket events
|
|
438
|
+
- RESTful HTTP endpoints
|
|
439
|
+
- Integration with bot and assistant modules
|
|
440
|
+
|
|
441
|
+
### OAuth2 Module
|
|
442
|
+
|
|
443
|
+
Complete OAuth2.0 protocol implementation:
|
|
444
|
+
|
|
445
|
+
- OAuth2 authorization and token management
|
|
446
|
+
- Client management and user authentication
|
|
447
|
+
- Token exchange and refresh operations
|
|
448
|
+
- Authorization code and access token generation
|
|
449
|
+
|
|
450
|
+
### Server Module
|
|
451
|
+
|
|
452
|
+
Solutions for basic server endpoints:
|
|
453
|
+
|
|
454
|
+
- Error handling for saving and retrieving server errors
|
|
455
|
+
- Server status monitoring with version and uptime information
|
|
456
|
+
- Server status snapshots for saving and retrieving status at specific times
|
|
457
|
+
- Error statistics for monitoring and analysis
|
|
458
|
+
|
|
459
|
+
#### Content-free database readiness probe
|
|
460
|
+
|
|
461
|
+
Applications can perform one foreground readiness check against their own Mongoose connection without
|
|
462
|
+
starting a timer, listener, retry loop, subscription, process hook, or background task:
|
|
463
|
+
|
|
464
|
+
```typescript
|
|
465
|
+
import {
|
|
466
|
+
DyNTS_DbReadinessProbe_ControlService,
|
|
467
|
+
DyNTS_DbReadinessProbeResult_Interface,
|
|
468
|
+
} from '@futdevpro/nts-dynamo/server';
|
|
469
|
+
|
|
470
|
+
const result: DyNTS_DbReadinessProbeResult_Interface =
|
|
471
|
+
await DyNTS_DbReadinessProbe_ControlService.probe({
|
|
472
|
+
connection: mongoose.connection,
|
|
473
|
+
});
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
The `dynts-db-readiness/1` result contains exactly six allowlisted fields: contract version, readiness,
|
|
477
|
+
normalized connection state, ping success, bounded stage, and stable result code. It never contains a host,
|
|
478
|
+
database name, URI, model metadata, credentials, driver error text, or arbitrary error properties. Failures
|
|
479
|
+
resolve to a content-free, fail-closed result and the probe writes no log output.
|
|
480
|
+
|
|
481
|
+
Timeout policy and cancellation are caller-owned. The probe observes the supplied `AbortSignal` before and
|
|
482
|
+
after its single ping, but it does not create a timeout or interrupt an already-running driver operation.
|
|
483
|
+
Configure the driver's operation timeout and abort the supplied signal at the application boundary.
|
|
484
|
+
|
|
485
|
+
### Defaults Module
|
|
486
|
+
|
|
487
|
+
Default implementations for common services:
|
|
488
|
+
|
|
489
|
+
- Default user data model and service for authentication and user management
|
|
490
|
+
- Default authentication service with basic token-based authentication
|
|
491
|
+
- Default socket events service with graceful degradation
|
|
492
|
+
- All services can be extended or replaced with custom implementations
|
|
493
|
+
|
|
494
|
+
### Custom Data Module
|
|
495
|
+
|
|
496
|
+
Tools for managing custom data:
|
|
497
|
+
|
|
498
|
+
- Data service for handling custom data operations with optional initialization
|
|
499
|
+
- Controller with RESTful endpoints for data operations
|
|
500
|
+
- GET endpoint for retrieving custom data by ID
|
|
501
|
+
- POST endpoint for modifying custom data
|
|
502
|
+
- Configurable routing module with optional security overrides
|
|
503
|
+
|
|
504
|
+
### Test Module
|
|
505
|
+
|
|
506
|
+
Testing and monitoring tools:
|
|
507
|
+
|
|
508
|
+
- Test endpoints for different HTTP methods (GET, POST, DELETE)
|
|
509
|
+
- Server status endpoint with version and uptime information
|
|
510
|
+
- Configurable routing module with security override options
|
|
511
|
+
- Automatic controller registration for easy setup
|
|
512
|
+
|
|
513
|
+
### Usage Module
|
|
514
|
+
|
|
515
|
+
Session and usage tracking tools:
|
|
516
|
+
|
|
517
|
+
- Session management tools for creating, updating, and closing sessions
|
|
518
|
+
- Usage data collection and analysis tools
|
|
519
|
+
- Location tracking from HTTP requests
|
|
520
|
+
- Usage statistics retrieval with time range filtering
|
|
521
|
+
- Daily usage statistics calculation
|
|
522
|
+
|
|
523
|
+
## Usage Examples
|
|
524
|
+
|
|
525
|
+
### Basic Application Setup
|
|
526
|
+
|
|
527
|
+
This example shows a complete application setup using `DyNTS_AppExtended`:
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
import {
|
|
531
|
+
DyNTS_AppExtended,
|
|
532
|
+
DyNTS_App_Params,
|
|
533
|
+
DyNTS_GlobalService_Settings,
|
|
534
|
+
DyNTS_Http_Settings,
|
|
535
|
+
DyNTS_RoutingModule
|
|
536
|
+
} from '@futdevpro/nts-dynamo';
|
|
537
|
+
import { DyNTS_SocketServerService } from '@futdevpro/nts-dynamo/socket';
|
|
538
|
+
|
|
539
|
+
export class App extends DyNTS_AppExtended {
|
|
540
|
+
|
|
541
|
+
getAppParams(): DyNTS_App_Params {
|
|
542
|
+
return new DyNTS_App_Params({
|
|
543
|
+
name: 'My Server',
|
|
544
|
+
version: '1.0.0',
|
|
545
|
+
dbName: 'myapp',
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
getGlobalServiceCollection(): DyNTS_GlobalService_Settings {
|
|
550
|
+
return {
|
|
551
|
+
authService: AuthService.getInstance(),
|
|
552
|
+
dbModels: [
|
|
553
|
+
// Your data models
|
|
554
|
+
],
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
getPortSettings(): DyNTS_Http_Settings {
|
|
559
|
+
return new DyNTS_Http_Settings({
|
|
560
|
+
httpPort: 3000,
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
getRoutingModules(): DyNTS_RoutingModule[] {
|
|
565
|
+
return [
|
|
566
|
+
new DyNTS_RoutingModule({
|
|
567
|
+
route: '/api',
|
|
568
|
+
controllers: [
|
|
569
|
+
MyController.getInstance(),
|
|
570
|
+
],
|
|
571
|
+
}),
|
|
572
|
+
];
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
getSocketServices(): DyNTS_SocketServerService<any>[] {
|
|
576
|
+
return [
|
|
577
|
+
MySocketService.getInstance(),
|
|
578
|
+
];
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
### Routing Module Configuration
|
|
584
|
+
|
|
585
|
+
Multiple routing modules can be configured to organize your API:
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
getRoutingModules(): DyNTS_RoutingModule[] {
|
|
589
|
+
return [
|
|
590
|
+
new DyNTS_RoutingModule({
|
|
591
|
+
route: '/user',
|
|
592
|
+
controllers: [
|
|
593
|
+
User_Controller.getInstance(),
|
|
594
|
+
UserData_Controller.getInstance(),
|
|
595
|
+
UserSettings_Controller.getInstance(),
|
|
596
|
+
],
|
|
597
|
+
}),
|
|
598
|
+
new DyNTS_RoutingModule({
|
|
599
|
+
route: '/project',
|
|
600
|
+
controllers: [
|
|
601
|
+
Project_Controller.getInstance(),
|
|
602
|
+
ProjectExtension_Controller.getInstance(),
|
|
603
|
+
],
|
|
604
|
+
}),
|
|
605
|
+
new DyNTS_RoutingModule({
|
|
606
|
+
route: '/server',
|
|
607
|
+
controllers: [
|
|
608
|
+
ServerStatus_Controller.getInstance(),
|
|
609
|
+
],
|
|
610
|
+
}),
|
|
611
|
+
DyNTS_getTestRoutingModule(),
|
|
612
|
+
DyNTS_getUsageRoutingModule(),
|
|
613
|
+
];
|
|
614
|
+
}
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
### Controller Implementation
|
|
618
|
+
|
|
619
|
+
Controllers define API endpoints with authentication and business logic:
|
|
620
|
+
|
|
621
|
+
```typescript
|
|
622
|
+
import { Request, Response } from 'express';
|
|
623
|
+
import { DyNTS_Controller, DyNTS_Endpoint_Params } from '@futdevpro/nts-dynamo';
|
|
624
|
+
import { DyFM_HttpCallType } from '@futdevpro/fsm-dynamo';
|
|
625
|
+
|
|
626
|
+
export class User_Controller extends DyNTS_Controller {
|
|
627
|
+
|
|
628
|
+
static getInstance(): User_Controller {
|
|
629
|
+
return User_Controller.getSingletonInstance();
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
private authService: AuthService = AuthService.getInstance();
|
|
633
|
+
|
|
634
|
+
setupEndpoints(): void {
|
|
635
|
+
this.endpoints = [
|
|
636
|
+
new DyNTS_Endpoint_Params({
|
|
637
|
+
name: 'getUser',
|
|
638
|
+
type: DyFM_HttpCallType.get,
|
|
639
|
+
endpoint: '/get/:userId',
|
|
640
|
+
preProcesses: [this.authService.authenticate_tokenSelf],
|
|
641
|
+
tasks: [
|
|
642
|
+
async (req: Request, res: Response, issuer: string): Promise<void> => {
|
|
643
|
+
const userService = new User_DataService({ issuer });
|
|
644
|
+
await userService.getDataById(req.params.userId);
|
|
645
|
+
res.send(userService.data);
|
|
646
|
+
},
|
|
647
|
+
],
|
|
648
|
+
}),
|
|
649
|
+
new DyNTS_Endpoint_Params({
|
|
650
|
+
name: 'updateUser',
|
|
651
|
+
type: DyFM_HttpCallType.post,
|
|
652
|
+
endpoint: '/update',
|
|
653
|
+
preProcesses: [this.authService.authenticate_tokenSelf],
|
|
654
|
+
tasks: [
|
|
655
|
+
async (req: Request, res: Response, issuer: string): Promise<void> => {
|
|
656
|
+
const userService = new User_DataService({ issuer });
|
|
657
|
+
await userService.saveData(req.body);
|
|
658
|
+
res.send(userService.data);
|
|
659
|
+
},
|
|
660
|
+
],
|
|
661
|
+
}),
|
|
662
|
+
];
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
### Data Service Implementation
|
|
668
|
+
|
|
669
|
+
Data services provide a structured way to interact with MongoDB:
|
|
670
|
+
|
|
671
|
+
```typescript
|
|
672
|
+
import { DyNTS_DataService } from '@futdevpro/nts-dynamo';
|
|
673
|
+
import { DyFM_DataModel_Params } from '@futdevpro/fsm-dynamo'; // FSM provides the data model parameter definition
|
|
674
|
+
|
|
675
|
+
// Define your data model parameters
|
|
676
|
+
const userDataParams: DyFM_DataModel_Params<UserData> = new DyFM_DataModel_Params({
|
|
677
|
+
dataName: 'userData',
|
|
678
|
+
typeSample: {
|
|
679
|
+
userId: '',
|
|
680
|
+
preferences: {},
|
|
681
|
+
},
|
|
682
|
+
// ... additional configuration
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
export class User_DataService extends DyNTS_DataService<UserData> {
|
|
686
|
+
constructor(params: { issuer: string }) {
|
|
687
|
+
super(userDataParams);
|
|
688
|
+
this.issuer = params.issuer;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// Custom business logic methods
|
|
692
|
+
async getUserPreferences(userId: string): Promise<UserPreferences> {
|
|
693
|
+
await this.getDataByDependencyId({ userId });
|
|
694
|
+
return this.data?.preferences || {};
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
### Socket Server Service
|
|
700
|
+
|
|
701
|
+
Socket services enable real-time communication:
|
|
702
|
+
|
|
703
|
+
```typescript
|
|
704
|
+
import { DyNTS_SocketServerService, DyNTS_SocketPresence } from '@futdevpro/nts-dynamo/socket';
|
|
705
|
+
|
|
706
|
+
export class Chat_SocketServerService extends DyNTS_SocketServerService<DyNTS_SocketPresence, any> {
|
|
707
|
+
|
|
708
|
+
static getInstance(): Chat_SocketServerService {
|
|
709
|
+
return Chat_SocketServerService.getSingletonInstance();
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
protected setupSocketEvents(): void {
|
|
713
|
+
this.socketServer.on('connection', (socket) => {
|
|
714
|
+
socket.on('joinRoom', (roomId: string) => {
|
|
715
|
+
socket.join(roomId);
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
socket.on('sendMessage', async (data: { roomId: string; message: string }) => {
|
|
719
|
+
this.socketServer.to(data.roomId).emit('newMessage', data);
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
### Vector Search with AI
|
|
727
|
+
|
|
728
|
+
Dynamo-NTS provides built-in support for MongoDB Atlas vector search with automatic vectorization:
|
|
729
|
+
|
|
730
|
+
```typescript
|
|
731
|
+
import { DyNTS_OAI_VectorDataService } from '@futdevpro/nts-dynamo/ai/open-ai';
|
|
732
|
+
|
|
733
|
+
export class Knowledge_DataService extends DyNTS_OAI_VectorDataService<Knowledge> {
|
|
734
|
+
|
|
735
|
+
constructor() {
|
|
736
|
+
super(knowledgeDataParams);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
async searchSimilarContent(query: string, limit: number = 10): Promise<Knowledge[]> {
|
|
740
|
+
return await this.vectorSearch({
|
|
741
|
+
input: query,
|
|
742
|
+
searchInKey: 'content', // Property that has vectorization enabled
|
|
743
|
+
limit: limit,
|
|
744
|
+
numberOfCandidates: 100,
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
The vector search automatically:
|
|
751
|
+
- Creates embeddings for search queries using the configured AI provider
|
|
752
|
+
- Performs semantic search in MongoDB Atlas vector database
|
|
753
|
+
- Returns results sorted by relevance
|
|
754
|
+
- Supports filtering with additional MongoDB queries
|
|
755
|
+
|
|
756
|
+
## Ecosystem Integration
|
|
757
|
+
|
|
758
|
+
Dynamo-NTS is part of the unified **Dynamo ecosystem**, which consists of several interconnected packages:
|
|
759
|
+
|
|
760
|
+
### Dynamo FSM (Full Stack Module)
|
|
761
|
+
|
|
762
|
+
The foundational package [`@futdevpro/fsm-dynamo`](https://www.npmjs.com/package/@futdevpro/fsm-dynamo) that provides:
|
|
763
|
+
- Core interfaces and types shared across the ecosystem
|
|
764
|
+
- Base model definitions (used by all Dynamo-NTS data services)
|
|
765
|
+
- Utility functions
|
|
766
|
+
- Type definitions for system-wide use
|
|
767
|
+
- Data model parameter definitions (`DyFM_DataModel_Params`)
|
|
768
|
+
|
|
769
|
+
Dynamo-NTS is built on top of Dynamo FSM and implements the server-side components of the FSM architecture. All data models, interfaces, and type definitions used in Dynamo-NTS are provided by FSM, ensuring consistency and type safety across the entire ecosystem.
|
|
770
|
+
|
|
771
|
+
### Dynamo NGX (AngularX)
|
|
772
|
+
|
|
773
|
+
The frontend counterpart [`@futdevpro/dynamo-ngx`](https://www.npmjs.com/package/@futdevpro/dynamo-ngx) provides:
|
|
774
|
+
- Angular components and services
|
|
775
|
+
- Frontend models that integrate with Dynamo-NTS backend (using shared FSM types)
|
|
776
|
+
- Real-time communication clients (connects to Dynamo-NTS socket services)
|
|
777
|
+
- Form management and data table components
|
|
778
|
+
|
|
779
|
+
### Unified Patterns
|
|
780
|
+
|
|
781
|
+
The Dynamo ecosystem enforces consistent patterns across all packages:
|
|
782
|
+
|
|
783
|
+
- **Naming Conventions**: Consistent prefixes (`DyNTS_` for backend, `DyNX_` for frontend, `DyFM_` for shared)
|
|
784
|
+
- **Type Safety**: Full TypeScript support with shared type definitions
|
|
785
|
+
- **Architecture Patterns**: Consistent service patterns, data models, and API structures
|
|
786
|
+
- **Error Handling**: Unified error handling across the stack
|
|
787
|
+
- **Logging**: Consistent logging patterns and utilities
|
|
788
|
+
|
|
789
|
+
This unified approach ensures that:
|
|
790
|
+
- Developers learn one set of patterns that apply everywhere
|
|
791
|
+
- Frontend and backend code integrate seamlessly
|
|
792
|
+
- Type safety is maintained across the entire stack
|
|
793
|
+
- Maintenance and updates are simplified
|
|
794
|
+
|
|
795
|
+
## API Reference
|
|
796
|
+
|
|
797
|
+
For detailed API documentation, see:
|
|
798
|
+
|
|
799
|
+
- [Dynamo-NTS Documentation](fdp-documentations/specifications/dynamo-packages/dynamo-nts/dynamo-nts.md)
|
|
800
|
+
- [Dynamo FSM Documentation](fdp-documentations/specifications/dynamo-packages/dynamo-fsm/dynamo-fsm.md)
|
|
801
|
+
- [Dynamo Ecosystem Overview](fdp-documentations/specifications/dynamo-packages/dynamo_packages.md)
|
|
802
|
+
|
|
803
|
+
## License
|
|
804
|
+
|
|
805
|
+
ISC
|
|
806
|
+
|
|
807
|
+
## Support
|
|
808
|
+
|
|
809
|
+
For issues, questions, or contributions, please refer to the project repository.
|