@opengeni/api-router 0.21.0 → 0.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createAppComposition,
3
3
  startSlackInteractionPump
4
- } from "./chunk-5EEC7Q6C.js";
4
+ } from "./chunk-AMMQI2D3.js";
5
5
 
6
6
  // src/index.ts
7
7
  import {
@@ -83,9 +83,13 @@ export declare function browseGoogleDrive(deps: ApiRouteDeps, input: {
83
83
  incompleteSearch: boolean;
84
84
  }>;
85
85
  export declare function saveGoogleDriveSource(deps: ApiRouteDeps, input: {
86
+ accountId: string;
86
87
  workspaceId: string;
87
88
  subjectId: string;
88
89
  connectionId: string;
89
90
  payload: unknown;
91
+ canManageOrganizationDestination: boolean;
92
+ canManageWorkspaceDestination: boolean;
93
+ canManagePersonalDestination: boolean;
90
94
  }): Promise<import("@opengeni/db").ConnectionMetadataWithVerification>;
91
95
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/api-router",
3
- "version": "0.21.0",
3
+ "version": "0.21.3",
4
4
  "description": "OpenGeni HTTP surface: the Hono adapter/router (createApp), routes, MCP HTTP transport, and HTTP access adapters over @opengeni/core. An engine-distribution surface — its runtime closure includes engine-internal packages.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -44,17 +44,17 @@
44
44
  "@modelcontextprotocol/sdk": "^1.29.0",
45
45
  "@opengeni/agent-proto": "^0.3.0",
46
46
  "@opengeni/codex": "^0.2.10",
47
- "@opengeni/config": "^0.10.7",
48
- "@opengeni/contracts": "^0.36.0",
49
- "@opengeni/core": "^0.20.3",
50
- "@opengeni/db": "^0.27.0",
51
- "@opengeni/documents": "^0.3.3",
52
- "@opengeni/events": "^0.3.66",
53
- "@opengeni/github": "^0.4.23",
54
- "@opengeni/network": "^0.1.1",
55
- "@opengeni/observability": "^0.4.10",
56
- "@opengeni/runtime": "^0.18.4",
57
- "@opengeni/storage": "^0.2.60",
47
+ "@opengeni/config": "^0.10.9",
48
+ "@opengeni/contracts": "^0.37.0",
49
+ "@opengeni/core": "^0.20.6",
50
+ "@opengeni/db": "^0.27.3",
51
+ "@opengeni/documents": "^0.4.1",
52
+ "@opengeni/events": "^0.3.69",
53
+ "@opengeni/github": "^0.4.25",
54
+ "@opengeni/network": "^0.1.2",
55
+ "@opengeni/observability": "^0.4.12",
56
+ "@opengeni/runtime": "^0.18.7",
57
+ "@opengeni/storage": "^0.2.62",
58
58
  "@temporalio/client": "^1.17.0",
59
59
  "better-auth": "^1.6.14",
60
60
  "hono": "^4.12.18",
@@ -1,5 +1,9 @@
1
1
  import { createHash, randomBytes } from "node:crypto";
2
2
  import type { Settings } from "@opengeni/config";
3
+ import {
4
+ bindConnectorDocumentDestination,
5
+ type ConnectorDocumentDestinationSelection,
6
+ } from "@opengeni/contracts/connector-destinations";
3
7
  import {
4
8
  GOOGLE_DRIVE_CREDENTIAL_LABEL,
5
9
  GOOGLE_DRIVE_CREDENTIAL_ROLE,
@@ -253,6 +257,9 @@ export async function completeGoogleDriveOAuthCallback(
253
257
  verifiedAt: new Date().toISOString(),
254
258
  accessMode: scopeDecision.accessMode,
255
259
  lifecycle: googleDriveLifecycle("active"),
260
+ ...(previousMetadata?.documentDestination
261
+ ? { documentDestination: previousMetadata.documentDestination }
262
+ : {}),
256
263
  ...(previousMetadata?.selectedSources
257
264
  ? { selectedSources: previousMetadata.selectedSources }
258
265
  : previousMetadata?.selectedSource
@@ -496,10 +503,14 @@ export async function browseGoogleDrive(
496
503
  export async function saveGoogleDriveSource(
497
504
  deps: ApiRouteDeps,
498
505
  input: {
506
+ accountId: string;
499
507
  workspaceId: string;
500
508
  subjectId: string;
501
509
  connectionId: string;
502
510
  payload: unknown;
511
+ canManageOrganizationDestination: boolean;
512
+ canManageWorkspaceDestination: boolean;
513
+ canManagePersonalDestination: boolean;
503
514
  },
504
515
  ) {
505
516
  const parsedPayload = SaveGoogleDriveSourceRequest.safeParse(input.payload);
@@ -516,7 +527,31 @@ export async function saveGoogleDriveSource(
516
527
  if (!existing) {
517
528
  throw new HTTPException(404, { message: "Google Drive connection not found" });
518
529
  }
530
+ if (existing.accountId !== input.accountId || existing.workspaceId !== input.workspaceId) {
531
+ throw new HTTPException(403, { message: "Google Drive connection authority mismatch" });
532
+ }
519
533
  await requireGoogleDriveSourceConnection(deps, existing, input.subjectId);
534
+ const destinationSelection: ConnectorDocumentDestinationSelection = payload.destination ?? {
535
+ authorityKind: "workspace",
536
+ collectionId: null,
537
+ };
538
+ if (
539
+ destinationSelection.authorityKind === "organization" &&
540
+ !input.canManageOrganizationDestination
541
+ ) {
542
+ throw new HTTPException(403, { message: "missing permission: account:admin" });
543
+ }
544
+ if (destinationSelection.authorityKind === "workspace" && !input.canManageWorkspaceDestination) {
545
+ throw new HTTPException(403, { message: "missing permission: workspace:admin" });
546
+ }
547
+ if (destinationSelection.authorityKind === "personal" && !input.canManagePersonalDestination) {
548
+ throw new HTTPException(403, { message: "personal destination requires the exact actor" });
549
+ }
550
+ const documentDestination = bindConnectorDocumentDestination(destinationSelection, {
551
+ accountId: input.accountId,
552
+ workspaceId: input.workspaceId,
553
+ initiatingSubjectId: input.subjectId,
554
+ });
520
555
  const verifiedSources = [];
521
556
  for (const source of payload.sources) {
522
557
  const sourceId = validDriveId(source.id, "source.id");
@@ -552,13 +587,14 @@ export async function saveGoogleDriveSource(
552
587
  expectedVersion: latest.version,
553
588
  metadata: GoogleDriveConnectionMetadata.parse({
554
589
  ...latestMetadata,
590
+ documentDestination,
555
591
  selectedSource: null,
556
592
  selectedSources: verifiedSources.map((verified) => ({
557
593
  id: verified.id,
558
594
  name: verified.name,
559
595
  mimeType: verified.mimeType,
560
596
  driveId: verified.driveId,
561
- targetScope: payload.targetScope,
597
+ destination: documentDestination,
562
598
  syncCadence: payload.syncCadence,
563
599
  readPolicy: payload.readPolicy,
564
600
  selectedAt: new Date().toISOString(),
@@ -24,6 +24,7 @@ import {
24
24
  isOpenGeniSlackBotConnection,
25
25
  openGeniSlackBotMetadata,
26
26
  requireAccessGrant,
27
+ requireAccessGrantAuthorization,
27
28
  requireEnvironmentEncryption,
28
29
  } from "@opengeni/core";
29
30
  import {
@@ -338,12 +339,25 @@ export function registerConnectionRoutes(app: Hono, deps: ApiRouteDeps): void {
338
339
  async (c) => {
339
340
  assertIntegrationsEnabled();
340
341
  const workspaceId = c.req.param("workspaceId");
341
- const grant = await requireAccessGrant(c, deps, workspaceId, "connections:write");
342
+ const authorization = await requireAccessGrantAuthorization(
343
+ c,
344
+ deps,
345
+ workspaceId,
346
+ "connections:write",
347
+ );
348
+ const { grant } = authorization;
342
349
  const connection = await saveGoogleDriveSource(deps, {
350
+ accountId: grant.accountId,
343
351
  workspaceId,
344
352
  subjectId: grant.subjectId,
345
353
  connectionId: c.req.param("connectionId"),
346
354
  payload: await c.req.json(),
355
+ canManageOrganizationDestination:
356
+ authorization.accountGrant?.permissions.includes("account:admin") === true,
357
+ canManageWorkspaceDestination: hasPermission(grant.permissions, "workspace:admin"),
358
+ canManagePersonalDestination:
359
+ authorization.contextIntegrity &&
360
+ authorization.authenticatedSubjectId === grant.subjectId,
347
361
  });
348
362
  return c.json(ConnectionResponse.parse({ connection }));
349
363
  },