Skip to content

Commit 5953b74

Browse files
Merge branch 'master' into develop
2 parents 5207deb + 3b0d4f2 commit 5953b74

File tree

5 files changed

+192
-12
lines changed

5 files changed

+192
-12
lines changed

.circleci/config.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Javascript Node CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
4+
#
5+
version: 2
6+
7+
defaults: &defaults
8+
working_directory: ~/repo
9+
docker:
10+
- image: circleci/node:8.9.1
11+
12+
jobs:
13+
test:
14+
<<: *defaults
15+
steps:
16+
- checkout
17+
18+
- restore_cache:
19+
keys:
20+
- v1-dependencies-
21+
# fallback to using the latest cache if no exact match is found
22+
- v1-dependencies-
23+
24+
- run: npm install
25+
- run:
26+
name: Run tests
27+
command: npm test
28+
29+
- save_cache:
30+
paths:
31+
- node_modules
32+
key: v1-dependencies-
33+
34+
- persist_to_workspace:
35+
root: ~/repo
36+
paths: .
37+
deploy:
38+
<<: *defaults
39+
steps:
40+
- attach_workspace:
41+
at: ~/repo
42+
- run:
43+
name: Authenticate with registry
44+
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc
45+
- run:
46+
name: Publish package
47+
command: npm publish --access public
48+
49+
workflows:
50+
version: 2
51+
test-deploy:
52+
jobs:
53+
- test:
54+
filters:
55+
tags:
56+
only: /^v.*/
57+
- deploy:
58+
requires:
59+
- test
60+
filters:
61+
tags:
62+
only: /^v.*/
63+
branches:
64+
ignore: /.*/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules/
22
coverage/
33
.nyc_output/
4-
.env
4+
.env

