@backstage/plugin-scaffolder-backend-module-notifications 0.0.0-nightly-20240507021634

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 ADDED
@@ -0,0 +1,12 @@
1
+ # @backstage/plugin-scaffolder-backend-module-notifications
2
+
3
+ ## 0.0.0-nightly-20240507021634
4
+
5
+ ### Patch Changes
6
+
7
+ - 503d769: Add a new scaffolder action to allow sending notifications from templates
8
+ - Updated dependencies
9
+ - @backstage/backend-common@0.0.0-nightly-20240507021634
10
+ - @backstage/plugin-notifications-node@0.0.0-nightly-20240507021634
11
+ - @backstage/backend-plugin-api@0.0.0-nightly-20240507021634
12
+ - @backstage/plugin-scaffolder-node@0.0.0-nightly-20240507021634
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @backstage/plugin-scaffolder-backend-module-notifications
2
+
3
+ The notifications backend module for the scaffolder plugin.
4
+
5
+ _This plugin was created through the Backstage CLI_
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
6
+ var backendPluginApi = require('@backstage/backend-plugin-api');
7
+ var pluginNotificationsNode = require('@backstage/plugin-notifications-node');
8
+ var alpha = require('@backstage/plugin-scaffolder-node/alpha');
9
+
10
+ function createSendNotificationAction(options) {
11
+ const { notifications } = options;
12
+ return pluginScaffolderNode.createTemplateAction({
13
+ id: "notification:send",
14
+ description: "Sends a notification using NotificationService",
15
+ schema: {
16
+ input: {
17
+ type: "object",
18
+ required: ["recipients", "title"],
19
+ properties: {
20
+ recipients: {
21
+ title: "Recipient",
22
+ enum: ["broadcast", "entity"],
23
+ description: "The recipient of the notification, either broadcast or entity. If using entity, also entityRef must be provided",
24
+ type: "string"
25
+ },
26
+ entityRefs: {
27
+ title: "Entity references",
28
+ description: "The entity references to send the notification to, required if using recipient of entity",
29
+ type: "array",
30
+ items: {
31
+ type: "string"
32
+ }
33
+ },
34
+ title: {
35
+ title: "Title",
36
+ description: "Notification title",
37
+ type: "string"
38
+ },
39
+ info: {
40
+ title: "Description",
41
+ description: "Notification description",
42
+ type: "string"
43
+ },
44
+ link: {
45
+ title: "Link",
46
+ description: "Notification link",
47
+ type: "string"
48
+ },
49
+ severity: {
50
+ title: "Severity",
51
+ type: "string",
52
+ description: `Notification severity`,
53
+ enum: ["low", "normal", "high", "critical"]
54
+ },
55
+ scope: {
56
+ title: "Scope",
57
+ description: "Notification scope",
58
+ type: "string"
59
+ },
60
+ optional: {
61
+ title: "Optional",
62
+ description: "Do not fail the action if the notification sending fails",
63
+ type: "boolean"
64
+ }
65
+ }
66
+ }
67
+ },
68
+ async handler(ctx) {
69
+ const {
70
+ recipients,
71
+ entityRefs,
72
+ title,
73
+ info,
74
+ link,
75
+ severity,
76
+ scope,
77
+ optional
78
+ } = ctx.input;
79
+ ctx.logger.info(`Sending notification to ${recipients}`);
80
+ if (recipients === "entity" && !entityRefs) {
81
+ if (optional !== true) {
82
+ throw new Error("Entity references must be provided");
83
+ }
84
+ return;
85
+ }
86
+ const notificationRecipients = recipients === "broadcast" ? { type: "broadcast" } : { type: "entity", entityRef: entityRefs };
87
+ const payload = {
88
+ title,
89
+ description: info,
90
+ link,
91
+ severity,
92
+ scope
93
+ };
94
+ try {
95
+ await notifications.send({
96
+ recipients: notificationRecipients,
97
+ payload
98
+ });
99
+ } catch (e) {
100
+ ctx.logger.error(`Failed to send notification: ${e}`);
101
+ if (optional !== true) {
102
+ throw e;
103
+ }
104
+ }
105
+ }
106
+ });
107
+ }
108
+
109
+ const scaffolderModuleNotifications = backendPluginApi.createBackendModule({
110
+ pluginId: "scaffolder",
111
+ moduleId: "notifications",
112
+ register(reg) {
113
+ reg.registerInit({
114
+ deps: {
115
+ notifications: pluginNotificationsNode.notificationService,
116
+ scaffolder: alpha.scaffolderActionsExtensionPoint
117
+ },
118
+ async init({ notifications, scaffolder }) {
119
+ scaffolder.addActions(createSendNotificationAction({ notifications }));
120
+ }
121
+ });
122
+ }
123
+ });
124
+
125
+ exports.createSendNotificationAction = createSendNotificationAction;
126
+ exports.default = scaffolderModuleNotifications;
127
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/actions/sendNotification.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n NotificationRecipients,\n NotificationService,\n} from '@backstage/plugin-notifications-node';\nimport {\n NotificationPayload,\n NotificationSeverity,\n} from '@backstage/plugin-notifications-common';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\n\n/**\n * @public\n */\nexport function createSendNotificationAction(options: {\n notifications: NotificationService;\n}) {\n const { notifications } = options;\n return createTemplateAction<{\n recipients: string;\n entityRefs?: string[];\n title: string;\n info?: string;\n link?: string;\n severity?: NotificationSeverity;\n scope?: string;\n optional?: boolean;\n }>({\n id: 'notification:send',\n description: 'Sends a notification using NotificationService',\n schema: {\n input: {\n type: 'object',\n required: ['recipients', 'title'],\n properties: {\n recipients: {\n title: 'Recipient',\n enum: ['broadcast', 'entity'],\n description:\n 'The recipient of the notification, either broadcast or entity. If using entity, also entityRef must be provided',\n type: 'string',\n },\n entityRefs: {\n title: 'Entity references',\n description:\n 'The entity references to send the notification to, required if using recipient of entity',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n title: {\n title: 'Title',\n description: 'Notification title',\n type: 'string',\n },\n info: {\n title: 'Description',\n description: 'Notification description',\n type: 'string',\n },\n link: {\n title: 'Link',\n description: 'Notification link',\n type: 'string',\n },\n severity: {\n title: 'Severity',\n type: 'string',\n description: `Notification severity`,\n enum: ['low', 'normal', 'high', 'critical'],\n },\n scope: {\n title: 'Scope',\n description: 'Notification scope',\n type: 'string',\n },\n optional: {\n title: 'Optional',\n description:\n 'Do not fail the action if the notification sending fails',\n type: 'boolean',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n recipients,\n entityRefs,\n title,\n info,\n link,\n severity,\n scope,\n optional,\n } = ctx.input;\n\n ctx.logger.info(`Sending notification to ${recipients}`);\n if (recipients === 'entity' && !entityRefs) {\n if (optional !== true) {\n throw new Error('Entity references must be provided');\n }\n return;\n }\n\n const notificationRecipients: NotificationRecipients =\n recipients === 'broadcast'\n ? { type: 'broadcast' }\n : { type: 'entity', entityRef: entityRefs! };\n const payload: NotificationPayload = {\n title,\n description: info,\n link,\n severity,\n scope,\n };\n\n try {\n await notifications.send({\n recipients: notificationRecipients,\n payload,\n });\n } catch (e) {\n ctx.logger.error(`Failed to send notification: ${e}`);\n if (optional !== true) {\n throw e;\n }\n }\n },\n });\n}\n","/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createBackendModule } from '@backstage/backend-plugin-api';\nimport { notificationService } from '@backstage/plugin-notifications-node';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport { createSendNotificationAction } from './actions';\n\n/**\n * @public\n * The Notifications module for the Scaffolder Backend\n */\nexport const scaffolderModuleNotifications = createBackendModule({\n pluginId: 'scaffolder',\n moduleId: 'notifications',\n register(reg) {\n reg.registerInit({\n deps: {\n notifications: notificationService,\n scaffolder: scaffolderActionsExtensionPoint,\n },\n async init({ notifications, scaffolder }) {\n scaffolder.addActions(createSendNotificationAction({ notifications }));\n },\n });\n },\n});\n"],"names":["createTemplateAction","createBackendModule","notificationService","scaffolderActionsExtensionPoint"],"mappings":";;;;;;;;;AA4BO,SAAS,6BAA6B,OAE1C,EAAA;AACD,EAAM,MAAA,EAAE,eAAkB,GAAA,OAAA,CAAA;AAC1B,EAAA,OAAOA,yCASJ,CAAA;AAAA,IACD,EAAI,EAAA,mBAAA;AAAA,IACJ,WAAa,EAAA,gDAAA;AAAA,IACb,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,YAAA,EAAc,OAAO,CAAA;AAAA,QAChC,UAAY,EAAA;AAAA,UACV,UAAY,EAAA;AAAA,YACV,KAAO,EAAA,WAAA;AAAA,YACP,IAAA,EAAM,CAAC,WAAA,EAAa,QAAQ,CAAA;AAAA,YAC5B,WACE,EAAA,iHAAA;AAAA,YACF,IAAM,EAAA,QAAA;AAAA,WACR;AAAA,UACA,UAAY,EAAA;AAAA,YACV,KAAO,EAAA,mBAAA;AAAA,YACP,WACE,EAAA,0FAAA;AAAA,YACF,IAAM,EAAA,OAAA;AAAA,YACN,KAAO,EAAA;AAAA,cACL,IAAM,EAAA,QAAA;AAAA,aACR;AAAA,WACF;AAAA,UACA,KAAO,EAAA;AAAA,YACL,KAAO,EAAA,OAAA;AAAA,YACP,WAAa,EAAA,oBAAA;AAAA,YACb,IAAM,EAAA,QAAA;AAAA,WACR;AAAA,UACA,IAAM,EAAA;AAAA,YACJ,KAAO,EAAA,aAAA;AAAA,YACP,WAAa,EAAA,0BAAA;AAAA,YACb,IAAM,EAAA,QAAA;AAAA,WACR;AAAA,UACA,IAAM,EAAA;AAAA,YACJ,KAAO,EAAA,MAAA;AAAA,YACP,WAAa,EAAA,mBAAA;AAAA,YACb,IA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AAa,EAAA,IAAA;AAAA,QACb,IAAA;AAAA,QACA,QAAA;AAAA,QACA,KAAA;AAAA,OACF,CAAA;AAEA,MAAI,IAAA;AACF,QAAA,MAAM,cAAc,IAAK,CAAA;AAAA,UACvB,UAAY,EAAA,sBAAA;AAAA,UACZ,OAAA;AAAA,SACD,CAAA,CAAA;AAAA,eACM,CAAG,EAAA;AACV,QAAA,GAAA,CAAI,MAAO,CAAA,KAAA,CAAM,CAAgC,6BAAA,EAAA,CAAC,CAAE,CAAA,CAAA,CAAA;AACpD,QAAA,IAAI,aAAa,IAAM,EAAA;AACrB,UAAM,MAAA,CAAA,CAAA;AAAA,SACR;AAAA,OACF;AAAA,KACF;AAAA,GACD,CAAA,CAAA;AACH;;ACzHO,MAAM,gCAAgCC,oCAAoB,CAAA;AAAA,EAC/D,QAAU,EAAA,YAAA;AAAA,EACV,QAAU,EAAA,eAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,aAAe,EAAAC,2CAAA;AAAA,QACf,UAAY,EAAAC,qCAAA;AAAA,OACd;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,aAAA,EAAe,YAAc,EAAA;AACxC,QAAA,UAAA,CAAW,UAAW,CAAA,4BAAA,CAA6B,EAAE,aAAA,EAAe,CAAC,CAAA,CAAA;AAAA,OACvE;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
@@ -0,0 +1,29 @@
1
+ import * as _backstage_plugin_scaffolder_node from '@backstage/plugin-scaffolder-node';
2
+ import * as _backstage_types from '@backstage/types';
3
+ import { NotificationService } from '@backstage/plugin-notifications-node';
4
+ import { NotificationSeverity } from '@backstage/plugin-notifications-common';
5
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
6
+
7
+ /**
8
+ * @public
9
+ */
10
+ declare function createSendNotificationAction(options: {
11
+ notifications: NotificationService;
12
+ }): _backstage_plugin_scaffolder_node.TemplateAction<{
13
+ recipients: string;
14
+ entityRefs?: string[] | undefined;
15
+ title: string;
16
+ info?: string | undefined;
17
+ link?: string | undefined;
18
+ severity?: NotificationSeverity | undefined;
19
+ scope?: string | undefined;
20
+ optional?: boolean | undefined;
21
+ }, _backstage_types.JsonObject>;
22
+
23
+ /**
24
+ * @public
25
+ * The Notifications module for the Scaffolder Backend
26
+ */
27
+ declare const scaffolderModuleNotifications: () => _backstage_backend_plugin_api.BackendFeature;
28
+
29
+ export { createSendNotificationAction, scaffolderModuleNotifications as default };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@backstage/plugin-scaffolder-backend-module-notifications",
3
+ "version": "0.0.0-nightly-20240507021634",
4
+ "description": "The notifications backend module for the scaffolder plugin.",
5
+ "backstage": {
6
+ "role": "backend-plugin-module"
7
+ },
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "main": "dist/index.cjs.js",
11
+ "types": "dist/index.d.ts"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/backstage/backstage",
16
+ "directory": "plugins/scaffolder-backend-module-notifications"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "main": "dist/index.cjs.js",
20
+ "types": "dist/index.d.ts",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "backstage-cli package build",
26
+ "clean": "backstage-cli package clean",
27
+ "lint": "backstage-cli package lint",
28
+ "prepack": "backstage-cli package prepack",
29
+ "postpack": "backstage-cli package postpack",
30
+ "start": "backstage-cli package start",
31
+ "test": "backstage-cli package test"
32
+ },
33
+ "dependencies": {
34
+ "@backstage/backend-common": "^0.0.0-nightly-20240507021634",
35
+ "@backstage/backend-plugin-api": "^0.0.0-nightly-20240507021634",
36
+ "@backstage/plugin-notifications-common": "^0.0.3",
37
+ "@backstage/plugin-notifications-node": "^0.0.0-nightly-20240507021634",
38
+ "@backstage/plugin-scaffolder-node": "^0.0.0-nightly-20240507021634",
39
+ "octokit": "^3.0.0"
40
+ },
41
+ "devDependencies": {
42
+ "@backstage/cli": "^0.0.0-nightly-20240507021634",
43
+ "@backstage/plugin-scaffolder-node-test-utils": "^0.0.0-nightly-20240507021634"
44
+ }
45
+ }