feat(events-backend,events-node): add a parser option to events by content type

Signed-off-by: Rogerio Angeliski <angeliski@hotmail.com>
This commit is contained in:
Rogerio Angeliski
2025-02-12 22:25:37 -03:00
parent 9c3eb928ef
commit b95aa77ce2
18 changed files with 393 additions and 47 deletions
+2
View File
@@ -55,7 +55,9 @@
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/errors": "workspace:^",
"@backstage/types": "workspace:^",
"@types/express": "^4.17.6",
"cross-fetch": "^4.0.0",
"express": "^4.17.1",
"uri-template": "^2.0.0"
},
"devDependencies": {
+3
View File
@@ -7,10 +7,13 @@ import { EventBroker } from '@backstage/plugin-events-node';
import { EventPublisher } from '@backstage/plugin-events-node';
import { EventSubscriber } from '@backstage/plugin-events-node';
import { ExtensionPoint } from '@backstage/backend-plugin-api';
import { HttpBodyParserOptions } from '@backstage/plugin-events-node';
import { HttpPostIngressOptions } from '@backstage/plugin-events-node';
// @alpha (undocumented)
export interface EventsExtensionPoint {
// (undocumented)
addHttpPostBodyParser(options: HttpBodyParserOptions): void;
// (undocumented)
addHttpPostIngress(options: HttpPostIngressOptions): void;
// @deprecated (undocumented)
+22
View File
@@ -9,6 +9,7 @@ import { AuthService } from '@backstage/backend-plugin-api';
import { DiscoveryService } from '@backstage/backend-plugin-api';
import { LifecycleService } from '@backstage/backend-plugin-api';
import { LoggerService } from '@backstage/backend-plugin-api';
import { Request as Request_2 } from 'express';
import { RootConfigService } from '@backstage/backend-plugin-api';
import { ServiceFactory } from '@backstage/backend-plugin-api';
import { ServiceRef } from '@backstage/backend-plugin-api';
@@ -111,6 +112,27 @@ export interface EventSubscriber {
supportsEventTopics(): string[];
}
// @public (undocumented)
export type HttpBodyParsed = {
bodyParsed: any;
bodyBuffer: Buffer;
encoding: string;
};
// @public (undocumented)
export type HttpBodyParser = (
request: Request_2,
topic: string,
) => Promise<HttpBodyParsed>;
// @public (undocumented)
export interface HttpBodyParserOptions {
// (undocumented)
contentType: string;
// (undocumented)
parser: HttpBodyParser;
}
// @public (undocumented)
export interface HttpPostIngressOptions {
// (undocumented)
@@ -0,0 +1,24 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { HttpBodyParser } from './body-parser';
/**
* @public
*/
export interface HttpBodyParserOptions {
contentType: string;
parser: HttpBodyParser;
}
@@ -0,0 +1,33 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Request } from 'express';
/**
* @public
*/
export type HttpBodyParsed = {
bodyParsed: any;
bodyBuffer: Buffer;
encoding: string;
};
/**
* @public
*/
export type HttpBodyParser = (
request: Request,
topic: string,
) => Promise<HttpBodyParsed>;
@@ -0,0 +1,16 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './HttpBodyParser';
@@ -15,4 +15,6 @@
*/
export type { HttpPostIngressOptions } from './HttpPostIngressOptions';
export type { HttpBodyParserOptions } from './HttpBodyParserOptions';
export * from './validation';
export * from './body-parser';
+3
View File
@@ -19,6 +19,7 @@ import {
EventBroker,
EventPublisher,
EventSubscriber,
HttpBodyParserOptions,
HttpPostIngressOptions,
} from '@backstage/plugin-events-node';
@@ -46,6 +47,8 @@ export interface EventsExtensionPoint {
): void;
addHttpPostIngress(options: HttpPostIngressOptions): void;
addHttpPostBodyParser(options: HttpBodyParserOptions): void;
}
/**