@pagerduty/backstage-plugin-common 0.0.3-next.8 → 0.1.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/README.md CHANGED
@@ -18,8 +18,8 @@ The installation of the PagerDuty plugin for Backstage is done with *yarn* as al
18
18
  To install this plugin run the following command from the Backstage root folder.
19
19
 
20
20
  ```bash
21
- yarn add --cwd packages/app @pagerduty/backstage-plugin
22
- yarn add --cwd packages/backend @pagerduty/backstage-plugin
21
+ yarn add --cwd packages/app @pagerduty/backstage-plugin-common
22
+ yarn add --cwd packages/backend @pagerduty/backstage-plugin-common
23
23
  ```
24
24
 
25
25
  ### Configuration
package/dist/index.cjs.js CHANGED
@@ -19,141 +19,7 @@ class HttpError extends Error {
19
19
  const PAGERDUTY_INTEGRATION_KEY = "pagerduty.com/integration-key";
20
20
  const PAGERDUTY_SERVICE_ID = "pagerduty.com/service-id";
21
21
 
22
- let authPersistence;
23
- async function getAuthToken() {
24
- if (authPersistence.authToken !== "" && authPersistence.authToken.includes("Bearer") && authPersistence.authTokenExpiryDate > Date.now() || authPersistence.authToken !== "" && authPersistence.authToken.includes("Token")) {
25
- return authPersistence.authToken;
26
- }
27
- await loadAuthConfig(authPersistence.logger, authPersistence.config);
28
- return authPersistence.authToken;
29
- }
30
- async function loadAuthConfig(logger, config) {
31
- var _a;
32
- try {
33
- authPersistence = {
34
- logger,
35
- config,
36
- authToken: "",
37
- authTokenExpiryDate: Date.now()
38
- };
39
- if (!config.getOptionalString("pagerDuty.apiToken")) {
40
- logger.warn("No PagerDuty API token found in config file. Trying OAuth token instead...");
41
- if (!config.getOptional("pagerDuty.oauth")) {
42
- logger.error("No PagerDuty OAuth configuration found in config file.");
43
- throw new Error("No PagerDuty 'apiToken' or 'oauth' configuration found in config file.");
44
- } else if (!config.getOptionalString("pagerDuty.oauth.clientId") || !config.getOptionalString("pagerDuty.oauth.clientSecret") || !config.getOptionalString("pagerDuty.oauth.subDomain")) {
45
- logger.error("Missing required PagerDuty OAuth parameters in config file. 'clientId', 'clientSecret', and 'subDomain' are required. 'region' is optional.");
46
- throw new Error("Missing required PagerDuty OAuth parameters in config file.");
47
- } else {
48
- authPersistence.authToken = await getOAuthToken(
49
- config.getString("pagerDuty.oauth.clientId"),
50
- config.getString("pagerDuty.oauth.clientSecret"),
51
- config.getString("pagerDuty.oauth.subDomain"),
52
- (_a = config.getOptionalString("pagerDuty.oauth.region")) != null ? _a : "us"
53
- );
54
- logger.info("PagerDuty OAuth configuration loaded successfully.");
55
- }
56
- } else {
57
- authPersistence.authToken = `Token token=${config.getString("pagerDuty.apiToken")}`;
58
- logger.info("PagerDuty API token loaded successfully.");
59
- }
60
- } catch (error) {
61
- logger.error(`Unable to retrieve valid PagerDuty AUTH configuration from config file: ${error}`);
62
- throw error;
63
- }
64
- }
65
- async function getOAuthToken(clientId, clientSecret, subDomain, region) {
66
- if (!clientId || !clientSecret || !subDomain) {
67
- throw new Error("Missing required PagerDuty OAuth parameters.");
68
- }
69
- const scopes = `
70
- abilities.read
71
- addons.read
72
- addons.write
73
- analytics.read
74
- audit_records.read
75
- change_events.read
76
- change_events.write
77
- custom_fields.read
78
- custom_fields.write
79
- escalation_policies.read
80
- escalation_policies.write
81
- event_orchestrations.read
82
- event_orchestrations.write
83
- event_rules.read
84
- event_rules.write
85
- extension_schemas.read
86
- extensions.read
87
- extensions.write
88
- incident_workflows.read
89
- incident_workflows.write
90
- incident_workflows:instances.write
91
- incidents.read
92
- incidents.write
93
- licenses.read
94
- notifications.read
95
- oncalls.read
96
- priorities.read
97
- response_plays.read
98
- response_plays.write
99
- schedules.read
100
- schedules.write
101
- services.read
102
- services.write
103
- standards.read
104
- standards.write
105
- status_dashboards.read
106
- status_pages.read
107
- status_pages.write
108
- subscribers.read
109
- subscribers.write
110
- tags.read
111
- tags.write
112
- teams.read
113
- teams.write
114
- templates.read
115
- templates.write
116
- users.read
117
- users.write
118
- users:contact_methods.read
119
- users:contact_methods.write
120
- users:sessions.read
121
- users:sessions.write
122
- vendors.read
123
- `;
124
- const urlencoded = new URLSearchParams();
125
- urlencoded.append("grant_type", "client_credentials");
126
- urlencoded.append("client_id", clientId);
127
- urlencoded.append("client_secret", clientSecret);
128
- urlencoded.append("scope", `as_account-${region}.${subDomain} ${scopes}`);
129
- let response;
130
- const options = {
131
- method: "POST",
132
- headers: {
133
- "Content-Type": "application/x-www-form-urlencoded"
134
- },
135
- body: urlencoded
136
- };
137
- const baseUrl = "https://identity.pagerduty.com/oauth/token";
138
- try {
139
- response = await fetch(baseUrl, options);
140
- } catch (error) {
141
- throw new Error(`Failed to retrieve oauth token: ${error}`);
142
- }
143
- switch (response.status) {
144
- case 400:
145
- throw new HttpError("Failed to retrieve valid token. Bad Request - Invalid arguments provided.", 400);
146
- case 401:
147
- throw new HttpError("Failed to retrieve valid token. Forbidden - Invalid credentials provided.", 401);
148
- }
149
- const authResponse = await response.json();
150
- authPersistence.authTokenExpiryDate = Date.now() + authResponse.expires_in * 1e3;
151
- return `Bearer ${authResponse.access_token}`;
152
- }
153
-
154
22
  exports.HttpError = HttpError;
155
23
  exports.PAGERDUTY_INTEGRATION_KEY = PAGERDUTY_INTEGRATION_KEY;
156
24
  exports.PAGERDUTY_SERVICE_ID = PAGERDUTY_SERVICE_ID;
157
- exports.getAuthToken = getAuthToken;
158
- exports.loadAuthConfig = loadAuthConfig;
159
25
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/types.ts","../src/constants.ts","../src/auth/auth.ts"],"sourcesContent":["/** @public */\nexport type PagerDutyIncident = {\n id: string;\n title: string;\n status: string;\n html_url: string;\n assignments: [\n {\n assignee: PagerDutyUser;\n },\n ];\n service: PagerDutyService;\n created_at: string;\n}\n\n/** @public */\nexport type PagerDutyUser = {\n id: string;\n summary: string;\n email: string;\n html_url: string;\n name: string;\n avatar_url: string;\n};\n\n/** @public */\nexport type PagerDutyChangeEvent = {\n id: string;\n integration: PagerDutyIntegration[];\n source: string;\n html_url?: string;\n links: [\n {\n href: string;\n text: string;\n },\n ];\n summary: string;\n timestamp: string;\n}\n\n/** @public */\nexport type PagerDutyService = {\n id: string;\n name: string;\n description?: string;\n escalation_policy: PagerDutyEscalationPolicy; \n alert_creation?: string;\n incident_urgency_rule?: PagerDutyIncidentUrgencyRule;\n integrations?: PagerDutyIntegration[];\n teams?: PagerDutyTeam[];\n status?: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url: string;\n}\n\n/** @public */\nexport type PagerDutyEscalationPolicy = {\n id: string;\n name: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyIncidentUrgencyRule = {\n type: string;\n urgency: string;\n}\n\n/** @public */\nexport type PagerDutyIntegration = {\n id: string;\n type: string;\n summary?: string;\n self?: string;\n html_url?: string;\n name?: string;\n service?: PagerDutyService;\n created_at?: string;\n vendor?: PagerDutyVendor;\n integration_key?: string;\n}\n\n/** @public */\nexport type PagerDutyTeam = {\n id: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyOnCall = {\n user: PagerDutyUser;\n escalation_level: number;\n}\n\n/** @public */\nexport type PagerDutyOnCallUsersResponse = {\n users: PagerDutyUser[];\n}\n\n/** @public */\nexport type PagerDutyVendor = {\n id: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyServicesResponse = {\n services: PagerDutyService[];\n};\n\n/** @public */\nexport type PagerDutyServiceResponse = {\n service: PagerDutyService;\n};\n\n/** @public */\nexport type PagerDutyIncidentsResponse = {\n incidents: PagerDutyIncident[];\n};\n\n/** @public */\nexport type PagerDutyChangeEventsResponse = {\n change_events: PagerDutyChangeEvent[];\n};\n\n/** @public */\nexport type PagerDutyOnCallsResponse = {\n oncalls: PagerDutyOnCall[];\n};\n\n/** @public */\nexport type PagerDutyIntegrationResponse = {\n integration: PagerDutyIntegration;\n}\n\n/** @public */\nexport type PagerDutyEscalationPoliciesResponse = {\n escalation_policies: PagerDutyEscalationPolicy[];\n limit?: number;\n offset?: number;\n more?: boolean;\n total?: number;\n};\n\n/** @public */\nexport type PagerDutyAbilitiesResponse = {\n abilities: string[];\n};\n\n/** @public */\nexport class HttpError extends Error {\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n }\n\n status: number;\n}\n\n/** @public */\nexport type PagerDutyOAuthConfig = {\n clientId: string;\n clientSecret: string;\n region?: string;\n subDomain: string;\n}\n","/** @public */\nexport const PAGERDUTY_INTEGRATION_KEY = 'pagerduty.com/integration-key';\n\n/** @public */\nexport const PAGERDUTY_SERVICE_ID = 'pagerduty.com/service-id';","import { Logger } from \"winston\";\nimport { Config } from \"@backstage/config\";\nimport { HttpError } from \"../types\";\n\ntype Auth = {\n logger: Logger;\n config: Config;\n authToken: string;\n authTokenExpiryDate: number;\n}\n\nlet authPersistence: Auth;\n\nexport async function getAuthToken(): Promise<string> {\n // check if token already exists and is valid\n if (\n (authPersistence.authToken !== '' &&\n authPersistence.authToken.includes('Bearer') &&\n authPersistence.authTokenExpiryDate > Date.now()) // case where OAuth token is still valid\n ||\n (authPersistence.authToken !== '' &&\n authPersistence.authToken.includes('Token'))) { // case where API token is used\n return authPersistence.authToken;\n }\n\n await loadAuthConfig(authPersistence.logger, authPersistence.config);\n return authPersistence.authToken;\n}\n\nexport async function loadAuthConfig(logger: Logger, config: Config) {\n try {\n // initiliaze the authPersistence in-memory object\n authPersistence = {\n logger: logger,\n config: config,\n authToken: '',\n authTokenExpiryDate: Date.now()\n };\n\n if (!config.getOptionalString('pagerDuty.apiToken')) {\n logger.warn('No PagerDuty API token found in config file. Trying OAuth token instead...');\n\n if (!config.getOptional('pagerDuty.oauth')) {\n \n logger.error('No PagerDuty OAuth configuration found in config file.');\n throw new Error(\"No PagerDuty 'apiToken' or 'oauth' configuration found in config file.\");\n\n } else if (!config.getOptionalString('pagerDuty.oauth.clientId') || !config.getOptionalString('pagerDuty.oauth.clientSecret') || !config.getOptionalString('pagerDuty.oauth.subDomain')) {\n \n logger.error(\"Missing required PagerDuty OAuth parameters in config file. 'clientId', 'clientSecret', and 'subDomain' are required. 'region' is optional.\");\n throw new Error('Missing required PagerDuty OAuth parameters in config file.');\n\n } else {\n\n authPersistence.authToken = await getOAuthToken(\n config.getString('pagerDuty.oauth.clientId'),\n config.getString('pagerDuty.oauth.clientSecret'),\n config.getString('pagerDuty.oauth.subDomain'),\n config.getOptionalString('pagerDuty.oauth.region') ?? 'us');\n\n logger.info('PagerDuty OAuth configuration loaded successfully.');\n }\n } else {\n authPersistence.authToken = `Token token=${config.getString('pagerDuty.apiToken')}`;\n\n logger.info('PagerDuty API token loaded successfully.');\n }\n }\n catch (error) {\n logger.error(`Unable to retrieve valid PagerDuty AUTH configuration from config file: ${error}`);\n throw error;\n }\n}\n\nasync function getOAuthToken(clientId: string, clientSecret: string, subDomain: string, region: string): Promise<string> {\n // check if required parameters are provided\n if (!clientId || !clientSecret || !subDomain) {\n throw new Error('Missing required PagerDuty OAuth parameters.');\n }\n\n // define the scopes required for the OAuth token\n // const scopes = `\n // abilities.read \n // change_events.read \n // escalation_policies.read \n // incidents.read \n // oncalls.read \n // priorities.read \n // schedules.read \n // services.read\n // services.write \n // teams.read \n // users.read \n // users:contact_methods.read \n // vendors.read\n // `;\n\n const scopes = `\n abilities.read \n addons.read \n addons.write \n analytics.read \n audit_records.read \n change_events.read \n change_events.write \n custom_fields.read \n custom_fields.write \n escalation_policies.read \n escalation_policies.write \n event_orchestrations.read \n event_orchestrations.write \n event_rules.read \n event_rules.write \n extension_schemas.read \n extensions.read \n extensions.write \n incident_workflows.read \n incident_workflows.write \n incident_workflows:instances.write \n incidents.read \n incidents.write \n licenses.read \n notifications.read \n oncalls.read \n priorities.read \n response_plays.read \n response_plays.write \n schedules.read \n schedules.write \n services.read \n services.write \n standards.read \n standards.write \n status_dashboards.read \n status_pages.read \n status_pages.write \n subscribers.read \n subscribers.write \n tags.read \n tags.write \n teams.read \n teams.write \n templates.read \n templates.write \n users.read \n users.write \n users:contact_methods.read \n users:contact_methods.write \n users:sessions.read \n users:sessions.write \n vendors.read\n `;\n\n // encode the parameters for the request\n const urlencoded = new URLSearchParams();\n urlencoded.append(\"grant_type\", \"client_credentials\");\n urlencoded.append(\"client_id\", clientId);\n urlencoded.append(\"client_secret\", clientSecret);\n urlencoded.append(\"scope\", `as_account-${region}.${subDomain} ${scopes}`);\n\n let response: Response;\n const options: RequestInit = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: urlencoded,\n };\n const baseUrl = 'https://identity.pagerduty.com/oauth/token';\n\n try {\n response = await fetch(baseUrl, options);\n } catch (error) {\n throw new Error(`Failed to retrieve oauth token: ${error}`);\n }\n\n switch (response.status) {\n case 400:\n throw new HttpError(\"Failed to retrieve valid token. Bad Request - Invalid arguments provided.\", 400);\n case 401:\n throw new HttpError(\"Failed to retrieve valid token. Forbidden - Invalid credentials provided.\", 401);\n default: // 200\n break;\n }\n\n const authResponse = await response.json();\n authPersistence.authTokenExpiryDate = Date.now() + (authResponse.expires_in * 1000);\n return `Bearer ${authResponse.access_token}`;\n}"],"names":[],"mappings":";;;;;;;;;;AAkKO,MAAM,kBAAkB,KAAM,CAAA;AAAA,EACjC,WAAA,CAAY,SAAiB,MAAgB,EAAA;AACzC,IAAA,KAAA,CAAM,OAAO,CAAA,CAAA;AAIjB,IAAA,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAHI,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA,CAAA;AAAA,GAClB;AAGJ;;ACxKO,MAAM,yBAA4B,GAAA,gCAAA;AAGlC,MAAM,oBAAuB,GAAA;;ACOpC,IAAI,eAAA,CAAA;AAEJ,eAAsB,YAAgC,GAAA;AAElD,EACK,IAAA,eAAA,CAAgB,cAAc,EAC3B,IAAA,eAAA,CAAgB,UAAU,QAAS,CAAA,QAAQ,KAC3C,eAAg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Aa,UAAa,GAAA,GAAA,CAAA;AAC9E,EAAO,OAAA,CAAA,OAAA,EAAU,aAAa,YAAY,CAAA,CAAA,CAAA;AAC9C;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/types.ts","../src/constants.ts"],"sourcesContent":["/** @public */\nexport type PagerDutyIncident = {\n id: string;\n title: string;\n status: string;\n html_url: string;\n assignments: [\n {\n assignee: PagerDutyUser;\n },\n ];\n service: PagerDutyService;\n created_at: string;\n}\n\n/** @public */\nexport type PagerDutyUser = {\n id: string;\n summary: string;\n email: string;\n html_url: string;\n name: string;\n avatar_url: string;\n};\n\n/** @public */\nexport type PagerDutyChangeEvent = {\n id: string;\n integration: PagerDutyIntegration[];\n source: string;\n html_url?: string;\n links: [\n {\n href: string;\n text: string;\n },\n ];\n summary: string;\n timestamp: string;\n}\n\n/** @public */\nexport type PagerDutyService = {\n id: string;\n name: string;\n description?: string;\n escalation_policy: PagerDutyEscalationPolicy; \n alert_creation?: string;\n incident_urgency_rule?: PagerDutyIncidentUrgencyRule;\n integrations?: PagerDutyIntegration[];\n teams?: PagerDutyTeam[];\n status?: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url: string;\n}\n\n/** @public */\nexport type PagerDutyEscalationPolicy = {\n id: string;\n name: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyIncidentUrgencyRule = {\n type: string;\n urgency: string;\n}\n\n/** @public */\nexport type PagerDutyIntegration = {\n id: string;\n type: string;\n summary?: string;\n self?: string;\n html_url?: string;\n name?: string;\n service?: PagerDutyService;\n created_at?: string;\n vendor?: PagerDutyVendor;\n integration_key?: string;\n}\n\n/** @public */\nexport type PagerDutyTeam = {\n id: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyOnCall = {\n user: PagerDutyUser;\n escalation_level: number;\n}\n\n/** @public */\nexport type PagerDutyOnCallUsersResponse = {\n users: PagerDutyUser[];\n}\n\n/** @public */\nexport type PagerDutyVendor = {\n id: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyServicesResponse = {\n services: PagerDutyService[];\n};\n\n/** @public */\nexport type PagerDutyServiceResponse = {\n service: PagerDutyService;\n};\n\n/** @public */\nexport type PagerDutyIncidentsResponse = {\n incidents: PagerDutyIncident[];\n};\n\n/** @public */\nexport type PagerDutyChangeEventsResponse = {\n change_events: PagerDutyChangeEvent[];\n};\n\n/** @public */\nexport type PagerDutyOnCallsResponse = {\n oncalls: PagerDutyOnCall[];\n};\n\n/** @public */\nexport type PagerDutyIntegrationResponse = {\n integration: PagerDutyIntegration;\n}\n\n/** @public */\nexport type PagerDutyEscalationPoliciesResponse = {\n escalation_policies: PagerDutyEscalationPolicy[];\n limit?: number;\n offset?: number;\n more?: boolean;\n total?: number;\n};\n\n/** @public */\nexport type PagerDutyAbilitiesResponse = {\n abilities: string[];\n};\n\n/** @public */\nexport class HttpError extends Error {\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n }\n\n status: number;\n}\n\n/** @public */\nexport type PagerDutyOAuthConfig = {\n clientId: string;\n clientSecret: string;\n region?: string;\n subDomain: string;\n}\n","/** @public */\nexport const PAGERDUTY_INTEGRATION_KEY = 'pagerduty.com/integration-key';\n\n/** @public */\nexport const PAGERDUTY_SERVICE_ID = 'pagerduty.com/service-id';"],"names":[],"mappings":";;;;;;;;;;AAkKO,MAAM,kBAAkB,KAAM,CAAA;AAAA,EACjC,WAAA,CAAY,SAAiB,MAAgB,EAAA;AACzC,IAAA,KAAA,CAAM,OAAO,CAAA,CAAA;AAIjB,IAAA,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAHI,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA,CAAA;AAAA,GAClB;AAGJ;;ACxKO,MAAM,yBAA4B,GAAA,gCAAA;AAGlC,MAAM,oBAAuB,GAAA;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { Logger } from 'winston';
2
- import { Config } from '@backstage/config';
3
-
4
1
  /** @public */
5
2
  type PagerDutyIncident = {
6
3
  id: string;
@@ -161,7 +158,4 @@ declare const PAGERDUTY_INTEGRATION_KEY = "pagerduty.com/integration-key";
161
158
  /** @public */
162
159
  declare const PAGERDUTY_SERVICE_ID = "pagerduty.com/service-id";
163
160
 
164
- declare function getAuthToken(): Promise<string>;
165
- declare function loadAuthConfig(logger: Logger, config: Config): Promise<void>;
166
-
167
- export { HttpError, PAGERDUTY_INTEGRATION_KEY, PAGERDUTY_SERVICE_ID, PagerDutyAbilitiesResponse, PagerDutyChangeEvent, PagerDutyChangeEventsResponse, PagerDutyEscalationPoliciesResponse, PagerDutyEscalationPolicy, PagerDutyIncident, PagerDutyIncidentUrgencyRule, PagerDutyIncidentsResponse, PagerDutyIntegration, PagerDutyIntegrationResponse, PagerDutyOAuthConfig, PagerDutyOnCall, PagerDutyOnCallUsersResponse, PagerDutyOnCallsResponse, PagerDutyService, PagerDutyServiceResponse, PagerDutyServicesResponse, PagerDutyTeam, PagerDutyUser, PagerDutyVendor, getAuthToken, loadAuthConfig };
161
+ export { HttpError, PAGERDUTY_INTEGRATION_KEY, PAGERDUTY_SERVICE_ID, PagerDutyAbilitiesResponse, PagerDutyChangeEvent, PagerDutyChangeEventsResponse, PagerDutyEscalationPoliciesResponse, PagerDutyEscalationPolicy, PagerDutyIncident, PagerDutyIncidentUrgencyRule, PagerDutyIncidentsResponse, PagerDutyIntegration, PagerDutyIntegrationResponse, PagerDutyOAuthConfig, PagerDutyOnCall, PagerDutyOnCallUsersResponse, PagerDutyOnCallsResponse, PagerDutyService, PagerDutyServiceResponse, PagerDutyServicesResponse, PagerDutyTeam, PagerDutyUser, PagerDutyVendor };
package/dist/index.esm.js CHANGED
@@ -15,137 +15,5 @@ class HttpError extends Error {
15
15
  const PAGERDUTY_INTEGRATION_KEY = "pagerduty.com/integration-key";
16
16
  const PAGERDUTY_SERVICE_ID = "pagerduty.com/service-id";
17
17
 
18
- let authPersistence;
19
- async function getAuthToken() {
20
- if (authPersistence.authToken !== "" && authPersistence.authToken.includes("Bearer") && authPersistence.authTokenExpiryDate > Date.now() || authPersistence.authToken !== "" && authPersistence.authToken.includes("Token")) {
21
- return authPersistence.authToken;
22
- }
23
- await loadAuthConfig(authPersistence.logger, authPersistence.config);
24
- return authPersistence.authToken;
25
- }
26
- async function loadAuthConfig(logger, config) {
27
- var _a;
28
- try {
29
- authPersistence = {
30
- logger,
31
- config,
32
- authToken: "",
33
- authTokenExpiryDate: Date.now()
34
- };
35
- if (!config.getOptionalString("pagerDuty.apiToken")) {
36
- logger.warn("No PagerDuty API token found in config file. Trying OAuth token instead...");
37
- if (!config.getOptional("pagerDuty.oauth")) {
38
- logger.error("No PagerDuty OAuth configuration found in config file.");
39
- throw new Error("No PagerDuty 'apiToken' or 'oauth' configuration found in config file.");
40
- } else if (!config.getOptionalString("pagerDuty.oauth.clientId") || !config.getOptionalString("pagerDuty.oauth.clientSecret") || !config.getOptionalString("pagerDuty.oauth.subDomain")) {
41
- logger.error("Missing required PagerDuty OAuth parameters in config file. 'clientId', 'clientSecret', and 'subDomain' are required. 'region' is optional.");
42
- throw new Error("Missing required PagerDuty OAuth parameters in config file.");
43
- } else {
44
- authPersistence.authToken = await getOAuthToken(
45
- config.getString("pagerDuty.oauth.clientId"),
46
- config.getString("pagerDuty.oauth.clientSecret"),
47
- config.getString("pagerDuty.oauth.subDomain"),
48
- (_a = config.getOptionalString("pagerDuty.oauth.region")) != null ? _a : "us"
49
- );
50
- logger.info("PagerDuty OAuth configuration loaded successfully.");
51
- }
52
- } else {
53
- authPersistence.authToken = `Token token=${config.getString("pagerDuty.apiToken")}`;
54
- logger.info("PagerDuty API token loaded successfully.");
55
- }
56
- } catch (error) {
57
- logger.error(`Unable to retrieve valid PagerDuty AUTH configuration from config file: ${error}`);
58
- throw error;
59
- }
60
- }
61
- async function getOAuthToken(clientId, clientSecret, subDomain, region) {
62
- if (!clientId || !clientSecret || !subDomain) {
63
- throw new Error("Missing required PagerDuty OAuth parameters.");
64
- }
65
- const scopes = `
66
- abilities.read
67
- addons.read
68
- addons.write
69
- analytics.read
70
- audit_records.read
71
- change_events.read
72
- change_events.write
73
- custom_fields.read
74
- custom_fields.write
75
- escalation_policies.read
76
- escalation_policies.write
77
- event_orchestrations.read
78
- event_orchestrations.write
79
- event_rules.read
80
- event_rules.write
81
- extension_schemas.read
82
- extensions.read
83
- extensions.write
84
- incident_workflows.read
85
- incident_workflows.write
86
- incident_workflows:instances.write
87
- incidents.read
88
- incidents.write
89
- licenses.read
90
- notifications.read
91
- oncalls.read
92
- priorities.read
93
- response_plays.read
94
- response_plays.write
95
- schedules.read
96
- schedules.write
97
- services.read
98
- services.write
99
- standards.read
100
- standards.write
101
- status_dashboards.read
102
- status_pages.read
103
- status_pages.write
104
- subscribers.read
105
- subscribers.write
106
- tags.read
107
- tags.write
108
- teams.read
109
- teams.write
110
- templates.read
111
- templates.write
112
- users.read
113
- users.write
114
- users:contact_methods.read
115
- users:contact_methods.write
116
- users:sessions.read
117
- users:sessions.write
118
- vendors.read
119
- `;
120
- const urlencoded = new URLSearchParams();
121
- urlencoded.append("grant_type", "client_credentials");
122
- urlencoded.append("client_id", clientId);
123
- urlencoded.append("client_secret", clientSecret);
124
- urlencoded.append("scope", `as_account-${region}.${subDomain} ${scopes}`);
125
- let response;
126
- const options = {
127
- method: "POST",
128
- headers: {
129
- "Content-Type": "application/x-www-form-urlencoded"
130
- },
131
- body: urlencoded
132
- };
133
- const baseUrl = "https://identity.pagerduty.com/oauth/token";
134
- try {
135
- response = await fetch(baseUrl, options);
136
- } catch (error) {
137
- throw new Error(`Failed to retrieve oauth token: ${error}`);
138
- }
139
- switch (response.status) {
140
- case 400:
141
- throw new HttpError("Failed to retrieve valid token. Bad Request - Invalid arguments provided.", 400);
142
- case 401:
143
- throw new HttpError("Failed to retrieve valid token. Forbidden - Invalid credentials provided.", 401);
144
- }
145
- const authResponse = await response.json();
146
- authPersistence.authTokenExpiryDate = Date.now() + authResponse.expires_in * 1e3;
147
- return `Bearer ${authResponse.access_token}`;
148
- }
149
-
150
- export { HttpError, PAGERDUTY_INTEGRATION_KEY, PAGERDUTY_SERVICE_ID, getAuthToken, loadAuthConfig };
18
+ export { HttpError, PAGERDUTY_INTEGRATION_KEY, PAGERDUTY_SERVICE_ID };
151
19
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/types.ts","../src/constants.ts","../src/auth/auth.ts"],"sourcesContent":["/** @public */\nexport type PagerDutyIncident = {\n id: string;\n title: string;\n status: string;\n html_url: string;\n assignments: [\n {\n assignee: PagerDutyUser;\n },\n ];\n service: PagerDutyService;\n created_at: string;\n}\n\n/** @public */\nexport type PagerDutyUser = {\n id: string;\n summary: string;\n email: string;\n html_url: string;\n name: string;\n avatar_url: string;\n};\n\n/** @public */\nexport type PagerDutyChangeEvent = {\n id: string;\n integration: PagerDutyIntegration[];\n source: string;\n html_url?: string;\n links: [\n {\n href: string;\n text: string;\n },\n ];\n summary: string;\n timestamp: string;\n}\n\n/** @public */\nexport type PagerDutyService = {\n id: string;\n name: string;\n description?: string;\n escalation_policy: PagerDutyEscalationPolicy; \n alert_creation?: string;\n incident_urgency_rule?: PagerDutyIncidentUrgencyRule;\n integrations?: PagerDutyIntegration[];\n teams?: PagerDutyTeam[];\n status?: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url: string;\n}\n\n/** @public */\nexport type PagerDutyEscalationPolicy = {\n id: string;\n name: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyIncidentUrgencyRule = {\n type: string;\n urgency: string;\n}\n\n/** @public */\nexport type PagerDutyIntegration = {\n id: string;\n type: string;\n summary?: string;\n self?: string;\n html_url?: string;\n name?: string;\n service?: PagerDutyService;\n created_at?: string;\n vendor?: PagerDutyVendor;\n integration_key?: string;\n}\n\n/** @public */\nexport type PagerDutyTeam = {\n id: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyOnCall = {\n user: PagerDutyUser;\n escalation_level: number;\n}\n\n/** @public */\nexport type PagerDutyOnCallUsersResponse = {\n users: PagerDutyUser[];\n}\n\n/** @public */\nexport type PagerDutyVendor = {\n id: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyServicesResponse = {\n services: PagerDutyService[];\n};\n\n/** @public */\nexport type PagerDutyServiceResponse = {\n service: PagerDutyService;\n};\n\n/** @public */\nexport type PagerDutyIncidentsResponse = {\n incidents: PagerDutyIncident[];\n};\n\n/** @public */\nexport type PagerDutyChangeEventsResponse = {\n change_events: PagerDutyChangeEvent[];\n};\n\n/** @public */\nexport type PagerDutyOnCallsResponse = {\n oncalls: PagerDutyOnCall[];\n};\n\n/** @public */\nexport type PagerDutyIntegrationResponse = {\n integration: PagerDutyIntegration;\n}\n\n/** @public */\nexport type PagerDutyEscalationPoliciesResponse = {\n escalation_policies: PagerDutyEscalationPolicy[];\n limit?: number;\n offset?: number;\n more?: boolean;\n total?: number;\n};\n\n/** @public */\nexport type PagerDutyAbilitiesResponse = {\n abilities: string[];\n};\n\n/** @public */\nexport class HttpError extends Error {\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n }\n\n status: number;\n}\n\n/** @public */\nexport type PagerDutyOAuthConfig = {\n clientId: string;\n clientSecret: string;\n region?: string;\n subDomain: string;\n}\n","/** @public */\nexport const PAGERDUTY_INTEGRATION_KEY = 'pagerduty.com/integration-key';\n\n/** @public */\nexport const PAGERDUTY_SERVICE_ID = 'pagerduty.com/service-id';","import { Logger } from \"winston\";\nimport { Config } from \"@backstage/config\";\nimport { HttpError } from \"../types\";\n\ntype Auth = {\n logger: Logger;\n config: Config;\n authToken: string;\n authTokenExpiryDate: number;\n}\n\nlet authPersistence: Auth;\n\nexport async function getAuthToken(): Promise<string> {\n // check if token already exists and is valid\n if (\n (authPersistence.authToken !== '' &&\n authPersistence.authToken.includes('Bearer') &&\n authPersistence.authTokenExpiryDate > Date.now()) // case where OAuth token is still valid\n ||\n (authPersistence.authToken !== '' &&\n authPersistence.authToken.includes('Token'))) { // case where API token is used\n return authPersistence.authToken;\n }\n\n await loadAuthConfig(authPersistence.logger, authPersistence.config);\n return authPersistence.authToken;\n}\n\nexport async function loadAuthConfig(logger: Logger, config: Config) {\n try {\n // initiliaze the authPersistence in-memory object\n authPersistence = {\n logger: logger,\n config: config,\n authToken: '',\n authTokenExpiryDate: Date.now()\n };\n\n if (!config.getOptionalString('pagerDuty.apiToken')) {\n logger.warn('No PagerDuty API token found in config file. Trying OAuth token instead...');\n\n if (!config.getOptional('pagerDuty.oauth')) {\n \n logger.error('No PagerDuty OAuth configuration found in config file.');\n throw new Error(\"No PagerDuty 'apiToken' or 'oauth' configuration found in config file.\");\n\n } else if (!config.getOptionalString('pagerDuty.oauth.clientId') || !config.getOptionalString('pagerDuty.oauth.clientSecret') || !config.getOptionalString('pagerDuty.oauth.subDomain')) {\n \n logger.error(\"Missing required PagerDuty OAuth parameters in config file. 'clientId', 'clientSecret', and 'subDomain' are required. 'region' is optional.\");\n throw new Error('Missing required PagerDuty OAuth parameters in config file.');\n\n } else {\n\n authPersistence.authToken = await getOAuthToken(\n config.getString('pagerDuty.oauth.clientId'),\n config.getString('pagerDuty.oauth.clientSecret'),\n config.getString('pagerDuty.oauth.subDomain'),\n config.getOptionalString('pagerDuty.oauth.region') ?? 'us');\n\n logger.info('PagerDuty OAuth configuration loaded successfully.');\n }\n } else {\n authPersistence.authToken = `Token token=${config.getString('pagerDuty.apiToken')}`;\n\n logger.info('PagerDuty API token loaded successfully.');\n }\n }\n catch (error) {\n logger.error(`Unable to retrieve valid PagerDuty AUTH configuration from config file: ${error}`);\n throw error;\n }\n}\n\nasync function getOAuthToken(clientId: string, clientSecret: string, subDomain: string, region: string): Promise<string> {\n // check if required parameters are provided\n if (!clientId || !clientSecret || !subDomain) {\n throw new Error('Missing required PagerDuty OAuth parameters.');\n }\n\n // define the scopes required for the OAuth token\n // const scopes = `\n // abilities.read \n // change_events.read \n // escalation_policies.read \n // incidents.read \n // oncalls.read \n // priorities.read \n // schedules.read \n // services.read\n // services.write \n // teams.read \n // users.read \n // users:contact_methods.read \n // vendors.read\n // `;\n\n const scopes = `\n abilities.read \n addons.read \n addons.write \n analytics.read \n audit_records.read \n change_events.read \n change_events.write \n custom_fields.read \n custom_fields.write \n escalation_policies.read \n escalation_policies.write \n event_orchestrations.read \n event_orchestrations.write \n event_rules.read \n event_rules.write \n extension_schemas.read \n extensions.read \n extensions.write \n incident_workflows.read \n incident_workflows.write \n incident_workflows:instances.write \n incidents.read \n incidents.write \n licenses.read \n notifications.read \n oncalls.read \n priorities.read \n response_plays.read \n response_plays.write \n schedules.read \n schedules.write \n services.read \n services.write \n standards.read \n standards.write \n status_dashboards.read \n status_pages.read \n status_pages.write \n subscribers.read \n subscribers.write \n tags.read \n tags.write \n teams.read \n teams.write \n templates.read \n templates.write \n users.read \n users.write \n users:contact_methods.read \n users:contact_methods.write \n users:sessions.read \n users:sessions.write \n vendors.read\n `;\n\n // encode the parameters for the request\n const urlencoded = new URLSearchParams();\n urlencoded.append(\"grant_type\", \"client_credentials\");\n urlencoded.append(\"client_id\", clientId);\n urlencoded.append(\"client_secret\", clientSecret);\n urlencoded.append(\"scope\", `as_account-${region}.${subDomain} ${scopes}`);\n\n let response: Response;\n const options: RequestInit = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: urlencoded,\n };\n const baseUrl = 'https://identity.pagerduty.com/oauth/token';\n\n try {\n response = await fetch(baseUrl, options);\n } catch (error) {\n throw new Error(`Failed to retrieve oauth token: ${error}`);\n }\n\n switch (response.status) {\n case 400:\n throw new HttpError(\"Failed to retrieve valid token. Bad Request - Invalid arguments provided.\", 400);\n case 401:\n throw new HttpError(\"Failed to retrieve valid token. Forbidden - Invalid credentials provided.\", 401);\n default: // 200\n break;\n }\n\n const authResponse = await response.json();\n authPersistence.authTokenExpiryDate = Date.now() + (authResponse.expires_in * 1000);\n return `Bearer ${authResponse.access_token}`;\n}"],"names":[],"mappings":";;;;;;AAkKO,MAAM,kBAAkB,KAAM,CAAA;AAAA,EACjC,WAAA,CAAY,SAAiB,MAAgB,EAAA;AACzC,IAAA,KAAA,CAAM,OAAO,CAAA,CAAA;AAIjB,IAAA,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAHI,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA,CAAA;AAAA,GAClB;AAGJ;;ACxKO,MAAM,yBAA4B,GAAA,gCAAA;AAGlC,MAAM,oBAAuB,GAAA;;ACOpC,IAAI,eAAA,CAAA;AAEJ,eAAsB,YAAgC,GAAA;AAElD,EACK,IAAA,eAAA,CAAgB,cAAc,EAC3B,IAAA,eAAA,CAAgB,UAAU,QAAS,CAAA,QAAQ,KAC3C,eAAgB,CAAA,mBAAA,GAAsB,KAAK,GAAI,EAAA,IAElD,gBAAgB,SAAc,KAAA,EAAA,IAC3B,gBAAgB,SAAU,CAAA,QAAA,CAAS,OAAO,CAAI,EAAA;AAClD,IAAA,OAAO,eAAgB,CAAA,SAAA,CAAA;AAAA,GAC3B;AAEA,EAAA,MAAM,cAAe,CAAA,eAAA,CAAgB,MAAQ,EAAA,eAAA,CAAgB,MAAM,CAAA,CAAA;AACnE,EAAA,OAAO,eAAgB,CAAA,SAAA,CAAA;AAC3B,CAAA;AAEsB,eAAA,cAAA,CAAe,QAAgB,MAAgB,EAAA;AA7BrE,EAAA,IAAA,EAAA,CAAA;AA8BI,EAAI,IAAA;AAEA,IAAkB,eAAA,GAAA;AAAA,MACd,MAAA;AAAA,MACA,MAAA;AAAA,MACA,SAAW,EAAA,EAAA;AAAA,MACX,mBAAA,EAAqB,KAAK,GAAI,EAAA;AAAA,KAClC,CAAA;AAEA,IAAA,IAAI,CAAC,MAAA,CAA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A,EAAA,MAAM,OAAU,GAAA,4CAAA,CAAA;AAEhB,EAAI,IAAA;AACA,IAAW,QAAA,GAAA,MAAM,KAAM,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;AAAA,WAClC,KAAO,EAAA;AACZ,IAAA,MAAM,IAAI,KAAA,CAAM,CAAmC,gCAAA,EAAA,KAAK,CAAE,CAAA,CAAA,CAAA;AAAA,GAC9D;AAEA,EAAA,QAAQ,SAAS,MAAQ;AAAA,IACrB,KAAK,GAAA;AACD,MAAM,MAAA,IAAI,SAAU,CAAA,2EAAA,EAA6E,GAAG,CAAA,CAAA;AAAA,IACxG,KAAK,GAAA;AACD,MAAM,MAAA,IAAI,SAAU,CAAA,2EAAA,EAA6E,GAAG,CAAA,CAAA;AAEpG,GACR;AAEA,EAAM,MAAA,YAAA,GAAe,MAAM,QAAA,CAAS,IAAK,EAAA,CAAA;AACzC,EAAA,eAAA,CAAgB,mBAAsB,GAAA,IAAA,CAAK,GAAI,EAAA,GAAK,aAAa,UAAa,GAAA,GAAA,CAAA;AAC9E,EAAO,OAAA,CAAA,OAAA,EAAU,aAAa,YAAY,CAAA,CAAA,CAAA;AAC9C;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/types.ts","../src/constants.ts"],"sourcesContent":["/** @public */\nexport type PagerDutyIncident = {\n id: string;\n title: string;\n status: string;\n html_url: string;\n assignments: [\n {\n assignee: PagerDutyUser;\n },\n ];\n service: PagerDutyService;\n created_at: string;\n}\n\n/** @public */\nexport type PagerDutyUser = {\n id: string;\n summary: string;\n email: string;\n html_url: string;\n name: string;\n avatar_url: string;\n};\n\n/** @public */\nexport type PagerDutyChangeEvent = {\n id: string;\n integration: PagerDutyIntegration[];\n source: string;\n html_url?: string;\n links: [\n {\n href: string;\n text: string;\n },\n ];\n summary: string;\n timestamp: string;\n}\n\n/** @public */\nexport type PagerDutyService = {\n id: string;\n name: string;\n description?: string;\n escalation_policy: PagerDutyEscalationPolicy; \n alert_creation?: string;\n incident_urgency_rule?: PagerDutyIncidentUrgencyRule;\n integrations?: PagerDutyIntegration[];\n teams?: PagerDutyTeam[];\n status?: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url: string;\n}\n\n/** @public */\nexport type PagerDutyEscalationPolicy = {\n id: string;\n name: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyIncidentUrgencyRule = {\n type: string;\n urgency: string;\n}\n\n/** @public */\nexport type PagerDutyIntegration = {\n id: string;\n type: string;\n summary?: string;\n self?: string;\n html_url?: string;\n name?: string;\n service?: PagerDutyService;\n created_at?: string;\n vendor?: PagerDutyVendor;\n integration_key?: string;\n}\n\n/** @public */\nexport type PagerDutyTeam = {\n id: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyOnCall = {\n user: PagerDutyUser;\n escalation_level: number;\n}\n\n/** @public */\nexport type PagerDutyOnCallUsersResponse = {\n users: PagerDutyUser[];\n}\n\n/** @public */\nexport type PagerDutyVendor = {\n id: string;\n type?: string;\n summary?: string;\n self?: string;\n html_url?: string;\n}\n\n/** @public */\nexport type PagerDutyServicesResponse = {\n services: PagerDutyService[];\n};\n\n/** @public */\nexport type PagerDutyServiceResponse = {\n service: PagerDutyService;\n};\n\n/** @public */\nexport type PagerDutyIncidentsResponse = {\n incidents: PagerDutyIncident[];\n};\n\n/** @public */\nexport type PagerDutyChangeEventsResponse = {\n change_events: PagerDutyChangeEvent[];\n};\n\n/** @public */\nexport type PagerDutyOnCallsResponse = {\n oncalls: PagerDutyOnCall[];\n};\n\n/** @public */\nexport type PagerDutyIntegrationResponse = {\n integration: PagerDutyIntegration;\n}\n\n/** @public */\nexport type PagerDutyEscalationPoliciesResponse = {\n escalation_policies: PagerDutyEscalationPolicy[];\n limit?: number;\n offset?: number;\n more?: boolean;\n total?: number;\n};\n\n/** @public */\nexport type PagerDutyAbilitiesResponse = {\n abilities: string[];\n};\n\n/** @public */\nexport class HttpError extends Error {\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n }\n\n status: number;\n}\n\n/** @public */\nexport type PagerDutyOAuthConfig = {\n clientId: string;\n clientSecret: string;\n region?: string;\n subDomain: string;\n}\n","/** @public */\nexport const PAGERDUTY_INTEGRATION_KEY = 'pagerduty.com/integration-key';\n\n/** @public */\nexport const PAGERDUTY_SERVICE_ID = 'pagerduty.com/service-id';"],"names":[],"mappings":";;;;;;AAkKO,MAAM,kBAAkB,KAAM,CAAA;AAAA,EACjC,WAAA,CAAY,SAAiB,MAAgB,EAAA;AACzC,IAAA,KAAA,CAAM,OAAO,CAAA,CAAA;AAIjB,IAAA,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAHI,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA,CAAA;AAAA,GAClB;AAGJ;;ACxKO,MAAM,yBAA4B,GAAA,gCAAA;AAGlC,MAAM,oBAAuB,GAAA;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pagerduty/backstage-plugin-common",
3
3
  "description": "Common components for PagerDuty plugins for Backstage",
4
- "version": "0.0.3-next.8",
4
+ "version": "0.1.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -35,16 +35,11 @@
35
35
  "@backstage/cli": "^0.25.1",
36
36
  "@commitlint/cli": "^17.7.1",
37
37
  "@commitlint/config-conventional": "^17.7.0",
38
- "@types/winston": "^2.4.4",
39
38
  "typescript": "^5.3.3"
40
39
  },
41
40
  "files": [
42
41
  "dist"
43
42
  ],
44
43
  "packageManager": "yarn@3.6.3",
45
- "dependencies": {
46
- "@backstage/config": "^1.1.1",
47
- "winston": "^3.2.1"
48
- },
49
44
  "module": "./dist/index.esm.js"
50
45
  }