@farm.js/create-app 0.1.61 → 0.1.62

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.js");
2
+ const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.js");
3
3
  const require_utils = require("./utils.js");
4
4
  let prompts = require("prompts");
5
5
  prompts = require_rolldown_runtime.__toESM(prompts);
@@ -180,12 +180,10 @@ Label.displayName = "Label";
180
180
  `;
181
181
  }
182
182
  }
183
- //#endregion
184
- //#region ../farm-cli/src/ui-registry.ts
183
+ // ../farm-cli/src/ui-registry.ts
185
184
  /** Value written into a generated `components.json` as `registries.farm.url`. */
186
185
  const UI_REGISTRY_URL_TEMPLATE = "https://farmjs.dev/r/{name}.json";
187
- //#endregion
188
- //#region ../farm-cli/src/ui-feature-registry.ts
186
+ // ../farm-cli/src/ui-feature-registry.ts
189
187
  async function installUIFeature(input) {
190
188
  const feature = input.definition.ui;
191
189
  if (!feature) {
@@ -1767,8 +1765,7 @@ function readObject(value) {
1767
1765
  function pushResultPath(list, filePath) {
1768
1766
  if (!list.includes(filePath)) list.push(filePath);
1769
1767
  }
1770
- //#endregion
1771
- //#region ../farm-cli/src/add-integration.ts
1768
+ // ../farm-cli/src/add-integration.ts
1772
1769
  const PROVIDERS = [
1773
1770
  {
1774
1771
  provider: "ai",
@@ -1787,6 +1784,7 @@ const PROVIDERS = [
1787
1784
  notes: [
1788
1785
  "Use @ai-sdk/react useChat with api: \"/api/chat\" on the client.",
1789
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.",
1790
1788
  "No farm.config integration wiring is required for this route."
1791
1789
  ],
1792
1790
  ui: aiChatUIFeature(),
@@ -1795,6 +1793,10 @@ const PROVIDERS = [
1795
1793
  export const POST = aiChatRoute({
1796
1794
  model: "openai/gpt-4o-mini",
1797
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",
1798
1800
  });
1799
1801
  `
1800
1802
  },
