Skip to content

Commit

Permalink
feat(camunda8): add modifyAuthorization method
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed Sep 27, 2024
1 parent bb5d8ea commit 0d97f68
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 28 deletions.
29 changes: 29 additions & 0 deletions src/c8/lib/C8Dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,32 @@ export interface CreateProcessInstanceFromProcessDefinition<
export type CreateProcessInstanceReq<T extends JSONDoc | LosslessDto> =
| CreateProcessInstanceFromBpmnProcessId<T>
| CreateProcessInstanceFromProcessDefinition<T>

export interface PatchAuthorizationRequest {
/** The key of the owner of the authorization. */
ownerKey: string
/** Indicates if permissions should be added or removed. */
action: 'ADD' | 'REMOVE'
/** The type of resource to add/remove perissions to/from. */
resourceType:
| 'AUTHORIZATION'
| 'MESSAGE'
| 'JOB'
| 'APPLICATION'
| 'TENANT'
| 'DEPLOYMENT'
| 'PROCESS_DEFINITION'
| 'USER_TASK'
| 'DECISION_REQUIREMENTS_DEFINITION'
| 'DECISION_DEFINITION'
| 'USER_GROUP'
| 'USER'
| 'ROLE'
/** The permissions to add/remove. */
permissions: {
/** Specifies the type of permissions. */
permissionType: 'CREATE' | 'READ' | 'UPDATE' | 'DELETE'
/** A list of resource IDs the permission relates to. */
resourceIds: []
}[]
}
90 changes: 62 additions & 28 deletions src/c8/lib/C8RestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
JobUpdateChangeset,
MigrationRequest,
NewUserInfo,
PatchAuthorizationRequest,
ProcessDeployment,
PublishMessageResponse,
TaskChangeSet,
Expand Down Expand Up @@ -131,6 +132,22 @@ export class C8RestClient {
return headers
}

/**
* Manage the permissions assigned to authorization.
*/
public async modifyAuthorization(req: PatchAuthorizationRequest) {
const headers = await this.getHeaders()
const { ownerKey, ...request } = req
return this.rest.then((rest) =>
rest
.patch(`authorizations/${ownerKey}`, {
headers,
body: stringify(request),
})
.json()
)
}

/**
* Broadcasts a signal.
*/
Expand Down Expand Up @@ -169,13 +186,15 @@ export class C8RestClient {
}) {
const headers = await this.getHeaders()
return this.rest.then((rest) =>
rest.post(`user-tasks/${userTaskKey}/completion`, {
body: losslessStringify({
variables,
action,
}),
headers,
})
rest
.post(`user-tasks/${userTaskKey}/completion`, {
body: losslessStringify({
variables,
action,
}),
headers,
})
.json()
)
}

Expand All @@ -194,14 +213,16 @@ export class C8RestClient {
const headers = await this.getHeaders()

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

Expand All @@ -216,18 +237,20 @@ export class C8RestClient {
const headers = await this.getHeaders()

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

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

Expand All @@ -238,10 +261,12 @@ export class C8RestClient {
const headers = await this.getHeaders()

return this.rest.then((rest) =>
rest.post(`users`, {
body: JSON.stringify(newUserInfo),
headers,
})
rest
.post(`users`, {
body: JSON.stringify(newUserInfo),
headers,
})
.json()
)
}

Expand All @@ -262,11 +287,12 @@ export class C8RestClient {
>
) {
const headers = await this.getHeaders()
const body = losslessStringify(this.addDefaultTenantId(message))

return this.rest.then((rest) =>
rest
.post(`messages/correlation`, {
body: losslessStringify(message),
body,
headers,
parseJson: (text) => losslessParse(text, CorrelateMessageResponse),
})
Expand All @@ -280,12 +306,14 @@ export class C8RestClient {
*/
public async publishMessage(publishMessageRequest: PublishMessageRequest) {
const headers = await this.getHeaders()
const request = this.addDefaultTenantId(publishMessageRequest)
const body = losslessStringify(
this.addDefaultTenantId(publishMessageRequest)
)
return this.rest.then((rest) =>
rest
.post(`messages/publication`, {
headers,
body: stringify(request),
body,
parseJson: (text) => losslessParse(text, PublishMessageResponse),
})
.json<PublishMessageResponse>()
Expand Down Expand Up @@ -491,14 +519,20 @@ export class C8RestClient {
* Create and start a process instance. This method awaits the outcome of the process.
*/
public async createProcessInstanceWithResult<T extends JSONDoc | LosslessDto>(
request: CreateProcessInstanceReq<T>
request: CreateProcessInstanceReq<T> & {
/** An array of variable names to fetch. If not supplied, all visible variables in the root scope will be returned */
fetchVariables?: string[]
}
): Promise<CreateProcessInstanceResponse<unknown>>

public async createProcessInstanceWithResult<
T extends JSONDoc | LosslessDto,
V extends LosslessDto,
>(
request: CreateProcessInstanceReq<T> & {
/** An array of variable names to fetch. If not supplied, all visible variables in the root scope will be returned */
fetchVariables?: string[]
/** A Dto specifying the shape of the output variables. If not supplied, the output variables will be returned as a `LosslessDto` of type `unknown`. */
outputVariablesDto: Ctor<V>
}
): Promise<CreateProcessInstanceResponse<V>>
Expand Down

0 comments on commit 0d97f68

Please sign in to comment.