@theholocron/cli 5.0.0-alpha.28 → 5.0.0-alpha.281
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/README.md +361 -59
- package/dist/cli.mjs +16093 -6797
- package/dist/cli.mjs.map +1 -1
- package/dist/compose-BmbYc-ZW.mjs +252 -0
- package/dist/index-Bh7jWkxS.d.mts +747 -0
- package/dist/index-aQ7iGTl7.d.mts +2153 -0
- package/dist/index.d.mts +155 -575
- package/dist/index.mjs +187 -255
- package/dist/plugin/capabilities.d.mts +2 -807
- package/dist/plugin/capabilities.mjs +46 -3
- package/dist/presets.d.mts +211 -0
- package/dist/presets.mjs +401 -0
- package/package.json +25 -21
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { CARDINALITY, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, isMulti } from "./plugin/capabilities.mjs";
|
|
1
|
+
import { CARDINALITY, ElevationRequiredError, MissingTokenError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, isMulti } from "./plugin/capabilities.mjs";
|
|
2
|
+
import { a as resolvePluginPackage, i as resolveEntry, n as ConfigError, r as resolveConfig, t as compose } from "./compose-BmbYc-ZW.mjs";
|
|
2
3
|
import { AuthError, createResolveToken as createResolveToken$1, createRestClient } from "@theholocron/http-client";
|
|
3
|
-
import { createEnvLookup } from "@theholocron/env-utils";
|
|
4
|
+
import { createEnvLookup, withEnvPrefix } from "@theholocron/env-utils";
|
|
4
5
|
import { Entry, findCredentials } from "@napi-rs/keyring";
|
|
5
|
-
import { readFile } from "node:fs/promises";
|
|
6
6
|
import { basename, dirname, join } from "node:path";
|
|
7
|
-
import {
|
|
8
|
-
import { promisify } from "node:util";
|
|
7
|
+
import { readPackageJson } from "@theholocron/pkg-utils";
|
|
9
8
|
import { loadTasksConfig } from "@theholocron/astromech/config";
|
|
10
9
|
import { ConfigFileError, ConfigFileError as ConfigFileError$1, loadConfigFile } from "@theholocron/datapad";
|
|
11
|
-
|
|
10
|
+
import { readGitRemote } from "@theholocron/git-utils";
|
|
11
|
+
import { lookup } from "node:dns/promises";
|
|
12
|
+
// src/env/env.ts
|
|
13
|
+
/** Singleton env for simple global lookups throughout the CLI. */
|
|
14
|
+
const env = createEnvLookup();
|
|
15
|
+
withEnvPrefix(env, "HOLOCRON");
|
|
12
16
|
/**
|
|
13
17
|
* Create an injectable env for commands that accept a fake env in tests.
|
|
14
18
|
* Pass `input.env` when available, falls back to `process.env`.
|
|
@@ -16,8 +20,7 @@ createEnvLookup();
|
|
|
16
20
|
function makeEnv(source) {
|
|
17
21
|
return createEnvLookup(source);
|
|
18
22
|
}
|
|
19
|
-
|
|
20
|
-
//#region src/auth/keyring.ts
|
|
23
|
+
// src/auth/keyring/keyring.ts
|
|
21
24
|
/**
|
|
22
25
|
* Keyring-backed bootstrap credential store.
|
|
23
26
|
*
|
|
@@ -86,15 +89,18 @@ function listStoredProviders() {
|
|
|
86
89
|
return [];
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
|
-
|
|
90
|
-
//#region src/auth/auth-resolver.ts
|
|
92
|
+
// src/auth/auth-resolver/auth-resolver.ts
|
|
91
93
|
/** Wraps `createResolveToken` from `@theholocron/http` and injects the
|
|
92
94
|
* system keyring so plugins stay at a one-liner call site. */
|
|
93
95
|
function createResolveToken(config) {
|
|
94
|
-
return createResolveToken$1({
|
|
96
|
+
return Object.assign(createResolveToken$1({
|
|
95
97
|
...config,
|
|
96
98
|
getKeyringToken: getToken
|
|
97
|
-
})
|
|
99
|
+
}), { token: {
|
|
100
|
+
envName: config.envName,
|
|
101
|
+
vendorEnvName: config.vendorEnvName,
|
|
102
|
+
keyringKey: config.keyringService
|
|
103
|
+
} });
|
|
98
104
|
}
|
|
99
105
|
/**
|
|
100
106
|
* Build a strict, single-feature token resolver.
|
|
@@ -104,16 +110,19 @@ function createResolveToken(config) {
|
|
|
104
110
|
* operation fails with a message naming the exact env var to set.
|
|
105
111
|
*/
|
|
106
112
|
function createFeatureResolver(config) {
|
|
107
|
-
|
|
113
|
+
const resolveFeatureToken = (input = {}) => {
|
|
108
114
|
const env = makeEnv(input.env);
|
|
109
115
|
const keyring = input.keyring ?? getToken;
|
|
110
116
|
const token = input.cliToken || env.get(config.envName) || keyring(config.keyringKey);
|
|
111
|
-
if (!token) throw new AuthError(`no GitHub token found for this operation. Pass --token <
|
|
117
|
+
if (!token) throw new AuthError(`no ${config.vendor ?? "GitHub"} token found for this operation. Pass --token <token>, set ${config.envName}, or run: holocron auth set ${config.keyringKey} <token>`);
|
|
112
118
|
return token;
|
|
113
119
|
};
|
|
120
|
+
return Object.assign(resolveFeatureToken, { token: {
|
|
121
|
+
envName: config.envName,
|
|
122
|
+
keyringKey: config.keyringKey
|
|
123
|
+
} });
|
|
114
124
|
}
|
|
115
|
-
|
|
116
|
-
//#region src/commands/setup/derived-properties.ts
|
|
125
|
+
// src/commands/setup/derived-properties/derived-properties.ts
|
|
117
126
|
/**
|
|
118
127
|
* Repo archetype, in priority order:
|
|
119
128
|
* 1. `*-template` repo name → `template` (independent of package shape).
|
|
@@ -184,7 +193,7 @@ function deriveCapabilities(providers) {
|
|
|
184
193
|
return Object.keys(providers ?? {}).sort();
|
|
185
194
|
}
|
|
186
195
|
/**
|
|
187
|
-
* `source` + `ci` are the minimal baseline every repo `holocron setup`
|
|
196
|
+
* `source` + `ci` are the minimal baseline every repo `holocron repo setup`
|
|
188
197
|
* touches wires — every `holocron.config.ts` in this org already satisfies
|
|
189
198
|
* this, so `non-compliant` here means drift (a provider manually removed
|
|
190
199
|
* after setup), not an unmet aspirational policy. Deliberately not a richer
|
|
@@ -192,6 +201,7 @@ function deriveCapabilities(providers) {
|
|
|
192
201
|
* a Phase B (GitHub App) refinement once it can post *why* on a check run.
|
|
193
202
|
*/
|
|
194
203
|
const REQUIRED_BASELINE = ["source", "ci"];
|
|
204
|
+
/** Whether a repo's capabilities include the required baseline (`source` and `ci`); `non-compliant` means drift. */
|
|
195
205
|
function deriveCompliance(capabilities) {
|
|
196
206
|
return REQUIRED_BASELINE.every((key) => capabilities.includes(key)) ? "compliant" : "non-compliant";
|
|
197
207
|
}
|
|
@@ -213,215 +223,18 @@ function missingCapabilities(capabilities) {
|
|
|
213
223
|
*/
|
|
214
224
|
async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
|
|
215
225
|
const results = [];
|
|
216
|
-
for (const { slug, dir = "packages" } of workspacePackages)
|
|
217
|
-
const
|
|
218
|
-
results.push(
|
|
219
|
-
} catch {}
|
|
220
|
-
return results;
|
|
221
|
-
}
|
|
222
|
-
//#endregion
|
|
223
|
-
//#region src/config/config.ts
|
|
224
|
-
var ConfigError = class extends Error {
|
|
225
|
-
name = "ConfigError";
|
|
226
|
-
};
|
|
227
|
-
const PLUGIN_PREFIX = "@theholocron/holocron-plugin-";
|
|
228
|
-
const COMMUNITY_PREFIX = "holocron-plugin-";
|
|
229
|
-
/**
|
|
230
|
-
* Resolve `"github"` → `"@theholocron/holocron-plugin-github"`.
|
|
231
|
-
* Fully-qualified names (scoped or not) are honored verbatim, which
|
|
232
|
-
* is how third-party plugins published outside the org work.
|
|
233
|
-
*/
|
|
234
|
-
function resolvePluginPackage(provider) {
|
|
235
|
-
if (!provider) throw new ConfigError("provider name is empty");
|
|
236
|
-
if (provider.startsWith("@")) return provider;
|
|
237
|
-
if (provider.startsWith(COMMUNITY_PREFIX)) return provider;
|
|
238
|
-
if (provider.includes("/")) return provider;
|
|
239
|
-
return PLUGIN_PREFIX + provider;
|
|
240
|
-
}
|
|
241
|
-
/** A bare `[provider, options]` tuple, with both elements present? */
|
|
242
|
-
function isOptionsTuple(value) {
|
|
243
|
-
if (!Array.isArray(value)) return false;
|
|
244
|
-
if (value.length !== 2) return false;
|
|
245
|
-
if (typeof value[0] !== "string") return false;
|
|
246
|
-
const opt = value[1];
|
|
247
|
-
return typeof opt === "object" && opt !== null && !Array.isArray(opt);
|
|
248
|
-
}
|
|
249
|
-
function normalizeEntry(entry) {
|
|
250
|
-
if (typeof entry === "string") return {
|
|
251
|
-
provider: entry,
|
|
252
|
-
packageName: resolvePluginPackage(entry),
|
|
253
|
-
options: {}
|
|
254
|
-
};
|
|
255
|
-
const [provider, options] = entry;
|
|
256
|
-
return {
|
|
257
|
-
provider,
|
|
258
|
-
packageName: resolvePluginPackage(provider),
|
|
259
|
-
options
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
function resolveEntry(key, raw) {
|
|
263
|
-
const cardinality = CARDINALITY[key];
|
|
264
|
-
if (typeof raw === "string") {
|
|
265
|
-
if (cardinality === "many") throw new ConfigError(`\`${key}\` accepts multiple providers; wrap a single one in an array: ["${raw}"]`);
|
|
266
|
-
return {
|
|
267
|
-
cardinality: "single",
|
|
268
|
-
tuple: normalizeEntry(raw)
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
if (!Array.isArray(raw)) throw new ConfigError(`\`${key}\` entry must be a string or array, got ${typeof raw}`);
|
|
272
|
-
if (isOptionsTuple(raw)) {
|
|
273
|
-
if (cardinality === "many") return {
|
|
274
|
-
cardinality: "many",
|
|
275
|
-
tuples: [normalizeEntry(raw)]
|
|
276
|
-
};
|
|
277
|
-
return {
|
|
278
|
-
cardinality: "single",
|
|
279
|
-
tuple: normalizeEntry(raw)
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
if (cardinality === "single") throw new ConfigError(`\`${key}\` accepts exactly one provider; got a multi-provider list with ${raw.length} entries`);
|
|
283
|
-
return {
|
|
284
|
-
cardinality: "many",
|
|
285
|
-
tuples: raw.map((entry, idx) => {
|
|
286
|
-
if (typeof entry === "string") return normalizeEntry(entry);
|
|
287
|
-
if (isOptionsTuple(entry)) return normalizeEntry(entry);
|
|
288
|
-
throw new ConfigError(`\`${key}[${idx}]\` must be a provider string or [provider, options] tuple`);
|
|
289
|
-
})
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
function resolveConfig(raw) {
|
|
293
|
-
if (!raw.name) throw new ConfigError("`name` is required");
|
|
294
|
-
if (!raw.providers || typeof raw.providers !== "object") throw new ConfigError("`providers` block is required");
|
|
295
|
-
const providers = {};
|
|
296
|
-
for (const [key, entry] of Object.entries(raw.providers)) {
|
|
297
|
-
if (entry === void 0) continue;
|
|
298
|
-
providers[key] = resolveEntry(key, entry);
|
|
299
|
-
}
|
|
300
|
-
for (const required of REQUIRED_CAPABILITIES) if (!providers[required]) throw new ConfigError(`required capability \`${required}\` is missing from providers`);
|
|
301
|
-
let docs;
|
|
302
|
-
if (raw.docs !== void 0) {
|
|
303
|
-
if (!raw.docs.build) throw new ConfigError("`docs.build` is required when `docs` is set");
|
|
304
|
-
docs = raw.docs;
|
|
305
|
-
}
|
|
306
|
-
const homepage = raw.homepage ?? (docs?.domain ? `https://${docs.domain}/` : void 0);
|
|
307
|
-
return {
|
|
308
|
-
name: raw.name,
|
|
309
|
-
description: raw.description,
|
|
310
|
-
homepage,
|
|
311
|
-
org: raw.org,
|
|
312
|
-
domain: raw.domain,
|
|
313
|
-
repo: raw.repo,
|
|
314
|
-
tasks: raw.tasks,
|
|
315
|
-
syncScripts: raw.syncScripts,
|
|
316
|
-
holocronScript: raw.holocronScript,
|
|
317
|
-
extraRequiredChecks: raw.extraRequiredChecks,
|
|
318
|
-
hooks: raw.hooks,
|
|
319
|
-
providers,
|
|
320
|
-
apps: raw.apps ?? [],
|
|
321
|
-
doctor: raw.doctor ?? {},
|
|
322
|
-
agent: raw.agent,
|
|
323
|
-
skills: raw.skills,
|
|
324
|
-
docs,
|
|
325
|
-
env: raw.env,
|
|
326
|
-
log: raw.log,
|
|
327
|
-
telemetry: raw.telemetry
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
//#endregion
|
|
331
|
-
//#region src/config/compose.ts
|
|
332
|
-
function taskName(e) {
|
|
333
|
-
return typeof e === "string" ? e : e.name;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Merge any number of capability fragments into a single preset object that
|
|
337
|
-
* spreads directly into `defineConfig()`.
|
|
338
|
-
*
|
|
339
|
-
* - Accepts individual capabilities or nested arrays (for bundle presets).
|
|
340
|
-
* - Deduplicates by `id` — when the same ID appears more than once, the last
|
|
341
|
-
* occurrence wins. This lets callers override bundle defaults by listing an
|
|
342
|
-
* explicit capability after the bundle.
|
|
343
|
-
* - Validates all `requires` at call time and throws `ConfigError` if any are
|
|
344
|
-
* unmet, listing every missing dependency in a single message.
|
|
345
|
-
*
|
|
346
|
-
* @example
|
|
347
|
-
* // docs-only site — no typecheck
|
|
348
|
-
* const preset = compose(node(), docs());
|
|
349
|
-
*
|
|
350
|
-
* // library with docs
|
|
351
|
-
* const preset = compose(node(), typecheck(), docs());
|
|
352
|
-
*
|
|
353
|
-
* // nextjs() is a bundle that returns Capability[]
|
|
354
|
-
* const preset = compose(node(), nextjs());
|
|
355
|
-
*/
|
|
356
|
-
function compose(...args) {
|
|
357
|
-
const flat = args.flat();
|
|
358
|
-
const byId = /* @__PURE__ */ new Map();
|
|
359
|
-
for (const cap of flat) byId.set(cap.id, cap);
|
|
360
|
-
const caps = [...byId.values()];
|
|
361
|
-
const available = new Set(caps.map((c) => c.id));
|
|
362
|
-
const errors = [];
|
|
363
|
-
for (const cap of caps) for (const req of cap.requires ?? []) if (!available.has(req)) errors.push(`"${cap.id}" requires "${req}"`);
|
|
364
|
-
if (errors.length > 0) throw new ConfigError(`compose(): unmet dependencies — ${errors.join(", ")}`);
|
|
365
|
-
const taskMap = /* @__PURE__ */ new Map();
|
|
366
|
-
for (const cap of caps) for (const entry of cap.tasks ?? []) taskMap.set(taskName(entry), entry);
|
|
367
|
-
let providers = {};
|
|
368
|
-
for (const cap of caps) if (cap.providers) providers = {
|
|
369
|
-
...providers,
|
|
370
|
-
...cap.providers
|
|
371
|
-
};
|
|
372
|
-
const checksSeen = /* @__PURE__ */ new Set();
|
|
373
|
-
const extraRequiredChecks = [];
|
|
374
|
-
for (const cap of caps) for (const check of cap.extraRequiredChecks ?? []) if (!checksSeen.has(check)) {
|
|
375
|
-
checksSeen.add(check);
|
|
376
|
-
extraRequiredChecks.push(check);
|
|
226
|
+
for (const { slug, dir = "packages", path } of workspacePackages) {
|
|
227
|
+
const pkg = await readPackageJson(join(repoRoot, path ?? join(dir, slug)));
|
|
228
|
+
if (pkg) results.push(pkg);
|
|
377
229
|
}
|
|
378
|
-
|
|
379
|
-
for (const cap of caps) {
|
|
380
|
-
if (!cap.repo) continue;
|
|
381
|
-
const { properties, topics, teams, ...scalars } = cap.repo;
|
|
382
|
-
repo = {
|
|
383
|
-
...repo,
|
|
384
|
-
...scalars
|
|
385
|
-
};
|
|
386
|
-
if (properties) repo.properties = {
|
|
387
|
-
...repo.properties,
|
|
388
|
-
...properties
|
|
389
|
-
};
|
|
390
|
-
if (topics) {
|
|
391
|
-
const merged = /* @__PURE__ */ new Set([...repo.topics ?? [], ...topics]);
|
|
392
|
-
repo.topics = [...merged];
|
|
393
|
-
}
|
|
394
|
-
if (teams) {
|
|
395
|
-
const teamMap = new Map((repo.teams ?? []).map((t) => [typeof t === "string" ? t : t.slug, t]));
|
|
396
|
-
for (const t of teams) teamMap.set(typeof t === "string" ? t : t.slug, t);
|
|
397
|
-
repo.teams = [...teamMap.values()];
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
let org;
|
|
401
|
-
let domain;
|
|
402
|
-
let docs;
|
|
403
|
-
for (const cap of caps) {
|
|
404
|
-
if (cap.org !== void 0) org = cap.org;
|
|
405
|
-
if (cap.domain !== void 0) domain = cap.domain;
|
|
406
|
-
if (cap.docs !== void 0) docs = cap.docs;
|
|
407
|
-
}
|
|
408
|
-
return {
|
|
409
|
-
tasks: [...taskMap.values()],
|
|
410
|
-
providers,
|
|
411
|
-
repo,
|
|
412
|
-
extraRequiredChecks,
|
|
413
|
-
...org !== void 0 ? { org } : {},
|
|
414
|
-
...domain !== void 0 ? { domain } : {},
|
|
415
|
-
...docs !== void 0 ? { docs } : {}
|
|
416
|
-
};
|
|
230
|
+
return results;
|
|
417
231
|
}
|
|
418
|
-
|
|
419
|
-
|
|
232
|
+
// src/config/define-config/define-config.ts
|
|
233
|
+
/** Returns the config unchanged; it exists to type and autocomplete a `holocron.config.ts`. */
|
|
420
234
|
function defineConfig(config) {
|
|
421
235
|
return config;
|
|
422
236
|
}
|
|
423
|
-
|
|
424
|
-
//#region src/config/load-config.ts
|
|
237
|
+
// src/config/load-config/load-config.ts
|
|
425
238
|
/**
|
|
426
239
|
* `holocron.config.{ts,js,mjs,cjs,json}` loader.
|
|
427
240
|
*
|
|
@@ -433,34 +246,40 @@ function defineConfig(config) {
|
|
|
433
246
|
* Probe order is TS-first (`.ts` → `.js` → `.mjs` → `.cjs` → `.json`) —
|
|
434
247
|
* see ADR-0010 / issue #75 / #81.
|
|
435
248
|
*/
|
|
436
|
-
const execFileAsync = promisify(execFile);
|
|
437
249
|
/**
|
|
438
|
-
* Read + parse + resolve `holocron.config.*` from the given
|
|
250
|
+
* Read + parse + resolve `holocron.config.*` starting from the given
|
|
251
|
+
* directory, walking up through ancestors to the nearest `.git` boundary
|
|
252
|
+
* when `cwd` itself has no match — every command is usable from any
|
|
253
|
+
* subdirectory of a repo, not only its exact root (see
|
|
254
|
+
* `@theholocron/datapad`'s own doc comment for the stop conditions).
|
|
439
255
|
* Throws {@link ConfigFileError} when nothing is found or a file cannot
|
|
440
|
-
* be loaded, or `ConfigError` when the config
|
|
256
|
+
* be loaded, or `ConfigError` when the config fails schema checks.
|
|
441
257
|
*/
|
|
442
258
|
async function loadConfig(cwd) {
|
|
443
259
|
const found = await loadConfigFile({
|
|
444
260
|
cwd,
|
|
445
|
-
name: "holocron"
|
|
261
|
+
name: "holocron",
|
|
262
|
+
walkUp: true
|
|
446
263
|
});
|
|
447
264
|
if (!found) throw new ConfigFileError$1(`no holocron.config.{ts,js,mjs,cjs,json} found in ${cwd}. Create one — see the README for the schema.`);
|
|
265
|
+
const withDefaults = await deriveDefaults(found);
|
|
448
266
|
return {
|
|
449
|
-
resolved: resolveConfig(
|
|
267
|
+
resolved: resolveConfig(withDefaults),
|
|
450
268
|
filepath: found.filepath
|
|
451
269
|
};
|
|
452
270
|
}
|
|
453
|
-
async function deriveDefaults(
|
|
454
|
-
const
|
|
271
|
+
async function deriveDefaults(found) {
|
|
272
|
+
const configDir = dirname(found.filepath);
|
|
273
|
+
const result = { ...found.config };
|
|
455
274
|
if (!result.name) result.name = await readPackageJsonName(configDir) ?? basename(configDir);
|
|
456
275
|
if (result.repo && !result.repo.name) {
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
276
|
+
const remote = await readGitRemote(configDir);
|
|
277
|
+
if (remote?.host === "github.com") result.repo = {
|
|
459
278
|
...result.repo,
|
|
460
|
-
name:
|
|
279
|
+
name: remote.slug
|
|
461
280
|
};
|
|
462
281
|
}
|
|
463
|
-
const manifest = await loadTasksConfig(configDir);
|
|
282
|
+
const manifest = await loadTasksConfig(configDir, { holocron: found });
|
|
464
283
|
if (manifest.tasks) result.tasks = manifest.tasks;
|
|
465
284
|
if (manifest.syncScripts !== void 0) result.syncScripts = manifest.syncScripts;
|
|
466
285
|
if (manifest.holocronScript !== void 0) result.holocronScript = manifest.holocronScript;
|
|
@@ -469,31 +288,144 @@ async function deriveDefaults(configDir, raw) {
|
|
|
469
288
|
return result;
|
|
470
289
|
}
|
|
471
290
|
async function readPackageJsonName(dir) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
291
|
+
const name = (await readPackageJson(dir))?.name;
|
|
292
|
+
return name === void 0 ? void 0 : name.replace(/^@[^/]+\//, "");
|
|
293
|
+
}
|
|
294
|
+
// src/plugin/connection-probe/connection-probe.ts
|
|
295
|
+
const TLS_CODES = /* @__PURE__ */ new Set([
|
|
296
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
297
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
298
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
299
|
+
"CERT_HAS_EXPIRED",
|
|
300
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
301
|
+
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
302
|
+
]);
|
|
303
|
+
/** The code Node attaches to a network failure, with that error's message: on the error itself, or on its `cause` (where `fetch` puts it). */
|
|
304
|
+
function codeOf(err) {
|
|
305
|
+
for (let e = err, depth = 0; e && depth < 4; depth++) {
|
|
306
|
+
if (typeof e.code === "string") return {
|
|
307
|
+
code: e.code,
|
|
308
|
+
message: String(e.message ?? "")
|
|
309
|
+
};
|
|
310
|
+
e = e.cause;
|
|
478
311
|
}
|
|
479
312
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
return;
|
|
313
|
+
/** A network failure in plain words, with what usually causes it. Never includes anything from a request. */
|
|
314
|
+
function describeNetworkError(err, timeoutMs) {
|
|
315
|
+
const found = codeOf(err);
|
|
316
|
+
const code = found?.code;
|
|
317
|
+
const name = err?.name;
|
|
318
|
+
if (name === "TimeoutError" || name === "AbortError" || code === "UND_ERR_CONNECT_TIMEOUT" || code === "ETIMEDOUT") return `no answer within ${timeoutMs / 1e3}s (${code ?? name}): a firewall, VPN or proxy may be dropping it`;
|
|
319
|
+
switch (code) {
|
|
320
|
+
case "ENOTFOUND":
|
|
321
|
+
case "EAI_AGAIN": return `${code}: the name did not resolve; check your network and DNS`;
|
|
322
|
+
case "ECONNREFUSED": return "ECONNREFUSED: the host refused the connection";
|
|
323
|
+
case "ECONNRESET":
|
|
324
|
+
case "UND_ERR_SOCKET": return `${code}: the connection was cut off; a proxy or firewall may be interfering`;
|
|
325
|
+
case "ENETUNREACH":
|
|
326
|
+
case "EHOSTUNREACH": return `${code}: no route to the host; check that you are online`;
|
|
327
|
+
default:
|
|
328
|
+
if (code && TLS_CODES.has(code)) return `${code}: the TLS certificate was not trusted; a corporate proxy that re-signs traffic needs NODE_EXTRA_CA_CERTS`;
|
|
329
|
+
return found ? `${found.code}: ${found.message}` : String(err?.message ?? err);
|
|
490
330
|
}
|
|
491
331
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
332
|
+
/**
|
|
333
|
+
* The `connection` probe every provider offers, for telling a network problem from a credential problem: does the name
|
|
334
|
+
* resolve, does the host answer, is there a token, and does the provider accept it. A step that cannot work because an
|
|
335
|
+
* earlier one failed is reported as not tried rather than failing a second time for the same reason.
|
|
336
|
+
*/
|
|
337
|
+
function connectionProbe(input) {
|
|
338
|
+
const timeoutMs = input.timeoutMs ?? 1e4;
|
|
339
|
+
return {
|
|
340
|
+
summary: `Check the network path to ${input.provider} and that it accepts your token.`,
|
|
341
|
+
writes: false,
|
|
342
|
+
async run(probe) {
|
|
343
|
+
let reachable = true;
|
|
344
|
+
if (input.url) {
|
|
345
|
+
const host = new URL(input.url).hostname;
|
|
346
|
+
const lookup$1 = input.lookup ?? (input.fetch ? void 0 : (h) => lookup(h));
|
|
347
|
+
if (lookup$1) try {
|
|
348
|
+
const { address } = await lookup$1(host);
|
|
349
|
+
probe.say({
|
|
350
|
+
status: "ok",
|
|
351
|
+
label: `DNS ${host}`,
|
|
352
|
+
detail: address
|
|
353
|
+
});
|
|
354
|
+
} catch (err) {
|
|
355
|
+
reachable = false;
|
|
356
|
+
probe.say({
|
|
357
|
+
status: "fail",
|
|
358
|
+
label: `DNS ${host}`,
|
|
359
|
+
detail: describeNetworkError(err, timeoutMs)
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
if (reachable) {
|
|
363
|
+
const started = Date.now();
|
|
364
|
+
try {
|
|
365
|
+
const res = await (input.fetch ?? fetch)(input.url, {
|
|
366
|
+
method: "GET",
|
|
367
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
368
|
+
});
|
|
369
|
+
probe.say({
|
|
370
|
+
status: "ok",
|
|
371
|
+
label: `reach ${host}`,
|
|
372
|
+
detail: `HTTP ${res.status} in ${Date.now() - started} ms`
|
|
373
|
+
});
|
|
374
|
+
} catch (err) {
|
|
375
|
+
reachable = false;
|
|
376
|
+
probe.say({
|
|
377
|
+
status: "fail",
|
|
378
|
+
label: `reach ${host}`,
|
|
379
|
+
detail: describeNetworkError(err, timeoutMs)
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
} else probe.say({
|
|
383
|
+
status: "info",
|
|
384
|
+
label: `reach ${host}`,
|
|
385
|
+
detail: "not tried: the name did not resolve"
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
let token;
|
|
389
|
+
try {
|
|
390
|
+
token = await input.token();
|
|
391
|
+
} catch (err) {
|
|
392
|
+
probe.say({
|
|
393
|
+
status: "fail",
|
|
394
|
+
label: "token",
|
|
395
|
+
detail: err.message
|
|
396
|
+
});
|
|
397
|
+
probe.say({
|
|
398
|
+
status: "info",
|
|
399
|
+
label: "accepted",
|
|
400
|
+
detail: "not tried: there is no token"
|
|
401
|
+
});
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
probe.secret(token);
|
|
405
|
+
probe.say({
|
|
406
|
+
status: "ok",
|
|
407
|
+
label: "token",
|
|
408
|
+
detail: "found"
|
|
409
|
+
});
|
|
410
|
+
if (!reachable) {
|
|
411
|
+
probe.say({
|
|
412
|
+
status: "info",
|
|
413
|
+
label: "accepted",
|
|
414
|
+
detail: "not tried: the host could not be reached"
|
|
415
|
+
});
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const result = await input.verify(token);
|
|
419
|
+
probe.say(result.ok ? {
|
|
420
|
+
status: "ok",
|
|
421
|
+
label: "accepted",
|
|
422
|
+
detail: result.subject
|
|
423
|
+
} : {
|
|
424
|
+
status: "fail",
|
|
425
|
+
label: "accepted",
|
|
426
|
+
detail: result.message
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
};
|
|
497
430
|
}
|
|
498
|
-
|
|
499
|
-
export { AuthError, CARDINALITY, ConfigError, ConfigFileError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, compose, createFeatureResolver, createResolveToken, createRestClient, defineConfig, deleteToken, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, getToken, isMulti, listStoredProviders, loadConfig, missingCapabilities, readWorkspacePackageJsons, resolveConfig, resolveEntry, resolvePluginPackage, setToken };
|
|
431
|
+
export { AuthError, CARDINALITY, ConfigError, ConfigFileError, ElevationRequiredError, MissingTokenError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, compose, connectionProbe, createFeatureResolver, createResolveToken, createRestClient, defineConfig, deleteToken, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, describeNetworkError, getToken, isMulti, listStoredProviders, loadConfig, missingCapabilities, readWorkspacePackageJsons, resolveConfig, resolveEntry, resolvePluginPackage, setToken };
|