Giter Site home page Giter Site logo

petstore-component-nodejs's Introduction

Petstore Component Node.js

Description

A fully working and operational component template to use for starting development of your own component for the elastic.io platform. This component comes with a basic architecture which you can use on the platform.

The component interacts with the petstore sample server.

Our documentation on building components in nodejs has more about each including file and their function.

Requirements

To use this component you must be registered platform user. Please see our home page at https://www.elastic.io to learn how to register.

Authentication

To authenticate use secret as an API key. For more details see the Petstore API docs.

Triggers

Get Pets By Status

Retrieves pets from the Petstore API by given pet status using Dynamic or Static Data Sample. The difference is how these functions are made. However, both can have the following statuses defined by the Petstore API:

  • Available - select to get all pets with status Available.
  • Pending - select for Pending.
  • Sold - select for Sold.

Actions

Creates a new pet

Creates a new Pet by making a POST to /pet endpoint of the API. The input fields are:

  • petId (required) - the Id of the pet.
  • name - the name of the pet.
  • status - the status which can have one Available, Pending and Sold values.

File Structure

The structure of petstore-component-nodejs component is quite flexible. elastic.io platform expects only two files to be present in the main directory. These are the component.json and package.json. Our documentation on how to build a component in node.js has more about each file and their function.

petstore-component-nodejs's People

Contributors

a3a3e1 avatar hannah-bulmer avatar hannatrotsenko avatar jhorbulyk avatar khanzadyan avatar nazar910 avatar olegosh avatar uaarsen avatar umkaline avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

petstore-component-nodejs's Issues

Error if pet status starts with a small letter

While following the instruction given in our online documentation https://docs.elastic.io/getting-started/webhooks-flow.html, we encountered problem if the pet status is given in small letter. This was not an issue in the previous version of the component.

Here is input JSON:

{
  "petname": "Gromit",
  "petstatus": "sold"
}

Here is the mapping stage:

Screenshot 2021-01-08 at 10 42 49

Here is the result with an error:

Starting your Docker container ...
Starting application in apprunner...
[INFO  tini (1)] Spawned child process '/run.sh' with pid '7'
Will try to start app at /home/apprunner
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
invokeModuleFunction – init is not found
Checking if incoming messages is lightweight...
Checking if incoming messages is lightweight...
Empty headers so not lightweight.
Message processed, going to emit
About to process message...
Error: Status is required
    at TaskExec.process (/home/apprunner/lib/actions/createPet.js:42:11)
    at /home/apprunner/node_modules/elasticio-sailor-nodejs/lib/executor.js:33:62
    at new Promise (<anonymous>)
    at TaskExec.process (/home/apprunner/node_modules/elasticio-sailor-nodejs/lib/executor.js:32:9)
    at /home/apprunner/node_modules/elasticio-sailor-nodejs/lib/sailor.js:341:22
    at new Promise (<anonymous>)
    at Sailor.runExec (/home/apprunner/node_modules/elasticio-sailor-nodejs/lib/sailor.js:317:15)
    at Sailor.processMessage (/home/apprunner/node_modules/elasticio-sailor-nodejs/lib/sailor.js:661:20)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Sailor.processMessageAndMaybeShutdownCallback (/home/apprunner/node_modules/elasticio-sailor-nodejs/lib/sailor.js:194:20)
    at async readAndProcess (/home/apprunner/node_modules/elasticio-sailor-nodejs/lib/amqp.js:238:21)
    at async Promise.all (index 0)
    at async Amqp.listenQueue (/home/apprunner/node_modules/elasticio-sailor-nodejs/lib/amqp.js:249:9)
    at async putOutToSea (/home/apprunner/node_modules/elasticio-sailor-nodejs/run.js:33:5)
    at async run (/home/apprunner/node_modules/elasticio-sailor-nodejs/run.js:78:9)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
[INFO  tini (1)] Spawned child process '/run.sh' with pid '6'
Starting application in apprunner...
Will try to start app at /home/apprunner
node: /usr/lib/libstdc++.so.6: no version information available (required by node)
invokeModuleFunction – init is not found
Checking if incoming messages is lightweight...
Empty headers so not lightweight.
Checking if incoming messages is lightweight...
Error occurred during trigger or action processing
Checking if incoming messages is lightweight...

The error is gone if you use the petstatus in capital letter like Sold.

Add eslint

In order to comply with code convention of PS team is required to add .eslint rules to the source code of the component.

Improve API error hadling

When supplying invalid pet status error looks like this:

image

400 - "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Error: Parameter (body) failed schema validation<br> &nbsp; &nbsp;at throwErrorWithCode (/app/node_modules/swagger-tools/lib/validators.js:121:13)<br> &nbsp; &nbsp;at Object.module.exports.validateAgainstSchema (/app/node_modules/swagger-tools/lib/validators.js:176:7)<br> &nbsp; &nbsp;at /app/node_modules/swagger-tools/middleware/swagger-validator.js:143:22<br> &nbsp; &nbsp;at /app/node_modules/async/lib/async.js:356:13<br> &nbsp; &nbsp;at async.forEachOf.async.eachOf (/app/node_modules/async/lib/async.js:233:13)<br> &nbsp; &nbsp;at _asyncMap (/app/node_modules/async/lib/async.js:355:9)<br> &nbsp; &nbsp;at Object.map (/app/node_modules/async/lib/async.js:337:20)<br> &nbsp; &nbsp;at validateValue (/app/node_modules/swagger-tools/middleware/swagger-validator.js:136:11)<br> &nbsp; &nbsp;at /app/node_modules/swagger-tools/middleware/swagger-validator.js:343:21<br> &nbsp; &nbsp;at /app/node_modules/async/lib/async.js:356:13</pre>\n</body>\n</html>\n"

Review component and update as this is an example of node.js component

What could be done:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.