gorules / zen

Open-source Business Rules Engine for your Rust, NodeJS, Python or Go applications.
https://gorules.io
MIT License
750 stars 73 forks source link

Using function is throwing an Error: invalid type: map, expected a string #231

Closed vsingh-neos closed 1 week ago

vsingh-neos commented 3 weeks ago

Getting error when doing a createDecision for below rule JSON.

{ "contentType": "application/vnd.gorules.decision", "nodes": [ { "type": "inputNode", "id": "65f04aa9-ce67-4a5e-9612-9aa91723cb0e", "name": "request", "position": { "x": -135, "y": 315 } }, { "type": "outputNode", "id": "c4608612-4d85-4d86-a8b8-2fd8044c14ab", "name": "response", "position": { "x": 1345, "y": 530 } }, { "type": "functionNode", "content": { "source": "export const handler = async (input) => {\n let result = true;\n return {result};\n};" }, "id": "a28a62a8-32a7-4261-a6e6-d75bff80380e", "name": "binding", "position": { "x": 600, "y": 315 } } ], "edges": [ { "id": "2ee2cd5e-1f82-4327-a0b8-c7dc296361d1", "sourceId": "a28a62a8-32a7-4261-a6e6-d75bff80380e", "type": "edge", "targetId": "c4608612-4d85-4d86-a8b8-2fd8044c14ab" }, { "id": "764627ea-15f8-45b9-9bed-e82b15cfa859", "sourceId": "65f04aa9-ce67-4a5e-9612-9aa91723cb0e", "type": "edge", "targetId": "a28a62a8-32a7-4261-a6e6-d75bff80380e" } ] }

In nodeJS I am doing const decision = engine.createDecision(rules); const result = await decision.evaluate(metadata);

Error I am getting: Invalid type: map, expected a string

Note: I am creating rules using online editor and downloading the rules JSON to use in the nodeJS project.

justin0108 commented 2 weeks ago

Hi @vsingh-neos,

I suspect the JDM content that you downloaded from the online editor does not match the engine version that you have in your nodeJS project. I saw you have a function node in the JDM. Older JDM editor is giving

"content": "..."

in your JDM your content is

"content": {
    "source": "..."
}

I happen to be using an older engine version and I cannot run the JDM given by you as well with the same error

ivanmiletic commented 2 weeks ago

Hi,

@justin0108 is right please update the version. Our newest engines are backwards compatible and they support all versions of the files.

In the future we will also build a checks in the engines.

vsingh-neos commented 2 weeks ago

Hi @justin0108 @ivanmiletic , below is the version i see in node_modules after installing

"name": "@gorules/zen-engine",
  "version": "0.23.0",

Could you help me with correct version I shall use for online editor?

Also, how can I run gorules editor container on mac. When I use command docker run -p 3000:3000 --platform=darwin/arm64 gorules/editor is throws error docker: no matching manifest for darwin/arm64 in the manifest list entries.

stefan-gorules commented 2 weeks ago

Hi @vsingh-neos, to run editor on Mac you would use

docker run -p 3000:3000 --platform=linux/amd64 gorules/editor

This ensures that editor will run as if it was on linux/amd64 infrastructure. Let me know if above works.

Gabrieltay commented 2 weeks ago
"name": "@gorules/zen-engine",
  "version": "0.23.0",

hi @vsingh-neos , i believe the latest is already on 0.27.0

Our newest engines are backwards compatible and they support all versions

Thanks @stefan-gorules, it works.

vsingh-neos commented 1 week ago

Thanks @stefan-gorules @Gabrieltay. Can confirm after updating the engine its working as expected.