@backstage/plugin-events-backend-module-github 0.4.3-next.0 → 0.4.4-next.0

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,22 @@
1
1
  # @backstage/plugin-events-backend-module-github
2
2
 
3
+ ## 0.4.4-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/integration@1.18.0-next.0
9
+ - @backstage/backend-plugin-api@1.4.3-next.0
10
+ - @backstage/plugin-events-node@0.4.15-next.0
11
+
12
+ ## 0.4.3
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+ - @backstage/backend-plugin-api@1.4.2
18
+ - @backstage/plugin-events-node@0.4.14
19
+
3
20
  ## 0.4.3-next.0
4
21
 
5
22
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"createGithubSignatureValidator.cjs.js","sources":["../../src/http/createGithubSignatureValidator.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 { Config } from '@backstage/config';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n RequestDetails,\n RequestValidationContext,\n RequestValidator,\n} from '@backstage/plugin-events-node';\nimport { verify } from '@octokit/webhooks-methods';\nimport { createAppIdResolver } from '../util/createAppIdResolver';\nimport { OctokitProviderService } from '../util/octokitProviderService';\n\n/**\n * Validates that the request received is the expected GitHub request\n * using the signature received with the `x-hub-signature-256` header\n * which is based on a secret token configured at GitHub and here.\n *\n * See https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks\n * for more details.\n *\n * @param config - root config\n * @public\n */\nexport function createGithubSignatureValidator(\n config: Config,\n octokitProvider: OctokitProviderService,\n): RequestValidator | undefined {\n const integrations = ScmIntegrations.fromConfig(config);\n\n // GitHub App installation ID to secret\n const githubAppSecrets = new Map<number, string>();\n for (const integration of integrations.github.list()) {\n for (const { appId, webhookSecret } of integration.config.apps ?? []) {\n if (appId && webhookSecret) {\n githubAppSecrets.set(appId, webhookSecret);\n }\n }\n }\n\n // A single optional secret for all GitHub events\n const genericSecret = config.getOptionalString(\n 'events.modules.github.webhookSecret',\n );\n\n if (!genericSecret && githubAppSecrets.size === 0) {\n return undefined;\n }\n\n const appIdResolver = createAppIdResolver(octokitProvider);\n\n return async (\n request: RequestDetails,\n context: RequestValidationContext,\n ): Promise<void> => {\n const signature = request.headers['x-hub-signature-256'] as\n | string\n | undefined;\n\n if (signature) {\n const body = request.raw.body.toString(request.raw.encoding);\n\n if (githubAppSecrets.size) {\n const appId = await appIdResolver(request);\n if (appId && githubAppSecrets.has(appId)) {\n if (await verify(githubAppSecrets.get(appId)!, body, signature)) {\n return;\n }\n }\n }\n\n if (genericSecret) {\n if (await verify(genericSecret, body, signature)) {\n return;\n }\n }\n }\n\n context.reject({\n status: 403,\n payload: { message: 'invalid signature' },\n });\n };\n}\n"],"names":["ScmIntegrations","createAppIdResolver","verify"],"mappings":";;;;;;AAsCgB,SAAA,8BAAA,CACd,QACA,eAC8B,EAAA;AAC9B,EAAM,MAAA,YAAA,GAAeA,2BAAgB,CAAA,UAAA,CAAW,MAAM,CAAA;AAGtD,EAAM,MAAA,gBAAA,uBAAuB,GAAoB,EAAA;AACjD,EAAA,KAAA,MAAW,WAAe,IAAA,YAAA,CAAa,MAAO,CAAA,IAAA,EAAQ,EAAA;AACpD,IAAW,KAAA,MAAA,EAAE,OAAO,aAAc,EAAA,IAAK,YAAY,MAAO,CAAA,IAAA,IAAQ,EAAI,EAAA;AACpE,MAAA,IAAI,S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SignatureValidator.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 { Config } from '@backstage/config';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n RequestDetails,\n RequestValidationContext,\n RequestValidator,\n} from '@backstage/plugin-events-node';\nimport { verify } from '@octokit/webhooks-methods';\nimport { createAppIdResolver } from '../util/createAppIdResolver';\nimport { OctokitProviderService } from '../util/octokitProviderService';\n\n/**\n * Validates that the request received is the expected GitHub request\n * using the signature received with the `x-hub-signature-256` header\n * which is based on a secret token configured at GitHub and here.\n *\n * See https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks\n * for more details.\n *\n * @param config - root config\n * @public\n */\nexport function createGithubSignatureValidator(\n config: Config,\n octokitProvider: OctokitProviderService,\n): RequestValidator | undefined {\n const integrations = ScmIntegrations.fromConfig(config);\n\n // GitHub App installation ID to secret\n const githubAppSecrets = new Map<number, string>();\n for (const integration of integrations.github.list()) {\n for (const { appId, webhookSecret } of integration.config.apps ?? []) {\n if (appId && webhookSecret) {\n githubAppSecrets.set(appId, webhookSecret);\n }\n }\n }\n\n // A single optional secret for all GitHub events\n const genericSecret = config.getOptionalString(\n 'events.modules.github.webhookSecret',\n );\n\n if (!genericSecret && githubAppSecrets.size === 0) {\n return undefined;\n }\n\n const appIdResolver = createAppIdResolver(octokitProvider);\n\n return async (\n request: RequestDetails,\n context: RequestValidationContext,\n ): Promise<void> => {\n const signature = request.headers['x-hub-signature-256'] as\n | string\n | undefined;\n\n if (signature) {\n const body = request.raw.body.toString(request.raw.encoding);\n\n if (githubAppSecrets.size) {\n const appId = await appIdResolver(request);\n if (appId && githubAppSecrets.has(appId)) {\n if (await verify(githubAppSecrets.get(appId)!, body, signature)) {\n return;\n }\n }\n }\n\n if (genericSecret) {\n if (await verify(genericSecret, body, signature)) {\n return;\n }\n }\n }\n\n context.reject({\n status: 403,\n payload: { message: 'invalid signature' },\n });\n };\n}\n"],"names":["ScmIntegrations","createAppIdResolver","verify"],"mappings":";;;;;;AAsCO,SAAS,8BAAA,CACd,QACA,eAAA,EAC8B;AAC9B,EAAA,MAAM,YAAA,GAAeA,2BAAA,CAAgB,UAAA,CAAW,MAAM,CAAA;AAGtD,EAAA,MAAM,gBAAA,uBAAuB,GAAA,EAAoB;AACjD,EAAA,KAAA,MAAW,WAAA,IAAe,YAAA,CAAa,MAAA,CAAO,IAAA,EAAK,EAAG;AACpD,IAAA,KAAA,MAAW,EAAE,OAAO,aAAA,EAAc,IAAK,YAAY,MAAA,CAAO,IAAA,IAAQ,EAAC,EAAG;AACpE,MAAA,IAAI,SAAS,aAAA,EAAe;AAC1B,QAAA,gBAAA,CAAiB,GAAA,CAAI,OAAO,aAAa,CAAA;AAAA,MAC3C;AAAA,IACF;AAAA,EACF;AAGA,EAAA,MAAM,gBAAgB,MAAA,CAAO,iBAAA;AAAA,IAC3B;AAAA,GACF;AAEA,EAAA,IAAI,CAAC,aAAA,IAAiB,gBAAA,CAAiB,IAAA,KAAS,CAAA,EAAG;AACjD,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,aAAA,GAAgBC,wCAAoB,eAAe,CAAA;AAEzD,EAAA,OAAO,OACL,SACA,OAAA,KACkB;AAClB,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,OAAA,CAAQ,qBAAqB,CAAA;AAIvD,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,MAAM,OAAO,OAAA,CAAQ,GAAA,CAAI,KAAK,QAAA,CAAS,OAAA,CAAQ,IAAI,QAAQ,CAAA;AAE3D,MAAA,IAAI,iBAAiB,IAAA,EAAM;AACzB,QAAA,MAAM,KAAA,GAAQ,MAAM,aAAA,CAAc,OAAO,CAAA;AACzC,QAAA,IAAI,KAAA,IAAS,gBAAA,CAAiB,GAAA,CAAI,KAAK,CAAA,EAAG;AACxC,UAAA,IAAI,MAAMC,uBAAO,gBAAA,CAAiB,GAAA,CAAI,KAAK,CAAA,EAAI,IAAA,EAAM,SAAS,CAAA,EAAG;AAC/D,YAAA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,MAAA,IAAI,aAAA,EAAe;AACjB,QAAA,IAAI,MAAMA,sBAAA,CAAO,aAAA,EAAe,IAAA,EAAM,SAAS,CAAA,EAAG;AAChD,UAAA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,IAAA,OAAA,CAAQ,MAAA,CAAO;AAAA,MACb,MAAA,EAAQ,GAAA;AAAA,MACR,OAAA,EAAS,EAAE,OAAA,EAAS,mBAAA;AAAoB,KACzC,CAAA;AAAA,EACH,CAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 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 * The module `github` for the Backstage backend plugin \"events-backend\"\n * adding an event router and signature validator for GitHub.\n *\n * @packageDocumentation\n */\n\nimport { createBackendFeatureLoader } from '@backstage/backend-plugin-api';\n\nexport default createBackendFeatureLoader({\n loader() {\n return [\n import('./service/eventsModuleGithubEventRouter'),\n import('./service/eventsModuleGithubWebhook'),\n ];\n },\n});\n\n// TODO(freben): This is not exported at the moment since it depends on the octokit provider.\n// Until we have made that a core thing in integrations, we can't export it\n// export { createGithubSignatureValidator } from './http/createGithubSignatureValidator';\n\nexport { GithubEventRouter } from './router/GithubEventRouter';\n"],"names":["createBackendFeatureLoader"],"mappings":";;;;;;;AAyBA,YAAeA,2CAA2B,CAAA;AAAA,EACxC,MAAS,GAAA;AACP,IAAO,OAAA;AAAA,MACL,OAAO,gDAAyC,CAAA;AAAA,MAChD,OAAO,4CAAqC;AAAA,KAC9C;AAAA;AAEJ,CAAC,CAAA;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 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 * The module `github` for the Backstage backend plugin \"events-backend\"\n * adding an event router and signature validator for GitHub.\n *\n * @packageDocumentation\n */\n\nimport { createBackendFeatureLoader } from '@backstage/backend-plugin-api';\n\nexport default createBackendFeatureLoader({\n loader() {\n return [\n import('./service/eventsModuleGithubEventRouter'),\n import('./service/eventsModuleGithubWebhook'),\n ];\n },\n});\n\n// TODO(freben): This is not exported at the moment since it depends on the octokit provider.\n// Until we have made that a core thing in integrations, we can't export it\n// export { createGithubSignatureValidator } from './http/createGithubSignatureValidator';\n\nexport { GithubEventRouter } from './router/GithubEventRouter';\n"],"names":["createBackendFeatureLoader"],"mappings":";;;;;;;AAyBA,YAAeA,2CAAA,CAA2B;AAAA,EACxC,MAAA,GAAS;AACP,IAAA,OAAO;AAAA,MACL,OAAO,gDAAyC,CAAA;AAAA,MAChD,OAAO,4CAAqC;AAAA,KAC9C;AAAA,EACF;AACF,CAAC,CAAA;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"GithubEventRouter.cjs.js","sources":["../../src/router/GithubEventRouter.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 EventParams,\n EventsService,\n SubTopicEventRouter,\n} from '@backstage/plugin-events-node';\n\n/**\n * Subscribes to the generic `github` topic\n * and publishes the events under the more concrete sub-topic\n * depending on the `x-github-event` provided.\n *\n * @public\n */\nexport class GithubEventRouter extends SubTopicEventRouter {\n constructor(options: { events: EventsService }) {\n super({\n events: options.events,\n topic: 'github',\n });\n }\n\n protected getSubscriberId(): string {\n return 'GithubEventRouter';\n }\n\n protected determineSubTopic(params: EventParams): string | undefined {\n return params.metadata?.['x-github-event'] as string | undefined;\n }\n}\n"],"names":["SubTopicEventRouter"],"mappings":";;;;AA6BO,MAAM,0BAA0BA,oCAAoB,CAAA;AAAA,EACzD,YAAY,OAAoC,EAAA;AAC9C,IAAM,KAAA,CAAA;AAAA,MACJ,QAAQ,OAAQ,CAAA,MAAA;AAAA,MAChB,KAAO,EAAA;AAAA,KACR,CAAA;AAAA;AACH,EAEU,eAA0B,GAAA;AAClC,IAAO,OAAA,mBAAA;AAAA;AACT,EAEU,kBAAkB,MAAyC,EAAA;AACnE,IAAO,OAAA,MAAA,CAAO,WAAW,gBAAgB,CAAA;AAAA;AAE7C;;;;"}
1
+ {"version":3,"file":"GithubEventRouter.cjs.js","sources":["../../src/router/GithubEventRouter.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 EventParams,\n EventsService,\n SubTopicEventRouter,\n} from '@backstage/plugin-events-node';\n\n/**\n * Subscribes to the generic `github` topic\n * and publishes the events under the more concrete sub-topic\n * depending on the `x-github-event` provided.\n *\n * @public\n */\nexport class GithubEventRouter extends SubTopicEventRouter {\n constructor(options: { events: EventsService }) {\n super({\n events: options.events,\n topic: 'github',\n });\n }\n\n protected getSubscriberId(): string {\n return 'GithubEventRouter';\n }\n\n protected determineSubTopic(params: EventParams): string | undefined {\n return params.metadata?.['x-github-event'] as string | undefined;\n }\n}\n"],"names":["SubTopicEventRouter"],"mappings":";;;;AA6BO,MAAM,0BAA0BA,oCAAA,CAAoB;AAAA,EACzD,YAAY,OAAA,EAAoC;AAC9C,IAAA,KAAA,CAAM;AAAA,MACJ,QAAQ,OAAA,CAAQ,MAAA;AAAA,MAChB,KAAA,EAAO;AAAA,KACR,CAAA;AAAA,EACH;AAAA,EAEU,eAAA,GAA0B;AAClC,IAAA,OAAO,mBAAA;AAAA,EACT;AAAA,EAEU,kBAAkB,MAAA,EAAyC;AACnE,IAAA,OAAO,MAAA,CAAO,WAAW,gBAAgB,CAAA;AAAA,EAC3C;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"eventsModuleGithubEventRouter.cjs.js","sources":["../../src/service/eventsModuleGithubEventRouter.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 { createBackendModule } from '@backstage/backend-plugin-api';\nimport { eventsServiceRef } from '@backstage/plugin-events-node';\nimport { GithubEventRouter } from '../router/GithubEventRouter';\n\n/**\n * Module for the events-backend plugin, adding an event router for GitHub.\n *\n * Registers the `GithubEventRouter`.\n *\n * @public\n */\nexport default createBackendModule({\n pluginId: 'events',\n moduleId: 'github-event-router',\n register(env) {\n env.registerInit({\n deps: {\n events: eventsServiceRef,\n },\n async init({ events }) {\n const eventRouter = new GithubEventRouter({ events });\n await eventRouter.subscribe();\n },\n });\n },\n});\n"],"names":["createBackendModule","eventsServiceRef","GithubEventRouter"],"mappings":";;;;;;;;AA2BA,oCAAeA,oCAAoB,CAAA;AAAA,EACjC,QAAU,EAAA,QAAA;AAAA,EACV,QAAU,EAAA,qBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,MAAQ,EAAAC;AAAA,OACV;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,MAAA,EAAU,EAAA;AACrB,QAAA,MAAM,WAAc,GAAA,IAAIC,mCAAkB,CAAA,EAAE,QAAQ,CAAA;AACpD,QAAA,MAAM,YAAY,SAAU,EAAA;AAAA;AAC9B,KACD,CAAA;AAAA;AAEL,CAAC,CAAA;;;;"}
1
+ {"version":3,"file":"eventsModuleGithubEventRouter.cjs.js","sources":["../../src/service/eventsModuleGithubEventRouter.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 { createBackendModule } from '@backstage/backend-plugin-api';\nimport { eventsServiceRef } from '@backstage/plugin-events-node';\nimport { GithubEventRouter } from '../router/GithubEventRouter';\n\n/**\n * Module for the events-backend plugin, adding an event router for GitHub.\n *\n * Registers the `GithubEventRouter`.\n *\n * @public\n */\nexport default createBackendModule({\n pluginId: 'events',\n moduleId: 'github-event-router',\n register(env) {\n env.registerInit({\n deps: {\n events: eventsServiceRef,\n },\n async init({ events }) {\n const eventRouter = new GithubEventRouter({ events });\n await eventRouter.subscribe();\n },\n });\n },\n});\n"],"names":["createBackendModule","eventsServiceRef","GithubEventRouter"],"mappings":";;;;;;;;AA2BA,oCAAeA,oCAAA,CAAoB;AAAA,EACjC,QAAA,EAAU,QAAA;AAAA,EACV,QAAA,EAAU,qBAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,MAAA,EAAQC;AAAA,OACV;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,MAAA,EAAO,EAAG;AACrB,QAAA,MAAM,WAAA,GAAc,IAAIC,mCAAA,CAAkB,EAAE,QAAQ,CAAA;AACpD,QAAA,MAAM,YAAY,SAAA,EAAU;AAAA,MAC9B;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"eventsModuleGithubWebhook.cjs.js","sources":["../../src/service/eventsModuleGithubWebhook.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 coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { eventsExtensionPoint } from '@backstage/plugin-events-node/alpha';\nimport { createGithubSignatureValidator } from '../http/createGithubSignatureValidator';\nimport { octokitProviderServiceRef } from '../util/octokitProviderService';\n\n/**\n * Module for the events-backend plugin,\n * registering an HTTP POST ingress with request validator\n * which verifies the webhook signature based on a secret.\n *\n * @public\n */\nexport default createBackendModule({\n pluginId: 'events',\n moduleId: 'github-webhook',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n events: eventsExtensionPoint,\n octokitProvider: octokitProviderServiceRef,\n },\n async init({ config, events, octokitProvider }) {\n const validator = createGithubSignatureValidator(\n config,\n octokitProvider,\n );\n if (validator) {\n events.addHttpPostIngress({\n topic: 'github',\n validator,\n });\n }\n },\n });\n },\n});\n"],"names":["createBackendModule","coreServices","eventsExtensionPoint","octokitProviderServiceRef","createGithubSignatureValidator"],"mappings":";;;;;;;;;AA+BA,gCAAeA,oCAAoB,CAAA;AAAA,EACjC,QAAU,EAAA,QAAA;AAAA,EACV,QAAU,EAAA,gBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,UAAA;AAAA,QACrB,MAAQ,EAAAC,0BAAA;AAAA,QACR,eAAiB,EAAAC;AAAA,OACnB;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,MAAQ,EAAA,MAAA,EAAQ,iBAAmB,EAAA;AAC9C,QAAA,MAAM,SAAY,GAAAC,6DAAA;AAAA,UAChB,MAAA;AAAA,UACA;AAAA,SACF;AACA,QAAA,IAAI,SAAW,EAAA;AACb,UAAA,MAAA,CAAO,kBAAmB,CAAA;AAAA,YACxB,KAAO,EAAA,QAAA;AAAA,YACP;AAAA,WACD,CAAA;AAAA;AACH;AACF,KACD,CAAA;AAAA;AAEL,CAAC,CAAA;;;;"}
1
+ {"version":3,"file":"eventsModuleGithubWebhook.cjs.js","sources":["../../src/service/eventsModuleGithubWebhook.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 coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { eventsExtensionPoint } from '@backstage/plugin-events-node/alpha';\nimport { createGithubSignatureValidator } from '../http/createGithubSignatureValidator';\nimport { octokitProviderServiceRef } from '../util/octokitProviderService';\n\n/**\n * Module for the events-backend plugin,\n * registering an HTTP POST ingress with request validator\n * which verifies the webhook signature based on a secret.\n *\n * @public\n */\nexport default createBackendModule({\n pluginId: 'events',\n moduleId: 'github-webhook',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n events: eventsExtensionPoint,\n octokitProvider: octokitProviderServiceRef,\n },\n async init({ config, events, octokitProvider }) {\n const validator = createGithubSignatureValidator(\n config,\n octokitProvider,\n );\n if (validator) {\n events.addHttpPostIngress({\n topic: 'github',\n validator,\n });\n }\n },\n });\n },\n});\n"],"names":["createBackendModule","coreServices","eventsExtensionPoint","octokitProviderServiceRef","createGithubSignatureValidator"],"mappings":";;;;;;;;;AA+BA,gCAAeA,oCAAA,CAAoB;AAAA,EACjC,QAAA,EAAU,QAAA;AAAA,EACV,QAAA,EAAU,gBAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,QAAQC,6BAAA,CAAa,UAAA;AAAA,QACrB,MAAA,EAAQC,0BAAA;AAAA,QACR,eAAA,EAAiBC;AAAA,OACnB;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,MAAA,EAAQ,iBAAgB,EAAG;AAC9C,QAAA,MAAM,SAAA,GAAYC,6DAAA;AAAA,UAChB,MAAA;AAAA,UACA;AAAA,SACF;AACA,QAAA,IAAI,SAAA,EAAW;AACb,UAAA,MAAA,CAAO,kBAAA,CAAmB;AAAA,YACxB,KAAA,EAAO,QAAA;AAAA,YACP;AAAA,WACD,CAAA;AAAA,QACH;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createAppIdResolver.cjs.js","sources":["../../src/util/createAppIdResolver.ts"],"sourcesContent":["/*\n * Copyright 2025 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 { RequestDetails } from '@backstage/plugin-events-node';\nimport { OctokitProviderService } from './octokitProviderService';\nimport lodash from 'lodash';\n\nexport type AppIdResolver = (\n request: RequestDetails,\n) => Promise<number | undefined>;\n\n/**\n * Helps with resolving what app ID (if any) that sent a webhook event.\n */\nexport function createAppIdResolver(\n octokitProvider: OctokitProviderService,\n): AppIdResolver {\n const installationIdToAppId = new Map<number, Promise<number | undefined>>();\n\n return async (request: RequestDetails) => {\n const installationId = lodash.get(\n request.body,\n 'installation.id',\n ) as unknown;\n\n if (!installationId || typeof installationId !== 'number') {\n return undefined;\n }\n\n let appIdPromsie = installationIdToAppId.get(installationId);\n if (appIdPromsie) {\n return await appIdPromsie;\n }\n\n const repositoryUrl = lodash.get(\n request.body,\n 'repository.html_url',\n ) as unknown;\n\n if (!repositoryUrl || typeof repositoryUrl !== 'string') {\n return undefined;\n }\n\n const octokit = await octokitProvider.getOctokit(repositoryUrl);\n appIdPromsie = octokit.rest.apps\n .getInstallation({ installation_id: installationId })\n .then(response => Number(response.data.app_id))\n .catch(() => undefined);\n\n installationIdToAppId.set(installationId, appIdPromsie);\n return await appIdPromsie;\n };\n}\n"],"names":["lodash"],"mappings":";;;;;;;;AA2BO,SAAS,oBACd,eACe,EAAA;AACf,EAAM,MAAA,qBAAA,uBAA4B,GAAyC,EAAA;AAE3E,EAAA,OAAO,OAAO,OAA4B,KAAA;AACxC,IAAA,MAAM,iBAAiBA,uBAAO,CAAA,GAAA;AAAA,MAC5B,OAAQ,CAAA,IAAA;AAAA,MACR;AAAA,KACF;AAEA,IAAA,IAAI,CAAC,cAAA,IAAkB,OAAO,cAAA,KAAmB,QAAU,EAAA;AACzD,MAAO,OAAA,KAAA,CAAA;AAAA;AAGT,IAAI,IAAA,YAAA,GAAe,qBAAsB,CAAA,GAAA,CAAI,cAAc,CAAA;AAC3D,IAAA,IAAI,YAAc,EAAA;AAChB,MAAA,OAAO,MAAM,YAAA;AAAA;AAGf,IAAA,MAAM,gBAAgBA,uBAAO,CAAA,GAAA;AAAA,MAC3B,OAAQ,CAAA,IAAA;AAAA,MACR;AAAA,KACF;AAEA,IAAA,IAAI,CAAC,aAAA,IAAiB,OAAO,aAAA,KAAkB,QAAU,EAAA;AACvD,MAAO,OAAA,KAAA,CAAA;AAAA;AAGT,IAAA,MAAM,OAAU,GAAA,MAAM,eAAgB,CAAA,UAAA,CAAW,aAAa,CAAA;AAC9D,IAAA,YAAA,GAAe,QAAQ,IAAK,CAAA,IAAA,CACzB,gBAAgB,EAAE,eAAA,EAAiB,gBAAgB,CAAA,CACnD,KAAK,CAAY,QAAA,KAAA,MAAA,CAAO,SAAS,IAAK,CAAA,MAAM,CAAC,CAC7C,CAAA,KAAA,CAAM,MAAM,KAAS,CAAA,CAAA;AAExB,IAAsB,qBAAA,CAAA,GAAA,CAAI,gBAAgB,YAAY,CAAA;AACtD,IAAA,OAAO,MAAM,YAAA;AAAA,GACf;AACF;;;;"}
1
+ {"version":3,"file":"createAppIdResolver.cjs.js","sources":["../../src/util/createAppIdResolver.ts"],"sourcesContent":["/*\n * Copyright 2025 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 { RequestDetails } from '@backstage/plugin-events-node';\nimport { OctokitProviderService } from './octokitProviderService';\nimport lodash from 'lodash';\n\nexport type AppIdResolver = (\n request: RequestDetails,\n) => Promise<number | undefined>;\n\n/**\n * Helps with resolving what app ID (if any) that sent a webhook event.\n */\nexport function createAppIdResolver(\n octokitProvider: OctokitProviderService,\n): AppIdResolver {\n const installationIdToAppId = new Map<number, Promise<number | undefined>>();\n\n return async (request: RequestDetails) => {\n const installationId = lodash.get(\n request.body,\n 'installation.id',\n ) as unknown;\n\n if (!installationId || typeof installationId !== 'number') {\n return undefined;\n }\n\n let appIdPromsie = installationIdToAppId.get(installationId);\n if (appIdPromsie) {\n return await appIdPromsie;\n }\n\n const repositoryUrl = lodash.get(\n request.body,\n 'repository.html_url',\n ) as unknown;\n\n if (!repositoryUrl || typeof repositoryUrl !== 'string') {\n return undefined;\n }\n\n const octokit = await octokitProvider.getOctokit(repositoryUrl);\n appIdPromsie = octokit.rest.apps\n .getInstallation({ installation_id: installationId })\n .then(response => Number(response.data.app_id))\n .catch(() => undefined);\n\n installationIdToAppId.set(installationId, appIdPromsie);\n return await appIdPromsie;\n };\n}\n"],"names":["lodash"],"mappings":";;;;;;;;AA2BO,SAAS,oBACd,eAAA,EACe;AACf,EAAA,MAAM,qBAAA,uBAA4B,GAAA,EAAyC;AAE3E,EAAA,OAAO,OAAO,OAAA,KAA4B;AACxC,IAAA,MAAM,iBAAiBA,uBAAA,CAAO,GAAA;AAAA,MAC5B,OAAA,CAAQ,IAAA;AAAA,MACR;AAAA,KACF;AAEA,IAAA,IAAI,CAAC,cAAA,IAAkB,OAAO,cAAA,KAAmB,QAAA,EAAU;AACzD,MAAA,OAAO,MAAA;AAAA,IACT;AAEA,IAAA,IAAI,YAAA,GAAe,qBAAA,CAAsB,GAAA,CAAI,cAAc,CAAA;AAC3D,IAAA,IAAI,YAAA,EAAc;AAChB,MAAA,OAAO,MAAM,YAAA;AAAA,IACf;AAEA,IAAA,MAAM,gBAAgBA,uBAAA,CAAO,GAAA;AAAA,MAC3B,OAAA,CAAQ,IAAA;AAAA,MACR;AAAA,KACF;AAEA,IAAA,IAAI,CAAC,aAAA,IAAiB,OAAO,aAAA,KAAkB,QAAA,EAAU;AACvD,MAAA,OAAO,MAAA;AAAA,IACT;AAEA,IAAA,MAAM,OAAA,GAAU,MAAM,eAAA,CAAgB,UAAA,CAAW,aAAa,CAAA;AAC9D,IAAA,YAAA,GAAe,QAAQ,IAAA,CAAK,IAAA,CACzB,gBAAgB,EAAE,eAAA,EAAiB,gBAAgB,CAAA,CACnD,KAAK,CAAA,QAAA,KAAY,MAAA,CAAO,SAAS,IAAA,CAAK,MAAM,CAAC,CAAA,CAC7C,KAAA,CAAM,MAAM,MAAS,CAAA;AAExB,IAAA,qBAAA,CAAsB,GAAA,CAAI,gBAAgB,YAAY,CAAA;AACtD,IAAA,OAAO,MAAM,YAAA;AAAA,EACf,CAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"octokitProviderService.cjs.js","sources":["../../src/util/octokitProviderService.ts"],"sourcesContent":["/*\n * Copyright 2025 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 RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport {\n DefaultGithubCredentialsProvider,\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n ScmIntegrations,\n} from '@backstage/integration';\nimport { durationToMilliseconds, HumanDuration } from '@backstage/types';\nimport { Octokit } from 'octokit';\n\nexport interface OctokitProviderService {\n getOctokit: (url: string) => Promise<Octokit>;\n}\n\nclass OctokitProviderImpl implements OctokitProviderService {\n readonly #integrations: ScmIntegrationRegistry;\n readonly #githubCredentials: GithubCredentialsProvider;\n readonly #octokitCache: Map<string, Octokit>;\n readonly #octokitCacheTtl: HumanDuration;\n\n constructor(config: RootConfigService) {\n this.#integrations = ScmIntegrations.fromConfig(config);\n this.#githubCredentials = DefaultGithubCredentialsProvider.fromIntegrations(\n this.#integrations,\n );\n this.#octokitCache = new Map();\n this.#octokitCacheTtl = { hours: 1 };\n }\n\n async getOctokit(url: string): Promise<Octokit> {\n // TODO(freben): Be smart and cache these more granularly, e.g. by\n // organization or even repo.\n const integration = this.#integrations.github.byUrl(url);\n if (!integration) {\n throw new Error(`No integration found for url: ${url}`);\n }\n const key = integration.config.host;\n\n if (this.#octokitCache.has(key)) {\n return this.#octokitCache.get(key)!;\n }\n\n const { createCallbackAuth } = await import('@octokit/auth-callback');\n\n const octokit = new Octokit({\n baseUrl: integration.config.apiBaseUrl,\n authStrategy: createCallbackAuth,\n auth: {\n callback: async () => {\n try {\n const credentials = await this.#githubCredentials.getCredentials({\n url,\n });\n return credentials.token;\n } catch {\n return undefined;\n }\n },\n },\n });\n\n this.#octokitCache.set(key, octokit);\n setTimeout(() => {\n this.#octokitCache.delete(key);\n }, durationToMilliseconds(this.#octokitCacheTtl));\n\n return octokit;\n }\n}\n\nexport const octokitProviderServiceRef =\n createServiceRef<OctokitProviderService>({\n id: 'octokitProvider',\n scope: 'root',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: { config: coreServices.rootConfig },\n async factory({ config }) {\n return new OctokitProviderImpl(config);\n },\n }),\n });\n"],"names":["ScmIntegrations","DefaultGithubCredentialsProvider","octokit","Octokit","durationToMilliseconds","createServiceRef","createServiceFactory","coreServices"],"mappings":";;;;;;;AAmCA,MAAM,mBAAsD,CAAA;AAAA,EACjD,aAAA;AAAA,EACA,kBAAA;AAAA,EACA,aAAA;AAAA,EACA,gBAAA;AAAA,EAET,YAAY,MAA2B,EAAA;AACrC,IAAK,IAAA,CAAA,aAAA,GAAgBA,2BAAgB,CAAA,UAAA,CAAW,MAAM,CAAA;AACtD,IAAA,IAAA,CAAK,qBAAqBC,4CAAiC,CAAA,gBAAA;AAAA,MACzD,IAAK,CAAA;AAAA,KACP;AACA,IAAK,IAAA,CAAA,aAAA,uBAAoB,GAAI,EAAA;AAC7B,IAAK,IAAA,CAAA,gBAAA,GAAmB,EAAE,KAAA,EAAO,CAAE,EAAA;AAAA;AACrC,EAEA,MAAM,WAAW,GAA+B,EAAA;AAG9C,IAAA,MAAM,WAAc,GAAA,IAAA,CAAK,aAAc,CAAA,MAAA,CAAO,MAAM,GAAG,CAAA;AACvD,IAAA,IAAI,CAAC,WAAa,EAAA;AAChB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAiC,8BAAA,EAAA,GAAG,CAAE,CAAA,CAAA;AAAA;AAExD,IAAM,MAAA,GAAA,GAAM,YAAY,MAAO,CAAA,IAAA;AAE/B,IAAA,IAAI,IAAK,CAAA,aAAA,CAAc,GAAI,CAAA,GAAG,CAAG,EAAA;AAC/B,MAAO,OAAA,IAAA,CAAK,aAAc,CAAA,GAA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Copyright 2025 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 RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport {\n DefaultGithubCredentialsProvider,\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n ScmIntegrations,\n} from '@backstage/integration';\nimport { durationToMilliseconds, HumanDuration } from '@backstage/types';\nimport { Octokit } from 'octokit';\n\nexport interface OctokitProviderService {\n getOctokit: (url: string) => Promise<Octokit>;\n}\n\nclass OctokitProviderImpl implements OctokitProviderService {\n readonly #integrations: ScmIntegrationRegistry;\n readonly #githubCredentials: GithubCredentialsProvider;\n readonly #octokitCache: Map<string, Octokit>;\n readonly #octokitCacheTtl: HumanDuration;\n\n constructor(config: RootConfigService) {\n this.#integrations = ScmIntegrations.fromConfig(config);\n this.#githubCredentials = DefaultGithubCredentialsProvider.fromIntegrations(\n this.#integrations,\n );\n this.#octokitCache = new Map();\n this.#octokitCacheTtl = { hours: 1 };\n }\n\n async getOctokit(url: string): Promise<Octokit> {\n // TODO(freben): Be smart and cache these more granularly, e.g. by\n // organization or even repo.\n const integration = this.#integrations.github.byUrl(url);\n if (!integration) {\n throw new Error(`No integration found for url: ${url}`);\n }\n const key = integration.config.host;\n\n if (this.#octokitCache.has(key)) {\n return this.#octokitCache.get(key)!;\n }\n\n const { createCallbackAuth } = await import('@octokit/auth-callback');\n\n const octokit = new Octokit({\n baseUrl: integration.config.apiBaseUrl,\n authStrategy: createCallbackAuth,\n auth: {\n callback: async () => {\n try {\n const credentials = await this.#githubCredentials.getCredentials({\n url,\n });\n return credentials.token;\n } catch {\n return undefined;\n }\n },\n },\n });\n\n this.#octokitCache.set(key, octokit);\n setTimeout(() => {\n this.#octokitCache.delete(key);\n }, durationToMilliseconds(this.#octokitCacheTtl));\n\n return octokit;\n }\n}\n\nexport const octokitProviderServiceRef =\n createServiceRef<OctokitProviderService>({\n id: 'octokitProvider',\n scope: 'root',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: { config: coreServices.rootConfig },\n async factory({ config }) {\n return new OctokitProviderImpl(config);\n },\n }),\n });\n"],"names":["ScmIntegrations","DefaultGithubCredentialsProvider","octokit","Octokit","durationToMilliseconds","createServiceRef","createServiceFactory","coreServices"],"mappings":";;;;;;;AAmCA,MAAM,mBAAA,CAAsD;AAAA,EACjD,aAAA;AAAA,EACA,kBAAA;AAAA,EACA,aAAA;AAAA,EACA,gBAAA;AAAA,EAET,YAAY,MAAA,EAA2B;AACrC,IAAA,IAAA,CAAK,aAAA,GAAgBA,2BAAA,CAAgB,UAAA,CAAW,MAAM,CAAA;AACtD,IAAA,IAAA,CAAK,qBAAqBC,4CAAA,CAAiC,gBAAA;AAAA,MACzD,IAAA,CAAK;AAAA,KACP;AACA,IAAA,IAAA,CAAK,aAAA,uBAAoB,GAAA,EAAI;AAC7B,IAAA,IAAA,CAAK,gBAAA,GAAmB,EAAE,KAAA,EAAO,CAAA,EAAE;AAAA,EACrC;AAAA,EAEA,MAAM,WAAW,GAAA,EAA+B;AAG9C,IAAA,MAAM,WAAA,GAAc,IAAA,CAAK,aAAA,CAAc,MAAA,CAAO,MAAM,GAAG,CAAA;AACvD,IAAA,IAAI,CAAC,WAAA,EAAa;AAChB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,8BAAA,EAAiC,GAAG,CAAA,CAAE,CAAA;AAAA,IACxD;AACA,IAAA,MAAM,GAAA,GAAM,YAAY,MAAA,CAAO,IAAA;AAE/B,IAAA,IAAI,IAAA,CAAK,aAAA,CAAc,GAAA,CAAI,GAAG,CAAA,EAAG;AAC/B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package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-backend-module-github",
3
- "version": "0.4.3-next.0",
3
+ "version": "0.4.4-next.0",
4
4
  "backstage": {
5
5
  "role": "backend-plugin-module",
6
6
  "pluginId": "events",
@@ -51,10 +51,10 @@
51
51
  "test": "backstage-cli package test"
52
52
  },
53
53
  "dependencies": {
54
- "@backstage/backend-plugin-api": "1.4.2-next.0",
54
+ "@backstage/backend-plugin-api": "1.4.3-next.0",
55
55
  "@backstage/config": "1.3.3",
56
- "@backstage/integration": "1.17.1",
57
- "@backstage/plugin-events-node": "0.4.14-next.0",
56
+ "@backstage/integration": "1.18.0-next.0",
57
+ "@backstage/plugin-events-node": "0.4.15-next.0",
58
58
  "@backstage/types": "1.2.1",
59
59
  "@octokit/auth-callback": "^5.0.0",
60
60
  "@octokit/webhooks-methods": "^3.0.0",
@@ -62,9 +62,9 @@
62
62
  "octokit": "^3.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@backstage/backend-test-utils": "1.7.1-next.0",
66
- "@backstage/cli": "0.33.2-next.0",
67
- "@backstage/plugin-events-backend-test-utils": "0.1.47-next.0"
65
+ "@backstage/backend-test-utils": "1.9.0-next.1",
66
+ "@backstage/cli": "0.34.2-next.1",
67
+ "@backstage/plugin-events-backend-test-utils": "0.1.48-next.0"
68
68
  },
69
69
  "configSchema": "config.d.ts"
70
70
  }