neon 9.0.0 → 9.2.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.
package/README.md CHANGED
@@ -642,7 +642,7 @@ If you'd rather not keep env vars on disk, inject them at runtime instead with `
642
642
 
643
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.
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
+ 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 resolve the same way they do for `neon deploy --env`. A variable declared `required: true` must be set, or `dev` fails before any Function starts; `--source` checks only the Function it serves. `required: "default-branch"` and `required: false` may be unset ([Function env](../config/README.md#function-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`:
646
646
 
647
647
  ```bash
648
648
  neon dev # loads .env, then .env.local (overrides .env)
@@ -1212,6 +1212,10 @@ neon inspect db stalled-queries --output json
1212
1212
 
1213
1213
  Every sub-command resolves the project through the standard chain (`--project-id`, then the `.neon` context file, then a single-project auto-detect), and takes `--branch <id|name>`, defaulting to the project's default branch. `logs query` searches the previous hour by default; `logs field-values` searches the previous six hours. The maximum time window is seven days.
1214
1214
 
1215
+ Use `neon logs query` for structured filters or LogQL with formatted records and cursor
1216
+ pagination. Use [`neon logs loki`](#loki-api-logs-loki) for the Loki read API, label
1217
+ discovery, and the complete Loki JSON response. Both appear in `neon logs --help`.
1218
+
1215
1219
  ```bash
1216
1220
  # The last 30 minutes on the default branch
1217
1221
  neon logs query --since 30m
@@ -1259,6 +1263,60 @@ Two combinations are rejected before the request: `--since` with `--start-time`,
1259
1263
 
1260
1264
  `--body-contains` compares a case-sensitive substring against the rendered message. Structured bodies, including object storage records, are rendered as compact JSON, so match the JSON form (for example, `"http_status":200`).
1261
1265
 
1266
+ ### Loki API (`logs loki`)
1267
+
1268
+ `neon logs loki` calls the branch's [Loki-compatible read API](https://neon.com/docs/cli/logs#loki-read-api) directly, using the CLI's
1269
+ normal authentication, project selection and branch resolution, through
1270
+ `neon.logs.loki` in `@neon/sdk`. JSON is the command's default output; `--output json` and `--output yaml` are supported. It preserves the full
1271
+ Loki response envelope. Help and shell completion work without authentication.
1272
+
1273
+ Discover labels and service names, then choose a selector and bound the query:
1274
+
1275
+ ```bash
1276
+ neon logs loki --endpoint labels
1277
+ neon logs loki --endpoint label/service_name/values --since 6h
1278
+ neon logs loki '{entity_type="function"} |= "error"' --since 30m --limit 100
1279
+ neon logs loki '{entity_type="function"}' --limit 200 --direction forward
1280
+ neon logs loki '{entity_type="function"}' --project-id <id> --branch main \
1281
+ --start 2026-11-01T00:00:00Z --end 2026-11-01T01:00:00Z
1282
+ neon logs loki '{entity_type="function"}' --endpoint label/severity_text/values
1283
+ neon logs loki '{entity_type="function"}' --since 30m --limit 100 \
1284
+ | jq '{warnings: (.warnings // []), streams: .data.result}'
1285
+ ```
1286
+
1287
+ The default endpoint is `query_range`. Each Loki parameter has a named flag, and with a
1288
+ label endpoint the positional query is an optional stream selector:
1289
+
1290
+ | Flag | Meaning |
1291
+ | --- | --- |
1292
+ | `--since <duration>` | Positive Go duration such as `30m` or `24h`. Defaults to 1h for range queries and 6h for label values. |
1293
+ | `--start <timestamp>` | RFC 3339 or Unix nanoseconds, kept as a string. Takes precedence over `since`. |
1294
+ | `--end <timestamp>` | RFC 3339 or Unix nanoseconds, kept as a string. Defaults to now. |
1295
+ | `--limit <count>` | `query_range` only. Positive integer limiting the number of log lines; the server enforces its cap. |
1296
+ | `--direction <order>` | `query_range` only. `forward` (oldest first) or `backward` (newest first). |
1297
+
1298
+ The CLI does not parse LogQL or convert nanosecond timestamps to numbers.
1299
+
1300
+ Range responses have `data.resultType: "streams"` and a `data.result` array. Each entry
1301
+ contains `stream` labels and `values` pairs of `[timestamp, line]`; timestamps are nanosecond
1302
+ strings. There is no continuation cursor. A result with `--limit` lines, or with the
1303
+ server's cap of 10,000 lines, may be incomplete, and reaching the cap adds no `warnings`
1304
+ entry. Narrow the time window or selector for complete results. The maximum window is
1305
+ 168 hours.
1306
+
1307
+ Neon's supported LogQL subset is stream selectors (`=`, `!=`, `=~`, `!~`) and line filters
1308
+ (`|=`, `!=`, `|~`, `!~`). Metric queries, parser/format stages and live tailing are unsupported.
1309
+ Instant queries are unsupported. The advertised labels are `service_name`,
1310
+ `severity_text`, `scope_name`, and `entity_type`; use `labels` to discover them. Label-value
1311
+ queries accept a stream selector without line filters.
1312
+
1313
+ Requests go to
1314
+ `/telemetry/v1/projects/<project>/branches/<branch>/loki/api/v1/<endpoint>` on the same
1315
+ origin as `--api-host` / `NEON_API_HOST` (default `https://console.neon.tech`). This is a
1316
+ separate API from the Management API used by `neon logs query --logql`. Access requires
1317
+ project read permission and telemetry enabled for the project's organization and region.
1318
+ The CLI reports the server's error when access or a query is rejected.
1319
+
1262
1320
  ## Profiles
1263
1321
 
1264
1322
  The CLI holds one Neon account by default. A profile adds another, and is a pointer: a
@@ -1557,7 +1615,7 @@ Every subcommand except `list` takes `--org-id`. Without it, the CLI uses the or
1557
1615
  | function | `deploy`, `list`, `get`, `delete`, `domains list`, `domains register`, `domains delete` | Manage Neon Functions |
1558
1616
  | [roles](https://neon.com/docs/reference/cli-roles) | `list`, `get`, `create`, `reset-password`, `delete` | Manage roles |
1559
1617
  | [operations](https://neon.com/docs/reference/cli-operations) | `list`, `get` | Manage operations |
1560
- | logs | `query`, `fields`, `field-values` | Query branch logs (Beta) |
1618
+ | [logs](#logs-logs) | `query`, `fields`, `field-values`, `loki [query]` | Query branch logs or the Loki API |
1561
1619
  | inspect | `db stalled-queries` | Inspect Postgres diagnostics |
1562
1620
  | snapshots | `list`, `get`, `create`, `update`, `delete`, `restore`, `finalize`, `schedule get`, `schedule set` | Manage snapshots |
1563
1621
  | triggers | `list`, `get`, `create`, `update`, `enable`, `disable`, `delete` | Manage function triggers |
@@ -12,8 +12,8 @@ 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
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";
15
+ import { a as applyPolicyOnCreate, f as envFlag, l as createBranchFromPolicyOnCheckout } from "./config-aBF_xpbX.js";
16
+ import { i as handler$1 } from "./link-CYwhNbA4.js";
17
17
  import chalk from "chalk";
18
18
  import prompts from "prompts";
19
19
  // src/commands/checkout.ts
@@ -89,7 +89,7 @@ const INSPECT_FIELDS = [
89
89
  "config"
90
90
  ];
91
91
  const envFlag = { env: {
92
- describe: "Path to a .env file to load into the environment before evaluating neon.ts so Function env values resolve from it. Existing env vars are not overridden. Function env values that read process.env must be set in this file or the environment.",
92
+ describe: "Path to a .env file to load into the environment before evaluating neon.ts so Function env values resolve from it. Existing env vars are not overridden. Required Function env (declared required: true, or required: \"default-branch\" when deploying the default branch) and values that read process.env must be set in this file or the environment.",
93
93
  type: "string"
94
94
  } };
95
95
  /** Apply-only flags, exported so `deploy` can reuse the exact same surface. */
@@ -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-BClSMzco.js";
3
+ import { f as envFlag, i as applyFlags, p as envPullFlag, r as applyCmd } from "./config-aBF_xpbX.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({
@@ -7,7 +7,7 @@ import { t as NEON_DEV_FUNCTION_PORTS } from "./env-EJU-0InB.js";
7
7
  import { branchIdResolve } from "../utils/enrichers.js";
8
8
  import { bundleEntry } from "../utils/esbuild.js";
9
9
  import { a as resolveDevEnv } from "./env-CFBmcKyo.js";
10
- import { f as envFlag } from "./config-BClSMzco.js";
10
+ import { f as envFlag } from "./config-aBF_xpbX.js";
11
11
  import { findConfigFunctionBySource, resolveFunctionsFromConfig } from "../dev/functions.js";
12
12
  import { resolveWatchInputs } from "../dev/inputs.js";
13
13
  import { existsSync, mkdirSync, rmSync, statSync, writeFileSync } from "node:fs";
@@ -194,12 +194,13 @@ const runSingleSource = async (props, shellEnv, envFiles) => {
194
194
  bundleDir: devBundleDir(process.cwd()),
195
195
  childEnv: buildChildEnv({
196
196
  ...neonEnv,
197
+ ...match?.declaredEnv,
197
198
  ...overlay
198
- }, port),
199
+ }, port, match?.unsetEnv),
199
200
  label: null,
200
201
  envSummary: {
201
202
  neon: Object.keys(neonEnv),
202
- fn: []
203
+ fn: Object.keys(match?.declaredEnv ?? {})
203
204
  }
204
205
  };
205
206
  await runSupervisor([unit], {
@@ -390,7 +391,7 @@ const plannedToUnit = (fn, branchEnv, port, overlay = {}) => {
390
391
  const childEnv = buildChildEnv({
391
392
  ...branchEnv,
392
393
  ...fn.env
393
- }, port);
394
+ }, port, fn.unsetEnv);
394
395
  return {
395
396
  slug: fn.slug,
396
397
  source: fn.source,
@@ -407,6 +408,7 @@ const plannedToUnit = (fn, branchEnv, port, overlay = {}) => {
407
408
  source: fn.source,
408
409
  port: fn.port ?? null,
409
410
  env: fn.env,
411
+ unsetEnv: fn.unsetEnv ?? null,
410
412
  overlay,
411
413
  externalPackages: fn.externalPackages ?? null,
412
414
  bundler: typeof fn.bundler === "function" ? "custom" : fn.bundler ?? null
@@ -420,13 +422,14 @@ const plannedToUnit = (fn, branchEnv, port, overlay = {}) => {
420
422
  * NEON_DEV_PORT (explicit) or NEON_DEV_PORT_BASE (search). An inherited
421
423
  * NEON_DEV_FUNCTION_PORTS names another process's ports, so only this one's applies.
422
424
  */
423
- const buildChildEnv = (neonEnv, port) => {
425
+ const buildChildEnv = (neonEnv, port, unset = []) => {
424
426
  const inherited = { ...process.env };
425
427
  delete inherited[NEON_DEV_FUNCTION_PORTS];
426
428
  const env = {
427
429
  ...inherited,
428
430
  ...neonEnv
429
431
  };
432
+ for (const key of unset) delete env[key];
430
433
  delete env.NEON_DEV_PORT;
431
434
  delete env.NEON_DEV_PORT_BASE;
432
435
  if (port.mode === "explicit") env.NEON_DEV_PORT = String(port.port);
@@ -5,8 +5,8 @@ import { CONTEXT_FILE, contextBranch, gitBranchMap, gitBranchMapping, isUnfollow
5
5
  import { writer } from "../writer.js";
6
6
  import { neonSafeBranchName } from "../utils/branch_name.js";
7
7
  import { currentGitBranch, gitPull, gitRepoRoot, hasUpstream, installPostCheckoutHook, isGitRepo, isManagedHook, localGitBranches, postCheckoutHookPath, readGitContext, removePostCheckoutHook } from "../utils/git.js";
8
- import { o as quoteFlagValue } from "./link-n40BxbmK.js";
9
- import { o as handler$1 } from "./checkout-B_gbS0nD.js";
8
+ import { o as quoteFlagValue } from "./link-CYwhNbA4.js";
9
+ import { o as handler$1 } from "./checkout-Bw48iTay.js";
10
10
  import { existsSync } from "node:fs";
11
11
  import { join } from "node:path";
12
12
  import chalk from "chalk";
@@ -14,7 +14,7 @@ import { createBranch, pickBranchInteractively } from "../utils/branch_picker.js
14
14
  import { looksLikeBranchId } from "../utils/formats.js";
15
15
  import { listAllProjectBranches } from "../utils/enrichers.js";
16
16
  import { n as autoPullEnvAfterPin } from "./env-DxcO3oJk.js";
17
- import { h as initCmd } from "./config-BClSMzco.js";
17
+ import { h as initCmd } from "./config-aBF_xpbX.js";
18
18
  import { formatLinkSummary } from "../commands/link_output.js";
19
19
  import { r as REGIONS } from "./projects-a3X4OFEJ.js";
20
20
  import prompts from "prompts";
@@ -4,6 +4,7 @@ import { isNeonApiError } from "../api.js";
4
4
  import { writer } from "../writer.js";
5
5
  import { noPassthrough, single } from "../utils/flags.js";
6
6
  import { branchIdFromProps, fillSingleProject } from "../utils/enrichers.js";
7
+ import { builder as builder$1, command as command$1, describe as describe$1, handler as handler$1 } from "../commands/loki.js";
7
8
  // src/commands/logs.ts
8
9
  var logs_exports = /* @__PURE__ */ __exportAll({
9
10
  assertReachableLogsPage: () => assertReachableLogsPage,
@@ -18,7 +19,9 @@ var logs_exports = /* @__PURE__ */ __exportAll({
18
19
  const LOGS_EPILOG = `
19
20
  Logs are currently available only for projects in aws-us-east-2, aws-us-east-1, aws-eu-central-1, and aws-ap-southeast-1.
20
21
 
21
- For more information, visit https://neon.com/docs/reference/neon-cli`;
22
+ Use neon logs query for structured filters, human-readable tables and cursor pagination. Use neon logs loki for the Loki read API and its complete JSON response envelope.
23
+
24
+ For more information, visit https://neon.com/docs/cli/logs`;
22
25
  const LOG_SOURCES = [
23
26
  "function",
24
27
  "storage",
@@ -91,8 +94,8 @@ const windowOptions = (defaultWindow) => ({
91
94
  }
92
95
  });
93
96
  const command = "logs";
94
- const describe = "Query branch logs";
95
- const builder = (argv) => argv.usage("$0 logs <sub-command> [options]").options(scopeOptions).middleware(fillSingleProject).command("query", "Query log records on a branch", (yargs) => yargs.epilogue(LOGS_EPILOG).options({
97
+ const describe = "Query branch logs with structured filters, LogQL, or the Loki API";
98
+ const builder = (argv) => argv.usage("$0 logs <sub-command> [options]").options(scopeOptions).middleware(fillSingleProject).command("query", "Query log records with structured filters or LogQL", (yargs) => yargs.epilogue(LOGS_EPILOG).options({
96
99
  ...windowOptions("1h"),
97
100
  limit: {
98
101
  describe: "Maximum number of records to return per page (1-1000)",
@@ -174,7 +177,7 @@ const builder = (argv) => argv.usage("$0 logs <sub-command> [options]").options(
174
177
  type: "number",
175
178
  coerce: logLimit
176
179
  }
177
- }).conflicts("since", "start-time").example([["$0 logs field-values service_name --since 6h", "Service names seen in the last six hours"]]).strict().check(noPassthrough("logs field-values")), (args) => fieldValues(args)).epilogue(LOGS_EPILOG);
180
+ }).conflicts("since", "start-time").example([["$0 logs field-values service_name --since 6h", "Service names seen in the last six hours"]]).strict().check(noPassthrough("logs field-values")), (args) => fieldValues(args)).command(command$1, describe$1, builder$1, (args) => handler$1(args)).epilogue(LOGS_EPILOG);
178
181
  const handler = (args) => {
179
182
  return args;
180
183
  };
@@ -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 { y as status } from "./config-BClSMzco.js";
3
+ import { y as status } from "./config-aBF_xpbX.js";
4
4
  // src/commands/status.ts
5
5
  var status_exports = /* @__PURE__ */ __exportAll({
6
6
  builder: () => builder,
package/dist/api.js CHANGED
@@ -64,6 +64,7 @@ function messageFromBody(body) {
64
64
  }
65
65
  if (body && typeof body === "object" && "error" in body) {
66
66
  const error = body.error;
67
+ if (typeof error === "string") return error;
67
68
  if (error && typeof error === "object" && "message" in error) {
68
69
  const message = error.message;
69
70
  if (typeof message === "string") return message;
@@ -1 +1 @@
1
- export { t as builder, r as command, i as describe, a as formatCheckoutPolicyFailure, o as handler } from "../_chunks/checkout-B_gbS0nD.js";
1
+ export { t as builder, r as command, i as describe, a as formatCheckoutPolicyFailure, o as handler } from "../_chunks/checkout-Bw48iTay.js";
@@ -1 +1 @@
1
- export { t as ConfigInstallFailed, n as addCmd, r as applyCmd, i as applyFlags, a as applyPolicyOnCreate, o as builder, s as command, l as createBranchFromPolicyOnCheckout, u as describe, d as ensureConfigPackages, f as envFlag, p as envPullFlag, m as handler, h as initCmd, g as installCommandFrom, _ as missingDependencies, v as planCmd, y as status } from "../_chunks/config-BClSMzco.js";
1
+ export { t as ConfigInstallFailed, n as addCmd, r as applyCmd, i as applyFlags, a as applyPolicyOnCreate, o as builder, s as command, l as createBranchFromPolicyOnCheckout, u as describe, d as ensureConfigPackages, f as envFlag, p as envPullFlag, m as handler, h as initCmd, g as installCommandFrom, _ as missingDependencies, v as planCmd, y as status } from "../_chunks/config-aBF_xpbX.js";
@@ -1 +1 @@
1
- export { t as builder, n as command, i as describe, a as handler } from "../_chunks/deploy-CJ22hy3i.js";
1
+ export { t as builder, n as command, i as describe, a as handler } from "../_chunks/deploy-CMYTjbf6.js";
@@ -1 +1 @@
1
- export { t as builder, n as captureShellEnv, r as command, i as describe, a as devBundleDir, o as devEnvContext, c as diffUnits, l as formatEnvFiles, u as formatEnvSummary, d as handler, f as loadDevEnvFiles, p as localFunctionPortsEnv, m as planFunctionsToUnits, h as reportDevCredential, g as sourceFunctionUrlOverlay } from "../_chunks/dev-CSoQfCuS.js";
1
+ export { t as builder, n as captureShellEnv, r as command, i as describe, a as devBundleDir, o as devEnvContext, c as diffUnits, l as formatEnvFiles, u as formatEnvSummary, d as handler, f as loadDevEnvFiles, p as localFunctionPortsEnv, m as planFunctionsToUnits, h as reportDevCredential, g as sourceFunctionUrlOverlay } from "../_chunks/dev-r0-8mPJk.js";
@@ -8,7 +8,7 @@ import { writer } from "../writer.js";
8
8
  import { formatInitDone, printInitDone } from "../init/chrome.js";
9
9
  import { FUNCTION_SLUG_PATTERN, deriveFunctionSlug } from "../utils/function_slug.js";
10
10
  import { displayPath } from "./env_output.js";
11
- import { _ as missingDependencies, d as ensureConfigPackages, g as installCommandFrom } from "../_chunks/config-BClSMzco.js";
11
+ import { _ as missingDependencies, d as ensureConfigPackages, g as installCommandFrom } from "../_chunks/config-aBF_xpbX.js";
12
12
  import { recommendedOperations } from "../functions/registry.js";
13
13
  import { collidingFiles, operationsFromFlags, planConfigRegistration, planEnvExample, planScaffold, writeScaffold } from "../functions/scaffold.js";
14
14
  import { describeRegistrySource, openRegistry } from "../functions/source.js";
@@ -1 +1 @@
1
- export { t as aliases, n as builder, r as cleanup, i as command, a as describe, s as handler, c as install, l as partitionBranchesToPrune, u as status, d as sync, f as uninstall } from "../_chunks/git-C6XPViK5.js";
1
+ export { t as aliases, n as builder, r as cleanup, i as command, a as describe, s as handler, c as install, l as partitionBranchesToPrune, u as status, d as sync, f as uninstall } from "../_chunks/git-0gR_dDCC.js";
@@ -3,32 +3,32 @@ import { t as api_exports } from "../_chunks/api-1MKsfpY3.js";
3
3
  import { n as api_keys_exports } from "../_chunks/api_keys-CTFHd5m_.js";
4
4
  import { n as ask_exports } from "../_chunks/ask-Xlek1Pxh.js";
5
5
  import { o as env_exports } from "../_chunks/env-DxcO3oJk.js";
6
- import { c as config_exports } from "../_chunks/config-BClSMzco.js";
6
+ import { c as config_exports } from "../_chunks/config-aBF_xpbX.js";
7
7
  import { u as projects_exports } from "../_chunks/projects-a3X4OFEJ.js";
8
- import { a as link_exports } from "../_chunks/link-n40BxbmK.js";
8
+ import { a as link_exports } from "../_chunks/link-CYwhNbA4.js";
9
9
  import { o as mcp_exports } from "../_chunks/mcp-SvqWzHnT.js";
10
10
  import { c as plugins_exports } from "../_chunks/plugins-BwUZQ6Ic.js";
11
11
  import { l as skills_exports } from "../_chunks/skills-Bv8oKKwE.js";
12
12
  import { t as bootstrap_exports } from "../_chunks/bootstrap-B73qVB39.js";
13
13
  import { r as branches_exports } from "../_chunks/branches-Bp-5z1lM.js";
14
14
  import { n as bucket_exports } from "../_chunks/bucket-D06bvDSa.js";
15
- import { n as checkout_exports } from "../_chunks/checkout-B_gbS0nD.js";
15
+ import { n as checkout_exports } from "../_chunks/checkout-Bw48iTay.js";
16
16
  import { o as claim_exports } from "../_chunks/claim-BVEwQ65H.js";
17
17
  import { o as connection_string_exports } from "../_chunks/connection_string-6WhV4WFx.js";
18
18
  import { a as credentials_exports } from "../_chunks/credentials-BMBNmW0t.js";
19
19
  import { r as data_api_exports } from "../_chunks/data_api-CHDwvMTG.js";
20
20
  import { s as databases_exports } from "../_chunks/databases-B-qY303S.js";
21
- import { r as deploy_exports } from "../_chunks/deploy-CJ22hy3i.js";
22
- import { s as dev_exports } from "../_chunks/dev-CSoQfCuS.js";
21
+ import { r as deploy_exports } from "../_chunks/deploy-CMYTjbf6.js";
22
+ import { s as dev_exports } from "../_chunks/dev-r0-8mPJk.js";
23
23
  import { i as diff_exports } from "../_chunks/diff-dnxneH0u.js";
24
24
  import { c as docs_exports } from "../_chunks/docs-BpLiSTmm.js";
25
25
  import { o as feedback_exports } from "../_chunks/feedback-mQmdTRFn.js";
26
26
  import { o as functions_exports } from "../_chunks/functions-PHaU-kRb.js";
27
- import { o as git_exports } from "../_chunks/git-C6XPViK5.js";
27
+ import { o as git_exports } from "../_chunks/git-0gR_dDCC.js";
28
28
  import { a as init_exports } from "../_chunks/init-D2fClHtC.js";
29
29
  import { o as inspect_exports } from "../_chunks/inspect-yFAb61qo.js";
30
30
  import { a as ip_allow_exports } from "../_chunks/ip_allow-DBdxNEUa.js";
31
- import { l as logs_exports } from "../_chunks/logs-BB4uvblR.js";
31
+ import { l as logs_exports } from "../_chunks/logs-Zf8mcRVE.js";
32
32
  import { a as neon_auth_exports } from "../_chunks/neon_auth-C4AXiUR6.js";
33
33
  import { a as open_exports } from "../_chunks/open-T2nI89Oh.js";
34
34
  import { c as operations_exports } from "../_chunks/operations-D7qGkKo3.js";
@@ -40,7 +40,7 @@ import { o as profile_exports } from "../_chunks/profile-CArcjyS4.js";
40
40
  import { s as realtime_exports } from "../_chunks/realtime-BwtzYf5a.js";
41
41
  import { a as set_context_exports } from "../_chunks/set_context-ompB6d2D.js";
42
42
  import { s as snapshots_exports } from "../_chunks/snapshots-DxNhjcco.js";
43
- import { a as status_exports } from "../_chunks/status-TDYLPWRO.js";
43
+ import { a as status_exports } from "../_chunks/status-Du6yqWxf.js";
44
44
  import { d as triggers_exports } from "../_chunks/triggers-BfvyeJUC.js";
45
45
  import { s as user_exports } from "../_chunks/user-D9mC430O.js";
46
46
  import { i as vpc_endpoints_exports } from "../_chunks/vpc_endpoints-C-Y4WK2M.js";
@@ -1 +1 @@
1
- export { t as builder, n as command, r as describe, i as handler, o as quoteFlagValue, s as runLink, c as shouldOfferConfigInit } from "../_chunks/link-n40BxbmK.js";
1
+ export { t as builder, n as command, r as describe, i as handler, o as quoteFlagValue, s as runLink, c as shouldOfferConfigInit } from "../_chunks/link-CYwhNbA4.js";
@@ -1 +1 @@
1
- export { t as assertReachableLogsPage, n as buildLogsQueryBody, r as builder, i as command, a as describe, o as escapeLogSingleLine, s as escapeLogTableCell, c as handler } from "../_chunks/logs-BB4uvblR.js";
1
+ export { t as assertReachableLogsPage, n as buildLogsQueryBody, r as builder, i as command, a as describe, o as escapeLogSingleLine, s as escapeLogTableCell, c as handler } from "../_chunks/logs-Zf8mcRVE.js";
@@ -0,0 +1,125 @@
1
+ import { NeonApiError } from "../api.js";
2
+ import { writer } from "../writer.js";
3
+ import { noPassthrough, single } from "../utils/flags.js";
4
+ import { branchIdFromProps } from "../utils/enrichers.js";
5
+ // src/commands/loki.ts
6
+ const LABEL_VALUES = /^label\/([a-zA-Z_][a-zA-Z0-9_]*)\/values$/;
7
+ const endpoint = (value) => {
8
+ const path = single("endpoint")(value);
9
+ if (path === void 0 || !(path === "query_range" || path === "labels" || LABEL_VALUES.test(path))) throw new Error("--endpoint must be query_range, labels, or label/<name>/values. See neon logs loki --help.");
10
+ return path;
11
+ };
12
+ const limit = (value) => {
13
+ if (value === void 0) return void 0;
14
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1) throw new Error("--limit must be a positive integer.");
15
+ return value;
16
+ };
17
+ const rangeQuery = ({ query }) => {
18
+ if (!query?.trim()) throw new Error("Pass a LogQL query, e.g. neon logs loki '{entity_type=\"function\"}'. See neon logs loki --help.");
19
+ return query;
20
+ };
21
+ const validate = (props) => {
22
+ if (props.endpoint === "query_range") {
23
+ rangeQuery(props);
24
+ return;
25
+ }
26
+ for (const name of ["limit", "direction"]) if (props[name] !== void 0) throw new Error(`--${name} applies only to --endpoint query_range.`);
27
+ };
28
+ const command = "loki [query]";
29
+ const describe = "Call the branch's Loki read API and return its JSON response";
30
+ const builder = (argv) => argv.usage("$0 logs loki [query] [options]").positional("query", {
31
+ describe: "LogQL expression. With a label endpoint, an optional stream selector that scopes the labels.",
32
+ type: "string",
33
+ coerce: single("query")
34
+ }).options({
35
+ "project-id": {
36
+ describe: "Project ID",
37
+ type: "string",
38
+ coerce: single("project-id")
39
+ },
40
+ branch: {
41
+ describe: "Branch ID or name (defaults to the project's default branch)",
42
+ type: "string",
43
+ coerce: single("branch")
44
+ },
45
+ since: {
46
+ describe: "Lookback window as a positive Go duration, e.g. 30m or 24h. Defaults to 1h for queries and 6h for label values. Explicit --start takes precedence.",
47
+ type: "string",
48
+ coerce: single("since")
49
+ },
50
+ start: {
51
+ describe: "Window start as RFC 3339 or Unix nanoseconds (kept as a string)",
52
+ type: "string",
53
+ coerce: single("start")
54
+ },
55
+ end: {
56
+ describe: "Window end as RFC 3339 or Unix nanoseconds (kept as a string). Defaults to now.",
57
+ type: "string",
58
+ coerce: single("end")
59
+ },
60
+ limit: {
61
+ describe: "Maximum number of log lines (query_range only); the server enforces its cap",
62
+ type: "number",
63
+ coerce: limit
64
+ },
65
+ direction: {
66
+ describe: "Timestamp order (query_range only): forward (oldest first) or backward (newest first)",
67
+ type: "string",
68
+ choices: ["forward", "backward"],
69
+ coerce: single("direction")
70
+ },
71
+ endpoint: {
72
+ describe: "Read endpoint: query_range, labels, or label/<name>/values",
73
+ type: "string",
74
+ default: "query_range",
75
+ coerce: endpoint
76
+ }
77
+ }).default("output", "json").middleware((args) => {
78
+ noPassthrough("logs loki")(args);
79
+ if (args.output !== "json" && args.output !== "yaml") throw new Error("--output must be json or yaml for neon logs loki.");
80
+ validate(args);
81
+ }, true).strict().example("$0 logs loki '{entity_type=\"function\"} |= \"error\"' --since 30m --limit 100", "Query function logs with a bounded time window and line count").example("$0 logs loki --endpoint labels", "Discover stream labels").example("$0 logs loki --endpoint label/service_name/values --since 6h", "Discover service names before choosing a selector").example("$0 logs loki '{entity_type=\"function\"}' --endpoint label/severity_text/values", "List the severities function logs carry").example("$0 logs loki '{entity_type=\"function\"}' --project-id <id> --branch <id|name> --start 2026-11-01T00:00:00Z --end 2026-11-01T01:00:00Z", "Query an explicit branch and absolute time window").epilogue([
82
+ "query_range requires a LogQL query and accepts --since, --start, --end, --limit and --direction. labels and label/<name>/values accept the time bounds and an optional stream selector without line filters. Use entity_type, not source, in Loki selectors.",
83
+ "Output: --output json (default) or --output yaml. data.result groups lines by stream labels; each values entry is [timestamp, line], with timestamps kept as nanosecond strings. There is no continuation cursor: a result with --limit lines, or the server's cap of 10,000, may be incomplete, and the cap adds no warnings entry. Narrow the time window or selector to retrieve complete results.",
84
+ "Neon supports stream selectors and line filters; metric queries, parser stages and live tailing are unsupported. Instant queries are unsupported.",
85
+ "For structured filters, human-readable tables and cursor pagination, use neon logs query --help.",
86
+ "Uses /telemetry/v1 on the origin selected by --api-host or NEON_API_HOST. Availability depends on the project's region and telemetry rollout. See https://neon.com/docs/cli/logs#loki-read-api"
87
+ ].join("\n\n"));
88
+ const handler = async (props) => {
89
+ const branchId = await branchIdFromProps(props);
90
+ const { fromSdkError, getNeonClient } = await import("../neon_client.js");
91
+ const { loki } = getNeonClient(props).logs;
92
+ const scope = {
93
+ projectId: props.projectId,
94
+ branchId,
95
+ since: props.since,
96
+ start: props.start,
97
+ end: props.end
98
+ };
99
+ const label = LABEL_VALUES.exec(props.endpoint)?.[1];
100
+ const data = await (props.endpoint === "query_range" ? loki.queryRange({
101
+ ...scope,
102
+ query: rangeQuery(props),
103
+ limit: props.limit,
104
+ direction: props.direction
105
+ }) : label === void 0 ? loki.labels({
106
+ ...scope,
107
+ query: props.query
108
+ }) : loki.labelValues({
109
+ ...scope,
110
+ name: label,
111
+ query: props.query
112
+ })).catch((error) => {
113
+ const failure = fromSdkError(error, new URL("/telemetry/v1", props.apiHost ?? "https://console.neon.tech/api/v2").toString());
114
+ if (!(failure instanceof NeonApiError) || failure.status === void 0 || failure.status < 400) throw failure;
115
+ throw new NeonApiError(`Loki request failed with status ${failure.status}`, {
116
+ status: failure.status,
117
+ statusText: failure.statusText,
118
+ data: failure.data,
119
+ headers: failure.headers,
120
+ requestPath: failure.requestPath
121
+ });
122
+ });
123
+ writer({ output: props.output }).end(data, { fields: [] });
124
+ };
125
+ export { builder, command, describe, handler };
@@ -97,7 +97,7 @@ const commandManifest = [
97
97
  },
98
98
  {
99
99
  command: "logs",
100
- describe: "Query branch logs",
100
+ describe: "Query branch logs with structured filters, LogQL, or the Loki API",
101
101
  load: () => import("./logs.js")
102
102
  },
103
103
  {
@@ -1 +1 @@
1
- export { t as builder, n as command, r as describe, i as handler } from "../_chunks/status-TDYLPWRO.js";
1
+ export { t as builder, n as command, r as describe, i as handler } from "../_chunks/status-Du6yqWxf.js";
@@ -1,7 +1,7 @@
1
1
  import { loadProjectConfig } from "../project.js";
2
2
  import { existsSync } from "node:fs";
3
3
  import { dirname, isAbsolute, resolve } from "node:path";
4
- import { resolveConfig } from "@neon/config";
4
+ import { assertFunctionEnv, authoredFunctions, resolveConfig, resolveFunctionEnv } from "@neon/config";
5
5
  // src/dev/functions.ts
6
6
  /**
7
7
  * Load `neon.ts` (if any) and resolve the list of functions it declares into
@@ -16,6 +16,7 @@ const resolveFunctionsFromConfig = async (cwd, branchName, contextFile) => {
16
16
  const loaded = await loadNeonConfig(cwd, contextFile);
17
17
  if (!loaded) return null;
18
18
  const { config, configDir, configPath } = loaded;
19
+ assertFunctionEnv(config, "development");
19
20
  return {
20
21
  configPath,
21
22
  functions: (resolveConfig(config, {
@@ -35,20 +36,31 @@ const resolveFunctionsFromConfig = async (cwd, branchName, contextFile) => {
35
36
  const findConfigFunctionBySource = async (cwd, source, contextFile) => {
36
37
  const loaded = await loadNeonConfig(cwd, contextFile);
37
38
  if (!loaded) return void 0;
38
- return (resolveConfig(loaded.config, {
39
+ const match = (resolveConfig(loaded.config, {
39
40
  name: "local",
40
41
  exists: false
41
- }).preview?.functions ?? []).map((fn) => toPlannedFunction(fn, resolveFunctionSource(fn.source, loaded.configDir))).find((fn) => fn.source === source);
42
+ }).preview?.functions ?? []).find((fn) => resolveFunctionSource(fn.source, loaded.configDir) === source);
43
+ if (!match) return void 0;
44
+ const served = Object.entries(authoredFunctions(loaded.config) ?? {}).filter(([slug]) => slug === match.slug);
45
+ assertFunctionEnv({ functions: Object.fromEntries(served) }, "development");
46
+ return toPlannedFunction(match, source);
42
47
  };
43
48
  const resolveFunctionSource = (source, configDir) => isAbsolute(source) ? source : resolve(configDir, source);
44
49
  const toPlannedFunction = (fn, source) => {
45
50
  const port = devPort(fn.dev);
51
+ const declaredEnv = resolveFunctionEnv(fn.envVars, "development").env;
52
+ const unsetEnv = Object.entries(fn.envVars ?? {}).filter(([key, declaration]) => !(key in declaredEnv) && declaration.onUndefined !== "skip").map(([key]) => key);
46
53
  return {
47
54
  slug: fn.slug,
48
55
  name: fn.name,
49
56
  source,
50
57
  ...port !== void 0 ? { port } : {},
51
- env: { ...fn.env },
58
+ env: {
59
+ ...fn.env,
60
+ ...declaredEnv
61
+ },
62
+ declaredEnv,
63
+ ...unsetEnv.length > 0 ? { unsetEnv } : {},
52
64
  ...fn.externalPackages ? { externalPackages: fn.externalPackages.map((pkg) => pkg.name) } : {},
53
65
  ...fn.bundler !== "esbuild" ? { bundler: fn.bundler } : {}
54
66
  };
@@ -4,9 +4,10 @@ import { c as ensureAuth } from "../_chunks/auth-rup6nemJ.js";
4
4
  import { recoverFrom401 } from "../auth_recovery.js";
5
5
  import { loadProjectConfig } from "../project.js";
6
6
  import { loadEnvFileIntoProcess } from "../env_file.js";
7
- import { r as applyCmd } from "../_chunks/config-BClSMzco.js";
7
+ import { r as applyCmd } from "../_chunks/config-aBF_xpbX.js";
8
8
  import { authContext } from "./auth.js";
9
9
  import { existsSync } from "node:fs";
10
+ import { missingFunctionEnv } from "@neon/config";
10
11
  // src/init/deploy.ts
11
12
  /**
12
13
  * The function env keys neon.ts reads that neither `envFile` nor the environment sets.
@@ -15,12 +16,13 @@ import { existsSync } from "node:fs";
15
16
  const missingDeployEnv = async (options) => {
16
17
  const applied = existsSync(options.envFile) ? loadEnvFileIntoProcess(options.envFile) : [];
17
18
  try {
18
- const { omittedFunctionEnv } = await loadProjectConfig({
19
+ const { config, omittedFunctionEnv } = await loadProjectConfig({
19
20
  cwd: options.cwd,
20
21
  contextFile: options.contextFile,
21
22
  unsetFunctionEnv: "omit"
22
23
  });
23
- return omittedFunctionEnv;
24
+ const declared = missingFunctionEnv(config, "deploy").map(({ key }) => key);
25
+ return [.../* @__PURE__ */ new Set([...omittedFunctionEnv, ...declared])];
24
26
  } finally {
25
27
  for (const key of applied) delete process.env[key];
26
28
  }
package/dist/init/link.js CHANGED
@@ -4,7 +4,7 @@ import "../config.js";
4
4
  import "../auth.js";
5
5
  import { c as ensureAuth } from "../_chunks/auth-rup6nemJ.js";
6
6
  import { recoverFrom401 } from "../auth_recovery.js";
7
- import { s as runLink } from "../_chunks/link-n40BxbmK.js";
7
+ import { s as runLink } from "../_chunks/link-CYwhNbA4.js";
8
8
  // src/init/link.ts
9
9
  const isUnauthorized = (error) => isNeonApiError(error) && error.status === 401;
10
10
  const authenticationFailed = () => /* @__PURE__ */ new Error("Authentication failed.");
package/dist/init/run.js CHANGED
@@ -14,8 +14,8 @@ import { getAgentDisplayName } from "../mcp/agents.js";
14
14
  import { missingPluginsCommands, pluginsCommandProblemText, pluginsInstallableAgents, unusablePluginsCommands } from "../plugins/targets.js";
15
15
  import { AGENTS_NOT_INSTALLED, CANCELLED_BODY, CLAIMABLE_ACCOUNT_FLAGS, CLAIMABLE_ALREADY_LINKED, CLAIMABLE_MCP_API_KEY, CLAIMABLE_NO_LINK, MCP_API_KEY_NEEDS_AUTH, MCP_SCOPED_NEEDS_PROJECT, NON_TTY_LINK_NEEDS_AUTH, NO_AGENTS_FALLBACK_STATUS, PROGRESS, PROJECT_PINNED_OFFLINE, claimableNext, claimableThenServicesNext, configInitNext, envPullFailedNext, existingConfigNext, installFailedNext, mcpAfterLinkNext, mcpConfigLocationSkipped, mcpConfigLocationUnavailable, mcpKeyFailedNext, namedAgentsUnavailable, newConfigNext, offlinePinNext, skippedLinkNext, toolingFailedNext, unattendedUnauthedNext } from "./copy.js";
16
16
  import { agentsRowValue, configRowValue, formatInitDone, headingForKind, printInitBanner, printInitDone, printInitProgress, projectRowValue, shouldPrintInitBanner } from "./chrome.js";
17
- import { h as initCmd, t as ConfigInstallFailed } from "../_chunks/config-BClSMzco.js";
18
- import { o as quoteFlagValue, s as runLink } from "../_chunks/link-n40BxbmK.js";
17
+ import { h as initCmd, t as ConfigInstallFailed } from "../_chunks/config-aBF_xpbX.js";
18
+ import { o as quoteFlagValue, s as runLink } from "../_chunks/link-CYwhNbA4.js";
19
19
  import { runAuthenticatedLink } from "./link.js";
20
20
  import { mcpInstallableAgents } from "../mcp/targets.js";
21
21
  import { skillsInstallableAgents } from "../skills/targets.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "9.0.0",
3
+ "version": "9.2.0",
4
4
  "description": "CLI tool for Neon, the cloud backend primitives built around Lakebase Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -73,10 +73,10 @@
73
73
  "yaml": "^2.9.0",
74
74
  "yargs": "17.7.2",
75
75
  "yoctocolors": "^2.1.2",
76
- "@neon/config-runtime": "1.11.8",
77
- "@neon/config": "1.12.0",
76
+ "@neon/config": "1.13.0",
77
+ "@neon/config-runtime": "1.12.0",
78
78
  "@neon/realtime": "0.2.0",
79
- "@neon/sdk": "7.10.0"
79
+ "@neon/sdk": "7.11.0"
80
80
  },
81
81
  "optionalDependencies": {
82
82
  "@napi-rs/keyring": "1.3.0",
@@ -113,10 +113,10 @@
113
113
  "typescript": "^5.9.0",
114
114
  "vitest": "^3.0.9",
115
115
  "@neon-internals/cli-core": "0.0.0",
116
- "@neon-internals/env-core": "0.0.46",
116
+ "@neon-internals/env-core": "0.0.48",
117
117
  "@neon/e2e-harness": "0.0.0",
118
- "@neon/functions": "0.11.0",
119
- "@neon/env": "2.0.0"
118
+ "@neon/env": "2.1.0",
119
+ "@neon/functions": "0.11.0"
120
120
  },
121
121
  "publishConfig": {
122
122
  "access": "public",