@neon/sdk 0.0.0 → 0.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 (151) hide show
  1. package/LICENSE.md +178 -0
  2. package/README.md +349 -0
  3. package/dist/_virtual/_rolldown/runtime.js +13 -0
  4. package/dist/client/client/client.gen.d.ts +7 -0
  5. package/dist/client/client/client.gen.d.ts.map +1 -0
  6. package/dist/client/client/client.gen.js +176 -0
  7. package/dist/client/client/client.gen.js.map +1 -0
  8. package/dist/client/client/index.d.ts +10 -0
  9. package/dist/client/client/index.js +6 -0
  10. package/dist/client/client/types.gen.d.ts +124 -0
  11. package/dist/client/client/types.gen.d.ts.map +1 -0
  12. package/dist/client/client/types.gen.js +1 -0
  13. package/dist/client/client/utils.gen.d.ts +42 -0
  14. package/dist/client/client/utils.gen.d.ts.map +1 -0
  15. package/dist/client/client/utils.gen.js +179 -0
  16. package/dist/client/client/utils.gen.js.map +1 -0
  17. package/dist/client/client.gen.d.ts +18 -0
  18. package/dist/client/client.gen.d.ts.map +1 -0
  19. package/dist/client/client.gen.js +8 -0
  20. package/dist/client/client.gen.js.map +1 -0
  21. package/dist/client/core/auth.gen.d.ts +29 -0
  22. package/dist/client/core/auth.gen.d.ts.map +1 -0
  23. package/dist/client/core/auth.gen.js +12 -0
  24. package/dist/client/core/auth.gen.js.map +1 -0
  25. package/dist/client/core/bodySerializer.gen.d.ts +29 -0
  26. package/dist/client/core/bodySerializer.gen.d.ts.map +1 -0
  27. package/dist/client/core/bodySerializer.gen.js +33 -0
  28. package/dist/client/core/bodySerializer.gen.js.map +1 -0
  29. package/dist/client/core/params.gen.d.ts +46 -0
  30. package/dist/client/core/params.gen.d.ts.map +1 -0
  31. package/dist/client/core/params.gen.js +65 -0
  32. package/dist/client/core/params.gen.js.map +1 -0
  33. package/dist/client/core/pathSerializer.gen.d.ts +52 -0
  34. package/dist/client/core/pathSerializer.gen.d.ts.map +1 -0
  35. package/dist/client/core/pathSerializer.gen.js +82 -0
  36. package/dist/client/core/pathSerializer.gen.js.map +1 -0
  37. package/dist/client/core/queryKeySerializer.gen.d.ts +22 -0
  38. package/dist/client/core/queryKeySerializer.gen.d.ts.map +1 -0
  39. package/dist/client/core/queryKeySerializer.gen.js +64 -0
  40. package/dist/client/core/queryKeySerializer.gen.js.map +1 -0
  41. package/dist/client/core/serverSentEvents.gen.d.ts +88 -0
  42. package/dist/client/core/serverSentEvents.gen.d.ts.map +1 -0
  43. package/dist/client/core/serverSentEvents.gen.js +95 -0
  44. package/dist/client/core/serverSentEvents.gen.js.map +1 -0
  45. package/dist/client/core/types.gen.d.ts +80 -0
  46. package/dist/client/core/types.gen.d.ts.map +1 -0
  47. package/dist/client/core/types.gen.js +1 -0
  48. package/dist/client/core/utils.gen.d.ts +33 -0
  49. package/dist/client/core/utils.gen.d.ts.map +1 -0
  50. package/dist/client/core/utils.gen.js +78 -0
  51. package/dist/client/core/utils.gen.js.map +1 -0
  52. package/dist/client/index.d.ts +3 -0
  53. package/dist/client/index.js +2 -0
  54. package/dist/client/sdk.gen.d.ts +1362 -0
  55. package/dist/client/sdk.gen.d.ts.map +1 -0
  56. package/dist/client/sdk.gen.js +4315 -0
  57. package/dist/client/sdk.gen.js.map +1 -0
  58. package/dist/client/types.gen.d.ts +9938 -0
  59. package/dist/client/types.gen.d.ts.map +1 -0
  60. package/dist/client/types.gen.js +1 -0
  61. package/dist/index.d.ts +19 -0
  62. package/dist/index.js +4 -0
  63. package/dist/neon/client.d.ts +52 -0
  64. package/dist/neon/client.d.ts.map +1 -0
  65. package/dist/neon/client.js +40 -0
  66. package/dist/neon/client.js.map +1 -0
  67. package/dist/neon/config.d.ts +40 -0
  68. package/dist/neon/config.d.ts.map +1 -0
  69. package/dist/neon/config.js +23 -0
  70. package/dist/neon/config.js.map +1 -0
  71. package/dist/neon/connection.d.ts +22 -0
  72. package/dist/neon/connection.d.ts.map +1 -0
  73. package/dist/neon/connection.js +33 -0
  74. package/dist/neon/connection.js.map +1 -0
  75. package/dist/neon/context.d.ts +50 -0
  76. package/dist/neon/context.d.ts.map +1 -0
  77. package/dist/neon/context.js +59 -0
  78. package/dist/neon/context.js.map +1 -0
  79. package/dist/neon/coverage.d.ts +26 -0
  80. package/dist/neon/coverage.d.ts.map +1 -0
  81. package/dist/neon/coverage.js +229 -0
  82. package/dist/neon/coverage.js.map +1 -0
  83. package/dist/neon/errors.d.ts +78 -0
  84. package/dist/neon/errors.d.ts.map +1 -0
  85. package/dist/neon/errors.js +116 -0
  86. package/dist/neon/errors.js.map +1 -0
  87. package/dist/neon/paginate.d.ts +34 -0
  88. package/dist/neon/paginate.d.ts.map +1 -0
  89. package/dist/neon/paginate.js +51 -0
  90. package/dist/neon/paginate.js.map +1 -0
  91. package/dist/neon/resources/account.d.ts +45 -0
  92. package/dist/neon/resources/account.d.ts.map +1 -0
  93. package/dist/neon/resources/account.js +65 -0
  94. package/dist/neon/resources/account.js.map +1 -0
  95. package/dist/neon/resources/branches.d.ts +84 -0
  96. package/dist/neon/resources/branches.d.ts.map +1 -0
  97. package/dist/neon/resources/branches.js +132 -0
  98. package/dist/neon/resources/branches.js.map +1 -0
  99. package/dist/neon/resources/consumption.d.ts +22 -0
  100. package/dist/neon/resources/consumption.d.ts.map +1 -0
  101. package/dist/neon/resources/consumption.js +59 -0
  102. package/dist/neon/resources/consumption.js.map +1 -0
  103. package/dist/neon/resources/dataapi.d.ts +25 -0
  104. package/dist/neon/resources/dataapi.d.ts.map +1 -0
  105. package/dist/neon/resources/dataapi.js +59 -0
  106. package/dist/neon/resources/dataapi.js.map +1 -0
  107. package/dist/neon/resources/databases.d.ts +30 -0
  108. package/dist/neon/resources/databases.d.ts.map +1 -0
  109. package/dist/neon/resources/databases.js +68 -0
  110. package/dist/neon/resources/databases.js.map +1 -0
  111. package/dist/neon/resources/endpoints.d.ts +39 -0
  112. package/dist/neon/resources/endpoints.d.ts.map +1 -0
  113. package/dist/neon/resources/endpoints.js +89 -0
  114. package/dist/neon/resources/endpoints.js.map +1 -0
  115. package/dist/neon/resources/operations.d.ts +27 -0
  116. package/dist/neon/resources/operations.d.ts.map +1 -0
  117. package/dist/neon/resources/operations.js +50 -0
  118. package/dist/neon/resources/operations.js.map +1 -0
  119. package/dist/neon/resources/postgres.d.ts +45 -0
  120. package/dist/neon/resources/postgres.d.ts.map +1 -0
  121. package/dist/neon/resources/postgres.js +104 -0
  122. package/dist/neon/resources/postgres.js.map +1 -0
  123. package/dist/neon/resources/projects.d.ts +84 -0
  124. package/dist/neon/resources/projects.d.ts.map +1 -0
  125. package/dist/neon/resources/projects.js +111 -0
  126. package/dist/neon/resources/projects.js.map +1 -0
  127. package/dist/neon/resources/roles.d.ts +40 -0
  128. package/dist/neon/resources/roles.d.ts.map +1 -0
  129. package/dist/neon/resources/roles.js +78 -0
  130. package/dist/neon/resources/roles.js.map +1 -0
  131. package/dist/neon/resources/snapshots.d.ts +86 -0
  132. package/dist/neon/resources/snapshots.d.ts.map +1 -0
  133. package/dist/neon/resources/snapshots.js +125 -0
  134. package/dist/neon/resources/snapshots.js.map +1 -0
  135. package/dist/neon/result.d.ts +32 -0
  136. package/dist/neon/result.d.ts.map +1 -0
  137. package/dist/neon/result.js +26 -0
  138. package/dist/neon/result.js.map +1 -0
  139. package/dist/neon/retry.d.ts +17 -0
  140. package/dist/neon/retry.d.ts.map +1 -0
  141. package/dist/neon/retry.js +42 -0
  142. package/dist/neon/retry.js.map +1 -0
  143. package/dist/neon/wait.d.ts +27 -0
  144. package/dist/neon/wait.d.ts.map +1 -0
  145. package/dist/neon/wait.js +70 -0
  146. package/dist/neon/wait.js.map +1 -0
  147. package/dist/raw.d.ts +13 -0
  148. package/dist/raw.d.ts.map +1 -0
  149. package/dist/raw.js +159 -0
  150. package/dist/raw.js.map +1 -0
  151. package/package.json +57 -16
