@coffre/client 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as SessionRow, C as Member, D as SecretKey, E as RemovedMember, M as WorkloadIds, O as SecretVersion, S as Me, T as ProjectSummary, _ as BindingView, a as Params, b as IdentityRow, c as RouteOutput, d as planImport, f as AccessValue, g as BindingPlan, h as AuthInfo, i as ImportAction, j as SetResult, k as ServiceTokenRow, l as Transport, m as AuditEntryView, n as CoffreClient, o as RouteInput, p as Api, r as CoffreError, s as RouteKey, t as ClientOptions, u as createClient, v as DryRunOutcome, w as OffboardingReport, x as InstanceState, y as DryRunResult } from "./index-BuMxAzSu.js";
2
- export { type AccessValue, type Api, type AuditEntryView, type AuthInfo, type BindingPlan, type BindingView, ClientOptions, CoffreClient, CoffreError, type DryRunOutcome, type DryRunResult, type IdentityRow, ImportAction, type InstanceState, type Me, type Member, type OffboardingReport, Params, type ProjectSummary, type RemovedMember, RouteInput, RouteKey, RouteOutput, type SecretKey, type SecretVersion, type ServiceTokenRow, type SessionRow, type SetResult, Transport, type WorkloadIds, createClient, planImport };
1
+ import { A as DryRunOutcome, B as ReferenceView, C as BindingPlan, D as Deletion, E as Decision, F as Me, G as SessionRow, H as SecretKey, I as Member, K as SetResult, L as MissingKey, M as IdentityRow, N as InheritedGrant, O as DeletionResult, P as ListedReference, R as OffboardingReport, S as AuthorizationView, T as ConnectedApp, U as SecretVersion, V as RemovedMember, W as ServiceTokenRow, _ as AccessValue, a as Params, b as AuditEntryView, c as RouteOutput, d as planImport, f as apiMember, g as foldersOf, h as byFolder, i as ImportAction, j as DryRunResult, k as DismissedKey, l as Transport, m as shownMember, n as CoffreClient, o as RouteInput, p as serviceName, q as WorkloadIds, r as CoffreError, s as RouteKey, t as ClientOptions, u as createClient, v as Api, w as BindingView, x as AuthInfo, y as ApprovalView, z as ProjectSummary } from "./index-CsGTyqgO.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, type WorkloadIds, apiMember, byFolder, createClient, foldersOf, planImport, serviceName, shownMember };
package/dist/index.js CHANGED
@@ -1,3 +1,42 @@
1
+ //#region src/folders.ts
2
+ /**
3
+ * Rows grouped by folder, as every list shows them: those in no folder
4
+ * first, then each folder by name, each keeping the order it was given. A
5
+ * folder only arranges a list (docs/design/environments.md).
6
+ */
7
+ function byFolder(rows) {
8
+ const groups = /* @__PURE__ */ new Map([[null, []]]);
9
+ for (const folder of [...new Set(rows.flatMap((row) => row.folder === null ? [] : [row.folder]))].sort()) groups.set(folder, []);
10
+ for (const row of rows) groups.get(row.folder).push(row);
11
+ return [...groups].filter(([, inFolder]) => inFolder.length > 0);
12
+ }
13
+ /** The folders in use among `rows`, by name. */
14
+ function foldersOf(rows) {
15
+ return [...new Set(rows.flatMap((row) => row.folder === null ? [] : [row.folder]))].sort();
16
+ }
17
+ //#endregion
18
+ //#region src/members.ts
19
+ /**
20
+ * How members are named, to people and to the API. A service account, a
21
+ * machine identity that signs in by OIDC (trust bindings) or with bearer
22
+ * tokens, is `service:<name>` wherever a person reads or types one. The
23
+ * API, the vault and the audit log keep `token:<name>`, which the log's
24
+ * signed entries hold: so the rename is here, at the edges, and nothing
25
+ * stored or verified changes.
26
+ */
27
+ /** A member as people read it: `service:deploy` for the API's `token:deploy`; anyone else as they are. */
28
+ function shownMember(member) {
29
+ return member.startsWith("token:") ? `service:${member.slice(6)}` : member;
30
+ }
31
+ /** A member as the API takes it, from what a person typed: `service:deploy` and `token:deploy` alike name a service account. */
32
+ function apiMember(member) {
33
+ return member.startsWith("service:") ? `token:${member.slice(8)}` : member;
34
+ }
35
+ /** A service account's name alone, from any of its forms: `deploy`, `service:deploy` or `token:deploy`. */
36
+ function serviceName(member) {
37
+ return member.replace(/^(?:service|token):/, "");
38
+ }
39
+ //#endregion
1
40
  //#region src/index.ts
2
41
  /** The API's error shape, `{ error, message }`, with the HTTP status. */
