@mastra/factory 0.28.0 → 0.29.0-alpha.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.
Files changed (224) hide show
  1. package/README.md +6 -4
  2. package/dist/boards/reroute.d.ts +31 -0
  3. package/dist/boards/reroute.d.ts.map +1 -0
  4. package/dist/boards/reroute.js +71 -0
  5. package/dist/boards/reroute.js.map +1 -0
  6. package/dist/environment/repository-access.d.ts +2 -0
  7. package/dist/environment/repository-access.d.ts.map +1 -1
  8. package/dist/environment/repository-access.js +9 -4
  9. package/dist/environment/repository-access.js.map +1 -1
  10. package/dist/factory.d.ts.map +1 -1
  11. package/dist/factory.js +9 -6
  12. package/dist/factory.js.map +1 -1
  13. package/dist/integrations/base.d.ts +8 -0
  14. package/dist/integrations/base.d.ts.map +1 -1
  15. package/dist/integrations/dependabot/default-rules.d.ts +38 -0
  16. package/dist/integrations/dependabot/default-rules.d.ts.map +1 -0
  17. package/dist/integrations/dependabot/default-rules.js +63 -0
  18. package/dist/integrations/dependabot/default-rules.js.map +1 -0
  19. package/dist/integrations/dependabot/rules.d.ts +42 -0
  20. package/dist/integrations/dependabot/rules.d.ts.map +1 -0
  21. package/dist/integrations/dependabot/rules.js +187 -0
  22. package/dist/integrations/dependabot/rules.js.map +1 -0
  23. package/dist/integrations/dependabot/sync.d.ts +76 -0
  24. package/dist/integrations/dependabot/sync.d.ts.map +1 -0
  25. package/dist/integrations/dependabot/sync.js +111 -0
  26. package/dist/integrations/dependabot/sync.js.map +1 -0
  27. package/dist/integrations/github/routes.d.ts.map +1 -1
  28. package/dist/integrations/github/routes.js +7 -2
  29. package/dist/integrations/github/routes.js.map +1 -1
  30. package/dist/integrations/github/sandbox.d.ts +12 -0
  31. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  32. package/dist/integrations/github/sandbox.js +22 -1
  33. package/dist/integrations/github/sandbox.js.map +1 -1
  34. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  35. package/dist/integrations/platform/connect/routes.js +4 -0
  36. package/dist/integrations/platform/connect/routes.js.map +1 -1
  37. package/dist/integrations/platform/github/event-worker.d.ts +5 -0
  38. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  39. package/dist/integrations/platform/github/event-worker.js +33 -2
  40. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  41. package/dist/integrations/platform/github/integration.d.ts +19 -1
  42. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  43. package/dist/integrations/platform/github/integration.js +46 -0
  44. package/dist/integrations/platform/github/integration.js.map +1 -1
  45. package/dist/integrations/platform/vanta/integration.d.ts +33 -0
  46. package/dist/integrations/platform/vanta/integration.d.ts.map +1 -0
  47. package/dist/integrations/platform/vanta/integration.js +133 -0
  48. package/dist/integrations/platform/vanta/integration.js.map +1 -0
  49. package/dist/integrations/vanta/default-rules.d.ts +34 -0
  50. package/dist/integrations/vanta/default-rules.d.ts.map +1 -0
  51. package/dist/integrations/vanta/default-rules.js +61 -0
  52. package/dist/integrations/vanta/default-rules.js.map +1 -0
  53. package/dist/integrations/vanta/rules.d.ts +40 -0
  54. package/dist/integrations/vanta/rules.d.ts.map +1 -0
  55. package/dist/integrations/vanta/rules.js +208 -0
  56. package/dist/integrations/vanta/rules.js.map +1 -0
  57. package/dist/integrations/vanta/sync.d.ts +36 -0
  58. package/dist/integrations/vanta/sync.d.ts.map +1 -0
  59. package/dist/integrations/vanta/sync.js +73 -0
  60. package/dist/integrations/vanta/sync.js.map +1 -0
  61. package/dist/mcp/routes.d.ts.map +1 -1
  62. package/dist/mcp/routes.js +1 -1
  63. package/dist/mcp/routes.js.map +1 -1
  64. package/dist/routes/board-snapshot.d.ts +8 -1
  65. package/dist/routes/board-snapshot.d.ts.map +1 -1
  66. package/dist/routes/board-snapshot.js +23 -2
  67. package/dist/routes/board-snapshot.js.map +1 -1
  68. package/dist/routes/contracts.d.ts +205 -0
  69. package/dist/routes/contracts.d.ts.map +1 -1
  70. package/dist/routes/contracts.js +159 -5
  71. package/dist/routes/contracts.js.map +1 -1
  72. package/dist/routes/intake-routes.d.ts +3 -0
  73. package/dist/routes/intake-routes.d.ts.map +1 -1
  74. package/dist/routes/intake-routes.js +44 -0
  75. package/dist/routes/intake-routes.js.map +1 -1
  76. package/dist/routes/knowledge.d.ts.map +1 -1
  77. package/dist/routes/knowledge.js +3 -2
  78. package/dist/routes/knowledge.js.map +1 -1
  79. package/dist/routes/source-control-sessions.d.ts +1 -1
  80. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  81. package/dist/routes/source-control-sessions.js +109 -3
  82. package/dist/routes/source-control-sessions.js.map +1 -1
  83. package/dist/routes/surface.d.ts +6 -1
  84. package/dist/routes/surface.d.ts.map +1 -1
  85. package/dist/routes/surface.js +72 -9
  86. package/dist/routes/surface.js.map +1 -1
  87. package/dist/routes/work-item-selection.d.ts +0 -4
  88. package/dist/routes/work-item-selection.d.ts.map +1 -1
  89. package/dist/routes/work-item-selection.js +4 -21
  90. package/dist/routes/work-item-selection.js.map +1 -1
  91. package/dist/routes/work-item-starters.d.ts.map +1 -1
  92. package/dist/routes/work-item-starters.js +4 -21
  93. package/dist/routes/work-item-starters.js.map +1 -1
  94. package/dist/routes/work-items.d.ts.map +1 -1
  95. package/dist/routes/work-items.js +112 -36
  96. package/dist/routes/work-items.js.map +1 -1
  97. package/dist/rules/dispatch-errors.d.ts +3 -0
  98. package/dist/rules/dispatch-errors.d.ts.map +1 -1
  99. package/dist/rules/dispatch-errors.js +5 -0
  100. package/dist/rules/dispatch-errors.js.map +1 -1
  101. package/dist/rules/dispatcher.d.ts +2 -0
  102. package/dist/rules/dispatcher.d.ts.map +1 -1
  103. package/dist/rules/dispatcher.js +39 -18
  104. package/dist/rules/dispatcher.js.map +1 -1
  105. package/dist/rules/index.d.ts +2 -2
  106. package/dist/rules/index.d.ts.map +1 -1
  107. package/dist/rules/index.js +2 -2
  108. package/dist/rules/start-coordinator.d.ts +6 -1
  109. package/dist/rules/start-coordinator.d.ts.map +1 -1
  110. package/dist/rules/start-coordinator.js +6 -2
  111. package/dist/rules/start-coordinator.js.map +1 -1
  112. package/dist/rules/transition-service.d.ts.map +1 -1
  113. package/dist/rules/transition-service.js +3 -2
  114. package/dist/rules/transition-service.js.map +1 -1
  115. package/dist/rules/types.d.ts +71 -3
  116. package/dist/rules/types.d.ts.map +1 -1
  117. package/dist/rules/types.js +10 -2
  118. package/dist/rules/types.js.map +1 -1
  119. package/dist/rules/validation.d.ts.map +1 -1
  120. package/dist/rules/validation.js +5 -0
  121. package/dist/rules/validation.js.map +1 -1
  122. package/dist/session/factory-session.d.ts +20 -5
  123. package/dist/session/factory-session.d.ts.map +1 -1
  124. package/dist/session/factory-session.js +20 -6
  125. package/dist/session/factory-session.js.map +1 -1
  126. package/dist/storage/domains/audit/actions.d.ts +1 -1
  127. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  128. package/dist/storage/domains/audit/actions.js +2 -1
  129. package/dist/storage/domains/audit/actions.js.map +1 -1
  130. package/dist/storage/domains/audit/actors.d.ts.map +1 -1
  131. package/dist/storage/domains/audit/actors.js +1 -1
  132. package/dist/storage/domains/audit/actors.js.map +1 -1
  133. package/dist/storage/domains/intake/base.d.ts +1 -1
  134. package/dist/storage/domains/intake/base.js +2 -2
  135. package/dist/storage/domains/intake/base.js.map +1 -1
  136. package/dist/storage/domains/projects/base.d.ts +8 -0
  137. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  138. package/dist/storage/domains/projects/base.js +11 -1
  139. package/dist/storage/domains/projects/base.js.map +1 -1
  140. package/dist/storage/domains/work-items/base.d.ts +15 -4
  141. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  142. package/dist/storage/domains/work-items/base.js +19 -1
  143. package/dist/storage/domains/work-items/base.js.map +1 -1
  144. package/dist/tools/approval-tools.d.ts +20 -0
  145. package/dist/tools/approval-tools.d.ts.map +1 -1
  146. package/dist/tools/approval-tools.js +79 -30
  147. package/dist/tools/approval-tools.js.map +1 -1
  148. package/dist/tools/audit-events-tool.d.ts +1 -1
  149. package/dist/tools/messaging-tools.d.ts.map +1 -1
  150. package/dist/tools/messaging-tools.js +1 -1
  151. package/dist/tools/messaging-tools.js.map +1 -1
  152. package/dist/tools/read-tools.d.ts +0 -2
  153. package/dist/tools/read-tools.d.ts.map +1 -1
  154. package/dist/tools/read-tools.js +2 -7
  155. package/dist/tools/read-tools.js.map +1 -1
  156. package/dist/tools/reports.d.ts +3 -0
  157. package/dist/tools/reports.d.ts.map +1 -1
  158. package/dist/tools/reports.js +3 -3
  159. package/dist/tools/reports.js.map +1 -1
  160. package/dist/tools/run-watch.d.ts +14 -2
  161. package/dist/tools/run-watch.d.ts.map +1 -1
  162. package/dist/tools/run-watch.js +24 -4
  163. package/dist/tools/run-watch.js.map +1 -1
  164. package/dist/tools/session-tools.d.ts.map +1 -1
  165. package/dist/tools/session-tools.js +17 -6
  166. package/dist/tools/session-tools.js.map +1 -1
  167. package/dist/tools/side-sessions.d.ts.map +1 -1
  168. package/dist/tools/side-sessions.js +1 -1
  169. package/dist/tools/side-sessions.js.map +1 -1
  170. package/dist/tools/work-item-tools.d.ts.map +1 -1
  171. package/dist/tools/work-item-tools.js +12 -2
  172. package/dist/tools/work-item-tools.js.map +1 -1
  173. package/dist/work-item-branch.d.ts +1 -1
  174. package/dist/work-item-branch.d.ts.map +1 -1
  175. package/dist/work-item-branch.js +2 -0
  176. package/dist/work-item-branch.js.map +1 -1
  177. package/dist/work-items/board-filter-options.d.ts +5 -0
  178. package/dist/work-items/board-filter-options.d.ts.map +1 -0
  179. package/dist/work-items/board-filter-options.js +27 -0
  180. package/dist/work-items/board-filter-options.js.map +1 -0
  181. package/dist/work-items/board-phases.d.ts +28 -0
  182. package/dist/work-items/board-phases.d.ts.map +1 -0
  183. package/dist/work-items/board-phases.js +165 -0
  184. package/dist/work-items/board-phases.js.map +1 -0
  185. package/dist/work-items/card-facts.d.ts +24 -0
  186. package/dist/work-items/card-facts.d.ts.map +1 -0
  187. package/dist/work-items/card-facts.js +75 -0
  188. package/dist/work-items/card-facts.js.map +1 -0
  189. package/dist/work-items/card-labels.d.ts +5 -0
  190. package/dist/work-items/card-labels.d.ts.map +1 -0
  191. package/dist/work-items/card-labels.js +13 -0
  192. package/dist/work-items/card-labels.js.map +1 -0
  193. package/dist/work-items/card-number.d.ts +10 -0
  194. package/dist/work-items/card-number.d.ts.map +1 -0
  195. package/dist/work-items/card-number.js +15 -0
  196. package/dist/work-items/card-number.js.map +1 -0
  197. package/dist/work-items/card-people.d.ts +25 -0
  198. package/dist/work-items/card-people.d.ts.map +1 -0
  199. package/dist/work-items/card-people.js +100 -0
  200. package/dist/work-items/card-people.js.map +1 -0
  201. package/dist/work-items/card-search-text.d.ts +4 -0
  202. package/dist/work-items/card-search-text.d.ts.map +1 -0
  203. package/dist/work-items/card-search-text.js +15 -0
  204. package/dist/work-items/card-search-text.js.map +1 -0
  205. package/dist/work-items/card-source-filters.d.ts +23 -0
  206. package/dist/work-items/card-source-filters.d.ts.map +1 -0
  207. package/dist/work-items/card-source-filters.js +25 -0
  208. package/dist/work-items/card-source-filters.js.map +1 -0
  209. package/dist/work-items/create-work-item.d.ts +0 -6
  210. package/dist/work-items/create-work-item.d.ts.map +1 -1
  211. package/dist/work-items/create-work-item.js +2 -7
  212. package/dist/work-items/create-work-item.js.map +1 -1
  213. package/dist/work-items/list-related-cards.d.ts +4 -0
  214. package/dist/work-items/list-related-cards.d.ts.map +1 -0
  215. package/dist/work-items/list-related-cards.js +24 -0
  216. package/dist/work-items/list-related-cards.js.map +1 -0
  217. package/dist/work-items/search-words.d.ts +5 -0
  218. package/dist/work-items/search-words.d.ts.map +1 -0
  219. package/dist/work-items/search-words.js +12 -0
  220. package/dist/work-items/search-words.js.map +1 -0
  221. package/dist/workspace.d.ts.map +1 -1
  222. package/dist/workspace.js +92 -47
  223. package/dist/workspace.js.map +1 -1
  224. package/package.json +6 -5
