@lucern/graph-primitives 0.3.0-alpha.0 → 0.3.0-alpha.10
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/{beliefDecay-Q_26RTc-.d.ts → beliefDecay-DZ6tkLYq.d.ts} +1 -1
- package/dist/beliefDecay.d.ts +1 -1
- package/dist/beliefDecay.js +188 -1144
- package/dist/beliefDecay.js.map +1 -1
- package/dist/{beliefEvidenceLinks-42FlR48t.d.ts → beliefEvidenceLinks-CWOXxxJg.d.ts} +1 -1
- package/dist/beliefEvidenceLinks.d.ts +1 -1
- package/dist/beliefEvidenceLinks.js +186 -871
- package/dist/beliefEvidenceLinks.js.map +1 -1
- package/dist/{beliefLifecycle-C-AehZgF.d.ts → beliefLifecycle-y8WLXqQj.d.ts} +1 -1
- package/dist/beliefLifecycle.d.ts +1 -1
- package/dist/confidencePropagationDispatch.d.ts +4 -4
- package/dist/confidencePropagationDispatch.js +31 -311
- package/dist/confidencePropagationDispatch.js.map +1 -1
- package/dist/{contradictions-Hdwl7zid.d.ts → contradictions-51VLsESq.d.ts} +1 -1
- package/dist/contradictions.d.ts +1 -1
- package/dist/contradictions.js +67 -800
- package/dist/contradictions.js.map +1 -1
- package/dist/debug.d.ts +4 -0
- package/dist/debug.js +34 -0
- package/dist/debug.js.map +1 -0
- package/dist/edges/contradicts.js +1 -122
- package/dist/edges/contradicts.js.map +1 -1
- package/dist/edges/dependsOn.js +14 -172
- package/dist/edges/dependsOn.js.map +1 -1
- package/dist/edges/elaborates.js +1 -49
- package/dist/edges/elaborates.js.map +1 -1
- package/dist/edges/index.js +15 -280
- package/dist/edges/index.js.map +1 -1
- package/dist/edges/informs.js +2 -65
- package/dist/edges/informs.js.map +1 -1
- package/dist/edges/propagationTypes.d.ts +2 -2
- package/dist/edges/propagationTypes.js.map +1 -1
- package/dist/edges/refutes.js +2 -65
- package/dist/edges/refutes.js.map +1 -1
- package/dist/edges/supports.js +1 -122
- package/dist/edges/supports.js.map +1 -1
- package/dist/edges/utils.d.ts +7 -7
- package/dist/edges/utils.js +2 -133
- package/dist/edges/utils.js.map +1 -1
- package/dist/embeddingTrigger.js +21 -1
- package/dist/embeddingTrigger.js.map +1 -1
- package/dist/entityBridge.js +3 -18
- package/dist/entityBridge.js.map +1 -1
- package/dist/{entityLifecycle-BkhRJ-XI.d.ts → entityLifecycle-CvgSK5FV.d.ts} +1 -1
- package/dist/entityLifecycle.d.ts +1 -1
- package/dist/entityLifecycle.js +193 -892
- package/dist/entityLifecycle.js.map +1 -1
- package/dist/{epistemicAnswers-DSP1slZ9.d.ts → epistemicAnswers-C5ib4z6_.d.ts} +1 -1
- package/dist/epistemicAnswers.d.ts +1 -1
- package/dist/epistemicAnswers.js +73 -810
- package/dist/epistemicAnswers.js.map +1 -1
- package/dist/{epistemicBeliefs-DtFVTp-k.d.ts → epistemicBeliefs-DzKjZAeC.d.ts} +3 -3
- package/dist/epistemicBeliefs.d.ts +2 -2
- package/dist/epistemicBeliefs.js +404 -1698
- package/dist/epistemicBeliefs.js.map +1 -1
- package/dist/epistemicContractHelpers.js +1 -318
- package/dist/epistemicContractHelpers.js.map +1 -1
- package/dist/epistemicContracts.d.ts +1 -1
- package/dist/epistemicContracts.js +417 -1980
- package/dist/epistemicContracts.js.map +1 -1
- package/dist/{epistemicEdges-DcA8ErUG.d.ts → epistemicEdges-CD5vxmlH.d.ts} +3 -3
- package/dist/epistemicEdges.d.ts +1 -1
- package/dist/epistemicEdges.js +248 -919
- package/dist/epistemicEdges.js.map +1 -1
- package/dist/{epistemicEvidence-Bo638XDP.d.ts → epistemicEvidence-xw6UUrwh.d.ts} +1 -1
- package/dist/epistemicEvidence.d.ts +1 -1
- package/dist/epistemicEvidence.js +229 -1087
- package/dist/epistemicEvidence.js.map +1 -1
- package/dist/{epistemicHelpers-Bd9xbaib.d.ts → epistemicHelpers-DevrYgPN.d.ts} +1 -1
- package/dist/epistemicHelpers.d.ts +1 -1
- package/dist/{epistemicLinking-CyeLOIzN.d.ts → epistemicLinking-CfE00tHJ.d.ts} +1 -1
- package/dist/epistemicLinking.d.ts +1 -1
- package/dist/epistemicLinking.js +3 -786
- package/dist/epistemicLinking.js.map +1 -1
- package/dist/{epistemicNodes-BpD6Koud.d.ts → epistemicNodes-NBrPW7fk.d.ts} +2 -2
- package/dist/epistemicNodes.d.ts +1 -1
- package/dist/epistemicNodes.js +172 -899
- package/dist/epistemicNodes.js.map +1 -1
- package/dist/{epistemicQuestions-CmEeY6zQ.d.ts → epistemicQuestions-B_nUclrH.d.ts} +1 -1
- package/dist/epistemicQuestions.d.ts +1 -1
- package/dist/epistemicQuestions.js +369 -1125
- package/dist/epistemicQuestions.js.map +1 -1
- package/dist/{epistemicSources-ZazxHOK1.d.ts → epistemicSources-dlKj58Jp.d.ts} +1 -1
- package/dist/epistemicSources.d.ts +1 -1
- package/dist/epistemicSources.js +86 -886
- package/dist/epistemicSources.js.map +1 -1
- package/dist/evaluators/index.js +417 -1980
- package/dist/evaluators/index.js.map +1 -1
- package/dist/evaluators/lintCheckerEvaluator.js.map +1 -1
- package/dist/evaluators/sentryCheckerEvaluator.js.map +1 -1
- package/dist/evaluators/shared.js +20 -1
- package/dist/evaluators/shared.js.map +1 -1
- package/dist/evaluators/testRunnerEvaluator.js +20 -1
- package/dist/evaluators/testRunnerEvaluator.js.map +1 -1
- package/dist/evaluators/tscCheckerEvaluator.js.map +1 -1
- package/dist/index.d.ts +20 -20
- package/dist/index.js +965 -3004
- package/dist/index.js.map +1 -1
- package/dist/{ontology-matching-Buhu23ss.d.ts → ontology-matching-C6rrz2VP.d.ts} +1 -1
- package/dist/ontology-matching.d.ts +1 -1
- package/dist/ontology-matching.js +1 -344
- package/dist/ontology-matching.js.map +1 -1
- package/dist/{ontologyApproval-Ba0Jjk1k.d.ts → ontologyApproval-CFYmqKmk.d.ts} +1 -1
- package/dist/ontologyApproval.d.ts +1 -1
- package/dist/ontologyApproval.js +1 -13
- package/dist/ontologyApproval.js.map +1 -1
- package/dist/ontologyDefinitions.js +6 -20
- package/dist/ontologyDefinitions.js.map +1 -1
- package/dist/ontologyHelpers.d.ts +1 -1
- package/dist/ontologyHelpers.js +4 -3
- package/dist/ontologyHelpers.js.map +1 -1
- package/dist/ontologyRegistry.js +2 -17
- package/dist/ontologyRegistry.js.map +1 -1
- package/dist/{projectionReconciliation-CxrXYGaB.d.ts → projectionReconciliation-jww2fBI0.d.ts} +1 -1
- package/dist/projectionReconciliation.d.ts +1 -1
- package/dist/projectionReconciliation.js +16 -37
- package/dist/projectionReconciliation.js.map +1 -1
- package/dist/{projectionStaleness-CAdpIsaW.d.ts → projectionStaleness-CmdbpjVK.d.ts} +1 -1
- package/dist/projectionStaleness.d.ts +1 -1
- package/dist/{questionEvidenceLinks-BdQD0TkM.d.ts → questionEvidenceLinks-DFlyPpAj.d.ts} +1 -1
- package/dist/questionEvidenceLinks.d.ts +1 -1
- package/dist/questionEvidenceLinks.js +199 -881
- package/dist/questionEvidenceLinks.js.map +1 -1
- package/dist/resolvers.js +86 -37
- package/dist/resolvers.js.map +1 -1
- package/dist/scopeResolverCompat.js +64 -7
- package/dist/scopeResolverCompat.js.map +1 -1
- package/dist/{text-matching-CMn2WnVD.d.ts → text-matching-DNg4M5Wd.d.ts} +1 -1
- package/dist/text-matching.d.ts +1 -1
- package/dist/text-matching.js +1 -244
- package/dist/text-matching.js.map +1 -1
- package/dist/topicProjectOverlay.js +56 -13
- package/dist/topicProjectOverlay.js.map +1 -1
- package/dist/topicScope.js +55 -6
- package/dist/topicScope.js.map +1 -1
- package/dist/workflowBridge.d.ts +27 -0
- package/dist/workflowBridge.js +352 -0
- package/dist/workflowBridge.js.map +1 -0
- package/dist/workspaceIsolation.js +56 -57
- package/dist/workspaceIsolation.js.map +1 -1
- package/package.json +6 -5
package/dist/epistemicLinking.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { v } from 'convex/values';
|
|
2
|
-
import { componentsGeneric,
|
|
2
|
+
import { componentsGeneric, anyApi, mutationGeneric } from 'convex/server';
|
|
3
|
+
import { checkProjectAccess } from '@lucern/access-control/access';
|
|
4
|
+
import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
|
|
3
5
|
|
|
4
6
|
// src/epistemicLinking.ts
|
|
5
7
|
componentsGeneric();
|
|
@@ -386,791 +388,6 @@ function validateEdgeLayers(edgeType, fromLayer, toLayer) {
|
|
|
386
388
|
}
|
|
387
389
|
return { valid: true };
|
|
388
390
|
}
|
|
389
|
-
var api = anyApi;
|
|
390
|
-
componentsGeneric();
|
|
391
|
-
|
|
392
|
-
// ../access-control/src/topicProjectOverlay.ts
|
|
393
|
-
var LEGACY_SCOPE_FIELD = "graphScopeProjectId";
|
|
394
|
-
function readNonEmptyString(value) {
|
|
395
|
-
if (typeof value !== "string") {
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
const normalized = value.trim();
|
|
399
|
-
return normalized.length > 0 ? normalized : void 0;
|
|
400
|
-
}
|
|
401
|
-
function readStringArray(value) {
|
|
402
|
-
if (!Array.isArray(value)) {
|
|
403
|
-
return [];
|
|
404
|
-
}
|
|
405
|
-
return value.map((entry) => readNonEmptyString(entry)).filter((entry) => Boolean(entry));
|
|
406
|
-
}
|
|
407
|
-
function readMetadata(topic) {
|
|
408
|
-
return topic.metadata && typeof topic.metadata === "object" ? topic.metadata : {};
|
|
409
|
-
}
|
|
410
|
-
function readLegacyProjectId(value) {
|
|
411
|
-
if (!value) {
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
return readNonEmptyString(value[LEGACY_SCOPE_FIELD]);
|
|
415
|
-
}
|
|
416
|
-
function coerceVisibility(value) {
|
|
417
|
-
return value === "private" || value === "team" || value === "firm" || value === "external" || value === "public" ? value : void 0;
|
|
418
|
-
}
|
|
419
|
-
function coerceStatus(value) {
|
|
420
|
-
return value === "active" || value === "archived" || value === "watching" ? value : void 0;
|
|
421
|
-
}
|
|
422
|
-
function mapProjectType(topic, metadata) {
|
|
423
|
-
const explicit = readNonEmptyString(metadata.projectType);
|
|
424
|
-
if (explicit) {
|
|
425
|
-
return explicit;
|
|
426
|
-
}
|
|
427
|
-
if (topic.type === "theme") {
|
|
428
|
-
return "thematic";
|
|
429
|
-
}
|
|
430
|
-
return readNonEmptyString(topic.type) || "general";
|
|
431
|
-
}
|
|
432
|
-
function isProjectLikeTopic(topic) {
|
|
433
|
-
const metadata = readMetadata(topic);
|
|
434
|
-
return topic.type === "theme" || topic.type === "thematic" || topic.type === "deal" || topic.type === "monitoring" || readLegacyProjectId(topic) !== void 0 || readNonEmptyString(metadata.projectType) !== void 0;
|
|
435
|
-
}
|
|
436
|
-
async function resolveTopicDoc(ctx, scopeId) {
|
|
437
|
-
if (ctx?.db && typeof ctx.db.get === "function") {
|
|
438
|
-
try {
|
|
439
|
-
const directTopic = await ctx.db.get(scopeId);
|
|
440
|
-
if (directTopic) {
|
|
441
|
-
return directTopic;
|
|
442
|
-
}
|
|
443
|
-
} catch {
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
if (typeof ctx.runQuery !== "function") {
|
|
447
|
-
return null;
|
|
448
|
-
}
|
|
449
|
-
try {
|
|
450
|
-
const topic = await ctx.runQuery(api.topics.get, {
|
|
451
|
-
id: String(scopeId)
|
|
452
|
-
});
|
|
453
|
-
if (topic?.name !== void 0 && topic?.type !== void 0) {
|
|
454
|
-
return topic;
|
|
455
|
-
}
|
|
456
|
-
} catch {
|
|
457
|
-
}
|
|
458
|
-
try {
|
|
459
|
-
const topic = await ctx.runQuery(api.topics.getByLegacyScopeId, {
|
|
460
|
-
projectId: String(scopeId)
|
|
461
|
-
});
|
|
462
|
-
if (topic?.name !== void 0 && topic?.type !== void 0) {
|
|
463
|
-
return topic;
|
|
464
|
-
}
|
|
465
|
-
} catch {
|
|
466
|
-
}
|
|
467
|
-
return null;
|
|
468
|
-
}
|
|
469
|
-
function materializeTopicProjectOverlay(topic, idMode = "legacy") {
|
|
470
|
-
const metadata = readMetadata(topic);
|
|
471
|
-
const topicId = String(topic._id);
|
|
472
|
-
const legacyProjectId = readLegacyProjectId(topic) || readLegacyProjectId(metadata) || readNonEmptyString(metadata.legacyProjectId);
|
|
473
|
-
const storageProjectId = legacyProjectId || topicId;
|
|
474
|
-
const outwardId = idMode === "topic" ? topicId : storageProjectId;
|
|
475
|
-
const visibility = coerceVisibility(topic.visibility) || coerceVisibility(metadata.visibility) || "private";
|
|
476
|
-
const status = coerceStatus(topic.status) || coerceStatus(metadata.status) || "active";
|
|
477
|
-
const createdAt = typeof topic.createdAt === "number" ? topic.createdAt : typeof topic._creationTime === "number" ? topic._creationTime : 0;
|
|
478
|
-
const updatedAt = typeof topic.updatedAt === "number" ? topic.updatedAt : typeof metadata.updatedAt === "number" ? metadata.updatedAt : createdAt;
|
|
479
|
-
return {
|
|
480
|
-
...metadata,
|
|
481
|
-
_id: outwardId,
|
|
482
|
-
projectId: outwardId,
|
|
483
|
-
topicId,
|
|
484
|
-
storageProjectId,
|
|
485
|
-
legacyProjectId,
|
|
486
|
-
name: readNonEmptyString(topic.name) || "Untitled Theme",
|
|
487
|
-
type: mapProjectType(topic, metadata),
|
|
488
|
-
description: readNonEmptyString(topic.description),
|
|
489
|
-
ownerId: readNonEmptyString(metadata.ownerId) || readNonEmptyString(topic.createdBy) || "system",
|
|
490
|
-
sharedWith: readStringArray(metadata.sharedWith),
|
|
491
|
-
visibility,
|
|
492
|
-
tenantId: readNonEmptyString(topic.tenantId) || readNonEmptyString(metadata.tenantId),
|
|
493
|
-
workspaceId: readNonEmptyString(topic.workspaceId) || readNonEmptyString(metadata.workspaceId),
|
|
494
|
-
status,
|
|
495
|
-
tags: readStringArray(metadata.tags),
|
|
496
|
-
chatCount: typeof metadata.chatCount === "number" ? metadata.chatCount : 0,
|
|
497
|
-
artifactCount: typeof metadata.artifactCount === "number" ? metadata.artifactCount : 0,
|
|
498
|
-
lastActivityAt: typeof metadata.lastActivityAt === "number" ? metadata.lastActivityAt : updatedAt,
|
|
499
|
-
_creationTime: typeof topic._creationTime === "number" ? topic._creationTime : createdAt,
|
|
500
|
-
createdAt,
|
|
501
|
-
updatedAt
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
async function resolveTopicProjectOverlay(ctx, scopeId, options = {}) {
|
|
505
|
-
const topic = await resolveTopicDoc(ctx, scopeId);
|
|
506
|
-
if (!topic) {
|
|
507
|
-
return null;
|
|
508
|
-
}
|
|
509
|
-
if (options.projectLikeOnly !== false && !isProjectLikeTopic(topic)) {
|
|
510
|
-
return null;
|
|
511
|
-
}
|
|
512
|
-
return materializeTopicProjectOverlay(topic, options.idMode);
|
|
513
|
-
}
|
|
514
|
-
async function listTopicProjectOverlays(ctx, options = {}) {
|
|
515
|
-
let allTopics = [];
|
|
516
|
-
if (ctx?.db?.query && typeof ctx.db.query === "function") {
|
|
517
|
-
try {
|
|
518
|
-
allTopics = await ctx.db.query("topics").collect();
|
|
519
|
-
} catch {
|
|
520
|
-
allTopics = [];
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
if (allTopics.length === 0 && typeof ctx.runQuery === "function") {
|
|
524
|
-
allTopics = (await ctx.runQuery(api.topics.list, {}) ?? []) || [];
|
|
525
|
-
}
|
|
526
|
-
return allTopics.filter(
|
|
527
|
-
(topic) => options.projectLikeOnly === false || isProjectLikeTopic(topic)
|
|
528
|
-
).map((topic) => materializeTopicProjectOverlay(topic, options.idMode));
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// ../access-control/src/projectGrantsBridge.ts
|
|
532
|
-
var PROJECT_GRANT_STATUSES = ["active", "revoked", "expired"];
|
|
533
|
-
function normalizeString(value) {
|
|
534
|
-
if (typeof value !== "string") {
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
const trimmed = value.trim();
|
|
538
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
539
|
-
}
|
|
540
|
-
async function resolveGrantScopeIds(ctx, args) {
|
|
541
|
-
const topicId = normalizeString(args.topicId);
|
|
542
|
-
const projectId = normalizeString(args.projectId);
|
|
543
|
-
for (const scopeId of [topicId, projectId]) {
|
|
544
|
-
if (!scopeId) {
|
|
545
|
-
continue;
|
|
546
|
-
}
|
|
547
|
-
try {
|
|
548
|
-
const overlay = await resolveTopicProjectOverlay(ctx, scopeId, {
|
|
549
|
-
idMode: "legacy",
|
|
550
|
-
projectLikeOnly: false
|
|
551
|
-
});
|
|
552
|
-
if (overlay) {
|
|
553
|
-
return {
|
|
554
|
-
topicId: normalizeString(overlay.topicId) ?? topicId,
|
|
555
|
-
projectId: normalizeString(overlay.projectId) ?? projectId ?? scopeId
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
} catch {
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
return { topicId, projectId };
|
|
562
|
-
}
|
|
563
|
-
async function normalizeProjectGrantRow(ctx, row) {
|
|
564
|
-
const scope = await resolveGrantScopeIds(ctx, {
|
|
565
|
-
topicId: row.topicId,
|
|
566
|
-
projectId: row.projectId
|
|
567
|
-
});
|
|
568
|
-
return {
|
|
569
|
-
...row,
|
|
570
|
-
...scope.topicId ? { topicId: scope.topicId } : {},
|
|
571
|
-
...scope.projectId ?? scope.topicId ? { projectId: scope.projectId ?? scope.topicId } : {}
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
async function normalizeProjectGrantRows(ctx, rows) {
|
|
575
|
-
return await Promise.all(rows.map((row) => normalizeProjectGrantRow(ctx, row)));
|
|
576
|
-
}
|
|
577
|
-
async function listProjectGrantsByPrincipal(ctx, principalId) {
|
|
578
|
-
const rows = await Promise.all(
|
|
579
|
-
PROJECT_GRANT_STATUSES.map(
|
|
580
|
-
(status) => ctx.db.query("projectGrants").withIndex(
|
|
581
|
-
"by_principal_status",
|
|
582
|
-
(q) => q.eq("principalId", principalId).eq("status", status)
|
|
583
|
-
).collect()
|
|
584
|
-
)
|
|
585
|
-
);
|
|
586
|
-
return await normalizeProjectGrantRows(ctx, rows.flat());
|
|
587
|
-
}
|
|
588
|
-
async function listProjectGrantsByGroup(ctx, groupId) {
|
|
589
|
-
const rows = await Promise.all(
|
|
590
|
-
PROJECT_GRANT_STATUSES.map(
|
|
591
|
-
(status) => ctx.db.query("projectGrants").withIndex(
|
|
592
|
-
"by_group_status",
|
|
593
|
-
(q) => q.eq("groupId", groupId).eq("status", status)
|
|
594
|
-
).collect()
|
|
595
|
-
)
|
|
596
|
-
);
|
|
597
|
-
return await normalizeProjectGrantRows(ctx, rows.flat());
|
|
598
|
-
}
|
|
599
|
-
function buildScopeMatchers(inputScopeId, resolved) {
|
|
600
|
-
return new Set(
|
|
601
|
-
[inputScopeId, resolved.topicId, resolved.projectId].map((value) => normalizeString(value)).filter((value) => Boolean(value))
|
|
602
|
-
);
|
|
603
|
-
}
|
|
604
|
-
function matchesResolvedScope(row, scopeIds) {
|
|
605
|
-
const rowTopicId = normalizeString(row.topicId);
|
|
606
|
-
const rowProjectId = normalizeString(row.projectId);
|
|
607
|
-
return rowTopicId !== void 0 && scopeIds.has(rowTopicId) || rowProjectId !== void 0 && scopeIds.has(rowProjectId);
|
|
608
|
-
}
|
|
609
|
-
async function bridgeListProjectGrantsByTopicAndPrincipal(ctx, topicId, principalId) {
|
|
610
|
-
const resolved = await resolveGrantScopeIds(ctx, { topicId });
|
|
611
|
-
const scopeIds = buildScopeMatchers(topicId, resolved);
|
|
612
|
-
const rows = await listProjectGrantsByPrincipal(ctx, principalId);
|
|
613
|
-
return rows.filter((row) => matchesResolvedScope(row, scopeIds));
|
|
614
|
-
}
|
|
615
|
-
async function bridgeListProjectGrantsByTopicAndGroup(ctx, topicId, groupId) {
|
|
616
|
-
const resolved = await resolveGrantScopeIds(ctx, { topicId });
|
|
617
|
-
const scopeIds = buildScopeMatchers(topicId, resolved);
|
|
618
|
-
const rows = await listProjectGrantsByGroup(ctx, groupId);
|
|
619
|
-
return rows.filter((row) => matchesResolvedScope(row, scopeIds));
|
|
620
|
-
}
|
|
621
|
-
async function bridgeListProjectGrantsByPrincipalStatus(ctx, principalId, status) {
|
|
622
|
-
const rows = await listProjectGrantsByPrincipal(ctx, principalId);
|
|
623
|
-
return rows.filter((row) => row.status === status);
|
|
624
|
-
}
|
|
625
|
-
async function bridgeListProjectGrantsByGroupStatus(ctx, groupId, status) {
|
|
626
|
-
const rows = await listProjectGrantsByGroup(ctx, groupId);
|
|
627
|
-
return rows.filter((row) => row.status === status);
|
|
628
|
-
}
|
|
629
|
-
async function bridgeInsertProjectGrant(ctx, value) {
|
|
630
|
-
const resolved = await resolveGrantScopeIds(ctx, value);
|
|
631
|
-
return await ctx.db.insert("projectGrants", {
|
|
632
|
-
...value,
|
|
633
|
-
...resolved.topicId ? { topicId: resolved.topicId } : {},
|
|
634
|
-
...resolved.projectId ?? resolved.topicId ? { projectId: resolved.projectId ?? resolved.topicId } : {}
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
// ../access-control/src/resolvers.ts
|
|
639
|
-
async function findUserByClerkId(ctx, clerkId) {
|
|
640
|
-
const normalizedClerkId = clerkId.trim();
|
|
641
|
-
if (!normalizedClerkId) {
|
|
642
|
-
return null;
|
|
643
|
-
}
|
|
644
|
-
if (typeof ctx.runQuery === "function") {
|
|
645
|
-
try {
|
|
646
|
-
const bridgedUser = await ctx.runQuery(api.users.getUserByClerkId, {
|
|
647
|
-
clerkId: normalizedClerkId
|
|
648
|
-
});
|
|
649
|
-
if (bridgedUser) {
|
|
650
|
-
return bridgedUser;
|
|
651
|
-
}
|
|
652
|
-
} catch {
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
try {
|
|
656
|
-
const users = await ctx.db.query("users").collect();
|
|
657
|
-
return users.find((user) => String(user.clerkId ?? "") === normalizedClerkId) ?? null;
|
|
658
|
-
} catch {
|
|
659
|
-
return null;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
async function findUserByPrincipalId(ctx, principalId) {
|
|
663
|
-
const normalizedPrincipalId = principalId.trim();
|
|
664
|
-
if (!normalizedPrincipalId) {
|
|
665
|
-
return null;
|
|
666
|
-
}
|
|
667
|
-
try {
|
|
668
|
-
const users = await ctx.db.query("users").collect();
|
|
669
|
-
return users.find(
|
|
670
|
-
(user) => String(user.defaultPrincipalId ?? "") === normalizedPrincipalId
|
|
671
|
-
) ?? null;
|
|
672
|
-
} catch {
|
|
673
|
-
return null;
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
async function findAgentByPrincipalId(ctx, principalId) {
|
|
677
|
-
const normalizedPrincipalId = principalId.trim();
|
|
678
|
-
if (!normalizedPrincipalId) {
|
|
679
|
-
return null;
|
|
680
|
-
}
|
|
681
|
-
if (typeof ctx.runQuery === "function") {
|
|
682
|
-
try {
|
|
683
|
-
const bridgedAgent = await ctx.runQuery(
|
|
684
|
-
api.agents.getAgentByPrincipalId,
|
|
685
|
-
{
|
|
686
|
-
principalId: normalizedPrincipalId
|
|
687
|
-
}
|
|
688
|
-
);
|
|
689
|
-
if (bridgedAgent) {
|
|
690
|
-
return bridgedAgent;
|
|
691
|
-
}
|
|
692
|
-
} catch {
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
try {
|
|
696
|
-
const agents = await ctx.db.query("agents").collect();
|
|
697
|
-
return agents.find(
|
|
698
|
-
(agent) => String(agent.principalId ?? "") === normalizedPrincipalId
|
|
699
|
-
) ?? null;
|
|
700
|
-
} catch {
|
|
701
|
-
return null;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
function defaultResolvers() {
|
|
705
|
-
return {
|
|
706
|
-
async getProject(ctx, topicId) {
|
|
707
|
-
return await resolveTopicProjectOverlay(ctx, topicId, {
|
|
708
|
-
idMode: "legacy",
|
|
709
|
-
projectLikeOnly: false
|
|
710
|
-
});
|
|
711
|
-
},
|
|
712
|
-
async listTopics(ctx) {
|
|
713
|
-
return await listTopicProjectOverlays(ctx, { idMode: "legacy" });
|
|
714
|
-
},
|
|
715
|
-
async listTopicsByOwner(ctx, ownerId) {
|
|
716
|
-
const topics = await listTopicProjectOverlays(ctx, { idMode: "legacy" });
|
|
717
|
-
return topics.filter((topic) => topic.ownerId === ownerId);
|
|
718
|
-
},
|
|
719
|
-
async listTopicsByVisibility(ctx, visibility) {
|
|
720
|
-
const topics = await listTopicProjectOverlays(ctx, { idMode: "legacy" });
|
|
721
|
-
return topics.filter((topic) => topic.visibility === visibility);
|
|
722
|
-
},
|
|
723
|
-
async listProjectGrantsByProjectAndPrincipal(ctx, topicId, principalId) {
|
|
724
|
-
return await bridgeListProjectGrantsByTopicAndPrincipal(
|
|
725
|
-
ctx,
|
|
726
|
-
topicId,
|
|
727
|
-
principalId
|
|
728
|
-
);
|
|
729
|
-
},
|
|
730
|
-
async listProjectGrantsByProjectAndGroup(ctx, topicId, groupId) {
|
|
731
|
-
return await bridgeListProjectGrantsByTopicAndGroup(ctx, topicId, groupId);
|
|
732
|
-
},
|
|
733
|
-
async listProjectGrantsByPrincipalStatus(ctx, principalId, status) {
|
|
734
|
-
return await bridgeListProjectGrantsByPrincipalStatus(
|
|
735
|
-
ctx,
|
|
736
|
-
principalId,
|
|
737
|
-
status
|
|
738
|
-
);
|
|
739
|
-
},
|
|
740
|
-
async listProjectGrantsByGroupStatus(ctx, groupId, status) {
|
|
741
|
-
return await bridgeListProjectGrantsByGroupStatus(ctx, groupId, status);
|
|
742
|
-
},
|
|
743
|
-
async insertProjectGrant(ctx, value) {
|
|
744
|
-
return await bridgeInsertProjectGrant(ctx, value);
|
|
745
|
-
},
|
|
746
|
-
async getAgentByPrincipalId(ctx, principalId) {
|
|
747
|
-
return await findAgentByPrincipalId(ctx, principalId);
|
|
748
|
-
},
|
|
749
|
-
async getUserByClerkId(ctx, clerkId) {
|
|
750
|
-
return await findUserByClerkId(ctx, clerkId);
|
|
751
|
-
},
|
|
752
|
-
async getUserByPrincipalId(ctx, principalId) {
|
|
753
|
-
return await findUserByPrincipalId(ctx, principalId);
|
|
754
|
-
}
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
var resolverOverrides = {};
|
|
758
|
-
function resolveAccessControlAppResolvers(_ctx) {
|
|
759
|
-
return {
|
|
760
|
-
...defaultResolvers(),
|
|
761
|
-
...resolverOverrides
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
// ../access-control/src/principalContext.ts
|
|
766
|
-
function requireCanonicalResolvedUser(user, clerkId) {
|
|
767
|
-
const resolved = user;
|
|
768
|
-
if (!resolved) {
|
|
769
|
-
throw new Error(
|
|
770
|
-
`[AccessControl] Canonical user identity required for ${clerkId}. Sync users.upsertUser before user-bound access checks.`
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
const { mcRole, defaultTenantId, defaultWorkspaceId, defaultPrincipalId } = resolved;
|
|
774
|
-
if (mcRole !== "platform_admin" && mcRole !== "tenant_admin" && mcRole !== "workspace_admin" && mcRole !== "editor" && mcRole !== "viewer" && mcRole !== "auditor" && mcRole !== "service_agent") {
|
|
775
|
-
throw new Error(
|
|
776
|
-
`[AccessControl] Canonical MC role required for ${clerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
777
|
-
);
|
|
778
|
-
}
|
|
779
|
-
if (typeof defaultTenantId !== "string" || defaultTenantId.trim().length === 0) {
|
|
780
|
-
throw new Error(
|
|
781
|
-
`[AccessControl] Canonical home tenant required for ${clerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
if (typeof defaultWorkspaceId !== "string" || defaultWorkspaceId.trim().length === 0) {
|
|
785
|
-
throw new Error(
|
|
786
|
-
`[AccessControl] Canonical home workspace required for ${clerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
787
|
-
);
|
|
788
|
-
}
|
|
789
|
-
if (typeof defaultPrincipalId !== "string" || defaultPrincipalId.trim().length === 0) {
|
|
790
|
-
throw new Error(
|
|
791
|
-
`[AccessControl] Canonical federated principal required for ${clerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
|
-
return {
|
|
795
|
-
mcRole,
|
|
796
|
-
defaultTenantId: defaultTenantId.trim(),
|
|
797
|
-
defaultWorkspaceId: defaultWorkspaceId.trim(),
|
|
798
|
-
defaultPrincipalId: defaultPrincipalId.trim()
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
function isPrincipalIdInput(value) {
|
|
802
|
-
return value.startsWith("user:") || value.startsWith("group:") || value.startsWith("service:") || value.startsWith("agent:") || value.startsWith("external_viewer:");
|
|
803
|
-
}
|
|
804
|
-
async function resolveCanonicalUserRecord(ctx, actorId) {
|
|
805
|
-
const normalizedActorId = actorId.trim();
|
|
806
|
-
const clerkId = isPrincipalIdInput(normalizedActorId) && normalizedActorId.startsWith("user:") ? normalizedActorId.slice("user:".length) : normalizedActorId;
|
|
807
|
-
const resolvers = resolveAccessControlAppResolvers();
|
|
808
|
-
const resolvedByClerkId = await resolvers.getUserByClerkId(ctx, clerkId);
|
|
809
|
-
if (resolvedByClerkId) {
|
|
810
|
-
return {
|
|
811
|
-
resolvedUser: resolvedByClerkId,
|
|
812
|
-
clerkId,
|
|
813
|
-
contextClerkId: clerkId
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
const resolvedByPrincipalId = await resolvers.getUserByPrincipalId(
|
|
817
|
-
ctx,
|
|
818
|
-
normalizedActorId
|
|
819
|
-
);
|
|
820
|
-
return {
|
|
821
|
-
resolvedUser: resolvedByPrincipalId ?? null,
|
|
822
|
-
clerkId,
|
|
823
|
-
contextClerkId: normalizedActorId.startsWith("user:") && clerkId.length > 0 ? clerkId : normalizedActorId
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
function uniqRoles(roles) {
|
|
827
|
-
const roleSet = /* @__PURE__ */ new Set();
|
|
828
|
-
for (const role of roles) {
|
|
829
|
-
if (role === "platform_admin" || role === "tenant_admin" || role === "workspace_admin" || role === "editor" || role === "viewer" || role === "auditor" || role === "service_agent") {
|
|
830
|
-
roleSet.add(role);
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
return [...roleSet];
|
|
834
|
-
}
|
|
835
|
-
function normalizeGroupIds(value) {
|
|
836
|
-
if (!Array.isArray(value)) {
|
|
837
|
-
return [];
|
|
838
|
-
}
|
|
839
|
-
return [...new Set(
|
|
840
|
-
value.filter((entry) => typeof entry === "string").map((entry) => entry.trim()).filter(Boolean)
|
|
841
|
-
)];
|
|
842
|
-
}
|
|
843
|
-
function requireServiceAgentUser(user, actorId) {
|
|
844
|
-
const canonicalUser = requireCanonicalResolvedUser(user, actorId);
|
|
845
|
-
if (canonicalUser.mcRole !== "service_agent") {
|
|
846
|
-
throw new Error(
|
|
847
|
-
`[AccessControl] Canonical service_agent identity required for ${actorId}. Sync users.upsertUser before agent-bound access checks.`
|
|
848
|
-
);
|
|
849
|
-
}
|
|
850
|
-
return canonicalUser;
|
|
851
|
-
}
|
|
852
|
-
function requireCanonicalResolvedAgent(agent, actorId) {
|
|
853
|
-
const resolved = agent;
|
|
854
|
-
if (!resolved) {
|
|
855
|
-
throw new Error(
|
|
856
|
-
`[AccessControl] Agent "${actorId}" not found in agents or users table.`
|
|
857
|
-
);
|
|
858
|
-
}
|
|
859
|
-
if (typeof resolved.principalId !== "string" || resolved.principalId.trim().length === 0) {
|
|
860
|
-
throw new Error(
|
|
861
|
-
`[AccessControl] Canonical agent principalId required for ${actorId}.`
|
|
862
|
-
);
|
|
863
|
-
}
|
|
864
|
-
if (typeof resolved.tenantId !== "string" || resolved.tenantId.trim().length === 0) {
|
|
865
|
-
throw new Error(
|
|
866
|
-
`[AccessControl] Canonical home tenant required for ${actorId}.`
|
|
867
|
-
);
|
|
868
|
-
}
|
|
869
|
-
if (typeof resolved.workspaceId !== "string" || resolved.workspaceId.trim().length === 0) {
|
|
870
|
-
throw new Error(
|
|
871
|
-
`[AccessControl] Canonical home workspace required for ${actorId}.`
|
|
872
|
-
);
|
|
873
|
-
}
|
|
874
|
-
return {
|
|
875
|
-
principalId: resolved.principalId.trim(),
|
|
876
|
-
tenantId: resolved.tenantId.trim(),
|
|
877
|
-
workspaceId: resolved.workspaceId.trim(),
|
|
878
|
-
roles: uniqRoles(Array.isArray(resolved.roles) ? resolved.roles : []) ?? ["service_agent"],
|
|
879
|
-
groupIds: normalizeGroupIds(resolved.groupIds)
|
|
880
|
-
};
|
|
881
|
-
}
|
|
882
|
-
async function resolvePrincipalContext(ctx, actorId) {
|
|
883
|
-
if (actorId.startsWith("agent:")) {
|
|
884
|
-
const resolvers = resolveAccessControlAppResolvers();
|
|
885
|
-
const resolvedAgent = await resolvers.getAgentByPrincipalId(ctx, actorId);
|
|
886
|
-
if (resolvedAgent) {
|
|
887
|
-
const agent = requireCanonicalResolvedAgent(
|
|
888
|
-
resolvedAgent,
|
|
889
|
-
actorId
|
|
890
|
-
);
|
|
891
|
-
return {
|
|
892
|
-
principalId: agent.principalId,
|
|
893
|
-
principalType: "service",
|
|
894
|
-
clerkId: actorId,
|
|
895
|
-
tenantId: agent.tenantId,
|
|
896
|
-
workspaceId: agent.workspaceId,
|
|
897
|
-
roles: agent.roles.length > 0 ? agent.roles : ["service_agent"],
|
|
898
|
-
groupIds: agent.groupIds,
|
|
899
|
-
isPlatformAdmin: false,
|
|
900
|
-
isTenantAdmin: false,
|
|
901
|
-
isWorkspaceAdmin: false,
|
|
902
|
-
isSystemFallback: false
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
const resolvedUser2 = await resolvers.getUserByClerkId(
|
|
906
|
-
ctx,
|
|
907
|
-
actorId
|
|
908
|
-
);
|
|
909
|
-
if (!resolvedUser2) {
|
|
910
|
-
throw new Error(
|
|
911
|
-
`[AccessControl] Agent "${actorId}" not found in agents or users table.`
|
|
912
|
-
);
|
|
913
|
-
}
|
|
914
|
-
const user2 = requireServiceAgentUser(
|
|
915
|
-
resolvedUser2,
|
|
916
|
-
actorId
|
|
917
|
-
);
|
|
918
|
-
console.warn(
|
|
919
|
-
`[AccessControl] Deprecated legacy service-agent fallback for ${actorId}; migrate this principal into identity.agents.`
|
|
920
|
-
);
|
|
921
|
-
return {
|
|
922
|
-
principalId: user2.defaultPrincipalId,
|
|
923
|
-
principalType: "service",
|
|
924
|
-
clerkId: actorId,
|
|
925
|
-
tenantId: user2.defaultTenantId,
|
|
926
|
-
workspaceId: user2.defaultWorkspaceId,
|
|
927
|
-
roles: ["service_agent"],
|
|
928
|
-
groupIds: normalizeGroupIds(resolvedUser2?.principalGroupIds),
|
|
929
|
-
isPlatformAdmin: false,
|
|
930
|
-
isTenantAdmin: false,
|
|
931
|
-
isWorkspaceAdmin: false,
|
|
932
|
-
isSystemFallback: false
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
const {
|
|
936
|
-
resolvedUser,
|
|
937
|
-
contextClerkId
|
|
938
|
-
} = await resolveCanonicalUserRecord(ctx, actorId);
|
|
939
|
-
const user = requireCanonicalResolvedUser(
|
|
940
|
-
resolvedUser,
|
|
941
|
-
contextClerkId
|
|
942
|
-
);
|
|
943
|
-
if (!user.defaultPrincipalId) {
|
|
944
|
-
throw new Error(
|
|
945
|
-
`[AccessControl] Canonical federated principal required for ${contextClerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
946
|
-
);
|
|
947
|
-
}
|
|
948
|
-
if (user.mcRole === "service_agent") {
|
|
949
|
-
return {
|
|
950
|
-
principalId: user.defaultPrincipalId,
|
|
951
|
-
principalType: "service",
|
|
952
|
-
clerkId: contextClerkId,
|
|
953
|
-
tenantId: user.defaultTenantId,
|
|
954
|
-
workspaceId: user.defaultWorkspaceId,
|
|
955
|
-
roles: ["service_agent"],
|
|
956
|
-
groupIds: normalizeGroupIds(resolvedUser?.principalGroupIds),
|
|
957
|
-
isPlatformAdmin: false,
|
|
958
|
-
isTenantAdmin: false,
|
|
959
|
-
isWorkspaceAdmin: false,
|
|
960
|
-
isSystemFallback: false
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
const principalId = user.defaultPrincipalId;
|
|
964
|
-
const effectiveRole = user.mcRole;
|
|
965
|
-
const roles = effectiveRole === "platform_admin" ? ["platform_admin", "tenant_admin"] : effectiveRole === "tenant_admin" ? ["tenant_admin"] : [effectiveRole];
|
|
966
|
-
const tenantId = user.defaultTenantId;
|
|
967
|
-
const workspaceId = user.defaultWorkspaceId;
|
|
968
|
-
const isPlatformAdmin = effectiveRole === "platform_admin";
|
|
969
|
-
return {
|
|
970
|
-
principalId,
|
|
971
|
-
principalType: "user",
|
|
972
|
-
clerkId: contextClerkId,
|
|
973
|
-
tenantId,
|
|
974
|
-
workspaceId,
|
|
975
|
-
roles: uniqRoles(roles),
|
|
976
|
-
groupIds: normalizeGroupIds(resolvedUser?.principalGroupIds),
|
|
977
|
-
isPlatformAdmin,
|
|
978
|
-
isTenantAdmin: isPlatformAdmin || effectiveRole === "tenant_admin",
|
|
979
|
-
isWorkspaceAdmin: isPlatformAdmin || effectiveRole === "tenant_admin" || effectiveRole === "workspace_admin",
|
|
980
|
-
isSystemFallback: false
|
|
981
|
-
};
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
// ../access-control/src/access.ts
|
|
985
|
-
function isTopicInPrincipalTenant(topic, principalTenantId) {
|
|
986
|
-
if (!topic.tenantId) {
|
|
987
|
-
return false;
|
|
988
|
-
}
|
|
989
|
-
if (!principalTenantId) {
|
|
990
|
-
return false;
|
|
991
|
-
}
|
|
992
|
-
return String(topic.tenantId) === String(principalTenantId);
|
|
993
|
-
}
|
|
994
|
-
function isTopicInPrincipalWorkspace(topic, principalWorkspaceId) {
|
|
995
|
-
if (!topic.workspaceId) {
|
|
996
|
-
return false;
|
|
997
|
-
}
|
|
998
|
-
if (!principalWorkspaceId) {
|
|
999
|
-
return false;
|
|
1000
|
-
}
|
|
1001
|
-
return String(topic.workspaceId) === String(principalWorkspaceId);
|
|
1002
|
-
}
|
|
1003
|
-
function isLegacyUnscopedTopic(topic) {
|
|
1004
|
-
return !topic.tenantId || !topic.workspaceId;
|
|
1005
|
-
}
|
|
1006
|
-
function isGrantScopeAlignedToTopic(topic, grant) {
|
|
1007
|
-
if (topic.tenantId && grant.tenantId && String(topic.tenantId) !== String(grant.tenantId)) {
|
|
1008
|
-
return false;
|
|
1009
|
-
}
|
|
1010
|
-
if (topic.workspaceId && grant.workspaceId && String(topic.workspaceId) !== String(grant.workspaceId)) {
|
|
1011
|
-
return false;
|
|
1012
|
-
}
|
|
1013
|
-
return true;
|
|
1014
|
-
}
|
|
1015
|
-
function isGrantSourceAllowedForVisibility(visibility, source) {
|
|
1016
|
-
if (source !== "external_share") {
|
|
1017
|
-
return true;
|
|
1018
|
-
}
|
|
1019
|
-
return visibility === "external" || visibility === "public";
|
|
1020
|
-
}
|
|
1021
|
-
function isGrantActive(grant) {
|
|
1022
|
-
if (grant.status !== "active") {
|
|
1023
|
-
return false;
|
|
1024
|
-
}
|
|
1025
|
-
if (grant.expiresAt !== void 0 && grant.expiresAt <= Date.now()) {
|
|
1026
|
-
return false;
|
|
1027
|
-
}
|
|
1028
|
-
return true;
|
|
1029
|
-
}
|
|
1030
|
-
async function hasPrincipalGrant(ctx, args) {
|
|
1031
|
-
const grants = await resolveAccessControlAppResolvers().listProjectGrantsByProjectAndPrincipal(
|
|
1032
|
-
ctx,
|
|
1033
|
-
args.topic._id,
|
|
1034
|
-
args.principalId
|
|
1035
|
-
);
|
|
1036
|
-
if (grants.some(
|
|
1037
|
-
(grant) => isGrantActive(grant) && isGrantScopeAlignedToTopic(args.topic, grant) && isGrantSourceAllowedForVisibility(
|
|
1038
|
-
args.topic.visibility,
|
|
1039
|
-
grant.source
|
|
1040
|
-
) && (!args.principalIsExternal || args.topic.visibility === "public" || grant.source === "external_share")
|
|
1041
|
-
)) {
|
|
1042
|
-
return true;
|
|
1043
|
-
}
|
|
1044
|
-
return false;
|
|
1045
|
-
}
|
|
1046
|
-
async function hasGroupGrant(ctx, args) {
|
|
1047
|
-
if (args.groupIds.length === 0) {
|
|
1048
|
-
return false;
|
|
1049
|
-
}
|
|
1050
|
-
for (const groupId of args.groupIds) {
|
|
1051
|
-
const grants = await resolveAccessControlAppResolvers().listProjectGrantsByProjectAndGroup(ctx, args.topic._id, groupId);
|
|
1052
|
-
if (grants.some(
|
|
1053
|
-
(grant) => isGrantActive(grant) && isGrantScopeAlignedToTopic(args.topic, grant) && isGrantSourceAllowedForVisibility(
|
|
1054
|
-
args.topic.visibility,
|
|
1055
|
-
grant.source
|
|
1056
|
-
)
|
|
1057
|
-
)) {
|
|
1058
|
-
return true;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
return false;
|
|
1062
|
-
}
|
|
1063
|
-
function isExternalPrincipal(_ctx, _args) {
|
|
1064
|
-
return false;
|
|
1065
|
-
}
|
|
1066
|
-
async function evaluateTopicAccessDetailed(ctx, args) {
|
|
1067
|
-
if (args.legacyUserId) {
|
|
1068
|
-
return {
|
|
1069
|
-
hasAccess: true,
|
|
1070
|
-
isAdmin: false,
|
|
1071
|
-
isOwner: false,
|
|
1072
|
-
isShared: false,
|
|
1073
|
-
hasGrant: true,
|
|
1074
|
-
isFirmVisible: true,
|
|
1075
|
-
isExternalVisible: false,
|
|
1076
|
-
isPublicVisible: false,
|
|
1077
|
-
isTenantScopeMatch: true,
|
|
1078
|
-
isWorkspaceScopeMatch: true,
|
|
1079
|
-
isPrincipalExternal: false
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
const topic = await resolveAccessControlAppResolvers().getProject(
|
|
1083
|
-
ctx,
|
|
1084
|
-
args.topicId
|
|
1085
|
-
);
|
|
1086
|
-
if (!topic) {
|
|
1087
|
-
return {
|
|
1088
|
-
hasAccess: false,
|
|
1089
|
-
isAdmin: false,
|
|
1090
|
-
isOwner: false,
|
|
1091
|
-
isShared: false,
|
|
1092
|
-
hasGrant: false,
|
|
1093
|
-
isFirmVisible: false,
|
|
1094
|
-
isExternalVisible: false,
|
|
1095
|
-
isPublicVisible: false,
|
|
1096
|
-
isTenantScopeMatch: false,
|
|
1097
|
-
isWorkspaceScopeMatch: false,
|
|
1098
|
-
isPrincipalExternal: false
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
const { principalContext, legacyUserId } = args;
|
|
1102
|
-
const userIsAdmin = principalContext.isPlatformAdmin;
|
|
1103
|
-
const isOwner = topic.ownerId === legacyUserId;
|
|
1104
|
-
const isShared = (topic.sharedWith ?? []).includes(legacyUserId);
|
|
1105
|
-
const principalIsExternal = await isExternalPrincipal(ctx, {
|
|
1106
|
-
groupIds: principalContext.groupIds,
|
|
1107
|
-
topicTenantId: topic.tenantId,
|
|
1108
|
-
topicWorkspaceId: topic.workspaceId
|
|
1109
|
-
});
|
|
1110
|
-
const hasPrincipalGrantResult = await hasPrincipalGrant(ctx, {
|
|
1111
|
-
topic,
|
|
1112
|
-
principalId: principalContext.principalId,
|
|
1113
|
-
principalIsExternal
|
|
1114
|
-
});
|
|
1115
|
-
const hasGroupGrantResult = await hasGroupGrant(ctx, {
|
|
1116
|
-
topic,
|
|
1117
|
-
groupIds: principalContext.groupIds
|
|
1118
|
-
});
|
|
1119
|
-
const hasGrant = isShared || hasPrincipalGrantResult || hasGroupGrantResult;
|
|
1120
|
-
const legacyUnscoped = isLegacyUnscopedTopic(topic);
|
|
1121
|
-
const tenantScopeMatch = isTopicInPrincipalTenant(
|
|
1122
|
-
topic,
|
|
1123
|
-
principalContext.tenantId
|
|
1124
|
-
);
|
|
1125
|
-
const workspaceScopeMatch = isTopicInPrincipalWorkspace(
|
|
1126
|
-
topic,
|
|
1127
|
-
principalContext.workspaceId
|
|
1128
|
-
);
|
|
1129
|
-
const isPublicVisible = topic.visibility === "public";
|
|
1130
|
-
const isFirmVisible = topic.visibility === "firm" && !legacyUnscoped && tenantScopeMatch && workspaceScopeMatch && !principalIsExternal;
|
|
1131
|
-
const hasScopedGrant = hasGrant && (legacyUnscoped || tenantScopeMatch && workspaceScopeMatch);
|
|
1132
|
-
const isExternalVisible = topic.visibility === "external" && hasScopedGrant;
|
|
1133
|
-
const hasAccess = userIsAdmin || isOwner || hasScopedGrant || isPublicVisible || isFirmVisible;
|
|
1134
|
-
return {
|
|
1135
|
-
hasAccess,
|
|
1136
|
-
isAdmin: userIsAdmin,
|
|
1137
|
-
isOwner,
|
|
1138
|
-
isShared,
|
|
1139
|
-
hasGrant,
|
|
1140
|
-
isFirmVisible,
|
|
1141
|
-
isExternalVisible,
|
|
1142
|
-
isPublicVisible,
|
|
1143
|
-
isTenantScopeMatch: tenantScopeMatch,
|
|
1144
|
-
isWorkspaceScopeMatch: workspaceScopeMatch,
|
|
1145
|
-
isPrincipalExternal: principalIsExternal
|
|
1146
|
-
};
|
|
1147
|
-
}
|
|
1148
|
-
async function checkTopicAccessDetailed(ctx, topicId, userId) {
|
|
1149
|
-
const principalContext = await resolvePrincipalContext(ctx, userId);
|
|
1150
|
-
return evaluateTopicAccessDetailed(ctx, {
|
|
1151
|
-
topicId,
|
|
1152
|
-
legacyUserId: userId,
|
|
1153
|
-
principalContext
|
|
1154
|
-
});
|
|
1155
|
-
}
|
|
1156
|
-
async function checkTopicAccess(ctx, topicId, userId) {
|
|
1157
|
-
const result = await checkTopicAccessDetailed(ctx, topicId, userId);
|
|
1158
|
-
return result.hasAccess;
|
|
1159
|
-
}
|
|
1160
|
-
var checkProjectAccess = checkTopicAccess;
|
|
1161
|
-
var permissiveReturn = v.optional(v.any());
|
|
1162
|
-
var looseJsonObject = v.record(v.string(), v.any());
|
|
1163
|
-
var looseJsonArray = v.array(v.any());
|
|
1164
|
-
v.union(
|
|
1165
|
-
v.string(),
|
|
1166
|
-
v.number(),
|
|
1167
|
-
v.boolean(),
|
|
1168
|
-
v.null(),
|
|
1169
|
-
looseJsonObject,
|
|
1170
|
-
looseJsonArray
|
|
1171
|
-
);
|
|
1172
|
-
|
|
1173
|
-
// src/epistemicLinking.ts
|
|
1174
391
|
var RELATION_TO_EDGE_TYPE = {
|
|
1175
392
|
// Cross-type: Evidence → Belief
|
|
1176
393
|
supports: "informs",
|