Skip to content

Commit

Permalink
fix(zeebe): add headers to all REST method calls
Browse files Browse the repository at this point in the history
method calls other that Topology were not passing headers with the request. They now pass headers.
  • Loading branch information
jwulf committed Jun 14, 2024
1 parent ea6919e commit 9b99177
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/zeebe/zb/ZeebeRESTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const ZEEBE_REST_API_VERSION = 'v1'
*/
interface TaskChangeSet {
/* The due date of the task. Reset by providing an empty String. */
dueDate: Date | string
dueDate?: Date | string
/* The follow-up date of the task. Reset by providing an empty String. */
followUpDate: Date | string
followUpDate?: Date | string
/* The list of candidate users of the task. Reset by providing an empty list. */
candidateUsers: string[]
candidateUsers?: string[]
/* The list of candidate groups of the task. Reset by providing an empty list. */
candidateGroups: string[]
candidateGroups?: string[]
}

export class ZeebeRestClient {
Expand Down Expand Up @@ -111,27 +111,29 @@ export class ZeebeRestClient {
}

/* Completes a user task with the given key. */
public completeUserTask({
public async completeUserTask({
userTaskKey,
variables,
variables = {},
action = 'complete',
}: {
userTaskKey: string
variables: Record<string, unknown>
action: string
variables?: Record<string, unknown>
action?: string
}) {
const headers = await this.getHeaders()
return this.rest.then((rest) =>
rest.post(`user-tasks/${userTaskKey}/completion`, {
body: JSON.stringify({
variables,
action,
}),
headers,
})
)
}

/* Assigns a user task with the given key to the given assignee. */
public assignTask({
public async assignTask({
userTaskKey,
assignee,
allowOverride = true,
Expand All @@ -142,35 +144,43 @@ export class ZeebeRestClient {
allowOverride?: boolean
action: string
}) {
const headers = await this.getHeaders()

return this.rest.then((rest) =>
rest.post(`user-tasks/${userTaskKey}/assignment`, {
body: JSON.stringify({
allowOverride,
action,
assignee,
}),
headers,
})
)
}

/** Update a user task with the given key. */
public updateTask({
public async updateTask({
userTaskKey,
changeset,
}: {
userTaskKey: string
changeset: TaskChangeSet
}) {
const headers = await this.getHeaders()

return this.rest.then((rest) =>
rest.post(`user-tasks/${userTaskKey}/update`, {
body: JSON.stringify(changeset),
headers,
})
)
}
/* Removes the assignee of a task with the given key. */
public removeAssignee({ userTaskKey }: { userTaskKey: string }) {
public async removeAssignee({ userTaskKey }: { userTaskKey: string }) {
const headers = await this.getHeaders()

return this.rest.then((rest) =>
rest.delete(`user-tasks/${userTaskKey}/assignee`)
rest.delete(`user-tasks/${userTaskKey}/assignee`, { headers })
)
}
}

0 comments on commit 9b99177

Please sign in to comment.