-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added webhooks for team create and delete (#140)
* added webhooks for team create and delete * moved to svix
- Loading branch information
1 parent
8e2b864
commit ad2fd3e
Showing
6 changed files
with
118 additions
and
224 deletions.
There are no files selected for viewing
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
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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
import { getEnvVariable } from "@stackframe/stack-shared/dist/utils/env"; | ||
import { captureError } from "@stackframe/stack-shared/dist/utils/errors"; | ||
import { Svix } from "svix"; | ||
|
||
export async function sendWebhooks(options: { | ||
type: string, | ||
projectId: string, | ||
data: any, | ||
}) { | ||
try { | ||
const dataString = getEnvVariable("STACK_WEBHOOK_DATA"); | ||
const apiKey = getEnvVariable("STACK_SVIX_API_KEY"); | ||
const svix = new Svix(apiKey); | ||
|
||
if (!dataString) { | ||
return; | ||
} | ||
const data = JSON.parse(dataString); | ||
for (const { url, projectId } of data) { | ||
if (projectId !== options.projectId) { | ||
continue; | ||
} | ||
|
||
await svix.application.getOrCreate({ uid: projectId, name: projectId }); | ||
await svix.endpoint.create(projectId, { url }); | ||
await svix.message.create(projectId, { | ||
eventType: options.type, | ||
payload: { | ||
data: options.data, | ||
}, | ||
}); | ||
} | ||
} catch (error) { | ||
captureError("Failed to send webhook", error); | ||
} | ||
} |
Oops, something went wrong.