formatting

This commit is contained in:
Shreyaschorge
2025-07-07 14:10:47 +05:30
parent f42a5f8d33
commit 193dffe03a
64 changed files with 6398 additions and 985 deletions

View File

@@ -26,9 +26,9 @@ async function lookupFidByCustodyAddress(custodyAddress, apiKey) {
`https://api.neynar.com/v2/farcaster/user/bulk-by-address?addresses=${lowerCasedCustodyAddress}&address_types=custody_address`,
{
headers: {
'accept': 'application/json',
'x-api-key': 'FARCASTER_V2_FRAMES_DEMO'
}
accept: 'application/json',
'x-api-key': 'FARCASTER_V2_FRAMES_DEMO',
},
}
);
@@ -37,7 +37,10 @@ async function lookupFidByCustodyAddress(custodyAddress, apiKey) {
}
const data = await response.json();
if (!data[lowerCasedCustodyAddress]?.length || !data[lowerCasedCustodyAddress][0].custody_address) {
if (
!data[lowerCasedCustodyAddress]?.length ||
!data[lowerCasedCustodyAddress][0].custody_address
) {
throw new Error('No FID found for this custody address');
}
@@ -51,19 +54,22 @@ async function loadEnvLocal() {
{
type: 'confirm',
name: 'loadLocal',
message: 'Found .env.local, likely created by the install script - would you like to load its values?',
default: false
}
message:
'Found .env.local, likely created by the install script - would you like to load its values?',
default: false,
},
]);
if (loadLocal) {
console.log('Loading values from .env.local...');
const localEnv = dotenv.parse(fs.readFileSync('.env.local'));
// Copy all values except SEED_PHRASE to .env
const envContent = fs.existsSync('.env') ? fs.readFileSync('.env', 'utf8') + '\n' : '';
const envContent = fs.existsSync('.env')
? fs.readFileSync('.env', 'utf8') + '\n'
: '';
let newEnvContent = envContent;
for (const [key, value] of Object.entries(localEnv)) {
if (key !== 'SEED_PHRASE') {
// Update process.env
@@ -74,7 +80,7 @@ async function loadEnvLocal() {
}
}
}
// Write updated content to .env
fs.writeFileSync('.env', newEnvContent);
console.log('✅ Values from .env.local have been written to .env');
@@ -102,9 +108,13 @@ const projectRoot = path.join(__dirname, '..');
async function validateDomain(domain) {
// Remove http:// or https:// if present
const cleanDomain = domain.replace(/^https?:\/\//, '');
// Basic domain validation
if (!cleanDomain.match(/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/)) {
if (
!cleanDomain.match(
/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/
)
) {
throw new Error('Invalid domain format');
}
@@ -120,8 +130,8 @@ async function queryNeynarApp(apiKey) {
`https://api.neynar.com/portal/app_by_api_key`,
{
headers: {
'x-api-key': apiKey
}
'x-api-key': apiKey,
},
}
);
const data = await response.json();
@@ -142,24 +152,36 @@ async function validateSeedPhrase(seedPhrase) {
}
}
async function generateFarcasterMetadata(domain, fid, accountAddress, seedPhrase, webhookUrl) {
async function generateFarcasterMetadata(
domain,
fid,
accountAddress,
seedPhrase,
webhookUrl
) {
const header = {
type: 'custody',
key: accountAddress,
fid,
};
const encodedHeader = Buffer.from(JSON.stringify(header), 'utf-8').toString('base64');
const encodedHeader = Buffer.from(JSON.stringify(header), 'utf-8').toString(
'base64'
);
const payload = {
domain
domain,
};
const encodedPayload = Buffer.from(JSON.stringify(payload), 'utf-8').toString('base64url');
const encodedPayload = Buffer.from(JSON.stringify(payload), 'utf-8').toString(
'base64url'
);
const account = mnemonicToAccount(seedPhrase);
const signature = await account.signMessage({
message: `${encodedHeader}.${encodedPayload}`
const signature = await account.signMessage({
message: `${encodedHeader}.${encodedPayload}`,
});
const encodedSignature = Buffer.from(signature, 'utf-8').toString('base64url');
const encodedSignature = Buffer.from(signature, 'utf-8').toString(
'base64url'
);
const tags = process.env.NEXT_PUBLIC_MINI_APP_TAGS?.split(',');
@@ -167,17 +189,17 @@ async function generateFarcasterMetadata(domain, fid, accountAddress, seedPhrase
accountAssociation: {
header: encodedHeader,
payload: encodedPayload,
signature: encodedSignature
signature: encodedSignature,
},
frame: {
version: "1",
version: '1',
name: process.env.NEXT_PUBLIC_MINI_APP_NAME,
iconUrl: `https://${domain}/icon.png`,
homeUrl: `https://${domain}`,
imageUrl: `https://${domain}/api/opengraph-image`,
buttonTitle: process.env.NEXT_PUBLIC_MINI_APP_BUTTON_TEXT,
splashImageUrl: `https://${domain}/splash.png`,
splashBackgroundColor: "#f7f7f7",
splashBackgroundColor: '#f7f7f7',
webhookUrl,
description: process.env.NEXT_PUBLIC_MINI_APP_DESCRIPTION,
primaryCategory: process.env.NEXT_PUBLIC_MINI_APP_PRIMARY_CATEGORY,
@@ -190,7 +212,7 @@ async function main() {
try {
console.log('\n📝 Checking environment variables...');
console.log('Loading values from .env...');
// Load .env.local if user wants to
await loadEnvLocal();
@@ -199,16 +221,17 @@ async function main() {
{
type: 'input',
name: 'domain',
message: 'Enter the domain where your mini app will be deployed (e.g., example.com):',
validate: async (input) => {
message:
'Enter the domain where your mini app will be deployed (e.g., example.com):',
validate: async input => {
try {
await validateDomain(input);
return true;
} catch (error) {
return error.message;
}
}
}
},
},
]);
// Get frame name from user
@@ -218,13 +241,13 @@ async function main() {
name: 'frameName',
message: 'Enter the name for your mini app (e.g., My Cool Mini App):',
default: process.env.NEXT_PUBLIC_MINI_APP_NAME,
validate: (input) => {
validate: input => {
if (input.trim() === '') {
return 'Mini app name cannot be empty';
}
return true;
}
}
},
},
]);
// Get button text from user
@@ -233,14 +256,15 @@ async function main() {
type: 'input',
name: 'buttonText',
message: 'Enter the text for your mini app button:',
default: process.env.NEXT_PUBLIC_MINI_APP_BUTTON_TEXT || 'Launch Mini App',
validate: (input) => {
default:
process.env.NEXT_PUBLIC_MINI_APP_BUTTON_TEXT || 'Launch Mini App',
validate: input => {
if (input.trim() === '') {
return 'Button text cannot be empty';
}
return true;
}
}
},
},
]);
// Get Neynar configuration
@@ -254,9 +278,10 @@ async function main() {
{
type: 'password',
name: 'neynarApiKey',
message: 'Enter your Neynar API key (optional - leave blank to skip):',
default: null
}
message:
'Enter your Neynar API key (optional - leave blank to skip):',
default: null,
},
]);
neynarApiKey = inputNeynarApiKey;
} else {
@@ -284,14 +309,16 @@ async function main() {
}
// If we get here, the API key was invalid
console.log('\n⚠ Could not find Neynar app information. The API key may be incorrect.');
console.log(
'\n⚠ Could not find Neynar app information. The API key may be incorrect.'
);
const { retry } = await inquirer.prompt([
{
type: 'confirm',
name: 'retry',
message: 'Would you like to try a different API key?',
default: true
}
default: true,
},
]);
// Reset for retry
@@ -311,18 +338,19 @@ async function main() {
{
type: 'password',
name: 'seedPhrase',
message: 'Your farcaster custody account seed phrase is required to create a signature proving this app was created by you.\n' +
`⚠️ ${yellow}${italic}seed phrase is only used to sign the mini app manifest, then discarded${reset} ⚠️\n` +
'Seed phrase:',
validate: async (input) => {
message:
'Your farcaster custody account seed phrase is required to create a signature proving this app was created by you.\n' +
`⚠️ ${yellow}${italic}seed phrase is only used to sign the mini app manifest, then discarded${reset} ⚠️\n` +
'Seed phrase:',
validate: async input => {
try {
await validateSeedPhrase(input);
return true;
} catch (error) {
return error.message;
}
}
}
},
},
]);
seedPhrase = inputSeedPhrase;
} else {
@@ -333,22 +361,36 @@ async function main() {
const accountAddress = await validateSeedPhrase(seedPhrase);
console.log('✅ Generated account address from seed phrase');
const fid = await lookupFidByCustodyAddress(accountAddress, neynarApiKey ?? 'FARCASTER_V2_FRAMES_DEMO');
const fid = await lookupFidByCustodyAddress(
accountAddress,
neynarApiKey ?? 'FARCASTER_V2_FRAMES_DEMO'
);
// Generate and sign manifest
console.log('\n🔨 Generating mini app manifest...');
// Determine webhook URL based on environment variables
const webhookUrl = neynarApiKey && neynarClientId
? `https://api.neynar.com/f/app/${neynarClientId}/event`
: `${domain}/api/webhook`;
const metadata = await generateFarcasterMetadata(domain, fid, accountAddress, seedPhrase, webhookUrl);
console.log('\n✅ Mini app manifest generated' + (seedPhrase ? ' and signed' : ''));
// Determine webhook URL based on environment variables
const webhookUrl =
neynarApiKey && neynarClientId
? `https://api.neynar.com/f/app/${neynarClientId}/event`
: `${domain}/api/webhook`;
const metadata = await generateFarcasterMetadata(
domain,
fid,
accountAddress,
seedPhrase,
webhookUrl
);
console.log(
'\n✅ Mini app manifest generated' + (seedPhrase ? ' and signed' : '')
);
// Read existing .env file or create new one
const envPath = path.join(projectRoot, '.env');
let envContent = fs.existsSync(envPath) ? fs.readFileSync(envPath, 'utf8') : '';
let envContent = fs.existsSync(envPath)
? fs.readFileSync(envPath, 'utf8')
: '';
// Add or update environment variables
const newEnvVars = [
@@ -366,10 +408,10 @@ async function main() {
`NEXT_PUBLIC_ANALYTICS_ENABLED="${process.env.NEXT_PUBLIC_ANALYTICS_ENABLED || 'false'}"`,
// Neynar configuration (if it exists in current env)
...(process.env.NEYNAR_API_KEY ?
[`NEYNAR_API_KEY="${process.env.NEYNAR_API_KEY}"`] : []),
...(neynarClientId ?
[`NEYNAR_CLIENT_ID="${neynarClientId}"`] : []),
...(process.env.NEYNAR_API_KEY
? [`NEYNAR_API_KEY="${process.env.NEYNAR_API_KEY}"`]
: []),
...(neynarClientId ? [`NEYNAR_CLIENT_ID="${neynarClientId}"`] : []),
// FID (if it exists in current env)
...(process.env.FID ? [`FID="${process.env.FID}"`] : []),
@@ -406,16 +448,21 @@ async function main() {
// Run next build
console.log('\nBuilding Next.js application...');
const nextBin = path.normalize(path.join(projectRoot, 'node_modules', '.bin', 'next'));
execSync(`"${nextBin}" build`, {
cwd: projectRoot,
const nextBin = path.normalize(
path.join(projectRoot, 'node_modules', '.bin', 'next')
);
execSync(`"${nextBin}" build`, {
cwd: projectRoot,
stdio: 'inherit',
shell: process.platform === 'win32'
shell: process.platform === 'win32',
});
console.log('\n✨ Build complete! Your mini app is ready for deployment. 🪐');
console.log('📝 Make sure to configure the environment variables from .env in your hosting provider');
console.log(
'\n✨ Build complete! Your mini app is ready for deployment. 🪐'
);
console.log(
'📝 Make sure to configure the environment variables from .env in your hosting provider'
);
} catch (error) {
console.error('\n❌ Error:', error.message);
process.exit(1);