@mastra/factory 0.29.0-alpha.5 → 0.29.0-alpha.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.
- package/README.md +55 -31
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +7 -1
- package/dist/boards/semantics.js.map +1 -1
- package/dist/factory.d.ts +10 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +98 -41
- package/dist/factory.js.map +1 -1
- package/dist/integrations/github/issue-intake.d.ts +15 -0
- package/dist/integrations/github/issue-intake.d.ts.map +1 -0
- package/dist/integrations/github/issue-intake.js +50 -0
- package/dist/integrations/github/issue-intake.js.map +1 -0
- package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +10 -1
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +2 -0
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +3 -0
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts +43 -1
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js +82 -7
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/connect/session-tools.d.ts +12 -0
- package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -1
- package/dist/integrations/platform/connect/session-tools.js +28 -10
- package/dist/integrations/platform/connect/session-tools.js.map +1 -1
- package/dist/integrations/platform/vanta/integration.d.ts.map +1 -1
- package/dist/integrations/platform/vanta/integration.js +3 -3
- package/dist/integrations/platform/vanta/integration.js.map +1 -1
- package/dist/integrations/vanta/sync.d.ts +9 -0
- package/dist/integrations/vanta/sync.d.ts.map +1 -1
- package/dist/integrations/vanta/sync.js +10 -1
- package/dist/integrations/vanta/sync.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +5 -5
- package/dist/routes/board-snapshot.d.ts.map +1 -1
- package/dist/routes/board-snapshot.js +10 -14
- package/dist/routes/board-snapshot.js.map +1 -1
- package/dist/routes/config.d.ts +11 -2
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +242 -75
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +43 -14
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +27 -17
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/custom-endpoint-url.d.ts +8 -0
- package/dist/routes/custom-endpoint-url.d.ts.map +1 -0
- package/dist/routes/custom-endpoint-url.js +45 -0
- package/dist/routes/custom-endpoint-url.js.map +1 -0
- package/dist/routes/custom-provider-source.d.ts +24 -8
- package/dist/routes/custom-provider-source.d.ts.map +1 -1
- package/dist/routes/custom-provider-source.js +93 -43
- package/dist/routes/custom-provider-source.js.map +1 -1
- package/dist/routes/intake.d.ts +6 -0
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +20 -0
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/project-sessions.d.ts +15 -3
- package/dist/routes/project-sessions.d.ts.map +1 -1
- package/dist/routes/project-sessions.js +56 -14
- package/dist/routes/project-sessions.js.map +1 -1
- package/dist/routes/projects.d.ts +6 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +19 -3
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/provider-credentials.d.ts +10 -1
- package/dist/routes/provider-credentials.d.ts.map +1 -1
- package/dist/routes/provider-credentials.js +13 -16
- package/dist/routes/provider-credentials.js.map +1 -1
- package/dist/routes/session-rows.d.ts +1 -1
- package/dist/routes/session-rows.d.ts.map +1 -1
- package/dist/routes/session-rows.js +38 -42
- package/dist/routes/session-rows.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +4 -4
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +3 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +20 -7
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/tenant-credentials.d.ts.map +1 -1
- package/dist/routes/tenant-credentials.js +4 -4
- package/dist/routes/tenant-credentials.js.map +1 -1
- package/dist/routes/work-items.d.ts +9 -3
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +39 -16
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/binding-context.d.ts +5 -0
- package/dist/rules/binding-context.d.ts.map +1 -1
- package/dist/rules/binding-context.js +51 -5
- package/dist/rules/binding-context.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +2 -1
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +2 -7
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/sandbox/session-retirement.d.ts +6 -0
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +17 -0
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +2 -1
- package/dist/session/factory-session.js.map +1 -1
- package/dist/session/live-sessions.d.ts +6 -1
- package/dist/session/live-sessions.d.ts.map +1 -1
- package/dist/session/live-sessions.js +4 -0
- package/dist/session/live-sessions.js.map +1 -1
- package/dist/session/run-audit.d.ts +1 -1
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/session-row-status.d.ts +3 -3
- package/dist/session/session-row-status.js +4 -4
- package/dist/session/session-row-status.js.map +1 -1
- package/dist/session/session-row-view.d.ts +3 -4
- package/dist/session/session-row-view.d.ts.map +1 -1
- package/dist/session/session-row-view.js +14 -21
- package/dist/session/session-row-view.js.map +1 -1
- package/dist/session/session-rows.d.ts +22 -8
- package/dist/session/session-rows.d.ts.map +1 -1
- package/dist/session/session-rows.js +158 -83
- package/dist/session/session-rows.js.map +1 -1
- package/dist/session/session-unloader.d.ts +101 -0
- package/dist/session/session-unloader.d.ts.map +1 -0
- package/dist/session/session-unloader.js +278 -0
- package/dist/session/session-unloader.js.map +1 -0
- package/dist/session/work-item-repository.d.ts +5 -1
- package/dist/session/work-item-repository.d.ts.map +1 -1
- package/dist/session/work-item-repository.js +39 -15
- package/dist/session/work-item-repository.js.map +1 -1
- package/dist/session-list-changes.d.ts +9 -0
- package/dist/session-list-changes.d.ts.map +1 -0
- package/dist/session-list-changes.js +54 -0
- package/dist/session-list-changes.js.map +1 -0
- package/dist/storage/announced-lists.d.ts +14 -0
- package/dist/storage/announced-lists.d.ts.map +1 -0
- package/dist/storage/announced-lists.js +78 -0
- package/dist/storage/announced-lists.js.map +1 -0
- package/dist/storage/domains/boards/base.d.ts +1 -1
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +27 -9
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/custom-providers/base.d.ts +62 -19
- package/dist/storage/domains/custom-providers/base.d.ts.map +1 -1
- package/dist/storage/domains/custom-providers/base.js +131 -100
- package/dist/storage/domains/custom-providers/base.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +25 -7
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +83 -19
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +8 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +110 -64
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +4 -0
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +8 -5
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +9 -1
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +43 -11
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/tools/read-tools.d.ts +9 -2
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +57 -12
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/session-tools.d.ts +0 -13
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +127 -336
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +91 -23
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-items/card-reference.d.ts +21 -0
- package/dist/work-items/card-reference.d.ts.map +1 -0
- package/dist/work-items/card-reference.js +58 -0
- package/dist/work-items/card-reference.js.map +1 -0
- package/package.json +8 -8
- package/dist/storage/probed-list.d.ts +0 -11
- package/dist/storage/probed-list.d.ts.map +0 -1
- package/dist/storage/probed-list.js +0 -52
- package/dist/storage/probed-list.js.map +0 -1
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* Platform's own rule for these providers: a signed-in organization member
|
|
13
13
|
* (org:write parity with Linear), not an organization admin.
|
|
14
14
|
*/
|
|
15
|
+
import { RequestContext } from '@mastra/core/request-context';
|
|
15
16
|
import type { ApiRoute } from '@mastra/core/server';
|
|
16
17
|
import type { RouteAuth } from '../../../routes/route.js';
|
|
17
18
|
import type { PlatformApiClient } from '../api-client.js';
|
|
@@ -35,8 +36,49 @@ export interface BuildPlatformConnectRoutesOptions {
|
|
|
35
36
|
export interface ConnectToolsSource {
|
|
36
37
|
client: PlatformApiClient;
|
|
37
38
|
projectId: string;
|
|
39
|
+
/**
|
|
40
|
+
* `default`: sessions get Factory's own Connect tools for this project.
|
|
41
|
+
* `custom`: the Factory's `tools` option sets session tools, and may or may
|
|
42
|
+
* not include these connections.
|
|
43
|
+
*/
|
|
44
|
+
toolsSource: 'default' | 'custom';
|
|
45
|
+
/**
|
|
46
|
+
* Resolves the tools a session started by this request would get from
|
|
47
|
+
* `toolsSource`: the project's Connect tools before Factory's filters for
|
|
48
|
+
* `default`, or what the `tools` option returns for `custom`. Rejects when
|
|
49
|
+
* they can't be resolved.
|
|
50
|
+
*/
|
|
51
|
+
resolveTools: (args: {
|
|
52
|
+
requestContext: RequestContext;
|
|
53
|
+
}) => Promise<Record<string, unknown>>;
|
|
38
54
|
}
|
|
39
|
-
|
|
55
|
+
/** One tool as Settings › Tools lists it. */
|
|
56
|
+
export interface ListedConnectTool {
|
|
57
|
+
name: string;
|
|
58
|
+
description: string | null;
|
|
59
|
+
/** The tool pauses the run until someone approves each call. */
|
|
60
|
+
requiresApproval: boolean;
|
|
61
|
+
/** Factory leaves this default Connect tool out of sessions: its name says it deletes or archives. */
|
|
62
|
+
excluded?: 'destructive';
|
|
63
|
+
}
|
|
64
|
+
/** The one piece of setup the Factory lacks to list its project's connections. */
|
|
65
|
+
export type ConnectToolsSetupMissing = 'no_credentials' | 'no_project_id';
|
|
66
|
+
/**
|
|
67
|
+
* Lists the Platform project's connections for Settings › Tools whenever the
|
|
68
|
+
* Factory has Platform credentials and `MASTRA_PROJECT_ID`, whatever its
|
|
69
|
+
* `tools` option. `toolsSource` tells the panel whether sessions get these
|
|
70
|
+
* connections by default or only through the Factory's own `tools` code.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildConnectToolsRoute(auth: RouteAuth, source: ConnectToolsSource | {
|
|
73
|
+
missing: ConnectToolsSetupMissing;
|
|
74
|
+
}): ApiRoute;
|
|
75
|
+
/**
|
|
76
|
+
* Lists the tools sessions get from the Connect tools source, as the signed-in
|
|
77
|
+
* caller's session would resolve them, for the tool lists in Settings › Tools.
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildConnectToolListRoute(auth: RouteAuth, source: ConnectToolsSource | {
|
|
80
|
+
missing: ConnectToolsSetupMissing;
|
|
81
|
+
}): ApiRoute;
|
|
40
82
|
/**
|
|
41
83
|
* Build the `/web/integrations/platform/*` routes. Callers only mount these
|
|
42
84
|
* when Platform machine credentials are configured.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/connect/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAKpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/connect/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAKpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAM1D,MAAM,WAAW,uBAAuB;IACtC,6DAA6D;IAC7D,aAAa,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,wBAAwB,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAK9E,CAAC;AAgCF,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,WAAW,EAAE,SAAS,GAAG,QAAQ,CAAC;IAClC;;;;;OAKG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE;QAAE,cAAc,EAAE,cAAc,CAAA;KAAE,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC9F;AAED,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,gEAAgE;IAChE,gBAAgB,EAAE,OAAO,CAAC;IAC1B,sGAAsG;IACtG,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,kFAAkF;AAClF,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAiD1E;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,kBAAkB,GAAG;IAAE,OAAO,EAAE,wBAAwB,CAAA;CAAE,GACjE,QAAQ,CAoDV;AAkBD;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,kBAAkB,GAAG;IAAE,OAAO,EAAE,wBAAwB,CAAA;CAAE,GACjE,QAAQ,CAmCV;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,iCAAiC,GAAG,QAAQ,EAAE,CAgFjG"}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { loose } from "../../../routes/route.js";
|
|
2
2
|
import { PlatformApiError } from "../api-client.js";
|
|
3
|
-
import { offersSessionTools } from "./session-tools.js";
|
|
3
|
+
import { connectToolExclusion, offersSessionTools } from "./session-tools.js";
|
|
4
|
+
import { RequestContext } from "@mastra/core/request-context";
|
|
4
5
|
import { registerApiRoute } from "@mastra/core/server";
|
|
5
6
|
// src/integrations/platform/connect/routes.ts
|
|
6
7
|
/**
|
|
8
|
+
* Mastra `apiRoutes` that let the Factory SPA connect and reconnect
|
|
9
|
+
* Platform-managed provider accounts without leaving Factory, and list the
|
|
10
|
+
* Platform project connections whose Mastra Connect tools sessions get.
|
|
11
|
+
*
|
|
12
|
+
* The browser cannot talk to the integrations service itself — it has no
|
|
13
|
+
* Platform session — so these routes mint Nango connect/reconnect sessions
|
|
14
|
+
* server-side with the deploy's machine credentials
|
|
15
|
+
* (`MASTRA_PLATFORM_ACCESS_TOKEN`/`MASTRA_PLATFORM_SECRET_KEY`) and hand the
|
|
16
|
+
* short-lived session token back to the SPA, which drives the provider's
|
|
17
|
+
* OAuth popup headlessly via `@nangohq/frontend`. Gating mirrors the
|
|
18
|
+
* Platform's own rule for these providers: a signed-in organization member
|
|
19
|
+
* (org:write parity with Linear), not an organization admin.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
7
22
|
* Providers the Factory SPA may connect through these routes. Keys are the
|
|
8
23
|
* SPA-facing provider slugs; `integrationId` is the Platform catalog id used
|
|
9
24
|
* for new connect sessions. Provider-specific PRs extend this registry when
|
|
@@ -27,6 +42,10 @@ const PLATFORM_CONNECT_PROVIDERS = {
|
|
|
27
42
|
connectionIntegrationIds: ["vanta"]
|
|
28
43
|
}
|
|
29
44
|
};
|
|
45
|
+
const MISSING_SETUP_MESSAGES = {
|
|
46
|
+
no_credentials: "This Factory has no Mastra Platform credentials. Set MASTRA_PLATFORM_SECRET_KEY or MASTRA_PLATFORM_ACCESS_TOKEN.",
|
|
47
|
+
no_project_id: "This Factory has Mastra Platform credentials but no MASTRA_PROJECT_ID."
|
|
48
|
+
};
|
|
30
49
|
async function resolveOrgTenant(c, auth) {
|
|
31
50
|
if (!auth.enabled()) return { response: c.json({
|
|
32
51
|
error: "auth_disabled",
|
|
@@ -64,21 +83,28 @@ function platformError(c, err) {
|
|
|
64
83
|
message: err instanceof Error ? err.message : String(err)
|
|
65
84
|
}, 502);
|
|
66
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Lists the Platform project's connections for Settings › Tools whenever the
|
|
88
|
+
* Factory has Platform credentials and `MASTRA_PROJECT_ID`, whatever its
|
|
89
|
+
* `tools` option. `toolsSource` tells the panel whether sessions get these
|
|
90
|
+
* connections by default or only through the Factory's own `tools` code.
|
|
91
|
+
*/
|
|
67
92
|
function buildConnectToolsRoute(auth, source) {
|
|
68
93
|
return registerApiRoute("/web/integrations/platform/connect-tools", {
|
|
69
94
|
method: "GET",
|
|
70
95
|
requiresAuth: false,
|
|
71
96
|
handler: async (rawContext) => {
|
|
72
97
|
const c = loose(rawContext);
|
|
73
|
-
if (!source) return c.json({
|
|
74
|
-
error: "connect_tools_off",
|
|
75
|
-
message: "This Factory's sessions don't get Mastra Connect tools."
|
|
76
|
-
}, 404);
|
|
77
98
|
if (auth.enabled()) {
|
|
78
99
|
await auth.ensureUser(c);
|
|
79
100
|
if (!auth.tenant(c)) return c.json({ error: "unauthorized" }, 401);
|
|
80
101
|
}
|
|
81
|
-
|
|
102
|
+
if ("missing" in source) return c.json({
|
|
103
|
+
error: "connect_tools_off",
|
|
104
|
+
reason: source.missing,
|
|
105
|
+
message: MISSING_SETUP_MESSAGES[source.missing]
|
|
106
|
+
}, 404);
|
|
107
|
+
const { client, projectId, toolsSource } = source;
|
|
82
108
|
try {
|
|
83
109
|
const [listed, catalog] = await Promise.all([client.request("GET", `/v2/projects/${encodeURIComponent(projectId)}/connections`), client.request("GET", "/v2/integrations").catch((error) => {
|
|
84
110
|
console.warn(`MastraFactory: listing connections without provider names; the Platform catalog failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -98,6 +124,7 @@ function buildConnectToolsRoute(auth, source) {
|
|
|
98
124
|
}).sort((a, b) => a.providerName.localeCompare(b.providerName));
|
|
99
125
|
return c.json({
|
|
100
126
|
projectId,
|
|
127
|
+
toolsSource,
|
|
101
128
|
connections
|
|
102
129
|
});
|
|
103
130
|
} catch (err) {
|
|
@@ -106,6 +133,54 @@ function buildConnectToolsRoute(auth, source) {
|
|
|
106
133
|
}
|
|
107
134
|
});
|
|
108
135
|
}
|
|
136
|
+
function listedTool(name, tool, toolsSource) {
|
|
137
|
+
const exclusion = toolsSource === "default" ? connectToolExclusion(name) : void 0;
|
|
138
|
+
if (exclusion === "source_control") return [];
|
|
139
|
+
const { description, requireApproval } = tool ?? {};
|
|
140
|
+
return [{
|
|
141
|
+
name,
|
|
142
|
+
description: typeof description === "string" && description.trim() ? description.trim() : null,
|
|
143
|
+
requiresApproval: requireApproval === true,
|
|
144
|
+
...exclusion ? { excluded: exclusion } : {}
|
|
145
|
+
}];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Lists the tools sessions get from the Connect tools source, as the signed-in
|
|
149
|
+
* caller's session would resolve them, for the tool lists in Settings › Tools.
|
|
150
|
+
*/
|
|
151
|
+
function buildConnectToolListRoute(auth, source) {
|
|
152
|
+
return registerApiRoute("/web/integrations/platform/connect-tools/tools", {
|
|
153
|
+
method: "GET",
|
|
154
|
+
requiresAuth: false,
|
|
155
|
+
handler: async (rawContext) => {
|
|
156
|
+
const c = loose(rawContext);
|
|
157
|
+
if (auth.enabled()) {
|
|
158
|
+
await auth.ensureUser(c);
|
|
159
|
+
if (!auth.tenant(c)) return c.json({ error: "unauthorized" }, 401);
|
|
160
|
+
}
|
|
161
|
+
if ("missing" in source) return c.json({
|
|
162
|
+
error: "connect_tools_off",
|
|
163
|
+
reason: source.missing,
|
|
164
|
+
message: MISSING_SETUP_MESSAGES[source.missing]
|
|
165
|
+
}, 404);
|
|
166
|
+
const { toolsSource, resolveTools } = source;
|
|
167
|
+
const requestContext = c.get("requestContext") ?? new RequestContext();
|
|
168
|
+
try {
|
|
169
|
+
const resolved = await resolveTools({ requestContext });
|
|
170
|
+
const tools = Object.entries(resolved).flatMap(([name, tool]) => listedTool(name, tool, toolsSource)).sort((a, b) => a.name.localeCompare(b.name));
|
|
171
|
+
return c.json({
|
|
172
|
+
toolsSource,
|
|
173
|
+
tools
|
|
174
|
+
});
|
|
175
|
+
} catch (err) {
|
|
176
|
+
return c.json({
|
|
177
|
+
error: "tools_unavailable",
|
|
178
|
+
message: `Couldn't resolve the tools: ${err instanceof Error ? err.message : String(err)}`
|
|
179
|
+
}, 502);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
109
184
|
/**
|
|
110
185
|
* Build the `/web/integrations/platform/*` routes. Callers only mount these
|
|
111
186
|
* when Platform machine credentials are configured.
|
|
@@ -171,6 +246,6 @@ function buildPlatformConnectRoutes(options) {
|
|
|
171
246
|
})
|
|
172
247
|
];
|
|
173
248
|
}
|
|
174
|
-
export { PLATFORM_CONNECT_PROVIDERS, buildConnectToolsRoute, buildPlatformConnectRoutes };
|
|
249
|
+
export { PLATFORM_CONNECT_PROVIDERS, buildConnectToolListRoute, buildConnectToolsRoute, buildPlatformConnectRoutes };
|
|
175
250
|
|
|
176
251
|
//# sourceMappingURL=routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","names":[],"sources":["../../../../src/integrations/platform/connect/routes.ts"],"sourcesContent":["/**\n * Mastra `apiRoutes` that let the Factory SPA connect and reconnect\n * Platform-managed provider accounts without leaving Factory, and list the\n * Platform project connections whose Mastra Connect tools sessions get.\n *\n * The browser cannot talk to the integrations service itself — it has no\n * Platform session — so these routes mint Nango connect/reconnect sessions\n * server-side with the deploy's machine credentials\n * (`MASTRA_PLATFORM_ACCESS_TOKEN`/`MASTRA_PLATFORM_SECRET_KEY`) and hand the\n * short-lived session token back to the SPA, which drives the provider's\n * OAuth popup headlessly via `@nangohq/frontend`. Gating mirrors the\n * Platform's own rule for these providers: a signed-in organization member\n * (org:write parity with Linear), not an organization admin.\n */\n\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\n\nimport { loose } from '../../../routes/route.js';\nimport type { RouteAuth } from '../../../routes/route.js';\nimport type { PlatformApiClient} from '../api-client.js';\nimport { PlatformApiError } from '../api-client.js';\nimport { offersSessionTools } from './session-tools.js';\n\ntype RouteContext = Context;\n\nexport interface PlatformConnectProvider {\n /** Platform integration id used to mint connect sessions. */\n integrationId: string;\n /** Connection `integrationId` variants that belong to this provider. */\n connectionIntegrationIds: readonly string[];\n}\n\n/**\n * Providers the Factory SPA may connect through these routes. Keys are the\n * SPA-facing provider slugs; `integrationId` is the Platform catalog id used\n * for new connect sessions. Provider-specific PRs extend this registry when\n * their Factory integrations are available.\n */\nexport const PLATFORM_CONNECT_PROVIDERS: Record<string, PlatformConnectProvider> = {\n jira: { integrationId: 'jira', connectionIntegrationIds: ['jira'] },\n 'incident-io': { integrationId: 'incident-io', connectionIntegrationIds: ['incident-io'] },\n gitlab: { integrationId: 'gitlab', connectionIntegrationIds: ['gitlab'] },\n vanta: { integrationId: 'vanta', connectionIntegrationIds: ['vanta'] },\n};\n\ninterface PlatformConnectionRow {\n id: string;\n integrationId: string;\n status: 'active' | 'needs_reauth';\n accountLabel: string | null;\n displayName?: string | null;\n connectedAt?: string;\n}\n\ninterface PlatformSessionResponse {\n connectionId: string;\n integrationId: string;\n connectUrl: string;\n sessionToken: string;\n expiresAt: string;\n}\n\ninterface ProjectConnectionRow {\n id: string;\n integrationId: string;\n status: string;\n accountLabel?: string | null;\n}\n\ninterface CatalogEntry {\n id: string;\n displayName?: string | null;\n logoUrl?: string | null;\n}\n\nexport interface BuildPlatformConnectRoutesOptions {\n auth: RouteAuth;\n client: PlatformApiClient;\n}\n\nexport interface ConnectToolsSource {\n client: PlatformApiClient;\n projectId: string;\n}\n\nasync function resolveOrgTenant(\n c: RouteContext,\n auth: RouteAuth,\n): Promise<{ tenant: { orgId: string; userId: string } } | { response: Response }> {\n if (!auth.enabled()) {\n return { response: c.json({ error: 'auth_disabled', message: 'Factory auth is not enabled.' }, 403) };\n }\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) return { response: c.json({ error: 'unauthorized' }, 401) };\n if (!tenant.orgId) {\n return {\n response: c.json(\n {\n error: 'organization_required',\n message: 'Provider connections require an organization. Personal accounts cannot connect providers.',\n },\n 403,\n ),\n };\n }\n return { tenant: { orgId: tenant.orgId, userId: tenant.userId } };\n}\n\nfunction providerFromParam(c: RouteContext): PlatformConnectProvider | null {\n const provider = c.req.param('provider');\n return provider ? (PLATFORM_CONNECT_PROVIDERS[provider] ?? null) : null;\n}\n\nfunction platformError(c: RouteContext, err: unknown) {\n if (err instanceof PlatformApiError) {\n if (err.status === 409) {\n return c.json({ error: 'session_pending', message: err.message }, 409);\n }\n if (err.status === 403) {\n return c.json({ error: 'platform_forbidden', message: err.message }, 403);\n }\n }\n return c.json({ error: 'platform_request_failed', message: err instanceof Error ? err.message : String(err) }, 502);\n}\n\nexport function buildConnectToolsRoute(auth: RouteAuth, source: ConnectToolsSource | undefined): ApiRoute {\n return registerApiRoute('/web/integrations/platform/connect-tools', {\n method: 'GET',\n requiresAuth: false,\n handler: async rawContext => {\n const c = loose(rawContext);\n if (!source) {\n return c.json(\n { error: 'connect_tools_off', message: \"This Factory's sessions don't get Mastra Connect tools.\" },\n 404,\n );\n }\n if (auth.enabled()) {\n await auth.ensureUser(c);\n if (!auth.tenant(c)) return c.json({ error: 'unauthorized' }, 401);\n }\n const { client, projectId } = source;\n try {\n const [listed, catalog] = await Promise.all([\n client.request<{ connections: ProjectConnectionRow[] }>(\n 'GET',\n `/v2/projects/${encodeURIComponent(projectId)}/connections`,\n ),\n client.request<{ integrations: CatalogEntry[] }>('GET', '/v2/integrations').catch((error: unknown) => {\n console.warn(\n `MastraFactory: listing connections without provider names; the Platform catalog failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n return { integrations: [] };\n }),\n ]);\n const entries = new Map(catalog.integrations.map(entry => [entry.id, entry]));\n const connections = listed.connections\n .filter(connection => offersSessionTools(connection.integrationId))\n .map(connection => {\n const entry = entries.get(connection.integrationId);\n return {\n id: connection.id,\n integrationId: connection.integrationId,\n providerName: entry?.displayName ?? connection.integrationId,\n logoUrl: entry?.logoUrl ?? null,\n accountLabel: connection.accountLabel ?? null,\n status: connection.status,\n };\n })\n .sort((a, b) => a.providerName.localeCompare(b.providerName));\n return c.json({ projectId, connections });\n } catch (err) {\n return platformError(c, err);\n }\n },\n });\n}\n\n/**\n * Build the `/web/integrations/platform/*` routes. Callers only mount these\n * when Platform machine credentials are configured.\n */\nexport function buildPlatformConnectRoutes(options: BuildPlatformConnectRoutesOptions): ApiRoute[] {\n const { auth, client } = options;\n\n return [\n registerApiRoute('/web/integrations/platform/:provider/connections', {\n method: 'GET',\n requiresAuth: false,\n handler: async rawContext => {\n const c = loose(rawContext);\n const provider = providerFromParam(c);\n if (!provider) return c.json({ error: 'unknown_provider' }, 404);\n const resolved = await resolveOrgTenant(c, auth);\n if ('response' in resolved) return resolved.response;\n try {\n const result = await client.request<{ connections: PlatformConnectionRow[] }>('GET', '/v2/connections');\n const connections = result.connections.filter(connection =>\n provider.connectionIntegrationIds.includes(connection.integrationId),\n );\n return c.json({ connections });\n } catch (err) {\n return platformError(c, err);\n }\n },\n }),\n registerApiRoute('/web/integrations/platform/:provider/connect-session', {\n method: 'POST',\n requiresAuth: false,\n handler: async rawContext => {\n const c = loose(rawContext);\n const provider = providerFromParam(c);\n if (!provider) return c.json({ error: 'unknown_provider' }, 404);\n const resolved = await resolveOrgTenant(c, auth);\n if ('response' in resolved) return resolved.response;\n try {\n const session = await client.request<PlatformSessionResponse>(\n 'POST',\n `/v2/integrations/${encodeURIComponent(provider.integrationId)}/connect-sessions`,\n {},\n );\n c.header('Cache-Control', 'no-store');\n return c.json(session, 201);\n } catch (err) {\n return platformError(c, err);\n }\n },\n }),\n registerApiRoute('/web/integrations/platform/:provider/connections/:connectionId/reconnect-session', {\n method: 'POST',\n requiresAuth: false,\n handler: async rawContext => {\n const c = loose(rawContext);\n const provider = providerFromParam(c);\n if (!provider) return c.json({ error: 'unknown_provider' }, 404);\n const resolved = await resolveOrgTenant(c, auth);\n if ('response' in resolved) return resolved.response;\n const connectionId = c.req.param('connectionId');\n if (!connectionId) return c.json({ error: 'connection_required' }, 400);\n try {\n // Confirm the connection belongs to this provider before minting so\n // one provider's page cannot reconnect a different provider's\n // connection through this route family.\n const listed = await client.request<{ connections: PlatformConnectionRow[] }>('GET', '/v2/connections');\n const connection = listed.connections.find(\n candidate =>\n candidate.id === connectionId && provider.connectionIntegrationIds.includes(candidate.integrationId),\n );\n if (!connection) return c.json({ error: 'connection_not_found' }, 404);\n const session = await client.request<PlatformSessionResponse>(\n 'POST',\n `/v2/connections/${encodeURIComponent(connectionId)}/reconnect-session`,\n {},\n );\n c.header('Cache-Control', 'no-store');\n return c.json(session, 201);\n } catch (err) {\n return platformError(c, err);\n }\n },\n }),\n ];\n}\n"],"mappings":";;;;;;;;;;;AAwCA,MAAa,6BAAsE;CACjF,MAAM;EAAE,eAAe;EAAQ,0BAA0B,CAAC,MAAM;CAAE;CAClE,eAAe;EAAE,eAAe;EAAe,0BAA0B,CAAC,aAAa;CAAE;CACzF,QAAQ;EAAE,eAAe;EAAU,0BAA0B,CAAC,QAAQ;CAAE;CACxE,OAAO;EAAE,eAAe;EAAS,0BAA0B,CAAC,OAAO;CAAE;AACvE;AA0CA,eAAe,iBACb,GACA,MACiF;CACjF,IAAI,CAAC,KAAK,QAAQ,GAChB,OAAO,EAAE,UAAU,EAAE,KAAK;EAAE,OAAO;EAAiB,SAAS;CAA+B,GAAG,GAAG,EAAE;CAEtG,MAAM,KAAK,WAAW,CAAC;CACvB,MAAM,SAAS,KAAK,OAAO,CAAC;CAC5B,IAAI,CAAC,QAAQ,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,eAAe,GAAG,GAAG,EAAE;CACvE,IAAI,CAAC,OAAO,OACV,OAAO,EACL,UAAU,EAAE,KACV;EACE,OAAO;EACP,SAAS;CACX,GACA,GACF,EACF;CAEF,OAAO,EAAE,QAAQ;EAAE,OAAO,OAAO;EAAO,QAAQ,OAAO;CAAO,EAAE;AAClE;AAEA,SAAS,kBAAkB,GAAiD;CAC1E,MAAM,WAAW,EAAE,IAAI,MAAM,UAAU;CACvC,OAAO,WAAY,2BAA2B,aAAa,OAAQ;AACrE;AAEA,SAAS,cAAc,GAAiB,KAAc;CACp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[],"sources":["../../../../src/integrations/platform/connect/routes.ts"],"sourcesContent":["/**\n * Mastra `apiRoutes` that let the Factory SPA connect and reconnect\n * Platform-managed provider accounts without leaving Factory, and list the\n * Platform project connections whose Mastra Connect tools sessions get.\n *\n * The browser cannot talk to the integrations service itself — it has no\n * Platform session — so these routes mint Nango connect/reconnect sessions\n * server-side with the deploy's machine credentials\n * (`MASTRA_PLATFORM_ACCESS_TOKEN`/`MASTRA_PLATFORM_SECRET_KEY`) and hand the\n * short-lived session token back to the SPA, which drives the provider's\n * OAuth popup headlessly via `@nangohq/frontend`. Gating mirrors the\n * Platform's own rule for these providers: a signed-in organization member\n * (org:write parity with Linear), not an organization admin.\n */\n\nimport { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\n\nimport { loose } from '../../../routes/route.js';\nimport type { RouteAuth } from '../../../routes/route.js';\nimport type { PlatformApiClient } from '../api-client.js';\nimport { PlatformApiError } from '../api-client.js';\nimport { connectToolExclusion, offersSessionTools } from './session-tools.js';\n\ntype RouteContext = Context;\n\nexport interface PlatformConnectProvider {\n /** Platform integration id used to mint connect sessions. */\n integrationId: string;\n /** Connection `integrationId` variants that belong to this provider. */\n connectionIntegrationIds: readonly string[];\n}\n\n/**\n * Providers the Factory SPA may connect through these routes. Keys are the\n * SPA-facing provider slugs; `integrationId` is the Platform catalog id used\n * for new connect sessions. Provider-specific PRs extend this registry when\n * their Factory integrations are available.\n */\nexport const PLATFORM_CONNECT_PROVIDERS: Record<string, PlatformConnectProvider> = {\n jira: { integrationId: 'jira', connectionIntegrationIds: ['jira'] },\n 'incident-io': { integrationId: 'incident-io', connectionIntegrationIds: ['incident-io'] },\n gitlab: { integrationId: 'gitlab', connectionIntegrationIds: ['gitlab'] },\n vanta: { integrationId: 'vanta', connectionIntegrationIds: ['vanta'] },\n};\n\ninterface PlatformConnectionRow {\n id: string;\n integrationId: string;\n status: 'active' | 'needs_reauth';\n accountLabel: string | null;\n displayName?: string | null;\n connectedAt?: string;\n}\n\ninterface PlatformSessionResponse {\n connectionId: string;\n integrationId: string;\n connectUrl: string;\n sessionToken: string;\n expiresAt: string;\n}\n\ninterface ProjectConnectionRow {\n id: string;\n integrationId: string;\n status: string;\n accountLabel?: string | null;\n}\n\ninterface CatalogEntry {\n id: string;\n displayName?: string | null;\n logoUrl?: string | null;\n}\n\nexport interface BuildPlatformConnectRoutesOptions {\n auth: RouteAuth;\n client: PlatformApiClient;\n}\n\nexport interface ConnectToolsSource {\n client: PlatformApiClient;\n projectId: string;\n /**\n * `default`: sessions get Factory's own Connect tools for this project.\n * `custom`: the Factory's `tools` option sets session tools, and may or may\n * not include these connections.\n */\n toolsSource: 'default' | 'custom';\n /**\n * Resolves the tools a session started by this request would get from\n * `toolsSource`: the project's Connect tools before Factory's filters for\n * `default`, or what the `tools` option returns for `custom`. Rejects when\n * they can't be resolved.\n */\n resolveTools: (args: { requestContext: RequestContext }) => Promise<Record<string, unknown>>;\n}\n\n/** One tool as Settings › Tools lists it. */\nexport interface ListedConnectTool {\n name: string;\n description: string | null;\n /** The tool pauses the run until someone approves each call. */\n requiresApproval: boolean;\n /** Factory leaves this default Connect tool out of sessions: its name says it deletes or archives. */\n excluded?: 'destructive';\n}\n\n/** The one piece of setup the Factory lacks to list its project's connections. */\nexport type ConnectToolsSetupMissing = 'no_credentials' | 'no_project_id';\n\nconst MISSING_SETUP_MESSAGES: Record<ConnectToolsSetupMissing, string> = {\n no_credentials:\n 'This Factory has no Mastra Platform credentials. Set MASTRA_PLATFORM_SECRET_KEY or MASTRA_PLATFORM_ACCESS_TOKEN.',\n no_project_id: 'This Factory has Mastra Platform credentials but no MASTRA_PROJECT_ID.',\n};\n\nasync function resolveOrgTenant(\n c: RouteContext,\n auth: RouteAuth,\n): Promise<{ tenant: { orgId: string; userId: string } } | { response: Response }> {\n if (!auth.enabled()) {\n return { response: c.json({ error: 'auth_disabled', message: 'Factory auth is not enabled.' }, 403) };\n }\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) return { response: c.json({ error: 'unauthorized' }, 401) };\n if (!tenant.orgId) {\n return {\n response: c.json(\n {\n error: 'organization_required',\n message: 'Provider connections require an organization. Personal accounts cannot connect providers.',\n },\n 403,\n ),\n };\n }\n return { tenant: { orgId: tenant.orgId, userId: tenant.userId } };\n}\n\nfunction providerFromParam(c: RouteContext): PlatformConnectProvider | null {\n const provider = c.req.param('provider');\n return provider ? (PLATFORM_CONNECT_PROVIDERS[provider] ?? null) : null;\n}\n\nfunction platformError(c: RouteContext, err: unknown) {\n if (err instanceof PlatformApiError) {\n if (err.status === 409) {\n return c.json({ error: 'session_pending', message: err.message }, 409);\n }\n if (err.status === 403) {\n return c.json({ error: 'platform_forbidden', message: err.message }, 403);\n }\n }\n return c.json({ error: 'platform_request_failed', message: err instanceof Error ? err.message : String(err) }, 502);\n}\n\n/**\n * Lists the Platform project's connections for Settings › Tools whenever the\n * Factory has Platform credentials and `MASTRA_PROJECT_ID`, whatever its\n * `tools` option. `toolsSource` tells the panel whether sessions get these\n * connections by default or only through the Factory's own `tools` code.\n */\nexport function buildConnectToolsRoute(\n auth: RouteAuth,\n source: ConnectToolsSource | { missing: ConnectToolsSetupMissing },\n): ApiRoute {\n return registerApiRoute('/web/integrations/platform/connect-tools', {\n method: 'GET',\n requiresAuth: false,\n handler: async rawContext => {\n const c = loose(rawContext);\n if (auth.enabled()) {\n await auth.ensureUser(c);\n if (!auth.tenant(c)) return c.json({ error: 'unauthorized' }, 401);\n }\n if ('missing' in source) {\n // `connect_tools_off` stays the code so settings pages from older CLIs still read it.\n return c.json(\n { error: 'connect_tools_off', reason: source.missing, message: MISSING_SETUP_MESSAGES[source.missing] },\n 404,\n );\n }\n const { client, projectId, toolsSource } = source;\n try {\n const [listed, catalog] = await Promise.all([\n client.request<{ connections: ProjectConnectionRow[] }>(\n 'GET',\n `/v2/projects/${encodeURIComponent(projectId)}/connections`,\n ),\n client.request<{ integrations: CatalogEntry[] }>('GET', '/v2/integrations').catch((error: unknown) => {\n console.warn(\n `MastraFactory: listing connections without provider names; the Platform catalog failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n return { integrations: [] };\n }),\n ]);\n const entries = new Map(catalog.integrations.map(entry => [entry.id, entry]));\n const connections = listed.connections\n .filter(connection => offersSessionTools(connection.integrationId))\n .map(connection => {\n const entry = entries.get(connection.integrationId);\n return {\n id: connection.id,\n integrationId: connection.integrationId,\n providerName: entry?.displayName ?? connection.integrationId,\n logoUrl: entry?.logoUrl ?? null,\n accountLabel: connection.accountLabel ?? null,\n status: connection.status,\n };\n })\n .sort((a, b) => a.providerName.localeCompare(b.providerName));\n return c.json({ projectId, toolsSource, connections });\n } catch (err) {\n return platformError(c, err);\n }\n },\n });\n}\n\nfunction listedTool(name: string, tool: unknown, toolsSource: ConnectToolsSource['toolsSource']): ListedConnectTool[] {\n // Factory filters only its default Connect tools; a `tools` option reaches sessions as written.\n const exclusion = toolsSource === 'default' ? connectToolExclusion(name) : undefined;\n // GitHub and GitLab connections aren't listed, so neither are their tools.\n if (exclusion === 'source_control') return [];\n const { description, requireApproval } = (tool ?? {}) as { description?: unknown; requireApproval?: unknown };\n return [\n {\n name,\n description: typeof description === 'string' && description.trim() ? description.trim() : null,\n requiresApproval: requireApproval === true,\n ...(exclusion ? { excluded: exclusion } : {}),\n },\n ];\n}\n\n/**\n * Lists the tools sessions get from the Connect tools source, as the signed-in\n * caller's session would resolve them, for the tool lists in Settings › Tools.\n */\nexport function buildConnectToolListRoute(\n auth: RouteAuth,\n source: ConnectToolsSource | { missing: ConnectToolsSetupMissing },\n): ApiRoute {\n return registerApiRoute('/web/integrations/platform/connect-tools/tools', {\n method: 'GET',\n requiresAuth: false,\n handler: async rawContext => {\n const c = loose(rawContext);\n if (auth.enabled()) {\n await auth.ensureUser(c);\n if (!auth.tenant(c)) return c.json({ error: 'unauthorized' }, 401);\n }\n if ('missing' in source) {\n return c.json(\n { error: 'connect_tools_off', reason: source.missing, message: MISSING_SETUP_MESSAGES[source.missing] },\n 404,\n );\n }\n const { toolsSource, resolveTools } = source;\n const requestContext = (c.get('requestContext' as never) as RequestContext | undefined) ?? new RequestContext();\n try {\n const resolved = await resolveTools({ requestContext });\n const tools = Object.entries(resolved)\n .flatMap(([name, tool]) => listedTool(name, tool, toolsSource))\n .sort((a, b) => a.name.localeCompare(b.name));\n return c.json({ toolsSource, tools });\n } catch (err) {\n return c.json(\n {\n error: 'tools_unavailable',\n message: `Couldn't resolve the tools: ${err instanceof Error ? err.message : String(err)}`,\n },\n 502,\n );\n }\n },\n });\n}\n\n/**\n * Build the `/web/integrations/platform/*` routes. Callers only mount these\n * when Platform machine credentials are configured.\n */\nexport function buildPlatformConnectRoutes(options: BuildPlatformConnectRoutesOptions): ApiRoute[] {\n const { auth, client } = options;\n\n return [\n registerApiRoute('/web/integrations/platform/:provider/connections', {\n method: 'GET',\n requiresAuth: false,\n handler: async rawContext => {\n const c = loose(rawContext);\n const provider = providerFromParam(c);\n if (!provider) return c.json({ error: 'unknown_provider' }, 404);\n const resolved = await resolveOrgTenant(c, auth);\n if ('response' in resolved) return resolved.response;\n try {\n const result = await client.request<{ connections: PlatformConnectionRow[] }>('GET', '/v2/connections');\n const connections = result.connections.filter(connection =>\n provider.connectionIntegrationIds.includes(connection.integrationId),\n );\n return c.json({ connections });\n } catch (err) {\n return platformError(c, err);\n }\n },\n }),\n registerApiRoute('/web/integrations/platform/:provider/connect-session', {\n method: 'POST',\n requiresAuth: false,\n handler: async rawContext => {\n const c = loose(rawContext);\n const provider = providerFromParam(c);\n if (!provider) return c.json({ error: 'unknown_provider' }, 404);\n const resolved = await resolveOrgTenant(c, auth);\n if ('response' in resolved) return resolved.response;\n try {\n const session = await client.request<PlatformSessionResponse>(\n 'POST',\n `/v2/integrations/${encodeURIComponent(provider.integrationId)}/connect-sessions`,\n {},\n );\n c.header('Cache-Control', 'no-store');\n return c.json(session, 201);\n } catch (err) {\n return platformError(c, err);\n }\n },\n }),\n registerApiRoute('/web/integrations/platform/:provider/connections/:connectionId/reconnect-session', {\n method: 'POST',\n requiresAuth: false,\n handler: async rawContext => {\n const c = loose(rawContext);\n const provider = providerFromParam(c);\n if (!provider) return c.json({ error: 'unknown_provider' }, 404);\n const resolved = await resolveOrgTenant(c, auth);\n if ('response' in resolved) return resolved.response;\n const connectionId = c.req.param('connectionId');\n if (!connectionId) return c.json({ error: 'connection_required' }, 400);\n try {\n // Confirm the connection belongs to this provider before minting so\n // one provider's page cannot reconnect a different provider's\n // connection through this route family.\n const listed = await client.request<{ connections: PlatformConnectionRow[] }>('GET', '/v2/connections');\n const connection = listed.connections.find(\n candidate =>\n candidate.id === connectionId && provider.connectionIntegrationIds.includes(candidate.integrationId),\n );\n if (!connection) return c.json({ error: 'connection_not_found' }, 404);\n const session = await client.request<PlatformSessionResponse>(\n 'POST',\n `/v2/connections/${encodeURIComponent(connectionId)}/reconnect-session`,\n {},\n );\n c.header('Cache-Control', 'no-store');\n return c.json(session, 201);\n } catch (err) {\n return platformError(c, err);\n }\n },\n }),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,6BAAsE;CACjF,MAAM;EAAE,eAAe;EAAQ,0BAA0B,CAAC,MAAM;CAAE;CAClE,eAAe;EAAE,eAAe;EAAe,0BAA0B,CAAC,aAAa;CAAE;CACzF,QAAQ;EAAE,eAAe;EAAU,0BAA0B,CAAC,QAAQ;CAAE;CACxE,OAAO;EAAE,eAAe;EAAS,0BAA0B,CAAC,OAAO;CAAE;AACvE;AAoEA,MAAM,yBAAmE;CACvE,gBACE;CACF,eAAe;AACjB;AAEA,eAAe,iBACb,GACA,MACiF;CACjF,IAAI,CAAC,KAAK,QAAQ,GAChB,OAAO,EAAE,UAAU,EAAE,KAAK;EAAE,OAAO;EAAiB,SAAS;CAA+B,GAAG,GAAG,EAAE;CAEtG,MAAM,KAAK,WAAW,CAAC;CACvB,MAAM,SAAS,KA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,IAAI,CAAC,cAAc,OAAO,EAAE,KAAK,EAAE,OAAO,sBAAsB,GAAG,GAAG;IACtE,IAAI;KASF,IAAI,EAJe,MADE,OAAO,QAAkD,OAAO,iBAAiB,EAAA,CAC5E,YAAY,MACpC,cACE,UAAU,OAAO,gBAAgB,SAAS,yBAAyB,SAAS,UAAU,aAAa,CAEzF,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,uBAAuB,GAAG,GAAG;KACrE,MAAM,UAAU,MAAM,OAAO,QAC3B,QACA,mBAAmB,mBAAmB,YAAY,EAAE,qBACpD,CAAC,CACH;KACA,EAAE,OAAO,iBAAiB,UAAU;KACpC,OAAO,EAAE,KAAK,SAAS,GAAG;IAC5B,SAAS,KAAK;KACZ,OAAO,cAAc,GAAG,GAAG;IAC7B;GACF;EACF,CAAC;CACH;AACF"}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import type { RequestContext } from '@mastra/core/request-context';
|
|
2
2
|
import type { IntegrationTools } from '../../base.js';
|
|
3
3
|
export declare function offersSessionTools(integrationId: string): boolean;
|
|
4
|
+
/** Why Factory keeps a Connect tool from sessions by default, or `undefined` when sessions get it. */
|
|
5
|
+
export type ConnectToolExclusion = 'destructive' | 'source_control';
|
|
6
|
+
export declare function connectToolExclusion(name: string): ConnectToolExclusion | undefined;
|
|
7
|
+
/** Rejects when `tools` takes longer than a run waits for Connect tools. */
|
|
8
|
+
export declare function resolveToolsInTime<T>(tools: Promise<T>): Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Every Mastra Connect tool of the project's connections, before Factory's
|
|
11
|
+
* filters. Rejects when the Platform fails or doesn't answer in time.
|
|
12
|
+
*/
|
|
13
|
+
export declare function projectConnectTools(projectId: string): (args: {
|
|
14
|
+
requestContext: RequestContext;
|
|
15
|
+
}) => Promise<IntegrationTools>;
|
|
4
16
|
/**
|
|
5
17
|
* The Mastra Connect tools Factory gives sessions by default, without delete,
|
|
6
18
|
* archive, and GitHub/GitLab tools. Passing `tools` replaces that default; call
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-tools.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/connect/session-tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAQtD,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,GAChB,CAAC,IAAI,EAAE;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,KAAK,OAAO,CAAC,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"session-tools.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/connect/session-tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAQtD,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED,sGAAsG;AACtG,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG,gBAAgB,CAAC;AAEpE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAInF;AAED,4EAA4E;AAC5E,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAazE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,GAChB,CAAC,IAAI,EAAE;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAGzE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,GAChB,CAAC,IAAI,EAAE;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAazE"}
|
|
@@ -7,29 +7,47 @@ const RESOLVE_TIMEOUT_MS = 15e3;
|
|
|
7
7
|
function offersSessionTools(integrationId) {
|
|
8
8
|
return !SOURCE_CONTROL_PROVIDERS.includes(integrationId);
|
|
9
9
|
}
|
|
10
|
+
function connectToolExclusion(name) {
|
|
11
|
+
if (SOURCE_CONTROL_TOOL.test(name)) return "source_control";
|
|
12
|
+
if (DESTRUCTIVE_TOOL.test(name)) return "destructive";
|
|
13
|
+
}
|
|
14
|
+
/** Rejects when `tools` takes longer than a run waits for Connect tools. */
|
|
15
|
+
async function resolveToolsInTime(tools) {
|
|
16
|
+
let timer;
|
|
17
|
+
const timeout = new Promise((_, reject) => {
|
|
18
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`the tools didn't resolve within ${RESOLVE_TIMEOUT_MS / 1e3}s`)), RESOLVE_TIMEOUT_MS);
|
|
19
|
+
});
|
|
20
|
+
try {
|
|
21
|
+
return await Promise.race([tools, timeout]);
|
|
22
|
+
} finally {
|
|
23
|
+
clearTimeout(timer);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Every Mastra Connect tool of the project's connections, before Factory's
|
|
28
|
+
* filters. Rejects when the Platform fails or doesn't answer in time.
|
|
29
|
+
*/
|
|
30
|
+
function projectConnectTools(projectId) {
|
|
31
|
+
const resolve = tools({ projectId });
|
|
32
|
+
return ({ requestContext }) => resolveToolsInTime(resolve({ requestContext }));
|
|
33
|
+
}
|
|
10
34
|
/**
|
|
11
35
|
* The Mastra Connect tools Factory gives sessions by default, without delete,
|
|
12
36
|
* archive, and GitHub/GitLab tools. Passing `tools` replaces that default; call
|
|
13
37
|
* this to keep it alongside your own.
|
|
14
38
|
*/
|
|
15
39
|
function platformConnectTools(projectId) {
|
|
16
|
-
const resolve =
|
|
40
|
+
const resolve = projectConnectTools(projectId);
|
|
17
41
|
return async ({ requestContext }) => {
|
|
18
|
-
let timer;
|
|
19
|
-
const timeout = new Promise((_, reject) => {
|
|
20
|
-
timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`the Platform didn't answer within ${RESOLVE_TIMEOUT_MS / 1e3}s`)), RESOLVE_TIMEOUT_MS);
|
|
21
|
-
});
|
|
22
42
|
try {
|
|
23
|
-
const tools = await
|
|
24
|
-
return Object.fromEntries(Object.entries(tools).filter(([name]) => !
|
|
43
|
+
const tools = await resolve({ requestContext });
|
|
44
|
+
return Object.fromEntries(Object.entries(tools).filter(([name]) => !connectToolExclusion(name)));
|
|
25
45
|
} catch (error) {
|
|
26
46
|
console.warn(`MastraFactory: Mastra Connect tools are unavailable for this run: ${error instanceof Error ? error.message : String(error)}`);
|
|
27
47
|
return {};
|
|
28
|
-
} finally {
|
|
29
|
-
clearTimeout(timer);
|
|
30
48
|
}
|
|
31
49
|
};
|
|
32
50
|
}
|
|
33
|
-
export { offersSessionTools, platformConnectTools };
|
|
51
|
+
export { connectToolExclusion, offersSessionTools, platformConnectTools, projectConnectTools, resolveToolsInTime };
|
|
34
52
|
|
|
35
53
|
//# sourceMappingURL=session-tools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-tools.js","names":["connectTools"],"sources":["../../../../src/integrations/platform/connect/session-tools.ts"],"sourcesContent":["import { tools as connectTools } from '@mastra/connect';\nimport type { RequestContext } from '@mastra/core/request-context';\n\nimport type { IntegrationTools } from '../../base.js';\n\n// Factory's own source-control tools enforce repository scope and self-review; Connect's would bypass both.\nconst SOURCE_CONTROL_PROVIDERS = ['github', 'gitlab'];\nconst SOURCE_CONTROL_TOOL = new RegExp(`^(${SOURCE_CONTROL_PROVIDERS.join('|')})_`);\nconst DESTRUCTIVE_TOOL = /delete|archive/i;\nconst RESOLVE_TIMEOUT_MS = 15_000;\n\nexport function offersSessionTools(integrationId: string): boolean {\n return !SOURCE_CONTROL_PROVIDERS.includes(integrationId);\n}\n\n
|
|
1
|
+
{"version":3,"file":"session-tools.js","names":["connectTools"],"sources":["../../../../src/integrations/platform/connect/session-tools.ts"],"sourcesContent":["import { tools as connectTools } from '@mastra/connect';\nimport type { RequestContext } from '@mastra/core/request-context';\n\nimport type { IntegrationTools } from '../../base.js';\n\n// Factory's own source-control tools enforce repository scope and self-review; Connect's would bypass both.\nconst SOURCE_CONTROL_PROVIDERS = ['github', 'gitlab'];\nconst SOURCE_CONTROL_TOOL = new RegExp(`^(${SOURCE_CONTROL_PROVIDERS.join('|')})_`);\nconst DESTRUCTIVE_TOOL = /delete|archive/i;\nconst RESOLVE_TIMEOUT_MS = 15_000;\n\nexport function offersSessionTools(integrationId: string): boolean {\n return !SOURCE_CONTROL_PROVIDERS.includes(integrationId);\n}\n\n/** Why Factory keeps a Connect tool from sessions by default, or `undefined` when sessions get it. */\nexport type ConnectToolExclusion = 'destructive' | 'source_control';\n\nexport function connectToolExclusion(name: string): ConnectToolExclusion | undefined {\n if (SOURCE_CONTROL_TOOL.test(name)) return 'source_control';\n if (DESTRUCTIVE_TOOL.test(name)) return 'destructive';\n return undefined;\n}\n\n/** Rejects when `tools` takes longer than a run waits for Connect tools. */\nexport async function resolveToolsInTime<T>(tools: Promise<T>): Promise<T> {\n let timer: NodeJS.Timeout | undefined;\n const timeout = new Promise<never>((_, reject) => {\n timer = setTimeout(\n () => reject(new Error(`the tools didn't resolve within ${RESOLVE_TIMEOUT_MS / 1000}s`)),\n RESOLVE_TIMEOUT_MS,\n );\n });\n try {\n return await Promise.race([tools, timeout]);\n } finally {\n clearTimeout(timer);\n }\n}\n\n/**\n * Every Mastra Connect tool of the project's connections, before Factory's\n * filters. Rejects when the Platform fails or doesn't answer in time.\n */\nexport function projectConnectTools(\n projectId: string,\n): (args: { requestContext: RequestContext }) => Promise<IntegrationTools> {\n const resolve = connectTools({ projectId });\n return ({ requestContext }) => resolveToolsInTime(resolve({ requestContext }));\n}\n\n/**\n * The Mastra Connect tools Factory gives sessions by default, without delete,\n * archive, and GitHub/GitLab tools. Passing `tools` replaces that default; call\n * this to keep it alongside your own.\n */\nexport function platformConnectTools(\n projectId: string,\n): (args: { requestContext: RequestContext }) => Promise<IntegrationTools> {\n const resolve = projectConnectTools(projectId);\n return async ({ requestContext }) => {\n try {\n const tools = await resolve({ requestContext });\n return Object.fromEntries(Object.entries(tools).filter(([name]) => !connectToolExclusion(name)));\n } catch (error) {\n console.warn(\n `MastraFactory: Mastra Connect tools are unavailable for this run: ${error instanceof Error ? error.message : String(error)}`,\n );\n return {};\n }\n };\n}\n"],"mappings":";;AAMA,MAAM,2BAA2B,CAAC,UAAU,QAAQ;AACpD,MAAM,sBAAsB,IAAI,OAAO,KAAK,yBAAyB,KAAK,GAAG,EAAE,GAAG;AAClF,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;AAE3B,SAAgB,mBAAmB,eAAgC;CACjE,OAAO,CAAC,yBAAyB,SAAS,aAAa;AACzD;AAKA,SAAgB,qBAAqB,MAAgD;CACnF,IAAI,oBAAoB,KAAK,IAAI,GAAG,OAAO;CAC3C,IAAI,iBAAiB,KAAK,IAAI,GAAG,OAAO;AAE1C;;AAGA,eAAsB,mBAAsB,OAA+B;CACzE,IAAI;CACJ,MAAM,UAAU,IAAI,SAAgB,GAAG,WAAW;EAChD,QAAQ,iBACA,uBAAO,IAAI,MAAM,mCAAmC,qBAAqB,IAAK,EAAE,CAAC,GACvF,kBACF;CACF,CAAC;CACD,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK,CAAC,OAAO,OAAO,CAAC;CAC5C,UAAU;EACR,aAAa,KAAK;CACpB;AACF;;;;;AAMA,SAAgB,oBACd,WACyE;CACzE,MAAM,UAAUA,MAAa,EAAE,UAAU,CAAC;CAC1C,QAAQ,EAAE,qBAAqB,mBAAmB,QAAQ,EAAE,eAAe,CAAC,CAAC;AAC/E;;;;;;AAOA,SAAgB,qBACd,WACyE;CACzE,MAAM,UAAU,oBAAoB,SAAS;CAC7C,OAAO,OAAO,EAAE,qBAAqB;EACnC,IAAI;GACF,MAAM,QAAQ,MAAM,QAAQ,EAAE,eAAe,CAAC;GAC9C,OAAO,OAAO,YAAY,OAAO,QAAQ,KAAK,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,qBAAqB,IAAI,CAAC,CAAC;EACjG,SAAS,OAAO;GACd,QAAQ,KACN,qEAAqE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAC5H;GACA,OAAO,CAAC;EACV;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/vanta/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,MAAM,EAAgB,MAAM,iCAAiC,CAAC;AAE5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/vanta/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,MAAM,EAAgB,MAAM,iCAAiC,CAAC;AAE5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAS5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,MAAM,WAAW,8BAA8B;IAC7C,YAAY,CAAC,EAAE,uBAAuB,CAAC;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAOD,UAAU,6BAA6B;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,QAAQ,GAAG,cAAc,CAAC;IAClC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AASD;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,kBAAkB;;IACjE,QAAQ,CAAC,EAAE,WAAW;IAItB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAOrB;IAEF,YAAY,MAAM,GAAE,8BAAmC,EAGtD;IAEK,eAAe,IAAI,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAMhE;IAYD,qFAAqF;IAC/E,mBAAmB,CAAC,WAAW,CAAC,EAAE,6BAA6B,EAAE,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA4BtG;IAEK,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,aAAa,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAYlJ;IAED,OAAO,CAAC,GAAG,EAAE,kBAAkB,GAAG,YAAY,EAAE,CAgB/C;IAED,MAAM,CAAC,GAAG,EAAE,kBAAkB,GAAG,QAAQ,EAAE,CAe1C;IAED,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAErC;CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { loose } from "../../../routes/route.js";
|
|
2
2
|
import { IssueReconcileWorker } from "../../issue-reconcile-worker.js";
|
|
3
3
|
import { attachVantaRules } from "../../vanta/rules.js";
|
|
4
|
-
import { VANTA_VULNERABILITIES_SOURCE_ID, createVantaSync } from "../../vanta/sync.js";
|
|
4
|
+
import { VANTA_VULNERABILITIES_SOURCE_ID, createVantaSync, vantaVulnerabilitiesSelected } from "../../vanta/sync.js";
|
|
5
5
|
import { PlatformApiClient, platformApiClientConfigFromEnv } from "../api-client.js";
|
|
6
6
|
import { registerApiRoute } from "@mastra/core/server";
|
|
7
7
|
// src/integrations/platform/vanta/integration.ts
|
|
@@ -91,10 +91,10 @@ var PlatformVantaIntegration = class {
|
|
|
91
91
|
connected: async () => (await this.#activeConnections()).length > 0,
|
|
92
92
|
listVulnerabilities: async (orgId) => this.listVulnerabilitiesForOrg(orgId, await projects.listAll()),
|
|
93
93
|
listProjects: () => projects.listAll(),
|
|
94
|
-
intakeEnabled: async (orgId) => (await intake.getConfig({
|
|
94
|
+
intakeEnabled: async (orgId) => vantaVulnerabilitiesSelected((await intake.getConfig({
|
|
95
95
|
orgId,
|
|
96
96
|
integrationIds: [this.id]
|
|
97
|
-
}))[this.id]
|
|
97
|
+
}))[this.id]),
|
|
98
98
|
boundProjectIds: async (orgId) => (await intake.listBindings({
|
|
99
99
|
orgId,
|
|
100
100
|
integrationId: this.id
|
|
@@ -1 +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 resourceId: 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 from the supplied connections, de-duplicated by id. */\n async listVulnerabilities(connections?: PlatformIntegrationConnection[]): Promise<VantaVulnerability[]> {\n const selected = connections ?? (await this.listConnections()).sort((a, b) => a.id.localeCompare(b.id));\n if (selected.length === 0) throw new Error('There is no active Vanta connection.');\n const unreadable = selected.find(connection => connection.status !== 'active');\n if (unreadable) throw new Error(`Vanta connection ${unreadable.id} is ${unreadable.status}.`);\n const byId = new Map<string, VantaVulnerability>();\n for (const connection of selected) {\n let cursor: string | null = null;\n for (let page = 0; ; page++) {\n if (page === MAX_PAGES) {\n // A cut-off list would read as the rest being resolved.\n throw new Error(`Vanta connection ${connection.id} has more than ${MAX_PAGES} pages of vulnerabilities.`);\n }\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) break;\n if (!result.results.pageInfo.endCursor || page === MAX_PAGES - 1) {\n throw new Error(`Incomplete Vanta vulnerability snapshot for connection ${connection.id}`);\n }\n cursor = result.results.pageInfo.endCursor;\n }\n }\n return [...byId.values()];\n }\n\n async listVulnerabilitiesForOrg(orgId: string, factoryProjects: ReadonlyArray<{ id: string; orgId: string }>): Promise<VantaVulnerability[] | null> {\n const connections = await this.listConnections();\n const ownerByProject = new Map(factoryProjects.map(project => [project.id, project.orgId]));\n // A global or unrecognized connection cannot be attributed safely across organizations.\n if (connections.some(connection => connection.resourceId && !ownerByProject.has(connection.resourceId))) return null;\n if (new Set(factoryProjects.map(project => project.orgId)).size > 1 &&\n connections.some(connection => !connection.resourceId)) return null;\n const owned = connections.filter(connection =>\n connection.resourceId ? ownerByProject.get(connection.resourceId) === orgId : true,\n );\n if (owned.length === 0 || owned.some(connection => connection.status === 'needs_reauth')) return null;\n return this.listVulnerabilities(owned.filter(connection => connection.status === 'active'));\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 connected: async () => (await this.#activeConnections()).length > 0,\n listVulnerabilities: async orgId => this.listVulnerabilitiesForOrg(orgId, await projects.listAll()),\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;;;;;AAoBlB,IAAa,2BAAb,MAAoE;CAClE,KAAc;CACd;CACA;CAEA,SAA0B;EACxB,mBAAmB,KAAK,aAAa;EACrC,WAAW,aAAa;GAAE,OAAO,CAAC;GAAG,YAAY;EAAK;EACtD,YAAY,aAAa;GAAE,QAAQ,CAAC;GAAG,YAAY;EAAK;EACxD,UAAU,YAAY;EAC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F"}
|
|
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 {\n createVantaSync,\n DEFAULT_VANTA_SYNC_INTERVAL_MS,\n VANTA_VULNERABILITIES_SOURCE_ID,\n vantaVulnerabilitiesSelected,\n} 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 resourceId: 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 from the supplied connections, de-duplicated by id. */\n async listVulnerabilities(connections?: PlatformIntegrationConnection[]): Promise<VantaVulnerability[]> {\n const selected = connections ?? (await this.listConnections()).sort((a, b) => a.id.localeCompare(b.id));\n if (selected.length === 0) throw new Error('There is no active Vanta connection.');\n const unreadable = selected.find(connection => connection.status !== 'active');\n if (unreadable) throw new Error(`Vanta connection ${unreadable.id} is ${unreadable.status}.`);\n const byId = new Map<string, VantaVulnerability>();\n for (const connection of selected) {\n let cursor: string | null = null;\n for (let page = 0; ; page++) {\n if (page === MAX_PAGES) {\n // A cut-off list would read as the rest being resolved.\n throw new Error(`Vanta connection ${connection.id} has more than ${MAX_PAGES} pages of vulnerabilities.`);\n }\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) break;\n if (!result.results.pageInfo.endCursor || page === MAX_PAGES - 1) {\n throw new Error(`Incomplete Vanta vulnerability snapshot for connection ${connection.id}`);\n }\n cursor = result.results.pageInfo.endCursor;\n }\n }\n return [...byId.values()];\n }\n\n async listVulnerabilitiesForOrg(orgId: string, factoryProjects: ReadonlyArray<{ id: string; orgId: string }>): Promise<VantaVulnerability[] | null> {\n const connections = await this.listConnections();\n const ownerByProject = new Map(factoryProjects.map(project => [project.id, project.orgId]));\n // A global or unrecognized connection cannot be attributed safely across organizations.\n if (connections.some(connection => connection.resourceId && !ownerByProject.has(connection.resourceId))) return null;\n if (new Set(factoryProjects.map(project => project.orgId)).size > 1 &&\n connections.some(connection => !connection.resourceId)) return null;\n const owned = connections.filter(connection =>\n connection.resourceId ? ownerByProject.get(connection.resourceId) === orgId : true,\n );\n if (owned.length === 0 || owned.some(connection => connection.status === 'needs_reauth')) return null;\n return this.listVulnerabilities(owned.filter(connection => connection.status === 'active'));\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 connected: async () => (await this.#activeConnections()).length > 0,\n listVulnerabilities: async orgId => this.listVulnerabilitiesForOrg(orgId, await projects.listAll()),\n listProjects: () => projects.listAll(),\n intakeEnabled: async orgId =>\n vantaVulnerabilitiesSelected((await intake.getConfig({ orgId, integrationIds: [this.id] }))[this.id]),\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":";;;;;;;;AAyBA,MAAM,8BAA8B;AACpC,MAAM,YAAY;AAClB,MAAM,YAAY;;;;;AAoBlB,IAAa,2BAAb,MAAoE;CAClE,KAAc;CACd;CACA;CAEA,SAA0B;EACxB,mBAAmB,KAAK,aAAa;EACrC,WAAW,aAAa;GAAE,OAAO,CAAC;GAAG,YAAY;EAAK;EACtD,YAAY,aAAa;GAAE,QAAQ,CAAC;GAAG,YAAY;EAAK;EACxD,UAAU,YAAY;EACtB,eAAe,YAAY;EAC3B,aAAa,YAAY;CAC3B;CAEA,YAAY,SAAyC,CAAC,GAAG;EACvD,KAAK,UAAU,IAAI,kBAAkB,OAAO,gBAAgB,+BAA+B,CAAC;EAC5F,KAAK,kBAAkB,OAAO,kBAAA;CAChC;CAEA,MAAM,kBAA4D;EAKhE,QAAO,MAJc,KAAK,QAAQ,QAChC,OACA,+BAA+B,6BACjC,EAAA,CACc;CAChB;CAEA,MAAM,qBAA+D;EAEnE,QAAO,MADmB,KAAK,gBAAgB,EAAA,CAC5B,QAAO,eAAc,WAAW,WAAW,QAAQ,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC;CACjH;CAEA,MAAM,eAAwC;EAC5C,KAAK,MAAM,KAAK,mBAAmB,EAAA,CAAG,WAAW,GAAG,OAAO,CAAC;EAC5D,OAAO,CAAC;GAAE,IAAI;GAAiC,MAAM;GAAmB,MAAM;EAAk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L,iBAAiB,qBAAqB;GACpC,QAAQ;GACR,cAAc;GACd,SAAS,OAAM,MAAK;IAClB,IAAI,CAAC,IAAI,KAAK,QAAQ,GAAG,OAAO,EAAE,KAAK;KAAE,SAAS;KAAO,YAAY;KAAM,QAAQ;IAAiB,CAAC;IACrG,MAAM,IAAI,KAAK,WAAW,MAAM,CAAC,CAAC;IAClC,MAAM,SAAS,IAAI,KAAK,OAAO,MAAM,CAAC,CAAC;IACvC,IAAI,CAAC,QAAQ,OAAO,EAAE,KAAK;KAAE,OAAO;KAAgB,QAAQ;IAAgB,GAAG,GAAG;IAClF,IAAI,CAAC,OAAO,OAAO,OAAO,EAAE,KAAK;KAAE,SAAS;KAAM,YAAY;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"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import type { IntakeConfig, IntakeSelection } from '../../storage/domains/intake/base.js';
|
|
1
2
|
import type { IssueReconcileSummary } from '../issue-reconciler.js';
|
|
2
3
|
import type { VantaRulesIngress, VantaVulnerabilityIngress } from './rules.js';
|
|
3
4
|
export declare const VANTA_VULNERABILITIES_SOURCE_ID = "vanta:vulnerabilities";
|
|
5
|
+
export declare const SELECT_VANTA_VULNERABILITIES_MIGRATION = "select_vanta_vulnerabilities_where_sync_was_on";
|
|
6
|
+
/** Vulnerabilities sync only once selected in Work Intake, like every other source. */
|
|
7
|
+
export declare function vantaVulnerabilitiesSelected(selection: IntakeSelection | undefined): boolean;
|
|
8
|
+
/** Orgs whose old sync switch was on with nothing selected, so selecting vulnerabilities keeps them syncing. */
|
|
9
|
+
export declare function vantaOrgsSyncingWithoutSource(configs: ReadonlyArray<{
|
|
10
|
+
orgId: string;
|
|
11
|
+
config: IntakeConfig;
|
|
12
|
+
}>): Map<string, string[]>;
|
|
4
13
|
export declare const DEFAULT_VANTA_SYNC_INTERVAL_MS: number;
|
|
5
14
|
/** The subset of Vanta's `GET /v1/vulnerabilities` item Factory reads. */
|
|
6
15
|
export interface VantaVulnerability {
|
|
@@ -1 +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,uGAAuG;AACvG,MAAM,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAAC;AAE/F,wBAAgB,cAAc,CAAC,aAAa,EAAE,kBAAkB,GAAG,yBAAyB,CAkB3F;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC;;;OAGG;IACH,SAAS,EAAE,MAAM,OAAO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BAAqB,CAAC,CAkDvC"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { vantaLabels } from "./rules.js";
|
|
2
2
|
// src/integrations/vanta/sync.ts
|
|
3
3
|
const VANTA_VULNERABILITIES_SOURCE_ID = "vanta:vulnerabilities";
|
|
4
|
+
const SELECT_VANTA_VULNERABILITIES_MIGRATION = "select_vanta_vulnerabilities_where_sync_was_on";
|
|
5
|
+
/** Vulnerabilities sync only once selected in Work Intake, like every other source. */
|
|
6
|
+
function vantaVulnerabilitiesSelected(selection) {
|
|
7
|
+
return Boolean(selection?.enabled && selection.sourceIds?.includes("vanta:vulnerabilities"));
|
|
8
|
+
}
|
|
9
|
+
/** Orgs whose old sync switch was on with nothing selected, so selecting vulnerabilities keeps them syncing. */
|
|
10
|
+
function vantaOrgsSyncingWithoutSource(configs) {
|
|
11
|
+
return new Map(configs.filter(({ config }) => config.vanta?.enabled && !config.vanta.sourceIds?.length).map(({ orgId }) => [orgId, [VANTA_VULNERABILITIES_SOURCE_ID]]));
|
|
12
|
+
}
|
|
4
13
|
const DEFAULT_VANTA_SYNC_INTERVAL_MS = 9e5;
|
|
5
14
|
function toVantaIngress(vulnerability) {
|
|
6
15
|
const severity = vulnerability.severity?.toLowerCase() ?? null;
|
|
@@ -76,6 +85,6 @@ function createVantaSync(options) {
|
|
|
76
85
|
return summary;
|
|
77
86
|
};
|
|
78
87
|
}
|
|
79
|
-
export { DEFAULT_VANTA_SYNC_INTERVAL_MS, VANTA_VULNERABILITIES_SOURCE_ID, createVantaSync, toVantaIngress };
|
|
88
|
+
export { DEFAULT_VANTA_SYNC_INTERVAL_MS, SELECT_VANTA_VULNERABILITIES_MIGRATION, VANTA_VULNERABILITIES_SOURCE_ID, createVantaSync, toVantaIngress, vantaOrgsSyncingWithoutSource, vantaVulnerabilitiesSelected };
|
|
80
89
|
|
|
81
90
|
//# sourceMappingURL=sync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","names":[],"sources":["../../../src/integrations/vanta/sync.ts"],"sourcesContent":["import type { IssueReconcileSummary } from '../issue-reconciler.js';\nimport { vantaLabels } from './rules.js';\nimport type { VantaRulesIngress, VantaVulnerabilityIngress } from './rules.js';\n\nexport const VANTA_VULNERABILITIES_SOURCE_ID = 'vanta:vulnerabilities';\nexport const DEFAULT_VANTA_SYNC_INTERVAL_MS = 15 * 60_000;\n\n/** The subset of Vanta's `GET /v1/vulnerabilities` item Factory reads. */\nexport interface VantaVulnerability {\n id: string;\n name: string;\n description?: string | null;\n packageIdentifier?: string | null;\n severity?: string | null;\n isFixable?: boolean | null;\n remediateByDate?: string | null;\n firstDetectedDate?: string | null;\n externalURL?: string | null;\n}\n\n/** Lists a complete snapshot for one org, or null when its connections cannot be reconciled safely. */\nexport type VantaVulnerabilityLister = (orgId: string) => Promise<VantaVulnerability[] | null>;\n\nexport function toVantaIngress(vulnerability: VantaVulnerability): VantaVulnerabilityIngress {\n const severity = vulnerability.severity?.toLowerCase() ?? null;\n const packageIdentifier = vulnerability.packageIdentifier ?? null;\n return {\n id: vulnerability.id,\n name: vulnerability.name,\n title: packageIdentifier ? `${packageIdentifier}: ${vulnerability.name}` : vulnerability.name,\n description:\n vulnerability.description && vulnerability.description !== vulnerability.name ? vulnerability.description : null,\n url: vulnerability.externalURL ?? null,\n state: 'open',\n severity,\n packageIdentifier,\n fixable: vulnerability.isFixable ?? null,\n remediateBy: vulnerability.remediateByDate ?? null,\n labels: vantaLabels(severity),\n createdAt: vulnerability.firstDetectedDate ?? new Date(0).toISOString(),\n };\n}\n\n/**\n * Reads a complete snapshot for each organization and hands it to that organization's\n * Factory projects taking Vanta intake. Unavailable snapshots are never reconciled.\n */\nexport function createVantaSync(options: {\n /**\n * Whether any Vanta connection is active. Without one the vulnerability list\n * is empty, which would read as every filed vulnerability being resolved.\n */\n connected: () => Promise<boolean>;\n listVulnerabilities: VantaVulnerabilityLister;\n listProjects: () => Promise<ReadonlyArray<{ orgId: string; id: string }>>;\n intakeEnabled: (orgId: string) => Promise<boolean>;\n boundProjectIds: (orgId: string) => Promise<string[]>;\n ingest: (input: VantaRulesIngress) => Promise<unknown>;\n userId: string;\n}): () => Promise<IssueReconcileSummary> {\n return async () => {\n const summary: IssueReconcileSummary = {\n projects: 0,\n checked: 0,\n updated: 0,\n closed: 0,\n missing: 0,\n failed: 0,\n errors: [],\n };\n if (!(await options.connected())) return summary;\n const projects = await options.listProjects();\n if (projects.length === 0) return summary;\n const orgTargets = new Map<string, { enabled: boolean; bound: string[]; loaded: boolean; vulnerabilities: VantaVulnerabilityIngress[] | null }>();\n for (const project of projects) {\n try {\n let target = orgTargets.get(project.orgId);\n if (!target) {\n const enabled = await options.intakeEnabled(project.orgId);\n target = {\n enabled,\n bound: enabled ? await options.boundProjectIds(project.orgId) : [],\n loaded: false,\n vulnerabilities: null,\n };\n orgTargets.set(project.orgId, target);\n }\n if (!target.enabled || (target.bound.length > 0 && !target.bound.includes(project.id))) continue;\n if (!target.loaded) {\n const snapshot = await options.listVulnerabilities(project.orgId);\n target.vulnerabilities = snapshot?.map(toVantaIngress) ?? null;\n target.loaded = true;\n }\n if (target.vulnerabilities === null) continue;\n await options.ingest({\n orgId: project.orgId,\n userId: options.userId,\n factoryProjectId: project.id,\n vulnerabilities: target.vulnerabilities,\n });\n summary.projects += 1;\n summary.checked += target.vulnerabilities.length;\n } catch (error) {\n summary.failed += 1;\n summary.errors.push({ projectId: project.id, error: error instanceof Error ? error.message : String(error) });\n }\n }\n return summary;\n };\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"sync.js","names":[],"sources":["../../../src/integrations/vanta/sync.ts"],"sourcesContent":["import type { IntakeConfig, IntakeSelection } from '../../storage/domains/intake/base.js';\nimport type { IssueReconcileSummary } from '../issue-reconciler.js';\nimport { vantaLabels } from './rules.js';\nimport type { VantaRulesIngress, VantaVulnerabilityIngress } from './rules.js';\n\nexport const VANTA_VULNERABILITIES_SOURCE_ID = 'vanta:vulnerabilities';\nexport const SELECT_VANTA_VULNERABILITIES_MIGRATION = 'select_vanta_vulnerabilities_where_sync_was_on';\n\n/** Vulnerabilities sync only once selected in Work Intake, like every other source. */\nexport function vantaVulnerabilitiesSelected(selection: IntakeSelection | undefined): boolean {\n return Boolean(selection?.enabled && selection.sourceIds?.includes(VANTA_VULNERABILITIES_SOURCE_ID));\n}\n\n/** Orgs whose old sync switch was on with nothing selected, so selecting vulnerabilities keeps them syncing. */\nexport function vantaOrgsSyncingWithoutSource(\n configs: ReadonlyArray<{ orgId: string; config: IntakeConfig }>,\n): Map<string, string[]> {\n return new Map(\n configs\n .filter(({ config }) => config.vanta?.enabled && !config.vanta.sourceIds?.length)\n .map(({ orgId }) => [orgId, [VANTA_VULNERABILITIES_SOURCE_ID]]),\n );\n}\nexport const DEFAULT_VANTA_SYNC_INTERVAL_MS = 15 * 60_000;\n\n/** The subset of Vanta's `GET /v1/vulnerabilities` item Factory reads. */\nexport interface VantaVulnerability {\n id: string;\n name: string;\n description?: string | null;\n packageIdentifier?: string | null;\n severity?: string | null;\n isFixable?: boolean | null;\n remediateByDate?: string | null;\n firstDetectedDate?: string | null;\n externalURL?: string | null;\n}\n\n/** Lists a complete snapshot for one org, or null when its connections cannot be reconciled safely. */\nexport type VantaVulnerabilityLister = (orgId: string) => Promise<VantaVulnerability[] | null>;\n\nexport function toVantaIngress(vulnerability: VantaVulnerability): VantaVulnerabilityIngress {\n const severity = vulnerability.severity?.toLowerCase() ?? null;\n const packageIdentifier = vulnerability.packageIdentifier ?? null;\n return {\n id: vulnerability.id,\n name: vulnerability.name,\n title: packageIdentifier ? `${packageIdentifier}: ${vulnerability.name}` : vulnerability.name,\n description:\n vulnerability.description && vulnerability.description !== vulnerability.name ? vulnerability.description : null,\n url: vulnerability.externalURL ?? null,\n state: 'open',\n severity,\n packageIdentifier,\n fixable: vulnerability.isFixable ?? null,\n remediateBy: vulnerability.remediateByDate ?? null,\n labels: vantaLabels(severity),\n createdAt: vulnerability.firstDetectedDate ?? new Date(0).toISOString(),\n };\n}\n\n/**\n * Reads a complete snapshot for each organization and hands it to that organization's\n * Factory projects taking Vanta intake. Unavailable snapshots are never reconciled.\n */\nexport function createVantaSync(options: {\n /**\n * Whether any Vanta connection is active. Without one the vulnerability list\n * is empty, which would read as every filed vulnerability being resolved.\n */\n connected: () => Promise<boolean>;\n listVulnerabilities: VantaVulnerabilityLister;\n listProjects: () => Promise<ReadonlyArray<{ orgId: string; id: string }>>;\n intakeEnabled: (orgId: string) => Promise<boolean>;\n boundProjectIds: (orgId: string) => Promise<string[]>;\n ingest: (input: VantaRulesIngress) => Promise<unknown>;\n userId: string;\n}): () => Promise<IssueReconcileSummary> {\n return async () => {\n const summary: IssueReconcileSummary = {\n projects: 0,\n checked: 0,\n updated: 0,\n closed: 0,\n missing: 0,\n failed: 0,\n errors: [],\n };\n if (!(await options.connected())) return summary;\n const projects = await options.listProjects();\n if (projects.length === 0) return summary;\n const orgTargets = new Map<string, { enabled: boolean; bound: string[]; loaded: boolean; vulnerabilities: VantaVulnerabilityIngress[] | null }>();\n for (const project of projects) {\n try {\n let target = orgTargets.get(project.orgId);\n if (!target) {\n const enabled = await options.intakeEnabled(project.orgId);\n target = {\n enabled,\n bound: enabled ? await options.boundProjectIds(project.orgId) : [],\n loaded: false,\n vulnerabilities: null,\n };\n orgTargets.set(project.orgId, target);\n }\n if (!target.enabled || (target.bound.length > 0 && !target.bound.includes(project.id))) continue;\n if (!target.loaded) {\n const snapshot = await options.listVulnerabilities(project.orgId);\n target.vulnerabilities = snapshot?.map(toVantaIngress) ?? null;\n target.loaded = true;\n }\n if (target.vulnerabilities === null) continue;\n await options.ingest({\n orgId: project.orgId,\n userId: options.userId,\n factoryProjectId: project.id,\n vulnerabilities: target.vulnerabilities,\n });\n summary.projects += 1;\n summary.checked += target.vulnerabilities.length;\n } catch (error) {\n summary.failed += 1;\n summary.errors.push({ projectId: project.id, error: error instanceof Error ? error.message : String(error) });\n }\n }\n return summary;\n };\n}\n"],"mappings":";;AAK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GACzC,IAAI,CAAC,QAAQ;IACX,MAAM,UAAU,MAAM,QAAQ,cAAc,QAAQ,KAAK;IACzD,SAAS;KACP;KACA,OAAO,UAAU,MAAM,QAAQ,gBAAgB,QAAQ,KAAK,IAAI,CAAC;KACjE,QAAQ;KACR,iBAAiB;IACnB;IACA,WAAW,IAAI,QAAQ,OAAO,MAAM;GACtC;GACA,IAAI,CAAC,OAAO,WAAY,OAAO,MAAM,SAAS,KAAK,CAAC,OAAO,MAAM,SAAS,QAAQ,EAAE,GAAI;GACxF,IAAI,CAAC,OAAO,QAAQ;IAClB,MAAM,WAAW,MAAM,QAAQ,oBAAoB,QAAQ,KAAK;IAChE,OAAO,kBAAkB,UAAU,IAAI,cAAc,KAAK;IAC1D,OAAO,SAAS;GAClB;GACA,IAAI,OAAO,oBAAoB,MAAM;GACrC,MAAM,QAAQ,OAAO;IACnB,OAAO,QAAQ;IACf,QAAQ,QAAQ;IAChB,kBAAkB,QAAQ;IAC1B,iBAAiB,OAAO;GAC1B,CAAC;GACD,QAAQ,YAAY;GACpB,QAAQ,WAAW,OAAO,gBAAgB;EAC5C,SAAS,OAAO;GACd,QAAQ,UAAU;GAClB,QAAQ,OAAO,KAAK;IAAE,WAAW,QAAQ;IAAI,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAAE,CAAC;EAC9G;EAEF,OAAO;CACT;AACF"}
|
|
@@ -6,18 +6,18 @@ export interface BoardSnapshot {
|
|
|
6
6
|
gzipped(): Promise<Buffer>;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* The listing's wire body for one board version
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* The listing's wire body for one board version. Every tab polling an unchanged board shares one
|
|
10
|
+
* serialization and one gzip, and its ETag lets the browser revalidate instead of downloading the
|
|
11
|
+
* board again.
|
|
12
12
|
*/
|
|
13
|
-
export declare function boardSnapshot(items: readonly Card[], toWire: (item: Card) => unknown,
|
|
13
|
+
export declare function boardSnapshot(items: readonly Card[], toWire: (item: Card) => unknown, cursor?: string): BoardSnapshot;
|
|
14
14
|
/**
|
|
15
15
|
* The wire body for the cards a scoped listing picked. Its ETag names the cards by a hash of
|
|
16
16
|
* their body, not by the board version: a write to a card outside the scope leaves it unchanged,
|
|
17
17
|
* so the tab gets a 304. A caller that passes the same list again shares its serialization.
|
|
18
18
|
* `total` is how many cards matched when `items` is only the first of them.
|
|
19
19
|
*/
|
|
20
|
-
export declare function scopedSnapshot(items: readonly Card[], toWire: (item: Card) => unknown,
|
|
20
|
+
export declare function scopedSnapshot(items: readonly Card[], toWire: (item: Card) => unknown, total?: number): BoardSnapshot;
|
|
21
21
|
/** What moved on a board, for the one reader whose cursor it answers: nothing of it is kept. */
|
|
22
22
|
export declare function movedBody(body: unknown): Pick<BoardSnapshot, 'json' | 'gzipped'>;
|
|
23
23
|
/**
|