3
42
  var CoffreError = class extends Error {
@@ -67,11 +106,29 @@ function createClient(options) {
67
106
  /** With their environments. */
68
107
  list: () => call("GET /projects", {}),
69
108
  create: (project, input) => call("PUT /projects/:project", { project }, input),
70
- update: (project, patch) => call("PATCH /projects/:project", { project }, patch)
109
+ update: (project, patch) => call("PATCH /projects/:project", { project }, patch),
110
+ /** What deleting an archived project would erase and revoke; changes nothing. */
111
+ previewDelete: (project) => {
112
+ const [method, route] = address("DELETE /projects/:project", { project });
113
+ return send(method, `${route}?dryRun=1`, void 0);
114
+ },
115
+ /** Delete an archived project for good: its values erased, its grants revoked, its slug free. Owners only. */
116
+ delete: (project) => call("DELETE /projects/:project", { project })
71
117
  },
72
118
  environments: {
73
119
  create: (path, input) => call("PUT /projects/:project/:environment", place(path), input),
74
- update: (path, patch) => call("PATCH /projects/:project/:environment", place(path), patch)
120
+ update: (path, patch) => call("PATCH /projects/:project/:environment", place(path), patch),
121
+ /** What deleting an archived environment would erase and revoke; changes nothing. */
122
+ previewDelete: (path) => {
123
+ const [method, route] = address("DELETE /projects/:project/:environment", place(path));
124
+ return send(method, `${route}?dryRun=1`, void 0);
125
+ },
126
+ /** Delete an archived environment for good, as a project is. Owners only. */
127
+ delete: (path) => call("DELETE /projects/:project/:environment", place(path)),
128
+ /** The keys its sibling environments have and it lacks, those you can see, and those its team dismissed. */
129
+ missing: (path) => call("GET /projects/:project/:environment/missing", place(path)),
130
+ /** Dismiss missing keys (`true`) or restore them (`null`). */
131
+ dismiss: (path, patch) => call("PATCH /projects/:project/:environment/dismissals", place(path), patch)
75
132
  },
76
133
  secrets: {
77
134
  /** Keys, versions and who changed what; never values. */
@@ -95,6 +152,16 @@ function createClient(options) {
95
152
  rename: (path, key) => call("PATCH /secrets/:project/:environment/:key", place(path), { key }),
96
153
  update: (path, patch) => call("PATCH /secrets/:project/:environment/:key", place(path), patch)
97
154
  },
155
+ /**
156
+ * References: secrets read through others (docs/design/environments.md).
157
+ * A key becomes one with `secrets.set(path, { KEY: { ref: 'market/prod/KEY' } })`.
158
+ */
159
+ references: {
160
+ /** The live references into and out of a place, `market`, `market/prod` or `market/prod/KEY`, and who reads through them. */
161
+ list: (path) => call("GET /references", {}, { path }),
162
+ /** Break the reference a secret is: its readers stop reading the source through it. */
163
+ break: (path) => call("DELETE /secrets/:project/:environment/:key/reference", place(path))
164
+ },
98
165
  members: {
99
166
  /** People and tokens, their role and their access; at a place, those who reach it. */
100
167
  list: (path) => call("GET /members", {}, { path }),
@@ -147,6 +214,55 @@ set: (member, access) => call("PATCH /access/:member", { member }, access) },
147
214
  get: (code) => call("GET /device-logins/:code", { code }),
148
215
  decide: (code, approve) => call("POST /device-logins/:code", { code }, { approve })
149
216
  },
217
+ /**
218
+ * Folders, which arrange lists and do nothing else: a folder exists while
219
+ * something is filed in it. Renaming one re-files all of it, onto a folder
220
+ * that exists merges the two; removing one takes all of it out, each item
221
+ * staying where it is, in no folder. Moving one item is `projects.update`
222
+ * or `secrets.update` with a `folder`.
223
+ */
224
+ folders: {
225
+ /** A folder of projects, renamed. Takes managing every project in it. */
226
+ rename: (folder, name) => call("PATCH /folders/:folder", { folder }, { name }),
227
+ /** Every project out of a folder. */
228
+ remove: (folder) => call("DELETE /folders/:folder", { folder }),
229
+ /** One of an environment's key folders, `market/prod`, renamed. Takes writing there. */
230
+ renameKeys: (environment, folder, name) => {
231
+ const { project, environment: slug } = place(environment);
232
+ return call("PATCH /folders/:project/:environment/:folder", {
233
+ project,
234
+ environment: slug,
235
+ folder
236
+ }, { name });
237
+ },
238
+ /** Every key out of one of an environment's folders. */
239
+ removeKeys: (environment, folder) => {
240
+ const { project, environment: slug } = place(environment);
241
+ return call("DELETE /folders/:project/:environment/:folder", {
242
+ project,
243
+ environment: slug,
244
+ folder
245
+ });
246
+ }
247
+ },
248
+ /**
249
+ * An MCP client asking to connect, by its authorization request, and the
250
+ * person's answer: where to send the browser next.
251
+ */
252
+ oauth: {
253
+ describe: (request) => call("GET /oauth/authorizations", {}, request),
254
+ decide: (input) => call("POST /oauth/authorizations", {}, input)
255
+ },
256
+ /** The MCP clients I connected. */
257
+ /** A change an MCP client asked for: what it would do, and the person's decision, which makes it. */
258
+ approvals: {
259
+ get: (id) => call("GET /approvals/:id", { id }),
260
+ decide: (id, input) => call("POST /approvals/:id", { id }, input)
261
+ },
262
+ apps: {
263
+ list: () => call("GET /apps", {}),
264
+ disconnect: (id) => call("DELETE /apps/:id", { id })
265
+ },
150
266
  audit: {
151
267
  list: (query = {}) => call("GET /audit", {}, query),
152
268
  verify: () => call("GET /audit/verification", {}),
@@ -187,4 +303,4 @@ async function planImport(coffre, path, entries) {
187
303
  };
188
304
  }
189
305
  //#endregion
190
- export { CoffreError, createClient, planImport };
306
+ export { CoffreError, apiMember, byFolder, createClient, foldersOf, planImport, serviceName, shownMember };
package/dist/routes.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Params, o as RouteInput, s as RouteKey } from "./index-BuMxAzSu.js";
1
+ import { a as Params, o as RouteInput, s as RouteKey } from "./index-CsGTyqgO.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/dist/routes.js CHANGED
@@ -5,11 +5,19 @@ function getCalls({ places, secrets, members, services }) {
5
5
  "GET /me": [{ params: {} }],
6
6
  "GET /projects": [{ params: {} }],
7
7
  "GET /secrets/:project/:environment": places.map((params) => ({ params })),
8
+ "GET /projects/:project/:environment/missing": places.map((params) => ({ params })),
8
9
  "GET /secrets/:project/:environment/:key/versions": secrets.map((params) => ({ params })),
9
10
  "GET /members": [{ params: {} }, ...first === void 0 ? [] : [{
10
11
  params: {},
11
12
  input: { path: `${first.project}/${first.environment}` }
12
13
  }]],
14
+ "GET /references": [...first === void 0 ? [] : [{
15
+ params: {},
16
+ input: { path: first.project }
17
+ }, {
18
+ params: {},
19
+ input: { path: `${first.project}/${first.environment}` }
20
+ }]],
13
21
  "GET /members/:member": members.map((member) => ({ params: { member } })),
14
22
  "GET /members/:member/tokens": services.map((member) => ({ params: { member } })),
15
23
  "GET /members/:member/bindings": services.map((member) => ({ params: { member } })),
@@ -20,6 +28,15 @@ function getCalls({ places, secrets, members, services }) {
20
28
  "GET /sessions": [{ params: {} }],
21
29
  "GET /identities": [{ params: {} }],
22
30
  "GET /device-logins/:code": [{ params: { code: "BCDF-GHJK" } }],
31
+ "GET /oauth/authorizations": [{
32
+ params: {},
33
+ input: {
34
+ client_id: "00000000-0000-4000-8000-000000000000",
35
+ redirect_uri: "https://conformance.invalid/callback"
36
+ }
37
+ }],
38
+ "GET /approvals/:id": [{ params: { id: "00000000-0000-4000-8000-000000000000" } }],
39
+ "GET /apps": [{ params: {} }],
23
40
  "GET /audit": [{
24
41
  params: {},
25
42
  input: { limit: 500 }
@@ -49,13 +66,23 @@ const EVERY_ROUTE = {
49
66
  "GET /projects": true,
50
67
  "PUT /projects/:project": true,
51
68
  "PATCH /projects/:project": true,
69
+ "DELETE /projects/:project": true,
52
70
  "PUT /projects/:project/:environment": true,
53
71
  "PATCH /projects/:project/:environment": true,
72
+ "DELETE /projects/:project/:environment": true,
73
+ "GET /projects/:project/:environment/missing": true,
74
+ "PATCH /projects/:project/:environment/dismissals": true,
54
75
  "GET /secrets/:project/:environment": true,
55
76
  "PATCH /secrets/:project/:environment": true,
56
77
  "PATCH /secrets/:project/:environment/:key": true,
57
78
  "GET /secrets/:project/:environment/:key/versions": true,
58
79
  "POST /secrets/:project/:environment/:key/restore": true,
80
+ "DELETE /secrets/:project/:environment/:key/reference": true,
81
+ "PATCH /folders/:folder": true,
82
+ "DELETE /folders/:folder": true,
83
+ "PATCH /folders/:project/:environment/:folder": true,
84
+ "DELETE /folders/:project/:environment/:folder": true,
85
+ "GET /references": true,
59
86
  "POST /reveals": true,
60
87
  "GET /members": true,
61
88
  "GET /members/:member": true,
@@ -75,6 +102,12 @@ const EVERY_ROUTE = {
75
102
  "DELETE /identities/:id": true,
76
103
  "GET /device-logins/:code": true,
77
104
  "POST /device-logins/:code": true,
105
+ "GET /oauth/authorizations": true,
106
+ "POST /oauth/authorizations": true,
107
+ "GET /approvals/:id": true,
108
+ "POST /approvals/:id": true,
109
+ "GET /apps": true,
110
+ "DELETE /apps/:id": true,
78
111
  "GET /audit": true,
79
112
  "GET /audit/verification": true,
80
113
  "GET /audit/keys": true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/client",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "The coffre API as typed function calls.",
5
5
  "license": "MIT",
6
6
  "repository": {