Merge pull request #23 from neynarxyz/fix-deploy-and-manifest-issue

fix-deploy-and-dynamic-import-issue
This commit is contained in:
Shreyaschorge 2025-07-19 04:20:59 +05:30 committed by GitHub
commit 572ab9aa44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 173 additions and 101 deletions

View File

@ -1,3 +1,32 @@
{ {
"extends": ["next/core-web-vitals", "next/typescript"] "extends": ["next/core-web-vitals", "next/typescript"],
"rules": {
// Disable img warnings since you're using them intentionally in specific contexts
"@next/next/no-img-element": "off",
// Allow @ts-ignore comments (though @ts-expect-error is preferred)
"@typescript-eslint/ban-ts-comment": "off",
// Allow explicit any types (sometimes necessary for dynamic imports and APIs)
"@typescript-eslint/no-explicit-any": "off",
// Allow unused variables that start with underscore
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
],
// Make display name warnings instead of errors for dynamic components
"react/display-name": "warn",
// Allow module assignment for dynamic imports
"@next/next/no-assign-module-variable": "warn",
// Make exhaustive deps a warning instead of error for complex hooks
"react-hooks/exhaustive-deps": "warn"
}
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@neynar/create-farcaster-mini-app", "name": "@neynar/create-farcaster-mini-app",
"version": "1.7.10", "version": "1.7.11",
"type": "module", "type": "module",
"private": false, "private": false,
"access": "public", "access": "public",
@ -35,7 +35,7 @@
"build:raw": "next build", "build:raw": "next build",
"start": "next start", "start": "next start",
"lint": "next lint", "lint": "next lint",
"deploy:vercel": "ts-node scripts/deploy.ts", "deploy:vercel": "node --loader ts-node/esm scripts/deploy.ts",
"deploy:raw": "vercel --prod", "deploy:raw": "vercel --prod",
"cleanup": "node scripts/cleanup.js" "cleanup": "node scripts/cleanup.js"
}, },

View File

@ -7,7 +7,7 @@ import inquirer from 'inquirer';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import crypto from 'crypto'; import crypto from 'crypto';
import { Vercel } from '@vercel/sdk'; import { Vercel } from '@vercel/sdk';
import { APP_NAME, APP_BUTTON_TEXT } from '../src/lib/constants'; import { APP_NAME, APP_BUTTON_TEXT } from '../src/lib/constants.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url)); const __dirname = path.dirname(fileURLToPath(import.meta.url));
const projectRoot = path.join(__dirname, '..'); const projectRoot = path.join(__dirname, '..');

View File

