Skip to content

Commit ca10765

Browse files
authored
Merge pull request #3 from sharathkumaranbu/Issue_1
Added tests with documentation of methods in wrapper
2 parents 8b4e1c8 + 628210f commit ca10765

23 files changed

+3145
-141
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules/
2+
coverage/
3+
.nyc_output/

README.md

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Wrapper library for Topcoder Bus API
1515

1616
```
1717
const busApi = require('tc-bus-api-wrapper')
18-
busApi(_.pick(config,
18+
const busApiClient = busApi(_.pick(config,
1919
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
2020
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
2121
'KAFKA_ERROR_TOPIC']))
@@ -30,17 +30,81 @@ busApi(_.pick(config,
3030
- AUTH0_CLIENT_ID
3131

3232
- BUSAPI_URL - Bus API URL. E.g. `https://api.topcoder-dev.com/v5`
33-
3433
- KAFKA_ERROR_TOPIC - Error topic in Kafka to which error message need to be posted
3534

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

3838
E.g.
3939

4040
```
41-
const result = yield busApiClient.getTopics()
41+
busApiClient
42+
.getTopics()
43+
.then(result => console.log(result.body, result.status))
44+
.catch(err => console.log(err))
4245
43-
yield busApiClient.postEvent(reqBody)
46+
await busApiClient.postEvent(reqBody)
4447
```
4548

46-
Refer `index.js` for the list of available wrapper functions
49+
Refer `index.js` for the list of available wrapper functions
50+
51+
## Documentation for Bus API wrapper methods
52+
53+
All URIs are relative to **BUSAPI_URL** configuration variable.
54+
55+
Method | HTTP request | Description
56+
------------- | ------------- | -------------
57+
[**postEvent**](docs/EventsApi.md#postEvent) | **POST** /bus/events | Post event to the message bus.
58+
[**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.
59+
[**getHealth**](docs/HealthchecksApi.md#getHealth) | **GET** /bus/health | Check API is healthy.
60+
[**headHealth**](docs/HealthchecksApi.md#headHealth) | **HEAD** /bus/health | Get only response status and headers information but no response body for the endpoint.
61+
[**clearPlaceholdersCache**](docs/PlaceholdersApi.md#clearPlaceholdersCache) | **DELETE** /bus/placeholders | Clear placeholders cache.
62+
[**createService**](docs/ServiceApi.md#createService) | **POST** /bus/services | Create a service.
63+
[**createServicePayload**](docs/ServiceApi.md#createServicePayload) | **POST** /bus/services/{serviceName}/payloads | Create the service payload.
64+
[**deleteService**](docs/ServiceApi.md#deleteService) | **DELETE** /bus/services/{serviceName} | Delete the service.
65+
[**deleteServicePayload**](docs/ServiceApi.md#deleteServicePayload) | **DELETE** /bus/services/{serviceName}/payloads/{payloadName} | Delete the service payload.
66+
[**getService**](docs/ServiceApi.md#getService) | **GET** /bus/services/{serviceName} | Get the service.
67+
[**getServicePayload**](docs/ServiceApi.md#getServicePayload) | **GET** /bus/services/{serviceName}/payloads/{payloadName} | Get the service payload.
68+
[**getServicePayloads**](docs/ServiceApi.md#getServicePayloads) | **GET** /bus/services/{serviceName}/payloads | Search the service payloads.
69+
[**getServices**](docs/ServiceApi.md#getServices) | **GET** /bus/services | Get all services.
70+
[**headService**](docs/ServiceApi.md#headService) | **HEAD** /bus/services/{serviceName} | Get only response status and headers information but no response body for the endpoint.
71+
[**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.
72+
[**headServicePayloads**](docs/ServiceApi.md#headServicePayloads) | **HEAD** /bus/services/{serviceName}/payloads | Get only response status and headers information but no response body for the endpoint.
73+
[**headServices**](docs/ServiceApi.md#headServices) | **HEAD** /bus/services | Get only response status and headers information but no response body for the endpoint.
74+
[**patchService**](docs/ServiceApi.md#patchService) | **PATCH** /bus/services/{serviceName} | Partially update the service.
75+
[**patchServicePayload**](docs/ServiceApi.md#patchServicePayload) | **PATCH** /bus/services/{serviceName}/payloads/{payloadName} | Partially update the payload.
76+
[**updateService**](docs/ServiceApi.md#updateService) | **PUT** /bus/services/{serviceName} | Update the service.
77+
[**updateServicePayload**](docs/ServiceApi.md#updateServicePayload) | **PUT** /bus/services/{serviceName}/payloads/{payloadName} | Update the service payload.
78+
[**getTopics**](docs/TopicsApi.md#getTopics) | **GET** /bus/topics | Get topics.
79+
[**headTopics**](docs/TopicsApi.md#headTopics) | **HEAD** /bus/topics | Get only response status and headers information but no response body for the endpoint.
80+
81+
## Authorization
82+
83+
Bus API wrapper internally generates a **JWT token using Auth0 credentials** and pass it in the `Authorization` header.
84+
85+
## Running tests
86+
87+
Following environment variables need to be set up before running the tests
88+
89+
```
90+
- TEST_AUTH0_URL
91+
- TEST_AUTH0_AUDIENCE
92+
- TEST_AUTH0_CLIENT_ID
93+
- TEST_AUTH0_CLIENT_SECRET
94+
- TEST_BUS_API_URL
95+
- TEST_KAFKA_ERROR_TOPIC
96+
```
97+
98+
Refer to Step # 2 in [this section](#how-to-use-this-wrapper) to learn more about the configuration variables.
99+
100+
To run the tests alone, execute the command
101+
102+
```
103+
npm run test
104+
```
105+
106+
To run tests with coverage report, execute the command
107+
108+
```
109+
npm run cov
110+
```

docs/EventPayload.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Event Payload
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**topic** | **String** | Topic name should be a dot separated fully qualified name i.e. domain.type.operation. |
7+
**originator** | **String** | Service repository name, from where message is published. |
8+
**timestamp** | **Date** | Timestamp at which message is published. The date-time notation as defined by RFC 3339, section 5.6, for example, 2018-04-13T00:00:00Z |
9+
**mimeType** | **String** | Mime-type for 'payload'. |
10+
**payload** | **Object** | Actual payload depending on mime-type for consumer. |

docs/EventPayloadWoTopic.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Event Payload Without Topic
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**originator** | **String** | Service repository name, from where message is published. |
7+
**timestamp** | **Date** | Timestamp at which message is published. The date-time notation as defined by RFC 3339, section 5.6, for example, 2018-04-13T00:00:00Z |
8+
**mimeType** | **String** | Mime-type for 'payload'. |
9+
**payload** | **Object** | Actual payload depending on mime-type for consumer. |

docs/EventsApi.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Events Api
2+
3+
All URIs are relative to **BUSAPI_URL** configuration variable.
4+
5+
Method | HTTP request | Description
6+
------------- | ------------- | -------------
7+
[**postEvent**](EventsApi.md#postEvent) | **POST** /bus/events | Post event to the message bus.
8+
[**postError**](EventsApi.md#postError) | **POST** /bus/events | Post error event to the message bus. Topic will be set by wrapper itself.
9+
10+
<a name="postEvent"></a>
11+
# **postEvent**
12+
> postEvent(body)
13+
14+
Post an event to the message bus.
15+
16+
### Example
17+
```javascript
18+
const busApi = require('tc-bus-api-wrapper')
19+
const busApiClient = busApi(_.pick(config,
20+
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
21+
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
22+
'KAFKA_ERROR_TOPIC']))
23+
24+
const reqBody = {
25+
'topic': 'test.topic.1',
26+
'originator': 'tester',
27+
'timestamp': '2018-05-20T07:00:30.123Z',
28+
'mime-type': 'application/json',
29+
'payload': { // Payload varies depending on the event
30+
'name': 'test'
31+
}
32+
}
33+
// Promise model
34+
busApiClient
35+
.postEvent(reqBody)
36+
.then(result => console.log(result.body, result.status))
37+
.catch(err => console.log(err))
38+
39+
// Async / await model
40+
await busApiClient.postEvent(reqBody)
41+
```
42+
43+
### Parameters
44+
45+
Name | Type | Description
46+
------------- | ------------- | -------------
47+
**body** | [**Event Payload**](EventPayload.md)| Payload of an event
48+
49+
### Return type
50+
51+
null (empty response body)
52+
53+
### Authorization
54+
55+
[Bearer](../README.md#authorization)
56+
57+
### HTTP request headers
58+
59+
- **Content-Type**: application/json
60+
- **Accept**: application/json
61+
62+
<a name="postError"></a>
63+
# **postError**
64+
> postError(body)
65+
66+
Post error event to the message bus.
67+
68+
### Example
69+
```javascript
70+
const busApi = require('tc-bus-api-wrapper')
71+
const busApiClient = busApi(_.pick(config,
72+
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
73+
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
74+
'KAFKA_ERROR_TOPIC']))
75+
76+
const reqBody = {
77+
'originator': 'tester',
78+
'timestamp': '2018-05-20T07:00:30.123Z',
79+
'mime-type': 'application/json',
80+
'payload': { // Payload varies depending on the event
81+
'name': 'test'
82+
}
83+
}
84+
// Promise model
85+
busApiClient
86+
.postError(reqBody)
87+
.then(result => console.log(result.body, result.status))
88+
.catch(err => console.log(err))
89+
90+
// Async / await model
91+
await busApiClient.postError(reqBody)
92+
```
93+
94+
### Parameters
95+
96+
Name | Type | Description
97+
------------- | ------------- | -------------
98+
**body** | [**Event Payload Without Topic**](EventPayloadWoTopic.md)| Payload of error event without topic
99+
100+
### Return type
101+
102+
null (empty response body)
103+
104+
### Authorization
105+
106+
[Bearer](../README.md#authorization)
107+
108+
### HTTP request headers
109+
110+
- **Content-Type**: application/json
111+
- **Accept**: application/json

docs/ExtendedService.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Extended Service
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**serviceId** | **String** | The service id. |
7+
**service** | [**Service**](Service.md) | Service definition | Attributes from Service will be merged into this object

docs/HealthCheckStatus.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Health Check Status
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**health** | **String** | Health check status. | [default to &#39;ok&#39;]

docs/HealthchecksApi.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Healthchecks Api
2+
3+
All URIs are relative to **BUSAPI_URL** configuration variable.
4+
5+
Method | HTTP request | Description
6+
------------- | ------------- | -------------
7+
[**getHealth**](HealthchecksApi.md#getHealth) | **GET** /bus/health | Check if API is healthy.
8+
[**headHealth**](HealthchecksApi.md#headHealth) | **HEAD** /bus/health | Get only response status and headers information but no response body for the endpoint.
9+
10+
11+
<a name="getHealth"></a>
12+
# **getHealth**
13+
> HealthCheckStatus getHealth()
14+
15+
Check if API is healthy.
16+
17+
### Example
18+
```javascript
19+
const busApi = require('tc-bus-api-wrapper')
20+
const busApiClient = busApi(_.pick(config,
21+
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
22+
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
23+
'KAFKA_ERROR_TOPIC']))
24+
25+
// Promise model
26+
busApiClient
27+
.getHealth()
28+
.then(result => console.log(result.body, result.status))
29+
.catch(err => console.log(err))
30+
31+
// Async / await model
32+
const result = await busApiClient.getHealth()
33+
```
34+
35+
### Parameters
36+
This endpoint does not need any parameter.
37+
38+
### Return type
39+
40+
[**Health Check Status**](HealthCheckStatus.md)
41+
42+
### Authorization
43+
44+
No authorization required
45+
46+
### HTTP request headers
47+
48+
- **Content-Type**: application/json
49+
- **Accept**: application/json
50+
51+
<a name="headHealth"></a>
52+
# **headHealth**
53+
> headHealth()
54+
55+
Get response status and headers information for the endpoint. It does not contain response body.
56+
57+
### Example
58+
```javascript
59+
const busApi = require('tc-bus-api-wrapper')
60+
const busApiClient = busApi(_.pick(config,
61+
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
62+
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
63+
'KAFKA_ERROR_TOPIC']))
64+
65+
// Promise model
66+
busApiClient
67+
.headHealth()
68+
.then(result => console.log(result.body, result.status)) // Body will be empty
69+
.catch(err => console.log(err))
70+
71+
// Async / await model
72+
const result = await busApiClient.headHealth()
73+
```
74+
75+
### Parameters
76+
This endpoint does not need any parameter.
77+
78+
### Return type
79+
80+
null (empty response body)
81+
82+
### Authorization
83+
84+
No authorization required
85+
86+
### HTTP request headers
87+
88+
- **Content-Type**: application/json
89+
- **Accept**: application/json
90+

docs/Payload.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Payload
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**name** | **String** | The payload name. | [optional]
7+
**topics** | **[String]** | The list of topics for a payload. |
8+
**payloadMimeType** | **String** | The payload mime type. |
9+
**payloadFormat** | **Object** | The payload format. |

0 commit comments

Comments
 (0)