@pagerduty/backstage-plugin-backend 0.1.3-next.4 → 0.1.3-next.5
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/dist/index.cjs.js +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -25,13 +25,13 @@ async function createRouter(options) {
|
|
|
25
25
|
headers: {
|
|
26
26
|
"Accept": "application/vnd.pagerduty+json;version=2",
|
|
27
27
|
"Content-Type": "application/json",
|
|
28
|
-
"Authorization": `Token token=${config.getOptionalString("
|
|
28
|
+
"Authorization": `Token token=${config.getOptionalString("pagerDuty.apiToken")}`
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
response.status(res.status);
|
|
32
|
+
if (res.status === 200) {
|
|
33
|
+
response.json(await res.json());
|
|
34
|
+
}
|
|
35
35
|
} catch (error) {
|
|
36
36
|
logger.error(error);
|
|
37
37
|
response.status(500).json({ error });
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/service/router.ts","../src/apis/pagerduty.ts","../src/actions/custom.ts"],"sourcesContent":["import { errorHandler } from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { Logger } from 'winston';\n\nexport interface RouterOptions {\n logger: Logger;\n config: Config;\n}\n\nexport async function createRouter(\n options: RouterOptions\n): Promise<express.Router> {\n const { logger, config } = options;\n\n const router = Router();\n router.use(express.json());\n\n router.get('/escalation_policies', async (_, response) => {\n logger.info('Getting escalation policies');\n\n try {\n const res = await fetch('https://api.pagerduty.com/escalation_policies?total=true&sort_by=name&limit=100', {\n method: 'GET',\n headers: {\n 'Accept': 'application/vnd.pagerduty+json;version=2',\n 'Content-Type': 'application/json',\n 'Authorization': `Token token=${config.getOptionalString('pagerduty.apiToken')}`\n }\n });\n\n logger.info(`apiToken: ${config.getOptionalString('pagerduty.apiToken')}`);\n logger.info(`http status: ${res.status}`);\n logger.info(`http body: ${JSON.stringify(await res.json())}`);\n\n response.status(res.status).json(await res.json());\n } catch (error) {\n logger.error(error);\n response.status(500).json({ error });\n }\n });\n\n router.get('/health', async (_, response) => {\n response.status(200).json({ status: 'ok' });\n });\n\n router.use(errorHandler());\n return router;\n}","import { PagerDutyCreateIntegrationResponse, PagerDutyCreateServiceResponse } from \"../types\";\n\nexport async function createService(name: string, description: string, escalationPolicyId: string): Promise<[string, string]> {\n let response: Response;\n const baseUrl = 'https://api.pagerduty.com/services';\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n name: name,\n description: description,\n escalation_policy: {\n id: escalationPolicyId,\n type: 'escalation_policy_reference',\n },\n }),\n headers: {\n Authorization: `Token token=${process.env.PAGERDUTY_TOKEN}`,\n 'Accept': 'application/vnd.pagerduty+json;version=2',\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(baseUrl, options);\n } catch (error) {\n throw new Error(`Failed to create service: ${error}`);\n }\n\n switch (response.status) {\n case 400:\n throw new Error(`Failed to create service. Caller provided invalid arguments.`);\n case 401:\n throw new Error(`Failed to create service. Caller did not supply credentials or did not provide the correct credentials.`);\n case 402:\n throw new Error(`Failed to create service. Account does not have the abilities to perform the action.`);\n case 403:\n throw new Error(`Failed to create service. Caller is not authorized to view the requested resource.`);\n default: // 201\n break;\n }\n\n let result: PagerDutyCreateServiceResponse;\n try {\n result = await response.json();\n\n return [result.service.id, result.service.htmlUrl];\n } catch (error) {\n throw new Error(`Failed to parse service information: ${error}`);\n }\n}\n\nexport async function createServiceIntegration(serviceId: string, vendorId: string): Promise<string> {\n let response: Response;\n const baseUrl = 'https://api.pagerduty.com/services';\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n integration: {\n name: 'Backstage',\n service: {\n id: serviceId,\n type: 'service_reference',\n },\n vendor: {\n id: vendorId,\n type: 'vendor_reference',\n }\n }\n }),\n headers: {\n Authorization: `Token token=${process.env.PAGERDUTY_TOKEN}`,\n 'Accept': 'application/vnd.pagerduty+json;version=2',\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(`${baseUrl}/${serviceId}/integrations`, options);\n } catch (error) {\n throw new Error(`Failed to create service: ${error}`);\n }\n\n switch (response.status) {\n case 400:\n throw new Error(`Failed to create service integration. Caller provided invalid arguments.`);\n case 401:\n throw new Error(`Failed to create service integration. Caller did not supply credentials or did not provide the correct credentials.`);\n case 403:\n throw new Error(`Failed to create service integration. Caller is not authorized to view the requested resource.`);\n case 429:\n throw new Error(`Failed to create service integration. Rate limit exceeded.`);\n default: // 201\n break;\n }\n\n let result: PagerDutyCreateIntegrationResponse;\n try {\n result = await response.json();\n\n return result.integration.integration_key;\n\n } catch (error) {\n throw new Error(`Failed to parse service information: ${error}`);\n }\n}\n","import { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { z } from 'zod';\nimport * as api from '../apis/pagerduty';\n\nexport const createPagerDutyServiceAction = () => {\n\n return createTemplateAction<{\n name: string;\n description: string;\n escalationPolicyId: string;\n }>({\n id: 'pagerduty:service:create',\n schema: {\n input: z.object({\n name: z.string().min(1, \"name is required\").describe('Name of the service'),\n description: z.string().min(1, \"description is required\").describe('Description of the service'),\n escalationPolicyId: z.string().min(1, \"Escalation policy is required\").describe('Escalation policy ID'),\n }),\n output: z.object({\n serviceUrl: z.string().describe('PagerDuty Service URL'),\n serviceId: z.string().describe('PagerDuty Service ID'),\n integrationKey: z.string().describe('Backstage Integration Key'),\n }),\n },\n\n async handler(ctx) {\n try {\n // Create service in PagerDuty\n const [serviceId, serviceUrl] = await api.createService(ctx.input.name, ctx.input.description, ctx.input.escalationPolicyId);\n ctx.logger.info(`Service '${ctx.input.name}' created successfully!`);\n\n ctx.output('serviceUrl', serviceUrl);\n ctx.output('serviceId', serviceId);\n\n // Create Backstage Integration in PagerDuty service\n const backstageIntegrationId = 'PRO19CT'; // ID for Backstage integration\n const integrationKey = await api.createServiceIntegration(serviceId, backstageIntegrationId);\n ctx.logger.info(`Backstage Integration for service '${ctx.input.name}' created successfully!`);\n\n ctx.output('integrationKey', integrationKey);\n } catch (error) {\n ctx.logger.error(`${error}`);\n }\n\n }\n });\n};\n"],"names":["Router","express","errorHandler","createTemplateAction","z","api.createService","api.createServiceIntegration"],"mappings":";;;;;;;;;;;;;;;AAWA,eAAsB,aAClB,OACuB,EAAA;AACvB,EAAM,MAAA,EAAE,MAAQ,EAAA,MAAA,EAAW,GAAA,OAAA,CAAA;AAE3B,EAAA,MAAM,SAASA,0BAAO,EAAA,CAAA;AACtB,EAAO,MAAA,CAAA,GAAA,CAAIC,2BAAQ,CAAA,IAAA,EAAM,CAAA,CAAA;AAEzB,EAAA,MAAA,CAAO,GAAI,CAAA,sBAAA,EAAwB,OAAO,CAAA,EAAG,QAAa,KAAA;AACtD,IAAA,MAAA,CAAO,KAAK,6BAA6B,CAAA,CAAA;AAEzC,IAAI,IAAA;AACA,MAAM,MAAA,GAAA,GAAM,MAAM,KAAA,CAAM,iFAAmF,EAAA;AAAA,QACvG,MAAQ,EAAA,KAAA;AAAA,QACR,OAAS,EAAA;AAAA,UACL,QAAU,EAAA,0CAAA;AAAA,UACV,cAAgB,EAAA,kBAAA;AAAA,UAChB,eAAiB,EAAA,CAAA,YAAA,EAAe,MAAO,CAAA,iBAAA,CAAkB,oBAAoB,CAAC,CAAA,CAAA;AAAA,SAClF;AAAA,OACH,CAAA,CAAA;AAED,MAAA,MAAA,CAAO,KAAK,CAAa,UAAA,EAAA,MAAA,CAAO,iBAAkB,CAAA,oBAAoB,CAAC,CAAE,CAAA,CAAA,CAAA;AACzE,MAAA,MAAA,CAAO,IAAK,CAAA,CAAA,aAAA,EAAgB,GAAI,CAAA,MAAM,CAAE,CAAA,CAAA,CAAA;AACxC,MAAO,MAAA,CAAA,IAAA,CAAK,cAAc,IAAK,CAAA,SAAA,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,CAAM,IAAI,CAAyB,uBAAA,CAAA,CAAA,CAAA;AAEnE,QAAI,GAAA,CAAA,MAAA,CAAO,cAAc,UAAU,CAAA,CAAA;AACnC,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA,CAAA;AAGjC,QAAA,MAAM,sBAAyB,GAAA,SAAA,CAAA;AAC/B,QAAA,MAAM,cAAiB,GAAA,MAAMC,wBAAI,CAAyB,WAAW,sBAAsB,CAAA,CAAA;AAC3F,QAAA,GAAA,CAAI,OAAO,IAAK,CAAA,CAAA,mCAAA,EAAsC,GAAI,CAAA,KAAA,CAAM,IAAI,CAAyB,uBAAA,CAAA,CAAA,CAAA;AAE7F,QAAI,GAAA,CAAA,MAAA,CAAO,kBAAkB,cAAc,CAAA,CAAA;AAAA,eACtC,KAAO,EAAA;AACZ,QAAA,GAAA,CAAI,MAAO,CAAA,KAAA,CAAM,CAAG,EAAA,KAAK,CAAE,CAAA,CAAA,CAAA;AAAA,OAC/B;AAAA,KAEJ;AAAA,GACH,CAAA,CAAA;AACL;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/service/router.ts","../src/apis/pagerduty.ts","../src/actions/custom.ts"],"sourcesContent":["import { errorHandler } from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { Logger } from 'winston';\n\nexport interface RouterOptions {\n logger: Logger;\n config: Config;\n}\n\nexport async function createRouter(\n options: RouterOptions\n): Promise<express.Router> {\n const { logger, config } = options;\n\n const router = Router();\n router.use(express.json());\n\n router.get('/escalation_policies', async (_, response) => {\n logger.info('Getting escalation policies');\n\n try {\n const res = await fetch('https://api.pagerduty.com/escalation_policies?total=true&sort_by=name&limit=100', {\n method: 'GET',\n headers: {\n 'Accept': 'application/vnd.pagerduty+json;version=2',\n 'Content-Type': 'application/json',\n 'Authorization': `Token token=${config.getOptionalString('pagerDuty.apiToken')}`\n }\n });\n\n response.status(res.status);\n \n if (res.status === 200) {\n response.json(await res.json());\n }\n } catch (error) {\n logger.error(error);\n response.status(500).json({ error });\n }\n });\n\n router.get('/health', async (_, response) => {\n response.status(200).json({ status: 'ok' });\n });\n\n router.use(errorHandler());\n return router;\n}","import { PagerDutyCreateIntegrationResponse, PagerDutyCreateServiceResponse } from \"../types\";\n\nexport async function createService(name: string, description: string, escalationPolicyId: string): Promise<[string, string]> {\n let response: Response;\n const baseUrl = 'https://api.pagerduty.com/services';\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n name: name,\n description: description,\n escalation_policy: {\n id: escalationPolicyId,\n type: 'escalation_policy_reference',\n },\n }),\n headers: {\n Authorization: `Token token=${process.env.PAGERDUTY_TOKEN}`,\n 'Accept': 'application/vnd.pagerduty+json;version=2',\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(baseUrl, options);\n } catch (error) {\n throw new Error(`Failed to create service: ${error}`);\n }\n\n switch (response.status) {\n case 400:\n throw new Error(`Failed to create service. Caller provided invalid arguments.`);\n case 401:\n throw new Error(`Failed to create service. Caller did not supply credentials or did not provide the correct credentials.`);\n case 402:\n throw new Error(`Failed to create service. Account does not have the abilities to perform the action.`);\n case 403:\n throw new Error(`Failed to create service. Caller is not authorized to view the requested resource.`);\n default: // 201\n break;\n }\n\n let result: PagerDutyCreateServiceResponse;\n try {\n result = await response.json();\n\n return [result.service.id, result.service.htmlUrl];\n } catch (error) {\n throw new Error(`Failed to parse service information: ${error}`);\n }\n}\n\nexport async function createServiceIntegration(serviceId: string, vendorId: string): Promise<string> {\n let response: Response;\n const baseUrl = 'https://api.pagerduty.com/services';\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n integration: {\n name: 'Backstage',\n service: {\n id: serviceId,\n type: 'service_reference',\n },\n vendor: {\n id: vendorId,\n type: 'vendor_reference',\n }\n }\n }),\n headers: {\n Authorization: `Token token=${process.env.PAGERDUTY_TOKEN}`,\n 'Accept': 'application/vnd.pagerduty+json;version=2',\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(`${baseUrl}/${serviceId}/integrations`, options);\n } catch (error) {\n throw new Error(`Failed to create service: ${error}`);\n }\n\n switch (response.status) {\n case 400:\n throw new Error(`Failed to create service integration. Caller provided invalid arguments.`);\n case 401:\n throw new Error(`Failed to create service integration. Caller did not supply credentials or did not provide the correct credentials.`);\n case 403:\n throw new Error(`Failed to create service integration. Caller is not authorized to view the requested resource.`);\n case 429:\n throw new Error(`Failed to create service integration. Rate limit exceeded.`);\n default: // 201\n break;\n }\n\n let result: PagerDutyCreateIntegrationResponse;\n try {\n result = await response.json();\n\n return result.integration.integration_key;\n\n } catch (error) {\n throw new Error(`Failed to parse service information: ${error}`);\n }\n}\n","import { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { z } from 'zod';\nimport * as api from '../apis/pagerduty';\n\nexport const createPagerDutyServiceAction = () => {\n\n return createTemplateAction<{\n name: string;\n description: string;\n escalationPolicyId: string;\n }>({\n id: 'pagerduty:service:create',\n schema: {\n input: z.object({\n name: z.string().min(1, \"name is required\").describe('Name of the service'),\n description: z.string().min(1, \"description is required\").describe('Description of the service'),\n escalationPolicyId: z.string().min(1, \"Escalation policy is required\").describe('Escalation policy ID'),\n }),\n output: z.object({\n serviceUrl: z.string().describe('PagerDuty Service URL'),\n serviceId: z.string().describe('PagerDuty Service ID'),\n integrationKey: z.string().describe('Backstage Integration Key'),\n }),\n },\n\n async handler(ctx) {\n try {\n // Create service in PagerDuty\n const [serviceId, serviceUrl] = await api.createService(ctx.input.name, ctx.input.description, ctx.input.escalationPolicyId);\n ctx.logger.info(`Service '${ctx.input.name}' created successfully!`);\n\n ctx.output('serviceUrl', serviceUrl);\n ctx.output('serviceId', serviceId);\n\n // Create Backstage Integration in PagerDuty service\n const backstageIntegrationId = 'PRO19CT'; // ID for Backstage integration\n const integrationKey = await api.createServiceIntegration(serviceId, backstageIntegrationId);\n ctx.logger.info(`Backstage Integration for service '${ctx.input.name}' created successfully!`);\n\n ctx.output('integrationKey', integrationKey);\n } catch (error) {\n ctx.logger.error(`${error}`);\n }\n\n }\n });\n};\n"],"names":["Router","express","errorHandler","createTemplateAction","z","api.createService","api.createServiceIntegration"],"mappings":";;;;;;;;;;;;;;;AAWA,eAAsB,aAClB,OACuB,EAAA;AACvB,EAAM,MAAA,EAAE,MAAQ,EAAA,MAAA,EAAW,GAAA,OAAA,CAAA;AAE3B,EAAA,MAAM,SAASA,0BAAO,EAAA,CAAA;AACtB,EAAO,MAAA,CAAA,GAAA,CAAIC,2BAAQ,CAAA,IAAA,EAAM,CAAA,CAAA;AAEzB,EAAA,MAAA,CAAO,GAAI,CAAA,sBAAA,EAAwB,OAAO,CAAA,EAAG,QAAa,KAAA;AACtD,IAAA,MAAA,CAAO,KAAK,6BAA6B,CAAA,CAAA;AAEzC,IAAI,IAAA;AACA,MAAM,MAAA,GAAA,GAAM,MAAM,KAAA,CAAM,iFAAmF,EAAA;AAAA,QACvG,MAAQ,EAAA,KAAA;AAAA,QACR,OAAS,EAAA;AAAA,UACL,QAAU,EAAA,0CAAA;AAAA,UACV,cAAgB,EAAA,kBAAA;AAAA,UAChB,eAAiB,EAAA,CAAA,YAAA,EAAe,MAAO,CAAA,iBAAA,CAAkB,oBAAoB,CAAC,CAAA,CAAA;AAAA,SAClF;AAAA,OACH,CAAA,CAAA;AAED,MAAS,QAAA,CAAA,MAAA,CAAO,IAAI,MAAM,CAAA,CAAA;AAE1B,MAAI,IAAA,GAAA,CAAI,WAAW,GAAK,EAAA;AACpB,QAAA,QAAA,CAAS,IAAK,CAAA,MAAM,GAAI,CAAA,IAAA,EAAM,CAAA,CAAA;AAAA,OAClC;AAAA,aACK,KAAO,EAAA;AACZ,MAAA,MAAA,CAAO,MAAM,KAAK,CAAA,CAAA;AAClB,MAAA,QAAA,CAAS,OAAO,GAAG,CAAA,CAAE,IAAK,CAAA,EAAE,OAAO,CAAA,CAAA;AAAA,KACvC;AAAA,GACH,CAAA,CAAA;AAED,EAAA,MAAA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