@ -22,9 +22,8 @@ export default async function RootLayout({
let session = null; let session = null;
if (shouldUseSession) { if (shouldUseSession) {
try { try {
// @ts-ignore - auth module may not exist in all template variants const { getSession } = await import('~/auth');
const authModule = eval('require("~/auth")'); session = await getSession();
session = await authModule.getSession();
} catch (error) { } catch (error) {
console.warn('Failed to get session:', error); console.warn('Failed to get session:', error);
} }

View File

@ -4,6 +4,7 @@ import dynamic from 'next/dynamic';
import { MiniAppProvider } from '@neynar/react'; import { MiniAppProvider } from '@neynar/react';
import { SafeFarcasterSolanaProvider } from '~/components/providers/SafeFarcasterSolanaProvider'; import { SafeFarcasterSolanaProvider } from '~/components/providers/SafeFarcasterSolanaProvider';
import { ANALYTICS_ENABLED } from '~/lib/constants'; import { ANALYTICS_ENABLED } from '~/lib/constants';
import React, { useState, useEffect } from 'react';
const WagmiProvider = dynamic( const WagmiProvider = dynamic(
() => import('~/components/providers/WagmiProvider'), () => import('~/components/providers/WagmiProvider'),
@ -12,7 +13,94 @@ const WagmiProvider = dynamic(
} }
); );
// Helper component to conditionally render auth providers
function AuthProviders({
children,
session,
shouldUseSession,
}: {
children: React.ReactNode;
session: any;
shouldUseSession: boolean;
}) {
const [authComponents, setAuthComponents] = useState<{
SessionProvider: React.ComponentType<any> | null;
AuthKitProvider: React.ComponentType<any> | null;
loaded: boolean;
}>({
SessionProvider: null,
AuthKitProvider: null,
loaded: false,
});
useEffect(() => {
if (!shouldUseSession) {
setAuthComponents({
SessionProvider: null,
AuthKitProvider: null,
loaded: true,
});
return;
}
const loadAuthComponents = async () => {
try {
// Dynamic imports for auth modules
let SessionProvider = null;
let AuthKitProvider = null;
try {
const nextAuth = await import('next-auth/react');
SessionProvider = nextAuth.SessionProvider;
} catch (error) {
console.warn('NextAuth not available:', error);
}
try {
const authKit = await import('@farcaster/auth-kit');
AuthKitProvider = authKit.AuthKitProvider;
} catch (error) {
console.warn('Farcaster AuthKit not available:', error);
}
setAuthComponents({
SessionProvider,
AuthKitProvider,
loaded: true,
});
} catch (error) {
console.error('Error loading auth components:', error);
setAuthComponents({
SessionProvider: null,
AuthKitProvider: null,
loaded: true,
});
}
};
loadAuthComponents();
}, [shouldUseSession]);
if (!authComponents.loaded) {
return <></>;
}
if (!shouldUseSession || !authComponents.SessionProvider) {
return <>{children}</>;
}
const { SessionProvider, AuthKitProvider } = authComponents;
if (AuthKitProvider) {
return (
<SessionProvider session={session}>
<AuthKitProvider config={{}}>{children}</AuthKitProvider>
</SessionProvider>
);
}
return <SessionProvider session={session}>{children}</SessionProvider>;
}
export function Providers({ export function Providers({
session, session,
@ -26,47 +114,6 @@ export function Providers({
const solanaEndpoint = const solanaEndpoint =
process.env.SOLANA_RPC_ENDPOINT || 'https://solana-rpc.publicnode.com'; process.env.SOLANA_RPC_ENDPOINT || 'https://solana-rpc.publicnode.com';
// Only wrap with SessionProvider if next auth is used
if (shouldUseSession) {
// Dynamic import for auth components - will work if modules exist, fallback if not
const AuthWrapper = dynamic(
() => {
return Promise.resolve().then(() => {
// Use eval to avoid build-time module resolution
try {
// @ts-ignore - These modules may not exist in all template variants
const nextAuth = eval('require("next-auth/react")');
const authKit = eval('require("@farcaster/auth-kit")');
return ({ children }: { children: React.ReactNode }) => (
<nextAuth.SessionProvider session={session}>
<authKit.AuthKitProvider config={{}}>{children}</authKit.AuthKitProvider>
</nextAuth.SessionProvider>
);
} catch (error) {
// Fallback component when auth modules aren't available
return ({ children }: { children: React.ReactNode }) => <>{children}</>;
}
});
},
{ ssr: false }
);
return (
<WagmiProvider>
<MiniAppProvider
analyticsEnabled={ANALYTICS_ENABLED}
backButtonEnabled={true}
>
<SafeFarcasterSolanaProvider endpoint={solanaEndpoint}>
<AuthWrapper>{children}</AuthWrapper>
</SafeFarcasterSolanaProvider>
</MiniAppProvider>
</WagmiProvider>
);
}
// Return without SessionProvider if no session
return ( return (
<WagmiProvider> <WagmiProvider>
<MiniAppProvider <MiniAppProvider
@ -74,7 +121,9 @@ export function Providers({
backButtonEnabled={true} backButtonEnabled={true}
> >
<SafeFarcasterSolanaProvider endpoint={solanaEndpoint}> <SafeFarcasterSolanaProvider endpoint={solanaEndpoint}>
<AuthProviders session={session} shouldUseSession={shouldUseSession}>
{children} {children}
</AuthProviders>
</SafeFarcasterSolanaProvider> </SafeFarcasterSolanaProvider>
</MiniAppProvider> </MiniAppProvider>
</WagmiProvider> </WagmiProvider>

View File

@ -1,7 +1,7 @@
'use client'; 'use client';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { useCallback, useState, type ComponentType } from 'react'; import { useCallback, useState } from 'react';
import { useMiniApp } from '@neynar/react'; import { useMiniApp } from '@neynar/react';
import { ShareButton } from '../Share'; import { ShareButton } from '../Share';
import { Button } from '../Button'; import { Button } from '../Button';
@ -9,24 +9,15 @@ import { SignIn } from '../wallet/SignIn';
import { type Haptics } from '@farcaster/miniapp-sdk'; import { type Haptics } from '@farcaster/miniapp-sdk';
import { APP_URL } from '~/lib/constants'; import { APP_URL } from '~/lib/constants';
// Optional import for NeynarAuthButton - may not exist in all templates // Import NeynarAuthButton
const NeynarAuthButton = dynamic( const NeynarAuthButton = dynamic(
() => { () =>
return Promise.resolve().then(() => { import('../NeynarAuthButton').then((module) => ({
try { default: module.NeynarAuthButton,
// @ts-ignore - NeynarAuthButton may not exist in all template variants })),
const module = eval('require("../NeynarAuthButton/index")');
return module.default || module.NeynarAuthButton;
} catch (error) {
// Return null component when module doesn't exist
return () => null;
}
});
},
{ ssr: false } { ssr: false }
); );
/** /**
* ActionsTab component handles mini app actions like sharing, notifications, and haptic feedback. * ActionsTab component handles mini app actions like sharing, notifications, and haptic feedback.
* *

View File

@ -1,4 +1,4 @@
import { type AccountAssociation } from '@farcaster/miniapp-node'; import { type AccountAssociation } from '@farcaster/miniapp-core/src/manifest';
/** /**
* Application constants and configuration values. * Application constants and configuration values.
@ -65,21 +65,22 @@ export const APP_SPLASH_URL: string = `${APP_URL}/splash.png`;
* Background color for the splash screen. * Background color for the splash screen.
* Used as fallback when splash image is loading. * Used as fallback when splash image is loading.
*/ */
export const APP_SPLASH_BACKGROUND_COLOR: string = "#f7f7f7"; export const APP_SPLASH_BACKGROUND_COLOR: string = '#f7f7f7';
/** /**
* Account association for the mini app. * Account association for the mini app.
* Used to associate the mini app with a Farcaster account. * Used to associate the mini app with a Farcaster account.
* If not provided, the mini app will be unsigned and have limited capabilities. * If not provided, the mini app will be unsigned and have limited capabilities.
*/ */
export const APP_ACCOUNT_ASSOCIATION: AccountAssociation | undefined = undefined; export const APP_ACCOUNT_ASSOCIATION: AccountAssociation | undefined =
undefined;
// --- UI Configuration --- // --- UI Configuration ---
/** /**
* Text displayed on the main action button. * Text displayed on the main action button.
* Used for the primary call-to-action in the mini app. * Used for the primary call-to-action in the mini app.
*/ */
export const APP_BUTTON_TEXT: string = 'Launch NSK'; export const APP_BUTTON_TEXT = 'Launch Mini App';
// --- Integration Configuration --- // --- Integration Configuration ---
/** /**
@ -89,7 +90,8 @@ export const APP_BUTTON_TEXT: string = 'Launch NSK';
* Neynar webhook endpoint. Otherwise, falls back to a local webhook * Neynar webhook endpoint. Otherwise, falls back to a local webhook
* endpoint for development and testing. * endpoint for development and testing.
*/ */
export const APP_WEBHOOK_URL: string = 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` ? `https://api.neynar.com/f/app/${process.env.NEYNAR_CLIENT_ID}/event`
: `${APP_URL}/api/webhook`; : `${APP_URL}/api/webhook`;
@ -100,7 +102,7 @@ export const APP_WEBHOOK_URL: string = process.env.NEYNAR_API_KEY && process.env
* When false, wallet functionality is completely hidden from the UI. * When false, wallet functionality is completely hidden from the UI.
* Useful for mini apps that don't require wallet integration. * Useful for mini apps that don't require wallet integration.
*/ */
export const USE_WALLET: boolean = true; export const USE_WALLET = false;
/** /**
* Flag to enable/disable analytics tracking. * Flag to enable/disable analytics tracking.
@ -109,7 +111,7 @@ export const USE_WALLET: boolean = true;
* When false, analytics collection is disabled. * When false, analytics collection is disabled.
* Useful for privacy-conscious users or development environments. * Useful for privacy-conscious users or development environments.
*/ */
export const ANALYTICS_ENABLED: boolean = true; export const ANALYTICS_ENABLED = true;
/** /**
* Required chains for the mini app. * Required chains for the mini app.

View File

@ -1,16 +1,18 @@
import { FrameNotificationDetails } from "@farcaster/miniapp-sdk"; import { MiniAppNotificationDetails } from '@farcaster/miniapp-sdk';
import { Redis } from "@upstash/redis"; import { Redis } from '@upstash/redis';
import { APP_NAME } from "./constants"; import { APP_NAME } from './constants';
// In-memory fallback storage // In-memory fallback storage
const localStore = new Map<string, FrameNotificationDetails>(); const localStore = new Map<string, MiniAppNotificationDetails>();
// Use Redis if KV env vars are present, otherwise use in-memory // Use Redis if KV env vars are present, otherwise use in-memory
const useRedis = process.env.KV_REST_API_URL && process.env.KV_REST_API_TOKEN; const useRedis = process.env.KV_REST_API_URL && process.env.KV_REST_API_TOKEN;
const redis = useRedis ? new Redis({ const redis = useRedis
? new Redis({
url: process.env.KV_REST_API_URL!, url: process.env.KV_REST_API_URL!,
token: process.env.KV_REST_API_TOKEN!, token: process.env.KV_REST_API_TOKEN!,
}) : null; })
: null;
function getUserNotificationDetailsKey(fid: number): string { function getUserNotificationDetailsKey(fid: number): string {
return `${APP_NAME}:user:${fid}`; return `${APP_NAME}:user:${fid}`;
@ -18,17 +20,17 @@ function getUserNotificationDetailsKey(fid: number): string {
export async function getUserNotificationDetails( export async function getUserNotificationDetails(
fid: number fid: number
): Promise<FrameNotificationDetails | null> { ): Promise<MiniAppNotificationDetails | null> {
const key = getUserNotificationDetailsKey(fid); const key = getUserNotificationDetailsKey(fid);
if (redis) { if (redis) {
return await redis.get<FrameNotificationDetails>(key); return await redis.get<MiniAppNotificationDetails>(key);
} }
return localStore.get(key) || null; return localStore.get(key) || null;
} }
export async function setUserNotificationDetails( export async function setUserNotificationDetails(
fid: number, fid: number,
notificationDetails: FrameNotificationDetails notificationDetails: MiniAppNotificationDetails
): Promise<void> { ): Promise<void> {
const key = getUserNotificationDetailsKey(fid); const key = getUserNotificationDetailsKey(fid);
if (redis) { if (redis) {

View File

@ -1,6 +1,6 @@
import { type ClassValue, clsx } from 'clsx'; import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge'; import { twMerge } from 'tailwind-merge';
import { type Manifest } from '@farcaster/miniapp-node'; import { Manifest } from '@farcaster/miniapp-core/src/manifest';
import { import {
APP_BUTTON_TEXT, APP_BUTTON_TEXT,
APP_DESCRIPTION, APP_DESCRIPTION,
@ -10,10 +10,10 @@ import {
APP_PRIMARY_CATEGORY, APP_PRIMARY_CATEGORY,
APP_SPLASH_BACKGROUND_COLOR, APP_SPLASH_BACKGROUND_COLOR,
APP_SPLASH_URL, APP_SPLASH_URL,
APP_TAGS, APP_URL, APP_TAGS,
APP_URL,
APP_WEBHOOK_URL, APP_WEBHOOK_URL,
APP_ACCOUNT_ASSOCIATION, APP_ACCOUNT_ASSOCIATION,
APP_REQUIRED_CHAINS,
} from './constants'; } from './constants';
export function cn(...inputs: ClassValue[]) { export function cn(...inputs: ClassValue[]) {
@ -22,7 +22,7 @@ export function cn(...inputs: ClassValue[]) {
export function getMiniAppEmbedMetadata(ogImageUrl?: string) { export function getMiniAppEmbedMetadata(ogImageUrl?: string) {
return { return {
version: "next", version: 'next',
imageUrl: ogImageUrl ?? APP_OG_IMAGE_URL, imageUrl: ogImageUrl ?? APP_OG_IMAGE_URL,
ogTitle: APP_NAME, ogTitle: APP_NAME,
ogDescription: APP_DESCRIPTION, ogDescription: APP_DESCRIPTION,
@ -30,7 +30,7 @@ export function getMiniAppEmbedMetadata(ogImageUrl?: string) {
button: { button: {
title: APP_BUTTON_TEXT, title: APP_BUTTON_TEXT,
action: { action: {
type: "launch_frame", type: 'launch_frame',
name: APP_NAME, name: APP_NAME,
url: APP_URL, url: APP_URL,
splashImageUrl: APP_SPLASH_URL, splashImageUrl: APP_SPLASH_URL,
@ -46,24 +46,17 @@ export function getMiniAppEmbedMetadata(ogImageUrl?: string) {
export async function getFarcasterDomainManifest(): Promise<Manifest> { export async function getFarcasterDomainManifest(): Promise<Manifest> {
return { return {
accountAssociation: APP_ACCOUNT_ASSOCIATION, accountAssociation: APP_ACCOUNT_ASSOCIATION!,
miniapp: { miniapp: {
version: "1", version: '1',
name: APP_NAME ?? "Neynar Starter Kit", name: APP_NAME ?? 'Neynar Starter Kit',
iconUrl: APP_ICON_URL,
homeUrl: APP_URL, homeUrl: APP_URL,
iconUrl: APP_ICON_URL,
imageUrl: APP_OG_IMAGE_URL, imageUrl: APP_OG_IMAGE_URL,
buttonTitle: APP_BUTTON_TEXT ?? "Launch Mini App", buttonTitle: APP_BUTTON_TEXT ?? 'Launch Mini App',
splashImageUrl: APP_SPLASH_URL, splashImageUrl: APP_SPLASH_URL,
splashBackgroundColor: APP_SPLASH_BACKGROUND_COLOR, splashBackgroundColor: APP_SPLASH_BACKGROUND_COLOR,
webhookUrl: APP_WEBHOOK_URL, webhookUrl: APP_WEBHOOK_URL,
description: APP_DESCRIPTION,
primaryCategory: APP_PRIMARY_CATEGORY,
tags: APP_TAGS,
requiredChains: APP_REQUIRED_CHAINS.length > 0 ? APP_REQUIRED_CHAINS : undefined,
ogTitle: APP_NAME,
ogDescription: APP_DESCRIPTION,
ogImageUrl: APP_OG_IMAGE_URL,
}, },
}; };
} }

View File

@ -22,6 +22,13 @@
"~/*": ["./src/*"] "~/*": ["./src/*"]
} }
}, },
"ts-node": {
"esm": true,
"compilerOptions": {
"module": "ES2020",
"moduleResolution": "node"
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }