Skip to content

YPP backend#40

Merged
zeeshanakram3 merged 16 commits intoJoystream:mainfrom
zeeshanakram3:YPP
Sep 22, 2022
Merged

YPP backend#40
zeeshanakram3 merged 16 commits intoJoystream:mainfrom
zeeshanakram3:YPP

Conversation

@zeeshanakram3
Copy link
Copy Markdown
Contributor

@zeeshanakram3 zeeshanakram3 commented Aug 30, 2022

implements

YoutubeSync

Required Stack

  • Docker
  • aws cli

Enter localhost:3001/docs to view all api endpoints and their descriptions

For user verification flow only two endpoints are needed

/users/verify

/users/verify-and-save

Running the app

  1. Install dependencies
    yarn

  2. Deploy all the necessary infrastructure

cd packages/infrastructue
./deploy.sh

This script deploys the relevant dynamoDB tables for needed for the verifications flow.

  1. Start the YPP backend server
    yarn nx run api:serve

This will start the YPP backend service at localhost:3001

  1. Start the frontend app
    yarn nx run app:serve

Open the browser window at localhost:4200 to interact with the app. Click VERIFY YOUR YOUTUBE CHANNEL button to start the verification flow. If verification is successful the YPP will respond back with email and userId of the verified user. (See response type for /users/verify endpoint at localhost:3001/docs).

After that the frontend app need to prepare the request for save the verified channel to the YPP backend state. There is no UI for that so, you can use any api client(e.g. Postman) for making request to users/verify-and-save with provided values of userId, joystreamChannelId, email, and optional referrerId

Copy link
Copy Markdown
Contributor

@kdembler kdembler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick first round of feedback after testing:

Error handling

I think we should introduce some kind of errorCode to make it easier to distinct between different error types. Currently if some validation is failed error is always Bad request, we could repurpose that to create some list of unique error codes to map to specific errors.

For example, if my channel doesn't meet some criteria I will see:

{
  "statusCode": 400,
  "message": "Channel UCCs9_brR2ADhDVuhrVTjKfQ with 0 subscribers does not \n          meet Youtube Partner Program requirement of 100 subscribers",
  "error": "Bad Request"
}

This is problematic because:
a) to understand what kind of error happened we need to do message string matching which can be risky if error message changes in the future
b) we need to parse the message to understand what is the requirement (100 subscribers)

Another issue is that when verifying the eligibility, code will return error on first error found. However, to properly present the status to the user we actually need to see all the failing criteria, not just the first one.

I would suggest error format along those lines:

{
  "errors": [
    {
      "errorCode": "CHANNEL_CRITERIA_UNMET_SUBSCRIBERS",
      "message": "Channel UCCs9_brR2ADhDVuhrVTjKfQ with 0 subscribers does not meet Youtube Partner Program requirement of 100 subscribers",
      "subscribers": 0,
      "requiredSubscribers": 100
    },
    {
        "errorCode": "CHANNEL_CRITERIA_UNMET_VIDEOS",
        "message": "Channel UCCs9_brR2ADhDVuhrVTjKfQ does not meet Youtube Partner Program requirement of at least 10 videos, each 1 month old",
        "videos": 3,
        "requiredVideos": 10
    }
  ]
}

Let me know how you think feasible this is.

Issues

  1. When I query /users/{userId}/videos I get 500 server error
  2. When I query /channels/{id}, what is the ID that should be passed here? Seems whatever I pass (I tried user ID, joystream channel ID) I get back
{
  "statusCode": 400,
  "message": "The number of conditions on the keys is invalid"
}
  1. When I query /users I get 500 server error

@zeeshanakram3
Copy link
Copy Markdown
Contributor Author

I would suggest error format along those lines: ...

Addressed error changes as suggested in the review

When I query /users/{userId}/videos I get 500 server error

Fixed

When I query /channels/{id}, what is the ID that should be passed here? Seems whatever I pass (I tried user ID, joystream channel ID) I get back

Fixed. You should pass the Joystream ChannelId as parameter. I have updated the description

When I query /users I get 500 server error

Fixed

Copy link
Copy Markdown
Contributor

@kdembler kdembler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API still fails to start if it fails to connect to RPC endpoint. The worst thing about it is that it fails silently and doesn't really indicate that the app failed to start. We should do one of the following:
a) Make the app work without a successful RPC connection, since that isn't really needed at the moment (for the YPP scope)
b) Make it clear that the app failed to load because of failed RPC connection

@kdembler
Copy link
Copy Markdown
Contributor

kdembler commented Sep 9, 2022

Also noticed that if I call verify (I will get my YT email back) and then call verify-and-save with different email, the different email is not saved and my user still has the YT email attached when I query /users

@zeeshanakram3
Copy link
Copy Markdown
Contributor Author

The API still fails to start if it fails to connect to RPC endpoint

Addressed. Now API won't crash on Node version > 14

Also noticed that if I call verify (I will get my YT email back) and then call verify-and-save with different email, the different email is not saved and my user still has the YT email attached when I query /users

Fixed.

Copy link
Copy Markdown
Contributor

@kdembler kdembler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional points:

  1. Seems this wasn't resolved? I still see the same behavior

Also noticed that if I call verify (I will get my YT email back) and then call verify-and-save with different email, the different email is not saved and my user still has the YT email attached when I query /users

Fixed.

  1. We discussed changing the endpoints 👇 Did you decide to skip this after all?

/users/verify would be just POST to /users as this call creates a user (it also saves some data, not just verifies)
/users/verify-and-save would be POST to /channels as this call creates an entry in /channels list


// YPP induction criteria, each channel should meet following criteria
const MINIMUM_SUBSCRIBERS_COUNT = 50
const MINiMUM_VIDEO_COUNT = 10
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, should be MINIMUM, all caps

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 5c475a3

message:
`Channel ${channel.id} with ${channel.statistics.videoCount} videos does not meet Youtube ` +
`Partner Program requirement of at least ${MINiMUM_VIDEO_COUNT} videos, each 1 month old`,
result: channel.statistics.videoCount,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should return videos.length instead, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 5c475a3

errorCode: ExitCodes.CHANNEL_CRITERIA_UNMET_VIDEOS,
message:
`Channel ${channel.id} with ${channel.statistics.videoCount} videos does not meet Youtube ` +
`Partner Program requirement of at least ${MINiMUM_VIDEO_COUNT} videos, each 1 month old`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each 1 month old should use MINIMUM_VIDEO_AGE_MONTHS

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 5c475a3

errorCode: ExitCodes.CHANNEL_CRITERIA_UNMET_CREATION_DATE,
message:
`Channel ${channel.id} with creation time of ${channel.publishedAt} does not ` +
`meet Youtube Partner Program requirement of channel being at least 3 months old`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least 3 months old should use MINIMUM_CHANNEL_AGE_MONTHS

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 5c475a3

@zeeshanakram3
Copy link
Copy Markdown
Contributor Author

Seems this wasn't resolved? I still see the same behavior

Sorry, there was an issue in the previous fix. Now resolved

We discussed changing the endpoints 👇 Did you decide to skip this after all?

Overlooked that before. Now resolved, now verify-and-save is POST to /channels

Copy link
Copy Markdown
Contributor

@kdembler kdembler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants