@neondatabase/config-runtime 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 (43) hide show
  1. package/LICENSE.md +178 -0
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.js +6 -0
  4. package/dist/lib/function-bundle.d.ts +25 -0
  5. package/dist/lib/function-bundle.d.ts.map +1 -0
  6. package/dist/lib/function-bundle.js +65 -0
  7. package/dist/lib/function-bundle.js.map +1 -0
  8. package/dist/lib/operations.d.ts +70 -0
  9. package/dist/lib/operations.d.ts.map +1 -0
  10. package/dist/lib/operations.js +60 -0
  11. package/dist/lib/operations.js.map +1 -0
  12. package/dist/lib/pull-config.d.ts +59 -0
  13. package/dist/lib/pull-config.d.ts.map +1 -0
  14. package/dist/lib/pull-config.js +93 -0
  15. package/dist/lib/pull-config.js.map +1 -0
  16. package/dist/lib/push-config.d.ts +104 -0
  17. package/dist/lib/push-config.d.ts.map +1 -0
  18. package/dist/lib/push-config.js +389 -0
  19. package/dist/lib/push-config.js.map +1 -0
  20. package/dist/v1.d.ts +6 -0
  21. package/dist/v1.js +6 -0
  22. package/package.json +69 -22
  23. package/e2e/conflict.e2e.test.ts +0 -34
  24. package/e2e/helpers.ts +0 -204
  25. package/e2e/lifecycle.e2e.test.ts +0 -50
  26. package/e2e/load-env.ts +0 -29
  27. package/e2e/setup.ts +0 -24
  28. package/src/index.ts +0 -5
  29. package/src/lib/fake-neon-api.ts +0 -782
  30. package/src/lib/function-bundle.test.ts +0 -60
  31. package/src/lib/function-bundle.ts +0 -104
  32. package/src/lib/operations.test.ts +0 -150
  33. package/src/lib/operations.ts +0 -103
  34. package/src/lib/pull-config.test.ts +0 -51
  35. package/src/lib/pull-config.ts +0 -215
  36. package/src/lib/push-config.test.ts +0 -421
  37. package/src/lib/push-config.ts +0 -619
  38. package/src/v1.test.ts +0 -30
  39. package/src/v1.ts +0 -74
  40. package/tsconfig.json +0 -4
  41. package/tsdown.config.ts +0 -22
  42. package/vitest.config.ts +0 -19
  43. package/vitest.e2e.config.ts +0 -29
