@backstage/plugin-events-backend 0.3.16 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # @backstage/plugin-events-backend
2
2
 
3
+ ## 0.4.0-next.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 384e494: Internal updates to generated code.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @backstage/backend-plugin-api@1.1.0-next.1
13
+ - @backstage/backend-openapi-utils@0.3.1-next.1
14
+ - @backstage/config@1.3.0
15
+ - @backstage/errors@1.2.5
16
+ - @backstage/types@1.2.0
17
+ - @backstage/plugin-events-node@0.4.6-next.1
18
+
19
+ ## 0.3.17-next.0
20
+
21
+ ### Patch Changes
22
+
23
+ - 1577511: Allow configuring a timeout for event bus polling requests. This can be set like so in your app-config:
24
+
25
+ ```yaml
26
+ events:
27
+ notifyTimeoutMs: 30000
28
+ ```
29
+
30
+ - Updated dependencies
31
+ - @backstage/backend-plugin-api@1.0.3-next.0
32
+ - @backstage/plugin-events-node@0.4.6-next.0
33
+ - @backstage/backend-openapi-utils@0.3.1-next.0
34
+ - @backstage/config@1.3.0
35
+ - @backstage/errors@1.2.5
36
+ - @backstage/types@1.2.0
37
+
3
38
  ## 0.3.16
4
39
 
5
40
  ### Patch Changes
package/config.d.ts CHANGED
@@ -16,6 +16,12 @@
16
16
 
