Skip to content
Merged
11 changes: 4 additions & 7 deletions src/endpoints/credential-requests.mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,20 @@ export const tools = [
status: { type: 'string', description: 'Filter by status' },
name: { type: 'string', description: 'Filter by name' },
},
required: ['teamId'],
},
execute: async (
make: Make,
args: {
teamId?: number;
teamId: number;
userId?: number;
makeProviderId?: string | number;
status?: string;
name?: string;
},
) => {
return await make.credentialRequests.list({
teamId: args.teamId,
userId: args.userId,
makeProviderId: args.makeProviderId,
status: args.status,
name: args.name,
return await make.credentialRequests.list(args.teamId, {
...args,
cols: ['*'],
});
},
Expand Down
32 changes: 27 additions & 5 deletions src/endpoints/credential-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ export type GetCredentialRequestOptions<C extends keyof CredentialRequest = neve
export type ListCredentialRequestsOptions<C extends keyof CredentialRequest = never> = {
/** Specific columns/fields to include in the response */
cols?: C[] | ['*'];
/** Filter by team ID */
teamId?: number;
/** Filter by user ID */
userId?: number;
/** Filter by Make provider ID */
Expand Down Expand Up @@ -219,14 +217,38 @@ export class CredentialRequests {
}

/**
* List credential requests with optional filtering and pagination
* List credential requests for a given team, with optional additional filtering and pagination.
*
* @param teamId - The team to list credential requests for.
* @param options - Optional filters (user, provider, status, name) and pagination.
*/
async list<C extends keyof CredentialRequest = never>(
options: ListCredentialRequestsOptions<C> = {},
teamId: number,
options?: ListCredentialRequestsOptions<C>,
): Promise<PickColumns<CredentialRequest, C>[]>;

/**
* @deprecated Pass `teamId` as the first argument: `list(teamId, options?)`.
*/
async list<C extends keyof CredentialRequest = never>(
options: ListCredentialRequestsOptions<C> & { teamId: number },
): Promise<PickColumns<CredentialRequest, C>[]>;

async list<C extends keyof CredentialRequest = never>(
teamIdOrOptions: number | (ListCredentialRequestsOptions<C> & { teamId: number }),
options?: ListCredentialRequestsOptions<C>,
): Promise<PickColumns<CredentialRequest, C>[]> {
Comment thread
JanKulhavy marked this conversation as resolved.
let teamId: number;
if (teamIdOrOptions !== null && typeof teamIdOrOptions === 'object') {
({ teamId, ...options } = teamIdOrOptions);
} else {
teamId = teamIdOrOptions as number;
options ??= {} as ListCredentialRequestsOptions<C>;
}

const response = await this.#fetch<{ requests: PickColumns<CredentialRequest, C>[] }>(
'/credential-requests/requests',
{ query: options },
{ query: { ...options, teamId } },
);
Comment thread
JanKulhavy marked this conversation as resolved.
return response.requests;
}
Expand Down
14 changes: 7 additions & 7 deletions test/credential-requests.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Integration: CredentialRequests', () => {
});

it('Should list credential requests', async () => {
const requests = await make.credentialRequests.list({ teamId: MAKE_TEAM });
const requests = await make.credentialRequests.list(MAKE_TEAM);
expect(Array.isArray(requests)).toBe(true);
expect(requests.some(r => r.id === requestId)).toBe(true);
});
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('Integration: CredentialRequests', () => {
await make.credentialRequests.delete(requestId);

// Check that request is deleted
const requests = await make.credentialRequests.list({ teamId: MAKE_TEAM });
const requests = await make.credentialRequests.list(MAKE_TEAM);
expect(requests.some(r => r.id === requestId)).toBe(false);
});

Expand Down Expand Up @@ -116,7 +116,7 @@ describe('Integration: CredentialRequests', () => {
await make.credentialRequests.delete(actionRequestId);

// Check that request is deleted
const requests = await make.credentialRequests.list({ teamId: MAKE_TEAM });
const requests = await make.credentialRequests.list(MAKE_TEAM);
expect(requests.some(r => r.id === actionRequestId)).toBe(false);
});

