Skip to content

Commit

Permalink
fix(frontend): webhook/route payload from args (#5088)
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoCasa authored Jan 17, 2025
1 parent 64f4958 commit 501c44b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions frontend/src/lib/components/ScriptBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@
on:exitTriggers={() => {
captureTable?.loadCaptures(true)
}}
{args}
{initialPath}
schema={script.schema}
noEditor={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
}
}}
on:testWithArgs
args={$previewArgs}
currentPath={$pathStore}
{initialPath}
schema={$flowStore.schema}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/components/triggers/CaptureWrapper.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
{path}
hash={data?.hash}
token={data?.token}
{args}
runnableArgs={data?.args}
scopes={data?.scopes}
{showCapture}
{captureInfo}
Expand All @@ -208,6 +208,7 @@
{path}
{showCapture}
can_write={true}
runnableArgs={data?.args}
bind:args
headless
{captureInfo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
export let captureInfo: CaptureInfo | undefined = undefined
export let captureTable: CaptureTable | undefined = undefined
export let isValid = false
export let runnableArgs: any = {}
let validateTimeout: NodeJS.Timeout | undefined = undefined
let routeError: string = ''
Expand Down Expand Up @@ -107,9 +108,9 @@
<CopyableCodeBlock
disabled={!captureInfo.active}
code={`curl \\
-X POST ${captureURL} \\
-X ${http_method.toUpperCase()} ${captureURL} \\
-H 'Content-Type: application/json' \\
-d '{"foo": 42}'`}
-d '${JSON.stringify(runnableArgs ?? {}, null, 2)}'`}
language={bash}
/>
</Label>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/triggers/RoutesPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
export let isEditor: boolean = false
export let canHavePreprocessor: boolean = false
export let hasPreprocessor: boolean = false
export let args: Record<string, any> = {}
let routeEditor: RouteEditor
Expand Down Expand Up @@ -82,6 +83,7 @@
{canHavePreprocessor}
{hasPreprocessor}
{newItem}
data={{ args }}
/>
{#if !newItem}
<Section label="Routes">
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/lib/components/triggers/TriggersEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
export let isFlow: boolean
export let canHavePreprocessor: boolean = false
export let hasPreprocessor: boolean = false
export let args: Record<string, any> = {}
let eventStreamType: 'kafka' | 'nats' = 'kafka'
$: {
Expand Down Expand Up @@ -80,7 +80,7 @@
path={currentPath}
{hash}
{isFlow}
args={{}}
{args}
token=""
{newItem}
isEditor={true}
Expand Down Expand Up @@ -113,6 +113,7 @@
on:updateSchema
on:testWithArgs
{newItem}
{args}
path={currentPath}
{isFlow}
isEditor={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
{disabled}
startIcon={{ icon: Save }}
on:click={() => {
console.log('saveTrigger', args)
dispatch('saveTrigger', {
config: args
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{path}
hash={data?.hash}
token={data?.token}
{args}
runnableArgs={data?.args}
scopes={data?.scopes}
showCapture={false}
/>
Expand Down
24 changes: 15 additions & 9 deletions frontend/src/lib/components/triggers/WebhooksConfigSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
export let path: string = ''
export let hash: string | undefined = undefined
export let token: string = ''
export let args: any
export let runnableArgs: any
export let triggerTokens: TriggerTokens | undefined = undefined
export let scopes: string[] = []
export let showCapture: boolean = false
Expand Down Expand Up @@ -117,7 +117,10 @@ async function triggerJob() {
${
requestType === 'get_path'
? '// Payload is a base64 encoded string of the arguments'
: `const body = JSON.stringify(${JSON.stringify(args, null, 2).replaceAll('\n', '\n\t')});`
: `const body = JSON.stringify(${JSON.stringify(runnableArgs ?? {}, null, 2).replaceAll(
'\n',
'\n\t'
)});`
}
const endpoint = \`${url}\`;
Expand All @@ -142,7 +145,10 @@ export async function main() {
// triggerJob function
let triggerJobFunction = `
async function triggerJob() {
const body = JSON.stringify(${JSON.stringify(args, null, 2).replaceAll('\n', '\n\t')});
const body = JSON.stringify(${JSON.stringify(runnableArgs ?? {}, null, 2).replaceAll(
'\n',
'\n\t'
)});
const endpoint = \`${url}\`;
return await fetch(endpoint, {
Expand Down Expand Up @@ -199,7 +205,7 @@ function waitForJobCompletion(UUID) {
function curlCode() {
return `TOKEN='${token}'
${requestType !== 'get_path' ? `BODY='${JSON.stringify(args)}'` : ''}
${requestType !== 'get_path' ? `BODY='${JSON.stringify(runnableArgs ?? {})}'` : ''}
URL='${url}'
${webhookType === 'sync' ? 'RESULT' : 'UUID'}=$(curl -s ${
requestType != 'get_path' ? "-H 'Content-Type: application/json'" : ''
Expand Down Expand Up @@ -230,12 +236,12 @@ done`
(tokenType === 'query'
? `?token=${token}${
requestType === 'get_path'
? `&payload=${encodeURIComponent(btoa(JSON.stringify(args)))}`
? `&payload=${encodeURIComponent(btoa(JSON.stringify(runnableArgs ?? {})))}`
: ''
}`
: `${
requestType === 'get_path'
? `?payload=${encodeURIComponent(btoa(JSON.stringify(args)))}`
? `?payload=${encodeURIComponent(btoa(JSON.stringify(runnableArgs ?? {})))}`
: ''
}`)
</script>
Expand Down Expand Up @@ -373,7 +379,7 @@ done`

{#if requestType !== 'get_path'}
<Label label="Body">
<ClipboardPanel content={JSON.stringify(args, null, 2)} />
<ClipboardPanel content={JSON.stringify(runnableArgs ?? {}, null, 2)} />
</Label>
{/if}
{#key requestType}
Expand All @@ -387,7 +393,7 @@ done`
</TabContent>
<TabContent value="curl" class="flex flex-col flex-1 h-full">
<div class="relative">
{#key args}
{#key runnableArgs}
{#key requestType}
{#key webhookType}
{#key tokenType}
Expand All @@ -408,7 +414,7 @@ done`
</div>
</TabContent>
<TabContent value="fetch">
{#key args}
{#key runnableArgs}
{#key requestType}
{#key webhookType}
{#key tokenType}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/triggers/WebhooksPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import TriggersEditorSection from './TriggersEditorSection.svelte'
export let token: string
export let args: any
export let args: Record<string, any> = {}
export let scopes: string[] = []
export let isFlow: boolean = false
export let hash: string | undefined = undefined
Expand All @@ -15,7 +15,7 @@
export let canHavePreprocessor: boolean = false
export let hasPreprocessor: boolean = false
let data: any = {
$: data = {
hash,
token,
scopes,
Expand Down

0 comments on commit 501c44b

Please sign in to comment.