-
Notifications
You must be signed in to change notification settings - Fork 55
feat: add Actor task publication endpoints #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,52 @@ export class TaskClient extends ResourceClient { | |
| return this._update(newFields); | ||
| } | ||
|
|
||
| /** | ||
| * Publishes the task on its public landing page. | ||
| * | ||
| * The task's Actor must be public and the task must have its public display configuration | ||
| * (`publicConfig`) set up via {@apilink TaskClient.update}. Requires write permission to | ||
| * both the task and its Actor. | ||
| * | ||
| * Publishing an already published task is a no-op that returns the current state, so this | ||
| * call is safe to retry (unlike {@apilink TaskClient.unpublish}). | ||
| * | ||
| * @returns The task object. | ||
| * @see https://docs.apify.com/api/v2/actor-task-publish-post | ||
| */ | ||
| async publish(): Promise<Task> { | ||
| const response = await this.httpClient.call({ | ||
| url: this._url('publish'), | ||
| method: 'POST', | ||
| params: this._params(), | ||
| }); | ||
|
|
||
| return cast(parseDateFields(pluckData(response.data))); | ||
| } | ||
|
|
||
| /** | ||
| * Unpublishes the task from its public landing page. | ||
| * | ||
| * The public display configuration (`publicConfig`) is preserved, so the task can be | ||
| * published again without re-entering it. Requires write permission to both the task | ||
| * and its Actor. | ||
| * | ||
| * Unlike {@apilink TaskClient.publish}, this call is not idempotent: unpublishing a task | ||
| * that is not currently published throws an `ApifyApiError` (`cannot-unpublish-actor-task`). | ||
| * | ||
| * @returns The task object. | ||
| * @see https://docs.apify.com/api/v2/actor-task-unpublish-post | ||
| */ | ||
| async unpublish(): Promise<Task> { | ||
| const response = await this.httpClient.call({ | ||
| url: this._url('unpublish'), | ||
| method: 'POST', | ||
| params: this._params(), | ||
| }); | ||
|
|
||
| return cast(parseDateFields(pluckData(response.data))); | ||
| } | ||
|
|
||
| /** | ||
| * Deletes the Task. | ||
| * | ||
|
|
@@ -293,6 +339,24 @@ export interface Task { | |
| options?: TaskOptions; | ||
| input?: Dictionary | Dictionary[]; | ||
| actorStandby?: Partial<ActorStandby>; | ||
| publicConfig?: TaskPublicConfig | null; | ||
| } | ||
|
|
||
| /** | ||
| * Public-facing display configuration of a task's public landing page. | ||
| * | ||
| * The task is published when `publishedAt` is set and unpublished when it is `null`. The | ||
| * `publishedAt` field is read-only - use {@apilink TaskClient.publish} and | ||
| * {@apilink TaskClient.unpublish} to change the publication state. | ||
| */ | ||
| export interface TaskPublicConfig { | ||
| publishedAt: Date | null; | ||
| seoTitle?: string | null; | ||
| seoDescription?: string | null; | ||
| categorization?: string | null; | ||
| inputSchemaFields?: string[] | null; | ||
| datasetName?: string | null; | ||
| datasetView?: string | null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important: You're missing
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's stale no? I don't think it's used anywhere and if we decide to use it, the I would add it to public facing API, wdyt?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, good catch I guess we kept duplicated field to |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -317,7 +381,7 @@ export interface TaskOptions { | |
| */ | ||
| export type TaskUpdateData = Partial< | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: I commented on it at https://github.com/apify/apify-core/pull/29623#discussion_r3682214152 - |
||
| Pick<Task, 'name' | 'title' | 'description' | 'options' | 'input' | 'actorStandby'> | ||
| >; | ||
| > & { publicConfig?: Omit<TaskPublicConfig, 'publishedAt'> }; | ||
|
|
||
| /** | ||
| * Options for filtering the last run of a Task. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,30 @@ describe('Task methods', () => { | |
| validateRequest({ query: {}, params: { taskId } }); | ||
| }); | ||
|
|
||
| test('publish() works', async () => { | ||
| const taskId = 'some-task-id'; | ||
|
|
||
| const res = await client.task(taskId).publish(); | ||
| expect(res.id).toEqual('publish-task'); | ||
| validateRequest({ query: {}, params: { taskId } }); | ||
|
|
||
| const browserRes = await page.evaluate((id) => client.task(id).publish(), taskId); | ||
| expect(browserRes).toEqual(res); | ||
| validateRequest({ query: {}, params: { taskId } }); | ||
| }); | ||
|
|
||
| test('unpublish() works', async () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this dependent on the previous test? Ideally, tests should work in isolation, if they are dependent, maybe just merge them to a single test case |
||
| const taskId = 'some-task-id'; | ||
|
|
||
| const res = await client.task(taskId).unpublish(); | ||
| expect(res.id).toEqual('unpublish-task'); | ||
| validateRequest({ query: {}, params: { taskId } }); | ||
|
|
||
| const browserRes = await page.evaluate((id) => client.task(id).unpublish(), taskId); | ||
| expect(browserRes).toEqual(res); | ||
| validateRequest({ query: {}, params: { taskId } }); | ||
| }); | ||
|
|
||
| test('get() works', async () => { | ||
| const taskId = 'some-id'; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.