@@ -0,0 +1,133 @@
1
+ import { loose } from "../../../routes/route.js";
2
+ import { IssueReconcileWorker } from "../../issue-reconcile-worker.js";
3
+ import { attachVantaRules } from "../../vanta/rules.js";
4
+ import { VANTA_VULNERABILITIES_SOURCE_ID, createVantaSync } from "../../vanta/sync.js";
5
+ import { PlatformApiClient, platformApiClientConfigFromEnv } from "../api-client.js";
6
+ import { registerApiRoute } from "@mastra/core/server";
7
+ // src/integrations/platform/vanta/integration.ts
8
+ /** Provider key registered for Vanta in Mastra Platform's integrations catalog. */
9
+ const PLATFORM_VANTA_PROVIDER_KEY = "vanta";
10
+ const PAGE_SIZE = 100;
11
+ const MAX_PAGES = 50;
12
+ /**
13
+ * Files Vanta vulnerabilities as `security`-labeled cards through Platform-managed (MastraConnect)
14
+ * Vanta connections. Vanta has no webhooks Factory can consume, so a worker polls the active list.
15
+ */
16
+ var PlatformVantaIntegration = class {
17
+ id = "vanta";
18
+ #client;
19
+ #syncIntervalMs;
20
+ intake = {
21
+ listSources: () => this.#listSources(),
22
+ listItems: async () => ({
23
+ items: [],
24
+ nextCursor: null
25
+ }),
26
+ listIssues: async () => ({
27
+ issues: [],
28
+ nextCursor: null
29
+ }),
30
+ getIssue: async () => null,
31
+ createComment: async () => null,
32
+ updateIssue: async () => null
33
+ };
34
+ constructor(config = {}) {
35
+ this.#client = new PlatformApiClient(config.clientConfig ?? platformApiClientConfigFromEnv());
36
+ this.#syncIntervalMs = config.syncIntervalMs ?? 9e5;
37
+ }
38
+ async listConnections() {
39
+ return (await this.#client.request("GET", `/v2/connections?providerKey=${PLATFORM_VANTA_PROVIDER_KEY}`)).connections;
40
+ }
41
+ async #activeConnections() {
42
+ return (await this.listConnections()).filter((connection) => connection.status === "active").sort((a, b) => a.id.localeCompare(b.id));
43
+ }
44
+ async #listSources() {
45
+ if ((await this.#activeConnections()).length === 0) return [];
46
+ return [{
47
+ id: VANTA_VULNERABILITIES_SOURCE_ID,
48
+ name: "Vulnerabilities",
49
+ type: "vulnerabilities"
50
+ }];
51
+ }
52
+ /** Every active vulnerability across all active Vanta connections, de-duplicated by id. */
53
+ async listVulnerabilities() {
54
+ const byId = /* @__PURE__ */ new Map();
55
+ for (const connection of await this.#activeConnections()) {
56
+ let cursor = null;
57
+ for (let page = 0; page < MAX_PAGES; page++) {
58
+ const query = new URLSearchParams({
59
+ isDeactivated: "false",
60
+ pageSize: String(PAGE_SIZE)
61
+ });
62
+ if (cursor) query.set("pageCursor", cursor);
63
+ const result = await this.#client.request("GET", `/v2/connections/${encodeURIComponent(connection.id)}/proxy/v1/vulnerabilities?${query}`);
64
+ for (const vulnerability of result.results.data) byId.set(vulnerability.id, vulnerability);
65
+ if (!result.results.pageInfo.hasNextPage || !result.results.pageInfo.endCursor) break;
66
+ cursor = result.results.pageInfo.endCursor;
67
+ }
68
+ }
69
+ return [...byId.values()];
70
+ }
71
+ workers(ctx) {
72
+ const ingest = attachVantaRules(ctx);
73
+ if (!ingest) return [];
74
+ const { projects, intake } = ctx.storage;
75
+ const sync = createVantaSync({
76
+ listVulnerabilities: async () => (await this.#activeConnections()).length ? this.listVulnerabilities() : [],
77
+ listProjects: () => projects.listAll(),
78
+ intakeEnabled: async (orgId) => (await intake.getConfig({
79
+ orgId,
80
+ integrationIds: [this.id]
81
+ }))[this.id]?.enabled ?? false,
82
+ boundProjectIds: async (orgId) => (await intake.listBindings({
83
+ orgId,
84
+ integrationId: this.id
85
+ })).map((binding) => binding.factoryProjectId),
86
+ ingest,
87
+ userId: "factory-rule-dispatcher"
88
+ });
89
+ return [new IssueReconcileWorker({
90
+ integrationId: this.id,
91
+ reconcile: sync,
92
+ intervalMs: this.#syncIntervalMs
93
+ })];
94
+ }
95
+ routes(ctx) {
96
+ return [registerApiRoute("/web/vanta/status", {
97
+ method: "GET",
98
+ requiresAuth: false,
99
+ handler: async (c) => {
100
+ if (!ctx.auth.enabled()) return c.json({
101
+ enabled: false,
102
+ configured: true,
103
+ reason: "missing_config"
104
+ });
105
+ await ctx.auth.ensureUser(loose(c));
106
+ const tenant = ctx.auth.tenant(loose(c));
107
+ if (!tenant) return c.json({
108
+ error: "unauthorized",
109
+ reason: "auth_required"
110
+ }, 401);
111
+ if (!tenant.orgId) return c.json({
112
+ enabled: true,
113
+ configured: true,
114
+ reason: "organization_required"
115
+ });
116
+ return c.json({
117
+ enabled: true,
118
+ configured: true,
119
+ reason: "ready"
120
+ });
121
+ }
122
+ })];
123
+ }
124
+ diagnostics() {
125
+ return {
126
+ configured: true,
127
+ mode: "platform"
128
+ };
129
+ }
130
+ };
131
+ export { PlatformVantaIntegration };
132
+
133
+ //# sourceMappingURL=integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.js","names":[],"sources":["../../../../src/integrations/platform/vanta/integration.ts"],"sourcesContent":["import type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { MastraWorker } from '@mastra/core/worker';\n\nimport type { Intake, IntakeSource } from '../../../capabilities/intake.js';\nimport { loose } from '../../../routes/route.js';\nimport type { FactoryIntegration, IntegrationContext } from '../../base.js';\nimport { IssueReconcileWorker } from '../../issue-reconcile-worker.js';\nimport { attachVantaRules } from '../../vanta/rules.js';\nimport { createVantaSync, DEFAULT_VANTA_SYNC_INTERVAL_MS, VANTA_VULNERABILITIES_SOURCE_ID } from '../../vanta/sync.js';\nimport type { VantaVulnerability } from '../../vanta/sync.js';\nimport { PlatformApiClient, platformApiClientConfigFromEnv } from '../api-client.js';\nimport type { PlatformApiClientConfig } from '../api-client.js';\n\nexport interface PlatformVantaIntegrationConfig {\n clientConfig?: PlatformApiClientConfig;\n syncIntervalMs?: number;\n}\n\n/** Provider key registered for Vanta in Mastra Platform's integrations catalog. */\nconst PLATFORM_VANTA_PROVIDER_KEY = 'vanta';\nconst PAGE_SIZE = 100;\nconst MAX_PAGES = 50;\n\ninterface PlatformIntegrationConnection {\n id: string;\n status: 'active' | 'needs_reauth';\n accountLabel: string | null;\n}\n\ninterface VantaVulnerabilityPage {\n results: {\n data: VantaVulnerability[];\n pageInfo: { endCursor: string | null; hasNextPage: boolean };\n };\n}\n\n/**\n * Files Vanta vulnerabilities as `security`-labeled cards through Platform-managed (MastraConnect)\n * Vanta connections. Vanta has no webhooks Factory can consume, so a worker polls the active list.\n */\nexport class PlatformVantaIntegration implements FactoryIntegration {\n readonly id = 'vanta';\n readonly #client: PlatformApiClient;\n readonly #syncIntervalMs: number;\n\n readonly intake: Intake = {\n listSources: () => this.#listSources(),\n listItems: async () => ({ items: [], nextCursor: null }),\n listIssues: async () => ({ issues: [], nextCursor: null }),\n getIssue: async () => null,\n createComment: async () => null,\n updateIssue: async () => null,\n };\n\n constructor(config: PlatformVantaIntegrationConfig = {}) {\n this.#client = new PlatformApiClient(config.clientConfig ?? platformApiClientConfigFromEnv());\n this.#syncIntervalMs = config.syncIntervalMs ?? DEFAULT_VANTA_SYNC_INTERVAL_MS;\n }\n\n async listConnections(): Promise<PlatformIntegrationConnection[]> {\n const result = await this.#client.request<{ connections: PlatformIntegrationConnection[] }>(\n 'GET',\n `/v2/connections?providerKey=${PLATFORM_VANTA_PROVIDER_KEY}`,\n );\n return result.connections;\n }\n\n async #activeConnections(): Promise<PlatformIntegrationConnection[]> {\n const connections = await this.listConnections();\n return connections.filter(connection => connection.status === 'active').sort((a, b) => a.id.localeCompare(b.id));\n }\n\n async #listSources(): Promise<IntakeSource[]> {\n if ((await this.#activeConnections()).length === 0) return [];\n return [{ id: VANTA_VULNERABILITIES_SOURCE_ID, name: 'Vulnerabilities', type: 'vulnerabilities' }];\n }\n\n /** Every active vulnerability across all active Vanta connections, de-duplicated by id. */\n async listVulnerabilities(): Promise<VantaVulnerability[]> {\n const byId = new Map<string, VantaVulnerability>();\n for (const connection of await this.#activeConnections()) {\n let cursor: string | null = null;\n for (let page = 0; page < MAX_PAGES; page++) {\n const query = new URLSearchParams({ isDeactivated: 'false', pageSize: String(PAGE_SIZE) });\n if (cursor) query.set('pageCursor', cursor);\n const result: VantaVulnerabilityPage = await this.#client.request<VantaVulnerabilityPage>(\n 'GET',\n `/v2/connections/${encodeURIComponent(connection.id)}/proxy/v1/vulnerabilities?${query}`,\n );\n for (const vulnerability of result.results.data) byId.set(vulnerability.id, vulnerability);\n if (!result.results.pageInfo.hasNextPage || !result.results.pageInfo.endCursor) break;\n cursor = result.results.pageInfo.endCursor;\n }\n }\n return [...byId.values()];\n }\n\n workers(ctx: IntegrationContext): MastraWorker[] {\n const ingest = attachVantaRules(ctx);\n if (!ingest) return [];\n const { projects, intake } = ctx.storage;\n const sync = createVantaSync({\n listVulnerabilities: async () => ((await this.#activeConnections()).length ? this.listVulnerabilities() : []),\n listProjects: () => projects.listAll(),\n intakeEnabled: async orgId =>\n (await intake.getConfig({ orgId, integrationIds: [this.id] }))[this.id]?.enabled ?? false,\n boundProjectIds: async orgId =>\n (await intake.listBindings({ orgId, integrationId: this.id })).map(binding => binding.factoryProjectId),\n ingest,\n userId: 'factory-rule-dispatcher',\n });\n return [new IssueReconcileWorker({ integrationId: this.id, reconcile: sync, intervalMs: this.#syncIntervalMs })];\n }\n\n routes(ctx: IntegrationContext): ApiRoute[] {\n return [\n registerApiRoute('/web/vanta/status', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n if (!ctx.auth.enabled()) return c.json({ enabled: false, configured: true, reason: 'missing_config' });\n await ctx.auth.ensureUser(loose(c));\n const tenant = ctx.auth.tenant(loose(c));\n if (!tenant) return c.json({ error: 'unauthorized', reason: 'auth_required' }, 401);\n if (!tenant.orgId) return c.json({ enabled: true, configured: true, reason: 'organization_required' });\n return c.json({ enabled: true, configured: true, reason: 'ready' });\n },\n }),\n ];\n }\n\n diagnostics(): Record<string, unknown> {\n return { configured: true, mode: 'platform' };\n }\n}\n"],"mappings":";;;;;;;;AAoBA,MAAM,8BAA8B;AACpC,MAAM,YAAY;AAClB,MAAM,YAAY;;;;;AAmBlB,IAAa,2BAAb,MAAoE;CAClE,KAAc;CACd;CACA;CAEA,SAA0B;EACxB,mBAAmB,KAAK,aAAa;EACrC,WAAW,aAAa;GAAE,OAAO,CAAC;GAAG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Y;KAAM,QAAQ;IAAwB,CAAC;IACrG,OAAO,EAAE,KAAK;KAAE,SAAS;KAAM,YAAY;KAAM,QAAQ;IAAQ,CAAC;GACpE;EACF,CAAC,CACH;CACF;CAEA,cAAuC;EACrC,OAAO;GAAE,YAAY;GAAM,MAAM;EAAW;CAC9C;AACF"}
@@ -0,0 +1,34 @@
1
+ import type { FactoryRuleHandler, FactoryVantaEventName, FactoryVantaRuleContext } from '../../rules/types.js';
2
+ export type VantaEventRules = Readonly<Record<FactoryVantaEventName, FactoryRuleHandler<FactoryVantaRuleContext> | null>>;
3
+ declare function vantaVulnerabilityObserved(context: FactoryVantaRuleContext): {
4
+ readonly type: 'upsertLinkedWorkItem';
5
+ readonly idempotencyKey: `${string}:vulnerability-intake`;
6
+ readonly board: string;
7
+ readonly source: 'vanta-vulnerability';
8
+ readonly sourceKey: string;
9
+ readonly title: string;
10
+ readonly description: string;
11
+ readonly url: string | null;
12
+ readonly stage: string;
13
+ readonly metadata: {
14
+ readonly identifier: string;
15
+ readonly body?: string | undefined;
16
+ readonly state: "open" | "resolved";
17
+ readonly severity: string | null;
18
+ readonly packageIdentifier: string | null;
19
+ readonly fixable: boolean | null;
20
+ readonly remediateBy: string | null;
21
+ readonly author: 'vanta';
22
+ readonly labels: string[];
23
+ readonly sourceCreatedAt: string;
24
+ readonly createdAt: string;
25
+ readonly updatedAt: string;
26
+ };
27
+ } | undefined;
28
+ declare function vantaVulnerabilityClosed(context: FactoryVantaRuleContext): import("../../rules/types.js").FactoryTransitionDecision | undefined;
29
+ export declare const defaultVantaRules: Readonly<{
30
+ vulnerabilityObserved: typeof vantaVulnerabilityObserved;
31
+ vulnerabilityClosed: typeof vantaVulnerabilityClosed;
32
+ }>;
33
+ export {};
34
+ //# sourceMappingURL=default-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/vanta/default-rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/G,MAAM,MAAM,eAAe,GAAG,QAAQ,CACpC,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC,CAClF,CAAC;AAkBF,iBAAS,0BAA0B,CAAC,OAAO,EAAE,uBAAuB;mBAI1D,sBAAsB;;;qBAIpB,qBAAqB;;;;;;;;;;;;;;yBAcnB,OAAO;yBACsB,MAAM,EAAE;;;;;cAMlD;AAED,iBAAS,wBAAwB,CAAC,OAAO,EAAE,uBAAuB,wEAYjE;AAED,eAAO,MAAM,iBAAiB;;;EAGF,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { closedByRoutes } from "../../rules/event-rules.js";
2
+ // src/integrations/vanta/default-rules.ts
3
+ const MAX_DESCRIPTION_LENGTH = 8e3;
4
+ function vantaDescription(vulnerability) {
5
+ const text = [[
6
+ `**Vulnerability:** ${vulnerability.name}`,
7
+ vulnerability.packageIdentifier && `**Package:** \`${vulnerability.packageIdentifier}\``,
8
+ vulnerability.severity && `**Severity:** ${vulnerability.severity}`,
9
+ vulnerability.fixable !== null && `**Fixable:** ${vulnerability.fixable ? "yes" : "no"}`,
10
+ vulnerability.remediateBy && `**Remediate by:** ${vulnerability.remediateBy.slice(0, 10)}`,
11
+ vulnerability.url && `**Details:** ${vulnerability.url}`
12
+ ].filter((fact) => typeof fact === "string").map((fact) => `- ${fact}`).join("\n"), vulnerability.description?.trim()].filter(Boolean).join("\n\n");
13
+ return text.length <= MAX_DESCRIPTION_LENGTH ? text : `${text.slice(0, 7999)}…`;
14
+ }
15
+ function vantaVulnerabilityObserved(context) {
16
+ if (context.item || !context.intake) return;
17
+ const { vulnerability } = context;
18
+ return {
19
+ type: "upsertLinkedWorkItem",
20
+ idempotencyKey: `${context.ingress.id}:vulnerability-intake`,
21
+ board: context.intake.board,
22
+ source: "vanta-vulnerability",
23
+ sourceKey: vulnerability.id,
24
+ title: vulnerability.title,
25
+ description: vantaDescription(vulnerability),
26
+ url: vulnerability.url,
27
+ stage: context.intake.initialPhase,
28
+ metadata: {
29
+ identifier: vulnerability.name,
30
+ ...vulnerability.description ? { body: vulnerability.description } : {},
31
+ state: vulnerability.state,
32
+ severity: vulnerability.severity,
33
+ packageIdentifier: vulnerability.packageIdentifier,
34
+ fixable: vulnerability.fixable,
35
+ remediateBy: vulnerability.remediateBy,
36
+ author: "vanta",
37
+ labels: [...vulnerability.labels],
38
+ sourceCreatedAt: vulnerability.createdAt,
39
+ createdAt: vulnerability.createdAt,
40
+ updatedAt: vulnerability.createdAt
41
+ }
42
+ };
43
+ }
44
+ function vantaVulnerabilityClosed(context) {
45
+ if (!context.item || context.item.source !== "vanta-vulnerability") return;
46
+ const closure = context.boardClosure;
47
+ if (!context.board || !closure || closure.itemTerminal) return;
48
+ return closedByRoutes(false, {
49
+ idempotencyKey: `${context.ingress.id}:vulnerability-closed`,
50
+ board: context.board,
51
+ stage: closure.completed.phase,
52
+ message: { text: `Vanta no longer lists ${context.vulnerability.name} as active; this ${closure.boardTitle} card was moved to ${closure.completed.title}.` }
53
+ });
54
+ }
55
+ const defaultVantaRules = Object.freeze({
56
+ vulnerabilityObserved: vantaVulnerabilityObserved,
57
+ vulnerabilityClosed: vantaVulnerabilityClosed
58
+ });
59
+ export { defaultVantaRules };
60
+
61
+ //# sourceMappingURL=default-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/vanta/default-rules.ts"],"sourcesContent":["import { closedByRoutes } from '../../rules/event-rules.js';\nimport type { FactoryRuleHandler, FactoryVantaEventName, FactoryVantaRuleContext } from '../../rules/types.js';\n\nexport type VantaEventRules = Readonly<\n Record<FactoryVantaEventName, FactoryRuleHandler<FactoryVantaRuleContext> | null>\n>;\n\nconst MAX_DESCRIPTION_LENGTH = 8000;\n\nfunction vantaDescription(vulnerability: FactoryVantaRuleContext['vulnerability']): string {\n const facts = [\n `**Vulnerability:** ${vulnerability.name}`,\n vulnerability.packageIdentifier && `**Package:** \\`${vulnerability.packageIdentifier}\\``,\n vulnerability.severity && `**Severity:** ${vulnerability.severity}`,\n vulnerability.fixable !== null && `**Fixable:** ${vulnerability.fixable ? 'yes' : 'no'}`,\n vulnerability.remediateBy && `**Remediate by:** ${vulnerability.remediateBy.slice(0, 10)}`,\n vulnerability.url && `**Details:** ${vulnerability.url}`,\n ].filter((fact): fact is string => typeof fact === 'string');\n const parts = [facts.map(fact => `- ${fact}`).join('\\n'), vulnerability.description?.trim()].filter(Boolean);\n const text = parts.join('\\n\\n');\n return text.length <= MAX_DESCRIPTION_LENGTH ? text : `${text.slice(0, MAX_DESCRIPTION_LENGTH - 1)}…`;\n}\n\nfunction vantaVulnerabilityObserved(context: FactoryVantaRuleContext) {\n if (context.item || !context.intake) return;\n const { vulnerability } = context;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:vulnerability-intake`,\n // Filed on the default board's first phase; the project's intake routes place it from there.\n board: context.intake.board,\n source: 'vanta-vulnerability',\n sourceKey: vulnerability.id,\n title: vulnerability.title,\n description: vantaDescription(vulnerability),\n url: vulnerability.url,\n stage: context.intake.initialPhase,\n metadata: {\n identifier: vulnerability.name,\n ...(vulnerability.description ? { body: vulnerability.description } : {}),\n state: vulnerability.state,\n severity: vulnerability.severity,\n packageIdentifier: vulnerability.packageIdentifier,\n fixable: vulnerability.fixable,\n remediateBy: vulnerability.remediateBy,\n author: 'vanta',\n labels: [...vulnerability.labels] as string[],\n sourceCreatedAt: vulnerability.createdAt,\n createdAt: vulnerability.createdAt,\n updatedAt: vulnerability.createdAt,\n },\n } as const;\n}\n\nfunction vantaVulnerabilityClosed(context: FactoryVantaRuleContext) {\n if (!context.item || context.item.source !== 'vanta-vulnerability') return;\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n return closedByRoutes(false, {\n idempotencyKey: `${context.ingress.id}:vulnerability-closed`,\n board: context.board,\n stage: closure.completed.phase,\n message: {\n text: `Vanta no longer lists ${context.vulnerability.name} as active; this ${closure.boardTitle} card was moved to ${closure.completed.title}.`,\n },\n });\n}\n\nexport const defaultVantaRules = Object.freeze({\n vulnerabilityObserved: vantaVulnerabilityObserved,\n vulnerabilityClosed: vantaVulnerabilityClosed,\n} satisfies VantaEventRules);\n"],"mappings":";;AAOA,MAAM,yBAAyB;AAE/B,SAAS,iBAAiB,eAAiE;CAUzF,MAAM,OADQ,CARA;EACZ,sBAAsB,cAAc;EACpC,cAAc,qBAAqB,kBAAkB,cAAc,kBAAkB;EACrF,cAAc,YAAY,iBAAiB,cAAc;EACzD,cAAc,YAAY,QAAQ,gBAAgB,cAAc,UAAU,QAAQ;EAClF,cAAc,eAAe,qBAAqB,cAAc,YAAY,MAAM,GAAG,EAAE;EACvF,cAAc,OAAO,gBAAgB,cAAc;CACrD,CAAC,CAAC,QAAQ,SAAyB,OAAO,SAAS,QAChC,CAAC,CAAC,KAAI,SAAQ,KAAK,MAAM,CAAC,CAAC,KAAK,IAAI,GAAG,cAAc,aAAa,KAAK,CAAC,CAAC,CAAC,OAAO,OACnF,CAAC,CAAC,KAAK,MAAM;CAC9B,OAAO,KAAK,UAAU,yBAAyB,OAAO,GAAG,KAAK,MAAM,GAAG,IAA0B,EAAE;AACrG;AAEA,SAAS,2BAA2B,SAAkC;CACpE,IAAI,QAAQ,QAAQ,CAAC,QAAQ,QAAQ;CACrC,MAAM,EAAE,kBAAkB;CAC1B,OAAO;EACL,MAAM;EACN,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EAEtC,OAAO,QAAQ,OAAO;EACtB,QAAQ;EACR,WAAW,cAAc;EACzB,OAAO,cAAc;EACrB,aAAa,iBAAiB,aAAa;EAC3C,KAAK,cAAc;EACnB,OAAO,QAAQ,OAAO;EACtB,UAAU;GACR,YAAY,cAAc;GAC1B,GAAI,cAAc,cAAc,EAAE,MAAM,cAAc,YAAY,IAAI,CAAC;GACvE,OAAO,cAAc;GACrB,UAAU,cAAc;GACxB,mBAAmB,cAAc;GACjC,SAAS,cAAc;GACvB,aAAa,cAAc;GAC3B,QAAQ;GACR,QAAQ,CAAC,GAAG,cAAc,MAAM;GAChC,iBAAiB,cAAc;GAC/B,WAAW,cAAc;GACzB,WAAW,cAAc;EAC3B;CACF;AACF;AAEA,SAAS,yBAAyB,SAAkC;CAClE,IAAI,CAAC,QAAQ,QAAQ,QAAQ,KAAK,WAAW,uBAAuB;CACpE,MAAM,UAAU,QAAQ;CACxB,IAAI,CAAC,QAAQ,SAAS,CAAC,WAAW,QAAQ,cAAc;CACxD,OAAO,eAAe,OAAO;EAC3B,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EACtC,OAAO,QAAQ;EACf,OAAO,QAAQ,UAAU;EACzB,SAAS,EACP,MAAM,yBAAyB,QAAQ,cAAc,KAAK,mBAAmB,QAAQ,WAAW,qBAAqB,QAAQ,UAAU,MAAM,GAC/I;CACF,CAAC;AACH;AAEA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,uBAAuB;CACvB,qBAAqB;AACvB,CAA2B"}
@@ -0,0 +1,40 @@
1
+ import type { BoardEventFacts } from '../../boards/board-events.js';
2
+ import type { BoardRegistry } from '../../boards/index.js';
3
+ import type { ProjectBoardSource } from '../../boards/project-boards.js';
4
+ import type { FactoryVantaRuleContext } from '../../rules/types.js';
5
+ import type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';
6
+ import type { WorkItemsStorage } from '../../storage/domains/work-items/base.js';
7
+ import type { IntegrationContext } from '../base.js';
8
+ import type { VantaEventRules } from './default-rules.js';
9
+ /** Labels every Vanta card carries, so the Security intake route matches them like any `security`-labeled issue. */
10
+ export declare function vantaLabels(severity: string | null): string[];
11
+ export type VantaVulnerabilityIngress = FactoryVantaRuleContext['vulnerability'];
12
+ export interface VantaRulesOptions {
13
+ projects: Pick<FactoryProjectsStorage, 'get'>;
14
+ storage: WorkItemsStorage;
15
+ configVersion: string;
16
+ boards: BoardRegistry | ProjectBoardSource;
17
+ rules?: VantaEventRules;
18
+ }
19
+ export interface VantaRulesIngress {
20
+ orgId: string;
21
+ userId: string;
22
+ factoryProjectId: string;
23
+ /** Every vulnerability Vanta currently lists as active. Open cards missing from it are closed. */
24
+ vulnerabilities: VantaVulnerabilityIngress[];
25
+ }
26
+ type IngressStatus = 'committed' | 'replayed' | 'missing';
27
+ /** A first sighting of an active vulnerability creates its card; dropping off Vanta's active list closes it. */
28
+ export declare function boardEventFor(context: Pick<FactoryVantaRuleContext, 'event' | 'item'>): BoardEventFacts | undefined;
29
+ export declare class VantaRules {
30
+ #private;
31
+ private readonly options;
32
+ constructor(options: VantaRulesOptions);
33
+ ingest(input: VantaRulesIngress): Promise<{
34
+ status: IngressStatus;
35
+ ingested: number;
36
+ }>;
37
+ }
38
+ export declare function attachVantaRules(context: IntegrationContext): ((input: VantaRulesIngress) => Promise<unknown>) | undefined;
39
+ export {};
40
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/vanta/rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,KAAK,EAAE,uBAAuB,EAAuB,MAAM,sBAAsB,CAAC;AAGzF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,KAAK,EAAQ,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAI1D,oHAAoH;AACpH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,EAAE,CAE7D;AAED,MAAM,MAAM,yBAAyB,GAAG,uBAAuB,CAAC,eAAe,CAAC,CAAC;AAEjF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,IAAI,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;IAC9C,OAAO,EAAE,gBAAgB,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,aAAa,GAAG,kBAAkB,CAAC;IAC3C,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,CAAC;IACzB,kGAAkG;IAClG,eAAe,EAAE,yBAAyB,EAAE,CAAC;CAC9C;AAED,KAAK,aAAa,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,CAAC;AAE1D,gHAAgH;AAChH,wBAAgB,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,uBAAuB,EAAE,OAAO,GAAG,MAAM,CAAC,GAAG,eAAe,GAAG,SAAS,CAKnH;AAsBD,qBAAa,UAAU;;IAGT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAApC,YAA6B,OAAO,EAAE,iBAAiB,EAEtD;IAMK,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,aAAa,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAwB3F;CAsGF;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,kBAAkB,GAC1B,CAAC,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAS9D"}
@@ -0,0 +1,208 @@
1
+ import { closeReason } from "../../boards/board-events.js";
2
+ import "../../boards/index.js";
3
+ import { boardForWorkItem, rulePhaseField, withBoardClosure, withIntakeTarget } from "../../boards/semantics.js";
4
+ import { toBoardSource } from "../../boards/project-boards.js";
5
+ import { routeEventDecision } from "../../rules/event-rules.js";
6
+ import { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from "../../rules/validation.js";
7
+ import { defaultVantaRules } from "./default-rules.js";
8
+ // src/integrations/vanta/rules.ts
9
+ const MAX_STALE_RULE_ATTEMPTS = 3;
10
+ /** Labels every Vanta card carries, so the Security intake route matches them like any `security`-labeled issue. */
11
+ function vantaLabels(severity) {
12
+ return [
13
+ "security",
14
+ "vanta",
15
+ ...severity ? [`severity:${severity.toLowerCase()}`] : []
16
+ ];
17
+ }
18
+ /** A first sighting of an active vulnerability creates its card; dropping off Vanta's active list closes it. */
19
+ function boardEventFor(context) {
20
+ if (context.event === "vulnerabilityClosed") return {
21
+ type: "work_item.closed",
22
+ reason: closeReason(false)
23
+ };
24
+ return context.item ? void 0 : { type: "work_item.created" };
25
+ }
26
+ /** The closing ingress for a card whose vulnerability Vanta stopped listing, rebuilt from the card. */
27
+ function resolvedFromCard(sourceKey, item) {
28
+ const metadata = item.metadata ?? {};
29
+ const text = (key) => typeof metadata[key] === "string" ? metadata[key] : null;
30
+ return {
31
+ id: sourceKey,
32
+ name: text("identifier") ?? sourceKey,
33
+ title: item.title,
34
+ description: null,
35
+ url: item.externalSource?.url ?? null,
36
+ state: "resolved",
37
+ severity: text("severity"),
38
+ packageIdentifier: text("packageIdentifier"),
39
+ fixable: null,
40
+ remediateBy: text("remediateBy"),
41
+ labels: [],
42
+ createdAt: text("sourceCreatedAt") ?? (/* @__PURE__ */ new Date(0)).toISOString()
43
+ };
44
+ }
45
+ var VantaRules = class {
46
+ options;
47
+ #rules;
48
+ constructor(options) {
49
+ this.options = options;
50
+ this.#rules = options.rules ?? defaultVantaRules;
51
+ }
52
+ #boards(scope) {
53
+ return toBoardSource(this.options.boards).forProject(scope);
54
+ }
55
+ async ingest(input) {
56
+ if (!await this.options.projects.get({
57
+ orgId: input.orgId,
58
+ id: input.factoryProjectId
59
+ })) return {
60
+ status: "missing",
61
+ ingested: 0
62
+ };
63
+ await toBoardSource(this.options.boards).load(input);
64
+ const items = await this.options.storage.listShared({
65
+ orgId: input.orgId,
66
+ factoryProjectId: input.factoryProjectId
67
+ });
68
+ const itemsBySourceKey = new Map(items.filter((item) => item.externalSource?.integrationId === "vanta" && item.externalSource.type === "vulnerability").map((item) => [item.externalSource?.externalId, item]));
69
+ const statuses = [];
70
+ const active = new Set(input.vulnerabilities.map((vulnerability) => vulnerability.id));
71
+ for (const vulnerability of input.vulnerabilities) {
72
+ const relatedItem = itemsBySourceKey.get(vulnerability.id);
73
+ statuses.push(await this.#ingestAlert(input, vulnerability, relatedItem && structuredClone(relatedItem)));
74
+ }
75
+ for (const [sourceKey, item] of itemsBySourceKey) {
76
+ if (!sourceKey || active.has(sourceKey) || item.metadata?.state === "resolved") continue;
77
+ statuses.push(await this.#ingestAlert(input, resolvedFromCard(sourceKey, item), structuredClone(item)));
78
+ }
79
+ if (statuses.includes("committed")) return {
80
+ status: "committed",
81
+ ingested: statuses.length
82
+ };
83
+ if (statuses.includes("replayed")) return {
84
+ status: "replayed",
85
+ ingested: statuses.length
86
+ };
87
+ return {
88
+ status: "missing",
89
+ ingested: statuses.length
90
+ };
91
+ }
92
+ async #ingestAlert(input, alert, relatedItem, attempt = 1) {
93
+ const closed = alert.state === "resolved";
94
+ if (closed && !relatedItem) return "missing";
95
+ const ingressId = `vanta:${alert.id}:${alert.state}`;
96
+ const actor = {
97
+ type: "human",
98
+ id: input.userId
99
+ };
100
+ const event = closed ? "vulnerabilityClosed" : "vulnerabilityObserved";
101
+ const boards = this.#boards(input);
102
+ const context = {
103
+ tenant: {
104
+ orgId: input.orgId,
105
+ projectId: input.factoryProjectId
106
+ },
107
+ actor,
108
+ ingress: {
109
+ type: "vanta",
110
+ id: ingressId
111
+ },
112
+ cause: `vanta.${event}`,
113
+ causalChain: [],
114
+ configVersion: this.options.configVersion,
115
+ ...relatedItem ? {
116
+ item: {
117
+ id: relatedItem.id,
118
+ source: "vanta-vulnerability",
119
+ sourceKey: relatedItem.externalSource?.externalId ?? null,
120
+ parentWorkItemId: relatedItem.parentWorkItemId,
121
+ title: relatedItem.title,
122
+ url: relatedItem.externalSource?.url ?? null,
123
+ stages: relatedItem.stages,
124
+ workItem: relatedItem.workItem,
125
+ acceptedAt: relatedItem.acceptedAt,
126
+ metadata: relatedItem.metadata
127
+ },
128
+ board: boardForWorkItem(relatedItem),
129
+ itemRevision: relatedItem.revision,
130
+ ...withBoardClosure(boards, relatedItem),
131
+ ...rulePhaseField(boards, relatedItem)
132
+ } : {},
133
+ ...withIntakeTarget(boards),
134
+ event,
135
+ vulnerability: alert
136
+ };
137
+ const boardEvent = boardEventFor(context);
138
+ if (boardEvent) context.boardEvent = boardEvent;
139
+ const rule = this.#rules[event];
140
+ let decision = void 0;
141
+ let decisions = [];
142
+ let outcome = { status: "accepted" };
143
+ try {
144
+ decision = rule ? await rule(Object.freeze(context)) : void 0;
145
+ if (decision?.type === "reject") outcome = {
146
+ status: "rejected",
147
+ code: decision.code,
148
+ reason: decision.reason
149
+ };
150
+ else if (decision) decisions = validateFactoryRuleDecisions([decision]).map((entry) => {
151
+ assertFactoryDecisionTarget(entry, boards, relatedItem ? boardForWorkItem(relatedItem) : void 0);
152
+ return { ...entry };
153
+ });
154
+ } catch (error) {
155
+ outcome = {
156
+ status: "rejected",
157
+ code: "rule_error",
158
+ reason: error instanceof Error ? error.message.slice(0, 2e3) : "Factory Vanta rule failed."
159
+ };
160
+ }
161
+ if (!decision && outcome.status === "accepted") {
162
+ const routed = await routeEventDecision(context, this.options.storage, {
163
+ orgId: input.orgId,
164
+ factoryProjectId: input.factoryProjectId
165
+ });
166
+ if (routed) decisions = [{ ...routed }];
167
+ }
168
+ const committed = await this.options.storage.commitRuleEvaluation({
169
+ orgId: input.orgId,
170
+ factoryProjectId: input.factoryProjectId,
171
+ workItemId: relatedItem?.id ?? null,
172
+ ingress: {
173
+ identity: ingressId,
174
+ triggerType: `vanta.${event}`
175
+ },
176
+ configVersion: this.options.configVersion,
177
+ expectedRevision: relatedItem?.revision ?? null,
178
+ actor,
179
+ outcome,
180
+ decisions,
181
+ causalChain: [],
182
+ now: /* @__PURE__ */ new Date()
183
+ });
184
+ if (committed.status === "stale") {
185
+ if (attempt >= MAX_STALE_RULE_ATTEMPTS) throw new Error(`Factory Vanta rule evaluation for ${ingressId} kept losing revision races.`);
186
+ const fresh = relatedItem ? await this.options.storage.get({
187
+ orgId: input.orgId,
188
+ id: relatedItem.id
189
+ }) : null;
190
+ if (relatedItem && !fresh) return "missing";
191
+ return this.#ingestAlert(input, alert, fresh ?? void 0, attempt + 1);
192
+ }
193
+ return committed.status;
194
+ }
195
+ };
196
+ function attachVantaRules(context) {
197
+ if (!context.runtime) return void 0;
198
+ const rules = new VantaRules({
199
+ projects: context.storage.projects,
200
+ storage: context.runtime.workItems,
201
+ configVersion: context.runtime.configVersion,
202
+ boards: context.runtime.boards
203
+ });
204
+ return (input) => rules.ingest(input);
205
+ }
206
+ export { VantaRules, attachVantaRules, boardEventFor, vantaLabels };
207
+
208
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","names":[],"sources":["../../../src/integrations/vanta/rules.ts"],"sourcesContent":["import { closeReason } from '../../boards/board-events.js';\nimport type { BoardEventFacts } from '../../boards/board-events.js';\nimport { boardForWorkItem, rulePhaseField, withBoardClosure, withIntakeTarget } from '../../boards/index.js';\nimport type { BoardRegistry } from '../../boards/index.js';\nimport { toBoardSource } from '../../boards/project-boards.js';\nimport type { ProjectBoardSource } from '../../boards/project-boards.js';\nimport { routeEventDecision } from '../../rules/event-rules.js';\nimport type { FactoryVantaRuleContext, FactoryRuleDecision } from '../../rules/types.js';\nimport { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from '../../rules/validation.js';\nimport type { StoredBoardScope } from '../../storage/domains/boards/base.js';\nimport type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';\nimport type { Card, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { IntegrationContext } from '../base.js';\nimport { defaultVantaRules } from './default-rules.js';\nimport type { VantaEventRules } from './default-rules.js';\n\nconst MAX_STALE_RULE_ATTEMPTS = 3;\n\n/** Labels every Vanta card carries, so the Security intake route matches them like any `security`-labeled issue. */\nexport function vantaLabels(severity: string | null): string[] {\n return ['security', 'vanta', ...(severity ? [`severity:${severity.toLowerCase()}`] : [])];\n}\n\nexport type VantaVulnerabilityIngress = FactoryVantaRuleContext['vulnerability'];\n\nexport interface VantaRulesOptions {\n projects: Pick<FactoryProjectsStorage, 'get'>;\n storage: WorkItemsStorage;\n configVersion: string;\n boards: BoardRegistry | ProjectBoardSource;\n rules?: VantaEventRules;\n}\n\nexport interface VantaRulesIngress {\n orgId: string;\n userId: string;\n factoryProjectId: string;\n /** Every vulnerability Vanta currently lists as active. Open cards missing from it are closed. */\n vulnerabilities: VantaVulnerabilityIngress[];\n}\n\ntype IngressStatus = 'committed' | 'replayed' | 'missing';\n\n/** A first sighting of an active vulnerability creates its card; dropping off Vanta's active list closes it. */\nexport function boardEventFor(context: Pick<FactoryVantaRuleContext, 'event' | 'item'>): BoardEventFacts | undefined {\n if (context.event === 'vulnerabilityClosed') {\n return { type: 'work_item.closed', reason: closeReason(false) };\n }\n return context.item ? undefined : { type: 'work_item.created' };\n}\n\n/** The closing ingress for a card whose vulnerability Vanta stopped listing, rebuilt from the card. */\nfunction resolvedFromCard(sourceKey: string, item: Card): VantaVulnerabilityIngress {\n const metadata = item.metadata ?? {};\n const text = (key: string) => (typeof metadata[key] === 'string' ? (metadata[key] as string) : null);\n return {\n id: sourceKey,\n name: text('identifier') ?? sourceKey,\n title: item.title,\n description: null,\n url: item.externalSource?.url ?? null,\n state: 'resolved',\n severity: text('severity'),\n packageIdentifier: text('packageIdentifier'),\n fixable: null,\n remediateBy: text('remediateBy'),\n labels: [],\n createdAt: text('sourceCreatedAt') ?? new Date(0).toISOString(),\n };\n}\n\nexport class VantaRules {\n readonly #rules: VantaEventRules;\n\n constructor(private readonly options: VantaRulesOptions) {\n this.#rules = options.rules ?? defaultVantaRules;\n }\n\n #boards(scope: StoredBoardScope): BoardRegistry {\n return toBoardSource(this.options.boards).forProject(scope);\n }\n\n async ingest(input: VantaRulesIngress): Promise<{ status: IngressStatus; ingested: number }> {\n const project = await this.options.projects.get({ orgId: input.orgId, id: input.factoryProjectId });\n if (!project) return { status: 'missing', ingested: 0 };\n await toBoardSource(this.options.boards).load(input);\n\n const items = await this.options.storage.listShared({ orgId: input.orgId, factoryProjectId: input.factoryProjectId });\n const itemsBySourceKey = new Map(\n items\n .filter(item => item.externalSource?.integrationId === 'vanta' && item.externalSource.type === 'vulnerability')\n .map(item => [item.externalSource?.externalId, item]),\n );\n const statuses: IngressStatus[] = [];\n const active = new Set(input.vulnerabilities.map(vulnerability => vulnerability.id));\n for (const vulnerability of input.vulnerabilities) {\n const relatedItem = itemsBySourceKey.get(vulnerability.id);\n statuses.push(await this.#ingestAlert(input, vulnerability, relatedItem && structuredClone(relatedItem)));\n }\n for (const [sourceKey, item] of itemsBySourceKey) {\n if (!sourceKey || active.has(sourceKey) || item.metadata?.state === 'resolved') continue;\n statuses.push(await this.#ingestAlert(input, resolvedFromCard(sourceKey, item), structuredClone(item)));\n }\n if (statuses.includes('committed')) return { status: 'committed', ingested: statuses.length };\n if (statuses.includes('replayed')) return { status: 'replayed', ingested: statuses.length };\n return { status: 'missing', ingested: statuses.length };\n }\n\n async #ingestAlert(\n input: VantaRulesIngress,\n alert: VantaVulnerabilityIngress,\n relatedItem: Card | undefined,\n attempt = 1,\n ): Promise<IngressStatus> {\n const closed = alert.state === 'resolved';\n // A resolved vulnerability Factory never filed stays off the board.\n if (closed && !relatedItem) return 'missing';\n\n const ingressId = `vanta:${alert.id}:${alert.state}`;\n const actor = { type: 'human' as const, id: input.userId };\n const event = closed ? 'vulnerabilityClosed' : 'vulnerabilityObserved';\n const boards = this.#boards(input);\n const context: FactoryVantaRuleContext = {\n tenant: { orgId: input.orgId, projectId: input.factoryProjectId },\n actor,\n ingress: { type: 'vanta', id: ingressId },\n cause: `vanta.${event}`,\n causalChain: [],\n configVersion: this.options.configVersion,\n ...(relatedItem\n ? {\n item: {\n id: relatedItem.id,\n source: 'vanta-vulnerability',\n sourceKey: relatedItem.externalSource?.externalId ?? null,\n parentWorkItemId: relatedItem.parentWorkItemId,\n title: relatedItem.title,\n url: relatedItem.externalSource?.url ?? null,\n stages: relatedItem.stages,\n workItem: relatedItem.workItem,\n acceptedAt: relatedItem.acceptedAt,\n metadata: relatedItem.metadata,\n },\n board: boardForWorkItem(relatedItem),\n itemRevision: relatedItem.revision,\n ...withBoardClosure(boards, relatedItem),\n ...rulePhaseField(boards, relatedItem),\n }\n : {}),\n ...withIntakeTarget(boards),\n event,\n vulnerability: alert,\n };\n const boardEvent = boardEventFor(context);\n if (boardEvent) context.boardEvent = boardEvent;\n\n const rule = this.#rules[event];\n let decision: FactoryRuleDecision | void = undefined;\n let decisions: Record<string, unknown>[] = [];\n let outcome: { status: 'accepted' | 'rejected'; code?: string; reason?: string } = { status: 'accepted' };\n try {\n decision = rule ? await rule(Object.freeze(context)) : undefined;\n if (decision?.type === 'reject') {\n outcome = { status: 'rejected', code: decision.code, reason: decision.reason };\n } else if (decision) {\n decisions = validateFactoryRuleDecisions([decision]).map(entry => {\n assertFactoryDecisionTarget(entry, boards, relatedItem ? boardForWorkItem(relatedItem) : undefined);\n return { ...entry };\n });\n }\n } catch (error) {\n outcome = {\n status: 'rejected',\n code: 'rule_error',\n reason: error instanceof Error ? error.message.slice(0, 2_000) : 'Factory Vanta rule failed.',\n };\n }\n if (!decision && outcome.status === 'accepted') {\n const routed = await routeEventDecision(context, this.options.storage, {\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n if (routed) decisions = [{ ...routed }];\n }\n\n const committed = await this.options.storage.commitRuleEvaluation({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n workItemId: relatedItem?.id ?? null,\n ingress: { identity: ingressId, triggerType: `vanta.${event}` },\n configVersion: this.options.configVersion,\n expectedRevision: relatedItem?.revision ?? null,\n actor,\n outcome,\n decisions,\n causalChain: [],\n now: new Date(),\n });\n if (committed.status === 'stale') {\n if (attempt >= MAX_STALE_RULE_ATTEMPTS) {\n throw new Error(`Factory Vanta rule evaluation for ${ingressId} kept losing revision races.`);\n }\n const fresh = relatedItem ? await this.options.storage.get({ orgId: input.orgId, id: relatedItem.id }) : null;\n if (relatedItem && !fresh) return 'missing';\n return this.#ingestAlert(input, alert, fresh ?? undefined, attempt + 1);\n }\n return committed.status;\n }\n}\n\nexport function attachVantaRules(\n context: IntegrationContext,\n): ((input: VantaRulesIngress) => Promise<unknown>) | undefined {\n if (!context.runtime) return undefined;\n const rules = new VantaRules({\n projects: context.storage.projects,\n storage: context.runtime.workItems,\n configVersion: context.runtime.configVersion,\n boards: context.runtime.boards,\n });\n return input => rules.ingest(input);\n}\n"],"mappings":";;;;;;;;AAgBA,MAAM,0BAA0B;;AAGhC,SAAgB,YAAY,UAAmC;CAC7D,OAAO;EAAC;EAAY;EAAS,GAAI,WAAW,CAAC,YAAY,SAAS,YAAY,GAAG,IAAI,CAAC;CAAE;AAC1F;;AAuBA,SAAgB,cAAc,SAAuF;CACnH,IAAI,QAAQ,UAAU,uBACpB,OAAO;EAAE,MAAM;EAAoB,QAAQ,YAAY,KAAK;CAAE;CAEhE,OAAO,QAAQ,OAAO,KAAA,IAAY,EAAE,MAAM,oBAAoB;AAChE;;AAGA,SAAS,iBAAiB,WAAmB,MAAuC;CAClF,MAAM,WAAW,KAAK,YAAY,CAAC;CACnC,MAAM,QAAQ,QAAiB,OAAO,SAAS,SAAS,WAAY,SAAS,OAAkB;CAC/F,OAAO;EACL,IAAI;EACJ,MAAM,KAAK,YAAY,KAAK;EAC5B,OAAO,KAAK;EACZ,aAAa;EACb,KAAK,KAAK,gBAAgB,OAAO;EACjC,OAAO;EACP,UAAU,K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W,yBACb,MAAM,IAAI,MAAM,qCAAqC,UAAU,6BAA6B;GAE9F,MAAM,QAAQ,cAAc,MAAM,KAAK,QAAQ,QAAQ,IAAI;IAAE,OAAO,MAAM;IAAO,IAAI,YAAY;GAAG,CAAC,IAAI;GACzG,IAAI,eAAe,CAAC,OAAO,OAAO;GAClC,OAAO,KAAK,aAAa,OAAO,OAAO,SAAS,KAAA,GAAW,UAAU,CAAC;EACxE;EACA,OAAO,UAAU;CACnB;AACF;AAEA,SAAgB,iBACd,SAC8D;CAC9D,IAAI,CAAC,QAAQ,SAAS,OAAO,KAAA;CAC7B,MAAM,QAAQ,IAAI,WAAW;EAC3B,UAAU,QAAQ,QAAQ;EAC1B,SAAS,QAAQ,QAAQ;EACzB,eAAe,QAAQ,QAAQ;EAC/B,QAAQ,QAAQ,QAAQ;CAC1B,CAAC;CACD,QAAO,UAAS,MAAM,OAAO,KAAK;AACpC"}
@@ -0,0 +1,36 @@
1
+ import type { IssueReconcileSummary } from '../issue-reconciler.js';
2
+ import type { VantaRulesIngress, VantaVulnerabilityIngress } from './rules.js';
3
+ export declare const VANTA_VULNERABILITIES_SOURCE_ID = "vanta:vulnerabilities";
4
+ export declare const DEFAULT_VANTA_SYNC_INTERVAL_MS: number;
5
+ /** The subset of Vanta's `GET /v1/vulnerabilities` item Factory reads. */
6
+ export interface VantaVulnerability {
7
+ id: string;
8
+ name: string;
9
+ description?: string | null;
10
+ packageIdentifier?: string | null;
11
+ severity?: string | null;
12
+ isFixable?: boolean | null;
13
+ remediateByDate?: string | null;
14
+ firstDetectedDate?: string | null;
15
+ externalURL?: string | null;
16
+ }
17
+ /** Lists every active Vanta vulnerability. Throws when Vanta can't be read. */
18
+ export type VantaVulnerabilityLister = () => Promise<VantaVulnerability[]>;
19
+ export declare function toVantaIngress(vulnerability: VantaVulnerability): VantaVulnerabilityIngress;
20
+ /**
21
+ * Reads Vanta's active vulnerabilities once and hands them to every Factory project that takes
22
+ * Vanta intake. A project takes it when its org has Vanta intake enabled and either binds the
23
+ * vulnerabilities source to it or binds it to no project at all.
24
+ */
25
+ export declare function createVantaSync(options: {
26
+ listVulnerabilities: VantaVulnerabilityLister;
27
+ listProjects: () => Promise<ReadonlyArray<{
28
+ orgId: string;
29
+ id: string;
30
+ }>>;
31
+ intakeEnabled: (orgId: string) => Promise<boolean>;
32
+ boundProjectIds: (orgId: string) => Promise<string[]>;
33
+ ingest: (input: VantaRulesIngress) => Promise<unknown>;
34
+ userId: string;
35
+ }): () => Promise<IssueReconcileSummary>;
36
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/integrations/vanta/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE/E,eAAO,MAAM,+BAA+B,0BAA0B,CAAC;AACvE,eAAO,MAAM,8BAA8B,QAAc,CAAC;AAE1D,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,+EAA+E;AAC/E,MAAM,MAAM,wBAAwB,GAAG,MAAM,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;AAE3E,wBAAgB,cAAc,CA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