Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

fix Deploy Form to Zeebe #332 #338

Merged
merged 6 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 8.3.1

## New Features

_New shiny stuff_

- You can now deploy forms to the Zeebe broker using `ZBClient.deployResource()`. See [#332](https://github.com/camunda-community-hub/zeebe-client-node-js/issues/332) for more details.

# 8.3.0

## Breaking changes
Expand All @@ -19,6 +27,10 @@ _New shiny stuff._
- Camunda Platform 8.3.0 introduces multi-tenancy. To support this, the Node.js client adds an optional `tenantId` parameter to `DeployResource`, `DeployProcess`, `CreateProcessInstance`, `CreateProcessInstanceWithResult`, and `PublishMessage`. You can also specify a `tenantId` in the ZBClient constructor or via the environment variable `ZEEBE_TENANT_ID`. In the case that you specify it via the environment or constructor, it will be transparently added to all method invocations. See [#330](https://github.com/camunda-community-hub/zeebe-client-node-js/issues/330) for more details.
- `@grpc/grpc-js` has been updated to 1.9.7, and `@grpc/proto-loader` has been updated to 0.7.10.

_Things that were broken and are now fixed._

- The `onReady` and `onConnection` event tests now pass, so these events should be usable. See [#215](https://github.com/camunda-community-hub/zeebe-client-node-js/issues/215) for more details.

## Fixes

_Things that were broken and are now fixed._
Expand Down
10 changes: 10 additions & 0 deletions src/__tests__/integration/Client-DeployResource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ test('deploys a DMN table', async () => {
})
expect(result.deployments[0].decision.decisionKey).not.toBeNull()
})
test('deploys a Form', async () => {
const form = fs.readFileSync(
'./src/__tests__/testdata/form_1.form'
)
const result = await zbc.deployResource({
form,
name: 'form_1.form',
})
expect(result.deployments[0].form).not.toBeNull()
})
34 changes: 17 additions & 17 deletions src/__tests__/integration/Worker-onReady.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@ import { ZBClient } from '../..'
jest.setTimeout(40000)
process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'

test(`Worker calls the onReady handler once if there is a broker`, done => {
let called = 0
const zbc2 = new ZBClient()
zbc2.createWorker({
onReady: () => {
called++
},
taskHandler: job => job.complete(),
taskType: 'nonsense-task',
})
setTimeout(async () => {
expect(called).toBe(1)
await zbc2.close()
done()
}, 12000)
})

test(`Worker emits the ready event once if there is a broker`, done => {
let called = 0
const zbc2 = new ZBClient()
Expand Down Expand Up @@ -89,3 +72,20 @@ test(`Does not emit the ready event if there is no broker`, done => {
done()
}, 5000)
})

test(`Worker calls the onReady handler once if there is a broker`, done => {
let called = 0
const zbc2 = new ZBClient()
zbc2.createWorker({
onReady: () => {
called++
},
taskHandler: job => job.complete(),
taskType: 'nonsense-task',
})
setTimeout(async () => {
expect(called).toBe(1)
await zbc2.close()
done()
}, 12000)
})
43 changes: 43 additions & 0 deletions src/__tests__/testdata/form_1.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"components": [
{
"label": "Number",
"type": "number",
"layout": {
"row": "Row_1h8ufhy",
"columns": null
},
"id": "Field_1qlk4je",
"key": "field_19ab8r7"
},
{
"label": "Text area",
"type": "textarea",
"layout": {
"row": "Row_08n9bxz",
"columns": null
},
"id": "Field_1xphwg1",
"key": "field_0t0ghcb"
},
{
"label": "Checkbox",
"type": "checkbox",
"layout": {
"row": "Row_0shlcir",
"columns": null
},
"id": "Field_07ux5ad",
"key": "field_0oqjpgs"
}
],
"type": "default",
"id": "Form_07zfo8o",
"executionPlatform": "Camunda Cloud",
"executionPlatformVersion": "8.2.0",
"exporter": {
"name": "Camunda Modeler",
"version": "5.14.0"
},
"schemaVersion": 10
}
60 changes: 54 additions & 6 deletions src/zb/ZBClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,17 +758,25 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
| { decisionFilename: string, tenantId?: string }
| { name: string; decision: Buffer, tenantId?: string },
): Promise<Grpc.DeployResourceResponse<Grpc.DecisionDeployment>>
public async deployResource(
resource:
| { formFilename: string, tenantId?: string }
| { name: string; form: Buffer, tenantId?: string }
): Promise<Grpc.DeployResourceResponse<Grpc.FormDeployment>>
async deployResource(
resource:
| { processFilename: string, tenantId?: string }
| { name: string; process: Buffer, tenantId?: string }
| { processFilename: string, tenantId?: string }
| { name: string; decision: Buffer, tenantId?: string }
| { decisionFilename: string, tenantId?: string },
| { decisionFilename: string, tenantId?: string }
| { name: string; form: Buffer, tenantId?: string }
| { formFilename: string, tenantId?: string }
): Promise<
Grpc.DeployResourceResponse<
| Grpc.ProcessDeployment
| Grpc.DecisionDeployment
| Grpc.DecisionRequirementsDeployment
| Grpc.FormDeployment
>
> {
const isProcess = (
Expand All @@ -783,6 +791,19 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
maybeDecision: any
): maybeDecision is { decision: Buffer; name: string } =>
!!maybeDecision.decision
const isDecisionFilename = (
maybeDecisionFilename: any
): maybeDecisionFilename is { decisionFilename: string } =>
!!maybeDecisionFilename.decisionFilename
// default fall-through
/* const isForm = ( maybeForm: any ): maybeForm is { form: Buffer; name: string } =>
!!maybeForm.form
*/
const isFormFilename = (
maybeFormFilename: any
): maybeFormFilename is {formFilename: string} =>
!!maybeFormFilename.formFilename

if (isProcessFilename(resource)) {
const filename = resource.processFilename
const process = readFileSync(filename)
Expand All @@ -809,6 +830,20 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
tenantId: resource.tenantId ?? this.tenantId
})
)
} else if (isDecisionFilename(resource)) {
const filename = resource.decisionFilename
const decision = readFileSync(filename)
return this.executeOperation('deployResource', () =>
this.grpc.deployResourceSync({
resources: [
{
name: filename,
content: decision,
},
],
tenantId: resource.tenantId ?? this.tenantId
})
)
} else if (isDecision(resource)) {
return this.executeOperation('deployResource', () =>
this.grpc.deployResourceSync({
Expand All @@ -821,20 +856,33 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
tenantId: resource.tenantId ?? this.tenantId
})
)
} else {
const filename = resource.decisionFilename
const decision = readFileSync(filename)
} else if (isFormFilename(resource)) {
const filename = resource.formFilename
const form = readFileSync(filename)
return this.executeOperation('deployResource', () =>
this.grpc.deployResourceSync({
resources: [
{
name: filename,
content: decision,
content: form,
},
],
tenantId: resource.tenantId ?? this.tenantId
})
)
} else /* if (isForm(resource)) */ {
// default fall-through
return this.executeOperation('deployResource', () =>
this.grpc.deployResourceSync({
resources: [
{
name: resource.name,
content: resource.form
}
],
tenantId: resource.tenantId ?? this.tenantId
})
)
}
}

Expand Down