- Notifications
You must be signed in to change notification settings - Fork1
topcoder-platform/member-api-v6
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- nodejshttps://nodejs.org/en/ (v10)
- prisma
- PostgreSQL
- Docker, Docker Compose
Please setup PostgreSQL first. If you are using docker, you can run:
docker run -d --name memberdb -p 5432:5432 \ -e POSTGRES_USER=johndoe -e POSTGRES_DB=memberdb \ -e POSTGRES_PASSWORD=mypassword \ postgres:16
After that, please set db URL environment variables:
export DATABASE_URL="postgresql://johndoe:mypassword@localhost:5432/memberdb"
This variable is important since it's required by prisma.
If you want to do anything with database, this variable is necessary.
Before running db scripts, please make sure you have setup db and config db url as above.
# set db url valuesexport DATABASE_URL="postgresql://johndoe:mypassword@localhost:5432/memberdb"# install dependenciesnpm install
Here are some helpful scripts for db operations.
# create db tablesnpm run init-db# Clear all db datanpm run clear-db# create test datanpm run seed-data# Reset dbnpm run reset-db
I have created a script to download data from dev environment and a script to load them into db.
To use them, you should:
- Make sure you have started db.
- Check configs in
src/scripts/config.js
. Add some handle if you like. - Open a terminal and navigate to codebase folder. Set
DATABASE_URL
above. - Run
npm install
. - Use
node src/scripts/download.js
to download profile data. - Run
npm run clear-db
to clear db data first - Run
npm run seed-data
to import data into db
Configuration for the application is atconfig/default.js
.The following parameters can be set in config files or in env variables:
- 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
- GROUPS_API_URL: Groups API URL
- 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.SESSION_TOKEN: The user session token, used when developing locally against the TC dev AWS services
- AMAZON.AWS_REGION: The Amazon certificate region to use when connecting.
- AMAZON.PHOTO_S3_BUCKET: the AWS S3 bucket to store photos
- AMAZON.S3_API_VERSION: the AWS S3 API version
- FILE_UPLOAD_SIZE_LIMIT: the file upload size limit in bytes
- PHOTO_URL_TEMPLATE: photo URL template, its will be replaced with S3 object key
- VERIFY_TOKEN_EXPIRATION: verify token expiration in minutes
- EMAIL_VERIFY_AGREE_URL: email verify agree URL, the will be replaced with generated verify token
- EMAIL_VERIFY_DISAGREE_URL: email verify disagree URL
- SCOPES: the configurable M2M token scopes, refer
config/default.js
for more details - MEMBER_SECURE_FIELDS: Member profile identifiable info fields, only admin, M2M, or member himself can fetch these fields
- COMMUNICATION_SECURE_FIELDS: Member contact information, accessible by admins, managers, and copilots - anyone with a role in the AUTOCOMPLETE_ROLES array
- MEMBER_TRAIT_SECURE_FIELDS: Member traits identifiable info fields, only admin, M2M, or member himself can fetch these fields
- MISC_SECURE_FIELDS: Misc identifiable info fields, only admin, M2M, or member himself can fetch these fields
- STATISTICS_SECURE_FIELDS: Member Statistics identifiable info fields, only admin, M2M, or member himself can fetch these fields
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds
Set the following environment variables used by bus API to get TC M2M token (use 'set' insted of 'export' for Windows OS):
export AUTH0_CLIENT_ID=export AUTH0_CLIENT_SECRET=export AUTH0_URL=export AUTH0_AUDIENCE=
Also properly configure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, PHOTO_S3_BUCKET config parameters.
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
- 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 to
localhost:9000
Go tohttps://console.aws.amazon.com/ and login. Choose S3 from Service folder and clickCreate bucket
. Following the instruction to create S3 bucket.After creating bucket, clickPermissions
tab of the bucket, in theBlock public access
section, disable the block, so that public accessis allowed, then we can upload public accessible photo to the bucket.
To make local development easier, I create a mock server atmock
.
You can start it withnode mock/mock-api.js
and it will listen to port4000
This mock service will simulate request and responses for other APIs like auth0 and event bus API.
Please run following commands to set necessary configs:
export AUTH0_URL="http://localhost:4000/v5/auth0"export BUSAPI_URL="http://localhost:4000/v5"export AUTH0_CLIENT_ID=xyzexport AUTH0_CLIENT_SECRET=xyzexport USERFLOW_PRIVATE_KEY=mysecretexport GROUPS_API_URL="http://localhost:4000/v5/groups"
These commands will set auth0 and event bus api to local mock server.
- Make sure you have started db and set
DATABASE_URL
. - Make sure you have create db structure. Seed data is optional.
- Install dependencies
npm install
- Start app
npm start
- App is running at port 3000. You can visit
http://localhost:3000/v6/members/health
Make sure you have followed above steps to
- setup db and config db url
- setup local mock api and set local configs
- it will really call service and mock api
Then you can run:
npm runtest
Refer to the verification documentVerification.md
About
Resources
Uh oh!
There was an error while loading.Please reload this page.