Javascript runtime call

#1

Hi I would like to add a third party javascript library to my c3 package. Here is my configuration

{
“name”: “myPackage”,
“description”: “Hello world”,
“author”: “The c3 users”,
“dependencies”: [“xxx”],
“runtime”: {
“js-sha256”: {
“language”: “JS”,
“runtime”: “NODE_JS”,
“repositories”: [“https://github.com/emn178/js-sha256”]
}
}
}

here “js-sha256” is the third party javascript package. A testing call is sha256(‘11111’). However, console returns “sha256 is not defined”.
I know the language is “JS”, and runtime is “NODE_JS”, but I am not sure what is “repositories”. Can someone give an example how to call javascript runtime?

1 Like

Package dependencies are specified in package.json
#2

Your runtime definition is off, please use something along those lines:

{
  "name": "myPackage",
  "runtimes": {
    "nodejs-hash": {
      "language": "JavaScript",
      "runtime": "Node.js",
      "modules": {
        "jssha": "^2.3.1"
      }
    }
  }
}

then to use it:

type MyType {
  @nodejs(env="hash")
  hashSomethingToSha256: function(text: !string) : !string
}
0 Likes