neon 4.16.0 → 4.17.1
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 +7 -6
- package/dist/_chunks/{env-DsakkOVZ.js → env-B75xufe_.js} +57 -64
- package/dist/_chunks/{env_services-CAWrZTWa.js → env_services-CbARRnq9.js} +66 -11
- package/dist/auth_recovery.js +61 -0
- package/dist/commands/bootstrap.js +30 -17
- package/dist/commands/branches.js +3 -3
- package/dist/commands/checkout.js +1 -1
- package/dist/commands/claim.js +3 -3
- package/dist/commands/config.js +2 -2
- package/dist/commands/connection_string.js +1 -1
- package/dist/commands/dev.js +9 -11
- package/dist/commands/env.js +8 -8
- package/dist/commands/index.js +3 -3
- package/dist/commands/init.js +47 -26
- package/dist/commands/ip_allow.js +1 -1
- package/dist/commands/link.js +20 -17
- package/dist/commands/mcp.js +1 -1
- package/dist/commands/plugins.js +1 -1
- package/dist/commands/skills.js +1 -1
- package/dist/dev/env.js +1 -1
- package/dist/env_services.js +1 -1
- package/dist/help.js +121 -66
- package/dist/index.js +4 -60
- package/dist/init/link.js +38 -0
- package/dist/init/wizard.js +13 -1
- package/dist/test_utils/fixtures.js +1 -0
- package/dist/utils/help_text.js +32 -4
- package/dist/writer.js +2 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -742,7 +742,7 @@ When a package cannot be bundled — a native addon with no esbuild loader, or a
|
|
|
742
742
|
|
|
743
743
|
`neon bootstrap` copies a Neon starter template into a new (or current) directory — conceptually like `degit`, but it only pulls from a small set of templates we maintain in the public [`neondatabase/examples`](https://github.com/neondatabase/examples) repo. The template copy needs no Neon login: it downloads files from GitHub.
|
|
744
744
|
|
|
745
|
-
After scaffolding, an interactive terminal asks about dependency install
|
|
745
|
+
After scaffolding, an interactive terminal asks about dependency install and git, then finishes agent setup before asking whether to link a Neon project. Dependency install is last, except when the template has a `neon.ts` and you chose to link — then install runs first so the link flow can pull env. `--default` / `-y` skips the template, install, git, and agent pickers, then installs agent tooling for project folders, else the host CLI agent. If none are found, it exits: pass `--agent <name>`, run from a supported agent, or omit `--default` / `-y` in a terminal to pick. `--agent` / `-a` names coding agents, skips agent selection, and is forwarded to `plugins`, or to `skills` and `mcp`, not both. Project selection may still be required. `--no-agent-setup` and `--no-link` skip those steps. Non-interactive without `--default` prints next steps and does not install, set up agents, or link.
|
|
746
746
|
|
|
747
747
|
Pass a target directory (or `.` for the current one). In an interactive terminal you pick the template from a list; in CI / non-interactive contexts pass `--template <id>`.
|
|
748
748
|
|
|
@@ -773,18 +773,19 @@ An empty directory (nothing except `.git`) asks how to set up the directory. Pic
|
|
|
773
773
|
|
|
774
774
|
`-y` in an empty directory scaffolds the default template (`bootstrap --default`) and does not add a later `config init` step. `--skip-template` skips scaffolding even with `-y`. `--template <id>` scaffolds that template; combine it with `-y` to skip the remaining bootstrap pickers.
|
|
775
775
|
|
|
776
|
-
An existing app (or skip-template) installs agent tooling, then
|
|
776
|
+
An existing app (or skip-template) installs agent tooling, then asks whether to link unless `.neon` already has a projectId, then asks whether to create `neon.ts`. Linking uses the same organization, project, and branch flow as `neon link`. Saying no to `neon.ts` skips the services picker and does not write the file. `--no-config` does the same without asking. `-y` writes `config init --services none` unless `--no-config`. `--services` implies creating `neon.ts`.
|
|
777
777
|
|
|
778
|
-
In an interactive terminal it offers one of: the Neon plugin (`neon plugins`), skills and MCP separately (`neon skills`, then `neon mcp`), or skip agent setup. It never runs plugin and skills+MCP together.
|
|
778
|
+
In an interactive terminal it offers one of: the Neon plugin (`neon plugins`), skills and MCP separately (`neon skills`, then `neon mcp`), or skip agent setup. Agent selection and setup finish before the link question. It never runs plugin and skills+MCP together.
|
|
779
779
|
|
|
780
780
|
```bash
|
|
781
781
|
$ neon init
|
|
782
782
|
$ neon init --skip-template
|
|
783
|
+
$ neon init --skip-template --no-link
|
|
783
784
|
$ neon init -y
|
|
784
785
|
$ neon init --agent cursor --agent claude-code
|
|
785
786
|
```
|
|
786
787
|
|
|
787
|
-
Without a TTY, pass `-y`. `--agent` skips agent selection but does not replace `-y` for link or templates.
|
|
788
|
+
Without a TTY, pass `-y`. `--agent` skips agent selection but does not replace `-y` for link or templates. `--no-link` skips project linking without asking, including when a template is scaffolded.
|
|
788
789
|
|
|
789
790
|
`-y` skips the template picker and the agent-setup offer. Empty dir: `bootstrap --default`. `--skip-template` or an existing app: plugin when Cursor, Claude Code, or Codex is in project folders, else the host CLI agent; otherwise skills and MCP. If none are found, it exits: pass `--agent <name>`, run from a supported agent, or omit `-y` in a terminal to pick. VS Code, GitHub Copilot CLI, and Grok only take the plugin user-level (`neon plugins --global`), so `-y` uses skills and MCP for those.
|
|
790
791
|
|
|
@@ -794,7 +795,7 @@ Without a TTY, pass `-y`. `--agent` skips agent selection but does not replace `
|
|
|
794
795
|
|
|
795
796
|
`--config`, `--no-config`, and `--services` apply on the existing-app and `--skip-template` path. A template's own `neon.ts` is left as the template shipped it. Passing those flags while scaffolding prints a warning and still copies the template as shipped. After a new `neon.ts` on a pinned branch, init runs `env pull`.
|
|
796
797
|
|
|
797
|
-
`-y` forwards `-y` to `plugins` or `skills`/`mcp`,
|
|
798
|
+
`-y` forwards `-y` to `plugins` or `skills`/`mcp`, uses default choices in the built-in link flow, passes `--default` to nested bootstrap, and forwards `--services none` to `config init`. `--agent` is forwarded to agent setup. `mcp -y` is the global install. Default linking skips the "already linked" confirmation; it can still require project selection.
|
|
798
799
|
|
|
799
800
|
A failed step stops the rest. `--profile` and `--config-dir` are forwarded to each child. `--output json` and `--output yaml` are refused; the commands init runs print their own output.
|
|
800
801
|
|
|
@@ -1228,7 +1229,7 @@ When both are only environment variables the key wins, which keeps a CI pipeline
|
|
|
1228
1229
|
|
|
1229
1230
|
`neon auth` and the `profile` subcommands are outside all of this, because they read the same flags to mean something else: `neon auth --profile work` names where to write a credential, and `neon profile create work --api-key …` names one to store.
|
|
1230
1231
|
|
|
1231
|
-
`neon init` forwards `--profile` and `--config-dir` to
|
|
1232
|
+
`neon init` forwards `--profile` and `--config-dir` to agent and config children and uses them directly for its link flow. An explicit `--api-key` is passed to authenticated children through `NEON_API_KEY`, not argv.
|
|
1232
1233
|
|
|
1233
1234
|
## API passthrough (`api`)
|
|
1234
1235
|
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { log } from "../log.js";
|
|
2
2
|
import { getCliName } from "../utils/cli_name.js";
|
|
3
3
|
import { declaredNeonServices } from "../config_services.js";
|
|
4
|
-
import { S as
|
|
4
|
+
import { C as resolveBranchPolicy, S as policyEnvKeys, _ as defaultStorageCredential, a as envKeysForSelection, b as isFunctionBaseUrlKey, d as servicesForEnvKeys, f as NEON_ENV_VAR_KEYS, g as defaultAiGatewayCredential, h as credentialName, i as ENV_PULL_SERVICES, m as credentialEnvKeys, p as createApiFromOptions, u as serviceForEnvKey, v as fetchEnvKeysState, w as toEntries, x as isLiveCredential, y as functionBaseUrlKey } from "./env_services-CbARRnq9.js";
|
|
5
5
|
import { formatInstallCommand, resolvePackageManager } from "../utils/package_manager.js";
|
|
6
6
|
import { credentialScopesSatisfied } from "@neon/config/v1";
|
|
7
7
|
import { ErrorCode as ErrorCode$1, createNeonApiFromOptions as createNeonApiFromOptions$1, isPlatformError as isPlatformError$1, loadConfigFromFile } from "@neon/config";
|
|
8
8
|
import { plan, pullConfig } from "@neon/config-runtime";
|
|
9
9
|
//#region ../../internals/env-core/dist/reuse-secrets.js
|
|
10
10
|
/**
|
|
11
|
-
* Resolve a branch's env while keeping
|
|
11
|
+
* Resolve a branch's env while keeping secrets the caller already holds.
|
|
12
12
|
*
|
|
13
|
-
* {@link fetchEnvKeys}
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* for only the rest.
|
|
13
|
+
* {@link fetchEnvKeys} reveals the platform default credentials (or mints a fallback when a
|
|
14
|
+
* region has none). Calling it on every `neon dev` start would rewrite `.env` with freshly
|
|
15
|
+
* revealed secrets each time. This wrapper looks at what the caller already has, keeps a
|
|
16
|
+
* half when it already *is* that default (storage and gateway are independent credentials),
|
|
17
|
+
* and asks `fetchEnv` for only the rest.
|
|
19
18
|
*
|
|
20
19
|
* The check is a real verification, not a presence test. A persisted secret is kept only when
|
|
21
|
-
* it names a credential that still exists on this branch, is not revoked or expired, and
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
20
|
+
* it names a credential that still exists on this branch, is not revoked or expired, and —
|
|
21
|
+
* when defaults exist — *is* that default. A leftover `neon-env ${branch}` credential this
|
|
22
|
+
* tool minted is replaced by the defaults and revoked. A `.env.example` placeholder, a
|
|
23
|
+
* credential revoked in the console, or one copied in from another branch fails that check.
|
|
25
24
|
*
|
|
26
25
|
* None of this needs local bookkeeping, because the secrets carry their own credential id:
|
|
27
26
|
* `AWS_ACCESS_KEY_ID` **is** the credential's `tokenId` (the storage gateway authenticates
|
|
@@ -71,47 +70,47 @@ async function fetchEnvReusingSecrets(config, options) {
|
|
|
71
70
|
const persisted = readPersistedSecrets(source);
|
|
72
71
|
const storageCredentialManaged = requested === null || storageCredentialSelected;
|
|
73
72
|
const gatewayCredentialManaged = requested === null || gatewayCredentialSelected;
|
|
74
|
-
const
|
|
75
|
-
const
|
|
73
|
+
const storageComplete = Boolean(persisted.accessKeyId && persisted.secretAccessKey);
|
|
74
|
+
const gatewayComplete = Boolean(persisted.apiToken);
|
|
75
|
+
const listed = storageCredentialManaged && persisted.accessKeyId !== "" || gatewayCredentialManaged && persisted.apiToken !== "" ? await api.listCredentials(options.projectId, branch.id) : [];
|
|
76
|
+
const named = listed.length > 0 ? namedCredentials(listed, persisted) : {
|
|
76
77
|
storage: null,
|
|
77
78
|
gateway: null
|
|
78
79
|
};
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const fetchKeys = requested === null ? null :
|
|
80
|
+
const now = Date.now();
|
|
81
|
+
const storageDefault = defaultStorageCredential(listed, now);
|
|
82
|
+
const gatewayDefault = defaultAiGatewayCredential(listed, now);
|
|
83
|
+
const keepStorage = !storageCredentialSelected || storageComplete && halfReusable(named.storage, storageDefault, ["storage:read", "storage:write"]);
|
|
84
|
+
const keepGateway = !gatewayCredentialSelected || gatewayComplete && halfReusable(named.gateway, gatewayDefault, ["ai_gateway:invoke"]);
|
|
85
|
+
const keptSecretKeys = credentialEnvKeys({
|
|
86
|
+
storage: storageCredentialSelected && keepStorage,
|
|
87
|
+
aiGateway: gatewayCredentialSelected && keepGateway
|
|
88
|
+
}).filter((key) => selected.has(key));
|
|
89
|
+
const fetchKeys = requested === null ? null : selectedPolicyKeys.filter((key) => !keptSecretKeys.includes(key));
|
|
89
90
|
const fetched = await fetchEnvKeysState(config, {
|
|
90
91
|
...fetchOptions,
|
|
91
92
|
branchId: branch.id,
|
|
92
93
|
api,
|
|
93
|
-
...
|
|
94
|
+
...keptSecretKeys.length > 0 && requested === null ? { omitKeys: keptSecretKeys } : {}
|
|
94
95
|
}, fetchKeys);
|
|
95
96
|
const vars = preferPersisted(toEntries(fetched.env), source);
|
|
96
97
|
const unavailable = fetched.functionUrlsUnavailable ? { functionUrlsUnavailable: true } : {};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (value !== void 0) vars[key] = value;
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
vars,
|
|
104
|
-
credential: {
|
|
105
|
-
issued: false,
|
|
106
|
-
keys: secretKeys,
|
|
107
|
-
revoked: [],
|
|
108
|
-
superseded: []
|
|
109
|
-
},
|
|
110
|
-
...unavailable
|
|
111
|
-
};
|
|
98
|
+
for (const key of keptSecretKeys) {
|
|
99
|
+
const value = source[key];
|
|
100
|
+
if (value !== void 0) vars[key] = value;
|
|
112
101
|
}
|
|
102
|
+
if (!(storageCredentialSelected && !keepStorage || gatewayCredentialSelected && !keepGateway)) return {
|
|
103
|
+
vars,
|
|
104
|
+
credential: {
|
|
105
|
+
issued: false,
|
|
106
|
+
keys: secretKeys,
|
|
107
|
+
revoked: [],
|
|
108
|
+
superseded: []
|
|
109
|
+
},
|
|
110
|
+
...unavailable
|
|
111
|
+
};
|
|
113
112
|
const ours = /* @__PURE__ */ new Set();
|
|
114
|
-
for (const meta of [storageCredentialManaged ? named.storage : null, gatewayCredentialManaged ? named.gateway : null]) if (meta !== null && meta.principalType === "user" && meta.name === credentialName(branch.name)) ours.add(meta.tokenId);
|
|
113
|
+
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);
|
|
115
114
|
if (revokeSuperseded) for (const tokenId of ours) await api.revokeCredential(options.projectId, branch.id, tokenId);
|
|
116
115
|
return {
|
|
117
116
|
vars,
|
|
@@ -162,13 +161,6 @@ function preferPersisted(vars, source) {
|
|
|
162
161
|
function gatewayTokenIdShort(apiToken) {
|
|
163
162
|
return /^nt_live_([^_]+)_.+$/.exec(apiToken)?.[1] ?? null;
|
|
164
163
|
}
|
|
165
|
-
/** Whether an issued credential can still be used: not revoked, not past its expiry. */
|
|
166
|
-
function isLiveCredential(meta, now) {
|
|
167
|
-
if (meta.revokedAt !== void 0) return false;
|
|
168
|
-
if (meta.expiresAt === void 0) return true;
|
|
169
|
-
const expiresAt = Date.parse(meta.expiresAt);
|
|
170
|
-
return Number.isNaN(expiresAt) || expiresAt > now;
|
|
171
|
-
}
|
|
172
164
|
/**
|
|
173
165
|
* The live credentials the persisted secrets name — at most one per half. A half that names
|
|
174
166
|
* nothing contributes nothing, which is what a placeholder, a credential revoked in the
|
|
@@ -183,17 +175,17 @@ function namedCredentials(live, persisted) {
|
|
|
183
175
|
};
|
|
184
176
|
}
|
|
185
177
|
/**
|
|
186
|
-
*
|
|
178
|
+
* Whether a persisted half can be reused.
|
|
187
179
|
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
180
|
+
* When a platform default exists, only that default is reusable — a leftover
|
|
181
|
+
* `neon-env ${branch}` mint is replaced. When no default exists (mint fallback),
|
|
182
|
+
* any live credential the secrets name is reusable if it still carries the
|
|
183
|
+
* scopes that half needs.
|
|
191
184
|
*/
|
|
192
|
-
function
|
|
193
|
-
if (
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
return null;
|
|
185
|
+
function halfReusable(named, defaultMeta, requiredScopes) {
|
|
186
|
+
if (named === null) return false;
|
|
187
|
+
if (defaultMeta !== null) return named.tokenId === defaultMeta.tokenId;
|
|
188
|
+
return credentialScopesSatisfied(named.scopes, requiredScopes);
|
|
197
189
|
}
|
|
198
190
|
//#endregion
|
|
199
191
|
//#region src/dev/env.ts
|
|
@@ -437,16 +429,17 @@ const withAiGateway = (config) => ({
|
|
|
437
429
|
*
|
|
438
430
|
* So the gateway is only added once its credential endpoint has been shown to answer, by
|
|
439
431
|
* reading the branch's credentials first. A project that does not have them says so on a
|
|
440
|
-
* read, before anything is minted — which is the whole question, since the
|
|
441
|
-
* credential and nothing else.
|
|
432
|
+
* read, before anything is revealed or minted — which is the whole question, since the
|
|
433
|
+
* gateway's env is a credential and nothing else.
|
|
442
434
|
*
|
|
443
435
|
* Deciding this **before** resolving, rather than by catching and retrying, is what keeps it
|
|
444
436
|
* honest. A retry re-runs every call the first attempt made, so it would blame the gateway for
|
|
445
|
-
* a one-off failure in shared work, and — worse — a first attempt that minted a
|
|
446
|
-
* then failed would be papered over by a second that succeeds without one,
|
|
447
|
-
* error and stranding a secret nobody holds. Once the read succeeds, a later
|
|
448
|
-
* failure and propagates: the same thing already happens on a branch with
|
|
449
|
-
* whose credential is minted whether or not the
|
|
437
|
+
* a one-off failure in shared work, and — worse — a first attempt that revealed or minted a
|
|
438
|
+
* credential and then failed would be papered over by a second that succeeds without one,
|
|
439
|
+
* swallowing the error and stranding a secret nobody holds. Once the read succeeds, a later
|
|
440
|
+
* failure is a real failure and propagates: the same thing already happens on a branch with
|
|
441
|
+
* object storage, whose credential is revealed (or minted as a fallback) whether or not the
|
|
442
|
+
* gateway is involved.
|
|
450
443
|
*/
|
|
451
444
|
const resolveWithImpliedGateway = async (config, ctx, branch) => {
|
|
452
445
|
const unreachable = await credentialsUnreachable(ctx, branch);
|
|
@@ -190,7 +190,7 @@ async function fetchEnvKeysState(config, options, keys) {
|
|
|
190
190
|
branchId: branch.id
|
|
191
191
|
} });
|
|
192
192
|
}
|
|
193
|
-
const secrets = wantsCredential ? await
|
|
193
|
+
const secrets = wantsCredential ? await resolveBranchCredentialSecrets({
|
|
194
194
|
api,
|
|
195
195
|
projectId,
|
|
196
196
|
branchId: branch.id,
|
|
@@ -303,9 +303,9 @@ async function resolveBranchPolicy(config, options, api) {
|
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
306
|
-
* Scopes
|
|
307
|
-
*
|
|
308
|
-
*
|
|
306
|
+
* Scopes a minted fallback credential should carry. Only object storage and the AI Gateway
|
|
307
|
+
* *require* secrets; functions never force a credential. `functions:invoke` rides along only
|
|
308
|
+
* when this path still has to mint (defaults already cover storage and the gateway).
|
|
309
309
|
*/
|
|
310
310
|
function previewCredentialScopes(preview, selected) {
|
|
311
311
|
if (!preview) return [];
|
|
@@ -348,15 +348,70 @@ function policyEnvKeys(desired) {
|
|
|
348
348
|
...desired.preview?.aiGatewayEnabled ? [K.aiGateway.apiKey, K.aiGateway.baseUrl] : []
|
|
349
349
|
];
|
|
350
350
|
}
|
|
351
|
+
/** Exact `name` values the credentials list endpoint returns for the platform defaults. */
|
|
352
|
+
const DEFAULT_AI_GATEWAY_CREDENTIAL_NAME = "Default AI gateway credential";
|
|
353
|
+
const DEFAULT_OBJECT_STORAGE_CREDENTIAL_NAME = "Default object storage credential";
|
|
354
|
+
/** Whether an issued credential can still be used: not revoked, not past its expiry. */
|
|
355
|
+
function isLiveCredential(meta, now) {
|
|
356
|
+
if (meta.revokedAt !== void 0) return false;
|
|
357
|
+
if (meta.expiresAt === void 0) return true;
|
|
358
|
+
const expiresAt = Date.parse(meta.expiresAt);
|
|
359
|
+
return Number.isNaN(expiresAt) || expiresAt > now;
|
|
360
|
+
}
|
|
361
|
+
function defaultStorageCredential(live, now) {
|
|
362
|
+
return live.find((meta) => meta.name === DEFAULT_OBJECT_STORAGE_CREDENTIAL_NAME && isLiveCredential(meta, now)) ?? null;
|
|
363
|
+
}
|
|
364
|
+
function defaultAiGatewayCredential(live, now) {
|
|
365
|
+
return live.find((meta) => meta.name === DEFAULT_AI_GATEWAY_CREDENTIAL_NAME && isLiveCredential(meta, now)) ?? null;
|
|
366
|
+
}
|
|
351
367
|
/**
|
|
352
|
-
*
|
|
368
|
+
* Resolve secrets for object storage / the AI Gateway.
|
|
353
369
|
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
370
|
+
* Regions that expose those products already have platform defaults on every branch.
|
|
371
|
+
* Reveal those by exact name instead of minting a combined `neon-env ${branch}` credential.
|
|
372
|
+
* Mint only the half (or both) that has no default — regions without the credentials
|
|
373
|
+
* endpoint still fail at list, same as before.
|
|
374
|
+
*
|
|
375
|
+
* A caller that already holds secrets for those defaults should leave the secret keys out
|
|
376
|
+
* of `keys` (see {@link fetchEnvReusingSecrets}) instead of revealing them again.
|
|
359
377
|
*/
|
|
378
|
+
async function resolveBranchCredentialSecrets(args) {
|
|
379
|
+
const needsStorage = args.scopes.includes("storage:read") || args.scopes.includes("storage:write");
|
|
380
|
+
const needsGateway = args.scopes.includes("ai_gateway:invoke");
|
|
381
|
+
const live = await args.api.listCredentials(args.projectId, args.branchId);
|
|
382
|
+
const now = Date.now();
|
|
383
|
+
const storageDefault = defaultStorageCredential(live, now);
|
|
384
|
+
const gatewayDefault = defaultAiGatewayCredential(live, now);
|
|
385
|
+
const secrets = {
|
|
386
|
+
accessKeyId: "",
|
|
387
|
+
secretAccessKey: "",
|
|
388
|
+
apiToken: ""
|
|
389
|
+
};
|
|
390
|
+
if (needsStorage && storageDefault) {
|
|
391
|
+
const revealed = await args.api.revealCredential(args.projectId, args.branchId, storageDefault.tokenId);
|
|
392
|
+
secrets.accessKeyId = revealed.tokenId;
|
|
393
|
+
secrets.secretAccessKey = revealed.s3SecretAccessKey;
|
|
394
|
+
}
|
|
395
|
+
if (needsGateway && gatewayDefault) secrets.apiToken = (await args.api.revealCredential(args.projectId, args.branchId, gatewayDefault.tokenId)).apiToken;
|
|
396
|
+
const missingStorage = needsStorage && storageDefault === null;
|
|
397
|
+
const missingGateway = needsGateway && gatewayDefault === null;
|
|
398
|
+
if (missingStorage || missingGateway) {
|
|
399
|
+
const minted = await mintBranchCredential({
|
|
400
|
+
...args,
|
|
401
|
+
scopes: deriveCredentialScopes({
|
|
402
|
+
storage: missingStorage,
|
|
403
|
+
aiGateway: missingGateway,
|
|
404
|
+
functions: args.scopes.includes("functions:invoke")
|
|
405
|
+
})
|
|
406
|
+
});
|
|
407
|
+
if (missingStorage) {
|
|
408
|
+
secrets.accessKeyId = minted.accessKeyId;
|
|
409
|
+
secrets.secretAccessKey = minted.secretAccessKey;
|
|
410
|
+
}
|
|
411
|
+
if (missingGateway) secrets.apiToken = minted.apiToken;
|
|
412
|
+
}
|
|
413
|
+
return secrets;
|
|
414
|
+
}
|
|
360
415
|
async function mintBranchCredential(args) {
|
|
361
416
|
const minted = await args.api.createCredential(args.projectId, args.branchId, {
|
|
362
417
|
scopes: args.scopes,
|
|
@@ -625,4 +680,4 @@ const editDistance = (left, right) => {
|
|
|
625
680
|
/** Narrow yargs' array option value without accepting any other runtime shape. */
|
|
626
681
|
const envPullFlagValue = (value) => Array.isArray(value) ? value.map(String) : void 0;
|
|
627
682
|
//#endregion
|
|
628
|
-
export {
|
|
683
|
+
export { resolveBranchPolicy as C, policyEnvKeys as S, defaultStorageCredential as _, envKeysForSelection as a, isFunctionBaseUrlKey as b, ownedEnvServiceKeys as c, servicesForEnvKeys as d, NEON_ENV_VAR_KEYS as f, defaultAiGatewayCredential as g, credentialName as h, ENV_PULL_SERVICES as i, parseEnvPullKeys as l, credentialEnvKeys as m, ENV_PULL_KEYS as n, envPullFlagValue as o, createApiFromOptions as p, ENV_PULL_KEY_HELP as r, envServiceKeys as s, BRANCH_ENV_KEY as t, serviceForEnvKey as u, fetchEnvKeysState as v, toEntries as w, isLiveCredential as x, functionBaseUrlKey as y };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { t as storeFor } from "./_chunks/credential_io-D8AR-jvB.js";
|
|
2
|
+
import { log } from "./log.js";
|
|
3
|
+
import { authFailureMessage, getAuthContext, locationFromContext } from "./auth_context.js";
|
|
4
|
+
import { AuthRefreshError } from "./auth.js";
|
|
5
|
+
import { isAccessTokenUsable, refreshStoredCredentials } from "./commands/auth.js";
|
|
6
|
+
//#region src/auth_recovery.ts
|
|
7
|
+
const supersededOnDisk = (rejectedToken) => {
|
|
8
|
+
if (rejectedToken === void 0) return false;
|
|
9
|
+
const context = getAuthContext();
|
|
10
|
+
if (context === null) return false;
|
|
11
|
+
const at = locationFromContext(context);
|
|
12
|
+
if (at === null) return false;
|
|
13
|
+
try {
|
|
14
|
+
const loaded = storeFor(context.configDir).read(at);
|
|
15
|
+
return loaded !== null && loaded.credentials.access_token !== rejectedToken && isAccessTokenUsable(loaded.credentials, Date.now());
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const recoverFrom401 = async (canRetry) => {
|
|
21
|
+
const context = getAuthContext();
|
|
22
|
+
if (context === null || context.source !== "stored-credentials") {
|
|
23
|
+
log.error(authFailureMessage(context));
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (context.refreshed === true || !canRetry) {
|
|
27
|
+
log.error(authFailureMessage(context));
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (supersededOnDisk(context.accessToken)) {
|
|
31
|
+
log.debug("The rejected token has already been replaced on disk; retrying with the current one");
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
const at = locationFromContext(context);
|
|
35
|
+
if (at === null || context.oauthHost === void 0 || context.clientId === void 0) {
|
|
36
|
+
log.error(authFailureMessage(context));
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
if (await refreshStoredCredentials(at, {
|
|
41
|
+
apiHost: "",
|
|
42
|
+
oauthHost: context.oauthHost,
|
|
43
|
+
clientId: context.clientId,
|
|
44
|
+
configDir: context.configDir
|
|
45
|
+
})) {
|
|
46
|
+
log.debug("Refreshed the stored session after a 401; retrying");
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
} catch (err) {
|
|
50
|
+
if (err instanceof AuthRefreshError) {
|
|
51
|
+
log.error(err.message);
|
|
52
|
+
if (err.terminal) log.error(`Run \`neon auth --profile ${context.profile ?? "DEFAULT"}\` to sign in again.`);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
log.debug("Refresh after 401 failed: %s", err instanceof Error ? err.message : "unknown error");
|
|
56
|
+
}
|
|
57
|
+
log.error(authFailureMessage(context));
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
//#endregion
|
|
61
|
+
export { recoverFrom401 };
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { t as __exportAll } from "../_chunks/rolldown-runtime-8H4AJuhK.js";
|
|
2
2
|
import { isCi } from "../env.js";
|
|
3
3
|
import { log } from "../log.js";
|
|
4
|
-
import { getCliName } from "../utils/cli_name.js";
|
|
5
4
|
import { t as credentialInputs } from "../_chunks/auth_selection-pitMFzDe.js";
|
|
5
|
+
import { getCliName } from "../utils/cli_name.js";
|
|
6
|
+
import { helpCsv, helpEpilogue } from "../utils/help_text.js";
|
|
6
7
|
import { writer } from "../writer.js";
|
|
7
8
|
import { FALLBACK_TEMPLATES, ensureTargetUsable, fetchTemplates, findTemplate, scaffoldTemplate, templateIds } from "../init/bootstrap.js";
|
|
8
9
|
import { spawnCliChild } from "../init/child.js";
|
|
9
10
|
import { agentSetupDoneLabel, formatInitDone, printInitBanner, printInitDone, shouldPrintInitBanner } from "../init/chrome.js";
|
|
11
|
+
import { formatInstallCommand, inferPackageManager, installArgs, installedPackageManagers, resolvePackageManager, runCommand } from "../utils/package_manager.js";
|
|
12
|
+
import { runAuthenticatedLink } from "../init/link.js";
|
|
10
13
|
import { coerceAgentFlag } from "../utils/agent_flag.js";
|
|
11
|
-
import { assertNamedAgentTooling, chooseYesAgentTooling, initPluginAgents, initSkillsMcpAgents,
|
|
14
|
+
import { assertNamedAgentTooling, chooseYesAgentTooling, initPluginAgents, initSkillsMcpAgents, postScaffoldActions, projectContextFile, resolveNamedAgents } from "../init/plan.js";
|
|
12
15
|
import { formatTemplateTitle } from "../init/template_title.js";
|
|
13
|
-
import { pickAgentSetupInteractively } from "../init/wizard.js";
|
|
14
|
-
import { runAgentTooling
|
|
15
|
-
import { helpCsv, helpEpilogue } from "../utils/help_text.js";
|
|
16
|
-
import { formatInstallCommand, inferPackageManager, installArgs, installedPackageManagers, resolvePackageManager, runCommand } from "../utils/package_manager.js";
|
|
16
|
+
import { pickAgentSetupInteractively, pickInitLinkInteractively } from "../init/wizard.js";
|
|
17
|
+
import { runAgentTooling } from "../init/tooling.js";
|
|
17
18
|
import { existsSync } from "node:fs";
|
|
18
19
|
import { join, relative, resolve } from "node:path";
|
|
19
20
|
import prompts from "prompts";
|
|
@@ -47,7 +48,7 @@ const builder = (argv) => argv.usage("$0 bootstrap [directory] [options]").posit
|
|
|
47
48
|
},
|
|
48
49
|
default: {
|
|
49
50
|
alias: "y",
|
|
50
|
-
describe: "Quick start: scaffold the default template (or --template), then install, git, agent tooling (project folders, else the host CLI agent; if none, pass --agent or omit --default in a terminal), and link
|
|
51
|
+
describe: "Quick start: scaffold the default template (or --template), then install, git, agent tooling (project folders, else the host CLI agent; if none, pass --agent or omit --default in a terminal), and link with defaults. Project selection may still be required",
|
|
51
52
|
type: "boolean",
|
|
52
53
|
default: false
|
|
53
54
|
},
|
|
@@ -62,7 +63,7 @@ const builder = (argv) => argv.usage("$0 bootstrap [directory] [options]").posit
|
|
|
62
63
|
default: true
|
|
63
64
|
},
|
|
64
65
|
link: {
|
|
65
|
-
describe:
|
|
66
|
+
describe: "Link a Neon project after scaffolding. Templates with neon.ts link after install so env pull works; otherwise linking happens before install. In interactive mode this is offered as a prompt; use --no-link to skip without being asked.",
|
|
66
67
|
type: "boolean",
|
|
67
68
|
default: true
|
|
68
69
|
},
|
|
@@ -78,7 +79,7 @@ const builder = (argv) => argv.usage("$0 bootstrap [directory] [options]").posit
|
|
|
78
79
|
describe: "Coding agent to install into (repeatable). Forwarded to plugins, or to skills and mcp. Skips agent selection. Values listed below",
|
|
79
80
|
coerce: coerceAgentFlag
|
|
80
81
|
}
|
|
81
|
-
}).example("$0 bootstrap my-app", "Create ./my-app from an interactively chosen template").example("$0 bootstrap . --template hono", "Scaffold the Hono template into the current directory").example("$0 bootstrap my-app --default", "Skip the pickers;
|
|
82
|
+
}).example("$0 bootstrap my-app", "Create ./my-app from an interactively chosen template").example("$0 bootstrap . --template hono", "Scaffold the Hono template into the current directory").example("$0 bootstrap my-app --default", "Skip the pickers; project selection may still be required").example("$0 bootstrap --list-templates --output json", "Print the template catalog as JSON").example("$0 bootstrap my-app --agent cursor --agent claude-code", "Skip agent selection; install the plugin for those agents").epilogue(helpEpilogue("--agent / -a is forwarded to plugins, or to skills and mcp, not both. It skips agent selection, including with --default.", helpCsv("Plugin agents", initPluginAgents()), helpCsv("Skills and MCP agents", initSkillsMcpAgents()))).strict();
|
|
82
83
|
const handler = async (props) => {
|
|
83
84
|
if (props.listTemplates) {
|
|
84
85
|
const templates = await fetchTemplates();
|
|
@@ -215,7 +216,6 @@ const runPostScaffoldSteps = async (props, targetDir, interactive, template, nam
|
|
|
215
216
|
const agentSetup = props.agentSetup === false ? "skip" : named.length > 0 ? chooseYesAgentTooling(named).setup : await (props.pickAgentSetup ?? pickAgentSetupInteractively)();
|
|
216
217
|
const canLink = props.link && !(neonConfig && !wantInstall);
|
|
217
218
|
if (props.link && !canLink) logSkippedLink(pm);
|
|
218
|
-
const wantLink = canLink && await confirm(`Link this project to a Neon project now? (runs ${getCliName()} link)`);
|
|
219
219
|
const outcome = await executePostScaffold(props, targetDir, {
|
|
220
220
|
yes: false,
|
|
221
221
|
lockAgentSetup: named.length === 0,
|
|
@@ -223,7 +223,7 @@ const runPostScaffoldSteps = async (props, targetDir, interactive, template, nam
|
|
|
223
223
|
git: wantGit,
|
|
224
224
|
agentSetup,
|
|
225
225
|
install: wantInstall,
|
|
226
|
-
link:
|
|
226
|
+
link: canLink,
|
|
227
227
|
hasNeonConfig: neonConfig,
|
|
228
228
|
named
|
|
229
229
|
});
|
|
@@ -239,9 +239,8 @@ const runPostScaffoldSteps = async (props, targetDir, interactive, template, nam
|
|
|
239
239
|
return nestedResult(template, targetDir, neonConfig, outcome);
|
|
240
240
|
};
|
|
241
241
|
const installPrompt = (inferred) => inferred ? `Install dependencies with ${inferred}?` : "Install dependencies?";
|
|
242
|
-
/** `link --yes` still asks for a project unless one is already linked. */
|
|
243
242
|
const runDefaultSteps = async (props, targetDir, pm, neonConfig, template, named) => {
|
|
244
|
-
log.info("Quick start (--default): skipping the template, install, git, and agent pickers.
|
|
243
|
+
log.info("Quick start (--default): skipping the template, install, git, and agent pickers. Project selection may still be required.");
|
|
245
244
|
const wantGit = props.git && !isGitRepo(targetDir);
|
|
246
245
|
const agentSetup = props.agentSetup === false ? "skip" : named.length > 0 ? chooseYesAgentTooling(named).setup : "skills-mcp";
|
|
247
246
|
const outcome = await executePostScaffold(props, targetDir, {
|
|
@@ -322,12 +321,26 @@ const executePostScaffold = async (props, targetDir, choices) => {
|
|
|
322
321
|
logSkippedLink(choices.pm);
|
|
323
322
|
continue;
|
|
324
323
|
}
|
|
325
|
-
await
|
|
324
|
+
if (!(choices.yes || await (props.pickLink ?? pickInitLinkInteractively)())) continue;
|
|
325
|
+
await (props.linkProject ?? runAuthenticatedLink)({
|
|
326
|
+
apiClient: props.apiClient,
|
|
327
|
+
apiKey: props.apiKey,
|
|
328
|
+
apiHost: props.apiHost,
|
|
329
|
+
output: props.output,
|
|
330
|
+
contextFile: projectContextFile(targetDir, props.contextFile),
|
|
326
331
|
yes: choices.yes,
|
|
327
|
-
|
|
328
|
-
|
|
332
|
+
clear: false,
|
|
333
|
+
checks: true,
|
|
334
|
+
envPull: true,
|
|
335
|
+
config: props.linkNoConfig !== true,
|
|
329
336
|
cwd: targetDir,
|
|
330
|
-
...
|
|
337
|
+
...props.linkInputs,
|
|
338
|
+
...props.configDir ? { configDir: props.configDir } : {},
|
|
339
|
+
...props.profile ? { profile: props.profile } : {},
|
|
340
|
+
...props.oauthHost ? { oauthHost: props.oauthHost } : {},
|
|
341
|
+
...props.clientId ? { clientId: props.clientId } : {},
|
|
342
|
+
...props.forceAuth !== void 0 ? { forceAuth: props.forceAuth } : {},
|
|
343
|
+
...props.allowUnsafeTls !== void 0 ? { allowUnsafeTls: props.allowUnsafeTls } : {}
|
|
331
344
|
});
|
|
332
345
|
linked = true;
|
|
333
346
|
}
|
|
@@ -3,13 +3,13 @@ import { log } from "../log.js";
|
|
|
3
3
|
import { retryOnLock } from "../api.js";
|
|
4
4
|
import { contextBranch, readContextFile } from "../context.js";
|
|
5
5
|
import { writer } from "../writer.js";
|
|
6
|
-
import { branchCreateRequest } from "../parameters.gen.js";
|
|
7
6
|
import { EndpointType } from "../utils/api_enums.js";
|
|
8
|
-
import { getComputeUnits } from "../utils/compute_units.js";
|
|
9
7
|
import { looksLikeBranchId, looksLikeLSN, looksLikeTimestamp } from "../utils/formats.js";
|
|
10
8
|
import { branchIdFromProps, branchIdResolve, fillSingleProject } from "../utils/enrichers.js";
|
|
11
|
-
import {
|
|
9
|
+
import { branchCreateRequest } from "../parameters.gen.js";
|
|
10
|
+
import { getComputeUnits } from "../utils/compute_units.js";
|
|
12
11
|
import { psql } from "../utils/psql.js";
|
|
12
|
+
import { parsePointInTime } from "../utils/point_in_time.js";
|
|
13
13
|
import { parseSchemaDiffParams, schemaDiff } from "./schema_diff.js";
|
|
14
14
|
//#region src/commands/branches.ts
|
|
15
15
|
var branches_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -4,9 +4,9 @@ import { log } from "../log.js";
|
|
|
4
4
|
import { isNeonApiError } from "../api.js";
|
|
5
5
|
import { applyContext, contextBranch, readContextFile } from "../context.js";
|
|
6
6
|
import { getCliName } from "../utils/cli_name.js";
|
|
7
|
+
import { createBranch, pickBranchInteractively } from "../utils/branch_picker.js";
|
|
7
8
|
import { looksLikeBranchId } from "../utils/formats.js";
|
|
8
9
|
import { fillSingleProject } from "../utils/enrichers.js";
|
|
9
|
-
import { createBranch, pickBranchInteractively } from "../utils/branch_picker.js";
|
|
10
10
|
import { autoPullEnvAfterPin } from "./env.js";
|
|
11
11
|
import { applyPolicyOnCreate, createBranchFromPolicyOnCheckout, envFlag } from "./config.js";
|
|
12
12
|
import { handler as handler$1 } from "./link.js";
|
package/dist/commands/claim.js
CHANGED
|
@@ -3,12 +3,12 @@ import { isCi } from "../env.js";
|
|
|
3
3
|
import { log } from "../log.js";
|
|
4
4
|
import { getApiClient } from "../api.js";
|
|
5
5
|
import { applyContext, contextBranch, readContextFile } from "../context.js";
|
|
6
|
-
import { claimableDataApiCreateBody, declaredNeonServices } from "../config_services.js";
|
|
7
|
-
import { NEON_SERVICES, deprecatedServiceMessage, parseServices, servicesFlagValue, servicesOption } from "../neon_services.js";
|
|
8
|
-
import { resolveEnvFilePath } from "../env_file.js";
|
|
9
6
|
import { t as credentialInputs } from "../_chunks/auth_selection-pitMFzDe.js";
|
|
10
7
|
import { ClaimableClient, ClaimableServiceError } from "../claimable/api.js";
|
|
11
8
|
import { assertionHasExpired, listClaimableCredentials, readClaimableCredentials, readLinkedClaimableCredentials, removeClaimableCredentials, writeClaimableCredentials } from "../claimable/state.js";
|
|
9
|
+
import { claimableDataApiCreateBody, declaredNeonServices } from "../config_services.js";
|
|
10
|
+
import { NEON_SERVICES, deprecatedServiceMessage, parseServices, servicesFlagValue, servicesOption } from "../neon_services.js";
|
|
11
|
+
import { resolveEnvFilePath } from "../env_file.js";
|
|
12
12
|
import { writer } from "../writer.js";
|
|
13
13
|
import { noPassthrough } from "../utils/flags.js";
|
|
14
14
|
import { pull } from "./env.js";
|
package/dist/commands/config.js
CHANGED
|
@@ -10,11 +10,11 @@ import { deprecatedServiceMessage, parseServices, servicesFlagValue, servicesOpt
|
|
|
10
10
|
import { CONFIG_INIT_NONE_MEANS, CONFIG_INIT_SERVICES, CONFIG_INIT_UNAVAILABLE, FUNCTION_FILENAME, FUNCTION_SLUG, FUNCTION_TEMPLATE, REQUIRED_PACKAGES, renderNeonConfig, renderNeonConfigFromView } from "../config_template.js";
|
|
11
11
|
import { loadEnvFileIntoProcess } from "../env_file.js";
|
|
12
12
|
import { writer } from "../writer.js";
|
|
13
|
-
import { formatInstallCommand, installArgs, resolvePackageManager, runCommand } from "../utils/package_manager.js";
|
|
14
|
-
import { fillSingleProject, resolveBranchRef } from "../utils/enrichers.js";
|
|
15
13
|
import { assertAiGatewayProvisionable, warnAiGateway } from "../utils/ai_gateway_notice.js";
|
|
16
14
|
import { announceTargetBranch } from "../utils/branch_notice.js";
|
|
17
15
|
import { renderAppliedChanges, renderBranchSettingConflicts } from "../utils/config_diff.js";
|
|
16
|
+
import { fillSingleProject, resolveBranchRef } from "../utils/enrichers.js";
|
|
17
|
+
import { formatInstallCommand, installArgs, resolvePackageManager, runCommand } from "../utils/package_manager.js";
|
|
18
18
|
import { bundleEntry } from "../utils/esbuild.js";
|
|
19
19
|
import { pickServicesInteractively } from "../utils/service_picker.js";
|
|
20
20
|
import { zipBundle } from "../utils/zip.js";
|
|
@@ -2,8 +2,8 @@ import { t as __exportAll } from "../_chunks/rolldown-runtime-8H4AJuhK.js";
|
|
|
2
2
|
import { writer } from "../writer.js";
|
|
3
3
|
import { EndpointType } from "../utils/api_enums.js";
|
|
4
4
|
import { branchIdFromProps, fillSingleProject } from "../utils/enrichers.js";
|
|
5
|
-
import { parsePITBranch } from "../utils/point_in_time.js";
|
|
6
5
|
import { psql } from "../utils/psql.js";
|
|
6
|
+
import { parsePITBranch } from "../utils/point_in_time.js";
|
|
7
7
|
//#region src/commands/connection_string.ts
|
|
8
8
|
var connection_string_exports = /* @__PURE__ */ __exportAll({
|
|
9
9
|
SSL_MODES: () => SSL_MODES,
|