@neondatabase/env 1.0.0 → 1.1.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 (59) hide show
  1. package/README.md +21 -1
  2. package/dist/cli.js +1304 -6
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{_shared/env-core/env.js → env.js} +62 -41
  5. package/dist/env.js.map +1 -0
  6. package/dist/index.d.ts +528 -3
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +197 -2
  9. package/dist/{lib/parse-env.js.map → index.js.map} +1 -1
  10. package/package.json +12 -7
  11. package/dist/_shared/auth_selection.d.ts +0 -95
  12. package/dist/_shared/auth_selection.d.ts.map +0 -1
  13. package/dist/_shared/auth_selection.js +0 -85
  14. package/dist/_shared/auth_selection.js.map +0 -1
  15. package/dist/_shared/credentials.d.ts +0 -186
  16. package/dist/_shared/credentials.d.ts.map +0 -1
  17. package/dist/_shared/credentials.js +0 -190
  18. package/dist/_shared/credentials.js.map +0 -1
  19. package/dist/_shared/env-core/env.d.ts +0 -424
  20. package/dist/_shared/env-core/env.d.ts.map +0 -1
  21. package/dist/_shared/env-core/env.js.map +0 -1
  22. package/dist/_shared/env-core/reuse-secrets.d.ts +0 -95
  23. package/dist/_shared/env-core/reuse-secrets.d.ts.map +0 -1
  24. package/dist/_shared/env-core/reuse-secrets.js +0 -181
  25. package/dist/_shared/env-core/reuse-secrets.js.map +0 -1
  26. package/dist/_shared/paths.d.ts +0 -116
  27. package/dist/_shared/paths.d.ts.map +0 -1
  28. package/dist/_shared/paths.js +0 -153
  29. package/dist/_shared/paths.js.map +0 -1
  30. package/dist/_shared/profiles.d.ts +0 -145
  31. package/dist/_shared/profiles.d.ts.map +0 -1
  32. package/dist/_shared/profiles.js +0 -228
  33. package/dist/_shared/profiles.js.map +0 -1
  34. package/dist/_shared/secure_file.d.ts +0 -25
  35. package/dist/_shared/secure_file.d.ts.map +0 -1
  36. package/dist/_shared/secure_file.js +0 -43
  37. package/dist/_shared/secure_file.js.map +0 -1
  38. package/dist/config/dist/lib/define-config.d.ts +0 -20
  39. package/dist/config/dist/lib/define-config.d.ts.map +0 -1
  40. package/dist/config/dist/lib/neon-api.d.ts +0 -375
  41. package/dist/config/dist/lib/neon-api.d.ts.map +0 -1
  42. package/dist/config/dist/lib/types.d.ts +0 -603
  43. package/dist/config/dist/lib/types.d.ts.map +0 -1
  44. package/dist/config/dist/v1.d.ts +0 -5
  45. package/dist/lib/cli/commands.d.ts +0 -68
  46. package/dist/lib/cli/commands.d.ts.map +0 -1
  47. package/dist/lib/cli/commands.js +0 -233
  48. package/dist/lib/cli/commands.js.map +0 -1
  49. package/dist/lib/cli/resolve-api-key.d.ts +0 -29
  50. package/dist/lib/cli/resolve-api-key.d.ts.map +0 -1
  51. package/dist/lib/cli/resolve-api-key.js +0 -74
  52. package/dist/lib/cli/resolve-api-key.js.map +0 -1
  53. package/dist/lib/cli/resolve-context.d.ts +0 -34
  54. package/dist/lib/cli/resolve-context.d.ts.map +0 -1
  55. package/dist/lib/cli/resolve-context.js +0 -88
  56. package/dist/lib/cli/resolve-context.js.map +0 -1
  57. package/dist/lib/parse-env.d.ts +0 -95
  58. package/dist/lib/parse-env.d.ts.map +0 -1
  59. package/dist/lib/parse-env.js +0 -198
