neon 8.23.3 → 9.0.0

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.
Files changed (37) hide show
  1. package/README.md +9 -8
  2. package/dist/_chunks/{checkout-Bsfl-B0h.js → checkout-B_gbS0nD.js} +3 -3
  3. package/dist/_chunks/{claim-B3tMeMuo.js → claim-BVEwQ65H.js} +1 -1
  4. package/dist/_chunks/{config-DZ3cDaOS.js → config-BClSMzco.js} +1 -43
  5. package/dist/_chunks/{deploy-CF4PxuNX.js → deploy-CJ22hy3i.js} +1 -1
  6. package/dist/_chunks/{dev-BnHQENZM.js → dev-CSoQfCuS.js} +21 -22
  7. package/dist/_chunks/{env-CIFMBEon.js → env-CFBmcKyo.js} +18 -45
  8. package/dist/_chunks/{env-BOt9AZ1j.js → env-DxcO3oJk.js} +21 -24
  9. package/dist/_chunks/{env-JgoSsmyt.js → env-EJU-0InB.js} +49 -110
  10. package/dist/_chunks/{git-CRYW7ku0.js → git-C6XPViK5.js} +2 -2
  11. package/dist/_chunks/{link-VYCSKqU-.js → link-n40BxbmK.js} +2 -2
  12. package/dist/_chunks/{status-rt-0bUaQ.js → status-TDYLPWRO.js} +1 -1
  13. package/dist/commands/checkout.js +1 -1
  14. package/dist/commands/claim.js +1 -1
  15. package/dist/commands/config.js +1 -1
  16. package/dist/commands/deploy.js +1 -1
  17. package/dist/commands/dev.js +1 -1
  18. package/dist/commands/env.js +1 -1
  19. package/dist/commands/env_output.js +4 -4
  20. package/dist/commands/functions_new.js +1 -1
  21. package/dist/commands/git.js +1 -1
  22. package/dist/commands/index.js +9 -9
  23. package/dist/commands/link.js +1 -1
  24. package/dist/commands/status.js +1 -1
  25. package/dist/commands/subscribe.js +1 -1
  26. package/dist/dev/env.js +1 -1
  27. package/dist/env_services.js +30 -23
  28. package/dist/errors.js +2 -1
  29. package/dist/init/auth.js +1 -1
  30. package/dist/init/choices.js +8 -6
  31. package/dist/init/deploy.js +1 -1
  32. package/dist/init/link.js +1 -1
  33. package/dist/init/run.js +3 -3
  34. package/dist/utils/ai_gateway_notice.js +47 -114
  35. package/dist/utils/hooks.js +9 -4
  36. package/dist/utils/service_picker.js +1 -1
  37. package/package.json +8 -8
package/README.md CHANGED
@@ -601,9 +601,8 @@ neon env pull -e DATABASE_URL,NEON_AUTH_BASE_URL
601
601
  # The selectors compose as a union: all Auth vars plus DATABASE_URL
602
602
  neon env pull -s auth -e DATABASE_URL
603
603
 
604
- # Function invocation URLs
604
+ # The variables functionBaseUrl("<slug>") from @neon/env reads
605
605
  neon env pull -s functions
606
- neon env pull -e NEON_FUNCTION_HELLO_BASE_URL
607
606
  ```
608
607
 
609
608
  Every services flag in the CLI takes those three spellings, the same value syntax, and the same service names — see [`config init --services`](#getting-a-neonts-config-init).
@@ -613,15 +612,17 @@ Every services flag in the CLI takes those three spellings, the same value synta
613
612
  | `postgres` | `DATABASE_URL`, `DATABASE_URL_UNPOOLED` |
614
613
  | `auth` | `NEON_AUTH_BASE_URL`, `NEON_AUTH_JWKS_URL` |
615
614
  | `data-api` | `NEON_DATA_API_URL` |
616
- | `functions` | `NEON_FUNCTION_<SLUG>_BASE_URL` for each deployed function |
615
+ | `functions` | `NEON_FUNCTION_HOST_SUFFIX` |
617
616
  | `object-storage` | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_ENDPOINT_URL_S3`, `AWS_REGION` |
618
617
  | `ai-gateway` | `NEON_AI_GATEWAY_TOKEN`, `NEON_AI_GATEWAY_BASE_URL` |
619
618
 
620
- `-e, --env` accepts any variable in the table plus `NEON_BRANCH`, or `NEON_FUNCTION_<SLUG>_BASE_URL` where `<SLUG>` is the function slug uppercased. It is case-sensitive and rejects unknown names rather than silently widening the pull. `NEON_BRANCH` is written by unscoped and service-scoped pulls because it is branch identity, not a service; an env-only pull writes it only when you select it.
619
+ `-e, --env` accepts any variable in the table plus `NEON_BRANCH` and `NEON_BRANCH_ID`. It is case-sensitive and rejects unknown names rather than silently widening the pull. `NEON_BRANCH` and `NEON_BRANCH_ID` are written by unscoped and service-scoped pulls because they are branch identity, not a service; an env-only pull writes them only when you select them.
621
620
 
622
- `--env` never narrows `--service`: `neon env pull -s postgres -e DATABASE_URL` still pulls the complete Postgres bundle (`DATABASE_URL`, `DATABASE_URL_UNPOOLED`, and `NEON_BRANCH`). The two selectors always form a union.
621
+ `NEON_BRANCH_ID` and `NEON_FUNCTION_HOST_SUFFIX` are what `functionBaseUrl("<slug>")` from `@neon/env` builds a function's URL from, and what the Functions runtime injects into every deployed function. An unscoped pull writes both whether or not `neon.ts` declares functions. Earlier releases wrote one `NEON_FUNCTION_<SLUG>_BASE_URL` per function instead; an unscoped or `-s functions` pull removes those lines, and `-e NEON_FUNCTION_<SLUG>_BASE_URL` fails with a pointer to `functionBaseUrl`.
623
622
 
