@webpieces/http-server 0.4.698 → 0.4.700
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/http-server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.700",
|
|
4
4
|
"description": "WebPieces server with filter chain and dependency injection",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@webpieces/core-context": "0.4.
|
|
26
|
-
"@webpieces/core-util": "0.4.
|
|
27
|
-
"@webpieces/gcp-identity": "0.4.
|
|
28
|
-
"@webpieces/http-routing": "0.4.
|
|
25
|
+
"@webpieces/core-context": "0.4.700",
|
|
26
|
+
"@webpieces/core-util": "0.4.700",
|
|
27
|
+
"@webpieces/gcp-identity": "0.4.700",
|
|
28
|
+
"@webpieces/http-routing": "0.4.700",
|
|
29
29
|
"cors": "2.8.5",
|
|
30
30
|
"express": "5.1.0",
|
|
31
31
|
"inversify": "7.10.4"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MethodMeta, WebpiecesConfig } from '@webpieces/http-routing';
|
|
2
|
-
import { Filter,
|
|
2
|
+
import { Filter, Service } from '@webpieces/core-util';
|
|
3
|
+
import { WpResponse } from '@webpieces/http-routing';
|
|
3
4
|
/**
|
|
4
5
|
* RecordingFilter - Records a request as a replayable test case (port of Java
|
|
5
6
|
* RecordingFilter).
|
|
@@ -5,8 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const inversify_1 = require("inversify");
|
|
6
6
|
const http_routing_1 = require("@webpieces/http-routing");
|
|
7
7
|
const core_context_1 = require("@webpieces/core-context");
|
|
8
|
-
const http_routing_2 = require("@webpieces/http-routing");
|
|
9
8
|
const core_util_1 = require("@webpieces/core-util");
|
|
9
|
+
const core_util_2 = require("@webpieces/core-util");
|
|
10
10
|
const TestCaseRecorderImpl_1 = require("../recorder/TestCaseRecorderImpl");
|
|
11
11
|
/**
|
|
12
12
|
* RecordingFilter - Records a request as a replayable test case (port of Java
|
|
@@ -26,7 +26,7 @@ const TestCaseRecorderImpl_1 = require("../recorder/TestCaseRecorderImpl");
|
|
|
26
26
|
* Recording NEVER alters the response - failures inside the recorder are
|
|
27
27
|
* caught and logged.
|
|
28
28
|
*/
|
|
29
|
-
let RecordingFilter = class RecordingFilter extends
|
|
29
|
+
let RecordingFilter = class RecordingFilter extends core_util_1.Filter {
|
|
30
30
|
config;
|
|
31
31
|
constructor(config) {
|
|
32
32
|
super();
|
|
@@ -38,7 +38,7 @@ let RecordingFilter = class RecordingFilter extends http_routing_2.Filter {
|
|
|
38
38
|
return await nextFilter.invoke(meta);
|
|
39
39
|
}
|
|
40
40
|
const recorder = new TestCaseRecorderImpl_1.TestCaseRecorderImpl();
|
|
41
|
-
core_context_1.RequestContext.putUntrusted(
|
|
41
|
+
core_context_1.RequestContext.putUntrusted(core_util_2.RecorderKeys.RECORDER, recorder);
|
|
42
42
|
const serverEndpoint = this.buildServerEndpoint(meta);
|
|
43
43
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- capture failure into the recording, then rethrow unchanged
|
|
44
44
|
try {
|
|
@@ -47,12 +47,12 @@ let RecordingFilter = class RecordingFilter extends http_routing_2.Filter {
|
|
|
47
47
|
return response;
|
|
48
48
|
}
|
|
49
49
|
catch (err) {
|
|
50
|
-
const error = (0,
|
|
51
|
-
serverEndpoint.failureResponse = new
|
|
50
|
+
const error = (0, core_util_2.toError)(err);
|
|
51
|
+
serverEndpoint.failureResponse = new core_util_2.RecordedError(error.name, error.message);
|
|
52
52
|
throw err;
|
|
53
53
|
}
|
|
54
54
|
finally {
|
|
55
|
-
core_context_1.RequestContext.removeKey(
|
|
55
|
+
core_context_1.RequestContext.removeKey(core_util_2.RecorderKeys.RECORDER);
|
|
56
56
|
recorder.spitOutTestCase(serverEndpoint, this.config.recordingDir);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -61,7 +61,7 @@ let RecordingFilter = class RecordingFilter extends http_routing_2.Filter {
|
|
|
61
61
|
return true;
|
|
62
62
|
}
|
|
63
63
|
// ContextFilter (priority 2000) already transferred the header into context
|
|
64
|
-
return core_context_1.RequestContext.hasKey(
|
|
64
|
+
return core_context_1.RequestContext.hasKey(core_util_2.WebpiecesCoreHeaders.RECORDING);
|
|
65
65
|
}
|
|
66
66
|
buildServerEndpoint(meta) {
|
|
67
67
|
// Masked snapshot of the magic context (secured values masked, keyed by name)
|
|
@@ -71,7 +71,7 @@ let RecordingFilter = class RecordingFilter extends http_routing_2.Filter {
|
|
|
71
71
|
ctxSnapshot[entry[0]] = entry[1];
|
|
72
72
|
}
|
|
73
73
|
const apiName = meta.routeMeta.apiName ?? meta.routeMeta.controllerClassName ?? 'UnknownApi';
|
|
74
|
-
return new
|
|
74
|
+
return new core_util_2.RecordedEndpoint(apiName, meta.methodName, [meta.requestDto], ctxSnapshot);
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
exports.RecordingFilter = RecordingFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecordingFilter.js","sourceRoot":"","sources":["../../../../../../packages/http/http-server/src/filters/RecordingFilter.ts"],"names":[],"mappings":";;;;AAAA,yCAAmC;AACnC,0DAKiC;AACjC,0DAAyD;AACzD,
|
|
1
|
+
{"version":3,"file":"RecordingFilter.js","sourceRoot":"","sources":["../../../../../../packages/http/http-server/src/filters/RecordingFilter.ts"],"names":[],"mappings":";;;;AAAA,yCAAmC;AACnC,0DAKiC;AACjC,0DAAyD;AACzD,oDAAuD;AAEvD,oDAM8B;AAE9B,2EAAwE;AAExE;;;;;;;;;;;;;;;;;GAiBG;AAGI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,kBAAuC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QAC5E,OAAO,6BAAc,CAAC,MAAM,CAAC,gCAAoB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;IAEO,mBAAmB,CAAC,IAAgB;QACxC,8EAA8E;QAC9E,MAAM,MAAM,GAAG,6BAAc,CAAC,cAAc,EAAE,CAAC;QAC/C,MAAM,WAAW,GAA2B,EAAE,CAAC;QAC/C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YACnC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,mBAAmB,IAAI,YAAY,CAAC;QAC7F,OAAO,IAAI,4BAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC;IAC1F,CAAC;CACJ,CAAA;AAxDY,0CAAe;0BAAf,eAAe;IAF3B,IAAA,wCAAyB,GAAE;IAC5B,sGAAsG;;IAI7F,mBAAA,IAAA,kBAAM,EAAC,qCAAsB,CAAC,CAAA;6CAAiB,8BAAe;GAH1D,eAAe,CAwD3B","sourcesContent":["import { inject } from 'inversify';\nimport {\n provideFrameworkSingleton,\n MethodMeta,\n WebpiecesConfig,\n WEBPIECES_CONFIG_TOKEN,\n} from '@webpieces/http-routing';\nimport { RequestContext } from '@webpieces/core-context';\nimport { Filter, Service } from '@webpieces/core-util';\nimport { WpResponse } from '@webpieces/http-routing';\nimport {\n RecordedEndpoint,\n RecordedError,\n RecorderKeys,\n WebpiecesCoreHeaders,\n toError,\n} from '@webpieces/core-util';\n\nimport { TestCaseRecorderImpl } from '../recorder/TestCaseRecorderImpl';\n\n/**\n * RecordingFilter - Records a request as a replayable test case (port of Java\n * RecordingFilter).\n *\n * Suggested priority: 1850 — a user-filter priority that runs BELOW the fixed\n * framework filters (LogApiFilter 1,000,000 outermost, AuthFilter 900,000), so\n * only real authorized flows are recorded.\n *\n * Activates when WebpiecesConfig.recordingAlwaysOn is set OR the request\n * carries WebpiecesCoreHeaders.RECORDING (x-webpieces-recording). While\n * active, a TestCaseRecorderImpl travels in the RequestContext under\n * RecorderKeys.RECORDER; the http-client proxy and recordable() wrappers add\n * every downstream call. On completion the fixture + generated spec are\n * logged (and written to config.recordingDir when set).\n *\n * Recording NEVER alters the response - failures inside the recorder are\n * caught and logged.\n */\n@provideFrameworkSingleton()\n// webpieces-disable no-any-unknown -- Filter generic params use unknown for response type flexibility\nexport class RecordingFilter extends Filter<MethodMeta, WpResponse<unknown>> {\n\n constructor(\n @inject(WEBPIECES_CONFIG_TOKEN) private config: WebpiecesConfig,\n ) {\n super();\n }\n\n // webpieces-disable no-any-unknown -- Filter generic params use unknown for response type flexibility\n async filter(\n meta: MethodMeta,\n nextFilter: Service<MethodMeta, WpResponse<unknown>>,\n ): Promise<WpResponse<unknown>> {\n if (!this.isRecordingRequested()) {\n return await nextFilter.invoke(meta);\n }\n\n const recorder = new TestCaseRecorderImpl();\n RequestContext.putUntrusted(RecorderKeys.RECORDER, recorder);\n\n const serverEndpoint = this.buildServerEndpoint(meta);\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- capture failure into the recording, then rethrow unchanged\n try {\n const response = await nextFilter.invoke(meta);\n serverEndpoint.successResponse = response.response;\n return response;\n } catch (err: unknown) {\n const error = toError(err);\n serverEndpoint.failureResponse = new RecordedError(error.name, error.message);\n throw err;\n } finally {\n RequestContext.removeKey(RecorderKeys.RECORDER);\n recorder.spitOutTestCase(serverEndpoint, this.config.recordingDir);\n }\n }\n\n private isRecordingRequested(): boolean {\n if (this.config.recordingAlwaysOn) {\n return true;\n }\n // ContextFilter (priority 2000) already transferred the header into context\n return RequestContext.hasKey(WebpiecesCoreHeaders.RECORDING);\n }\n\n private buildServerEndpoint(meta: MethodMeta): RecordedEndpoint {\n // Masked snapshot of the magic context (secured values masked, keyed by name)\n const logMap = RequestContext.buildLogFields();\n const ctxSnapshot: Record<string, string> = {};\n for (const entry of logMap.entries()) {\n ctxSnapshot[entry[0]] = entry[1];\n }\n\n const apiName = meta.routeMeta.apiName ?? meta.routeMeta.controllerClassName ?? 'UnknownApi';\n return new RecordedEndpoint(apiName, meta.methodName, [meta.requestDto], ctxSnapshot);\n }\n}\n"]}
|