feat: update deploy script to and manifest generation for simplicity

This commit is contained in:
veganbeef
2025-07-11 09:51:42 -07:00
parent 8c2603098a
commit d487a3e8e5
9 changed files with 236 additions and 778 deletions

View File

@@ -1,9 +1,9 @@
import { NextResponse } from 'next/server';
import { getFarcasterMetadata } from '../../../lib/utils';
import { getFarcasterDomainManifest } from '~/lib/utils';
export async function GET() {
try {
const config = await getFarcasterMetadata();
const config = await getFarcasterDomainManifest();
return NextResponse.json(config);
} catch (error) {
console.error('Error generating metadata:', error);

View File

@@ -4,6 +4,7 @@ import { useCallback, useState, useEffect } from 'react';
import { Button } from './Button';
import { useMiniApp } from '@neynar/react';
import { type ComposeCast } from "@farcaster/miniapp-sdk";
import { APP_URL } from '~/lib/constants';
interface EmbedConfig {
path?: string;
@@ -72,7 +73,7 @@ export function ShareButton({ buttonText, cast, className = '', isLoading = fals
return embed;
}
if (embed.path) {
const baseUrl = process.env.NEXT_PUBLIC_URL || window.location.origin;
const baseUrl = APP_URL || window.location.origin;
const url = new URL(`${baseUrl}${embed.path}`);
// Add UTM parameters

View File

@@ -6,6 +6,7 @@ import { ShareButton } from "../Share";
import { Button } from "../Button";
import { SignIn } from "../wallet/SignIn";
import { type Haptics } from "@farcaster/miniapp-sdk";
import { APP_URL } from "~/lib/constants";
/**
* ActionsTab component handles mini app actions like sharing, notifications, and haptic feedback.
@@ -90,7 +91,7 @@ export function ActionsTab() {
*/
const copyUserShareUrl = useCallback(async () => {
if (context?.user?.fid) {
const userShareUrl = `${process.env.NEXT_PUBLIC_URL}/share/${context.user.fid}`;
const userShareUrl = `${APP_URL}/share/${context.user.fid}`;
await navigator.clipboard.writeText(userShareUrl);
setNotificationState((prev) => ({ ...prev, shareUrlCopied: true }));
setTimeout(() => setNotificationState((prev) => ({ ...prev, shareUrlCopied: false })), 2000);
@@ -120,7 +121,7 @@ export function ActionsTab() {
cast={{
text: "Check out this awesome frame @1 @2 @3! 🚀🪐",
bestFriends: true,
embeds: [`${process.env.NEXT_PUBLIC_URL}/share/${context?.user?.fid || ''}`]
embeds: [`${APP_URL}/share/${context?.user?.fid || ''}`]
}}
className="w-full"
/>

View File

@@ -1,3 +1,5 @@
import { type AccountAssociation } from '@farcaster/miniapp-node';
/**
* Application constants and configuration values.
*
@@ -14,63 +16,70 @@
* The base URL of the application.
* Used for generating absolute URLs for assets and API endpoints.
*/
export const APP_URL = process.env.NEXT_PUBLIC_URL!;
export const APP_URL: string = process.env.NEXT_PUBLIC_URL!;
/**
* The name of the mini app as displayed to users.
* Used in titles, headers, and app store listings.
*/
export const APP_NAME = 'Starter Kit';
export const APP_NAME: string = 'Starter Kit';
/**
* A brief description of the mini app's functionality.
* Used in app store listings and metadata.
*/
export const APP_DESCRIPTION = 'A demo of the Neynar Starter Kit';
export const APP_DESCRIPTION: string = 'A demo of the Neynar Starter Kit';
/**
* The primary category for the mini app.
* Used for app store categorization and discovery.
*/
export const APP_PRIMARY_CATEGORY = 'developer-tools';
export const APP_PRIMARY_CATEGORY: string = 'developer-tools';
/**
* Tags associated with the mini app.
* Used for search and discovery in app stores.
*/
export const APP_TAGS = ['neynar', 'starter-kit', 'demo'];
export const APP_TAGS: string[] = ['neynar', 'starter-kit', 'demo'];
// --- Asset URLs ---
/**
* URL for the app's icon image.
* Used in app store listings and UI elements.
*/
export const APP_ICON_URL = `${APP_URL}/icon.png`;
export const APP_ICON_URL: string = `${APP_URL}/icon.png`;
/**
* URL for the app's Open Graph image.
* Used for social media sharing and previews.
*/
export const APP_OG_IMAGE_URL = `${APP_URL}/api/opengraph-image`;
export const APP_OG_IMAGE_URL: string = `${APP_URL}/api/opengraph-image`;
/**
* URL for the app's splash screen image.
* Displayed during app loading.
*/
export const APP_SPLASH_URL = `${APP_URL}/splash.png`;
export const APP_SPLASH_URL: string = `${APP_URL}/splash.png`;
/**
* Background color for the splash screen.
* Used as fallback when splash image is loading.
*/
export const APP_SPLASH_BACKGROUND_COLOR = "#f7f7f7";
export const APP_SPLASH_BACKGROUND_COLOR: string = "#f7f7f7";
/**
* Account association for the mini app.
* Used to associate the mini app with a Farcaster account.
* If not provided, the mini app will be unsigned and have limited capabilities.
*/
export const APP_ACCOUNT_ASSOCIATION: AccountAssociation | undefined = undefined;
// --- UI Configuration ---
/**
* Text displayed on the main action button.
* Used for the primary call-to-action in the mini app.
*/
export const APP_BUTTON_TEXT = 'Launch NSK';
export const APP_BUTTON_TEXT: string = 'Launch NSK';
// --- Integration Configuration ---
/**
@@ -80,7 +89,7 @@ export const APP_BUTTON_TEXT = 'Launch NSK';
* Neynar webhook endpoint. Otherwise, falls back to a local webhook
* endpoint for development and testing.
*/
export const APP_WEBHOOK_URL = process.env.NEYNAR_API_KEY && process.env.NEYNAR_CLIENT_ID
export const APP_WEBHOOK_URL: string = process.env.NEYNAR_API_KEY && process.env.NEYNAR_CLIENT_ID
? `https://api.neynar.com/f/app/${process.env.NEYNAR_CLIENT_ID}/event`
: `${APP_URL}/api/webhook`;
@@ -91,7 +100,7 @@ export const APP_WEBHOOK_URL = process.env.NEYNAR_API_KEY && process.env.NEYNAR_
* When false, wallet functionality is completely hidden from the UI.
* Useful for mini apps that don't require wallet integration.
*/
export const USE_WALLET = true;
export const USE_WALLET: boolean = true;
/**
* Flag to enable/disable analytics tracking.
@@ -100,4 +109,4 @@ export const USE_WALLET = true;
* When false, analytics collection is disabled.
* Useful for privacy-conscious users or development environments.
*/
export const ANALYTICS_ENABLED = true;
export const ANALYTICS_ENABLED: boolean = true;

View File

@@ -1,32 +1,19 @@
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { mnemonicToAccount } from 'viem/accounts';
import { APP_BUTTON_TEXT, APP_DESCRIPTION, APP_ICON_URL, APP_NAME, APP_OG_IMAGE_URL, APP_PRIMARY_CATEGORY, APP_SPLASH_BACKGROUND_COLOR, APP_TAGS, APP_URL, APP_WEBHOOK_URL } from './constants';
import { APP_SPLASH_URL } from './constants';
interface MiniAppMetadata {
version: string;
name: string;
iconUrl: string;
homeUrl: string;
imageUrl?: string;
buttonTitle?: string;
splashImageUrl?: string;
splashBackgroundColor?: string;
webhookUrl?: string;
description?: string;
primaryCategory?: string;
tags?: string[];
};
interface MiniAppManifest {
accountAssociation?: {
header: string;
payload: string;
signature: string;
};
frame: MiniAppMetadata;
}
import { type Manifest } from '@farcaster/miniapp-node';
import {
APP_BUTTON_TEXT,
APP_DESCRIPTION,
APP_ICON_URL,
APP_NAME,
APP_OG_IMAGE_URL,
APP_PRIMARY_CATEGORY,
APP_SPLASH_BACKGROUND_COLOR,
APP_SPLASH_URL,
APP_TAGS, APP_URL,
APP_WEBHOOK_URL,
APP_ACCOUNT_ASSOCIATION,
} from './constants';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
@@ -64,64 +51,10 @@ export function getMiniAppEmbedMetadata(ogImageUrl?: string) {
};
}
export async function getFarcasterMetadata(): Promise<MiniAppManifest> {
// First check for MINI_APP_METADATA in .env and use that if it exists
if (process.env.MINI_APP_METADATA) {
try {
const metadata = JSON.parse(process.env.MINI_APP_METADATA);
console.log('Using pre-signed mini app metadata from environment');
return metadata;
} catch (error) {
console.warn('Failed to parse MINI_APP_METADATA from environment:', error);
}
}
if (!APP_URL) {
throw new Error('NEXT_PUBLIC_URL not configured');
}
// Get the domain from the URL (without https:// prefix)
const domain = new URL(APP_URL).hostname;
console.log('Using domain for manifest:', domain);
const secretEnvVars = getSecretEnvVars();
if (!secretEnvVars) {
console.warn('No seed phrase or FID found in environment variables -- generating unsigned metadata');
}
let accountAssociation;
if (secretEnvVars) {
// Generate account from seed phrase
const account = mnemonicToAccount(secretEnvVars.seedPhrase);
const custodyAddress = account.address;
const header = {
fid: parseInt(secretEnvVars.fid),
type: 'custody',
key: custodyAddress,
};
const encodedHeader = Buffer.from(JSON.stringify(header), 'utf-8').toString('base64');
const payload = {
domain
};
const encodedPayload = Buffer.from(JSON.stringify(payload), 'utf-8').toString('base64url');
const signature = await account.signMessage({
message: `${encodedHeader}.${encodedPayload}`
});
const encodedSignature = Buffer.from(signature, 'utf-8').toString('base64url');
accountAssociation = {
header: encodedHeader,
payload: encodedPayload,
signature: encodedSignature
};
}
export async function getFarcasterDomainManifest(): Promise<Manifest> {
return {
accountAssociation,
frame: {
accountAssociation: APP_ACCOUNT_ASSOCIATION,
miniapp: {
version: "1",
name: APP_NAME ?? "Neynar Starter Kit",
iconUrl: APP_ICON_URL,