PlatformWebhooksPage.utils.ts47 lines · main
| 1 | import type { WebhookScope } from './PlatformWebhooks.types' |
| 2 | |
| 3 | export const shouldHandleEndpointNotFound = ({ |
| 4 | endpointId, |
| 5 | hasSelectedEndpoint, |
| 6 | pendingCreatedEndpointId, |
| 7 | }: { |
| 8 | endpointId?: string |
| 9 | hasSelectedEndpoint: boolean |
| 10 | pendingCreatedEndpointId: string | null |
| 11 | }) => { |
| 12 | if (!endpointId) return false |
| 13 | if (hasSelectedEndpoint) return false |
| 14 | return endpointId !== pendingCreatedEndpointId |
| 15 | } |
| 16 | |
| 17 | interface PendingSigningSecretReveal { |
| 18 | endpointId: string |
| 19 | signingSecret: string |
| 20 | } |
| 21 | |
| 22 | const pendingSigningSecretRevealByScope: Partial<Record<WebhookScope, PendingSigningSecretReveal>> = |
| 23 | {} |
| 24 | |
| 25 | export const setPendingSigningSecretReveal = ( |
| 26 | scope: WebhookScope, |
| 27 | value: PendingSigningSecretReveal |
| 28 | ) => { |
| 29 | pendingSigningSecretRevealByScope[scope] = value |
| 30 | } |
| 31 | |
| 32 | export const getPendingSigningSecretReveal = (scope: WebhookScope, endpointId?: string) => { |
| 33 | const pending = pendingSigningSecretRevealByScope[scope] |
| 34 | if (!pending) return null |
| 35 | if (endpointId && pending.endpointId !== endpointId) return null |
| 36 | return pending |
| 37 | } |
| 38 | |
| 39 | export const clearPendingSigningSecretReveal = (scope: WebhookScope) => { |
| 40 | delete pendingSigningSecretRevealByScope[scope] |
| 41 | } |
| 42 | |
| 43 | export const resetPendingSigningSecretRevealForTests = () => { |
| 44 | for (const key of Object.keys(pendingSigningSecretRevealByScope) as WebhookScope[]) { |
| 45 | delete pendingSigningSecretRevealByScope[key] |
| 46 | } |
| 47 | } |