@@ -2142,7 +2144,7 @@ export const autumnIntegration = autumn({
2142
2144
  "BETTER_AUTH_DATABASE_PATH"
2143
2145
  ],
2144
2146
  dependencies: {
2145
- "better-auth": "^1.5.5",
2147
+ "better-auth": "^1.6.22",
2146
2148
  "better-sqlite3": "^12.6.2"
2147
2149
  },
2148
2150
  devDependencies: { "@types/better-sqlite3": "^7.6.13" },
@@ -2172,7 +2174,8 @@ await migrations.runMigrations();
2172
2174
  {
2173
2175
  path: ".env.example",
2174
2176
  merge: "lines",
2175
- source: () => `BETTER_AUTH_SECRET=replace-with-at-least-32-random-characters
2177
+ source: () => `# Generate with: openssl rand -base64 32
2178
+ BETTER_AUTH_SECRET=
2176
2179
  BETTER_AUTH_URL=http://localhost:3000
2177
2180
  BETTER_AUTH_DATABASE_PATH=better-auth.sqlite
2178
2181
  `
@@ -2215,7 +2218,7 @@ export const betterAuthIntegration = betterAuth({
2215
2218
  "AUTH_GITHUB_ID",
2216
2219
  "AUTH_GITHUB_SECRET"
2217
2220
  ],
2218
- dependencies: { "@auth/core": "0.34.3" },
2221
+ dependencies: { "@auth/core": "^0.41.3" },
2219
2222
  setupFiles: [{
2220
2223
  path: "src/lib/auth.ts",
2221
2224
  source: () => `import { Auth } from "@auth/core";
@@ -2230,6 +2233,8 @@ const config = {
2230
2233
  ],
2231
2234
  secret: process.env.AUTH_SECRET,
2232
2235
  trustHost: true,
2236
+ // @farm.js/authjs serves Auth.js at /api/auth; Auth.js expects /auth otherwise.
2237
+ basePath: "/api/auth",
2233
2238
  };
2234
2239
 
2235
2240
  const handler = (request: Request) => Auth(request, config);
@@ -2698,8 +2703,7 @@ function toImportPath(relativePath) {
2698
2703
  function escapeRegExp(input) {
2699
2704
  return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2700
2705
  }
2701
- //#endregion
2702
- //#region ../farm-cli/src/telemetry-contract.ts
2706
+ // ../farm-cli/src/telemetry-contract.ts
2703
2707
  const FARM_CREATE_APP_TELEMETRY_COMMANDS = ["create", "list-templates"];
2704
2708
  const FARM_TELEMETRY_TEMPLATES = [
2705
2709
  "basic",
@@ -2735,8 +2739,7 @@ const FARM_TELEMETRY_PACKAGE_MANAGERS = [
2735
2739
  "yarn",
2736
2740
  "bun"
2737
2741
  ];
2738
- //#endregion
2739
- //#region ../farm-cli/src/telemetry.ts
2742
+ // ../farm-cli/src/telemetry.ts
2740
2743
  const TELEMETRY_SCHEMA_VERSION = 1;
2741
2744
  const DEFAULT_TELEMETRY_ENDPOINT = "https://farmjs.dev/api/telemetry/v1/events";
2742
2745
  const TELEMETRY_NOTICE_URL = "https://farmjs.dev/docs/telemetry";
@@ -3062,8 +3065,7 @@ function normalizePlatform(value) {
3062
3065
  function normalizeArchitecture(value) {
3063
3066
  return value === "arm64" || value === "x64" ? value : "other";
3064
3067
  }
3065
- //#endregion
3066
- //#region src/index.ts
3068
+ // src/index.ts
3067
3069
  const templateDetails = {
3068
3070
  basic: {
3069
3071
  title: "Basic starter",
@@ -3078,7 +3080,7 @@ const templateDetails = {
3078
3080
  auth: {
3079
3081
  title: "Auth starter",
3080
3082
  description: "Farm.js-native auth with local SQLite, secure sessions, and protected routes",
3081
- instructions: ["FARMJS Auth uses local SQLite automatically; no auth environment variables are needed locally.", "For production, set FARM_AUTH_URL, FARM_AUTH_SECRET, and DATABASE_URL, then run the auth:migrate script."]
3083
+ instructions: ["FARMJS Auth uses local SQLite automatically and generates a random .farm/auth-secret; no auth environment variables are needed locally.", "For production, set FARM_AUTH_URL, FARM_AUTH_SECRET, and DATABASE_URL, then run the auth:migrate script."]
3082
3084
  },
3083
3085
  "better-auth": {
3084
3086
  title: "Better Auth starter",
@@ -3351,7 +3353,7 @@ async function createApp(projectName, options = {}) {
3351
3353
  if (integrationResult) {
3352
3354
  const details = templateDetails[template].integration;
3353
3355
  require_utils.logger.info(`Open ${details.route} for the ${details.label} starter.`);
3354
- if (integrationResult.env.length) require_utils.logger.info("Copy .env.example to .env.local and add your provider credentials.");
3356
+ 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.");
3355
3357
  for (const note of integrationResult.notes) require_utils.logger.info(note);
3356
3358
  }
3357
3359
  trackFarmProjectCreated({
@@ -3482,14 +3484,20 @@ async function writeEnvironmentExample(projectPath, keys) {
3482
3484
  current = await fs_promises.default.readFile(envPath, "utf8");
3483
3485
  } catch {}
3484
3486
  const existingKeys = new Set(current.split(/\r?\n/).map((line) => line.match(/^([A-Z][A-Z0-9_]*)=/)?.[1]).filter((key) => Boolean(key)));
3485
- const additions = keys.filter((key) => !existingKeys.has(key)).map((key) => `${key}=${environmentExampleValue(key)}`);
3487
+ const additions = keys.filter((key) => !existingKeys.has(key)).flatMap((key) => environmentExampleLines(key));
3486
3488
  if (additions.length > 0) await fs_promises.default.writeFile(envPath, `${current.trimEnd()}${current.trim() ? "\n" : ""}${additions.join("\n")}\n`, "utf8");
3487
3489
  }
3488
- function environmentExampleValue(key) {
3489
- if (key === "APP_BASE_URL") return "http://localhost:3000";
3490
- if (key === "AUTH_SECRET") return "replace-with-at-least-32-random-characters";
3491
- if (key === "UNKEY_BASE_URL") return "https://api.unkey.com";
3492
- return "";
3490
+ const GENERATED_SECRET_KEYS = /* @__PURE__ */ new Set([
3491
+ "AUTH_SECRET",
3492
+ "AUTH0_SECRET",
3493
+ "BETTER_AUTH_SECRET",
3494
+ "WORKOS_COOKIE_PASSWORD"
3495
+ ]);
3496
+ function environmentExampleLines(key) {
3497
+ if (GENERATED_SECRET_KEYS.has(key)) return ["# Generate with: openssl rand -base64 32", `${key}=`];
3498
+ if (key === "APP_BASE_URL") return [`${key}=http://localhost:3000`];
3499
+ if (key === "UNKEY_BASE_URL") return [`${key}=https://api.unkey.com`];
3500
+ return [`${key}=`];
3493
3501
  }
3494
3502
  async function writeIntegrationHomePage(projectPath, integration, hasEnvironment) {
3495
3503
  const commandRows = [...hasEnvironment ? ["cp .env.example .env.local"] : [], "pnpm dev"].map((command, index) => ` <div className="command-row">
@@ -3529,8 +3537,8 @@ ${commandRows}
3529
3537
  await fs_promises.default.writeFile(path.default.join(projectPath, "src", "app", "page.tsx"), source, "utf8");
3530
3538
  }
3531
3539
  async function writeIntegrationReadme(projectPath, integration, env) {
3532
- const environmentSetup = env.length ? `cp .env.example .env.local\n# Add values for: ${env.join(", ")}\n` : "";
3533
- 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`.";
3540
+ const environmentSetup = env.length ? `cp .env.example .env.local\n# Add values for: ${env.join(", ")}\n# Generate secrets with: openssl rand -base64 32\n` : "";
3541
+ 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`.";
3534
3542
  const source = `# FARMJS ${integration.label} Starter
3535
3543
 
3536
3544
  ## Getting started
@@ -3623,8 +3631,7 @@ function detectPackageManager(userAgent = process.env.npm_config_user_agent) {
3623
3631
  function installDependencies(projectPath, packageManager) {
3624
3632
  return new Promise((resolve, reject) => {
3625
3633
  const isWindows = process.platform === "win32";
3626
- const command = isWindows ? `${packageManager.name}.cmd` : packageManager.name;
3627
- const child = (0, node_child_process.spawn)(command, ["install"], {
3634
+ const child = (0, node_child_process.spawn)(packageManager.name, ["install"], {
3628
3635
  cwd: projectPath,
3629
3636
  env: process.env,
3630
3637
  stdio: "inherit",
@@ -3674,7 +3681,6 @@ async function updatePackageManagerInstructions(projectPath, packageManager) {
3674
3681
  }
3675
3682
  }));
3676
3683
  }
3677
- //#endregion
3678
3684
  exports.createApp = createApp;
3679
3685
  exports.detectPackageManager = detectPackageManager;
3680
3686
  exports.installDependencies = installDependencies;