cauthy-auth 0.13.0 → 0.15.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.mjs CHANGED
@@ -997,6 +997,15 @@ function createCauthy(given = {}) {
997
997
  createdAt: String(d?.created_at ?? ""),
998
998
  lastUsedAt: d?.last_used_at ? String(d.last_used_at) : null
999
999
  });
1000
+ const agentOf = (d) => ({
1001
+ id: String(d?.id ?? ""),
1002
+ name: String(d?.agent?.name ?? ""),
1003
+ redirectHost: String(d?.agent?.redirect_host ?? ""),
1004
+ resource: { name: String(d?.resource?.name ?? ""), uri: String(d?.resource?.uri ?? "") },
1005
+ scopes: Array.isArray(d?.scopes) ? d.scopes.map((s) => ({ name: String(s?.name ?? ""), description: String(s?.description ?? "") })) : [],
1006
+ connectedAt: String(d?.created_at ?? ""),
1007
+ lastUsedAt: String(d?.last_used_at ?? "")
1008
+ });
1000
1009
  const problem = (status2, code, message, field, headers) => json({ error: { code, message, ...field ? { field } : {} } }, status2, headers);
1001
1010
  const invalid = (p) => problem(400, p.code, p.message, p.field);
1002
1011
  function ownRequest(request) {
@@ -1121,7 +1130,9 @@ function createCauthy(given = {}) {
1121
1130
  "/me/passkeys",
1122
1131
  "/me/passkeys/add/begin",
1123
1132
  "/me/passkeys/add/finish",
1124
- "/me/passkeys/remove"
1133
+ "/me/passkeys/remove",
1134
+ "/me/agents",
1135
+ "/me/agents/disconnect"
1125
1136
  ].includes(route) || route.startsWith("/sign-in/social/") || route.startsWith("/callback/") || route.startsWith("/me/identities/link/");
1126
1137
  if (!own) return null;
1127
1138
  if (tenant === "") {
@@ -1220,6 +1231,14 @@ function createCauthy(given = {}) {
1220
1231
  const list = Array.isArray(res.data) ? res.data : [];
1221
1232
  return json({ passkeys: list.map(passkeyOf) }, 200, mine.headers);
1222
1233
  }
1234
+ if (route === "/me/agents" && !post) {
1235
+ const mine = await signedInAs(request);
1236
+ if ("response" in mine) return mine.response;
1237
+ const res = await ask(request, "GET", "/v1/auth/me/agents", void 0, void 0, mine.token);
1238
+ if (res.error) return problem(res.status, res.error.code, res.error.message, void 0, mine.headers);
1239
+ const list = Array.isArray(res.data) ? res.data : [];
1240
+ return json({ agents: list.map(agentOf) }, 200, mine.headers);
1241
+ }
1223
1242
  if (route === "/me/mfa/factors" && !post) {
1224
1243
  const mine = await signedInAs(request);
1225
1244
  if ("response" in mine) return mine.response;
@@ -1416,6 +1435,13 @@ function createCauthy(given = {}) {
1416
1435
  if (res.error) return refused(res);
1417
1436
  return json({ status: "removed", id }, 200, mine.headers);
1418
1437
  }
1438
+ if (route === "/me/agents/disconnect") {
1439
+ const id = typeof b.id === "string" ? b.id : "";
1440
+ if (!/^[0-9a-f-]{36}$/i.test(id)) return problem(400, "invalid_agent", "Say which agent to disconnect.", void 0, mine.headers);
1441
+ const res = await as(`/v1/auth/me/agents/${id}`, void 0, "DELETE");
1442
+ if (res.error) return refused(res);
1443
+ return json({ status: "disconnected", id }, 200, mine.headers);
1444
+ }
1419
1445
  if (route === "/me/sessions/end") {
1420
1446
  const res = await as("/v1/auth/me/sessions", void 0, "DELETE");
1421
1447
  if (res.error) return refused(res);