@rothenbergt/backstage-plugin-roadmap-backend 0.5.0 → 0.6.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.
@@ -2,15 +2,26 @@
2
2
 
3
3
  var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
4
4
  var errors = require('@backstage/errors');
5
+ var featureBoardFilter = require('./featureBoardFilter.cjs.js');
6
+ var RoadmapDatabaseClient = require('../database/RoadmapDatabaseClient.cjs.js');
5
7
 
6
8
  class FeatureService {
7
- constructor(db, logger) {
9
+ constructor(db, logger, boardColumns, datasource) {
8
10
  this.db = db;
9
11
  this.logger = logger;
12
+ this.boardColumns = boardColumns;
13
+ this.datasource = datasource;
10
14
  }
11
- /**
12
- * Validates a feature before adding it
13
- */
15
+ /** Ensures we are on the Knex-backed datasource before DB-only operations. */
16
+ requireDatabase() {
17
+ if (this.datasource !== "database" || !(this.db instanceof RoadmapDatabaseClient.RoadmapDatabaseClient)) {
18
+ throw new errors.NotAllowedError(
19
+ "This operation is not supported for the GitLab roadmap datasource"
20
+ );
21
+ }
22
+ return this.db;
23
+ }
24
+ /** Rules for creating a suggestion from the API. */
14
25
  validateNewFeature(feature) {
15
26
  if (!feature.title || feature.title.trim() === "") {
16
27
  throw new errors.InputError("Title is required and cannot be empty");
@@ -22,9 +33,7 @@ class FeatureService {
22
33
  throw new errors.InputError("Title cannot be longer than 100 characters");
23
34
  }
24
35
  }
25
- /**
26
- * Validates a feature status before updating
27
- */
36
+ /** Ensures status values match the shared enum (used by status changes and reorder). */
28
37
  validateStatus(status) {
29
38
  const validStatuses = Object.values(backstagePluginRoadmapCommon.FeatureStatus);
30
39
  if (!validStatuses.includes(status)) {
@@ -35,24 +44,90 @@ class FeatureService {
35
44
  );
36
45
  }
37
46
  }
47
+ /**
48
+ * Primary list for the board: applies column visibility and, for the database
49
+ * datasource, per-column retention unless `includeBeyondRetention` is true.
50
+ */
51
+ async listFeaturesForBoard(includeBeyondRetention) {
52
+ this.logger.info("Fetching roadmap features for board list");
53
+ const raw = await this.db.getAllFeatures();
54
+ return featureBoardFilter.filterFeaturesForBoardList(raw, this.boardColumns, {
55
+ includeBeyondRetention,
56
+ datasource: this.datasource
57
+ });
58
+ }
59
+ /** Same as the board list with default retention filtering (backward compatible name). */
38
60
  async getAllFeatures() {
39
- this.logger.info("Fetching all features");
40
- return this.db.getAllFeatures();
61
+ return this.listFeaturesForBoard(false);
41
62
  }
42
63
  async getFeatureById(id) {
43
64
  this.logger.info(`Fetching feature with id ${id}`);
44
65
  return this.db.getFeatureById(id);
45
66
  }
67
+ /** Creates a new feature in Suggested status with the given author ref. */
46
68
  async addFeature(feature, author) {
47
69
  this.logger.info(`Adding new feature: ${feature.title} by ${author}`);
48
70
  this.validateNewFeature(feature);
49
71
  return this.db.addFeature({ ...feature, author });
50
72
  }
73
+ /**
74
+ * Admin workflow: change status. Supported for both database and GitLab
75
+ * (GitLab implementation updates labels on the issue).
76
+ */
51
77
  async updateFeatureStatus(id, status) {
52
78
  this.logger.info(`Updating feature ${id} status to ${status}`);
53
79
  this.validateStatus(status);
54
80
  return this.db.updateFeatureStatus(id, status);
55
81
  }
82
+ /**
83
+ * Database only. Router decides admin vs author-on-Suggested; this layer only validates fields.
84
+ */
85
+ async updateFeatureDetails(id, fields) {
86
+ const client = this.requireDatabase();
87
+ if (fields.title !== void 0) {
88
+ if (!fields.title.trim()) {
89
+ throw new errors.InputError("Title cannot be empty");
90
+ }
91
+ if (fields.title.length > 100) {
92
+ throw new errors.InputError("Title cannot be longer than 100 characters");
93
+ }
94
+ }
95
+ if (fields.description !== void 0 && !fields.description.trim()) {
96
+ throw new errors.InputError("Description cannot be empty");
97
+ }
98
+ return client.updateFeatureDetails(id, fields);
99
+ }
100
+ /** Database only: hard-delete feature row (and FK-cascaded comments/votes). */
101
+ async deleteFeature(id) {
102
+ const client = this.requireDatabase();
103
+ await client.deleteFeature(id);
104
+ }
105
+ /**
106
+ * Database only: persist admin drag-and-drop order within a single status column.
107
+ */
108
+ async reorderFeatures(status, orderedIds) {
109
+ this.validateStatus(status);
110
+ const client = this.requireDatabase();
111
+ await client.reorderFeaturesInStatus(status, orderedIds);
112
+ }
113
+ /**
114
+ * Non-admin edit/delete path: loads the feature and ensures it is Suggested
115
+ * and owned by `username`; otherwise throws NotAllowed. Missing ids surface as NotFound from the datasource.
116
+ */
117
+ async assertAuthorSuggestedOrNotFound(id, username) {
118
+ const feature = await this.db.getFeatureById(id);
119
+ if (feature.status !== backstagePluginRoadmapCommon.FeatureStatus.Suggested) {
120
+ throw new errors.NotAllowedError(
121
+ "Only suggested features can be edited by the author"
122
+ );
123
+ }
124
+ if (feature.author !== username) {
125
+ throw new errors.NotAllowedError(
126
+ "You can only edit your own suggested features"
127
+ );
128
+ }
129
+ return feature;
130
+ }
56
131
  }
57
132
 
58
133
  exports.FeatureService = FeatureService;
@@ -1 +1 @@
1
- {"version":3,"file":"FeatureService.cjs.js","sources":["../../src/services/FeatureService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatasource } from '../types';\nimport { FeatureServiceInterface } from './types';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Implementation of the Feature Service\n */\nexport class FeatureService implements FeatureServiceInterface {\n constructor(\n private readonly db: RoadmapDatasource,\n private readonly logger: LoggerService,\n ) {}\n\n /**\n * Validates a feature before adding it\n */\n private validateNewFeature(feature: NewFeature): void {\n if (!feature.title || feature.title.trim() === '') {\n throw new InputError('Title is required and cannot be empty');\n }\n\n if (!feature.description || feature.description.trim() === '') {\n throw new InputError('Description is required and cannot be empty');\n }\n\n if (feature.title.length > 100) {\n throw new InputError('Title cannot be longer than 100 characters');\n }\n }\n\n /**\n * Validates a feature status before updating\n */\n private validateStatus(status: FeatureStatus): void {\n const validStatuses = Object.values(FeatureStatus);\n if (!validStatuses.includes(status)) {\n throw new InputError(\n `Invalid status: ${status}. Must be one of: ${validStatuses.join(\n ', ',\n )}`,\n );\n }\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n this.logger.info('Fetching all features');\n return this.db.getAllFeatures();\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n this.logger.info(`Fetching feature with id ${id}`);\n return this.db.getFeatureById(id);\n }\n\n async addFeature(feature: NewFeature, author: string): Promise<Feature> {\n this.logger.info(`Adding new feature: ${feature.title} by ${author}`);\n this.validateNewFeature(feature);\n return this.db.addFeature({ ...feature, author });\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n this.logger.info(`Updating feature ${id} status to ${status}`);\n this.validateStatus(status);\n return this.db.updateFeatureStatus(id, status);\n }\n}\n"],"names":["InputError","FeatureStatus"],"mappings":";;;;;AAaO,MAAM,cAAkD,CAAA;AAAA,EAC7D,WAAA,CACmB,IACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAChB;AAAA;AAAA;AAAA,EAKK,mBAAmB,OAA2B,EAAA;AACpD,IAAA,IAAI,CAAC,OAAQ,CAAA,KAAA,IAAS,QAAQ,KAAM,CAAA,IAAA,OAAW,EAAI,EAAA;AACjD,MAAM,MAAA,IAAIA,kBAAW,uCAAuC,CAAA;AAAA;AAG9D,IAAA,IAAI,CAAC,OAAQ,CAAA,WAAA,IAAe,QAAQ,WAAY,CAAA,IAAA,OAAW,EAAI,EAAA;AAC7D,MAAM,MAAA,IAAIA,kBAAW,6CAA6C,CAAA;AAAA;AAGpE,IAAI,IAAA,OAAA,CAAQ,KAAM,CAAA,MAAA,GAAS,GAAK,EAAA;AAC9B,MAAM,MAAA,IAAIA,kBAAW,4CAA4C,CAAA;AAAA;AACnE;AACF;AAAA;AAAA;AAAA,EAKQ,eAAe,MAA6B,EAAA;AAClD,IAAM,MAAA,aAA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;;"}
1
+ {"version":3,"file":"FeatureService.cjs.js","sources":["../../src/services/FeatureService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatasource } from '../types';\nimport { DatasourceType } from '../types';\nimport { FeatureServiceInterface } from './types';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n RoadmapBoardColumnResolved,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { InputError, NotAllowedError } from '@backstage/errors';\nimport { filterFeaturesForBoardList } from './featureBoardFilter';\nimport { RoadmapDatabaseClient } from '../database/RoadmapDatabaseClient';\n\n/**\n * Feature business logic: validation, board list filtering (visibility + retention),\n * and database-only writes. GitLab mutations that are not supported stay in the router.\n */\nexport class FeatureService implements FeatureServiceInterface {\n constructor(\n private readonly db: RoadmapDatasource,\n private readonly logger: LoggerService,\n private readonly boardColumns: RoadmapBoardColumnResolved[],\n private readonly datasource: DatasourceType,\n ) {}\n\n /** Ensures we are on the Knex-backed datasource before DB-only operations. */\n private requireDatabase(): RoadmapDatabaseClient {\n if (\n this.datasource !== 'database' ||\n !(this.db instanceof RoadmapDatabaseClient)\n ) {\n throw new NotAllowedError(\n 'This operation is not supported for the GitLab roadmap datasource',\n );\n }\n return this.db;\n }\n\n /** Rules for creating a suggestion from the API. */\n private validateNewFeature(feature: NewFeature): void {\n if (!feature.title || feature.title.trim() === '') {\n throw new InputError('Title is required and cannot be empty');\n }\n\n if (!feature.description || feature.description.trim() === '') {\n throw new InputError('Description is required and cannot be empty');\n }\n\n if (feature.title.length > 100) {\n throw new InputError('Title cannot be longer than 100 characters');\n }\n }\n\n /** Ensures status values match the shared enum (used by status changes and reorder). */\n private validateStatus(status: FeatureStatus): void {\n const validStatuses = Object.values(FeatureStatus);\n if (!validStatuses.includes(status)) {\n throw new InputError(\n `Invalid status: ${status}. Must be one of: ${validStatuses.join(\n ', ',\n )}`,\n );\n }\n }\n\n /**\n * Primary list for the board: applies column visibility and, for the database\n * datasource, per-column retention unless `includeBeyondRetention` is true.\n */\n async listFeaturesForBoard(\n includeBeyondRetention: boolean,\n ): Promise<Feature[]> {\n this.logger.info('Fetching roadmap features for board list');\n const raw = await this.db.getAllFeatures();\n return filterFeaturesForBoardList(raw, this.boardColumns, {\n includeBeyondRetention,\n datasource: this.datasource,\n });\n }\n\n /** Same as the board list with default retention filtering (backward compatible name). */\n async getAllFeatures(): Promise<Feature[]> {\n return this.listFeaturesForBoard(false);\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n this.logger.info(`Fetching feature with id ${id}`);\n return this.db.getFeatureById(id);\n }\n\n /** Creates a new feature in Suggested status with the given author ref. */\n async addFeature(feature: NewFeature, author: string): Promise<Feature> {\n this.logger.info(`Adding new feature: ${feature.title} by ${author}`);\n this.validateNewFeature(feature);\n return this.db.addFeature({ ...feature, author });\n }\n\n /**\n * Admin workflow: change status. Supported for both database and GitLab\n * (GitLab implementation updates labels on the issue).\n */\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n this.logger.info(`Updating feature ${id} status to ${status}`);\n this.validateStatus(status);\n return this.db.updateFeatureStatus(id, status);\n }\n\n /**\n * Database only. Router decides admin vs author-on-Suggested; this layer only validates fields.\n */\n async updateFeatureDetails(\n id: string,\n fields: { title?: string; description?: string },\n ): Promise<Feature> {\n const client = this.requireDatabase();\n if (fields.title !== undefined) {\n if (!fields.title.trim()) {\n throw new InputError('Title cannot be empty');\n }\n if (fields.title.length > 100) {\n throw new InputError('Title cannot be longer than 100 characters');\n }\n }\n if (fields.description !== undefined && !fields.description.trim()) {\n throw new InputError('Description cannot be empty');\n }\n return client.updateFeatureDetails(id, fields);\n }\n\n /** Database only: hard-delete feature row (and FK-cascaded comments/votes). */\n async deleteFeature(id: string): Promise<void> {\n const client = this.requireDatabase();\n await client.deleteFeature(id);\n }\n\n /**\n * Database only: persist admin drag-and-drop order within a single status column.\n */\n async reorderFeatures(\n status: FeatureStatus,\n orderedIds: string[],\n ): Promise<void> {\n this.validateStatus(status);\n const client = this.requireDatabase();\n await client.reorderFeaturesInStatus(status, orderedIds);\n }\n\n /**\n * Non-admin edit/delete path: loads the feature and ensures it is Suggested\n * and owned by `username`; otherwise throws NotAllowed. Missing ids surface as NotFound from the datasource.\n */\n async assertAuthorSuggestedOrNotFound(\n id: string,\n username: string,\n ): Promise<Feature> {\n const feature = await this.db.getFeatureById(id);\n if (feature.status !== FeatureStatus.Suggested) {\n throw new NotAllowedError(\n 'Only suggested features can be edited by the author',\n );\n }\n if (feature.author !== username) {\n throw new NotAllowedError(\n 'You can only edit your own suggested features',\n );\n }\n return feature;\n }\n}\n"],"names":["RoadmapDatabaseClient","NotAllowedError","InputError","FeatureStatus","filterFeaturesForBoardList"],"mappings":";;;;;;;AAkBO,MAAM,cAAkD,CAAA;AAAA,EAC7D,WACmB,CAAA,EAAA,EACA,MACA,EAAA,YAAA,EACA,UACjB,EAAA;AAJiB,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA;AACA,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA;AAChB;AAAA,EAGK,eAAyC,GAAA;AAC/C,IAAA,IACE,KAAK,UAAe,KAAA,UAAA,IACpB,EAAE,IAAA,CAAK,cAAcA,2CACrB,CAAA,EAAA;AACA,MAAA,MAAM,IAAIC,sBAAA;AAAA,QACR;AAAA,OACF;AAAA;AAEF,IAAA,OAAO,IAAK,CAAA,EAAA;AAAA;AACd;AAAA,EAGQ,mBAAmB,OAA2B,EAAA;AACpD,IAAA,IAAI,CAAC,OAAQ,CAAA,KAAA,IAAS,QAAQ,KAAM,CAAA,IAAA,OAAW,EAAI,EAAA;AACjD,MAAM,MAAA,IAAIC,kBAAW,uCAAuC,CAAA;AAAA;AAG9D,IAAA,IAAI,CAAC,OAAQ,CAAA,WAAA,IAAe,QAAQ,WAAY,CAAA,IAAA,OAAW,EAAI,EAAA;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A;AAC7C,IAAM,MAAA,MAAA,GAAS,KAAK,eAAgB,EAAA;AACpC,IAAM,MAAA,MAAA,CAAO,cAAc,EAAE,CAAA;AAAA;AAC/B;AAAA;AAAA;AAAA,EAKA,MAAM,eACJ,CAAA,MAAA,EACA,UACe,EAAA;AACf,IAAA,IAAA,CAAK,eAAe,MAAM,CAAA;AAC1B,IAAM,MAAA,MAAA,GAAS,KAAK,eAAgB,EAAA;AACpC,IAAM,MAAA,MAAA,CAAO,uBAAwB,CAAA,MAAA,EAAQ,UAAU,CAAA;AAAA;AACzD;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,+BACJ,CAAA,EAAA,EACA,QACkB,EAAA;AAClB,IAAA,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,EAAA,CAAG,eAAe,EAAE,CAAA;AAC/C,IAAI,IAAA,OAAA,CAAQ,MAAW,KAAAC,0CAAA,CAAc,SAAW,EAAA;AAC9C,MAAA,MAAM,IAAIF,sBAAA;AAAA,QACR;AAAA,OACF;AAAA;AAEF,IAAI,IAAA,OAAA,CAAQ,WAAW,QAAU,EAAA;AAC/B,MAAA,MAAM,IAAIA,sBAAA;AAAA,QACR;AAAA,OACF;AAAA;AAEF,IAAO,OAAA,OAAA;AAAA;AAEX;;;;"}
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ function parseFeatureDate(value) {
4
+ const t = Date.parse(value);
5
+ return Number.isNaN(t) ? 0 : t;
6
+ }
7
+ function retentionCutoffMs(days) {
8
+ return Date.now() - days * 24 * 60 * 60 * 1e3;
9
+ }
10
+ function columnForStatus(columns, status) {
11
+ return columns.find((c) => c.status === status);
12
+ }
13
+ function filterFeaturesForBoardList(features, columns, options) {
14
+ return features.filter((feature) => {
15
+ const col = columnForStatus(columns, feature.status);
16
+ if (!col || !col.visible) {
17
+ return false;
18
+ }
19
+ if (options.datasource !== "database") {
20
+ return true;
21
+ }
22
+ if (options.includeBeyondRetention) {
23
+ return true;
24
+ }
25
+ const days = col.retentionDays;
26
+ if (!days || days <= 0) {
27
+ return true;
28
+ }
29
+ const anchor = col.retentionAnchor === "created" ? feature.created_at : feature.updated_at;
30
+ const ts = parseFeatureDate(anchor);
31
+ return ts >= retentionCutoffMs(days);
32
+ });
33
+ }
34
+
35
+ exports.filterFeaturesForBoardList = filterFeaturesForBoardList;
36
+ //# sourceMappingURL=featureBoardFilter.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"featureBoardFilter.cjs.js","sources":["../../src/services/featureBoardFilter.ts"],"sourcesContent":["import {\n Feature,\n FeatureStatus,\n RoadmapBoardColumnResolved,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { DatasourceType } from '../types';\n\nfunction parseFeatureDate(value: string): number {\n const t = Date.parse(value);\n return Number.isNaN(t) ? 0 : t;\n}\n\nfunction retentionCutoffMs(days: number): number {\n return Date.now() - days * 24 * 60 * 60 * 1000;\n}\n\nfunction columnForStatus(\n columns: RoadmapBoardColumnResolved[],\n status: FeatureStatus,\n): RoadmapBoardColumnResolved | undefined {\n return columns.find(c => c.status === status);\n}\n\n/**\n * Filters features for the roadmap board list: hidden columns and (database only) retention.\n */\nexport function filterFeaturesForBoardList(\n features: Feature[],\n columns: RoadmapBoardColumnResolved[],\n options: {\n includeBeyondRetention: boolean;\n datasource: DatasourceType;\n },\n): Feature[] {\n return features.filter(feature => {\n const col = columnForStatus(columns, feature.status);\n if (!col || !col.visible) {\n return false;\n }\n if (options.datasource !== 'database') {\n return true;\n }\n if (options.includeBeyondRetention) {\n return true;\n }\n const days = col.retentionDays;\n if (!days || days <= 0) {\n return true;\n }\n const anchor =\n col.retentionAnchor === 'created'\n ? feature.created_at\n : feature.updated_at;\n const ts = parseFeatureDate(anchor);\n return ts >= retentionCutoffMs(days);\n });\n}\n"],"names":[],"mappings":";;AAOA,SAAS,iBAAiB,KAAuB,EAAA;AAC/C,EAAM,MAAA,CAAA,GAAI,IAAK,CAAA,KAAA,CAAM,KAAK,CAAA;AAC1B,EA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ex.schema.alterTable('features', table => {
6
+ table.integer('board_position').notNullable().defaultTo(0);
7
+ });
8
+ };
9
+
10
+ /**
11
+ * @param {import('knex').Knex} knex
12
+ */
13
+ exports.down = async function down(knex) {
14
+ await knex.schema.alterTable('features', table => {
15
+ table.dropColumn('board_position');
16
+ });
17
+ };
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.5.0",
4
+ "version": "0.6.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -39,7 +39,7 @@
39
39
  "@backstage/errors": "^1.2.7",
40
40
  "@backstage/plugin-permission-common": "^0.9.6",
41
41
  "@backstage/plugin-permission-node": "^0.10.10",
42
- "@rothenbergt/backstage-plugin-roadmap-common": "^0.3.0",
42
+ "@rothenbergt/backstage-plugin-roadmap-common": "^0.4.0",
43
43
  "express": "^4.17.1",
44
44
  "express-promise-router": "^4.1.0",
45
45
  "knex": "^3.1.0"
@@ -51,6 +51,7 @@
51
51
  "@backstage/plugin-auth-backend-module-guest-provider": "^0.2.16",
52
52
  "@types/express": "*",
53
53
  "@types/supertest": "^2.0.12",
54
+ "better-sqlite3": "^12.0.0",
54
55
  "msw": "^2.3.1",
55
56
  "supertest": "^6.2.4"
56
57
  },