Files
speckle-server/packages/server/modules/core/index.ts
T
Gergő Jedlicska 7c16abc8eb feat(workspace): 1119 define workspaces dataschema (#2431)
* feat(workspaces): add workspaces module with roles and scopes

* feat(workspaces): add domain, graphql and persistent storage dataschema

* fix(workspaces): correct db injections

* chore(workspaces): add EE license

* chore(license): mentions workspaces separately in license file

* fix(core): roles import in migration

* fix(workspaces): drop workspace_acl on down migration

* fix(workspaces): roles constants

* fix(workspaces): coding standards

---------

Co-authored-by: Dimitrie Stefanescu <didimitrie@gmail.com>
2024-06-26 17:00:56 +02:00

89 lines
2.6 KiB
TypeScript

import { moduleLogger } from '@/logging/logging'
import {
setupResultListener,
shutdownResultListener
} from '@/modules/core/utils/dbNotificationListener'
import * as mp from '@/modules/shared/utils/mixpanel'
import { Optional, SpeckleModule } from '@/modules/shared/helpers/typeHelper'
import staticRest from '@/modules/core/rest/static'
import uploadRest from '@/modules/core/rest/upload'
import downloadRest from '@/modules/core/rest/download'
import diffUpload from '@/modules/core/rest/diffUpload'
import diffDownload from '@/modules/core/rest/diffDownload'
import healthRest from '@/modules/core/rest/health'
import scopes from '@/modules/core/scopes'
import roles from '@/modules/core/roles'
import Redis from 'ioredis'
import { createRedisClient } from '@/modules/shared/redis/redis'
import { getRedisUrl } from '@/modules/shared/helpers/envHelper'
import { UninitializedResourceAccessError } from '@/modules/shared/errors'
import { registerOrUpdateScopeFactory } from '@/modules/shared/repositories/scopes'
import db from '@/db/knex'
import { registerOrUpdateRole } from '@/modules/shared/repositories/roles'
let genericRedisClient: Optional<Redis> = undefined
const coreModule: SpeckleModule<{
getGenericRedis: () => Redis
}> = {
async init(app, isInitial) {
moduleLogger.info('💥 Init core module')
// Initialize the static route
staticRest(app)
// Initialize the health check route
healthRest(app)
// Initialises the two main bulk upload/download endpoints
uploadRest(app)
downloadRest(app)
// Initialises the two diff-based upload/download endpoints
diffUpload(app)
diffDownload(app)
const scopeRegisterFunc = registerOrUpdateScopeFactory({ db })
// Register core-based scoeps
for (const scope of scopes) {
await scopeRegisterFunc({ scope })
}
const roleRegisterFunc = registerOrUpdateRole({ db })
// Register core-based roles
for (const role of roles) {
await roleRegisterFunc({ role })
}
if (isInitial) {
// Setup global pg notification listener
setupResultListener()
// Init mp
mp.initialize()
// Generic redis client
genericRedisClient = createRedisClient(getRedisUrl(), {})
}
},
async shutdown() {
await shutdownResultListener()
if (genericRedisClient) {
await genericRedisClient.quit()
}
},
/**
* A general purpose redis client that can be used after safely all modules are initialized
*/
getGenericRedis() {
if (!genericRedisClient) {
throw new UninitializedResourceAccessError('Generic redis client not initialized')
}
return genericRedisClient
}
}
export = coreModule