Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
NotificationsYou must be signed in to change notification settings

topcoder-platform/challenge-api-v6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This microservice provides access and interaction with all sorts of Challenge data.

Devlopment status

Total alertsLanguage grade: JavaScript

Deployment status

Dev:CircleCI Prod:CircleCI

Swagger definition

Intended use

  • Production API

Related repos

Prerequisites

Configuration

Configuration for the application is atconfig/default.js.The following parameters can be set in config files or in env variables:

  • READONLY: sets the API in read-only mode. POST/PUT/PATCH/DELETE operations will return 403 Forbidden
  • LOG_LEVEL: the log level, default is 'debug'
  • PORT: the server port, default is 3000
  • AUTH_SECRET: The authorization secret used during token verification.
  • VALID_ISSUERS: The valid issuer of tokens.
  • AUTH0_URL: AUTH0 URL, used to get M2M token
  • AUTH0_PROXY_SERVER_URL: AUTH0 proxy server URL, used to get M2M token
  • AUTH0_AUDIENCE: AUTH0 audience, used to get M2M token
  • TOKEN_CACHE_TIME: AUTH0 token cache time, used to get M2M token
  • AUTH0_CLIENT_ID: AUTH0 client id, used to get M2M token
  • AUTH0_CLIENT_SECRET: AUTH0 client secret, used to get M2M token
  • BUSAPI_URL: Bus API URL
  • KAFKA_ERROR_TOPIC: Kafka error topic used by bus API wrapper
  • AMAZON.AWS_ACCESS_KEY_ID: The Amazon certificate key to use when connecting.
  • AMAZON.AWS_SECRET_ACCESS_KEY: The Amazon certificate access key to use when connecting.
  • AMAZON.AWS_REGION: The Amazon certificate region to use when connecting.
  • AMAZON.ATTACHMENT_S3_BUCKET: the AWS S3 bucket to store attachments
  • FILE_UPLOAD_SIZE_LIMIT: the file upload size limit in bytes
  • RESOURCES_API_URL: TC resources API base URL
  • GROUPS_API_URL: TC groups API base URL
  • PROJECTS_API_URL: TC projects API base URL
  • CHALLENGE_MIGRATION_APP_URL: migration app URL
  • TERMS_API_URL: TC Terms API Base URL
  • COPILOT_RESOURCE_ROLE_IDS: copilot resource role ids allowed to upload attachment
  • HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds
  • SCOPES: the configurable M2M token scopes, referconfig/default.js for more details
  • M2M_AUDIT_HANDLE: the audit name used when perform create/update operation using M2M token
  • FORUM_TITLE_LENGTH_LIMIT: the forum title length limit

You can find sample.env files inside the/docs directory.

Available commands

Make sure you have set environment variableDATABASE_URL before any database operations.

  1. Creating tables:npm run create-tables
  2. Seed/Insert data to tables:npm run seed-tables
  3. Start all the depending services for local deployment:npm run services:up
  4. Stop all the depending services for local deployment:npm run services:down
  5. Check the logs of all the depending services for local deployment:npm run services:logs
  6. Initialize the local environments:npm run local:init
  7. Reset the local environments:npm run local:reset

Notes

  • The seed data are located insrc/scripts/seed

