@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.js
CHANGED
|
@@ -1784,6 +1784,7 @@ const PROVIDERS = [
|
|
|
1784
1784
|
notes: [
|
|
1785
1785
|
"Use @ai-sdk/react useChat with api: \"/api/chat\" on the client.",
|
|
1786
1786
|
"Replace model with any AI SDK provider model or Vercel AI Gateway model id.",
|
|
1787
|
+
"The chat route answers only in development until authorize checks your session: every request spends your AI credits.",
|
|
1787
1788
|
"No farm.config integration wiring is required for this route."
|
|
1788
1789
|
],
|
|
1789
1790
|
ui: aiChatUIFeature(),
|
|
@@ -1792,6 +1793,10 @@ const PROVIDERS = [
|
|
|
1792
1793
|
export const POST = aiChatRoute({
|
|
1793
1794
|
model: "openai/gpt-4o-mini",
|
|
1794
1795
|
system: "You are a helpful assistant.",
|
|
1796
|
+
// Every request spends your AI credits. TODO: check the signed-in user, for
|
|
1797
|
+
// example authorize: async ({ request }) => Boolean(await getSession(request)).
|
|
1798
|
+
// Until then the route answers in development and refuses in production.
|
|
1799
|
+
authorize: () => process.env.NODE_ENV === "development",
|
|
1795
1800
|
});
|
|
1796
1801
|
`
|
|
1797
1802
|
},
|
|
@@ -2169,7 +2174,8 @@ await migrations.runMigrations();
|
|
|
2169
2174
|
{
|
|
2170
2175
|
path: ".env.example",
|
|
2171
2176
|
merge: "lines",
|
|
2172
|
-
source: () =>
|
|
2177
|
+
source: () => `# Generate with: openssl rand -base64 32
|
|
2178
|
+
BETTER_AUTH_SECRET=
|
|
2173
2179
|
BETTER_AUTH_URL=http://localhost:3000
|
|
2174
2180
|
BETTER_AUTH_DATABASE_PATH=better-auth.sqlite
|
|
2175
2181
|
`
|
|
@@ -3345,7 +3351,7 @@ async function createApp(projectName, options = {}) {
|
|
|
3345
3351
|
if (integrationResult) {
|
|
3346
3352
|
const details = templateDetails[template].integration;
|
|
3347
3353
|
require_utils.logger.info(`Open ${details.route} for the ${details.label} starter.`);
|
|
3348
|
-
if (integrationResult.env.length) require_utils.logger.info("Copy .env.example to .env.local
|
|
3354
|
+
if (integrationResult.env.length) require_utils.logger.info("Copy .env.example to .env.local, add your provider credentials, and generate any empty secret with openssl rand -base64 32.");
|
|
3349
3355
|
for (const note of integrationResult.notes) require_utils.logger.info(note);
|
|
3350
3356
|
}
|
|
3351
3357
|
trackFarmProjectCreated({
|
|
@@ -3476,14 +3482,20 @@ async function writeEnvironmentExample(projectPath, keys) {
|
|
|
3476
3482
|
current = await fs_promises.default.readFile(envPath, "utf8");
|
|
3477
3483
|
} catch {}
|
|
3478
3484
|
const existingKeys = new Set(current.split(/\r?\n/).map((line) => line.match(/^([A-Z][A-Z0-9_]*)=/)?.[1]).filter((key) => Boolean(key)));
|
|
3479
|
-
const additions = keys.filter((key) => !existingKeys.has(key)).
|
|
3485
|
+
const additions = keys.filter((key) => !existingKeys.has(key)).flatMap((key) => environmentExampleLines(key));
|
|
3480
3486
|
if (additions.length > 0) await fs_promises.default.writeFile(envPath, `${current.trimEnd()}${current.trim() ? "\n" : ""}${additions.join("\n")}\n`, "utf8");
|
|
3481
3487
|
}
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3488
|
+
const GENERATED_SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
3489
|
+
"AUTH_SECRET",
|
|
3490
|
+
"AUTH0_SECRET",
|
|
3491
|
+
"BETTER_AUTH_SECRET",
|
|
3492
|
+
"WORKOS_COOKIE_PASSWORD"
|
|
3493
|
+
]);
|
|
3494
|
+
function environmentExampleLines(key) {
|
|
3495
|
+
if (GENERATED_SECRET_KEYS.has(key)) return ["# Generate with: openssl rand -base64 32", `${key}=`];
|
|
3496
|
+
if (key === "APP_BASE_URL") return [`${key}=http://localhost:3000`];
|
|
3497
|
+
if (key === "UNKEY_BASE_URL") return [`${key}=https://api.unkey.com`];
|
|
3498
|
+
return [`${key}=`];
|
|
3487
3499
|
}
|
|
3488
3500
|
async function writeIntegrationHomePage(projectPath, integration, hasEnvironment) {
|
|
3489
3501
|
const commandRows = [...hasEnvironment ? ["cp .env.example .env.local"] : [], "pnpm dev"].map((command, index) => ` <div className="command-row">
|
|
@@ -3523,8 +3535,8 @@ ${commandRows}
|
|
|
3523
3535
|
await fs_promises.default.writeFile(path.default.join(projectPath, "src", "app", "page.tsx"), source, "utf8");
|
|
3524
3536
|
}
|
|
3525
3537
|
async function writeIntegrationReadme(projectPath, integration, env) {
|
|
3526
|
-
const environmentSetup = env.length ? `cp .env.example .env.local\n# Add values for: ${env.join(", ")}\n` : "";
|
|
3527
|
-
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`.";
|
|
3538
|
+
const environmentSetup = env.length ? `cp .env.example .env.local\n# Add values for: ${env.join(", ")}\n# Generate secrets with: openssl rand -base64 32\n` : "";
|
|
3539
|
+
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`.";
|
|
3528
3540
|
const source = `# FARMJS ${integration.label} Starter
|
|
3529
3541
|
|
|
3530
3542
|
## Getting started
|