17
17
  export interface Config {
18
18
  events?: {
19
+ /**
20
+ * Timeout in milliseconds for how long to wait before closing subscription events
21
+ * requests to ensure they don't stall or that events get stuck. Defaults to 55 seconds.
22
+ */
23
+ notifyTimeoutMs?: number;
24
+
19
25
  http?: {
20
26
  /**
21
27
  * Topics for which a route has to be registered
@@ -265,8 +265,11 @@ const spec = {
265
265
  }
266
266
  }
267
267
  };
268
- const createOpenApiRouter = async (options) => backendOpenapiUtils.createValidatedOpenApiRouter(spec, options);
268
+ const createOpenApiRouter = async (options) => backendOpenapiUtils.createValidatedOpenApiRouterFromGeneratedEndpointMap(
269
+ spec,
270
+ options
271
+ );
269
272
 
270
273
  exports.createOpenApiRouter = createOpenApiRouter;
271
274
  exports.spec = spec;
272
- //# sourceMappingURL=openapi.generated.cjs.js.map
275
+ //# sourceMappingURL=router.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.cjs.js","sources":["../../../../src/schema/openapi/generated/router.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// ******************************************************************\n// * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. *\n// ******************************************************************\nimport { createValidatedOpenApiRouterFromGeneratedEndpointMap } from '@backstage/backend-openapi-utils';\nimport { EndpointMap } from './';\n\nexport const spec = {\n openapi: '3.0.3',\n info: {\n title: 'events',\n version: '1',\n description: 'The Backstage backend plugin that powers the events system.',\n license: {\n name: 'Apache-2.0',\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html',\n },\n contact: {},\n },\n servers: [\n {\n url: '/',\n },\n ],\n components: {\n examples: {},\n headers: {},\n parameters: {\n subscriptionId: {\n name: 'subscriptionId',\n in: 'path',\n required: true,\n allowReserved: true,\n schema: {\n type: 'string',\n },\n },\n },\n requestBodies: {},\n responses: {\n ErrorResponse: {\n description: 'An error response from the backend.',\n content: {\n 'application/json; charset=utf-8': {\n schema: {\n $ref: '#/components/schemas/Error',\n },\n },\n },\n },\n },\n schemas: {\n Event: {\n type: 'object',\n required: ['topic', 'payload'],\n properties: {\n topic: {\n type: 'string',\n description: 'The topic that the event is published on',\n },\n payload: {\n description: 'The event payload',\n },\n },\n },\n Error: {\n type: 'object',\n properties: {\n error: {\n type: 'object',\n properties: {\n name: {\n type: 'string',\n },\n message: {\n type: 'string',\n },\n },\n required: ['name', 'message'],\n },\n request: {\n type: 'object',\n properties: {\n method: {\n type: 'string',\n },\n url: {\n type: 'string',\n },\n },\n required: ['method', 'url'],\n },\n response: {\n type: 'object',\n properties: {\n statusCode: {\n type: 'number',\n },\n },\n required: ['statusCode'],\n },\n },\n required: ['error', 'request', 'response'],\n },\n },\n securitySchemes: {\n JWT: {\n type: 'http',\n scheme: 'bearer',\n bearerFormat: 'JWT',\n },\n },\n },\n paths: {\n '/bus/v1/events': {\n post: {\n operationId: 'PostEvent',\n description: 'Publish a new event',\n responses: {\n '201': {\n description: 'The event was published successfully',\n },\n '204': {\n description:\n 'The event did not need to be published as all subscribers have already been notified',\n },\n default: {\n $ref: '#/components/responses/ErrorResponse',\n },\n },\n security: [\n {},\n {\n JWT: [],\n },\n ],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['event'],\n properties: {\n event: {\n $ref: '#/components/schemas/Event',\n },\n notifiedSubscribers: {\n type: 'array',\n description:\n 'The IDs of subscriptions that have already received this event',\n items: {\n type: 'string',\n },\n },\n },\n },\n examples: {\n 'Publishing a simple Event': {\n value: {\n event: {\n topic: 'test-topic',\n payload: {\n myData: 'foo',\n },\n },\n },\n },\n },\n },\n },\n },\n },\n },\n '/bus/v1/subscriptions/{subscriptionId}': {\n put: {\n operationId: 'PutSubscription',\n description:\n 'Ensures that the subscription exists with the provided configuration',\n responses: {\n '201': {\n description: 'The subscription exists or was created successfully',\n },\n default: {\n $ref: '#/components/responses/ErrorResponse',\n },\n },\n security: [\n {},\n {\n JWT: [],\n },\n ],\n parameters: [\n {\n $ref: '#/components/parameters/subscriptionId',\n },\n ],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['topics'],\n properties: {\n topics: {\n type: 'array',\n description: 'The topics to subscribe to',\n items: {\n type: 'string',\n },\n },\n },\n },\n examples: {\n 'Subscribing to a single topic': {\n value: {\n topics: ['test-topic'],\n },\n },\n },\n },\n },\n },\n },\n },\n '/bus/v1/subscriptions/{subscriptionId}/events': {\n get: {\n operationId: 'GetSubscriptionEvents',\n description: 'Get new events for the provided subscription',\n responses: {\n '200': {\n description: 'New events',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['events'],\n properties: {\n events: {\n type: 'array',\n items: {\n $ref: '#/components/schemas/Event',\n },\n },\n },\n },\n },\n },\n },\n '202': {\n description:\n 'No new events are available. Response will block until the client should try again.',\n },\n default: {\n $ref: '#/components/responses/ErrorResponse',\n },\n },\n security: [\n {},\n {\n JWT: [],\n },\n ],\n parameters: [\n {\n $ref: '#/components/parameters/subscriptionId',\n },\n ],\n },\n },\n },\n} as const;\nexport const createOpenApiRouter = async (\n options?: Parameters<\n typeof createValidatedOpenApiRouterFromGeneratedEndpointMap\n >['1'],\n) =>\n createValidatedOpenApiRouterFromGeneratedEndpointMap<EndpointMap>(\n spec,\n options,\n );\n"],"names":["createValidatedOpenApiRouterFromGeneratedEndpointMap"],"mappings":";;;;AAsBO,MAAM,IAAO,GAAA;AAAA,EAClB,OAAS,EAAA,OAAA;AAAA,EACT,IAAM,EAAA;AAAA,IACJ,KAAO,EAAA,QAAA;AAAA,IACP,OAAS,EAAA,GAAA;AAAA,IACT,WAAa,EAAA,6DAAA;AAAA,IACb,OAAS,EAAA;AAAA,MACP,IAAM,EAAA,YAAA;AAAA,MACN,GAAK,EAAA;AAAA,KACP;AAAA,IACA,SAAS;AAAC,GACZ;AAAA,EACA,OAAS,EAAA;AAAA,IACP;AAAA,MACE,GAAK,EAAA;AAAA;AACP,GACF;AAAA,EACA,UAAY,EAAA;AAAA,IACV,UAAU,EAAC;AAAA,IACX,SAAS,EAAC;AAAA,IACV,UAAY,EAAA;AAAA,MACV,cAAgB,EAAA;AAAA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AAC,YAAY;AAAA;AACvB;AACF;AACF;AACF;AACF;AACF;AACF,KACF;AAAA,IACA,+CAAiD,EAAA;AAAA,MAC/C,GAAK,EAAA;AAAA,QACH,WAAa,EAAA,uBAAA;AAAA,QACb,WAAa,EAAA,8CAAA;AAAA,QACb,SAAW,EAAA;AAAA,UACT,KAAO,EAAA;AAAA,YACL,WAAa,EAAA,YAAA;AAAA,YACb,OAAS,EAAA;AAAA,cACP,kBAAoB,EAAA;AAAA,gBAClB,MAAQ,EAAA;AAAA,kBACN,IAAM,EAAA,QAAA;AAAA,kBACN,QAAA,EAAU,CAAC,QAAQ,CAAA;AAAA,kBACnB,UAAY,EAAA;AAAA,oBACV,MAAQ,EAAA;AAAA,sBACN,IAAM,EAAA,OAAA;AAAA,sBACN,KAAO,EAAA;AAAA,wBACL,IAAM,EAAA;AAAA;AACR;AACF;AACF;AACF;AACF;AACF,WACF;AAAA,UACA,KAAO,EAAA;AAAA,YACL,WACE,EAAA;AAAA,WACJ;AAAA,UACA,OAAS,EAAA;AAAA,YACP,IAAM,EAAA;AAAA;AACR,SACF;AAAA,QACA,QAAU,EAAA;AAAA,UACR,EAAC;AAAA,UACD;AAAA,YACE,KAAK;AAAC;AACR,SACF;AAAA,QACA,UAAY,EAAA;AAAA,UACV;AAAA,YACE,IAAM,EAAA;AAAA;AACR;AACF;AACF;AACF;AAEJ;AACa,MAAA,mBAAA,GAAsB,OACjC,OAIA,KAAAA,wEAAA;AAAA,EACE,IAAA;AAAA,EACA;AACF;;;;;"}
@@ -76,13 +76,17 @@ const eventsPlugin = backendPluginApi.createBackendPlugin({
76
76
  const eventsRouter = Router__default.default();
77
77
  http.bind(eventsRouter);
78
78
  httpRouter.use(eventsRouter);
79
+ const notifyTimeoutMs = config.getOptionalNumber(
80
+ "events.notifyTimeoutMs"
81
+ );
79
82
  httpRouter.use(
80
83
  await createEventBusRouter.createEventBusRouter({
81
84
  database,
82
85
  lifecycle,
83
86
  logger,
84
87
  httpAuth,
85
- scheduler
88
+ scheduler,
89
+ notifyTimeoutMs
86
90
  })
87
91
  );
88
92
  httpRouter.addAuthPolicy({
@@ -1 +1 @@
1
- {"version":3,"file":"EventsPlugin.cjs.js","sources":["../../src/service/EventsPlugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createBackendPlugin,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport {\n eventsExtensionPoint,\n EventsExtensionPoint,\n} from '@backstage/plugin-events-node/alpha';\nimport {\n eventsServiceRef,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\nimport Router from 'express-promise-router';\nimport { HttpPostIngressEventPublisher } from './http';\nimport { createEventBusRouter } from './hub';\n\nclass EventsExtensionPointImpl implements EventsExtensionPoint {\n #httpPostIngresses: HttpPostIngressOptions[] = [];\n\n setEventBroker(_: any): void {\n throw new Error(\n 'setEventBroker is not supported anymore; use eventsServiceRef instead',\n );\n }\n\n addPublishers(_: any): void {\n throw new Error(\n 'addPublishers is not supported anymore; use EventsService instead',\n );\n }\n\n addSubscribers(_: any): void {\n throw new Error(\n 'addSubscribers is not supported anymore; use EventsService instead',\n );\n }\n\n addHttpPostIngress(options: HttpPostIngressOptions) {\n this.#httpPostIngresses.push(options);\n }\n\n get httpPostIngresses() {\n return this.#httpPostIngresses;\n }\n}\n\n/**\n * Events plugin\n *\n * @public\n */\nexport const eventsPlugin = createBackendPlugin({\n pluginId: 'events',\n register(env) {\n const extensionPoint = new EventsExtensionPointImpl();\n env.registerExtensionPoint(eventsExtensionPoint, extensionPoint);\n\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n events: eventsServiceRef,\n database: coreServices.database,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n lifecycle: coreServices.lifecycle,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({\n config,\n events,\n database,\n httpAuth,\n httpRouter,\n lifecycle,\n logger,\n scheduler,\n }) {\n const ingresses = Object.fromEntries(\n extensionPoint.httpPostIngresses.map(ingress => [\n ingress.topic,\n ingress as Omit<HttpPostIngressOptions, 'topic'>,\n ]),\n );\n\n const http = HttpPostIngressEventPublisher.fromConfig({\n config,\n events,\n ingresses,\n logger,\n });\n const eventsRouter = Router();\n http.bind(eventsRouter);\n\n // MUST be registered *before* the event bus router.\n // Otherwise, it would already make use of `express.json()`\n // that is used there as part of the middleware stack.\n httpRouter.use(eventsRouter);\n\n httpRouter.use(\n await createEventBusRouter({\n database,\n lifecycle,\n logger,\n httpAuth,\n scheduler,\n }),\n );\n\n httpRouter.addAuthPolicy({\n allow: 'unauthenticated',\n path: '/http',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","eventsExtensionPoint","coreServices","eventsServiceRef","HttpPostIngressEventPublisher","Router","createEventBusRouter"],"mappings":";;;;;;;;;;;;;AAgCA,MAAM,wBAAyD,CAAA;AAAA,EAC7D,qBAA+C,EAAC;AAAA,EAEhD,eAAe,CAAc,EAAA;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,cAAc,CAAc,EAAA;AAC1B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,eAAe,CAAc,EAAA;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,mBAAmB,OAAiC,EAAA;AAClD,IAAK,IAAA,CAAA,kBAAA,CAAmB,KAAK,OAAO,CAAA;AAAA;AACtC,EAEA,IAAI,iBAAoB,GAAA;AACtB,IAAA,OA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A,CAAA,GAAA;AAAA,UACT,MAAMC,yCAAqB,CAAA;AAAA,YACzB,QAAA;AAAA,YACA,SAAA;AAAA,YACA,MAAA;AAAA,YACA,QAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAEA,QAAA,UAAA,CAAW,aAAc,CAAA;AAAA,UACvB,KAAO,EAAA,iBAAA;AAAA,UACP,IAAM,EAAA;AAAA,SACP,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
1
+ {"version":3,"file":"EventsPlugin.cjs.js","sources":["../../src/service/EventsPlugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createBackendPlugin,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport {\n eventsExtensionPoint,\n EventsExtensionPoint,\n} from '@backstage/plugin-events-node/alpha';\nimport {\n eventsServiceRef,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\nimport Router from 'express-promise-router';\nimport { HttpPostIngressEventPublisher } from './http';\nimport { createEventBusRouter } from './hub';\n\nclass EventsExtensionPointImpl implements EventsExtensionPoint {\n #httpPostIngresses: HttpPostIngressOptions[] = [];\n\n setEventBroker(_: any): void {\n throw new Error(\n 'setEventBroker is not supported anymore; use eventsServiceRef instead',\n );\n }\n\n addPublishers(_: any): void {\n throw new Error(\n 'addPublishers is not supported anymore; use EventsService instead',\n );\n }\n\n addSubscribers(_: any): void {\n throw new Error(\n 'addSubscribers is not supported anymore; use EventsService instead',\n );\n }\n\n addHttpPostIngress(options: HttpPostIngressOptions) {\n this.#httpPostIngresses.push(options);\n }\n\n get httpPostIngresses() {\n return this.#httpPostIngresses;\n }\n}\n\n/**\n * Events plugin\n *\n * @public\n */\nexport const eventsPlugin = createBackendPlugin({\n pluginId: 'events',\n register(env) {\n const extensionPoint = new EventsExtensionPointImpl();\n env.registerExtensionPoint(eventsExtensionPoint, extensionPoint);\n\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n events: eventsServiceRef,\n database: coreServices.database,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n lifecycle: coreServices.lifecycle,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({\n config,\n events,\n database,\n httpAuth,\n httpRouter,\n lifecycle,\n logger,\n scheduler,\n }) {\n const ingresses = Object.fromEntries(\n extensionPoint.httpPostIngresses.map(ingress => [\n ingress.topic,\n ingress as Omit<HttpPostIngressOptions, 'topic'>,\n ]),\n );\n\n const http = HttpPostIngressEventPublisher.fromConfig({\n config,\n events,\n ingresses,\n logger,\n });\n const eventsRouter = Router();\n http.bind(eventsRouter);\n\n // MUST be registered *before* the event bus router.\n // Otherwise, it would already make use of `express.json()`\n // that is used there as part of the middleware stack.\n httpRouter.use(eventsRouter);\n\n const notifyTimeoutMs = config.getOptionalNumber(\n 'events.notifyTimeoutMs',\n );\n\n httpRouter.use(\n await createEventBusRouter({\n database,\n lifecycle,\n logger,\n httpAuth,\n scheduler,\n notifyTimeoutMs,\n }),\n );\n\n httpRouter.addAuthPolicy({\n allow: 'unauthenticated',\n path: '/http',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","eventsExtensionPoint","coreServices","eventsServiceRef","HttpPostIngressEventPublisher","Router","createEventBusRouter"],"mappings":";;;;;;;;;;;;;AAgCA,MAAM,wBAAyD,CAAA;AAAA,EAC7D,qBAA+C,EAAC;AAAA,EAEhD,eAAe,CAAc,EAAA;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,cAAc,CAAc,EAAA;AA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ACD;AAAA,SACH;AAEA,QAAM,MAAA,IAAA,GAAOE,4DAA8B,UAAW,CAAA;AAAA,UACpD,MAAA;AAAA,UACA,MAAA;AAAA,UACA,SAAA;AAAA,UACA;AAAA,SACD,CAAA;AACD,QAAA,MAAM,eAAeC,uBAAO,EAAA;AAC5B,QAAA,IAAA,CAAK,KAAK,YAAY,CAAA;AAKtB,QAAA,UAAA,CAAW,IAAI,YAAY,CAAA;AAE3B,QAAA,MAAM,kBAAkB,MAAO,CAAA,iBAAA;AAAA,UAC7B;AAAA,SACF;AAEA,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAMC,yCAAqB,CAAA;AAAA,YACzB,QAAA;AAAA,YACA,SAAA;AAAA,YACA,MAAA;AAAA,YACA,QAAA;AAAA,YACA,SAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAEA,QAAA,UAAA,CAAW,aAAc,CAAA;AAAA,UACvB,KAAO,EAAA,iBAAA;AAAA,UACP,IAAM,EAAA;AAAA,SACP,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var openapi_generated = require('../../schema/openapi.generated.cjs.js');
3
+ var router = require('../../schema/openapi/generated/router.cjs.js');
4
4
  var MemoryEventBusStore = require('./MemoryEventBusStore.cjs.js');
5
5
  var DatabaseEventBusStore = require('./DatabaseEventBusStore.cjs.js');
6
+ var pluginEventsNode = require('@backstage/plugin-events-node');
6
7
 
7
8
  const DEFAULT_NOTIFY_TIMEOUT_MS = 55e3;
8
9
  async function createEventBusStore(deps) {
@@ -18,7 +19,7 @@ async function createEventBusRouter(options) {
18
19
  const { httpAuth, notifyTimeoutMs = DEFAULT_NOTIFY_TIMEOUT_MS } = options;
19
20
  const logger = options.logger.child({ type: "EventBus" });
20
21
  const store = await createEventBusStore(options);
21
- const apiRouter = await openapi_generated.createOpenApiRouter();
22
+ const apiRouter = await router.createOpenApiRouter();
22
23
  apiRouter.post("/bus/v1/events", async (req, res) => {
23
24
  const credentials = await httpAuth.credentials(req, {
24
25
  allow: ["service"]
@@ -86,6 +87,10 @@ async function createEventBusRouter(options) {
86
87
  }))
87
88
  });
88
89
  } else {
90
+ res.setHeader(
91
+ pluginEventsNode.EVENTS_NOTIFY_TIMEOUT_HEADER,
92
+ notifyTimeoutMs.toString()
93
+ );
89
94
  res.status(202);
90
95
  res.flushHeaders();
91
96
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"createEventBusRouter.cjs.js","sources":["../../../src/service/hub/createEventBusRouter.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DatabaseService,\n HttpAuthService,\n LifecycleService,\n LoggerService,\n SchedulerService,\n} from '@backstage/backend-plugin-api';\nimport { Handler } from 'express';\nimport { createOpenApiRouter } from '../../schema/openapi.generated';\nimport { MemoryEventBusStore } from './MemoryEventBusStore';\nimport { DatabaseEventBusStore } from './DatabaseEventBusStore';\nimport { EventBusStore } from './types';\nimport { EventParams } from '@backstage/plugin-events-node';\n\nconst DEFAULT_NOTIFY_TIMEOUT_MS = 55_000; // Just below 60s, which is a common HTTP timeout\n\n/*\n\n# Event Bus\n\nThis comment describes the event bus that is implemented here in the events\nbackend, and by default used by the events service.\n\n## Overview\n\nThe events bus implements a subscription mechanism where subscribers must exist\nupfront for events to be stored. It uses a single inbox for all events, with\neach subscriber having its own pointer for how far into the inbox it has read.\n\nIn order to avoid busy polling, the API uses a long-polling mechanism where a\nrequest is left hanging until the client should try to read again.\n\nThe event bus is not implemented with any guarantees of events being consumed,\nbut it does aim to make it unlikely that events are dropped\n\n## API\n\n### POST /bus/v1/events\n\nThis endpoint is used to publish new events to the event bus on a specific\ntopic. It can optionally include a set of subscription IDs for subscribers that\nhave already been notified of the event. This is to enable an optimization where\nwe notify subscribers locally if possible, and avoid the need for events to be\nrelayed through the events bus at all of possible.\n\nFor an event to be published and stored there must already exist a subscriber\nthat is subscribed to the event's topic, and that hasn't already been notified\nof the event. If no such subscriber is found, the event will be discarded.\n\n### PUT /bus/v1/subscriptions/:subscriptionId\n\nThis endpoint is used to create or update a subscriptions. Subscriptions are\nshared across the entire bus and divided by subscription ID. Multiple clients\ncan be reading events from the same subscription at the same time, but only one\nof those clients will receive each event. This enables division of work by using\nthe same subscriber ID across multiple instances, as well as broadcasting by\nensuring separate subscribers IDs.\n\n### GET /bus/v1/subscriptions/:subscriptionId/events\n\nThis endpoint is used to read events from a subscription. It will return a batch\nof events for the subscribed topics that have not yet been read by the\nsubscription. If no such events are available, the endpoint will return a 202\nresponse and then hang end response until an event is available or a timeout is\nreached. This allows clients to call this endpoint in a loop but will keep\ntraffic overhead fairly low.\n\n## Delivery guarantees\n\nWhen reading events from the event bus, clients should always implement a\ngraceful shutdown where they process any events that are received from the\nevents endpoint before shutting down. This is also the reason that the events\nendpoint does not return any events when responding with a 202 blocking the\nresponse, because there would otherwise be a race condition where the events\nmight be lost in transit if the client shuts down. By always sending an empty\nresponse and requiring the client to send another request, we ensure that the\nclient is prepared to halt shutdown until the request had been fully processed.\n\n## Local processing optimization\n\nWhen possible, events will be processed locally before sent to the event bus.\nThe client will also inform the bus of which subscriptions have already been\nnotified of the event, so that the bus can completely avoid storing an event if\nit has already been fully consumed by all subscribers.\n\n## Automated cleanup & event window\n\nEvents are deleted once they are outside the guaranteed storage window. By\ndefault the window 10 minutes for all events, and 24 hours for the last 10000\nevents. This ensures that the event log doesn't grow indefinitely, while still\nallowing subscribers with restarts or outages to catch up to past events,\nensuring that events are likely not lost.\n\nSubscriptions are also cleaned up if their read pointer falls outside of the\ncurrent event window. This ensures that stale subscribers don't accumulate and\ncause unnecessary storage of events.\n\n*/\n\nasync function createEventBusStore(deps: {\n logger: LoggerService;\n database: DatabaseService;\n scheduler: SchedulerService;\n lifecycle: LifecycleService;\n httpAuth: HttpAuthService;\n}): Promise<EventBusStore> {\n const db = await deps.database.getClient();\n if (db.client.config.client === 'pg') {\n deps.logger.info('Database is PostgreSQL, using database store');\n return await DatabaseEventBusStore.create(deps);\n }\n\n deps.logger.info('Database is not PostgreSQL, using memory store');\n return new MemoryEventBusStore();\n}\n\n/**\n * Creates a new event bus router\n * @internal\n */\nexport async function createEventBusRouter(options: {\n logger: LoggerService;\n database: DatabaseService;\n scheduler: SchedulerService;\n lifecycle: LifecycleService;\n httpAuth: HttpAuthService;\n notifyTimeoutMs?: number; // for testing\n}): Promise<Handler> {\n const { httpAuth, notifyTimeoutMs = DEFAULT_NOTIFY_TIMEOUT_MS } = options;\n const logger = options.logger.child({ type: 'EventBus' });\n\n const store = await createEventBusStore(options);\n\n const apiRouter = await createOpenApiRouter();\n\n apiRouter.post('/bus/v1/events', async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const topic = req.body.event.topic;\n const notifiedSubscribers = req.body.notifiedSubscribers;\n const result = await store.publish({\n event: {\n topic,\n eventPayload: req.body.event.payload,\n } as EventParams,\n notifiedSubscribers,\n credentials,\n });\n if (result) {\n logger.debug(\n `Published event to '${topic}' with ID '${result.eventId}'`,\n {\n subject: credentials.principal.subject,\n },\n );\n res.status(201).end();\n } else {\n if (notifiedSubscribers) {\n const notified = `'${notifiedSubscribers.join(\"', '\")}'`;\n logger.debug(\n `Skipped publishing of event to '${topic}', subscribers have already been notified: ${notified}`,\n { subject: credentials.principal.subject },\n );\n } else {\n logger.debug(\n `Skipped publishing of event to '${topic}', no subscribers present`,\n { subject: credentials.principal.subject },\n );\n }\n res.status(204).end();\n }\n });\n\n apiRouter.get(\n '/bus/v1/subscriptions/:subscriptionId/events',\n async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const id = req.params.subscriptionId;\n\n const controller = new AbortController();\n req.on('end', () => controller.abort());\n\n // By setting up the listener first we make sure we don't miss any events\n // that are published while reading. If an event is published we'll receive\n // a notification, which we may ignore depending on the outcome of the read\n const listener = await store.setupListener(id, {\n signal: controller.signal,\n });\n\n // By timing out requests we make sure they don't stall or that events get stuck.\n // For the caller there's no difference between a timeout and a\n // notification, either way they should try reading again.\n const timeout = setTimeout(() => {\n controller.abort();\n }, notifyTimeoutMs);\n\n try {\n const { events } = await store.readSubscription(id);\n\n logger.debug(\n `Reading subscription '${id}' resulted in ${events.length} events`,\n { subject: credentials.principal.subject },\n );\n\n if (events.length > 0) {\n res.json({\n events: events.map(event => ({\n topic: event.topic,\n payload: event.eventPayload,\n })),\n });\n } else {\n res.status(202);\n res.flushHeaders();\n\n try {\n const { topic } = await listener.waitForUpdate();\n logger.debug(\n `Received notification for subscription '${id}' for topic '${topic}'`,\n { subject: credentials.principal.subject },\n );\n } catch (error) {\n if (error !== controller.signal.reason) {\n logger.error(`Error listening for subscription '${id}'`, error);\n }\n } finally {\n // A small extra delay ensures a more even spread of events across\n // consumers in case some consumers are faster than others\n await new Promise(resolve =>\n setTimeout(resolve, 1 + Math.random() * 9),\n );\n res.end();\n }\n }\n } finally {\n controller.abort();\n clearTimeout(timeout);\n }\n },\n );\n\n apiRouter.put('/bus/v1/subscriptions/:subscriptionId', async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const id = req.params.subscriptionId;\n\n await store.upsertSubscription(id, req.body.topics, credentials);\n\n logger.debug(\n `New subscription '${id}' for topics '${req.body.topics.join(\"', '\")}'`,\n { subject: credentials.principal.subject },\n );\n\n res.status(201).end();\n });\n\n return apiRouter;\n}\n"],"names":["DatabaseEventBusStore","MemoryEventBusStore","createOpenApiRouter"],"mappings":";;;;;;AA8BA,MAAM,yBAA4B,GAAA,IAAA;AAqFlC,eAAe,oBAA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createEventBusRouter.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DatabaseService,\n HttpAuthService,\n LifecycleService,\n LoggerService,\n SchedulerService,\n} from '@backstage/backend-plugin-api';\nimport { Handler } from 'express';\nimport { createOpenApiRouter } from '../../schema/openapi';\nimport { MemoryEventBusStore } from './MemoryEventBusStore';\nimport { DatabaseEventBusStore } from './DatabaseEventBusStore';\nimport { EventBusStore } from './types';\nimport {\n EVENTS_NOTIFY_TIMEOUT_HEADER,\n EventParams,\n} from '@backstage/plugin-events-node';\n\nconst DEFAULT_NOTIFY_TIMEOUT_MS = 55_000; // Just below 60s, which is a common HTTP timeout\n\n/*\n\n# Event Bus\n\nThis comment describes the event bus that is implemented here in the events\nbackend, and by default used by the events service.\n\n## Overview\n\nThe events bus implements a subscription mechanism where subscribers must exist\nupfront for events to be stored. It uses a single inbox for all events, with\neach subscriber having its own pointer for how far into the inbox it has read.\n\nIn order to avoid busy polling, the API uses a long-polling mechanism where a\nrequest is left hanging until the client should try to read again.\n\nThe event bus is not implemented with any guarantees of events being consumed,\nbut it does aim to make it unlikely that events are dropped\n\n## API\n\n### POST /bus/v1/events\n\nThis endpoint is used to publish new events to the event bus on a specific\ntopic. It can optionally include a set of subscription IDs for subscribers that\nhave already been notified of the event. This is to enable an optimization where\nwe notify subscribers locally if possible, and avoid the need for events to be\nrelayed through the events bus at all of possible.\n\nFor an event to be published and stored there must already exist a subscriber\nthat is subscribed to the event's topic, and that hasn't already been notified\nof the event. If no such subscriber is found, the event will be discarded.\n\n### PUT /bus/v1/subscriptions/:subscriptionId\n\nThis endpoint is used to create or update a subscriptions. Subscriptions are\nshared across the entire bus and divided by subscription ID. Multiple clients\ncan be reading events from the same subscription at the same time, but only one\nof those clients will receive each event. This enables division of work by using\nthe same subscriber ID across multiple instances, as well as broadcasting by\nensuring separate subscribers IDs.\n\n### GET /bus/v1/subscriptions/:subscriptionId/events\n\nThis endpoint is used to read events from a subscription. It will return a batch\nof events for the subscribed topics that have not yet been read by the\nsubscription. If no such events are available, the endpoint will return a 202\nresponse and then hang end response until an event is available or a timeout is\nreached. This allows clients to call this endpoint in a loop but will keep\ntraffic overhead fairly low.\n\n## Delivery guarantees\n\nWhen reading events from the event bus, clients should always implement a\ngraceful shutdown where they process any events that are received from the\nevents endpoint before shutting down. This is also the reason that the events\nendpoint does not return any events when responding with a 202 blocking the\nresponse, because there would otherwise be a race condition where the events\nmight be lost in transit if the client shuts down. By always sending an empty\nresponse and requiring the client to send another request, we ensure that the\nclient is prepared to halt shutdown until the request had been fully processed.\n\n## Local processing optimization\n\nWhen possible, events will be processed locally before sent to the event bus.\nThe client will also inform the bus of which subscriptions have already been\nnotified of the event, so that the bus can completely avoid storing an event if\nit has already been fully consumed by all subscribers.\n\n## Automated cleanup & event window\n\nEvents are deleted once they are outside the guaranteed storage window. By\ndefault the window 10 minutes for all events, and 24 hours for the last 10000\nevents. This ensures that the event log doesn't grow indefinitely, while still\nallowing subscribers with restarts or outages to catch up to past events,\nensuring that events are likely not lost.\n\nSubscriptions are also cleaned up if their read pointer falls outside of the\ncurrent event window. This ensures that stale subscribers don't accumulate and\ncause unnecessary storage of events.\n\n*/\n\nasync function createEventBusStore(deps: {\n logger: LoggerService;\n database: DatabaseService;\n scheduler: SchedulerService;\n lifecycle: LifecycleService;\n httpAuth: HttpAuthService;\n}): Promise<EventBusStore> {\n const db = await deps.database.getClient();\n if (db.client.config.client === 'pg') {\n deps.logger.info('Database is PostgreSQL, using database store');\n return await DatabaseEventBusStore.create(deps);\n }\n\n deps.logger.info('Database is not PostgreSQL, using memory store');\n return new MemoryEventBusStore();\n}\n\n/**\n * Creates a new event bus router\n * @internal\n */\nexport async function createEventBusRouter(options: {\n logger: LoggerService;\n database: DatabaseService;\n scheduler: SchedulerService;\n lifecycle: LifecycleService;\n httpAuth: HttpAuthService;\n notifyTimeoutMs?: number; // for testing\n}): Promise<Handler> {\n const { httpAuth, notifyTimeoutMs = DEFAULT_NOTIFY_TIMEOUT_MS } = options;\n const logger = options.logger.child({ type: 'EventBus' });\n\n const store = await createEventBusStore(options);\n\n const apiRouter = await createOpenApiRouter();\n\n apiRouter.post('/bus/v1/events', async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const topic = req.body.event.topic;\n const notifiedSubscribers = req.body.notifiedSubscribers;\n const result = await store.publish({\n event: {\n topic,\n eventPayload: req.body.event.payload,\n } as EventParams,\n notifiedSubscribers,\n credentials,\n });\n if (result) {\n logger.debug(\n `Published event to '${topic}' with ID '${result.eventId}'`,\n {\n subject: credentials.principal.subject,\n },\n );\n res.status(201).end();\n } else {\n if (notifiedSubscribers) {\n const notified = `'${notifiedSubscribers.join(\"', '\")}'`;\n logger.debug(\n `Skipped publishing of event to '${topic}', subscribers have already been notified: ${notified}`,\n { subject: credentials.principal.subject },\n );\n } else {\n logger.debug(\n `Skipped publishing of event to '${topic}', no subscribers present`,\n { subject: credentials.principal.subject },\n );\n }\n res.status(204).end();\n }\n });\n\n apiRouter.get(\n '/bus/v1/subscriptions/:subscriptionId/events',\n async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const id = req.params.subscriptionId;\n\n const controller = new AbortController();\n req.on('end', () => controller.abort());\n\n // By setting up the listener first we make sure we don't miss any events\n // that are published while reading. If an event is published we'll receive\n // a notification, which we may ignore depending on the outcome of the read\n const listener = await store.setupListener(id, {\n signal: controller.signal,\n });\n\n // By timing out requests we make sure they don't stall or that events get stuck.\n // For the caller there's no difference between a timeout and a\n // notification, either way they should try reading again.\n const timeout = setTimeout(() => {\n controller.abort();\n }, notifyTimeoutMs);\n\n try {\n const { events } = await store.readSubscription(id);\n\n logger.debug(\n `Reading subscription '${id}' resulted in ${events.length} events`,\n { subject: credentials.principal.subject },\n );\n\n if (events.length > 0) {\n res.json({\n events: events.map(event => ({\n topic: event.topic,\n payload: event.eventPayload,\n })),\n });\n } else {\n res.setHeader(\n EVENTS_NOTIFY_TIMEOUT_HEADER,\n notifyTimeoutMs.toString(),\n );\n res.status(202);\n res.flushHeaders();\n\n try {\n const { topic } = await listener.waitForUpdate();\n logger.debug(\n `Received notification for subscription '${id}' for topic '${topic}'`,\n { subject: credentials.principal.subject },\n );\n } catch (error) {\n if (error !== controller.signal.reason) {\n logger.error(`Error listening for subscription '${id}'`, error);\n }\n } finally {\n // A small extra delay ensures a more even spread of events across\n // consumers in case some consumers are faster than others\n await new Promise(resolve =>\n setTimeout(resolve, 1 + Math.random() * 9),\n );\n res.end();\n }\n }\n } finally {\n controller.abort();\n clearTimeout(timeout);\n }\n },\n );\n\n apiRouter.put('/bus/v1/subscriptions/:subscriptionId', async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const id = req.params.subscriptionId;\n\n await store.upsertSubscription(id, req.body.topics, credentials);\n\n logger.debug(\n `New subscription '${id}' for topics '${req.body.topics.join(\"', '\")}'`,\n { subject: credentials.principal.subject },\n );\n\n res.status(201).end();\n });\n\n return apiRouter;\n}\n"],"names":["DatabaseEventBusStore","MemoryEventBusStore","createOpenApiRouter","EVENTS_NOTIFY_TIMEOUT_HEADER"],"mappings":";;;;;;;AAiCA,MAAM,yBAA4B,GAAA,IAAA;AAqFlC,eAAe,oBAAoB,IAMR,EAAA;AACzB,EAAA,MAAM,EAAK,GAAA,MAAM,IAAK,CAAA,QAAA,CAAS,SAAU,EAAA;AACzC,EAAA,IAAI,EAAG,CAAA,MAAA,CAAO,MAAO,CAAA,MAAA,KAAW,IAAM,EAAA;AACpC,IAAK,IAAA,CAAA,MAAA,CA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A,kCAAA,EAAqC,EAAE,CAAA,CAAA,CAAA,EAAK,KAAK,CAAA;AAAA;AAChE,WACA,SAAA;AAGA,YAAA,MAAM,IAAI,OAAA;AAAA,cAAQ,aAChB,UAAW,CAAA,OAAA,EAAS,IAAI,IAAK,CAAA,MAAA,KAAW,CAAC;AAAA,aAC3C;AACA,YAAA,GAAA,CAAI,GAAI,EAAA;AAAA;AACV;AACF,OACA,SAAA;AACA,QAAA,UAAA,CAAW,KAAM,EAAA;AACjB,QAAA,YAAA,CAAa,OAAO,CAAA;AAAA;AACtB;AACF,GACF;AAEA,EAAA,SAAA,CAAU,GAAI,CAAA,uCAAA,EAAyC,OAAO,GAAA,EAAK,GAAQ,KAAA;AACzE,IAAA,MAAM,WAAc,GAAA,MAAM,QAAS,CAAA,WAAA,CAAY,GAAK,EAAA;AAAA,MAClD,KAAA,EAAO,CAAC,SAAS;AAAA,KAClB,CAAA;AACD,IAAM,MAAA,EAAA,GAAK,IAAI,MAAO,CAAA,cAAA;AAEtB,IAAA,MAAM,MAAM,kBAAmB,CAAA,EAAA,EAAI,GAAI,CAAA,IAAA,CAAK,QAAQ,WAAW,CAAA;AAE/D,IAAO,MAAA,CAAA,KAAA;AAAA,MACL,CAAA,kBAAA,EAAqB,EAAE,CAAiB,cAAA,EAAA,GAAA,CAAI,KAAK,MAAO,CAAA,IAAA,CAAK,MAAM,CAAC,CAAA,CAAA,CAAA;AAAA,MACpE,EAAE,OAAA,EAAS,WAAY,CAAA,SAAA,CAAU,OAAQ;AAAA,KAC3C;AAEA,IAAI,GAAA,CAAA,MAAA,CAAO,GAAG,CAAA,CAAE,GAAI,EAAA;AAAA,GACrB,CAAA;AAED,EAAO,OAAA,SAAA;AACT;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-backend",
3
- "version": "0.3.16",
3
+ "version": "0.4.0-next.1",
4
4
  "backstage": {
5
5
  "role": "backend-plugin",
6
6
  "pluginId": "events",
@@ -64,12 +64,12 @@
64
64
  },
65
65
  "dependencies": {
66
66
  "@backstage/backend-common": "^0.25.0",
67
- "@backstage/backend-openapi-utils": "^0.3.0",
68
- "@backstage/backend-plugin-api": "^1.0.2",
69
- "@backstage/config": "^1.3.0",
70
- "@backstage/errors": "^1.2.5",
71
- "@backstage/plugin-events-node": "^0.4.5",
72
- "@backstage/types": "^1.2.0",
67
+ "@backstage/backend-openapi-utils": "0.3.1-next.1",
68
+ "@backstage/backend-plugin-api": "1.1.0-next.1",
69
+ "@backstage/config": "1.3.0",
70
+ "@backstage/errors": "1.2.5",
71
+ "@backstage/plugin-events-node": "0.4.6-next.1",
72
+ "@backstage/types": "1.2.0",
73
73
  "@types/express": "^4.17.6",
74
74
  "content-type": "^1.0.5",
75
75
  "express": "^4.17.1",
@@ -78,12 +78,12 @@
78
78
  "winston": "^3.2.1"
79
79
  },
80
80
  "devDependencies": {
81
- "@backstage/backend-app-api": "^1.0.2",
82
- "@backstage/backend-defaults": "^0.5.3",
83
- "@backstage/backend-test-utils": "^1.1.0",
84
- "@backstage/cli": "^0.29.0",
85
- "@backstage/plugin-events-backend-test-utils": "^0.1.38",
86
- "@backstage/repo-tools": "^0.11.0",
81
+ "@backstage/backend-app-api": "1.1.0-next.1",
82
+ "@backstage/backend-defaults": "0.6.0-next.1",
83
+ "@backstage/backend-test-utils": "1.2.0-next.1",
84
+ "@backstage/cli": "0.29.3-next.1",
85
+ "@backstage/plugin-events-backend-test-utils": "0.1.39-next.1",
86
+ "@backstage/repo-tools": "0.12.0-next.1",
87
87
  "@types/content-type": "^1.1.8",
88
88
  "supertest": "^7.0.0"
89
89
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"openapi.generated.cjs.js","sources":["../../src/schema/openapi.generated.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// ******************************************************************\n// * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. *\n// ******************************************************************\nimport { createValidatedOpenApiRouter } from '@backstage/backend-openapi-utils';\n\nexport const spec = {\n openapi: '3.0.3',\n info: {\n title: 'events',\n version: '1',\n description: 'The Backstage backend plugin that powers the events system.',\n license: {\n name: 'Apache-2.0',\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html',\n },\n contact: {},\n },\n servers: [\n {\n url: '/',\n },\n ],\n components: {\n examples: {},\n headers: {},\n parameters: {\n subscriptionId: {\n name: 'subscriptionId',\n in: 'path',\n required: true,\n allowReserved: true,\n schema: {\n type: 'string',\n },\n },\n },\n requestBodies: {},\n responses: {\n ErrorResponse: {\n description: 'An error response from the backend.',\n content: {\n 'application/json; charset=utf-8': {\n schema: {\n $ref: '#/components/schemas/Error',\n },\n },\n },\n },\n },\n schemas: {\n Event: {\n type: 'object',\n required: ['topic', 'payload'],\n properties: {\n topic: {\n type: 'string',\n description: 'The topic that the event is published on',\n },\n payload: {\n description: 'The event payload',\n },\n },\n },\n Error: {\n type: 'object',\n properties: {\n error: {\n type: 'object',\n properties: {\n name: {\n type: 'string',\n },\n message: {\n type: 'string',\n },\n },\n required: ['name', 'message'],\n },\n request: {\n type: 'object',\n properties: {\n method: {\n type: 'string',\n },\n url: {\n type: 'string',\n },\n },\n required: ['method', 'url'],\n },\n response: {\n type: 'object',\n properties: {\n statusCode: {\n type: 'number',\n },\n },\n required: ['statusCode'],\n },\n },\n required: ['error', 'request', 'response'],\n },\n },\n securitySchemes: {\n JWT: {\n type: 'http',\n scheme: 'bearer',\n bearerFormat: 'JWT',\n },\n },\n },\n paths: {\n '/bus/v1/events': {\n post: {\n operationId: 'PostEvent',\n description: 'Publish a new event',\n responses: {\n '201': {\n description: 'The event was published successfully',\n },\n '204': {\n description:\n 'The event did not need to be published as all subscribers have already been notified',\n },\n default: {\n $ref: '#/components/responses/ErrorResponse',\n },\n },\n security: [\n {},\n {\n JWT: [],\n },\n ],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['event'],\n properties: {\n event: {\n $ref: '#/components/schemas/Event',\n },\n notifiedSubscribers: {\n type: 'array',\n description:\n 'The IDs of subscriptions that have already received this event',\n items: {\n type: 'string',\n },\n },\n },\n },\n examples: {\n 'Publishing a simple Event': {\n value: {\n event: {\n topic: 'test-topic',\n payload: {\n myData: 'foo',\n },\n },\n },\n },\n },\n },\n },\n },\n },\n },\n '/bus/v1/subscriptions/{subscriptionId}': {\n put: {\n operationId: 'PutSubscription',\n description:\n 'Ensures that the subscription exists with the provided configuration',\n responses: {\n '201': {\n description: 'The subscription exists or was created successfully',\n },\n default: {\n $ref: '#/components/responses/ErrorResponse',\n },\n },\n security: [\n {},\n {\n JWT: [],\n },\n ],\n parameters: [\n {\n $ref: '#/components/parameters/subscriptionId',\n },\n ],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['topics'],\n properties: {\n topics: {\n type: 'array',\n description: 'The topics to subscribe to',\n items: {\n type: 'string',\n },\n },\n },\n },\n examples: {\n 'Subscribing to a single topic': {\n value: {\n topics: ['test-topic'],\n },\n },\n },\n },\n },\n },\n },\n },\n '/bus/v1/subscriptions/{subscriptionId}/events': {\n get: {\n operationId: 'GetSubscriptionEvents',\n description: 'Get new events for the provided subscription',\n responses: {\n '200': {\n description: 'New events',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['events'],\n properties: {\n events: {\n type: 'array',\n items: {\n $ref: '#/components/schemas/Event',\n },\n },\n },\n },\n },\n },\n },\n '202': {\n description:\n 'No new events are available. Response will block until the client should try again.',\n },\n default: {\n $ref: '#/components/responses/ErrorResponse',\n },\n },\n security: [\n {},\n {\n JWT: [],\n },\n ],\n parameters: [\n {\n $ref: '#/components/parameters/subscriptionId',\n },\n ],\n },\n },\n },\n} as const;\nexport const createOpenApiRouter = async (\n options?: Parameters<typeof createValidatedOpenApiRouter>['1'],\n) => createValidatedOpenApiRouter<typeof spec>(spec, options);\n"],"names":["createValidatedOpenApiRouter"],"mappings":";;;;AAqBO,MAAM,IAAO,GAAA;AAAA,EAClB,OAAS,EAAA,OAAA;AAAA,EACT,IAAM,EAAA;AAAA,IACJ,KAAO,EAAA,QAAA;AAAA,IACP,OAAS,EAAA,GAAA;AAAA,IACT,WAAa,EAAA,6DAAA;AAAA,IACb,OAAS,EAAA;AAAA,MACP,IAAM,EAAA,YAAA;AAAA,MACN,GAAK,EAAA;AAAA,KACP;AAAA,IACA,SAAS;AAAC,GACZ;AAAA,EACA,OAAS,EAAA;AAAA,IACP;AAAA,MACE,GAAK,EAAA;AAAA;AACP,GACF;AAAA,EACA,UAAY,EAAA;AAAA,IACV,UAAU,EAAC;AAAA,IACX,SAAS,EAAC;AAAA,IACV,UAAY,EAAA;AAAA,MACV,cAAgB,EAAA;AAAA,QACd,IAAM,EAAA,gBAAA;AAAA,QACN,EAAI,EAAA,MAAA;AAAA,QACJ,QAAU,EAAA,IAAA;AAAA,QACV,aAAe,EAAA,IAAA;AAAA,QACf,MAAQ,EAAA;AAAA,UACN,IAAM,EAAA;AAAA;AACR;AACF,KACF;AAAA,IACA,eAAe,EAAC;AAAA,IAChB,SAAW,EAAA;AAAA,MACT,aAAe,EAAA;AAAA,QACb,WAAa,EAAA,qCAAA;AAAA,QACb,OAAS,EAAA;AAAA,UACP,iCAAmC,EAAA;AAAA,YACjC,MAAQ,EAAA;AAAA,cACN,IAAM,EAAA;AAAA;AACR;AACF;AACF;AACF,KACF;AAAA,IACA,OAAS,EAAA;AAAA,MACP,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,OAAA,EAAS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