httpHeaderAddActions.ts30 lines · main
| 1 | import type { KeyValueFieldArrayAction } from 'ui-patterns/form/KeyValueFieldArray/KeyValueFieldArray' |
| 2 | |
| 3 | interface BuildEdgeFunctionHeaderAddActionsParams<TRow> { |
| 4 | apiKey: string |
| 5 | includeApiKeyHeader?: boolean |
| 6 | createRow: (name: string, value: string) => TRow |
| 7 | } |
| 8 | |
| 9 | export const buildEdgeFunctionHeaderAddActions = <TRow>({ |
| 10 | apiKey, |
| 11 | includeApiKeyHeader = false, |
| 12 | createRow, |
| 13 | }: BuildEdgeFunctionHeaderAddActionsParams<TRow>): KeyValueFieldArrayAction<TRow>[] => [ |
| 14 | { |
| 15 | key: 'add-auth-header', |
| 16 | label: 'Add auth header with secret key', |
| 17 | description: 'Required if your edge function enforces JWT verification', |
| 18 | createRows: () => [ |
| 19 | createRow('Authorization', `Bearer ${apiKey}`), |
| 20 | ...(includeApiKeyHeader ? [createRow('apikey', apiKey)] : []), |
| 21 | ], |
| 22 | }, |
| 23 | { |
| 24 | key: 'add-source-header', |
| 25 | label: 'Add custom source header', |
| 26 | description: 'Useful to verify that the edge function was triggered from this webhook', |
| 27 | createRows: () => createRow('x-briven-webhook-source', '[Use a secret value]'), |
| 28 | separatorAbove: true, |
| 29 | }, |
| 30 | ] |