Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

social Inbox: webhooks #7

Merged
merged 15 commits into from
Sep 6, 2023
Merged

social Inbox: webhooks #7

merged 15 commits into from
Sep 6, 2023

Conversation

akhileshthite
Copy link
Collaborator

@akhileshthite akhileshthite added the enhancement New feature or request label Sep 1, 2023
@akhileshthite akhileshthite self-assigned this Sep 1, 2023
Copy link
Contributor

@RangerMauve RangerMauve left a comment

Choose a reason for hiding this comment

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

Great start, just some minor changes needed.

Also could you add the new routes to api/index.js so that they're registered by fastify?

Also, the CI is saying there's linter errors, mind running npm run lint and npm test and fixing any errors there?

api/hooks.ts Outdated
url: Type.String({
format: 'uri'
}),
method: Type.Union([Type.Literal('GET'), Type.Literal('POST'), Type.Literal('PUT'), Type.Literal('DELETE')]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you take this type and put it into it's own const at the top called WebHookSchema? Maybe place the type definition into hookstore or hooksystem.

api/hooks.ts Outdated
}, async (request, reply) => {
// const domain = request.params.domain;
const hook = request.body
await store.setModerationQueued(hook)
Copy link
Contributor

Choose a reason for hiding this comment

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

The hook store should be set on the actor store.

Suggested change
await store.setModerationQueued(hook)
await store.forActor(actor).setModerationQueued(hook)

api/hooks.ts Outdated
}),
response: {
200: Type.Object({
message: Type.String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you omit the message property and just have the hook in the response? Ideally we should keep the raw objects in get responses without extra wrappers.

store: HookStore
fetch: FetchLike

constructor (store: HookStore, fetch: FetchLike = globalThis.fetch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
constructor (store: HookStore, fetch: FetchLike = globalThis.fetch) {
constructor (store: Store, fetch: FetchLike = globalThis.fetch) {

Hook stores are actor specific so we should take the full store and use store.forActor(actor).hooks

api/hooks.ts Outdated
import { Type } from '@sinclair/typebox'
import { HookStore } from '../store/HookStore'

export const hookRoutes = (cfg: APIConfig, store: HookStore) => async (server: FastifyTypebox): Promise<void> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing in the hook store, pass in the full Store

@akhileshthite
Copy link
Collaborator Author

Great start, just some minor changes needed.

Also could you add the new routes to api/index.js so that they're registered by fastify?

Also, the CI is saying there's linter errors, mind running npm run lint and npm test and fixing any errors there?

Done.

  • The new routes (hookRoutes) are already registered in the ./api/index.ts/.

    await server.register(hookRoutes(cfg, store))

  • The linter errors in apsystem.ts and index.test.ts test fails will be resolved once we address the merge conflicts arising from the latest updates on the initial branch.

@RangerMauve RangerMauve marked this pull request as ready for review September 4, 2023 19:34
Copy link
Contributor

@RangerMauve RangerMauve left a comment

Choose a reason for hiding this comment

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

added some more comments mostly for style

api/apsystem.ts Outdated Show resolved Hide resolved
api/apsystem.ts Outdated Show resolved Hide resolved
api/hooks.ts Outdated Show resolved Hide resolved
api/hooks.ts Outdated Show resolved Hide resolved
store/ActorStore.ts Show resolved Hide resolved
this.db = db
}

async setHook (type: string, hook: Hook): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
async setHook (type: string, hook: Hook): Promise<void> {
async set (type: string, hook: Hook): Promise<void> {

what do you think of removing the word hook from the methods since it will likely be accessed as hooks.set() anyways

@akhileshthite
Copy link
Collaborator Author

added some more comments mostly for style

Done.

Copy link
Contributor

@RangerMauve RangerMauve left a comment

Choose a reason for hiding this comment

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

One last thing, mind doing the method rename for the hook store as well?

api/apsystem.ts Outdated

constructor (publicURL: string, store: Store, modCheck: ModerationChecker, fetch: FetchLike = globalThis.fetch) {
this.publicURL = publicURL
this.store = store
this.modCheck = modCheck
this.fetch = fetch
this.hookSystem = new HookSystem(store, fetch)
Copy link
Contributor

Choose a reason for hiding this comment

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

The hooksystem should be passed into the constructor in case we wanted to mock it.

@akhileshthite
Copy link
Collaborator Author

One last thing, mind doing the method rename for the hook store as well?

Ah, missed this one.
Done.

@RangerMauve RangerMauve merged commit 25b4ff4 into initial Sep 6, 2023
2 checks passed
@RangerMauve
Copy link
Contributor

Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants