@powerhousedao/reactor-api 6.0.0-dev.153 → 6.0.0-dev.154
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.d.mts +2948 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6353 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src/packages/vite-loader.mjs +142 -0
- package/dist/src/packages/vite-loader.mjs.map +1 -0
- package/dist/types-Do4QTfT3.d.mts +37 -0
- package/dist/types-Do4QTfT3.d.mts.map +1 -0
- package/dist/utils-DEEhP99G.mjs +286 -0
- package/dist/utils-DEEhP99G.mjs.map +1 -0
- package/dist/vite-loader.d.mts +29 -0
- package/dist/vite-loader.d.mts.map +1 -0
- package/package.json +17 -25
- package/dist/codegen.d.ts +0 -4
- package/dist/codegen.d.ts.map +0 -1
- package/dist/codegen.js +0 -38
- package/dist/codegen.js.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/src/config.d.ts +0 -6
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js +0 -6
- package/dist/src/config.js.map +0 -1
- package/dist/src/dev.d.ts +0 -2
- package/dist/src/dev.d.ts.map +0 -1
- package/dist/src/dev.js +0 -51
- package/dist/src/dev.js.map +0 -1
- package/dist/src/graphql/analytics-subgraph.d.ts +0 -14
- package/dist/src/graphql/analytics-subgraph.d.ts.map +0 -1
- package/dist/src/graphql/analytics-subgraph.js +0 -26
- package/dist/src/graphql/analytics-subgraph.js.map +0 -1
- package/dist/src/graphql/auth/index.d.ts +0 -2
- package/dist/src/graphql/auth/index.d.ts.map +0 -1
- package/dist/src/graphql/auth/index.js +0 -2
- package/dist/src/graphql/auth/index.js.map +0 -1
- package/dist/src/graphql/auth/resolvers.d.ts +0 -166
- package/dist/src/graphql/auth/resolvers.d.ts.map +0 -1
- package/dist/src/graphql/auth/resolvers.js +0 -227
- package/dist/src/graphql/auth/resolvers.js.map +0 -1
- package/dist/src/graphql/auth/schema.graphql +0 -195
- package/dist/src/graphql/auth/subgraph.d.ts +0 -202
- package/dist/src/graphql/auth/subgraph.d.ts.map +0 -1
- package/dist/src/graphql/auth/subgraph.js +0 -384
- package/dist/src/graphql/auth/subgraph.js.map +0 -1
- package/dist/src/graphql/base-subgraph.d.ts +0 -27
- package/dist/src/graphql/base-subgraph.d.ts.map +0 -1
- package/dist/src/graphql/base-subgraph.js +0 -126
- package/dist/src/graphql/base-subgraph.js.map +0 -1
- package/dist/src/graphql/document-model-subgraph.d.ts +0 -110
- package/dist/src/graphql/document-model-subgraph.d.ts.map +0 -1
- package/dist/src/graphql/document-model-subgraph.js +0 -336
- package/dist/src/graphql/document-model-subgraph.js.map +0 -1
- package/dist/src/graphql/gateway/adapter-gateway-apollo.d.ts +0 -23
- package/dist/src/graphql/gateway/adapter-gateway-apollo.d.ts.map +0 -1
- package/dist/src/graphql/gateway/adapter-gateway-apollo.js +0 -156
- package/dist/src/graphql/gateway/adapter-gateway-apollo.js.map +0 -1
- package/dist/src/graphql/gateway/adapter-gateway-mercurius.d.ts +0 -17
- package/dist/src/graphql/gateway/adapter-gateway-mercurius.d.ts.map +0 -1
- package/dist/src/graphql/gateway/adapter-gateway-mercurius.js +0 -154
- package/dist/src/graphql/gateway/adapter-gateway-mercurius.js.map +0 -1
- package/dist/src/graphql/gateway/adapter-http-express.d.ts +0 -25
- package/dist/src/graphql/gateway/adapter-http-express.d.ts.map +0 -1
- package/dist/src/graphql/gateway/adapter-http-express.js +0 -163
- package/dist/src/graphql/gateway/adapter-http-express.js.map +0 -1
- package/dist/src/graphql/gateway/adapter-http-fastify.d.ts +0 -23
- package/dist/src/graphql/gateway/adapter-http-fastify.d.ts.map +0 -1
- package/dist/src/graphql/gateway/adapter-http-fastify.js +0 -228
- package/dist/src/graphql/gateway/adapter-http-fastify.js.map +0 -1
- package/dist/src/graphql/gateway/auth-middleware.d.ts +0 -7
- package/dist/src/graphql/gateway/auth-middleware.d.ts.map +0 -1
- package/dist/src/graphql/gateway/auth-middleware.js +0 -15
- package/dist/src/graphql/gateway/auth-middleware.js.map +0 -1
- package/dist/src/graphql/gateway/factory.d.ts +0 -11
- package/dist/src/graphql/gateway/factory.d.ts.map +0 -1
- package/dist/src/graphql/gateway/factory.js +0 -21
- package/dist/src/graphql/gateway/factory.js.map +0 -1
- package/dist/src/graphql/gateway/types.d.ts +0 -100
- package/dist/src/graphql/gateway/types.d.ts.map +0 -1
- package/dist/src/graphql/gateway/types.js +0 -2
- package/dist/src/graphql/gateway/types.js.map +0 -1
- package/dist/src/graphql/graphql-manager.d.ts +0 -65
- package/dist/src/graphql/graphql-manager.d.ts.map +0 -1
- package/dist/src/graphql/graphql-manager.js +0 -483
- package/dist/src/graphql/graphql-manager.js.map +0 -1
- package/dist/src/graphql/index.d.ts +0 -13
- package/dist/src/graphql/index.d.ts.map +0 -1
- package/dist/src/graphql/index.js +0 -13
- package/dist/src/graphql/index.js.map +0 -1
- package/dist/src/graphql/packages/index.d.ts +0 -2
- package/dist/src/graphql/packages/index.d.ts.map +0 -1
- package/dist/src/graphql/packages/index.js +0 -2
- package/dist/src/graphql/packages/index.js.map +0 -1
- package/dist/src/graphql/packages/resolvers.d.ts +0 -31
- package/dist/src/graphql/packages/resolvers.d.ts.map +0 -1
- package/dist/src/graphql/packages/resolvers.js +0 -37
- package/dist/src/graphql/packages/resolvers.js.map +0 -1
- package/dist/src/graphql/packages/schema.graphql +0 -50
- package/dist/src/graphql/packages/subgraph.d.ts +0 -55
- package/dist/src/graphql/packages/subgraph.d.ts.map +0 -1
- package/dist/src/graphql/packages/subgraph.js +0 -73
- package/dist/src/graphql/packages/subgraph.js.map +0 -1
- package/dist/src/graphql/playground.d.ts +0 -2
- package/dist/src/graphql/playground.d.ts.map +0 -1
- package/dist/src/graphql/playground.js +0 -81
- package/dist/src/graphql/playground.js.map +0 -1
- package/dist/src/graphql/reactor/adapters.d.ts +0 -62
- package/dist/src/graphql/reactor/adapters.d.ts.map +0 -1
- package/dist/src/graphql/reactor/adapters.js +0 -271
- package/dist/src/graphql/reactor/adapters.js.map +0 -1
- package/dist/src/graphql/reactor/factory.d.ts +0 -105
- package/dist/src/graphql/reactor/factory.d.ts.map +0 -1
- package/dist/src/graphql/reactor/factory.js +0 -7
- package/dist/src/graphql/reactor/factory.js.map +0 -1
- package/dist/src/graphql/reactor/gen/graphql.d.ts +0 -1489
- package/dist/src/graphql/reactor/gen/graphql.d.ts.map +0 -1
- package/dist/src/graphql/reactor/gen/graphql.js +0 -731
- package/dist/src/graphql/reactor/gen/graphql.js.map +0 -1
- package/dist/src/graphql/reactor/index.d.ts +0 -4
- package/dist/src/graphql/reactor/index.d.ts.map +0 -1
- package/dist/src/graphql/reactor/index.js +0 -4
- package/dist/src/graphql/reactor/index.js.map +0 -1
- package/dist/src/graphql/reactor/operations.graphql +0 -443
- package/dist/src/graphql/reactor/pubsub.d.ts +0 -27
- package/dist/src/graphql/reactor/pubsub.d.ts.map +0 -1
- package/dist/src/graphql/reactor/pubsub.js +0 -93
- package/dist/src/graphql/reactor/pubsub.js.map +0 -1
- package/dist/src/graphql/reactor/requester.d.ts +0 -4
- package/dist/src/graphql/reactor/requester.d.ts.map +0 -1
- package/dist/src/graphql/reactor/requester.js +0 -22
- package/dist/src/graphql/reactor/requester.js.map +0 -1
- package/dist/src/graphql/reactor/requester.with-zod.d.ts +0 -4
- package/dist/src/graphql/reactor/requester.with-zod.d.ts.map +0 -1
- package/dist/src/graphql/reactor/requester.with-zod.js +0 -129
- package/dist/src/graphql/reactor/requester.with-zod.js.map +0 -1
- package/dist/src/graphql/reactor/resolvers.d.ts +0 -223
- package/dist/src/graphql/reactor/resolvers.d.ts.map +0 -1
- package/dist/src/graphql/reactor/resolvers.js +0 -682
- package/dist/src/graphql/reactor/resolvers.js.map +0 -1
- package/dist/src/graphql/reactor/schema.graphql +0 -475
- package/dist/src/graphql/reactor/subgraph.d.ts +0 -18
- package/dist/src/graphql/reactor/subgraph.d.ts.map +0 -1
- package/dist/src/graphql/reactor/subgraph.js +0 -460
- package/dist/src/graphql/reactor/subgraph.js.map +0 -1
- package/dist/src/graphql/reactor/validation.d.ts +0 -348
- package/dist/src/graphql/reactor/validation.d.ts.map +0 -1
- package/dist/src/graphql/reactor/validation.js +0 -167
- package/dist/src/graphql/reactor/validation.js.map +0 -1
- package/dist/src/graphql/sse.d.ts +0 -35
- package/dist/src/graphql/sse.d.ts.map +0 -1
- package/dist/src/graphql/sse.js +0 -29
- package/dist/src/graphql/sse.js.map +0 -1
- package/dist/src/graphql/system/env/getters.d.ts +0 -2
- package/dist/src/graphql/system/env/getters.d.ts.map +0 -1
- package/dist/src/graphql/system/env/getters.js +0 -4
- package/dist/src/graphql/system/env/getters.js.map +0 -1
- package/dist/src/graphql/system/env/index.d.ts +0 -2
- package/dist/src/graphql/system/env/index.d.ts.map +0 -1
- package/dist/src/graphql/system/env/index.js +0 -5
- package/dist/src/graphql/system/env/index.js.map +0 -1
- package/dist/src/graphql/system/index.d.ts +0 -2
- package/dist/src/graphql/system/index.d.ts.map +0 -1
- package/dist/src/graphql/system/index.js +0 -2
- package/dist/src/graphql/system/index.js.map +0 -1
- package/dist/src/graphql/system/types.d.ts +0 -2
- package/dist/src/graphql/system/types.d.ts.map +0 -1
- package/dist/src/graphql/system/types.js +0 -2
- package/dist/src/graphql/system/types.js.map +0 -1
- package/dist/src/graphql/temp-hack-rwa-type-defs.d.ts +0 -57
- package/dist/src/graphql/temp-hack-rwa-type-defs.d.ts.map +0 -1
- package/dist/src/graphql/temp-hack-rwa-type-defs.js +0 -2
- package/dist/src/graphql/temp-hack-rwa-type-defs.js.map +0 -1
- package/dist/src/graphql/types.d.ts +0 -102
- package/dist/src/graphql/types.d.ts.map +0 -1
- package/dist/src/graphql/types.js +0 -2
- package/dist/src/graphql/types.js.map +0 -1
- package/dist/src/graphql/utils.d.ts +0 -9
- package/dist/src/graphql/utils.d.ts.map +0 -1
- package/dist/src/graphql/utils.js +0 -72
- package/dist/src/graphql/utils.js.map +0 -1
- package/dist/src/graphql/websocket.d.ts +0 -3
- package/dist/src/graphql/websocket.d.ts.map +0 -1
- package/dist/src/graphql/websocket.js +0 -15
- package/dist/src/graphql/websocket.js.map +0 -1
- package/dist/src/migrations/001_create_document_permissions.d.ts +0 -4
- package/dist/src/migrations/001_create_document_permissions.d.ts.map +0 -1
- package/dist/src/migrations/001_create_document_permissions.js +0 -91
- package/dist/src/migrations/001_create_document_permissions.js.map +0 -1
- package/dist/src/migrations/002_add_document_protection.d.ts +0 -4
- package/dist/src/migrations/002_add_document_protection.d.ts.map +0 -1
- package/dist/src/migrations/002_add_document_protection.js +0 -18
- package/dist/src/migrations/002_add_document_protection.js.map +0 -1
- package/dist/src/migrations/index.d.ts +0 -10
- package/dist/src/migrations/index.d.ts.map +0 -1
- package/dist/src/migrations/index.js +0 -58
- package/dist/src/migrations/index.js.map +0 -1
- package/dist/src/packages/http-loader.d.ts +0 -59
- package/dist/src/packages/http-loader.d.ts.map +0 -1
- package/dist/src/packages/http-loader.js +0 -203
- package/dist/src/packages/http-loader.js.map +0 -1
- package/dist/src/packages/https-hooks.d.mts +0 -37
- package/dist/src/packages/https-hooks.d.mts.map +0 -1
- package/dist/src/packages/https-hooks.mjs +0 -95
- package/dist/src/packages/https-hooks.mjs.map +0 -1
- package/dist/src/packages/import-loader.d.ts +0 -14
- package/dist/src/packages/import-loader.d.ts.map +0 -1
- package/dist/src/packages/import-loader.js +0 -47
- package/dist/src/packages/import-loader.js.map +0 -1
- package/dist/src/packages/import-resolver.d.ts +0 -5
- package/dist/src/packages/import-resolver.d.ts.map +0 -1
- package/dist/src/packages/import-resolver.js +0 -127
- package/dist/src/packages/import-resolver.js.map +0 -1
- package/dist/src/packages/package-manager.d.ts +0 -33
- package/dist/src/packages/package-manager.d.ts.map +0 -1
- package/dist/src/packages/package-manager.js +0 -216
- package/dist/src/packages/package-manager.js.map +0 -1
- package/dist/src/packages/types.d.ts +0 -39
- package/dist/src/packages/types.d.ts.map +0 -1
- package/dist/src/packages/types.js +0 -2
- package/dist/src/packages/types.js.map +0 -1
- package/dist/src/packages/util.d.ts +0 -26
- package/dist/src/packages/util.d.ts.map +0 -1
- package/dist/src/packages/util.js +0 -85
- package/dist/src/packages/util.js.map +0 -1
- package/dist/src/packages/vite-loader.d.ts +0 -25
- package/dist/src/packages/vite-loader.d.ts.map +0 -1
- package/dist/src/packages/vite-loader.js +0 -171
- package/dist/src/packages/vite-loader.js.map +0 -1
- package/dist/src/server.d.ts +0 -55
- package/dist/src/server.d.ts.map +0 -1
- package/dist/src/server.js +0 -351
- package/dist/src/server.js.map +0 -1
- package/dist/src/services/auth.service.d.ts +0 -53
- package/dist/src/services/auth.service.d.ts.map +0 -1
- package/dist/src/services/auth.service.js +0 -165
- package/dist/src/services/auth.service.js.map +0 -1
- package/dist/src/services/authorization.service.d.ts +0 -70
- package/dist/src/services/authorization.service.d.ts.map +0 -1
- package/dist/src/services/authorization.service.js +0 -155
- package/dist/src/services/authorization.service.js.map +0 -1
- package/dist/src/services/document-permission.service.d.ts +0 -241
- package/dist/src/services/document-permission.service.d.ts.map +0 -1
- package/dist/src/services/document-permission.service.js +0 -791
- package/dist/src/services/document-permission.service.js.map +0 -1
- package/dist/src/services/package-management.service.d.ts +0 -32
- package/dist/src/services/package-management.service.d.ts.map +0 -1
- package/dist/src/services/package-management.service.js +0 -95
- package/dist/src/services/package-management.service.js.map +0 -1
- package/dist/src/services/package-storage.d.ts +0 -23
- package/dist/src/services/package-storage.d.ts.map +0 -1
- package/dist/src/services/package-storage.js +0 -19
- package/dist/src/services/package-storage.js.map +0 -1
- package/dist/src/tracing.d.ts +0 -4
- package/dist/src/tracing.d.ts.map +0 -1
- package/dist/src/tracing.js +0 -146
- package/dist/src/tracing.js.map +0 -1
- package/dist/src/types.d.ts +0 -26
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -2
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils/create-schema.d.ts +0 -36
- package/dist/src/utils/create-schema.d.ts.map +0 -1
- package/dist/src/utils/create-schema.js +0 -728
- package/dist/src/utils/create-schema.js.map +0 -1
- package/dist/src/utils/db.d.ts +0 -82
- package/dist/src/utils/db.d.ts.map +0 -1
- package/dist/src/utils/db.js +0 -101
- package/dist/src/utils/db.js.map +0 -1
- package/dist/src/utils/drive-url.d.ts +0 -2
- package/dist/src/utils/drive-url.d.ts.map +0 -1
- package/dist/src/utils/drive-url.js +0 -3
- package/dist/src/utils/drive-url.js.map +0 -1
- package/dist/src/utils/index.d.ts +0 -4
- package/dist/src/utils/index.d.ts.map +0 -1
- package/dist/src/utils/index.js +0 -4
- package/dist/src/utils/index.js.map +0 -1
- package/dist/test/auth-chain.test.d.ts +0 -12
- package/dist/test/auth-chain.test.d.ts.map +0 -1
- package/dist/test/auth-chain.test.js +0 -157
- package/dist/test/auth-chain.test.js.map +0 -1
- package/dist/test/auth.service.test.d.ts +0 -10
- package/dist/test/auth.service.test.d.ts.map +0 -1
- package/dist/test/auth.service.test.js +0 -141
- package/dist/test/auth.service.test.js.map +0 -1
- package/dist/test/authorization.service.test.d.ts +0 -2
- package/dist/test/authorization.service.test.d.ts.map +0 -1
- package/dist/test/authorization.service.test.js +0 -252
- package/dist/test/authorization.service.test.js.map +0 -1
- package/dist/test/connect-switchboard-reshuffle-convergence.test.d.ts +0 -2
- package/dist/test/connect-switchboard-reshuffle-convergence.test.d.ts.map +0 -1
- package/dist/test/connect-switchboard-reshuffle-convergence.test.js +0 -204
- package/dist/test/connect-switchboard-reshuffle-convergence.test.js.map +0 -1
- package/dist/test/connect-switchboard-sync.test.d.ts +0 -2
- package/dist/test/connect-switchboard-sync.test.d.ts.map +0 -1
- package/dist/test/connect-switchboard-sync.test.js +0 -633
- package/dist/test/connect-switchboard-sync.test.js.map +0 -1
- package/dist/test/document-drive-subgraph.test.d.ts +0 -2
- package/dist/test/document-drive-subgraph.test.d.ts.map +0 -1
- package/dist/test/document-drive-subgraph.test.js +0 -244
- package/dist/test/document-drive-subgraph.test.js.map +0 -1
- package/dist/test/document-model-subgraph-permissions.test.d.ts +0 -2
- package/dist/test/document-model-subgraph-permissions.test.d.ts.map +0 -1
- package/dist/test/document-model-subgraph-permissions.test.js +0 -587
- package/dist/test/document-model-subgraph-permissions.test.js.map +0 -1
- package/dist/test/document-permission.service.test.d.ts +0 -2
- package/dist/test/document-permission.service.test.d.ts.map +0 -1
- package/dist/test/document-permission.service.test.js +0 -480
- package/dist/test/document-permission.service.test.js.map +0 -1
- package/dist/test/drive-info-endpoint.test.d.ts +0 -2
- package/dist/test/drive-info-endpoint.test.d.ts.map +0 -1
- package/dist/test/drive-info-endpoint.test.js +0 -123
- package/dist/test/drive-info-endpoint.test.js.map +0 -1
- package/dist/test/fault-injection-sync.test.d.ts +0 -2
- package/dist/test/fault-injection-sync.test.d.ts.map +0 -1
- package/dist/test/fault-injection-sync.test.js +0 -197
- package/dist/test/fault-injection-sync.test.js.map +0 -1
- package/dist/test/gateway/adapter-gateway-apollo.test.d.ts +0 -2
- package/dist/test/gateway/adapter-gateway-apollo.test.d.ts.map +0 -1
- package/dist/test/gateway/adapter-gateway-apollo.test.js +0 -206
- package/dist/test/gateway/adapter-gateway-apollo.test.js.map +0 -1
- package/dist/test/gateway/adapter-gateway-mercurius.test.d.ts +0 -2
- package/dist/test/gateway/adapter-gateway-mercurius.test.d.ts.map +0 -1
- package/dist/test/gateway/adapter-gateway-mercurius.test.js +0 -23
- package/dist/test/gateway/adapter-gateway-mercurius.test.js.map +0 -1
- package/dist/test/gateway/adapter-http-express.test.d.ts +0 -2
- package/dist/test/gateway/adapter-http-express.test.d.ts.map +0 -1
- package/dist/test/gateway/adapter-http-express.test.js +0 -17
- package/dist/test/gateway/adapter-http-express.test.js.map +0 -1
- package/dist/test/gateway/adapter-http-fastify.test.d.ts +0 -2
- package/dist/test/gateway/adapter-http-fastify.test.d.ts.map +0 -1
- package/dist/test/gateway/adapter-http-fastify.test.js +0 -17
- package/dist/test/gateway/adapter-http-fastify.test.js.map +0 -1
- package/dist/test/gateway/auth-middleware.test.d.ts +0 -8
- package/dist/test/gateway/auth-middleware.test.d.ts.map +0 -1
- package/dist/test/gateway/auth-middleware.test.js +0 -73
- package/dist/test/gateway/auth-middleware.test.js.map +0 -1
- package/dist/test/gateway/gateway-adapter-contract.d.ts +0 -30
- package/dist/test/gateway/gateway-adapter-contract.d.ts.map +0 -1
- package/dist/test/gateway/gateway-adapter-contract.js +0 -347
- package/dist/test/gateway/gateway-adapter-contract.js.map +0 -1
- package/dist/test/gateway/http-adapter-contract.d.ts +0 -30
- package/dist/test/gateway/http-adapter-contract.d.ts.map +0 -1
- package/dist/test/gateway/http-adapter-contract.js +0 -277
- package/dist/test/gateway/http-adapter-contract.js.map +0 -1
- package/dist/test/graphql-manager.test.d.ts +0 -12
- package/dist/test/graphql-manager.test.d.ts.map +0 -1
- package/dist/test/graphql-manager.test.js +0 -576
- package/dist/test/graphql-manager.test.js.map +0 -1
- package/dist/test/index.d.ts +0 -2
- package/dist/test/index.d.ts.map +0 -1
- package/dist/test/index.js +0 -2
- package/dist/test/index.js.map +0 -1
- package/dist/test/permissions-integration.test.d.ts +0 -2
- package/dist/test/permissions-integration.test.d.ts.map +0 -1
- package/dist/test/permissions-integration.test.js +0 -407
- package/dist/test/permissions-integration.test.js.map +0 -1
- package/dist/test/push-backfill.test.d.ts +0 -2
- package/dist/test/push-backfill.test.d.ts.map +0 -1
- package/dist/test/push-backfill.test.js +0 -299
- package/dist/test/push-backfill.test.js.map +0 -1
- package/dist/test/reactor-adapters.test.d.ts +0 -2
- package/dist/test/reactor-adapters.test.d.ts.map +0 -1
- package/dist/test/reactor-adapters.test.js +0 -380
- package/dist/test/reactor-adapters.test.js.map +0 -1
- package/dist/test/reactor-client.test.d.ts +0 -2
- package/dist/test/reactor-client.test.d.ts.map +0 -1
- package/dist/test/reactor-client.test.js +0 -371
- package/dist/test/reactor-client.test.js.map +0 -1
- package/dist/test/reactor-resolvers.test.d.ts +0 -2
- package/dist/test/reactor-resolvers.test.d.ts.map +0 -1
- package/dist/test/reactor-resolvers.test.js +0 -259
- package/dist/test/reactor-resolvers.test.js.map +0 -1
- package/dist/test/reactor-subgraph-permissions.test.d.ts +0 -2
- package/dist/test/reactor-subgraph-permissions.test.d.ts.map +0 -1
- package/dist/test/reactor-subgraph-permissions.test.js +0 -371
- package/dist/test/reactor-subgraph-permissions.test.js.map +0 -1
- package/dist/test/router.test.d.ts +0 -2
- package/dist/test/router.test.d.ts.map +0 -1
- package/dist/test/router.test.js +0 -38
- package/dist/test/router.test.js.map +0 -1
- package/dist/test/subscriptions-sse.test.d.ts +0 -2
- package/dist/test/subscriptions-sse.test.d.ts.map +0 -1
- package/dist/test/subscriptions-sse.test.js +0 -264
- package/dist/test/subscriptions-sse.test.js.map +0 -1
- package/dist/test/subscriptions.test.d.ts +0 -2
- package/dist/test/subscriptions.test.d.ts.map +0 -1
- package/dist/test/subscriptions.test.js +0 -248
- package/dist/test/subscriptions.test.js.map +0 -1
- package/dist/test/utils/gql-resolver-bridge.d.ts +0 -15
- package/dist/test/utils/gql-resolver-bridge.d.ts.map +0 -1
- package/dist/test/utils/gql-resolver-bridge.js +0 -89
- package/dist/test/utils/gql-resolver-bridge.js.map +0 -1
- package/dist/test/utils.d.ts +0 -6
- package/dist/test/utils.d.ts.map +0 -1
- package/dist/test/utils.js +0 -13
- package/dist/test/utils.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/vitest.config.d.ts +0 -3
- package/dist/vitest.config.d.ts.map +0 -1
- package/dist/vitest.config.js +0 -39
- package/dist/vitest.config.js.map +0 -1
|
@@ -1,791 +0,0 @@
|
|
|
1
|
-
import { sql } from "kysely";
|
|
2
|
-
/**
|
|
3
|
-
* Service for managing document-level permissions.
|
|
4
|
-
*
|
|
5
|
-
* Permission levels for documents:
|
|
6
|
-
* - READ: Can fetch and read the document
|
|
7
|
-
* - WRITE: Can push updates and modify the document
|
|
8
|
-
* - ADMIN: Can manage document permissions and settings
|
|
9
|
-
*
|
|
10
|
-
* Operation permissions:
|
|
11
|
-
* - Users and groups can be granted permission to execute specific operations
|
|
12
|
-
*/
|
|
13
|
-
export class DocumentPermissionService {
|
|
14
|
-
db;
|
|
15
|
-
config;
|
|
16
|
-
constructor(db, config = { defaultProtection: false }) {
|
|
17
|
-
this.db = db;
|
|
18
|
-
this.config = config;
|
|
19
|
-
}
|
|
20
|
-
// ============================================
|
|
21
|
-
// User Permission Operations
|
|
22
|
-
// ============================================
|
|
23
|
-
/**
|
|
24
|
-
* Get the permission level for a user on a specific document.
|
|
25
|
-
* Returns null if no permission is set.
|
|
26
|
-
*/
|
|
27
|
-
async getUserPermission(documentId, userAddress) {
|
|
28
|
-
const result = await this.db
|
|
29
|
-
.selectFrom("DocumentPermission")
|
|
30
|
-
.select("permission")
|
|
31
|
-
.where("documentId", "=", documentId)
|
|
32
|
-
.where("userAddress", "=", userAddress.toLowerCase())
|
|
33
|
-
.executeTakeFirst();
|
|
34
|
-
return result?.permission ?? null;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Get all permissions for a document
|
|
38
|
-
*/
|
|
39
|
-
async getDocumentPermissions(documentId) {
|
|
40
|
-
const results = await this.db
|
|
41
|
-
.selectFrom("DocumentPermission")
|
|
42
|
-
.select([
|
|
43
|
-
"documentId",
|
|
44
|
-
"userAddress",
|
|
45
|
-
"permission",
|
|
46
|
-
"grantedBy",
|
|
47
|
-
"createdAt",
|
|
48
|
-
"updatedAt",
|
|
49
|
-
])
|
|
50
|
-
.where("documentId", "=", documentId)
|
|
51
|
-
.execute();
|
|
52
|
-
return results;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get all documents a user has explicit access to
|
|
56
|
-
*/
|
|
57
|
-
async getUserDocuments(userAddress) {
|
|
58
|
-
const results = await this.db
|
|
59
|
-
.selectFrom("DocumentPermission")
|
|
60
|
-
.select([
|
|
61
|
-
"documentId",
|
|
62
|
-
"userAddress",
|
|
63
|
-
"permission",
|
|
64
|
-
"grantedBy",
|
|
65
|
-
"createdAt",
|
|
66
|
-
"updatedAt",
|
|
67
|
-
])
|
|
68
|
-
.where("userAddress", "=", userAddress.toLowerCase())
|
|
69
|
-
.execute();
|
|
70
|
-
return results;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Grant or update a user's permission on a document.
|
|
74
|
-
*/
|
|
75
|
-
async grantPermission(documentId, userAddress, permission, grantedBy) {
|
|
76
|
-
const now = new Date();
|
|
77
|
-
const normalizedAddress = userAddress.toLowerCase();
|
|
78
|
-
await this.db
|
|
79
|
-
.insertInto("DocumentPermission")
|
|
80
|
-
.values({
|
|
81
|
-
documentId,
|
|
82
|
-
userAddress: normalizedAddress,
|
|
83
|
-
permission,
|
|
84
|
-
grantedBy: grantedBy.toLowerCase(),
|
|
85
|
-
createdAt: now,
|
|
86
|
-
updatedAt: now,
|
|
87
|
-
})
|
|
88
|
-
.onConflict((oc) => oc.columns(["documentId", "userAddress"]).doUpdateSet({
|
|
89
|
-
permission,
|
|
90
|
-
grantedBy: grantedBy.toLowerCase(),
|
|
91
|
-
updatedAt: now,
|
|
92
|
-
}))
|
|
93
|
-
.execute();
|
|
94
|
-
const result = await this.db
|
|
95
|
-
.selectFrom("DocumentPermission")
|
|
96
|
-
.select([
|
|
97
|
-
"documentId",
|
|
98
|
-
"userAddress",
|
|
99
|
-
"permission",
|
|
100
|
-
"grantedBy",
|
|
101
|
-
"createdAt",
|
|
102
|
-
"updatedAt",
|
|
103
|
-
])
|
|
104
|
-
.where("documentId", "=", documentId)
|
|
105
|
-
.where("userAddress", "=", normalizedAddress)
|
|
106
|
-
.executeTakeFirstOrThrow();
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Revoke a user's permission on a document
|
|
111
|
-
*/
|
|
112
|
-
async revokePermission(documentId, userAddress) {
|
|
113
|
-
await this.db
|
|
114
|
-
.deleteFrom("DocumentPermission")
|
|
115
|
-
.where("documentId", "=", documentId)
|
|
116
|
-
.where("userAddress", "=", userAddress.toLowerCase())
|
|
117
|
-
.execute();
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Delete all permissions for a document (used when deleting a document)
|
|
121
|
-
*/
|
|
122
|
-
async deleteAllDocumentPermissions(documentId) {
|
|
123
|
-
await this.db
|
|
124
|
-
.deleteFrom("DocumentPermission")
|
|
125
|
-
.where("documentId", "=", documentId)
|
|
126
|
-
.execute();
|
|
127
|
-
await this.db
|
|
128
|
-
.deleteFrom("DocumentGroupPermission")
|
|
129
|
-
.where("documentId", "=", documentId)
|
|
130
|
-
.execute();
|
|
131
|
-
await this.db
|
|
132
|
-
.deleteFrom("OperationUserPermission")
|
|
133
|
-
.where("documentId", "=", documentId)
|
|
134
|
-
.execute();
|
|
135
|
-
await this.db
|
|
136
|
-
.deleteFrom("OperationGroupPermission")
|
|
137
|
-
.where("documentId", "=", documentId)
|
|
138
|
-
.execute();
|
|
139
|
-
}
|
|
140
|
-
// ============================================
|
|
141
|
-
// Access Control Checks
|
|
142
|
-
// ============================================
|
|
143
|
-
/**
|
|
144
|
-
* Check if a user can read a document.
|
|
145
|
-
* Returns true if user has READ, WRITE, or ADMIN permission (direct or via group)
|
|
146
|
-
*/
|
|
147
|
-
async canReadDocument(documentId, userAddress) {
|
|
148
|
-
if (!userAddress) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
// Check direct user permission
|
|
152
|
-
const directPermission = await this.getUserPermission(documentId, userAddress);
|
|
153
|
-
if (directPermission !== null) {
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
// Check group permission
|
|
157
|
-
const groupPermission = await this.getUserGroupPermission(documentId, userAddress);
|
|
158
|
-
return groupPermission !== null;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Check if a user can write to a document.
|
|
162
|
-
* Returns true if user has WRITE or ADMIN permission (direct or via group)
|
|
163
|
-
*/
|
|
164
|
-
async canWriteDocument(documentId, userAddress) {
|
|
165
|
-
if (!userAddress) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
// Check direct user permission
|
|
169
|
-
const directPermission = await this.getUserPermission(documentId, userAddress);
|
|
170
|
-
if (directPermission === "WRITE" || directPermission === "ADMIN") {
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
// Check group permission
|
|
174
|
-
const groupPermission = await this.getUserGroupPermission(documentId, userAddress);
|
|
175
|
-
return groupPermission === "WRITE" || groupPermission === "ADMIN";
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Check if a user can manage a document (change permissions, settings).
|
|
179
|
-
* Returns true if user has ADMIN permission (direct or via group)
|
|
180
|
-
*/
|
|
181
|
-
async canManageDocument(documentId, userAddress) {
|
|
182
|
-
if (!userAddress) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
// Check direct user permission
|
|
186
|
-
const directPermission = await this.getUserPermission(documentId, userAddress);
|
|
187
|
-
if (directPermission === "ADMIN") {
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
// Check group permission
|
|
191
|
-
const groupPermission = await this.getUserGroupPermission(documentId, userAddress);
|
|
192
|
-
return groupPermission === "ADMIN";
|
|
193
|
-
}
|
|
194
|
-
// ============================================
|
|
195
|
-
// Access Control Checks (With Parent Hierarchy)
|
|
196
|
-
// ============================================
|
|
197
|
-
/**
|
|
198
|
-
* Check if a user can read a document, including parent permission inheritance.
|
|
199
|
-
* Returns true if user has permission on the document OR any parent in the hierarchy.
|
|
200
|
-
*/
|
|
201
|
-
async canRead(documentId, userAddress, getParentIds) {
|
|
202
|
-
// Check if user has direct permission on this document
|
|
203
|
-
const canReadThis = await this.canReadDocument(documentId, userAddress);
|
|
204
|
-
if (canReadThis) {
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
// Check if user has permission on any parent (inheritance)
|
|
208
|
-
const parentIds = await getParentIds(documentId);
|
|
209
|
-
for (const parentId of parentIds) {
|
|
210
|
-
const canReadParent = await this.canRead(parentId, userAddress, getParentIds);
|
|
211
|
-
if (canReadParent) {
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Check if a user can write to a document, including parent permission inheritance.
|
|
219
|
-
* Returns true if user has write permission on the document OR any parent in the hierarchy.
|
|
220
|
-
*/
|
|
221
|
-
async canWrite(documentId, userAddress, getParentIds) {
|
|
222
|
-
// Check if user has direct write permission on this document
|
|
223
|
-
const canWriteThis = await this.canWriteDocument(documentId, userAddress);
|
|
224
|
-
if (canWriteThis) {
|
|
225
|
-
return true;
|
|
226
|
-
}
|
|
227
|
-
// Check if user has write permission on any parent (inheritance)
|
|
228
|
-
const parentIds = await getParentIds(documentId);
|
|
229
|
-
for (const parentId of parentIds) {
|
|
230
|
-
const canWriteParent = await this.canWrite(parentId, userAddress, getParentIds);
|
|
231
|
-
if (canWriteParent) {
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Filter a list of document IDs to only include those the user can read.
|
|
239
|
-
*/
|
|
240
|
-
async filterReadableDocuments(documentIds, userAddress, getParentIds) {
|
|
241
|
-
const results = [];
|
|
242
|
-
for (const docId of documentIds) {
|
|
243
|
-
const canReadDoc = await this.canRead(docId, userAddress, getParentIds);
|
|
244
|
-
if (canReadDoc) {
|
|
245
|
-
results.push(docId);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return results;
|
|
249
|
-
}
|
|
250
|
-
// ============================================
|
|
251
|
-
// Group Management
|
|
252
|
-
// ============================================
|
|
253
|
-
/**
|
|
254
|
-
* Create a new group
|
|
255
|
-
*/
|
|
256
|
-
async createGroup(name, description) {
|
|
257
|
-
const now = new Date();
|
|
258
|
-
await this.db
|
|
259
|
-
.insertInto("Group")
|
|
260
|
-
.values({
|
|
261
|
-
name,
|
|
262
|
-
description: description ?? null,
|
|
263
|
-
createdAt: now,
|
|
264
|
-
updatedAt: now,
|
|
265
|
-
})
|
|
266
|
-
.execute();
|
|
267
|
-
const result = await this.db
|
|
268
|
-
.selectFrom("Group")
|
|
269
|
-
.select(["id", "name", "description", "createdAt", "updatedAt"])
|
|
270
|
-
.where("name", "=", name)
|
|
271
|
-
.executeTakeFirstOrThrow();
|
|
272
|
-
return result;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Delete a group and all its associations
|
|
276
|
-
*/
|
|
277
|
-
async deleteGroup(groupId) {
|
|
278
|
-
// Delete group permissions on operations
|
|
279
|
-
await this.db
|
|
280
|
-
.deleteFrom("OperationGroupPermission")
|
|
281
|
-
.where("groupId", "=", groupId)
|
|
282
|
-
.execute();
|
|
283
|
-
// Delete group document permissions
|
|
284
|
-
await this.db
|
|
285
|
-
.deleteFrom("DocumentGroupPermission")
|
|
286
|
-
.where("groupId", "=", groupId)
|
|
287
|
-
.execute();
|
|
288
|
-
// Delete user-group memberships
|
|
289
|
-
await this.db
|
|
290
|
-
.deleteFrom("UserGroup")
|
|
291
|
-
.where("groupId", "=", groupId)
|
|
292
|
-
.execute();
|
|
293
|
-
// Delete the group
|
|
294
|
-
await this.db.deleteFrom("Group").where("id", "=", groupId).execute();
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Get a group by ID
|
|
298
|
-
*/
|
|
299
|
-
async getGroup(groupId) {
|
|
300
|
-
const result = await this.db
|
|
301
|
-
.selectFrom("Group")
|
|
302
|
-
.select(["id", "name", "description", "createdAt", "updatedAt"])
|
|
303
|
-
.where("id", "=", groupId)
|
|
304
|
-
.executeTakeFirst();
|
|
305
|
-
return result ?? null;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* List all groups
|
|
309
|
-
*/
|
|
310
|
-
async listGroups() {
|
|
311
|
-
return this.db
|
|
312
|
-
.selectFrom("Group")
|
|
313
|
-
.select(["id", "name", "description", "createdAt", "updatedAt"])
|
|
314
|
-
.execute();
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Add a user to a group
|
|
318
|
-
*/
|
|
319
|
-
async addUserToGroup(userAddress, groupId) {
|
|
320
|
-
const now = new Date();
|
|
321
|
-
const normalizedAddress = userAddress.toLowerCase();
|
|
322
|
-
await this.db
|
|
323
|
-
.insertInto("UserGroup")
|
|
324
|
-
.values({
|
|
325
|
-
userAddress: normalizedAddress,
|
|
326
|
-
groupId,
|
|
327
|
-
createdAt: now,
|
|
328
|
-
})
|
|
329
|
-
.onConflict((oc) => oc.columns(["userAddress", "groupId"]).doNothing())
|
|
330
|
-
.execute();
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Remove a user from a group
|
|
334
|
-
*/
|
|
335
|
-
async removeUserFromGroup(userAddress, groupId) {
|
|
336
|
-
await this.db
|
|
337
|
-
.deleteFrom("UserGroup")
|
|
338
|
-
.where("userAddress", "=", userAddress.toLowerCase())
|
|
339
|
-
.where("groupId", "=", groupId)
|
|
340
|
-
.execute();
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Get all groups a user belongs to
|
|
344
|
-
*/
|
|
345
|
-
async getUserGroups(userAddress) {
|
|
346
|
-
return this.db
|
|
347
|
-
.selectFrom("UserGroup")
|
|
348
|
-
.innerJoin("Group", "Group.id", "UserGroup.groupId")
|
|
349
|
-
.select([
|
|
350
|
-
"Group.id",
|
|
351
|
-
"Group.name",
|
|
352
|
-
"Group.description",
|
|
353
|
-
"Group.createdAt",
|
|
354
|
-
"Group.updatedAt",
|
|
355
|
-
])
|
|
356
|
-
.where("UserGroup.userAddress", "=", userAddress.toLowerCase())
|
|
357
|
-
.execute();
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* Get all members of a group
|
|
361
|
-
*/
|
|
362
|
-
async getGroupMembers(groupId) {
|
|
363
|
-
const results = await this.db
|
|
364
|
-
.selectFrom("UserGroup")
|
|
365
|
-
.select("userAddress")
|
|
366
|
-
.where("groupId", "=", groupId)
|
|
367
|
-
.execute();
|
|
368
|
-
return results.map((r) => r.userAddress);
|
|
369
|
-
}
|
|
370
|
-
// ============================================
|
|
371
|
-
// Group Document Permissions
|
|
372
|
-
// ============================================
|
|
373
|
-
/**
|
|
374
|
-
* Grant a group permission on a document
|
|
375
|
-
*/
|
|
376
|
-
async grantGroupPermission(documentId, groupId, permission, grantedBy) {
|
|
377
|
-
const now = new Date();
|
|
378
|
-
await this.db
|
|
379
|
-
.insertInto("DocumentGroupPermission")
|
|
380
|
-
.values({
|
|
381
|
-
documentId,
|
|
382
|
-
groupId,
|
|
383
|
-
permission,
|
|
384
|
-
grantedBy: grantedBy.toLowerCase(),
|
|
385
|
-
createdAt: now,
|
|
386
|
-
updatedAt: now,
|
|
387
|
-
})
|
|
388
|
-
.onConflict((oc) => oc.columns(["documentId", "groupId"]).doUpdateSet({
|
|
389
|
-
permission,
|
|
390
|
-
grantedBy: grantedBy.toLowerCase(),
|
|
391
|
-
updatedAt: now,
|
|
392
|
-
}))
|
|
393
|
-
.execute();
|
|
394
|
-
const result = await this.db
|
|
395
|
-
.selectFrom("DocumentGroupPermission")
|
|
396
|
-
.select([
|
|
397
|
-
"documentId",
|
|
398
|
-
"groupId",
|
|
399
|
-
"permission",
|
|
400
|
-
"grantedBy",
|
|
401
|
-
"createdAt",
|
|
402
|
-
"updatedAt",
|
|
403
|
-
])
|
|
404
|
-
.where("documentId", "=", documentId)
|
|
405
|
-
.where("groupId", "=", groupId)
|
|
406
|
-
.executeTakeFirstOrThrow();
|
|
407
|
-
return result;
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Revoke a group's permission on a document
|
|
411
|
-
*/
|
|
412
|
-
async revokeGroupPermission(documentId, groupId) {
|
|
413
|
-
await this.db
|
|
414
|
-
.deleteFrom("DocumentGroupPermission")
|
|
415
|
-
.where("documentId", "=", documentId)
|
|
416
|
-
.where("groupId", "=", groupId)
|
|
417
|
-
.execute();
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Get all group permissions for a document
|
|
421
|
-
*/
|
|
422
|
-
async getDocumentGroupPermissions(documentId) {
|
|
423
|
-
return this.db
|
|
424
|
-
.selectFrom("DocumentGroupPermission")
|
|
425
|
-
.select([
|
|
426
|
-
"documentId",
|
|
427
|
-
"groupId",
|
|
428
|
-
"permission",
|
|
429
|
-
"grantedBy",
|
|
430
|
-
"createdAt",
|
|
431
|
-
"updatedAt",
|
|
432
|
-
])
|
|
433
|
-
.where("documentId", "=", documentId)
|
|
434
|
-
.execute();
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Get best permission level a user has on a document via groups
|
|
438
|
-
*/
|
|
439
|
-
async getUserGroupPermission(documentId, userAddress) {
|
|
440
|
-
const result = await this.db
|
|
441
|
-
.selectFrom("DocumentGroupPermission")
|
|
442
|
-
.innerJoin("UserGroup", "UserGroup.groupId", "DocumentGroupPermission.groupId")
|
|
443
|
-
.select("DocumentGroupPermission.permission")
|
|
444
|
-
.where("DocumentGroupPermission.documentId", "=", documentId)
|
|
445
|
-
.where("UserGroup.userAddress", "=", userAddress.toLowerCase())
|
|
446
|
-
.execute();
|
|
447
|
-
if (result.length === 0) {
|
|
448
|
-
return null;
|
|
449
|
-
}
|
|
450
|
-
// Return highest permission level
|
|
451
|
-
if (result.some((r) => r.permission === "ADMIN"))
|
|
452
|
-
return "ADMIN";
|
|
453
|
-
if (result.some((r) => r.permission === "WRITE"))
|
|
454
|
-
return "WRITE";
|
|
455
|
-
return "READ";
|
|
456
|
-
}
|
|
457
|
-
// ============================================
|
|
458
|
-
// Operation Permissions
|
|
459
|
-
// ============================================
|
|
460
|
-
/**
|
|
461
|
-
* Grant a user permission to execute an operation on a document
|
|
462
|
-
*/
|
|
463
|
-
async grantOperationPermission(documentId, operationType, userAddress, grantedBy) {
|
|
464
|
-
const now = new Date();
|
|
465
|
-
const normalizedAddress = userAddress.toLowerCase();
|
|
466
|
-
await this.db
|
|
467
|
-
.insertInto("OperationUserPermission")
|
|
468
|
-
.values({
|
|
469
|
-
documentId,
|
|
470
|
-
operationType,
|
|
471
|
-
userAddress: normalizedAddress,
|
|
472
|
-
grantedBy: grantedBy.toLowerCase(),
|
|
473
|
-
createdAt: now,
|
|
474
|
-
})
|
|
475
|
-
.onConflict((oc) => oc.columns(["documentId", "operationType", "userAddress"]).doNothing())
|
|
476
|
-
.execute();
|
|
477
|
-
const result = await this.db
|
|
478
|
-
.selectFrom("OperationUserPermission")
|
|
479
|
-
.select([
|
|
480
|
-
"documentId",
|
|
481
|
-
"operationType",
|
|
482
|
-
"userAddress",
|
|
483
|
-
"grantedBy",
|
|
484
|
-
"createdAt",
|
|
485
|
-
])
|
|
486
|
-
.where("documentId", "=", documentId)
|
|
487
|
-
.where("operationType", "=", operationType)
|
|
488
|
-
.where("userAddress", "=", normalizedAddress)
|
|
489
|
-
.executeTakeFirstOrThrow();
|
|
490
|
-
return result;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Revoke a user's permission to execute an operation
|
|
494
|
-
*/
|
|
495
|
-
async revokeOperationPermission(documentId, operationType, userAddress) {
|
|
496
|
-
await this.db
|
|
497
|
-
.deleteFrom("OperationUserPermission")
|
|
498
|
-
.where("documentId", "=", documentId)
|
|
499
|
-
.where("operationType", "=", operationType)
|
|
500
|
-
.where("userAddress", "=", userAddress.toLowerCase())
|
|
501
|
-
.execute();
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Grant a group permission to execute an operation on a document
|
|
505
|
-
*/
|
|
506
|
-
async grantGroupOperationPermission(documentId, operationType, groupId, grantedBy) {
|
|
507
|
-
const now = new Date();
|
|
508
|
-
await this.db
|
|
509
|
-
.insertInto("OperationGroupPermission")
|
|
510
|
-
.values({
|
|
511
|
-
documentId,
|
|
512
|
-
operationType,
|
|
513
|
-
groupId,
|
|
514
|
-
grantedBy: grantedBy.toLowerCase(),
|
|
515
|
-
createdAt: now,
|
|
516
|
-
})
|
|
517
|
-
.onConflict((oc) => oc.columns(["documentId", "operationType", "groupId"]).doNothing())
|
|
518
|
-
.execute();
|
|
519
|
-
const result = await this.db
|
|
520
|
-
.selectFrom("OperationGroupPermission")
|
|
521
|
-
.select([
|
|
522
|
-
"documentId",
|
|
523
|
-
"operationType",
|
|
524
|
-
"groupId",
|
|
525
|
-
"grantedBy",
|
|
526
|
-
"createdAt",
|
|
527
|
-
])
|
|
528
|
-
.where("documentId", "=", documentId)
|
|
529
|
-
.where("operationType", "=", operationType)
|
|
530
|
-
.where("groupId", "=", groupId)
|
|
531
|
-
.executeTakeFirstOrThrow();
|
|
532
|
-
return result;
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Revoke a group's permission to execute an operation
|
|
536
|
-
*/
|
|
537
|
-
async revokeGroupOperationPermission(documentId, operationType, groupId) {
|
|
538
|
-
await this.db
|
|
539
|
-
.deleteFrom("OperationGroupPermission")
|
|
540
|
-
.where("documentId", "=", documentId)
|
|
541
|
-
.where("operationType", "=", operationType)
|
|
542
|
-
.where("groupId", "=", groupId)
|
|
543
|
-
.execute();
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Get all users with permission to execute an operation
|
|
547
|
-
*/
|
|
548
|
-
async getOperationUserPermissions(documentId, operationType) {
|
|
549
|
-
return this.db
|
|
550
|
-
.selectFrom("OperationUserPermission")
|
|
551
|
-
.select([
|
|
552
|
-
"documentId",
|
|
553
|
-
"operationType",
|
|
554
|
-
"userAddress",
|
|
555
|
-
"grantedBy",
|
|
556
|
-
"createdAt",
|
|
557
|
-
])
|
|
558
|
-
.where("documentId", "=", documentId)
|
|
559
|
-
.where("operationType", "=", operationType)
|
|
560
|
-
.execute();
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Get all groups with permission to execute an operation
|
|
564
|
-
*/
|
|
565
|
-
async getOperationGroupPermissions(documentId, operationType) {
|
|
566
|
-
return this.db
|
|
567
|
-
.selectFrom("OperationGroupPermission")
|
|
568
|
-
.select([
|
|
569
|
-
"documentId",
|
|
570
|
-
"operationType",
|
|
571
|
-
"groupId",
|
|
572
|
-
"grantedBy",
|
|
573
|
-
"createdAt",
|
|
574
|
-
])
|
|
575
|
-
.where("documentId", "=", documentId)
|
|
576
|
-
.where("operationType", "=", operationType)
|
|
577
|
-
.execute();
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* Check if a user can execute a specific operation on a document.
|
|
581
|
-
* Returns true if user has direct permission or is in a group with permission.
|
|
582
|
-
*/
|
|
583
|
-
async canExecuteOperation(documentId, operationType, userAddress) {
|
|
584
|
-
if (!userAddress) {
|
|
585
|
-
return false;
|
|
586
|
-
}
|
|
587
|
-
const normalizedAddress = userAddress.toLowerCase();
|
|
588
|
-
// Check direct user permission
|
|
589
|
-
const userPermission = await this.db
|
|
590
|
-
.selectFrom("OperationUserPermission")
|
|
591
|
-
.select("userAddress")
|
|
592
|
-
.where("documentId", "=", documentId)
|
|
593
|
-
.where("operationType", "=", operationType)
|
|
594
|
-
.where("userAddress", "=", normalizedAddress)
|
|
595
|
-
.executeTakeFirst();
|
|
596
|
-
if (userPermission) {
|
|
597
|
-
return true;
|
|
598
|
-
}
|
|
599
|
-
// Check group permission
|
|
600
|
-
const groupPermission = await this.db
|
|
601
|
-
.selectFrom("OperationGroupPermission")
|
|
602
|
-
.innerJoin("UserGroup", "UserGroup.groupId", "OperationGroupPermission.groupId")
|
|
603
|
-
.select("OperationGroupPermission.groupId")
|
|
604
|
-
.where("OperationGroupPermission.documentId", "=", documentId)
|
|
605
|
-
.where("OperationGroupPermission.operationType", "=", operationType)
|
|
606
|
-
.where("UserGroup.userAddress", "=", normalizedAddress)
|
|
607
|
-
.executeTakeFirst();
|
|
608
|
-
return !!groupPermission;
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Check if an operation has any permissions set (is restricted)
|
|
612
|
-
*/
|
|
613
|
-
async isOperationRestricted(documentId, operationType) {
|
|
614
|
-
const userPermCount = await this.db
|
|
615
|
-
.selectFrom("OperationUserPermission")
|
|
616
|
-
.select(sql `count(*)`.as("count"))
|
|
617
|
-
.where("documentId", "=", documentId)
|
|
618
|
-
.where("operationType", "=", operationType)
|
|
619
|
-
.executeTakeFirst();
|
|
620
|
-
if (userPermCount && Number(userPermCount.count) > 0) {
|
|
621
|
-
return true;
|
|
622
|
-
}
|
|
623
|
-
const groupPermCount = await this.db
|
|
624
|
-
.selectFrom("OperationGroupPermission")
|
|
625
|
-
.select(sql `count(*)`.as("count"))
|
|
626
|
-
.where("documentId", "=", documentId)
|
|
627
|
-
.where("operationType", "=", operationType)
|
|
628
|
-
.executeTakeFirst();
|
|
629
|
-
return groupPermCount !== undefined && Number(groupPermCount.count) > 0;
|
|
630
|
-
}
|
|
631
|
-
// ============================================
|
|
632
|
-
// Document Protection
|
|
633
|
-
// ============================================
|
|
634
|
-
/**
|
|
635
|
-
* Check if a specific document has a protection row set to true.
|
|
636
|
-
* Falls back to `config.defaultProtection` if no row exists.
|
|
637
|
-
*/
|
|
638
|
-
async isDocumentProtected(documentId) {
|
|
639
|
-
const row = await this.db
|
|
640
|
-
.selectFrom("DocumentProtection")
|
|
641
|
-
.select("protected")
|
|
642
|
-
.where("documentId", "=", documentId)
|
|
643
|
-
.executeTakeFirst();
|
|
644
|
-
if (row === undefined) {
|
|
645
|
-
return this.config.defaultProtection;
|
|
646
|
-
}
|
|
647
|
-
return row.protected;
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Walk the parent chain: if the document itself or any ancestor is protected, return true.
|
|
651
|
-
* Collects all ancestor IDs first (with cycle detection), then batch-checks protection.
|
|
652
|
-
*/
|
|
653
|
-
async isProtectedWithAncestors(documentId, getParentIds) {
|
|
654
|
-
// Collect all IDs in the hierarchy (document + all ancestors)
|
|
655
|
-
const allIds = await this.collectAncestorIds(documentId, getParentIds);
|
|
656
|
-
// Batch-check protection for all IDs at once
|
|
657
|
-
if (allIds.length === 0) {
|
|
658
|
-
return this.config.defaultProtection;
|
|
659
|
-
}
|
|
660
|
-
const rows = await this.db
|
|
661
|
-
.selectFrom("DocumentProtection")
|
|
662
|
-
.select(["documentId", "protected"])
|
|
663
|
-
.where("documentId", "in", allIds)
|
|
664
|
-
.execute();
|
|
665
|
-
const protectionMap = new Map(rows.map((r) => [r.documentId, r.protected]));
|
|
666
|
-
for (const id of allIds) {
|
|
667
|
-
const isProtected = protectionMap.get(id);
|
|
668
|
-
// If no row exists, fall back to defaultProtection
|
|
669
|
-
if (isProtected ?? this.config.defaultProtection) {
|
|
670
|
-
return true;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
return false;
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Collect all ancestor IDs (including the document itself) with cycle detection.
|
|
677
|
-
*/
|
|
678
|
-
async collectAncestorIds(documentId, getParentIds) {
|
|
679
|
-
const visited = new Set();
|
|
680
|
-
const queue = [documentId];
|
|
681
|
-
while (queue.length > 0) {
|
|
682
|
-
const current = queue.shift();
|
|
683
|
-
if (visited.has(current))
|
|
684
|
-
continue;
|
|
685
|
-
visited.add(current);
|
|
686
|
-
const parentIds = await getParentIds(current);
|
|
687
|
-
for (const parentId of parentIds) {
|
|
688
|
-
if (!visited.has(parentId)) {
|
|
689
|
-
queue.push(parentId);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
return Array.from(visited);
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Upsert protection status for a document.
|
|
697
|
-
*/
|
|
698
|
-
async setDocumentProtection(documentId, isProtected) {
|
|
699
|
-
const now = new Date();
|
|
700
|
-
await this.db
|
|
701
|
-
.insertInto("DocumentProtection")
|
|
702
|
-
.values({
|
|
703
|
-
documentId,
|
|
704
|
-
protected: isProtected,
|
|
705
|
-
ownerAddress: null,
|
|
706
|
-
createdAt: now,
|
|
707
|
-
updatedAt: now,
|
|
708
|
-
})
|
|
709
|
-
.onConflict((oc) => oc.column("documentId").doUpdateSet({
|
|
710
|
-
protected: isProtected,
|
|
711
|
-
updatedAt: now,
|
|
712
|
-
}))
|
|
713
|
-
.execute();
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Get the owner address for a document, or null if not set.
|
|
717
|
-
*/
|
|
718
|
-
async getDocumentOwner(documentId) {
|
|
719
|
-
const row = await this.db
|
|
720
|
-
.selectFrom("DocumentProtection")
|
|
721
|
-
.select("ownerAddress")
|
|
722
|
-
.where("documentId", "=", documentId)
|
|
723
|
-
.executeTakeFirst();
|
|
724
|
-
return row?.ownerAddress ?? null;
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* Upsert owner address for a document.
|
|
728
|
-
*/
|
|
729
|
-
async setDocumentOwner(documentId, ownerAddress) {
|
|
730
|
-
const now = new Date();
|
|
731
|
-
const normalizedAddress = ownerAddress.toLowerCase();
|
|
732
|
-
await this.db
|
|
733
|
-
.insertInto("DocumentProtection")
|
|
734
|
-
.values({
|
|
735
|
-
documentId,
|
|
736
|
-
protected: this.config.defaultProtection,
|
|
737
|
-
ownerAddress: normalizedAddress,
|
|
738
|
-
createdAt: now,
|
|
739
|
-
updatedAt: now,
|
|
740
|
-
})
|
|
741
|
-
.onConflict((oc) => oc.column("documentId").doUpdateSet({
|
|
742
|
-
ownerAddress: normalizedAddress,
|
|
743
|
-
updatedAt: now,
|
|
744
|
-
}))
|
|
745
|
-
.execute();
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Initialize protection for a newly created document.
|
|
749
|
-
* Sets protection status and grants ADMIN to the owner.
|
|
750
|
-
*/
|
|
751
|
-
async initializeDocumentProtection(documentId, ownerAddress, defaultProtection) {
|
|
752
|
-
const now = new Date();
|
|
753
|
-
const normalizedAddress = ownerAddress.toLowerCase();
|
|
754
|
-
const isProtected = defaultProtection ?? this.config.defaultProtection;
|
|
755
|
-
await this.db
|
|
756
|
-
.insertInto("DocumentProtection")
|
|
757
|
-
.values({
|
|
758
|
-
documentId,
|
|
759
|
-
protected: isProtected,
|
|
760
|
-
ownerAddress: normalizedAddress,
|
|
761
|
-
createdAt: now,
|
|
762
|
-
updatedAt: now,
|
|
763
|
-
})
|
|
764
|
-
.onConflict((oc) => oc.column("documentId").doUpdateSet({
|
|
765
|
-
ownerAddress: normalizedAddress,
|
|
766
|
-
updatedAt: now,
|
|
767
|
-
}))
|
|
768
|
-
.execute();
|
|
769
|
-
// Grant ADMIN permission to the owner
|
|
770
|
-
await this.grantPermission(documentId, normalizedAddress, "ADMIN", normalizedAddress);
|
|
771
|
-
}
|
|
772
|
-
/**
|
|
773
|
-
* Get the full protection info for a document.
|
|
774
|
-
*/
|
|
775
|
-
async getDocumentProtection(documentId) {
|
|
776
|
-
const row = await this.db
|
|
777
|
-
.selectFrom("DocumentProtection")
|
|
778
|
-
.select(["documentId", "protected", "ownerAddress"])
|
|
779
|
-
.where("documentId", "=", documentId)
|
|
780
|
-
.executeTakeFirst();
|
|
781
|
-
if (!row) {
|
|
782
|
-
return {
|
|
783
|
-
documentId,
|
|
784
|
-
protected: this.config.defaultProtection,
|
|
785
|
-
ownerAddress: null,
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
return row;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
//# sourceMappingURL=document-permission.service.js.map
|