xypriss 9.10.20 → 9.10.22
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/dist/cjs/src/index.js +2 -0
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/server/core/XyServerCreator.js +0 -9
- package/dist/cjs/src/server/core/XyServerCreator.js.map +1 -1
- package/dist/cjs/src/utils/Send.js +170 -0
- package/dist/cjs/src/utils/Send.js.map +1 -0
- package/dist/cjs/src/xhsc.js +23 -1
- package/dist/cjs/src/xhsc.js.map +1 -1
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/server/core/XyServerCreator.js +0 -9
- package/dist/esm/src/server/core/XyServerCreator.js.map +1 -1
- package/dist/esm/src/utils/Send.js +168 -0
- package/dist/esm/src/utils/Send.js.map +1 -0
- package/dist/esm/src/xhsc.js +23 -1
- package/dist/esm/src/xhsc.js.map +1 -1
- package/dist/index.d.ts +173 -56
- package/package.json +1 -1
package/dist/cjs/src/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var XyGuard = require('./server/routing/modules/XyGuard.js');
|
|
|
16
16
|
var PluginHookIds = require('./plugins/const/PluginHookIds.js');
|
|
17
17
|
var mergeWithDefaults = require('./utils/mergeWithDefaults.js');
|
|
18
18
|
var getIp = require('./utils/getIp.js');
|
|
19
|
+
var Send = require('./utils/Send.js');
|
|
19
20
|
var ProjectDiscovery = require('./utils/ProjectDiscovery.js');
|
|
20
21
|
var XemsPlugin = require('./plugins/builtin/xems/XemsPlugin.js');
|
|
21
22
|
var getMime = require('./utils/getMime.js');
|
|
@@ -84,6 +85,7 @@ exports.PluginHookIds = PluginHookIds.PluginHookIds;
|
|
|
84
85
|
exports.mergeWithDefaults = mergeWithDefaults.mergeWithDefaults;
|
|
85
86
|
exports.mwdef = mergeWithDefaults.mergeWithDefaults;
|
|
86
87
|
exports.getIp = getIp.getIp;
|
|
88
|
+
exports.Send = Send.Send;
|
|
87
89
|
exports.getCallerProjectRoot = ProjectDiscovery.getCallerProjectRoot;
|
|
88
90
|
exports.identifyProjectRoot = ProjectDiscovery.identifyProjectRoot;
|
|
89
91
|
exports.xems = XemsPlugin.xems;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":["configLoader","XyPrissRouter"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":["configLoader","XyPrissRouter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBiF;AACjF;AAEA;AACA;AAqBA;AACA,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;IACnCA,yBAAY,CAAC,qBAAqB,EAAE;AACxC;AA+BA;;AAEG;SACa,MAAM,GAAA;IAClB,OAAO,IAAIC,sBAAa,CAAC;AACrB,QAAA,aAAa,EAAE,KAAK;AACpB,QAAA,WAAW,EAAE,KAAK;AAClB,QAAA,MAAM,EAAE,KAAK;AAChB,KAAA,CAAC;AACN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -40,15 +40,6 @@ class XyServerCreator {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
// 3.5 Configure Environment Security Shield (XESS)
|
|
44
|
-
if (typeof globalThis !== "undefined" &&
|
|
45
|
-
globalThis.__sys__ &&
|
|
46
|
-
globalThis.__sys__.__env__) {
|
|
47
|
-
const xessConfig = options.security?.xess || options.security?.envShield;
|
|
48
|
-
if (xessConfig) {
|
|
49
|
-
globalThis.__sys__.__env__.configureShield(xessConfig);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
43
|
// 4. Update __sys__ with port if provided
|
|
53
44
|
if (options.server?.port &&
|
|
54
45
|
typeof globalThis !== "undefined" &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XyServerCreator.js","sources":["../../../../../src/server/core/XyServerCreator.ts"],"sourcesContent":[null],"names":["configLoader","Logger","Configs","getMimes","handleWorkerMode","XyPrissServer","PluginManager"],"mappings":";;;;;;;;;;AAAA;;;;;AAK6E;AAc7E;;AAEG;MACU,eAAe,CAAA;AACxB;;;;;;AAMG;AACI,IAAA,OAAO,MAAM,CAAC,OAAA,GAAiC,EAAE,EAAA;;QAEpDA,yBAAY,CAAC,qBAAqB,EAAE;;AAGpC,QAAAC,aAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,IAAIC,uBAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;;AAG7D,QAAA,IAAI,OAAO,CAAC,GAAG,EAAE;YACb,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,GAAG;YACrC,IACI,OAAO,UAAU,KAAK,WAAW;gBAChC,UAAkB,CAAC,OAAO,EAC7B;AACG,gBAAA,UAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;oBACpC,OAAO,EAAE,OAAO,CAAC,GAAG;AACvB,iBAAA,CAAC;YACN;QACJ;;
|
|
1
|
+
{"version":3,"file":"XyServerCreator.js","sources":["../../../../../src/server/core/XyServerCreator.ts"],"sourcesContent":[null],"names":["configLoader","Logger","Configs","getMimes","handleWorkerMode","XyPrissServer","PluginManager"],"mappings":";;;;;;;;;;AAAA;;;;;AAK6E;AAc7E;;AAEG;MACU,eAAe,CAAA;AACxB;;;;;;AAMG;AACI,IAAA,OAAO,MAAM,CAAC,OAAA,GAAiC,EAAE,EAAA;;QAEpDA,yBAAY,CAAC,qBAAqB,EAAE;;AAGpC,QAAAC,aAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,IAAIC,uBAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;;AAG7D,QAAA,IAAI,OAAO,CAAC,GAAG,EAAE;YACb,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,OAAO,CA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MAAW,EAAE,MAAY,KAAI;YACrD,OAAO,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACjD,QAAA,CAAC;AAED,QAAA,GAAG,CAAC,SAAS,GAAG,CAAC,IAAY,KAAI;AAC7B,YAAA,OAAO,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC;AACxC,QAAA,CAAC;;AAGD,QAAA,IAAI,OAAO,CAAC,eAAe,EAAE;AACzB,YAAA,GAAG,CAAC,kBAAkB,CAAC,OAAO,CAAC,eAAe,CAAC;QACnD;;;;;AAOA,QAAA,OAAQ,GAAW,CAAC,QAAQ,EAAE;IAClC;AACH;;;;"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Helpers
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
/**
|
|
7
|
+
* Derives a compact, uppercase error code from a {@link SupportedStatus} key.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* buildErrorCode("BAD_REQUEST") // → "EBADR"
|
|
11
|
+
* buildErrorCode("INTERNAL_SERVER_ERR") // → "EINTE"
|
|
12
|
+
*
|
|
13
|
+
* @param status - The status key to convert.
|
|
14
|
+
* @returns A 5-character string starting with `"E"`.
|
|
15
|
+
*/
|
|
16
|
+
function buildErrorCode(status) {
|
|
17
|
+
// Remove all underscores, take first 4 chars, prepend "E"
|
|
18
|
+
return "E" + status.replace(/_/g, "").slice(0, 4).toUpperCase();
|
|
19
|
+
}
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Default HTTP status code registry
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
const DEFAULT_CONFIGS = {
|
|
24
|
+
BAD_REQUEST: 400,
|
|
25
|
+
NOT_FOUND: 404,
|
|
26
|
+
TOO_MANY_REQUEST: 429,
|
|
27
|
+
INTERNAL_SERVER_ERR: 500,
|
|
28
|
+
};
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Send class
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
/**
|
|
33
|
+
* A structured HTTP response helper that standardises all error responses
|
|
34
|
+
* across the application.
|
|
35
|
+
*
|
|
36
|
+
* Every method sends a JSON body conforming to {@link IResTemplate}, ensuring
|
|
37
|
+
* consistent error shapes for API consumers regardless of where the error
|
|
38
|
+
* originates.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const send = new Send(res);
|
|
43
|
+
*
|
|
44
|
+
* // 400 – validation failure
|
|
45
|
+
* send.badRequest("The 'email' field is required.");
|
|
46
|
+
*
|
|
47
|
+
* // 404 – resource missing
|
|
48
|
+
* send.notFound("User not found.", { userId: 42 });
|
|
49
|
+
*
|
|
50
|
+
* // 429 – rate limit exceeded
|
|
51
|
+
* send.tooManyRequest("Too many requests. Please slow down.");
|
|
52
|
+
*
|
|
53
|
+
* // 500 – unexpected failure
|
|
54
|
+
* send.internalError("An unexpected error occurred.");
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
class Send {
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new `Send` instance bound to the given response object.
|
|
60
|
+
*
|
|
61
|
+
* @param res - The active `XyPrisResponse` to write into.
|
|
62
|
+
* @param configs - Optional override for the default status-code registry.
|
|
63
|
+
* Useful for non-standard or custom HTTP codes.
|
|
64
|
+
*/
|
|
65
|
+
constructor(res, configs = {
|
|
66
|
+
includeServerName: true,
|
|
67
|
+
statusCode: {},
|
|
68
|
+
}) {
|
|
69
|
+
// -------------------------------------------------------------------------
|
|
70
|
+
// Public methods
|
|
71
|
+
// -------------------------------------------------------------------------
|
|
72
|
+
/**
|
|
73
|
+
* Sends a **400 Bad Request** response.
|
|
74
|
+
*
|
|
75
|
+
* Use when the client submits a malformed or invalid request
|
|
76
|
+
* (e.g. missing required fields, invalid format, constraint violation).
|
|
77
|
+
*
|
|
78
|
+
* @param message - Human-readable explanation of why the request was rejected.
|
|
79
|
+
* @param data - Optional payload (e.g. a list of validation errors per field).
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* send.badRequest("The 'username' field must be at least 3 characters.");
|
|
83
|
+
* send.badRequest("Validation failed.", { fields: { email: "Invalid format" } });
|
|
84
|
+
*/
|
|
85
|
+
this.badRequest = (message, data) => {
|
|
86
|
+
this.dispatch("BAD_REQUEST", "Bad Request", message, data);
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Sends a **404 Not Found** response.
|
|
90
|
+
*
|
|
91
|
+
* Use when the requested resource does not exist or has been permanently removed.
|
|
92
|
+
*
|
|
93
|
+
* @param message - Human-readable explanation of what could not be found.
|
|
94
|
+
* @param data - Optional payload (e.g. the identifier that was looked up).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* send.notFound("No user found with id '42'.");
|
|
98
|
+
* send.notFound("Resource not found.", { id: "42" });
|
|
99
|
+
*/
|
|
100
|
+
this.notFound = (message, data) => {
|
|
101
|
+
this.dispatch("NOT_FOUND", "Not Found", message, data);
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Sends a **429 Too Many Requests** response.
|
|
105
|
+
*
|
|
106
|
+
* Use when the client has exceeded an allowed request rate or quota.
|
|
107
|
+
* Consider pairing this with a `Retry-After` header at the middleware level.
|
|
108
|
+
*
|
|
109
|
+
* @param message - Human-readable explanation of the rate limit breach.
|
|
110
|
+
* @param data - Optional payload (e.g. retry delay, remaining quota).
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* send.tooManyRequest("Rate limit reached. Try again in 60 seconds.");
|
|
114
|
+
* send.tooManyRequest("Quota exceeded.", { retryAfter: 60 });
|
|
115
|
+
*/
|
|
116
|
+
this.tooManyRequest = (message, data) => {
|
|
117
|
+
this.dispatch("TOO_MANY_REQUEST", "Too Many Requests", message, data);
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Sends a **500 Internal Server Error** response.
|
|
121
|
+
*
|
|
122
|
+
* Use for unexpected, unhandled server-side failures.
|
|
123
|
+
* Avoid leaking internal stack traces or sensitive details in the message.
|
|
124
|
+
*
|
|
125
|
+
* @param message - Human-readable explanation safe to expose to the client.
|
|
126
|
+
* @param data - Optional payload (use sparingly — never expose raw stack traces).
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* send.internalError("An unexpected error occurred. Please try again later.");
|
|
130
|
+
*/
|
|
131
|
+
this.internalError = (message, data) => {
|
|
132
|
+
this.dispatch("INTERNAL_SERVER_ERR", "Internal Server Error", message, data);
|
|
133
|
+
};
|
|
134
|
+
this.res = res;
|
|
135
|
+
this.configs = { ...DEFAULT_CONFIGS, ...configs.statusCode };
|
|
136
|
+
this.serverName = __sys__.vars.__name__;
|
|
137
|
+
this.includeServerName = configs?.includeServerName;
|
|
138
|
+
}
|
|
139
|
+
// -------------------------------------------------------------------------
|
|
140
|
+
// Core dispatcher
|
|
141
|
+
// -------------------------------------------------------------------------
|
|
142
|
+
/**
|
|
143
|
+
* Resolves the status code, builds the full response body, and flushes it.
|
|
144
|
+
*
|
|
145
|
+
* @param statusKey - One of the {@link SupportedStatus} keys.
|
|
146
|
+
* @param errorLabel - Human-readable short label for the error type.
|
|
147
|
+
* @param message - Optional caller-supplied message; falls back to `errorLabel`.
|
|
148
|
+
* @param data - Optional payload to attach to the response body.
|
|
149
|
+
*/
|
|
150
|
+
dispatch(statusKey, errorLabel, message, data) {
|
|
151
|
+
const statusCode = this.configs[statusKey];
|
|
152
|
+
const body = {
|
|
153
|
+
success: false,
|
|
154
|
+
message: message ?? errorLabel,
|
|
155
|
+
serverName: this.includeServerName
|
|
156
|
+
? this.serverName
|
|
157
|
+
: undefined,
|
|
158
|
+
...(data !== undefined && { data }),
|
|
159
|
+
details: {
|
|
160
|
+
error: errorLabel,
|
|
161
|
+
errorCode: buildErrorCode(statusKey),
|
|
162
|
+
statusCode,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
this.res.status(statusCode).json(body);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
exports.Send = Send;
|
|
170
|
+
//# sourceMappingURL=Send.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Send.js","sources":["../../../../src/utils/Send.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAsFA;AACA;AACA;AAEA;;;;;;;;;AASG;AACH,SAAS,cAAc,CAAC,MAAuB,EAAA;;IAE7C,OAAO,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE;AACjE;AAEA;AACA;AACA;AAEA,MAAM,eAAe,GAAe;AAClC,IAAA,WAAW,EAAE,GAAG;AAChB,IAAA,SAAS,EAAE,GAAG;AACd,IAAA,gBAAgB,EAAE,GAAG;AACrB,IAAA,mBAAmB,EAAE,GAAG;CACzB;AAED;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;MACU,IAAI,CAAA;AAMf;;;;;;AAMG;IACH,WAAA,CACE,GAAmB,EACnB,OAAA,GAGK;AACH,QAAA,iBAAiB,EAAE,IAAI;AACvB,QAAA,UAAU,EAAE,EAAE;AACf,KAAA,EAAA;;;;AAiDH;;;;;;;;;;;;AAYG;AACI,QAAA,IAAA,CAAA,UAAU,GAAiB,CAAC,OAAO,EAAE,IAAI,KAAI;YAClD,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC;AAC5D,QAAA,CAAC;AAED;;;;;;;;;;;AAWG;AACI,QAAA,IAAA,CAAA,QAAQ,GAAiB,CAAC,OAAO,EAAE,IAAI,KAAI;YAChD,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC;AACxD,QAAA,CAAC;AAED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I,CAAC;IACxC;AA4ED;;;;"}
|
package/dist/cjs/src/xhsc.js
CHANGED
|
@@ -4,6 +4,7 @@ var fs = require('fs');
|
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var System = require('./xhsc/System.js');
|
|
6
6
|
var DotEnvLoader = require('./utils/DotEnvLoader.js');
|
|
7
|
+
var JsonUtils = require('./utils/JsonUtils.js');
|
|
7
8
|
var env = require('./xhsc/api/env/env.js');
|
|
8
9
|
var ProjectDiscovery = require('./utils/ProjectDiscovery.js');
|
|
9
10
|
var Logger = require('./shared/logger/Logger.js');
|
|
@@ -215,9 +216,26 @@ if (typeof globalThis !== "undefined") {
|
|
|
215
216
|
}
|
|
216
217
|
// Initialize the Symbol-keyed secure store as a Map of project environments
|
|
217
218
|
globalThis[env.XY_ENV_STORE_KEY] = projectEnvs;
|
|
218
|
-
// Use the primary project root's environment for system defaults
|
|
219
219
|
const primaryEnv = projectEnvs.get(foundRoot) || {};
|
|
220
220
|
const defaultPort = parseInt(primaryEnv["PORT"] || "3000");
|
|
221
|
+
// Read xypriss.config.jsonc or xypriss.config.json early to apply XESS configuration declaratively
|
|
222
|
+
let earlyXessConfig = null;
|
|
223
|
+
try {
|
|
224
|
+
for (const name of ["xypriss.config.jsonc", "xypriss.config.json"]) {
|
|
225
|
+
const potentialConfig = path.join(foundRoot, name);
|
|
226
|
+
if (fs.existsSync(potentialConfig)) {
|
|
227
|
+
const rawContent = fs.readFileSync(potentialConfig, "utf8");
|
|
228
|
+
const config = JsonUtils.JsonUtils.parse(rawContent);
|
|
229
|
+
if (config?.$env) {
|
|
230
|
+
earlyXessConfig = config.$env;
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
// Silently fallback on parse error
|
|
238
|
+
}
|
|
221
239
|
if (!globalThis.__sys__) {
|
|
222
240
|
const sysInstance = new XyPrissXHSC({
|
|
223
241
|
__root__: foundRoot,
|
|
@@ -225,6 +243,10 @@ if (typeof globalThis !== "undefined") {
|
|
|
225
243
|
__PORT__: defaultPort,
|
|
226
244
|
__mode__: primaryEnv["NODE_ENV"] || "development",
|
|
227
245
|
});
|
|
246
|
+
// Apply declarative XESS early configuration if found
|
|
247
|
+
if (earlyXessConfig && sysInstance.__env__) {
|
|
248
|
+
sysInstance.__env__.configureShield(earlyXessConfig);
|
|
249
|
+
}
|
|
228
250
|
// ==========================================
|
|
229
251
|
// ENTERPRISE IMMUTABILITY SHIELD (V2)
|
|
230
252
|
// ==========================================
|
package/dist/cjs/src/xhsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xhsc.js","sources":["../../../src/xhsc.ts"],"sourcesContent":[null],"names":["XyPrissFS","XY_XHSC_REGISTER_FS","getCallerProjectRoot","isProjectRoot","logger","generateXUserTmpDir","loadXyConfig","DotEnvLoader","XY_ENV_STORE_KEY","createSecurityShield"],"mappings":"
|
|
1
|
+
{"version":3,"file":"xhsc.js","sources":["../../../src/xhsc.ts"],"sourcesContent":[null],"names":["XyPrissFS","XY_XHSC_REGISTER_FS","getCallerProjectRoot","isProjectRoot","logger","generateXUserTmpDir","loadXyConfig","DotEnvLoader","XY_ENV_STORE_KEY","JsonUtils","createSecurityShield"],"mappings":";;;;;;;;;;;;;AAoBA;;;;;;;;;;;AAWG;AACG,MAAO,WAAY,SAAQA,gBAAS,CAAA;AAO/B,IAAA,CAACC,uBAAmB,CAAC,CAAC,QAAgB,EAAE,QAAmB,EAAA;QAC9D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC3C;AAEA,IAAA,IAAoB,QAAQ,GAAA;AACxB,QAAA,OAAOC,qCAAoB,EAAE,IAAI,IAAI,CAAC,aAAa;IACvD;AACA,IAAA,WAAA,CAAY,OAA4B,EAAE,EAAA;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,E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;AAClB,YAAA,QAAQ,EAAE,KAAK;AACf,YAAA,UAAU,EAAE,IAAI;AAChB,YAAA,YAAY,EAAE,KAAK;AACtB,SAAA,CAAC;IACN;AACJ;AAEA;AACO,MAAM,OAAO,GAAI,UAAkB,CAAC;;;;;;"}
|
package/dist/esm/src/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export { XyGuard } from './server/routing/modules/XyGuard.js';
|
|
|
14
14
|
export { PluginHookIds } from './plugins/const/PluginHookIds.js';
|
|
15
15
|
export { mergeWithDefaults, mergeWithDefaults as mwdef } from './utils/mergeWithDefaults.js';
|
|
16
16
|
export { getIp } from './utils/getIp.js';
|
|
17
|
+
export { Send } from './utils/Send.js';
|
|
17
18
|
export { getCallerProjectRoot, identifyProjectRoot } from './utils/ProjectDiscovery.js';
|
|
18
19
|
export { xems } from './plugins/builtin/xems/XemsPlugin.js';
|
|
19
20
|
export { getMime, getMimes } from './utils/getMime.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBiF;AACjF;AAEA;AACA;AAqBA;AACA,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;IACnC,YAAY,CAAC,qBAAqB,EAAE;AACxC;AA+BA;;AAEG;SACa,MAAM,GAAA;IAClB,OAAO,IAAI,aAAa,CAAC;AACrB,QAAA,aAAa,EAAE,KAAK;AACpB,QAAA,WAAW,EAAE,KAAK;AAClB,QAAA,MAAM,EAAE,KAAK;AAChB,KAAA,CAAC;AACN;;;;"}
|
|
@@ -38,15 +38,6 @@ class XyServerCreator {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
// 3.5 Configure Environment Security Shield (XESS)
|
|
42
|
-
if (typeof globalThis !== "undefined" &&
|
|
43
|
-
globalThis.__sys__ &&
|
|
44
|
-
globalThis.__sys__.__env__) {
|
|
45
|
-
const xessConfig = options.security?.xess || options.security?.envShield;
|
|
46
|
-
if (xessConfig) {
|
|
47
|
-
globalThis.__sys__.__env__.configureShield(xessConfig);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
41
|
// 4. Update __sys__ with port if provided
|
|
51
42
|
if (options.server?.port &&
|
|
52
43
|
typeof globalThis !== "undefined" &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XyServerCreator.js","sources":["../../../../../src/server/core/XyServerCreator.ts"],"sourcesContent":[null],"names":["Configs","PluginManager"],"mappings":";;;;;;;;AAAA;;;;;AAK6E;AAc7E;;AAEG;MACU,eAAe,CAAA;AACxB;;;;;;AAMG;AACI,IAAA,OAAO,MAAM,CAAC,OAAA,GAAiC,EAAE,EAAA;;QAEpD,YAAY,CAAC,qBAAqB,EAAE;;AAGpC,QAAA,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,IAAIA,oBAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;;AAG7D,QAAA,IAAI,OAAO,CAAC,GAAG,EAAE;YACb,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,GAAG;YACrC,IACI,OAAO,UAAU,KAAK,WAAW;gBAChC,UAAkB,CAAC,OAAO,EAC7B;AACG,gBAAA,UAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;oBACpC,OAAO,EAAE,OAAO,CAAC,GAAG;AACvB,iBAAA,CAAC;YACN;QACJ;;
|
|
1
|
+
{"version":3,"file":"XyServerCreator.js","sources":["../../../../../src/server/core/XyServerCreator.ts"],"sourcesContent":[null],"names":["Configs","PluginManager"],"mappings":";;;;;;;;AAAA;;;;;AAK6E;AAc7E;;AAEG;MACU,eAAe,CAAA;AACxB;;;;;;AAMG;AACI,IAAA,OAAO,MAAM,CA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AK,CAAC,OAAO,CAAA,CAAE,EAChD,KAAK,CACR;AACD,gBAAA,MAAM,KAAK;YACf;QACJ,CAAC,GAAG;;AAGH,QAAA,GAAW,CAAC,aAAa,GAAG,aAAa;AACzC,QAAA,GAAW,CAAC,eAAe,GAAG,aAAa;AAC3C,QAAA,GAAW,CAAC,iBAAiB,GAAG,iBAAiB;QAElD,GAAG,CAAC,cAAc,GAAG,OAAO,MAAW,EAAE,MAAY,KAAI;YACrD,OAAO,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACjD,QAAA,CAAC;AAED,QAAA,GAAG,CAAC,SAAS,GAAG,CAAC,IAAY,KAAI;AAC7B,YAAA,OAAO,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC;AACxC,QAAA,CAAC;;AAGD,QAAA,IAAI,OAAO,CAAC,eAAe,EAAE;AACzB,YAAA,GAAG,CAAC,kBAAkB,CAAC,OAAO,CAAC,eAAe,CAAC;QACnD;;;;;AAOA,QAAA,OAAQ,GAAW,CAAC,QAAQ,EAAE;IAClC;AACH;;;;"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Helpers
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
/**
|
|
5
|
+
* Derives a compact, uppercase error code from a {@link SupportedStatus} key.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* buildErrorCode("BAD_REQUEST") // → "EBADR"
|
|
9
|
+
* buildErrorCode("INTERNAL_SERVER_ERR") // → "EINTE"
|
|
10
|
+
*
|
|
11
|
+
* @param status - The status key to convert.
|
|
12
|
+
* @returns A 5-character string starting with `"E"`.
|
|
13
|
+
*/
|
|
14
|
+
function buildErrorCode(status) {
|
|
15
|
+
// Remove all underscores, take first 4 chars, prepend "E"
|
|
16
|
+
return "E" + status.replace(/_/g, "").slice(0, 4).toUpperCase();
|
|
17
|
+
}
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// Default HTTP status code registry
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
const DEFAULT_CONFIGS = {
|
|
22
|
+
BAD_REQUEST: 400,
|
|
23
|
+
NOT_FOUND: 404,
|
|
24
|
+
TOO_MANY_REQUEST: 429,
|
|
25
|
+
INTERNAL_SERVER_ERR: 500,
|
|
26
|
+
};
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Send class
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
/**
|
|
31
|
+
* A structured HTTP response helper that standardises all error responses
|
|
32
|
+
* across the application.
|
|
33
|
+
*
|
|
34
|
+
* Every method sends a JSON body conforming to {@link IResTemplate}, ensuring
|
|
35
|
+
* consistent error shapes for API consumers regardless of where the error
|
|
36
|
+
* originates.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const send = new Send(res);
|
|
41
|
+
*
|
|
42
|
+
* // 400 – validation failure
|
|
43
|
+
* send.badRequest("The 'email' field is required.");
|
|
44
|
+
*
|
|
45
|
+
* // 404 – resource missing
|
|
46
|
+
* send.notFound("User not found.", { userId: 42 });
|
|
47
|
+
*
|
|
48
|
+
* // 429 – rate limit exceeded
|
|
49
|
+
* send.tooManyRequest("Too many requests. Please slow down.");
|
|
50
|
+
*
|
|
51
|
+
* // 500 – unexpected failure
|
|
52
|
+
* send.internalError("An unexpected error occurred.");
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
class Send {
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new `Send` instance bound to the given response object.
|
|
58
|
+
*
|
|
59
|
+
* @param res - The active `XyPrisResponse` to write into.
|
|
60
|
+
* @param configs - Optional override for the default status-code registry.
|
|
61
|
+
* Useful for non-standard or custom HTTP codes.
|
|
62
|
+
*/
|
|
63
|
+
constructor(res, configs = {
|
|
64
|
+
includeServerName: true,
|
|
65
|
+
statusCode: {},
|
|
66
|
+
}) {
|
|
67
|
+
// -------------------------------------------------------------------------
|
|
68
|
+
// Public methods
|
|
69
|
+
// -------------------------------------------------------------------------
|
|
70
|
+
/**
|
|
71
|
+
* Sends a **400 Bad Request** response.
|
|
72
|
+
*
|
|
73
|
+
* Use when the client submits a malformed or invalid request
|
|
74
|
+
* (e.g. missing required fields, invalid format, constraint violation).
|
|
75
|
+
*
|
|
76
|
+
* @param message - Human-readable explanation of why the request was rejected.
|
|
77
|
+
* @param data - Optional payload (e.g. a list of validation errors per field).
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* send.badRequest("The 'username' field must be at least 3 characters.");
|
|
81
|
+
* send.badRequest("Validation failed.", { fields: { email: "Invalid format" } });
|
|
82
|
+
*/
|
|
83
|
+
this.badRequest = (message, data) => {
|
|
84
|
+
this.dispatch("BAD_REQUEST", "Bad Request", message, data);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Sends a **404 Not Found** response.
|
|
88
|
+
*
|
|
89
|
+
* Use when the requested resource does not exist or has been permanently removed.
|
|
90
|
+
*
|
|
91
|
+
* @param message - Human-readable explanation of what could not be found.
|
|
92
|
+
* @param data - Optional payload (e.g. the identifier that was looked up).
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* send.notFound("No user found with id '42'.");
|
|
96
|
+
* send.notFound("Resource not found.", { id: "42" });
|
|
97
|
+
*/
|
|
98
|
+
this.notFound = (message, data) => {
|
|
99
|
+
this.dispatch("NOT_FOUND", "Not Found", message, data);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Sends a **429 Too Many Requests** response.
|
|
103
|
+
*
|
|
104
|
+
* Use when the client has exceeded an allowed request rate or quota.
|
|
105
|
+
* Consider pairing this with a `Retry-After` header at the middleware level.
|
|
106
|
+
*
|
|
107
|
+
* @param message - Human-readable explanation of the rate limit breach.
|
|
108
|
+
* @param data - Optional payload (e.g. retry delay, remaining quota).
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* send.tooManyRequest("Rate limit reached. Try again in 60 seconds.");
|
|
112
|
+
* send.tooManyRequest("Quota exceeded.", { retryAfter: 60 });
|
|
113
|
+
*/
|
|
114
|
+
this.tooManyRequest = (message, data) => {
|
|
115
|
+
this.dispatch("TOO_MANY_REQUEST", "Too Many Requests", message, data);
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Sends a **500 Internal Server Error** response.
|
|
119
|
+
*
|
|
120
|
+
* Use for unexpected, unhandled server-side failures.
|
|
121
|
+
* Avoid leaking internal stack traces or sensitive details in the message.
|
|
122
|
+
*
|
|
123
|
+
* @param message - Human-readable explanation safe to expose to the client.
|
|
124
|
+
* @param data - Optional payload (use sparingly — never expose raw stack traces).
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* send.internalError("An unexpected error occurred. Please try again later.");
|
|
128
|
+
*/
|
|
129
|
+
this.internalError = (message, data) => {
|
|
130
|
+
this.dispatch("INTERNAL_SERVER_ERR", "Internal Server Error", message, data);
|
|
131
|
+
};
|
|
132
|
+
this.res = res;
|
|
133
|
+
this.configs = { ...DEFAULT_CONFIGS, ...configs.statusCode };
|
|
134
|
+
this.serverName = __sys__.vars.__name__;
|
|
135
|
+
this.includeServerName = configs?.includeServerName;
|
|
136
|
+
}
|
|
137
|
+
// -------------------------------------------------------------------------
|
|
138
|
+
// Core dispatcher
|
|
139
|
+
// -------------------------------------------------------------------------
|
|
140
|
+
/**
|
|
141
|
+
* Resolves the status code, builds the full response body, and flushes it.
|
|
142
|
+
*
|
|
143
|
+
* @param statusKey - One of the {@link SupportedStatus} keys.
|
|
144
|
+
* @param errorLabel - Human-readable short label for the error type.
|
|
145
|
+
* @param message - Optional caller-supplied message; falls back to `errorLabel`.
|
|
146
|
+
* @param data - Optional payload to attach to the response body.
|
|
147
|
+
*/
|
|
148
|
+
dispatch(statusKey, errorLabel, message, data) {
|
|
149
|
+
const statusCode = this.configs[statusKey];
|
|
150
|
+
const body = {
|
|
151
|
+
success: false,
|
|
152
|
+
message: message ?? errorLabel,
|
|
153
|
+
serverName: this.includeServerName
|
|
154
|
+
? this.serverName
|
|
155
|
+
: undefined,
|
|
156
|
+
...(data !== undefined && { data }),
|
|
157
|
+
details: {
|
|
158
|
+
error: errorLabel,
|
|
159
|
+
errorCode: buildErrorCode(statusKey),
|
|
160
|
+
statusCode,
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
this.res.status(statusCode).json(body);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { Send };
|
|
168
|
+
//# sourceMappingURL=Send.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Send.js","sources":["../../../../src/utils/Send.ts"],"sourcesContent":[null],"names":[],"mappings":"AAsFA;AACA;AACA;AAEA;;;;;;;;;AASG;AACH,SAAS,cAAc,CAAC,MAAuB,EAAA;;IAE7C,OAAO,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE;AACjE;AAEA;AACA;AACA;AAEA,MAAM,eAAe,GAAe;AAClC,IAAA,WAAW,EAAE,GAAG;AAChB,IAAA,SAAS,EAAE,GAAG;AACd,IAAA,gBAAgB,EAAE,GAAG;AACrB,IAAA,mBAAmB,EAAE,GAAG;CACzB;AAED;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;MACU,IAAI,CAAA;AAMf;;;;;;AAMG;IACH,WAAA,CACE,GAAmB,EACnB,OAAA,GAGK;AACH,QAAA,iBAAiB,EAAE,IAAI;AACvB,QAAA,UAAU,EAAE,EAAE;AACf,KAAA,EAAA;;;;AAiDH;;;;;;;;;;;;AAYG;AACI,QAAA,IAAA,CAAA,UAAU,GAAiB,CAAC,OAAO,EAAE,IAAI,KAAI;YAClD,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE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AAE,CAAC;AACnC,YAAA,OAAO,EAAE;AACP,gBAAA,KAAK,EAAE,UAAU;AACjB,gBAAA,SAAS,EAAE,cAAc,CAAC,SAAS,CAAC;gBACpC,UAAU;AACX,aAAA;SACF;AAED,QAAA,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACxC;AA4ED;;;;"}
|
package/dist/esm/src/xhsc.js
CHANGED
|
@@ -2,6 +2,7 @@ import fs__default from 'fs';
|
|
|
2
2
|
import path__default from 'path';
|
|
3
3
|
import { XyPrissFS } from './xhsc/System.js';
|
|
4
4
|
import { DotEnvLoader } from './utils/DotEnvLoader.js';
|
|
5
|
+
import { JsonUtils } from './utils/JsonUtils.js';
|
|
5
6
|
import { XY_ENV_STORE_KEY, XY_XHSC_REGISTER_FS } from './xhsc/api/env/env.js';
|
|
6
7
|
import { isProjectRoot, getCallerProjectRoot, loadXyConfig } from './utils/ProjectDiscovery.js';
|
|
7
8
|
import { logger } from './shared/logger/Logger.js';
|
|
@@ -213,9 +214,26 @@ if (typeof globalThis !== "undefined") {
|
|
|
213
214
|
}
|
|
214
215
|
// Initialize the Symbol-keyed secure store as a Map of project environments
|
|
215
216
|
globalThis[XY_ENV_STORE_KEY] = projectEnvs;
|
|
216
|
-
// Use the primary project root's environment for system defaults
|
|
217
217
|
const primaryEnv = projectEnvs.get(foundRoot) || {};
|
|
218
218
|
const defaultPort = parseInt(primaryEnv["PORT"] || "3000");
|
|
219
|
+
// Read xypriss.config.jsonc or xypriss.config.json early to apply XESS configuration declaratively
|
|
220
|
+
let earlyXessConfig = null;
|
|
221
|
+
try {
|
|
222
|
+
for (const name of ["xypriss.config.jsonc", "xypriss.config.json"]) {
|
|
223
|
+
const potentialConfig = path__default.join(foundRoot, name);
|
|
224
|
+
if (fs__default.existsSync(potentialConfig)) {
|
|
225
|
+
const rawContent = fs__default.readFileSync(potentialConfig, "utf8");
|
|
226
|
+
const config = JsonUtils.parse(rawContent);
|
|
227
|
+
if (config?.$env) {
|
|
228
|
+
earlyXessConfig = config.$env;
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
// Silently fallback on parse error
|
|
236
|
+
}
|
|
219
237
|
if (!globalThis.__sys__) {
|
|
220
238
|
const sysInstance = new XyPrissXHSC({
|
|
221
239
|
__root__: foundRoot,
|
|
@@ -223,6 +241,10 @@ if (typeof globalThis !== "undefined") {
|
|
|
223
241
|
__PORT__: defaultPort,
|
|
224
242
|
__mode__: primaryEnv["NODE_ENV"] || "development",
|
|
225
243
|
});
|
|
244
|
+
// Apply declarative XESS early configuration if found
|
|
245
|
+
if (earlyXessConfig && sysInstance.__env__) {
|
|
246
|
+
sysInstance.__env__.configureShield(earlyXessConfig);
|
|
247
|
+
}
|
|
226
248
|
// ==========================================
|
|
227
249
|
// ENTERPRISE IMMUTABILITY SHIELD (V2)
|
|
228
250
|
// ==========================================
|
package/dist/esm/src/xhsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xhsc.js","sources":["../../../src/xhsc.ts"],"sourcesContent":[null],"names":["fs","path"],"mappings":"
|
|
1
|
+
{"version":3,"file":"xhsc.js","sources":["../../../src/xhsc.ts"],"sourcesContent":[null],"names":["fs","path"],"mappings":";;;;;;;;;;;AAoBA;;;;;;;;;;;AAWG;AACG,MAAO,WAAY,SAAQ,SAAS,CAAA;AAO/B,IAAA,CAAC,mBAAmB,CAAC,CAAC,QAAgB,EAAE,QAAmB,EAAA;QAC9D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC3C;AAEA,IAAA,IAAoB,QAAQ,GAAA;AACxB,QAAA,OAAO,oBAAoB,EAAE,IAAI,IAAI,CAAC,aAAa;IACvD;AACA,IAAA,WAAA,CAAY,OAA4B,EAAE,EAAA;QACtC,MAAM,IAAI,GA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EAAE,SAAS,EAAE;AACzC,YAAA,KAAK,EAAE,WAAW;AAClB,YAAA,QAAQ,EAAE,KAAK;AACf,YAAA,UAAU,EAAE,IAAI;AAChB,YAAA,YAAY,EAAE,KAAK;AACtB,SAAA,CAAC;IACN;AACJ;AAEA;AACO,MAAM,OAAO,GAAI,UAAkB,CAAC;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Server, IncomingMessage, ServerResponse } from 'http';
|
|
|
2
2
|
import { SecureCacheAdapter } from 'xypriss-security';
|
|
3
3
|
import * as reliant_type from 'reliant-type';
|
|
4
4
|
import { Readable, Writable } from 'node:stream';
|
|
5
|
+
import { XyPrisResponse as XyPrisResponse$2 } from 'xypriss';
|
|
5
6
|
|
|
6
7
|
declare const LOG_LEVELS: readonly ["silent", "error", "warn", "info", "debug", "verbose"];
|
|
7
8
|
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
@@ -1524,50 +1525,6 @@ interface SecurityModuleRouteConfig {
|
|
|
1524
1525
|
/** Routes to include for this security module (if specified, only these routes will be protected) */
|
|
1525
1526
|
includeRoutes?: (string | RegExp | RoutePattern)[];
|
|
1526
1527
|
}
|
|
1527
|
-
/**
|
|
1528
|
-
* Security Configuration Interface
|
|
1529
|
-
*
|
|
1530
|
-
* Defines comprehensive security settings for XyPriss applications.
|
|
1531
|
-
* Each security feature can be enabled/disabled or configured with detailed options.
|
|
1532
|
-
*
|
|
1533
|
-
* @example
|
|
1534
|
-
* ```typescript
|
|
1535
|
-
* const securityConfig: SecurityConfig = {
|
|
1536
|
-
* level: 'enhanced',
|
|
1537
|
-
* helmet: {
|
|
1538
|
-
* contentSecurityPolicy: {
|
|
1539
|
-
* directives: { defaultSrc: ["'self'"] }
|
|
1540
|
-
* }
|
|
1541
|
-
* },
|
|
1542
|
-
* cors: {
|
|
1543
|
-
* origin: 'https://myapp.com',
|
|
1544
|
-
* credentials: true
|
|
1545
|
-
* },
|
|
1546
|
-
* bruteForce: {
|
|
1547
|
-
* windowMs: 15 * 60 * 1000,
|
|
1548
|
-
* max: 100
|
|
1549
|
-
* },
|
|
1550
|
-
* routeConfig: {
|
|
1551
|
-
* pathTraversal: {
|
|
1552
|
-
* excludeRoutes: ['/api/templates/*', '/api/content/*']
|
|
1553
|
-
* }
|
|
1554
|
-
* }
|
|
1555
|
-
* };
|
|
1556
|
-
* ```
|
|
1557
|
-
*/
|
|
1558
|
-
interface XessConfig {
|
|
1559
|
-
/**
|
|
1560
|
-
* Custom list of environment variable keys allowed to bypass the shield.
|
|
1561
|
-
* This will extend or override the default system whitelist.
|
|
1562
|
-
*/
|
|
1563
|
-
whitelist?: string[];
|
|
1564
|
-
/**
|
|
1565
|
-
* If true, the custom whitelist will completely replace the built-in system whitelist.
|
|
1566
|
-
* If false, the custom whitelist will merge with (extend) the built-in system whitelist.
|
|
1567
|
-
* @default false
|
|
1568
|
-
*/
|
|
1569
|
-
replaceDefaultWhitelist?: boolean;
|
|
1570
|
-
}
|
|
1571
1528
|
interface SecurityConfig {
|
|
1572
1529
|
/**
|
|
1573
1530
|
* Strategic route bypass configuration.
|
|
@@ -2067,16 +2024,6 @@ interface SecurityConfig {
|
|
|
2067
2024
|
* ```
|
|
2068
2025
|
*/
|
|
2069
2026
|
requestSignature?: boolean | RequestSignatureConfig;
|
|
2070
|
-
/**
|
|
2071
|
-
* XyPriss Environment Security Shield (XESS) Configuration.
|
|
2072
|
-
* Hardens process.env access to protect system stability and prevent secrets leaks.
|
|
2073
|
-
*/
|
|
2074
|
-
xess?: XessConfig;
|
|
2075
|
-
/**
|
|
2076
|
-
* Environment Security Shield (XESS) Configuration.
|
|
2077
|
-
* Alias for `xess`.
|
|
2078
|
-
*/
|
|
2079
|
-
envShield?: XessConfig;
|
|
2080
2027
|
}
|
|
2081
2028
|
/**
|
|
2082
2029
|
* Encryption configuration interface.
|
|
@@ -11196,6 +11143,176 @@ type IpSource = "cf-connecting-ip" | "true-client-ip" | "x-real-ip" | "x-forward
|
|
|
11196
11143
|
declare function getIp(req: XyPrisRequest): string;
|
|
11197
11144
|
declare function getIp(req: XyPrisRequest, enriched: true): GetIpResult;
|
|
11198
11145
|
|
|
11146
|
+
/**
|
|
11147
|
+
* @file Send.ts
|
|
11148
|
+
* @description Structured HTTP error response helper for the XyPriss framework.
|
|
11149
|
+
*
|
|
11150
|
+
* @copyright Copyright © 2025–2026 NEHONIX. All Rights Reserved.
|
|
11151
|
+
* @license NEHONIX Open Source License v2.0 (NOSL v2)
|
|
11152
|
+
* https://dll.nehonix.com/licenses/NOSL/v2
|
|
11153
|
+
*
|
|
11154
|
+
* This file is part of a NEHONIX open source project.
|
|
11155
|
+
* You may use, modify, and redistribute it freely — including for commercial
|
|
11156
|
+
* purposes — provided that NEHONIX is always credited as the original author.
|
|
11157
|
+
*
|
|
11158
|
+
* @author NEHONIX
|
|
11159
|
+
*/
|
|
11160
|
+
|
|
11161
|
+
/**
|
|
11162
|
+
* All HTTP status keys supported by the `Send` helper.
|
|
11163
|
+
* Each key maps to a standard HTTP status code.
|
|
11164
|
+
*/
|
|
11165
|
+
type SupportedStatus = "BAD_REQUEST" | "NOT_FOUND" | "TOO_MANY_REQUEST" | "INTERNAL_SERVER_ERR";
|
|
11166
|
+
/**
|
|
11167
|
+
* Maps every {@link SupportedStatus} key to its corresponding HTTP status code.
|
|
11168
|
+
*/
|
|
11169
|
+
type ISeConfigs = Record<SupportedStatus, number>;
|
|
11170
|
+
/**
|
|
11171
|
+
* Signature shared by all public error-dispatch methods.
|
|
11172
|
+
*
|
|
11173
|
+
* @param message - Human-readable description of the error shown to the API consumer.
|
|
11174
|
+
* @param data - Optional payload to attach to the response body (e.g. validation details).
|
|
11175
|
+
*/
|
|
11176
|
+
type TSendPropsFn = (message?: string, data?: unknown) => void;
|
|
11177
|
+
/**
|
|
11178
|
+
* Contract that the {@link Send} class must satisfy.
|
|
11179
|
+
* Ensures every supported error type exposes a consistent public API.
|
|
11180
|
+
*/
|
|
11181
|
+
interface ISeResponder {
|
|
11182
|
+
badRequest: TSendPropsFn;
|
|
11183
|
+
notFound: TSendPropsFn;
|
|
11184
|
+
tooManyRequest: TSendPropsFn;
|
|
11185
|
+
internalError: TSendPropsFn;
|
|
11186
|
+
}
|
|
11187
|
+
/**
|
|
11188
|
+
* Shape of every JSON response body produced by this helper.
|
|
11189
|
+
*
|
|
11190
|
+
* @property success - Always `false` for error responses.
|
|
11191
|
+
* @property message - Human-readable summary of the error.
|
|
11192
|
+
* @property serverName - Identifier of the server that handled the request.
|
|
11193
|
+
* @property data - Optional payload (echoed from the caller when relevant).
|
|
11194
|
+
* @property details - Machine-readable error metadata.
|
|
11195
|
+
*/
|
|
11196
|
+
interface IResTemplate {
|
|
11197
|
+
success: false;
|
|
11198
|
+
message: string;
|
|
11199
|
+
serverName: string;
|
|
11200
|
+
data?: unknown;
|
|
11201
|
+
details: {
|
|
11202
|
+
/** Short error label (e.g. `"Bad Request"`). */
|
|
11203
|
+
error: string;
|
|
11204
|
+
/** Compact error code derived from the status key (e.g. `"EBADR"`). */
|
|
11205
|
+
errorCode: string;
|
|
11206
|
+
/** The HTTP status code that was sent. */
|
|
11207
|
+
statusCode: number;
|
|
11208
|
+
};
|
|
11209
|
+
}
|
|
11210
|
+
/**
|
|
11211
|
+
* A structured HTTP response helper that standardises all error responses
|
|
11212
|
+
* across the application.
|
|
11213
|
+
*
|
|
11214
|
+
* Every method sends a JSON body conforming to {@link IResTemplate}, ensuring
|
|
11215
|
+
* consistent error shapes for API consumers regardless of where the error
|
|
11216
|
+
* originates.
|
|
11217
|
+
*
|
|
11218
|
+
* @example
|
|
11219
|
+
* ```ts
|
|
11220
|
+
* const send = new Send(res);
|
|
11221
|
+
*
|
|
11222
|
+
* // 400 – validation failure
|
|
11223
|
+
* send.badRequest("The 'email' field is required.");
|
|
11224
|
+
*
|
|
11225
|
+
* // 404 – resource missing
|
|
11226
|
+
* send.notFound("User not found.", { userId: 42 });
|
|
11227
|
+
*
|
|
11228
|
+
* // 429 – rate limit exceeded
|
|
11229
|
+
* send.tooManyRequest("Too many requests. Please slow down.");
|
|
11230
|
+
*
|
|
11231
|
+
* // 500 – unexpected failure
|
|
11232
|
+
* send.internalError("An unexpected error occurred.");
|
|
11233
|
+
* ```
|
|
11234
|
+
*/
|
|
11235
|
+
declare class Send implements ISeResponder {
|
|
11236
|
+
private readonly res;
|
|
11237
|
+
private readonly configs;
|
|
11238
|
+
private readonly serverName;
|
|
11239
|
+
private readonly includeServerName;
|
|
11240
|
+
/**
|
|
11241
|
+
* Creates a new `Send` instance bound to the given response object.
|
|
11242
|
+
*
|
|
11243
|
+
* @param res - The active `XyPrisResponse` to write into.
|
|
11244
|
+
* @param configs - Optional override for the default status-code registry.
|
|
11245
|
+
* Useful for non-standard or custom HTTP codes.
|
|
11246
|
+
*/
|
|
11247
|
+
constructor(res: XyPrisResponse$2, configs?: Partial<{
|
|
11248
|
+
statusCode: Partial<ISeConfigs>;
|
|
11249
|
+
includeServerName: boolean;
|
|
11250
|
+
}>);
|
|
11251
|
+
/**
|
|
11252
|
+
* Resolves the status code, builds the full response body, and flushes it.
|
|
11253
|
+
*
|
|
11254
|
+
* @param statusKey - One of the {@link SupportedStatus} keys.
|
|
11255
|
+
* @param errorLabel - Human-readable short label for the error type.
|
|
11256
|
+
* @param message - Optional caller-supplied message; falls back to `errorLabel`.
|
|
11257
|
+
* @param data - Optional payload to attach to the response body.
|
|
11258
|
+
*/
|
|
11259
|
+
private dispatch;
|
|
11260
|
+
/**
|
|
11261
|
+
* Sends a **400 Bad Request** response.
|
|
11262
|
+
*
|
|
11263
|
+
* Use when the client submits a malformed or invalid request
|
|
11264
|
+
* (e.g. missing required fields, invalid format, constraint violation).
|
|
11265
|
+
*
|
|
11266
|
+
* @param message - Human-readable explanation of why the request was rejected.
|
|
11267
|
+
* @param data - Optional payload (e.g. a list of validation errors per field).
|
|
11268
|
+
*
|
|
11269
|
+
* @example
|
|
11270
|
+
* send.badRequest("The 'username' field must be at least 3 characters.");
|
|
11271
|
+
* send.badRequest("Validation failed.", { fields: { email: "Invalid format" } });
|
|
11272
|
+
*/
|
|
11273
|
+
badRequest: TSendPropsFn;
|
|
11274
|
+
/**
|
|
11275
|
+
* Sends a **404 Not Found** response.
|
|
11276
|
+
*
|
|
11277
|
+
* Use when the requested resource does not exist or has been permanently removed.
|
|
11278
|
+
*
|
|
11279
|
+
* @param message - Human-readable explanation of what could not be found.
|
|
11280
|
+
* @param data - Optional payload (e.g. the identifier that was looked up).
|
|
11281
|
+
*
|
|
11282
|
+
* @example
|
|
11283
|
+
* send.notFound("No user found with id '42'.");
|
|
11284
|
+
* send.notFound("Resource not found.", { id: "42" });
|
|
11285
|
+
*/
|
|
11286
|
+
notFound: TSendPropsFn;
|
|
11287
|
+
/**
|
|
11288
|
+
* Sends a **429 Too Many Requests** response.
|
|
11289
|
+
*
|
|
11290
|
+
* Use when the client has exceeded an allowed request rate or quota.
|
|
11291
|
+
* Consider pairing this with a `Retry-After` header at the middleware level.
|
|
11292
|
+
*
|
|
11293
|
+
* @param message - Human-readable explanation of the rate limit breach.
|
|
11294
|
+
* @param data - Optional payload (e.g. retry delay, remaining quota).
|
|
11295
|
+
*
|
|
11296
|
+
* @example
|
|
11297
|
+
* send.tooManyRequest("Rate limit reached. Try again in 60 seconds.");
|
|
11298
|
+
* send.tooManyRequest("Quota exceeded.", { retryAfter: 60 });
|
|
11299
|
+
*/
|
|
11300
|
+
tooManyRequest: TSendPropsFn;
|
|
11301
|
+
/**
|
|
11302
|
+
* Sends a **500 Internal Server Error** response.
|
|
11303
|
+
*
|
|
11304
|
+
* Use for unexpected, unhandled server-side failures.
|
|
11305
|
+
* Avoid leaking internal stack traces or sensitive details in the message.
|
|
11306
|
+
*
|
|
11307
|
+
* @param message - Human-readable explanation safe to expose to the client.
|
|
11308
|
+
* @param data - Optional payload (use sparingly — never expose raw stack traces).
|
|
11309
|
+
*
|
|
11310
|
+
* @example
|
|
11311
|
+
* send.internalError("An unexpected error occurred. Please try again later.");
|
|
11312
|
+
*/
|
|
11313
|
+
internalError: TSendPropsFn;
|
|
11314
|
+
}
|
|
11315
|
+
|
|
11199
11316
|
/**
|
|
11200
11317
|
* Identifies the project root for a given caller path by traversing up the filesystem.
|
|
11201
11318
|
*/
|
|
@@ -11501,5 +11618,5 @@ declare class XStatic {
|
|
|
11501
11618
|
*/
|
|
11502
11619
|
declare function Router(): XyPrissRouter;
|
|
11503
11620
|
|
|
11504
|
-
export { ConfigurationManager as CM, ConfigurationManager as Configs, FileUploadAPI as FLA, FileUploadAPI, Plugin, PluginHookIds, Router, SecurityMiddleware, Upload, XJsonResponseHandler, XStatic, XyGuard, MultiServerApp as XyPMS, XyPrissRouter, XyPrissXHSC, __cfg__, __const__, __sys__, createOptimalCache, createServer, getCallerProjectRoot, getIp, getMime, getMimes, identifyProjectRoot, initializeFileUpload, mergeWithDefaults, mergeWithDefaults as mwdef, quickServer, uploadAny, uploadArray, uploadFields, uploadSingle, xems };
|
|
11505
|
-
export type { ArchiveOptions, BatchRenameChange, CacheConfig, FileUploadConfig as FiUpConfig, FileUploadConfig, GetIpResult, IpSource, MonitorSnapshot, MultiServerConfig, NetworkStats, NextFunction, PerformanceConfig, PluginCreator, PluginServer, ProcessInfo, ProcessMonitorSnapshot, XyPrisRequest as Request, RequestHandler, XyPrisResponse as Response, RoutRateLimit, RouteConfig, RouteGuard, RouteMeta, RouteOptions, ParamType as RouteParamType, SecurityConfig, ServerOptions$1 as ServerOptions, XyPrisRequest$1 as XRequest, XyPrisResponse$1 as XResponse, XemsTypes, XyPrisRequest$1 as XyPrisRequest, XyPrisResponse$1 as XyPrisResponse, XyPrissApp, XyPrissPlugin };
|
|
11621
|
+
export { ConfigurationManager as CM, ConfigurationManager as Configs, FileUploadAPI as FLA, FileUploadAPI, Plugin, PluginHookIds, Router, SecurityMiddleware, Send, Upload, XJsonResponseHandler, XStatic, XyGuard, MultiServerApp as XyPMS, XyPrissRouter, XyPrissXHSC, __cfg__, __const__, __sys__, createOptimalCache, createServer, getCallerProjectRoot, getIp, getMime, getMimes, identifyProjectRoot, initializeFileUpload, mergeWithDefaults, mergeWithDefaults as mwdef, quickServer, uploadAny, uploadArray, uploadFields, uploadSingle, xems };
|
|
11622
|
+
export type { ArchiveOptions, BatchRenameChange, CacheConfig, FileUploadConfig as FiUpConfig, FileUploadConfig, GetIpResult, IResTemplate, ISeConfigs, ISeResponder, IpSource, MonitorSnapshot, MultiServerConfig, NetworkStats, NextFunction, PerformanceConfig, PluginCreator, PluginServer, ProcessInfo, ProcessMonitorSnapshot, XyPrisRequest as Request, RequestHandler, XyPrisResponse as Response, RoutRateLimit, RouteConfig, RouteGuard, RouteMeta, RouteOptions, ParamType as RouteParamType, SecurityConfig, ServerOptions$1 as ServerOptions, SupportedStatus, TSendPropsFn, XyPrisRequest$1 as XRequest, XyPrisResponse$1 as XResponse, XemsTypes, XyPrisRequest$1 as XyPrisRequest, XyPrisResponse$1 as XyPrisResponse, XyPrissApp, XyPrissPlugin };
|