package/LICENSE.md ADDED
@@ -0,0 +1,178 @@
1
+ # Apache License 2.0
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,349 @@
1
+ # @neon/sdk
2
+
3
+ The official TypeScript SDK for the [Neon API](https://api-docs.neon.tech/reference) — a modern, **Fetch-based**, **zero-dependency**, ESM-only client generated from Neon's [OpenAPI specification](https://neon.com/api_spec/release/v2.json). Successor to [`@neondatabase/api-client`](https://www.npmjs.com/package/@neondatabase/api-client).
4
+
5
+ Two layers, one package:
6
+
7
+ - **`createNeonClient`** — an ergonomic client (auth once, `{ data, error }` results, typed errors, retries, readiness polling, auto-pagination, workflows), organized into resource namespaces.
8
+ - **`raw`** — the full generated 1:1 surface: every endpoint as a standalone, tree-shakeable function. Also at the `@neon/sdk/raw` subpath.
9
+
10
+ ---
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install @neon/sdk
16
+ ```
17
+
18
+ Requires Node.js ≥ 22 (or any runtime with a global `fetch` — Bun, Deno, edge, browser).
19
+
20
+ ## Quick start
21
+
22
+ ```ts
23
+ import { createNeonClient } from "@neon/sdk";
24
+
25
+ const neon = createNeonClient({ apiKey: process.env.NEON_API_KEY! });
26
+
27
+ // create a project and get a ready-to-use connection string
28
+ const { data, error } = await neon.projects.createAndConnect({ name: "my-app" });
29
+ if (error) throw error;
30
+ const { project, connectionString } = data;
31
+ ```
32
+
33
+ ---
34
+
35
+ ## Client configuration
36
+
37
+ `createNeonClient(config)`:
38
+
39
+ | Option | Type | Default | Description |
40
+ | --- | --- | --- | --- |
41
+ | `apiKey` | `string \| (() => string \| Promise<string>)` | — (required) | Neon API key, or a function returning it (sync/async). Sent as a Bearer token. |
42
+ | `throwOnError` | `boolean` | `false` | When `true`, methods return the resource directly and **throw** on error. When `false`, they return `{ data, error }`. **Narrows return types** at the type level. |
43
+ | `waitForReadiness` | `boolean` | `false` | When `true`, mutations block until their provisioning `operations` finish, so the returned resource is ready to use. |
44
+ | `wait` | `{ pollIntervalMs?: number; timeoutMs?: number }` | `1000` / `300000` | Tuning for the readiness poller. |
45
+ | `retries` | `number` | `2` | Automatic retries on always-safe statuses (`423`, `429`, `503`) with backoff. |
46
+ | `orgId` | `string` | — | Default organization, applied to project create/list and as the transfer source org. Overridable per call. |
47
+ | `baseUrl` | `string` | `https://console.neon.tech/api/v2` | Override the API base URL. |
48
+ | `fetch` | `typeof fetch` | global `fetch` | Custom fetch implementation (proxies, tests, non-global runtimes). |
49
+
50
+ Every option except `apiKey` is also accepted **per call** via the last `options` argument (`{ throwOnError?, waitForReadiness?, signal? }`), overriding the client default.
51
+
52
+ ## The result model
53
+
54
+ By default every method resolves to a discriminated `{ data, error }` envelope — no `try/catch` needed:
55
+
56
+ ```ts
57
+ const { data, error } = await neon.projects.get("late-frost-12345");
58
+ if (error) {
59
+ // error is a typed NeonError union
60
+ return;
61
+ }
62
+ data; // narrowed to Project
63
+ ```
64
+
65
+ Set `throwOnError` (on the client or per call) to get the bare resource and throw instead — and the **return types narrow accordingly**:
66
+
67
+ ```ts
68
+ const neon = createNeonClient({ apiKey, throwOnError: true });
69
+ const project = await neon.projects.get("…"); // Project (throws on error)
70
+ const res = await neon.projects.get("…", { throwOnError: false }); // { data, error }
71
+ ```
72
+
73
+ ## Errors
74
+
75
+ The `error` channel carries a typed hierarchy (all `Error` subclasses with a `kind` discriminant); the same value is thrown when `throwOnError` is set.
76
+
77
+ | Class | `kind` | Notable fields |
78
+ | --- | --- | --- |
79
+ | `NeonError` | (base) | `message`, `kind` |
80
+ | `NeonApiError` | `"api"` | `status`, `code`, `requestId`, `response`, `body` |
81
+ | `NeonNotFoundError` | `"not_found"` | (404) — extends `NeonApiError` |
82
+ | `NeonAuthError` | `"auth"` | (401/403) |
83
+ | `NeonRateLimitError` | `"rate_limit"` | (429, after retries) |
84
+ | `NeonOperationError` | `"operation"` | `operationId`, `status` — an awaited operation failed |
85
+ | `NeonTimeoutError` | `"timeout"` | readiness/wait deadline exceeded |
86
+ | `NeonNetworkError` | `"network"` | transport failure (no response) |
87
+ | `NeonError` | `"client"` | SDK-side errors (e.g. ambiguous connection-string selection) |
88
+
89
+ ```ts
90
+ const { error } = await neon.branches.get(pid, "nope");
91
+ if (error?.kind === "not_found") { /* … */ }
92
+ ```
93
+
94
+ ## Pagination
95
+
96
+ Cursor-paginated `list()` methods return a lazy `Paginated<T>`:
97
+
98
+ ```ts
99
+ const { data: all } = await neon.projects.list().all(); // every page → { data, error }
100
+ const { data: page } = await neon.projects.list().page(); // one page
101
+ for await (const project of neon.projects.list()) { … } // stream; throws on a page error
102
+ ```
103
+
104
+ ## Readiness & workflows
105
+
106
+ Neon mutations are asynchronous (they return `operations`). `waitForReadiness` blocks until they settle; the **workflow** methods (`createAndConnect`, `createWithCompute`) default it on and hand back a connection string in one call. The primitive is `neon.operations.waitFor(operations)`.
107
+
108
+ ---
109
+
110
+ ## API reference
111
+
112
+ Legend: **[P]** returns `Paginated<T>` · **[W]** workflow (multi-step) · **→void** resolves to `void`. Unless noted, methods take an optional trailing `options` arg and resolve to the resource (or `{ data, error }`).
113
+
114
+ ### `neon.projects`
115
+
116
+ | Method | Returns | Notes |
117
+ | --- | --- | --- |
118
+ | `list(query?)` | **[P]** `ProjectListItem` | `query`: `{ search?, org_id?, limit? }` (cursor managed for you) |
119
+ | `get(id)` | `Project` | |
120
+ | `create(input?)` | `Project` | `input`: `{ name?, region_id?, pg_version?, org_id?, autoscaling_limit_min_cu?, autoscaling_limit_max_cu?, settings? }` |
121
+ | `createAndConnect(input?, { pooled? })` | **[W]** `{ project, connectionString }` | one call + readiness; `pooled` default `true` |
122
+ | `update(id, input)` | `Project` | `input`: `{ name?, settings? }` |
123
+ | `delete(id)` | `Project` | |
124
+ | `transfer({ fromOrgId?, toOrgId, projectIds })` | **→void** | `fromOrgId` defaults to client `orgId` |
125
+ | `transferFromUser({ toOrgId, projectIds })` | **→void** | personal account → org |
126
+
127
+ ```ts
128
+ // Provision a project and get a pooled connection string in one call
129
+ const { data } = await neon.projects.createAndConnect(
130
+ { name: "tenant-42", region_id: "aws-us-east-1" },
131
+ { pooled: true },
132
+ );
133
+ // data: { project, connectionString }
134
+
135
+ // Upgrade path: move projects from the sponsored org to the paid org
136
+ await neon.projects.transfer({
137
+ fromOrgId: sponsoredOrgId, // defaults to the client's `orgId`
138
+ toOrgId: paidOrgId,
139
+ projectIds: ["late-frost-12345"],
140
+ });
141
+ ```
142
+
143
+ ### `neon.branches`
144
+
145
+ | Method | Returns | Notes |
146
+ | --- | --- | --- |
147
+ | `list(projectId, query?)` | **[P]** `Branch` | `query`: `{ search?, sort_by?, sort_order? }` |
148
+ | `get(projectId, branchId)` | `Branch` | |
149
+ | `create(projectId, input?)` | `Branch` | `input`: `{ name?, parent_id?, parent_lsn?, parent_timestamp?, protected? }` |
150
+ | `update(projectId, branchId, input)` | `Branch` | `input`: `{ name?, protected?, expires_at? }` |
151
+ | `delete(projectId, branchId)` | **→void** | |
152
+ | `createWithCompute(projectId, input, { pooled? })` | **[W]** `{ branch, endpoint, connectionString }` | `input`: `{ name?, parentId?, compute?: { minCu?, maxCu?, suspendTimeoutSeconds? } }` |
153
+ | `getDefault(projectId)` | `Branch` | resolves the default branch by the `default` flag |
154
+ | `setDefault(projectId, branchId)` | `Branch` | |
155
+ | `finalizeRestore(projectId, branchId, { name? }?)` | **→void** | commits a restore previewed with `snapshots.restore({ finalize: false })` |
156
+
157
+ ```ts
158
+ // Resolve the project's default ("production") branch
159
+ const { data: prod } = await neon.branches.getDefault(projectId);
160
+
161
+ // Branch off it with its own compute — returns a ready connection string
162
+ const { data } = await neon.branches.createWithCompute(projectId, {
163
+ name: "preview/pr-123",
164
+ parentId: prod?.id,
165
+ compute: { minCu: 0.25, maxCu: 2 },
166
+ });
167
+ // data: { branch, endpoint, connectionString }
168
+ ```
169
+
170
+ ### `neon.postgres`
171
+
172
+ The Postgres data plane of a branch. `neon.postgres.connectionString(params, options?)` resolves a URI, **auto-selecting** the default branch and the sole role/database when omitted:
173
+
174
+ ```ts
175
+ const { data: uri } = await neon.postgres.connectionString({
176
+ projectId,
177
+ branchId?, endpointId?, databaseName?, roleName?, pooled?, // all optional; pooled default true
178
+ });
179
+ ```
180
+
181
+ #### `neon.postgres.endpoints`
182
+
183
+ | Method | Returns |
184
+ | --- | --- |
185
+ | `list(projectId)` | `Endpoint[]` |
186
+ | `get(projectId, endpointId)` | `Endpoint` |
187
+ | `create(projectId, input)` | `Endpoint` — `input`: `{ branch_id, type, autoscaling_limit_min_cu?, autoscaling_limit_max_cu?, suspend_timeout_seconds?, provisioner? }` |
188
+ | `update(projectId, endpointId, input)` | `Endpoint` |
189
+ | `delete(projectId, endpointId)` | **→void** |
190
+ | `start` / `suspend` / `restart(projectId, endpointId)` | `Endpoint` |
191
+
192
+ #### `neon.postgres.roles`
193
+
194
+ | Method | Returns |
195
+ | --- | --- |
196
+ | `list(projectId, branchId)` | `Role[]` |
197
+ | `get(projectId, branchId, name)` | `Role` |
198
+ | `create(projectId, branchId, { name, no_login? })` | `Role` |
199
+ | `delete(projectId, branchId, name)` | **→void** |
200
+ | `password(projectId, branchId, name)` | `string` (reveals the password) |
201
+ | `resetPassword(projectId, branchId, name)` | `Role` (carries the new password) |
202
+
203
+ ```ts
204
+ // Reveal a role's password, or rotate it
205
+ const { data: password } = await neon.postgres.roles.password(projectId, branchId, "neondb_owner");
206
+ const { data: role } = await neon.postgres.roles.resetPassword(projectId, branchId, "neondb_owner");
207
+ // role.password holds the new secret
208
+ ```
209
+
210
+ #### `neon.postgres.databases`
211
+
212
+ | Method | Returns |
213
+ | --- | --- |
214
+ | `list(projectId, branchId)` | `Database[]` |
215
+ | `get(projectId, branchId, name)` | `Database` |
216
+ | `create(projectId, branchId, { name, owner_name })` | `Database` |
217
+ | `update(projectId, branchId, name, { name?, owner_name? })` | `Database` |
218
+ | `delete(projectId, branchId, name)` | **→void** |
219
+
220
+ #### `neon.postgres.dataApi`
221
+
222
+ | Method | Returns |
223
+ | --- | --- |
224
+ | `get(projectId, branchId, databaseName)` | `DataApiReponse` |
225
+ | `create(projectId, branchId, databaseName, input?)` | `DataApiCreateResponse` |
226
+ | `update(projectId, branchId, databaseName, input?)` | **→void** |
227
+ | `delete(projectId, branchId, databaseName)` | **→void** |
228
+
229
+ ### `neon.snapshots`
230
+
231
+ | Method | Returns | Notes |
232
+ | --- | --- | --- |
233
+ | `list(projectId)` | `Snapshot[]` | |
234
+ | `create(projectId, branchId, input?)` | `Snapshot` | `input`: `{ name?, timestamp?, lsn?, expiresAt? }` (point-in-time) |
235
+ | `update(projectId, snapshotId, { name? })` | `Snapshot` | |
236
+ | `delete(projectId, snapshotId)` | **→void** | |
237
+ | `restore(projectId, snapshotId, input?)` | `Branch` | see below |
238
+ | `getSchedule(projectId, branchId)` | `BackupSchedule` | |
239
+ | `setSchedule(projectId, branchId, schedule)` | **→void** | |
240
+
241
+ ```ts
242
+ // Snapshot a branch at a point in time (or an `lsn`), with a name + TTL
243
+ const { data: snapshot } = await neon.snapshots.create(projectId, branchId, {
244
+ name: "pre-migration",
245
+ timestamp: "2026-06-01T00:00:00Z",
246
+ expiresAt: "2026-07-01T00:00:00Z",
247
+ });
248
+ ```
249
+
250
+ `restore` input: `{ name?, targetBranchId?, finalize?, preview?, keepOnAbort? }`.
251
+ - Restoring **as a new branch** (no `targetBranchId`) finalizes by default → ready to use.
252
+ - Restoring **onto an existing branch** doesn't finalize by default, so you can preview first.
253
+ - **Transaction-style** with `preview`: it restores un-finalized, runs your callback against the restored branch, then **finalizes (commit)** if it returns `true` or **deletes the preview branch (abort)** if `false` (unless `keepOnAbort`):
254
+
255
+ ```ts
256
+ await neon.snapshots.restore(projectId, snapshotId, {
257
+ targetBranchId,
258
+ preview: async (branch) => (await checks(branch)) === "ok", // true → commit · false → abort
259
+ });
260
+ ```
261
+
262
+ ### `neon.operations`
263
+
264
+ | Method | Returns | Notes |
265
+ | --- | --- | --- |
266
+ | `list(projectId)` | **[P]** `Operation` | |
267
+ | `get(projectId, operationId)` | `Operation` | |
268
+ | `waitFor(operations, options?)` | **→void** | `options`: `{ pollIntervalMs?, timeoutMs?, signal? }` — the readiness primitive |
269
+
270
+ ```ts
271
+ // Wait on operations from a raw call (or when waitForReadiness is off)
272
+ const { data } = await raw.createProjectBranch({
273
+ client: neon.client,
274
+ path: { project_id: projectId },
275
+ body: { branch: { name: "wip" } },
276
+ });
277
+ const { error } = await neon.operations.waitFor(data!.operations, { timeoutMs: 120_000 });
278
+ ```
279
+
280
+ ### `neon.consumption`
281
+
282
+ Cursor-paginated billing metrics. Each takes `{ from, to, granularity, project_ids?, org_id? }` (`perBranchV2` requires `project_ids`).
283
+
284
+ | Method | Returns |
285
+ | --- | --- |
286
+ | `perProject(query)` | **[P]** `ConsumptionHistoryPerProject` |
287
+ | `perProjectV2(query)` | **[P]** `ConsumptionHistoryPerProjectV2` |
288
+ | `perBranchV2(query)` | **[P]** `ConsumptionHistoryPerBranchV2` |
289
+
290
+ ```ts
291
+ // Paginated consumption metrics — stream every project across the range
292
+ for await (const project of neon.consumption.perProject({
293
+ from: "2026-06-01T00:00:00Z",
294
+ to: "2026-06-30T00:00:00Z",
295
+ granularity: "daily",
296
+ })) {
297
+ console.log(project);
298
+ }
299
+ ```
300
+
301
+ ### `neon.apiKeys`
302
+
303
+ | Method | Returns | Notes |
304
+ | --- | --- | --- |
305
+ | `list()` | `ApiKeysListResponseItem[]` | |
306
+ | `create(keyName)` | `ApiKeyCreateResponse` | the `key` token is shown **once** |
307
+ | `revoke(keyId)` | `ApiKeyRevokeResponse` | |
308
+
309
+ ### `neon.regions` / `neon.user`
310
+
311
+ | Method | Returns |
312
+ | --- | --- |
313
+ | `regions.list()` | `RegionResponse[]` |
314
+ | `user.me()` | `CurrentUserInfoResponse` |
315
+ | `user.organizations()` | `Organization[]` |
316
+
317
+ ---
318
+
319
+ ## Raw layer (every endpoint, 1:1)
320
+
321
+ Anything not wrapped above is available raw. Pass `neon.client` to reuse the client's auth:
322
+
323
+ ```ts
324
+ import { raw } from "@neon/sdk";
325
+ // or, for guaranteed tree-shaking: import { getProjectBranchSchema } from "@neon/sdk/raw";
326
+
327
+ const { data } = await raw.getProjectBranchSchema({
328
+ client: neon.client,
329
+ path: { project_id, branch_id },
330
+ });
331
+ ```
332
+
333
+ `neon.client` is the underlying configured Fetch client; `raw.*` are the generated functions, and all request/response/error **types** are re-exported flat from `@neon/sdk` for `import type { Project, Branch, … }`.
334
+
335
+ ## Regenerating the client
336
+
337
+ The client is generated from a vendored, pinned copy of the spec in [`spec/neon-openapi.json`](./spec/neon-openapi.json) using [`@hey-api/openapi-ts`](https://heyapi.dev).
338
+
339
+ ```bash
340
+ pnpm --filter @neon/sdk spec:pull # refresh the vendored spec from neon.com
341
+ pnpm --filter @neon/sdk generate # regenerate src/client
342
+ pnpm --filter @neon/sdk build # typecheck + bundle
343
+ ```
344
+
345
+ A coverage test (`src/neon/coverage.test.ts`) fails CI whenever the generated operation set changes, so every new endpoint is consciously wrapped or left raw-only.
346
+
347
+ ## License
348
+
349
+ Apache-2.0
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll };
@@ -0,0 +1,7 @@
1
+ import { Client, Config } from "./types.gen.js";
2
+
3
+ //#region src/client/client/client.gen.d.ts
4
+ declare const createClient: (config?: Config) => Client;
5
+ //#endregion
6
+ export { createClient };
7
+ //# sourceMappingURL=client.gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.gen.d.ts","names":[],"sources":["../../../src/client/client/client.gen.ts"],"mappings":";;;cAqBa,wBAAwB,WAAc"}