Skip to content

Commit f44e309

Browse files
authored
Make status case insensitive (#25)
* Fix tests. Make statuses insensitive. * Bump dependencies.
1 parent 02e8828 commit f44e309

15 files changed

+4522
-146
lines changed

.gitignore

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,106 @@
11
# Logs
22
logs
33
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
411

512
# Runtime data
613
pids
714
*.pid
815
*.seed
16+
*.pid.lock
917

1018
# Directory for instrumented libs generated by jscoverage/JSCover
1119
lib-cov
1220

1321
# Coverage directory used by tools like istanbul
1422
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
1527

16-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
1729
.grunt
1830

31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
1934
# node-waf configuration
2035
.lock-wscript
2136

22-
# Compiled binary addons (http://nodejs.org/api/addons.html)
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
2338
build/Release
2439

25-
# Dependency directory
26-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27-
node_modules
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
105+
106+
.idea

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
## 1.0.2 (Jan 4, 2021)
1+
## 1.0.3 (May 28, 2021)
2+
3+
* Make statuses case-insensitive
4+
* Update to sailor version 2.6.24
5+
* Update README documentation
6+
* Changed petstore password in component.json
7+
8+
## 1.0.2 (January 4, 2021)
9+
210
* Update to sailor version 2.6.21
311
* Update to version 14 of node
412

README.md

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
1-
# petstore-component-nodejs
2-
> Petstore Node.js component template for the [elastic.io platform](http://www.elastic.io "elastic.io platform")
1+
# Petstore Component Node.js
32

4-
This is a component template which we commonly refer as **the first step of the development** for creating a component to deploy into our platform. This component comes with a basic architecture which can be used on our platform. You can clone it and use it. However, **if you plan to deploy it into [elastic.io platform](https://www.elastic.io "elastic.io platform") you must follow sets of instructions to succeed**.
3+
## Description
54

6-
## Before you Begin
5+
A fully working and operational component template to use for starting development of your
6+
own component for the [elastic.io platform](http://www.elastic.io "elastic.io platform").
7+
This component comes with a basic architecture which you can use on the platform.
78

8-
Before you can deploy any code into our system **you must be a registered elastic.io platform user**. Please see our home page at [https://www.elastic.io](https://www.elastic.io) to learn how.
9+
The component interacts with the [petstore sample server](https://petstore.elastic.io/docs/).
910

10-
> Any attempt to deploy a code into our platform without a registration would be rejected.
11+
Our documentation on [building components in nodejs](https://docs.elastic.io/guides/building-nodejs-component)
12+
has more about each including file and their function.
1113

12-
After the registration and opening of the account you must **[upload your SSH Key](http://go2.elastic.io/manage-ssh-keys)** into our platform.
14+
## Requirements
1315

14-
> If you fail to upload you SSH Key you will get **permission denied** error during the deployment.
16+
To use this component you must be registered platform user. Please see our home
17+
page at [https://www.elastic.io](https://www.elastic.io) to learn how to register.
1518

16-
## Getting Started
19+
### Authentication
1720

18-
After registration and uploading of your SSH Key you can proceed to deploy it into our system. At this stage we suggest you to:
19-
* [Create a team](http://go2.elastic.io/manage-teams) to work on your new component. This is not required but will be automatically created using random naming by our system so we suggest you name your team accordingly.
20-
* [Create a repository](http://go2.elastic.io/manage-repositories) where your new component is going to *reside* inside the team that you have just created.
21+
To authenticate use `secret` as an API key. For more details see the
22+
[Petstore API docs](https://petstore.elastic.io/docs/).
2123

22-
```bash
23-
$ git clone https://github.com/elasticio/petstore-component-nodejs.git your-repository
24+
## Triggers
2425

25-
$ cd your-repository
26-
```
27-
Now you can edit your version of **petstore-component-nodejs** component and build your desired component. Or you can just ``PUSH``it into our system to see the process in action:
26+
### Get Pets By Status
2827

29-
```bash
30-
$ git remote add elasticio your-team@git.elastic.io:your-repository.git
28+
Retrieves pets from the Petstore API by given pet status using Dynamic or Static
29+
Data Sample. The difference is how these functions are made. However, both can have
30+
the following statuses defined by the Petstore API:
3131

32-
$ git push elasticio master
33-
```
34-
Obviously the naming of your team and repository is entirely up-to you and if you do not put any corresponding naming our system will auto generate it for you but the naming might not entirely correspond to your project requirements.
32+
* `Available` - select to get all pets with status `Available`.
33+
* `Pending` - select for `Pending`.
34+
* `Sold` - select for `Sold`.
35+
36+
37+
## Actions
38+
39+
### Creates a new pet
40+
41+
Creates a new Pet by making a `POST` to `/pet` endpoint of the API. The input
42+
fields are:
43+
44+
* `petId` (required) - the Id of the pet.
45+
* `name` - the name of the pet.
46+
* `status` - the status which can have one `Available`, `Pending` and `Sold` values.
3547

3648
## File Structure
3749

38-
The structure of **petstore-component-nodejs** component is quite flexible. [elastic.io platform](https://www.elastic.io) 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](https://support.elastic.io/support/solutions/articles/14000027123-how-to-build-a-component-in-node-js) has more about each file and their function.
50+
The structure of **petstore-component-nodejs** component is quite flexible.
51+
[elastic.io platform](https://www.elastic.io) expects only two files to be present
52+
in the main directory. These are the ``component.json`` and ``package.json``. Our
53+
documentation on [how to build a component in node.js](https://docs.elastic.io/guides/building-nodejs-component)
54+
has more about each file and their function.

component.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
"description": "elastic.io component for the Petstore API",
44
"docsUrl": "https://github.com/elasticio/petstore-component-nodejs",
55
"buildType":"docker",
6+
"version": "1.0.3",
67
"credentials": {
78
"fields": {
89
"apiKey": {
910
"label": "API key",
1011
"required": true,
11-
"viewClass": "TextFieldWithNoteView",
12-
"note": "Please use <b>elasticio</b> as API key. For more details see <a href='https://petstore.elastic.io/docs/' target='_blank'>Petstore API docs</a>."
12+
"viewClass": "PasswordFieldView",
13+
"note": "Please use 'secret' as API key. For more details see Petstore API docs: https://petstore.elastic.io/docs"
1314
}
1415
}
1516
},
@@ -18,7 +19,10 @@
1819
"main": "./lib/triggers/getPetsByStatus.js",
1920
"type": "polling",
2021
"title": "Get Pets By Status (Dynamic Data Example)",
21-
"description": "Get pets by status, with the available statuses pulled dynamically from API",
22+
"help": {
23+
"description": "Get pets by status, with the available statuses pulled dynamically from API",
24+
"link": "/components/petstore-nodejs"
25+
},
2226
"fields": {
2327
"status": {
2428
"label": "Pet Status",
@@ -36,7 +40,10 @@
3640
"main": "./lib/triggers/getPetsByStatusWithStaticData.js",
3741
"type": "polling",
3842
"title": "Get Pets By Status (Static Data Example)",
39-
"description": "Get pets by status, with the available statuses statically typed to the component.json",
43+
"help": {
44+
"description": "Get pets by status, with the available statuses statically typed to the component.json",
45+
"link": "/components/petstore-nodejs"
46+
},
4047
"fields": {
4148
"status": {
4249
"label": "Pet Status",
@@ -59,7 +66,10 @@
5966
"createPet": {
6067
"main": "./lib/actions/createPet.js",
6168
"title": "Creates a new pet",
62-
"description": "Creates a pet and adds it to the shop",
69+
"help": {
70+
"description": "Creates a pet and adds it to the shop",
71+
"link": "/components/petstore-nodejs"
72+
},
6373
"metadata": {
6474
"in": "./lib/schemas/createPet.in.json",
6575
"out": "./lib/schemas/createPet.out.json"

lib/actions/createPet.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const { messages } = require('elasticio-node');
22
const PetstoreClient = require('../petstoreClient');
33

4+
const statuses = ['available', 'pending', 'sold'];
5+
46
/**
5-
* Executes the action's logic by sending a request to the Petstore API and emitting response to the platform.
7+
* Executes the action's logic by sending a request to the
8+
* Petstore API and emitting response to the platform.
69
* The function emits the results of the request to the platform as a message
710
*
811
* @param msg incoming messages which is empty for triggers
@@ -25,21 +28,18 @@ exports.process = async function process(msg, cfg) {
2528
*/
2629
const { name } = msg.body;
2730

28-
const statuses = {
29-
Available: 'available',
30-
Pending: 'pending',
31-
Sold: 'sold',
32-
};
31+
if (!msg.body.status) {
32+
throw new Error('Status is required');
33+
}
3334

34-
// map the status value from the readable value to the internal camel case one
35-
const status = statuses[msg.body.status];
35+
const status = msg.body.status.toLowerCase();
3636

37-
if (!name) {
38-
throw new Error('Name is required');
37+
if (!statuses.includes(status)) {
38+
throw new Error('Provided status is invalid.');
3939
}
4040

41-
if (!status) {
42-
throw new Error('Status is required');
41+
if (!name) {
42+
throw new Error('Name is required');
4343
}
4444

4545
// create pet object to post

lib/petstoreClient.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const API_BASE_URI = 'https://petstore.elastic.io/v2';
77
module.exports = class PetstoreClient extends ApiKeyRestClient {
88
constructor(emitter, cfg) {
99
// this first line is a hack for a small sailor bug
10+
// eslint-disable-next-line no-param-reassign
1011
if (!emitter.logger) emitter.logger = { trace: () => {} };
1112

1213
// begin constructor

lib/triggers/getPetsByStatus.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const { messages } = require('elasticio-node');
22
const PetstoreClient = require('../petstoreClient');
33

44
/**
5-
* Executes the trigger's logic by sending a request to the Petstore API and emitting response to the platform.
5+
* Executes the trigger's logic by sending a request to the
6+
* Petstore API and emitting response to the platform.
67
* The function emits the results of the request to the platform as a message
78
*
89
* @param msg incoming messages which is empty for triggers
@@ -29,7 +30,6 @@ exports.process = async function getPetsByStatus(msg, cfg) {
2930
await this.emit('data', messages.newMessageWithBody(result));
3031
};
3132

32-
3333
/**
3434
* getStatusModel is supplied in component.json as the model for credential statuses
3535
* The results of this function will dynamicaly provide the statuses from the API

lib/triggers/getPetsByStatusWithStaticData.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const { messages } = require('elasticio-node');
22
const PetstoreClient = require('../petstoreClient');
33

44
/**
5-
* Executes the trigger's logic by sending a request to the Petstore API and emitting response to the platform.
5+
* Executes the trigger's logic by sending a request to the
6+
* Petstore API and emitting response to the platform.
67
* The function emits the results of the request to the platform as a message
78
*
89
* @param msg incoming messages which is empty for triggers

0 commit comments

Comments
 (0)