blackcoffee2 2.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/CHANGELOG.md +664 -0
- package/LICENSE +201 -0
- package/NOTICE +25 -0
- package/README.md +246 -0
- package/apps.zip +0 -0
- package/bin/adminclient +105 -0
- package/bin/blackcoffee +133 -0
- package/cli/admin-users.js +282 -0
- package/cli/commands/app.js +561 -0
- package/cli/commands/config.js +182 -0
- package/cli/commands/db.js +257 -0
- package/cli/commands/server.js +200 -0
- package/config/applications.json +5 -0
- package/config/database.json +28 -0
- package/config/database.json.example +23 -0
- package/config/server.json +32 -0
- package/controllers/admin/AdminController.js +529 -0
- package/controllers/admin/AdminViewController.js +90 -0
- package/controllers/admin/AuthController.js +293 -0
- package/controllers/admin/DatabaseAdminController.js +218 -0
- package/core/SQLiteAdapter.js +333 -0
- package/core/appLoader.js +385 -0
- package/core/databasePoolManager.js +431 -0
- package/core/hotReload.js +363 -0
- package/data/ADMIN-README.md +145 -0
- package/data/CHANGELOG.md +48 -0
- package/data/GTK3-NODE-PROPOSALS.md +410 -0
- package/data/admin-db.js +150 -0
- package/data/admin-gui.js +452 -0
- package/data/blackcoffee_admin.db-shm +0 -0
- package/data/blackcoffee_admin.db-wal +0 -0
- package/data/migrations/001_create_admin_users.sql +33 -0
- package/docs/APP_HOOKS_HANDLER.md +432 -0
- package/docs/APP_HOOKS_REQUIREMENTS.md +588 -0
- package/docs/ARCHITECTURE.md +435 -0
- package/docs/CREAR_APP_Y_USAR_POOLS.md +1595 -0
- package/docs/EVENTS_APP_MANUAL.md +289 -0
- package/docs/INSITU_BINARY_UPLOAD_PROPOSAL.md +186 -0
- package/docs/INSITU_FIREWALL_EXCEPTION.md +187 -0
- package/docs/ROADMAP.md +242 -0
- package/docs/ROADMAP.md.backup +243 -0
- package/includes/404-hooks.js +423 -0
- package/includes/adminAuth.js +214 -0
- package/includes/adminExtension.js +53 -0
- package/includes/appHooks.js +302 -0
- package/includes/initAdminDb.js +115 -0
- package/includes/routeLoader.js +67 -0
- package/includes/sessions.js +223 -0
- package/issues/001-duplicate-module-loading.md +92 -0
- package/manuales/ADMIN_EXTENSION_COMMANDS_MANUAL.md +261 -0
- package/manuales/ADMIN_EXTENSION_HOOK_EXAMPLE.md +28 -0
- package/manuales/ADMIN_EXTENSION_INTEGRATION_MANUAL.md +232 -0
- package/manuales/CACHE_REGEX_COMMANDS.md +136 -0
- package/manuales/CACHE_SYSTEM_MAP.md +206 -0
- package/manuales/CREACION_DE_CONTROLADORES_INSITU.md +383 -0
- package/manuales/QUEUE_CLI_MODULE_MANUAL.md +289 -0
- package/manuales/QUEUE_SYSTEM_MANUAL.md +320 -0
- package/manuales/ROUTE_CACHE_MODULE_MANUAL.md +205 -0
- package/manuales/SESSION_MANAGER_GUIDE.md +529 -0
- package/manuales/SESSION_SECURITY_FLAGS.md +174 -0
- package/manuales/WAF_MODULE_MANUAL.md +229 -0
- package/manuales/after_route_handler_filter_example.md +116 -0
- package/manuales/after_route_handler_usage.md +130 -0
- package/manuales/an/303/241lisis-completo-insitu-framework.md +213 -0
- package/manuales/async_hooks_promises_guide.md +325 -0
- package/manuales/before_route_handler_filter_example.md +97 -0
- package/manuales/before_route_handler_usage.md +122 -0
- package/manuales/hooks_chaining_conditions_guide.md +261 -0
- package/manuales/hooks_filters_documentation.md +493 -0
- package/manuales/hooks_filters_documentation_en.md +493 -0
- package/manuales/hooks_vs_middlewares_comparison.md +87 -0
- package/manuales/manual-mvc-completo.md +934 -0
- package/manuales/modulos_administracion.md +89 -0
- package/manuales/router_execution_points.md +74 -0
- package/manuales/static_file_hooks_usage.md +222 -0
- package/models/AdminUserModel.js +132 -0
- package/package.json +45 -0
- package/programatically/PRoutes.js +89 -0
- package/programatically/initFlow.js +211 -0
- package/public/admin/css/db-pools.css +336 -0
- package/public/admin/css/styles.css +310 -0
- package/public/admin/database.html +312 -0
- package/public/admin/index.html +116 -0
- package/public/admin/js/app.js +470 -0
- package/public/admin/js/db-pools.js +253 -0
- package/public/admin/login.html +278 -0
- package/public/assets/css/styles.css +477 -0
- package/public/assets/js/main.js +89 -0
- package/public/index.html +136 -0
- package/public/templates/404.html +158 -0
- package/routes/admin-views.json +20 -0
- package/routes/admin.json +38 -0
- package/routes/auth.json +32 -0
- package/routes/static.json +18 -0
- package/server.js +299 -0
- package/test-aplicacion.con-logisession/BlackCoffee.js +226 -0
- package/test-aplicacion.con-logisession/SSL_SETUP.md +53 -0
- package/test-aplicacion.con-logisession/certs/ca-certificate.pem +32 -0
- package/test-aplicacion.con-logisession/certs/ca-private-key.pem +52 -0
- package/test-aplicacion.con-logisession/certs/certificate-2048.pem +22 -0
- package/test-aplicacion.con-logisession/certs/certificate.pem +32 -0
- package/test-aplicacion.con-logisession/certs/private-key-2048.pem +28 -0
- package/test-aplicacion.con-logisession/certs/private-key.pem +52 -0
- package/test-aplicacion.con-logisession/config/iaQueueSetup.js +84 -0
- package/test-aplicacion.con-logisession/config/qwen-rules.json +39 -0
- package/test-aplicacion.con-logisession/controllers/analyticsController.js +117 -0
- package/test-aplicacion.con-logisession/controllers/auth/AdminAuthController.js +142 -0
- package/test-aplicacion.con-logisession/controllers/auth/AuthController.js +439 -0
- package/test-aplicacion.con-logisession/controllers/auth/AuthViewController.js +223 -0
- package/test-aplicacion.con-logisession/controllers/endpointController.js +66 -0
- package/test-aplicacion.con-logisession/controllers/example.js +183 -0
- package/test-aplicacion.con-logisession/controllers/iaQueueController.js +367 -0
- package/test-aplicacion.con-logisession/controllers/queueController.js +206 -0
- package/test-aplicacion.con-logisession/controllers/qwenQueueController.js +197 -0
- package/test-aplicacion.con-logisession/controllers/test.js +0 -0
- package/test-aplicacion.con-logisession/controllers/tracking/EventsNoFinishController.js +78 -0
- package/test-aplicacion.con-logisession/controllers/tracking/TrackingController.js +412 -0
- package/test-aplicacion.con-logisession/controllers/tracking/TrackingControllerWithLoadModel.js +437 -0
- package/test-aplicacion.con-logisession/hooks/admin-hooks.js +20 -0
- package/test-aplicacion.con-logisession/hooks/general-hooks.js +97 -0
- package/test-aplicacion.con-logisession/hooks/queue-hooks.js +64 -0
- package/test-aplicacion.con-logisession/hooks/route-directory-hooks.js +38 -0
- package/test-aplicacion.con-logisession/hooks/security-hooks.js +24 -0
- package/test-aplicacion.con-logisession/insitu-admin-client/README.md +69 -0
- package/test-aplicacion.con-logisession/insitu-admin-client/package.json +23 -0
- package/test-aplicacion.con-logisession/insitu-admin-client.js +257 -0
- package/test-aplicacion.con-logisession/models/ExampleModel.js +88 -0
- package/test-aplicacion.con-logisession/models/QueueJobModel.js +263 -0
- package/test-aplicacion.con-logisession/models/TokenModel.js +207 -0
- package/test-aplicacion.con-logisession/models/auth/AuthModel.js +66 -0
- package/test-aplicacion.con-logisession/models/auth/UserModel.js +189 -0
- package/test-aplicacion.con-logisession/models/tracking/CompletedCartModel.js +213 -0
- package/test-aplicacion.con-logisession/models/tracking/EventModel.js +366 -0
- package/test-aplicacion.con-logisession/models/tracking/EventsNoFinishModel.js +131 -0
- package/test-aplicacion.con-logisession/models/tracking/SessionModel.js +360 -0
- package/test-aplicacion.con-logisession/models/tracking/SiteFlowModel.js +286 -0
- package/test-aplicacion.con-logisession/models/tracking/TokenModel.js +207 -0
- package/test-aplicacion.con-logisession/package-lock.json +3313 -0
- package/test-aplicacion.con-logisession/package.json +32 -0
- package/test-aplicacion.con-logisession/public/blackcoffee-welcome/index.html +1339 -0
- package/test-aplicacion.con-logisession/public/css/style.css +64 -0
- package/test-aplicacion.con-logisession/public/ejemplo-estatica/index.html +18 -0
- package/test-aplicacion.con-logisession/public/ejemplo-estatica/script.js +16 -0
- package/test-aplicacion.con-logisession/public/ejemplo-estatica/styles.css +43 -0
- package/test-aplicacion.con-logisession/public/images/logo.svg +7 -0
- package/test-aplicacion.con-logisession/public/js/main.js +67 -0
- package/test-aplicacion.con-logisession/routes/analytics-routes.json +8 -0
- package/test-aplicacion.con-logisession/routes/auth-routes.json +98 -0
- package/test-aplicacion.con-logisession/routes/blackcoffee-welcome-routes.json +20 -0
- package/test-aplicacion.con-logisession/routes/duplicate-test-routes.json.disabled +16 -0
- package/test-aplicacion.con-logisession/routes/ejemplo-estatica-routes.json +11 -0
- package/test-aplicacion.con-logisession/routes/endpoints-routes.json +8 -0
- package/test-aplicacion.con-logisession/routes/ia-queue-routes.json +26 -0
- package/test-aplicacion.con-logisession/routes/product-routes.json.disabled +20 -0
- package/test-aplicacion.con-logisession/routes/queue-routes.json +32 -0
- package/test-aplicacion.con-logisession/routes/qwen-routes.json +14 -0
- package/test-aplicacion.con-logisession/routes/static-routes.json +29 -0
- package/test-aplicacion.con-logisession/routes/tracking-routes.json +58 -0
- package/test-aplicacion.con-logisession/routes/tracking-with-loadmodel-routes.json +51 -0
- package/test-aplicacion.con-logisession/utils/dbAdapter.js +88 -0
- package/test-aplicacion.con-logisession/utils/qbWrapper.js +4 -0
- package/test-aplicacion.con-logisession/utils/queueProcessor.js +305 -0
- package/test-aplicacion.con-logisession/utils/qwenRulesService.js +131 -0
- package/test-aplicacion.con-logisession/utils/tokenHelper.js +22 -0
- package/test-aplicacion.con-logisession/views/auth/dashboard.html +443 -0
- package/test-aplicacion.con-logisession/views/auth/forgot-password.html +200 -0
- package/test-aplicacion.con-logisession/views/auth/login.html +213 -0
- package/test-aplicacion.con-logisession/views/auth/register.html +294 -0
- package/test-aplicacion.con-logisession/views/contact/form.html +47 -0
- package/test-aplicacion.con-logisession/views/products/index.html +39 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
# Hooks and Filters Documentation - Insitu Framework
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
1. [Introduction](#introduction)
|
|
5
|
+
2. [Types of Hooks](#types-of-hooks)
|
|
6
|
+
3. [Available Hooks](#available-hooks)
|
|
7
|
+
4. [Available Filters](#available-filters)
|
|
8
|
+
5. [Route Hooks](#route-hooks)
|
|
9
|
+
6. [Static File Hooks](#static-file-hooks)
|
|
10
|
+
7. [Controller Hooks](#controller-hooks)
|
|
11
|
+
8. [Request Hooks](#request-hooks)
|
|
12
|
+
9. [Server Hooks](#server-hooks)
|
|
13
|
+
10. [View Hooks](#view-hooks)
|
|
14
|
+
11. [Statistics Hooks](#statistics-hooks)
|
|
15
|
+
12. [Security Hooks](#security-hooks)
|
|
16
|
+
13. [Administration Hooks](#administration-hooks)
|
|
17
|
+
14. [Queue System Hooks](#queue-system-hooks)
|
|
18
|
+
15. [Model Hooks](#model-hooks)
|
|
19
|
+
16. [Session Hooks](#session-hooks)
|
|
20
|
+
17. [Authentication Hooks](#authentication-hooks)
|
|
21
|
+
18. [Middleware Hooks](#middleware-hooks)
|
|
22
|
+
19. [Cache Hooks](#cache-hooks)
|
|
23
|
+
20. [Database Hooks](#database-hooks)
|
|
24
|
+
|
|
25
|
+
## Introduction
|
|
26
|
+
|
|
27
|
+
The Insitu framework provides a robust system of hooks and filters that allows extending and customizing the framework's behavior at multiple points in the request lifecycle and operations. Hooks allow executing code at specific moments, while filters allow modifying data during the execution flow.
|
|
28
|
+
|
|
29
|
+
## Types of Hooks
|
|
30
|
+
|
|
31
|
+
### Action Hooks
|
|
32
|
+
Action hooks allow executing code at specific points without modifying data. They are registered with `addAction()`.
|
|
33
|
+
|
|
34
|
+
### Filter Hooks
|
|
35
|
+
Filter hooks allow modifying data during the execution flow. They are registered with `addFilter()` and must return the modified value.
|
|
36
|
+
|
|
37
|
+
## Available Hooks
|
|
38
|
+
|
|
39
|
+
### `request_received`
|
|
40
|
+
**Type:** Action and Filter
|
|
41
|
+
**Description:** Triggered when an HTTP request is received.
|
|
42
|
+
**Parameters:** `(req, res)`
|
|
43
|
+
**Filter Parameters:** `({ req, res }, req, res)`
|
|
44
|
+
**Usage:** Ideal for registering activity, initializing context, or applying global logic to all requests.
|
|
45
|
+
|
|
46
|
+
### `route_matched`
|
|
47
|
+
**Type:** Action and Filter
|
|
48
|
+
**Description:** Triggered when a matching route is found.
|
|
49
|
+
**Parameters:** `(matchedRoute, req, res)`
|
|
50
|
+
**Filter Parameters:** `({ matchedRoute, req, res }, matchedRoute, req, res)`
|
|
51
|
+
**Usage:** To apply specific logic after a route has been found.
|
|
52
|
+
|
|
53
|
+
### `route_handler_executed`
|
|
54
|
+
**Type:** Action and Filter
|
|
55
|
+
**Description:** Triggered after executing a route handler.
|
|
56
|
+
**Parameters:** `(matchedRoute, req, res)`
|
|
57
|
+
**Filter Parameters:** `({ matchedRoute, req, res }, matchedRoute, req, res)`
|
|
58
|
+
**Usage:** For post-execution auditing, metrics, or cleanup.
|
|
59
|
+
|
|
60
|
+
### `route_not_found`
|
|
61
|
+
**Type:** Action and Filter
|
|
62
|
+
**Description:** Triggered when no matching route is found (404 error).
|
|
63
|
+
**Parameters:** `(pathname, req, res)`
|
|
64
|
+
**Filter Parameters:** `({ pathname, req, res }, pathname, req, res)`
|
|
65
|
+
**Usage:** To handle unfound routes or register 404 errors.
|
|
66
|
+
|
|
67
|
+
### `customize_404_response`
|
|
68
|
+
**Type:** Filter
|
|
69
|
+
**Description:** Executes when a 404 error occurs to allow customizing the response.
|
|
70
|
+
**Parameters:** `({ shouldSendDefaultResponse, pathname, req, res }, pathname, req, res)`
|
|
71
|
+
**Usage:** To completely customize the 404 error response, including sending custom messages or avoiding the standard response.
|
|
72
|
+
|
|
73
|
+
### `request_processed`
|
|
74
|
+
**Type:** Action and Filter
|
|
75
|
+
**Description:** Triggered after completely processing a request.
|
|
76
|
+
**Parameters:** `(req, res)`
|
|
77
|
+
**Filter Parameters:** `({ req, res }, req, res)`
|
|
78
|
+
**Usage:** For cleanup tasks or request completion logging.
|
|
79
|
+
|
|
80
|
+
### `request_error`
|
|
81
|
+
**Type:** Action and Filter
|
|
82
|
+
**Description:** Triggered when an error occurs during request processing.
|
|
83
|
+
**Parameters:** `(req, res, error)`
|
|
84
|
+
**Filter Parameters:** `({ req, res, error }, req, res, error)`
|
|
85
|
+
**Usage:** For centralized error handling.
|
|
86
|
+
|
|
87
|
+
### `middleware_response_finished`
|
|
88
|
+
**Type:** Action and Filter
|
|
89
|
+
**Description:** Triggered when a middleware responds and finishes the request.
|
|
90
|
+
**Parameters:** `(req, res)`
|
|
91
|
+
**Filter Parameters:** `({ req, res }, req, res)`
|
|
92
|
+
**Usage:** To register when a middleware responds directly.
|
|
93
|
+
|
|
94
|
+
### `options_response_sent`
|
|
95
|
+
**Type:** Action and Filter
|
|
96
|
+
**Description:** Triggered when an OPTIONS response is sent.
|
|
97
|
+
**Parameters:** `(req, res)`
|
|
98
|
+
**Filter Parameters:** `({ req, res }, req, res)`
|
|
99
|
+
**Usage:** To register or audit OPTIONS responses (CORS preflight).
|
|
100
|
+
|
|
101
|
+
## Available Filters
|
|
102
|
+
|
|
103
|
+
### `before_route_handler`
|
|
104
|
+
**Type:** Filter
|
|
105
|
+
**Description:** Executes before running a route handler (only for non-OPTIONS requests).
|
|
106
|
+
**Parameters:** `({ req, res, matchedRoute }, req, res, matchedRoute)`
|
|
107
|
+
**Usage:** For authentication, authorization, context preparation, or request/response object modification.
|
|
108
|
+
|
|
109
|
+
### `after_route_handler`
|
|
110
|
+
**Type:** Filter
|
|
111
|
+
**Description:** Executes after running a route handler (only for non-OPTIONS requests).
|
|
112
|
+
**Parameters:** `({ req, res, matchedRoute }, req, res, matchedRoute)`
|
|
113
|
+
**Usage:** For post-execution auditing, metrics, response modification, or cleanup.
|
|
114
|
+
|
|
115
|
+
### `before_static_file_load`
|
|
116
|
+
**Type:** Filter
|
|
117
|
+
**Description:** Executes before loading a static file.
|
|
118
|
+
**Parameters:** `({ req, res, filePath, staticConfig }, req, res, filePath, staticConfig)`
|
|
119
|
+
**Usage:** For permission checking, authentication, or static file configuration modification.
|
|
120
|
+
|
|
121
|
+
### `after_static_file_load`
|
|
122
|
+
**Type:** Filter
|
|
123
|
+
**Description:** Executes after loading a static file but before sending it to the client.
|
|
124
|
+
**Parameters:** `({ req, res, filePath, staticConfig, fileContent }, req, res, filePath, staticConfig, fileContent)`
|
|
125
|
+
**Usage:** To modify static file content, inject scripts, or apply transformations.
|
|
126
|
+
|
|
127
|
+
### `before_controller_load`
|
|
128
|
+
**Type:** Filter
|
|
129
|
+
**Description:** Executes before loading a controller.
|
|
130
|
+
**Parameters:** `({ controllerPath }, controllerPath)`
|
|
131
|
+
**Usage:** To modify the controller path or apply pre-loading logic.
|
|
132
|
+
|
|
133
|
+
### `after_controller_load`
|
|
134
|
+
**Type:** Filter
|
|
135
|
+
**Description:** Executes after loading a controller.
|
|
136
|
+
**Parameters:** `({ controllerModule, controllerPath }, controllerModule, controllerPath)`
|
|
137
|
+
**Usage:** To decorate controllers, apply post-loading logic, or modify controller modules.
|
|
138
|
+
|
|
139
|
+
## Route Hooks
|
|
140
|
+
|
|
141
|
+
### `route_registered`
|
|
142
|
+
**Type:** Action
|
|
143
|
+
**Description:** Triggered when a new route is registered.
|
|
144
|
+
**Parameters:** `(route)`
|
|
145
|
+
**Usage:** To maintain active route records or apply post-registration logic.
|
|
146
|
+
|
|
147
|
+
## Static File Hooks
|
|
148
|
+
|
|
149
|
+
### `pre_static_file_serve`
|
|
150
|
+
**Type:** Action and Filter
|
|
151
|
+
**Description:** Triggered before serving a static file.
|
|
152
|
+
**Parameters:** `(req, res, staticConfig, routePath)`
|
|
153
|
+
**Filter Parameters:** `({ req, res, staticConfig, routePath }, req, res, staticConfig, routePath)`
|
|
154
|
+
**Usage:** For permission checks or pre-delivery logic.
|
|
155
|
+
|
|
156
|
+
### `static_file_access_denied`
|
|
157
|
+
**Type:** Action
|
|
158
|
+
**Description:** Triggered when access to a static file is denied.
|
|
159
|
+
**Parameters:** `(req, res, normalizedPath)`
|
|
160
|
+
**Usage:** To register denied accesses or apply security measures.
|
|
161
|
+
|
|
162
|
+
### `serving_index_file`
|
|
163
|
+
**Type:** Action
|
|
164
|
+
**Description:** Triggered when serving an index file (like index.html).
|
|
165
|
+
**Parameters:** `(indexPath, req, res)`
|
|
166
|
+
**Usage:** To register access to main pages.
|
|
167
|
+
|
|
168
|
+
### `static_file_served`
|
|
169
|
+
**Type:** Action
|
|
170
|
+
**Description:** Triggered after serving a static file.
|
|
171
|
+
**Parameters:** `(filePath, req, res)`
|
|
172
|
+
**Usage:** To register static file access or apply auditing.
|
|
173
|
+
|
|
174
|
+
### `static_file_not_found`
|
|
175
|
+
**Type:** Action
|
|
176
|
+
**Description:** Triggered when a static file is not found.
|
|
177
|
+
**Parameters:** `(filePath, req, res)`
|
|
178
|
+
**Usage:** To register missing files or apply fallback logic.
|
|
179
|
+
|
|
180
|
+
### `static_directory_no_index`
|
|
181
|
+
**Type:** Action
|
|
182
|
+
**Description:** Triggered when accessing a directory without an index file.
|
|
183
|
+
**Parameters:** `(dirPath, req, res)`
|
|
184
|
+
**Usage:** To register directory accesses or apply directory logic.
|
|
185
|
+
|
|
186
|
+
### `before_reading_static_file`
|
|
187
|
+
**Type:** Action
|
|
188
|
+
**Description:** Triggered before reading a static file from disk.
|
|
189
|
+
**Parameters:** `(filePath, req, res)`
|
|
190
|
+
**Usage:** To apply pre-read logic.
|
|
191
|
+
|
|
192
|
+
## Controller Hooks
|
|
193
|
+
|
|
194
|
+
### `pre_controller_load` (DEPRECATED)
|
|
195
|
+
**Type:** Action
|
|
196
|
+
**Description:** Triggered before loading a controller (will be removed in future versions).
|
|
197
|
+
**Parameters:** `(controllerPath)`
|
|
198
|
+
**Usage:** To apply pre-loading logic to controllers (use `before_controller_load` instead).
|
|
199
|
+
|
|
200
|
+
### `post_controller_load` (DEPRECATED)
|
|
201
|
+
**Type:** Action
|
|
202
|
+
**Description:** Triggered after loading a controller (will be removed in future versions).
|
|
203
|
+
**Parameters:** `(controllerModule, controllerPath)`
|
|
204
|
+
**Usage:** To apply post-loading logic to controllers (use `after_controller_load` instead).
|
|
205
|
+
|
|
206
|
+
### `controller_registered_with_model`
|
|
207
|
+
**Type:** Action
|
|
208
|
+
**Description:** Triggered when a controller is registered with a model.
|
|
209
|
+
**Parameters:** `(controllerName, modelName)`
|
|
210
|
+
**Usage:** To maintain relationships between controllers and models.
|
|
211
|
+
|
|
212
|
+
### `controller_unregistered_from_model`
|
|
213
|
+
**Type:** Action
|
|
214
|
+
**Description:** Triggered when a controller is unregistered from a model.
|
|
215
|
+
**Parameters:** `(controllerName, modelName)`
|
|
216
|
+
**Usage:** To clean up relationships between controllers and models.
|
|
217
|
+
|
|
218
|
+
## Request Hooks
|
|
219
|
+
|
|
220
|
+
### `framework_init`
|
|
221
|
+
**Type:** Action
|
|
222
|
+
**Description:** Triggered during framework initialization.
|
|
223
|
+
**Parameters:** None
|
|
224
|
+
**Usage:** To initialize global components or apply initial configurations.
|
|
225
|
+
|
|
226
|
+
## Server Hooks
|
|
227
|
+
|
|
228
|
+
### `server_started`
|
|
229
|
+
**Type:** Action
|
|
230
|
+
**Description:** Triggered when the server starts.
|
|
231
|
+
**Parameters:** `(server)`
|
|
232
|
+
**Usage:** To apply post-server startup logic.
|
|
233
|
+
|
|
234
|
+
### `server_stopped`
|
|
235
|
+
**Type:** Action
|
|
236
|
+
**Description:** Triggered when the server stops.
|
|
237
|
+
**Parameters:** `(server)`
|
|
238
|
+
**Usage:** To apply cleanup or shutdown logic.
|
|
239
|
+
|
|
240
|
+
### `server_pre_start`
|
|
241
|
+
**Type:** Action
|
|
242
|
+
**Description:** Triggered before starting the server.
|
|
243
|
+
**Parameters:** `(server)`
|
|
244
|
+
**Usage:** To apply pre-startup configurations.
|
|
245
|
+
|
|
246
|
+
### `server_post_start`
|
|
247
|
+
**Type:** Action
|
|
248
|
+
**Description:** Triggered after starting the server.
|
|
249
|
+
**Parameters:** `(server)`
|
|
250
|
+
**Usage:** To apply post-startup logic.
|
|
251
|
+
|
|
252
|
+
## View Hooks
|
|
253
|
+
|
|
254
|
+
### `view_rendered`
|
|
255
|
+
**Type:** Action
|
|
256
|
+
**Description:** Triggered after rendering a view.
|
|
257
|
+
**Parameters:** `(viewName, data, req, res)`
|
|
258
|
+
**Usage:** To register rendered views or apply post-rendering logic.
|
|
259
|
+
|
|
260
|
+
### `view_render_error`
|
|
261
|
+
**Type:** Action
|
|
262
|
+
**Description:** Triggered when an error occurs while rendering a view.
|
|
263
|
+
**Parameters:** `(viewName, data, req, res, error)`
|
|
264
|
+
**Usage:** To handle view rendering errors.
|
|
265
|
+
|
|
266
|
+
## Statistics Hooks
|
|
267
|
+
|
|
268
|
+
### `stats_updated`
|
|
269
|
+
**Type:** Action
|
|
270
|
+
**Description:** Triggered when server statistics are updated.
|
|
271
|
+
**Parameters:** `(stats)`
|
|
272
|
+
**Usage:** To register or process updated statistics.
|
|
273
|
+
|
|
274
|
+
### `request_bytes_updated`
|
|
275
|
+
**Type:** Action
|
|
276
|
+
**Description:** Triggered when request bytes are updated.
|
|
277
|
+
**Parameters:** `(bytes)`
|
|
278
|
+
**Usage:** To monitor incoming traffic.
|
|
279
|
+
|
|
280
|
+
### `response_bytes_updated`
|
|
281
|
+
**Type:** Action
|
|
282
|
+
**Description:** Triggered when response bytes are updated.
|
|
283
|
+
**Parameters:** `(bytes)`
|
|
284
|
+
**Usage:** To monitor outgoing traffic.
|
|
285
|
+
|
|
286
|
+
### `requests_processed_updated`
|
|
287
|
+
**Type:** Action
|
|
288
|
+
**Description:** Triggered when the processed requests counter is updated.
|
|
289
|
+
**Parameters:** `()`
|
|
290
|
+
**Usage:** To monitor request volume.
|
|
291
|
+
|
|
292
|
+
### `responses_sent_updated`
|
|
293
|
+
**Type:** Action
|
|
294
|
+
**Description:** Triggered when the sent responses counter is updated.
|
|
295
|
+
**Parameters:** `()`
|
|
296
|
+
**Usage:** To monitor response volume.
|
|
297
|
+
|
|
298
|
+
### `route_access_registered`
|
|
299
|
+
**Type:** Action
|
|
300
|
+
**Description:** Triggered when route access is registered.
|
|
301
|
+
**Parameters:** `(req)`
|
|
302
|
+
**Usage:** To monitor route usage.
|
|
303
|
+
|
|
304
|
+
### `endpoint_hit_registered`
|
|
305
|
+
**Type:** Action
|
|
306
|
+
**Description:** Triggered when an endpoint hit is registered.
|
|
307
|
+
**Parameters:** `(matchedRoute)`
|
|
308
|
+
**Usage:** To monitor usage of specific endpoints.
|
|
309
|
+
|
|
310
|
+
## Security Hooks
|
|
311
|
+
|
|
312
|
+
### `waf_request_processed`
|
|
313
|
+
**Type:** Action
|
|
314
|
+
**Description:** Triggered when the WAF processes a request.
|
|
315
|
+
**Parameters:** `(req, res, action)`
|
|
316
|
+
**Usage:** To monitor firewall actions.
|
|
317
|
+
|
|
318
|
+
### `security_check_performed`
|
|
319
|
+
**Type:** Action
|
|
320
|
+
**Description:** Triggered when a security check is performed.
|
|
321
|
+
**Parameters:** `(req, checkType, result)`
|
|
322
|
+
**Usage:** To register security checks.
|
|
323
|
+
|
|
324
|
+
## Administration Hooks
|
|
325
|
+
|
|
326
|
+
### `admin_route_active`
|
|
327
|
+
**Type:** Action
|
|
328
|
+
**Description:** Triggered when an active route is registered in the administration system.
|
|
329
|
+
**Parameters:** `(routeInfo)`
|
|
330
|
+
**Usage:** To maintain records of active routes in the admin panel.
|
|
331
|
+
|
|
332
|
+
## Queue System Hooks
|
|
333
|
+
|
|
334
|
+
### `queue_task_added`
|
|
335
|
+
**Type:** Action
|
|
336
|
+
**Description:** Triggered when a task is added to a queue.
|
|
337
|
+
**Parameters:** `(task, queueName)`
|
|
338
|
+
**Usage:** To monitor addition of tasks to queues.
|
|
339
|
+
|
|
340
|
+
### `queue_task_executed`
|
|
341
|
+
**Type:** Action
|
|
342
|
+
**Description:** Triggered when a queue task is executed.
|
|
343
|
+
**Parameters:** `(task, queueName)`
|
|
344
|
+
**Usage:** To monitor execution of tasks.
|
|
345
|
+
|
|
346
|
+
### `queue_task_failed`
|
|
347
|
+
**Type:** Action
|
|
348
|
+
**Description:** Triggered when a queue task fails.
|
|
349
|
+
**Parameters:** `(task, queueName, error)`
|
|
350
|
+
**Usage:** To handle queue task failures.
|
|
351
|
+
|
|
352
|
+
## Model Hooks
|
|
353
|
+
|
|
354
|
+
### `model_loaded`
|
|
355
|
+
**Type:** Action
|
|
356
|
+
**Description:** Triggered when a model is loaded.
|
|
357
|
+
**Parameters:** `(modelName, modelInstance)`
|
|
358
|
+
**Usage:** To register model loading or apply post-loading logic.
|
|
359
|
+
|
|
360
|
+
### `model_saved`
|
|
361
|
+
**Type:** Action
|
|
362
|
+
**Description:** Triggered when a model is saved.
|
|
363
|
+
**Parameters:** `(modelName, modelInstance, data)`
|
|
364
|
+
**Usage:** To register save operations or apply post-save logic.
|
|
365
|
+
|
|
366
|
+
### `model_deleted`
|
|
367
|
+
**Type:** Action
|
|
368
|
+
**Description:** Triggered when a model is deleted.
|
|
369
|
+
**Parameters:** `(modelName, modelInstance, id)`
|
|
370
|
+
**Usage:** To register deletion operations or apply post-delete logic.
|
|
371
|
+
|
|
372
|
+
## Session Hooks
|
|
373
|
+
|
|
374
|
+
### `session_created`
|
|
375
|
+
**Type:** Action
|
|
376
|
+
**Description:** Triggered when a session is created.
|
|
377
|
+
**Parameters:** `(sessionId, sessionData)`
|
|
378
|
+
**Usage:** To register session creation or apply post-creation logic.
|
|
379
|
+
|
|
380
|
+
### `session_destroyed`
|
|
381
|
+
**Type:** Action
|
|
382
|
+
**Description:** Triggered when a session is destroyed.
|
|
383
|
+
**Parameters:** `(sessionId)`
|
|
384
|
+
**Usage:** To register session destruction or apply cleanup logic.
|
|
385
|
+
|
|
386
|
+
## Authentication Hooks
|
|
387
|
+
|
|
388
|
+
### `authentication_success`
|
|
389
|
+
**Type:** Action
|
|
390
|
+
**Description:** Triggered when an authentication is successful.
|
|
391
|
+
**Parameters:** `(user, req)`
|
|
392
|
+
**Usage:** To register successful authentications or apply post-authentication logic.
|
|
393
|
+
|
|
394
|
+
### `authentication_failure`
|
|
395
|
+
**Type:** Action
|
|
396
|
+
**Description:** Triggered when an authentication fails.
|
|
397
|
+
**Parameters:** `(credentials, req, reason)`
|
|
398
|
+
**Usage:** To register authentication failures or apply security measures.
|
|
399
|
+
|
|
400
|
+
## Middleware Hooks
|
|
401
|
+
|
|
402
|
+
### `middleware_executed`
|
|
403
|
+
**Type:** Action
|
|
404
|
+
**Description:** Triggered when a middleware is executed.
|
|
405
|
+
**Parameters:** `(middleware, req, res)`
|
|
406
|
+
**Usage:** To register middleware execution or apply post-execution logic.
|
|
407
|
+
|
|
408
|
+
## Cache Hooks
|
|
409
|
+
|
|
410
|
+
### `cache_hit`
|
|
411
|
+
**Type:** Action
|
|
412
|
+
**Description:** Triggered when a cached element is found.
|
|
413
|
+
**Parameters:** `(key, value)`
|
|
414
|
+
**Usage:** To monitor cache effectiveness.
|
|
415
|
+
|
|
416
|
+
### `cache_miss`
|
|
417
|
+
**Type:** Action
|
|
418
|
+
**Description:** Triggered when a cached element is not found.
|
|
419
|
+
**Parameters:** `(key)`
|
|
420
|
+
**Usage:** To monitor cache misses.
|
|
421
|
+
|
|
422
|
+
### `cache_set`
|
|
423
|
+
**Type:** Action
|
|
424
|
+
**Description:** Triggered when a value is set in cache.
|
|
425
|
+
**Parameters:** `(key, value, ttl)`
|
|
426
|
+
**Usage:** To register cache write operations.
|
|
427
|
+
|
|
428
|
+
### `cache_delete`
|
|
429
|
+
**Type:** Action
|
|
430
|
+
**Description:** Triggered when a value is deleted from cache.
|
|
431
|
+
**Parameters:** `(key)`
|
|
432
|
+
**Usage:** To register cache deletion operations.
|
|
433
|
+
|
|
434
|
+
## Database Hooks
|
|
435
|
+
|
|
436
|
+
### `db_query_executed`
|
|
437
|
+
**Type:** Action
|
|
438
|
+
**Description:** Triggered when a database query is executed.
|
|
439
|
+
**Parameters:** `(query, params, executionTime)`
|
|
440
|
+
**Usage:** To monitor database queries or apply auditing.
|
|
441
|
+
|
|
442
|
+
### `db_connection_acquired`
|
|
443
|
+
**Type:** Action
|
|
444
|
+
**Description:** Triggered when a database connection is acquired.
|
|
445
|
+
**Parameters:** `(connectionId)`
|
|
446
|
+
**Usage:** To monitor connection usage.
|
|
447
|
+
|
|
448
|
+
### `db_connection_released`
|
|
449
|
+
**Type:** Action
|
|
450
|
+
**Description:** Triggered when a database connection is released.
|
|
451
|
+
**Parameters:** `(connectionId)`
|
|
452
|
+
**Usage:** To monitor connection release.
|
|
453
|
+
|
|
454
|
+
## Using Hooks and Filters
|
|
455
|
+
|
|
456
|
+
### Registering an Action Hook
|
|
457
|
+
```javascript
|
|
458
|
+
hooks.addAction('request_received', (req, res) => {
|
|
459
|
+
console.log(`Request received: ${req.method} ${req.url}`);
|
|
460
|
+
}, 10, 2);
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Registering a Filter
|
|
464
|
+
```javascript
|
|
465
|
+
hooks.addFilter('before_route_handler', (data, req, res, matchedRoute) => {
|
|
466
|
+
req.startTime = Date.now();
|
|
467
|
+
return {
|
|
468
|
+
...data,
|
|
469
|
+
req: req
|
|
470
|
+
};
|
|
471
|
+
}, 10, 3);
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
### Registration Parameters
|
|
475
|
+
- `hookName`: Name of the hook
|
|
476
|
+
- `callback`: Function to execute
|
|
477
|
+
- `priority`: Priority (lower number executes first)
|
|
478
|
+
- `acceptedArgs`: Number of accepted arguments
|
|
479
|
+
- `identifier`: Optional identifier for the callback
|
|
480
|
+
|
|
481
|
+
## Common Priorities
|
|
482
|
+
- 1-10: Critical validation and security
|
|
483
|
+
- 11-30: Authentication and authorization
|
|
484
|
+
- 31-50: Context preparation
|
|
485
|
+
- 51-70: Business logic
|
|
486
|
+
- 71-90: Auditing and logging
|
|
487
|
+
- 91-100: Cleanup and post-processing
|
|
488
|
+
|
|
489
|
+
## Performance Considerations
|
|
490
|
+
- Synchronous hooks execute in order and can block
|
|
491
|
+
- Asynchronous hooks resolve in order but don't block
|
|
492
|
+
- Recommended to use appropriate priorities to control execution order
|
|
493
|
+
- Filters must always return a value to maintain the chain
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Hooks vs Middlewares
|
|
2
|
+
|
|
3
|
+
## Comparación entre Hooks y Middlewares en el Framework Insitu
|
|
4
|
+
|
|
5
|
+
### Middlewares
|
|
6
|
+
|
|
7
|
+
#### Ventajas:
|
|
8
|
+
- **Fáciles para principiantes**: Sintaxis familiar similar a otros frameworks
|
|
9
|
+
- **Ejecución lineal**: Secuencia predecible de ejecución
|
|
10
|
+
- **Interceptan solicitudes**: Pueden modificar `req` y `res` antes de llegar al handler
|
|
11
|
+
- **Útiles para autenticación**: Ideal para verificar credenciales antes de procesar rutas
|
|
12
|
+
- **Manejo de errores centralizado**: Pueden capturar errores de forma temprana
|
|
13
|
+
|
|
14
|
+
#### Desventajas:
|
|
15
|
+
- **Ejecución lineal rígida**: No se puede alterar fácilmente el flujo
|
|
16
|
+
- **Menos flexibilidad**: Solo se pueden aplicar en puntos específicos del flujo
|
|
17
|
+
- **Dependencia del orden**: El comportamiento puede depender del orden de registro
|
|
18
|
+
- **Menos granularidad**: No permiten puntos de extensión tan específicos
|
|
19
|
+
|
|
20
|
+
### Hooks
|
|
21
|
+
|
|
22
|
+
#### Ventajas:
|
|
23
|
+
- **Mayor control para expertos**: Permite personalización precisa del comportamiento
|
|
24
|
+
- **Prioridades configurables**: Se puede definir el orden exacto de ejecución
|
|
25
|
+
- **Puntos de extensión específicos**: Se pueden insertar en momentos precisos del ciclo de vida
|
|
26
|
+
- **Flexibilidad extrema**: Se pueden aplicar tanto como acciones como filtros
|
|
27
|
+
- **Orquestación fina**: Permite coordinar múltiples componentes de forma precisa
|
|
28
|
+
- **Separación de responsabilidades**: Cada hook tiene un propósito bien definido
|
|
29
|
+
|
|
30
|
+
#### Desventajas:
|
|
31
|
+
- **Curva de aprendizaje más pronunciada**: Requiere comprensión más profunda del sistema
|
|
32
|
+
- **Complejidad**: Puede ser sobrecargado para casos simples
|
|
33
|
+
- **Dependencia del conocimiento del sistema**: Se necesita entender los puntos de extensión
|
|
34
|
+
|
|
35
|
+
### Casos de uso recomendados
|
|
36
|
+
|
|
37
|
+
#### Middlewares:
|
|
38
|
+
- Autenticación y autorización
|
|
39
|
+
- Logging de solicitudes
|
|
40
|
+
- Parsing de cuerpos de solicitud
|
|
41
|
+
- CORS y seguridad básica
|
|
42
|
+
- Manejo de sesiones
|
|
43
|
+
|
|
44
|
+
#### Hooks:
|
|
45
|
+
- Modificación de comportamiento interno del framework
|
|
46
|
+
- Integración profunda con sistemas externos
|
|
47
|
+
- Auditoría detallada
|
|
48
|
+
- Personalización de respuesta
|
|
49
|
+
- Manipulación de contenido de archivos estáticos
|
|
50
|
+
- Extensión de funcionalidades del sistema
|
|
51
|
+
|
|
52
|
+
### Ejemplo práctico
|
|
53
|
+
|
|
54
|
+
#### Middleware para autenticación:
|
|
55
|
+
```javascript
|
|
56
|
+
const authMiddleware = (req, res, next) => {
|
|
57
|
+
if (!req.headers.authorization) {
|
|
58
|
+
res.writeHead(401);
|
|
59
|
+
res.end('Unauthorized');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
next();
|
|
63
|
+
};
|
|
64
|
+
server.use('/protected', authMiddleware);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### Hook para manipulación de archivos estáticos:
|
|
68
|
+
```javascript
|
|
69
|
+
// Modificar contenido de archivos HTML antes de enviarlos
|
|
70
|
+
hooks.addFilter('after_static_file_load', (data, req, res, filePath, staticConfig, fileContent) => {
|
|
71
|
+
if (filePath.endsWith('.html')) {
|
|
72
|
+
let content = data.fileContent.toString();
|
|
73
|
+
// Inyectar script de analytics
|
|
74
|
+
content = content.replace('</body>', '<script src="/analytics.js"></script></body>');
|
|
75
|
+
return {
|
|
76
|
+
...data,
|
|
77
|
+
fileContent: Buffer.from(content)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return data;
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Conclusión
|
|
85
|
+
|
|
86
|
+
- **Middlewares**: Ideales para developers que buscan soluciones rápidas y sencillas, especialmente para tareas de preprocesamiento de solicitudes.
|
|
87
|
+
- **Hooks**: Potentes herramientas para desarrolladores avanzados que necesitan control preciso sobre el comportamiento del framework en puntos específicos del ciclo de vida de las solicitudes y otros procesos.
|