@rothenbergt/backstage-plugin-roadmap-backend 0.3.1 → 0.5.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/dist/config.cjs.js +39 -9
- package/dist/config.cjs.js.map +1 -1
- package/dist/database/RoadmapDatabaseClient.cjs.js.map +1 -1
- package/dist/gitlab/RoadmapGitlabClient.cjs.js +446 -0
- package/dist/gitlab/RoadmapGitlabClient.cjs.js.map +1 -0
- package/dist/index.d.ts +15 -45
- package/dist/plugin.cjs.js +19 -7
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/routes/featuresRouter.cjs.js +6 -0
- package/dist/routes/featuresRouter.cjs.js.map +1 -1
- package/dist/routes/router.cjs.js.map +1 -1
- package/dist/services/CommentService.cjs.js.map +1 -1
- package/dist/services/FeatureService.cjs.js.map +1 -1
- package/dist/services/PermissionService.cjs.js +5 -2
- package/dist/services/PermissionService.cjs.js.map +1 -1
- package/dist/services/VoteService.cjs.js.map +1 -1
- package/package.json +3 -3
package/dist/config.cjs.js
CHANGED
|
@@ -1,15 +1,45 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
adminUsers: roadmapConfig?.getOptionalStringArray("adminUsers") ?? []
|
|
8
|
-
};
|
|
9
|
-
} catch (error) {
|
|
10
|
-
return { adminUsers: [] };
|
|
3
|
+
function getDatasource(config) {
|
|
4
|
+
const source = config.getOptionalConfig("roadmap")?.getOptionalString("source") ?? "database";
|
|
5
|
+
if (source !== "database" && source !== "gitlab") {
|
|
6
|
+
throw new Error(`Unknown roadmap datasource: ${source}`);
|
|
11
7
|
}
|
|
8
|
+
return source;
|
|
9
|
+
}
|
|
10
|
+
function getGitlabConfig(config) {
|
|
11
|
+
const gitlab = config.getConfig("roadmap.gitlab");
|
|
12
|
+
const apiBaseUrl = gitlab.getString("apiBaseUrl");
|
|
13
|
+
const token = gitlab.getString("token");
|
|
14
|
+
const projectId = gitlab.getOptionalString("projectId");
|
|
15
|
+
const groupId = gitlab.getOptionalString("groupId");
|
|
16
|
+
if (projectId && groupId) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"roadmap.gitlab: only one of projectId or groupId may be provided, not both"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (!projectId && !groupId) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"roadmap.gitlab: exactly one of projectId or groupId must be provided"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
apiBaseUrl,
|
|
28
|
+
token,
|
|
29
|
+
projectId,
|
|
30
|
+
groupId,
|
|
31
|
+
defaultProjectId: gitlab.getOptionalString("defaultProjectId")
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function getAdminUsers(config) {
|
|
35
|
+
return config.getOptionalConfig("roadmap")?.getOptionalStringArray("adminUsers") ?? [];
|
|
36
|
+
}
|
|
37
|
+
function isPermissionEnabled(config) {
|
|
38
|
+
return config.getOptionalBoolean("permission.enabled") ?? false;
|
|
12
39
|
}
|
|
13
40
|
|
|
14
|
-
exports.
|
|
41
|
+
exports.getAdminUsers = getAdminUsers;
|
|
42
|
+
exports.getDatasource = getDatasource;
|
|
43
|
+
exports.getGitlabConfig = getGitlabConfig;
|
|
44
|
+
exports.isPermissionEnabled = isPermissionEnabled;
|
|
15
45
|
//# sourceMappingURL=config.cjs.js.map
|
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';\n\nexport
|
|
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,MAAgC,EAAA;AAC5D,EAAA,MAAM,SACJ,MAAO,CAAA,iBAAA,CAAkB,SAAS,CAAG,EAAA,iBAAA,CAAkB,QAAQ,CAC/D,IAAA,UAAA;AACF,EAAI,IAAA,MAAA,KAAW,UAAc,IAAA,MAAA,KAAW,QAAU,EAAA;AAChD,IAAA,MAAM,IAAI,KAAA,CAAM,CAA+B,4BAAA,EAAA,MAAM,CAAE,CAAA,CAAA;AAAA;AAEzD,EAAO,OAAA,MAAA;AACT;AAGO,SAAS,gBAAgB,MAA8B,EAAA;AAC5D,EAAM,MAAA,MAAA,GAAS,MAAO,CAAA,SAAA,CAAU,gBAAgB,CAAA;AAChD,EAAM,MAAA,UAAA,GAAa,MAAO,CAAA,SAAA,CAAU,YAAY,CAAA;AAChD,EAAM,MAAA,KAAA,GAAQ,MAAO,CAAA,SAAA,CAAU,OAAO,CAAA;AACtC,EAAM,MAAA,SAAA,GAAY,MAAO,CAAA,iBAAA,CAAkB,WAAW,CAAA;AACtD,EAAM,MAAA,OAAA,GAAU,MAAO,CAAA,iBAAA,CAAkB,SAAS,CAAA;AAElD,EAAA,IAAI,aAAa,OAAS,EAAA;AACxB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AAEF,EAAI,IAAA,CAAC,SAAa,IAAA,CAAC,OAAS,EAAA;AAC1B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AAGF,EAAO,OAAA;AAAA,IACL,UAAA;AAAA,IACA,KAAA;AAAA,IACA,SAAA;AAAA,IACA,OAAA;AAAA,IACA,gBAAA,EAAkB,MAAO,CAAA,iBAAA,CAAkB,kBAAkB;AAAA,GAC/D;AACF;AAGO,SAAS,cAAc,MAA0B,EAAA;AACtD,EAAA,OACE,OAAO,iBAAkB,CAAA,SAAS,GAAG,sBAAuB,CAAA,YAAY,KACxE,EAAC;AAEL;AAGO,SAAS,oBAAoB,MAAyB,EAAA;AAC3D,EAAO,OAAA,MAAA,CAAO,kBAAmB,CAAA,oBAAoB,CAAK,IAAA,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 { RoadmapDatabase } from './types';\nimport { LoggerService, DatabaseService } from '@backstage/backend-plugin-api';\nimport { NotFoundError, ConflictError } from '@backstage/errors';\nimport { resolvePackagePath } from '@backstage/backend-plugin-api';\n\nconst migrationsDir = resolvePackagePath(\n '@rothenbergt/backstage-plugin-roadmap-backend',\n 'migrations',\n);\n\n/**\n * Implementation of the RoadmapDatabase interface using Knex\n */\nexport class RoadmapDatabaseClient implements RoadmapDatabase {\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 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 // Insert feature and return the complete inserted object\n const [newFeature] = await trx('features')\n .insert({\n ...feature,\n status: FeatureStatus.Suggested,\n votes: 0,\n })\n .returning('*');\n\n await trx.commit();\n return 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 return this.knex('features').orderBy('created_at', 'desc').select('*');\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 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,\n updated_at: this.knex.fn.now(),\n })\n .returning('*');\n\n await trx.commit();\n return 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 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","NotFoundError","ConflictError","FeatureStatus"],"mappings":";;;;;;AAaA,MAAM,aAAgB,GAAAA,mCAAA;AAAA,EACpB,+CAAA;AAAA,EACA;AACF,CAAA;AAKO,MAAM,qBAAiD,CAAA;AAAA,EAC5D,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,YAA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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';\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 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 // Insert feature and return the complete inserted object\n const [newFeature] = await trx('features')\n .insert({\n ...feature,\n status: FeatureStatus.Suggested,\n votes: 0,\n })\n .returning('*');\n\n await trx.commit();\n return 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 return this.knex('features').orderBy('created_at', 'desc').select('*');\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 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,\n updated_at: this.knex.fn.now(),\n })\n .returning('*');\n\n await trx.commit();\n return 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 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","NotFoundError","ConflictError","FeatureStatus"],"mappings":";;;;;;AAaA,MAAM,aAAgB,GAAAA,mCAAA;AAAA,EACpB,+CAAA;AAAA,EACA;AACF,CAAA;AAKO,MAAM,qBAAmD,CAAA;AAAA,EAC9D,aAAa,OAAO,OAGe,EAAA;AACjC,IAAM,MAAA,E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AAGV,MAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,IAAK,CAAA,OAAO,EAClC,OAAQ,CAAA,YAAA,EAAc,UAAU,CAAA,CAChC,MAAM,EAAE,KAAA,EAAO,CAAA,CACf,OAAO,YAAY,CAAA;AAEtB,MAAM,MAAA,eAAA,GAAkB,IAAI,GAAA,CAAI,KAAM,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;;;;"}
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
4
|
+
var errors = require('@backstage/errors');
|
|
5
|
+
var catalogModel = require('@backstage/catalog-model');
|
|
6
|
+
|
|
7
|
+
const ROADMAP_LABEL = "roadmap";
|
|
8
|
+
const ROADMAP_SCOPE_LABEL = `${ROADMAP_LABEL}::`;
|
|
9
|
+
const STATUS_LABELS = Object.values(backstagePluginRoadmapCommon.FeatureStatus).map(
|
|
10
|
+
(status) => `${ROADMAP_SCOPE_LABEL}${status}`
|
|
11
|
+
);
|
|
12
|
+
const PAGINATION = "per_page=100";
|
|
13
|
+
const AUTHOR_TAG_RE = /^<!-- author:(\S+) -->\n/;
|
|
14
|
+
const VOTE_TAG_RE = /^<!-- vote:(\S+) -->$/;
|
|
15
|
+
function formatStatusAsGitLabLabel(status) {
|
|
16
|
+
return `${ROADMAP_SCOPE_LABEL}${status}`;
|
|
17
|
+
}
|
|
18
|
+
function extractStatusFromLabels(labels) {
|
|
19
|
+
const match = labels.find((l) => STATUS_LABELS.includes(l));
|
|
20
|
+
if (!match) return backstagePluginRoadmapCommon.FeatureStatus.Suggested;
|
|
21
|
+
return match.replace(ROADMAP_SCOPE_LABEL, "");
|
|
22
|
+
}
|
|
23
|
+
function replaceStatusLabels(labels, newStatus) {
|
|
24
|
+
const cleaned = labels.filter((l) => !STATUS_LABELS.includes(l));
|
|
25
|
+
if (!cleaned.includes(ROADMAP_LABEL)) cleaned.push(ROADMAP_LABEL);
|
|
26
|
+
cleaned.push(formatStatusAsGitLabLabel(newStatus));
|
|
27
|
+
return cleaned;
|
|
28
|
+
}
|
|
29
|
+
function formatIsoDateForStorage(isoDate) {
|
|
30
|
+
return isoDate.replace("T", " ").replace(/\.\d+Z$/, "");
|
|
31
|
+
}
|
|
32
|
+
function mapGitLabIssueToFeature(issue, voteCount) {
|
|
33
|
+
return {
|
|
34
|
+
id: String(issue.iid),
|
|
35
|
+
title: issue.title,
|
|
36
|
+
description: issue.description ?? "",
|
|
37
|
+
status: extractStatusFromLabels(issue.labels ?? []),
|
|
38
|
+
votes: voteCount ?? issue.upvotes ?? 0,
|
|
39
|
+
author: issue.author?.username ?? "",
|
|
40
|
+
created_at: formatIsoDateForStorage(issue.created_at),
|
|
41
|
+
updated_at: formatIsoDateForStorage(issue.updated_at)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function mapGitLabNoteToComment(note, featureId) {
|
|
45
|
+
const body = note.body ?? "";
|
|
46
|
+
const authorMatch = body.match(AUTHOR_TAG_RE);
|
|
47
|
+
return {
|
|
48
|
+
id: String(note.id),
|
|
49
|
+
author: authorMatch ? authorMatch[1] : note.author?.username ?? "",
|
|
50
|
+
featureId,
|
|
51
|
+
text: authorMatch ? body.replace(AUTHOR_TAG_RE, "") : body,
|
|
52
|
+
created_at: formatIsoDateForStorage(note.created_at),
|
|
53
|
+
updated_at: formatIsoDateForStorage(note.updated_at)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function isHiddenVoteMarker(body) {
|
|
57
|
+
return VOTE_TAG_RE.test(body?.trim());
|
|
58
|
+
}
|
|
59
|
+
function isUserComment(note) {
|
|
60
|
+
return !note.system && !isHiddenVoteMarker(note.body ?? "");
|
|
61
|
+
}
|
|
62
|
+
function sanitizeLog(value) {
|
|
63
|
+
return value.replace(/[\r\n]/g, "");
|
|
64
|
+
}
|
|
65
|
+
function parseUsernameFromEntityRef(userEntityRef) {
|
|
66
|
+
const entity = catalogModel.parseEntityRef(userEntityRef);
|
|
67
|
+
return entity.name;
|
|
68
|
+
}
|
|
69
|
+
function buildAuthorTaggedBody(username, text) {
|
|
70
|
+
return `<!-- author:${username} -->
|
|
71
|
+
${text}`;
|
|
72
|
+
}
|
|
73
|
+
function buildVoteMarker(username) {
|
|
74
|
+
return `<!-- vote:${username} -->`;
|
|
75
|
+
}
|
|
76
|
+
function convertIssuesToFeatures(issues, voteCounts) {
|
|
77
|
+
return issues.map(
|
|
78
|
+
(issue) => mapGitLabIssueToFeature(issue, voteCounts?.[String(issue.iid)])
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
function convertNotesToComments(notes, featureId) {
|
|
82
|
+
return notes.map((n) => mapGitLabNoteToComment(n, featureId));
|
|
83
|
+
}
|
|
84
|
+
function filterUserComments(notes) {
|
|
85
|
+
return notes.filter(isUserComment);
|
|
86
|
+
}
|
|
87
|
+
function buildCommentBody(comment) {
|
|
88
|
+
const author = comment.author ? parseUsernameFromEntityRef(comment.author) : void 0;
|
|
89
|
+
return author ? buildAuthorTaggedBody(author, comment.text) : comment.text;
|
|
90
|
+
}
|
|
91
|
+
function buildNewRoadmapIssuePayload(feature) {
|
|
92
|
+
return JSON.stringify({
|
|
93
|
+
title: feature.title,
|
|
94
|
+
description: feature.description,
|
|
95
|
+
labels: `${ROADMAP_LABEL},${formatStatusAsGitLabLabel(
|
|
96
|
+
backstagePluginRoadmapCommon.FeatureStatus.Suggested
|
|
97
|
+
)}`
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const VOTE_CACHE_TTL_MS = 3e4;
|
|
101
|
+
const PROJECT_MAP_CACHE_TTL_MS = 3e5;
|
|
102
|
+
function issueProjectCacheKey(issueIid) {
|
|
103
|
+
return `roadmap:issue-project:${issueIid}`;
|
|
104
|
+
}
|
|
105
|
+
function voteCacheKey(featureId) {
|
|
106
|
+
return `roadmap:votes:${featureId}`;
|
|
107
|
+
}
|
|
108
|
+
function voteMapToJson(map) {
|
|
109
|
+
return Object.fromEntries(map);
|
|
110
|
+
}
|
|
111
|
+
function jsonToVoteMap(json) {
|
|
112
|
+
return new Map(Object.entries(json));
|
|
113
|
+
}
|
|
114
|
+
class RoadmapGitlabClient {
|
|
115
|
+
baseUrl;
|
|
116
|
+
token;
|
|
117
|
+
projectId;
|
|
118
|
+
groupId;
|
|
119
|
+
defaultProjectId;
|
|
120
|
+
logger;
|
|
121
|
+
cache;
|
|
122
|
+
async getCachedVotes(featureId) {
|
|
123
|
+
const cached = await this.cache.get(
|
|
124
|
+
voteCacheKey(featureId)
|
|
125
|
+
);
|
|
126
|
+
return cached ? jsonToVoteMap(cached) : void 0;
|
|
127
|
+
}
|
|
128
|
+
async setCachedVotes(featureId, data) {
|
|
129
|
+
await this.cache.set(voteCacheKey(featureId), voteMapToJson(data), {
|
|
130
|
+
ttl: VOTE_CACHE_TTL_MS
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async invalidateCachedVotes(featureId) {
|
|
134
|
+
await this.cache.delete(voteCacheKey(featureId));
|
|
135
|
+
}
|
|
136
|
+
static create(options) {
|
|
137
|
+
const { gitlab, logger, cache } = options;
|
|
138
|
+
return new RoadmapGitlabClient(
|
|
139
|
+
gitlab.apiBaseUrl,
|
|
140
|
+
gitlab.token,
|
|
141
|
+
logger,
|
|
142
|
+
cache,
|
|
143
|
+
gitlab.projectId,
|
|
144
|
+
gitlab.groupId,
|
|
145
|
+
gitlab.defaultProjectId
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
constructor(baseUrl, token, logger, cache, projectId, groupId, defaultProjectId) {
|
|
149
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
150
|
+
this.token = token;
|
|
151
|
+
this.projectId = projectId ? encodeURIComponent(projectId) : void 0;
|
|
152
|
+
this.groupId = groupId ? encodeURIComponent(groupId) : void 0;
|
|
153
|
+
this.defaultProjectId = defaultProjectId ? encodeURIComponent(defaultProjectId) : void 0;
|
|
154
|
+
this.logger = logger;
|
|
155
|
+
this.cache = cache;
|
|
156
|
+
}
|
|
157
|
+
get isGroupMode() {
|
|
158
|
+
return !!this.groupId;
|
|
159
|
+
}
|
|
160
|
+
projectApiUrl(path, projectId) {
|
|
161
|
+
const pid = projectId ?? this.projectId;
|
|
162
|
+
if (!pid) {
|
|
163
|
+
throw new Error("projectId is required for this operation");
|
|
164
|
+
}
|
|
165
|
+
return `${this.baseUrl}/projects/${pid}${path}`;
|
|
166
|
+
}
|
|
167
|
+
groupApiUrl(path) {
|
|
168
|
+
return `${this.baseUrl}/groups/${this.groupId}${path}`;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Resolves the encoded project ID for a given issue iid.
|
|
172
|
+
* In project mode, returns the configured projectId.
|
|
173
|
+
* In group mode, looks up the cached mapping from group issue responses.
|
|
174
|
+
*/
|
|
175
|
+
async resolveProjectId(issueIid) {
|
|
176
|
+
if (!this.isGroupMode) return this.projectId;
|
|
177
|
+
const pid = await this.cache.get(issueProjectCacheKey(issueIid));
|
|
178
|
+
if (!pid) {
|
|
179
|
+
throw new errors.NotFoundError(
|
|
180
|
+
`No cached project mapping for issue ${issueIid}. Fetch all features first.`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return pid;
|
|
184
|
+
}
|
|
185
|
+
async hasIssueProjectCached(issueIid) {
|
|
186
|
+
const pid = await this.cache.get(issueProjectCacheKey(issueIid));
|
|
187
|
+
return !!pid;
|
|
188
|
+
}
|
|
189
|
+
/** Caches the project_id for issues returned from group-level queries. */
|
|
190
|
+
async cacheIssueProjects(issues) {
|
|
191
|
+
await Promise.all(
|
|
192
|
+
issues.filter((issue) => issue.project_id).map(
|
|
193
|
+
(issue) => this.cache.set(
|
|
194
|
+
issueProjectCacheKey(String(issue.iid)),
|
|
195
|
+
String(issue.project_id),
|
|
196
|
+
{ ttl: PROJECT_MAP_CACHE_TTL_MS }
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
authHeaders() {
|
|
202
|
+
return {
|
|
203
|
+
"PRIVATE-TOKEN": this.token,
|
|
204
|
+
"Content-Type": "application/json"
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
async ensureIssueProjectCached(featureId) {
|
|
208
|
+
if (this.isGroupMode && !await this.hasIssueProjectCached(featureId)) {
|
|
209
|
+
await this.fetchAllRoadmapIssues();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async callGitLabApi(url, init) {
|
|
213
|
+
const method = init?.method ?? "GET";
|
|
214
|
+
this.logger.info(`GitLab API request: ${method} ${sanitizeLog(url)}`);
|
|
215
|
+
const res = await fetch(url, { ...init, headers: this.authHeaders() });
|
|
216
|
+
if (!res.ok) {
|
|
217
|
+
const text = await res.text();
|
|
218
|
+
this.logger.error(
|
|
219
|
+
`GitLab API error: ${res.status} ${sanitizeLog(text)} (${sanitizeLog(
|
|
220
|
+
url
|
|
221
|
+
)})`
|
|
222
|
+
);
|
|
223
|
+
if (res.status === 401)
|
|
224
|
+
throw new errors.NotAllowedError(
|
|
225
|
+
"GitLab API authentication failed: token is missing or invalid"
|
|
226
|
+
);
|
|
227
|
+
if (res.status === 404) throw new errors.NotFoundError(text);
|
|
228
|
+
throw new errors.ConflictError(`GitLab API error: ${res.status}`);
|
|
229
|
+
}
|
|
230
|
+
if (res.status === 204 || res.headers.get("content-length") === "0") {
|
|
231
|
+
return { data: void 0, res };
|
|
232
|
+
}
|
|
233
|
+
const data = await res.json();
|
|
234
|
+
return { data, res };
|
|
235
|
+
}
|
|
236
|
+
async fetchAllPages(url) {
|
|
237
|
+
const results = [];
|
|
238
|
+
let nextUrl = url;
|
|
239
|
+
while (nextUrl) {
|
|
240
|
+
const { data, res } = await this.callGitLabApi(nextUrl);
|
|
241
|
+
results.push(...data);
|
|
242
|
+
const nextPage = res.headers.get("x-next-page");
|
|
243
|
+
if (nextPage) {
|
|
244
|
+
const parsed = new URL(nextUrl);
|
|
245
|
+
parsed.searchParams.set("page", nextPage);
|
|
246
|
+
nextUrl = parsed.toString();
|
|
247
|
+
} else {
|
|
248
|
+
nextUrl = void 0;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return results;
|
|
252
|
+
}
|
|
253
|
+
async fetchAllRoadmapIssues() {
|
|
254
|
+
const issues = await this.fetchAllPages(
|
|
255
|
+
this.roadmapIssuesUrl("desc")
|
|
256
|
+
);
|
|
257
|
+
if (this.isGroupMode) await this.cacheIssueProjects(issues);
|
|
258
|
+
return issues;
|
|
259
|
+
}
|
|
260
|
+
async fetchIssueById(id) {
|
|
261
|
+
const pid = await this.resolveProjectId(id);
|
|
262
|
+
const { data } = await this.callGitLabApi(
|
|
263
|
+
this.projectApiUrl(`/issues/${id}`, pid)
|
|
264
|
+
);
|
|
265
|
+
if (this.isGroupMode && data.project_id) {
|
|
266
|
+
await this.cache.set(
|
|
267
|
+
issueProjectCacheKey(String(data.iid)),
|
|
268
|
+
String(data.project_id),
|
|
269
|
+
{ ttl: PROJECT_MAP_CACHE_TTL_MS }
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
return data;
|
|
273
|
+
}
|
|
274
|
+
async createRoadmapIssue(feature) {
|
|
275
|
+
if (this.isGroupMode && !this.defaultProjectId) {
|
|
276
|
+
throw new errors.ConflictError(
|
|
277
|
+
"Creating features in group mode requires defaultProjectId to be configured"
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
const pid = this.isGroupMode ? this.defaultProjectId : this.projectId;
|
|
281
|
+
const { data } = await this.callGitLabApi(
|
|
282
|
+
this.projectApiUrl("/issues", pid),
|
|
283
|
+
{
|
|
284
|
+
method: "POST",
|
|
285
|
+
body: buildNewRoadmapIssuePayload(feature)
|
|
286
|
+
}
|
|
287
|
+
);
|
|
288
|
+
return data;
|
|
289
|
+
}
|
|
290
|
+
async updateIssueLabels(id, labels) {
|
|
291
|
+
const pid = await this.resolveProjectId(id);
|
|
292
|
+
const { data } = await this.callGitLabApi(
|
|
293
|
+
this.projectApiUrl(`/issues/${id}`, pid),
|
|
294
|
+
{ method: "PUT", body: JSON.stringify({ labels: labels.join(",") }) }
|
|
295
|
+
);
|
|
296
|
+
return data;
|
|
297
|
+
}
|
|
298
|
+
async fetchIssueNotes(featureId, sort = "desc") {
|
|
299
|
+
const pid = await this.resolveProjectId(featureId);
|
|
300
|
+
return this.fetchAllPages(
|
|
301
|
+
this.projectApiUrl(
|
|
302
|
+
`/issues/${featureId}/notes?sort=${sort}&order_by=created_at&${PAGINATION}`,
|
|
303
|
+
pid
|
|
304
|
+
)
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
async collectVoteMarkersByUser(featureId) {
|
|
308
|
+
const notes = await this.fetchIssueNotes(featureId, "asc");
|
|
309
|
+
const votesByUser = /* @__PURE__ */ new Map();
|
|
310
|
+
for (const note of notes) {
|
|
311
|
+
if (note.system) continue;
|
|
312
|
+
const match = (note.body ?? "").trim().match(VOTE_TAG_RE);
|
|
313
|
+
if (match) votesByUser.set(match[1], note.id);
|
|
314
|
+
}
|
|
315
|
+
return votesByUser;
|
|
316
|
+
}
|
|
317
|
+
async deleteNote(featureId, noteId) {
|
|
318
|
+
const pid = await this.resolveProjectId(featureId);
|
|
319
|
+
await this.callGitLabApi(
|
|
320
|
+
this.projectApiUrl(`/issues/${featureId}/notes/${noteId}`, pid),
|
|
321
|
+
{ method: "DELETE" }
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
async createNote(featureId, body) {
|
|
325
|
+
const pid = await this.resolveProjectId(featureId);
|
|
326
|
+
const { data } = await this.callGitLabApi(
|
|
327
|
+
this.projectApiUrl(`/issues/${featureId}/notes`, pid),
|
|
328
|
+
{ method: "POST", body: JSON.stringify({ body }) }
|
|
329
|
+
);
|
|
330
|
+
return data;
|
|
331
|
+
}
|
|
332
|
+
async ensureFeatureExists(featureId) {
|
|
333
|
+
await this.ensureIssueProjectCached(featureId);
|
|
334
|
+
await this.fetchIssueById(featureId);
|
|
335
|
+
}
|
|
336
|
+
async removeVote(featureId, noteId, votesByUser, username) {
|
|
337
|
+
await this.deleteNote(featureId, noteId);
|
|
338
|
+
votesByUser.delete(username);
|
|
339
|
+
}
|
|
340
|
+
async addVote(featureId, votesByUser, username) {
|
|
341
|
+
await this.createNote(featureId, buildVoteMarker(username));
|
|
342
|
+
votesByUser.set(username, 0);
|
|
343
|
+
}
|
|
344
|
+
async getOrFetchVotes(featureId) {
|
|
345
|
+
const cached = await this.getCachedVotes(featureId);
|
|
346
|
+
if (cached) return cached;
|
|
347
|
+
const votes = await this.collectVoteMarkersByUser(featureId);
|
|
348
|
+
await this.setCachedVotes(featureId, votes);
|
|
349
|
+
return votes;
|
|
350
|
+
}
|
|
351
|
+
async collectAllVoteCounts(issues) {
|
|
352
|
+
const counts = {};
|
|
353
|
+
await Promise.all(
|
|
354
|
+
issues.map(async (issue) => {
|
|
355
|
+
const id = String(issue.iid);
|
|
356
|
+
const votes = await this.getOrFetchVotes(id);
|
|
357
|
+
counts[id] = votes.size;
|
|
358
|
+
})
|
|
359
|
+
);
|
|
360
|
+
return counts;
|
|
361
|
+
}
|
|
362
|
+
roadmapIssuesUrl(sort = "desc") {
|
|
363
|
+
const query = `/issues?labels=${ROADMAP_LABEL}&${PAGINATION}&order_by=created_at&sort=${sort}`;
|
|
364
|
+
return this.isGroupMode ? this.groupApiUrl(query) : this.projectApiUrl(query);
|
|
365
|
+
}
|
|
366
|
+
async addComment(comment) {
|
|
367
|
+
await this.ensureIssueProjectCached(comment.featureId);
|
|
368
|
+
const body = buildCommentBody(comment);
|
|
369
|
+
const gitlabNote = await this.createNote(comment.featureId, body);
|
|
370
|
+
return mapGitLabNoteToComment(gitlabNote, comment.featureId);
|
|
371
|
+
}
|
|
372
|
+
async getCommentsByFeatureId(featureId) {
|
|
373
|
+
await this.ensureFeatureExists(featureId);
|
|
374
|
+
const allNotes = await this.fetchIssueNotes(featureId, "desc");
|
|
375
|
+
const commentNotes = filterUserComments(allNotes);
|
|
376
|
+
return convertNotesToComments(commentNotes, featureId);
|
|
377
|
+
}
|
|
378
|
+
async addFeature(feature) {
|
|
379
|
+
const gitlabIssue = await this.createRoadmapIssue(feature);
|
|
380
|
+
return mapGitLabIssueToFeature(gitlabIssue);
|
|
381
|
+
}
|
|
382
|
+
async getAllFeatures() {
|
|
383
|
+
this.logger.info("Fetching all roadmap features from GitLab");
|
|
384
|
+
const gitlabIssues = await this.fetchAllRoadmapIssues();
|
|
385
|
+
const voteCounts = await this.collectAllVoteCounts(gitlabIssues);
|
|
386
|
+
return convertIssuesToFeatures(gitlabIssues, voteCounts);
|
|
387
|
+
}
|
|
388
|
+
async getFeatureById(id) {
|
|
389
|
+
await this.ensureIssueProjectCached(id);
|
|
390
|
+
const gitlabIssue = await this.fetchIssueById(id);
|
|
391
|
+
const voteCount = await this.getVoteCount(id);
|
|
392
|
+
return mapGitLabIssueToFeature(gitlabIssue, voteCount);
|
|
393
|
+
}
|
|
394
|
+
async updateFeatureStatus(id, status) {
|
|
395
|
+
await this.ensureIssueProjectCached(id);
|
|
396
|
+
const existingIssue = await this.fetchIssueById(id);
|
|
397
|
+
const updatedLabels = replaceStatusLabels(
|
|
398
|
+
existingIssue.labels ?? [],
|
|
399
|
+
status
|
|
400
|
+
);
|
|
401
|
+
const updatedIssue = await this.updateIssueLabels(id, updatedLabels);
|
|
402
|
+
return mapGitLabIssueToFeature(updatedIssue);
|
|
403
|
+
}
|
|
404
|
+
async toggleVote(featureId, voter) {
|
|
405
|
+
await this.ensureIssueProjectCached(featureId);
|
|
406
|
+
await this.invalidateCachedVotes(featureId);
|
|
407
|
+
const username = parseUsernameFromEntityRef(voter);
|
|
408
|
+
const votesByUser = await this.collectVoteMarkersByUser(featureId);
|
|
409
|
+
const existingNoteId = votesByUser.get(username);
|
|
410
|
+
if (existingNoteId) {
|
|
411
|
+
await this.removeVote(featureId, existingNoteId, votesByUser, username);
|
|
412
|
+
} else {
|
|
413
|
+
await this.addVote(featureId, votesByUser, username);
|
|
414
|
+
}
|
|
415
|
+
await this.setCachedVotes(featureId, votesByUser);
|
|
416
|
+
return { voteAdded: !existingNoteId, voteCount: votesByUser.size };
|
|
417
|
+
}
|
|
418
|
+
async getVoteCount(featureId) {
|
|
419
|
+
await this.ensureIssueProjectCached(featureId);
|
|
420
|
+
const votes = await this.getOrFetchVotes(featureId);
|
|
421
|
+
return votes.size;
|
|
422
|
+
}
|
|
423
|
+
async getVoteCounts(featureIds) {
|
|
424
|
+
const counts = {};
|
|
425
|
+
for (const id of featureIds) {
|
|
426
|
+
counts[id] = await this.getVoteCount(id);
|
|
427
|
+
}
|
|
428
|
+
return counts;
|
|
429
|
+
}
|
|
430
|
+
async hasVoted(featureId, voter) {
|
|
431
|
+
await this.ensureIssueProjectCached(featureId);
|
|
432
|
+
const username = parseUsernameFromEntityRef(voter);
|
|
433
|
+
const votes = await this.getOrFetchVotes(featureId);
|
|
434
|
+
return votes.has(username);
|
|
435
|
+
}
|
|
436
|
+
async hasVotedBatch(featureIds, voter) {
|
|
437
|
+
const results = {};
|
|
438
|
+
for (const id of featureIds) {
|
|
439
|
+
results[id] = await this.hasVoted(id, voter);
|
|
440
|
+
}
|
|
441
|
+
return results;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
exports.RoadmapGitlabClient = RoadmapGitlabClient;
|
|
446
|
+
//# sourceMappingURL=RoadmapGitlabClient.cjs.js.map
|
|
@@ -0,0 +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 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.iid),\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.iid)]),\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(issueIid: string): string {\n return `roadmap:issue-project:${issueIid}`;\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 iid.\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(issueIid: string): Promise<string> {\n if (!this.isGroupMode) return this.projectId!;\n const pid = await this.cache.get<string>(issueProjectCacheKey(issueIid));\n if (!pid) {\n throw new NotFoundError(\n `No cached project mapping for issue ${issueIid}. Fetch all features first.`,\n );\n }\n return pid;\n }\n\n private async hasIssueProjectCached(issueIid: string): Promise<boolean> {\n const pid = await this.cache.get<string>(issueProjectCacheKey(issueIid));\n return !!pid;\n }\n\n /** Caches the project_id for issues returned from group-level queries. */\n private async cacheIssueProjects(issues: GitLabIssue[]): Promise<void> {\n await Promise.all(\n issues\n .filter(issue => issue.project_id)\n .map(issue =>\n this.cache.set(\n issueProjectCacheKey(String(issue.iid)),\n String(issue.project_id),\n { ttl: PROJECT_MAP_CACHE_TTL_MS },\n ),\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 (this.isGroupMode && !(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.info(`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 if (this.isGroupMode) await this.cacheIssueProjects(issues);\n return issues;\n }\n\n private async fetchIssueById(id: string): Promise<GitLabIssue> {\n const pid = await this.resolveProjectId(id);\n const { data } = await this.callGitLabApi<GitLabIssue>(\n this.projectApiUrl(`/issues/${id}`, pid),\n );\n if (this.isGroupMode && data.project_id) {\n await this.cache.set(\n issueProjectCacheKey(String(data.iid)),\n String(data.project_id),\n { ttl: PROJECT_MAP_CACHE_TTL_MS },\n );\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 { data } = await this.callGitLabApi<GitLabIssue>(\n this.projectApiUrl(`/issues/${id}`, 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 return this.fetchAllPages<GitLabNote>(\n this.projectApiUrl(\n `/issues/${featureId}/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 await this.callGitLabApi<void>(\n this.projectApiUrl(`/issues/${featureId}/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 { data } = await this.callGitLabApi<GitLabNote>(\n this.projectApiUrl(`/issues/${featureId}/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.iid);\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,CAAE,CAAA,GAAA;AAAA,EACjD,CAAU,MAAA,KAAA,CAAA,EAAG,mBAAmB,CAAA,EAAG,MAAM,CAAA;AAC3C,CAAA;AACA,MAAM,UAAa,GAAA,cAAA;AAEnB,MAAM,aAAgB,GAAA,0BAAA;AACtB,MAAM,WAAc,GAAA,uBAAA;AAuBpB,SAAS,0BAA0B,MAA+B,EAAA;AAChE,EAAO,OAAA,CAAA,EAAG,mBAAmB,CAAA,EAAG,MAAM,CAAA,CAAA;AACxC;AAEA,SAAS,wBAAwB,MAAiC,EAAA;AAChE,EAAA,MAAM,QAAQ,MAAO,CAAA,IAAA,CAAK,OAAK,aAAc,CAAA,QAAA,CAAS,CAAC,CAAC,CAAA;AACxD,EAAI,IAAA,CAAC,KAAO,EAAA,OAAOA,0CAAc,CAAA,SAAA;AACjC,EAAO,OAAA,KAAA,CAAM,OAAQ,CAAA,mBAAA,EAAqB,EAAE,CAAA;AAC9C;AAEA,SAAS,mBAAA,CACP,QACA,SACU,EAAA;AACV,EAAM,MAAA,OAAA,GAAU,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
import {
|
|
2
|
+
import { LoggerService, HttpAuthService, UserInfoService, PermissionsService, CacheService } from '@backstage/backend-plugin-api';
|
|
3
3
|
import { Config } from '@backstage/config';
|
|
4
4
|
import express from 'express';
|
|
5
|
-
import { Knex } from 'knex';
|
|
6
5
|
import { NewComment, Comment, NewFeature, Feature, FeatureStatus } from '@rothenbergt/backstage-plugin-roadmap-common';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
|
-
* Interface for the Roadmap
|
|
8
|
+
* Interface for the Roadmap datasource operations
|
|
10
9
|
*/
|
|
11
|
-
interface
|
|
10
|
+
interface RoadmapDatasource {
|
|
12
11
|
/**
|
|
13
12
|
* Add a comment to a feature
|
|
14
13
|
*
|
|
15
14
|
* @param comment - The comment to add
|
|
16
15
|
* @returns The created comment
|
|
17
16
|
* @throws {NotFoundError} When the referenced feature does not exist
|
|
18
|
-
* @throws {ConflictError} When the
|
|
17
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
19
18
|
*/
|
|
20
19
|
addComment(comment: NewComment): Promise<Comment>;
|
|
21
20
|
/**
|
|
@@ -24,7 +23,7 @@ interface RoadmapDatabase {
|
|
|
24
23
|
* @param featureId - The ID of the feature
|
|
25
24
|
* @returns Array of comments
|
|
26
25
|
* @throws {NotFoundError} When the feature does not exist
|
|
27
|
-
* @throws {ConflictError} When the
|
|
26
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
28
27
|
*/
|
|
29
28
|
getCommentsByFeatureId(featureId: string): Promise<Comment[]>;
|
|
30
29
|
/**
|
|
@@ -32,7 +31,7 @@ interface RoadmapDatabase {
|
|
|
32
31
|
*
|
|
33
32
|
* @param feature - The feature to add
|
|
34
33
|
* @returns The created feature
|
|
35
|
-
* @throws {ConflictError} When the
|
|
34
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
36
35
|
*/
|
|
37
36
|
addFeature(feature: NewFeature & {
|
|
38
37
|
author: string;
|
|
@@ -41,7 +40,7 @@ interface RoadmapDatabase {
|
|
|
41
40
|
* Get all features
|
|
42
41
|
*
|
|
43
42
|
* @returns Array of all features
|
|
44
|
-
* @throws {ConflictError} When the
|
|
43
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
45
44
|
*/
|
|
46
45
|
getAllFeatures(): Promise<Feature[]>;
|
|
47
46
|
/**
|
|
@@ -50,7 +49,7 @@ interface RoadmapDatabase {
|
|
|
50
49
|
* @param id - The ID of the feature
|
|
51
50
|
* @returns The feature
|
|
52
51
|
* @throws {NotFoundError} When the feature does not exist
|
|
53
|
-
* @throws {ConflictError} When the
|
|
52
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
54
53
|
*/
|
|
55
54
|
getFeatureById(id: string): Promise<Feature>;
|
|
56
55
|
/**
|
|
@@ -60,7 +59,7 @@ interface RoadmapDatabase {
|
|
|
60
59
|
* @param status - The new status
|
|
61
60
|
* @returns The updated feature
|
|
62
61
|
* @throws {NotFoundError} When the feature does not exist
|
|
63
|
-
* @throws {ConflictError} When the
|
|
62
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
64
63
|
*/
|
|
65
64
|
updateFeatureStatus(id: string, status: FeatureStatus): Promise<Feature>;
|
|
66
65
|
/**
|
|
@@ -70,7 +69,7 @@ interface RoadmapDatabase {
|
|
|
70
69
|
* @param voter - The user voting
|
|
71
70
|
* @returns Object with voteAdded (true if added, false if removed) and updated voteCount
|
|
72
71
|
* @throws {NotFoundError} When the feature does not exist
|
|
73
|
-
* @throws {ConflictError} When the
|
|
72
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
74
73
|
*/
|
|
75
74
|
toggleVote(featureId: string, voter: string): Promise<{
|
|
76
75
|
voteAdded: boolean;
|
|
@@ -82,7 +81,7 @@ interface RoadmapDatabase {
|
|
|
82
81
|
* @param featureId - The ID of the feature
|
|
83
82
|
* @returns The number of votes
|
|
84
83
|
* @throws {NotFoundError} When the feature does not exist
|
|
85
|
-
* @throws {ConflictError} When the
|
|
84
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
86
85
|
*/
|
|
87
86
|
getVoteCount(featureId: string): Promise<number>;
|
|
88
87
|
/**
|
|
@@ -90,7 +89,7 @@ interface RoadmapDatabase {
|
|
|
90
89
|
*
|
|
91
90
|
* @param featureIds - Array of feature IDs
|
|
92
91
|
* @returns Object mapping feature IDs to vote counts
|
|
93
|
-
* @throws {ConflictError} When the
|
|
92
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
94
93
|
*/
|
|
95
94
|
getVoteCounts(featureIds: string[]): Promise<Record<string, number>>;
|
|
96
95
|
/**
|
|
@@ -99,7 +98,7 @@ interface RoadmapDatabase {
|
|
|
99
98
|
* @param featureId - The ID of the feature
|
|
100
99
|
* @param voter - The user
|
|
101
100
|
* @returns Boolean indicating if the user has voted
|
|
102
|
-
* @throws {ConflictError} When the
|
|
101
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
103
102
|
*/
|
|
104
103
|
hasVoted(featureId: string, voter: string): Promise<boolean>;
|
|
105
104
|
/**
|
|
@@ -108,47 +107,18 @@ interface RoadmapDatabase {
|
|
|
108
107
|
* @param featureIds - Array of feature IDs
|
|
109
108
|
* @param voter - The user
|
|
110
109
|
* @returns Object mapping feature IDs to boolean (has voted)
|
|
111
|
-
* @throws {ConflictError} When the
|
|
110
|
+
* @throws {ConflictError} When the datasource operation fails
|
|
112
111
|
*/
|
|
113
112
|
hasVotedBatch(featureIds: string[], voter: string): Promise<Record<string, boolean>>;
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
/**
|
|
117
|
-
* Implementation of the RoadmapDatabase interface using Knex
|
|
118
|
-
*/
|
|
119
|
-
declare class RoadmapDatabaseClient implements RoadmapDatabase {
|
|
120
|
-
static create(options: {
|
|
121
|
-
database: DatabaseService;
|
|
122
|
-
logger: LoggerService;
|
|
123
|
-
}): Promise<RoadmapDatabaseClient>;
|
|
124
|
-
private readonly knex;
|
|
125
|
-
private readonly logger;
|
|
126
|
-
constructor(knexInstance: Knex, logger: LoggerService);
|
|
127
|
-
addComment(comment: NewComment): Promise<Comment>;
|
|
128
|
-
getCommentsByFeatureId(featureId: string): Promise<Comment[]>;
|
|
129
|
-
addFeature(feature: NewFeature & {
|
|
130
|
-
author: string;
|
|
131
|
-
}): Promise<Feature>;
|
|
132
|
-
getAllFeatures(): Promise<Feature[]>;
|
|
133
|
-
getFeatureById(id: string): Promise<Feature>;
|
|
134
|
-
updateFeatureStatus(id: string, status: FeatureStatus): Promise<Feature>;
|
|
135
|
-
toggleVote(featureId: string, voter: string): Promise<{
|
|
136
|
-
voteAdded: boolean;
|
|
137
|
-
voteCount: number;
|
|
138
|
-
}>;
|
|
139
|
-
getVoteCount(featureId: string): Promise<number>;
|
|
140
|
-
getVoteCounts(featureIds: string[]): Promise<Record<string, number>>;
|
|
141
|
-
hasVoted(featureId: string, voter: string): Promise<boolean>;
|
|
142
|
-
hasVotedBatch(featureIds: string[], voter: string): Promise<Record<string, boolean>>;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
115
|
/**
|
|
146
116
|
* Options for configuring the roadmap plugin router
|
|
147
117
|
*/
|
|
148
118
|
interface RouterOptions {
|
|
149
119
|
logger: LoggerService;
|
|
150
120
|
config: Config;
|
|
151
|
-
db:
|
|
121
|
+
db: RoadmapDatasource;
|
|
152
122
|
httpAuth: HttpAuthService;
|
|
153
123
|
userInfo: UserInfoService;
|
|
154
124
|
permissions?: PermissionsService;
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -5,8 +5,10 @@ var router = require('./routes/router.cjs.js');
|
|
|
5
5
|
require('express-promise-router');
|
|
6
6
|
require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
7
7
|
require('@backstage/errors');
|
|
8
|
+
var config = require('./config.cjs.js');
|
|
8
9
|
require('@backstage/plugin-permission-common');
|
|
9
10
|
var RoadmapDatabaseClient = require('./database/RoadmapDatabaseClient.cjs.js');
|
|
11
|
+
var RoadmapGitlabClient = require('./gitlab/RoadmapGitlabClient.cjs.js');
|
|
10
12
|
|
|
11
13
|
const roadmapPlugin = backendPluginApi.createBackendPlugin({
|
|
12
14
|
pluginId: "roadmap",
|
|
@@ -25,18 +27,28 @@ const roadmapPlugin = backendPluginApi.createBackendPlugin({
|
|
|
25
27
|
async init({
|
|
26
28
|
httpRouter,
|
|
27
29
|
logger,
|
|
28
|
-
config,
|
|
30
|
+
config: config$1,
|
|
29
31
|
database,
|
|
30
32
|
userInfo,
|
|
31
33
|
httpAuth,
|
|
32
34
|
permissions,
|
|
33
35
|
cache
|
|
34
36
|
}) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const datasource = config.getDatasource(config$1);
|
|
38
|
+
const permissionEnabled = config.isPermissionEnabled(config$1);
|
|
39
|
+
let db;
|
|
40
|
+
if (datasource === "database") {
|
|
41
|
+
db = await RoadmapDatabaseClient.RoadmapDatabaseClient.create({
|
|
42
|
+
database,
|
|
43
|
+
logger
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
db = RoadmapGitlabClient.RoadmapGitlabClient.create({
|
|
47
|
+
gitlab: config.getGitlabConfig(config$1),
|
|
48
|
+
logger,
|
|
49
|
+
cache
|
|
50
|
+
});
|
|
51
|
+
}
|
|
40
52
|
if (!permissionEnabled) {
|
|
41
53
|
logger.warn(
|
|
42
54
|
"Permissions are disabled. Using configArray for admin users."
|
|
@@ -45,7 +57,7 @@ const roadmapPlugin = backendPluginApi.createBackendPlugin({
|
|
|
45
57
|
httpRouter.use(
|
|
46
58
|
await router.createRouter({
|
|
47
59
|
logger,
|
|
48
|
-
config,
|
|
60
|
+
config: config$1,
|
|
49
61
|
db,
|
|
50
62
|
userInfo,
|
|
51
63
|
httpAuth,
|
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 { RoadmapDatabaseClient } from './database/RoadmapDatabaseClient';\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 db = await RoadmapDatabaseClient.create({\n
|
|
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';\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\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 }),\n );\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","config","getDatasource","isPermissionEnabled","RoadmapDatabaseClient","RoadmapGitlabClient","getGitlabConfig","createRouter"],"mappings":";;;;;;;;;;;;AAeO,MAAM,gBAAgBA,oCAAoB,CAAA;AAAA,EAC/C,QAAU,EAAA,SAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,YAAYC,6BAAa,CAAA,UAAA;AAAA,QACzB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,aAAaA,6BAAa,CAAA,WAAA;AAAA,QAC1B,OAAOA,6BAAa,CAAA;AAAA,OACtB;AAAA,MACA,MAAM,IAAK,CAAA;AAAA,QACT,UAAA;AAAA,QACA,MAAA;AAAA,gBACAC,QAAA;AAAA,QACA,QAAA;AAAA,QACA,QAAA;AAAA,QACA,QAAA;AAAA,QACA,WAAA;AAAA,QACA;AAAA,OACC,EAAA;AACD,QAAM,MAAA,UAAA,GAAaC,qBAAcD,QAAM,CAAA;AACvC,QAAM,MAAA,iBAAA,GAAoBE,2BAAoBF,QAAM,CAAA;AAEpD,QAAI,IAAA,EAAA;AACJ,QAAA,IAAI,eAAe,UAAY,EAAA;AAC7B,UAAK,EAAA,GAAA,MAAMG,4CAAsB,MAAO,CAAA;AAAA,YACtC,QAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,SACI,MAAA;AACL,UAAA,EAAA,GAAKC,wCAAoB,MAAO,CAAA;AAAA,YAC9B,MAAA,EAAQC,uBAAgBL,QAAM,CAAA;AAAA,YAC9B,MAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA;AAGH,QAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,UAAO,MAAA,CAAA,IAAA;AAAA,YACL;AAAA,WACF;AAAA;AAGF,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAMM,mBAAa,CAAA;AAAA,YACjB,MAAA;AAAA,oBACAN,QAAA;AAAA,YACA,EAAA;AAAA,YACA,QAAA;AAAA,YACA,QAAA;AAAA,YACA,WAAA,EAAa,oBAAoB,WAAc,GAAA,MAAA;AAAA,YAC/C;AAAA,WACD;AAAA,SACH;AACA,QAAA,UAAA,CAAW,aAAc,CAAA;AAAA,UACvB,IAAM,EAAA,SAAA;AAAA,UACN,KAAO,EAAA;AAAA,SACR,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
|
|
@@ -18,6 +18,12 @@ function featuresRouter(options) {
|
|
|
18
18
|
router.post("/", async (req, res, next) => {
|
|
19
19
|
try {
|
|
20
20
|
const username = await permissionService.getUsername(req);
|
|
21
|
+
const canCreate = await permissionService.canCreateFeature(req, username);
|
|
22
|
+
if (!canCreate) {
|
|
23
|
+
throw new errors.NotAllowedError(
|
|
24
|
+
"User does not have permission to create features"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
21
27
|
const { title, description } = req.body;
|
|
22
28
|
if (!title || typeof title !== "string") {
|
|
23
29
|
throw new errors.InputError("Title is required");
|
|
@@ -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 } = options;\n const router = Router();\n\n // Initialize services\n const featureService = new FeatureService(db, logger);\n const permissionService = new PermissionService(options);\n\n // Create new feature\n router.post('/', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\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 (_, res, next) => {\n try {\n const features = await featureService.getAllFeatures();\n res.status(200).json(features);\n } catch (error) {\n next(error);\n }\n });\n\n // Get feature by ID\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 // Update feature status (admin only)\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 return router;\n}\n"],"names":["Router","FeatureService","PermissionService","
|
|
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 } = options;\n const router = Router();\n\n // Initialize services\n const featureService = new FeatureService(db, logger);\n const permissionService = new PermissionService(options);\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 (_, res, next) => {\n try {\n const features = await featureService.getAllFeatures();\n res.status(200).json(features);\n } catch (error) {\n next(error);\n }\n });\n\n // Get feature by ID\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 // Update feature status (admin only)\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 return router;\n}\n"],"names":["Router","FeatureService","Permission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;AAAA;AAGF,MAAA,MAAM,QAAW,GAAA,MAAM,iBAAkB,CAAA,WAAA,CAAY,GAAG,CAAA;AACxD,MAAA,MAAM,OAAU,GAAA,MAAM,iBAAkB,CAAA,cAAA,CAAe,KAAK,QAAQ,CAAA;AAEpE,MAAA,IAAI,CAAC,OAAS,EAAA;AACZ,QAAM,MAAA,IAAIF,uBAAgB,6BAA6B,CAAA;AAAA;AAGzD,MAAM,MAAA,cAAA,GAAiB,MAAM,cAAe,CAAA,mBAAA;AAAA,QAC1C,EAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,GAAA,CAAI,MAAO,CAAA,GAAG,CAAE,CAAA,IAAA,CAAK,cAAc,CAAA;AAAA,aAC5B,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA;AACZ,GACD,CAAA;AAED,EAAO,OAAA,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 {
|
|
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 { RoadmapDatasource } from '../types';\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}\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":";;;;;;;;;;;;;;;;;AAmCA,eAAsB,aACpB,OACyB,EAAA;AACzB,EAAM,MAAA,EAAE,MAAQ,EAAA,MAAA,EAAW,GAAA,OAAA;AAE3B,EAAA,MAAM,SAASA,uBAAO,EAAA;AACtB,EAAO,MAAA,CAAA,GAAA,CAAIC,wBAAQ,CAAA,IAAA,EAAM,CAAA;AAGzB,EAAA,MAAM,8BAA8BC,sDAAkC,CAAA;AAAA,IACpE,WAAa,EAAAC;AAAA,GACd,CAAA;AAGD,EAAA,MAAA,CAAO,GAAI,CAAA,SAAA,EAAW,CAAC,CAAA,EAAG,QAAa,KAAA;AACrC,IAAA,MAAA,CAAO,KAAK,OAAO,CAAA;AACnB,IAAA,QAAA,CAAS,IAAK,CAAA,EAAE,MAAQ,EAAA,IAAA,EAAM,CAAA;AAAA,GAC/B,CAAA;AAED,EAAA,MAAA,CAAO,IAAI,2BAA2B,CAAA;AAGtC,EAAA,MAAA,CAAO,GAAI,CAAA,WAAA,EAAaC,6BAAe,CAAA,OAAO,CAAC,CAAA;AAC/C,EAAA,MAAA,CAAO,GAAI,CAAA,WAAA,EAAaC,6BAAe,CAAA,OAAO,CAAC,CAAA;AAC/C,EAAA,MAAA,CAAO,GAAI,CAAA,QAAA,EAAUC,uBAAY,CAAA,OAAO,CAAC,CAAA;AACzC,EAAA,MAAA,CAAO,GAAI,CAAA,cAAA,EAAgBC,2CAAsB,CAAA,OAAO,CAAC,CAAA;AAGzD,EAAA,MAAM,aAAaC,gCAAkB,CAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,QAAQ,CAAA;AAC9D,EAAO,MAAA,CAAA,GAAA,CAAI,UAAW,CAAA,KAAA,EAAO,CAAA;AAE7B,EAAO,OAAA,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 {
|
|
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 { CommentServiceInterface } from './types';\nimport {\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { InputError } from '@backstage/errors';\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 ) {}\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"],"names":["InputError"],"mappings":";;;;AAYO,MAAM,cAAkD,CAAA;AAAA,EAC7D,WAAA,CACmB,IACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAChB;AAAA;AAAA;AAAA,EAKK,mBAAmB,OAA2B,EAAA;AACpD,IAAI,IAAA,CAAC,QAAQ,SAAW,EAAA;AACtB,MAAM,MAAA,IAAIA,kBAAW,wBAAwB,CAAA;AAAA;AAG/C,IAAA,IAAI,CAAC,OAAQ,CAAA,IAAA,IAAQ,QAAQ,IAAK,CAAA,IAAA,OAAW,EAAI,EAAA;AAC/C,MAAM,MAAA,IAAIA,kBAAW,8CAA8C,CAAA;AAAA;AAGrE,IAAI,IAAA,OAAA,CAAQ,IAAK,CAAA,MAAA,GAAS,GAAM,EAAA;AAC9B,MAAA,MAAM,IAAIA,iBAAA;AAAA,QACR;AAAA,OACF;AAAA;AACF;AACF,EAEA,MAAM,WAAW,OAAuC,EAAA;AACtD,IAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,CAA6B,0BAAA,EAAA,OAAA,CAAQ,SAAS,CAAE,CAAA,CAAA;AACjE,IAAA,IAAA,CAAK,mBAAmB,OAAO,CAAA;AAC/B,IAAO,OAAA,IAAA,CAAK,EAAG,CAAA,UAAA,CAAW,OAAO,CAAA;AAAA;AACnC,EAEA,MAAM,uBAAuB,SAAuC,EAAA;AAClE,IAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,CAAiC,8BAAA,EAAA,SAAS,CAAE,CAAA,CAAA;AAC7D,IAAO,OAAA,IAAA,CAAK,EAAG,CAAA,sBAAA,CAAuB,SAAS,CAAA;AAAA;AAEnD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeatureService.cjs.js","sources":["../../src/services/FeatureService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport {
|
|
1
|
+
{"version":3,"file":"FeatureService.cjs.js","sources":["../../src/services/FeatureService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatasource } from '../types';\nimport { FeatureServiceInterface } from './types';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Implementation of the Feature Service\n */\nexport class FeatureService implements FeatureServiceInterface {\n constructor(\n private readonly db: RoadmapDatasource,\n private readonly logger: LoggerService,\n ) {}\n\n /**\n * Validates a feature before adding it\n */\n private validateNewFeature(feature: NewFeature): void {\n if (!feature.title || feature.title.trim() === '') {\n throw new InputError('Title is required and cannot be empty');\n }\n\n if (!feature.description || feature.description.trim() === '') {\n throw new InputError('Description is required and cannot be empty');\n }\n\n if (feature.title.length > 100) {\n throw new InputError('Title cannot be longer than 100 characters');\n }\n }\n\n /**\n * Validates a feature status before updating\n */\n private validateStatus(status: FeatureStatus): void {\n const validStatuses = Object.values(FeatureStatus);\n if (!validStatuses.includes(status)) {\n throw new InputError(\n `Invalid status: ${status}. Must be one of: ${validStatuses.join(\n ', ',\n )}`,\n );\n }\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n this.logger.info('Fetching all features');\n return this.db.getAllFeatures();\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n this.logger.info(`Fetching feature with id ${id}`);\n return this.db.getFeatureById(id);\n }\n\n async addFeature(feature: NewFeature, author: string): Promise<Feature> {\n this.logger.info(`Adding new feature: ${feature.title} by ${author}`);\n this.validateNewFeature(feature);\n return this.db.addFeature({ ...feature, author });\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n this.logger.info(`Updating feature ${id} status to ${status}`);\n this.validateStatus(status);\n return this.db.updateFeatureStatus(id, status);\n }\n}\n"],"names":["InputError","FeatureStatus"],"mappings":";;;;;AAaO,MAAM,cAAkD,CAAA;AAAA,EAC7D,WAAA,CACmB,IACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAChB;AAAA;AAAA;AAAA,EAKK,mBAAmB,OAA2B,EAAA;AACpD,IAAA,IAAI,CAAC,OAAQ,CAAA,KAAA,IAAS,QAAQ,KAAM,CAAA,IAAA,OAAW,EAAI,EAAA;AACjD,MAAM,MAAA,IAAIA,kBAAW,uCAAuC,CAAA;AAAA;AAG9D,IAAA,IAAI,CAAC,OAAQ,CAAA,WAAA,IAAe,QAAQ,WAAY,CAAA,IAAA,OAAW,EAAI,EAAA;AAC7D,MAAM,MAAA,IAAIA,kBAAW,6CAA6C,CAAA;AAAA;AAGpE,IAAI,IAAA,OAAA,CAAQ,KAAM,CAAA,MAAA,GAAS,GAAK,EAAA;AAC9B,MAAM,MAAA,IAAIA,kBAAW,4CAA4C,CAAA;AAAA;AACnE;AACF;AAAA;AAAA;AAAA,EAKQ,eAAe,MAA6B,EAAA;AAClD,IAAM,MAAA,aAAA,GAAgB,MAAO,CAAA,MAAA,CAAOC,0CAAa,CAAA;AACjD,IAAA,IAAI,CAAC,aAAA,CAAc,QAAS,CAAA,MAAM,CAAG,EAAA;AACnC,MAAA,MAAM,IAAID,iBAAA;AAAA,QACR,CAAA,gBAAA,EAAmB,MAAM,CAAA,kBAAA,EAAqB,aAAc,CAAA,IAAA;AAAA,UAC1D;AAAA,SACD,CAAA;AAAA,OACH;AAAA;AACF;AACF,EAEA,MAAM,cAAqC,GAAA;AACzC,IAAK,IAAA,CAAA,MAAA,CAAO,KAAK,uBAAuB,CAAA;AACxC,IAAO,OAAA,IAAA,CAAK,GAAG,cAAe,EAAA;AAAA;AAChC,EAEA,MAAM,eAAe,EAA8B,EAAA;AACjD,IAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,CAA4B,yBAAA,EAAA,EAAE,CAAE,CAAA,CAAA;AACjD,IAAO,OAAA,IAAA,CAAK,EAAG,CAAA,cAAA,CAAe,EAAE,CAAA;AAAA;AAClC,EAEA,MAAM,UAAW,CAAA,OAAA,EAAqB,MAAkC,EAAA;AACtE,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAA,oBAAA,EAAuB,QAAQ,KAAK,CAAA,IAAA,EAAO,MAAM,CAAE,CAAA,CAAA;AACpE,IAAA,IAAA,CAAK,mBAAmB,OAAO,CAAA;AAC/B,IAAA,OAAO,KAAK,EAAG,CAAA,UAAA,CAAW,EAAE,GAAG,OAAA,EAAS,QAAQ,CAAA;AAAA;AAClD,EAEA,MAAM,mBACJ,CAAA,EAAA,EACA,MACkB,EAAA;AAClB,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAA,iBAAA,EAAoB,EAAE,CAAA,WAAA,EAAc,MAAM,CAAE,CAAA,CAAA;AAC7D,IAAA,IAAA,CAAK,eAAe,MAAM,CAAA;AAC1B,IAAA,OAAO,IAAK,CAAA,EAAA,CAAG,mBAAoB,CAAA,EAAA,EAAI,MAAM,CAAA;AAAA;AAEjD;;;;"}
|
|
@@ -27,8 +27,8 @@ class PermissionService {
|
|
|
27
27
|
}
|
|
28
28
|
async checkPermission(req, username, permission) {
|
|
29
29
|
const { config: config$1, logger, permissions, httpAuth } = this.options;
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
30
|
+
const adminUsers = config.getAdminUsers(config$1);
|
|
31
|
+
if (adminUsers.includes(username)) {
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
34
|
if (!permissions) {
|
|
@@ -57,6 +57,9 @@ class PermissionService {
|
|
|
57
57
|
async isRoadmapAdmin(req, username) {
|
|
58
58
|
return this.checkPermission(req, username, backstagePluginRoadmapCommon.roadmapAdminPermission);
|
|
59
59
|
}
|
|
60
|
+
async canCreateFeature(req, username) {
|
|
61
|
+
return this.checkPermission(req, username, backstagePluginRoadmapCommon.roadmapCreatePermission);
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
exports.PermissionService = PermissionService;
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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,iBAAwD,CAAA;AAAA,EAClD,OAAA;AAAA,EAEjB,YAAY,OAAwB,EAAA;AAClC,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA;AAAA;AACjB,EAEA,MAAM,YAAY,GAA+B,EAAA;AAC/C,IAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,MAAA,KAAW,IAAK,CAAA,OAAA;AAC5C,IAAA,MAAM,WAAc,GAAA,MAAM,QAAS,CAAA,WAAA,CAAY,GAAG,CAAA;AAClD,IAAA,IAAI,CAAC,WAAa,EAAA;AAChB,MAAA,MAAA,CAAO,KAAK,6BAA6B,CAAA;AACzC,MAAM,MAAA,IAAIA,uBAAgB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AgB,CAAA,KAAA;AACtD,MAAO,MAAA,CAAA,IAAA;AAAA,QACL,CAAA,WAAA,EAAc,WAAW,IAAI,CAAA,CAAA,EAC3B,YAAY,SAAY,GAAA,QAC1B,YAAY,QAAQ,CAAA;AAAA,OACtB;AAEA,MAAO,OAAA,SAAA;AAAA,aACA,KAAO,EAAA;AACd,MAAO,MAAA,CAAA,KAAA,CAAM,CAAgC,6BAAA,EAAA,QAAQ,CAAE,CAAA,CAAA;AACvD,MAAM,MAAA,IAAIJ,uBAAgB,yBAAyB,CAAA;AAAA;AACrD;AACF,EAEA,MAAM,cAAe,CAAA,GAAA,EAAc,QAAoC,EAAA;AACrE,IAAA,OAAO,IAAK,CAAA,eAAA,CAAgB,GAAK,EAAA,QAAA,EAAUK,mDAAsB,CAAA;AAAA;AACnE,EAEA,MAAM,gBAAiB,CAAA,GAAA,EAAc,QAAoC,EAAA;AACvE,IAAA,OAAO,IAAK,CAAA,eAAA,CAAgB,GAAK,EAAA,QAAA,EAAUC,oDAAuB,CAAA;AAAA;AAEtE;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoteService.cjs.js","sources":["../../src/services/VoteService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport {
|
|
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,WAA4C,CAAA;AAAA,EACvD,WAAA,CACmB,IACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAChB,EAEH,MAAM,UACJ,CAAA,SAAA,EACA,KACoD,EAAA;AACpD,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAA,0BAAA,EAA6B,SAAS,CAAA,IAAA,EAAO,KAAK,CAAE,CAAA,CAAA;AACrE,IAAA,OAAO,IAAK,CAAA,EAAA,CAAG,UAAW,CAAA,SAAA,EAAW,KAAK,CAAA;AAAA;AAC5C,EAEA,MAAM,aAAa,SAAoC,EAAA;AACrD,IAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,CAAkC,+BAAA,EAAA,SAAS,CAAE,CAAA,CAAA;AAC9D,IAAO,OAAA,IAAA,CAAK,EAAG,CAAA,YAAA,CAAa,SAAS,CAAA;AAAA;AACvC,EAEA,MAAM,cAAc,UAAuD,EAAA;AACzE,IAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,CAA2B,wBAAA,EAAA,UAAA,CAAW,MAAM,CAAW,SAAA,CAAA,CAAA;AACxE,IAAI,IAAA,UAAA,CAAW,WAAW,CAAG,EAAA;AAC3B,MAAA,OAAO,EAAC;AAAA;AAEV,IAAO,OAAA,IAAA,CAAK,EAAG,CAAA,aAAA,CAAc,UAAU,CAAA;AAAA;AACzC,EAEA,MAAM,QAAS,CAAA,SAAA,EAAmB,KAAiC,EAAA;AACjE,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAA,YAAA,EAAe,KAAK,CAAA,sBAAA,EAAyB,SAAS,CAAE,CAAA,CAAA;AACzE,IAAA,OAAO,IAAK,CAAA,EAAA,CAAG,QAAS,CAAA,SAAA,EAAW,KAAK,CAAA;AAAA;AAC1C,EAEA,MAAM,aACJ,CAAA,UAAA,EACA,KACkC,EAAA;AAClC,IAAA,IAAA,CAAK,MAAO,CAAA,IAAA;AAAA,MACV,CAAe,YAAA,EAAA,KAAK,CAAiB,cAAA,EAAA,UAAA,CAAW,MAAM,CAAA,SAAA;AAAA,KACxD;AACA,IAAI,IAAA,UAAA,CAAW,WAAW,CAAG,EAAA;AAC3B,MAAA,OAAO,EAAC;AAAA;AAEV,IAAA,OAAO,IAAK,CAAA,EAAA,CAAG,aAAc,CAAA,UAAA,EAAY,KAAK,CAAA;AAAA;AAElD;;;;"}
|
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.5.0",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@backstage/backend-defaults": "^0.15.2",
|
|
36
36
|
"@backstage/backend-plugin-api": "^1.7.0",
|
|
37
|
+
"@backstage/catalog-model": "^1.7.7",
|
|
37
38
|
"@backstage/config": "^1.3.6",
|
|
38
39
|
"@backstage/errors": "^1.2.7",
|
|
39
40
|
"@backstage/plugin-permission-common": "^0.9.6",
|
|
@@ -41,8 +42,7 @@
|
|
|
41
42
|
"@rothenbergt/backstage-plugin-roadmap-common": "^0.3.0",
|
|
42
43
|
"express": "^4.17.1",
|
|
43
44
|
"express-promise-router": "^4.1.0",
|
|
44
|
-
"knex": "^3.1.0"
|
|
45
|
-
"node-fetch": "^2.6.7"
|
|
45
|
+
"knex": "^3.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@backstage/backend-test-utils": "^1.11.0",
|