From 61d01be34282a6e58e536db2cc6c0054d0a9e23c Mon Sep 17 00:00:00 2001 From: saif <11242541+saifsmailbox98@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:12:03 +0530 Subject: [PATCH 1/6] feat(agent-vault): choose the Agent Vault project with projectId --- sink/agent-vault.test.ts | 84 ++++++++++++++++++++++++++++++++ src/api/endpoints/agent-vault.ts | 33 +++++++++---- src/api/types/agent-vault.ts | 40 +++++++++++++++ src/custom/agent-vault.ts | 45 ++++++++++------- 4 files changed, 175 insertions(+), 27 deletions(-) diff --git a/sink/agent-vault.test.ts b/sink/agent-vault.test.ts index 3c80b16..3492414 100644 --- a/sink/agent-vault.test.ts +++ b/sink/agent-vault.test.ts @@ -413,6 +413,90 @@ describe("agent vault routes", () => { }); }); +// The ROUTES table above checks that a call without projectId leaves it out, so the server picks the project. +describe("agent vault project", () => { + const PROJECT_ID = "4d6f8a0c-2e4b-4c6d-8f0a-1b3d5f7a9c2e"; + const project = { projectId: PROJECT_ID }; + + it.each([ + { name: "proxies.list", call: (av: AgentVault) => av.proxies.list(project), response: { proxies: [], totalCount: 0 } }, + { name: "sessions.list", call: (av: AgentVault) => av.sessions.list(project), response: { sessions: [], totalCount: 0 } }, + { + name: "accessBundles.list", + call: (av: AgentVault) => av.accessBundles.list(project), + response: { accessBundles: [], totalCount: 0 } + }, + { + name: "delegations.list", + call: (av: AgentVault) => av.delegations.list(project), + response: { delegations: [], totalCount: 0 } + }, + { + name: "delegations.get", + call: (av: AgentVault) => av.delegations.get(MACHINE_IDENTITY_ID, project), + response: { delegation: DELEGATION_DETAIL } + }, + { + name: "delegations.set", + call: (av: AgentVault) => av.delegations.set(MACHINE_IDENTITY_ID, { ...project, scope: "all-members" }), + response: { delegation: DELEGATION_DETAIL }, + body: { scope: "all-members" } + }, + { + name: "delegations.delete", + call: (av: AgentVault) => av.delegations.delete(MACHINE_IDENTITY_ID, project), + response: { delegation: DELEGATION } + }, + { + name: "delegations.addSubjects", + call: (av: AgentVault) => av.delegations.addSubjects(MACHINE_IDENTITY_ID, { ...project, userIds: [USER_ID] }), + response: { delegation: DELEGATION_DETAIL }, + body: { userIds: [USER_ID] } + }, + { + name: "delegations.removeSubjects", + call: (av: AgentVault) => av.delegations.removeSubjects(MACHINE_IDENTITY_ID, { ...project, userIds: [USER_ID] }), + response: { delegation: DELEGATION_DETAIL }, + body: { userIds: [USER_ID] } + }, + { + name: "delegations.listAvailableSubjects", + call: (av: AgentVault) => av.delegations.listAvailableSubjects(MACHINE_IDENTITY_ID, project), + response: { members: [], totalCount: 0 } + } + ])("$name sends projectId in the query string", async ({ call, response, body }) => { + respondWith(response); + await call(agentVault); + const request = lastRequest(); + expect(request.query.projectId).toBe(PROJECT_ID); + expect(request.body).toEqual(body); + }); + + it.each([ + { + name: "proxies.create", + call: (av: AgentVault) => av.proxies.create({ ...project, name: "edge-proxy" }), + response: { proxy: PROXY, proxyToken: "proxy-token" } + }, + { + name: "sessions.create", + call: (av: AgentVault) => av.sessions.create({ ...project, accessBundle: "release" }), + response: { session: CREATED_SESSION } + }, + { + name: "accessBundles.create", + call: (av: AgentVault) => av.accessBundles.create({ ...project, name: "release" }), + response: { accessBundle: BUNDLE } + } + ])("$name sends projectId in the body", async ({ call, response }) => { + respondWith(response); + await call(agentVault); + const request = lastRequest(); + expect(request.body.projectId).toBe(PROJECT_ID); + expect(request.query).toEqual({}); + }); +}); + describe("agent vault proxies", () => { it.each([[[]], [""], [" "]])("update sends null to remove every allowed host when given %j", async (allowedHosts) => { respondWith({ proxy: PROXY }); diff --git a/src/api/endpoints/agent-vault.ts b/src/api/endpoints/agent-vault.ts index 3bd7548..351bc1a 100644 --- a/src/api/endpoints/agent-vault.ts +++ b/src/api/endpoints/agent-vault.ts @@ -1,6 +1,7 @@ import { InfisicalSDKError } from "../../custom/errors"; import { ApiClient } from "../base"; import { + AgentVaultProjectQuery, AgentVaultProxyWithTokenResponse, ChangeAgentVaultAccessBundleGrantsRequest, ChangeAgentVaultDelegationSubjectsRequest, @@ -150,32 +151,44 @@ export class AgentVaultApi { list: (params: ListAgentVaultDelegationsRequest) => this.apiClient.get(`${BASE_PATH}/delegations`, { params }), - get: (machineIdentityId: string) => + get: (machineIdentityId: string, params: AgentVaultProjectQuery) => this.apiClient.get( - `${BASE_PATH}/delegations/${segment(machineIdentityId)}` + `${BASE_PATH}/delegations/${segment(machineIdentityId)}`, + { params } ), - set: (machineIdentityId: string, data: SetAgentVaultDelegationRequest) => + set: (machineIdentityId: string, data: SetAgentVaultDelegationRequest, params: AgentVaultProjectQuery) => this.apiClient.put( `${BASE_PATH}/delegations/${segment(machineIdentityId)}`, - data + data, + { params } ), - delete: (machineIdentityId: string) => + delete: (machineIdentityId: string, params: AgentVaultProjectQuery) => this.apiClient.deleteOnce( - `${BASE_PATH}/delegations/${segment(machineIdentityId)}` + `${BASE_PATH}/delegations/${segment(machineIdentityId)}`, + { params } ), - addSubjects: (machineIdentityId: string, data: ChangeAgentVaultDelegationSubjectsRequest) => + addSubjects: ( + machineIdentityId: string, + data: ChangeAgentVaultDelegationSubjectsRequest, + params: AgentVaultProjectQuery + ) => this.apiClient.post( `${BASE_PATH}/delegations/${segment(machineIdentityId)}/subjects`, - data + data, + { params } ), - removeSubjects: (machineIdentityId: string, data: ChangeAgentVaultDelegationSubjectsRequest) => + removeSubjects: ( + machineIdentityId: string, + data: ChangeAgentVaultDelegationSubjectsRequest, + params: AgentVaultProjectQuery + ) => this.apiClient.deleteOnce( `${BASE_PATH}/delegations/${segment(machineIdentityId)}/subjects`, - { data } + { data, params } ), listAvailableSubjects: (machineIdentityId: string, params: ListAvailableAgentVaultDelegationSubjectsRequest) => diff --git a/src/api/types/agent-vault.ts b/src/api/types/agent-vault.ts index ec15dca..9b5586d 100644 --- a/src/api/types/agent-vault.ts +++ b/src/api/types/agent-vault.ts @@ -512,7 +512,13 @@ export interface RemoveAgentVaultDelegationSubjectsResponse { // Requests, as sent to the API +/** The query string of a delegation route, which names the project because a machine identity can be in several. */ +export interface AgentVaultProjectQuery { + projectId?: string; +} + export interface ListAgentVaultProxiesRequest { + projectId?: string; search?: string; orderBy: "name" | "createdAt"; orderDirection: AgentVaultOrderDirection; @@ -521,6 +527,7 @@ export interface ListAgentVaultProxiesRequest { } export interface CreateAgentVaultProxyRequest { + projectId?: string; name: string; /** "bundle-hosts" is the old name of "service-hosts", and the only one an Infisical version from before the rename accepts. */ trafficPolicy: AgentVaultTrafficPolicy | `${AgentVaultTrafficPolicy}` | "bundle-hosts"; @@ -540,6 +547,7 @@ export interface UpdateAgentVaultProxyRequest { } export interface ListAgentVaultSessionsRequest { + projectId?: string; scope: AgentVaultSessionScope | `${AgentVaultSessionScope}`; /** Statuses, separated by commas. */ status?: string; @@ -549,6 +557,7 @@ export interface ListAgentVaultSessionsRequest { } export interface CreateAgentVaultSessionRequest { + projectId?: string; accessBundle?: string; services?: AgentVaultInlineServiceInput[]; ttl?: string; @@ -561,6 +570,7 @@ export interface UpdateAgentVaultSessionRequest { } export interface ListAgentVaultAccessBundlesRequest { + projectId?: string; search?: string; requiresSetup?: boolean; granted?: boolean; @@ -573,6 +583,7 @@ export interface ListAgentVaultAccessBundlesRequest { } export interface CreateAgentVaultAccessBundleRequest { + projectId?: string; name: string; description?: string; } @@ -596,6 +607,7 @@ export interface ChangeAgentVaultAccessBundleGrantsRequest { } export interface ListAgentVaultDelegationsRequest { + projectId?: string; /** Machine identity IDs, separated by commas. */ machineIdentityIds?: string; limit: number; @@ -614,6 +626,7 @@ export interface ChangeAgentVaultDelegationSubjectsRequest { } export interface ListAvailableAgentVaultDelegationSubjectsRequest { + projectId?: string; actorType?: AgentVaultMemberType.User | AgentVaultMemberType.Group | "user" | "group"; search?: string; limit: number; @@ -622,7 +635,14 @@ export interface ListAvailableAgentVaultDelegationSubjectsRequest { // Options for the SDK's Agent Vault methods +export type AgentVaultProjectOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; +}; + export type ListAgentVaultProxiesOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** Match proxies by name or description. */ search?: string; /** What to sort proxies by. Defaults to "createdAt". */ @@ -636,6 +656,8 @@ export type ListAgentVaultProxiesOptions = { }; export type CreateAgentVaultProxyOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** The name of the proxy (a slug, at most 64 characters). */ name: string; /** Which hosts an agent may reach through this proxy: "any-host", or "service-hosts" for only the hosts that the session's services cover. Defaults to "any-host". */ @@ -662,6 +684,8 @@ export type UpdateAgentVaultProxyOptions = { }; export type ListAgentVaultSessionsOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** Whose sessions to list: your own ("mine") or everyone's ("all", admins only). Defaults to "mine". */ scope?: AgentVaultSessionScope | `${AgentVaultSessionScope}`; /** Only return sessions with any of these statuses. */ @@ -675,6 +699,8 @@ export type ListAgentVaultSessionsOptions = { }; export type CreateAgentVaultSessionOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** The name of the access bundle the session carries. Pass accessBundle, services, or both. */ accessBundle?: string; /** @@ -700,6 +726,8 @@ export type UpdateAgentVaultSessionOptions = { }; export type ListAgentVaultAccessBundlesOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** Match access bundles by name or description. */ search?: string; /** true lists only the access bundles with services that still need your personal values, and false lists the rest. Defaults to both. */ @@ -721,6 +749,8 @@ export type ListAgentVaultAccessBundlesOptions = { }; export type CreateAgentVaultAccessBundleOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** The name of the access bundle (a slug, at most 64 characters). */ name: string; /** What the access bundle is for, up to 256 characters, without line breaks or other control characters. */ @@ -764,6 +794,8 @@ export type RevokeAgentVaultAccessBundleOptions = { }; export type ListAgentVaultDelegationsOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** Only return the delegations of these machine identities, up to 100. */ machineIdentityIds?: string[]; /** The maximum number of delegations to return (1-100). Defaults to 100. */ @@ -773,6 +805,8 @@ export type ListAgentVaultDelegationsOptions = { }; export type SetAgentVaultDelegationOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** "all-members" for every Agent Vault member, admins included, or "selected" for only the users and groups you name. */ scope: AgentVaultDelegationScope | `${AgentVaultDelegationScope}`; /** With the "selected" scope, the users the machine identity can act on behalf of, up to 100. Each must be a member of Agent Vault. For a user who's in Agent Vault only through a group, name the group instead. */ @@ -782,6 +816,8 @@ export type SetAgentVaultDelegationOptions = { }; export type AddAgentVaultDelegationSubjectsOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** The users to add, up to 100. Each must be a member of Agent Vault. Users the delegation already names are skipped. */ userIds?: string[]; /** The groups to add, up to 100. Each must be a member of Agent Vault. Groups the delegation already names are skipped. */ @@ -789,6 +825,8 @@ export type AddAgentVaultDelegationSubjectsOptions = { }; export type RemoveAgentVaultDelegationSubjectsOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** The users to take out, up to 100. Users the delegation doesn't name are skipped. */ userIds?: string[]; /** The groups to take out, up to 100. Groups the delegation doesn't name are skipped. */ @@ -796,6 +834,8 @@ export type RemoveAgentVaultDelegationSubjectsOptions = { }; export type ListAvailableAgentVaultDelegationSubjectsOptions = { + /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + projectId?: string; /** List only users or only groups. Defaults to both. */ actorType?: AgentVaultMemberType.User | AgentVaultMemberType.Group | "user" | "group"; /** Match users by name, username or email address, and groups by name. */ diff --git a/src/custom/agent-vault.ts b/src/custom/agent-vault.ts index b50faa3..e2c0793 100644 --- a/src/custom/agent-vault.ts +++ b/src/custom/agent-vault.ts @@ -1,6 +1,7 @@ import { AgentVaultApi } from "../api/endpoints/agent-vault"; import { AddAgentVaultDelegationSubjectsOptions, + AgentVaultProjectOptions, AgentVaultInlineService, AgentVaultSessionScope, AgentVaultTrafficPolicy, @@ -85,6 +86,7 @@ export default class AgentVaultClient { list: (options: ListAgentVaultProxiesOptions = {}) => run(async () => { const res = await this.apiClient.proxies.list({ + projectId: options.projectId, search: options.search, orderBy: options.orderBy ?? "createdAt", orderDirection: options.orderDirection ?? "desc", @@ -101,6 +103,7 @@ export default class AgentVaultClient { create: (options: CreateAgentVaultProxyOptions) => run(async () => { const res = await this.apiClient.proxies.create({ + projectId: options.projectId, name: options.name, trafficPolicy: toWireTrafficPolicy(options.trafficPolicy) ?? AgentVaultTrafficPolicy.AnyHost, // An empty value means no allowed hosts, so it's left out. @@ -168,6 +171,7 @@ export default class AgentVaultClient { list: (options: ListAgentVaultSessionsOptions = {}) => run(async () => { const res = await this.apiClient.sessions.list({ + projectId: options.projectId, scope: options.scope ?? AgentVaultSessionScope.Mine, status: joinList(options.statuses), search: options.search, @@ -214,6 +218,7 @@ export default class AgentVaultClient { } const res = await this.apiClient.sessions.create({ + projectId: options.projectId, // Left out without an access bundle, for a session that carries only services of its own. accessBundle: isSet(options.accessBundle) ? options.accessBundle : undefined, services: options.services, @@ -261,6 +266,7 @@ export default class AgentVaultClient { checkOneUser(options.onBehalfOfUserEmail, options.onBehalfOfUserId); return this.apiClient.accessBundles.list({ + projectId: options.projectId, search: options.search, requiresSetup: options.requiresSetup, granted: options.granted, @@ -290,6 +296,7 @@ export default class AgentVaultClient { create: (options: CreateAgentVaultAccessBundleOptions) => run(async () => { const res = await this.apiClient.accessBundles.create({ + projectId: options.projectId, name: options.name, description: options.description }); @@ -388,6 +395,7 @@ export default class AgentVaultClient { list: (options: ListAgentVaultDelegationsOptions = {}) => run(() => this.apiClient.delegations.list({ + projectId: options.projectId, machineIdentityIds: joinList(options.machineIdentityIds), limit: options.limit ?? 100, offset: options.offset ?? 0 @@ -399,9 +407,9 @@ export default class AgentVaultClient { * delegation, throws an InfisicalSDKRequestError whose statusCode is 404. * @returns The delegation, with the access bundles the machine identity can't create sessions with. */ - get: (machineIdentityId: string) => + get: (machineIdentityId: string, options: AgentVaultProjectOptions = {}) => run(async () => { - const res = await this.apiClient.delegations.get(machineIdentityId); + const res = await this.apiClient.delegations.get(machineIdentityId, { projectId: options.projectId }); return res.delegation; }), @@ -412,11 +420,11 @@ export default class AgentVaultClient { */ set: (machineIdentityId: string, options: SetAgentVaultDelegationOptions) => run(async () => { - const res = await this.apiClient.delegations.set(machineIdentityId, { - scope: options.scope, - userIds: options.userIds, - groupIds: options.groupIds - }); + const res = await this.apiClient.delegations.set( + machineIdentityId, + { scope: options.scope, userIds: options.userIds, groupIds: options.groupIds }, + { projectId: options.projectId } + ); return res.delegation; }), @@ -426,9 +434,9 @@ export default class AgentVaultClient { * for good. * @returns The deleted delegation, without missingAccessBundles. */ - delete: (machineIdentityId: string) => + delete: (machineIdentityId: string, options: AgentVaultProjectOptions = {}) => run(async () => { - const res = await this.apiClient.delegations.delete(machineIdentityId); + const res = await this.apiClient.delegations.delete(machineIdentityId, { projectId: options.projectId }); return res.delegation; }), @@ -440,10 +448,11 @@ export default class AgentVaultClient { */ addSubjects: (machineIdentityId: string, options: AddAgentVaultDelegationSubjectsOptions) => run(async () => { - const res = await this.apiClient.delegations.addSubjects(machineIdentityId, { - userIds: options.userIds, - groupIds: options.groupIds - }); + const res = await this.apiClient.delegations.addSubjects( + machineIdentityId, + { userIds: options.userIds, groupIds: options.groupIds }, + { projectId: options.projectId } + ); return res.delegation; }), @@ -455,10 +464,11 @@ export default class AgentVaultClient { */ removeSubjects: (machineIdentityId: string, options: RemoveAgentVaultDelegationSubjectsOptions) => run(async () => { - const res = await this.apiClient.delegations.removeSubjects(machineIdentityId, { - userIds: options.userIds, - groupIds: options.groupIds - }); + const res = await this.apiClient.delegations.removeSubjects( + machineIdentityId, + { userIds: options.userIds, groupIds: options.groupIds }, + { projectId: options.projectId } + ); return res.delegation; }), @@ -470,6 +480,7 @@ export default class AgentVaultClient { listAvailableSubjects: (machineIdentityId: string, options: ListAvailableAgentVaultDelegationSubjectsOptions = {}) => run(() => this.apiClient.delegations.listAvailableSubjects(machineIdentityId, { + projectId: options.projectId, actorType: options.actorType, search: options.search, limit: options.limit ?? 20, From d4aaeed331c25f08fa10211f1476af748a1644ce Mon Sep 17 00:00:00 2001 From: saif <11242541+saifsmailbox98@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:16:02 +0530 Subject: [PATCH 2/6] docs(agent-vault): describe projectId without the fallback --- src/api/types/agent-vault.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/api/types/agent-vault.ts b/src/api/types/agent-vault.ts index 9b5586d..9a9538d 100644 --- a/src/api/types/agent-vault.ts +++ b/src/api/types/agent-vault.ts @@ -636,12 +636,12 @@ export interface ListAvailableAgentVaultDelegationSubjectsRequest { // Options for the SDK's Agent Vault methods export type AgentVaultProjectOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project. */ projectId?: string; }; export type ListAgentVaultProxiesOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project to list proxies from. */ projectId?: string; /** Match proxies by name or description. */ search?: string; @@ -656,7 +656,7 @@ export type ListAgentVaultProxiesOptions = { }; export type CreateAgentVaultProxyOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project to register the proxy in. */ projectId?: string; /** The name of the proxy (a slug, at most 64 characters). */ name: string; @@ -684,7 +684,7 @@ export type UpdateAgentVaultProxyOptions = { }; export type ListAgentVaultSessionsOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project to list sessions from. */ projectId?: string; /** Whose sessions to list: your own ("mine") or everyone's ("all", admins only). Defaults to "mine". */ scope?: AgentVaultSessionScope | `${AgentVaultSessionScope}`; @@ -699,7 +699,7 @@ export type ListAgentVaultSessionsOptions = { }; export type CreateAgentVaultSessionOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project to create the session in. */ projectId?: string; /** The name of the access bundle the session carries. Pass accessBundle, services, or both. */ accessBundle?: string; @@ -726,7 +726,7 @@ export type UpdateAgentVaultSessionOptions = { }; export type ListAgentVaultAccessBundlesOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project to list access bundles from. */ projectId?: string; /** Match access bundles by name or description. */ search?: string; @@ -749,7 +749,7 @@ export type ListAgentVaultAccessBundlesOptions = { }; export type CreateAgentVaultAccessBundleOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project to create the access bundle in. */ projectId?: string; /** The name of the access bundle (a slug, at most 64 characters). */ name: string; @@ -794,7 +794,7 @@ export type RevokeAgentVaultAccessBundleOptions = { }; export type ListAgentVaultDelegationsOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project to list delegations from. */ projectId?: string; /** Only return the delegations of these machine identities, up to 100. */ machineIdentityIds?: string[]; @@ -805,7 +805,7 @@ export type ListAgentVaultDelegationsOptions = { }; export type SetAgentVaultDelegationOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project the delegation belongs to. */ projectId?: string; /** "all-members" for every Agent Vault member, admins included, or "selected" for only the users and groups you name. */ scope: AgentVaultDelegationScope | `${AgentVaultDelegationScope}`; @@ -816,7 +816,7 @@ export type SetAgentVaultDelegationOptions = { }; export type AddAgentVaultDelegationSubjectsOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project the delegation belongs to. */ projectId?: string; /** The users to add, up to 100. Each must be a member of Agent Vault. Users the delegation already names are skipped. */ userIds?: string[]; @@ -825,7 +825,7 @@ export type AddAgentVaultDelegationSubjectsOptions = { }; export type RemoveAgentVaultDelegationSubjectsOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project the delegation belongs to. */ projectId?: string; /** The users to take out, up to 100. Users the delegation doesn't name are skipped. */ userIds?: string[]; @@ -834,7 +834,7 @@ export type RemoveAgentVaultDelegationSubjectsOptions = { }; export type ListAvailableAgentVaultDelegationSubjectsOptions = { - /** The ID of the Agent Vault project. For now, Infisical uses your organization's first Agent Vault project if you leave it out. */ + /** The ID of the Agent Vault project the delegation belongs to. */ projectId?: string; /** List only users or only groups. Defaults to both. */ actorType?: AgentVaultMemberType.User | AgentVaultMemberType.Group | "user" | "group"; From 01a87f487a8d2003177a83d1b3dcad4727de0163 Mon Sep 17 00:00:00 2001 From: saif <11242541+saifsmailbox98@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:43:55 +0530 Subject: [PATCH 3/6] feat(agent-vault)!: require the Agent Vault project --- sink/agent-vault.test.ts | 166 ++++++++++++++++++++++------------- sink/test-agent-vault.ts | 42 +++++---- src/api/types/agent-vault.ts | 42 ++++----- src/custom/agent-vault.ts | 14 +-- 4 files changed, 155 insertions(+), 109 deletions(-) diff --git a/sink/agent-vault.test.ts b/sink/agent-vault.test.ts index 3492414..358be7e 100644 --- a/sink/agent-vault.test.ts +++ b/sink/agent-vault.test.ts @@ -22,6 +22,8 @@ const USER_ID = "0d9a7c3e-5b1f-4e2a-8c6d-7f4b2e1a9c50"; const USER_EMAIL = "jsmith@example.com"; const GROUP_ID = "7b1e4f2a-9c3d-4a6b-8e5f-1d2c3b4a5e6f"; const CREATED_AT = "2026-10-27T00:00:00.000Z"; +const PROJECT_ID = "4d6f8a0c-2e4b-4c6d-8f0a-1b3d5f7a9c2e"; +const PROJECT = { projectId: PROJECT_ID }; const PROXY = { id: PROXY_ID, @@ -159,19 +161,19 @@ const ROUTES: { }[] = [ { name: "proxies.list", - call: (av) => av.proxies.list(), + call: (av) => av.proxies.list(PROJECT), method: "GET", path: "/proxies", - query: { orderBy: "createdAt", orderDirection: "desc", limit: "20", offset: "0" }, + query: { projectId: PROJECT_ID, orderBy: "createdAt", orderDirection: "desc", limit: "20", offset: "0" }, response: { proxies: [PROXY], totalCount: 1 }, returns: (res) => res }, { name: "proxies.create", - call: (av) => av.proxies.create({ name: "edge-proxy" }), + call: (av) => av.proxies.create({ ...PROJECT, name: "edge-proxy" }), method: "POST", path: "/proxies", - body: { name: "edge-proxy", trafficPolicy: "any-host", pollInterval: 60 }, + body: { projectId: PROJECT_ID, name: "edge-proxy", trafficPolicy: "any-host", pollInterval: 60 }, response: { proxy: PROXY, proxyToken: "proxy-token" }, returns: (res) => res }, @@ -210,10 +212,10 @@ const ROUTES: { }, { name: "sessions.list", - call: (av) => av.sessions.list(), + call: (av) => av.sessions.list(PROJECT), method: "GET", path: "/sessions", - query: { scope: "mine", limit: "20", offset: "0" }, + query: { projectId: PROJECT_ID, scope: "mine", limit: "20", offset: "0" }, response: { sessions: [SESSION], totalCount: 1 }, returns: (res) => res }, @@ -227,10 +229,10 @@ const ROUTES: { }, { name: "sessions.create", - call: (av) => av.sessions.create({ accessBundle: "release" }), + call: (av) => av.sessions.create({ ...PROJECT, accessBundle: "release" }), method: "POST", path: "/sessions", - body: { accessBundle: "release" }, + body: { projectId: PROJECT_ID, accessBundle: "release" }, response: { session: CREATED_SESSION }, returns: (res) => res.session }, @@ -253,10 +255,10 @@ const ROUTES: { }, { name: "accessBundles.list", - call: (av) => av.accessBundles.list(), + call: (av) => av.accessBundles.list(PROJECT), method: "GET", path: "/access-bundles", - query: { orderBy: "createdAt", orderDirection: "desc", limit: "20", offset: "0" }, + query: { projectId: PROJECT_ID, orderBy: "createdAt", orderDirection: "desc", limit: "20", offset: "0" }, response: { accessBundles: [ { @@ -281,10 +283,10 @@ const ROUTES: { }, { name: "accessBundles.create", - call: (av) => av.accessBundles.create({ name: "release" }), + call: (av) => av.accessBundles.create({ ...PROJECT, name: "release" }), method: "POST", path: "/access-bundles", - body: { name: "release" }, + body: { projectId: PROJECT_ID, name: "release" }, response: { accessBundle: BUNDLE }, returns: (res) => res.accessBundle }, @@ -343,62 +345,67 @@ const ROUTES: { }, { name: "delegations.list", - call: (av) => av.delegations.list(), + call: (av) => av.delegations.list(PROJECT), method: "GET", path: "/delegations", - query: { limit: "100", offset: "0" }, + query: { projectId: PROJECT_ID, limit: "100", offset: "0" }, response: { delegations: [DELEGATION], totalCount: 1 }, returns: (res) => res }, { name: "delegations.get", - call: (av) => av.delegations.get(MACHINE_IDENTITY_ID), + call: (av) => av.delegations.get(MACHINE_IDENTITY_ID, PROJECT), method: "GET", path: `/delegations/${MACHINE_IDENTITY_ID}`, + query: { projectId: PROJECT_ID }, response: { delegation: DELEGATION_DETAIL }, returns: (res) => res.delegation }, { name: "delegations.set", - call: (av) => av.delegations.set(MACHINE_IDENTITY_ID, { scope: AgentVaultDelegationScope.AllMembers }), + call: (av) => av.delegations.set(MACHINE_IDENTITY_ID, { ...PROJECT, scope: AgentVaultDelegationScope.AllMembers }), method: "PUT", path: `/delegations/${MACHINE_IDENTITY_ID}`, + query: { projectId: PROJECT_ID }, body: { scope: "all-members" }, response: { delegation: { ...DELEGATION_DETAIL, scope: "all-members", users: [], groups: [] } }, returns: (res) => res.delegation }, { name: "delegations.delete", - call: (av) => av.delegations.delete(MACHINE_IDENTITY_ID), + call: (av) => av.delegations.delete(MACHINE_IDENTITY_ID, PROJECT), method: "DELETE", path: `/delegations/${MACHINE_IDENTITY_ID}`, + query: { projectId: PROJECT_ID }, response: { delegation: DELEGATION }, returns: (res) => res.delegation }, { name: "delegations.addSubjects", - call: (av) => av.delegations.addSubjects(MACHINE_IDENTITY_ID, { userIds: [USER_ID] }), + call: (av) => av.delegations.addSubjects(MACHINE_IDENTITY_ID, { ...PROJECT, userIds: [USER_ID] }), method: "POST", path: `/delegations/${MACHINE_IDENTITY_ID}/subjects`, + query: { projectId: PROJECT_ID }, body: { userIds: [USER_ID] }, response: { delegation: DELEGATION_DETAIL }, returns: (res) => res.delegation }, { name: "delegations.removeSubjects", - call: (av) => av.delegations.removeSubjects(MACHINE_IDENTITY_ID, { groupIds: [GROUP_ID] }), + call: (av) => av.delegations.removeSubjects(MACHINE_IDENTITY_ID, { ...PROJECT, groupIds: [GROUP_ID] }), method: "DELETE", path: `/delegations/${MACHINE_IDENTITY_ID}/subjects`, + query: { projectId: PROJECT_ID }, body: { groupIds: [GROUP_ID] }, response: { delegation: { ...DELEGATION_DETAIL, groups: [] } }, returns: (res) => res.delegation }, { name: "delegations.listAvailableSubjects", - call: (av) => av.delegations.listAvailableSubjects(MACHINE_IDENTITY_ID), + call: (av) => av.delegations.listAvailableSubjects(MACHINE_IDENTITY_ID, PROJECT), method: "GET", path: `/delegations/${MACHINE_IDENTITY_ID}/subjects/available`, - query: { limit: "20", offset: "0" }, + query: { projectId: PROJECT_ID, limit: "20", offset: "0" }, response: { members: [AVAILABLE_MEMBER], totalCount: 1 }, returns: (res) => res } @@ -413,10 +420,8 @@ describe("agent vault routes", () => { }); }); -// The ROUTES table above checks that a call without projectId leaves it out, so the server picks the project. describe("agent vault project", () => { - const PROJECT_ID = "4d6f8a0c-2e4b-4c6d-8f0a-1b3d5f7a9c2e"; - const project = { projectId: PROJECT_ID }; + const project = PROJECT; it.each([ { name: "proxies.list", call: (av: AgentVault) => av.proxies.list(project), response: { proxies: [], totalCount: 0 } }, @@ -495,6 +500,39 @@ describe("agent vault project", () => { expect(request.body.projectId).toBe(PROJECT_ID); expect(request.query).toEqual({}); }); + + it("is required by every method that takes it", () => { + // Never called: tsc fails on an unused @ts-expect-error, so each line checks that leaving projectId out doesn't compile. + const withoutProject = (av: AgentVault) => [ + // @ts-expect-error projectId is required + av.proxies.list(), + // @ts-expect-error projectId is required + av.proxies.create({ name: "edge-proxy" }), + // @ts-expect-error projectId is required + av.sessions.list({}), + // @ts-expect-error projectId is required + av.sessions.create({ accessBundle: "release" }), + // @ts-expect-error projectId is required + av.accessBundles.list(), + // @ts-expect-error projectId is required + av.accessBundles.create({ name: "release" }), + // @ts-expect-error projectId is required + av.delegations.list(), + // @ts-expect-error projectId is required + av.delegations.get(MACHINE_IDENTITY_ID), + // @ts-expect-error projectId is required + av.delegations.set(MACHINE_IDENTITY_ID, { scope: "all-members" }), + // @ts-expect-error projectId is required + av.delegations.delete(MACHINE_IDENTITY_ID, {}), + // @ts-expect-error projectId is required + av.delegations.addSubjects(MACHINE_IDENTITY_ID, { userIds: [USER_ID] }), + // @ts-expect-error projectId is required + av.delegations.removeSubjects(MACHINE_IDENTITY_ID, { userIds: [USER_ID] }), + // @ts-expect-error projectId is required + av.delegations.listAvailableSubjects(MACHINE_IDENTITY_ID) + ]; + expect(withoutProject).toBeTypeOf("function"); + }); }); describe("agent vault proxies", () => { @@ -512,7 +550,7 @@ describe("agent vault proxies", () => { it("create sends and returns the description", async () => { respondWith({ proxy: { ...PROXY, description: "Edge traffic" }, proxyToken: "proxy-token" }); - const created = await agentVault.proxies.create({ name: "edge-proxy", description: "Edge traffic" }); + const created = await agentVault.proxies.create({ ...PROJECT, name: "edge-proxy", description: "Edge traffic" }); expect(lastRequest().body.description).toBe("Edge traffic"); expect(created.proxy.description).toBe("Edge traffic"); }); @@ -532,13 +570,14 @@ describe("agent vault proxies", () => { it.each([[[]], [""]])("create leaves out empty allowed hosts when given %j", async (allowedHosts) => { respondWith({ proxy: PROXY, proxyToken: "proxy-token" }); - await agentVault.proxies.create({ name: "edge-proxy", allowedHosts }); + await agentVault.proxies.create({ ...PROJECT, name: "edge-proxy", allowedHosts }); expect(lastRequest().body).not.toHaveProperty("allowedHosts"); }); it("create joins a list of allowed hosts into the comma-separated string the API takes", async () => { respondWith({ proxy: PROXY, proxyToken: "proxy-token" }); await agentVault.proxies.create({ + ...PROJECT, name: "edge-proxy", trafficPolicy: AgentVaultTrafficPolicy.ServiceHosts, allowedHosts: ["api.github.com", "*.slack.com"] @@ -554,7 +593,7 @@ describe("agent vault traffic policy", () => { it.each(hostsOnly)("create sends %s as bundle-hosts, which every Infisical version accepts", async (trafficPolicy) => { respondWith({ proxy: PROXY, proxyToken: "proxy-token" }); - await agentVault.proxies.create({ name: "edge-proxy", trafficPolicy }); + await agentVault.proxies.create({ ...PROJECT, name: "edge-proxy", trafficPolicy }); expect(lastRequest().body.trafficPolicy).toBe("bundle-hosts"); }); @@ -566,7 +605,7 @@ describe("agent vault traffic policy", () => { it("sends any-host as it is", async () => { respondWith({ proxy: PROXY, proxyToken: "proxy-token" }); - await agentVault.proxies.create({ name: "edge-proxy", trafficPolicy: AgentVaultTrafficPolicy.AnyHost }); + await agentVault.proxies.create({ ...PROJECT, name: "edge-proxy", trafficPolicy: AgentVaultTrafficPolicy.AnyHost }); expect(lastRequest().body.trafficPolicy).toBe("any-host"); await agentVault.proxies.update(PROXY_ID, { trafficPolicy: "any-host" }); expect(lastRequest().body).toEqual({ trafficPolicy: "any-host" }); @@ -578,9 +617,9 @@ describe("agent vault traffic policy", () => { const reported: unknown[] = []; respondWith({ proxies: [proxy], totalCount: 1 }); - reported.push((await agentVault.proxies.list()).proxies[0].trafficPolicy); + reported.push((await agentVault.proxies.list(PROJECT)).proxies[0].trafficPolicy); respondWith({ proxy, proxyToken: "proxy-token" }); - reported.push((await agentVault.proxies.create({ name: "edge-proxy" })).proxy.trafficPolicy); + reported.push((await agentVault.proxies.create({ ...PROJECT, name: "edge-proxy" })).proxy.trafficPolicy); respondWith({ proxy }); reported.push((await agentVault.proxies.update(PROXY_ID, { pollInterval: 30 })).trafficPolicy); respondWith({ proxy, proxyToken: "proxy-token" }); @@ -594,7 +633,7 @@ describe("agent vault traffic policy", () => { it("leaves any-host, and a member's proxy without settings, as they are", async () => { const { trafficPolicy, allowedHosts, pollInterval, createdAt, ...memberView } = PROXY; respondWith({ proxies: [PROXY, memberView], totalCount: 2 }); - const { proxies } = await agentVault.proxies.list(); + const { proxies } = await agentVault.proxies.list(PROJECT); expect(proxies).toEqual([PROXY, memberView]); }); }); @@ -602,22 +641,22 @@ describe("agent vault traffic policy", () => { describe("agent vault inline services", () => { it("create sends services without an access bundle", async () => { respondWith({ session: { ...CREATED_SESSION, accessBundle: null, services: [INLINE_SERVICE] } }); - const created = await agentVault.sessions.create({ services: [INLINE_SERVICE_INPUT], ttl: "15m" }); - expect(lastRequest().body).toEqual({ services: [INLINE_SERVICE_INPUT], ttl: "15m" }); + const created = await agentVault.sessions.create({ ...PROJECT, services: [INLINE_SERVICE_INPUT], ttl: "15m" }); + expect(lastRequest().body).toEqual({ projectId: PROJECT_ID, services: [INLINE_SERVICE_INPUT], ttl: "15m" }); expect(created.services).toEqual([INLINE_SERVICE]); expect(created.accessBundle).toBeNull(); }); it("create sends an access bundle and services together", async () => { respondWith({ session: { ...CREATED_SESSION, services: [INLINE_SERVICE] } }); - await agentVault.sessions.create({ accessBundle: "release", services: [INLINE_SERVICE_INPUT] }); - expect(lastRequest().body).toEqual({ accessBundle: "release", services: [INLINE_SERVICE_INPUT] }); + await agentVault.sessions.create({ ...PROJECT, accessBundle: "release", services: [INLINE_SERVICE_INPUT] }); + expect(lastRequest().body).toEqual({ projectId: PROJECT_ID, accessBundle: "release", services: [INLINE_SERVICE_INPUT] }); }); it("create sends an empty access bundle name, so the server rejects it instead of dropping it", async () => { respondWith({ session: CREATED_SESSION }); - await agentVault.sessions.create({ accessBundle: "" }); - expect(lastRequest().body).toEqual({ accessBundle: "" }); + await agentVault.sessions.create({ ...PROJECT, accessBundle: "" }); + expect(lastRequest().body).toEqual({ projectId: PROJECT_ID, accessBundle: "" }); }); it("returns a session's services as the API sends them", async () => { @@ -643,7 +682,7 @@ describe("agent vault inline services", () => { }, 422 ); - await expect(agentVault.sessions.create({ services: [INLINE_SERVICE_INPUT] })).rejects.toThrow( + await expect(agentVault.sessions.create({ ...PROJECT, services: [INLINE_SERVICE_INPUT] })).rejects.toThrow( /\[StatusCode=422\].*at most 20 services/ ); }); @@ -657,7 +696,7 @@ describe("agent vault inline services", () => { }, 403 ); - await expect(agentVault.sessions.create({ services: [INLINE_SERVICE_INPUT] })).rejects.toThrow( + await expect(agentVault.sessions.create({ ...PROJECT, services: [INLINE_SERVICE_INPUT] })).rejects.toThrow( /\[StatusCode=403\] Only an Agent Vault admin can send services with a session/ ); }); @@ -668,13 +707,13 @@ describe("agent vault inline services", () => { const { services: createdServices, ...olderCreated } = CREATED_SESSION; respondWith({ sessions: [olderSession], totalCount: 1 }); - expect((await agentVault.sessions.list()).sessions[0].services).toEqual([]); + expect((await agentVault.sessions.list(PROJECT)).sessions[0].services).toEqual([]); respondWith({ session: olderSession }); expect((await agentVault.sessions.get(SESSION_ID)).services).toEqual([]); respondWith({ session: olderSession }); expect((await agentVault.sessions.update(SESSION_ID, { label: null })).services).toEqual([]); respondWith({ session: olderCreated }); - expect((await agentVault.sessions.create({ accessBundle: "release" })).services).toEqual([]); + expect((await agentVault.sessions.create({ ...PROJECT, accessBundle: "release" })).services).toEqual([]); }); }); @@ -689,8 +728,8 @@ describe("agent vault sessions", () => { it("create sends one access bundle and reads it back", async () => { respondWith({ session: CREATED_SESSION }); - const created = await agentVault.sessions.create({ accessBundle: "release", ttl: "1h" }); - expect(lastRequest().body).toEqual({ accessBundle: "release", ttl: "1h" }); + const created = await agentVault.sessions.create({ ...PROJECT, accessBundle: "release", ttl: "1h" }); + expect(lastRequest().body).toEqual({ projectId: PROJECT_ID, accessBundle: "release", ttl: "1h" }); expect(created.accessBundle).toEqual({ id: BUNDLE_ID, name: "release" }); }); @@ -703,8 +742,8 @@ describe("agent vault sessions", () => { it("create leaves out ttl so the server picks the default", async () => { respondWith({ session: CREATED_SESSION }); - await agentVault.sessions.create({ accessBundle: "release" }); - expect(lastRequest().body).toEqual({ accessBundle: "release" }); + await agentVault.sessions.create({ ...PROJECT, accessBundle: "release" }); + expect(lastRequest().body).toEqual({ projectId: PROJECT_ID, accessBundle: "release" }); }); it.each([ @@ -713,12 +752,13 @@ describe("agent vault sessions", () => { { name: "empty email", options: { onBehalfOfUserEmail: "" }, onBehalfOf: { userEmail: "" } } ])("create names the user it acts for by $name", async ({ options, onBehalfOf }) => { respondWith({ session: CREATED_SESSION }); - await agentVault.sessions.create({ accessBundle: "release", ...options }); - expect(lastRequest().body).toEqual({ accessBundle: "release", onBehalfOf }); + await agentVault.sessions.create({ ...PROJECT, accessBundle: "release", ...options }); + expect(lastRequest().body).toEqual({ projectId: PROJECT_ID, accessBundle: "release", onBehalfOf }); }); it("create rejects both a user email and a user ID before sending a request", async () => { const created = agentVault.sessions.create({ + ...PROJECT, accessBundle: "release", onBehalfOfUserEmail: USER_EMAIL, onBehalfOfUserId: USER_ID @@ -731,6 +771,7 @@ describe("agent vault sessions", () => { it("list takes enum values or their strings, and joins the statuses", async () => { respondWith({ sessions: [], totalCount: 0 }); await agentVault.sessions.list({ + ...PROJECT, scope: AgentVaultSessionScope.All, statuses: [AgentVaultSessionStatus.Active, "expired"] }); @@ -741,20 +782,20 @@ describe("agent vault sessions", () => { describe("agent vault access bundles", () => { it("list sends booleans the way the API reads them", async () => { respondWith({ accessBundles: [], totalCount: 0 }); - await agentVault.accessBundles.list({ requiresSetup: true, granted: false }); + await agentVault.accessBundles.list({ ...PROJECT, requiresSetup: true, granted: false }); expect(lastRequest().query).toMatchObject({ requiresSetup: "true", granted: "false" }); }); it("list names the user a session would act for", async () => { respondWith({ accessBundles: [], totalCount: 0 }); - await agentVault.accessBundles.list({ onBehalfOfUserEmail: USER_EMAIL }); + await agentVault.accessBundles.list({ ...PROJECT, onBehalfOfUserEmail: USER_EMAIL }); const { query } = lastRequest(); expect(query.onBehalfOfUserEmail).toBe(USER_EMAIL); expect(query).not.toHaveProperty("onBehalfOfUserId"); }); it("list rejects both a user email and a user ID before sending a request", async () => { - const listed = agentVault.accessBundles.list({ onBehalfOfUserEmail: USER_EMAIL, onBehalfOfUserId: USER_ID }); + const listed = agentVault.accessBundles.list({ ...PROJECT, onBehalfOfUserEmail: USER_EMAIL, onBehalfOfUserId: USER_ID }); await expect(listed).rejects.toThrow("not both"); expect(fetchSpy).not.toHaveBeenCalled(); }); @@ -789,6 +830,7 @@ describe("agent vault delegations", () => { it("set puts the scope value", async () => { respondWith({ delegation: DELEGATION_DETAIL }); await agentVault.delegations.set(MACHINE_IDENTITY_ID, { + ...PROJECT, scope: AgentVaultDelegationScope.Selected, groupIds: [GROUP_ID] }); @@ -797,20 +839,20 @@ describe("agent vault delegations", () => { it("list joins the machine identity IDs", async () => { respondWith({ delegations: [DELEGATION], totalCount: 1 }); - await agentVault.delegations.list({ machineIdentityIds: [MACHINE_IDENTITY_ID, OTHER_MACHINE_IDENTITY_ID] }); + await agentVault.delegations.list({ ...PROJECT, machineIdentityIds: [MACHINE_IDENTITY_ID, OTHER_MACHINE_IDENTITY_ID] }); expect(lastRequest().query.machineIdentityIds).toBe(`${MACHINE_IDENTITY_ID},${OTHER_MACHINE_IDENTITY_ID}`); }); it("removeSubjects returns null once the last one is gone", async () => { respondWith({ delegation: null }); - const delegation = await agentVault.delegations.removeSubjects(MACHINE_IDENTITY_ID, { userIds: [USER_ID] }); + const delegation = await agentVault.delegations.removeSubjects(MACHINE_IDENTITY_ID, { ...PROJECT, userIds: [USER_ID] }); expect(delegation).toBeNull(); expect(lastRequest().body).toEqual({ userIds: [USER_ID] }); }); it("listAvailableSubjects sends the actor type value", async () => { respondWith({ members: [], totalCount: 0 }); - await agentVault.delegations.listAvailableSubjects(MACHINE_IDENTITY_ID, { actorType: AgentVaultMemberType.Group }); + await agentVault.delegations.listAvailableSubjects(MACHINE_IDENTITY_ID, { ...PROJECT, actorType: AgentVaultMemberType.Group }); expect(lastRequest().query.actorType).toBe("group"); }); }); @@ -820,20 +862,20 @@ describe("agent vault retries", () => { const timeoutError = () => new DOMException("The request timed out after 10 seconds", "TimeoutError"); it.each([ - { name: "proxies.create", call: (av: AgentVault) => av.proxies.create({ name: "edge-proxy" }) }, + { name: "proxies.create", call: (av: AgentVault) => av.proxies.create({ ...PROJECT, name: "edge-proxy" }) }, { name: "proxies.rotateToken", call: (av: AgentVault) => av.proxies.rotateToken(PROXY_ID) }, - { name: "sessions.create", call: (av: AgentVault) => av.sessions.create({ accessBundle: "release" }) }, - { name: "accessBundles.create", call: (av: AgentVault) => av.accessBundles.create({ name: "release" }) }, + { name: "sessions.create", call: (av: AgentVault) => av.sessions.create({ ...PROJECT, accessBundle: "release" }) }, + { name: "accessBundles.create", call: (av: AgentVault) => av.accessBundles.create({ ...PROJECT, name: "release" }) }, // A retry after a lost response would report every grantee as skipped. { name: "accessBundles.grant", call: (av: AgentVault) => av.accessBundles.grant(BUNDLE_ID, { userIds: [USER_ID] }) }, { name: "accessBundles.revoke", call: (av: AgentVault) => av.accessBundles.revoke(BUNDLE_ID, { userIds: [USER_ID] }) }, // A retry after a lost response would fail with a 404 for a delete that worked. { name: "proxies.delete", call: (av: AgentVault) => av.proxies.delete(PROXY_ID) }, { name: "accessBundles.delete", call: (av: AgentVault) => av.accessBundles.delete(BUNDLE_ID) }, - { name: "delegations.delete", call: (av: AgentVault) => av.delegations.delete(MACHINE_IDENTITY_ID) }, + { name: "delegations.delete", call: (av: AgentVault) => av.delegations.delete(MACHINE_IDENTITY_ID, PROJECT) }, { name: "delegations.removeSubjects", - call: (av: AgentVault) => av.delegations.removeSubjects(MACHINE_IDENTITY_ID, { userIds: [USER_ID] }) + call: (av: AgentVault) => av.delegations.removeSubjects(MACHINE_IDENTITY_ID, { ...PROJECT, userIds: [USER_ID] }) } ])("$name isn't retried once the request may have reached the server", async ({ call }) => { vi.useFakeTimers(); @@ -881,7 +923,7 @@ describe("agent vault IDs", () => { describe("agent vault errors", () => { it("throws an InfisicalSDKRequestError, exported from the package root, with the status code", async () => { respondWith({ statusCode: 404, message: "This machine identity has no delegation", error: "NotFound" }, 404); - const error = await agentVault.delegations.get(MACHINE_IDENTITY_ID).catch((err: unknown) => err); + const error = await agentVault.delegations.get(MACHINE_IDENTITY_ID, PROJECT).catch((err: unknown) => err); expect(error).toBeInstanceOf(InfisicalSDKRequestError); expect((error as InfisicalSDKRequestError).statusCode).toBe(404); expect((error as Error).message).toMatch(/\[StatusCode=404\] This machine identity has no delegation$/); @@ -895,7 +937,7 @@ describe("agent vault errors", () => { new Promise((_resolve, reject) => init.signal!.addEventListener("abort", () => reject(init.signal!.reason))) ); - const error = agentVault.sessions.create({ accessBundle: "release" }).catch((err: unknown) => err); + const error = agentVault.sessions.create({ ...PROJECT, accessBundle: "release" }).catch((err: unknown) => err); await vi.advanceTimersByTimeAsync(10_000); const thrown = (await error) as InfisicalSDKError; @@ -909,7 +951,7 @@ describe("agent vault errors", () => { const reset = new TypeError("fetch failed", { cause: Object.assign(new Error("ECONNRESET"), { code: "ECONNRESET" }) }); fetchSpy.mockRejectedValue(reset); - const thrown = (await agentVault.sessions.create({ accessBundle: "release" }).catch((err: unknown) => err)) as Error; + const thrown = (await agentVault.sessions.create({ ...PROJECT, accessBundle: "release" }).catch((err: unknown) => err)) as Error; expect(thrown).toBeInstanceOf(InfisicalSDKError); expect(thrown.message).toBe("fetch failed"); @@ -932,7 +974,7 @@ describe("agent vault errors", () => { it("throws an error the SDK raised itself as it is, without wrapping it", async () => { const error = await agentVault.accessBundles - .list({ onBehalfOfUserEmail: USER_EMAIL, onBehalfOfUserId: USER_ID }) + .list({ ...PROJECT, onBehalfOfUserEmail: USER_EMAIL, onBehalfOfUserId: USER_ID }) .catch((err: unknown) => err); expect(error).toBeInstanceOf(InfisicalSDKError); expect((error as Error).cause).toBeUndefined(); diff --git a/sink/test-agent-vault.ts b/sink/test-agent-vault.ts index afb6a82..3c7e78c 100644 --- a/sink/test-agent-vault.ts +++ b/sink/test-agent-vault.ts @@ -8,6 +8,7 @@ // - AGENT_CLIENT_ID / AGENT_CLIENT_SECRET / AGENT_MACHINE_IDENTITY_ID: a machine identity that's a member of // Agent Vault and has no delegation yet. delegations.set replaces a delegation, so the script stops if it has one. // - USER_ID / USER_EMAIL: a user who's a member of Agent Vault directly, not only through a group. +// - PROJECT_ID: the ID of the Agent Vault project that the machine identities and the user are members of. // - SITE_URL: optional, defaults to http://localhost:8080. // // It only deletes what it creates: a proxy, an access bundle (with its grants) and the agent's delegation, and it @@ -49,6 +50,7 @@ const expectRejection = async (label: string, run: () => Promise, patte (async () => { const siteUrl = process.env.SITE_URL || "http://localhost:8080"; + const project = { projectId: env("PROJECT_ID") }; const agentId = env("AGENT_MACHINE_IDENTITY_ID"); const userId = env("USER_ID"); const userEmail = env("USER_EMAIL"); @@ -74,7 +76,7 @@ const expectRejection = async (label: string, run: () => Promise, patte try { // delegations.set replaces a delegation, so the script must not run against one someone set up. - const existing = await adminVault.delegations.get(agentId).catch((err: Error) => { + const existing = await adminVault.delegations.get(agentId, project).catch((err: Error) => { if (err instanceof InfisicalSDKRequestError && err.statusCode === 404) return null; throw err; }); @@ -88,6 +90,7 @@ const expectRejection = async (label: string, run: () => Promise, patte "proxies.create", async () => { const res = await adminVault.proxies.create({ + ...project, name: `sdk-check-${suffix}`, description: "Node SDK check", trafficPolicy: AgentVaultTrafficPolicy.ServiceHosts, @@ -104,7 +107,7 @@ const expectRejection = async (label: string, run: () => Promise, patte : `got ${JSON.stringify(res.proxy)}` ); const proxy = created.proxy; - await step("proxies.list by description", () => adminVault.proxies.list({ search: "Node SDK check" }), (res) => + await step("proxies.list by description", () => adminVault.proxies.list({ ...project, search: "Node SDK check" }), (res) => res.proxies.some((listed) => listed.id === proxy.id) ? undefined : "proxy not listed" ); await step("proxies.update removes the description and allowed hosts", () => @@ -127,7 +130,7 @@ const expectRejection = async (label: string, run: () => Promise, patte console.log("\n== access bundles =="); const bundle = await step("accessBundles.create", async () => { - const res = await adminVault.accessBundles.create({ name: `sdk-check-${suffix}`, description: "Node SDK check" }); + const res = await adminVault.accessBundles.create({ ...project, name: `sdk-check-${suffix}`, description: "Node SDK check" }); bundleId = res.id; return res; }); @@ -137,7 +140,7 @@ const expectRejection = async (label: string, run: () => Promise, patte await step("accessBundles.update removes the description", () => adminVault.accessBundles.update(bundle.id, { description: "" }), (res) => res.description === null ? undefined : `description is ${JSON.stringify(res.description)}` ); - await step("accessBundles.list", () => adminVault.accessBundles.list({ search: bundle.name }), (res) => + await step("accessBundles.list", () => adminVault.accessBundles.list({ ...project, search: bundle.name }), (res) => res.accessBundles.some((listed) => listed.id === bundle.id) ? undefined : "bundle not listed" ); await step("accessBundles.listAvailableGrantees", () => adminVault.accessBundles.listAvailableGrantees(bundle.id)); @@ -155,41 +158,41 @@ const expectRejection = async (label: string, run: () => Promise, patte console.log("\n== delegations =="); await step("delegations.listAvailableSubjects (users)", () => - adminVault.delegations.listAvailableSubjects(agentId, { actorType: AgentVaultMemberType.User, search: userEmail }), + adminVault.delegations.listAvailableSubjects(agentId, { ...project, actorType: AgentVaultMemberType.User, search: userEmail }), (res) => (res.members.some((member) => member.id === userId) ? undefined : "user isn't available") ); await step( "delegations.set", async () => { - const delegation = await adminVault.delegations.set(agentId, { scope: AgentVaultDelegationScope.Selected, userIds: [userId] }); + const delegation = await adminVault.delegations.set(agentId, { ...project, scope: AgentVaultDelegationScope.Selected, userIds: [userId] }); delegationSet = true; return delegation; }, (delegation) => (delegation.users.some((user) => user.id === userId) ? undefined : `got ${JSON.stringify(delegation)}`) ); - await step("delegations.get", () => adminVault.delegations.get(agentId), (delegation) => + await step("delegations.get", () => adminVault.delegations.get(agentId, project), (delegation) => Array.isArray(delegation.missingAccessBundles) ? undefined : "no missingAccessBundles" ); - await step("delegations.list for the agent", () => adminVault.delegations.list({ machineIdentityIds: [agentId] }), (res) => + await step("delegations.list for the agent", () => adminVault.delegations.list({ ...project, machineIdentityIds: [agentId] }), (res) => res.delegations.length === 1 ? undefined : `got ${res.delegations.length} delegations` ); await step("delegations.addSubjects skips a user it already names", () => - adminVault.delegations.addSubjects(agentId, { userIds: [userId] }), + adminVault.delegations.addSubjects(agentId, { ...project, userIds: [userId] }), (delegation) => (delegation.users.length === 1 ? undefined : `got ${delegation.users.length} users`) ); console.log("\n== sessions on behalf of the user =="); - await step("accessBundles.list on behalf of the user", () => agentVault.accessBundles.list({ onBehalfOfUserEmail: userEmail }), (res) => + await step("accessBundles.list on behalf of the user", () => agentVault.accessBundles.list({ ...project, onBehalfOfUserEmail: userEmail }), (res) => res.accessBundles.some((listed) => listed.id === bundle.id) ? undefined : "bundle not listed for the user" ); await expectRejection("sessions.create with both an email and an ID", () => - agentVault.sessions.create({ accessBundle: bundle.name, onBehalfOfUserEmail: userEmail, onBehalfOfUserId: userId }), + agentVault.sessions.create({ ...project, accessBundle: bundle.name, onBehalfOfUserEmail: userEmail, onBehalfOfUserId: userId }), /not both/ ); const session = await step( "sessions.create on behalf of the user", async () => { - const res = await agentVault.sessions.create({ accessBundle: bundle.name, onBehalfOfUserEmail: userEmail, label: "node sdk check" }); + const res = await agentVault.sessions.create({ ...project, accessBundle: bundle.name, onBehalfOfUserEmail: userEmail, label: "node sdk check" }); openSessionIds.add(res.id); return res; }, @@ -201,7 +204,7 @@ const expectRejection = async (label: string, run: () => Promise, patte await step("sessions.get names the user", () => agentVault.sessions.get(session.id), (res) => res.onBehalfOf?.id === userId ? undefined : `onBehalfOf is ${JSON.stringify(res.onBehalfOf)}` ); - await step("sessions.list by the user's email", () => agentVault.sessions.list({ search: userEmail }), (res) => + await step("sessions.list by the user's email", () => agentVault.sessions.list({ ...project, search: userEmail }), (res) => res.sessions.some((listed) => listed.id === session.id) ? undefined : "session not listed" ); await step("sessions.update removes the label", () => agentVault.sessions.update(session.id, { label: null }), (res) => @@ -232,7 +235,7 @@ const expectRejection = async (label: string, run: () => Promise, patte const inline = await step( "sessions.create with only inline services, as the admin", async () => { - const res = await adminVault.sessions.create({ services: [inlineService], ttl: "15m", label: "node sdk inline check" }); + const res = await adminVault.sessions.create({ ...project, services: [inlineService], ttl: "15m", label: "node sdk inline check" }); openSessionIds.add(res.id); return res; }, @@ -254,6 +257,7 @@ const expectRejection = async (label: string, run: () => Promise, patte "sessions.create with an access bundle and inline services, as the admin", async () => { const res = await adminVault.sessions.create({ + ...project, accessBundle: bundle.name, services: [{ ...inlineService, name: "httpbin-eu", hostPattern: "eu.httpbin.org" }], ttl: "15m" @@ -268,7 +272,7 @@ const expectRejection = async (label: string, run: () => Promise, patte "sessions.create with inline services as a member is refused", async () => { try { - const res = await agentVault.sessions.create({ services: [inlineService], ttl: "15m" }); + const res = await agentVault.sessions.create({ ...project, services: [inlineService], ttl: "15m" }); openSessionIds.add(res.id); return "the session was created"; } catch (err) { @@ -293,7 +297,7 @@ const expectRejection = async (label: string, run: () => Promise, patte await step( "delegations.removeSubjects of the last user returns null", async () => { - const delegation = await adminVault.delegations.removeSubjects(agentId, { userIds: [userId] }); + const delegation = await adminVault.delegations.removeSubjects(agentId, { ...project, userIds: [userId] }); if (delegation === null) delegationSet = false; return delegation; }, @@ -302,14 +306,14 @@ const expectRejection = async (label: string, run: () => Promise, patte await step( "delegations.addSubjects creates a delegation", async () => { - const delegation = await adminVault.delegations.addSubjects(agentId, { userIds: [userId] }); + const delegation = await adminVault.delegations.addSubjects(agentId, { ...project, userIds: [userId] }); delegationSet = true; return delegation; }, (delegation) => (delegation.scope === AgentVaultDelegationScope.Selected ? undefined : `scope is ${delegation.scope}`) ); await step("delegations.delete", async () => { - const deleted = await adminVault.delegations.delete(agentId); + const deleted = await adminVault.delegations.delete(agentId, project); delegationSet = false; return deleted; }); @@ -333,7 +337,7 @@ const expectRejection = async (label: string, run: () => Promise, patte const leftProxy = proxyId; // The admin can revoke every session, including the agent's. for (const id of openSessionIds) leftovers.push([`revoke session ${id}`, () => adminVault.sessions.revoke(id)]); - if (delegationSet) leftovers.push([`delete the delegation of machine identity ${agentId}`, () => adminVault.delegations.delete(agentId)]); + if (delegationSet) leftovers.push([`delete the delegation of machine identity ${agentId}`, () => adminVault.delegations.delete(agentId, project)]); if (leftBundle) leftovers.push([`delete access bundle ${leftBundle}`, () => adminVault.accessBundles.delete(leftBundle)]); if (leftProxy) leftovers.push([`delete proxy ${leftProxy}`, () => adminVault.proxies.delete(leftProxy)]); diff --git a/src/api/types/agent-vault.ts b/src/api/types/agent-vault.ts index 9a9538d..02185dd 100644 --- a/src/api/types/agent-vault.ts +++ b/src/api/types/agent-vault.ts @@ -514,11 +514,11 @@ export interface RemoveAgentVaultDelegationSubjectsResponse { /** The query string of a delegation route, which names the project because a machine identity can be in several. */ export interface AgentVaultProjectQuery { - projectId?: string; + projectId: string; } export interface ListAgentVaultProxiesRequest { - projectId?: string; + projectId: string; search?: string; orderBy: "name" | "createdAt"; orderDirection: AgentVaultOrderDirection; @@ -527,7 +527,7 @@ export interface ListAgentVaultProxiesRequest { } export interface CreateAgentVaultProxyRequest { - projectId?: string; + projectId: string; name: string; /** "bundle-hosts" is the old name of "service-hosts", and the only one an Infisical version from before the rename accepts. */ trafficPolicy: AgentVaultTrafficPolicy | `${AgentVaultTrafficPolicy}` | "bundle-hosts"; @@ -547,7 +547,7 @@ export interface UpdateAgentVaultProxyRequest { } export interface ListAgentVaultSessionsRequest { - projectId?: string; + projectId: string; scope: AgentVaultSessionScope | `${AgentVaultSessionScope}`; /** Statuses, separated by commas. */ status?: string; @@ -557,7 +557,7 @@ export interface ListAgentVaultSessionsRequest { } export interface CreateAgentVaultSessionRequest { - projectId?: string; + projectId: string; accessBundle?: string; services?: AgentVaultInlineServiceInput[]; ttl?: string; @@ -570,7 +570,7 @@ export interface UpdateAgentVaultSessionRequest { } export interface ListAgentVaultAccessBundlesRequest { - projectId?: string; + projectId: string; search?: string; requiresSetup?: boolean; granted?: boolean; @@ -583,7 +583,7 @@ export interface ListAgentVaultAccessBundlesRequest { } export interface CreateAgentVaultAccessBundleRequest { - projectId?: string; + projectId: string; name: string; description?: string; } @@ -607,7 +607,7 @@ export interface ChangeAgentVaultAccessBundleGrantsRequest { } export interface ListAgentVaultDelegationsRequest { - projectId?: string; + projectId: string; /** Machine identity IDs, separated by commas. */ machineIdentityIds?: string; limit: number; @@ -626,7 +626,7 @@ export interface ChangeAgentVaultDelegationSubjectsRequest { } export interface ListAvailableAgentVaultDelegationSubjectsRequest { - projectId?: string; + projectId: string; actorType?: AgentVaultMemberType.User | AgentVaultMemberType.Group | "user" | "group"; search?: string; limit: number; @@ -637,12 +637,12 @@ export interface ListAvailableAgentVaultDelegationSubjectsRequest { export type AgentVaultProjectOptions = { /** The ID of the Agent Vault project. */ - projectId?: string; + projectId: string; }; export type ListAgentVaultProxiesOptions = { /** The ID of the Agent Vault project to list proxies from. */ - projectId?: string; + projectId: string; /** Match proxies by name or description. */ search?: string; /** What to sort proxies by. Defaults to "createdAt". */ @@ -657,7 +657,7 @@ export type ListAgentVaultProxiesOptions = { export type CreateAgentVaultProxyOptions = { /** The ID of the Agent Vault project to register the proxy in. */ - projectId?: string; + projectId: string; /** The name of the proxy (a slug, at most 64 characters). */ name: string; /** Which hosts an agent may reach through this proxy: "any-host", or "service-hosts" for only the hosts that the session's services cover. Defaults to "any-host". */ @@ -685,7 +685,7 @@ export type UpdateAgentVaultProxyOptions = { export type ListAgentVaultSessionsOptions = { /** The ID of the Agent Vault project to list sessions from. */ - projectId?: string; + projectId: string; /** Whose sessions to list: your own ("mine") or everyone's ("all", admins only). Defaults to "mine". */ scope?: AgentVaultSessionScope | `${AgentVaultSessionScope}`; /** Only return sessions with any of these statuses. */ @@ -700,7 +700,7 @@ export type ListAgentVaultSessionsOptions = { export type CreateAgentVaultSessionOptions = { /** The ID of the Agent Vault project to create the session in. */ - projectId?: string; + projectId: string; /** The name of the access bundle the session carries. Pass accessBundle, services, or both. */ accessBundle?: string; /** @@ -727,7 +727,7 @@ export type UpdateAgentVaultSessionOptions = { export type ListAgentVaultAccessBundlesOptions = { /** The ID of the Agent Vault project to list access bundles from. */ - projectId?: string; + projectId: string; /** Match access bundles by name or description. */ search?: string; /** true lists only the access bundles with services that still need your personal values, and false lists the rest. Defaults to both. */ @@ -750,7 +750,7 @@ export type ListAgentVaultAccessBundlesOptions = { export type CreateAgentVaultAccessBundleOptions = { /** The ID of the Agent Vault project to create the access bundle in. */ - projectId?: string; + projectId: string; /** The name of the access bundle (a slug, at most 64 characters). */ name: string; /** What the access bundle is for, up to 256 characters, without line breaks or other control characters. */ @@ -795,7 +795,7 @@ export type RevokeAgentVaultAccessBundleOptions = { export type ListAgentVaultDelegationsOptions = { /** The ID of the Agent Vault project to list delegations from. */ - projectId?: string; + projectId: string; /** Only return the delegations of these machine identities, up to 100. */ machineIdentityIds?: string[]; /** The maximum number of delegations to return (1-100). Defaults to 100. */ @@ -806,7 +806,7 @@ export type ListAgentVaultDelegationsOptions = { export type SetAgentVaultDelegationOptions = { /** The ID of the Agent Vault project the delegation belongs to. */ - projectId?: string; + projectId: string; /** "all-members" for every Agent Vault member, admins included, or "selected" for only the users and groups you name. */ scope: AgentVaultDelegationScope | `${AgentVaultDelegationScope}`; /** With the "selected" scope, the users the machine identity can act on behalf of, up to 100. Each must be a member of Agent Vault. For a user who's in Agent Vault only through a group, name the group instead. */ @@ -817,7 +817,7 @@ export type SetAgentVaultDelegationOptions = { export type AddAgentVaultDelegationSubjectsOptions = { /** The ID of the Agent Vault project the delegation belongs to. */ - projectId?: string; + projectId: string; /** The users to add, up to 100. Each must be a member of Agent Vault. Users the delegation already names are skipped. */ userIds?: string[]; /** The groups to add, up to 100. Each must be a member of Agent Vault. Groups the delegation already names are skipped. */ @@ -826,7 +826,7 @@ export type AddAgentVaultDelegationSubjectsOptions = { export type RemoveAgentVaultDelegationSubjectsOptions = { /** The ID of the Agent Vault project the delegation belongs to. */ - projectId?: string; + projectId: string; /** The users to take out, up to 100. Users the delegation doesn't name are skipped. */ userIds?: string[]; /** The groups to take out, up to 100. Groups the delegation doesn't name are skipped. */ @@ -835,7 +835,7 @@ export type RemoveAgentVaultDelegationSubjectsOptions = { export type ListAvailableAgentVaultDelegationSubjectsOptions = { /** The ID of the Agent Vault project the delegation belongs to. */ - projectId?: string; + projectId: string; /** List only users or only groups. Defaults to both. */ actorType?: AgentVaultMemberType.User | AgentVaultMemberType.Group | "user" | "group"; /** Match users by name, username or email address, and groups by name. */ diff --git a/src/custom/agent-vault.ts b/src/custom/agent-vault.ts index e2c0793..b9ca1a1 100644 --- a/src/custom/agent-vault.ts +++ b/src/custom/agent-vault.ts @@ -83,7 +83,7 @@ export default class AgentVaultClient { * Lists the organization's Agent Vault proxies. * @returns The proxies and totalCount. A proxy's settings are only set for admins. */ - list: (options: ListAgentVaultProxiesOptions = {}) => + list: (options: ListAgentVaultProxiesOptions) => run(async () => { const res = await this.apiClient.proxies.list({ projectId: options.projectId, @@ -168,7 +168,7 @@ export default class AgentVaultClient { * Lists Agent Vault sessions. * @returns The sessions and totalCount. */ - list: (options: ListAgentVaultSessionsOptions = {}) => + list: (options: ListAgentVaultSessionsOptions) => run(async () => { const res = await this.apiClient.sessions.list({ projectId: options.projectId, @@ -261,7 +261,7 @@ export default class AgentVaultClient { * Lists the Agent Vault access bundles you can reach. Admins reach every access bundle. * @returns The access bundles and totalCount. */ - list: (options: ListAgentVaultAccessBundlesOptions = {}) => + list: (options: ListAgentVaultAccessBundlesOptions) => run(() => { checkOneUser(options.onBehalfOfUserEmail, options.onBehalfOfUserId); @@ -392,7 +392,7 @@ export default class AgentVaultClient { * Lists the machine identities that can create Agent Vault sessions on behalf of users. * @returns The delegations and totalCount. A listed delegation has no missingAccessBundles; call get for them. */ - list: (options: ListAgentVaultDelegationsOptions = {}) => + list: (options: ListAgentVaultDelegationsOptions) => run(() => this.apiClient.delegations.list({ projectId: options.projectId, @@ -407,7 +407,7 @@ export default class AgentVaultClient { * delegation, throws an InfisicalSDKRequestError whose statusCode is 404. * @returns The delegation, with the access bundles the machine identity can't create sessions with. */ - get: (machineIdentityId: string, options: AgentVaultProjectOptions = {}) => + get: (machineIdentityId: string, options: AgentVaultProjectOptions) => run(async () => { const res = await this.apiClient.delegations.get(machineIdentityId, { projectId: options.projectId }); return res.delegation; @@ -434,7 +434,7 @@ export default class AgentVaultClient { * for good. * @returns The deleted delegation, without missingAccessBundles. */ - delete: (machineIdentityId: string, options: AgentVaultProjectOptions = {}) => + delete: (machineIdentityId: string, options: AgentVaultProjectOptions) => run(async () => { const res = await this.apiClient.delegations.delete(machineIdentityId, { projectId: options.projectId }); return res.delegation; @@ -477,7 +477,7 @@ export default class AgentVaultClient { * identity must be a member of Agent Vault. * @returns The users and groups in members, and totalCount. */ - listAvailableSubjects: (machineIdentityId: string, options: ListAvailableAgentVaultDelegationSubjectsOptions = {}) => + listAvailableSubjects: (machineIdentityId: string, options: ListAvailableAgentVaultDelegationSubjectsOptions) => run(() => this.apiClient.delegations.listAvailableSubjects(machineIdentityId, { projectId: options.projectId, From c6e6b6ce712afdc635433362b504797f36314633 Mon Sep 17 00:00:00 2001 From: saif <11242541+saifsmailbox98@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:49:17 +0530 Subject: [PATCH 4/6] test(agent-vault): drop the type test nothing compiles --- sink/agent-vault.test.ts | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/sink/agent-vault.test.ts b/sink/agent-vault.test.ts index 358be7e..f14e8d9 100644 --- a/sink/agent-vault.test.ts +++ b/sink/agent-vault.test.ts @@ -500,39 +500,6 @@ describe("agent vault project", () => { expect(request.body.projectId).toBe(PROJECT_ID); expect(request.query).toEqual({}); }); - - it("is required by every method that takes it", () => { - // Never called: tsc fails on an unused @ts-expect-error, so each line checks that leaving projectId out doesn't compile. - const withoutProject = (av: AgentVault) => [ - // @ts-expect-error projectId is required - av.proxies.list(), - // @ts-expect-error projectId is required - av.proxies.create({ name: "edge-proxy" }), - // @ts-expect-error projectId is required - av.sessions.list({}), - // @ts-expect-error projectId is required - av.sessions.create({ accessBundle: "release" }), - // @ts-expect-error projectId is required - av.accessBundles.list(), - // @ts-expect-error projectId is required - av.accessBundles.create({ name: "release" }), - // @ts-expect-error projectId is required - av.delegations.list(), - // @ts-expect-error projectId is required - av.delegations.get(MACHINE_IDENTITY_ID), - // @ts-expect-error projectId is required - av.delegations.set(MACHINE_IDENTITY_ID, { scope: "all-members" }), - // @ts-expect-error projectId is required - av.delegations.delete(MACHINE_IDENTITY_ID, {}), - // @ts-expect-error projectId is required - av.delegations.addSubjects(MACHINE_IDENTITY_ID, { userIds: [USER_ID] }), - // @ts-expect-error projectId is required - av.delegations.removeSubjects(MACHINE_IDENTITY_ID, { userIds: [USER_ID] }), - // @ts-expect-error projectId is required - av.delegations.listAvailableSubjects(MACHINE_IDENTITY_ID) - ]; - expect(withoutProject).toBeTypeOf("function"); - }); }); describe("agent vault proxies", () => { From ccd3cb600b25ce7eb86be15288126f8d6eaa1392 Mon Sep 17 00:00:00 2001 From: saif <11242541+saifsmailbox98@users.noreply.github.com> Date: Fri, 6 Nov 2026 02:22:49 +0530 Subject: [PATCH 5/6] fix(agent-vault): keep the project a created session belongs to --- sink/agent-vault.test.ts | 7 +++++++ src/api/types/agent-vault.ts | 2 ++ 2 files changed, 9 insertions(+) diff --git a/sink/agent-vault.test.ts b/sink/agent-vault.test.ts index f14e8d9..1f8f74d 100644 --- a/sink/agent-vault.test.ts +++ b/sink/agent-vault.test.ts @@ -54,6 +54,7 @@ const SESSION = { }; const CREATED_SESSION = { id: SESSION_ID, + projectId: PROJECT_ID, label: null, token: "session-token", expiresAt: SESSION.expiresAt, @@ -700,6 +701,12 @@ describe("agent vault sessions", () => { expect(created.accessBundle).toEqual({ id: BUNDLE_ID, name: "release" }); }); + it("create reads the project the session belongs to", async () => { + respondWith({ session: CREATED_SESSION }); + const created = await agentVault.sessions.create({ ...PROJECT, accessBundle: "release" }); + expect(created.projectId).toBe(PROJECT_ID); + }); + it.each(["nightly deploy", null])("update always sends the label (%j)", async (label) => { respondWith({ session: { ...SESSION, label } }); const updated = await agentVault.sessions.update(SESSION_ID, { label }); diff --git a/src/api/types/agent-vault.ts b/src/api/types/agent-vault.ts index 02185dd..2c8ee7f 100644 --- a/src/api/types/agent-vault.ts +++ b/src/api/types/agent-vault.ts @@ -245,6 +245,8 @@ export interface AgentVaultSession { /** An Agent Vault session as returned at creation. */ export interface CreatedAgentVaultSession { id: string; + /** The Agent Vault project the session belongs to. */ + projectId: string; label: string | null; /** The session token. It's only returned once. */ token: string; From f5a00fc098b6fffc0da0fcc5c6c011f51bbd3795 Mon Sep 17 00:00:00 2001 From: saif <11242541+saifsmailbox98@users.noreply.github.com> Date: Fri, 6 Nov 2026 04:45:32 +0530 Subject: [PATCH 6/6] chore: sync the pull request with the branch