@rothenbergt/backstage-plugin-roadmap-backend 0.6.1 → 0.7.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/config.d.ts +80 -0
- package/dist/index.d.ts +3 -0
- package/dist/plugin.cjs.js +7 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/routes/commentsRouter.cjs.js +16 -0
- package/dist/routes/commentsRouter.cjs.js.map +1 -1
- package/dist/routes/featuresRouter.cjs.js +16 -0
- package/dist/routes/featuresRouter.cjs.js.map +1 -1
- package/dist/routes/router.cjs.js.map +1 -1
- package/dist/services/RoadmapNotificationService.cjs.js +75 -0
- package/dist/services/RoadmapNotificationService.cjs.js.map +1 -0
- package/package.json +10 -2
package/config.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
roadmap?: {
|
|
3
|
+
/**
|
|
4
|
+
* Datasource for roadmap data. Defaults to 'database'.
|
|
5
|
+
*/
|
|
6
|
+
source?: 'database' | 'gitlab';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Entity refs treated as roadmap admins when the permission framework is
|
|
10
|
+
* disabled, and recipients of new-suggestion notifications in all modes.
|
|
11
|
+
* Group refs are expanded by the notifications backend.
|
|
12
|
+
*/
|
|
13
|
+
adminUsers?: string[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* GitLab datasource connection details. Required when source is 'gitlab'.
|
|
17
|
+
*/
|
|
18
|
+
gitlab?: {
|
|
19
|
+
/**
|
|
20
|
+
* Base URL for the GitLab API, e.g. https://gitlab.com/api/v4
|
|
21
|
+
*/
|
|
22
|
+
apiBaseUrl: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Personal access token with API access to the project or group.
|
|
26
|
+
* @visibility secret
|
|
27
|
+
*/
|
|
28
|
+
token: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* GitLab project ID (numeric) or URL-encoded path. Mutually exclusive
|
|
32
|
+
* with groupId.
|
|
33
|
+
*/
|
|
34
|
+
projectId?: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* GitLab group ID or path; aggregates roadmap issues across all
|
|
38
|
+
* projects in the group. Mutually exclusive with projectId.
|
|
39
|
+
*/
|
|
40
|
+
groupId?: string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Project where new features are created in group mode.
|
|
44
|
+
*/
|
|
45
|
+
defaultProjectId?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Board column customization, merged with built-in defaults per status.
|
|
50
|
+
*/
|
|
51
|
+
columns?: Array<{
|
|
52
|
+
/**
|
|
53
|
+
* One of: Suggested, Planned, In Progress, Completed, Declined.
|
|
54
|
+
*/
|
|
55
|
+
status: string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Column heading shown on the board. Defaults to the status name.
|
|
59
|
+
*/
|
|
60
|
+
title?: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Hide the column (and omit its features from the default list) when
|
|
64
|
+
* false.
|
|
65
|
+
*/
|
|
66
|
+
visible?: boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Hide features older than this many days from the default list
|
|
70
|
+
* (database datasource only).
|
|
71
|
+
*/
|
|
72
|
+
retentionDays?: number;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Which timestamp retention uses. Defaults to 'updated'.
|
|
76
|
+
*/
|
|
77
|
+
retentionAnchor?: 'created' | 'updated';
|
|
78
|
+
}>;
|
|
79
|
+
};
|
|
80
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { LoggerService, HttpAuthService, UserInfoService, PermissionsService, Ca
|
|
|
3
3
|
import { Config } from '@backstage/config';
|
|
4
4
|
import express from 'express';
|
|
5
5
|
import { NewComment, Comment, NewFeature, Feature, FeatureStatus, RoadmapBoardColumnResolved, RoadmapBoardConfigResponse } from '@rothenbergt/backstage-plugin-roadmap-common';
|
|
6
|
+
import { NotificationService } from '@backstage/plugin-notifications-node';
|
|
6
7
|
|
|
7
8
|
/** Supported datasource backends for the roadmap plugin */
|
|
8
9
|
type DatasourceType = 'database' | 'gitlab';
|
|
@@ -128,6 +129,8 @@ interface RouterOptions {
|
|
|
128
129
|
datasource: DatasourceType;
|
|
129
130
|
boardColumns: RoadmapBoardColumnResolved[];
|
|
130
131
|
boardConfigResponse: RoadmapBoardConfigResponse;
|
|
132
|
+
/** Optional so the router also works in setups without the notifications service. */
|
|
133
|
+
notifications?: NotificationService;
|
|
131
134
|
}
|
|
132
135
|
/**
|
|
133
136
|
* Creates the main router for the roadmap plugin
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var pluginNotificationsNode = require('@backstage/plugin-notifications-node');
|
|
4
5
|
var router = require('./routes/router.cjs.js');
|
|
5
6
|
require('express-promise-router');
|
|
6
7
|
require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
@@ -23,7 +24,8 @@ const roadmapPlugin = backendPluginApi.createBackendPlugin({
|
|
|
23
24
|
userInfo: backendPluginApi.coreServices.userInfo,
|
|
24
25
|
httpAuth: backendPluginApi.coreServices.httpAuth,
|
|
25
26
|
permissions: backendPluginApi.coreServices.permissions,
|
|
26
|
-
cache: backendPluginApi.coreServices.cache
|
|
27
|
+
cache: backendPluginApi.coreServices.cache,
|
|
28
|
+
notifications: pluginNotificationsNode.notificationService
|
|
27
29
|
},
|
|
28
30
|
async init({
|
|
29
31
|
httpRouter,
|
|
@@ -33,7 +35,8 @@ const roadmapPlugin = backendPluginApi.createBackendPlugin({
|
|
|
33
35
|
userInfo,
|
|
34
36
|
httpAuth,
|
|
35
37
|
permissions,
|
|
36
|
-
cache
|
|
38
|
+
cache,
|
|
39
|
+
notifications
|
|
37
40
|
}) {
|
|
38
41
|
const datasource = config.getDatasource(config$1);
|
|
39
42
|
const permissionEnabled = config.isPermissionEnabled(config$1);
|
|
@@ -68,7 +71,8 @@ const roadmapPlugin = backendPluginApi.createBackendPlugin({
|
|
|
68
71
|
cache,
|
|
69
72
|
datasource,
|
|
70
73
|
boardColumns,
|
|
71
|
-
boardConfigResponse
|
|
74
|
+
boardConfigResponse,
|
|
75
|
+
notifications
|
|
72
76
|
})
|
|
73
77
|
);
|
|
74
78
|
httpRouter.addAuthPolicy({
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["import {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './routes';\nimport { RoadmapDatasource } from './types';\nimport { RoadmapDatabaseClient } from './database/RoadmapDatabaseClient';\nimport { RoadmapGitlabClient } from './gitlab';\nimport { getDatasource, getGitlabConfig, isPermissionEnabled } from './config';\nimport { getBoardConfigResponse, getMergedBoardColumns } from './boardConfig';\n\n/**\n * Backend plugin for the Roadmap feature\n *\n * Provides endpoints for managing roadmap features, comments, and votes\n */\nexport const roadmapPlugin = createBackendPlugin({\n pluginId: 'roadmap',\n register(env) {\n env.registerInit({\n deps: {\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n database: coreServices.database,\n userInfo: coreServices.userInfo,\n httpAuth: coreServices.httpAuth,\n permissions: coreServices.permissions,\n cache: coreServices.cache,\n },\n async init({\n httpRouter,\n logger,\n config,\n database,\n userInfo,\n httpAuth,\n permissions,\n cache,\n }) {\n const datasource = getDatasource(config);\n const permissionEnabled = isPermissionEnabled(config);\n const boardColumns = getMergedBoardColumns(config);\n const boardConfigResponse = getBoardConfigResponse(config, datasource);\n\n let db: RoadmapDatasource;\n if (datasource === 'database') {\n db = await RoadmapDatabaseClient.create({\n database,\n logger,\n });\n } else {\n db = RoadmapGitlabClient.create({\n gitlab: getGitlabConfig(config),\n logger,\n cache,\n });\n }\n\n if (!permissionEnabled) {\n logger.warn(\n 'Permissions are disabled. Using configArray for admin users.',\n );\n }\n\n httpRouter.use(\n await createRouter({\n logger,\n config,\n db,\n userInfo,\n httpAuth,\n permissions: permissionEnabled ? permissions : undefined,\n cache,\n datasource,\n boardColumns,\n boardConfigResponse,\n }),\n );\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","config","getDatasource","isPermissionEnabled","getMergedBoardColumns","getBoardConfigResponse","RoadmapDatabaseClient","RoadmapGitlabClient","getGitlabConfig","createRouter"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["import {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { notificationService } from '@backstage/plugin-notifications-node';\nimport { createRouter } from './routes';\nimport { RoadmapDatasource } from './types';\nimport { RoadmapDatabaseClient } from './database/RoadmapDatabaseClient';\nimport { RoadmapGitlabClient } from './gitlab';\nimport { getDatasource, getGitlabConfig, isPermissionEnabled } from './config';\nimport { getBoardConfigResponse, getMergedBoardColumns } from './boardConfig';\n\n/**\n * Backend plugin for the Roadmap feature\n *\n * Provides endpoints for managing roadmap features, comments, and votes\n */\nexport const roadmapPlugin = createBackendPlugin({\n pluginId: 'roadmap',\n register(env) {\n env.registerInit({\n deps: {\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n database: coreServices.database,\n userInfo: coreServices.userInfo,\n httpAuth: coreServices.httpAuth,\n permissions: coreServices.permissions,\n cache: coreServices.cache,\n notifications: notificationService,\n },\n async init({\n httpRouter,\n logger,\n config,\n database,\n userInfo,\n httpAuth,\n permissions,\n cache,\n notifications,\n }) {\n const datasource = getDatasource(config);\n const permissionEnabled = isPermissionEnabled(config);\n const boardColumns = getMergedBoardColumns(config);\n const boardConfigResponse = getBoardConfigResponse(config, datasource);\n\n let db: RoadmapDatasource;\n if (datasource === 'database') {\n db = await RoadmapDatabaseClient.create({\n database,\n logger,\n });\n } else {\n db = RoadmapGitlabClient.create({\n gitlab: getGitlabConfig(config),\n logger,\n cache,\n });\n }\n\n if (!permissionEnabled) {\n logger.warn(\n 'Permissions are disabled. Using configArray for admin users.',\n );\n }\n\n httpRouter.use(\n await createRouter({\n logger,\n config,\n db,\n userInfo,\n httpAuth,\n permissions: permissionEnabled ? permissions : undefined,\n cache,\n datasource,\n boardColumns,\n boardConfigResponse,\n notifications,\n }),\n );\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","notificationService","config","getDatasource","isPermissionEnabled","getMergedBoardColumns","getBoardConfigResponse","RoadmapDatabaseClient","RoadmapGitlabClient","getGitlabConfig","createRouter"],"mappings":";;;;;;;;;;;;;;AAiBO,MAAM,gBAAgBA,oCAAA,CAAoB;AAAA,EAC/C,QAAA,EAAU,SAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,YAAYC,6BAAA,CAAa,UAAA;AAAA,QACzB,QAAQA,6BAAA,CAAa,MAAA;AAAA,QACrB,QAAQA,6BAAA,CAAa,UAAA;AAAA,QACrB,UAAUA,6BAAA,CAAa,QAAA;AAAA,QACvB,UAAUA,6BAAA,CAAa,QAAA;AAAA,QACvB,UAAUA,6BAAA,CAAa,QAAA;AAAA,QACvB,aAAaA,6BAAA,CAAa,WAAA;AAAA,QAC1B,OAAOA,6BAAA,CAAa,KAAA;AAAA,QACpB,aAAA,EAAeC;AAAA,OACjB;AAAA,MACA,MAAM,IAAA,CAAK;AAAA,QACT,UAAA;AAAA,QACA,MAAA;AAAA,gBACAC,QAAA;AAAA,QACA,QAAA;AAAA,QACA,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3,8 @@
|
|
|
3
3
|
var Router = require('express-promise-router');
|
|
4
4
|
var CommentService = require('../services/CommentService.cjs.js');
|
|
5
5
|
var PermissionService = require('../services/PermissionService.cjs.js');
|
|
6
|
+
var RoadmapNotificationService = require('../services/RoadmapNotificationService.cjs.js');
|
|
7
|
+
var config = require('../config.cjs.js');
|
|
6
8
|
var errors = require('@backstage/errors');
|
|
7
9
|
|
|
8
10
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
@@ -14,6 +16,11 @@ function commentsRouter(options) {
|
|
|
14
16
|
const router = Router__default.default();
|
|
15
17
|
const commentService = new CommentService.CommentService(db, logger, datasource);
|
|
16
18
|
const permissionService = new PermissionService.PermissionService(options);
|
|
19
|
+
const roadmapNotifications = options.notifications ? new RoadmapNotificationService.RoadmapNotificationService(
|
|
20
|
+
options.notifications,
|
|
21
|
+
logger,
|
|
22
|
+
config.getAdminUsers(options.config)
|
|
23
|
+
) : void 0;
|
|
17
24
|
router.post("/", async (req, res, next) => {
|
|
18
25
|
try {
|
|
19
26
|
const username = await permissionService.getUsername(req);
|
|
@@ -23,6 +30,15 @@ function commentsRouter(options) {
|
|
|
23
30
|
text,
|
|
24
31
|
author: username
|
|
25
32
|
});
|
|
33
|
+
if (roadmapNotifications) {
|
|
34
|
+
db.getFeatureById(featureId).then(
|
|
35
|
+
(feature) => roadmapNotifications.notifyCommentAdded(feature, username)
|
|
36
|
+
).catch((error) => {
|
|
37
|
+
logger.warn(
|
|
38
|
+
`Failed to send comment notification for feature ${featureId}: ${error}`
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
26
42
|
res.status(201).json(comment);
|
|
27
43
|
} catch (error) {
|
|
28
44
|
next(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commentsRouter.cjs.js","sources":["../../src/routes/commentsRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { CommentService } from '../services/CommentService';\nimport { PermissionService } from '../services/PermissionService';\nimport { InputError, NotAllowedError } from '@backstage/errors';\n\n/**\n * Router for comment-related endpoints\n */\nexport function commentsRouter(options: RouterOptions): express.Router {\n const { logger, db, datasource } = options;\n const router = Router();\n\n // Initialize services\n const commentService = new CommentService(db, logger, datasource);\n const permissionService = new PermissionService(options);\n\n // Add a comment to a feature\n router.post('/', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\n const { featureId, text } = req.body;\n\n const comment = await commentService.addComment({\n featureId,\n text,\n author: username,\n });\n\n res.status(201).json(comment);\n } catch (error) {\n next(error);\n }\n });\n\n // Get comments for a specific feature\n router.get('/', async (req, res, next) => {\n try {\n const { featureId } = req.query;\n if (!featureId || typeof featureId !== 'string') {\n throw new InputError('featureId is required and must be a string');\n }\n\n const comments = await commentService.getCommentsByFeatureId(featureId);\n res.status(200).json(comments);\n } catch (error) {\n next(error);\n }\n });\n\n router.delete('/:commentId', async (req, res, next) => {\n try {\n if (datasource !== 'database') {\n throw new NotAllowedError(\n 'This operation is not supported for the GitLab roadmap datasource',\n );\n }\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n if (!isAdmin) {\n throw new NotAllowedError('User is not a Roadmap admin');\n }\n const { commentId } = req.params;\n await commentService.deleteComment(commentId);\n res.status(204).send();\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","CommentService","PermissionService","InputError","NotAllowedError"],"mappings":"
|
|
1
|
+
{"version":3,"file":"commentsRouter.cjs.js","sources":["../../src/routes/commentsRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { CommentService } from '../services/CommentService';\nimport { PermissionService } from '../services/PermissionService';\nimport { RoadmapNotificationService } from '../services/RoadmapNotificationService';\nimport { getAdminUsers } from '../config';\nimport { InputError, NotAllowedError } from '@backstage/errors';\n\n/**\n * Router for comment-related endpoints\n */\nexport function commentsRouter(options: RouterOptions): express.Router {\n const { logger, db, datasource } = options;\n const router = Router();\n\n // Initialize services\n const commentService = new CommentService(db, logger, datasource);\n const permissionService = new PermissionService(options);\n const roadmapNotifications = options.notifications\n ? new RoadmapNotificationService(\n options.notifications,\n logger,\n getAdminUsers(options.config),\n )\n : undefined;\n\n // Add a comment to a feature\n router.post('/', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\n const { featureId, text } = req.body;\n\n const comment = await commentService.addComment({\n featureId,\n text,\n author: username,\n });\n\n if (roadmapNotifications) {\n // Fire-and-forget: neither the feature lookup nor the send may fail\n // the comment request. Uses the request's featureId because the\n // database datasource returns the column name feature_id instead.\n db.getFeatureById(featureId)\n .then(feature =>\n roadmapNotifications.notifyCommentAdded(feature, username),\n )\n .catch(error => {\n logger.warn(\n `Failed to send comment notification for feature ${featureId}: ${error}`,\n );\n });\n }\n\n res.status(201).json(comment);\n } catch (error) {\n next(error);\n }\n });\n\n // Get comments for a specific feature\n router.get('/', async (req, res, next) => {\n try {\n const { featureId } = req.query;\n if (!featureId || typeof featureId !== 'string') {\n throw new InputError('featureId is required and must be a string');\n }\n\n const comments = await commentService.getCommentsByFeatureId(featureId);\n res.status(200).json(comments);\n } catch (error) {\n next(error);\n }\n });\n\n router.delete('/:commentId', async (req, res, next) => {\n try {\n if (datasource !== 'database') {\n throw new NotAllowedError(\n 'This operation is not supported for the GitLab roadmap datasource',\n );\n }\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n if (!isAdmin) {\n throw new NotAllowedError('User is not a Roadmap admin');\n }\n const { commentId } = req.params;\n await commentService.deleteComment(commentId);\n res.status(204).send();\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","CommentService","PermissionService","RoadmapNotificationService","getAdminUsers","InputError","NotAllowedError"],"mappings":";;;;;;;;;;;;;AAYO,SAAS,eAAe,OAAA,EAAwC;AACrE,EAAA,MAAM,EAAE,MAAA,EA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AAA,CAAO,GAAG,CAAA,CAAE,IAAA,EAAK;AAAA,IACvB,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA,IACZ;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;;;;"}
|
|
@@ -4,6 +4,8 @@ var Router = require('express-promise-router');
|
|
|
4
4
|
var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
5
5
|
var FeatureService = require('../services/FeatureService.cjs.js');
|
|
6
6
|
var PermissionService = require('../services/PermissionService.cjs.js');
|
|
7
|
+
var RoadmapNotificationService = require('../services/RoadmapNotificationService.cjs.js');
|
|
8
|
+
var config = require('../config.cjs.js');
|
|
7
9
|
var errors = require('@backstage/errors');
|
|
8
10
|
|
|
9
11
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
@@ -20,6 +22,11 @@ function featuresRouter(options) {
|
|
|
20
22
|
datasource
|
|
21
23
|
);
|
|
22
24
|
const permissionService = new PermissionService.PermissionService(options);
|
|
25
|
+
const roadmapNotifications = options.notifications ? new RoadmapNotificationService.RoadmapNotificationService(
|
|
26
|
+
options.notifications,
|
|
27
|
+
logger,
|
|
28
|
+
config.getAdminUsers(options.config)
|
|
29
|
+
) : void 0;
|
|
23
30
|
router.get("/board-config", async (_req, res, next) => {
|
|
24
31
|
try {
|
|
25
32
|
res.status(200).json(options.boardConfigResponse);
|
|
@@ -47,6 +54,7 @@ function featuresRouter(options) {
|
|
|
47
54
|
{ title, description },
|
|
48
55
|
username
|
|
49
56
|
);
|
|
57
|
+
roadmapNotifications?.notifyFeatureCreated(feature, username);
|
|
50
58
|
res.status(201).json(feature);
|
|
51
59
|
} catch (error) {
|
|
52
60
|
next(error);
|
|
@@ -105,10 +113,18 @@ function featuresRouter(options) {
|
|
|
105
113
|
if (!isAdmin) {
|
|
106
114
|
throw new errors.NotAllowedError("User is not a Roadmap admin");
|
|
107
115
|
}
|
|
116
|
+
const before = await featureService.getFeatureById(id);
|
|
108
117
|
const updatedFeature = await featureService.updateFeatureStatus(
|
|
109
118
|
id,
|
|
110
119
|
status
|
|
111
120
|
);
|
|
121
|
+
if (before.status !== updatedFeature.status) {
|
|
122
|
+
roadmapNotifications?.notifyStatusChanged(
|
|
123
|
+
updatedFeature,
|
|
124
|
+
before.status,
|
|
125
|
+
username
|
|
126
|
+
);
|
|
127
|
+
}
|
|
112
128
|
res.status(200).json(updatedFeature);
|
|
113
129
|
} catch (error) {
|
|
114
130
|
next(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featuresRouter.cjs.js","sources":["../../src/routes/featuresRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { FeatureStatus } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { FeatureService } from '../services/FeatureService';\nimport { PermissionService } from '../services/PermissionService';\n\nimport { NotAllowedError, InputError } from '@backstage/errors';\n/**\n * Router for feature-related endpoints\n */\nexport function featuresRouter(options: RouterOptions): express.Router {\n const { logger, db, boardColumns, datasource } = options;\n const router = Router();\n\n // Initialize services\n const featureService = new FeatureService(\n db,\n logger,\n boardColumns,\n datasource,\n );\n const permissionService = new PermissionService(options);\n\n router.get('/board-config', async (_req, res, next) => {\n try {\n res.status(200).json(options.boardConfigResponse);\n } catch (error) {\n next(error);\n }\n });\n\n // Create new feature\n router.post('/', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\n const canCreate = await permissionService.canCreateFeature(req, username);\n if (!canCreate) {\n throw new NotAllowedError(\n 'User does not have permission to create features',\n );\n }\n const { title, description } = req.body;\n\n if (!title || typeof title !== 'string') {\n throw new InputError('Title is required');\n }\n if (!description || typeof description !== 'string') {\n throw new InputError('Description is required');\n }\n\n const feature = await featureService.addFeature(\n { title, description },\n username,\n );\n res.status(201).json(feature);\n } catch (error) {\n next(error);\n }\n });\n\n // Get all features\n router.get('/', async (req, res, next) => {\n try {\n const raw = req.query.includeBeyondRetention;\n const includeBeyondRetention =\n datasource === 'database' &&\n typeof raw === 'string' &&\n (raw === 'true' || raw === '1');\n const features = await featureService.listFeaturesForBoard(\n includeBeyondRetention,\n );\n res.status(200).json(features);\n } catch (error) {\n next(error);\n }\n });\n\n router.put('/reorder', async (req, res, next) => {\n try {\n if (datasource !== 'database') {\n throw new NotAllowedError(\n 'This operation is not supported for the GitLab roadmap datasource',\n );\n }\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n if (!isAdmin) {\n throw new NotAllowedError('User is not a Roadmap admin');\n }\n const { status, orderedIds } = req.body as {\n status?: string;\n orderedIds?: string[];\n };\n if (\n !status ||\n !Object.values(FeatureStatus).includes(status as FeatureStatus)\n ) {\n throw new InputError('Invalid status');\n }\n if (\n !Array.isArray(orderedIds) ||\n !orderedIds.every(id => typeof id === 'string')\n ) {\n throw new InputError('orderedIds must be an array of string ids');\n }\n await featureService.reorderFeatures(status as FeatureStatus, orderedIds);\n res.status(204).send();\n } catch (error) {\n next(error);\n }\n });\n\n // Update feature status (admin only) — after literal paths, before PUT /:id\n router.put('/:id/status', async (req, res, next) => {\n try {\n const { id } = req.params;\n const { status } = req.body;\n\n if (!status || !Object.values(FeatureStatus).includes(status)) {\n throw new InputError(\n `Invalid status. Must be one of: ${Object.values(FeatureStatus).join(\n ', ',\n )}`,\n );\n }\n\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n\n if (!isAdmin) {\n throw new NotAllowedError('User is not a Roadmap admin');\n }\n\n const updatedFeature = await featureService.updateFeatureStatus(\n id,\n status,\n );\n res.status(200).json(updatedFeature);\n } catch (error) {\n next(error);\n }\n });\n\n router.put('/:id', async (req, res, next) => {\n try {\n if (datasource !== 'database') {\n throw new NotAllowedError(\n 'This operation is not supported for the GitLab roadmap datasource',\n );\n }\n const { id } = req.params;\n const { title, description } = req.body as {\n title?: string;\n description?: string;\n };\n if (title === undefined && description === undefined) {\n throw new InputError(\n 'At least one of title or description is required',\n );\n }\n\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n\n if (isAdmin) {\n const updated = await featureService.updateFeatureDetails(id, {\n title,\n description,\n });\n res.status(200).json(updated);\n return;\n }\n\n await featureService.assertAuthorSuggestedOrNotFound(id, username);\n const updated = await featureService.updateFeatureDetails(id, {\n title,\n description,\n });\n res.status(200).json(updated);\n } catch (error) {\n next(error);\n }\n });\n\n router.delete('/:id', async (req, res, next) => {\n try {\n if (datasource !== 'database') {\n throw new NotAllowedError(\n 'This operation is not supported for the GitLab roadmap datasource',\n );\n }\n const { id } = req.params;\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n\n if (isAdmin) {\n await featureService.deleteFeature(id);\n res.status(204).send();\n return;\n }\n\n await featureService.assertAuthorSuggestedOrNotFound(id, username);\n await featureService.deleteFeature(id);\n res.status(204).send();\n } catch (error) {\n next(error);\n }\n });\n\n // Get feature by ID (must be after static paths like /reorder)\n router.get('/:id', async (req, res, next) => {\n try {\n const { id } = req.params;\n const feature = await featureService.getFeatureById(id);\n res.status(200).json(feature);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","FeatureService","PermissionService","NotAllowedError","InputError","FeatureStatus","updated"],"mappings":";;;;;;;;;;;;AAWO,SAAS,eAAe,OAAA,EAAwC;AACrE,EAAA,MAAM,EAAE,MAAA,EAAQ,EAAA,EAAI,YAAA,EAAc,YAAW,GAAI,OAAA;AACjD,EAAA,MAAM,SAASA,uBAAA,EAAO;AAGtB,EAAA,MAAM,iBAAiB,IAAIC,6BAAA;AAAA,IACzB,EAAA;AAAA,IACA,MAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,MAAM,iBAAA,GAAoB,IAAIC,mCAAA,CAAkB,OAAO,CAAA;AAEvD,EAAA,MAAA,CAAO,GAAA,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AAA,MAAM,EAAE,EAAA,EAAG,GAAI,GAAA,CAAI,MAAA;AACnB,MAAA,MAAM,OAAA,GAAU,MAAM,cAAA,CAAe,cAAA,CAAe,EAAE,CAAA;AACtD,MAAA,GAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK,OAAO,CAAA;AAAA,IAC9B,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA,IACZ;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"featuresRouter.cjs.js","sources":["../../src/routes/featuresRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { FeatureStatus } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { FeatureService } from '../services/FeatureService';\nimport { PermissionService } from '../services/PermissionService';\nimport { RoadmapNotificationService } from '../services/RoadmapNotificationService';\nimport { getAdminUsers } from '../config';\n\nimport { NotAllowedError, InputError } from '@backstage/errors';\n/**\n * Router for feature-related endpoints\n */\nexport function featuresRouter(options: RouterOptions): express.Router {\n const { logger, db, boardColumns, datasource } = options;\n const router = Router();\n\n // Initialize services\n const featureService = new FeatureService(\n db,\n logger,\n boardColumns,\n datasource,\n );\n const permissionService = new PermissionService(options);\n const roadmapNotifications = options.notifications\n ? new RoadmapNotificationService(\n options.notifications,\n logger,\n getAdminUsers(options.config),\n )\n : undefined;\n\n router.get('/board-config', async (_req, res, next) => {\n try {\n res.status(200).json(options.boardConfigResponse);\n } catch (error) {\n next(error);\n }\n });\n\n // Create new feature\n router.post('/', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\n const canCreate = await permissionService.canCreateFeature(req, username);\n if (!canCreate) {\n throw new NotAllowedError(\n 'User does not have permission to create features',\n );\n }\n const { title, description } = req.body;\n\n if (!title || typeof title !== 'string') {\n throw new InputError('Title is required');\n }\n if (!description || typeof description !== 'string') {\n throw new InputError('Description is required');\n }\n\n const feature = await featureService.addFeature(\n { title, description },\n username,\n );\n roadmapNotifications?.notifyFeatureCreated(feature, username);\n res.status(201).json(feature);\n } catch (error) {\n next(error);\n }\n });\n\n // Get all features. The search collator module reads this endpoint with a\n // service token, so it must stay accessible to service principals.\n router.get('/', async (req, res, next) => {\n try {\n const raw = req.query.includeBeyondRetention;\n const includeBeyondRetention =\n datasource === 'database' &&\n typeof raw === 'string' &&\n (raw === 'true' || raw === '1');\n const features = await featureService.listFeaturesForBoard(\n includeBeyondRetention,\n );\n res.status(200).json(features);\n } catch (error) {\n next(error);\n }\n });\n\n router.put('/reorder', async (req, res, next) => {\n try {\n if (datasource !== 'database') {\n throw new NotAllowedError(\n 'This operation is not supported for the GitLab roadmap datasource',\n );\n }\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n if (!isAdmin) {\n throw new NotAllowedError('User is not a Roadmap admin');\n }\n const { status, orderedIds } = req.body as {\n status?: string;\n orderedIds?: string[];\n };\n if (\n !status ||\n !Object.values(FeatureStatus).includes(status as FeatureStatus)\n ) {\n throw new InputError('Invalid status');\n }\n if (\n !Array.isArray(orderedIds) ||\n !orderedIds.every(id => typeof id === 'string')\n ) {\n throw new InputError('orderedIds must be an array of string ids');\n }\n await featureService.reorderFeatures(status as FeatureStatus, orderedIds);\n res.status(204).send();\n } catch (error) {\n next(error);\n }\n });\n\n // Update feature status (admin only) — after literal paths, before PUT /:id\n router.put('/:id/status', async (req, res, next) => {\n try {\n const { id } = req.params;\n const { status } = req.body;\n\n if (!status || !Object.values(FeatureStatus).includes(status)) {\n throw new InputError(\n `Invalid status. Must be one of: ${Object.values(FeatureStatus).join(\n ', ',\n )}`,\n );\n }\n\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n\n if (!isAdmin) {\n throw new NotAllowedError('User is not a Roadmap admin');\n }\n\n const before = await featureService.getFeatureById(id);\n const updatedFeature = await featureService.updateFeatureStatus(\n id,\n status,\n );\n if (before.status !== updatedFeature.status) {\n roadmapNotifications?.notifyStatusChanged(\n updatedFeature,\n before.status,\n username,\n );\n }\n res.status(200).json(updatedFeature);\n } catch (error) {\n next(error);\n }\n });\n\n router.put('/:id', async (req, res, next) => {\n try {\n if (datasource !== 'database') {\n throw new NotAllowedError(\n 'This operation is not supported for the GitLab roadmap datasource',\n );\n }\n const { id } = req.params;\n const { title, description } = req.body as {\n title?: string;\n description?: string;\n };\n if (title === undefined && description === undefined) {\n throw new InputError(\n 'At least one of title or description is required',\n );\n }\n\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n\n if (isAdmin) {\n const updated = await featureService.updateFeatureDetails(id, {\n title,\n description,\n });\n res.status(200).json(updated);\n return;\n }\n\n await featureService.assertAuthorSuggestedOrNotFound(id, username);\n const updated = await featureService.updateFeatureDetails(id, {\n title,\n description,\n });\n res.status(200).json(updated);\n } catch (error) {\n next(error);\n }\n });\n\n router.delete('/:id', async (req, res, next) => {\n try {\n if (datasource !== 'database') {\n throw new NotAllowedError(\n 'This operation is not supported for the GitLab roadmap datasource',\n );\n }\n const { id } = req.params;\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n\n if (isAdmin) {\n await featureService.deleteFeature(id);\n res.status(204).send();\n return;\n }\n\n await featureService.assertAuthorSuggestedOrNotFound(id, username);\n await featureService.deleteFeature(id);\n res.status(204).send();\n } catch (error) {\n next(error);\n }\n });\n\n // Get feature by ID (must be after static paths like /reorder)\n router.get('/:id', async (req, res, next) => {\n try {\n const { id } = req.params;\n const feature = await featureService.getFeatureById(id);\n res.status(200).json(feature);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","FeatureService","PermissionService","RoadmapNotificationService","getAdminUsers","NotAllowedError","InputError","FeatureStatus","updated"],"mappings":";;;;;;;;;;;;;;AAaO,SAAS,eAAe,OAAA,EAAwC;AACrE,EAAA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esContent":["import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport { CacheService, LoggerService } from '@backstage/backend-plugin-api';\nimport { Config } from '@backstage/config';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { DatasourceType, RoadmapDatasource } from '../types';\nimport {\n RoadmapBoardColumnResolved,\n RoadmapBoardConfigResponse,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport {\n HttpAuthService,\n UserInfoService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport { createPermissionIntegrationRouter } from '@backstage/plugin-permission-node';\nimport { roadmapPermissions } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { commentsRouter } from './commentsRouter';\nimport { featuresRouter } from './featuresRouter';\nimport { votesRouter } from './votesRouter';\nimport { permissionCheckRouter } from './permissionCheckRouter';\n\n/**\n * Options for configuring the roadmap plugin router\n */\nexport interface RouterOptions {\n logger: LoggerService;\n config: Config;\n db: RoadmapDatasource;\n httpAuth: HttpAuthService;\n userInfo: UserInfoService;\n permissions?: PermissionsService;\n cache: CacheService;\n datasource: DatasourceType;\n boardColumns: RoadmapBoardColumnResolved[];\n boardConfigResponse: RoadmapBoardConfigResponse;\n}\n\n/**\n * Creates the main router for the roadmap plugin\n * Sets up sub-routers for features, comments, votes, and permissions\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 // Set up permission integration for Backstage permission framework\n const permissionIntegrationRouter = createPermissionIntegrationRouter({\n permissions: roadmapPermissions,\n });\n\n // Health check endpoint\n router.get('/health', (_, response) => {\n logger.info('PONG!');\n response.json({ status: 'ok' });\n });\n\n router.use(permissionIntegrationRouter);\n\n // Register sub-routers\n router.use('/comments', commentsRouter(options));\n router.use('/features', featuresRouter(options));\n router.use('/votes', votesRouter(options));\n router.use('/permissions', permissionCheckRouter(options));\n\n // Add error handling middleware\n const middleware = MiddlewareFactory.create({ logger, config });\n router.use(middleware.error());\n\n return router;\n}\n"],"names":["Router","express","createPermissionIntegrationRouter","roadmapPermissions","commentsRouter","featuresRouter","votesRouter","permissionCheckRouter","MiddlewareFactory"],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"router.cjs.js","sources":["../../src/routes/router.ts"],"sourcesContent":["import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport { CacheService, LoggerService } from '@backstage/backend-plugin-api';\nimport { Config } from '@backstage/config';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { DatasourceType, RoadmapDatasource } from '../types';\nimport {\n RoadmapBoardColumnResolved,\n RoadmapBoardConfigResponse,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport {\n HttpAuthService,\n UserInfoService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport { createPermissionIntegrationRouter } from '@backstage/plugin-permission-node';\nimport { NotificationService } from '@backstage/plugin-notifications-node';\nimport { roadmapPermissions } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { commentsRouter } from './commentsRouter';\nimport { featuresRouter } from './featuresRouter';\nimport { votesRouter } from './votesRouter';\nimport { permissionCheckRouter } from './permissionCheckRouter';\n\n/**\n * Options for configuring the roadmap plugin router\n */\nexport interface RouterOptions {\n logger: LoggerService;\n config: Config;\n db: RoadmapDatasource;\n httpAuth: HttpAuthService;\n userInfo: UserInfoService;\n permissions?: PermissionsService;\n cache: CacheService;\n datasource: DatasourceType;\n boardColumns: RoadmapBoardColumnResolved[];\n boardConfigResponse: RoadmapBoardConfigResponse;\n /** Optional so the router also works in setups without the notifications service. */\n notifications?: NotificationService;\n}\n\n/**\n * Creates the main router for the roadmap plugin\n * Sets up sub-routers for features, comments, votes, and permissions\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 // Set up permission integration for Backstage permission framework\n const permissionIntegrationRouter = createPermissionIntegrationRouter({\n permissions: roadmapPermissions,\n });\n\n // Health check endpoint\n router.get('/health', (_, response) => {\n logger.info('PONG!');\n response.json({ status: 'ok' });\n });\n\n router.use(permissionIntegrationRouter);\n\n // Register sub-routers\n router.use('/comments', commentsRouter(options));\n router.use('/features', featuresRouter(options));\n router.use('/votes', votesRouter(options));\n router.use('/permissions', permissionCheckRouter(options));\n\n // Add error handling middleware\n const middleware = MiddlewareFactory.create({ logger, config });\n router.use(middleware.error());\n\n return router;\n}\n"],"names":["Router","express","createPermissionIntegrationRouter","roadmapPermissions","commentsRouter","featuresRouter","votesRouter","permissionCheckRouter","MiddlewareFactory"],"mappings":";;;;;;;;;;;;;;;;;AA6CA,eAAsB,aACpB,OAAA,EACyB;AACzB,EAAA,MAAM,EAAE,MAAA,EAAQ,MAAA,EAAO,GAAI,OAAA;AAE3B,EAAA,MAAM,SAASA,uBAAA,EAAO;AACtB,EAAA,MAAA,CAAO,GAAA,CAAIC,wBAAA,CAAQ,IAAA,EAAM,CAAA;AAGzB,EAAA,MAAM,8BAA8BC,sDAAA,CAAkC;AAAA,IACpE,WAAA,EAAaC;AAAA,GACd,CAAA;AAGD,EAAA,MAAA,CAAO,GAAA,CAAI,SAAA,EAAW,CAAC,CAAA,EAAG,QAAA,KAAa;AACrC,IAAA,MAAA,CAAO,KAAK,OAAO,CAAA;AACnB,IAAA,QAAA,CAAS,IAAA,CAAK,EAAE,MAAA,EAAQ,IAAA,EAAM,CAAA;AAAA,EAChC,CAAC,CAAA;AAED,EAAA,MAAA,CAAO,IAAI,2BAA2B,CAAA;AAGtC,EAAA,MAAA,CAAO,GAAA,CAAI,WAAA,EAAaC,6BAAA,CAAe,OAAO,CAAC,CAAA;AAC/C,EAAA,MAAA,CAAO,GAAA,CAAI,WAAA,EAAaC,6BAAA,CAAe,OAAO,CAAC,CAAA;AAC/C,EAAA,MAAA,CAAO,GAAA,CAAI,QAAA,EAAUC,uBAAA,CAAY,OAAO,CAAC,CAAA;AACzC,EAAA,MAAA,CAAO,GAAA,CAAI,cAAA,EAAgBC,2CAAA,CAAsB,OAAO,CAAC,CAAA;AAGzD,EAAA,MAAM,aAAaC,gCAAA,CAAkB,MAAA,CAAO,EAAE,MAAA,EAAQ,QAAQ,CAAA;AAC9D,EAAA,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,KAAA,EAAO,CAAA;AAE7B,EAAA,OAAO,MAAA;AACT;;;;"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const featureLink = (id) => `/roadmap?feature=${encodeURIComponent(id)}`;
|
|
4
|
+
const displayName = (ref) => ref.split("/").pop() ?? ref;
|
|
5
|
+
class RoadmapNotificationService {
|
|
6
|
+
constructor(notifications, logger, adminUsers) {
|
|
7
|
+
this.notifications = notifications;
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
this.adminUsers = adminUsers;
|
|
10
|
+
}
|
|
11
|
+
notifications;
|
|
12
|
+
logger;
|
|
13
|
+
adminUsers;
|
|
14
|
+
/** New feature suggested: notify configured admins, excluding the author. */
|
|
15
|
+
notifyFeatureCreated(feature, actor) {
|
|
16
|
+
const recipients = this.adminUsers.filter((ref) => ref !== actor);
|
|
17
|
+
if (recipients.length === 0) {
|
|
18
|
+
this.logger.debug(
|
|
19
|
+
"No roadmap.adminUsers configured; skipping new-feature notification"
|
|
20
|
+
);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this.send({
|
|
24
|
+
recipients: { type: "entity", entityRef: recipients },
|
|
25
|
+
payload: {
|
|
26
|
+
title: `New roadmap suggestion: ${feature.title}`,
|
|
27
|
+
description: `${displayName(
|
|
28
|
+
actor
|
|
29
|
+
)} suggested a new feature for the roadmap.`,
|
|
30
|
+
link: featureLink(feature.id),
|
|
31
|
+
topic: "new-features"
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Status changed: notify the feature author, unless they made the change. */
|
|
36
|
+
notifyStatusChanged(feature, previousStatus, actor) {
|
|
37
|
+
if (!feature.author || feature.author === actor) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.send({
|
|
41
|
+
recipients: { type: "entity", entityRef: feature.author },
|
|
42
|
+
payload: {
|
|
43
|
+
title: `Your roadmap suggestion moved to ${feature.status}`,
|
|
44
|
+
description: `"${feature.title}" changed from ${previousStatus} to ${feature.status}.`,
|
|
45
|
+
link: featureLink(feature.id),
|
|
46
|
+
topic: "status-changes"
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** New comment: notify the feature author, unless they wrote it. */
|
|
51
|
+
notifyCommentAdded(feature, commenter) {
|
|
52
|
+
if (!feature.author || feature.author === commenter) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this.send({
|
|
56
|
+
recipients: { type: "entity", entityRef: feature.author },
|
|
57
|
+
payload: {
|
|
58
|
+
title: `New comment on "${feature.title}"`,
|
|
59
|
+
description: `${displayName(
|
|
60
|
+
commenter
|
|
61
|
+
)} commented on your roadmap suggestion.`,
|
|
62
|
+
link: featureLink(feature.id),
|
|
63
|
+
topic: "comments"
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
send(options) {
|
|
68
|
+
this.notifications.send(options).catch((error) => {
|
|
69
|
+
this.logger.warn(`Failed to send roadmap notification: ${error}`);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.RoadmapNotificationService = RoadmapNotificationService;
|
|
75
|
+
//# sourceMappingURL=RoadmapNotificationService.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoadmapNotificationService.cjs.js","sources":["../../src/services/RoadmapNotificationService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { NotificationService } from '@backstage/plugin-notifications-node';\nimport { Feature } from '@rothenbergt/backstage-plugin-roadmap-common';\n\nconst featureLink = (id: string) =>\n `/roadmap?feature=${encodeURIComponent(id)}`;\n\n/** Short human-readable name from a user entity ref like `user:default/jdoe`. */\nconst displayName = (ref: string) => ref.split('/').pop() ?? ref;\n\n/**\n * Sends roadmap notifications through the Backstage notifications service.\n *\n * Every send is fire-and-forget: failures are logged and never propagate to\n * the request that triggered them, so the roadmap works with or without the\n * notifications backend installed.\n *\n * Topics (`new-features`, `status-changes`, `comments`) give users per-topic\n * toggles in Backstage's built-in notification settings.\n */\nexport class RoadmapNotificationService {\n constructor(\n private readonly notifications: NotificationService,\n private readonly logger: LoggerService,\n private readonly adminUsers: string[],\n ) {}\n\n /** New feature suggested: notify configured admins, excluding the author. */\n notifyFeatureCreated(feature: Feature, actor: string): void {\n const recipients = this.adminUsers.filter(ref => ref !== actor);\n if (recipients.length === 0) {\n // The permission framework is a decision API and cannot enumerate which\n // users hold roadmap.admin, so recipients always come from\n // roadmap.adminUsers (user or group refs), even in framework mode.\n this.logger.debug(\n 'No roadmap.adminUsers configured; skipping new-feature notification',\n );\n return;\n }\n this.send({\n recipients: { type: 'entity', entityRef: recipients },\n payload: {\n title: `New roadmap suggestion: ${feature.title}`,\n description: `${displayName(\n actor,\n )} suggested a new feature for the roadmap.`,\n link: featureLink(feature.id),\n topic: 'new-features',\n },\n });\n }\n\n /** Status changed: notify the feature author, unless they made the change. */\n notifyStatusChanged(\n feature: Feature,\n previousStatus: string,\n actor: string,\n ): void {\n if (!feature.author || feature.author === actor) {\n return;\n }\n this.send({\n recipients: { type: 'entity', entityRef: feature.author },\n payload: {\n title: `Your roadmap suggestion moved to ${feature.status}`,\n description: `\"${feature.title}\" changed from ${previousStatus} to ${feature.status}.`,\n link: featureLink(feature.id),\n topic: 'status-changes',\n },\n });\n }\n\n /** New comment: notify the feature author, unless they wrote it. */\n notifyCommentAdded(feature: Feature, commenter: string): void {\n if (!feature.author || feature.author === commenter) {\n return;\n }\n this.send({\n recipients: { type: 'entity', entityRef: feature.author },\n payload: {\n title: `New comment on \"${feature.title}\"`,\n description: `${displayName(\n commenter,\n )} commented on your roadmap suggestion.`,\n link: featureLink(feature.id),\n topic: 'comments',\n },\n });\n }\n\n private send(options: Parameters<NotificationService['send']>[0]): void {\n this.notifications.send(options).catch(error => {\n this.logger.warn(`Failed to send roadmap notification: ${error}`);\n });\n }\n}\n"],"names":[],"mappings":";;AAIA,MAAM,cAAc,CAAC,EAAA,KACnB,CAAA,iBAAA,EAAoB,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAA;AAG5C,MAAM,WAAA,GAAc,CAAC,GAAA,KAAgB,GAAA,CAAI,MAAM,GAAG,CAAA,CAAE,KAAI,IAAK,GAAA;AAYtD,MAAM,0BAAA,CAA2B;AAAA,EACtC,WAAA,CACmB,aAAA,EACA,MAAA,EACA,UAAA,EACjB;AAHiB,IAAA,IAAA,CAAA,aAAA,GAAA,aAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAChB;AAAA,EAHgB,aAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA;AAAA,EAInB,oBAAA,CAAqB,SAAkB,KAAA,EAAqB;AAC1D,IAAA,MAAM,aAAa,IAAA,CAAK,UAAA,CAAW,MAAA,CAAO,CAAA,GAAA,KAAO,QAAQ,KAAK,CAAA;AAC9D,IAAA,IAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AAI3B,MAAA,IAAA,CAAK,MAAA,CAAO,KAAA;AAAA,QACV;AAAA,OACF;AACA,MAAA;AAAA,IACF;AACA,IAAA,IAAA,CAAK,IAAA,CAAK;AAAA,MACR,UAAA,EAAY,EAAE,IAAA,EAAM,QAAA,EAAU,WAAW,UAAA,EAAW;AAAA,MACpD,OAAA,EAAS;AAAA,QACP,KAAA,EAAO,CAAA,wBAAA,EAA2B,OAAA,CAAQ,KAAK,CAAA,CAAA;AAAA,QAC/C,aAAa,CAAA,EAAG,WAAA;AAAA,UACd;AAAA,SACD,CAAA,yCAAA,CAAA;AAAA,QACD,IAAA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AC5B,KAAA,EAAO;AAAA;AACT,KACD,CAAA;AAAA,EACH;AAAA,EAEQ,KAAK,OAAA,EAA2D;AACtE,IAAA,IAAA,CAAK,aAAA,CAAc,IAAA,CAAK,OAAO,CAAA,CAAE,MAAM,CAAA,KAAA,KAAS;AAC9C,MAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,CAAA,qCAAA,EAAwC,KAAK,CAAA,CAAE,CAAA;AAAA,IAClE,CAAC,CAAA;AAAA,EACH;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rothenbergt/backstage-plugin-roadmap-backend",
|
|
3
3
|
"description": "Backstage Roadmap plugin backend",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@backstage/catalog-model": "^1.9.0",
|
|
38
38
|
"@backstage/config": "^1.3.8",
|
|
39
39
|
"@backstage/errors": "^1.3.1",
|
|
40
|
+
"@backstage/plugin-notifications-node": "^0.2.27",
|
|
40
41
|
"@backstage/plugin-permission-common": "^0.9.9",
|
|
41
42
|
"@backstage/plugin-permission-node": "^0.11.1",
|
|
42
43
|
"@rothenbergt/backstage-plugin-roadmap-common": "^0.4.1",
|
|
@@ -49,17 +50,24 @@
|
|
|
49
50
|
"@backstage/cli": "^0.36.3",
|
|
50
51
|
"@backstage/plugin-auth-backend": "^0.29.1",
|
|
51
52
|
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.20",
|
|
53
|
+
"@backstage/plugin-catalog-backend": "^3.8.0",
|
|
54
|
+
"@backstage/plugin-notifications-backend": "^0.6.6",
|
|
52
55
|
"@backstage/plugin-permission-backend": "^0.7.2",
|
|
53
56
|
"@backstage/plugin-permission-backend-module-allow-all-policy": "^0.2.10",
|
|
57
|
+
"@backstage/plugin-search-backend": "^2.1.3",
|
|
58
|
+
"@backstage/plugin-signals-backend": "^0.3.16",
|
|
59
|
+
"@rothenbergt/backstage-plugin-search-backend-module-roadmap": "^0.2.0",
|
|
54
60
|
"@types/express": "*",
|
|
55
61
|
"@types/supertest": "^2.0.12",
|
|
56
62
|
"better-sqlite3": "^12.0.0",
|
|
57
63
|
"msw": "^2.3.1",
|
|
58
64
|
"supertest": "^6.2.4"
|
|
59
65
|
},
|
|
66
|
+
"configSchema": "config.d.ts",
|
|
60
67
|
"files": [
|
|
61
68
|
"dist",
|
|
62
|
-
"migrations"
|
|
69
|
+
"migrations",
|
|
70
|
+
"config.d.ts"
|
|
63
71
|
],
|
|
64
72
|
"typesVersions": {
|
|
65
73
|
"*": {
|