@3sixty/api-processors 0.0.0-stage → 0.20.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +24 -2
- package/dist/es/data/restRouteProcessor.js +118 -0
- package/dist/es/data/restRouteProcessor.js.map +1 -0
- package/dist/es/data/socketRouteProcessor.js +131 -0
- package/dist/es/data/socketRouteProcessor.js.map +1 -0
- package/dist/es/identity/contextIdProcessor.js +69 -0
- package/dist/es/identity/contextIdProcessor.js.map +1 -0
- package/dist/es/identity/staticContextIdProcessor.js +60 -0
- package/dist/es/identity/staticContextIdProcessor.js.map +1 -0
- package/dist/es/index.js +19 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/logging/loggingProcessor.js +217 -0
- package/dist/es/logging/loggingProcessor.js.map +1 -0
- package/dist/es/mimeType/jsonLdMimeTypeProcessor.js +38 -0
- package/dist/es/mimeType/jsonLdMimeTypeProcessor.js.map +1 -0
- package/dist/es/mimeType/jwtMimeTypeProcessor.js +34 -0
- package/dist/es/mimeType/jwtMimeTypeProcessor.js.map +1 -0
- package/dist/es/models/IContextIdProcessorConfig.js +4 -0
- package/dist/es/models/IContextIdProcessorConfig.js.map +1 -0
- package/dist/es/models/IContextIdProcessorConstructorOptions.js +2 -0
- package/dist/es/models/IContextIdProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/ILoggingProcessorConfig.js +4 -0
- package/dist/es/models/ILoggingProcessorConfig.js.map +1 -0
- package/dist/es/models/ILoggingProcessorConstructorOptions.js +2 -0
- package/dist/es/models/ILoggingProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/IRestRouteProcessorConstructorOptions.js +2 -0
- package/dist/es/models/IRestRouteProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/IRouteProcessorConfig.js +4 -0
- package/dist/es/models/IRouteProcessorConfig.js.map +1 -0
- package/dist/es/models/ISocketRouteProcessorConstructorOptions.js +2 -0
- package/dist/es/models/ISocketRouteProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/IStaticContextIdProcessorConfig.js +4 -0
- package/dist/es/models/IStaticContextIdProcessorConfig.js.map +1 -0
- package/dist/es/models/IStaticContextIdProcessorConstructorOptions.js +2 -0
- package/dist/es/models/IStaticContextIdProcessorConstructorOptions.js.map +1 -0
- package/dist/types/data/restRouteProcessor.d.ts +36 -0
- package/dist/types/data/socketRouteProcessor.d.ts +50 -0
- package/dist/types/identity/contextIdProcessor.d.ts +40 -0
- package/dist/types/identity/staticContextIdProcessor.d.ts +34 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/logging/loggingProcessor.d.ts +46 -0
- package/dist/types/mimeType/jsonLdMimeTypeProcessor.d.ts +26 -0
- package/dist/types/mimeType/jwtMimeTypeProcessor.d.ts +26 -0
- package/dist/types/models/IContextIdProcessorConfig.d.ts +13 -0
- package/dist/types/models/IContextIdProcessorConstructorOptions.d.ts +10 -0
- package/dist/types/models/ILoggingProcessorConfig.d.ts +22 -0
- package/dist/types/models/ILoggingProcessorConstructorOptions.d.ts +14 -0
- package/dist/types/models/IRestRouteProcessorConstructorOptions.d.ts +10 -0
- package/dist/types/models/IRouteProcessorConfig.d.ts +9 -0
- package/dist/types/models/ISocketRouteProcessorConstructorOptions.d.ts +10 -0
- package/dist/types/models/IStaticContextIdProcessorConfig.d.ts +17 -0
- package/dist/types/models/IStaticContextIdProcessorConstructorOptions.d.ts +10 -0
- package/docs/changelog.md +16 -0
- package/docs/examples.md +189 -0
- package/docs/reference/classes/ContextIdProcessor.md +129 -0
- package/docs/reference/classes/JsonLdMimeTypeProcessor.md +87 -0
- package/docs/reference/classes/JwtMimeTypeProcessor.md +87 -0
- package/docs/reference/classes/LoggingProcessor.md +153 -0
- package/docs/reference/classes/RestRouteProcessor.md +107 -0
- package/docs/reference/classes/SocketRouteProcessor.md +185 -0
- package/docs/reference/classes/StaticContextIdProcessor.md +103 -0
- package/docs/reference/index.md +23 -0
- package/docs/reference/interfaces/IContextIdProcessorConfig.md +19 -0
- package/docs/reference/interfaces/IContextIdProcessorConstructorOptions.md +11 -0
- package/docs/reference/interfaces/ILoggingProcessorConfig.md +36 -0
- package/docs/reference/interfaces/ILoggingProcessorConstructorOptions.md +19 -0
- package/docs/reference/interfaces/IRestRouteProcessorConstructorOptions.md +11 -0
- package/docs/reference/interfaces/IRouteProcessorConfig.md +11 -0
- package/docs/reference/interfaces/ISocketRouteProcessorConstructorOptions.md +11 -0
- package/docs/reference/interfaces/IStaticContextIdProcessorConfig.md +27 -0
- package/docs/reference/interfaces/IStaticContextIdProcessorConstructorOptions.md +11 -0
- package/locales/en.json +22 -0
- package/package.json +50 -5
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { IBaseRoute, IBaseRouteProcessor, IHttpResponse, IHttpServerRequest } from "@3sixty/api-models";
|
|
2
|
+
import { type IContextIds } from "@3sixty/context";
|
|
3
|
+
import type { IContextIdProcessorConstructorOptions } from "../models/IContextIdProcessorConstructorOptions.js";
|
|
4
|
+
/**
|
|
5
|
+
* Adds an id to the request context ids.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ContextIdProcessor implements IBaseRouteProcessor {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of ContextIdProcessor.
|
|
14
|
+
* @param options Options for the processor.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options: IContextIdProcessorConstructorOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Returns the class name of the component.
|
|
19
|
+
* @returns The class name of the component.
|
|
20
|
+
*/
|
|
21
|
+
className(): string;
|
|
22
|
+
/**
|
|
23
|
+
* The service needs to be started when the application is initialized.
|
|
24
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
25
|
+
* @returns A promise that resolves when the context ID has been loaded from the store.
|
|
26
|
+
*/
|
|
27
|
+
start(nodeLoggingComponentType?: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Pre process the REST request for the specified route.
|
|
30
|
+
* @param request The incoming request.
|
|
31
|
+
* @param response The outgoing response.
|
|
32
|
+
* @param route The route to process.
|
|
33
|
+
* @param contextIds The context IDs of the request.
|
|
34
|
+
* @param processorState The state handed through the processors.
|
|
35
|
+
* @returns A promise that resolves when the context ID has been injected into the request.
|
|
36
|
+
*/
|
|
37
|
+
pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
|
|
38
|
+
[id: string]: unknown;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IBaseRoute, IBaseRouteProcessor, IHttpResponse, IHttpServerRequest } from "@3sixty/api-models";
|
|
2
|
+
import type { IContextIds } from "@3sixty/context";
|
|
3
|
+
import type { IStaticContextIdProcessorConstructorOptions } from "../models/IStaticContextIdProcessorConstructorOptions.js";
|
|
4
|
+
/**
|
|
5
|
+
* Adds a static context id to the request context.
|
|
6
|
+
*/
|
|
7
|
+
export declare class StaticContextIdProcessor implements IBaseRouteProcessor {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of StaticContextIdProcessor.
|
|
14
|
+
* @param options Options for the processor.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options: IStaticContextIdProcessorConstructorOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Returns the class name of the component.
|
|
19
|
+
* @returns The class name of the component.
|
|
20
|
+
*/
|
|
21
|
+
className(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Pre process the REST request for the specified route.
|
|
24
|
+
* @param request The incoming request.
|
|
25
|
+
* @param response The outgoing response.
|
|
26
|
+
* @param route The route to process.
|
|
27
|
+
* @param contextIds The context IDs of the request.
|
|
28
|
+
* @param processorState The state handed through the processors.
|
|
29
|
+
* @returns A promise that resolves when the static context ID has been injected into the request.
|
|
30
|
+
*/
|
|
31
|
+
pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
|
|
32
|
+
[id: string]: unknown;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./data/restRouteProcessor.js";
|
|
2
|
+
export * from "./data/socketRouteProcessor.js";
|
|
3
|
+
export * from "./identity/contextIdProcessor.js";
|
|
4
|
+
export * from "./identity/staticContextIdProcessor.js";
|
|
5
|
+
export * from "./logging/loggingProcessor.js";
|
|
6
|
+
export * from "./mimeType/jsonLdMimeTypeProcessor.js";
|
|
7
|
+
export * from "./mimeType/jwtMimeTypeProcessor.js";
|
|
8
|
+
export * from "./models/IContextIdProcessorConfig.js";
|
|
9
|
+
export * from "./models/IContextIdProcessorConstructorOptions.js";
|
|
10
|
+
export * from "./models/ILoggingProcessorConfig.js";
|
|
11
|
+
export * from "./models/ILoggingProcessorConstructorOptions.js";
|
|
12
|
+
export * from "./models/IRestRouteProcessorConstructorOptions.js";
|
|
13
|
+
export * from "./models/IRouteProcessorConfig.js";
|
|
14
|
+
export * from "./models/ISocketRouteProcessorConstructorOptions.js";
|
|
15
|
+
export * from "./models/IStaticContextIdProcessorConfig.js";
|
|
16
|
+
export * from "./models/IStaticContextIdProcessorConstructorOptions.js";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { IBaseRoute, IBaseRouteProcessor, IHttpResponse, IHttpServerRequest } from "@3sixty/api-models";
|
|
2
|
+
import type { IContextIds } from "@3sixty/context";
|
|
3
|
+
import type { ILoggingProcessorConstructorOptions } from "../models/ILoggingProcessorConstructorOptions.js";
|
|
4
|
+
/**
|
|
5
|
+
* Process the REST request and log its information.
|
|
6
|
+
*/
|
|
7
|
+
export declare class LoggingProcessor implements IBaseRouteProcessor {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of LoggingProcessor.
|
|
14
|
+
* @param options Options for the processor.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options?: ILoggingProcessorConstructorOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Returns the class name of the component.
|
|
19
|
+
* @returns The class name of the component.
|
|
20
|
+
*/
|
|
21
|
+
className(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Pre process the REST request for the specified route.
|
|
24
|
+
* @param request The incoming request.
|
|
25
|
+
* @param response The outgoing response.
|
|
26
|
+
* @param route The route to process.
|
|
27
|
+
* @param contextIds The context IDs of the request.
|
|
28
|
+
* @param processorState The state handed through the processors.
|
|
29
|
+
* @returns A promise that resolves when the pre-processing log entry has been written.
|
|
30
|
+
*/
|
|
31
|
+
pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
|
|
32
|
+
[id: string]: unknown;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Post process the REST request for the specified route.
|
|
36
|
+
* @param request The incoming request.
|
|
37
|
+
* @param response The outgoing response.
|
|
38
|
+
* @param route The route to process.
|
|
39
|
+
* @param contextIds The context IDs of the request.
|
|
40
|
+
* @param processorState The state handed through the processors.
|
|
41
|
+
* @returns A promise that resolves when the post-processing log entry has been written.
|
|
42
|
+
*/
|
|
43
|
+
post(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
|
|
44
|
+
[id: string]: unknown;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IMimeTypeProcessor } from "@3sixty/api-models";
|
|
2
|
+
/**
|
|
3
|
+
* Process the JSON-LD mime type.
|
|
4
|
+
*/
|
|
5
|
+
export declare class JsonLdMimeTypeProcessor implements IMimeTypeProcessor {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the class name of the component.
|
|
12
|
+
* @returns The class name of the component.
|
|
13
|
+
*/
|
|
14
|
+
className(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Get the MIME types that this handler can handle.
|
|
17
|
+
* @returns The MIME types that this handler can handle.
|
|
18
|
+
*/
|
|
19
|
+
getTypes(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Handle content.
|
|
22
|
+
* @param body The body to process.
|
|
23
|
+
* @returns The processed body.
|
|
24
|
+
*/
|
|
25
|
+
handle(body: Uint8Array): Promise<unknown>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IMimeTypeProcessor } from "@3sixty/api-models";
|
|
2
|
+
/**
|
|
3
|
+
* Process the JWT mime type.
|
|
4
|
+
*/
|
|
5
|
+
export declare class JwtMimeTypeProcessor implements IMimeTypeProcessor {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the class name of the component.
|
|
12
|
+
* @returns The class name of the component.
|
|
13
|
+
*/
|
|
14
|
+
className(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Get the MIME types that this handler can handle.
|
|
17
|
+
* @returns The MIME types that this handler can handle.
|
|
18
|
+
*/
|
|
19
|
+
getTypes(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Handle content.
|
|
22
|
+
* @param body The body to process.
|
|
23
|
+
* @returns The processed body.
|
|
24
|
+
*/
|
|
25
|
+
handle(body: Uint8Array): Promise<unknown>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the context id processor.
|
|
3
|
+
*/
|
|
4
|
+
export interface IContextIdProcessorConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The fixed identity key for request context.
|
|
7
|
+
*/
|
|
8
|
+
key: string;
|
|
9
|
+
/**
|
|
10
|
+
* Only add the identity if the request is authenticated.
|
|
11
|
+
*/
|
|
12
|
+
authOnly?: boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IContextIdProcessorConfig } from "./IContextIdProcessorConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the ContextIdProcessor constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IContextIdProcessorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The configuration for the processor.
|
|
8
|
+
*/
|
|
9
|
+
config: IContextIdProcessorConfig;
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the request logging processor.
|
|
3
|
+
*/
|
|
4
|
+
export interface ILoggingProcessorConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Include the body objects when logging the information.
|
|
7
|
+
*/
|
|
8
|
+
includeBody?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Show the full base64 content for data, default to abbreviate.
|
|
11
|
+
*/
|
|
12
|
+
fullBase64?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* List of property names to obfuscate, can be regex, defaults to "password".
|
|
15
|
+
*/
|
|
16
|
+
obfuscateProperties?: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Request URL path prefixes to exclude from logging, defaults to ["/logging"].
|
|
19
|
+
* Use this to prevent the logging endpoint itself from appearing in its own output.
|
|
20
|
+
*/
|
|
21
|
+
excludePaths?: string[];
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ILoggingProcessorConfig } from "./ILoggingProcessorConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the LoggingProcessor constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface ILoggingProcessorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The type for the logging component.
|
|
8
|
+
*/
|
|
9
|
+
loggingComponentType?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The configuration for the logging processor.
|
|
12
|
+
*/
|
|
13
|
+
config?: ILoggingProcessorConfig;
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IRouteProcessorConfig } from "../models/IRouteProcessorConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the RestRouteProcessor constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IRestRouteProcessorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The configuration for the processor.
|
|
8
|
+
*/
|
|
9
|
+
config?: IRouteProcessorConfig;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IRouteProcessorConfig } from "./IRouteProcessorConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the SocketRouteProcessor constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface ISocketRouteProcessorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The configuration for the processor.
|
|
8
|
+
*/
|
|
9
|
+
config?: IRouteProcessorConfig;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the static id processor.
|
|
3
|
+
*/
|
|
4
|
+
export interface IStaticContextIdProcessorConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The fixed identity key for request context.
|
|
7
|
+
*/
|
|
8
|
+
key: string;
|
|
9
|
+
/**
|
|
10
|
+
* The fixed identity value for request context.
|
|
11
|
+
*/
|
|
12
|
+
value: string;
|
|
13
|
+
/**
|
|
14
|
+
* Only add the identity if the request is authenticated.
|
|
15
|
+
*/
|
|
16
|
+
authOnly?: boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IStaticContextIdProcessorConfig } from "./IStaticContextIdProcessorConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the StaticContextIdProcessor constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IStaticContextIdProcessorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The configuration for the processor.
|
|
8
|
+
*/
|
|
9
|
+
config: IStaticContextIdProcessorConfig;
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.20.0-next.1](https://github.com/3sixtyglobal/api/compare/api-processors-v0.20.0-next.0...api-processors-v0.20.0-next.1) (2026-10-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* publish packages under the [@3sixty](https://github.com/3sixty) namespace ([91b1822](https://github.com/3sixtyglobal/api/commit/91b1822dba38f70692087ad4643572531d6634dc))
|
|
9
|
+
* updated ts compile ([d9a5c86](https://github.com/3sixtyglobal/api/commit/d9a5c86ec7dd1faf3045b5cd1e0d38a4b331313d))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* The following workspace dependencies were updated
|
|
15
|
+
* dependencies
|
|
16
|
+
* @3sixty/api-models bumped from 0.20.0-next.0 to 0.20.0-next.1
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Processors Examples
|
|
2
|
+
|
|
3
|
+
These snippets demonstrate request and response processors that can be composed into REST, socket, and MIME handling pipelines.
|
|
4
|
+
|
|
5
|
+
## SocketRouteProcessor
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { SocketRouteProcessor } from '@3sixty/api-processors';
|
|
9
|
+
|
|
10
|
+
const socketProcessor = new SocketRouteProcessor();
|
|
11
|
+
|
|
12
|
+
console.log(socketProcessor.className()); // SocketRouteProcessor
|
|
13
|
+
|
|
14
|
+
const socketRoute = {
|
|
15
|
+
event: 'tenant.updated',
|
|
16
|
+
handler: async () => ({
|
|
17
|
+
body: {
|
|
18
|
+
ok: true
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const socketRequest = {
|
|
24
|
+
socketId: 'conn-1',
|
|
25
|
+
url: '/tenant.updated',
|
|
26
|
+
pathParams: {},
|
|
27
|
+
query: {},
|
|
28
|
+
body: {
|
|
29
|
+
tenantId: '0123456789abcdef0123456789abcdef'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const socketResponse = {};
|
|
34
|
+
const socketProcessorState = {};
|
|
35
|
+
|
|
36
|
+
await socketProcessor.connected(socketRequest, socketRoute);
|
|
37
|
+
|
|
38
|
+
await socketProcessor.process(
|
|
39
|
+
socketRequest,
|
|
40
|
+
socketResponse,
|
|
41
|
+
socketRoute,
|
|
42
|
+
socketProcessorState,
|
|
43
|
+
async (topic, response) => {
|
|
44
|
+
console.log(topic); // tenant.updated
|
|
45
|
+
console.log(response.statusCode ?? 200); // 200
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
await socketProcessor.disconnected(socketRequest, socketRoute);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## ContextIdProcessor
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { ContextIdProcessor } from '@3sixty/api-processors';
|
|
56
|
+
|
|
57
|
+
const contextProcessor = new ContextIdProcessor({
|
|
58
|
+
config: {
|
|
59
|
+
key: 'node'
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await contextProcessor.start('default');
|
|
64
|
+
console.log(contextProcessor.className()); // ContextIdProcessor
|
|
65
|
+
|
|
66
|
+
const contextIds = {};
|
|
67
|
+
await contextProcessor.pre(
|
|
68
|
+
{ method: 'get', url: '/health', headers: {} },
|
|
69
|
+
{},
|
|
70
|
+
undefined,
|
|
71
|
+
contextIds,
|
|
72
|
+
{}
|
|
73
|
+
);
|
|
74
|
+
console.log(typeof contextIds.node); // string
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## LoggingProcessor
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { LoggingProcessor } from '@3sixty/api-processors';
|
|
81
|
+
|
|
82
|
+
const logging = new LoggingProcessor();
|
|
83
|
+
|
|
84
|
+
console.log(logging.className()); // LoggingProcessor
|
|
85
|
+
|
|
86
|
+
const request = {
|
|
87
|
+
method: 'get',
|
|
88
|
+
url: 'http://localhost:3000/health',
|
|
89
|
+
headers: {}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const response = {
|
|
93
|
+
statusCode: 200,
|
|
94
|
+
headers: {}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const processorState: { [id: string]: unknown } = {};
|
|
98
|
+
|
|
99
|
+
await logging.pre(request, response, undefined, {}, processorState);
|
|
100
|
+
await logging.post(request, response, undefined, {}, processorState);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## JsonLdMimeTypeProcessor
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { JsonLdMimeTypeProcessor } from '@3sixty/api-processors';
|
|
107
|
+
|
|
108
|
+
const jsonLd = new JsonLdMimeTypeProcessor();
|
|
109
|
+
|
|
110
|
+
const mediaTypes = jsonLd.getTypes();
|
|
111
|
+
const body = new TextEncoder().encode('{"@context":"https://schema.org","name":"Tenant"}');
|
|
112
|
+
const handled = await jsonLd.handle(body);
|
|
113
|
+
|
|
114
|
+
console.log(mediaTypes[0]); // application/ld+json
|
|
115
|
+
console.log(typeof handled); // object
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## JwtMimeTypeProcessor
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { JwtMimeTypeProcessor } from '@3sixty/api-processors';
|
|
122
|
+
|
|
123
|
+
const jwt = new JwtMimeTypeProcessor();
|
|
124
|
+
|
|
125
|
+
const mediaTypes = jwt.getTypes();
|
|
126
|
+
const body = new TextEncoder().encode('eyJhbGciOiJIUzI1NiJ9.payload.signature');
|
|
127
|
+
const handled = await jwt.handle(body);
|
|
128
|
+
|
|
129
|
+
console.log(mediaTypes[0]); // application/jwt
|
|
130
|
+
console.log(typeof handled); // string
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## RestRouteProcessor
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { RestRouteProcessor } from '@3sixty/api-processors';
|
|
137
|
+
|
|
138
|
+
const restProcessor = new RestRouteProcessor();
|
|
139
|
+
|
|
140
|
+
console.log(restProcessor.className()); // RestRouteProcessor
|
|
141
|
+
|
|
142
|
+
const request = {
|
|
143
|
+
method: 'get',
|
|
144
|
+
url: '/info',
|
|
145
|
+
headers: {},
|
|
146
|
+
pathParams: {},
|
|
147
|
+
query: {}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const response = {};
|
|
151
|
+
|
|
152
|
+
const route = {
|
|
153
|
+
method: 'get',
|
|
154
|
+
path: '/info',
|
|
155
|
+
handler: async () => ({
|
|
156
|
+
body: {
|
|
157
|
+
name: '3Sixty API'
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
await restProcessor.process(request, response, route, {});
|
|
163
|
+
console.log(response.statusCode ?? 200); // 200
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## StaticContextIdProcessor
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { StaticContextIdProcessor } from '@3sixty/api-processors';
|
|
170
|
+
|
|
171
|
+
const staticContext = new StaticContextIdProcessor({
|
|
172
|
+
config: {
|
|
173
|
+
key: 'environment',
|
|
174
|
+
value: 'test'
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
console.log(staticContext.className()); // StaticContextIdProcessor
|
|
179
|
+
|
|
180
|
+
const contextIds = {};
|
|
181
|
+
await staticContext.pre(
|
|
182
|
+
{ method: 'get', url: '/health', headers: {} },
|
|
183
|
+
{},
|
|
184
|
+
undefined,
|
|
185
|
+
contextIds,
|
|
186
|
+
{}
|
|
187
|
+
);
|
|
188
|
+
console.log(contextIds.environment); // test
|
|
189
|
+
```
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Class: ContextIdProcessor
|
|
2
|
+
|
|
3
|
+
Adds an id to the request context ids.
|
|
4
|
+
|
|
5
|
+
## Implements
|
|
6
|
+
|
|
7
|
+
- `IBaseRouteProcessor`
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
> **new ContextIdProcessor**(`options`): `ContextIdProcessor`
|
|
14
|
+
|
|
15
|
+
Create a new instance of ContextIdProcessor.
|
|
16
|
+
|
|
17
|
+
#### Parameters
|
|
18
|
+
|
|
19
|
+
##### options
|
|
20
|
+
|
|
21
|
+
[`IContextIdProcessorConstructorOptions`](../interfaces/IContextIdProcessorConstructorOptions.md)
|
|
22
|
+
|
|
23
|
+
Options for the processor.
|
|
24
|
+
|
|
25
|
+
#### Returns
|
|
26
|
+
|
|
27
|
+
`ContextIdProcessor`
|
|
28
|
+
|
|
29
|
+
## Properties
|
|
30
|
+
|
|
31
|
+
### CLASS\_NAME {#class_name}
|
|
32
|
+
|
|
33
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
34
|
+
|
|
35
|
+
Runtime name for the class.
|
|
36
|
+
|
|
37
|
+
## Methods
|
|
38
|
+
|
|
39
|
+
### className() {#classname}
|
|
40
|
+
|
|
41
|
+
> **className**(): `string`
|
|
42
|
+
|
|
43
|
+
Returns the class name of the component.
|
|
44
|
+
|
|
45
|
+
#### Returns
|
|
46
|
+
|
|
47
|
+
`string`
|
|
48
|
+
|
|
49
|
+
The class name of the component.
|
|
50
|
+
|
|
51
|
+
#### Implementation of
|
|
52
|
+
|
|
53
|
+
`IBaseRouteProcessor.className`
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### start() {#start}
|
|
58
|
+
|
|
59
|
+
> **start**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
|
|
60
|
+
|
|
61
|
+
The service needs to be started when the application is initialized.
|
|
62
|
+
|
|
63
|
+
#### Parameters
|
|
64
|
+
|
|
65
|
+
##### nodeLoggingComponentType?
|
|
66
|
+
|
|
67
|
+
`string`
|
|
68
|
+
|
|
69
|
+
The node logging component type.
|
|
70
|
+
|
|
71
|
+
#### Returns
|
|
72
|
+
|
|
73
|
+
`Promise`\<`void`\>
|
|
74
|
+
|
|
75
|
+
A promise that resolves when the context ID has been loaded from the store.
|
|
76
|
+
|
|
77
|
+
#### Implementation of
|
|
78
|
+
|
|
79
|
+
`IBaseRouteProcessor.start`
|
|
80
|
+
|
|
81
|
+
***
|
|
82
|
+
|
|
83
|
+
### pre() {#pre}
|
|
84
|
+
|
|
85
|
+
> **pre**(`request`, `response`, `route`, `contextIds`, `processorState`): `Promise`\<`void`\>
|
|
86
|
+
|
|
87
|
+
Pre process the REST request for the specified route.
|
|
88
|
+
|
|
89
|
+
#### Parameters
|
|
90
|
+
|
|
91
|
+
##### request
|
|
92
|
+
|
|
93
|
+
`IHttpServerRequest`
|
|
94
|
+
|
|
95
|
+
The incoming request.
|
|
96
|
+
|
|
97
|
+
##### response
|
|
98
|
+
|
|
99
|
+
`IHttpResponse`
|
|
100
|
+
|
|
101
|
+
The outgoing response.
|
|
102
|
+
|
|
103
|
+
##### route
|
|
104
|
+
|
|
105
|
+
`IBaseRoute` \| `undefined`
|
|
106
|
+
|
|
107
|
+
The route to process.
|
|
108
|
+
|
|
109
|
+
##### contextIds
|
|
110
|
+
|
|
111
|
+
`IContextIds`
|
|
112
|
+
|
|
113
|
+
The context IDs of the request.
|
|
114
|
+
|
|
115
|
+
##### processorState
|
|
116
|
+
|
|
117
|
+
\{\[`id`: `string`\]: `unknown`; \}
|
|
118
|
+
|
|
119
|
+
The state handed through the processors.
|
|
120
|
+
|
|
121
|
+
#### Returns
|
|
122
|
+
|
|
123
|
+
`Promise`\<`void`\>
|
|
124
|
+
|
|
125
|
+
A promise that resolves when the context ID has been injected into the request.
|
|
126
|
+
|
|
127
|
+
#### Implementation of
|
|
128
|
+
|
|
129
|
+
`IBaseRouteProcessor.pre`
|