π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: enterprise
Nevo Davidf5ef80546edb
diff --git a/apps/backend/src/api/routes/enterprise.controller.ts b/apps/backend/src/api/routes/enterprise.controller.tsnew file mode 100644index 000000000..06abf7d6d--- /dev/null+++ b/apps/backend/src/api/routes/enterprise.controller.ts@@ -0,0 +1,78 @@+import { Body, Controller, Param, Post, Res } from '@nestjs/common';+import { ApiTags } from '@nestjs/swagger';+import { AuthService } from '@gitroom/helpers/auth/auth.service';+import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';+import { IntegrationManager } from '@gitroom/nestjs-libraries/integrations/integration.manager';+import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.service';++@ApiTags('Enterprise')+@Controller('/enterprise')+export class EnterpriseController {+ constructor(+ private _integrationManager: IntegrationManager,+ private _organizationService: OrganizationService+ ) {}++ @Post('/test')+ async test(@Body('params') params: string) {+ try {+ const load = AuthService.verifyJWT(params) as {+ apiKey: string;+ };++ const org = await this._organizationService.getOrgByApiKey(load.apiKey);+ return {+ connection: !!org,+ };+ } catch (err) {+ return { connection: false };+ }+ }++ @Post('/url')+ async redirectParams(@Body('params') params: string) {+ try {+ const load = AuthService.verifyJWT(params) as {+ redirectUrl: string;+ apiKey: string;+ refreshId?: string;+ provider: string;+ };++ if (!load || !load.redirectUrl || !load.apiKey || !load.provider) {+ return;+ }++ const org = await this._organizationService.getOrgByApiKey(load.apiKey);++ if (!org) {+ throw new Error('Organization not found');+ }++ if (+ !this._integrationManager+ .getAllowedSocialsIntegrations()+ .includes(load.provider)+ ) {+ throw new Error('Integration not allowed');+ }++ const integrationProvider = this._integrationManager.getSocialIntegration(+ load.provider+ );++ const { codeVerifier, state, url } =+ await integrationProvider.generateAuthUrl();++ if (load.refreshId) {+ await ioRedis.set(`refresh:${state}`, load.refreshId, 'EX', 3600);+ }++ await ioRedis.set(`redirect:${state}`, load.redirectUrl, 'EX', 3600);+ await ioRedis.set(`organization:${state}`, org.id, 'EX', 3600);+ await ioRedis.set(`login:${state}`, codeVerifier, 'EX', 3600);++ return url;+ } catch (err) {}+ }+}