@coffre/client 0.4.0 → 0.4.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/{index-CsGTyqgO.d.ts → index-ZGDlpCwB.d.ts} +94 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +56 -2
- package/dist/routes.d.ts +1 -1
- package/package.json +1 -1
- package/src/api.ts +45 -8
- package/src/index.ts +13 -2
- package/src/reach.ts +62 -0
|
@@ -14,7 +14,7 @@ type Api = {
|
|
|
14
14
|
isRootAdmin: boolean;
|
|
15
15
|
canReadAudit: boolean;
|
|
16
16
|
features: {
|
|
17
|
-
mcp:
|
|
17
|
+
mcp: string | null;
|
|
18
18
|
workloads: boolean;
|
|
19
19
|
};
|
|
20
20
|
environments: {
|
|
@@ -421,6 +421,7 @@ type Api = {
|
|
|
421
421
|
sessions: number;
|
|
422
422
|
tokens: number;
|
|
423
423
|
identities: number;
|
|
424
|
+
apps: number;
|
|
424
425
|
};
|
|
425
426
|
exposed: {
|
|
426
427
|
project: string;
|
|
@@ -439,6 +440,17 @@ type Api = {
|
|
|
439
440
|
expiresAt: string;
|
|
440
441
|
lastUsedAt: string | null;
|
|
441
442
|
}[];
|
|
443
|
+
apps: {
|
|
444
|
+
id: string;
|
|
445
|
+
name: string;
|
|
446
|
+
host: string | null;
|
|
447
|
+
registration: "cimd" | "dcr";
|
|
448
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
449
|
+
createdAt: string;
|
|
450
|
+
lastUsedAt: string | null;
|
|
451
|
+
lastUsedIp: string | null;
|
|
452
|
+
expiresAt: string;
|
|
453
|
+
}[];
|
|
442
454
|
references: {
|
|
443
455
|
id: string;
|
|
444
456
|
holder: string;
|
|
@@ -470,6 +482,7 @@ type Api = {
|
|
|
470
482
|
sessions: number;
|
|
471
483
|
tokens: number;
|
|
472
484
|
identities: number;
|
|
485
|
+
apps: number;
|
|
473
486
|
};
|
|
474
487
|
report: {
|
|
475
488
|
principalType: "service" | "user";
|
|
@@ -484,6 +497,7 @@ type Api = {
|
|
|
484
497
|
sessions: number;
|
|
485
498
|
tokens: number;
|
|
486
499
|
identities: number;
|
|
500
|
+
apps: number;
|
|
487
501
|
};
|
|
488
502
|
exposed: {
|
|
489
503
|
project: string;
|
|
@@ -502,6 +516,17 @@ type Api = {
|
|
|
502
516
|
expiresAt: string;
|
|
503
517
|
lastUsedAt: string | null;
|
|
504
518
|
}[];
|
|
519
|
+
apps: {
|
|
520
|
+
id: string;
|
|
521
|
+
name: string;
|
|
522
|
+
host: string | null;
|
|
523
|
+
registration: "cimd" | "dcr";
|
|
524
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
525
|
+
createdAt: string;
|
|
526
|
+
lastUsedAt: string | null;
|
|
527
|
+
lastUsedIp: string | null;
|
|
528
|
+
expiresAt: string;
|
|
529
|
+
}[];
|
|
505
530
|
references: {
|
|
506
531
|
id: string;
|
|
507
532
|
holder: string;
|
|
@@ -729,8 +754,8 @@ type Api = {
|
|
|
729
754
|
};
|
|
730
755
|
redirectHost: string;
|
|
731
756
|
loopbackOnly: boolean;
|
|
732
|
-
scopes: ("
|
|
733
|
-
connections: ("
|
|
757
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
758
|
+
connections: ("manage-access" | "read" | "reveal" | "write")[][];
|
|
734
759
|
days: number;
|
|
735
760
|
};
|
|
736
761
|
};
|
|
@@ -761,7 +786,7 @@ type Api = {
|
|
|
761
786
|
name: string;
|
|
762
787
|
host: string | null;
|
|
763
788
|
registration: "cimd" | "dcr";
|
|
764
|
-
scopes: ("
|
|
789
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
765
790
|
createdAt: string;
|
|
766
791
|
lastUsedAt: string | null;
|
|
767
792
|
lastUsedIp: string | null;
|
|
@@ -1016,8 +1041,8 @@ type AuthorizationView = {
|
|
|
1016
1041
|
};
|
|
1017
1042
|
redirectHost: string;
|
|
1018
1043
|
loopbackOnly: boolean;
|
|
1019
|
-
scopes: ("
|
|
1020
|
-
connections: ("
|
|
1044
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
1045
|
+
connections: ("manage-access" | "read" | "reveal" | "write")[][];
|
|
1021
1046
|
days: number;
|
|
1022
1047
|
};
|
|
1023
1048
|
type BindingPlan = {
|
|
@@ -1050,7 +1075,7 @@ type ConnectedApp = {
|
|
|
1050
1075
|
name: string;
|
|
1051
1076
|
host: string | null;
|
|
1052
1077
|
registration: "cimd" | "dcr";
|
|
1053
|
-
scopes: ("
|
|
1078
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
1054
1079
|
createdAt: string;
|
|
1055
1080
|
lastUsedAt: string | null;
|
|
1056
1081
|
lastUsedIp: string | null;
|
|
@@ -1156,7 +1181,7 @@ type Me = {
|
|
|
1156
1181
|
isRootAdmin: boolean;
|
|
1157
1182
|
canReadAudit: boolean;
|
|
1158
1183
|
features: {
|
|
1159
|
-
mcp:
|
|
1184
|
+
mcp: string | null;
|
|
1160
1185
|
workloads: boolean;
|
|
1161
1186
|
};
|
|
1162
1187
|
environments: {
|
|
@@ -1200,6 +1225,7 @@ type OffboardingReport = {
|
|
|
1200
1225
|
sessions: number;
|
|
1201
1226
|
tokens: number;
|
|
1202
1227
|
identities: number;
|
|
1228
|
+
apps: number;
|
|
1203
1229
|
};
|
|
1204
1230
|
exposed: {
|
|
1205
1231
|
project: string;
|
|
@@ -1218,6 +1244,17 @@ type OffboardingReport = {
|
|
|
1218
1244
|
expiresAt: string;
|
|
1219
1245
|
lastUsedAt: string | null;
|
|
1220
1246
|
}[];
|
|
1247
|
+
apps: {
|
|
1248
|
+
id: string;
|
|
1249
|
+
name: string;
|
|
1250
|
+
host: string | null;
|
|
1251
|
+
registration: "cimd" | "dcr";
|
|
1252
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
1253
|
+
createdAt: string;
|
|
1254
|
+
lastUsedAt: string | null;
|
|
1255
|
+
lastUsedIp: string | null;
|
|
1256
|
+
expiresAt: string;
|
|
1257
|
+
}[];
|
|
1221
1258
|
references: {
|
|
1222
1259
|
id: string;
|
|
1223
1260
|
holder: string;
|
|
@@ -1369,6 +1406,25 @@ declare function apiMember(member: string): string;
|
|
|
1369
1406
|
/** A service account's name alone, from any of its forms: `deploy`, `service:deploy` or `token:deploy`. */
|
|
1370
1407
|
declare function serviceName(member: string): string;
|
|
1371
1408
|
//#endregion
|
|
1409
|
+
//#region src/reach.d.ts
|
|
1410
|
+
/**
|
|
1411
|
+
* Why an instance could not be reached, from what `fetch` threw. Node's
|
|
1412
|
+
* `fetch` says only `fetch failed`: what happened is in its `cause`, Node's
|
|
1413
|
+
* own error, with a code (`ENOTFOUND`, `ECONNREFUSED`, a certificate's) and
|
|
1414
|
+
* often the address it tried. A browser's says nothing more, and has no cause.
|
|
1415
|
+
*/
|
|
1416
|
+
/**
|
|
1417
|
+
* `could not reach <origin>: <why>`, and what to try when the cause is a
|
|
1418
|
+
* common one: `could not reach https://x: getaddrinfo ENOTFOUND x; the name
|
|
1419
|
+
* does not resolve here: …`.
|
|
1420
|
+
*/
|
|
1421
|
+
declare function unreachable(origin: string, error: unknown): string;
|
|
1422
|
+
/** A request that never reached the instance: its message says why, `cause` is what `fetch` threw. */
|
|
1423
|
+
declare class Unreachable extends Error {
|
|
1424
|
+
readonly origin: string;
|
|
1425
|
+
constructor(origin: string, error: unknown);
|
|
1426
|
+
}
|
|
1427
|
+
//#endregion
|
|
1372
1428
|
//#region src/index.d.ts
|
|
1373
1429
|
type RouteKey = keyof Api;
|
|
1374
1430
|
/** What a caller sends: the body, or the query string for a GET. */
|
|
@@ -1411,7 +1467,7 @@ declare function createClient(options: ClientOptions): {
|
|
|
1411
1467
|
isRootAdmin: boolean;
|
|
1412
1468
|
canReadAudit: boolean;
|
|
1413
1469
|
features: {
|
|
1414
|
-
mcp:
|
|
1470
|
+
mcp: string | null;
|
|
1415
1471
|
workloads: boolean;
|
|
1416
1472
|
};
|
|
1417
1473
|
environments: {
|
|
@@ -1721,6 +1777,7 @@ declare function createClient(options: ClientOptions): {
|
|
|
1721
1777
|
sessions: number;
|
|
1722
1778
|
tokens: number;
|
|
1723
1779
|
identities: number;
|
|
1780
|
+
apps: number;
|
|
1724
1781
|
};
|
|
1725
1782
|
exposed: {
|
|
1726
1783
|
project: string;
|
|
@@ -1739,6 +1796,17 @@ declare function createClient(options: ClientOptions): {
|
|
|
1739
1796
|
expiresAt: string;
|
|
1740
1797
|
lastUsedAt: string | null;
|
|
1741
1798
|
}[];
|
|
1799
|
+
apps: {
|
|
1800
|
+
id: string;
|
|
1801
|
+
name: string;
|
|
1802
|
+
host: string | null;
|
|
1803
|
+
registration: "cimd" | "dcr";
|
|
1804
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
1805
|
+
createdAt: string;
|
|
1806
|
+
lastUsedAt: string | null;
|
|
1807
|
+
lastUsedIp: string | null;
|
|
1808
|
+
expiresAt: string;
|
|
1809
|
+
}[];
|
|
1742
1810
|
references: {
|
|
1743
1811
|
id: string;
|
|
1744
1812
|
holder: string;
|
|
@@ -1763,6 +1831,7 @@ declare function createClient(options: ClientOptions): {
|
|
|
1763
1831
|
sessions: number;
|
|
1764
1832
|
tokens: number;
|
|
1765
1833
|
identities: number;
|
|
1834
|
+
apps: number;
|
|
1766
1835
|
};
|
|
1767
1836
|
report: {
|
|
1768
1837
|
principalType: "service" | "user";
|
|
@@ -1777,6 +1846,7 @@ declare function createClient(options: ClientOptions): {
|
|
|
1777
1846
|
sessions: number;
|
|
1778
1847
|
tokens: number;
|
|
1779
1848
|
identities: number;
|
|
1849
|
+
apps: number;
|
|
1780
1850
|
};
|
|
1781
1851
|
exposed: {
|
|
1782
1852
|
project: string;
|
|
@@ -1795,6 +1865,17 @@ declare function createClient(options: ClientOptions): {
|
|
|
1795
1865
|
expiresAt: string;
|
|
1796
1866
|
lastUsedAt: string | null;
|
|
1797
1867
|
}[];
|
|
1868
|
+
apps: {
|
|
1869
|
+
id: string;
|
|
1870
|
+
name: string;
|
|
1871
|
+
host: string | null;
|
|
1872
|
+
registration: "cimd" | "dcr";
|
|
1873
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
1874
|
+
createdAt: string;
|
|
1875
|
+
lastUsedAt: string | null;
|
|
1876
|
+
lastUsedIp: string | null;
|
|
1877
|
+
expiresAt: string;
|
|
1878
|
+
}[];
|
|
1798
1879
|
references: {
|
|
1799
1880
|
id: string;
|
|
1800
1881
|
holder: string;
|
|
@@ -1979,8 +2060,8 @@ declare function createClient(options: ClientOptions): {
|
|
|
1979
2060
|
};
|
|
1980
2061
|
redirectHost: string;
|
|
1981
2062
|
loopbackOnly: boolean;
|
|
1982
|
-
scopes: ("
|
|
1983
|
-
connections: ("
|
|
2063
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
2064
|
+
connections: ("manage-access" | "read" | "reveal" | "write")[][];
|
|
1984
2065
|
days: number;
|
|
1985
2066
|
}>;
|
|
1986
2067
|
decide: (input: RouteInput<"POST /oauth/authorizations">) => Promise<{
|
|
@@ -2048,7 +2129,7 @@ declare function createClient(options: ClientOptions): {
|
|
|
2048
2129
|
name: string;
|
|
2049
2130
|
host: string | null;
|
|
2050
2131
|
registration: "cimd" | "dcr";
|
|
2051
|
-
scopes: ("
|
|
2132
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
2052
2133
|
createdAt: string;
|
|
2053
2134
|
lastUsedAt: string | null;
|
|
2054
2135
|
lastUsedIp: string | null;
|
|
@@ -2152,4 +2233,4 @@ declare function planImport(coffre: CoffreClient, path: string, entries: readonl
|
|
|
2152
2233
|
changes: Record<string, string>;
|
|
2153
2234
|
}>;
|
|
2154
2235
|
//#endregion
|
|
2155
|
-
export {
|
|
2236
|
+
export { DeletionResult as A, OffboardingReport as B, AuthInfo as C, ConnectedApp as D, BindingView as E, InheritedGrant as F, SecretVersion as G, ReferenceView as H, ListedReference as I, SetResult as J, ServiceTokenRow as K, Me as L, DryRunOutcome as M, DryRunResult as N, Decision as O, IdentityRow as P, Member as R, AuditEntryView as S, BindingPlan as T, RemovedMember as U, ProjectSummary as V, SecretKey as W, WorkloadIds as Y, byFolder as _, Params as a, Api as b, RouteOutput as c, planImport as d, Unreachable as f, shownMember as g, serviceName as h, ImportAction as i, DismissedKey as j, Deletion as k, Transport as l, apiMember as m, CoffreClient as n, RouteInput as o, unreachable as p, SessionRow as q, CoffreError as r, RouteKey as s, ClientOptions as t, createClient as u, foldersOf as v, AuthorizationView as w, ApprovalView as x, AccessValue as y, MissingKey as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { type AccessValue, type Api, type ApprovalView, type AuditEntryView, type AuthInfo, type AuthorizationView, type BindingPlan, type BindingView, ClientOptions, CoffreClient, CoffreError, type ConnectedApp, type Decision, type Deletion, type DeletionResult, type DismissedKey, type DryRunOutcome, type DryRunResult, type IdentityRow, ImportAction, type InheritedGrant, type ListedReference, type Me, type Member, type MissingKey, type OffboardingReport, Params, type ProjectSummary, type ReferenceView, type RemovedMember, RouteInput, RouteKey, RouteOutput, type SecretKey, type SecretVersion, type ServiceTokenRow, type SessionRow, type SetResult, Transport, type WorkloadIds, apiMember, byFolder, createClient, foldersOf, planImport, serviceName, shownMember };
|
|
1
|
+
import { A as DeletionResult, B as OffboardingReport, C as AuthInfo, D as ConnectedApp, E as BindingView, F as InheritedGrant, G as SecretVersion, H as ReferenceView, I as ListedReference, J as SetResult, K as ServiceTokenRow, L as Me, M as DryRunOutcome, N as DryRunResult, O as Decision, P as IdentityRow, R as Member, S as AuditEntryView, T as BindingPlan, U as RemovedMember, V as ProjectSummary, W as SecretKey, Y as WorkloadIds, _ as byFolder, a as Params, b as Api, c as RouteOutput, d as planImport, f as Unreachable, g as shownMember, h as serviceName, i as ImportAction, j as DismissedKey, k as Deletion, l as Transport, m as apiMember, n as CoffreClient, o as RouteInput, p as unreachable, q as SessionRow, r as CoffreError, s as RouteKey, t as ClientOptions, u as createClient, v as foldersOf, w as AuthorizationView, x as ApprovalView, y as AccessValue, z as MissingKey } from "./index-ZGDlpCwB.js";
|
|
2
|
+
export { type AccessValue, type Api, type ApprovalView, type AuditEntryView, type AuthInfo, type AuthorizationView, type BindingPlan, type BindingView, ClientOptions, CoffreClient, CoffreError, type ConnectedApp, type Decision, type Deletion, type DeletionResult, type DismissedKey, type DryRunOutcome, type DryRunResult, type IdentityRow, ImportAction, type InheritedGrant, type ListedReference, type Me, type Member, type MissingKey, type OffboardingReport, Params, type ProjectSummary, type ReferenceView, type RemovedMember, RouteInput, RouteKey, RouteOutput, type SecretKey, type SecretVersion, type ServiceTokenRow, type SessionRow, type SetResult, Transport, Unreachable, type WorkloadIds, apiMember, byFolder, createClient, foldersOf, planImport, serviceName, shownMember, unreachable };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
+
//#region src/reach.ts
|
|
2
|
+
/** Two colons or more, in hex: an IPv6 address, as `::1` or `2001:db8::1:443` with its port. */
|
|
3
|
+
const IPV6 = /[0-9a-f]*:[0-9a-f]*:[0-9a-f:]*/i;
|
|
4
|
+
const TIMEOUT_OR_REFUSAL = /* @__PURE__ */ new Set([
|
|
5
|
+
"ECONNREFUSED",
|
|
6
|
+
"ETIMEDOUT",
|
|
7
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
8
|
+
"ENETUNREACH",
|
|
9
|
+
"EHOSTUNREACH"
|
|
10
|
+
]);
|
|
11
|
+
/** What to try for the common causes; null for the others. */
|
|
12
|
+
function hint(cause) {
|
|
13
|
+
const code = cause.code ?? "";
|
|
14
|
+
if (code === "ENOTFOUND" || code === "EAI_AGAIN") return "the name does not resolve here: check the address, or flush this machine's DNS cache";
|
|
15
|
+
const tried = [cause, ...cause.errors ?? []].flatMap((each) => [each.address ?? "", each.message]);
|
|
16
|
+
if (TIMEOUT_OR_REFUSAL.has(code) && tried.some((each) => IPV6.test(each))) return "it was tried over IPv6, which this network may not carry: try NODE_OPTIONS=--dns-result-order=ipv4first";
|
|
17
|
+
if (/CERT|UNABLE_TO_VERIFY|SELF_SIGNED/.test(code)) return "something between you and the instance, such as a proxy or a network filter, presents its own certificate";
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
/** The cause's own words, with its code and address when they don't already say them. */
|
|
21
|
+
function described(cause) {
|
|
22
|
+
const said = cause.message || (cause.errors ?? []).map((each) => each.message).join(", ");
|
|
23
|
+
const address = cause.address === void 0 ? void 0 : cause.port === void 0 ? cause.address : `${cause.address}:${cause.port}`;
|
|
24
|
+
const more = [cause.code, address].filter((each) => each !== void 0 && !said.includes(each));
|
|
25
|
+
if (said === "") return more.join(" ") || cause.name;
|
|
26
|
+
return more.length === 0 ? said : `${said} (${more.join(", ")})`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* `could not reach <origin>: <why>`, and what to try when the cause is a
|
|
30
|
+
* common one: `could not reach https://x: getaddrinfo ENOTFOUND x; the name
|
|
31
|
+
* does not resolve here: …`.
|
|
32
|
+
*/
|
|
33
|
+
function unreachable(origin, error) {
|
|
34
|
+
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : null;
|
|
35
|
+
if (cause === null) return `could not reach ${origin}: ${error instanceof Error ? error.message : String(error)}`;
|
|
36
|
+
const then = hint(cause);
|
|
37
|
+
return `could not reach ${origin}: ${described(cause)}${then === null ? "" : `; ${then}`}`;
|
|
38
|
+
}
|
|
39
|
+
/** A request that never reached the instance: its message says why, `cause` is what `fetch` threw. */
|
|
40
|
+
var Unreachable = class extends Error {
|
|
41
|
+
origin;
|
|
42
|
+
constructor(origin, error) {
|
|
43
|
+
super(unreachable(origin, error), { cause: error });
|
|
44
|
+
this.name = "Unreachable";
|
|
45
|
+
this.origin = origin;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
1
49
|
//#region src/folders.ts
|
|
2
50
|
/**
|
|
3
51
|
* Rows grouped by folder, as every list shows them: those in no folder
|
|
@@ -63,7 +111,13 @@ function place(path) {
|
|
|
63
111
|
}
|
|
64
112
|
function createClient(options) {
|
|
65
113
|
const origin = options.url.replace(/\/+$/, "");
|
|
66
|
-
const transport = options.transport ?? ((request) =>
|
|
114
|
+
const transport = options.transport ?? (async (request) => {
|
|
115
|
+
try {
|
|
116
|
+
return await fetch(request);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw new Unreachable(origin, error);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
67
121
|
async function send(method, path, input) {
|
|
68
122
|
const url = new URL(`${origin}/api${path}`);
|
|
69
123
|
const headers = new Headers(await options.headers?.());
|
|
@@ -303,4 +357,4 @@ async function planImport(coffre, path, entries) {
|
|
|
303
357
|
};
|
|
304
358
|
}
|
|
305
359
|
//#endregion
|
|
306
|
-
export { CoffreError, apiMember, byFolder, createClient, foldersOf, planImport, serviceName, shownMember };
|
|
360
|
+
export { CoffreError, Unreachable, apiMember, byFolder, createClient, foldersOf, planImport, serviceName, shownMember, unreachable };
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Params, o as RouteInput, s as RouteKey } from "./index-
|
|
1
|
+
import { a as Params, o as RouteInput, s as RouteKey } from "./index-ZGDlpCwB.js";
|
|
2
2
|
//#region src/routes.d.ts
|
|
3
3
|
export type GetKey = Extract<RouteKey, `GET ${string}`>;
|
|
4
4
|
/** Each GET route, with what to ask it. */
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type Api = {
|
|
|
17
17
|
isRootAdmin: boolean;
|
|
18
18
|
canReadAudit: boolean;
|
|
19
19
|
features: {
|
|
20
|
-
mcp:
|
|
20
|
+
mcp: string | null;
|
|
21
21
|
workloads: boolean;
|
|
22
22
|
};
|
|
23
23
|
environments: {
|
|
@@ -424,6 +424,7 @@ export type Api = {
|
|
|
424
424
|
sessions: number;
|
|
425
425
|
tokens: number;
|
|
426
426
|
identities: number;
|
|
427
|
+
apps: number;
|
|
427
428
|
};
|
|
428
429
|
exposed: {
|
|
429
430
|
project: string;
|
|
@@ -442,6 +443,17 @@ export type Api = {
|
|
|
442
443
|
expiresAt: string;
|
|
443
444
|
lastUsedAt: string | null;
|
|
444
445
|
}[];
|
|
446
|
+
apps: {
|
|
447
|
+
id: string;
|
|
448
|
+
name: string;
|
|
449
|
+
host: string | null;
|
|
450
|
+
registration: "cimd" | "dcr";
|
|
451
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
452
|
+
createdAt: string;
|
|
453
|
+
lastUsedAt: string | null;
|
|
454
|
+
lastUsedIp: string | null;
|
|
455
|
+
expiresAt: string;
|
|
456
|
+
}[];
|
|
445
457
|
references: {
|
|
446
458
|
id: string;
|
|
447
459
|
holder: string;
|
|
@@ -473,6 +485,7 @@ export type Api = {
|
|
|
473
485
|
sessions: number;
|
|
474
486
|
tokens: number;
|
|
475
487
|
identities: number;
|
|
488
|
+
apps: number;
|
|
476
489
|
};
|
|
477
490
|
report: {
|
|
478
491
|
principalType: "service" | "user";
|
|
@@ -487,6 +500,7 @@ export type Api = {
|
|
|
487
500
|
sessions: number;
|
|
488
501
|
tokens: number;
|
|
489
502
|
identities: number;
|
|
503
|
+
apps: number;
|
|
490
504
|
};
|
|
491
505
|
exposed: {
|
|
492
506
|
project: string;
|
|
@@ -505,6 +519,17 @@ export type Api = {
|
|
|
505
519
|
expiresAt: string;
|
|
506
520
|
lastUsedAt: string | null;
|
|
507
521
|
}[];
|
|
522
|
+
apps: {
|
|
523
|
+
id: string;
|
|
524
|
+
name: string;
|
|
525
|
+
host: string | null;
|
|
526
|
+
registration: "cimd" | "dcr";
|
|
527
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
528
|
+
createdAt: string;
|
|
529
|
+
lastUsedAt: string | null;
|
|
530
|
+
lastUsedIp: string | null;
|
|
531
|
+
expiresAt: string;
|
|
532
|
+
}[];
|
|
508
533
|
references: {
|
|
509
534
|
id: string;
|
|
510
535
|
holder: string;
|
|
@@ -732,8 +757,8 @@ export type Api = {
|
|
|
732
757
|
};
|
|
733
758
|
redirectHost: string;
|
|
734
759
|
loopbackOnly: boolean;
|
|
735
|
-
scopes: ("
|
|
736
|
-
connections: ("
|
|
760
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
761
|
+
connections: ("manage-access" | "read" | "reveal" | "write")[][];
|
|
737
762
|
days: number;
|
|
738
763
|
};
|
|
739
764
|
};
|
|
@@ -764,7 +789,7 @@ export type Api = {
|
|
|
764
789
|
name: string;
|
|
765
790
|
host: string | null;
|
|
766
791
|
registration: "cimd" | "dcr";
|
|
767
|
-
scopes: ("
|
|
792
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
768
793
|
createdAt: string;
|
|
769
794
|
lastUsedAt: string | null;
|
|
770
795
|
lastUsedIp: string | null;
|
|
@@ -1024,8 +1049,8 @@ export type AuthorizationView = {
|
|
|
1024
1049
|
};
|
|
1025
1050
|
redirectHost: string;
|
|
1026
1051
|
loopbackOnly: boolean;
|
|
1027
|
-
scopes: ("
|
|
1028
|
-
connections: ("
|
|
1052
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
1053
|
+
connections: ("manage-access" | "read" | "reveal" | "write")[][];
|
|
1029
1054
|
days: number;
|
|
1030
1055
|
};
|
|
1031
1056
|
|
|
@@ -1061,7 +1086,7 @@ export type ConnectedApp = {
|
|
|
1061
1086
|
name: string;
|
|
1062
1087
|
host: string | null;
|
|
1063
1088
|
registration: "cimd" | "dcr";
|
|
1064
|
-
scopes: ("
|
|
1089
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
1065
1090
|
createdAt: string;
|
|
1066
1091
|
lastUsedAt: string | null;
|
|
1067
1092
|
lastUsedIp: string | null;
|
|
@@ -1177,7 +1202,7 @@ export type Me = {
|
|
|
1177
1202
|
isRootAdmin: boolean;
|
|
1178
1203
|
canReadAudit: boolean;
|
|
1179
1204
|
features: {
|
|
1180
|
-
mcp:
|
|
1205
|
+
mcp: string | null;
|
|
1181
1206
|
workloads: boolean;
|
|
1182
1207
|
};
|
|
1183
1208
|
environments: {
|
|
@@ -1224,6 +1249,7 @@ export type OffboardingReport = {
|
|
|
1224
1249
|
sessions: number;
|
|
1225
1250
|
tokens: number;
|
|
1226
1251
|
identities: number;
|
|
1252
|
+
apps: number;
|
|
1227
1253
|
};
|
|
1228
1254
|
exposed: {
|
|
1229
1255
|
project: string;
|
|
@@ -1242,6 +1268,17 @@ export type OffboardingReport = {
|
|
|
1242
1268
|
expiresAt: string;
|
|
1243
1269
|
lastUsedAt: string | null;
|
|
1244
1270
|
}[];
|
|
1271
|
+
apps: {
|
|
1272
|
+
id: string;
|
|
1273
|
+
name: string;
|
|
1274
|
+
host: string | null;
|
|
1275
|
+
registration: "cimd" | "dcr";
|
|
1276
|
+
scopes: ("manage-access" | "read" | "reveal" | "write")[];
|
|
1277
|
+
createdAt: string;
|
|
1278
|
+
lastUsedAt: string | null;
|
|
1279
|
+
lastUsedIp: string | null;
|
|
1280
|
+
expiresAt: string;
|
|
1281
|
+
}[];
|
|
1245
1282
|
references: {
|
|
1246
1283
|
id: string;
|
|
1247
1284
|
holder: string;
|
package/src/index.ts
CHANGED
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Every call is one `fetch`. Pass a `transport` to send requests somewhere
|
|
9
9
|
* else: the web app hands requests straight to its router, and the CLI adds
|
|
10
|
-
* its own handling of Cloudflare Access redirects.
|
|
10
|
+
* its own handling of Cloudflare Access redirects. A request that never
|
|
11
|
+
* reaches the instance throws `Unreachable`, which says why.
|
|
11
12
|
*/
|
|
12
13
|
import type { Api, AuthInfo, BindingPlan, BindingView, DeletionResult, DryRunOutcome, DryRunResult, SetResult } from './api.ts';
|
|
14
|
+
import { Unreachable } from './reach.ts';
|
|
13
15
|
|
|
14
16
|
export type {
|
|
15
17
|
AccessValue,
|
|
@@ -47,6 +49,7 @@ export type {
|
|
|
47
49
|
|
|
48
50
|
export { byFolder, foldersOf } from './folders.ts';
|
|
49
51
|
export { apiMember, serviceName, shownMember } from './members.ts';
|
|
52
|
+
export { unreachable, Unreachable } from './reach.ts';
|
|
50
53
|
|
|
51
54
|
export type RouteKey = keyof Api;
|
|
52
55
|
/** What a caller sends: the body, or the query string for a GET. */
|
|
@@ -104,7 +107,15 @@ function place(path: string): { project: string; environment: string; key: strin
|
|
|
104
107
|
|
|
105
108
|
export function createClient(options: ClientOptions) {
|
|
106
109
|
const origin = options.url.replace(/\/+$/, '');
|
|
107
|
-
const transport =
|
|
110
|
+
const transport =
|
|
111
|
+
options.transport ??
|
|
112
|
+
(async (request: Request) => {
|
|
113
|
+
try {
|
|
114
|
+
return await fetch(request);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw new Unreachable(origin, error);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
108
119
|
|
|
109
120
|
async function send(method: string, path: string, input: unknown): Promise<unknown> {
|
|
110
121
|
const url = new URL(`${origin}/api${path}`);
|
package/src/reach.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why an instance could not be reached, from what `fetch` threw. Node's
|
|
3
|
+
* `fetch` says only `fetch failed`: what happened is in its `cause`, Node's
|
|
4
|
+
* own error, with a code (`ENOTFOUND`, `ECONNREFUSED`, a certificate's) and
|
|
5
|
+
* often the address it tried. A browser's says nothing more, and has no cause.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Node's error under a failed `fetch`; an AggregateError, with no message, when every address failed. */
|
|
9
|
+
type Cause = Error & { code?: string; address?: string; port?: number; hostname?: string; errors?: Cause[] };
|
|
10
|
+
|
|
11
|
+
/** Two colons or more, in hex: an IPv6 address, as `::1` or `2001:db8::1:443` with its port. */
|
|
12
|
+
const IPV6 = /[0-9a-f]*:[0-9a-f]*:[0-9a-f:]*/i;
|
|
13
|
+
|
|
14
|
+
const TIMEOUT_OR_REFUSAL = new Set(['ECONNREFUSED', 'ETIMEDOUT', 'UND_ERR_CONNECT_TIMEOUT', 'ENETUNREACH', 'EHOSTUNREACH']);
|
|
15
|
+
|
|
16
|
+
/** What to try for the common causes; null for the others. */
|
|
17
|
+
function hint(cause: Cause): string | null {
|
|
18
|
+
const code = cause.code ?? '';
|
|
19
|
+
if (code === 'ENOTFOUND' || code === 'EAI_AGAIN') {
|
|
20
|
+
return "the name does not resolve here: check the address, or flush this machine's DNS cache";
|
|
21
|
+
}
|
|
22
|
+
const tried = [cause, ...(cause.errors ?? [])].flatMap((each) => [each.address ?? '', each.message]);
|
|
23
|
+
if (TIMEOUT_OR_REFUSAL.has(code) && tried.some((each) => IPV6.test(each))) {
|
|
24
|
+
return "it was tried over IPv6, which this network may not carry: try NODE_OPTIONS=--dns-result-order=ipv4first";
|
|
25
|
+
}
|
|
26
|
+
if (/CERT|UNABLE_TO_VERIFY|SELF_SIGNED/.test(code)) {
|
|
27
|
+
return 'something between you and the instance, such as a proxy or a network filter, presents its own certificate';
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The cause's own words, with its code and address when they don't already say them. */
|
|
33
|
+
function described(cause: Cause): string {
|
|
34
|
+
const said = cause.message || (cause.errors ?? []).map((each) => each.message).join(', ');
|
|
35
|
+
const address = cause.address === undefined ? undefined : cause.port === undefined ? cause.address : `${cause.address}:${cause.port}`;
|
|
36
|
+
const more = [cause.code, address].filter((each): each is string => each !== undefined && !said.includes(each));
|
|
37
|
+
if (said === '') return more.join(' ') || cause.name;
|
|
38
|
+
return more.length === 0 ? said : `${said} (${more.join(', ')})`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* `could not reach <origin>: <why>`, and what to try when the cause is a
|
|
43
|
+
* common one: `could not reach https://x: getaddrinfo ENOTFOUND x; the name
|
|
44
|
+
* does not resolve here: …`.
|
|
45
|
+
*/
|
|
46
|
+
export function unreachable(origin: string, error: unknown): string {
|
|
47
|
+
const cause = error instanceof Error && error.cause instanceof Error ? (error.cause as Cause) : null;
|
|
48
|
+
if (cause === null) return `could not reach ${origin}: ${error instanceof Error ? error.message : String(error)}`;
|
|
49
|
+
const then = hint(cause);
|
|
50
|
+
return `could not reach ${origin}: ${described(cause)}${then === null ? '' : `; ${then}`}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A request that never reached the instance: its message says why, `cause` is what `fetch` threw. */
|
|
54
|
+
export class Unreachable extends Error {
|
|
55
|
+
readonly origin: string;
|
|
56
|
+
|
|
57
|
+
constructor(origin: string, error: unknown) {
|
|
58
|
+
super(unreachable(origin, error), { cause: error });
|
|
59
|
+
this.name = 'Unreachable';
|
|
60
|
+
this.origin = origin;
|
|
61
|
+
}
|
|
62
|
+
}
|