@@ -0,0 +1,104 @@
1
+ import { Config, NeonApi, PushResult } from "@neondatabase/config";
2
+
3
+ //#region src/lib/push-config.d.ts
4
+ interface PushConfigOptions {
5
+ /**
6
+ * Neon project id. **Required** — the management API addresses every branch through
7
+ * its project, so there is no way to push without it. `pushConfig` never creates a
8
+ * project; resolve the id yourself (e.g. via neonctl) and pass it in.
9
+ */
10
+ projectId: string;
11
+ /**
12
+ * Neon branch id (`br-…`). **Required.** `pushConfig` never creates a branch — it must
13
+ * already exist on the project. Resolve names to ids before calling.
14
+ */
15
+ branchId: string;
16
+ /** Neon API key. Falls back to `NEON_API_KEY` / neonctl credentials. Ignored when `api` is supplied. */
17
+ apiKey?: string;
18
+ /**
19
+ * Inject a custom NeonApi adapter. Primarily used by tests; production callers can rely
20
+ * on the default real adapter built from `apiKey`.
21
+ */
22
+ api?: NeonApi;
23
+ /**
24
+ * Auto-confirm overriding existing remote settings.
25
+ *
26
+ * When `true`, mutable drift on the selected branch (TTL, `protected` flag, compute
27
+ * settings) is applied as actual mutations and the override-confirm prompt is
28
+ * skipped. When `false` (default) the behaviour depends on whether `confirm` is
29
+ * supplied:
30
+ * - With `confirm`: the callback is asked whether to apply the override.
31
+ * - Without `confirm`: drift is reported as a `PushConflictError` (legacy
32
+ * non-interactive default — preserved so programmatic SDK callers don't
33
+ * silently start mutating remote state).
34
+ */
35
+ updateExisting?: boolean;
36
+ /**
37
+ * Auto-confirm pushing to a protected branch.
38
+ *
39
+ * When `true`, no protected-branch confirmation is asked. When `false` (default):
40
+ * - With `confirm`: the callback is asked.
41
+ * - Without `confirm`: the push proceeds (legacy SDK default).
42
+ */
43
+ allowProtectedBranch?: boolean;
44
+ /**
45
+ * Optional confirmation callback. Invoked once with a single context object before
46
+ * any mutations run when the push needs confirmation: pushing to a protected
47
+ * branch (unless `allowProtectedBranch` is `true`) and/or applying mutable drift
48
+ * (unless `updateExisting` is `true`).
49
+ *
50
+ * Both prompts collapse into a single callback invocation when both apply, so the
51
+ * CLI can render one combined "are you sure?" prompt.
52
+ *
53
+ * Resolves to `true` to proceed, `false` to abort with {@link PushAbortedError}.
54
+ *
55
+ * Never invoked on `dryRun`.
56
+ */
57
+ confirm?: (context: PushConfirmContext) => boolean | Promise<boolean>;
58
+ /**
59
+ * When `true`, compute the full plan against the live remote state but **do not
60
+ * execute any mutations**. The resulting `PushResult.applied` array records every
61
+ * change that *would* run on a real push (with the same action / identifier / details
62
+ * shape, so the existing CLI summary formatter just works), and conflicts are
63
+ * reported instead of thrown.
64
+ *
65
+ * Used by `plan(config, branchId)` and any caller that wants a "would this push do
66
+ * something dangerous?" check before invoking `pushConfig` for real.
67
+ */
68
+ dryRun?: boolean;
69
+ }
70
+ /**
71
+ * Context handed to a {@link PushConfigOptions.confirm} callback. Both flags can be
72
+ * `true` simultaneously when the push targets a protected branch *and* would override
73
+ * existing settings — render a single combined prompt covering both reasons.
74
+ */
75
+ interface PushConfirmContext {
76
+ /** Name of the target branch on Neon. */
77
+ branchName: string;
78
+ /**
79
+ * `true` when the target branch has the `protected` flag on Neon and the caller
80
+ * did not pass `allowProtectedBranch: true`.
81
+ */
82
+ protectedBranch: boolean;
83
+ /**
84
+ * `true` when the plan would override existing remote settings (TTL, `protected`
85
+ * flag, compute settings on an existing endpoint) and the caller did not pass
86
+ * `updateExisting: true`. Additive operations (enabling Neon Auth / Data API for
87
+ * the first time) are **not** counted here — those are unambiguous and never
88
+ * prompt.
89
+ */
90
+ overrideUpdates: boolean;
91
+ }
92
+ /**
93
+ * Push a Neon branch policy to a specific project + branch.
94
+ *
95
+ * Filesystem- and env-agnostic: the caller supplies an already-validated `Config` object
96
+ * (from `defineConfig` / `loadConfigFromFile`) and explicit `projectId` + `branch` in
97
+ * `options`. `pushConfig` performs no `.neon` lookups and reads no `NEON_*` env vars.
98
+ *
99
+ * It will **not** create a project or branch — both must already exist on Neon.
100
+ */
101
+ declare function pushConfig(config: Config, options: PushConfigOptions): Promise<PushResult>;
102
+ //#endregion
103
+ export { PushConfigOptions, PushConfirmContext, pushConfig };
104
+ //# sourceMappingURL=push-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-config.d.ts","names":[],"sources":["../../src/lib/push-config.ts"],"mappings":";;;UAoBiB,iBAAA;;AAAjB;;;;WAqDsD,EAAA,MAAA;EAAO;AAmB7D;AA2BA;;UACS,EAAA,MAAA;;QAEE,CAAA,EAAA,MAAA;;AAAD;;;QApFH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAmCc,iCAAiC;;;;;;;;;;;;;;;;;;UAmBrC,kBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BK,UAAA,SACb,iBACC,oBACP,QAAQ"}
@@ -0,0 +1,389 @@
1
+ import { buildFunctionBundle } from "./function-bundle.js";
2
+ import { ErrorCode, PlatformError, PushAbortedError, PushConflictError, createNeonApiFromOptions, diffConfig, resolveConfig } from "@neondatabase/config";
3
+ //#region src/lib/push-config.ts
4
+ /**
5
+ * Push a Neon branch policy to a specific project + branch.
6
+ *
7
+ * Filesystem- and env-agnostic: the caller supplies an already-validated `Config` object
8
+ * (from `defineConfig` / `loadConfigFromFile`) and explicit `projectId` + `branch` in
9
+ * `options`. `pushConfig` performs no `.neon` lookups and reads no `NEON_*` env vars.
10
+ *
11
+ * It will **not** create a project or branch — both must already exist on Neon.
12
+ */
13
+ async function pushConfig(config, options) {
14
+ const api = options.api ?? createApiFromOptions(options);
15
+ const projectId = options.projectId;
16
+ const dryRun = options.dryRun === true;
17
+ const updateExisting = options.updateExisting === true;
18
+ const allowProtectedBranch = options.allowProtectedBranch === true;
19
+ const remoteProject = await api.getProject(projectId);
20
+ const [branches, endpoints] = await Promise.all([api.listBranches(remoteProject.id), api.listEndpoints(remoteProject.id)]);
21
+ const branch = resolveRemoteBranch(options.branchId, branches);
22
+ const resolved = resolveConfig(config, {
23
+ name: branch.name,
24
+ id: branch.id,
25
+ exists: true,
26
+ ...branch.parentId ? { parentId: branch.parentId } : {},
27
+ isDefault: branch.isDefault,
28
+ isProtected: branch.protected,
29
+ ...branch.expiresAt ? { expiresAt: branch.expiresAt } : {}
30
+ });
31
+ const services = await resolveServiceState({
32
+ api,
33
+ projectId: remoteProject.id,
34
+ branch,
35
+ wantsAuth: resolved.authEnabled,
36
+ wantsDataApi: resolved.dataApiEnabled
37
+ });
38
+ const remote = {
39
+ projectId: remoteProject.id,
40
+ branch,
41
+ endpoint: endpoints.find((ep) => ep.type === "read_write" && ep.branchId === branch.id),
42
+ services
43
+ };
44
+ if (resolved.preview) remote.preview = await resolvePreviewState({
45
+ api,
46
+ projectId: remoteProject.id,
47
+ branchId: branch.id
48
+ });
49
+ const diff = diffConfig(resolved, remote, { updateExisting: true });
50
+ const needsOverrideConfirm = diff.plan.filter(isOverrideStep).length > 0 && !updateExisting;
51
+ const needsProtectedConfirm = branch.protected && !allowProtectedBranch;
52
+ if (!dryRun && diff.conflicts.length > 0) throw new PushConflictError(diff.conflicts);
53
+ if (!dryRun && (needsOverrideConfirm || needsProtectedConfirm)) {
54
+ if (options.confirm) {
55
+ if (!await options.confirm({
56
+ branchName: branch.name,
57
+ protectedBranch: needsProtectedConfirm,
58
+ overrideUpdates: needsOverrideConfirm
59
+ })) {
60
+ const reasons = [];
61
+ if (needsProtectedConfirm) reasons.push("protected-branch");
62
+ if (needsOverrideConfirm) reasons.push("override-updates");
63
+ throw new PushAbortedError(branch.name, reasons);
64
+ }
65
+ } else if (needsOverrideConfirm) throw new PushConflictError(diffConfig(resolved, remote, { updateExisting: false }).conflicts);
66
+ }
67
+ const applied = [{
68
+ kind: "branch",
69
+ action: "noop",
70
+ identifier: branch.name
71
+ }];
72
+ const branchById = new Map(branches.map((b) => [b.id, b]));
73
+ const branchByName = new Map(branches.map((b) => [b.name, b]));
74
+ for (const step of diff.plan) {
75
+ const change = dryRun ? synthesizeAppliedChange(step) : await applyStep(step, {
76
+ api,
77
+ remoteProjectId: remoteProject.id,
78
+ branchById,
79
+ branchByName
80
+ });
81
+ applied.push(change);
82
+ }
83
+ const result = {
84
+ projectId: remoteProject.id,
85
+ branchId: branch.id,
86
+ branchName: branch.name,
87
+ dryRun,
88
+ applied,
89
+ conflicts: diff.conflicts
90
+ };
91
+ if (remoteProject.orgId) result.orgId = remoteProject.orgId;
92
+ return result;
93
+ }
94
+ /**
95
+ * `update-*` plan steps mutate existing remote state. `enable-*` steps are additive (no
96
+ * existing resource to override) and never trigger the override-confirm prompt.
97
+ */
98
+ function isOverrideStep(step) {
99
+ return step.kind === "update-branch-ttl" || step.kind === "update-branch-protected" || step.kind === "update-endpoint";
100
+ }
101
+ /**
102
+ * Build an {@link AppliedChange} from a {@link PlanStep} without calling the Neon API.
103
+ * Used by dry-run mode so callers see the same record shape they would on a live push,
104
+ * just with no side effects. Identifiers are the branch names from the plan; any
105
+ * sub-resource ids (`branchId`, `endpointId`) flow through unchanged when known.
106
+ */
107
+ function synthesizeAppliedChange(step) {
108
+ switch (step.kind) {
109
+ case "update-branch-ttl": return {
110
+ kind: "branch",
111
+ action: "update",
112
+ identifier: step.branchName,
113
+ details: {
114
+ field: "ttl",
115
+ expiresAt: step.expiresAt
116
+ }
117
+ };
118
+ case "update-branch-protected": return {
119
+ kind: "branch",
120
+ action: "update",
121
+ identifier: step.branchName,
122
+ details: {
123
+ field: "protected",
124
+ protected: step.protected
125
+ }
126
+ };
127
+ case "update-endpoint": return {
128
+ kind: "branch",
129
+ action: "update",
130
+ identifier: step.branchName,
131
+ details: {
132
+ field: "computeSettings",
133
+ endpointId: step.endpointId,
134
+ settings: step.settings
135
+ }
136
+ };
137
+ case "enable-auth": return {
138
+ kind: "service",
139
+ action: "create",
140
+ identifier: "auth",
141
+ details: {
142
+ branchName: step.branchName,
143
+ ...step.databaseName ? { databaseName: step.databaseName } : {}
144
+ }
145
+ };
146
+ case "enable-data-api": return {
147
+ kind: "service",
148
+ action: "create",
149
+ identifier: "dataApi",
150
+ details: {
151
+ branchName: step.branchName,
152
+ databaseName: step.databaseName
153
+ }
154
+ };
155
+ case "create-bucket": return {
156
+ kind: "service",
157
+ action: "create",
158
+ identifier: `bucket:${step.bucketName}`,
159
+ details: {
160
+ branchName: step.branchName,
161
+ bucketName: step.bucketName,
162
+ accessLevel: step.accessLevel
163
+ }
164
+ };
165
+ case "create-function": return {
166
+ kind: "service",
167
+ action: "create",
168
+ identifier: `function:${step.fn.slug}`,
169
+ details: {
170
+ branchName: step.branchName,
171
+ slug: step.fn.slug,
172
+ name: step.fn.name
173
+ }
174
+ };
175
+ case "deploy-function": return {
176
+ kind: "service",
177
+ action: "update",
178
+ identifier: `function:${step.fn.slug}`,
179
+ details: {
180
+ branchName: step.branchName,
181
+ slug: step.fn.slug,
182
+ source: step.fn.source,
183
+ runtime: step.fn.runtime,
184
+ memoryMib: step.fn.memoryMib
185
+ }
186
+ };
187
+ case "enable-ai-gateway": return {
188
+ kind: "service",
189
+ action: "create",
190
+ identifier: "aiGateway",
191
+ details: { branchName: step.branchName }
192
+ };
193
+ }
194
+ }
195
+ function createApiFromOptions(options) {
196
+ return createNeonApiFromOptions("pushConfig", { ...options.apiKey ? { apiKey: options.apiKey } : {} });
197
+ }
198
+ function resolveRemoteBranch(branchId, branches) {
199
+ const found = branches.find((b) => b.id === branchId);
200
+ if (found) return found;
201
+ throw new PlatformError(ErrorCode.BranchNotFound, [
202
+ `pushConfig: branch id ${JSON.stringify(branchId)} does not exist on the project.`,
203
+ `Available branches: ${branches.map((b) => `${b.name} (${b.id})`).join(", ") || "(none)"}.`,
204
+ "Pass an existing branch id, or create the branch first with the neonctl CLI."
205
+ ].join(" "), { details: {
206
+ branchId,
207
+ available: branches.map((b) => b.id)
208
+ } });
209
+ }
210
+ /**
211
+ * Pre-fetch the current state of branch-scoped integrations on the selected branch.
212
+ */
213
+ async function resolveServiceState(args) {
214
+ const { api, projectId, branch, wantsAuth, wantsDataApi } = args;
215
+ if (!wantsAuth && !wantsDataApi) return {
216
+ databaseName: "neondb",
217
+ authEnabled: false,
218
+ dataApiEnabled: false
219
+ };
220
+ const databaseName = await pickServiceDatabaseName(api, projectId, branch.id);
221
+ const [auth, dataApi] = await Promise.all([wantsAuth ? api.getNeonAuth(projectId, branch.id) : Promise.resolve(null), wantsDataApi ? api.getNeonDataApi(projectId, branch.id, databaseName) : Promise.resolve(null)]);
222
+ return {
223
+ databaseName,
224
+ authEnabled: auth !== null,
225
+ dataApiEnabled: dataApi !== null
226
+ };
227
+ }
228
+ /**
229
+ * Pre-fetch the current state of branch-scoped Preview features (buckets, functions, AI
230
+ * Gateway) so the diff can be computed additively. Only called when the policy has a
231
+ * `preview` block.
232
+ */
233
+ async function resolvePreviewState(args) {
234
+ const { api, projectId, branchId } = args;
235
+ const [buckets, functions, aiGatewayEnabled] = await Promise.all([
236
+ api.listBranchBuckets(projectId, branchId),
237
+ api.listBranchFunctions(projectId, branchId),
238
+ api.getAiGatewayEnabled(projectId, branchId)
239
+ ]);
240
+ return {
241
+ buckets,
242
+ functions,
243
+ aiGatewayEnabled
244
+ };
245
+ }
246
+ /**
247
+ * Resolve the database name for a Data API integration. Auto-pick when the branch has
248
+ * exactly one database; otherwise fall back to Neon's default (`neondb`) so the call
249
+ * stays useful even on branches with multiple databases — push doesn't have a way to
250
+ * surface a "pick one" prompt the way `fetchEnv` does.
251
+ */
252
+ async function pickServiceDatabaseName(api, projectId, branchId) {
253
+ const databases = await api.listBranchDatabases(projectId, branchId);
254
+ if (databases.length === 1) return databases[0].name;
255
+ const neondb = databases.find((d) => d.name === "neondb");
256
+ if (neondb) return neondb.name;
257
+ return databases[0]?.name ?? "neondb";
258
+ }
259
+ async function applyStep(step, ctx) {
260
+ switch (step.kind) {
261
+ case "update-branch-ttl": {
262
+ const updated = await ctx.api.updateBranch(ctx.remoteProjectId, step.branchId, { expiresAt: step.expiresAt ?? null });
263
+ ctx.branchById.set(updated.id, updated);
264
+ ctx.branchByName.set(updated.name, updated);
265
+ return {
266
+ kind: "branch",
267
+ action: "update",
268
+ identifier: updated.name,
269
+ details: {
270
+ field: "ttl",
271
+ expiresAt: step.expiresAt
272
+ }
273
+ };
274
+ }
275
+ case "update-branch-protected": {
276
+ const updated = await ctx.api.updateBranch(ctx.remoteProjectId, step.branchId, { protected: step.protected });
277
+ ctx.branchById.set(updated.id, updated);
278
+ ctx.branchByName.set(updated.name, updated);
279
+ return {
280
+ kind: "branch",
281
+ action: "update",
282
+ identifier: updated.name,
283
+ details: {
284
+ field: "protected",
285
+ protected: step.protected
286
+ }
287
+ };
288
+ }
289
+ case "update-endpoint": {
290
+ const updated = await ctx.api.updateEndpoint(ctx.remoteProjectId, step.endpointId, step.settings);
291
+ return {
292
+ kind: "branch",
293
+ action: "update",
294
+ identifier: step.branchName,
295
+ details: {
296
+ field: "computeSettings",
297
+ endpointId: updated.id,
298
+ settings: step.settings
299
+ }
300
+ };
301
+ }
302
+ case "enable-auth":
303
+ await ctx.api.enableNeonAuth(ctx.remoteProjectId, step.branchId, { ...step.databaseName ? { databaseName: step.databaseName } : {} });
304
+ return {
305
+ kind: "service",
306
+ action: "create",
307
+ identifier: "auth",
308
+ details: {
309
+ branchName: step.branchName,
310
+ ...step.databaseName ? { databaseName: step.databaseName } : {}
311
+ }
312
+ };
313
+ case "enable-data-api":
314
+ await ctx.api.enableProjectBranchDataApi(ctx.remoteProjectId, step.branchId, step.databaseName);
315
+ return {
316
+ kind: "service",
317
+ action: "create",
318
+ identifier: "dataApi",
319
+ details: {
320
+ branchName: step.branchName,
321
+ databaseName: step.databaseName
322
+ }
323
+ };
324
+ case "create-bucket":
325
+ await ctx.api.createBranchBucket(ctx.remoteProjectId, step.branchId, {
326
+ name: step.bucketName,
327
+ accessLevel: step.accessLevel
328
+ });
329
+ return {
330
+ kind: "service",
331
+ action: "create",
332
+ identifier: `bucket:${step.bucketName}`,
333
+ details: {
334
+ branchName: step.branchName,
335
+ bucketName: step.bucketName,
336
+ accessLevel: step.accessLevel
337
+ }
338
+ };
339
+ case "create-function":
340
+ await ctx.api.createBranchFunction(ctx.remoteProjectId, step.branchId, {
341
+ slug: step.fn.slug,
342
+ name: step.fn.name
343
+ });
344
+ return {
345
+ kind: "service",
346
+ action: "create",
347
+ identifier: `function:${step.fn.slug}`,
348
+ details: {
349
+ branchName: step.branchName,
350
+ slug: step.fn.slug,
351
+ name: step.fn.name
352
+ }
353
+ };
354
+ case "deploy-function": {
355
+ const bundle = await buildFunctionBundle(step.fn);
356
+ const deployment = await ctx.api.deployBranchFunction(ctx.remoteProjectId, step.branchId, step.fn.slug, {
357
+ bundle,
358
+ runtime: step.fn.runtime,
359
+ memoryMib: step.fn.memoryMib,
360
+ environment: step.fn.env
361
+ });
362
+ return {
363
+ kind: "service",
364
+ action: "update",
365
+ identifier: `function:${step.fn.slug}`,
366
+ details: {
367
+ branchName: step.branchName,
368
+ slug: step.fn.slug,
369
+ source: step.fn.source,
370
+ runtime: step.fn.runtime,
371
+ memoryMib: step.fn.memoryMib,
372
+ deploymentId: deployment.id
373
+ }
374
+ };
375
+ }
376
+ case "enable-ai-gateway":
377
+ await ctx.api.enableAiGateway(ctx.remoteProjectId, step.branchId);
378
+ return {
379
+ kind: "service",
380
+ action: "create",
381
+ identifier: "aiGateway",
382
+ details: { branchName: step.branchName }
383
+ };
384
+ }
385
+ }
386
+ //#endregion
387
+ export { pushConfig };
388
+
389
+ //# sourceMappingURL=push-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-config.js","names":[],"sources":["../../src/lib/push-config.ts"],"sourcesContent":["import {\n\ttype AppliedChange,\n\ttype Config,\n\tcreateNeonApiFromOptions,\n\tdiffConfig,\n\tErrorCode,\n\ttype NeonApi,\n\ttype NeonBranchSnapshot,\n\ttype PlanStep,\n\tPlatformError,\n\tPushAbortedError,\n\tPushConflictError,\n\ttype PushResult,\n\ttype RemotePreviewState,\n\ttype RemoteServiceState,\n\ttype RemoteState,\n\tresolveConfig,\n} from \"@neondatabase/config\";\nimport { buildFunctionBundle } from \"./function-bundle.js\";\n\nexport interface PushConfigOptions {\n\t/**\n\t * Neon project id. **Required** — the management API addresses every branch through\n\t * its project, so there is no way to push without it. `pushConfig` never creates a\n\t * project; resolve the id yourself (e.g. via neonctl) and pass it in.\n\t */\n\tprojectId: string;\n\t/**\n\t * Neon branch id (`br-…`). **Required.** `pushConfig` never creates a branch — it must\n\t * already exist on the project. Resolve names to ids before calling.\n\t */\n\tbranchId: string;\n\t/** Neon API key. Falls back to `NEON_API_KEY` / neonctl credentials. Ignored when `api` is supplied. */\n\tapiKey?: string;\n\t/**\n\t * Inject a custom NeonApi adapter. Primarily used by tests; production callers can rely\n\t * on the default real adapter built from `apiKey`.\n\t */\n\tapi?: NeonApi;\n\t/**\n\t * Auto-confirm overriding existing remote settings.\n\t *\n\t * When `true`, mutable drift on the selected branch (TTL, `protected` flag, compute\n\t * settings) is applied as actual mutations and the override-confirm prompt is\n\t * skipped. When `false` (default) the behaviour depends on whether `confirm` is\n\t * supplied:\n\t * - With `confirm`: the callback is asked whether to apply the override.\n\t * - Without `confirm`: drift is reported as a `PushConflictError` (legacy\n\t * non-interactive default — preserved so programmatic SDK callers don't\n\t * silently start mutating remote state).\n\t */\n\tupdateExisting?: boolean;\n\t/**\n\t * Auto-confirm pushing to a protected branch.\n\t *\n\t * When `true`, no protected-branch confirmation is asked. When `false` (default):\n\t * - With `confirm`: the callback is asked.\n\t * - Without `confirm`: the push proceeds (legacy SDK default).\n\t */\n\tallowProtectedBranch?: boolean;\n\t/**\n\t * Optional confirmation callback. Invoked once with a single context object before\n\t * any mutations run when the push needs confirmation: pushing to a protected\n\t * branch (unless `allowProtectedBranch` is `true`) and/or applying mutable drift\n\t * (unless `updateExisting` is `true`).\n\t *\n\t * Both prompts collapse into a single callback invocation when both apply, so the\n\t * CLI can render one combined \"are you sure?\" prompt.\n\t *\n\t * Resolves to `true` to proceed, `false` to abort with {@link PushAbortedError}.\n\t *\n\t * Never invoked on `dryRun`.\n\t */\n\tconfirm?: (context: PushConfirmContext) => boolean | Promise<boolean>;\n\t/**\n\t * When `true`, compute the full plan against the live remote state but **do not\n\t * execute any mutations**. The resulting `PushResult.applied` array records every\n\t * change that *would* run on a real push (with the same action / identifier / details\n\t * shape, so the existing CLI summary formatter just works), and conflicts are\n\t * reported instead of thrown.\n\t *\n\t * Used by `plan(config, branchId)` and any caller that wants a \"would this push do\n\t * something dangerous?\" check before invoking `pushConfig` for real.\n\t */\n\tdryRun?: boolean;\n}\n\n/**\n * Context handed to a {@link PushConfigOptions.confirm} callback. Both flags can be\n * `true` simultaneously when the push targets a protected branch *and* would override\n * existing settings — render a single combined prompt covering both reasons.\n */\nexport interface PushConfirmContext {\n\t/** Name of the target branch on Neon. */\n\tbranchName: string;\n\t/**\n\t * `true` when the target branch has the `protected` flag on Neon and the caller\n\t * did not pass `allowProtectedBranch: true`.\n\t */\n\tprotectedBranch: boolean;\n\t/**\n\t * `true` when the plan would override existing remote settings (TTL, `protected`\n\t * flag, compute settings on an existing endpoint) and the caller did not pass\n\t * `updateExisting: true`. Additive operations (enabling Neon Auth / Data API for\n\t * the first time) are **not** counted here — those are unambiguous and never\n\t * prompt.\n\t */\n\toverrideUpdates: boolean;\n}\n\n/**\n * Push a Neon branch policy to a specific project + branch.\n *\n * Filesystem- and env-agnostic: the caller supplies an already-validated `Config` object\n * (from `defineConfig` / `loadConfigFromFile`) and explicit `projectId` + `branch` in\n * `options`. `pushConfig` performs no `.neon` lookups and reads no `NEON_*` env vars.\n *\n * It will **not** create a project or branch — both must already exist on Neon.\n */\nexport async function pushConfig(\n\tconfig: Config,\n\toptions: PushConfigOptions,\n): Promise<PushResult> {\n\tconst api = options.api ?? createApiFromOptions(options);\n\tconst projectId = options.projectId;\n\n\tconst dryRun = options.dryRun === true;\n\tconst updateExisting = options.updateExisting === true;\n\tconst allowProtectedBranch = options.allowProtectedBranch === true;\n\n\tconst remoteProject = await api.getProject(projectId);\n\n\tconst [branches, endpoints] = await Promise.all([\n\t\tapi.listBranches(remoteProject.id),\n\t\tapi.listEndpoints(remoteProject.id),\n\t]);\n\tconst branch = resolveRemoteBranch(options.branchId, branches);\n\tconst resolved = resolveConfig(config, {\n\t\tname: branch.name,\n\t\tid: branch.id,\n\t\texists: true,\n\t\t...(branch.parentId ? { parentId: branch.parentId } : {}),\n\t\tisDefault: branch.isDefault,\n\t\tisProtected: branch.protected,\n\t\t...(branch.expiresAt ? { expiresAt: branch.expiresAt } : {}),\n\t});\n\tconst services = await resolveServiceState({\n\t\tapi,\n\t\tprojectId: remoteProject.id,\n\t\tbranch,\n\t\twantsAuth: resolved.authEnabled,\n\t\twantsDataApi: resolved.dataApiEnabled,\n\t});\n\tconst remote: RemoteState = {\n\t\tprojectId: remoteProject.id,\n\t\tbranch,\n\t\tendpoint: endpoints.find(\n\t\t\t(ep) => ep.type === \"read_write\" && ep.branchId === branch.id,\n\t\t),\n\t\tservices,\n\t};\n\t// Only fetch Preview state when the policy actually uses it — keeps pushes that don't\n\t// touch functions/buckets/aiGateway at the same number of API calls as before.\n\tif (resolved.preview) {\n\t\tremote.preview = await resolvePreviewState({\n\t\t\tapi,\n\t\t\tprojectId: remoteProject.id,\n\t\t\tbranchId: branch.id,\n\t\t});\n\t}\n\n\t// Always compute the plan with `updateExisting: true` so we can see what *would* be\n\t// overridden. The decision of whether to apply / prompt / fail is gated below using\n\t// the recorded steps.\n\tconst diff = diffConfig(resolved, remote, { updateExisting: true });\n\tconst overrideSteps = diff.plan.filter(isOverrideStep);\n\tconst needsOverrideConfirm = overrideSteps.length > 0 && !updateExisting;\n\tconst needsProtectedConfirm = branch.protected && !allowProtectedBranch;\n\n\tif (!dryRun && diff.conflicts.length > 0) {\n\t\tthrow new PushConflictError(diff.conflicts);\n\t}\n\n\tif (!dryRun && (needsOverrideConfirm || needsProtectedConfirm)) {\n\t\tif (options.confirm) {\n\t\t\tconst ok = await options.confirm({\n\t\t\t\tbranchName: branch.name,\n\t\t\t\tprotectedBranch: needsProtectedConfirm,\n\t\t\t\toverrideUpdates: needsOverrideConfirm,\n\t\t\t});\n\t\t\tif (!ok) {\n\t\t\t\tconst reasons: (\"protected-branch\" | \"override-updates\")[] = [];\n\t\t\t\tif (needsProtectedConfirm) reasons.push(\"protected-branch\");\n\t\t\t\tif (needsOverrideConfirm) reasons.push(\"override-updates\");\n\t\t\t\tthrow new PushAbortedError(branch.name, reasons);\n\t\t\t}\n\t\t} else if (needsOverrideConfirm) {\n\t\t\t// Legacy non-interactive fallback: surface the would-be drift as a\n\t\t\t// `PushConflictError` so programmatic callers that skipped both\n\t\t\t// `updateExisting` and `confirm` see the previous fail-fast behavior.\n\t\t\tconst legacy = diffConfig(resolved, remote, {\n\t\t\t\tupdateExisting: false,\n\t\t\t});\n\t\t\tthrow new PushConflictError(legacy.conflicts);\n\t\t}\n\t\t// Protected branch + no confirm callback: legacy default proceeds without\n\t\t// any extra check (no programmatic regression).\n\t}\n\n\tconst applied: AppliedChange[] = [\n\t\t{ kind: \"branch\", action: \"noop\", identifier: branch.name },\n\t];\n\n\tconst branchById = new Map(branches.map((b) => [b.id, b] as const));\n\tconst branchByName = new Map(branches.map((b) => [b.name, b] as const));\n\n\tfor (const step of diff.plan) {\n\t\tconst change = dryRun\n\t\t\t? synthesizeAppliedChange(step)\n\t\t\t: await applyStep(step, {\n\t\t\t\t\tapi,\n\t\t\t\t\tremoteProjectId: remoteProject.id,\n\t\t\t\t\tbranchById,\n\t\t\t\t\tbranchByName,\n\t\t\t\t});\n\t\tapplied.push(change);\n\t}\n\n\tconst result: PushResult = {\n\t\tprojectId: remoteProject.id,\n\t\tbranchId: branch.id,\n\t\tbranchName: branch.name,\n\t\tdryRun,\n\t\tapplied,\n\t\tconflicts: diff.conflicts,\n\t};\n\tif (remoteProject.orgId) result.orgId = remoteProject.orgId;\n\treturn result;\n}\n\n/**\n * `update-*` plan steps mutate existing remote state. `enable-*` steps are additive (no\n * existing resource to override) and never trigger the override-confirm prompt.\n */\nfunction isOverrideStep(step: PlanStep): boolean {\n\treturn (\n\t\tstep.kind === \"update-branch-ttl\" ||\n\t\tstep.kind === \"update-branch-protected\" ||\n\t\tstep.kind === \"update-endpoint\"\n\t);\n}\n\n/**\n * Build an {@link AppliedChange} from a {@link PlanStep} without calling the Neon API.\n * Used by dry-run mode so callers see the same record shape they would on a live push,\n * just with no side effects. Identifiers are the branch names from the plan; any\n * sub-resource ids (`branchId`, `endpointId`) flow through unchanged when known.\n */\nfunction synthesizeAppliedChange(step: PlanStep): AppliedChange {\n\tswitch (step.kind) {\n\t\tcase \"update-branch-ttl\":\n\t\t\treturn {\n\t\t\t\tkind: \"branch\",\n\t\t\t\taction: \"update\",\n\t\t\t\tidentifier: step.branchName,\n\t\t\t\tdetails: { field: \"ttl\", expiresAt: step.expiresAt },\n\t\t\t};\n\t\tcase \"update-branch-protected\":\n\t\t\treturn {\n\t\t\t\tkind: \"branch\",\n\t\t\t\taction: \"update\",\n\t\t\t\tidentifier: step.branchName,\n\t\t\t\tdetails: { field: \"protected\", protected: step.protected },\n\t\t\t};\n\t\tcase \"update-endpoint\":\n\t\t\treturn {\n\t\t\t\tkind: \"branch\",\n\t\t\t\taction: \"update\",\n\t\t\t\tidentifier: step.branchName,\n\t\t\t\tdetails: {\n\t\t\t\t\tfield: \"computeSettings\",\n\t\t\t\t\tendpointId: step.endpointId,\n\t\t\t\t\tsettings: step.settings,\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"enable-auth\":\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: \"auth\",\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\t...(step.databaseName\n\t\t\t\t\t\t? { databaseName: step.databaseName }\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"enable-data-api\":\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: \"dataApi\",\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\tdatabaseName: step.databaseName,\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"create-bucket\":\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: `bucket:${step.bucketName}`,\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\tbucketName: step.bucketName,\n\t\t\t\t\taccessLevel: step.accessLevel,\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"create-function\":\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: `function:${step.fn.slug}`,\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\tslug: step.fn.slug,\n\t\t\t\t\tname: step.fn.name,\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"deploy-function\":\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"update\",\n\t\t\t\tidentifier: `function:${step.fn.slug}`,\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\tslug: step.fn.slug,\n\t\t\t\t\tsource: step.fn.source,\n\t\t\t\t\truntime: step.fn.runtime,\n\t\t\t\t\tmemoryMib: step.fn.memoryMib,\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"enable-ai-gateway\":\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: \"aiGateway\",\n\t\t\t\tdetails: { branchName: step.branchName },\n\t\t\t};\n\t}\n}\n\nfunction createApiFromOptions(options: PushConfigOptions): NeonApi {\n\treturn createNeonApiFromOptions(\"pushConfig\", {\n\t\t...(options.apiKey ? { apiKey: options.apiKey } : {}),\n\t});\n}\n\nfunction resolveRemoteBranch(\n\tbranchId: string,\n\tbranches: NeonBranchSnapshot[],\n): NeonBranchSnapshot {\n\tconst found = branches.find((b) => b.id === branchId);\n\tif (found) return found;\n\tthrow new PlatformError(\n\t\tErrorCode.BranchNotFound,\n\t\t[\n\t\t\t`pushConfig: branch id ${JSON.stringify(branchId)} does not exist on the project.`,\n\t\t\t`Available branches: ${branches.map((b) => `${b.name} (${b.id})`).join(\", \") || \"(none)\"}.`,\n\t\t\t\"Pass an existing branch id, or create the branch first with the neonctl CLI.\",\n\t\t].join(\" \"),\n\t\t{ details: { branchId, available: branches.map((b) => b.id) } },\n\t);\n}\n\n/**\n * Pre-fetch the current state of branch-scoped integrations on the selected branch.\n */\nasync function resolveServiceState(args: {\n\tapi: NeonApi;\n\tprojectId: string;\n\tbranch: NeonBranchSnapshot;\n\twantsAuth: boolean;\n\twantsDataApi: boolean;\n}): Promise<RemoteServiceState> {\n\tconst { api, projectId, branch, wantsAuth, wantsDataApi } = args;\n\tif (!wantsAuth && !wantsDataApi) {\n\t\treturn {\n\t\t\tdatabaseName: \"neondb\",\n\t\t\tauthEnabled: false,\n\t\t\tdataApiEnabled: false,\n\t\t};\n\t}\n\n\tconst databaseName = await pickServiceDatabaseName(\n\t\tapi,\n\t\tprojectId,\n\t\tbranch.id,\n\t);\n\n\tconst [auth, dataApi] = await Promise.all([\n\t\twantsAuth\n\t\t\t? api.getNeonAuth(projectId, branch.id)\n\t\t\t: Promise.resolve(null),\n\t\twantsDataApi\n\t\t\t? api.getNeonDataApi(projectId, branch.id, databaseName)\n\t\t\t: Promise.resolve(null),\n\t]);\n\treturn {\n\t\tdatabaseName,\n\t\tauthEnabled: auth !== null,\n\t\tdataApiEnabled: dataApi !== null,\n\t};\n}\n\n/**\n * Pre-fetch the current state of branch-scoped Preview features (buckets, functions, AI\n * Gateway) so the diff can be computed additively. Only called when the policy has a\n * `preview` block.\n */\nasync function resolvePreviewState(args: {\n\tapi: NeonApi;\n\tprojectId: string;\n\tbranchId: string;\n}): Promise<RemotePreviewState> {\n\tconst { api, projectId, branchId } = args;\n\tconst [buckets, functions, aiGatewayEnabled] = await Promise.all([\n\t\tapi.listBranchBuckets(projectId, branchId),\n\t\tapi.listBranchFunctions(projectId, branchId),\n\t\tapi.getAiGatewayEnabled(projectId, branchId),\n\t]);\n\treturn { buckets, functions, aiGatewayEnabled };\n}\n\n/**\n * Resolve the database name for a Data API integration. Auto-pick when the branch has\n * exactly one database; otherwise fall back to Neon's default (`neondb`) so the call\n * stays useful even on branches with multiple databases — push doesn't have a way to\n * surface a \"pick one\" prompt the way `fetchEnv` does.\n */\nasync function pickServiceDatabaseName(\n\tapi: NeonApi,\n\tprojectId: string,\n\tbranchId: string,\n): Promise<string> {\n\tconst databases = await api.listBranchDatabases(projectId, branchId);\n\tif (databases.length === 1) return databases[0].name;\n\tconst neondb = databases.find((d) => d.name === \"neondb\");\n\tif (neondb) return neondb.name;\n\treturn databases[0]?.name ?? \"neondb\";\n}\n\ninterface ApplyContext {\n\tapi: NeonApi;\n\tremoteProjectId: string;\n\tbranchById: Map<string, NeonBranchSnapshot>;\n\tbranchByName: Map<string, NeonBranchSnapshot>;\n}\n\nasync function applyStep(\n\tstep: PlanStep,\n\tctx: ApplyContext,\n): Promise<AppliedChange> {\n\tswitch (step.kind) {\n\t\tcase \"update-branch-ttl\": {\n\t\t\tconst updated = await ctx.api.updateBranch(\n\t\t\t\tctx.remoteProjectId,\n\t\t\t\tstep.branchId,\n\t\t\t\t{\n\t\t\t\t\texpiresAt: step.expiresAt ?? null,\n\t\t\t\t},\n\t\t\t);\n\t\t\tctx.branchById.set(updated.id, updated);\n\t\t\tctx.branchByName.set(updated.name, updated);\n\t\t\treturn {\n\t\t\t\tkind: \"branch\",\n\t\t\t\taction: \"update\",\n\t\t\t\tidentifier: updated.name,\n\t\t\t\tdetails: { field: \"ttl\", expiresAt: step.expiresAt },\n\t\t\t};\n\t\t}\n\t\tcase \"update-branch-protected\": {\n\t\t\tconst updated = await ctx.api.updateBranch(\n\t\t\t\tctx.remoteProjectId,\n\t\t\t\tstep.branchId,\n\t\t\t\t{ protected: step.protected },\n\t\t\t);\n\t\t\tctx.branchById.set(updated.id, updated);\n\t\t\tctx.branchByName.set(updated.name, updated);\n\t\t\treturn {\n\t\t\t\tkind: \"branch\",\n\t\t\t\taction: \"update\",\n\t\t\t\tidentifier: updated.name,\n\t\t\t\tdetails: { field: \"protected\", protected: step.protected },\n\t\t\t};\n\t\t}\n\t\tcase \"update-endpoint\": {\n\t\t\tconst updated = await ctx.api.updateEndpoint(\n\t\t\t\tctx.remoteProjectId,\n\t\t\t\tstep.endpointId,\n\t\t\t\tstep.settings,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tkind: \"branch\",\n\t\t\t\taction: \"update\",\n\t\t\t\tidentifier: step.branchName,\n\t\t\t\tdetails: {\n\t\t\t\t\tfield: \"computeSettings\",\n\t\t\t\t\tendpointId: updated.id,\n\t\t\t\t\tsettings: step.settings,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase \"enable-auth\": {\n\t\t\tawait ctx.api.enableNeonAuth(ctx.remoteProjectId, step.branchId, {\n\t\t\t\t...(step.databaseName\n\t\t\t\t\t? { databaseName: step.databaseName }\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: \"auth\",\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\t...(step.databaseName\n\t\t\t\t\t\t? { databaseName: step.databaseName }\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase \"enable-data-api\": {\n\t\t\tawait ctx.api.enableProjectBranchDataApi(\n\t\t\t\tctx.remoteProjectId,\n\t\t\t\tstep.branchId,\n\t\t\t\tstep.databaseName,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: \"dataApi\",\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\tdatabaseName: step.databaseName,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase \"create-bucket\": {\n\t\t\tawait ctx.api.createBranchBucket(\n\t\t\t\tctx.remoteProjectId,\n\t\t\t\tstep.branchId,\n\t\t\t\t{ name: step.bucketName, accessLevel: step.accessLevel },\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: `bucket:${step.bucketName}`,\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\tbucketName: step.bucketName,\n\t\t\t\t\taccessLevel: step.accessLevel,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase \"create-function\": {\n\t\t\tawait ctx.api.createBranchFunction(\n\t\t\t\tctx.remoteProjectId,\n\t\t\t\tstep.branchId,\n\t\t\t\t{ slug: step.fn.slug, name: step.fn.name },\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: `function:${step.fn.slug}`,\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\tslug: step.fn.slug,\n\t\t\t\t\tname: step.fn.name,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase \"deploy-function\": {\n\t\t\tconst bundle = await buildFunctionBundle(step.fn);\n\t\t\tconst deployment = await ctx.api.deployBranchFunction(\n\t\t\t\tctx.remoteProjectId,\n\t\t\t\tstep.branchId,\n\t\t\t\tstep.fn.slug,\n\t\t\t\t{\n\t\t\t\t\tbundle,\n\t\t\t\t\truntime: step.fn.runtime,\n\t\t\t\t\tmemoryMib: step.fn.memoryMib,\n\t\t\t\t\tenvironment: step.fn.env,\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"update\",\n\t\t\t\tidentifier: `function:${step.fn.slug}`,\n\t\t\t\tdetails: {\n\t\t\t\t\tbranchName: step.branchName,\n\t\t\t\t\tslug: step.fn.slug,\n\t\t\t\t\tsource: step.fn.source,\n\t\t\t\t\truntime: step.fn.runtime,\n\t\t\t\t\tmemoryMib: step.fn.memoryMib,\n\t\t\t\t\tdeploymentId: deployment.id,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase \"enable-ai-gateway\": {\n\t\t\tawait ctx.api.enableAiGateway(ctx.remoteProjectId, step.branchId);\n\t\t\treturn {\n\t\t\t\tkind: \"service\",\n\t\t\t\taction: \"create\",\n\t\t\t\tidentifier: \"aiGateway\",\n\t\t\t\tdetails: { branchName: step.branchName },\n\t\t\t};\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAuHA,eAAsB,WACrB,QACA,SACsB;CACtB,MAAM,MAAM,QAAQ,OAAO,qBAAqB,OAAO;CACvD,MAAM,YAAY,QAAQ;CAE1B,MAAM,SAAS,QAAQ,WAAW;CAClC,MAAM,iBAAiB,QAAQ,mBAAmB;CAClD,MAAM,uBAAuB,QAAQ,yBAAyB;CAE9D,MAAM,gBAAgB,MAAM,IAAI,WAAW,SAAS;CAEpD,MAAM,CAAC,UAAU,aAAa,MAAM,QAAQ,IAAI,CAC/C,IAAI,aAAa,cAAc,EAAE,GACjC,IAAI,cAAc,cAAc,EAAE,CACnC,CAAC;CACD,MAAM,SAAS,oBAAoB,QAAQ,UAAU,QAAQ;CAC7D,MAAM,WAAW,cAAc,QAAQ;EACtC,MAAM,OAAO;EACb,IAAI,OAAO;EACX,QAAQ;EACR,GAAI,OAAO,WAAW,EAAE,UAAU,OAAO,SAAS,IAAI,CAAC;EACvD,WAAW,OAAO;EAClB,aAAa,OAAO;EACpB,GAAI,OAAO,YAAY,EAAE,WAAW,OAAO,UAAU,IAAI,CAAC;CAC3D,CAAC;CACD,MAAM,WAAW,MAAM,oBAAoB;EAC1C;EACA,WAAW,cAAc;EACzB;EACA,WAAW,SAAS;EACpB,cAAc,SAAS;CACxB,CAAC;CACD,MAAM,SAAsB;EAC3B,WAAW,cAAc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AK,GAAG;IAAM,MAAM,KAAK,GAAG;GAAK,CAC1C;GACA,OAAO;IACN,MAAM;IACN,QAAQ;IACR,YAAY,YAAY,KAAK,GAAG;IAChC,SAAS;KACR,YAAY,KAAK;KACjB,MAAM,KAAK,GAAG;KACd,MAAM,KAAK,GAAG;IACf;GACD;EAED,KAAK,mBAAmB;GACvB,MAAM,SAAS,MAAM,oBAAoB,KAAK,EAAE;GAChD,MAAM,aAAa,MAAM,IAAI,IAAI,qBAChC,IAAI,iBACJ,KAAK,UACL,KAAK,GAAG,MACR;IACC;IACA,SAAS,KAAK,GAAG;IACjB,WAAW,KAAK,GAAG;IACnB,aAAa,KAAK,GAAG;GACtB,CACD;GACA,OAAO;IACN,MAAM;IACN,QAAQ;IACR,YAAY,YAAY,KAAK,GAAG;IAChC,SAAS;KACR,YAAY,KAAK;KACjB,MAAM,KAAK,GAAG;KACd,QAAQ,KAAK,GAAG;KAChB,SAAS,KAAK,GAAG;KACjB,WAAW,KAAK,GAAG;KACnB,cAAc,WAAW;IAC1B;GACD;EACD;EACA,KAAK;GACJ,MAAM,IAAI,IAAI,gBAAgB,IAAI,iBAAiB,KAAK,QAAQ;GAChE,OAAO;IACN,MAAM;IACN,QAAQ;IACR,YAAY;IACZ,SAAS,EAAE,YAAY,KAAK,WAAW;GACxC;CAEF;AACD"}
package/dist/v1.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { buildFunctionBundle } from "./lib/function-bundle.js";
2
+ import { PullConfigOptions, PulledBranchConfig, PulledPreview, pullConfig } from "./lib/pull-config.js";
3
+ import { PushConfigOptions, PushConfirmContext, pushConfig } from "./lib/push-config.js";
4
+ import { ApplyOptions, ConfigOperationOptions, apply, inspect, plan } from "./lib/operations.js";
5
+ import { AppliedChange, Config, ConfigLoadError, ConfigValidationError, ConflictReport, ErrorCode, LoadConfigOptions, MissingContextError, NeonApi, PlatformError, PushAbortedError, PushConflictError, PushResult, createNeonApiFromOptions, createRealNeonApi, defineConfig, loadConfigFromFile } from "@neondatabase/config";
6
+ export { type AppliedChange, type ApplyOptions, type Config, ConfigLoadError, type ConfigOperationOptions, ConfigValidationError, type ConflictReport, ErrorCode, type LoadConfigOptions, MissingContextError, type NeonApi, PlatformError, type PullConfigOptions, type PulledBranchConfig, type PulledPreview, PushAbortedError, type PushConfigOptions, type PushConfirmContext, PushConflictError, type PushResult, apply, buildFunctionBundle, createNeonApiFromOptions, createRealNeonApi, defineConfig, inspect, loadConfigFromFile, plan, pullConfig, pushConfig };
package/dist/v1.js ADDED
@@ -0,0 +1,6 @@
1
+ import { buildFunctionBundle } from "./lib/function-bundle.js";
2
+ import { pullConfig } from "./lib/pull-config.js";
3
+ import { pushConfig } from "./lib/push-config.js";
4
+ import { apply, inspect, plan } from "./lib/operations.js";
5
+ import { ConfigLoadError, ConfigValidationError, ErrorCode, MissingContextError, PlatformError, PushAbortedError, PushConflictError, createNeonApiFromOptions, createRealNeonApi, defineConfig, loadConfigFromFile } from "@neondatabase/config";
6
+ export { ConfigLoadError, ConfigValidationError, ErrorCode, MissingContextError, PlatformError, PushAbortedError, PushConflictError, apply, buildFunctionBundle, createNeonApiFromOptions, createRealNeonApi, defineConfig, inspect, loadConfigFromFile, plan, pullConfig, pushConfig };
package/package.json CHANGED
@@ -1,23 +1,70 @@
1
1
  {
2
- "name": "@neondatabase/config-runtime",
3
- "version": "0.0.0",
4
- "description": "Imperative runtime for @neondatabase/config: inspect/plan/apply a neon.ts policy against the Neon API and bundle + deploy Neon Functions. Pulls in esbuild; import this from CLIs and CI, not from neon.ts.",
5
- "keywords": [
6
- "neon",
7
- "database",
8
- "postgres",
9
- "iac",
10
- "config-as-code",
11
- "platform",
12
- "deploy"
13
- ],
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/neondatabase/neon-pkgs.git"
17
- },
18
- "license": "Apache-2.0",
19
- "author": {
20
- "name": "Neon",
21
- "url": "https://neon.com"
22
- }
23
- }
2
+ "name": "@neondatabase/config-runtime",
3
+ "version": "0.1.0",
4
+ "description": "Imperative runtime for @neondatabase/config: inspect/plan/apply a neon.ts policy against the Neon API and bundle + deploy Neon Functions. Pulls in esbuild; import this from CLIs and CI, not from neon.ts.",
5
+ "keywords": [
6
+ "neon",
7
+ "database",
8
+ "postgres",
9
+ "iac",
10
+ "config-as-code",
11
+ "platform",
12
+ "deploy"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/neondatabase/neon-pkgs.git"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "author": {
20
+ "name": "Neon",
21
+ "url": "https://neon.com"
22
+ },
23
+ "type": "module",
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./v1": {
33
+ "types": "./dist/v1.d.ts",
34
+ "import": "./dist/v1.js",
35
+ "default": "./dist/v1.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "README.md",
40
+ "dist/",
41
+ "package.json"
42
+ ],
43
+ "devDependencies": {
44
+ "@neondatabase/api-client": "^2.7.1",
45
+ "@types/node": "^20.19.0",
46
+ "@vitest/coverage-v8": "3.0.9",
47
+ "console-fail-test": "0.5.0",
48
+ "tsdown": "^0.14.1",
49
+ "typescript": "^5.8.2",
50
+ "vitest": "^3.0.9"
51
+ },
52
+ "dependencies": {
53
+ "esbuild": "^0.25.0",
54
+ "fflate": "^0.8.2",
55
+ "@neondatabase/config": "0.1.0"
56
+ },
57
+ "engines": {
58
+ "node": ">=22"
59
+ },
60
+ "publishConfig": {
61
+ "provenance": false
62
+ },
63
+ "scripts": {
64
+ "build": "tsc --noEmit && tsdown",
65
+ "test": "vitest --passWithNoTests",
66
+ "test:ci": "vitest run --passWithNoTests",
67
+ "test:e2e": "vitest run --config vitest.e2e.config.ts",
68
+ "tsc": "tsc"
69
+ }
70
+ }