@powerhousedao/vetra 6.0.0-dev.6 → 6.0.0-dev.61
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/document-models/app-module/actions.d.ts +1 -1
- package/dist/document-models/app-module/actions.d.ts.map +1 -1
- package/dist/document-models/app-module/hooks.d.ts.map +1 -1
- package/dist/document-models/app-module/module.d.ts.map +1 -1
- package/dist/document-models/app-module/module.js +1 -0
- package/dist/document-models/app-module/src/tests/base-operations.test.js +2 -2
- package/dist/document-models/app-module/src/tests/dnd-operations.test.js +1 -1
- package/dist/document-models/document-editor/actions.d.ts +1 -1
- package/dist/document-models/document-editor/actions.d.ts.map +1 -1
- package/dist/document-models/document-editor/hooks.d.ts.map +1 -1
- package/dist/document-models/document-editor/module.d.ts.map +1 -1
- package/dist/document-models/document-editor/module.js +1 -0
- package/dist/document-models/document-editor/src/tests/base-operations.test.js +2 -2
- package/dist/document-models/processor-module/actions.d.ts +3 -1
- package/dist/document-models/processor-module/actions.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/base-operations/actions.d.ts +10 -2
- package/dist/document-models/processor-module/gen/base-operations/actions.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/base-operations/creators.d.ts +4 -2
- package/dist/document-models/processor-module/gen/base-operations/creators.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/base-operations/creators.js +3 -1
- package/dist/document-models/processor-module/gen/base-operations/operations.d.ts +3 -1
- package/dist/document-models/processor-module/gen/base-operations/operations.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/document-model.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/document-model.js +24 -2
- package/dist/document-models/processor-module/gen/document-schema.d.ts +3 -0
- package/dist/document-models/processor-module/gen/document-schema.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/ph-factories.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/ph-factories.js +1 -0
- package/dist/document-models/processor-module/gen/reducer.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/reducer.js +11 -1
- package/dist/document-models/processor-module/gen/schema/types.d.ts +7 -0
- package/dist/document-models/processor-module/gen/schema/types.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/schema/zod.d.ts +3 -1
- package/dist/document-models/processor-module/gen/schema/zod.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/schema/zod.js +11 -0
- package/dist/document-models/processor-module/gen/utils.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/utils.js +1 -0
- package/dist/document-models/processor-module/hooks.d.ts.map +1 -1
- package/dist/document-models/processor-module/module.d.ts.map +1 -1
- package/dist/document-models/processor-module/module.js +1 -0
- package/dist/document-models/processor-module/src/reducers/base-operations.d.ts.map +1 -1
- package/dist/document-models/processor-module/src/reducers/base-operations.js +14 -0
- package/dist/document-models/processor-module/src/tests/base-operations.test.js +26 -2
- package/dist/document-models/subgraph-module/actions.d.ts +1 -1
- package/dist/document-models/subgraph-module/actions.d.ts.map +1 -1
- package/dist/document-models/subgraph-module/hooks.d.ts.map +1 -1
- package/dist/document-models/subgraph-module/module.d.ts.map +1 -1
- package/dist/document-models/subgraph-module/module.js +1 -0
- package/dist/document-models/subgraph-module/src/tests/base-operations.test.js +2 -2
- package/dist/document-models/vetra-package/actions.d.ts +1 -1
- package/dist/document-models/vetra-package/actions.d.ts.map +1 -1
- package/dist/document-models/vetra-package/gen/schema/zod.js +7 -7
- package/dist/document-models/vetra-package/hooks.d.ts.map +1 -1
- package/dist/document-models/vetra-package/module.d.ts.map +1 -1
- package/dist/document-models/vetra-package/module.js +1 -0
- package/dist/document-models/vetra-package/src/tests/base-operations.test.js +1 -1
- package/dist/editors/app-editor/components/AppEditorForm.js +1 -1
- package/dist/editors/app-editor/editor.js +1 -1
- package/dist/editors/app-editor/editor.test.js +8 -1
- package/dist/editors/document-editor/components/DocumentEditorForm.js +1 -1
- package/dist/editors/document-editor/editor.js +1 -1
- package/dist/editors/processor-editor/components/ProcessorEditorForm.d.ts +4 -0
- package/dist/editors/processor-editor/components/ProcessorEditorForm.d.ts.map +1 -1
- package/dist/editors/processor-editor/components/ProcessorEditorForm.js +32 -6
- package/dist/editors/processor-editor/editor.d.ts.map +1 -1
- package/dist/editors/processor-editor/editor.js +7 -1
- package/dist/editors/processor-editor/editor.test.js +166 -173
- package/dist/editors/subgraph-editor/components/SubgraphEditorForm.js +1 -1
- package/dist/editors/subgraph-editor/editor.js +1 -1
- package/dist/editors/vetra-drive-app/DriveExplorer.js +1 -1
- package/dist/editors/vetra-drive-app/components/DriveHeader.js +1 -1
- package/dist/editors/vetra-drive-app/editor.js +1 -1
- package/dist/editors/vetra-package/components/MetaForm.js +1 -1
- package/dist/editors/vetra-package/editor.js +1 -1
- package/dist/processors/codegen/__tests__/codegen-processor-e2e.test.js +46 -22
- package/dist/processors/codegen/document-handlers/generators/app-generator.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/app-generator.js +12 -6
- package/dist/processors/codegen/document-handlers/generators/constants.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/constants.js +1 -0
- package/dist/processors/codegen/document-handlers/generators/document-editor-generator.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/document-editor-generator.js +10 -4
- package/dist/processors/codegen/document-handlers/generators/document-model-generator.d.ts +4 -0
- package/dist/processors/codegen/document-handlers/generators/document-model-generator.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/document-model-generator.js +42 -20
- package/dist/processors/codegen/document-handlers/generators/package-generator.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/package-generator.js +8 -2
- package/dist/processors/codegen/document-handlers/generators/processor-generator.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/processor-generator.js +38 -3
- package/dist/processors/codegen/document-handlers/generators/subgraph-generator.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/subgraph-generator.js +8 -2
- package/dist/processors/codegen/document-handlers/generators/utils.d.ts +7 -0
- package/dist/processors/codegen/document-handlers/generators/utils.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/utils.js +18 -1
- package/dist/processors/codegen/factory.d.ts +1 -1
- package/dist/processors/codegen/factory.d.ts.map +1 -1
- package/dist/processors/codegen/factory.legacy.d.ts +4 -0
- package/dist/processors/codegen/factory.legacy.d.ts.map +1 -0
- package/dist/processors/codegen/factory.legacy.js +53 -0
- package/dist/processors/codegen/index.d.ts +2 -2
- package/dist/processors/codegen/index.d.ts.map +1 -1
- package/dist/processors/codegen/index.js +22 -21
- package/dist/processors/codegen/index.legacy.d.ts +11 -0
- package/dist/processors/codegen/index.legacy.d.ts.map +1 -0
- package/dist/processors/codegen/index.legacy.js +57 -0
- package/dist/processors/factory.d.ts +3 -4
- package/dist/processors/factory.d.ts.map +1 -1
- package/dist/processors/factory.js +5 -4
- package/dist/processors/factory.legacy.d.ts +7 -0
- package/dist/processors/factory.legacy.d.ts.map +1 -0
- package/dist/processors/factory.legacy.js +19 -0
- package/dist/processors/index.d.ts +8 -2
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +10 -2
- package/dist/processors/vetra-read-model/factory.d.ts +2 -2
- package/dist/processors/vetra-read-model/factory.d.ts.map +1 -1
- package/dist/processors/vetra-read-model/factory.js +13 -16
- package/dist/processors/vetra-read-model/factory.legacy.d.ts +5 -0
- package/dist/processors/vetra-read-model/factory.legacy.d.ts.map +1 -0
- package/dist/processors/vetra-read-model/factory.legacy.js +24 -0
- package/dist/processors/vetra-read-model/index.d.ts +6 -5
- package/dist/processors/vetra-read-model/index.d.ts.map +1 -1
- package/dist/processors/vetra-read-model/index.js +20 -37
- package/dist/processors/vetra-read-model/index.legacy.d.ts +9 -0
- package/dist/processors/vetra-read-model/index.legacy.d.ts.map +1 -0
- package/dist/processors/vetra-read-model/index.legacy.js +75 -0
- package/dist/processors/vetra-read-model/migrations.d.ts +3 -3
- package/dist/processors/vetra-read-model/migrations.d.ts.map +1 -1
- package/dist/style.css +4 -1
- package/dist/subgraphs/__tests__/permission-utils.test.d.ts +2 -0
- package/dist/subgraphs/__tests__/permission-utils.test.d.ts.map +1 -0
- package/dist/subgraphs/__tests__/permission-utils.test.js +348 -0
- package/dist/subgraphs/__tests__/vetra-read-model-permissions.test.d.ts +2 -0
- package/dist/subgraphs/__tests__/vetra-read-model-permissions.test.d.ts.map +1 -0
- package/dist/subgraphs/__tests__/vetra-read-model-permissions.test.js +289 -0
- package/dist/subgraphs/index.d.ts +0 -5
- package/dist/subgraphs/index.d.ts.map +1 -1
- package/dist/subgraphs/index.js +0 -5
- package/dist/subgraphs/permission-utils.d.ts +30 -0
- package/dist/subgraphs/permission-utils.d.ts.map +1 -0
- package/dist/subgraphs/permission-utils.js +97 -0
- package/dist/subgraphs/vetra-read-model/resolvers.d.ts +2 -2
- package/dist/subgraphs/vetra-read-model/resolvers.d.ts.map +1 -1
- package/dist/subgraphs/vetra-read-model/resolvers.js +18 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/vitest.config.d.ts.map +1 -1
- package/dist/vitest.config.js +1 -0
- package/package.json +31 -42
- package/dist/subgraphs/app-module/index.d.ts +0 -11
- package/dist/subgraphs/app-module/index.d.ts.map +0 -1
- package/dist/subgraphs/app-module/index.js +0 -11
- package/dist/subgraphs/app-module/resolvers.d.ts +0 -3
- package/dist/subgraphs/app-module/resolvers.d.ts.map +0 -1
- package/dist/subgraphs/app-module/resolvers.js +0 -144
- package/dist/subgraphs/app-module/schema.d.ts +0 -3
- package/dist/subgraphs/app-module/schema.d.ts.map +0 -1
- package/dist/subgraphs/app-module/schema.js +0 -78
- package/dist/subgraphs/document-editor/index.d.ts +0 -11
- package/dist/subgraphs/document-editor/index.d.ts.map +0 -1
- package/dist/subgraphs/document-editor/index.js +0 -11
- package/dist/subgraphs/document-editor/resolvers.d.ts +0 -3
- package/dist/subgraphs/document-editor/resolvers.d.ts.map +0 -1
- package/dist/subgraphs/document-editor/resolvers.js +0 -120
- package/dist/subgraphs/document-editor/schema.d.ts +0 -3
- package/dist/subgraphs/document-editor/schema.d.ts.map +0 -1
- package/dist/subgraphs/document-editor/schema.js +0 -59
- package/dist/subgraphs/processor-module/index.d.ts +0 -10
- package/dist/subgraphs/processor-module/index.d.ts.map +0 -1
- package/dist/subgraphs/processor-module/index.js +0 -11
- package/dist/subgraphs/processor-module/resolvers.d.ts +0 -3
- package/dist/subgraphs/processor-module/resolvers.d.ts.map +0 -1
- package/dist/subgraphs/processor-module/resolvers.js +0 -132
- package/dist/subgraphs/processor-module/schema.d.ts +0 -3
- package/dist/subgraphs/processor-module/schema.d.ts.map +0 -1
- package/dist/subgraphs/processor-module/schema.js +0 -67
- package/dist/subgraphs/subgraph-module/index.d.ts +0 -10
- package/dist/subgraphs/subgraph-module/index.d.ts.map +0 -1
- package/dist/subgraphs/subgraph-module/index.js +0 -11
- package/dist/subgraphs/subgraph-module/resolvers.d.ts +0 -3
- package/dist/subgraphs/subgraph-module/resolvers.d.ts.map +0 -1
- package/dist/subgraphs/subgraph-module/resolvers.js +0 -96
- package/dist/subgraphs/subgraph-module/schema.d.ts +0 -3
- package/dist/subgraphs/subgraph-module/schema.d.ts.map +0 -1
- package/dist/subgraphs/subgraph-module/schema.js +0 -42
- package/dist/subgraphs/vetra-package/index.d.ts +0 -10
- package/dist/subgraphs/vetra-package/index.d.ts.map +0 -1
- package/dist/subgraphs/vetra-package/index.js +0 -11
- package/dist/subgraphs/vetra-package/resolvers.d.ts +0 -3
- package/dist/subgraphs/vetra-package/resolvers.d.ts.map +0 -1
- package/dist/subgraphs/vetra-package/resolvers.js +0 -192
- package/dist/subgraphs/vetra-package/schema.d.ts +0 -3
- package/dist/subgraphs/vetra-package/schema.d.ts.map +0 -1
- package/dist/subgraphs/vetra-package/schema.js +0 -108
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
export * as AppModuleSubgraph from "./app-module/index.js";
|
|
2
|
-
export * as ProcessorModuleSubgraph from "./processor-module/index.js";
|
|
3
|
-
export * as SubgraphModuleSubgraph from "./subgraph-module/index.js";
|
|
4
|
-
export * as VetraPackageSubgraph from "./vetra-package/index.js";
|
|
5
1
|
export * as VetraReadModelSubgraph from "./vetra-read-model/index.js";
|
|
6
|
-
export * as DocumentEditorSubgraph from "./document-editor/index.js";
|
|
7
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../subgraphs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../subgraphs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC"}
|
package/dist/subgraphs/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
export * as AppModuleSubgraph from "./app-module/index.js";
|
|
2
|
-
export * as ProcessorModuleSubgraph from "./processor-module/index.js";
|
|
3
|
-
export * as SubgraphModuleSubgraph from "./subgraph-module/index.js";
|
|
4
|
-
export * as VetraPackageSubgraph from "./vetra-package/index.js";
|
|
5
1
|
export * as VetraReadModelSubgraph from "./vetra-read-model/index.js";
|
|
6
|
-
export * as DocumentEditorSubgraph from "./document-editor/index.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BaseSubgraph, Context } from "@powerhousedao/reactor-api";
|
|
2
|
+
/**
|
|
3
|
+
* Check if user has global admin access.
|
|
4
|
+
* Legacy fallback when authorizationService is not available.
|
|
5
|
+
*/
|
|
6
|
+
export declare function hasGlobalAdminAccess(ctx: Context): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Check if user can read a document (with hierarchy).
|
|
9
|
+
* Delegates to AuthorizationService when available.
|
|
10
|
+
*/
|
|
11
|
+
export declare function canReadDocument(subgraph: BaseSubgraph, documentId: string, ctx: Context): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Check if user can write to a document (with hierarchy).
|
|
14
|
+
* Delegates to AuthorizationService when available.
|
|
15
|
+
*/
|
|
16
|
+
export declare function canWriteDocument(subgraph: BaseSubgraph, documentId: string, ctx: Context): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Throw an error if user cannot read the document
|
|
19
|
+
*/
|
|
20
|
+
export declare function assertCanRead(subgraph: BaseSubgraph, documentId: string, ctx: Context): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Throw an error if user cannot write to the document
|
|
23
|
+
*/
|
|
24
|
+
export declare function assertCanWrite(subgraph: BaseSubgraph, documentId: string, ctx: Context): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if user can execute a specific operation on a document.
|
|
27
|
+
* Delegates to AuthorizationService.canMutate when available.
|
|
28
|
+
*/
|
|
29
|
+
export declare function assertCanExecuteOperation(subgraph: BaseSubgraph, documentId: string, operationType: string, ctx: Context): Promise<void>;
|
|
30
|
+
//# sourceMappingURL=permission-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-utils.d.ts","sourceRoot":"","sources":["../../subgraphs/permission-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAiBxE;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAE1D;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,OAAO,CAAC,CAkBlB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,OAAO,CAAC,CAkBlB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC,CAwCf"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { GraphQLError } from "graphql";
|
|
2
|
+
/**
|
|
3
|
+
* Get the parent IDs function for hierarchical permission checks
|
|
4
|
+
*/
|
|
5
|
+
function getParentIdsFn(subgraph) {
|
|
6
|
+
return async (documentId) => {
|
|
7
|
+
try {
|
|
8
|
+
const result = await subgraph.reactorClient.getParents(documentId);
|
|
9
|
+
return result.results.map((doc) => doc.header.id);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check if user has global admin access.
|
|
18
|
+
* Legacy fallback when authorizationService is not available.
|
|
19
|
+
*/
|
|
20
|
+
export function hasGlobalAdminAccess(ctx) {
|
|
21
|
+
return !!ctx.isAdmin?.(ctx.user?.address ?? "");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check if user can read a document (with hierarchy).
|
|
25
|
+
* Delegates to AuthorizationService when available.
|
|
26
|
+
*/
|
|
27
|
+
export async function canReadDocument(subgraph, documentId, ctx) {
|
|
28
|
+
if (subgraph.authorizationService) {
|
|
29
|
+
return subgraph.authorizationService.canRead(documentId, ctx.user?.address, getParentIdsFn(subgraph));
|
|
30
|
+
}
|
|
31
|
+
// Legacy fallback
|
|
32
|
+
if (hasGlobalAdminAccess(ctx))
|
|
33
|
+
return true;
|
|
34
|
+
if (subgraph.documentPermissionService) {
|
|
35
|
+
return subgraph.documentPermissionService.canRead(documentId, ctx.user?.address, getParentIdsFn(subgraph));
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if user can write to a document (with hierarchy).
|
|
41
|
+
* Delegates to AuthorizationService when available.
|
|
42
|
+
*/
|
|
43
|
+
export async function canWriteDocument(subgraph, documentId, ctx) {
|
|
44
|
+
if (subgraph.authorizationService) {
|
|
45
|
+
return subgraph.authorizationService.canWrite(documentId, ctx.user?.address, getParentIdsFn(subgraph));
|
|
46
|
+
}
|
|
47
|
+
// Legacy fallback
|
|
48
|
+
if (hasGlobalAdminAccess(ctx))
|
|
49
|
+
return true;
|
|
50
|
+
if (subgraph.documentPermissionService) {
|
|
51
|
+
return subgraph.documentPermissionService.canWrite(documentId, ctx.user?.address, getParentIdsFn(subgraph));
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Throw an error if user cannot read the document
|
|
57
|
+
*/
|
|
58
|
+
export async function assertCanRead(subgraph, documentId, ctx) {
|
|
59
|
+
const canRead = await canReadDocument(subgraph, documentId, ctx);
|
|
60
|
+
if (!canRead) {
|
|
61
|
+
throw new GraphQLError("Forbidden: insufficient permissions to read this document");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Throw an error if user cannot write to the document
|
|
66
|
+
*/
|
|
67
|
+
export async function assertCanWrite(subgraph, documentId, ctx) {
|
|
68
|
+
const canWrite = await canWriteDocument(subgraph, documentId, ctx);
|
|
69
|
+
if (!canWrite) {
|
|
70
|
+
throw new GraphQLError("Forbidden: insufficient permissions to write to this document");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Check if user can execute a specific operation on a document.
|
|
75
|
+
* Delegates to AuthorizationService.canMutate when available.
|
|
76
|
+
*/
|
|
77
|
+
export async function assertCanExecuteOperation(subgraph, documentId, operationType, ctx) {
|
|
78
|
+
if (subgraph.authorizationService) {
|
|
79
|
+
const canMutate = await subgraph.authorizationService.canMutate(documentId, operationType, ctx.user?.address, getParentIdsFn(subgraph));
|
|
80
|
+
if (!canMutate) {
|
|
81
|
+
throw new GraphQLError(`Forbidden: insufficient permissions to execute operation "${operationType}" on this document`);
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Legacy fallback
|
|
86
|
+
if (!subgraph.documentPermissionService)
|
|
87
|
+
return;
|
|
88
|
+
if (ctx.isAdmin?.(ctx.user?.address ?? ""))
|
|
89
|
+
return;
|
|
90
|
+
const isRestricted = await subgraph.documentPermissionService.isOperationRestricted(documentId, operationType);
|
|
91
|
+
if (isRestricted) {
|
|
92
|
+
const canExecute = await subgraph.documentPermissionService.canExecuteOperation(documentId, operationType, ctx.user?.address);
|
|
93
|
+
if (!canExecute) {
|
|
94
|
+
throw new GraphQLError(`Forbidden: insufficient permissions to execute operation "${operationType}" on this document`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const getResolvers: (subgraph:
|
|
1
|
+
import type { BaseSubgraph } from "@powerhousedao/reactor-api";
|
|
2
|
+
export declare const getResolvers: (subgraph: BaseSubgraph) => Record<string, unknown>;
|
|
3
3
|
//# sourceMappingURL=resolvers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../../subgraphs/vetra-read-model/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../../subgraphs/vetra-read-model/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAW,MAAM,4BAA4B,CAAC;AAKxE,eAAO,MAAM,YAAY,GACvB,UAAU,YAAY,KACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAsExB,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VetraReadModelProcessorLegacy } from "../../processors/vetra-read-model/index.legacy.js";
|
|
2
|
+
import { canReadDocument, hasGlobalAdminAccess } from "../permission-utils.js";
|
|
2
3
|
export const getResolvers = (subgraph) => {
|
|
3
|
-
const reactor = subgraph.reactor;
|
|
4
4
|
const db = subgraph.relationalDb;
|
|
5
5
|
return {
|
|
6
6
|
Query: {
|
|
7
|
-
vetraPackages: async (
|
|
7
|
+
vetraPackages: async (_parent, args, ctx) => {
|
|
8
8
|
const { search, documentId_in } = args;
|
|
9
9
|
const sortOrder = args.sortOrder || "asc";
|
|
10
|
-
let query =
|
|
10
|
+
let query = VetraReadModelProcessorLegacy.query("vetra-packages", db)
|
|
11
11
|
.selectFrom("vetra_package")
|
|
12
12
|
.selectAll();
|
|
13
13
|
if (search) {
|
|
@@ -17,7 +17,8 @@ export const getResolvers = (subgraph) => {
|
|
|
17
17
|
query = query.where("document_id", "in", documentId_in);
|
|
18
18
|
}
|
|
19
19
|
query = query.orderBy("name", sortOrder);
|
|
20
|
-
|
|
20
|
+
const results = await query.execute();
|
|
21
|
+
const mappedResults = results.map((pkg) => ({
|
|
21
22
|
...pkg,
|
|
22
23
|
documentId: pkg.document_id,
|
|
23
24
|
name: pkg.name,
|
|
@@ -30,6 +31,18 @@ export const getResolvers = (subgraph) => {
|
|
|
30
31
|
keywords: pkg.keywords,
|
|
31
32
|
driveId: pkg.drive_id,
|
|
32
33
|
}));
|
|
34
|
+
// If user doesn't have global read access, filter by document-level permissions
|
|
35
|
+
if (!hasGlobalAdminAccess(ctx) && subgraph.documentPermissionService) {
|
|
36
|
+
const filteredResults = [];
|
|
37
|
+
for (const pkg of mappedResults) {
|
|
38
|
+
const canRead = await canReadDocument(subgraph, pkg.documentId, ctx);
|
|
39
|
+
if (canRead) {
|
|
40
|
+
filteredResults.push(pkg);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return filteredResults;
|
|
44
|
+
}
|
|
45
|
+
return mappedResults;
|
|
33
46
|
},
|
|
34
47
|
},
|
|
35
48
|
};
|