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

Start work on API endpoints and API access used by frontend adapters#79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jjnp wants to merge15 commits intomain
base:main
Choose a base branch
Loading
fromfeature/adapter-api-endpoints

Conversation

@jjnp
Copy link
Contributor

@jjnpjjnp commentedJun 2, 2024

This PR starts adding some groundwork necessary for the endpoints that allow frontend adapters to sync.
Among other minor things, it:

  • Adds endpoints to configure projects via api
  • Adds endpoints to read and write translations for projects
  • add ApiAccess as an entity to the DB (including repo and services) to manage api keys for projects
  • add basic Project repository implementations as they were necessary for the apiAccess

@jjnpjjnp requested a review frommledl as acode ownerJune 2, 2024 12:31
@jjnpjjnpforce-pushed thefeature/adapter-api-endpoints branch from0fc6207 tobb1cdfaCompareJune 2, 2024 12:46
@jjnpjjnpforce-pushed thefeature/adapter-api-endpoints branch frombb1cdfa to6a45b80CompareJune 2, 2024 12:49
Copy link
Collaborator

@sjaghorisjaghori 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! 🚀
I got some comments...

"kysely":"^0.27.3",
"pino":"^9.0.0",
"pino-pretty":"^11.0.0",
"uuid":"^9.0.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

since node v20 the std. crypto library has builtin uuid v4 generator. Let's not add the dependency here.

mledl reacted with thumbs up emoji
import{createTableMigration}from'../migration.util'

exportasyncfunctionup(db:Kysely<unknown>):Promise<void>{
awaitcreateTableMigration(db,'apiaccess')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
awaitcreateTableMigration(db,'apiaccess')
awaitcreateTableMigration(db,'api_access')


exportasyncfunctionup(db:Kysely<unknown>):Promise<void>{
awaitcreateTableMigration(db,'apiaccess')
.addColumn('apikey','text',(col)=>col.unique().notNull())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.addColumn('apikey','text',(col)=>col.unique().notNull())
.addColumn('api_key','text',(col)=>col.unique().notNull())

what do you think?

import{z}from'zod'

consttranslationKeySchema=z.string().brand('translation-key')
exporttypeTranslationKey=z.infer<typeoftranslationKeySchema>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to keep this in this folder?

@@ -1 +1 @@
pnpm exec lint-staged
npm test
Copy link
Collaborator

Choose a reason for hiding this comment

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

we also want to run lint-staged no?

}

returnvalidationResult.data
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great, we got something similar in production, here is the snippet.
Theoratically the request payload clould be a formdata as well, let's support both json and formdata.

importtype{Logger}from'pino'import{ZodError,typez}from'zod'typeParsedRequestData<Textendsz.ZodType>=|{status:'success'data:z.output<T>}|{status:'error'data:{validationErrorMessage:stringcode:number}}exportconstparseRequestData=async<Textendsz.ZodType>(schema:T,request:Request,logger:Logger,kind:'json'|'from-data'='json'):Promise<ParsedRequestData<T>>=>{letparsedPayload:z.output<typeofschema>try{letpayload:unknownif(kind==='json'){payload=awaitrequest.json()}else{payload=Object.fromEntries(awaitrequest.formData())}parsedPayload=schema.parse(payload)}catch(e:unknown){letvalidationErrorMessage:string='Error parsing request payload.'letcode=500if(einstanceofZodError){validationErrorMessage=`Error validating request payload against zod schema.${e.message}`code=400logger.error({message:validationErrorMessage,name:e.name,errors:e.issues})}else{logger.error(validationErrorMessage)}return{status:'error',data:{ validationErrorMessage, code}}}return{status:'success',data:parsedPayload}}

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

Reviewers

@sjaghorisjaghorisjaghori requested changes

@mledlmledlAwaiting requested review from mledlmledl is a code owner

@benjaminstrasserbenjaminstrasserAwaiting requested review from benjaminstrasserbenjaminstrasser is a code owner

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@jjnp@sjaghori

[8]ページ先頭

©2009-2025 Movatter.jp