624
- **A scoped pull is scoped in both directions.** An unscoped `env pull` owns the Neon-named variables: pointing a directory at a branch without Neon Auth prunes the stale `NEON_AUTH_*` lines, and a branch without those functions prunes stale `NEON_FUNCTION_*_BASE_URL` lines. `--service` narrows that to the services you named, while `--env` narrows it to the exact keys you named, so `env pull -e DATABASE_URL` never touches `DATABASE_URL_UNPOOLED`. (`AWS_*` is never pruned by any pull: those names collide with credentials you may set yourself, so `env pull` only ever writes them.)
623
+ `--env` never narrows `--service`: `neon env pull -s postgres -e DATABASE_URL` still pulls the complete Postgres bundle (`DATABASE_URL`, `DATABASE_URL_UNPOOLED`, `NEON_BRANCH`, and `NEON_BRANCH_ID`). The two selectors always form a union.
624
+
625
+ **A scoped pull is scoped in both directions.** An unscoped `env pull` owns the Neon-named variables: pointing a directory at a branch without Neon Auth prunes the stale `NEON_AUTH_*` lines. `--service` narrows that to the services you named, while `--env` narrows it to the exact keys you named, so `env pull -e DATABASE_URL` never touches `DATABASE_URL_UNPOOLED`. (`AWS_*` is never pruned by any pull: those names collide with credentials you may set yourself, so `env pull` only ever writes them.)
625
626
 
626
627
  **A scoped pull also never revokes a credential.** Where an unscoped pull revokes the credential it replaces, a scoped one leaves the old one live — it can't tell which other variables still use it. It says so when it happens; revoke it in the Neon Console if nothing does.
627
628
 
@@ -639,7 +640,7 @@ Console), or drop auth from --service.
639
640
 
640
641
  If you'd rather not keep env vars on disk, inject them at runtime instead with `neon-env run -- <your dev command>` (from `@neon/env`) or `neon dev`, and pass `--no-env-pull` to `link` / `checkout`.
641
642
 
642
- **`neon dev` resolves the same set, by the same rules** — including the AI Gateway on a branch with no `neon.ts`. A function running locally gets the same Postgres / Auth / Data API / storage / AI Gateway vars a deploy would inject. Each `NEON_FUNCTION_<SLUG>_BASE_URL` this process is serving is rewritten to `http://localhost:<port>`: every neon.ts function, or the matching slug when `--source` names one. `neon env pull` and `neon-env run` write the production URL (`https://<branchId>-<slug>.compute.…`).
643
+ **`neon dev` resolves the same set, by the same rules** — including the AI Gateway on a branch with no `neon.ts`. A function running locally gets the same Postgres / Auth / Data API / storage / AI Gateway vars a deploy would inject. `dev` also sets `NEON_DEV_FUNCTION_PORTS`, a JSON map of the slugs this process is serving to their ports (every neon.ts function, or the matching slug when `--source` names one), so `functionBaseUrl("<slug>")` returns `http://localhost:<port>` for those and the deployed URL on the linked branch for any other slug.
643
644
 
644
645
  Before `neon.ts` is evaluated, `dev` loads the project directory's `.env`, then `.env.local`, which overrides it, into the environment, so Function env values written as `process.env.X!` resolve the same way they do for `neon deploy --env`. A variable already set in the shell wins over both. Local Functions inherit every loaded variable, including keys `neon.ts` doesn't declare; the deployed runtime gets only declared and Neon-injected env. `--env <file>` loads only that file, resolved from the current directory, matching `neon deploy --env`:
645
646
 
@@ -694,7 +695,7 @@ export default defineConfig({
694
695
  ◯ Object Storage
695
696
  S3-compatible blob storage that branches with your projects.
696
697
  ◯ AI Gateway
697
- All models, one API, one bill. Powered by Databricks. Not available on the Neon free plan.
698
+ All models, one API, one bill. Powered by Databricks.
698
699
  ```
699
700
 
700
701
  Postgres cannot be unselected. Selecting nothing else is a valid answer: you get the starter policy, which is also what a non-interactive run (CI, no TTY) writes. Pass `--services` to skip the prompt anywhere:
@@ -11,9 +11,9 @@ import { looksLikeBranchId } from "../utils/formats.js";
11
11
  import { fillSingleProject, listAllProjectBranches } from "../utils/enrichers.js";
12
12
  import { buildCheckoutEvent, readGitContext } from "../utils/git.js";
13
13
  import { buildHookBranch, loadHookConfig, resolveHookEnv, runCheckoutAfterHook, runCheckoutBeforeHook, runCreateAfterHook, runCreateBeforeHook } from "../utils/hooks.js";
14
- import { n as autoPullEnvAfterPin } from "./env-BOt9AZ1j.js";
15
- import { a as applyPolicyOnCreate, f as envFlag, l as createBranchFromPolicyOnCheckout } from "./config-DZ3cDaOS.js";
16
- import { i as handler$1 } from "./link-VYCSKqU-.js";
14
+ import { n as autoPullEnvAfterPin } from "./env-DxcO3oJk.js";
15
+ import { a as applyPolicyOnCreate, f as envFlag, l as createBranchFromPolicyOnCheckout } from "./config-BClSMzco.js";
16
+ import { i as handler$1 } from "./link-n40BxbmK.js";
17
17
  import chalk from "chalk";
18
18
  import prompts from "prompts";
19
19
  // src/commands/checkout.ts
@@ -12,7 +12,7 @@ import { projectConfigPath } from "../project.js";
12
12
  import { resolveEnvFilePath } from "../env_file.js";
13
13
  import { writer } from "../writer.js";
14
14
  import { noPassthrough } from "../utils/flags.js";
15
- import { c as pull } from "./env-BOt9AZ1j.js";
15
+ import { c as pull } from "./env-DxcO3oJk.js";
16
16
  import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
17
17
  import open from "open";
18
18
  import prompts from "prompts";
@@ -18,7 +18,6 @@ import { loadEnvFileIntoProcess } from "../env_file.js";
18
18
  import { formatInstallCommand, installArgs, resolvePackageManager, runCommandWithDetail } from "../utils/package_manager.js";
19
19
  import { writer } from "../writer.js";
20
20
  import { fillSingleProject, resolveBranchRef } from "../utils/enrichers.js";
21
- import { assertAiGatewayProvisionable, warnAiGateway } from "../utils/ai_gateway_notice.js";
22
21
  import { announceTargetBranch } from "../utils/branch_notice.js";
23
22
  import { renderAppliedChanges, renderBranchSettingConflicts, renderCustomDomainFollowup } from "../utils/config_diff.js";
24
23
  import { bundleEntry } from "../utils/esbuild.js";
@@ -27,7 +26,7 @@ import { readGitContext } from "../utils/git.js";
27
26
  import { resolveHookEnv, runDeployAfterHook, runDeployBeforeHook } from "../utils/hooks.js";
28
27
  import { pickServicesInteractively } from "../utils/service_picker.js";
29
28
  import { zipBundle } from "../utils/zip.js";
30
- import { n as autoPullEnvAfterPin } from "./env-BOt9AZ1j.js";
29
+ import { n as autoPullEnvAfterPin } from "./env-DxcO3oJk.js";
31
30
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
32
31
  import { dirname, join, relative, resolve } from "node:path";
33
32
  import chalk from "chalk";
@@ -740,11 +739,6 @@ const planCmd = async (props) => {
740
739
  const services = utilizedServices(config);
741
740
  reportPushResult(props, result, "plan", services);
742
741
  if (result.conflicts.some((conflict) => conflict.field === "customDomain" && !reasonAllowsUpdateExisting(conflict.reason))) process.exitCode = 1;
743
- if (services.includes("AI Gateway")) await warnAiGateway({
744
- apiClient: props.apiClient,
745
- projectId: props.projectId,
746
- branchId
747
- });
748
742
  };
749
743
  const warnDeprecatedPreview = (config, target) => {
750
744
  const message = previewGaWarningForConfig(config, target);
@@ -817,10 +811,6 @@ const applyCmd = async (props) => {
817
811
  announceTargetBranch(props, branch, "Applying to branch");
818
812
  warnDeprecatedPreview(config, warningTargetFromResolved(branch));
819
813
  const branchId = branch.branchId;
820
- if (utilizedServices(config).includes("AI Gateway")) await assertAiGatewayProvisionable({
821
- apiClient: props.apiClient,
822
- projectId: props.projectId
823
- });
824
814
  const cwd = process.cwd();
825
815
  const git = readGitContext(cwd);
826
816
  const event = { type: "neon-deploy" };
@@ -994,24 +984,6 @@ const reportConflicts = (props, conflicts) => {
994
984
  for (const conflict of conflicts) if (!reasonAllowsUpdateExisting(conflict.reason)) out.text(` ! ${conflict.field}: ${conflict.reason}\n`);
995
985
  };
996
986
  /**
997
- * Block provisioning the AI Gateway on a Free plan from the `checkout` policy paths, which
998
- * carry raw credentials (`apiKey`/`apiHost`) rather than the CLI's api client. Builds a client
999
- * from them and defers to {@link assertAiGatewayProvisionable}. Skipped when a `runtimeApi` is
1000
- * injected (tests) or no `apiKey` is available; the interactive commands always have a key.
1001
- */
1002
- const assertAiGatewayProvisionableFromCreds = async (props) => {
1003
- if (props.runtimeApi || !props.apiKey) return;
1004
- if (!utilizedServices(props.config).includes("AI Gateway")) return;
1005
- const apiClient = getApiClient({
1006
- apiKey: props.apiKey,
1007
- ...props.apiHost ? { apiHost: props.apiHost } : {}
1008
- });
1009
- await assertAiGatewayProvisionable({
1010
- apiClient,
1011
- projectId: props.projectId
1012
- });
1013
- };
1014
- /**
1015
987
  * Apply a `neon.ts` policy to a **freshly created** branch (used by `neonctl checkout`
1016
988
  * when it creates a branch). No-op when there is no `neon.ts` on the path from cwd up to
1017
989
  * the repo root — checkout still succeeds, it just has no policy to apply.
@@ -1045,13 +1017,6 @@ const applyPolicyOnCreate = async (props) => {
1045
1017
  } catch {
1046
1018
  warnDeprecatedPreview(config);
1047
1019
  }
1048
- await assertAiGatewayProvisionableFromCreds({
1049
- projectId: props.projectId,
1050
- ...props.apiKey ? { apiKey: props.apiKey } : {},
1051
- ...props.apiHost ? { apiHost: props.apiHost } : {},
1052
- ...props.runtimeApi ? { runtimeApi: props.runtimeApi } : {},
1053
- config
1054
- });
1055
1020
  log.info("Applying neon.ts policy to the new branch…");
1056
1021
  const result = await apply(config, {
1057
1022
  projectId: props.projectId,
@@ -1117,13 +1082,6 @@ const createBranchFromPolicyOnCheckout = async (props) => {
1117
1082
  if (/Could not find a Neon config file/i.test(message)) return null;
1118
1083
  throw err;
1119
1084
  }
1120
- await assertAiGatewayProvisionableFromCreds({
1121
- projectId: props.projectId,
1122
- ...props.apiKey ? { apiKey: props.apiKey } : {},
1123
- ...props.apiHost ? { apiHost: props.apiHost } : {},
1124
- ...props.runtimeApi ? { runtimeApi: props.runtimeApi } : {},
1125
- config
1126
- });
1127
1085
  try {
1128
1086
  const { branchId, branchName, result } = await createBranch(config, {
1129
1087
  projectId: props.projectId,
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
2
  import { fillSingleProject } from "../utils/enrichers.js";
3
- import { f as envFlag, i as applyFlags, p as envPullFlag, r as applyCmd } from "./config-DZ3cDaOS.js";
3
+ import { f as envFlag, i as applyFlags, p as envPullFlag, r as applyCmd } from "./config-BClSMzco.js";
4
4
  import { DEPLOY_COMMANDS_EPILOGUE } from "../commands/deploy_help.js";
5
5
  // src/commands/deploy.ts
6
6
  var deploy_exports = /* @__PURE__ */ __exportAll({
@@ -3,13 +3,13 @@ import { log } from "../log.js";
3
3
  import { isClaimableEnvTarget } from "../claimable/state.js";
4
4
  import { getCliName } from "../utils/cli_name.js";
5
5
  import { defaultDevEnvFiles, readEnvFile, resolveEnvFilePath } from "../env_file.js";
6
- import { l as functionBaseUrlKey } from "./env-JgoSsmyt.js";
7
- import { a as resolveDevEnv } from "./env-CIFMBEon.js";
8
- import { findConfigFunctionBySource, resolveFunctionsFromConfig } from "../dev/functions.js";
9
- import { resolveWatchInputs } from "../dev/inputs.js";
6
+ import { t as NEON_DEV_FUNCTION_PORTS } from "./env-EJU-0InB.js";
10
7
  import { branchIdResolve } from "../utils/enrichers.js";
11
8
  import { bundleEntry } from "../utils/esbuild.js";
12
- import { f as envFlag } from "./config-DZ3cDaOS.js";
9
+ import { a as resolveDevEnv } from "./env-CFBmcKyo.js";
10
+ import { f as envFlag } from "./config-BClSMzco.js";
11
+ import { findConfigFunctionBySource, resolveFunctionsFromConfig } from "../dev/functions.js";
12
+ import { resolveWatchInputs } from "../dev/inputs.js";
13
13
  import { existsSync, mkdirSync, rmSync, statSync, writeFileSync } from "node:fs";
14
14
  import { basename, dirname, join, relative, resolve } from "node:path";
15
15
  import { fileURLToPath } from "node:url";
@@ -31,7 +31,7 @@ var dev_exports = /* @__PURE__ */ __exportAll({
31
31
  formatEnvSummary: () => formatEnvSummary,
32
32
  handler: () => handler,
33
33
  loadDevEnvFiles: () => loadDevEnvFiles,
34
- localFunctionUrlEnv: () => localFunctionUrlEnv,
34
+ localFunctionPortsEnv: () => localFunctionPortsEnv,
35
35
  planFunctionsToUnits: () => planFunctionsToUnits,
36
36
  reportDevCredential: () => reportDevCredential,
37
37
  sourceFunctionUrlOverlay: () => sourceFunctionUrlOverlay
@@ -55,10 +55,10 @@ const builder = (argv) => argv.usage("$0 dev [--source <path>] [options]").examp
55
55
  "object storage and the AI Gateway where the branch has them. A neon.ts in",
56
56
  "this directory decides instead, exactly as it does for `env pull`.",
57
57
  "",
58
- "NEON_FUNCTION_<SLUG>_BASE_URL from `env pull` / `neon-env run` is the production",
59
- "invocation URL. `dev` rewrites it to `http://localhost:<port>` for each function",
60
- "this process is serving (every neon.ts function, or the matching slug when",
61
- "`--source` names one).",
58
+ "`functionBaseUrl(\"<slug>\")` from @neon/env returns `http://localhost:<port>` for",
59
+ "each function this process is serving (every neon.ts function, or the matching",
60
+ "slug when `--source` names one), through NEON_DEV_FUNCTION_PORTS, and the",
61
+ "deployed URL on the linked branch for any other slug.",
62
62
  "",
63
63
  "Before neon.ts is evaluated, `dev` loads the project's .env, then .env.local,",
64
64
  "which overrides it, into the environment, so Function env values that read",
@@ -267,7 +267,7 @@ const planFunctionsToUnits = async (functions, neonEnv, searchBase, keepPorts =
267
267
  port
268
268
  };
269
269
  });
270
- const overlay = localFunctionUrlEnv(assigned.map(({ fn, port }) => ({
270
+ const overlay = localFunctionPortsEnv(assigned.map(({ fn, port }) => ({
271
271
  slug: fn.slug,
272
272
  port
273
273
  })));
@@ -281,14 +281,10 @@ const planFunctionsToUnits = async (functions, neonEnv, searchBase, keepPorts =
281
281
  }, overlay));
282
282
  };
283
283
  /**
284
- * Local invocation URLs for functions `neon dev` is serving, so siblings call each
285
- * other on localhost instead of the production compute host.
284
+ * The ports of the functions `neon dev` is serving, which `functionBaseUrl` reads so
285
+ * siblings call each other on localhost instead of the deployed compute host.
286
286
  */
287
- const localFunctionUrlEnv = (functions) => {
288
- const out = {};
289
- for (const fn of functions) out[functionBaseUrlKey(fn.slug)] = `http://localhost:${fn.port}`;
290
- return out;
291
- };
287
+ const localFunctionPortsEnv = (functions) => ({ [NEON_DEV_FUNCTION_PORTS]: JSON.stringify(Object.fromEntries(functions.map((fn) => [fn.slug, fn.port]))) });
292
288
  /**
293
289
  * `--source` serves one file. If that file is a neon.ts function, rewrite only that
294
290
  * slug to localhost — this process is not listening for the others.
@@ -301,7 +297,7 @@ const sourceFunctionUrlOverlay = async (match, cliPort, shellEnv = process.env)
301
297
  };
302
298
  const port = portSpec.mode === "explicit" ? portSpec.port : match.port ?? await pickFreePort(portSpec.from);
303
299
  return {
304
- overlay: localFunctionUrlEnv([{
300
+ overlay: localFunctionPortsEnv([{
305
301
  slug: match.slug,
306
302
  port
307
303
  }]),
@@ -421,11 +417,14 @@ const plannedToUnit = (fn, branchEnv, port, overlay = {}) => {
421
417
  * Build a child's env. Neon vars layer over the inherited environment (so the branch's
422
418
  * DATABASE_URL wins over a stale inherited value); a function that loads its own `.env`
423
419
  * at runtime still overrides them. The port spec is encoded for the runtime via
424
- * NEON_DEV_PORT (explicit) or NEON_DEV_PORT_BASE (search).
420
+ * NEON_DEV_PORT (explicit) or NEON_DEV_PORT_BASE (search). An inherited
421
+ * NEON_DEV_FUNCTION_PORTS names another process's ports, so only this one's applies.
425
422
  */
426
423
  const buildChildEnv = (neonEnv, port) => {
424
+ const inherited = { ...process.env };
425
+ delete inherited[NEON_DEV_FUNCTION_PORTS];
427
426
  const env = {
428
- ...process.env,
427
+ ...inherited,
429
428
  ...neonEnv
430
429
  };
431
430
  delete env.NEON_DEV_PORT;
@@ -941,4 +940,4 @@ const resolveRuntimePath = () => {
941
940
  if (!existsSync(candidate)) throw new Error(`Could not locate the dev runtime at ${candidate}`);
942
941
  return candidate;
943
942
  };
944
- export { devBundleDir as a, diffUnits as c, handler as d, loadDevEnvFiles as f, sourceFunctionUrlOverlay as g, reportDevCredential as h, describe as i, formatEnvFiles as l, planFunctionsToUnits as m, captureShellEnv as n, devEnvContext as o, localFunctionUrlEnv as p, command as r, dev_exports as s, builder as t, formatEnvSummary as u };
943
+ export { devBundleDir as a, diffUnits as c, handler as d, loadDevEnvFiles as f, sourceFunctionUrlOverlay as g, reportDevCredential as h, describe as i, formatEnvFiles as l, planFunctionsToUnits as m, captureShellEnv as n, devEnvContext as o, localFunctionPortsEnv as p, command as r, dev_exports as s, builder as t, formatEnvSummary as u };
@@ -2,7 +2,7 @@ import { log } from "../log.js";
2
2
  import { getCliName } from "../utils/cli_name.js";
3
3
  import { declaredNeonServices } from "../config_services.js";
4
4
  import { loadProjectConfig } from "../project.js";
5
- import { a as defaultAiGatewayCredential, c as fetchEnvKeysState, d as isLiveCredential, h as toEntries, i as credentialName, l as functionBaseUrlKey, m as resolveBranchPolicy, n as createApiFromOptions, o as defaultStorageCredential, p as policyEnvKeys, r as credentialEnvKeys, t as NEON_ENV_VAR_KEYS, u as isFunctionBaseUrlKey } from "./env-JgoSsmyt.js";
5
+ import { a as credentialName, d as policyEnvKeys, f as resolveBranchPolicy, i as credentialEnvKeys, l as fetchEnvKeysState, n as NEON_ENV_VAR_KEYS, o as defaultAiGatewayCredential, p as toEntries, r as createApiFromOptions, s as defaultStorageCredential, u as isLiveCredential } from "./env-EJU-0InB.js";
6
6
  import { ENV_PULL_SERVICES, envKeysForSelection, serviceForEnvKey, servicesForEnvKeys } from "../env_services.js";
7
7
  import { formatInstallCommand, resolvePackageManager } from "../utils/package_manager.js";
8
8
  import { StagingOnlyError } from "../utils/staging.js";
@@ -48,7 +48,7 @@ async function fetchEnvReusingSecrets(config, options) {
48
48
  const { branch, desired } = await resolveBranchPolicy(config, options, api, resolvedBranch);
49
49
  const allPolicyKeys = policyEnvKeys(desired);
50
50
  const requested = requestedKeys ? new Set(requestedKeys) : null;
51
- const selectedPolicyKeys = requested === null ? allPolicyKeys : [...allPolicyKeys.filter((key) => requested.has(key)), ...[...requested].filter(isFunctionBaseUrlKey).sort()];
51
+ const selectedPolicyKeys = requested === null ? allPolicyKeys : [...allPolicyKeys.filter((key) => requested.has(key)), ...Object.values(NEON_ENV_VAR_KEYS.branch).filter((key) => requested.has(key) && !allPolicyKeys.includes(key))];
52
52
  const selected = new Set(selectedPolicyKeys);
53
53
  const K = NEON_ENV_VAR_KEYS;
54
54
  const storageCredentialSelected = (desired.preview?.buckets.length ?? 0) > 0 && (selected.has(K.storage.accessKeyId) || selected.has(K.storage.secretAccessKey));
@@ -70,8 +70,7 @@ async function fetchEnvReusingSecrets(config, options) {
70
70
  fresh: [],
71
71
  revoked: [],
72
72
  superseded: []
73
- },
74
- ...fetched.functionUrlsUnavailable ? { functionUrlsUnavailable: true } : {}
73
+ }
75
74
  };
76
75
  }
77
76
  const persisted = readPersistedSecrets(source);
@@ -103,7 +102,6 @@ async function fetchEnvReusingSecrets(config, options) {
103
102
  desired
104
103
  });
105
104
  const vars = preferPersisted(toEntries(fetched.env), source);
106
- const unavailable = fetched.functionUrlsUnavailable ? { functionUrlsUnavailable: true } : {};
107
105
  for (const key of keptSecretKeys) {
108
106
  const value = source[key];
109
107
  if (value !== void 0) vars[key] = value;
@@ -116,8 +114,7 @@ async function fetchEnvReusingSecrets(config, options) {
116
114
  fresh: [],
117
115
  revoked: [],
118
116
  superseded: []
119
- },
120
- ...unavailable
117
+ }
121
118
  };
122
119
  const ours = /* @__PURE__ */ new Set();
123
120
  for (const meta of [storageCredentialManaged && !keepStorage ? named.storage : null, gatewayCredentialManaged && !keepGateway ? named.gateway : null]) if (meta !== null && meta.principalType === "user" && meta.name === credentialName(branch.name)) ours.add(meta.tokenId);
@@ -130,8 +127,7 @@ async function fetchEnvReusingSecrets(config, options) {
130
127
  fresh: secretKeys.filter((key) => !keptSecretKeys.includes(key)),
131
128
  revoked: revokeSuperseded ? [...ours] : [],
132
129
  superseded: revokeSuperseded ? [] : [...ours]
133
- },
134
- ...unavailable
130
+ }
135
131
  };
136
132
  }
137
133
  /** Read the branch credential's secrets out of an env source. */
@@ -378,16 +374,13 @@ const resolveClaimableNeonEnvVars = async (ctx) => {
378
374
  * 1. a `neon.ts` policy is found -> the policy is the source of truth. We first
379
375
  * check it against the branch's live state (`plan`); if it declares a resource
380
376
  * the branch is missing, we stop with a {@link DevEnvMismatchError} pointing at
381
- * `neonctl deploy`. Function declarations are excluded from that check: their
382
- * invocation URLs are derived from the branch connection host, so an undeployed
383
- * function still gets `NEON_FUNCTION_*_BASE_URL`. Otherwise `fetchEnv` evaluates
377
+ * `neonctl deploy`. Function declarations are excluded from that check: local env
378
+ * does not depend on whether a function is deployed. Otherwise `fetchEnv` evaluates
384
379
  * the policy.
385
380
  * 2. no `neon.ts`, but a project + branch are known -> `pullConfig` reads the
386
381
  * branch's live state (Auth / Data API / Realtime enablement plus any object-storage
387
382
  * buckets) into a config, then `fetchEnv` resolves what is actually enabled —
