@neondatabase/env 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.
- package/LICENSE.md +178 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +61 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/dist/lib/neon-api.d.ts +264 -0
- package/dist/config/dist/lib/neon-api.d.ts.map +1 -0
- package/dist/config/dist/lib/types.d.ts +184 -0
- package/dist/config/dist/lib/types.d.ts.map +1 -0
- package/dist/config/dist/v1.d.ts +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/lib/cli/commands.d.ts +46 -0
- package/dist/lib/cli/commands.d.ts.map +1 -0
- package/dist/lib/cli/commands.js +181 -0
- package/dist/lib/cli/commands.js.map +1 -0
- package/dist/lib/cli/resolve-context.d.ts +35 -0
- package/dist/lib/cli/resolve-context.d.ts.map +1 -0
- package/dist/lib/cli/resolve-context.js +90 -0
- package/dist/lib/cli/resolve-context.js.map +1 -0
- package/dist/lib/env.d.ts +194 -0
- package/dist/lib/env.d.ts.map +1 -0
- package/dist/lib/env.js +263 -0
- package/dist/lib/env.js.map +1 -0
- package/dist/v1.d.ts +2 -0
- package/dist/v1.js +2 -0
- package/package.json +72 -21
- package/.env.example +0 -5
- package/e2e/env.e2e.test.ts +0 -36
- package/e2e/helpers.ts +0 -188
- package/e2e/load-env.ts +0 -29
- package/e2e/setup.ts +0 -24
- package/src/cli.ts +0 -107
- package/src/index.ts +0 -5
- package/src/lib/cli/commands.test.ts +0 -101
- package/src/lib/cli/commands.ts +0 -267
- package/src/lib/cli/resolve-context.test.ts +0 -242
- package/src/lib/cli/resolve-context.ts +0 -142
- package/src/lib/env.test.ts +0 -172
- package/src/lib/env.ts +0 -610
- package/src/lib/fake-neon-api.ts +0 -782
- package/src/lib/test-utils.ts +0 -83
- package/src/v1.ts +0 -32
- package/tsconfig.json +0 -4
- package/tsdown.config.ts +0 -20
- package/vitest.config.ts +0 -19
- package/vitest.e2e.config.ts +0 -29
package/src/lib/env.test.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type BranchConfig,
|
|
3
|
-
defineConfig,
|
|
4
|
-
ErrorCode,
|
|
5
|
-
} from "@neondatabase/config/v1";
|
|
6
|
-
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
7
|
-
import {
|
|
8
|
-
fetchEnv,
|
|
9
|
-
type NeonAuthEnv,
|
|
10
|
-
type NeonEnv,
|
|
11
|
-
parseEnv,
|
|
12
|
-
toEntries,
|
|
13
|
-
} from "./env.js";
|
|
14
|
-
import { FakeNeonApi } from "./fake-neon-api.js";
|
|
15
|
-
import { stubCleanNeonEnv } from "./test-utils.js";
|
|
16
|
-
|
|
17
|
-
beforeEach(() => stubCleanNeonEnv());
|
|
18
|
-
|
|
19
|
-
function expectType<T>(_value: T): void {
|
|
20
|
-
// Compile-time assertion only.
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function seededFake() {
|
|
24
|
-
const api = new FakeNeonApi();
|
|
25
|
-
const projectId = "proj-env";
|
|
26
|
-
api.seedProject({
|
|
27
|
-
project: {
|
|
28
|
-
id: projectId,
|
|
29
|
-
name: "env-test",
|
|
30
|
-
regionId: "aws-us-east-1",
|
|
31
|
-
pgVersion: 17,
|
|
32
|
-
},
|
|
33
|
-
branches: [
|
|
34
|
-
{ branch: { id: "br-main", name: "main", isDefault: true } },
|
|
35
|
-
],
|
|
36
|
-
});
|
|
37
|
-
return { api, projectId };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
describe("fetchEnv", () => {
|
|
41
|
-
test("fetches postgres env for selected branch", async () => {
|
|
42
|
-
const { api, projectId } = seededFake();
|
|
43
|
-
const config = defineConfig(() => ({}));
|
|
44
|
-
const env = await fetchEnv(config, {
|
|
45
|
-
api,
|
|
46
|
-
projectId,
|
|
47
|
-
branchId: "br-main",
|
|
48
|
-
});
|
|
49
|
-
expect(env.postgres.databaseUrl).toContain("postgresql://");
|
|
50
|
-
expect(env.postgres.databaseUrl).toContain("-pooler");
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("requires auth integration when branch policy enables auth", async () => {
|
|
54
|
-
const { api, projectId } = seededFake();
|
|
55
|
-
const config = defineConfig(() => ({ auth: {} }));
|
|
56
|
-
await expect(
|
|
57
|
-
fetchEnv(config, { api, projectId, branchId: "br-main" }),
|
|
58
|
-
).rejects.toMatchObject({ code: ErrorCode.NotFound });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test("returns the integration base URL from the live snapshot", async () => {
|
|
62
|
-
const { api, projectId } = seededFake();
|
|
63
|
-
await api.enableNeonAuth(projectId, "br-main");
|
|
64
|
-
const config = defineConfig(() => ({ auth: {} }));
|
|
65
|
-
|
|
66
|
-
const env = await fetchEnv(config, {
|
|
67
|
-
api,
|
|
68
|
-
projectId,
|
|
69
|
-
branchId: "br-main",
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
expect(env.auth.baseUrl).toBe(
|
|
73
|
-
`https://api.fake.neon.tech/auth/${projectId}/br-main`,
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("falls back to the supplied env source when the snapshot omits base URL", async () => {
|
|
78
|
-
const { api, projectId } = seededFake();
|
|
79
|
-
api.seedNeonAuth(projectId, "br-main", {
|
|
80
|
-
projectId: "auth-br-main",
|
|
81
|
-
jwksUrl: "https://example.com/jwks.json",
|
|
82
|
-
});
|
|
83
|
-
const config = defineConfig(() => ({ auth: {} }));
|
|
84
|
-
|
|
85
|
-
const env = await fetchEnv(config, {
|
|
86
|
-
api,
|
|
87
|
-
projectId,
|
|
88
|
-
branchId: "br-main",
|
|
89
|
-
env: { NEON_AUTH_BASE_URL: "https://auth.example.com" },
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
expect(env.auth.baseUrl).toBe("https://auth.example.com");
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe("parseEnv", () => {
|
|
97
|
-
test("parses postgres env synchronously", () => {
|
|
98
|
-
vi.stubEnv("DATABASE_URL", "postgres://pooled");
|
|
99
|
-
vi.stubEnv("DATABASE_URL_UNPOOLED", "postgres://direct");
|
|
100
|
-
const env = parseEnv(
|
|
101
|
-
defineConfig(() => ({})),
|
|
102
|
-
"main",
|
|
103
|
-
);
|
|
104
|
-
expect(env.postgres.databaseUrl).toBe("postgres://pooled");
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test("requires service env when service namespaces are present", () => {
|
|
108
|
-
vi.stubEnv("DATABASE_URL", "postgres://pooled");
|
|
109
|
-
vi.stubEnv("DATABASE_URL_UNPOOLED", "postgres://direct");
|
|
110
|
-
const config = defineConfig(() => ({
|
|
111
|
-
auth: {},
|
|
112
|
-
dataApi: {},
|
|
113
|
-
}));
|
|
114
|
-
|
|
115
|
-
expect(() => parseEnv(config, "main")).toThrow(
|
|
116
|
-
expect.objectContaining({ code: ErrorCode.EnvNotInjected }),
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test("types auth env when config spreads BranchConfig defaults", () => {
|
|
121
|
-
vi.stubEnv("DATABASE_URL", "postgres://pooled");
|
|
122
|
-
vi.stubEnv("DATABASE_URL_UNPOOLED", "postgres://direct");
|
|
123
|
-
vi.stubEnv("NEON_AUTH_BASE_URL", "https://auth.example.com");
|
|
124
|
-
const config = defineConfig((branch) => {
|
|
125
|
-
const defaults: BranchConfig = {
|
|
126
|
-
auth: {},
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
if (branch.name === "main") {
|
|
130
|
-
return {
|
|
131
|
-
...defaults,
|
|
132
|
-
protected: true,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
...defaults,
|
|
138
|
-
parent: "main",
|
|
139
|
-
ttl: "7d",
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
const env = parseEnv(config, "main");
|
|
144
|
-
|
|
145
|
-
expectType<NeonEnv<typeof config>>(env);
|
|
146
|
-
expectType<NeonAuthEnv>(env.auth);
|
|
147
|
-
// @ts-expect-error Auth defaults must not imply Data API env.
|
|
148
|
-
env.dataApi;
|
|
149
|
-
expect(env.auth.baseUrl).toBe("https://auth.example.com");
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test("rejects an empty NEON_AUTH_BASE_URL value", () => {
|
|
153
|
-
vi.stubEnv("DATABASE_URL", "postgres://pooled");
|
|
154
|
-
vi.stubEnv("DATABASE_URL_UNPOOLED", "postgres://direct");
|
|
155
|
-
vi.stubEnv("NEON_AUTH_BASE_URL", "");
|
|
156
|
-
|
|
157
|
-
expect(() =>
|
|
158
|
-
parseEnv(
|
|
159
|
-
defineConfig(() => ({ auth: {} })),
|
|
160
|
-
"main",
|
|
161
|
-
),
|
|
162
|
-
).toThrow(expect.objectContaining({ code: ErrorCode.EnvNotInjected }));
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test("projects env object to process env keys", () => {
|
|
166
|
-
const pairs = toEntries({
|
|
167
|
-
postgres: { databaseUrl: "a", databaseUrlUnpooled: "b" },
|
|
168
|
-
});
|
|
169
|
-
expect(pairs.DATABASE_URL).toBe("a");
|
|
170
|
-
expect(pairs.DATABASE_URL_UNPOOLED).toBe("b");
|
|
171
|
-
});
|
|
172
|
-
});
|