@coffre/conformance 0.1.6 → 0.1.8

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/src/routes.ts DELETED
@@ -1,112 +0,0 @@
1
- // The API's routes, as the checks call them. Both tables are typed over the
2
- // client's route map, so a route added to the server fails the typecheck
3
- // here until it is listed, and from then on every check that walks a table
4
- // covers it: the anonymous refusal, the canary scans, the cross-site one.
5
- import type { Params, RouteInput, RouteKey } from '@coffre/client';
6
-
7
- export type GetKey = Extract<RouteKey, `GET ${string}`>;
8
-
9
- /** Each GET route, with what to ask it. */
10
- export type GetCalls = { [K in GetKey]: { params: Params<K>; input?: RouteInput<K> }[] };
11
-
12
- /** What the GET routes are asked about: places, secrets and members to name. */
13
- export type Subjects = {
14
- places: { project: string; environment: string }[];
15
- /** Secrets whose history to ask for. */
16
- secrets: { project: string; environment: string; key: string }[];
17
- /** `user:…` and `token:…`. */
18
- members: string[];
19
- /** Tokens whose credentials to list. */
20
- services: string[];
21
- };
22
-
23
- export function getCalls({ places, secrets, members, services }: Subjects): GetCalls {
24
- const first = places[0];
25
- return {
26
- 'GET /me': [{ params: {} }],
27
- 'GET /projects': [{ params: {} }],
28
- 'GET /secrets/:project/:environment': places.map((params) => ({ params })),
29
- 'GET /secrets/:project/:environment/:key/versions': secrets.map((params) => ({ params })),
30
- 'GET /members': [
31
- { params: {} },
32
- ...(first === undefined ? [] : [{ params: {}, input: { path: `${first.project}/${first.environment}` } }]),
33
- ],
34
- 'GET /members/:member': members.map((member) => ({ params: { member } })),
35
- 'GET /members/:member/tokens': services.map((member) => ({ params: { member } })),
36
- 'GET /sessions': [{ params: {} }],
37
- 'GET /identities': [{ params: {} }],
38
- 'GET /device-logins/:code': [{ params: { code: 'BCDF-GHJK' } }],
39
- 'GET /syncs/providers': [{ params: {} }],
40
- 'GET /syncs/:project/:environment': places.map((params) => ({ params })),
41
- 'GET /audit': [{ params: {}, input: { limit: 500 } }, { params: {}, input: { limit: 500, detail: '1' } }],
42
- 'GET /audit/verification': [{ params: {} }],
43
- };
44
- }
45
-
46
- /** Each GET call as a URL, with its parameters and query filled in. */
47
- export function getUrls(origin: string, calls: GetCalls): { key: GetKey; url: string }[] {
48
- const urls: { key: GetKey; url: string }[] = [];
49
- for (const [key, asks] of Object.entries(calls) as [GetKey, { params: Record<string, string>; input?: object }[]][]) {
50
- for (const { params, input } of asks) urls.push({ key, url: address(origin, key, params, input) });
51
- }
52
- return urls;
53
- }
54
-
55
- /** Every route, whatever its method. */
56
- const EVERY_ROUTE: { [K in RouteKey]: true } = {
57
- 'GET /me': true,
58
- 'GET /projects': true,
59
- 'PUT /projects/:project': true,
60
- 'PATCH /projects/:project': true,
61
- 'PUT /projects/:project/:environment': true,
62
- 'PATCH /projects/:project/:environment': true,
63
- 'GET /secrets/:project/:environment': true,
64
- 'PATCH /secrets/:project/:environment': true,
65
- 'PATCH /secrets/:project/:environment/:key': true,
66
- 'GET /secrets/:project/:environment/:key/versions': true,
67
- 'POST /secrets/:project/:environment/:key/restore': true,
68
- 'POST /reveals': true,
69
- 'GET /members': true,
70
- 'GET /members/:member': true,
71
- 'PUT /members/:member': true,
72
- 'DELETE /members/:member': true,
73
- 'GET /members/:member/tokens': true,
74
- 'POST /members/:member/tokens': true,
75
- 'DELETE /members/:member/tokens/:id': true,
76
- 'PATCH /access/:member': true,
77
- 'GET /sessions': true,
78
- 'DELETE /sessions/:id': true,
79
- 'GET /identities': true,
80
- 'DELETE /identities/:id': true,
81
- 'GET /device-logins/:code': true,
82
- 'POST /device-logins/:code': true,
83
- 'GET /syncs/providers': true,
84
- 'GET /syncs/:project/:environment': true,
85
- 'POST /syncs/:project/:environment': true,
86
- 'PATCH /syncs/by-id/:id': true,
87
- 'DELETE /syncs/by-id/:id': true,
88
- 'POST /syncs/by-id/:id/runs': true,
89
- 'GET /audit': true,
90
- 'GET /audit/verification': true,
91
- };
92
-
93
- /**
94
- * Every route as a method and a URL, each parameter a made-up value: what
95
- * a caller with no right to any of them would send.
96
- */
97
- export function everyRoute(origin: string): { key: RouteKey; method: string; url: string }[] {
98
- return (Object.keys(EVERY_ROUTE) as RouteKey[]).map((key) => {
99
- const [method, pattern] = key.split(' ') as [string, string];
100
- const path = pattern.replace(/:(\w+)/g, (_, name: string) =>
101
- encodeURIComponent(name === 'member' ? 'token:conformance-nobody' : 'conformance-nobody'),
102
- );
103
- return { key, method, url: `${origin}/api${path}` };
104
- });
105
- }
106
-
107
- function address(origin: string, key: GetKey, params: Record<string, string>, input: object | undefined): string {
108
- const path = key.slice('GET '.length).replace(/:(\w+)/g, (_, name: string) => encodeURIComponent(params[name]!));
109
- const url = new URL(`${origin}/api${path}`);
110
- for (const [name, value] of Object.entries(input ?? {})) url.searchParams.set(name, String(value));
111
- return url.href;
112
- }