1.2.0 • Published 4 years ago

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

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

Topcoder Submission API Wrapper

Wrapper library for Topcoder Submission API

How to use this Wrapper

  1. Include the wrapper in package.json as follows

    "topcoder-submission-api-wrapper": "topcoder-platform/topcoder-submission-api-wrapper.git"
  2. 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 dev https://topcoder-dev.auth0.com/oauth/ro
    • TC_AUTHZ_URL - Topcoder API token URL, e.g. https://api.topcoder.com/v3/authorizations or for dev https://api.topcoder-dev.com/v3/authorizations
    • TC_CLIENT_ID - OAUTH2 Client ID, e.g. 6ZwZEUo2ZK4c50aLPpgupeg5v2Ffxp9P or for dev JFDo7HMkf0q2CkVFHojy3zHWafziprhT
    • TC_CLIENT_V2CONNECTION - The OAUTH2 Client data source, e.g. LDAP or for dev TC-User-Database
    • SUBMISSION_API_URL - Topcoder V5 Submission API URL. E.g. https://api.topcoder.com/v5 or for dev https://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 dev https://api.topcoder-dev.com/v5
  3. 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

MethodHTTP requestDescription
searchReviewTypesGET /reviewTypesSearch review types.
headReviewTypesHEAD /reviewTypesSame to search review types, but only response status and headers information return.
createReviewTypePOST /reviewTypesCreate a review type.
getReviewTypeGET /reviewTypes/{reviewTypeId}Get the review type.
headReviewTypeHEAD /reviewTypes/{reviewTypeId}Same to get review type, but only response status and headers information return.
updateReviewTypePUT /reviewTypes/{reviewTypeId}Fully update review type.
patchReviewTypePATCH /reviewTypes/{reviewTypeId}Partially update review type.
deleteReviewTypeDELETE /reviewTypes/{reviewTypeId}Delete the review type.

Reviews wrapper methods

MethodHTTP requestDescription
searchReviewsGET /reviewsSearch reviews.
headReviewsHEAD /reviewsSame to search reviews, but only response status and headers information return.
createReviewPOST /reviewsCreate a review.
getReviewGET /reviews/{reviewId}Get the review.
headReviewHEAD /reviews/{reviewId}Same to get review, but only response status and headers information return.
updateReviewPUT /reviews/{reviewId}Fully update review.
patchReviewPATCH /reviews/{reviewId}Partially update review.
deleteReviewDELETE /reviews/{reviewId}Delete the review.

Review Summations wrapper methods

MethodHTTP requestDescription
searchReviewSummationsGET /reviewSummationsSearch review summations.
headReviewSummationsHEAD /reviewSummationsSame to search review summations, but only response status and headers information return.
createReviewSummationPOST /reviewSummationsCreate a review summation.
getReviewSummationGET /reviewSummations/{reviewSummationId}Get the review summation.
headReviewSummationHEAD /reviewSummations/{reviewSummationId}Same to get review summation, but only response status and headers information return.
updateReviewSummationPUT /reviewSummations/{reviewSummationId}Fully update review summation.
patchReviewSummationPATCH /reviewSummations/{reviewSummationId}Partially update review summation.
deleteReviewSummationDELETE /reviewSummations/{reviewSummationId}Delete the review summation.

Submissions wrapper methods

MethodHTTP requestDescription
searchSubmissionsGET /submissionsSearch submissions.
headSubmissionsHEAD /submissionsSame to search submissions, but only response status and headers information return.
createSubmissionPOST /submissionsCreate a submission.
getSubmissionGET /submissions/{submissionId}Get the submission.
headSubmissionHEAD /submissions/{submissionId}Same to get submission, but only response status and headers information return.
updateSubmissionPUT /submissions/{submissionId}Fully update submission.
patchSubmissionPATCH /submissions/{submissionId}Partially update submission.
deleteSubmissionDELETE /submissions/{submissionId}Delete the submission.
downloadSubmissionGET /submissions/{submissionId}/downloadDownload the submission.
createArtifactPOST /submissions/{submissionId}/artifactsCreate artifact for submission.
listArtifactsGET /submissions/{submissionId}/artifactsList artifacts of specified submission.
downloadArtifactGET /submissions/{submissionId}/artifacts/{artifactId}/downloadDownload artifact
deleteArtifactDELETE /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