@topcoder-platform/topcoder-submission-api-wrapper
v1.2.0
Published
Wrapper for Topcoder Submission API
Downloads
18
Keywords
Readme
Topcoder Submission API Wrapper
Wrapper library for Topcoder Submission API
How to use this Wrapper
Include the wrapper in package.json as follows
"topcoder-submission-api-wrapper": "topcoder-platform/topcoder-submission-api-wrapper.git"
Create an instance of this wrapper with any one of the approaches listed below, depending on your use case
M2M Authentication Configuration:
const submissionApi = require('topcoder-submission-api-wrapper') const submissionApiM2MClient = submissionApi(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'SUBMISSION_API_URL', 'AUTH0_PROXY_SERVER_URL']))
- AUTH0_URL - the auth0 url
- AUTH0_AUDIENCE - the auth0 audience
- TOKEN_CACHE_TIME - (optional) the token cache time
- AUTH0_CLIENT_ID - the auth0 client id, used as credential
- AUTH0_CLIENT_SECRET - the auth0 client secret, used as credential
- AUTH0_PROXY_SERVER_URL - (optional) the auth0 proxy server url
- SUBMISSION_API_URL - Topcoder V5 Submission API URL. E.g.
https://api.topcoder-dev.com/v5
- PAGE - the page number
- PER_PAGE - the page size
- MAX_PAGE_SIZE - the max number of page size
User Credentials Authentication Configuration:
const submissionApiUserCredentialsClient = submissionApi(_.pick(config, ['USERNAME', 'PASSWORD', 'TC_AUTHN_URL', 'TC_AUTHZ_URL', 'TC_CLIENT_ID', 'TC_CLIENT_V2CONNECTION', 'SUBMISSION_API_URL']))
- USERNAME - Topcoder handle
- PASSWORD - Topcoder password
- TC_AUTHN_URL - OAUTH2 token URL, e.g.
https://topcoder.auth0.com/oauth/ro
or for devhttps://topcoder-dev.auth0.com/oauth/ro
- TC_AUTHZ_URL - Topcoder API token URL, e.g.
https://api.topcoder.com/v3/authorizations
or for devhttps://api.topcoder-dev.com/v3/authorizations
- TC_CLIENT_ID - OAUTH2 Client ID, e.g.
6ZwZEUo2ZK4c50aLPpgupeg5v2Ffxp9P
or for devJFDo7HMkf0q2CkVFHojy3zHWafziprhT
- TC_CLIENT_V2CONNECTION - The OAUTH2 Client data source, e.g.
LDAP
or for devTC-User-Database
- SUBMISSION_API_URL - Topcoder V5 Submission API URL. E.g.
https://api.topcoder.com/v5
or for devhttps://api.topcoder-dev.com/v5
JWT Method Argument Authentication Configuration:
const submissionJwtMethodArgClient = submissionApi(_.pick(config, ['SUBMISSION_API_URL']))
- SUBMISSION_API_URL - Topcoder V5 Submission API URL. E.g.
https://api.topcoder.com/v5
or for devhttps://api.topcoder-dev.com/v5
Every function in this wrapper will return a promise, Handling promises is at the caller end. Call the functions with appropriate arguments
E.g.
const reviewTypeId = '8f4e8b6a-0ad2-4ff6-ab19-afeb102ff3b4'
submissionApiClient
.createReviewType({ name: 'test-for-create', isActive: true })
.then(result => console.log(result.body, result.status))
.catch(err => console.log(err))
await submissionApiClient.deleteReviewType(reviewTypeId)
const result = await submissionApiClient.searchReviews({ page: 2, perPage: 30 })
Refer index.js
for the list of available wrapper functions
Documentation for wrapper methods
All URIs are relative to SUBMISSION_API_URL configuration variable.
Review Types wrapper methods
Method | HTTP request | Description ------------- | ------------- | ------------- searchReviewTypes | GET /reviewTypes | Search review types. headReviewTypes | HEAD /reviewTypes | Same to search review types, but only response status and headers information return. createReviewType | POST /reviewTypes | Create a review type. getReviewType | GET /reviewTypes/{reviewTypeId} | Get the review type. headReviewType | HEAD /reviewTypes/{reviewTypeId} | Same to get review type, but only response status and headers information return. updateReviewType | PUT /reviewTypes/{reviewTypeId} | Fully update review type. patchReviewType | PATCH /reviewTypes/{reviewTypeId} | Partially update review type. deleteReviewType | DELETE /reviewTypes/{reviewTypeId} | Delete the review type.
Reviews wrapper methods
Method | HTTP request | Description ------------- | ------------- | ------------- searchReviews | GET /reviews | Search reviews. headReviews | HEAD /reviews | Same to search reviews, but only response status and headers information return. createReview | POST /reviews | Create a review. getReview | GET /reviews/{reviewId} | Get the review. headReview | HEAD /reviews/{reviewId} | Same to get review, but only response status and headers information return. updateReview | PUT /reviews/{reviewId} | Fully update review. patchReview | PATCH /reviews/{reviewId} | Partially update review. deleteReview | DELETE /reviews/{reviewId} | Delete the review.
Review Summations wrapper methods
Method | HTTP request | Description ------------- | ------------- | ------------- searchReviewSummations | GET /reviewSummations | Search review summations. headReviewSummations | HEAD /reviewSummations | Same to search review summations, but only response status and headers information return. createReviewSummation | POST /reviewSummations | Create a review summation. getReviewSummation | GET /reviewSummations/{reviewSummationId} | Get the review summation. headReviewSummation | HEAD /reviewSummations/{reviewSummationId} | Same to get review summation, but only response status and headers information return. updateReviewSummation | PUT /reviewSummations/{reviewSummationId} | Fully update review summation. patchReviewSummation | PATCH /reviewSummations/{reviewSummationId} | Partially update review summation. deleteReviewSummation | DELETE /reviewSummations/{reviewSummationId} | Delete the review summation.
Submissions wrapper methods
Method | HTTP request | Description ------------- | ------------- | ------------- searchSubmissions | GET /submissions | Search submissions. headSubmissions | HEAD /submissions | Same to search submissions, but only response status and headers information return. createSubmission | POST /submissions | Create a submission. getSubmission | GET /submissions/{submissionId} | Get the submission. headSubmission | HEAD /submissions/{submissionId} | Same to get submission, but only response status and headers information return. updateSubmission | PUT /submissions/{submissionId} | Fully update submission. patchSubmission | PATCH /submissions/{submissionId} | Partially update submission. deleteSubmission | DELETE /submissions/{submissionId} | Delete the submission. downloadSubmission | GET /submissions/{submissionId}/download | Download the submission. createArtifact | POST /submissions/{submissionId}/artifacts | Create artifact for submission. listArtifacts | GET /submissions/{submissionId}/artifacts | List artifacts of specified submission. downloadArtifact | GET /submissions/{submissionId}/artifacts/{artifactId}/download | Download artifact deleteArtifact | DELETE /submissions/{submissionId}/artifacts/{artifactId} | Delete artifact
Authorization
The wrapper internally generates the JWT token based on the method used when initialising the wrapper (m2m v/s user) or uses the jwt passed during method invocation and passes 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_SUBMISSION_API_URL
- TEST_JWT
- TEST_USERNAME
- TEST_PASSWORD
- TEST_TC_AUTHN_URL
- TEST_TC_AUTHZ_URL
- TEST_TC_CLIENT_ID
- TEST_TC_CLIENT_V2CONNECTION
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