-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ecbdab
commit e07142f
Showing
6 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
apps/backend/src/app/api/v1/integrations/neon/webhooks/route.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { getSvixClient } from "@/lib/webhooks"; | ||
import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler"; | ||
import { adaptSchema, neonAuthorizationHeaderSchema, urlSchema, yupNumber, yupObject, yupString, yupTuple } from "@stackframe/stack-shared/dist/schema-fields"; | ||
|
||
export const POST = createSmartRouteHandler({ | ||
metadata: { | ||
hidden: true, | ||
}, | ||
request: yupObject({ | ||
auth: yupObject({ | ||
project: adaptSchema.defined(), | ||
}).defined(), | ||
body: yupObject({ | ||
url: urlSchema.defined(), | ||
description: yupString().optional(), | ||
}).defined(), | ||
headers: yupObject({ | ||
authorization: yupTuple([neonAuthorizationHeaderSchema.defined()]).defined(), | ||
}).defined(), | ||
}), | ||
response: yupObject({ | ||
statusCode: yupNumber().oneOf([200]).defined(), | ||
bodyType: yupString().oneOf(["json"]).defined(), | ||
body: yupObject({ | ||
secret: yupString().defined(), | ||
}).defined(), | ||
}), | ||
handler: async ({ auth, body }) => { | ||
const svix = getSvixClient(); | ||
await svix.application.getOrCreate({ uid: auth.project.id, name: auth.project.id }); | ||
const endpoint = await svix.endpoint.create(auth.project.id, { url: body.url, description: body.description }); | ||
const secret = await svix.endpoint.getSecret(auth.project.id, endpoint.id); | ||
|
||
return { | ||
statusCode: 200, | ||
bodyType: "json", | ||
body: { | ||
secret: secret.key, | ||
}, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
apps/e2e/tests/backend/endpoints/api/v1/integrations/neon/webhooks.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { it } from "../../../../../../helpers"; | ||
import { niceBackendFetch } from "../../../../../backend-helpers"; | ||
import { provisionProject } from "./projects/provision.test"; | ||
|
||
|
||
it("should be able to create a webhook", async ({ expect }) => { | ||
await provisionProject(); | ||
const response = await niceBackendFetch("/api/v1/integrations/neon/webhooks", { | ||
method: "POST", | ||
body: { | ||
url: "https://example.com/neon", | ||
description: "Test webhook", | ||
}, | ||
headers: { | ||
"Authorization": "Basic bmVvbi1sb2NhbDpuZW9uLWxvY2FsLXNlY3JldA==", | ||
}, | ||
accessType: "admin", | ||
}); | ||
expect(response).toMatchInlineSnapshot(` | ||
NiceResponse { | ||
"status": 200, | ||
"body": { "secret": <stripped field 'secret'> }, | ||
"headers": Headers { <some fields may have been hidden> }, | ||
} | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters