1.2.0 • Published 4 years ago

@topcoder-platform/topcoder-bus-api-wrapper v1.2.0

Weekly downloads
22
License
ISC
Repository
github
Last release
4 years ago

tc-bus-api-wrapper

Wrapper library for Topcoder Bus API

How to use this Wrapper

  1. Include the wrapper in package.json as follows
"tc-bus-api-wrapper": "topcoder-platform/tc-bus-api-wrapper.git"
  1. Create an instance of this wrapper with the configuration variables listed below
const busApi = require('tc-bus-api-wrapper')
const busApiClient = busApi(_.pick(config,
      ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
        'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
        'KAFKA_ERROR_TOPIC', 'AUTH0_PROXY_SERVER_URL']))

Configuration / Environment variables:

  • Auth0 related variables AUTH0_URL AUTH0_AUDIENCE TOKEN_CACHE_TIME (optional) AUTH0_CLIENT_ID

  • BUSAPI_URL - Bus API URL. E.g. https://api.topcoder-dev.com/v5

  • KAFKA_ERROR_TOPIC - Error topic in Kafka to which error message need to be posted
  1. Every function in this wrapper will return a promise, Handling promises is at the caller end. Call the functions with appropriate arguments

E.g.

busApiClient
  .getTopics()
  .then(result => console.log(result.body, result.status))
  .catch(err => console.log(err))

await busApiClient.postEvent(reqBody)

Refer index.js for the list of available wrapper functions

Documentation for Bus API wrapper methods

All URIs are relative to BUSAPI_URL configuration variable.

MethodHTTP requestDescription
postEventPOST /bus/eventsPost event to the message bus.
postErrorPOST /bus/eventsPost error event to the message bus. This method is same as postEvent except that topic will be set by the wrapper itself.
getHealthGET /bus/healthCheck API is healthy.
headHealthHEAD /bus/healthGet only response status and headers information but no response body for the endpoint.
clearPlaceholdersCacheDELETE /bus/placeholdersClear placeholders cache.
createServicePOST /bus/servicesCreate a service.
createServicePayloadPOST /bus/services/{serviceName}/payloadsCreate the service payload.
deleteServiceDELETE /bus/services/{serviceName}Delete the service.
deleteServicePayloadDELETE /bus/services/{serviceName}/payloads/{payloadName}Delete the service payload.
getServiceGET /bus/services/{serviceName}Get the service.
getServicePayloadGET /bus/services/{serviceName}/payloads/{payloadName}Get the service payload.
getServicePayloadsGET /bus/services/{serviceName}/payloadsSearch the service payloads.
getServicesGET /bus/servicesGet all services.
headServiceHEAD /bus/services/{serviceName}Get only response status and headers information but no response body for the endpoint.
headServicePayloadHEAD /bus/services/{serviceName}/payloads/{payloadName}Get only response status and headers information but no response body for the endpoint.
headServicePayloadsHEAD /bus/services/{serviceName}/payloadsGet only response status and headers information but no response body for the endpoint.
headServicesHEAD /bus/servicesGet only response status and headers information but no response body for the endpoint.
patchServicePATCH /bus/services/{serviceName}Partially update the service.
patchServicePayloadPATCH /bus/services/{serviceName}/payloads/{payloadName}Partially update the payload.
updateServicePUT /bus/services/{serviceName}Update the service.
updateServicePayloadPUT /bus/services/{serviceName}/payloads/{payloadName}Update the service payload.
getTopicsGET /bus/topicsGet topics.
headTopicsHEAD /bus/topicsGet only response status and headers information but no response body for the endpoint.

Authorization

Bus API wrapper internally generates a JWT token using Auth0 credentials and pass it in the Authorization header.

Running tests

Following environment variables need to be set up before running the tests

- TEST_AUTH0_URL
- TEST_AUTH0_AUDIENCE
- TEST_AUTH0_CLIENT_ID
- TEST_AUTH0_CLIENT_SECRET
- TEST_BUS_API_URL
- TEST_KAFKA_ERROR_TOPIC

Refer to Step # 2 in this section to learn more about the configuration variables.

To run the tests alone, execute the command

npm run test

To run tests with coverage report, execute the command

npm run cov