@rothenbergt/backstage-plugin-roadmap-backend 0.6.0 → 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/boardConfig.cjs.js.map +1 -1
- package/dist/config.cjs.js.map +1 -1
- package/dist/database/RoadmapDatabaseClient.cjs.js.map +1 -1
- package/dist/database/statusDbMapping.cjs.js.map +1 -1
- package/dist/gitlab/RoadmapGitlabClient.cjs.js.map +1 -1
- 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/permissionCheckRouter.cjs.js.map +1 -1
- package/dist/routes/router.cjs.js.map +1 -1
- package/dist/routes/votesRouter.cjs.js.map +1 -1
- package/dist/services/CommentService.cjs.js +3 -0
- package/dist/services/CommentService.cjs.js.map +1 -1
- package/dist/services/FeatureService.cjs.js +4 -0
- package/dist/services/FeatureService.cjs.js.map +1 -1
- package/dist/services/PermissionService.cjs.js.map +1 -1
- package/dist/services/RoadmapNotificationService.cjs.js +75 -0
- package/dist/services/RoadmapNotificationService.cjs.js.map +1 -0
- package/dist/services/VoteService.cjs.js +2 -0
- package/dist/services/VoteService.cjs.js.map +1 -1
- package/dist/services/featureBoardFilter.cjs.js.map +1 -1
- package/package.json +24 -14
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
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boardConfig.cjs.js","sources":["../src/boardConfig.ts"],"sourcesContent":["import { Config } from '@backstage/config';\nimport {\n FeatureStatus,\n RoadmapBoardColumnResolved,\n RoadmapRetentionAnchor,\n RoadmapBoardConfigResponse,\n RoadmapUiCapabilities,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { DatasourceType } from './types';\n\nconst ALL_STATUSES = Object.values(FeatureStatus);\n\nfunction defaultTitle(status: FeatureStatus): string {\n return status;\n}\n\nfunction buildDefaultColumns(): RoadmapBoardColumnResolved[] {\n return ALL_STATUSES.map(status => ({\n status,\n title: defaultTitle(status),\n visible: status === FeatureStatus.InProgress ? false : true,\n retentionAnchor: 'updated' as RoadmapRetentionAnchor,\n }));\n}\n\nfunction parseAnchor(v: string | undefined): RoadmapRetentionAnchor {\n if (v === 'created' || v === 'updated') return v;\n return 'updated';\n}\n\n/**\n * Reads optional `roadmap.columns` from config and merges with defaults.\n * Default: In Progress column exists but `visible: false`.\n */\nexport function getMergedBoardColumns(\n config: Config,\n): RoadmapBoardColumnResolved[] {\n const defaults = buildDefaultColumns();\n const roadmap = config.getOptionalConfig('roadmap');\n const entries = roadmap?.getOptionalConfigArray('columns');\n if (!entries?.length) {\n return defaults;\n }\n\n const byStatus = new Map<FeatureStatus, RoadmapBoardColumnResolved>(\n defaults.map(c => [c.status, { ...c }]),\n );\n\n for (const entry of entries) {\n const statusStr = entry.getOptionalString('status');\n if (!statusStr || !ALL_STATUSES.includes(statusStr as FeatureStatus)) {\n continue;\n }\n const status = statusStr as FeatureStatus;\n const existing = byStatus.get(status)!;\n const title = entry.getOptionalString('title') ?? existing.title;\n const visible = entry.getOptionalBoolean('visible') ?? existing.visible;\n const retentionDays = entry.getOptionalNumber('retentionDays');\n const retentionAnchor = parseAnchor(\n entry.getOptionalString('retentionAnchor'),\n );\n byStatus.set(status, {\n status,\n title,\n visible,\n retentionDays:\n retentionDays !== undefined && retentionDays > 0\n ? retentionDays\n : undefined,\n retentionAnchor,\n });\n }\n\n return ALL_STATUSES.map(s => byStatus.get(s)!);\n}\n\nexport function getRoadmapUiCapabilities(\n datasource: DatasourceType,\n): RoadmapUiCapabilities {\n if (datasource === 'gitlab') {\n return {\n retentionFiltering: false,\n includeBeyondRetentionQuery: false,\n adminEditTitleDescription: false,\n adminDeleteFeature: false,\n adminDeleteComment: false,\n creatorEditDeleteSuggested: false,\n adminReorder: false,\n };\n }\n return {\n retentionFiltering: true,\n includeBeyondRetentionQuery: true,\n adminEditTitleDescription: true,\n adminDeleteFeature: true,\n adminDeleteComment: true,\n creatorEditDeleteSuggested: true,\n adminReorder: true,\n };\n}\n\nexport function getBoardConfigResponse(\n config: Config,\n datasource: DatasourceType,\n): RoadmapBoardConfigResponse {\n return {\n columns: getMergedBoardColumns(config),\n capabilities: getRoadmapUiCapabilities(datasource),\n };\n}\n"],"names":["FeatureStatus"],"mappings":";;;;AAUA,MAAM,YAAA,GAAe,
|
|
1
|
+
{"version":3,"file":"boardConfig.cjs.js","sources":["../src/boardConfig.ts"],"sourcesContent":["import { Config } from '@backstage/config';\nimport {\n FeatureStatus,\n RoadmapBoardColumnResolved,\n RoadmapRetentionAnchor,\n RoadmapBoardConfigResponse,\n RoadmapUiCapabilities,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { DatasourceType } from './types';\n\nconst ALL_STATUSES = Object.values(FeatureStatus);\n\nfunction defaultTitle(status: FeatureStatus): string {\n return status;\n}\n\nfunction buildDefaultColumns(): RoadmapBoardColumnResolved[] {\n return ALL_STATUSES.map(status => ({\n status,\n title: defaultTitle(status),\n visible: status === FeatureStatus.InProgress ? false : true,\n retentionAnchor: 'updated' as RoadmapRetentionAnchor,\n }));\n}\n\nfunction parseAnchor(v: string | undefined): RoadmapRetentionAnchor {\n if (v === 'created' || v === 'updated') return v;\n return 'updated';\n}\n\n/**\n * Reads optional `roadmap.columns` from config and merges with defaults.\n * Default: In Progress column exists but `visible: false`.\n */\nexport function getMergedBoardColumns(\n config: Config,\n): RoadmapBoardColumnResolved[] {\n const defaults = buildDefaultColumns();\n const roadmap = config.getOptionalConfig('roadmap');\n const entries = roadmap?.getOptionalConfigArray('columns');\n if (!entries?.length) {\n return defaults;\n }\n\n const byStatus = new Map<FeatureStatus, RoadmapBoardColumnResolved>(\n defaults.map(c => [c.status, { ...c }]),\n );\n\n for (const entry of entries) {\n const statusStr = entry.getOptionalString('status');\n if (!statusStr || !ALL_STATUSES.includes(statusStr as FeatureStatus)) {\n continue;\n }\n const status = statusStr as FeatureStatus;\n const existing = byStatus.get(status)!;\n const title = entry.getOptionalString('title') ?? existing.title;\n const visible = entry.getOptionalBoolean('visible') ?? existing.visible;\n const retentionDays = entry.getOptionalNumber('retentionDays');\n const retentionAnchor = parseAnchor(\n entry.getOptionalString('retentionAnchor'),\n );\n byStatus.set(status, {\n status,\n title,\n visible,\n retentionDays:\n retentionDays !== undefined && retentionDays > 0\n ? retentionDays\n : undefined,\n retentionAnchor,\n });\n }\n\n return ALL_STATUSES.map(s => byStatus.get(s)!);\n}\n\nexport function getRoadmapUiCapabilities(\n datasource: DatasourceType,\n): RoadmapUiCapabilities {\n if (datasource === 'gitlab') {\n return {\n retentionFiltering: false,\n includeBeyondRetentionQuery: false,\n adminEditTitleDescription: false,\n adminDeleteFeature: false,\n adminDeleteComment: false,\n creatorEditDeleteSuggested: false,\n adminReorder: false,\n };\n }\n return {\n retentionFiltering: true,\n includeBeyondRetentionQuery: true,\n adminEditTitleDescription: true,\n adminDeleteFeature: true,\n adminDeleteComment: true,\n creatorEditDeleteSuggested: true,\n adminReorder: true,\n };\n}\n\nexport function getBoardConfigResponse(\n config: Config,\n datasource: DatasourceType,\n): RoadmapBoardConfigResponse {\n return {\n columns: getMergedBoardColumns(config),\n capabilities: getRoadmapUiCapabilities(datasource),\n };\n}\n"],"names":["FeatureStatus"],"mappings":";;;;AAUA,MAAM,YAAA,GAAe,MAAA,CAAO,MAAA,CAAOA,0CAAa,CAAA;AAEhD,SAAS,aAAa,MAAA,EAA+B;AACnD,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,mBAAA,GAAoD;AAC3D,EAAA,OAAO,YAAA,CAAa,IAAI,CAAA,MAAA,MAAW;AAAA,IACjC,MAAA;AAAA,IACA,KAAA,EAAO,aAAa,MAAM,CAAA;AAAA,IAC1B,OAAA,EAAS,MAAA,KAAWA,0CAAA,CAAc,UAAA,GAAa,KAAA,GAAQ,IAAA;AAAA,IACvD,eAAA,EAAiB;AAAA,GACnB,CAAE,CAAA;AACJ;AAEA,SAAS,YAAY,CAAA,EAA+C;AAClE,EAAA,IAAI,CAAA,KAAM,SAAA,IAAa,CAAA,KAAM,SAAA,EAAW,OAAO,CAAA;AAC/C,EAAA,OAAO,SAAA;AACT;AAMO,SAAS,sBACd,MAAA,EAC8B;AAC9B,EAAA,MAAM,WAAW,mBAAA,EAAoB;AACrC,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,iBAAA,CAAkB,SAAS,CAAA;AAClD,EAAA,MAAM,OAAA,GAAU,OAAA,EAAS,sBAAA,CAAuB,SAAS,CAAA;AACzD,EAAA,IAAI,CAAC,SAAS,MAAA,EAAQ;AACpB,IAAA,OAAO,QAAA;AAAA,EACT;AAEA,EAAA,MAAM,WAAW,IAAI,GAAA;AAAA,IACnB,QAAA,CAAS,GAAA,CAAI,CAAA,CAAA,KAAK,CAAC,CAAA,CAAE,QAAQ,EAAE,GAAG,CAAA,EAAG,CAAC;AAAA,GACxC;AAE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ACpB,0BAAA,EAA4B,KAAA;AAAA,MAC5B,YAAA,EAAc;AAAA,KAChB;AAAA,EACF;AACA,EAAA,OAAO;AAAA,IACL,kBAAA,EAAoB,IAAA;AAAA,IACpB,2BAAA,EAA6B,IAAA;AAAA,IAC7B,yBAAA,EAA2B,IAAA;AAAA,IAC3B,kBAAA,EAAoB,IAAA;AAAA,IACpB,kBAAA,EAAoB,IAAA;AAAA,IACpB,0BAAA,EAA4B,IAAA;AAAA,IAC5B,YAAA,EAAc;AAAA,GAChB;AACF;AAEO,SAAS,sBAAA,CACd,QACA,UAAA,EAC4B;AAC5B,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,sBAAsB,MAAM,CAAA;AAAA,IACrC,YAAA,EAAc,yBAAyB,UAAU;AAAA,GACnD;AACF;;;;;;"}
|
package/dist/config.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs.js","sources":["../src/config.ts"],"sourcesContent":["import { Config } from '@backstage/config';\nimport { GitlabConfig, DatasourceType } from './types';\n\n/** Reads the configured datasource type, defaulting to 'database'. */\nexport function getDatasource(config: Config): DatasourceType {\n const source =\n config.getOptionalConfig('roadmap')?.getOptionalString('source') ??\n 'database';\n if (source !== 'database' && source !== 'gitlab') {\n throw new Error(`Unknown roadmap datasource: ${source}`);\n }\n return source;\n}\n\n/** Reads the GitLab datasource configuration from `roadmap.gitlab.*`. */\nexport function getGitlabConfig(config: Config): GitlabConfig {\n const gitlab = config.getConfig('roadmap.gitlab');\n const apiBaseUrl = gitlab.getString('apiBaseUrl');\n const token = gitlab.getString('token');\n const projectId = gitlab.getOptionalString('projectId');\n const groupId = gitlab.getOptionalString('groupId');\n\n if (projectId && groupId) {\n throw new Error(\n 'roadmap.gitlab: only one of projectId or groupId may be provided, not both',\n );\n }\n if (!projectId && !groupId) {\n throw new Error(\n 'roadmap.gitlab: exactly one of projectId or groupId must be provided',\n );\n }\n\n return {\n apiBaseUrl,\n token,\n projectId,\n groupId,\n defaultProjectId: gitlab.getOptionalString('defaultProjectId'),\n };\n}\n\n/** Returns the list of admin user entity refs from `roadmap.adminUsers`. */\nexport function getAdminUsers(config: Config): string[] {\n return (\n config.getOptionalConfig('roadmap')?.getOptionalStringArray('adminUsers') ??\n []\n );\n}\n\n/** Checks whether the Backstage permission framework is enabled. */\nexport function isPermissionEnabled(config: Config): boolean {\n return config.getOptionalBoolean('permission.enabled') ?? false;\n}\n"],"names":[],"mappings":";;AAIO,SAAS,cAAc,
|
|
1
|
+
{"version":3,"file":"config.cjs.js","sources":["../src/config.ts"],"sourcesContent":["import { Config } from '@backstage/config';\nimport { GitlabConfig, DatasourceType } from './types';\n\n/** Reads the configured datasource type, defaulting to 'database'. */\nexport function getDatasource(config: Config): DatasourceType {\n const source =\n config.getOptionalConfig('roadmap')?.getOptionalString('source') ??\n 'database';\n if (source !== 'database' && source !== 'gitlab') {\n throw new Error(`Unknown roadmap datasource: ${source}`);\n }\n return source;\n}\n\n/** Reads the GitLab datasource configuration from `roadmap.gitlab.*`. */\nexport function getGitlabConfig(config: Config): GitlabConfig {\n const gitlab = config.getConfig('roadmap.gitlab');\n const apiBaseUrl = gitlab.getString('apiBaseUrl');\n const token = gitlab.getString('token');\n const projectId = gitlab.getOptionalString('projectId');\n const groupId = gitlab.getOptionalString('groupId');\n\n if (projectId && groupId) {\n throw new Error(\n 'roadmap.gitlab: only one of projectId or groupId may be provided, not both',\n );\n }\n if (!projectId && !groupId) {\n throw new Error(\n 'roadmap.gitlab: exactly one of projectId or groupId must be provided',\n );\n }\n\n return {\n apiBaseUrl,\n token,\n projectId,\n groupId,\n defaultProjectId: gitlab.getOptionalString('defaultProjectId'),\n };\n}\n\n/** Returns the list of admin user entity refs from `roadmap.adminUsers`. */\nexport function getAdminUsers(config: Config): string[] {\n return (\n config.getOptionalConfig('roadmap')?.getOptionalStringArray('adminUsers') ??\n []\n );\n}\n\n/** Checks whether the Backstage permission framework is enabled. */\nexport function isPermissionEnabled(config: Config): bo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B,YAAY,KACxE,EAAC;AAEL;AAGO,SAAS,oBAAoB,MAAA,EAAyB;AAC3D,EAAA,OAAO,MAAA,CAAO,kBAAA,CAAmB,oBAAoB,CAAA,IAAK,KAAA;AAC5D;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RoadmapDatabaseClient.cjs.js","sources":["../../src/database/RoadmapDatabaseClient.ts"],"sourcesContent":["import { Knex } from 'knex';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { RoadmapDatasource } from '../types';\nimport { LoggerService, DatabaseService } from '@backstage/backend-plugin-api';\nimport { NotFoundError, ConflictError } from '@backstage/errors';\nimport { resolvePackagePath } from '@backstage/backend-plugin-api';\nimport { statusFromDb, statusToDb } from './statusDbMapping';\n\nconst migrationsDir = resolvePackagePath(\n '@rothenbergt/backstage-plugin-roadmap-backend',\n 'migrations',\n);\n\n/**\n * Implementation of the RoadmapDatasource interface using Knex\n */\nexport class RoadmapDatabaseClient implements RoadmapDatasource {\n static async create(options: {\n database: DatabaseService;\n logger: LoggerService;\n }): Promise<RoadmapDatabaseClient> {\n const { database, logger } = options;\n logger.info('Creating database for roadmap plugin');\n\n const client = await database.getClient();\n\n if (!database.migrations?.skip) {\n logger.info('Running migrations for roadmap plugin');\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new RoadmapDatabaseClient(client, logger);\n }\n\n private readonly knex: Knex;\n private readonly logger: LoggerService;\n\n constructor(knexInstance: Knex, logger: LoggerService) {\n this.knex = knexInstance;\n this.logger = logger;\n }\n\n private mapFeature(row: Record<string, unknown>): Feature {\n return {\n id: String(row.id),\n title: String(row.title),\n description: String(row.description),\n status: statusFromDb(String(row.status)),\n votes: Number(row.votes ?? 0),\n author: String(row.author),\n created_at: String(row.created_at),\n updated_at: String(row.updated_at),\n board_position:\n row.board_position !== undefined && row.board_position !== null\n ? Number(row.board_position)\n : 0,\n };\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features')\n .where({ id: comment.featureId })\n .first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(\n `Feature with id ${comment.featureId} not found`,\n );\n }\n\n // Insert comment and return the complete inserted object\n const [newComment] = await trx('comments')\n .insert({\n feature_id: comment.featureId,\n text: comment.text,\n author: comment.author,\n })\n .returning('*');\n\n await trx.commit();\n return newComment;\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error inserting comment', { error: String(error) });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError('Failed to add comment', error as Error);\n }\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n try {\n // First check if the feature exists\n const feature = await this.knex('features')\n .where({ id: featureId })\n .first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n // Get comments ordered by creation date (newest first)\n return this.knex('comments')\n .where({ feature_id: featureId })\n .orderBy('created_at', 'desc')\n .select('*');\n } catch (error) {\n this.logger.error(`Error fetching comments for feature ${featureId}`, {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get comments for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async addFeature(feature: NewFeature & { author: string }): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n const maxRow = await trx('features')\n .where({ status: statusToDb(FeatureStatus.Suggested) })\n .max('board_position as maxp')\n .first();\n const nextPosition =\n Number((maxRow as { maxp?: string | number })?.maxp ?? 0) + 1;\n\n // Insert feature and return the complete inserted object\n const [newFeature] = await trx('features')\n .insert({\n ...feature,\n status: statusToDb(FeatureStatus.Suggested),\n votes: 0,\n board_position: nextPosition,\n })\n .returning('*');\n\n await trx.commit();\n return this.mapFeature(newFeature);\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error adding feature', { error: String(error) });\n throw new ConflictError('Failed to add feature', error as Error);\n }\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n try {\n const rows = await this.knex('features')\n .orderBy([\n { column: 'status', order: 'asc' },\n { column: 'board_position', order: 'asc' },\n { column: 'created_at', order: 'desc' },\n ])\n .select('*');\n return rows.map(r => this.mapFeature(r));\n } catch (error) {\n this.logger.error('Error fetching all features', {\n error: String(error),\n });\n throw new ConflictError('Failed to get all features', error as Error);\n }\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n try {\n const feature = await this.knex('features').where({ id }).first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n return this.mapFeature(feature);\n } catch (error) {\n this.logger.error(`Error fetching feature ${id}`, {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get feature with id ${id}`,\n error as Error,\n );\n }\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n // Update the status and return the updated object\n const [updatedFeature] = await trx('features')\n .where({ id })\n .update({\n status: statusToDb(status),\n updated_at: this.knex.fn.now(),\n })\n .returning('*');\n\n await trx.commit();\n return this.mapFeature(updatedFeature);\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error updating feature status', {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to update status for feature ${id}`,\n error as Error,\n );\n }\n }\n\n async updateFeatureDetails(\n id: string,\n fields: { title?: string; description?: string },\n ): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n const feature = await trx('features').where({ id }).first();\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n const patch: Record<string, unknown> = { updated_at: this.knex.fn.now() };\n if (fields.title !== undefined) patch.title = fields.title;\n if (fields.description !== undefined)\n patch.description = fields.description;\n const [updated] = await trx('features')\n .where({ id })\n .update(patch)\n .returning('*');\n await trx.commit();\n return this.mapFeature(updated);\n } catch (error) {\n await trx.rollback();\n if (error instanceof NotFoundError) throw error;\n this.logger.error('Error updating feature details', {\n error: String(error),\n });\n throw new ConflictError(`Failed to update feature ${id}`, error as Error);\n }\n }\n\n async deleteFeature(id: string): Promise<void> {\n const n = await this.knex('features').where({ id }).delete();\n if (!n) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n }\n\n async reorderFeaturesInStatus(\n status: FeatureStatus,\n orderedIds: string[],\n ): Promise<void> {\n const trx = await this.knex.transaction();\n try {\n for (let i = 0; i < orderedIds.length; i += 1) {\n const updated = await trx('features')\n .where({ id: orderedIds[i], status: statusToDb(status) })\n .update({\n board_position: i,\n });\n if (!updated) {\n await trx.rollback();\n throw new NotFoundError(\n `Feature ${orderedIds[i]} not found or not in status ${status}`,\n );\n }\n }\n await trx.commit();\n } catch (error) {\n await trx.rollback();\n if (error instanceof NotFoundError) throw error;\n this.logger.error('Error reordering features', { error: String(error) });\n throw new ConflictError('Failed to reorder features', error as Error);\n }\n }\n\n async deleteCommentById(commentId: string): Promise<void> {\n const n = await this.knex('comments').where({ id: commentId }).delete();\n if (!n) {\n throw new NotFoundError(`Comment with id ${commentId} not found`);\n }\n }\n\n async toggleVote(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id: featureId }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n const existingVote = await trx('votes')\n .where({ feature_id: featureId, voter })\n .first();\n\n let voteAdded: boolean;\n if (existingVote) {\n // Remove the vote\n await trx('votes').where({ feature_id: featureId, voter }).delete();\n await trx('features').where({ id: featureId }).decrement('votes', 1);\n voteAdded = false;\n } else {\n // Add the vote\n await trx('votes').insert({ feature_id: featureId, voter });\n await trx('features').where({ id: featureId }).increment('votes', 1);\n voteAdded = true;\n }\n\n // Read the updated count within the same transaction\n const updated = await trx('features')\n .where({ id: featureId })\n .select('votes')\n .first();\n await trx.commit();\n return { voteAdded, voteCount: updated?.votes ?? 0 };\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error toggling vote', { error: String(error) });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to toggle vote for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n const counts = await this.getVoteCounts([featureId]);\n return counts[featureId] || 0;\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n try {\n if (featureIds.length === 0) {\n return {};\n }\n\n const results = await this.knex('features')\n .whereIn('id', featureIds)\n .select('id', 'votes');\n\n return results.reduce((acc, { id, votes }) => {\n acc[id] = votes;\n return acc;\n }, {} as Record<string, number>);\n } catch (error) {\n this.logger.error('Error getting vote counts', { error: String(error) });\n throw new ConflictError('Failed to get vote counts', error as Error);\n }\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n try {\n const vote = await this.knex('votes')\n .where({ feature_id: featureId, voter })\n .first();\n return !!vote;\n } catch (error) {\n this.logger.error('Error checking if user has voted', {\n error: String(error),\n });\n throw new ConflictError(\n `Failed to check if user ${voter} has voted on feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n try {\n if (featureIds.length === 0) {\n return {};\n }\n\n const votes = await this.knex('votes')\n .whereIn('feature_id', featureIds)\n .where({ voter })\n .select('feature_id');\n\n const votedFeatureIds = new Set(votes.map(v => v.feature_id.toString()));\n\n return featureIds.reduce((acc, featureId) => {\n acc[featureId] = votedFeatureIds.has(featureId);\n return acc;\n }, {} as Record<string, boolean>);\n } catch (error) {\n this.logger.error('Error checking batch votes', { error: String(error) });\n throw new ConflictError(\n `Failed to check votes for user ${voter}`,\n error as Error,\n );\n }\n }\n}\n"],"names":["resolvePackagePath","statusFromDb","NotFoundError","ConflictError","statusToDb","FeatureStatus"],"mappings":";;;;;;;AAcA,MAAM,aAAgB,GAAAA,mCAAA;AAAA,EACpB,+CAAA;AAAA,EACA;AACF,CAAA;AAKO,MAAM,qBAAmD,CAAA;AAAA,EAC9D,aAAa,OAAO,OAGe,EAAA;AACjC,IAAM,MAAA,EAAE,QAAU,EAAA,MAAA,EAAW,GAAA,OAAA;AAC7B,IAAA,MAAA,CAAO,KAAK,sCAAsC,CAAA;AAElD,IAAM,MAAA,MAAA,GAAS,MAAM,QAAA,CAAS,SAAU,EAAA;AAExC,IAAI,IAAA,CAAC,QAAS,CAAA,UAAA,EAAY,IAAM,EAAA;AAC9B,MAAA,MAAA,CAAO,KAAK,uCAAuC,CAAA;AACnD,MAAM,MAAA,MAAA,CAAO,QAAQ,MAAO,CAAA;AAAA,QAC1B,SAAW,EAAA;AAAA,OACZ,CAAA;AAAA;AAGH,IAAO,OAAA,IAAI,qBAAsB,CAAA,MAAA,EAAQ,MAAM,CAAA;AAAA;AACjD,EAEiB,IAAA;AAAA,EACA,MAAA;AAAA,EAEjB,WAAA,CAAY,cAAoB,MAAuB,EAAA;AACrD,IAAA,IAAA,CAAK,IAAO,GAAA,YAAA;AACZ,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA;AAAA;AAChB,EAEQ,WAAW,GAAuC,EAAA;AACxD,IAAO,OAAA;AAAA,MACL,EAAA,EAAI,MAAO,CAAA,GAAA,CAAI,EAAE,CAAA;AAAA,MACjB,KAAA,EAAO,MAAO,CAAA,GAAA,CAAI,KAAK,CAAA;AAAA,MACvB,WAAA,EAAa,MAAO,CAAA,GAAA,CAAI,WAAW,CAAA;AAAA,MACnC,MAAQ,EAAAC,4BAAA,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M,CAAA,GAAA,CAAI,OAAK,CAAE,CAAA,UAAA,CAAW,QAAS,EAAC,CAAC,CAAA;AAEvE,MAAA,OAAO,UAAW,CAAA,MAAA,CAAO,CAAC,GAAA,EAAK,SAAc,KAAA;AAC3C,QAAA,GAAA,CAAI,SAAS,CAAA,GAAI,eAAgB,CAAA,GAAA,CAAI,SAAS,CAAA;AAC9C,QAAO,OAAA,GAAA;AAAA,OACT,EAAG,EAA6B,CAAA;AAAA,aACzB,KAAO,EAAA;AACd,MAAK,IAAA,CAAA,MAAA,CAAO,MAAM,4BAA8B,EAAA,EAAE,OAAO,MAAO,CAAA,KAAK,GAAG,CAAA;AACxE,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,kCAAkC,KAAK,CAAA,CAAA;AAAA,QACvC;AAAA,OACF;AAAA;AACF;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"RoadmapDatabaseClient.cjs.js","sources":["../../src/database/RoadmapDatabaseClient.ts"],"sourcesContent":["import { Knex } from 'knex';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { RoadmapDatasource } from '../types';\nimport { LoggerService, DatabaseService } from '@backstage/backend-plugin-api';\nimport { NotFoundError, ConflictError } from '@backstage/errors';\nimport { resolvePackagePath } from '@backstage/backend-plugin-api';\nimport { statusFromDb, statusToDb } from './statusDbMapping';\n\nconst migrationsDir = resolvePackagePath(\n '@rothenbergt/backstage-plugin-roadmap-backend',\n 'migrations',\n);\n\n/**\n * Implementation of the RoadmapDatasource interface using Knex\n */\nexport class RoadmapDatabaseClient implements RoadmapDatasource {\n static async create(options: {\n database: DatabaseService;\n logger: LoggerService;\n }): Promise<RoadmapDatabaseClient> {\n const { database, logger } = options;\n logger.info('Creating database for roadmap plugin');\n\n const client = await database.getClient();\n\n if (!database.migrations?.skip) {\n logger.info('Running migrations for roadmap plugin');\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new RoadmapDatabaseClient(client, logger);\n }\n\n private readonly knex: Knex;\n private readonly logger: LoggerService;\n\n constructor(knexInstance: Knex, logger: LoggerService) {\n this.knex = knexInstance;\n this.logger = logger;\n }\n\n private mapFeature(row: Record<string, unknown>): Feature {\n return {\n id: String(row.id),\n title: String(row.title),\n description: String(row.description),\n status: statusFromDb(String(row.status)),\n votes: Number(row.votes ?? 0),\n author: String(row.author),\n created_at: String(row.created_at),\n updated_at: String(row.updated_at),\n board_position:\n row.board_position !== undefined && row.board_position !== null\n ? Number(row.board_position)\n : 0,\n };\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features')\n .where({ id: comment.featureId })\n .first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(\n `Feature with id ${comment.featureId} not found`,\n );\n }\n\n // Insert comment and return the complete inserted object\n const [newComment] = await trx('comments')\n .insert({\n feature_id: comment.featureId,\n text: comment.text,\n author: comment.author,\n })\n .returning('*');\n\n await trx.commit();\n return newComment;\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error inserting comment', { error: String(error) });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError('Failed to add comment', error as Error);\n }\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n try {\n // First check if the feature exists\n const feature = await this.knex('features')\n .where({ id: featureId })\n .first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n // Get comments ordered by creation date (newest first)\n return this.knex('comments')\n .where({ feature_id: featureId })\n .orderBy('created_at', 'desc')\n .select('*');\n } catch (error) {\n this.logger.error(`Error fetching comments for feature ${featureId}`, {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get comments for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async addFeature(feature: NewFeature & { author: string }): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n const maxRow = await trx('features')\n .where({ status: statusToDb(FeatureStatus.Suggested) })\n .max('board_position as maxp')\n .first();\n const nextPosition =\n Number((maxRow as { maxp?: string | number })?.maxp ?? 0) + 1;\n\n // Insert feature and return the complete inserted object\n const [newFeature] = await trx('features')\n .insert({\n ...feature,\n status: statusToDb(FeatureStatus.Suggested),\n votes: 0,\n board_position: nextPosition,\n })\n .returning('*');\n\n await trx.commit();\n return this.mapFeature(newFeature);\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error adding feature', { error: String(error) });\n throw new ConflictError('Failed to add feature', error as Error);\n }\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n try {\n const rows = await this.knex('features')\n .orderBy([\n { column: 'status', order: 'asc' },\n { column: 'board_position', order: 'asc' },\n { column: 'created_at', order: 'desc' },\n ])\n .select('*');\n return rows.map(r => this.mapFeature(r));\n } catch (error) {\n this.logger.error('Error fetching all features', {\n error: String(error),\n });\n throw new ConflictError('Failed to get all features', error as Error);\n }\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n try {\n const feature = await this.knex('features').where({ id }).first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n return this.mapFeature(feature);\n } catch (error) {\n this.logger.error(`Error fetching feature ${id}`, {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get feature with id ${id}`,\n error as Error,\n );\n }\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n // Update the status and return the updated object\n const [updatedFeature] = await trx('features')\n .where({ id })\n .update({\n status: statusToDb(status),\n updated_at: this.knex.fn.now(),\n })\n .returning('*');\n\n await trx.commit();\n return this.mapFeature(updatedFeature);\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error updating feature status', {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to update status for feature ${id}`,\n error as Error,\n );\n }\n }\n\n async updateFeatureDetails(\n id: string,\n fields: { title?: string; description?: string },\n ): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n const feature = await trx('features').where({ id }).first();\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n const patch: Record<string, unknown> = { updated_at: this.knex.fn.now() };\n if (fields.title !== undefined) patch.title = fields.title;\n if (fields.description !== undefined)\n patch.description = fields.description;\n const [updated] = await trx('features')\n .where({ id })\n .update(patch)\n .returning('*');\n await trx.commit();\n return this.mapFeature(updated);\n } catch (error) {\n await trx.rollback();\n if (error instanceof NotFoundError) throw error;\n this.logger.error('Error updating feature details', {\n error: String(error),\n });\n throw new ConflictError(`Failed to update feature ${id}`, error as Error);\n }\n }\n\n async deleteFeature(id: string): Promise<void> {\n const n = await this.knex('features').where({ id }).delete();\n if (!n) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n }\n\n async reorderFeaturesInStatus(\n status: FeatureStatus,\n orderedIds: string[],\n ): Promise<void> {\n const trx = await this.knex.transaction();\n try {\n for (let i = 0; i < orderedIds.length; i += 1) {\n const updated = await trx('features')\n .where({ id: orderedIds[i], status: statusToDb(status) })\n .update({\n board_position: i,\n });\n if (!updated) {\n await trx.rollback();\n throw new NotFoundError(\n `Feature ${orderedIds[i]} not found or not in status ${status}`,\n );\n }\n }\n await trx.commit();\n } catch (error) {\n await trx.rollback();\n if (error instanceof NotFoundError) throw error;\n this.logger.error('Error reordering features', { error: String(error) });\n throw new ConflictError('Failed to reorder features', error as Error);\n }\n }\n\n async deleteCommentById(commentId: string): Promise<void> {\n const n = await this.knex('comments').where({ id: commentId }).delete();\n if (!n) {\n throw new NotFoundError(`Comment with id ${commentId} not found`);\n }\n }\n\n async toggleVote(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id: featureId }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n const existingVote = await trx('votes')\n .where({ feature_id: featureId, voter })\n .first();\n\n let voteAdded: boolean;\n if (existingVote) {\n // Remove the vote\n await trx('votes').where({ feature_id: featureId, voter }).delete();\n await trx('features').where({ id: featureId }).decrement('votes', 1);\n voteAdded = false;\n } else {\n // Add the vote\n await trx('votes').insert({ feature_id: featureId, voter });\n await trx('features').where({ id: featureId }).increment('votes', 1);\n voteAdded = true;\n }\n\n // Read the updated count within the same transaction\n const updated = await trx('features')\n .where({ id: featureId })\n .select('votes')\n .first();\n await trx.commit();\n return { voteAdded, voteCount: updated?.votes ?? 0 };\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error toggling vote', { error: String(error) });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to toggle vote for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n const counts = await this.getVoteCounts([featureId]);\n return counts[featureId] || 0;\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n try {\n if (featureIds.length === 0) {\n return {};\n }\n\n const results = await this.knex('features')\n .whereIn('id', featureIds)\n .select('id', 'votes');\n\n return results.reduce((acc, { id, votes }) => {\n acc[id] = votes;\n return acc;\n }, {} as Record<string, number>);\n } catch (error) {\n this.logger.error('Error getting vote counts', { error: String(error) });\n throw new ConflictError('Failed to get vote counts', error as Error);\n }\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n try {\n const vote = await this.knex('votes')\n .where({ feature_id: featureId, voter })\n .first();\n return !!vote;\n } catch (error) {\n this.logger.error('Error checking if user has voted', {\n error: String(error),\n });\n throw new ConflictError(\n `Failed to check if user ${voter} has voted on feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n try {\n if (featureIds.length === 0) {\n return {};\n }\n\n const votes = await this.knex('votes')\n .whereIn('feature_id', featureIds)\n .where({ voter })\n .select('feature_id');\n\n const votedFeatureIds = new Set(votes.map(v => v.feature_id.toString()));\n\n return featureIds.reduce((acc, featureId) => {\n acc[featureId] = votedFeatureIds.has(featureId);\n return acc;\n }, {} as Record<string, boolean>);\n } catch (error) {\n this.logger.error('Error checking batch votes', { error: String(error) });\n throw new ConflictError(\n `Failed to check votes for user ${voter}`,\n error as Error,\n );\n }\n }\n}\n"],"names":["resolvePackagePath","statusFromDb","NotFoundError","ConflictError","statusToDb","FeatureStatus"],"mappings":";;;;;;;AAcA,MAAM,aAAA,GAAgBA,mCAAA;AAAA,EACpB,+CAAA;AAAA,EACA;AACF,CAAA;AAKO,MAAM,qBAAA,CAAmD;AAAA,EAC9D,aAAa,OAAO,OAAA,EAGe;AACjC,IAAA,MAAM,EAAE,QAAA,EAAU,MAAA,EAAO,GAAI,OAAA;AAC7B,IAAA,MAAA,CAAO,KAAK,sCAAsC,CAAA;AAElD,IAAA,MAAM,MAAA,GAAS,MAAM,QAAA,CAAS,SAAA,EAAU;AAExC,IAAA,IAAI,CAAC,QAAA,CAAS,UAAA,EAAY,IAAA,EAAM;AAC9B,MAAA,MAAA,CAAO,KAAK,uCAAuC,CAAA;AACnD,MAAA,MAAM,MAAA,CAAO,QAAQ,MAAA,CAAO;AAAA,QAC1B,SAAA,EAAW;AAAA,OACZ,CAAA;AAAA,IACH;AAEA,IAAA,OAAO,IAAI,qBAAA,CAAsB,MAAA,EAAQ,MAAM,CAAA;AAAA,EACjD;AAAA,EAEiB,IAAA;AAAA,EACA,MAAA;AAAA,EAEjB,WAAA,CAAY,cAAoB,MAAA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|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statusDbMapping.cjs.js","sources":["../../src/database/statusDbMapping.ts"],"sourcesContent":["import { FeatureStatus } from '@rothenbergt/backstage-plugin-roadmap-common';\n\n/**\n * API uses `FeatureStatus.InProgress` (`In Progress`); SQLite CHECK uses `InProgress`.\n * See migrations/20250330000000_init.js.\n */\nexport const DB_STATUS_IN_PROGRESS = 'InProgress';\n\n/** Value written to the `features.status` column. */\nexport function statusToDb(status: FeatureStatus): string {\n return status === FeatureStatus.InProgress ? DB_STATUS_IN_PROGRESS : status;\n}\n\n/** Value returned to callers as `FeatureStatus`. */\nexport function statusFromDb(dbStatus: string): FeatureStatus {\n if (dbStatus === DB_STATUS_IN_PROGRESS) {\n return FeatureStatus.InProgress;\n }\n return dbStatus as FeatureStatus;\n}\n"],"names":["FeatureStatus"],"mappings":";;;;AAMO,MAAM,
|
|
1
|
+
{"version":3,"file":"statusDbMapping.cjs.js","sources":["../../src/database/statusDbMapping.ts"],"sourcesContent":["import { FeatureStatus } from '@rothenbergt/backstage-plugin-roadmap-common';\n\n/**\n * API uses `FeatureStatus.InProgress` (`In Progress`); SQLite CHECK uses `InProgress`.\n * See migrations/20250330000000_init.js.\n */\nexport const DB_STATUS_IN_PROGRESS = 'InProgress';\n\n/** Value written to the `features.status` column. */\nexport function statusToDb(status: FeatureStatus): string {\n return status === FeatureStatus.InProgress ? DB_STATUS_IN_PROGRESS : status;\n}\n\n/** Value returned to callers as `FeatureStatus`. */\nexport function statusFromDb(dbStatus: string): FeatureStatus {\n if (dbStatus === DB_STATUS_IN_PROGRESS) {\n return FeatureStatus.InProgress;\n }\n return dbStatus as FeatureStatus;\n}\n"],"names":["FeatureStatus"],"mappings":";;;;AAMO,MAAM,qBAAA,GAAwB;AAG9B,SAAS,WAAW,MAAA,EAA+B;AACxD,EAAA,OAAO,MAAA,KAAWA,0CAAA,CAAc,UAAA,GAAa,qBAAA,GAAwB,MAAA;AACvE;AAGO,SAAS,aAAa,QAAA,EAAiC;AAC5D,EAAA,IAAI,aAAa,qBAAA,EAAuB;AACtC,IAAA,OAAOA,0CAAA,CAAc,UAAA;AAAA,EACvB;AACA,EAAA,OAAO,QAAA;AACT;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RoadmapGitlabClient.cjs.js","sources":["../../src/gitlab/RoadmapGitlabClient.ts"],"sourcesContent":["import {\n NewComment,\n Comment,\n NewFeature,\n Feature,\n FeatureStatus,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { RoadmapDatasource } from '../types';\nimport {\n NotFoundError,\n ConflictError,\n NotAllowedError,\n} from '@backstage/errors';\nimport { CacheService, LoggerService } from '@backstage/backend-plugin-api';\nimport { GitlabConfig } from '../types';\nimport { parseEntityRef } from '@backstage/catalog-model';\n\nconst ROADMAP_LABEL = 'roadmap';\nconst ROADMAP_SCOPE_LABEL = `${ROADMAP_LABEL}::`;\nconst STATUS_LABELS = Object.values(FeatureStatus).map(\n status => `${ROADMAP_SCOPE_LABEL}${status}`,\n);\nconst PAGINATION = 'per_page=100';\n\nconst AUTHOR_TAG_RE = /^<!-- author:(\\S+) -->\\n/;\nconst VOTE_TAG_RE = /^<!-- vote:(\\S+) -->$/;\n\ninterface GitLabIssue {\n id: number;\n iid: number;\n project_id?: number;\n title: string;\n description?: string;\n labels?: string[];\n upvotes?: number;\n author?: { username: string };\n created_at: string;\n updated_at: string;\n}\n\ninterface GitLabNote {\n id: number;\n body?: string;\n system?: boolean;\n author?: { username: string };\n created_at: string;\n updated_at: string;\n}\n\nfunction formatStatusAsGitLabLabel(status: FeatureStatus): string {\n return `${ROADMAP_SCOPE_LABEL}${status}`;\n}\n\nfunction extractStatusFromLabels(labels: string[]): FeatureStatus {\n const match = labels.find(l => STATUS_LABELS.includes(l));\n if (!match) return FeatureStatus.Suggested;\n return match.replace(ROADMAP_SCOPE_LABEL, '') as FeatureStatus;\n}\n\nfunction replaceStatusLabels(\n labels: string[],\n newStatus: FeatureStatus,\n): string[] {\n const cleaned = labels.filter(l => !STATUS_LABELS.includes(l));\n if (!cleaned.includes(ROADMAP_LABEL)) cleaned.push(ROADMAP_LABEL);\n cleaned.push(formatStatusAsGitLabLabel(newStatus));\n return cleaned;\n}\n\nfunction formatIsoDateForStorage(isoDate: string): string {\n return isoDate.replace('T', ' ').replace(/\\.\\d+Z$/, '');\n}\n\nfunction mapGitLabIssueToFeature(\n issue: GitLabIssue,\n voteCount?: number,\n): Feature {\n return {\n id: String(issue.id),\n title: issue.title,\n description: issue.description ?? '',\n status: extractStatusFromLabels(issue.labels ?? []),\n votes: voteCount ?? issue.upvotes ?? 0,\n author: issue.author?.username ?? '',\n created_at: formatIsoDateForStorage(issue.created_at),\n updated_at: formatIsoDateForStorage(issue.updated_at),\n };\n}\n\nfunction mapGitLabNoteToComment(note: GitLabNote, featureId: string): Comment {\n const body = note.body ?? '';\n const authorMatch = body.match(AUTHOR_TAG_RE);\n return {\n id: String(note.id),\n author: authorMatch ? authorMatch[1] : note.author?.username ?? '',\n featureId,\n text: authorMatch ? body.replace(AUTHOR_TAG_RE, '') : body,\n created_at: formatIsoDateForStorage(note.created_at),\n updated_at: formatIsoDateForStorage(note.updated_at),\n };\n}\n\nfunction isHiddenVoteMarker(body: string): boolean {\n return VOTE_TAG_RE.test(body?.trim());\n}\n\nfunction isUserComment(note: GitLabNote): boolean {\n return !note.system && !isHiddenVoteMarker(note.body ?? '');\n}\n\nfunction sanitizeLog(value: string): string {\n return value.replace(/[\\r\\n]/g, '');\n}\n\nfunction parseUsernameFromEntityRef(userEntityRef: string): string {\n const entity = parseEntityRef(userEntityRef);\n return entity.name;\n}\n\nfunction buildAuthorTaggedBody(username: string, text: string): string {\n return `<!-- author:${username} -->\\n${text}`;\n}\n\nfunction buildVoteMarker(username: string): string {\n return `<!-- vote:${username} -->`;\n}\n\nfunction convertIssuesToFeatures(\n issues: GitLabIssue[],\n voteCounts?: Record<string, number>,\n): Feature[] {\n return issues.map(issue =>\n mapGitLabIssueToFeature(issue, voteCounts?.[String(issue.id)]),\n );\n}\n\nfunction convertNotesToComments(\n notes: GitLabNote[],\n featureId: string,\n): Comment[] {\n return notes.map(n => mapGitLabNoteToComment(n, featureId));\n}\n\nfunction filterUserComments(notes: GitLabNote[]): GitLabNote[] {\n return notes.filter(isUserComment);\n}\n\nfunction buildCommentBody(comment: NewComment): string {\n const author = comment.author\n ? parseUsernameFromEntityRef(comment.author)\n : undefined;\n return author ? buildAuthorTaggedBody(author, comment.text) : comment.text;\n}\n\nfunction buildNewRoadmapIssuePayload(feature: NewFeature): string {\n return JSON.stringify({\n title: feature.title,\n description: feature.description,\n labels: `${ROADMAP_LABEL},${formatStatusAsGitLabLabel(\n FeatureStatus.Suggested,\n )}`,\n });\n}\n\nconst VOTE_CACHE_TTL_MS = 30_000; // 30 seconds\nconst PROJECT_MAP_CACHE_TTL_MS = 300_000; // 5 minutes\n\nfunction issueProjectCacheKey(issueId: string): string {\n return `roadmap:issue-project:${issueId}`;\n}\n\nfunction issueIidCacheKey(issueId: string): string {\n return `roadmap:issue-iid:${issueId}`;\n}\n\nfunction voteCacheKey(featureId: string): string {\n return `roadmap:votes:${featureId}`;\n}\n\nfunction voteMapToJson(map: Map<string, number>): Record<string, number> {\n return Object.fromEntries(map);\n}\n\nfunction jsonToVoteMap(json: Record<string, number>): Map<string, number> {\n return new Map(Object.entries(json));\n}\n\nexport class RoadmapGitlabClient implements RoadmapDatasource {\n private readonly baseUrl: string;\n private readonly token: string;\n private readonly projectId?: string;\n private readonly groupId?: string;\n private readonly defaultProjectId?: string;\n private readonly logger: LoggerService;\n private readonly cache: CacheService;\n\n private async getCachedVotes(\n featureId: string,\n ): Promise<Map<string, number> | undefined> {\n const cached = await this.cache.get<Record<string, number>>(\n voteCacheKey(featureId),\n );\n return cached ? jsonToVoteMap(cached) : undefined;\n }\n\n private async setCachedVotes(\n featureId: string,\n data: Map<string, number>,\n ): Promise<void> {\n await this.cache.set(voteCacheKey(featureId), voteMapToJson(data), {\n ttl: VOTE_CACHE_TTL_MS,\n });\n }\n\n private async invalidateCachedVotes(featureId: string): Promise<void> {\n await this.cache.delete(voteCacheKey(featureId));\n }\n\n static create(options: {\n gitlab: GitlabConfig;\n logger: LoggerService;\n cache: CacheService;\n }): RoadmapGitlabClient {\n const { gitlab, logger, cache } = options;\n return new RoadmapGitlabClient(\n gitlab.apiBaseUrl,\n gitlab.token,\n logger,\n cache,\n gitlab.projectId,\n gitlab.groupId,\n gitlab.defaultProjectId,\n );\n }\n\n private constructor(\n baseUrl: string,\n token: string,\n logger: LoggerService,\n cache: CacheService,\n projectId?: string,\n groupId?: string,\n defaultProjectId?: string,\n ) {\n this.baseUrl = baseUrl.replace(/\\/+$/, '');\n this.token = token;\n this.projectId = projectId ? encodeURIComponent(projectId) : undefined;\n this.groupId = groupId ? encodeURIComponent(groupId) : undefined;\n this.defaultProjectId = defaultProjectId\n ? encodeURIComponent(defaultProjectId)\n : undefined;\n this.logger = logger;\n this.cache = cache;\n }\n\n private get isGroupMode(): boolean {\n return !!this.groupId;\n }\n\n private projectApiUrl(path: string, projectId?: string): string {\n const pid = projectId ?? this.projectId;\n if (!pid) {\n throw new Error('projectId is required for this operation');\n }\n return `${this.baseUrl}/projects/${pid}${path}`;\n }\n\n private groupApiUrl(path: string): string {\n return `${this.baseUrl}/groups/${this.groupId}${path}`;\n }\n\n /**\n * Resolves the encoded project ID for a given issue id.\n * In project mode, returns the configured projectId.\n * In group mode, looks up the cached mapping from group issue responses.\n */\n private async resolveProjectId(issueId: string): Promise<string> {\n if (!this.isGroupMode) return this.projectId!;\n const pid = await this.cache.get<string>(issueProjectCacheKey(issueId));\n if (!pid) {\n throw new NotFoundError(\n `No cached project mapping for issue ${issueId}. Fetch all features first.`,\n );\n }\n return pid;\n }\n\n /**\n * Resolves the project-scoped iid for a given global issue id.\n * Looks up the cached id→iid mapping.\n */\n private async resolveIid(issueId: string): Promise<string> {\n const iid = await this.cache.get<string>(issueIidCacheKey(issueId));\n if (!iid) {\n throw new NotFoundError(\n `No cached iid mapping for issue ${issueId}. Fetch all features first.`,\n );\n }\n return iid;\n }\n\n private async hasIssueProjectCached(issueId: string): Promise<boolean> {\n const iid = await this.cache.get<string>(issueIidCacheKey(issueId));\n if (!iid) return false;\n if (!this.isGroupMode) return true;\n const pid = await this.cache.get<string>(issueProjectCacheKey(issueId));\n return !!pid;\n }\n\n /** Caches the project_id and iid for issues returned from group-level queries. */\n private async cacheIssueMetadata(issues: GitLabIssue[]): Promise<void> {\n await Promise.all(\n issues.flatMap(issue => {\n const ops = [\n this.cache.set(\n issueIidCacheKey(String(issue.id)),\n String(issue.iid),\n { ttl: PROJECT_MAP_CACHE_TTL_MS },\n ),\n ];\n if (this.isGroupMode && issue.project_id) {\n ops.push(\n this.cache.set(\n issueProjectCacheKey(String(issue.id)),\n String(issue.project_id),\n { ttl: PROJECT_MAP_CACHE_TTL_MS },\n ),\n );\n }\n return ops;\n }),\n );\n }\n\n private authHeaders(): Record<string, string> {\n return {\n 'PRIVATE-TOKEN': this.token,\n 'Content-Type': 'application/json',\n };\n }\n\n private async ensureIssueProjectCached(featureId: string): Promise<void> {\n if (!(await this.hasIssueProjectCached(featureId))) {\n await this.fetchAllRoadmapIssues();\n }\n }\n\n private async callGitLabApi<T>(\n url: string,\n init?: { method?: string; body?: string },\n ): Promise<{ data: T; res: Response }> {\n const method = init?.method ?? 'GET';\n this.logger.debug(`GitLab API request: ${method} ${sanitizeLog(url)}`);\n const res = await fetch(url, { ...init, headers: this.authHeaders() });\n if (!res.ok) {\n const text = await res.text();\n this.logger.error(\n `GitLab API error: ${res.status} ${sanitizeLog(text)} (${sanitizeLog(\n url,\n )})`,\n );\n if (res.status === 401)\n throw new NotAllowedError(\n 'GitLab API authentication failed: token is missing or invalid',\n );\n if (res.status === 404) throw new NotFoundError(text);\n throw new ConflictError(`GitLab API error: ${res.status}`);\n }\n if (res.status === 204 || res.headers.get('content-length') === '0') {\n return { data: undefined as T, res };\n }\n const data = (await res.json()) as T;\n return { data, res };\n }\n\n private async fetchAllPages<T>(url: string): Promise<T[]> {\n const results: T[] = [];\n let nextUrl: string | undefined = url;\n while (nextUrl) {\n const { data, res } = await this.callGitLabApi<T[]>(nextUrl);\n results.push(...data);\n const nextPage = res.headers.get('x-next-page');\n if (nextPage) {\n const parsed: URL = new URL(nextUrl);\n parsed.searchParams.set('page', nextPage);\n nextUrl = parsed.toString();\n } else {\n nextUrl = undefined;\n }\n }\n return results;\n }\n\n private async fetchAllRoadmapIssues(): Promise<GitLabIssue[]> {\n const issues = await this.fetchAllPages<GitLabIssue>(\n this.roadmapIssuesUrl('desc'),\n );\n await this.cacheIssueMetadata(issues);\n return issues;\n }\n\n private async fetchIssueById(id: string): Promise<GitLabIssue> {\n const pid = await this.resolveProjectId(id);\n const iid = await this.resolveIid(id);\n const { data } = await this.callGitLabApi<GitLabIssue>(\n this.projectApiUrl(`/issues/${iid}`, pid),\n );\n if (this.isGroupMode && data.project_id) {\n await this.cache.set(\n issueProjectCacheKey(String(data.id)),\n String(data.project_id),\n { ttl: PROJECT_MAP_CACHE_TTL_MS },\n );\n }\n await this.cache.set(issueIidCacheKey(String(data.id)), String(data.iid), {\n ttl: PROJECT_MAP_CACHE_TTL_MS,\n });\n return data;\n }\n\n private async createRoadmapIssue(feature: NewFeature): Promise<GitLabIssue> {\n if (this.isGroupMode && !this.defaultProjectId) {\n throw new ConflictError(\n 'Creating features in group mode requires defaultProjectId to be configured',\n );\n }\n const pid = this.isGroupMode ? this.defaultProjectId : this.projectId;\n const { data } = await this.callGitLabApi<GitLabIssue>(\n this.projectApiUrl('/issues', pid),\n {\n method: 'POST',\n body: buildNewRoadmapIssuePayload(feature),\n },\n );\n return data;\n }\n\n private async updateIssueLabels(\n id: string,\n labels: string[],\n ): Promise<GitLabIssue> {\n const pid = await this.resolveProjectId(id);\n const iid = await this.resolveIid(id);\n const { data } = await this.callGitLabApi<GitLabIssue>(\n this.projectApiUrl(`/issues/${iid}`, pid),\n { method: 'PUT', body: JSON.stringify({ labels: labels.join(',') }) },\n );\n return data;\n }\n\n private async fetchIssueNotes(\n featureId: string,\n sort: 'asc' | 'desc' = 'desc',\n ): Promise<GitLabNote[]> {\n const pid = await this.resolveProjectId(featureId);\n const iid = await this.resolveIid(featureId);\n return this.fetchAllPages<GitLabNote>(\n this.projectApiUrl(\n `/issues/${iid}/notes?sort=${sort}&order_by=created_at&${PAGINATION}`,\n pid,\n ),\n );\n }\n\n private async collectVoteMarkersByUser(\n featureId: string,\n ): Promise<Map<string, number>> {\n const notes = await this.fetchIssueNotes(featureId, 'asc');\n const votesByUser = new Map<string, number>();\n for (const note of notes) {\n if (note.system) continue;\n const match = (note.body ?? '').trim().match(VOTE_TAG_RE);\n if (match) votesByUser.set(match[1], note.id);\n }\n return votesByUser;\n }\n\n private async deleteNote(featureId: string, noteId: number): Promise<void> {\n const pid = await this.resolveProjectId(featureId);\n const iid = await this.resolveIid(featureId);\n await this.callGitLabApi<void>(\n this.projectApiUrl(`/issues/${iid}/notes/${noteId}`, pid),\n { method: 'DELETE' },\n );\n }\n\n private async createNote(\n featureId: string,\n body: string,\n ): Promise<GitLabNote> {\n const pid = await this.resolveProjectId(featureId);\n const iid = await this.resolveIid(featureId);\n const { data } = await this.callGitLabApi<GitLabNote>(\n this.projectApiUrl(`/issues/${iid}/notes`, pid),\n { method: 'POST', body: JSON.stringify({ body }) },\n );\n return data;\n }\n\n private async ensureFeatureExists(featureId: string): Promise<void> {\n await this.ensureIssueProjectCached(featureId);\n await this.fetchIssueById(featureId);\n }\n\n private async removeVote(\n featureId: string,\n noteId: number,\n votesByUser: Map<string, number>,\n username: string,\n ): Promise<void> {\n await this.deleteNote(featureId, noteId);\n votesByUser.delete(username);\n }\n\n private async addVote(\n featureId: string,\n votesByUser: Map<string, number>,\n username: string,\n ): Promise<void> {\n await this.createNote(featureId, buildVoteMarker(username));\n votesByUser.set(username, 0);\n }\n\n private async getOrFetchVotes(\n featureId: string,\n ): Promise<Map<string, number>> {\n const cached = await this.getCachedVotes(featureId);\n if (cached) return cached;\n const votes = await this.collectVoteMarkersByUser(featureId);\n await this.setCachedVotes(featureId, votes);\n return votes;\n }\n\n private async collectAllVoteCounts(\n issues: GitLabIssue[],\n ): Promise<Record<string, number>> {\n const counts: Record<string, number> = {};\n await Promise.all(\n issues.map(async issue => {\n const id = String(issue.id);\n const votes = await this.getOrFetchVotes(id);\n counts[id] = votes.size;\n }),\n );\n return counts;\n }\n\n private roadmapIssuesUrl(sort: 'asc' | 'desc' = 'desc'): string {\n const query = `/issues?labels=${ROADMAP_LABEL}&${PAGINATION}&order_by=created_at&sort=${sort}`;\n return this.isGroupMode\n ? this.groupApiUrl(query)\n : this.projectApiUrl(query);\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n await this.ensureIssueProjectCached(comment.featureId);\n const body = buildCommentBody(comment);\n const gitlabNote = await this.createNote(comment.featureId, body);\n return mapGitLabNoteToComment(gitlabNote, comment.featureId);\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n await this.ensureFeatureExists(featureId);\n const allNotes = await this.fetchIssueNotes(featureId, 'desc');\n const commentNotes = filterUserComments(allNotes);\n return convertNotesToComments(commentNotes, featureId);\n }\n\n async addFeature(feature: NewFeature & { author: string }): Promise<Feature> {\n const gitlabIssue = await this.createRoadmapIssue(feature);\n return mapGitLabIssueToFeature(gitlabIssue);\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n this.logger.info('Fetching all roadmap features from GitLab');\n const gitlabIssues = await this.fetchAllRoadmapIssues();\n const voteCounts = await this.collectAllVoteCounts(gitlabIssues);\n return convertIssuesToFeatures(gitlabIssues, voteCounts);\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n await this.ensureIssueProjectCached(id);\n const gitlabIssue = await this.fetchIssueById(id);\n const voteCount = await this.getVoteCount(id);\n return mapGitLabIssueToFeature(gitlabIssue, voteCount);\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n await this.ensureIssueProjectCached(id);\n const existingIssue = await this.fetchIssueById(id);\n const updatedLabels = replaceStatusLabels(\n existingIssue.labels ?? [],\n status,\n );\n const updatedIssue = await this.updateIssueLabels(id, updatedLabels);\n return mapGitLabIssueToFeature(updatedIssue);\n }\n\n async toggleVote(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n await this.ensureIssueProjectCached(featureId);\n await this.invalidateCachedVotes(featureId);\n const username = parseUsernameFromEntityRef(voter);\n const votesByUser = await this.collectVoteMarkersByUser(featureId);\n const existingNoteId = votesByUser.get(username);\n\n if (existingNoteId) {\n await this.removeVote(featureId, existingNoteId, votesByUser, username);\n } else {\n await this.addVote(featureId, votesByUser, username);\n }\n\n await this.setCachedVotes(featureId, votesByUser);\n return { voteAdded: !existingNoteId, voteCount: votesByUser.size };\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n await this.ensureIssueProjectCached(featureId);\n const votes = await this.getOrFetchVotes(featureId);\n return votes.size;\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n const counts: Record<string, number> = {};\n for (const id of featureIds) {\n counts[id] = await this.getVoteCount(id);\n }\n return counts;\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n await this.ensureIssueProjectCached(featureId);\n const username = parseUsernameFromEntityRef(voter);\n const votes = await this.getOrFetchVotes(featureId);\n return votes.has(username);\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n const results: Record<string, boolean> = {};\n for (const id of featureIds) {\n results[id] = await this.hasVoted(id, voter);\n }\n return results;\n }\n}\n"],"names":["FeatureStatus","parseEntityRef","NotFoundError","NotAllowedError","ConflictError"],"mappings":";;;;;;AAiBA,MAAM,aAAgB,GAAA,SAAA;AACtB,MAAM,mBAAA,GAAsB,GAAG,aAAa,CAAA,EAAA,CAAA;AAC5C,MAAM,aAAgB,GAAA,MAAA,CAAO,MAAO,CAAAA,0CAAa,CA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AAA,KAAA,MAAW,MAAM,UAAY,EAAA;AAC3B,MAAA,MAAA,CAAO,EAAE,CAAA,GAAI,MAAM,IAAA,CAAK,aAAa,EAAE,CAAA;AAAA;AAEzC,IAAO,OAAA,MAAA;AAAA;AACT,EAEA,MAAM,QAAS,CAAA,SAAA,EAAmB,KAAiC,EAAA;AACjE,IAAM,MAAA,IAAA,CAAK,yBAAyB,SAAS,CAAA;AAC7C,IAAM,MAAA,QAAA,GAAW,2BAA2B,KAAK,CAAA;AACjD,IAAA,MAAM,KAAQ,GAAA,MAAM,IAAK,CAAA,eAAA,CAAgB,SAAS,CAAA;AAClD,IAAO,OAAA,KAAA,CAAM,IAAI,QAAQ,CAAA;AAAA;AAC3B,EAEA,MAAM,aACJ,CAAA,UAAA,EACA,KACkC,EAAA;AAClC,IAAA,MAAM,UAAmC,EAAC;AAC1C,IAAA,KAAA,MAAW,MAAM,UAAY,EAAA;AAC3B,MAAA,OAAA,CAAQ,EAAE,CAAI,GAAA,MAAM,IAAK,CAAA,QAAA,CAAS,IAAI,KAAK,CAAA;AAAA;AAE7C,IAAO,OAAA,OAAA;AAAA;AAEX;;;;"}
|
|
1
|
+
{"version":3,"file":"RoadmapGitlabClient.cjs.js","sources":["../../src/gitlab/RoadmapGitlabClient.ts"],"sourcesContent":["import {\n NewComment,\n Comment,\n NewFeature,\n Feature,\n FeatureStatus,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { RoadmapDatasource } from '../types';\nimport {\n NotFoundError,\n ConflictError,\n NotAllowedError,\n} from '@backstage/errors';\nimport { CacheService, LoggerService } from '@backstage/backend-plugin-api';\nimport { GitlabConfig } from '../types';\nimport { parseEntityRef } from '@backstage/catalog-model';\n\nconst ROADMAP_LABEL = 'roadmap';\nconst ROADMAP_SCOPE_LABEL = `${ROADMAP_LABEL}::`;\nconst STATUS_LABELS = Object.values(FeatureStatus).map(\n status => `${ROADMAP_SCOPE_LABEL}${status}`,\n);\nconst PAGINATION = 'per_page=100';\n\nconst AUTHOR_TAG_RE = /^<!-- author:(\\S+) -->\\n/;\nconst VOTE_TAG_RE = /^<!-- vote:(\\S+) -->$/;\n\ninterface GitLabIssue {\n id: number;\n iid: number;\n project_id?: number;\n title: string;\n description?: string;\n labels?: string[];\n upvotes?: number;\n author?: { username: string };\n created_at: string;\n updated_at: string;\n}\n\ninterface GitLabNote {\n id: number;\n body?: string;\n system?: boolean;\n author?: { username: string };\n created_at: string;\n updated_at: string;\n}\n\nfunction formatStatusAsGitLabLabel(status: FeatureStatus): string {\n return `${ROADMAP_SCOPE_LABEL}${status}`;\n}\n\nfunction extractStatusFromLabels(labels: string[]): FeatureStatus {\n const match = labels.find(l => STATUS_LABELS.includes(l));\n if (!match) return FeatureStatus.Suggested;\n return match.replace(ROADMAP_SCOPE_LABEL, '') as FeatureStatus;\n}\n\nfunction replaceStatusLabels(\n labels: string[],\n newStatus: FeatureStatus,\n): string[] {\n const cleaned = labels.filter(l => !STATUS_LABELS.includes(l));\n if (!cleaned.includes(ROADMAP_LABEL)) cleaned.push(ROADMAP_LABEL);\n cleaned.push(formatStatusAsGitLabLabel(newStatus));\n return cleaned;\n}\n\nfunction formatIsoDateForStorage(isoDate: string): string {\n return isoDate.replace('T', ' ').replace(/\\.\\d+Z$/, '');\n}\n\nfunction mapGitLabIssueToFeature(\n issue: GitLabIssue,\n voteCount?: number,\n): Feature {\n return {\n id: String(issue.id),\n title: issue.title,\n description: issue.description ?? '',\n status: extractStatusFromLabels(issue.labels ?? []),\n votes: voteCount ?? issue.upvotes ?? 0,\n author: issue.author?.username ?? '',\n created_at: formatIsoDateForStorage(issue.created_at),\n updated_at: formatIsoDateForStorage(issue.updated_at),\n };\n}\n\nfunction mapGitLabNoteToComment(note: GitLabNote, featureId: string): Comment {\n const body = note.body ?? '';\n const authorMatch = body.match(AUTHOR_TAG_RE);\n return {\n id: String(note.id),\n author: authorMatch ? authorMatch[1] : note.author?.username ?? '',\n featureId,\n text: authorMatch ? body.replace(AUTHOR_TAG_RE, '') : body,\n created_at: formatIsoDateForStorage(note.created_at),\n updated_at: formatIsoDateForStorage(note.updated_at),\n };\n}\n\nfunction isHiddenVoteMarker(body: string): boolean {\n return VOTE_TAG_RE.test(body?.trim());\n}\n\nfunction isUserComment(note: GitLabNote): boolean {\n return !note.system && !isHiddenVoteMarker(note.body ?? '');\n}\n\nfunction sanitizeLog(value: string): string {\n return value.replace(/[\\r\\n]/g, '');\n}\n\nfunction parseUsernameFromEntityRef(userEntityRef: string): string {\n const entity = parseEntityRef(userEntityRef);\n return entity.name;\n}\n\nfunction buildAuthorTaggedBody(username: string, text: string): string {\n return `<!-- author:${username} -->\\n${text}`;\n}\n\nfunction buildVoteMarker(username: string): string {\n return `<!-- vote:${username} -->`;\n}\n\nfunction convertIssuesToFeatures(\n issues: GitLabIssue[],\n voteCounts?: Record<string, number>,\n): Feature[] {\n return issues.map(issue =>\n mapGitLabIssueToFeature(issue, voteCounts?.[String(issue.id)]),\n );\n}\n\nfunction convertNotesToComments(\n notes: GitLabNote[],\n featureId: string,\n): Comment[] {\n return notes.map(n => mapGitLabNoteToComment(n, featureId));\n}\n\nfunction filterUserComments(notes: GitLabNote[]): GitLabNote[] {\n return notes.filter(isUserComment);\n}\n\nfunction buildCommentBody(comment: NewComment): string {\n const author = comment.author\n ? parseUsernameFromEntityRef(comment.author)\n : undefined;\n return author ? buildAuthorTaggedBody(author, comment.text) : comment.text;\n}\n\nfunction buildNewRoadmapIssuePayload(feature: NewFeature): string {\n return JSON.stringify({\n title: feature.title,\n description: feature.description,\n labels: `${ROADMAP_LABEL},${formatStatusAsGitLabLabel(\n FeatureStatus.Suggested,\n )}`,\n });\n}\n\nconst VOTE_CACHE_TTL_MS = 30_000; // 30 seconds\nconst PROJECT_MAP_CACHE_TTL_MS = 300_000; // 5 minutes\n\nfunction issueProjectCacheKey(issueId: string): string {\n return `roadmap:issue-project:${issueId}`;\n}\n\nfunction issueIidCacheKey(issueId: string): string {\n return `roadmap:issue-iid:${issueId}`;\n}\n\nfunction voteCacheKey(featureId: string): string {\n return `roadmap:votes:${featureId}`;\n}\n\nfunction voteMapToJson(map: Map<string, number>): Record<string, number> {\n return Object.fromEntries(map);\n}\n\nfunction jsonToVoteMap(json: Record<string, number>): Map<string, number> {\n return new Map(Object.entries(json));\n}\n\nexport class RoadmapGitlabClient implements RoadmapDatasource {\n private readonly baseUrl: string;\n private readonly token: string;\n private readonly projectId?: string;\n private readonly groupId?: string;\n private readonly defaultProjectId?: string;\n private readonly logger: LoggerService;\n private readonly cache: CacheService;\n\n private async getCachedVotes(\n featureId: string,\n ): Promise<Map<string, number> | undefined> {\n const cached = await this.cache.get<Record<string, number>>(\n voteCacheKey(featureId),\n );\n return cached ? jsonToVoteMap(cached) : undefined;\n }\n\n private async setCachedVotes(\n featureId: string,\n data: Map<string, number>,\n ): Promise<void> {\n await this.cache.set(voteCacheKey(featureId), voteMapToJson(data), {\n ttl: VOTE_CACHE_TTL_MS,\n });\n }\n\n private async invalidateCachedVotes(featureId: string): Promise<void> {\n await this.cache.delete(voteCacheKey(featureId));\n }\n\n static create(options: {\n gitlab: GitlabConfig;\n logger: LoggerService;\n cache: CacheService;\n }): RoadmapGitlabClient {\n const { gitlab, logger, cache } = options;\n return new RoadmapGitlabClient(\n gitlab.apiBaseUrl,\n gitlab.token,\n logger,\n cache,\n gitlab.projectId,\n gitlab.groupId,\n gitlab.defaultProjectId,\n );\n }\n\n private constructor(\n baseUrl: string,\n token: string,\n logger: LoggerService,\n cache: CacheService,\n projectId?: string,\n groupId?: string,\n defaultProjectId?: string,\n ) {\n this.baseUrl = baseUrl.replace(/\\/+$/, '');\n this.token = token;\n this.projectId = projectId ? encodeURIComponent(projectId) : undefined;\n this.groupId = groupId ? encodeURIComponent(groupId) : undefined;\n this.defaultProjectId = defaultProjectId\n ? encodeURIComponent(defaultProjectId)\n : undefined;\n this.logger = logger;\n this.cache = cache;\n }\n\n private get isGroupMode(): boolean {\n return !!this.groupId;\n }\n\n private projectApiUrl(path: string, projectId?: string): string {\n const pid = projectId ?? this.projectId;\n if (!pid) {\n throw new Error('projectId is required for this operation');\n }\n return `${this.baseUrl}/projects/${pid}${path}`;\n }\n\n private groupApiUrl(path: string): string {\n return `${this.baseUrl}/groups/${this.groupId}${path}`;\n }\n\n /**\n * Resolves the encoded project ID for a given issue id.\n * In project mode, returns the configured projectId.\n * In group mode, looks up the cached mapping from group issue responses.\n */\n private async resolveProjectId(issueId: string): Promise<string> {\n if (!this.isGroupMode) return this.projectId!;\n const pid = await this.cache.get<string>(issueProjectCacheKey(issueId));\n if (!pid) {\n throw new NotFoundError(\n `No cached project mapping for issue ${issueId}. Fetch all features first.`,\n );\n }\n return pid;\n }\n\n /**\n * Resolves the project-scoped iid for a given global issue id.\n * Looks up the cached id→iid mapping.\n */\n private async resolveIid(issueId: string): Promise<string> {\n const iid = await this.cache.get<string>(issueIidCacheKey(issueId));\n if (!iid) {\n throw new NotFoundError(\n `No cached iid mapping for issue ${issueId}. Fetch all features first.`,\n );\n }\n return iid;\n }\n\n private async hasIssueProjectCached(issueId: string): Promise<boolean> {\n const iid = await this.cache.get<string>(issueIidCacheKey(issueId));\n if (!iid) return false;\n if (!this.isGroupMode) return true;\n const pid = await this.cache.get<string>(issueProjectCacheKey(issueId));\n return !!pid;\n }\n\n /** Caches the project_id and iid for issues returned from group-level queries. */\n private async cacheIssueMetadata(issues: GitLabIssue[]): Promise<void> {\n await Promise.all(\n issues.flatMap(issue => {\n const ops = [\n this.cache.set(\n issueIidCacheKey(String(issue.id)),\n String(issue.iid),\n { ttl: PROJECT_MAP_CACHE_TTL_MS },\n ),\n ];\n if (this.isGroupMode && issue.project_id) {\n ops.push(\n this.cache.set(\n issueProjectCacheKey(String(issue.id)),\n String(issue.project_id),\n { ttl: PROJECT_MAP_CACHE_TTL_MS },\n ),\n );\n }\n return ops;\n }),\n );\n }\n\n private authHeaders(): Record<string, string> {\n return {\n 'PRIVATE-TOKEN': this.token,\n 'Content-Type': 'application/json',\n };\n }\n\n private async ensureIssueProjectCached(featureId: string): Promise<void> {\n if (!(await this.hasIssueProjectCached(featureId))) {\n await this.fetchAllRoadmapIssues();\n }\n }\n\n private async callGitLabApi<T>(\n url: string,\n init?: { method?: string; body?: string },\n ): Promise<{ data: T; res: Response }> {\n const method = init?.method ?? 'GET';\n this.logger.debug(`GitLab API request: ${method} ${sanitizeLog(url)}`);\n const res = await fetch(url, { ...init, headers: this.authHeaders() });\n if (!res.ok) {\n const text = await res.text();\n this.logger.error(\n `GitLab API error: ${res.status} ${sanitizeLog(text)} (${sanitizeLog(\n url,\n )})`,\n );\n if (res.status === 401)\n throw new NotAllowedError(\n 'GitLab API authentication failed: token is missing or invalid',\n );\n if (res.status === 404) throw new NotFoundError(text);\n throw new ConflictError(`GitLab API error: ${res.status}`);\n }\n if (res.status === 204 || res.headers.get('content-length') === '0') {\n return { data: undefined as T, res };\n }\n const data = (await res.json()) as T;\n return { data, res };\n }\n\n private async fetchAllPages<T>(url: string): Promise<T[]> {\n const results: T[] = [];\n let nextUrl: string | undefined = url;\n while (nextUrl) {\n const { data, res } = await this.callGitLabApi<T[]>(nextUrl);\n results.push(...data);\n const nextPage = res.headers.get('x-next-page');\n if (nextPage) {\n const parsed: URL = new URL(nextUrl);\n parsed.searchParams.set('page', nextPage);\n nextUrl = parsed.toString();\n } else {\n nextUrl = undefined;\n }\n }\n return results;\n }\n\n private async fetchAllRoadmapIssues(): Promise<GitLabIssue[]> {\n const issues = await this.fetchAllPages<GitLabIssue>(\n this.roadmapIssuesUrl('desc'),\n );\n await this.cacheIssueMetadata(issues);\n return issues;\n }\n\n private async fetchIssueById(id: string): Promise<GitLabIssue> {\n const pid = await this.resolveProjectId(id);\n const iid = await this.resolveIid(id);\n const { data } = await this.callGitLabApi<GitLabIssue>(\n this.projectApiUrl(`/issues/${iid}`, pid),\n );\n if (this.isGroupMode && data.project_id) {\n await this.cache.set(\n issueProjectCacheKey(String(data.id)),\n String(data.project_id),\n { ttl: PROJECT_MAP_CACHE_TTL_MS },\n );\n }\n await this.cache.set(issueIidCacheKey(String(data.id)), String(data.iid), {\n ttl: PROJECT_MAP_CACHE_TTL_MS,\n });\n return data;\n }\n\n private async createRoadmapIssue(feature: NewFeature): Promise<GitLabIssue> {\n if (this.isGroupMode && !this.defaultProjectId) {\n throw new ConflictError(\n 'Creating features in group mode requires defaultProjectId to be configured',\n );\n }\n const pid = this.isGroupMode ? this.defaultProjectId : this.projectId;\n const { data } = await this.callGitLabApi<GitLabIssue>(\n this.projectApiUrl('/issues', pid),\n {\n method: 'POST',\n body: buildNewRoadmapIssuePayload(feature),\n },\n );\n return data;\n }\n\n private async updateIssueLabels(\n id: string,\n labels: string[],\n ): Promise<GitLabIssue> {\n const pid = await this.resolveProjectId(id);\n const iid = await this.resolveIid(id);\n const { data } = await this.callGitLabApi<GitLabIssue>(\n this.projectApiUrl(`/issues/${iid}`, pid),\n { method: 'PUT', body: JSON.stringify({ labels: labels.join(',') }) },\n );\n return data;\n }\n\n private async fetchIssueNotes(\n featureId: string,\n sort: 'asc' | 'desc' = 'desc',\n ): Promise<GitLabNote[]> {\n const pid = await this.resolveProjectId(featureId);\n const iid = await this.resolveIid(featureId);\n return this.fetchAllPages<GitLabNote>(\n this.projectApiUrl(\n `/issues/${iid}/notes?sort=${sort}&order_by=created_at&${PAGINATION}`,\n pid,\n ),\n );\n }\n\n private async collectVoteMarkersByUser(\n featureId: string,\n ): Promise<Map<string, number>> {\n const notes = await this.fetchIssueNotes(featureId, 'asc');\n const votesByUser = new Map<string, number>();\n for (const note of notes) {\n if (note.system) continue;\n const match = (note.body ?? '').trim().match(VOTE_TAG_RE);\n if (match) votesByUser.set(match[1], note.id);\n }\n return votesByUser;\n }\n\n private async deleteNote(featureId: string, noteId: number): Promise<void> {\n const pid = await this.resolveProjectId(featureId);\n const iid = await this.resolveIid(featureId);\n await this.callGitLabApi<void>(\n this.projectApiUrl(`/issues/${iid}/notes/${noteId}`, pid),\n { method: 'DELETE' },\n );\n }\n\n private async createNote(\n featureId: string,\n body: string,\n ): Promise<GitLabNote> {\n const pid = await this.resolveProjectId(featureId);\n const iid = await this.resolveIid(featureId);\n const { data } = await this.callGitLabApi<GitLabNote>(\n this.projectApiUrl(`/issues/${iid}/notes`, pid),\n { method: 'POST', body: JSON.stringify({ body }) },\n );\n return data;\n }\n\n private async ensureFeatureExists(featureId: string): Promise<void> {\n await this.ensureIssueProjectCached(featureId);\n await this.fetchIssueById(featureId);\n }\n\n private async removeVote(\n featureId: string,\n noteId: number,\n votesByUser: Map<string, number>,\n username: string,\n ): Promise<void> {\n await this.deleteNote(featureId, noteId);\n votesByUser.delete(username);\n }\n\n private async addVote(\n featureId: string,\n votesByUser: Map<string, number>,\n username: string,\n ): Promise<void> {\n await this.createNote(featureId, buildVoteMarker(username));\n votesByUser.set(username, 0);\n }\n\n private async getOrFetchVotes(\n featureId: string,\n ): Promise<Map<string, number>> {\n const cached = await this.getCachedVotes(featureId);\n if (cached) return cached;\n const votes = await this.collectVoteMarkersByUser(featureId);\n await this.setCachedVotes(featureId, votes);\n return votes;\n }\n\n private async collectAllVoteCounts(\n issues: GitLabIssue[],\n ): Promise<Record<string, number>> {\n const counts: Record<string, number> = {};\n await Promise.all(\n issues.map(async issue => {\n const id = String(issue.id);\n const votes = await this.getOrFetchVotes(id);\n counts[id] = votes.size;\n }),\n );\n return counts;\n }\n\n private roadmapIssuesUrl(sort: 'asc' | 'desc' = 'desc'): string {\n const query = `/issues?labels=${ROADMAP_LABEL}&${PAGINATION}&order_by=created_at&sort=${sort}`;\n return this.isGroupMode\n ? this.groupApiUrl(query)\n : this.projectApiUrl(query);\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n await this.ensureIssueProjectCached(comment.featureId);\n const body = buildCommentBody(comment);\n const gitlabNote = await this.createNote(comment.featureId, body);\n return mapGitLabNoteToComment(gitlabNote, comment.featureId);\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n await this.ensureFeatureExists(featureId);\n const allNotes = await this.fetchIssueNotes(featureId, 'desc');\n const commentNotes = filterUserComments(allNotes);\n return convertNotesToComments(commentNotes, featureId);\n }\n\n async addFeature(feature: NewFeature & { author: string }): Promise<Feature> {\n const gitlabIssue = await this.createRoadmapIssue(feature);\n return mapGitLabIssueToFeature(gitlabIssue);\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n this.logger.info('Fetching all roadmap features from GitLab');\n const gitlabIssues = await this.fetchAllRoadmapIssues();\n const voteCounts = await this.collectAllVoteCounts(gitlabIssues);\n return convertIssuesToFeatures(gitlabIssues, voteCounts);\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n await this.ensureIssueProjectCached(id);\n const gitlabIssue = await this.fetchIssueById(id);\n const voteCount = await this.getVoteCount(id);\n return mapGitLabIssueToFeature(gitlabIssue, voteCount);\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n await this.ensureIssueProjectCached(id);\n const existingIssue = await this.fetchIssueById(id);\n const updatedLabels = replaceStatusLabels(\n existingIssue.labels ?? [],\n status,\n );\n const updatedIssue = await this.updateIssueLabels(id, updatedLabels);\n return mapGitLabIssueToFeature(updatedIssue);\n }\n\n async toggleVote(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n await this.ensureIssueProjectCached(featureId);\n await this.invalidateCachedVotes(featureId);\n const username = parseUsernameFromEntityRef(voter);\n const votesByUser = await this.collectVoteMarkersByUser(featureId);\n const existingNoteId = votesByUser.get(username);\n\n if (existingNoteId) {\n await this.removeVote(featureId, existingNoteId, votesByUser, username);\n } else {\n await this.addVote(featureId, votesByUser, username);\n }\n\n await this.setCachedVotes(featureId, votesByUser);\n return { voteAdded: !existingNoteId, voteCount: votesByUser.size };\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n await this.ensureIssueProjectCached(featureId);\n const votes = await this.getOrFetchVotes(featureId);\n return votes.size;\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n const counts: Record<string, number> = {};\n for (const id of featureIds) {\n counts[id] = await this.getVoteCount(id);\n }\n return counts;\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n await this.ensureIssueProjectCached(featureId);\n const username = parseUsernameFromEntityRef(voter);\n const votes = await this.getOrFetchVotes(featureId);\n return votes.has(username);\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n const results: Record<string, boolean> = {};\n for (const id of featureIds) {\n results[id] = await this.hasVoted(id, voter);\n }\n return results;\n }\n}\n"],"names":["FeatureStatus","parseEntityRef","NotFoundError","NotAllowedError","ConflictError"],"mappings":";;;;;;AAiBA,MAAM,aAAA,GAAgB,SAAA;AACtB,MAAM,mBAAA,GAAsB,GAAG,aAAa,CAAA,EAAA,CAAA;AAC5C,MAAM,aAAA,GAAgB,MAAA,CAAO,MAAA,CAAOA,0CAAa,CAAA,CAAE,GAAA;AAAA,EACjD,CAAA,MAAA,KAAU,CAAA,EAAG,mBAAmB,CAAA,EAAG,MAAM,CAAA;AAC3C,CAAA;AACA,MAAM,UAAA,GAAa,cAAA;AAEnB,MAAM,aAAA,GAAgB,0BAAA;AACtB,MAAM,WAAA,GAAc,uBAAA;AAwBpB,SAAS,0BAA0B,MAAA,EAA+B;AAChE,EAAA,OAAO,CAAA,EAAG,mBAAmB,CAAA,EAAG,MAAM,CAAA,CAAA;AACxC;AAEA,SAAS,wBAAwB,MAAA,EAAiC;AAChE,EAAA,MAAM,QAAQ,MAAA,CAAO,IAAA,CAAK,OAAK,aAAA,CAAc,QAAA,CAAS,CAAC,CAAC,CAAA;AACxD,EAAA,IAAI,CAAC,KAAA,EAAO,OAAOA,0CAAA,CAAc,SAAA;AACjC,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,mBAAA,EAAqB,EAAE,CAAA;AAC9C;AAEA,SAAS,mBAAA,CACP,QACA,SAAA,EACU;AACV,EAAA,MAAM,OAAA,GAAU,OAAO,MAAA,CAAO,CAAA,CAAA,KAAK,CAAC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gB,SAAS,CAAA;AAClD,IAAA,OAAO,KAAA,CAAM,IAAI,QAAQ,CAAA;AAAA,EAC3B;AAAA,EAEA,MAAM,aAAA,CACJ,UAAA,EACA,KAAA,EACkC;AAClC,IAAA,MAAM,UAAmC,EAAC;AAC1C,IAAA,KAAA,MAAW,MAAM,UAAA,EAAY;AAC3B,MAAA,OAAA,CAAQ,EAAE,CAAA,GAAI,MAAM,IAAA,CAAK,QAAA,CAAS,IAAI,KAAK,CAAA;AAAA,IAC7C;AACA,IAAA,OAAO,OAAA;AAAA,EACT;AACF;;;;"}
|
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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iBAAA,EAAmB;AACtB,UAAA,MAAA,CAAO,IAAA;AAAA,YACL;AAAA,WACF;AAAA,QACF;AAEA,QAAA,UAAA,CAAW,GAAA;AAAA,UACT,MAAMQ,mBAAA,CAAa;AAAA,YACjB,MAAA;AAAA,oBACAR,QAAA;AAAA,YACA,EAAA;AAAA,YACA,QAAA;AAAA,YACA,QAAA;AAAA,YACA,WAAA,EAAa,oBAAoB,WAAA,GAAc,MAAA;AAAA,YAC/C,KAAA;AAAA,YACA,UAAA;AAAA,YACA,YAAA;AAAA,YACA,mBAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AACA,QAAA,UAAA,CAAW,aAAA,CAAc;AAAA,UACvB,IAAA,EAAM,SAAA;AAAA,UACN,KAAA,EAAO;AAAA,SACR,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
|
|
@@ -3,6 +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,EAAQ,EAAA,EAAI,UAAA,EAAW,GAAI,OAAA;AACnC,EAAA,MAAM,SAASA,uBAAA,EAAO;AAGtB,EAAA,MAAM,cAAA,GAAiB,IAAIC,6BAAA,CAAe,EAAA,EAAI,QAAQ,UAAU,CAAA;AAChE,EAAA,MAAM,iBAAA,GAAoB,IAAIC,mCAAA,CAAkB,OAAO,CAAA;AACvD,EAAA,MAAM,oBAAA,GAAuB,OAAA,CAAQ,aAAA,GACjC,IAAIC,qDAAA;AAAA,IACF,OAAA,CAAQ,aAAA;AAAA,IACR,MAAA;AAAA,IACAC,oBAAA,CAAc,QAAQ,MAAM;AAAA,GAC9B,GACA,MAAA;AAGJ,EAAA,MAAA,CAAO,IAAA,CAAK,GAAA,EAAK,OAAO,GAAA,EAAK,KAAK,IAAA,KAAS;AACzC,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,iBAAA,CAAkB,WAAA,CAAY,GAAG,CAAA;AACxD,MAAA,MAAM,EAAE,SAAA,EAAW,IAAA,EAAK,GAAI,GAAA,CAAI,IAAA;AAEhC,MAAA,MA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AO,aAAA,EAAe,OAAO,GAAA,EAAK,KAAK,IAAA,KAAS;AACrD,IAAA,IAAI;AACF,MAAA,IAAI,eAAe,UAAA,EAAY;AAC7B,QAAA,MAAM,IAAIC,sBAAA;AAAA,UACR;AAAA,SACF;AAAA,MACF;AACA,MAAA,MAAM,QAAA,GAAW,MAAM,iBAAA,CAAkB,WAAA,CAAY,GAAG,CAAA;AACxD,MAAA,MAAM,OAAA,GAAU,MAAM,iBAAA,CAAkB,cAAA,CAAe,KAAK,QAAQ,CAAA;AACpE,MAAA,IAAI,CAAC,OAAA,EAAS;AACZ,QAAA,MAAM,IAAIA,uBAAgB,6BAA6B,CAAA;AAAA,MACzD;AACA,MAAA,MAAM,EAAE,SAAA,EAAU,GAAI,GAAA,CAAI,MAAA;AAC1B,MAAA,MAAM,cAAA,CAAe,cAAc,SAAS,CAAA;AAC5C,MAAA,GAAA,CAAI,MAAA,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,OAAwC,EAAA;AACrE,EAAA,MAAM,EAAE,MAAA,EAAQ,EAAI,EAAA,YAAA,EAAc,YAAe,GAAA,OAAA;AACjD,EAAA,MAAM,SAASA,uBAAO,EAAA;AAGtB,EAAA,MAAM,iBAAiB,IAAIC,6BAAA;AAAA,IACzB,EAAA;AAAA,IACA,MAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACA,EAAM,MAAA,iBAAA,GAAoB,IAAIC,mCAAA,CAAkB,OAAO,CAAA;AAEvD,EAAA,MAAA,CAAO,GAAI,CAAA,eAAA,EAAiB,OAAO,IAAA,EAAM,KAAK,IAAS,KAAA;AACrD,IAAI,IAAA;AACF,MAAA,GAAA,CAAI,MAAO,CAAA,GAAG,CAAE,CAAA,IAAA,CAAK,QAAQ,mBAAmB,CAAA;AAAA,aACzC,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA;AACZ,GACD,CAAA;AAGD,EAAA,MAAA,CAAO,IAAK,CAAA,GAAA,EAAK,OAAO,GAAA,EAAK,KAAK,IAAS,KAAA;AACzC,IAAI,IAAA;AACF,MAAA,MAAM,QAAW,GAAA,MAAM,iBAAkB,CAAA,WAAA,CAAY,GAAG,CAAA;AACxD,MAAA,MAAM,SAAY,GAAA,MAAM,iBAAkB,CAAA,gBAAA,CAAiB,KAAK,QAAQ,CAAA;AACxE,MAAA,IAAI,CAAC,SAAW,EAAA;AACd,QAAA,MAAM,IAAIC,sBAAA;AAAA,UACR;AAAA,SACF;AAAA;AAEF,MAAA,MAAM,EAAE,KAAA,EAAO,WAAY,EAAA,GAAI,GAAI,CAAA,IAAA;AAEnC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,MAAA,cAAA,CAAe,+BAAgC,CAAA,EAAA,EAAI,QAAQ,CAAA;AACjE,MAAM,MAAA,cAAA,CAAe,cAAc,EAAE,CAAA;AACrC,MAAI,GAAA,CAAA,MAAA,CAAO,GAAG,CAAA,CAAE,IAAK,EAAA;AAAA,aACd,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA;AACZ,GACD,CAAA;AAGD,EAAA,MAAA,CAAO,GAAI,CAAA,MAAA,EAAQ,OAAO,GAAA,EAAK,KAAK,IAAS,KAAA;AAC3C,IAAI,IAAA;AACF,MAAM,MAAA,EAAE,EAAG,EAAA,GAAI,GAAI,CAAA,MAAA;AACnB,MAAA,MAAM,OAAU,GAAA,MAAM,cAAe,CAAA,cAAA,CAAe,EAAE,CAAA;AACtD,MAAA,GAAA,CAAI,MAAO,CAAA,GAAG,CAAE,CAAA,IAAA,CAAK,OAAO,CAAA;AAAA,aACrB,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA;AACZ,GACD,CAAA;AAED,EAAO,OAAA,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,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;AACvD,EAAA,MAAM,oBAAA,GAAuB,OAAA,CAAQ,aAAA,GACjC,IAAIC,qDAAA;AAAA,IACF,OAAA,CAAQ,aAAA;AAAA,IACR,MAAA;AAAA,IACAC,oBAAA,CAAc,QAAQ,MAAM;AAAA,GAC9B,GACA,MAAA;AAEJ,EAAA,MAAA,CAAO,GAAA,CAAI,eAAA,EAAiB,OAAO,IAAA,EAAM,KAAK,IAAA,KAAS;AACrD,IAAA,IAAI;AACF,MAAA,GAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK,QAAQ,mBAAmB,CAAA;AAAA,IAClD,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA,IACZ;AAAA,EACF,CAAC,CAAA;AAGD,EAAA,MAAA,CAAO,IAAA,CAAK,GAAA,EAAK,OAAO,GAAA,EAAK,KAAK,IAAA,KAAS;AACzC,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GA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A,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissionCheckRouter.cjs.js","sources":["../../src/routes/permissionCheckRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { roadmapAdminPermission } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { PermissionService } from '../services/PermissionService';\n\n/**\n * Router for permission-checking endpoints\n */\nexport function permissionCheckRouter(options: RouterOptions): express.Router {\n const router = Router();\n\n // Initialize service\n const permissionService = new PermissionService(options);\n\n // Check if the current user is an admin\n router.get('/check-admin', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.checkPermission(\n req,\n username,\n roadmapAdminPermission,\n );\n\n res.json(isAdmin);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","PermissionService","roadmapAdminPermission"],"mappings":";;;;;;;;;;AASO,SAAS,sBAAsB,
|
|
1
|
+
{"version":3,"file":"permissionCheckRouter.cjs.js","sources":["../../src/routes/permissionCheckRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { roadmapAdminPermission } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { PermissionService } from '../services/PermissionService';\n\n/**\n * Router for permission-checking endpoints\n */\nexport function permissionCheckRouter(options: RouterOptions): express.Router {\n const router = Router();\n\n // Initialize service\n const permissionService = new PermissionService(options);\n\n // Check if the current user is an admin\n router.get('/check-admin', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.checkPermission(\n req,\n username,\n roadmapAdminPermission,\n );\n\n res.json(isAdmin);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","PermissionService","roadmapAdminPermission"],"mappings":";;;;;;;;;;AASO,SAAS,sBAAsB,OAAA,EAAwC;AAC5E,EAAA,MAAM,SAASA,uBAAA,EAAO;AAGtB,EAAA,MAAM,iBAAA,GAAoB,IAAIC,mCAAA,CAAkB,OAAO,CAAA;AAGvD,EAAA,MAAA,CAAO,GAAA,CAAI,cAAA,EAAgB,OAAO,GAAA,EAAK,KAAK,IAAA,KAAS;AACnD,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,iBAAA,CAAkB,WAAA,CAAY,GAAG,CAAA;AACxD,MAAA,MAAM,OAAA,GAAU,MAAM,iBAAA,CAAkB,eAAA;AAAA,QACtC,GAAA;AAAA,QACA,QAAA;AAAA,QACAC;AAAA,OACF;AAEA,MAAA,GAAA,CAAI,KAAK,OAAO,CAAA;AAAA,IAClB,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA,IACZ;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
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 { 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;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"votesRouter.cjs.js","sources":["../../src/routes/votesRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { VoteService } from '../services/VoteService';\nimport { PermissionService } from '../services/PermissionService';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Router for vote-related endpoints\n */\nexport function votesRouter(options: RouterOptions): express.Router {\n const { logger, db } = options;\n const router = Router();\n\n // Initialize services\n const voteService = new VoteService(db, logger);\n const permissionService = new PermissionService(options);\n\n // Get vote counts for multiple features\n router.get('/counts', async (req, res, next) => {\n try {\n const idsParam = req.query.ids;\n\n // Handle empty parameter case gracefully\n if (!idsParam || typeof idsParam !== 'string' || idsParam === '') {\n res.json({});\n return;\n }\n\n const featureIds = idsParam.split(',').filter(Boolean);\n\n if (featureIds.length === 0) {\n res.json({});\n return;\n }\n\n const voteCounts = await voteService.getVoteCounts(featureIds);\n res.json(voteCounts);\n } catch (error) {\n next(error);\n }\n });\n\n // Check if user has voted on multiple features (batch)\n router.get('/user/batch', async (req, res, next) => {\n try {\n const idsParam = req.query.ids;\n\n // Handle empty parameter case gracefully\n if (!idsParam || typeof idsParam !== 'string' || idsParam === '') {\n res.json({});\n return;\n }\n\n const featureIds = idsParam.split(',').filter(Boolean);\n\n if (featureIds.length === 0) {\n res.json({});\n return;\n }\n\n const username = await permissionService.getUsername(req);\n const hasVotedMap = await voteService.hasVotedBatch(featureIds, username);\n\n res.json(hasVotedMap);\n } catch (error) {\n next(error);\n }\n });\n\n // --- Parameterized routes below ---\n\n // Toggle vote for a feature\n router.post('/:featureId', async (req, res, next) => {\n try {\n const featureId = req.params.featureId;\n\n if (!featureId) {\n throw new InputError('Feature ID is required');\n }\n\n const username = await permissionService.getUsername(req);\n const result = await voteService.toggleVote(featureId, username);\n\n res.status(200).json(result);\n } catch (error) {\n next(error);\n }\n });\n\n // Get vote count for a feature\n router.get('/:featureId/count', async (req, res, next) => {\n try {\n const featureId = req.params.featureId;\n\n if (!featureId) {\n throw new InputError('Feature ID is required');\n }\n\n const count = await voteService.getVoteCount(featureId);\n res.json(count);\n } catch (error) {\n next(error);\n }\n });\n\n // Check if a user has voted on a feature\n router.get('/:featureId/user', async (req, res, next) => {\n try {\n const featureId = req.params.featureId;\n\n if (!featureId) {\n throw new InputError('Feature ID is required');\n }\n\n const username = await permissionService.getUsername(req);\n const hasVoted = await voteService.hasVoted(featureId, username);\n\n res.json(hasVoted);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","VoteService","PermissionService","InputError"],"mappings":";;;;;;;;;;;AAUO,SAAS,YAAY,
|
|
1
|
+
{"version":3,"file":"votesRouter.cjs.js","sources":["../../src/routes/votesRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { VoteService } from '../services/VoteService';\nimport { PermissionService } from '../services/PermissionService';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Router for vote-related endpoints\n */\nexport function votesRouter(options: RouterOptions): express.Router {\n const { logger, db } = options;\n const router = Router();\n\n // Initialize services\n const voteService = new VoteService(db, logger);\n const permissionService = new PermissionService(options);\n\n // Get vote counts for multiple features\n router.get('/counts', async (req, res, next) => {\n try {\n const idsParam = req.query.ids;\n\n // Handle empty parameter case gracefully\n if (!idsParam || typeof idsParam !== 'string' || idsParam === '') {\n res.json({});\n return;\n }\n\n const featureIds = idsParam.split(',').filter(Boolean);\n\n if (featureIds.length === 0) {\n res.json({});\n return;\n }\n\n const voteCounts = await voteService.getVoteCounts(featureIds);\n res.json(voteCounts);\n } catch (error) {\n next(error);\n }\n });\n\n // Check if user has voted on multiple features (batch)\n router.get('/user/batch', async (req, res, next) => {\n try {\n const idsParam = req.query.ids;\n\n // Handle empty parameter case gracefully\n if (!idsParam || typeof idsParam !== 'string' || idsParam === '') {\n res.json({});\n return;\n }\n\n const featureIds = idsParam.split(',').filter(Boolean);\n\n if (featureIds.length === 0) {\n res.json({});\n return;\n }\n\n const username = await permissionService.getUsername(req);\n const hasVotedMap = await voteService.hasVotedBatch(featureIds, username);\n\n res.json(hasVotedMap);\n } catch (error) {\n next(error);\n }\n });\n\n // --- Parameterized routes below ---\n\n // Toggle vote for a feature\n router.post('/:featureId', async (req, res, next) => {\n try {\n const featureId = req.params.featureId;\n\n if (!featureId) {\n throw new InputError('Feature ID is required');\n }\n\n const username = await permissionService.getUsername(req);\n const result = await voteService.toggleVote(featureId, username);\n\n res.status(200).json(result);\n } catch (error) {\n next(error);\n }\n });\n\n // Get vote count for a feature\n router.get('/:featureId/count', async (req, res, next) => {\n try {\n const featureId = req.params.featureId;\n\n if (!featureId) {\n throw new InputError('Feature ID is required');\n }\n\n const count = await voteService.getVoteCount(featureId);\n res.json(count);\n } catch (error) {\n next(error);\n }\n });\n\n // Check if a user has voted on a feature\n router.get('/:featureId/user', async (req, res, next) => {\n try {\n const featureId = req.params.featureId;\n\n if (!featureId) {\n throw new InputError('Feature ID is required');\n }\n\n const username = await permissionService.getUsername(req);\n const hasVoted = await voteService.hasVoted(featureId, username);\n\n res.json(hasVoted);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","VoteService","PermissionService","InputError"],"mappings":";;;;;;;;;;;AAUO,SAAS,YAAY,OAAA,EAAwC;AAClE,EAAA,MAAM,EAAE,MAAA,EAAQ,EAAA,EAAG,GAAI,OAAA;AACvB,EAAA,MAAM,SAASA,uBAAA,EAAO;AAGtB,EAAA,MAAM,WAAA,GAAc,IAAIC,uBAAA,CAAY,EAAA,EAAI,MAAM,CAAA;AAC9C,EAAA,MAAM,iBAAA,GAAoB,IAAIC,mCAAA,CAAkB,OAAO,CAAA;AAGvD,EAAA,MAAA,CAAO,GAAA,CAAI,SAAA,EAAW,OAAO,GAAA,EAAK,KAAK,IAAA,KAAS;AAC9C,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,IAAI,KAAA,CAAM,GAAA;AAG3B,MAAA,IAAI,CAAC,QAAA,IAAY,OAAO,QAAA,KAAa,QAAA,IAAY,aAAa,EAAA,EAAI;AAChE,QAAA,GAAA,CAAI,IAAA,CAAK,EAAE,CAAA;AACX,QAAA;AAAA,MACF;AAEA,MA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EAAW;AACd,QAAA,MAAM,IAAIA,kBAAW,wBAAwB,CAAA;AAAA,MAC/C;AAEA,MAAA,MAAM,QAAA,GAAW,MAAM,iBAAA,CAAkB,WAAA,CAAY,GAAG,CAAA;AACxD,MAAA,MAAM,QAAA,GAAW,MAAM,WAAA,CAAY,QAAA,CAAS,WAAW,QAAQ,CAAA;AAE/D,MAAA,GAAA,CAAI,KAAK,QAAQ,CAAA;AAAA,IACnB,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA,IACZ;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommentService.cjs.js","sources":["../../src/services/CommentService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatasource } from '../types';\nimport { DatasourceType } from '../types';\nimport { CommentServiceInterface } from './types';\nimport {\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { InputError, NotAllowedError } from '@backstage/errors';\nimport { RoadmapDatabaseClient } from '../database/RoadmapDatabaseClient';\n\n/**\n * Implementation of the Comment Service\n */\nexport class CommentService implements CommentServiceInterface {\n constructor(\n private readonly db: RoadmapDatasource,\n private readonly logger: LoggerService,\n private readonly datasource: DatasourceType,\n ) {}\n\n /**\n * Validates a comment before adding it\n */\n private validateNewComment(comment: NewComment): void {\n if (!comment.featureId) {\n throw new InputError('Feature ID is required');\n }\n\n if (!comment.text || comment.text.trim() === '') {\n throw new InputError('Comment text is required and cannot be empty');\n }\n\n if (comment.text.length > 1000) {\n throw new InputError(\n 'Comment text cannot be longer than 1000 characters',\n );\n }\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n this.logger.info(`Adding comment to feature ${comment.featureId}`);\n this.validateNewComment(comment);\n return this.db.addComment(comment);\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n this.logger.info(`Fetching comments for feature ${featureId}`);\n return this.db.getCommentsByFeatureId(featureId);\n }\n\n /** Database only; GitLab roadmap does not support deleting notes via this plugin. */\n async deleteComment(commentId: string): Promise<void> {\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 this.logger.info(`Deleting comment ${commentId}`);\n await this.db.deleteCommentById(commentId);\n }\n}\n"],"names":["InputError","RoadmapDatabaseClient","NotAllowedError"],"mappings":";;;;;AAcO,MAAM,
|
|
1
|
+
{"version":3,"file":"CommentService.cjs.js","sources":["../../src/services/CommentService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatasource } from '../types';\nimport { DatasourceType } from '../types';\nimport { CommentServiceInterface } from './types';\nimport {\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { InputError, NotAllowedError } from '@backstage/errors';\nimport { RoadmapDatabaseClient } from '../database/RoadmapDatabaseClient';\n\n/**\n * Implementation of the Comment Service\n */\nexport class CommentService implements CommentServiceInterface {\n constructor(\n private readonly db: RoadmapDatasource,\n private readonly logger: LoggerService,\n private readonly datasource: DatasourceType,\n ) {}\n\n /**\n * Validates a comment before adding it\n */\n private validateNewComment(comment: NewComment): void {\n if (!comment.featureId) {\n throw new InputError('Feature ID is required');\n }\n\n if (!comment.text || comment.text.trim() === '') {\n throw new InputError('Comment text is required and cannot be empty');\n }\n\n if (comment.text.length > 1000) {\n throw new InputError(\n 'Comment text cannot be longer than 1000 characters',\n );\n }\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n this.logger.info(`Adding comment to feature ${comment.featureId}`);\n this.validateNewComment(comment);\n return this.db.addComment(comment);\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n this.logger.info(`Fetching comments for feature ${featureId}`);\n return this.db.getCommentsByFeatureId(featureId);\n }\n\n /** Database only; GitLab roadmap does not support deleting notes via this plugin. */\n async deleteComment(commentId: string): Promise<void> {\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 this.logger.info(`Deleting comment ${commentId}`);\n await this.db.deleteCommentById(commentId);\n }\n}\n"],"names":["InputError","RoadmapDatabaseClient","NotAllowedError"],"mappings":";;;;;AAcO,MAAM,cAAA,CAAkD;AAAA,EAC7D,WAAA,CACmB,EAAA,EACA,MAAA,EACA,UAAA,EACjB;AAHiB,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAChB;AAAA,EAHgB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA;AAAA;AAAA;AAAA,EAMX,mBAAmB,OAAA,EAA2B;AACpD,IAAA,IAAI,CAAC,QAAQ,SAAA,EAAW;AACtB,MAAA,MAAM,IAAIA,kBAAW,wBAAwB,CAAA;AAAA,IAC/C;AAEA,IAAA,IAAI,CAAC,OAAA,CAAQ,IAAA,IAAQ,QAAQ,IAAA,CAAK,IAAA,OAAW,EAAA,EAAI;AAC/C,MAAA,MAAM,IAAIA,kBAAW,8CAA8C,CAAA;AAAA,IACrE;AAEA,IAAA,IAAI,OAAA,CAAQ,IAAA,CAAK,MAAA,GAAS,GAAA,EAAM;AAC9B,MAAA,MAAM,IAAIA,iBAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,OAAA,EAAuC;AACtD,IAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,CAAA,0BAAA,EAA6B,OAAA,CAAQ,SAAS,CAAA,CAAE,CAAA;AACjE,IAAA,IAAA,CAAK,mBAAmB,OAAO,CAAA;AAC/B,IAAA,OAAO,IAAA,CAAK,EAAA,CAAG,UAAA,CAAW,OAAO,CAAA;AAAA,EACnC;AAAA,EAEA,MAAM,uBAAuB,SAAA,EAAuC;AAClE,IAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,CAAA,8BAAA,EAAiC,SAAS,CAAA,CAAE,CAAA;AAC7D,IAAA,OAAO,IAAA,CAAK,EAAA,CAAG,sBAAA,CAAuB,SAAS,CAAA;AAAA,EACjD;AAAA;AAAA,EAGA,MAAM,cAAc,SAAA,EAAkC;AACpD,IAAA,IACE,KAAK,UAAA,KAAe,UAAA,IACpB,EAAE,IAAA,CAAK,cAAcC,2CAAA,CAAA,EACrB;AACA,MAAA,MAAM,IAAIC,sBAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AACA,IAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,CAAA,iBAAA,EAAoB,SAAS,CAAA,CAAE,CAAA;AAChD,IAAA,MAAM,IAAA,CAAK,EAAA,CAAG,iBAAA,CAAkB,SAAS,CAAA;AAAA,EAC3C;AACF;;;;"}
|
|
@@ -12,6 +12,10 @@ class FeatureService {
|
|
|
12
12
|
this.boardColumns = boardColumns;
|
|
13
13
|
this.datasource = datasource;
|
|
14
14
|
}
|
|
15
|
+
db;
|
|
16
|
+
logger;
|
|
17
|
+
boardColumns;
|
|
18
|
+
datasource;
|
|
15
19
|
/** Ensures we are on the Knex-backed datasource before DB-only operations. */
|
|
16
20
|
requireDatabase() {
|
|
17
21
|
if (this.datasource !== "database" || !(this.db instanceof RoadmapDatabaseClient.RoadmapDatabaseClient)) {
|
|
@@ -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 { 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,
|
|
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,cAAA,CAAkD;AAAA,EAC7D,WAAA,CACmB,EAAA,EACA,MAAA,EACA,YAAA,EACA,UAAA,EACjB;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,EAChB;AAAA,EAJgB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,UAAA;AAAA;AAAA,EAIX,eAAA,GAAyC;AAC/C,IAAA,IACE,KAAK,UAAA,KAAe,UAAA,IACpB,EAAE,IAAA,CAAK,cAAcA,2CAAA,CAAA,EACrB;AACA,MAAA,MAAM,IAAIC,sBAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AACA,IAAA,OAAO,IAAA,CAAK,EAAA;AAA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ermissionService.cjs.js","sources":["../../src/services/PermissionService.ts"],"sourcesContent":["import { Request } from 'express';\nimport { PermissionServiceInterface } from './types';\nimport { RouterOptions } from '../routes/router';\nimport {\n roadmapAdminPermission,\n roadmapCreatePermission,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { BasicPermission } from '@backstage/plugin-permission-common';\nimport { NotFoundError, NotAllowedError } from '@backstage/errors';\nimport { getAdminUsers } from '../config';\nimport {\n AuthorizeResult,\n DefinitivePolicyDecision,\n} from '@backstage/plugin-permission-common';\n\n/**\n * Implementation of the Permission Service\n */\nexport class PermissionService implements PermissionServiceInterface {\n private readonly options: RouterOptions;\n\n constructor(options: RouterOptions) {\n this.options = options;\n }\n\n async getUsername(req: Request): Promise<string> {\n const { httpAuth, userInfo, logger } = this.options;\n const credentials = await httpAuth.credentials(req);\n if (!credentials) {\n logger.warn('Unauthorized access attempt');\n throw new NotAllowedError('Unauthorized access');\n }\n const user = await userInfo.getUserInfo(credentials);\n const username = user?.userEntityRef?.toString();\n if (!username) {\n logger.warn('User not found');\n throw new NotFoundError('User not found');\n }\n return username;\n }\n\n async checkPermission(\n req: Request,\n username: string,\n permission: BasicPermission,\n ): Promise<boolean> {\n const { config, logger, permissions, httpAuth } = this.options;\n const adminUsers = getAdminUsers(config);\n\n // Admin users early exit\n if (adminUsers.includes(username)) {\n return true;\n }\n\n // Check if permissions service is available\n if (!permissions) {\n return false;\n }\n\n // Authenticate request credentials\n const credentials = await httpAuth.credentials(req);\n if (!credentials) {\n logger.warn(`Unauthorized access attempt by user ${username}`);\n throw new NotAllowedError('Unauthorized access');\n }\n\n let decision: DefinitivePolicyDecision = { result: AuthorizeResult.DENY };\n\n try {\n // Authorize user with permission service\n decision = (\n await permissions.authorize([{ permission }], {\n credentials,\n })\n )[0];\n\n const isAllowed = decision.result === AuthorizeResult.ALLOW;\n logger.info(\n `Permission ${permission.name} ${\n isAllowed ? 'granted' : 'denied'\n } to user ${username}`,\n );\n\n return isAllowed;\n } catch (error) {\n logger.error(`Error while authorizing user ${username}`);\n throw new NotAllowedError('Permission check failed');\n }\n }\n\n async isRoadmapAdmin(req: Request, username: string): Promise<boolean> {\n return this.checkPermission(req, username, roadmapAdminPermission);\n }\n\n async canCreateFeature(req: Request, username: string): Promise<boolean> {\n return this.checkPermission(req, username, roadmapCreatePermission);\n }\n}\n"],"names":["NotAllowedError","NotFoundError","config","getAdminUsers","AuthorizeResult","roadmapAdminPermission","roadmapCreatePermission"],"mappings":";;;;;;;AAkBO,MAAM,
|
|
1
|
+
{"version":3,"file":"PermissionService.cjs.js","sources":["../../src/services/PermissionService.ts"],"sourcesContent":["import { Request } from 'express';\nimport { PermissionServiceInterface } from './types';\nimport { RouterOptions } from '../routes/router';\nimport {\n roadmapAdminPermission,\n roadmapCreatePermission,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { BasicPermission } from '@backstage/plugin-permission-common';\nimport { NotFoundError, NotAllowedError } from '@backstage/errors';\nimport { getAdminUsers } from '../config';\nimport {\n AuthorizeResult,\n DefinitivePolicyDecision,\n} from '@backstage/plugin-permission-common';\n\n/**\n * Implementation of the Permission Service\n */\nexport class PermissionService implements PermissionServiceInterface {\n private readonly options: RouterOptions;\n\n constructor(options: RouterOptions) {\n this.options = options;\n }\n\n async getUsername(req: Request): Promise<string> {\n const { httpAuth, userInfo, logger } = this.options;\n const credentials = await httpAuth.credentials(req);\n if (!credentials) {\n logger.warn('Unauthorized access attempt');\n throw new NotAllowedError('Unauthorized access');\n }\n const user = await userInfo.getUserInfo(credentials);\n const username = user?.userEntityRef?.toString();\n if (!username) {\n logger.warn('User not found');\n throw new NotFoundError('User not found');\n }\n return username;\n }\n\n async checkPermission(\n req: Request,\n username: string,\n permission: BasicPermission,\n ): Promise<boolean> {\n const { config, logger, permissions, httpAuth } = this.options;\n const adminUsers = getAdminUsers(config);\n\n // Admin users early exit\n if (adminUsers.includes(username)) {\n return true;\n }\n\n // Check if permissions service is available\n if (!permissions) {\n return false;\n }\n\n // Authenticate request credentials\n const credentials = await httpAuth.credentials(req);\n if (!credentials) {\n logger.warn(`Unauthorized access attempt by user ${username}`);\n throw new NotAllowedError('Unauthorized access');\n }\n\n let decision: DefinitivePolicyDecision = { result: AuthorizeResult.DENY };\n\n try {\n // Authorize user with permission service\n decision = (\n await permissions.authorize([{ permission }], {\n credentials,\n })\n )[0];\n\n const isAllowed = decision.result === AuthorizeResult.ALLOW;\n logger.info(\n `Permission ${permission.name} ${\n isAllowed ? 'granted' : 'denied'\n } to user ${username}`,\n );\n\n return isAllowed;\n } catch (error) {\n logger.error(`Error while authorizing user ${username}`);\n throw new NotAllowedError('Permission check failed');\n }\n }\n\n async isRoadmapAdmin(req: Request, username: string): Promise<boolean> {\n return this.checkPermission(req, username, roadmapAdminPermission);\n }\n\n async canCreateFeature(req: Request, username: string): Promise<boolean> {\n return this.checkPermission(req, username, roadmapCreatePermission);\n }\n}\n"],"names":["NotAllowedError","NotFoundError","config","getAdminUsers","AuthorizeResult","roadmapAdminPermission","roadmapCreatePermission"],"mappings":";;;;;;;AAkBO,MAAM,iBAAA,CAAwD;AAAA,EAClD,OAAA;AAAA,EAEjB,YAAY,OAAA,EAAwB;AAClC,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AAAA,EAEA,MAAM,YAAY,GAAA,EAA+B;AAC/C,IAAA,MAAM,EAAE,QAAA,EAAU,QAAA,EAAU,MAAA,KAAW,IAAA,CAAK,OAAA;AAC5C,IAAA,MAAM,WAAA,GAAc,MAAM,QAAA,CAAS,WAAA,CAAY,GAAG,CAAA;AAClD,IAAA,IAAI,CAAC,WAAA,EAAa;AAChB,MAAA,MAAA,CAAO,KAAK,6BAA6B,CAAA;AACzC,MAAA,MAAM,IAAIA,uBAAgB,qBAAqB,CAAA;AAAA,IACjD;AACA,IAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,WAAA,CAAY,WAAW,CAAA;AACnD,IAAA,MAAM,QAAA,GAAW,IAAA,EAAM,aA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AA,GAAY,QAC1B,YAAY,QAAQ,CAAA;AAAA,OACtB;AAEA,MAAA,OAAO,SAAA;AAAA,IACT,SAAS,KAAA,EAAO;AACd,MAAA,MAAA,CAAO,KAAA,CAAM,CAAA,6BAAA,EAAgC,QAAQ,CAAA,CAAE,CAAA;AACvD,MAAA,MAAM,IAAIJ,uBAAgB,yBAAyB,CAAA;AAAA,IACrD;AAAA,EACF;AAAA,EAEA,MAAM,cAAA,CAAe,GAAA,EAAc,QAAA,EAAoC;AACrE,IAAA,OAAO,IAAA,CAAK,eAAA,CAAgB,GAAA,EAAK,QAAA,EAAUK,mDAAsB,CAAA;AAAA,EACnE;AAAA,EAEA,MAAM,gBAAA,CAAiB,GAAA,EAAc,QAAA,EAAoC;AACvE,IAAA,OAAO,IAAA,CAAK,eAAA,CAAgB,GAAA,EAAK,QAAA,EAAUC,oDAAuB,CAAA;AAAA,EACpE;AACF;;;;"}
|
|
@@ -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,KAA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AAK,IAAA,CAAK;AAAA,MACR,YAAY,EAAE,IAAA,EAAM,QAAA,EAAU,SAAA,EAAW,QAAQ,MAAA,EAAO;AAAA,MACxD,OAAA,EAAS;AAAA,QACP,KAAA,EAAO,CAAA,gBAAA,EAAmB,OAAA,CAAQ,KAAK,CAAA,CAAA,CAAA;AAAA,QACvC,aAAa,CAAA,EAAG,WAAA;AAAA,UACd;AAAA,SACD,CAAA,sCAAA,CAAA;AAAA,QACD,IAAA,EAAM,WAAA,CAAY,OAAA,CAAQ,EAAE,CAAA;AAAA,QAC5B,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;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoteService.cjs.js","sources":["../../src/services/VoteService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatasource } from '../types';\nimport { VoteServiceInterface } from './types';\n\n/**\n * Implementation of the Vote Service\n */\nexport class VoteService implements VoteServiceInterface {\n constructor(\n private readonly db: RoadmapDatasource,\n private readonly logger: LoggerService,\n ) {}\n\n async toggleVote(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n this.logger.info(`Toggling vote for feature ${featureId} by ${voter}`);\n return this.db.toggleVote(featureId, voter);\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n this.logger.info(`Getting vote count for feature ${featureId}`);\n return this.db.getVoteCount(featureId);\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n this.logger.info(`Getting vote counts for ${featureIds.length} features`);\n if (featureIds.length === 0) {\n return {};\n }\n return this.db.getVoteCounts(featureIds);\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n this.logger.info(`Checking if ${voter} has voted on feature ${featureId}`);\n return this.db.hasVoted(featureId, voter);\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n this.logger.info(\n `Checking if ${voter} has voted on ${featureIds.length} features`,\n );\n if (featureIds.length === 0) {\n return {};\n }\n return this.db.hasVotedBatch(featureIds, voter);\n }\n}\n"],"names":[],"mappings":";;AAOO,MAAM,
|
|
1
|
+
{"version":3,"file":"VoteService.cjs.js","sources":["../../src/services/VoteService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatasource } from '../types';\nimport { VoteServiceInterface } from './types';\n\n/**\n * Implementation of the Vote Service\n */\nexport class VoteService implements VoteServiceInterface {\n constructor(\n private readonly db: RoadmapDatasource,\n private readonly logger: LoggerService,\n ) {}\n\n async toggleVote(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n this.logger.info(`Toggling vote for feature ${featureId} by ${voter}`);\n return this.db.toggleVote(featureId, voter);\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n this.logger.info(`Getting vote count for feature ${featureId}`);\n return this.db.getVoteCount(featureId);\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n this.logger.info(`Getting vote counts for ${featureIds.length} features`);\n if (featureIds.length === 0) {\n return {};\n }\n return this.db.getVoteCounts(featureIds);\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n this.logger.info(`Checking if ${voter} has voted on feature ${featureId}`);\n return this.db.hasVoted(featureId, voter);\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n this.logger.info(\n `Checking if ${voter} has voted on ${featureIds.length} features`,\n );\n if (featureIds.length === 0) {\n return {};\n }\n return this.db.hasVotedBat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,SAAA,EAAW,KAAK,CAAA;AAAA,EAC1C;AAAA,EAEA,MAAM,aAAA,CACJ,UAAA,EACA,KAAA,EACkC;AAClC,IAAA,IAAA,CAAK,MAAA,CAAO,IAAA;AAAA,MACV,CAAA,YAAA,EAAe,KAAK,CAAA,cAAA,EAAiB,UAAA,CAAW,MAAM,CAAA,SAAA;AAAA,KACxD;AACA,IAAA,IAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AAC3B,MAAA,OAAO,EAAC;AAAA,IACV;AACA,IAAA,OAAO,IAAA,CAAK,EAAA,CAAG,aAAA,CAAc,UAAA,EAAY,KAAK,CAAA;AAAA,EAChD;AACF;;;;"}
|
|
@@ -1 +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,
|
|
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,KAAA,EAAuB;AAC/C,EAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,KAAK,CAAA;AAC1B,EAAA,OAAO,MAAA,CAAO,KAAA,CAAM,CAAC,CAAA,GAAI,CAAA,GAAI,CAAA;AAC/B;AAEA,SAAS,kBAAkB,IAAA,EAAsB;AAC/C,EAAA,OAAO,KAAK,GAAA,EAAI,GAAI,IAAA,GAAO,EAAA,GAAK,KAAK,EAAA,GAAK,GAAA;AAC5C;AAEA,SAAS,eAAA,CACP,SACA,MAAA,EACwC;AACxC,EAAA,OAAO,OAAA,CAAQ,IAAA,CAAK,CAAA,CAAA,KAAK,CAAA,CAAE,WAAW,MAAM,CAAA;AAC9C;AAKO,SAAS,0BAAA,CACd,QAAA,EACA,OAAA,EACA,OAAA,EAIW;AACX,EAAA,OAAO,QAAA,CAAS,OAAO,CAAA,OAAA,KAAW;AAChC,IAAA,MAAM,GAAA,GAAM,eAAA,CAAgB,OAAA,EAAS,OAAA,CAAQ,MAAM,CAAA;AACnD,IAAA,IAAI,CAAC,GAAA,IAAO,CAAC,GAAA,CAAI,OAAA,EAAS;AACxB,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,IAAI,OAAA,CAAQ,eAAe,UAAA,EAAY;AACrC,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,IAAI,QAAQ,sBAAA,EAAwB;AAClC,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,MAAM,OAAO,GAAA,CAAI,aAAA;AACjB,IAAA,IAAI,CAAC,IAAA,IAAQ,IAAA,IAAQ,CAAA,EAAG;AACtB,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,MAAM,SACJ,GAAA,CAAI,eAAA,KAAoB,SAAA,GACpB,OAAA,CAAQ,aACR,OAAA,CAAQ,UAAA;AACd,IAAA,MAAM,EAAA,GAAK,iBAAiB,MAAM,CAAA;AAClC,IAAA,OAAO,EAAA,IAAM,kBAAkB,IAAI,CAAA;AAAA,EACrC,CAAC,CAAA;AACH;;;;"}
|
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",
|
|
@@ -32,32 +32,42 @@
|
|
|
32
32
|
"postpack": "backstage-cli package postpack"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@backstage/backend-defaults": "^0.
|
|
36
|
-
"@backstage/backend-plugin-api": "^1.
|
|
37
|
-
"@backstage/catalog-model": "^1.
|
|
38
|
-
"@backstage/config": "^1.3.
|
|
39
|
-
"@backstage/errors": "^1.
|
|
40
|
-
"@backstage/plugin-
|
|
41
|
-
"@backstage/plugin-permission-
|
|
42
|
-
"@
|
|
35
|
+
"@backstage/backend-defaults": "^0.17.4",
|
|
36
|
+
"@backstage/backend-plugin-api": "^1.9.2",
|
|
37
|
+
"@backstage/catalog-model": "^1.9.0",
|
|
38
|
+
"@backstage/config": "^1.3.8",
|
|
39
|
+
"@backstage/errors": "^1.3.1",
|
|
40
|
+
"@backstage/plugin-notifications-node": "^0.2.27",
|
|
41
|
+
"@backstage/plugin-permission-common": "^0.9.9",
|
|
42
|
+
"@backstage/plugin-permission-node": "^0.11.1",
|
|
43
|
+
"@rothenbergt/backstage-plugin-roadmap-common": "^0.4.1",
|
|
43
44
|
"express": "^4.17.1",
|
|
44
45
|
"express-promise-router": "^4.1.0",
|
|
45
46
|
"knex": "^3.1.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@backstage/backend-test-utils": "^1.11.
|
|
49
|
-
"@backstage/cli": "^0.
|
|
50
|
-
"@backstage/plugin-auth-backend": "^0.
|
|
51
|
-
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.
|
|
49
|
+
"@backstage/backend-test-utils": "^1.11.4",
|
|
50
|
+
"@backstage/cli": "^0.36.3",
|
|
51
|
+
"@backstage/plugin-auth-backend": "^0.29.1",
|
|
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",
|
|
55
|
+
"@backstage/plugin-permission-backend": "^0.7.2",
|
|
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",
|
|
52
60
|
"@types/express": "*",
|
|
53
61
|
"@types/supertest": "^2.0.12",
|
|
54
62
|
"better-sqlite3": "^12.0.0",
|
|
55
63
|
"msw": "^2.3.1",
|
|
56
64
|
"supertest": "^6.2.4"
|
|
57
65
|
},
|
|
66
|
+
"configSchema": "config.d.ts",
|
|
58
67
|
"files": [
|
|
59
68
|
"dist",
|
|
60
|
-
"migrations"
|
|
69
|
+
"migrations",
|
|
70
|
+
"config.d.ts"
|
|
61
71
|
],
|
|
62
72
|
"typesVersions": {
|
|
63
73
|
"*": {
|