Repository: strapi/strapi
File: packages/core/admin/ee/server/src/index.ts (TypeScript)

Code before:

  const isAIEnabled =
    strapi.config.get('admin.ai.enabled', true) && strapi.ee.features.isEnabled('cms-ai');

  const isAuditLogsEnabled =
    strapi.config.get('admin.auditLogs.enabled', true) &&
    strapi.ee.features.isEnabled('audit-logs');
  return {
    ...eeAdmin,
    controllers: {
      ...eeAdmin.controllers,
      ...(isAuditLogsEnabled ? { 'audit-logs': auditLogsController } : {}),
      ...(isAIEnabled ? { ai: aiController } : {}),
    },
    routes: {
      ...eeAdmin.routes,
      ...(isAuditLogsEnabled ? { 'audit-logs': auditLogsRoutes } : {}),
      ...(isAIEnabled ? { ai: aiRoutes } : {}),
    },
    async register({ strapi }: { strapi: Core.Strapi }) {
      // Run the the default registration
      await eeAdmin.register({ strapi });

      // Register internal ai service
      if (isAIEnabled) {
        strapi.add('ai', createAIService({ strapi }));
      }

      if (isAuditLogsEnabled) {
        // Register an internal audit logs service
        strapi.add('audit-logs', createAuditLogsService(strapi));
        // Register an internal audit logs lifecycle service
        const auditLogsLifecycle = createAuditLogsLifecycleService(strapi);
        strapi.add('audit-logs-lifecycle', auditLogsLifecycle);

        await auditLogsLifecycle.register();
      }
    },
    async destroy({ strapi }: { strapi: Core.Strapi }) {
      if (isAuditLogsEnabled) {
        strapi.get('audit-logs-lifecycle').destroy();
      }
      await eeAdmin.destroy({ strapi });
    },
  };
};

export default getAdminEE;


Review comment (suggestion):
I think what this does is different from creating a service, it's more creating an entire namespace outside of services. Is it intentional? If so I'd rename createAIService and move it out of services folder

Code after:

  const isAIEnabled =
    strapi.config.get('admin.ai.enabled', true) && strapi.ee.features.isEnabled('cms-ai');

  const isAuditLogsEnabled =
    strapi.config.get('admin.auditLogs.enabled', true) &&
    strapi.ee.features.isEnabled('audit-logs');
  return {
    ...eeAdmin,
    controllers: {
      ...eeAdmin.controllers,
      ...(isAuditLogsEnabled ? { 'audit-logs': auditLogsController } : {}),
      ...(isAIEnabled ? { ai: aiController } : {}),
    },
    routes: {
      ...eeAdmin.routes,
      ...(isAuditLogsEnabled ? { 'audit-logs': auditLogsRoutes } : {}),
      ...(isAIEnabled ? { ai: aiRoutes } : {}),
    },
    async register({ strapi }: { strapi: Core.Strapi }) {
      // Run the the default registration
      await eeAdmin.register({ strapi });

      // Register internal ai service
      if (isAIEnabled) {
        strapi.add('ai', createAIContainer({ strapi }));
      }

      if (isAuditLogsEnabled) {
        // Register an internal audit logs service
        strapi.add('audit-logs', createAuditLogsService(strapi));
        // Register an internal audit logs lifecycle service
        const auditLogsLifecycle = createAuditLogsLifecycleService(strapi);
        strapi.add('audit-logs-lifecycle', auditLogsLifecycle);

        await auditLogsLifecycle.register();
      }
    },
    async destroy({ strapi }: { strapi: Core.Strapi }) {
      if (isAuditLogsEnabled) {
        strapi.get('audit-logs-lifecycle').destroy();
      }
      await eeAdmin.destroy({ strapi });
    },
  };
};

export default getAdminEE;