Skip to content

Commit 3292609

Browse files
authored
fix: get-actor-definition-default-build (#73)
* fix get default build in get actor definition * fix tests * fix double import, lint
1 parent a8f598e commit 3292609

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/apify-client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ function addUserAgent(config: AxiosRequestConfig): AxiosRequestConfig {
1616
return updatedConfig;
1717
}
1818

19+
export function getApifyAPIBaseUrl(): string {
20+
return process.env.APIFY_API_BASE_URL || 'https://api.apify.com';
21+
}
22+
1923
export class ApifyClient extends _ApifyClient {
2024
constructor(options: ApifyClientOptions) {
2125
super({
2226
...options,
23-
baseUrl: process.env.APIFY_API_BASE_URL || undefined,
27+
baseUrl: getApifyAPIBaseUrl(),
2428
requestInterceptors: [addUserAgent],
2529
});
2630
}

src/mcp/actors.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ActorDefinition } from 'apify-client';
22

3-
import { ApifyClient } from '../apify-client.js';
3+
import { ApifyClient, getApifyAPIBaseUrl } from '../apify-client.js';
44

55
export async function isActorMCPServer(actorID: string, apifyToken: string): Promise<boolean> {
66
const mcpPath = await getActorsMCPServerPath(actorID, apifyToken);
@@ -63,18 +63,25 @@ export async function getActorDefinition(actorID: string, apifyToken: string): P
6363
if (!info) {
6464
throw new Error(`Actor ${actorID} not found`);
6565
}
66-
const latestBuildID = info.taggedBuilds?.latest?.buildId;
67-
if (!latestBuildID) {
68-
throw new Error(`Actor ${actorID} does not have a latest build`);
66+
67+
const actorObjID = info.id;
68+
const res = await fetch(`${getApifyAPIBaseUrl()}/v2/acts/${actorObjID}/builds/default`, {
69+
headers: {
70+
// This is done so tests can pass with public Actors without token
71+
...(apifyToken ? { Authorization: `Bearer ${apifyToken}` } : {}),
72+
},
73+
});
74+
if (!res.ok) {
75+
throw new Error(`Failed to fetch default build for actor ${actorID}: ${res.statusText}`);
6976
}
70-
const build = apifyClient.build(latestBuildID);
71-
const buildInfo = await build.get();
77+
const json = await res.json() as any; // eslint-disable-line @typescript-eslint/no-explicit-any
78+
const buildInfo = json.data;
7279
if (!buildInfo) {
73-
throw new Error(`Build ${latestBuildID} not found`);
80+
throw new Error(`Default build for Actor ${actorID} not found`);
7481
}
7582
const { actorDefinition } = buildInfo;
7683
if (!actorDefinition) {
77-
throw new Error(`Build ${latestBuildID} does not have an actor definition`);
84+
throw new Error(`Actor default build ${actorID} does not have Actor definition`);
7885
}
7986

8087
return actorDefinition;

0 commit comments

Comments
 (0)