Local Deployment

  1. Make sure to use Node v10+ by commandnode -v. We recommend usingNVM to quickly switch to the right version:

    nvm use
  2. ⚙ Local configIn thechallenge-api root directory create.env file with the next environment variables. Values forAuth0 config should be shared with you on the forum.

    # Auth0 configAUTH0_URL=AUTH0_PROXY_SERVER_URL=AUTH0_AUDIENCE=AUTH0_CLIENT_ID=AUTH0_CLIENT_SECRET=
    • Values from this file would be automatically used by manynpm commands.
    • ⚠️ Never commit this file or its copy to the repository!

    Please make sure database url is configured before everything.

    DATABASE_URL=

    After that you can runnpm install to install dependencies. And then prisma will setup clients automatically.

  3. 🚢 Start docker-compose with services which are required to start Topcoder Challenges API locally

    npm run services:up

    This command will start postgres with docker-compose.

    If you are running services with docker, you can run:

    docker run -d --name challengedb -p 5432:5432 \   -e POSTGRES_USER=johndoe -e POSTGRES_DB=challengedb \   -e POSTGRES_PASSWORD=mypassword \   postgres:16.8

    The command to setDATABASE_URL environment variable will be like

    export DATABASE_URL="postgresql://johndoe:mypassword@localhost:5432/challengedb?schema=public"

    Be sure to run it before runningnpm install

  4. ♻ Running mock-api:

    TopCoder Challenge API calls many other APIs like Terms API, Groups API, Projects API, Resources API.

    Starting them all is a little complicated. Mock APIs are created inmock-api.

    You can run it with

    cd mock-apinpm start

    It will start a mock service at port4000 at default, and it works well with Challenge API.

    You might also need to update the API URLs inconfig/default.js Line 44~57 with environment variables. The commands are like:

    export RESOURCES_API_URL="http://localhost:4000/v5/resources"export PROJECTS_API_URL="http://localhost:4000/v5/projects"export TERMS_API_URL="http://localhost:4000/v5/terms"export RESOURCE_ROLES_API_URL="http://localhost:4000/v5/resource-roles"
  5. ♻ Create tables and setup testdata

    To create database tables, you can run:

    npm run create-tables

    To create test data, you can run:

    npm run seed-tables

    To reset db structure and create testdata, you can run:

    npm run local:init
  6. Comment Code for M2M Token and postBusEvent

    In local environment, you don't need to use M2M Token or bus API.

    You can just comment them to make it working.

    For M2M token, you need to commentsrc/common/m2m-helper.js#L18, just return an empty string.

    The content will be like:

    getM2MToken(){// return M2MHelper.m2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET);return'';}

    For postBusEvent, you need to comment codes insrc/common/helper.js#L684. The content will be like:

    asyncfunctionpostBusEvent(topic,payload,options={}){// const client = getBusApiClient();constmessage={      topic,originator:constants.EVENT_ORIGINATOR,timestamp:newDate().toISOString(),"mime-type":constants.EVENT_MIME_TYPE,      payload,};if(options.key){message.key=options.key;}// await client.postEvent(message);}
  7. 🚀 Start Topcoder Challenge API

    npm start

    The Topcoder Challenge API will be served onhttp://localhost:3000

Production deployment

  • TBD

Running tests

Configuration

Test configuration is atconfig/test.js. You don't need to change them.The following test parameters can be set in config file or in env variables:

  • ADMIN_TOKEN: admin token
  • COPILOT_TOKEN: copilot token
  • USER_TOKEN: user token
  • EXPIRED_TOKEN: expired token
  • INVALID_TOKEN: invalid token
  • M2M_FULL_ACCESS_TOKEN: M2M full access token
  • M2M_READ_ACCESS_TOKEN: M2M read access token
  • M2M_UPDATE_ACCESS_TOKEN: M2M update (including 'delete') access token
  • S3_ENDPOINT: endpoint of AWS S3 API, for unit and e2e test only; default tolocalhost:9000

Prepare

  • Start Local services in docker.
  • Create tables.
  • Various config parameters should be properly set.

Seeding db data is not needed.

Running unit tests

To run unit tests alone

npm runtest

To run unit tests with coverage report

npm run test:cov

Running integration tests

To run integration tests alone

npm run e2e

To run integration tests with coverage report

npm run e2e:cov

Verification

Refer to the verification documentVerification.md

Notes

  • after uploading attachments, the returned attachment ids should be used to update challenge;finally, attachments have challengeId field linking to their challenge,challenge also have attachments field linking to its attachments,this will speed up challenge CRUDS operations.

  • In the app-constants.js Topics field, the used topics are using a test topic,the suggested ones are commented out, because these topics are not created in TC dev Kafka yet.

Downstream Usage

  • This service is consumed by multiple Topcoder apps. Below is a quick map of where and how it’s called to help with debugging.

platform-ui

  • Admin and Review apps read challenge data and metadata via v6 endpoints:
    • Search challenges:GET /v6/challenges?{filters}. Seeplatform-ui/src/apps/admin/src/lib/services/challenge-management.service.ts.
    • Fetch challenge by id:GET /v6/challenges/{id}. Seeplatform-ui/src/apps/admin/src/lib/services/challenge-management.service.ts andplatform-ui/src/apps/review/src/lib/services/challenges.service.ts.
    • Challenge types and tracks:GET /v6/challenge-types,GET /v6/challenge-tracks. Seeplatform-ui/src/apps/admin/src/lib/services/challenge-management.service.ts andplatform-ui/src/apps/review/src/lib/services/challenges.service.ts.
    • Support requests:POST /v6/challenges/support-requests. Seeplatform-ui/src/libs/shared/lib/components/contact-support-form/contact-support-functions/contact-support-store/contact-support.store.ts.
  • Local dev proxy maps/v6/challenges,/v6/challenge-types,/v6/challenge-tracks,/v6/challenge-phases, and/v6/timeline-templates to this service on port 3000. Seeplatform-ui/src/config/environments/local.env.ts.

community-app

  • Uses v6 endpoints for public challenge listing and details:
    • List/search challenges for dashboards and content blocks:GET /v6/challenges?{filters}. Seecommunity-app/src/shared/services/dashboard.js andcommunity-app/src/shared/actions/contentful.js.
    • Fetch challenge details (e.g., for review opportunity details pages):GET /v6/challenges/{id}. Seecommunity-app/src/shared/services/reviewOpportunities.js.

work-manager

  • Work Manager CRUD and metadata flows rely on v6 Challenge API:
    • Get challenge details:GET /v6/challenges/{id}. Seework-manager/src/services/challenges.js.
    • Create/update/delete challenges:POST /v6/challenges,PUT /v6/challenges/{id},PATCH /v6/challenges/{id},DELETE /v6/challenges/{id}. Seework-manager/src/services/challenges.js.
    • Manage attachments:POST /v6/challenges/{id}/attachments,DELETE /v6/challenges/{id}/attachments/{attachmentId}. Seework-manager/src/services/challenges.js.
    • Default reviewers:GET /v6/challenge/default-reviewers?typeId&trackId. Seework-manager/src/services/challenges.js.
    • Challenge metadata:GET /v6/challenge-types,GET /v6/challenge-tracks,GET /v6/challenge-phases,GET /v6/challenge-timelines. Seework-manager/src/services/challenges.js and config underwork-manager/config/constants/*.
  • API base configuration points to v6 in dev/local and v5 in prod (for compatibility):
    • Dev:work-manager/config/constants/development.js.
    • Local:work-manager/config/constants/local.js.
    • Prod:work-manager/config/constants/production.js.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors6

Languages


[8]ページ先頭

©2009-2025 Movatter.jp