README

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# topcoder-bus-api-wrapper
2+
3+
Wrapper library for Topcoder Bus API
4+
5+
## How to use this Wrapper
6+
7+
Install Topcoder bus api wrapper as
8+
9+
```
10+
npm i topcoder-bus-api-wrapper
11+
```
12+
13+
Create an instance of this wrapper with the configuration variables listed below
14+
15+
```
16+
const busApi = require('topcoder-bus-api-wrapper')
17+
const busApiClient = busApi(_.pick(config,
18+
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
19+
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
20+
'KAFKA_ERROR_TOPIC']))
21+
```
22+
23+
**Configuration / Environment variables:**
24+
25+
* *Auth0 related variables*
26+
* AUTH0_URL
27+
* AUTH0_AUDIENCE
28+
* TOKEN_CACHE_TIME (optional)
29+
* AUTH0_CLIENT_ID
30+
31+
* BUSAPI_URL - Bus API URL. E.g. `https://api.topcoder-dev.com/v5`
32+
* KAFKA_ERROR_TOPIC - Error topic in Kafka to which error message need to be posted
33+
34+
Every function in this wrapper will return a promise, Handling promises is at the caller end. Call the functions with appropriate arguments
35+
36+
E.g.
37+
38+
```
39+
busApiClient
40+
.getTopics()
41+
.then(result => console.log(result.body, result.status))
42+
.catch(err => console.log(err))
43+
44+
await busApiClient.postEvent(reqBody)
45+
```
46+
47+
Refer `index.js` for the list of available wrapper functions
48+
49+
## Documentation for Bus API wrapper methods
50+
51+
All URIs are relative to **BUSAPI_URL** configuration variable.
52+
53+
Method | HTTP request | Description
54+
------------- | ------------- | -------------
55+
[**postEvent**](docs/EventsApi.md#postEvent) | **POST** /bus/events | Post event to the message bus.
56+
[**postError**](docs/EventsApi.md#postError) | **POST** /bus/events | Post error event to the message bus. This method is same as postEvent except that topic will be set by the wrapper itself.
57+
[**getHealth**](docs/HealthchecksApi.md#getHealth) | **GET** /bus/health | Check API is healthy.
58+
[**headHealth**](docs/HealthchecksApi.md#headHealth) | **HEAD** /bus/health | Get only response status and headers information but no response body for the endpoint.
59+
[**clearPlaceholdersCache**](docs/PlaceholdersApi.md#clearPlaceholdersCache) | **DELETE** /bus/placeholders | Clear placeholders cache.
60+
[**createService**](docs/ServiceApi.md#createService) | **POST** /bus/services | Create a service.
61+
[**createServicePayload**](docs/ServiceApi.md#createServicePayload) | **POST** /bus/services/{serviceName}/payloads | Create the service payload.
62+
[**deleteService**](docs/ServiceApi.md#deleteService) | **DELETE** /bus/services/{serviceName} | Delete the service.
63+
[**deleteServicePayload**](docs/ServiceApi.md#deleteServicePayload) | **DELETE** /bus/services/{serviceName}/payloads/{payloadName} | Delete the service payload.
64+
[**getService**](docs/ServiceApi.md#getService) | **GET** /bus/services/{serviceName} | Get the service.
65+
[**getServicePayload**](docs/ServiceApi.md#getServicePayload) | **GET** /bus/services/{serviceName}/payloads/{payloadName} | Get the service payload.
66+
[**getServicePayloads**](docs/ServiceApi.md#getServicePayloads) | **GET** /bus/services/{serviceName}/payloads | Search the service payloads.
67+
[**getServices**](docs/ServiceApi.md#getServices) | **GET** /bus/services | Get all services.
68+
[**headService**](docs/ServiceApi.md#headService) | **HEAD** /bus/services/{serviceName} | Get only response status and headers information but no response body for the endpoint.
69+
[**headServicePayload**](docs/ServiceApi.md#headServicePayload) | **HEAD** /bus/services/{serviceName}/payloads/{payloadName} | Get only response status and headers information but no response body for the endpoint.
70+
[**headServicePayloads**](docs/ServiceApi.md#headServicePayloads) | **HEAD** /bus/services/{serviceName}/payloads | Get only response status and headers information but no response body for the endpoint.
71+
[**headServices**](docs/ServiceApi.md#headServices) | **HEAD** /bus/services | Get only response status and headers information but no response body for the endpoint.
72+
[**patchService**](docs/ServiceApi.md#patchService) | **PATCH** /bus/services/{serviceName} | Partially update the service.
73+
[**patchServicePayload**](docs/ServiceApi.md#patchServicePayload) | **PATCH** /bus/services/{serviceName}/payloads/{payloadName} | Partially update the payload.
74+
[**updateService**](docs/ServiceApi.md#updateService) | **PUT** /bus/services/{serviceName} | Update the service.
75+
[**updateServicePayload**](docs/ServiceApi.md#updateServicePayload) | **PUT** /bus/services/{serviceName}/payloads/{payloadName} | Update the service payload.
76+
[**getTopics**](docs/TopicsApi.md#getTopics) | **GET** /bus/topics | Get topics.
77+
[**headTopics**](docs/TopicsApi.md#headTopics) | **HEAD** /bus/topics | Get only response status and headers information but no response body for the endpoint.
78+
79+
## Authorization
80+
81+
Bus API wrapper internally generates a **JWT token using Auth0 credentials** and pass it in the `Authorization` header.
82+
83+
## Running tests
84+
85+
Following environment variables need to be set up before running the tests
86+
87+
```
88+
- TEST_AUTH0_URL
89+
- TEST_AUTH0_AUDIENCE
90+
- TEST_AUTH0_CLIENT_ID
91+
- TEST_AUTH0_CLIENT_SECRET
92+
- TEST_BUS_API_URL
93+
- TEST_KAFKA_ERROR_TOPIC
94+
```
95+
96+
Refer to Step # 2 in [this section](#how-to-use-this-wrapper) to learn more about the configuration variables.
97+
98+
To run the tests alone, execute the command
99+
100+
```
101+
npm run test
102+
```
103+
104+
To run tests with coverage report, execute the command
105+
106+
```
107+
npm run cov
108+
```

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ const busApiClient = busApi(_.pick(config,
2323

2424
**Configuration / Environment variables:**
2525

26-
*Auth0 related variables:*
27-
- AUTH0_URL
28-
- AUTH0_AUDIENCE
29-
- TOKEN_CACHE_TIME (optional)
30-
- AUTH0_CLIENT_ID
31-
32-
- BUSAPI_URL - Bus API URL. E.g. `https://api.topcoder-dev.com/v5`
33-
- KAFKA_ERROR_TOPIC - Error topic in Kafka to which error message need to be posted
34-
26+
* *Auth0 related variables*
27+
* AUTH0_URL
28+
* AUTH0_AUDIENCE
29+
* TOKEN_CACHE_TIME (optional)
30+
* AUTH0_CLIENT_ID
31+
32+
* BUSAPI_URL - Bus API URL. E.g. `https://api.topcoder-dev.com/v5`
33+
* KAFKA_ERROR_TOPIC - Error topic in Kafka to which error message need to be posted
3534

3635
3. Every function in this wrapper will return a promise, Handling promises is at the caller end. Call the functions with appropriate arguments
3736

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "tc-bus-api-wrapper",
3-
"version": "1.0.0",
2+
"name": "@topcoder-platform/topcoder-bus-api-wrapper",
3+
"version": "1.1.0",
44
"description": "Wrapper for Topcoder Bus API",
55
"main": "index.js",
66
"scripts": {
@@ -26,5 +26,14 @@
2626
"env": [
2727
"mocha"
2828
]
29+
},
30+
"repository": {
31+
"type": "git",
32+
"url": "git+ssh://git@github.com/topcoder-platform/tc-bus-api-wrapper.git"
33+
},
34+
"author": "lazybaer",
35+
"license": "ISC",
36+
"bugs": {
37+
"url": "https://github.com/topcoder-platform/tc-bus-api-wrapper/issues"
2938
}
3039
}

0 commit comments

Comments
 (0)