|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Any, Literal |
| 4 | + |
| 5 | +from linkedapi.types.base import LinkedApiModel |
| 6 | + |
| 7 | +WebhookPayloadMode = Literal["thin", "fat"] |
| 8 | +WebhookEventType = Literal[ |
| 9 | + "workflow.created", |
| 10 | + "workflow.started", |
| 11 | + "workflow.completed", |
| 12 | + "account.active", |
| 13 | + "account.reconnectionRequired", |
| 14 | + "account.frozen", |
| 15 | + "account.deleted", |
| 16 | + "webhook.test", |
| 17 | +] |
| 18 | +WebhookDeliveryStatus = Literal["pending", "delivering", "success", "failed"] |
| 19 | +WorkflowWebhookStatus = Literal["pending", "running", "completed", "failed"] |
| 20 | +AccountWebhookStatus = Literal["active", "reconnection_required", "frozen", "deleted"] |
| 21 | + |
| 22 | + |
| 23 | +class WebhookSubscription(LinkedApiModel): |
| 24 | + id: str | None = None |
| 25 | + url: str | None = None |
| 26 | + payload_mode: WebhookPayloadMode | None = None |
| 27 | + is_active: bool | None = None |
| 28 | + created_at: str | None = None |
| 29 | + |
| 30 | + |
| 31 | +class WebhookDelivery(LinkedApiModel): |
| 32 | + id: str | None = None |
| 33 | + event_type: WebhookEventType | None = None |
| 34 | + event_id: str | None = None |
| 35 | + status: WebhookDeliveryStatus | None = None |
| 36 | + attempts: int | None = None |
| 37 | + response_status_code: int | None = None |
| 38 | + last_error: str | None = None |
| 39 | + created_at: str | None = None |
| 40 | + updated_at: str | None = None |
| 41 | + |
| 42 | + |
| 43 | +class SetWebhookParams(LinkedApiModel): |
| 44 | + url: str |
| 45 | + payload_mode: WebhookPayloadMode | None = None |
| 46 | + |
| 47 | + |
| 48 | +class SetWebhookPayloadModeParams(LinkedApiModel): |
| 49 | + id: str |
| 50 | + payload_mode: WebhookPayloadMode |
| 51 | + |
| 52 | + |
| 53 | +class DeleteWebhookParams(LinkedApiModel): |
| 54 | + id: str |
| 55 | + |
| 56 | + |
| 57 | +class ReplayWebhookDeliveryParams(LinkedApiModel): |
| 58 | + delivery_id: str |
| 59 | + |
| 60 | + |
| 61 | +class WorkflowWebhookEventData(LinkedApiModel): |
| 62 | + workflow_id: str | None = None |
| 63 | + account_id: str | None = None |
| 64 | + status: WorkflowWebhookStatus | None = None |
| 65 | + # Present only on workflow.completed delivered in `fat` payload mode; in `thin` mode fetch the |
| 66 | + # result via the workflow API by workflow_id. |
| 67 | + result: Any | None = None |
| 68 | + |
| 69 | + |
| 70 | +class WorkflowWebhookEvent(LinkedApiModel): |
| 71 | + id: str |
| 72 | + type: Literal["workflow.created", "workflow.started", "workflow.completed"] |
| 73 | + created_at: str | None = None |
| 74 | + data: WorkflowWebhookEventData |
| 75 | + |
| 76 | + |
| 77 | +class AccountWebhookEventData(LinkedApiModel): |
| 78 | + account_id: str | None = None |
| 79 | + status: AccountWebhookStatus | None = None |
| 80 | + |
| 81 | + |
| 82 | +class AccountWebhookEvent(LinkedApiModel): |
| 83 | + id: str |
| 84 | + type: Literal[ |
| 85 | + "account.active", |
| 86 | + "account.reconnectionRequired", |
| 87 | + "account.frozen", |
| 88 | + "account.deleted", |
| 89 | + ] |
| 90 | + created_at: str | None = None |
| 91 | + data: AccountWebhookEventData |
| 92 | + |
| 93 | + |
| 94 | +class WebhookTestEventData(LinkedApiModel): |
| 95 | + message: str | None = None |
| 96 | + |
| 97 | + |
| 98 | +class WebhookTestEvent(LinkedApiModel): |
| 99 | + id: str |
| 100 | + type: Literal["webhook.test"] |
| 101 | + created_at: str | None = None |
| 102 | + data: WebhookTestEventData |
| 103 | + |
| 104 | + |
| 105 | +WebhookEvent = WorkflowWebhookEvent | AccountWebhookEvent | WebhookTestEvent |
0 commit comments