Skip to content

Commit

Permalink
feat(camunda8): implement deleteResource over REST
Browse files Browse the repository at this point in the history
fixes #251
  • Loading branch information
jwulf committed Sep 18, 2024
1 parent 008c789 commit 1650115
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/__tests__/c8/rest/deleteResourceRest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { C8RestClient } from '../../../c8/lib/C8RestClient'

const c8 = new C8RestClient()

test('It can delete a resource', async () => {
const res = await c8.deployResourcesFromFiles([
'./src/__tests__/testdata/Delete-Resource-Rest.bpmn',
])
const key = res.processes[0].processDefinitionKey
const id = res.processes[0].bpmnProcessId
const wfi = await c8.createProcessInstance({
bpmnProcessId: id,
variables: {},
})
expect(wfi.processKey).toBe(key)
await c8.deleteResource({ resourceKey: key })
await expect(
c8.createProcessInstance({ bpmnProcessId: id, variables: {} })
).rejects.toThrow()
})
32 changes: 32 additions & 0 deletions src/__tests__/testdata/Delete-Resource-Rest.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_09sn3dz" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.27.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:process id="delete-me-rest" name="Deletable Resource" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="Start">
<bpmn:outgoing>Flow_0z9jd9c</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:endEvent id="Event_1jyt422" name="End">
<bpmn:incoming>Flow_0z9jd9c</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0z9jd9c" sourceRef="StartEvent_1" targetRef="Event_1jyt422" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="delete-me-rest">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="79" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="185" y="122" width="24" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1jyt422_di" bpmnElement="Event_1jyt422">
<dc:Bounds x="272" y="79" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="280" y="122" width="20" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0z9jd9c_di" bpmnElement="Flow_0z9jd9c">
<di:waypoint x="215" y="97" />
<di:waypoint x="272" y="97" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
3 changes: 2 additions & 1 deletion src/c8/lib/C8Dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export class CreateProcessInstanceResponse extends LosslessDto {
* The unique key identifying the process definition (e.g. returned from a process
* in the DeployResourceResponse message)
*/
readonly processDefinitionKey!: string
@Int64String
readonly processKey!: string
/**
* The BPMN process ID of the process definition
*/
Expand Down
17 changes: 17 additions & 0 deletions src/c8/lib/C8RestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,23 @@ export class C8RestClient {
return this.deployResources(resources)
}

/**
* Deletes a deployed resource. This can be a process definition, decision requirements definition, or form definition deployed using the deploy resources endpoint. Specify the resource you want to delete in the resourceKey parameter.
*/
public async deleteResource(req: {
resourceKey: string
operationReference?: number
}) {
const headers = await this.getHeaders()
const { resourceKey, operationReference } = req
return this.rest.then((rest) =>
rest.post(`resources/${resourceKey}/deletion`, {
headers,
body: stringify({ operationReference }),
})
)
}

/**
* Set a precise, static time for the Zeebe engine's internal clock.
* When the clock is pinned, it remains at the specified time and does not advance.
Expand Down

0 comments on commit 1650115

Please sign in to comment.