388
- * so a branch with a bucket gets its `AWS_*` storage vars pulled with no policy.
389
- * Function invocation URLs are listed live (`functionUrls: "all-live"`) because
390
- * `pullConfig` cannot round-trip them into `functions`. With
383
+ * so a branch with a bucket gets its `AWS_*` storage vars pulled with no policy. With
391
384
  * {@link DevEnvContext.implyAiGateway}, the AI Gateway is added on top, since
392
385
  * `pullConfig` cannot read it back.
393
386
  * 3. otherwise -> throw {@link MissingBranchContextError}.
@@ -422,10 +415,7 @@ const resolveNeonEnvVars = async (ctx) => {
422
415
  protected: pulled.branch.protected,
423
416
  ...pulled.branch.expiresAt ? { expiresAt: pulled.branch.expiresAt } : {}
424
417
  };
425
- if (!ctx.implyAiGateway) return await fetchAndProject(pulled.config, ctx, {
426
- functionUrls: "all-live",
427
- resolvedBranch
428
- });
418
+ if (!ctx.implyAiGateway) return await fetchAndProject(pulled.config, ctx, { resolvedBranch });
429
419
  return await resolveWithImpliedGateway(pulled.config, ctx, {
430
420
  projectId: ctx.projectId,
431
421
  branchId: ctx.branchId,
@@ -466,15 +456,9 @@ const withAiGateway = (config) => ({
466
456
  */
467
457
  const resolveWithImpliedGateway = async (config, ctx, branch) => {
468
458
  const unreachable = await credentialsUnreachable(ctx, branch);
469
- if (unreachable === null) return await fetchAndProject(withAiGateway(config), ctx, {
470
- functionUrls: "all-live",
471
- resolvedBranch: branch.resolvedBranch
472
- });
459
+ if (unreachable === null) return await fetchAndProject(withAiGateway(config), ctx, { resolvedBranch: branch.resolvedBranch });
473
460
  log.warning(`Could not reach the AI Gateway's credentials, so %s were not resolved. Everything else was. Either this project does not have the AI Gateway, or the call failed — \`${getCliName()} env pull -s ai-gateway\` will say which.\nDetails: %s`, [NEON_ENV_VAR_KEYS.aiGateway.apiKey, NEON_ENV_VAR_KEYS.aiGateway.baseUrl].join(" and "), unreachable);
474
- const pulled = await fetchAndProject(config, ctx, {
475
- functionUrls: "all-live",
476
- resolvedBranch: branch.resolvedBranch
477
- });
461
+ const pulled = await fetchAndProject(config, ctx, { resolvedBranch: branch.resolvedBranch });
478
462
  return {
479
463
  ...pulled,
480
464
  skipped: [...pulled.skipped ?? [], "ai-gateway"]
@@ -514,18 +498,13 @@ const resolveSelectedServices = async (ctx, directServices, envKeys) => {
514
498
  const api = apiFor(ctx);
515
499
  const has = (service) => services.includes(service);
516
500
  const checkAiGateway = has("ai-gateway") && !selectedKeys.includes(NEON_ENV_VAR_KEYS.aiGateway.apiKey);
517
- const [auth, dataApiEnabled, realtime, buckets, aiGatewayAvailable, functions] = await Promise.all([
501
+ const [auth, dataApiEnabled, realtime, buckets, aiGatewayAvailable] = await Promise.all([
518
502
  has("auth") ? api.getNeonAuth(projectId, branchId) : null,
519
503
  has("data-api") ? readDataApiEnabled(api, projectId, branchId) : null,
520
504
  has("realtime") ? readRealtime(api, projectId, branchId) : null,
521
505
  has("object-storage") ? api.listBranchBuckets(projectId, branchId) : null,
522
- checkAiGateway ? readAiGatewayAvailable(api, projectId, branchId) : null,
523
- directServices.includes("functions") ? api.listBranchFunctions(projectId, branchId) : null
506
+ checkAiGateway ? readAiGatewayAvailable(api, projectId, branchId) : null
524
507
  ]);
525
- const callableFunctions = (functions ?? []).filter((fn) => fn.invocationUrl !== "");
526
- if (directServices.includes("functions") && callableFunctions.length === 0) throw new ServiceNotOnBranchError(`--service functions: branch ${branchId} has no deployed functions, so there are no NEON_FUNCTION_*_BASE_URL vars to pull. Deploy a function first (\`${getCliName()} deploy\`, or in the Neon Console), or drop functions from --service.`);
527
- const functionKeys = directServices.includes("functions") ? callableFunctions.map((fn) => functionBaseUrlKey(fn.slug)).sort((left, right) => left.localeCompare(right)) : [];
528
- const fetchKeys = [.../* @__PURE__ */ new Set([...selectedKeys, ...functionKeys])];
529
508
  const config = configForServices(services, branchId, {
530
509
  authEnabled: auth !== null,
531
510
  dataApiEnabled,
@@ -537,12 +516,8 @@ const resolveSelectedServices = async (ctx, directServices, envKeys) => {
537
516
  envKeys
538
517
  });
539
518
  return await fetchAndProject(config, ctx, {
540
- keys: fetchKeys,
541
- revokeSuperseded: false,
542
- ...directServices.includes("functions") ? {
543
- functionUrls: "all-live",
544
- listedFunctions: callableFunctions
545
- } : {}
519
+ keys: selectedKeys,
520
+ revokeSuperseded: false
546
521
  });
547
522
  };
548
523
  /**
@@ -703,14 +678,12 @@ const fetchAndProject = async (config, ctx, opts = {}) => {
703
678
  ...ctx.env ? { env: ctx.env } : {},
704
679
  ...opts.keys ? { keys: opts.keys } : {},
705
680
  ...opts.revokeSuperseded === false ? { revokeSuperseded: false } : {},
706
- ...opts.functionUrls ? { functionUrls: opts.functionUrls } : {},
707
- ...opts.listedFunctions ? { listedFunctions: opts.listedFunctions } : {},
708
- ...opts.resolvedBranch ? { resolvedBranch: opts.resolvedBranch } : {}
681
+ ...opts.resolvedBranch ? { resolvedBranch: opts.resolvedBranch } : {},
682
+ functionHostSuffix: "always"
709
683
  });
710
684
  return {
711
685
  vars: result.vars,
712
- credential: result.credential,
713
- ...result.functionUrlsUnavailable ? { skipped: ["functions"] } : {}
686
+ credential: result.credential
714
687
  };
715
688
  };
716
689
  /**
@@ -5,10 +5,10 @@ import { isClaimableEnvTarget } from "../claimable/state.js";
5
5
  import { getCliName } from "../utils/cli_name.js";
6
6
  import { deprecatedServiceMessage, parseServices, servicesFlagValue, servicesOption } from "../neon_services.js";
7
7
  import { mergeEnvFile, readEnvFile, resolveEnvFilePath } from "../env_file.js";
8
- import { t as NEON_ENV_VAR_KEYS, u as isFunctionBaseUrlKey } from "./env-JgoSsmyt.js";
9
- import { ENV_PULL_KEY_HELP, ENV_PULL_SERVICES, envKeysForSelection, envPullFlagValue, ownedEnvServiceKeys, parseEnvPullKeys } from "../env_services.js";
10
- import { i as dropClaimableUnsupported, o as resolveNeonEnvVars } from "./env-CIFMBEon.js";
8
+ import { n as NEON_ENV_VAR_KEYS } from "./env-EJU-0InB.js";
9
+ import { ENV_PULL_KEY_HELP, ENV_PULL_SERVICES, envKeysForSelection, envPullFlagValue, isLegacyFunctionBaseUrlKey, ownedEnvServiceKeys, parseEnvPullKeys } from "../env_services.js";
11
10
  import { fillSingleProject, resolveBranchRef } from "../utils/enrichers.js";
11
+ import { i as dropClaimableUnsupported, o as resolveNeonEnvVars } from "./env-CFBmcKyo.js";
12
12
  import { warnAiGateway } from "../utils/ai_gateway_notice.js";
13
13
  import { formatPulledEnv, pulledBranch } from "../commands/env_output.js";
14
14
  import { existsSync } from "node:fs";
@@ -66,8 +66,7 @@ const builder = (argv) => argv.usage("$0 env <sub-command> [options]").options({
66
66
  "What gets pulled, in precedence order:",
67
67
  " 1. --service / --env, when given — their union, ignoring neon.ts.",
68
68
  " 2. neon.ts, when the project directory (next to .neon, or cwd",
69
- " without one) has one — including derived function URLs (the",
70
- " function does not have to be deployed).",
69
+ " without one) has one.",
71
70
  " 3. Otherwise everything the branch has, plus the AI Gateway —",
72
71
  " which pulls the default AI Gateway credential.",
73
72
  "",
@@ -82,7 +81,7 @@ const builder = (argv) => argv.usage("$0 env <sub-command> [options]").options({
82
81
  "The pull bundled into link / checkout / config apply follows 2 and 3",
83
82
  "without the AI Gateway, so it never writes a gateway token you did",
84
83
  "not ask for. Run `env pull` to add it."
85
- ].join("\n")).example("$0 env pull", "Write the linked branch's Neon vars into .env.local (or .env if present)").example("$0 env pull --branch preview --file .env.preview", "Pull a specific branch into a specific file").example("$0 env pull -s ai-gateway -s postgres", "Pull only the AI Gateway and Postgres variables").example("$0 env pull -e DATABASE_URL", "Pull only the pooled Postgres connection string").example("$0 env pull -s auth -e DATABASE_URL", "Pull all Auth variables plus DATABASE_URL").example("$0 env pull -s functions", "Pull NEON_FUNCTION_<SLUG>_BASE_URL for every deployed function").example("$0 env pull -e NEON_FUNCTION_HELLO_BASE_URL", "Write that function's production invocation URL (no deploy required)").strict(), async (args) => {
84
+ ].join("\n")).example("$0 env pull", "Write the linked branch's Neon vars into .env.local (or .env if present)").example("$0 env pull --branch preview --file .env.preview", "Pull a specific branch into a specific file").example("$0 env pull -s ai-gateway -s postgres", "Pull only the AI Gateway and Postgres variables").example("$0 env pull -e DATABASE_URL", "Pull only the pooled Postgres connection string").example("$0 env pull -s auth -e DATABASE_URL", "Pull all Auth variables plus DATABASE_URL").example("$0 env pull -s functions", "Pull NEON_BRANCH_ID and NEON_FUNCTION_HOST_SUFFIX, which functionBaseUrl(\"<slug>\") from @neon/env reads").strict(), async (args) => {
86
85
  const rawServices = servicesFlagValue(args.service);
87
86
  const rawEnvKeys = envPullFlagValue(args.env);
88
87
  const services = rawServices ? parseServices(rawServices, {
@@ -118,6 +117,8 @@ const NEON_VAR_NAMES = Object.values(NEON_ENV_VAR_KEYS).flatMap((group) => Objec
118
117
  */
119
118
  const NEON_OWNED_ENV_KEYS = [
120
119
  ...Object.values(NEON_ENV_VAR_KEYS.postgres),
120
+ NEON_ENV_VAR_KEYS.branch.id,
121
+ NEON_ENV_VAR_KEYS.branch.functionHostSuffix,
121
122
  ...Object.values(NEON_ENV_VAR_KEYS.auth),
122
123
  ...Object.values(NEON_ENV_VAR_KEYS.dataApi),
123
124
  ...Object.values(NEON_ENV_VAR_KEYS.realtime),
@@ -162,12 +163,12 @@ const pull = async (props, opts = {}) => {
162
163
  ...props.apiHost ? { apiHost: props.apiHost } : {},
163
164
  ...props.runtimeApi ? { api: props.runtimeApi } : {}
164
165
  });
165
- const neonVars = pickSelectedVars(pickNeonVars(vars), selectedKeys, props.services !== void 0 ? selectionServices : void 0);
166
+ const neonVars = pickSelectedVars(pickNeonVars(vars), selectedKeys);
166
167
  if (Object.keys(neonVars).length === 0) {
167
168
  if (!(dropped !== null && dropped.services.length === 0 && dropped.envKeys.length === 0 && dropped.skipped.length > 0)) log.info(`No Neon env variables to pull from ${namedBranch ? pulledBranch(namedBranch) : "this branch"}: no DATABASE_URL or enabled Auth / Data API.`);
168
169
  return { status: "empty" };
169
170
  }
170
- const { written, removed } = mergeEnvFile(targetPath, neonVars, { managedKeys: managedKeysFor(selectedKeys, unreachedButCurrent(skipped, existingEnv, branchId), existingEnv, props.services !== void 0 ? selectionServices : void 0, props.envKeys !== void 0 ? selectionEnvKeys : void 0) });
171
+ const { written, removed } = mergeEnvFile(targetPath, neonVars, { managedKeys: managedKeysFor(selectedKeys, unreachedButCurrent(skipped, existingEnv, branchId), existingEnv, props.services !== void 0 ? selectionServices : void 0) });
171
172
  process.stderr.write(formatPulledEnv({
172
173
  status: "written",
173
174
  written,
@@ -179,7 +180,6 @@ const pull = async (props, opts = {}) => {
179
180
  const gatewayBaseUrl = neonVars.NEON_AI_GATEWAY_BASE_URL;
180
181
  const gatewayToken = neonVars.NEON_AI_GATEWAY_TOKEN;
181
182
  if (gatewayBaseUrl && gatewayToken) await warnAiGateway({
182
- apiClient: props.apiClient,
183
183
  projectId: props.projectId,
184
184
  branchId,
185
185
  gateway: {
@@ -196,18 +196,17 @@ const pull = async (props, opts = {}) => {
196
196
  ...skipped && skipped.length > 0 ? { skipped } : {}
197
197
  };
198
198
  };
199
- /** Prevents scoped or unavailable services from pruning values they did not resolve. */
200
- const managedKeysFor = (selectedKeys, unreached, existingEnv, services, envKeys) => {
201
- const existingFunctionKeys = Object.keys(existingEnv).filter(isFunctionBaseUrlKey);
202
- const namedFunctionKeys = (envKeys ?? []).filter(isFunctionBaseUrlKey);
203
- const ownedFunctionKeys = selectedKeys === void 0 || (services?.includes("functions") ?? false) ? existingFunctionKeys : namedFunctionKeys;
204
- const owned = selectedKeys ? [...NEON_OWNED_ENV_KEYS.filter((key) => selectedKeys.includes(key)), ...ownedFunctionKeys] : [...NEON_OWNED_ENV_KEYS, ...ownedFunctionKeys];
199
+ /**
200
+ * Prevents scoped or unavailable services from pruning values they did not resolve. A pull
201
+ * that covers functions also prunes the `NEON_FUNCTION_<SLUG>_BASE_URL` lines earlier
202
+ * releases wrote, since nothing reads or refreshes them anymore.
203
+ */
204
+ const managedKeysFor = (selectedKeys, unreached, existingEnv, services) => {
205
+ const legacyFunctionKeys = selectedKeys === void 0 || (services?.includes("functions") ?? false) ? Object.keys(existingEnv).filter(isLegacyFunctionBaseUrlKey) : [];
206
+ const owned = [...selectedKeys ? NEON_OWNED_ENV_KEYS.filter((key) => selectedKeys.includes(key)) : NEON_OWNED_ENV_KEYS, ...legacyFunctionKeys];
205
207
  if (unreached.length === 0) return owned;
206
208
  const keep = new Set(ownedEnvServiceKeys(unreached));
207
- return owned.filter((key) => {
208
- if (unreached.includes("functions") && isFunctionBaseUrlKey(key)) return false;
209
- return !keep.has(key);
210
- });
209
+ return owned.filter((key) => !keep.has(key));
211
210
  };
212
211
  /**
213
212
  * Endpoint failure is not evidence that existing values are stale; the gateway host check
@@ -220,7 +219,6 @@ const unreachedButCurrent = (skipped, existingEnv, branchId) => {
220
219
  const baseUrl = existingEnv[NEON_ENV_VAR_KEYS.aiGateway.baseUrl];
221
220
  if (baseUrl !== void 0 && isBranchGatewayUrl(baseUrl, branchId)) keep.push("ai-gateway");
222
221
  }
223
- if (skipped.includes("functions")) keep.push("functions");
224
222
  return keep;
225
223
  };
226
224
  /**
@@ -238,11 +236,10 @@ const isBranchGatewayUrl = (baseUrl, branchId) => URL.canParse(baseUrl) && new U
238
236
  * supporting values that were not selected (the direct connection URI derives the AI Gateway
239
237
  * host, for example); those must not land in the target file.
240
238
  */
241
- const pickSelectedVars = (vars, selectedKeys, services) => {
239
+ const pickSelectedVars = (vars, selectedKeys) => {
242
240
  if (!selectedKeys) return vars;
243
241
  const wanted = new Set(selectedKeys);
244
- const keepFunctionUrls = services?.includes("functions") ?? false;
245
- return Object.fromEntries(Object.entries(vars).filter(([key]) => wanted.has(key) || keepFunctionUrls && isFunctionBaseUrlKey(key)));
242
+ return Object.fromEntries(Object.entries(vars).filter(([key]) => wanted.has(key)));
246
243
  };
247
244
  /**
248
245
  * Pull a freshly-pinned branch's Neon env vars into a local `.env`, bundled into `link` and
@@ -277,7 +274,7 @@ Run \`${getCliName()} env pull\` once resolved (e.g. \`${getCliName()} deploy\`
277
274
  */
278
275
  const pickNeonVars = (vars) => {
279
276
  const out = {};
280
- for (const [name, value] of Object.entries(vars)) if (NEON_VAR_NAMES.some((key) => key === name) || isFunctionBaseUrlKey(name)) out[name] = value;
277
+ for (const [name, value] of Object.entries(vars)) if (NEON_VAR_NAMES.some((key) => key === name)) out[name] = value;
281
278
  return out;
282
279
  };
283
280
  export { describe as a, pull as c, command as i, autoPullEnvAfterPin as n, env_exports as o, builder as r, handler as s, ENV_PULL_SKIPPED_HINT as t };