@andypai/agent-kanban 0.3.4 → 0.3.6

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.
@@ -0,0 +1,104 @@
1
+ import { providerNotConfigured } from './providers/errors'
2
+ import { resolvePollingSyncIntervalMs } from './sync-config'
3
+
4
+ export type TrackerProvider = 'local' | 'linear' | 'jira'
5
+
6
+ export interface LocalTrackerConfig {
7
+ provider: 'local'
8
+ defaultColumns?: string[]
9
+ defaultTaskColumn?: string
10
+ syncIntervalMs?: number
11
+ }
12
+
13
+ export interface LinearTrackerConfig {
14
+ provider: 'linear'
15
+ apiKey: string
16
+ teamId: string
17
+ syncIntervalMs?: number
18
+ }
19
+
20
+ export interface JiraTrackerConfig {
21
+ provider: 'jira'
22
+ baseUrl: string
23
+ email: string
24
+ apiToken: string
25
+ projectKey: string
26
+ boardId?: number
27
+ defaultIssueType?: string
28
+ syncIntervalMs?: number
29
+ }
30
+
31
+ export type TrackerConfig = LocalTrackerConfig | LinearTrackerConfig | JiraTrackerConfig
32
+
33
+ export function trackerConfigFromEnv(
34
+ env: Record<string, string | undefined> = process.env,
35
+ ): TrackerConfig {
36
+ const provider = (env['KANBAN_PROVIDER'] ?? 'local').trim().toLowerCase()
37
+
38
+ if (provider === 'linear') {
39
+ const apiKey = env['LINEAR_API_KEY']
40
+ const teamId = env['LINEAR_TEAM_ID']
41
+ const missing: string[] = []
42
+ if (!apiKey) missing.push('LINEAR_API_KEY')
43
+ if (!teamId) missing.push('LINEAR_TEAM_ID')
44
+ if (missing.length > 0) {
45
+ providerNotConfigured(
46
+ `${missing.join(', ')} ${missing.length === 1 ? 'is' : 'are'} required when KANBAN_PROVIDER=linear`,
47
+ )
48
+ }
49
+ return {
50
+ provider,
51
+ apiKey: apiKey!,
52
+ teamId: teamId!,
53
+ syncIntervalMs: resolvePollingSyncIntervalMs(env['KANBAN_SYNC_INTERVAL_MS']),
54
+ }
55
+ }
56
+
57
+ if (provider === 'jira') {
58
+ const baseUrl = env['JIRA_BASE_URL']
59
+ const email = env['JIRA_EMAIL']
60
+ const apiToken = env['JIRA_API_TOKEN']
61
+ const projectKey = env['JIRA_PROJECT_KEY']
62
+ const missing: string[] = []
63
+ if (!baseUrl) missing.push('JIRA_BASE_URL')
64
+ if (!email) missing.push('JIRA_EMAIL')
65
+ if (!apiToken) missing.push('JIRA_API_TOKEN')
66
+ if (!projectKey) missing.push('JIRA_PROJECT_KEY')
67
+ if (missing.length > 0) {
68
+ providerNotConfigured(
69
+ `${missing.join(', ')} ${missing.length === 1 ? 'is' : 'are'} required when KANBAN_PROVIDER=jira`,
70
+ )
71
+ }
72
+ const boardIdRaw = env['JIRA_BOARD_ID']
73
+ const boardId = boardIdRaw ? Number.parseInt(boardIdRaw, 10) : undefined
74
+ return {
75
+ provider,
76
+ baseUrl: baseUrl!,
77
+ email: email!,
78
+ apiToken: apiToken!,
79
+ projectKey: projectKey!,
80
+ ...(Number.isFinite(boardId) ? { boardId } : {}),
81
+ defaultIssueType: env['JIRA_ISSUE_TYPE'] ?? 'Task',
82
+ syncIntervalMs: resolvePollingSyncIntervalMs(env['KANBAN_SYNC_INTERVAL_MS']),
83
+ }
84
+ }
85
+
86
+ const defaultColumns = defaultColumnsFromEnv(env)
87
+ return {
88
+ provider: 'local',
89
+ ...(defaultColumns ? { defaultColumns } : {}),
90
+ ...(env['KANBAN_DEFAULT_TASK_COLUMN']?.trim()
91
+ ? { defaultTaskColumn: env['KANBAN_DEFAULT_TASK_COLUMN']!.trim() }
92
+ : {}),
93
+ }
94
+ }
95
+
96
+ function defaultColumnsFromEnv(env: Record<string, string | undefined>): string[] | undefined {
97
+ const raw = env['KANBAN_DEFAULT_COLUMNS']?.trim()
98
+ if (!raw) return undefined
99
+ const columns = raw
100
+ .split(',')
101
+ .map((name) => name.trim())
102
+ .filter(Boolean)
103
+ return columns.length > 0 ? columns : undefined
104
+ }
package/src/webhooks.ts CHANGED
@@ -27,6 +27,20 @@ export function verifyHmacSha256(
27
27
  return timingSafeEqual(macBuf, expBuf)
28
28
  }
29
29
 
30
+ export function verifySha256HmacSignatureHeader(
31
+ secret: string,
32
+ rawBody: string,
33
+ providedSignature: string | undefined | null,
34
+ ): boolean {
35
+ if (!providedSignature) return false
36
+ const eq = providedSignature.indexOf('=')
37
+ if (eq === -1) return false
38
+ const method = providedSignature.slice(0, eq).toLowerCase()
39
+ const signature = providedSignature.slice(eq + 1)
40
+ if (method !== 'sha256') return false
41
+ return verifyHmacSha256(secret, rawBody, signature)
42
+ }
43
+
30
44
  export function headerLower(headers: Record<string, string>, name: string): string | undefined {
31
45
  const target = name.toLowerCase()
32
46
  for (const [k, v] of Object.entries(headers)) {