PlatformWebhooksPage.utils.ts47 lines · main
1import type { WebhookScope } from './PlatformWebhooks.types'
2
3export 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
17interface PendingSigningSecretReveal {
18 endpointId: string
19 signingSecret: string
20}
21
22const pendingSigningSecretRevealByScope: Partial<Record<WebhookScope, PendingSigningSecretReveal>> =
23 {}
24
25export const setPendingSigningSecretReveal = (
26 scope: WebhookScope,
27 value: PendingSigningSecretReveal
28) => {
29 pendingSigningSecretRevealByScope[scope] = value
30}
31
32export 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
39export const clearPendingSigningSecretReveal = (scope: WebhookScope) => {
40 delete pendingSigningSecretRevealByScope[scope]
41}
42
43export const resetPendingSigningSecretRevealForTests = () => {
44 for (const key of Object.keys(pendingSigningSecretRevealByScope) as WebhookScope[]) {
45 delete pendingSigningSecretRevealByScope[key]
46 }
47}