@@ -1,603 +0,0 @@
1
- //#region ../config/dist/lib/types.d.ts
2
- //#region src/lib/types.d.ts
3
- /**
4
- * Valid Neon Compute Unit values.
5
- * Most plans support 0.25, 0.5, 1, 2, 4, 8. Higher values may be available on Business plans.
6
- */
7
- type ComputeUnit = 0.25 | 0.5 | 1 | 2 | 4 | 8;
8
- /** Time units accepted in a {@link DurationString}: seconds, minutes, hours, days, weeks. */
9
- type DurationUnit = "s" | "m" | "h" | "d" | "w";
10
- /**
11
- * A Neon duration string: a positive integer **followed by a unit** — `s` (seconds),
12
- * `m` (minutes), `h` (hours), `d` (days), or `w` (weeks). Used by
13
- * {@link ComputeSettings.suspendTimeout} and {@link BranchTuning.ttl}.
14
- *
15
- * A **unit is required**: a bare numeric string like `"7"` is rejected at the type level. To
16
- * express a raw number of seconds, pass a `number` (`300`) — not a string (`"300"`). This
17
- * removes the old ambiguity where `"7"` silently meant 7 *seconds* instead of, say, `"7d"`.
18
- *
19
- * @example "5m" // 5 minutes
20
- * @example "1h" // 1 hour
21
- * @example "7d" // 7 days
22
- */
23
- type DurationString = `${number}${DurationUnit}`;
24
- /**
25
- * Autocomplete suggestions for {@link ComputeSettings.suspendTimeout}. Every value sits inside
26
- * the Neon API's allowed scale-to-zero band: **60s–604800s** (1 minute – 1 week). This is *not*
27
- * a closed set — the field also accepts any other {@link DurationString} or a `number` of
28
- * seconds; out-of-range values type-check but are rejected at apply time.
29
- */
30
- type SuspendTimeoutSuggestion = "1m" | "5m" | "15m" | "30m" | "1h" | "6h" | "12h" | "1d" | "7d";
31
- /**
32
- * Autocomplete suggestions for {@link BranchTuning.ttl}. Every value sits within the Neon API's
33
- * branch-expiration limit (**max 30 days** from creation; the Console's own presets are 1h / 1d
34
- * / 7d). This is *not* a closed set — the field also accepts any other {@link DurationString} or
35
- * a `number` of seconds; values over 30 days are rejected at apply time.
36
- */
37
- type TtlSuggestion = "1h" | "6h" | "12h" | "1d" | "3d" | "7d" | "14d" | "30d";
38
- /**
39
- * Compose a field's duration type: its curated autocomplete `Suggestions` plus the open
40
- * `DurationString` template (so any `<integer><unit>` string still type-checks) and a `number`
41
- * of seconds. Intersecting the template arm with `NonNullable<unknown>` stops TypeScript from
42
- * collapsing the literal suggestions into the template, which is what preserves the autocomplete.
43
- */
44
- type DurationField<Suggestions extends DurationString> = Suggestions | (DurationString & NonNullable<unknown>) | number;
45
- /**
46
- * Compute settings applied to the read/write endpoint of a branch.
47
- *
48
- * Mirrors the subset of {@link https://api-docs.neon.tech/reference/getting-started-with-neon-api Neon endpoint}
49
- * fields that we expose as IaC primitives. Anything left undefined falls back to the project's
50
- * `default_endpoint_settings` (which themselves fall back to Neon defaults).
51
- */
52
- interface ComputeSettings {
53
- /**
54
- * Minimum number of Compute Units. Set to 0.25 for true scale-to-zero.
55
- * @example 0.25 // scale-to-zero
56
- * @example 1 // always-on with 1 CU minimum
57
- */
58
- autoscalingLimitMinCu?: ComputeUnit;
59
- /**
60
- * Maximum number of Compute Units for autoscaling.
61
- * @example 2
62
- * @example 8
63
- */
64
- autoscalingLimitMaxCu?: ComputeUnit;
65
- /**
66
- * How long an idle compute waits before suspending (Neon's scale-to-zero). Accepts a
67
- * {@link DurationString} (autocompletes common values), a number of seconds, or `false`.
68
- *
69
- * - `false` — never suspend (always-on compute)
70
- * - {@link DurationString} — e.g. `"5m"`; autocompletes the in-range values `"1m"`, `"5m"`,
71
- * `"15m"`, `"30m"`, `"1h"`, `"6h"`, `"12h"`, `"1d"`, `"7d"`, and accepts any other
72
- * `<integer><unit>` (units: `s`, `m`, `h`, `d`, `w`). A **unit is required** — for raw
73
- * seconds pass a `number`, not a string.
74
- * - `number` — custom timeout in **seconds**, must be in `60`–`604800` (1 minute to 1 week)
75
- * - `undefined` — use the Neon default (currently 300s / 5 minutes)
76
- *
77
- * Whichever form you use, the resolved timeout must fall in `60`–`604800` seconds (the Neon
78
- * API limit); the suggestions are all within that band, anything else is checked at apply.
79
- *
80
- * @example false // never suspend (always-on)
81
- * @example "5m" // suspend after 5 minutes idle
82
- * @example "1h" // suspend after 1 hour idle
83
- * @example 300 // 5 minutes, expressed in seconds
84
- */
85
- suspendTimeout?: false | DurationField<SuspendTimeoutSuggestion>;
86
- }
87
- /**
88
- * Read-only descriptor of the branch a {@link Config} policy is being evaluated for — the
89
- * `branch` argument passed to your `defineConfig({ branch: (branch) => … })` closure. It describes
90
- * **which** branch this invocation decides for; it is not a live branch handle and must not
91
- * be mutated. Switch on its fields and return the desired {@link BranchConfig}.
92
- */
93
- interface BranchTarget {
94
- /** Branch name being evaluated. For `branch dev`, this is the generated branch name. */
95
- name: string;
96
- /** Neon branch id when the branch already exists. Undefined during pre-create eval. */
97
- id?: string;
98
- /** Whether this branch already exists on Neon. */
99
- exists: boolean;
100
- /** Parent branch id from Neon when known. */
101
- parentId?: string;
102
- /** Whether Neon marks this branch as the project default. */
103
- isDefault?: boolean;
104
- /** Whether Neon currently marks this branch protected. */
105
- isProtected?: boolean;
106
- /** Current expiration timestamp from Neon, when set. */
107
- expiresAt?: string;
108
- }
109
- /**
110
- * Object form of a branch-scoped service toggle. `{}` or `{ enabled: true }` enables it;
111
- * `{ enabled: false }` opts out. Used as the object half of {@link ServiceToggleInput}.
112
- */
113
- interface ServiceToggle {
114
- /** Defaults to `true` when the service namespace is present. Set `false` to opt out. */
115
- enabled?: boolean;
116
- }
117
- /**
118
- * How a branch-scoped service (Neon Auth, Data API, AI Gateway) is toggled in a policy.
119
- *
120
- * - `true` / `{}` / `{ enabled: true }` — enabled.
121
- * - `false` / `{ enabled: false }` — disabled.
122
- * - omitted (`undefined`) — not part of the policy at all.
123
- *
124
- * These toggles are **static** (they live in the top-level `defineConfig({ … })` object,
125
- * not in the per-branch `branch` closure) so the secret set they imply can be derived at
126
- * the type level — that's what makes `NeonEnv<typeof config>` exact.
127
- */
128
- type ServiceToggleInput = boolean | ServiceToggle;
129
- /**
130
- * Resolve a **static** service toggle (`true` / `false` / `{ enabled?: boolean }` / object /
131
- * `undefined`) to a type-level boolean. The tuple wrapping (`[T] extends […]`) disables
132
- * distribution so a union/`undefined` is judged as a single unit:
133
- *
134
- * - `false` / `{ enabled: false }` / `undefined` → `false`
135
- * - `true` / `{ enabled: true }` / any other object (`{}`, `{ enabled?: boolean }`) → `true`
136
- * (a present toggle defaults to enabled)
137
- * - the bare `boolean | … | undefined` (no literal info) → `false`
138
- *
139
- * Shared by the {@link Config} static cross-field checks and the `@neon/env`
140
- * `NeonEnv` namespace derivation, so both read "is this service on?" identically.
141
- */
142
-
143
- interface PostgresConfig {
144
- computeSettings?: ComputeSettings;
145
- }
146
- /**
147
- * Authentication providers a Data API integration can verify JWTs against, as written in
148
- * `neon.ts`. Friendly authoring values (mapped to the Neon API's `neon_auth` / `external`
149
- * at the API boundary):
150
- *
151
- * - `"neon"` — verify tokens minted by **Neon Auth** on the same branch. Neon supplies the
152
- * JWKS URL / provider wiring for you, so the `jwksUrl` / `providerName` / `jwtAudience`
153
- * fields are forbidden (a type error) on this variant — and the policy must also enable
154
- * top-level `auth` (Neon Auth) so the tokens exist.
155
- * - `"external"` — verify tokens from a third-party IdP (Clerk, Stytch, Auth0, …). You
156
- * provide `jwksUrl` (and optionally `providerName` / `jwtAudience`).
157
- */
158
- declare const DATA_API_AUTH_PROVIDERS: readonly ["neon", "external"];
159
- type DataApiAuthProvider = (typeof DATA_API_AUTH_PROVIDERS)[number];
160
- /**
161
- * Reusable runtime settings for a Data API integration (the Neon API `DataAPISettings`,
162
- * camelCased to match the rest of `neon.ts`). Every field is optional; omitted fields keep
163
- * the Neon defaults shown below. These are the **only** Data API fields that can change on
164
- * an already-enabled integration — drift here is reconciled as an *update* (requires
165
- * `updateExisting` / `--update-existing`); the create-only auth wiring above cannot.
166
- */
167
- interface DataApiSettings {
168
- /** Enable the aggregates feature (`db_aggregates_enabled`). Default `true`. */
169
- dbAggregatesEnabled?: boolean;
170
- /** Database role used for anonymous requests (`db_anon_role`). Default `"anonymous"`. */
171
- dbAnonRole?: string;
172
- /** Extra schemas appended to the search path (`db_extra_search_path`). */
173
- dbExtraSearchPath?: string;
174
- /** Maximum rows returned in a single request (`db_max_rows`). */
175
- dbMaxRows?: number;
176
- /** Schemas exposed via the API (`db_schemas`). Default `["public"]`. */
177
- dbSchemas?: string[];
178
- /** JWT claim key used for role extraction (`jwt_role_claim_key`). Default `".role"`. */
179
- jwtRoleClaimKey?: string;
180
- /** Maximum lifetime of the JWT cache, in seconds (`jwt_cache_max_lifetime`). */
181
- jwtCacheMaxLifetime?: number;
182
- /** OpenAPI spec mode (`openapi_mode`). Default `"disabled"`. */
183
- openapiMode?: "ignore-privileges" | "disabled";
184
- /** CORS allowed origins (`server_cors_allowed_origins`). */
185
- serverCorsAllowedOrigins?: string;
186
- /** Emit server-timing headers (`server_timing_enabled`). */
187
- serverTimingEnabled?: boolean;
188
- }
189
- /** Fields shared by every {@link DataApiConfig} variant. */
190
- interface DataApiConfigBase {
191
- /** Defaults to `true` when the `dataApi` namespace is present. Set `false` to opt out. */
192
- enabled?: boolean;
193
- /** Reusable runtime settings. Drift here is reconciled as an update. */
194
- settings?: DataApiSettings;
195
- }
196
- /**
197
- * Data API verified by **Neon Auth** (`authProvider: "neon"`, the default). The external
198
- * IdP fields are statically forbidden (`?: never`) because Neon supplies them; declaring any
199
- * of them is a type error directing you to `authProvider: "external"`.
200
- */
201
- interface DataApiNeonAuthConfig extends DataApiConfigBase {
202
- authProvider?: "neon";
203
- /** Forbidden with `authProvider: "neon"` — Neon provides the JWKS URL. */
204
- jwksUrl?: never;
205
- /** Forbidden with `authProvider: "neon"` — the provider is Neon Auth. */
206
- providerName?: never;
207
- /** Forbidden with `authProvider: "neon"` — Neon manages the audience. */
208
- jwtAudience?: never;
209
- }
210
- /**
211
- * Data API verified by an **external** IdP (`authProvider: "external"`). You provide the
212
- * JWKS URL (and optionally a provider label / expected audience).
213
- */
214
- interface DataApiExternalAuthConfig extends DataApiConfigBase {
215
- authProvider: "external";
216
- /** URL that publishes the IdP's JWKS (JSON Web Key Set). */
217
- jwksUrl?: string;
218
- /** Human label for the IdP (e.g. "Clerk", "Stytch", "Auth0"). */
219
- providerName?: string;
220
- /**
221
- * Expected `aud` claim. ⚠️ This only **rejects** tokens carrying a *different* audience;
222
- * tokens with no `aud` claim are still accepted.
223
- */
224
- jwtAudience?: string;
225
- }
226
- /**
227
- * Object form of the `dataApi` toggle. A discriminated union on {@link DataApiAuthProvider}:
228
- * the `"neon"` variant forbids the external-IdP fields, the `"external"` variant allows them.
229
- */
230
- type DataApiConfig = DataApiNeonAuthConfig | DataApiExternalAuthConfig;
231
- /**
232
- * How the Data API is toggled in a policy: a bare boolean (like the other service toggles)
233
- * or the richer {@link DataApiConfig} object. `true` / `{}` / `{ enabled: true }` enable it
234
- * with Neon defaults; `false` / `{ enabled: false }` opt out.
235
- */
236
- type DataApiInput = boolean | DataApiConfig;
237
- /**
238
- * Supported function runtimes. Mirrors the Neon Functions deploy API `runtime` enum.
239
- * Only `nodejs24` exists today; kept as a union so adding runtimes later is a
240
- * non-breaking, type-checked change.
241
- */
242
- type FunctionRuntime = "nodejs24";
243
- /**
244
- * Local-development settings for a function, used by `neon dev` when it serves every
245
- * function declared in `neon.ts` (i.e. invoked with no `--source`). Never affects deploy.
246
- */
247
- interface FunctionDevConfig {
248
- /**
249
- * Port the local server binds. Bound exactly (and `neon dev` fails loudly if it is taken)
250
- * when set; a free port is found automatically when omitted.
251
- */
252
- port?: number;
253
- }
254
- /**
255
- * The object form of an {@link FunctionDef.externalPackages} entry, for the one case the
256
- * bare string cannot express: externalizing a package without shipping its files.
257
- */
258
- interface ExternalPackageDef {
259
- /** Package name, optionally with a subpath: `sharp`, `@scope/pkg`, `pkg/sub`. */
260
- name: string;
261
- /**
262
- * Whether the package's real files ship into the deployed archive next to the bundle.
263
- *
264
- * Defaults to `true`, which is the state where the import resolves and the function
265
- * works. Set it to `false` only for a package the function never reaches: nothing is
266
- * shipped for it, so reaching it throws `Cannot find module` at invoke.
267
- */
268
- includeFiles?: boolean;
269
- }
270
- /**
271
- * One entry of {@link FunctionDef.externalPackages}. A bare string is the common form and
272
- * ships the package's files; {@link ExternalPackageDef} exists to turn that off.
273
- */
274
- type ExternalPackageEntry = string | ExternalPackageDef;
275
- /**
276
- * An {@link ExternalPackageEntry} with its default applied, as every consumer downstream of
277
- * `resolveConfig` reads it.
278
- */
279
- interface ResolvedExternalPackage {
280
- /** Package name as declared, subpath included. */
281
- name: string;
282
- /** Whether this package's files are staged into the archive. */
283
- includeFiles: boolean;
284
- }
285
- /**
286
- * Static definition of a Neon Function (Preview feature). Declares that the function
287
- * **exists** on every branch; its branch-unique slug is the **record key** in
288
- * {@link PreviewInput.functions} (not a field here), so slugs are statically enumerable,
289
- * cannot duplicate, and the `branch` closure can only tune slugs that are declared here.
290
- *
291
- * A function is invoked like a Cloudflare/Vercel handler — its source module
292
- * `export default { fetch }` or `export async function handler(req): Response`. The
293
- * `source` path is bundled (esbuild) and uploaded as a deployment; the newest deployment
294
- * becomes active.
295
- *
296
- * Runtime tuning is **not** here — it varies per branch and lives in the `branch` closure
297
- * (see {@link FunctionTuning}). Memory is fixed by the platform policy for now and is not
298
- * user-configurable.
299
- */
300
- interface FunctionDef {
301
- /** Free-form display name. @example "Hello World" */
302
- name: string;
303
- /**
304
- * Path to the function's entry module, **relative to `neon.ts`** (or absolute). The
305
- * module's default export (`{ fetch }`) or `handler` export is the function entry. This
306
- * path is resolved against the loaded `neon.ts` location and bundled with esbuild at
307
- * deploy time.
308
- *
309
- * We require a string path rather than an imported handler because a JS function value
310
- * carries no reference back to its source file, so esbuild has nothing to bundle from.
311
- * @example "./functions/hello-world.ts"
312
- */
313
- source: string;
314
- /**
315
- * Environment variables injected into the deployed function, keyed by the var name the
316
- * function reads at runtime. The **keys** are static (preserved at the type level so
317
- * `parseEnv(config, "<slug>").function.<key>` is typed); the **values** are arbitrary
318
- * strings evaluated when `neon.ts` is loaded (typically `process.env.X`) and uploaded
319
- * at `config apply`. Every value must be a defined string — a `process.env.X` that is
320
- * `undefined` (unset) errors at validation time rather than silently shipping
321
- * `undefined`.
322
- * @example { resendApiKey: process.env.RESEND_API_KEY ?? "" }
323
- */
324
- env?: Record<string, string>;
325
- /**
326
- * Ship a dependency's real files into the deployed archive instead of bundling it —
327
- * `sharp` and other packages backed by a native binary.
328
- *
329
- * The deploy-time equivalent of Next.js's `serverExternalPackages`. Every entry is passed
330
- * to esbuild's `external`, so the import survives into the bundle instead of being
331
- * followed, and the package's own files are shipped beside the bundle so that import
332
- * resolves.
333
- *
334
- * Reach for this when bundling a package is impossible rather than merely undesirable.
335
- * The case that comes up is a package backed by a native `.node` binary: the binary is a
336
- * compiled object the platform loads from a real path, so no bundler can inline it.
337
- * `sharp` is the common one, and it does not even fail at build time — it loads its
338
- * binary through `createRequire`, which esbuild does not follow, so it bundles cleanly
339
- * and then fails at invoke with "Could not load the sharp module".
340
- *
341
- * ```ts
342
- * externalPackages: ["sharp"]
343
- * ```
344
- *
345
- * Each declared package is installed for the Functions runtime target — **linux-arm64,
346
- * glibc** — into a throwaway directory, traced for the files it actually reaches, and
347
- * copied into the archive under `node_modules/` with its directory layout preserved. That
348
- * layout is load-bearing rather than cosmetic: a `.node` addon locates its sibling shared
349
- * libraries relative to its own directory, so a flattened tree fails to load.
350
- *
351
- * Your own `node_modules` is never read for these files or modified. Its binaries are
352
- * built for your machine rather than the deploy target, and a cross-platform install does
353
- * not survive your next plain `npm install`, so the target's packages are resolved fresh
354
- * on each deploy.
355
- *
356
- * Requirements, all reported at deploy time rather than at invoke: the package must
357
- * publish a linux-arm64 glibc build (`sharp` and most `@napi-rs/*` packages do; anything
358
- * compiled from source at install time does not), `npm` must be on `PATH`, and the
359
- * archive must stay inside the deploy size limits — native binaries are large.
360
- *
361
- * ### Excluding a package's files
362
- *
363
- * `includeFiles: false` externalizes the import without shipping anything, which is the
364
- * escape hatch for a package that cannot be staged — no build for the target, or too
365
- * large — and that the function never actually reaches:
366
- *
367
- * ```ts
368
- * externalPackages: ["sharp", { name: "canvas", includeFiles: false }]
369
- * ```
370
- *
371
- * **An excluded package is not resolvable at runtime.** Nothing is shipped for it, so it
372
- * throws `Cannot find module` if the function reaches it. It unblocks an import that is
373
- * never evaluated; it does not make a dependency usable.
374
- *
375
- * Entries are package names, optionally with a subpath (`pkg`, `@scope/pkg`, `pkg/sub`),
376
- * matching esbuild. A relative or absolute path is rejected at validation time: those are
377
- * local modules, and a local module that cannot be bundled is a different problem. Files
378
- * are staged per package, so a subpath narrows what esbuild leaves unresolved without
379
- * narrowing what ships.
380
- *
381
- * Under `neon dev` the list only keeps the package out of the bundle — nothing is
382
- * installed or copied, and it resolves from your own `node_modules` against your host
383
- * architecture, which is what you want locally.
384
- * @example ["sharp", { name: "canvas", includeFiles: false }]
385
- */
386
- externalPackages?: ExternalPackageEntry[];
387
- /**
388
- * Local-development settings used by `neon dev` when serving every function from
389
- * `neon.ts`. Ignored at deploy time. See {@link FunctionDevConfig}.
390
- */
391
- dev?: FunctionDevConfig;
392
- }
393
- /**
394
- * A single capability a branch-scoped service credential may exercise (Preview). A
395
- * credential is granted a set of these and may only perform the listed actions. Mirrors
396
- * the Neon API `CredentialScope` enum (`x-stability-level: beta`):
397
- *
398
- * - `storage:read` / `storage:write` — object-storage (bucket) access via the S3 key.
399
- * - `ai_gateway:invoke` — call the AI Gateway with the bearer `api_token`.
400
- * - `functions:invoke` — invoke Neon Functions with the bearer `api_token`.
401
- *
402
- * The set a policy needs is derived from its enabled Preview features (see
403
- * {@link deriveCredentialScopes}); it is never authored by hand.
404
- */
405
- type CredentialScope = "storage:read" | "storage:write" | "ai_gateway:invoke" | "functions:invoke";
406
- /**
407
- * Who a credential acts as. `user` is the developer/app principal minted for local dev and
408
- * app bootstrap (`fetchEnv` / `env pull`); `function` is a deployed-function principal
409
- * (carries a `function_id`). The env tooling only mints `user` credentials today.
410
- */
411
- type CredentialPrincipalType = "user" | "function";
412
- /** Anonymous-access level for a branchable object-storage bucket. */
413
- type BucketAccessLevel = "private" | "public_read";
414
- /**
415
- * Static definition of a branchable object-storage bucket (Preview feature). The bucket's
416
- * name is the **record key** in {@link PreviewInput.buckets}, so names are statically
417
- * enumerable and cannot duplicate.
418
- */
419
- interface BucketDef {
420
- /**
421
- * Anonymous access level. `private` (default) requires authenticated reads/writes;
422
- * `public_read` allows anonymous GetObject/HeadObject.
423
- */
424
- access?: BucketAccessLevel;
425
- }
426
- /**
427
- * Static, branch-scoped **Preview** features. Grouped under `preview` to signal they are
428
- * backed by Neon `x-stability-level: beta` endpoints and may change before GA. Everything
429
- * here is existential (it determines what exists on the branch); per-branch tuning lives in
430
- * the `branch` closure.
431
- */
432
- interface PreviewInput {
433
- /** Enable/disable the AI Gateway on the branch (toggle, like auth / dataApi). */
434
- aiGateway?: ServiceToggleInput;
435
- /** Functions to deploy, keyed by branch-unique slug (`^[a-z0-9]{1,20}$`). */
436
- functions?: Record<string, FunctionDef>;
437
- /** Object-storage buckets to create, keyed by bucket name. */
438
- buckets?: Record<string, BucketDef>;
439
- }
440
- /**
441
- * Per-branch deploy tuning for a single function. Returned (per slug) by the `branch`
442
- * closure. Deliberately **cannot** change the function's existence, source, name, env
443
- * **keys**, or memory — only runtime selection is currently configurable — so the static
444
- * secret/function set stays sound.
445
- */
446
- interface FunctionTuning {
447
- /** Runtime to execute the function with. Defaults to `"nodejs24"`. */
448
- runtime?: FunctionRuntime;
449
- }
450
- /**
451
- * Per-branch tuning of Preview features. Only existing function slugs (those declared in
452
- * the static {@link PreviewInput.functions}) may be tuned — `Slug` is constrained to the
453
- * declared keys by {@link BranchTuningFn}.
454
- */
455
- interface PreviewTuning<Slug extends string = string> {
456
- functions?: Partial<Record<Slug, FunctionTuning>>;
457
- }
458
- /**
459
- * The per-branch tuning object returned by the `branch` closure. It can adjust branch
460
- * lifecycle (`parent`, `ttl`, `protected`), Postgres compute settings, and per-function
461
- * deploy tuning — but **cannot** add/remove services or functions. That guarantee is what
462
- * keeps the static secret set (and therefore `NeonEnv`) exact.
463
- */
464
- interface BranchTuning<Slug extends string = string> {
465
- /** Parent branch name used when creating a new branch. Not a Postgres setting. */
466
- parent?: string;
467
- /**
468
- * Branch time-to-live: how long after creation the branch should auto-expire. Applied
469
- * when creating a new branch and reconciled on existing branches (when `updateExisting`
470
- * is set). Accepts a {@link DurationString} (autocompletes common values) or a number of
471
- * seconds. Omit to keep the branch indefinitely.
472
- *
473
- * - {@link DurationString} — e.g. `"7d"`; autocompletes `"1h"`, `"6h"`, `"12h"`, `"1d"`,
474
- * `"3d"`, `"7d"`, `"14d"`, `"30d"`, and accepts any other `<integer><unit>` (units: `s`,
475
- * `m`, `h`, `d`, `w` — e.g. `"12h"`, `"2w"`). A **unit is required** — `"7"` is rejected;
476
- * for raw seconds pass a `number`.
477
- * - `number` — custom TTL in **seconds** (e.g. `3600`)
478
- * - `undefined` — no expiry; the branch persists until explicitly deleted
479
- *
480
- * The Neon API caps branch expiration at **30 days** from creation, so the resolved TTL must
481
- * be `> 0` and `<= 30d`; the suggestions stay within that limit and anything longer is
482
- * rejected at apply.
483
- *
484
- * @example "1d" // ephemeral preview branch: expires a day after creation
485
- * @example "7d" // one-week TTL
486
- * @example "30d" // the maximum the API allows
487
- * @example 3600 // 1 hour, expressed in seconds
488
- */
489
- ttl?: DurationField<TtlSuggestion>;
490
- /** Whether the selected branch should be protected. Undefined means "leave as-is". */
491
- protected?: boolean;
492
- postgres?: PostgresConfig;
493
- preview?: PreviewTuning<Slug>;
494
- }
495
- /** Extract the declared function slugs from a {@link PreviewInput} for closure typing. */
496
- type FunctionSlugsOf<Preview extends PreviewInput | undefined> = Preview extends {
497
- functions: infer F;
498
- } ? Extract<keyof F, string> : string;
499
- /**
500
- * Signature of the `branch` closure. Generic over the static {@link PreviewInput} so the
501
- * `preview.functions` keys it may tune are constrained to the slugs actually declared.
502
- */
503
- type BranchTuningFn<Preview extends PreviewInput | undefined = PreviewInput | undefined> = (branch: BranchTarget) => BranchTuning<FunctionSlugsOf<Preview>>;
504
- /**
505
- * A validated Neon branch policy — the value `defineConfig({ … })` returns and `neon.ts`
506
- * default-exports.
507
- *
508
- * Split into a **static** existential set (top-level `auth` / `dataApi` GA toggles plus the
509
- * beta `preview` block) and a **dynamic** per-branch `branch` closure for tuning. The
510
- * static half is what makes the secret set — and therefore `NeonEnv<typeof config>` and
511
- * `parseEnv` — exact; the closure can tune but never change what exists.
512
- *
513
- * Generic over the three static fields so the type system can read the exact toggle/slug
514
- * literals; the defaults make the bare `Config` a usable "any policy" type for runtime
515
- * function signatures.
516
- */
517
- interface Config<Auth extends ServiceToggleInput | undefined = ServiceToggleInput | undefined, DataApi extends DataApiInput | undefined = DataApiInput | undefined, Preview extends PreviewInput | undefined = PreviewInput | undefined> {
518
- /** Neon Auth integration toggle (GA). Static — drives `NeonEnv.auth`. */
519
- auth?: Auth;
520
- /**
521
- * Neon Data API integration (GA). Static — drives `NeonEnv.dataApi`. A boolean/toggle, or
522
- * a {@link DataApiConfig} object selecting the auth provider (`"neon"` / `"external"`) and
523
- * runtime {@link DataApiSettings}. With `authProvider: "neon"` the policy must also enable
524
- * top-level `auth`.
525
- */
526
- dataApi?: DataApi;
527
- /** Beta (Preview) feature set: AI Gateway, functions, buckets. Static. */
528
- preview?: Preview;
529
- /** Per-branch tuning closure. Cannot change the static existential set. */
530
- branch?: BranchTuningFn<Preview>;
531
- }
532
- /**
533
- * A function with all deploy defaults applied. `resolveConfig` fills in `runtime` so
534
- * downstream diff/apply never has to re-derive it.
535
- */
536
- interface ResolvedFunctionConfig {
537
- slug: string;
538
- name: string;
539
- source: string;
540
- env: Record<string, string>;
541
- /**
542
- * Packages the bundler leaves unresolved, normalized from
543
- * {@link FunctionDef.externalPackages} with `includeFiles` defaulted.
544
- *
545
- * Absent rather than empty when undeclared, so a policy that never mentions it takes the
546
- * pre-existing bundling path and produces the archive it always did.
547
- */
548
- externalPackages?: ResolvedExternalPackage[];
549
- runtime: FunctionRuntime;
550
- /**
551
- * Local-development settings, passed through untouched from {@link FunctionDef.dev}
552
- * (no defaults applied). Only consumed by `neon dev`; deploy ignores it.
553
- */
554
- dev?: FunctionDevConfig;
555
- }
556
- /** A bucket with its access level defaulted to `private`. */
557
- interface ResolvedBucketConfig {
558
- name: string;
559
- access: BucketAccessLevel;
560
- }
561
- /**
562
- * Normalized {@link PreviewInput}. Only present on {@link ResolvedBranchConfig} when the
563
- * policy returned a `preview` block. `aiGatewayEnabled` follows the same
564
- * "present-and-not-`false`" semantics as `authEnabled` / `dataApiEnabled`.
565
- */
566
- interface ResolvedPreviewConfig {
567
- functions: ResolvedFunctionConfig[];
568
- buckets: ResolvedBucketConfig[];
569
- aiGatewayEnabled: boolean;
570
- }
571
- /**
572
- * Normalized Data API integration. Present on {@link ResolvedBranchConfig} only when the
573
- * policy enables `dataApi`. `authProvider` always resolves (defaults to `"neon"`); the
574
- * external-IdP wiring is present only for `"external"`; `settings` carries the camelCase
575
- * runtime settings (reconciled as an update when they drift).
576
- */
577
- interface ResolvedDataApiConfig {
578
- authProvider: DataApiAuthProvider;
579
- jwksUrl?: string;
580
- providerName?: string;
581
- jwtAudience?: string;
582
- settings?: DataApiSettings;
583
- }
584
- interface ResolvedBranchConfig {
585
- parent?: string;
586
- ttlSeconds?: number;
587
- protected?: boolean;
588
- postgres?: PostgresConfig;
589
- authEnabled: boolean;
590
- dataApiEnabled: boolean;
591
- /**
592
- * Resolved Data API integration. Present iff {@link dataApiEnabled} is `true`. Carries the
593
- * create-time auth wiring and the updatable {@link DataApiSettings}.
594
- */
595
- dataApi?: ResolvedDataApiConfig;
596
- preview?: ResolvedPreviewConfig;
597
- }
598
- /**
599
- * One concrete change `pushConfig` made (or, in dry-run, would make) on the remote.
600
- */
601
- //#endregion
602
- export { BranchTarget, BranchTuning, BranchTuningFn, BucketAccessLevel, BucketDef, ComputeSettings, ComputeUnit, Config, CredentialPrincipalType, CredentialScope, DATA_API_AUTH_PROVIDERS, DataApiAuthProvider, DataApiConfig, DataApiExternalAuthConfig, DataApiInput, DataApiNeonAuthConfig, DataApiSettings, DurationString, DurationUnit, ExternalPackageDef, ExternalPackageEntry, FunctionDef, FunctionDevConfig, FunctionRuntime, FunctionTuning, PostgresConfig, PreviewInput, PreviewTuning, ResolvedBranchConfig, ResolvedBucketConfig, ResolvedDataApiConfig, ResolvedExternalPackage, ResolvedFunctionConfig, ResolvedPreviewConfig, ServiceToggle, ServiceToggleInput };
603
- //# sourceMappingURL=types.d.ts.map