@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/app.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  validateToolRefs,
23
23
  withDefaultEnabledCapabilityMcpTools,
24
24
  workflowIdForSession
25
- } from "./chunk-5EEC7Q6C.js";
25
+ } from "./chunk-AMMQI2D3.js";
26
26
  export {
27
27
  API_MAX_REQUEST_BODY_BYTES,
28
28
  allowedCorsOrigin,
@@ -10960,6 +10960,7 @@ import {
10960
10960
  isOpenGeniSlackBotConnection as isOpenGeniSlackBotConnection2,
10961
10961
  openGeniSlackBotMetadata as openGeniSlackBotMetadata2,
10962
10962
  requireAccessGrant as requireAccessGrant3,
10963
+ requireAccessGrantAuthorization,
10963
10964
  requireEnvironmentEncryption as requireEnvironmentEncryption4
10964
10965
  } from "@opengeni/core";
10965
10966
  import {
@@ -10981,6 +10982,9 @@ import { HTTPException as HTTPException11 } from "hono/http-exception";
10981
10982
 
10982
10983
  // src/integrations/google-drive.ts
10983
10984
  import { createHash as createHash6, randomBytes as randomBytes3 } from "crypto";
10985
+ import {
10986
+ bindConnectorDocumentDestination
10987
+ } from "@opengeni/contracts/connector-destinations";
10984
10988
  import {
10985
10989
  GOOGLE_DRIVE_CREDENTIAL_LABEL,
10986
10990
  GOOGLE_DRIVE_CREDENTIAL_ROLE,
@@ -11171,6 +11175,7 @@ async function completeGoogleDriveOAuthCallback(deps, input) {
11171
11175
  verifiedAt: (/* @__PURE__ */ new Date()).toISOString(),
11172
11176
  accessMode: scopeDecision.accessMode,
11173
11177
  lifecycle: googleDriveLifecycle("active"),
11178
+ ...previousMetadata?.documentDestination ? { documentDestination: previousMetadata.documentDestination } : {},
11174
11179
  ...previousMetadata?.selectedSources ? { selectedSources: previousMetadata.selectedSources } : previousMetadata?.selectedSource ? { selectedSources: [previousMetadata.selectedSource] } : {}
11175
11180
  });
11176
11181
  const connection = existing ? await updateConnection2(deps.db, {
@@ -11382,7 +11387,28 @@ async function saveGoogleDriveSource(deps, input) {
11382
11387
  if (!existing) {
11383
11388
  throw new HTTPException10(404, { message: "Google Drive connection not found" });
11384
11389
  }
11390
+ if (existing.accountId !== input.accountId || existing.workspaceId !== input.workspaceId) {
11391
+ throw new HTTPException10(403, { message: "Google Drive connection authority mismatch" });
11392
+ }
11385
11393
  await requireGoogleDriveSourceConnection(deps, existing, input.subjectId);
11394
+ const destinationSelection = payload.destination ?? {
11395
+ authorityKind: "workspace",
11396
+ collectionId: null
11397
+ };
11398
+ if (destinationSelection.authorityKind === "organization" && !input.canManageOrganizationDestination) {
11399
+ throw new HTTPException10(403, { message: "missing permission: account:admin" });
11400
+ }
11401
+ if (destinationSelection.authorityKind === "workspace" && !input.canManageWorkspaceDestination) {
11402
+ throw new HTTPException10(403, { message: "missing permission: workspace:admin" });
11403
+ }
11404
+ if (destinationSelection.authorityKind === "personal" && !input.canManagePersonalDestination) {
11405
+ throw new HTTPException10(403, { message: "personal destination requires the exact actor" });
11406
+ }
11407
+ const documentDestination = bindConnectorDocumentDestination(destinationSelection, {
11408
+ accountId: input.accountId,
11409
+ workspaceId: input.workspaceId,
11410
+ initiatingSubjectId: input.subjectId
11411
+ });
11386
11412
  const verifiedSources = [];
11387
11413
  for (const source of payload.sources) {
11388
11414
  const sourceId = validDriveId(source.id, "source.id");
@@ -11413,13 +11439,14 @@ async function saveGoogleDriveSource(deps, input) {
11413
11439
  expectedVersion: latest.version,
11414
11440
  metadata: GoogleDriveConnectionMetadata.parse({
11415
11441
  ...latestMetadata,
11442
+ documentDestination,
11416
11443
  selectedSource: null,
11417
11444
  selectedSources: verifiedSources.map((verified) => ({
11418
11445
  id: verified.id,
11419
11446
  name: verified.name,
11420
11447
  mimeType: verified.mimeType,
11421
11448
  driveId: verified.driveId,
11422
- targetScope: payload.targetScope,
11449
+ destination: documentDestination,
11423
11450
  syncCadence: payload.syncCadence,
11424
11451
  readPolicy: payload.readPolicy,
11425
11452
  selectedAt: (/* @__PURE__ */ new Date()).toISOString()
@@ -12205,12 +12232,22 @@ function registerConnectionRoutes(app, deps) {
12205
12232
  async (c) => {
12206
12233
  assertIntegrationsEnabled();
12207
12234
  const workspaceId = c.req.param("workspaceId");
12208
- const grant = await requireAccessGrant3(c, deps, workspaceId, "connections:write");
12235
+ const authorization = await requireAccessGrantAuthorization(
12236
+ c,
12237
+ deps,
12238
+ workspaceId,
12239
+ "connections:write"
12240
+ );
12241
+ const { grant } = authorization;
12209
12242
  const connection = await saveGoogleDriveSource(deps, {
12243
+ accountId: grant.accountId,
12210
12244
  workspaceId,
12211
12245
  subjectId: grant.subjectId,
12212
12246
  connectionId: c.req.param("connectionId"),
12213
- payload: await c.req.json()
12247
+ payload: await c.req.json(),
12248
+ canManageOrganizationDestination: authorization.accountGrant?.permissions.includes("account:admin") === true,
12249
+ canManageWorkspaceDestination: hasPermission8(grant.permissions, "workspace:admin"),
12250
+ canManagePersonalDestination: authorization.contextIntegrity && authorization.authenticatedSubjectId === grant.subjectId
12214
12251
  });
12215
12252
  return c.json(ConnectionResponse.parse({ connection }));
12216
12253
  }
@@ -12693,7 +12730,7 @@ import {
12693
12730
  } from "@opengeni/documents";
12694
12731
  import { WebStandardStreamableHTTPServerTransport as WebStandardStreamableHTTPServerTransport2 } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
12695
12732
  import { HTTPException as HTTPException13 } from "hono/http-exception";
12696
- import { requireAccessGrant as requireAccessGrant5, requireAccessGrantAuthorization } from "@opengeni/core";
12733
+ import { requireAccessGrant as requireAccessGrant5, requireAccessGrantAuthorization as requireAccessGrantAuthorization2 } from "@opengeni/core";
12697
12734
  import { recordWorkspaceUsage as recordWorkspaceUsage3, requireLimit as requireLimit3 } from "@opengeni/core";
12698
12735
 
12699
12736
  // src/mcp/documents.ts
@@ -13400,7 +13437,7 @@ function registerDocumentRoutes(app, deps) {
13400
13437
  });
13401
13438
  app.post("/v1/workspaces/:workspaceId/document-bases/:baseId/documents", async (c) => {
13402
13439
  const workspaceId = c.req.param("workspaceId");
13403
- const access = await requireAccessGrantAuthorization(c, deps, workspaceId, "documents:manage");
13440
+ const access = await requireAccessGrantAuthorization2(c, deps, workspaceId, "documents:manage");
13404
13441
  const { grant } = access;
13405
13442
  if (!objectStorage) {
13406
13443
  throw new HTTPException13(503, { message: "object storage is not configured" });
@@ -13467,7 +13504,7 @@ function registerDocumentRoutes(app, deps) {
13467
13504
  "/v1/workspaces/:workspaceId/document-bases/:baseId/documents/:documentId",
13468
13505
  async (c) => {
13469
13506
  const workspaceId = c.req.param("workspaceId");
13470
- const authorization = await requireAccessGrantAuthorization(
13507
+ const authorization = await requireAccessGrantAuthorization2(
13471
13508
  c,
13472
13509
  deps,
13473
13510
  workspaceId,
@@ -13504,7 +13541,7 @@ function registerDocumentRoutes(app, deps) {
13504
13541
  "/v1/workspaces/:workspaceId/document-bases/:baseId/documents/:documentId/reindex",
13505
13542
  async (c) => {
13506
13543
  const workspaceId = c.req.param("workspaceId");
13507
- const authorization = await requireAccessGrantAuthorization(
13544
+ const authorization = await requireAccessGrantAuthorization2(
13508
13545
  c,
13509
13546
  deps,
13510
13547
  workspaceId,
@@ -13630,7 +13667,7 @@ function registerDocumentRoutes(app, deps) {
13630
13667
  });
13631
13668
  app.post("/v1/workspaces/:workspaceId/knowledge/drops", async (c) => {
13632
13669
  const workspaceId = c.req.param("workspaceId");
13633
- const access = await requireAccessGrantAuthorization(c, deps, workspaceId, "documents:manage");
13670
+ const access = await requireAccessGrantAuthorization2(c, deps, workspaceId, "documents:manage");
13634
13671
  const { grant } = access;
13635
13672
  if (!objectStorage) {
13636
13673
  throw new HTTPException13(503, { message: "object storage is not configured" });
@@ -13750,7 +13787,7 @@ function registerDocumentRoutes(app, deps) {
13750
13787
  });
13751
13788
  app.post("/v1/workspaces/:workspaceId/documents/:documentId/move", async (c) => {
13752
13789
  const workspaceId = c.req.param("workspaceId");
13753
- const authorization = await requireAccessGrantAuthorization(
13790
+ const authorization = await requireAccessGrantAuthorization2(
13754
13791
  c,
13755
13792
  deps,
13756
13793
  workspaceId,
@@ -22915,7 +22952,7 @@ import {
22915
22952
  import {
22916
22953
  hasPermission as hasPermission13,
22917
22954
  requireAccessGrant as requireAccessGrant20,
22918
- requireAccessGrantAuthorization as requireAccessGrantAuthorization2
22955
+ requireAccessGrantAuthorization as requireAccessGrantAuthorization3
22919
22956
  } from "@opengeni/core";
22920
22957
  import {
22921
22958
  activatePreferenceRegistryRevision,
@@ -23063,7 +23100,7 @@ function registerPreferenceRegistryRoutes(app, deps) {
23063
23100
  });
23064
23101
  app.post(`${base}/proposals`, async (context) => {
23065
23102
  const workspaceId = context.req.param("workspaceId");
23066
- const access = await requireAccessGrantAuthorization2(
23103
+ const access = await requireAccessGrantAuthorization3(
23067
23104
  context,
23068
23105
  deps,
23069
23106
  workspaceId,
@@ -23143,7 +23180,7 @@ function registerPreferenceRegistryRoutes(app, deps) {
23143
23180
  });
23144
23181
  app.post(`${base}/:preferenceId/activate`, async (context) => {
23145
23182
  const workspaceId = context.req.param("workspaceId");
23146
- const access = await requireAccessGrantAuthorization2(
23183
+ const access = await requireAccessGrantAuthorization3(
23147
23184
  context,
23148
23185
  deps,
23149
23186
  workspaceId,
@@ -23172,7 +23209,7 @@ function registerPreferenceRegistryRoutes(app, deps) {
23172
23209
  });
23173
23210
  app.post(`${base}/:preferenceId/correct`, async (context) => {
23174
23211
  const workspaceId = context.req.param("workspaceId");
23175
- const access = await requireAccessGrantAuthorization2(
23212
+ const access = await requireAccessGrantAuthorization3(
23176
23213
  context,
23177
23214
  deps,
23178
23215
  workspaceId,
@@ -23201,7 +23238,7 @@ function registerPreferenceRegistryRoutes(app, deps) {
23201
23238
  });
23202
23239
  app.post(`${base}/:preferenceId/scope`, async (context) => {
23203
23240
  const workspaceId = context.req.param("workspaceId");
23204
- const access = await requireAccessGrantAuthorization2(
23241
+ const access = await requireAccessGrantAuthorization3(
23205
23242
  context,
23206
23243
  deps,
23207
23244
  workspaceId,
@@ -23230,7 +23267,7 @@ function registerPreferenceRegistryRoutes(app, deps) {
23230
23267
  });
23231
23268
  app.post(`${base}/:preferenceId/deactivate`, async (context) => {
23232
23269
  const workspaceId = context.req.param("workspaceId");
23233
- const access = await requireAccessGrantAuthorization2(
23270
+ const access = await requireAccessGrantAuthorization3(
23234
23271
  context,
23235
23272
  deps,
23236
23273
  workspaceId,
@@ -23259,7 +23296,7 @@ function registerPreferenceRegistryRoutes(app, deps) {
23259
23296
  });
23260
23297
  app.post(`${base}/:preferenceId/supersede`, async (context) => {
23261
23298
  const workspaceId = context.req.param("workspaceId");
23262
- const access = await requireAccessGrantAuthorization2(
23299
+ const access = await requireAccessGrantAuthorization3(
23263
23300
  context,
23264
23301
  deps,
23265
23302
  workspaceId,
@@ -23288,7 +23325,7 @@ function registerPreferenceRegistryRoutes(app, deps) {
23288
23325
  });
23289
23326
  app.post(`${base}/:preferenceId/reject`, async (context) => {
23290
23327
  const workspaceId = context.req.param("workspaceId");
23291
- const access = await requireAccessGrantAuthorization2(
23328
+ const access = await requireAccessGrantAuthorization3(
23292
23329
  context,
23293
23330
  deps,
23294
23331
  workspaceId,
@@ -26090,4 +26127,4 @@ export {
26090
26127
  withDefaultEnabledCapabilityMcpTools,
26091
26128
  workflowIdForSession2 as workflowIdForSession
26092
26129
  };
26093
- //# sourceMappingURL=chunk-5EEC7Q6C.js.map
26130
+ //# sourceMappingURL=chunk-AMMQI2D3.js.map