Guidelines and best practices for building applications with [Beefree SDK](https://docs.beefree.io/beefree-sdk), including installation, authentication, configuration, customization, and template management
Add this skill
npx mdskills install PatrickJS/cursor-beefreesdkComprehensive, well-structured guidelines with strong security practices and extensive code examples
Guidelines and best practices for building applications with Beefree SDK, including installation, authentication, configuration, customization, and template management.
npm install @beefree.io/sdk
# or
yarn add @beefree.io/sdk
{
"dependencies": {
"@beefree.io/sdk": "^9.0.2-fix-optional-url-config.0",
"axios": "^1.10.0",
"express": "^5.1.0",
"cors": "^2.8.5",
"dotenv": "^17.2.0"
}
}
.env file in your project root with your Beefree credentials:
BEE_CLIENT_ID=your_client_id_here
BEE_CLIENT_SECRET=your_client_secret_here
proxy-server.js) to handle authentication:
import express from 'express';
import cors from 'cors';
import axios from 'axios';
import dotenv from 'dotenv';
dotenv.config();
const app = express();
const PORT = 3001;
app.use(cors());
app.use(express.json());
const BEE_CLIENT_ID = process.env.BEE_CLIENT_ID;
const BEE_CLIENT_SECRET = process.env.BEE_CLIENT_SECRET;
// V2 Auth Endpoint
app.post('/proxy/bee-auth', async (req, res) => {
try {
const { uid } = req.body;
const response = await axios.post(
'https://auth.getbee.io/loginV2',
{
client_id: BEE_CLIENT_ID,
client_secret: BEE_CLIENT_SECRET,
uid: uid || 'demo-user'
},
{ headers: { 'Content-Type': 'application/json' } }
);
res.json(response.data);
} catch (error) {
console.error('Auth error:', error.message);
res.status(500).json({ error: 'Failed to authenticate' });
}
});
app.listen(PORT, () => {
console.log(`Proxy server running on http://localhost:${PORT}`);
});
https://auth.getbee.io/loginV2const token = await fetch('http://localhost:3001/proxy/bee-auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ uid: 'demo-user' })
}).then(res => res.json());
#beefree-sdk-container {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
height: 600px;
width: 90%;
margin: 20px auto;
border: 1px solid #ddd;
border-radius: 8px;
}
const containerRef = useRef(null);
return (
);
container parameter in your configuration:
const beeConfig = {
container: 'beefree-sdk-container', // Required
language: 'en-US'
};
const beeConfig = {
container: 'beefree-sdk-container', // Required
language: 'en-US',
specialLinks: [
{
type: "unsubscribe",
label: "Unsubscribe",
link: "http://[unsubscribe]/",
},
{
type: "subscribe",
label: "Subscribe",
link: "http://[subscribe]/",
},
],
mergeTags: [
{
name: "First Name",
value: "[first_name]",
},
{
name: "Last Name",
value: "[last_name]",
},
{
name: "Email",
value: "[email]",
},
]
};
const beeConfig = {
container: 'beefree-sdk-container',
onSave: function (jsonFile, htmlFile) {
console.log("Template saved:", jsonFile);
// Implement custom save logic here
},
onAutoSave: function (jsonFile) {
console.log("Auto-saving template...");
localStorage.setItem("email.autosave", jsonFile);
},
onSend: function (htmlFile) {
console.log("Email ready to send:", htmlFile);
// Implement custom send logic here
},
onError: function (errorMessage) {
console.error("Beefree SDK error:", errorMessage);
// Handle errors appropriately
}
};
async function initializeBeefree(authResponse) {
try {
const bee = new BeefreeSDK(authResponse);
bee.start(beeConfig, {});
console.log('Beefree SDK initialized successfully');
} catch (error) {
console.error('Failed to initialize Beefree SDK:', error);
}
}
useEffect(() => {
async function initializeEditor() {
const beeConfig = {
container: 'beefree-react-demo',
language: 'en-US',
onSave: (pageJson: string, pageHtml: string, ampHtml: string | null, templateVersion: number, language: string | null) => {
console.log('Saved!', { pageJson, pageHtml, ampHtml, templateVersion, language });
},
onError: (error: unknown) => {
console.error('Error:', error);
}
};
const token = await fetch('http://localhost:3001/proxy/bee-auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ uid: 'demo-user' })
}).then(res => res.json());
const bee = new BeefreeSDK(token);
bee.start(beeConfig, {});
}
initializeEditor();
}, []);
start() method with template data to load existing templates:
// Load template from localStorage
const selectedTemplate = JSON.parse(localStorage.getItem('currentEmailData'));
if (selectedTemplate) {
beefreeSDKInstance.start(selectedTemplate);
console.log('Loaded template from localStorage');
} else {
// Start with empty template
beefreeSDKInstance.start();
console.log('Started with empty template');
}
// Save template data
localStorage.setItem('currentEmailData', JSON.stringify(templateData));
localStorage.setItem('currentEmailName', emailName);
// Load template data
const emailData = localStorage.getItem('currentEmailData');
const emailName = localStorage.getItem('currentEmailName');
onAutoSave: function (jsonFile) {
console.log("Auto-saving template...");
localStorage.setItem("email.autosave", jsonFile);
}
https://api.getbee.io/v1/conversion/html-to-jsonconst response = await fetch('https://api.getbee.io/v1/conversion/html-to-json', {
method: 'POST',
headers: {
"Authorization": "Bearer Enter Dev Console API Key as Bearer token",
"Content-Type": "text/html"
},
body: "Hello World"
});
const data = await response.json();
const importedTemplate = await importHtmlTemplate(htmlContent);
beefreeSDK.start(importedTemplate);
onError callback to handle SDK errors:
onError: function (errorMessage) {
console.error("Beefree SDK error:", errorMessage);
// Display user-friendly error message
document.getElementById('beefree-sdk-container').innerHTML =
'Error loading Beefree SDK: ' + errorMessage.message + '';
}
function getBeeToken(callback) {
fetch('/api/beefree/auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
client_id: 'your_client_id',
client_secret: 'your_client_secret',
uid: beeConfig.uid
})
})
.then(response => {
if (!response.ok) throw new Error('Auth failed: ' + response.status);
return response.json();
})
.then(data => {
callback(data);
})
.catch(error => {
console.error('Error getting Beefree token:', error);
document.getElementById('beefree-sdk-container').innerHTML =
'Failed to authenticate with Beefree. Please check your credentials and try again.';
});
}
onChange callback to track template changes:
onChange: function (jsonFile, response) {
console.log('json', jsonFile);
console.log('response', response);
},
Customize the Beefree SDK appearance with:
const beeConfig = {
container: 'beefree-sdk-container',
language: 'en-US', // or 'es-ES', 'fr-FR', etc.
};
const beeConfig = {
container: 'beefree-sdk-container',
mergeTags: [
{ name: "First Name", value: "[first_name]" },
{ name: "Last Name", value: "[last_name]" },
{ name: "Email", value: "[email]" },
{ name: "Company", value: "[company]" }
],
specialLinks: [
{ type: "unsubscribe", label: "Unsubscribe", link: "http://[unsubscribe]/" },
{ type: "subscribe", label: "Subscribe", link: "http://[subscribe]/" },
{ type: "webview", label: "View in Browser", link: "http://[webview]/" }
]
};
Reference the official Beefree SDK technical documentation for a comprehnsive reference of possible customizations.
Reference the full project at beefree-react-demo.
import { useEffect, useRef } from 'react';
import BeefreeSDK from '@beefree.io/sdk';
export default function BeefreeEditor() {
const containerRef = useRef(null);
useEffect(() => {
async function initializeEditor() {
const beeConfig = {
container: 'beefree-react-demo',
language: 'en-US',
onSave: (pageJson: string, pageHtml: string, ampHtml: string | null, templateVersion: number, language: string | null) => {
console.log('Saved!', { pageJson, pageHtml, ampHtml, templateVersion, language });
},
onError: (error: unknown) => {
console.error('Error:', error);
}
};
const token = await fetch('http://localhost:3001/proxy/bee-auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ uid: 'demo-user' })
}).then(res => res.json());
const bee = new BeefreeSDK(token);
bee.start(beeConfig, {});
}
initializeEditor();
}, []);
return (
);
}
Reference the complete project at Beefree SDK multiple-versions-concept.
Beefree SDK - Email Builder
#beefree-sdk-container {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
const beeConfig = {
container: 'beefree-sdk-container',
uid: 'demo-user-' + Date.now(),
language: 'en-US',
onSave: function (jsonFile, htmlFile) {
console.log("Template saved:", jsonFile);
},
onError: function (errorMessage) {
console.error("Beefree SDK error:", errorMessage);
}
};
function getBeeToken(callback) {
fetch('/api/beefree/auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
client_id: 'your_client_id',
client_secret: 'your_client_secret',
uid: beeConfig.uid
})
})
.then(response => response.json())
.then(data => callback(data))
.catch(error => {
console.error('Error getting Beefree token:', error);
});
}
function initializeBeefree(authResponse) {
BeefreeSDK.create(authResponse, beeConfig, function (beefreeSDKInstance) {
console.log('Beefree SDK initialized successfully');
beefreeSDKInstance.start();
});
}
getBeeToken(initializeBeefree);
Install via CLI
npx mdskills install PatrickJS/cursor-beefreesdkBeefree SDK is a free, open-source AI agent skill. Guidelines and best practices for building applications with [Beefree SDK](https://docs.beefree.io/beefree-sdk), including installation, authentication, configuration, customization, and template management
Install Beefree SDK with a single command:
npx mdskills install PatrickJS/cursor-beefreesdkThis downloads the skill files into your project and your AI agent picks them up automatically.
Beefree SDK works with Cursor. Skills use the open SKILL.md format which is compatible with any AI coding agent that reads markdown instructions.