feat: add basic webui
This commit is contained in:
6
packages/webhooks/index.ts
Normal file
6
packages/webhooks/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { getAppPortal, send } from './lib/svix';
|
||||
|
||||
export const webhooks = {
|
||||
send,
|
||||
getAppPortal,
|
||||
};
|
||||
51
packages/webhooks/lib/svix.ts
Normal file
51
packages/webhooks/lib/svix.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import 'server-only';
|
||||
import { getSessionFromHeaders } from '@konobangu/auth/server';
|
||||
import { env } from '@konobangu/env';
|
||||
import { Svix } from 'svix';
|
||||
|
||||
export const send = async (eventType: string, payload: object) => {
|
||||
if (!env.SVIX_TOKEN) {
|
||||
throw new Error('SVIX_TOKEN is not set');
|
||||
}
|
||||
|
||||
const svix = new Svix(env.SVIX_TOKEN);
|
||||
const session = await getSessionFromHeaders();
|
||||
const { orgId } = session;
|
||||
|
||||
if (!orgId) {
|
||||
return;
|
||||
}
|
||||
|
||||
return svix.message.create(orgId, {
|
||||
eventType,
|
||||
payload: {
|
||||
eventType,
|
||||
...payload,
|
||||
},
|
||||
application: {
|
||||
name: orgId,
|
||||
uid: orgId,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const getAppPortal = async () => {
|
||||
if (!env.SVIX_TOKEN) {
|
||||
throw new Error('SVIX_TOKEN is not set');
|
||||
}
|
||||
|
||||
const svix = new Svix(env.SVIX_TOKEN);
|
||||
const session = await getSessionFromHeaders();
|
||||
const { orgId } = session;
|
||||
|
||||
if (!orgId) {
|
||||
return;
|
||||
}
|
||||
|
||||
return svix.authentication.appPortalAccess(orgId, {
|
||||
application: {
|
||||
name: orgId,
|
||||
uid: orgId,
|
||||
},
|
||||
});
|
||||
};
|
||||
18
packages/webhooks/package.json
Normal file
18
packages/webhooks/package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@konobangu/webhooks",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
||||
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
|
||||
},
|
||||
"dependencies": {
|
||||
"@konobangu/auth": "workspace:*",
|
||||
"@konobangu/env": "workspace:*",
|
||||
"svix": "^1.43.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.7.2",
|
||||
"@konobangu/typescript-config": "workspace:*"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user