π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: hubspot integration
Nevo David20609d33a003
diff --git a/apps/frontend/public/icons/third-party/hubspot.png b/apps/frontend/public/icons/third-party/hubspot.pngnew file mode 100644index 000000000..a25e8c879Binary files /dev/null and b/apps/frontend/public/icons/third-party/hubspot.png differdiff --git a/apps/frontend/src/components/third-parties/third-party.list.component.tsx b/apps/frontend/src/components/third-parties/third-party.list.component.tsxindex f8d7a842c..f072fab4a 100644--- a/apps/frontend/src/components/third-parties/third-party.list.component.tsx+++ b/apps/frontend/src/components/third-parties/third-party.list.component.tsx@@ -125,11 +125,24 @@ export const ThirdPartyListComponent: FC<{ reload: () => void }> = (props) => {[]);+ // Installed on the other platform, not connected here with an API key.+ // noopener: the page it ends on closes itself when it has an opener+ const install = useCallback(+ (installUrl: string) => () => {+ window.open(installUrl, '_blank', 'noopener,noreferrer');+ },+ []+ );+return (<div className="grid grid-cols-4 tablet:grid-cols-3 mobile:!grid-cols-2 gap-[10px] justify-items-center justify-center">{data?.map((p: any) => (<div- onClick={addApiKey(p.title, p.identifier)}+ onClick={+ p.installUrl+ ? install(p.installUrl)+ : addApiKey(p.title, p.identifier)+ }key={p.identifier}className="w-full h-full p-[20px] mobile:p-[14px] min-h-[100px] text-[14px] bg-newTableHeader hover:bg-newTableBorder rounded-[8px] transition-all text-textColor relative flex flex-col gap-[15px] cursor-pointer">diff --git a/libraries/nestjs-libraries/src/3rdparties/hubspot/hubspot.provider.ts b/libraries/nestjs-libraries/src/3rdparties/hubspot/hubspot.provider.tsnew file mode 100644index 000000000..92460d6b9--- /dev/null+++ b/libraries/nestjs-libraries/src/3rdparties/hubspot/hubspot.provider.ts@@ -0,0 +1,24 @@+import {+ ThirdParty,+ ThirdPartyAbstract,+} from '@gitroom/nestjs-libraries/3rdparties/thirdparty.interface';+import { hubspotInstallUrl } from '@gitroom/nestjs-libraries/database/prisma/oauth/oauth.service';++@ThirdParty({+ identifier: 'hubspot',+ title: 'HubSpot',+ description:+ 'Schedule and manage your posts from HubSpot agents in Agent Builder.',+ fields: [],+ installUrl: hubspotInstallUrl,+})+export class HubspotProvider extends ThirdPartyAbstract {+ // Installed in HubSpot through installUrl, never connected with an API key+ async checkConnection(): Promise<false> {+ return false;+ }++ async sendData(): Promise<string> {+ throw new Error('HubSpot provider does not support sendData');+ }+}diff --git a/libraries/nestjs-libraries/src/3rdparties/thirdparty.interface.ts b/libraries/nestjs-libraries/src/3rdparties/thirdparty.interface.tsindex 828ca6f16..5a612ba81 100644--- a/libraries/nestjs-libraries/src/3rdparties/thirdparty.interface.ts+++ b/libraries/nestjs-libraries/src/3rdparties/thirdparty.interface.ts@@ -11,7 +11,8 @@ export interface ThirdPartyParams {identifier: string;title: string;description: string;- position: 'media' | 'media-library' | 'webhook';+ // where a connected integration shows up in the post editor+ position?: 'media' | 'media-library' | 'webhook';fields: {name: string;description: string;@@ -19,6 +20,9 @@ export interface ThirdPartyParams {placeholder: string;validation?: RegExp;}[];+ // An integration installed on the other platform instead of connected here+ // with an API key: the list opens this link. undefined hides it+ installUrl?: () => string | undefined;}export function ThirdParty(params: ThirdPartyParams) {diff --git a/libraries/nestjs-libraries/src/3rdparties/thirdparty.manager.ts b/libraries/nestjs-libraries/src/3rdparties/thirdparty.manager.tsindex 2f367fa9d..642d691e5 100644--- a/libraries/nestjs-libraries/src/3rdparties/thirdparty.manager.ts+++ b/libraries/nestjs-libraries/src/3rdparties/thirdparty.manager.ts@@ -14,14 +14,15 @@ export class ThirdPartyManager {) {}getAllThirdParties(): any[] {- return (Reflect.getMetadata('third:party', ThirdPartyAbstract) || []).map(- (p: any) => ({+ return (Reflect.getMetadata('third:party', ThirdPartyAbstract) || [])+ .filter((p: any) => !p.installUrl || p.installUrl())+ .map((p: any) => ({identifier: p.identifier,title: p.title,description: p.description,fields: p.fields || [],- })- );+ installUrl: p.installUrl?.(),+ }));}getThirdPartyByName(diff --git a/libraries/nestjs-libraries/src/3rdparties/thirdparty.module.ts b/libraries/nestjs-libraries/src/3rdparties/thirdparty.module.tsindex d46a49bbf..65a54cb12 100644--- a/libraries/nestjs-libraries/src/3rdparties/thirdparty.module.ts+++ b/libraries/nestjs-libraries/src/3rdparties/thirdparty.module.ts@@ -1,11 +1,17 @@import { Global, Module } from '@nestjs/common';import { HeygenProvider } from '@gitroom/nestjs-libraries/3rdparties/heygen/heygen.provider';import { ReelFarmProvider } from '@gitroom/nestjs-libraries/3rdparties/reelfarm/reelfarm.provider';+import { HubspotProvider } from '@gitroom/nestjs-libraries/3rdparties/hubspot/hubspot.provider';import { ThirdPartyManager } from '@gitroom/nestjs-libraries/3rdparties/thirdparty.manager';@Global()@Module({- providers: [HeygenProvider, ReelFarmProvider, ThirdPartyManager],+ providers: [+ HeygenProvider,+ ReelFarmProvider,+ HubspotProvider,+ ThirdPartyManager,+ ],get exports() {return this.providers;},diff --git a/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts b/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.tsindex ee9a328a1..5300dca0d 100644--- a/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts+++ b/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts@@ -30,6 +30,23 @@ const hubspotTokenExpiresIn = 10 * 365 * 24 * 60 * 60;const hubspotAppClientId = () => process.env.HUBSPOT_APP_CLIENT_ID?.trim();const hubspotAppClientSecret = () =>process.env.HUBSPOT_APP_CLIENT_SECRET?.trim();+const hubspotInstallRedirectUri = () =>+ `${process.env.NEXT_PUBLIC_BACKEND_URL}/oauth/hubspot/callback`;++// The link that installs the HubSpot app in a HubSpot account (listed in+// Settings > Integrations), undefined when the install can't be completed here+export const hubspotInstallUrl = () => {+ const clientId = hubspotAppClientId();+ if (!clientId || !hubspotAppClientSecret()) {+ return undefined;+ }++ const url = new URL('https://app.hubspot.com/oauth/authorize');+ url.searchParams.set('client_id', clientId);+ url.searchParams.set('redirect_uri', hubspotInstallRedirectUri());+ url.searchParams.set('scope', 'oauth');+ return url.toString();+};// Postiz Cloud only, a self-hosted install has nothing to relay toexport const selfHostedRelayEnabled = () =>@@ -696,7 +713,7 @@ export class OAuthService {grant_type: 'authorization_code',client_id: clientId,client_secret: clientSecret,- redirect_uri: `${process.env.NEXT_PUBLIC_BACKEND_URL}/oauth/hubspot/callback`,+ redirect_uri: hubspotInstallRedirectUri(),code,}),signal: AbortSignal.timeout(30000),