neon 8.6.1 → 8.7.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/dist/api.js CHANGED
@@ -669,6 +669,13 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
669
669
  database_name: databaseName
670
670
  }
671
671
  })),
672
+ getProjectBranchRealtime: (projectId, branchId) => call(() => raw.getProjectBranchRealtime({
673
+ client,
674
+ path: {
675
+ project_id: projectId,
676
+ branch_id: branchId
677
+ }
678
+ })),
672
679
  enableProjectBranchRealtime: (projectId, branchId, data) => call(() => raw.enableProjectBranchRealtime({
673
680
  client,
674
681
  path: {
@@ -684,6 +691,13 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
684
691
  branch_id: branchId
685
692
  }
686
693
  })),
694
+ rotateProjectBranchRealtimeSecret: (projectId, branchId) => call(() => raw.rotateProjectBranchRealtimeSecret({
695
+ client,
696
+ path: {
697
+ project_id: projectId,
698
+ branch_id: branchId
699
+ }
700
+ })),
687
701
  listProjectVpcEndpoints: (projectId) => call(() => raw.listProjectVpcEndpoints({
688
702
  client,
689
703
  path: { project_id: projectId }
@@ -1,6 +1,7 @@
1
1
  import { t as __exportAll } from "../_chunks/rolldown-runtime-8H4AJuhK.js";
2
2
  import { log } from "../log.js";
3
3
  import { retryOnLock } from "../api.js";
4
+ import { getCliName } from "../utils/cli_name.js";
4
5
  import { branchIdFromProps, fillSingleProject } from "../utils/enrichers.js";
5
6
  import { builder as builder$1, handler as handler$1 } from "./subscribe.js";
6
7
  import { defineConfig } from "@neon/config";
@@ -11,8 +12,11 @@ var realtime_exports = /* @__PURE__ */ __exportAll({
11
12
  describe: () => describe,
12
13
  disable: () => disable,
13
14
  enable: () => enable,
14
- handler: () => handler
15
+ handler: () => handler,
16
+ rotateSecret: () => rotateSecret
15
17
  });
18
+ const ROTATION_POLL_INTERVAL_MS = Number(process.env.NEON_REALTIME_POLL_INTERVAL_MS) || 1e3;
19
+ const ROTATION_POLL_TIMEOUT_MS = Number(process.env.NEON_REALTIME_POLL_TIMEOUT_MS) || 6e4;
16
20
  /** Request Realtime provisioning or an allowed-origin update for a branch. */
17
21
  const enable = async (props) => {
18
22
  const realtime = props.allowedOrigins === void 0 ? true : { allowedOrigins: props.allowedOrigins };
@@ -27,6 +31,26 @@ const disable = async (props) => {
27
31
  await retryOnLock(() => props.apiClient.disableProjectBranchRealtime(props.projectId, branchId));
28
32
  log.info("Realtime disable requested for branch %s.", branchId);
29
33
  };
34
+ /** Request replacement of a branch's Realtime shared secret. */
35
+ const rotateSecret = async (props) => {
36
+ const branchId = await branchIdFromProps(props);
37
+ await retryOnLock(() => props.apiClient.rotateProjectBranchRealtimeSecret(props.projectId, branchId));
38
+ log.info("Realtime secret rotation requested for branch %s.", branchId);
39
+ if (!props.wait) return;
40
+ const deadline = Date.now() + ROTATION_POLL_TIMEOUT_MS;
41
+ do {
42
+ const { data } = await props.apiClient.getProjectBranchRealtime(props.projectId, branchId);
43
+ if (!data.pending) {
44
+ log.info("Realtime secret rotation completed for branch %s.", branchId);
45
+ log.info("Run %s env pull --service realtime to update NEON_REALTIME_SECRET.", getCliName());
46
+ return;
47
+ }
48
+ const remainingMs = deadline - Date.now();
49
+ if (remainingMs <= 0) break;
50
+ await new Promise((resolve) => setTimeout(resolve, Math.min(ROTATION_POLL_INTERVAL_MS, remainingMs)));
51
+ } while (Date.now() < deadline);
52
+ throw new Error(`Timed out waiting for Realtime secret rotation on branch ${branchId}. It may still be in progress.`);
53
+ };
30
54
  const command = "realtime";
31
55
  const describe = "Manage Neon Realtime for a branch";
32
56
  const builder = (argv) => argv.usage("$0 realtime <sub-command> [options]").options({
@@ -45,7 +69,11 @@ const builder = (argv) => argv.usage("$0 realtime <sub-command> [options]").opti
45
69
  }), (args) => enable({
46
70
  ...args,
47
71
  ...args.allowedOrigin !== void 0 ? { allowedOrigins: args.allowedOrigin } : {}
48
- })).command("disable", "Disable Realtime on a branch", (yargs) => yargs.strict(), (args) => disable(args)).command("subscribe <query>", "Subscribe to a live SQL query with Neon Realtime", builder$1, handler$1);
72
+ })).command("disable", "Disable Realtime on a branch", (yargs) => yargs.strict(), (args) => disable(args)).command("rotate-secret", "Replace a branch's Realtime shared secret", (yargs) => yargs.strict().option("wait", {
73
+ describe: "Wait for the Realtime secret rotation to finish",
74
+ type: "boolean",
75
+ default: true
76
+ }), (args) => rotateSecret(args)).command("subscribe <query>", "Subscribe to a live SQL query with Neon Realtime", builder$1, handler$1);
49
77
  const handler = (_args) => {};
50
78
  //#endregion
51
- export { builder, command, describe, disable, enable, handler, realtime_exports as t };
79
+ export { builder, command, describe, disable, enable, handler, rotateSecret, realtime_exports as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "8.6.1",
3
+ "version": "8.7.0",
4
4
  "description": "CLI tool for Neon, the cloud backend primitives built around Lakebase Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -71,9 +71,9 @@
71
71
  "yargs": "17.7.2",
72
72
  "yoctocolors": "^2.1.2",
73
73
  "@neon/config": "1.9.1",
74
- "@neon/config-runtime": "1.10.0",
75
74
  "@neon/realtime": "0.1.0",
76
- "@neon/sdk": "7.2.0"
75
+ "@neon/sdk": "7.2.0",
76
+ "@neon/config-runtime": "1.10.0"
77
77
  },
78
78
  "optionalDependencies": {
79
79
  "@napi-rs/keyring": "1.3.0",