@backstage/plugin-events-node 0.4.4 → 0.4.5-next.3
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 +28 -7
- package/dist/api/DefaultEventsService.cjs.js.map +1 -1
- package/dist/api/EventRouter.cjs.js.map +1 -1
- package/dist/api/SubTopicEventRouter.cjs.js.map +1 -1
- package/dist/extensions.cjs.js.map +1 -1
- package/dist/generated/apis/DefaultApi.client.cjs.js.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/service.cjs.js.map +1 -1
- package/package.json +17 -8
- package/alpha/package.json +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
# @backstage/plugin-events-node
|
|
2
2
|
|
|
3
|
-
## 0.4.
|
|
3
|
+
## 0.4.5-next.3
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- 9816f51: Add raw body information to `RequestDetails`
|
|
8
|
+
and use the raw body when validating incoming event requests.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @backstage/backend-plugin-api@1.0.2-next.2
|
|
11
|
+
- @backstage/errors@1.2.4
|
|
12
|
+
- @backstage/types@1.1.1
|
|
13
|
+
|
|
14
|
+
## 0.4.5-next.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 0b57aa1: Fixed an issue where the event bus polling would duplicate and increase exponentially over time.
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @backstage/backend-plugin-api@1.0.2-next.2
|
|
21
|
+
- @backstage/errors@1.2.4
|
|
22
|
+
- @backstage/types@1.1.1
|
|
8
23
|
|
|
9
|
-
## 0.4.
|
|
24
|
+
## 0.4.4-next.1
|
|
10
25
|
|
|
11
26
|
### Patch Changes
|
|
12
27
|
|
|
13
|
-
-
|
|
28
|
+
- Updated dependencies
|
|
29
|
+
- @backstage/backend-plugin-api@1.0.2-next.1
|
|
30
|
+
- @backstage/errors@1.2.4
|
|
31
|
+
- @backstage/types@1.1.1
|
|
14
32
|
|
|
15
|
-
## 0.4.
|
|
33
|
+
## 0.4.3-next.0
|
|
16
34
|
|
|
17
35
|
### Patch Changes
|
|
18
36
|
|
|
19
|
-
-
|
|
37
|
+
- 4501631: Fixed an issue where subscribing to events threw an error and gave up too easily. Calling the subscribe method will cause the background polling loop to keep trying to connect to the events backend, even if the initial request fails.
|
|
20
38
|
|
|
21
39
|
By default the events service will attempt to publish and subscribe to events from the events bus API in the events backend, but if it fails due to the events backend not being installed, it will bail and never try calling the API again. There is now a new `events.useEventBus` configuration and option for the `DefaultEventsService` that lets you control this behavior. You can set it to `'never'` to disabled API calls to the events backend completely, or `'always'` to never allow it to be disabled.
|
|
22
40
|
|
|
41
|
+
- e02a02b: Fix `events.useEventBus` by propagating config to `DefaultEventsService`
|
|
23
42
|
- Updated dependencies
|
|
24
|
-
- @backstage/backend-plugin-api@1.0.
|
|
43
|
+
- @backstage/backend-plugin-api@1.0.2-next.0
|
|
44
|
+
- @backstage/errors@1.2.4
|
|
45
|
+
- @backstage/types@1.1.1
|
|
25
46
|
|
|
26
47
|
## 0.4.1
|
|
27
48
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultEventsService.cjs.js","sources":["../../src/api/DefaultEventsService.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 AuthService,\n DiscoveryService,\n LifecycleService,\n LoggerService,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport { EventParams } from './EventParams';\nimport { EventsService, EventsServiceSubscribeOptions } from './EventsService';\nimport { DefaultApiClient } from '../generated';\nimport { ResponseError } from '@backstage/errors';\n\nconst POLL_BACKOFF_START_MS = 1_000;\nconst POLL_BACKOFF_MAX_MS = 60_000;\nconst POLL_BACKOFF_FACTOR = 2;\n\nconst EVENT_BUS_MODES = ['never', 'always', 'auto'] as const;\n\n/**\n * @public\n */\nexport type EventBusMode = 'never' | 'always' | 'auto';\n\n/**\n * Local event bus for subscribers within the same process.\n *\n * When publishing events we'll keep track of which subscribers we managed to\n * reach locally, and forward those subscriber IDs to the events backend if it\n * is in use. The events backend will then both avoid forwarding the same events\n * to those subscribers again, but also avoid storing the event altogether if\n * there are no other subscribers.\n * @internal\n */\nexport class LocalEventBus {\n readonly #logger: LoggerService;\n\n readonly #subscribers = new Map<\n string,\n Omit<EventsServiceSubscribeOptions, 'topics'>[]\n >();\n\n constructor(logger: LoggerService) {\n this.#logger = logger;\n }\n\n async publish(\n params: EventParams,\n ): Promise<{ notifiedSubscribers: string[] }> {\n this.#logger.debug(\n `Event received: topic=${params.topic}, metadata=${JSON.stringify(\n params.metadata,\n )}, payload=${JSON.stringify(params.eventPayload)}`,\n );\n\n if (!this.#subscribers.has(params.topic)) {\n return { notifiedSubscribers: [] };\n }\n\n const onEventPromises: Promise<string>[] = [];\n this.#subscribers.get(params.topic)?.forEach(subscription => {\n onEventPromises.push(\n (async () => {\n try {\n await subscription.onEvent(params);\n } catch (error) {\n this.#logger.warn(\n `Subscriber \"${subscription.id}\" failed to process event for topic \"${params.topic}\"`,\n error,\n );\n }\n return subscription.id;\n })(),\n );\n });\n\n return { notifiedSubscribers: await Promise.all(onEventPromises) };\n }\n\n async subscribe(options: EventsServiceSubscribeOptions): Promise<void> {\n options.topics.forEach(topic => {\n if (!this.#subscribers.has(topic)) {\n this.#subscribers.set(topic, []);\n }\n\n this.#subscribers.get(topic)!.push({\n id: options.id,\n onEvent: options.onEvent,\n });\n });\n }\n}\n\n/**\n * Plugin specific events bus that delegates to the local bus, as well as the\n * events backend if it is available.\n */\nclass PluginEventsService implements EventsService {\n constructor(\n private readonly pluginId: string,\n private readonly localBus: LocalEventBus,\n private readonly logger: LoggerService,\n private readonly mode: EventBusMode,\n private client?: DefaultApiClient,\n private readonly auth?: AuthService,\n ) {}\n\n async publish(params: EventParams): Promise<void> {\n const lock = this.#getShutdownLock();\n if (!lock) {\n throw new Error('Service is shutting down');\n }\n try {\n const { notifiedSubscribers } = await this.localBus.publish(params);\n\n const client = this.client;\n if (!client) {\n return;\n }\n const token = await this.#getToken();\n if (!token) {\n return;\n }\n const res = await client.postEvent(\n {\n body: {\n event: { payload: params.eventPayload, topic: params.topic },\n notifiedSubscribers,\n },\n },\n { token },\n );\n\n if (!res.ok) {\n if (res.status === 404 && this.mode !== 'always') {\n this.logger.warn(\n `Event publish request failed with status 404, events backend not found. Future events will not be persisted.`,\n );\n delete this.client;\n return;\n }\n throw await ResponseError.fromResponse(res);\n }\n } finally {\n lock.release();\n }\n }\n\n async subscribe(options: EventsServiceSubscribeOptions): Promise<void> {\n const subscriptionId = `${this.pluginId}.${options.id}`;\n\n await this.localBus.subscribe({\n id: subscriptionId,\n topics: options.topics,\n onEvent: options.onEvent,\n });\n\n if (!this.client) {\n return;\n }\n\n this.#startPolling(subscriptionId, options.topics, options.onEvent);\n }\n\n #startPolling(\n subscriptionId: string,\n topics: string[],\n onEvent: EventsServiceSubscribeOptions['onEvent'],\n ) {\n let hasSubscription = false;\n let backoffMs = POLL_BACKOFF_START_MS;\n const poll = async () => {\n const client = this.client;\n if (!client) {\n return;\n }\n const lock = this.#getShutdownLock();\n if (!lock) {\n return; // shutting down\n }\n try {\n const token = await this.#getToken();\n if (!token) {\n return;\n }\n\n if (hasSubscription) {\n const res = await client.getSubscriptionEvents(\n {\n path: { subscriptionId },\n },\n { token },\n );\n\n if (res.status === 202) {\n // 202 means there were no immediately available events, but the\n // response will block until either new events are available or the\n // request times out. In both cases we should should try to read events\n // immediately again\n\n lock.release();\n // We don't actually expect any response body here, but waiting for\n // an empty body to be returned has been more reliable that waiting\n // for the response body stream to close.\n await res.text();\n } else if (res.status === 200) {\n const data = await res.json();\n if (data) {\n for (const event of data.events ?? []) {\n try {\n await onEvent({\n topic: event.topic,\n eventPayload: event.payload,\n });\n } catch (error) {\n this.logger.warn(\n `Subscriber \"${subscriptionId}\" failed to process event for topic \"${event.topic}\"`,\n error,\n );\n }\n }\n }\n } else {\n if (res.status === 404) {\n this.logger.info(\n `Polling event subscription resulted in a 404, recreating subscription`,\n );\n hasSubscription = false;\n } else {\n throw await ResponseError.fromResponse(res);\n }\n }\n }\n\n // If we haven't yet created the subscription, or if it was removed, create a new one\n if (!hasSubscription) {\n const res = await client.putSubscription(\n {\n path: { subscriptionId },\n body: { topics },\n },\n { token },\n );\n hasSubscription = true;\n if (!res.ok) {\n if (res.status === 404 && this.mode !== 'always') {\n this.logger.warn(\n `Event subscribe request failed with status 404, events backend not found. Will only receive events that were sent locally on this process.`,\n );\n // Events backend is not present and not configured to always be used, bail out and stop polling\n delete this.client;\n return;\n }\n throw await ResponseError.fromResponse(res);\n }\n }\n\n // No errors, reset backoff\n backoffMs = POLL_BACKOFF_START_MS;\n\n process.nextTick(poll);\n } catch (error) {\n this.logger.warn(\n `Poll failed for subscription \"${subscriptionId}\", retrying in ${backoffMs.toFixed(\n 0,\n )}ms`,\n error,\n );\n setTimeout(poll, backoffMs);\n backoffMs = Math.min(\n backoffMs * POLL_BACKOFF_FACTOR,\n POLL_BACKOFF_MAX_MS,\n );\n } finally {\n lock.release();\n }\n };\n poll();\n }\n\n async #getToken() {\n if (!this.auth) {\n throw new Error('Auth service not available');\n }\n\n try {\n const { token } = await this.auth.getPluginRequestToken({\n onBehalfOf: await this.auth.getOwnServiceCredentials(),\n targetPluginId: 'events',\n });\n return token;\n } catch (error) {\n // This is a bit hacky, but handles the case where new auth is used\n // without legacy auth fallback, and the events backend is not installed\n if (\n String(error).includes('Unable to generate legacy token') &&\n this.mode !== 'always'\n ) {\n this.logger.warn(\n `The events backend is not available and neither is legacy auth. Future events will not be persisted.`,\n );\n delete this.client;\n return undefined;\n }\n throw error;\n }\n }\n\n async shutdown() {\n this.#isShuttingDown = true;\n await Promise.all(this.#shutdownLocks);\n }\n\n #isShuttingDown = false;\n #shutdownLocks = new Set<Promise<void>>();\n\n // This locking mechanism helps ensure that we are either idle or waiting for\n // a blocked events call before shutting down. It increases out changes of\n // never dropping any events on shutdown.\n #getShutdownLock(): { release(): void } | undefined {\n if (this.#isShuttingDown) {\n return undefined;\n }\n\n let release: () => void;\n\n const lock = new Promise<void>(resolve => {\n release = () => {\n resolve();\n this.#shutdownLocks.delete(lock);\n };\n });\n this.#shutdownLocks.add(lock);\n return { release: release! };\n }\n}\n\n/**\n * In-process event broker which will pass the event to all registered subscribers\n * interested in it.\n * Events will not be persisted in any form.\n * Events will not be passed to subscribers at other instances of the same cluster.\n *\n * @public\n */\n// TODO(pjungermann): add opentelemetry? (see plugins/catalog-backend/src/util/opentelemetry.ts, etc.)\nexport class DefaultEventsService implements EventsService {\n private constructor(\n private readonly logger: LoggerService,\n private readonly localBus: LocalEventBus,\n private readonly mode: EventBusMode,\n ) {}\n\n static create(options: {\n logger: LoggerService;\n config?: RootConfigService;\n useEventBus?: EventBusMode;\n }): DefaultEventsService {\n const eventBusMode =\n options.useEventBus ??\n ((options.config?.getOptionalString('events.useEventBus') ??\n 'auto') as EventBusMode);\n if (!EVENT_BUS_MODES.includes(eventBusMode)) {\n throw new Error(\n `Invalid events.useEventBus config, must be one of ${EVENT_BUS_MODES.join(\n ', ',\n )}, got '${eventBusMode}'`,\n );\n }\n\n return new DefaultEventsService(\n options.logger,\n new LocalEventBus(options.logger),\n eventBusMode,\n );\n }\n\n /**\n * Returns a plugin-scoped context of the `EventService`\n * that ensures to prefix subscriber IDs with the plugin ID.\n *\n * @param pluginId - The plugin that the `EventService` should be created for.\n */\n forPlugin(\n pluginId: string,\n options?: {\n discovery: DiscoveryService;\n logger: LoggerService;\n auth: AuthService;\n lifecycle: LifecycleService;\n },\n ): EventsService {\n const client =\n options && this.mode !== 'never'\n ? new DefaultApiClient({\n discoveryApi: options.discovery,\n fetchApi: { fetch }, // use native node fetch\n })\n : undefined;\n const logger = options?.logger ?? this.logger;\n const service = new PluginEventsService(\n pluginId,\n this.localBus,\n logger,\n this.mode,\n client,\n options?.auth,\n );\n options?.lifecycle.addShutdownHook(async () => {\n await service.shutdown();\n });\n return service;\n }\n\n async publish(params: EventParams): Promise<void> {\n await this.localBus.publish(params);\n }\n\n async subscribe(options: EventsServiceSubscribeOptions): Promise<void> {\n this.localBus.subscribe(options);\n }\n}\n"],"names":["ResponseError","DefaultApiClient"],"mappings":";;;;;AA4BA,MAAM,qBAAwB,GAAA,GAAA,CAAA;AAC9B,MAAM,mBAAsB,GAAA,GAAA,CAAA;AAC5B,MAAM,mBAAsB,GAAA,CAAA,CAAA;AAE5B,MAAM,eAAkB,GAAA,CAAC,OAAS,EAAA,QAAA,EAAU,MAAM,CAAA,CAAA;AAiB3C,MAAM,aAAc,CAAA;AAAA,EAChB,OAAA,CAAA;AAAA,EAEA,YAAA,uBAAmB,GAG1B,EAAA,CAAA;AAAA,EAEF,YAAY,MAAuB,EAAA;AACjC,IAAA,IAAA,CAAK,OAAU,GAAA,MAAA,CAAA;AAAA,GACjB;AAAA,EAEA,MAAM,QACJ,MAC4C,EAAA;AAC5C,IAAA,IAAA,CAAK,OAAQ,CAAA,KAAA;AAAA,MACX,CAAyB,sBAAA,EAAA,MAAA,CAAO,KAAK,CAAA,WAAA,EAAc,IAAK,CAAA,SAAA;AAAA,QACtD,MAAO,CAAA,QAAA;AAAA,OACR,CAAa,UAAA,EAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,YAAY,CAAC,CAAA,CAAA;AAAA,KACnD,CAAA;AAEA,IAAA,IAAI,CAAC,IAAK,CAAA,YAAA,CAAa,GAAI,CAAA,MAAA,CAAO,KAAK,CAAG,EAAA;AACxC,M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MAAA;AAAA,MACR,IAAI,aAAc,CAAA,OAAA,CAAQ,MAAM,CAAA;AAAA,MAChC,YAAA;AAAA,KACF,CAAA;AAAA,GACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAA,CACE,UACA,OAMe,EAAA;AACf,IAAA,MAAM,SACJ,OAAW,IAAA,IAAA,CAAK,IAAS,KAAA,OAAA,GACrB,IAAIC,kCAAiB,CAAA;AAAA,MACnB,cAAc,OAAQ,CAAA,SAAA;AAAA,MACtB,QAAA,EAAU,EAAE,KAAM,EAAA;AAAA;AAAA,KACnB,CACD,GAAA,KAAA,CAAA,CAAA;AACN,IAAM,MAAA,MAAA,GAAS,OAAS,EAAA,MAAA,IAAU,IAAK,CAAA,MAAA,CAAA;AACvC,IAAA,MAAM,UAAU,IAAI,mBAAA;AAAA,MAClB,QAAA;AAAA,MACA,IAAK,CAAA,QAAA;AAAA,MACL,MAAA;AAAA,MACA,IAAK,CAAA,IAAA;AAAA,MACL,MAAA;AAAA,MACA,OAAS,EAAA,IAAA;AAAA,KACX,CAAA;AACA,IAAS,OAAA,EAAA,SAAA,CAAU,gBAAgB,YAAY;AAC7C,MAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AAAA,KACxB,CAAA,CAAA;AACD,IAAO,OAAA,OAAA,CAAA;AAAA,GACT;AAAA,EAEA,MAAM,QAAQ,MAAoC,EAAA;AAChD,IAAM,MAAA,IAAA,CAAK,QAAS,CAAA,OAAA,CAAQ,MAAM,CAAA,CAAA;AAAA,GACpC;AAAA,EAEA,MAAM,UAAU,OAAuD,EAAA;AACrE,IAAK,IAAA,CAAA,QAAA,CAAS,UAAU,OAAO,CAAA,CAAA;AAAA,GACjC;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"DefaultEventsService.cjs.js","sources":["../../src/api/DefaultEventsService.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 AuthService,\n DiscoveryService,\n LifecycleService,\n LoggerService,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport { EventParams } from './EventParams';\nimport { EventsService, EventsServiceSubscribeOptions } from './EventsService';\nimport { DefaultApiClient } from '../generated';\nimport { ResponseError } from '@backstage/errors';\n\nconst POLL_BACKOFF_START_MS = 1_000;\nconst POLL_BACKOFF_MAX_MS = 60_000;\nconst POLL_BACKOFF_FACTOR = 2;\n\nconst EVENT_BUS_MODES = ['never', 'always', 'auto'] as const;\n\n/**\n * @public\n */\nexport type EventBusMode = 'never' | 'always' | 'auto';\n\n/**\n * Local event bus for subscribers within the same process.\n *\n * When publishing events we'll keep track of which subscribers we managed to\n * reach locally, and forward those subscriber IDs to the events backend if it\n * is in use. The events backend will then both avoid forwarding the same events\n * to those subscribers again, but also avoid storing the event altogether if\n * there are no other subscribers.\n * @internal\n */\nexport class LocalEventBus {\n readonly #logger: LoggerService;\n\n readonly #subscribers = new Map<\n string,\n Omit<EventsServiceSubscribeOptions, 'topics'>[]\n >();\n\n constructor(logger: LoggerService) {\n this.#logger = logger;\n }\n\n async publish(\n params: EventParams,\n ): Promise<{ notifiedSubscribers: string[] }> {\n this.#logger.debug(\n `Event received: topic=${params.topic}, metadata=${JSON.stringify(\n params.metadata,\n )}, payload=${JSON.stringify(params.eventPayload)}`,\n );\n\n if (!this.#subscribers.has(params.topic)) {\n return { notifiedSubscribers: [] };\n }\n\n const onEventPromises: Promise<string>[] = [];\n this.#subscribers.get(params.topic)?.forEach(subscription => {\n onEventPromises.push(\n (async () => {\n try {\n await subscription.onEvent(params);\n } catch (error) {\n this.#logger.warn(\n `Subscriber \"${subscription.id}\" failed to process event for topic \"${params.topic}\"`,\n error,\n );\n }\n return subscription.id;\n })(),\n );\n });\n\n return { notifiedSubscribers: await Promise.all(onEventPromises) };\n }\n\n async subscribe(options: EventsServiceSubscribeOptions): Promise<void> {\n options.topics.forEach(topic => {\n if (!this.#subscribers.has(topic)) {\n this.#subscribers.set(topic, []);\n }\n\n this.#subscribers.get(topic)!.push({\n id: options.id,\n onEvent: options.onEvent,\n });\n });\n }\n}\n\n/**\n * Plugin specific events bus that delegates to the local bus, as well as the\n * events backend if it is available.\n */\nclass PluginEventsService implements EventsService {\n constructor(\n private readonly pluginId: string,\n private readonly localBus: LocalEventBus,\n private readonly logger: LoggerService,\n private readonly mode: EventBusMode,\n private client?: DefaultApiClient,\n private readonly auth?: AuthService,\n ) {}\n\n async publish(params: EventParams): Promise<void> {\n const lock = this.#getShutdownLock();\n if (!lock) {\n throw new Error('Service is shutting down');\n }\n try {\n const { notifiedSubscribers } = await this.localBus.publish(params);\n\n const client = this.client;\n if (!client) {\n return;\n }\n const token = await this.#getToken();\n if (!token) {\n return;\n }\n const res = await client.postEvent(\n {\n body: {\n event: { payload: params.eventPayload, topic: params.topic },\n notifiedSubscribers,\n },\n },\n { token },\n );\n\n if (!res.ok) {\n if (res.status === 404 && this.mode !== 'always') {\n this.logger.warn(\n `Event publish request failed with status 404, events backend not found. Future events will not be persisted.`,\n );\n delete this.client;\n return;\n }\n throw await ResponseError.fromResponse(res);\n }\n } finally {\n lock.release();\n }\n }\n\n async subscribe(options: EventsServiceSubscribeOptions): Promise<void> {\n const subscriptionId = `${this.pluginId}.${options.id}`;\n\n await this.localBus.subscribe({\n id: subscriptionId,\n topics: options.topics,\n onEvent: options.onEvent,\n });\n\n if (!this.client) {\n return;\n }\n\n this.#startPolling(subscriptionId, options.topics, options.onEvent);\n }\n\n #startPolling(\n subscriptionId: string,\n topics: string[],\n onEvent: EventsServiceSubscribeOptions['onEvent'],\n ) {\n let hasSubscription = false;\n let backoffMs = POLL_BACKOFF_START_MS;\n const poll = async () => {\n const client = this.client;\n if (!client) {\n return;\n }\n const lock = this.#getShutdownLock();\n if (!lock) {\n return; // shutting down\n }\n try {\n const token = await this.#getToken();\n if (!token) {\n return;\n }\n\n if (hasSubscription) {\n const res = await client.getSubscriptionEvents(\n {\n path: { subscriptionId },\n },\n { token },\n );\n\n if (res.status === 202) {\n // 202 means there were no immediately available events, but the\n // response will block until either new events are available or the\n // request times out. In both cases we should should try to read events\n // immediately again\n\n lock.release();\n // We don't actually expect any response body here, but waiting for\n // an empty body to be returned has been more reliable that waiting\n // for the response body stream to close.\n await res.text();\n } else if (res.status === 200) {\n const data = await res.json();\n if (data) {\n for (const event of data.events ?? []) {\n try {\n await onEvent({\n topic: event.topic,\n eventPayload: event.payload,\n });\n } catch (error) {\n this.logger.warn(\n `Subscriber \"${subscriptionId}\" failed to process event for topic \"${event.topic}\"`,\n error,\n );\n }\n }\n }\n } else {\n if (res.status === 404) {\n this.logger.info(\n `Polling event subscription resulted in a 404, recreating subscription`,\n );\n hasSubscription = false;\n } else {\n throw await ResponseError.fromResponse(res);\n }\n }\n }\n\n // If we haven't yet created the subscription, or if it was removed, create a new one\n if (!hasSubscription) {\n const res = await client.putSubscription(\n {\n path: { subscriptionId },\n body: { topics },\n },\n { token },\n );\n hasSubscription = true;\n if (!res.ok) {\n if (res.status === 404 && this.mode !== 'always') {\n this.logger.warn(\n `Event subscribe request failed with status 404, events backend not found. Will only receive events that were sent locally on this process.`,\n );\n // Events backend is not present and not configured to always be used, bail out and stop polling\n delete this.client;\n return;\n }\n throw await ResponseError.fromResponse(res);\n }\n }\n\n // No errors, reset backoff\n backoffMs = POLL_BACKOFF_START_MS;\n\n process.nextTick(poll);\n } catch (error) {\n this.logger.warn(\n `Poll failed for subscription \"${subscriptionId}\", retrying in ${backoffMs.toFixed(\n 0,\n )}ms`,\n error,\n );\n setTimeout(poll, backoffMs);\n backoffMs = Math.min(\n backoffMs * POLL_BACKOFF_FACTOR,\n POLL_BACKOFF_MAX_MS,\n );\n } finally {\n lock.release();\n }\n };\n poll();\n }\n\n async #getToken() {\n if (!this.auth) {\n throw new Error('Auth service not available');\n }\n\n try {\n const { token } = await this.auth.getPluginRequestToken({\n onBehalfOf: await this.auth.getOwnServiceCredentials(),\n targetPluginId: 'events',\n });\n return token;\n } catch (error) {\n // This is a bit hacky, but handles the case where new auth is used\n // without legacy auth fallback, and the events backend is not installed\n if (\n String(error).includes('Unable to generate legacy token') &&\n this.mode !== 'always'\n ) {\n this.logger.warn(\n `The events backend is not available and neither is legacy auth. Future events will not be persisted.`,\n );\n delete this.client;\n return undefined;\n }\n throw error;\n }\n }\n\n async shutdown() {\n this.#isShuttingDown = true;\n await Promise.all(this.#shutdownLocks);\n }\n\n #isShuttingDown = false;\n #shutdownLocks = new Set<Promise<void>>();\n\n // This locking mechanism helps ensure that we are either idle or waiting for\n // a blocked events call before shutting down. It increases out changes of\n // never dropping any events on shutdown.\n #getShutdownLock(): { release(): void } | undefined {\n if (this.#isShuttingDown) {\n return undefined;\n }\n\n let release: () => void;\n\n const lock = new Promise<void>(resolve => {\n release = () => {\n resolve();\n this.#shutdownLocks.delete(lock);\n };\n });\n this.#shutdownLocks.add(lock);\n return { release: release! };\n }\n}\n\n/**\n * In-process event broker which will pass the event to all registered subscribers\n * interested in it.\n * Events will not be persisted in any form.\n * Events will not be passed to subscribers at other instances of the same cluster.\n *\n * @public\n */\n// TODO(pjungermann): add opentelemetry? (see plugins/catalog-backend/src/util/opentelemetry.ts, etc.)\nexport class DefaultEventsService implements EventsService {\n private constructor(\n private readonly logger: LoggerService,\n private readonly localBus: LocalEventBus,\n private readonly mode: EventBusMode,\n ) {}\n\n static create(options: {\n logger: LoggerService;\n config?: RootConfigService;\n useEventBus?: EventBusMode;\n }): DefaultEventsService {\n const eventBusMode =\n options.useEventBus ??\n ((options.config?.getOptionalString('events.useEventBus') ??\n 'auto') as EventBusMode);\n if (!EVENT_BUS_MODES.includes(eventBusMode)) {\n throw new Error(\n `Invalid events.useEventBus config, must be one of ${EVENT_BUS_MODES.join(\n ', ',\n )}, got '${eventBusMode}'`,\n );\n }\n\n return new DefaultEventsService(\n options.logger,\n new LocalEventBus(options.logger),\n eventBusMode,\n );\n }\n\n /**\n * Returns a plugin-scoped context of the `EventService`\n * that ensures to prefix subscriber IDs with the plugin ID.\n *\n * @param pluginId - The plugin that the `EventService` should be created for.\n */\n forPlugin(\n pluginId: string,\n options?: {\n discovery: DiscoveryService;\n logger: LoggerService;\n auth: AuthService;\n lifecycle: LifecycleService;\n },\n ): EventsService {\n const client =\n options && this.mode !== 'never'\n ? new DefaultApiClient({\n discoveryApi: options.discovery,\n fetchApi: { fetch }, // use native node fetch\n })\n : undefined;\n const logger = options?.logger ?? this.logger;\n const service = new PluginEventsService(\n pluginId,\n this.localBus,\n logger,\n this.mode,\n client,\n options?.auth,\n );\n options?.lifecycle.addShutdownHook(async () => {\n await service.shutdown();\n });\n return service;\n }\n\n async publish(params: EventParams): Promise<void> {\n await this.localBus.publish(params);\n }\n\n async subscribe(options: EventsServiceSubscribeOptions): Promise<void> {\n this.localBus.subscribe(options);\n }\n}\n"],"names":["ResponseError","DefaultApiClient"],"mappings":";;;;;AA4BA,MAAM,qBAAwB,GAAA,GAAA;AAC9B,MAAM,mBAAsB,GAAA,GAAA;AAC5B,MAAM,mBAAsB,GAAA,CAAA;AAE5B,MAAM,eAAkB,GAAA,CAAC,OAAS,EAAA,QAAA,EAAU,MAAM,CAAA;AAiB3C,MAAM,aAAc,CAAA;AAAA,EAChB,OAAA;AAAA,EAEA,YAAA,uBAAmB,GAG1B,EAAA;AAAA,EAEF,YAAY,MAAuB,EAAA;AACjC,IAAA,IAAA,CAAK,OAAU,GAAA,MAAA;AAAA;AACjB,EAEA,MAAM,QACJ,MAC4C,EAAA;AAC5C,IAAA,IAAA,CAAK,OAAQ,CAAA,KAAA;AAAA,MACX,CAAyB,sBAAA,EAAA,MAAA,CAAO,KAAK,CAAA,WAAA,EAAc,IAAK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,gBAAgB,YAAY;AAC7C,MAAA,MAAM,QAAQ,QAAS,EAAA;AAAA,KACxB,CAAA;AACD,IAAO,OAAA,OAAA;AAAA;AACT,EAEA,MAAM,QAAQ,MAAoC,EAAA;AAChD,IAAM,MAAA,IAAA,CAAK,QAAS,CAAA,OAAA,CAAQ,MAAM,CAAA;AAAA;AACpC,EAEA,MAAM,UAAU,OAAuD,EAAA;AACrE,IAAK,IAAA,CAAA,QAAA,CAAS,UAAU,OAAO,CAAA;AAAA;AAEnC;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventRouter.cjs.js","sources":["../../src/api/EventRouter.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 { EventParams } from './EventParams';\nimport { EventsService } from './EventsService';\n\n/**\n * Subscribes to a topic and - depending on a set of conditions -\n * republishes the event to another topic.\n *\n * @see {@link https://www.enterpriseintegrationpatterns.com/MessageRouter.html | Message Router pattern}.\n * @public\n */\nexport abstract class EventRouter {\n private readonly events: EventsService;\n private readonly topics: string[];\n private subscribed: boolean = false;\n\n protected constructor(options: { events: EventsService; topics: string[] }) {\n this.events = options.events;\n this.topics = options.topics;\n }\n\n protected abstract getSubscriberId(): string;\n\n protected abstract determineDestinationTopic(\n params: EventParams,\n ): string | undefined;\n\n /**\n * Subscribes itself to the topic(s),\n * after which events potentially can be received\n * and processed by {@link EventRouter.onEvent}.\n */\n async subscribe(): Promise<void> {\n if (this.subscribed) {\n return;\n }\n\n this.subscribed = true;\n\n await this.events.subscribe({\n id: this.getSubscriberId(),\n topics: this.topics,\n onEvent: this.onEvent.bind(this),\n });\n }\n\n async onEvent(params: EventParams): Promise<void> {\n const topic = this.determineDestinationTopic(params);\n\n if (!topic) {\n return;\n }\n\n // republish to different topic\n await this.events.publish({\n ...params,\n topic,\n });\n }\n}\n"],"names":[],"mappings":";;AA0BO,MAAe,WAAY,CAAA;AAAA,EACf,MAAA
|
|
1
|
+
{"version":3,"file":"EventRouter.cjs.js","sources":["../../src/api/EventRouter.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 { EventParams } from './EventParams';\nimport { EventsService } from './EventsService';\n\n/**\n * Subscribes to a topic and - depending on a set of conditions -\n * republishes the event to another topic.\n *\n * @see {@link https://www.enterpriseintegrationpatterns.com/MessageRouter.html | Message Router pattern}.\n * @public\n */\nexport abstract class EventRouter {\n private readonly events: EventsService;\n private readonly topics: string[];\n private subscribed: boolean = false;\n\n protected constructor(options: { events: EventsService; topics: string[] }) {\n this.events = options.events;\n this.topics = options.topics;\n }\n\n protected abstract getSubscriberId(): string;\n\n protected abstract determineDestinationTopic(\n params: EventParams,\n ): string | undefined;\n\n /**\n * Subscribes itself to the topic(s),\n * after which events potentially can be received\n * and processed by {@link EventRouter.onEvent}.\n */\n async subscribe(): Promise<void> {\n if (this.subscribed) {\n return;\n }\n\n this.subscribed = true;\n\n await this.events.subscribe({\n id: this.getSubscriberId(),\n topics: this.topics,\n onEvent: this.onEvent.bind(this),\n });\n }\n\n async onEvent(params: EventParams): Promise<void> {\n const topic = this.determineDestinationTopic(params);\n\n if (!topic) {\n return;\n }\n\n // republish to different topic\n await this.events.publish({\n ...params,\n topic,\n });\n }\n}\n"],"names":[],"mappings":";;AA0BO,MAAe,WAAY,CAAA;AAAA,EACf,MAAA;AAAA,EACA,MAAA;AAAA,EACT,UAAsB,GAAA,KAAA;AAAA,EAEpB,YAAY,OAAsD,EAAA;AAC1E,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA;AACtB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA;AAAA;AACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,SAA2B,GAAA;AAC/B,IAAA,IAAI,KAAK,UAAY,EAAA;AACnB,MAAA;AAAA;AAGF,IAAA,IAAA,CAAK,UAAa,GAAA,IAAA;AAElB,IAAM,MAAA,IAAA,CAAK,OAAO,SAAU,CAAA;AAAA,MAC1B,EAAA,EAAI,KAAK,eAAgB,EAAA;AAAA,MACzB,QAAQ,IAAK,CAAA,MAAA;AAAA,MACb,OAAS,EAAA,IAAA,CAAK,OAAQ,CAAA,IAAA,CAAK,IAAI;AAAA,KAChC,CAAA;AAAA;AACH,EAEA,MAAM,QAAQ,MAAoC,EAAA;AAChD,IAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,yBAAA,CAA0B,MAAM,CAAA;AAEnD,IAAA,IAAI,CAAC,KAAO,EAAA;AACV,MAAA;AAAA;AAIF,IAAM,MAAA,IAAA,CAAK,OAAO,OAAQ,CAAA;AAAA,MACxB,GAAG,MAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA;AAEL;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubTopicEventRouter.cjs.js","sources":["../../src/api/SubTopicEventRouter.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 { EventParams } from './EventParams';\nimport { EventRouter } from './EventRouter';\nimport { EventsService } from './EventsService';\n\n/**\n * Subscribes to the provided (generic) topic\n * and publishes the events under the more concrete sub-topic\n * depending on the implemented logic for determining it.\n * Implementing classes might use information from `metadata`\n * and/or properties within the payload.\n *\n * @public\n */\nexport abstract class SubTopicEventRouter extends EventRouter {\n protected constructor(options: { events: EventsService; topic: string }) {\n super({\n events: options.events,\n topics: [options.topic],\n });\n }\n\n protected abstract determineSubTopic(params: EventParams): string | undefined;\n\n protected determineDestinationTopic(params: EventParams): string | undefined {\n const subTopic = this.determineSubTopic(params);\n return subTopic ? `${params.topic}.${subTopic}` : undefined;\n }\n}\n"],"names":["EventRouter"],"mappings":";;;;AA6BO,MAAe,4BAA4BA,uBAAY,CAAA;AAAA,EAClD,YAAY,OAAmD,EAAA;AACvE,IAAM,KAAA,CAAA;AAAA,MACJ,QAAQ,OAAQ,CAAA,MAAA;AAAA,MAChB,MAAA,EAAQ,CAAC,OAAA,CAAQ,KAAK
|
|
1
|
+
{"version":3,"file":"SubTopicEventRouter.cjs.js","sources":["../../src/api/SubTopicEventRouter.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 { EventParams } from './EventParams';\nimport { EventRouter } from './EventRouter';\nimport { EventsService } from './EventsService';\n\n/**\n * Subscribes to the provided (generic) topic\n * and publishes the events under the more concrete sub-topic\n * depending on the implemented logic for determining it.\n * Implementing classes might use information from `metadata`\n * and/or properties within the payload.\n *\n * @public\n */\nexport abstract class SubTopicEventRouter extends EventRouter {\n protected constructor(options: { events: EventsService; topic: string }) {\n super({\n events: options.events,\n topics: [options.topic],\n });\n }\n\n protected abstract determineSubTopic(params: EventParams): string | undefined;\n\n protected determineDestinationTopic(params: EventParams): string | undefined {\n const subTopic = this.determineSubTopic(params);\n return subTopic ? `${params.topic}.${subTopic}` : undefined;\n }\n}\n"],"names":["EventRouter"],"mappings":";;;;AA6BO,MAAe,4BAA4BA,uBAAY,CAAA;AAAA,EAClD,YAAY,OAAmD,EAAA;AACvE,IAAM,KAAA,CAAA;AAAA,MACJ,QAAQ,OAAQ,CAAA,MAAA;AAAA,MAChB,MAAA,EAAQ,CAAC,OAAA,CAAQ,KAAK;AAAA,KACvB,CAAA;AAAA;AACH,EAIU,0BAA0B,MAAyC,EAAA;AAC3E,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,iBAAA,CAAkB,MAAM,CAAA;AAC9C,IAAA,OAAO,WAAW,CAAG,EAAA,MAAA,CAAO,KAAK,CAAA,CAAA,EAAI,QAAQ,CAAK,CAAA,GAAA,KAAA,CAAA;AAAA;AAEtD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions.cjs.js","sources":["../src/extensions.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 { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport {\n EventBroker,\n EventPublisher,\n EventSubscriber,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\n\n/**\n * @alpha\n */\nexport interface EventsExtensionPoint {\n /**\n * @deprecated use `eventsServiceRef` and `eventsServiceFactory` instead\n */\n setEventBroker(eventBroker: EventBroker): void;\n\n /**\n * @deprecated use `EventsService.publish` instead\n */\n addPublishers(\n ...publishers: Array<EventPublisher | Array<EventPublisher>>\n ): void;\n\n /**\n * @deprecated use `EventsService.subscribe` instead\n */\n addSubscribers(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): void;\n\n addHttpPostIngress(options: HttpPostIngressOptions): void;\n}\n\n/**\n * @alpha\n */\nexport const eventsExtensionPoint = createExtensionPoint<EventsExtensionPoint>({\n id: 'events',\n});\n"],"names":["createExtensionPoint"],"mappings":";;;;AAqDO,MAAM,uBAAuBA,qCAA2C,CAAA;AAAA,EAC7E,EAAI,EAAA
|
|
1
|
+
{"version":3,"file":"extensions.cjs.js","sources":["../src/extensions.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 { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport {\n EventBroker,\n EventPublisher,\n EventSubscriber,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\n\n/**\n * @alpha\n */\nexport interface EventsExtensionPoint {\n /**\n * @deprecated use `eventsServiceRef` and `eventsServiceFactory` instead\n */\n setEventBroker(eventBroker: EventBroker): void;\n\n /**\n * @deprecated use `EventsService.publish` instead\n */\n addPublishers(\n ...publishers: Array<EventPublisher | Array<EventPublisher>>\n ): void;\n\n /**\n * @deprecated use `EventsService.subscribe` instead\n */\n addSubscribers(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): void;\n\n addHttpPostIngress(options: HttpPostIngressOptions): void;\n}\n\n/**\n * @alpha\n */\nexport const eventsExtensionPoint = createExtensionPoint<EventsExtensionPoint>({\n id: 'events',\n});\n"],"names":["createExtensionPoint"],"mappings":";;;;AAqDO,MAAM,uBAAuBA,qCAA2C,CAAA;AAAA,EAC7E,EAAI,EAAA;AACN,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultApi.client.cjs.js","sources":["../../../src/generated/apis/DefaultApi.client.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 { DiscoveryApi } from '../types/discovery';\nimport { FetchApi } from '../types/fetch';\nimport crossFetch from 'cross-fetch';\nimport { pluginId } from '../pluginId';\nimport * as parser from 'uri-template';\n\nimport { GetSubscriptionEvents200Response } from '../models/GetSubscriptionEvents200Response.model';\nimport { PostEventRequest } from '../models/PostEventRequest.model';\nimport { PutSubscriptionRequest } from '../models/PutSubscriptionRequest.model';\n\n/**\n * Wraps the Response type to convey a type on the json call.\n *\n * @public\n */\nexport type TypedResponse<T> = Omit<Response, 'json'> & {\n json: () => Promise<T>;\n};\n\n/**\n * Options you can pass into a request for additional information.\n *\n * @public\n */\nexport interface RequestOptions {\n token?: string;\n}\n\n/**\n * no description\n */\nexport class DefaultApiClient {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n\n constructor(options: {\n discoveryApi: { getBaseUrl(pluginId: string): Promise<string> };\n fetchApi?: { fetch: typeof fetch };\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi || { fetch: crossFetch };\n }\n\n /**\n * Get new events for the provided subscription\n * @param subscriptionId\n */\n public async getSubscriptionEvents(\n // @ts-ignore\n request: {\n path: {\n subscriptionId: string;\n };\n },\n options?: RequestOptions,\n ): Promise<TypedResponse<void | GetSubscriptionEvents200Response>> {\n const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);\n\n const uriTemplate = `/bus/v1/subscriptions/{subscriptionId}/events`;\n\n const uri = parser.parse(uriTemplate).expand({\n subscriptionId: request.path.subscriptionId,\n });\n\n return await this.fetchApi.fetch(`${baseUrl}${uri}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(options?.token && { Authorization: `Bearer ${options?.token}` }),\n },\n method: 'GET',\n });\n }\n\n /**\n * Publish a new event\n * @param postEventRequest\n */\n public async postEvent(\n // @ts-ignore\n request: {\n body: PostEventRequest;\n },\n options?: RequestOptions,\n ): Promise<TypedResponse<void>> {\n const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);\n\n const uriTemplate = `/bus/v1/events`;\n\n const uri = parser.parse(uriTemplate).expand({});\n\n return await this.fetchApi.fetch(`${baseUrl}${uri}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(options?.token && { Authorization: `Bearer ${options?.token}` }),\n },\n method: 'POST',\n body: JSON.stringify(request.body),\n });\n }\n\n /**\n * Ensures that the subscription exists with the provided configuration\n * @param subscriptionId\n * @param putSubscriptionRequest\n */\n public async putSubscription(\n // @ts-ignore\n request: {\n path: {\n subscriptionId: string;\n };\n body: PutSubscriptionRequest;\n },\n options?: RequestOptions,\n ): Promise<TypedResponse<void>> {\n const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);\n\n const uriTemplate = `/bus/v1/subscriptions/{subscriptionId}`;\n\n const uri = parser.parse(uriTemplate).expand({\n subscriptionId: request.path.subscriptionId,\n });\n\n return await this.fetchApi.fetch(`${baseUrl}${uri}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(options?.token && { Authorization: `Bearer ${options?.token}` }),\n },\n method: 'PUT',\n body: JSON.stringify(request.body),\n });\n }\n}\n"],"names":["crossFetch","pluginId","parser"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDO,MAAM,gBAAiB,CAAA;AAAA,EACX,YAAA
|
|
1
|
+
{"version":3,"file":"DefaultApi.client.cjs.js","sources":["../../../src/generated/apis/DefaultApi.client.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 { DiscoveryApi } from '../types/discovery';\nimport { FetchApi } from '../types/fetch';\nimport crossFetch from 'cross-fetch';\nimport { pluginId } from '../pluginId';\nimport * as parser from 'uri-template';\n\nimport { GetSubscriptionEvents200Response } from '../models/GetSubscriptionEvents200Response.model';\nimport { PostEventRequest } from '../models/PostEventRequest.model';\nimport { PutSubscriptionRequest } from '../models/PutSubscriptionRequest.model';\n\n/**\n * Wraps the Response type to convey a type on the json call.\n *\n * @public\n */\nexport type TypedResponse<T> = Omit<Response, 'json'> & {\n json: () => Promise<T>;\n};\n\n/**\n * Options you can pass into a request for additional information.\n *\n * @public\n */\nexport interface RequestOptions {\n token?: string;\n}\n\n/**\n * no description\n */\nexport class DefaultApiClient {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n\n constructor(options: {\n discoveryApi: { getBaseUrl(pluginId: string): Promise<string> };\n fetchApi?: { fetch: typeof fetch };\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi || { fetch: crossFetch };\n }\n\n /**\n * Get new events for the provided subscription\n * @param subscriptionId\n */\n public async getSubscriptionEvents(\n // @ts-ignore\n request: {\n path: {\n subscriptionId: string;\n };\n },\n options?: RequestOptions,\n ): Promise<TypedResponse<void | GetSubscriptionEvents200Response>> {\n const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);\n\n const uriTemplate = `/bus/v1/subscriptions/{subscriptionId}/events`;\n\n const uri = parser.parse(uriTemplate).expand({\n subscriptionId: request.path.subscriptionId,\n });\n\n return await this.fetchApi.fetch(`${baseUrl}${uri}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(options?.token && { Authorization: `Bearer ${options?.token}` }),\n },\n method: 'GET',\n });\n }\n\n /**\n * Publish a new event\n * @param postEventRequest\n */\n public async postEvent(\n // @ts-ignore\n request: {\n body: PostEventRequest;\n },\n options?: RequestOptions,\n ): Promise<TypedResponse<void>> {\n const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);\n\n const uriTemplate = `/bus/v1/events`;\n\n const uri = parser.parse(uriTemplate).expand({});\n\n return await this.fetchApi.fetch(`${baseUrl}${uri}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(options?.token && { Authorization: `Bearer ${options?.token}` }),\n },\n method: 'POST',\n body: JSON.stringify(request.body),\n });\n }\n\n /**\n * Ensures that the subscription exists with the provided configuration\n * @param subscriptionId\n * @param putSubscriptionRequest\n */\n public async putSubscription(\n // @ts-ignore\n request: {\n path: {\n subscriptionId: string;\n };\n body: PutSubscriptionRequest;\n },\n options?: RequestOptions,\n ): Promise<TypedResponse<void>> {\n const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);\n\n const uriTemplate = `/bus/v1/subscriptions/{subscriptionId}`;\n\n const uri = parser.parse(uriTemplate).expand({\n subscriptionId: request.path.subscriptionId,\n });\n\n return await this.fetchApi.fetch(`${baseUrl}${uri}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(options?.token && { Authorization: `Bearer ${options?.token}` }),\n },\n method: 'PUT',\n body: JSON.stringify(request.body),\n });\n }\n}\n"],"names":["crossFetch","pluginId","parser"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDO,MAAM,gBAAiB,CAAA;AAAA,EACX,YAAA;AAAA,EACA,QAAA;AAAA,EAEjB,YAAY,OAGT,EAAA;AACD,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA;AAC5B,IAAA,IAAA,CAAK,QAAW,GAAA,OAAA,CAAQ,QAAY,IAAA,EAAE,OAAOA,2BAAW,EAAA;AAAA;AAC1D;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,qBAEX,CAAA,OAAA,EAKA,OACiE,EAAA;AACjE,IAAA,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,YAAA,CAAa,WAAWC,iBAAQ,CAAA;AAE3D,IAAA,MAAM,WAAc,GAAA,CAAA,6CAAA,CAAA;AAEpB,IAAA,MAAM,GAAM,GAAAC,iBAAA,CAAO,KAAM,CAAA,WAAW,EAAE,MAAO,CAAA;AAAA,MAC3C,cAAA,EAAgB,QAAQ,IAAK,CAAA;AAAA,KAC9B,CAAA;AAED,IAAO,OAAA,MAAM,KAAK,QAAS,CAAA,KAAA,CAAM,GAAG,OAAO,CAAA,EAAG,GAAG,CAAI,CAAA,EAAA;AAAA,MACnD,OAAS,EAAA;AAAA,QACP,cAAgB,EAAA,kBAAA;AAAA,QAChB,GAAI,SAAS,KAAS,IAAA,EAAE,eAAe,CAAU,OAAA,EAAA,OAAA,EAAS,KAAK,CAAG,CAAA;AAAA,OACpE;AAAA,MACA,MAAQ,EAAA;AAAA,KACT,CAAA;AAAA;AACH;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,SAEX,CAAA,OAAA,EA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AK,CAAG,CAAA;AAAA,OACpE;AAAA,MACA,MAAQ,EAAA,KAAA;AAAA,MACR,IAAM,EAAA,IAAA,CAAK,SAAU,CAAA,OAAA,CAAQ,IAAI;AAAA,KAClC,CAAA;AAAA;AAEL;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
3
|
import { LoggerService, RootConfigService, DiscoveryService, AuthService, LifecycleService } from '@backstage/backend-plugin-api';
|
|
3
4
|
|
|
@@ -121,6 +122,8 @@ declare class DefaultEventsService implements EventsService {
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
/**
|
|
125
|
+
* View on an incoming request that has to be validated.
|
|
126
|
+
*
|
|
124
127
|
* @public
|
|
125
128
|
*/
|
|
126
129
|
interface RequestDetails {
|
|
@@ -132,6 +135,20 @@ interface RequestDetails {
|
|
|
132
135
|
* Key-value pairs of header names and values. Header names are lower-cased.
|
|
133
136
|
*/
|
|
134
137
|
headers: Record<string, string | string[] | undefined>;
|
|
138
|
+
/**
|
|
139
|
+
* Raw request details.
|
|
140
|
+
*/
|
|
141
|
+
raw: {
|
|
142
|
+
/**
|
|
143
|
+
* Raw request body (buffer).
|
|
144
|
+
*/
|
|
145
|
+
body: Buffer;
|
|
146
|
+
/**
|
|
147
|
+
* Encoding of the raw request body.
|
|
148
|
+
* Can be used to decode the raw request body like `raw.body.toString(raw.encoding)`.
|
|
149
|
+
*/
|
|
150
|
+
encoding: BufferEncoding;
|
|
151
|
+
};
|
|
135
152
|
}
|
|
136
153
|
|
|
137
154
|
/**
|
package/dist/service.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.cjs.js","sources":["../src/service.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 coreServices,\n createServiceFactory,\n createServiceRef,\n} from '@backstage/backend-plugin-api';\nimport { EventsService, DefaultEventsService } from './api';\n\n/**\n * The {@link EventsService} that allows to publish events, and subscribe to topics.\n * Uses the `root` scope so that events can be shared across all plugins, modules, and more.\n *\n * @public\n */\nexport const eventsServiceRef = createServiceRef<EventsService>({\n id: 'events.service',\n scope: 'plugin',\n});\n\n/** @public */\nexport const eventsServiceFactory = createServiceFactory({\n service: eventsServiceRef,\n deps: {\n pluginMetadata: coreServices.pluginMetadata,\n rootLogger: coreServices.rootLogger,\n discovery: coreServices.discovery,\n logger: coreServices.logger,\n lifecycle: coreServices.lifecycle,\n auth: coreServices.auth,\n config: coreServices.rootConfig,\n },\n async createRootContext({ rootLogger, config }) {\n return DefaultEventsService.create({ logger: rootLogger, config });\n },\n async factory(\n { pluginMetadata, discovery, logger, lifecycle, auth },\n eventsService,\n ) {\n return eventsService.forPlugin(pluginMetadata.getId(), {\n discovery,\n logger,\n lifecycle,\n auth,\n });\n },\n});\n"],"names":["createServiceRef","createServiceFactory","coreServices","DefaultEventsService"],"mappings":";;;;;AA6BO,MAAM,mBAAmBA,iCAAgC,CAAA;AAAA,EAC9D,EAAI,EAAA,gBAAA;AAAA,EACJ,KAAO,EAAA
|
|
1
|
+
{"version":3,"file":"service.cjs.js","sources":["../src/service.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 coreServices,\n createServiceFactory,\n createServiceRef,\n} from '@backstage/backend-plugin-api';\nimport { EventsService, DefaultEventsService } from './api';\n\n/**\n * The {@link EventsService} that allows to publish events, and subscribe to topics.\n * Uses the `root` scope so that events can be shared across all plugins, modules, and more.\n *\n * @public\n */\nexport const eventsServiceRef = createServiceRef<EventsService>({\n id: 'events.service',\n scope: 'plugin',\n});\n\n/** @public */\nexport const eventsServiceFactory = createServiceFactory({\n service: eventsServiceRef,\n deps: {\n pluginMetadata: coreServices.pluginMetadata,\n rootLogger: coreServices.rootLogger,\n discovery: coreServices.discovery,\n logger: coreServices.logger,\n lifecycle: coreServices.lifecycle,\n auth: coreServices.auth,\n config: coreServices.rootConfig,\n },\n async createRootContext({ rootLogger, config }) {\n return DefaultEventsService.create({ logger: rootLogger, config });\n },\n async factory(\n { pluginMetadata, discovery, logger, lifecycle, auth },\n eventsService,\n ) {\n return eventsService.forPlugin(pluginMetadata.getId(), {\n discovery,\n logger,\n lifecycle,\n auth,\n });\n },\n});\n"],"names":["createServiceRef","createServiceFactory","coreServices","DefaultEventsService"],"mappings":";;;;;AA6BO,MAAM,mBAAmBA,iCAAgC,CAAA;AAAA,EAC9D,EAAI,EAAA,gBAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAC;AAGM,MAAM,uBAAuBC,qCAAqB,CAAA;AAAA,EACvD,OAAS,EAAA,gBAAA;AAAA,EACT,IAAM,EAAA;AAAA,IACJ,gBAAgBC,6BAAa,CAAA,cAAA;AAAA,IAC7B,YAAYA,6BAAa,CAAA,UAAA;AAAA,IACzB,WAAWA,6BAAa,CAAA,SAAA;AAAA,IACxB,QAAQA,6BAAa,CAAA,MAAA;AAAA,IACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,IACxB,MAAMA,6BAAa,CAAA,IAAA;AAAA,IACnB,QAAQA,6BAAa,CAAA;AAAA,GACvB;AAAA,EACA,MAAM,iBAAA,CAAkB,EAAE,UAAA,EAAY,QAAU,EAAA;AAC9C,IAAA,OAAOC,0CAAqB,MAAO,CAAA,EAAE,MAAQ,EAAA,UAAA,EAAY,QAAQ,CAAA;AAAA,GACnE;AAAA,EACA,MAAM,QACJ,EAAE,cAAA,EAAgB,WAAW,MAAQ,EAAA,SAAA,EAAW,IAAK,EAAA,EACrD,aACA,EAAA;AACA,IAAA,OAAO,aAAc,CAAA,SAAA,CAAU,cAAe,CAAA,KAAA,EAAS,EAAA;AAAA,MACrD,SAAA;AAAA,MACA,MAAA;AAAA,MACA,SAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA;AAEL,CAAC;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-events-node",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5-next.3",
|
|
4
4
|
"description": "The plugin-events-node module for @backstage/plugin-events-backend",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library",
|
|
@@ -36,10 +36,19 @@
|
|
|
36
36
|
},
|
|
37
37
|
"main": "./dist/index.cjs.js",
|
|
38
38
|
"types": "./dist/index.d.ts",
|
|
39
|
+
"typesVersions": {
|
|
40
|
+
"*": {
|
|
41
|
+
"index": [
|
|
42
|
+
"dist/index.d.ts"
|
|
43
|
+
],
|
|
44
|
+
"alpha": [
|
|
45
|
+
"dist/alpha.d.ts"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
39
49
|
"files": [
|
|
40
50
|
"dist",
|
|
41
|
-
"config.d.ts"
|
|
42
|
-
"alpha"
|
|
51
|
+
"config.d.ts"
|
|
43
52
|
],
|
|
44
53
|
"scripts": {
|
|
45
54
|
"build": "backstage-cli package build",
|
|
@@ -51,16 +60,16 @@
|
|
|
51
60
|
"test": "backstage-cli package test"
|
|
52
61
|
},
|
|
53
62
|
"dependencies": {
|
|
54
|
-
"@backstage/backend-plugin-api": "
|
|
55
|
-
"@backstage/errors": "
|
|
56
|
-
"@backstage/types": "
|
|
63
|
+
"@backstage/backend-plugin-api": "1.0.2-next.2",
|
|
64
|
+
"@backstage/errors": "1.2.4",
|
|
65
|
+
"@backstage/types": "1.1.1",
|
|
57
66
|
"cross-fetch": "^4.0.0",
|
|
58
67
|
"uri-template": "^2.0.0"
|
|
59
68
|
},
|
|
60
69
|
"devDependencies": {
|
|
61
70
|
"@backstage/backend-common": "^0.25.0",
|
|
62
|
-
"@backstage/backend-test-utils": "
|
|
63
|
-
"@backstage/cli": "
|
|
71
|
+
"@backstage/backend-test-utils": "1.1.0-next.3",
|
|
72
|
+
"@backstage/cli": "0.29.0-next.3",
|
|
64
73
|
"msw": "^1.0.0"
|
|
65
74
|
},
|
|
66
75
|
"configSchema": "config.d.ts"
|