chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { isApiClientError } from '@/lib/api/client/errors'
|
||||
import { requestJson } from '@/lib/api/client/request'
|
||||
import {
|
||||
type ListWebhooksByBlockResponse,
|
||||
listWebhooksByBlockContract,
|
||||
updateWebhookContract,
|
||||
type WebhookData,
|
||||
} from '@/lib/api/contracts/webhooks'
|
||||
|
||||
export const WEBHOOK_DETAIL_STALE_TIME = 60 * 1000
|
||||
|
||||
export const webhookKeys = {
|
||||
all: ['webhooks'] as const,
|
||||
details: () => [...webhookKeys.all, 'detail'] as const,
|
||||
byBlock: (workflowId?: string, blockId?: string) =>
|
||||
[...webhookKeys.details(), workflowId ?? '', blockId ?? ''] as const,
|
||||
}
|
||||
|
||||
export type { WebhookData }
|
||||
|
||||
async function fetchWebhooks(
|
||||
workflowId: string,
|
||||
blockId: string,
|
||||
signal?: AbortSignal
|
||||
): Promise<WebhookData | null> {
|
||||
let data: ListWebhooksByBlockResponse
|
||||
try {
|
||||
data = await requestJson(listWebhooksByBlockContract, {
|
||||
query: { workflowId, blockId },
|
||||
signal,
|
||||
})
|
||||
} catch (error) {
|
||||
if (isApiClientError(error) && error.status === 404) return null
|
||||
throw error
|
||||
}
|
||||
|
||||
if (data.webhooks && data.webhooks.length > 0) {
|
||||
return data.webhooks[0].webhook
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function useWebhookQuery(workflowId: string, blockId: string, enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: webhookKeys.byBlock(workflowId, blockId),
|
||||
queryFn: ({ signal }) => fetchWebhooks(workflowId, blockId, signal),
|
||||
enabled: enabled && Boolean(workflowId && blockId),
|
||||
staleTime: WEBHOOK_DETAIL_STALE_TIME,
|
||||
})
|
||||
}
|
||||
|
||||
interface ReactivateWebhookVariables {
|
||||
webhookId: string
|
||||
workflowId: string
|
||||
blockId: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactivates a disabled webhook and invalidates the block's webhook query so
|
||||
* the shared cache (read by useWebhookQuery / useWebhookManagement) reflects the
|
||||
* new active state immediately instead of serving the stale value for staleTime.
|
||||
*/
|
||||
export function useReactivateWebhook() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ webhookId }: ReactivateWebhookVariables) =>
|
||||
requestJson(updateWebhookContract, {
|
||||
params: { id: webhookId },
|
||||
body: { isActive: true, failedCount: 0 },
|
||||
}),
|
||||
onSettled: (_data, _error, variables) =>
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: webhookKeys.byBlock(variables.workflowId, variables.blockId),
|
||||
}),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user