@principal-ai/subsystems-core 0.53.1 → 0.53.2
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/infra/index.d.ts +2 -2
- package/dist/infra/index.d.ts.map +1 -1
- package/dist/infra/index.js +4 -1
- package/dist/infra/index.js.map +1 -1
- package/dist/infra/observe.d.ts +40 -2
- package/dist/infra/observe.d.ts.map +1 -1
- package/dist/infra/observe.js +253 -30
- package/dist/infra/observe.js.map +1 -1
- package/package.json +1 -1
- package/src/infra/index.ts +5 -0
- package/src/infra/observe.neon.test.ts +232 -0
- package/src/infra/observe.ts +329 -39
package/dist/infra/index.d.ts
CHANGED
|
@@ -12,6 +12,6 @@ export { extractTerraformManifest, terraformStateObservations } from './terrafor
|
|
|
12
12
|
export type { ExtractTerraformOptions } from './terraform';
|
|
13
13
|
export { infraContainerId, infraDeploymentRef, infraToC4 } from './c4';
|
|
14
14
|
export type { InfraC4Container, InfraC4Deployment, InfraC4Edge } from './c4';
|
|
15
|
-
export { CLOUDFLARE_OBSERVED_TYPES, observeCloudflare, parseWranglerAuthToken, resolveCloudflareAccount, withoutUnknownOverwrites, } from './observe';
|
|
16
|
-
export type { CloudflareAccess, CloudflareAccountResult, InfraObserveDeps, InfraObserveResult, } from './observe';
|
|
15
|
+
export { CLOUDFLARE_OBSERVED_TYPES, NEON_OBSERVED_TYPES, observeCloudflare, observeNeon, parseWranglerAuthToken, resolveCloudflareAccount, resolveNeonAccount, withoutUnknownOverwrites, } from './observe';
|
|
16
|
+
export type { CloudflareAccess, CloudflareAccountResult, InfraObserveDeps, InfraObserveResult, NeonAccess, NeonAccountResult, } from './observe';
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/infra/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,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,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACnF,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACvE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC7E,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
|
package/dist/infra/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* the caller supplies.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.withoutUnknownOverwrites = exports.resolveCloudflareAccount = exports.parseWranglerAuthToken = exports.observeCloudflare = exports.CLOUDFLARE_OBSERVED_TYPES = exports.infraToC4 = exports.infraDeploymentRef = exports.infraContainerId = exports.terraformStateObservations = exports.extractTerraformManifest = exports.extractWranglerManifest = exports.stripJsonc = exports.parseJsonc = exports.mergeInfraManifests = exports.infraResourceKey = void 0;
|
|
8
|
+
exports.withoutUnknownOverwrites = exports.resolveNeonAccount = exports.resolveCloudflareAccount = exports.parseWranglerAuthToken = exports.observeNeon = exports.observeCloudflare = exports.NEON_OBSERVED_TYPES = exports.CLOUDFLARE_OBSERVED_TYPES = exports.infraToC4 = exports.infraDeploymentRef = exports.infraContainerId = exports.terraformStateObservations = exports.extractTerraformManifest = exports.extractWranglerManifest = exports.stripJsonc = exports.parseJsonc = exports.mergeInfraManifests = exports.infraResourceKey = void 0;
|
|
9
9
|
var types_1 = require("./types");
|
|
10
10
|
Object.defineProperty(exports, "infraResourceKey", { enumerable: true, get: function () { return types_1.infraResourceKey; } });
|
|
11
11
|
Object.defineProperty(exports, "mergeInfraManifests", { enumerable: true, get: function () { return types_1.mergeInfraManifests; } });
|
|
@@ -23,8 +23,11 @@ Object.defineProperty(exports, "infraDeploymentRef", { enumerable: true, get: fu
|
|
|
23
23
|
Object.defineProperty(exports, "infraToC4", { enumerable: true, get: function () { return c4_1.infraToC4; } });
|
|
24
24
|
var observe_1 = require("./observe");
|
|
25
25
|
Object.defineProperty(exports, "CLOUDFLARE_OBSERVED_TYPES", { enumerable: true, get: function () { return observe_1.CLOUDFLARE_OBSERVED_TYPES; } });
|
|
26
|
+
Object.defineProperty(exports, "NEON_OBSERVED_TYPES", { enumerable: true, get: function () { return observe_1.NEON_OBSERVED_TYPES; } });
|
|
26
27
|
Object.defineProperty(exports, "observeCloudflare", { enumerable: true, get: function () { return observe_1.observeCloudflare; } });
|
|
28
|
+
Object.defineProperty(exports, "observeNeon", { enumerable: true, get: function () { return observe_1.observeNeon; } });
|
|
27
29
|
Object.defineProperty(exports, "parseWranglerAuthToken", { enumerable: true, get: function () { return observe_1.parseWranglerAuthToken; } });
|
|
28
30
|
Object.defineProperty(exports, "resolveCloudflareAccount", { enumerable: true, get: function () { return observe_1.resolveCloudflareAccount; } });
|
|
31
|
+
Object.defineProperty(exports, "resolveNeonAccount", { enumerable: true, get: function () { return observe_1.resolveNeonAccount; } });
|
|
29
32
|
Object.defineProperty(exports, "withoutUnknownOverwrites", { enumerable: true, get: function () { return observe_1.withoutUnknownOverwrites; } });
|
|
30
33
|
//# sourceMappingURL=index.js.map
|
package/dist/infra/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/infra/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,iCAAgE;AAAvD,yGAAA,gBAAgB,OAAA;AAAE,4GAAA,mBAAmB,OAAA;AAU9C,iCAAiD;AAAxC,mGAAA,UAAU,OAAA;AAAE,mGAAA,UAAU,OAAA;AAC/B,uCAAqD;AAA5C,mHAAA,uBAAuB,OAAA;AAEhC,yCAAmF;AAA1E,qHAAA,wBAAwB,OAAA;AAAE,uHAAA,0BAA0B,OAAA;AAE7D,2BAAuE;AAA9D,sGAAA,gBAAgB,OAAA;AAAE,wGAAA,kBAAkB,OAAA;AAAE,+FAAA,SAAS,OAAA;AAExD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/infra/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,iCAAgE;AAAvD,yGAAA,gBAAgB,OAAA;AAAE,4GAAA,mBAAmB,OAAA;AAU9C,iCAAiD;AAAxC,mGAAA,UAAU,OAAA;AAAE,mGAAA,UAAU,OAAA;AAC/B,uCAAqD;AAA5C,mHAAA,uBAAuB,OAAA;AAEhC,yCAAmF;AAA1E,qHAAA,wBAAwB,OAAA;AAAE,uHAAA,0BAA0B,OAAA;AAE7D,2BAAuE;AAA9D,sGAAA,gBAAgB,OAAA;AAAE,wGAAA,kBAAkB,OAAA;AAAE,+FAAA,SAAS,OAAA;AAExD,qCASmB;AARjB,oHAAA,yBAAyB,OAAA;AACzB,8GAAA,mBAAmB,OAAA;AACnB,4GAAA,iBAAiB,OAAA;AACjB,sGAAA,WAAW,OAAA;AACX,iHAAA,sBAAsB,OAAA;AACtB,mHAAA,wBAAwB,OAAA;AACxB,6GAAA,kBAAkB,OAAA;AAClB,mHAAA,wBAAwB,OAAA"}
|
package/dist/infra/observe.d.ts
CHANGED
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
* Fetch-only and browser-safe. The token travels only in the Authorization
|
|
13
13
|
* header of requests to the provider's API, and never appears in a result.
|
|
14
14
|
*
|
|
15
|
-
* Cloudflare
|
|
16
|
-
* with no lookup is reported as skipped
|
|
15
|
+
* Cloudflare (Workers, R2, D1, KV, Queues and Containers) and Neon (projects
|
|
16
|
+
* and their databases). A resource type with no lookup is reported as skipped
|
|
17
|
+
* rather than guessed at.
|
|
17
18
|
*/
|
|
18
19
|
import type { InfraDeploymentObservation } from './types';
|
|
19
20
|
/** What a check needs to run, besides the credential. */
|
|
@@ -99,4 +100,41 @@ export declare function parseWranglerAuthToken(stdout: string): {
|
|
|
99
100
|
token: string;
|
|
100
101
|
type: 'oauth' | 'api_token';
|
|
101
102
|
} | null;
|
|
103
|
+
/** A credential for Neon: an API key, and the organization it is used in. */
|
|
104
|
+
export interface NeonAccess {
|
|
105
|
+
/** A personal, organization or project-scoped API key; sent as a Bearer token. */
|
|
106
|
+
token: string;
|
|
107
|
+
/** Needed with a personal key whose owner belongs to an organization. */
|
|
108
|
+
orgId?: string;
|
|
109
|
+
}
|
|
110
|
+
export type NeonAccountResult = {
|
|
111
|
+
ok: true;
|
|
112
|
+
orgId?: string;
|
|
113
|
+
account?: string;
|
|
114
|
+
} | {
|
|
115
|
+
ok: false;
|
|
116
|
+
error: string;
|
|
117
|
+
/** Set when the key's owner is in several organizations and one must be chosen. */
|
|
118
|
+
accounts?: Array<{
|
|
119
|
+
id: string;
|
|
120
|
+
name: string;
|
|
121
|
+
}>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Prove a Neon API key can do the job — list projects — and work out which
|
|
125
|
+
* organization it is used in. A personal key whose owner belongs to
|
|
126
|
+
* organizations has to name one; an organization or project key carries its
|
|
127
|
+
* own.
|
|
128
|
+
*/
|
|
129
|
+
export declare function resolveNeonAccount(input: {
|
|
130
|
+
token: string;
|
|
131
|
+
orgId?: string;
|
|
132
|
+
}, deps?: InfraObserveDeps): Promise<NeonAccountResult>;
|
|
133
|
+
/** Neon resource types a check can look at. */
|
|
134
|
+
export declare const NEON_OBSERVED_TYPES: readonly string[];
|
|
135
|
+
/**
|
|
136
|
+
* Look at the named Neon resources and say what was seen, with the same three
|
|
137
|
+
* outcomes as {@link observeCloudflare}. Keys for other providers are ignored.
|
|
138
|
+
*/
|
|
139
|
+
export declare function observeNeon(resourceKeys: readonly string[], access: NeonAccess, deps?: InfraObserveDeps): Promise<InfraObserveResult>;
|
|
102
140
|
//# sourceMappingURL=observe.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../src/infra/observe.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../src/infra/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAM1D,yDAAyD;AACzD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,+CAA+C;AAC/C,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAyDD,MAAM,MAAM,uBAAuB,GAC/B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACjD;IACE,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD,CAAC;AAEN;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,EAC5C,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,uBAAuB,CAAC,CAuDlC;AA2JD,qDAAqD;AACrD,eAAO,MAAM,yBAAyB,EAAE,SAAS,MA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CAAA;KAAE,CAAC,CAAC;CAChD,CAAC;AAEN;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EACxC,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAiE5B;AA6HD,+CAA+C;AAC/C,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAA6B,CAAC;AAE/E;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,MAAM,EAAE,UAAU,EAClB,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAO7B"}
|
package/dist/infra/observe.js
CHANGED
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
* Fetch-only and browser-safe. The token travels only in the Authorization
|
|
14
14
|
* header of requests to the provider's API, and never appears in a result.
|
|
15
15
|
*
|
|
16
|
-
* Cloudflare
|
|
17
|
-
* with no lookup is reported as skipped
|
|
16
|
+
* Cloudflare (Workers, R2, D1, KV, Queues and Containers) and Neon (projects
|
|
17
|
+
* and their databases). A resource type with no lookup is reported as skipped
|
|
18
|
+
* rather than guessed at.
|
|
18
19
|
*/
|
|
19
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.parseWranglerAuthToken = exports.withoutUnknownOverwrites = exports.observeCloudflare = exports.CLOUDFLARE_OBSERVED_TYPES = exports.resolveCloudflareAccount = void 0;
|
|
21
|
+
exports.observeNeon = exports.NEON_OBSERVED_TYPES = exports.resolveNeonAccount = exports.parseWranglerAuthToken = exports.withoutUnknownOverwrites = exports.observeCloudflare = exports.CLOUDFLARE_OBSERVED_TYPES = exports.resolveCloudflareAccount = void 0;
|
|
21
22
|
const CLOUDFLARE_API = 'https://api.cloudflare.com/client/v4';
|
|
22
23
|
const REQUEST_TIMEOUT_MS = 15000;
|
|
23
24
|
const ACCOUNT_ID_SHAPE = /^[a-f0-9]{32}$/;
|
|
@@ -242,49 +243,28 @@ const CHECKS = {
|
|
|
242
243
|
/** Cloudflare resource types a check can look at. */
|
|
243
244
|
exports.CLOUDFLARE_OBSERVED_TYPES = Object.keys(CHECKS);
|
|
244
245
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* Three outcomes per resource, kept apart on purpose:
|
|
248
|
-
* - it is there → `deployed`, with whatever address and dashboard page it has;
|
|
249
|
-
* - Cloudflare says it does not exist → `not-found`;
|
|
250
|
-
* - the question could not be asked (auth, network) → `unknown`.
|
|
251
|
-
*
|
|
252
|
-
* Failures are per resource: a token that cannot read R2 still gets the
|
|
253
|
-
* Workers checked, and the R2 failure is reported in `failure`. Keys for other
|
|
254
|
-
* providers are ignored.
|
|
246
|
+
* Run one provider's lookups over the keys that are its own. Keys for other
|
|
247
|
+
* providers are ignored; a type with no lookup is skipped, with the reason.
|
|
255
248
|
*/
|
|
256
|
-
async function
|
|
257
|
-
const doFetch = deps.fetch ?? fetch;
|
|
258
|
-
const now = deps.now ?? (() => new Date());
|
|
259
|
-
const { token, accountId } = access;
|
|
249
|
+
async function runChecks(provider, source, resourceKeys, checks, ctx, now) {
|
|
260
250
|
const skipped = [];
|
|
261
251
|
const targets = [];
|
|
262
252
|
for (const key of new Set(resourceKeys)) {
|
|
263
253
|
const parsed = parseKey(key);
|
|
264
|
-
if (!parsed || parsed.provider !==
|
|
254
|
+
if (!parsed || parsed.provider !== provider)
|
|
265
255
|
continue;
|
|
266
|
-
if (
|
|
256
|
+
if (Object.prototype.hasOwnProperty.call(checks, parsed.resourceType))
|
|
267
257
|
targets.push({ key, ...parsed });
|
|
268
258
|
else
|
|
269
259
|
skipped.push({ resourceKey: key, reason: `${parsed.resourceType} is not checked yet` });
|
|
270
260
|
}
|
|
271
261
|
const observedAt = now().toISOString();
|
|
272
|
-
const source = 'cloudflare-api';
|
|
273
|
-
let subdomain;
|
|
274
|
-
const ctx = {
|
|
275
|
-
accountId,
|
|
276
|
-
get: (path) => cloudflareGet(path, token, doFetch),
|
|
277
|
-
workersSubdomain: () => {
|
|
278
|
-
subdomain ?? (subdomain = cloudflareGet(`/accounts/${accountId}/workers/subdomain`, token, doFetch).then((sub) => sub.ok && typeof sub.result?.subdomain === 'string' ? sub.result.subdomain : undefined));
|
|
279
|
-
return subdomain;
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
262
|
const observations = [];
|
|
283
263
|
const failures = new Set();
|
|
284
264
|
for (const { key, resourceType, identifier } of targets) {
|
|
285
265
|
let seen;
|
|
286
266
|
try {
|
|
287
|
-
seen = await
|
|
267
|
+
seen = await checks[resourceType](identifier, ctx);
|
|
288
268
|
}
|
|
289
269
|
catch {
|
|
290
270
|
seen = { state: 'unknown', reason: `could not check ${resourceType}` };
|
|
@@ -307,6 +287,33 @@ async function observeCloudflare(resourceKeys, access, deps = {}) {
|
|
|
307
287
|
...(failures.size > 0 ? { failure: [...failures].join('; ') } : {}),
|
|
308
288
|
};
|
|
309
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Look at the named Cloudflare resources and say what was seen.
|
|
292
|
+
*
|
|
293
|
+
* Three outcomes per resource, kept apart on purpose:
|
|
294
|
+
* - it is there → `deployed`, with whatever address and dashboard page it has;
|
|
295
|
+
* - Cloudflare says it does not exist → `not-found`;
|
|
296
|
+
* - the question could not be asked (auth, network) → `unknown`.
|
|
297
|
+
*
|
|
298
|
+
* Failures are per resource: a token that cannot read R2 still gets the
|
|
299
|
+
* Workers checked, and the R2 failure is reported in `failure`. Keys for other
|
|
300
|
+
* providers are ignored.
|
|
301
|
+
*/
|
|
302
|
+
async function observeCloudflare(resourceKeys, access, deps = {}) {
|
|
303
|
+
const doFetch = deps.fetch ?? fetch;
|
|
304
|
+
const now = deps.now ?? (() => new Date());
|
|
305
|
+
const { token, accountId } = access;
|
|
306
|
+
let subdomain;
|
|
307
|
+
const ctx = {
|
|
308
|
+
accountId,
|
|
309
|
+
get: (path) => cloudflareGet(path, token, doFetch),
|
|
310
|
+
workersSubdomain: () => {
|
|
311
|
+
subdomain ?? (subdomain = cloudflareGet(`/accounts/${accountId}/workers/subdomain`, token, doFetch).then((sub) => sub.ok && typeof sub.result?.subdomain === 'string' ? sub.result.subdomain : undefined));
|
|
312
|
+
return subdomain;
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
return runChecks('cloudflare', 'cloudflare-api', resourceKeys, CHECKS, ctx, now);
|
|
316
|
+
}
|
|
310
317
|
exports.observeCloudflare = observeCloudflare;
|
|
311
318
|
/**
|
|
312
319
|
* Drop `unknown` observations for resources something is already known about.
|
|
@@ -344,4 +351,220 @@ function parseWranglerAuthToken(stdout) {
|
|
|
344
351
|
return { token, type };
|
|
345
352
|
}
|
|
346
353
|
exports.parseWranglerAuthToken = parseWranglerAuthToken;
|
|
354
|
+
// ── Neon ─────────────────────────────────────────────────────────────────────
|
|
355
|
+
const NEON_API = 'https://console.neon.tech/api/v2';
|
|
356
|
+
const NEON_ORG_ID_SHAPE = /^[a-z0-9-]{1,60}$/;
|
|
357
|
+
/** How many projects are opened to look for a database known only by name. */
|
|
358
|
+
const NEON_PROJECTS_SEARCHED = 20;
|
|
359
|
+
/** One read against the Neon API. Failures come back as values. */
|
|
360
|
+
async function neonGet(path, token, doFetch) {
|
|
361
|
+
let response;
|
|
362
|
+
try {
|
|
363
|
+
response = await doFetch(`${NEON_API}${path}`, {
|
|
364
|
+
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
|
|
365
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
return { ok: false, status: 0, message: 'could not reach the Neon API' };
|
|
370
|
+
}
|
|
371
|
+
let body;
|
|
372
|
+
try {
|
|
373
|
+
body = await response.json();
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
return { ok: false, status: response.status, message: `Neon answered ${response.status}` };
|
|
377
|
+
}
|
|
378
|
+
if (response.ok)
|
|
379
|
+
return { ok: true, result: body };
|
|
380
|
+
return {
|
|
381
|
+
ok: false,
|
|
382
|
+
status: response.status,
|
|
383
|
+
message: isRecord(body) && typeof body['message'] === 'string' && body['message']
|
|
384
|
+
? body['message']
|
|
385
|
+
: `Neon answered ${response.status}`,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Prove a Neon API key can do the job — list projects — and work out which
|
|
390
|
+
* organization it is used in. A personal key whose owner belongs to
|
|
391
|
+
* organizations has to name one; an organization or project key carries its
|
|
392
|
+
* own.
|
|
393
|
+
*/
|
|
394
|
+
async function resolveNeonAccount(input, deps = {}) {
|
|
395
|
+
const doFetch = deps.fetch ?? fetch;
|
|
396
|
+
const { token } = input;
|
|
397
|
+
let orgId = input.orgId?.trim() ?? '';
|
|
398
|
+
if (orgId && !NEON_ORG_ID_SHAPE.test(orgId)) {
|
|
399
|
+
return { ok: false, error: 'That does not look like a Neon organization id.' };
|
|
400
|
+
}
|
|
401
|
+
const probe = (org) => neonGet(`/projects?limit=1${org ? `&org_id=${encodeURIComponent(org)}` : ''}`, token, doFetch);
|
|
402
|
+
let probed = await probe(orgId);
|
|
403
|
+
if (!probed.ok && !orgId && probed.status === 400 && /org_id/i.test(probed.message)) {
|
|
404
|
+
const listed = await neonGet('/users/me/organizations', token, doFetch);
|
|
405
|
+
const organizations = (listed.ok && Array.isArray(listed.result?.organizations)
|
|
406
|
+
? listed.result.organizations
|
|
407
|
+
: [])
|
|
408
|
+
.filter((o) => typeof o?.id === 'string')
|
|
409
|
+
.map((o) => ({ id: o.id, name: o.name ?? o.id }));
|
|
410
|
+
if (organizations.length > 1) {
|
|
411
|
+
return {
|
|
412
|
+
ok: false,
|
|
413
|
+
error: 'This key can see several organizations. Choose one.',
|
|
414
|
+
accounts: organizations,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
if (organizations.length === 0) {
|
|
418
|
+
return {
|
|
419
|
+
ok: false,
|
|
420
|
+
error: 'This key needs an organization. Enter its organization id as the account id.',
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
orgId = organizations[0].id;
|
|
424
|
+
probed = await probe(orgId);
|
|
425
|
+
if (probed.ok)
|
|
426
|
+
return { ok: true, orgId, account: organizations[0].name };
|
|
427
|
+
}
|
|
428
|
+
if (!probed.ok) {
|
|
429
|
+
return {
|
|
430
|
+
ok: false,
|
|
431
|
+
error: probed.status === 0
|
|
432
|
+
? probed.message
|
|
433
|
+
: probed.status === 401 || probed.status === 403
|
|
434
|
+
? `Neon rejected the key: ${probed.message}`
|
|
435
|
+
: `The key cannot list projects: ${probed.message}`,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
// Who it is, best effort: an organization's name, or the key owner's.
|
|
439
|
+
let account;
|
|
440
|
+
if (orgId) {
|
|
441
|
+
const org = await neonGet(`/organizations/${encodeURIComponent(orgId)}`, token, doFetch);
|
|
442
|
+
if (org.ok && typeof org.result?.name === 'string')
|
|
443
|
+
account = org.result.name;
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
const me = await neonGet('/users/me', token, doFetch);
|
|
447
|
+
if (me.ok) {
|
|
448
|
+
const full = [me.result?.name, me.result?.last_name].filter((part) => typeof part === 'string' && part).join(' ');
|
|
449
|
+
account = full || (typeof me.result?.login === 'string' ? me.result.login : undefined);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return { ok: true, ...(orgId ? { orgId } : {}), ...(account ? { account } : {}) };
|
|
453
|
+
}
|
|
454
|
+
exports.resolveNeonAccount = resolveNeonAccount;
|
|
455
|
+
const neonConsole = (projectId) => `https://console.neon.tech/app/projects/${encodeURIComponent(projectId)}`;
|
|
456
|
+
/** Projects whose name or id is exactly `wanted`. The search itself is partial. */
|
|
457
|
+
async function neonProjectsNamed(wanted, ctx) {
|
|
458
|
+
const listed = await ctx.get(`/projects?limit=100&search=${encodeURIComponent(wanted)}${ctx.org}`);
|
|
459
|
+
if (!listed.ok)
|
|
460
|
+
return listed;
|
|
461
|
+
if (!Array.isArray(listed.result?.projects)) {
|
|
462
|
+
return { ok: false, status: 200, message: 'unexpected answer for projects' };
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
ok: true,
|
|
466
|
+
result: listed.result.projects.filter((p) => typeof p?.id === 'string' && (p.id === wanted || p.name === wanted)),
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
/** Whether the project's default branch holds a database of that name. */
|
|
470
|
+
async function neonHasDatabase(projectId, database, ctx) {
|
|
471
|
+
const project = encodeURIComponent(projectId);
|
|
472
|
+
const branches = await ctx.get(`/projects/${project}/branches`);
|
|
473
|
+
if (!branches.ok)
|
|
474
|
+
return { reason: branches.message };
|
|
475
|
+
const list = Array.isArray(branches.result?.branches) ? branches.result.branches : [];
|
|
476
|
+
const branch = list.find((b) => b?.default === true) ?? list.find((b) => b?.primary === true);
|
|
477
|
+
if (typeof branch?.id !== 'string')
|
|
478
|
+
return { reason: 'no default branch found' };
|
|
479
|
+
const databases = await ctx.get(`/projects/${project}/branches/${encodeURIComponent(branch.id)}/databases`);
|
|
480
|
+
if (!databases.ok)
|
|
481
|
+
return { reason: databases.message };
|
|
482
|
+
if (!Array.isArray(databases.result?.databases))
|
|
483
|
+
return { reason: 'unexpected answer for databases' };
|
|
484
|
+
return { found: databases.result.databases.some((d) => d?.name === database) };
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Neon lookups. A key names a project by its name or id; a database is named
|
|
488
|
+
* either as `project/database`, or by one name alone, which is taken as the
|
|
489
|
+
* project's name first (people call the whole project "the database") and
|
|
490
|
+
* then as a database inside whichever project holds it. Every call is a read.
|
|
491
|
+
*/
|
|
492
|
+
const NEON_CHECKS = {
|
|
493
|
+
project: async (wanted, ctx) => {
|
|
494
|
+
const found = await neonProjectsNamed(wanted, ctx);
|
|
495
|
+
if (!found.ok)
|
|
496
|
+
return { state: 'unknown', reason: found.message };
|
|
497
|
+
const project = found.result[0];
|
|
498
|
+
if (!project)
|
|
499
|
+
return { state: 'not-found' };
|
|
500
|
+
return { state: 'deployed', resourceId: project.id, consoleUrl: neonConsole(project.id) };
|
|
501
|
+
},
|
|
502
|
+
database: async (wanted, ctx) => {
|
|
503
|
+
const slash = wanted.indexOf('/');
|
|
504
|
+
const projectName = slash > 0 ? wanted.slice(0, slash) : wanted;
|
|
505
|
+
const databaseName = slash > 0 ? wanted.slice(slash + 1) : '';
|
|
506
|
+
const named = await neonProjectsNamed(projectName, ctx);
|
|
507
|
+
if (!named.ok)
|
|
508
|
+
return { state: 'unknown', reason: named.message };
|
|
509
|
+
const project = named.result[0];
|
|
510
|
+
if (databaseName) {
|
|
511
|
+
if (!project)
|
|
512
|
+
return { state: 'not-found' };
|
|
513
|
+
const held = await neonHasDatabase(project.id, databaseName, ctx);
|
|
514
|
+
if ('reason' in held)
|
|
515
|
+
return { state: 'unknown', reason: held.reason };
|
|
516
|
+
return held.found
|
|
517
|
+
? { state: 'deployed', resourceId: `${project.id}/${databaseName}`, consoleUrl: neonConsole(project.id) }
|
|
518
|
+
: { state: 'not-found' };
|
|
519
|
+
}
|
|
520
|
+
if (project) {
|
|
521
|
+
return { state: 'deployed', resourceId: project.id, consoleUrl: neonConsole(project.id) };
|
|
522
|
+
}
|
|
523
|
+
// No project of that name: look for a database of that name instead.
|
|
524
|
+
const all = await ctx.get(`/projects?limit=${NEON_PROJECTS_SEARCHED + 1}${ctx.org}`);
|
|
525
|
+
if (!all.ok)
|
|
526
|
+
return { state: 'unknown', reason: all.message };
|
|
527
|
+
const projects = (Array.isArray(all.result?.projects) ? all.result.projects : []).filter((p) => typeof p?.id === 'string');
|
|
528
|
+
let unread;
|
|
529
|
+
for (const candidate of projects.slice(0, NEON_PROJECTS_SEARCHED)) {
|
|
530
|
+
const held = await neonHasDatabase(candidate.id, wanted, ctx);
|
|
531
|
+
if ('reason' in held) {
|
|
532
|
+
unread ?? (unread = held.reason);
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
if (held.found) {
|
|
536
|
+
return {
|
|
537
|
+
state: 'deployed',
|
|
538
|
+
resourceId: `${candidate.id}/${wanted}`,
|
|
539
|
+
consoleUrl: neonConsole(candidate.id),
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
// "Not there" is only said when everywhere it could be was read.
|
|
544
|
+
if (unread)
|
|
545
|
+
return { state: 'unknown', reason: unread };
|
|
546
|
+
if (projects.length > NEON_PROJECTS_SEARCHED) {
|
|
547
|
+
return {
|
|
548
|
+
state: 'unknown',
|
|
549
|
+
reason: `no project is named ${wanted}, and there are too many to search; name it as project/database`,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
return { state: 'not-found' };
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
/** Neon resource types a check can look at. */
|
|
556
|
+
exports.NEON_OBSERVED_TYPES = Object.keys(NEON_CHECKS);
|
|
557
|
+
/**
|
|
558
|
+
* Look at the named Neon resources and say what was seen, with the same three
|
|
559
|
+
* outcomes as {@link observeCloudflare}. Keys for other providers are ignored.
|
|
560
|
+
*/
|
|
561
|
+
async function observeNeon(resourceKeys, access, deps = {}) {
|
|
562
|
+
const doFetch = deps.fetch ?? fetch;
|
|
563
|
+
const ctx = {
|
|
564
|
+
get: (path) => neonGet(path, access.token, doFetch),
|
|
565
|
+
org: access.orgId ? `&org_id=${encodeURIComponent(access.orgId)}` : '',
|
|
566
|
+
};
|
|
567
|
+
return runChecks('neon', 'neon-api', resourceKeys, NEON_CHECKS, ctx, deps.now ?? (() => new Date()));
|
|
568
|
+
}
|
|
569
|
+
exports.observeNeon = observeNeon;
|
|
347
570
|
//# sourceMappingURL=observe.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe.js","sourceRoot":"","sources":["../../src/infra/observe.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAIH,MAAM,cAAc,G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AAC;aACH;SACF;QACD,iEAAiE;QACjE,IAAI,MAAM;YAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QACxD,IAAI,QAAQ,CAAC,MAAM,GAAG,sBAAsB,EAAE;YAC5C,OAAO;gBACL,KAAK,EAAE,SAAS;gBAChB,MAAM,EAAE,uBAAuB,MAAM,iEAAiE;aACvG,CAAC;SACH;QACD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAChC,CAAC;CACF,CAAC;AAEF,+CAA+C;AAClC,QAAA,mBAAmB,GAAsB,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAE/E;;;GAGG;AACI,KAAK,UAAU,WAAW,CAC/B,YAA+B,EAC/B,MAAkB,EAClB,OAAyB,EAAE;IAE3B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;IACpC,MAAM,GAAG,GAAgB;QACvB,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;QACnD,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;KACvE,CAAC;IACF,OAAO,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;AACvG,CAAC;AAXD,kCAWC"}
|
package/package.json
CHANGED
package/src/infra/index.ts
CHANGED
|
@@ -23,9 +23,12 @@ export { infraContainerId, infraDeploymentRef, infraToC4 } from './c4';
|
|
|
23
23
|
export type { InfraC4Container, InfraC4Deployment, InfraC4Edge } from './c4';
|
|
24
24
|
export {
|
|
25
25
|
CLOUDFLARE_OBSERVED_TYPES,
|
|
26
|
+
NEON_OBSERVED_TYPES,
|
|
26
27
|
observeCloudflare,
|
|
28
|
+
observeNeon,
|
|
27
29
|
parseWranglerAuthToken,
|
|
28
30
|
resolveCloudflareAccount,
|
|
31
|
+
resolveNeonAccount,
|
|
29
32
|
withoutUnknownOverwrites,
|
|
30
33
|
} from './observe';
|
|
31
34
|
export type {
|
|
@@ -33,4 +36,6 @@ export type {
|
|
|
33
36
|
CloudflareAccountResult,
|
|
34
37
|
InfraObserveDeps,
|
|
35
38
|
InfraObserveResult,
|
|
39
|
+
NeonAccess,
|
|
40
|
+
NeonAccountResult,
|
|
36
41
|
} from './observe';
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { observeNeon, resolveNeonAccount } from './observe';
|
|
3
|
+
|
|
4
|
+
const KEY = `napi_${'k'.repeat(64)}`;
|
|
5
|
+
const NOW = () => new Date('2026-12-05T12:00:00.000Z');
|
|
6
|
+
|
|
7
|
+
type Route = { status?: number; body: unknown };
|
|
8
|
+
|
|
9
|
+
/** A Neon API stand-in: path (with query, when given) → answer. */
|
|
10
|
+
function fakeNeon(routes: Record<string, Route>) {
|
|
11
|
+
const seen: Array<{ method: string; path: string; authorization: string | null }> = [];
|
|
12
|
+
const fetchImpl = (async (input: string | URL | Request, init?: RequestInit) => {
|
|
13
|
+
const url = new URL(String(input));
|
|
14
|
+
expect(url.origin).toBe('https://console.neon.tech');
|
|
15
|
+
const path = url.pathname.replace('/api/v2', '');
|
|
16
|
+
seen.push({
|
|
17
|
+
method: init?.method ?? 'GET',
|
|
18
|
+
path: `${path}${url.search}`,
|
|
19
|
+
authorization: new Headers(init?.headers).get('authorization'),
|
|
20
|
+
});
|
|
21
|
+
const route = routes[`${path}${url.search}`] ?? routes[path];
|
|
22
|
+
if (!route) return Response.json({ code: '', message: 'not found' }, { status: 404 });
|
|
23
|
+
return Response.json(route.body, { status: route.status ?? 200 });
|
|
24
|
+
}) as typeof fetch;
|
|
25
|
+
return { fetchImpl, seen };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const branches = (projectId: string) => ({
|
|
29
|
+
[`/projects/${projectId}/branches`]: {
|
|
30
|
+
body: { branches: [{ id: 'br-dev', default: false }, { id: 'br-main', default: true }] },
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const databases = (projectId: string, names: string[]) => ({
|
|
34
|
+
[`/projects/${projectId}/branches/br-main/databases`]: {
|
|
35
|
+
body: { databases: names.map((name) => ({ name })) },
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('resolveNeonAccount', () => {
|
|
40
|
+
test('a key that can list projects is accepted, named after its owner', async () => {
|
|
41
|
+
const { fetchImpl, seen } = fakeNeon({
|
|
42
|
+
'/projects': { body: { projects: [] } },
|
|
43
|
+
'/users/me': { body: { name: 'Ada', last_name: 'Lovelace', email: 'ada@example.com' } },
|
|
44
|
+
});
|
|
45
|
+
expect(await resolveNeonAccount({ token: KEY }, { fetch: fetchImpl })).toEqual({
|
|
46
|
+
ok: true,
|
|
47
|
+
account: 'Ada Lovelace',
|
|
48
|
+
});
|
|
49
|
+
expect(seen.every((call) => call.method === 'GET')).toBe(true);
|
|
50
|
+
expect(seen.every((call) => call.authorization === `Bearer ${KEY}`)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('a personal key in one organization uses that organization', async () => {
|
|
54
|
+
const { fetchImpl } = fakeNeon({
|
|
55
|
+
'/projects?limit=1': { status: 400, body: { code: '', message: 'org_id is required' } },
|
|
56
|
+
'/projects?limit=1&org_id=org-acme-1': { body: { projects: [] } },
|
|
57
|
+
'/users/me/organizations': { body: { organizations: [{ id: 'org-acme-1', name: 'Acme' }] } },
|
|
58
|
+
});
|
|
59
|
+
expect(await resolveNeonAccount({ token: KEY }, { fetch: fetchImpl })).toEqual({
|
|
60
|
+
ok: true,
|
|
61
|
+
orgId: 'org-acme-1',
|
|
62
|
+
account: 'Acme',
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('several organizations: the caller has to choose', async () => {
|
|
67
|
+
const { fetchImpl } = fakeNeon({
|
|
68
|
+
'/projects?limit=1': { status: 400, body: { code: '', message: 'org_id is required' } },
|
|
69
|
+
'/users/me/organizations': {
|
|
70
|
+
body: { organizations: [{ id: 'org-a', name: 'A' }, { id: 'org-b', name: 'B' }] },
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const result = await resolveNeonAccount({ token: KEY }, { fetch: fetchImpl });
|
|
74
|
+
expect(result.ok).toBe(false);
|
|
75
|
+
expect(!result.ok && result.accounts).toEqual([
|
|
76
|
+
{ id: 'org-a', name: 'A' },
|
|
77
|
+
{ id: 'org-b', name: 'B' },
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('a chosen organization is used and named', async () => {
|
|
82
|
+
const { fetchImpl } = fakeNeon({
|
|
83
|
+
'/projects?limit=1&org_id=org-b': { body: { projects: [] } },
|
|
84
|
+
'/organizations/org-b': { body: { id: 'org-b', name: 'B' } },
|
|
85
|
+
});
|
|
86
|
+
expect(await resolveNeonAccount({ token: KEY, orgId: 'org-b' }, { fetch: fetchImpl })).toEqual({
|
|
87
|
+
ok: true,
|
|
88
|
+
orgId: 'org-b',
|
|
89
|
+
account: 'B',
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('a rejected key says so, and never echoes the key', async () => {
|
|
94
|
+
const { fetchImpl } = fakeNeon({
|
|
95
|
+
'/projects': { status: 401, body: { code: '', message: 'authentication failed' } },
|
|
96
|
+
});
|
|
97
|
+
const result = await resolveNeonAccount({ token: KEY }, { fetch: fetchImpl });
|
|
98
|
+
expect(result).toEqual({ ok: false, error: 'Neon rejected the key: authentication failed' });
|
|
99
|
+
expect(JSON.stringify(result)).not.toContain(KEY);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('a malformed organization id is refused before any request', async () => {
|
|
103
|
+
const { fetchImpl, seen } = fakeNeon({});
|
|
104
|
+
const result = await resolveNeonAccount({ token: KEY, orgId: 'Not An Org' }, { fetch: fetchImpl });
|
|
105
|
+
expect(result.ok).toBe(false);
|
|
106
|
+
expect(seen).toEqual([]);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('observeNeon', () => {
|
|
111
|
+
test('a database named after its project is deployed; the search is matched exactly', async () => {
|
|
112
|
+
const { fetchImpl, seen } = fakeNeon({
|
|
113
|
+
'/projects?limit=100&search=openbot': {
|
|
114
|
+
body: {
|
|
115
|
+
projects: [
|
|
116
|
+
{ id: 'old-moon-1', name: 'openbot-staging' },
|
|
117
|
+
{ id: 'calm-sea-2', name: 'openbot' },
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
const result = await observeNeon(
|
|
123
|
+
['neon:database:openbot', 'cloudflare:worker:openbot', 'neon:role:app'],
|
|
124
|
+
{ token: KEY },
|
|
125
|
+
{ fetch: fetchImpl, now: NOW },
|
|
126
|
+
);
|
|
127
|
+
expect(result.observations).toEqual([
|
|
128
|
+
{
|
|
129
|
+
resourceKey: 'neon:database:openbot',
|
|
130
|
+
status: 'deployed',
|
|
131
|
+
resourceId: 'calm-sea-2',
|
|
132
|
+
consoleUrl: 'https://console.neon.tech/app/projects/calm-sea-2',
|
|
133
|
+
observedAt: '2026-12-05T12:00:00.000Z',
|
|
134
|
+
source: 'neon-api',
|
|
135
|
+
},
|
|
136
|
+
]);
|
|
137
|
+
expect(result.skipped).toEqual([{ resourceKey: 'neon:role:app', reason: 'role is not checked yet' }]);
|
|
138
|
+
expect(result.failure).toBeUndefined();
|
|
139
|
+
expect(seen.every((call) => call.method === 'GET')).toBe(true);
|
|
140
|
+
expect(JSON.stringify(result)).not.toContain(KEY);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('a project can be named by id, and the organization is passed along', async () => {
|
|
144
|
+
const { fetchImpl } = fakeNeon({
|
|
145
|
+
'/projects?limit=100&search=calm-sea-2&org_id=org-acme-1': {
|
|
146
|
+
body: { projects: [{ id: 'calm-sea-2', name: 'whatever' }] },
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
const result = await observeNeon(
|
|
150
|
+
['neon:project:calm-sea-2'],
|
|
151
|
+
{ token: KEY, orgId: 'org-acme-1' },
|
|
152
|
+
{ fetch: fetchImpl, now: NOW },
|
|
153
|
+
);
|
|
154
|
+
expect(result.observations[0]).toMatchObject({ status: 'deployed', resourceId: 'calm-sea-2' });
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('project/database looks on the default branch', async () => {
|
|
158
|
+
const { fetchImpl } = fakeNeon({
|
|
159
|
+
'/projects?limit=100&search=shop': { body: { projects: [{ id: 'p1', name: 'shop' }] } },
|
|
160
|
+
'/projects?limit=100&search=nope': { body: { projects: [] } },
|
|
161
|
+
...branches('p1'),
|
|
162
|
+
...databases('p1', ['neondb', 'orders']),
|
|
163
|
+
});
|
|
164
|
+
const result = await observeNeon(
|
|
165
|
+
['neon:database:shop/orders', 'neon:database:shop/missing', 'neon:database:nope/orders'],
|
|
166
|
+
{ token: KEY },
|
|
167
|
+
{ fetch: fetchImpl, now: NOW },
|
|
168
|
+
);
|
|
169
|
+
expect(result.observations.map((o) => [o.resourceKey, o.status, o.resourceId])).toEqual([
|
|
170
|
+
['neon:database:shop/orders', 'deployed', 'p1/orders'],
|
|
171
|
+
['neon:database:shop/missing', 'not-found', undefined],
|
|
172
|
+
['neon:database:nope/orders', 'not-found', undefined],
|
|
173
|
+
]);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('a lone name that is no project is looked for as a database in each project', async () => {
|
|
177
|
+
const { fetchImpl } = fakeNeon({
|
|
178
|
+
'/projects?limit=100&search=orders': { body: { projects: [] } },
|
|
179
|
+
'/projects?limit=100&search=ghost': { body: { projects: [] } },
|
|
180
|
+
'/projects?limit=21': { body: { projects: [{ id: 'p1', name: 'a' }, { id: 'p2', name: 'b' }] } },
|
|
181
|
+
...branches('p1'),
|
|
182
|
+
...databases('p1', ['neondb']),
|
|
183
|
+
...branches('p2'),
|
|
184
|
+
...databases('p2', ['orders']),
|
|
185
|
+
});
|
|
186
|
+
const result = await observeNeon(
|
|
187
|
+
['neon:database:orders', 'neon:database:ghost'],
|
|
188
|
+
{ token: KEY },
|
|
189
|
+
{ fetch: fetchImpl, now: NOW },
|
|
190
|
+
);
|
|
191
|
+
expect(result.observations.map((o) => [o.status, o.resourceId])).toEqual([
|
|
192
|
+
['deployed', 'p2/orders'],
|
|
193
|
+
['not-found', undefined],
|
|
194
|
+
]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('not found is not claimed when a project could not be read or there are too many', async () => {
|
|
198
|
+
const many = Array.from({ length: 21 }, (_, i) => ({ id: `p${i}`, name: `n${i}` }));
|
|
199
|
+
const empty = Object.assign(
|
|
200
|
+
{},
|
|
201
|
+
...many.map((p) => ({ ...branches(p.id), ...databases(p.id, ['neondb']) })),
|
|
202
|
+
);
|
|
203
|
+
const tooMany = fakeNeon({
|
|
204
|
+
'/projects?limit=100&search=orders': { body: { projects: [] } },
|
|
205
|
+
'/projects?limit=21': { body: { projects: many } },
|
|
206
|
+
...empty,
|
|
207
|
+
});
|
|
208
|
+
const first = await observeNeon(['neon:database:orders'], { token: KEY }, { fetch: tooMany.fetchImpl, now: NOW });
|
|
209
|
+
expect(first.observations[0]?.status).toBe('unknown');
|
|
210
|
+
expect(first.failure).toContain('project/database');
|
|
211
|
+
|
|
212
|
+
const unreadable = fakeNeon({
|
|
213
|
+
'/projects?limit=100&search=orders': { body: { projects: [] } },
|
|
214
|
+
'/projects?limit=21': { body: { projects: [{ id: 'p1', name: 'a' }] } },
|
|
215
|
+
'/projects/p1/branches': { status: 403, body: { code: '', message: 'forbidden' } },
|
|
216
|
+
});
|
|
217
|
+
const second = await observeNeon(['neon:database:orders'], { token: KEY }, { fetch: unreadable.fetchImpl, now: NOW });
|
|
218
|
+
expect(second.observations[0]?.status).toBe('unknown');
|
|
219
|
+
expect(second.failure).toBe('database: forbidden');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('a failed request is unknown, with the reason', async () => {
|
|
223
|
+
const { fetchImpl } = fakeNeon({
|
|
224
|
+
'/projects': { status: 401, body: { code: '', message: 'authentication failed' } },
|
|
225
|
+
});
|
|
226
|
+
const result = await observeNeon(['neon:project:x'], { token: KEY }, { fetch: fetchImpl, now: NOW });
|
|
227
|
+
expect(result.observations).toEqual([
|
|
228
|
+
{ resourceKey: 'neon:project:x', status: 'unknown', observedAt: '2026-12-05T12:00:00.000Z', source: 'neon-api' },
|
|
229
|
+
]);
|
|
230
|
+
expect(result.failure).toBe('project: authentication failed');
|
|
231
|
+
});
|
|
232
|
+
});
|
package/src/infra/observe.ts
CHANGED
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
* Fetch-only and browser-safe. The token travels only in the Authorization
|
|
13
13
|
* header of requests to the provider's API, and never appears in a result.
|
|
14
14
|
*
|
|
15
|
-
* Cloudflare
|
|
16
|
-
* with no lookup is reported as skipped
|
|
15
|
+
* Cloudflare (Workers, R2, D1, KV, Queues and Containers) and Neon (projects
|
|
16
|
+
* and their databases). A resource type with no lookup is reported as skipped
|
|
17
|
+
* rather than guessed at.
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
20
|
import type { InfraDeploymentObservation } from './types';
|
|
@@ -336,59 +337,33 @@ export interface InfraObserveResult {
|
|
|
336
337
|
}
|
|
337
338
|
|
|
338
339
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* Three outcomes per resource, kept apart on purpose:
|
|
342
|
-
* - it is there → `deployed`, with whatever address and dashboard page it has;
|
|
343
|
-
* - Cloudflare says it does not exist → `not-found`;
|
|
344
|
-
* - the question could not be asked (auth, network) → `unknown`.
|
|
345
|
-
*
|
|
346
|
-
* Failures are per resource: a token that cannot read R2 still gets the
|
|
347
|
-
* Workers checked, and the R2 failure is reported in `failure`. Keys for other
|
|
348
|
-
* providers are ignored.
|
|
340
|
+
* Run one provider's lookups over the keys that are its own. Keys for other
|
|
341
|
+
* providers are ignored; a type with no lookup is skipped, with the reason.
|
|
349
342
|
*/
|
|
350
|
-
|
|
343
|
+
async function runChecks<C>(
|
|
344
|
+
provider: string,
|
|
345
|
+
source: string,
|
|
351
346
|
resourceKeys: readonly string[],
|
|
352
|
-
|
|
353
|
-
|
|
347
|
+
checks: Record<string, (identifier: string, ctx: C) => Promise<Seen>>,
|
|
348
|
+
ctx: C,
|
|
349
|
+
now: () => Date,
|
|
354
350
|
): Promise<InfraObserveResult> {
|
|
355
|
-
const doFetch = deps.fetch ?? fetch;
|
|
356
|
-
const now = deps.now ?? (() => new Date());
|
|
357
|
-
const { token, accountId } = access;
|
|
358
|
-
|
|
359
351
|
const skipped: InfraObserveResult['skipped'] = [];
|
|
360
352
|
const targets: Array<{ key: string; resourceType: string; identifier: string }> = [];
|
|
361
353
|
for (const key of new Set(resourceKeys)) {
|
|
362
354
|
const parsed = parseKey(key);
|
|
363
|
-
if (!parsed || parsed.provider !==
|
|
364
|
-
if (
|
|
355
|
+
if (!parsed || parsed.provider !== provider) continue;
|
|
356
|
+
if (Object.prototype.hasOwnProperty.call(checks, parsed.resourceType)) targets.push({ key, ...parsed });
|
|
365
357
|
else skipped.push({ resourceKey: key, reason: `${parsed.resourceType} is not checked yet` });
|
|
366
358
|
}
|
|
367
359
|
|
|
368
360
|
const observedAt = now().toISOString();
|
|
369
|
-
const source = 'cloudflare-api';
|
|
370
|
-
let subdomain: Promise<string | undefined> | undefined;
|
|
371
|
-
const ctx: CheckContext = {
|
|
372
|
-
accountId,
|
|
373
|
-
get: (path) => cloudflareGet(path, token, doFetch),
|
|
374
|
-
workersSubdomain: () => {
|
|
375
|
-
subdomain ??= cloudflareGet<{ subdomain?: string }>(
|
|
376
|
-
`/accounts/${accountId}/workers/subdomain`,
|
|
377
|
-
token,
|
|
378
|
-
doFetch,
|
|
379
|
-
).then((sub) =>
|
|
380
|
-
sub.ok && typeof sub.result?.subdomain === 'string' ? sub.result.subdomain : undefined,
|
|
381
|
-
);
|
|
382
|
-
return subdomain;
|
|
383
|
-
},
|
|
384
|
-
};
|
|
385
|
-
|
|
386
361
|
const observations: InfraDeploymentObservation[] = [];
|
|
387
362
|
const failures = new Set<string>();
|
|
388
363
|
for (const { key, resourceType, identifier } of targets) {
|
|
389
364
|
let seen: Seen;
|
|
390
365
|
try {
|
|
391
|
-
seen = await
|
|
366
|
+
seen = await checks[resourceType]!(identifier, ctx);
|
|
392
367
|
} catch {
|
|
393
368
|
seen = { state: 'unknown', reason: `could not check ${resourceType}` };
|
|
394
369
|
}
|
|
@@ -411,6 +386,46 @@ export async function observeCloudflare(
|
|
|
411
386
|
};
|
|
412
387
|
}
|
|
413
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Look at the named Cloudflare resources and say what was seen.
|
|
391
|
+
*
|
|
392
|
+
* Three outcomes per resource, kept apart on purpose:
|
|
393
|
+
* - it is there → `deployed`, with whatever address and dashboard page it has;
|
|
394
|
+
* - Cloudflare says it does not exist → `not-found`;
|
|
395
|
+
* - the question could not be asked (auth, network) → `unknown`.
|
|
396
|
+
*
|
|
397
|
+
* Failures are per resource: a token that cannot read R2 still gets the
|
|
398
|
+
* Workers checked, and the R2 failure is reported in `failure`. Keys for other
|
|
399
|
+
* providers are ignored.
|
|
400
|
+
*/
|
|
401
|
+
export async function observeCloudflare(
|
|
402
|
+
resourceKeys: readonly string[],
|
|
403
|
+
access: CloudflareAccess,
|
|
404
|
+
deps: InfraObserveDeps = {},
|
|
405
|
+
): Promise<InfraObserveResult> {
|
|
406
|
+
const doFetch = deps.fetch ?? fetch;
|
|
407
|
+
const now = deps.now ?? (() => new Date());
|
|
408
|
+
const { token, accountId } = access;
|
|
409
|
+
|
|
410
|
+
let subdomain: Promise<string | undefined> | undefined;
|
|
411
|
+
const ctx: CheckContext = {
|
|
412
|
+
accountId,
|
|
413
|
+
get: (path) => cloudflareGet(path, token, doFetch),
|
|
414
|
+
workersSubdomain: () => {
|
|
415
|
+
subdomain ??= cloudflareGet<{ subdomain?: string }>(
|
|
416
|
+
`/accounts/${accountId}/workers/subdomain`,
|
|
417
|
+
token,
|
|
418
|
+
doFetch,
|
|
419
|
+
).then((sub) =>
|
|
420
|
+
sub.ok && typeof sub.result?.subdomain === 'string' ? sub.result.subdomain : undefined,
|
|
421
|
+
);
|
|
422
|
+
return subdomain;
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
return runChecks('cloudflare', 'cloudflare-api', resourceKeys, CHECKS, ctx, now);
|
|
427
|
+
}
|
|
428
|
+
|
|
414
429
|
/**
|
|
415
430
|
* Drop `unknown` observations for resources something is already known about.
|
|
416
431
|
* A failed check must not erase what was known: `unknown` is only worth
|
|
@@ -449,3 +464,278 @@ export function parseWranglerAuthToken(
|
|
|
449
464
|
if (typeof token !== 'string' || !/^[\x21-\x7e]{20,4096}$/.test(token)) return null;
|
|
450
465
|
return { token, type };
|
|
451
466
|
}
|
|
467
|
+
|
|
468
|
+
// ── Neon ─────────────────────────────────────────────────────────────────────
|
|
469
|
+
|
|
470
|
+
const NEON_API = 'https://console.neon.tech/api/v2';
|
|
471
|
+
const NEON_ORG_ID_SHAPE = /^[a-z0-9-]{1,60}$/;
|
|
472
|
+
/** How many projects are opened to look for a database known only by name. */
|
|
473
|
+
const NEON_PROJECTS_SEARCHED = 20;
|
|
474
|
+
|
|
475
|
+
/** A credential for Neon: an API key, and the organization it is used in. */
|
|
476
|
+
export interface NeonAccess {
|
|
477
|
+
/** A personal, organization or project-scoped API key; sent as a Bearer token. */
|
|
478
|
+
token: string;
|
|
479
|
+
/** Needed with a personal key whose owner belongs to an organization. */
|
|
480
|
+
orgId?: string;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
type NeonResult<T> =
|
|
484
|
+
| { ok: true; result: T }
|
|
485
|
+
| { ok: false; status: number; message: string };
|
|
486
|
+
|
|
487
|
+
/** One read against the Neon API. Failures come back as values. */
|
|
488
|
+
async function neonGet<T>(path: string, token: string, doFetch: typeof fetch): Promise<NeonResult<T>> {
|
|
489
|
+
let response: Response;
|
|
490
|
+
try {
|
|
491
|
+
response = await doFetch(`${NEON_API}${path}`, {
|
|
492
|
+
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
|
|
493
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
494
|
+
});
|
|
495
|
+
} catch {
|
|
496
|
+
return { ok: false, status: 0, message: 'could not reach the Neon API' };
|
|
497
|
+
}
|
|
498
|
+
let body: unknown;
|
|
499
|
+
try {
|
|
500
|
+
body = await response.json();
|
|
501
|
+
} catch {
|
|
502
|
+
return { ok: false, status: response.status, message: `Neon answered ${response.status}` };
|
|
503
|
+
}
|
|
504
|
+
if (response.ok) return { ok: true, result: body as T };
|
|
505
|
+
return {
|
|
506
|
+
ok: false,
|
|
507
|
+
status: response.status,
|
|
508
|
+
message:
|
|
509
|
+
isRecord(body) && typeof body['message'] === 'string' && body['message']
|
|
510
|
+
? body['message']
|
|
511
|
+
: `Neon answered ${response.status}`,
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export type NeonAccountResult =
|
|
516
|
+
| { ok: true; orgId?: string; account?: string }
|
|
517
|
+
| {
|
|
518
|
+
ok: false;
|
|
519
|
+
error: string;
|
|
520
|
+
/** Set when the key's owner is in several organizations and one must be chosen. */
|
|
521
|
+
accounts?: Array<{ id: string; name: string }>;
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Prove a Neon API key can do the job — list projects — and work out which
|
|
526
|
+
* organization it is used in. A personal key whose owner belongs to
|
|
527
|
+
* organizations has to name one; an organization or project key carries its
|
|
528
|
+
* own.
|
|
529
|
+
*/
|
|
530
|
+
export async function resolveNeonAccount(
|
|
531
|
+
input: { token: string; orgId?: string },
|
|
532
|
+
deps: InfraObserveDeps = {},
|
|
533
|
+
): Promise<NeonAccountResult> {
|
|
534
|
+
const doFetch = deps.fetch ?? fetch;
|
|
535
|
+
const { token } = input;
|
|
536
|
+
let orgId = input.orgId?.trim() ?? '';
|
|
537
|
+
if (orgId && !NEON_ORG_ID_SHAPE.test(orgId)) {
|
|
538
|
+
return { ok: false, error: 'That does not look like a Neon organization id.' };
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const probe = (org: string) =>
|
|
542
|
+
neonGet<unknown>(`/projects?limit=1${org ? `&org_id=${encodeURIComponent(org)}` : ''}`, token, doFetch);
|
|
543
|
+
let probed = await probe(orgId);
|
|
544
|
+
if (!probed.ok && !orgId && probed.status === 400 && /org_id/i.test(probed.message)) {
|
|
545
|
+
const listed = await neonGet<{ organizations?: Array<{ id?: string; name?: string }> }>(
|
|
546
|
+
'/users/me/organizations',
|
|
547
|
+
token,
|
|
548
|
+
doFetch,
|
|
549
|
+
);
|
|
550
|
+
const organizations = (listed.ok && Array.isArray(listed.result?.organizations)
|
|
551
|
+
? listed.result.organizations
|
|
552
|
+
: []
|
|
553
|
+
)
|
|
554
|
+
.filter((o): o is { id: string; name?: string } => typeof o?.id === 'string')
|
|
555
|
+
.map((o) => ({ id: o.id, name: o.name ?? o.id }));
|
|
556
|
+
if (organizations.length > 1) {
|
|
557
|
+
return {
|
|
558
|
+
ok: false,
|
|
559
|
+
error: 'This key can see several organizations. Choose one.',
|
|
560
|
+
accounts: organizations,
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
if (organizations.length === 0) {
|
|
564
|
+
return {
|
|
565
|
+
ok: false,
|
|
566
|
+
error: 'This key needs an organization. Enter its organization id as the account id.',
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
orgId = organizations[0]!.id;
|
|
570
|
+
probed = await probe(orgId);
|
|
571
|
+
if (probed.ok) return { ok: true, orgId, account: organizations[0]!.name };
|
|
572
|
+
}
|
|
573
|
+
if (!probed.ok) {
|
|
574
|
+
return {
|
|
575
|
+
ok: false,
|
|
576
|
+
error:
|
|
577
|
+
probed.status === 0
|
|
578
|
+
? probed.message
|
|
579
|
+
: probed.status === 401 || probed.status === 403
|
|
580
|
+
? `Neon rejected the key: ${probed.message}`
|
|
581
|
+
: `The key cannot list projects: ${probed.message}`,
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Who it is, best effort: an organization's name, or the key owner's.
|
|
586
|
+
let account: string | undefined;
|
|
587
|
+
if (orgId) {
|
|
588
|
+
const org = await neonGet<{ name?: string }>(`/organizations/${encodeURIComponent(orgId)}`, token, doFetch);
|
|
589
|
+
if (org.ok && typeof org.result?.name === 'string') account = org.result.name;
|
|
590
|
+
} else {
|
|
591
|
+
const me = await neonGet<{ name?: string; last_name?: string; login?: string }>('/users/me', token, doFetch);
|
|
592
|
+
if (me.ok) {
|
|
593
|
+
const full = [me.result?.name, me.result?.last_name].filter((part) => typeof part === 'string' && part).join(' ');
|
|
594
|
+
account = full || (typeof me.result?.login === 'string' ? me.result.login : undefined);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return { ok: true, ...(orgId ? { orgId } : {}), ...(account ? { account } : {}) };
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
interface NeonProject {
|
|
601
|
+
id: string;
|
|
602
|
+
name?: string;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
interface NeonContext {
|
|
606
|
+
get: <T>(path: string) => Promise<NeonResult<T>>;
|
|
607
|
+
/** `&org_id=…`, or nothing. */
|
|
608
|
+
org: string;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const neonConsole = (projectId: string) =>
|
|
612
|
+
`https://console.neon.tech/app/projects/${encodeURIComponent(projectId)}`;
|
|
613
|
+
|
|
614
|
+
/** Projects whose name or id is exactly `wanted`. The search itself is partial. */
|
|
615
|
+
async function neonProjectsNamed(wanted: string, ctx: NeonContext): Promise<NeonResult<NeonProject[]>> {
|
|
616
|
+
const listed = await ctx.get<{ projects?: NeonProject[] }>(
|
|
617
|
+
`/projects?limit=100&search=${encodeURIComponent(wanted)}${ctx.org}`,
|
|
618
|
+
);
|
|
619
|
+
if (!listed.ok) return listed;
|
|
620
|
+
if (!Array.isArray(listed.result?.projects)) {
|
|
621
|
+
return { ok: false, status: 200, message: 'unexpected answer for projects' };
|
|
622
|
+
}
|
|
623
|
+
return {
|
|
624
|
+
ok: true,
|
|
625
|
+
result: listed.result.projects.filter(
|
|
626
|
+
(p) => typeof p?.id === 'string' && (p.id === wanted || p.name === wanted),
|
|
627
|
+
),
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/** Whether the project's default branch holds a database of that name. */
|
|
632
|
+
async function neonHasDatabase(
|
|
633
|
+
projectId: string,
|
|
634
|
+
database: string,
|
|
635
|
+
ctx: NeonContext,
|
|
636
|
+
): Promise<{ found: boolean } | { reason: string }> {
|
|
637
|
+
const project = encodeURIComponent(projectId);
|
|
638
|
+
const branches = await ctx.get<{
|
|
639
|
+
branches?: Array<{ id?: string; default?: boolean; primary?: boolean }>;
|
|
640
|
+
}>(`/projects/${project}/branches`);
|
|
641
|
+
if (!branches.ok) return { reason: branches.message };
|
|
642
|
+
const list = Array.isArray(branches.result?.branches) ? branches.result.branches : [];
|
|
643
|
+
const branch = list.find((b) => b?.default === true) ?? list.find((b) => b?.primary === true);
|
|
644
|
+
if (typeof branch?.id !== 'string') return { reason: 'no default branch found' };
|
|
645
|
+
const databases = await ctx.get<{ databases?: Array<{ name?: string }> }>(
|
|
646
|
+
`/projects/${project}/branches/${encodeURIComponent(branch.id)}/databases`,
|
|
647
|
+
);
|
|
648
|
+
if (!databases.ok) return { reason: databases.message };
|
|
649
|
+
if (!Array.isArray(databases.result?.databases)) return { reason: 'unexpected answer for databases' };
|
|
650
|
+
return { found: databases.result.databases.some((d) => d?.name === database) };
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Neon lookups. A key names a project by its name or id; a database is named
|
|
655
|
+
* either as `project/database`, or by one name alone, which is taken as the
|
|
656
|
+
* project's name first (people call the whole project "the database") and
|
|
657
|
+
* then as a database inside whichever project holds it. Every call is a read.
|
|
658
|
+
*/
|
|
659
|
+
const NEON_CHECKS: Record<string, (identifier: string, ctx: NeonContext) => Promise<Seen>> = {
|
|
660
|
+
project: async (wanted, ctx) => {
|
|
661
|
+
const found = await neonProjectsNamed(wanted, ctx);
|
|
662
|
+
if (!found.ok) return { state: 'unknown', reason: found.message };
|
|
663
|
+
const project = found.result[0];
|
|
664
|
+
if (!project) return { state: 'not-found' };
|
|
665
|
+
return { state: 'deployed', resourceId: project.id, consoleUrl: neonConsole(project.id) };
|
|
666
|
+
},
|
|
667
|
+
|
|
668
|
+
database: async (wanted, ctx) => {
|
|
669
|
+
const slash = wanted.indexOf('/');
|
|
670
|
+
const projectName = slash > 0 ? wanted.slice(0, slash) : wanted;
|
|
671
|
+
const databaseName = slash > 0 ? wanted.slice(slash + 1) : '';
|
|
672
|
+
|
|
673
|
+
const named = await neonProjectsNamed(projectName, ctx);
|
|
674
|
+
if (!named.ok) return { state: 'unknown', reason: named.message };
|
|
675
|
+
const project = named.result[0];
|
|
676
|
+
if (databaseName) {
|
|
677
|
+
if (!project) return { state: 'not-found' };
|
|
678
|
+
const held = await neonHasDatabase(project.id, databaseName, ctx);
|
|
679
|
+
if ('reason' in held) return { state: 'unknown', reason: held.reason };
|
|
680
|
+
return held.found
|
|
681
|
+
? { state: 'deployed', resourceId: `${project.id}/${databaseName}`, consoleUrl: neonConsole(project.id) }
|
|
682
|
+
: { state: 'not-found' };
|
|
683
|
+
}
|
|
684
|
+
if (project) {
|
|
685
|
+
return { state: 'deployed', resourceId: project.id, consoleUrl: neonConsole(project.id) };
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// No project of that name: look for a database of that name instead.
|
|
689
|
+
const all = await ctx.get<{ projects?: NeonProject[] }>(
|
|
690
|
+
`/projects?limit=${NEON_PROJECTS_SEARCHED + 1}${ctx.org}`,
|
|
691
|
+
);
|
|
692
|
+
if (!all.ok) return { state: 'unknown', reason: all.message };
|
|
693
|
+
const projects = (Array.isArray(all.result?.projects) ? all.result.projects : []).filter(
|
|
694
|
+
(p) => typeof p?.id === 'string',
|
|
695
|
+
);
|
|
696
|
+
let unread: string | undefined;
|
|
697
|
+
for (const candidate of projects.slice(0, NEON_PROJECTS_SEARCHED)) {
|
|
698
|
+
const held = await neonHasDatabase(candidate.id, wanted, ctx);
|
|
699
|
+
if ('reason' in held) {
|
|
700
|
+
unread ??= held.reason;
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
if (held.found) {
|
|
704
|
+
return {
|
|
705
|
+
state: 'deployed',
|
|
706
|
+
resourceId: `${candidate.id}/${wanted}`,
|
|
707
|
+
consoleUrl: neonConsole(candidate.id),
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
// "Not there" is only said when everywhere it could be was read.
|
|
712
|
+
if (unread) return { state: 'unknown', reason: unread };
|
|
713
|
+
if (projects.length > NEON_PROJECTS_SEARCHED) {
|
|
714
|
+
return {
|
|
715
|
+
state: 'unknown',
|
|
716
|
+
reason: `no project is named ${wanted}, and there are too many to search; name it as project/database`,
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
return { state: 'not-found' };
|
|
720
|
+
},
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
/** Neon resource types a check can look at. */
|
|
724
|
+
export const NEON_OBSERVED_TYPES: readonly string[] = Object.keys(NEON_CHECKS);
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Look at the named Neon resources and say what was seen, with the same three
|
|
728
|
+
* outcomes as {@link observeCloudflare}. Keys for other providers are ignored.
|
|
729
|
+
*/
|
|
730
|
+
export async function observeNeon(
|
|
731
|
+
resourceKeys: readonly string[],
|
|
732
|
+
access: NeonAccess,
|
|
733
|
+
deps: InfraObserveDeps = {},
|
|
734
|
+
): Promise<InfraObserveResult> {
|
|
735
|
+
const doFetch = deps.fetch ?? fetch;
|
|
736
|
+
const ctx: NeonContext = {
|
|
737
|
+
get: (path) => neonGet(path, access.token, doFetch),
|
|
738
|
+
org: access.orgId ? `&org_id=${encodeURIComponent(access.orgId)}` : '',
|
|
739
|
+
};
|
|
740
|
+
return runChecks('neon', 'neon-api', resourceKeys, NEON_CHECKS, ctx, deps.now ?? (() => new Date()));
|
|
741
|
+
}
|