Skip to content

Commit

Permalink
feat: add log() method to BuildClient (#509)
Browse files Browse the repository at this point in the history
This exposes the new /actor-builds/:build_id/log endpoint.

For more information, see the API reference at:
https://docs.apify.com/api/v2/#/reference/actor-builds/build-log
  • Loading branch information
tobice authored Feb 14, 2024
1 parent ad67688 commit 8821df6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/resource_clients/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ACT_JOB_TERMINAL_STATUSES } from '@apify/consts';
import ow from 'ow';

import { LogClient } from './log';
import { ApiClientSubResourceOptions } from '../base/api_client';
import { ResourceClient } from '../base/resource_client';
import {
Expand Down Expand Up @@ -69,6 +70,15 @@ export class BuildClient extends ResourceClient {

return this._waitForFinish(options);
}

/**
* https://docs.apify.com/api/v2#/reference/actor-builds/build-log
*/
log(): LogClient {
return new LogClient(this._subResourceOptions({
resourcePath: 'log',
}));
}
}

export interface BuildClientGetOptions {
Expand Down
12 changes: 12 additions & 0 deletions test/builds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,17 @@ describe('Build methods', () => {
expect(browserRes).toEqual(res);
validateRequest({ waitForFinish: 0 }, { buildId });
});

test('log().get() works', async () => {
const buildId = 'some-build-id';

const resource = await client.build(buildId).log().get();
expect(resource).toEqual('build-log');
validateRequest({}, { buildId });

const browserRes = await page.evaluate((id) => client.build(id).log().get(), buildId);
expect(browserRes).toEqual('build-log');
validateRequest({}, { buildId });
});
});
});
1 change: 1 addition & 0 deletions test/mock_server/routes/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const builds = express.Router();
const ROUTES = [
{ id: 'get-build', method: 'GET', path: '/:buildId', type: 'responseJsonMock' },
{ id: 'abort-build', method: 'POST', path: '/:buildId/abort' },
{ id: 'build-log', method: 'GET', path: '/:buildId/log', type: 'text' },
];

addRoutes(builds, ROUTES);
Expand Down

0 comments on commit 8821df6

Please sign in to comment.