-
Notifications
You must be signed in to change notification settings - Fork 605
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
feat: svix integration #3814
Merged
Merged
feat: svix integration #3814
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd83adf
Add create_webhook page
wendrul b7715c3
Make small fixes
wendrul b30d435
Add token and change layout
wendrul 92b8d5e
Rename to create-webhook
wendrul cee0d0d
Change query param to domain
wendrul da7bb17
Merge remote-tracking branch 'origin/main' into win-86-svix-integration
wendrul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
149 changes: 149 additions & 0 deletions
149
frontend/src/routes/(root)/(logged)/svix/create-webhook/+page@(root).svelte
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,149 @@ | ||
<script lang="ts"> | ||
import PageHeader from '$lib/components/PageHeader.svelte' | ||
import ScriptPicker from '$lib/components/ScriptPicker.svelte' | ||
import CenteredPage from '$lib/components/CenteredPage.svelte' | ||
import { Button } from '$lib/components/common' | ||
import { page } from '$app/stores' | ||
import { userStore, workspaceStore } from '$lib/stores' | ||
import { sendUserToast } from '$lib/toast' | ||
import UserSettings from '$lib/components/UserSettings.svelte' | ||
import { generateRandomString } from '$lib/utils' | ||
import Tooltip from '$lib/components/Tooltip.svelte' | ||
|
||
let itemPath: string | undefined = undefined | ||
let itemKind: 'script' | 'flow' | 'app' = 'script' | ||
let clientName = $page.url.searchParams.get('domain') ?? undefined | ||
let redirectURI = $page.url.searchParams.get('redirect_uri') | ||
|
||
let userSettings: UserSettings | ||
let token: string | undefined = undefined | ||
let scopes: string[] = [] | ||
|
||
$: updateTokenAndScope(itemPath) | ||
|
||
async function createWebhook(path: string, kind: 'script' | 'flow' | 'app', token: string) { | ||
try { | ||
let webhook: string | ||
switch (kind) { | ||
case 'script': | ||
webhook = `${$page.url.origin}/api/w/${$workspaceStore}/jobs/run/p/${path}` | ||
redirectSuccess(webhook, token) | ||
break | ||
case 'flow': | ||
webhook = `${$page.url.origin}/api/w/${$workspaceStore}/jobs/run/f/${path}` | ||
redirectSuccess(webhook, token) | ||
break | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
sendUserToast('Invalid item type', true) | ||
break | ||
} | ||
} catch (error) { | ||
sendUserToast(error, true) | ||
} | ||
} | ||
|
||
function redirectSuccess(webhook: string, token: string) { | ||
const webhook_url = new URL(webhook) | ||
webhook_url.searchParams.append('token', token) | ||
const url = new URL(redirectURI!) | ||
url.searchParams.append('webhook_url', webhook_url.toString()) | ||
window.location.href = url.toString() | ||
} | ||
|
||
function redirectCancel(e: string): void { | ||
const url = new URL(redirectURI!) | ||
url.searchParams.append('error', e) | ||
window.location.href = url.toString() | ||
} | ||
|
||
function updateTokenAndScope(scriptPath: string | undefined) { | ||
if (!scriptPath) { | ||
scopes = [] | ||
token = undefined | ||
return | ||
} | ||
|
||
token = undefined | ||
scopes = [`run:${itemKind}/${scriptPath}`] | ||
} | ||
</script> | ||
|
||
<UserSettings | ||
bind:this={userSettings} | ||
on:tokenCreated={(e) => { | ||
token = e.detail | ||
}} | ||
newTokenLabel={`webhook-${$userStore?.username ?? 'superadmin'}-${generateRandomString(4)}`} | ||
{scopes} | ||
/> | ||
|
||
<CenteredPage> | ||
<div class="flex items-center justify-center h-screen"> | ||
<div class="flex flex-col gap-5"> | ||
<div class="flex flex-row gap-3 items-center justify-center"> | ||
<PageHeader title={`${clientName} wants to create a webhook`} /> | ||
</div> | ||
<div class="flex flex-row gap-3 items-center"> | ||
<div | ||
class="flex items-center justify-center w-10 h-10 border-2 border-blue-500 text-blue-500 font-bold rounded-full" | ||
> | ||
1 | ||
</div> | ||
<h2>Select the script or flow to be triggered by the webhook</h2> | ||
</div> | ||
<div class="flex flex-row items-center justify-center w-100%"> | ||
<div class="flex flex-col items-center gap-3 w-full"> | ||
<ScriptPicker | ||
allowEdit={false} | ||
allowFlow={true} | ||
allowRefresh={true} | ||
bind:scriptPath={itemPath} | ||
bind:itemKind | ||
/> | ||
<h4>or</h4> | ||
<div class="flex flex-row gap-2"> | ||
<Button size="xs" color="light" variant="border" target="_blank" href="/scripts/add">Create New Script</Button> | ||
<Button size="xs" color="light" variant="border" target="_blank" href="/flows/add?nodraft=true">Create New Flow</Button> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="flex flex-row gap-3 items-center mt-3"> | ||
<div | ||
class="flex items-center justify-center w-10 h-10 border-2 border-blue-500 text-blue-500 font-bold rounded-full" | ||
> | ||
2 | ||
</div> | ||
<h2>Create a token for this webhook</h2> | ||
<Tooltip customSize="150%"> | ||
If you generate a token, it will have a scope such that it can only be used to | ||
trigger this {itemKind}. It is safe to share as it cannot be used to impersonate you. | ||
Otherwise you may enter another token but beware that it will be shared with the external | ||
application. | ||
</Tooltip> | ||
</div> | ||
<div class="flex flex-row items-center justify-center"> | ||
<div class="flex flex-col items-center gap-5 w-100%"> | ||
<div class="flex flex-row items-center gap-2"> | ||
<input | ||
bind:value={token} | ||
disabled={itemPath == undefined} | ||
placeholder="enter or generate token" | ||
class="!text-md" | ||
/> | ||
<Button size="md" disabled={itemPath == undefined} on:click={userSettings.openDrawer}> | ||
Generate webhook-specific Token | ||
</Button> | ||
</div> | ||
<div class="flex flex-row gap-2 mt-10"> | ||
<Button | ||
disabled={!itemPath || !token || token === ''} | ||
on:click={() => itemPath && token && createWebhook(itemPath, itemKind, token)} | ||
>Approve and share with {clientName}</Button | ||
> | ||
<Button color="red" on:click={() => redirectCancel('user_canceled')}>Cancel</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</CenteredPage> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider validating
redirectURI
to ensure it's a valid URL before using it. This will prevent potential runtime errors if the URL is malformed.