Expand Down Expand Up @@ -169,7 +169,7 @@ describe('Integration: CredentialRequests', () => {
it('Should delete the credential request created with a connection', async () => {
await make.credentialRequests.delete(connectionRequestId);

const requests = await make.credentialRequests.list({ teamId: MAKE_TEAM });
const requests = await make.credentialRequests.list(MAKE_TEAM);
expect(requests.some(r => r.id === connectionRequestId)).toBe(false);
});

Expand All @@ -196,7 +196,7 @@ describe('Integration: CredentialRequests', () => {
it('Should delete the credential request created with a key', async () => {
await make.credentialRequests.delete(keyRequestId);

const requests = await make.credentialRequests.list({ teamId: MAKE_TEAM });
const requests = await make.credentialRequests.list(MAKE_TEAM);
expect(requests.some(r => r.id === keyRequestId)).toBe(false);
});

Expand Down Expand Up @@ -232,7 +232,7 @@ describe('Integration: CredentialRequests', () => {
it('Should delete the credential request created with both connections and keys', async () => {
await make.credentialRequests.delete(mixedRequestId);

const requests = await make.credentialRequests.list({ teamId: MAKE_TEAM });
const requests = await make.credentialRequests.list(MAKE_TEAM);
expect(requests.some(r => r.id === mixedRequestId)).toBe(false);
});

Expand All @@ -256,7 +256,7 @@ describe('Integration: CredentialRequests', () => {
it('Should delete the credential request created with nameOverride', async () => {
await make.credentialRequests.delete(nameOverrideRequestId);

const requests = await make.credentialRequests.list({ teamId: MAKE_TEAM });
const requests = await make.credentialRequests.list(MAKE_TEAM);
expect(requests.some(r => r.id === nameOverrideRequestId)).toBe(false);
});
});
38 changes: 24 additions & 14 deletions test/credential-requests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,13 @@ const MAKE_ZONE = 'make.local';
describe('Endpoints: CredentialRequests', () => {
const make = new Make(MAKE_API_KEY, MAKE_ZONE);

it('Should list credential requests', async () => {
mockFetch('GET https://make.local/api/v2/credential-requests/requests', listMock);

const result = await make.credentialRequests.list();

expect(result).toStrictEqual(listMock.requests);
});

it('Should list credential requests with filters and pagination', async () => {
mockFetch(
'GET https://make.local/api/v2/credential-requests/requests?teamId=123&status=pending&pg%5Blimit%5D=50',
'GET https://make.local/api/v2/credential-requests/requests?status=pending&pg%5Blimit%5D=50&teamId=123',
listMock,
);

const result = await make.credentialRequests.list({
teamId: 123,
const result = await make.credentialRequests.list(123, {
status: 'pending',
pg: {
limit: 50,
Expand All @@ -43,14 +34,33 @@ describe('Endpoints: CredentialRequests', () => {
expect(result).toStrictEqual(listMock.requests);
});

it('Should list credential requests with teamId only', async () => {
mockFetch('GET https://make.local/api/v2/credential-requests/requests?teamId=123', listMock);

const result = await make.credentialRequests.list(123);

expect(result).toStrictEqual(listMock.requests);
});

it('Should list credential requests using deprecated options object signature', async () => {
mockFetch(
'GET https://make.local/api/v2/credential-requests/requests?status=pending&teamId=123',
listMock,
);

// eslint-disable-next-line @typescript-eslint/no-deprecated
const result = await make.credentialRequests.list({ teamId: 123, status: 'pending' });

expect(result).toStrictEqual(listMock.requests);
});

it('Should list credential requests with multiple filters', async () => {
mockFetch(
'GET https://make.local/api/v2/credential-requests/requests?teamId=123&userId=789&makeProviderId=456&name=Google+Workspace+Access',
'GET https://make.local/api/v2/credential-requests/requests?userId=789&makeProviderId=456&name=Google+Workspace+Access&teamId=123',
listMock,
);

const result = await make.credentialRequests.list({
teamId: 123,
const result = await make.credentialRequests.list(123, {
userId: 789,
makeProviderId: '456',
name: 'Google Workspace Access',
Expand Down