Skip to content

Commit 3924ce0

Browse files
authored
fix: Fix incomplete type hint of last run/task (#952)
The API accepts the `origin` argument as well. Type is not complete. - Fix type by adding `origin` - Reuse duplicate type - Add the argument to one integration test to make it covered. API source: Task: https://github.com/apify/apify-core/blob/v0.1508.0/src/api/src/routes/actor_tasks/last_run.ts#L21 Run: https://github.com/apify/apify-core/blob/v0.1508.0/src/api/src/routes/actors/last_run.ts#L21
1 parent 06bf32b commit 3924ce0

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/resource_clients/actor.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AxiosRequestConfig } from 'axios';
22
import ow from 'ow';
33

44
import type { RUN_GENERAL_ACCESS } from '@apify/consts';
5-
import { ACT_JOB_STATUSES, ACTOR_PERMISSION_LEVEL, META_ORIGINS } from '@apify/consts';
5+
import { ACTOR_JOB_STATUSES, ACTOR_PERMISSION_LEVEL, META_ORIGINS } from '@apify/consts';
66
import { Log } from '@apify/log';
77

88
import type { ApiClientSubResourceOptions } from '../base/api_client';
@@ -18,6 +18,7 @@ import { RunClient } from './run';
1818
import { RunCollectionClient } from './run_collection';
1919
import type { WebhookUpdateData } from './webhook';
2020
import { WebhookCollectionClient } from './webhook_collection';
21+
import type { ValueOf } from 'type-fest';
2122

2223
/**
2324
* Client for managing a specific Actor.
@@ -371,7 +372,7 @@ export class ActorClient extends ResourceClient {
371372
ow(
372373
options,
373374
ow.object.exactShape({
374-
status: ow.optional.string.oneOf(Object.values(ACT_JOB_STATUSES)),
375+
status: ow.optional.string.oneOf(Object.values(ACTOR_JOB_STATUSES)),
375376
origin: ow.optional.string.oneOf(Object.values(META_ORIGINS)),
376377
}),
377378
);
@@ -708,7 +709,7 @@ export interface ActorRunListItem {
708709
actorTaskId?: string;
709710
startedAt: Date;
710711
finishedAt: Date;
711-
status: (typeof ACT_JOB_STATUSES)[keyof typeof ACT_JOB_STATUSES];
712+
status: (typeof ACTOR_JOB_STATUSES)[keyof typeof ACTOR_JOB_STATUSES];
712713
meta: ActorRunMeta;
713714
buildId: string;
714715
buildNumber: string;
@@ -843,7 +844,8 @@ export interface ActorBuildOptions {
843844
* Options for filtering the last run of an Actor.
844845
*/
845846
export interface ActorLastRunOptions {
846-
status?: keyof typeof ACT_JOB_STATUSES;
847+
status?: ValueOf<typeof ACTOR_JOB_STATUSES>;
848+
origin?: ValueOf<typeof META_ORIGINS>;
847849
}
848850

849851
/**

src/resource_clients/task.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ResourceClient } from '../base/resource_client';
88
import type { ApifyRequestConfig } from '../http_client';
99
import type { Dictionary } from '../utils';
1010
import { cast, catchNotFoundOrThrow, parseDateFields, pluckData, stringifyWebhooksToBase64 } from '../utils';
11-
import type { ActorRun, ActorStandby, ActorStartOptions } from './actor';
11+
import type { ActorLastRunOptions, ActorRun, ActorStandby, ActorStartOptions } from './actor';
1212
import { RunClient } from './run';
1313
import { RunCollectionClient } from './run_collection';
1414
import { WebhookCollectionClient } from './webhook_collection';
@@ -322,9 +322,7 @@ export type TaskUpdateData = Partial<
322322
/**
323323
* Options for filtering the last run of a Task.
324324
*/
325-
export interface TaskLastRunOptions {
326-
status?: keyof typeof ACT_JOB_STATUSES;
327-
}
325+
export interface TaskLastRunOptions extends ActorLastRunOptions {}
328326

329327
/**
330328
* Options for starting a Task.

test/actors.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import express from 'express';
99
import type { Page } from 'puppeteer';
1010
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
1111

12-
import { WEBHOOK_EVENT_TYPES } from '@apify/consts';
12+
import { META_ORIGINS, WEBHOOK_EVENT_TYPES } from '@apify/consts';
1313
import { LEVELS, Log } from '@apify/log';
1414

1515
import { stringifyWebhooksToBase64 } from '../src/utils';
@@ -385,9 +385,11 @@ describe('Actor methods', () => {
385385
'%s() works',
386386
async (method) => {
387387
const actorId = 'some-actor-id';
388-
const requestedStatus = 'SUCCEEDED';
388+
const requestedStatus = 'TIMING-OUT';
389389

390-
const lastRunClient = client.actor(actorId).lastRun({ status: requestedStatus });
390+
const lastRunClient = client
391+
.actor(actorId)
392+
.lastRun({ status: requestedStatus, origin: META_ORIGINS.API });
391393
const res = method === 'get' ? await lastRunClient.get() : await lastRunClient[method]().get();
392394

393395
const endpointIdMap = {
@@ -398,7 +400,7 @@ describe('Actor methods', () => {
398400
log: 'last-run-log',
399401
} as const;
400402
validateRequest({
401-
query: { status: requestedStatus },
403+
query: { status: requestedStatus, origin: META_ORIGINS.API },
402404
params: { actorId },
403405
endpointId: endpointIdMap[method],
404406
});

0 commit comments

Comments
 (0)