@stackmemoryai/stackmemory 0.5.28 → 0.5.30
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/README.md +37 -16
- package/dist/cli/claude-sm.js +17 -5
- package/dist/cli/claude-sm.js.map +2 -2
- package/dist/core/database/batch-operations.js +29 -4
- package/dist/core/database/batch-operations.js.map +2 -2
- package/dist/core/database/connection-pool.js +13 -2
- package/dist/core/database/connection-pool.js.map +2 -2
- package/dist/core/database/migration-manager.js +130 -34
- package/dist/core/database/migration-manager.js.map +2 -2
- package/dist/core/database/paradedb-adapter.js +23 -7
- package/dist/core/database/paradedb-adapter.js.map +2 -2
- package/dist/core/database/query-router.js +8 -3
- package/dist/core/database/query-router.js.map +2 -2
- package/dist/core/database/sqlite-adapter.js +152 -33
- package/dist/core/database/sqlite-adapter.js.map +2 -2
- package/dist/hooks/session-summary.js +23 -2
- package/dist/hooks/session-summary.js.map +2 -2
- package/dist/hooks/sms-notify.js +47 -13
- package/dist/hooks/sms-notify.js.map +2 -2
- package/dist/integrations/linear/auth.js +34 -20
- package/dist/integrations/linear/auth.js.map +2 -2
- package/dist/integrations/linear/auto-sync.js +18 -8
- package/dist/integrations/linear/auto-sync.js.map +2 -2
- package/dist/integrations/linear/client.js +42 -9
- package/dist/integrations/linear/client.js.map +2 -2
- package/dist/integrations/linear/migration.js +94 -36
- package/dist/integrations/linear/migration.js.map +2 -2
- package/dist/integrations/linear/oauth-server.js +77 -34
- package/dist/integrations/linear/oauth-server.js.map +2 -2
- package/dist/integrations/linear/rest-client.js +13 -3
- package/dist/integrations/linear/rest-client.js.map +2 -2
- package/dist/integrations/linear/sync-service.js +18 -15
- package/dist/integrations/linear/sync-service.js.map +2 -2
- package/dist/integrations/linear/sync.js +12 -4
- package/dist/integrations/linear/sync.js.map +2 -2
- package/dist/integrations/linear/unified-sync.js +33 -8
- package/dist/integrations/linear/unified-sync.js.map +2 -2
- package/dist/integrations/linear/webhook-handler.js +5 -1
- package/dist/integrations/linear/webhook-handler.js.map +2 -2
- package/dist/integrations/linear/webhook-server.js +7 -7
- package/dist/integrations/linear/webhook-server.js.map +2 -2
- package/dist/integrations/linear/webhook.js +9 -2
- package/dist/integrations/linear/webhook.js.map +2 -2
- package/dist/integrations/mcp/schemas.js +147 -0
- package/dist/integrations/mcp/schemas.js.map +7 -0
- package/dist/integrations/mcp/server.js +19 -3
- package/dist/integrations/mcp/server.js.map +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/integrations/linear/migration.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Linear Workspace Migration Tool\n * Migrates all tasks from one Linear workspace to another\n */\n\nimport { LinearRestClient } from './rest-client.js';\nimport { logger } from '../../core/monitoring/logger.js';\nimport chalk from 'chalk';\n\nexport interface MigrationConfig {\n sourceApiKey: string;\n targetApiKey: string;\n dryRun?: boolean;\n includeStates?: string[]; // Filter by state\n taskPrefix?: string; // Only migrate tasks with this identifier prefix (e.g., \"STA-\")\n deleteFromSource?: boolean; // Delete tasks from source after successful migration\n batchSize?: number;\n delayMs?: number; // Delay between API calls\n}\n\nexport interface MigrationResult {\n totalTasks: number;\n exported: number;\n imported: number;\n failed: number;\n deleted: number;\n deleteFailed: number;\n errors: string[];\n taskMappings: Array<{\n sourceId: string;\n sourceIdentifier: string;\n targetId?: string;\n targetIdentifier?: string;\n deleted?: boolean;\n error?: string;\n }>;\n}\n\nexport class LinearMigrator {\n private sourceClient: LinearRestClient;\n private targetClient: LinearRestClient;\n private config: MigrationConfig;\n\n constructor(config: MigrationConfig) {\n this.config = config;\n this.sourceClient = new LinearRestClient(config.sourceApiKey);\n this.targetClient = new LinearRestClient(config.targetApiKey);\n }\n\n /**\n * Test connections to both workspaces\n */\n async testConnections(): Promise<{\n source: { success: boolean; info?: any; error?: string };\n target: { success: boolean; info?: any; error?: string };\n }> {\n const result = {\n source: { success: false } as any,\n target: { success: false } as any\n };\n\n // Test source connection\n try {\n const sourceViewer = await this.sourceClient.getViewer();\n const sourceTeam = await this.sourceClient.getTeam();\n result.source = {\n success: true,\n info: {\n user: sourceViewer,\n team: sourceTeam\n }\n };\n } catch (error: unknown) {\n result.source = {\n success: false,\n error: (error as Error).message\n };\n }\n\n // Test target connection \n try {\n const targetViewer = await this.targetClient.getViewer();\n const targetTeam = await this.targetClient.getTeam();\n result.target = {\n success: true,\n info: {\n user: targetViewer,\n team: targetTeam\n }\n };\n } catch (error: unknown) {\n result.target = {\n success: false,\n error: (error as Error).message\n };\n }\n\n return result;\n }\n\n /**\n * Migrate all tasks from source to target workspace\n */\n async migrate(): Promise<MigrationResult> {\n const result: MigrationResult = {\n totalTasks: 0,\n exported: 0,\n imported: 0,\n failed: 0,\n deleted: 0,\n deleteFailed: 0,\n errors: [],\n taskMappings: []\n };\n\n try {\n console.log(chalk.yellow('\uD83D\uDD04 Starting Linear workspace migration...'));\n\n // Get all tasks from source\n const sourceTasks = await this.sourceClient.getAllTasks(true); // Force refresh\n result.totalTasks = sourceTasks.length;\n console.log(chalk.cyan(`\uD83D\uDCCB Found ${sourceTasks.length} tasks in source workspace`));\n\n // Filter by prefix (e.g., \"STA-\" tasks only)\n let tasksToMigrate = sourceTasks;\n if (this.config.taskPrefix) {\n tasksToMigrate = sourceTasks.filter((task: any) => \n task.identifier.startsWith(this.config.taskPrefix!)\n );\n console.log(chalk.cyan(`\uD83D\uDCCB Filtered to ${tasksToMigrate.length} tasks with prefix \"${this.config.taskPrefix}\"`));\n }\n\n // Filter by states if specified\n if (this.config.includeStates?.length) {\n tasksToMigrate = tasksToMigrate.filter((task: any) => \n this.config.includeStates!.includes(task.state.type)\n );\n console.log(chalk.cyan(`\uD83D\uDCCB Further filtered to ${tasksToMigrate.length} tasks matching states: ${this.config.includeStates.join(', ')}`));\n }\n\n result.exported = tasksToMigrate.length;\n\n if (this.config.dryRun) {\n console.log(chalk.yellow('\uD83D\uDD0D DRY RUN - No tasks will be created'));\n tasksToMigrate.forEach(task => {\n result.taskMappings.push({\n sourceId: task.id,\n sourceIdentifier: task.identifier,\n targetId: 'DRY_RUN',\n targetIdentifier: 'DRY_RUN'\n });\n });\n result.imported = tasksToMigrate.length;\n return result;\n }\n\n // Get target team info\n const targetTeam = await this.targetClient.getTeam();\n console.log(chalk.cyan(`\uD83C\uDFAF Target team: ${targetTeam.name} (${targetTeam.key})`));\n\n // Migrate tasks in batches\n const batchSize = this.config.batchSize || 5;\n const delayMs = this.config.delayMs || 2000;\n\n for (let i = 0; i < tasksToMigrate.length; i += batchSize) {\n const batch = tasksToMigrate.slice(i, i + batchSize);\n console.log(chalk.yellow(`\uD83D\uDCE6 Processing batch ${Math.floor(i / batchSize) + 1}/${Math.ceil(tasksToMigrate.length / batchSize)}`));\n\n for (const task of batch) {\n try {\n const newTask = await this.migrateTask(task, targetTeam.id);\n const mapping = {\n sourceId: task.id,\n sourceIdentifier: task.identifier,\n targetId: newTask.id,\n targetIdentifier: newTask.identifier,\n deleted: false\n };\n\n result.imported++;\n console.log(chalk.green(`\u2705 ${task.identifier} \u2192 ${newTask.identifier}: ${task.title}`));\n\n // Delete from source if configured\n if (this.config.deleteFromSource) {\n try {\n await this.deleteTask(task.id);\n mapping.deleted = true;\n result.deleted++;\n console.log(chalk.gray(`\uD83D\uDDD1\uFE0F Deleted ${task.identifier} from source`));\n } catch (deleteError: unknown) {\n result.deleteFailed++;\n result.errors.push(`Delete failed for ${task.identifier}: ${(deleteError as Error).message}`);\n console.log(chalk.yellow(`\u26A0\uFE0F Failed to delete ${task.identifier} from source: ${(deleteError as Error).message}`));\n }\n }\n\n result.taskMappings.push(mapping);\n } catch (error: unknown) {\n const errorMsg = (error as Error).message;\n result.errors.push(`${task.identifier}: ${errorMsg}`);\n result.taskMappings.push({\n sourceId: task.id,\n sourceIdentifier: task.identifier,\n error: errorMsg\n });\n result.failed++;\n console.log(chalk.red(`\u274C ${task.identifier}: ${errorMsg}`));\n }\n }\n\n // Delay between batches to avoid rate limits\n if (i + batchSize < tasksToMigrate.length) {\n console.log(chalk.gray(`\u23F3 Waiting ${delayMs}ms before next batch...`));\n await this.delay(delayMs);\n }\n }\n\n } catch (error: unknown) {\n result.errors.push(`Migration failed: ${(error as Error).message}`);\n logger.error('Migration failed:', error as Error);\n }\n\n return result;\n }\n\n /**\n * Migrate a single task\n */\n private async migrateTask(sourceTask: any, targetTeamId: string): Promise<any> {\n // Map states from source to target format\n const stateMapping: Record<string, string> = {\n 'backlog': 'backlog',\n 'unstarted': 'unstarted', \n 'started': 'started',\n 'completed': 'completed',\n 'canceled': 'canceled'\n };\n\n // Create task in target workspace using GraphQL\n const createTaskQuery = `\n mutation CreateIssue($input: IssueCreateInput!) {\n issueCreate(input: $input) {\n success\n issue {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n // Prepare task input\n const taskInput = {\n title: `[MIGRATED] ${sourceTask.title}`,\n description: this.formatMigratedDescription(sourceTask),\n teamId: targetTeamId,\n priority: this.mapPriority(sourceTask.priority)\n };\n\n const response = await this.targetClient.makeRequest<{\n data: {\n issueCreate: {\n success: boolean;\n issue: any;\n };\n };\n }>(createTaskQuery, { input: taskInput });\n\n if (!response.data?.issueCreate?.success) {\n throw new Error('Failed to create task in target workspace');\n }\n\n return response.data.issueCreate.issue;\n }\n\n /**\n * Format description with migration context\n */\n private formatMigratedDescription(sourceTask: any): string {\n let description = sourceTask.description || '';\n \n description += `\\n\\n---\\n**Migration Info:**\\n`;\n description += `- Original ID: ${sourceTask.identifier}\\n`;\n description += `- Migrated: ${new Date().toISOString()}\\n`;\n description += `- Original State: ${sourceTask.state.name}\\n`;\n \n if (sourceTask.assignee) {\n description += `- Original Assignee: ${sourceTask.assignee.name}\\n`;\n }\n \n if (sourceTask.estimate) {\n description += `- Original Estimate: ${sourceTask.estimate} points\\n`;\n }\n\n return description;\n }\n\n /**\n * Map priority values\n */\n private mapPriority(priority?: number): number {\n // Linear priorities: 0=none, 1=urgent, 2=high, 3=medium, 4=low\n return priority || 0;\n }\n\n /**\n * Delete a task from the source workspace\n */\n private async deleteTask(taskId: string): Promise<void> {\n const deleteQuery = `\n mutation DeleteIssue($id: String!) {\n issueDelete(id: $id) {\n success\n }\n }\n `;\n\n const response = await (this.sourceClient as any).makeRequest(deleteQuery, { id: taskId });\n \n if (!response.data?.issueDelete?.success) {\n throw new Error('Failed to delete task from source workspace');\n }\n }\n\n /**\n * Delay helper\n */\n private delay(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n}\n\n/**\n * CLI function to run migration\n */\nexport async function runMigration(config: MigrationConfig): Promise<void> {\n const migrator = new LinearMigrator(config);\n \n console.log(chalk.blue('\uD83D\uDD0D Testing connections...'));\n const connectionTest = await migrator.testConnections();\n \n if (!connectionTest.source.success) {\n console.error(chalk.red(`\u274C Source connection failed: ${connectionTest.source.error}`));\n return;\n }\n \n if (!connectionTest.target.success) {\n console.error(chalk.red(`\u274C Target connection failed: ${connectionTest.target.error}`));\n return;\n }\n \n console.log(chalk.green('\u2705 Both connections successful'));\n console.log(chalk.cyan(`\uD83D\uDCE4 Source: ${connectionTest.source.info.user.name} @ ${connectionTest.source.info.team.name}`));\n console.log(chalk.cyan(`\uD83D\uDCE5 Target: ${connectionTest.target.info.user.name} @ ${connectionTest.target.info.team.name}`));\n \n const result = await migrator.migrate();\n \n console.log(chalk.blue('\\n\uD83D\uDCCA Migration Summary:'));\n console.log(` Total tasks: ${result.totalTasks}`);\n console.log(` Exported: ${result.exported}`);\n console.log(chalk.green(` \u2705 Imported: ${result.imported}`));\n console.log(chalk.red(` \u274C Failed: ${result.failed}`));\n if (config.deleteFromSource) {\n console.log(chalk.gray(` \uD83D\uDDD1\uFE0F Deleted: ${result.deleted}`));\n if (result.deleteFailed > 0) {\n console.log(chalk.yellow(` \u26A0\uFE0F Delete failed: ${result.deleteFailed}`));\n }\n }\n \n if (result.errors.length > 0) {\n console.log(chalk.red('\\n\u274C Errors:'));\n result.errors.forEach(error => console.log(chalk.red(` - ${error}`)));\n }\n \n if (result.imported > 0) {\n console.log(chalk.green(`\\n\uD83C\uDF89 Migration completed! ${result.imported} tasks migrated successfully.`));\n if (config.deleteFromSource && result.deleted > 0) {\n console.log(chalk.gray(` ${result.deleted} tasks deleted from source workspace.`));\n }\n }\n}"],
|
|
5
|
-
"mappings": ";;;;AAKA,SAAS,wBAAwB;AACjC,SAAS,cAAc;AACvB,OAAO,WAAW;AA+BX,MAAM,eAAe;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,QAAyB;AACnC,SAAK,SAAS;AACd,SAAK,eAAe,IAAI,iBAAiB,OAAO,YAAY;AAC5D,SAAK,eAAe,IAAI,iBAAiB,OAAO,YAAY;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,kBAGH;AACD,UAAM,SAAS;AAAA,MACb,QAAQ,EAAE,SAAS,MAAM;AAAA,MACzB,QAAQ,EAAE,SAAS,MAAM;AAAA,IAC3B;AAGA,QAAI;AACF,YAAM,eAAe,MAAM,KAAK,aAAa,UAAU;AACvD,YAAM,aAAa,MAAM,KAAK,aAAa,QAAQ;AACnD,aAAO,SAAS;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,MAAM;AAAA,UACN,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF,SAAS,OAAgB;AACvB,aAAO,SAAS;AAAA,QACd,SAAS;AAAA,QACT,OAAQ,MAAgB;AAAA,MAC1B;AAAA,IACF;AAGA,QAAI;AACF,YAAM,eAAe,MAAM,KAAK,aAAa,UAAU;AACvD,YAAM,aAAa,MAAM,KAAK,aAAa,QAAQ;AACnD,aAAO,SAAS;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,MAAM;AAAA,UACN,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF,SAAS,OAAgB;AACvB,aAAO,SAAS;AAAA,QACd,SAAS;AAAA,QACT,OAAQ,MAAgB;AAAA,MAC1B;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAAoC;AACxC,UAAM,SAA0B;AAAA,MAC9B,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,cAAc;AAAA,MACd,QAAQ,CAAC;AAAA,MACT,cAAc,CAAC;AAAA,IACjB;AAEA,QAAI;AACF,cAAQ,IAAI,MAAM,OAAO,
|
|
4
|
+
"sourcesContent": ["/**\n * Linear Workspace Migration Tool\n * Migrates all tasks from one Linear workspace to another\n */\n\nimport { LinearRestClient } from './rest-client.js';\nimport { logger } from '../../core/monitoring/logger.js';\nimport { IntegrationError, ErrorCode } from '../../core/errors/index.js';\nimport chalk from 'chalk';\n\nexport interface MigrationConfig {\n sourceApiKey: string;\n targetApiKey: string;\n dryRun?: boolean;\n includeStates?: string[]; // Filter by state\n taskPrefix?: string; // Only migrate tasks with this identifier prefix (e.g., \"STA-\")\n deleteFromSource?: boolean; // Delete tasks from source after successful migration\n batchSize?: number;\n delayMs?: number; // Delay between API calls\n}\n\nexport interface MigrationResult {\n totalTasks: number;\n exported: number;\n imported: number;\n failed: number;\n deleted: number;\n deleteFailed: number;\n errors: string[];\n taskMappings: Array<{\n sourceId: string;\n sourceIdentifier: string;\n targetId?: string;\n targetIdentifier?: string;\n deleted?: boolean;\n error?: string;\n }>;\n}\n\nexport class LinearMigrator {\n private sourceClient: LinearRestClient;\n private targetClient: LinearRestClient;\n private config: MigrationConfig;\n\n constructor(config: MigrationConfig) {\n this.config = config;\n this.sourceClient = new LinearRestClient(config.sourceApiKey);\n this.targetClient = new LinearRestClient(config.targetApiKey);\n }\n\n /**\n * Test connections to both workspaces\n */\n async testConnections(): Promise<{\n source: { success: boolean; info?: any; error?: string };\n target: { success: boolean; info?: any; error?: string };\n }> {\n const result = {\n source: { success: false } as any,\n target: { success: false } as any,\n };\n\n // Test source connection\n try {\n const sourceViewer = await this.sourceClient.getViewer();\n const sourceTeam = await this.sourceClient.getTeam();\n result.source = {\n success: true,\n info: {\n user: sourceViewer,\n team: sourceTeam,\n },\n };\n } catch (error: unknown) {\n result.source = {\n success: false,\n error: (error as Error).message,\n };\n }\n\n // Test target connection\n try {\n const targetViewer = await this.targetClient.getViewer();\n const targetTeam = await this.targetClient.getTeam();\n result.target = {\n success: true,\n info: {\n user: targetViewer,\n team: targetTeam,\n },\n };\n } catch (error: unknown) {\n result.target = {\n success: false,\n error: (error as Error).message,\n };\n }\n\n return result;\n }\n\n /**\n * Migrate all tasks from source to target workspace\n */\n async migrate(): Promise<MigrationResult> {\n const result: MigrationResult = {\n totalTasks: 0,\n exported: 0,\n imported: 0,\n failed: 0,\n deleted: 0,\n deleteFailed: 0,\n errors: [],\n taskMappings: [],\n };\n\n try {\n console.log(chalk.yellow('Starting Linear workspace migration...'));\n\n // Get all tasks from source\n const sourceTasks = await this.sourceClient.getAllTasks(true); // Force refresh\n result.totalTasks = sourceTasks.length;\n console.log(\n chalk.cyan(`Found ${sourceTasks.length} tasks in source workspace`)\n );\n\n // Filter by prefix (e.g., \"STA-\" tasks only)\n let tasksToMigrate = sourceTasks;\n if (this.config.taskPrefix) {\n tasksToMigrate = sourceTasks.filter((task: any) =>\n task.identifier.startsWith(this.config.taskPrefix!)\n );\n console.log(\n chalk.cyan(\n `Filtered to ${tasksToMigrate.length} tasks with prefix \"${this.config.taskPrefix}\"`\n )\n );\n }\n\n // Filter by states if specified\n if (this.config.includeStates?.length) {\n tasksToMigrate = tasksToMigrate.filter((task: any) =>\n this.config.includeStates!.includes(task.state.type)\n );\n const stateStr = this.config.includeStates.join(', ');\n console.log(\n chalk.cyan(\n `Further filtered to ${tasksToMigrate.length} tasks matching states: ${stateStr}`\n )\n );\n }\n\n result.exported = tasksToMigrate.length;\n\n if (this.config.dryRun) {\n console.log(chalk.yellow('DRY RUN - No tasks will be created'));\n tasksToMigrate.forEach((task) => {\n result.taskMappings.push({\n sourceId: task.id,\n sourceIdentifier: task.identifier,\n targetId: 'DRY_RUN',\n targetIdentifier: 'DRY_RUN',\n });\n });\n result.imported = tasksToMigrate.length;\n return result;\n }\n\n // Get target team info\n const targetTeam = await this.targetClient.getTeam();\n console.log(\n chalk.cyan(`Target team: ${targetTeam.name} (${targetTeam.key})`)\n );\n\n // Migrate tasks in batches\n const batchSize = this.config.batchSize || 5;\n const delayMs = this.config.delayMs || 2000;\n\n for (let i = 0; i < tasksToMigrate.length; i += batchSize) {\n const batch = tasksToMigrate.slice(i, i + batchSize);\n console.log(\n chalk.yellow(\n `Processing batch ${Math.floor(i / batchSize) + 1}/${Math.ceil(tasksToMigrate.length / batchSize)}`\n )\n );\n\n for (const task of batch) {\n try {\n const newTask = await this.migrateTask(task, targetTeam.id);\n const mapping = {\n sourceId: task.id,\n sourceIdentifier: task.identifier,\n targetId: newTask.id,\n targetIdentifier: newTask.identifier,\n deleted: false,\n };\n\n result.imported++;\n console.log(\n chalk.green(\n `${task.identifier} \u2192 ${newTask.identifier}: ${task.title}`\n )\n );\n\n // Delete from source if configured\n if (this.config.deleteFromSource) {\n try {\n await this.deleteTask(task.id);\n mapping.deleted = true;\n result.deleted++;\n console.log(\n chalk.gray(`Deleted ${task.identifier} from source`)\n );\n } catch (deleteError: unknown) {\n result.deleteFailed++;\n result.errors.push(\n `Delete failed for ${task.identifier}: ${(deleteError as Error).message}`\n );\n console.log(\n chalk.yellow(\n `Failed to delete ${task.identifier} from source: ${(deleteError as Error).message}`\n )\n );\n }\n }\n\n result.taskMappings.push(mapping);\n } catch (error: unknown) {\n const errorMsg = (error as Error).message;\n result.errors.push(`${task.identifier}: ${errorMsg}`);\n result.taskMappings.push({\n sourceId: task.id,\n sourceIdentifier: task.identifier,\n error: errorMsg,\n });\n result.failed++;\n console.log(chalk.red(`${task.identifier}: ${errorMsg}`));\n }\n }\n\n // Delay between batches to avoid rate limits\n if (i + batchSize < tasksToMigrate.length) {\n console.log(chalk.gray(`Waiting ${delayMs}ms before next batch...`));\n await this.delay(delayMs);\n }\n }\n } catch (error: unknown) {\n result.errors.push(`Migration failed: ${(error as Error).message}`);\n logger.error('Migration failed:', error as Error);\n }\n\n return result;\n }\n\n /**\n * Migrate a single task\n */\n private async migrateTask(\n sourceTask: any,\n targetTeamId: string\n ): Promise<any> {\n // Map states from source to target format\n const stateMapping: Record<string, string> = {\n backlog: 'backlog',\n unstarted: 'unstarted',\n started: 'started',\n completed: 'completed',\n canceled: 'canceled',\n };\n\n // Create task in target workspace using GraphQL\n const createTaskQuery = `\n mutation CreateIssue($input: IssueCreateInput!) {\n issueCreate(input: $input) {\n success\n issue {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n // Prepare task input\n const taskInput = {\n title: `[MIGRATED] ${sourceTask.title}`,\n description: this.formatMigratedDescription(sourceTask),\n teamId: targetTeamId,\n priority: this.mapPriority(sourceTask.priority),\n };\n\n const response = await this.targetClient.makeRequest<{\n data: {\n issueCreate: {\n success: boolean;\n issue: any;\n };\n };\n }>(createTaskQuery, { input: taskInput });\n\n if (!response.data?.issueCreate?.success) {\n throw new IntegrationError(\n 'Failed to create task in target workspace',\n ErrorCode.LINEAR_SYNC_FAILED,\n { sourceTaskId: sourceTask.id, sourceIdentifier: sourceTask.identifier }\n );\n }\n\n return response.data.issueCreate.issue;\n }\n\n /**\n * Format description with migration context\n */\n private formatMigratedDescription(sourceTask: any): string {\n let description = sourceTask.description || '';\n\n description += `\\n\\n---\\n**Migration Info:**\\n`;\n description += `- Original ID: ${sourceTask.identifier}\\n`;\n description += `- Migrated: ${new Date().toISOString()}\\n`;\n description += `- Original State: ${sourceTask.state.name}\\n`;\n\n if (sourceTask.assignee) {\n description += `- Original Assignee: ${sourceTask.assignee.name}\\n`;\n }\n\n if (sourceTask.estimate) {\n description += `- Original Estimate: ${sourceTask.estimate} points\\n`;\n }\n\n return description;\n }\n\n /**\n * Map priority values\n */\n private mapPriority(priority?: number): number {\n // Linear priorities: 0=none, 1=urgent, 2=high, 3=medium, 4=low\n return priority || 0;\n }\n\n /**\n * Delete a task from the source workspace\n */\n private async deleteTask(taskId: string): Promise<void> {\n const deleteQuery = `\n mutation DeleteIssue($id: String!) {\n issueDelete(id: $id) {\n success\n }\n }\n `;\n\n const response = await (this.sourceClient as any).makeRequest(deleteQuery, {\n id: taskId,\n });\n\n if (!response.data?.issueDelete?.success) {\n throw new IntegrationError(\n 'Failed to delete task from source workspace',\n ErrorCode.LINEAR_SYNC_FAILED,\n { taskId }\n );\n }\n }\n\n /**\n * Delay helper\n */\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n\n/**\n * CLI function to run migration\n */\nexport async function runMigration(config: MigrationConfig): Promise<void> {\n const migrator = new LinearMigrator(config);\n\n console.log(chalk.blue('Testing connections...'));\n const connectionTest = await migrator.testConnections();\n\n if (!connectionTest.source.success) {\n console.error(\n chalk.red(`Source connection failed: ${connectionTest.source.error}`)\n );\n return;\n }\n\n if (!connectionTest.target.success) {\n console.error(\n chalk.red(`Target connection failed: ${connectionTest.target.error}`)\n );\n return;\n }\n\n console.log(chalk.green('Both connections successful'));\n console.log(\n chalk.cyan(\n `Source: ${connectionTest.source.info.user.name} @ ${connectionTest.source.info.team.name}`\n )\n );\n console.log(\n chalk.cyan(\n `Target: ${connectionTest.target.info.user.name} @ ${connectionTest.target.info.team.name}`\n )\n );\n\n const result = await migrator.migrate();\n\n console.log(chalk.blue('\\nMigration Summary:'));\n console.log(` Total tasks: ${result.totalTasks}`);\n console.log(` Exported: ${result.exported}`);\n console.log(chalk.green(` Imported: ${result.imported}`));\n console.log(chalk.red(` Failed: ${result.failed}`));\n if (config.deleteFromSource) {\n console.log(chalk.gray(` Deleted: ${result.deleted}`));\n if (result.deleteFailed > 0) {\n console.log(chalk.yellow(` Delete failed: ${result.deleteFailed}`));\n }\n }\n\n if (result.errors.length > 0) {\n console.log(chalk.red('\\nErrors:'));\n result.errors.forEach((error) => console.log(chalk.red(` - ${error}`)));\n }\n\n if (result.imported > 0) {\n console.log(\n chalk.green(\n `\\nMigration completed! ${result.imported} tasks migrated successfully.`\n )\n );\n if (config.deleteFromSource && result.deleted > 0) {\n console.log(\n chalk.gray(` ${result.deleted} tasks deleted from source workspace.`)\n );\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAKA,SAAS,wBAAwB;AACjC,SAAS,cAAc;AACvB,SAAS,kBAAkB,iBAAiB;AAC5C,OAAO,WAAW;AA+BX,MAAM,eAAe;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,QAAyB;AACnC,SAAK,SAAS;AACd,SAAK,eAAe,IAAI,iBAAiB,OAAO,YAAY;AAC5D,SAAK,eAAe,IAAI,iBAAiB,OAAO,YAAY;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,kBAGH;AACD,UAAM,SAAS;AAAA,MACb,QAAQ,EAAE,SAAS,MAAM;AAAA,MACzB,QAAQ,EAAE,SAAS,MAAM;AAAA,IAC3B;AAGA,QAAI;AACF,YAAM,eAAe,MAAM,KAAK,aAAa,UAAU;AACvD,YAAM,aAAa,MAAM,KAAK,aAAa,QAAQ;AACnD,aAAO,SAAS;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,MAAM;AAAA,UACN,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF,SAAS,OAAgB;AACvB,aAAO,SAAS;AAAA,QACd,SAAS;AAAA,QACT,OAAQ,MAAgB;AAAA,MAC1B;AAAA,IACF;AAGA,QAAI;AACF,YAAM,eAAe,MAAM,KAAK,aAAa,UAAU;AACvD,YAAM,aAAa,MAAM,KAAK,aAAa,QAAQ;AACnD,aAAO,SAAS;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,MAAM;AAAA,UACN,MAAM;AAAA,QACR;AAA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M,IAAI,aAAa,OAAO,MAAM,EAAE,CAAC;AACnD,MAAI,OAAO,kBAAkB;AAC3B,YAAQ,IAAI,MAAM,KAAK,cAAc,OAAO,OAAO,EAAE,CAAC;AACtD,QAAI,OAAO,eAAe,GAAG;AAC3B,cAAQ,IAAI,MAAM,OAAO,oBAAoB,OAAO,YAAY,EAAE,CAAC;AAAA,IACrE;AAAA,EACF;AAEA,MAAI,OAAO,OAAO,SAAS,GAAG;AAC5B,YAAQ,IAAI,MAAM,IAAI,WAAW,CAAC;AAClC,WAAO,OAAO,QAAQ,CAAC,UAAU,QAAQ,IAAI,MAAM,IAAI,OAAO,KAAK,EAAE,CAAC,CAAC;AAAA,EACzE;AAEA,MAAI,OAAO,WAAW,GAAG;AACvB,YAAQ;AAAA,MACN,MAAM;AAAA,QACJ;AAAA,uBAA0B,OAAO,QAAQ;AAAA,MAC3C;AAAA,IACF;AACA,QAAI,OAAO,oBAAoB,OAAO,UAAU,GAAG;AACjD,cAAQ;AAAA,QACN,MAAM,KAAK,MAAM,OAAO,OAAO,uCAAuC;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,11 +7,15 @@ import { URL } from "url";
|
|
|
7
7
|
import { logger } from "../../core/monitoring/logger.js";
|
|
8
8
|
import { LinearAuthManager } from "./auth.js";
|
|
9
9
|
import chalk from "chalk";
|
|
10
|
+
import { IntegrationError, ErrorCode } from "../../core/errors/index.js";
|
|
10
11
|
function getEnv(key, defaultValue) {
|
|
11
12
|
const value = process.env[key];
|
|
12
13
|
if (value === void 0) {
|
|
13
14
|
if (defaultValue !== void 0) return defaultValue;
|
|
14
|
-
throw new
|
|
15
|
+
throw new IntegrationError(
|
|
16
|
+
`Environment variable ${key} is required`,
|
|
17
|
+
ErrorCode.LINEAR_AUTH_FAILED
|
|
18
|
+
);
|
|
15
19
|
}
|
|
16
20
|
return value;
|
|
17
21
|
}
|
|
@@ -49,10 +53,12 @@ class LinearOAuthServer {
|
|
|
49
53
|
const { code, state, error, error_description } = req.query;
|
|
50
54
|
if (error) {
|
|
51
55
|
logger.error(`OAuth error: ${error} - ${error_description}`);
|
|
52
|
-
res.send(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
res.send(
|
|
57
|
+
this.generateErrorPage(
|
|
58
|
+
"Authorization Failed",
|
|
59
|
+
`${error}: ${error_description || "An error occurred during authorization"}`
|
|
60
|
+
)
|
|
61
|
+
);
|
|
56
62
|
if (state && this.authCompleteCallbacks.has(state)) {
|
|
57
63
|
this.authCompleteCallbacks.get(state)(false);
|
|
58
64
|
this.authCompleteCallbacks.delete(state);
|
|
@@ -61,20 +67,28 @@ class LinearOAuthServer {
|
|
|
61
67
|
return;
|
|
62
68
|
}
|
|
63
69
|
if (!code) {
|
|
64
|
-
res.send(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
res.send(
|
|
71
|
+
this.generateErrorPage(
|
|
72
|
+
"Missing Authorization Code",
|
|
73
|
+
"No authorization code was provided in the callback"
|
|
74
|
+
)
|
|
75
|
+
);
|
|
68
76
|
this.scheduleShutdown();
|
|
69
77
|
return;
|
|
70
78
|
}
|
|
71
79
|
try {
|
|
72
80
|
const codeVerifier = state ? this.pendingCodeVerifiers.get(state) : process.env["_LINEAR_CODE_VERIFIER"];
|
|
73
81
|
if (!codeVerifier) {
|
|
74
|
-
throw new
|
|
82
|
+
throw new IntegrationError(
|
|
83
|
+
"Code verifier not found. Please restart the authorization process.",
|
|
84
|
+
ErrorCode.LINEAR_AUTH_FAILED
|
|
85
|
+
);
|
|
75
86
|
}
|
|
76
87
|
logger.info("Exchanging authorization code for tokens...");
|
|
77
|
-
await this.authManager.exchangeCodeForToken(
|
|
88
|
+
await this.authManager.exchangeCodeForToken(
|
|
89
|
+
code,
|
|
90
|
+
codeVerifier
|
|
91
|
+
);
|
|
78
92
|
if (state) {
|
|
79
93
|
this.pendingCodeVerifiers.delete(state);
|
|
80
94
|
}
|
|
@@ -84,7 +98,10 @@ class LinearOAuthServer {
|
|
|
84
98
|
res.send(this.generateSuccessPage());
|
|
85
99
|
logger.info("Linear OAuth authentication completed successfully!");
|
|
86
100
|
} else {
|
|
87
|
-
throw new
|
|
101
|
+
throw new IntegrationError(
|
|
102
|
+
"Failed to verify Linear connection",
|
|
103
|
+
ErrorCode.LINEAR_AUTH_FAILED
|
|
104
|
+
);
|
|
88
105
|
}
|
|
89
106
|
if (state && this.authCompleteCallbacks.has(state)) {
|
|
90
107
|
this.authCompleteCallbacks.get(state)(true);
|
|
@@ -93,10 +110,12 @@ class LinearOAuthServer {
|
|
|
93
110
|
this.scheduleShutdown();
|
|
94
111
|
} catch (error2) {
|
|
95
112
|
logger.error("Failed to complete OAuth flow:", error2);
|
|
96
|
-
res.send(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
res.send(
|
|
114
|
+
this.generateErrorPage(
|
|
115
|
+
"Authentication Failed",
|
|
116
|
+
error2.message
|
|
117
|
+
)
|
|
118
|
+
);
|
|
100
119
|
if (state && this.authCompleteCallbacks.has(state)) {
|
|
101
120
|
this.authCompleteCallbacks.get(state)(false);
|
|
102
121
|
this.authCompleteCallbacks.delete(state);
|
|
@@ -108,10 +127,12 @@ class LinearOAuthServer {
|
|
|
108
127
|
try {
|
|
109
128
|
const config = this.authManager.loadConfig();
|
|
110
129
|
if (!config) {
|
|
111
|
-
res.status(400).send(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
130
|
+
res.status(400).send(
|
|
131
|
+
this.generateErrorPage(
|
|
132
|
+
"Configuration Missing",
|
|
133
|
+
"Linear OAuth configuration not found. Please configure your client ID and secret."
|
|
134
|
+
)
|
|
135
|
+
);
|
|
115
136
|
return;
|
|
116
137
|
}
|
|
117
138
|
const state = this.generateState();
|
|
@@ -120,10 +141,12 @@ class LinearOAuthServer {
|
|
|
120
141
|
res.redirect(url);
|
|
121
142
|
} catch (error) {
|
|
122
143
|
logger.error("Failed to start OAuth flow:", error);
|
|
123
|
-
res.status(500).send(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
144
|
+
res.status(500).send(
|
|
145
|
+
this.generateErrorPage(
|
|
146
|
+
"OAuth Start Failed",
|
|
147
|
+
error.message
|
|
148
|
+
)
|
|
149
|
+
);
|
|
127
150
|
}
|
|
128
151
|
});
|
|
129
152
|
this.app.use((req, res) => {
|
|
@@ -277,7 +300,7 @@ class LinearOAuthServer {
|
|
|
277
300
|
const response = await fetch("https://api.linear.app/graphql", {
|
|
278
301
|
method: "POST",
|
|
279
302
|
headers: {
|
|
280
|
-
|
|
303
|
+
Authorization: `Bearer ${token}`,
|
|
281
304
|
"Content-Type": "application/json"
|
|
282
305
|
},
|
|
283
306
|
body: JSON.stringify({
|
|
@@ -287,7 +310,9 @@ class LinearOAuthServer {
|
|
|
287
310
|
if (response.ok) {
|
|
288
311
|
const result = await response.json();
|
|
289
312
|
if (result.data?.viewer) {
|
|
290
|
-
logger.info(
|
|
313
|
+
logger.info(
|
|
314
|
+
`Connected to Linear as: ${result.data.viewer.name} (${result.data.viewer.email})`
|
|
315
|
+
);
|
|
291
316
|
return true;
|
|
292
317
|
}
|
|
293
318
|
}
|
|
@@ -315,16 +340,26 @@ class LinearOAuthServer {
|
|
|
315
340
|
this.config.port,
|
|
316
341
|
this.config.host,
|
|
317
342
|
() => {
|
|
318
|
-
console.log(
|
|
343
|
+
console.log(
|
|
344
|
+
chalk.green("\u2713") + chalk.bold(" Linear OAuth Server Started")
|
|
345
|
+
);
|
|
319
346
|
console.log(chalk.cyan(" Authorization URL: ") + setupUrl);
|
|
320
|
-
console.log(
|
|
347
|
+
console.log(
|
|
348
|
+
chalk.cyan(" Callback URL: ") + `http://${this.config.host}:${this.config.port}${this.config.redirectPath}`
|
|
349
|
+
);
|
|
321
350
|
console.log("");
|
|
322
351
|
console.log(chalk.yellow(" \u26A0 Configuration Required:"));
|
|
323
|
-
console.log(
|
|
324
|
-
|
|
352
|
+
console.log(
|
|
353
|
+
" 1. Create a Linear OAuth app at: https://linear.app/settings/api"
|
|
354
|
+
);
|
|
355
|
+
console.log(
|
|
356
|
+
` 2. Set redirect URI to: http://${this.config.host}:${this.config.port}${this.config.redirectPath}`
|
|
357
|
+
);
|
|
325
358
|
console.log(" 3. Set environment variables:");
|
|
326
359
|
console.log(' export LINEAR_CLIENT_ID="your_client_id"');
|
|
327
|
-
console.log(
|
|
360
|
+
console.log(
|
|
361
|
+
' export LINEAR_CLIENT_SECRET="your_client_secret"'
|
|
362
|
+
);
|
|
328
363
|
console.log(" 4. Restart the auth process");
|
|
329
364
|
resolve({ url: setupUrl });
|
|
330
365
|
}
|
|
@@ -338,17 +373,25 @@ class LinearOAuthServer {
|
|
|
338
373
|
this.config.port,
|
|
339
374
|
this.config.host,
|
|
340
375
|
() => {
|
|
341
|
-
console.log(
|
|
376
|
+
console.log(
|
|
377
|
+
chalk.green("\u2713") + chalk.bold(" Linear OAuth Server Started")
|
|
378
|
+
);
|
|
342
379
|
console.log(chalk.cyan(" Open this URL in your browser:"));
|
|
343
380
|
console.log(" " + chalk.underline(url));
|
|
344
381
|
console.log("");
|
|
345
|
-
console.log(
|
|
382
|
+
console.log(
|
|
383
|
+
chalk.gray(
|
|
384
|
+
" The server will automatically shut down after authorization completes."
|
|
385
|
+
)
|
|
386
|
+
);
|
|
346
387
|
resolve({ url, codeVerifier });
|
|
347
388
|
}
|
|
348
389
|
);
|
|
349
390
|
this.authCompleteCallbacks.set(state, (success) => {
|
|
350
391
|
if (success) {
|
|
351
|
-
console.log(
|
|
392
|
+
console.log(
|
|
393
|
+
chalk.green("\n\u2713 Linear authorization completed successfully!")
|
|
394
|
+
);
|
|
352
395
|
} else {
|
|
353
396
|
console.log(chalk.red("\n\u2717 Linear authorization failed"));
|
|
354
397
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/integrations/linear/oauth-server.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * OAuth Callback Server for Linear Integration\n * Handles the OAuth callback redirect and completes the authentication flow\n */\n\nimport express from 'express';\nimport http from 'http';\nimport { URL } from 'url';\nimport { logger } from '../../core/monitoring/logger.js';\nimport { LinearAuthManager } from './auth.js';\nimport chalk from 'chalk';\n// Type-safe environment variable access\nfunction getEnv(key: string, defaultValue?: string): string {\n const value = process.env[key];\n if (value === undefined) {\n if (defaultValue !== undefined) return defaultValue;\n throw new Error(`Environment variable ${key} is required`);\n }\n return value;\n}\n\nfunction getOptionalEnv(key: string): string | undefined {\n return process.env[key];\n}\n\n\nexport interface OAuthServerConfig {\n port?: number;\n host?: string;\n redirectPath?: string;\n autoShutdown?: boolean;\n shutdownDelay?: number;\n}\n\nexport class LinearOAuthServer {\n private app: express.Application;\n private server: http.Server | null = null;\n private authManager: LinearAuthManager;\n private config: OAuthServerConfig;\n private pendingCodeVerifiers: Map<string, string> = new Map();\n private authCompleteCallbacks: Map<string, (success: boolean) => void> = new Map();\n\n constructor(projectRoot: string, config?: OAuthServerConfig) {\n this.app = express();\n this.authManager = new LinearAuthManager(projectRoot);\n \n this.config = {\n port: config?.port || 3456,\n host: config?.host || 'localhost',\n redirectPath: config?.redirectPath || '/auth/linear/callback',\n autoShutdown: config?.autoShutdown !== false,\n shutdownDelay: config?.shutdownDelay || 5000,\n };\n\n this.setupRoutes();\n }\n\n private setupRoutes(): void {\n // Health check endpoint\n this.app.get('/health', (req, res) => {\n res.json({\n status: 'healthy',\n service: 'linear-oauth',\n timestamp: new Date().toISOString(),\n });\n });\n\n // OAuth callback endpoint\n this.app.get(this.config.redirectPath!, async (req, res) => {\n const { code, state, error, error_description } = req.query;\n\n // Handle OAuth errors\n if (error) {\n logger.error(`OAuth error: ${error} - ${error_description}`);\n res.send(this.generateErrorPage(\n 'Authorization Failed',\n `${error}: ${error_description || 'An error occurred during authorization'}`\n ));\n \n if (state && this.authCompleteCallbacks.has(state as string)) {\n this.authCompleteCallbacks.get(state as string)!(false);\n this.authCompleteCallbacks.delete(state as string);\n }\n \n this.scheduleShutdown();\n return;\n }\n\n // Validate required parameters\n if (!code) {\n res.send(this.generateErrorPage(\n 'Missing Authorization Code',\n 'No authorization code was provided in the callback'\n ));\n this.scheduleShutdown();\n return;\n }\n\n try {\n // Get the code verifier for this session\n const codeVerifier = state \n ? this.pendingCodeVerifiers.get(state as string)\n : process.env['_LINEAR_CODE_VERIFIER'];\n\n if (!codeVerifier) {\n throw new Error('Code verifier not found. Please restart the authorization process.');\n }\n\n // Exchange code for tokens\n logger.info('Exchanging authorization code for tokens...');\n await this.authManager.exchangeCodeForToken(code as string, codeVerifier);\n\n // Clean up\n if (state) {\n this.pendingCodeVerifiers.delete(state as string);\n }\n delete process.env['_LINEAR_CODE_VERIFIER'];\n\n // Test the connection\n const testSuccess = await this.testConnection();\n \n if (testSuccess) {\n res.send(this.generateSuccessPage());\n logger.info('Linear OAuth authentication completed successfully!');\n } else {\n throw new Error('Failed to verify Linear connection');\n }\n\n // Notify callback if registered\n if (state && this.authCompleteCallbacks.has(state as string)) {\n this.authCompleteCallbacks.get(state as string)!(true);\n this.authCompleteCallbacks.delete(state as string);\n }\n\n // Schedule server shutdown if auto-shutdown is enabled\n this.scheduleShutdown();\n } catch (error: unknown) {\n logger.error('Failed to complete OAuth flow:', error as Error);\n res.send(this.generateErrorPage(\n 'Authentication Failed',\n (error as Error).message\n ));\n \n if (state && this.authCompleteCallbacks.has(state as string)) {\n this.authCompleteCallbacks.get(state as string)!(false);\n this.authCompleteCallbacks.delete(state as string);\n }\n \n this.scheduleShutdown();\n }\n });\n\n // Start OAuth flow endpoint\n this.app.get('/auth/linear/start', (req, res) => {\n try {\n const config = this.authManager.loadConfig();\n if (!config) {\n res.status(400).send(this.generateErrorPage(\n 'Configuration Missing',\n 'Linear OAuth configuration not found. Please configure your client ID and secret.'\n ));\n return;\n }\n\n // Generate state for CSRF protection\n const state = this.generateState();\n const { url, codeVerifier } = this.authManager.generateAuthUrl(state);\n \n // Store code verifier for this session\n this.pendingCodeVerifiers.set(state, codeVerifier);\n\n // Redirect to Linear OAuth page\n res.redirect(url);\n } catch (error: unknown) {\n logger.error('Failed to start OAuth flow:', error as Error);\n res.status(500).send(this.generateErrorPage(\n 'OAuth Start Failed',\n (error as Error).message\n ));\n }\n });\n\n // 404 handler\n this.app.use((req, res) => {\n res.status(404).json({ error: 'Not found' });\n });\n }\n\n private generateState(): string {\n return Math.random().toString(36).substring(2, 15) + \n Math.random().toString(36).substring(2, 15);\n }\n\n private generateSuccessPage(): string {\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <title>Linear Authorization Successful</title>\n <style>\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100vh;\n margin: 0;\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n }\n .container {\n background: white;\n padding: 3rem;\n border-radius: 12px;\n box-shadow: 0 20px 60px rgba(0,0,0,0.3);\n text-align: center;\n max-width: 400px;\n }\n h1 {\n color: #2d3748;\n margin-bottom: 1rem;\n }\n .success-icon {\n font-size: 4rem;\n margin-bottom: 1rem;\n }\n p {\n color: #4a5568;\n line-height: 1.6;\n margin: 1rem 0;\n }\n .close-note {\n color: #718096;\n font-size: 0.875rem;\n margin-top: 2rem;\n }\n code {\n background: #f7fafc;\n padding: 0.25rem 0.5rem;\n border-radius: 4px;\n font-family: 'Courier New', monospace;\n }\n </style>\n </head>\n <body>\n <div class=\"container\">\n <div class=\"success-icon\">\u2705</div>\n <h1>Authorization Successful!</h1>\n <p>Your Linear account has been successfully connected to StackMemory.</p>\n <p>You can now use Linear integration features:</p>\n <p><code>stackmemory linear sync</code></p>\n <p><code>stackmemory linear create</code></p>\n <p class=\"close-note\">You can safely close this window and return to your terminal.</p>\n </div>\n </body>\n </html>\n `;\n }\n\n private generateErrorPage(title: string, message: string): string {\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <title>${title}</title>\n <style>\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100vh;\n margin: 0;\n background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);\n }\n .container {\n background: white;\n padding: 3rem;\n border-radius: 12px;\n box-shadow: 0 20px 60px rgba(0,0,0,0.3);\n text-align: center;\n max-width: 400px;\n }\n h1 {\n color: #e53e3e;\n margin-bottom: 1rem;\n }\n .error-icon {\n font-size: 4rem;\n margin-bottom: 1rem;\n }\n p {\n color: #4a5568;\n line-height: 1.6;\n margin: 1rem 0;\n }\n .error-message {\n background: #fff5f5;\n border: 1px solid #fed7d7;\n color: #742a2a;\n padding: 1rem;\n border-radius: 6px;\n margin-top: 1rem;\n font-size: 0.875rem;\n }\n .retry-note {\n color: #718096;\n font-size: 0.875rem;\n margin-top: 2rem;\n }\n code {\n background: #f7fafc;\n padding: 0.25rem 0.5rem;\n border-radius: 4px;\n font-family: 'Courier New', monospace;\n }\n </style>\n </head>\n <body>\n <div class=\"container\">\n <div class=\"error-icon\">\u274C</div>\n <h1>${title}</h1>\n <p>Unable to complete Linear authorization.</p>\n <div class=\"error-message\">${message}</div>\n <p class=\"retry-note\">\n Please try again with:<br>\n <code>stackmemory linear auth</code>\n </p>\n </div>\n </body>\n </html>\n `;\n }\n\n private async testConnection(): Promise<boolean> {\n try {\n const token = await this.authManager.getValidToken();\n \n const response = await fetch('https://api.linear.app/graphql', {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n query: 'query { viewer { id name email } }',\n }),\n });\n\n if (response.ok) {\n const result = await response.json() as {\n data?: { viewer?: { id: string; name: string; email: string } };\n };\n if (result.data?.viewer) {\n logger.info(`Connected to Linear as: ${result.data.viewer.name} (${result.data.viewer.email})`);\n return true;\n }\n }\n\n return false;\n } catch (error: unknown) {\n logger.error('Linear connection test failed:', error as Error);\n return false;\n }\n }\n\n private scheduleShutdown(): void {\n if (this.config.autoShutdown && this.server) {\n setTimeout(() => {\n logger.info('Auto-shutting down OAuth server...');\n this.stop();\n }, this.config.shutdownDelay);\n }\n }\n\n public async start(): Promise<{ url: string; codeVerifier?: string }> {\n return new Promise((resolve, reject) => {\n try {\n // Load config and generate auth URL\n const config = this.authManager.loadConfig();\n if (!config) {\n // If no config, provide setup instructions\n const setupUrl = `http://${this.config.host}:${this.config.port}/auth/linear/start`;\n \n this.server = this.app.listen(\n this.config.port!,\n this.config.host!,\n () => {\n console.log(chalk.green('\u2713') + chalk.bold(' Linear OAuth Server Started'));\n console.log(chalk.cyan(' Authorization URL: ') + setupUrl);\n console.log(chalk.cyan(' Callback URL: ') + \n `http://${this.config.host}:${this.config.port}${this.config.redirectPath}`);\n console.log('');\n console.log(chalk.yellow(' \u26A0 Configuration Required:'));\n console.log(' 1. Create a Linear OAuth app at: https://linear.app/settings/api');\n console.log(` 2. Set redirect URI to: http://${this.config.host}:${this.config.port}${this.config.redirectPath}`);\n console.log(' 3. Set environment variables:');\n console.log(' export LINEAR_CLIENT_ID=\"your_client_id\"');\n console.log(' export LINEAR_CLIENT_SECRET=\"your_client_secret\"');\n console.log(' 4. Restart the auth process');\n \n resolve({ url: setupUrl });\n }\n );\n return;\n }\n\n // Generate state and auth URL\n const state = this.generateState();\n const { url, codeVerifier } = this.authManager.generateAuthUrl(state);\n \n // Store code verifier\n this.pendingCodeVerifiers.set(state, codeVerifier);\n\n this.server = this.app.listen(\n this.config.port!,\n this.config.host!,\n () => {\n console.log(chalk.green('\u2713') + chalk.bold(' Linear OAuth Server Started'));\n console.log(chalk.cyan(' Open this URL in your browser:'));\n console.log(' ' + chalk.underline(url));\n console.log('');\n console.log(chalk.gray(' The server will automatically shut down after authorization completes.'));\n \n resolve({ url, codeVerifier });\n }\n );\n\n // Register auth complete callback\n this.authCompleteCallbacks.set(state, (success) => {\n if (success) {\n console.log(chalk.green('\\n\u2713 Linear authorization completed successfully!'));\n } else {\n console.log(chalk.red('\\n\u2717 Linear authorization failed'));\n }\n });\n\n } catch (error: unknown) {\n reject(error);\n }\n });\n }\n\n public async stop(): Promise<void> {\n return new Promise((resolve) => {\n if (this.server) {\n this.server.close(() => {\n logger.info('OAuth server stopped');\n this.server = null;\n resolve();\n });\n } else {\n resolve();\n }\n });\n }\n\n public async waitForAuth(state: string, timeout: number = 300000): Promise<boolean> {\n return new Promise((resolve) => {\n const timeoutId = setTimeout(() => {\n this.authCompleteCallbacks.delete(state);\n resolve(false);\n }, timeout);\n\n this.authCompleteCallbacks.set(state, (success) => {\n clearTimeout(timeoutId);\n resolve(success);\n });\n });\n }\n}\n\n// Standalone execution support\nif (process.argv[1] === new URL(import.meta.url).pathname) {\n const projectRoot = process.cwd();\n const server = new LinearOAuthServer(projectRoot, {\n autoShutdown: true,\n shutdownDelay: 5000,\n });\n\n server.start()\n .then(({ url }) => {\n if (url) {\n console.log(chalk.cyan('\\nWaiting for authorization...'));\n console.log(chalk.gray('Press Ctrl+C to cancel\\n'));\n }\n })\n .catch((error) => {\n console.error(chalk.red('Failed to start OAuth server:'), error);\n process.exit(1);\n });\n\n process.on('SIGINT', async () => {\n console.log(chalk.yellow('\\n\\nShutting down OAuth server...'));\n await server.stop();\n process.exit(0);\n });\n}"],
|
|
5
|
-
"mappings": ";;;;AAKA,OAAO,aAAa;AAEpB,SAAS,WAAW;AACpB,SAAS,cAAc;AACvB,SAAS,yBAAyB;AAClC,OAAO,WAAW;
|
|
4
|
+
"sourcesContent": ["/**\n * OAuth Callback Server for Linear Integration\n * Handles the OAuth callback redirect and completes the authentication flow\n */\n\nimport express from 'express';\nimport http from 'http';\nimport { URL } from 'url';\nimport { logger } from '../../core/monitoring/logger.js';\nimport { LinearAuthManager } from './auth.js';\nimport chalk from 'chalk';\nimport { IntegrationError, ErrorCode } from '../../core/errors/index.js';\n// Type-safe environment variable access\nfunction getEnv(key: string, defaultValue?: string): string {\n const value = process.env[key];\n if (value === undefined) {\n if (defaultValue !== undefined) return defaultValue;\n throw new IntegrationError(\n `Environment variable ${key} is required`,\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n return value;\n}\n\nfunction getOptionalEnv(key: string): string | undefined {\n return process.env[key];\n}\n\nexport interface OAuthServerConfig {\n port?: number;\n host?: string;\n redirectPath?: string;\n autoShutdown?: boolean;\n shutdownDelay?: number;\n}\n\nexport class LinearOAuthServer {\n private app: express.Application;\n private server: http.Server | null = null;\n private authManager: LinearAuthManager;\n private config: OAuthServerConfig;\n private pendingCodeVerifiers: Map<string, string> = new Map();\n private authCompleteCallbacks: Map<string, (success: boolean) => void> =\n new Map();\n\n constructor(projectRoot: string, config?: OAuthServerConfig) {\n this.app = express();\n this.authManager = new LinearAuthManager(projectRoot);\n\n this.config = {\n port: config?.port || 3456,\n host: config?.host || 'localhost',\n redirectPath: config?.redirectPath || '/auth/linear/callback',\n autoShutdown: config?.autoShutdown !== false,\n shutdownDelay: config?.shutdownDelay || 5000,\n };\n\n this.setupRoutes();\n }\n\n private setupRoutes(): void {\n // Health check endpoint\n this.app.get('/health', (req, res) => {\n res.json({\n status: 'healthy',\n service: 'linear-oauth',\n timestamp: new Date().toISOString(),\n });\n });\n\n // OAuth callback endpoint\n this.app.get(this.config.redirectPath!, async (req, res) => {\n const { code, state, error, error_description } = req.query;\n\n // Handle OAuth errors\n if (error) {\n logger.error(`OAuth error: ${error} - ${error_description}`);\n res.send(\n this.generateErrorPage(\n 'Authorization Failed',\n `${error}: ${error_description || 'An error occurred during authorization'}`\n )\n );\n\n if (state && this.authCompleteCallbacks.has(state as string)) {\n this.authCompleteCallbacks.get(state as string)!(false);\n this.authCompleteCallbacks.delete(state as string);\n }\n\n this.scheduleShutdown();\n return;\n }\n\n // Validate required parameters\n if (!code) {\n res.send(\n this.generateErrorPage(\n 'Missing Authorization Code',\n 'No authorization code was provided in the callback'\n )\n );\n this.scheduleShutdown();\n return;\n }\n\n try {\n // Get the code verifier for this session\n const codeVerifier = state\n ? this.pendingCodeVerifiers.get(state as string)\n : process.env['_LINEAR_CODE_VERIFIER'];\n\n if (!codeVerifier) {\n throw new IntegrationError(\n 'Code verifier not found. Please restart the authorization process.',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n // Exchange code for tokens\n logger.info('Exchanging authorization code for tokens...');\n await this.authManager.exchangeCodeForToken(\n code as string,\n codeVerifier\n );\n\n // Clean up\n if (state) {\n this.pendingCodeVerifiers.delete(state as string);\n }\n delete process.env['_LINEAR_CODE_VERIFIER'];\n\n // Test the connection\n const testSuccess = await this.testConnection();\n\n if (testSuccess) {\n res.send(this.generateSuccessPage());\n logger.info('Linear OAuth authentication completed successfully!');\n } else {\n throw new IntegrationError(\n 'Failed to verify Linear connection',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n // Notify callback if registered\n if (state && this.authCompleteCallbacks.has(state as string)) {\n this.authCompleteCallbacks.get(state as string)!(true);\n this.authCompleteCallbacks.delete(state as string);\n }\n\n // Schedule server shutdown if auto-shutdown is enabled\n this.scheduleShutdown();\n } catch (error: unknown) {\n logger.error('Failed to complete OAuth flow:', error as Error);\n res.send(\n this.generateErrorPage(\n 'Authentication Failed',\n (error as Error).message\n )\n );\n\n if (state && this.authCompleteCallbacks.has(state as string)) {\n this.authCompleteCallbacks.get(state as string)!(false);\n this.authCompleteCallbacks.delete(state as string);\n }\n\n this.scheduleShutdown();\n }\n });\n\n // Start OAuth flow endpoint\n this.app.get('/auth/linear/start', (req, res) => {\n try {\n const config = this.authManager.loadConfig();\n if (!config) {\n res\n .status(400)\n .send(\n this.generateErrorPage(\n 'Configuration Missing',\n 'Linear OAuth configuration not found. Please configure your client ID and secret.'\n )\n );\n return;\n }\n\n // Generate state for CSRF protection\n const state = this.generateState();\n const { url, codeVerifier } = this.authManager.generateAuthUrl(state);\n\n // Store code verifier for this session\n this.pendingCodeVerifiers.set(state, codeVerifier);\n\n // Redirect to Linear OAuth page\n res.redirect(url);\n } catch (error: unknown) {\n logger.error('Failed to start OAuth flow:', error as Error);\n res\n .status(500)\n .send(\n this.generateErrorPage(\n 'OAuth Start Failed',\n (error as Error).message\n )\n );\n }\n });\n\n // 404 handler\n this.app.use((req, res) => {\n res.status(404).json({ error: 'Not found' });\n });\n }\n\n private generateState(): string {\n return (\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15)\n );\n }\n\n private generateSuccessPage(): string {\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <title>Linear Authorization Successful</title>\n <style>\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100vh;\n margin: 0;\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n }\n .container {\n background: white;\n padding: 3rem;\n border-radius: 12px;\n box-shadow: 0 20px 60px rgba(0,0,0,0.3);\n text-align: center;\n max-width: 400px;\n }\n h1 {\n color: #2d3748;\n margin-bottom: 1rem;\n }\n .success-icon {\n font-size: 4rem;\n margin-bottom: 1rem;\n }\n p {\n color: #4a5568;\n line-height: 1.6;\n margin: 1rem 0;\n }\n .close-note {\n color: #718096;\n font-size: 0.875rem;\n margin-top: 2rem;\n }\n code {\n background: #f7fafc;\n padding: 0.25rem 0.5rem;\n border-radius: 4px;\n font-family: 'Courier New', monospace;\n }\n </style>\n </head>\n <body>\n <div class=\"container\">\n <div class=\"success-icon\">\u2705</div>\n <h1>Authorization Successful!</h1>\n <p>Your Linear account has been successfully connected to StackMemory.</p>\n <p>You can now use Linear integration features:</p>\n <p><code>stackmemory linear sync</code></p>\n <p><code>stackmemory linear create</code></p>\n <p class=\"close-note\">You can safely close this window and return to your terminal.</p>\n </div>\n </body>\n </html>\n `;\n }\n\n private generateErrorPage(title: string, message: string): string {\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <title>${title}</title>\n <style>\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100vh;\n margin: 0;\n background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);\n }\n .container {\n background: white;\n padding: 3rem;\n border-radius: 12px;\n box-shadow: 0 20px 60px rgba(0,0,0,0.3);\n text-align: center;\n max-width: 400px;\n }\n h1 {\n color: #e53e3e;\n margin-bottom: 1rem;\n }\n .error-icon {\n font-size: 4rem;\n margin-bottom: 1rem;\n }\n p {\n color: #4a5568;\n line-height: 1.6;\n margin: 1rem 0;\n }\n .error-message {\n background: #fff5f5;\n border: 1px solid #fed7d7;\n color: #742a2a;\n padding: 1rem;\n border-radius: 6px;\n margin-top: 1rem;\n font-size: 0.875rem;\n }\n .retry-note {\n color: #718096;\n font-size: 0.875rem;\n margin-top: 2rem;\n }\n code {\n background: #f7fafc;\n padding: 0.25rem 0.5rem;\n border-radius: 4px;\n font-family: 'Courier New', monospace;\n }\n </style>\n </head>\n <body>\n <div class=\"container\">\n <div class=\"error-icon\">\u274C</div>\n <h1>${title}</h1>\n <p>Unable to complete Linear authorization.</p>\n <div class=\"error-message\">${message}</div>\n <p class=\"retry-note\">\n Please try again with:<br>\n <code>stackmemory linear auth</code>\n </p>\n </div>\n </body>\n </html>\n `;\n }\n\n private async testConnection(): Promise<boolean> {\n try {\n const token = await this.authManager.getValidToken();\n\n const response = await fetch('https://api.linear.app/graphql', {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n query: 'query { viewer { id name email } }',\n }),\n });\n\n if (response.ok) {\n const result = (await response.json()) as {\n data?: { viewer?: { id: string; name: string; email: string } };\n };\n if (result.data?.viewer) {\n logger.info(\n `Connected to Linear as: ${result.data.viewer.name} (${result.data.viewer.email})`\n );\n return true;\n }\n }\n\n return false;\n } catch (error: unknown) {\n logger.error('Linear connection test failed:', error as Error);\n return false;\n }\n }\n\n private scheduleShutdown(): void {\n if (this.config.autoShutdown && this.server) {\n setTimeout(() => {\n logger.info('Auto-shutting down OAuth server...');\n this.stop();\n }, this.config.shutdownDelay);\n }\n }\n\n public async start(): Promise<{ url: string; codeVerifier?: string }> {\n return new Promise((resolve, reject) => {\n try {\n // Load config and generate auth URL\n const config = this.authManager.loadConfig();\n if (!config) {\n // If no config, provide setup instructions\n const setupUrl = `http://${this.config.host}:${this.config.port}/auth/linear/start`;\n\n this.server = this.app.listen(\n this.config.port!,\n this.config.host!,\n () => {\n console.log(\n chalk.green('\u2713') + chalk.bold(' Linear OAuth Server Started')\n );\n console.log(chalk.cyan(' Authorization URL: ') + setupUrl);\n console.log(\n chalk.cyan(' Callback URL: ') +\n `http://${this.config.host}:${this.config.port}${this.config.redirectPath}`\n );\n console.log('');\n console.log(chalk.yellow(' \u26A0 Configuration Required:'));\n console.log(\n ' 1. Create a Linear OAuth app at: https://linear.app/settings/api'\n );\n console.log(\n ` 2. Set redirect URI to: http://${this.config.host}:${this.config.port}${this.config.redirectPath}`\n );\n console.log(' 3. Set environment variables:');\n console.log(' export LINEAR_CLIENT_ID=\"your_client_id\"');\n console.log(\n ' export LINEAR_CLIENT_SECRET=\"your_client_secret\"'\n );\n console.log(' 4. Restart the auth process');\n\n resolve({ url: setupUrl });\n }\n );\n return;\n }\n\n // Generate state and auth URL\n const state = this.generateState();\n const { url, codeVerifier } = this.authManager.generateAuthUrl(state);\n\n // Store code verifier\n this.pendingCodeVerifiers.set(state, codeVerifier);\n\n this.server = this.app.listen(\n this.config.port!,\n this.config.host!,\n () => {\n console.log(\n chalk.green('\u2713') + chalk.bold(' Linear OAuth Server Started')\n );\n console.log(chalk.cyan(' Open this URL in your browser:'));\n console.log(' ' + chalk.underline(url));\n console.log('');\n console.log(\n chalk.gray(\n ' The server will automatically shut down after authorization completes.'\n )\n );\n\n resolve({ url, codeVerifier });\n }\n );\n\n // Register auth complete callback\n this.authCompleteCallbacks.set(state, (success) => {\n if (success) {\n console.log(\n chalk.green('\\n\u2713 Linear authorization completed successfully!')\n );\n } else {\n console.log(chalk.red('\\n\u2717 Linear authorization failed'));\n }\n });\n } catch (error: unknown) {\n reject(error);\n }\n });\n }\n\n public async stop(): Promise<void> {\n return new Promise((resolve) => {\n if (this.server) {\n this.server.close(() => {\n logger.info('OAuth server stopped');\n this.server = null;\n resolve();\n });\n } else {\n resolve();\n }\n });\n }\n\n public async waitForAuth(\n state: string,\n timeout: number = 300000\n ): Promise<boolean> {\n return new Promise((resolve) => {\n const timeoutId = setTimeout(() => {\n this.authCompleteCallbacks.delete(state);\n resolve(false);\n }, timeout);\n\n this.authCompleteCallbacks.set(state, (success) => {\n clearTimeout(timeoutId);\n resolve(success);\n });\n });\n }\n}\n\n// Standalone execution support\nif (process.argv[1] === new URL(import.meta.url).pathname) {\n const projectRoot = process.cwd();\n const server = new LinearOAuthServer(projectRoot, {\n autoShutdown: true,\n shutdownDelay: 5000,\n });\n\n server\n .start()\n .then(({ url }) => {\n if (url) {\n console.log(chalk.cyan('\\nWaiting for authorization...'));\n console.log(chalk.gray('Press Ctrl+C to cancel\\n'));\n }\n })\n .catch((error) => {\n console.error(chalk.red('Failed to start OAuth server:'), error);\n process.exit(1);\n });\n\n process.on('SIGINT', async () => {\n console.log(chalk.yellow('\\n\\nShutting down OAuth server...'));\n await server.stop();\n process.exit(0);\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAKA,OAAO,aAAa;AAEpB,SAAS,WAAW;AACpB,SAAS,cAAc;AACvB,SAAS,yBAAyB;AAClC,OAAO,WAAW;AAClB,SAAS,kBAAkB,iBAAiB;AAE5C,SAAS,OAAO,KAAa,cAA+B;AAC1D,QAAM,QAAQ,QAAQ,IAAI,GAAG;AAC7B,MAAI,UAAU,QAAW;AACvB,QAAI,iBAAiB,OAAW,QAAO;AACvC,UAAM,IAAI;AAAA,MACR,wBAAwB,GAAG;AAAA,MAC3B,UAAU;AAAA,IACZ;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,eAAe,KAAiC;AACvD,SAAO,QAAQ,IAAI,GAAG;AACxB;AAUO,MAAM,kB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AAA,EACH;AACF;AAGA,IAAI,QAAQ,KAAK,CAAC,MAAM,IAAI,IAAI,YAAY,GAAG,EAAE,UAAU;AACzD,QAAM,cAAc,QAAQ,IAAI;AAChC,QAAM,SAAS,IAAI,kBAAkB,aAAa;AAAA,IAChD,cAAc;AAAA,IACd,eAAe;AAAA,EACjB,CAAC;AAED,SACG,MAAM,EACN,KAAK,CAAC,EAAE,IAAI,MAAM;AACjB,QAAI,KAAK;AACP,cAAQ,IAAI,MAAM,KAAK,gCAAgC,CAAC;AACxD,cAAQ,IAAI,MAAM,KAAK,0BAA0B,CAAC;AAAA,IACpD;AAAA,EACF,CAAC,EACA,MAAM,CAAC,UAAU;AAChB,YAAQ,MAAM,MAAM,IAAI,+BAA+B,GAAG,KAAK;AAC/D,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AAEH,UAAQ,GAAG,UAAU,YAAY;AAC/B,YAAQ,IAAI,MAAM,OAAO,mCAAmC,CAAC;AAC7D,UAAM,OAAO,KAAK;AAClB,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACH;",
|
|
6
6
|
"names": ["error"]
|
|
7
7
|
}
|
|
@@ -3,6 +3,7 @@ import { dirname as __pathDirname } from 'path';
|
|
|
3
3
|
const __filename = __fileURLToPath(import.meta.url);
|
|
4
4
|
const __dirname = __pathDirname(__filename);
|
|
5
5
|
import { logger } from "../../core/monitoring/logger.js";
|
|
6
|
+
import { IntegrationError, ErrorCode } from "../../core/errors/index.js";
|
|
6
7
|
class LinearRestClient {
|
|
7
8
|
apiKey;
|
|
8
9
|
baseUrl = "https://api.linear.app/graphql";
|
|
@@ -60,7 +61,10 @@ class LinearRestClient {
|
|
|
60
61
|
}
|
|
61
62
|
`;
|
|
62
63
|
const variables = cursor ? { after: cursor } : {};
|
|
63
|
-
const response = await this.makeRequest(
|
|
64
|
+
const response = await this.makeRequest(
|
|
65
|
+
query,
|
|
66
|
+
variables
|
|
67
|
+
);
|
|
64
68
|
const tasks = response.data.issues.nodes;
|
|
65
69
|
allTasks.push(...tasks);
|
|
66
70
|
tasks.forEach((task) => {
|
|
@@ -153,7 +157,10 @@ class LinearRestClient {
|
|
|
153
157
|
`;
|
|
154
158
|
const response = await this.makeRequest(query);
|
|
155
159
|
if (response.data.teams.nodes.length === 0) {
|
|
156
|
-
throw new
|
|
160
|
+
throw new IntegrationError(
|
|
161
|
+
"ENG team not found",
|
|
162
|
+
ErrorCode.LINEAR_API_ERROR
|
|
163
|
+
);
|
|
157
164
|
}
|
|
158
165
|
return response.data.teams.nodes[0];
|
|
159
166
|
}
|
|
@@ -192,7 +199,10 @@ class LinearRestClient {
|
|
|
192
199
|
const result = await response.json();
|
|
193
200
|
if (!response.ok || result.errors) {
|
|
194
201
|
const errorMsg = result.errors?.[0]?.message || `${response.status} ${response.statusText}`;
|
|
195
|
-
throw new
|
|
202
|
+
throw new IntegrationError(
|
|
203
|
+
`Linear API error: ${errorMsg}`,
|
|
204
|
+
ErrorCode.LINEAR_API_ERROR
|
|
205
|
+
);
|
|
196
206
|
}
|
|
197
207
|
return result;
|
|
198
208
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/integrations/linear/rest-client.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Linear REST Client for StackMemory\n * Provides memory-based task storage using REST API instead of GraphQL\n */\n\nimport { logger } from '../../core/monitoring/logger.js';\n\nexport interface LinearTask {\n id: string;\n identifier: string;\n title: string;\n description?: string;\n state: {\n name: string;\n type: string;\n };\n priority: number;\n assignee?: {\n id: string;\n name: string;\n };\n estimate?: number;\n createdAt: string;\n updatedAt: string;\n url: string;\n}\n\nexport interface LinearTasksResponse {\n data: {\n issues: {\n nodes: LinearTask[];\n pageInfo: {\n hasNextPage: boolean;\n endCursor?: string;\n };\n };\n };\n}\n\nexport class LinearRestClient {\n private apiKey: string;\n private baseUrl = 'https://api.linear.app/graphql';\n private taskCache = new Map<string, LinearTask>();\n private lastSync = 0;\n private cacheTTL = 5 * 60 * 1000; // 5 minutes\n\n constructor(apiKey: string) {\n this.apiKey = apiKey;\n }\n\n /**\n * Get all tasks and store in memory\n */\n async getAllTasks(forceRefresh = false): Promise<LinearTask[]> {\n const now = Date.now();\n
|
|
5
|
-
"mappings": ";;;;AAKA,SAAS,cAAc;
|
|
4
|
+
"sourcesContent": ["/**\n * Linear REST Client for StackMemory\n * Provides memory-based task storage using REST API instead of GraphQL\n */\n\nimport { logger } from '../../core/monitoring/logger.js';\nimport { IntegrationError, ErrorCode } from '../../core/errors/index.js';\n\nexport interface LinearTask {\n id: string;\n identifier: string;\n title: string;\n description?: string;\n state: {\n name: string;\n type: string;\n };\n priority: number;\n assignee?: {\n id: string;\n name: string;\n };\n estimate?: number;\n createdAt: string;\n updatedAt: string;\n url: string;\n}\n\nexport interface LinearTasksResponse {\n data: {\n issues: {\n nodes: LinearTask[];\n pageInfo: {\n hasNextPage: boolean;\n endCursor?: string;\n };\n };\n };\n}\n\nexport class LinearRestClient {\n private apiKey: string;\n private baseUrl = 'https://api.linear.app/graphql';\n private taskCache = new Map<string, LinearTask>();\n private lastSync = 0;\n private cacheTTL = 5 * 60 * 1000; // 5 minutes\n\n constructor(apiKey: string) {\n this.apiKey = apiKey;\n }\n\n /**\n * Get all tasks and store in memory\n */\n async getAllTasks(forceRefresh = false): Promise<LinearTask[]> {\n const now = Date.now();\n\n // Return cached data if fresh\n if (\n !forceRefresh &&\n now - this.lastSync < this.cacheTTL &&\n this.taskCache.size > 0\n ) {\n return Array.from(this.taskCache.values());\n }\n\n try {\n const allTasks: LinearTask[] = [];\n let hasNextPage = true;\n let cursor: string | undefined;\n\n while (hasNextPage) {\n const query = `\n query($after: String) {\n issues(\n filter: { team: { key: { eq: \"ENG\" } } }\n first: 100\n after: $after\n ) {\n nodes {\n id\n identifier\n title\n description\n state {\n name\n type\n }\n priority\n assignee {\n id\n name\n }\n estimate\n createdAt\n updatedAt\n url\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n `;\n\n const variables = cursor ? { after: cursor } : {};\n const response = await this.makeRequest<LinearTasksResponse>(\n query,\n variables\n );\n\n const tasks = response.data.issues.nodes;\n allTasks.push(...tasks);\n\n // Update cache\n tasks.forEach((task) => {\n this.taskCache.set(task.id, task);\n });\n\n hasNextPage = response.data.issues.pageInfo.hasNextPage;\n cursor = response.data.issues.pageInfo.endCursor;\n\n logger.info(`Fetched ${tasks.length} tasks, total: ${allTasks.length}`);\n }\n\n this.lastSync = now;\n logger.info(`Cached ${allTasks.length} Linear tasks in memory`);\n\n return allTasks;\n } catch (error: unknown) {\n logger.error('Failed to fetch Linear tasks:', error as Error);\n return Array.from(this.taskCache.values()); // Return cached data on error\n }\n }\n\n /**\n * Get tasks by status\n */\n async getTasksByStatus(status: string): Promise<LinearTask[]> {\n const tasks = await this.getAllTasks();\n return tasks.filter((task: any) => task.state.type === status);\n }\n\n /**\n * Get tasks assigned to current user\n */\n async getMyTasks(): Promise<LinearTask[]> {\n try {\n const viewer = await this.getViewer();\n const tasks = await this.getAllTasks();\n return tasks.filter((task: any) => task.assignee?.id === viewer.id);\n } catch (error: unknown) {\n logger.error('Failed to get assigned tasks:', error as Error);\n return [];\n }\n }\n\n /**\n * Get task count by status\n */\n async getTaskCounts(): Promise<Record<string, number>> {\n const tasks = await this.getAllTasks();\n const counts: Record<string, number> = {};\n\n tasks.forEach((task) => {\n const status = task.state.type;\n counts[status] = (counts[status] || 0) + 1;\n });\n\n return counts;\n }\n\n /**\n * Search tasks by title or description\n */\n async searchTasks(query: string): Promise<LinearTask[]> {\n const tasks = await this.getAllTasks();\n const searchTerm = query.toLowerCase();\n\n return tasks.filter(\n (task: any) =>\n task.title.toLowerCase().includes(searchTerm) ||\n task.description?.toLowerCase().includes(searchTerm) ||\n task.identifier.toLowerCase().includes(searchTerm)\n );\n }\n\n /**\n * Get current viewer info\n */\n async getViewer(): Promise<{ id: string; name: string; email: string }> {\n const query = `\n query {\n viewer {\n id\n name\n email\n }\n }\n `;\n\n const response = await this.makeRequest<{\n data: {\n viewer: { id: string; name: string; email: string };\n };\n }>(query);\n\n return response.data.viewer;\n }\n\n /**\n * Get team info\n */\n async getTeam(): Promise<{ id: string; name: string; key: string }> {\n const query = `\n query {\n teams(filter: { key: { eq: \"ENG\" } }, first: 1) {\n nodes {\n id\n name\n key\n }\n }\n }\n `;\n\n const response = await this.makeRequest<{\n data: {\n teams: {\n nodes: Array<{ id: string; name: string; key: string }>;\n };\n };\n }>(query);\n\n if (response.data.teams.nodes.length === 0) {\n throw new IntegrationError(\n 'ENG team not found',\n ErrorCode.LINEAR_API_ERROR\n );\n }\n\n return response.data.teams.nodes[0]!;\n }\n\n /**\n * Get cache stats\n */\n getCacheStats(): {\n size: number;\n lastSync: number;\n age: number;\n fresh: boolean;\n } {\n const now = Date.now();\n return {\n size: this.taskCache.size,\n lastSync: this.lastSync,\n age: now - this.lastSync,\n fresh: now - this.lastSync < this.cacheTTL,\n };\n }\n\n /**\n * Clear cache\n */\n clearCache(): void {\n this.taskCache.clear();\n this.lastSync = 0;\n logger.info('Linear task cache cleared');\n }\n\n /**\n * Make GraphQL request\n */\n async makeRequest<T>(\n query: string,\n variables: Record<string, unknown> = {}\n ): Promise<T> {\n const response = await fetch(this.baseUrl, {\n method: 'POST',\n headers: {\n Authorization: this.apiKey,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ query, variables }),\n });\n\n const result = (await response.json()) as {\n data?: unknown;\n errors?: Array<{ message: string }>;\n };\n\n if (!response.ok || result.errors) {\n const errorMsg =\n result.errors?.[0]?.message ||\n `${response.status} ${response.statusText}`;\n throw new IntegrationError(\n `Linear API error: ${errorMsg}`,\n ErrorCode.LINEAR_API_ERROR\n );\n }\n\n return result as T;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAKA,SAAS,cAAc;AACvB,SAAS,kBAAkB,iBAAiB;AAkCrC,MAAM,iBAAiB;AAAA,EACpB;AAAA,EACA,UAAU;AAAA,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AAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,17 +6,7 @@ import { LinearClient } from "./client.js";
|
|
|
6
6
|
import { ContextService } from "../../services/context-service.js";
|
|
7
7
|
import { ConfigService } from "../../services/config-service.js";
|
|
8
8
|
import { logger } from "../../core/monitoring/logger.js";
|
|
9
|
-
|
|
10
|
-
const value = process.env[key];
|
|
11
|
-
if (value === void 0) {
|
|
12
|
-
if (defaultValue !== void 0) return defaultValue;
|
|
13
|
-
throw new Error(`Environment variable ${key} is required`);
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
function getOptionalEnv(key) {
|
|
18
|
-
return process.env[key];
|
|
19
|
-
}
|
|
9
|
+
import { IntegrationError, ErrorCode } from "../../core/errors/index.js";
|
|
20
10
|
class LinearSyncService {
|
|
21
11
|
linearClient;
|
|
22
12
|
contextService;
|
|
@@ -27,7 +17,10 @@ class LinearSyncService {
|
|
|
27
17
|
this.contextService = new ContextService();
|
|
28
18
|
const apiKey = process.env["LINEAR_API_KEY"];
|
|
29
19
|
if (!apiKey) {
|
|
30
|
-
throw new
|
|
20
|
+
throw new IntegrationError(
|
|
21
|
+
"LINEAR_API_KEY environment variable not set",
|
|
22
|
+
ErrorCode.LINEAR_AUTH_FAILED
|
|
23
|
+
);
|
|
31
24
|
}
|
|
32
25
|
this.linearClient = new LinearClient({ apiKey });
|
|
33
26
|
}
|
|
@@ -43,7 +36,10 @@ class LinearSyncService {
|
|
|
43
36
|
const config = await this.configService.getConfig();
|
|
44
37
|
const teamId = config.integrations?.linear?.teamId;
|
|
45
38
|
if (!teamId) {
|
|
46
|
-
throw new
|
|
39
|
+
throw new IntegrationError(
|
|
40
|
+
"Linear team ID not configured",
|
|
41
|
+
ErrorCode.LINEAR_SYNC_FAILED
|
|
42
|
+
);
|
|
47
43
|
}
|
|
48
44
|
const issues = await this.linearClient.getIssues({ teamId });
|
|
49
45
|
for (const issue of issues) {
|
|
@@ -93,7 +89,11 @@ class LinearSyncService {
|
|
|
93
89
|
try {
|
|
94
90
|
const task = await this.contextService.getTask(taskId);
|
|
95
91
|
if (!task) {
|
|
96
|
-
throw new
|
|
92
|
+
throw new IntegrationError(
|
|
93
|
+
`Task ${taskId} not found`,
|
|
94
|
+
ErrorCode.LINEAR_SYNC_FAILED,
|
|
95
|
+
{ taskId }
|
|
96
|
+
);
|
|
97
97
|
}
|
|
98
98
|
if (task.externalId) {
|
|
99
99
|
const updateData = this.convertTaskToUpdateData(task);
|
|
@@ -107,7 +107,10 @@ class LinearSyncService {
|
|
|
107
107
|
const config = await this.configService.getConfig();
|
|
108
108
|
const teamId = config.integrations?.linear?.teamId;
|
|
109
109
|
if (!teamId) {
|
|
110
|
-
throw new
|
|
110
|
+
throw new IntegrationError(
|
|
111
|
+
"Linear team ID not configured",
|
|
112
|
+
ErrorCode.LINEAR_SYNC_FAILED
|
|
113
|
+
);
|
|
111
114
|
}
|
|
112
115
|
const createData = {
|
|
113
116
|
title: task.title,
|