Compare commits

...

3 Commits

Author SHA1 Message Date
Nevo David
3f36259489 feat: beehiiv 2026-10-06 09:32:40 +07:00
Nevo David
61b34fd40c Merge branch 'main' into feat/beehiiv 2026-10-05 22:01:47 +07:00
Nevo David
5b435b6e42 feat: behiiv 2026-09-28 14:26:08 +07:00
12 changed files with 432 additions and 0 deletions

View File

@ -107,6 +107,8 @@ DRIBBBLE_CLIENT_ID=""
DRIBBBLE_CLIENT_SECRET=""
TUMBLR_CLIENT_ID=""
TUMBLR_CLIENT_SECRET=""
BEEHIIV_CLIENT_ID=""
BEEHIIV_CLIENT_SECRET=""
DISCORD_CLIENT_ID=""
DISCORD_CLIENT_SECRET=""
DISCORD_BOT_TOKEN_ID=""

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -273,6 +273,7 @@ export const ContinueIntegration: FC<{
youtube: 'YouTube',
gmb: 'Google Business',
tumblr: 'Tumblr',
beehiiv: 'beehiiv',
'tiktok-business': 'TikTok Business',
};
return names[provider] || provider;

View File

@ -0,0 +1,65 @@
'use client';
import { FC } from 'react';
import {
PostComment,
withProvider,
} from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
import { BeehiivDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/beehiiv.dto';
import { Input } from '@gitroom/react/form/input';
import { Select } from '@gitroom/react/form/select';
import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values';
import { MediaComponent } from '@gitroom/frontend/components/media/media.component';
const status = [
{
label: 'Draft',
value: 'draft',
},
{
label: 'Publish',
value: 'confirmed',
},
];
const BeehiivSettings: FC = () => {
const { register } = useSettings();
return (
<>
<div className="text-[14px] mb-[18px] text-balance">
beehiiv only allows creating posts through its API on Pro and
Enterprise plans. This applies to both drafts and published posts.
</div>
<Input label="Title" {...register('title')} />
<Input label="Subtitle" {...register('subtitle')} />
<Select
label="Status"
{...register('status', {
value: 'draft',
})}
>
{status.map((t) => (
<option key={t.value} value={t.value}>
{t.label}
</option>
))}
</Select>
<MediaComponent
type="image"
label="Thumbnail"
description="Thumbnail picture (optional)"
{...register('thumbnail')}
/>
</>
);
};
export default withProvider({
postComment: PostComment.POST,
minimumCharacters: [],
SettingsComponent: BeehiivSettings,
CustomPreviewComponent: undefined,
dto: BeehiivDto,
maximumCharacters: 300000,
});

View File

@ -0,0 +1,54 @@
'use client';
import { withContinueProvider } from '../with-continue-provider';
interface BeehiivPublicationItem {
id: string;
name: string;
username?: string;
}
interface BeehiivPublicationSelection {
id: string;
}
export const BeehiivContinue = withContinueProvider<
BeehiivPublicationItem,
BeehiivPublicationSelection
>({
endpoint: 'pages',
swrKey: 'load-beehiiv-publications',
titleKey: 'select_beehiiv_publication',
titleDefault: 'Select beehiiv Publication:',
emptyStateMessages: [
{
key: 'beehiiv_no_publications_found',
text: "We couldn't find any beehiiv publications connected to your account.",
},
{
key: 'beehiiv_ensure_publication_exists',
text: 'Please ensure your beehiiv workspace has a publication you can post to.',
},
{
key: 'beehiiv_try_again',
text: 'Please close this dialog, delete the integration and try again.',
},
],
getItemId: (item) => item.id,
getSelectionValue: (item) => ({ id: item.id }),
transformSaveData: (selection) => selection,
isSelected: (item, selection) => selection?.id === item.id,
renderItem: (item) => (
<>
<div className="flex justify-center">
<div className="w-[80px] h-[80px] bg-input rounded-full flex items-center justify-center text-[32px] font-semibold">
{item.name?.charAt(0)?.toUpperCase()}
</div>
</div>
<div className="text-sm font-medium">{item.name}</div>
{item.username && (
<div className="text-xs text-gray-500 break-all">{item.username}</div>
)}
</>
),
});

View File

@ -6,6 +6,7 @@ import { LinkedinContinue } from '@gitroom/frontend/components/new-launch/provid
import { GmbContinue } from '@gitroom/frontend/components/new-launch/providers/continue-provider/gmb/gmb.continue';
import { YoutubeContinue } from '@gitroom/frontend/components/new-launch/providers/continue-provider/youtube/youtube.continue';
import { TumblrContinue } from '@gitroom/frontend/components/new-launch/providers/continue-provider/tumblr/tumblr.continue';
import { BeehiivContinue } from '@gitroom/frontend/components/new-launch/providers/continue-provider/beehiiv/beehiiv.continue';
export const continueProviderList = {
instagram: InstagramContinue,
@ -14,4 +15,5 @@ export const continueProviderList = {
gmb: GmbContinue,
youtube: YoutubeContinue,
tumblr: TumblrContinue,
beehiiv: BeehiivContinue,
};

View File

@ -34,6 +34,7 @@ import { useT } from '@gitroom/react/translation/get.transation.service.client';
import { PostComment } from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
import WordpressProvider from '@gitroom/frontend/components/new-launch/providers/wordpress/wordpress.provider';
import ListmonkProvider from '@gitroom/frontend/components/new-launch/providers/listmonk/listmonk.provider';
import BeehiivProvider from '@gitroom/frontend/components/new-launch/providers/beehiiv/beehiiv.provider';
import GmbProvider from '@gitroom/frontend/components/new-launch/providers/gmb/gmb.provider';
import MoltbookProvider from '@gitroom/frontend/components/new-launch/providers/moltbook/moltbook.provider';
import SkoolProvider from '@gitroom/frontend/components/new-launch/providers/skool/skool.provider';
@ -158,6 +159,10 @@ export const Providers = [
identifier: 'listmonk',
component: ListmonkProvider,
},
{
identifier: 'beehiiv',
component: BeehiivProvider,
},
{
identifier: 'gmb',
component: GmbProvider,

View File

@ -62,6 +62,8 @@ services:
DRIBBBLE_CLIENT_SECRET: ''
TUMBLR_CLIENT_ID: ''
TUMBLR_CLIENT_SECRET: ''
BEEHIIV_CLIENT_ID: ''
BEEHIIV_CLIENT_SECRET: ''
DISCORD_CLIENT_ID: ''
DISCORD_CLIENT_SECRET: ''
DISCORD_BOT_TOKEN_ID: ''

View File

@ -17,6 +17,7 @@ import { DevToSettingsDto } from '@gitroom/nestjs-libraries/dtos/posts/providers
import { HashnodeSettingsDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/hashnode.settings.dto';
import { WordpressDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/wordpress.dto';
import { ListmonkDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/listmonk.dto';
import { BeehiivDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/beehiiv.dto';
import { GmbSettingsDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/gmb.settings.dto';
import { FarcasterDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/farcaster.dto';
import { FacebookDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/facebook.dto';
@ -49,6 +50,7 @@ export type AllProvidersSettings =
| ProviderExtension<'hashnode', HashnodeSettingsDto>
| ProviderExtension<'wordpress', WordpressDto>
| ProviderExtension<'listmonk', ListmonkDto>
| ProviderExtension<'beehiiv', BeehiivDto>
| ProviderExtension<'gmb', GmbSettingsDto>
| ProviderExtension<'facebook', FacebookDto>
| ProviderExtension<'wrapcast', FarcasterDto>
@ -89,6 +91,7 @@ export const allProviders = (setEmpty?: any) => {
{ value: WordpressDto, name: 'wordpress' },
{ value: HashnodeSettingsDto, name: 'hashnode' },
{ value: ListmonkDto, name: 'listmonk' },
{ value: BeehiivDto, name: 'beehiiv' },
{ value: GmbSettingsDto, name: 'gmb' },
{ value: FarcasterDto, name: 'wrapcast' },
{ value: FacebookDto, name: 'facebook' },

View File

@ -0,0 +1,35 @@
import {
IsDefined,
IsIn,
IsOptional,
IsString,
MinLength,
ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';
import { JSONSchema } from 'class-validator-jsonschema';
import { MediaDto } from '@gitroom/nestjs-libraries/dtos/media/media.dto';
export class BeehiivDto {
@IsString()
@MinLength(1)
@IsDefined()
title: string;
@IsString()
@IsOptional()
subtitle?: string;
@IsOptional()
@ValidateNested()
@Type(() => MediaDto)
thumbnail?: MediaDto;
@IsIn(['draft', 'confirmed'])
@IsOptional()
@JSONSchema({
description:
'draft (default) creates a draft in beehiiv, confirmed publishes it. Both require a beehiiv Pro / Enterprise plan',
})
status?: 'draft' | 'confirmed';
}

View File

@ -29,6 +29,7 @@ import { NostrProvider } from '@gitroom/nestjs-libraries/integrations/social/nos
import { VkProvider } from '@gitroom/nestjs-libraries/integrations/social/vk.provider';
import { WordpressProvider } from '@gitroom/nestjs-libraries/integrations/social/wordpress.provider';
import { ListmonkProvider } from '@gitroom/nestjs-libraries/integrations/social/listmonk.provider';
import { BeehiivProvider } from '@gitroom/nestjs-libraries/integrations/social/beehiiv.provider';
import { GmbProvider } from '@gitroom/nestjs-libraries/integrations/social/gmb.provider';
import { KickProvider } from '@gitroom/nestjs-libraries/integrations/social/kick.provider';
import { TwitchProvider } from '@gitroom/nestjs-libraries/integrations/social/twitch.provider';
@ -70,6 +71,7 @@ export const socialIntegrationList: Array<SocialAbstract & SocialProvider> = [
new HashnodeProvider(),
new WordpressProvider(),
new ListmonkProvider(),
new BeehiivProvider(),
new MoltbookProvider(),
new WhopProvider(),
new SkoolProvider(),

View File

@ -0,0 +1,261 @@
import {
AuthTokenDetails,
PostDetails,
PostResponse,
SocialProvider,
} from '@gitroom/nestjs-libraries/integrations/social/social.integrations.interface';
import { SocialAbstract } from '@gitroom/nestjs-libraries/integrations/social.abstract';
import { Integration } from '@prisma/client';
import { makeSecureId } from '@gitroom/nestjs-libraries/services/make.secure.id';
import { BeehiivDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/beehiiv.dto';
const BEEHIIV_OAUTH_URL = 'https://app.beehiiv.com/oauth';
const BEEHIIV_API_URL = 'https://api.beehiiv.com/v2';
interface BeehiivTokenResponse {
access_token: string;
refresh_token?: string;
expires_in: number;
scope?: string;
}
interface BeehiivWorkspace {
data: {
id: string;
name: string;
};
}
interface BeehiivPublications {
data: {
id: string;
name: string;
organization_name: string;
}[];
}
export class BeehiivProvider extends SocialAbstract implements SocialProvider {
override maxConcurrentJob = 3;
identifier = 'beehiiv';
name = 'beehiiv';
toolTip =
'Posting to beehiiv (including drafts) requires a beehiiv Pro or Enterprise plan.';
isBetweenSteps = true;
scopes = ['identify:read', 'publications:read', 'posts:write'];
editor = 'html' as const;
dto = BeehiivDto;
maxLength() {
return 100000000;
}
// beehiiv returns { errors: [{ message, code }] }, surface its message
// instead of a generic failure (e.g. a plan that can't publish via the API).
override handleErrors(body: string, status: number) {
if ([400, 403, 404, 422].includes(status)) {
try {
const message = JSON.parse(body)?.errors?.[0]?.message;
if (message) {
return {
type: 'bad-body' as const,
value: message,
};
}
} catch (err) {
// Non-JSON error body
}
}
return undefined;
}
async refreshToken(refreshToken: string): Promise<AuthTokenDetails> {
const token = await this.requestToken(
new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: refreshToken,
client_id: process.env.BEEHIIV_CLIENT_ID!,
client_secret: process.env.BEEHIIV_CLIENT_SECRET!,
})
);
// beehiiv rotates the refresh token, so no extra call here that could fail
// and lose it - reConnect fills the publication details afterwards.
return {
id: '',
name: '',
accessToken: token.access_token,
refreshToken: token.refresh_token || refreshToken,
expiresIn: token.expires_in,
picture: '',
username: '',
};
}
async generateAuthUrl() {
const state = makeSecureId(6);
const params = new URLSearchParams({
client_id: process.env.BEEHIIV_CLIENT_ID!,
redirect_uri: this.redirectUri(),
response_type: 'code',
scope: this.scopes.join(' '),
state,
});
return {
url: `${BEEHIIV_OAUTH_URL}/authorize?${params.toString()}`,
codeVerifier: makeSecureId(10),
state,
};
}
async authenticate(params: { code: string; codeVerifier: string }) {
const token = await this.requestToken(
new URLSearchParams({
grant_type: 'authorization_code',
code: params.code,
client_id: process.env.BEEHIIV_CLIENT_ID!,
client_secret: process.env.BEEHIIV_CLIENT_SECRET!,
redirect_uri: this.redirectUri(),
})
);
if (token.scope) {
this.checkScopes(this.scopes, token.scope);
}
const { data } = await this.getWorkspace(token.access_token);
return {
id: data.id,
name: data.name,
accessToken: token.access_token,
refreshToken: token.refresh_token || '',
expiresIn: token.expires_in,
picture: '',
username: data.name,
};
}
async pages(accessToken: string) {
const { data } = (await (
await this.fetch(
`${BEEHIIV_API_URL}/publications?limit=100`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
this.identifier
)
).json()) as BeehiivPublications;
return data.map((publication) => ({
id: publication.id,
name: publication.name,
username: publication.organization_name,
}));
}
async fetchPageInformation(accessToken: string, data: { id: string }) {
const publications = await this.pages(accessToken);
const publication = publications.find((item) => item.id === data.id);
if (!publication) {
throw new Error('beehiiv publication not found');
}
return {
id: publication.id,
name: publication.name,
access_token: accessToken,
picture: '',
username: publication.username,
};
}
async reConnect(
id: string,
requiredId: string,
accessToken: string
): Promise<Omit<AuthTokenDetails, 'refreshToken' | 'expiresIn'>> {
const information = await this.fetchPageInformation(accessToken, {
id: requiredId,
});
return {
id: information.id,
name: information.name,
accessToken: information.access_token,
picture: information.picture,
username: information.username,
};
}
async post(
id: string,
accessToken: string,
postDetails: PostDetails<BeehiivDto>[],
integration: Integration
): Promise<PostResponse[]> {
const { settings } = postDetails?.[0] || { settings: {} as BeehiivDto };
const { data } = await (
await this.fetch(
`${BEEHIIV_API_URL}/publications/${id}/posts`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({
title: settings.title,
...(settings.subtitle ? { subtitle: settings.subtitle } : {}),
body_content: postDetails[0].message,
status: settings.status || 'draft',
...(settings?.thumbnail?.path
? { thumbnail_image_url: settings.thumbnail.path }
: {}),
}),
},
this.identifier
)
).json();
return [
{
id: postDetails[0].id,
status: 'completed',
postId: data.id,
releaseURL: data.preview_url || '',
},
];
}
private redirectUri() {
return `${process.env.FRONTEND_URL}/integrations/social/beehiiv`;
}
private async requestToken(body: URLSearchParams) {
return (await (
await this.fetch(`${BEEHIIV_OAUTH_URL}/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body,
})
).json()) as BeehiivTokenResponse;
}
private async getWorkspace(accessToken: string) {
return (await (
await this.fetch(`${BEEHIIV_API_URL}/workspaces/identify`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
})
).json()) as BeehiivWorkspace;
}
}