diff --git a/src/c8/lib/C8Dto.ts b/src/c8/lib/C8Dto.ts index af234b35..d671892c 100644 --- a/src/c8/lib/C8Dto.ts +++ b/src/c8/lib/C8Dto.ts @@ -280,3 +280,32 @@ export interface CreateProcessInstanceFromProcessDefinition< export type CreateProcessInstanceReq = | CreateProcessInstanceFromBpmnProcessId | CreateProcessInstanceFromProcessDefinition + +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: [] + }[] +} diff --git a/src/c8/lib/C8RestClient.ts b/src/c8/lib/C8RestClient.ts index 02b21a50..6788ed35 100644 --- a/src/c8/lib/C8RestClient.ts +++ b/src/c8/lib/C8RestClient.ts @@ -51,6 +51,7 @@ import { JobUpdateChangeset, MigrationRequest, NewUserInfo, + PatchAuthorizationRequest, ProcessDeployment, PublishMessageResponse, TaskChangeSet, @@ -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. */ @@ -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() ) } @@ -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() ) } @@ -216,10 +237,12 @@ 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. */ @@ -227,7 +250,7 @@ export class C8RestClient { 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() ) } @@ -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() ) } @@ -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), }) @@ -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() @@ -491,7 +519,10 @@ export class C8RestClient { * Create and start a process instance. This method awaits the outcome of the process. */ public async createProcessInstanceWithResult( - request: CreateProcessInstanceReq + request: CreateProcessInstanceReq & { + /** An array of variable names to fetch. If not supplied, all visible variables in the root scope will be returned */ + fetchVariables?: string[] + } ): Promise> public async createProcessInstanceWithResult< @@ -499,6 +530,9 @@ export class C8RestClient { V extends LosslessDto, >( request: CreateProcessInstanceReq & { + /** 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 } ): Promise>