@farm.js/create-app 0.1.40 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +22 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/templates/_renderers/preact/package.json +3 -3
- package/templates/_renderers/solid/package.json +3 -3
- package/templates/_renderers/svelte/package.json +3 -3
- package/templates/_renderers/vue/package.json +3 -3
- package/templates/auth/.env.example +2 -1
- package/templates/auth/package.json +4 -4
- package/templates/basic/package.json +3 -3
- package/templates/better-auth/.env.example +2 -1
- package/templates/better-auth/package.json +4 -4
- package/templates/react-compiler/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1777,6 +1777,7 @@ const PROVIDERS = [
|
|
|
1777
1777
|
notes: [
|
|
1778
1778
|
"Use @ai-sdk/react useChat with api: \"/api/chat\" on the client.",
|
|
1779
1779
|
"Replace model with any AI SDK provider model or Vercel AI Gateway model id.",
|
|
1780
|
+
"The chat route answers only in development until authorize checks your session: every request spends your AI credits.",
|
|
1780
1781
|
"No farm.config integration wiring is required for this route."
|
|
1781
1782
|
],
|
|
1782
1783
|
ui: aiChatUIFeature(),
|
|
@@ -1785,6 +1786,10 @@ const PROVIDERS = [
|
|
|
1785
1786
|
export const POST = aiChatRoute({
|
|
1786
1787
|
model: "openai/gpt-4o-mini",
|
|
1787
1788
|
system: "You are a helpful assistant.",
|
|
1789
|
+
// Every request spends your AI credits. TODO: check the signed-in user, for
|
|
1790
|
+
// example authorize: async ({ request }) => Boolean(await getSession(request)).
|
|
1791
|
+
// Until then the route answers in development and refuses in production.
|
|
1792
|
+
authorize: () => process.env.NODE_ENV === "development",
|
|
1788
1793
|
});
|
|
1789
1794
|
`
|
|
1790
1795
|
},
|
|
@@ -2162,7 +2167,8 @@ await migrations.runMigrations();
|
|
|
2162
2167
|
{
|
|
2163
2168
|
path: ".env.example",
|
|
2164
2169
|
merge: "lines",
|
|
2165
|
-
source: () =>
|
|
2170
|
+
source: () => `# Generate with: openssl rand -base64 32
|
|
2171
|
+
BETTER_AUTH_SECRET=
|
|
2166
2172
|
BETTER_AUTH_URL=http://localhost:3000
|
|
2167
2173
|
BETTER_AUTH_DATABASE_PATH=better-auth.sqlite
|
|
2168
2174
|
`
|
|
@@ -3338,7 +3344,7 @@ async function createApp(projectName, options = {}) {
|
|
|
3338
3344
|
if (integrationResult) {
|
|
3339
3345
|
const details = templateDetails[template].integration;
|
|
3340
3346
|
logger.info(`Open ${details.route} for the ${details.label} starter.`);
|
|
3341
|
-
if (integrationResult.env.length) logger.info("Copy .env.example to .env.local
|
|
3347
|
+
if (integrationResult.env.length) logger.info("Copy .env.example to .env.local, add your provider credentials, and generate any empty secret with openssl rand -base64 32.");
|
|
3342
3348
|
for (const note of integrationResult.notes) logger.info(note);
|
|
3343
3349
|
}
|
|
3344
3350
|
trackFarmProjectCreated({
|
|
@@ -3469,14 +3475,20 @@ async function writeEnvironmentExample(projectPath, keys) {
|
|
|
3469
3475
|
current = await fs.readFile(envPath, "utf8");
|
|
3470
3476
|
} catch {}
|
|
3471
3477
|
const existingKeys = new Set(current.split(/\r?\n/).map((line) => line.match(/^([A-Z][A-Z0-9_]*)=/)?.[1]).filter((key) => Boolean(key)));
|
|
3472
|
-
const additions = keys.filter((key) => !existingKeys.has(key)).
|
|
3478
|
+
const additions = keys.filter((key) => !existingKeys.has(key)).flatMap((key) => environmentExampleLines(key));
|
|
3473
3479
|
if (additions.length > 0) await fs.writeFile(envPath, `${current.trimEnd()}${current.trim() ? "\n" : ""}${additions.join("\n")}\n`, "utf8");
|
|
3474
3480
|
}
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3481
|
+
const GENERATED_SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
3482
|
+
"AUTH_SECRET",
|
|
3483
|
+
"AUTH0_SECRET",
|
|
3484
|
+
"BETTER_AUTH_SECRET",
|
|
3485
|
+
"WORKOS_COOKIE_PASSWORD"
|
|
3486
|
+
]);
|
|
3487
|
+
function environmentExampleLines(key) {
|
|
3488
|
+
if (GENERATED_SECRET_KEYS.has(key)) return ["# Generate with: openssl rand -base64 32", `${key}=`];
|
|
3489
|
+
if (key === "APP_BASE_URL") return [`${key}=http://localhost:3000`];
|
|
3490
|
+
if (key === "UNKEY_BASE_URL") return [`${key}=https://api.unkey.com`];
|
|
3491
|
+
return [`${key}=`];
|
|
3480
3492
|
}
|
|
3481
3493
|
async function writeIntegrationHomePage(projectPath, integration, hasEnvironment) {
|
|
3482
3494
|
const commandRows = [...hasEnvironment ? ["cp .env.example .env.local"] : [], "pnpm dev"].map((command, index) => ` <div className="command-row">
|
|
@@ -3516,8 +3528,8 @@ ${commandRows}
|
|
|
3516
3528
|
await fs.writeFile(path.join(projectPath, "src", "app", "page.tsx"), source, "utf8");
|
|
3517
3529
|
}
|
|
3518
3530
|
async function writeIntegrationReadme(projectPath, integration, env) {
|
|
3519
|
-
const environmentSetup = env.length ? `cp .env.example .env.local\n# Add values for: ${env.join(", ")}\n` : "";
|
|
3520
|
-
const wiring = integration.provider === "ai" ? "The AI route lives in `src/app/api/chat/route.ts` and its local UI lives under `src/components/farm`." : "The provider wiring lives in `src/lib/integrations` and is registered from `farm.config.ts`.";
|
|
3531
|
+
const environmentSetup = env.length ? `cp .env.example .env.local\n# Add values for: ${env.join(", ")}\n# Generate secrets with: openssl rand -base64 32\n` : "";
|
|
3532
|
+
const wiring = integration.provider === "ai" ? "The AI route lives in `src/app/api/chat/route.ts` and its local UI lives under `src/components/farm`. Every request spends your AI credits, so the route answers only in development until its `authorize` checks a signed-in user." : "The provider wiring lives in `src/lib/integrations` and is registered from `farm.config.ts`.";
|
|
3521
3533
|
const source = `# FARMJS ${integration.label} Starter
|
|
3522
3534
|
|
|
3523
3535
|
## Getting started
|